acp

package
v0.14.4-dev.53 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const SubagentKey = "_subagent"

SubagentKey marks a log entry that belongs to a subagent rather than to the conversation itself. Its value is the child's ACP session ID, or "tool:<toolCallId>" for an agent that flattens its subagents into the parent session (not cancellable).

Variables

View Source
var ErrSubagentNotCancellable = errors.New("subagent cannot be cancelled")

ErrSubagentNotCancellable reports a child the agent did not announce with a cancel capability.

Functions

func Accepted added in v0.14.1

func Accepted(ctx context.Context)

Accepted reports that the prompt carried by ctx was logged and is being sent to the agent.

func AddSessionCapabilities

func AddSessionCapabilities(line []byte) []byte

AddSessionCapabilities adds standard fields missing from SDK v0.13.5's client capability type.

func AppendRawSessionUpdate added in v0.14.1

func AppendRawSessionUpdate(log *EventLog, line []byte) bool

AppendRawSessionUpdate logs session/update variants SDK v0.13.5 cannot decode and reports whether the line was consumed. It also registers announced subagents before their own updates reach the SDK, so HarnessClient can stamp them.

func CancelSubagent added in v0.14.1

func CancelSubagent(ctx context.Context, log *EventLog, broker *Broker, id string) error

CancelSubagent sends session/cancel for one announced child, leaving the parent turn running.

func InitializeRequest

func InitializeRequest() sdkacp.InitializeRequest

InitializeRequest advertises the client capabilities agentpack implements on the worker.

func NewClientConnection

func NewClientConnection(client sdkacp.Client, peerInput io.Writer, peerOutput io.Reader) *sdkacp.ClientSideConnection

NewClientConnection connects client to an agent with backpressure on notification floods. Pass the outermost client so its overrides are the handlers that release the gate.

func ReadWorkspaceFile

func ReadWorkspaceFile(root string, extra []string, path string, line, limit *int) (string, error)

ReadWorkspaceFile reads a text file confined to the workspace roots.

func ResolveWorkspacePath

func ResolveWorkspacePath(root string, extra []string, path string) (string, error)

ResolveWorkspacePath follows symlinks and ensures path stays under root or extra dirs.

func StripControls

func StripControls(s string) string

StripControls removes terminal controls from agent text while retaining newlines.

func WithAccepted added in v0.14.1

func WithAccepted(ctx context.Context, accept func()) context.Context

WithAccepted returns a context whose prompt implementation calls accept once the prompt is durably sent.

func WriteWorkspaceFile

func WriteWorkspaceFile(root string, extra []string, path, content string) error

WriteWorkspaceFile atomically replaces a text file confined to the workspace roots.

Types

type Broker

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

Broker forwards conversation control and coordinates per-request answers.

func NewBroker

func NewBroker(
	prompt func(context.Context, PromptInput) error,
	cancel func(context.Context) error,
	answer func(context.Context, string, string) error,
	setConfig func(context.Context, string, string) error,
) *Broker

func (*Broker) Answer

func (b *Broker) Answer(requestID, optionID string) bool

Answer records the first option ID for an active request.

func (*Broker) AnswerPermission

func (b *Broker) AnswerPermission(ctx context.Context, requestID, optionID string) error

AnswerPermission forwards and records the first answer for an active request.

func (*Broker) Begin

func (b *Broker) Begin(requestID string) error

Begin starts a request lifecycle. Active IDs cannot be reused.

func (*Broker) Cancel

func (b *Broker) Cancel(ctx context.Context) error

func (*Broker) End

func (b *Broker) End(requestID string)

End consumes the result and permits a later request to reuse the ID.

func (*Broker) Prompt

func (b *Broker) Prompt(ctx context.Context, input PromptInput) error

func (*Broker) SetConfig

func (b *Broker) SetConfig(ctx context.Context, key, value string) error

func (*Broker) Wait

func (b *Broker) Wait(ctx context.Context, requestID string) (string, error)

Wait blocks until the active request is answered or ctx is done.

type EventLog

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

EventLog stores bounded session events for replay and coalesced retention.

func NewEventLog

func NewEventLog(limitBytes int) *EventLog

func (*EventLog) Append

func (log *EventLog) Append(kind string, ts int64, payload json.RawMessage) LogEntry

func (*EventLog) Changed added in v0.14.1

func (log *EventLog) Changed() <-chan struct{}

Changed returns a channel that closes on the next append, restore or truncation.

func (*EventLog) Close

func (log *EventLog) Close() error

func (*EventLog) EnableSink added in v0.14.0

func (log *EventLog) EnableSink(sink func(LogChanges) error) error

EnableSink calls sink serially under the log lock; sink must not call log methods. Failed writes remain pending for retry, and Close reports the first failure.

func (*EventLog) Flush added in v0.14.0

func (log *EventLog) Flush() error

Flush makes a turn boundary durable before its acknowledgement or idle state is visible.

func (*EventLog) MarkTruncated

func (log *EventLog) MarkTruncated()

MarkTruncated records that an event could not be retained, such as an oversized wire frame.

func (*EventLog) ReadSince

func (log *EventLog) ReadSince(since int64) (out []LogEntry, truncated bool)

func (*EventLog) Restore added in v0.14.0

func (log *EventLog) Restore(entries []LogEntry, lastSeq int64, truncated bool) error

Restore seeds a new log without renumbering events or notifying live subscribers.

func (*EventLog) Seq added in v0.14.1

func (log *EventLog) Seq() int64

Seq is the sequence of the newest event; it moves on every append.

func (*EventLog) SetOnAppend

func (log *EventLog) SetOnAppend(onAppend func(LogEntry)) []LogEntry

func (*EventLog) SetReplaying added in v0.14.0

func (log *EventLog) SetReplaying(replaying bool)

SetReplaying suppresses the native load response when durable history is already restored. Process exits remain live events even while the adapter is loading its session.

func (*EventLog) Snapshot

func (log *EventLog) Snapshot() []LogEntry

func (*EventLog) SubagentCancellable added in v0.14.1

func (log *EventLog) SubagentCancellable(id string) bool

SubagentCancellable reports whether the agent announced id with the cancel capability.

func (*EventLog) Truncated

func (log *EventLog) Truncated() bool

type HarnessClient

type HarnessClient struct {
	Root      string
	Extra     []string
	Log       *EventLog
	Broker    *Broker
	Terminals *TerminalPool

	// AutoApprove reports that the agent runs in a mode where the user chose never to be asked.
	// Some agents still request permission then (Claude Code for commands outside the project).
	AutoApprove func() bool
	// contains filtered or unexported fields
}

HarnessClient is the agentpack ACP client: permissions via Broker, updates to EventLog, fs confined to workspace.

func NewHarnessClient

func NewHarnessClient(root string, extra []string, log *EventLog, broker *Broker) *HarnessClient

NewHarnessClient wires a client implementation for ClientSideConnection.

func (*HarnessClient) CreateTerminal

func (*HarnessClient) DrainSessionUpdates added in v0.14.0

func (c *HarnessClient) DrainSessionUpdates(ctx context.Context) error

DrainSessionUpdates waits for queued handlers after the connection reader has stopped. SDK Done closes before those handlers finish; session/load already has its own SDK barrier.

func (*HarnessClient) HandleExtensionMethod

func (c *HarnessClient) HandleExtensionMethod(ctx context.Context, method string, params json.RawMessage) (any, error)

func (*HarnessClient) KillTerminal

func (*HarnessClient) NewClientSideConnection

func (c *HarnessClient) NewClientSideConnection(peerInput io.Writer, peerOutput io.Reader) *sdkacp.ClientSideConnection

NewClientSideConnection returns an SDK client connection over the given transport.

func (*HarnessClient) ReadTextFile

func (*HarnessClient) SessionUpdate

func (c *HarnessClient) SessionUpdate(ctx context.Context, n sdkacp.SessionNotification) error

func (*HarnessClient) TerminalOutput

func (*HarnessClient) UnstableCompleteElicitation

func (*HarnessClient) WriteTextFile

type LogChanges added in v0.14.0

type LogChanges struct {
	Entries   []LogEntry
	Removed   []int64
	LastSeq   int64
	Truncated bool
}

LogChanges contains durable updates, including replacements for coalesced chunks. Removed contains only absorbed chunks, never ordinary memory evictions.

type LogEntry

type LogEntry struct {
	Seq     int64           `json:"seq"`
	TS      int64           `json:"ts"`
	Kind    string          `json:"kind"`
	Payload json.RawMessage `json:"payload"`
}

LogEntry is one append-only row in a session event log. Payload is the ACP sessionUpdate body or a synthetic envelope for prompt, permission, and turn events.

type PromptImage

type PromptImage struct {
	Sha           string
	Name          string
	Mime          string
	Kind          string
	Width, Height int
}

PromptImage references an image blob stored under the worker session directory.

type PromptInput

type PromptInput struct {
	QueueID      string
	Text         string
	Image        *PromptImage
	Images       []PromptImage
	ResourceLink *PromptResourceLink
}

PromptInput is a user message sent to the agent.

type PromptResourceLink struct {
	Sha  string
	Name string
}

PromptResourceLink references a stored file that an agent can read by URI.

type TerminalPool

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

TerminalPool runs ACP terminal/create commands with a bounded output buffer.

func NewTerminalPool

func NewTerminalPool() *TerminalPool

NewTerminalPool returns an empty terminal pool.

func (*TerminalPool) Close

func (p *TerminalPool) Close() error

Close prevents new terminals and terminates every managed process group.

type ThreadItem

type ThreadItem struct {
	Kind string          `json:"kind"`
	Data json.RawMessage `json:"data,omitempty"`
}

ThreadItem is the reduced view the worker keeps for session state.

type ThreadReducer

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

ThreadReducer applies conversation entries and retains only outstanding requests. ReduceLog also keeps the transcript items needed for full replay.

func (*ThreadReducer) Apply

func (reducer *ThreadReducer) Apply(entry LogEntry) ThreadState

type ThreadState

type ThreadState struct {
	Items         []ThreadItem `json:"items"`
	NeedsYou      bool         `json:"needs_you"`
	Working       bool         `json:"working"`
	PlanKind      string       `json:"plan_kind,omitempty"`
	ContextTokens int          `json:"context_tokens,omitempty"`
	ContextLimit  int          `json:"context_limit,omitempty"`
	CostUSD       float64      `json:"cost_usd,omitempty"`
}

ThreadState tracks composer-adjacent session UI state.

func ReduceLog

func ReduceLog(entries []LogEntry) ThreadState

ReduceLog folds append-only log entries into a thread view.

type Usage added in v0.14.1

type Usage struct {
	Turns, InputTokens, OutputTokens, CacheReadTokens, CacheWriteTokens int64
	// CostMicros is cost this entry adds; CostTotalMicros is a session's running total. -1 when not reported.
	CostMicros, CostTotalMicros int64
	Model                       string
}

Usage is what one log entry adds to a session's counters. Input excludes cache reads and writes for every agent, so the four token counts add up to everything the turn processed.

func ParseUsage added in v0.14.1

func ParseUsage(entry LogEntry) (Usage, bool)

ParseUsage normalizes the usage an agent reports in one log entry; ok is false when it reports none. One shape per agent: ACP turn_end.usage (Claude, Codex, OMP, Antigravity), Grok's turn_end._meta, and usage_update.cost, a running total (Claude, OMP). Cursor reports nothing, so its turns only count.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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