The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui): profiles.configure toolset pin writes the key the runtime reads (#119399)
Siddharth Balyan79ee6bcf7248
diff --git a/tests/tui_gateway/test_profiles_toolset_pin.py b/tests/tui_gateway/test_profiles_toolset_pin.pynew file mode 100644index 00000000000..7c8446bbdb9--- /dev/null+++ b/tests/tui_gateway/test_profiles_toolset_pin.py@@ -0,0 +1,48 @@+"""profiles.configure ``enabled_toolsets`` must pin the key the runtime reads.++Invariant: whatever ``_save_toolset_pin`` writes, ``_load_enabled_toolsets`` (via ``_get_platform_tools(cfg, "cli")``)+reads back as the enabled set, and ``_describe_toolsets`` reports the same pin. Before the fix the writer used a+``tools.enabled_toolsets`` key that nothing reads, so a pin of ``[web]`` still produced the full default set.+"""++import pytest++from tui_gateway.methods_profiles import _describe_toolsets, _save_toolset_pin+++def _pin_and_resolve(cfg: dict, names: list[str]) -> tuple[set[str], set[str] | None]:+ from hermes_cli.tools_config import _get_platform_tools++ _save_toolset_pin(cfg, names, save_config=lambda _c: None)+ resolved = set(_get_platform_tools(cfg, "cli", include_default_mcp_servers=False))+ _toolsets, pinned = _describe_toolsets(cfg)+ return resolved, pinned+++def test_toolset_pin_is_what_the_runtime_reads():+ cfg: dict = {}+ resolved, pinned = _pin_and_resolve(cfg, ["web"])+ assert resolved == {"web"}, f"runtime resolved {sorted(resolved)} for a [web] pin"+ assert pinned == {"web"}+ assert "enabled_toolsets" not in (cfg.get("tools") or {}), "writer must not leave the phantom key behind"++[email protected]("second", [["file", "terminal"], []])+def test_toolset_pin_round_trips_a_then_b_then_a(second):+ cfg: dict = {}+ first, _ = _pin_and_resolve(cfg, ["web"])+ _pin_and_resolve(cfg, second)+ again, pinned = _pin_and_resolve(cfg, ["web"])+ assert first == again == {"web"}+ assert pinned == {"web"}+++def test_empty_pin_clears_the_pin_and_falls_back_to_the_platform_default():+ from hermes_cli.tools_config import _get_platform_tools++ cfg: dict = {}+ _pin_and_resolve(cfg, ["web"])+ _save_toolset_pin(cfg, [], save_config=lambda _c: None)+ _toolsets, pinned = _describe_toolsets(cfg)+ assert pinned is None+ assert set(_get_platform_tools(cfg, "cli", include_default_mcp_servers=False)) != {"web"}diff --git a/tui_gateway/methods_profiles.py b/tui_gateway/methods_profiles.pyindex 074bb51ac66..3c0a140a358 100644--- a/tui_gateway/methods_profiles.py+++ b/tui_gateway/methods_profiles.py@@ -427,9 +427,10 @@ def _describe_toolsets(cfg):"""``(toolsets, pinned_set)`` as the `hermes tools` checklist presents them (the raw registryleaks platform composites and reports everything enabled without a pin)."""from hermes_cli.tools_config import (- _get_effective_configurable_toolsets, _get_platform_tools, _toolset_allowed_for_platform)+ _coerce_platform_toolsets_value, _get_effective_configurable_toolsets, _get_platform_tools,+ _toolset_allowed_for_platform)from toolsets import resolve_toolset- pinned = (cfg.get("tools") if isinstance(cfg.get("tools"), dict) else {}).get("enabled_toolsets")+ pinned = _coerce_platform_toolsets_value((cfg.get("platform_toolsets") or {}).get("cli"), "cli")pinned_set = _clean_names(pinned) if isinstance(pinned, list) else Noneplatform_enabled = _try(lambda: set(_get_platform_tools(cfg, "cli", include_default_mcp_servers=False)), set())default_off = _try(lambda: _lazy("hermes_cli.tools_config", "_DEFAULT_OFF_TOOLSETS"), set())@@ -556,13 +557,15 @@ def _clean_names(values) -> set:def _save_toolset_pin(cfg, enabled, save_config) -> None:- wanted = sorted(_clean_names(enabled))- tools_cfg = cfg.get("tools") if isinstance(cfg.get("tools"), dict) else {}+ """Pin ``platform_toolsets.cli``: the key ``_load_enabled_toolsets`` reads and ``hermes tools`` writes.+ An empty selection clears the pin so the platform default applies again."""+ from hermes_cli.tools_config import _save_platform_tools++ wanted = _clean_names(enabled)if wanted:- tools_cfg["enabled_toolsets"] = wanted- else:- tools_cfg.pop("enabled_toolsets", None)- cfg["tools"] = tools_cfg+ _save_platform_tools(cfg, "cli", wanted)+ elif isinstance(cfg.get("platform_toolsets"), dict):+ cfg["platform_toolsets"].pop("cli", None)save_config(cfg)