The standalone (curl installer) channel had no upgrade path of its own: the
documented one was 're-run the installer', which the Neovim plugin cannot do
safely and which re-downloads 35 MB without version arithmetic, provenance or
rollback. ADR 0003 records the design; this is the implementation.
- install.sh now installs one immutable tree per version
(`<prefix>/versions/<v>/{bin,share,LICENSE}`) behind a single atomically
swapped `current` symlink, writes `<prefix>/install.json` as the install
receipt, and migrates a pre-0.1.7 flat layout in place. Keeping `current` plus
one previous tree gives a one-step rollback for free.
- `pi2 update` (native TypeScript, no `curl | sh` subprocess) resolves the
release with an ETag-cached GitHub lookup, picks the asset from the
build-time `PI2_BUILD_TARGET` define instead of re-probing libc, verifies
SHA256SUMS, verifies SLSA provenance with `gh attestation verify`, runs the
new binary once, then swaps `current` and rewrites the receipt. Flags:
--check/--dry-run/--version/--force/--json/--require-attestation/
--skip-attestation. Downgrades need --force; restarts stay manual.
- the receipt is the only channel detection: npm, Homebrew and the AUR are
refused with the command that owns their tree, and a flat install is told to
re-run the installer once. No heuristics on `process.execPath`.
- `pi2 install-service` renders `<prefix>/current/bin/pi2`, so an update no
longer invalidates the unit.
- `scripts/build-binary.sh` injects `PI2_BUILD_TARGET`; `tarball.ts` is a
dependency-free ustar/PAX reader with traversal and symlink rejection.
Verified against the real release: install.sh into a scratch prefix, update
--check/--dry-run, a local 0.1.7 mirror upgrade (attestation warn path), then
`pi2 update --version 0.1.6 --force` (real download, real attestation
verified), plus boot-check and the refusal paths. typecheck + 567 daemon tests
+ web typecheck + 537 web tests + smoke are green.
4.9 KiB
AGENTS.md — pi2d
pi2 daemon: the web-console daemon for pi2.nvim.
A browser talks HTTP/WS to it; it relays JSONL to one nvim per workspace. It is a router and
supervisor — it never runs pi and never owns session state.
This file is an index and must stay under 100 lines. When something needs more than a line
or two, put the depth in docs/ or a skill under .agents/skills/ and leave a pointer here.
Adding bulk to this file is a mistake, not a contribution.
Quick reference
| Task | Command |
|---|---|
| Install | pnpm install && pnpm --dir web install |
| Typecheck | pnpm typecheck && pnpm --dir web typecheck |
| Unit tests | pnpm test (daemon) · pnpm --dir web exec vitest run (web) |
| Build | pnpm build → dist/ · pnpm build:web → web/dist/ · pnpm build:binary → dist-bin/ |
| Smoke | bash scripts/smoke.sh (Node) · bash scripts/smoke-binary.sh (compiled binary) |
| E2E | bash scripts/e2e/run-all.sh — API suite then Playwright; needs a real pi, nvim, curl |
| Dev loop | pnpm dev (:7676) · pnpm --dir web dev (:5173, proxies /api + /ws) |
| Release | skill .agents/skills/release/ |
Layout
| Path | Contents |
|---|---|
src/protocol/ |
wire types, command/event vocabulary, error codes, canonical reducer |
src/daemon/ |
HTTP/WS/SSE, auth, static assets, routing, event relay |
src/instances/ |
discovery, lazy spawn, one-instance-per-workspace, crash handling |
src/workspaces/ |
registry, disk discovery, aliases/trust, visibility policy |
src/cli/ |
pi2 — daemon, open, attach, status, doctor, pairing, install-service, update |
src/config.ts |
env-only configuration (PI2_*, PI2_HOST, PI2_WORKSPACE_*) |
src/core/network.ts |
reachable addresses: kind classification, bases[] order, CORS origins |
src/core/qr.ts |
zero-dependency QR encoder (pairing links; rows, no quiet zone) |
web/ |
React console (own lockfile + workspace); built into web/dist and served by the daemon |
packaging/ |
Homebrew formula & Arch AUR PKGBUILD templates, generator script |
fixtures/ |
golden event streams + expected state, shared with pi2.nvim conformance tests |
test/ |
vitest, hermetic, injectable I/O |
scripts/ |
install.sh, build-binary.sh, smoke*.sh, e2e/ drivers, gen-expected.ts |
Hard rules
docs/protocol.mdis the contract. Any wire change lands with the daemon, the web client and the pi2.nvim bridge in view;fixtures/are regenerated viascripts/gen-expected.ts.- The daemon is not an agent runtime. No
pispawning, no JSONL session parsing, no session state. Snapshots and mutations are relayed to the plugin, which stays the single authority. dist/andweb/dist/are build output — gitignored, never committed. They ship inside the npm tarball throughprepack+ thefilesallowlist.- Two lockfiles. Root
pnpm-lock.yamlandweb/pnpm-lock.yamlare independent: usepnpm --dir web …for anything web-side, never a root install. - Tests are hermetic. No real sockets, spawns or networks outside
scripts/e2e/; inject probes (DoctorContext,WorkspaceStoreOptions.env, fake instance managers) and keepfixtures/byte-identical. - Local sign-in is loopback-only.
POST /api/v1/console/sessionrequires the CLI token from the runtime dir, the browser token travels in the URL fragment only, device tokens are stored hashed, andlan/tailscalemodes never auto-sign-in. - Conventional commits (
feat(daemon):,fix(web):,docs:,ci:), scoped to the area.
Naming, so you do not get lost
npm package @yuez/pi2d (scoped — the unscoped pi2d is rejected by the registry's similarity
filter), executable pi2, GitHub repo zgs225/pi2d (the trusted publisher matches on
owner/repo/workflow filename, not the npm name).
Where to read deeper
| Doc | Contents |
|---|---|
docs/protocol.md |
the browser ↔ daemon ↔ plugin wire contract |
docs/install.md |
canonical CLI-first install guide, channels, run modes, services, pi2 update |
docs/session-dot.md |
the session-list status dot: the :PiSessions matrix, the unread flags, the one blink clock |
docs/deployment.md |
env vars, runtime files, ports, auth, services, troubleshooting |
docs/e2e.md |
scenario ids, isolation, skip conditions, report paths |
docs/testing.md |
test architecture, performance tuning, hybrid core CPU guidelines |
docs/releasing.md |
npm Trusted Publishing, the bootstrap phases, verification |
README.md |
install paths, :PiWeb, binding & pairing |
.agents/skills/release/ |
how to cut and verify a release |
Before you say "done"
pnpm typecheck && pnpm test && pnpm --dir web typecheck && pnpm --dir web exec vitest run && bash scripts/smoke.sh green; docs updated where behaviour changed; no build output staged.