The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(kanban): goal_mode workers keep the live tool feed in their worker log
teknium13187d68b49a9
diff --git a/cli.py b/cli.pyindex eff3d816c63..46889d5bfeb 100644--- a/cli.py+++ b/cli.py@@ -4034,10 +4034,12 @@ def _interrupt_agent_for_signal(agent, signum) -> None:pass # never block signal handling-def _run_kanban_goal_loop_q(cli: "HermesCLI", first_response: str) -> None:+def _run_kanban_goal_loop_q(cli: "HermesCLI", first_response: str, run_turn=None, log=None) -> None:"""Drive a kanban goal_mode worker through ``goals.run_kanban_goal_loop`` after its first turn.- The caller swallows all errors: a broken loop must never wedge a worker.+ ``run_turn`` defaults to the bare ``-Q`` turn (final answer only). The ``-q`` worker path+ passes ``cli.chat`` so every follow-up turn keeps the tool activity feed that the Kanban+ worker log is made of. The caller swallows all errors: a broken loop must never wedge a worker."""task_id = (os.environ.get("HERMES_KANBAN_TASK") or "").strip()if not task_id:@@ -4061,7 +4063,7 @@ def _run_kanban_goal_loop_q(cli: "HermesCLI", first_response: str) -> None:if not goal_text:return- def _run_turn(prompt: str) -> str:+ def _quiet_turn(prompt: str) -> str:result = cli.agent.run_conversation(user_message=prompt, conversation_history=cli.conversation_history)_sync_cli_session_id_from_agent(cli)resp = result.get("final_response", "") if isinstance(result, dict) else str(result)@@ -4078,12 +4080,25 @@ def _run_kanban_goal_loop_q(cli: "HermesCLI", first_response: str) -> None:_kb.block_task(c, task_id, reason=reason, expected_run_id=worker_run_id)_run_loop(- task_id=task_id, goal_text=goal_text, run_turn=_run_turn, task_status_fn=_task_status, block_fn=_block,+ task_id=task_id, goal_text=goal_text, run_turn=run_turn or _quiet_turn,+ task_status_fn=_task_status, block_fn=_block,max_turns=task.goal_max_turns or _DEF_TURNS, first_response=first_response or "",- log=lambda m: logger.info("%s", m),+ log=log or (lambda m: logger.info("%s", m)),)+def _run_kanban_goal_loop_chat(cli: "HermesCLI", first_response: str) -> None:+ """``-q`` worker variant: follow-up turns go through ``cli.chat`` (tool feed stays on stdout,+ which is the Kanban worker log) and judge verdicts are printed there too, so a goal_mode card's+ log reads like any other worker's instead of staying blank until the final answer."""++ def _log(msg: str) -> None:+ logger.info("%s", msg)+ print(msg, flush=True)++ _run_kanban_goal_loop_q(cli, first_response, run_turn=lambda p: cli.chat(p) or "", log=_log)++def _sync_cli_session_id_from_agent(cli) -> None:"""Keep ``cli.session_id`` in sync when mid-run compression rotated the agent's session."""if getattr(cli.agent, "session_id", None) and cli.agent.session_id != cli.session_id:@@ -4550,7 +4565,15 @@ def _run_single_query_mode(cli, query, image, quiet, oneshot, stream_json: boolif _query_label:cli.console.print(f"[bold blue]Query:[/] {_query_label}")cli._show_security_advisories()- cli.chat(query, images=single_query_images or None)+ response = cli.chat(query, images=single_query_images or None)+ # Kanban goal_mode on the `-q` path: same judge loop as `-Q`, but each follow-up turn+ # runs through cli.chat so the worker log keeps its live tool feed (the dispatcher+ # used to force -Q here, which left goal_mode cards with a blank Worker log).+ if os.environ.get("HERMES_KANBAN_GOAL_MODE") == "1":+ try:+ _run_kanban_goal_loop_chat(cli, response or "")+ except Exception as _goal_exc:+ logger.debug("kanban goal loop failed: %s", _goal_exc)cli._print_exit_summary(clear_screen=False)# Same exit contract as `-Q`: scripts and the Kanban dispatcher read the outcome from# the exit code. This path used to fall through to an implicit 0 for every outcome.diff --git a/hermes_cli/kanban_db_dispatch.py b/hermes_cli/kanban_db_dispatch.pyindex ba561f56aff..bb1fd931868 100644--- a/hermes_cli/kanban_db_dispatch.py+++ b/hermes_cli/kanban_db_dispatch.py@@ -2461,11 +2461,8 @@ def _worker_argv(task: Task, profile_arg: str, hermes_home: Optional[str]) -> liif worker_toolsets:cmd.extend(["--toolsets", ",".join(worker_toolsets)])cmd.extend(["chat", "-q", f"work kanban task {task.id}"])- if task.goal_mode:- # The kanban goal-loop hook only runs in cli.py's fully-quiet branch.- # Without -Q the worker gets one turn, prints text, exits rc=0, and the- # dispatcher records a protocol violation.- cmd.append("-Q")+ # goal_mode rides the same `-q` path: cli.py runs the judge loop there too, so the+ # worker log keeps its live tool feed (forcing -Q blanked it).return cmddiff --git a/tests/hermes_cli/test_kanban_goal_mode_worker_log.py b/tests/hermes_cli/test_kanban_goal_mode_worker_log.pynew file mode 100644index 00000000000..11559574ee1--- /dev/null+++ b/tests/hermes_cli/test_kanban_goal_mode_worker_log.py@@ -0,0 +1,91 @@+"""A goal_mode Kanban worker keeps the live tool feed in its worker log.++The dispatcher used to force ``-Q`` on goal_mode cards because the judge loop only ran in+cli.py's fully-quiet branch; ``-Q`` strips every tool callback, so the dashboard's Worker log+stayed blank for the whole run while non-goal cards logged normally (Discord report, Sep 2026).+The loop now also runs on the ``-q`` path, driving follow-up turns through ``cli.chat``.+"""++from __future__ import annotations++from types import SimpleNamespace++import cli+from hermes_cli import goals+from hermes_cli import kanban_db_dispatch as dispatch+from hermes_cli.kanban_db import Task+++def _task(**overrides) -> Task:+ base = dict(+ id="t_goal1", title="ship it", body="acceptance: tests pass", assignee="worker",+ status="running", priority=0, created_by=None, created_at=1, started_at=None,+ completed_at=None, workspace_kind="scratch", workspace_path=None,+ claim_lock=None, claim_expires=None, tenant=None,+ )+ base.update(overrides)+ return Task(**base)+++def test_goal_mode_worker_takes_the_same_stdout_rich_path_as_a_one_shot_worker(monkeypatch):+ monkeypatch.setattr(dispatch, "_resolve_hermes_argv", lambda: ["hermes"])+ monkeypatch.setattr(dispatch, "_resolve_worker_cli_toolsets", lambda home: None)+ plain = dispatch._worker_argv(_task(goal_mode=False), "worker", None)+ goal = dispatch._worker_argv(_task(goal_mode=True), "worker", None)+ # The mode travels in HERMES_KANBAN_GOAL_MODE; the argv must not opt the worker out of+ # the tool feed that the Worker log is made of.+ assert goal == plain+ assert "-Q" not in goal+++def test_non_quiet_one_shot_runs_the_goal_loop_through_cli_chat(monkeypatch):+ monkeypatch.setenv("HERMES_KANBAN_TASK", "t_goal1")+ monkeypatch.setenv("HERMES_KANBAN_GOAL_MODE", "1")+ monkeypatch.setattr(cli, "_should_seed_interactive", lambda *a, **k: False)+ monkeypatch.setattr(cli, "_collect_query_images", lambda q, i: (q, []))+ monkeypatch.setattr(cli, "_collect_kanban_task_images", lambda imgs: [])+ monkeypatch.setattr(cli, "_finalize_single_query", lambda c: None)++ class _Conn:+ def __enter__(self):+ return self++ def __exit__(self, *a):+ return False++ monkeypatch.setattr("hermes_cli.kanban_db_connect.connect_closing", lambda: _Conn())+ monkeypatch.setattr("hermes_cli.kanban_db.get_task", lambda conn, tid: _task(goal_mode=True))++ def _fake_loop(*, run_turn, first_response, log, **_kw):+ # One continuation turn: it must go through cli.chat (tool feed on stdout), and the+ # verdict line must reach stdout too, not only agent.log.+ assert first_response == "first answer"+ assert run_turn("keep going") == "second answer"+ log("kanban goal loop: turn 1/20 verdict=continue reason=x")+ return {"turns": 1}++ monkeypatch.setattr(goals, "run_kanban_goal_loop", _fake_loop)++ chats: list[str] = []++ def _chat(message, images=None):+ chats.append(message)+ return "first answer" if len(chats) == 1 else "second answer"++ stub = SimpleNamespace(+ _single_query_mode=False,+ _claim_active_session=lambda *a, **k: True,+ console=SimpleNamespace(print=lambda *a, **k: None),+ _show_security_advisories=lambda: None,+ chat=_chat,+ _print_exit_summary=lambda **k: None,+ _last_turn_result={"final_response": "second answer", "completed": True},+ )+ printed: list[str] = []+ monkeypatch.setattr("builtins.print", lambda *a, **k: printed.append(" ".join(str(x) for x in a)))+ try:+ cli._run_single_query_mode(stub, "work kanban task t_goal1", None, False, True)+ except SystemExit as exc:+ assert exc.code == 0+ assert chats == ["work kanban task t_goal1", "keep going"]+ assert any("verdict=continue" in line for line in printed)diff --git a/website/docs/user-guide/features/kanban.md b/website/docs/user-guide/features/kanban.mdindex 4c258163326..203a194dda8 100644--- a/website/docs/user-guide/features/kanban.md+++ b/website/docs/user-guide/features/kanban.md@@ -632,6 +632,8 @@ hermes kanban create "Translate the docs site to French" \Use it for open-ended, multi-step, or "keep going until X is true" cards. Skip it for cheap one-shot work — the per-turn judge overhead isn't worth it, and the dispatcher's existing retry/circuit-breaker already handles transient worker failures. The judge is only as good as your goal text, so write the body as **explicit acceptance criteria**.+A goal-mode worker's **Worker log** (dashboard drawer, `hermes kanban log <id>`) carries the same live tool feed as any other worker's, plus one `kanban goal loop: turn N/M verdict=…` line per judged turn, so you can follow what the loop is doing while the card is running.+:::note Goal-mode cards borrow the `/goal` engine — they don't connect to it`--goal` runs the continuation loop *inside that one card's worker session*. It shares the engine with the [`/goal` slash command](./goals), not the state: setting a `/goal` in a chat session never creates, claims, or moves a kanban card, and a goal-mode card's loop is invisible to any chat session's `/goal status`. If you want this conversation to keep iterating, use [`/goal`](./goals); if you want work on the board, create a card.:::