Skip to content

The agent that grows with you

feat(plugins): install actually installs python deps — consent, try-resolve, enable-only-if-resolves

ethernet96604184b410
diff --git a/hermes_cli/plugins_cmd.py b/hermes_cli/plugins_cmd.py
index 7ab3d6c875a..2f87216c883 100644
--- a/hermes_cli/plugins_cmd.py
+++ b/hermes_cli/plugins_cmd.py
@@ -399,30 +399,69 @@ def _missing_requires_env_names(manifest: dict) -> list[str]:
return [s["name"] for s in env_specs if s.get("name") and not get_env_value(s["name"])]
-def _print_python_dependencies(manifest: dict, console) -> None:
- """Surface declared python_dependencies at install time (#64165).
-
- Declaration seam ONLY — Hermes never auto-installs plugin pip
- dependencies (isolation design deferred; see #64165 / #15220). We print
- the declared requirements with a copy-pasteable install hint.
+def _install_plugin_python_deps(
+ manifest: dict, target: Path, console
+) -> tuple[bool, Optional[str]]:
+ """Consent + try-resolve for plugin python deps (settled 2026-09-02).
+
+ y/n prompt (auto-NO when non-interactive) → materialize the legacy
+ bridge if needed → resolve through the pm workspace union. Returns
+ (installed, reason): installed=True when the deps resolve; on
+ conflict the resolver's message is the reason. Never raises — the
+ caller keeps the plugin installed-but-disabled on failure.
"""
deps = manifest.get("python_dependencies") or []
if not isinstance(deps, list):
- return
+ return True, None
deps = [d.strip() for d in deps if isinstance(d, str) and d.strip()]
- if not deps:
- return
+ has_pyproject = (target / "pyproject.toml").is_file()
+ if not deps and not has_pyproject:
+ return True, None # no declared python deps at all
+
plugin_name = manifest.get("name", "this plugin")
console.print(
- f"\n[bold]{plugin_name}[/bold] declares Python dependencies "
- "(not installed automatically):"
- )
- for dep in deps:
- console.print(f" - {dep}")
- console.print(
- "[dim]Install them yourself if needed: "
- f"pip install {' '.join(repr(d) for d in deps)}[/dim]\n"
+ f"\n[bold]{plugin_name}[/bold] declares Python dependencies:"
)
+ if deps:
+ for dep in deps:
+ console.print(f" - {dep}")
+ else:
+ console.print(" - (declared in its pyproject.toml)")
+
+ # Non-interactive (pipelines, cron) or a decline → skip the install;
+ # the plugin still works if the deps happen to be importable.
+ if not (sys.stdin.isatty() and sys.stdout.isatty()):
+ console.print(
+ "[dim]Non-interactive install — skipping dependency install. "
+ "Run `hermes pm install` after enabling if the plugin needs "
+ "them.[/dim]\n"
+ )
+ return False, "dependency install skipped (non-interactive)"
+ try:
+ answer = input(
+ " Install these into the Hermes venv now? [y/N]: "
+ ).strip().lower()
+ except (EOFError, KeyboardInterrupt):
+ answer = ""
+ if answer not in {"y", "yes"}:
+ console.print(
+ "[dim]Skipped — run `hermes pm install` later to install "
+ "them.[/dim]\n"
+ )
+ return False, "dependency install declined"
+
+ from pm.workspace import enabled_member_dirs, lock_and_sync, materialize_legacy_pyproject
+
+ try:
+ # Legacy manifest-only plugins need their generated pyproject before
+ # the union can see their deps.
+ materialize_legacy_pyproject(target)
+ # The plugin's own dir is a member candidate already (dropped by
+ # _install_plugin_core); union with the other enabled plugins.
+ lock_and_sync(enabled_member_dirs() or [target])
+ except Exception as exc:
+ return False, str(exc)
+ return True, None
def _prompt_plugin_env_vars(manifest: dict, console) -> None:
@@ -1031,13 +1070,28 @@ def cmd_install(
_prompt_plugin_env_vars(installed_manifest, console)
- _print_python_dependencies(installed_manifest, console)
+ deps_ok, deps_reason = _install_plugin_python_deps(
+ installed_manifest, target, console
+ )
_display_after_install(target, identifier)
should_enable = enable
+ if should_enable and not deps_ok:
+ # Explicitly requested enable, but the deps failed to resolve:
+ # enabling would break the venv union on the next sync. Refuse
+ # with the resolver's reason.
+ console.print(
+ f"[red]✗[/red] Cannot enable [bold]{installed_name}[/bold]: "
+ f"its Python dependencies did not resolve: {deps_reason}"
+ )
+ console.print(
+ "[dim]The plugin stays installed but disabled; re-enable "
+ "after resolving the conflict.[/dim]"
+ )
+ should_enable = False
if should_enable is None:
- if sys.stdin.isatty() and sys.stdout.isatty():
+ if deps_ok and sys.stdin.isatty() and sys.stdout.isatty():
try:
answer = input(
f" Enable '{installed_name}' now? [y/N]: ",
@@ -1047,6 +1101,16 @@ def cmd_install(
should_enable = False
else:
should_enable = False
+ if not deps_ok:
+ console.print(
+ f"[yellow]Plugin [bold]{installed_name}[/bold] installed "
+ f"but NOT enabled — Python dependencies did not resolve:[/yellow]"
+ )
+ console.print(f" [dim]{deps_reason}[/dim]")
+ console.print(
+ "[dim]Re-enable after resolving the conflict "
+ f"(hermes plugins enable {installed_name}).[/dim]\n"
+ )
if should_enable:
enabled = _get_enabled_set()
diff --git a/tests/hermes_cli/test_plugins_cmd_deps_flow.py b/tests/hermes_cli/test_plugins_cmd_deps_flow.py
new file mode 100644
index 00000000000..16ab3598ed2
--- /dev/null
+++ b/tests/hermes_cli/test_plugins_cmd_deps_flow.py
@@ -0,0 +1,128 @@
+"""hermes plugins install: python-deps consent + try-resolve flow.
+
+Settled 2026-09-02 (.hermes/plans/2026-09-02_164500-plugin-deps-workspace-
+union.md): install drops the folder, prompts y/n for declared python
+deps, resolves through the pm workspace union, and ENABLES ONLY IF THE
+DEPS RESOLVE — a conflicting plugin stays installed-but-disabled with
+the resolver's reason.
+"""
+
+from __future__ import annotations
+
+from pathlib import Path
+from unittest.mock import patch
+
+import pytest
+
+import hermes_cli.plugins_cmd as pc
+
+
+class _Console:
+ def __init__(self):
+ self.lines: list[str] = []
+
+ def print(self, *args, **kwargs):
+ for arg in args:
+ self.lines.append(str(arg))
+
+
+def _legacy_plugin(target: Path) -> None:
+ target.mkdir(parents=True, exist_ok=True)
+ (target / "plugin.yaml").write_text(
+ "name: dep-plug\npip_dependencies:\n - \"somepkg>=1,<2\"\n",
+ encoding="utf-8",
+ )
+
+
+def test_no_deps_short_circuits_true(tmp_path):
+ plug = tmp_path / "plain"
+ plug.mkdir()
+ (plug / "plugin.yaml").write_text("name: plain\n", encoding="utf-8")
+ ok, reason = pc._install_plugin_python_deps(
+ {"name": "plain", "python_dependencies": []}, plug, _Console()
+ )
+ assert ok is True and reason is None
+
+
+def test_noninteractive_skips_install(tmp_path, monkeypatch):
+ plug = tmp_path / "dep-plug"
+ _legacy_plugin(plug)
+ monkeypatch.setattr(pc.sys.stdin, "isatty", lambda: False, raising=False)
+ called = []
+ monkeypatch.setattr(
+ "pm.workspace.lock_and_sync", lambda *a, **k: called.append(a)
+ )
+ ok, reason = pc._install_plugin_python_deps(
+ {"name": "dep-plug", "python_dependencies": ["somepkg>=1,<2"]},
+ plug,
+ _Console(),
+ )
+ assert ok is False
+ assert "non-interactive" in reason
+ assert not called # nothing installed, nothing enabled
+
+
+def test_decline_skips_install(tmp_path, monkeypatch):
+ plug = tmp_path / "dep-plug"
+ _legacy_plugin(plug)
+ monkeypatch.setattr(pc.sys.stdin, "isatty", lambda: True, raising=False)
+ monkeypatch.setattr(pc.sys.stdout, "isatty", lambda: True, raising=False)
+ monkeypatch.setattr("builtins.input", lambda *a: "n")
+ called = []
+ monkeypatch.setattr(
+ "pm.workspace.lock_and_sync", lambda *a, **k: called.append(a)
+ )
+ ok, reason = pc._install_plugin_python_deps(
+ {"name": "dep-plug", "python_dependencies": ["somepkg>=1,<2"]},
+ plug,
+ _Console(),
+ )
+ assert ok is False
+ assert "declined" in reason
+ assert not called
+
+
+def test_conflict_reports_reason_not_crash(tmp_path, monkeypatch):
+ plug = tmp_path / "dep-plug"
+ _legacy_plugin(plug)
+ monkeypatch.setattr(pc.sys.stdin, "isatty", lambda: True, raising=False)
+ monkeypatch.setattr(pc.sys.stdout, "isatty", lambda: True, raising=False)
+ monkeypatch.setattr("builtins.input", lambda *a: "y")
+
+ def boom(*a, **k):
+ raise RuntimeError(
+ "uv lock exited 1: Because dep-plug depends on somepkg==9.9.9 "
+ "and hermes-agent depends on somepkg==1.0.0, unsatisfiable"
+ )
+
+ monkeypatch.setattr("pm.workspace.lock_and_sync", boom)
+ ok, reason = pc._install_plugin_python_deps(
+ {"name": "dep-plug", "python_dependencies": ["somepkg==9.9.9"]},
+ plug,
+ _Console(),
+ )
+ assert ok is False
+ assert "unsatisfiable" in reason
+
+
+def test_success_installs_and_legacy_bridge_materializes(tmp_path, monkeypatch):
+ plug = tmp_path / "dep-plug"
+ _legacy_plugin(plug)
+ monkeypatch.setattr(pc.sys.stdin, "isatty", lambda: True, raising=False)
+ monkeypatch.setattr(pc.sys.stdout, "isatty", lambda: True, raising=False)
+ monkeypatch.setattr("builtins.input", lambda *a: "y")
+ synced = []
+ monkeypatch.setattr(
+ "pm.workspace.lock_and_sync", lambda *a, **k: synced.append(a)
+ )
+ ok, reason = pc._install_plugin_python_deps(
+ {"name": "dep-plug", "python_dependencies": ["somepkg>=1,<2"]},
+ plug,
+ _Console(),
+ )
+ assert ok is True and reason is None
+ assert synced # the union ran
+ # the legacy bridge materialized the pyproject before the resolve
+ generated = plug / "pyproject.toml"
+ assert generated.is_file()
+ assert "GENERATED by pm" in generated.read_text(encoding="utf-8")