small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
albedo docs client-api.md

# Client API ownership The Go `daemon` package owns protocol 3. Application commands and TUI screens call named operations and receive typed results. Generated code constructs routes and queries. The adapter checks responses, bounds decoding, and chooses recovery policy. [OpenAPI](openapi.yaml) defines the wire format; [HTTP API design](http-api-design.md) defines its behavior. ## Request flow Opening a context page follows this flow: 1. The screen calls `GetContextSnapshot` to obtain the latest prepared snapshot. 2. It calls `GetContextPage` with that snapshot ID, section, and page. 3. The adapter validates the response and returns a typed page or an error. 4. A typed UI message carries the result to the screen, which owns selection, rendering, and rejection of outdated replies. Reading context does not prepare a model request. If the snapshot changes, the client obtains the new summary before requesting its pages. ## Code organization Each domain keeps its operations and application-facing types together. `protocol/api.gen.go` contains wire types and HTTP request builders generated from OpenAPI with pinned `oapi-codegen`. Conversion stays inside the adapter. Run `go -C cli generate ./internal/daemon` after editing the contract. `test.sh` checks that generation produces the checked-in file. The generator runs in `cli/tools/apigen`, outside the CLI dependency graph. It projects OpenAPI 3.2 to 3.1 in memory for the generator, selects raw JSON for unions, and preserves nullable field tags for adapter validation. The canonical spec remains authoritative. The adapter owns bounded response reads, semantic validation, authentication recovery, and SSE framing and replay. Session stream parsing is separate from chat operations. Transport, decoding, and receipt recovery are private machinery. Extension-specific result bodies remain explicit `json.RawMessage` values. Local discovery and launching have separate responsibilities. API recovery cannot launch or replace a daemon. The interactive CLI still offers to …