The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(plugins): let --yes-deps answer the consent gate for headless installs
liuhao1024169e77039a38
diff --git a/hermes_cli/plugins_cmd.py b/hermes_cli/plugins_cmd.pyindex a517e1c55f2..562601931c1 100644--- a/hermes_cli/plugins_cmd.py+++ b/hermes_cli/plugins_cmd.py@@ -968,7 +968,8 @@ _PLUGIN_ACTIONS = {enable=_tri_state_flag(args, "enable", "no_enable"),ref=getattr(args, "ref", None),allow_removed=getattr(args, "allow_removed", False),- no_deps=getattr(args, "no_deps", False)),+ no_deps=getattr(args, "no_deps", False),+ yes_deps=getattr(args, "yes_deps", False)),"search": lambda args: _catalog().cmd_search(getattr(args, "term", "") or "", json_output=getattr(args, "json", False)),"browse": lambda args: _catalog().cmd_search(""),diff --git a/hermes_cli/plugins_cmd_catalog.py b/hermes_cli/plugins_cmd_catalog.pyindex 9fbdcee61b5..29b6ec0b5ef 100644--- a/hermes_cli/plugins_cmd_catalog.py+++ b/hermes_cli/plugins_cmd_catalog.py@@ -237,7 +237,7 @@ def _refuse_unsupported_catalog_platform(entry: PluginCatalogEntry) -> None:def install_catalog_entry(entry: PluginCatalogEntry, *, force: bool, ref: Optional[str] = None,allow_removed: bool = False, scan_decision_cb=None, python_deps: bool = True,- before_swap=None) -> tuple:+ assume_deps_consent: bool = False, before_swap=None) -> tuple:"""``_install_plugin_core`` at the catalog pin (an explicit *ref* wins) + provenance recorded on theinstall-metadata record at the sha ACTUALLY checked out (a ``--ref`` install is not at the reviewedpin, so ``update_available`` must say so). Returns the core's ``(target, manifest, installed_name)``."""@@ -247,7 +247,8 @@ def install_catalog_entry(entry: PluginCatalogEntry, *, force: bool, ref: Option_refuse_unsupported_catalog_platform(entry)target, manifest, installed_name = _install_plugin_core(entry.install_identifier, force=force, ref=ref or entry.sha, scan_decision_cb=scan_decision_cb,- reviewed_pin=entry.sha, python_deps=python_deps, allow_removed=allow_removed, before_swap=before_swap,+ reviewed_pin=entry.sha, python_deps=python_deps, assume_deps_consent=assume_deps_consent,+ allow_removed=allow_removed, before_swap=before_swap,catalog={"name": entry.name, "repo": entry.repo, "tier": entry.tier, "pin": entry.sha})return target, manifest, installed_namediff --git a/hermes_cli/plugins_cmd_install.py b/hermes_cli/plugins_cmd_install.pyindex 58ac0032700..58d4c5951db 100644--- a/hermes_cli/plugins_cmd_install.py+++ b/hermes_cli/plugins_cmd_install.py@@ -26,7 +26,7 @@ def _pc():def _install_plugin_python_deps(- manifest: dict, target: Path, console+ manifest: dict, target: Path, console, *, assume_yes: bool = False) -> tuple[bool, Optional[str]]:"""Consent gate for plugin python deps (settled 2026-09-02; C13 rework).@@ -39,6 +39,8 @@ def _install_plugin_python_deps(reason): consented=True when the user accepted (or no prompt wasneeded); a decline/skip returns False and NOTHING is installed.Never raises — the caller keeps the plugin installed-but-disabled.+ *assume_yes* is ``--yes-deps``: the user's own non-interactive answer+ to the Python question, so a headless install is not refused (#122134)."""from pm.plugin_declarations import read_python_declaration@@ -78,13 +80,17 @@ def _install_plugin_python_deps(if not has_python:return True, None- return _consent_python_deps(manifest.get("name", "this plugin"), deps, console)+ return _consent_python_deps(manifest.get("name", "this plugin"), deps, console, assume_yes=assume_yes)-def _consent_python_deps(plugin_name: str, deps: tuple[str, ...], console) -> tuple[bool, Optional[str]]:+def _consent_python_deps(+ plugin_name: str, deps: tuple[str, ...], console, *, assume_yes: bool = False+) -> tuple[bool, Optional[str]]:"""The y/N gate for Python deps entering the shared environment — install,reinstall AND an update that declares new ones all pass through here.- Returns (consented, reason); never raises."""+ Returns (consented, reason); never raises. *assume_yes* (``--yes-deps``)+ answers the question on the user's behalf ONLY because the user passed the+ flag; the non-interactive default below stays a refusal."""console.print(f"\n[bold]{plugin_name}[/bold] declares Python dependencies:")@@ -94,6 +100,13 @@ def _consent_python_deps(plugin_name: str, deps: tuple[str, ...], console) -> tuelse:console.print(" - (declared in its pyproject.toml)")+ # An explicit --yes-deps is the user's own answer, TTY or not.+ if assume_yes:+ console.print(+ "[dim]--yes-deps: preparing the declared dependencies without prompting.[/dim]\n"+ )+ return True, None+# A decline or non-interactive invocation leaves the new plugin disabled.if not (sys.stdin.isatty() and sys.stdout.isatty()):console.print(@@ -285,6 +298,7 @@ def _install_plugin_core(scan_decision_cb=None,reviewed_pin: Optional[str] = None,python_deps: bool = True,+ assume_deps_consent: bool = False,catalog: Optional[dict] = None,allow_removed: bool = False,before_swap=None,@@ -294,7 +308,9 @@ def _install_plugin_core(*reviewed_pin* is the curated-catalog sha for this install; the scan trusts the treeonly when the checked-out revision is exactly that sha (an annotated-tag pin is peeled toits commit first — HEAD can only ever be the commit). *python_deps* False refuses active- replacements; it never bypasses PM dependency admission. *catalog*+ replacements; it never bypasses PM dependency admission. *assume_deps_consent* is the+ caller's ``--yes-deps`` answer carried into the publication consent gate, so a headless+ install of an active replacement is not refused non-interactively (#122134). *catalog*(``{"name", "repo", "tier", "pin"}``) is recorded on the install-metadata record with thechecked-out sha — provenance lives OUTSIDE the plugin tree, so a repo cannot forge it;its ``pin`` is kept only when the checkout satisfies it (a ``--ref`` install is off-pin).@@ -392,7 +408,8 @@ def _install_plugin_core(from hermes_cli.plugins_transaction import publish_plugintry:- publish_plugin(tmp_target, target, old_metadata, new_metadata, require_consent=True)+ publish_plugin(tmp_target, target, old_metadata, new_metadata, require_consent=True,+ assume_consent=assume_deps_consent)except Exception as exc:raise _pc().PluginOperationError(f"Plugin '{plugin_name}' was not published: {exc}") from exc@@ -428,6 +445,7 @@ def cmd_install(ref: Optional[str] = None,allow_removed: bool = False,no_deps: bool = False,+ yes_deps: bool = False,) -> None:"""Install a plugin from the curated catalog (bare name), a Git URL, or owner/repo shorthand.@@ -435,6 +453,11 @@ def cmd_install(metadata. An explicit different ``--ref`` is a custom pin. URLs/shorthand are custom sources. Everyinstall is checked against the catalog kill list unless *allow_removed*.*enable* None prompts "Enable now? [y/N]"; True/False skip the prompt.+ *yes_deps* is ``--yes-deps``: the explicit answer to the Python-deps consent+ question, so non-interactive installs (SSH automation, CI, Docker entrypoints)+ finish in one run instead of being refused and left for an ``enable`` that+ cannot recover a refused publication (#122134). The default without it stays+ fail-closed in non-interactive sessions."""from hermes_cli import plugins_cmd_catalog as catalogconsole = _pc()._console()@@ -476,10 +499,10 @@ def cmd_install(if entry is not None:return catalog.install_catalog_entry(entry, force=force, ref=ref, allow_removed=allow_removed, scan_decision_cb=_interactive_scan_decision,- python_deps=not no_deps)+ python_deps=not no_deps, assume_deps_consent=yes_deps)return _pc()._install_plugin_core(identifier, force=force, ref=ref, scan_decision_cb=_interactive_scan_decision,- python_deps=not no_deps, allow_removed=allow_removed)+ python_deps=not no_deps, allow_removed=allow_removed, assume_deps_consent=yes_deps)try:target, installed_manifest, installed_name = recorded_install(@@ -504,7 +527,8 @@ def cmd_install(should_enable = _pc()._is_tty() and _pc()._ask_yes(f" Enable '{installed_name}' now? [y/N]: ")deps_ok, deps_reason = (True, None)if should_enable and not already_active:- deps_ok, deps_reason = _install_plugin_python_deps(installed_manifest, target, console)+ deps_ok, deps_reason = _install_plugin_python_deps(installed_manifest, target, console,+ assume_yes=yes_deps)_pc()._display_after_install(target, identifier)diff --git a/hermes_cli/plugins_transaction.py b/hermes_cli/plugins_transaction.pyindex bb98a212cd6..20d86c21a9f 100644--- a/hermes_cli/plugins_transaction.py+++ b/hermes_cli/plugins_transaction.py@@ -14,12 +14,17 @@ def recover_plugin_publication(project: Path, row: dict, journal: Path) -> None:def publish_plugin(staged: Path, target: Path, old_metadata: dict, new_metadata: dict,- *, target_digest: str | None = None, require_consent: bool = False) -> None:+ *, target_digest: str | None = None, require_consent: bool = False,+ assume_consent: bool = False) -> None:+ """Publish *staged* into *target*. *assume_consent* is the caller's own+ ``--yes-deps`` answer: the active-replacement consent veto is skipped, so+ an unattended install can carry the user's explicit decision instead of+ being refused non-interactively."""from pm.client import sync_venvfrom pm.plugin_inputs import StagedUpdatefrom pm.store import tree_digest- if require_consent:+ if require_consent and not assume_consent:from hermes_cli import plugins_cmdfrom pm.workspace import enabled_plugin_dirsdiff --git a/hermes_cli/subcommands/plugins.py b/hermes_cli/subcommands/plugins.pyindex 59b35bc4f36..47501b6c2e4 100644--- a/hermes_cli/subcommands/plugins.py+++ b/hermes_cli/subcommands/plugins.py@@ -29,9 +29,14 @@ def build_plugins_parser(subparsers, *, cmd_plugins: Callable) -> None:plugins_install.add_argument("--allow-removed", action="store_true",help="DANGEROUS: bypass the catalog removed-plugin blocklist check")- plugins_install.add_argument(+ _install_deps_group = plugins_install.add_mutually_exclusive_group()+ _install_deps_group.add_argument("--no-deps", action="store_true",help="Download without dependency consent and leave disabled; cannot replace an active plugin")+ _install_deps_group.add_argument(+ "--yes-deps", action="store_true",+ help="Answer the Python dependency consent question yourself, so non-interactive installs "+ "(SSH automation, CI, Docker entrypoints) finish in one run instead of being refused")_install_enable_group = plugins_install.add_mutually_exclusive_group()_install_enable_group.add_argument("--enable", action="store_true",diff --git a/tests/hermes_cli/test_plugin_dependency_consent.py b/tests/hermes_cli/test_plugin_dependency_consent.pyindex ed5b36b4c1c..c2a1ce7c856 100644--- a/tests/hermes_cli/test_plugin_dependency_consent.py+++ b/tests/hermes_cli/test_plugin_dependency_consent.py@@ -64,3 +64,67 @@ def test_node_sidecar_question_stays_independent(tmp_path, monkeypatch):assert installs == [(target, {'explicit': True})]assert len(prompts) == 1 and 'node_modules' in prompts[0]assert not any('Python dependencies' in str(line) for line in lines)+++def test_yes_deps_carries_consent_through_non_interactive_install(admission_env, monkeypatch, capsys):+ """--yes-deps (#122134): the flag is the user's own answer to the consent+ question, so a non-interactive install publishes AND enables in one run+ instead of being refused (the `enable` recovery cannot publish a plugin)."""+ root, home = admission_env+ source = root / 'plugin-source'+ source.mkdir()+ (source / 'plugin.yaml').write_text(yaml.safe_dump({'name': 'yes-deps-plugin'}), encoding='utf-8')+ (source / '__init__.py').write_text('def register(ctx):\n pass\n', encoding='utf-8')+ (source / 'pyproject.toml').write_text(+ '[project]\nname="yes-deps-plugin"\nversion="1.0"\nrequires-python=">=3.11"\n', encoding='utf-8')+ env = {k: v for k, v in os.environ.items() if k not in {'GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE'}}+ for args in [('init', '-q'), ('add', '.'), ('-c', 'user.name=test', '-c', '[email protected]', 'commit', '-qm', 'fixture')]:+ subprocess.run(['git', *args], cwd=source, env=env, check=True, capture_output=True, timeout=30)+ monkeypatch.setattr(plugins_cmd.sys.stdin, 'isatty', lambda: False)++ plugins_cmd.cmd_install(source.as_uri(), enable=True, allow_removed=True, yes_deps=True)++ enabled = yaml.safe_load((home / 'config.yaml').read_text(encoding='utf-8'))['plugins']['enabled']+ output = capsys.readouterr().out+ assert 'yes-deps-plugin' in enabled+ assert 'dependency install skipped (non-interactive)' not in output+++def test_publish_assume_consent_skips_replacement_veto(tmp_path, monkeypatch):+ """The active-replacement veto at publication honors --yes-deps: with the+ explicit answer the PM handoff runs; the default without it stays the+ non-interactive refusal (#122134's 'Reinstall declined' half)."""+ from hermes_cli import plugins_transaction+ from pm import workspace as ws++ staged, target = tmp_path / 'staged', tmp_path / 'target'+ staged.mkdir()+ target.mkdir()+ (staged / 'plugin.yaml').write_text(yaml.safe_dump({'name': 'active-plugin'}), encoding='utf-8')+ (staged / 'pyproject.toml').write_text(+ '[project]\nname="active-plugin"\nversion="1.0"\nrequires-python=">=3.11"\n', encoding='utf-8')+ monkeypatch.setattr(ws, 'enabled_plugin_dirs', lambda **kwargs: [target])+ syncs = []+ monkeypatch.setattr('pm.client.sync_venv', lambda **kwargs: syncs.append(kwargs))+ monkeypatch.setattr(plugins_cmd.sys.stdin, 'isatty', lambda: False)++ plugins_transaction.publish_plugin(+ staged, target, {}, {'active-plugin': {}}, require_consent=True, assume_consent=True)+ assert len(syncs) == 1++ with pytest.raises(plugins_cmd.PluginOperationError, match='Reinstall declined'):+ plugins_transaction.publish_plugin(staged, target, {}, {'active-plugin': {}}, require_consent=True)+++def test_install_parser_offers_yes_deps_exclusive_with_no_deps():+ import argparse++ from hermes_cli.subcommands.plugins import build_plugins_parser++ parser = argparse.ArgumentParser(prog='hermes')+ build_plugins_parser(parser.add_subparsers(), cmd_plugins=lambda args: None)+ ns = parser.parse_args(['plugins', 'install', 'x', '--yes-deps'])+ assert ns.yes_deps is True+ assert ns.no_deps is False+ with pytest.raises(SystemExit):+ parser.parse_args(['plugins', 'install', 'x', '--no-deps', '--yes-deps'])