Skip to content

Latest commit

 

History

History
300 lines (230 loc) · 20.3 KB

acp.md

File metadata and controls

300 lines (230 loc) · 20.3 KB

Editor integration

Two ways in, both spawned by the editor over stdio: ACP drives whole runs, and agent6 mcp serve exposes a few tools to another agent (see As an MCP server).

Agent Client Protocol

agent6 acp runs agent6 as an Agent Client Protocol agent: an editor spawns it, sends prompts, and renders the run as it happens. It uses the same engine, config, and jail as agent6 run.

// Zed: settings.json
{
  "agent_servers": {
    "agent6": { "type": "custom", "command": "agent6", "args": ["acp"] }
  }
}

Protocol versions

agent6 serves ACP v1 and v2, one version per connection.

  • initialize selects the highest version agent6 serves that is at most the protocolVersion the editor requests: 1 selects v1, 2 or more selects v2
  • a request for 0 answers -32022 with data.supported: [1, 2]
  • an editor that sends no initialize is served as v1
  • v2 is the protocol's Preview; agent6 follows its schema-v2.0.0-beta.3

The sections below describe v1. What v2 changes lists each difference.

What the editor sees

Every run writes one event journal; the CLI, TUI, web UI, and ACP all render it the same way. An editor sees what agent6 attach shows: reasoning, each tool call and its outcome, auto-commits, and how the run ended.

ACP v1 carries a tool call as two messages.

  • tool_call (in_progress) when the run dispatches it, tool_call_update (completed or failed, with the output) when its result lands
  • a call names its tool (name) beside the call's title; built-in calls carry their ACP kind, and an edit result carries each written or deleted path as an absolute follow-along location, without a line
  • a call waiting on an approval or an ask_user answer is updated to pending while its prompt is open, and back to in_progress once answered
  • a long verify shows as in progress while it runs; a call the run never returned from settles as failed when the run's session.stop is written, or when the tail ends without one (a worker killed mid-call)
  • toolCallId is <run id>:<execution id>:<call>, unique for the life of the session; the dispatcher numbers each execution's calls from 1

An edit shows as a diff.

  • the tool_call_update of a successful apply_edit or apply_patch carries its text summary, then one diff entry per file: the absolute path, oldText and newText
  • a created file has oldText: null; a deleted file has newText: "", and the summary says deleted
  • both texts are recorded when the tool writes, so two edits to one file in a turn each show their own diff, and session/load replays the diffs the live run showed
  • the budget is 64 KiB of UTF-8 per call, both sides of all its files together. A call over it carries no diff, and its summary ends (diff omitted for size); a side is never cut to fit.
  • a preview, a failed call, a command and an MCP tool carry no diff
  • after sessions prune removed a run's stored texts, a replayed edit carries its summary and diff unavailable: its stored text is gone

Worker text and thinking arrive as they stream; output from side calls stays out of the conversation.

Inspect persisted line-origin evidence with /findings, agent6 sessions findings <id> or the web Findings card.

Four more updates ride the journal.

  • session_info_update: the task's headline as the session title, the line agent6 sessions list shows
  • available_commands_update: the slash commands the editor can offer for this run's mode. The front end handles finding actions without sending their text to the model. abort, exit and detach are task text over ACP, not terminal commands. The editor cancels through session/cancel.
  • usage_update after each model call: the last call's whole prompt over the model's context window (the ctx N% rule), and the run's cumulative USD when it spent any and every call was priced (a plan-metered run carries none); nothing while the window is unknown
  • plan: the run's task list, in the depth-first order every other surface shows it. Each change of the task graph sends the complete list, an empty one included; so does the run's end, which clears the focus, and session/load replays them.
    • the content is the task's title, and every entry is medium priority
    • a pending task reads pending; a task in progress, or the one the worker is on, reads in_progress; a passed task reads completed
    • a failed task reads pending with (failed) after its title, since ACP has no failed status
    • skipped and obsolete tasks are left out

Images in a prompt

initialize answers promptCapabilities.image: a session/prompt may carry image blocks.

  • the block's inline data is read; its uri is never opened
  • the images go with the task a first prompt starts, or with the instruction a later prompt resumes the run with, after the prompt's text
  • the limits and the refusals are the ones every image has; a refused image answers the request with a JSON-RPC error that names it
  • a prompt that is a directive (/review, /parallel) takes no image
  • a request line may be 4 MiB plus the base64 of 4 MiB

Parallel work

/parallel [SPEC --] TASK starts child attempts on the same terms as a run. Repeat /parallel in the prompt to start another task. A first prompt can dispatch these tasks without a parent model call. The model can dispatch work only when [harness.parallel].tool is on.

Child steps appear as labelled messages in the parent conversation while the children run. The parent relays a child's approval request with the child id in the title. The children run in their own clones under the run's budget and sandbox settings. They get no editor filesystem, terminal or connection.

Review findings

Findings and dispositions appear as [agent6] transcript notices, not native review threads. Commands act on the conversation's recorded run. An answer to a queued question reaches the run at its next turn. An ended run receives the answer on its next prompt, which resumes it.

Use /fix with --resume to confirm Resume to fix when the session is idle. --all selects every open finding without a queued Fix. Fix uses the stored reports and leaves the findings open. It refuses a missing resume point rather than starting a new run.

Live disposition actions use the worker's IPC queue; their notices arrive when recorded. Fix does not support mid-run steering through ACP.

Receipts

The advertised /receipt command reads testing, review and reversal evidence without calling the worker or rerunning checks. Ask for a reversal in a subsequent prompt or a new isolated run; displayed git commands are explanations, not executable actions.

Code-review rule sources

See Code-review rules for discovery and limits.

Approvals

session/request_permission carries every approval the CLI would prompt for.

  • a command under run_commands = "ask"
  • an MCP tool call the server's approve does not cover
  • a fetch to a host outside the allow-list
  • an unsandboxed autorun
  • a new run on another run's branch

The editor renders the buttons; the request names the tool call it gates and carries the prompt as that call's title. A prompt that gates no call (a pre-run question) announces a tool call of its own and closes it with the answer. The prompt and its answer go through the same gate every front-end answers through, so agent6 attach and the web show the run as waiting; the answer journals source: "acp", "frontend" when another surface answered it, or "headless" when the client cannot answer it.

  • an unanswered request denies after five minutes, and the run continues without it
  • a command or an MCP tool call offers the four answers every front-end shares: "allow" (allow_once) and "deny" (reject_once) answer the one call, "allow all" (allow_always) grants that scope's later calls for the session, "deny all" (reject_always) withdraws the scope's tools for the session
  • an off-list fetch host is offered as allow_once only, so an editor's "always allow" cannot cover a different host later
  • a standing "allow all", from the editor or an earlier front-end, answers that scope's later prompts without asking the editor (source: "session")

Sessions

A session is one conversation in one directory.

  • session/new carries an absolute cwd, a git repository, whose own layered config applies Each execution uses that directory without changing the connection process's cwd.
  • the first prompt starts an agent6 run; every later prompt resumes it with the text as its steering instruction (an execution that died before its first checkpoint leaves nothing to resume: the next prompt starts a new run, and the editor is told) After an undo on another surface, the next prompt follows the run's continuation.
  • under v1 a busy session refuses a prompt rather than queueing it; under v2 the prompt steers the run
  • one connection runs one prompt at a time across its sessions, and a prompt on another session queues and says for which session it waits
  • session/list (cwd optional, absolute) names the repository's resumable runs, newest first: agent6's run id as sessionId, the task as title, the last activity as updatedAt; one page, no cursor. A run agent6 resume would refuse (a child, a run whose worktree is gone, a run with no checkpoint) is left out. Without cwd it covers every repository the connection has a session open in.
  • session/resume opens a conversation on a recorded run by that id, so an editor reopens its thread after a restart. session/resume refuses a plan, an ask, a run whose worker is alive, or a run agent6 resume would refuse. It also refuses a run this connection has open for another directory or with a prompt in flight.
  • session/load opens the recorded run like session/resume, replays its journal as ordered session/update notifications, then returns.
  • session/prompt answers end_turn when the run finishes, a red gate included, and max_turn_requests at the turn cap. A run that fails or never starts answers with a JSON-RPC error (-32603, or -32602 for a prompt agent6 refuses); the reason arrives first as a message.
  • session/close ends a conversation; a prompt in flight is cancelled first and answers cancelled.
  • session/cancel cuts a model call in flight and ends a running foreground command at once, without waiting for or signalling the worker (the ACP server itself). The prompt answers cancelled (ACP's word) and the run's record reads stopped, as every operator stop does; what it had not yet committed stays in the tree for the next prompt, which resumes it. A prompt still queued answers cancelled at once. Cancellation releases an open permission wait without waiting for the client's reply. A late permission reply is ignored and cannot grant permission to a later prompt.

Model and effort

session/new, session/load and session/resume answer with configOptions: two selects an editor shows as pickers.

  • model (category model): the routes the configured providers offer, the list every other front-end's picker offers. Its current value is the route the next prompt runs: the picked one, else the one the run recorded, else the config's.
  • effort (category thought_level): inherit, which takes the config's effort, then off, low, medium, high, xhigh and max
  • session/set_config_option picks a value for that session alone and answers with the complete list. The pick applies from the next prompt, a prompt that resumes the run included. It changes no running turn and writes no config file.
  • a set is refused while a prompt runs on the session, and for an id or a value the session does not offer; the error says which
  • config_option_update carries the complete list when agent6 changes it: a run cached a provider's listing, or recorded another route
  • there is no mode option and no modes: an ACP session only opens runs
  • a session with no route to run offers no option: its config does not load or names no model, and no run is recorded. The first prompt says why it cannot run.
  • a run another front-end detaches to the background keeps the picked model and takes the config's effort

What v2 changes

An editor that requests protocolVersion: 2 gets the same runs through v2's messages.

The prompt turn

  • session/prompt answers {messageId} once the prompt's message is in the conversation, not when the run ends. A first prompt is in once its run has recorded it as the task. A later prompt is in once the resumed run has queued it as its steer.
  • a user_message update carries the same messageId and the prompt's text
  • state_update reports the session: running as work starts, requires_action while a permission request is open, idle as work ends
  • the idle that ends the work carries its stopReason: end_turn, max_turn_requests, cancelled or error
  • a run that fails after its message is in ends with stopReason: "error" and the JSON-RPC error object in error. A prompt that fails before that answers the request with the error.
  • a command agent6 answers itself (/receipt, /findings, /answer, /resolve, /reopen) is a turn of its own: its message, running, its answer, idle with end_turn. Answered during a run, it reports no state.

A prompt during a run

  • a prompt that arrives while the session runs joins the run's steer queue, as a message typed during a run does on every other surface
  • it answers {messageId} once it is queued, and the run takes it at its next turn boundary
  • if the run ends or is cancelled first, the steer waits in the queue: the next execution delivers the waiting steers in order before its own prompt reaches the model
  • a steer the run handles as a directive (/pin, /parallel, a skill) is reported when it is sent, and a replay does not repeat it as a user message
  • abort, exit, detach and /undo travel as task text; a composer command (/compact) or a malformed directive answers -32602
  • a prompt that arrives before the execution has chosen its run answers -32603; send it again

Retrying a prompt

  • a prompt may carry an idempotencyKey of 1 to 255 characters; anything else answers -32602
  • the message's id is derived from the session and the key, and the run's journal keeps that id with the message; the key itself is not stored
  • a prompt whose key names a message the conversation holds answers that messageId and adds nothing, after a restart too
  • a retry that arrives before the first request is answered shares its answer
  • a prompt that answered an error left no message, so its key can be sent again
  • the key of a command agent6 answered itself is known until the connection ends

Updates

  • every message carries a messageId. A message from the journal is named by its row, and a prompt's message by the id its reply carried, so a replay names both as the live run did. The model's streamed text and thinking are chunks of one message per model call; every other message arrives whole.
  • a tool call is created by its first tool_call_update, which carries its title, name and kind; there is no tool_call
  • a call waiting on an approval or an answer reads paused, and a call the operator's stop cut short reads cancelled
  • an edit's diff is one entry: changes names each file's operation (add, delete, modify) and absolute path, and patch holds a git_patch of them all. The patch gives an added or deleted file mode 100644, since the stored change holds its text alone.
  • the task list is a plan_update with planId: "tasks"
  • usage_update carries cost: null when the run has no priced total
  • each command and each command input carries its type

Sessions and requests

  • session/new and session/resume answer with availableCommands beside configOptions; an option's key is configId
  • session/resume takes replayFrom: {"type": "start"} to replay the conversation, then sends replay_complete. Every resume sends the session's state_update before its reply. There is no session/load.
  • session/set_config_option needs type: "id"
  • session/request_permission carries the prompt as title and names the gated call as its subject; a prompt that gates no call has no subject. A request nobody waits on any more is cancelled with $/cancel_request.
  • session/close replies after the cancelled work's last update, and closing a session that is not open succeeds
  • session/cancel ends with idle and stopReason: "cancelled"; a prompt cancelled before its message is in answers -32800
  • an unknown session answers -32002 with data.sessionId
  • a request with a null id, and an initialize after another request, answer -32600
  • a prompt block that is not text, resource_link or image answers -32602
  • capabilities.session.prompt.image advertises image blocks; no MCP transport is advertised

Not implemented

  • session/delete: the operator removes a run's record (agent6 sessions remove).
  • Mid-run steering under v1: v1 has no message for a prompt while the previous prompt is running.
  • fs/* and terminal/* (v1): ACP lets the client own the filesystem and the terminal, and agent6 keeps both behind the jail the operator configured.
  • Free-text answers to a waiting ask_user question: the editor gets option buttons only, so a waiting question without options is unanswered and not queued (see the frontend cases); /answer takes any text.
  • Embedded resources in a prompt: text, resource_link and image blocks are read (a link rides in as its uri; the workspace boundary still decides what it reaches)
    • v1 drops an embedded resource, as promptCapabilities.embeddedContext says; v2 refuses the prompt
  • MCP servers and additional directories from the editor: agent6 takes both from its own config, and a session that carries either is refused.

v2 parts agent6 does not send or serve:

  • notice, compaction_update, compaction_summary_chunk, terminal_update, terminal_output_chunk, subagent_update, session_message, session_message_chunk and the background list: agent6's own lines are [agent6] agent messages, and child steps are labelled messages in the parent conversation
  • tool_call_content_chunk: a tool call's content arrives whole in a tool_call_update
  • plan_removed: the task list is the only plan, and it stays
  • tool_call/cancel, terminal/cancel, elicitation/create, elicitation/complete, auth/login, auth/logout and systemPrompt

v2 rules agent6 does not meet:

  • a request before initialize is served as v1 instead of answering -32600
  • session/resume of a session with a prompt in flight on the same connection is refused instead of synchronized
  • a resume sends no session_info_update

Troubleshooting

  • stdout is the protocol stream: nothing but JSON-RPC
  • everything agent6 would print goes to stderr (the editor's agent logs)
  • a wrapper echoing to stdout before exec'ing agent6 breaks the connection irrecoverably; write to stderr

As an MCP server

agent6 mcp serve speaks MCP over stdio, so another agent (an editor's own, or a second agent6 with [mcp.servers]) can use agent6's jail and run state. The cwd's config decides everything: the sandbox the commands run in, and which tools exist at all.

Five tools, of which a default config publishes two:

Tool Withheld when
get_task_graph (a run's task graph) never
list_sessions (this repository's sessions) never
run_verify_command (the configured gate, jailed) no [harness.verify] command, or [sandbox] run_commands is not allow
run_in_sandbox (an argv, jailed) [sandbox] run_commands is not allow
apply_patch_in_sandbox (a patch, then the gate) either of the two above

run_commands = "ask" withholds the command tools: the MCP boundary has no operator to prompt.

// Zed: settings.json -- agent6's jail as another agent's tool surface
{
  "context_servers": {
    "agent6": { "command": "agent6", "args": ["mcp", "serve"] }
  }
}

The tools reach the repository the server was started in, under that repository's sandbox policy; list_sessions and get_task_graph read its state dir and nothing else.