The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): the downgrade refusal names the invoking named profile
Teknium9a91cf679e66
diff --git a/hermes_cli/update_downgrade_guard.py b/hermes_cli/update_downgrade_guard.pyindex 5e83eb6e62b..e9dcfd5fbc8 100644--- a/hermes_cli/update_downgrade_guard.py+++ b/hermes_cli/update_downgrade_guard.py@@ -72,6 +72,16 @@ def _pre_runtime_snapshot(home: Path) -> str | None:return None+def _named_profile(home: Path) -> str:+ """The ``-p`` name that opens ``home`` (``hermes -p acme update`` passes ``profiles/acme``);+ ``""`` for the default root or a custom HERMES_HOME, which bare ``hermes`` opens."""+ from hermes_cli.profiles import _PROFILE_ID_RE, _get_profiles_root+ parent = _get_profiles_root().resolve()+ resolved = home.resolve()+ named = resolved.parent == parent and _PROFILE_ID_RE.match(resolved.name) and resolved.name != "default"+ return resolved.name if named else ""++def downgrade_refusal(git_cmd, root: Path, target_ref: str, home: Path | None = None) -> str | None:"""Why the update must not move to ``target_ref``, or ``None``: refuses only a pre-runtime targetwhile this profile's or a sibling profile's state.db holds runtime ledger rows."""@@ -79,7 +89,7 @@ def downgrade_refusal(git_cmd, root: Path, target_ref: str, home: Path | None =from hermes_constants import get_hermes_homehome = Path(home or get_hermes_home())- profiles = [("", home), *_sibling_profile_homes(home)]+ profiles = [(_named_profile(home), home), *_sibling_profile_homes(home)]ledgered = [(name, h) for name, h in profiles if _has_ledger_rows(h / "state.db")]if not ledgered or not target_predates_runtime(git_cmd, root, target_ref):return Nonediff --git a/tests/hermes_cli/test_update_downgrade_guard_named_profile.py b/tests/hermes_cli/test_update_downgrade_guard_named_profile.pynew file mode 100644index 00000000000..a6b9f307e75--- /dev/null+++ b/tests/hermes_cli/test_update_downgrade_guard_named_profile.py@@ -0,0 +1,29 @@+"""A named-profile update's refusal tells the user to reopen THAT profile for its snapshot."""+import subprocess++from hermes_cli import update_downgrade_guard as guard+from tests.hermes_cli import test_update_downgrade_guard as base++repo = base.repo # the real git repo fixture: an old tag predating the runtime ledger+++def _rev(root, ref):+ return subprocess.run(["git", "rev-parse", ref], cwd=root, check=True, capture_output=True,+ text=True, encoding="utf-8").stdout.strip()+++def test_named_profile_refusal_names_its_own_profile(repo, tmp_path, monkeypatch):+ root = tmp_path / "root"+ acme = root / "profiles" / "acme"+ monkeypatch.setenv("HERMES_HOME", str(acme)) # `hermes -p acme update`+ base._ledgered_store(acme)+ base._pre_cutover_snapshot(acme, "20261001-000000-pre-update")+ out = guard.downgrade_refusal(["git"], repo, _rev(repo, "old-release"), home=acme)+ assert f"{acme}: run `hermes -p acme` and enter `/snapshot restore 20261001-000000-pre-update`" in out+ assert "run `hermes` and" not in out+ # The default root's own update still points at bare `hermes`.+ base._ledgered_store(root)+ base._pre_cutover_snapshot(root, "20261002-000000-pre-update")+ monkeypatch.setenv("HERMES_HOME", str(root))+ out = guard.downgrade_refusal(["git"], repo, _rev(repo, "old-release"), home=root)+ assert f"{root}: run `hermes` and enter `/snapshot restore 20261002-000000-pre-update`" in out