acp

package
v1.3.6 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrCodeParseError     = -32700
	ErrCodeInvalidRequest = -32600
	ErrCodeMethodNotFound = -32601
	ErrCodeInvalidParams  = -32602
	ErrCodeInternalError  = -32603
)

JSON-RPC 2.0 error codes

View Source
const (
	UpdateAgentMessageChunk = "agent_message_chunk"
	UpdateUserMessageChunk  = "user_message_chunk"
	UpdateToolCall          = "tool_call"
	UpdateToolCallUpdate    = "tool_call_update"
	UpdatePlan              = "plan"
)

Session update type constants.

View Source
const ProtocolVersion = 1

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentCapabilities

type AgentCapabilities struct {
	Meta                json.RawMessage      `json:"_meta,omitempty"`
	LoadSession         bool                 `json:"loadSession"`
	PromptCapabilities  *PromptCapabilities  `json:"promptCapabilities,omitempty"`
	MCPCapabilities     *MCPCapabilities     `json:"mcpCapabilities,omitempty"`
	SessionCapabilities *SessionCapabilities `json:"sessionCapabilities,omitempty"`
}

type AgentLoop

type AgentLoop struct {
	// contains filtered or unexported fields
}

AgentLoop runs the headless agent loop for ACP sessions. It reuses ggcode's existing Agent.RunStreamWithContent and converts provider.StreamEvents into ACP session/update notifications.

func NewAgentLoop

func NewAgentLoop(
	cfg *config.Config,
	registry *tool.Registry,
	transport *Transport,
	session *Session,
	clientCaps ClientCapabilities,
	prov provider.Provider,
) *AgentLoop

NewAgentLoop creates a new AgentLoop for the given session. It configures the agent identically to the TUI/daemon path:

  • Project memory (GGCODE.md, AGENTS.md, etc.)
  • Hook config (pre/post tool hooks)
  • Auto compaction (via contextManager)
  • Usage tracking
  • Checkpoint support
  • Vision support

func (*AgentLoop) ExecutePrompt

func (al *AgentLoop) ExecutePrompt(ctx context.Context, prompt []ContentBlock) error

ExecutePrompt runs a single prompt through the agent loop. Stream events are converted to ACP session/update notifications.

func (*AgentLoop) ReadFile

func (al *AgentLoop) ReadFile(ctx context.Context, path string) (string, error)

ReadFile reads a file, using the Client's FS capability if available.

func (*AgentLoop) RequestPermission

func (al *AgentLoop) RequestPermission(ctx context.Context, permType string, toolCall ToolCallUpdate) (bool, error)

RequestPermission sends a permission request to the Client and waits for response.

func (*AgentLoop) RestoreConversation added in v1.1.49

func (al *AgentLoop) RestoreConversation(messages []Message)

RestoreConversation restores previously saved messages into the agent's context. Used by session/resume to rebuild the conversation history.

func (*AgentLoop) SetMode

func (al *AgentLoop) SetMode(mode string)

SetMode updates the permission mode for this agent loop.

func (*AgentLoop) Stop

func (al *AgentLoop) Stop()

Stop cancels the current agent execution.

func (*AgentLoop) WriteFile

func (al *AgentLoop) WriteFile(ctx context.Context, path, content string) error

WriteFile writes a file, using the Client's FS capability if available.

type Annotations added in v1.1.49

type Annotations struct {
	Meta         json.RawMessage `json:"_meta,omitempty"`
	Audience     []string        `json:"audience,omitempty"` // "user", "assistant"
	Priority     float64         `json:"priority,omitempty"`
	LastModified string          `json:"lastModified,omitempty"`
}

Annotations for content blocks.

type AuthEnvVar

type AuthEnvVar struct {
	Meta     json.RawMessage `json:"_meta,omitempty"`
	Name     string          `json:"name"`
	Label    string          `json:"label,omitempty"`
	Secret   *bool           `json:"secret,omitempty"`
	Optional *bool           `json:"optional,omitempty"`
}

type AuthHandler

type AuthHandler struct {
	// contains filtered or unexported fields
}

AuthHandler manages ACP authentication.

func NewAuthHandler

func NewAuthHandler(transport *Transport, sessionID string) *AuthHandler

NewAuthHandler creates a new auth handler.

func (*AuthHandler) HandleAgentAuth

func (ah *AuthHandler) HandleAgentAuth(ctx context.Context) error

HandleAgentAuth performs GitHub Device Flow authentication. It sends the user_code and verification_uri to the Client via session/update notifications, then polls GitHub for the token.

func (*AuthHandler) HandleEnvVarAuth

func (ah *AuthHandler) HandleEnvVarAuth(vars []AuthEnvVar) error

HandleEnvVarAuth validates that required environment variables are set.

type AuthMethod

type AuthMethod struct {
	Meta        json.RawMessage `json:"_meta,omitempty"`
	ID          string          `json:"id"`
	Name        string          `json:"name"`
	Description string          `json:"description,omitempty"`
	Type        string          `json:"type,omitempty"` // "agent" | "env_var" | "terminal"
	Vars        []AuthEnvVar    `json:"vars,omitempty"`
	Link        string          `json:"link,omitempty"`
	Args        []string        `json:"args,omitempty"`
	Env         []EnvVariable   `json:"env,omitempty"`
}

type AuthenticateParams

type AuthenticateParams = AuthenticateRequest

Aliases so handler.go/agent_loop.go compile with minimal changes

type AuthenticateRequest added in v1.1.49

type AuthenticateRequest struct {
	Meta         json.RawMessage `json:"_meta,omitempty"`
	AuthMethodID string          `json:"authMethodId"`
}

AuthenticateRequest for the authenticate method.

type AuthenticateResponse added in v1.1.49

type AuthenticateResponse struct {
	Meta json.RawMessage `json:"_meta,omitempty"`
}

AuthenticateResponse for the authenticate method response.

type AuthenticateResult

type AuthenticateResult = AuthenticateResponse

Aliases so handler.go/agent_loop.go compile with minimal changes

type AvailableCommand added in v1.1.49

type AvailableCommand struct {
	Meta        json.RawMessage `json:"_meta,omitempty"`
	Name        string          `json:"name"`
	Description string          `json:"description,omitempty"`
	Input       interface{}     `json:"input,omitempty"` // AvailableCommandInput
}

AvailableCommand describes a slash command.

type AvailableCommandsUpdate added in v1.1.49

type AvailableCommandsUpdate struct {
	Meta              json.RawMessage    `json:"_meta,omitempty"`
	SessionID         string             `json:"sessionId"`
	AvailableCommands []AvailableCommand `json:"availableCommands"`
}

AvailableCommandsUpdate notifies about slash command changes.

type BlobResourceContents added in v1.1.49

type BlobResourceContents struct {
	Meta     json.RawMessage `json:"_meta,omitempty"`
	URI      string          `json:"uri"`
	Blob     string          `json:"blob"` // base64
	MIMEType string          `json:"mimeType,omitempty"`
}

BlobResourceContents for binary resources.

type CancelNotification added in v1.1.49

type CancelNotification struct {
	Meta      json.RawMessage `json:"_meta,omitempty"`
	SessionID string          `json:"sessionId"`
}

CancelNotification cancels ongoing session work.

type ClientCapabilities

type ClientCapabilities struct {
	Meta     json.RawMessage `json:"_meta,omitempty"`
	FS       *FSCapability   `json:"fs,omitempty"`
	Terminal bool            `json:"terminal,omitempty"`
}

type CloseSessionRequest added in v1.1.49

type CloseSessionRequest struct {
	Meta      json.RawMessage `json:"_meta,omitempty"`
	SessionID string          `json:"sessionId"`
}

CloseSessionRequest closes an active session.

type CloseSessionResponse added in v1.1.49

type CloseSessionResponse struct {
	Meta json.RawMessage `json:"_meta,omitempty"`
}

CloseSessionResponse is the response from closing a session.

type ConfigOptionUpdate added in v1.1.49

type ConfigOptionUpdate struct {
	Meta          json.RawMessage       `json:"_meta,omitempty"`
	SessionID     string                `json:"sessionId"`
	ConfigOptions []SessionConfigOption `json:"configOptions"`
}

ConfigOptionUpdate notifies that config options changed.

type ContentBlock

type ContentBlock struct {
	Type      string            `json:"type"` // "text", "image", "audio", "resource", "resource_link", "tool_use", "tool_result"
	Meta      json.RawMessage   `json:"_meta,omitempty"`
	Text      string            `json:"text,omitempty"`
	ImageURL  string            `json:"imageUrl,omitempty"`
	ImageMIME string            `json:"imageMime,omitempty"`
	ImageData string            `json:"imageData,omitempty"`
	AudioURL  string            `json:"audioUrl,omitempty"`
	AudioMIME string            `json:"audioMime,omitempty"`
	AudioData string            `json:"audioData,omitempty"`
	Resource  *EmbeddedResource `json:"resource,omitempty"`
	URI       string            `json:"uri,omitempty"` // for resource_link
	ToolName  string            `json:"toolName,omitempty"`
	ToolID    string            `json:"toolId,omitempty"`
	Input     json.RawMessage   `json:"input,omitempty"`
	Output    string            `json:"output,omitempty"`
	IsError   bool              `json:"isError,omitempty"`
}

ContentBlock represents displayable information.

type CreateTerminalRequest added in v1.1.49

type CreateTerminalRequest struct {
	Meta    json.RawMessage `json:"_meta,omitempty"`
	Command string          `json:"command"`
	Env     []EnvVariable   `json:"env,omitempty"`
	CWD     string          `json:"cwd,omitempty"`
}

CreateTerminalRequest asks the client to create a terminal and run a command.

type CreateTerminalResponse added in v1.1.49

type CreateTerminalResponse struct {
	Meta       json.RawMessage `json:"_meta,omitempty"`
	TerminalID string          `json:"terminalId"`
}

CreateTerminalResponse returns the terminal ID.

type CurrentModeUpdate added in v1.1.49

type CurrentModeUpdate struct {
	Meta      json.RawMessage `json:"_meta,omitempty"`
	SessionID string          `json:"sessionId"`
	Mode      SessionModeId   `json:"mode"`
}

CurrentModeUpdate notifies that the session mode changed.

type DeviceCodeResponse

type DeviceCodeResponse struct {
	DeviceCode      string `json:"device_code"`
	UserCode        string `json:"user_code"`
	VerificationURI string `json:"verification_uri"`
	ExpiresIn       int    `json:"expires_in"`
	Interval        int    `json:"interval"`
}

DeviceCodeResponse represents GitHub's device code response.

type DeviceTokenResponse

type DeviceTokenResponse struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	Scope       string `json:"scope"`
	Error       string `json:"error,omitempty"`
}

DeviceTokenResponse represents GitHub's token polling response.

type Diff added in v1.1.49

type Diff struct {
	Meta    json.RawMessage `json:"_meta,omitempty"`
	Path    string          `json:"path"`
	OldText string          `json:"oldText,omitempty"`
	NewText string          `json:"newText,omitempty"`
}

Diff represents file modifications.

type EmbeddedResource added in v1.1.49

type EmbeddedResource struct {
	Meta json.RawMessage       `json:"_meta,omitempty"`
	Text *TextResourceContents `json:"text,omitempty"`
	Blob *BlobResourceContents `json:"blob,omitempty"`
}

EmbeddedResource contains resource content that can be embedded.

type EnvVariable

type EnvVariable struct {
	Meta  json.RawMessage `json:"_meta,omitempty"`
	Name  string          `json:"name"`
	Value string          `json:"value"`
}

type ExtNotification added in v1.1.49

type ExtNotification struct {
	Meta   json.RawMessage `json:"_meta,omitempty"`
	Method string          `json:"method"`
	Params json.RawMessage `json:"params,omitempty"`
}

ExtNotification sends a custom notification not in spec.

type ExtRequest added in v1.1.49

type ExtRequest struct {
	Meta   json.RawMessage `json:"_meta,omitempty"`
	ID     RequestID       `json:"id"`
	Method string          `json:"method"`
	Params json.RawMessage `json:"params,omitempty"`
}

ExtRequest sends a custom request not in spec.

type ExtResponse added in v1.1.49

type ExtResponse struct {
	Meta   json.RawMessage `json:"_meta,omitempty"`
	Result interface{}     `json:"result,omitempty"`
}

ExtResponse responds to an ExtRequest.

type FSCapability

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

type FSReadTextFileParams

type FSReadTextFileParams = ReadTextFileRequest

FS operations

type FSReadTextFileResult

type FSReadTextFileResult = ReadTextFileResponse

Aliases so handler.go/agent_loop.go compile with minimal changes

type FSWriteTextFileParams

type FSWriteTextFileParams = WriteTextFileRequest

Aliases so handler.go/agent_loop.go compile with minimal changes

type FSWriteTextFileResult

type FSWriteTextFileResult = WriteTextFileResponse

Aliases so handler.go/agent_loop.go compile with minimal changes

type HTTPHeader

type HTTPHeader struct {
	Meta  json.RawMessage `json:"_meta,omitempty"`
	Name  string          `json:"name"`
	Value string          `json:"value"`
}

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler processes ACP JSON-RPC requests and dispatches to appropriate methods.

func NewHandler

func NewHandler(cfg *config.Config, registry *tool.Registry, transport *Transport, prov provider.Provider) *Handler

NewHandler creates a new ACP handler.

func (*Handler) Run

func (h *Handler) Run(ctx context.Context) error

Run starts the main ACP message loop. It reads messages from the transport and dispatches them to the appropriate handler methods. Supports bi-directional communication: Client requests are dispatched to handlers, and Client responses (to our Agent→Client requests) are delivered to pending callers.

type ImplementationInfo

type ImplementationInfo struct {
	Meta    json.RawMessage `json:"_meta,omitempty"`
	Name    string          `json:"name"`
	Title   string          `json:"title,omitempty"`
	Version string          `json:"version"`
}

type InitializeParams

type InitializeParams = InitializeRequest

Old type names → new canonical names

type InitializeRequest added in v1.1.49

type InitializeRequest struct {
	Meta               json.RawMessage     `json:"_meta,omitempty"`
	ProtocolVersion    int                 `json:"protocolVersion"`
	ClientCapabilities ClientCapabilities  `json:"clientCapabilities"`
	ClientInfo         *ImplementationInfo `json:"clientInfo,omitempty"`
}

InitializeRequest is sent by the client to establish connection.

type InitializeResponse added in v1.1.49

type InitializeResponse struct {
	Meta              json.RawMessage    `json:"_meta,omitempty"`
	ProtocolVersion   int                `json:"protocolVersion"`
	AgentCapabilities AgentCapabilities  `json:"agentCapabilities"`
	AgentInfo         ImplementationInfo `json:"agentInfo"`
	AuthMethods       []AuthMethod       `json:"authMethods"`
}

InitializeResponse is the agent's response to initialize.

type InitializeResult

type InitializeResult = InitializeResponse

Aliases so handler.go/agent_loop.go compile with minimal changes

type JSONRPCError

type JSONRPCError struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

type JSONRPCNotification

type JSONRPCNotification struct {
	JSONRPC string          `json:"jsonrpc"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
}

type JSONRPCRequest

type JSONRPCRequest struct {
	JSONRPC string          `json:"jsonrpc"` // always "2.0"
	ID      RequestID       `json:"id"`      // nil for notifications
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
}

type JSONRPCResponse

type JSONRPCResponse struct {
	JSONRPC   string          `json:"jsonrpc"`
	ID        RequestID       `json:"id"`
	Result    interface{}     `json:"result,omitempty"`
	RawResult json.RawMessage `json:"-"` // populated by ReadAnyMessage for SendRequest
	Error     *JSONRPCError   `json:"error,omitempty"`
}

type KillTerminalRequest added in v1.1.49

type KillTerminalRequest struct {
	Meta       json.RawMessage `json:"_meta,omitempty"`
	TerminalID string          `json:"terminalId"`
}

KillTerminalRequest kills a terminal without releasing it.

type KillTerminalResponse added in v1.1.49

type KillTerminalResponse struct {
	Meta json.RawMessage `json:"_meta,omitempty"`
}

KillTerminalResponse confirms the kill.

type ListSessionsRequest added in v1.1.49

type ListSessionsRequest struct {
	Meta   json.RawMessage `json:"_meta,omitempty"`
	Cursor string          `json:"cursor,omitempty"`
	CWD    string          `json:"cwd,omitempty"`
}

ListSessionsRequest lists existing sessions.

type ListSessionsResponse added in v1.1.49

type ListSessionsResponse struct {
	Meta       json.RawMessage `json:"_meta,omitempty"`
	Sessions   []SessionInfo   `json:"sessions"`
	NextCursor string          `json:"nextCursor,omitempty"`
}

ListSessionsResponse returns session info list.

type LoadSessionRequest added in v1.1.49

type LoadSessionRequest struct {
	Meta      json.RawMessage `json:"_meta,omitempty"`
	SessionID string          `json:"sessionId"`
}

LoadSessionRequest loads a saved session.

type LoadSessionResponse added in v1.1.49

type LoadSessionResponse struct {
	Meta      json.RawMessage `json:"_meta,omitempty"`
	SessionID string          `json:"sessionId"`
	Messages  []Message       `json:"messages"`
}

LoadSessionResponse returns session data.

type MCPCapabilities

type MCPCapabilities struct {
	Meta json.RawMessage `json:"_meta,omitempty"`
	HTTP bool            `json:"http"`
	SSE  bool            `json:"sse"`
}

type MCPManager

type MCPManager struct {
	// contains filtered or unexported fields
}

MCPManager manages dynamically connected MCP servers for ACP sessions. It connects servers, discovers their tools, registers them in the tool registry, and provides cleanup on Close().

func NewMCPManager

func NewMCPManager(registry *tool.Registry) *MCPManager

NewMCPManager creates a new MCP manager.

func (*MCPManager) Close

func (m *MCPManager) Close() error

Close shuts down all connected MCP servers.

func (*MCPManager) ConnectServers

func (m *MCPManager) ConnectServers(ctx context.Context, servers []MCPServer) error

ConnectServers starts and connects the given MCP servers. Each server is initialized, its tools are discovered via tools/list, and registered in the tool registry with "mcp__" prefix.

type MCPServer

type MCPServer struct {
	Meta    json.RawMessage `json:"_meta,omitempty"`
	Name    string          `json:"name"`
	Type    string          `json:"type,omitempty"` // "http", "sse", "stdio" (default)
	Command string          `json:"command,omitempty"`
	Args    []string        `json:"args,omitempty"`
	Env     []EnvVariable   `json:"env,omitempty"`
	URL     string          `json:"url,omitempty"`
	Headers []HTTPHeader    `json:"headers,omitempty"`
}

MCPServer describes how to connect to an MCP server.

type Message

type Message struct {
	Role    string // "user" or "assistant"
	Content []ContentBlock
}

Message represents a single conversation message within a session.

type NewSessionRequest added in v1.1.49

type NewSessionRequest struct {
	Meta       json.RawMessage `json:"_meta,omitempty"`
	CWD        string          `json:"cwd"`
	MCPServers []MCPServer     `json:"mcpServers,omitempty"`
}

NewSessionRequest creates a new conversation session.

type NewSessionResponse added in v1.1.49

type NewSessionResponse struct {
	Meta          json.RawMessage       `json:"_meta,omitempty"`
	SessionID     string                `json:"sessionId"`
	Modes         *SessionModeState     `json:"modes,omitempty"`
	ConfigOptions []SessionConfigOption `json:"configOptions,omitempty"`
}

NewSessionResponse returns session info including available modes and config.

type PermissionOption added in v1.1.49

type PermissionOption struct {
	Meta     json.RawMessage      `json:"_meta,omitempty"`
	OptionID PermissionOptionId   `json:"optionId"`
	Name     string               `json:"name"`
	Kind     PermissionOptionKind `json:"kind,omitempty"`
}

PermissionOption is an option presented to the user.

type PermissionOptionId added in v1.1.49

type PermissionOptionId = string

PermissionOptionId uniquely identifies a permission option.

type PermissionOptionKind added in v1.1.49

type PermissionOptionKind string

PermissionOptionKind categorizes the permission option.

const (
	PermissionOptionAllowOnce    PermissionOptionKind = "allow_once"
	PermissionOptionAllowAlways  PermissionOptionKind = "allow_always"
	PermissionOptionRejectOnce   PermissionOptionKind = "reject_once"
	PermissionOptionRejectAlways PermissionOptionKind = "reject_always"
)

type PermissionRequest

type PermissionRequest = ToolCallUpdate

PermissionRequest is the old name for the tool call being authorized

type PermissionRequestParams

type PermissionRequestParams = RequestPermissionRequest

Permission request/response (old handler code)

type PermissionResponseParams

type PermissionResponseParams = RequestPermissionResponse

Aliases so handler.go/agent_loop.go compile with minimal changes

type Plan added in v1.1.49

type Plan struct {
	Meta    json.RawMessage `json:"_meta,omitempty"`
	Entries []PlanEntry     `json:"entries"`
}

Plan represents an agent's execution plan.

type PlanEntry added in v1.1.49

type PlanEntry struct {
	Meta     json.RawMessage   `json:"_meta,omitempty"`
	Content  string            `json:"content"`
	Priority PlanEntryPriority `json:"priority,omitempty"`
	Status   PlanEntryStatus   `json:"status,omitempty"`
}

PlanEntry is a single task in the execution plan.

type PlanEntryPriority added in v1.1.49

type PlanEntryPriority string
const (
	PlanEntryPriorityHigh   PlanEntryPriority = "high"
	PlanEntryPriorityMedium PlanEntryPriority = "medium"
	PlanEntryPriorityLow    PlanEntryPriority = "low"
)

type PlanEntryStatus added in v1.1.49

type PlanEntryStatus string
const (
	PlanEntryStatusPending    PlanEntryStatus = "pending"
	PlanEntryStatusInProgress PlanEntryStatus = "in_progress"
	PlanEntryStatusCompleted  PlanEntryStatus = "completed"
	PlanEntryStatusFailed     PlanEntryStatus = "failed"
)

type PromptCapabilities

type PromptCapabilities struct {
	Meta            json.RawMessage `json:"_meta,omitempty"`
	Image           bool            `json:"image"`
	Audio           bool            `json:"audio"`
	EmbeddedContext bool            `json:"embeddedContext"`
}

type PromptRequest added in v1.1.49

type PromptRequest struct {
	Meta      json.RawMessage `json:"_meta,omitempty"`
	SessionID string          `json:"sessionId"`
	Prompt    []ContentBlock  `json:"prompt"`
}

PromptRequest sends a user prompt to the agent.

type PromptResponse added in v1.1.49

type PromptResponse struct {
	Meta       json.RawMessage `json:"_meta,omitempty"`
	StopReason StopReason      `json:"stopReason"`
}

PromptResponse contains the stop reason.

type ReadTextFileRequest added in v1.1.49

type ReadTextFileRequest struct {
	Meta json.RawMessage `json:"_meta,omitempty"`
	Path string          `json:"path"`
}

ReadTextFileRequest asks the client to read a file.

type ReadTextFileResponse added in v1.1.49

type ReadTextFileResponse struct {
	Meta    json.RawMessage `json:"_meta,omitempty"`
	Content string          `json:"content"`
}

ReadTextFileResponse returns file contents.

type ReleaseTerminalRequest added in v1.1.49

type ReleaseTerminalRequest struct {
	Meta       json.RawMessage `json:"_meta,omitempty"`
	TerminalID string          `json:"terminalId"`
}

ReleaseTerminalRequest releases terminal resources.

type ReleaseTerminalResponse added in v1.1.49

type ReleaseTerminalResponse struct {
	Meta json.RawMessage `json:"_meta,omitempty"`
}

ReleaseTerminalResponse confirms the release.

type RequestID added in v1.1.49

type RequestID = interface{} // string | int

RequestId is a JSON-RPC request identifier (string or integer).

type RequestPermissionOutcome added in v1.1.49

type RequestPermissionOutcome struct {
	Outcome        string                     `json:"outcome"` // "cancelled", "selected", "rejected"
	SelectedOption *SelectedPermissionOutcome `json:"selectedOption,omitempty"`
}

RequestPermissionOutcome is a discriminated union. We use a struct with an "outcome" discriminator field.

type RequestPermissionRequest added in v1.1.49

type RequestPermissionRequest struct {
	Meta      json.RawMessage    `json:"_meta,omitempty"`
	SessionID string             `json:"sessionId"`
	ToolCall  *ToolCallUpdate    `json:"toolCall,omitempty"`
	Options   []PermissionOption `json:"options"`
}

RequestPermissionRequest asks the client for user authorization.

type RequestPermissionResponse added in v1.1.49

type RequestPermissionResponse struct {
	Meta    json.RawMessage          `json:"_meta,omitempty"`
	Outcome RequestPermissionOutcome `json:"outcome"`
}

RequestPermissionResponse is the client's response to a permission request.

type ResumeSessionRequest added in v1.1.49

type ResumeSessionRequest struct {
	Meta       json.RawMessage `json:"_meta,omitempty"`
	SessionID  string          `json:"sessionId"`
	CWD        string          `json:"cwd,omitempty"`
	MCPServers []MCPServer     `json:"mcpServers,omitempty"`
}

ResumeSessionRequest resumes an existing session.

type ResumeSessionResponse added in v1.1.49

type ResumeSessionResponse struct {
	Meta          json.RawMessage       `json:"_meta,omitempty"`
	Modes         *SessionModeState     `json:"modes,omitempty"`
	ConfigOptions []SessionConfigOption `json:"configOptions,omitempty"`
}

ResumeSessionResponse returns session info after resume.

type SelectedPermissionOutcome added in v1.1.49

type SelectedPermissionOutcome struct {
	Meta     json.RawMessage    `json:"_meta,omitempty"`
	OptionID PermissionOptionId `json:"optionId"`
}

SelectedPermissionOutcome when user selected an option.

type Session

type Session struct {
	ID         string
	CWD        string
	MCPServers []MCPServer
	CreatedAt  time.Time
	Cancel     func()
	// contains filtered or unexported fields
}

Session represents an active ACP session.

func LoadSession

func LoadSession(dir, id string) (*Session, error)

LoadSession loads a session from disk.

func NewSession

func NewSession(cwd string, mcpServers []MCPServer) *Session

NewSession creates a new session with a unique ID.

func (*Session) AddMessage

func (s *Session) AddMessage(role string, content []ContentBlock)

AddMessage appends a message to the session conversation.

func (*Session) DoCancel

func (s *Session) DoCancel()

DoCancel cancels the current operation for this session.

func (*Session) HasMessages added in v1.1.50

func (s *Session) HasMessages() bool

HasMessages returns true if the session has any conversation history.

func (*Session) Messages

func (s *Session) Messages() []Message

Messages returns a copy of the conversation history.

func (*Session) ReplaceConversation added in v1.1.50

func (s *Session) ReplaceConversation(msgs []Message)

ReplaceConversation replaces the entire conversation history. Used after context compaction to store the compressed messages.

func (*Session) Save

func (s *Session) Save(dir string) error

Save persists the session to disk. If the session has no conversation history, the file is deleted (or not created).

func (*Session) SaveDir added in v1.1.49

func (s *Session) SaveDir() string

SaveDir returns the session save directory.

func (*Session) SetCancel

func (s *Session) SetCancel(cancel func())

SetCancel sets the cancellation function for this session.

func (*Session) SetSaveDir added in v1.1.49

func (s *Session) SetSaveDir(dir string)

SetSaveDir sets the directory where session files are persisted.

type SessionCancelParams

type SessionCancelParams = CancelNotification

Aliases so handler.go/agent_loop.go compile with minimal changes

type SessionCapabilities added in v1.1.49

type SessionCapabilities struct {
	Meta   json.RawMessage            `json:"_meta,omitempty"`
	Close  *SessionCloseCapabilities  `json:"close,omitempty"`
	List   *SessionListCapabilities   `json:"list,omitempty"`
	Resume *SessionResumeCapabilities `json:"resume,omitempty"`
}

SessionCapabilities describes which optional session methods the agent supports.

type SessionCloseCapabilities added in v1.1.49

type SessionCloseCapabilities struct {
	Meta json.RawMessage `json:"_meta,omitempty"`
}

type SessionConfigGroupId added in v1.1.49

type SessionConfigGroupId = string

SessionConfigGroupId identifies a group of config values.

type SessionConfigId added in v1.1.49

type SessionConfigId = string

SessionConfigId identifies a configuration option.

type SessionConfigOption added in v1.1.49

type SessionConfigOption struct {
	Meta         json.RawMessage            `json:"_meta,omitempty"`
	Type         string                     `json:"type"` // "select"
	ID           SessionConfigId            `json:"id"`
	Name         string                     `json:"name"`
	Description  string                     `json:"description,omitempty"`
	Category     string                     `json:"category,omitempty"` // "mode", "model", "thought_level", or other string
	CurrentValue SessionConfigValueId       `json:"currentValue"`
	Options      SessionConfigSelectOptions `json:"options"`
}

SessionConfigOption is a session configuration selector. Type discriminator: currently only "select" is defined.

type SessionConfigSelectGroup added in v1.1.49

type SessionConfigSelectGroup struct {
	Meta    json.RawMessage             `json:"_meta,omitempty"`
	ID      SessionConfigGroupId        `json:"id"`
	Name    string                      `json:"name"`
	Options []SessionConfigSelectOption `json:"options"`
}

SessionConfigSelectGroup is a named group of options.

type SessionConfigSelectOption added in v1.1.49

type SessionConfigSelectOption struct {
	Meta    json.RawMessage      `json:"_meta,omitempty"`
	ID      SessionConfigValueId `json:"id"`
	Name    string               `json:"name"`
	GroupID SessionConfigGroupId `json:"groupId,omitempty"`
}

SessionConfigSelectOption is a single selectable value.

type SessionConfigSelectOptions added in v1.1.49

type SessionConfigSelectOptions []interface{} // SessionConfigSelectOption | SessionConfigSelectGroup

SessionConfigSelectOptions is either a flat list or grouped list.

type SessionConfigValueId added in v1.1.49

type SessionConfigValueId = string

SessionConfigValueId identifies a value within a config option.

type SessionData

type SessionData struct {
	ID         string      `json:"id"`
	CWD        string      `json:"cwd"`
	CreatedAt  time.Time   `json:"createdAt"`
	UpdatedAt  time.Time   `json:"updatedAt"`
	Messages   []Message   `json:"messages"`
	MCPServers []MCPServer `json:"mcpServers,omitempty"`
}

SessionData is the JSON-serializable form of a session for persistence.

type SessionInfo added in v1.1.49

type SessionInfo struct {
	Meta      json.RawMessage `json:"_meta,omitempty"`
	SessionID string          `json:"sessionId"`
	CWD       string          `json:"cwd,omitempty"`
	Title     string          `json:"title,omitempty"`
	CreatedAt string          `json:"createdAt,omitempty"`
	UpdatedAt string          `json:"updatedAt,omitempty"`
}

SessionInfo is summary info about a session.

type SessionInfoUpdate added in v1.1.49

type SessionInfoUpdate struct {
	Meta      json.RawMessage `json:"_meta,omitempty"`
	SessionID string          `json:"sessionId"`
	Title     string          `json:"title,omitempty"`
}

SessionInfoUpdate notifies about session metadata changes.

type SessionListCapabilities added in v1.1.49

type SessionListCapabilities struct {
	Meta json.RawMessage `json:"_meta,omitempty"`
}

type SessionLoadParams

type SessionLoadParams = LoadSessionRequest

Aliases so handler.go/agent_loop.go compile with minimal changes

type SessionLoadResult

type SessionLoadResult = LoadSessionResponse

Aliases so handler.go/agent_loop.go compile with minimal changes

type SessionMode added in v1.1.49

type SessionMode struct {
	Meta        json.RawMessage `json:"_meta,omitempty"`
	ID          SessionModeId   `json:"id"`
	Name        string          `json:"name"`
	Description string          `json:"description,omitempty"`
}

SessionMode describes an available operating mode.

type SessionModeId added in v1.1.49

type SessionModeId = string

SessionModeId identifies a session mode.

type SessionModeState added in v1.1.49

type SessionModeState struct {
	Modes   []SessionMode `json:"modes"`
	Current SessionModeId `json:"current"`
}

SessionModeState contains the list of available modes and the active one.

type SessionNewParams

type SessionNewParams = NewSessionRequest

Aliases so handler.go/agent_loop.go compile with minimal changes

type SessionNewResult

type SessionNewResult = NewSessionResponse

Aliases so handler.go/agent_loop.go compile with minimal changes

type SessionNotification added in v1.1.49

type SessionNotification struct {
	Meta      json.RawMessage `json:"_meta,omitempty"`
	SessionID string          `json:"sessionId"`
	Update    SessionUpdate   `json:"update"`
}

SessionNotification is a session/update notification.

type SessionPromptParams

type SessionPromptParams = PromptRequest

Aliases so handler.go/agent_loop.go compile with minimal changes

type SessionPromptResult

type SessionPromptResult = PromptResponse

Aliases so handler.go/agent_loop.go compile with minimal changes

type SessionResumeCapabilities added in v1.1.49

type SessionResumeCapabilities struct {
	Meta json.RawMessage `json:"_meta,omitempty"`
}

type SessionSetModeParams

type SessionSetModeParams = SetSessionModeRequest

Aliases so handler.go/agent_loop.go compile with minimal changes

type SessionSetModeResult

type SessionSetModeResult = SetSessionModeResponse

Aliases so handler.go/agent_loop.go compile with minimal changes

type SessionUpdate

type SessionUpdate struct {
	Type string          `json:"sessionUpdate"` // discriminator: agent_message_chunk, tool_call, tool_call_update, plan, etc.
	Meta json.RawMessage `json:"_meta,omitempty"`

	// Content: polymorphic — single ContentBlock for messages, or []ToolCallContentEntry for tool_call_update.
	// Using interface{} because ACP spec reuses the "content" key for both shapes.
	Content interface{} `json:"content,omitempty"`

	// Tool call fields (tool_call, tool_call_update) — flattened, not nested
	ToolCallID string             `json:"toolCallId,omitempty"`
	Title      string             `json:"title,omitempty"`
	Kind       ToolKind           `json:"kind,omitempty"`
	Status     ToolCallStatus     `json:"status,omitempty"`
	Locations  []ToolCallLocation `json:"locations,omitempty"`
	RawInput   json.RawMessage    `json:"rawInput,omitempty"`
	RawOutput  json.RawMessage    `json:"rawOutput,omitempty"`

	// Plan fields
	Plan *Plan `json:"plan,omitempty"`
}

SessionUpdate is a flattened discriminated union for session/update notifications. Per ACP spec, all fields are direct children of the update object — no nesting.

type SessionUpdateParams

type SessionUpdateParams = SessionNotification

Session update params (old notification wrapper)

type SetSessionConfigOptionRequest added in v1.1.49

type SetSessionConfigOptionRequest struct {
	Meta      json.RawMessage      `json:"_meta,omitempty"`
	SessionID string               `json:"sessionId"`
	ConfigID  SessionConfigId      `json:"configId"`
	Value     SessionConfigValueId `json:"value"`
}

SetSessionConfigOptionRequest sets a config option value.

type SetSessionConfigOptionResponse added in v1.1.49

type SetSessionConfigOptionResponse struct {
	Meta          json.RawMessage       `json:"_meta,omitempty"`
	ConfigOptions []SessionConfigOption `json:"configOptions"`
}

SetSessionConfigOptionResponse returns updated config options.

type SetSessionModeRequest added in v1.1.49

type SetSessionModeRequest struct {
	Meta      json.RawMessage `json:"_meta,omitempty"`
	SessionID string          `json:"sessionId"`
	Mode      SessionModeId   `json:"mode"`
}

SetSessionModeRequest changes the active session mode.

type SetSessionModeResponse added in v1.1.49

type SetSessionModeResponse struct {
	Meta json.RawMessage `json:"_meta,omitempty"`
}

SetSessionModeResponse is the response for set_mode.

type StopReason added in v1.1.49

type StopReason string

StopReason describes why the agent stopped processing.

const (
	StopReasonEndTurn   StopReason = "end_turn"
	StopReasonMaxTokens StopReason = "max_tokens"
	StopReasonMaxTurns  StopReason = "max_turns"
	StopReasonCancelled StopReason = "cancelled"
	StopReasonError     StopReason = "error"
	StopReasonToolUse   StopReason = "tool_use"
)

type TerminalCreateParams

type TerminalCreateParams = CreateTerminalRequest

Terminal (old types kept for compilation)

type TerminalCreateResult

type TerminalCreateResult = CreateTerminalResponse

Aliases so handler.go/agent_loop.go compile with minimal changes

type TerminalExitStatus added in v1.1.49

type TerminalExitStatus struct {
	Meta     json.RawMessage `json:"_meta,omitempty"`
	ExitCode *int            `json:"exitCode,omitempty"`
	Signal   string          `json:"signal,omitempty"`
}

TerminalExitStatus describes how a terminal command exited.

type TerminalOutputParams

type TerminalOutputParams = TerminalOutputRequest

Aliases so handler.go/agent_loop.go compile with minimal changes

type TerminalOutputRequest added in v1.1.49

type TerminalOutputRequest struct {
	Meta       json.RawMessage `json:"_meta,omitempty"`
	TerminalID string          `json:"terminalId"`
}

TerminalOutputRequest asks for current terminal output.

type TerminalOutputResponse added in v1.1.49

type TerminalOutputResponse struct {
	Meta       json.RawMessage     `json:"_meta,omitempty"`
	Output     string              `json:"output"`
	ExitStatus *TerminalExitStatus `json:"exitStatus,omitempty"`
	Truncated  bool                `json:"truncated,omitempty"`
}

TerminalOutputResponse returns terminal output.

type TextResourceContents added in v1.1.49

type TextResourceContents struct {
	Meta json.RawMessage `json:"_meta,omitempty"`
	URI  string          `json:"uri"`
	Text string          `json:"text"`
}

TextResourceContents for text-based resources.

type ToolCallContent added in v1.1.49

type ToolCallContent struct {
	Meta json.RawMessage `json:"_meta,omitempty"`
	// Standard content fields
	Type string `json:"type"` // "text", "image", "diff", "terminal"
	Text string `json:"text,omitempty"`
	// Diff fields
	Diff *Diff `json:"diff,omitempty"`
	// Terminal fields
	TerminalID string `json:"terminalId,omitempty"`
}

ToolCallContent wraps tool call output content (standard content or diff).

type ToolCallContentEntry added in v1.1.49

type ToolCallContentEntry struct {
	Meta    json.RawMessage `json:"_meta,omitempty"`
	Type    string          `json:"type"`              // "content", "diff", "terminal"
	Content *ContentBlock   `json:"content,omitempty"` // for type="content"
	// Diff fields (type="diff")
	Path    string `json:"path,omitempty"`
	OldText string `json:"oldText,omitempty"`
	NewText string `json:"newText,omitempty"`
	// Terminal fields (type="terminal")
	TerminalID string `json:"terminalId,omitempty"`
}

ToolCallContentEntry is a content item within a tool call update.

type ToolCallId added in v1.1.49

type ToolCallId = string

ToolCallId identifies a tool call within a session.

type ToolCallLocation added in v1.1.49

type ToolCallLocation struct {
	Meta json.RawMessage `json:"_meta,omitempty"`
	Path string          `json:"path"`
	Line *int            `json:"line,omitempty"`
}

ToolCallLocation tracks file locations accessed by tools.

type ToolCallStatus added in v1.1.49

type ToolCallStatus string

ToolCallStatus tracks tool call lifecycle.

const (
	ToolCallStatusPending    ToolCallStatus = "pending"
	ToolCallStatusInProgress ToolCallStatus = "in_progress"
	ToolCallStatusCompleted  ToolCallStatus = "completed"
	ToolCallStatusFailed     ToolCallStatus = "failed"
)

type ToolCallUpdate

type ToolCallUpdate struct {
	Meta       json.RawMessage    `json:"_meta,omitempty"`
	ToolCallID ToolCallId         `json:"toolCallId"`
	Title      string             `json:"title,omitempty"`
	Kind       ToolKind           `json:"kind,omitempty"`
	Status     ToolCallStatus     `json:"status,omitempty"`
	Content    *ToolCallContent   `json:"content,omitempty"`
	RawInput   string             `json:"rawInput,omitempty"`
	RawOutput  string             `json:"rawOutput,omitempty"`
	Locations  []ToolCallLocation `json:"locations,omitempty"`
}

ToolCallUpdate reports progress on a tool call.

type ToolKind added in v1.1.49

type ToolKind string

ToolKind categorizes a tool.

const (
	ToolKindRead    ToolKind = "read"
	ToolKindEdit    ToolKind = "edit"
	ToolKindExecute ToolKind = "execute"
	ToolKindSearch  ToolKind = "search"
	ToolKindBrowser ToolKind = "browser"
	ToolKindThink   ToolKind = "think"
	ToolKindOther   ToolKind = "other"
)

type Transport

type Transport struct {
	Scanner *bufio.Scanner
	Writer  io.Writer
	// contains filtered or unexported fields
}

Transport manages JSON-RPC 2.0 communication over stdio. All writes to the writer are protected by a mutex to ensure atomic messages. Supports bi-directional communication: both responding to Client requests and sending Agent→Client requests (e.g. session/request_permission, fs/read_text_file).

func NewTransport

func NewTransport(r io.Reader, w io.Writer) *Transport

NewTransport creates a new Transport reading from r and writing to w.

func (*Transport) CloseWriter

func (t *Transport) CloseWriter() error

CloseWriter closes the underlying writer if it implements io.Closer.

func (*Transport) DeliverResponse

func (t *Transport) DeliverResponse(resp *JSONRPCResponse)

DeliverResponse delivers a response from the Client to a pending SendRequest caller. Called by the Handler's message loop when it receives a JSON-RPC response.

func (*Transport) ReadAnyMessage

func (t *Transport) ReadAnyMessage() (*JSONRPCRequest, *JSONRPCResponse, error)

ReadAnyMessage reads the next JSON-RPC message, which can be either a request (from Client) or a response (to a pending Agent→Client request). Returns (request, nil, nil) for Client requests, (nil, response, nil) for responses to our pending requests, (nil, nil, nil) for empty lines (skip), (nil, nil, io.EOF) when stream ends.

func (*Transport) ReadMessage

func (t *Transport) ReadMessage() (*JSONRPCRequest, error)

ReadMessage reads and parses the next JSON-RPC request from stdin. Returns io.EOF when the input stream is closed.

func (*Transport) ReadRaw

func (t *Transport) ReadRaw() ([]byte, error)

ReadRaw reads the next raw line from the transport. Returns the bytes without parsing. Returns io.EOF when the input stream is closed. This is primarily useful for testing.

func (*Transport) SendRequest

func (t *Transport) SendRequest(method string, params interface{}, timeout time.Duration) (json.RawMessage, error)

SendRequest sends a JSON-RPC request to the Client and waits for the response. This is used for Agent→Client requests like session/request_permission and fs/read_text_file. Returns the raw response result or an error.

func (*Transport) WriteError

func (t *Transport) WriteError(id RequestID, code int, msg string) error

WriteError writes a JSON-RPC error response.

func (*Transport) WriteErrorNilID

func (t *Transport) WriteErrorNilID(code int, msg string) error

WriteErrorNilID writes a JSON-RPC error response with a nil ID.

func (*Transport) WriteNotification

func (t *Transport) WriteNotification(method string, params interface{}) error

WriteNotification writes a JSON-RPC notification (no ID).

func (*Transport) WriteRaw

func (t *Transport) WriteRaw(data []byte) error

WriteRaw writes a raw byte slice to the transport followed by a newline. This is primarily useful for testing — production code should use SendMessage or SendNotification.

func (*Transport) WriteResponse

func (t *Transport) WriteResponse(id RequestID, result interface{}) error

WriteResponse writes a JSON-RPC response with the given result.

type WaitForTerminalExitRequest added in v1.1.49

type WaitForTerminalExitRequest struct {
	Meta       json.RawMessage `json:"_meta,omitempty"`
	TerminalID string          `json:"terminalId"`
}

WaitForTerminalExitRequest waits for terminal command to exit.

type WaitForTerminalExitResponse added in v1.1.49

type WaitForTerminalExitResponse struct {
	Meta       json.RawMessage    `json:"_meta,omitempty"`
	ExitStatus TerminalExitStatus `json:"exitStatus"`
}

WaitForTerminalExitResponse returns the exit status.

type WriteTextFileRequest added in v1.1.49

type WriteTextFileRequest struct {
	Meta    json.RawMessage `json:"_meta,omitempty"`
	Path    string          `json:"path"`
	Content string          `json:"content"`
}

WriteTextFileRequest asks the client to write a file.

type WriteTextFileResponse added in v1.1.49

type WriteTextFileResponse struct {
	Meta json.RawMessage `json:"_meta,omitempty"`
}

WriteTextFileResponse confirms the write.

Jump to

Keyboard shortcuts

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