mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
feat(plugins): make all plugins opt-in by default
Plugins now require explicit consent to load. Discovery still finds every plugin — user-installed, bundled, and pip — so they all show up in `hermes plugins` and `/plugins`, but the loader only instantiates plugins whose name appears in `plugins.enabled` in config.yaml. This removes the previous ambient-execution risk where a newly-installed or bundled plugin could register hooks, tools, and commands on first run without the user opting in. The three-state model is now explicit: enabled — in plugins.enabled, loads on next session disabled — in plugins.disabled, never loads (wins over enabled) not enabled — discovered but never opted in (default for new installs) `hermes plugins install <repo>` prompts "Enable 'name' now? [y/N]" (defaults to no). New `--enable` / `--no-enable` flags skip the prompt for scripted installs. `hermes plugins enable/disable` manage both lists so a disabled plugin stays explicitly off even if something later adds it to enabled. Config migration (schema v20 → v21): existing user plugins already installed under ~/.hermes/plugins/ (minus anything in plugins.disabled) are auto-grandfathered into plugins.enabled so upgrades don't silently break working setups. Bundled plugins are NOT grandfathered — even existing users have to opt in explicitly. Also: HERMES_DISABLE_BUNDLED_PLUGINS env var removed (redundant with opt-in default), cmd_list now shows bundled + user plugins together with their three-state status, interactive UI tags bundled entries [bundled], docs updated across plugins.md and built-in-plugins.md. Validation: 442 plugin/config tests pass. E2E: fresh install discovers disk-cleanup but does not load it; `hermes plugins enable disk-cleanup` activates hooks; migration grandfathers existing user plugins correctly while leaving bundled plugins off.
This commit is contained in:
parent
a25c8c6a56
commit
70111eea24
10 changed files with 578 additions and 167 deletions
|
|
@ -366,35 +366,62 @@ class TestSlashCommand:
|
|||
# ---------------------------------------------------------------------------
|
||||
|
||||
class TestBundledDiscovery:
|
||||
def test_disk_cleanup_is_discovered_as_bundled(self, _isolate_env, monkeypatch):
|
||||
# The default hermetic conftest disables bundled plugin discovery.
|
||||
# This test specifically exercises it, so clear the suppression.
|
||||
monkeypatch.delenv("HERMES_DISABLE_BUNDLED_PLUGINS", raising=False)
|
||||
def _write_enabled_config(self, hermes_home, names):
|
||||
"""Write plugins.enabled allow-list to config.yaml."""
|
||||
import yaml
|
||||
cfg_path = hermes_home / "config.yaml"
|
||||
cfg_path.write_text(yaml.safe_dump({"plugins": {"enabled": list(names)}}))
|
||||
|
||||
def test_disk_cleanup_discovered_but_not_loaded_by_default(self, _isolate_env):
|
||||
"""Bundled plugins are discovered but NOT loaded without opt-in."""
|
||||
from hermes_cli import plugins as pmod
|
||||
mgr = pmod.PluginManager()
|
||||
mgr.discover_and_load()
|
||||
# Discovered — appears in the registry
|
||||
assert "disk-cleanup" in mgr._plugins
|
||||
loaded = mgr._plugins["disk-cleanup"]
|
||||
assert loaded.manifest.source == "bundled"
|
||||
# But NOT enabled — no hooks or commands registered
|
||||
assert not loaded.enabled
|
||||
assert loaded.error and "not enabled" in loaded.error
|
||||
|
||||
def test_disk_cleanup_loads_when_enabled(self, _isolate_env):
|
||||
"""Adding to plugins.enabled activates the bundled plugin."""
|
||||
self._write_enabled_config(_isolate_env, ["disk-cleanup"])
|
||||
from hermes_cli import plugins as pmod
|
||||
mgr = pmod.PluginManager()
|
||||
mgr.discover_and_load()
|
||||
loaded = mgr._plugins["disk-cleanup"]
|
||||
assert loaded.enabled
|
||||
assert "post_tool_call" in loaded.hooks_registered
|
||||
assert "on_session_end" in loaded.hooks_registered
|
||||
assert "disk-cleanup" in loaded.commands_registered
|
||||
|
||||
def test_memory_and_context_engine_subdirs_skipped(self, _isolate_env, monkeypatch):
|
||||
def test_disabled_beats_enabled(self, _isolate_env):
|
||||
"""plugins.disabled wins even if the plugin is also in plugins.enabled."""
|
||||
import yaml
|
||||
cfg_path = _isolate_env / "config.yaml"
|
||||
cfg_path.write_text(yaml.safe_dump({
|
||||
"plugins": {
|
||||
"enabled": ["disk-cleanup"],
|
||||
"disabled": ["disk-cleanup"],
|
||||
}
|
||||
}))
|
||||
from hermes_cli import plugins as pmod
|
||||
mgr = pmod.PluginManager()
|
||||
mgr.discover_and_load()
|
||||
loaded = mgr._plugins["disk-cleanup"]
|
||||
assert not loaded.enabled
|
||||
assert loaded.error == "disabled via config"
|
||||
|
||||
def test_memory_and_context_engine_subdirs_skipped(self, _isolate_env):
|
||||
"""Bundled scan must NOT pick up plugins/memory or plugins/context_engine
|
||||
as top-level plugins — they have their own discovery paths."""
|
||||
monkeypatch.delenv("HERMES_DISABLE_BUNDLED_PLUGINS", raising=False)
|
||||
self._write_enabled_config(
|
||||
_isolate_env, ["memory", "context_engine", "disk-cleanup"]
|
||||
)
|
||||
from hermes_cli import plugins as pmod
|
||||
mgr = pmod.PluginManager()
|
||||
mgr.discover_and_load()
|
||||
assert "memory" not in mgr._plugins
|
||||
assert "context_engine" not in mgr._plugins
|
||||
|
||||
def test_bundled_scan_suppressed_by_env_var(self, _isolate_env, monkeypatch):
|
||||
"""HERMES_DISABLE_BUNDLED_PLUGINS=1 suppresses bundled discovery."""
|
||||
monkeypatch.setenv("HERMES_DISABLE_BUNDLED_PLUGINS", "1")
|
||||
from hermes_cli import plugins as pmod
|
||||
mgr = pmod.PluginManager()
|
||||
mgr.discover_and_load()
|
||||
assert "disk-cleanup" not in mgr._plugins
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue