mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-23 13:13:46 +01:00
Bind optional ACP candidate assets into local and Daytona provider packs
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
411df9fa58
commit
1cee50ed48
7 files changed
+128
-1
No files matched your search
@@ -34,10 +34,13 @@ RUN pnpm install --resolution-only --ignore-scripts --no-frozen-lockfile \
|
||||
&& sha256sum -c /tmp/provider-lock.sha256 \
|
||||
&& pnpm install --frozen-lockfile --filter '@paperclipai/paperclip-runner...'
|
||||
ARG PAPERCLIP_RUNNER_SOURCE_REVISION
|
||||
# Optional qualification assets; this never promotes candidate profiles.
|
||||
ARG PAPERCLIP_RUNNER_CANDIDATE_PROVIDERS=
|
||||
RUN test -n "${PAPERCLIP_RUNNER_SOURCE_REVISION}"
|
||||
RUN pnpm --filter @paperclipai/paperclip-runner build:typescript \
|
||||
&& PAPERCLIP_RUNNER_SOURCE_REVISION="${PAPERCLIP_RUNNER_SOURCE_REVISION}" \
|
||||
node packages/paperclip-runner/scripts/build-provider-pack.mjs /provider-pack \
|
||||
"--candidate-providers=${PAPERCLIP_RUNNER_CANDIDATE_PROVIDERS}" \
|
||||
&& chmod -R a+rX /provider-pack
|
||||
|
||||
# Fleet sandbox base image. Keep this section aligned with
|
||||
|
||||
@@ -77,3 +77,24 @@ with source dependency changes; registry-time resolution drift fails closed.
|
||||
Keep one latest stable CLI installation per provider; refresh exact runtime
|
||||
versions and qualification digests together, never install a private older copy
|
||||
or download dependencies when a task starts.
|
||||
|
||||
## Candidate ACP qualification assets
|
||||
|
||||
Provider branches can build their pinned assets with
|
||||
`node packages/paperclip-runner/scripts/build-provider-pack.mjs /absolute/pack --candidate-providers=cursor`
|
||||
(or `copilot` or `pi`). The source revision must include the named provider's
|
||||
builder. Assets are installed at build time under `provider-assets/<provider>/<platform>-<architecture>`.
|
||||
The pack manifest binds each complete asset tree. Runtime admission separately
|
||||
checks the provider's source-owned closure pins and copies a verified launch snapshot.
|
||||
A pack with candidate assets does not qualify or enable that provider.
|
||||
|
||||
For an isolated Linux x64 Daytona qualification image, pass
|
||||
`--build-arg PAPERCLIP_RUNNER_CANDIDATE_PROVIDERS=cursor` with the normal build arguments.
|
||||
Use each provider branch's recorded version and explicit model. Keep credentials
|
||||
out of images. Paid qualification requires bound provider and Daytona credentials,
|
||||
inspectable spend, and the shared $100 ceiling recorded in the capability report.
|
||||
|
||||
The pack builder tests its copied Node interpreter after relocation. Use a
|
||||
standalone Node distribution if the host interpreter depends on a package manager's
|
||||
private shared libraries. Pi additionally pins its complete portable interpreter
|
||||
and npm dependency graph.
|
||||
@@ -18,10 +18,11 @@ import { tmpdir } from "node:os";
|
||||
import { dirname, join, relative, resolve } from "node:path";
|
||||
import { createRequire } from "node:module";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { parseProviderPackArguments, materializeCandidateProviderPack } from "./candidate-provider-pack.mjs";
|
||||
|
||||
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const workspaceRoot = resolve(packageRoot, "../..");
|
||||
const outputArgument = process.argv.slice(2).find((value) => value !== "--");
|
||||
const { output: outputArgument, candidates } = parseProviderPackArguments(process.argv.slice(2));
|
||||
const outputRoot = resolve(
|
||||
process.cwd(),
|
||||
outputArgument ?? join(packageRoot, "provider-pack"),
|
||||
@@ -163,6 +164,24 @@ try {
|
||||
mkdirSync(dirname(stableNodeCommand), { recursive: true, mode: 0o755 });
|
||||
copyFileSync(process.execPath, stableNodeCommand);
|
||||
chmodSync(stableNodeCommand, 0o755);
|
||||
const relocatedNode = spawnSync(stableNodeCommand, ["--version"], {
|
||||
cwd: temporaryRoot, env: { PATH: "/usr/bin:/bin" }, encoding: "utf8", timeout: 10_000,
|
||||
});
|
||||
if (relocatedNode.status !== 0 || relocatedNode.stdout.trim() !== `v${process.versions.node}`) {
|
||||
throw new Error("Provider pack Node is not portable after relocation; build with a standalone Node distribution");
|
||||
}
|
||||
|
||||
const candidateProviders = {};
|
||||
for (const provider of candidates) {
|
||||
const assetPath = `provider-assets/${provider}/${process.platform}-${process.arch}`;
|
||||
const metadata = await materializeCandidateProviderPack({ provider, outputRoot: join(temporaryRoot, assetPath) });
|
||||
if (typeof metadata?.version !== "string" || !metadata.version || metadata.version.length > 120
|
||||
|| !/^sha256:[a-f0-9]{64}$/.test(metadata.profileDigest)
|
||||
|| !/^sha256:[a-f0-9]{64}$/.test(metadata.closureDigest)) throw new Error("Candidate builder omitted its pinned identity");
|
||||
candidateProviders[provider] = { version: metadata.version, profileDigest: metadata.profileDigest,
|
||||
closureDigest: metadata.closureDigest, qualification: "pending", path: assetPath,
|
||||
sha256: sha256Tree(join(temporaryRoot, assetPath)) };
|
||||
}
|
||||
|
||||
// pnpm's generated .bin shims embed the temporary deployment directory in
|
||||
// NODE_PATH. That makes an otherwise identical provider pack hash differ on
|
||||
@@ -312,6 +331,7 @@ try {
|
||||
codex:
|
||||
"sha256:c4538599d1ab767db5dff50934f13bb5ba313a59d9c4a83e993fac4617ea63d3",
|
||||
},
|
||||
...(candidates.length ? { candidateProviders } : {}),
|
||||
artifacts: {
|
||||
nodeCommand: {
|
||||
path: nodeCommand,
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
const CANDIDATES = new Set(["cursor", "copilot", "pi"]);
|
||||
|
||||
export function parseProviderPackArguments(args) {
|
||||
let output;
|
||||
const candidates = [];
|
||||
for (const value of args.filter(value => value !== "--")) {
|
||||
if (value.startsWith("--candidate-providers=")) {
|
||||
for (const provider of value.slice("--candidate-providers=".length).split(",").filter(Boolean)) {
|
||||
if (!CANDIDATES.has(provider) || candidates.includes(provider)) throw new Error("Unknown or duplicate candidate provider");
|
||||
candidates.push(provider);
|
||||
}
|
||||
} else if (value.startsWith("--") || output !== undefined) throw new Error("Invalid provider-pack arguments");
|
||||
else output = value;
|
||||
}
|
||||
return { output, candidates };
|
||||
}
|
||||
|
||||
/** Closed source-owned builder registry; provider branches add their exact pins. */
|
||||
export async function materializeCandidateProviderPack({ provider, outputRoot }) {
|
||||
if (!CANDIDATES.has(provider)) throw new Error("Unknown candidate provider");
|
||||
throw new Error(`The ${provider} candidate distribution builder is not included in this source revision`);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { parseProviderPackArguments, materializeCandidateProviderPack } from "./candidate-provider-pack.mjs";
|
||||
|
||||
test("candidate builds are explicit and leave qualified-only builds unchanged", () => {
|
||||
assert.deepEqual(parseProviderPackArguments(["--", "/pack"]), { output: "/pack", candidates: [] });
|
||||
assert.deepEqual(parseProviderPackArguments(["/pack", "--candidate-providers=pi,cursor"]), { output: "/pack", candidates: ["pi", "cursor"] });
|
||||
});
|
||||
test("candidate builder cannot admit unknown providers, options or duplicate assets", async () => {
|
||||
for (const args of [["--candidate-providers=cursor,cursor"], ["--candidate-providers=other"], ["--executable=/tmp/x"], ["/one", "/two"]]) {
|
||||
assert.throws(() => parseProviderPackArguments(args));
|
||||
}
|
||||
await assert.rejects(materializeCandidateProviderPack({ provider: "arbitrary", outputRoot: "/tmp/unused" }), /Unknown candidate/);
|
||||
});
|
||||
@@ -1044,6 +1044,26 @@ describe("remote provider pack manifest", () => {
|
||||
expect(readRemoteProviderPackManifest(root).payload.pins.opencode).toBe(
|
||||
"1.18.29",
|
||||
);
|
||||
const candidatePath = "provider-assets/pi/linux-x64";
|
||||
await mkdir(join(root, candidatePath), { recursive: true });
|
||||
await writeFile(join(root, candidatePath, "runtime"), "pinned runtime");
|
||||
const candidates = { pi: { version: "0.0.33", profileDigest: digest("profile"),
|
||||
closureDigest: digest("closure"), qualification: "pending", path: candidatePath,
|
||||
sha256: sha256DirectoryTree(join(root, candidatePath)) } };
|
||||
Object.assign(payload, { candidateProviders: candidates });
|
||||
await writeManifest();
|
||||
expect(readRemoteProviderPackManifest(root).payload.candidateProviders?.pi?.qualification).toBe("pending");
|
||||
await writeFile(join(root, candidatePath, "runtime"), "substitute runtime");
|
||||
expect(() => readRemoteProviderPackManifest(root)).toThrow("candidate asset tree digest mismatch");
|
||||
await writeFile(join(root, candidatePath, "runtime"), "pinned runtime");
|
||||
for (const invalid of [{ path: "../outside" }, { qualification: "qualified" }]) {
|
||||
const original = { ...candidates.pi };
|
||||
Object.assign(candidates.pi, invalid);
|
||||
await writeManifest();
|
||||
expect(() => readRemoteProviderPackManifest(root)).toThrow("invalid candidate identity");
|
||||
candidates.pi = original;
|
||||
}
|
||||
await writeManifest();
|
||||
for (const [artifactName, substituteName] of [
|
||||
["nodeCommand", "productionLock"],
|
||||
["opencodeExecutable", "opencodeCommand"],
|
||||
|
||||
@@ -8962,6 +8962,10 @@ type RemoteProviderPackManifest = {
|
||||
distDigest: string;
|
||||
bridgeDigest: string;
|
||||
acpxProfileDigests: typeof REMOTE_PROVIDER_PACK_PROFILE_DIGESTS;
|
||||
candidateProviders?: Partial<Record<"cursor" | "copilot" | "pi", {
|
||||
version: string; profileDigest: string; closureDigest: string; qualification: "pending";
|
||||
path: string; sha256: string;
|
||||
}>>;
|
||||
artifacts: {
|
||||
nodeCommand: { path: string; sha256: string };
|
||||
productionLock: { path: string; sha256: string };
|
||||
@@ -9116,6 +9120,28 @@ export function readRemoteProviderPackManifest(
|
||||
"runner_remote_provider_artifact_incompatible: provider dist tree digest mismatch",
|
||||
);
|
||||
}
|
||||
if (payload.candidateProviders !== undefined) {
|
||||
const candidates = payload.candidateProviders;
|
||||
if (!candidates || typeof candidates !== "object" || Array.isArray(candidates) || Object.keys(candidates).length > 3) {
|
||||
throw new Error("runner_remote_provider_artifact_incompatible: invalid candidate inventory");
|
||||
}
|
||||
for (const [provider, candidate] of Object.entries(candidates)) {
|
||||
const expectedPath = `provider-assets/${provider}/${payload.target.platform}-${payload.target.architecture}`;
|
||||
if (!["cursor", "copilot", "pi"].includes(provider) || !candidate
|
||||
|| Object.keys(candidate).some(key => !["version", "profileDigest", "closureDigest", "qualification", "path", "sha256"].includes(key))
|
||||
|| candidate.qualification !== "pending" || candidate.path !== expectedPath
|
||||
|| typeof candidate.version !== "string" || !candidate.version || candidate.version.length > 120
|
||||
|| !/^sha256:[a-f0-9]{64}$/.test(candidate.profileDigest)
|
||||
|| !/^sha256:[a-f0-9]{64}$/.test(candidate.closureDigest)
|
||||
|| !/^sha256:[a-f0-9]{64}$/.test(candidate.sha256)) {
|
||||
throw new Error("runner_remote_provider_artifact_incompatible: invalid candidate identity");
|
||||
}
|
||||
const candidatePath = providerPackRelativePath(candidate.path, "candidate assets");
|
||||
if (sha256DirectoryTree(resolve(packRoot, candidatePath)) !== candidate.sha256) {
|
||||
throw new Error("runner_remote_provider_artifact_incompatible: candidate asset tree digest mismatch");
|
||||
}
|
||||
}
|
||||
}
|
||||
const bridgeDigest = `sha256:${createHash("sha256")
|
||||
.update(payload.artifacts.opencodeProxy.sha256)
|
||||
.update("\n")
|
||||
@@ -10486,6 +10512,7 @@ async function createRunnerdBackendWithinSessionClaim(
|
||||
"const tree=(treeRoot)=>{const digest=crypto.createHash('sha256');const visit=(directory,prefix='')=>{for(const entry of fs.readdirSync(directory,{withFileTypes:true}).sort((a,b)=>a.name.localeCompare(b.name))){const relative=prefix?prefix+'/'+entry.name:entry.name;const absolute=path.join(directory,entry.name);if(entry.isDirectory()){digest.update('directory\\0'+relative+'\\n');visit(absolute,relative)}else if(entry.isFile()){digest.update('file\\0'+relative+'\\0'+'sha256:'+crypto.createHash('sha256').update(fs.readFileSync(absolute)).digest('hex')+'\\n')}else if(entry.isSymbolicLink()){digest.update('symlink\\0'+relative+'\\0'+fs.readlinkSync(absolute)+'\\n')}else throw new Error('unsupported dist entry '+relative)}};visit(treeRoot);return 'sha256:'+digest.digest('hex')}",
|
||||
"for(const name of ['nodeCommand','productionLock','opencodeCommand','opencodeExecutable','opencodeProxy','acpxSidecar']){const artifact=manifest.payload.artifacts[name];if(hash(artifact.path)!==artifact.sha256)throw new Error(name+' digest mismatch')}",
|
||||
"if(tree(path.join(root,'dist'))!==manifest.payload.distDigest)throw new Error('dist tree digest mismatch')",
|
||||
"for(const candidate of Object.values(manifest.payload.candidateProviders||{})){if(tree(path.join(root,candidate.path))!==candidate.sha256)throw new Error('candidate asset tree digest mismatch')}",
|
||||
"const version=process.versions.node.split('.').map(Number)",
|
||||
"const minimum=manifest.payload.pins.nodeMinimum.split('.').map(Number)",
|
||||
"if(version[0]<minimum[0]||(version[0]===minimum[0]&&(version[1]<minimum[1]||(version[1]===minimum[1]&&version[2]<minimum[2]))))throw new Error('Node version incompatible')",
|
||||
|
||||
Reference in new issue
Block a user