Skip to content

The agent that grows with you

fix(cli): send the host launch dir, not a sandbox terminal.cwd, to session.create

unsupportedpastels04c5ae471a2e
diff --git a/hermes_cli/gateway_session_store.py b/hermes_cli/gateway_session_store.py
index 44399d4eb35..84ec0854b3c 100644
--- a/hermes_cli/gateway_session_store.py
+++ b/hermes_cli/gateway_session_store.py
@@ -164,7 +164,7 @@ class GatewaySessionStore:
``--create-if-missing``) leaves the row's cwd empty, as main's explicit creates did."""
from agent.session_source import CLI_FAMILY_SOURCES, create_surface, session_source_for
params = _creation_policy(launch or {})
- params["cwd"] = os.path.realpath(os.getenv("TERMINAL_CWD") or os.getcwd())
+ params["cwd"] = _launch_cwd()
# Main's row label: ``cli``, ``oneshot`` for a finite -q/-Q run, or an explicit --source.
params["source"] = create_surface(session_source_for("cli"))
# Main's row stamp (run_agent._launch_cwd_for_session): this process's cwd (``-w`` never
@@ -486,6 +486,14 @@ def _creation_policy(launch):
return policy
+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())
+
+
def _classic_only_policy(launch):
"""Main's `--run-budget` and `-v`, which the thin client refuses."""
policy = {}
@@ -542,7 +550,7 @@ def create_titled_session(title):
(``row_cwd`` ""). Returns the id, or None when the gateway refused (the caller prints main's
"could not be created" copy)."""
params = _creation_policy({})
- params["cwd"] = os.path.realpath(os.getenv("TERMINAL_CWD") or os.getcwd())
+ params["cwd"] = _launch_cwd()
params["source"] = "cli" # main's titled row is `cli` (hermes_cli.main._create_titled_session)
params["row_cwd"] = ""
try:
diff --git a/tests/hermes_cli/test_gateway_session_store.py b/tests/hermes_cli/test_gateway_session_store.py
index 704c9237ff2..eb808e20890 100644
--- a/tests/hermes_cli/test_gateway_session_store.py
+++ b/tests/hermes_cli/test_gateway_session_store.py
@@ -513,6 +513,24 @@ def test_row_cwd_is_mains_stamp_while_the_tools_run_in_terminal_cwd(store, monke
assert [p for m, p in client.calls if m == "session.create"][-1]["row_cwd"] == ""
[email protected]("backend", ["docker", "ssh"])
+def test_a_sandbox_backend_sends_the_host_launch_dir_not_its_terminal_cwd(store, monkeypatch, tmp_path, backend):
+ """A docker/ssh ``terminal.cwd`` (bridged to TERMINAL_CWD) names a path inside the sandbox. The
+ owner checks ``cwd`` on its own host, so sending it refused every launch with ``invalid_params``;
+ like the thin client and the TUI, the classic CLI sends its host launch dir."""
+ from hermes_cli import gateway_session_store as gss
+ db, client = store
+ monkeypatch.chdir(tmp_path)
+ monkeypatch.setenv("TERMINAL_CWD", "/project/not-on-this-host")
+ monkeypatch.setenv("TERMINAL_ENV", backend)
+ 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(tmp_path.resolve())
+ monkeypatch.setattr(gss, "session_store", lambda: db)
+ gss.create_titled_session("Remote Named")
+ assert [p for m, p in client.calls if m == "session.create"][-1]["cwd"] == str(tmp_path.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