config

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const EnvPrefix = "NATIVE_AGENT_"

EnvPrefix is the prefix shared by every gateway environment variable.

View Source
const MinTokenLength = 32

MinTokenLength is the minimum accepted plain API token length.

View Source
const ProfileNative = "native"

ProfileNative selects the native CLI's own default profile location under HOME.

Variables

This section is empty.

Functions

func HashToken

func HashToken(token string) [sha256.Size]byte

HashToken returns the SHA-256 digest used for NATIVE_AGENT_TOKEN_SHA256.

func MergeFile

func MergeFile(processEnv map[string]string, path string) (map[string]string, error)

MergeFile reads an explicit application env file, then overlays processEnv. It does not perform interpolation, command substitution, file discovery, or fallback lookup.

func PrepareDataDir

func PrepareDataDir(workDir string) error

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.

func Load

func Load(environ map[string]string) (Config, error)

Load parses and validates the configuration from environ (e.g. the result of os.Environ split into a map).

func (Config) Validate

func (c Config) Validate() error

Validate checks value ranges and the authentication rule: a non-loopback listener requires a token unless NATIVE_AGENT_ALLOW_UNAUTHENTICATED=true is set explicitly.

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.

func (Network) Allows

func (n Network) Allows(addr netip.Addr) bool

Allows reports whether a client address passes the allowlist.

Jump to

Keyboard shortcuts

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