oficina / equipo Public

docs/device-api

Document what a paired device is answered with

Review: Claude Fable 5.2, APPROVED WITH FIXES on 21322855; fixed in ea559855.

Paul ruled on 2026-11-19 that Equipo's API is documented: docs/api/equipo-v1.openapi.json must describe what a paired device is answered with. Until now it described the earlier person API's conversation, which a device bearer never sees on the conversation, task and event routes.

What the document now says

  • Every route a device bearer calls on the conversation engine (chat.HTTP.Mount, housekeeping, usage, and the Assistant's two Oficina connect routes) has an operation: 69 engine operations, each with its request body, each success status and its body, 401, the specific 409 bodies (CardConflict, ActionConflict), and a default Error. Security is personBearer alone, except GET /events, which also takes a same-origin browser session. The person API's own routes for devices (pairing, devices, /me, notifications, errors) are unchanged.
  • Answer schemas mirror internal/wire exactly. A new package, internal/wire/wireschema, generates them from the Go types by reflection, following encoding/json: - a field is required unless omitempty can drop it (a struct value never is) or omitzero; - a pointer, slice or map that is written when nil may be null; - every struct is additionalProperties: false; - each schema carries x-go-type. The generator refuses, rather than guesses at, what it cannot describe: types with their own MarshalJSON or MarshalText, ,string fields, embedded pointer structs, and maps without string keys.
  • Request bodies require nothing. wire.Strict rejects an unknown field but takes a missing one; the handler checks the fields it needs and answers 422 invalid_input. An input type that is also an answer's is named with the suffix Input (BudgetInput, PreferencesInput, QuietHoursInput, ThinkingChoiceInput).
  • Enums come from the wire constants where the set is closed: turn, task, step, question, connection, advice, specialist and housekeeping states, activity kinds, priorities, usage periods, and event types and resources. A field also takes "" where the server sends a zero value: - Message.role and Turn.state, in a card answer that starts no turn; - Runner.role, in a snapshot before a primary runner reports. Fields with scattered or open sets (card kind and state, providers) stay plain strings.
  • The event stream: GET /events documents after, Last-Event-ID, retry: 2000, the 20 second ping, the 24 hour cursor and 410 cursor_expired. Its body is StreamEvent, a oneOf with one schema for each type and resource pair the engine appends (MessageEvent, DeltaTurnEvent, ActivityTurnEvent with label, ActivityStepEvent, ...), plus PingEvent.
  • Error codes: Error.code lists every code the engine writes.

How the shared paths are expressed

OpenAPI allows one operation per path and method. So each shared operation describes what a device gets, says in its description which requests are answered differently, and keeps the earlier answer whole under a vendor extension:

"x-earlierPersonAPI": {"servedWhen": "The id does not start with `tk`.", "operation": { ...the earlier operation... }}

I chose this over two alternatives:

  • oneOf responses would make a generated client decode two unrelated shapes and guess.
  • Dropping the earlier answer would lose a real answer: a browser still gets it, and so does a device asking with an earlier id.

Generators ignore x- fields, so Swift types come from the device's answer only. The prose says plainly that a client generated from the contract does not see the earlier operations.

The rules:

  • By client (deviceClient): GET /tasks, /needs-you, /runners, /connections, /specialists.
  • By id prefix: GET /tasks/{id} and POST /tasks/{id}/cancel (tk), GET /questions/{id} (q_), GET and DELETE /connections/{id} (cn_).
  • Replaced: GET and POST /projects are the engine's alone. Their earlier operation and its orphan ProjectPage schema are removed.

The earlier schemas that shared a name with a wire type take the prefix PersonAPI (PersonAPITask, PersonAPIMe, ...).

Tests

internal/plan3test TestPersonAPIDeviceContract fails if:

  • any generated schema differs from the document;
  • the document's operations don't match what the person API and the engine serve;
  • an operation's bodies don't match wireschema.Ops, or its security is wrong;
  • a shared path's rule disagrees with the router;
  • a captured native fixture fails its operation's schema (no unknown property allowed);
  • the engine writes an error code missing from Error;
  • x-eventTypes differs from the Event types plus ping;
  • any schema is no operation's.

TestPersonAPIDeviceProbes reads a new instance (no runner, task or project) with a device bearer:

  • 29 reads, each answer checked against its schema: /snapshot, /messages, /tasks, /needs-you, /projects, /runners, /connections, /notebook, /thinking, /connections/preference, /specialists, /housekeeping, /housekeeping/actions, /advice, every documented /usage period and grouping, and each documented limit bound;
  • one past each documented limit bound, and an unknown period and by, must each answer 422.

TestPersonAPIContractCoverage runs the person API's checks against the earlier operations kept under x-earlierPersonAPI: request DTO $ref, typed 200, required Idempotency-Key, operation ID.

internal/wire/wireschema tests:

  • TestEnumsAreTheWireConstants: each enum equals its family of wire string constants. Constants that belong to another field are listed, so a new constant fails until it is placed.
  • TestEventDataIsWhatTheEngineAppends: reads every txn.event call in internal/equipo/chat and fails on a type and resource pair with no schema, or a schema nothing appends.
  • TestOpsAreWhatTheHandlersWrite: reads every engine route's handler source (following helpers such as sendWith and serveFile) for its request type and each status and wire type it writes, and compares them with Ops. All 66 non-stream routes resolve.
  • Rules for the generator and validator, refusal of what the generator cannot describe, and input schemas.

What stays unchecked against a live answer: writes and populated reads, which are held by the handler source scan, the generated schemas and the fixtures, and the event data type of each pair.

Mutations, each restored afterwards, every one failing:

  • First round: the document on origin/main; Task.stage typed integer; GET /needs-you answering Task; an invented field in tasks.json; stage missing from task.json; an event state outside the enum; wire.Delta growing a field; the wrong /projects rule; hold_bar missing from Error; an undocumented route; a missing x-earlierPersonAPI; the card answer documented for a browser session; an omitempty struct treated as optional; the validator allowing unknown properties.
  • Review fixes: Runner.role without ""; a new StageParked constant; thinking thinking dropped from, or glance turn added to, EventData; Ops saying GET /turns/{id} answers Task; the cancel handler answering 200; the earlier cancel operation losing its Idempotency-Key; the earlier cancel operation getting another DTO; the earlier GET /tasks left untyped; inputs requiring fields; an orphan schema; step dropped from x-eventTypes; the generator taking ,string, its own MarshalJSON, or an embedded pointer; the limit maximum documented as 250; year added to the usage periods.

To refresh after a wire change, run EQUIPO_DEVICE_SCHEMAS=<file> go test ./internal/wire/wireschema -run TestDump.

Prose

docs/api/equipo-v1.md gains "Talk to your Coordinator from a device", which covers request bodies and the earlier operations. The copy inventory marks it, and the three changed sections, COPY REVIEW REQUIRED.

Server behaviour worth a look (not changed here)

  • GET and POST /projects answer only a device bearer. The engine replaces the person API's handlers, so a browser session gets 401 and the earlier handlers never run.
  • A device can still get the earlier task, question and connection shapes for any id without the engine's prefix. If notifications still carry earlier ids, a device following task_ready gets PersonAPITask.
  • Zero values instead of absence: - a card answer that starts no turn returns a zero message and turn; - a snapshot with no primary runner returns a zero runner (role: "", empty id).
  • UndoAction ignores actionView's error on two conflict paths (out, _ = t.actionView(r)). If that read fails, the 409 body carries a zero action with an empty state, which is not in the enum. I did not add "" for a path that only an error reaches.
  • Many arrays can be null, because they are nil slices without omitempty.
Commits 0
Discussions 0 0 open
Tasks 0/0 done

Discussions

  • No discussions on this branch yet.

Tasks

  • No tasks yet.

Activity

  • No activity yet.