# Contributing to dsh-opencode-patch

## Prerequisites

- Node.js `>= 24` (CI runs the version in `.node-version`, and the floor in a job of its own), `pnpm` (v12). The suite refuses to start below the floor and names both versions: below it, `node:sqlite`, `Intl.DurationFormat` and the ICU strings the tests pin differ, and the failures read like regressions.
- The plugin supports the latest release of **both** harness channels, `rc` (its newest build, which the harness publishes under `dsh@next` ahead of `dsh@latest`) and `alpha` (`dsh@alpha`). Their hosts (the `@deepseek-ai` cluster, cordis, its loader, and the pi range the bridge declares) are named once, in `test/support/host-versions.ts`. `pnpm install` installs the alpha channel from the root lockfile; `node --experimental-strip-types scripts/use-channel.ts rc` switches to the rc channel's committed lockfile (`channels/rc/pnpm-lock.yaml`), `… alpha` switches back, and `--floor` puts pi at the range's floor (the harness's own pin) for a local run. Each install runs pi **unpatched**, as an npm user does: this repository carries no pi patch. A switch restores every file it touched, so `git status` stays clean, and the suite reads which channel is installed from the marker the switch leaves (`DSH_CHANNEL` overrides it). `scripts/use-channel.ts rc --relock` regenerates the rc lockfile from the root one, and it runs in the same commit as **any** change to `package.json`'s dependencies or to `pnpm-workspace.yaml`'s catalog or overrides, not only a channel bump: the rc lockfile carries every specifier the root one does, CI installs it frozen, and `test/harness-channel.test.ts` fails, naming the command, when the two disagree (a Dependabot pull request included, which cannot relock it). A relock keeps the cordis family at the record's floors: `package.json` pins every member the install resolves (cordis, the loader, include, group, cosmokit, schemastery; the timer plugin is resolved by nothing here) and `pinFor` moves each with the channel, so pnpm resolves include and group (peers it installs itself) and cosmokit (a dependency of cordis) from those pins rather than taking the newest patch inside their `~` ranges. A relock that fails the family case in `test/harness-channel.test.ts` means a member arrived some other way: pin it the same way, never loosen the case.
- A checkout of this repo; for live testing, a DeepSeek Harness profile (see README for the `link:` setup)

## Commands

All tasks go through `pnpm` (which delegates to the Vite+ toolchain):

```sh
pnpm install     # install dependencies
pnpm run check   # format + lint + types; zero errors and zero warnings (a lint warning fails it: vp check --deny-warnings)
pnpm run typecheck   # tsc over src/, scripts/ and every test file, the .tsx ones included
pnpm run build   # vp pack + client rename -> lib/index.mjs, lib/index.d.mts, lib/client.js (before the tests: the client-bundle tests read lib/)
pnpm run test    # Vitest suite, must be fully green and deterministic
pnpm run test:coverage   # the same run, with the coverage ratchet enforced
pnpm run test:shuffle    # the same run in a random order; reproduce a failure with --sequence.seed=<n>
pnpm run test:mock       # gateway mock suite: offline, loopback only, runs in CI
node --experimental-strip-types scripts/check.ts   # bundle gate: lib freshness, consumer install (both halves), size
pnpm run test:e2e   # opt-in end-to-end suite; talks to the real OpenCode gateway
pnpm run test:e2e:host  # opt-in: the published host binary with the probe (see "The e2e-host job")
pnpm run catalog:shim   # is src/catalog-data.ts current? (-- --write regenerates it from models.dev)
pnpm run limits:shim    # is src/go-limits-data.ts current? (-- --write regenerates it)
pnpm run cli:version    # is the pinned OpenCode CLI version the published one? (-- --copies: does every copy agree with it?)
```

CI runs the same steps through one composite setup action (`.github/actions/setup`: pnpm from `packageManager`, Node from `.node-version`, a frozen install), after each job's own checkout, and builds explicitly before anything that reads `lib/`. The unit suite runs once per install: the default install (alpha, newest pi) runs it as `test:coverage`, which is the ratchet, in the `check · test · build · gate` job (the one status check `main` requires, so a red suite or a coverage drop blocks a merge), and every other cell of the `test` matrix runs `pnpm run test`. `pnpm run typecheck` is for local use only: CI type-checks the same tsconfig program through `pnpm run check` (`vp check --deny-warnings`, whose lint config has `typeCheck` on), and runs no `typecheck` script.

> Note: in some shells `pnpm exec` stalls; invoke the binary directly if so: `node node_modules/.pnpm/vite-plus@*/node_modules/vite-plus/bin/vp <cmd>`.

## End-to-end suite

`pnpm run test:e2e` runs `test/e2e/**/*.e2e.ts` through its own config (`vitest.e2e.config.ts`), so `pnpm run test` stays a fully offline, deterministic unit run. Nothing here is collected by the unit suite. Every e2e-only switch these files obey — `OPENCODE_E2E`, the key tier, a mirror's bases, the record directory, the CI run and the host-binary cell — is read in one place, `test/support/e2e-env.ts` (`readE2eEnvironment`, and `e2e()` for the process's own, read on first call); no e2e file reads `process.env` for them itself. The one switch they share with the unit and real-host suites, the harness channel (`DSH_CHANNEL`, `DSH_PI`), is read by `test/support/host-versions.ts` (`selectedHost`).

```sh
OPENCODE_E2E=1 OPENCODE_API_KEY=… OPENCODE_GO_API_KEY=… pnpm run test:e2e
```

- `OPENCODE_E2E=1` is required; without it every case skips, so a bare `pnpm run test:e2e` is a safe no-op.
- `OPENCODE_API_KEY` (Zen) arms the live `/models` enrichment case and the **paid** protocol-routing cases; `OPENCODE_GO_API_KEY` (Go plan) arms the live `/usage` case. Both keys also arm the keyed probes (`keyed-probes.e2e.ts`, each plane with its own key) on the `probes` tier and above, while the full keyed suites need the `full` tier (`OPENCODE_E2E_KEYED`, below). Each block skips when its key is absent, which is why the CI `e2e` job stays green on fork PRs (secrets are not exposed to them) while still checking the endpoints answer.
- The **free-tier and unmetered** routing cases run keyless on purpose: measured 2026-10-06, a paid model answers `401 AuthError` on every endpoint without a credential, so keyless probing cannot tell the right PROTOCOL endpoint from a wrong one. Keyless protocol discrimination is real only for the free classes. What a paid model's keyless answer does still tell is whether a PATH exists at all — a removed path answers 404 — which is the one thing the keyless matrix below reads.
- `OPENCODE_E2E_KEYED` is the tier of what may spend a key: `none` runs only the keyless cases, `probes` adds the minimal keyed probes (`keyed-probes.e2e.ts`), and `full` adds the full keyed suites (`protocol-routing`, `opencode-live`'s keyed blocks, `dispatch-levels`' live block). Unset means `full`, so a local run with keys arms everything; any other value fails the run. CI sets it per event — `probes` on a pull request that touches `src/host/**`, `src/utils/protocols.ts` (the legacy URLs the probes send and the protocol each probe model speaks), `src/utils/plane-model.ts` (the family the plugin dispatches to, `AUTO_ENDPOINT_FAMILY`, which the probes must keep matching), `src/identity.ts` (the CLI version in the user agent the probes carry), `src/utils/request-shape.ts` (the `anthropic-version` every Messages probe sends) or the probes' own inputs (the composite setup action under `.github/actions/` among them); `full` nightly; on a dispatch, its `keyed` input (`full` when empty, and `none` from the nightly bump proposal's floor-cell dispatch); `none` otherwise — and passes the secrets only when it is not `none`. Nothing else arms them. Left out, and covered by the offline suite and the nightly run, which arms everything: the generated catalog (`src/catalog-data.ts`) and the live model choice (`src/models-catalog.ts`), which pick the probes' modern URLs and models and whose paths the keyless matrix checks on every pull request; and the `OPENCODE_UA` alias in `src/session.ts`, which a turn and a probe share, so `test/keyed-probes.test.ts` holds the probe's identity to the real fetch patch offline.
- `OPENCODE_E2E_RECORD_DIR`, when set, is where the keyless matrix and the keyed probes write their dated tables (`keyless.md`, `keyed.md`); CI publishes them to the run summary and the `endpoint-families` artifact, and a run's tables are pasted into `docs/redirect-planes.md` §13.
- `OPENCODE_ZEN_BASE_URL` / `OPENCODE_GO_BASE_URL` retarget `opencode-live` and `protocol-routing` at a mirror. The keyless matrix and the keyed probes measure the vendor's own paths, which a mirror's base cannot name, so both skip while either is set.

The e2e files, one job each:

- `opencode-live.e2e.ts` — the only place the plugin meets the real API. It catches what a stub cannot: **the vendor changing the payload**. The meter parses `/zen/go/v1/usage` and the picker consumes an enriched `/models` listing, so both shapes are asserted against the live service. The unkeyed cases assert reachability (never a 404) and that our header set does not change the gateway's verdict on a request — compared against the same call without it, rather than hardcoding a status the vendor may tighten.
- `keyless-matrix.e2e.ts` — the keyless 401-vs-404 matrix: two planes × four protocols × three URL shapes — legacy (`/zen(/go)/v1`), the root (`/inference(/go)/v1`, the provider-level base the catalog declared until 2026-10-16) and modern (`/inference(/go)/{openai,anthropic,google}/…`) — one PAID model per cell from the live catalog, never a free one, which the gateway serves keyless with a real completion. It **sends no key and reads none**, so the `e2e` job runs it on every pull request, and it retries a cell once on a 429, a 5xx or a transport error before reading it. A 404 means the path is gone, a 401/403 that it exists, a 410, a 400 "Model is unavailable" or a refusal of type `ModelDeprecated` at any status that the model is. It asserts that all twenty-four cells have a model and were sent, that every legacy and modern answer is readable (a root answer is recorded whatever it is: nothing dispatches there), and that no cell the plugin dispatches to today with the default endpoint (`auto`, an alias of `modern`; `TODAY_DISPATCH`: all four protocols on the modern family, per plane) is gone. A redirect is never followed (`redirect: "manual"`): it reads as `redirected`, unreadable. Beside the matrix, a keyless free-model probe sends a free completions model to `/inference/openai/v1/chat/completions` and asserts it is served or free-tier-gated; a retired free model (`model-gone`, a `ModelDeprecated` refusal included) or a busy upstream (a 503, a 529, or a 5xx naming an overload) moves on to the next candidate (`runFreeProbe`, which records the deciding candidate's own model and status), and a rate limit (a 429, or a 429 and then no answer), a busy upstream no candidate got past, or the free tier's usage cap (`429 FreeUsageLimitError`, its own verdict `free-usage-limited`, never retried and never read as served) skips it. The System One family's three shapes on the Zen plane (`/zen/v1/systemone`, `/inference/v1/systemone`, `/inference/systemone/v1/systemone`) are probed keyless with no model and recorded, never asserted: the plugin serves no classifier. `endpoint: legacy` is recorded, not guarded: the cells it dispatches to (`LEGACY_DISPATCH`: completions, Responses and Messages on both planes, and Zen's Google; Go's Google stays on `/inference/go/google/v1beta`, `GO_GOOGLE_BASE_URL`) must answer readably, like every legacy cell, but their path-gone is recorded and asserted nowhere live (Go's Google, whose cell under `endpoint: legacy` is the modern one, is guarded as a default cell), and `test/endpoint-family.test.ts` pins their mapping offline. Both probe suites rewrite their record after every cell, so a job killed at its time limit keeps what it measured. The cell table, the sets and the classifiers are a pure module (`test/support/keyless-matrix.ts`), unit-tested offline in `test/keyless-matrix.test.ts`, which also derives `TODAY_DISPATCH` from the URLs each host cell's rows measured (every cell reaches the same cells: the plugin builds every base from its own endpoint table).
- `keyed-probes.e2e.ts` — the keyed half: the same twenty-four cells, each sent with the plane's own key in the header its protocol reads, the plugin's identity headers (`PROBE_IDENTITY`: the turn's user agent, `x-opencode-client`, `x-opencode-project`, an in-band session id under both session headers — the Go plane refuses a keyed request without one; the per-request metric id `x-opencode-request` is left out on purpose) and a body of a few output tokens, on the `probes` and `full` tiers. Per plane it decides from the `TODAY_DISPATCH` cells (`planeOutcome`), each read beside the legacy and root cells of the same protocol, which carry the same model and key: it fails when one answers path-gone, wrong-protocol or auth-refused, a retired model another shape accepted, or nothing readable — `other`, a redirect, a refused session, `transport-error` or `no-model`. Only a wrong-protocol, path-gone, auth-refused or model-gone that the cell `endpoint: legacy` dispatches to — a different one, so never Go's Google — accepted is flip evidence; a refusal only the root or Go Google's `/zen/go` cell accepted is red but not evidence (no flip reaches it), a key refused on every shape that read it names the CI secret instead, and a protocol or a path the flip's cell measured nothing about asks for a re-run. The account's answer counts as acceptance beside a refused key or a gone path, never beside a refused protocol or model. It skips when none of them was served (the account's answer, a rate limit, a busy upstream, a retired model, a parsed but refused body), since that measured nothing. Every other cell is recorded. Like the keyless matrix, it skips while a mirror base URL is set. A second case per plane records, and asserts nothing about: the lessons' variants of the default completions cell (a minted `x-opencode-request`; `x-opencode-project` as a folder name and as a 40-hex digest beside the identity's `global`; a paid completions model that reasons, with no `reasoning_effort` and with `"none"`), for L4, L5 and L10; the console study's rows (the host's raw `session-<uuid>` session id, OC9; the session-only header set, OC8; the harness's User-Agent, OC6; and a free completions model sent keyless inside the keyed tier with the free turn's body, as the identity, with a raw session id and with the harness's User-Agent), which feed an owner's OC6 decision, the session derivation's OC9 and P6's OC8; and every keyed rate-limit 429's `Retry-After` (`retryAfterOf`; the keyless free rows and the free tier's usage cap are left out, `docs/redirect-planes.md` §13), for L9. Headers and keys are never printed, and a body only through a redacting excerpt. The cells, tier, classifier and plane outcome are `test/support/keyed-probes.ts`, unit-tested in `test/keyed-probes.test.ts`, which also runs every keyed cell through the offline gateway mock's judge.
- `protocol-routing.e2e.ts` — asks the gateway which endpoint serves each model's wire format, at the URL the plane adapter sends it to (the modern family by default, Go's Google included): keyless for the free classes, keyed (and skipped without a secret, or below the `full` tier) for paid ones. The keyed record of every URL shape per protocol, the legacy family included, is `keyed-probes.e2e.ts`. Its last block sends paid models through the plane adapter on a tier-A host: each protocol walks up to three candidates (`walkPerProtocol`, `test/support/live-walk.ts`, unit-tested in `test/live-walk.test.ts`), moving past an entitlement answer or a withdrawal that a raw probe of the same id confirms (`test/support/live-probe.ts`), and a protocol no candidate reached skips the case by name rather than passing.
- `dispatch-levels.e2e.ts` — a keyed live block, on the `full` tier, that sends one toggle model per plane and protocol through the plane adapter on a tier-A host with the picker's "On" effort, walking up to three toggle candidates per protocol the same way, and skips without the plane's key, below the `full` tier, or, naming it, when a protocol had no entitled, still-served candidate. Its offline half — every thinking level the picker offers is one pi's own rule accepts, swept over the whole shipped catalog — needs no network and no port, so it is `test/dispatch-levels.test.ts` in the unit run.
- `host-binary.e2e.ts` — the published host binary; see [The real-host harness](#the-real-host-harness). It skips unless `DSH_HOST_E2E=1`.

## Mock suite

`pnpm run test:mock` runs `test/mock/**/*.mock.ts` through `vitest.mock.config.ts`: every case that binds a socket lives there, and none of them needs a key or leaves the loopback interface, so CI runs it on every push. The gateway mock (`test/mock/opencode-gateway.ts`, served by `gateway-server.ts`) refuses what the vendor refuses, so a 200 means the request the plugin built also satisfies the endpoint's contract; `test/mock/helpers.ts` is the one harness (`gatewayHarness`, `fixtureModel`, `lastRecorded`), and a request the gateway mock judges takes its model from the catalog (`fixtureModel`, or `firstSpecFor` by SDK), never a named vendor id. Two exceptions are deliberate: `plane-dispatch.mock.ts` sends the characterized S0 ids, because they are the S0 fixture, and the model names in the two loopback-listener files (`patched-fetch-headers`, `refusal-classification`) are turn labels nothing judges. A case asserts what the PLUGIN put on the wire: one that would pass with a raw `fetch` carrying the same headers tests the mock, not the plugin, and does not belong here.

- `request-shapes.mock.ts` — the request shape per configuration: session, origin, project, user-agent, credential and the gateway's refusals passed through untouched.
- `protocol-endpoints.mock.ts` — each protocol's endpoint, streamed and unary, on its own credential header; the usage listing; the models listing enriched or not; the core-tool fallback.
- `plane-dispatch.mock.ts` — every characterized model on each plane, through the real `LlmRuntime` and the plugin's `PlaneAdapter` on a tier-A host.
- `protocol-compat.mock.ts` — plane × protocol × endpoint family, driven through pi's own protocol implementations.
- `patched-fetch-headers.mock.ts` — a local `node:http` listener, so the _outgoing_ header set crosses a real socket. The live gateway cannot echo a request back; everywhere else in the suite the injected headers are asserted against a captured `fetch`.
- `refusal-classification.mock.ts` — the refusal classifier's verdicts on the gateway's bytes over a real `node:http` socket, on pi-ai's own route.
- `plane-refusals.mock.ts` — the gateway's five typed refusals on a plane turn, through the real `LlmRuntime` and the `PlaneAdapter` on a tier-A host: each finishes as `FREE_TIER` or `MODEL_UNAVAILABLE` with the gateway's words, and its status except on Google-protocol models, whose failure text carries none; a 401 and a plain 429 keep the host's reading. Its request count guards against a duplicate dispatch only: retrying belongs to `dsh-llm-retry`, which tier A does not mount, so whether a refusal is resent is judged by its code being outside the plane's `retryableCodes`.
- `host-drift-cli.mock.ts` — the nightly host-drift report's CLI against a loopback registry, as CI runs it; the rules it prints are `test/host-drift.test.ts`'s, on the registry views in `test/support/host-drift-fixture.ts`. The bump proposal's CLI (`scripts/propose-host-bump.ts`) runs the same way: a data plan, a cut inside the release-age window, a refusing registry, the `--out` files CI's push step reads (with no tracked file touched without `--write`), and, on a scratch copy through `--root`, a `--write` whose pnpm step fails putting every file back. Its rules are `test/host-bump.test.ts`'s.
- `cli-version.mock.ts` — `scripts/check-vendor-version.ts` against a loopback registry through `--registry`: the dist-tags request, a pinned `latest`, a bump, a generation change (`latest` left the pinned major) and a refusing registry.

## The real-host harness

`test/support/host.ts` builds the host from the packages this repository installs: the harness channel `test/support/host-versions.ts` selects (the `@deepseek-ai` cluster at that channel's published tag), with pi unpatched at the newest version the bridge's range admits, or at the range's floor after `scripts/use-channel.ts <channel> --floor`. The routing work is judged against it: the contract tests pin the host facts the design rests on that the host can answer in-process (`docs/improvement-plan.md`: F1, F2, F4, F5, F8, F10–F16, F18 and F20, each by number; F6 and F19's auth half (constructing a `PiAiAdapter`) are first exercised by P-R1; F19's export half is pinned in `host-shapes` (`recordKeyFor`); F17 is honoured, not pinned — tier B fixes the apply order and the binary e2e infers it; F9 is a fact about opencode's own client, outside this host; F21 is pinned by P3 in `host-discovery`, the pi-ai restart and contract cases), and the characterization rows record what today's plugin does.

**Host cells.** The rows are measured on three cells (`HostCell` in `host.ts`): `newest`, either channel's default install (pi 1.5.2 today, one pi for both channels, so one column; a fixture case fails the day the two records disagree), and `rc-floor` and `alpha-floor` (pi 1.3.0 on both, since both bridges declare `^1.3.0`), the pi the desktop app ships. The two floors share one table today (`S0_FLOOR`, `FLOOR_CATALOG`) and stay two cells because CI and the binary e2e install each channel's floor. Where the cells differ, a row carries one expectation per cell (`forHost`, keyed by the cell's role, never by a pi version) or per channel (`forChannel`, for what the `@deepseek-ai` cluster decides: today only the route-level `api` set, below), and every tier file runs on whichever cell is installed. CI runs the unit suite, tiers A and B included, on both channels' `newest` install on every pull request and on both floors nightly and on dispatch; locally, `scripts/use-channel.ts` switches the install and the same run reads the cell from the marker it leaves. The cells differ today in pi's catalog bases (the root `/inference(/go)/v1` on 1.3.0, per-protocol roots on 1.5, whose catalog counts moved again on 1.5.2) and in which S0 ids pi can place (`PI_GAPS_BY_CELL`: 1.5 places both Go gap ids). Every supported pi's Go provider carries Google (F10's pi 1.1.0 row is gone with the rc `0.2.1` floor), and both bridges resolve the same pi-ai defaults (1_000_000 / 128_000, and `maxRequestImages` 50) but not the same route-level `api` set: rc's bridge serves `google-generative-ai` on a route, alpha's refuses it at the schema (`host-shapes`, a `[HOST_LIMITATION]` row on alpha, D26). Since P-R1 none of that moves what the plugin routes: it builds every model's protocol and base from its own catalog and endpoint table, so a characterization row differs by cell only where the host itself decides — pi-ai's defaults for an id no catalog describes (the plugin restates none) and the route-level `api` set.

Two tiers, both in-process:

- **Tier A — `mountTierA`.** A bare cordis `Context`, `LlmRuntime`, and `dsh-llm-pi-ai` mounted as a plugin with `{ providers }` (and optionally this plugin). No loader and no files. Use it for the `internal/config` waterfall and pi-ai's credential paths — anything that needs a fiber and the registry and nothing that reads a profile (`host-waterfall`, `host-shapes`, `host-credentials`). Mounted here (`plugin`), this plugin is the real one: tier A has no loader, so `mountTierA` swaps the plugin's host-module source for `hostModulesForTests` through the seam in `src/cordis-context.ts` (`replaceHostModuleSource`), restores it on dispose, and the route claim serves both planes as it does on the real host (`host-planes`). pi-ai is mounted first there, so the claim restarts it once. Pass `hostModules: null` to keep the plugin's default source instead: with no loader it cannot find pi-ai's module, so the claim stands down and pi-ai keeps the planes (`host-discovery`'s stood-down case). Characterize the plugin as it ships in tier B, which keeps the default source.
- **Tier B — `bootTierB`.** dsh-app-boot's `boot()` with a temporary HOME, a test bundle and a profile patch, the way the harness's own composition tests boot one. Use it for the config editor, `settings.describe`, the loader's volatile commit and the characterization of the plugin as it ships (`host-editor-contracts`, `host-characterization`, `host-discovery`). Its rows carry **package names**, resolved by a stub module loader, not `cordis:` builtins: the plugin's default host-module source finds pi-ai's entry by `options.name === "@deepseek-ai/dsh-llm-pi-ai"` (`piAiEntry` in `src/host/host-modules.ts`), so a builtin-named row would leave the route claim without pi-ai's module. The loader starts rows in parallel, so tier B makes the order explicit: `order: "plugin-first"` (the default, and what the published binary does) or `"pi-ai-first"`. `realm: { label, credentials }` puts pi-ai's row in a `credentials` realm of its own beside a row of `realmCredentialsPlugin` that provides that fake there, the shape another plugin's setup writes (D27, `host-planes-foreign`); the plugin's row stays outside it.

What every case does:

- **Install the recording fetch before mounting** (`vi.stubGlobal("fetch", recordingFetch().fetch)`) and restore it with `vi.unstubAllGlobals()` after disposal: the plugin's fetch patch wraps whatever `fetch` is current when it mounts. The recording fetch answers `opencode.ai` and `models.opencode.ai` with a 401, refuses every other host, and keeps credential headers by length only.
- **Dispose in `afterEach`** (or a `finally`), and boot per case: a key the fetch patch captured is kept per root, so a host shared between cases would carry one case's key into the next one's listing.
- **Credentials come from the fakes, not the environment.** The fakes (`fakeCredentials`, `fakeLaunchEnvironment`) are provided on the root, which is where pi-ai looks first. The plugin reads `OPENCODE_API_KEY`/`OPENCODE_GO_API_KEY` from the environment directly (the fill and the meter's key resolution, both in `src/credentials.ts`), so the suite runs keyless whatever your shell exports: `test/support/offline.ts`, a setup file of the unit and mock configs, unsets both before every file, so tier B always boots keyless there. `bootTierB` also blanks either one that is set for the life of the boot and restores it on dispose; under those two configs it has nothing to do, and it is the second line for a runner without that setup file. A tier-B case never sets them itself. A unit case that tests the declared source does set one, through `vi.stubEnv` or a plain assignment, and undoes it in its file's `afterEach` (`vi.unstubAllEnvs()` or a named `delete`), so the next file starts keyless again (the parity pin's meter contrast is one).
- **Give tier-B cases 30 s**, and wait with a deadline (`waitForPlaneOwner`, 10 s by default, so a plane the plugin never claims fails by name inside the hook's budget), never a fixed sleep: the route claim registers the planes asynchronously, after pi-ai's commit. `piAiRestarts` counts pi-ai's restarts when a case needs to know how many the claim caused.
- **A first row that fails does not hang the boot.** Tier B holds the second of pi-ai and the plugin until the first applies OR its fiber settles in any state, so a row whose config the schema rejects boots with that fiber FAILED (`fiber.await()` rethrows the real error) and the other row applied.

**Tags.** Every characterization row is titled `[BASELINE]` (must survive every phase), `[KNOWN_DEFECT]` (wrong today; a phase fixes it), `[INTENDED_CHANGE]` (right today; a phase changes it on purpose) or `[HOST_LIMITATION]` (something one channel's host, as one install runs it, lacks or breaks, its pi or its own code, that no phase of this plugin fixes: the install is a host cell for an in-process row, or an `e2e-host` cell, `npm` or `floor`, for the binary e2e; the title names the channel, the host and that install, and it is reported upstream, D26). `RowTag` in `test/support/host.ts` holds the one definition of the four. A phase that flips a row names it in its PR body; nothing else may move, except that the `fix:` that flips `AUTO_ENDPOINT_FAMILY` on P-R2's measured evidence (`docs/redirect-planes.md` §13) may move the family part of a `[BASELINE]` wire facet, re-tagging each one it moves and naming it in its PR body. The per-model rows live in `S0_TODAY_BY_CELL` in `host.ts` (`S0_TODAY` is the installed cell's), which the binary e2e reads too, and each model's three facets — model info, the call-config verdict, the wire — carry their own tag there: `host-characterization` generates one test per model and facet titled with that tag, in each apply order (`todayRowsFor` answers the cell's rows for either order), so the tags in `S0_TODAY` are what govern which entries a phase may flip. Since P-R1 the plugin places, describes and routes every declared id itself, so every cell takes its channel's table (`s0PluginFor`), and the two channels' tables differ only in pi-ai's own defaults for the catalog-unknown id (`PI_AI_DEFAULTS`); `forHost`/`forChannel` pick any other per-cell or per-channel expectation outside the table (such as `PI_GAPS`). P-T1b pinned the one facet that depended on the apply order (Go Gemini's call config, on the floors) with its own `[KNOWN_DEFECT]` case outside the booted blocks; P-R1 flipped that row, dropped `todayRowsFor`'s pi-ai-first override and turned the case into the `[BASELINE]` "no facet depends on the apply order" check, on every cell, in the same diff. The fixture is S0 plus one declared id no catalog knows (`CHARACTERIZED_PROFILE`); the contract tests keep plain S0.

**A catalog refresh can touch the rows.** The rows' context windows and effort lists are copied from the generated `src/catalog-data.ts`, which the nightly refresh rewrites. A fixture-sanity case derives each row's context window and effort ids the way the plane adapter does (D17: the profile row's `contextWindow`, else the catalog; the efforts from `reasoningFor`), holds every cell's table to the same derivation, and names the model that moved; when it fails on a refresh pull request, update the row in `s0PluginFor` in `host.ts`, the table every cell shares. A phase that moves an `info` facet off that derivation on purpose adds that row's key to the case's `INFO_NOT_FROM_CATALOG` set in the same diff; the case refuses to exempt a `BASELINE` facet, and since P-R1 the set is empty. The `e2e-host` job's scope includes `test/support/host.ts`, so the binary e2e runs on that pull request too and checks the edited row against the published binary.

**The apply order is a race on the real host.** Tier B fixes it; the published binary does not. Since P-R1 the rows no longer depend on it — the route claim answers the same in both orders, which the characterization asserts by running both — so `todayRowsFor` answers `S0_TODAY.rows` for either order, and the probe waits until both planes are owned by the plugin's `PlaneAdapter` (`planesSettled`) before it measures.

### The `e2e-host` job

`.github/workflows/ci.yml`'s `e2e-host` job installs each channel's published `@deepseek-ai/dsh` (its record's `dsh`) into a throwaway prefix with npm, the way a user installs it, builds this checkout, and runs `test/e2e/host-binary.e2e.ts`. That file creates a temporary HOME whose profile links this checkout and the probe bundle (`test/e2e/host/`) through relative `link:` paths, stores dummy keys in the temporary home's credentials document (`$DSH_HOME/.credentials.yaml`, shared by every profile under that home), boots `dsh --profile e2e --no-open --port 0`, and reads what `test/e2e/host/probe-plugin.mjs` measured. It asserts the rows `S0_TODAY_BY_CELL` records for its cell, which P-R1 flipped to the plugin owning both planes.

- **Cells, per channel, pi unpatched in both.** `npm` is the published host exactly as npm resolves it, cordis and pi included, what an npm user runs, and asserts the `newest` rows while its pi is the channel record's; a pi published since the record still has to sit in the bridge's range, but the per-model rows (a newer pi's own entry can still move a model's metadata where the catalog states none) are skipped with a warning, and the nightly `host-drift` job names the new pi. The listings before and after a turn, the save rows (the catalog-unknown id is accepted on the first try) and the row that the plane provider is built from the host prefix's own pi are asserted in every cell, since the plugin owns both planes there on either host core and none of them depends on which ids pi describes; a `[BASELINE]` row asserts that both planes are the plugin's `PlaneAdapter` whichever `internal/config` call shape the host dispatched (next bullet). `floor` is the tree the desktop app ships: npm `overrides` (`floorOverrides` in `host-versions.ts`) force the channel's whole cordis family (cordis, the loader, the include, group and timer plugins, cosmokit, schemastery) at the record's versions, which are the floors of the `~` ranges the published cluster declares (what the harness vendors at the tag), and pi with its telemetry package at the range's floor; the job and the e2e assert that npm applied each one, and the cell asserts every row of the channel's floor cell. In both cells the e2e also holds each cordis-family field to the floor of the range the installed published package declares for it, which no override rewrites, with one rule for cosmokit: its declarer is cordis, so it is checked only where the installed cordis is the record's, and elsewhere only the nightly drift report checks it (measured 2026-11-12, every cell's installed cordis is its record's, so cosmokit is checked in all four). It is cached by channel, `dsh` and a hash of those overrides, so a cache filled before the record or its overrides moved is never reused; the rest of the tree is what npm resolved when the cache was filled. The installed `dsh` must be the channel record's, so a prefix of the wrong channel fails by name. The save rows skip only where the host itself cannot save (next bullet).
- **Settings' fetch.** The probe also records what Settings → Models → Fetch offers on each plane, through the gateway's Remote face. Every cell asserts the whole servable catalog, each id once, in the Remote's five fields, and the order: the list the prefix's own pi exports (`getBuiltinModels`, read from the prefix, not the checkout) first, then the catalog models that pi lacks. The wrapper complements a fetch only while the route claim has engaged (`RouteClaim.claiming()`), which it does on both host cores, so each row first asserts both planes on the plugin's `PlaneAdapter`. It reads engaged through a handover's window too, while the newly served row's restart is in flight: the fetch is complemented until the row unloads and the plane's catalog alone while it does, as in the mount's restart. Only a served row whose restart has settled still holding a plane (a call shape the claim's listener does not speak) leaves the fetch pi's own list.
- **The host's own failures are recorded, not worked around.** Only the `npm` cell lets cordis float, as the published host's `~` ranges do for a user, and the job reports what it resolved. Where that leaves the host unable to run its own save path, the run records a `[HOST_LIMITATION]` row (titled with the channel and the `dsh`) and skips the save rows. It is detected from what the host answered, never from a version (D26): the plane edit and a control edit no plugin's listener reads (the probe's own entry) both fail with the same `TypeError` thrown by `@deepseek-ai/dsh-app-boot`; where the host saves, the row skips and a `[BASELINE]` row asserts the control was accepted. It was alpha's `0.2.2-alpha.2` as npm installed it: cordis `4.0.6-alpha.2` calls `internal/update` in a new shape while that `dsh-app-boot` registered its listener in the old one, so every config-editor save threw `next is not a function`. `0.2.2-alpha.3` and `0.2.2-rc.2` ship the cordis core their `dsh-app-boot` was written for: measured 2026-11-12, all four cells (both channels, `npm` and `floor`) save the control edit, so the row skips everywhere and the save rows run. The same core hands `internal/config` listeners the fiber and reads the config from `next()`, where the older one bound the fiber as `this` and passed the config; the route claim speaks both (`src/utils/config-run.ts`). The probe records the shape of every dispatch (`configHook`, the first; `configHooks`, a count per shape) with the claim's own fiber predicate, and a `[BASELINE]` row requires one known shape throughout and both planes on the plugin's `PlaneAdapter`. It was a `[KNOWN_DEFECT]` row asserting that pi-ai served both planes on the new core, with the rows that need the claim skipping by name, until the claim spoke that shape.
- **Triggers.** Dispatch and the nightly run take both cells of both channels. A pull request takes the `npm` cell of both channels, and only when it touches the host seam — `src/host/**` (the route claim, the plane adapter, the Settings graft, the discovery patch, the host-module loaders) and the modules whose behaviour depends on the real loader and apply order beside it, `src/lifecycle.ts`, `src/identity.ts` and `src/cordis-context.ts`, and the two that still carry host-level patches outside `src/host/` (`src/request/**`, the global fetch wrapper's stages, whose order the probe reads, installed by `src/host/global-fetch.ts`, and `src/stream-hook.ts`) (every other row producer, such as the pure plane model and profile in `src/utils/`, `src/key-capture.ts`, `src/models-catalog.ts` or `src/config.ts`, is covered on each pull request by the in-process characterization of the same rows, and by the nightly run), `cordis.patch.yml`, `test/e2e/host/**`, `test/e2e/host-binary.e2e.ts`, `test/support/host.ts` (the rows the binary e2e asserts), `test/support/e2e-env.ts` (the reader the binary e2e's gate, prefix and cell come through; its channel is `host-versions.ts`'s `selectedHost`), `test/support/host-versions.ts` (what the job installs), `scripts/host-drift.ts` (the family table the binary e2e asserts against the installed manifests), `.github/workflows/ci.yml`, `.github/actions/` (the composite setup action, which holds the install), `vitest.e2e.config.ts` or `vite.config.ts` (the job's own steps and runner config; `vite.config.ts` also holds the pack config that builds `lib/index.mjs`, the bundle only this job loads into a real host, and the test settings the e2e config inherits) (scoped by a step: a workflow-level path filter would silence every other job; a diff the step cannot compute fails it rather than skipping the job). `package.json` is left out because every dependency bump touches it, so a change to its `test:e2e:host` script alone is exercised only by the nightly run. It needs no secret.

To run it locally, install a channel's host into a prefix outside the checkout, then point the suite at it (placeholder paths; `pnpm` must be on `PATH`). The first line reads the channel's record from `test/support/host-versions.ts`, the same way the CI job does, so the snippet never names a version itself:

```sh
export DSH_CHANNEL=alpha   # or rc
eval "$(node --experimental-strip-types --input-type=module -e "import { CHANNELS } from './test/support/host-versions.ts'; const r = CHANNELS[process.env.DSH_CHANNEL]; console.log('DSH=' + r.dsh)")"
mkdir -p /home/you/dsh-host
printf '{ "private": true }\n' > /home/you/dsh-host/package.json
npm install --prefix /home/you/dsh-host "@deepseek-ai/dsh@$DSH"
pnpm run build
DSH_HOST_E2E=1 DSH_HOST_PREFIX=/home/you/dsh-host pnpm run test:e2e:host --run
```

On macOS the suite's temporary HOME lands under `/tmp`, which is a symlink to `/private/tmp`; the profile's relative `link:` dependencies then resolve through the symlink and miss the checkout, and the run fails at `dsh plugin … install` with "cannot resolve profile bundle". Point `TMPDIR` at a directory under the checkout first, so the HOME and the checkout share one real root:

```sh
mkdir -p node_modules/.e2e-tmp
TMPDIR="$PWD/node_modules/.e2e-tmp" DSH_HOST_E2E=1 DSH_HOST_PREFIX=/home/you/dsh-host pnpm run test:e2e:host --run
```

For the `floor` cell, use a fresh prefix whose `package.json` carries the channel's `floorOverrides` (the cordis family at the record's versions and pi with its telemetry package at the range's floor) as `"overrides"` before the install, written the same way the CI job writes it, and run the suite with `DSH_HOST_PI_CELL=floor`:

```sh
mkdir -p /home/you/dsh-host-floor
node --experimental-strip-types --input-type=module -e "import { CHANNELS, floorOverrides } from './test/support/host-versions.ts'; console.log(JSON.stringify({ private: true, overrides: floorOverrides(CHANNELS[process.env.DSH_CHANNEL]) }))" > /home/you/dsh-host-floor/package.json
```

## Live profile loop

The web profile wires this checkout with `link:`, so builds are picked up like this:

- **Host (`lib/index.mjs`) — restart required.** The base bundle ships `hmr root: []` (config watches only, `**/node_modules` ignored) and the loader caches ESM imports per process, so a linked package is never re-imported after boot. After every `pnpm run build`, restart `dsh web` — otherwise the profile silently keeps running the module from boot time. Symptom of a stale host: the plugin row is active but the settings card shows "This plugin is not loaded, so it cannot be configured." — `dsh-settings` is filtering on the old module's `Config` schema.
- **Client (`lib/client.js`) — refresh suffices.** The client bundle is re-served from disk on every page load; a browser refresh picks it up.
- **Verify after a restart:** the Plugins page shows the **OpenCode Patch** card, and its configure view renders every card field (`CARD_FIELDS` in `src/settings-fields.ts`; the `CONFIG_ONLY_FIELDS` knobs stay off the card by design) and no unavailable line. `node --experimental-strip-types scripts/check.ts` catches a stale `lib/` before you do (`src/` newer than `lib/`).

## Code conventions

- **100% strict TypeScript.** No `any` leaks, no `as` assertions in `src/` — narrow `unknown` with `in`-operator type guards (`isRecord`, `isUnknownArray`, …).
- **Zero errors and zero warnings.** `vite.config.ts`'s lint block sets `denyWarnings`, so a lint warning fails `vp check` and `vp lint`, bare or through a script, and `pnpm run check` and `pnpm run lint` also pass `--deny-warnings`: a warning fails `release:gate` and CI exactly as an error does. `test/toolchain.test.ts` runs the config option and holds the flag's text: it lints a fixture with one warning and requires a bare `vp check`, a bare `vp lint` and each script's own arguments (a script that is not one `vp check` / `vp lint` invocation followed only by flags is named, not run, since `vp` silently drops a stray word such as a trailing `&`) to exit non-zero reporting it, and `scriptsToleratingWarnings` names any script that lints without the flag. No case runs the flag with the option off, so the flag is the second line of defence on paper, not one proven alone. `test/ci-wiring.test.ts` holds that CI's check job and the release's `verify` job run exactly `pnpm run check`, unconditionally and without `continue-on-error`, and that `publish` needs `verify` and has no `if:` of its own. `pnpm run lint:fix` fails too when a warning is left that it cannot fix. The two tiers remain in `vite.config.ts` to say what a finding is (`error` for defects: async safety and throw contracts; `warn` for the rest), not whether it blocks. A toolchain bump (vite-plus, oxlint or the presets adding a `warn`-tier rule) can therefore turn `check` red with no source change, and the bump's pull request fixes what it reports. Fix the cause; if a rule fights a correct pattern (e.g. sync Promise wrappers that preserve `AsyncLocalStorage` context), prefer a targeted `oxlint-disable` comment with justification over weakening the rule globally.
- **Sync-over-async for context propagation.** `withStore` iterators and the `fetch` patch intentionally return promises from non-`async` functions so `als.run()` keeps turn context without an extra tick. Don't "fix" these into `async`.
- **Style:** arrow-function consts (not `function` declarations), dot notation, explicit `=== undefined` checks, `oxfmt` formatting.

## Test conventions

- **Deterministic only.** No `Math.random()`, no fixed `sleep()` waits. Async file assertions poll with a deadline (`waitForFileContent`).
- **No secret fixtures.** A session id a gateway, the mock or a live probe READS is derived at runtime (`openCodeSessionIdFor`) or read from `OPENCODE_SESSION_ID`, never written out; an opaque value a captured `fetch` only echoes, or a deliberately malformed input, may stay literal. An API key is never a fixture. `lib/` and `*.log` stay gitignored.
- **Restore globals.** Tests that touch `globalThis.fetch` or `process.env` must restore them in `afterEach` (`vi.unstubAllGlobals()`, `delete process.env.…`).
- **Offline by construction.** `test/support/offline.ts` refuses every non-loopback request in the unit and mock suites. The catalog's background revalidation used to reach `models.opencode.ai` dozens of times per run, so a networked runner's results could depend on the vendor's live catalog. A case that means to fetch stubs `fetch` itself.
- **No order dependence.** `test/support/reset-process-state.ts` clears the plugin's module-level stores (session spend, the live catalog) after every test. Captured keys are kept per composition root (`captureStoreFor`): a case seeds and reads the store of the context it resolves against, and a fresh `Context` starts empty. A new module-level store gets a reset next to its siblings. `pnpm run test:shuffle` is how to check, and CI runs it.
- **Tests reach `src` through `test/support/src.ts`.** It re-exports, from each defining module, everything a test needs, so a module move or a barrel change edits one file instead of thirty. A new test imports from `./support/src.ts` (`../support/src.ts` under `test/mock` and `test/e2e`); add a missing name there rather than importing a `src` path. The exceptions are `vi.mock("../src/x.ts")` targets (and their `importOriginal<typeof import(…)>` type), which must name the module; fresh-module re-imports after `vi.resetModules()`, whose subject is module identity; the architecture and public-API tests, whose subject is the `src` layout and the barrel; the jsdom (client) tests, which import the defining module directly, because `src.ts` re-exports the host graph (`node:sqlite`, pi, `lifecycle.ts`) and the next rule keeps that out of client tests; and the setup file `test/support/reset-process-state.ts`, which runs before the jsdom tests too. `test/architecture.test.ts` fails on a static or side-effect `src` import anywhere else, on a dynamic `import("../src/…")` in a file that never calls `vi.resetModules()`, and on a jsdom test that value-imports the door. Importing the door loads the whole `src` graph, host and client, so a module that fails to load fails every test that comes through it.
- **Host-only fixtures stay out of shared helpers.** `test/test-helpers.ts` is imported by the jsdom (client) tests, so anything that needs `node:sqlite` or the filesystem belongs in `test/support/`, as `opencode-store-fixture.ts` does. It carries no contexts either.
- **A unit test that means "the plugin, applied" mounts it on a real cordis `Context`.** `test/support/composition.ts`'s `mountPlugin` does what the Loader does — `ctx.plugin({ apply, Config, inject, name }, config)`, the module's own exports and the row's config, which makes the schema resolve the config and the fiber carry the plugin's name — so cordis decides when each part runs, a turn goes through `ctx.waterfall("llm/stream", …)` as `LlmRuntime` sends it, and `disposeMounted()` (in `afterEach`) undoes the plugin's effects through `fiber.dispose()`. A service under test gets `new Context()` with what it reads provided on it (one context per service: a cordis Service registers itself on the context it is built on). The mount passes those exports unchanged, so repeated activations on one root share one cordis runtime, as the Loader's do. The go-discovery and usage-service files serve their loader rows and credentials on `new Context()` too (`test/support/loader-rows.ts`). The one stand-in for the plugin's composition, `degradedHost`, is for a composition a real `Context` cannot be, because a real one registers what it is asked to and always has `plugin`: a `plugin` that registers nothing or throws, with and without `get` (the three unreachable-service diagnostics and a refused mount), a `plugin` whose fiber the case settles (`apply` waiting on the services' reports), and a composition with no `plugin` (with or without `provide`, which is never called). Module-level clause tests keep the object their function reads where a real host cannot be put in the state they need on demand: the route claim's stand-in host (`test/support/route-claim-stand-in.ts`: a LOADING or FAILED pi-ai, a null uid, a refusing registry), with `test/host-planes*.test.ts` covering the claim on the real host, `test/remote-service.test.ts`'s stand-in compositions for `installRemoteService`'s clauses (a `plugin` that throws, answers no fiber or answers a fiber the case settles; no `plugin`; no `effect`), and the `llm` objects the discovery, Settings-graft and reload seams wrap. The client entry's tests (`test/settings-page*.test.tsx`, `test/client-bundle.test.ts`) keep a hand-built settings host: the web runtime has no in-process tier, and the jsdom files must not load the door. `until` and `logLines` live in `test/support/cordis-wait.ts` (re-exported by `host.ts`), so a bare-`Context` unit file loads no host package through them.
- **A test for a fix fails without it.** Before committing a regression test, revert the fix locally and watch it fail.
- **Meaningful coverage.** Every config field in the `SPECS` register (`src/settings-fields.ts`) needs both the on and off path where it has one; every passthrough claim needs a non-OpenCode URL test proving headers are untouched; helper functions exported from the meter's pure modules (`usage-state.ts`, `usage-copy.ts`, `usage-time.ts`) are asserted directly, not re-derived in the test.
- **A component with hooks needs a real mount.** Calling `Component(props)` returns an element and runs none of its state, so a hook-bearing component can have twenty passing cases and still be untested — `usage-pill.tsx` sat at 9% exactly that way, with the poll loop, retry and dismissal all uncovered. `test/usage-pill-mount.test.tsx` is the answer: a `// @vitest-environment jsdom` pragma scoped to that one file, so the rest of the suite keeps the fast node environment and the zero-dependency element-tree style.

### The coverage ratchet

`pnpm run test:coverage` runs the same suite with thresholds from `vite.config.ts`. They are a **ratchet, not a target**: they sit at the level the suite actually reaches, so they fail when coverage DROPS and nothing else. Two rules follow.

- **Raise them when you genuinely add coverage** — a PR that lifts statements by a few points should lift the threshold with it, or the next contributor inherits a gate nobody re-measured.
- **Never set one above the current measurement.** That does not make the suite better; it makes every subsequent PR fail until someone deletes tests.

`src/index.ts` is excluded from the report — it is a pure re-export barrel, and the coverage tools attribute an untaken re-export line to whichever file re-exports it, so leaving it in reports a hole nobody can fill while hiding real ones. Load-bearing modules carry their own per-file floors, so a well-covered average cannot hide one that stopped being exercised: `host/patch-method.ts`, `host/remote.ts`, `host/global-fetch.ts`, the credential rules (`utils/credential-policy.ts`), the fetch patch's stages (`request/claim.ts`, `request/body.ts`, `request/credential.ts`, `request/headers.ts`), the four pure plane modules (`utils/protocols.ts`, `utils/model-metadata.ts`, `utils/plane-model.ts`, `utils/plane-profile.ts`) and `utils/gateway-refusal.ts` at 100%, because each branch is a reload case, a mount outcome, a disposal order, a credential source or strike, a protocol, a precedence, one of pi-ai's checks, a refusal type or a text shape; `host/route-claim.ts`, `host/plane-provider.ts`, `host/describe-graft.ts`, `host/host-modules.ts` and the credential resolver (`credentials.ts`, whose one unreachable guard arrived with the meter's discovery in P10a) just below what they measure; and the three modules that install the plugin's effects on the host, `lifecycle.ts`, `stream-hook.ts` and the fetch patch's composition (`request/patch-fetch.ts`), just below what they measure too, with the branches no composition reaches named beside the floor. `test/architecture.test.ts` fails the build on a floor whose file no longer exists, which would otherwise be a floor on nothing.

## The freshness checks in CI

The `catalog freshness` job runs three checks against what the vendor publishes: `catalog:shim` (the bundled catalog, `src/catalog-data.ts`), `limits:shim` (the Go allowances, `src/go-limits-data.ts`) and `cli:version` (the pinned CLI version in `src/identity.ts`). The vendor moves all three most days, so what a run does with a mismatch depends on whether the change under test could have caused it.

- **A pull request is gated on a check only when its own diff touches that check's inputs.** The inputs are the check's script and every local module it loads, transitively, plus `src/identity.ts` for `cli:version`, which the script reads as data. The edges are the ones Node loads: the source's types are erased by Node's own stripper and the specifiers read by a real lexer, so a whole-statement `import type` loads nothing and is no edge, and an import written in a string or template is not one either; anything else is, so the set reaches further than the generator's own folder: the catalog parser loads `src/config.ts`, so a settings change gates `catalog:shim`. `scripts/freshness-scope.ts` derives the inputs from the sources and answers `gate` or `report` for the diff (`git diff --name-only HEAD^1 HEAD` on the merge ref). Change `src/models-catalog.ts` and forget to regenerate, and the pull request fails; that omission is what the gate exists to catch.
- **One half of `cli:version` gates every pull request.** The script checks two things: that every copy of the CLI version in `src/`, `test/`, `docs/`, `scripts/` and `README.md` agrees with `src/identity.ts`, and that the pin is the published version. The first is offline and skips the two generated tables (they hold the vendor's data, not copies the repository maintains), so only the repository can break it, and `pnpm run cli:version -- --copies` runs on every pull request as a gate. It also refuses any literal in the 2.x User-Agent form, `opencode/<channel>/<version>/<client>`: no constant pins that generation, so a concrete one is a claim nothing checks (write the placeholder; the client-generation table is P7's). The second reads the registry's dist-tags for `opencode-ai`: the pin must be `latest`; a `latest` on another version of the pinned major is a bump, and one that left the major is a generation change, named as such, since the User-Agent format moved with it; the snapshot builds under dist-tags (`0.0.0-<tag>-<stamp>`: the 2.x line's `dev`, `next` and `beta`, and many older 1.x feature branches) are listed as not claimed, with no generation or User-Agent format asserted for any of them. Only the registry comparison is scoped as above, and when it only warns, the warning quotes the script's own `error:` line.
- **Otherwise the check reports.** A stale file is a `::warning::`, the job stays green, and the nightly run regenerates both files and opens the refresh as a pull request of its own. A stale CLI pin is only warned about, by every run including the nightly; bumping it is a human pull request to `src/identity.ts` and its copies, which is then gated, because the pin is an input. Vendor drift is not a regression your pull request introduced, so it is not a reason to fail it.
- **The generated files are never inputs.** A pull request that carries only a refresh reports. One that changes `src/catalog-data.ts` or `src/go-limits-data.ts` without touching what generates it gets a warning naming the file, because those files are never edited by hand.
- **A push to `main` reports.** The nightly run regenerates the two generated files and opens the refresh as a pull request; for the CLI version it warns. A manual dispatch only reports the CLI version. None of these paths gates, for the same reason.
- **One broken source does not hold back the other.** When either generator fails on the nightly run, the failure is annotated where it happens, its file is left as committed, the other file's refresh still goes out, and the run fails at the end. The catalog generator runs first and its file is put back before the limits generator starts, because that generator imports `src/catalog-data.ts`. The refresh branch is rebuilt from `main` and force-pushed every night, so a partial run replaces a refresh pull request left open: an earlier night's change to the failed file is no longer proposed until its generator works again, and the run says so in a warning naming the file. That is deliberate, because an older night's output is never carried into a commit that says it was regenerated. From 2026-11-07 the limits failure stopped both, because the two generators ran in one fail-fast step. A refresh pull request that cannot be opened fails the run too, unless one is already open, which the run asks GitHub rather than assumes; and when nothing changed, the log calls current only the files that regenerated. `test/freshness-scope.test.ts` runs the step itself, in a scratch repository that no inherited `GIT_*` variable can redirect, with each generator failing, both, and neither, and with the pull request's creation failing. The job's checkout keeps no git credential, so the refresh is pushed as the token's owner and its pull request's CI runs without waiting for an approval.
- **The gates fail closed.** Each runs unless the scope step answered `report`, so a lost answer gates every pull request rather than skipping the check.

To see the answer for your branch before CI does:

```sh
git diff --name-only main... \
  | node --experimental-strip-types --disable-warning=ExperimentalWarning scripts/freshness-scope.ts catalog:shim
```

## Release process (maintainers)

1. Use conventional commits (`feat:`, `fix:`) — release-please opens the version-bump + changelog PR automatically; merging it tags and creates the GitHub Release, which fires OIDC publishing to npm and GitHub Packages.
2. Avoid manual releases: release-please anchors on the latest GitHub **Release**, not the latest tag, so a bare tag is invisible to it (`AGENTS.md`, "Releasing"). If one is unavoidable, bump `version` in `package.json`, commit, tag, push the tag, and create the GitHub Release in the same step (`gh release create vX.Y.Z --generate-notes`). Never touch `CHANGELOG.md`: release-please owns it.
3. On every release, after smoke-testing (registry install resolves, plugin loads in the DSH Web profile, and a free-tier Zen call succeeds), check the **Supported: the latest release of both DeepSeek Harness channels** line and the **Support policy** paragraph under "Compatibility & Verification" in both READMEs. Their "today" versions, pi ranges and floors, and the default install named a paragraph below, are copied from the channel records in `test/support/host-versions.ts`, and `test/harness-channel.test.ts` holds them to the records. A channel bump **inside the prerelease tuples the peer ranges already admit** (a new `dsh` cut whose cluster changes no host hook, say) moves version data, and this is its whole set: for `rc`, the rc record (with the dist-tag that carries the build: `next` while the rc line publishes ahead of `latest`) and `channels/rc/pnpm-lock.yaml` (`scripts/use-channel.ts rc --relock`); for `alpha`, the alpha record, `package.json`'s exact `@deepseek-ai/*` pins (the cordis family's among them) and the root lockfile (`pnpm install`); for either, those README sentences in both languages, and `minimumReleaseAgeExclude` lines in `pnpm-workspace.yaml` for the exact versions when the cut is younger than pnpm's one-day release-age window. A pi move is the same data: `pnpm install` and `--relock` keep the pi a lockfile already satisfies, so move it with `pnpm update @earendil-works/pi-ai --no-save` (the root lockfile; `package.json` keeps the union range), then `scripts/use-channel.ts rc --relock`, which carries the root's pi into the rc lockfile, and set each record's `pi` (both records: both lockfiles hold the one pi, so a pi move is every record's or none). The cordis family (cordis, the loader, include, group, timer, cosmokit, schemastery) moves only with `dsh`, to the floors of the `~` ranges the new tag's cluster declares (the drift report prints them; they are what the harness vendors at that tag): a newer family patch inside the same ranges is what the `e2e-host` npm cell already runs and logs, never a record bump. A relock keeps the family at the record's floors, because `package.json` pins every member the install resolves and `pinFor` moves each with the channel (the timer plugin, resolved by nothing here, has no pin). The same update is what leaves one pi when a new bridge raises its floor above the locked one. The F10 characterization (`test/mount-protocols.test.ts`) is keyed by pi line, so a pi inside a line leaves it alone; a pi outside every line is a new major, and a reviewed change. **Data only while the host behaves the same.** A bump stays version data while tiers A and B and the binary e2e stay green on the new install. A pull request runs only the default installs, so a bump that moves `piFloor` or any cordis-family field is green only after a `workflow_dispatch` run on the bump branch, which adds both channels' floor cells to the `test` and `e2e-host` jobs. One that turns them red because the host behaves differently is a reviewed change made in the bump's own pull request and named in its body: a pi whose catalog or bases moved (a model added or dropped, a gap id learned) re-measures the `newest` cell's column of `WHOLE_CATALOG` (`test/host-shapes.test.ts`) and of `PI_GAPS_BY_CELL` (`test/support/host.ts`), and a moved `piFloor` re-measures that floor's columns of the same two; no S0 row follows pi, since the plugin places and routes every declared id itself (D26). A cluster whose bridge defaults moved updates `PI_AI_DEFAULTS` (`test/support/host.ts`), which `test/host-shapes.test.ts` pins against the installed pi-ai and which feeds `s0PluginFor`'s catalog-unknown rows; any other row change goes in `s0PluginFor`, the one table every cell takes its channel's copy of. A host event whose call shape or waterfall order moved is adopted by the plugin's own listener (the route claim's `internal/config` listener in `src/host/route-claim.ts`) and by the tier listeners in `test/support/host.ts`, each detected from what the host dispatches (`test/support/config-shape.ts` decodes the call in the tests), never from a version, and the contract tests re-measure the facts they pin (F8, F12, F14, F20) with one expectation per shape and are never loosened to pass on either shape. The `0.2.2-alpha.3` and `0.2.2-rc.2` bumps were that case: cordis `4.0.6-alpha.2` and `4.1.0` call `internal/config` as `(fiber, next)` with `this` null and `internal/update` as `(resolved, next)`, so the tier listeners decode both shapes, the stand-in fibers in `test/config-shape.test.ts` keep the older one covered, and the route claim speaks the same two shapes (`src/utils/config-run.ts`, with stand-in fibers of both cores in `test/support/route-claim-stand-in.ts` and the new core's call-shape cases in `test/route-claim-listener.test.ts`), which flipped the binary e2e's `[KNOWN_DEFECT]` row to a `[BASELINE]` row. A cut that **opens a new prerelease tuple** (dsh `0.2.3-*`, cordis `4.0.7-*`) is not data: semver admits a prerelease only through a comparator in its own tuple, so it is a reviewed range change that also adds the matching `>=X.Y.Z-0 <next` clause to the `peerDependencies` entry (`test/harness-channel.test.ts` requires every record inside its peer range) and the new line to the README pair's peer-range paragraph. The nightly drift report (`scripts/report-host-drift.ts`, CI's `host-drift` job) is what notices that a channel moved, and the same job proposes the bump (`scripts/propose-host-bump.ts`): it moves exactly this data set (the record, alpha's pins, both lockfiles, the README pair's "today" sentences) on `chore/host-bump` and opens the pull request, whose own CI is the run. It waits a night for a cut younger than pnpm's release-age window rather than adding `minimumReleaseAgeExclude` lines, dispatches ci.yml on the branch for the floor cells when `piFloor` or a cordis-family field moved (with the dispatch's `keyed` input at `none`, so that run spends no key), never edits a measured table (the re-measure above is the reviewed part of that pull request, which its body names), leaves a README value both channels share (unless both records move it to the same value), and any dist-tag wording, for the reviewer, and opens a cut that starts a new prerelease tuple, or sits under a dist-tag `ChannelRecord.distTag` does not admit, as a range change for review rather than as data. A dist-tag never moves alone: it moves with `dsh`, so a tag retired or repointed at the same build is no proposal, as it is no drift. **An open proposal is the reviewer's.** The re-measure, a shared README sentence and a range plan's peer clause are commits made on `chore/host-bump`, and until the pull request merges the record on `main` is still behind, so the nightly plans the same bump every night. It therefore leaves an open proposal with the same target alone: no push, no edit, no dispatch. The target is the marker line the body ends with (`bumpTarget`: every proposed record in full), read from the open pull request's body, not its title, which names only each record's headline value (a pi that moves after a dsh cut was proposed leaves the title as it was). A newer target rebuilds the branch only while every commit on it is the nightly's own, with the bot as both its author and its committer (an amend, a rebase or a fixup squash keeps the bot as author and makes the reviewer the committer, so it counts as the reviewer's), and only this repository's own `chore/host-bump` counts as the proposal, never a fork's pull request from a branch of that name; once a reviewer has committed, the nightly leaves the branch alone and names the newer target in a warning, and the next proposal follows the merge. Since both lockfiles hold one pi, a proposed pi move carries every record: a channel waiting only on its own young cut takes a pi-only move the same night when its recorded pi range admits the pi, and a channel that cannot (a partial read, another pi, a recorded range that stops short, a proposal that keeps the old pi) holds the pi move for every channel (`coupleSharedPi`). The plan is written in a step with no token in its environment (the proposer installs a cut nobody has reviewed yet); a second step, which only commits, pushes and opens or edits the pull request, carries the tokens. Both steps run in one job, so the split holds only because the install runs none of the cut's code: pnpm runs a dependency's build script only when something approves it (in the pinned pnpm, an `allowBuilds` entry, a `build` permission or the allow-all in `pnpm-workspace.yaml`, a `PNPM_CONFIG_*` variable in the step's environment, a CLI flag in the step or in a script it runs, the proposer and the rc relock, or a pnpmfile, whose `updateConfig` hook can set any of those: `.pnpmfile.cjs` or `.pnpmfile.mjs` at the root, or one the workspace's `pnpmfile` or `configDependencies`, `.npmrc` or a `--pnpmfile` flag names), and nothing does, so any build approval is a change to this boundary (`test/host-drift.test.ts` names each of those, and the older spellings pnpm 12 ignores: package.json's `pnpm` field, `.npmrc`, the allow-list and the deny-list).

## Docs

- `README.md` is consumer-facing: problem-first, install, UI config, troubleshooting. No dev internals.
- `CHANGELOG.md` is the per-version record. `AGENTS.md` is the agent-facing project brief — keep it specific to this repo.
