mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-21 08:22:20 +02:00
## Thinking Path > - Paperclip must run the selected agent on its selected host. > - Claude needs verified packages for each supported target. > - A Mac controller must select the correct Linux provider pack. > - New defaults must follow package and execution evidence. > - This PR adds Claude platform packaging and target-specific pack selection. > - Existing Codex Linux ARM64 behavior remains intact. ## Linked Issues or Issue Description Refs #15683. This PR depends on #15993 and #15994. Related scope: #15422 and #15224. ## What Changed - Reuse the merged four-target daemon producer/consumer matrix. Add target-owned Linux provider packs and carry their immutable identities through release assembly and vendoring. - Reuse master’s landed pinned Claude SDK ARM64 executable admission and retain package-integrity, architecture and no-follow admission. - Select target-specific remote packs so Mac controllers can use Linux hosts without a development pack override. - Preserve read-only runtime context on SSH startup and resume without accepting unverified old content. - Check ordinary installed Claude readiness without injected package authority. Retain Codex and Linux x64 consumer checks. - Extend Claude automatic target selection for the remaining qualified package targets. Retain unsupported-platform and external-override behavior. - Qualify managed Daytona snapshot names through provider IDs during Claude Connect. Pin native acquisition to the measured ID. Preserve a revocation marker after failed probes or target edits, and block native acquisition until requalification instead of falling back to a mutable name. Preserve immutable-image proof, company and account boundaries, and Legacy acquisition. ## Verification - Reconciled with master `9179d8dcc3e908c217fde4f63c9d08ccf8132eeb` through the prerequisite stack, retaining the merged startup fix and latest Codex Linux ARM64 behavior. - [Four-target exact-source package qualification](https://github.com/paperclipai/paperclip/actions/runs/39267321383) passed on source `04e0202ca81387b17cbe7fd094a8338648356fe9`: all four native builds, public-package assembly, Linux x64 verification and clean installed consumers on Apple Silicon, Intel Mac and Linux ARM64. The later master reconciliation adds shared OpenRouter attribution and changes runtime source. This historical result keeps its original source identity; [later qualification](https://github.com/paperclipai/paperclip/actions/runs/39281100929) passed at `dca62c7aeb4b45f0dd91a8e18d386a16a2658ef8`. It predates the subsequent TypeScript startup fix. - Fresh local product acceptance on integrated source `b2c9fe43f9cd3bc5dd9d22552da0148845ba71a4` completed a useful file and follow-up through native Claude/Opus 5.5, High effort and the API-key connection. Both actual browser downloads were independently checked; the revision preserves the original body and session continuity. Total task estimates: $0.518432800. Ordinary web and API creation saved defaults with the native experiment disabled. - Local focused verification passed 993 startup/session tests, 243 UI tests, 12 workflow security tests, direct server/UI TypeScript checks, and token/palette gates before the last review changes. Initial DB-backed snapshot pin/revocation coverage passed 18 cases; the final serial route suites pass 122 credential/permission and 232 snapshot/environment cases after correcting a test hook timeout. Current-head cloud suites pass. - Preserved the failed pre-provider local fixture and its full pending reservation. The successful fixture has no unpriced or pending usage. Historical failed Cloud journeys, accounting holds, source identities and subscription limitations remain in the dated plan. - All Docker/Rust release production was performed in cloud CI. No local Docker image was built. An inadvertently invoked local Rust prerequisite was stopped. - Current-head cloud CI is green. All three stack PRs have fresh Greptile 5/5 reviews and zero unresolved review threads. Required typecheck, test and build gates ran in cloud CI; Docker work stayed remote. Earlier failed checks remain in their original runs. - The final master merge preserves task-loading, permission, skill-retention and OpenRouter changes. Pi uses a fresh combined profile 27, preserving both historical profile-24 declarations; Copilot remains profile 22. Focused protocol checks passed 155 cases (one skipped), the updated Pi attestation check passed 18 (one skipped), and 91 evaluation/catalog checks passed. - Latest-application manual continuation passed in 37.942 seconds on `695e5c005a85bddc8711d3fcddcaf6b7e1fb64d0`, with High effort, native Opus 5.5, Anthropic API attribution, the same resumed Claude session, an independently checked 635-byte file and persisted Done status. It uses the earlier verified Mac daemon; the preceding-source package qualification passed at `dca62c7aeb4b45f0dd91a8e18d386a16a2658ef8`. That package run predates the small TypeScript startup fix and is not relabeled as qualification for it. - Upgrade limitation: changed compiled sidecar identity rejected old durable launch state and recovery hit session-open bounds before eventually resuming. That attempt was operator-cancelled and retained; the successful manual continuation does not qualify seamless upgrades. - Local latency profile, Opus 5.5/High unchanged: three alternating real-ACP loopback samples per variant reduce median provider-ready time from 5.081s to 4.034s. The matched real API task startup improves from 5.533s to 4.348s, but total reply time changes from 17.933s to 20.221s because agent work varies. This establishes a startup saving of about one second, not a consistent total-reply speedup. A real candidate follow-up passed in 20.146s and resumed the same saved session. The loopback fixture makes no external model requests; failed initial probes remain retained. - The startup change passes 107 focused runtime/effort/lease tests, 53 profile checks (one skipped), TypeScript checking and the TypeScript-only runtime build. Native hire fixture checks pass 70 tests; their first local run retained a socket-hangup failure and stale OpenCode expectation, both accounted for before the passing rerun. Broader required checks run in cloud CI. ## Risks - **Experience needs improvement:** successful connection setup still shows “Connection needs attention” because runtime checks are deferred. Cold provider-pack upload took 122–126 seconds per run while the task mainly showed “Thinking.” The tested Core-only preview excludes private Cloud UI plugins; this is not full Cloud distribution or subscription qualification. Desktop dark theme was tested; mobile and comprehensive accessibility were not. The portable report validates, but gallery interaction could not be inspected because host preview was queued. - The optional supply-chain scan returned neutral/inconclusive because GitHub Actions package coverage and infrastructure parsing are unavailable. It is not counted as a successful supply-chain qualification. Exact package, daemon and image integrity checks passed. - A stale, missing or wrong-architecture pack must fail admission. It must not change runner or target silently. - Provider-pack source changes invalidate affected earlier execution results. Existing unknown-cost and cleanup holds remain intact. - Live subscription execution remains unverified under the API-key qualification direction. Built-in authentication flows are retained. ARM64 cloud-image production is deferred. Merge and production deployment remain separate. ## Model Used OpenAI Codex, GPT-6 family, with reasoning, repository tools, code execution and browser testing. The exact serving model ID and context-window size are not exposed in this session. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [ ] Focused local tests and final cloud verification pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
381 lines
27 KiB
JavaScript
381 lines
27 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { closeSync, constants, fstatSync, lstatSync, openSync, readFileSync, readSync, readdirSync, realpathSync, statSync, writeFileSync } from 'node:fs';
|
|
import { basename, dirname, join } from 'node:path';
|
|
|
|
// Keep public-package lifecycle code off the verification host. Resolve and
|
|
// cache the public npm graph without scripts, then execute it offline.
|
|
export const GROK_PUBLIC_INSTALL_IMAGE =
|
|
'node:24-trixie@sha256:be40f6a87b9b22215ddb20da0a2320a5c6d583fe3ee3b0024d9fa4f05b40c8fd';
|
|
// Complete the scripts-disabled install without resolving the graph again.
|
|
export const GROK_PUBLIC_INSTALL_LIFECYCLE = [
|
|
'npm', 'rebuild', '--offline', '--ignore-scripts=false', '--dangerously-allow-all-scripts',
|
|
];
|
|
|
|
export function runMacInitialInstallWithDiagnostics(install, { sourceRevision, platform, architecture, cacheDirectory, receiptPath }) {
|
|
const started = performance.now();
|
|
try {
|
|
return install();
|
|
} catch (error) {
|
|
try {
|
|
const phases = new Set(['npm', 'load', 'config', 'command', 'idealTree', 'reify', 'build', 'extract', 'unpack', 'fetch', 'audit', 'cache', 'arborist', 'metavuln']);
|
|
const operations = new Set(['load', 'install', 'init', 'userRequests', 'buildDeps', 'inflate', 'fixDepFlags', 'diffTrees', 'loadTrees', 'retireShallow', 'markDeleted', 'loadBundles', 'unpack', 'unretire', 'build', 'trash', 'save', 'audit', 'manifest', 'failed']);
|
|
const safePhase = value => {
|
|
const [phase, detail] = value.split(':');
|
|
return phases.has(phase) ? phase + (operations.has(detail) ? ':' + detail : '') : null;
|
|
};
|
|
const tails = [];
|
|
try {
|
|
const logs = join(cacheDirectory, '_logs');
|
|
assert.equal(realpathSync(logs), logs);
|
|
for (const name of readdirSync(logs).filter(name => /^[0-9TZ_.:-]+-(?:debug-\d+\.log|timing\.json)$/.test(name)).sort().slice(-2)) {
|
|
const file = join(logs, name);
|
|
if (!lstatSync(file).isFile()) continue;
|
|
const fd = openSync(file, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
try {
|
|
const stat = fstatSync(fd);
|
|
assert.ok(stat.isFile());
|
|
const size = stat.size;
|
|
const bytes = Buffer.alloc(Math.min(size, 16 * 1024));
|
|
const length = readSync(fd, bytes, 0, bytes.length, Math.max(0, size - bytes.length));
|
|
const text = bytes.subarray(0, length).toString('utf8');
|
|
const entries = [];
|
|
if (name.endsWith('-timing.json')) {
|
|
if (size > bytes.length) continue;
|
|
const timing = JSON.parse(text);
|
|
for (const [key, duration] of Object.entries(timing.timers ?? {})) {
|
|
const phase = safePhase(key);
|
|
if (phase && Number.isFinite(duration) && duration >= 0) entries.push({ phase, durationMilliseconds: duration });
|
|
}
|
|
} else {
|
|
for (const line of text.split('\n')) {
|
|
const match = line.match(/^\d+\s+(timing|silly|verbose|http)\s+(\S+)(?:\s+(\S+))?/);
|
|
if (!match) continue;
|
|
const phase = safePhase(match[2]);
|
|
if (!phase) continue;
|
|
const entry = { level: match[1], phase };
|
|
if (operations.has(match[3])) entry.operation = match[3];
|
|
const duration = line.match(/^\d+\s+timing\s+\S+\s+Completed in (\d{1,10})ms\s*$/);
|
|
if (duration) entry.durationMilliseconds = Number(duration[1]);
|
|
if (match[1] === 'http') {
|
|
const response = line.match(/^\d+\s+http\s+fetch\s+(GET|POST|PUT|DELETE|HEAD)\s+(\d{3})\s+/);
|
|
if (response) {
|
|
entry.method = response[1]; entry.status = Number(response[2]);
|
|
const fetched = line.match(/\s(\d{1,10})ms(?:\s+\(cache (?:hit|miss|revalidated|updated)\))?\s*$/);
|
|
if (fetched) entry.durationMilliseconds = Number(fetched[1]);
|
|
}
|
|
}
|
|
entries.push(entry);
|
|
}
|
|
}
|
|
tails.push({ kind: name.endsWith('-timing.json') ? 'npm-timing' : 'npm-debug', truncated: size > bytes.length || entries.length > 32, entries: entries.slice(-32) });
|
|
} finally { closeSync(fd); }
|
|
}
|
|
} catch {}
|
|
const codes = new Set(['ETIMEDOUT', 'ENOENT', 'EACCES', 'EPERM', 'ENOMEM', 'ENOBUFS', 'EIO', 'EPIPE', 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER']);
|
|
const signals = new Set(['SIGTERM', 'SIGKILL', 'SIGABRT', 'SIGINT', 'SIGHUP', 'SIGQUIT', 'SIGSEGV', 'SIGBUS']);
|
|
writeFileSync(receiptPath, JSON.stringify({ schema: 'paperclip.runner.mac-public-install-failure.v1',
|
|
sourceRevision, platform, architecture, phase: 'initial-npm-install', outcome: 'FAILED', qualified: false,
|
|
runtimeNotAttempted: true, providerCalls: 0, elapsedMilliseconds: Math.round(performance.now() - started), timeoutMilliseconds: 600000,
|
|
error: { code: codes.has(error?.code) ? error.code : null, status: Number.isInteger(error?.status) ? error.status : null,
|
|
signal: signals.has(error?.signal) ? error.signal : null, errno: Number.isInteger(error?.errno) ? error.errno : null },
|
|
npmDiagnosticTail: tails }, null, 2) + '\n');
|
|
} catch {}
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
export function macNodeHeadersDirectory(nodeExecutable, nodeVersion) {
|
|
assert.match(nodeVersion, /^\d+\.\d+\.\d+$/, 'Executing Node must have an exact release version');
|
|
const executable = realpathSync(nodeExecutable);
|
|
assert.equal(basename(executable), 'node', 'Node SDK must belong to the executing Node binary');
|
|
assert.ok(statSync(executable).isFile(), 'Executing Node must be a regular file');
|
|
const prefix = realpathSync(join(dirname(executable), '..'));
|
|
const include = join(prefix, 'include/node');
|
|
for (const name of ['node.h', 'node_version.h']) {
|
|
const header = join(include, name);
|
|
assert.equal(realpathSync(header), header, 'Node SDK headers must remain inside the executing Node prefix');
|
|
assert.ok(statSync(header).isFile(), 'Node SDK headers must be regular files');
|
|
}
|
|
assert.match(readFileSync(join(include, 'node.h'), 'utf8'), /#\s*include\s+"node_version\.h"/, 'Node SDK must include its version header');
|
|
const versionHeader = readFileSync(join(include, 'node_version.h'), 'utf8');
|
|
const versions = ['MAJOR', 'MINOR', 'PATCH'].map(part => {
|
|
const matches = [...versionHeader.matchAll(new RegExp('^#\\s*define\\s+NODE_' + part + '_VERSION\\s+(\\d+)\\s*$', 'gm'))];
|
|
assert.equal(matches.length, 1, 'Node SDK must declare one ' + part.toLowerCase() + ' version');
|
|
return matches[0][1];
|
|
});
|
|
assert.equal(versions.join('.'), nodeVersion, 'Node SDK version must match the executing Node');
|
|
return prefix;
|
|
}
|
|
|
|
// Inspect the actual npm archive, independently of the staging helper.
|
|
export function assertNoBundledCodexPayloads(entries) {
|
|
assert.ok(Array.isArray(entries) && entries.length > 0, 'Packed package must have tar members');
|
|
for (const entry of entries) {
|
|
assert.equal(typeof entry, 'string');
|
|
assert.ok(!entry.startsWith('/') && !entry.split('/').includes('..'), 'Tar member must remain inside the package');
|
|
assert.doesNotMatch(entry, /(?:^|\/)node_modules\/@openai\/codex-(?:linux|darwin|win32)-(?:x64|arm64)(?:\/|$)/,
|
|
'Paperclip tarballs must not bundle Codex platform packages');
|
|
assert.doesNotMatch(entry, /(?:^|\/)node_modules\/@openai\/codex\/vendor(?:\/|$)/,
|
|
'Paperclip tarballs must not bundle the Codex wrapper vendor payload');
|
|
if (!entry.endsWith('/')) assert.doesNotMatch(entry, /(?:^|\/)codex(?:\.exe)?$/,
|
|
'Paperclip tarballs must not bundle native Codex executables');
|
|
}
|
|
}
|
|
|
|
// Verify every host payload against its own official npm provenance, including
|
|
// independent legacy closures. The selected native runtime is pinned below.
|
|
export function assertInstalledCodexPlatformProvenance(lock, installed, target) {
|
|
assert.match(target, /^(linux|darwin|win32)-(x64|arm64)$/);
|
|
assert.ok(Array.isArray(installed) && installed.length > 0, 'Consumer must install its host Codex platform package');
|
|
const alias = `@openai/codex-${target}`;
|
|
for (const { path, manifest } of installed) {
|
|
assert.ok(path.endsWith(`/node_modules/${alias}`) || path === `node_modules/${alias}`,
|
|
'Consumer must contain only the host Codex platform payload');
|
|
const version = manifest.version;
|
|
assert.ok(typeof version === 'string' && version.endsWith('-' + target)
|
|
&& /^\d+\.\d+\.\d+$/.test(version.slice(0, -target.length - 1)), 'Installed Codex platform must declare an exact host version');
|
|
assert.ok([alias, '@openai/codex'].includes(manifest.name), 'Installed Codex platform package identity must match its alias');
|
|
const [os, cpu] = target.split('-');
|
|
assert.deepEqual(manifest.os, [os]);
|
|
assert.deepEqual(manifest.cpu, [cpu]);
|
|
const entry = lock.packages?.[path];
|
|
assert.ok(entry, 'Installed Codex platform must have a consumer lock entry');
|
|
assert.notEqual(entry.inBundle, true, 'Codex platform package must be downloaded, not bundled');
|
|
assert.notEqual(entry.link, true, 'Codex platform package must not be a local link');
|
|
assert.equal(entry.version, version, 'Consumer lock must pin the host Codex platform version');
|
|
const url = new URL(entry.resolved);
|
|
assert.equal(url.protocol, 'https:');
|
|
assert.equal(url.host, 'registry.npmjs.org', 'Codex platform must resolve from official npm');
|
|
assert.equal(url.username + url.password + url.search + url.hash, '', 'Codex npm URL must not have credentials or modifiers');
|
|
assert.equal(decodeURIComponent(url.pathname), `/@openai/codex/-/codex-${version}.tgz`, 'Codex platform must use its exact official npm tarball');
|
|
assert.match(entry.integrity ?? '', /^sha512-[A-Za-z0-9+/]+={0,2}$/, 'Codex platform must have npm integrity');
|
|
assert.equal(Buffer.from(entry.integrity.slice(7), 'base64').length, 64, 'Codex npm integrity must be a SHA-512 digest');
|
|
}
|
|
return { codexConsumerHostOnly: true, codexConsumerPlatform: target, codexPlatformPackageSource: 'official npm',
|
|
codexPlatformPackages: installed.map(({ path, manifest }) => ({ path, name: manifest.name, version: manifest.version,
|
|
resolved: lock.packages[path].resolved, integrity: lock.packages[path].integrity, inBundle: false })) };
|
|
}
|
|
|
|
// Execute this in the existing offline public consumer, never in the checkout.
|
|
// The public index and returned command must both come from the installed graph.
|
|
export function installedClaudeProbeSource(indexPath) {
|
|
return `
|
|
import assert from 'node:assert/strict';
|
|
import { pathToFileURL } from 'node:url';
|
|
assert.equal(process.env.PAPERCLIP_ACPX_PROVIDER_PACKAGE_ROOT, undefined);
|
|
assert.equal(process.env.PAPERCLIP_ACPX_PROVIDER_PACKAGE_MANIFEST, undefined);
|
|
const { probeAcpxClaudeInstallation } = await import(pathToFileURL(${JSON.stringify(indexPath)}).href);
|
|
await probeAcpxClaudeInstallation('claude-opus-5-5');
|
|
console.log(JSON.stringify({ schema: 'paperclip.claude-installed-admission.v1',
|
|
platform: process.platform, architecture: process.arch, model: 'claude-opus-5-5',
|
|
packageIntegrityAndNoFollowLease: 'passed', defaultPackageAuthority: true, providerCalls: 0 }));
|
|
`;
|
|
}
|
|
|
|
export function installedCodexProbeSource(indexPath, consumerRoot, expectedVersion, { nativeCodex = false } = {}) {
|
|
return `
|
|
import assert from 'node:assert/strict';
|
|
import { execFileSync } from 'node:child_process';
|
|
import { createHash } from 'node:crypto';
|
|
import { createRequire } from 'node:module';
|
|
import { accessSync, constants, existsSync, lstatSync, readFileSync, readdirSync, realpathSync, statSync } from 'node:fs';
|
|
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
import { pathToFileURL } from 'node:url';
|
|
const root = realpathSync(${JSON.stringify(consumerRoot)});
|
|
const contained = path => { const value = relative(root, realpathSync(path)); return value !== '' && value !== '..' && !value.startsWith('..' + sep) && !isAbsolute(value); };
|
|
const lock = JSON.parse(readFileSync(join(root, 'package-lock.json'), 'utf8'));
|
|
const installed = [], pending = [join(root, 'node_modules')];
|
|
let visited = 0;
|
|
while (pending.length) {
|
|
const directory = pending.pop();
|
|
assert.ok(contained(directory), 'Installed dependency directory must remain in the consumer');
|
|
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
if (entry.name.startsWith('.') || !(entry.isDirectory() || entry.isSymbolicLink())) continue;
|
|
const namespace = join(directory, entry.name);
|
|
const packages = entry.name.startsWith('@') ? readdirSync(namespace, { withFileTypes: true })
|
|
.filter(value => value.isDirectory() || value.isSymbolicLink()).map(value => join(namespace, value.name)) : [namespace];
|
|
for (const packageRoot of packages) {
|
|
assert.ok(++visited <= 10000 && contained(packageRoot), 'Installed dependency graph must be bounded and contained');
|
|
const path = relative(root, packageRoot).split(sep).join('/');
|
|
if (${/(?:^|\/)node_modules\/@openai\/codex-(?:linux|darwin|win32)-(?:x64|arm64)$/.toString()}.test(path)) {
|
|
let manifest;
|
|
try { manifest = JSON.parse(readFileSync(join(packageRoot, 'package.json'), 'utf8')); }
|
|
catch (error) {
|
|
if (error.code !== 'ENOENT') throw error;
|
|
const contents = readdirSync(packageRoot), slot = lstatSync(packageRoot);
|
|
assert.ok(slot.isDirectory() && !slot.isSymbolicLink() && contents.length === 0,
|
|
'Codex optional slot without a manifest must be an empty regular directory; found ' +
|
|
JSON.stringify(contents.sort().slice(0, 16).map(name => name.slice(0, 256))));
|
|
// npm can leave an empty nested optional slot while hoisting the
|
|
// actual host payload. Its real lock and manifest still qualify below.
|
|
continue;
|
|
}
|
|
installed.push({ path, manifest });
|
|
}
|
|
const nested = join(packageRoot, 'node_modules');
|
|
if (existsSync(nested)) pending.push(nested);
|
|
}
|
|
}
|
|
}
|
|
const provenance = (${assertInstalledCodexPlatformProvenance.toString()})(lock, installed, process.platform + '-' + process.arch);
|
|
const index = ${JSON.stringify(indexPath)};
|
|
assert.ok(contained(index), 'Codex public index must be installed in the consumer');
|
|
const { resolvePinnedCodexCommand } = await import(pathToFileURL(index).href);
|
|
assert.equal(typeof resolvePinnedCodexCommand, 'function', 'Installed public index must export the pinned Codex resolver');
|
|
const command = resolvePinnedCodexCommand();
|
|
assert.ok(isAbsolute(command) && contained(command), 'Pinned Codex must resolve inside the installed consumer');
|
|
assert.ok(statSync(command).isFile(), 'Pinned Codex must be a regular executable');
|
|
accessSync(command, constants.X_OK);
|
|
const selectedPlatformManifest = realpathSync(createRequire(command).resolve('@openai/codex-' + process.platform + '-' + process.arch + '/package.json'));
|
|
const selectedPlatform = installed.find(({ path }) => realpathSync(join(root, path, 'package.json')) === selectedPlatformManifest);
|
|
assert.ok(selectedPlatform, 'Codex wrapper must resolve an official host platform package from its installed graph');
|
|
const selectedMetadata = JSON.parse(readFileSync(selectedPlatformManifest, 'utf8'));
|
|
assert.deepEqual(selectedMetadata, selectedPlatform.manifest, 'Selected Codex platform metadata must match its scanned provenance');
|
|
${nativeCodex ? '' : `assert.equal(selectedMetadata.version, ${JSON.stringify(expectedVersion)} + '-' + process.platform + '-' + process.arch,
|
|
'Selected Codex platform version must match the qualified pin');`}
|
|
const version = execFileSync(command, ['--version'], { timeout: 30_000, maxBuffer: 128 * 1024, encoding: 'utf8',
|
|
env: { PATH: process.env.PATH, HOME: process.env.HOME, NODE_PATH: '' } }).trim();
|
|
${nativeCodex ? "assert.match(version, /^codex-cli /, 'Installed official Codex command must execute');" : `assert.equal(version, 'codex-cli ' + ${JSON.stringify(expectedVersion)}, 'Installed Codex version must match the qualified pin');`}
|
|
const vendor = dirname(index);
|
|
const integrityPath = join(vendor, 'drivers/acpx/installation-integrity.js');
|
|
const profilesPath = join(vendor, 'drivers/acpx/qualified-profiles.js');
|
|
const securityPath = join(vendor, 'drivers/codex/codex-security-config.js');
|
|
assert.ok(contained(integrityPath) && contained(profilesPath) && contained(securityPath), 'Codex verification modules must come from the installed consumer');
|
|
const { codexExecutableReadOnlyRoots, createIsolatedCodexAppServerArgs } = await import(pathToFileURL(securityPath).href);
|
|
const platformRoot = realpathSync(dirname(selectedPlatformManifest));
|
|
const nativeVendor = realpathSync(join(platformRoot, 'vendor'));
|
|
assert.ok(contained(nativeVendor) && nativeVendor.startsWith(platformRoot + sep), 'Codex vendor resources must remain inside their installed platform package');
|
|
const triple = { 'linux-x64': 'x86_64-unknown-linux-musl', 'linux-arm64': 'aarch64-unknown-linux-musl',
|
|
'darwin-x64': 'x86_64-apple-darwin', 'darwin-arm64': 'aarch64-apple-darwin',
|
|
'win32-x64': 'x86_64-pc-windows-msvc', 'win32-arm64': 'aarch64-pc-windows-msvc' }[process.platform + '-' + process.arch];
|
|
assert.ok(triple, 'Codex native payload requires a known host target');
|
|
const nativeName = process.platform === 'win32' ? 'codex.exe' : 'codex';
|
|
const nativeCandidates = ['bin', 'codex'].map(directory => join(nativeVendor, triple, directory, nativeName)).filter(existsSync);
|
|
assert.equal(nativeCandidates.length, 1, 'Selected official Codex platform must contain one native executable');
|
|
const nativeExecutable = realpathSync(nativeCandidates[0]);
|
|
const nativeStat = lstatSync(nativeCandidates[0]);
|
|
assert.ok(nativeExecutable.startsWith(nativeVendor + sep) && nativeStat.isFile() && !nativeStat.isSymbolicLink()
|
|
&& nativeStat.size >= 20 && nativeStat.size <= 512 * 1024 * 1024, 'Codex native executable must be a bounded regular file in its selected platform package');
|
|
accessSync(nativeExecutable, constants.X_OK);
|
|
const nativeBytes = readFileSync(nativeExecutable);
|
|
const { runnerBinaryTarget } = await import(pathToFileURL(join(vendor, 'live/runner-binary.js')).href);
|
|
assert.equal(runnerBinaryTarget(nativeBytes), process.platform + '-' + process.arch, 'Codex native executable must match the actual host architecture');
|
|
const sandboxSource = { HOME: '/private-provider-home', PATH: '/usr/local/bin:/usr/bin:/bin' };
|
|
const readRoots = codexExecutableReadOnlyRoots(sandboxSource, command);
|
|
assert.ok(readRoots.includes(nativeVendor), 'Selected native Codex vendor directory must be readable inside its sandbox');
|
|
assert.ok(!readRoots.includes(platformRoot) && !readRoots.includes(root) && !readRoots.includes(sandboxSource.HOME), 'Codex sandbox must not grant enclosing npm or credential-home access');
|
|
const sandboxArgs = createIsolatedCodexAppServerArgs(sandboxSource, readRoots).join('\\n');
|
|
assert.ok(sandboxArgs.includes(JSON.stringify(nativeVendor) + '="read"'), 'Codex sandbox configuration must retain the selected native executable resources');
|
|
${nativeCodex ? '' : `const { createAcpxPackageJsonResolver, verifyQualifiedAcpxInstallation } = await import(pathToFileURL(integrityPath).href);
|
|
const { resolveQualifiedAcpxProfile } = await import(pathToFileURL(profilesPath).href);
|
|
const serverRoot = resolve(vendor, '../../..');
|
|
assert.ok(contained(serverRoot), 'Codex package authority must be the installed server');
|
|
const installation = await verifyQualifiedAcpxInstallation(resolveQualifiedAcpxProfile('codex', 'gpt-5.4'),
|
|
createAcpxPackageJsonResolver(serverRoot, join(serverRoot, 'package.json')));
|
|
const lease = await installation.openCommand();
|
|
await lease.close();`}
|
|
console.log(JSON.stringify({ pinnedCodexCommandVerified: true, installedCodexVersion: version,
|
|
codexCommandSha256: createHash('sha256').update(readFileSync(command)).digest('hex'),
|
|
codexNativeExecutableSha256: createHash('sha256').update(nativeBytes).digest('hex'),
|
|
codexNativeExecutablePath: relative(root, nativeExecutable).split(sep).join('/'),
|
|
...provenance, codexSelectedPlatformPath: selectedPlatform.path, codexSelectedPlatformVersion: selectedMetadata.version,
|
|
codexNativeSandboxResourcesVerified: true,
|
|
${nativeCodex ? '' : `pinnedCodexVersion: ${JSON.stringify(expectedVersion)}, codexQualifiedInstallationVerified: true, codexCommandLeaseVerified: true,`}
|
|
providerCalls: 0 }));
|
|
`;
|
|
}
|
|
|
|
export function assertInstalledNativeConsumerContinuity(before, after) {
|
|
for (const field of ['lockSha256', 'runnerSha256', 'codexCommandSha256', 'codexNativeExecutableSha256']) {
|
|
if (!/^[a-f0-9]{64}$/.test(before[field]) || before[field] !== after[field]) {
|
|
throw new Error(`Installed native host startup changed ${field}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
export function installedDaemonProbeSource(outputRoot, consumerRoot, sourceRevision) {
|
|
return `
|
|
import assert from 'node:assert/strict';
|
|
import { createHash } from 'node:crypto';
|
|
import { execFileSync } from 'node:child_process';
|
|
import { readFileSync, realpathSync } from 'node:fs';
|
|
import { isAbsolute, join, relative, sep } from 'node:path';
|
|
import { pathToFileURL } from 'node:url';
|
|
const root = realpathSync(${JSON.stringify(consumerRoot)}), output = realpathSync(${JSON.stringify(outputRoot)});
|
|
const inside = path => { const value = relative(root, realpathSync(path)); return value !== '' && value !== '..' && !value.startsWith('..' + sep) && !isAbsolute(value); };
|
|
assert.ok(inside(output));
|
|
const { defaultCapabilityRunnerdBinary } = await import(pathToFileURL(join(output, 'live/runnerd-codex-transport.js')).href);
|
|
const { runnerBinaryTarget } = await import(pathToFileURL(join(output, 'live/runner-binary.js')).href);
|
|
const { parsePaperclipRunnerdBuildMetadata } = await import(pathToFileURL(join(output, 'evals/runnerd-artifact.js')).href);
|
|
const { PAPERCLIP_RUNNER_BUILD_METADATA: expected } = await import(pathToFileURL(join(output, 'evals/build-metadata.js')).href);
|
|
const manifest = JSON.parse(readFileSync(join(output, 'bin/release-manifest.json'), 'utf8'));
|
|
const targets = ['darwin-arm64', 'darwin-x64', 'linux-x64', 'linux-arm64'];
|
|
assert.equal(manifest.schema, 'paperclip.runner.release-binaries.v1');
|
|
assert.equal(manifest.sourceRevision, ${JSON.stringify(sourceRevision)});
|
|
assert.deepEqual(Object.keys(manifest.platforms).sort(), targets.sort());
|
|
for (const target of targets) {
|
|
const record = manifest.platforms[target];
|
|
assert.equal(record.path, target + '/paperclip-runnerd');
|
|
const file = join(output, 'bin', record.path); assert.ok(inside(file));
|
|
const bytes = readFileSync(file);
|
|
assert.equal(runnerBinaryTarget(bytes), target);
|
|
assert.equal('sha256:' + createHash('sha256').update(bytes).digest('hex'), record.sha256);
|
|
}
|
|
const target = process.platform + '-' + process.arch, selected = defaultCapabilityRunnerdBinary();
|
|
assert.ok(inside(selected));
|
|
assert.equal(realpathSync(selected), realpathSync(join(output, 'bin', manifest.platforms[target].path)), 'Production must select the packaged host daemon');
|
|
const metadata = parsePaperclipRunnerdBuildMetadata(JSON.parse(execFileSync(selected, ['--build-metadata'], {
|
|
timeout: 15000, maxBuffer: 64 * 1024, encoding: 'utf8', env: { PATH: process.env.PATH, HOME: process.env.HOME, NODE_PATH: '' },
|
|
})));
|
|
assert.equal(metadata.binaryContractVersion, expected.contracts.runnerdArtifact);
|
|
assert.equal(metadata.nativeExecutionVersion, expected.contracts.nativeExecution);
|
|
assert.equal(metadata.harnessDriverVersion, expected.contracts.harnessDriver);
|
|
assert.equal(metadata.prp.name, expected.prp.name);
|
|
assert.ok(metadata.prp.minimumVersion <= expected.prp.maximumVersion && metadata.prp.maximumVersion >= expected.prp.minimumVersion);
|
|
console.log(JSON.stringify({ installedRunnerDaemonVerified: true, target, sourceRevision: manifest.sourceRevision,
|
|
sha256: manifest.platforms[target].sha256, buildMetadata: metadata, providerCalls: 0 }));
|
|
`;
|
|
}
|
|
|
|
export function macPublicInstallLifecycleProfile(ownedRoot) {
|
|
if (!ownedRoot.startsWith('/') || ownedRoot.includes('\0')) throw new Error('Mac lifecycle requires an absolute owned root');
|
|
return `(version 1)\n(allow default)\n(deny network*)\n(deny file-write* (require-all (require-not (subpath ${JSON.stringify(ownedRoot)})) (require-not (literal "/dev/null"))))\n`;
|
|
}
|
|
|
|
export function macInstalledStartupProbeSource(consumerRoot, serverRoot, runnerDigest, helperPath) {
|
|
if (!/^sha256:[a-f0-9]{64}$/.test(runnerDigest)) throw new Error('Installed Mac startup requires the verified SHA-256 manifest identity');
|
|
return `import { probeInstalledCodexStartup } from ${JSON.stringify(helperPath)};
|
|
console.log(JSON.stringify(await probeInstalledCodexStartup({consumerRoot:${JSON.stringify(consumerRoot)},
|
|
serverRoot:${JSON.stringify(serverRoot)},expectedRunnerSha256:${JSON.stringify(runnerDigest.slice(7))}})));`;
|
|
}
|
|
|
|
export function grokConsumerDockerArgs({ assets, consumer, cache, command, uid, gid, download = false, prerequisite, temporarySizeMiB = 256, temporaryExecutable = false, platform = 'linux/amd64' }) {
|
|
if (!['linux/amd64', 'linux/arm64'].includes(platform)) throw new Error('Public-install verification requires a supported native Linux platform');
|
|
if (!Number.isSafeInteger(uid) || uid <= 0 || !Number.isSafeInteger(gid) || gid <= 0) {
|
|
throw new Error('Public-install verification requires an unprivileged host user');
|
|
}
|
|
if (!Number.isSafeInteger(temporarySizeMiB) || temporarySizeMiB < 256 || temporarySizeMiB > 2048) {
|
|
throw new Error('Public-install temporary storage must be bounded between 256 and 2048 MiB');
|
|
}
|
|
if (typeof temporaryExecutable !== 'boolean' || (temporaryExecutable && download)) {
|
|
throw new Error('Executable runtime snapshots require an offline verification sandbox');
|
|
}
|
|
return [
|
|
'run', '--rm', '--platform', platform,
|
|
'--user', `${uid}:${gid}`, '--read-only',
|
|
'--cap-drop', 'ALL', '--security-opt', 'no-new-privileges',
|
|
'--pids-limit', '256', '--memory', '3g',
|
|
'--network', download ? 'bridge' : 'none',
|
|
'--tmpfs', `/tmp:rw,nosuid,nodev,${temporaryExecutable ? 'exec' : 'noexec'},size=${temporarySizeMiB}m,mode=1777`,
|
|
'--env', 'HOME=/tmp', '--env', 'npm_config_cache=/cache',
|
|
'--env', 'npm_config_nodedir=/usr/local',
|
|
'--env', 'npm_config_audit=false', '--env', 'npm_config_fund=false',
|
|
'--env', `npm_config_ignore_scripts=${download ? 'true' : 'false'}`,
|
|
'--mount', `type=bind,src=${assets},dst=/packages,readonly`,
|
|
'--mount', `type=bind,src=${consumer},dst=/consumer`,
|
|
'--mount', `type=bind,src=${cache},dst=/cache`,
|
|
...(prerequisite ? ['--mount', `type=bind,src=${prerequisite},dst=/opt/paperclip/providers/grok/1.0.13/grok,readonly`] : []),
|
|
'--workdir', '/consumer', GROK_PUBLIC_INSTALL_IMAGE, ...command,
|
|
];
|
|
}
|