feat(plugins): bundled platform plugins auto-load by default

Platform plugins shipped in-repo under plugins/platforms/ should be
available out of the box — users shouldn't have to add 'irc-platform'
to plugins.enabled before they can pick IRC from the gateway setup menu.

Adds a new ``kind: platform`` plugin type that mirrors the existing
``kind: backend`` auto-load semantics:

- Bundled (shipped in the hermes-agent repo): auto-load unconditionally.
- User-installed (~/.hermes/plugins/): still opt-in via plugins.enabled
  so untrusted code doesn't silently run.

Changes:

* hermes_cli/plugins.py: add 'platform' to _VALID_PLUGIN_KINDS, document
  the new kind in the PluginManifest docstring, extend the bundled auto-
  load rule from 'backend only' to 'backend or platform'.

* plugins/platforms/irc/plugin.yaml: declare kind: platform.

* hermes_cli/gateway.py: remove the now-redundant
  _load_bundled_platform_plugins_for_enumeration() helper and the
  _enable_plugin_for_platform() helper. The setup menu's _all_platforms()
  just calls discover_plugins() and reads the registry — bundled
  platforms are already loaded at that point. Drops the 'needs_enable'
  flag and the 'plugin disabled — select to enable' status string.

* hermes_cli/setup.py: relax the "gateway is configured" detector used
  during OpenClaw migration. Switching to _platform_status() in an
  earlier commit tightened the check to require an exact "configured"
  match, dropping platforms whose status is "enabled, not paired",
  "partially configured", "configured + E2EE", etc. Now any non-"not
  configured" status counts — the user has already started setup there
  and we shouldn't force the section to rerun.

* tests/hermes_cli/test_setup_irc.py: drop the TestIRCPluginDisabledFlow
  class and test_configure_platform_enables_disabled_plugin_first — the
  no-longer-existent flow they were testing.

* tests/hermes_cli/test_setup_openclaw_migration.py: patch both
  setup.get_env_value and gateway.get_env_value in the 4 gateway-section
  tests that reach _platform_status() through the unified setup flow;
  switch WHATSAPP_ENABLED to the literal "true" in the registry-parity
  test so WhatsApp's value-shape validator matches.

Verified via fresh-install smoke (empty plugins.enabled, no env vars):
IRC plugin loads, Platform('irc') resolves, _all_platforms() lists IRC
with status 'not configured'. 160 targeted tests pass.
This commit is contained in:
Teknium
2026-04-29 21:02:16 -07:00
parent 71c8ca17dc
commit 4d363499db
6 changed files with 53 additions and 190 deletions

View File

@@ -17,7 +17,6 @@ def _register_irc_platform(**overrides):
Tests run outside the normal plugin-discovery path, so we inject the entry
directly into the singleton registry and yield its dict shape.
"""
needs_enable = overrides.pop("needs_enable", False)
defaults = dict(
name="irc",
label="IRC",
@@ -47,7 +46,6 @@ def _register_irc_platform(**overrides):
"token_var": entry.required_env[0] if entry.required_env else "",
"install_hint": entry.install_hint,
"_registry_entry": entry,
"needs_enable": needs_enable,
}
@@ -126,42 +124,6 @@ class TestIRCFreshInstallDiscovery:
_unregister_irc_platform()
# ── Plugin-disabled flow ────────────────────────────────────────────────────
class TestIRCPluginDisabledFlow:
"""When the IRC plugin is disabled, setup offers to enable it."""
def test_disabled_plugin_shows_enable_prompt(self, monkeypatch):
"""A disabled plugin platform surfaces 'plugin disabled — select to enable'."""
import hermes_cli.gateway as gateway_mod
plat = _register_irc_platform(needs_enable=True)
try:
for key in ("IRC_SERVER", "IRC_CHANNEL", "IRC_NICKNAME"):
monkeypatch.delenv(key, raising=False)
status = gateway_mod._platform_status(plat)
assert "plugin disabled" in status.lower()
assert "select to enable" in status.lower()
finally:
_unregister_irc_platform()
def test_disabled_but_already_configured_shows_configured(self, monkeypatch):
"""If the plugin is disabled but env vars are already present, show 'configured'."""
import hermes_cli.gateway as gateway_mod
plat = _register_irc_platform(needs_enable=True)
try:
monkeypatch.setenv("IRC_SERVER", "irc.libera.chat")
monkeypatch.setenv("IRC_CHANNEL", "#hermes")
status = gateway_mod._platform_status(plat)
assert status == "configured"
finally:
_unregister_irc_platform()
# ── Interactive setup dispatch ──────────────────────────────────────────────
@@ -188,32 +150,6 @@ class TestIRCInteractiveSetup:
out = capsys.readouterr().out
assert "IRC setup complete!" in out
def test_configure_platform_enables_disabled_plugin_first(self, monkeypatch, capsys, tmp_path):
"""If the plugin is disabled, _configure_platform enables it before running setup."""
import hermes_cli.gateway as gateway_mod
from hermes_cli.config import save_config, load_config
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
# Ensure plugins.enabled exists but does NOT include irc_platform
cfg = load_config()
cfg.setdefault("plugins", {})["enabled"] = ["some_other_plugin"]
save_config(cfg)
calls = []
def fake_setup():
calls.append("setup_called")
plat = _register_irc_platform(setup_fn=fake_setup, needs_enable=True)
try:
gateway_mod._configure_platform(plat)
finally:
_unregister_irc_platform()
assert "setup_called" in calls
# Plugin should now be enabled
reloaded = load_config()
assert "irc_platform" in reloaded.get("plugins", {}).get("enabled", [])
def test_configure_platform_fallback_when_no_setup_fn(self, monkeypatch, capsys):
"""A plugin with no setup_fn falls back to env-var instructions."""