The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(plugins): decide "memory provider" on install from code, not a text match
Teknium7c46cd9ff7ce
diff --git a/hermes_cli/plugins_cmd_install.py b/hermes_cli/plugins_cmd_install.pyindex 9e6443deb78..2684d04d771 100644--- a/hermes_cli/plugins_cmd_install.py+++ b/hermes_cli/plugins_cmd_install.py@@ -563,9 +563,10 @@ def cmd_install(if no_deps:console.print("[dim]--no-deps: skipping dependency consent; the plugin stays disabled.[/dim]")# A memory provider activates through memory.provider alone; the loader never reads plugins.enabled.- # Decide from the installed tree: catalog category "memory" also holds hooks, context engines and skills.- from plugins.memory import _is_memory_provider_dir- is_memory_provider = _is_memory_provider_dir(target)+ # Decide from the installed tree's code (not a text match): catalog category "memory" also holds hooks,+ # context engines and skills, and a hook's docstring may name MemoryProvider.+ from plugins.memory import _defines_memory_provider+ is_memory_provider = _defines_memory_provider(target)if should_enable is None and not already_active:should_enable = _pc()._is_tty() and _pc()._ask_yes(f" Use '{installed_name}' as the memory provider now? [y/N]: " if is_memory_providerdiff --git a/plugins/memory/__init__.py b/plugins/memory/__init__.pyindex 815c82ed6b8..890b3e49e5d 100644--- a/plugins/memory/__init__.py+++ b/plugins/memory/__init__.py@@ -9,6 +9,7 @@ must never shadow a shipped provider. Changing this order is a breaking change.from __future__ import annotations+import astimport hashlibimport importlib.metadataimport importlib.util@@ -74,6 +75,27 @@ def _is_memory_provider_dir(path: Path) -> bool:return False+def _defines_memory_provider(path: Path) -> bool:+ """Parse (never import) the package's top-level modules for what ``_load_provider_from_dir`` can load:+ a ``register_memory_provider(...)`` call or a ``MemoryProvider`` subclass. Unlike the discovery+ heuristic, a docstring or comment naming the contract does not count."""+ for module in sorted(path.glob("*.py")):+ try:+ tree = ast.parse(module.read_text(errors="replace", encoding="utf-8-sig"))+ except (OSError, SyntaxError, ValueError):+ continue+ bases = {"MemoryProvider"} | {a.asname for n in ast.walk(tree) if isinstance(n, ast.ImportFrom)+ for a in n.names if a.name == "MemoryProvider" and a.asname}+ for node in ast.walk(tree):+ if isinstance(node, ast.Call) and "register_memory_provider" in (+ getattr(node.func, "attr", None), getattr(node.func, "id", None)):+ return True+ if isinstance(node, ast.ClassDef) and any(+ (getattr(b, "attr", None) or getattr(b, "id", None)) in bases for b in node.bases):+ return True+ return False++def _is_bundled(provider_dir: Path) -> bool:return _MEMORY_PLUGINS_DIR in provider_dir.parents or provider_dir.parent == _MEMORY_PLUGINS_DIRdiff --git a/tests/hermes_cli/test_plugins_cmd_catalog.py b/tests/hermes_cli/test_plugins_cmd_catalog.pyindex 0f98693ab59..393939f09b5 100644--- a/tests/hermes_cli/test_plugins_cmd_catalog.py+++ b/tests/hermes_cli/test_plugins_cmd_catalog.py@@ -332,16 +332,28 @@ def test_kill_list_covers_update_enable_and_load_of_an_installed_plugin(world, tassert gate_manifest(manifest, set(), {"killed"}).action == "load"[email protected]("provider,enable", [(True, True), (True, False), (False, True)])+_HOOK = "def register(ctx):\n ctx.register_hook('pre_llm_call', print)\n"+++_PROVIDER = "def register(ctx):\n ctx.register_memory_provider(object())\n"++[email protected]("init,enable", [+ (_PROVIDER, True),+ (_PROVIDER, False),+ (_HOOK, True),+ ('"""Recall hook. Not a MemoryProvider: it only injects context."""\n' + _HOOK, True),+])def test_memory_category_install_activates_via_memory_provider_not_plugins_enable(world, monkeypatch,- provider, enable):+ init, enable):"""A memory provider activates through memory.provider alone — the loader never consultsplugins.enabled — so "Enable now?" must select the provider, and a decline must point at`hermes memory setup`, never at the dead-end `plugins enable` hint. Catalog category "memory" also- holds hook plugins: those enable normally and leave the user's memory.provider alone."""+ holds hook plugins: those enable normally and leave the user's memory.provider alone, even when their+ docstring names MemoryProvider (the loader would return None for them)."""repo = world["repo"]- (repo / "__init__.py").write_text("def register_memory_provider(ctx):\n pass\n" if provider- else "def register(ctx):\n ctx.register_hook('pre_llm_call', print)\n")+ provider = init is _PROVIDER+ (repo / "__init__.py").write_text(init)world["state"]["pin"] = _commit(repo, "memory category plugin")def _memory_entries():@@ -381,7 +393,8 @@ def test_url_install_of_a_memory_provider_dir_gets_the_provider_hint(world, tmp_repo = tmp_path / "mem-repo"repo.mkdir()(repo / "plugin.yaml").write_text("name: mem-plugin\nversion: 1.0.0\ndescription: d\n")- (repo / "__init__.py").write_text("from plugins.memory import MemoryProvider\n")+ (repo / "__init__.py").write_text("from agent.memory_provider import MemoryProvider\n\n\n"+ "class Mem(MemoryProvider):\n pass\n")sp.run(["git", "init", "-q"], cwd=repo, check=True, env=_GIT_ENV)_commit(repo, "v1")