mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-24 14:20:12 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The native Runner starts each agent harness and owns its lifecycle, credentials and recovery > - Google Antigravity is Google's only first-party coding harness, and it is the harness for Gemini 4 Neon > - The Runner had an Antigravity integration, but only as a pending candidate: ACP server 1.4.3, macOS ARM64 only, Google sign-in only, closed unless an operator opened it for one company and one model > - Cloud sandboxes run Linux and use API keys, so the candidate could not run there, and it had one attended test cell > - This pull request moves the integration to ACP server 1.5.2, makes it run on Linux and with a Gemini API key, adds the tests the other ACPX harnesses have, and removes the code paths that would block recovery after release > - The benefit is that the release of Antigravity becomes a small declaration change after the live suites pass. The profile stays `pending` in this pull request. ## Linked Issues or Issue Description Refs #98 Refs #6559 Refs #8523 Refs #21121 (a separate legacy-style `agy_local` adapter that uses the CLI print protocol; this pull request does not replace or include it) ## What Changed **Runtime** - Pin Antigravity ACP server 1.5.2 (was 1.4.3). Owned admission patch is `1.5.2-paperclip.2`. - Verified patched closures for `darwin-arm64`, `linux-x64` and `linux-arm64`. `darwin-x64` stays inventory-only. - The patcher reads Mach-O and ELF builds. It signs macOS output only. One admission source serves all platforms. - Platform gates in TypeScript, Rust, the sidecar schema and the server admit each host that has a verified closure. **Auth and models** - Gemini API-key auth reaches an exact-model session receipt. Admission accepts a model only when the base model and the thinking level both match the requested ID. - API-key connections get a model list on local and cloud environments. The list is generated at build time from the pinned runtime. The server starts no process to read it. - Gemini 4 Neon, Carbon, Argon and Hydrogen are selectable. The picker marks them "needs a paid Gemini API plan" for API-key connections. - One shared module maps model ID to family and thinking level. - `google/gemini-4-neon` is added to the OpenCode model list. A new model audit is in `doc/adapter-model-audit-2026-11-22.md`. **Lifecycle and failures** - A provider error no longer completes the turn. The driver classifies it: overloaded, rate limit, quota, auth rejected, model unavailable. - Overload retries are bounded (3 attempts, about 14 seconds). - A refused session reload maps to incompatible saved state, so the automatic replacement conversation applies. - Server gates that refused restart recovery, remote targets and shared state for Antigravity now apply only while the profile is pending. - A Google sign-in connection with a cloud environment is refused at save and at Test, with a plain message. - A released profile rejects candidate grants in TypeScript and in Rust. **Launch cost and integrity (all native ACPX providers)** - Each closure is verified one time into a sealed read-only store. Later launches check file identities and hash the exact executable they start. - Remote provider-pack verification is recorded per sandbox lease. Later runs check kernel identity and fall back to the full hash on any difference. - Superseded stores are removed in the background after a launch. **Provider pack and image** - The provider pack carries Antigravity for `linux-x64` as a candidate provider. It becomes an ordinary provider from the profile status alone. - The Daytona image build accepts the candidate. A credential-free smoke runs in the build. **Tests and CI** - New `antigravity-qualification` suite: 24 cells, local and Daytona. - New model lineup suites: 14 API-key cells and 14 Gemini 4 cells. Each cell requires the exact model in the Runner receipt. - Antigravity can run the `chat-features` cases with `--profile runner-acpx-antigravity`. - `runner-full-stack-e2e.yml` passes `GEMINI_API_KEY` for the new profile and derives candidate providers from the selected Daytona cells. **Docs** - `doc/plans/2026-11-22-antigravity-qualification.md` is the current release contract, acceptance ledger and operator recipe. ## Verification Commands that passed on the final revision: - `pnpm build` - Typecheck for all packages, including the runner-e2e test projects - `pnpm test:e2e:runner:unit`: 11,665 Vitest tests passed, 25 skipped; 386 node tests passed - `cargo test -p paperclip-runner-core -- --test-threads=4`: 1,199 passed, 2 failed. The 2 failures are Codex transport timing tests that pass alone and on `master`. - `cargo fmt --check`, `check:acpx-profiles`, `check:protocol-types`, `node scripts/check-maps.mjs` - Native patch tests: 9 of 9 on `darwin-arm64` and 9 of 9 on `linux-x64` - UI picker tests: 397 of 397 Known failures that also fail on `master`: - 11 runner package script tests (browser, Pi and package-boundary checks) - 6 `runtime-selection` tests that read an untracked local skill file Live evidence, without a prompt: - Clean provisioning on `darwin-arm64` and on `linux-x64` in a Daytona sandbox. The closure digests reproduce. A changed or missing file is rejected. - `initialize` reports 1.5.2. An API-key session returns a receipt for exactly `gemini-3.8-flash-low` and the exact instruction bytes, on both platforms. - All 28 model IDs (14 Gemini 3, 14 Gemini 4) return an exact receipt under an API key. - A session survives a process kill and resumes in a new process with exact receipts, on both platforms. - The server's remote path verifies the provider pack in a Daytona sandbox. - Run start to native `initialize`: 3.45 s to 1.46 s on macOS, 3.65 s to 1.74 s on Linux x64, before the per-launch executable hash was restored (about 60 ms on macOS; not measured on Linux). - Remote pack verification on a reused sandbox lease: about 4.3 s to about 0.25 s. Live evidence, with a prompt, on an already-released harness: - Pi native, `pi-native.runner-acpx-pi.local.agent-files-fresh-run`, on `darwin-arm64` at `427e9b088b`: 1 of 1 passed, 14 of 14 checks, both native runs succeeded (25.5 s and 25.7 s). The process started from the new launch store with no fallback warning. - The same cell and `native-pending-controller-restart` failed in the paid workflow on this branch and on `master` in the same way, before any native start. The workflow does not install the Pi runtime for local cells, so the agent setup check fails. That is a workflow gap, not part of this change. **Not run.** No Antigravity prompt completed on 1.5.2 on any platform. The only Gemini key available is on the free tier, and Google returned 503 or 429 for each attempt on two days. These gates are open: - All 24 `antigravity-qualification` cells - Both model lineup suites, including inference on Gemini 4 Neon - The attended Google sign-in journey on 1.5.2 - The chat cases under Antigravity - Image pull time and startup time on a published image - A native start on `linux-arm64` - A live provider-death cell for Kimi, Pi or Copilot on the new launch store (one ordinary Pi cell passed live; see above) ## Risks - **The launch store changes how every native ACPX provider starts** (Kimi, Copilot, Cursor, Pi), not only Antigravity. A review found two defects in the first version (an executable swap was possible, and Pi launches broke). Both are fixed with tests. One live Pi cell passed on this branch on macOS. No live provider-death cell and no Linux cell ran for those providers. - The profile digest changes. Saved Antigravity candidate sessions and existing candidate grants stop working. The new release refuses old state by name and starts a replacement conversation. - The Linux provider pack and the Daytona image grow by about 834 MB (about 274 MB compressed) when Antigravity is included. - The pack verification record is in server memory. The first run after a server restart pays the full hash again. - Antigravity 1.5.2 reads the workspace `GEMINI.md` and `AGENTS.md` as user rules. This is deliberate and matches Codex. Any other rule file is refused. - Orchestrator mode is not available. ACP server 1.5.2 does not expose it. - Antigravity stays `pending`. Normal users cannot run it until a later change removes the pending status. ## Model Used - Claude Fable 5.2 (`claude-fable-5-2`) planned, briefed and integrated the work, with tool use. - Claude Opus 5.5 (`claude-opus-5-5`) subagents wrote the code and ran the tests, with tool use and code execution. ## 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 - [x] I have run tests locally and they 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 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
194 lines
12 KiB
JavaScript
194 lines
12 KiB
JavaScript
import { createHash } from 'node:crypto';
|
|
import { createReadStream, createWriteStream } from 'node:fs';
|
|
import { chmod, copyFile, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
import { execFileSync } from 'node:child_process';
|
|
import { pipeline } from 'node:stream/promises';
|
|
import { Transform } from 'node:stream';
|
|
import { join, resolve } from 'node:path';
|
|
import { pathToFileURL } from 'node:url';
|
|
import { isDeepStrictEqual } from 'node:util';
|
|
import { verifyReleaseProviderPack } from '../packages/paperclip-runner/scripts/release-provider-pack.mjs';
|
|
|
|
export function validateReleaseRun(run, source) {
|
|
if (!/^[a-f0-9]{40}$/.test(source) || !/^[a-f0-9]{40}$/.test(run.head_sha ?? '') || run.conclusion !== 'success'
|
|
|| run.path !== '.github/workflows/release-smoke.yml' || run.repository?.full_name !== 'paperclipai/paperclip') {
|
|
throw Error('Image inputs require a successful repository-owned Release Smoke run in paperclipai/paperclip');
|
|
}
|
|
}
|
|
|
|
export function selectReleaseArtifacts(artifacts, runId, attempt) {
|
|
const names = [
|
|
`runner-provider-packs-${runId}-${attempt}-linux-x64`,
|
|
`runner-release-${runId}-${attempt}-linux-x64`,
|
|
];
|
|
const selected = names.map(name => artifacts.filter(a => a.name === name));
|
|
selected.push(artifacts.filter(a => /^[a-zA-Z0-9._-]+-public-packages$/.test(a.name)));
|
|
if (selected.some(matches => matches.length !== 1)) throw Error('Expected one pack, daemon and public-package artifact');
|
|
return selected.map(([a]) => {
|
|
if (a.expired || !Number.isSafeInteger(a.id) || a.id <= 0 || !/^sha256:[a-f0-9]{64}$/.test(a.digest)
|
|
|| !Number.isSafeInteger(a.size_in_bytes) || a.size_in_bytes < 1 || a.size_in_bytes > 2 * 1024 ** 3) {
|
|
throw Error('Invalid or expired release artifact');
|
|
}
|
|
return a;
|
|
});
|
|
}
|
|
|
|
export function validateReleaseImageBase(base) {
|
|
if (!/^ghcr\.io\/paperclipai\/paperclip-daytona-runner@sha256:[a-f0-9]{64}$/.test(base)) {
|
|
throw Error('Release image base must be an immutable Paperclip Daytona image');
|
|
}
|
|
return base;
|
|
}
|
|
|
|
export function validateImageBindings({ source, pack, publicPack, receipt, release, daemonBytes }) {
|
|
if (!isDeepStrictEqual(publicPack, pack)) throw Error('Image pack differs from public package authority');
|
|
const sha256 = createHash('sha256').update(daemonBytes).digest('hex');
|
|
if (receipt.schema !== 'paperclip.runner.release-artifact.v1' || receipt.sourceRevision !== source || receipt.target !== 'linux-x64'
|
|
|| receipt.sha256 !== `sha256:${sha256}` || release.sourceRevision !== source || release.platforms?.['linux-x64']?.sha256 !== `sha256:${sha256}`
|
|
|| daemonBytes.length < 64 || daemonBytes.subarray(0, 4).toString('hex') !== '7f454c46'
|
|
|| daemonBytes[4] !== 2 || daemonBytes[5] !== 1 || daemonBytes.readUInt16LE(18) !== 62) {
|
|
throw Error('Daemon source, digest or architecture mismatch');
|
|
}
|
|
return sha256;
|
|
}
|
|
|
|
export function decodeReleaseJson(file, path) {
|
|
if (file?.type !== 'file' || file.path !== path || file.encoding !== 'base64'
|
|
|| !Number.isSafeInteger(file.size) || file.size < 1 || file.size > 1024 * 1024
|
|
|| typeof file.content !== 'string') throw Error('Invalid frozen release JSON');
|
|
const bytes = Buffer.from(file.content, 'base64');
|
|
if (bytes.length !== file.size) throw Error('Frozen release JSON size mismatch');
|
|
return JSON.parse(bytes.toString('utf8'));
|
|
}
|
|
|
|
export function decodeReleaseKimiClosures(file, path) {
|
|
if (file?.type !== 'file' || file.path !== path || file.encoding !== 'base64'
|
|
|| !Number.isSafeInteger(file.size) || file.size < 1 || file.size > 1024 * 1024
|
|
|| typeof file.content !== 'string') throw Error('Invalid frozen Kimi closure source');
|
|
const bytes = Buffer.from(file.content, 'base64');
|
|
if (bytes.length !== file.size) throw Error('Frozen Kimi closure source size mismatch');
|
|
const matches = [...bytes.toString('utf8').matchAll(/export const KIMI_DISTRIBUTION_CLOSURE_SHA256 = Object\.freeze\(\{\s*"darwin-arm64": "([a-f0-9]{64})",\s*"linux-x64": "([a-f0-9]{64})",?\s*\}\);/g)];
|
|
if (matches.length !== 1) throw Error('Invalid frozen Kimi closure declaration');
|
|
return { 'darwin-arm64': matches[0][1], 'linux-x64': matches[0][2] };
|
|
}
|
|
|
|
/** The release's frozen Antigravity declaration, read as data from the release
|
|
* commit. Its PATCHED Linux closure is what the image pack must carry. */
|
|
export async function loadReleaseAntigravityDistributions(profiles, fetchFile) {
|
|
if (!profiles?.profiles?.antigravity) return undefined;
|
|
const path = 'packages/paperclip-runner/antigravity-distributions.json';
|
|
const frozen = decodeReleaseJson(await fetchFile(path), path);
|
|
if (frozen?.schema !== 'paperclip.antigravity_distribution.v1') throw Error('Invalid frozen Antigravity distribution declaration');
|
|
return frozen;
|
|
}
|
|
|
|
const digestFile = async file => {
|
|
const hash = createHash('sha256');
|
|
for await (const chunk of createReadStream(file)) hash.update(chunk);
|
|
return hash.digest('hex');
|
|
};
|
|
|
|
async function main() {
|
|
const source = process.env.SOURCE_SHA, runId = process.env.RELEASE_RUN_ID, token = process.env.GH_TOKEN;
|
|
const output = resolve(process.argv[2] ?? 'remote-verification/release-context');
|
|
validateReleaseImageBase(process.env.RELEASE_BASE_IMAGE);
|
|
if (!/^[1-9][0-9]*$/.test(runId ?? '') || !token) throw Error('Release run ID and GitHub token required');
|
|
const api = async endpoint => {
|
|
const response = await fetch(`https://api.github.com/repos/paperclipai/paperclip/${endpoint}`, {
|
|
headers: { authorization: `Bearer ${token}`, accept: 'application/vnd.github+json' }, redirect: 'error',
|
|
signal: AbortSignal.timeout(30_000),
|
|
});
|
|
if (!response.ok) throw Error(`GitHub release metadata request failed: ${response.status}`);
|
|
return response.json();
|
|
};
|
|
const run = await api(`actions/runs/${runId}`);
|
|
validateReleaseRun(run, source);
|
|
const artifacts = [];
|
|
for (let page = 1; ; page++) {
|
|
const result = await api(`actions/runs/${runId}/artifacts?per_page=100&page=${page}`);
|
|
artifacts.push(...result.artifacts);
|
|
if (result.artifacts.length < 100) break;
|
|
if (page === 10) throw Error('Unexpected artifact count');
|
|
}
|
|
const selected = selectReleaseArtifacts(artifacts, runId, run.run_attempt);
|
|
await mkdir(output, { recursive: false });
|
|
const dirs = [];
|
|
for (const [index, artifact] of selected.entries()) {
|
|
const response = await fetch(`https://api.github.com/repos/paperclipai/paperclip/actions/artifacts/${artifact.id}/zip`, {
|
|
headers: { authorization: `Bearer ${token}`, accept: 'application/vnd.github+json' }, redirect: 'manual',
|
|
signal: AbortSignal.timeout(30_000),
|
|
});
|
|
const url = response.headers.get('location');
|
|
if (response.status !== 302 || !url || new URL(url).protocol !== 'https:'
|
|
|| !new URL(url).hostname.endsWith('.blob.core.windows.net')) throw Error('Unexpected artifact download redirect');
|
|
const download = await fetch(url, { redirect: 'error', signal: AbortSignal.timeout(300_000) });
|
|
if (!download.ok || !download.body) throw Error('Release artifact download failed');
|
|
const archive = join(output, `artifact-${index}.zip`), hash = createHash('sha256');
|
|
let size = 0;
|
|
await pipeline(download.body, new Transform({ transform(chunk, encoding, callback) {
|
|
size += chunk.length;
|
|
if (size > artifact.size_in_bytes) return callback(Error('Artifact exceeds its declared size'));
|
|
hash.update(chunk); callback(null, chunk);
|
|
} }), createWriteStream(archive, { flags: 'wx', mode: 0o600 }));
|
|
if (size !== artifact.size_in_bytes || `sha256:${hash.digest('hex')}` !== artifact.digest) throw Error('Artifact digest or size mismatch');
|
|
const dir = join(output, `artifact-${index}`);
|
|
execFileSync('python3', ['-c', `import zipfile,sys,pathlib,stat
|
|
z=zipfile.ZipFile(sys.argv[1]); dest=pathlib.Path(sys.argv[2]); kind=int(sys.argv[3]); entries=z.infolist()
|
|
expected=[{'linux-x64/provider-pack.json','linux-x64/provider-pack.tar.gz'},{'linux-x64/paperclip-runnerd','linux-x64/receipt.json'}]
|
|
names=[e.filename for e in entries]
|
|
if len(names)!=len(set(names)): raise RuntimeError('Duplicate archive paths')
|
|
if kind<2:
|
|
if set(names)!=expected[kind]: raise RuntimeError('Unexpected release artifact entries')
|
|
else:
|
|
import re
|
|
if 'manifest.json' not in names or any(not re.fullmatch(r'(manifest.json|paperclipai-[a-z0-9.-]+\\.tgz)',n) for n in names): raise RuntimeError('Unexpected public package entries')
|
|
if sum(e.file_size for e in entries)>4*1024**3 or any(stat.S_ISLNK(e.external_attr>>16) for e in entries): raise RuntimeError('Unsafe artifact extraction')
|
|
z.extractall(dest)
|
|
`, archive, dir, String(index)], { stdio: 'pipe' });
|
|
await rm(archive);
|
|
dirs.push(dir);
|
|
}
|
|
const pack = JSON.parse(await readFile(join(dirs[0], 'linux-x64/provider-pack.json'), 'utf8'));
|
|
// The workflow source can be newer than the immutable release being consumed.
|
|
// Read data from that release commit, never execute source from the artifact.
|
|
const [profiles, distributions] = await Promise.all(['acpx-profiles.json', 'cursor-distributions.json'].map(async name => {
|
|
const path = `packages/paperclip-runner/${name}`;
|
|
return decodeReleaseJson(await api(`contents/${path}?ref=${source}`), path);
|
|
}));
|
|
let kimiClosures;
|
|
if (profiles.profiles.kimi && profiles.profiles.kimi.qualificationStatus !== 'pending') {
|
|
const path = 'packages/paperclip-runner/src/drivers/acpx/kimi-closure-pins.ts';
|
|
kimiClosures = decodeReleaseKimiClosures(await api(`contents/${path}?ref=${source}`), path);
|
|
}
|
|
const antigravityDistributions = await loadReleaseAntigravityDistributions(profiles, path => api(`contents/${path}?ref=${source}`));
|
|
verifyReleaseProviderPack(pack, source, 'linux-x64', { profiles, distributions, kimiClosures, antigravityDistributions });
|
|
const packages = JSON.parse(await readFile(join(dirs[2], 'manifest.json'), 'utf8'));
|
|
if (packages.schema !== 'paperclip.runner.public-packages/v1' || packages.sourceRevision !== source) throw Error('Wrong public-package source');
|
|
const server = packages.archives?.filter(a => a.name === '@paperclipai/server');
|
|
if (server?.length !== 1 || !/^paperclipai-server-[a-z0-9.-]+\.tgz$/.test(server[0].file)
|
|
|| !/^[a-f0-9]{64}$/.test(server[0].sha256)) throw Error('Invalid server archive');
|
|
const serverArchive = join(dirs[2], server[0].file);
|
|
if (await digestFile(serverArchive) !== server[0].sha256) throw Error('Server archive digest mismatch');
|
|
const fromServer = name => JSON.parse(execFileSync('tar', ['-xOf', serverArchive, `package/dist/vendor/paperclip-runner/${name}`], { encoding: 'utf8', maxBuffer: 1024 * 1024 }));
|
|
const publicPack = fromServer('remote-provider-packs/linux-x64/provider-pack.json');
|
|
const packArchive = join(dirs[0], 'linux-x64/provider-pack.tar.gz');
|
|
if (!isDeepStrictEqual(JSON.parse(execFileSync('tar', ['-xOf', packArchive, './provider-pack.json'], { encoding: 'utf8', maxBuffer: 1024 * 1024 })), pack)) throw Error('Pack archive manifest mismatch');
|
|
const receipt = JSON.parse(await readFile(join(dirs[1], 'linux-x64/receipt.json'), 'utf8'));
|
|
const daemon = join(dirs[1], 'linux-x64/paperclip-runnerd'), bytes = await readFile(daemon);
|
|
const release = fromServer('bin/release-manifest.json');
|
|
const sha256 = validateImageBindings({ source, pack, publicPack, receipt, release, daemonBytes: bytes });
|
|
await chmod(daemon, 0o700);
|
|
if (!isDeepStrictEqual(JSON.parse(execFileSync(daemon, ['--build-metadata'], { encoding: 'utf8', timeout: 15_000, maxBuffer: 65536 })), receipt.buildMetadata)) throw Error('Daemon metadata mismatch');
|
|
await copyFile(packArchive, join(output, 'provider-pack.tar.gz'));
|
|
await copyFile(daemon, join(output, 'paperclip-runnerd'));
|
|
await copyFile(new URL('../docker/daytona-runner/Dockerfile.release', import.meta.url), join(output, 'Dockerfile'));
|
|
await copyFile(join(dirs[0], 'linux-x64/provider-pack.json'), join(output, 'provider-pack.json'));
|
|
for (const dir of dirs) await rm(dir, { recursive: true });
|
|
const evidence = { sourceRevision: source, producerRunId: runId, producerWorkflowSource: run.head_sha, producerAttempt: run.run_attempt, providerPackDigest: pack.digest,
|
|
daemonSha256: sha256, baseImage: process.env.RELEASE_BASE_IMAGE, artifacts: selected.map(a => ({ id: a.id, name: a.name, digest: a.digest })), providerCalls: 0 };
|
|
await writeFile(resolve(output, '../release-image-inputs.json'), JSON.stringify(evidence, null, 2) + '\n');
|
|
console.log(JSON.stringify(evidence));
|
|
}
|
|
|
|
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) await main();
|