feat(cli): agent-paste upgrade binary self-update (AP-165 Phase 3)#252
Conversation
Adds the `agent-paste upgrade` command (ADR 0080 §5): a standalone binary install downloads the matching release asset from the GitHub Release, verifies it against SHA256SUMS, and atomically replaces the running binary in place. Off the binary channel it redirects to the npm/npx updater and exits 1 without touching the filesystem. - Validate the release tag against a strict `cli-v<semver>` pattern before it reaches the URL: an unvalidated `../` tag would re-point the base at an attacker repo whose own SHA256SUMS would "pass" verification. - Verify SHA-256 before any write to the target; refuse on mismatch or a missing checksum, writing nothing. - Atomic replace: temp in the binary's own dir (no EXDEV), rename-aside dance on all platforms (Windows + ETXTBSY-strict Linux), restore the original if the final rename fails. - Permission wall (sudo'd install dir): re-stage the verified bytes in the config dir and print an accurate `sudo mv` to finish; no silent escalation. - OS/arch asset table ported from the install scripts, locked by a parity test. README documents `version`, `upgrade`, and `AGENT_PASTE_NO_UPDATE_CHECK`. Issue: AP-165 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
AP-165 CLI auto-update: version baking, update check, and binary self-upgrade
OutcomeThe ContextThree distribution channels with different update mechanics: standalone binary ( Scope (phased)
Out of scopeSilent binary self-update (explicit Acceptance criteria
Required checks
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
agent-paste PR preview is ready. API: https://agent-paste-api-pr-252.isaac-a46.workers.dev |
|
agent-paste PR preview resources were cleaned up. The shared Preview GitHub Environment is retained for future preview deploys. |
Summary
Phase 3 of the CLI auto-update feature (ADR 0080 §5). Adds
agent-paste upgrade: a standalone binary install downloads the matching release asset from the GitHub Release, verifies it againstSHA256SUMS, and atomically replaces the running binary in place. This is the command the Phase 2 staleness nag already tells binary users to run, so it closes the last build gap — every channel's hint now points at a working command. Binary self-update is always explicit (the user runsupgrade), never silent.Phases 1 (version baking, #232) and 2 (update check + KV endpoint + release auto-publish, #244) are already on
main.Changes
apps/cli/src/upgrade.ts(new): the command.cli-v<semver>pattern before it is interpolated into the download URL. An unvalidated../-style tag would be path-normalized into a different GitHub repo, and since the asset and itsSHA256SUMSwould both come from that attacker-controlled base, the checksum check would pass against the attacker's own sums — silent RCE. The validator stops it before any fetch..old, new → target, drop.old) on all platforms so a running exe is replaceable on Windows and ETXTBSY-strict Linux. The original is restored if the final rename fails.sudo mv <staged> <target>to finish. No silent privilege escalation; the hint always points at a file that exists.apps/apex/src/install-{sh,ps1}.ts, locked by a parity test so the three sources can't drift.apps/cli/src/index.ts: routesupgrade [<tag>]before auth resolution (it needs no client). The pinned version is a positional tag (agent-paste upgrade cli-v1.2.3) to avoid colliding with the--version/-vprint flag; the bare version-print shortcut is now gated on there being no subcommand.apps/cli/src/node-globals.d.ts: addedprocess.archandfs.renameto the CLI's minimal node-types shim.apps/cli/README.md: documentsversion,upgrade,AGENT_PASTE_NO_UPDATE_CHECK, and the per-channel update-check behavior.docs/ops/cli-auto-update-plan.md: Phase 3 marked done.Risk: MEDIUM
Test plan
pnpm --filter @zaks-io/agent-paste test— 113 pass (26 new upgrade tests + index routing).pnpm verify— 88/88 Turbo tasks + scripts green.pnpm test:coverage— branches 80.37% / lines 89.14% (above the 80% gate);upgrade.tsat 92% lines / 81.81% branches.pnpm lint+pnpm typecheckclean.cli-v*release, not in CI (all fetch/fs injected in unit tests).Issue: AP-165
🤖 Generated with Claude Code