Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,18 @@ def load_cli_config() -> Dict[str, Any]:
if terminal_config.get("cwd") in (".", "auto", "cwd"):
effective_backend = terminal_config.get("env_type", "local")
if effective_backend == "local":
terminal_config["cwd"] = os.getcwd()
defaults["terminal"]["cwd"] = terminal_config["cwd"]
try:
terminal_config["cwd"] = os.getcwd()
defaults["terminal"]["cwd"] = terminal_config["cwd"]
except FileNotFoundError:
logger.warning("Current working directory no longer exists; leaving terminal.cwd unset")
terminal_config.pop("cwd", None)
defaults["terminal"].pop("cwd", None)
os.environ.pop("TERMINAL_CWD", None)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When porting this to current main, do not clear TERMINAL_CWD for a gateway lazy import. gateway/run.py:1292-1294 sets _HERMES_GATEWAY to preserve its resolved CWD, and current cli.py:646-653 honors that contract.

else:
# Remove so TERMINAL_CWD stays unset → tool picks backend default
terminal_config.pop("cwd", None)
os.environ.pop("TERMINAL_CWD", None)

env_mappings = {
"env_type": "TERMINAL_ENV",
Expand Down
20 changes: 20 additions & 0 deletions tests/cli/test_cli_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ def test_tool_progress_mode_is_string(self):
assert cli.tool_progress_mode in ("off", "new", "all", "verbose")


class TestLoadCliConfig:
def test_missing_current_working_directory_falls_back_safely(self, tmp_path, monkeypatch):
import importlib

hermes_home = tmp_path / ".hermes"
hermes_home.mkdir()
monkeypatch.setenv("HERMES_HOME", str(hermes_home))

import cli as _cli_mod
_cli_mod = importlib.reload(_cli_mod)
monkeypatch.setattr(_cli_mod, "_hermes_home", hermes_home)
monkeypatch.setenv("TERMINAL_CWD", "/tmp/stale")
monkeypatch.setattr(_cli_mod.os, "getcwd", MagicMock(side_effect=FileNotFoundError("gone")))

cfg = _cli_mod.load_cli_config()

assert cfg["terminal"].get("cwd") in (None, "")
assert "TERMINAL_CWD" not in _cli_mod.os.environ


class TestBusyInputMode:
def test_default_busy_input_mode_is_interrupt(self):
cli = _make_cli()
Expand Down