The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: admitted plugin providers are selectable and status-accurate on every surface
teknium1f7240ca980bb
diff --git a/agent/account_usage.py b/agent/account_usage.pyindex f94d410f881..5f8641e9b67 100644--- a/agent/account_usage.py+++ b/agent/account_usage.py@@ -635,6 +635,28 @@ _USAGE_FETCHERS: dict[str, Callable[[Optional[str], Optional[str]], Optional[Acc}+# Wall-clock bound on a plugin profile's ``fetch_account_usage`` hook. The built-in fetchers above carry+# their own httpx timeouts; a plugin hook is arbitrary code, and the gateway/TUI ``/usage`` paths await+# this function with no deadline of their own (only the CLI wraps it in a 10 s future), so the bound+# lives here where every surface shares it.+PLUGIN_USAGE_HOOK_DEADLINE_S = 10.0+++def _call_plugin_usage_hook(profile, base_url: Optional[str], api_key: Optional[str]) -> Optional[AccountUsageSnapshot]:+ """Run the profile hook on a daemon thread; past the deadline (or on any exception) → None."""+ import contextvars+ import threading+ result: list = []+ context = contextvars.copy_context() # the hook may read profile-scoped secrets+ worker = threading.Thread(+ target=lambda: result.append(+ context.run(profile.fetch_account_usage, base_url=base_url, api_key=api_key)),+ name="plugin-account-usage", daemon=True)+ worker.start()+ worker.join(PLUGIN_USAGE_HOOK_DEADLINE_S)+ return result[0] if result else None++def fetch_account_usage(provider: Optional[str], *, base_url: Optional[str] = None, api_key: Optional[str] = None,) -> Optional[AccountUsageSnapshot]:@@ -645,6 +667,6 @@ def fetch_account_usage(from providers import get_provider_profileprofile = get_provider_profile(str(provider or "").strip().lower())- return profile.fetch_account_usage(base_url=base_url, api_key=api_key) if profile else None+ return _call_plugin_usage_hook(profile, base_url, api_key) if profile else Noneexcept Exception:return Nonediff --git a/agent/agent_init.py b/agent/agent_init.pyindex a038cc2971f..e8783ff2a86 100644--- a/agent/agent_init.py+++ b/agent/agent_init.py@@ -478,7 +478,6 @@ def _finalize_routing(agent, api_mode, credential_pool):api_mode is Noneand agent.api_mode == "chat_completions"and not is_actual_route(agent.provider, agent.base_url)- and agent.provider != "copilot-acp"and not _base_lower.startswith(("acp://", "acp+tcp://"))and not agent._is_azure_openai_url()and (diff --git a/hermes_cli/auth.py b/hermes_cli/auth.pyindex 058ca6da25c..c6d34e36a61 100644--- a/hermes_cli/auth.py+++ b/hermes_cli/auth.py@@ -257,7 +257,7 @@ from hermes_cli.config import ( # noqa: E402# Plugin profiles (plugins/model-providers/<name>/) are mirrored into PROVIDER_REGISTRY with the# auth_type they declare; the mirror lives in the sibling so it can be re-run after discovery.from hermes_cli.auth_plugin_providers import ( # noqa: E402- registry_lookup as _registry_lookup, sync_plugin_provider_registry)+ get_plugin_oauth_auth_status, registry_lookup as _registry_lookup, sync_plugin_provider_registry)sync_plugin_provider_registry()@@ -1763,14 +1763,21 @@ def get_api_key_provider_status(provider_id: str) -> Dict[str, Any]:"base_url": base_url, "logged_in": configured}-def _external_process_auth_evidence(provider_id: str) -> tuple[bool, Optional[str]]:+def _external_process_auth_evidence(provider_id: str, resolved_command: Optional[str]) -> tuple[bool, Optional[str]]:"""Best-effort POSITIVE evidence ``(verified, source)`` that an external-process CLI is authed.- False means "not verifiable from here", NOT "signed out" (the Copilot CLI may use an OS keychain- Hermes can't read). Deliberately subprocess-free: spawning ``gh auth token`` from status- endpoints/pickers re-creates the cold-start stall copilot_auth.py avoids."""- if provider_id != "copilot-acp":- return False, None+ False means "not verifiable from here", NOT "signed out". Subprocess-free (spawning the CLI from+ status endpoints/pickers re-creates the cold-start stall copilot_auth.py avoids). Generic evidence+ for any external-process profile is its binary resolving: the subprocess owns real auth and Hermes+ has nothing else to inspect, so out-of-tree ACP rows pass credential-gated surfaces (Desktop+ ``explicit_only`` picker) like the bundled one, whose CLI additionally exposes readable token stores."""+ if provider_id == "copilot-acp":+ return _copilot_acp_auth_evidence()+ return (True, f"command: {resolved_command}") if resolved_command else (False, None)+++def _copilot_acp_auth_evidence() -> tuple[bool, Optional[str]]:+ """Copilot CLI token stores readable without spawning it (env tokens, plaintext config, hosts.json)."""# 1. Supported env tokens — the same vars the Copilot CLI itself honors.try:from hermes_cli.copilot_auth import COPILOT_ENV_VARS, validate_copilot_token@@ -1836,7 +1843,7 @@ def get_external_process_provider_status(provider_id: str) -> Dict[str, Any]:return {"configured": False}command, args, base_url, resolved_command, _ = _external_process_spec(pconfig)available = bool(resolved_command or base_url.startswith("acp+tcp://"))- auth_verified, auth_source = _external_process_auth_evidence(provider_id)+ auth_verified, auth_source = _external_process_auth_evidence(provider_id, resolved_command)return {"configured": available, "provider": provider_id, "name": pconfig.name, "command": command,"args": args, "resolved_command": resolved_command, "base_url": base_url,@@ -1878,7 +1885,10 @@ _BESPOKE_STATUS_FUNCTIONS: Dict[str, str] = {_STATUS_BY_AUTH_TYPE: Dict[str, str] = {"external_process": "get_external_process_provider_status","api_key": "get_api_key_provider_status",- "aws_sdk": "_get_aws_sdk_auth_status"}+ "aws_sdk": "_get_aws_sdk_auth_status",+ # OAuth-shaped plugin providers (their login lives in the plugin's auth_handler, tokens in the pool).+ "oauth_device_code": "get_plugin_oauth_auth_status",+ "oauth_external": "get_plugin_oauth_auth_status"}def _get_azure_foundry_auth_status() -> Dict[str, Any]:diff --git a/hermes_cli/auth_plugin_providers.py b/hermes_cli/auth_plugin_providers.pyindex 5701e719ae5..631ff8bbe74 100644--- a/hermes_cli/auth_plugin_providers.py+++ b/hermes_cli/auth_plugin_providers.py@@ -158,3 +158,38 @@ def plugin_missing_auth_handler_error(provider: str, action: str) -> Optional[Syf"Provider '{provider}' declares auth_type '{profile.auth_type}' but its plugin ships no "f"auth_handler, so `hermes auth {action} {provider}` cannot be handled. Add ""`auth_handler=` to its ProviderProfile (see the model-provider plugin guide).")+++def _pool_entry_expired(entry: Any) -> bool:+ """A pooled OAuth row is expired when its ``expires_at_ms`` / ISO ``expires_at`` is in the past."""+ import time+ from hermes_cli.auth import _parse_iso_timestamp++ if entry.expires_at_ms is not None:+ return int(entry.expires_at_ms) <= int(time.time() * 1000)+ if entry.expires_at:+ epoch = _parse_iso_timestamp(entry.expires_at)+ return epoch is not None and epoch <= time.time()+ return False+++def get_plugin_oauth_auth_status(provider_id: str) -> dict[str, Any]:+ """Status for an OAuth-shaped PLUGIN provider, read from the credential pool its ``auth_handler`` fills.++ ``configured`` = the profile is registered; ``logged_in`` = a pool row carries a live token;+ ``needs_refresh`` = every token is expired but refresh material (and a ``refresh_credential`` hook)+ exists. Bundled OAuth providers keep their bespoke builders (``_BESPOKE_STATUS_FUNCTIONS``) — this+ one is gated on the plugin-mirrored set so their status bytes never change.+ """+ if provider_id not in PLUGIN_MIRRORED_PROVIDERS:+ return {"logged_in": False}+ from agent.credential_pool import load_pool++ entries = [e for e in load_pool(provider_id).entries() if (e.access_token or e.agent_key or "").strip()]+ live = [e for e in entries if not _pool_entry_expired(e)]+ refreshable = [e for e in entries if e.refresh_token] if not live and plugin_refresh_hook(provider_id) else []+ return {+ "configured": True, "provider": provider_id, "logged_in": bool(live),+ "needs_refresh": bool(refreshable), "accounts": len(entries),+ "base_url": next((e.base_url for e in live + refreshable if e.base_url), "") or "",+ "hint": "" if live else f"Run `hermes auth add {provider_id}` to sign in."}diff --git a/hermes_cli/main.py b/hermes_cli/main.pyindex 564ae1b782b..82141b3376c 100644--- a/hermes_cli/main.py+++ b/hermes_cli/main.py@@ -747,6 +747,8 @@ from hermes_cli.model_setup_flows import (_model_flow_anthropic,_model_flow_moa,_model_flow_ai_gateway,+ _model_flow_plugin_provider,+ _is_profile_plugin_flow_provider,)logger = logging.getLogger(__name__)from hermes_cli.main_agent_cmds import (@@ -2102,6 +2104,9 @@ def select_provider_and_model(args=None):# _model_flow_* names at call time so test monkeypatches on# hermes_cli.main keep intercepting.flow = _PROVIDER_MODEL_FLOWS.get(selected_provider)+ if flow is None and _is_profile_plugin_flow_provider(selected_provider):+ # Registered plugin profile with no bespoke flow: the generic one, keyed by its auth_type.+ flow = lambda c, m, a: _model_flow_plugin_provider(c, selected_provider, m) # noqa: E731if flow is not None:flow(config, current_model, args)elif (diff --git a/hermes_cli/model_setup_flows.py b/hermes_cli/model_setup_flows.pyindex 51f6dc1d239..458ff761568 100644--- a/hermes_cli/model_setup_flows.py+++ b/hermes_cli/model_setup_flows.py@@ -1063,6 +1063,77 @@ def _model_flow_anthropic(config, current_model=""):_finish_model(selected, "anthropic", f"Default model set to: {selected} (via Anthropic)", drop_base_url=True, drop_api_mode=True)+# ── Generic flow for plugin providers without a bespoke `_model_flow_*` ────────────────────────────+# The credential step is keyed by the profile's auth_type: each returns ``(base_url, api_key)`` or+# None when the picker must stop (the helper already printed why). ``api_key`` providers keep+# ``_model_flow_api_key_provider``; ``hermes_cli.main`` routes every registered profile missing+# from ``_PROVIDER_MODEL_FLOWS`` here, so an admitted plugin is never a silent no-op.++def _plugin_flow_external_process(provider_id: str, profile) -> tuple[str, str] | None:+ from hermes_cli.auth import get_external_process_provider_status, resolve_external_process_provider_credentials+ status = get_external_process_provider_status(provider_id)+ _say(f" {profile.display_name or provider_id} delegates Hermes turns to a local `{status.get('command') or profile.process_command}` process.",+ f" Command: {status.get('resolved_command') or status.get('command') or '(not found)'}",+ f" Backend marker: {status.get('base_url') or profile.base_url}", "")+ try:+ creds = resolve_external_process_provider_credentials(provider_id)+ except Exception as exc:+ _say(f" ⚠ {exc}")+ return None+ return str(creds.get("base_url") or profile.base_url or ""), ""+++def _plugin_flow_oauth(provider_id: str, profile) -> tuple[str, str] | None:+ from hermes_cli.auth import get_auth_status+ from hermes_cli.auth_plugin_providers import plugin_missing_auth_handler_error+ status = get_auth_status(provider_id)+ if not status.get("logged_in"):+ missing = plugin_missing_auth_handler_error(provider_id, "add")+ _say(f" ⚠ Not signed in to {profile.display_name or provider_id}.",+ f" {missing.code if missing else status.get('hint') or f'Run `hermes auth add {provider_id}` to sign in.'}")+ return None+ from agent.credential_pool import load_pool+ entry = load_pool(provider_id).select()+ base_url = (entry.runtime_base_url if entry else "") or status.get("base_url") or profile.base_url or ""+ return str(base_url), (entry.runtime_api_key if entry else "") or ""+++_PLUGIN_FLOW_CREDENTIALS = {+ "external_process": _plugin_flow_external_process,+ "oauth_device_code": _plugin_flow_oauth,+ "oauth_external": _plugin_flow_oauth,+}+++def _is_profile_plugin_flow_provider(provider_id: str) -> bool:+ """True when *provider_id* is a registered profile whose auth_type the generic plugin flow handles."""+ from hermes_cli.auth_plugin_providers import plugin_profile+ profile = plugin_profile(provider_id)+ return profile is not None and profile.auth_type in _PLUGIN_FLOW_CREDENTIALS+++def _model_flow_plugin_provider(config, provider_id, current_model=""):+ """Generic ``hermes model`` flow for a registered plugin profile: credential step by auth_type,+ catalog via ``merge_profile_catalog`` (live ``fetch_models()`` ⊕ ``fallback_models``), persist."""+ from hermes_cli.auth_plugin_providers import plugin_profile+ from hermes_cli.models import merge_profile_catalog+ del config+ profile = plugin_profile(provider_id)+ creds = _PLUGIN_FLOW_CREDENTIALS[profile.auth_type](provider_id, profile)+ if creds is None:+ return+ base_url, api_key = creds+ live = None+ with contextlib.suppress(Exception):+ live = profile.fetch_models(api_key=api_key or None, base_url=base_url or None)+ model_list = merge_profile_catalog(provider_id, profile, live) or []+ selected = _pick_model_or_prompt(+ model_list, "Model name: ", current_model=current_model, confirm_provider=provider_id,+ confirm_base_url=base_url, confirm_api_key=api_key)+ _finish_model(selected, provider_id, f"Default model set to: {selected} (via {profile.display_name or provider_id})",+ base_url=base_url or None, api_mode=profile.api_mode or None)++# ---- BEGIN PLUGIN-COMPAT (revert-scheduled; see COMPAT_MANIFEST.md) ----# Names external plugins imported from this module before the Sep 2026 decomposition.# Internal code MUST NOT use these (scripts/check_compat_pointers.py fails CI if it does).diff --git a/tests/agent/test_account_usage_fetch.py b/tests/agent/test_account_usage_fetch.pyindex 6b0d47d5921..93d7adbb72b 100644--- a/tests/agent/test_account_usage_fetch.py+++ b/tests/agent/test_account_usage_fetch.py@@ -257,3 +257,32 @@ def test_fetch_account_usage_openrouter_omits_quota_window_when_key_has_no_limitassert snapshot.windows == ()assert "Credits balance: $74.50" in snapshot.detailsassert "API key usage: $25.50 total • $1.25 today • $4.50 this week • $18.00 this month" in snapshot.details+++def test_plugin_usage_hook_is_bounded_and_fails_open(monkeypatch):+ """A plugin hook that overruns the shared deadline yields None within deadline+1 s on every surface+ (gateway/TUI call ``fetch_account_usage`` with no bound of their own); built-in fetchers are untouched."""+ import threading+ import time++ from agent import account_usage++ started = threading.Event()++ class _Hang(ProviderProfile):+ def fetch_account_usage(self, *, base_url=None, api_key=None):+ started.set()+ time.sleep(5)+ return AccountUsageSnapshot(provider=self.name, source="late", fetched_at=datetime.now(timezone.utc))++ _register_profile(monkeypatch, _Hang(name="plugin-hang"))+ monkeypatch.setattr(account_usage, "PLUGIN_USAGE_HOOK_DEADLINE_S", 0.3)+ builtin_calls = []+ monkeypatch.setattr(account_usage, "_USAGE_FETCHERS",+ {"openrouter": lambda base_url, api_key: builtin_calls.append(1)})++ t0 = time.monotonic()+ assert account_usage.fetch_account_usage("plugin-hang") is None+ assert time.monotonic() - t0 < 1.3 and started.is_set()+ account_usage.fetch_account_usage("openrouter")+ assert builtin_calls == [1]diff --git a/tests/agent/test_external_process_provider_init.py b/tests/agent/test_external_process_provider_init.pyindex 9771c682858..44db7532aef 100644--- a/tests/agent/test_external_process_provider_init.py+++ b/tests/agent/test_external_process_provider_init.py@@ -16,3 +16,29 @@ def test_explicit_client_kwargs_injects_command_for_any_external_process_profileassert kwargs["command"] == "/tmp/test-process"assert kwargs["args"] == ["--acp", "--stdio"]+++def _routing_agent(provider: str, base_url: str) -> SimpleNamespace:+ return SimpleNamespace(+ provider=provider, base_url=base_url, model="gpt-5.4", api_mode="chat_completions",+ _get_transport=lambda: None, _is_azure_openai_url=lambda: False, _is_openrouter_url=lambda: False,+ _is_direct_openai_url=lambda: base_url.startswith("https://api.openai.com"),+ _provider_model_requires_responses_api=lambda model, provider=None: False, _transport_cache={})+++def test_responses_upgrade_is_skipped_by_acp_scheme_not_vendor_slug(monkeypatch):+ """The Responses auto-upgrade guard keys on the ``acp://`` scheme alone: every external-process+ provider on an ACP marker keeps chat_completions (bundled and out-of-tree alike), while a direct+ OpenAI URL is upgraded whatever the slug — the vendor literal carried no behaviour of its own."""+ from agent.agent_init import _finalize_routing++ monkeypatch.setattr("hermes_cli.anon_auth.pin_model_for_route", lambda provider, base_url, model: model)+ for provider, base_url in (("copilot-acp", "acp://copilot"), ("acme-acp", "acp://acme"),+ ("acme-acp", "acp+tcp://127.0.0.1:9000")):+ agent = _routing_agent(provider, base_url)+ _finalize_routing(agent, None, None)+ assert agent.api_mode == "chat_completions", (provider, base_url)++ upgraded = _routing_agent("acme-acp", "https://api.openai.com/v1")+ _finalize_routing(upgraded, None, None)+ assert upgraded.api_mode == "codex_responses"diff --git a/tests/hermes_cli/test_plugin_provider_picker_residue.py b/tests/hermes_cli/test_plugin_provider_picker_residue.pynew file mode 100644index 00000000000..24593903fa0--- /dev/null+++ b/tests/hermes_cli/test_plugin_provider_picker_residue.py@@ -0,0 +1,147 @@+"""An admitted plugin provider is selectable and status-accurate on every surface (#116408).++Residue after picker admission: `hermes model` had no flow for a plugin profile (selection was a silent+no-op), OAuth-shaped plugins had no ``_STATUS_BY_AUTH_TYPE`` builder (``authenticated`` stayed False with+a live pool entry) and external-process sign-in evidence existed for one bundled vendor only, so the+Desktop ``explicit_only`` picker hid out-of-tree ACP rows.+"""++import os+import stat++import pytest++from providers.base import ProviderProfile+++def plugin(monkeypatch):+ """Register *profile* the way plugin discovery does (providers registry + auth mirror), no leaks."""+ import providers+ from hermes_cli import auth+ from hermes_cli.auth_plugin_providers import PLUGIN_MIRRORED_PROVIDERS, register_plugin_provider++ monkeypatch.setattr(providers, "_REGISTRY", dict(providers._REGISTRY))+ monkeypatch.setattr(providers, "_ALIASES", dict(providers._ALIASES))+ monkeypatch.setattr(providers, "_PROVIDER_LIST_CACHE", None, raising=False)+ monkeypatch.setattr(auth, "PROVIDER_REGISTRY", dict(auth.PROVIDER_REGISTRY))+ mirrored = set(PLUGIN_MIRRORED_PROVIDERS)+ monkeypatch.setattr("hermes_cli.auth_plugin_providers.PLUGIN_MIRRORED_PROVIDERS", mirrored)++ def _register(profile: ProviderProfile) -> ProviderProfile:+ providers.register_provider(profile)+ register_plugin_provider(profile)+ return profile++ return _register+++def _fake_binary(tmp_path, monkeypatch, name: str) -> None:+ exe = tmp_path / name+ exe.write_text("#!/bin/sh\nexit 0\n")+ exe.chmod(exe.stat().st_mode | stat.S_IXUSR)+ monkeypatch.setenv("PATH", f"{tmp_path}{os.pathsep}{os.environ.get('PATH', '')}")+++def _pool_entry(provider: str, **fields):+ from agent.credential_pool import AUTH_TYPE_OAUTH, PooledCredential, load_pool++ entry = PooledCredential(+ provider=provider, id="e1", label="acme", auth_type=AUTH_TYPE_OAUTH, priority=0,+ source="manual:example_device", base_url="https://example.invalid/v1", **fields)+ load_pool(provider).add_entry(entry)+ return entry+++def test_hermes_model_routes_registered_plugin_profiles_to_the_generic_flow(plugin, monkeypatch, tmp_path):+ """Selecting an admitted external-process or OAuth plugin in `hermes model` persists config.model;+ an api_key profile still takes the api-key flow and an unknown slug stays a no-op."""+ import hermes_cli.main as main+ from hermes_cli import auth+ from hermes_cli.config import load_config++ plugin(ProviderProfile(name="example-acp", auth_type="external_process", base_url="acp://example",+ process_command="example-acp-bin", fallback_models=("acp-a", "acp-b")))+ plugin(ProviderProfile(name="example-oauth", auth_type="oauth_external",+ base_url="https://example.invalid/v1", fallback_models=("oauth-a",)))+ plugin(ProviderProfile(name="example-key", auth_type="api_key", env_vars=("EXAMPLE_API_KEY",),+ base_url="https://example.invalid/v1", fallback_models=("key-a",)))+ _fake_binary(tmp_path, monkeypatch, "example-acp-bin")+ _pool_entry("example-oauth", access_token="tok-1", refresh_token="rt-1")+ monkeypatch.setattr(main, "_offer_reasoning_after_pick", lambda *a, **k: None)+ monkeypatch.setattr(auth, "_prompt_model_selection", lambda models, **k: models[-1])+ api_key_flow_calls = []+ monkeypatch.setattr(main, "_model_flow_api_key_provider",+ lambda config, pid, current="": api_key_flow_calls.append(pid))++ for slug, expected in (("example-acp", ("acp-b", "acp://example")),+ ("example-oauth", ("oauth-a", "https://example.invalid/v1"))):+ monkeypatch.setattr(main, "_pick_provider", lambda *a, _s=slug, **k: _s)+ main.select_provider_and_model(args=None)+ model = load_config()["model"]+ assert (model["provider"], model["default"], model["base_url"]) == (slug, *expected)++ monkeypatch.setattr(main, "_pick_provider", lambda *a, **k: "example-key")+ main.select_provider_and_model(args=None)+ assert api_key_flow_calls == ["example-key"]+ monkeypatch.setattr(main, "_pick_provider", lambda *a, **k: "no-such-provider")+ main.select_provider_and_model(args=None)+ assert load_config()["model"]["provider"] == "example-oauth"+++def test_oauth_plugin_status_follows_the_credential_pool(plugin):+ """``get_auth_status``/``authenticated`` for an OAuth-shaped plugin read the pool: live token →+ logged in; expired token with refresh material → needs_refresh; nothing → signed out with the+ `hermes auth add` hint. Bundled OAuth providers never reach this builder."""+ from hermes_cli import auth, models++ plugin(ProviderProfile(name="example-oauth", auth_type="oauth_external",+ base_url="https://example.invalid/v1", refresh_credential=lambda entry: {}))+ plugin(ProviderProfile(name="example-device", auth_type="oauth_device_code", base_url="https://d.invalid/v1"))++ signed_out = auth.get_auth_status("example-oauth")+ assert signed_out["logged_in"] is False and signed_out["configured"] is True+ assert "hermes auth add example-oauth" in signed_out["hint"]+ assert models._provider_has_credentials("example-oauth") is True # registered = usable with provider:model++ _pool_entry("example-oauth", access_token="tok-1", refresh_token="rt-1")+ assert auth.get_auth_status("example-oauth")["logged_in"] is True++ _pool_entry("example-device", access_token="tok-old", refresh_token="rt-old", expires_at_ms=1_000)+ expired = auth.get_auth_status("example-device")+ assert (expired["logged_in"], expired["needs_refresh"]) == (False, False) # no refresh hook → not refreshable+ _pool_entry("example-oauth", access_token="tok-old", refresh_token="rt-old", expires_at_ms=1_000)+ # the live entry still wins for example-oauth+ assert auth.get_auth_status("example-oauth")["logged_in"] is True++ assert auth._STATUS_BY_AUTH_TYPE["oauth_external"] == auth._STATUS_BY_AUTH_TYPE["oauth_device_code"]+ for builtin in ("nous", "openai-codex"):+ assert builtin in auth._BESPOKE_STATUS_FUNCTIONS # bespoke status wins; plugin builder never consulted+ assert auth.get_plugin_oauth_auth_status("openai-codex") == {"logged_in": False}+++def test_any_external_process_plugin_counts_as_signed_in_when_its_binary_resolves(plugin, monkeypatch, tmp_path):+ """The Desktop ``explicit_only`` filter (``build_model_options_payload`` behind+ ``tui_gateway/methods_complete.py::model.options``) keeps an out-of-tree ACP row exactly like the+ bundled one: binary resolves → auth evidence; missing binary → hidden."""+ from hermes_cli import auth+ from hermes_cli.inventory import _external_process_signed_in, _filter_explicit_provider_rows++ plugin(ProviderProfile(name="example-acp", auth_type="external_process", base_url="acp://example",+ process_command="example-acp-bin", fallback_models=("acp-a",)))++ class _Ctx:+ current_provider = "nous"++ rows = [{"slug": "example-acp", "models": ["acp-a"]}]+ monkeypatch.setenv("PATH", str(tmp_path / "nowhere"))+ assert _external_process_signed_in("example-acp") is False+ assert _filter_explicit_provider_rows(rows, _Ctx()) == []++ _fake_binary(tmp_path, monkeypatch, "example-acp-bin")+ status = auth.get_external_process_provider_status("example-acp")+ assert status["auth_verified"] is True and status["auth_source"].startswith("command: ")+ assert [r["slug"] for r in _filter_explicit_provider_rows(rows, _Ctx())] == ["example-acp"]+ # Bundled Copilot keeps its token-store evidence: a resolving binary alone is not a sign-in there.+ assert auth._external_process_auth_evidence("copilot-acp", str(tmp_path / "copilot")) == \+ auth._copilot_acp_auth_evidence()diff --git a/website/docs/developer-guide/model-provider-plugin.md b/website/docs/developer-guide/model-provider-plugin.mdindex 82f4389295d..3d0ee6160c4 100644--- a/website/docs/developer-guide/model-provider-plugin.md+++ b/website/docs/developer-guide/model-provider-plugin.md@@ -219,7 +219,10 @@ overriding `ProviderProfile.fetch_account_usage`. Import and return the sharedentries); do not format output in the plugin. Returning `None`, or raising anexception, leaves `/usage` empty just as it does for providers without usagedata. Built-in usage fetchers always take precedence, so this hook cannot-replace the account-usage behavior for a built-in provider.+replace the account-usage behavior for a built-in provider. The hook runs under a shared+10 s deadline (`agent.account_usage.PLUGIN_USAGE_HOOK_DEADLINE_S`) on every surface; overrunning it+renders nothing for that turn rather than stalling `/usage`, so give your own HTTP calls a shorter+timeout.The bundled `plugins/model-providers/opencode-zen/` profile implements this hook for theOpenCode Go plan windows; every `/usage` surface (CLI `hermes usage` and `/usage`, the messaging@@ -258,11 +261,13 @@ Every registered profile joins `CANONICAL_PROVIDERS` by slug (a plugin re-declar| `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) |+| `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. A resolving binary is also the sign-in evidence (`auth_verified`) the Desktop model selector's explicit-only filter uses, so the row shows there like the bundled ACP provider does | `fetch_models()` (your subprocess probe), else `fallback_models` |+| `oauth_external` / `oauth_device_code` | the credential pool holds a row for the slug with a live (non-expired) token — `hermes auth status <name>` and `list_available_providers().authenticated` both read the pool; an expired row with `refresh_token` and a `refresh_credential` hook reports `needs_refresh` | `fetch_models()` with the pooled token, else `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.+Selecting the row in `hermes model` (and the setup wizard) runs one generic flow keyed by the profile's `auth_type`: external-process profiles are launch-checked (`resolve_external_process_provider_credentials`), OAuth profiles need a live pool row (otherwise the flow prints `hermes auth add <name>` and stops), then the merged catalog is offered and `config.model` is persisted with the profile's `base_url`/`api_mode`. No `_model_flow_*` entry in core is needed.+## Hook reference examplesLook at these bundled plugins for idioms: