Skip to content

feat(api): wire schemas, HttpApi and --json on every command #71

Closed

Description

@allisonmahmood

Problem

Request/response shapes live implicitly in apps/server/src/app.ts and are re-typed by hand in the CLI and its stubs; only status has --json; there is no API reference. Supersedes #35.

Do

  • New packages/api (@patchy/api), importing only @patchy/core + Effect: one Schema.Class per wire shape; the HttpApi with two groups — auth (tokens, mint, me) and patches — under .prefix("/api"). The wire renames draft → patch here: paths (/api/patches/*) and field names are written with patch naming from the start so agents see one wire break, not two; update the CLI (drafts.json cache keys included), docs/API.md and skills/patchy/SKILL.md in the same PR. Tables and code keep draft until the patches ticket; the bearer HttpApiMiddleware.Service definition with security: { bearer } and the 401 body pinned as today's { ok: false, error: "Missing or invalid API token." } (plain Schema.Struct + HttpApiSchema.status(401), no _tag); the derived HttpApiClient. Shape to copy: packages/effect-slice/src/api.ts on prototype/effect-slice.
  • Error responses carry the same field names and status codes as today for every route (400/401/403/404/409/413/429); the CLI's exit-code ladder later keys off status, not body.
  • Fastify decodes and encodes through these schemas as the interim adapter (Schema.decodeUnknownSync / encodeSync at the route boundary). No handler is rewritten; runPromise is not needed.
  • CLI: --json on every command (auth set, whoami, status, validate, upload; delete if #41 has landed), printing exactly the api shape; success is one stdout document, failure { ok: false, error } on stderr (the kind field arrives with the cli port). status --json's contract test reads its keys from a real run.
  • docs/API.md rendered from OpenApi.fromApi(PatchyApi) by a small local markdown renderer in packages/api/scripts/, pinned by a test that fails on drift.
  • ADR api is the contract package in docs/adr/ (why wire types live beside neither context).
  • Tests: HttpApiTest.groups is not yet usable without handlers — pin schemas with decode/encode round-trip tests and keep the existing route tests green through the adapter.

Done when

One schema per wire shape used by server, CLI and docs; no draft on the wire; every command has --json; the API.md test fails on drift; #35 closed as superseded.

Decisions implemented

Spec §1 (HTTP shape, 401 body), §9 (wire schemas, API.md); #35; vertical slice.


Filed from the Effect v4 port spec (#68) by the map task Write the port spec and file the build tickets.

Activity

  1. added
    ready-for-agent
    area:server
    area:cli
    area:core
    area:docs
    on Aug 28, 2026
  2. added a commit that references this issue on Aug 28, 2026
    4e43ef5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:cliarea:corearea:docsarea:serverready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions