Skip to content

The agent that grows with you

fix(cli): read a JSON-list string platform_toolsets entry as the list it encodes

liuhao1024d4798eae1fb3
diff --git a/hermes_cli/tools_config.py b/hermes_cli/tools_config.py
index 03f01c4e99c..03b8a949cd4 100644
--- a/hermes_cli/tools_config.py
+++ b/hermes_cli/tools_config.py
@@ -1,5 +1,6 @@
"""Unified tool configuration for Hermes Agent."""
+import ast
import json as _json
import logging
import os
@@ -548,10 +549,29 @@ def _context_engine_active(config: dict) -> bool:
return bool(name) and name != "compressor"
+def _coerce_platform_toolsets_value(value):
+ """Read a JSON-list string saved for ``platform_toolsets.<platform>`` as the list it encodes.
+
+ ``hermes config set`` stores a bare ``[...]`` argument as a plain string, so an explicit
+ selection like ``'["browser", "terminal"]'`` parses as str, not list — readers then treat
+ the platform as unconfigured and substitute the platform default, and the next save
+ overwrites the user's entries (#115866). Anything that does not parse as a list keeps its
+ original value: a scalar string still means "not a list" and keeps the default fallback.
+ """
+ if isinstance(value, str) and value.strip().startswith("["):
+ try:
+ parsed = ast.literal_eval(value.strip())
+ except (ValueError, SyntaxError):
+ return value
+ if isinstance(parsed, list):
+ return [str(item) for item in parsed]
+ return value
+
+
def _get_platform_tools(config: dict, platform: str, *, include_default_mcp_servers: bool = True) -> Set[str]:
"""Resolve which individual toolset names are enabled for a platform."""
platform_toolsets = config.get("platform_toolsets") or {}
- toolset_names = platform_toolsets.get(platform)
+ toolset_names = _coerce_platform_toolsets_value(platform_toolsets.get(platform))
# An explicitly saved list (even a composite like ``hermes-discord``) is an opt-in to the platform's
# native default-off toolsets — see _default_off_toolsets.
# Track whether the user explicitly saved a toolset list for this platform (vs. falling back to the
@@ -603,7 +623,7 @@ def _get_platform_tools(config: dict, platform: str, *, include_default_mcp_serv
enabled_toolsets = _prune_toolsets_stripped_by_disabled(enabled_toolsets, disabled_names)
if explicitly_configured and toolset_names:
- _warn_all_invalid_platform_toolsets(platform, platform_toolsets[platform])
+ _warn_all_invalid_platform_toolsets(platform, toolset_names)
return enabled_toolsets
@@ -692,7 +712,9 @@ def _save_platform_tools(config: dict, platform: str, enabled_toolset_keys: Set[
# unchecked selections on the next read. Saving from the picker is consent to clear the "no_mcp" sentinel
# (no checkbox for it; users who once set it by hand could otherwise never re-enable MCP via the UI).
drop = _configurable_keys() | plugin_keys | _platform_default_keys() | {"no_mcp"}
- existing_toolsets = cfg_get(config, "platform_toolsets", platform, default=[])
+ existing_toolsets = _coerce_platform_toolsets_value(
+ cfg_get(config, "platform_toolsets", platform, default=[])
+ )
preserved_entries = {str(e) for e in (existing_toolsets if isinstance(existing_toolsets, list) else [])
if str(e) not in drop}
config["platform_toolsets"][platform] = sorted(enabled_toolset_keys | preserved_entries)
diff --git a/tests/hermes_cli/test_tools_config.py b/tests/hermes_cli/test_tools_config.py
index 0fb971c5b44..3fa23acdc85 100644
--- a/tests/hermes_cli/test_tools_config.py
+++ b/tests/hermes_cli/test_tools_config.py
@@ -98,6 +98,45 @@ def test_scalar_platform_toolsets_fall_back_to_platform_default():
assert enabled == default_enabled
+def test_string_platform_toolsets_resolves_as_the_list_it_encodes():
+ """#115866: `hermes config set` stores a bare ``[...]`` argument as a plain
+ string, so an explicit selection parses as str and was treated as
+ unconfigured — resolving to the platform default instead of the listed
+ toolsets (including default-off ones like video/video_gen)."""
+ config = {"platform_toolsets": {"telegram": '["browser", "terminal", "video", "video_gen"]'}}
+
+ enabled = _get_platform_tools(config, "telegram", include_default_mcp_servers=False)
+
+ assert {"browser", "terminal", "video", "video_gen"} <= enabled
+
+
+def test_enable_on_string_platform_toolsets_keeps_listed_entries():
+ """#115866: `hermes tools enable` must operate on the selection a JSON-list
+ string encodes — not re-baseline it on the platform default, which silently
+ dropped the user's default-off entries (video, video_gen) on write."""
+ config = {"platform_toolsets": {"telegram": '["browser", "terminal", "video", "video_gen"]'}}
+
+ with patch("hermes_cli.tools_config.save_config"):
+ _apply_toolset_change(config, "telegram", ["computer_use"], "enable")
+
+ saved = config["platform_toolsets"]["telegram"]
+ assert isinstance(saved, list)
+ assert {"browser", "terminal", "video", "video_gen", "computer_use"} <= set(saved)
+
+
+def test_malformed_list_string_platform_toolsets_fall_back_to_platform_default():
+ """A string that fails to parse as a list is still "not a list" — the
+ resolver keeps the platform-default fallback instead of raising (#115866)."""
+ config = {"platform_toolsets": {"cli": '["web", terminal'}}
+
+ enabled = _get_platform_tools(config, "cli", include_default_mcp_servers=False)
+ default_enabled = _get_platform_tools(
+ {}, "cli", include_default_mcp_servers=False
+ )
+
+ assert enabled == default_enabled
+
+