The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): hermes update from a PM environment's venv updates the checkout that owns it
teknium12cf037300f7f
diff --git a/hermes_cli/update_owning_install.py b/hermes_cli/update_owning_install.pyindex 86238ec3c70..e73534abcc3 100644--- a/hermes_cli/update_owning_install.py+++ b/hermes_cli/update_owning_install.py@@ -28,11 +28,11 @@ def owning_install_root(project_root: Path) -> Path | None:if sys.prefix == sys.base_prefix:return Nonevenv = Path(sys.prefix).resolve()- owner = venv.parentroot = Path(project_root).resolve()- if venv.name not in ("venv", ".venv") or owner == root:+ if venv.name not in ("venv", ".venv"):return None- if not (owner / "hermes_cli" / "main.py").is_file():+ owner = venv.parent if (venv.parent / "hermes_cli" / "main.py").is_file() else _pm_environment_owner(venv)+ if owner is None or owner == root:return Nonechosen = (Path(p).resolve() for p in os.environ.get("PYTHONPATH", "").split(os.pathsep) if p)if root in chosen:@@ -40,6 +40,28 @@ def owning_install_root(project_root: Path) -> Path | None:return owner+def _pm_environment_owner(venv: Path) -> Path | None:+ """The checkout a PM generation venv (``<installs>/<key>/environments/<gen>/venv``) belongs to.++ Its ``hermes_cli`` is the generation's ``workspace/`` snapshot, which has no ``.git``, so an+ update run from it must go to the checkout (#122627). The install key hashes the checkout+ path, which proves the path recorded beside it.+ """+ from pm.environments import install_key++ state = venv.parent.parent.parent+ if venv.parent.parent.name != "environments":+ return None+ try:+ # pm.environments.record_activation_inputs writes it on every full install.+ owner = Path((state / "inputs" / ".project-root").read_text(encoding="utf-8").strip())+ except OSError:+ return None+ if install_key(owner) != state.name or not (owner / "hermes_cli" / "main.py").is_file():+ return None+ return owner++def retarget_to_owning_install(project_root: Path) -> None:"""Re-run this command with the owning install's code; returns only when nothing is redirected."""owner = owning_install_root(project_root)diff --git a/tests/hermes_cli/test_update_owning_install.py b/tests/hermes_cli/test_update_owning_install.pynew file mode 100644index 00000000000..4ee79d89d20--- /dev/null+++ b/tests/hermes_cli/test_update_owning_install.py@@ -0,0 +1,28 @@+"""``hermes update`` from a PM environment's workspace goes to the checkout that owns it (#122627)."""+import sys++from hermes_cli.update_owning_install import owning_install_root+from pm.environments import install_key+++def test_pm_generation_venv_is_owned_by_the_checkout_its_install_key_names(tmp_path, monkeypatch):+ checkout = tmp_path / "hermes-agent"+ (checkout / "hermes_cli").mkdir(parents=True)+ (checkout / "hermes_cli" / "main.py").write_text("", encoding="utf-8")+ state = tmp_path / "installs" / install_key(checkout)+ generation = state / "environments" / "0123abcd"+ (generation / "venv").mkdir(parents=True)+ workspace = generation / "workspace"+ (workspace / "hermes_cli").mkdir(parents=True)+ (workspace / "hermes_cli" / "main.py").write_text("", encoding="utf-8")+ (state / "inputs").mkdir()+ record = state / "inputs" / ".project-root"+ record.write_text(str(checkout), encoding="utf-8")+ monkeypatch.setattr(sys, "prefix", str(generation / "venv"))+ monkeypatch.setattr(sys, "base_prefix", str(tmp_path / "python"))+ monkeypatch.delenv("PYTHONPATH", raising=False)++ assert owning_install_root(workspace) == checkout.resolve()++ record.write_text(str(tmp_path / "elsewhere"), encoding="utf-8") # not the path the key hashes+ assert owning_install_root(workspace) is None