mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-25 16:14:26 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The Paperclip Runner ships a provider pack with pinned provider runtimes and small entrypoints > - Most provider entrypoints, such as the Kimi metadata probe and the ACPX sidecar, are esbuild bundles that run as one file > - The Copilot metadata probe is plain `tsc` output that imports sibling driver modules > - So an environment that installs only selected provider-pack files cannot run the Copilot probe > - This pull request makes the Copilot metadata probe a standalone verified entrypoint, like the Kimi probe > - The benefit is that every metadata probe has the same self-contained shape, and a consumer can ship the probe as one file ## Linked Issues or Issue Description No public issue exists. This is an enhancement. **What existing behavior does this improve?** The Copilot metadata probe entrypoint (`dist/cli/copilot-metadata-probe.js`, the `paperclip-runner-copilot-metadata-probe` bin and provider-pack shim). **Subsystem affected** Paperclip Runner provider pack build (`packages/paperclip-runner`). **Current behavior** The probe is plain `tsc` output. It imports `../drivers/copilot-metadata-probe.js` and more modules. It fails when a consumer installs only selected provider-pack artifacts. The Kimi probe does not have this problem because `scripts/build-verified-provider-entrypoints.mjs` bundles it. **Proposed behavior** The build bundles the Copilot probe into one self-contained file, like the Kimi probe. The bundle still finds the pinned Copilot assets when it runs from `dist/cli/`. **Reason and benefit** Every metadata probe has the same standalone shape. A consumer can ship the probe as one file. An alternative was to ship the full `dist/drivers` tree with the probe, but that keeps the multi-file shape. **Breaking changes** None. The bin name, the output path and the probe output do not change. ## What Changed - `scripts/build-verified-provider-entrypoints.mjs`: add `copilot-metadata-probe` (source `src/cli/copilot-metadata-probe.ts`, outputs `dist/cli/copilot-metadata-probe.js` and `.cjs`) with the same format and flags as `kimi-metadata-probe`. The bundler asserts one output and only `node:` imports. - `src/cli/copilot-metadata-probe.ts`: move the top-level `await` into `main()`. esbuild cannot emit top-level `await` in the CommonJS bundle. Output and exit codes do not change. - `src/drivers/acpx/provider-assets-root.ts`: when no package root is bound, accept the bundled `dist/cli/copilot-metadata-probe.(js|cjs)` module URL for the `copilot` provider only. This is the same rule the bundled ACPX sidecar uses. Before this change, the bundle's `import.meta.url` is the `dist/cli` file, not `dist/drivers/acpx/copilot-installation.js`, so the module-URL lookup failed. The bound `PAPERCLIP_ACPX_PROVIDER_PACKAGE_ROOT` path does not change. - Tests: a bundler test that runs both bundles alone in a temporary pack layout, and an asset-root test for the bundled probe path that also proves other providers do not get the new path. ## Verification - `node --test scripts/build-verified-provider-entrypoints.test.mjs` (44 tests, includes the new standalone-run test) - `pnpm exec vitest run src/drivers/acpx/provider-assets-root.test.ts src/drivers/copilot-metadata-probe.test.ts src/drivers/acpx/copilot-installation.test.ts` - `node --test scripts/kimi-metadata-probe.test.mjs scripts/provider-pack-executable-shims.test.mjs test/acpx-codex-package-contract.test.mjs` - `pnpm exec vitest run server/src/__tests__/copilot-connection-probe.test.ts` - `pnpm --filter @paperclipai/paperclip-runner run typecheck:typescript` - Manual check on darwin-arm64 with the pinned Copilot closure installed, child process spawn denied by a preload: - Bundled `.js` and `.cjs`, no bound root: installation verification passes and the probe reaches the spawn step. - Same run without the `provider-assets-root.ts` change: `COPILOT_INSTALLATION_INVALID`. - Bundled `.js` with `PAPERCLIP_ACPX_PROVIDER_PACKAGE_ROOT` bound: installation verification passes. - `pnpm verify` requires broader coverage (the bundler is a broad input), so CI supplies it. ## Risks - Low risk. The bin name, output path and shim do not change. The probe output and exit codes do not change. - The new module-URL rule accepts only `/dist/cli/copilot-metadata-probe.(js|cjs)` and only for `copilot`. It resolves to the package that holds `dist/cli`, the same as the sidecar rule. - The build now also writes `dist/cli/copilot-metadata-probe.cjs`. Nothing reads it yet. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used - Provider: Anthropic Claude - Model: Claude Opus 5.5 (`claude-opus-5-5`) - Mode: agentic coding with tool use (shell, file edits, test runs) ## 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 Opus 5.5 <noreply@anthropic.com>
197 lines
8.4 KiB
JavaScript
197 lines
8.4 KiB
JavaScript
import { chmod, copyFile, cp, mkdir } from "node:fs/promises";
|
|
import { builtinModules } from "node:module";
|
|
import { dirname, resolve } from "node:path";
|
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
|
import { build } from "esbuild";
|
|
|
|
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
|
|
export const verifiedProviderEntrypoints = Object.freeze([
|
|
Object.freeze({
|
|
name: "cursor-cloud-app-server-proxy",
|
|
source: resolve(packageRoot, "src/cli/cursor-cloud-app-server-proxy.ts"),
|
|
output: resolve(packageRoot, "dist/cli/cursor-cloud-app-server-proxy.js"),
|
|
verifiedOutput: resolve(packageRoot, "dist/cli/cursor-cloud-app-server-proxy.cjs"),
|
|
}),
|
|
Object.freeze({
|
|
name: "kimi-metadata-probe",
|
|
source: resolve(packageRoot, "src/cli/kimi-metadata-probe.ts"),
|
|
output: resolve(packageRoot, "dist/cli/kimi-metadata-probe.js"),
|
|
verifiedOutput: resolve(packageRoot, "dist/cli/kimi-metadata-probe.cjs"),
|
|
}),
|
|
Object.freeze({
|
|
name: "copilot-metadata-probe",
|
|
source: resolve(packageRoot, "src/cli/copilot-metadata-probe.ts"),
|
|
output: resolve(packageRoot, "dist/cli/copilot-metadata-probe.js"),
|
|
verifiedOutput: resolve(packageRoot, "dist/cli/copilot-metadata-probe.cjs"),
|
|
}),
|
|
Object.freeze({
|
|
name: "provision-antigravity",
|
|
source: resolve(packageRoot, "scripts/provision-antigravity.mjs"),
|
|
output: resolve(packageRoot, "dist/cli/provision-antigravity.js"),
|
|
verifiedOutput: resolve(packageRoot, "dist/cli/provision-antigravity.cjs"),
|
|
}),
|
|
Object.freeze({
|
|
name: "provision-cursor",
|
|
source: resolve(packageRoot, "scripts/provision-cursor.mjs"),
|
|
output: resolve(packageRoot, "dist/cli/provision-cursor.js"),
|
|
verifiedOutput: resolve(packageRoot, "dist/cli/provision-cursor.cjs"),
|
|
}),
|
|
Object.freeze({
|
|
name: "acpx-runtime-sidecar",
|
|
source: resolve(packageRoot, "src/cli/acpx-runtime-sidecar.ts"),
|
|
output: resolve(packageRoot, "dist/cli/acpx-runtime-sidecar.js"),
|
|
verifiedOutput: resolve(packageRoot, "dist/cli/acpx-runtime-sidecar.cjs"),
|
|
}),
|
|
Object.freeze({
|
|
name: "opencode-app-server-proxy",
|
|
source: resolve(packageRoot, "src/cli/opencode-app-server-proxy.ts"),
|
|
output: resolve(packageRoot, "dist/cli/opencode-app-server-proxy.js"),
|
|
verifiedOutput: resolve(
|
|
packageRoot,
|
|
"dist/cli/opencode-app-server-proxy.cjs",
|
|
),
|
|
}),
|
|
]);
|
|
|
|
const nodeBuiltins = new Set([
|
|
...builtinModules,
|
|
...builtinModules.map((name) => `node:${name}`),
|
|
]);
|
|
|
|
function assertSelfContainedBundle(entrypoint, result) {
|
|
const outputs = Object.entries(result.metafile.outputs).filter(
|
|
([, output]) => output.entryPoint !== undefined,
|
|
);
|
|
if (outputs.length !== 1) {
|
|
throw new Error(
|
|
`${entrypoint.name} bundle emitted ${outputs.length} entrypoint outputs instead of one`,
|
|
);
|
|
}
|
|
const imports = outputs[0][1].imports;
|
|
for (const dependency of imports) {
|
|
if (!dependency.external || !nodeBuiltins.has(dependency.path)) {
|
|
throw new Error(
|
|
`${entrypoint.name} bundle retained a non-builtin import: ${dependency.path}`,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
export async function bundleVerifiedProviderEntrypoints({ write = true } = {}) {
|
|
if (write) {
|
|
await mkdir(resolve(packageRoot, "dist/providers"), { recursive: true });
|
|
await cp(resolve(packageRoot, "src/providers"), resolve(packageRoot, "dist/providers"), { recursive: true });
|
|
await copyFile(resolve(packageRoot, "cursor-distributions.json"), resolve(packageRoot, "dist/cursor-distributions.json"));
|
|
await copyFile(resolve(packageRoot, "antigravity-distributions.json"), resolve(packageRoot, "dist/antigravity-distributions.json"));
|
|
await mkdir(resolve(packageRoot, "dist/cli"), { recursive: true });
|
|
await copyFile(resolve(packageRoot, "scripts/patch-antigravity-runtime.admission.py"), resolve(packageRoot, "dist/cli/patch-antigravity-runtime.admission.py"));
|
|
}
|
|
const results = [];
|
|
for (const entrypoint of verifiedProviderEntrypoints) {
|
|
const buildBundle = async (outfile, format) => {
|
|
const result = await build({
|
|
entryPoints: [entrypoint.source],
|
|
outfile,
|
|
bundle: true,
|
|
platform: "node",
|
|
format,
|
|
target: "node24",
|
|
absWorkingDir: entrypoint.name === "kimi-metadata-probe" ? packageRoot : undefined,
|
|
packages: "bundle",
|
|
splitting: false,
|
|
sourcemap: false,
|
|
legalComments: "none",
|
|
metafile: true,
|
|
treeShaking: true,
|
|
write,
|
|
logLevel: "silent",
|
|
banner:
|
|
format === "cjs"
|
|
? {
|
|
js: 'const __paperclipVerifiedEntrypointUrl = require("node:url").pathToFileURL(__filename).href;',
|
|
}
|
|
: undefined,
|
|
define:
|
|
format === "cjs"
|
|
? {
|
|
"import.meta.dirname": "__dirname",
|
|
"import.meta.url": "__paperclipVerifiedEntrypointUrl",
|
|
}
|
|
: undefined,
|
|
});
|
|
assertSelfContainedBundle(entrypoint, result);
|
|
return result;
|
|
};
|
|
const result = await buildBundle(entrypoint.output, "esm");
|
|
const verifiedResult = await buildBundle(entrypoint.verifiedOutput, "cjs");
|
|
if (write && process.platform !== "win32") {
|
|
await Promise.all([
|
|
chmod(entrypoint.output, 0o755),
|
|
chmod(entrypoint.verifiedOutput, 0o755),
|
|
]);
|
|
}
|
|
results.push({ entrypoint, result, verifiedResult });
|
|
}
|
|
await bundlePiProvisioner({ write });
|
|
await bundleKimiProvisioner({ write });
|
|
return results;
|
|
}
|
|
|
|
/** Explicit setup tooling; no provider payload is included in the npm tarball. */
|
|
export async function bundlePiProvisioner({ write = true, outputRoot = resolve(packageRoot, "dist/cli") } = {}) {
|
|
const entrypoint = { name: "provision-pi", source: resolve(packageRoot, "scripts/provision-pi.mjs") };
|
|
const result = await build({
|
|
entryPoints: [entrypoint.source], outfile: resolve(outputRoot, "provision-pi.cjs"),
|
|
bundle: true, platform: "node", format: "cjs", target: "node24", packages: "bundle",
|
|
splitting: false, sourcemap: false, legalComments: "none", metafile: true,
|
|
treeShaking: true, write, logLevel: "silent",
|
|
banner: { js: 'const __paperclipVerifiedEntrypointUrl = require("node:url").pathToFileURL(__filename).href;' },
|
|
define: { "import.meta.dirname": "__dirname", "import.meta.url": "__paperclipVerifiedEntrypointUrl" },
|
|
});
|
|
assertSelfContainedBundle(entrypoint, result);
|
|
if (write) {
|
|
const inputs = resolve(outputRoot, "pi-provision-inputs");
|
|
await mkdir(inputs, { recursive: true });
|
|
for (const [source, name] of [
|
|
["scripts/pi-distribution/package.json", "package.json"],
|
|
["scripts/pi-distribution/package-lock.json", "package-lock.json"],
|
|
["../../patches/pi-acp@0.0.33.patch", "pi-acp.patch"],
|
|
["../../patches/brace-expansion@5.0.9.patch", "brace-expansion.patch"],
|
|
["src/drivers/acpx/pi-acp-runtime.ts", "pi-acp-runtime.ts"],
|
|
["src/drivers/acpx/pi-runtime-extension.ts", "pi-runtime-extension.ts"],
|
|
]) await cp(resolve(packageRoot, source), resolve(inputs, name));
|
|
}
|
|
return result;
|
|
}
|
|
|
|
export async function bundleKimiProvisioner({ write = true, outputRoot = resolve(packageRoot, "dist/cli") } = {}) {
|
|
const entrypoint = { name: "provision-kimi", source: resolve(packageRoot, "scripts/provision-kimi.mjs") };
|
|
const result = await build({
|
|
entryPoints: [entrypoint.source], outfile: resolve(outputRoot, "provision-kimi.cjs"),
|
|
bundle: true, platform: "node", format: "cjs", target: "node24", packages: "bundle",
|
|
splitting: false, sourcemap: false, legalComments: "none", metafile: true,
|
|
treeShaking: true, write, logLevel: "silent",
|
|
banner: { js: 'const __paperclipVerifiedEntrypointUrl = require("node:url").pathToFileURL(__filename).href;' },
|
|
define: { "import.meta.dirname": "__dirname", "import.meta.url": "__paperclipVerifiedEntrypointUrl" },
|
|
});
|
|
assertSelfContainedBundle(entrypoint, result);
|
|
if (write) {
|
|
const inputs = resolve(outputRoot, "kimi-provision-inputs");
|
|
await mkdir(inputs, { recursive: true });
|
|
for (const [source, name] of [
|
|
["scripts/kimi-distribution/package.json", "package.json"],
|
|
["scripts/kimi-distribution/package-lock.json", "package-lock.json"],
|
|
]) await cp(resolve(packageRoot, source), resolve(inputs, name));
|
|
}
|
|
return result;
|
|
}
|
|
|
|
const invokedPath = process.argv[1]
|
|
? pathToFileURL(resolve(process.argv[1])).href
|
|
: null;
|
|
if (invokedPath === import.meta.url) {
|
|
await bundleVerifiedProviderEntrypoints();
|
|
}
|