Skip to content

The agent that grows with you

fix(cli): judge saved selections the way the runtime does in config check

kshitijk4poor361dc5cf69fb
diff --git a/hermes_cli/config.py b/hermes_cli/config.py
index 8bce48d65b4..bb5ce3bfe44 100644
--- a/hermes_cli/config.py
+++ b/hermes_cli/config.py
@@ -1453,12 +1453,10 @@ def _warn_invalid_platform_toolsets(results: Dict[str, Any], quiet: bool) -> Non
"""Surface invalid toolset names in platform_toolsets: ``resolve_toolset()`` returns [] for an
unknown name, silently disabling the affected tools. Best-effort; never blocks migration."""
try:
- from toolsets import validate_toolset
- from hermes_cli.toolset_validation import validate_platform_toolsets
- from hermes_cli.toolset_scope import toolset_allowed_for_platform
+ from hermes_cli.toolset_validation import saved_toolset_resolver, validate_platform_toolsets
- for w in validate_platform_toolsets(
- read_raw_config().get("platform_toolsets"), validate_toolset, toolset_allowed_for_platform):
+ config = read_raw_config()
+ for w in validate_platform_toolsets(config.get("platform_toolsets"), saved_toolset_resolver(config)):
results["warnings"].append(w)
if not quiet:
print(f" ⚠ {w}")
@@ -3932,7 +3930,7 @@ def _cmd_config_check(args):
from hermes_cli.config_check_diagnostics import config_check_diagnostics
- diagnostics = config_check_diagnostics(read_raw_config(), get_env_value)
+ diagnostics = config_check_diagnostics(read_raw_config_readonly(), get_env_value)
if diagnostics:
print()
print(color(" Saved configuration:", Colors.BOLD))
@@ -4108,12 +4106,12 @@ def _platform_plugin_manifests(home: Optional[Path] = None, source: PlatformMani
PLATFORM_SECRET_ENV_SUFFIXES = ("_TOKEN", "_SECRET", "_KEY", "_PASSWORD", "_JSON")
-def _platform_manifest_env_entries(manifest: dict):
- """Yield ``(name, is_secret, meta)`` for a manifest's ``requires_env`` / ``optional_env``
- entries (a bare name or a dict with ``name`` plus optional ``description``/``url``/
- ``password``/``prompt``/``category``). A name ending in PLATFORM_SECRET_ENV_SUFFIXES is a
- password field unless the entry says ``password: false``."""
- for entry in [*(manifest.get("requires_env") or []), *(manifest.get("optional_env") or [])]:
+def _platform_manifest_env_entries(manifest: dict, *, optional: bool = True):
+ """Yield ``(name, is_secret, meta)`` for a manifest's ``requires_env`` (and, unless
+ ``optional=False``, ``optional_env``) entries (a bare name or a dict with ``name`` plus optional
+ ``description``/``url``/``password``/``prompt``/``category``). A name ending in
+ PLATFORM_SECRET_ENV_SUFFIXES is a password field unless the entry says ``password: false``."""
+ for entry in [*(manifest.get("requires_env") or []), *((manifest.get("optional_env") or []) if optional else [])]:
meta = {"name": entry} if isinstance(entry, str) else entry if isinstance(entry, dict) else {}
name = meta.get("name")
if not name or not isinstance(name, str):
diff --git a/hermes_cli/config_check_diagnostics.py b/hermes_cli/config_check_diagnostics.py
index 71121465ec4..6d2d1f4a2cd 100644
--- a/hermes_cli/config_check_diagnostics.py
+++ b/hermes_cli/config_check_diagnostics.py
@@ -9,63 +9,24 @@ from typing import Any
def config_check_diagnostics(config: dict[str, Any], get_env_value: Callable[[str], str | None]) -> list[str]:
"""Report saved selections that would otherwise be lost in startup output.
- Keep this aligned with the runtime's MCP/plugin exceptions and manifest-based
- platform gate. A configured credential is only a reason to *mention* a
+ Toolset names are judged by the resolver ``hermes config migrate`` also uses, disabled platforms
+ by the runtime's own ``plugins.disabled`` reader and the manifest-name gate of
+ ``plugins_discovery.gate_manifest``. A configured credential is only a reason to *mention* a
disabled platform; disabling it may have been intentional.
"""
- from agent.skill_utils import parse_config_string_list
- from hermes_cli.config import _platform_plugin_manifests
- from hermes_cli.tools_config import enabled_mcp_server_names, _get_plugin_toolset_keys
- from hermes_cli.toolset_validation import validate_platform_toolsets
- from toolsets import validate_toolset
+ from hermes_cli.config import _platform_manifest_env_entries, _platform_plugin_manifests
+ from hermes_cli.plugins_discovery import _get_disabled_plugins
+ from hermes_cli.toolset_validation import saved_toolset_resolver, validate_platform_toolsets
- manifests = list(_platform_plugin_manifests(source="bundled"))
- platform_bundles = {f"hermes-{name}" for name, _manifest in manifests}
- platform_bundles.update(
- f"hermes-{name}" for name, _manifest in _platform_plugin_manifests(source="user")
- )
- plugin_toolsets = set(_get_plugin_toolset_keys())
- remembered = config.get("known_plugin_toolsets")
- if isinstance(remembered, dict):
- for names in remembered.values():
- if isinstance(names, list):
- plugin_toolsets.update(str(name) for name in names)
+ diagnostics = validate_platform_toolsets(config.get("platform_toolsets"), saved_toolset_resolver(config))
- mcp_config = config.get("mcp_servers") or {}
- mcp_names = set(mcp_config) if isinstance(mcp_config, dict) else set()
- platform_passthrough = (
- enabled_mcp_server_names(config) | plugin_toolsets | platform_bundles | {"no_mcp"}
- )
-
- def is_valid_platform_name(name: str) -> bool:
- return validate_toolset(name) or name in platform_passthrough
-
- diagnostics = []
- known_cli_names = mcp_names | plugin_toolsets | {"all", "*"}
- if "toolsets" in config:
- for name in parse_config_string_list(config["toolsets"]):
- if name not in known_cli_names and not validate_toolset(name):
- diagnostics.append(
- f"toolsets contains unknown name '{name}'. "
- "Run `hermes config edit` to remove or replace it."
- )
- diagnostics.extend(validate_platform_toolsets(config.get("platform_toolsets"), is_valid_platform_name))
-
- plugins = config.get("plugins") or {}
- disabled = set(parse_config_string_list(plugins.get("disabled"))) if isinstance(plugins, dict) else set()
- for name, manifest in manifests:
+ disabled = _get_disabled_plugins()
+ for name, manifest in _platform_plugin_manifests(source="bundled"):
key = f"platforms/{name}"
- if not {key, str(manifest.get("name") or "")}.intersection(disabled):
+ if not {key, str(manifest.get("name"))} & disabled:
continue
- requirements = manifest.get("requires_env") or []
- required_names = [
- item if isinstance(item, str) else item.get("name")
- for item in requirements
- if isinstance(item, str) or isinstance(item, dict)
- ]
- if required_names and all(
- required_name and get_env_value(required_name) for required_name in required_names
- ):
+ required = [env for env, _secret, _meta in _platform_manifest_env_entries(manifest, optional=False)]
+ if required and all(get_env_value(env) for env in required):
diagnostics.append(
f"platform plugin '{key}' is disabled while its required credentials are configured. "
f"Run `hermes plugins enable {key}` if you want it active."
diff --git a/hermes_cli/toolset_validation.py b/hermes_cli/toolset_validation.py
index 4846f558da0..5c15300045d 100644
--- a/hermes_cli/toolset_validation.py
+++ b/hermes_cli/toolset_validation.py
@@ -50,6 +50,30 @@ def _platform_default_is_valid(
return False
+def saved_toolset_resolver(config: dict) -> Callable[[str], bool]:
+ """``is_valid_toolset`` for a saved ``platform_toolsets`` list, mirroring what
+ ``tools_config._get_platform_tools`` lets through: registered toolsets, any configured MCP server
+ (a disabled one is inactive, not a typo), ``hermes-<platform>`` plugin-platform bundles and the
+ ``no_mcp`` sentinel. Plugin-provided names are consulted last because resolving them may run
+ plugin discovery, which a config without such names never needs."""
+ from functools import cache
+
+ from hermes_cli.config import _platform_plugin_manifests
+ from toolsets import validate_toolset
+
+ mcp_servers = config.get("mcp_servers")
+ known = {str(name) for name in mcp_servers} if isinstance(mcp_servers, dict) else set()
+ known |= {f"hermes-{name}" for name, _manifest in _platform_plugin_manifests()} | {"no_mcp"}
+
+ @cache
+ def plugin_names() -> frozenset:
+ from hermes_cli.plugins import get_plugin_toolset_keys_nowait, get_portable_mcp_server_names_nowait
+
+ return frozenset(get_plugin_toolset_keys_nowait() | get_portable_mcp_server_names_nowait())
+
+ return lambda name: validate_toolset(name) or name in known or name in plugin_names()
+
+
def validate_platform_toolsets(
platform_toolsets: object, is_valid_toolset: Callable[[str], bool],
is_allowed_for_platform: Callable[[str, str], bool] = toolset_allowed_for_platform,
diff --git a/tests/hermes_cli/test_config_check_diagnostics.py b/tests/hermes_cli/test_config_check_diagnostics.py
index 3920fd96398..d7cf955a872 100644
--- a/tests/hermes_cli/test_config_check_diagnostics.py
+++ b/tests/hermes_cli/test_config_check_diagnostics.py
@@ -2,7 +2,16 @@
from pathlib import Path
-from hermes_cli.config import DEFAULT_CONFIG, _cmd_config_check
+import hermes_cli.config as config_mod
+from hermes_cli.config import DEFAULT_CONFIG, _cmd_config_check, _warn_invalid_platform_toolsets
+
+
+def _write_home(home: Path, body: str, env: str = "") -> Path:
+ home.mkdir()
+ (home / "config.yaml").write_text(f"_config_version: {DEFAULT_CONFIG['_config_version']}\n{body}", encoding="utf-8")
+ if env:
+ (home / ".env").write_text(env, encoding="utf-8")
+ return home
def _check(home: Path, monkeypatch, capsys) -> str:
@@ -11,57 +20,55 @@ def _check(home: Path, monkeypatch, capsys) -> str:
return capsys.readouterr().out
-def test_config_check_reports_stale_toolsets_without_mislabeling_mcp_or_plugin_bundles(
- tmp_path, monkeypatch, capsys,
-):
- home_a = tmp_path / "a"
- home_b = tmp_path / "b"
- home_a.mkdir()
- home_b.mkdir()
- version = DEFAULT_CONFIG["_config_version"]
- (home_a / "config.yaml").write_text(
- f"_config_version: {version}\n"
- "toolsets: [hermes-cli, messaging]\n"
+def test_config_check_and_migrate_agree_on_stale_platform_toolsets(tmp_path, monkeypatch, capsys):
+ stale = _write_home(
+ tmp_path / "stale",
"platform_toolsets:\n"
- " cli: [hermes-cli, messaging, linear]\n"
+ " cli: [hermes-cli, messaging, linear, ghost]\n"
" teams: [hermes-teams]\n"
"mcp_servers:\n"
" linear:\n"
- " command: linear-mcp\n",
- encoding="utf-8",
- )
- (home_b / "config.yaml").write_text(
- f"_config_version: {version}\ntoolsets: [hermes-cli]\n",
- encoding="utf-8",
+ " command: linear-mcp\n"
+ " enabled: false\n"
+ # Bookkeeping for a plugin that is no longer installed is not proof its toolset exists.
+ "known_plugin_toolsets:\n"
+ " cli: [ghost]\n",
)
+ # A malformed mcp_servers section must not crash the check.
+ clean = _write_home(tmp_path / "clean", "platform_toolsets:\n cli: [hermes-cli]\nmcp_servers: [a]\n")
- for home, stale in ((home_a, True), (home_b, False), (home_a, True)):
+ for home, expected in ((stale, {"messaging", "ghost"}), (clean, set()), (stale, {"messaging", "ghost"})):
output = _check(home, monkeypatch, capsys)
- assert ("toolsets contains unknown name 'messaging'" in output) is stale
- assert ("platform 'cli' references unknown toolset 'messaging'" in output) is stale
- assert "unknown toolset 'linear'" not in output
- assert "unknown toolset 'hermes-teams'" not in output
+ for name in ("messaging", "ghost", "linear", "hermes-teams"):
+ assert (f"unknown toolset '{name}'" in output) is (name in expected), (home.name, name)
+ results = {"warnings": []}
+ _warn_invalid_platform_toolsets(results, quiet=True)
+ assert {w for w in results["warnings"] if "unknown toolset" in w} == {
+ line.strip().removeprefix("⚠ ") for line in output.splitlines() if "unknown toolset" in line
+ }
-def test_config_check_reports_only_configured_disabled_platforms(tmp_path, monkeypatch, capsys):
- home_a = tmp_path / "a"
- home_b = tmp_path / "b"
- home_c = tmp_path / "c"
- for home in (home_a, home_b, home_c):
- home.mkdir()
- disabled_name = "telegram-platform" if home == home_c else "platforms/telegram"
- (home / "config.yaml").write_text(
- f"_config_version: {DEFAULT_CONFIG['_config_version']}\n"
- f"plugins:\n disabled: [{disabled_name}]\n",
- encoding="utf-8",
- )
- (home_a / ".env").write_text("TELEGRAM_BOT_TOKEN=synthetic-test-token\n", encoding="utf-8")
- (home_c / ".env").write_text("TELEGRAM_BOT_TOKEN=synthetic-test-token\n", encoding="utf-8")
- monkeypatch.delenv("TELEGRAM_BOT_TOKEN", raising=False)
- for home, configured in ((home_a, True), (home_b, False), (home_c, True), (home_a, True)):
+def test_config_check_reports_disabled_platform_only_when_runtime_disables_it(tmp_path, monkeypatch, capsys):
+ manifest = {
+ "name": "fakechat-platform",
+ "requires_env": [{"name": "FAKECHAT_TOKEN"}],
+ "optional_env": [{"name": "FAKECHAT_HOME_CHANNEL"}],
+ }
+ monkeypatch.setattr(config_mod, "_platform_plugin_manifests", lambda *a, **k: iter([("fakechat", manifest)]))
+ monkeypatch.delenv("FAKECHAT_TOKEN", raising=False)
+ token = "FAKECHAT_TOKEN=synthetic-test-token\n"
+ cases = (
+ (_write_home(tmp_path / "key", "plugins:\n disabled: [platforms/fakechat]\n", token), True),
+ (_write_home(tmp_path / "name", "plugins:\n disabled: [fakechat-platform]\n", token), True),
+ (_write_home(tmp_path / "no_token", "plugins:\n disabled: [platforms/fakechat]\n"), False),
+ # The runtime ignores a non-list plugins.disabled, so the platform is not disabled.
+ (_write_home(tmp_path / "string", "plugins:\n disabled: platforms/fakechat\n", token), False),
+ )
+
+ for home, reported in (*cases, cases[0]):
output = _check(home, monkeypatch, capsys)
- assert ("platform plugin 'platforms/telegram' is disabled" in output) is configured
- if configured:
- assert "hermes plugins enable platforms/telegram" in output
+ assert ("platform plugin 'platforms/fakechat' is disabled" in output) is reported, home.name
+ if reported:
+ assert "hermes plugins enable platforms/fakechat" in output
assert "synthetic-test-token" not in output