The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): set a branch's /yolo on the gateway before showing it locally
unsupportedpastels41e280bfcc36
diff --git a/hermes_cli/cli_commands_mixin.py b/hermes_cli/cli_commands_mixin.pyindex 9783aacb1d4..fb8877b37d1 100644--- a/hermes_cli/cli_commands_mixin.py+++ b/hermes_cli/cli_commands_mixin.py@@ -1094,22 +1094,22 @@ class CLICommandsMixin(CLICommandsSessionToolsMixin):from gateway.slash_commands_branch_thread import parse_branch_args_, branch_name = parse_branch_args(_command_arg(cmd_original))now = datetime.now()- new_session_id = self._new_session_id(now, branch_of=self.session_id) # the gateway's branch child- branch_title = branch_name or self._session_db.get_next_title_in_lineage(- self._session_db.get_session_title(self.session_id) or "branch")- parent_session_id = self.session_id- # Create the child BEFORE ending the parent: a failed create_session must leave the session the- # user is still on open, not ended with end_reason="branched" and no branch (#11030).+ from tools.approval_yolo import transfer_session_yolo, with_session_yolo+ # Create the child BEFORE ending the parent: a failed create_session or gateway branch (or its /yolo+ # carry) must leave the session the user is still on open, not ended "branched" with no branch (#11030).# The stable ``_branched_from`` marker keeps the branch visible in /resume + /sessions even after the# parent is re-ended with a different end_reason; with_session_yolo keeps a live /yolo on the branch.- # The child sends the parent's exact system prompt: a row without one makes the branch's first turn rebuild- # (re-probing the workspace), losing the copied transcript's warm cache whenever the repo moved since.- parent_prompt = getattr(self.agent, "_cached_system_prompt", None)- if not isinstance(parent_prompt, str) or not parent_prompt:- with suppress(Exception):- parent_prompt = (self._session_db.get_session(parent_session_id) or {}).get("system_prompt")- from tools.approval_yolo import transfer_session_yolo, with_session_yolo+ # The child sends the parent's exact system prompt: a row without one makes the branch's first turn+ # rebuild (re-probing the workspace), losing the copied transcript's warm cache if the repo moved since.try:+ new_session_id = self._new_session_id(now, branch_of=self.session_id) # the gateway's branch child+ branch_title = branch_name or self._session_db.get_next_title_in_lineage(+ self._session_db.get_session_title(self.session_id) or "branch")+ parent_session_id = self.session_id+ parent_prompt = getattr(self.agent, "_cached_system_prompt", None)+ if not isinstance(parent_prompt, str) or not parent_prompt:+ with suppress(Exception):+ parent_prompt = (self._session_db.get_session(parent_session_id) or {}).get("system_prompt")self._session_db.create_session(session_id=new_session_id, source=os.environ.get("HERMES_SESSION_SOURCE", "cli"),model=self.model, parent_session_id=parent_session_id, system_prompt=parent_prompt or None,diff --git a/hermes_cli/cli_init_mixin.py b/hermes_cli/cli_init_mixin.pyindex d2d7492eb89..08814dc1fb9 100644--- a/hermes_cli/cli_init_mixin.py+++ b/hermes_cli/cli_init_mixin.py@@ -439,10 +439,12 @@ class CLIInitMixin:child = store.branch(branch_of, title)# Main's with_session_yolo: a live /yolo carries onto the branch. The gateway's child starts# without the parent's toggle, so set it there too (/branch moves the CLI's own flag over).- from tools.approval import is_session_yolo_enabled+ # Approvals run on the gateway, so this write is not toggle_session_yolo's best-effort persist:+ # a failure raises before the child shows YOLO locally.+ from tools.approval import enable_session_yolo, is_session_yolo_enabledif is_session_yolo_enabled(branch_of):- from tools.approval_yolo import toggle_session_yolo- toggle_session_yolo(child, True, persist=lambda on: store.set_session_yolo(child, on))+ store.set_session_yolo(child, True)+ enable_session_yolo(child)return child# The run's other launch flags hold for every session it opens, as main's one AIAgent did across /new.launch = {key: value for key, value in _gateway_launch(self).items() if key not in _ROUTE_FLAGS}diff --git a/tests/hermes_cli/test_branch_command.py b/tests/hermes_cli/test_branch_command.pyindex 745f17e572f..d04ba1bb640 100644--- a/tests/hermes_cli/test_branch_command.py+++ b/tests/hermes_cli/test_branch_command.py@@ -84,6 +84,22 @@ class TestBranchCommandCLI:row = session_db.get_session(original)assert row["end_reason"] is None and row["ended_at"] is None+ def test_gateway_refusal_is_reported_and_leaves_the_session(self, cli_instance, session_db, capsys):+ """A gateway /branch step that fails (e.g. the child's YOLO could not be set, CLI-20) prints+ main's branch error and keeps the user on the original session, never a traceback."""+ from cli import HermesCLI+ from hermes_cli.gateway_client import GatewayClientError++ def refused(now, **kw):+ raise GatewayClientError("Gateway did not answer config.set")+ cli_instance._new_session_id = refused+ original = cli_instance.session_id+ HermesCLI._handle_branch_command(cli_instance, "/branch")++ assert cli_instance.session_id == original+ assert "Gateway did not answer config.set" in capsys.readouterr().out+ assert session_db.get_session(original)["end_reason"] is None+def test_branch_copies_history(self, cli_instance, session_db):"""Branching should copy all messages to the new session."""from cli import HermesCLIdiff --git a/tests/hermes_cli/test_gateway_session_store.py b/tests/hermes_cli/test_gateway_session_store.pyindex b0d24c2d8f6..04840c80475 100644--- a/tests/hermes_cli/test_gateway_session_store.py+++ b/tests/hermes_cli/test_gateway_session_store.py@@ -589,3 +589,32 @@ def test_branch_carries_a_live_yolo_onto_the_gateway_child(store):for key in ("local-old", plain, "local-child"):approval.disable_session_yolo(key)assert [p for m, p in client.calls if m == "config.set"] == [{"session_id": child, "key": "yolo", "value": "1"}]+++def test_branch_never_shows_yolo_the_gateway_refused(store):+ """CLI-20: approvals run on the gateway, so a failed ``config.set yolo`` on the child surfaces instead of+ being logged as a best-effort persist, and the child's local flag stays off (no YOLO display while the+ gateway still asks)."""+ from hermes_cli.cli_init_mixin import CLIInitMixin+ from tools import approval+ db, client = store+ base = client.rpc++ async def rpc(method, *, _timeout=None, **params):+ if method == "session.mutate" and params["operation"] == "branch":+ client.known.add("local-child")+ return {"branched_session_id": "local-child", "copied_messages": 0}+ if method == "config.set":+ raise GatewayClientError("Gateway did not answer config.set")+ return await base(method, _timeout=_timeout, **params)+ client.rpc = rpc+ db.open_session(cli("local-old", resumed=True))+ host = types.SimpleNamespace(session_id="local-old", _session_db=db, _gateway_session_open=True)+ approval.enable_session_yolo("local-old")+ try:+ with pytest.raises(GatewayClientError, match="config.set"):+ CLIInitMixin._new_session_id(host, None, branch_of="local-old")+ assert not approval.is_session_yolo_enabled("local-child")+ finally:+ for key in ("local-old", "local-child"):+ approval.disable_session_yolo(key)