Documentation
¶
Overview ¶
Package config implements golder's optional user config file at $GOLDER_HOME/config.toml (~/.golder/config.toml by default) plus the provider-agnostic base-url env-var name derivation. Values in the file replace golder's built-in defaults, but an explicit command-line flag always wins over the file:
command-line flag > config.toml > built-in default
A missing file is not an error (defaults apply); a malformed file is surfaced to the caller so it can warn rather than silently ignore user intent.
The package is intentionally free of any cliOptions/run-assembly concern: it only loads and decodes the file and derives env-var names. Overlaying a FileConfig onto the parsed CLI options lives in cmd/golder, alongside the options struct it mutates.
Memory/checkpoint/compaction config: the nested TOML tables [memory], [checkpoint], and compaction.max_context (spec-persistent-memory-infinite- context §3/§4/§5.2). This file is pure config plumbing — parse, defaults, and resolve helpers only. The actual memory Store, checkpoint persistence, and compaction trigger live in later layers (internal/memory, internal/runtime, internal/compaction) and consume the resolved values overlaid in cmd/golder.
Index ¶
- Constants
- func DefaultCheckpointThresholds() []string
- func FileConfigPath() string
- func GenericBaseURLEnvVar(providerName string) string
- func ParseThresholdFraction(s string) (float64, bool)
- func ProxyConfigPath() string
- func SaveProxyConfig(cfg ProxyConfig) error
- type CheckpointConfig
- type CompactionConfig
- type DreamConfig
- type FileConfig
- type IntOrString
- type MaxContext
- type MemoryConfig
- type MemorySettings
- type ProxyConfig
- type ResolvedMemory
Constants ¶
const ( DefaultMemoryEnabled = true DefaultMemoryReconcileOnSearch = true DefaultMemorySearchScoreFloor = 0.15 DefaultMemoryCCIndex = false )
Built-in defaults for the [memory] table. Exposed so overlay and tests share one source of truth (mirrors the flat-config defaults documented in main.go).
Variables ¶
This section is empty.
Functions ¶
func DefaultCheckpointThresholds ¶
func DefaultCheckpointThresholds() []string
DefaultCheckpointThresholds is the built-in compaction trigger ladder as percentage strings; ResolveThresholds parses them into fractions in (0,1].
func FileConfigPath ¶
func FileConfigPath() string
FileConfigPath returns the path to the user config file: config.toml in the golder state root ($GOLDER_HOME, else ~/.golder). It returns "" when the root cannot be resolved, so the caller treats the file as absent.
func GenericBaseURLEnvVar ¶
GenericBaseURLEnvVar derives the generic base-url override env var name for a provider: the provider name uppercased with hyphens rewritten to underscores, suffixed with _BASE_URL. For example "zai-coding-cn" → "ZAI_CODING_CN_BASE_URL" and "deepseek" → "DEEPSEEK_BASE_URL". An empty provider name yields "".
It lives here (not with ResolveBaseURL) because it is a pure name derivation with no dependency on the provider registry — the provider-agnostic part of base-url resolution. ResolveBaseURL itself lives in internal/provider.
func ParseThresholdFraction ¶
ParseThresholdFraction parses a percentage string like "80%" into a fraction in (0,1]. Values outside that range (<=0, >100%) or lacking a % suffix are rejected with ok=false so callers fall back to a default.
func ProxyConfigPath ¶
func ProxyConfigPath() string
func SaveProxyConfig ¶
func SaveProxyConfig(cfg ProxyConfig) error
Types ¶
type CheckpointConfig ¶
type CheckpointConfig struct {
Thresholds []string `toml:"thresholds"`
Reserved IntOrString `toml:"reserved"`
PushCaps map[string]int `toml:"push_caps"`
}
CheckpointConfig is the [checkpoint] TOML table. push_caps is a nested table of per-section token caps (e.g. [checkpoint.push_caps] with memory = 800, recall = 1200), modeled as a map.
func (CheckpointConfig) ResolveThresholds ¶
func (c CheckpointConfig) ResolveThresholds() []float64
ResolveThresholds parses the configured threshold percentage strings into fractions in (0,1], skipping out-of-range/unparseable entries. An empty list — or one where every entry is invalid — falls back to the built-in defaults.
type CompactionConfig ¶
type CompactionConfig struct {
MaxContext string `toml:"max_context"`
}
CompactionConfig is the [compaction] TOML table. Only max_context is wired here; it lowers the auto-compaction trigger point and is always clamped by the provider window by the consumer.
func (CompactionConfig) ResolveMaxContext ¶
func (c CompactionConfig) ResolveMaxContext() (MaxContext, error)
ResolveMaxContext parses the max_context string form. An empty value yields an unset MaxContext (no error).
type DreamConfig ¶
type DreamConfig struct {
Enabled *bool `toml:"enabled"`
IntervalDays int `toml:"interval_days"`
RecentSessions int `toml:"recent_sessions"`
}
DreamConfig is the [dream] TOML table for /dream memory consolidation. Enabled is a pointer so an absent key (nil) is distinguishable from an explicit false: nil is treated as true, only enabled = false disables auto-trigger. IntervalDays and RecentSessions use zero as "apply default" (7 and 20 respectively); normalization lives in dream.Config.
type FileConfig ¶
type FileConfig struct {
Model string `toml:"model"`
BaseURL string `toml:"base_url"`
APIKey string `toml:"api_key"`
// Credential is a named credential REFERENCE (issue #568): the literal key
// lives in $GOLDER_HOME/.credentials.yaml (mode 0600) under this name, and
// config.toml carries only the name. It resolves to the API-key tier, below
// an explicit --api-key flag. Empty means no reference.
Credential string `toml:"credential"`
Protocol string `toml:"protocol"`
Provider string `toml:"provider"`
ThinkingLevel string `toml:"thinking_level"`
OutputFormat string `toml:"output_format"`
NoTools bool `toml:"no_tools"`
NoSkills bool `toml:"no_skills"`
Approve bool `toml:"approve"`
SystemPrompt string `toml:"system_prompt"`
// AllowedTools and DisallowedTools are the tool-level admission boundary:
// the config-file tier of --allowed-tools / --disallowed-tools. Names match
// case-insensitively and DisallowedTools wins when a name appears in both.
// A CLI flag replaces the file value wholesale rather than merging with it,
// so passing --allowed-tools can widen a boundary the file narrowed.
AllowedTools []string `toml:"allowed_tools"`
DisallowedTools []string `toml:"disallowed_tools"`
// Prompts is the config.toml `prompts` array: paths (files or dirs) to load
// prompt templates from at the settings tier (mirrors pi's settings prompts).
Prompts []string `toml:"prompts"`
// Memory, Checkpoint, and Compaction are nested TOML tables for the
// persistent-memory / infinite-context feature. They are pure config
// plumbing here; defaults/parsing live in memory.go (Resolve* helpers) and
// the overlay into runtime options lives in cmd/golder. See
// tasks/spec-persistent-memory-infinite-context.md §3/§4/§5.2.
Memory MemoryConfig `toml:"memory"`
Checkpoint CheckpointConfig `toml:"checkpoint"`
Compaction CompactionConfig `toml:"compaction"`
// Dream is the [dream] TOML table for the /dream memory-consolidation
// feature. Pure config plumbing here; defaults/normalization live in
// internal/dream (Config). See tasks/spec-dream-memory-consolidation.md
// §3.3.
Dream DreamConfig `toml:"dream"`
}
FileConfig is the on-disk shape of config.toml. Every field is optional; an absent (zero-value) field leaves the corresponding default/flag untouched. Keys are snake_case to read naturally in TOML.
func LoadFileConfig ¶
func LoadFileConfig(path string) (FileConfig, error)
LoadFileConfig reads and decodes config.toml. A missing file (or an empty path) returns a zero config with no error; a malformed file is an error.
func (FileConfig) ResolveMemorySettings ¶
func (c FileConfig) ResolveMemorySettings() MemorySettings
ResolveMemorySettings resolves the three nested tables into MemorySettings, applying defaults. It never fails: an unparseable compaction.max_context is dropped to unset so a single bad key cannot break config overlay.
type IntOrString ¶
IntOrString accepts either a TOML integer or string for the optional [checkpoint].reserved key (e.g. reserved = 4096 or reserved = "10%"). Set reports whether the key was present; IsInt selects the populated field.
func (*IntOrString) UnmarshalTOML ¶
func (v *IntOrString) UnmarshalTOML(data any) error
UnmarshalTOML implements toml.Unmarshaler so a bare int or a quoted string both decode without failing the whole file.
type MaxContext ¶
type MaxContext struct {
// contains filtered or unexported fields
}
MaxContext is a parsed compaction.max_context value: either an absolute token count or a fraction of the provider window. The zero value is "unset" and Resolve returns 0. Resolve is a pure function; the provider-limit clamp is applied by the consumer.
func ParseMaxContext ¶
func ParseMaxContext(s string) (MaxContext, error)
ParseMaxContext parses the accepted max_context forms: a plain token count ("300000"), a K/M-suffixed count ("300K", "1M", case-insensitive, fractions allowed like "1.5M"), or a percentage of the provider window ("50%"). An empty string is unset (no error); other malformed or non-positive values are errors.
func (MaxContext) IsSet ¶
func (m MaxContext) IsSet() bool
IsSet reports whether max_context was configured.
func (MaxContext) Resolve ¶
func (m MaxContext) Resolve(window int) int
Resolve returns the token budget for the given provider window: window* fraction (rounded) for a percentage form, or the absolute token count otherwise. An unset value returns 0. This is intentionally unclamped — the consumer applies the provider-limit clamp.
type MemoryConfig ¶
type MemoryConfig struct {
Enabled *bool `toml:"enabled"`
ReconcileOnSearch *bool `toml:"reconcile_on_search"`
SearchScoreFloor *float64 `toml:"search_score_floor"`
CCIndex bool `toml:"cc_index"`
}
MemoryConfig is the [memory] TOML table. Bool fields whose default is true (Enabled, ReconcileOnSearch) and the float ScoreFloor use pointers so an absent key is distinguishable from an explicit false/0 — nil means "apply the default", which is what makes memory.enabled=false representable and default-safe. CCIndex defaults to false, so a plain bool suffices.
func (MemoryConfig) Resolve ¶
func (m MemoryConfig) Resolve() ResolvedMemory
Resolve applies the [memory] defaults: absent keys fall back to true/true/0.15/false; an explicit search_score_floor outside [0,1] is clamped into range.
type MemorySettings ¶
type MemorySettings struct {
Memory ResolvedMemory
CheckpointThresholds []float64
CheckpointReserved IntOrString
CheckpointPushCaps map[string]int
MaxContext MaxContext
}
MemorySettings bundles the resolved [memory]/[checkpoint]/[compaction] config for overlay into runtime options: defaults applied, string forms pre-parsed. It is produced by FileConfig.ResolveMemorySettings and is always well-formed (an invalid max_context is treated as unset rather than failing the overlay).
type ProxyConfig ¶
ProxyConfig is kept separately so /proxy never rewrites credentials or unrelated settings/comments in config.toml. A nil Providers list retains legacy routing; an explicit empty list means no providers use the proxy.
func LoadProxyConfig ¶
func LoadProxyConfig() (ProxyConfig, error)