LemonCore.Config.Modular (lemon_core v0.1.0)

View Source

Modular configuration interface for Lemon.

This module is the canonical runtime configuration loader for Lemon. It delegates to specialized sub-modules for each config domain and is the source of truth behind LemonCore.Config.

Configuration Priority

Configuration values are resolved in the following priority:

  1. Environment variables (highest priority)
  2. Project config (.lemon/config.toml)
  3. Global config (~/.lemon/config.toml)

Both config locations are configurable; see LemonCore.Paths.

  1. Default values (lowest priority)

Example Usage

# Load full configuration using modular approach
config = LemonCore.Config.Modular.load()

# Access specific sections
config.agent.default_model
config.gateway.enable_telegram
config.providers.providers["anthropic"].api_key

Sub-modules

See LemonCore.Config for the legacy configuration interface.

Summary

Functions

Checks for deprecated TOML sections and raises ValidationError if found.

Returns the path to the global config file.

Loads the full configuration from all sources using the modular approach.

Loads and validates configuration, raising on validation errors.

Loads configuration with validation, returning ok/error tuple.

Returns the path to the project config file for the given directory.

Types

t()

@type t() :: %LemonCore.Config.Modular{
  agent: LemonCore.Config.Agent.t(),
  features: LemonCore.Config.Features.t(),
  gateway: LemonCore.Config.Gateway.t(),
  logging: LemonCore.Config.Logging.t(),
  providers: LemonCore.Config.Providers.t(),
  tools: LemonCore.Config.Tools.t(),
  tui: LemonCore.Config.TUI.t()
}

Functions

check_deprecated_sections!(settings)

@spec check_deprecated_sections!(map()) :: :ok

Checks for deprecated TOML sections and raises ValidationError if found.

Deprecated sections:

  • [agent] - use [defaults] and [runtime] instead
  • [agents] - use [profiles.<id>] instead
  • [agent.tools] - use [runtime.tools.*] instead
  • [tools] - use [runtime.tools.*] instead

global_path()

@spec global_path() :: String.t()

Returns the path to the global config file.

load(opts \\ [])

@spec load(keyword()) :: t()

Loads the full configuration from all sources using the modular approach.

Merges global config, project config, and environment variables.

Options

  • :project_dir - Project directory to load config from (default: current directory)
  • :validate - Whether to validate the config (default: false)

Examples

config = LemonCore.Config.Modular.load()
config = LemonCore.Config.Modular.load(project_dir: "~/my-project")
config = LemonCore.Config.Modular.load(validate: true)

load!(opts \\ [])

@spec load!(keyword()) :: t()

Loads and validates configuration, raising on validation errors.

Options

  • :project_dir - Project directory to load config from (default: current directory)

Examples

config = LemonCore.Config.Modular.load!()

Raises

load_with_validation(opts \\ [])

@spec load_with_validation(keyword()) :: {:ok, t()} | {:error, [String.t()]}

Loads configuration with validation, returning ok/error tuple.

Options

  • :project_dir - Project directory to load config from (default: current directory)

Examples

case LemonCore.Config.Modular.load_with_validation() do
  {:ok, config} -> use_config(config)
  {:error, errors} -> handle_errors(errors)
end

project_path(dir)

@spec project_path(String.t()) :: String.t()

Returns the path to the project config file for the given directory.