The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): keep the -w worktree as session.create's cwd on a mounting docker backend
unsupportedpastels79e0464fd930
diff --git a/hermes_cli/gateway_session_store.py b/hermes_cli/gateway_session_store.pyindex 84ec0854b3c..44e411c4e9c 100644--- a/hermes_cli/gateway_session_store.py+++ b/hermes_cli/gateway_session_store.py@@ -487,11 +487,12 @@ def _creation_policy(launch):def _launch_cwd():- """``session.create``'s ``cwd``: a host folder, which the owner checks on its own host. Only a local- backend's TERMINAL_CWD is one; a docker/ssh ``terminal.cwd`` names a path inside the sandbox, so- those send the launch dir and the backend keeps its own cwd (``terminal_uses_host_cwd``)."""- local = (os.getenv("TERMINAL_ENV") or "local").strip().lower() in ("", "local")- return os.path.realpath((os.getenv("TERMINAL_CWD") if local else None) or os.getcwd())+ """``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+ the backend keeps its own cwd (``terminal_uses_host_cwd``)."""+ terminal_cwd = os.getenv("TERMINAL_CWD")+ return os.path.realpath(terminal_cwd if terminal_cwd and 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 eb808e20890..1b55f8e37b5 100644--- a/tests/hermes_cli/test_gateway_session_store.py+++ b/tests/hermes_cli/test_gateway_session_store.py@@ -531,6 +531,22 @@ def test_a_sandbox_backend_sends_the_host_launch_dir_not_its_terminal_cwd(store,assert [p for m, p in client.calls if m == "session.create"][-1]["cwd"] == str(tmp_path.resolve())+def test_a_mounting_docker_backend_sends_the_w_worktree_not_the_launch_dir(store, monkeypatch, tmp_path):+ """``-w`` puts its host worktree in TERMINAL_CWD without a chdir. A docker backend mounting the+ session cwd at ``/workspace`` would otherwise mount the original checkout, so the tools edit it+ instead of the isolated tree."""+ db, client = store+ repo, tree = tmp_path / "repo", tmp_path / "repo" / ".worktrees" / "wt"+ tree.mkdir(parents=True)+ monkeypatch.chdir(repo)+ monkeypatch.setenv("TERMINAL_CWD", str(tree))+ monkeypatch.setenv("TERMINAL_ENV", "docker")+ monkeypatch.setenv("TERMINAL_DOCKER_MOUNT_CWD_TO_WORKSPACE", "true")+ 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())++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 usesdiff --git a/tests/tools/test_terminal_inflight_reap_guard.py b/tests/tools/test_terminal_inflight_reap_guard.pyindex 0b832fe99c2..6ad9d02d010 100644--- a/tests/tools/test_terminal_inflight_reap_guard.py+++ b/tests/tools/test_terminal_inflight_reap_guard.py@@ -30,7 +30,7 @@ class _ReapingEnv:def execute(self, command, cwd=None, timeout=None, **kwargs):_sweep_after_long_call()self.cleaned_mid_call = self.cleaned- return {"output": "hi", "returncode": 0}+ return {"output": "OK", "returncode": 0}def _sweep_after_long_call():@@ -64,9 +64,17 @@ def test_a_foreground_terminal_call_keeps_its_environment_past_the_lifetime(env)assert env.cleaned-def test_a_remote_execute_code_call_keeps_its_environment_past_the_lifetime(env):- code_execution_tool._execute_remote("print(1)", "session-42", None)+def test_a_remote_execute_code_call_keeps_its_environment_past_the_lifetime(env, monkeypatch):+ from tools import code_kernel_remote+ def run_cell(code, *, env, **kwargs):+ env.execute("python3 cell.py")+ return {"status": "success", "stdout": "1\n"}++ monkeypatch.setattr(code_kernel_remote, "execute_in_remote_kernel", run_cell)+ result = json.loads(code_execution_tool._execute_remote("print(1)", "session-42", None))++ assert result["status"] == "success" and result["output"] == "1\n"assert env.cleaned_mid_call is Falseassert tt._active_environments["default"] is env