Documentation
¶
Overview ¶
Package config loads and validates the gateway configuration from environment variables.
All gateway variables use the NATIVE_AGENT_ prefix and are parsed with caarlos0/env. The configuration is read exactly once at startup and is immutable afterwards: there is no reload, no file watching and no API that changes it. Agent processes never inherit the gateway environment.
One server process serves exactly one agent selected by NATIVE_AGENT_AGENT.
Index ¶
Constants ¶
const EnvPrefix = "NATIVE_AGENT_"
EnvPrefix is the prefix shared by every gateway environment variable.
const MinTokenLength = 32
MinTokenLength is the minimum accepted plain API token length.
const ProfileNative = "native"
ProfileNative selects the native CLI's own default profile location under HOME.
Variables ¶
This section is empty.
Functions ¶
func MergeFile ¶
MergeFile reads an explicit application env file, then overlays processEnv. It does not perform interpolation, command substitution, file discovery, or fallback lookup.
func PrepareDataDir ¶
PrepareDataDir creates the maintenance working directory (mode 0700) and its parents.
Types ¶
type Auth ¶
type Auth struct {
Enabled bool
TokenHash [sha256.Size]byte
// PlainToken reports that the token was configured in clear text.
PlainToken bool
// AllowUnauthenticated explicitly permits running without a token on any listener.
AllowUnauthenticated bool
}
Auth configures bearer token authentication.
Only the SHA-256 digest of the token is kept in memory. Prefer NATIVE_AGENT_TOKEN_SHA256 (or _FILE): agent processes run as the same OS user as the gateway and can read its environment, so a plain NATIVE_AGENT_TOKEN would be visible to them while a digest is not usable as a credential.
type Config ¶
type Config struct {
Network Network
Auth Auth
Log Log
// Docs serves /openapi.yaml and the /docs reference UI without a token.
Docs bool
// Agent is the single agent served by this process (NATIVE_AGENT_AGENT).
Agent string
// SandboxMode is cli (the CLI's own OS sandbox) or external (an outer boundary such as
// a container isolates the CLI).
SandboxMode string
// HomeDir is passed to agent processes as HOME.
HomeDir string
// User is passed to agent processes as USER (needed for the macOS Keychain).
User string
// SearchPath is passed to agent processes as PATH.
SearchPath string
// TempDir hosts per-run private files.
TempDir string
// ProxyEnv holds the standard proxy variables that are set, passed on to agent processes.
ProxyEnv []string
// DataDir is the gateway's own state directory (NATIVE_AGENT_DATA_DIR).
DataDir string
// WorkDir (<DataDir>/work) is the working directory for maintenance commands.
WorkDir string
// WorkspaceRoot (<DataDir>/workspaces) holds managed workspaces as <root>/<workspace_id>.
WorkspaceRoot string
// AllowedRoots are host directories that may be attached as workspaces or handed to the
// agent as extra directories (add_dirs, plugin_dirs). Read once at startup; empty
// disables both.
AllowedRoots []string
// ProfileDir is the agent profile (settings, login, history): "native" for the CLI's own
// default location, or an absolute directory.
ProfileDir string
Limits Limits
}
Config is the validated runtime configuration. Treat it as read-only.
type InteractiveConfig ¶
type InteractiveConfig struct {
Agent string
HomeDir string
User string
SearchPath string
TempDir string
ProxyEnv []string
DataDir string
WorkDir string
ProfileDir string
}
InteractiveConfig is the complete configuration needed by the login and status commands. It intentionally excludes server, authentication, logging, workspace, and run-limit settings.
func LoadInteractive ¶
func LoadInteractive(environ map[string]string) (InteractiveConfig, error)
LoadInteractive parses only the settings used by the login and status commands.
type Limits ¶
type Limits struct {
MaxConcurrent int
QueryTimeout time.Duration
CommandTimeout time.Duration
// LoginTimeout bounds one API-driven native login flow.
LoginTimeout time.Duration
// RunRetention is how long finished runs (and their events) stay readable.
RunRetention time.Duration
MaxRetainedRuns int
MaxRunEvents int
MaxRunObservations int
// RunIdle closes an interactive run that has had no turn for this long.
RunIdle time.Duration
MaxBodyBytes int64
MaxOutputBytes int64
MaxFileBytes int64
MaxListEntries int
}
Limits bounds resource usage per request and per process.
type Log ¶
type Log struct {
// Level is NATIVE_AGENT_LOG_LEVEL: debug, info, warn or error.
Level slog.Level
// Format is NATIVE_AGENT_LOG_FORMAT: json, text or console (colored, for a terminal).
Format string
// Requests enables one access log line per request (NATIVE_AGENT_LOG_REQUESTS).
Requests bool
// Bodies adds request and response bodies to the access log (NATIVE_AGENT_LOG_BODIES).
// Bodies are truncated to BodyLimit bytes and credentials are redacted;
// file transfers are never logged. Prompts and answers will appear in logs.
Bodies bool
BodyLimit int
}
Log configures structured logging.
type Network ¶
type Network struct {
// Listen is the explicitly configured ip:port to bind.
Listen string
// AllowedIPs restricts clients by source address (NATIVE_AGENT_ALLOWED_IPS, comma
// separated IPs or CIDRs). Empty allows every source. Forwarding headers such as
// X-Forwarded-For are never trusted.
AllowedIPs []netip.Prefix
}
Network configures the listener and the client IP allowlist.