Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

fix(installer): support npm 12 remote dependency policy (#1992)

Seth Kartencd10724fe02b
diff --git a/.github/workflows/build-binaries.yml b/.github/workflows/build-binaries.yml
index c140daa67f..6fd1ab47af 100644
--- a/.github/workflows/build-binaries.yml
+++ b/.github/workflows/build-binaries.yml
@@ -172,6 +172,41 @@ jobs:
--base-url "$PRIME_AGENT_DOWNLOAD_BASE_URL" \
--out-dir packages/coding-agent/release/beta
+ - name: Smoke test installer with npm 12
+ run: |
+ npm install --global [email protected]
+ npm --version | grep -Eq '^12\.'
+
+ SMOKE_VERSION=0.0.0-installer-smoke
+ SMOKE_BASE_URL=http://127.0.0.1:18188
+ SMOKE_OUT=packages/coding-agent/release/npm12-smoke
+ SMOKE_ROOT=$(mktemp -d)
+
+ npm run release:pack -- \
+ --channel stable \
+ --version "$SMOKE_VERSION" \
+ --base-url "$SMOKE_BASE_URL" \
+ --out-dir "$SMOKE_OUT"
+
+ mkdir -p "$SMOKE_ROOT/releases/v$SMOKE_VERSION"
+ cp "$SMOKE_OUT/artifacts/"* "$SMOKE_ROOT/releases/v$SMOKE_VERSION/"
+ sed \
+ -e "s|__PRIME_AGENT_DOWNLOAD_BASE_URL__|$SMOKE_BASE_URL|g" \
+ -e 's|__PRIME_AGENT_DEFAULT_RELEASE_CHANNEL__|stable|g' \
+ install.sh > /tmp/prime-agent-npm12-install.sh
+
+ python3 -m http.server 18188 --bind 127.0.0.1 --directory "$SMOKE_ROOT" >/tmp/prime-agent-npm12-http.log 2>&1 &
+ server_pid=$!
+ trap 'kill "$server_pid" 2>/dev/null || true; rm -rf "$SMOKE_ROOT" "$SMOKE_OUT"' EXIT
+
+ curl -fsS --retry 5 --retry-connrefused "$SMOKE_BASE_URL/releases/v$SMOKE_VERSION/SHA256SUMS"
+ export NPM_CONFIG_PREFIX="$SMOKE_ROOT/npm-prefix"
+ PATH="$NPM_CONFIG_PREFIX/bin:$PATH" \
+ PRIME_AGENT_BOOTSTRAP_KERNEL_ON_INSTALL=0 \
+ PRIME_AGENT_INSTALLER_PLAIN=1 \
+ sh /tmp/prime-agent-npm12-install.sh "$SMOKE_VERSION"
+ test -x "$NPM_CONFIG_PREFIX/bin/prime-agent"
+
- name: Upload production artifacts
if: env.PUBLISH_PRODUCTION == 'true'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
diff --git a/install.sh b/install.sh
index c1b5c52458..9a4ae18ed7 100755
--- a/install.sh
+++ b/install.sh
@@ -1589,6 +1589,27 @@ confirm_kernel_runtime_setup() {
fi
}
+prime_agent_npm_requires_remote_policy() {
+ npm_version=$(npm --version 2>/dev/null) || return 1
+ npm_major=${npm_version%%.*}
+ case "$npm_major" in
+ ""|*[!0-9]*) return 1 ;;
+ esac
+ [ "$npm_major" -ge 12 ]
+}
+
+prime_agent_npm_install() {
+ tarball_path="$1"
+ shift
+ if prime_agent_npm_requires_remote_policy; then
+ # Limit npm 12's required policy overrides to the verified root package.
+ env "$@" npm install -g --no-fund --no-audit --loglevel=error --progress=false \
+ --allow-remote=all --allow-scripts="$tarball_path" "$tarball_path"
+ else
+ env "$@" npm install -g --no-fund --no-audit --loglevel=error --progress=false "$tarball_path"
+ fi
+}
+
install_prime_agent_package() {
tarball_path="$1"
if [ "$prime_agent_bootstrap_kernel_on_install" = 1 ]; then
@@ -1602,7 +1623,7 @@ Finalizing npm install."
"Installing Prime Agent" \
"Installing Prime Agent" \
"$npm_install_details" \
- env PRIME_AGENT_BOOTSTRAP_TOOLS_ON_INSTALL=1 PRIME_AGENT_BOOTSTRAP_KERNEL_ON_INSTALL=1 PRIME_AGENT_INSTALL_UV=1 npm install -g --no-fund --no-audit --loglevel=error --progress=false "$tarball_path"
+ prime_agent_npm_install "$tarball_path" PRIME_AGENT_BOOTSTRAP_TOOLS_ON_INSTALL=1 PRIME_AGENT_BOOTSTRAP_KERNEL_ON_INSTALL=1 PRIME_AGENT_INSTALL_UV=1
else
npm_install_details="Preparing global install.
Linking command binaries.
@@ -1613,7 +1634,7 @@ Finalizing npm install."
"Installing Prime Agent" \
"Installing Prime Agent" \
"$npm_install_details" \
- env PRIME_AGENT_BOOTSTRAP_TOOLS_ON_INSTALL=1 npm install -g --no-fund --no-audit --loglevel=error --progress=false "$tarball_path"
+ prime_agent_npm_install "$tarball_path" PRIME_AGENT_BOOTSTRAP_TOOLS_ON_INSTALL=1
fi
}
diff --git a/package.json b/package.json
index 6d64610db8..8644fe9131 100644
--- a/package.json
+++ b/package.json
@@ -15,7 +15,7 @@
"dev": "concurrently --names \"ai,agent,coding-agent,tui\" --prefix-colors \"cyan,yellow,red,magenta\" \"cd packages/ai && npm run dev\" \"cd packages/agent && npm run dev\" \"cd packages/coding-agent && npm run dev\" \"cd packages/tui && npm run dev\"",
"dev:tsc": "cd packages/ai && npm run dev:tsc",
"check": "biome check --write --error-on-warnings . && tsgo --noEmit && npm run check:installer && npm run check:browser-smoke",
- "check:installer": "node scripts/check-installer-render.mjs",
+ "check:installer": "node scripts/check-installer.mjs",
"check:browser-smoke": "node scripts/check-browser-smoke.mjs",
"profile:tui": "node scripts/profile-coding-agent-node.mjs --mode tui",
"profile:rpc": "node scripts/profile-coding-agent-node.mjs --mode rpc",
diff --git a/packages/coding-agent/.changes/npm-12-stable-installer.md b/packages/coding-agent/.changes/npm-12-stable-installer.md
new file mode 100644
index 0000000000..be401f17ef
--- /dev/null
+++ b/packages/coding-agent/.changes/npm-12-stable-installer.md
@@ -0,0 +1 @@
+- Fixed the stable installer failing under npm 12 when resolving verified release dependencies. ([Discussion #1988](https://github.com/PrimeIntellect-ai/prime-agent/discussions/1988))
diff --git a/scripts/check-installer-render.mjs b/scripts/check-installer.mjs
similarity index 84%
rename from scripts/check-installer-render.mjs
rename to scripts/check-installer.mjs
index 835f306bbc..6f6fad233e 100644
--- a/scripts/check-installer-render.mjs
+++ b/scripts/check-installer.mjs
@@ -1,7 +1,7 @@
import { spawnSync } from "node:child_process";
-import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
+import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
-import { join } from "node:path";
+import { delimiter, join } from "node:path";
const installerSource = readFileSync("install.sh", "utf-8");
const mainCall = '\nmain "$@"';
@@ -11,7 +11,7 @@ const syncEnd = "\x1b[?2026l";
const failures = [];
if (mainCallIndex === -1) {
- console.error('Installer render check failed: could not find final main "$@" call.');
+ console.error('Installer check failed: could not find final main "$@" call.');
process.exit(1);
}
@@ -152,16 +152,78 @@ try {
check(compactRows.meta.first.visible === "1", "expected the initial tall render to show the logo");
check(compactRows.meta.second.compact === "1", "expected shrink below frozen splash height to use compact mode");
check(compactRows.meta.second.visible === "0", "expected compact row mode to hide the logo");
+
+ checkNpmInstallPolicies();
} finally {
rmSync(tempDir, { recursive: true, force: true });
}
if (failures.length > 0) {
- console.error(["Installer render check failed:", ...failures.map((failure) => `- ${failure}`)].join("\n"));
+ console.error(["Installer check failed:", ...failures.map((failure) => `- ${failure}`)].join("\n"));
process.exit(1);
}
-console.log("Installer render check passed.");
+console.log("Installer check passed.");
+
+function checkNpmInstallPolicies() {
+ const binDir = join(tempDir, "bin");
+ const installHarnessPath = join(tempDir, "install-harness.sh");
+ const npmPath = join(binDir, "npm");
+ const tarballPath = join(tempDir, "verified release package.tgz");
+ const installHarnessSource = `${installerSource.slice(0, mainCallIndex)}
+
+prime_agent_npm_install "$1"
+`;
+ const npmSource = `#!/bin/sh
+set -eu
+
+if [ "\${1:-}" = "--version" ]; then
+ printf '%s\\n' "$FAKE_NPM_VERSION"
+ exit 0
+fi
+[ "\${1:-}" = install ] || exit 1
+
+remote_policy=
+script_policy=
+target=
+for arg in "$@"; do
+ case "$arg" in
+ --allow-remote=*) remote_policy=\${arg#*=} ;;
+ --allow-scripts=*) script_policy=\${arg#*=} ;;
+ "$FAKE_NPM_TARBALL") target="$arg" ;;
+ esac
+done
+[ "$target" = "$FAKE_NPM_TARBALL" ] || exit 1
+
+npm_major=\${FAKE_NPM_VERSION%%.*}
+if [ "$npm_major" -ge 12 ]; then
+ [ "$remote_policy" = all ] && [ "$script_policy" = "$FAKE_NPM_TARBALL" ] || exit 1
+else
+ [ -z "$remote_policy" ] && [ -z "$script_policy" ] || exit 1
+fi
+`;
+
+ mkdirSync(binDir);
+ writeFileSync(installHarnessPath, installHarnessSource, "utf-8");
+ writeFileSync(npmPath, npmSource, "utf-8");
+ writeFileSync(tarballPath, "verified fixture", "utf-8");
+ chmodSync(npmPath, 0o755);
+
+ for (const npmVersion of ["10.9.8", "11.12.1", "12.0.2"]) {
+ const result = spawnSync("sh", [installHarnessPath, tarballPath], {
+ encoding: "utf-8",
+ env: {
+ ...process.env,
+ FAKE_NPM_TARBALL: tarballPath,
+ FAKE_NPM_VERSION: npmVersion,
+ PATH: `${binDir}${delimiter}${process.env.PATH ?? ""}`,
+ },
+ });
+ if (result.status !== 0) {
+ failures.push(`npm ${npmVersion}: install policy check failed\n${result.stderr}${result.stdout}`);
+ }
+ }
+}
function runCase(name, initialCols, initialRows, resizedCols, resizedRows) {
const result = spawnSync("sh", [harnessPath, String(initialCols), String(initialRows), String(resizedCols), String(resizedRows)], {