The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(skills): expand variables in Hermes home paths
KoNit-K138ae22a2412
diff --git a/hermes_constants.py b/hermes_constants.pyindex d090995b2a9..09d5f131bf9 100644--- a/hermes_constants.py+++ b/hermes_constants.py@@ -42,6 +42,11 @@ def get_hermes_home_override() -> str | None:return str(override) if override is not _UNSET and override else None+def _expand_hermes_home(path: str) -> Path:+ """Expand environment and user-home syntax in a Hermes home path."""+ return Path(os.path.expanduser(os.path.expandvars(path)))++def _get_platform_default_hermes_home() -> Path:"""Return the platform-native default Hermes home path."""if sys.platform == "win32":@@ -102,7 +107,7 @@ def get_hermes_home() -> Path:"""Hermes home: context-local override → ``HERMES_HOME`` env var → platform default."""override = get_hermes_home_override()if override:- return Path(override)+ return _expand_hermes_home(override)if not os.environ.get("HERMES_HOME", "").strip():_warn_profile_fallback_once()return get_process_hermes_home()@@ -154,7 +159,7 @@ def get_process_hermes_home() -> Path:request is scoped to another profile (e.g. embedded ``/chat`` under ``--open-profile``)."""val = os.environ.get("HERMES_HOME", "").strip()- return Path(val) if val else _get_platform_default_hermes_home()+ return _expand_hermes_home(val) if val else _get_platform_default_hermes_home()# Hermes-managed runtime downloads at the root of a home (GGUF models, llama.cpp runtimes,@@ -163,8 +168,8 @@ def get_process_hermes_home() -> Path:# default profile) so the two lists cannot drift apart.LOCAL_RUNTIME_ROOT_DIRS: frozenset[str] = frozenset({"models", "runtimes", "node"})-# get_default_hermes_root() memo keyed on (native home, HERMES_HOME) so it stays-# fresh when a test or plugin mutates HERMES_HOME; saves ~80us/call at 31+ sites.+# get_default_hermes_root() memo keyed on (native home, expanded HERMES_HOME) so it stays+# fresh when a test or plugin mutates either input; saves ~80us/call at 31+ sites._default_hermes_root_memo: "tuple[str, str, Path] | None" = None@@ -172,18 +177,19 @@ def get_default_hermes_root() -> Path:"""Root Hermes dir for profile-level ops: ``<root>`` when ``HERMES_HOME=<root>/profiles/<name>``."""global _default_hermes_root_memonative_home = _get_platform_default_hermes_home()- env_home = os.environ.get("HERMES_HOME", "")+ env_home = os.environ.get("HERMES_HOME", "").strip()+ env_path = _expand_hermes_home(env_home) if env_home else None+ memo_key = (str(native_home), str(env_path) if env_path is not None else "")memo = _default_hermes_root_memo- if memo is not None and memo[:2] == (str(native_home), env_home):+ if memo is not None and memo[:2] == memo_key:return memo[2]result = native_home- if env_home:- env_path = Path(env_home)+ if env_path is not None:try:env_path.resolve().relative_to(native_home.resolve()) # under ~/.hermes (normal or profile mode)except ValueError: # Docker/custom root: <root>/profiles/<name> -> <root>, else HERMES_HOME itselfresult = env_path.parent.parent if env_path.parent.name == "profiles" else env_path- _default_hermes_root_memo = (str(native_home), env_home, result)+ _default_hermes_root_memo = (*memo_key, result)return resultdiff --git a/tests/test_hermes_constants.py b/tests/test_hermes_constants.pyindex 7aac9c6bf8d..97b86b24baf 100644--- a/tests/test_hermes_constants.py+++ b/tests/test_hermes_constants.py@@ -55,6 +55,17 @@ class TestGetDefaultHermesRoot:monkeypatch.setenv("HERMES_HOME", str(profile))assert get_default_hermes_root() == docker_root+ def test_expanded_custom_profile_returns_custom_root(self, tmp_path, monkeypatch):+ custom_root = tmp_path / "deployment"+ home_token = "$" + "HOME"+ monkeypatch.setenv("HOME", str(tmp_path))+ monkeypatch.setenv(+ "HERMES_HOME", f"{home_token}/deployment/profiles/research"+ )+ monkeypatch.setattr(Path, "home", lambda: tmp_path / "native-home")++ assert get_default_hermes_root() == custom_root+@pytest.mark.windows_onlydef test_no_hermes_home_returns_localappdata_root_on_windows(self, tmp_path, monkeypatch):"""Native Windows falls back to %LOCALAPPDATA%\\hermes, not ~/.hermes."""@@ -152,6 +163,26 @@ class TestGetProcessHermesHome:monkeypatch.setenv("HERMES_HOME", str(home))assert get_process_hermes_home() == home+ def test_process_and_context_homes_expand_environment_and_user_syntax(+ self, tmp_path, monkeypatch+ ):+ home_token = "$" + "HOME"+ monkeypatch.setenv("HOME", str(tmp_path))+ monkeypatch.setenv("USERPROFILE", str(tmp_path))++ for syntax in (home_token, "~"):+ process_home = tmp_path / "process-home"+ monkeypatch.setenv("HERMES_HOME", f"{syntax}/process-home")+ assert get_process_hermes_home() == process_home++ override_home = tmp_path / "override-home"+ token = set_hermes_home_override(f"{syntax}/override-home")+ try:+ assert get_hermes_home() == override_home+ assert get_process_hermes_home() == process_home+ finally:+ reset_hermes_home_override(token)+