Skip to content

The agent that grows with you

fix(plugins): a user model provider reports enabled only where provider discovery loads it

unsupportedpastels80309111b480
diff --git a/hermes_cli/plugins_cmd.py b/hermes_cli/plugins_cmd.py
index 4d3e39d167d..f9f9bd02fda 100644
--- a/hermes_cli/plugins_cmd.py
+++ b/hermes_cli/plugins_cmd.py
@@ -740,8 +740,11 @@ _BUNDLED_DEFAULT_ON_KINDS = frozenset({"backend", "platform", "model-provider"})
def _default_on(dir_path, source: str) -> bool:
"""True when a plugin is active without a ``plugins.enabled`` entry (portable ``plugin.json``
- packages have no kind, so never). Model providers load through providers/ discovery from any
- source (``gate_manifest``); the other default-on kinds only when bundled.
+ packages have no kind, so never). Bundled default-on kinds always; a user model provider only
+ where providers/ discovery loads it (``providers._scan_home_layer``): a
+ ``plugins/model-providers/<name>/`` child whose kind is model-provider, or a flat
+ ``plugins/<name>/`` child declaring exactly ``kind: model-provider``. Discovery imports any other
+ ``model-providers/`` child too, but nothing calls its ``register(ctx)``, so it is not on.
Entry-point rows store ``module:attr`` in the path slot. That string is not a directory;
opening it as one is WinError 123 on Windows and aborts the whole plugin list.
@@ -749,6 +752,13 @@ def _default_on(dir_path, source: str) -> bool:
path = Path(dir_path)
if not path.is_dir():
return False
+ if source != "bundled":
+ from providers import _declares_model_provider_kind
+ root = _plugins_dir()
+ if path.name.startswith(("_", ".")) or path.parent not in (root, root / "model-providers"):
+ return False
+ if path.parent == root:
+ return _declares_model_provider_kind(path)
manifest_file = _native_manifest_file(path)
if manifest_file is None:
return False
diff --git a/tests/hermes_cli/test_plugins_cmd_activation_keys.py b/tests/hermes_cli/test_plugins_cmd_activation_keys.py
index 3d9a26f322b..d05f39fd893 100644
--- a/tests/hermes_cli/test_plugins_cmd_activation_keys.py
+++ b/tests/hermes_cli/test_plugins_cmd_activation_keys.py
@@ -122,3 +122,26 @@ def test_status_matches_the_loader_for_a_user_installed_model_provider(home):
name, _v, _d, source, dir_path, _k = by_key["fakeprov"]
assert plugins_cmd._plugin_status(name, enabled, {"fakeprov"}, key="fakeprov", source=source,
dir_path=dir_path) == "disabled"
+
+
+def test_status_enables_a_user_model_provider_only_where_provider_discovery_imports_it(home):
+ """providers/ discovery imports every ``plugins/model-providers/<name>/`` child, but a flat
+ ``plugins/<name>/`` one only when it declares exactly ``kind: model-provider``. A provider in a
+ category directory, or flat with a differently-cased kind, never loads, so status must not call
+ it enabled. A non-provider under ``model-providers/`` is imported but never registered."""
+ import providers
+
+ for rel, kind in (("flatprov", "model-provider"), ("model-providers/subprov", "model-provider"),
+ ("model-providers/subcaps", "MODEL-PROVIDER"), ("custom/nestedprov", "model-provider"),
+ ("model-providers/substand", "standalone"), ("capsprov", "MODEL-PROVIDER")):
+ d = _write_plugin(home / "plugins", rel, rel.rsplit("/", 1)[-1], f"kind: {kind}\n")
+ (d / "__init__.py").write_text(f"open({str(d / 'imported')!r}, 'w').close()\n", encoding="utf-8")
+ providers._scan_home_layer(providers._HomeLayer(), str(home))
+
+ rows = {e[5]: e for e in plugins_cmd._discover_all_plugins() if e[3] == "user"}
+ imported = {key: (row[4] / "imported").exists() for key, row in rows.items()}
+ assert imported == {"flatprov": True, "model-providers/subprov": True, "model-providers/subcaps": True,
+ "model-providers/substand": True, "custom/nestedprov": False, "capsprov": False}
+ status = {key: plugins_cmd._plugin_status(row[0], set(), set(), key=key, source=row[3], dir_path=row[4])
+ == "enabled" for key, row in rows.items()}
+ assert status == {**imported, "model-providers/substand": False}