# ACP adapter The CLI presents ACP over stdio as newline JSON-RPC and translates each request into a daemon operation. [`server.go`](../cli/internal/acp/server.go) owns the connection; accepted work belongs to the daemon, so an adapter that exits leaves its turns running. See [sessions](sessions.md) for the actor and stream it observes. The adapter uses Coder’s Go ACP SDK for v1 wire types. The v2 adapter reuses method names and payloads where the draft preserves their shape. Albedo owns stdin dispatch and the output queue so requests retain per-session arrival order and slow editors have bounded buffered output. ## Requests `requestRoutes` in [`server.go`](../cli/internal/acp/server.go) is the whole surface: `initialize`, `authenticate`, `session/list`, `session/new`, `session/resume`, `session/load`, `session/close`, `session/delete`, `session/set_config_option`, `session/prompt`, and the `session/cancel` notification. A route says whether the request runs on a worker and whether requests naming one session keep arrival order; other sessions stay free. An ordered request reserves its session's place on the reader before its worker starts, so two of them cannot overtake each other, and `session/close` and `session/delete` join that order so an in-flight resume cannot outlive them. The v1 adapter pins schema v1.32.0 in [`testdata`](../cli/internal/acp/testdata/acp-schema-v1.32.0.json) and advertises `loadSession` plus the `resume`, `list`, `close`, and `delete` session capabilities, MCP HTTP support, and the `image` and `embeddedContext` prompt capabilities. Audio prompt blocks are unsupported because the shared provider model has no audio input type. ## ACP v2 draft The compatibility kit pins draft schema `2.0.0-alpha.16`. An editor selects v2 with `protocolVersion: 2` in `initialize`. The adapter advertises stdio and HTTP MCP servers, image and embedded context inputs, and session deletion. Editors use `session/resume` to attach to an existing session. Pass `replayFrom: {"type":"start"}` to receive history through the captured cutoff and a `replay_complete` notification. Omit the cursor to receive the current session snapshot without retransmitting history. See [v2 wire handling](../cli/internal/acp/v2.go) and [session attachment](../cli/internal/acp/load.go). A successful `session/prompt` response carries the admitted user message ID. Watch `state_update` for the transition back to idle and the turn's stop reason. Requests received during a turn wait for admission. Cancellation discards waiting requests. Retrying with the same session and `idempotencyKey` returns the original message ID, including after reattachment. The adapter uses the daemon's durable input IDs to recognize those retries. See [prompt admission](../cli/internal/acp/session.go). ## Session lifecycle Requests before a successful `initialize` receive JSON-RPC error `-32600`. An unknown session on prompt, configuration, load, or resume receives `-32002` with the requested `data.sessionId`. Closing or deleting an unknown session succeeds. In v1, an explicit `session/close` cancels the outstanding editor prompt and waits for its response before releasing the attachment. [`state.go`](../cli/internal/acp/state.go) holds one session's lifecycle as a value: an observation phase, one activity slot, one queued activity, and the daemon turn that work belongs to. Its transitions are pure and return effects, which [`session.go`](../cli/internal/acp/session.go) performs. Add a state to that value rather than a flag to `session`. When an idle session loses its stream or lease, its next prompt or configuration request reattaches with the saved workspace and editor MCP servers. The [adapter](../cli/internal/acp/load.go) compares the new attachment's durable history cutoff with the last observed transcript position. Recovery requires an idle capture with no pending ACP input or unfinished output. The replacement stream must deliver its initial batch before the adapter admits the request. The adapter releases a failed replacement lease. Cancellation while a prompt waits for reattachment discards the waiting prompt. The adapter notes on diagnostics when an idle session's stream or lease is lost. A prompt that arrives before the adapter has read the loss is admitted to the old observation, and the loss then fails it as `observation_uncertain`. The adapter cannot tell a dead stream from a quiet one until a read fails, so both outcomes are expected after a daemon restart. A disconnect during a turn or an uncertain write requires an explicit session load or resume. `lost` is terminal: the adapter cannot prove which output the editor already saw, so it refuses further prompts and configuration until the editor resumes. A configuration write marks `preparing` for its duration. `session/load` replays history only after the event stream is accepted. A stream that fails before subscribing, or that never starts within 30 seconds, answers the request instead of leaving it open, and a session that ended up `lost` fails the load rather than replaying into an observation nobody can reconcile. [Stored history](../cli/internal/daemon/history.go) supplies positioned rows to [the loader](../cli/internal/acp/load.go). The loader flushes each bounded piece before moving on and sends buffered live output after the load response. `session/delete` detaches only once the daemon deleted the session, so a refusal leaves the editor's session usable. ## Configuration [`option.go`](../cli/internal/acp/option.go) models each selector once: its ACP id, name, category, choices, the value it writes, and what that value means locally, so the offered choices are also the validation rule. The selectors are `model`, `effort`, `contextWindow`, and `compactionStrategy`. `effort` offers `default` and the model's own levels, and a session with no saved level reads as `default`, so picking it changes nothing; `contextWindow` offers `0` ("Automatic") and a fixed ladder of 50k, 100k, 250k, 500k, 750k and 1M, clipped to the model's usable window. The catalogue's default and maximum are not separate choices, and a window saved outside ACP stays selectable. `compactionStrategy` offers `auto`, which clears the session's choice. Model levels come from the provider catalogue, a session's own values from its account, and an unreadable catalogue is reported on diagnostics instead of silently shortening a selector. [`app/acp.go`](../cli/internal/app/acp.go) owns the backend side. `ACPSettings` is one session's whole configuration, catalogue and selection together; `Catalog` lists what the connection offers before a session exists, `Refresh` adds one session's selection to a catalogue, and `Settings` is both; each write replaces the value wholesale, so no caller merges partial results. ## Output and reconciliation [`update.go`](../cli/internal/acp/update.go) defines every session update the adapter sends, keyed by one `updateKind`. The writer coalesces consecutive agent and thought chunks of one message up to 32 KiB and bounds its queue at 4 MiB. [`reconcile.go`](../cli/internal/acp/reconcile.go) keeps the bounded identity metadata that orders live output against durable replay; reaching its limit marks the session lost instead of dropping the excess. `usage_update` is sent only once the window is known, because ACP requires a non-null size. That window is the session's override or the model's configured window, falling back to its catalogue window. `used` is the latest call's prompt tokens, its total tokens, or the daemon's estimated request size, clamped to the window; cost is `USD`, or `credits` for a counted statement. A compaction becomes one `compaction_update`, `completed` with the summary or `failed` with the error, and only when the client advertised `clientCapabilities.session.compaction`. Its id combines the daemon generation and stream sequence, so a restarted actor does not reuse a boundary, while a replayed row uses its durable entry. A leading skill slash command activates the skill with the remaining prompt as its arguments. Ordinary ACP text supports the same `$name` skill mentions as native chat. Resource link metadata does not trigger mentions. See [skills](skills.md). For compaction, a `/compact` prompt invokes compaction only when it is the entire prompt in one exact text block. A command that arrives during a turn waits for it like a queued prompt. Its 195 s deadline outlasts the daemon's action so the verdict reaches the editor. ## Prompt context [`validation.go`](../cli/internal/acp/validation.go) translates editor block fields to the daemon request. [`http_api.gleam`](../apps/albedo/src/albedo/http/http_api.gleam) checks the request shape, and [`acp.gleam`](../apps/albedo/src/albedo/acp/acp.gleam) renders the model and display text separately. Resource links remain references. The daemon uses an embedded resource's supplied `text` or base64 `blob` as model context, labeled with its URI, optional MIME type, and payload encoding. It does not fetch an embedded resource URI. History displays a resource label without its payload. Only editor text blocks contribute skill mentions. Image blocks use the existing user image input. The daemon checks the declared MIME type against the supplied PNG, JPEG, or WebP and accepts up to ten images per prompt. Provider image limits still apply. A malformed block or invalid image returns a parameter error and leaves the session usable. History displays the image type and optional URI without the base64 data. The submission identity includes the ordered blocks, payloads, and metadata, so an altered payload cannot reuse an accepted input ID. ## Session snapshots In v1, after a successful new, resume, or load response, the adapter sends the session's current title, available commands, and plan. A load replays transcript output first and reads the current snapshots after replay. For live changes, the adapter rereads the resource named by a matching session-stream invalidation. One worker per attachment serializes the reads, coalesces pending invalidations, and sends a replacement only when its visible value changes. If a read fails, the adapter logs the failure and keeps the last value. The local `compact` command is still offered if the first command read fails. See [`resources.go`](../cli/internal/acp/resources.go). - `available_commands_update` contains eligible skill commands. V1 also offers `compact`. A first preparation or catalog reload can add, remove, or change a command. See [skills](skills.md). - `session_info_update` carries the daemon's effective display title, with `null` for no title. Changes can arrive while the session is idle. See [generated titles](sessions.md#generated-titles). - V2 clients and v1 clients advertising `clientCapabilities.plan` receive `plan_update` with an items plan named `checklist`. Other clients receive `plan`. Each contains the retained checklist in creation order. Open items are `pending`, checked items are `completed`, and all entries have `medium` priority. An empty checklist sends an empty entries array. Each update replaces the whole plan. The daemon serves the snapshot through [`GET /sessions/{session_id}/acp-plan`](../docs/openapi.yaml). The [checklist extension](../extensions/checklist/README.md) announces the change after a successful checklist write. ## Ownership and recovery [`acp_attachments.gleam`](../apps/albedo/src/albedo/acp/acp_attachments.gleam) owns writer attachments and overlays in a daemon-lifetime actor. The normal lease is 20 seconds and heartbeat interval is 5 seconds, before test time scaling. Attachments and overlays are not durable across a daemon or attachment actor restart. The actor reads lease deadlines through the clock passed to `start_with_clock`; `start` passes the monotonic clock, and a test passes a fake one to cross a deadline without waiting for it. The session actor checks the attachment token when authorizing ACP cancellation. A missing or lost attachment returns `attachment_lost`. An enabled overlay that must be restored returns `overlay_reattach_required`. A failed reload can return `overlay_installed_reload_failed`. The attachment holder may also compact its own session through the compaction route, set its fast mode, which changes what its turns cost, and move it to another daemon, which takes it from the editor. A client without a token still gets `acp_owned`; a wrong token gets `attachment_lost`. See [`acp_session.gleam`](../apps/albedo/src/albedo/acp/acp_session.gleam). Each change under `/sessions/{session_id}` in [`docs/openapi.yaml`](../docs/openapi.yaml) declares `x-albedo-acp-other-clients`. `refused` means a client that does not hold the attachment gets `acp_owned` or `attachment_lost`; `allowed` comes with an `x-albedo-acp-reason` saying why any client may make the change. The API generator ([`cli/tools/apigen`](../cli/tools/apigen/metadata.go)) rejects a change without a declaration, and the ownership sweep in [`e2e/acp_daemon_test.py`](../e2e/acp_daemon_test.py) sends every `refused` operation to an ACP session without a token and with another connection's token. Declare a new route before adding its guard, and give an `allowed` route the reason a reviewer needs. ## MCP overlays The Go adapter forwards stdio and Streamable HTTP MCP servers on `session/new`, `session/load`, and `session/resume`. V1 skips legacy SSE servers with a diagnostic. V2 rejects them with an invalid-params error. Streamable HTTP can carry SSE responses. On create and reattach, the daemon rejects duplicate editor names, then drops editor servers whose names appear in the installed `McpServersPlugin` settings. The remaining stdio servers need absolute command paths and unique environment variable names. The remaining HTTP servers need case-insensitively unique header names and an endpoint accepted by the MCP extension. The daemon compares, probes, fingerprints, and stores this effective overlay. If all names are configured, the editor overlay is empty. [`http_acp`](../apps/albedo/src/albedo/http/http_acp.gleam) starts candidates with the installed `EditorMcpPlugin`. Both answer while their extensions are disabled. Without an `McpServersPlugin`, no names are reserved. Without an `EditorMcpPlugin`, a non-empty overlay fails with `409 mcp_overlay_failed`. See [plugins](plugins.md#mcp-settings-and-editor-probes). The daemon stores keyed fingerprints of server configuration, while the attachment actor holds the live overlay. For HTTP, the endpoint and literal header values affect the fingerprint. Header order and name casing are immaterial. [`acp_session.publish`](../apps/albedo/src/albedo/acp/acp_session.gleam) publishes at an idle session boundary and restores the previous durable requirement if publication fails. A session that requires an absent overlay must reattach before using it. Overlay contents and credentials are runtime configuration and must be handled accordingly. When an editor restores an overlay after restart, reload compares the tools in the previous prepared composition even if the session has not acquired a Python kernel. This lets the next model request see the restored MCP catalogue. Session preparation reaches the overlay through [`acp_overlay.resolve`](../apps/albedo/src/albedo/acp/acp_overlay.gleam), which the composition binds to `extension.Preparation.editor_overlay`. It reads the ACP marker first and returns `None` for a session without one, so ordinary turns do not load `acp_session`. Its catalogue lookup and save callbacks keep the revision it captured. See [MCP](mcp.md#editor-servers-over-acp). ## Protocol compatibility The [upstream compatibility kit](https://github.com/agentclientprotocol/acp-tck) checks ACP v1 and the v2 draft against the checkout’s stdio adapter. The [compatibility test](../e2e/acp_tck_test.py) runs in the full end-to-end gate with a private daemon and scripted provider. The v2 provider calls the Python tool to write a workspace file so the kit can check tool progress and file changes. Its output gives the path to the JSON report, which includes the verdict and unexercised requirements. Any failed requirement, including an advisory one, fails the gate. To run it on its own after building the CLI: ```sh nix develop -c go -C cli build -o bin/ ./cmd/albedo... nix develop -c python3 e2e/run.py acp_tck_test.py ``` Keep Albedo-specific attachment, overlay, and recovery scenarios in the [adapter integration tests](../e2e/acp_test.py). ## Related pages - [All topics](README.md) - [Change guidance](contributing.md) - [Session attachment](sessions.md) - [MCP extension](mcp.md)