The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): /plan, /learn, /init acknowledge on the turn's paint channel (main's order)
Teknium1eb3868ef127
diff --git a/hermes_cli/cli_commands_mixin.py b/hermes_cli/cli_commands_mixin.pyindex c82d65931d9..b189e7eb2bc 100644--- a/hermes_cli/cli_commands_mixin.py+++ b/hermes_cli/cli_commands_mixin.py@@ -1604,9 +1604,12 @@ class CLICommandsMixin(CLICommandsSessionToolsMixin):_save(f"{subsystem}.write_approval", bool(enabled))# ---- prompt-queueing handlers: /learn, /plan, /init ------------------------------------ def _queue_prompt_turn(self, msg: str, command: str) -> None:+ def _queue_prompt_turn(self, msg: str, command: str, ack: str = "") -> None:"""Inject ``msg`` onto the agent's input queue as the next normal user turn (the- /learn, /plan, /init pattern: no engine, no model-tool footprint, prompt-cache safe)."""+ /learn, /plan, /init pattern: no engine, no model-tool footprint, prompt-cache safe). ``ack``+ paints first on the turn's own channel (_cprint), so the turn's `────` never overtakes it."""+ if ack:+ __import__("cli")._cli_visible_print("\n" + ack)if hasattr(self, "_pending_input"):self._pending_input.put(msg)else: # pragma: no cover - defensive (no live input loop)@@ -1618,16 +1621,14 @@ class CLICommandsMixin(CLICommandsSessionToolsMixin):tools it already has and authors the skill via ``skill_manage``."""from agent.learn_prompt import build_learn_promptuser_request = _command_arg(cmd)- print("\n" + _t("learn.from_description" if user_request else "learn.from_conversation"))- self._queue_prompt_turn(build_learn_prompt(user_request), "/learn")+ self._queue_prompt_turn(build_learn_prompt(user_request), "/learn", _t("learn.from_description" if user_request else "learn.from_conversation"))def _handle_plan_command(self, cmd: str):"""Handle /plan — write a markdown implementation plan, no execution. The live agentinspects the workspace read-only and saves the plan under ``.hermes/plans/``."""from agent.plan_prompt import build_plan_prompttask = _command_arg(cmd) # optional — empty infers the task from conversation context- print("\n" + (_t("plan.planning", task=_ellipsize(task, 80)) if task else _t("plan.from_conversation")))- self._queue_prompt_turn(build_plan_prompt(task), "/plan")+ self._queue_prompt_turn(build_plan_prompt(task), "/plan", _t("plan.planning", task=_ellipsize(task, 80)) if task else _t("plan.from_conversation"))def _handle_init_command(self, cmd: str):"""Handle /init — generate or update AGENTS.md from a project scan performed by the@@ -1636,8 +1637,7 @@ class CLICommandsMixin(CLICommandsSessionToolsMixin):# session_key="" targets the single-session CLI's "default" cwd record, which tracks# `cd` and workspace switches, so /init follows the directory the user works in.msg = build_init_prompt_for_cwd(extra=_command_arg(cmd), session_key="") # optional user emphasis- print("\n" + _t("init.updating" if "UPDATE the existing AGENTS.md" in msg else "init.generating"))- self._queue_prompt_turn(msg, "/init")+ self._queue_prompt_turn(msg, "/init", _t("init.updating" if "UPDATE the existing AGENTS.md" in msg else "init.generating"))# ---- side-session handlers: /bg, /btw -------------------------------------------------def _handle_background_command(self, cmd: str):diff --git a/tests/hermes_cli/test_prompt_turn_ack_order.py b/tests/hermes_cli/test_prompt_turn_ack_order.pynew file mode 100644index 00000000000..e8d4536dd07--- /dev/null+++ b/tests/hermes_cli/test_prompt_turn_ack_order.py@@ -0,0 +1,36 @@+"""/plan, /learn, /init acknowledge on the same paint channel as the turn they queue.++Main prints the acknowledgement, then the queued turn paints its ``────`` separator. A bare+``print`` under patch_stdout is flushed by the proxy's writer thread after its batching sleep,+while the separator is a ``_cprint`` on the app loop, so a fast turn start painted the separator+first. Both on ``_cprint`` keeps main's order whatever the turn's start latency."""+import queue+import types++import pytest++[email protected](("handler", "arg", "needle"), [+ ("_handle_plan_command", "/plan a tiny plan", "a tiny plan"),+ ("_handle_learn_command", "/learn the deploy flow", None),+ ("_handle_init_command", "/init", None),+])+def test_prompt_turn_ack_paints_through_cprint_before_the_turn_is_queued(handler, arg, needle, monkeypatch, capsys):+ import cli+ from hermes_cli.cli_commands_mixin import CLICommandsMixin+ events = []+ monkeypatch.setattr(cli, "_pt_app_is_running", lambda: True)+ monkeypatch.setattr(cli, "_cprint", lambda text: events.append(("paint", text)))++ class Q(queue.Queue):+ def put(self, item, *a, **k):+ events.append(("queued", None))+ super().put(item, *a, **k)+ host = types.SimpleNamespace(_pending_input=Q())+ host._queue_prompt_turn = lambda *a: CLICommandsMixin._queue_prompt_turn(host, *a)+ getattr(CLICommandsMixin, handler)(host, arg)+ assert capsys.readouterr().out == "" # nothing through the patch_stdout proxy+ assert [kind for kind, _ in events] == ["paint", "queued"]+ assert events[0][1].startswith("\n")+ if needle:+ assert needle in events[0][1]