Skip to content

The agent that grows with you

fix(catalog): sessions off the desktop no longer see manage_catalog through tool_search (review)

alt-glitch901da1cb6a91
diff --git a/agent/agent_init.py b/agent/agent_init.py
index eaf57f603ce..b992849908c 100644
--- a/agent/agent_init.py
+++ b/agent/agent_init.py
@@ -1140,16 +1140,15 @@ def _load_tools(agent, enabled_toolsets, disabled_toolsets):
except Exception:
agent._tool_snapshot_generation = 0
import model_tools
+ from toolsets import agent_tool_drops, session_disabled_toolsets
+ disabled_toolsets = session_disabled_toolsets(disabled_toolsets, getattr(agent, "platform", None))
+ agent.disabled_toolsets = disabled_toolsets # so the tool_search bridge and delegate children drop them too
agent.tools = model_tools.get_tool_definitions(
- enabled_toolsets=enabled_toolsets, disabled_toolsets=disabled_toolsets,
- quiet_mode=agent.quiet_mode,
- )
+ enabled_toolsets=enabled_toolsets, disabled_toolsets=disabled_toolsets, quiet_mode=agent.quiet_mode)
# A finite -q run has no later session to learn for: no skill authoring tool (agent/oneshot_footprint.py).
from agent.oneshot_footprint import prune_oneshot_tools
agent.tools = prune_oneshot_tools(agent.tools or [])
- from toolsets import agent_tool_drops
- drops = agent_tool_drops(agent)
- if drops:
+ if drops := agent_tool_drops(agent):
agent.tools = [t for t in agent.tools if t["function"]["name"] not in drops]
agent.valid_tool_names = {tool["function"]["name"] for tool in agent.tools} if agent.tools else set()
diff --git a/apps/shared/src/gateway-contract.generated.ts b/apps/shared/src/gateway-contract.generated.ts
index 0aa03c2935a..59bf5d62c15 100644
--- a/apps/shared/src/gateway-contract.generated.ts
+++ b/apps/shared/src/gateway-contract.generated.ts
@@ -1084,7 +1084,7 @@ export interface CatalogScan {
export type CatalogScanStatus = 'passed' | 'warnings' | 'failed'
/** The desktop app a catalog plugin drives, from its ``hermes_platform`` declaration. */
export type CatalogAppState = 'present' | 'missing_app' | 'app_not_running' | 'unknown'
-/** The slow steps of an install, as ids; the desktop catalog card words them in its own language. The wire contract imports this enum. */
+/** The slow steps of an install, as ids; the desktop catalog card words them in its own language. */
export type InstallPhase = 'downloading' | 'python_packages' | 'loading_tools'
/** The non-secret Advanced choices the user approved on a catalog row; a Try again after the operation settled repeats them. */
export interface CatalogApproved {
diff --git a/apps/shared/src/gateway-contract.openrpc.json b/apps/shared/src/gateway-contract.openrpc.json
index dbd6379bef8..e658afe5bbb 100644
--- a/apps/shared/src/gateway-contract.openrpc.json
+++ b/apps/shared/src/gateway-contract.openrpc.json
@@ -16816,7 +16816,7 @@
"type": "object"
},
"InstallPhase": {
- "description": "The slow steps of an install, as ids; the desktop catalog card words them in its own language.\nThe wire contract imports this enum.",
+ "description": "The slow steps of an install, as ids; the desktop catalog card words them in its own language.",
"enum": [
"downloading",
"python_packages",
diff --git a/hermes_cli/plugin_install_phase.py b/hermes_cli/plugin_install_phase.py
new file mode 100644
index 00000000000..5a76eb20b77
--- /dev/null
+++ b/hermes_cli/plugin_install_phase.py
@@ -0,0 +1,12 @@
+"""The slow steps of a plugin install, as ids. A leaf module (stdlib only) so the gateway wire contract
+(``tui_gateway/contracts/connectors_operation.py``) can type them without importing the installer."""
+
+from enum import StrEnum
+
+
+class InstallPhase(StrEnum):
+ """The slow steps of an install, as ids; the desktop catalog card words them in its own language."""
+
+ downloading = "downloading"
+ python_packages = "python_packages"
+ loading_tools = "loading_tools"
diff --git a/hermes_cli/plugins_cmd.py b/hermes_cli/plugins_cmd.py
index 1e6bb076a1f..ba3950ae51a 100644
--- a/hermes_cli/plugins_cmd.py
+++ b/hermes_cli/plugins_cmd.py
@@ -11,11 +11,10 @@ import logging
import os
import shutil
import sys
-import threading
from pathlib import Path
from typing import Any, NoReturn, Optional
-from hermes_constants import get_hermes_home, hermes_home_key
+from hermes_constants import get_hermes_home
from hermes_cli.config import cfg_get
from hermes_cli.plugin_capabilities import _child_dict
# Tests patch these two on the facade; the install/remove siblings read them through it.
@@ -602,32 +601,19 @@ def _forget_plugin_config(aliases: set) -> dict[str, Any]:
return result
-# One lock per Hermes home. The Desktop install card enables several plugins at once, each on its own
-# thread; without it every thread read the same config version and all but the first commit were
-# refused as stale. The version check in PM stays: it still catches an edit from another process.
-_SELECTION_LOCKS: dict[str, threading.Lock] = {}
-_SELECTION_LOCKS_GUARD = threading.Lock()
-
-
-def _selection_lock() -> threading.Lock:
- with _SELECTION_LOCKS_GUARD:
- return _SELECTION_LOCKS.setdefault(hermes_home_key(), threading.Lock())
-
-
def _set_plugin_enabled(name: str, *, enable: bool, aliases=(), console=None) -> None:
"""Submit the command's delta with the version of the selection it read."""
from pm.plugins_state import read_home_selection
- with _selection_lock():
- expected_config = _plugin_selection_version()
- config = read_home_selection(get_hermes_home()) or {}
- plugins = config.get("plugins") or {}
- enabled = set(plugins.get("enabled") or ())
- disabled = set(plugins.get("disabled") or ())
- _apply_activation(enabled, disabled, name, aliases, enable=enable)
- _admit_and_save_plugin_sets(enabled, disabled, console=console,
- action=f"{'Enable' if enable else 'Disable'} '{name}'",
- expected_config=expected_config, plugin=name if enable else None)
+ expected_config = _plugin_selection_version()
+ config = read_home_selection(get_hermes_home()) or {}
+ plugins = config.get("plugins") or {}
+ enabled = set(plugins.get("enabled") or ())
+ disabled = set(plugins.get("disabled") or ())
+ _apply_activation(enabled, disabled, name, aliases, enable=enable)
+ _admit_and_save_plugin_sets(enabled, disabled, console=console,
+ action=f"{'Enable' if enable else 'Disable'} '{name}'",
+ expected_config=expected_config, plugin=name if enable else None)
def _apply_activation(enabled: set, disabled: set, key: str, aliases, *, enable: bool) -> None:
diff --git a/hermes_cli/plugins_cmd_install.py b/hermes_cli/plugins_cmd_install.py
index b3b529b32d9..0273926884e 100644
--- a/hermes_cli/plugins_cmd_install.py
+++ b/hermes_cli/plugins_cmd_install.py
@@ -11,13 +11,15 @@ import logging
import os
import sys
import tempfile
+import threading
from contextlib import contextmanager
from contextvars import ContextVar
-from enum import StrEnum
from pathlib import Path
from typing import Any, Callable, Optional
from hermes_cli.cli_output import line_input
+from hermes_cli.plugin_install_phase import InstallPhase
+from hermes_constants import hermes_home_key
logger = logging.getLogger(__name__)
@@ -710,15 +712,6 @@ def _select_memory_provider(name: str, console, *, select: bool) -> None:
f"Run `hermes memory setup {name}` to configure it; new sessions use it.")
-class InstallPhase(StrEnum):
- """The slow steps of an install, as ids; the desktop catalog card words them in its own language.
- The wire contract imports this enum."""
-
- downloading = "downloading"
- python_packages = "python_packages"
- loading_tools = "loading_tools"
-
-
def _catalog_install_on_disk(catalog_name: str, ref: Optional[str]) -> Optional[tuple]:
"""``(target, manifest, installed_name)`` of the installed, not enabled tree whose install record
names catalog entry *catalog_name*, else None. A refused enable leaves the published clone in
@@ -726,13 +719,14 @@ def _catalog_install_on_disk(catalog_name: str, ref: Optional[str]) -> Optional[
"already exists" on a second clone and the plugin could never be turned on from the card.
Like ``hermes plugins enable``, the tree is used at the commit it has; an explicit *ref* only
matches a tree checked out at that commit."""
+ from hermes_cli.plugins_cmd_catalog import catalog_install_record
enabled = _pc()._get_enabled_set()
- for key, record in _pc()._read_install_metadata().items():
- block = record.get("catalog") if isinstance(record, dict) else None
+ for key in _pc()._read_install_metadata():
target = _pc()._plugins_dir() / key
- if not (isinstance(block, dict) and block.get("name") == catalog_name and target.is_dir()):
+ record = catalog_install_record(target) if target.is_dir() else None
+ if not record or record["catalog_name"] != catalog_name:
continue
- if ref and str(block.get("sha") or "").lower() != ref.lower():
+ if ref and str(record["sha"]).lower() != ref.lower():
return None
manifest = _pc()._read_manifest(target)
installed_name = manifest.get("name") or target.name
@@ -801,6 +795,18 @@ def _place_tree(entry, identifier: str, *, force: bool, ref: Optional[str], assu
return {"ok": False, "error": str(exc)}
+# One lock per Hermes home. The Desktop install card enables several plugins at once, each on its own
+# thread; without it every thread read the same config version and all but the first commit were
+# refused as stale. The version check in PM stays: it still catches an edit from another process.
+_ENABLE_LOCKS: dict[str, threading.Lock] = {}
+_ENABLE_LOCKS_GUARD = threading.Lock()
+
+
+def _enable_lock() -> threading.Lock:
+ with _ENABLE_LOCKS_GUARD:
+ return _ENABLE_LOCKS.setdefault(hermes_home_key(), threading.Lock())
+
+
def _enable_placed(installed_name: str, deps, step: Callable[[InstallPhase], None]) -> Optional[dict]:
"""None once enabled, else the refusal result. Enabling admits the plugin, and admission resolves
its Python dependencies."""
@@ -809,7 +815,8 @@ def _enable_placed(installed_name: str, deps, step: Callable[[InstallPhase], Non
if deps:
step(InstallPhase.python_packages)
try:
- _pc()._set_plugin_enabled(installed_name, enable=True)
+ with _enable_lock():
+ _pc()._set_plugin_enabled(installed_name, enable=True)
except AdmissionRefused as exc:
return {"ok": False, "error": f"enable refused: {exc}", "plugin_name": installed_name, "enabled": False}
return None
diff --git a/hermes_cli/profiles.py b/hermes_cli/profiles.py
index 77ebe934e4e..5f33582f295 100644
--- a/hermes_cli/profiles.py
+++ b/hermes_cli/profiles.py
@@ -92,7 +92,7 @@ _CLONE_ALL_HISTORY_EXCLUDE_ROOT: frozenset[str] = frozenset({
# dashboard) skip bundled-skill seeding. Delete the file to opt back in.
NO_BUNDLED_SKILLS_MARKER = ".no-bundled-skills"
-# ``profile.yaml`` ``role`` values. A role grants backend capabilities (the setup toolset), so
+# ``profile.yaml`` ``role`` values. A role marks a backend-created profile (setup) and grants no toolset;
# only the backend writes one, and a copy of a profile (clone-all, import) never inherits it.
SETUP_ROLE = "setup"
PROFILE_ROLES = frozenset({SETUP_ROLE})
diff --git a/tests/tools/test_connectors_catalog.py b/tests/tools/test_connectors_catalog.py
index 631f9ef3c10..bcdb088feba 100644
--- a/tests/tools/test_connectors_catalog.py
+++ b/tests/tools/test_connectors_catalog.py
@@ -119,6 +119,33 @@ def test_only_a_desktop_session_carries_the_tool():
assert is_deferrable_tool_name("manage_catalog", frozenset(DEFAULT_CONFIG["tools"]["tool_search"]["defer"]))
+def _desktop_child_toolsets():
+ from tools.delegate_tool_toolsets import _resolve_child_toolsets
+ parent = SimpleNamespace(enabled_toolsets=["catalog", "web"], disabled_toolsets=None)
+ return _resolve_child_toolsets(parent, None, "leaf")
+
+
[email protected]("platform", ["desktop", "cli", "subagent"])
+def test_a_session_off_the_desktop_never_hears_of_the_tool_even_through_tool_search(monkeypatch, platform):
+ """A CLI config naming ``catalog``, and a delegate child of a desktop chat, lose manage_catalog from
+ the direct tools, the tool_search listing and the bridge's search, not just from the direct tools."""
+ import model_tools
+ from agent.agent_init import _load_tools
+
+ monkeypatch.setattr("hermes_cli.plugins.discover_plugins", lambda: None)
+ enabled, disabled = _desktop_child_toolsets() if platform == "subagent" else (["catalog", "web"], None)
+ assert "catalog" in enabled
+ agent = SimpleNamespace(quiet_mode=True, platform=platform, enabled_toolsets=enabled, disabled_toolsets=disabled)
+
+ _load_tools(agent, enabled, disabled)
+ found = json.loads(model_tools.handle_function_call(
+ "tool_search", {"queries": ["catalog plugin install"]},
+ enabled_toolsets=agent.enabled_toolsets, disabled_toolsets=agent.disabled_toolsets))
+
+ carried = "manage_catalog" in json.dumps(agent.tools) or "manage_catalog" in json.dumps(found)
+ assert carried is (platform == "desktop")
+
+
@pytest.mark.parametrize("args", [
{"action": "install", "items": [{"kind": "plugin", "id": "x"}], "profile": "work"},
{"action": "install", "items": [{"kind": "plugin", "id": "x", "sha": "b" * 40}]},
diff --git a/tools/connectors/catalog.py b/tools/connectors/catalog.py
index cfb416c4a7d..2a3be0c9f9e 100644
--- a/tools/connectors/catalog.py
+++ b/tools/connectors/catalog.py
@@ -20,16 +20,14 @@ import re
import threading
from dataclasses import dataclass, field
from pathlib import Path
-from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional
+from typing import Any, Callable, Dict, List, Optional
+from hermes_cli.plugin_install_phase import InstallPhase
from hermes_constants import get_hermes_home, profile_name_for_home
from tools.connectors.contract import Actor, SettleReason, TargetState
from tools.connectors.mcp import _fail, _move
from tools.connectors.operation import ConnectionOperation, IllegalTransition, Target
-if TYPE_CHECKING:
- from hermes_cli.plugins_cmd_install import InstallPhase
-
logger = logging.getLogger(__name__)
# The Advanced modal's own keys (CATALOG-ROW-CONTRACT.md); every other answer key is a credential.
@@ -262,8 +260,6 @@ class _Runner:
def _install(self, target: Target, env: Dict[str, str], options: Dict[str, Any],
step: Callable[[InstallPhase], None]) -> Dict[str, Any]:
- from hermes_cli.plugins_cmd_install import InstallPhase
-
named = (env.get("target_profile") or "").strip()
with target_scope(_named_home(named) if named else self.home):
_save_credentials({k: v for k, v in env.items() if k not in _OPTION_KEYS and v})
@@ -299,8 +295,9 @@ class _Runner:
from agent.redact import redact_sensitive_text
text = str(exc) or exc.__class__.__name__
- for value in self.approved_env.get(target.name, {}).values():
- if value and len(value) > 3:
+ # Only credentials are secret: the Advanced choices (a profile name, a commit) stay readable.
+ for key, value in self.approved_env.get(target.name, {}).items():
+ if key not in _OPTION_KEYS and value and len(value) > 3:
text = text.replace(value, "[REDACTED]")
return redact_sensitive_text(text, force=True) or "error"
diff --git a/tools/mcp_tool_agent.py b/tools/mcp_tool_agent.py
index 6d7bb8960d0..1d9f5817e23 100644
--- a/tools/mcp_tool_agent.py
+++ b/tools/mcp_tool_agent.py
@@ -37,7 +37,9 @@ def _resolve_refresh_toolsets(agent, enabled_override, disabled_override):
disabled = getattr(agent, "disabled_toolsets", None)
if enabled_override is not None or disabled_override is not None:
enabled = enabled_override if enabled_override is not None else enabled
- disabled = disabled_override if disabled_override is not None else disabled
+ if disabled_override is not None:
+ from toolsets import session_disabled_toolsets
+ disabled = session_disabled_toolsets(disabled_override, getattr(agent, "platform", None))
agent.enabled_toolsets, agent.disabled_toolsets = enabled, disabled
return enabled, disabled
diff --git a/toolsets.py b/toolsets.py
index 2dcbe18d362..4af6106020e 100644
--- a/toolsets.py
+++ b/toolsets.py
@@ -458,6 +458,15 @@ def session_platform_tool_drops(platform: Optional[str]) -> frozenset:
for tool in resolve_toolset(name))
+def session_disabled_toolsets(disabled: Optional[List[str]], platform: Optional[str]) -> Optional[List[str]]:
+ """*disabled* plus every platform-gated toolset a session on *platform* does not get. An agent stores
+ this as its ``disabled_toolsets``, so the tool list, the tool_search listing and bridge, MCP refreshes
+ and delegate children (which inherit it) all subtract the gated tools in ``_select_tool_names``."""
+ gated = [name for name, platforms in TOOLSET_SESSION_PLATFORMS.items()
+ if platform not in platforms and name not in (disabled or ())]
+ return [*(disabled or ()), *gated] if gated else disabled
+
+
def agent_tool_drops(agent: Any) -> frozenset:
"""Tool names *agent* never carries, whatever its toolsets resolved to: the side-agent drops and
the toolsets its session platform does not get. Applied at load, MCP refresh and prefix restore."""
diff --git a/tui_gateway/contracts/connectors_operation.py b/tui_gateway/contracts/connectors_operation.py
index e0c76f94b18..eb526dfd4bb 100644
--- a/tui_gateway/contracts/connectors_operation.py
+++ b/tui_gateway/contracts/connectors_operation.py
@@ -13,7 +13,7 @@ from typing import Literal
from pydantic import Field
-from hermes_cli.plugins_cmd_install import InstallPhase
+from hermes_cli.plugin_install_phase import InstallPhase
from .base import Params, Payload, Result, WireEnum
from .common import ConnectorOwner, ProfileParams