The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(config): hermes doctor and plugins enable read a list-literal platform_toolsets string
teknium1b5d7a7b15ded
diff --git a/hermes_cli/nous_subscription.py b/hermes_cli/nous_subscription.pyindex 9f551b9cb82..b8bc183007f 100644--- a/hermes_cli/nous_subscription.py+++ b/hermes_cli/nous_subscription.py@@ -165,8 +165,9 @@ def _toolset_enabled(config: Dict[str, object], toolset_key: str) -> bool:target_tools = set(resolve_toolset(toolset_key))if not target_tools:return False+ from hermes_cli.toolset_validation import parse_platform_toolsets_valuefor platform, raw_toolsets in platform_toolsets.items():- toolset_names = list(raw_toolsets) if isinstance(raw_toolsets, list) else []+ toolset_names = list(parse_platform_toolsets_value(raw_toolsets) or [])if not toolset_names:toolset_names = [t for t in (_DEFAULT_PLATFORM_TOOLSETS.get(platform),) if t]available_tools: Set[str] = set()diff --git a/hermes_cli/plugins_cmd.py b/hermes_cli/plugins_cmd.pyindex 13a787efe4f..a16a7af3d66 100644--- a/hermes_cli/plugins_cmd.py+++ b/hermes_cli/plugins_cmd.py@@ -1908,12 +1908,17 @@ def _toggle_plugin_toolset(name: str, *, enable: bool) -> None:if not toolset_key:returnfrom hermes_cli.config import load_config, save_config+ from hermes_cli.toolset_validation import parse_platform_toolsets_valueconfig = load_config()platform_toolsets = _child_dict(config, "platform_toolsets")changed = False- for ts_list in platform_toolsets.values():- if isinstance(ts_list, list) and enable != (toolset_key in ts_list):+ for platform, raw in list(platform_toolsets.items()):+ # A list-literal string (older `hermes config set`) is the user's real selection; toggling+ # it re-saves the entry as a proper list so the string never persists.+ ts_list = parse_platform_toolsets_value(raw)+ if ts_list is not None and enable != (toolset_key in ts_list):(ts_list.append if enable else ts_list.remove)(toolset_key)+ platform_toolsets[platform] = ts_listchanged = True# Enabling with no platform lists yet: seed "cli" at minimum.if enable and not changed and not platform_toolsets:diff --git a/hermes_cli/tools_config.py b/hermes_cli/tools_config.pyindex d766e457684..1453d4a0da4 100644--- a/hermes_cli/tools_config.py+++ b/hermes_cli/tools_config.py@@ -1,6 +1,5 @@"""Unified tool configuration for Hermes Agent."""-import astimport json as _jsonimport loggingimport os@@ -15,6 +14,7 @@ from hermes_cli.nous_subscription import (from hermes_cli.platforms import PLATFORMS as _PLATFORMS_REGISTRYfrom hermes_cli.toolset_scope import (_TOOLSET_PLATFORM_RESTRICTIONS, toolset_allowed_for_platform as _toolset_allowed_for_platform)+from hermes_cli.toolset_validation import parse_platform_toolsets_value# Re-exports: keep ``hermes_cli.tools_config.X`` callers and test patch targets resolving.from hermes_cli.tools_config_cua import ( # noqa: F401_post_setup_no_window_flags, _cua_driver_cmd, _cua_version_summary, _resolved_cua_driver_cmd, _cua_driver_env,@@ -552,23 +552,16 @@ def _context_engine_active(config: dict) -> bool:def _coerce_platform_toolsets_value(value, platform: str):"""Read a list-literal string saved for ``platform_toolsets.<platform>`` as the list it encodes.- Older ``hermes config set`` builds stored a bare ``[...]`` argument as a plain string, so an- explicit selection like ``'["browser", "terminal"]'`` parses as str, not list — readers then- treated the platform as unconfigured and substituted the platform default, and the next save- overwrote the user's entries (#115866). The parser is ``ast.literal_eval``, so any Python- list literal (JSON-style double quotes included) is accepted. Any other non-list value is- warned about once (naming the expected shape) and left as-is, so the default fallback below- is loud rather than silent.+ The parser is shared with ``hermes doctor`` and ``hermes plugins`` (``toolset_validation``+ ``parse_platform_toolsets_value``) so every surface agrees on the user's selection (#115866).+ Any other non-list value is warned about once (naming the expected shape) and left as-is, so+ the default fallback below is loud rather than silent."""- if value is None or isinstance(value, list):- return value- if isinstance(value, str) and value.strip().startswith("["):- try:- parsed = ast.literal_eval(value.strip())- except (ValueError, SyntaxError):- parsed = None- if isinstance(parsed, list):- return [str(item) for item in parsed]+ if value is None:+ return None+ parsed = parse_platform_toolsets_value(value)+ if parsed is not None:+ return parsedif platform not in _warned_invalid_platform_toolsets:_warned_invalid_platform_toolsets.add(platform)logger.warning(diff --git a/hermes_cli/toolset_validation.py b/hermes_cli/toolset_validation.pyindex 72cbc3a6b97..4846f558da0 100644--- a/hermes_cli/toolset_validation.py+++ b/hermes_cli/toolset_validation.py@@ -1,6 +1,7 @@"""Validation for the ``platform_toolsets`` config section."""-from typing import Callable, List+import ast+from typing import Callable, List, Optionalfrom hermes_cli.platforms import PLATFORMSfrom hermes_cli.toolset_scope import toolset_allowed_for_platform@@ -8,6 +9,27 @@ from hermes_cli.toolset_scope import toolset_allowed_for_platform_NO_TOOLS = "the agent will have no tools on this platform. Run `hermes tools` to reconfigure."+def parse_platform_toolsets_value(value: object) -> Optional[List[str]]:+ """The toolset list a saved ``platform_toolsets.<platform>`` value encodes, or None.++ Older ``hermes config set`` builds stored a bare ``[...]`` argument as a plain string, so an+ explicit selection like ``'["browser", "terminal"]'`` parses as str, not list (#115866).+ Every reader and writer of the section goes through this one parser so the runtime,+ ``hermes doctor`` and ``hermes plugins enable`` agree on what the user configured. Any other+ shape (null, scalar, unparseable string) is None: the caller decides how to report it.+ """+ if isinstance(value, list):+ return value+ if isinstance(value, str) and value.strip().startswith("["):+ try:+ parsed = ast.literal_eval(value.strip())+ except (ValueError, SyntaxError):+ return None+ if isinstance(parsed, list):+ return [str(item) for item in parsed]+ return None++def _platform_default_toolset(platform: object) -> str:info = PLATFORMS.get(platform)return info.default_toolset if info is not None else f"hermes-{platform}"@@ -47,7 +69,8 @@ def validate_platform_toolsets(default = _platform_default_toolset(platform)default_valid = _platform_default_is_valid(platform, default, is_valid_toolset, is_allowed_for_platform)platform_valid_count = 0- if not isinstance(raw, list):+ toolsets = parse_platform_toolsets_value(raw)+ if toolsets is None:if default_valid:valid_count += 1platform_valid_count += 1@@ -65,7 +88,7 @@ def validate_platform_toolsets(warnings.append(f"platform '{platform}' has no valid toolsets configured — {_NO_TOOLS}")continue- for name in raw:+ for name in toolsets:if not isinstance(name, str) or not name:continueif not is_valid_toolset(name):@@ -80,7 +103,7 @@ def validate_platform_toolsets()if platform_valid_count == 0:- reason = "is configured with an empty toolset list" if not raw else "has no valid toolsets configured"+ reason = "is configured with an empty toolset list" if not toolsets else "has no valid toolsets configured"warnings.append(f"platform '{platform}' {reason} — {_NO_TOOLS}")if valid_count == 0:diff --git a/tests/hermes_cli/test_plugins_cmd.py b/tests/hermes_cli/test_plugins_cmd.pyindex 600ae1bd3bc..fb4f3f09bf8 100644--- a/tests/hermes_cli/test_plugins_cmd.py+++ b/tests/hermes_cli/test_plugins_cmd.py@@ -945,3 +945,26 @@ def test_autostash_dirty_tree_promotes_intent_to_add_entries(tmp_path):assert (stashed, error) == (True, ""), "the plugin autostash must not be blocked by i-t-a entries"assert git("status", "--porcelain").stdout == ""+++def test_toggle_plugin_toolset_rewrites_a_list_literal_string_platform_entry(tmp_path, monkeypatch):+ """``hermes plugins enable`` must reach a platform whose ``platform_toolsets`` entry is the+ list-literal string an older ``hermes config set`` stored, and re-save it as a real list —+ the runtime already reads that string as the user's selection (follow-up to #115866)."""++ from hermes_cli import plugins_cmd++ monkeypatch.setenv("HERMES_HOME", str(tmp_path))+ (tmp_path / "config.yaml").write_text(+ yaml.safe_dump({"platform_toolsets": {"cli": '["web", "terminal"]', "telegram": ["hermes-telegram"]}}),+ encoding="utf-8")+ monkeypatch.setattr(plugins_cmd, "_get_plugin_toolset_key", lambda name: "my-plugin")++ plugins_cmd._toggle_plugin_toolset("my-plugin", enable=True)+ saved = yaml.safe_load((tmp_path / "config.yaml").read_text(encoding="utf-8"))["platform_toolsets"]+ assert saved["cli"] == ["web", "terminal", "my-plugin"]+ assert saved["telegram"] == ["hermes-telegram", "my-plugin"]++ plugins_cmd._toggle_plugin_toolset("my-plugin", enable=False)+ saved = yaml.safe_load((tmp_path / "config.yaml").read_text(encoding="utf-8"))["platform_toolsets"]+ assert saved["cli"] == ["web", "terminal"]diff --git a/tests/hermes_cli/test_toolset_validation.py b/tests/hermes_cli/test_toolset_validation.pyindex 6663d1bcfb0..c6b2bffea8a 100644--- a/tests/hermes_cli/test_toolset_validation.py+++ b/tests/hermes_cli/test_toolset_validation.py@@ -141,6 +141,17 @@ def test_scalar_platform_value_warns_but_uses_platform_default():assert not any("zero valid toolsets" in w for w in warnings)+def test_list_literal_string_is_validated_as_the_list_it_encodes():+ """A ``'["web", "terminal"]'`` string (older ``hermes config set``) is the user's real selection:+ the runtime resolves it, so ``hermes doctor`` must validate its names instead of reporting a+ fallback to the platform default that never happens (follow-up to #115866)."""+ assert validate_platform_toolsets({"cli": '["web", "terminal"]'}, _is_valid) == []++ warnings = validate_platform_toolsets({"cli": '["web", "nope"]'}, _is_valid)+ assert any("platform 'cli' references unknown toolset 'nope'" in w for w in warnings)+ assert not any("falling back" in w for w in warnings)++def test_platform_restricted_toolset_warns_when_other_platform_is_valid():cfg = {"telegram": ["discord"], "cli": ["hermes-cli"]}warnings = validate_platform_toolsets(cfg, _is_valid)