server

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: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiscoverAvailableCommands added in v0.0.25

func DiscoverAvailableCommands(cwd string) []acp.AvailableCommand

DiscoverAvailableCommands resolves slash commands for a specific session cwd. User skills are always included, while project skills are discovered from the nearest ancestor directories of the session working directory.

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
	// AvailableCommandsResolver resolves slash commands for a session cwd.
	// If nil, the agent falls back to the static Skills/Subagents slices.
	AvailableCommandsResolver func(cwd string) []acp.AvailableCommand
	// Skills are the loaded skill definitions used to populate AvailableCommands.
	Skills []extension.Skill
	// Subagents are the loaded sub-agent definitions used to populate AvailableCommands.
	Subagents []subagent.AgentConfig
	// Logger is used for diagnostic output. If nil, a discard logger is used.
	Logger *slog.Logger
	// 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. EmbeddedContext is on so Zed can inline file context; Image defaults to false until zed-09 wires the provider gate.

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. Handlers own all session-update emission through turn.Updater; Prompt itself does not emit an AgentMessageText summary, avoiding the duplicate-message bug. The handler runs under a cancelable context registered on the session so an inbound ACP Cancel notification can abort the in-flight turn. When the request carries a MessageId it is echoed back as UserMessageId.

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. It maintains a per-ACP-session cache so the pi agent (and its ADK session history) is reused across turns rather than re-created on every prompt.

type PromptResult

type PromptResult struct {
	FinalText  string
	StopReason acp.StopReason
}

PromptResult is the adapter output returned from a PromptHandler.

func EchoPromptHandler

func EchoPromptHandler(ctx context.Context, turn PromptTurn) (PromptResult, error)

EchoPromptHandler is the default PromptHandler used when none is configured. It streams a deterministic "echo: <prompt>" reply through the turn's updater and returns the same text as PromptResult.FinalText. The stream is the sole emission surface so Prompt no longer needs to re-send FinalText.

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

Directories

Path Synopsis
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