The open-source app everyone uses to manage agents at work
TypeScript acpxagent-orchestrationagent-skillsagentic-aiai-agentsai-engineeringai-governanceai-toolsautonomous-agentsclaudeclaude-codeclaude-skillscodexhermesllmmcpmulti-agentopenclawproject-managementworkflow-automation
fix: make Copilot provider-pack wrappers portable (#15586)
Devin Foley0ac194450a48
diff --git a/packages/paperclip-runner/README.md b/packages/paperclip-runner/README.mdindex 5d758d956b..735cfddeb1 100644--- a/packages/paperclip-runner/README.md+++ b/packages/paperclip-runner/README.md@@ -138,6 +138,9 @@ build and include them in the server's vendored Runner output before npm packingAssembly requires the provider pack's source revision to match `sourceRevision`and its ACPX profiles and Cursor distribution to match the current source pins.An independently rehashed older pack is rejected.+Provider-pack builds replace the installed Copilot platform wrappers with relative+launchers. These wrappers remain usable after the pack moves into an image. The+build still rejects any wrapper that retains its temporary deployment path.Ordinary remote Cursor startup uses the packaged Linux daemon and verifies everyimage asset against that manifest. A mismatched image fails before the providerstarts; install the matching package and image together.diff --git a/packages/paperclip-runner/package.json b/packages/paperclip-runner/package.jsonindex 8444136502..c3fb478f7c 100644--- a/packages/paperclip-runner/package.json+++ b/packages/paperclip-runner/package.json@@ -75,7 +75,7 @@"typecheck:browser": "tsc -p tsconfig.browser.json --noEmit","test": "pnpm run test:typescript && pnpm run test:rust","test:typescript": "pnpm run test:typescript:prep && vitest run",- "test:typescript:prep": "pnpm run ensure:eval-build-deps && pnpm run build:rust && node --test test/protocol-contract.test.mjs test/acpx-sidecar-contract.test.mjs test/acpx-codex-package-contract.test.mjs test/acpx-model-selection-package-contract.test.mjs test/acpx-rich-extensions-package-contract.test.mjs test/acpx-pi-receipt-package-contract.test.mjs test/acpx-response-delivery-package-contract.test.mjs scripts/candidate-provider-pack.test.mjs scripts/cursor-provisioner-layout.test.mjs scripts/release-provider-pack.test.mjs scripts/aws-agentcore-provisioning.test.mjs scripts/build-verified-provider-entrypoints.test.mjs scripts/local-provider-smoke-environment.test.mjs scripts/materialize-opencode-binary.test.mjs",+ "test:typescript:prep": "pnpm run ensure:eval-build-deps && pnpm run build:rust && node --test test/protocol-contract.test.mjs test/acpx-sidecar-contract.test.mjs test/acpx-codex-package-contract.test.mjs test/acpx-model-selection-package-contract.test.mjs test/acpx-rich-extensions-package-contract.test.mjs test/acpx-pi-receipt-package-contract.test.mjs test/acpx-response-delivery-package-contract.test.mjs scripts/candidate-provider-pack.test.mjs scripts/cursor-provisioner-layout.test.mjs scripts/release-provider-pack.test.mjs scripts/provider-pack-executable-shims.test.mjs scripts/aws-agentcore-provisioning.test.mjs scripts/build-verified-provider-entrypoints.test.mjs scripts/local-provider-smoke-environment.test.mjs scripts/materialize-opencode-binary.test.mjs","test:typescript:vitest": "node ./scripts/run-pr-vitest-lane.mjs","test:rust": "cargo test --release --manifest-path runner/Cargo.toml --locked --workspace","test:codex": "cargo test --manifest-path runner/Cargo.toml --locked -p paperclip-runner-core --test codex_provider",diff --git a/packages/paperclip-runner/scripts/build-provider-pack.mjs b/packages/paperclip-runner/scripts/build-provider-pack.mjsindex d6a0982248..858b799c79 100644--- a/packages/paperclip-runner/scripts/build-provider-pack.mjs+++ b/packages/paperclip-runner/scripts/build-provider-pack.mjs@@ -20,6 +20,7 @@ import { dirname, join, relative, resolve } from "node:path";import { createRequire } from "node:module";import { fileURLToPath } from "node:url";import { parseProviderPackArguments, materializeCandidateProviderPack, providerPackProviders, providerPackManifestFields } from "./candidate-provider-pack.mjs";+import { writePortableCopilotShims, writePortableExecutableShim } from "./provider-pack-executable-shims.mjs";import { buildNodeStartupTimeout } from "./build-node-startup-timeout.mjs";const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");@@ -101,21 +102,6 @@ function writePortableNodeShim(name, entrypoint) {chmodSync(shimPath, 0o755);}-function writePortableExecutableShim(name, executable) {- const shimPath = join(temporaryRoot, "node_modules", ".bin", name);- writeFileSync(- shimPath,- [- "#!/bin/sh",- "set -eu",- 'basedir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)',- `exec "$basedir/../${executable}" "$@"`,- "",- ].join("\n"),- );- chmodSync(shimPath, 0o755);-}-try {const deployed = spawnSync("pnpm",@@ -204,11 +190,13 @@ try {`@anthropic-ai/claude-agent-sdk-${process.platform}-${process.arch}/claude`,);writePortableExecutableShim(+ temporaryRoot,"claude",relative(realpathSync(join(temporaryRoot, "node_modules")), realpathSync(claudeExecutable)),);- writePortableExecutableShim("node", "node/bin/node");- writePortableExecutableShim("opencode", "opencode-ai/bin/opencode.exe");+ writePortableExecutableShim(temporaryRoot, "node", "node/bin/node");+ writePortableExecutableShim(temporaryRoot, "opencode", "opencode-ai/bin/opencode.exe");+ writePortableCopilotShims(temporaryRoot);writePortableNodeShim("acpx", "acpx/dist/cli.js");writePortableNodeShim("claude-agent-acp",diff --git a/packages/paperclip-runner/scripts/provider-pack-executable-shims.mjs b/packages/paperclip-runner/scripts/provider-pack-executable-shims.mjsnew file mode 100644index 0000000000..49e5ffbe19--- /dev/null+++ b/packages/paperclip-runner/scripts/provider-pack-executable-shims.mjs@@ -0,0 +1,34 @@+import { chmodSync, existsSync, realpathSync, writeFileSync } from "node:fs";+import { createRequire } from "node:module";+import { join, relative } from "node:path";++export function writePortableExecutableShim(packRoot, name, executable) {+ const shimPath = join(packRoot, "node_modules", ".bin", name);+ writeFileSync(+ shimPath,+ [+ "#!/bin/sh",+ "set -eu",+ 'basedir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)',+ `exec "$basedir/../${executable}" "$@"`,+ "",+ ].join("\n"),+ );+ chmodSync(shimPath, 0o755);+}++export function writePortableCopilotShims(packRoot) {+ const packRequire = createRequire(join(packRoot, "package.json"));+ // Optional platform packages expose native .bin entries. Rewrite only the+ // installed entries, and resolve their pinned executable without running it.+ for (const platform of ["darwin-arm64", "darwin-x64", "linux-x64"]) {+ const name = `copilot-${platform}`;+ if (!existsSync(join(packRoot, "node_modules", ".bin", name))) continue;+ const executable = packRequire.resolve(`@github/${name}`);+ writePortableExecutableShim(+ packRoot,+ name,+ relative(realpathSync(join(packRoot, "node_modules")), realpathSync(executable)),+ );+ }+}diff --git a/packages/paperclip-runner/scripts/provider-pack-executable-shims.test.mjs b/packages/paperclip-runner/scripts/provider-pack-executable-shims.test.mjsnew file mode 100644index 0000000000..df8aa94f0d--- /dev/null+++ b/packages/paperclip-runner/scripts/provider-pack-executable-shims.test.mjs@@ -0,0 +1,59 @@+import assert from "node:assert/strict";+import { spawnSync } from "node:child_process";+import { existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";+import { tmpdir } from "node:os";+import { join } from "node:path";+import test from "node:test";+import { writePortableCopilotShims } from "./provider-pack-executable-shims.mjs";++function fixture(t) {+ const root = mkdtempSync(join(tmpdir(), "provider-shims-"));+ t.after(() => rmSync(root, { recursive: true, force: true }));+ const pack = join(root, "temporary pack");+ mkdirSync(join(pack, "node_modules", ".bin"), { recursive: true });+ writeFileSync(join(pack, "package.json"), '{"type":"module"}');+ return { root, pack };+}++for (const platform of ["darwin-arm64", "darwin-x64", "linux-x64"]) {+ test(`relocates the installed ${platform} Copilot command and preserves arguments and exit status`, (t) => {+ const { root, pack } = fixture(t);+ const name = `copilot-${platform}`;+ const installed = join(pack, "node_modules", "@github", name);+ mkdirSync(installed, { recursive: true });+ writeFileSync(join(installed, "package.json"), JSON.stringify({+ name: `@github/${name}`, exports: { ".": "./copilot" }, bin: { [name]: "copilot" },+ }));+ // A provider-free executable proves relocation without invoking a real CLI.+ writeFileSync(join(installed, "copilot"), '#!/bin/sh\nprintf "%s\\n" "$@"\nexit 17\n', { mode: 0o755 });+ const shim = join(pack, "node_modules", ".bin", name);+ writeFileSync(shim, `#!/bin/sh\nexport NODE_PATH="${pack}/node_modules"\nexit 99\n`);++ writePortableCopilotShims(pack);+ assert.equal(readFileSync(shim, "utf8").includes(root), false);+ const relocated = join(root, "relocated pack");+ renameSync(pack, relocated);+ const args = ["argument with spaces", "", "$(not-a-command)"];+ const result = spawnSync(join(relocated, "node_modules", ".bin", name), args, {+ cwd: root, env: { PATH: "/usr/bin:/bin" }, encoding: "utf8", timeout: 5_000,+ });+ assert.equal(result.error, undefined);+ assert.equal(result.status, 17);+ assert.equal(result.stdout, args.join("\n") + "\n");+ assert.equal(result.stderr, "");+ });+}++test("does not create commands for absent optional platform packages", (t) => {+ const { pack } = fixture(t);+ writePortableCopilotShims(pack);+ for (const platform of ["darwin-arm64", "darwin-x64", "linux-x64"]) {+ assert.equal(existsSync(join(pack, "node_modules", ".bin", `copilot-${platform}`)), false);+ }+});++test("fails when an installed command has no matching package", (t) => {+ const { pack } = fixture(t);+ writeFileSync(join(pack, "node_modules", ".bin", "copilot-linux-x64"), "invalid old shim");+ assert.throws(() => writePortableCopilotShims(pack), { code: "MODULE_NOT_FOUND" });+});diff --git a/tests/runner-e2e/daytona-image-content.ts b/tests/runner-e2e/daytona-image-content.tsindex 2c79b6d52a..0bb601acf0 100644--- a/tests/runner-e2e/daytona-image-content.ts+++ b/tests/runner-e2e/daytona-image-content.ts@@ -37,6 +37,7 @@ export const DAYTONA_IMAGE_INPUT_PATHS = ["packages/paperclip-runner/runner/crates","packages/paperclip-runner/scripts/acpx-sidecar-contract.mjs","packages/paperclip-runner/scripts/build-provider-pack.mjs",+ "packages/paperclip-runner/scripts/provider-pack-executable-shims.mjs","packages/paperclip-runner/scripts/build-node-startup-timeout.mjs","packages/paperclip-runner/scripts/candidate-provider-pack.mjs","packages/paperclip-runner/scripts/materialize-cursor-distribution.mjs",diff --git a/tests/runner-e2e/daytona-image.test.ts b/tests/runner-e2e/daytona-image.test.tsindex 25696be09f..bb38e762cb 100644--- a/tests/runner-e2e/daytona-image.test.ts+++ b/tests/runner-e2e/daytona-image.test.ts@@ -334,9 +334,11 @@ describe("runner E2E Daytona image contract", () => {}});- it("invalidates the image when the Cursor runtime isolation patch changes", async () => {- const root = await mkdtemp(path.join(tmpdir(), "paperclip-cursor-image-id-"));- const patchPath = "packages/paperclip-runner/scripts/cursor-runtime-patch.mjs";+ it.each([+ "packages/paperclip-runner/scripts/cursor-runtime-patch.mjs",+ "packages/paperclip-runner/scripts/provider-pack-executable-shims.mjs",+ ])("invalidates the image when %s changes", async (patchPath) => {+ const root = await mkdtemp(path.join(tmpdir(), "paperclip-provider-image-id-"));expect(DAYTONA_IMAGE_INPUT_PATHS).toContain(patchPath);const options = {repositoryRoot: root,