Skip to content

The agent that grows with you

fix(cli): let the early interface probe follow the profile's home

rodricksz4h5f50c6f43a2f4
diff --git a/hermes_cli/main.py b/hermes_cli/main.py
index 1e7cb737cd0..0de61ea4a80 100644
--- a/hermes_cli/main.py
+++ b/hermes_cli/main.py
@@ -241,23 +241,31 @@ def _set_process_title() -> None:
# Cheap read of `display.interface` for the earliest hot-path decisions
# (mouse-residue suppression, Termux fast launch) that run before
-# hermes_cli.config is importable. Cached so early callers don't re-parse YAML.
-_EARLY_INTERFACE_CACHE: "list | None" = None
+# hermes_cli.config is importable. Cached per config path so early callers
+# don't re-parse YAML, and so the answer follows the home the process ends up
+# in: mouse-residue suppression reads this BEFORE `_apply_profile_override()`
+# sets HERMES_HOME, and a cache keyed on nothing pinned every later caller to
+# the default home's interface for the whole run (#116902).
+_EARLY_INTERFACE_CACHE: "tuple[str, str] | None" = None
+
+
+def _early_interface_config_path() -> str:
+ """config.yaml of the home this process is currently pointed at."""
+ home = os.environ.get("HERMES_HOME")
+ if home:
+ return os.path.join(home, "config.yaml")
+ return os.path.join(os.path.expanduser("~"), ".hermes", "config.yaml")
def _config_default_interface_early() -> str:
"""Return the configured default interface ("cli"/"tui") via a minimal
YAML read. Best-effort: any error falls back to "cli" (legacy behavior)."""
global _EARLY_INTERFACE_CACHE
- if _EARLY_INTERFACE_CACHE is not None:
- return _EARLY_INTERFACE_CACHE[0]
+ cfg_path = _early_interface_config_path()
+ if _EARLY_INTERFACE_CACHE is not None and _EARLY_INTERFACE_CACHE[0] == cfg_path:
+ return _EARLY_INTERFACE_CACHE[1]
value = "cli"
try:
- home = os.environ.get("HERMES_HOME")
- if home:
- cfg_path = os.path.join(home, "config.yaml")
- else:
- cfg_path = os.path.join(os.path.expanduser("~"), ".hermes", "config.yaml")
if os.path.exists(cfg_path):
import yaml as _yaml_iface
@@ -272,7 +280,7 @@ def _config_default_interface_early() -> str:
value = "tui"
except Exception:
value = "cli" # best-effort — default to classic REPL on any error
- _EARLY_INTERFACE_CACHE = [value]
+ _EARLY_INTERFACE_CACHE = (cfg_path, value)
return value
diff --git a/tests/hermes_cli/test_default_interface_resolution.py b/tests/hermes_cli/test_default_interface_resolution.py
index 431e84c3f3b..3f6216cd9af 100644
--- a/tests/hermes_cli/test_default_interface_resolution.py
+++ b/tests/hermes_cli/test_default_interface_resolution.py
@@ -125,6 +125,39 @@ class TestWantsTuiEarly:
monkeypatch.setattr(m, "_EARLY_INTERFACE_CACHE", None)
assert m._wants_tui_early([]) is False
+ # REGRESSION (#116902): mouse-residue suppression reads the interface
+ # before `_apply_profile_override()` sets HERMES_HOME, so a cache that
+ # ignored the home answered every later caller with the DEFAULT home's
+ # interface — `hermes -p <name>` booted the wrong one.
+ def test_reread_after_the_profile_rehomes_the_process(self, tmp_path, monkeypatch):
+ default_home = tmp_path / "default"
+ profile_home = tmp_path / "profiles" / "coder"
+ for home, interface in ((default_home, "cli"), (profile_home, "tui")):
+ home.mkdir(parents=True)
+ (home / "config.yaml").write_text(
+ f"display:\n interface: {interface}\n"
+ )
+
+ # The import-time read, on the home the process starts in.
+ _fake_tty(monkeypatch, True)
+ monkeypatch.setenv("HERMES_HOME", str(default_home))
+ m._suppress_mouse_residue_early()
+ assert m._config_default_interface_early() == "cli"
+
+ # What `-p coder` does, after that read already happened.
+ monkeypatch.setenv("HERMES_HOME", str(profile_home))
+ assert m._config_default_interface_early() == "tui"
+ assert m._wants_tui_early([]) is True
+
+ def test_same_home_is_read_only_once(self, tmp_path, monkeypatch):
+ (tmp_path / "config.yaml").write_text("display:\n interface: tui\n")
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))
+ assert m._config_default_interface_early() == "tui"
+
+ # The cache still spares the hot path a second YAML parse.
+ (tmp_path / "config.yaml").write_text("display:\n interface: cli\n")
+ assert m._config_default_interface_early() == "tui"
+
# ---------------------------------------------------------------------------
# argument parser — flags exist at both levels and are relaunch-inherited