The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(kanban): attribute worker turns to the dispatcher, not the operator
calvinnwqeb1d54ad76af
diff --git a/hermes_cli/cli_chat_turn_mixin.py b/hermes_cli/cli_chat_turn_mixin.pyindex e49e32f8cd0..bdf19d2373c 100644--- a/hermes_cli/cli_chat_turn_mixin.py+++ b/hermes_cli/cli_chat_turn_mixin.py@@ -334,6 +334,11 @@ class CLIChatTurnMixin:_persist_clean_user_message = message if (turn.voice_prefix or agent_message != message) else None_one_turn_model_restore = getattr(self, "_pending_one_turn_model_restore", None)self._pending_one_turn_model_restore = None+ # Set only by a dispatcher-spawned `-q` run; a human turn keeps today's call shape.+ from agent.interrupt_compat import _accepts_keyword+ _author = getattr(self, "_single_query_turn_author", None)+ _author_kwargs = ({"turn_author": _author}+ if _author is not None and _accepts_keyword(self.agent.run_conversation, "turn_author") else {})try:from agent.notification_presentation import notification_turnmuted = getattr(turn, "mute_notification_reply", False)@@ -343,6 +348,7 @@ class CLIChatTurnMixin:conversation_history=self.conversation_history[:-1],stream_callback=None if muted else turn.stream_callback, task_id=self.session_id,persist_user_message=_persist_clean_user_message, moa_config=_moa_cfg,+ **_author_kwargs,)if getattr(self, "_pending_moa_disable_after_turn", False):_restore = getattr(self, "_pending_moa_restore_model", None) or {}diff --git a/hermes_cli/cli_single_query.py b/hermes_cli/cli_single_query.pyindex 5b31b23b96c..17035db5b9b 100644--- a/hermes_cli/cli_single_query.py+++ b/hermes_cli/cli_single_query.py@@ -546,6 +546,11 @@ def _run_single_query_mode(cli, query, image, quiet, oneshot, stream_json: boolif _query_label:cli.console.print(f"[bold blue]{t('cli.single_query.query_label')}[/] {_query_label}")cli._show_security_advisories()+ # Same author contract as `-Q`: a dispatcher (the Kanban worker spawn) names who wrote this run's+ # prompts. Consumed before the first turn so tool subprocesses never inherit it; every turn of+ # the run (recovery and goal follow-ups included) carries it to memory providers.+ from agent.turn_author import take_turn_author_from_env+ cli._single_query_turn_author = take_turn_author_from_env()response = cli.chat(query, images=single_query_images or None)# Kanban worker: a failed-silently turn used to end the run as rc=0 with no# terminal kanban call, so the dispatcher booked a protocol violation anddiff --git a/hermes_cli/kanban_db_dispatch.py b/hermes_cli/kanban_db_dispatch.pyindex e25346e58dd..393a8c0f273 100644--- a/hermes_cli/kanban_db_dispatch.py+++ b/hermes_cli/kanban_db_dispatch.py@@ -2814,10 +2814,10 @@ def _default_spawn(task: Task, workspace: str, *, board: Optional[str] = None) -# Tag the session `kanban` so session-browsing surfaces filter it out by# source instead of rendering one sidebar row per attempt.env["HERMES_SESSION_SOURCE"] = "kanban"- # TERMINAL_CWD takes precedence over process cwd in file_tools and- # build_context_files_prompt; without it relative writes land in the gateway- # user's home and workers load the gateway's AGENTS.md. file_tools rejects- # relative / sentinel values, so only set a real absolute directory.+ # The worker's prompts are this dispatcher's, not the operator's: a bot author keeps memory+ # providers from filing "work kanban task t_..." and the worker's reply under the human's peer.+ from agent.turn_author import bot_author_id, turn_author_env+ env.update(turn_author_env({"id": bot_author_id("kanban"), "name": "Kanban dispatcher", "is_bot": True}))# Pin TERMINAL_CWD to the task's workspace so the worker's file tools and context-file loader anchor on# the workspace, not whatever cwd the dispatching gateway happened to export. The worker subprocess is# already launched with cwd=workspace, but TERMINAL_CWD takes precedence over the process cwd in bothdiff --git a/tests/hermes_cli/test_kanban_worker_turn_author.py b/tests/hermes_cli/test_kanban_worker_turn_author.pynew file mode 100644index 00000000000..c1252e7e52a--- /dev/null+++ b/tests/hermes_cli/test_kanban_worker_turn_author.py@@ -0,0 +1,111 @@+"""A Kanban worker's turns are authored by the dispatcher, not the operator.++The dispatcher spawns ``hermes chat -q "work kanban task <id>"``. Without an author, memory providers+filed that prompt and the worker's reply under the human's peer ("the user mentioned kanban task+t_..."). The spawn now names a bot author and the non-quiet one-shot path forwards it to every turn,+the same contract the quiet path and Bot Mode deliveries already follow.+"""++from __future__ import annotations++import os+import subprocess+from types import SimpleNamespace+from unittest.mock import Mock++import pytest++import cli+from agent.turn_author import TURN_AUTHOR_ENV, parse_turn_author+++def _task(kb):+ return kb.Task(+ id="t_author", title="author", body=None, assignee="elias", status="running", priority=0,+ created_by="test", created_at=1, started_at=None, completed_at=None, workspace_kind="dir",+ workspace_path=None, claim_lock="lock", claim_expires=None, tenant=None, current_run_id=3,+ )+++def test_worker_spawn_names_the_dispatcher_as_a_bot_author(monkeypatch, tmp_path):+ root = tmp_path / ".hermes"+ (root / "profiles" / "elias").mkdir(parents=True)+ root.joinpath("config.yaml").write_text("{}\n", encoding="utf-8")+ monkeypatch.setenv("HERMES_HOME", str(root))+ monkeypatch.setenv(TURN_AUTHOR_ENV, '{"id": "operator", "name": "human", "is_bot": false}')++ from hermes_cli import kanban_db as kb+ from hermes_cli import kanban_db_dispatch as kbd++ monkeypatch.setattr(kbd, "_resolve_hermes_argv", lambda: ["hermes"])+ captured = {}++ def fake_popen(cmd, *args, **kwargs):+ captured["env"] = dict(kwargs.get("env") or {})+ return SimpleNamespace(pid=4321)++ monkeypatch.setattr(subprocess, "Popen", fake_popen)+ workspace = tmp_path / "workspace"+ workspace.mkdir()+ kbd._default_spawn(_task(kb), str(workspace))++ author = parse_turn_author(captured["env"].get(TURN_AUTHOR_ENV))+ assert author is not None and author["is_bot"] is True+ assert author["id"].startswith("bot:")+++def _one_shot_cli(monkeypatch):+ """A real HermesCLI whose ``chat`` runs the real agent-thread body against a recording agent."""+ monkeypatch.delenv("HERMES_KANBAN_TASK", raising=False)+ monkeypatch.delenv("HERMES_KANBAN_GOAL_MODE", raising=False)+ 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)++ calls = []++ def run_conversation(**kwargs):+ calls.append({**kwargs, "env_author": os.environ.get(TURN_AUTHOR_ENV)})+ return {"final_response": "done"}++ the_cli = cli.HermesCLI.__new__(cli.HermesCLI)+ the_cli.session_id = "s-1"+ the_cli.conversation_history = [{"role": "user", "content": "work kanban task t_author"}]+ the_cli.agent = SimpleNamespace(run_conversation=Mock(side_effect=run_conversation))+ the_cli._flush_credit_notices = lambda: None+ the_cli._single_query_mode = False+ the_cli._claim_active_session = lambda *a, **k: True+ the_cli.console = SimpleNamespace(print=lambda *a, **k: None)+ the_cli._show_security_advisories = lambda: None+ the_cli._print_exit_summary = lambda **k: None+ the_cli._last_turn_result = {"failed": False}++ def chat(message, images=None):+ the_cli._chat_run_agent(cli._ChatTurn(), message)+ return "done"++ the_cli.chat = chat+ return the_cli, calls+++def test_dispatcher_author_reaches_the_worker_turn_and_is_consumed(monkeypatch):+ monkeypatch.setenv(TURN_AUTHOR_ENV, '{"id": "bot:kanban", "name": "Kanban dispatcher", "is_bot": true}')+ the_cli, calls = _one_shot_cli(monkeypatch)+ with pytest.raises(SystemExit):+ cli._run_single_query_mode(the_cli, "work kanban task t_author", None, False, True)++ assert len(calls) == 1+ assert calls[0]["turn_author"] == {"id": "bot:kanban", "name": "Kanban dispatcher", "is_bot": True}+ # Tool subprocesses started during the turn must not inherit the dispatcher's author.+ assert calls[0]["env_author"] is None+++def test_human_one_shot_keeps_an_unattributed_turn(monkeypatch):+ monkeypatch.delenv(TURN_AUTHOR_ENV, raising=False)+ the_cli, calls = _one_shot_cli(monkeypatch)+ with pytest.raises(SystemExit):+ cli._run_single_query_mode(the_cli, "hello", None, False, True)++ assert len(calls) == 1+ assert "turn_author" not in calls[0]