The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(models): admit every plugin provider to the picker by slug; catalogs fall back to the profile
teknium16f12165a9458
diff --git a/hermes_cli/model_switch_providers.py b/hermes_cli/model_switch_providers.pyindex 7b3001cfc47..c2aa01b50d0 100644--- a/hermes_cli/model_switch_providers.py+++ b/hermes_cli/model_switch_providers.py@@ -937,14 +937,14 @@ def _lap_canonical_rows(b: _PickerBuild) -> None:continuehas_creds = has_creds or _auth_store_has_provider(cp.slug) or _pool_usable(cp.slug) or (_is_aws_sdk(cp_config) and _has_aws_sdk_creds_for_listing(cp.slug, b.current_provider))- if not has_creds and cp_config is not None and getattr(cp_config, "auth_type", "") == "external_process":- # Subprocess-backed providers own their auth; structural reachability- # (the binary resolves) is the credential evidence for listing.+ if not has_creds and cp_config is not None and cp_config.auth_type == "external_process":+ # Subprocess-backed providers own their auth; the binary resolving is the credential+ # evidence for listing (same gate as the copilot-acp overlay row and hermes auth status).try:from hermes_cli.auth import get_external_process_provider_statushas_creds = bool(get_external_process_provider_status(cp.slug).get("configured"))- except Exception:- has_creds = False+ except Exception as exc:+ logger.debug("External-process check failed for %s: %s", cp.slug, exc)if not has_creds:continueif _is_aws_sdk(cp_config):@@ -952,10 +952,6 @@ def _lap_canonical_rows(b: _PickerBuild) -> None:else:model_ids = _live_or_curated_ids(cp.slug, b.curated, merge_models_dev=False,non_blocking=b.non_blocking_catalogs)- if not model_ids and cp_config is not None and getattr(cp_config, "auth_type", "") == "external_process":- # No models.dev / curated entry exists for agent CLIs; the provider- # name is itself the selectable model (maps to the session default).- model_ids = [cp.slug]b.add_builtin_row(cp.slug, cp.label, cp.slug == b.current_provider, model_ids, "canonical", uncapped_ok=False)diff --git a/hermes_cli/models.py b/hermes_cli/models.pyindex fb0a026b0f3..d03d15c6b98 100644--- a/hermes_cli/models.py+++ b/hermes_cli/models.py@@ -1504,21 +1504,17 @@ def _profile_live_catalog(normalized: str) -> Optional[list[str]]:from providers import get_provider_profileprofile = get_provider_profile(normalized)- # external_process providers (ACP agent CLIs) have no api_key/base_url credentials:- # the profile's fetch_models drives its own subprocess, so let it supply the catalog.- if profile and profile.auth_type == "external_process":- # Signature tolerance: external_process profiles own their subprocess and most take no- # kwargs, but a profile may require keyword-only HTTP credentials (#111194 hardened- # discovery the same way). Probe no-args first, fall back to credential kwargs.- try:- live = profile.fetch_models()- except TypeError:- api_key, base_url = _api_key_credentials(normalized)- live = profile.fetch_models(- api_key=api_key, base_url=base_url or profile.base_url or None)- return list(live) if live else None- if not (profile and profile.auth_type == "api_key" and profile.base_url):+ if not profile:return None+ # external_process providers (ACP agent CLIs) have no api_key/base_url credentials: the+ # profile's fetch_models drives its own subprocess (kwargs are ignored per the base contract).+ # Every non-api-key profile falls back to its own fallback_models (OAuth plugins have no+ # static _PROVIDER_MODELS row), exactly as api_key plugins do below.+ if profile.auth_type == "external_process":+ live = profile.fetch_models()+ return list(live) if live else (list(profile.fallback_models) or None)+ if not (profile.auth_type == "api_key" and profile.base_url):+ return list(profile.fallback_models) or Noneapi_key, base_url = _api_key_credentials(normalized)live = profile.fetch_models(api_key=api_key, base_url=base_url or profile.base_url or None) if api_key else Noneif live and normalized in _LIVE_FIRST_PICKER_PROVIDERS:@@ -1666,6 +1662,18 @@ def _credential_fingerprint(provider: str) -> str:except Exception:pass+ # External-process providers discover models through the launched program, so the command /+ # argv env overrides identify the catalog the way an API key identifies an HTTP catalog.+ try:+ from providers import get_provider_profile+ profile = get_provider_profile(provider)+ if profile is not None and profile.auth_type == "external_process":+ for ev in (*profile.process_command_env_vars, profile.process_args_env_var):+ if ev:+ parts.append(f"{ev}={os.environ.get(ev, '')}")+ except Exception:+ pass+# config.yaml's model.base_url changes the endpoint discovery probes (data-residency hosts)# without touching any env var, so it must change the fingerprint too.if provider in ("openai", "openai-api"):diff --git a/hermes_cli/models_catalog_static.py b/hermes_cli/models_catalog_static.pyindex 03bc8473e85..38cde0aab05 100644--- a/hermes_cli/models_catalog_static.py+++ b/hermes_cli/models_catalog_static.py@@ -347,18 +347,18 @@ CANONICAL_PROVIDERS: list[ProviderEntry] = [ProviderEntry(*row) for row in (# Auto-extend CANONICAL_PROVIDERS with providers registered under plugins/model-providers/<name>/# so a new provider reaches the picker, /model and every downstream consumer without edits here.-# Auth classes whose picker selection needs bespoke UX (OAuth device flows, vendor CLIs) are-# skipped; external_process providers are admitted because their picker row is honest —-# `_provider_has_credentials` routes through auth.get_external_process_provider_status, which-# reports configured only when the subprocess binary resolves, and selection rides the standard-# model_switch pipeline.+# Admission is by slug only: every in-tree non-api-key profile (OAuth, external-process, cloud+# SDK) already owns a hand-written row above, so the old auth_type skip set never excluded an+# in-tree provider — it only hid out-of-tree plugins. Visibility is gated downstream by+# credentials, not here: ``models._provider_has_credentials`` / ``_lap_canonical_rows`` route+# through ``auth.get_auth_status`` (external_process → the binary resolves; OAuth → auth.json /+# credential-pool entry), so an admitted row reads authenticated=False until the user signs in._canonical_slugs = {p.slug for p in CANONICAL_PROVIDERS}-_BESPOKE_UX_AUTH_TYPES = {"oauth_device_code", "oauth_external", "aws_sdk", "copilot", "vertex"}def _plugin_provider_enters_picker(pp) -> bool:- """Picker admission for a plugin model-provider profile."""- return pp.name not in _canonical_slugs and pp.auth_type not in _BESPOKE_UX_AUTH_TYPES+ """Picker admission for a plugin model-provider profile: any slug without a built-in row."""+ return pp.name not in _canonical_slugstry:diff --git a/tests/hermes_cli/test_plugin_acp_picker_parity.py b/tests/hermes_cli/test_plugin_acp_picker_parity.pydeleted file mode 100644index 95fbdc0c4c7..00000000000--- a/tests/hermes_cli/test_plugin_acp_picker_parity.py+++ /dev/null@@ -1,182 +0,0 @@-"""Picker parity for plugin external-process (ACP) providers.--Regression: the CANONICAL_PROVIDERS auto-extend skipped every plugin-`auth_type="external_process"` provider, so plugin ACP backends never reached-`/model` / `list_available_providers()` — while the in-tree copilot-acp-provider (same auth_type, hardcoded list entry) does appear. Selection already-works through the standard model_switch pipeline, and the authenticated flag-comes from auth.get_external_process_provider_status; only picker admission-was missing.-"""--from types import SimpleNamespace--import pytest---def _profile(name: str, auth_type: str) -> SimpleNamespace:- return SimpleNamespace(- name=name, auth_type=auth_type, display_name=name.title(),- description=f"{name} test provider", aliases=(),- )---def test_external_process_plugin_provider_admitted():- from hermes_cli.models_catalog_static import _plugin_provider_enters_picker-- assert _plugin_provider_enters_picker(_profile("acme-acp", "external_process")) is True---def test_explicit_client_kwargs_launches_any_external_process_profile(monkeypatch):- """Launch kwargs are keyed on the provider profile's auth_type, not a hardcoded- vendor slug: an out-of-tree external_process provider gets the same ACP launch- path (command/args) as copilot-acp (#102421)."""- import providers as providers_mod- from agent.agent_init import _explicit_client_kwargs-- class _Agent:- provider = "acme-acp"- acp_command = ["acme"]- acp_args = ["--stdio"]-- monkeypatch.setattr(providers_mod, "get_provider_profile",- lambda name: SimpleNamespace(auth_type="external_process"))- kwargs = _explicit_client_kwargs(_Agent(), api_key=None, base_url=None, _provider_timeout=None)- assert kwargs["command"] == ["acme"] and kwargs["args"] == ["--stdio"]---def test_explicit_client_kwargs_copilot_acp_still_launches(monkeypatch):- """The built-in copilot-acp provider keeps its launch kwargs through the generic- profile-keyed path — same contract, now without the vendor hardcode."""- import providers as providers_mod- from agent.agent_init import _explicit_client_kwargs-- class _Agent:- provider = "copilot-acp"- acp_command = ["copilot"]- acp_args = []-- monkeypatch.setattr(providers_mod, "get_provider_profile",- lambda name: SimpleNamespace(auth_type="external_process"))- kwargs = _explicit_client_kwargs(_Agent(), api_key=None, base_url=None, _provider_timeout=None)- assert kwargs["command"] == ["copilot"]--[email protected]("auth_type", ["oauth_device_code", "oauth_external", "aws_sdk", "copilot", "vertex"])-def test_bespoke_auth_classes_still_excluded(auth_type):- from hermes_cli.models_catalog_static import _plugin_provider_enters_picker-- assert _plugin_provider_enters_picker(_profile("acme-" + auth_type.replace("_", ""), auth_type)) is False---def test_api_key_plugin_providers_unchanged():- from hermes_cli.models_catalog_static import _plugin_provider_enters_picker-- assert _plugin_provider_enters_picker(_profile("acme-api", "api_key")) is True---def test_live_catalog_tolerates_credential_kwargs_fetch_models():- """A signature-strict external_process profile (fetch_models requiring keyword-only- api_key/base_url) still yields its catalog: probe no-args, fall back to credentials- (#111194 hardened discovery the same way)."""- from hermes_cli.models import _profile_live_catalog-- def _strict_fetch(*, api_key, base_url):- assert api_key, "credential kwargs must be passed on the TypeError fallback"- return ["acme-pro"]-- profile = SimpleNamespace(- auth_type="external_process", fetch_models=_strict_fetch,- base_url="https://acme.example/v1",- )- import providers as providers_mod- import hermes_cli.models as models_mod- orig = getattr(providers_mod, "get_provider_profile", None)- providers_mod.get_provider_profile = lambda name: profile- orig_creds = models_mod._api_key_credentials- models_mod._api_key_credentials = lambda normalized: ("test-key", None)- try:- assert _profile_live_catalog("acme-acp") == ["acme-pro"]- finally:- if orig is not None:- providers_mod.get_provider_profile = orig- models_mod._api_key_credentials = orig_creds---def test_external_process_providers_in_model_options_payload(monkeypatch):- """Layer 1 admits it into CANONICAL_PROVIDERS; layer 2 (inventory) seats a- row with a self-named model, reachability as the credential."""- import hermes_cli.auth as auth- import hermes_cli.inventory as inv- import hermes_cli.models as models-- fake = _make_registry_profile()- monkeypatch.setattr("providers.list_providers", lambda: [fake])- monkeypatch.setattr(auth, "get_external_process_provider_status", lambda slug: {"configured": True})- entry = models.ProviderEntry("ext-proc", "Ext Proc", "external process test provider")- monkeypatch.setattr(models, "CANONICAL_PROVIDERS", list(models.CANONICAL_PROVIDERS) + [entry])- ctx = inv.ConfigContext(- current_provider="zai", current_model="glm-5.3",- current_base_url="https://api.z.ai/api/coding/paas/v4",- user_providers={}, custom_providers=[])- payload = inv.build_model_options_payload(ctx, explicit_only=False)- rows = [p for p in payload["providers"] if p.get("slug") == "ext-proc"]- assert rows, "external_process plugin provider missing from model.options payload"- assert rows[0]["models"] == ["ext-proc"]- assert rows[0]["authenticated"] is True---def test_unresolvable_external_process_binary_not_listed(monkeypatch):- """Reachability is the credential: a binary that doesn't resolve stays hidden."""- import hermes_cli.auth as auth- import hermes_cli.inventory as inv- import hermes_cli.models as models-- fake = _make_registry_profile()- monkeypatch.setattr("providers.list_providers", lambda: [fake])- monkeypatch.setattr(- auth, "get_external_process_provider_status",- lambda slug: {"configured": False})- entry = models.ProviderEntry("ext-proc", "Ext Proc", "external process test provider")- monkeypatch.setattr(models, "CANONICAL_PROVIDERS", list(models.CANONICAL_PROVIDERS) + [entry])- ctx = inv.ConfigContext(- current_provider="zai", current_model="glm-5.3", current_base_url="",- user_providers={}, custom_providers=[])- payload = inv.build_model_options_payload(ctx, explicit_only=False)- assert not [p for p in payload["providers"] if p.get("slug") == "ext-proc"]---def _make_registry_profile():- """A profile + matching ProviderConfig, registered in both registries."""- from types import SimpleNamespace- profile = SimpleNamespace(- name="ext-proc", auth_type="external_process", display_name="Ext Proc",- description="external process test provider", aliases=(),- process_command="/fake/does-not-exist", process_args=("acp",),- )- import hermes_cli.auth as auth- registry_entry = SimpleNamespace(- name="ext-proc", display_name="Ext Proc", auth_type="external_process",- api_key_env_vars=(), base_url="acp://ext", inference_base_url="acp://ext",- command="ext-proc", args=("acp",), base_url_env_var=None,- )- auth.PROVIDER_REGISTRY.setdefault("ext-proc", registry_entry)- return profile---def test_auto_extend_seats_external_process_provider(monkeypatch):- """Integration through the real auto-extend loop (reloaded with a stubbed- plugin registry, mirroring discovery output)."""- import importlib- import providers- import hermes_cli.models_catalog_static as mcs-- fake = [_profile("acme-acp", "external_process"), _profile("acme-oauth", "oauth_external")]- monkeypatch.setattr(providers, "list_providers", lambda: fake)- reloaded = importlib.reload(mcs)- try:- ids = [p.slug for p in reloaded.CANONICAL_PROVIDERS]- assert "acme-acp" in ids- assert "acme-oauth" not in ids- finally:- importlib.reload(mcs) # restore the real module statediff --git a/tests/hermes_cli/test_plugin_provider_picker_admission.py b/tests/hermes_cli/test_plugin_provider_picker_admission.pynew file mode 100644index 00000000000..b482df29a71--- /dev/null+++ b/tests/hermes_cli/test_plugin_provider_picker_admission.py@@ -0,0 +1,61 @@+"""Picker admission for out-of-tree provider plugins with non-api-key auth types.++Regression: the CANONICAL_PROVIDERS auto-extend skipped every plugin profile whose ``auth_type``+was not ``api_key``, so an out-of-tree external-process (ACP) or OAuth provider loaded, inferred and+was invisible to ``/model``, ``hermes model`` and ``list_available_providers()`` — while the in-tree+copilot-acp row (same auth_type, hand-written entry) appeared. Visibility is gated by credentials+downstream, so admission by slug is safe (#102421).+"""++import os+import stat++import pytest+++def _register(monkeypatch, profile):+ import providers+ from hermes_cli import auth++ monkeypatch.setitem(providers._REGISTRY, profile.name, profile)+ monkeypatch.delitem(auth.PROVIDER_REGISTRY, profile.name, raising=False)+ auth._register_plugin_provider(profile) # what plugin discovery does at import time+ monkeypatch.setitem(auth.PROVIDER_REGISTRY, profile.name, auth.PROVIDER_REGISTRY[profile.name])++[email protected]("auth_type", ["external_process", "oauth_external", "oauth_device_code", "api_key"])+def test_plugin_profiles_are_admitted_by_slug_not_auth_type(auth_type):+ from providers.base import ProviderProfile+ from hermes_cli.models_catalog_static import CANONICAL_PROVIDERS, _plugin_provider_enters_picker++ assert _plugin_provider_enters_picker(ProviderProfile(name="acme-plugin", auth_type=auth_type)) is True+ # A plugin re-declaring a built-in slug is deduped, never doubled (bedrock is aws_sdk in-tree).+ assert _plugin_provider_enters_picker(ProviderProfile(name="bedrock", auth_type="aws_sdk")) is False+ assert [p.slug for p in CANONICAL_PROVIDERS].count("bedrock") == 1+++def test_external_process_plugin_authenticated_flag_tracks_binary_and_catalog_uses_fallback(+ monkeypatch, tmp_path):+ """The row's authenticated flag is the real binary-resolves gate (not a hardcoded slug), and the+ profile's fallback_models is its catalog when the subprocess probe yields nothing."""+ from providers.base import ProviderProfile+ from hermes_cli import models, models_catalog_static++ exe = tmp_path / "acme-acp"+ exe.write_text("#!/bin/sh\nexit 0\n")+ exe.chmod(exe.stat().st_mode | stat.S_IXUSR)+ profile = ProviderProfile(+ name="acme-acp", auth_type="external_process", base_url="acp://acme", process_command="acme-acp",+ fallback_models=("acme-acp",))+ _register(monkeypatch, profile)+ entry = models_catalog_static.ProviderEntry("acme-acp", "Acme ACP", "acme")+ monkeypatch.setattr(models, "CANONICAL_PROVIDERS", [*models.CANONICAL_PROVIDERS, entry])++ def authenticated():+ return {r["id"]: r["authenticated"] for r in models.list_available_providers()}["acme-acp"]++ monkeypatch.setenv("PATH", f"{tmp_path}{os.pathsep}{os.environ.get('PATH', '')}")+ assert authenticated() is True+ monkeypatch.setenv("PATH", str(tmp_path / "nowhere"))+ assert authenticated() is False+ assert models.provider_model_ids("acme-acp") == ["acme-acp"]diff --git a/website/docs/developer-guide/model-provider-plugin.md b/website/docs/developer-guide/model-provider-plugin.mdindex fcdb077ee26..d012739f202 100644--- a/website/docs/developer-guide/model-provider-plugin.md+++ b/website/docs/developer-guide/model-provider-plugin.md@@ -206,6 +206,17 @@ An agent CLI driven over stdio is not an HTTP endpoint. Set `auth_type="externalThe client your `create_client` returns receives `command` and `args` in `client_kwargs`. If it is already complete and async-safe, declare `HERMES_SKIP_TRANSPORT_WRAP = True` / `HERMES_SKIP_ASYNC_WRAP = True` as class attributes so the auxiliary client does not re-dispatch it through an HTTP wire adapter.+### Picker rows for non-api-key plugins++Every registered profile joins `CANONICAL_PROVIDERS` by slug (a plugin re-declaring a built-in slug such as `bedrock` is deduped, never doubled), so external-process and OAuth plugins appear in `hermes model`, `/model` and the Desktop model selector alongside `copilot-acp`. Visibility is gated by credentials, not by `auth_type`:++| `auth_type` | Row is listed / `authenticated` when | Model list |+|---|---|---|+| `external_process` | the binary resolves (`process_command` or one of `process_command_env_vars` is on `PATH`), or `base_url` is `acp+tcp://…` — the same structural gate `hermes auth status` reports | `fetch_models()` (your subprocess probe), else `fallback_models` |+| `oauth_external` / `oauth_device_code` | `auth.json` or the credential pool holds an entry for the slug | `fallback_models` (declare at least one) |++The catalog cache is keyed on the profile's `process_command_env_vars` / `process_args_env_var` values, so pointing `HERMES_<X>_COMMAND` at a different binary re-discovers models. Executable discovery is not a login check: an unauthenticated CLI still lists, and the subprocess reports the failure at first use.+## Hook reference examplesLook at these bundled plugins for idioms: