The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(plugins): no "restart the gateway" after an install when no gateway exists; brief install for setup
Teknium71d00c30cd0a
diff --git a/hermes_cli/plugins_activation.py b/hermes_cli/plugins_activation.pyindex 7cbc1d5483f..80639ed26be 100644--- a/hermes_cli/plugins_activation.py+++ b/hermes_cli/plugins_activation.py@@ -230,8 +230,27 @@ def notify_serve_backend(name: str, home: Path) -> Optional[dict[str, Any]]:return None+def _gateway_present() -> bool:+ """A gateway runs for this profile (its own, or the multiplexer serving it from the root), or a+ gateway service is installed for it."""+ from gateway.status import get_running_pid+ from hermes_cli.gateway import _installed_service_kind+ from hermes_constants import get_default_hermes_root, get_hermes_home+ homes = {Path(get_hermes_home()).resolve(), Path(get_default_hermes_root()).resolve()}+ return (any(get_running_pid(home / "gateway.pid", cleanup_stale=False) for home in homes)+ or _installed_service_kind() is not None)+++def report_activation(console, name: str) -> None:+ """After a CLI install/enable: load *name* where it can go live now (:func:`activate_plugin_now`)+ and print :func:`activation_hint`, or nothing when there is nothing to say."""+ if hint := activation_hint(activate_plugin_now(name, in_process=False)):+ console.print(f"[dim]{hint}[/dim]")++def activation_hint(result: dict[str, Any]) -> str:- """One honest sentence for CLI surfaces from an :func:`activate_plugin_now` result."""+ """One honest sentence for CLI surfaces from an :func:`activate_plugin_now` result; empty when+ there is nothing to say."""act = result.get("activation") or {}live = act.get("live_now") or {}connected = [s for s in live.get("mcp_servers") or () if s.get("connected")]@@ -242,7 +261,9 @@ def activation_hint(result: dict[str, Any]) -> str:lines.extend(f"MCP server {s['name']} not connected: {s.get('error') or 'unknown error'}"for s in live.get("mcp_servers") or () if not s.get("connected"))if not result.get("gateway_reloaded"):- if lines: # live in open chats; a messaging gateway that starts later loads it at boot+ # Live in open chats, or no gateway runs or is installed for this profile (first-time setup):+ # a messaging gateway that starts later loads it at boot, so a restart applies to nothing.+ if lines or not _gateway_present():return "\n".join(lines)return "\n".join([*lines, "Restart the gateway for the plugin to take effect:\n hermes gateway restart"])now, deferred = act.get("activated_now") or {}, act.get("deferred") or {}diff --git a/hermes_cli/plugins_cmd.py b/hermes_cli/plugins_cmd.pyindex 8052f8108ed..d8c35332528 100644--- a/hermes_cli/plugins_cmd.py+++ b/hermes_cli/plugins_cmd.py@@ -725,9 +725,9 @@ def cmd_enable(name: str, allow_tool_override: Optional[bool] = None) -> None:changed = _activate_key(key, enable=True, console=console)if changed:- from hermes_cli.plugins_activation import activate_plugin_now, activation_hint+ from hermes_cli.plugins_activation import report_activationconsole.print(f"[green]✓[/green] Plugin [bold]{key}[/bold] enabled.") # the hint says when it applies- console.print(f"[dim]{activation_hint(activate_plugin_now(key, in_process=False))}[/dim]")+ report_activation(console, key)else:console.print(f"[dim]Plugin '{key}' is already enabled.[/dim]")if source != "bundled":diff --git a/hermes_cli/plugins_cmd_install.py b/hermes_cli/plugins_cmd_install.pyindex 5c0423a5ade..ded3fef3d44 100644--- a/hermes_cli/plugins_cmd_install.py+++ b/hermes_cli/plugins_cmd_install.py@@ -204,12 +204,14 @@ def _prompt_plugin_env_vars(manifest: dict, console) -> None:console.print()-def _display_after_install(plugin_dir: Path, identifier: str) -> None:- """Show after-install.md if it exists, otherwise a default message."""+def _display_after_install(plugin_dir: Path, identifier: str, *, brief: bool = False) -> None:+ """Show after-install.md if it exists, otherwise a default message (skipped when *brief*)."""from rich.markdown import Markdownfrom rich.panel import Panelconsole = _pc()._console()after_install = plugin_dir / "after-install.md"+ if brief and not after_install.exists():+ returnif after_install.exists():body, title = Markdown(after_install.read_text(encoding="utf-8-sig")), Noneelse:@@ -557,6 +559,20 @@ def recorded_install(install: Callable[[], tuple], *, catalog_name: Optional[strreturn result+def _announce_source(identifier: str, console, *, brief: bool) -> tuple[Optional[Any], str]:+ """``(catalog entry or None, install identifier)``, printing where the install comes from: the+ catalog pin (plus the entry's description unless *brief*) or the custom-source warning."""+ from hermes_cli import plugins_cmd_catalog as catalog+ if not catalog.looks_like_catalog_name(identifier):+ console.print("[yellow]Warning:[/yellow] custom (unreviewed) source — not from the Hermes catalog.")+ return None, identifier+ entry = catalog.resolve_catalog_name(identifier, console)+ console.print(f"[bold]{entry.name}[/bold] [cyan]\\[{entry.tier}][/cyan] [dim]pinned @ {entry.sha[:8]}[/dim]")+ if not brief:+ console.print(catalog.entry_capability_summary(entry))+ return entry, entry.install_identifier++def cmd_install(identifier: str,force: bool = False,@@ -565,6 +581,7 @@ def cmd_install(allow_removed: bool = False,no_deps: bool = False,yes_deps: bool = False,+ brief: bool = False,) -> None:"""Install a plugin from the curated catalog (bare name), a Git URL, or owner/repo shorthand.@@ -577,17 +594,13 @@ def cmd_install(finish in one run instead of being refused and left for an ``enable`` thatcannot recover a refused publication (#122134). The default without it staysfail-closed in non-interactive sessions.+ *brief* is for a caller that already told the user what is being installed and why (first-time+ setup): the catalog line, questions, warnings, errors and the outcome print, the catalog+ description, clone line and default "Installed" panel do not."""from hermes_cli import plugins_cmd_catalog as catalogconsole = _pc()._console()- entry = None- if catalog.looks_like_catalog_name(identifier):- entry = catalog.resolve_catalog_name(identifier, console)- identifier = entry.install_identifier- console.print(f"[bold]{entry.name}[/bold] [cyan]\\[{entry.tier}][/cyan] [dim]pinned @ {entry.sha[:8]}[/dim]")- console.print(catalog.entry_capability_summary(entry))- else:- console.print("[yellow]Warning:[/yellow] custom (unreviewed) source — not from the Hermes catalog.")+ entry, identifier = _announce_source(identifier, console, brief=brief)if allow_removed:console.print("[bold red]WARNING:[/bold red] [red]--allow-removed set — skipping the catalog kill-list check. "@@ -604,7 +617,8 @@ def cmd_install("[yellow]Warning:[/yellow] Using insecure/local URL scheme. ""Consider using https:// or git@ for production installs.")- console.print(f"[dim]Cloning {git_url}{f' (subdir: {_subdir})' if _subdir else ''}...[/dim]")+ if not brief:+ console.print(f"[dim]Cloning {git_url}{f' (subdir: {_subdir})' if _subdir else ''}...[/dim]")_interactive_scan_decision = interactive_scan_decision(console, "Install")def _install() -> tuple:@@ -649,7 +663,7 @@ def cmd_install(deps_ok, deps_reason = _install_plugin_python_deps(installed_manifest, target, console,assume_yes=yes_deps)- _pc()._display_after_install(target, identifier)+ _pc()._display_after_install(target, identifier, brief=brief)# ONE admission transaction for the enable (C13): resolve the candidate# union (enabled members + this target) and commit the config in the@@ -702,8 +716,8 @@ def cmd_install(_pc()._run_capability_consent(console, installed_name, declared_caps, context="install")if enable and not is_memory_provider:# Loads it into the running gateway now (handlers live) or says what needs a restart (#87770).- from hermes_cli.plugins_activation import activate_plugin_now, activation_hint- console.print(f"[dim]{activation_hint(activate_plugin_now(installed_name, in_process=False))}[/dim]")+ from hermes_cli.plugins_activation import report_activation+ report_activation(console, installed_name)console.print()diff --git a/tests/hermes_cli/test_plugin_worker_lifecycle.py b/tests/hermes_cli/test_plugin_worker_lifecycle.pyindex 12bfff2d00f..89b930467d8 100644--- a/tests/hermes_cli/test_plugin_worker_lifecycle.py+++ b/tests/hermes_cli/test_plugin_worker_lifecycle.py@@ -111,7 +111,7 @@ def test_active_reinstall_does_not_overwrite_a_later_disable(plugin_world, monkesecond = version(origin, pin="2.0")watched = [world.home / "config.yaml", paths.runtime_facts_path()]acknowledged = {}- def disable_after_publication(*args):+ def disable_after_publication(*args, **kwargs):world.command("disable", name="plugin-worker-proof")acknowledged.update({path: path.read_bytes() for path in watched})monkeypatch.setattr(plugins_cmd, "_display_after_install", disable_after_publication)diff --git a/tests/hermes_cli/test_plugins_cmd_catalog.py b/tests/hermes_cli/test_plugins_cmd_catalog.pyindex 018d46555d9..7cf9882bd9e 100644--- a/tests/hermes_cli/test_plugins_cmd_catalog.py+++ b/tests/hermes_cli/test_plugins_cmd_catalog.py@@ -538,3 +538,24 @@ def test_catalog_rows_maps_resolves_the_live_catalog_once(monkeypatch):monkeypatch.setattr(cat, "load_catalog_live", boom)assert cat.catalog_rows_maps() == ({}, {}, {})++[email protected]("gateway_pid", [None, 4242], ids=["no-gateway", "gateway-running"])+def test_brief_install_prints_the_pin_and_outcome_and_a_restart_hint_only_for_a_gateway(+ world, monkeypatch, gateway_pid):+ """First-time setup already said what it installs and why, so ``brief`` leaves out the catalog+ description, the clone line and the "Installed" panel; with no gateway running or installed (a+ first-time setup) there is nothing to restart, so no restart hint either."""+ from rich.panel import Panel+ printed: list = []+ monkeypatch.setattr(pc, "_console", lambda: type("C", (), {"print": lambda self, *a, **k: printed.extend(a)})())+ monkeypatch.setattr("gateway.status.get_running_pid", lambda *a, **k: gateway_pid) # no reload answered+ monkeypatch.setattr("hermes_cli.gateway._installed_service_kind", lambda: None)++ pc.cmd_install("cat-plugin", enable=True, brief=True)++ text = "\n".join(str(p) for p in printed if not isinstance(p, Panel))+ assert "pinned @" in text and "Plugin [bold]cat-plugin[/bold] enabled" in text+ assert not any(isinstance(p, Panel) for p in printed)+ assert "maintained by" not in text and "Cloning" not in text+ assert ("Restart the gateway" in text) is bool(gateway_pid)diff --git a/tests/hermes_cli/test_plugins_disable_reaches_gateway.py b/tests/hermes_cli/test_plugins_disable_reaches_gateway.pyindex cd0d8c9172d..487384bbb99 100644--- a/tests/hermes_cli/test_plugins_disable_reaches_gateway.py+++ b/tests/hermes_cli/test_plugins_disable_reaches_gateway.py@@ -154,6 +154,8 @@ def test_enable_prints_only_the_outcome_that_applies(home, monkeypatch, capsys,outcome = {"gateway_reloaded": reloaded, "restart_required": not reloaded,"activation": {"activated_now": {"hooks": 1}} if reloaded else None}monkeypatch.setattr(plugins_activation, "activate_plugin_now", lambda *_a, **_k: outcome)+ # Not reloaded: a gateway runs but did not answer the reload (an older one), so it needs a restart.+ monkeypatch.setattr("gateway.status.get_running_pid", lambda *_a, **_k: 4242)plugins_cmd.cmd_enable("probe", allow_tool_override=False)