The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(plugins): discover entrypoint capabilities
Jeeves Assistant17dc77315677
diff --git a/hermes_cli/plugins.py b/hermes_cli/plugins.pyindex 36b5ba24dc8..5124516ca03 100644--- a/hermes_cli/plugins.py+++ b/hermes_cli/plugins.py@@ -65,6 +65,7 @@ from hermes_cli.config import cfg_get, load_config_readonlyfrom hermes_cli.middleware import OBSERVER_SCHEMA_VERSION, VALID_MIDDLEWAREfrom hermes_cli.plugin_capabilities import ( # noqa: F401 — re-exportedCAPABILITY_REGISTRY,+ VALID_CAPABILITY_IDS,plugin_capability_granted,)from hermes_cli.plugin_capabilities import (@@ -391,6 +392,103 @@ SHELL_UNSUPPORTED_HOOKS: Set[str] = {}ENTRY_POINTS_GROUP = "hermes_agent.plugins"+ENTRY_POINT_CAPABILITIES_GROUP = "hermes_agent.plugin_capabilities"+++def _select_entry_point_group(entry_points: Any, group: str) -> list:+ """Return one metadata entry-point group across supported Python APIs."""+ if hasattr(entry_points, "select"):+ return list(entry_points.select(group=group))+ if isinstance(entry_points, dict):+ return list(entry_points.get(group, []))+ return [ep for ep in entry_points if ep.group == group]+++def discover_entrypoint_manifests() -> List["PluginManifest"]:+ """Return metadata-only manifests for installed entry-point plugins.++ Composes the full entry-point manifest contract in one place:++ * **Kind classification** — the module source is resolved import-free+ (``_resolve_module_source``) and scanned for provider markers+ (``_detect_kind_from_source``), so memory providers (``exclusive``)+ and model providers (``model-provider``) are routed to their own+ discovery systems instead of being eagerly imported here.+ * **Capability declarations** — read from the companion+ ``hermes_agent.plugin_capabilities`` entry-point group (declarations+ named ``<plugin-id>.<capability-id>`` pointing at the same object),+ so consent/introspection is accurate without importing plugin code.++ Failures are isolated per entry point: one malformed distribution must+ not blank the manifests of every other installed plugin.+ """+ manifests: List[PluginManifest] = []+ try:+ eps = importlib.metadata.entry_points()+ group_eps = _select_entry_point_group(eps, ENTRY_POINTS_GROUP)+ capability_eps = _select_entry_point_group(+ eps, ENTRY_POINT_CAPABILITIES_GROUP+ )+ except Exception as exc:+ logger.debug("Entry-point scan failed: %s", exc)+ return manifests++ for ep in group_eps:+ try:+ capabilities = []+ for capability in VALID_CAPABILITY_IDS:+ declaration_name = f"{ep.name}.{capability}"+ if any(+ declaration.name == declaration_name+ and declaration.value == ep.value+ for declaration in capability_eps+ ):+ capabilities.append(capability)+ dist = getattr(ep, "dist", None)+ metadata = getattr(dist, "metadata", None)+ manifest = PluginManifest(+ name=ep.name,+ version=str(getattr(dist, "version", "") or ""),+ description=(+ str(metadata.get("Summary", "") or "")+ if metadata is not None+ else ""+ ),+ source="entrypoint",+ path=ep.value,+ key=ep.name,+ capabilities=_parse_declared_capabilities(+ capabilities, ep.name+ ),+ )+ manifest.kind = _classify_entrypoint_value_kind(ep.value)+ manifests.append(manifest)+ except Exception as exc:+ logger.debug(+ "Entry-point manifest for %r skipped: %s",+ getattr(ep, "name", "?"),+ exc,+ )+ return manifests+++def _classify_entrypoint_value_kind(value: str) -> str:+ """Classify an entry-point target by import-free source scan.++ Module-level twin of ``PluginManager._classify_entrypoint_kind`` so+ ``discover_entrypoint_manifests()`` callers outside the manager (the+ CLI capabilities path) get identical routing. Unresolvable or+ non-Python modules stay ``standalone``.+ """+ try:+ module_name = str(value).split(":", 1)[0].strip()+ if not module_name:+ return "standalone"+ return _detect_kind_from_source(+ _resolve_module_source(module_name)+ ) or "standalone"+ except Exception:+ return "standalone"# System-prompt sections are deliberately more constrained than lifecycle# hooks. They become high-trust prompt bytes and are charged on every turn.@@ -4290,31 +4388,17 @@ class PluginManager:return "standalone"def _scan_entry_points(self) -> List[PluginManifest]:- """Check ``importlib.metadata`` for pip-installed plugins."""- manifests: List[PluginManifest] = []- try:- eps = importlib.metadata.entry_points()- # Python 3.12+ returns a SelectableGroups; earlier returns dict- if hasattr(eps, "select"):- group_eps = eps.select(group=ENTRY_POINTS_GROUP)- elif isinstance(eps, dict):- group_eps = eps.get(ENTRY_POINTS_GROUP, [])- else:- group_eps = [ep for ep in eps if ep.group == ENTRY_POINTS_GROUP]-- for ep in group_eps:- manifest = PluginManifest(- name=ep.name,- source="entrypoint",- path=ep.value,- key=ep.name,- )- manifest.kind = self._classify_entrypoint_kind(ep)- manifests.append(manifest)- except Exception as exc:- logger.debug("Entry-point scan failed: %s", exc)-- return manifests+ """Read installed plugin and companion capability entry points.++ Delegates to ``discover_entrypoint_manifests()``, which composes+ kind classification (import-free source scan routing memory/model+ providers away from the general manager) with capability+ declarations from the ``hermes_agent.plugin_capabilities`` group.+ Capability declarations live in distribution metadata so discovery+ is available before importing untrusted plugin code and does not+ depend on a package-data ``plugin.yaml`` being present.+ """+ return discover_entrypoint_manifests()# -----------------------------------------------------------------------# Loadingdiff --git a/tests/hermes_cli/test_plugin_capabilities.py b/tests/hermes_cli/test_plugin_capabilities.pyindex 059dd8ba4ee..7c9b619bffa 100644--- a/tests/hermes_cli/test_plugin_capabilities.py+++ b/tests/hermes_cli/test_plugin_capabilities.py@@ -7,6 +7,7 @@ and backward compatibility with the legacy ``allow_*`` gates.from __future__ import annotations+from types import SimpleNamespacefrom unittest.mock import MagicMock, patchimport pytest@@ -113,6 +114,45 @@ class TestDeclarationParsing:assert manifest is not Noneassert manifest.capabilities == []+ def test_entrypoint_companion_metadata_declares_capabilities_without_import(+ self, monkeypatch+ ):+ """Installed plugins can declare consent metadata in dist entry points."""+ from hermes_cli import plugins as plugins_mod+ from hermes_cli.plugins import PluginManager++ load = MagicMock(side_effect=AssertionError("plugin code must not be imported"))+ plugin_ep = SimpleNamespace(+ name="thread-namer",+ value="thread_namer.plugin:register",+ group="hermes_agent.plugins",+ dist=SimpleNamespace(+ version="1.2.3",+ metadata={"Summary": "Names gateway threads"},+ ),+ load=load,+ )+ capability_ep = SimpleNamespace(+ name="thread-namer.gateway.platform_actions",+ value="thread_namer.plugin:register",+ group="hermes_agent.plugin_capabilities",+ load=load,+ )+ monkeypatch.setattr(+ plugins_mod.importlib.metadata,+ "entry_points",+ lambda: [plugin_ep, capability_ep],+ )++ manifests = PluginManager()._scan_entry_points()++ assert len(manifests) == 1+ assert manifests[0].name == "thread-namer"+ assert manifests[0].version == "1.2.3"+ assert manifests[0].description == "Names gateway threads"+ assert manifests[0].capabilities == ["gateway.platform_actions"]+ load.assert_not_called()+# ── Consent grant + persistence ──────────────────────────────────────────────diff --git a/tests/hermes_cli/test_plugins_cmd_list.py b/tests/hermes_cli/test_plugins_cmd_list.pyindex e40e7de53fd..9c8ffe60422 100644--- a/tests/hermes_cli/test_plugins_cmd_list.py+++ b/tests/hermes_cli/test_plugins_cmd_list.py@@ -94,3 +94,36 @@ def test_discover_all_plugins_includes_entrypoint_plugins(monkeypatch, tmp_path)]+def test_declared_capabilities_for_entrypoint_uses_distribution_metadata(+ monkeypatch, tmp_path+):+ bundled_dir = tmp_path / "bundled"+ user_dir = tmp_path / "user"+ bundled_dir.mkdir()+ user_dir.mkdir()+ plugin_ep = SimpleNamespace(+ name="thread-namer",+ value="thread_namer.plugin:register",+ group="hermes_agent.plugins",+ dist=SimpleNamespace(version="1.0", metadata={"Summary": ""}),+ )+ capability_ep = SimpleNamespace(+ name="thread-namer.gateway.platform_actions",+ value="thread_namer.plugin:register",+ group="hermes_agent.plugin_capabilities",+ )+ monkeypatch.setattr(plugins_cmd, "_plugins_dir", lambda: user_dir)+ monkeypatch.setattr(+ "hermes_cli.plugins.get_bundled_plugins_dir", lambda: bundled_dir+ )+ monkeypatch.setattr(+ plugins_cmd.importlib.metadata,+ "entry_points",+ lambda: [plugin_ep, capability_ep],+ )++ assert plugins_cmd._declared_capabilities_for_key("thread-namer") == [+ "gateway.platform_actions"+ ]++