Repository navigation
feat(api): one wire contract for server, CLI and docs, with --json on every command - #82
Conversation
New packages/api (@patchy/api): one Schema.Class per wire shape, the HttpApi
with its auth and patches groups under /api, the bearer middleware definition
with today's 401 body, and the derived HttpApiClient. The wire renames
draft -> patch here (paths, fields, codes, messages); tables and code keep
draft until the patches port.
Fastify decodes bodies and encodes responses through the schemas at the route
boundary (apps/server/src/wire.ts); no handler is rewritten. The CLI decodes
through the same schemas, caches patchId in drafts.json, and takes --json on
every command: one stdout document on success, { ok: false, error } on stderr
on failure.
docs/API.md is rendered from OpenApi.fromApi(PatchyApi) by a small renderer in
packages/api and pinned by a test. ADR-0002 records why the contract lives
beside neither context.
Closes #71.
Co-Authored-By: Claude Fable 5 <[email protected]>
Review follow-up on #71: the body-limit 413 and malformed-JSON 400 left the error handler raw while every route went through @patchy/api; now they use PayloadTooLarge and BadRequest. Also folds the repeated optional-text field schema into one OptionalText. Co-Authored-By: Claude Fable 5 <[email protected]>
Code review (PR 82 × #71)Two-axis review of Intent vs what shipped#71's bet: stop the wire living as implied Fastify JSON with CLI/stub copies. One That bet mostly landed. Agents get Where intent and checklist diverge even though the ticket can still be ticked:
A publishing agent got machine-readable stdout/stderr and a real API reference. It did not get a typed client, a single noun, or MethodSound, with caveats. This is the method #71 asked for, not a lookalike. Defining the full Adapter thickness is right. Caveats on method, not nits: the markdown renderer lives in YAGNIThis is the smallest step that makes the contract unsurprising. Dual sources of truth (HttpApi spec vs Fastify) are the cost of the interim, not extra architecture. What to leave alone: unused What not to grow: the markdown renderer ( The Standards(a) Documented standards
Suppressed (repo wins): no (b) Baseline smells (always judgement)
SpecQuoted against #71. (a) Missing / partial
(b) Scope creep
(c) Looks implemented, looks wrong
Summary: Standards 2 hard + 4 judgement (worst: mint still hand-reads Reviewed by Grok 4.6 in Grok Build. |
Review follow-up on #82: the mint reply decodes through MintedToken instead of reading body.token by hand; a Commander parse error under --json is one stderr document like every other failure; a drafts.json entry still keyed draftId keeps updating its page and is rewritten as patchId; a client still sending draftId gets a 400 naming the rename instead of a silent create; the 401 sentence is pinned in the schema; 414 is declared only on the routes Fastify answers it from, and path ids are plain strings so the reference matches the live 404; client.ts namespace-imports its own module; every wire shape has a round-trip test. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Thanks — worked through the review. Fixed in d43449c:
Left as is, on purpose:
CI green on the first two commits; waiting on the run for d43449c before merge. |
Request and response shapes lived only implicitly in
apps/server/src/app.ts; the CLI and its test stubs re-typed them by hand, onlystatushad--json, and there was no API reference an agent could read before calling a route. Closes #71.Now there is one place the wire is described.
packages/api(@patchy/api) holds oneSchema.Classper wire shape, theHttpApi(authandpatchesgroups under/api), the bearer middleware definition with today's 401 body, and the derived client. Fastify decodes bodies and encodes responses through those schemas at the route boundary (apps/server/src/wire.ts, interim until the router ports); the CLI decodes through the same schemas. The wire renamesdraft → patchhere — paths, fields, codes, messages — so agents see one break, not two; tables, code and CLI text keepdraftuntil thepatchesport. Every CLI command takes--json: one stdout document on success,{ ok: false, error }on stderr on failure.docs/API.mdis rendered fromOpenApi.fromApi(PatchyApi)and pinned by a test that fails on drift; ADR-0002 records why the contract lives beside neither context.Verified with lint, typecheck, the full suite and the packed-CLI e2e against a real server.
Written by Claude Fable 5 in Claude Code.