Documentation
¶
Overview ¶
Package config loads akari-server configuration.
The server is a container workload, so it reads its configuration from the environment by convention. (The akari client, by contrast, uses a config file and defines no environment variables of its own; see docs/DESIGN.md.)
Index ¶
Constants ¶
const MachineEnvVar = "AKARI_MACHINE"
MachineEnvVar overrides the machine identity a client reports for its sessions. It is the only environment variable akari itself defines (the agent root overrides discovery honors belong to the agents). It wins over the config's machine field, which in turn wins over the OS hostname; see ResolveMachine.
Variables ¶
This section is empty.
Functions ¶
func DefaultClientPath ¶
DefaultClientPath returns the platform-standard config file path: ~/.config/akari/config.toml on Linux, ~/Library/Application Support/akari/config.toml on macOS, %AppData%\akari\config.toml on Windows.
func ResolveMachine ¶ added in v0.2.7
ResolveMachine determines the machine identity a client reports for its sessions. Ephemeral and containerized hosts (CI jobs, autoscaled workers, throwaway dev containers) each get a distinct one-off hostname, so a fleet of them otherwise pollutes the machine facet with thousands of single-use values. An explicit identity lets that fleet share one stable logical machine (for example "ci" or "sandbox-pool").
Precedence, highest first:
- the AKARI_MACHINE environment variable, for a per-run override without touching the config, the natural fit for ephemeral hosts, which set an env var far more easily than they write a config file;
- the machine field in the client config, set at login for a stable per-host or per-fleet name;
- the OS hostname, the historical default.
A blank env var or config value falls through rather than reporting an empty machine, and surrounding whitespace is trimmed. hostname is injected (pass os.Hostname) so the fallback is testable; its error is ignored exactly as the bare `machine, _ := os.Hostname()` call sites it replaces did.
func SaveClient ¶
SaveClient writes the config to path (creating parent directories) with owner-only permissions since it holds an API token. It writes to a temporary file and atomically renames it into place, so a crash or write error cannot truncate or destroy an existing config.
Types ¶
type Client ¶
type Client struct {
// ServerURL is the base URL of the akari server, e.g. https://akari.example.
ServerURL string `toml:"server_url"`
// Token is an API token (ingest or full scope) used as a Bearer credential.
Token string `toml:"token"`
// Machine is the logical machine name reported for every session this client
// uploads. Empty falls back to the OS hostname. Set it (at login or by hand)
// to give a fleet of ephemeral or containerized hosts one stable identity
// instead of leaking a distinct one-off hostname per run. AKARI_MACHINE
// overrides it per run; see ResolveMachine.
Machine string `toml:"machine"`
// ExtraRoots are additional session directories to discover beyond each
// agent's standard roots.
ExtraRoots []ExtraRoot `toml:"extra_roots"`
// Excludes are glob patterns of paths to skip during discovery, applied to
// both `akari sync` and `akari watch`. Patterns match the full path with
// forward slashes and `*`/`**` span separators (see discover.Excluder), so
// `**/tmp/**` ignores any path with a `tmp` segment. Empty means discover
// everything.
Excludes []string `toml:"excludes"`
}
Client holds the akari client configuration. All of it lives in one TOML file at the platform per-user config location; the client keeps no other on-disk state and defines a single environment variable of its own (AKARI_MACHINE, see ResolveMachine).
func LoadClient ¶
LoadClient reads and validates the client config. An empty path uses DefaultClientPath. A missing file is a usable error directing the user to log in.
func ReadClient ¶
ReadClient decodes the config without validating it. It reports whether the file existed (a missing file is not an error: callers like login start from a blank config) and returns an error only on a genuine read or parse failure, so a corrupt file is never silently treated as empty.
type ExtraRoot ¶
type ExtraRoot struct {
Agent string `toml:"agent"` // claude | codex | pi
Path string `toml:"path"`
}
ExtraRoot is a user-configured session directory for one agent.
type Server ¶
type Server struct {
// DatabaseURL is the Postgres connection string (AKARI_DATABASE_URL).
DatabaseURL string
// Listen is the address the HTTP server binds (AKARI_LISTEN), e.g. ":8080".
Listen string
// CookieSecure marks session cookies Secure. Defaults true; set
// AKARI_COOKIE_INSECURE=1 for plain-HTTP local development.
CookieSecure bool
// PublicURL is the externally reachable base URL of the server (scheme and
// host, no trailing slash), e.g. "https://akari.example.com". It is the OAuth
// issuer and the base of every absolute URL the MCP authorization flow
// advertises (the discovery documents, the authorize and token endpoints, the
// MCP resource identifier). Read from AKARI_PUBLIC_URL, falling back to
// AKARI_URL (which eph already exports for the dev stack). When neither is set,
// it is empty and the OAuth handlers derive the base from each request's scheme
// and Host header, which is correct for a single-origin deployment behind a
// well-behaved proxy.
PublicURL string
// SweepInterval is how often the server reclaims orphaned CAS blobs
// (AKARI_SWEEP_INTERVAL, a Go duration like "1h"). Defaults to 1h; set "0" to
// disable the background sweep (for example to run it only via the subcommand).
SweepInterval time.Duration
// OGCacheTTL is how long a rendered Open Graph preview card is served from the
// cache before the next request re-renders it (AKARI_OG_CACHE_TTL, a Go duration
// like "1h"). A published overview's card is rendered lazily on first request and
// cached; once it ages past this TTL a later request renders a fresh one in its
// place. Defaults to 1h and must be positive (the card is always cached).
OGCacheTTL time.Duration
// OGCleanupInterval is how often the server sweeps expired preview cards from the
// cache (AKARI_OG_CLEANUP_INTERVAL, a Go duration). Each pass deletes cards older
// than OGCacheTTL, so a card for an overview nobody shares does not linger. It is
// pure housekeeping: a live share re-renders its card on demand regardless.
// Defaults to 24h; set "0" to disable the sweep.
OGCleanupInterval time.Duration
// ProxyAuthHeader is the request header a trusted reverse proxy sets to the
// authenticated username (AKARI_PROXY_AUTH_HEADER, e.g.
// "X-Auth-Request-Preferred-Username"). Setting it turns on proxy-header auth:
// the server trusts the header's value as the signed-in user and provisions the
// account on first sight. It is empty (disabled) by default, because trusting a
// header is only safe when akari is reachable ONLY through the proxy that sets
// it. Leave it unset for a direct deployment. See auth.go's proxyPrincipal and
// the deployment notes in docs/development.md.
ProxyAuthHeader string
// ProxyAuthSecret, when set (AKARI_PROXY_AUTH_SECRET), is a shared secret the
// proxy must echo in ProxyAuthSecretHeader for the identity header to be
// trusted. It is defense in depth for when network isolation alone is not
// enough: a client that reaches akari directly cannot forge an identity without
// also knowing the secret. Empty means the identity header is trusted on
// network isolation alone.
ProxyAuthSecret string
// ProxyAuthSecretHeader is the header carrying ProxyAuthSecret
// (AKARI_PROXY_AUTH_SECRET_HEADER). Defaults to "X-Akari-Proxy-Secret". Only
// consulted when ProxyAuthSecret is set.
ProxyAuthSecretHeader string
// SignalsSettleInterval is how often the server wakes to compute per-session
// signals for sessions that have settled (AKARI_SIGNALS_SETTLE_INTERVAL). The
// ingest append path deliberately does not recompute signals per message (that
// would be quadratic and would grade a still-running session with a
// time-dependent outcome), so a settled session's grade is filled in here, once,
// after it has been idle past the abandoned threshold. Defaults to 5m; set "0"
// to disable the background pass (signals then land only on reparse or via the
// subcommand).
SignalsSettleInterval time.Duration
}
Server holds the akari-server runtime configuration.
func LoadServer ¶
LoadServer reads server configuration from the environment, applying defaults and validating required values.