acp

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusSuccess = "success"
	StatusError   = "error"

	EventTypeMessage  = "message"
	EventTypeProgress = "progress"
	EventTypeTool     = "tool"
	EventTypeError    = "error"
	// EventTypeStderr carries a single line of subprocess stderr. Distinct
	// from Progress so the UI can render diagnostic chatter (npm install
	// progress, "API key required", protocol error dumps) differently from
	// real tool calls or agent thinking.
	EventTypeStderr = "stderr"
)

Variables

This section is empty.

Functions

func AutoApproveOutcome

AutoApproveOutcome picks the "best" allow option from a permission request and returns a Selected outcome for it. Preference order is allow_always > allow_once > any other option whose Kind starts with "allow_". If no allow option is present, the first option is selected so the agent can make forward progress; if the request carries no options at all, the request is canceled.

pi-go ACP subagents (claude / gemini / cursor) run inside a single user- initiated session that has already been authorized at the parent process boundary, so deferring every tool call back to the user is unnecessary noise. Routing all requests through this helper keeps that policy in one place.

func EnrichToolCallTitle

func EnrichToolCallTitle(title string, rawInput any) string

EnrichToolCallTitle returns a title that combines the agent-provided display title with a short snippet pulled from RawInput. ACP agents often send generic titles like "Terminal", "TaskOutput", or "Read" with the real detail (the command, the file path, the task description) buried in RawInput, which produces a stream of unhelpful "TaskOutput / TaskOutput / TaskOutput" lines in the parent UI. Pulling the first useful field out of RawInput restores per-call context.

If RawInput is nil or carries no recognizable string field, the original title is returned unchanged.

Types

type Event

type Event struct {
	Type      string `json:"type"`
	Content   string `json:"content,omitempty"`
	Error     string `json:"error,omitempty"`
	SessionID string `json:"session_id,omitempty"`
}

Event is the shared local streaming model for ACP updates.

func (Event) Validate

func (e Event) Validate() error

Validate checks whether the event carries a supported type and payload.

type RunRequest

type RunRequest struct {
	Command    []string
	Prompt     string
	SessionID  string
	CWD        string
	Env        []string
	RPCTimeout time.Duration
}

RunRequest describes a local ACP turn request shared by client and server code.

func (RunRequest) Validate

func (r RunRequest) Validate() error

Validate checks whether the request has the required fields for execution.

type RunResult

type RunResult struct {
	Status     string `json:"status"`
	Result     string `json:"result,omitempty"`
	Error      string `json:"error,omitempty"`
	SessionID  string `json:"session_id,omitempty"`
	Stderr     string `json:"stderr,omitempty"`     // Captured subprocess stderr for diagnostics
	StopReason string `json:"stopReason,omitempty"` // ACP stopReason from PromptResponse
}

RunResult is the shared local result model for ACP executions.

func (RunResult) Validate

func (r RunResult) Validate() error

Validate checks whether the result carries a supported terminal status.

type ToolCallTitleFilter

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

ToolCallTitleFilter dedupes tool-call title emissions per tool_call_id.

Most ACP agents send a generic ToolCall first (Title: "Terminal", "Read", "Bash") and then a ToolCallUpdate with a far more useful Title (the actual command, file path, etc.). Streaming both produces redundant lines like:

  • Terminal
  • `go test ./internal/acp/... 2>&1`

This filter buffers the initial title; if a ToolCallUpdate arrives for the same id with a non-empty title, the buffered title is dropped and only the update's title is emitted. If no update ever arrives (rare), Flush emits the buffered title at session end so the call is still visible.

func NewToolCallTitleFilter

func NewToolCallTitleFilter(emit func(title string)) *ToolCallTitleFilter

NewToolCallTitleFilter wires the filter to the per-session emit callback. emit is invoked with the chosen title each time the filter decides to surface one — the caller is responsible for wrapping it in the appropriate event.

func (*ToolCallTitleFilter) Flush

func (f *ToolCallTitleFilter) Flush()

Flush emits any pending titles whose tool calls produced no update before the session ended. Safe to call multiple times.

func (*ToolCallTitleFilter) OnToolCall

func (f *ToolCallTitleFilter) OnToolCall(id, title string)

OnToolCall records an initial tool-call title without emitting it. Empty titles are ignored. If id is empty the title is emitted immediately, since without an id we cannot correlate a later update.

func (*ToolCallTitleFilter) OnToolCallUpdate

func (f *ToolCallTitleFilter) OnToolCallUpdate(id, title string)

OnToolCallUpdate emits the update's title (when non-empty) and forgets any buffered initial title for the same id. If the update carries no title and nothing is pending, this is a no-op.

type ValidationError

type ValidationError string

func (ValidationError) Error

func (e ValidationError) Error() string

Directories

Path Synopsis
claudecode
Package claudecode provides an ACP client for Claude Code via the @agentclientprotocol/claude-agent-acp subprocess adapter.
Package claudecode provides an ACP client for Claude Code via the @agentclientprotocol/claude-agent-acp subprocess adapter.
cursor
Package cursor provides an ACP client for Cursor CLI via its `agent acp` subprocess (https://cursor.com/docs/cli/acp).
Package cursor provides an ACP client for Cursor CLI via its `agent acp` subprocess (https://cursor.com/docs/cli/acp).
gemini
Package gemini provides an ACP client for Google Gemini CLI via the Gemini CLI subprocess adapter.
Package gemini provides an ACP client for Google Gemini CLI via the Gemini CLI subprocess adapter.
adapter
Package adapter translates pi runtime (ADK) events into ACP session updates.
Package adapter translates pi runtime (ADK) events into ACP session updates.

Jump to

Keyboard shortcuts

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