An always-on second brain you talk to. Voice notes in Telegram → typed, linked knowledge in your Obsidian vault. Runs 24/7 on the Claude subscription you already have.
Python ai-agentsai-automationclaudeclaude-codeebbinghausknowledge-graphllmmemory-systemobsidianpersonal-assistantpkmproductivitypythonsecond-braintelegram-botvoice-assistant
fix: stream long prompts via tmux stdin buffer
smixs973031cc7f32
diff --git a/src/d_brain/services/claude_session.py b/src/d_brain/services/claude_session.pyindex 52c65e9..7512583 100644--- a/src/d_brain/services/claude_session.py+++ b/src/d_brain/services/claude_session.py@@ -122,9 +122,15 @@ class ClaudeSession:# ── tmux helpers ─────────────────────────────────────────────────- def _tmux(self, *args: str) -> subprocess.CompletedProcess:+ def _tmux(+ self, *args: str, input_text: str | None = None+ ) -> subprocess.CompletedProcess:proc = self._runner(- ["tmux", *args], capture_output=True, text=True, check=False+ ["tmux", *args],+ capture_output=True,+ text=True,+ check=False,+ input=input_text,)if proc.returncode != 0:logger.warning(@@ -280,8 +286,13 @@ class ClaudeSession:# ── sending ──────────────────────────────────────────────────────def _send_text(self, text: str) -> None:+ # Stream the payload to `load-buffer -` over stdin; passing it as an+ # argv element trips tmux's "set-buffer: command too long" on long+ # prompts and the text is silently dropped (session then stalls).+ if not text:+ return # 0 bytes ⇒ no buffer ⇒ paste-buffer would fail `no buffer`buf = f"dbrain_{uuid.uuid4().hex[:6]}"- self._tmux("set-buffer", "-b", buf, text)+ self._tmux("load-buffer", "-b", buf, "-", input_text=text)self._tmux("paste-buffer", "-t", self._target, "-b", buf, "-d")self._sleep(self._paste_settle)diff --git a/tests/test_claude_session.py b/tests/test_claude_session.pyindex c4bb873..2239baa 100644--- a/tests/test_claude_session.py+++ b/tests/test_claude_session.py@@ -143,6 +143,50 @@ def test_ensure_session_raises_if_never_ready(tmp_path, clock):s.ensure_session()+# ── sending (buffer) ─────────────────────────────────────────────────────+++def test_send_text_pipes_long_payload_via_stdin(tmp_path, clock):+ """Regression: a long prompt must be streamed to `tmux load-buffer -` over+ stdin, never passed as an argv element — argv data trips tmux's+ `set-buffer: command too long` and the prompt is silently dropped."""+ recorded: list[tuple[list[str], dict]] = []++ def runner(args, **kwargs):+ recorded.append((args, kwargs))+ return subprocess.CompletedProcess(args, 0, stdout="", stderr="")++ s = make_session(tmp_path, runner, clock)+ big = "x" * 200_000+ s._send_text(big)++ loads = [+ (a, k)+ for (a, k) in recorded+ if len(a) > 1 and a[1] in ("set-buffer", "load-buffer")+ ]+ assert loads, "expected a buffer-load tmux call"+ args, kwargs = loads[0]+ assert big not in args, "payload must not be passed as an argv element"+ assert kwargs.get("input") == big, "payload must be piped via stdin"+ assert args[1] == "load-buffer" and "-" in args+++def test_send_text_noop_on_empty(tmp_path, clock):+ """`load-buffer -` of zero bytes creates no buffer, so a following+ paste-buffer would fail `no buffer` — empty text must send nothing."""+ recorded: list[list[str]] = []++ def runner(args, **kwargs):+ recorded.append(args)+ return subprocess.CompletedProcess(args, 0, stdout="", stderr="")++ s = make_session(tmp_path, runner, clock)+ s._send_text("")+ subs = [a[1] for a in recorded if len(a) > 1 and a[0] == "tmux"]+ assert "load-buffer" not in subs and "paste-buffer" not in subs++# ── ask ─────────────────────────────────────────────────────────────────