Help us shape the future of Go! Take the 2026 Go Developer Survey

acp

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolVersion = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentInfo

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

type AgentSpec

type AgentSpec struct {
	Name        string
	Command     string
	Args        []string
	Environment map[string]string
}

type Connection

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

func NewConnection

func NewConnection(reader io.ReadCloser, writer io.WriteCloser, requestHandler RequestHandler, notificationHandler NotificationHandler) *Connection

func (*Connection) Close

func (c *Connection) Close() error

func (*Connection) Closed

func (c *Connection) Closed() <-chan struct{}

func (*Connection) Notify

func (c *Connection) Notify(method string, params any) error

func (*Connection) Request

func (c *Connection) Request(ctx context.Context, method string, params any, result any) error

type ContentBlock added in v0.9.0

type ContentBlock map[string]any

ContentBlock 保留 ACP/MCP ContentBlock 的开放字段,但在进入协议层前按 type 与 initialize.promptCapabilities 做严格能力校验。动态 map 只停留在协议边界。

func TextBlock added in v0.9.0

func TextBlock(text string) ContentBlock

type ContextPolicy

type ContextPolicy struct {
	HistoryOwner                  string `json:"history_owner"`
	AgentDockPersistsTranscript   bool   `json:"agentdock_persists_transcript"`
	AgentDockReplaysTranscript    bool   `json:"agentdock_replays_transcript"`
	ManagedSessionAutoReactivates bool   `json:"managed_session_auto_reactivates"`
	HistoryReadUsesAdapterLoad    bool   `json:"history_read_uses_adapter_load"`
}

type Error

type Error struct {
	Code      string
	Message   string
	Retryable bool
	Details   map[string]any
	Cause     error
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Event

type Event struct {
	Seq                 uint64          `json:"seq"`
	Source              string          `json:"source"`
	Type                string          `json:"type"`
	SessionID           string          `json:"session_id"`
	RunID               string          `json:"run_id,omitempty"`
	CreatedAt           time.Time       `json:"created_at"`
	Update              json.RawMessage `json:"update,omitempty"`
	UpdateTruncated     bool            `json:"update_truncated,omitempty"`
	OriginalUpdateBytes int             `json:"original_update_bytes,omitempty"`
	StopReason          string          `json:"stop_reason,omitempty"`
	ErrorCode           string          `json:"error_code,omitempty"`
	Message             string          `json:"message,omitempty"`
}

type EventPolicy

type EventPolicy struct {
	Incremental              bool   `json:"incremental"`
	Cursor                   string `json:"cursor"`
	MaxEventsPerPage         int    `json:"max_events_per_page"`
	MaxRetainedEvents        int    `json:"max_retained_events"`
	MaxRetainedBytes         int    `json:"max_retained_bytes"`
	MaxUpdateBytes           int    `json:"max_update_bytes"`
	PrivateReasoningFiltered bool   `json:"private_reasoning_filtered"`
}

type HistoryEvent added in v0.9.0

type HistoryEvent struct {
	Source              string          `json:"source"`
	Type                string          `json:"type"`
	Update              json.RawMessage `json:"update"`
	UpdateTruncated     bool            `json:"update_truncated,omitempty"`
	OriginalUpdateBytes int             `json:"original_update_bytes,omitempty"`
}

HistoryEvent 是一次 session/load 期间由 Adapter 回放的原生会话事件。 AgentDock 只在当前调用内暂存这些事件,不把 transcript 写入本地 SessionRecord。

type HistoryReplay added in v0.9.0

type HistoryReplay struct {
	Events    []HistoryEvent `json:"events"`
	Truncated bool           `json:"truncated"`
}

type InitializeResult

type InitializeResult struct {
	ProtocolVersion   int            `json:"protocolVersion"`
	AgentCapabilities map[string]any `json:"agentCapabilities"`
	AgentInfo         AgentInfo      `json:"agentInfo"`
	AuthMethods       []any          `json:"authMethods,omitempty"`
	Meta              map[string]any `json:"_meta,omitempty"`
}

type Interaction

type Interaction struct {
	ID        string             `json:"id"`
	SessionID string             `json:"session_id"`
	Kind      string             `json:"kind"`
	Status    InteractionStatus  `json:"status"`
	ToolCall  map[string]any     `json:"tool_call,omitempty"`
	Options   []PermissionOption `json:"options,omitempty"`
	CreatedAt time.Time          `json:"created_at"`
	ExpiresAt time.Time          `json:"expires_at"`
	// contains filtered or unexported fields
}

type InteractionPolicy

type InteractionPolicy struct {
	MemoryOnly            bool `json:"memory_only"`
	MaxOptions            int  `json:"max_options"`
	MaxToolCallBytes      int  `json:"max_tool_call_bytes"`
	MaxPendingGlobal      int  `json:"max_pending_global"`
	MaxPendingPerSession  int  `json:"max_pending_per_session"`
	AlwaysOptionsFiltered bool `json:"always_options_filtered"`
	ElicitationAdvertised bool `json:"elicitation_advertised"`
}

type InteractionStatus

type InteractionStatus string
const (
	InteractionPending   InteractionStatus = "pending"
	InteractionResponded InteractionStatus = "responded"
	InteractionCancelled InteractionStatus = "cancelled"
	InteractionExpired   InteractionStatus = "expired"
)

type Manager

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

func NewManager

func NewManager(opts Options) (*Manager, error)

func (*Manager) AgentInfo

func (m *Manager) AgentInfo(ctx context.Context) (InitializeResult, error)

func (*Manager) AttachRemoteSession added in v0.9.0

func (m *Manager) AttachRemoteSession(remote RemoteSession) (SessionRecord, error)

func (*Manager) Authenticate

func (m *Manager) Authenticate(ctx context.Context, methodID string) error

func (*Manager) CancelPrompt

func (m *Manager) CancelPrompt(_ context.Context, sessionID, runID string) error

func (*Manager) Close

func (m *Manager) Close() error

func (*Manager) CloseSession

func (m *Manager) CloseSession(ctx context.Context, id string) (SessionRecord, error)

func (*Manager) DeleteRemoteSession added in v0.9.0

func (m *Manager) DeleteRemoteSession(ctx context.Context, remoteSessionID string) error

DeleteRemoteSession 删除 Adapter 原生会话。若该 remote session 已经被 AgentDock 管理,则复用 DeleteSession 保证本地映射与持久化记录同步清理;否则只调用标准 session/delete。该方法绝不把“Adapter 不支持 delete”静默降级为本地解绑。

func (*Manager) DeleteSession

func (m *Manager) DeleteSession(ctx context.Context, id string) error

func (*Manager) EnsureSessionActive added in v0.9.0

func (m *Manager) EnsureSessionActive(ctx context.Context, id string) (SessionResult, error)

EnsureSessionActive 只负责让已 managed 的会话可继续执行,不要求调用方理解 ACP 的 load/resume 差异。优先使用 resume 避免无意义的历史回放;仅当 Adapter 没有 resume 时才退回标准 session/load。

func (*Manager) FindRemoteSession added in v0.9.0

func (m *Manager) FindRemoteSession(ctx context.Context, remoteSessionID string) (RemoteSession, error)

func (*Manager) ForkSession

func (m *Manager) ForkSession(ctx context.Context, id, cwd string, additionalDirectories []string) (SessionResult, error)

func (*Manager) InspectInteraction

func (m *Manager) InspectInteraction(id string) (Interaction, error)

func (*Manager) InspectSession

func (m *Manager) InspectSession(id string) (SessionRecord, error)

func (*Manager) ListInteractions

func (m *Manager) ListInteractions(sessionID string, pendingOnly bool) []Interaction

func (*Manager) ListManagedSessions added in v0.9.0

func (m *Manager) ListManagedSessions() ([]SessionRecord, error)

func (*Manager) ListRemoteSessions added in v0.9.0

func (m *Manager) ListRemoteSessions(ctx context.Context, cwd, cursor string) (RemoteSessionPage, error)

func (*Manager) ListSessions

func (m *Manager) ListSessions() ([]SessionRecord, error)

ListSessions 保留为内部兼容别名。工具层的 list 已经不再把它误认为 ACP session/list。

func (*Manager) LoadSession

func (m *Manager) LoadSession(ctx context.Context, id string) (SessionResult, error)

func (*Manager) ManagedSessionForRemote added in v0.9.0

func (m *Manager) ManagedSessionForRemote(remoteSessionID string) (SessionRecord, bool)

func (*Manager) NewSession

func (m *Manager) NewSession(ctx context.Context, cwd string, additionalDirectories []string) (SessionResult, error)

func (*Manager) OpenSession added in v0.9.0

func (m *Manager) OpenSession(ctx context.Context, sessionID, remoteSessionID string) (SessionResult, bool, error)

OpenSession 接受 AgentDock session id 或 Adapter 原生 remote id。 对 remote id,AgentDock 只建立轻量映射,不复制 transcript,再自动选择 resume/load 激活。

func (*Manager) PromptEvents

func (m *Manager) PromptEvents(ctx context.Context, runID string, after uint64, limit int, wait time.Duration) (PromptEventsResult, error)

func (*Manager) ReadRemoteHistory added in v0.9.0

func (m *Manager) ReadRemoteHistory(ctx context.Context, remoteSessionID, cwd string, additionalDirectories []string) (HistoryReplay, sessionLifecycleResponse, error)

ReadRemoteHistory 显式调用标准 session/load,并只收集该调用期间 Adapter 回放的 session/update。它不会创建 acps_* 映射,也不会把历史写入 AgentDock 持久化状态。

func (*Manager) RespondInteraction

func (m *Manager) RespondInteraction(id, optionID string, cancelled bool) (Interaction, error)

func (*Manager) ResumeSession

func (m *Manager) ResumeSession(ctx context.Context, id string) (SessionResult, error)

func (*Manager) SessionProjection added in v0.9.0

func (m *Manager) SessionProjection(sessionID string) (SessionProjection, error)

func (*Manager) SetSessionConfigOption

func (m *Manager) SetSessionConfigOption(ctx context.Context, id, configID string, value any) (any, error)

func (*Manager) SetSessionMode

func (m *Manager) SetSessionMode(ctx context.Context, id, modeID string) error

func (*Manager) StartPrompt

func (m *Manager) StartPrompt(ctx context.Context, sessionID, text string) (PromptStartResult, error)

func (*Manager) StartPromptBlocks added in v0.9.0

func (m *Manager) StartPromptBlocks(ctx context.Context, sessionID string, blocks []ContentBlock) (PromptStartResult, error)

func (*Manager) Steer

func (m *Manager) Steer(ctx context.Context, sessionID, text string) (map[string]any, error)

func (*Manager) SubmitPrompt added in v0.9.0

func (m *Manager) SubmitPrompt(ctx context.Context, sessionID string, blocks []ContentBlock) (PromptStartResult, error)

SubmitPrompt 是工具层唯一的 prompt 入口:空闲时启动新的 session/prompt;已有 active Run 时仅在 Adapter 广告 steering 扩展且输入为纯文本时自动注入当前 Run。

type NotificationHandler

type NotificationHandler func(string, json.RawMessage)

type Options

type Options struct {
	Home               string
	DefaultCWD         string
	Agent              AgentSpec
	MaxConcurrentRuns  int
	InteractionTimeout time.Duration
}

type PermissionOption

type PermissionOption struct {
	OptionID string `json:"optionId"`
	Name     string `json:"name"`
	Kind     string `json:"kind"`
}

type PromptEventsResult

type PromptEventsResult struct {
	RunID           string     `json:"run_id"`
	SessionID       string     `json:"session_id"`
	Status          RunStatus  `json:"status"`
	Events          []Event    `json:"events"`
	NextSeq         uint64     `json:"next_seq"`
	FirstSeq        uint64     `json:"first_seq"`
	LatestSeq       uint64     `json:"latest_seq"`
	DroppedCount    uint64     `json:"dropped_count"`
	HasMore         bool       `json:"has_more"`
	Truncated       bool       `json:"truncated"`
	StartedAt       time.Time  `json:"started_at"`
	EndedAt         *time.Time `json:"ended_at,omitempty"`
	StopReason      string     `json:"stop_reason,omitempty"`
	ErrorCode       string     `json:"error_code,omitempty"`
	Message         string     `json:"message,omitempty"`
	CancelRequested bool       `json:"cancel_requested"`
}

type PromptStartResult

type PromptStartResult struct {
	RunID       string    `json:"run_id"`
	SessionID   string    `json:"session_id"`
	Status      RunStatus `json:"status"`
	Disposition string    `json:"disposition"`
	StartedAt   time.Time `json:"started_at"`
}

type RemoteSession added in v0.9.0

type RemoteSession struct {
	RemoteSessionID       string         `json:"remote_session_id"`
	CWD                   string         `json:"cwd"`
	AdditionalDirectories []string       `json:"additional_directories,omitempty"`
	Title                 string         `json:"title,omitempty"`
	UpdatedAt             string         `json:"updated_at,omitempty"`
	Meta                  map[string]any `json:"_meta,omitempty"`
	Managed               bool           `json:"managed"`
	SessionID             string         `json:"session_id,omitempty"`
}

RemoteSession 描述 Adapter 通过标准 session/list 暴露的原生会话。 SessionID 只有在该 remote session 已经被 AgentDock 管理时才会出现。

type RemoteSessionPage added in v0.9.0

type RemoteSessionPage struct {
	Sessions   []RemoteSession `json:"sessions"`
	NextCursor string          `json:"next_cursor,omitempty"`
}

type RequestHandler

type RequestHandler func(context.Context, string, json.RawMessage) (any, *rpcError)

type Run

type Run struct {
	ID              string
	SessionID       string
	Status          RunStatus
	StartedAt       time.Time
	EndedAt         *time.Time
	StopReason      string
	Err             error
	CancelRequested bool
	// contains filtered or unexported fields
}

type RunStatus

type RunStatus string
const (
	RunRunning     RunStatus = "running"
	RunCompleted   RunStatus = "completed"
	RunCancelled   RunStatus = "cancelled"
	RunInterrupted RunStatus = "interrupted"
	RunFailed      RunStatus = "failed"
)

type RuntimePolicies

type RuntimePolicies struct {
	Context      ContextPolicy     `json:"context_policy"`
	Events       EventPolicy       `json:"event_policy"`
	Interactions InteractionPolicy `json:"interaction_policy"`
	Steering     SteeringPolicy    `json:"steering_policy"`
}

RuntimePolicies is the machine-readable contract returned by acp_session info. Values are derived from the same constants that enforce the runtime, keeping client guidance and server behavior in one source of truth.

func CurrentPolicies

func CurrentPolicies() RuntimePolicies

type SessionProjection added in v0.9.0

type SessionProjection struct {
	ModeID            string         `json:"mode_id,omitempty"`
	ConfigOptions     any            `json:"config_options,omitempty"`
	AvailableCommands any            `json:"available_commands,omitempty"`
	SessionInfo       map[string]any `json:"session_info,omitempty"`
	Usage             map[string]any `json:"usage,omitempty"`
}

SessionProjection is bounded, process-local Adapter state derived from standard session/update notifications. It is not a transcript and is never treated as a second source of truth for conversation history.

type SessionRecord

type SessionRecord struct {
	SchemaVersion         int           `json:"schema_version"`
	ID                    string        `json:"id"`
	Agent                 string        `json:"agent"`
	RemoteSessionID       string        `json:"remote_session_id"`
	CWD                   string        `json:"cwd"`
	Title                 string        `json:"title,omitempty"`
	AdditionalDirectories []string      `json:"additional_directories,omitempty"`
	ModeID                string        `json:"mode_id,omitempty"`
	Status                SessionStatus `json:"status"`
	LastStopReason        string        `json:"last_stop_reason,omitempty"`
	CreatedAt             time.Time     `json:"created_at"`
	UpdatedAt             time.Time     `json:"updated_at"`
	ClosedAt              *time.Time    `json:"closed_at,omitempty"`
}

type SessionResult

type SessionResult struct {
	Session       SessionRecord `json:"session"`
	Modes         any           `json:"modes,omitempty"`
	ConfigOptions any           `json:"config_options,omitempty"`
	History       HistoryReplay `json:"history,omitempty"`
	Agent         AgentInfo     `json:"agent"`
}

type SessionStatus

type SessionStatus string
const (
	SessionReady       SessionStatus = "ready"
	SessionRunning     SessionStatus = "running"
	SessionInterrupted SessionStatus = "interrupted"
	SessionClosed      SessionStatus = "closed"
	SessionError       SessionStatus = "error"
)

type SteeringPolicy

type SteeringPolicy struct {
	NativeWhenSupported             bool `json:"native_when_supported"`
	IdlePromptRequiredStartsRun     bool `json:"idle_prompt_required_starts_run"`
	CompatibilityFallbackReturnsRun bool `json:"compatibility_fallback_returns_run"`
}

Jump to

Keyboard shortcuts

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