The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): no false "[HERMES_HOME fallback] wrong profile" warning on every command
teknium12452b882ad55
diff --git a/hermes_cli/_parser.py b/hermes_cli/_parser.pyindex a9067f50143..cc73a1506f3 100644--- a/hermes_cli/_parser.py+++ b/hermes_cli/_parser.py@@ -27,10 +27,16 @@ _OPTIONAL_VALUE_FLAGS_FALLBACK: frozenset[str] = frozenset({"-c", "--continue"})def _cfg_path() -> str:- """``~/.hermes/config.yaml`` spelled for the active profile, for help text."""- from hermes_constants import display_hermes_home+ """``~/.hermes/config.yaml`` spelled for the active profile, for help text.- return f"{display_hermes_home()}/config.yaml"+ ``main._apply_profile_override`` builds this parser (via ``top_level_value_flag_sets``) BEFORE+ it re-homes the process to the sticky ``active_profile``; ``get_hermes_home()`` would emit the+ "[HERMES_HOME fallback] ... wrong profile" warning on every ``hermes`` command for that+ throwaway help string. Read the process home directly: after the override it IS the profile home.+ """+ from hermes_constants import display_hermes_home, get_process_hermes_home++ return f"{display_hermes_home(get_process_hermes_home())}/config.yaml"@lru_cache(maxsize=1)diff --git a/hermes_constants.py b/hermes_constants.pyindex 4db5f1f71e8..7691909070e 100644--- a/hermes_constants.py+++ b/hermes_constants.py@@ -809,9 +809,14 @@ def _legacy_path_has_content(path: Path) -> bool:return True-def display_hermes_home() -> str:- """User-facing ``~/`` display string for HERMES_HOME (``~/.hermes/profiles/coder``)."""- home = get_hermes_home()+def display_hermes_home(home: Path | None = None) -> str:+ """User-facing ``~/`` display string for HERMES_HOME (``~/.hermes/profiles/coder``).++ ``home`` overrides the lookup for callers that run before the CLI has applied the sticky+ ``active_profile`` (``get_hermes_home()`` would emit the wrong-profile fallback warning there).+ """+ if home is None:+ home = get_hermes_home()try: # as_posix(): str() on Windows yields chimeras like ~/AppData\Local\hermes/skills/return "~/" + home.relative_to(Path.home()).as_posix()except ValueError:diff --git a/tests/hermes_cli/test_parser_help_home.py b/tests/hermes_cli/test_parser_help_home.pynew file mode 100644index 00000000000..583c1d5d9ae--- /dev/null+++ b/tests/hermes_cli/test_parser_help_home.py@@ -0,0 +1,40 @@+"""The top-level parser's help text must not trip the wrong-profile fallback warning.++``main._apply_profile_override`` builds the parser (``top_level_value_flag_sets``) before it+re-homes the process to the sticky ``active_profile``; a help string that resolved the home through+``get_hermes_home()`` printed ``[HERMES_HOME fallback] ... wrong profile`` on every ``hermes``+command for users of ``hermes profile use`` (#112319, also reported in #112839).+"""++from pathlib import Path++import pytest+++def sticky_profile_home(monkeypatch, tmp_path):+ import hermes_constants++ monkeypatch.setattr(Path, "home", lambda: tmp_path)+ monkeypatch.delenv("HERMES_HOME", raising=False)+ root = tmp_path / ".hermes"+ (root / "profiles" / "coder").mkdir(parents=True)+ (root / "active_profile").write_text("coder\n", encoding="utf-8")+ monkeypatch.setattr(hermes_constants, "_profile_fallback_warned", False)+ return root+++def test_building_the_parser_before_the_profile_override_stays_silent(sticky_profile_home, capsys):+ from hermes_cli._parser import build_top_level_parser++ build_top_level_parser()++ assert "HERMES_HOME fallback" not in capsys.readouterr().err+++def test_help_text_names_the_profile_config_once_the_process_is_re_homed(sticky_profile_home, monkeypatch):+ from hermes_cli._parser import _cfg_path++ monkeypatch.setenv("HERMES_HOME", str(sticky_profile_home / "profiles" / "coder"))++ assert _cfg_path() == "~/.hermes/profiles/coder/config.yaml"