Documentation
¶
Overview ¶
Package config loads ~/.yottacode/config.toml — the single tunable surface for context-window watermarks, retrieval, and provider profiles.
The file is parsed with github.com/BurntSushi/toml so we get arrays of tables ([[providers]], [[providers.models]]) without writing a parser. Unknown keys and unknown sections are rejected at load time so a typo like `enbled = ture` doesn't silently pass — we walk the metadata's Undecoded() set after decoding.
API keys NEVER live in this file. Each [[providers]] block names an environment variable via api_key_env; the actual key is provided either via that OS env var or via ~/.yottacode/.env or <repo>/.yottacode/.env. Inline api_key fields are refused at load.
Index ¶
- Constants
- Variables
- func DefaultPath() (string, error)
- func EnsureDefault(path string) (string, error)
- func ParseCandidate(raw string) (provider, model string, err error)
- func Render(cfg Config) string
- func Save(cfg Config, path string) error
- func Validate(cfg Config) error
- type Active
- type CheckpointsConfig
- type Config
- type ContextConfig
- type Model
- type Provider
- type ResolvedCandidate
- type RetrievalConfig
- type RouterConfig
Constants ¶
const DefaultCheckpointRetentionDays = 30
DefaultCheckpointRetentionDays mirrors Claude Code's 30-day TTL — long enough to step back through a few days of work, short enough that blob storage doesn't grow without bound. Override per-host via `[checkpoints] retention_days = N` in config.toml.
const DefaultRouterHealthFailureThreshold = 3
DefaultRouterHealthFailureThreshold is the number of failures within the window that mark a candidate as degraded. Set to 0 in the config file to disable observation entirely.
const DefaultRouterHealthWindowSeconds = 60
DefaultRouterHealthWindowSeconds is the sliding-window length the router uses when the user enables routing without specifying health_window_seconds.
const DefaultsTOML = `` /* 4967-byte string literal not displayed */
DefaultsTOML is the documented default file written by EnsureDefault.
Variables ¶
var ValidKinds = []string{"anthropic", "openai", "openai-auth", "openai-compatible", "ollama", "gemini"}
ValidKinds is the whitelist for Provider.Kind.
var ValidPolicies = []string{"fallback-chain", "cheap-first"}
ValidPolicies is the whitelist for RouterConfig.Policy. Empty is treated as the default (fallback-chain) at construction time.
var ValidTiers = []string{"cheap", "balanced", "expensive"}
ValidTiers is the whitelist for Model.Tier. Empty is also accepted (treated as unspecified).
Functions ¶
func EnsureDefault ¶
EnsureDefault writes the documented default config.toml at path if none exists. Returns the resolved path either way so callers can show it to the user. Idempotent — never overwrites an existing file.
func ParseCandidate ¶
ParseCandidate splits a "provider" or "provider:model" router candidate string. Empty model means "use the provider's default". Whitespace is trimmed; an empty input is rejected.
func Render ¶
Render produces the canonical TOML body for a Config. Stable section order: tunables block (auto_memory / context / retrieval) first via the BurntSushi encoder, then human-edited sections (active, providers, router) hand-rendered with explicit alignment so diffs read top-to-bottom. The encoder's emit order isn't guaranteed across releases, which is why we don't lean on it for the human-edited bits.
Used both by wizard.Apply (for fresh writes and merges) and by the TUI's /provider add / /model picker save paths so a single rendering function owns the file shape. Callers that need atomic persistence should pair this with Save.
Types ¶
type Active ¶
type Active struct {
Provider string `toml:"provider"`
Model string `toml:"model"`
DefaultModel string `toml:"default_model"`
}
Active selects which configured provider + model is the session default. All fields are optional — if Provider is empty the user is expected to pass --model / --base-url / --provider via flag or env.
Two TOML keys spell the active model: the new canonical `default_model` and the legacy `model`. Both populate the same in-memory value: after Load(), Model and DefaultModel are kept in sync — whichever the file set (with default_model winning if both appear) is mirrored into the other so existing readers (cfg.Active.Model) keep working unchanged.
type CheckpointsConfig ¶ added in v0.2.0
type CheckpointsConfig struct {
RetentionDays int `toml:"retention_days"`
}
CheckpointsConfig tunes the per-prompt file/conversation snapshot store behind /checkpoints + Esc Esc. RetentionDays<=0 falls through to DefaultCheckpointRetentionDays so the on-disk default doesn't require users to write a [checkpoints] block.
type Config ¶
type Config struct {
Context ContextConfig `toml:"context"`
Retrieval RetrievalConfig `toml:"retrieval"`
Router RouterConfig `toml:"router"`
Active Active `toml:"active"`
Providers []Provider `toml:"providers"`
Checkpoints CheckpointsConfig `toml:"checkpoints"`
// Experimental gates non-default features behind named opt-ins.
// Mirrors the --experimental CLI flag and the
// $YOTTACODE_EXPERIMENTAL env var. Each entry is a feature name
// from internal/experimental; values must be `true` to enable.
// Unrecognized names load without error and emit a startup
// warning so graduated/removed feature names don't break old
// configs.
Experimental map[string]bool `toml:"experimental"`
}
Config bundles every tunable yottacode reads from disk. Sub-structs map 1:1 to TOML sections so the file shape mirrors the Go shape.
func Default ¶
func Default() Config
Default returns a Config populated with the documented defaults.
func Load ¶
Load reads config.toml at the given path, returning the parsed config merged onto Default(). A missing file is not an error — defaults are returned. Invalid values (out-of-range, malformed, unknown sections) ARE an error.
func LoadDefault ¶
LoadDefault loads the file at ~/.yottacode/config.toml.
func (*Config) FindProvider ¶
FindProvider returns a pointer to the provider with the given name, or nil. Pointer receiver lets callers mutate the slice element if they need to (e.g. /provider use updating Active.Model on switch).
func (*Config) ResolveCandidates ¶
func (c *Config) ResolveCandidates() ([]ResolvedCandidate, error)
ResolveCandidates parses each router.candidates entry and resolves it against the provider catalog. Validate has already been called by Load, so the caller knows every candidate refers to a real provider and a real model — but ResolveCandidates is callable independently for tests and for /router introspection.
type ContextConfig ¶
type ContextConfig struct {
WarnThreshold float64 `toml:"warn_threshold"`
AutoThreshold float64 `toml:"auto_threshold"`
DefaultWindow int `toml:"default_window"`
}
ContextConfig governs context-window watermark behavior.
type Model ¶
type Model struct {
// Name is the model identifier passed to the API (e.g.
// "claude-sonnet-4-6"). Required.
Name string `toml:"name"`
// Tier is a coarse cost/capability bucket used by the future
// auto-router. Empty means unspecified. Validated at load time
// against the whitelist below.
Tier string `toml:"tier"`
// ContextWindow overrides yottacode's built-in context-window
// table for this model. 0 means use the built-in fallback.
ContextWindow int `toml:"context_window"`
}
Model is one entry in a provider's catalog.
type Provider ¶
type Provider struct {
// Name is the user-chosen label for this configuration, unique
// within the file. Used by /provider use <name>.
Name string `toml:"name"`
// Kind selects the adapter family. One of:
//
// anthropic — native Messages API (claude-*)
// openai — OpenAI's own endpoints (chat completions
// + responses; auto-routes for o-series and
// gpt-5*)
// openai-compatible — anything that speaks /v1/chat/completions
// (vLLM, Llama Stack, OpenRouter, Together,
// xAI, NVIDIA NIM, Groq, …)
// ollama — Ollama's local server (OpenAI-shim variant)
Kind string `toml:"kind"`
// BaseURL is the HTTPS endpoint for the API. For Anthropic this is
// typically https://api.anthropic.com; for OpenAI-compatible
// endpoints include the /v1 suffix where the upstream expects it.
BaseURL string `toml:"base_url"`
// APIKeyEnv is the name of the OS environment variable that holds
// the bearer token. Empty for local providers like Ollama. Looked
// up at adapter-construction time, NOT stored here.
APIKeyEnv string `toml:"api_key_env"`
// DefaultModel is the model name to adopt when /provider use
// switches to this provider. Must appear in Models when set.
DefaultModel string `toml:"default_model"`
// Models is the catalog of models available through this provider.
// Used by /model list and as the source of truth for the future
// auto-router.
Models []Model `toml:"models"`
// APIKey is reserved as a tripwire: declaring it inline produces a
// load-time error that points the user at .env. We don't read its
// value — declaring it at all is the failure.
APIKey string `toml:"api_key"`
}
Provider describes one upstream model vendor configuration. Two provider entries can share the same Kind (e.g. OpenRouter and Together both Kind = "openai-compatible") but differ in name + base_url + models.
type ResolvedCandidate ¶
ResolvedCandidate is the fully-resolved view of one router.candidates entry: provider profile + concrete model + tier (looked up from providers.models). Returned by ResolveCandidates so callers (cli.BuildRouter) don't repeat the lookup.
type RetrievalConfig ¶
type RetrievalConfig struct {
Enabled bool `toml:"enabled"`
TopK int `toml:"top_k"`
MinScore float64 `toml:"min_score"`
}
RetrievalConfig governs the per-turn retrieval orchestrator that scores agent-managed memory entries against the user's prompt and injects only the most relevant ones into the system prompt.
type RouterConfig ¶
type RouterConfig struct {
Enabled bool `toml:"enabled"`
Policy string `toml:"policy"`
Candidates []string `toml:"candidates"`
HealthWindowSeconds int `toml:"health_window_seconds"`
HealthFailureThreshold int `toml:"health_failure_threshold"`
}
RouterConfig describes the multi-provider routing policy. When Enabled is false, yottacode dispatches to the single configured provider (the legacy behavior). When true, Candidates names an ordered list of "<provider>" or "<provider>:<model>" entries and Policy selects the dispatch strategy.
Capability gating across providers is a Phase 2 concern: candidates listed here must be capability-aligned (e.g. all support web_search, or none do) for predictable system-prompt composition. The first candidate is the representative for connection probes and system-prompt rendering.
HealthWindowSeconds and HealthFailureThreshold control the router-level sliding-window failure tracker. After HealthFailureThreshold failures within HealthWindowSeconds for a candidate, the router demotes that candidate to the back of the dispatch order on subsequent requests. A successful turn clears the candidate's failure history. Set either to 0 to disable observation entirely; defaults are 60 seconds / 3 failures.