Skip to content

The agent that grows with you

fix(profiles): HERMES_HOME-blind path sites resolve through hermes_constants

teknium193d0dba281a9
diff --git a/hermes_cli/dashboard_procs.py b/hermes_cli/dashboard_procs.py
index 38a5a99291e..8fe8cc4fd62 100644
--- a/hermes_cli/dashboard_procs.py
+++ b/hermes_cli/dashboard_procs.py
@@ -524,9 +524,10 @@ _HEX32 = set("0123456789abcdef")
def _hermes_home_dir() -> Path:
- """Resolved Hermes home (HERMES_HOME override or ~/.hermes)."""
- override = os.environ.get("HERMES_HOME", "").strip()
- return Path(override).expanduser() if override else Path.home() / ".hermes"
+ """The process's Hermes home: remote-backend locks are a process-level asset, so a request scoped
+ to another profile must still see the same lock dir."""
+ from hermes_constants import get_process_hermes_home
+ return get_process_hermes_home()
def _is_hex(value: object, length: int) -> bool:
diff --git a/hermes_cli/env_loader.py b/hermes_cli/env_loader.py
index f1c5c48f2a0..f42501dec58 100644
--- a/hermes_cli/env_loader.py
+++ b/hermes_cli/env_loader.py
@@ -319,7 +319,10 @@ def load_hermes_dotenv(
) -> list[Path]:
"""Load Hermes env files: ``~/.hermes/.env`` overrides stale shell exports; project ``.env`` is a dev
fallback that only fills gaps when the user env exists (and overrides shell vars when it does not)."""
- home_path = Path(hermes_home or os.getenv("HERMES_HOME", Path.home() / ".hermes"))
+ # Process home on purpose (never the per-turn override): a startup .env load must not follow a routed
+ # profile — see the multiplex guard below.
+ from hermes_constants import get_process_hermes_home
+ home_path = Path(hermes_home) if hermes_home else get_process_hermes_home()
# Multiplex gateway: while a routed profile-home override is active, copying that profile's .env
# into os.environ would expose its credentials to sibling turns and every spawned child. Unscoped
diff --git a/hermes_cli/worktree_gc.py b/hermes_cli/worktree_gc.py
index 5969c7e4c4a..5306c39a382 100644
--- a/hermes_cli/worktree_gc.py
+++ b/hermes_cli/worktree_gc.py
@@ -91,7 +91,8 @@ def _dirty_split(path: str) -> tuple[bool, List[str]]:
def _archive_untracked(tree: Path, untracked: List[str]) -> Optional[Path]:
"""Copy untracked files out of a doomed tree; None on any failure (caller must then keep)."""
stamp = time.strftime("%Y%m%d-%H%M%S")
- dest = Path.home() / ".hermes" / "archive" / "worktree-prune" / f"{tree.name}-{stamp}"
+ from hermes_constants import get_hermes_home
+ dest = get_hermes_home() / "archive" / "worktree-prune" / f"{tree.name}-{stamp}"
try:
for rel in untracked:
src = tree / rel
diff --git a/tests/hermes_cli/test_worktree_gc.py b/tests/hermes_cli/test_worktree_gc.py
index 03e24a51ed4..7f4c485161c 100644
--- a/tests/hermes_cli/test_worktree_gc.py
+++ b/tests/hermes_cli/test_worktree_gc.py
@@ -153,16 +153,22 @@ class TestReclaim:
)
assert probe.returncode != 0, "branch should be gone with its tree"
- def test_untracked_files_archived_before_removal(self, repo):
+ def test_untracked_files_archived_under_the_active_profile_home(self, repo, tmp_path, monkeypatch):
+ """The archive follows the active Hermes home (a named profile here), never ~/.hermes."""
+ native_home = tmp_path / "native"
+ profile_home = tmp_path / "root" / "profiles" / "work"
+ profile_home.mkdir(parents=True)
+ monkeypatch.setattr(Path, "home", lambda: native_home)
+ monkeypatch.setenv("HERMES_HOME", str(profile_home))
tree, _ = _add_worktree(repo, "hermes-scratch")
(tree / "NOTES.md").write_text("important scribbles\n")
records = worktree_gc.audit_worktrees(str(repo), with_sizes=False)
worktree_gc.reclaim_worktrees(str(repo), records=records)
assert not tree.exists()
- archive_root = Path.home() / ".hermes" / "archive" / "worktree-prune"
- archived = list(archive_root.rglob("NOTES.md"))
- assert archived, "untracked file must be archived, not destroyed"
+ archived = list((profile_home / "archive" / "worktree-prune").rglob("NOTES.md"))
+ assert archived, "untracked file must be archived under the profile home, not destroyed"
assert archived[0].read_text() == "important scribbles\n"
+ assert not (native_home / ".hermes").exists()
def test_dry_run_changes_nothing(self, repo):
tree, _ = _add_worktree(repo, "hermes-clean")
diff --git a/tools/bot_mode_dm.py b/tools/bot_mode_dm.py
index a933d107d3c..99d31317bfd 100644
--- a/tools/bot_mode_dm.py
+++ b/tools/bot_mode_dm.py
@@ -53,7 +53,8 @@ _LOCAL_TARGET_RE = re.compile(r"^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$")
def _default_home() -> str:
- return os.getenv("HERMES_HOME") or os.path.expanduser("~/.hermes")
+ from hermes_constants import get_process_hermes_home
+ return str(get_process_hermes_home())
def message_agent_tool_schema() -> dict:
diff --git a/tools/bot_mode_probe.py b/tools/bot_mode_probe.py
index cb71c4b5693..2fbd9af4613 100644
--- a/tools/bot_mode_probe.py
+++ b/tools/bot_mode_probe.py
@@ -38,8 +38,9 @@ _cached: dict[str, str] = {}
def _default_home() -> str:
- """Ambient HERMES_HOME (env, else ~/.hermes) as a string."""
- return os.getenv("HERMES_HOME") or os.path.expanduser("~/.hermes")
+ """Ambient process HERMES_HOME (env, else the platform default) as a string."""
+ from hermes_constants import get_process_hermes_home
+ return str(get_process_hermes_home())
def _resolve_home(home: str | os.PathLike | None) -> Path:
diff --git a/tui_gateway/methods_bot_relay.py b/tui_gateway/methods_bot_relay.py
index 5a675746e5b..fd7ba3c80bc 100644
--- a/tui_gateway/methods_bot_relay.py
+++ b/tui_gateway/methods_bot_relay.py
@@ -21,8 +21,8 @@ method = _registry.method
def _relay_root() -> Path:
"""Install root shared by every profile (relay state is install-wide)."""
- home = Path(os.getenv("HERMES_HOME") or os.path.expanduser("~/.hermes"))
- return home.parent.parent if home.parent.name == "profiles" else home
+ from hermes_constants import get_default_hermes_root
+ return get_default_hermes_root()
def _run_delivery(profile: str, tmp: str, env: dict | None = None) -> subprocess.CompletedProcess: