The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): /yolo, /verbose and /reasoning <level> change the gateway session, not only the screen
Teknium4a82d388feee
diff --git a/hermes_cli/gateway_agent.py b/hermes_cli/gateway_agent.pyindex c410f449e03..1c9313bd523 100644--- a/hermes_cli/gateway_agent.py+++ b/hermes_cli/gateway_agent.py@@ -90,8 +90,6 @@ class GatewayAgent:self.api_key = None # never on this side of the wireself.max_iterations = max_iterationsself.quiet_mode = quiet_mode- self.tool_progress_mode = tool_progress_mode- self.reasoning_config = reasoning_configself.service_tier = service_tierself.clarify_callback = clarify_callbackself.connection_callback = connection_callback@@ -150,6 +148,12 @@ class GatewayAgent:self._interrupt_sent_at = Noneself._rate_limit_state = Noneself._config_context_length = None+ # Session-scope settings the gateway applies (its turn renders tools in this mode, its agent asks+ # for this effort): written once main's rebuilt agent is ready, then on every change.+ self._tool_progress_mode = "all"+ self.tool_progress_mode = tool_progress_mode+ self._reasoning_config = None+ self.reasoning_config = reasoning_configself._apply_info(self._state().info)self.reasoning_callback = reasoning_callbackstate = self._state()@@ -179,6 +183,48 @@ class GatewayAgent:returnself._show_reasoning_sent = wanted+ # -- session-scope settings ------------------------------------------------------------------+ @property+ def tool_progress_mode(self):+ return self._tool_progress_mode++ @tool_progress_mode.setter+ def tool_progress_mode(self, mode):+ """``/verbose`` / ``/focus``: ``config.set verbose`` with the explicit mode (never ``cycle``, which+ could drift from the CLI's own cycle)."""+ if mode == self._tool_progress_mode or mode not in {"off", "new", "all", "verbose"}:+ self._tool_progress_mode = mode+ return+ self._tool_progress_mode = mode+ try:+ self.connection.call("config.set", session_id=self.session_id, key="verbose", value=mode)+ except GatewayClientError as exc:+ logger.debug("config.set verbose failed: %s", exc)++ @property+ def reasoning_config(self):+ return self._reasoning_config++ @reasoning_config.setter+ def reasoning_config(self, config):+ """``/reasoning <level>`` (session scope; main rebuilds its agent with the new config) and /new's+ re-derived effort: ``session.mutate reasoning`` when it differs from the session's effort."""+ self._reasoning_config = config+ effort = _effort_word(config)+ if effort is None:+ return+ info = self._state().info or {}+ if info.get("reasoning_effort") == effort:+ return+ try:+ snapshot = self.connection.call("session.resume", session_id=self.session_id)+ self.connection.call("session.mutate", session_id=self.session_id, request_id=uuid.uuid4().hex,+ expected_revision=snapshot["revision"], operation="reasoning",+ payload={"effort": effort})+ info["reasoning_effort"] = effort+ except (GatewayClientError, KeyError, TypeError) as exc:+ logger.debug("session.mutate reasoning failed: %s", exc)+# -- session identity ----------------------------------------------------------------------@propertydef session_id(self):@@ -835,6 +881,16 @@ class GatewayAgent:self.apply_session_usage(usage)+def _effort_word(config):+ """The ``session.mutate reasoning`` effort for main's ``reasoning_config`` dict (None: no override)."""+ if not isinstance(config, dict):+ return None+ if config.get("enabled") is False:+ return "none"+ effort = config.get("effort")+ return effort if isinstance(effort, str) and effort else None++def _rate_limit_state(data):"""``get_rate_limit_state()`` rebuilt from its serialized dict (None stays None)."""if not isinstance(data, dict):diff --git a/hermes_cli/gateway_session_store.py b/hermes_cli/gateway_session_store.pyindex f144fbc30e8..759b69abcc1 100644--- a/hermes_cli/gateway_session_store.py+++ b/hermes_cli/gateway_session_store.py@@ -224,6 +224,11 @@ class GatewaySessionStore:live_text=live_text if live_text is not None else flatten_message_text(live_view.get("content")),rewound_count=int(receipt.get("rewound_count") or 0), turns_undone=len(durable_user) - user_ordinal)+ def set_session_yolo(self, session_id, enabled):+ """Main's ``/yolo`` persist hook: the gateway session's own bypass (``config.set yolo``, persisted+ on the route), since approvals run there. The CLI's in-process flag stays main's display state."""+ self.call("config.set", session_id=session_id, key="yolo", value="1" if enabled else "0")+def _title_holder(self, session_id, title):db = self._db()if db is None or not title:diff --git a/tests/hermes_cli/test_gateway_agent.py b/tests/hermes_cli/test_gateway_agent.pyindex 5be00d1bf1c..bfb6b61b64e 100644--- a/tests/hermes_cli/test_gateway_agent.py+++ b/tests/hermes_cli/test_gateway_agent.py@@ -37,6 +37,8 @@ class FakeClient:return {"admission_id": "adm-1", "status": "queued", "execution_generation": 7}if method == "prompt.receipt":return {"admission_id": "adm-1", "status": "terminal", "result": self.result, "usage": self.usage}+ if method == "session.resume":+ return {"session_id": params["session_id"], "revision": 1, "execution_generation": 7, "messages": []}if method == "session.interrupt":if self.on_interrupt:await self.events.put(self.on_interrupt)@@ -594,3 +596,35 @@ def test_voice_turn_flag_rides_prompt_submit(make_agent):agent._voice_turn_pending = Falseagent.run_conversation("typed")assert "voice_turn" not in dict(client.calls)["prompt.submit"]+++def test_verbose_mode_reaches_the_gateway_session(make_agent):+ """``/verbose`` / ``/focus`` write ``agent.tool_progress_mode``: the gateway renders tool events in+ that mode (``config.set verbose`` with the explicit mode, never ``cycle``)."""+ agent, client = make_agent([])+ agent.tool_progress_mode = "verbose"+ agent.tool_progress_mode = "verbose"+ agent.tool_progress_mode = "off"+ sets = [p for m, p in client.calls if m == "config.set"]+ assert sets == [{"session_id": SID, "key": "verbose", "value": "verbose"},+ {"session_id": SID, "key": "verbose", "value": "off"}]+++def test_a_non_default_verbose_mode_is_sent_when_the_agent_is_built(make_agent):+ agent, client = make_agent([], tool_progress_mode="new")+ assert {"session_id": SID, "key": "verbose", "value": "new"} in [p for m, p in client.calls if m == "config.set"]+++def test_reasoning_level_change_is_the_session_reasoning_mutation(make_agent):+ """``/reasoning high`` sets ``reasoning_config`` and rebuilds the agent: the rebuilt agent commits+ the effort as ``session.mutate reasoning`` (session scope, as main's), once."""+ agent, client = make_agent([], reasoning_config={"enabled": True, "effort": "high"})+ mut = [p for m, p in client.calls if m == "session.mutate"]+ assert len(mut) == 1 and mut[0]["operation"] == "reasoning" and mut[0]["payload"] == {"effort": "high"}+ agent.reasoning_config = {"enabled": False}+ mut = [p for m, p in client.calls if m == "session.mutate"]+ assert mut[-1]["payload"] == {"effort": "none"}+ agent.connection.state(SID).info["reasoning_effort"] = "none"+ agent2 = GatewayAgent(connection=agent.connection, session_id=SID, reasoning_config={"enabled": False})+ assert len([p for m, p in client.calls if m == "session.mutate"]) == 2 # already the session's effort+ assert agent2.reasoning_config == {"enabled": False}diff --git a/tests/hermes_cli/test_gateway_session_store.py b/tests/hermes_cli/test_gateway_session_store.pyindex 62e511931fc..2be11e8af24 100644--- a/tests/hermes_cli/test_gateway_session_store.py+++ b/tests/hermes_cli/test_gateway_session_store.py@@ -385,3 +385,15 @@ def test_verbose_flag_rides_session_create():from hermes_cli.gateway_session_store import _creation_policyassert _creation_policy({"verbose": True})["verbose"] is Trueassert "verbose" not in _creation_policy({"verbose": None})+++def test_yolo_toggle_persists_as_the_gateway_session_yolo(store):+ """Main's ``/yolo`` persist hook (``db.set_session_yolo``) is the gateway's ``config.set yolo`` with an+ explicit value: approvals run in the gateway, so its bypass is the one that matters."""+ db, client = store+ db.open_session(cli("local-old", resumed=True))+ db.set_session_yolo("local-old", True)+ db.set_session_yolo("local-old", False)+ sets = [p for m, p in client.calls if m == "config.set"]+ assert sets == [{"session_id": "local-old", "key": "yolo", "value": "1"},+ {"session_id": "local-old", "key": "yolo", "value": "0"}]