Skip to content

Config

Source: core/config/config.gleam, core/config/helpers.gleam

The config loader reads .env (secrets) and agent.toml (configuration) at startup and populates OS environment variables via envoy. It is one of the Blessed Violators (violator #1) -- the only core module that imports every service and plugin cfg module, because it must delegate TOML parsing to each submodule.

Loading priority: environment variable > TOML value > hardcoded default.

Key Functions

config.gleam

  • load_env() -- reads .env and agent.toml, sets environment variables. Called once at startup.
  • load_config() -- parses agent-level settings from TOML, then delegates to each cfg module's load(toml) function.
  • get(key) -- returns Result(String, Nil) for an env var. Does not panic.
  • require(key) -- like get but panics if the variable is missing. Use for mandatory vars.
  • get_or(key, default) -- returns the env var value or a default string.
  • get_api_key() -- reads DEEPSEEK_API_KEY.

Agent identity getters (get_working_dir, get_default_persona, get_timezone, etc.) live here as truly-core settings. Session lifecycle (prune, crash recovery) and approval configuration also live here.

helpers.gleam

Shared utilities for env var access and TOML loading, used by both config.gleam and per-module cfg.gleam files:

  • get_or(key, default) -- get a string env var with a default
  • get_or_int(key, default) -- get an integer env var with a default
  • get_or_float(key, default) -- get a float env var with a default
  • get_or_bool(key, default) -- get a boolean env var (truthy: "true", "1", "yes")
  • get_or_list(key, default) -- get a comma-separated list env var
  • resolve_home(path) -- expand ~ to the user's home directory
  • set_default(key, toml_val, path) -- set an env var from a TOML string, only if not already set
  • set_default_int, set_default_float, set_default_bool, set_default_list -- typed variants
  • Blessed Violators -- Why this module is allowed to import from everywhere
  • Behaviours -- Behaviour records that config maps to service constructors

Built with Gleam on the BEAM/Erlang VM.