mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-25 07:27:13 +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>
269 lines
16 KiB
JavaScript
269 lines
16 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Derives the Google Antigravity model catalog from the pinned 1.5.2 runtime.
|
|
*
|
|
* Generation (on a host with the pinned closure installed) does two reads and
|
|
* requires them to agree:
|
|
* - live: the real patched runtime is started without a credential or prompt,
|
|
* authenticated with `gemini-api-key` (the server does not validate the key
|
|
* and builds that catalog locally), and one session lists its models;
|
|
* - static: the server's built-in catalog table, read from the verified
|
|
* vendor archive, supplies every family's levels, including the Gemini 4
|
|
* families the server lists only for Agent Platform.
|
|
* The output is bound to the runtime version and the vendor archive identity.
|
|
* `--check` needs no runtime: it rejects a hand-edited file and a file whose
|
|
* binding no longer matches the checked-in distribution declaration.
|
|
*/
|
|
import { spawn } from "node:child_process";
|
|
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { dirname, join, resolve } from "node:path";
|
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
import { inflateRawSync } from "node:zlib";
|
|
|
|
const PACKAGE_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
const DISTRIBUTIONS_PATH = join(PACKAGE_ROOT, "antigravity-distributions.json");
|
|
export const ANTIGRAVITY_MODELS_OUTPUT = resolve(PACKAGE_ROOT, "../shared/src/antigravity-models.generated.ts");
|
|
const SOURCE_PLATFORM = "darwin-arm64";
|
|
const SCHEMA = "paperclip.antigravity.model_catalog.v1";
|
|
const MODEL_SELECTION_SOURCE = "google3/cloud/developer_experience/antigravity_extensions/acp_server/model_selection.py";
|
|
const LEVELS = { MINIMAL: "minimal", LOW: "low", MEDIUM: "medium", HIGH: "high", EXTRA_HIGH: "extra_high" };
|
|
/** Not a credential: the server stores it without a network call, and no prompt is sent. */
|
|
const PLACEHOLDER_API_KEY = "paperclip-catalog-probe-sends-no-prompt";
|
|
const BEGIN = "/* BEGIN GENERATED CATALOG */";
|
|
const END = "/* END GENERATED CATALOG */";
|
|
const fail = message => { throw new Error(`Antigravity model catalog: ${message}`); };
|
|
|
|
/** Reads the families from `DEFAULT_MODEL_METADATA_MAP` in the server's own source.
|
|
* Every entry must be a `_thinking_family(...)` call this parser fully understands. */
|
|
export function parseAntigravityCatalogSource(source) {
|
|
const tuples = new Map();
|
|
for (const match of source.matchAll(/^(_[A-Z_]+) = \(\s*([^)]*?)\s*\)$/gm)) {
|
|
tuples.set(match[1], parseLevels(match[2]));
|
|
}
|
|
const start = source.indexOf("\nDEFAULT_MODEL_METADATA_MAP = {\n");
|
|
const end = source.indexOf("\n}\n", start);
|
|
if (start < 0 || end < 0) fail("the built-in catalog table was not found");
|
|
const body = source.slice(start + "\nDEFAULT_MODEL_METADATA_MAP = {\n".length, end);
|
|
const code = body.split("\n").filter(line => !line.trim().startsWith("#")).join("\n").trim();
|
|
const calls = code.split(/\*\*_thinking_family\(/).map(part => part.trim()).filter(Boolean);
|
|
if (!code.startsWith("**_thinking_family(")) fail("the built-in catalog has an entry this generator does not understand");
|
|
const families = calls.map(call => {
|
|
const strings = [...call.matchAll(/^\s*"([^"]+)",\s*$/gm)].map(match => match[1]);
|
|
if (strings.length !== 2) fail("a catalog family has an unexpected shape");
|
|
const [id, label] = strings;
|
|
let levels;
|
|
const named = call.match(/^\s*(_[A-Z_]+),\s*$/m);
|
|
const inline = call.match(/^\s*\(\s*([\s\S]*?)\s*\),\s*$/m);
|
|
if (named) levels = tuples.get(named[1]);
|
|
else if (inline) levels = parseLevels(inline[1]);
|
|
if (!levels?.length) fail(`levels for ${id} were not found`);
|
|
const base = call.match(/base_model_id="([^"]+)"/);
|
|
const agentPlatformOnly = /agent_platform_only=True/.test(call);
|
|
const known = call.replace(/^\s*"[^"]+",\s*$/gm, "").replace(/^\s*_[A-Z_]+,\s*$/m, "").replace(/^\s*\(\s*[\s\S]*?\s*\),\s*$/m, "")
|
|
.replace(/max_tokens=[\d_]+,?/, "").replace(/base_model_id="[^"]+",?/, "").replace(/agent_platform_only=True,?/, "").replace(/\),?$/, "");
|
|
if (known.trim()) fail(`${id} has a catalog field this generator does not understand`);
|
|
if (!/^[a-z0-9][a-z0-9.-]*$/.test(id) || !label.trim()) fail("invalid family identity");
|
|
return { id, label, baseModelId: base ? base[1] : id, levels, agentPlatformOnly };
|
|
});
|
|
if (new Set(families.map(family => family.id)).size !== families.length) fail("duplicate family");
|
|
return families;
|
|
}
|
|
|
|
function parseLevels(text) {
|
|
const names = text.split(",").map(part => part.trim()).filter(Boolean);
|
|
return names.map(name => {
|
|
const match = name.match(/^sdk_types_module\.ThinkingLevel\.([A-Z_]+)$/);
|
|
if (!match || !Object.hasOwn(LEVELS, match[1])) fail(`unknown thinking level ${name}`);
|
|
return LEVELS[match[1]];
|
|
});
|
|
}
|
|
|
|
/** Reads one stored or deflated member of the verified ZIP embedded in the server. */
|
|
export function readZipMember(zip, name) {
|
|
let end = zip.length - 22;
|
|
while (end >= 0 && zip.readUInt32LE(end) !== 0x06054b50) end--;
|
|
if (end < 0) fail("embedded archive has no directory");
|
|
let cursor = zip.readUInt32LE(end + 16);
|
|
const count = zip.readUInt16LE(end + 10);
|
|
for (let index = 0; index < count; index++) {
|
|
if (zip.readUInt32LE(cursor) !== 0x02014b50) fail("embedded archive directory is invalid");
|
|
const method = zip.readUInt16LE(cursor + 10), compressed = zip.readUInt32LE(cursor + 20);
|
|
const nameLength = zip.readUInt16LE(cursor + 28), extra = zip.readUInt16LE(cursor + 30), comment = zip.readUInt16LE(cursor + 32);
|
|
const local = zip.readUInt32LE(cursor + 42);
|
|
if (zip.subarray(cursor + 46, cursor + 46 + nameLength).toString("utf8") === name) {
|
|
const start = local + 30 + zip.readUInt16LE(local + 26) + zip.readUInt16LE(local + 28);
|
|
const data = zip.subarray(start, start + compressed);
|
|
return method === 0 ? data : method === 8 ? inflateRawSync(data) : fail("unsupported compression");
|
|
}
|
|
cursor += 46 + nameLength + extra + comment;
|
|
}
|
|
return fail(`${name} is not in the embedded archive`);
|
|
}
|
|
|
|
/** Minimal line-delimited JSON-RPC client. Provider text never enters errors. */
|
|
function rpcClient(child) {
|
|
const waiting = new Map();
|
|
let buffer = "", bytes = 0, failure;
|
|
const stop = error => { failure ??= error; for (const { reject } of waiting.values()) reject(failure); waiting.clear(); };
|
|
child.stdout.on("data", chunk => {
|
|
bytes += chunk.length;
|
|
if (bytes > 4 * 1024 * 1024) { stop(new Error("antigravity_stdout_limit")); return; }
|
|
buffer += chunk.toString("utf8");
|
|
while (buffer.includes("\n")) {
|
|
const line = buffer.slice(0, buffer.indexOf("\n")); buffer = buffer.slice(buffer.indexOf("\n") + 1);
|
|
if (!line.trim()) continue;
|
|
let message;
|
|
try { message = JSON.parse(line); } catch { stop(new Error("antigravity_malformed_json")); return; }
|
|
if (message.method !== undefined) {
|
|
// Requests from the agent are refused; notifications are ignored.
|
|
if (message.id !== undefined) child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", id: message.id, error: { code: -32601, message: "unsupported" } })}\n`);
|
|
continue;
|
|
}
|
|
const entry = waiting.get(message.id);
|
|
if (!entry) continue;
|
|
waiting.delete(message.id);
|
|
if (message.error) entry.reject(Object.assign(new Error(`antigravity_request_rejected:${entry.method}`), { rpcError: { code: message.error.code, message: String(message.error.message ?? "").slice(0, 300) } }));
|
|
else entry.resolve(message.result);
|
|
}
|
|
});
|
|
child.once("error", () => stop(new Error("antigravity_spawn_failure")));
|
|
child.once("close", () => stop(new Error("antigravity_exited")));
|
|
let next = 1;
|
|
return (method, params, timeoutMs = 30_000) => new Promise((resolve, reject) => {
|
|
if (failure) { reject(failure); return; }
|
|
const id = next++;
|
|
const timer = setTimeout(() => { waiting.delete(id); reject(new Error(`antigravity_timeout:${method}`)); }, timeoutMs);
|
|
waiting.set(id, { method, resolve: value => { clearTimeout(timer); resolve(value); }, reject: error => { clearTimeout(timer); reject(error); } });
|
|
child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", id, method, params })}\n`);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Starts the pinned patched runtime with only an API-key auth choice, runs
|
|
* `steps(request, workspace)` and always stops the process tree. Never sends a
|
|
* prompt.
|
|
*/
|
|
export async function withPromptFreeAntigravitySession(steps) {
|
|
const { antigravityDistribution, verifyAntigravityDistribution } = await import("./materialize-antigravity-distribution.mjs");
|
|
const { antigravityRuntimeCachePath } = await import("./antigravity-provisioner-layout.mjs");
|
|
const { antigravityMetadataEnvironment, stopAntigravityMetadataChild } = await import("./probe-antigravity-metadata.mjs");
|
|
const distribution = await antigravityDistribution();
|
|
if (`${distribution.platform}-${distribution.architecture}` !== SOURCE_PLATFORM) fail(`generate on ${SOURCE_PLATFORM}`);
|
|
const runtimeDirectory = antigravityRuntimeCachePath(distribution.closureSha256, distribution.platform, distribution.architecture);
|
|
await verifyAntigravityDistribution(runtimeDirectory, distribution);
|
|
const root = await mkdtemp(join(tmpdir(), "paperclip-antigravity-catalog-"));
|
|
let child;
|
|
try {
|
|
const env = { ...antigravityMetadataEnvironment(root, runtimeDirectory), GEMINI_API_KEY: PLACEHOLDER_API_KEY };
|
|
for (const key of ["HOME", "GEMINI_HOME", "XDG_CONFIG_HOME", "XDG_DATA_HOME", "XDG_CACHE_HOME", "TMPDIR"]) await mkdir(env[key], { mode: 0o700 });
|
|
const workspace = join(root, "workspace");
|
|
await mkdir(workspace, { mode: 0o700 });
|
|
child = spawn(join(runtimeDirectory, distribution.executable), distribution.args, { cwd: root, env, stdio: "pipe", detached: true });
|
|
child.stderr.resume();
|
|
const request = rpcClient(child);
|
|
const initialized = await request("initialize", { protocolVersion: 1, clientInfo: { name: "paperclip-runner", version: "1" }, clientCapabilities: {} });
|
|
if (initialized?.agentInfo?.name !== "antigravity-acp" || initialized.agentInfo.version !== distribution.version) fail("runtime identity differs from the pin");
|
|
await request("authenticate", { methodId: "gemini-api-key" });
|
|
return { distribution, result: await steps(request, workspace) };
|
|
} finally {
|
|
await stopAntigravityMetadataChild(child, { eofTimeoutMs: 1_000, terminateTimeoutMs: 1_000, killTimeoutMs: 1_000 });
|
|
await rm(root, { recursive: true, force: true });
|
|
}
|
|
}
|
|
|
|
/** The API-key catalog exactly as one fresh native session lists it. */
|
|
export async function readLiveApiKeyCatalog() {
|
|
return withPromptFreeAntigravitySession(async (request, workspace) => {
|
|
const session = await request("session/new", { cwd: workspace, mcpServers: [] });
|
|
const models = session?.models;
|
|
if (!Array.isArray(models?.availableModels) || typeof models.currentModelId !== "string") fail("session did not list models");
|
|
await request("session/close", { sessionId: session.sessionId }).catch(() => undefined);
|
|
return {
|
|
defaultModelId: models.currentModelId,
|
|
models: models.availableModels.map(model => ({ id: model.modelId, label: model.name })),
|
|
};
|
|
});
|
|
}
|
|
|
|
async function staticCatalog(distribution) {
|
|
const { antigravityRuntimeCachePath } = await import("./antigravity-provisioner-layout.mjs");
|
|
const { antigravityEmbeddedArchive, ANTIGRAVITY_PATCH_TARGETS } = await import("./patch-antigravity-runtime.mjs");
|
|
const directory = antigravityRuntimeCachePath(distribution.closureSha256, distribution.platform, distribution.architecture);
|
|
// The patch replaces server.py and SDK files only; the catalog table is vendor source.
|
|
const server = await readFile(join(directory, distribution.executable));
|
|
const { start, length } = antigravityEmbeddedArchive(server, ANTIGRAVITY_PATCH_TARGETS[SOURCE_PLATFORM]);
|
|
return parseAntigravityCatalogSource(readZipMember(server.subarray(start, start + length), MODEL_SELECTION_SOURCE).toString("utf8"));
|
|
}
|
|
|
|
/** Joins the two reads; any disagreement stops generation. */
|
|
export function buildAntigravityModelCatalog({ families, live, binding }) {
|
|
const expanded = families.filter(family => !family.agentPlatformOnly).flatMap(family => family.levels.map(level => `${family.id}-${level}`));
|
|
const liveIds = live.models.map(model => model.id);
|
|
if (JSON.stringify(expanded) !== JSON.stringify(liveIds)) fail("the live API-key catalog differs from the built-in table");
|
|
if (!liveIds.includes(live.defaultModelId)) fail("the live default model is not listed");
|
|
const labels = new Map(live.models.map(model => [model.id, model.label]));
|
|
for (const family of families) {
|
|
for (const level of family.levels) {
|
|
const id = `${family.id}-${level}`;
|
|
if (labels.has(id) && !labels.get(id).startsWith(`${family.label} (`)) fail(`label for ${id} differs from its family`);
|
|
}
|
|
}
|
|
return { schema: SCHEMA, source: binding, apiKey: { defaultModelId: live.defaultModelId, models: live.models }, families };
|
|
}
|
|
|
|
export function bindingFromDeclaration(declaration) {
|
|
const item = declaration.platforms?.[SOURCE_PLATFORM];
|
|
if (!item) fail(`${SOURCE_PLATFORM} is not declared`);
|
|
return { runtimeVersion: declaration.version, platform: SOURCE_PLATFORM, archiveSha256: item.archiveSha256, vendorClosureSha256: item.vendorClosureSha256 };
|
|
}
|
|
|
|
export function renderAntigravityModelCatalog(catalog) {
|
|
return `// Generated by packages/paperclip-runner/scripts/generate-antigravity-models.mjs from the
|
|
// pinned Google Antigravity runtime. Do not edit; regenerate with
|
|
// \`node packages/paperclip-runner/scripts/generate-antigravity-models.mjs\` on darwin-arm64.
|
|
${BEGIN}
|
|
export const ANTIGRAVITY_GENERATED_MODEL_CATALOG = ${JSON.stringify(catalog, null, 2)} as const;
|
|
${END}
|
|
`;
|
|
}
|
|
|
|
export function parseRenderedCatalog(text) {
|
|
const start = text.indexOf(BEGIN), end = text.indexOf(END);
|
|
if (start < 0 || end < 0) fail("generated markers are missing");
|
|
const body = text.slice(start + BEGIN.length, end).trim();
|
|
const match = body.match(/^export const ANTIGRAVITY_GENERATED_MODEL_CATALOG = ([\s\S]*) as const;$/);
|
|
if (!match) fail("generated body has an unexpected shape");
|
|
return JSON.parse(match[1]);
|
|
}
|
|
|
|
/** Static staleness check used by the package build. */
|
|
export async function checkAntigravityModelCatalog({ output = ANTIGRAVITY_MODELS_OUTPUT, declarationPath = DISTRIBUTIONS_PATH } = {}) {
|
|
const text = await readFile(output, "utf8");
|
|
const catalog = parseRenderedCatalog(text);
|
|
if (renderAntigravityModelCatalog(catalog) !== text) fail("generated file was edited by hand; regenerate it");
|
|
if (catalog.schema !== SCHEMA) fail("unexpected schema");
|
|
const expected = bindingFromDeclaration(JSON.parse(await readFile(declarationPath, "utf8")));
|
|
if (JSON.stringify(catalog.source) !== JSON.stringify(expected)) fail("catalog is stale: the pinned Antigravity runtime changed; regenerate it on darwin-arm64");
|
|
buildAntigravityModelCatalog({ families: catalog.families, live: catalog.apiKey, binding: catalog.source });
|
|
return catalog;
|
|
}
|
|
|
|
async function main() {
|
|
if (process.argv.includes("--check")) {
|
|
await checkAntigravityModelCatalog();
|
|
process.stdout.write("Antigravity model catalog is current.\n");
|
|
return;
|
|
}
|
|
const { distribution, result: live } = await readLiveApiKeyCatalog();
|
|
const binding = bindingFromDeclaration(JSON.parse(await readFile(DISTRIBUTIONS_PATH, "utf8")));
|
|
if (binding.runtimeVersion !== distribution.version) fail("runtime version differs from the declaration");
|
|
const catalog = buildAntigravityModelCatalog({ families: await staticCatalog(distribution), live, binding });
|
|
await writeFile(ANTIGRAVITY_MODELS_OUTPUT, renderAntigravityModelCatalog(catalog));
|
|
process.stdout.write(`Wrote ${catalog.apiKey.models.length} API-key models and ${catalog.families.length} families.\n`);
|
|
}
|
|
|
|
if (process.argv[1] && pathToFileURL(resolve(process.argv[1])).href === import.meta.url) {
|
|
main().catch(error => { process.stderr.write(`${error.message}\n`); process.exitCode = 1; });
|
|
}
|