Repository navigation
fix(cli): stage git-ref installs the way release.sh stages packages - #13928
oliver-mee wants to merge 4 commits into
Conversation
|
| @@ -278,16 +305,24 @@ export async function installGitPayload(repo: string, sha: string, runCommand: C | |||
| await runCommand("corepack", ["pnpm", "install", "--frozen-lockfile"], { cwd: checkoutPath, env: buildEnv(), maxBuffer: 32 * 1024 * 1024 }); | |||
| await runCommand("bash", ["scripts/build-npm.sh", "--skip-checks", "--skip-typecheck"], { cwd: checkoutPath, env: buildEnv(), maxBuffer: 32 * 1024 * 1024 }); | |||
| await runCommand("corepack", ["pnpm", "-r", "--filter", "@paperclipai/server...", "--if-present", "run", "build"], { cwd: checkoutPath, env: buildEnv(), maxBuffer: 32 * 1024 * 1024 }); | |||
| // Stage the non-built publish artifacts the way release.sh does. Bundled packages go through | |||
| // prepare-bundled-package, which copies `files` without running prepack, so nothing else creates them. | |||
| await runCommand("bash", ["scripts/prepare-server-ui-dist.sh"], { cwd: checkoutPath, env: buildEnv({ PAPERCLIP_RELEASE_REUSE_UI_DIST: "1" }), maxBuffer: 32 * 1024 * 1024 }); | |||
There was a problem hiding this comment.
P2: The git-ref installer newly runs fork-controlled UI build scripts with ambient credentials
New UI build execution inherits process.env, including GH_TOKEN/GITHUB_TOKEN, from a downloaded fork.
Sanitize the git-ref build environment and remove ambient tokens before running fork-controlled package scripts.
AI prompt
Check if this security scanner issue is valid. If so, understand the root cause and fix it. If appropriate, update or add tests. Keep the change focused and preserve intended behavior.
<file name="cli/src/commands/install.ts">
<violation number="1" location="cli/src/commands/install.ts:310">
<priority>P2</priority>
<title>The git-ref installer newly runs fork-controlled UI build scripts with ambient credentials</title>
<evidence>The git-ref install path now executes `bash scripts/prepare-server-ui-dist.sh` from the downloaded repository. That script runs `pnpm ... --filter @paperclipai/ui build`, so a fork/ref controls the UI package build command and its imported build configuration. The command receives `buildEnv(...)`, which is derived from `{ ...process.env, ...extra }`; therefore ambient `GH_TOKEN` or `GITHUB_TOKEN` and other user environment secrets are inherited by the fork-controlled build. A less-trusted fork maintainer can place code in the UI build path that sends those values to a remote service when a user installs that fork/ref. The existing install confirmation warns that repository dependency and build scripts execute, but it does not remove credentials from the child-process environment.</evidence>
<recommendation>Run repository-controlled build steps with a minimal sanitized environment that excludes GH_TOKEN, GITHUB_TOKEN, cloud credentials, and other secrets. Preferably build the UI using trusted installer-owned tooling or explicitly document and enforce that git-ref builds cannot access ambient credentials.</recommendation>
</violation>
</file>
There was a problem hiding this comment.
Thanks for flagging it. I checked, and this does not add a new exposure. On current master, the git-ref install already runs code from the downloaded checkout with the same buildEnv(): pnpm install (with lifecycle scripts), scripts/build-npm.sh, and pnpm -r --filter @paperclipai/server... run build. Before the server became a bundled package, pnpm pack also ran its prepack, which is the same UI build. So the downloaded ref could already read ambient tokens before this PR, and stripping them only from the UI step would not change that.
Removing tokens such as GH_TOKEN and GITHUB_TOKEN from every git-install build step could still be a sensible hardening, but it is a separate policy change for the whole path (some installs may need a token for private dependencies). I have kept it out of this PR so it stays focused on the packaging fix, and I am happy to open an issue for it if the maintainers want one.
There was a problem hiding this comment.
The developer correctly notes that ambient credential exposure is pre-existing across the git-ref install path (lifecycle scripts, build scripts, and prior prepack hooks), so this PR does not introduce a new vulnerability. Removing tokens only for the UI build would be inconsistent and provide incomplete protection. We agree that comprehensive environment sanitization for all fork-controlled build steps is better handled as a focused follow-up hardening change. Please open a tracking issue for sanitizing the entire git-ref installer environment, and ensure the install confirmation warning clearly states that ambient credentials are visible to the downloaded ref.
`paperclipai install --ref` builds a checkout and packs it into a payload, but its packaging steps are a copy of the release flow that stopped matching it once @paperclipai/server became a bundled package. Four steps from release.sh were missing, and each one fails the install on its own: - server/ui-dist was never built. prepare-bundled-package copies `files` directly, so the server's prepack never runs (ENOENT on server/ui-dist). - skills/ was never copied into server, claude-local and codex-local (ENOENT on server/skills; the two adapters pack without their skills). - The staged bundled package was packed without --ignore-scripts, so npm re-ran the server's prepack inside the staging directory, where ../scripts/prepare-server-ui-dist.sh does not exist. - Workspace versions were not unified. plugin-sdk is 1.0.0 in source and the server pins it to its own version, 0.3.1, so the final npm install fails with ETARGET against the public registry. Run prepare-server-ui-dist.sh, copy skills/, run `release-package-map.mjs set-version` with the CLI version, and pack the staged package with --ignore-scripts, matching release.sh and release-lib.sh. The install-command tests now assert each step and its order. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
`release-package-map.mjs set-version` validates every public workspace package against the release manifest. A fork that adds an unrelated public package would fail the whole git install at that step, although the install packs only the server's workspace dependency closure. Rewrite the version and the `workspace:` ranges only for the packages this install packs, plus the CLI's ranges that point at them. Other packages and ranges are left as they are. The git-install test now models the server as a bundled package, so it goes through prepare-bundled-package and `npm pack`, and it checks the skills in the staged server directory. A new test covers the version rewrite and confirms that an unrelated package does not change. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The CLI is packed with plain `npm pack`, which does not rewrite `workspace:` ranges. The staged set only held the server's dependency closure, so a CLI runtime dependency outside that closure kept its `workspace:*` range, and the final `npm install` could not resolve it. Resolve the CLI's runtime @paperclipai dependencies as roots next to the server, so they are versioned, packed and installed as local tarballs too. On the current repo every CLI dependency is already in the server closure, so the staged set is the same 17 packages. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
c63cf56 to
bbdcf46
Compare
|
Rebased onto current |
A registry-published @paperclipai dependency installs from the registry and need not be in the release manifest, so skip it instead of failing the git-ref install.
A git-ref payload carries no .git, so /api/health reported git unavailable and every package kept the 0.3.1 source placeholder version. - Write the resolved SHA to @paperclipai/server/.paperclip-build-commit in the payload, where server/src/build-commit.ts already looks (Docker builds set PAPERCLIP_BUILD_COMMIT for the same reason). - When the ref is a version tag (v2026.916.1, or a fork's <name>-<version> tag such as ome-2026.916.1-2), unify the packed packages to that version, as release.sh does before packing. Branch and SHA refs keep the source version. Extends paperclipai#13928. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Git-ref installs run build-npm.sh and then pack the workspace packages. They never run the release.sh staging step, so prepare-bundled-package fails on the missing server/ui-dist, and the server and adapter packages ship without the Paperclip skills. Stage both here. Refs paperclipai#17063, paperclipai#13928 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for this PR. I rechecked the current #13928 code against our updated installer branch. The main four fixes in #13928 already cover server UI dist, copying the root skills into the server and two adapters, These are the additional parts of our branch, with the overlap made explicit:
The current branch is https://github.com/appleguy/paperclip/tree/fix/installer-bundled-workspaces (two commits). The focused installer suite passed 32 tests, and the bundled-package packaging suite passed 29 tests in an isolated checkout. I recommend a separate small follow-up PR after #13928 merges, limited to the independent missing parts. I will not open it here. Generated by Claude Code |
|
I checked this PR against the current What I checked:
A test to consider adding. The git-install tests replace it("stages a bundled server that asks for the plugin-sdk version the install packs", async () => {
const checkout = path.join(root, "checkout");
const write = (dir: string, packageJson: Record<string, unknown>) => {
fs.mkdirSync(path.join(checkout, dir), { recursive: true });
fs.writeFileSync(path.join(checkout, dir, "package.json"), JSON.stringify(packageJson));
};
write("packages/plugins/sdk", { name: "@paperclipai/plugin-sdk", version: "1.0.0" });
write("server", { name: "@paperclipai/server", version: "0.3.1", dependencies: { "@paperclipai/plugin-sdk": "workspace:*" }, bundleDependencies: ["acpx"] });
write("cli", { name: "paperclipai", version: "0.3.1" });
const read = (dir: string) => JSON.parse(fs.readFileSync(path.join(checkout, dir, "package.json"), "utf8"));
const { materializePublishManifest } = await import(new URL("../../../scripts/prepare-bundled-package.mjs", import.meta.url).href) as {
materializePublishManifest: (pkg: Record<string, unknown>) => { dependencies: Record<string, string> };
};
unifyGitInstallWorkspaceVersions(checkout, [
{ dir: "packages/plugins/sdk", name: "@paperclipai/plugin-sdk" },
{ dir: "server", name: "@paperclipai/server" },
], "0.3.1");
expect(materializePublishManifest(read("server")).dependencies["@paperclipai/plugin-sdk"]).toBe(read("packages/plugins/sdk").version);
});Two other notes:
We carry these four commits in a fork since late September. |
Thinking Path
Linked Issues or Issue Description
Refs #10045
Refs #13923
No issue exists for this bug. This is the description.
What happened?
paperclipai install --ref <ref>fails after the build, while it packs the workspace packages. Four separate errors occur. Each one stops the install. You see the next one only after you fix the one before it:ENOENT: no such file or directory, lstat '.../source/server/ui-dist'.scripts/prepare-bundled-package.mjscopies the packagefilesdirectly. Thus the serverprepackscript, which buildsui-dist, does not run.ENOENT: no such file or directory, lstat '.../source/server/skills'.release.shcopies the rootskills/intoserver,packages/adapters/claude-localandpackages/adapters/codex-local. The install does not. The two adapters use plainpnpm pack, so they do not fail. They pack without their skills.npm packon the staged server fails withcommand sh -c pnpm run prepare:ui-dist && pnpm run build. The release flow packs staged bundles with--ignore-scripts(run_bundled_npm_packinscripts/release-lib.sh). The install does not, so npm runsprepackin the staging directory, where../scripts/prepare-server-ui-dist.shdoes not exist.npm error notarget No matching version found for @paperclipai/plugin-sdk@0.3.1. In source,@paperclipai/plugin-sdkhas version1.0.0and the other packages have0.3.1.materializePublishManifestchanges eachworkspace:*dependency to the version of the package that has the dependency. The staged server thus asks forplugin-sdk@0.3.1. No local tarball has that version, so npm goes to the public registry and fails. The release flow runsrelease-package-map.mjs set-versionfirst, so all versions are the same.Expected behavior
paperclipai install --ref <ref>builds, packs, and activates a payload. The payload has the server UI and the skills, the same as a published npm release.Steps to reproduce
pnpm install --frozen-lockfilepasses. Onmastertoday, the lockfile problem inpaperclipai install --refaborts on lockfile drift: install.ts runs a frozen pnpm install with no fallback, unlike provision-worktree.sh and release.yml #13923 stops the install before these steps. The tagv2026.916.1has a clean lockfile.npx paperclipai install --ref v2026.916.1 --yes.Paperclip version or commit
v2026.916.1(d554c4789ed3). The samecli/src/commands/install.tsand the same test file are onmasterat7b7c4d4172d6.Installation method
paperclipai install --ref(managed git-ref install).Node.js version
v24.20.0
Operating system
Ubuntu 24.04, arm64
What Changed
cli/src/commands/install.ts: after the server build, runscripts/prepare-server-ui-dist.shwithPAPERCLIP_RELEASE_REUSE_UI_DIST=1. This is the same as step 2 ofrelease.sh.cli/src/commands/install.ts: copy the rootskills/intoserver,packages/adapters/claude-localandpackages/adapters/codex-local. These are the same three directories thatrelease.shuses.cli/src/commands/install.ts: before the pack steps, set the CLI version on each package that the install packs, and on theworkspace:ranges that point at those packages. This has the same result as step 3 ofrelease.sh(release-package-map.mjs set-version) for these packages. That script is not used here, because it validates every public package in the repo, and an unrelated package in a fork can then stop the install.cli/src/commands/install.ts: pack staged bundled packages withnpm pack --ignore-scripts. This is the same asrun_bundled_npm_pack.cli/src/__tests__/install-command.test.ts: the fixture now has a rootskills/directory. The mockpnpm packof the server fails ifserver/skillsis missing. New assertions check that the UI dist step and the version step run before packing, and that the staged pack uses--ignore-scripts.Verification
pnpm exec vitest run cli/src/__tests__/install-command.test.ts cli/src/__tests__/install-store.test.ts: 29 of 29 pass.install.ts, the tests fail. Each fix makes its assertion pass.pnpm --filter paperclipai typecheck: pass.cli/src/__tests__/suite: this change adds no failures. Some tests fail on my machine with and without the change (company,prompt,doctor,company-import-transferandcompany-import-export-e2e). They fail because of the local environment (a pnpm version pin and timeouts), not because of this change.paperclipai install --repo <fork> --ref <branch> --yes, where the branch isv2026.916.1plus these fixes. The four earlier runs stopped at errors 1 to 4 in sequence. The run with all four fixes completed:Installed paperclipai git payload <sha12>. The payload has@paperclipai/server/ui-dist/index.html,skills/in the server and in both adapters, and"@paperclipai/plugin-sdk": "0.3.1"in the server manifest.paperclipai --versionruns from the managed shim.Risks
package.jsonversions in its temporary checkout. The checkout is deleted when the install completes, so no user files change.skills/directories is a copy of the list inrelease.sh. If the release list changes, this list must change too. A shared helper for both flows can prevent this drift. I did not add one here, to keep this change small.Model Used
claude-opus-5-5), 1M context, agentic tool use (shell, file edits, test runs). The model found the four failures in real install runs, wrote the fix and the tests, and wrote this description. A human directed the work and reviewed the result.Checklist
Fixes: #/Closes #/Refs #OR (b) described the issue in-PR following the relevant issue template#NNN/github.com/paperclipai/paperclipURLs)docs/...,fix/...) and contains no internal Paperclip ticket id or instance-derived detailsdoc/INSTALLING.mdsays)🤖 Generated with Claude Opus 5.5
🧑💻 Ideated, directed and reviewed by a human, @oliver-mee