The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
pm: install agent-browser by default, with a recorded --without opt-out
ethernet3addc73a8385
diff --git a/pm/cli.py b/pm/cli.pyindex e9e51534b21..aaa5ca09b3f 100644--- a/pm/cli.py+++ b/pm/cli.py@@ -280,9 +280,33 @@ def _install_flag_error(args, *, extras: list[str], cross_target, tools_only: boreturn "--trust-recorded installs the default closure and then stops; it does not take names, --extra, or --target"if extras and cross_target:return "--extra syncs this install's venv and cannot combine with --target"+ without = getattr(args, "without", None) or ()+ if without and (extras or cross_target or args.names):+ return "--without shapes the default closure; it does not take names, --extra, or --target"+ if without:+ from pm.defaults import default_package_names++ allowed = default_package_names()+ unknown = [name for name in without if name not in allowed]+ if unknown:+ return (f"--without accepts only optional default packages ({', '.join(allowed)}); "+ f"not {', '.join(unknown)}")return None+def _install_defaults(names: list[str], *, verify: bool) -> None:+ """Install the optional defaults; a failure warns and never fails the install.++ They are conveniences (the browser tools), not what Hermes needs to run:+ a Chromium download that fails behind a proxy must not abort an install+ whose required closure and venv are fine.+ """+ for name in names:+ if _install_names([name], verify=verify):+ print(f"⚠ optional {name} was not installed; its tools stay unavailable until "+ f"`hermes pm install {name}` succeeds", flush=True)++def _install_python_environments(extras: list[str], *, sync: bool, test_environment) -> int:"""Sync the venv and build the side test environment; return the failure count."""failed = 0@@ -330,6 +354,18 @@ def cmd_install(args) -> int:print(f"✗ {error}")return 1names = args.names if args.names or extras else source_install_packages(_lockfile().names())+ without = list(dict.fromkeys(getattr(args, "without", None) or ()))+ if without:+ from pm.defaults import record_declined++ # Persisted before anything installs: later bare installs and+ # `hermes update` read the same record, so the opt-out sticks.+ record_declined(add=without)+ defaults: list[str] = []+ if not (args.names or extras):+ from pm.defaults import default_packages++ defaults = default_packages(_lockfile().names())# Only the whole default closure verifies everything an activated shell# composes from, so only it advances the prologue's input stamps.full_closure = not (args.names or tools_only or cross_target)@@ -343,6 +379,12 @@ def cmd_install(args) -> int:tool_names = names if args.names else tool_roots(names)if _install_names(tool_names, target=cross_target, verify=not trust_recorded):return 1+ if args.names and not cross_target:+ from pm.defaults import record_declined++ # Naming a declined default is the opt-back-in: updates carry it again.+ record_declined(remove=args.names)+ _install_defaults(defaults, verify=not trust_recorded)if not cross_target and (not args.names or tools_only):from pm.install import activate@@ -745,10 +787,13 @@ def main(argv=None) -> int:p.add_argument("version", nargs="?", metavar="VERSION", help="the tool version (only with --bump)")p.set_defaults(func=cmd_lock)- p = sub.add_parser("install", help="install packages (default: all required)")+ p = sub.add_parser("install", help="install packages (default: all required + optional defaults)")p.add_argument("names", nargs="*")p.add_argument("--extra", action="append", default=[], metavar="NAME",help="enable a declared dependency extra in the venv (repeatable)")+ p.add_argument("--without", action="append", default=[], metavar="NAME",+ help="leave an optional default package (agent-browser) out of this and every later "+ "default install and update; `hermes pm install NAME` opts back in (repeatable)")p.add_argument("--tools-only", action="store_true",help="install the tool closure, put it on PATH, and stop before the venv sync")p.add_argument("--trust-recorded", action="store_true",diff --git a/pm/defaults.py b/pm/defaults.pynew file mode 100644index 00000000000..61bf92b9bcc--- /dev/null+++ b/pm/defaults.py@@ -0,0 +1,88 @@+"""Optional packages the default install carries, and the user's opt-outs.++A ``default`` package (see ``Package.default``) joins the installers' PM stage,+a bare ``hermes pm install`` and ``hermes update`` on every target it builds+for. The user can decline one (``install.sh --skip-browser``,+``install.ps1 -SkipBrowser``, ``hermes pm install --without NAME``). The choice+is recorded per installation beside PM's other install state, so a later+update or bare install never re-adds it. An explicit+``hermes pm install NAME`` clears it.++Stdlib-only apart from PM's own modules: the installers run this before any+application dependency exists.+"""++from __future__ import annotations++import json+from collections.abc import Iterable+from pathlib import Path++DECLINED_FILENAME = "declined-packages.json"+++def declined_path(project_root: Path | None = None) -> Path:+ from pm.environments import install_state_dir+ from pm.paths import repo_root++ return install_state_dir(repo_root() if project_root is None else Path(project_root)) / DECLINED_FILENAME+++def declined(project_root: Path | None = None) -> frozenset[str]:+ try:+ data = json.loads(declined_path(project_root).read_text(encoding="utf-8-sig"))+ except FileNotFoundError:+ return frozenset()+ except (OSError, ValueError) as exc:+ # Silently treating a damaged record as "nothing declined" would+ # re-add a package the user explicitly refused.+ from pm.package import InstallError++ raise InstallError("defaults", f"cannot read {declined_path(project_root)}: {exc}",+ "fix or delete the file, then retry") from exc+ names = data.get("declined") if isinstance(data, dict) else None+ return frozenset(name for name in names or () if isinstance(name, str))+++def record_declined(*, add: Iterable[str] = (), remove: Iterable[str] = (),+ project_root: Path | None = None) -> frozenset[str]:+ """Update the recorded opt-outs; returns the new set. Writes only on change."""+ from pm.filesystem import durable_write_bytes++ current = declined(project_root)+ updated = (current | set(add)) - set(remove)+ if updated != current:+ body = json.dumps({"schema": 1, "declined": sorted(updated)}, indent=2) + "\n"+ durable_write_bytes(declined_path(project_root), body.encode("utf-8"))+ return frozenset(updated)+++def default_package_names() -> list[str]:+ """Every package that may be declined: the ``default`` ones, any target."""+ from pm.registry import all_packages, get_package++ return [name for name in all_packages() if get_package(name).default and not get_package(name).internal]+++def default_packages(names: list[str], *, target: str | None = None,+ declined_names: frozenset[str] | None = None) -> list[str]:+ """The optional defaults among ``names`` this install should carry.++ Excludes targets the package has no build for (its ``gaps``) and packages+ the user declined. ``names`` is the lockfile's package list.+ """+ from pm.registry import get_package+ from pm.store import current_target++ target = current_target() if target is None else target+ refused = declined() if declined_names is None else declined_names+ selected = []+ for name in names:+ try:+ package = get_package(name)+ except KeyError:+ continue # Lockfile/definition skew mid-update; drift() skips these too.+ if package.default and not package.internal and name not in refused \+ and package.missing_reason(target) is None:+ selected.append(name)+ return selecteddiff --git a/pm/package.py b/pm/package.pyindex 9f49699a118..37ff1205af7 100644--- a/pm/package.py+++ b/pm/package.py@@ -51,6 +51,10 @@ class Package:name: unique id.deps: packages installed before this one.optional: not part of the root closure; installed on demand.+ default: an optional package the default install also carries (installers,+ bare `pm install`, `hermes update`) unless the user declined it+ (pm/defaults.py). It stays optional: a failed download warns instead of+ failing the install, and its absence never blocks PATH activation.internal: tooling PM uses inside install/build steps — never on PATHand never selected as an application root. Dependencies and explicitbuild requests can select it. node/npm are shipped runtime tools@@ -65,6 +69,7 @@ class Package:name: str = ""deps: tuple[str, ...] = ()optional: bool = False+ default: bool = Falseinternal: bool = Falseon_path: bool = Trueurl: str = ""diff --git a/pm/packages.py b/pm/packages.pyindex 559b22457f2..0e36e923b4b 100644--- a/pm/packages.py+++ b/pm/packages.py@@ -826,7 +826,15 @@ class CuaDriver(BinaryPackage):class AgentBrowser(BinaryPackage):name = "agent-browser"optional = True+ # Browser tools find agent-browser only in PM's store or on PATH (no npx+ # fallback), and their readiness check never installs it, so an install+ # without it silently loses every browser_* tool.+ # Default-install it; `install.sh --skip-browser` declines it.+ default = Truedeps = ("chromium",)+ # Termux owns its browser stack (`npm install -g agent-browser`; see+ # tools/browser_tool_install.py), and PM has no bionic Chromium to drive.+ gaps = {"linux-arm64-bionic": "Termux installs agent-browser through npm"}flatten = Trueprobe_version = Falseurl = "https://registry.npmjs.org/agent-browser/-/agent-browser-{version}.tgz"@@ -882,6 +890,8 @@ class Chromium(Package):name = "chromium"optional = Trueon_path = False+ # Neither Chrome-for-Testing nor Playwright's mirror builds for Android.+ gaps = {"linux-arm64-bionic": "no Chromium build for Android/Termux"}emulated_arch_targets = frozenset({"win32-arm64"})_CDN = "https://cdn.playwright.dev"diff --git a/tests/pm/test_install_default_closure.py b/tests/pm/test_install_default_closure.pyindex d1feeeb9829..50d464f0953 100644--- a/tests/pm/test_install_default_closure.py+++ b/tests/pm/test_install_default_closure.py@@ -23,12 +23,14 @@ import pm.cli@pytest.fixture()def install_spy(monkeypatch):- calls = {"names": None, "verified": None, "sync_extras": None, "activated": []}+ calls = {"names": None, "verified": None, "sync_extras": None, "activated": [], "fail": set()}def fake_install_names(names, target=None, *, verify=True):- calls["names"] = list(names)+ # Accumulate: optional defaults install in their own call after the+ # required closure.+ calls["names"] = [*(calls["names"] or []), *names]calls["verified"] = verify- return 0+ return len(calls["fail"] & set(names))def fake_sync_venv(extras=None, **kwargs):calls["sync_extras"] = list(extras or [])@@ -100,3 +102,40 @@ def test_a_missing_tool_blocks_the_venv_sync(install_spy, monkeypatch, capsys):assert pm.cli.cmd_install(argparse.Namespace(names=None, tools_only=False)) == 1assert install_spy["sync_extras"] is Noneassert "git: not installed or outdated" in capsys.readouterr().out+++def _bare_install(install_spy, **kwargs) -> list[str]:+ install_spy["names"] = None+ assert pm.cli.cmd_install(argparse.Namespace(names=None, tools_only=False, **kwargs)) == 0+ return install_spy["names"]+++def test_browser_tools_are_a_default_the_user_can_decline_and_restore(install_spy):+ assert "agent-browser" in _bare_install(install_spy)+ assert "agent-browser" not in _bare_install(install_spy, without=["agent-browser"])+ # The opt-out is recorded: a later bare install (the updater's shape) keeps it.+ assert "agent-browser" not in _bare_install(install_spy)+ install_spy["names"] = None+ assert pm.cli.cmd_install(argparse.Namespace(names=["agent-browser"], tools_only=False)) == 0+ assert "agent-browser" in _bare_install(install_spy)+++def test_a_failed_default_download_does_not_fail_the_install(install_spy, capsys):+ install_spy["fail"] = {"agent-browser"}+ assert "agent-browser" in _bare_install(install_spy)+ assert install_spy["sync_extras"] == ["all"]+ assert "hermes pm install agent-browser" in capsys.readouterr().out+++def test_termux_has_no_pm_browser_default():+ from pm.defaults import default_packages++ names = pm.cli._lockfile().names()+ assert "agent-browser" in default_packages(names, target="linux-x64", declined_names=frozenset())+ assert default_packages(names, target="linux-arm64-bionic", declined_names=frozenset()) == []+++def test_without_refuses_a_required_package(install_spy, capsys):+ assert pm.cli.cmd_install(argparse.Namespace(names=None, tools_only=False, without=["git"])) == 1+ assert "--without accepts only" in capsys.readouterr().out+ assert install_spy["names"] is Nonediff --git a/website/docs/reference/package-management.md b/website/docs/reference/package-management.mdindex 837460ae12c..046f6f08325 100644--- a/website/docs/reference/package-management.md+++ b/website/docs/reference/package-management.md@@ -515,7 +515,8 @@ hermes pm install chromium| Command | Effect ||---|---|-| `pm install [names...]` | Install named packages. With no names, provision required tools plus Python, put those tools on PATH, and then sync the `all` extra. |+| `pm install [names...]` | Install named packages. With no names, provision required tools plus Python, put those tools on PATH, and then sync the `all` extra. A bare install also installs the default optional tools (`agent-browser` and Chromium); a failed download of these prints a warning and does not fail the install. Naming a package you declined earlier undoes that choice. |+| `pm install --without NAME` | Do a bare install without the default optional package `NAME` (only `agent-browser`), and record that choice. Later bare installs and `hermes update` also leave it out. The installers' `--skip-browser` / `-SkipBrowser` use this. || `pm install --tools-only` | Install that tool closure and put it on PATH, then stop. The venv sync does not run. || `pm env [names...]` | Print installed packages' PM-contributed environment values as JSON. It does not install missing packages, though a cold Hermes launch may prepare its own Python runtime first. || `pm doctor` | Check installed tool identities, files, and digests against the lock. |