Documentation
¶
Overview ¶
Package opencodeacp exposes the local OpenCode CLI as an Agent Client Protocol agent.
Most hosts run the agent over a pair of JSON-RPC streams using Serve. Serve launches one authenticated loopback `opencode serve` process owned by the Agent, maps ACP requests into directory-scoped OpenCode REST/SSE calls, and keeps that runtime alive across session close. Hosts must complete ACP initialization before issuing session or other agent methods.
Hosts should use Serve for the JSON-RPC transport; hosts that embed the agent directly construct one with NewAgent and the same Option values. OpenCode authentication and provider credentials remain owned by the local OpenCode installation. WithHome selects the Agent's exclusive shared XDG root. When it is empty, the adapter materializes the root beneath the parent selected by WithScratchDir.
Darwin native startup fails closed unless WithDarwinBestEffortContainment is selected. That option accepts a bounded original-process-group cleanup and direct-child reap; descendants that escape the group can survive, so it is not an authoritative absence proof.
Hosts that need durable remote resume can provide WithSessionStore. A session store receives `opencode-sync-events-v1` native event bundles keyed by the ACP-visible session ID and subpath, can back session/list, and can replay an adopted parent/child graph through OpenCode's online sync API.
Hosts that need structured output can attach OpenCodeOptions with WithSessionOpenCodeOptions or use WithSessionOutputSchema. Parsed response objects are returned under _meta.opencode.structuredOutput.
Hosts can call CallForkSession for the OpenCode fork extension method _opencode/session/fork. Raw OpenCode events are emitted as RawEventMethod notifications only when a session request opts in with WithSessionRawEvents.
Hosts that need adapter telemetry can provide OpenTelemetry providers with WithTracerProvider and WithMeterProvider. The package never configures global OpenTelemetry providers; the acp-go-opencode binary handles env-based exporter setup for command-line use. Caller-supplied providers remain owned by the caller, including ForceFlush and Shutdown.
Index ¶
- Constants
- Variables
- func CallForkSession(ctx context.Context, conn *acp.ClientSideConnection, ...) (acp.UnstableForkSessionResponse, error)
- func CancelRequest(sessionID acp.SessionId, turnNonce string) acp.CancelNotification
- func DeleteSessionRequest(sessionID acp.SessionId) acp.UnstableDeleteSessionRequest
- func ForkSessionRequest(sessionID acp.SessionId, cwd string, opts ...SessionRequestOption) acp.UnstableForkSessionRequest
- func HTTPMCPServer(name string, url string, headers map[string]string) acp.McpServer
- func ListSessionsRequest(opts ...ListSessionsRequestOption) acp.ListSessionsRequest
- func LoadSessionRequest(sessionID acp.SessionId, cwd string, opts ...SessionRequestOption) acp.LoadSessionRequest
- func NewSessionRequest(cwd string, opts ...SessionRequestOption) acp.NewSessionRequest
- func NewTurnNonce() (string, error)
- func PromptRequest(sessionID acp.SessionId, turnNonce string, blocks ...acp.ContentBlock) acp.PromptRequest
- func ResumeSessionRequest(sessionID acp.SessionId, cwd string, opts ...SessionRequestOption) acp.ResumeSessionRequest
- func Serve(ctx context.Context, input io.Reader, output io.Writer, opts ...Option) (serveErr error)
- func SetConfigOptionRequest(sessionID acp.SessionId, configID acp.SessionConfigId, ...) acp.SetSessionConfigOptionRequest
- func SetModelRequest(sessionID acp.SessionId, model string) acp.SetSessionConfigOptionRequest
- func StdioMCPServer(name string, command string, args []string, env map[string]string) acp.McpServer
- func TextPromptRequest(sessionID acp.SessionId, turnNonce, text string) acp.PromptRequest
- type Agent
- func (a *Agent) Authenticate(_ context.Context, params acp.AuthenticateRequest) (acp.AuthenticateResponse, error)
- func (a *Agent) Cancel(ctx context.Context, params acp.CancelNotification) error
- func (a *Agent) Close() error
- func (a *Agent) CloseSession(ctx context.Context, params acp.CloseSessionRequest) (acp.CloseSessionResponse, error)
- func (a *Agent) ContainmentMode() RuntimeContainmentMode
- func (a *Agent) HandleExtensionMethod(ctx context.Context, method string, params json.RawMessage) (any, error)
- func (a *Agent) Initialize(_ context.Context, params acp.InitializeRequest) (acp.InitializeResponse, error)
- func (a *Agent) ListSessions(ctx context.Context, params acp.ListSessionsRequest) (acp.ListSessionsResponse, error)
- func (a *Agent) LoadSession(ctx context.Context, params acp.LoadSessionRequest) (acp.LoadSessionResponse, error)
- func (a *Agent) Logout(context.Context, acp.LogoutRequest) (acp.LogoutResponse, error)
- func (a *Agent) NewSession(ctx context.Context, params acp.NewSessionRequest) (acp.NewSessionResponse, error)
- func (a *Agent) Prompt(ctx context.Context, params acp.PromptRequest) (resp acp.PromptResponse, err error)
- func (a *Agent) ResumeSession(ctx context.Context, params acp.ResumeSessionRequest) (acp.ResumeSessionResponse, error)
- func (a *Agent) SetSessionConfigOption(ctx context.Context, params acp.SetSessionConfigOptionRequest) (acp.SetSessionConfigOptionResponse, error)
- func (a *Agent) SetSessionMode(context.Context, acp.SetSessionModeRequest) (acp.SetSessionModeResponse, error)
- func (a *Agent) UnstableDeleteSession(ctx context.Context, params acp.UnstableDeleteSessionRequest) (acp.UnstableDeleteSessionResponse, error)
- type ConcurrencyLimits
- type ImageLimits
- type InMemorySessionStore
- func (s *InMemorySessionStore) Append(ctx context.Context, key SessionKey, entries []SessionStoreEntry) error
- func (s *InMemorySessionStore) Delete(ctx context.Context, key SessionKey) error
- func (s *InMemorySessionStore) ListSessions(ctx context.Context) ([]SessionSummary, error)
- func (s *InMemorySessionStore) ListSubkeys(ctx context.Context, key SessionKey) ([]string, error)
- func (s *InMemorySessionStore) Load(ctx context.Context, key SessionKey) ([]SessionStoreEntry, error)
- func (s *InMemorySessionStore) Replace(ctx context.Context, main SessionKey, replacements []SessionStoreReplacement) error
- type ListSessionsRequestOption
- type OpenCodeOption
- func WithOpenCodeEnv(env map[string]string) OpenCodeOption
- func WithOpenCodeExtraPathDirs(dirs ...string) OpenCodeOption
- func WithOpenCodeMode(mode string) OpenCodeOption
- func WithOpenCodeModel(model string) OpenCodeOption
- func WithOpenCodeOutputSchema(schema map[string]any) OpenCodeOption
- func WithOpenCodePermission(permission string) OpenCodeOption
- type OpenCodeOptions
- type Option
- func WithAgentName(name string) Option
- func WithAgentTitle(title string) Option
- func WithAgentVersion(version string) Option
- func WithConcurrencyLimits(limits ConcurrencyLimits) Option
- func WithDarwinBestEffortContainment() Option
- func WithDefaultModel(model string) Option
- func WithEnv(env map[string]string) Option
- func WithExecutablePath(path string) Option
- func WithHome(path string) Option
- func WithImageLimits(limits ImageLimits) Option
- func WithInputHandoffRoot(dir string) Option
- func WithLogger(logger *slog.Logger) Option
- func WithMeterProvider(provider metric.MeterProvider) Option
- func WithOpenCodeHealthCheckTimeout(timeout time.Duration) Option
- func WithOpenCodeLogLevel(level string) Option
- func WithOpenCodePure(enabled bool) Option
- func WithOpenCodeQuestionTool(enabled bool) Option
- func WithProcessIsolation(isolation ProcessIsolation) Option
- func WithProviderAuthDirectHome(path string) Option
- func WithProviderAuthRoot(path string) Option
- func WithRuntimeResourceHooks(hooks RuntimeResourceHooks) Option
- func WithScratchDir(dir string) Option
- func WithSeedFiles(files map[string]string) Option
- func WithSessionStore(store SessionStore) Option
- func WithSessionStoreLoadTimeout(timeout time.Duration) Option
- func WithTextMapPropagator(propagator propagation.TextMapPropagator) Option
- func WithTracerProvider(provider trace.TracerProvider) Option
- func WithTurnTimeout(timeout time.Duration) Option
- type Options
- type ProcessIdentityLockCapability
- type ProcessIsolation
- type RuntimeContainmentMode
- type RuntimeProcessKind
- type RuntimeResourceHooks
- type RuntimeResourceKind
- type RuntimeStartupStage
- type SessionKey
- type SessionRequestOption
- func WithSessionAdditionalDirectories(paths ...string) SessionRequestOption
- func WithSessionMCPServers(servers ...acp.McpServer) SessionRequestOption
- func WithSessionMeta(meta map[string]any) SessionRequestOption
- func WithSessionOpenCodeOptions(options OpenCodeOptions) SessionRequestOption
- func WithSessionOutputSchema(schema map[string]any) SessionRequestOption
- func WithSessionRawEvents(enabled bool) SessionRequestOption
- type SessionStore
- type SessionStoreEntry
- type SessionStoreReplacement
- type SessionStoreTerminalState
- type SessionSummary
Examples ¶
Constants ¶
const ( AuthMethodsMethod = "_opencode/auth/methods" AuthAuthorizeMethod = "_opencode/auth/authorize" AuthCallbackMethod = "_opencode/auth/callback" AuthStatusMethod = "_opencode/auth/status" AuthCancelMethod = "_opencode/auth/cancel" AuthInventoryMethod = "_opencode/auth/inventory" AuthDisconnectMethod = "_opencode/auth/disconnect" )
Session-scoped provider-auth extension methods. OpenCode installs a completed credential into its own durable runtime store, so it brokers no credential out and accepts no injection: there is no credential leg and no injection key.
const ( ForkSessionMethod = "_opencode/session/fork" RawEventMethod = "_opencode/rawEvent" )
const ( SessionStoreMainSubpath = "" SessionStoreFormat = "opencode-sync-events-v1" )
Variables ¶
var ErrProcessContainmentIncomplete = opencode.ErrProcessContainmentIncomplete
ErrProcessContainmentIncomplete means the selected native containment boundary did not complete. Callers must keep the runtime quarantined.
Functions ¶
func CallForkSession ¶
func CallForkSession(ctx context.Context, conn *acp.ClientSideConnection, params acp.UnstableForkSessionRequest) (acp.UnstableForkSessionResponse, error)
func CancelRequest ¶
func CancelRequest(sessionID acp.SessionId, turnNonce string) acp.CancelNotification
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 ListSessionsRequest ¶
func ListSessionsRequest(opts ...ListSessionsRequestOption) acp.ListSessionsRequest
func LoadSessionRequest ¶
func LoadSessionRequest(sessionID acp.SessionId, cwd string, opts ...SessionRequestOption) acp.LoadSessionRequest
func NewSessionRequest ¶
func NewSessionRequest(cwd string, opts ...SessionRequestOption) acp.NewSessionRequest
func NewTurnNonce ¶
func PromptRequest ¶
func PromptRequest(sessionID acp.SessionId, turnNonce string, blocks ...acp.ContentBlock) acp.PromptRequest
func ResumeSessionRequest ¶
func ResumeSessionRequest(sessionID acp.SessionId, cwd string, opts ...SessionRequestOption) acp.ResumeSessionRequest
func Serve ¶
Example (Initialize) ¶
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
clientToAgentReader, clientToAgentWriter := io.Pipe()
agentToClientReader, agentToClientWriter := io.Pipe()
defer clientToAgentReader.Close()
defer clientToAgentWriter.Close()
defer agentToClientReader.Close()
defer agentToClientWriter.Close()
done := make(chan error, 1)
go func() {
done <- Serve(ctx, clientToAgentReader, agentToClientWriter)
}()
_, _ = fmt.Fprintln(clientToAgentWriter, `{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":1}}`)
line, _ := bufio.NewReader(agentToClientReader).ReadString('\n')
cancel()
_ = clientToAgentWriter.Close()
<-done
var response struct {
Result struct {
AuthMethods []any `json:"authMethods"`
AgentCapabilities struct {
LoadSession bool `json:"loadSession"`
McpCapabilities struct {
Http bool `json:"http"`
} `json:"mcpCapabilities"`
} `json:"agentCapabilities"`
} `json:"result"`
}
_ = json.Unmarshal([]byte(line), &response)
fmt.Println(len(response.Result.AuthMethods) == 0)
fmt.Println(response.Result.AgentCapabilities.LoadSession)
fmt.Println(response.Result.AgentCapabilities.McpCapabilities.Http)
Output: true true true
func SetConfigOptionRequest ¶
func SetConfigOptionRequest(sessionID acp.SessionId, configID acp.SessionConfigId, value acp.SessionConfigValueId) acp.SetSessionConfigOptionRequest
func SetModelRequest ¶
func SetModelRequest(sessionID acp.SessionId, model string) acp.SetSessionConfigOptionRequest
func StdioMCPServer ¶
func TextPromptRequest ¶
func TextPromptRequest(sessionID acp.SessionId, turnNonce, text string) acp.PromptRequest
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent exposes OpenCode through ACP.
func (*Agent) Authenticate ¶
func (a *Agent) Authenticate(_ context.Context, params acp.AuthenticateRequest) (acp.AuthenticateResponse, error)
func (*Agent) CloseSession ¶
func (a *Agent) CloseSession(ctx context.Context, params acp.CloseSessionRequest) (acp.CloseSessionResponse, error)
func (*Agent) ContainmentMode ¶
func (a *Agent) ContainmentMode() RuntimeContainmentMode
ContainmentMode reports the effective native process boundary.
func (*Agent) HandleExtensionMethod ¶
func (*Agent) Initialize ¶
func (a *Agent) Initialize(_ 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(context.Context, 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) (resp acp.PromptResponse, err error)
func (*Agent) ResumeSession ¶
func (a *Agent) ResumeSession(ctx context.Context, params acp.ResumeSessionRequest) (acp.ResumeSessionResponse, error)
func (*Agent) SetSessionConfigOption ¶
func (a *Agent) SetSessionConfigOption(ctx context.Context, params acp.SetSessionConfigOptionRequest) (acp.SetSessionConfigOptionResponse, error)
func (*Agent) SetSessionMode ¶
func (a *Agent) SetSessionMode(context.Context, acp.SetSessionModeRequest) (acp.SetSessionModeResponse, error)
func (*Agent) UnstableDeleteSession ¶
func (a *Agent) UnstableDeleteSession(ctx context.Context, params acp.UnstableDeleteSessionRequest) (acp.UnstableDeleteSessionResponse, error)
type ConcurrencyLimits ¶
ConcurrencyLimits bounds work accepted by one Agent.
type ImageLimits ¶
type ImageLimits struct {
MaxInputBytesPerImage int64
MaxInputBytesPerPrompt int64
MaxOutputBytesPerImage int64
MaxOutputBytesPerToolCall int64
}
ImageLimits bounds decoded image bytes crossing the ACP boundary. Input fields bound prompt images before a native turn starts; output fields bound emitted image content. A zero field disables that adapter policy limit; it never bypasses hard native framing, provider, or host request limits. Negative fields are rejected when the agent is constructed.
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 (s *InMemorySessionStore) Load(ctx context.Context, key SessionKey) ([]SessionStoreEntry, error)
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 OpenCodeOption ¶
type OpenCodeOption func(*OpenCodeOptions)
func WithOpenCodeEnv ¶
func WithOpenCodeEnv(env map[string]string) OpenCodeOption
WithOpenCodeEnv sets the environment this session's native process runs under, overlaying WithEnv. One native process serves every session of an Agent, so a session asking for an environment the running process was not started under is served by a fresh process, and is refused outright while another session still holds the running one.
func WithOpenCodeExtraPathDirs ¶
func WithOpenCodeExtraPathDirs(dirs ...string) OpenCodeOption
WithOpenCodeExtraPathDirs places absolute directories ahead of the inherited PATH of that process, in the order given. It is the only way to extend the search path: WithOpenCodeEnv rejects PATH because its entries replace whole values.
func WithOpenCodeMode ¶
func WithOpenCodeMode(mode string) OpenCodeOption
func WithOpenCodeModel ¶
func WithOpenCodeModel(model string) OpenCodeOption
func WithOpenCodeOutputSchema ¶
func WithOpenCodeOutputSchema(schema map[string]any) OpenCodeOption
func WithOpenCodePermission ¶
func WithOpenCodePermission(permission string) OpenCodeOption
type OpenCodeOptions ¶
type OpenCodeOptions struct {
Model string `json:"model,omitempty"`
OutputSchema map[string]any `json:"outputSchema,omitempty"`
Mode string `json:"mode,omitempty"`
Permission string `json:"permission,omitempty"`
// Env overlays the agent-wide environment for the native process this
// session runs under. PATH belongs in ExtraPathDirs.
Env map[string]string `json:"env,omitempty"`
// ExtraPathDirs are absolute directories placed ahead of the inherited PATH
// of that process, in order.
ExtraPathDirs []string `json:"extraPathDirs,omitempty"`
}
OpenCodeOptions is the stable OpenCode-specific subset accepted at _meta.opencode.options.
func NewOpenCodeOptions ¶
func NewOpenCodeOptions(opts ...OpenCodeOption) OpenCodeOptions
func (OpenCodeOptions) Meta ¶
func (options OpenCodeOptions) Meta() map[string]any
Meta returns an ACP _meta object for the supported OpenCode-specific options.
type Option ¶
type Option func(*Options)
Option configures the OpenCode ACP agent.
func WithAgentName ¶
func WithAgentTitle ¶
func WithAgentVersion ¶
func WithConcurrencyLimits ¶
func WithConcurrencyLimits(limits ConcurrencyLimits) Option
func WithDarwinBestEffortContainment ¶
func WithDarwinBestEffortContainment() Option
WithDarwinBestEffortContainment explicitly accepts Darwin process-group containment.
func WithDefaultModel ¶
func WithEnv ¶
WithEnv adds ordinary variables to the shared native runtime environment. Managed home, XDG, database, and config roots are rejected during agent initialization.
func WithExecutablePath ¶
func WithImageLimits ¶
func WithImageLimits(limits ImageLimits) Option
WithImageLimits replaces every image byte limit. The supplied struct owns all four fields: an unset field is zero and disables that policy limit.
func WithInputHandoffRoot ¶
WithInputHandoffRoot sets the absolute directory a prompt image may be read from when it arrives in the handoff form: an image block with empty data, a file URI, and a digest envelope. It is a read root only — the wrapper never writes, moves, or deletes anything beneath it, and it materializes nothing, so it carries no scratch semantics. Unset rejects every handoff-form block.
func WithLogger ¶
func WithMeterProvider ¶
func WithMeterProvider(provider metric.MeterProvider) Option
func WithOpenCodeLogLevel ¶
func WithOpenCodePure ¶
func WithProcessIsolation ¶
func WithProcessIsolation(isolation ProcessIsolation) Option
WithProcessIsolation requires every native process to run as the supplied uid/gid with no supplementary groups. BaseEnvironment is the complete native environment base; the adapter never overlays os.Environ.
func WithProviderAuthDirectHome ¶
WithProviderAuthDirectHome names the canonical native home an operator consents to an account-level provider-auth leg reading or clearing. OpenCode removes a credential through a scoped per-provider call, so it has no leg to gate and rejects any configured value at session start.
func WithProviderAuthRoot ¶
WithProviderAuthRoot sets the absolute durable directory holding the values-free provider-auth ledger. It sits outside session scratch, outlives every session and native generation, and carries no config or auth-resolution semantics. Unset — or set alongside no Home — leaves every provider-auth method unadvertised.
func WithRuntimeResourceHooks ¶
func WithRuntimeResourceHooks(hooks RuntimeResourceHooks) Option
func WithScratchDir ¶
WithScratchDir sets the parent directory for all ephemeral on-disk materialization, including a generated shared runtime root. An empty value uses the system temporary directory.
func WithSeedFiles ¶
WithSeedFiles writes immutable bootstrap files into the shared OpenCode runtime config root before launching opencode serve. Keys are paths relative to <XDG_CONFIG_HOME>/opencode/ directory mapped to file contents; absolute paths, parent-directory escapes, and empty keys are rejected. A native-owned durable runtime home accepts only opencode.json, which is delivered through the managed process environment without a privileged write beneath the home. A seeded opencode.json must not contain permission or MCP policy because those values are bound to native sessions and directory scopes respectively. The map is cloned like WithEnv.
func WithSessionStore ¶
func WithSessionStore(store SessionStore) Option
func WithSessionStoreLoadTimeout ¶
WithSessionStoreLoadTimeout bounds session store reads (load, list, and subkey enumeration). Store writes use a separate fixed bound.
func WithTextMapPropagator ¶
func WithTextMapPropagator(propagator propagation.TextMapPropagator) Option
func WithTracerProvider ¶
func WithTracerProvider(provider trace.TracerProvider) Option
func WithTurnTimeout ¶
WithTurnTimeout bounds how long a single prompt turn may run before the wrapper aborts the native turn and fails the prompt with a turn-failure error carrying cause "timeout". The default of 0 disables the deadline.
type Options ¶
type Options struct {
AgentName string
AgentTitle string
AgentVersion string
ExecutablePath string
// Home is the exclusive shared XDG root owned by this Agent runtime. Empty
// creates one beneath ScratchDir.
Home string
// ScratchDir is the parent for a generated shared runtime root and transient
// adapter scratch material. It is never a per-session OpenCode home.
ScratchDir string
// InputHandoffRoot is the only directory a prompt image may be read from.
// Empty rejects the handoff input form outright.
InputHandoffRoot string
// ProviderAuthRoot is the durable host-owned directory holding the
// values-free provider-auth ledger. Empty leaves every provider-auth method
// unadvertised.
ProviderAuthRoot string
// ProviderAuthDirectHome names a canonical native home an account-level
// provider-auth leg may read or clear. OpenCode removes a credential with a
// scoped per-provider call and has no such leg, so a configured value is
// rejected at session start.
ProviderAuthDirectHome string
DefaultModel string
Env map[string]string
ProcessIsolation *ProcessIsolation
Logger *slog.Logger
TracerProvider trace.TracerProvider
MeterProvider metric.MeterProvider
TextMapPropagator propagation.TextMapPropagator
SessionStore SessionStore
SessionStoreLoadTimeout time.Duration
ConcurrencyLimits ConcurrencyLimits
SeedFiles map[string]string
ImageLimits ImageLimits
Pure bool
QuestionTool bool
LogLevel string
HealthCheckTimeout time.Duration
TurnTimeout time.Duration
RuntimeResourceHooks RuntimeResourceHooks
DarwinBestEffortContainment bool
// contains filtered or unexported fields
}
Options configures the ACP agent process and OpenCode sessions it starts.
type ProcessIdentityLockCapability ¶
ProcessIsolation defines the complete operating-system identity and base environment inherited by every native OpenCode process.
type ProcessIsolation ¶
type ProcessIsolation struct {
UID uint32
GID uint32
BaseEnvironment map[string]string
StandaloneOwnerID string
StandaloneStateRoot string
// IdentityLock is an optional trusted-supervisor descriptor for the
// host-global UID lock. Linux supervisors validate it and never expose it to
// the native OpenCode process. Standalone embeddings should leave it nil.
IdentityLock ProcessIdentityLockCapability
AuthorityDomain ProcessIdentityLockCapability
}
type RuntimeContainmentMode ¶
type RuntimeContainmentMode string
RuntimeContainmentMode reports the selected native process boundary.
const ( // RuntimeContainmentAuthoritative identifies a platform proof boundary. RuntimeContainmentAuthoritative RuntimeContainmentMode = "authoritative" // RuntimeContainmentBestEffort identifies explicitly accepted Darwin process-group containment. RuntimeContainmentBestEffort RuntimeContainmentMode = "best_effort" RuntimeContainmentUnavailable RuntimeContainmentMode = "unavailable" )
type RuntimeProcessKind ¶
type RuntimeProcessKind string
const ( RuntimeProcessHomeLockSupervisor RuntimeProcessKind = "home_lock_supervisor" RuntimeProcessProviderDescendant RuntimeProcessKind = "provider_descendant" )
type RuntimeResourceHooks ¶
type RuntimeResourceHooks struct {
AcquireNativeRoot func(context.Context, RuntimeResourceKind) (func(), error)
ReserveScratchRoot func(context.Context, RuntimeResourceKind) (func(), error)
ObserveProcess func(context.Context, RuntimeProcessKind, int64)
ObserveProcessSnapshot func(context.Context, RuntimeProcessKind, int)
ObserveStartupStage func(context.Context, RuntimeResourceKind, RuntimeStartupStage, time.Duration, error)
ObserveContainment func(context.Context, RuntimeContainmentMode)
}
RuntimeResourceHooks lets an embedding worker account for native roots and adapter-created scratch roots in its worker-global permit pools. A nil hook selects the standalone, unbounded controller.
type RuntimeResourceKind ¶
type RuntimeResourceKind string
const ( RuntimeResourceRuntime RuntimeResourceKind = "runtime" RuntimeResourceSession RuntimeResourceKind = "session" RuntimeResourcePrompt RuntimeResourceKind = "prompt" RuntimeResourceDiscovery RuntimeResourceKind = "discovery" )
type RuntimeStartupStage ¶
type RuntimeStartupStage string
const ( RuntimeStartupSpawn RuntimeStartupStage = "spawn" RuntimeStartupReadiness RuntimeStartupStage = "readiness" RuntimeStartupConfiguration RuntimeStartupStage = "configuration" RuntimeStartupSession RuntimeStartupStage = "session" )
type SessionKey ¶
type SessionRequestOption ¶
type SessionRequestOption func(*sessionRequestConfig)
func WithSessionAdditionalDirectories ¶
func WithSessionAdditionalDirectories(paths ...string) SessionRequestOption
func WithSessionMCPServers ¶
func WithSessionMCPServers(servers ...acp.McpServer) SessionRequestOption
func WithSessionMeta ¶
func WithSessionMeta(meta map[string]any) SessionRequestOption
func WithSessionOpenCodeOptions ¶
func WithSessionOpenCodeOptions(options OpenCodeOptions) 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 SessionStoreTerminalState ¶
type SessionStoreTerminalState struct {
MessageID string
}
SessionStoreTerminalState is the provider-native terminal identity recovered from one committed opencode-sync-events-v1 snapshot entry.
func InspectSessionStoreTerminalState ¶
func InspectSessionStoreTerminalState( logicalSessionID string, entries []SessionStoreEntry, ) (SessionStoreTerminalState, error)
InspectSessionStoreTerminalState validates the current-format snapshot for logicalSessionID and returns its latest finished assistant message. The snapshot owns the private native aggregate identity; callers do not need to know it. OpenCode may append repeated user-message events after the terminal assistant; those events are intentionally not terminal state.
A valid snapshot with no terminal assistant returns the zero state. Invalid cardinality, JSON, snapshot formats, message events, and aggregate ordering fail closed.
Source Files
¶
- agent.go
- agent_connection.go
- agent_goroutine.go
- agent_route.go
- agent_runtime.go
- agent_runtime_containment.go
- agent_runtime_observation.go
- agent_runtime_recovery.go
- agent_runtime_resources.go
- agent_session.go
- auth.go
- auth_admission.go
- auth_broker.go
- auth_catalog.go
- auth_flows.go
- auth_ledger.go
- doc.go
- ids.go
- image_artifacts.go
- image_handoff.go
- image_handoff_unix.go
- image_input.go
- image_limits.go
- image_output.go
- image_raster.go
- native_path_ownership.go
- native_path_ownership_linux.go
- options.go
- process_tree.go
- raw_events.go
- request_builders.go
- scratch.go
- session.go
- session_config.go
- session_meta.go
- session_prompt.go
- session_restore_ownership.go
- session_state_store.go
- session_store.go
- session_store_terminal.go
- session_validation.go
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
acp-go-opencode
command
|
|
|
examples
|
|
|
interactive-chat
command
|
|
|
minimal-client
command
|
|
|
resume-from-file
command
|
|
|
internal
|
|