The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): send a vanished -w worktree as is so the gateway refuses it
unsupportedpastels29e94c21b189
diff --git a/hermes_cli/gateway_session_store.py b/hermes_cli/gateway_session_store.pyindex 44e411c4e9c..a0ba27916af 100644--- a/hermes_cli/gateway_session_store.py+++ b/hermes_cli/gateway_session_store.py@@ -487,12 +487,17 @@ def _creation_policy(launch):def _launch_cwd():- """``session.create``'s ``cwd``: a host folder, which the owner checks on its own host. TERMINAL_CWD- when it is one (a local backend's cwd, or the ``-w`` worktree a mounting docker backend works in);- a docker/ssh ``terminal.cwd`` that names a path inside the sandbox sends the launch dir instead and+ """``session.create``'s ``cwd``, a host folder the owner checks on its own host. A folder chosen on+ this host (the ``-w`` / ``/worktree new`` tree, or a local backend's TERMINAL_CWD) is sent as is, so+ a vanished one is refused as on main rather than swapped for the checkout. Only a docker/ssh+ ``terminal.cwd`` that is not a host directory (a path inside the sandbox) sends the launch dir, andthe backend keeps its own cwd (``terminal_uses_host_cwd``)."""+ worktree = getattr(sys.modules.get("cli"), "_active_worktree", None)+ if worktree and worktree.get("path"):+ return os.path.realpath(worktree["path"])terminal_cwd = os.getenv("TERMINAL_CWD")- return os.path.realpath(terminal_cwd if terminal_cwd and os.path.isdir(terminal_cwd) else os.getcwd())+ local = (os.getenv("TERMINAL_ENV") or "local").strip().lower() in ("", "local")+ return os.path.realpath(terminal_cwd if terminal_cwd and (local or os.path.isdir(terminal_cwd)) else os.getcwd())def _classic_only_policy(launch):diff --git a/tests/hermes_cli/test_gateway_session_store.py b/tests/hermes_cli/test_gateway_session_store.pyindex 1b55f8e37b5..471e19a22d5 100644--- a/tests/hermes_cli/test_gateway_session_store.py+++ b/tests/hermes_cli/test_gateway_session_store.py@@ -547,6 +547,30 @@ def test_a_mounting_docker_backend_sends_the_w_worktree_not_the_launch_dir(storeassert [p for m, p in client.calls if m == "session.create"][-1]["cwd"] == str(tree.resolve())[email protected]("backend,mount", [("local", None), ("docker", "true")])+def test_a_removed_w_worktree_is_sent_so_the_gateway_refuses_it(store, monkeypatch, tmp_path, backend, mount):+ """-w publishes its tree in TERMINAL_CWD without a chdir; once the tree is gone, creating from the+ original checkout would put the agent's edits there. Main sent the path and the gateway refused it."""+ import sys+ from hermes_cli import gateway_session_store as gss+ db, client = store+ repo = tmp_path / "repo"+ repo.mkdir()+ tree = repo / ".worktrees" / "wt" # never created: removed while the CLI was open+ monkeypatch.chdir(repo)+ monkeypatch.setitem(sys.modules, "cli", types.SimpleNamespace(_active_worktree={"path": str(tree)}))+ monkeypatch.setenv("TERMINAL_CWD", str(tree))+ monkeypatch.setenv("TERMINAL_ENV", backend)+ if mount:+ monkeypatch.setenv("TERMINAL_DOCKER_MOUNT_CWD_TO_WORKSPACE", mount)+ monkeypatch.delenv("HERMES_SESSION_SOURCE", raising=False)+ db.create({"toolsets": ["file"]})+ assert [p for m, p in client.calls if m == "session.create"][-1]["cwd"] == str(tree.resolve())+ monkeypatch.setattr(gss, "session_store", lambda: db)+ gss.create_titled_session("Named")+ assert [p for m, p in client.calls if m == "session.create"][-1]["cwd"] == str(tree.resolve())++def test_explicit_reasoning_max_turns_and_checkpoints_reach_session_create(store, monkeypatch):"""Main's HermesCLI built AIAgent with the run's `--reasoning`, `--max-turns` and `--checkpoints`;the gateway now builds the agent, so `session.create` must carry them or the run silently uses