Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/build-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 npm@12.0.2
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
Expand Down
25 changes: 23 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
}

install_prime_agent_package() {
tarball_path="$1"
if [ "$prime_agent_bootstrap_kernel_on_install" = 1 ]; then
Expand All @@ -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.
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/coding-agent/.changes/npm-12-stable-installer.md
Original file line number Diff line number Diff line change
@@ -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))
72 changes: 67 additions & 5 deletions scripts/check-installer-render.mjs → scripts/check-installer.mjs
Original file line number Diff line number Diff line change
@@ -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 "$@"';
Expand All @@ -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);
}

Expand Down Expand Up @@ -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)], {
Expand Down
Loading