Documentation
¶
Index ¶
- func Serve(ctx context.Context, cfg ServeConfig) error
- type Agent
- func (a *Agent) Authenticate(context.Context, acp.AuthenticateRequest) (acp.AuthenticateResponse, error)
- func (a *Agent) Cancel(_ context.Context, params acp.CancelNotification) error
- func (a *Agent) Initialize(context.Context, acp.InitializeRequest) (acp.InitializeResponse, error)
- func (a *Agent) ListSessions(context.Context, acp.ListSessionsRequest) (acp.ListSessionsResponse, error)
- func (a *Agent) LoadSession(_ context.Context, params acp.LoadSessionRequest) (acp.LoadSessionResponse, error)
- func (a *Agent) NewSession(_ context.Context, params acp.NewSessionRequest) (acp.NewSessionResponse, error)
- func (a *Agent) Prompt(ctx context.Context, params acp.PromptRequest) (acp.PromptResponse, error)
- func (a *Agent) SetAgentConnection(conn *acp.AgentSideConnection)
- func (a *Agent) SetSessionConfigOption(context.Context, acp.SetSessionConfigOptionRequest) (acp.SetSessionConfigOptionResponse, error)
- func (a *Agent) SetSessionMode(context.Context, acp.SetSessionModeRequest) (acp.SetSessionModeResponse, error)
- type PromptHandler
- type PromptResult
- type PromptTurn
- type RuntimeConfig
- type ServeConfig
- type SessionUpdater
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Agent ¶
type Agent struct {
// AgentInfo advertises pi to the peer during initialize.
AgentInfo acp.Implementation
// Handler processes one prompt turn. If nil, EchoPromptHandler is used.
Handler PromptHandler
// contains filtered or unexported fields
}
Agent implements acp.Agent for pi. The zero value is a usable skeleton that accepts prompts and echoes them back through EchoPromptHandler.
func (*Agent) Authenticate ¶
func (a *Agent) Authenticate(context.Context, acp.AuthenticateRequest) (acp.AuthenticateResponse, error)
Authenticate always succeeds; pi does not require ACP-level authentication.
func (*Agent) Cancel ¶
Cancel routes an ACP cancel notification to the in-flight Prompt for the session, if any, by canceling the context passed to its PromptHandler. If no prompt is running for the id, the notification is silently dropped — ACP cancellation is best-effort per spec.
func (*Agent) Initialize ¶
func (a *Agent) Initialize(context.Context, acp.InitializeRequest) (acp.InitializeResponse, error)
Initialize advertises pi's baseline capabilities.
func (*Agent) ListSessions ¶
func (a *Agent) ListSessions(context.Context, acp.ListSessionsRequest) (acp.ListSessionsResponse, error)
ListSessions is not yet supported; advertise method-not-found so clients can detect capability absence.
func (*Agent) LoadSession ¶
func (a *Agent) LoadSession(_ context.Context, params acp.LoadSessionRequest) (acp.LoadSessionResponse, error)
LoadSession binds the supplied session id to this agent with the given cwd. If the id is unknown (e.g. the client is resuming a persisted session id against a fresh agent process), a new state record is created so subsequent Prompt calls succeed. Loading is idempotent — repeated loads simply refresh the session's cwd.
func (*Agent) NewSession ¶
func (a *Agent) NewSession(_ context.Context, params acp.NewSessionRequest) (acp.NewSessionResponse, error)
NewSession registers a new session and returns its identifier.
func (*Agent) Prompt ¶
func (a *Agent) Prompt(ctx context.Context, params acp.PromptRequest) (acp.PromptResponse, error)
Prompt bridges a prompt request through the configured handler and, on success, streams the final reply as a single AgentMessageText update. The handler is invoked with a cancelable context registered on the session so an inbound ACP Cancel notification can abort the in-flight turn.
func (*Agent) SetAgentConnection ¶
func (a *Agent) SetAgentConnection(conn *acp.AgentSideConnection)
SetAgentConnection wires the agent-side connection after construction so Prompt handlers can stream updates. Called from Serve; tests may skip it.
func (*Agent) SetSessionConfigOption ¶
func (a *Agent) SetSessionConfigOption(context.Context, acp.SetSessionConfigOptionRequest) (acp.SetSessionConfigOptionResponse, error)
SetSessionConfigOption is not yet supported.
func (*Agent) SetSessionMode ¶
func (a *Agent) SetSessionMode(context.Context, acp.SetSessionModeRequest) (acp.SetSessionModeResponse, error)
SetSessionMode is not yet supported; Slice 10 wires mode flows.
type PromptHandler ¶
type PromptHandler func(ctx context.Context, turn PromptTurn) (PromptResult, error)
PromptHandler runs one ACP prompt turn for a session. The skeleton uses EchoPromptHandler; the real pi runtime is plugged in behind this seam by later slices.
func NewPromptHandler ¶
func NewPromptHandler(rt RuntimeConfig) PromptHandler
NewPromptHandler returns a real pi-backed ACP prompt handler.
type PromptResult ¶
type PromptResult struct {
FinalText string
StopReason acp.StopReason
}
PromptResult is the adapter output returned from a PromptHandler.
func EchoPromptHandler ¶
func EchoPromptHandler(_ context.Context, turn PromptTurn) (PromptResult, error)
EchoPromptHandler is the default PromptHandler used when none is configured. It returns a deterministic "echo: <prompt>" reply so the skeleton is independently testable without the pi runtime.
type PromptTurn ¶
type PromptTurn struct {
SessionID string
CWD string
Prompt string
Updater SessionUpdater
}
PromptTurn is the adapter input handed to a PromptHandler.
type RuntimeConfig ¶
type RuntimeConfig struct {
Model string
BaseURL string
Headers []string
Insecure bool
System string
LoadConfig func() (config.Config, error)
SandboxRootFunc func(turn PromptTurn) string
}
RuntimeConfig controls how the ACP prompt handler resolves and builds the pi runtime.
type ServeConfig ¶
type ServeConfig struct {
// Agent is the pi ACP agent. Required.
Agent *Agent
// In is the byte stream from the ACP client. Typically os.Stdin.
In io.Reader
// Out is the byte stream to the ACP client. Typically os.Stdout.
Out io.Writer
// Logger receives diagnostic output from the ACP connection. Optional.
Logger *slog.Logger
}
ServeConfig configures a server.Serve run.
type SessionUpdater ¶
type SessionUpdater interface {
Update(ctx context.Context, update acp.SessionUpdate) error
}
SessionUpdater streams session updates back to the ACP peer. A nil Updater silently discards updates so PromptHandlers work both with and without a live connection (tests vs. live serve).