Documentation
¶
Overview ¶
Package nanocodexacp exposes the Nanocodex Rust agent library through ACP.
Serve runs the protocol over caller-supplied streams. The adapter launches acp-go-nanocodex-native with the session workspace and environment for each prompt. WithExecutablePath selects the helper; WithHome selects its native configuration root. Build and install the Rust helper separately when using go get or go install; make build stages both executables under bin/.
WithSessionStore selects the authoritative store for native rollout rows and session configuration. Its default is a fresh in-memory store. Native files remain available after closing the adapter.
Authentication belongs to the native runtime. Configure OPENAI_API_KEY or native auth.json credentials through the inherited environment and home.
Index ¶
- Constants
- func HelperRelease() (version, fingerprint string)
- func Serve(ctx context.Context, input io.Reader, output io.Writer, opts ...Option) (returnErr error)
- func SetModelRequest(sessionID acp.SessionId, model string) acp.SetSessionConfigOptionRequest
- func ValidateNanocodexSessionMeta(meta map[string]any) error
- func WithSessionNanocodexOptions(options NanocodexOptions) wire.SessionRequestOption
- func WithSessionRawEvents(enabled bool) wire.SessionRequestOption
- type Agent
- func (a *Agent) Authenticate(_ context.Context, p acp.AuthenticateRequest) (acp.AuthenticateResponse, error)
- func (a *Agent) Cancel(_ context.Context, p acp.CancelNotification) error
- func (a *Agent) Close() error
- func (a *Agent) CloseSession(ctx context.Context, p acp.CloseSessionRequest) (acp.CloseSessionResponse, error)
- func (a *Agent) HandleExtensionMethod(_ context.Context, method string, _ json.RawMessage) (any, error)
- func (a *Agent) Initialize(ctx context.Context, p acp.InitializeRequest) (resp acp.InitializeResponse, err error)
- func (a *Agent) ListSessions(ctx context.Context, p acp.ListSessionsRequest) (acp.ListSessionsResponse, error)
- func (a *Agent) LoadSession(ctx context.Context, p acp.LoadSessionRequest) (acp.LoadSessionResponse, error)
- func (a *Agent) Logout(_ context.Context, p acp.LogoutRequest) (acp.LogoutResponse, error)
- func (a *Agent) NewSession(ctx context.Context, p acp.NewSessionRequest) (resp acp.NewSessionResponse, err error)
- func (a *Agent) Prompt(ctx context.Context, p acp.PromptRequest) (resp acp.PromptResponse, err error)
- func (a *Agent) ResumeSession(ctx context.Context, p acp.ResumeSessionRequest) (acp.ResumeSessionResponse, error)
- func (a *Agent) SetSessionConfigOption(ctx context.Context, params acp.SetSessionConfigOptionRequest) (acp.SetSessionConfigOptionResponse, error)
- func (a *Agent) SetSessionMode(_ context.Context, p acp.SetSessionModeRequest) (acp.SetSessionModeResponse, error)
- func (a *Agent) UnstableDeleteSession(ctx context.Context, p acp.UnstableDeleteSessionRequest) (acp.UnstableDeleteSessionResponse, error)
- type ConcurrencyLimits
- type ImageLimits
- type NanocodexOption
- func WithNanocodexAPIBaseURL(baseURL string) NanocodexOption
- func WithNanocodexAPIKeyEnv(name string) NanocodexOption
- func WithNanocodexAuthFile(path string) NanocodexOption
- func WithNanocodexBaseModel(model string) NanocodexOption
- func WithNanocodexContextWindow(tokens int64) NanocodexOption
- func WithNanocodexEnv(env map[string]string) NanocodexOption
- func WithNanocodexExtraPathDirs(dirs ...string) NanocodexOption
- func WithNanocodexModel(model string) NanocodexOption
- func WithNanocodexModelIDPrefix(prefix string) NanocodexOption
- func WithNanocodexShellEnv(names ...string) NanocodexOption
- func WithNanocodexThinking(thinking string) NanocodexOption
- func WithNanocodexTransport(transport string) NanocodexOption
- func WithNanocodexWebsocketURL(endpoint string) NanocodexOption
- type NanocodexOptions
- type Option
- func WithAgentName(name string) Option
- func WithAgentTitle(title string) Option
- func WithAgentVersion(version string) Option
- func WithConcurrencyLimits(limits ConcurrencyLimits) Option
- func WithConfiguredModels(ids []string) 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 WithScratchDir(dir string) Option
- func WithSeedFiles(files map[string]string) Option
- func WithSessionStore(store acpcore.SessionStore) Option
- func WithTextMapPropagator(propagator propagation.TextMapPropagator) Option
- func WithTracerProvider(provider trace.TracerProvider) Option
- type Options
Examples ¶
Constants ¶
const ( // RawEventMethod delivers opted-in native events during live turns. RawEventMethod = "_nanocodex/rawEvent" // SessionStoreFormat identifies native rollout rows and their configuration. SessionStoreFormat = "nanocodex-rollout-jsonl-v1" )
Variables ¶
This section is empty.
Functions ¶
func HelperRelease ¶
func HelperRelease() (version, fingerprint string)
HelperRelease returns the helper release and build-input fingerprint that initialization requires from the helper executable.
func Serve ¶
func Serve(ctx context.Context, input io.Reader, output io.Writer, opts ...Option) (returnErr error)
Serve runs ACP over the supplied streams and joins native cleanup on exit.
Example (Initialize) ¶
package main
import (
"bufio"
"context"
"encoding/json"
"fmt"
"io"
nanocodexacp "github.com/savid/acp-go-nanocodex"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
clientReader, clientWriter := io.Pipe()
agentReader, agentWriter := io.Pipe()
defer clientReader.Close()
defer clientWriter.Close()
defer agentReader.Close()
defer agentWriter.Close()
done := make(chan error, 1)
go func() {
defer agentWriter.Close()
done <- nanocodexacp.Serve(ctx, clientReader, agentWriter)
}()
_, _ = fmt.Fprintln(clientWriter,
`{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":1}}`)
line, _ := bufio.NewReader(agentReader).ReadString('\n')
cancel()
_ = clientWriter.Close()
<-done
var response struct {
Result struct {
AuthMethods []any `json:"authMethods"`
AgentCapabilities struct {
LoadSession bool `json:"loadSession"`
PromptCapabilities struct {
Image bool `json:"image"`
} `json:"promptCapabilities"`
} `json:"agentCapabilities"`
} `json:"result"`
}
_ = json.Unmarshal([]byte(line), &response)
fmt.Println(len(response.Result.AuthMethods))
fmt.Println(response.Result.AgentCapabilities.LoadSession)
fmt.Println(response.Result.AgentCapabilities.PromptCapabilities.Image)
}
Output: 0 true true
func SetModelRequest ¶
func SetModelRequest(sessionID acp.SessionId, model string) acp.SetSessionConfigOptionRequest
SetModelRequest constructs a model selector update.
func ValidateNanocodexSessionMeta ¶
ValidateNanocodexSessionMeta runs the owned-namespace parsing of a session lifecycle request's _meta without an Agent and returns the same refusal.
func WithSessionNanocodexOptions ¶
func WithSessionNanocodexOptions(options NanocodexOptions) wire.SessionRequestOption
WithSessionNanocodexOptions merges Nanocodex-specific options into _meta.nanocodex.options.
func WithSessionRawEvents ¶
func WithSessionRawEvents(enabled bool) wire.SessionRequestOption
WithSessionRawEvents toggles raw Nanocodex event emission for the session.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent exposes the Nanocodex agent library through its native Rust helper.
func (*Agent) Authenticate ¶
func (a *Agent) Authenticate(_ context.Context, p acp.AuthenticateRequest) (acp.AuthenticateResponse, error)
Authenticate leaves native credential management outside ACP.
func (*Agent) Cancel ¶
Cancel silently ignores unknown sessions and cancels only the addressed turn.
func (*Agent) CloseSession ¶
func (a *Agent) CloseSession(ctx context.Context, p acp.CloseSessionRequest) (acp.CloseSessionResponse, error)
CloseSession releases the addressed session while preserving its native state.
func (*Agent) HandleExtensionMethod ¶
func (a *Agent) HandleExtensionMethod(_ context.Context, method string, _ json.RawMessage) (any, error)
HandleExtensionMethod refuses inbound extension methods.
func (*Agent) Initialize ¶
func (a *Agent) Initialize(ctx context.Context, p acp.InitializeRequest) (resp acp.InitializeResponse, err error)
Initialize advertises the implemented ACP surfaces and prompt-contained lifecycle.
func (*Agent) ListSessions ¶
func (a *Agent) ListSessions(ctx context.Context, p acp.ListSessionsRequest) (acp.ListSessionsResponse, error)
ListSessions lists only live generations from the authoritative session store.
func (*Agent) LoadSession ¶
func (a *Agent) LoadSession(ctx context.Context, p acp.LoadSessionRequest) (acp.LoadSessionResponse, error)
LoadSession restores native state and replays the conversation to the client.
func (*Agent) Logout ¶
func (a *Agent) Logout(_ context.Context, p acp.LogoutRequest) (acp.LogoutResponse, error)
Logout is not supported by this adapter.
func (*Agent) NewSession ¶
func (a *Agent) NewSession(ctx context.Context, p acp.NewSessionRequest) (resp acp.NewSessionResponse, err error)
NewSession creates native state and publishes its first durable generation.
func (*Agent) Prompt ¶
func (a *Agent) Prompt(ctx context.Context, p acp.PromptRequest) (resp acp.PromptResponse, err error)
Prompt retains foreground ownership through persistence and terminal publication.
func (*Agent) ResumeSession ¶
func (a *Agent) ResumeSession(ctx context.Context, p acp.ResumeSessionRequest) (acp.ResumeSessionResponse, error)
ResumeSession restores native state without replaying it to the client.
func (*Agent) SetSessionConfigOption ¶
func (a *Agent) SetSessionConfigOption(ctx context.Context, params acp.SetSessionConfigOptionRequest) (acp.SetSessionConfigOptionResponse, error)
SetSessionConfigOption validates native selectors and commits their configuration.
func (*Agent) SetSessionMode ¶
func (a *Agent) SetSessionMode(_ context.Context, p acp.SetSessionModeRequest) (acp.SetSessionModeResponse, error)
SetSessionMode is required by the SDK but no session modes are advertised.
func (*Agent) UnstableDeleteSession ¶
func (a *Agent) UnstableDeleteSession(ctx context.Context, p acp.UnstableDeleteSessionRequest) (acp.UnstableDeleteSessionResponse, error)
UnstableDeleteSession tombstones store state before retiring a loaded session.
type ConcurrencyLimits ¶
ConcurrencyLimits controls per-agent backpressure. Zero fields use defaults.
type ImageLimits ¶
type ImageLimits struct {
MaxInputBytesPerImage int64
MaxInputBytesPerPrompt int64
MaxOutputBytesPerImage int64
MaxOutputBytesPerToolCall int64
}
ImageLimits bounds decoded image bytes. A zero field disables that policy limit; the frame clamp still applies.
type NanocodexOption ¶
type NanocodexOption func(*NanocodexOptions)
NanocodexOption configures per-session native options.
func WithNanocodexAPIBaseURL ¶
func WithNanocodexAPIBaseURL(baseURL string) NanocodexOption
WithNanocodexAPIBaseURL selects the provider's API base URL.
func WithNanocodexAPIKeyEnv ¶
func WithNanocodexAPIKeyEnv(name string) NanocodexOption
WithNanocodexAPIKeyEnv selects the inherited environment variable containing a key.
func WithNanocodexAuthFile ¶
func WithNanocodexAuthFile(path string) NanocodexOption
WithNanocodexAuthFile selects a native authentication file.
func WithNanocodexBaseModel ¶ added in v0.3.0
func WithNanocodexBaseModel(model string) NanocodexOption
WithNanocodexBaseModel selects the native model whose settings a gateway model uses.
func WithNanocodexContextWindow ¶ added in v0.3.0
func WithNanocodexContextWindow(tokens int64) NanocodexOption
WithNanocodexContextWindow sets the token window used for context accounting, usage size, and compaction.
func WithNanocodexEnv ¶
func WithNanocodexEnv(env map[string]string) NanocodexOption
WithNanocodexEnv sets the session environment overlay.
func WithNanocodexExtraPathDirs ¶
func WithNanocodexExtraPathDirs(dirs ...string) NanocodexOption
WithNanocodexExtraPathDirs prepends the ordered directories to the session PATH.
func WithNanocodexModel ¶
func WithNanocodexModel(model string) NanocodexOption
WithNanocodexModel selects a native model ID, or a gateway model ID on a configured gateway route.
func WithNanocodexModelIDPrefix ¶
func WithNanocodexModelIDPrefix(prefix string) NanocodexOption
WithNanocodexModelIDPrefix selects a gateway namespace for native model IDs.
func WithNanocodexShellEnv ¶ added in v0.5.0
func WithNanocodexShellEnv(names ...string) NanocodexOption
WithNanocodexShellEnv names variables of the helper's environment that the tool shell receives even though the shell's sensitive-name filter would strip them. Each helper launch reads the values and skips unset names. Without names it withholds every sensitive variable and ignores NANOCODEX_SHELL_ENV.
func WithNanocodexThinking ¶
func WithNanocodexThinking(thinking string) NanocodexOption
WithNanocodexThinking selects a native reasoning effort.
func WithNanocodexTransport ¶
func WithNanocodexTransport(transport string) NanocodexOption
WithNanocodexTransport selects https or websocket transport.
func WithNanocodexWebsocketURL ¶
func WithNanocodexWebsocketURL(endpoint string) NanocodexOption
WithNanocodexWebsocketURL overrides the Responses WebSocket endpoint.
type NanocodexOptions ¶
type NanocodexOptions struct {
Model string `json:"model,omitempty"`
Env map[string]string `json:"env,omitempty"`
ExtraPathDirs []string `json:"extraPathDirs,omitempty"`
// BaseModel is the native model whose settings a gateway model uses.
BaseModel string `json:"baseModel,omitempty"`
// ContextWindow is the token window used for context accounting, usage
// size, and compaction; zero leaves the helper's environment value or the
// model default.
ContextWindow int64 `json:"contextWindow,omitempty"`
Thinking string `json:"thinking,omitempty"`
APIBaseURL string `json:"apiBaseUrl,omitempty"`
WebsocketURL string `json:"websocketUrl,omitempty"`
ModelIDPrefix string `json:"modelIdPrefix,omitempty"`
Transport string `json:"transport,omitempty"`
APIKeyEnv string `json:"apiKeyEnv,omitempty"`
AuthFile string `json:"authFile,omitempty"`
// ShellEnv names variables of the helper's environment that the tool
// shell receives even though their names look sensitive. Nil leaves
// NANOCODEX_SHELL_ENV in effect; an empty list withholds every name.
ShellEnv []string `json:"shellEnv,omitzero"`
}
NanocodexOptions selects one native agent's model, route, and environment.
func NewNanocodexOptions ¶
func NewNanocodexOptions(opts ...NanocodexOption) NanocodexOptions
NewNanocodexOptions constructs independently owned session options.
Example ¶
package main
import (
"fmt"
nanocodexacp "github.com/savid/acp-go-nanocodex"
)
func main() {
options := nanocodexacp.NewNanocodexOptions(
nanocodexacp.WithNanocodexModel("gpt-6.1-sol"),
nanocodexacp.WithNanocodexThinking("medium"),
)
fmt.Println(options.Model)
fmt.Println(options.Thinking)
}
Output: gpt-6.1-sol medium
func (NanocodexOptions) Meta ¶
func (options NanocodexOptions) Meta() map[string]any
Meta returns a fresh owned nanocodex options namespace.
type Option ¶
type Option func(*Options)
Option configures the Nanocodex ACP agent.
func WithAgentName ¶
WithAgentName sets the protocol identifier advertised during ACP initialize.
func WithAgentTitle ¶
WithAgentTitle sets the human-readable agent name advertised during ACP initialize.
func WithAgentVersion ¶
WithAgentVersion sets the agent version advertised during ACP initialize.
func WithConcurrencyLimits ¶
func WithConcurrencyLimits(limits ConcurrencyLimits) Option
WithConcurrencyLimits sets process-local backpressure limits.
func WithConfiguredModels ¶
WithConfiguredModels names the models the host lists explicitly.
func WithDefaultModel ¶
WithDefaultModel selects the model for new sessions.
func WithEnv ¶
WithEnv sets the static agent-scoped environment overlay applied to every Nanocodex helper process after the inherited environment and before the session env.
func WithExecutablePath ¶
WithExecutablePath selects the Nanocodex helper executable.
func WithHome ¶
WithHome sets Nanocodex's native config root, passed to every session as CODEX_HOME.
func WithImageLimits ¶
func WithImageLimits(limits ImageLimits) Option
WithImageLimits bounds decoded image bytes. A zero field disables that policy limit; a negative field fails construction.
func WithInputHandoffRoot ¶
WithInputHandoffRoot sets the absolute directory under which handoff-form prompt images are read. The adapter never writes there.
func WithLogger ¶
WithLogger configures structured diagnostic logging.
func WithMeterProvider ¶
func WithMeterProvider(provider metric.MeterProvider) Option
WithMeterProvider configures the OpenTelemetry meter provider.
func WithScratchDir ¶
WithScratchDir accepts an absolute scratch parent; this adapter allocates no scratch state.
func WithSeedFiles ¶
WithSeedFiles registers files written into Nanocodex's config root before each launch. Keys are paths relative to that root; values are the contents.
func WithSessionStore ¶
func WithSessionStore(store acpcore.SessionStore) Option
WithSessionStore configures the session store.
func WithTextMapPropagator ¶
func WithTextMapPropagator(propagator propagation.TextMapPropagator) Option
WithTextMapPropagator configures trace-context extraction from ACP _meta.
func WithTracerProvider ¶
func WithTracerProvider(provider trace.TracerProvider) Option
WithTracerProvider configures the OpenTelemetry tracer provider.
type Options ¶
type Options struct {
// AgentName is the protocol identifier advertised during ACP initialize.
AgentName string
// AgentTitle is the human-readable agent name advertised during ACP initialize.
AgentTitle string
// AgentVersion is the agent version advertised during ACP initialize.
AgentVersion string
// ExecutablePath selects the Nanocodex helper executable. A bare name is searched on the
// base PATH; a path containing a separator is used as given. Empty means
// "acp-go-nanocodex-native".
ExecutablePath string
// Home is Nanocodex's native config, auth, and runtime root, passed to every
// session as CODEX_HOME. Empty leaves Nanocodex to resolve its home from
// the inherited environment exactly as it would from a shell.
Home string
// ScratchDir accepts an absolute scratch parent. This adapter allocates no
// ephemeral scratch state.
ScratchDir string
// InputHandoffRoot is the absolute directory under which handoff-form
// prompt images are read. Empty rejects the handoff form.
InputHandoffRoot string
// DefaultModel selects the model for new sessions.
DefaultModel string
// ConfiguredModels are the model ids the host lists explicitly.
ConfiguredModels []string
// Env is the static agent-scoped overlay on the inherited process
// environment every Nanocodex helper process runs with.
Env map[string]string
// Logger receives structured diagnostic logs. If nil, the default logger is used.
Logger *slog.Logger
// TracerProvider records adapter spans. If nil, tracing is a no-op.
TracerProvider trace.TracerProvider
// MeterProvider records adapter metrics. If nil, metrics are no-ops.
MeterProvider metric.MeterProvider
// TextMapPropagator extracts trace context from ACP _meta. If nil, W3C
// trace context plus baggage propagation is used.
TextMapPropagator propagation.TextMapPropagator
// SessionStore is the durability boundary for session rows. Nil installs a
// fresh in-memory store.
SessionStore acpcore.SessionStore
// ConcurrencyLimits controls process-local backpressure.
ConcurrencyLimits ConcurrencyLimits
// SeedFiles maps paths relative to Nanocodex's config root to file contents
// written there before each launch.
SeedFiles map[string]string
// ImageLimits bounds decoded image bytes on prompt input and emitted
// output. Every field defaults to 6 MiB when the option is omitted.
ImageLimits ImageLimits
// contains filtered or unexported fields
}
Options configures the ACP agent process and the Nanocodex helper sessions it starts.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
acp-go-nanocodex
command
|
|
|
Package integration holds the tests that run against the Nanocodex helper.
|
Package integration holds the tests that run against the Nanocodex helper. |
|
internal
|
|
|
nanocodex
Package nanocodex implements the private Rust helper protocol.
|
Package nanocodex implements the private Rust helper protocol. |