The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(pm): a borrower's own dependency state never makes it the checkout's owner
unsupportedpastels78189b2bb602
diff --git a/pm/environments.py b/pm/environments.pyindex bd4888baff8..48562228a60 100644--- a/pm/environments.py+++ b/pm/environments.py@@ -44,26 +44,29 @@ def owning_home_root(project_root: Path) -> Path | None:Dependency state is scoped per data root (``<root>/installs/<install_key>``), but a sourcecheckout -- its launchers, product builds and install stamp -- exists once. A launch underanother root (a test's temporary ``HERMES_HOME``, a per-task home, a CI service home) borrows- it: the root that installed it already holds committed state for it, under the platform- default root or the root the checkout sits in (``<root>/hermes-agent``). ``None`` when the- active root's state is that state (the owner itself, or one of its profiles), and when no+ it: the root that installed it already holds committed state for it, under the root the+ checkout sits in (``<root>/hermes-agent``) or else the platform default root. ``None`` when+ the active root's state is that state (the owner itself, or one of its profiles), and when nosuch root has state for this checkout -- a fresh install, or a custom root that owns its owntree -- so those keep today's behaviour (#123238).++ The root the checkout sits in outranks the platform default: a borrowing launch's own sync+ leaves ``facts.json`` under the borrower too, and that must never make it the owner."""from hermes_constants import _get_platform_default_hermes_homeroot = Path(project_root).resolve()key = install_key(root)- active = install_state_dir(root)- owners = [candidate for candidate in dict.fromkeys((_get_platform_default_hermes_home(), root.parent))- if (candidate / "installs" / key / "facts.json").is_file()]- for owner in owners:- try:- if (owner / "installs" / key).resolve() == active.resolve():- return None- except OSError:- continue- return owners[0] if owners else None+ owner = next((candidate for candidate in (root.parent, _get_platform_default_hermes_home())+ if (candidate / "installs" / key / "facts.json").is_file()), None)+ if owner is None:+ return None+ try:+ if (owner / "installs" / key).resolve() == install_state_dir(root).resolve():+ return None+ except OSError:+ pass+ return ownerdef install_state_permission_message(project_root: Path, exc: PermissionError) -> str | None:diff --git a/tests/hermes_cli/test_borrowed_home_launch.py b/tests/hermes_cli/test_borrowed_home_launch.pyindex 153561af712..1ce07bd21a7 100644--- a/tests/hermes_cli/test_borrowed_home_launch.py+++ b/tests/hermes_cli/test_borrowed_home_launch.py@@ -81,6 +81,20 @@ def test_a_fresh_install_and_a_custom_root_keep_their_own_store(tmp_path, monkeyassert store_root(root) == tmp_path / "data" / "h" / "tools"+def test_a_borrowers_own_dependency_state_never_makes_it_the_owner(tmp_path, monkeypatch):+ """`install.sh --hermes-home <custom>` owns the checkout. The default root launching it borrows,+ and still borrows after its own dependency sync leaves state for the checkout."""+ custom = tmp_path / "data" / "h"+ root = _checkout(tmp_path, monkeypatch, parent=custom)+ _state(custom, root)+ monkeypatch.delenv("HERMES_HOME", raising=False)+ assert owning_home_root(root) == custom++ _state(tmp_path / ".hermes", root) # the borrowing launch's own sync+ assert owning_home_root(root) == custom+ assert store_root(root) == custom / "tools"++def test_a_borrowing_launch_syncs_its_own_dependencies_and_nothing_of_the_checkout(tmp_path, monkeypatch, completion_tail):