The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): leave the profile-default toolsets to the gateway on session.create
unsupportedpastels1d2f5a441e94
diff --git a/cli.py b/cli.pyindex 2c9e37f672e..20462b8acac 100644--- a/cli.py+++ b/cli.py@@ -1499,6 +1499,7 @@ class HermesCLI(CLIInitMixin, CLITuiRuntimeMixin, CLIProcessNotificationsMixin,def _build_cli_from_args(model, toolsets, provider, reasoning, api_key, base_url, max_turns, run_budget, verbose, compact, resume, checkpoints, pass_session_id, ignore_rules, skills):"""Resolve the toolset list (explicit / coding posture / platform default), construct HermesCLI, and start the background skills preload."""toolsets_list = None+ profile_default = Falseif isinstance(toolsets, str) and toolsets:toolsets_list = [t.strip() for t in toolsets.split(",")]elif isinstance(toolsets, (list, tuple)) and toolsets:@@ -1516,6 +1517,7 @@ def _build_cli_from_args(model, toolsets, provider, reasoning, api_key, base_urlif toolsets_list is None:from hermes_cli.tools_config import _get_platform_toolstoolsets_list = sorted(_get_platform_tools(CLI_CONFIG, "cli"))+ profile_default = Trueparsed_skills = _parse_skills_argument(skills)@@ -1543,6 +1545,8 @@ def _build_cli_from_args(model, toolsets, provider, reasoning, api_key, base_urlif emit_partial_update_hint(e):sys.exit(1)raise+ if profile_default:+ cli._explicit_toolsets = False # the gateway resolves the profile's toolsets itself# skills.auto_load rides the same background preload as -s; --ignore-rules skips it with# the rest of the auto-injected context. Resolved here (not lazily in the agent) so thediff --git a/hermes_cli/cli_init_mixin.py b/hermes_cli/cli_init_mixin.pyindex b7750127be3..7dd41eabf26 100644--- a/hermes_cli/cli_init_mixin.py+++ b/hermes_cli/cli_init_mixin.py@@ -215,6 +215,9 @@ class CLIInitMixin:def _init_toolsets(self, toolsets):from cli import CLI_CONFIG, validate_toolsetself.enabled_toolsets = toolsets+ # Only a picked list rides session.create; _build_cli_from_args clears this for the profile default,+ # which the gateway resolves itself (an explicit list with a stale name is refused, #138670).+ self._explicit_toolsets = toolsets is not Nonefrom agent.skill_utils import parse_config_string_listself.disabled_toolsets = parse_config_string_list(CLI_CONFIG["agent"].get("disabled_toolsets"))@@ -372,7 +375,7 @@ class CLIInitMixin:and self.requested_provider not in {None, "", "auto"} else None),"api_key": getattr(self, "_explicit_api_key", None),"base_url": getattr(self, "_explicit_base_url", None),- "toolsets": self.enabled_toolsets,+ "toolsets": self.enabled_toolsets if getattr(self, "_explicit_toolsets", False) else None,# Main handed these to AIAgent; the gateway's agent gets them as creation policy."reasoning": getattr(self, "_explicit_reasoning", None),"max_turns": getattr(self, "_explicit_max_turns", None),@@ -411,7 +414,8 @@ class CLIInitMixin:return new_session_id(now)if branch_of:return store.branch(branch_of, title)- sid = store.create({"toolsets": getattr(self, "enabled_toolsets", None),+ toolsets = getattr(self, "enabled_toolsets", None) if getattr(self, "_explicit_toolsets", False) else None+ sid = store.create({"toolsets": toolsets,"pass_session_id": getattr(self, "pass_session_id", False) or None,"ignore_rules": getattr(self, "ignore_rules", False) or None}, record_cwd=False)self.session_id = siddiff --git a/tests/hermes_cli/test_cli_profile_toolsets.py b/tests/hermes_cli/test_cli_profile_toolsets.pynew file mode 100644index 00000000000..96369a3217f--- /dev/null+++ b/tests/hermes_cli/test_cli_profile_toolsets.py@@ -0,0 +1,87 @@+"""A stale ``platform_toolsets.cli`` entry (a toolset whose plugin was uninstalled) must not refuse every+`hermes chat` (#138670): the profile default is the gateway's to resolve, only a picked list rides+session.create. The CLI's launch params go through the real gateway policy build (scripted transport)."""+from contextlib import asynccontextmanager++import pytest++from hermes_cli.gateway_connection import GatewayConnection+from hermes_cli.gateway_session_store import GatewaySessionStore+from tests.hermes_cli.test_gateway_session_store import FakeClient++CONFIG = {"agent": {}, "platform_toolsets": {"cli": ["terminal", "gone_plugin"]}}+++def store():+ client = FakeClient()++ @asynccontextmanager+ async def connect():+ yield client+ conn = GatewayConnection(connect=connect)+ conn.start(5)+ yield GatewaySessionStore(conn), client+ conn.close()+++def _launch(monkeypatch, db, toolsets=None, coding=None):+ """``_build_cli_from_args`` then the session's gateway create; HermesCLI is the real toolset init on a+ bare host. Returns the CLI and the lines its startup printed."""+ import cli as cli_mod+ from hermes_cli.cli_init_mixin import CLIInitMixin+ monkeypatch.delenv("HERMES_SESSION_SOURCE", raising=False)+ monkeypatch.setattr(cli_mod, "CLI_CONFIG", CONFIG)+ monkeypatch.setattr("agent.coding_context.coding_selection", lambda **_: coding)+ monkeypatch.setattr("hermes_cli.plugins.get_plugin_toolset_keys_nowait", lambda: set())+ printed = []++ class Host(CLIInitMixin):+ def __init__(self, toolsets=None, **_):+ self.model, self.requested_provider, self._resumed = "m1", "auto", False+ self.session_id, self._session_db, self.ignore_rules = "20261012_000000_abcdef", db, False+ self._console_print = printed.append+ self._init_toolsets(toolsets)+ monkeypatch.setattr(cli_mod, "HermesCLI", Host)+ host = cli_mod._build_cli_from_args(None, toolsets, None, None, None, None, None, None, None, False, None,+ False, False, False, None)+ host._ensure_gateway_session()+ return host, printed+++def _created(client):+ return dict([c for c in client.calls if c[0] == "session.create"][-1][1])+++def test_stale_profile_toolset_warns_and_the_session_is_created(store, monkeypatch):+ from gateway.session_local_inventory import _policy_tools+ from gateway.session_policy import build_policy+ db, client = store+ host, printed = _launch(monkeypatch, db)+ assert len(printed) == 1 and "gone_plugin" in printed[0] # main's "Unknown toolsets" startup warning+ params = _created(client)+ assert "toolsets" not in params+ policy = build_policy(params, CONFIG)+ assert "terminal" in policy.toolsets+ _enabled, tools = _policy_tools(policy, CONFIG)+ assert "terminal" in {tool["function"]["name"] for tool in tools}+ # /new is a fresh session.create on the same profile default.+ host._new_session_id(None)+ assert "toolsets" not in _created(client)+++def test_explicit_unknown_toolset_is_still_refused(store, monkeypatch):+ from gateway.session_policy import build_policy+ from hermes_state_runtime import RuntimeStoreError+ db, client = store+ _launch(monkeypatch, db, toolsets="terminal,bogus")+ params = _created(client)+ assert params["toolsets"] == ["terminal", "bogus"]+ with pytest.raises(RuntimeStoreError, match="invalid_params"):+ build_policy(params, CONFIG)+++def test_coding_posture_selection_still_rides_session_create(store, monkeypatch):+ db, client = store+ _launch(monkeypatch, db, coding=["terminal"])+ assert _created(client)["toolsets"] == ["terminal"]