ACP adapter #
The CLI presents ACP over stdio as newline JSON-RPC and translates each request
into a daemon operation. server.go owns the
connection; accepted work belongs to the daemon, so an adapter that exits leaves
its turns running. See sessions for the actor and stream it
observes.
Requests #
requestRoutes in 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
adapter pins ACP schema v1.32.0 in
testdata 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.
Session lifecycle #
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 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 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.
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.
session/delete detaches only once the daemon deleted the session, so a refusal
leaves the editor's session usable.
Configuration #
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 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 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 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. 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 translates editor block
fields to the daemon request.
http_api.gleam checks the
request shape, and 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 #
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.
available_commands_updatecontains eligible skill commands andcompact. A first preparation or catalog reload can add, remove, or change a command. See skills.session_info_updatecarries the daemon's effective display title, withnullfor no title. Changes can arrive while the session is idle. See generated titles.plancontains the retained checklist in creation order. Open items arepending, checked items arecompleted, and all entries havemediumpriority. An empty checklist sends an empty entries array. Each update replaces the whole plan. The daemon serves the snapshot throughGET /sessions/{session_id}/acp-plan. The checklist extension announces the change after a successful checklist write.
Ownership and recovery #
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 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. A client without a token still gets
acp_owned; a wrong token gets attachment_lost. See
acp_session.gleam.
MCP overlays #
The Go adapter forwards stdio and Streamable HTTP MCP servers on session/new,
session/load, and session/resume. It skips legacy SSE servers with a
diagnostic. 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 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. 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
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, 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.