The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(plugins): update scans every new revision and a caution verdict can be overridden
alt-glitch5bc0767821d0
diff --git a/hermes_cli/plugins_cmd.py b/hermes_cli/plugins_cmd.pyindex 2dc5bb13c77..8052f8108ed 100644--- a/hermes_cli/plugins_cmd.py+++ b/hermes_cli/plugins_cmd.py@@ -1067,8 +1067,10 @@ def _action_update(args):if args.name:if getattr(args, "yes", False):_fail(_console(), "[red]Error:[/red] --yes only applies to `hermes plugins update` with no name.")- cmd_update(args.name)+ cmd_update(args.name, force=getattr(args, "force", False))return+ if getattr(args, "force", False):+ _fail(_console(), "[red]Error:[/red] --force applies to one named plugin: `hermes plugins update <name> --force`.")from hermes_cli.plugins_cmd_update_all import cmd_update_allcmd_update_all(yes=getattr(args, "yes", False))diff --git a/hermes_cli/plugins_cmd_install.py b/hermes_cli/plugins_cmd_install.pyindex 2aee13fdd3f..0eff3ec5851 100644--- a/hermes_cli/plugins_cmd_install.py+++ b/hermes_cli/plugins_cmd_install.py@@ -328,10 +328,36 @@ def _known_issue_warnings(entry) -> list[str]:return [f"Known issue: {issue}" for issue in entry.known_issues]+def interactive_scan_decision(console, verb: str) -> Callable[[Any], bool]:+ """The terminal ``[y/N]`` that accepts a caution verdict, shared by install and update (*verb*)."""+ def decide(scan_result) -> bool:+ from tools.plugin_guard import format_scan_report+ console.print()+ console.print("[yellow]⚠ Security scan flagged this plugin:[/yellow]")+ console.print(format_scan_report(scan_result))+ return _pc()._is_tty() and _pc()._ask_yes(f" {verb} anyway? Only continue if you trust the source. [y/N]: ")+ return decide+++def scan_blocked_result(exc) -> dict[str, Any]:+ """The non-interactive surfaces' answer to a scan block: the verdict and findings, so the client can+ show them and, for a caution verdict, retry with ``force``."""+ fields = ("pattern_id", "severity", "category", "file", "line", "description")+ return {+ "ok": False, "error": str(exc), "scan_blocked": True,+ "scan_verdict": getattr(exc.scan_result, "verdict", "dangerous"),+ "scan_findings": [+ {k: getattr(f, k) for k in fields}+ for f in (exc.scan_result.findings if exc.scan_result is not None else ())+ ],+ }++def _install_plugin_core(identifier: str,*,force: bool,+ accept_caution: Optional[bool] = None,ref: Optional[str] = None,scan_decision_cb=None,reviewed_pin: Optional[str] = None,@@ -356,7 +382,9 @@ def _install_plugin_core(*before_swap(manifest, tree)* runs on the manifest-checked clone BEFORE the security scan, sothe single scan and portable-package check admit the merged tree (file-count/size limitsincluded). It may return the relative paths it merged in, which a scan block then attributes,- and may raise :class:`PluginOperationError` to abort (re-pin consent)."""+ and may raise :class:`PluginOperationError` to abort (re-pin consent). *accept_caution* decides a+ caution scan verdict on its own when *force* only means "replace the existing tree" (an update's+ re-clone); None lets *force* decide both, as ``install --force`` does."""requested_revision = _pc()._normalize_exact_revision(ref) if ref is not None else Nonetry:git_url, subdir = _pc()._resolve_git_url(identifier)@@ -415,8 +443,8 @@ def _install_plugin_core(# admits the final bytes.merged = before_swap(manifest, tmp_target) if before_swap is not None else None# Scan BEFORE anything is moved into place; raises PluginScanBlocked when blocked.- _pc()._scan_merged_tree(tmp_target, identifier, merged, force=force, scan_decision_cb=scan_decision_cb,- reviewed_pin=at_reviewed_pin)+ _pc()._scan_merged_tree(tmp_target, identifier, merged, force=force if accept_caution is None else accept_caution,+ scan_decision_cb=scan_decision_cb, reviewed_pin=at_reviewed_pin)if not python_deps:from pm.workspace import enabled_plugin_dirs@@ -577,14 +605,7 @@ def cmd_install("Consider using https:// or git@ for production installs.")console.print(f"[dim]Cloning {git_url}{f' (subdir: {_subdir})' if _subdir else ''}...[/dim]")-- def _interactive_scan_decision(scan_result) -> bool:- """Prompt the user to accept a caution-verdict plugin."""- from tools.plugin_guard import format_scan_report- console.print()- console.print("[yellow]⚠ Security scan flagged this plugin:[/yellow]")- console.print(format_scan_report(scan_result))- return _pc()._is_tty() and _pc()._ask_yes(" Install anyway? Only continue if you trust the source. [y/N]: ")+ _interactive_scan_decision = interactive_scan_decision(console, "Install")def _install() -> tuple:if entry is not None:@@ -792,15 +813,7 @@ def _place_tree(entry, identifier: str, *, force: bool, ref: Optional[str], assureturn recorded_install(_install, catalog_name=entry.name if entry is not None else None,identifier=identifier)except _pc().PluginScanBlocked as exc:- fields = ("pattern_id", "severity", "category", "file", "line", "description")- return {- "ok": False, "error": str(exc), "scan_blocked": True,- "scan_verdict": getattr(exc.scan_result, "verdict", "dangerous"),- "scan_findings": [- {k: getattr(f, k) for k in fields}- for f in (exc.scan_result.findings if exc.scan_result is not None else ())- ],- }+ return scan_blocked_result(exc)except _pc().PluginOperationError as exc:return {"ok": False, "error": str(exc)}diff --git a/hermes_cli/plugins_cmd_update.py b/hermes_cli/plugins_cmd_update.pyindex 20eb0cc1153..6ba4ca8ec56 100644--- a/hermes_cli/plugins_cmd_update.py+++ b/hermes_cli/plugins_cmd_update.py@@ -20,11 +20,14 @@ def _pc():return plugins_cmd-def _pull_plugin_update(target: Path, pinned_msg, not_git_msg, before_pull=None, *, interactive: bool = False) -> str:+def _pull_plugin_update(target: Path, pinned_msg, not_git_msg, before_pull=None, *, interactive: bool = False,+ force: bool = False, scan_decision_cb=None) -> str:"""Shared ``update`` core: refuse pinned checkouts, ``git pull`` (or re-install from therecorded source when the tree carries no ``.git`` — subdirectory installs), record the newrevision. Returns the pull output; raises :class:`PluginOperationError` on any refusal.- *pinned_msg(install_record)* / *not_git_msg()* build the caller-specific error text."""+ *pinned_msg(install_record)* / *not_git_msg()* build the caller-specific error text. Both paths+ scan the candidate tree the same way: *force* or a truthy *scan_decision_cb* accepts a caution+ verdict, nothing accepts a dangerous one."""metadata = _pc()._read_install_metadata()install_record = metadata.get(target.name, {})if install_record.get("pinned") is True:@@ -39,25 +42,31 @@ def _pull_plugin_update(target: Path, pinned_msg, not_git_msg, before_pull=None,raise _pc().PluginOperationError(not_git_msg())if before_pull is not None:before_pull()- return _reclone_plugin_update(target, source, install_record.get("revision"))+ return _reclone_plugin_update(target, source, install_record.get("revision"),+ force=force, scan_decision_cb=scan_decision_cb)if before_pull is not None:before_pull()from hermes_cli.plugins_transaction import update_plugin- return update_plugin(target, interactive=interactive)+ return update_plugin(target, interactive=interactive, force=force, scan_decision_cb=scan_decision_cb)-def _reclone_plugin_update(target: Path, source: str, previous_revision: object) -> str:+def _reclone_plugin_update(target: Path, source: str, previous_revision: object, *, force: bool = False,+ scan_decision_cb=None) -> str:"""Update a subdirectory install by re-cloning its source and atomically replacing the tree.These installs carry no local ``.git``, so the staged replacement also carries user-ownedconfig/data from *target* before publication instead of silently deleting it (#122006).+ Replacing the tree needs the install core's ``force``; accepting a caution scan is a separate+ decision (*force* / *scan_decision_cb*), the same as the git-pull path."""from hermes_cli.plugins_cmd_catalog import _carry_user_filesnew_target, _manifest, _name = _pc()._install_plugin_core(source,force=True,+ accept_caution=force,+ scan_decision_cb=scan_decision_cb,before_swap=lambda _manifest, tree: _carry_user_files(target, tree, None),)revision = str(_pc()._read_install_metadata().get(new_target.name, {}).get("revision") or "")@@ -67,15 +76,18 @@ def _reclone_plugin_update(target: Path, source: str, previous_revision: object)return f"Re-installed from {source}: {previous[:8]}..{revision[:8]}"-def update_one(name: str, target: Path, console, *, interactive: bool = True) -> bool:+def update_one(name: str, target: Path, console, *, interactive: bool = True, force: bool = False) -> bool:"""Update one installed plugin, printing progress and consent prompts; True when it moved.+ Every update is scanned. A caution verdict on a git update asks ``Update anyway? [y/N]`` when+ *interactive*; *force* (``--force``) accepts it without asking. A dangerous verdict always blocks.Refusals raise :class:`~hermes_cli.plugins_cmd_catalog.RepinConsentRequired` or``PluginOperationError`` with nothing changed; :func:`cmd_update` turns them into exit 1 and``hermes plugins update`` with no name records them per plugin and moves on."""from rich.markup import escapefrom hermes_cli import plugins_cmd_catalog as catalog+ from hermes_cli.plugins_cmd_install import interactive_scan_decisionsidecar = catalog.catalog_install_record(target)if sidecar: # catalog installs re-pin to the reviewed SHA — never `git pull`return catalog.cmd_update_catalog(name, target, sidecar, console, interactive=interactive)@@ -87,7 +99,9 @@ def update_one(name: str, target: Path, console, *, interactive: bool = True) ->"--ref <40-character commit SHA>`."),lambda: f"Plugin '{name}' was not installed from git (no .git directory). Cannot update.",before_pull=lambda: console.print(f"[dim]Updating {name}...[/dim]"),- interactive=interactive)+ interactive=interactive,+ force=force,+ scan_decision_cb=interactive_scan_decision(console, "Update") if interactive else None)_post_pull_housekeeping(target, console)# Update-time re-consent (#64228): if the new version declares@@ -115,15 +129,17 @@ def update_one(name: str, target: Path, console, *, interactive: bool = True) ->return True-def cmd_update(name: str, *, interactive: bool = True) -> None:- """``hermes plugins update <name>``: :func:`update_one`, exit 1 on a refusal."""+def cmd_update(name: str, *, interactive: bool = True, force: bool = False) -> None:+ """``hermes plugins update <name> [--force]``: :func:`update_one`, exit 1 on a refusal."""from hermes_cli.plugins_cmd_catalog import RepinConsentRequiredconsole = _pc()._console()target = _pc()._require_installed_plugin(name, _pc()._plugins_dir(), console)try:- update_one(name, target, console, interactive=interactive)+ update_one(name, target, console, interactive=interactive, force=force)except RepinConsentRequired as exc:_pc()._fail(console, f"[yellow]Update of {name} not applied:[/yellow] {exc}")+ except _pc().PluginScanBlocked as exc:+ _pc()._fail(console, f"[red]Blocked:[/red] {exc}")except _pc().PluginOperationError as exc:_pc()._fail(console, f"[red]Error:[/red] {exc}")diff --git a/hermes_cli/plugins_transaction.py b/hermes_cli/plugins_transaction.pyindex 1838658cd7c..bbb5df4038f 100644--- a/hermes_cli/plugins_transaction.py+++ b/hermes_cli/plugins_transaction.py@@ -3,6 +3,7 @@ from __future__ import annotationsfrom collections.abc import Callablefrom pathlib import Path+from typing import Anyimport shutil@@ -92,12 +93,16 @@ def update_plugin(*,catalog_entry=None,interactive: bool = False,+ force: bool = False,+ scan_decision_cb: Callable[[Any], bool] | None = None,carry_user_files: Callable[[Path], list[str]] | None = None,) -> str:"""Prepare a catalog re-pin or custom Git pull without changing the live tree.*interactive*: a terminal user is present to consent to newly declared dependencies;the dashboard and the gateway's auto-apply pass False and get a refusal instead.+ Every update is scanned: *force* accepts a caution verdict (the user already saw it), and+ *scan_decision_cb(result)* may accept one by asking; a dangerous verdict always blocks.*carry_user_files(staged)* may merge user-owned state into the staged tree beforemanifest validation, example-file generation, dependency preparation and publication; itreturns the carried paths so a scan block can attribute findings to them."""@@ -186,7 +191,8 @@ def update_plugin(raise pc.PluginOperationError(f"The updated plugin renamed itself to '{installed_name}', but that plugin already exists.")pc._check_manifest_version(manifest, installed_name)- pc._scan_merged_tree(staged, source, merged, force=False, reviewed_pin=catalog_entry is not None)+ pc._scan_merged_tree(staged, source, merged, force=force, scan_decision_cb=scan_decision_cb,+ reviewed_pin=catalog_entry is not None)pc._copy_example_files(staged, pc._console())_refresh_declared_dependencies(target, staged, manifest, interactive=interactive)if tree_digest(target) != before:diff --git a/hermes_cli/subcommands/plugins.py b/hermes_cli/subcommands/plugins.pyindex 1c71fd85bc2..26a0eec6469 100644--- a/hermes_cli/subcommands/plugins.py+++ b/hermes_cli/subcommands/plugins.py@@ -72,6 +72,10 @@ def build_plugins_parser(subparsers, *, cmd_plugins: Callable) -> None:plugins_update.add_argument("--yes", "-y", action="store_true",help="With no name: update everything listed without the confirmation question (required without a terminal)")+ plugins_update.add_argument(+ "--force", "-f", action="store_true",+ help="Apply the update even when the security scan returns a caution verdict (a dangerous verdict "+ "still blocks). Without it, a terminal asks first")plugins_adopt = plugins_subparsers.add_parser("adopt",