diff --git a/packages/agent-browser/build.ncl b/packages/agent-browser/build.ncl index b9ad2ed8a..d6a025be5 100644 --- a/packages/agent-browser/build.ncl +++ b/packages/agent-browser/build.ncl @@ -1,4 +1,4 @@ -let { standaloneTest, subsetOf, Attrs, BuildSpec, Local, OutputBin, OutputData, Source, Test, .. } = import "minimal.ncl" in +let { Attrs, BuildSpec, Local, OutputBin, OutputData, Source, Test, .. } = import "minimal.ncl" in let base = import "../base/build.ncl" in let toolchain = import "../toolchain/build.ncl" in let make = import "../make/build.ncl" in @@ -6,6 +6,7 @@ let pkgconf = import "../pkgconf/build.ncl" in let rust = import "../rust/build.ncl" in let node-lts = import "../node-lts/build.ncl" in let pnpm = import "../pnpm/build.ncl" in +let ca-certificates = import "../ca-certificates/build.ncl" in let bash = import "../bash/build.ncl" in let glibc = import "../glibc/build.ncl" in @@ -37,14 +38,14 @@ let glibc = import "../glibc/build.ncl" in # upstream changes (the pkgmgr-rs#1028 trigger), if the smaller closure matters. let chromium-bin = import "../chromium-bin/build.ncl" in -let version = "0.15.1" in +let version = "0.41.1" in { name = "agent-browser", build_deps = [ { file = "build.sh" } | Local, { url = "gs://minimal-staging-archives/vercel-labs/agent-browser/v%{version}.tar.gz", - sha256 = "c30724a5fba1beb217ca5ce5ce9eee43b596dc72efe9ac29adb9af717795b6c9", + sha256 = "b3d9d60b8a38f05e0f9b4d84d9e0b6995c21df2eb963eefb703008682a69f3bb", extract = true, strip_prefix = "agent-browser-%{version}", } | Source, @@ -56,23 +57,53 @@ let version = "0.15.1" in node-lts, pnpm, ], + # node-lts and pnpm build only the dashboard the binary embeds. The CLI is a + # native Rust binary: 0.20.0 removed the Node.js daemon (upstream #754), and + # the npm package's bin/agent-browser.js is just a launcher that picks the + # per-platform binary. So node is no longer a runtime dep and no + # node_modules ships. runtime_deps = [ - bash, - subsetOf node-lts ["node"], + bash, # the /usr/bin/agent-browser wrapper glibc, chromium-bin, + # The wrapper sets AGENT_BROWSER_USE_SYSTEM_CA=1: the CLI's own HTTPS + # (`read`, `doctor`, plugins…) reads /etc/ssl/certs instead of its + # compiled-in webpki-roots (pkgs AGENTS.md "Trust store"). + ca-certificates, ], cmd = "./build.sh", outputs = { + # Wrapper: sets AGENT_BROWSER_EXECUTABLE_PATH / AGENT_BROWSER_USE_SYSTEM_CA + # defaults, then execs the binary below (see build.sh). bin = { glob = "usr/bin/agent-browser" } | OutputBin, + # The binary (with the dashboard, axe-core and the CDP protocol compiled + # in) and the skills/ + skill-data/ trees it serves via `agent-browser + # skills` and the MCP `skills_*` tools. It finds them relative to its own + # canonical path, so they must stay beside bin/. libexec = { glob = "usr/libexec/agent-browser/**", allow_executable = true } | OutputData, + licenses = { glob = "usr/share/licenses/agent-browser/**" } | OutputData, }, attrs = { upstream_version = version, - license_spdx = "Apache-2.0", + # The binary compiles in more than agent-browser's own Apache-2.0 code + # (checked for 0.41.1; dual-licensed parts counted at MIT/Apache-2.0): + # MPL-2.0 axe-core 4.12.1 (cli/src/native/a11y/axe.min.js, include_str!), + # and the option-ext crate (via dirs) + # MIT, ISC axe-core's bundled third-party code (LICENSE-axe-core-THIRD-PARTY.txt); + # React DevTools installHook.js (cli/src/native/react) + # BSD-3-Clause Chrome DevTools Protocol JSON (cli/cdp-protocol, codegen in build.rs); + # subtle, exr, ravif crates + # OFL-1.1 Geist, which next/font self-hosts into the embedded dashboard + # dashboard JS next, react, radix-ui, ai, streamdown, d3, ... (MIT, ISC, Apache-2.0, + # BSD-3-Clause) + # Rust crates (cli/Cargo.lock) mostly MIT OR Apache-2.0, plus ISC (ring, + # rustls-webpki, untrusted), Unicode-3.0 (icu_*, zerovec, ...), + # BSD-2-Clause (rav1e), Zlib (zlib-rs, foldhash) and + # CDLA-Permissive-2.0 (webpki-roots' root list) + license_spdx = "Apache-2.0 AND MPL-2.0 AND MIT AND ISC AND BSD-2-Clause AND BSD-3-Clause AND Unicode-3.0 AND Zlib AND CDLA-Permissive-2.0 AND OFL-1.1", source_provenance = { category = 'GithubRepo, owner = "vercel-labs", @@ -82,30 +113,82 @@ let version = "0.15.1" in } | Attrs, tests = { - smoketest = standaloneTest "/bin/agent-browser --version", + version_check = + { + class = 'Standalone, + test_deps = [base], + cmds = [ + ["/bin/bash", "-c", "/bin/agent-browser --version | grep -qx 'agent-browser %{version}'"], + ], + } | Test, + # The skills lookup is relative to the binary's canonical path + # (skills.rs find_package_root): a layout change breaks it silently, so + # list them and require the bundled `core` skill. + skills = + { + class = 'Standalone, + test_deps = [base], + cmds = [ + ["/bin/bash", "-c", "/bin/agent-browser skills list | grep -qw core"], + ["/bin/bash", "-c", "/bin/agent-browser skills get core | grep -q agent-browser"], + ], + } | Test, + # No Node runtime or node_modules ships any more; the embedded code's + # licence texts do. + layout = + { + class = 'Standalone, + test_deps = [base], + cmds = [ + ["/bin/bash", "-c", "test ! -e /usr/libexec/agent-browser/node_modules && test ! -e /usr/bin/node"], + ["/bin/bash", "-c", "grep -q 'Mozilla Public License' /usr/share/licenses/agent-browser/LICENSE-axe-core.txt"], + ["/bin/bash", "-c", "test -s /usr/share/licenses/agent-browser/LICENSE-axe-core-THIRD-PARTY.txt"], + ], + } | Test, + # The real dashboard export is embedded, not cli/build.rs's placeholder. + dashboard_embedded = + { + class = 'Standalone, + test_deps = [base], + cmds = [ + ["/bin/bash", "-c", "grep -qa 'Observability dashboard for agent-browser' /usr/libexec/agent-browser/bin/agent-browser"], + ["/bin/bash", "-c", "! grep -qa 'Dashboard not built' /usr/libexec/agent-browser/bin/agent-browser"], + ], + } | Test, open_check = { class = 'Standalone, test_deps = [base], cmds = [ - # End-to-end: drive `agent-browser open` against a data: URL - # and assert the page title appears in stdout. This exercises - # the full path — Rust CLI launches the TS daemon, daemon - # spawns chromium via /bin/chromium, navigates, returns - # title. - ["/bin/bash", "-c", "/bin/agent-browser open 'data:text/html,agent-browser-open-ok' | grep -q agent-browser-open-ok"], + # End-to-end: the CLI starts its native daemon, which launches + # chromium-bin's /usr/bin/chromium headless (the wrapper's + # AGENT_BROWSER_EXECUTABLE_PATH), navigates to a data: URL, and + # prints the page title. + # TEST-ONLY --no-sandbox: the build-bot's test sandbox has no + # unprivileged user namespaces, so Chromium aborts with "No usable + # sandbox!" (pkgs#1269 build-bot run, both arches). chromium-bin's own + # launch test does the same. The shipped wrapper keeps Chromium's + # sandbox; AGENT_BROWSER_ARGS (comma-separated launch args, cli + # flags.rs) is set only inside these test shells. + ["/bin/bash", "-c", "export AGENT_BROWSER_ARGS=--no-sandbox,--disable-dev-shm-usage; /bin/agent-browser open 'data:text/html,agent-browser-open-ok' | grep -q agent-browser-open-ok"], + # A follow-up command reaches the same daemon and page. One shell: + # the daemon does not outlive a test command. + ["/bin/bash", "-c", "set -o pipefail; export AGENT_BROWSER_ARGS=--no-sandbox,--disable-dev-shm-usage; /bin/agent-browser open 'data:text/html,agent-browser-reuse-ok' >/dev/null && /bin/agent-browser get title | grep -q agent-browser-reuse-ok; rc=$?; /bin/agent-browser close >/dev/null; exit $rc"], ], } | Test, # CVE-2026-111943: the daemon must launch chromium-bin's full browser, # which reads the CADistrustedCertificates policy. headless-shell cannot - # (see the comment at the chromium-bin import). + # (see the comment at the chromium-bin import). And the CLI's own HTTPS + # must use the system store, not its compiled-in webpki-roots. distrust_policy_wired = { class = 'Standalone, test_deps = [base], cmds = [ - ["/bin/bash", "-c", "grep -qF -- '--executable-path /usr/bin/chromium \"' /usr/bin/agent-browser"], + ["/bin/bash", "-c", "grep -qF 'AGENT_BROWSER_EXECUTABLE_PATH:-/usr/bin/chromium}' /usr/bin/agent-browser"], + ["/bin/bash", "-c", "grep -qF 'AGENT_BROWSER_USE_SYSTEM_CA:-1}' /usr/bin/agent-browser"], ["/bin/bash", "-c", "grep -q CADistrustedCertificates /etc/chromium/policies/managed/ca-distrusted-certificates.json"], + ["/bin/bash", "-c", "test -s /etc/ssl/certs/ca-certificates.crt"], ], } | Test, }, diff --git a/packages/agent-browser/build.sh b/packages/agent-browser/build.sh index 12d012be1..ca4703319 100755 --- a/packages/agent-browser/build.sh +++ b/packages/agent-browser/build.sh @@ -1,74 +1,107 @@ #!/bin/sh -set -e +set -eu -# pnpm 11 migration: strictDepBuilds now defaults to true, so unreviewed -# dependency build scripts (esbuild/geckodriver/…) are a hard error -# (ERR_PNPM_IGNORED_BUILDS) rather than a warning — but this build deliberately -# skips them (`--ignore-scripts`; the daemon ships a prebuilt binary), so demote -# it back to a warning. Also disable the pre-script deps check, which otherwise -# reinstalls before `pnpm build` and re-runs the husky postinstall (which needs -# a `.git` the source tarball doesn't have). +# agent-browser >= 0.20 is a native Rust CLI (upstream #754). The npm package's +# bin/agent-browser.js is only a launcher that picks the per-platform binary +# (and scripts/postinstall.js downloads one), so we build the binary from +# source and ship it on its own: no node, no node_modules at runtime. +# +# Build order mirrors upstream's `pnpm run build:source`: +# 1. the dashboard (Next.js static export, packages/dashboard/out), which +# cli/src/native/stream/http.rs embeds with rust-embed at compile time; +# without it cli/build.rs embeds a "Dashboard not built" placeholder; +# 2. the Rust CLI. + +# pnpm 11+: strictDepBuilds defaults to true. We install with --ignore-scripts +# (no dependency build script is needed for a static export), so keep the +# skipped builds a warning. Also skip the pre-script deps check, which would +# reinstall and re-run lifecycle scripts before `pnpm build`. export PNPM_CONFIG_STRICT_DEP_BUILDS=false export PNPM_CONFIG_VERIFY_DEPS_BEFORE_RUN=false - -# pnpm 12 places its default store on the project's own volume when it cannot -# hardlink into its home store, and in the sandbox /build is a separate mount, -# so the store lands in node_modules/.pnpm-store — which the `cp -R node_modules` -# below would ship. Pin it outside the build tree, where pnpm 11 put it. +# Keep pnpm's store out of the source tree (pnpm 12 otherwise puts it in +# node_modules/.pnpm-store when /build is a separate mount). export PNPM_CONFIG_STORE_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/pnpm/store" +# package.json pins "packageManager": "pnpm@11.1.3". Build with our pnpm +# (engines: pnpm >= 11) instead of letting it download that one at build time +# (pmOnFail is pnpm 11+'s setting; manage-package-manager-versions pnpm 10's). +export PNPM_CONFIG_PM_ON_FAIL=ignore +export PNPM_CONFIG_MANAGE_PACKAGE_MANAGER_VERSIONS=false +# No Next.js telemetry from the build. +export NEXT_TELEMETRY_DISABLED=1 + +# --- 1. dashboard ----------------------------------------------------------- +# Only the dashboard's dependencies (the workspace also holds docs and the +# @agent-browser/{eve,sandbox} packages, none of which ship). Lockfile-pinned. +pnpm install --frozen-lockfile --ignore-scripts --filter dashboard + +# Next.js bakes a random (nanoid) buildId into out/_next/static// and +# every page's RSC payload; pin it so the embedded dashboard, and with it the +# binary, is reproducible (same fix as packages/next's bundle-analyzer). +sed -i 's/output: "export",/output: "export", generateBuildId: async () => "agent-browser-reproducible",/' \ + packages/dashboard/next.config.ts +grep -q 'agent-browser-reproducible' packages/dashboard/next.config.ts \ + || { echo "ERROR: dashboard generateBuildId repro patch did not apply (next.config.ts changed upstream)" >&2; exit 1; } + +# next/font/google (layout.tsx's Geist) downloads the font at build time and +# self-hosts it in out/_next/static/media; the build has network via rust's +# `needs`. +(cd packages/dashboard && pnpm build) +test -f packages/dashboard/out/index.html +if grep -q 'Dashboard not built' packages/dashboard/out/index.html; then + echo "ERROR: dashboard export is the placeholder" >&2 + exit 1 +fi +# --- 2. Rust CLI ------------------------------------------------------------ export CC=gcc export LD=gcc export RUSTFLAGS="-C linker=gcc --remap-path-prefix=$(pwd)=/builddir --remap-path-prefix=$HOME/.cargo=/cargo -C codegen-units=1" export CONST_RANDOM_SEED=0 # pin ahash/const-random compile-time seed -# Install JS deps (skip postinstall which downloads pre-built binary). -# Use the hoisted node-linker so node_modules is a flat, self-contained -# tree — pnpm's default symlinked layout into .pnpm/ doesn't survive -# being copied into $OUTPUT_DIR and causes runtime ERR_MODULE_NOT_FOUND -# on transitive deps (e.g. jszip). -pnpm install --ignore-scripts --config.node-linker=hoisted +cargo build --release --locked --manifest-path cli/Cargo.toml -# Build TypeScript daemon -pnpm build +# --- install ---------------------------------------------------------------- +# Layout matches the npm package, which the binary's lookups assume: +# skills.rs find_package_root(): /../skill-data/core/SKILL.md +# stream/chat.rs find_skills_dir(): walks up from the exe to skills/agent-browser/SKILL.md +# Both canonicalize current_exe(), so the real binary must live inside the tree. +LIBEXEC=$OUTPUT_DIR/usr/libexec/agent-browser +install -d "$LIBEXEC/bin" "$OUTPUT_DIR/usr/bin" "$OUTPUT_DIR/usr/share/licenses/agent-browser" +install -m 0755 cli/target/release/agent-browser "$LIBEXEC/bin/agent-browser" +cp -R skills skill-data "$LIBEXEC/" +test -f "$LIBEXEC/skill-data/core/SKILL.md" +test -f "$LIBEXEC/skills/agent-browser/SKILL.md" -# Build Rust CLI -cargo build --release --manifest-path cli/Cargo.toml +# Licences of what the binary embeds: axe-core (MPL-2.0, include_str! of +# axe.min.js) with its third-party notices, as upstream's package.json ships +# them; React DevTools' installHook.js (MIT, its notice is in the file). +install -m 0644 LICENSE "$OUTPUT_DIR/usr/share/licenses/agent-browser/LICENSE" +install -m 0644 cli/src/native/a11y/LICENSE-axe-core.txt \ + cli/src/native/a11y/LICENSE-axe-core-THIRD-PARTY.txt \ + "$OUTPUT_DIR/usr/share/licenses/agent-browser/" -# Determine platform -case $(uname -m) in - x86_64) PLATFORM="linux-x64" ;; - aarch64) PLATFORM="linux-arm64" ;; -esac - -mkdir -p bin -cp cli/target/release/agent-browser bin/agent-browser-${PLATFORM} - -# Chromium is provided by the chromium-bin pkg as a runtime dep. We pass its -# binary to the daemon via --executable-path; no need to ship our own copy or -# run `npx playwright install`. It must be chromium-bin's `chromium`, not -# chromium-headless-shell: only the full browser reads the -# CADistrustedCertificates policy (CVE-2026-111943; see build.ncl). +# The wrapper sets two defaults; a caller's own env var wins, and so does a +# command-line flag. # -# Upstream's own default is to fetch Chrome for Testing's `chrome` bundle, -# which we may not redistribute (inbox#284). Passing an explicit -# --executable-path is what stops `agent-browser install` ever reaching for -# it, so this flag is load-bearing for licensing, not just convenience. - -install -d $OUTPUT_DIR/usr/bin -install -d $OUTPUT_DIR/usr/libexec/agent-browser - -# pnpm bakes wall-clock timestamps into its node_modules state files -# (.modules.yaml `prunedAt`, .pnpm-workspace-state-v1.json `lastValidatedTimestamp`) -# — non-deterministic and not needed at runtime. Drop them before packaging. -rm -f node_modules/.modules.yaml node_modules/.pnpm-workspace-state-v1.json -test ! -e node_modules/.pnpm-store \ - || { echo "agent-browser: the pnpm store is inside node_modules and would ship" >&2; exit 1; } -cp -R dist bin node_modules package.json $OUTPUT_DIR/usr/libexec/agent-browser/ - -cat > $OUTPUT_DIR/usr/bin/agent-browser << EOF +# AGENT_BROWSER_EXECUTABLE_PATH -> chromium-bin's full browser, NOT +# chromium-headless-shell: only the full browser reads the +# CADistrustedCertificates policy (CVE-2026-111943; see build.ncl). The env +# var (rather than the old prepended --executable-path) also reaches the +# paths that never parse the flag: the daemon's own auto-launch +# (native/actions.rs), `mcp` mode, and `doctor`. Upstream's fallback is to +# look for google-chrome/chromium on PATH or a Chrome for Testing download +# from `agent-browser install`, which we may not redistribute (inbox#284). +# +# AGENT_BROWSER_USE_SYSTEM_CA=1 -> the CLI's own HTTPS (`read`, which fetches +# arbitrary URLs without a browser, plus `doctor`, `install`, `upgrade`, +# `chat`, plugins) verifies against /etc/ssl/certs (ca-certificates) instead +# of the webpki-roots bundle compiled into the binary (pkgs AGENTS.md "Do not +# embed a trust store"; the locked webpki-roots 1.0.5 predates the +# CVE-2026-111943 emSign distrust, RUSTSEC-2026-0381). +cat > "$OUTPUT_DIR/usr/bin/agent-browser" << 'EOF' #!/bin/bash -exec /usr/libexec/agent-browser/bin/agent-browser-${PLATFORM} \\ - --executable-path /usr/bin/chromium "\$@" +export AGENT_BROWSER_EXECUTABLE_PATH="${AGENT_BROWSER_EXECUTABLE_PATH:-/usr/bin/chromium}" +export AGENT_BROWSER_USE_SYSTEM_CA="${AGENT_BROWSER_USE_SYSTEM_CA:-1}" +exec /usr/libexec/agent-browser/bin/agent-browser "$@" EOF -chmod +x $OUTPUT_DIR/usr/bin/agent-browser +chmod 0755 "$OUTPUT_DIR/usr/bin/agent-browser"