A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
publish musl and baseline linux archives so linux stops falling back to node (#2344)
ktebe299ee599d
diff --git a/.github/workflows/build-binaries.yml b/.github/workflows/build-binaries.ymlindex b382289117..a291feaf34 100644--- a/.github/workflows/build-binaries.yml+++ b/.github/workflows/build-binaries.yml@@ -189,7 +189,7 @@ jobs:- name: Verify and stage standalone binariesrun: |- for platform in darwin-arm64 darwin-x64 linux-arm64 linux-x64; do+ for platform in $(node scripts/release-platforms.mjs); dosource_dir="standalone-artifacts/standalone-$platform"(cd "$source_dir" && sha256sum --check SHA256SUMS)destination="packages/coding-agent/binaries/$platform"diff --git a/.github/workflows/standalone-binaries.yml b/.github/workflows/standalone-binaries.ymlindex 48545dfcf6..9cca2133bd 100644--- a/.github/workflows/standalone-binaries.yml+++ b/.github/workflows/standalone-binaries.yml@@ -20,14 +20,26 @@ jobs:fail-fast: falsematrix:include:+ # Darwin builds must be compiled and signed on their own architecture.- platform: darwin-arm64runner: macos-15- platform: darwin-x64runner: macos-15-intel+ # Bun cross-compiles musl and baseline targets, so each Linux variant is+ # built on the runner whose architecture it targets and then executed on+ # that architecture: glibc archives on the runner, musl archives in Alpine.- platform: linux-arm64runner: ubuntu-24.04-arm+ - platform: linux-arm64-musl+ runner: ubuntu-24.04-arm- platform: linux-x64runner: ubuntu-24.04+ - platform: linux-x64-baseline+ runner: ubuntu-24.04+ - platform: linux-x64-musl+ runner: ubuntu-24.04+ - platform: linux-x64-musl-baseline+ runner: ubuntu-24.04steps:- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0with:@@ -62,7 +74,7 @@ jobs:- name: Compile standalone applicationworking-directory: source/packages/coding-agent- run: npm run build:binary+ run: npm run build:binary -- --platform ${{ matrix.platform }}- name: Assemble native archiveworking-directory: source@@ -75,10 +87,43 @@ jobs:- name: Remove the build paths from the test machinerun: mv "$GITHUB_WORKSPACE/source" "$RUNNER_TEMP/standalone-source"+ # A musl archive cannot execute on the glibc runner that cross-compiled it, and+ # the checkout's node_modules are glibc builds, so Vitest cannot move into Alpine+ # either. musl archives are executed by the Alpine step below instead.- name: Test extracted application without JavaScript runtimes on PATH+ if: ${{ !contains(matrix.platform, 'musl') }}working-directory: ${{ runner.temp }}/standalone-source/packages/coding-agentrun: npx tsx ../../node_modules/vitest/dist/cli.js --run test/release-signatures.test.ts test/compiled-artifact.test.ts test/native-installer.test.ts test/native-probe-timeout.test.ts+ # Real musl execution evidence: Alpine has no glibc and no JavaScript runtime.+ # Bun's musl executables link against libstdc++, which Alpine does not preinstall.+ - name: Test extracted application on Alpine without JavaScript runtimes+ if: ${{ contains(matrix.platform, 'musl') }}+ env:+ TARGET_PLATFORM: ${{ matrix.platform }}+ run: |+ version=$(node -p "require('$RUNNER_TEMP/standalone-source/package.json').version")+ docker run --rm --init \+ --volume "$RUNNER_TEMP/standalone:/archives:ro" \+ --env "ARCHIVE=prime-agent-$version-$TARGET_PLATFORM.tar.gz" \+ --env "VERSION=$version" \+ --env DO_NOT_TRACK=1 \+ --env PI_OFFLINE=1 \+ --env PRIME_AGENT_INSTALL_UV=0 \+ alpine:3.21 sh -eu -c '+ apk add --no-cache libstdc++ > /dev/null+ for runtime in node npm bun deno; do+ if command -v "$runtime" >/dev/null 2>&1; then+ echo "A JavaScript runtime must not be present: $runtime" >&2+ exit 1+ fi+ done+ mkdir /application+ tar -xzf "/archives/$ARCHIVE" -C /application+ test "$(timeout 60 /application/prime-agent --version)" = "$VERSION"+ timeout 60 /application/prime-agent --help > /dev/null+ '+- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7with:name: standalone-${{ matrix.platform }}diff --git a/install.sh b/install.shindex 019c5b8181..29ccac9926 100755--- a/install.sh+++ b/install.sh@@ -61,6 +61,8 @@ prime_agent_animation_frame=0prime_agent_native_stage=prime_agent_native_lock=prime_agent_allow_insecure_http=0+# Tests point platform detection at a fake /proc and /lib without needing a container.+prime_agent_native_sysroot="${PRIME_AGENT_NATIVE_SYSROOT_FOR_TESTS:-}"main() {if [ "${1:-}" = --rollback ]; then@@ -1711,7 +1713,31 @@ Finalizing npm install."fi}+# Supported glibc releases carry no libc suffix; musl builds are published separately.+prime_agent_native_glibc() {+ native_glibc_version=$(getconf GNU_LIBC_VERSION 2>/dev/null) || return 1+ printf '%s\n' "$native_glibc_version" |+ awk '$1 == "glibc" { split($2, v, "."); if (v[1] > 2 || (v[1] == 2 && v[2] >= 17)) ok=1 } END { exit !ok }'+}++# Alpine and other musl distributions ship the loader under a fixed name; `ldd`+# without arguments prints its musl banner and is the fallback for stripped images.+prime_agent_native_musl() {+ for native_musl_loader in "$prime_agent_native_sysroot"/lib/ld-musl-*.so.1; do+ [ -e "$native_musl_loader" ] && return 0+ done+ ldd 2>&1 | grep -q musl+}++# Bun's default x64 build needs AVX2; hosts without it need the baseline build.+# An unreadable CPU inventory selects baseline, which runs on every x86-64 CPU.+prime_agent_native_avx2() {+ awk '/^flags[[:space:]]*:/ { for (i = 3; i <= NF; i++) if ($i == "avx2") found = 1 } END { exit !found }' \+ "$prime_agent_native_sysroot/proc/cpuinfo" 2>/dev/null+}+prime_agent_native_platform() {+ native_libc_suffix=case "$(uname -s)" inDarwin)native_os_version=$(sw_vers -productVersion) || return 1@@ -1720,15 +1746,26 @@ prime_agent_native_platform() {native_os=darwin;;Linux)- native_libc=$(getconf GNU_LIBC_VERSION 2>/dev/null) || return 1- printf '%s\n' "$native_libc" | awk '$1 == "glibc" { split($2, v, "."); if (v[1] > 2 || (v[1] == 2 && v[2] >= 17)) ok=1 } END { exit !ok }' || return 1native_os=linux+ if prime_agent_native_glibc; then+ native_libc_suffix=+ elif prime_agent_native_musl; then+ native_libc_suffix=-musl+ else+ return 1+ fi;;*) return 1 ;;esaccase "$(uname -m)" in- arm64|aarch64) printf '%s-arm64' "$native_os" ;;- x86_64|amd64) printf '%s-x64' "$native_os" ;;+ arm64|aarch64) printf '%s-arm64%s' "$native_os" "$native_libc_suffix" ;;+ x86_64|amd64)+ if [ "$native_os" = linux ] && ! prime_agent_native_avx2; then+ printf '%s-x64%s-baseline' "$native_os" "$native_libc_suffix"+ else+ printf '%s-x64%s' "$native_os" "$native_libc_suffix"+ fi+ ;;*) return 1 ;;esac}@@ -1759,6 +1796,22 @@ prime_agent_native_cleanup() {rmdir "$prime_agent_native_lock"fiprime_agent_native_lock=+ prime_agent_native_discard_adopted_root+}++# A first install that never activated a release must not keep the ownership+# marker: the next run would find a managed tree holding no executable. Only a+# root this run created, still empty apart from what this run created, is given up.+prime_agent_native_discard_adopted_root() {+ [ "${prime_agent_native_root_adopted:-0}" = 1 ] || return 0+ prime_agent_native_root_adopted=0+ [ -n "${native_root:-}" ] || return 0+ if [ -e "$native_root/bin/prime-agent" ] || [ -L "$native_root/bin/prime-agent" ]; then return 0; fi+ [ -z "$(ls -A "$native_root" 2>/dev/null | grep -vxE '\.managed|bin|releases' || :)" ] || return 0+ rmdir "$native_root/bin" "$native_root/releases" 2>/dev/null || :+ if [ -e "$native_root/bin" ] || [ -e "$native_root/releases" ]; then return 0; fi+ rm -f "$native_root/.managed"+ rmdir "$native_root" 2>/dev/null || :}prime_agent_native_prepare_root() {@@ -1769,6 +1822,7 @@ prime_agent_native_prepare_root() {if [ -L "$native_root/.managed" ] || [ -L "$native_root/releases" ] || [ -L "$native_root/bin" ]; thenprintf 'error: managed installation directories must not be symlinks.\n' >&2; exit 1fi+ prime_agent_native_root_adopted=0if [ -e "$native_root/.managed" ]; then[ "$(cat "$native_root/.managed")" = prime-agent-native-v1 ] || {printf 'error: unrecognized installation owner in %s.\n' "$native_root" >&2; exit 1;@@ -1776,6 +1830,9 @@ prime_agent_native_prepare_root() {elif [ -n "$(ls -A "$native_root")" ]; thenprintf 'error: refusing to take ownership of nonempty directory %s.\n' "$native_root" >&2exit 1+ else+ # Ownership taken now is given back if this run never activates a release.+ prime_agent_native_root_adopted=1fi# Never steal a lock: even stale-lock recovery can race with another installer.if ! mkdir "$native_root/.install-lock" 2>/dev/null; then@@ -1849,13 +1906,20 @@ prime_agent_native_parse_target() {case "$native_parsed_unique" in *[!0-9A-Za-z]*) return 1 ;; esacfinative_parsed_prefix=${native_parsed_name%-"$native_parsed_digest_suffix"}+ # Longest platform suffix first: a shorter arm matches the prefix of a longer+ # platform name, so `<version>-linux-x64-musl` must not be read as `linux-x64`.case "$native_parsed_prefix" in- *-darwin-arm64) native_parsed_version=${native_parsed_prefix%-darwin-arm64}; native_parsed_platform=darwin-arm64 ;;- *-darwin-x64) native_parsed_version=${native_parsed_prefix%-darwin-x64}; native_parsed_platform=darwin-x64 ;;- *-linux-arm64) native_parsed_version=${native_parsed_prefix%-linux-arm64}; native_parsed_platform=linux-arm64 ;;- *-linux-x64) native_parsed_version=${native_parsed_prefix%-linux-x64}; native_parsed_platform=linux-x64 ;;+ *-linux-x64-musl-baseline) native_parsed_platform=linux-x64-musl-baseline ;;+ *-linux-x64-musl) native_parsed_platform=linux-x64-musl ;;+ *-linux-x64-baseline) native_parsed_platform=linux-x64-baseline ;;+ *-linux-arm64-musl) native_parsed_platform=linux-arm64-musl ;;+ *-darwin-arm64) native_parsed_platform=darwin-arm64 ;;+ *-darwin-x64) native_parsed_platform=darwin-x64 ;;+ *-linux-arm64) native_parsed_platform=linux-arm64 ;;+ *-linux-x64) native_parsed_platform=linux-x64 ;;*) return 1 ;;esac+ native_parsed_version=${native_parsed_prefix%-"$native_parsed_platform"}printf '%s\n' "$native_parsed_version" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$' || return 1native_parsed_dir="$native_root/releases/$native_parsed_name"}@@ -1926,6 +1990,24 @@ prime_agent_native_probe() (exit "$native_probe_status")+# Bun's musl executables link against libstdc++, which Alpine does not preinstall.+# The loader either names the library or reports a wall of C++ relocation failures.+prime_agent_native_probe_missing_libstdcxx() {+ native_probe_log="$1"+ [ -f "$native_probe_log" ] || return 1+ grep -q 'libstdc++\.so\.6' "$native_probe_log" && return 0+ # musl names no library when every C++ runtime symbol is unresolved, so match+ # the mangled and Itanium ABI names it does report.+ grep -Eq 'Error relocating .*: (_Z|__cxa_|__dynamic_cast|__once_proxy)[A-Za-z0-9_]*: symbol not found' "$native_probe_log"+}++# One actionable line beats sixty relocation errors the user cannot act on.+prime_agent_native_report_missing_libstdcxx() {+ printf 'error: the compiled executable needs the libstdc++ runtime library, which is missing here.\n' >&2+ printf 'Install it and run this installer again (Alpine: apk add --no-cache libstdc++).\n' >&2+ printf 'To install the Node.js build instead, set PRIME_AGENT_INSTALL_METHOD=node.\n' >&2+}+prime_agent_native_verify_release_target() {native_verify_target="$1"native_verify_label="$2"@@ -2154,6 +2236,12 @@ prime_agent_install_native() {[ -f "$native_extracted/$native_asset" ] || { printf 'error: missing archive asset: %s\n' "$native_asset" >&2; exit 1; }doneif ! prime_agent_native_probe "$native_extracted/prime-agent" --version >"$prime_agent_native_stage/version" 2>"$prime_agent_native_stage/probe.log"; then+ # A missing libstdc++ is one package away, so name it instead of downloading Node.+ if prime_agent_native_probe_missing_libstdcxx "$prime_agent_native_stage/probe.log"; then+ prime_agent_native_cleanup+ prime_agent_native_report_missing_libstdcxx+ exit 1+ ficat "$prime_agent_native_stage/probe.log" >&2prime_agent_native_cleanupif [ "${PRIME_AGENT_INSTALL_METHOD:-auto}" = auto ]; thendiff --git a/packages/coding-agent/.changes/native-platform-matrix.md b/packages/coding-agent/.changes/native-platform-matrix.mdnew file mode 100644index 0000000000..7343e9818c--- /dev/null+++ b/packages/coding-agent/.changes/native-platform-matrix.md@@ -0,0 +1 @@+- Added musl and baseline compiled releases so Linux hosts stop falling back to the Node installation. Releases now publish `linux-arm64-musl`, `linux-x64-baseline`, `linux-x64-musl`, and `linux-x64-musl-baseline` alongside the existing four archives. The installer detects musl (Alpine) and x86-64 CPUs without AVX2 and downloads the matching archive. musl archives need `libstdc++` (`apk add --no-cache libstdc++` on Alpine); when it is missing, the installer now names that package and stops instead of falling back to the Node installation, and a failed first install no longer leaves an empty installation directory behind.diff --git a/packages/coding-agent/docs/standalone-binaries.md b/packages/coding-agent/docs/standalone-binaries.mdindex 99eda39913..d99aa3a0ab 100644--- a/packages/coding-agent/docs/standalone-binaries.md+++ b/packages/coding-agent/docs/standalone-binaries.md@@ -1,6 +1,6 @@# Standalone binaries-The macOS and Linux release archives contain `prime-agent` and its support files. Normal application execution does not require Node, npm, or Bun. Keep the archive contents together: moving only the executable breaks asset and Python runtime discovery. Linux archives target glibc; Alpine/musl and Windows are outside this distribution.+The macOS and Linux release archives contain `prime-agent` and its support files. Normal application execution does not require Node, npm, or Bun. Keep the archive contents together: moving only the executable breaks asset and Python runtime discovery. Linux archives cover glibc and musl (Alpine), on ARM64 and x64, plus baseline x64 builds for CPUs without AVX2. Windows is outside this distribution.On macOS, use the published installer:@@ -10,7 +10,20 @@ curl --proto '=https' --proto-redir '=https' -fsSL https://app.primeintellect.aiThe current macOS archives are not Developer ID signed or notarized. A browser-downloaded archive may retain quarantine metadata and be blocked by Gatekeeper, so manual macOS archive installation is not supported yet. Do not bypass Gatekeeper; use the installer until signed and notarized downloads are available.-On Linux, download `prime-agent-<version>-<platform>.tar.gz` and `SHA256SUMS` over HTTPS from the same release. Platforms are `linux-arm64` and `linux-x64`. Check the selected archive's SHA-256 against that inventory, extract it into its own directory, and run `./prime-agent --help`.+On Linux, download `prime-agent-<version>-<platform>.tar.gz` and `SHA256SUMS` over HTTPS from the same release. Platforms are:++| Platform | Host |+| --- | --- |+| `linux-arm64` | glibc 2.17+, ARM64 |+| `linux-arm64-musl` | musl (Alpine), ARM64 |+| `linux-x64` | glibc 2.17+, x64 with AVX2 |+| `linux-x64-baseline` | glibc 2.17+, x64 without AVX2 |+| `linux-x64-musl` | musl (Alpine), x64 with AVX2 |+| `linux-x64-musl-baseline` | musl (Alpine), x64 without AVX2 |++Bun's default x64 build requires AVX2, so hosts without it need the `baseline` archive; `grep -q avx2 /proc/cpuinfo` answers that question. Check the selected archive's SHA-256 against the release inventory, extract it into its own directory, and run `./prime-agent --help`.++musl archives link against `libstdc++`, which Alpine does not preinstall. Run `apk add --no-cache libstdc++` first; without it the executable cannot start. The installer recognizes that loader failure, names the package, and stops instead of downloading the much larger Node installation; set `PRIME_AGENT_INSTALL_METHOD=node` to take the Node route anyway.The Python tool uses the existing managed CPython setup. Its first use requires uv and network access to install Python and Python dependencies. The archive includes the matching `prime-agent-runtime` sources and built-in Python skills. It contains no prebuilt virtual environment or `node_modules` directory. External tools and extension-specific dependencies retain their own requirements.@@ -27,7 +40,7 @@ npm run build:binarynpm run build:binary -- --platform all```-The first command builds the native platform; the second cross-compiles all four targets. A single target can also be selected with `--platform linux-arm64`. Both commands compile the workspace TypeScript packages using the committed model catalog, then bundle the existing Bun CLI entry. They do not install dependencies or change the lockfile. Output goes to `packages/coding-agent/binaries/<platform>/`.+The first command builds the host platform; the second cross-compiles every release target listed in `scripts/release-platforms.mjs`. A single target can also be selected with `--platform linux-x64-musl`. Both commands compile the workspace TypeScript packages using the committed model catalog, then bundle the existing Bun CLI entry. They do not install dependencies or change the lockfile. Output goes to `packages/coding-agent/binaries/<platform>/`.Assemble local archives from the repository root:@@ -64,13 +77,15 @@ npx tsx ../../node_modules/vitest/dist/cli.js --run test/compiled-artifact.test.The suite extracts outside the checkout, creates isolated homes and a PATH without JavaScript runtimes, and exercises provider requests against a local HTTP/2 server, extension and skill loading, Photon image resizing, HTML export, RPC, managed Python, and daemon shutdown. It never uses real provider credentials. Python bootstrap requires network access. Other tests skip this suite when `PRIME_AGENT_TEST_ARCHIVE` is unset.-CI builds and tests natively on all four target platforms. Before testing, it moves the build checkout so absolute build-time paths and its original `node_modules` cannot satisfy missing runtime files. Cross-compilation alone is not native execution evidence.+CI builds each release target on a runner of the same architecture and executes it there. Before testing, it moves the build checkout so absolute build-time paths and its original `node_modules` cannot satisfy missing runtime files. Cross-compilation alone is not native execution evidence.++glibc and baseline archives run the Vitest suites directly on the runner. A musl archive cannot run on the glibc runner that cross-compiled it, and the checkout's `node_modules` are glibc builds, so Vitest cannot follow it into Alpine. Those archives are instead extracted and executed inside an Alpine container on the same runner, with no JavaScript runtime present.-The release workflow consumes those tested artifacts, adds the stable or beta package version, and includes all four archives in the existing aggregate `SHA256SUMS`. Existing npm tarballs and manifest fields remain. The `binaries` array adds `{ platform, file, sha256 }` entries; each file lives under `releases/v<version>/`. Stable/beta pointers retain their existing routing. Production and beta uploads use the same archives for GitHub and R2.+The release workflow consumes those tested artifacts, adds the stable or beta package version, and includes every platform archive in the existing aggregate `SHA256SUMS`. Existing npm tarballs and manifest fields remain. The `binaries` array adds `{ platform, file, sha256 }` entries; each file lives under `releases/v<version>/`. Stable/beta pointers retain their existing routing. Production and beta uploads use the same archives for GitHub and R2.## Installation-The published installer defaults to the compiled archive on macOS 13+ and glibc Linux, on ARM64 or x64. It requires an HTTPS release base, allows redirects only to HTTPS, checks the exact release checksum, rejects unsafe archive entries, validates required assets, and runs the executable before activating it. Machines outside those targets use the existing Node installer; an executable that cannot run also falls back to Node. A failed checksum never triggers a fallback.+The published installer defaults to the compiled archive on macOS 13+, glibc 2.17+ Linux, and musl Linux, on ARM64 or x64. On x64 it reads `/proc/cpuinfo` and selects the `baseline` archive when the CPU has no AVX2; an unreadable CPU inventory also selects `baseline`, which runs on every x86-64 CPU. It requires an HTTPS release base, allows redirects only to HTTPS, checks the exact release checksum, rejects unsafe archive entries, validates required assets, and runs the executable before activating it. Machines outside those targets use the existing Node installer; an executable that cannot run also falls back to Node. A failed checksum never triggers a fallback.The archive and `SHA256SUMS` inventory are served by the same release origin. The checksum detects corruption or inconsistent content but is not an independent signature and does not protect against a compromised origin; HTTPS authentication of the configured origin is the trust boundary.@@ -116,7 +131,7 @@ Normal interruption during rollback finishes retaining the release being left. A## Coverage and recovery limits-Native CI runs the extracted archives on macOS 15 (ARM64 and x64) and Ubuntu 24.04 (ARM64 and x64). It tests installation, forced reinstall, later update, offline rollback, daemon replacement, runtime assets, RPC, and managed Python without JavaScript runtimes on the application PATH. The installer selects macOS 13+ and compatible glibc Linux, but these selection checks do not constitute execution testing on every older OS release.+Native CI runs the extracted archives on macOS 15 (ARM64 and x64), Ubuntu 24.04 (ARM64 and x64), and Alpine containers on those Ubuntu runners for the musl archives. It tests installation, forced reinstall, later update, offline rollback, daemon replacement, runtime assets, RPC, and managed Python without JavaScript runtimes on the application PATH. The installer selects macOS 13+, compatible glibc Linux, and musl Linux, but these selection checks do not constitute execution testing on every older OS release. No CI runner lacks AVX2, so `baseline` selection is covered by fixture tests against a substituted `/proc/cpuinfo` rather than by no-AVX2 hardware.Focused regressions cover migration without lifecycle scripts, incompatible existing binaries, deferred migration during internal daemon startup, competing installs and npm command handoffs, checksum/manifest failures, rollback metadata and executable-version mismatches, interrupted activation recovery, conservative release retention, and orphan staging cleanup. Normal installer hangups release the lock. A forced kill still requires confirming and clearing its stale lock before recovery can run; complete filesystem power-loss, disk-exhaustion, ACL, and network-filesystem fault testing is outside this matrix.diff --git a/packages/coding-agent/scripts/build-binary.mjs b/packages/coding-agent/scripts/build-binary.mjsindex 50333d3617..e0105792b9 100644--- a/packages/coding-agent/scripts/build-binary.mjs+++ b/packages/coding-agent/scripts/build-binary.mjs@@ -3,16 +3,17 @@ import { execFileSync } from "node:child_process";import { mkdirSync, mkdtempSync, renameSync, rmSync } from "node:fs";import { dirname, join, resolve } from "node:path";import { fileURLToPath } from "node:url";+import { releasePlatforms } from "../../../scripts/release-platforms.mjs";import { copyBinaryAssets, validateBinaryAssets } from "./copy-binary-assets.mjs";import { signMacosBinary } from "./macos-signature.mjs";const root = resolve(dirname(fileURLToPath(import.meta.url)), "../../..");const packageDir = join(root, "packages/coding-agent");-const platforms = ["darwin-arm64", "darwin-x64", "linux-arm64", "linux-x64"];+const platforms = releasePlatforms;const args = process.argv.slice(2);const platform = args.length === 0 ? `${process.platform}-${process.arch}` : args[1];if (args.length !== 0 && (args.length !== 2 || args[0] !== "--platform")) {- throw new Error("Usage: npm run build:binary -- [--platform darwin-arm64|darwin-x64|linux-arm64|linux-x64|all]");+ throw new Error(`Usage: npm run build:binary -- [--platform ${[...platforms, "all"].join("|")}]`);}if (platform !== "all" && !platforms.includes(platform)) throw new Error(`Unsupported binary platform: ${platform}`);diff --git a/packages/coding-agent/scripts/macos-signature.mjs b/packages/coding-agent/scripts/macos-signature.mjsindex 8cfa5b2f6e..e5a6de5ad9 100644--- a/packages/coding-agent/scripts/macos-signature.mjs+++ b/packages/coding-agent/scripts/macos-signature.mjs@@ -2,10 +2,11 @@import { execFileSync } from "node:child_process";import { resolve } from "node:path";import { pathToFileURL } from "node:url";+import { darwinReleasePlatforms, releasePlatforms } from "../../../scripts/release-platforms.mjs";function requiresMacosSigning(platform) {- if (platform === "linux-arm64" || platform === "linux-x64") return false;- if (platform !== "darwin-arm64" && platform !== "darwin-x64") throw new Error(`Unsupported binary platform: ${platform}`);+ if (!releasePlatforms.includes(platform)) throw new Error(`Unsupported binary platform: ${platform}`);+ if (!darwinReleasePlatforms.includes(platform)) return false;if (process.platform !== "darwin") throw new Error("Darwin binaries must be signed and verified on macOS");return true;}diff --git a/packages/coding-agent/src/utils/native-installation.ts b/packages/coding-agent/src/utils/native-installation.tsindex bffe3e352b..ed0e39bfca 100644--- a/packages/coding-agent/src/utils/native-installation.ts+++ b/packages/coding-agent/src/utils/native-installation.ts@@ -1,6 +1,33 @@import { lstatSync, readFileSync, readlinkSync, realpathSync } from "node:fs";import { dirname, join, resolve } from "node:path";+/**+ * Compiled release platforms, mirroring scripts/release-platforms.mjs. Linux+ * publishes glibc and musl builds, plus Bun baseline builds for x64 CPUs+ * without AVX2, so every supported host has a runnable archive.+ */+export const NATIVE_PLATFORMS = [+ "darwin-arm64",+ "darwin-x64",+ "linux-arm64",+ "linux-arm64-musl",+ "linux-x64",+ "linux-x64-baseline",+ "linux-x64-musl",+ "linux-x64-musl-baseline",+] as const;++// Longest name first so `linux-x64-musl` never matches as `linux-x64`.+const NATIVE_PLATFORM_PATTERN = [...NATIVE_PLATFORMS].sort((left, right) => right.length - left.length).join("|");++const NATIVE_RELEASE_DIRECTORY = new RegExp(+ `^\\.\\./releases/(\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?)-(${NATIVE_PLATFORM_PATTERN})-([a-f0-9]{64})(?:\\.[A-Za-z0-9]{6})?/prime-agent$`,+);++export function isNativePlatform(platform: string): boolean {+ return (NATIVE_PLATFORMS as readonly string[]).includes(platform);+}+export const NATIVE_RELEASE_ASSETS = ["prime-agent","package.json",@@ -37,10 +64,7 @@ function readNativeTarget(root: string, link: string, recoveredTarget?: string):if (readFileSync(join(root, ".managed"), "utf8").trim() !== "prime-agent-native-v1") return undefined;const launcher = join(root, "bin", link);const target = recoveredTarget ?? readlinkSync(launcher);- const match =- /^\.\.\/releases\/(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)-(darwin|linux)-(arm64|x64)-([a-f0-9]{64})(?:\.[A-Za-z0-9]{6})?\/prime-agent$/.exec(- target,- );+ const match = NATIVE_RELEASE_DIRECTORY.exec(target);if (!match) return undefined;const executable = resolve(dirname(launcher), target);const releaseDir = dirname(executable);@@ -50,8 +74,8 @@ function readNativeTarget(root: string, link: string, recoveredTarget?: string):executable,releaseDir,version: match[1],- platform: `${match[2]}-${match[3]}`,- sha256: match[4],+ platform: match[2],+ sha256: match[3],};} catch {return undefined;diff --git a/packages/coding-agent/src/utils/version-check.ts b/packages/coding-agent/src/utils/version-check.tsindex 895c5e563a..8a2996b2cf 100644--- a/packages/coding-agent/src/utils/version-check.ts+++ b/packages/coding-agent/src/utils/version-check.ts@@ -1,3 +1,4 @@+import { isNativePlatform } from "./native-installation.js";import { getPiUserAgent } from "./pi-user-agent.js";const DEFAULT_PRIME_AGENT_DOWNLOAD_BASE_URL = "https://pub-728493de92a943e2a9b2d17b4719f318.r2.dev";@@ -213,7 +214,7 @@ export async function getLatestPiRelease(const artifact = candidate as Partial<NativeReleaseArtifact>;if (typeof artifact.platform !== "string" ||- !/^(darwin|linux)-(arm64|x64)$/.test(artifact.platform) ||+ !isNativePlatform(artifact.platform) ||platforms.has(artifact.platform) ||artifact.file !== `prime-agent-${release.version}-${artifact.platform}.tar.gz` ||typeof artifact.sha256 !== "string" ||diff --git a/packages/coding-agent/test/installer-platform.ts b/packages/coding-agent/test/installer-platform.tsnew file mode 100644index 0000000000..eb235777a6--- /dev/null+++ b/packages/coding-agent/test/installer-platform.ts@@ -0,0 +1,26 @@+import { execFileSync } from "node:child_process";+import { basename, resolve } from "node:path";+import { NATIVE_PLATFORMS } from "../src/utils/native-installation.js";++export const installerPath = resolve(__dirname, "../../../install.sh");++/**+ * The platform the installer selects on this host. Fixtures name their archives+ * after it so the suite also runs on musl and non-AVX2 machines, where the host+ * platform is no longer `${process.platform}-${process.arch}`.+ */+export function hostNativePlatform(): string {+ // Windows has no compiled release and no `sh`; these suites skip there.+ if (process.platform === "win32") return `${process.platform}-${process.arch}`;+ try {+ return execFileSync("sh", [installerPath, "--native-platform"], { encoding: "utf8" }).trim();+ } catch {+ return `${process.platform}-${process.arch}`;+ }+}++/** The platform an archive filename advertises, or undefined when it names none. */+export function archiveNativePlatform(archive: string): string | undefined {+ const name = basename(archive);+ return NATIVE_PLATFORMS.find((platform) => name.endsWith(`-${platform}.tar.gz`));+}diff --git a/packages/coding-agent/test/installer-release-format.test.ts b/packages/coding-agent/test/installer-release-format.test.tsindex 04832ea94f..d69e0cc424 100644--- a/packages/coding-agent/test/installer-release-format.test.ts+++ b/packages/coding-agent/test/installer-release-format.test.ts@@ -13,10 +13,12 @@ import { createServer } from "node:http";import { tmpdir } from "node:os";import { dirname, join, resolve } from "node:path";import { afterAll, beforeAll, describe, expect, it } from "vitest";+import { hostNativePlatform } from "./installer-platform.js";const version = "1.2.3";const nodeFile = `prime-agent-${version}.tgz`;-const nativeFile = `prime-agent-${version}-${process.platform}-${process.arch}.tar.gz`;+// The inventory must advertise the archive the installer actually selects here.+const nativeFile = `prime-agent-${version}-${hostNativePlatform()}.tar.gz`;const digest = "a".repeat(64);let root: string;let harness: string;diff --git a/packages/coding-agent/test/native-installer.test.ts b/packages/coding-agent/test/native-installer.test.tsindex 702fb4b083..42e741b947 100644--- a/packages/coding-agent/test/native-installer.test.ts+++ b/packages/coding-agent/test/native-installer.test.ts@@ -21,6 +21,8 @@ import { Agent, getGlobalDispatcher, setGlobalDispatcher } from "undici";import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";import { getNativeUpdatePlan } from "../src/cli/native-update.js";import { DaemonClient } from "../src/modes/daemon/daemon-client.js";+import { NATIVE_PLATFORMS } from "../src/utils/native-installation.js";+import { archiveNativePlatform, hostNativePlatform } from "./installer-platform.js";const installer = resolve(__dirname, "../../../install.sh");const assets = [@@ -32,7 +34,10 @@ const assets = ["export-html/template.html","photon_rs_bg.wasm",];-const platform = `${process.platform}-${process.arch}`;+// Fixtures follow the installer's own selection so the suite also runs on musl+// and non-AVX2 hosts, where that is no longer `${process.platform}-${process.arch}`.+const platform = hostNativePlatform();+const testArchive = process.env.PRIME_AGENT_TEST_ARCHIVE;const feed = new Map<string, Buffer>();let beforeArchiveResponse: (() => void) | undefined;let redirectToHttp = false;@@ -55,7 +60,7 @@ let fixtureDispatcher: Agent;function publish(version: string,- options: { broken?: boolean; missing?: boolean; link?: boolean; installer?: string } = {},+ options: { broken?: boolean; missing?: boolean; link?: boolean; installer?: string; libstdcxx?: boolean } = {},) {const source = mkdtempSync(join(root, "archive-"));for (const asset of assets) {@@ -65,9 +70,20 @@ function publish(}writeFileSync(join(source, "package.json"), JSON.stringify({ version }));writeFileSync(join(source, "install.sh"), options.installer ?? readFileSync(installer));+ // A musl host without libstdc++ fails in the loader, exactly as reproduced on Alpine.+ const missingLibstdcxx = `#!/bin/sh+printf 'Error loading shared library libstdc++.so.6: No such file or directory (needed by %s)\\n' "$0" >&2+printf 'Error relocating %s: _ZSt17__throw_bad_allocv: symbol not found\\n' "$0" >&2+printf 'Error relocating %s: __cxa_pure_virtual: symbol not found\\n' "$0" >&2+exit 1+`;writeFileSync(join(source, "prime-agent"),- options.broken ? "#!/bin/sh\nexit 1\n" : `#!/bin/sh\nprintf '%s\\n' '${version}'\n`,+ options.libstdcxx+ ? missingLibstdcxx+ : options.broken+ ? "#!/bin/sh\nexit 1\n"+ : `#!/bin/sh\nprintf '%s\\n' '${version}'\n`,{ mode: 0o755 },);if (options.link) symlinkSync("/tmp", join(source, "outside"));@@ -152,6 +168,29 @@ function releaseDirectories() {.map((entry) => join(installationRoot(), "releases", entry.name));}+// Stands in for the npm route so a test can prove whether the installer took it.+function nodeFallbackHarness() {+ const harness = join(home, "fallback-installer.sh");+ writeFileSync(+ harness,+ readFileSync(installer, "utf8").replace(+ /\nmain "\$@"\s*$/,+ () => `+prime_agent_install_node() {+ mkdir -p "$HOME/.local/bin" "$HOME/.local/lib/node_modules/prime-agent/dist/bundle"+ printf '%s\\n' "$1" > "$HOME/.local/lib/node_modules/prime-agent/dist/bundle/cli.js"+ if [ ! -L "$HOME/.local/bin/prime-agent" ]; then+ ln -s ../lib/node_modules/prime-agent/dist/bundle/cli.js "$HOME/.local/bin/prime-agent"+ fi+ printf 'node-route:%s\\n' "$1"+}+main "$@"+`,+ ),+ );+ return harness;+}+function createLsofShim() {const shim = mkdtempSync(join(root, "lsof-"));writeFileSync(@@ -635,24 +674,7 @@ download_prime_agent_package "$1" "$prime_agent_base_url/releases/v$1/$prime_ageit.each(["1.0.0", "1.0.1"])("retries the Node fallback when reinstalling or upgrading to %s", async (version) => {publish("1.0.0", { broken: true });publish("1.0.1", { broken: true });- const harness = join(home, "fallback-installer.sh");- writeFileSync(- harness,- readFileSync(installer, "utf8").replace(- /\nmain "\$@"\s*$/,- () => `-prime_agent_install_node() {- mkdir -p "$HOME/.local/bin" "$HOME/.local/lib/node_modules/prime-agent/dist/bundle"- printf '%s\\n' "$1" > "$HOME/.local/lib/node_modules/prime-agent/dist/bundle/cli.js"- if [ ! -L "$HOME/.local/bin/prime-agent" ]; then- ln -s ../lib/node_modules/prime-agent/dist/bundle/cli.js "$HOME/.local/bin/prime-agent"- fi- printf 'node-route:%s\\n' "$1"-}-main "$@"-`,- ),- );+ const harness = nodeFallbackHarness();const first = await install("1.0.0", { PRIME_AGENT_INSTALL_METHOD: "auto" }, harness);expect(first.code, first.output).toBe(0);expect(first.output).toContain("node-route:1.0.0");@@ -677,6 +699,43 @@ main "$@"expect(existsSync(command())).toBe(false);});+ it.each(["auto", "binary"])(+ "names the missing libstdc++ package instead of falling back to Node with method=%s",+ async (method) => {+ publish("1.0.0", { libstdcxx: true });+ const harness = nodeFallbackHarness();+ const result = await install("1.0.0", { PRIME_AGENT_INSTALL_METHOD: method }, harness);+ expect(result.code, result.output).not.toBe(0);+ expect(result.output).toContain("needs the libstdc++ runtime library");+ expect(result.output).toContain("apk add --no-cache libstdc++");+ expect(result.output).toContain("PRIME_AGENT_INSTALL_METHOD=node");+ // Sixty relocation errors and the false "cannot run" claim stay out of the terminal.+ expect(result.output).not.toContain("Error relocating");+ expect(result.output).not.toContain("cannot run");+ expect(result.output).not.toContain("node-route:");+ expect(existsSync(join(home, ".local/bin/prime-agent"))).toBe(false);+ expect(existsSync(installationRoot())).toBe(false);+ },+ );++ it("gives back an installation root it adopted when no release is ever activated", async () => {+ publish("1.0.0", { broken: true });+ const failed = await install("1.0.0");+ expect(failed.code, failed.output).not.toBe(0);+ expect(existsSync(installationRoot())).toBe(false);+ // The next run must still be able to install into the same place.+ publish("1.0.1");+ const installed = await install("1.0.1");+ expect(installed.code, installed.output).toBe(0);+ expect(execFileSync(command(), ["--version"], { encoding: "utf8" })).toBe("1.0.1\n");+ // A root an earlier install legitimately owns survives a later failure.+ publish("1.0.2", { broken: true });+ const later = await install("1.0.2");+ expect(later.code, later.output).not.toBe(0);+ expect(readFileSync(join(installationRoot(), ".managed"), "utf8")).toBe("prime-agent-native-v1\n");+ expect(execFileSync(command(), ["--version"], { encoding: "utf8" })).toBe("1.0.1\n");+ });+it("refuses to replace an unrelated public command", async () => {publish("1.0.0");mkdirSync(join(home, ".local/bin"), { recursive: true });@@ -1046,10 +1105,12 @@ exec /bin/${operation} "$@"expect(existsSync(join(home, "data/prime-agent"))).toBe(false);});- it.skipIf(!process.env.PRIME_AGENT_TEST_ARCHIVE)(+ // The installer downloads the archive for the platform it selects, so an archive+ // built for another platform (a baseline or musl cross-build) cannot be installed here.+ it.skipIf(!testArchive || archiveNativePlatform(testArchive) !== platform)("installs, updates, and rolls back actual compiled releases without Node",async () => {- const archive = process.env.PRIME_AGENT_TEST_ARCHIVE!;+ const archive = testArchive!;const name = basename(archive);const version = name.slice("prime-agent-".length, -`-${platform}.tar.gz`.length);const manifestPath = /-beta(?:\.|$)/.test(version) ? "/beta.json" : "/latest.json";@@ -1145,3 +1206,133 @@ exec /bin/${operation} "$@"120000,);});++describe.skipIf(process.platform === "win32")("installer platform selection", () => {+ let sandbox: string;+ let harness: string;+ let shims: string;++ function sysroot(name: string, contents: { cpuinfo?: string; muslLoader?: string }): string {+ const directory = join(sandbox, name);+ if (contents.cpuinfo !== undefined) {+ mkdirSync(join(directory, "proc"), { recursive: true });+ writeFileSync(join(directory, "proc/cpuinfo"), contents.cpuinfo);+ }+ if (contents.muslLoader) {+ mkdirSync(join(directory, "lib"), { recursive: true });+ writeFileSync(join(directory, "lib", contents.muslLoader), "");+ }+ mkdirSync(directory, { recursive: true });+ return directory;+ }++ function detect(host: { os: string; arch: string; glibc?: string; ldd?: string; root: string }) {+ return execFileSync("sh", [harness], {+ encoding: "utf8",+ env: {+ PATH: `${shims}:/usr/bin:/bin`,+ FAKE_OS: host.os,+ FAKE_ARCH: host.arch,+ FAKE_GLIBC: host.glibc ?? "",+ FAKE_LDD: host.ldd ?? "ldd: missing file arguments",+ PRIME_AGENT_NATIVE_SYSROOT_FOR_TESTS: host.root,+ },+ });+ }++ beforeAll(() => {+ sandbox = mkdtempSync(join(tmpdir(), "installer-platform-"));+ harness = join(sandbox, "detect.sh");+ writeFileSync(+ harness,+ readFileSync(installer, "utf8").replace(/\nmain "\$@"\s*$/, () => "\nprime_agent_native_platform\n"),+ );+ shims = join(sandbox, "shims");+ mkdirSync(shims);+ writeFileSync(+ join(shims, "uname"),+ '#!/bin/sh\ncase "$1" in -s) printf \'%s\\n\' "$FAKE_OS" ;; -m) printf \'%s\\n\' "$FAKE_ARCH" ;; esac\n',+ { mode: 0o755 },+ );+ writeFileSync(+ join(shims, "getconf"),+ '#!/bin/sh\n[ -n "$FAKE_GLIBC" ] || exit 1\nprintf \'glibc %s\\n\' "$FAKE_GLIBC"\n',+ { mode: 0o755 },+ );+ writeFileSync(join(shims, "ldd"), "#!/bin/sh\nprintf '%s\\n' \"$FAKE_LDD\" >&2\nexit 1\n", { mode: 0o755 });+ writeFileSync(join(shims, "sw_vers"), "#!/bin/sh\nprintf '%s\\n' \"$FAKE_OS_VERSION\"\n", { mode: 0o755 });+ });+ afterAll(() => rmSync(sandbox, { recursive: true, force: true }));++ const avx2 = "processor\t: 0\nflags\t\t: fpu vme de avx avx2 bmi2\n";+ const withoutAvx2 = "processor\t: 0\nflags\t\t: fpu vme de sse4_2 avx\n";++ it("selects the AVX2 build only when the CPU advertises avx2", () => {+ expect(+ detect({ os: "Linux", arch: "x86_64", glibc: "2.39", root: sysroot("glibc-avx2", { cpuinfo: avx2 }) }),+ ).toBe("linux-x64");+ expect(+ detect({ os: "Linux", arch: "x86_64", glibc: "2.39", root: sysroot("glibc-plain", { cpuinfo: withoutAvx2 }) }),+ ).toBe("linux-x64-baseline");+ // An unreadable CPU inventory must select the build that runs on every x86-64 CPU.+ expect(detect({ os: "Linux", arch: "x86_64", glibc: "2.39", root: sysroot("glibc-bare", {}) })).toBe(+ "linux-x64-baseline",+ );+ });++ it("selects musl builds from the musl loader or the ldd banner", () => {+ const loader = sysroot("musl-x64", { cpuinfo: avx2, muslLoader: "ld-musl-x86_64.so.1" });+ expect(detect({ os: "Linux", arch: "x86_64", root: loader })).toBe("linux-x64-musl");+ expect(+ detect({+ os: "Linux",+ arch: "x86_64",+ root: sysroot("musl-x64-plain", { cpuinfo: withoutAvx2, muslLoader: "ld-musl-x86_64.so.1" }),+ }),+ ).toBe("linux-x64-musl-baseline");+ expect(+ detect({ os: "Linux", arch: "aarch64", root: sysroot("musl-arm64", { muslLoader: "ld-musl-aarch64.so.1" }) }),+ ).toBe("linux-arm64-musl");+ expect(+ detect({+ os: "Linux",+ arch: "x86_64",+ ldd: "musl libc (x86_64)",+ root: sysroot("stripped", { cpuinfo: avx2 }),+ }),+ ).toBe("linux-x64-musl");+ });++ it("keeps glibc ahead of musl and leaves arm64 glibc unsuffixed", () => {+ const both = sysroot("glibc-and-musl", { cpuinfo: avx2, muslLoader: "ld-musl-x86_64.so.1" });+ expect(detect({ os: "Linux", arch: "x86_64", glibc: "2.39", ldd: "musl libc", root: both })).toBe("linux-x64");+ expect(detect({ os: "Linux", arch: "aarch64", glibc: "2.39", root: both })).toBe("linux-arm64");+ });++ it.each([+ ["glibc older than 2.17", { os: "Linux", arch: "x86_64", glibc: "2.12" }],+ ["no recognisable libc", { os: "Linux", arch: "x86_64" }],+ ["an unsupported architecture", { os: "Linux", arch: "riscv64", glibc: "2.39" }],+ ["an unsupported operating system", { os: "FreeBSD", arch: "x86_64", glibc: "2.39" }],+ ])("reports no compiled platform for %s", (_label, host) => {+ const root = sysroot("unsupported", { cpuinfo: avx2 });+ expect(() => detect({ ...host, root })).toThrow();+ });++ it.each(NATIVE_PLATFORMS)("parses the %s release directory name without confusing platform suffixes", (target) => {+ const parser = join(sandbox, "parse.sh");+ writeFileSync(+ parser,+ readFileSync(installer, "utf8").replace(+ /\nmain "\$@"\s*$/,+ () =>+ '\nnative_root=/tmp\nprime_agent_native_parse_target "$1"\nprintf \'%s %s\\n\' "$native_parsed_version" "$native_parsed_platform"\n',+ ),+ );+ const digest = "a".repeat(64);+ const parsed = execFileSync("sh", [parser, `../releases/1.2.3-beta.4-${target}-${digest}/prime-agent`], {+ encoding: "utf8",+ });+ expect(parsed).toBe(`1.2.3-beta.4 ${target}\n`);+ });+});diff --git a/packages/coding-agent/test/release-signatures.test.ts b/packages/coding-agent/test/release-signatures.test.tsindex 4572342012..993c6d97b5 100644--- a/packages/coding-agent/test/release-signatures.test.ts+++ b/packages/coding-agent/test/release-signatures.test.ts@@ -13,6 +13,7 @@ import {import { tmpdir } from "node:os";import { dirname, join, resolve } from "node:path";import { afterAll, beforeAll, describe, expect, it } from "vitest";+import { NATIVE_PLATFORMS } from "../src/utils/native-installation.js";const repository = resolve(__dirname, "../../..");const signatureScript = join(repository, "packages/coding-agent/scripts/macos-signature.mjs");@@ -69,16 +70,19 @@ afterAll(() => {});describe("release signature command", () => {- it.each(["linux-arm64", "linux-x64"])("leaves %s binaries untouched", (target) => {- const binary = join(root, target);- writeFileSync(binary, `Linux fixture ${target}`);- const original = sha256(binary);- for (const command of ["sign", "verify"]) {- const result = signature(command, binary, target);- expect(result.status, result.stderr).toBe(0);- expect(sha256(binary)).toBe(original);- }- });+ it.each(NATIVE_PLATFORMS.filter((target) => target.startsWith("linux-")))(+ "leaves %s binaries untouched",+ (target) => {+ const binary = join(root, target);+ writeFileSync(binary, `Linux fixture ${target}`);+ const original = sha256(binary);+ for (const command of ["sign", "verify"]) {+ const result = signature(command, binary, target);+ expect(result.status, result.stderr).toBe(0);+ expect(sha256(binary)).toBe(original);+ }+ },+ );it("rejects unsupported targets and invalid commands", () => {expect(signature("sign", "unused", "windows-x64").status).not.toBe(0);@@ -195,9 +199,9 @@ interface BinaryManifest {}describe.skipIf(process.platform === "win32")("release archive executable identity", () => {- it("keeps all four executable bytes identical across stable and beta metadata rewrites", () => {+ it("keeps every executable's bytes identical across stable and beta metadata rewrites", () => {const binaries = join(root, "binaries");- const targets = ["darwin-arm64", "darwin-x64", "linux-arm64", "linux-x64"];+ const targets = [...NATIVE_PLATFORMS];for (const target of targets) binaryAssets(join(binaries, target), Buffer.from(`unchanged ${target} executable`));for (const version of ["1.2.3", "1.2.3-beta.4.1.abcdef0"]) {const output = join(root, version);diff --git a/packages/coding-agent/test/release-validation-receipts.test.ts b/packages/coding-agent/test/release-validation-receipts.test.tsindex 723487a089..d3abb27689 100644--- a/packages/coding-agent/test/release-validation-receipts.test.ts+++ b/packages/coding-agent/test/release-validation-receipts.test.ts@@ -169,7 +169,11 @@ describe("macOS validation receipt publication gate", () => {symlinkSync(value.artifacts, join(working, "release-artifacts", channel));symlinkSync(value.receipts, join(working, "macos-validation"));mkdirSync(join(working, "scripts"));- for (const name of ["verify-macos-validation-receipts.mjs", "release-artifact-integrity.mjs"]) {+ for (const name of [+ "verify-macos-validation-receipts.mjs",+ "release-artifact-integrity.mjs",+ "release-platforms.mjs",+ ]) {copyFileSync(resolve(__dirname, "../../../scripts", name), join(working, "scripts", name));}const workflow = parse(diff --git a/packages/coding-agent/test/release-workflow.test.ts b/packages/coding-agent/test/release-workflow.test.tsindex 8a9df9b689..3716c2c906 100644--- a/packages/coding-agent/test/release-workflow.test.ts+++ b/packages/coding-agent/test/release-workflow.test.ts@@ -4,6 +4,7 @@ import { tmpdir } from "node:os";import { join, resolve } from "node:path";import { describe, expect, it } from "vitest";import { parse } from "yaml";+import { NATIVE_PLATFORMS } from "../src/utils/native-installation.js";interface Step {name?: string;@@ -28,6 +29,12 @@ interface Workflow {}const repository = resolve(__dirname, "../../..");+// The same command the release workflow uses to enumerate publishable platforms.+const releasePlatforms = spawnSync(process.execPath, [join(repository, "scripts/release-platforms.mjs")], {+ encoding: "utf8",+})+ .stdout.trim()+ .split("\n");const release: Workflow = parse(readFileSync(join(repository, ".github/workflows/build-binaries.yml"), "utf8"));const standalone: Workflow = parse(readFileSync(join(repository, ".github/workflows/standalone-binaries.yml"), "utf8"));@@ -146,14 +153,11 @@ ${step(validation, "Verify and exercise exact final Mac archives").run}`,},);- it("retains all four standalone targets and only uploads tested executable identities", () => {+ it("retains every standalone target and only uploads tested executable identities", () => {const build = standalone.jobs.build!;- expect(build.strategy?.matrix.include.map((entry) => entry.platform)).toEqual([- "darwin-arm64",- "darwin-x64",- "linux-arm64",- "linux-x64",- ]);+ expect(build.strategy?.matrix.include.map((entry) => entry.platform)).toEqual(releasePlatforms);+ // Each target must be compiled explicitly; the host default cannot produce a cross-build.+ expect(step(build, "Compile standalone application").run).toContain(`--platform \${{ matrix.platform }}`);const test = step(build, "Test extracted application without JavaScript runtimes on PATH");expect(test.run).toContain("test/compiled-artifact.test.ts");expect(test.run).toContain("test/release-signatures.test.ts");@@ -164,6 +168,34 @@ ${step(validation, "Verify and exercise exact final Mac archives").run}`,expect(release.jobs.standalone!.with?.build_ref).toBe(`\${{ needs.release-context.outputs.build_ref }}`);});+ it("executes every archive on its own libc, musl archives inside Alpine", () => {+ const build = standalone.jobs.build!;+ const glibc = step(build, "Test extracted application without JavaScript runtimes on PATH");+ const musl = step(build, "Test extracted application on Alpine without JavaScript runtimes");+ // A cross-compiled musl archive cannot run on the glibc runner that built it.+ expect(glibc.if).toBe(`\${{ !contains(matrix.platform, 'musl') }}`);+ expect(musl.if).toBe(`\${{ contains(matrix.platform, 'musl') }}`);+ expect(musl.run).toContain("docker run");+ expect(musl.run).toContain("alpine:");+ expect(musl.run).toContain("prime-agent --version");+ expect(musl.run).toContain("prime-agent --help");+ const upload = build.steps.find((entry) => entry.uses?.startsWith("actions/upload-artifact@"))!;+ expect(build.steps.indexOf(musl)).toBeLessThan(build.steps.indexOf(upload));+ // A container smoke test only proves execution when the runner matches the target architecture.+ for (const entry of build.strategy!.matrix.include) {+ if (!entry.platform.startsWith("linux-")) continue;+ expect(entry.runner.endsWith("-arm"), entry.platform).toBe(entry.platform.includes("arm64"));+ }+ });++ it("keeps one platform set across the installer, the release scripts, and the workflows", () => {+ expect([...NATIVE_PLATFORMS]).toEqual(releasePlatforms);+ const stage = step(release.jobs.build!, "Verify and stage standalone binaries");+ // A hardcoded list here silently drops newly published platforms from a release.+ expect(stage.run).toContain("node scripts/release-platforms.mjs");+ for (const platform of releasePlatforms) expect(stage.run).not.toContain(` ${platform} `);+ });+it.skipIf(process.platform === "win32")("selects both real packer paths for PR validation without allowing publication",() => {diff --git a/scripts/assemble-release-archives.mjs b/scripts/assemble-release-archives.mjsindex 211b2f8f36..1ac902c684 100644--- a/scripts/assemble-release-archives.mjs+++ b/scripts/assemble-release-archives.mjs@@ -20,15 +20,16 @@ import {setBinaryVersion,validateBinaryAssets,} from "../packages/coding-agent/scripts/copy-binary-assets.mjs";+import { releasePlatforms } from "./release-platforms.mjs";-const platforms = ["darwin-arm64", "darwin-x64", "linux-arm64", "linux-x64"];+const platforms = releasePlatforms;export function assembleBinaryArchives({ binaryDir, artifactsDir, version, requireAll = true }) {if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(version)) throw new Error(`Invalid binary version: ${version}`);const available = readdirSync(binaryDir);const targets = platforms.filter((platform) => available.includes(platform));if (targets.length === 0 || (requireAll && targets.length !== platforms.length)) {- throw new Error("Missing compiled binaries; build all four platforms before packing a release");+ throw new Error(`Missing compiled binaries; build all ${platforms.length} platforms before packing a release`);}mkdirSync(artifactsDir, { recursive: true });const archives = [];diff --git a/scripts/pack-prime-agent-release.mjs b/scripts/pack-prime-agent-release.mjsindex 69eadacb13..2e05753362 100644--- a/scripts/pack-prime-agent-release.mjs+++ b/scripts/pack-prime-agent-release.mjs@@ -110,7 +110,7 @@ Creates private npm tarballs for R2 distribution:<out-dir>/artifacts/<channel><out-dir>/artifacts/latest.json (stable) or beta.json (beta)-Add --binary-dir packages/coding-agent/binaries to include all four standalone platform archives.+Add --binary-dir packages/coding-agent/binaries to include every standalone platform archive.`);}diff --git a/scripts/release-platforms.mjs b/scripts/release-platforms.mjsnew file mode 100644index 0000000000..20e78946ed--- /dev/null+++ b/scripts/release-platforms.mjs@@ -0,0 +1,29 @@+#!/usr/bin/env node+import { resolve } from "node:path";+import { pathToFileURL } from "node:url";++// The single source of truth for the compiled release platform set.+// Every entry is a Bun compile target (`bun-<platform>`), an archive suffix+// (`prime-agent-<version>-<platform>.tar.gz`), and a value the installer can+// emit from `install.sh --native-platform`.+//+// Linux ships four x64 and two arm64 variants so that no Linux host falls back+// to the Node installation: glibc and musl each need their own build, and x64+// CPUs without AVX2 need Bun's baseline build. macOS needs no baseline variant+// because macOS 13 only runs on 2017-and-newer Macs, which all have AVX2.+export const releasePlatforms = [+ "darwin-arm64",+ "darwin-x64",+ "linux-arm64",+ "linux-arm64-musl",+ "linux-x64",+ "linux-x64-baseline",+ "linux-x64-musl",+ "linux-x64-musl-baseline",+];++export const darwinReleasePlatforms = releasePlatforms.filter((platform) => platform.startsWith("darwin-"));++if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {+ console.log(releasePlatforms.join("\n"));+}diff --git a/scripts/verify-macos-validation-receipts.mjs b/scripts/verify-macos-validation-receipts.mjsindex 8c459408b5..12dfcd8f11 100644--- a/scripts/verify-macos-validation-receipts.mjs+++ b/scripts/verify-macos-validation-receipts.mjs@@ -3,10 +3,11 @@ import { readFileSync } from "node:fs";import { join, resolve } from "node:path";import { pathToFileURL } from "node:url";import { readReleaseBinary } from "./release-artifact-integrity.mjs";+import { darwinReleasePlatforms } from "./release-platforms.mjs";export function verifyMacosValidationReceipts(artifactsDir, receiptsDir, channel) {if (!["production", "beta"].includes(channel)) throw new Error("Expected production or beta channel");- for (const platform of ["darwin-arm64", "darwin-x64"]) {+ for (const platform of darwinReleasePlatforms) {const release = readReleaseBinary(artifactsDir, platform);const receipt = JSON.parse(readFileSync(join(receiptsDir, `${channel}-${platform}.json`), "utf8"));if (receipt.schemaVersion !== 1) throw new Error("Unsupported validation receipt");