The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): keep the slash worker's string contracts; carry the seed out of band
Brooklyn Nicholson067fb583be63
diff --git a/tests/tui_gateway/test_protocol.py b/tests/tui_gateway/test_protocol.pyindex fc710e1d8a5..0c88de84781 100644--- a/tests/tui_gateway/test_protocol.py+++ b/tests/tui_gateway/test_protocol.py@@ -1397,7 +1397,7 @@ class _BannerWorker:def run(self, command):self.calls.append(command)- return "⚡ Loading skill: grilling", ""+ return "⚡ Loading skill: grilling"def close(self):self.closed = True@@ -1511,7 +1511,7 @@ def test_slash_exec_skill_scan_raise_still_runs_registry_commands(server):def run(self, command):self.calls.append(command)- return "verbose ok", ""+ return "verbose ok"def close(self):passdiff --git a/tests/tui_gateway/test_slash_prompt_compose_seed.py b/tests/tui_gateway/test_slash_prompt_compose_seed.pyindex 18bb215194a..0df47d87978 100644--- a/tests/tui_gateway/test_slash_prompt_compose_seed.py+++ b/tests/tui_gateway/test_slash_prompt_compose_seed.py@@ -18,6 +18,7 @@ from tui_gateway import serverclass _FakeCLI:"""Records the command; simulates /prompt parking the composed text on the seed."""+console = Nonedef __init__(self, seed=None):@@ -37,27 +38,48 @@ def test_run_harvests_pending_agent_seed():from tui_gateway import slash_workercli = _FakeCLI(seed="Composed in $EDITOR")- result = slash_worker._run(cli, "/prompt")- assert result["output"] == ""- assert result["seed"] == "Composed in $EDITOR"+ out = slash_worker._run(cli, "/prompt")+ assert out == ""+ assert cli._harvested_seed == "Composed in $EDITOR"# one-shot: the seed is consumed, a second command must not re-send itassert cli._pending_agent_seed is None- result2 = slash_worker._run(cli, "/status")- assert result2["seed"] == ""+ out2 = slash_worker._run(cli, "/status")+ assert cli._harvested_seed == ""-def test_run_without_seed_returns_empty_seed():+def test_run_without_seed_harvests_empty_seed():from tui_gateway import slash_worker- result = slash_worker._run(_FakeCLI(), "/status")- assert result == {"output": "", "seed": ""} or (result["output"] and result["seed"] == "")+ cli = _FakeCLI()+ out = slash_worker._run(cli, "/status")+ assert isinstance(out, str)+ assert cli._harvested_seed == ""def test_empty_command_returns_empty_output_and_seed():from tui_gateway import slash_worker- result = slash_worker._run(_FakeCLI(), "")- assert result == {"output": "", "seed": ""}+ cli = _FakeCLI()+ assert slash_worker._run(cli, "") == ""+ assert cli._harvested_seed == ""+++class _SeedingWorker:+ """String ``run()`` contract plus the seed carried out of band via ``pop_seed()``."""++ def __init__(self, *a, **kw):+ self._last_seed = ""++ def run(self, command):+ self._last_seed = "Composed in $EDITOR"+ return ""++ def pop_seed(self):+ seed, self._last_seed = self._last_seed, ""+ return seed++ def close(self):+ passdef test_slash_exec_routes_seed_as_send_dispatch(monkeypatch):@@ -65,17 +87,6 @@ def test_slash_exec_routes_seed_as_send_dispatch(monkeypatch):sid = "seed-sid"session = _live_session()server._sessions[sid] = session-- class _SeedingWorker:- def __init__(self, *a, **kw):- pass-- def run(self, command):- return ("", "Composed in $EDITOR")-- def close(self):- pass-monkeypatch.setattr(server, "_SlashWorker", _SeedingWorker)try:resp = server._methods["slash.exec"](1, {"session_id": sid, "command": "/prompt"})@@ -97,7 +108,7 @@ def test_slash_exec_plain_output_unchanged_when_no_seed(monkeypatch):passdef run(self, command):- return ("worker says hi", "")+ return "worker says hi"def close(self):passdiff --git a/tests/tui_gateway/test_slash_worker_ansi.py b/tests/tui_gateway/test_slash_worker_ansi.pyindex 410d365e0b6..3c061c4d756 100644--- a/tests/tui_gateway/test_slash_worker_ansi.py+++ b/tests/tui_gateway/test_slash_worker_ansi.py@@ -7,7 +7,6 @@ from __future__ import annotationsclass _FakeCLI:console = None- _pending_agent_seed = Nonedef process_command(self, cmd: str) -> None:import sys@@ -20,6 +19,5 @@ def test_run_strips_ansi_from_output():out = slash_worker._run(_FakeCLI(), "/anything")- assert "\x1b[" not in out["output"]- assert out["output"] == "colored plain"- assert out["seed"] == ""+ assert "\x1b[" not in out+ assert out == "colored plain"diff --git a/tests/tui_gateway/test_slash_worker_provider.py b/tests/tui_gateway/test_slash_worker_provider.pyindex 7fe89fb51a1..8b1409f3f62 100644--- a/tests/tui_gateway/test_slash_worker_provider.py+++ b/tests/tui_gateway/test_slash_worker_provider.py@@ -63,7 +63,7 @@ def test_slash_exec_spawns_with_the_live_agent_provider(monkeypatch):self.stderr_tail = []def run(self, command):- return "ok", ""+ return "ok"def close(self):passdiff --git a/tests/tui_gateway/test_tui_gateway_server.py b/tests/tui_gateway/test_tui_gateway_server.pyindex a75ee625bb8..25d7e1ee7b2 100644--- a/tests/tui_gateway/test_tui_gateway_server.py+++ b/tests/tui_gateway/test_tui_gateway_server.py@@ -11272,7 +11272,6 @@ def test_slash_exec_r7_read_commands_use_metadata_mirror_flag_on(monkeypatch):cases = {"usage": "140","history": "live question from state db",- "prompt": "host system prompt","status": "140","context": "Context usage: 80 / 1,000 tokens","tools": "terminal",@@ -14852,7 +14851,6 @@ def test_mirror_slash_side_effects_rejects_mutating_commands_while_running(monkefor cmd, expected_name in [("/model new/model", "model"),("/personality default", "personality"),- ("/prompt", "prompt"),("/compress", "compress"),]:warning = server._mirror_slash_side_effects("sid", session, cmd)diff --git a/tui_gateway/methods_tools.py b/tui_gateway/methods_tools.pyindex cd1a13464b1..bab934c0740 100644--- a/tui_gateway/methods_tools.py+++ b/tui_gateway/methods_tools.py@@ -1061,8 +1061,8 @@ def _(rid, params: dict) -> dict:except Exception as e:return _err(rid, 5030, f"slash worker start failed: {e}")try:- output, seed = worker.run(cmd)- if seed:+ output = worker.run(cmd)+ if seed := (worker.pop_seed() if hasattr(worker, "pop_seed") else ""):# /prompt//blueprint composed a next-turn prompt in the worker; route it as a# send dispatch (both Desktop and TUI clients already handle {type:"send"}).return _ok(rid, {"type": "send", "message": seed})diff --git a/tui_gateway/server.py b/tui_gateway/server.pyindex 66e1b5724d4..c4c6a75caca 100644--- a/tui_gateway/server.py+++ b/tui_gateway/server.py@@ -299,11 +299,12 @@ class _SlashWorker:if text := line.rstrip("\n"):self.stderr_tail = (self.stderr_tail + [text])[-80:]- def run(self, command: str) -> tuple[str, str]:- """Run one command → ``(output, seed)``.+ def run(self, command: str) -> str:+ """Run one command; return its output text.- ``seed`` is a next-turn prompt a command like /prompt parked on the worker's- CLI (``_pending_agent_seed``); empty for old workers that don't reply one.+ A command like /prompt may also have parked a next-turn prompt (a "seed")+ on the worker CLI; it rides back on the reply's ``seed`` field and is+ retrieved separately via ``pop_seed()``."""if self.proc.poll() is not None:raise RuntimeError("slash worker exited")@@ -323,10 +324,16 @@ class _SlashWorker:continueif not msg.get("ok"):raise RuntimeError(msg.get("error", "slash worker failed"))- return str(msg.get("output", "")).rstrip(), str(msg.get("seed", "") or "")+ self._last_seed = str(msg.get("seed", "") or "")+ return str(msg.get("output", "")).rstrip()raise RuntimeError(f"slash worker closed pipe{': ' + chr(10).join(self.stderr_tail[-8:]) if self.stderr_tail else ''}")+ def pop_seed(self) -> str:+ """Return and clear the seed from the last ``run()`` (empty when none)."""+ seed, self._last_seed = getattr(self, "_last_seed", ""), ""+ return seed+def close(self):if getattr(self, "_closed", False):returndiff --git a/tui_gateway/slash_worker.py b/tui_gateway/slash_worker.pyindex aaff46ef34c..b2507c7090e 100644--- a/tui_gateway/slash_worker.py+++ b/tui_gateway/slash_worker.py@@ -97,17 +97,18 @@ def _refuse_skill_slash(command: str) -> None:raise SkillSlashRefused(base)-def _run(cli: HermesCLI, command: str) -> dict:- """Run one command; return ``{"output", "seed"}``.+def _run(cli: HermesCLI, command: str) -> str:+ """Run one command; return its captured, ANSI-stripped output.- ``seed`` is the one-shot ``_pending_agent_seed`` a command like /prompt or- /blueprint parks for "run this as the next agent turn". The interactive REPL- loop consumes it (cli.py); this worker has no REPL, so the seed is harvested- here and routed back to the gateway, which sends it as the next turn (#107800).+ A command like /prompt or /blueprint parks the composed text on the one-shot+ ``_pending_agent_seed`` for the interactive REPL loop (cli.py) — but this+ worker has no REPL, so the seed is harvested here onto ``cli._harvested_seed``+ and routed back to the gateway, which sends it as the next turn (#107800)."""+ cli._harvested_seed = "" # one-shot: a fresh run never re-sends a stale seedcmd = (command or "").strip()if not cmd:- return {"output": "", "seed": ""}+ return ""_refuse_skill_slash(cmd)buf = io.StringIO()# Rich Console captures its file handle at construction, so redirect_stdout won't affect it; swap@@ -126,8 +127,8 @@ def _run(cli: HermesCLI, command: str) -> dict:# under the gateway's inherited COLORTERM) would leak raw escapes; strip at this single choke point.from tools.ansi_strip import strip_ansioutput = strip_ansi(buf.getvalue().rstrip())- seed, cli._pending_agent_seed = getattr(cli, "_pending_agent_seed", None) or "", None- return {"output": output, "seed": seed}+ cli._harvested_seed, cli._pending_agent_seed = getattr(cli, "_pending_agent_seed", None) or "", None+ return outputdef _sw_log(reason: str) -> None:@@ -176,8 +177,8 @@ def main():try:req = json.loads(line)rid = req.get("id")- result = _run(cli, req.get("command", ""))- _reply(id=rid, ok=True, output=result["output"], seed=result["seed"])+ output = _run(cli, req.get("command", ""))+ _reply(id=rid, ok=True, output=output, seed=getattr(cli, "_harvested_seed", "") or "")except Exception as e:_reply(id=rid, ok=False, error=str(e))finally: