The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): warn once when platform_toolsets.<platform> is not a list
teknium13adc178718fd
diff --git a/hermes_cli/tools_config.py b/hermes_cli/tools_config.pyindex c12dcdab386..d766e457684 100644--- a/hermes_cli/tools_config.py+++ b/hermes_cli/tools_config.py@@ -549,31 +549,39 @@ def _context_engine_active(config: dict) -> bool:return bool(name) and name != "compressor"-def _coerce_platform_toolsets_value(value):+def _coerce_platform_toolsets_value(value, platform: str):"""Read a list-literal 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). The parser is ``ast.literal_eval``, so any- Python list literal (JSON-style double quotes included) is accepted. 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.+ 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."""+ if value is None or isinstance(value, list):+ return valueif isinstance(value, str) and value.strip().startswith("["):try:parsed = ast.literal_eval(value.strip())except (ValueError, SyntaxError):- return value+ parsed = Noneif isinstance(parsed, list):return [str(item) for item in parsed]+ if platform not in _warned_invalid_platform_toolsets:+ _warned_invalid_platform_toolsets.add(platform)+ logger.warning(+ "platform_toolsets.%s is %r, expected a YAML list of toolset names "+ "(e.g. [terminal, file, web]) - falling back to the platform default. "+ "Run `hermes tools` to reconfigure.", platform, value)return valuedef _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 = _coerce_platform_toolsets_value(platform_toolsets.get(platform))+ toolset_names = _coerce_platform_toolsets_value(platform_toolsets.get(platform), 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@@ -715,7 +723,7 @@ def _save_platform_tools(config: dict, platform: str, enabled_toolset_keys: Set[# (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 = _coerce_platform_toolsets_value(- cfg_get(config, "platform_toolsets", platform, default=[])+ cfg_get(config, "platform_toolsets", platform, default=[]), platform)preserved_entries = {str(e) for e in (existing_toolsets if isinstance(existing_toolsets, list) else [])if str(e) not in drop}diff --git a/tests/hermes_cli/test_tools_config.py b/tests/hermes_cli/test_tools_config.pyindex 9ec8db25145..2e217a081b3 100644--- a/tests/hermes_cli/test_tools_config.py+++ b/tests/hermes_cli/test_tools_config.py@@ -98,18 +98,6 @@ 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 list-literalstring encodes — not re-baseline it on the platform default, which silently@@ -124,19 +112,21 @@ def test_enable_on_string_platform_toolsets_keeps_listed_entries():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)."""+def test_malformed_list_string_platform_toolsets_warns_then_falls_back(caplog):+ """A string that does not parse as a list falls back to the platform default+ loudly: one warning naming the expected shape, never a silent substitution (#115866)."""+ import hermes_cli.tools_config as tc+config = {"platform_toolsets": {"cli": '["web", terminal'}}+ tc._warned_invalid_platform_toolsets.discard("cli")- enabled = _get_platform_tools(config, "cli", include_default_mcp_servers=False)- default_enabled = _get_platform_tools(- {}, "cli", include_default_mcp_servers=False- )+ with caplog.at_level("WARNING", logger="hermes_cli.tools_config"):+ 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--+ assert [r for r in caplog.records if "platform_toolsets.cli" in r.getMessage()+ and "expected a YAML list" in r.getMessage()]