The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(memory): detect providers past the first 8 KB of __init__.py
Tekniuma114e7a3444f
diff --git a/plugins/memory/__init__.py b/plugins/memory/__init__.pyindex 46a06f3a945..6c1c3d13cac 100644--- a/plugins/memory/__init__.py+++ b/plugins/memory/__init__.py@@ -63,13 +63,14 @@ def _get_project_plugins_dir() -> Optional[Path]:def _is_memory_provider_dir(path: Path) -> bool:- """Cheap text heuristic (no import): ``__init__.py`` mentions the memory provider contract."""+ """Cheap text heuristic (no import): ``__init__.py`` mentions the memory provider contract.+ A miss in the first 8 KB falls back to parsing, so a long module docstring cannot hide a provider."""init_file = path / "__init__.py"try:if not init_file.exists():return Falsesource = init_file.read_text(errors="replace", encoding="utf-8-sig")[:8192]- return "register_memory_provider" in source or "MemoryProvider" in source+ return "register_memory_provider" in source or "MemoryProvider" in source or _defines_memory_provider(path)except OSError as exc: # one mode-000 / ACL-denied child must not abort discoverylogger.warning("Skipping unreadable plugin directory %s: %s", path, exc)return Falsediff --git a/tests/plugins/memory/test_discovery_sources.py b/tests/plugins/memory/test_discovery_sources.pyindex 439de730ef0..ab4c8d3e9b0 100644--- a/tests/plugins/memory/test_discovery_sources.py+++ b/tests/plugins/memory/test_discovery_sources.py@@ -221,6 +221,18 @@ def test_activation_is_not_gated_on_plugins_enabled(tmp_path, monkeypatch):assert memory_plugins.load_memory_provider("gatedmem") is not None+def test_provider_registered_past_the_first_8kb_is_discovered(tmp_path, monkeypatch):+ """A long module docstring must not push the registration out of discovery's view."""+ provider = tmp_path / "plugins" / "longdoc"+ provider.mkdir(parents=True)+ docstring = '"""' + "Plain prose about storage.\n" * 400 + '"""\n' # ~10.8 KB, no contract tokens+ (provider / "__init__.py").write_text(docstring + PROVIDER_SOURCE.format(name="longdoc"), encoding="utf-8")+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))++ assert "longdoc" in memory_plugins.list_memory_provider_names()+ assert memory_plugins.find_provider_dir("longdoc") == provider++def test_unreadable_user_plugin_does_not_abort_memory_discovery(tmp_path, monkeypatch):"""One mode-000 / ACL-denied ``$HERMES_HOME/plugins/<x>`` must not hide the bundledproviders or its readable siblings from the dashboard / ``hermes memory`` pickers (#111804)."""