From a8425a51b662b0946cf7edb9cd3be32df2a67c15 Mon Sep 17 00:00:00 2001 From: yuez Date: Fri, 23 Oct 2026 10:54:44 +0800 Subject: [PATCH] docs: add the AGENTS.md index and a release skill AGENTS.md is a 77-line index (the file itself states the <=100-line rule): quick commands, layout, the hard invariants that keep the daemon a router rather than an agent runtime, and pointers into docs/ and .agents/skills/. The release skill turns docs/releasing.md into a runbook plus a checkable artifact: scripts/verify-release.sh asserts the registry version, the SLSA provenance attestation, a clean install from the public registry, the tarball contents, a booting daemon serving / and a healthy /api/v1/health, and the GitHub release. Verified against the live 0.1.2 publish. --- .agents/skills/release/SKILL.md | 90 +++++++++++++ .../skills/release/scripts/verify-release.sh | 127 ++++++++++++++++++ AGENTS.md | 77 +++++++++++ 3 files changed, 294 insertions(+) create mode 100644 .agents/skills/release/SKILL.md create mode 100755 .agents/skills/release/scripts/verify-release.sh create mode 100644 AGENTS.md diff --git a/.agents/skills/release/SKILL.md b/.agents/skills/release/SKILL.md new file mode 100644 index 0000000..d5cb15d --- /dev/null +++ b/.agents/skills/release/SKILL.md @@ -0,0 +1,90 @@ +--- +name: release +description: Cut and verify a pi2d release — pick the version, tag it, let GitHub Actions publish to npm through Trusted Publishing (OIDC), then verify the registry artifact, provenance, a clean install and a booting daemon. Use when asked to "release", "publish", "cut a version", "bump the version", or to diagnose a failed release run. +--- + +# Release pi2d + +Runbook. Architecture and house rules live in `AGENTS.md`; the npmjs.com checklist, provenance +rationale and the long troubleshooting table live in `../../../docs/releasing.md`. This file is the +procedure to execute. + +## Non-negotiables + +- **Publish only from CI.** Tag → `.github/workflows/release.yml` → OIDC. A local `npm publish` + is the one-time bootstrap only (see below), never the steady state. +- **No tokens.** The publish step holds no credentials; the workflow's first guard step fails the + job when `NPM_TOKEN` / `NODE_AUTH_TOKEN` is still present in the repo. +- **Tag == `package.json` version.** The workflow verifies the pair and refuses to publish a + mismatch. +- **Push the tag explicitly.** `git push --follow-tags` only pushes *annotated* tags; a + lightweight tag is skipped silently and `release.yml` never runs. + +## Steady-state release + +1. **Preconditions** — clean tree on `main`, in sync with `origin/main`, and CI green on the commit + you are about to tag: `gh run list --repo zgs225/pi2d --workflow ci.yml --limit 3`. +2. **Pick the version with the user** (do not assume). Semver: breaking → major, feature → minor, + fix → patch. There is no `CHANGELOG.md`; build the notes from + `git log --oneline "$(git describe --tags --abbrev=0)"..HEAD`, grouped by conventional type. +3. **Bump and commit:** + ```bash + npm version --no-git-tag-version + git commit -am "chore: release " + ``` +4. **Tag and push** (annotated tag, pushed explicitly): + ```bash + git tag -a "v" -m "v" + git push origin main + git push origin "v" + ``` +5. **Watch the publish:** + ```bash + gh run watch "$(gh run list --repo zgs225/pi2d --workflow release.yml --limit 1 \ + --json databaseId --jq '.[0].databaseId')" --repo zgs225/pi2d --exit-status + ``` + The interesting steps are `Upgrade npm`, `Preflight — npm/node support trusted publishing`, + `Publish to npm (trusted publishing, no token)` and `Create GitHub release`. +6. **Verify the artifact** — do not trust a green job, check the registry: + ```bash + bash .agents/skills/release/scripts/verify-release.sh + ``` + It asserts the exact version is on the registry, the SLSA provenance attestation exists, a clean + install from the public registry reports `pi2 `, the tarball ships `web/dist`, + `dist/cli/pi2.js` and `LICENSE`, the daemon boots and serves `/` + a healthy + `/api/v1/health`, and the GitHub release exists. Every line is `PASS`/`FAIL`; exit non-zero on + any failure. +7. **Report** the version, the run URL, the verification output and the release URL. Mention whether + the new version is `latest` (a backport is not). + +## Bootstrap (once per package name, already done for `@yuez/pi2d`) + +Only relevant if the package has left the registry. npmjs.com offers the Trusted Publisher page +only for a package that already exists, so the first publish is manual: + +1. From the repo root: `npm login` (account `yuez`, 2FA) → `npm whoami` → `npm publish --access public`. + That artifact has no provenance; every later release does. +2. Then add the trusted publisher on npmjs.com: owner `zgs225` (GitHub), repo `pi2d`, workflow + filename `release.yml`, environment empty, **and tick `npm publish`** (post-2026-09-03 configs + allow only `npm stage publish` by default). The first CI publish must happen within 2 days or the + configuration expires. +3. Bump to a **higher** version for the first CI release — npm rejects republishing a version. + +## Failure playbook + +| Symptom | Cause / action | +|---|---| +| No `release.yml` run after pushing | The tag never reached the remote. Check `gh api repos/zgs225/pi2d/tags --jq '.[].name'`; a lightweight tag plus `--follow-tags` is silent. Push the tag explicitly. | +| `ENEEDAUTH` / "Unable to authenticate" | OIDC or policy mismatch: workflow filename must be exactly `release.yml`, `npm publish` must be ticked under allowed actions, `id-token: write` must be present, and the trusted publisher must be attached to *this* package. | +| `Preflight` fails on npm version | setup-node's node 22 ships npm 10; the `Upgrade npm` step must run before the preflight. | +| `Refuse token-based publishing` fails | A `NPM_TOKEN`/`NODE_AUTH_TOKEN` repo secret still exists. Delete it — OIDC is the intended path. | +| `E403 Package name too similar` | Unscoped names hit the registry's similarity filter; this package is scoped as `@yuez/pi2d` and must stay scoped. | +| `E403 You cannot publish over the previously published versions` | The version was already published (often the bootstrap). Bump and re-tag. | +| `Create GitHub release` 403 | Workflow `permissions` lost `contents: write`. | +| `EOTP` on a local publish | Only the bootstrap needs 2FA; pass `--otp=`. Steady state never publishes locally. | + +## Definition of done + +Registry shows the version with a `slsa.dev/provenance` attestation, `verify-release.sh` prints +`OK`, the GitHub release exists, the working tree is clean, and the report tells the user what to +install (`npm i -g @yuez/pi2d@`). diff --git a/.agents/skills/release/scripts/verify-release.sh b/.agents/skills/release/scripts/verify-release.sh new file mode 100755 index 0000000..0cccc98 --- /dev/null +++ b/.agents/skills/release/scripts/verify-release.sh @@ -0,0 +1,127 @@ +#!/usr/bin/env bash +# Verify a published `@yuez/pi2d` release end to end. +# +# bash .agents/skills/release/scripts/verify-release.sh +# +# Checks, in order: the registry carries that exact version, the provenance +# attestation is present, a clean install from the public registry reports the +# same version, the packaged daemon boots and serves the console + health, and +# the GitHub release exists. Every line is PASS/FAIL/INFO; the script exits +# non-zero when any check fails. +set -uo pipefail + +PKG="@yuez/pi2d" +REPO="zgs225/pi2d" +VERSION="${1:-}" +if [ -z "$VERSION" ]; then + echo "usage: verify-release.sh " >&2 + exit 2 +fi + +WORK=$(mktemp -d "${TMPDIR:-/tmp}/pi2d-verify-release.XXXXXX") +DPID="" +cleanup() { + [ -n "$DPID" ] && kill "$DPID" 2>/dev/null + [ -n "$DPID" ] && wait "$DPID" 2>/dev/null + rm -rf "$WORK" +} +trap cleanup EXIT + +FAILED=0 +pass() { printf 'PASS %-42s %s\n' "$1" "${2:-}"; } +fail() { printf 'FAIL %-42s %s\n' "$1" "${2:-}"; FAILED=1; } +info() { printf 'INFO %-42s %s\n' "$1" "${2:-}"; } + +# 1 — the registry has this version ----------------------------------------- +PUBLISHED=$(npm view "$PKG@$VERSION" version 2>/dev/null) +if [ "$PUBLISHED" = "$VERSION" ]; then + pass "registry version" "$PKG@$PUBLISHED" +else + fail "registry version" "expected $VERSION, got '${PUBLISHED:-}'" +fi + +LATEST=$(npm view "$PKG" dist-tags.latest 2>/dev/null) +if [ "$LATEST" = "$VERSION" ]; then + pass "dist-tag latest" "$LATEST" +else + info "dist-tag latest" "$LATEST (this release is not the latest tag)" +fi + +# 2 — provenance ------------------------------------------------------------- +PREDICATE=$(npm view "$PKG@$VERSION" dist.attestations.provenance.predicateType 2>/dev/null) +case "$PREDICATE" in + *slsa.dev/provenance*) pass "provenance attestation" "$PREDICATE" ;; + "") fail "provenance attestation" "none (bootstrap version? published outside CI?)" ;; + *) fail "provenance attestation" "unexpected predicate $PREDICATE" ;; +esac + +# 3 — a clean install from the public registry ------------------------------- +if npm i -g --prefix "$WORK/prefix" --no-audit --no-fund "$PKG@$VERSION" >"$WORK/install.log" 2>&1; then + pass "clean global install" "$(tail -1 "$WORK/install.log")" +else + fail "clean global install" "see $WORK/install.log" +fi +PI2="$WORK/prefix/bin/pi2" +if [ -x "$PI2" ]; then + INSTALLED=$("$PI2" --version 2>&1 | head -1) + if [ "$INSTALLED" = "pi2 $VERSION" ]; then + pass "installed binary version" "$INSTALLED" + else + fail "installed binary version" "expected 'pi2 $VERSION', got '$INSTALLED'" + fi + PKG_DIR="$WORK/prefix/lib/node_modules/$PKG" + for f in "web/dist/index.html" "dist/cli/pi2.js" "LICENSE"; do + if [ -e "$PKG_DIR/$f" ]; then + pass "tarball ships" "$f" + else + fail "tarball ships" "$f missing" + fi + done +else + fail "installed binary version" "no $PI2" +fi + +# 4 — the daemon boots and serves -------------------------------------------- +export PI2_RUNTIME_DIR="$WORK/rt" PI2_DATA_DIR="$WORK/data" PI2_STATE_DIR="$WORK/state" +if [ -x "$PI2" ]; then + "$PI2" daemon -p 0 >"$WORK/daemon.out" 2>"$WORK/daemon.err" & + DPID=$! + for _ in $(seq 1 150); do [ -f "$WORK/rt/daemon.json" ] && break; sleep 0.1; done + if [ -f "$WORK/rt/daemon.json" ]; then + PORT=$(node -pe "JSON.parse(require('fs').readFileSync('$WORK/rt/daemon.json','utf8')).port" 2>/dev/null) + pass "daemon start" "$(head -1 "$WORK/daemon.out")" + CODE=$(curl -s -o "$WORK/index.html" -w '%{http_code}' --max-time 10 "http://127.0.0.1:$PORT/") + [ "$CODE" = "200" ] && pass "GET / serves the console" "200, $(wc -c <"$WORK/index.html" | tr -d ' ') bytes" \ + || fail "GET / serves the console" "HTTP $CODE" + HEALTH=$(curl -s --max-time 10 "http://127.0.0.1:$PORT/api/v1/health") + if printf '%s' "$HEALTH" | grep -q '"ok":true'; then + pass "health ok" "$(printf '%s' "$HEALTH" | node -pe 'JSON.parse(require("fs").readFileSync(0,"utf8")).items.map(i=>i.name+"="+(i.ok?"ok":"FAIL")).join(" ")' 2>/dev/null)" + else + fail "health ok" "${HEALTH:-}" + fi + kill "$DPID" 2>/dev/null; wait "$DPID" 2>/dev/null; DPID="" + [ -f "$WORK/rt/daemon.lock" ] && fail "clean shutdown" "daemon.lock left behind" \ + || pass "clean shutdown" "lock + daemon.json removed" + else + fail "daemon start" "$(tail -2 "$WORK/daemon.err" | tr '\n' ' ')" + fi +fi + +# 5 — the GitHub release ----------------------------------------------------- +if command -v gh >/dev/null 2>&1; then + if gh release view "v$VERSION" --repo "$REPO" --json url --jq .url >"$WORK/release.url" 2>/dev/null; then + pass "GitHub release" "$(cat "$WORK/release.url")" + else + info "GitHub release" "no release for v$VERSION (informational)" + fi +else + info "GitHub release" "gh not installed, skipped" +fi + +echo +if [ "$FAILED" -eq 0 ]; then + echo "OK — $PKG@$VERSION is published and usable." +else + echo "FAILED — see the FAIL lines above." >&2 +fi +exit "$FAILED" diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..ffc0232 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,77 @@ +# AGENTS.md — pi2d + +`pi2 daemon`: the web-console daemon for [pi2.nvim](https://github.com/zgs225/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/` | +| Smoke | `bash scripts/smoke.sh` — isolated tmp dirs, asserts HTTP, static UI, tokens, clean SIGTERM | +| 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` | +| `src/config.ts` | env-only configuration (`PI2_*`, `PI2_ACCESS_MODE`, `PI2_WORKSPACE_*`) | +| `web/` | React console (own lockfile + workspace); built into `web/dist` and served by the daemon | +| `fixtures/` | golden event streams + expected state, shared with pi2.nvim conformance tests | +| `test/` | vitest, hermetic, injectable I/O | +| `scripts/` | `smoke.sh`, `e2e/` drivers, `gen-expected.ts` | + +## Hard rules + +1. **`docs/protocol.md` is the contract.** Any wire change lands with the daemon, the web client + and the pi2.nvim bridge in view; `fixtures/` are regenerated via `scripts/gen-expected.ts`. +2. **The daemon is not an agent runtime.** No `pi` spawning, no JSONL session parsing, no session + state. Snapshots and mutations are relayed to the plugin, which stays the single authority. +3. **`dist/` and `web/dist/` are build output** — gitignored, never committed. They ship inside + the npm tarball through `prepack` + the `files` allowlist. +4. **Two lockfiles.** Root `pnpm-lock.yaml` and `web/pnpm-lock.yaml` are independent: use + `pnpm --dir web …` for anything web-side, never a root install. +5. **Tests are hermetic.** No real sockets, spawns or networks outside `scripts/e2e/`; inject + probes (`DoctorContext`, `WorkspaceStoreOptions.env`, fake instance managers) and keep + `fixtures/` byte-identical. +6. **Local sign-in is loopback-only.** `POST /api/v1/console/session` requires the CLI token from + the runtime dir, the browser token travels in the URL fragment only, device tokens are stored + hashed, and `lan`/`tailscale` modes never auto-sign-in. +7. **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/deployment.md` | env vars, runtime files, ports, auth, services, troubleshooting | +| `docs/e2e.md` | scenario ids, isolation, skip conditions, report paths | +| `docs/releasing.md` | npm Trusted Publishing, the bootstrap phases, verification | +| `README.md` | install paths, `:PiWeb`, access modes | +| `.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.