mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-06 21:05:21 +02:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Local Claude, Codex, Gemini, and custom ACP adapters run through the shared embedded ACPX engine > - That engine wrapped every local agent command in a generated Bash script to inject environment variables and filter child stderr > - Windows cannot directly spawn that Bash wrapper, and npm/pnpm ACP binaries are exposed through `.cmd` shims there > - ACPX 0.12 already supports per-session child environment variables, so the wrapper is unnecessary > - This pull request registers agent commands directly, injects env through ACPX session options, captures child stderr in-process, and adds a real Node ACP spawn smoke on Ubuntu and Windows > - The benefit is one cross-platform spawn path with a reusable smoke test instead of parallel shell-wrapper implementations ## Linked Issues or Issue Description Fixes #9941. Refs #9428 and #9771. **What happened** ACPX-backed local agents failed to start on Windows because Paperclip registered a generated POSIX `.sh` wrapper as the agent command. Windows also needs the `.cmd` npm/pnpm shim when resolving built-in ACP binaries, and symlink creation can fail with `EPERM` for seeded auth/skill files. **Expected behavior** The same ACPX engine path should spawn a real ACP agent on Windows and Linux, forward Paperclip/runtime env without mutating `process.env`, preserve filtered/unfiltered child stderr behavior, and fall back to copies where Windows symlinks are unavailable. **Steps to reproduce** Run a local ACPX adapter on Windows with the prior wrapper path. ACPX attempts to spawn the generated `.sh` file and the agent never initializes. **Deployment mode** Local Paperclip adapters using `packages/adapter-utils/src/acpx-engine/`. ## What Changed - Removed generated Bash agent/env wrappers and registered local commands directly with ACPX. - Passed the resolved child environment through ACPX `sessionOptions.env`, including resume retry paths. - Added a minimal `acpx@0.12.0` package patch exposing child stderr callbacks and allowing documented uppercase env-map keys in persisted session options. - Moved stderr tee/filter behavior in-process: raw stderr remains in the per-run file while benign `nes/close` noise is omitted from live stderr. - Preferred `.cmd` ancestor binaries on Windows and added `EPERM` copy fallbacks for Codex auth seeding and Gemini skill materialization. - Added a real Node ACP echo-agent spawn smoke that can run directly on any supported platform. ## Verification - `pnpm exec vitest run packages/adapter-utils/src/acpx-engine/execute.test.ts packages/adapter-utils/src/acpx-engine/spawn-smoke.test.ts` — 57 passed. - `pnpm --filter @paperclipai/adapter-utils typecheck` — passed. - `node --test scripts/acpx-patch-packaging.test.mjs scripts/release-lib.test.mjs` — 10 passed. - Full canary release dry run under Node 24.18.0 / npm 11.16.0 — passed in an isolated scratch clone. - `git diff --check` — passed during implementation verification. - One-time GitHub Actions proof: [Ubuntu ACPX spawn smoke](https://github.com/paperclipai/paperclip/actions/runs/29924348927/job/88937774579), [Windows ACPX spawn smoke](https://github.com/paperclipai/paperclip/actions/runs/29924348927/job/88937774558), and [Canary Dry Run](https://github.com/paperclipai/paperclip/actions/runs/29924348927/job/88937774497) passed on head `f345ac69f2`; the dedicated smoke jobs are intentionally not retained in the recurring PR workflow. ## Risks - The ACPX stderr callback and env persistence exemption are carried as a pnpm dependency patch until ACPX exposes/fixes those behaviors upstream. - Child stderr is synchronously appended to preserve ordering and failure diagnostics; unusually high-volume agent stderr could briefly block the Node event loop. - The Windows-specific `.cmd` resolution and symlink `EPERM` branches are proven by the standalone smoke test and the linked one-time `windows-latest` run rather than a permanent CI gate. > 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 - OpenAI GPT-5.4 via Codex CLI, medium reasoning, repository/tool execution enabled; context-window size is not exposed in this session. ## 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 - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
195 lines
5.8 KiB
JavaScript
195 lines
5.8 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { execFileSync } from "node:child_process";
|
|
import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import test from "node:test";
|
|
|
|
const repoRoot = new URL("..", import.meta.url).pathname.replace(/\/$/, "");
|
|
|
|
function writeExecutable(path, body) {
|
|
writeFileSync(path, body, { mode: 0o755 });
|
|
}
|
|
|
|
function runPublishHelper({
|
|
pnpmMode,
|
|
npmVersionExists = false,
|
|
distTag = "canary",
|
|
callerPipefail = true,
|
|
publishTool = "pnpm",
|
|
}) {
|
|
const fixtureDir = mkdtempSync(join(tmpdir(), "paperclip-release-lib-"));
|
|
const binDir = join(fixtureDir, "bin");
|
|
const stateDir = join(fixtureDir, "state");
|
|
const callLog = join(fixtureDir, "calls.log");
|
|
mkdirSync(binDir);
|
|
mkdirSync(stateDir);
|
|
writeFileSync(callLog, "");
|
|
|
|
writeExecutable(
|
|
join(binDir, "pnpm"),
|
|
`#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
printf 'pnpm %s\\n' "$*" >> "$FAKE_CALL_LOG"
|
|
case "$PNPM_MODE" in
|
|
success)
|
|
echo "published"
|
|
exit 0
|
|
;;
|
|
tlog-then-success)
|
|
if [ ! -f "$FAKE_STATE_DIR/pnpm-called" ]; then
|
|
touch "$FAKE_STATE_DIR/pnpm-called"
|
|
echo "npm error code TLOG_CREATE_ENTRY_ERROR"
|
|
echo "npm error error creating tlog entry - (409) an equivalent entry already exists in the transparency log with UUID abc"
|
|
exit 1
|
|
fi
|
|
case " $* " in
|
|
*" --provenance=false "*)
|
|
echo "published without provenance"
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo "retry did not disable provenance"
|
|
exit 1
|
|
;;
|
|
esac
|
|
;;
|
|
tlog-always-fails)
|
|
echo "npm error code TLOG_CREATE_ENTRY_ERROR"
|
|
echo "npm error error creating tlog entry - (409) an equivalent entry already exists in the transparency log with UUID abc"
|
|
exit 1
|
|
;;
|
|
non-tlog-failure)
|
|
echo "npm error code E500"
|
|
exit 1
|
|
;;
|
|
esac
|
|
exit 1
|
|
`,
|
|
);
|
|
|
|
writeExecutable(
|
|
join(binDir, "npm"),
|
|
`#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
printf 'npm %s\\n' "$*" >> "$FAKE_CALL_LOG"
|
|
if [ "$1" = "view" ] && [ "$NPM_VERSION_EXISTS" = "true" ]; then
|
|
echo "1.2.3"
|
|
exit 0
|
|
fi
|
|
if [ "$1" = "publish" ]; then
|
|
echo "published"
|
|
exit 0
|
|
fi
|
|
exit 1
|
|
`,
|
|
);
|
|
|
|
writeExecutable(
|
|
join(binDir, "npx"),
|
|
`#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
printf 'npx %s\n' "$*" >> "$FAKE_CALL_LOG"
|
|
[ "$1" = "--yes" ] && shift
|
|
[ "$1" = "npm@10.9.7" ] && shift
|
|
exec npm "$@"
|
|
`,
|
|
);
|
|
|
|
const shellOptions = callerPipefail ? "set -euo pipefail" : "set -eu";
|
|
const script = `
|
|
${shellOptions}
|
|
source "${repoRoot}/scripts/release-lib.sh"
|
|
publish_package_to_npm ${distTag} @paperclipai/example 1.2.3 ${publishTool}
|
|
`;
|
|
|
|
let status = 0;
|
|
let output = "";
|
|
try {
|
|
output = execFileSync("bash", ["-c", script], {
|
|
cwd: fixtureDir,
|
|
encoding: "utf8",
|
|
env: {
|
|
...process.env,
|
|
PATH: `${binDir}:${process.env.PATH}`,
|
|
FAKE_CALL_LOG: callLog,
|
|
FAKE_STATE_DIR: stateDir,
|
|
NPM_VERSION_EXISTS: npmVersionExists ? "true" : "false",
|
|
PNPM_MODE: pnpmMode,
|
|
REPO_ROOT: fixtureDir,
|
|
},
|
|
stdio: ["ignore", "pipe", "pipe"],
|
|
});
|
|
} catch (error) {
|
|
status = error.status ?? 1;
|
|
output = `${error.stdout ?? ""}${error.stderr ?? ""}`;
|
|
}
|
|
|
|
return {
|
|
calls: readFileSync(callLog, "utf8"),
|
|
output,
|
|
status,
|
|
};
|
|
}
|
|
|
|
test("publish_package_to_npm returns after a successful pnpm publish", () => {
|
|
const result = runPublishHelper({ pnpmMode: "success" });
|
|
|
|
assert.equal(result.status, 0);
|
|
assert.match(result.calls, /^pnpm publish --no-git-checks --tag canary --access public$/m);
|
|
assert.doesNotMatch(result.calls, /npm view/);
|
|
assert.doesNotMatch(result.calls, /--provenance=false/);
|
|
});
|
|
|
|
test("publish_package_to_npm uses npm for bundled dependencies", () => {
|
|
const result = runPublishHelper({ pnpmMode: "success", publishTool: "npm" });
|
|
|
|
assert.equal(result.status, 0);
|
|
assert.match(result.calls, /^npx --yes npm@10\.9\.7 publish --tag canary --access public$/m);
|
|
assert.match(result.calls, /^npm publish --tag canary --access public$/m);
|
|
assert.doesNotMatch(result.calls, /^pnpm publish/m);
|
|
});
|
|
|
|
test("publish_package_to_npm retries duplicate tlog failures without provenance", () => {
|
|
const result = runPublishHelper({ pnpmMode: "tlog-then-success" });
|
|
|
|
assert.equal(result.status, 0);
|
|
assert.match(result.calls, /^npm view @paperclipai\/example@1\.2\.3 version$/m);
|
|
assert.match(
|
|
result.calls,
|
|
/^pnpm publish --no-git-checks --tag canary --access public --provenance=false$/m,
|
|
);
|
|
});
|
|
|
|
test("publish_package_to_npm treats a duplicate tlog failure as complete when npm exposes the version", () => {
|
|
const result = runPublishHelper({ pnpmMode: "tlog-always-fails", npmVersionExists: true });
|
|
|
|
assert.equal(result.status, 0);
|
|
assert.match(result.calls, /^npm view @paperclipai\/example@1\.2\.3 version$/m);
|
|
assert.doesNotMatch(result.calls, /--provenance=false/);
|
|
});
|
|
|
|
test("publish_package_to_npm does not retry unrelated publish failures", () => {
|
|
const result = runPublishHelper({ pnpmMode: "non-tlog-failure" });
|
|
|
|
assert.notEqual(result.status, 0);
|
|
assert.doesNotMatch(result.calls, /npm view/);
|
|
assert.doesNotMatch(result.calls, /--provenance=false/);
|
|
});
|
|
|
|
test("publish_package_to_npm does not mask failures when caller has no pipefail", () => {
|
|
const result = runPublishHelper({ pnpmMode: "non-tlog-failure", callerPipefail: false });
|
|
|
|
assert.notEqual(result.status, 0);
|
|
assert.doesNotMatch(result.calls, /npm view/);
|
|
assert.doesNotMatch(result.calls, /--provenance=false/);
|
|
});
|
|
|
|
test("publish_package_to_npm does not retry stable publishes without provenance", () => {
|
|
const result = runPublishHelper({ pnpmMode: "tlog-then-success", distTag: "latest" });
|
|
|
|
assert.notEqual(result.status, 0);
|
|
assert.match(result.calls, /^npm view @paperclipai\/example@1\.2\.3 version$/m);
|
|
assert.doesNotMatch(result.calls, /--provenance=false/);
|
|
});
|