acp

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
const (
	StopEndTurn   = "end_turn"
	StopMaxTokens = "max_tokens"
	StopMaxTurns  = "max_turn_requests"
	StopRefusal   = "refusal"
	StopCancelled = "cancelled"
)

Stop reasons a prompt turn ends with.

View Source
const ProtocolVersion = 1

ProtocolVersion is the ACP version conch speaks.

Variables

View Source
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.

View Source
var ErrClosed = errors.New("the agent's connection closed")

ErrClosed is a call made on, or cut short by, a connection that ended.

View Source
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.

View Source
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

func Main(args []string) error

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.

func Run

func Run(ctx context.Context, o RunOptions) error

Run is `conch acp`: the agent started, a session opened, and the conversation drawn until the person leaves or the agent does.

Types

type AgentCapabilities

type AgentCapabilities struct {
	LoadSession         bool                `json:"loadSession"`
	SessionCapabilities SessionCapabilities `json:"sessionCapabilities"`
}

type AuthMethod

type AuthMethod struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
}

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 Start

func Start(ctx context.Context, o Options) (*Client, error)

Start runs the agent and initializes it.

func (*Client) Cancel

func (c *Client) Cancel(sessionID string) error

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

func (c *Client) LoadSession(ctx context.Context, id string) error

LoadSession reopens a saved conversation; the agent replays it as updates before answering.

func (*Client) NewSession

func (c *Client) NewSession(ctx context.Context) (string, error)

NewSession starts a conversation in the workspace.

func (*Client) Prompt

func (c *Client) Prompt(ctx context.Context, sessionID, text string) (string, error)

Prompt sends one turn and waits for the agent to end it.

func (*Client) Stderr

func (c *Client) Stderr() string

Stderr is the end of what the agent wrote to stderr.

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 EnvVar

type EnvVar struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

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.

func (*Error) Error

func (e *Error) Error() string

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

type ExitError struct {
	What   string // the call it was answering
	Stderr string
}

ExitError is the agent having exited while conch waited on it, with the end of what it wrote to stderr — usually why.

func (*ExitError) Error

func (e *ExitError) Error() string

func (*ExitError) Unwrap

func (e *ExitError) Unwrap() error

type ExitStatus

type ExitStatus struct {
	ExitCode *int    `json:"exitCode"`
	Signal   *string `json:"signal"`
}

type FSCapabilities

type FSCapabilities struct {
	ReadTextFile  bool `json:"readTextFile"`
	WriteTextFile bool `json:"writeTextFile"`
}

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 Info

type Info struct {
	Name    string `json:"name"`
	Title   string `json:"title,omitempty"`
	Version string `json:"version,omitempty"`
}

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 ListSessionsParams struct {
	Cwd    string `json:"cwd,omitempty"`
	Cursor string `json:"cursor,omitempty"`
}

type ListSessionsResult

type ListSessionsResult struct {
	Sessions   []SessionInfo `json:"sessions"`
	NextCursor string        `json:"nextCursor,omitempty"`
}

type LoadSessionParams

type LoadSessionParams struct {
	SessionID  string `json:"sessionId"`
	Cwd        string `json:"cwd"`
	MCPServers []any  `json:"mcpServers"`
}

type NewSessionParams

type NewSessionParams struct {
	Cwd        string `json:"cwd"`
	MCPServers []any  `json:"mcpServers"`
}

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 PermissionOutcome struct {
	Outcome  string `json:"outcome"` // selected, cancelled
	OptionID string `json:"optionId,omitempty"`
}

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 PlanEntry

type PlanEntry struct {
	Content  string `json:"content"`
	Priority string `json:"priority,omitempty"`
	Status   string `json:"status,omitempty"`
}

type ProbeError

type ProbeError struct {
	Err   error
	Noise string
}

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 ReadFileParams struct {
	SessionID string `json:"sessionId"`
	Path      string `json:"path"`
	Line      int    `json:"line,omitempty"`
	Limit     int    `json:"limit,omitempty"`
}

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 SessionInfo struct {
	SessionID string `json:"sessionId"`
	Cwd       string `json:"cwd"`
	Title     string `json:"title,omitempty"`
	UpdatedAt string `json:"updatedAt,omitempty"`
}

type TermCreateParams

type TermCreateParams struct {
	SessionID       string   `json:"sessionId"`
	Command         string   `json:"command"`
	Args            []string `json:"args,omitempty"`
	Env             []EnvVar `json:"env,omitempty"`
	Cwd             string   `json:"cwd,omitempty"`
	OutputByteLimit int      `json:"outputByteLimit,omitempty"`
}

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 TermParams struct {
	SessionID  string `json:"sessionId"`
	TerminalID string `json:"terminalId"`
}

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.

type UpdateParams

type UpdateParams struct {
	SessionID string `json:"sessionId"`
	Update    Update `json:"update"`
}

type WriteFileParams

type WriteFileParams struct {
	SessionID string `json:"sessionId"`
	Path      string `json:"path"`
	Content   string `json:"content"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL