Skip to content

The agent that grows with you

fix(plugins): re-enabling a plugin restores its toolset in a saved platform_toolsets list

teknium105df0382a5db
diff --git a/hermes_cli/plugins_cmd.py b/hermes_cli/plugins_cmd.py
index b63a887f4e9..75a4f500f50 100644
--- a/hermes_cli/plugins_cmd.py
+++ b/hermes_cli/plugins_cmd.py
@@ -717,16 +717,21 @@ def cmd_enable(name: str, allow_tool_override: Optional[bool] = None) -> None:
except PluginOperationError as exc:
_fail(console, f"[red]Error:[/red] {exc}")
- if _activate_key(key, enable=True, console=console):
+ changed = _activate_key(key, enable=True, console=console)
+ if changed:
from hermes_cli.plugins_activation import activate_plugin_now, activation_hint
console.print(f"[green]✓[/green] Plugin [bold]{key}[/bold] enabled. Takes effect on next session.")
console.print(f"[dim]{activation_hint(activate_plugin_now(key, in_process=False))}[/dim]")
else:
console.print(f"[dim]Plugin '{key}' is already enabled.[/dim]")
+ if source != "bundled":
+ _enable_consent(console, key, allow_tool_override)
+ if changed: # after consent: register() sees the grants; same saved-list edit as the Desktop toggle
+ _toggle_plugin_toolset(key, enable=True)
- # Built-in tool override is a privileged grant; bundled plugins are trusted.
- if source == "bundled":
- return
+
+def _enable_consent(console, key: str, allow_tool_override: Optional[bool]) -> None:
+ """Capability consent and the legacy tool-override grant for a non-bundled plugin's enable."""
# When the manifest declares capabilities the consent screen is the canonical grant path
# (it covers tools.override too); the legacy prompt then only runs on an explicit flag.
# See #64228.
@@ -745,9 +750,11 @@ def cmd_disable(name: str) -> None:
key = _resolve_plugin_key(name)
if key is None:
_fail(console, _unknown_plugin_message(name))
+ toolset_key = _saved_list_toolset_key(key) # resolve while the plugin still loads
if not _activate_key(key, enable=False, console=console):
console.print(f"[dim]Plugin '{key}' is already disabled.[/dim]")
return
+ _toggle_plugin_toolset(key, enable=False, toolset_key=toolset_key)
console.print(
f"[yellow]\u2298[/yellow] Plugin [bold]{key}[/bold] disabled. Takes effect on next session.")
@@ -939,12 +946,24 @@ def _get_plugin_toolset_key(name: str) -> Optional[str]:
return None
-def _toggle_plugin_toolset(name: str, *, enable: bool) -> None:
+def _saved_list_toolset_key(name: str) -> Optional[str]:
+ """The plugin's toolset key, or None without loading any plugin when no platform has a SAVED
+ ``platform_toolsets`` list (the only lists :func:`_toggle_plugin_toolset` edits)."""
+ from hermes_cli.config import load_config
+ from hermes_cli.toolset_validation import parse_platform_toolsets_value
+ saved = load_config().get("platform_toolsets")
+ if not isinstance(saved, dict) or all(parse_platform_toolsets_value(v) is None for v in saved.values()):
+ return None
+ return _get_plugin_toolset_key(name)
+
+
+def _toggle_plugin_toolset(name: str, *, enable: bool, toolset_key: Optional[str] = None) -> None:
"""Add/remove a plugin's toolset in every SAVED ``platform_toolsets`` list (no-op when the plugin
provides no tools). Platforms with no saved list are left alone: a plugin toolset is already on
there by default, and seeding ``[<plugin_ts>]`` would replace the core composite and strip every
- built-in tool."""
- toolset_key = _get_plugin_toolset_key(name)
+ built-in tool. The key resolves only while the plugin is loaded, so enable calls this after the
+ plugin loads and disable resolves *toolset_key* before the disable is written."""
+ toolset_key = toolset_key or _saved_list_toolset_key(name)
if not toolset_key:
return
from hermes_cli.config import load_config, save_config
@@ -974,6 +993,7 @@ def dashboard_set_agent_plugin_enabled(name: str, *, enabled: bool) -> dict[str,
return {"ok": False, "error": f"Plugin '{name}' is not installed or bundled."}
from hermes_cli.plugins_admission import AdmissionRefused
+ toolset_key = None if enabled else _saved_list_toolset_key(key)
try:
changed = _activate_key(key, enable=enabled)
except AdmissionRefused as exc:
@@ -984,13 +1004,17 @@ def dashboard_set_agent_plugin_enabled(name: str, *, enabled: bool) -> dict[str,
"unchanged": True,
"restart_required": False,
}
- if changed:
- _toggle_plugin_toolset(key, enable=enabled)
if changed and enabled:
# Load it now, here and in the running gateway; ``activation`` tells the UI what is live vs
# deferred, and ``restart_required`` only survives when no gateway answered (#87770).
from hermes_cli.plugins_activation import activate_plugin_now
- return {"ok": True, "name": key, "unchanged": False, **activate_plugin_now(key)}
+ result = {"ok": True, "name": key, "unchanged": False, **activate_plugin_now(key)}
+ # Only now is the plugin loaded here, so its toolset key resolves: a backend that scanned
+ # while the plugin was off held a placeholder and the toolset was never re-added.
+ _toggle_plugin_toolset(key, enable=True)
+ return result
+ if changed:
+ _toggle_plugin_toolset(key, enable=False, toolset_key=toolset_key)
# Disable is config-only: there is no un-wire primitive, so a running gateway keeps the plugin's
# handlers until restart and every UI says so — #71595/#54941.
return {"ok": True, "name": key, "unchanged": not changed, "restart_required": changed}
diff --git a/tests/hermes_cli/test_plugins_cmd_activation_keys.py b/tests/hermes_cli/test_plugins_cmd_activation_keys.py
index c57d31c0133..fde00c1af12 100644
--- a/tests/hermes_cli/test_plugins_cmd_activation_keys.py
+++ b/tests/hermes_cli/test_plugins_cmd_activation_keys.py
@@ -113,6 +113,67 @@ def test_dashboard_enable_on_a_fresh_config_keeps_the_core_tools(home):
registry.deregister("zzseed_tool")
+def _restart_backend():
+ """A new process: no plugin manager has scanned yet and no plugin tool is registered."""
+ from hermes_cli.plugins import _reset_plugin_managers_for_tests
+ from tools.registry import registry
+
+ _reset_plugin_managers_for_tests()
+ registry.deregister("zzre_tool")
+
+
+def _saved_cli_list():
+ return load_config()["platform_toolsets"]["cli"]
+
+
+def saved_list_plugin(home):
+ """An enabled tool plugin on a config whose tool picker was saved (explicit ``platform_toolsets``)."""
+ _write_tool_plugin(home / "plugins", "zzre")
+ cfg = load_config()
+ cfg["plugins"]["enabled"] = ["zzre"]
+ cfg["platform_toolsets"] = {"cli": ["hermes-cli", "zzre_ts"]}
+ save_config(cfg)
+ yield
+ _restart_backend()
+
+
+def test_dashboard_reenable_restores_the_toolset_in_a_saved_list(saved_list_plugin):
+ """Desktop/TUI/dashboard disable drops the plugin toolset from a saved list; re-enabling from a
+ backend that scanned while the plugin was off must add it back. The toggle ran before the plugin
+ loaded, found no registered tool, and left the plugin enabled with its tools off."""
+ from hermes_cli.plugins import discover_plugins
+
+ discover_plugins() # long-lived backend: scanned while the plugin was on
+ assert plugins_cmd.dashboard_set_agent_plugin_enabled("zzre", enabled=False)["ok"] is True
+ assert _saved_cli_list() == ["hermes-cli"]
+
+ _restart_backend()
+ discover_plugins() # the backend now holds only a placeholder for the disabled plugin
+ assert plugins_cmd.dashboard_set_agent_plugin_enabled("zzre", enabled=True)["ok"] is True
+ assert _saved_cli_list() == ["hermes-cli", "zzre_ts"]
+
+
+def test_cli_disable_and_enable_round_trip_the_toolset_in_a_saved_list(saved_list_plugin):
+ """``hermes plugins disable`` / ``enable`` edit a saved list the same way the dashboard does, each
+ in its own process; they never touched it, so a toolset the dashboard dropped stayed off."""
+ plugins_cmd.cmd_disable("zzre")
+ assert _saved_cli_list() == ["hermes-cli"]
+
+ _restart_backend()
+ plugins_cmd.cmd_enable("zzre")
+ assert _saved_cli_list() == ["hermes-cli", "zzre_ts"]
+
+
+def test_cli_enable_on_a_fresh_config_writes_no_toolset_list(home):
+ """No saved ``platform_toolsets``: enable must not seed one (it would replace the core composite)."""
+ _write_tool_plugin(home / "plugins", "zzre")
+ plugins_cmd.cmd_enable("zzre")
+ plugins_cmd.cmd_disable("zzre")
+ assert not load_config().get("platform_toolsets")
+ _restart_backend()
+
+
def test_status_reports_bundled_defaults_and_the_live_memory_provider(home):
"""Bundled backends (auto-load) and the plugin selected by ``memory.provider`` run without a
``plugins.enabled`` entry; status must not call them "not enabled" (#73131, #82898)."""
diff --git a/website/docs/user-guide/features/plugins.md b/website/docs/user-guide/features/plugins.md
index b413655aa76..2a6818c6fd9 100644
--- a/website/docs/user-guide/features/plugins.md
+++ b/website/docs/user-guide/features/plugins.md
@@ -191,6 +191,11 @@ hermes plugins enable <name> # add to allow-list
hermes plugins disable <name> # remove from allow-list + add to disabled
```
+If you saved a tool selection (`hermes tools`, so `platform_toolsets` lists toolsets explicitly), disabling a
+plugin also takes its toolset out of those saved lists, and enabling it puts the toolset back. The CLI and the
+Desktop/TUI/dashboard switch behave the same. With no saved selection the lists are left alone: a plugin's
+toolset is on by default.
+
After `hermes plugins install owner/repo`, you're asked `Enable 'name' now? [y/N]` — defaults to no. Skip the prompt for scripted installs with `--enable` or `--no-enable`. A memory provider (a plugin whose `__init__.py` registers a `MemoryProvider`) asks `Use 'name' as the memory provider now?` instead: yes (or `--enable`) sets `memory.provider`, which is the only switch that activates a provider; no leaves it for `hermes memory setup`.
For a reproducible install, pin a full immutable commit (tags, branches, and
diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/plugins.md b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/plugins.md
index 6e8922a7dd0..ee6926de3db 100644
--- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/plugins.md
+++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/plugins.md
@@ -164,6 +164,8 @@ hermes plugins enable <name> # 添加到允许列表
hermes plugins disable <name> # 从允许列表移除并添加到禁用列表
```
+如果你保存过工具选择(`hermes tools`,即 `platform_toolsets` 显式列出工具集),禁用插件时也会把它的工具集从这些已保存的列表中移除,启用时再加回去。CLI 与 Desktop/TUI/仪表盘开关的行为一致。没有已保存的选择时不会改动列表:插件的工具集默认开启。
+
执行 `hermes plugins install owner/repo` 后,会询问 `Enable 'name' now? [y/N]` — 默认为否。脚本化安装时可用 `--enable` 或 `--no-enable` 跳过提示。
### 允许列表不控制的内容