Documentation
¶
Overview ¶
Package acp is conch's side of the Agent Client Protocol (agentclientprotocol.com): JSON-RPC 2.0 over an agent's stdin and stdout, one message a line. conch is the *client* — the agent asks it to read and write files, run commands and ask the person for permission, and conch asks the agent to start, load and prompt sessions.
It is the third way conch runs an agent, beside the supported nine and the manifests it only runs: an agent that speaks ACP has no terminal interface of its own, so `conch acp` (cmd/conch/acp.go, Run here) runs in the pane as the client, draws the conversation and reports the agent's state over OSC 7501 from the protocol itself — no screen rules.
Index ¶
- Constants
- Variables
- func Main(args []string) error
- func Probe(ctx context.Context, o Options, list bool) (InitializeResult, []SessionInfo, error)
- func Run(ctx context.Context, o RunOptions) error
- type AgentCapabilities
- type AuthMethod
- type CancelParams
- type Client
- func (c *Client) Cancel(sessionID string) error
- func (c *Client) Close()
- func (c *Client) Done() <-chan struct{}
- func (c *Client) ListSessions(ctx context.Context) ([]SessionInfo, error)
- func (c *Client) LoadSession(ctx context.Context, id string) error
- func (c *Client) NewSession(ctx context.Context) (string, error)
- func (c *Client) Prompt(ctx context.Context, sessionID, text string) (string, error)
- func (c *Client) Stderr() string
- type ClientCapabilities
- type ContentBlock
- type EnvVar
- type Error
- type Events
- type ExitError
- type ExitStatus
- type FSCapabilities
- type Handler
- type Info
- type InitializeParams
- type InitializeResult
- type ListSessionsParams
- type ListSessionsResult
- type LoadSessionParams
- type NewSessionParams
- type NewSessionResult
- type Options
- type PermissionOption
- type PermissionOutcome
- type PermissionParams
- type PermissionResult
- type PermissionToolCall
- type PlanEntry
- type ProbeError
- type PromptParams
- type PromptResult
- type ReadFileParams
- type ReadFileResult
- type RunOptions
- type SessionCapabilities
- type SessionInfo
- type TermCreateParams
- type TermCreateResult
- type TermOutputResult
- type TermParams
- type ToolCallContent
- type Update
- type UpdateParams
- type WriteFileParams
Constants ¶
const ( MethodInitialize = "initialize" MethodSessionNew = "session/new" MethodSessionLoad = "session/load" MethodSessionList = "session/list" MethodPrompt = "session/prompt" MethodCancel = "session/cancel" MethodUpdate = "session/update" MethodPermission = "session/request_permission" MethodReadFile = "fs/read_text_file" MethodWriteFile = "fs/write_text_file" MethodTermCreate = "terminal/create" MethodTermOutput = "terminal/output" MethodTermWait = "terminal/wait_for_exit" MethodTermKill = "terminal/kill" MethodTermRelease = "terminal/release" MethodAuthenticate = "authenticate" )
Methods conch calls on the agent.
const ( StopEndTurn = "end_turn" StopMaxTokens = "max_tokens" StopMaxTurns = "max_turn_requests" StopRefusal = "refusal" StopCancelled = "cancelled" )
Stop reasons a prompt turn ends with.
const ProtocolVersion = 1
ProtocolVersion is the ACP version conch speaks.
Variables ¶
var ClientCaps = ClientCapabilities{FS: FSCapabilities{ReadTextFile: true, WriteTextFile: true}, Terminal: true}
ClientCaps is what conch offers an agent: files and terminals, inside the folder it was started in.
var ErrClosed = errors.New("the agent's connection closed")
ErrClosed is a call made on, or cut short by, a connection that ended.
var ErrNoList = errors.New("the agent does not list its sessions (no sessionCapabilities.list)")
ErrNoList is an agent asked for its sessions that cannot say.
var ErrNoLoad = errors.New("the agent cannot reopen a saved session (it does not offer loadSession)")
ErrNoLoad is an agent asked to reopen a session that cannot.
Functions ¶
func Main ¶
Main is `conch acp ARGS`: the client run in an ACP agent's pane, on this process's terminal. It is here rather than in cmd/conch so that a test binary standing in for conch can run it too.
func Probe ¶
func Probe(ctx context.Context, o Options, list bool) (InitializeResult, []SessionInfo, error)
Probe starts the agent, initializes it and, when it lists them, asks for its sessions in o.Dir — what the Sessions view shows for an ACP agent. The agent is ended before Probe returns. o.Events is ignored.
Types ¶
type AgentCapabilities ¶
type AgentCapabilities struct {
LoadSession bool `json:"loadSession"`
SessionCapabilities SessionCapabilities `json:"sessionCapabilities"`
}
type AuthMethod ¶
type CancelParams ¶
type CancelParams struct {
SessionID string `json:"sessionId"`
}
type Client ¶
type Client struct {
// Init is what the agent answered initialize with.
Init InitializeResult
// contains filtered or unexported fields
}
Client is a running agent, spoken to over ACP.
func (*Client) Cancel ¶
Cancel asks the agent to stop the current turn. Permission requests still waiting are answered "cancelled", as are any it asks afterwards in this turn — the protocol's rule, and the only safe answer to a question nobody is there to read.
func (*Client) Close ¶
func (c *Client) Close()
Close ends the agent and every terminal it left running, and returns once it has.
func (*Client) Done ¶
func (c *Client) Done() <-chan struct{}
Done is closed when the agent's output ends — it exited, or closed it.
func (*Client) ListSessions ¶
func (c *Client) ListSessions(ctx context.Context) ([]SessionInfo, error)
ListSessions is the agent's sessions in the workspace.
func (*Client) LoadSession ¶
LoadSession reopens a saved conversation; the agent replays it as updates before answering.
func (*Client) NewSession ¶
NewSession starts a conversation in the workspace.
type ClientCapabilities ¶
type ClientCapabilities struct {
FS FSCapabilities `json:"fs"`
Terminal bool `json:"terminal"`
}
type ContentBlock ¶
type ContentBlock struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
URI string `json:"uri,omitempty"`
Name string `json:"name,omitempty"`
}
ContentBlock is text, or another kind conch shows by its type.
type Error ¶
type Error struct {
Code int `json:"code"`
Message string `json:"message"`
Data json.RawMessage `json:"data,omitempty"`
}
Error is a JSON-RPC error, sent or received.
type Events ¶
type Events interface {
// Update is one session/update.
Update(sessionID string, u Update)
// Permission asks the person, and returns what they chose. ctx ends
// when the turn is cancelled, and the answer is then "cancelled"
// whatever Permission returns.
Permission(ctx context.Context, p PermissionParams) PermissionOutcome
// Problem is something wrong with what the agent sent, worth saying
// but not worth stopping for.
Problem(msg string)
}
Events is what the client tells whoever draws the agent: the updates it streams, the permissions it asks for, and lines conch could not read.
type ExitError ¶
ExitError is the agent having exited while conch waited on it, with the end of what it wrote to stderr — usually why.
type ExitStatus ¶
type FSCapabilities ¶
type Handler ¶
type Handler func(ctx context.Context, method string, params json.RawMessage, notify bool) (any, *Error)
Handler answers what the agent asks or tells: a request (notify false) gets the result or error back; a notification's answer is dropped.
type InitializeParams ¶
type InitializeParams struct {
ProtocolVersion int `json:"protocolVersion"`
ClientCapabilities ClientCapabilities `json:"clientCapabilities"`
ClientInfo *Info `json:"clientInfo,omitempty"`
}
type InitializeResult ¶
type InitializeResult struct {
ProtocolVersion int `json:"protocolVersion"`
AgentCapabilities AgentCapabilities `json:"agentCapabilities"`
AgentInfo *Info `json:"agentInfo,omitempty"`
AuthMethods []AuthMethod `json:"authMethods,omitempty"`
}
func (InitializeResult) CanList ¶
func (r InitializeResult) CanList() bool
CanList is whether the agent lists its sessions (session/list).
type ListSessionsParams ¶
type ListSessionsResult ¶
type ListSessionsResult struct {
Sessions []SessionInfo `json:"sessions"`
NextCursor string `json:"nextCursor,omitempty"`
}
type LoadSessionParams ¶
type NewSessionParams ¶
type NewSessionResult ¶
type NewSessionResult struct {
SessionID string `json:"sessionId"`
}
type Options ¶
type Options struct {
// Argv is the command that speaks ACP on its stdin and stdout.
Argv []string
Env []string // the whole environment; nil is this process's
// Dir is the folder the agent works in, and the one its file and
// terminal requests are kept to.
Dir string
Events Events
// InitTimeout bounds initialize; 0 is a minute (an agent written in
// node can take a while to load).
InitTimeout time.Duration
}
Options start an agent.
type PermissionOption ¶
type PermissionOption struct {
OptionID string `json:"optionId"`
Name string `json:"name"`
Kind string `json:"kind"` // allow_once, allow_always, reject_once, reject_always
}
PermissionOption is one answer to a permission request.
type PermissionOutcome ¶
type PermissionParams ¶
type PermissionParams struct {
SessionID string `json:"sessionId"`
ToolCall PermissionToolCall `json:"toolCall"`
Options []PermissionOption `json:"options"`
}
type PermissionResult ¶
type PermissionResult struct {
Outcome PermissionOutcome `json:"outcome"`
}
type PermissionToolCall ¶
type PermissionToolCall struct {
ToolCallID string `json:"toolCallId"`
Title *string `json:"title,omitempty"`
Kind string `json:"kind,omitempty"`
Content []ToolCallContent `json:"content,omitempty"`
}
type ProbeError ¶
ProbeError is a probe that never got as far as an answer to initialize: Noise is the first line it wrote that was not ACP, if any.
func (*ProbeError) Error ¶
func (e *ProbeError) Error() string
func (*ProbeError) Unwrap ¶
func (e *ProbeError) Unwrap() error
type PromptParams ¶
type PromptParams struct {
SessionID string `json:"sessionId"`
Prompt []ContentBlock `json:"prompt"`
}
type PromptResult ¶
type PromptResult struct {
StopReason string `json:"stopReason"`
}
type ReadFileParams ¶
type ReadFileResult ¶
type ReadFileResult struct {
Content string `json:"content"`
}
type RunOptions ¶
type RunOptions struct {
// Agent is the agent's name in conch (its manifest), said in its
// status reports; Label the name people know it by.
Agent, Label string
Argv []string
Env []string
Dir string
// Prompt is a first message; Load a saved session to reopen.
Prompt, Load string
In io.Reader
Out io.Writer
// Width is the terminal's width now, for redrawing the prompt line;
// nil is 80.
Width func() int
}
RunOptions are what `conch acp` was started with.
type SessionCapabilities ¶
type SessionCapabilities struct {
// List is an object when the agent can list its sessions; absent,
// it cannot — loadSession alone reopens an id somebody already has.
List *json.RawMessage `json:"list,omitempty"`
}
type SessionInfo ¶
type TermCreateParams ¶
type TermCreateResult ¶
type TermCreateResult struct {
TerminalID string `json:"terminalId"`
}
type TermOutputResult ¶
type TermOutputResult struct {
Output string `json:"output"`
Truncated bool `json:"truncated"`
ExitStatus *ExitStatus `json:"exitStatus,omitempty"`
}
type TermParams ¶
type ToolCallContent ¶
type ToolCallContent struct {
Type string `json:"type"`
Content *ContentBlock `json:"content,omitempty"`
Path string `json:"path,omitempty"`
OldText *string `json:"oldText,omitempty"`
NewText string `json:"newText,omitempty"`
TerminalID string `json:"terminalId,omitempty"`
}
ToolCallContent is what a tool call shows: content, a diff or a terminal.
type Update ¶
type Update struct {
SessionUpdate string `json:"sessionUpdate"`
Content json.RawMessage `json:"content,omitempty"` // a block, or a tool call's list
ToolCallID string `json:"toolCallId,omitempty"`
Title *string `json:"title,omitempty"`
Kind string `json:"kind,omitempty"`
Status string `json:"status,omitempty"`
Entries []PlanEntry `json:"entries,omitempty"`
Locations []json.RawMessage `json:"locations,omitempty"`
}
Update is one session/update's update: SessionUpdate says which kind, and the fields that kind uses are set.