返回 CodeWhale
RELEASE_RUNBOOK.md
根目录 / docs / RELEASE_RUNBOOK.md
1 # Codewhale Release Runbook
2
3 This runbook is the source of truth for shipping Rust crates, GitHub release assets,
4 and the `codewhale` npm wrapper.
5
6 Use [`RELEASE_CHECKLIST.md`](RELEASE_CHECKLIST.md) as the ordered release
7 sequence: reconcile the canonical checkout, prepare and land verified slices,
8 freeze one SHA, verify Cargo tarballs and exact-SHA hosted CI/RC, obtain Hunter's
9 publication approval, tag that SHA, then verify each public destination.
10 Agent-owned preparation is built in a short-lived agent worktree and lands on
11 `main`; do not create release branches or nested clones.
12 Freeze, tag and publish from the clean canonical checkout on `main`. Coordinate file ownership and preserve dirty work before any recovery.
13 Keep evidence in the existing release packet instead of maintaining a second
14 release queue here.
15
16 GitHub assets are uploaded into a draft and published only after every expected
17 asset's name, upload state, size and GitHub SHA-256 digest match the verified
18 local set. A failed upload leaves an unpublished draft. Reruns may reuse matching
19 draft assets; missing or mismatched digests stop publication for maintainer
20 review. Public assets are never replaced. Draft lookup checks every release page.
21 CNB release tags and GHCR version/latest tags follow canonical publication;
22 manual CNB tag recovery also requires a complete public GitHub asset inventory.
23
24 Current packaging note:
25 - `codewhale-tui` is the live runtime crate linked into the installed
26 `codewhale`/`codew` commands; it is not a third installed command.
27 - `codewhale-app-server` is a supporting library crate. The shipped entrypoint
28 is `codewhale app-server`; do not add or publish a standalone app-server binary.
29
30 ## Canonical Publish Targets
31
32 - End-user crates:
33 - `codewhale-tui`
34 - `codewhale-cli`
35
36 The complete supporting-crate list and dependency order live in
37 [`scripts/release/crates.sh`](../scripts/release/crates.sh), validated against
38 the locked workspace graph by the publish helper. Do not maintain a second
39 handwritten list here.
40
41 `codewhale-ratatui` (`vendor/codewhale-ratatui`) is a workspace member with its
42 own version, `0.2.2`, independent of the workspace version. It publishes right after `codewhale-protocol`, which it depends on,
43 and before the crates that depend on it. `check-versions.sh` exempts only its
44 own `0.2.2` pin from the workspace-version rule; its `codewhale-protocol` pin
45 still follows the workspace version. Bumping the crate means changing its
46 manifest version and the `0.2.2` pins in `codewhale-engine`,
47 `codewhale-tui-kit` and `codewhale-tui`, and the exception line in
48 `check-versions.sh`, together.
49
50 ## Version Coordination
51
52 - Rust crates inherit the shared workspace version from [Cargo.toml](../Cargo.toml).
53 - Internal path dependency versions should match the shared workspace version; stale older pins are release blockers once the workspace version moves.
54 - The npm wrapper version lives in [npm/codewhale/package.json](../npm/codewhale/package.json).
55 - `codewhaleBinaryVersion` controls which GitHub release binaries the npm wrapper downloads.
56 - Packaging-only npm releases are allowed:
57 - bump the npm package version
58 - leave `codewhaleBinaryVersion` pinned to the previously released Rust binaries
59 - rerun `npm pack` smoke checks before `npm publish`
60
61 ## Release Source Timing
62
63 Freeze the source before creating a public `vX.Y.Z` tag. A version bump is
64 preparation, not a release: all intended source must reach `main` before the
65 final candidate is chosen. Record the full SHA and coordinate a pause with
66 shared writers through packaging and publication. Clean local `HEAD`, `main`
67 and freshly fetched `origin/main` must agree. A later fix changes the candidate
68 and needs affected proofs replaced. Once created, the tag is the immutable
69 release anchor; later main commits cannot change its contents.
70
71 Before tagging, verify the live queue and existing anchors:
72
73 ```bash
74 gh issue list --repo codewhale-hq/CodeWhale --milestone "vX.Y.Z" --state open
75 gh pr list --repo codewhale-hq/CodeWhale --state open --limit 100
76 git ls-remote origin refs/heads/main refs/tags/vX.Y.Z
77 gh release view vX.Y.Z --repo codewhale-hq/CodeWhale
78 ./scripts/release/check-published.sh X.Y.Z
79 ```
80
81 If a same-version tag already exists but there is no GitHub Release and nothing
82 is published, stop and choose deliberately:
83
84 - publish exactly the tagged SHA, leaving later commits for the next patch;
85 - bump the later work to the next patch version and tag that later SHA; or
86 - with explicit maintainer approval only, delete/recreate the unpublished tag
87 after confirming no package, GitHub Release, mirror, or installer consumer has
88 treated it as public.
89
90 Do not delete, move, or recreate a release tag implicitly during ordinary
91 preparation or milestone cleanup. Publishing an older tagged SHA after canonical
92 `main` has advanced needs a separately authorized recovery plan; do not switch
93 the shared checkout or create another lane to bypass the source guard.
94
95 ## Preflight
96
97 For each preparation slice, run the existing checks appropriate to its changed
98 surface once, then record the actual result in the commit message and land owned
99 paths directly on `main`. Batch coherent Rust edits before compiling. Web changes
100 use `npm test && npm run check:web` from the repository root. Do not repeat a
101 passed check merely to commit/push or run exhaustive local workspace builds in
102 addition to the final hosted gates.
103
104 Before freezing the candidate, use the lightweight preparation checks:
105
106 ```bash
107 ./scripts/release/check-versions.sh --require-dated-release
108 ./scripts/release/check-ohos-deps.sh
109 ./scripts/release/check-feature-release-notes.sh vPREV HEAD
110 python3 scripts/check-contributor-credit.py
111 ```
112
113 `check-versions.sh` also runs on every full `ci.yml` dispatch (the `versions` job), which
114 `main-landing.yml` issues for each push to `main` that lacks one, so drift between `Cargo.toml`, the per-crate
115 manifests, the npm wrapper and Runtime SDK, the VS Code extension and lock,
116 generated web facts, and `Cargo.lock` is caught before release time rather than
117 at it.
118
119 `main-landing.yml` dispatches the full `ci.yml` for every push to `main`, so
120 ordinary main-push CI is the full suite. A successful pointer job is still not
121 a Linux test receipt. The final manual full-CI dispatch forces the real Linux,
122 macOS and Windows gates; keep its exact-SHA evidence rather than substituting
123 an older run.
124
125 Releases are signed from 0.10.5. `release-artifacts.yml` signs the checksum
126 manifest with the `CODEWHALE_RELEASE_SIGNING_KEY` Actions secret when it is
127 configured. `release.yml` sets `require_signature`, so a tag release fails
128 when the key is absent; a release candidate without the key is unsigned, and
129 an unsigned build makes automatic updates wait for each user's OK. Builds carrying the release public key refuse a missing or
130 invalid signature, so every release after 0.10.5 must be signed. Confirm
131 `codewhale-artifacts-sha256.txt.sig` is among the release assets before the
132 release is announced.
133
134 After changing `LICENSE`, `THIRD_PARTY_NOTICES.md` or `docs/THIRD_PARTY_NOTICES.md`, run `scripts/release/sync-package-notices.sh` and commit the refreshed package files. Cargo and npm archive checks compare their contents with these sources.
135
136 `publish-crates.sh` requires Cargo 1.90 or newer for multi-package verification;
137 this release-tool requirement is separate from the workspace's Rust 1.89 MSRV.
138 Use a release toolchain meeting that requirement.
139
140 Run the package preflight once for the clean frozen candidate and retain its
141 SHA/result:
142
143 ```bash
144 ./scripts/release/publish-crates.sh dry-run
145 ```
146
147 Both modes validate publication order against the locked workspace graph, then
148 run one `cargo publish --dry-run --locked --registry crates-io` covering all
149 release crates listed in `scripts/release/crates.sh`. Cargo resolves unpublished
150 workspace dependencies through a
151 temporary local registry, builds every unpacked tarball, and checks publication
152 metadata and real tarball sizes before any upload. Dry-run mode can permit
153 source edits, but the final release receipt must describe the frozen source.
154 It stops without uploading. CI/RC does not verify Cargo publication tarballs
155 and cannot replace this gate. Publish mode necessarily verifies them again.
156
157 Cargo treats every crate it serves from that temporary registry as immutable by
158 name and version, so a later run at the same version can verify an earlier
159 run's code. It skips extracting a crate under `$CARGO_HOME/registry/src/` once
160 `.cargo-ok` exists, and it keeps compiled units of those crates in the build
161 directory because they track no source files. At 0.10.2 one dry run failed with
162 `E0432 unresolved import anyhow` in codewhale-core from an older extraction;
163 after that extraction was moved aside, the next run passed while linking
164 codewhale-state and codewhale-config built from older sources. Before
165 packaging, both modes therefore refuse to start when they find a release
166 crate's `<crate>-<version>` directory under any `$CARGO_HOME/registry/src/*`
167 other than crates.io's `index.crates.io-*`, or a dep-info file under the build
168 directory's `*/deps/` that names such a directory. The refusal lists what it
169 found and deletes nothing; removing shared cache directories still needs
170 explicit cleanup approval. It prints, with the paths filled in, the kind of
171 rerun that produced the 0.10.2 receipt at 14683c9983 on 2026-10-16: a new,
172 empty `CARGO_HOME` and build directory.
173
174 ```bash
175 mode=dry-run
176 cache="${CODEWHALE_CACHE_ROOT:-${XDG_CACHE_HOME:-$HOME/.cache}/codewhale}"
177 lock="${CODEWHALE_BUILD_LOCK_FILE:-${cache}/build.lock}"
178 root="${cache}/release-verify-$(git rev-parse --short=10 HEAD)-${mode}-$(date -u +%Y%m%dT%H%M%SZ)"
179 mkdir -p "${cache}" && mkdir "${root}" &&
180 CARGO_HOME="${root}/cargo-home" CARGO_TARGET_DIR="${root}/target" \
181 python3 scripts/build-lock.py "${lock}" -- ./scripts/release/publish-crates.sh "${mode}"
182 ```
183
184 That run was a cold build of about 19 GB and 962 compile steps, so check
185 `df -h` first. `cache` and `lock` use the same fallbacks as
186 `scripts/dev-cache.sh`. `CARGO_TARGET_DIR` moves the build directory with
187 plain Cargo and with `scripts/dev-cargo.sh`, which honors an inherited target
188 directory, and `scripts/build-lock.py` holds the machine build lock whichever
189 `cargo` is on `PATH`. That lock serializes only with `scripts/dev-cargo.sh`
190 and other `build-lock.py` users; a `cargo` wrapper with its own build slots
191 does not take it. The 0.10.2 receipt run set `CODEWHALE_CACHE_ROOT`
192 instead, which only `scripts/dev-cargo.sh` reads, and kept its lock inside the
193 new root. `mkdir` without `-p` refuses a root that already exists, and the
194 `&&` chain stops the run there. Every run leaves state that the next run at
195 the same version refuses, so the root name carries the SHA, the mode and a
196 UTC timestamp:
197 publish mode (step 5 of the Rust crates release) and each partial-publish
198 rerun get their own root. Pass the crates.io token to publish mode as
199 `CARGO_REGISTRY_TOKEN` for that one command, as step 5 shows; Cargo then
200 writes no `credentials.toml` under the root. If you run `cargo login` with
201 that `CARGO_HOME` instead, run `CARGO_HOME="${root}/cargo-home" cargo logout`
202 once the publish finishes, so no plaintext token copy stays in the cache tree.
203 The CNB `work/v*` release preflight in `.cnb.yml` calls this script in a fresh
204 container, where the check finds nothing. Known limits: the check also refuses
205 compiled units recorded against a different `CARGO_HOME`, which Cargo would
206 rebuild rather than reuse, and it does not scan `<target-triple>/`
207 subdirectories of the build directory, which host-only package verification
208 does not use.
209
210 If a dry-run is interrupted (Ctrl-C, or a shell that gets killed), inspect the
211 half-packed `package/` directory in Cargo's build directory before retrying and
212 coordinate with active builds. For a run from the blocks above that is
213 `${root}/target/package` with any `cargo`. Otherwise plain Cargo uses
214 `target/package` and `scripts/dev-cargo.sh` moves it under
215 `${CODEWHALE_CACHE_ROOT}/build/`; `cargo metadata --format-version 1
216 --no-deps` reports it as `build_directory`.
217 Cargo can resume against it and every unpacked tarball may then fail with
218 `error: Current directory is invalid:
219 No such file or directory (os error 2)` — which looks like a compiler or
220 workspace defect and is neither (seen 2026-09-21; a clean re-run passed).
221 Keep recovery material and obtain explicit cleanup approval before deleting
222 shared build/package directories; do not reset the source to repair packaging.
223 Publish mode requires the approved release checkout and assets, then skips
224 versions already on crates.io and uploads the remaining crates in dependency
225 order. Resuming still verifies the complete source release; it never weakens
226 the artifact gate merely because an earlier crate was already uploaded.
227 Registry-side acceptance and credentials are still checked during real upload;
228 a successful preflight cannot guarantee that every later upload will succeed.
229
230 The final full-CI and RC workflows own npm wrapper build/install smoke. When a
231 wrapper change needs focused local verification, reuse a valid matching runtime
232 or build the single runtime once and run the cross-platform smoke harness.
233 This packs the npm wrapper, installs it into a
234 clean temporary project, serves local release assets over HTTP, and checks both
235 published commands against that runtime: `codewhale doctor --help` and
236 `codew --version`.
237
238 ```bash
239 cargo build --release --locked -p codewhale-cli --bin codewhale
240 node scripts/release/npm-wrapper-smoke.js
241 ```
242
243 Set `DEEPSEEK_TUI_KEEP_SMOKE_DIR=1` to keep the temporary pack/install
244 directory for inspection.
245
246 ## Exact-head GitHub proof before publication
247
248 Two manual workflows provide exact-head evidence without crossing the public
249 release boundary. Run them after the intended source is frozen on canonical
250 `main`, and pass the full commit SHA as an independent
251 guard against that ref moving between inspection and dispatch:
252
253 ```bash
254 git fetch origin main
255 candidate_sha="$(git rev-parse HEAD)"
256
257 gh workflow run ci.yml --ref main \
258 -f expected_sha="${candidate_sha}"
259 gh workflow run release-candidate.yml --ref main \
260 -f expected_sha="${candidate_sha}"
261 ```
262
263 The manual `ci.yml` path verifies that the dispatch resolved to
264 `expected_sha`, disables light-change shortcuts, and forces the heavy Rust,
265 workflow, mobile, Actions, Linux, macOS, Windows, npm-wrapper, and documentation
266 gates. A mismatch fails before those gates start; it never silently tests a
267 different head. The Linux, macOS and Windows suites run as `Sharded tests (<os>)`
268 (`ci-test-suite.yml`): one test build per OS, parallel nextest shards of that
269 archive, and a `Suite check` job that fails unless the shards together ran
270 exactly the tests the archive lists; read that job, not only the shard jobs.
271
272 `ci.yml` also takes optional scoped-run inputs for a quick answer from an agent
273 or a maintainer. With `crate` (one workspace package, for example
274 `codewhale-tui`) and/or `filter` (a nextest filterset such as
275 `test(auto_review)`) set, only the `Scoped test` job runs, on the operating
276 systems named by `os` (default `ubuntu-latest`; a comma-separated list or
277 `all`), and the full suite and every other gate are skipped. `expected_sha`
278 stays required and is still verified:
279
280 ```bash
281 gh workflow run ci.yml --ref ci/my-task \
282 -f expected_sha="$(git rev-parse HEAD)" \
283 -f crate=codewhale-tui -f filter='test(auto_review)'
284 ```
285
286 A scoped run proves a slice, never a release; release evidence is a full
287 dispatch with the scoped inputs empty. A newer dispatch on the same non-main
288 branch cancels the older run of the same workflow; runs on `main` are keyed by SHA and never cancel each other, and a
289 scoped run never cancels a full one.
290
291 Verify beforehand that clean local `HEAD`, `main` and `origin/main` agree.
292 Record both run URLs, resolved SHAs and required job results; inspect executed
293 gates rather than the workflow badge. If `main` changes before tagging, choose
294 the new candidate deliberately and replace affected evidence. Do not run these
295 exhaustive gates locally as well.
296
297 `release-candidate.yml` also fails unless the selected ref resolves to the
298 exact requested SHA. It runs the same parity gate as the public release
299 (`release-parity.yml`: fmt, check, clippy, workspace nextest, doctests,
300 protocol and state parity), and `release.yml` refuses to start unless a green
301 release-candidate run with a green Parity job exists for the exact tag SHA
302 (`scripts/release/require-rc-receipt.sh`). Tag the SHA the final full CI and RC
303 validated. A missing receipt stops publication; do not move the tag to conceal
304 it or use a different SHA's green run.
305 It invokes the same reusable artifact workflow as the
306 public release, building all eight targets (including Android arm64, native
307 Windows arm64 and native HarmonyOS arm64), staging `codewhale` and `codew`
308 (single binary), building the NSIS installer and ten platform archives, and
309 validating the authoritative
310 38-file inventory from `npm/codewhale/scripts/artifacts.js` (30 current
311 artifacts and manifests plus eight compatibility-only `codewhale-tui-*`
312 filenames containing the same compiled `codewhale` bytes for v0.9.4 update
313 clients). The HarmonyOS leg is the one target whose bytes are post-processed:
314 the binary is self-signed before staging, because a device refuses to execute
315 an unsigned ELF. It then installs
316 the packed npm wrapper against those assembled local assets and exercises its
317 delegated entrypoints. The resulting `codewhale-release-assets` bundle is a
318 short-lived GitHub Actions artifact only.
319
320 `nightly-candidate.yml` dispatches this workflow with `nightly=true` for the
321 tip of `main` once a day at 14:47 UTC, when that tip has a green full `ci.yml`
322 run (`scripts/release/require-full-ci-receipt.sh`), no release-candidate run
323 yet, and no candidate already building; otherwise it records why and waits for
324 the next night. A nightly run accepts an undated CHANGELOG and never receives
325 the signing key, so its manifest is unsigned; the build is otherwise the same.
326 Its green run is the receipt `release.yml` accepts when the tag points at that
327 exact SHA, and `release.yml` still reruns the dated-release check, rebuilds and
328 signs. Its artifacts expire after 7 days. Run it by hand with
329 `gh workflow run nightly-candidate.yml -f dry_run=true` to see the decision.
330 Retain required asset/evidence copies before artifact expiry; record cross-build,
331 install and real-device/provider results separately in the existing packet.
332
333 Windows import evidence uses independent profiles for the native x64
334 compatibility target, observed ARM64 environment and x86 NSIS/WOW64 contracts;
335 see [ENVIRONMENTS.md](ENVIRONMENTS.md#windows-support-and-release-qualification).
336 Keep every staged Windows executable and the actual embedded NSIS PE plugin
337 dumps, hashes and failures. The generated Uninstall.exe needs its own scoped
338 installation receipt. Static import qualification does not prove final release
339 startup on Windows 10 1607, installed runtime dependencies or native ARM64
340 package/desktop behavior. Preserve these runtime receipts separately before
341 claiming the release is ready.
342
343 This candidate workflow does not create a tag or GitHub Release, publish a
344 crate or npm package, push a container, update Homebrew, deploy anything, or
345 write repository contents. Its green result is evidence, not publication
346 authorization. The stop line remains explicit Hunter approval: do not create
347 the `vX.Y.Z` tag, dispatch `release.yml`, or run any registry publication step
348 until that approval is given for the exact version/SHA and intended destinations.
349 Tag creation can immediately start GitHub, npm, GHCR, CNB and Homebrew
350 publication; include those destinations in the approval. Cargo publication
351 waits for Hunter to approve the `release` environment for the `crates` job; any
352 deployment/downstream launch also requires its applicable authorization.
353
354 The Android target is cross-built and included in the checksum/bundle gates,
355 but GitHub's Linux runner cannot execute the Android binary as a real Termux
356 user. Keep the real-device limitation in the release packet unless separate
357 device evidence exists.
358
359 To exercise `npm run release:check` locally as well, regenerate the local asset
360 directory with a full asset matrix fixture before starting the server:
361
362 ```bash
363 DEEPSEEK_TUI_PREPARE_ALL_ASSETS=1 node scripts/release/prepare-local-release-assets.js
364 cd npm/codewhale
365 DEEPSEEK_TUI_VERSION=X.Y.Z DEEPSEEK_TUI_RELEASE_BASE_URL=http://127.0.0.1:8123/ npm run release:check
366 ```
367
368 Set `DEEPSEEK_TUI_VERSION` to the npm package version you are verifying for that local run.
369
370 CNB can supply a separate Linux tarball/install receipt. The final manual
371 full-CI run supplies hosted Linux, macOS and Windows wrapper smoke. Neither
372 proves installation from a subsequently published registry or a real provider
373 turn; retain those separate acceptance receipts where required.
374
375 After publishing, prove the release is visible in both registries:
376
377 ```bash
378 ./scripts/release/check-published.sh X.Y.Z
379 ```
380
381 Do not mark a Rust release complete until that command sees `codewhale@X.Y.Z`
382 on npm and every `codewhale-*` crate at `X.Y.Z` on crates.io, except
383 `codewhale-ratatui`, which it checks at its own version. For a rare
384 npm packaging-only release, run with `--allow-npm-binary-mismatch` and keep the
385 release notes explicit that no new Rust binary version shipped.
386
387 ## Historical Branch and Checkout Inventory
388
389 No new agent release/integration branch is part of this process. Inspect active
390 branches and checkouts with `git branch -a`, `git worktree list`, and
391 `git status` before cleanup. Removal of any branch or checkout needs explicit
392 Hunter approval for the named targets. Preserve unique commits, dirty/untracked
393 work, and contributor credit before an approved cleanup. Cleanup does not block
394 a release once its canonical source is reconciled.
395
396 Report canonical path, branch, SHA, upstream state and unresolved work at
397 handoff. Keep backups as recovery artifacts, not alternate development lanes.
398
399 ## Rust Crates Release
400
401 The `crates` job in `.github/workflows/release.yml` publishes to crates.io once
402 Hunter approves it. It uses the protected `release` environment (Hunter is the
403 required reviewer), which holds the crates.io publish token as the environment
404 secret `CARGO_REGISTRY_TOKEN`; the job cannot read the secret until the
405 deployment is approved. It runs only for a stable `vX.Y.Z` tag of
406 `codewhale-hq/Codewhale`, after the GitHub Release and npm jobs succeed, so a
407 crates.io failure or a long rate-limit wait never holds or half-publishes
408 either of them. Users who install from crates.io see the previous version until
409 the job finishes; npm and the GitHub Release are the canonical channels.
410
411 The job checks out the tag commit, runs `require-release-tag-checkout.sh`, then
412 runs `publish-crates.sh publish` from a fresh `CARGO_HOME` and build directory
413 under `$RUNNER_TEMP` with the token in that one step's environment, and finally
414 runs `check-published.sh X.Y.Z`. Verifying all 46 tarballs is a cold build of
415 over an hour on a hosted runner, so the job allows 360 minutes, the hosted
416 maximum. A missing secret fails the publish step before any build, naming the
417 secret and the environment. Runs for the same tag never overlap. A timeout or
418 failure after some uploads is recovered by **Re-run failed jobs** (and
419 approving again): the script skips every version the crates.io index already
420 serves and uploads the rest. Prereleases publish no crates.
421
422 Running the helpers from a developer workstation (step 5) remains the
423 documented fallback for when the job cannot run or the secret is not stored.
424
425 Trusted publishing is the intended replacement for the stored token: crates.io
426 would then mint a short-lived token from the job's GitHub OIDC identity. It
427 needs each of the 46 release crates configured on crates.io with a trusted
428 publisher for `codewhale-hq/Codewhale`, workflow `release.yml` and environment
429 `release`, plus `id-token: write` on the `crates` job and a token-exchange step.
430 It is not implemented.
431
432 Release preparation lands directly on canonical `main` in verified slices. The source must be on
433 `main` before any approved `vX.Y.Z` tag is pushed. The tag release workflow runs
434 `scripts/release/ensure-release-on-main.sh` for tag pushes and manual dispatches,
435 and fails branch-only release sources before assets are published.
436
437 1. Write the CHANGELOG entry, then run
438 `./scripts/release/prepare-release.sh X.Y.Z` — it bumps every
439 version-bearing file (workspace + crate pins + npm wrapper + Runtime SDK +
440 VS Code extension/lock + public source-candidate
441 facts + README install tags), refreshes the Cargo/npm locks and generated
442 files, and runs
443 the version and OHOS gates. It is safe to rerun after the workspace already
444 equals `X.Y.Z`: the second run skips replacements, refreshes the packaged
445 changelog and web facts, and reruns both gates.
446 2. Freeze clean canonical `main` at the intended SHA, run
447 `./scripts/release/publish-crates.sh dry-run`, and complete the exact-SHA
448 manual full-CI/RC and version-specific acceptance gates above. Retain the
449 receipts rather than repeating unchanged local checks.
450 3. Obtain Hunter's explicit publication approval, then create `vX.Y.Z`
451 from `main` with the manual **Create release tag** workflow or with a signed
452 local tag push from a developer machine.
453 - If `RELEASE_TAG_PAT` is configured, the tag push starts `release.yml`.
454 - If no Release run appears and the tag already exists, first confirm that
455 no tag-triggered run is queued or active, then dispatch the exact tag:
456 `gh workflow run release.yml --ref vX.Y.Z -f version=X.Y.Z`.
457 - Never dispatch from `main`, and do not start a duplicate while the
458 tag-triggered run is merely delayed. The workflow serializes runs for the
459 same tag. It also refuses to start release work when that tag already owns
460 any GitHub Release asset, rechecks immediately before upload, and disables
461 the release action's overwrite behavior. A normal rerun must never replace
462 public bytes.
463 4. Wait for the GitHub Release workflow and all public assets to finish, then
464 fetch the release tag and run the public asset gate. Do not publish any
465 Cargo or npm package until it passes:
466
467 ```bash
468 git fetch origin tag vX.Y.Z
469 ./scripts/release/verify-release-assets.sh X.Y.Z
470 ```
471
472 5. When the Release run shows the `crates` job waiting for the `release`
473 environment, Hunter approves it (**Review deployments** on the run). The
474 job publishes and ends with `check-published.sh`; then verify with
475 `./scripts/release/check-published.sh X.Y.Z` from any checkout. If the job
476 reports the secret missing, store `CARGO_REGISTRY_TOKEN` in the `release`
477 environment and re-run the failed job, or use the fallback below.
478
479 **Manual fallback.** Publish approved Rust crates from the same clean
480 canonical checkout on `main`, with `HEAD` still matching the immutable
481 remote release tag. Do not run it while the `crates` job is running for the
482 same tag:
483
484 ```bash
485 ./scripts/release/require-release-tag-checkout.sh X.Y.Z && {
486 mode=publish
487 cache="${CODEWHALE_CACHE_ROOT:-${XDG_CACHE_HOME:-$HOME/.cache}/codewhale}"
488 lock="${CODEWHALE_BUILD_LOCK_FILE:-${cache}/build.lock}"
489 root="${cache}/release-verify-$(git rev-parse --short=10 HEAD)-${mode}-$(date -u +%Y%m%dT%H%M%SZ)"
490 token=; while [ -z "${token}" ]; do printf 'crates.io token: ' >&2; read -rs token || break; echo >&2; done
491 [ -n "${token}" ] && mkdir -p "${cache}" && mkdir "${root}" &&
492 CARGO_REGISTRY_TOKEN="${token}" CARGO_HOME="${root}/cargo-home" \
493 CARGO_TARGET_DIR="${root}/target" \
494 python3 scripts/build-lock.py "${lock}" -- ./scripts/release/publish-crates.sh "${mode}"
495 unset token
496 }
497 ```
498
499 Both Cargo and npm publication fail closed unless `HEAD`, the clean local
500 checkout, and the remote `vX.Y.Z` tag still agree. The authoritative crate
501 dependency order lives in `scripts/release/crates.sh`; do not maintain a
502 second handwritten order in this runbook. The helper waits for each new
503 version to appear in the crates.io sparse index before moving to dependents
504 and safely skips versions the index already serves on a rerun. On HTTP 429
505 it sleeps until the time crates.io names (ten minutes if none) and retries,
506 up to ten times per crate; any other upload failure stops the run. The
507 block runs it from a new, empty `CARGO_HOME` and build directory of its own, as the package preflight
508 above describes; the dry run's state makes it refuse otherwise. The braces
509 make the shell read the whole block before `read` runs, so a pasted or
510 piped block never takes its own next line as the token, and the prompt
511 repeats on an empty line, so a stray blank line from a paste is not
512 taken as the token. `read -rs` keeps the token out of shell history,
513 end of input stops the block, and the environment variable keeps the
514 token out of `credentials.toml`. The tag check is chained with `&&`, so a
515 failed check asks for no token.
516 If shared `main` advances or the checkout becomes dirty, stop and coordinate
517 a new candidate or separately authorized recovery with Hunter. Do not switch
518 branches, create another checkout, force-fetch a conflicting tag or bypass
519 the guard.
520
521 The publish helper is idempotent for reruns, in the job and by hand:
522 already-published crate versions are skipped. In both paths it verifies the
523 tarballs with `CARGO_REGISTRY_TOKEN` removed from Cargo's environment; each
524 real upload still builds that crate with the token present.
525
526 ## GitHub Release Assets
527
528 `.github/workflows/release.yml` builds and stages these artifacts:
529
530 - one `codewhale-*` runtime binary for Linux x64/arm64, Android arm64, macOS
531 x64/arm64, and Windows x64/arm64
532 - byte-identical `codew-*` command assets copied from that runtime
533 - byte-identical `codewhale-tui-*` compatibility filenames so installed v0.9.4
534 clients can discover and complete the one-runtime upgrade; current installers
535 never expose those filenames as a third command
536 - `codewhale.bat` for the Windows npm/GitHub x64 launcher, and the same
537 filename inside Windows zip archives and the NSIS install (those copies
538 launch `codewhale.exe` and prefer Windows Terminal)
539 - platform `.tar.gz` / `.zip` archives and `CodeWhaleSetup.exe`
540
541 The release job also uploads `codewhale-artifacts-sha256.txt` and
542 `codewhale-bundles-sha256.txt`. The npm installer and release verification
543 script depend on those manifests. The authoritative release asset list lives in
544 `npm/codewhale/scripts/artifacts.js`.
545
546 Before any Cargo or npm publish, prove that the public GitHub Release assets
547 belong to the tag commit you are publishing:
548
549 ```bash
550 ./scripts/release/verify-release-assets.sh X.Y.Z
551 ```
552
553 That gate compares the local and remote `vX.Y.Z` tag SHAs, confirms a
554 successful `Release` workflow run used that SHA, then runs the npm wrapper's
555 release check against the public GitHub asset URLs. The npm check fails if the
556 release is missing a required binary, archive, installer, or manifest; either
557 manifest omits a required row; or the assets predate the matching release
558 workflow run. If the command fails, rerun or repair `release.yml`; do not
559 publish Cargo or npm against stale assets.
560
561 ## AUR / Omarchy Package
562
563 `codewhale-bin` is a downstream package of the same Linux release, not a new
564 Codewhale semantic version. After the public asset gate above passes, render
565 its AUR metadata from the verified release directory:
566
567 ```bash
568 ./packaging/aur/render.sh /path/to/release-assets /tmp/codewhale-bin
569 ```
570
571 The renderer reads the workspace version and extracts the x64/arm64 archive
572 hashes only after both release checksum manifests agree with the actual files.
573 It emits no `SKIP` checksums or source-controlled per-release values. Follow
574 [`packaging/aur/README.md`](../packaging/aur/README.md) for the clean Arch build,
575 `.SRCINFO` comparison, and package-content checks.
576
577 The GitHub release workflows only verify that the AUR metadata can be rendered
578 from their candidate assets. They do not publish to AUR. AUR publication is a
579 separate, explicitly authorized maintainer action after the matching tag and
580 assets are public.
581
582 ## npm Wrapper Release
583
584 `release.yml` publishes `codewhale` through npm Trusted Publishing after the
585 exact-SHA GitHub Release job succeeds. The job has only `contents: read` and
586 `id-token: write`; it does not use `NPM_TOKEN`, `NODE_AUTH_TOKEN`, or a
587 long-lived bypass-2FA credential.
588
589 Before the first automated publish, configure the `codewhale` package's npm
590 Trusted Publisher with these exact values:
591
592 - organization or user: `codewhale-hq`
593 - repository: `Codewhale`
594 - workflow filename: `release.yml`
595 - environment: leave blank (the workflow does not claim a GitHub environment)
596
597 That npm-side binding is an external release gate. If it is missing or differs
598 in case, repository, workflow filename, or environment, the publish job must
599 fail; do not add a token fallback to make it pass.
600
601 ### Steps
602
603 1. Set the npm package version in [npm/codewhale/package.json](../npm/codewhale/package.json) to match the workspace `Cargo.toml`. CI's version-drift guard will catch mismatches before tag.
604 2. Set `codewhaleBinaryVersion` to the GitHub release tag that should supply binaries.
605 3. Follow the single candidate/approval/tag sequence above. `release.yml` builds
606 the binary matrix and publishes the GitHub Release after its artifact and
607 container-build gates. CNB release-tag sync and GHCR uploads depend on that
608 GitHub publication; include these destinations in publication approval.
609 4. **Wait for the GitHub Release to finalize** with the full binary and archive
610 matrix, Windows installer, and both checksum manifests. The dependent `npm`
611 job checks the remote tag again, runs the public asset freshness gate and
612 package tests, then publishes with OIDC. The package's `prepublishOnly` hook
613 repeats the clean exact-tag and public-asset checks immediately before the
614 registry write.
615 5. Confirm the `npm` job succeeded, then prove the published package and binary
616 version are visible:
617
618 ```bash
619 npm view codewhale@X.Y.Z version codewhaleBinaryVersion --json
620 ./scripts/release/check-published.sh X.Y.Z
621 ```
622
623 For a rare packaging-only npm release where the npm package version intentionally
624 points at older Rust binaries, add `--allow-npm-binary-mismatch` and keep the
625 release notes explicit that no new binary version shipped. That exception is a
626 separate manual release path: the normal trusted-publishing job deliberately
627 does not set `CODEWHALE_ALLOW_NPM_BINARY_MISMATCH`.
628
629 Legacy `npm/deepseek-tui/` has been retired from the repository; npmjs `deepseek-tui` stays deprecated and unpublished.
630
631 ### Manual recovery
632
633 If GitHub OIDC is unavailable after the GitHub Release and public-asset gate are
634 green and manual npm publication is approved, use the same clean canonical
635 checkout on `main` with `HEAD` matching the immutable tag. Authenticate
636 interactively with npm's normal WebAuthn/2FA flow; never create a long-lived
637 bypass-2FA token:
638
639 ```bash
640 ./scripts/release/require-release-tag-checkout.sh X.Y.Z
641 ./scripts/release/verify-release-assets.sh X.Y.Z
642 npm login
643 npm whoami
644 cd npm/codewhale
645 npm publish --access public
646 ```
647
648 The same `prepublishOnly` gates rerun on every attempt. An OIDC or login failure
649 is not permission to edit the tagged package, move the tag, or skip asset
650 verification.
651
652 ## CNB Cool mirror
653
654 The `Sync to CNB` workflow mirrors `main` source pushes (and existing supported
655 contributor branch patterns) to `cnb.cool/codewhale.net/codewhale` for source
656 access and Linux CI. These workflow patterns do not require an agent branch.
657 Release-tag sync is called by `release.yml` after canonical GitHub publication;
658 an ordinary GitHub tag push is not an independent CNB publication receipt.
659 After approved release publication, **verify the mirror caught the exact tag**
660 before declaring that destination shipped:
661
662 ```bash
663 git ls-remote https://cnb.cool/codewhale.net/codewhale.git refs/tags/vX.Y.Z
664 ```
665
666 If the workflow failed for the release tag, use the exact-tag rerun or
667 `workflow_dispatch --ref vX.Y.Z` recovery documented in
668 [docs/CNB_MIRROR.md](CNB_MIRROR.md#manual-fallback).
669
670 ## Website Deployment
671
672 For a stable (`X.Y.Z`, non-prerelease) tag of `codewhale-hq/Codewhale`,
673 `.github/workflows/release.yml`'s `web_deploy` job deploys `codewhale.net`
674 automatically once both the `release` (GitHub Release) and `npm` jobs succeed.
675 The job holds only `actions: write` and `contents: read` (no Cloudflare
676 credentials): it resolves `main`'s current 40-character SHA, confirms `main`
677 contains the tagged release commit, dispatches `.github/workflows/web.yml` on
678 `main` with `-f expected_sha=<main_sha>`, waits for both `Lint & Type Check` and
679 `Deploy to Cloudflare` to succeed, and then polls `https://codewhale.net/en` for
680 up to 120 seconds until the page prints `Version X.Y.Z is released`.
681
682 `web.yml` keeps its existing `workflow_dispatch`-on-`main` contract,
683 `deploy-codewhale-web` concurrency serialization, `check:deploy-env` credential
684 preflight, and post-deploy `check:deployed-facts` exact-SHA check. Before
685 building the OpenNext bundle, `deploy` refreshes the published-release facts
686 from GitHub's latest release (`sync-latest-release.mjs`, `derive-facts.mjs`,
687 `derive-release-docs.mjs`) so `codewhale.net` serves `Version X.Y.Z is released`
688 immediately without waiting for `sync-release-record`'s pull request to merge.
689 Prereleases skip `web_deploy`.
690
691 ### Manual fallback
692
693 If `web_deploy` fails or a post-release website fix lands on `main`, dispatch
694 `web.yml` manually on `main` with `expected_sha` and verify the live page:
695
696 ```bash
697 git fetch origin main
698 gh workflow run web.yml --repo codewhale-hq/Codewhale --ref main \
699 -f expected_sha="$(git rev-parse origin/main)"
700 curl -fsSL https://codewhale.net/en | grep -F "Version X.Y.Z is released"
701 ```
702
703 ## Recovery and Rollback
704
705 ### Re-tagging an UNPUBLISHED release (pulled before npm/crates)
706
707 If `vX.Y.Z` was tagged and a GitHub Release was created, but **no package was
708 published** (npm still on the prior version, `check-published.sh` shows the
709 crates unpublished), the tag is still recoverable — a bug found after tagging
710 can be fixed and the same version recut. Confirm first that nothing consumed it:
711 `npm view codewhale version` and crates.io both show the PRIOR version, no
712 Homebrew/Winget/mirror points at it, and the GitHub Release download counts are
713 only the release pipeline's own verification passes. Then, only with explicit
714 Hunter approval naming the release/tag to remove and recreate, use this
715 exceptional recovery sequence:
716
717 ```bash
718 # 1. land the verified fix on canonical main, then freeze its new candidate
719 # 2. delete the premature Release + tag
720 gh release delete vX.Y.Z --repo codewhale-hq/CodeWhale --yes --cleanup-tag
721 git push origin :refs/tags/vX.Y.Z # belt-and-suspenders
722 git tag -d vX.Y.Z # local
723 # 3. validate the fixed HEAD: full CI and RC (Parity included), same exact SHA
724 candidate_sha="$(git rev-parse HEAD)"
725 gh workflow run ci.yml --repo codewhale-hq/Codewhale --ref main \
726 -f expected_sha="${candidate_sha}"
727 gh workflow run release-candidate.yml --repo codewhale-hq/CodeWhale --ref main \
728 -f expected_sha="${candidate_sha}"
729 # 4. after both receipts and approval, recut at that same HEAD
730 gh workflow run auto-tag.yml --repo codewhale-hq/CodeWhale --ref main
731 # 5. release.yml rebuilds assets; rebuild + reinstall locally from the new tag
732 ```
733
734 This is the sanctioned path from "do not delete/move/recreate a release tag
735 implicitly": it is explicit, approved, and only for a tag no registry consumer
736 has treated as public. Never do it once a crate or the npm wrapper is published
737 for that version — bump to the next patch instead.
738
739 ### External publish gates (not code defects)
740
741 - **crates.io:** publishing needs a valid crates.io publish token, passed to
742 the publish command as `CARGO_REGISTRY_TOKEN` (Rust crates release, step 5).
743 Verify it with an authenticated, read-only *client* call rather
744 than the `/api/v1/me` endpoint: crates.io answers `/api/v1/me` with
745 `403 {"errors":[{"detail":"this action can only be performed on the
746 crates.io website"}]}` even for a good token (checked 2026-09-21 with a
747 token that `cargo owner` accepts), so a 403 there proves nothing about the
748 credential. A good token prints the owner, e.g. `Hmbown (Hunter Bown)`:
749
750 ```bash
751 {
752 token=; while [ -z "${token}" ]; do printf 'crates.io token: ' >&2; read -rs token || break; echo >&2; done
753 [ -n "${token}" ] && CARGO_REGISTRY_TOKEN="${token}" cargo owner --list codewhale-tui
754 unset token
755 }
756 ```
757
758 A 403 or `401` from this call, or `cargo publish` refusing credentials,
759 means the token is missing/expired. Create a new token, check it with this
760 call, then rerun the step 5 block. It makes another new `CARGO_HOME` and
761 build directory, which the rerun needs because the failed run's own state makes
762 the guard refuse otherwise, and it keeps the token out of that root.
763 - **npm:** the OIDC job publishes only if the npmjs.com Trusted Publisher for
764 `codewhale-hq` / `Codewhale` / workflow `release.yml` / blank environment is
765 configured. Missing config → the `npm` job fails `E404 No match found`. Fix
766 the binding (or use the manual WebAuthn recovery above), then re-run the
767 failed `npm` job: `gh run rerun <release-run-id> --failed`.
768
769 - User-facing rollback:
770 - npm: `npm install -g codewhale@X.Y.Z`
771 - Cargo: `cargo install codewhale-cli --version X.Y.Z --locked --force`;
772 add an optional `codew` alias as documented in
773 [docs/INSTALL.md](INSTALL.md#7-build-from-source)
774 - manual assets: download binaries or the platform archive plus the matching
775 `codewhale-artifacts-sha256.txt` or `codewhale-bundles-sha256.txt`
776 manifest from `https://github.com/codewhale-hq/CodeWhale/releases/tag/vX.Y.Z`
777 - workspace files: use `/restore list [N]` and `/restore <N>` for side-git
778 snapshots; this does not change the installed binary version or rewrite
779 conversation history
780 - keep [docs/INSTALL.md](INSTALL.md#roll-back-to-a-previous-release) in sync
781 with these commands
782 - Crates publish partially:
783 - rerun the Rust crates release step 5 block; its timestamped root gives
784 each rerun another new, empty `CARGO_HOME` and build directory, and the failed
785 run's own state makes `publish-crates.sh publish` refuse otherwise
786 - already-published crate versions will be skipped
787 - GitHub assets missing or checksum manifest incomplete:
788 - fix `.github/workflows/release.yml`, but do not rerun it over an existing
789 asset set and do not delete assets merely to make the guard pass
790 - if any asset may have been public or consumed, cut a new patch version
791 - only after explicit maintainer approval and proof that no downstream
792 publication or consumer treated the failed asset set as public may a
793 deliberately scoped recovery remove the failed release before an exact-tag
794 rerun; record that exception in the release packet
795 - npm packaging-only problem:
796 - bump only the npm package version
797 - keep `codewhaleBinaryVersion` on the last known-good Rust release
798 - repack and republish the wrapper
799 - A bad npm publish cannot be overwritten:
800 - publish a new npm version with corrected metadata or install logic
801 - CNB mirror failed for the release tag:
802 - check the run via `gh run list --workflow=sync-cnb.yml`
803 - rerun the failed tag run, or dispatch
804 `gh workflow run sync-cnb.yml --ref vX.Y.Z`; never omit the tag ref
805 - follow the proof steps in
806 [docs/CNB_MIRROR.md](CNB_MIRROR.md#manual-fallback)
807 - Website deploy (`web_deploy`) failed after release:
808 - inspect the dispatched `web.yml` run URL logged by `web_deploy`
809 - rerun the failed `web_deploy` job once the underlying issue is resolved, or
810 dispatch `gh workflow run web.yml --repo codewhale-hq/Codewhale --ref main -f expected_sha="$(git rev-parse origin/main)"`
811 - confirm `https://codewhale.net/en` prints `Version X.Y.Z is released`
812 - Workflow runner failure or hung release job:
813 - every release-lane job carries an explicit `timeout-minutes` to contain
814 unattended runs, but timeouts are containment rather than immediate recovery
815 - if a workflow job sits `in_progress` with 404 logs (or produces no useful
816 log output for 20 minutes), cancel the run and rerun failed jobs / dispatch
817 an exact-ref rerun rather than waiting out the full job timeout
818 - check the last-useful-log timestamp before cancelling to distinguish an
819 infrastructure failure (runner dropped / HTTP 404 on log stream) from a
820 legitimate long build step (e.g. Windows artifact compilation)
821
821 lines MARKDOWN