The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(plugins): `hermes plugins disable` unloads the plugin from the running gateway
unsupportedpastels2109290ce070
diff --git a/hermes_cli/plugins_activation.py b/hermes_cli/plugins_activation.pyindex 24076d0d928..7c583f44da5 100644--- a/hermes_cli/plugins_activation.py+++ b/hermes_cli/plugins_activation.py@@ -109,22 +109,42 @@ def activate_plugin_now(name: str, *, in_process: bool = True) -> dict[str, Any]activation: Optional[dict[str, Any]] = load_and_go_live(name) if in_process else Noneif not in_process:activation = (notify_serve_backend(name, Path(get_hermes_home())) or {}).get("activation")- answer = None+ answer = reload_running_gateway()+ reloaded = bool(answer and answer.get("reloaded"))+ if reloaded and activation is None:+ activation = find_activation((answer or {}).get("activations"), name)+ return {"gateway_reloaded": reloaded, "activation": activation, "restart_required": not reloaded}+++def reload_running_gateway() -> Optional[dict[str, Any]]:+ """Ask the gateway serving this profile (its own socket, else the multiplexer's for a served+ secondary) to force plugin re-discovery, so an enable loads and a disable unloads for every session+ the gateway starts from now on. The ``reload-plugins`` answer, or None when no gateway answered."""try:from gateway.control_socket import reload_gateway_plugins- from hermes_constants import get_default_hermes_root+ from hermes_constants import get_default_hermes_root, get_hermes_homehome = Path(get_hermes_home())answer = reload_gateway_plugins(home)if answer is None:root = Path(get_default_hermes_root())if root.resolve() != home.resolve(): # a served secondary: the multiplexer's socketanswer = reload_gateway_plugins(root, profile_home=home)+ return answerexcept Exception:- logger.debug("gateway reload-plugins nudge for %r failed", name, exc_info=True)- reloaded = bool(answer and answer.get("reloaded"))- if reloaded and activation is None:- activation = find_activation((answer or {}).get("activations"), name)- return {"gateway_reloaded": reloaded, "activation": activation, "restart_required": not reloaded}+ logger.debug("gateway reload-plugins nudge failed", exc_info=True)+ return None+++def gateway_reload_hint(answer: Optional[dict[str, Any]]) -> str:+ """One honest sentence after a plugin-set change that only the gateway's re-discovery applies."""+ if answer and answer.get("reloaded"):+ return "The running gateway reloaded its plugins; new sessions use this change."+ if answer is not None: # a gateway answered and refused: say so, with its reason+ return (f"The running gateway refused to reload its plugins: {answer.get('error') or 'no reason given'}.\n"+ "Only the saved config changed; restart the gateway serving this profile to apply it:\n"+ " hermes gateway restart")+ return ("No running gateway answered. If one is running, restart it for this to take effect:\n"+ " hermes gateway restart")def load_and_go_live(name: str) -> Optional[dict[str, Any]]:diff --git a/hermes_cli/plugins_cmd.py b/hermes_cli/plugins_cmd.pyindex ad061ca6772..8eb7a66b6ed 100644--- a/hermes_cli/plugins_cmd.py+++ b/hermes_cli/plugins_cmd.py@@ -761,8 +761,9 @@ def cmd_disable(name: str) -> None: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.")+ from hermes_cli.plugins_activation import gateway_reload_hint, reload_running_gateway+ console.print(f"[yellow]⊘[/yellow] Plugin [bold]{key}[/bold] disabled.")+ console.print(f"[dim]{gateway_reload_hint(reload_running_gateway())}[/dim]")def _read_manifest_info(d: Path, prefix: str):diff --git a/tests/hermes_cli/test_plugins_disable_reaches_gateway.py b/tests/hermes_cli/test_plugins_disable_reaches_gateway.pynew file mode 100644index 00000000000..3e49359800a--- /dev/null+++ b/tests/hermes_cli/test_plugins_disable_reaches_gateway.py@@ -0,0 +1,132 @@+"""``hermes plugins disable`` must reach the running gateway, or say a restart is needed (LC-3).++Under one gateway the daemon holds the plugin manager for every session, so "takes effect on next+session" was false: new sessions kept the disabled plugin's hooks and tools until a restart. The+command now asks the gateway to re-discover (the same ``reload-plugins`` verb enable uses).+"""++from __future__ import annotations++from pathlib import Path++import pytest++from hermes_cli import plugins_cmd+from hermes_cli.config import load_config, save_config+++def home(tmp_path, monkeypatch):+ hermes_home = tmp_path / "hermes-home"+ plugin_dir = hermes_home / "plugins" / "probe"+ plugin_dir.mkdir(parents=True)+ (plugin_dir / "plugin.yaml").write_text("name: probe\nversion: '1.0'\n", encoding="utf-8")+ (plugin_dir / "__init__.py").write_text("def register(ctx):\n pass\n", encoding="utf-8")+ (hermes_home / "config.yaml").write_text("plugins:\n enabled: [probe]\n disabled: []\n", encoding="utf-8")+ monkeypatch.setenv("HERMES_HOME", str(hermes_home))++ def admit(enabled, disabled, **_kwargs):+ cfg = load_config()+ cfg["plugins"] = {"enabled": sorted(enabled), "disabled": sorted(disabled)}+ save_config(cfg)++ monkeypatch.setattr("hermes_cli.plugins_admission.admit_plugin_set_change", admit)+ return hermes_home+++def _gateway(monkeypatch, answer, *, shared=None):+ """``answer`` from the profile's own socket; ``shared`` (when given) from the multiplexer's."""+ calls: list[tuple[Path, object]] = []++ def reload_gateway_plugins(target, *, profile_home=None, timeout=30.0):+ calls.append((Path(target), profile_home))+ return answer if profile_home is None else shared++ monkeypatch.setattr("gateway.control_socket.reload_gateway_plugins", reload_gateway_plugins)+ return calls+++def test_disable_unloads_the_plugin_from_the_running_gateway(home, monkeypatch, capsys):+ calls = _gateway(monkeypatch, {"reloaded": True, "plugins": []})++ plugins_cmd.cmd_disable("probe")++ out = capsys.readouterr().out+ assert calls and calls[0][0].resolve() == home.resolve()+ assert "next session" not in out+ assert "running gateway reloaded" in out+++def test_the_gateways_forced_rediscovery_drops_a_disabled_plugins_hook(home):+ """What the ``reload-plugins`` verb runs: the reloaded manager no longer offers the plugin's hook."""+ from hermes_cli import plugins++ (home / "plugins" / "probe" / "__init__.py").write_text(+ "def _probe_hook(**kwargs):\n return None\n\n"+ "def register(ctx):\n ctx.register_hook('on_session_start', _probe_hook)\n", encoding="utf-8")++ def _probe_hooked() -> bool:+ return any(cb.__name__ == "_probe_hook" for cb in plugins.iter_hook_callbacks("on_session_start"))++ plugins._reset_plugin_managers_for_tests()+ try:+ plugins.discover_plugins(force=True)+ assert _probe_hooked()+ cfg = load_config()+ cfg["plugins"] = {"enabled": [], "disabled": ["probe"]}+ save_config(cfg)+ plugins.discover_plugins(force=True)+ assert not _probe_hooked()+ finally:+ plugins._reset_plugin_managers_for_tests()+++_UNSERVED = {"reloaded": False, "error": "home is not served by this gateway"}+++def test_an_explicit_refusal_is_reported_not_called_silence(home, monkeypatch, capsys):+ _gateway(monkeypatch, _UNSERVED)++ plugins_cmd.cmd_disable("probe")++ out = " ".join(capsys.readouterr().out.split())+ assert "refused" in out and "home is not served by this gateway" in out+ assert "saved config" in out and "No running gateway answered" not in out+++def shared_root(tmp_path, monkeypatch):+ root = tmp_path / "shared-root"+ root.mkdir()+ monkeypatch.setattr("hermes_constants.get_default_hermes_root", lambda: root)+ return root+++def test_a_profile_without_its_own_gateway_reaches_the_shared_one(home, shared_root, monkeypatch, capsys):+ calls = _gateway(monkeypatch, None, shared={"reloaded": True, "plugins": []})++ plugins_cmd.cmd_disable("probe")++ assert [(t.resolve(), p and Path(str(p)).resolve()) for t, p in calls] == [+ (home.resolve(), None), (shared_root.resolve(), home.resolve())]+ assert "running gateway reloaded" in capsys.readouterr().out+++def test_a_shared_gateway_refusing_an_unserved_home_is_reported(home, shared_root, monkeypatch, capsys):+ calls = _gateway(monkeypatch, None, shared=_UNSERVED)++ plugins_cmd.cmd_disable("probe")++ out = " ".join(capsys.readouterr().out.split())+ assert len(calls) == 2 and "home is not served by this gateway" in out+ assert "saved config" in out and "No running gateway answered" not in out+++def test_disable_without_an_answering_gateway_says_a_restart_is_needed(home, monkeypatch, capsys):+ _gateway(monkeypatch, None)++ plugins_cmd.cmd_disable("probe")++ out = capsys.readouterr().out+ assert "next session" not in out+ assert "hermes gateway restart" in out