ADR-0006: One capability list drives the API, the SDK and token scopes
- Status: accepted
- Date: 2026-11-18
- Decided by: Stefan Imhoff
Context
SI-558 asks for one typed SDK that every client uses (browser, CLI, TUI, cron, agents), OpenAPI docs, token scopes including cron, and a test that fails when a client lacks a capability. By then the API had grown to about 100 routes and the SDK had a method for most of them. Nothing kept the two in step. Many settings pages still saved through SvelteKit form actions that called core directly, so the browser could do things no token could. Scopes were a method check in hooks.server.ts (a read token may only GET), with a special case for POST /api/v1/views/resolve.
Decision
packages/sdk/src/capabilities.ts lists every route and method once: the client method that calls it, the scope it needs, its query, body and response schemas, and a summary. Everything else follows from that list:
- Parity tests.
packages/sdk/src/capabilities.spec.tsfails when a capability has no client method or a client method has no capability.apps/web/src/lib/server/capabilities.spec.tsfails when an API route or method is missing from the list, or the list names one the server doesn’t have. - Scopes.
hooks.server.tslooks up the request’s capability and checks its scope. Token scopes are ordered:read<cron<write. Acrontoken may read and start work: fetch a source, rerun an item’s pipeline, group topics, run a taste review. Rerunning and grouping are paid AI calls, still bound by the monthly budget. A fourth scope,session, is for a logged-in browser only. Managing API tokens and the starred feed’s secret issession, so a leaked token can’t mint more tokens. - OpenAPI.
GET /api/v1/openapi.jsonis generated from the list and its zod schemas (openApiDocument()in the SDK). - The browser uses the SDK. Pages change data only through the SDK client (
apiinapps/web/src/lib/stream/stream.svelte.ts), and follow live updates through its event streams. A test fails on a form action outside the login pages, or a directfetch('/api/…')orEventSource.
Exceptions
- Server
loadfunctions keep callingcoredirectly. They only read, run on the server, and aren’t endpoints the browser calls. Every read they do has an API twin. - Login, logout, registration and password reset stay form actions. Better Auth runs them on cookies, and a token client has no use for them.
Rejected alternatives
- Generate the client from the OpenAPI document. It would add a build step and lose the hand-written method names, defaults and doc comments the SDK already has. Listing capabilities next to the schemas keeps one source with no generator.
- Keep form actions and only test that each has an API twin. That checks names, not behavior: an action’s validation and messages drift from its endpoint’s. Calling the API from the page makes the browser a client like any other.
- Scopes per resource (
items:write,sources:read). More than one person’s reader needs. Three ordered scopes and a session-only marker cover the clients M5 plans.
Consequences
- A new endpoint needs a capability entry and a client method, or the tests fail. The entry’s scope is the one place to decide who may call it.
- A route missing from the list needs a
writetoken. The parity test keeps that from happening silently. - Forms that used to work without JavaScript need it now: the settings, Sources, Tags and Stats pages. The app already needed JavaScript for the stream, the reader and most settings.
Notes
- 2026-11-19: Scopes are no longer one line. SI-570 added
subscribefor the browser extension: read,discoverandsubscribe, nothing else, because awritetoken in a browser could also delete.cronandsubscribeeach includereadbut not each other, andwriteincludes both, soscopeAllowsuses a table of what each scope includes instead of a rank. The capability list is still the one place a request’s scope is decided.