The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): check an explicit -t on resume; drop the dead client worktree note
unsupportedpastelse65b61c37e7d
diff --git a/cli.py b/cli.pyindex 20462b8acac..b3f523f67c8 100644--- a/cli.py+++ b/cli.py@@ -1547,6 +1547,8 @@ def _build_cli_from_args(model, toolsets, provider, reasoning, api_key, base_urlraiseif profile_default:cli._explicit_toolsets = False # the gateway resolves the profile's toolsets itself+ # Only a typed -t is checked against a resumed session's frozen toolsets.+ cli._typed_toolsets = toolsets_list if toolsets else None# skills.auto_load rides the same background preload as -s; --ignore-rules skips it with# the rest of the auto-injected context. Resolved here (not lazily in the agent) so the@@ -1745,16 +1747,7 @@ def main(if _join_worktree is not None and not wt_info:return- # Inject worktree context into agent's system prompt- if wt_info:- wt_note = (- f"\n\n[System note: You are working in an isolated git worktree at "- f"{wt_info['path']}. Your branch is `{wt_info['branch']}`. "- f"Changes here do not affect the main working tree or other agents. "- f"Remember to commit and push your changes, and create a PR if appropriate. "- f"The original repo is at {wt_info['repo_root']}.]"- )- cli.system_prompt = (cli.system_prompt or "") + wt_note+ # The worktree note is rendered by the gateway from the session's folder (agent/coding_context.py).if list_tools or list_toolsets:cli.show_banner()diff --git a/hermes_cli/gateway_session_store.py b/hermes_cli/gateway_session_store.pyindex a5756bdc8b0..ae769f3cc76 100644--- a/hermes_cli/gateway_session_store.py+++ b/hermes_cli/gateway_session_store.py@@ -134,7 +134,8 @@ class GatewaySessionStore:if str(exc) in {"not_found", "permission_denied"}:return Noneraise- _check_resume_launch(launch or {}, snapshot)+ # The CLI always sends its resolved toolsets; only an explicit -t is checked.+ _check_resume_launch({**(launch or {}), "toolsets": getattr(cli, "_typed_toolsets", None)}, snapshot)return self._adopt(snapshot)return self.create(launch)@@ -409,16 +410,18 @@ def _classic_only_policy(launch):return policy-# Flags a resume may only repeat. Not ``toolsets``: the classic CLI always sends its resolved selection, so-# an unset ``-t`` cannot be told from an explicit one here.-_RESUME_CHECKED = tuple(key for key in _LAUNCH_POLICY if key != "toolsets")+# Flags a resume may only repeat (``toolsets`` arrives here only from an explicit ``-t``).+_RESUME_CHECKED = _LAUNCH_POLICYdef _check_resume_launch(launch, snapshot):"""Explicit launch flags on ``--resume`` / ``-c`` against the session's frozen route, as the thinclient checks them: the same flags again are fine, a different value is refused, never dropped."""from hermes_cli.gateway_chat import _RESUME_POLICY_MISMATCH, check_resume_policy- check_resume_policy(argparse.Namespace(**{key: launch.get(key) for key in _RESUME_CHECKED}), snapshot)+ fields = {key: launch.get(key) for key in _RESUME_CHECKED}+ if isinstance(fields.get("toolsets"), (list, tuple)):+ fields["toolsets"] = ",".join(str(item) for item in fields["toolsets"])+ check_resume_policy(argparse.Namespace(**fields), snapshot)frozen = ((snapshot.get("info") or {}).get("launch_request") or {})if any(frozen.get(key) != value for key, value in _classic_only_policy(launch).items()):raise GatewayClientError(_RESUME_POLICY_MISMATCH)diff --git a/tests/hermes_cli/test_gateway_session_store.py b/tests/hermes_cli/test_gateway_session_store.pyindex 807fe17d3b3..b0d24c2d8f6 100644--- a/tests/hermes_cli/test_gateway_session_store.py+++ b/tests/hermes_cli/test_gateway_session_store.py@@ -529,6 +529,21 @@ def test_explicit_flags_on_resume_are_checked_against_the_frozen_route(store):assert GatewaySessionStore(db.connection).open_session(cli("local-old", resumed=True), launch) == "local-old"+def test_explicit_toolsets_on_resume_are_checked_against_the_frozen_route(store):+ """CLI-2 `-t`: only an explicit `-t` (``cli._typed_toolsets``) is checked on resume; the CLI's+ resolved default selection in ``launch`` never refuses one."""+ db, client = store+ _frozen_launch(client, {"toolsets": ["file"]})+ host = cli("local-old", resumed=True)+ host._typed_toolsets = ["web"]+ with pytest.raises(GatewayClientError, match="Resume retains gateway session policy"):+ GatewaySessionStore(db.connection).open_session(host, {"toolsets": ["web"]})+ host._typed_toolsets = ["file"]+ assert GatewaySessionStore(db.connection).open_session(host, {"toolsets": ["file"]}) == "local-old"+ host._typed_toolsets = None+ assert GatewaySessionStore(db.connection).open_session(host, {"toolsets": ["web"]}) == "local-old"++def test_new_session_keeps_the_runs_launch_policy(store, monkeypatch):"""CLI-3: `/new` keeps `--max-turns`, `--checkpoints`, `--run-budget`, `-v` and `-s` (main kept oneAIAgent across /new); only the explicit model route is left to the profile default."""