The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(memory): one profile's refused migration no longer skips the others; hints name the right profile
teknium1c5b3d66a9757
diff --git a/hermes_cli/memory_provider_migration.py b/hermes_cli/memory_provider_migration.pyindex 7701e318daa..4a8809d45fd 100644--- a/hermes_cli/memory_provider_migration.py+++ b/hermes_cli/memory_provider_migration.py@@ -74,10 +74,13 @@ def _pending_provider(home: Path, *, say: Callable[[str], None]) -> Optional[strdef _install_command(name: str, home: Path) -> str:- """The exact command that installs *name* into *home* (``-p`` when it is not the active home)."""- from hermes_constants import get_hermes_home, hermes_home_key, profile_name_for_home+ """The exact command that installs *name* into *home*. ``-p`` is dropped only for the default+ home while no sticky profile is set: a bare command run from a shell targets the sticky+ profile, never the home of the agent (Desktop, gateway, ``hermes -p``) that printed it."""+ from hermes_cli.profiles import get_active_profile+ from hermes_constants import profile_name_for_homeprofile = profile_name_for_home(home)- if profile is None or hermes_home_key(home) == hermes_home_key(get_hermes_home()):+ if profile is None or (profile == "default" and get_active_profile() == "default"):return f"hermes plugins install {name}"return f"hermes -p {profile} plugins install {name}"@@ -112,16 +115,28 @@ def migrate_home(home: Path, *, install: Callable[[str], dict], say: Callable[[sreturn name if _install_pending(home, name, install=install, say=say) else None+def _interactive() -> bool:+ return sys.stdin is not None and sys.stdout is not None and sys.stdin.isatty() and sys.stdout.isatty()++def _unattended_consent() -> bool:"""Without a terminal (Desktop, gateway, ``hermes update`` from a script) nobody can answer thedependency prompt, so every provider that declares Python deps would fail to migrate. The- configured ``memory.provider`` plus ``security.allow_lazy_installs`` (read for the home being- migrated) is the same consent that let the bundled provider install its deps on demand; with a- terminal the user is still asked."""+ configured ``memory.provider`` plus ``security.allow_lazy_installs`` (read for the active home,+ i.e. the one being migrated) is the same consent that let the bundled provider install its deps+ on demand; with a terminal the user is still asked."""from pm.install import lazy_installs_allowed- interactive = sys.stdin is not None and sys.stdout is not None and sys.stdin.isatty() and sys.stdout.isatty()- return not interactive and lazy_installs_allowed()+ return not _interactive() and lazy_installs_allowed()+++def _home_consent(home: Path) -> bool:+ from hermes_constants import reset_hermes_home_override, set_hermes_home_override+ token = set_hermes_home_override(home)+ try:+ return _unattended_consent()+ finally:+ reset_hermes_home_override(token)def _install_into(home: Path) -> Callable[[str], dict]:@@ -148,9 +163,11 @@ def migrate_all_homes(*, say: Callable[[str], None] = print) -> list[str]:Each line names the profile it is about. Homes missing the same provider share one environment,so they share one set of dependency answers (#125794): the first install asks, the rest reuse- its answers, and when it fails the remaining homes are named in one line instead of failing (or- re-prompting) one by one. Ctrl-C ends the migration with a message, not a traceback into the- updater.+ its answers. Homes are grouped by provider AND by their unattended consent (each home's own+ ``security.allow_lazy_installs``), so a refusal only speaks for homes that would be refused the+ same way: when an install in a group fails, the rest of that group are named in one line+ instead of failing (or re-prompting) one by one, and the other groups still migrate. Ctrl-C+ ends the migration with a message, not a traceback into the updater."""from hermes_cli.plugins_cmd_install import shared_dependency_answersfrom pm.plugins_state import dependency_homes@@ -158,20 +175,21 @@ def migrate_all_homes(*, say: Callable[[str], None] = print) -> list[str]:def labelled(home: Path) -> Callable[[str], None]:return lambda message: say(f" [{_home_label(home)}] {message.lstrip()}")- pending: dict[str, list[Path]] = {}+ pending: dict[tuple[str, bool], list[Path]] = {}for home in dependency_homes():try:name = _pending_provider(home, say=labelled(home))+ consent = bool(name) and _home_consent(home)except Exception as exc:logger.debug("memory provider migration skipped for %s: %s", home, exc)continueif name:- pending.setdefault(name, []).append(home)+ pending.setdefault((name, consent), []).append(home)installed: list[str] = []try:- for name, homes in pending.items():- if len(homes) > 1:+ for (name, _consent), homes in pending.items():+ if len(homes) > 1 and _interactive():say(f" Memory provider '{name}' is configured in {len(homes)} profiles "f"({', '.join(_home_label(h) for h in homes)}); your answers to its dependency "f"questions apply to all of them.")@@ -215,6 +233,6 @@ def recover_at_startup(name: str, *, say: Optional[Callable[[str], None]] = Noneif not lazy_installs_allowed():report(f"⚠ Memory provider '{name}' is not installed, so external memory is off for this session. "f"security.allow_lazy_installs is off, so Hermes did not fetch it: "- f"run `hermes plugins install {name}`.")+ f"run `{_install_command(name, home)}`.")return Falsereturn migrate_home(home, install=_install_into(home), say=report) == namediff --git a/tests/hermes_cli/test_memory_provider_migration.py b/tests/hermes_cli/test_memory_provider_migration.pyindex f69ee33ae97..05bdb7645c6 100644--- a/tests/hermes_cli/test_memory_provider_migration.py+++ b/tests/hermes_cli/test_memory_provider_migration.py@@ -169,3 +169,59 @@ def test_update_asks_once_and_names_each_profile(tmp_path, monkeypatch):else:assert [line.split("]")[0] for line in said[1:]] == [" [profile 'default'", " [profile 'work-a'", " [profile 'work-b'"]+++def _profile_homes(tmp_path, monkeypatch, *names):+ root = tmp_path / ".hermes"+ homes = [root, *(root / "profiles" / n for n in names)]+ for profile_home in homes:+ profile_home.mkdir(parents=True, exist_ok=True)+ (profile_home / "config.yaml").write_text("memory:\n provider: twin\n", encoding="utf-8")+ monkeypatch.setenv("HERMES_HOME", str(root))+ monkeypatch.setattr("hermes_constants.get_default_hermes_root", lambda: root)+ monkeypatch.setattr(mig, "provider_present", lambda name, home: (home / "plugins" / name).is_dir())+ monkeypatch.setattr(mig, "catalog_source", lambda name: name)+ return homes+++def test_unattended_update_refusal_in_one_profile_does_not_skip_the_others(tmp_path, monkeypatch):+ """Unattended consent is each home's own allow_lazy_installs: the default home refusing says+ nothing about a profile that allows it, which must still migrate (not be reported as failed)."""+ import io++ from hermes_cli import plugins_cmd+ from hermes_constants import get_hermes_home+ from pm import install as pm_install++ default, work = _profile_homes(tmp_path, monkeypatch, "work")+ monkeypatch.setattr("pm.plugins_state.dependency_homes", lambda: [default, work])+ monkeypatch.setattr("sys.stdin", io.StringIO()) # Desktop / scripted `hermes update`: no terminal+ monkeypatch.setattr(pm_install, "lazy_installs_allowed", lambda: get_hermes_home() == work)++ def install(*_a, catalog_name, assume_deps_consent, **_kw):+ if not assume_deps_consent:+ return {"ok": False, "error": "dependency install skipped (non-interactive)"}+ (get_hermes_home() / "plugins" / catalog_name).mkdir(parents=True)+ return {"ok": True}++ monkeypatch.setattr(plugins_cmd, "dashboard_install_plugin", install)+ said: list[str] = []+ assert mig.migrate_all_homes(say=said.append) == ["twin"]+ assert (work / "plugins" / "twin").is_dir() and not (default / "plugins").exists()+ assert not any("either" in line for line in said)+++def test_startup_hint_installs_into_the_profile_that_printed_it(tmp_path, monkeypatch):+ """A bare `hermes plugins install` from a shell targets the sticky profile, so the hint an agent+ started for a named profile (Desktop, gateway, `hermes -p`) prints must carry `-p`."""+ from pm import install as pm_install++ default, work = _profile_homes(tmp_path, monkeypatch, "work")+ monkeypatch.setattr(pm_install, "lazy_installs_allowed", lambda: False)+ for profile_home, command in ((work, "hermes -p work plugins install twin"),+ (default, "hermes plugins install twin")):+ monkeypatch.setattr(mig, "_attempted", set())+ monkeypatch.setenv("HERMES_HOME", str(profile_home))+ said: list[str] = []+ assert mig.recover_at_startup("twin", say=said.append) is False+ assert f"`{command}`" in said[0]