The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): /agents reads the opened gateway session before the first turn
unsupportedpastels81263a12e574
diff --git a/hermes_cli/cli_init_mixin.py b/hermes_cli/cli_init_mixin.pyindex dbc918c774b..b7750127be3 100644--- a/hermes_cli/cli_init_mixin.py+++ b/hermes_cli/cli_init_mixin.py@@ -390,6 +390,8 @@ class CLIInitMixin:self._release_active_session()sid = store.open_session(self, launch)self._gateway_session_open = True+ from hermes_cli.gateway_tools import bind_session+ bind_session(self, store.connection) # the session's processes, before _init_agent's chat proxyif sid and sid != self.session_id:self.session_id = sidgetattr(self, "_write_terminal_breadcrumb", lambda: None)()diff --git a/hermes_cli/gateway_tools.py b/hermes_cli/gateway_tools.pyindex 00a1bdcd42e..7764fa149ff 100644--- a/hermes_cli/gateway_tools.py+++ b/hermes_cli/gateway_tools.py@@ -129,6 +129,18 @@ class GatewayProcessView:return value if isinstance(value, int) else 0+class _OpenedSession:+ """The CLI's open gateway session before any chat agent exists (``_init_agent`` builds that on the+ first turn): the view's ``connection`` and ``session_id``, following the CLI's id."""++ def __init__(self, cli, connection):+ self.cli, self.connection = cli, connection++ @property+ def session_id(self):+ return self.cli.session_id++def bind(agent):"""Called when the CLI's gateway-backed agent is built."""global _view@@ -136,6 +148,12 @@ def bind(agent):return _view+def bind_session(cli, connection):+ """Called when the CLI opens its gateway session, so ``/agents``, ``/stop``, the dock and the status+ bar read the session's processes before the first turn (a resumed session's work keeps running)."""+ return bind(_OpenedSession(cli, connection))++def mark_dirty():if _view is not None:_view.mark_dirty()diff --git a/tests/hermes_cli/test_gateway_tools.py b/tests/hermes_cli/test_gateway_tools.pyindex 978884a33f1..c428d3c89f6 100644--- a/tests/hermes_cli/test_gateway_tools.py+++ b/tests/hermes_cli/test_gateway_tools.py@@ -110,6 +110,29 @@ def test_agents_lists_the_gateway_sessions_processes_and_subagents(gateway, capsassert ("process.list", {"session_id": SID}) in client.calls+def test_agents_before_the_first_turn_reads_the_opened_sessions_processes(gateway, capsys):+ """A resumed session's background work runs on the gateway before this CLI's first turn builds+ its chat agent: opening the session binds the view, so /agents never reads the empty local+ registry (Greptile 4277259979)."""+ from cli import HermesCLI+ from hermes_cli.gateway_session_store import GatewaySessionStore++ class _ResumedStore(GatewaySessionStore):+ def open_session(self, cli, launch=None):+ return SID++ agent, client = gateway+ gateway_tools._view = None # no chat agent built yet+ cli = HermesCLI.__new__(HermesCLI)+ cli.session_id, cli._resumed, cli.enabled_toolsets = SID, True, ["terminal"]+ cli._session_db = _ResumedStore(agent.connection)+ cli._ensure_gateway_session()+ cli._handle_agents_command()+ out = capsys.readouterr().out+ assert "proc_1" in out and "sleep 300" in out+ assert ("process.list", {"session_id": SID}) in client.calls++def test_stop_typed_mid_turn_interrupts_the_turn_then_stops_processes(gateway, capsys):"""/stop typed while a turn runs is dispatched inline and interrupts it like Ctrl+C (tracker#134889 N4), instead of being queued until the turn it should stop has finished."""