Documentation
¶
Index ¶
- Constants
- Variables
- func Accepted(ctx context.Context)
- func AddSessionCapabilities(line []byte) []byte
- func AppendRawSessionUpdate(log *EventLog, line []byte) bool
- func CancelSubagent(ctx context.Context, log *EventLog, broker *Broker, id string) error
- func InitializeRequest() sdkacp.InitializeRequest
- func NewClientConnection(client sdkacp.Client, peerInput io.Writer, peerOutput io.Reader) *sdkacp.ClientSideConnection
- func ReadWorkspaceFile(root string, extra []string, path string, line, limit *int) (string, error)
- func ResolveWorkspacePath(root string, extra []string, path string) (string, error)
- func StripControls(s string) string
- func WithAccepted(ctx context.Context, accept func()) context.Context
- func WriteWorkspaceFile(root string, extra []string, path, content string) error
- type Broker
- func (b *Broker) Answer(requestID, optionID string) bool
- func (b *Broker) AnswerPermission(ctx context.Context, requestID, optionID string) error
- func (b *Broker) Begin(requestID string) error
- func (b *Broker) Cancel(ctx context.Context) error
- func (b *Broker) End(requestID string)
- func (b *Broker) Prompt(ctx context.Context, input PromptInput) error
- func (b *Broker) SetConfig(ctx context.Context, key, value string) error
- func (b *Broker) Wait(ctx context.Context, requestID string) (string, error)
- type EventLog
- func (log *EventLog) Append(kind string, ts int64, payload json.RawMessage) LogEntry
- func (log *EventLog) Changed() <-chan struct{}
- func (log *EventLog) Close() error
- func (log *EventLog) EnableSink(sink func(LogChanges) error) error
- func (log *EventLog) Flush() error
- func (log *EventLog) MarkTruncated()
- func (log *EventLog) ReadSince(since int64) (out []LogEntry, truncated bool)
- func (log *EventLog) Restore(entries []LogEntry, lastSeq int64, truncated bool) error
- func (log *EventLog) Seq() int64
- func (log *EventLog) SetOnAppend(onAppend func(LogEntry)) []LogEntry
- func (log *EventLog) SetReplaying(replaying bool)
- func (log *EventLog) Snapshot() []LogEntry
- func (log *EventLog) SubagentCancellable(id string) bool
- func (log *EventLog) Truncated() bool
- type HarnessClient
- func (c *HarnessClient) CreateTerminal(ctx context.Context, p sdkacp.CreateTerminalRequest) (sdkacp.CreateTerminalResponse, error)
- func (c *HarnessClient) DrainSessionUpdates(ctx context.Context) error
- func (c *HarnessClient) HandleExtensionMethod(ctx context.Context, method string, params json.RawMessage) (any, error)
- func (c *HarnessClient) KillTerminal(ctx context.Context, p sdkacp.KillTerminalRequest) (sdkacp.KillTerminalResponse, error)
- func (c *HarnessClient) NewClientSideConnection(peerInput io.Writer, peerOutput io.Reader) *sdkacp.ClientSideConnection
- func (c *HarnessClient) ReadTextFile(ctx context.Context, p sdkacp.ReadTextFileRequest) (sdkacp.ReadTextFileResponse, error)
- func (c *HarnessClient) ReleaseTerminal(ctx context.Context, p sdkacp.ReleaseTerminalRequest) (sdkacp.ReleaseTerminalResponse, error)
- func (c *HarnessClient) RequestPermission(ctx context.Context, p sdkacp.RequestPermissionRequest) (sdkacp.RequestPermissionResponse, error)
- func (c *HarnessClient) SessionUpdate(ctx context.Context, n sdkacp.SessionNotification) error
- func (c *HarnessClient) TerminalOutput(ctx context.Context, p sdkacp.TerminalOutputRequest) (sdkacp.TerminalOutputResponse, error)
- func (c *HarnessClient) UnstableCompleteElicitation(_ context.Context, _ sdkacp.UnstableCompleteElicitationNotification) error
- func (c *HarnessClient) UnstableCreateElicitation(ctx context.Context, params sdkacp.UnstableCreateElicitationRequest) (sdkacp.UnstableCreateElicitationResponse, error)
- func (c *HarnessClient) WaitForTerminalExit(ctx context.Context, p sdkacp.WaitForTerminalExitRequest) (sdkacp.WaitForTerminalExitResponse, error)
- func (c *HarnessClient) WriteTextFile(ctx context.Context, p sdkacp.WriteTextFileRequest) (sdkacp.WriteTextFileResponse, error)
- type LogChanges
- type LogEntry
- type PromptImage
- type PromptInput
- type PromptResourceLink
- type TerminalPool
- type ThreadItem
- type ThreadReducer
- type ThreadState
- type Usage
Constants ¶
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 ¶
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
Accepted reports that the prompt carried by ctx was logged and is being sent to the agent.
func AddSessionCapabilities ¶
AddSessionCapabilities adds standard fields missing from SDK v0.13.5's client capability type.
func AppendRawSessionUpdate ¶ added in v0.14.1
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
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 ¶
ReadWorkspaceFile reads a text file confined to the workspace roots.
func ResolveWorkspacePath ¶
ResolveWorkspacePath follows symlinks and ensures path stays under root or extra dirs.
func StripControls ¶
StripControls removes terminal controls from agent text while retaining newlines.
func WithAccepted ¶ added in v0.14.1
WithAccepted returns a context whose prompt implementation calls accept once the prompt is durably sent.
Types ¶
type Broker ¶
type Broker struct {
// contains filtered or unexported fields
}
Broker forwards conversation control and coordinates per-request answers.
func (*Broker) AnswerPermission ¶
AnswerPermission forwards and records the first answer for an active request.
type EventLog ¶
type EventLog struct {
// contains filtered or unexported fields
}
EventLog stores bounded session events for replay and coalesced retention.
func NewEventLog ¶
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) 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
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) Restore ¶ added in v0.14.0
Restore seeds a new log without renumbering events or notifying live subscribers.
func (*EventLog) Seq ¶ added in v0.14.1
Seq is the sequence of the newest event; it moves on every append.
func (*EventLog) SetOnAppend ¶
func (*EventLog) SetReplaying ¶ added in v0.14.0
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) SubagentCancellable ¶ added in v0.14.1
SubagentCancellable reports whether the agent announced id with the cancel capability.
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 (c *HarnessClient) CreateTerminal(ctx context.Context, p sdkacp.CreateTerminalRequest) (sdkacp.CreateTerminalResponse, error)
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 (c *HarnessClient) KillTerminal(ctx context.Context, p sdkacp.KillTerminalRequest) (sdkacp.KillTerminalResponse, error)
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 (c *HarnessClient) ReadTextFile(ctx context.Context, p sdkacp.ReadTextFileRequest) (sdkacp.ReadTextFileResponse, error)
func (*HarnessClient) ReleaseTerminal ¶
func (c *HarnessClient) ReleaseTerminal(ctx context.Context, p sdkacp.ReleaseTerminalRequest) (sdkacp.ReleaseTerminalResponse, error)
func (*HarnessClient) RequestPermission ¶
func (c *HarnessClient) RequestPermission(ctx context.Context, p sdkacp.RequestPermissionRequest) (sdkacp.RequestPermissionResponse, error)
func (*HarnessClient) SessionUpdate ¶
func (c *HarnessClient) SessionUpdate(ctx context.Context, n sdkacp.SessionNotification) error
func (*HarnessClient) TerminalOutput ¶
func (c *HarnessClient) TerminalOutput(ctx context.Context, p sdkacp.TerminalOutputRequest) (sdkacp.TerminalOutputResponse, error)
func (*HarnessClient) UnstableCompleteElicitation ¶
func (c *HarnessClient) UnstableCompleteElicitation(_ context.Context, _ sdkacp.UnstableCompleteElicitationNotification) error
func (*HarnessClient) UnstableCreateElicitation ¶
func (c *HarnessClient) UnstableCreateElicitation(ctx context.Context, params sdkacp.UnstableCreateElicitationRequest) (sdkacp.UnstableCreateElicitationResponse, error)
func (*HarnessClient) WaitForTerminalExit ¶
func (c *HarnessClient) WaitForTerminalExit(ctx context.Context, p sdkacp.WaitForTerminalExitRequest) (sdkacp.WaitForTerminalExitResponse, error)
func (*HarnessClient) WriteTextFile ¶
func (c *HarnessClient) WriteTextFile(ctx context.Context, p sdkacp.WriteTextFileRequest) (sdkacp.WriteTextFileResponse, error)
type LogChanges ¶ added in v0.14.0
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 ¶
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 ¶
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 {
// StateOnly keeps only what Working and NeedsYou need: unanswered requests. A worker never
// renders the thread, so it skips message text, tools and plans and its memory stays bounded.
StateOnly bool
// contains filtered or unexported fields
}
ThreadReducer applies conversation entries without rescanning the full log.
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
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.