server

package
v0.0.24 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Serve

func Serve(ctx context.Context, cfg ServeConfig) error

Serve runs pi as an ACP agent over the given byte streams and returns when the peer disconnects or ctx is canceled. Serve does not close In or Out; callers own the streams.

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

Authenticate always succeeds; pi does not require ACP-level authentication.

func (*Agent) Cancel

func (a *Agent) Cancel(_ context.Context, params acp.CancelNotification) error

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

Initialize advertises pi's baseline capabilities.

func (*Agent) ListSessions

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

SetSessionConfigOption is not yet supported.

func (*Agent) SetSessionMode

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).

Jump to

Keyboard shortcuts

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