acp

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package acp provides types and utilities for working with the Agent Client Protocol.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ACPAgent added in v0.7.0

type ACPAgent interface {
	acpsdk.Agent // Embeds the SDK's Agent interface

	// GetVersion returns the agent version
	GetVersion() string

	// GetCapabilities returns the agent capabilities
	GetCapabilities() acpsdk.AgentCapabilities
}

ACPAgent is the interface that ACP agents must implement. This allows the HTTP transport to work with different agent implementations.

type ACPAgentConfig

type ACPAgentConfig struct {
	// Name is the unique identifier for this agent configuration
	Name string `json:"name" yaml:"name"`

	// Title is a human-readable name for the agent
	Title string `json:"title" yaml:"title"`

	// Command is the binary to execute (e.g., "claude-code", "zed-acp")
	Command string `json:"command" yaml:"command"`

	// Args are the command-line arguments to pass to the agent
	Args []string `json:"args" yaml:"args"`

	// Env is a map of environment variables to set for the agent
	Env map[string]string `json:"env" yaml:"env"`

	// WorkDir is the default working directory for spawned tasks
	WorkDir string `json:"work_dir" yaml:"work_dir"`

	// Mode is the default operation mode: "code", "ask", or "architect"
	Mode string `json:"mode" yaml:"mode"`

	// McpServers is a list of MCP servers to pass to the agent
	McpServers []McpServerConfig `json:"mcp_servers" yaml:"mcp_servers"`
}

ACPAgentConfig represents the configuration of an ACP agent in config.yaml.

type ACPCapabilities

type ACPCapabilities struct {
	Terminals   bool
	FileAccess  bool
	Permissions bool
}

ACPCapabilities defines what an ACP agent is allowed to do.

type ACPClientCallbacks added in v0.7.0

ACPClientCallbacks defines the interface for calling back to the client.

type ACPClientConnection added in v0.7.0

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

ACPClientConnection wraps a client connection and provides methods to call back to the client for file operations and terminal execution. This is the INVERSE of MesnadaACPClient - it's used by Pando when acting as an ACP server to call methods on the connected client.

func NewACPClientConnection added in v0.7.0

func NewACPClientConnection(sessionID acpsdk.SessionId, conn ACPClientCallbacks, workDir string, logFile *os.File) *ACPClientConnection

NewACPClientConnection creates a new client connection wrapper.

func (*ACPClientConnection) CreateTerminal added in v0.7.0

func (c *ACPClientConnection) CreateTerminal(ctx context.Context, command string, args []string, cwd string) (string, error)

CreateTerminal calls the client to create a terminal and execute a command.

func (*ACPClientConnection) GetSessionID added in v0.7.0

func (c *ACPClientConnection) GetSessionID() acpsdk.SessionId

GetSessionID returns the session ID for this connection.

func (*ACPClientConnection) GetWorkDir added in v0.7.0

func (c *ACPClientConnection) GetWorkDir() string

GetWorkDir returns the working directory for this connection.

func (*ACPClientConnection) KillTerminal added in v0.7.0

func (c *ACPClientConnection) KillTerminal(ctx context.Context, terminalID string) error

KillTerminal calls the client to kill a running terminal.

func (*ACPClientConnection) ReadTextFile added in v0.7.0

func (c *ACPClientConnection) ReadTextFile(ctx context.Context, path string) (string, error)

ReadTextFile calls the client to read a file from their filesystem.

func (*ACPClientConnection) ReleaseTerminal added in v0.7.0

func (c *ACPClientConnection) ReleaseTerminal(ctx context.Context, terminalID string) error

ReleaseTerminal calls the client to release a terminal without waiting for it to exit.

func (*ACPClientConnection) TerminalOutput added in v0.7.0

func (c *ACPClientConnection) TerminalOutput(ctx context.Context, terminalID string) (string, error)

TerminalOutput calls the client to get the current output from a terminal.

func (*ACPClientConnection) WaitForTerminalExit added in v0.7.0

func (c *ACPClientConnection) WaitForTerminalExit(ctx context.Context, terminalID string) (*int, error)

WaitForTerminalExit calls the client to wait for a terminal to exit.

func (*ACPClientConnection) WriteTextFile added in v0.7.0

func (c *ACPClientConnection) WriteTextFile(ctx context.Context, path string, content string) error

WriteTextFile calls the client to write a file to their filesystem.

type ACPSession

type ACPSession struct {
	// TaskID is the mesnada task identifier
	TaskID string

	// SessionID is the ACP session identifier returned by the agent
	SessionID acpsdk.SessionId

	// Conn is the client-side connection to the ACP agent
	Conn *acpsdk.ClientSideConnection

	// Cmd is the os/exec.Cmd for the running agent process
	Cmd *exec.Cmd

	// Cancel is the context cancellation function for this session
	Cancel context.CancelFunc
}

ACPSession represents an active session with an ACP agent.

type HTTPTransport added in v0.7.0

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

HTTPTransport implements HTTP/SSE transport for ACP. It manages multiple client sessions and routes requests to the ACP agent.

func NewHTTPTransport added in v0.7.0

func NewHTTPTransport(agent ACPAgent, logger *log.Logger, config HTTPTransportConfig) *HTTPTransport

NewHTTPTransport creates a new HTTP transport for the ACP agent.

func (*HTTPTransport) ActiveSessions added in v0.7.0

func (t *HTTPTransport) ActiveSessions() int

ActiveSessions returns the number of active sessions.

func (*HTTPTransport) Cleanup added in v0.7.0

func (t *HTTPTransport) Cleanup(ctx context.Context)

Cleanup removes idle sessions.

func (*HTTPTransport) CloseSession added in v0.7.0

func (t *HTTPTransport) CloseSession(sessionID string) error

CloseSession closes a session and cleans up resources.

func (*HTTPTransport) GetSessionInfo added in v0.7.0

func (t *HTTPTransport) GetSessionInfo(sessionID string) (*SessionInfo, error)

GetSessionInfo returns information about a specific session.

func (*HTTPTransport) GetStats added in v0.7.0

func (t *HTTPTransport) GetStats() TransportStats

GetStats returns current transport statistics.

func (*HTTPTransport) HandleHealth added in v0.7.0

func (t *HTTPTransport) HandleHealth(w http.ResponseWriter, r *http.Request)

HandleHealth handles health check requests.

func (*HTTPTransport) HandleRequest added in v0.7.0

func (t *HTTPTransport) HandleRequest(w http.ResponseWriter, r *http.Request)

HandleRequest handles HTTP POST requests for ACP JSON-RPC.

func (*HTTPTransport) HandleSSE added in v0.7.0

func (t *HTTPTransport) HandleSSE(w http.ResponseWriter, r *http.Request)

HandleSSE handles Server-Sent Events for notifications.

func (*HTTPTransport) ListSessions added in v0.7.0

func (t *HTTPTransport) ListSessions() []SessionInfo

ListSessions returns information about all active sessions.

type HTTPTransportConfig added in v0.7.0

type HTTPTransportConfig struct {
	MaxSessions  int
	IdleTimeout  time.Duration
	EventBufSize int
}

HTTPTransportConfig holds configuration for the HTTP transport.

func DefaultHTTPTransportConfig added in v0.7.0

func DefaultHTTPTransportConfig() HTTPTransportConfig

DefaultHTTPTransportConfig returns default configuration.

type McpServerConfig

type McpServerConfig struct {
	// Name is the unique identifier for this MCP server
	Name string `json:"name" yaml:"name"`

	// Command is the binary to execute for stdio-based MCP servers
	Command string `json:"command" yaml:"command"`

	// Args are the command-line arguments for the MCP server
	Args []string `json:"args" yaml:"args"`

	// Env is a map of environment variables for the MCP server
	Env map[string]string `json:"env" yaml:"env"`

	// Type is the transport type: "stdio", "http", or "sse"
	Type string `json:"type,omitempty" yaml:"type,omitempty"`

	// URL is the endpoint URL for http or sse transports
	URL string `json:"url,omitempty" yaml:"url,omitempty"`

	// Headers are additional HTTP headers for http/sse transports
	Headers map[string]string `json:"headers,omitempty" yaml:"headers,omitempty"`
}

McpServerConfig represents the configuration of an MCP server to pass to an ACP agent.

type MesnadaACPClient

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

MesnadaACPClient implements the ACP client interface required by the SDK. It handles callbacks from ACP agents, managing file operations, terminal sessions, and session state updates for mesnada tasks.

func NewMesnadaACPClient

func NewMesnadaACPClient(taskID string, workDir string, logFile *os.File, onUpdate func(SessionUpdateInfo)) *MesnadaACPClient

NewMesnadaACPClient creates a new MesnadaACPClient.

func (*MesnadaACPClient) CreateTerminal

CreateTerminal creates a new terminal session for executing commands.

func (*MesnadaACPClient) GetOutput

func (c *MesnadaACPClient) GetOutput() string

GetOutput returns the accumulated output from the agent session.

func (*MesnadaACPClient) GetPermissionQueue

func (c *MesnadaACPClient) GetPermissionQueue() *PermissionQueue

GetPermissionQueue returns the permission queue for manual approval.

func (*MesnadaACPClient) GetProgress

func (c *MesnadaACPClient) GetProgress() (int, string)

GetProgress returns the current progress percentage and description.

func (*MesnadaACPClient) GetToolCallCount

func (c *MesnadaACPClient) GetToolCallCount() int

GetToolCallCount returns the number of tool calls made during the session.

func (*MesnadaACPClient) KillTerminalCommand

KillTerminalCommand kills a running terminal command.

func (*MesnadaACPClient) ReadTextFile

ReadTextFile reads a file from the task's workspace. This implements strict security: the file must be within the task's workDir.

func (*MesnadaACPClient) ReleaseTerminal

ReleaseTerminal releases a terminal session without waiting for it to complete. The terminal continues running but we stop tracking it.

func (*MesnadaACPClient) RequestPermission

RequestPermission handles permission requests from the ACP agent. In auto-permission mode (CI/batch), this auto-approves all requests. In manual mode, this queues the request for approval via API endpoints.

func (*MesnadaACPClient) SessionUpdate

func (c *MesnadaACPClient) SessionUpdate(ctx context.Context, params acpsdk.SessionNotification) error

SessionUpdate handles session updates from the ACP agent. This is called when the agent sends new messages, tool calls, or state changes.

func (*MesnadaACPClient) SetAutoPermission

func (c *MesnadaACPClient) SetAutoPermission(auto bool)

SetAutoPermission sets whether to auto-approve all permission requests.

func (*MesnadaACPClient) SetCapabilities

func (c *MesnadaACPClient) SetCapabilities(caps ACPCapabilities)

SetCapabilities sets the capabilities for this client.

func (*MesnadaACPClient) TerminalOutput

TerminalOutput retrieves the current output from a terminal session.

func (*MesnadaACPClient) WaitForTerminalExit

WaitForTerminalExit waits for a terminal session to complete and returns its exit code.

func (*MesnadaACPClient) WriteTextFile

WriteTextFile writes a file to the task's workspace. This implements strict security: the file must be within the task's workDir.

type PendingPermission

type PendingPermission struct {
	TaskID     string                           `json:"task_id"`
	SessionID  acpsdk.SessionId                 `json:"session_id"`
	RequestID  string                           `json:"request_id"`
	ToolCall   acpsdk.RequestPermissionToolCall `json:"tool_call"`
	Options    []acpsdk.PermissionOption        `json:"options"`
	Outcome    *acpsdk.RequestPermissionOutcome `json:"outcome,omitempty"` // nil = pending, non-nil = resolved
	CreatedAt  time.Time                        `json:"created_at"`
	ResolvedAt *time.Time                       `json:"resolved_at,omitempty"`
}

PendingPermission represents a permission request awaiting resolution.

type PermissionQueue

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

PermissionQueue manages permission requests from ACP agents. It queues requests that need manual approval and allows resolution via API endpoints or automatic policies.

func NewPermissionQueue

func NewPermissionQueue() *PermissionQueue

NewPermissionQueue creates a new permission queue.

func (*PermissionQueue) CleanupResolved

func (q *PermissionQueue) CleanupResolved(maxAge time.Duration) int

CleanupResolved removes resolved permission requests older than the specified duration.

func (*PermissionQueue) GetAllPending

func (q *PermissionQueue) GetAllPending() []*PendingPermission

GetAllPending returns all pending permission requests across all tasks.

func (*PermissionQueue) GetPending

func (q *PermissionQueue) GetPending(taskID string) []*PendingPermission

GetPending returns all pending permission requests for a task.

func (*PermissionQueue) GetPermission

func (q *PermissionQueue) GetPermission(requestID string) (*PendingPermission, bool)

GetPermission returns a specific permission request by ID.

func (*PermissionQueue) QueuePermission

func (q *PermissionQueue) QueuePermission(taskID string, sessionID acpsdk.SessionId, req acpsdk.RequestPermissionRequest) string

QueuePermission adds a permission request to the queue for manual approval. Returns the request ID that can be used to resolve it later.

func (*PermissionQueue) ResolvePermission

func (q *PermissionQueue) ResolvePermission(requestID string, outcome acpsdk.RequestPermissionOutcome) error

ResolvePermission resolves a pending permission request. outcome contains the selected option or denial.

func (*PermissionQueue) WaitForResolution

func (q *PermissionQueue) WaitForResolution(ctx context.Context, requestID string) (acpsdk.RequestPermissionOutcome, error)

WaitForResolution waits for a permission request to be resolved. Returns the outcome or an error if the context is cancelled.

type SessionInfo added in v0.7.0

type SessionInfo struct {
	ID        string        `json:"id"`
	CreatedAt time.Time     `json:"created_at"`
	LastUsed  time.Time     `json:"last_used"`
	IdleTime  time.Duration `json:"idle_time"`
}

SessionInfo contains information about a specific session.

type SessionUpdateInfo

type SessionUpdateInfo struct {
	// TaskID is the mesnada task identifier
	TaskID string

	// MessageText is the text content from the agent (for text blocks)
	MessageText string

	// ToolCall contains information about tool calls made by the agent
	ToolCall *ToolCallInfo

	// Plan contains planning information from the agent
	Plan string

	// StopReason indicates why the agent stopped (if applicable)
	StopReason string

	// Error contains any error message
	Error string
}

SessionUpdateInfo represents information about a session update from the ACP agent. This is used to communicate agent state changes to the mesnada orchestrator.

type SimpleACPAgent added in v0.7.0

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

SimpleACPAgent is a minimal ACP agent for testing HTTP transport. This is used when the full PandoACPAgent is not available due to import cycles.

func NewSimpleACPAgent added in v0.7.0

func NewSimpleACPAgent(version string, logger *log.Logger) *SimpleACPAgent

NewSimpleACPAgent creates a simple ACP agent for testing.

func (*SimpleACPAgent) Authenticate added in v0.7.0

Authenticate is not implemented.

func (*SimpleACPAgent) Cancel added in v0.7.0

Cancel handles cancellation.

func (*SimpleACPAgent) GetCapabilities added in v0.7.0

func (a *SimpleACPAgent) GetCapabilities() acpsdk.AgentCapabilities

GetCapabilities returns the agent capabilities.

func (*SimpleACPAgent) GetVersion added in v0.7.0

func (a *SimpleACPAgent) GetVersion() string

GetVersion returns the agent version.

func (*SimpleACPAgent) Initialize added in v0.7.0

Initialize handles the initialization handshake.

func (*SimpleACPAgent) NewSession added in v0.7.0

NewSession is not implemented.

func (*SimpleACPAgent) Prompt added in v0.7.0

Prompt is not implemented.

func (*SimpleACPAgent) SetSessionMode added in v0.7.0

SetSessionMode is not implemented.

type ToolCallInfo

type ToolCallInfo struct {
	// Name is the name of the tool being called
	Name string

	// Arguments are the arguments passed to the tool
	Arguments map[string]interface{}

	// Status is the status of the tool call: "started", "progress", "completed", "failed"
	Status string

	// Result is the result of the tool call (if completed)
	Result string
}

ToolCallInfo represents information about a tool call from the ACP agent.

type TransportStats added in v0.7.0

type TransportStats struct {
	ActiveSessions    int           `json:"active_sessions"`
	TotalSessions     int           `json:"total_sessions"`
	RequestsProcessed int           `json:"requests_processed"`
	MaxSessions       int           `json:"max_sessions"`
	Uptime            time.Duration `json:"uptime"`
	IdleTimeout       time.Duration `json:"idle_timeout"`
}

TransportStats holds statistics about the HTTP transport.

Jump to

Keyboard shortcuts

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