Skip to content

The agent that grows with you

feat(providers): let an external-process provider ship out of tree

Alexander Prendota1bd0b8ed41c5
diff --git a/hermes_cli/auth.py b/hermes_cli/auth.py
index d2935755192..3f6700b7c70 100644
--- a/hermes_cli/auth.py
+++ b/hermes_cli/auth.py
@@ -579,6 +579,24 @@ try:
for _pp in _list_providers_for_registry():
if _pp.name in PROVIDER_REGISTRY:
continue
+ if _pp.auth_type == "external_process":
+ # An external-process provider (an ACP CLI driven over stdio) has no
+ # API-key env vars to resolve — its credentials come from
+ # resolve_external_process_provider_credentials(), keyed on this
+ # auth_type. Registering it here is what lets a provider shipped
+ # outside this tree pass resolve_provider()'s known-provider gate;
+ # without it, `hermes -m <that provider>` dies with
+ # "Unknown provider" before any client is ever built.
+ PROVIDER_REGISTRY[_pp.name] = ProviderConfig(
+ id=_pp.name,
+ name=_pp.display_name or _pp.name,
+ auth_type="external_process",
+ inference_base_url=_pp.base_url,
+ )
+ for _alias in _pp.aliases:
+ if _alias not in PROVIDER_REGISTRY:
+ PROVIDER_REGISTRY[_alias] = PROVIDER_REGISTRY[_pp.name]
+ continue
if _pp.auth_type != "api_key" or not _pp.env_vars:
continue
# Skip providers that need custom token resolution or are special-cased
@@ -8188,25 +8206,52 @@ def resolve_external_process_provider_credentials(provider_id: str) -> Dict[str,
if not base_url:
base_url = pconfig.inference_base_url
- command = (
- os.getenv("HERMES_COPILOT_ACP_COMMAND", "").strip()
- or os.getenv("COPILOT_CLI_PATH", "").strip()
- or "copilot"
- )
- raw_args = os.getenv("HERMES_COPILOT_ACP_ARGS", "").strip()
- args = shlex.split(raw_args) if raw_args else ["--acp", "--stdio"]
+ # How to launch the CLI comes from the provider's own profile, so a provider
+ # shipped outside this tree describes its binary/args instead of inheriting
+ # another vendor's. copilot-acp's values live in its profile, which is why
+ # HERMES_COPILOT_ACP_COMMAND / COPILOT_CLI_PATH / HERMES_COPILOT_ACP_ARGS
+ # keep working unchanged.
+ profile = None
+ try:
+ from providers import get_provider_profile as _get_provider_profile
+
+ profile = _get_provider_profile(provider_id)
+ except Exception:
+ profile = None
+
+ command_env_vars = tuple(getattr(profile, "process_command_env_vars", ()) or ())
+ default_command = str(getattr(profile, "process_command", "") or "")
+ default_args = list(getattr(profile, "process_args", ()) or [])
+ args_env_var = str(getattr(profile, "process_args_env_var", "") or "")
+
+ command = ""
+ for _var in command_env_vars:
+ command = os.getenv(_var, "").strip()
+ if command:
+ break
+ if not command:
+ command = default_command
+
+ raw_args = os.getenv(args_env_var, "").strip() if args_env_var else ""
+ args = shlex.split(raw_args) if raw_args else list(default_args)
+
resolved_command = shutil.which(command) if command else None
if not resolved_command and not base_url.startswith("acp+tcp://"):
+ _hint = (
+ " or set " + "/".join(command_env_vars) if command_env_vars else ""
+ )
raise AuthError(
- f"Could not find the Copilot CLI command '{command}'. "
- "Install GitHub Copilot CLI or set HERMES_COPILOT_ACP_COMMAND/COPILOT_CLI_PATH.",
+ f"Could not find the '{provider_id}' CLI command "
+ f"'{command or '(none configured)'}'. Install it{_hint}.",
provider=provider_id,
- code="missing_copilot_cli",
+ code="missing_external_process_cli",
)
return {
"provider": provider_id,
- "api_key": "copilot-acp",
+ # Placeholder credential: the subprocess owns real auth. Keyed on the
+ # provider id so each external-process provider gets a distinct value.
+ "api_key": pconfig.id or provider_id,
"base_url": base_url.rstrip("/"),
"command": resolved_command or command,
"args": args,
diff --git a/hermes_cli/runtime_provider.py b/hermes_cli/runtime_provider.py
index 605d2d71354..bee78f192ef 100644
--- a/hermes_cli/runtime_provider.py
+++ b/hermes_cli/runtime_provider.py
@@ -1952,6 +1952,33 @@ def _resolve_explicit_runtime(
return None
+def _is_external_process_provider(provider: str) -> bool:
+ """Whether ``provider`` is declared as an external-process (CLI) provider.
+
+ Reads the CLI provider registry first (which now absorbs registered
+ ProviderProfiles, in-tree and out), then falls back to the profile registry
+ directly so the check works before the CLI registry has been extended.
+ """
+ name = (provider or "").strip().lower()
+ if not name:
+ return False
+ try:
+ from hermes_cli.auth import PROVIDER_REGISTRY
+
+ pconfig = PROVIDER_REGISTRY.get(name)
+ if pconfig is not None:
+ return pconfig.auth_type == "external_process"
+ except Exception:
+ pass
+ try:
+ from providers import get_provider_profile
+
+ profile = get_provider_profile(name)
+ except Exception:
+ return False
+ return profile is not None and getattr(profile, "auth_type", "") == "external_process"
+
+
def resolve_runtime_provider(
*,
requested: Optional[str] = None,
@@ -2337,10 +2364,13 @@ def resolve_runtime_provider(
"requested_provider": requested_provider,
}
- if provider == "copilot-acp":
+ # External-process providers (an agent CLI driven over stdio, e.g. ACP).
+ # Keyed on the registered provider's auth_type rather than on one name, so a
+ # provider shipped outside this tree lands on the same credential path.
+ if _is_external_process_provider(provider):
creds = resolve_external_process_provider_credentials(provider)
return {
- "provider": "copilot-acp",
+ "provider": provider,
"api_mode": "chat_completions",
"base_url": creds.get("base_url", "").rstrip("/"),
"api_key": creds.get("api_key", ""),
diff --git a/plugins/model-providers/copilot-acp/__init__.py b/plugins/model-providers/copilot-acp/__init__.py
index 95ba9700e6b..89f51b850f2 100644
--- a/plugins/model-providers/copilot-acp/__init__.py
+++ b/plugins/model-providers/copilot-acp/__init__.py
@@ -42,6 +42,13 @@ copilot_acp = CopilotACPProfile(
env_vars=(), # Managed by ACP subprocess
base_url="acp://copilot", # ACP internal scheme
auth_type="external_process",
+ # How to launch the CLI. Previously hardcoded in
+ # hermes_cli/auth.py::resolve_external_process_provider_credentials; the env
+ # var names are unchanged, so existing setups keep working.
+ process_command="copilot",
+ process_args=("--acp", "--stdio"),
+ process_command_env_vars=("HERMES_COPILOT_ACP_COMMAND", "COPILOT_CLI_PATH"),
+ process_args_env_var="HERMES_COPILOT_ACP_ARGS",
)
register_provider(copilot_acp)
diff --git a/providers/base.py b/providers/base.py
index 7ddd01f8afd..b76748f0dcb 100644
--- a/providers/base.py
+++ b/providers/base.py
@@ -78,6 +78,17 @@ class ProviderProfile:
# top-level fields rather than ignoring them.
supports_prompt_cache_key: bool = False
+ # ── External-process providers (auth_type="external_process") ──
+ # An agent CLI driven over stdio (ACP) rather than an HTTP endpoint. These
+ # describe how to launch it; hermes_cli/auth.py's
+ # resolve_external_process_provider_credentials() reads them instead of
+ # hardcoding one vendor's binary. Env vars are checked in order and win
+ # over the static defaults, so an operator can point at a custom build.
+ process_command: str = "" # default binary, e.g. "copilot"
+ process_args: tuple = () # default argv tail, e.g. ("--acp", "--stdio")
+ process_command_env_vars: tuple = () # env overrides for the binary, in priority order
+ process_args_env_var: str = "" # env override for argv (shlex-split)
+
# ── Model catalog ─────────────────────────────────────────
# fallback_models: curated list shown in /model picker when live fetch fails.
# Only agentic models that support tool calling should appear here.
diff --git a/tests/hermes_cli/test_external_process_provider_seam.py b/tests/hermes_cli/test_external_process_provider_seam.py
new file mode 100644
index 00000000000..e0e6f73369b
--- /dev/null
+++ b/tests/hermes_cli/test_external_process_provider_seam.py
@@ -0,0 +1,218 @@
+"""An external-process provider can ship from outside this tree.
+
+An ACP agent CLI is not an HTTP endpoint: it is a subprocess Hermes drives over
+stdio. Everything about launching it used to be spelled out for one vendor —
+the known-provider gate, the binary, the argv, the env var names. A provider
+registered from ``~/.hermes/plugins/model-providers/`` or a pip entry point
+therefore could not be reached at all: ``hermes -m <it>`` died with "Unknown
+provider" long before any client was built.
+
+This registers a provider the way a standalone package does — before importing
+any ``hermes_cli`` module, exactly as plugin discovery does — and walks the real
+resolution path end to end. ``copilot-acp`` is asserted alongside it at every
+step, so the generalisation cannot quietly change the in-tree provider.
+"""
+
+from __future__ import annotations
+
+import os
+import stat
+import sys
+
+import pytest
+
+_REPO_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+if _REPO_ROOT not in sys.path:
+ sys.path.insert(0, _REPO_ROOT)
+
+from providers import register_provider # noqa: E402
+from providers.base import ProviderProfile # noqa: E402
+
+
+class _AcmeClient:
+ HERMES_SKIP_TRANSPORT_WRAP = True
+ HERMES_SKIP_ASYNC_WRAP = True
+
+ def __init__(self, **kwargs):
+ self.kwargs = kwargs
+ self.api_key = kwargs.get("api_key")
+ self.base_url = kwargs.get("base_url")
+
+
+class _AcmeACPProfile(ProviderProfile):
+ def create_client(self, **kwargs):
+ return _AcmeClient(**kwargs)
+
+ def fetch_models(self, **kwargs):
+ return None
+
+
+# Registered at import time — the same moment a plugin's ``__init__.py`` or a
+# pip entry point runs, i.e. before hermes_cli.auth builds PROVIDER_REGISTRY.
+register_provider(
+ _AcmeACPProfile(
+ name="acme-acp",
+ aliases=("acme",),
+ display_name="Acme ACP",
+ api_mode="chat_completions",
+ base_url="acp://acme",
+ auth_type="external_process",
+ process_command="acme-cli",
+ process_args=("--acp",),
+ process_command_env_vars=("ACME_CLI_PATH",),
+ process_args_env_var="ACME_ACP_ARGS",
+ )
+)
+
+
+def fake_cli(tmp_path, monkeypatch):
+ """Put stub `acme-cli` and `copilot` binaries on PATH."""
+ bindir = tmp_path / "bin"
+ bindir.mkdir()
+ for name in ("acme-cli", "copilot"):
+ exe = bindir / name
+ exe.write_text("#!/bin/sh\nexit 0\n")
+ exe.chmod(exe.stat().st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH)
+ monkeypatch.setenv("PATH", f"{bindir}{os.pathsep}{os.environ.get('PATH', '')}")
+ return bindir
+
+
+# ── the known-provider gate ──────────────────────────────────────────────────
+
+
+def test_the_provider_is_absorbed_into_the_cli_registry():
+ """Without this the resolver raises "Unknown provider" before anything else."""
+ from hermes_cli.auth import PROVIDER_REGISTRY
+
+ assert "acme-acp" in PROVIDER_REGISTRY
+ assert PROVIDER_REGISTRY["acme-acp"].auth_type == "external_process"
+ assert PROVIDER_REGISTRY["acme-acp"].inference_base_url == "acp://acme"
+ assert PROVIDER_REGISTRY["acme-acp"].name == "Acme ACP"
+ # Aliases resolve to the same config.
+ assert PROVIDER_REGISTRY["acme"] is PROVIDER_REGISTRY["acme-acp"]
+ # The in-tree one is declared explicitly and must not be shadowed.
+ assert PROVIDER_REGISTRY["copilot-acp"].auth_type == "external_process"
+
+
+def test_resolve_provider_accepts_the_name_and_its_alias():
+ from hermes_cli.auth import resolve_provider
+
+ assert resolve_provider("acme-acp") == "acme-acp"
+ assert resolve_provider("acme") == "acme-acp"
+
+
+# ── launching the CLI ────────────────────────────────────────────────────────
+
+
+def test_credentials_come_from_the_profile(fake_cli):
+ from hermes_cli.auth import resolve_external_process_provider_credentials
+
+ creds = resolve_external_process_provider_credentials("acme-acp")
+ assert creds["command"] == str(fake_cli / "acme-cli")
+ assert creds["args"] == ["--acp"]
+ assert creds["base_url"] == "acp://acme"
+ # Placeholder credential keyed on the provider, not a borrowed literal.
+ assert creds["api_key"] == "acme-acp"
+
+
+def test_copilot_launch_details_are_unchanged(fake_cli):
+ """These moved from hardcoded resolver code into copilot-acp's profile."""
+ from hermes_cli.auth import resolve_external_process_provider_credentials
+
+ creds = resolve_external_process_provider_credentials("copilot-acp")
+ assert creds["command"] == str(fake_cli / "copilot")
+ assert creds["args"] == ["--acp", "--stdio"]
+ assert creds["api_key"] == "copilot-acp"
+ assert creds["base_url"] == "acp://copilot"
+
+
+ "provider,env_var,binary",
+ [
+ ("acme-acp", "ACME_CLI_PATH", "acme-cli"),
+ ("copilot-acp", "HERMES_COPILOT_ACP_COMMAND", "copilot"),
+ ("copilot-acp", "COPILOT_CLI_PATH", "copilot"),
+ ],
+)
+def test_the_binary_can_be_overridden_by_env(fake_cli, monkeypatch, provider, env_var, binary):
+ from hermes_cli.auth import resolve_external_process_provider_credentials
+
+ custom = fake_cli / f"custom-{binary}"
+ custom.write_text("#!/bin/sh\nexit 0\n")
+ custom.chmod(custom.stat().st_mode | stat.S_IEXEC)
+ monkeypatch.setenv(env_var, str(custom))
+ creds = resolve_external_process_provider_credentials(provider)
+ assert creds["command"] == str(custom)
+
+
+ "provider,env_var",
+ [("acme-acp", "ACME_ACP_ARGS"), ("copilot-acp", "HERMES_COPILOT_ACP_ARGS")],
+)
+def test_the_args_can_be_overridden_by_env(fake_cli, monkeypatch, provider, env_var):
+ from hermes_cli.auth import resolve_external_process_provider_credentials
+
+ monkeypatch.setenv(env_var, "--acp=true --verbose")
+ assert resolve_external_process_provider_credentials(provider)["args"] == [
+ "--acp=true",
+ "--verbose",
+ ]
+
+
+def test_a_missing_binary_names_the_provider_and_its_env_override(monkeypatch, tmp_path):
+ from hermes_cli.auth import AuthError, resolve_external_process_provider_credentials
+
+ monkeypatch.setenv("PATH", str(tmp_path))
+ with pytest.raises(AuthError) as excinfo:
+ resolve_external_process_provider_credentials("acme-acp")
+ message = str(excinfo.value)
+ assert "acme-acp" in message
+ assert "ACME_CLI_PATH" in message
+
+
+def test_a_non_external_process_provider_is_still_rejected():
+ from hermes_cli.auth import AuthError, resolve_external_process_provider_credentials
+
+ with pytest.raises(AuthError):
+ resolve_external_process_provider_credentials("openai-api")
+
+
+# ── runtime resolution ───────────────────────────────────────────────────────
+
+
+ "requested,expected_base_url",
+ [
+ ("acme-acp", "acp://acme"),
+ ("acme", "acp://acme"),
+ ("copilot-acp", "acp://copilot"),
+ ],
+)
+def test_runtime_resolution_reaches_the_external_process_branch(
+ fake_cli, requested, expected_base_url
+):
+ """Previously keyed on the literal "copilot-acp", so anything else fell
+ through to the OpenRouter default instead of its own runtime."""
+ from hermes_cli.runtime_provider import resolve_runtime_provider
+
+ runtime = resolve_runtime_provider(requested=requested, target_model=requested)
+ assert runtime["base_url"] == expected_base_url
+ assert runtime["api_mode"] == "chat_completions"
+ assert runtime["source"] == "process"
+ assert runtime["command"]
+
+
+def test_the_client_is_built_from_the_profile(fake_cli):
+ from types import SimpleNamespace
+
+ from agent.agent_runtime_helpers import _provider_supplied_client
+ from hermes_cli.runtime_provider import resolve_runtime_provider
+
+ runtime = resolve_runtime_provider(requested="acme-acp", target_model="acme-acp")
+ agent = SimpleNamespace(provider=runtime["provider"], _client_log_context=lambda: "")
+ client = _provider_supplied_client(
+ agent, {"api_key": runtime["api_key"], "base_url": runtime["base_url"]}
+ )
+ assert isinstance(client, _AcmeClient)
+ assert client.base_url == "acp://acme"