Skip to content

The agent that grows with you

fix(tui): local sessions start in the launch dir, not terminal.cwd (#84015)

Brooklyn Nicholsoneb1578400214
diff --git a/hermes_cli/main_tui_launch.py b/hermes_cli/main_tui_launch.py
index 79b07876104..99e053ee8f6 100644
--- a/hermes_cli/main_tui_launch.py
+++ b/hermes_cli/main_tui_launch.py
@@ -399,6 +399,14 @@ def _launch_tui(
env["HERMES_CWD"] = wt_info["path"]
env["TERMINAL_CWD"] = wt_info["path"]
+ # A local interactive session starts where the user launched (or in the --worktree), the
+ # classic CLI's rule; terminal.cwd stays the default for gateway, cron and remote backends.
+ # HERMES_TUI_CWD is what the TUI sends on session.create, which beats the configured cwd (#84015).
+ if str(env.get("TERMINAL_ENV") or "local") == "local":
+ env["TERMINAL_CWD"] = env["HERMES_TUI_CWD"] = env["HERMES_CWD"]
+ else:
+ env.pop("HERMES_TUI_CWD", None)
+
_apply_tui_python_env(env)
skills_value = ""
diff --git a/tests/hermes_cli/test_tui_resume_flow.py b/tests/hermes_cli/test_tui_resume_flow.py
index c4ef95f9604..545014e2138 100644
--- a/tests/hermes_cli/test_tui_resume_flow.py
+++ b/tests/hermes_cli/test_tui_resume_flow.py
@@ -221,6 +221,7 @@ def test_launch_tui_prefers_launch_cwd_over_inherited_hermes_cwd(monkeypatch, ma
launch = tmp_path / "launch-project"
stale.mkdir()
launch.mkdir()
+ monkeypatch.setenv("HERMES_PYTHON", sys.executable)
monkeypatch.setenv("HERMES_CWD", str(stale))
monkeypatch.chdir(launch)
@@ -246,6 +247,7 @@ def test_launch_tui_worktree_still_outranks_the_launch_cwd(monkeypatch, main_mod
launch = tmp_path / "launch-project"
worktree.mkdir()
launch.mkdir()
+ monkeypatch.setenv("HERMES_PYTHON", sys.executable)
monkeypatch.setenv("HERMES_CWD", str(tmp_path))
monkeypatch.chdir(launch)
@@ -264,3 +266,41 @@ def test_launch_tui_worktree_still_outranks_the_launch_cwd(monkeypatch, main_mod
assert captured["env"]["HERMES_CWD"] == str(worktree)
assert captured["env"]["TERMINAL_CWD"] == str(worktree)
assert Path(captured["env"]["HERMES_CWD"]).resolve() != launch.resolve()
+
+
[email protected]("backend", ["local", "docker"])
+def test_launch_tui_local_session_starts_in_launch_dir_not_terminal_cwd(monkeypatch, main_mod, tmp_path, backend):
+ """A local TUI follows the classic CLI rule: the launch dir beats an absolute terminal.cwd (#84015).
+
+ Remote backends keep terminal.cwd: the launch dir names nothing on the sandbox.
+ """
+ configured = tmp_path / "configured-home"
+ launch = tmp_path / "launch-project"
+ configured.mkdir()
+ launch.mkdir()
+ (Path(os.environ["HERMES_HOME"]) / "config.yaml").write_text(
+ f"terminal:\n backend: {backend}\n cwd: {configured}\n", encoding="utf-8")
+ monkeypatch.delenv("TERMINAL_ENV", raising=False)
+ monkeypatch.delenv("TERMINAL_CWD", raising=False)
+ monkeypatch.setenv("HERMES_PYTHON", sys.executable)
+ monkeypatch.setenv("HERMES_TUI_CWD", str(tmp_path)) # stale, from an outer launcher
+ monkeypatch.chdir(launch)
+
+ captured = {}
+ monkeypatch.setattr(main_tui_launch, "_make_tui_argv",
+ lambda tui_dir, tui_dev: (["node", "dist/entry.js"], Path(".")),
+ )
+ monkeypatch.setattr(main_mod.subprocess, "call",
+ lambda argv, cwd=None, env=None: captured.update({"env": env}) or 1,
+ )
+
+ with pytest.raises(SystemExit):
+ main_mod._launch_tui()
+
+ env = captured["env"]
+ if backend == "local":
+ assert Path(env["HERMES_TUI_CWD"]).resolve() == launch.resolve()
+ assert Path(env["TERMINAL_CWD"]).resolve() == launch.resolve()
+ else:
+ assert "HERMES_TUI_CWD" not in env
+ assert Path(env["TERMINAL_CWD"]).resolve() == configured.resolve()