ampacp

package module
v0.0.0-...-ae65a1c Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: GPL-3.0 Imports: 20 Imported by: 0

README

acp-go-amp

acp-go-amp exposes the Amp CLI as an Agent Client Protocol agent for Go hosts.

The package uses Amp thread IDs as ACP session IDs. session/new creates an empty server-side Amp thread with amp threads new; each prompt starts one short-lived amp threads continue <thread> --stream-json --stream-json-input -x process with isolated native HOME/XDG state, an isolated settings file, and dedicated stdout/stderr pipes.

err := ampacp.Serve(ctx, input, output,
	ampacp.WithExecutablePath("amp"),
	ampacp.WithSessionStore(ampacp.NewInMemorySessionStore()),
)

The session store mirrors Amp stream JSON frames for load replay. local transcript restore is not native thread resurrection: continuation requires the live server-side Amp thread and AMP_API_KEY. If that server-side thread is gone, session/load can still replay local display history and a later prompt returns the native_state_missing terminal error.

Amp does not expose a documented fork or thread-seeding CLI surface, so _amp/session/fork returns the package's unsupported error. Stable session/fork returns method-not-found.

Documentation

Overview

Package ampacp exposes the Amp CLI as an Agent Client Protocol agent.

Hosts embed the package with Serve over caller-owned JSON-RPC streams. The adapter creates Amp threads, continues them with short-lived stream-json processes, mirrors stream frames into a SessionStore, and keeps Amp settings isolated per ACP session.

Index

Constants

View Source
const (
	ForkSessionMethod = "_amp/session/fork"
	RawEventMethod    = "_amp/rawEvent"
)
View Source
const (
	SessionStoreMainSubpath = ""
	SessionStoreFormat      = "amp-thread-mirror-v1"
)

Variables

This section is empty.

Functions

func DeleteSessionRequest

func DeleteSessionRequest(sessionID acp.SessionId) acp.UnstableDeleteSessionRequest

func ForkSessionRequest

func ForkSessionRequest(sessionID acp.SessionId, cwd string, opts ...SessionRequestOption) acp.UnstableForkSessionRequest

func HTTPMCPServer

func HTTPMCPServer(name string, url string, headers map[string]string) acp.McpServer

func LoadSessionRequest

func LoadSessionRequest(sessionID acp.SessionId, cwd string, opts ...SessionRequestOption) acp.LoadSessionRequest

func NewSessionRequest

func NewSessionRequest(cwd string, opts ...SessionRequestOption) acp.NewSessionRequest

func PromptRequest

func PromptRequest(sessionID acp.SessionId, blocks ...acp.ContentBlock) acp.PromptRequest

func ResumeSessionRequest

func ResumeSessionRequest(sessionID acp.SessionId, cwd string, opts ...SessionRequestOption) acp.ResumeSessionRequest

func Serve

func Serve(ctx context.Context, input io.Reader, output io.Writer, opts ...Option) error

func SetModelRequest

func SetModelRequest(sessionID acp.SessionId, model string) acp.SetSessionConfigOptionRequest

func StdioMCPServer

func StdioMCPServer(name string, command string, args []string, env map[string]string) acp.McpServer

func TextPromptRequest

func TextPromptRequest(sessionID acp.SessionId, text string) acp.PromptRequest

Types

type Agent

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

func NewAgent

func NewAgent(opts ...Option) *Agent

func (*Agent) Authenticate

func (a *Agent) Authenticate(ctx context.Context, params acp.AuthenticateRequest) (acp.AuthenticateResponse, error)

func (*Agent) Cancel

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

func (*Agent) Close

func (a *Agent) Close() error

func (*Agent) CloseSession

func (a *Agent) CloseSession(ctx context.Context, params acp.CloseSessionRequest) (acp.CloseSessionResponse, error)

func (*Agent) HandleExtensionMethod

func (a *Agent) HandleExtensionMethod(ctx context.Context, method string, params json.RawMessage) (any, error)

func (*Agent) Initialize

func (a *Agent) Initialize(ctx context.Context, params acp.InitializeRequest) (acp.InitializeResponse, error)

func (*Agent) ListSessions

func (a *Agent) ListSessions(ctx context.Context, params acp.ListSessionsRequest) (acp.ListSessionsResponse, error)

func (*Agent) LoadSession

func (a *Agent) LoadSession(ctx context.Context, params acp.LoadSessionRequest) (acp.LoadSessionResponse, error)

func (*Agent) Logout

func (a *Agent) Logout(ctx context.Context, params acp.LogoutRequest) (acp.LogoutResponse, error)

func (*Agent) NewSession

func (a *Agent) NewSession(ctx context.Context, params acp.NewSessionRequest) (acp.NewSessionResponse, error)

func (*Agent) Prompt

func (a *Agent) Prompt(ctx context.Context, params acp.PromptRequest) (acp.PromptResponse, error)

func (*Agent) ResumeSession

func (a *Agent) ResumeSession(ctx context.Context, params acp.ResumeSessionRequest) (acp.ResumeSessionResponse, error)

func (*Agent) SetSessionMode

func (a *Agent) SetSessionMode(ctx context.Context, params acp.SetSessionModeRequest) (acp.SetSessionModeResponse, error)

type AmpOption

type AmpOption func(*AmpOptions)

AmpOption configures AmpOptions.

func WithAmpEffort

func WithAmpEffort(effort string) AmpOption

func WithAmpEnv

func WithAmpEnv(env map[string]string) AmpOption

func WithAmpMode

func WithAmpMode(mode string) AmpOption

func WithAmpModel

func WithAmpModel(model string) AmpOption

func WithAmpOutputSchema

func WithAmpOutputSchema(schema map[string]any) AmpOption

type AmpOptions

type AmpOptions struct {
	Model        string            `json:"model,omitempty"`
	Env          map[string]string `json:"env,omitempty"`
	OutputSchema map[string]any    `json:"outputSchema,omitempty"`
	Mode         string            `json:"mode,omitempty"`
	Effort       string            `json:"effort,omitempty"`
}

AmpOptions contains per-session Amp configuration accepted under _meta.amp.options.

func NewAmpOptions

func NewAmpOptions(opts ...AmpOption) AmpOptions

func (AmpOptions) Meta

func (options AmpOptions) Meta() map[string]any

type ConcurrencyLimits

type ConcurrencyLimits struct {
	MaxActiveSessions        int
	MaxConcurrentPrompts     int
	MaxConcurrentClientCalls int
}

ConcurrencyLimits configures ACP backpressure limits.

type InMemorySessionStore

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

func NewInMemorySessionStore

func NewInMemorySessionStore() *InMemorySessionStore

func (*InMemorySessionStore) Append

func (s *InMemorySessionStore) Append(ctx context.Context, key SessionKey, entries []SessionStoreEntry) error

func (*InMemorySessionStore) Delete

func (s *InMemorySessionStore) Delete(ctx context.Context, key SessionKey) error

func (*InMemorySessionStore) ListSessions

func (s *InMemorySessionStore) ListSessions(ctx context.Context) ([]SessionSummary, error)

func (*InMemorySessionStore) ListSubkeys

func (s *InMemorySessionStore) ListSubkeys(ctx context.Context, key SessionKey) ([]string, error)

func (*InMemorySessionStore) Load

func (*InMemorySessionStore) Replace

func (s *InMemorySessionStore) Replace(ctx context.Context, main SessionKey, replacements []SessionStoreReplacement) error

type ListSessionsRequestOption

type ListSessionsRequestOption func(*acp.ListSessionsRequest)

func WithListSessionsCursor

func WithListSessionsCursor(cursor string) ListSessionsRequestOption

func WithListSessionsCwd

func WithListSessionsCwd(cwd string) ListSessionsRequestOption

func WithListSessionsMeta

func WithListSessionsMeta(meta map[string]any) ListSessionsRequestOption

type Option

type Option func(*Options)

Option configures an Agent.

func WithAgentName

func WithAgentName(name string) Option

func WithAgentTitle

func WithAgentTitle(title string) Option

func WithAgentVersion

func WithAgentVersion(version string) Option

func WithConcurrencyLimits

func WithConcurrencyLimits(limits ConcurrencyLimits) Option

func WithDefaultModel

func WithDefaultModel(model string) Option

func WithEnv

func WithEnv(env map[string]string) Option

func WithExecutablePath

func WithExecutablePath(path string) Option

func WithHome

func WithHome(path string) Option

func WithLogger

func WithLogger(logger *slog.Logger) Option

func WithMeterProvider

func WithMeterProvider(provider metric.MeterProvider) Option

func WithSessionStore

func WithSessionStore(store SessionStore) Option

func WithSessionStoreLoadTimeout

func WithSessionStoreLoadTimeout(timeout time.Duration) Option

func WithTextMapPropagator

func WithTextMapPropagator(propagator propagation.TextMapPropagator) Option

func WithTracerProvider

func WithTracerProvider(provider trace.TracerProvider) Option

type Options

type Options struct {
	AgentName    string
	AgentTitle   string
	AgentVersion string

	ExecutablePath string
	Home           string
	DefaultModel   string
	Env            map[string]string

	Logger            *slog.Logger
	TracerProvider    trace.TracerProvider
	MeterProvider     metric.MeterProvider
	TextMapPropagator propagation.TextMapPropagator

	SessionStore            SessionStore
	SessionStoreLoadTimeout time.Duration
	ConcurrencyLimits       ConcurrencyLimits
	// contains filtered or unexported fields
}

Options contains package-level agent configuration.

type SessionKey

type SessionKey struct {
	SessionID string
	Subpath   string
}

type SessionRequestOption

type SessionRequestOption func(*sessionRequestConfig)

func WithSessionAdditionalDirectories

func WithSessionAdditionalDirectories(paths ...string) SessionRequestOption

func WithSessionAmpOptions

func WithSessionAmpOptions(options AmpOptions) SessionRequestOption

func WithSessionMCPServers

func WithSessionMCPServers(servers ...acp.McpServer) SessionRequestOption

func WithSessionMeta

func WithSessionMeta(meta map[string]any) SessionRequestOption

func WithSessionOutputSchema

func WithSessionOutputSchema(schema map[string]any) SessionRequestOption

func WithSessionRawEvents

func WithSessionRawEvents(enabled bool) SessionRequestOption

type SessionStore

type SessionStore interface {
	Append(ctx context.Context, key SessionKey, entries []SessionStoreEntry) error
	Load(ctx context.Context, key SessionKey) ([]SessionStoreEntry, error)
	Replace(ctx context.Context, main SessionKey, replacements []SessionStoreReplacement) error
	Delete(ctx context.Context, key SessionKey) error
	ListSessions(ctx context.Context) ([]SessionSummary, error)
	ListSubkeys(ctx context.Context, key SessionKey) ([]string, error)
}

type SessionStoreEntry

type SessionStoreEntry = json.RawMessage

type SessionStoreReplacement

type SessionStoreReplacement struct {
	Key     SessionKey
	Entries []SessionStoreEntry
}

type SessionSummary

type SessionSummary struct {
	SessionID          string
	UpdatedAtUnixMilli int64
	Cwd                string
	Title              string
	Meta               map[string]any
}

Directories

Path Synopsis
cmd
acp-go-amp command
examples
minimal-client command
internal
amp

Jump to

Keyboard shortcuts

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