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 DefaultModel() (string, error)
- func DefaultModelFor(providerName string) (string, error)
- func DefaultProvider() (string, error)
- func DefaultThinkingLevel() (string, error)
- func DefaultThinkingLevelFor(providerName, model string) (string, error)
- func FileConfigPath() string
- func GenericBaseURLEnvVar(providerName string) string
- func ParseThresholdFraction(s string) (float64, bool)
- func ProxyConfigPath() string
- func SaveProxyConfig(cfg ProxyConfig) error
- func SetDefaultModel(model, thinkingLevel, providerName string) error
- func SetDefaultModelFor(providerName, model, thinkingLevel string) error
- func SetDefaultProvider(name, model string) (bool, error)
- func SetDefaultThinkingLevel(thinkingLevel string) error
- func SetDefaultThinkingLevelFor(providerName, model, level string) error
- func SetMemoryRecall(on bool) error
- func SetProviderDefaults(s ProviderDefaults) error
- type CheckpointConfig
- type CompactionConfig
- type DreamConfig
- type FileConfig
- type IntOrString
- type MaxContext
- type MemoryConfig
- type MemorySettings
- type ProviderDefaults
- type ProxyConfig
- type RedactConfig
- type ResolvedMemory
Constants ¶
const ( DefaultMemoryEnabled = true DefaultMemoryReconcileOnSearch = true DefaultMemorySearchScoreFloor = 0.15 DefaultMemoryCCIndex = false // The per-turn recall (the memory reminder) ships on, but with guards: a // query made of one unit ("继续", "ok") recalls nothing, and a hit has to // share at least DefaultMemoryRecallMinOverlap of the query's units before // it is injected. The relative score floor in the store keeps the top hit // always, which is why the guards live here: "some hit exists" is not the // same question as "this hit is relevant". DefaultMemoryRecall = false DefaultMemoryRecallMinUnits = 2 DefaultMemoryRecallMinOverlap = 2 DefaultMemoryRecallReconcileSecs = 30 )
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 DefaultModel ¶ added in v1.4.2
DefaultModel returns the top-level `model` value, or "" when the file does not set one.
func DefaultModelFor ¶ added in v1.4.2
DefaultModelFor returns the default model saved for one provider. A config written before the per-provider table existed still works: the top-level model is used when it was saved for the same provider.
func DefaultProvider ¶ added in v1.3.6
DefaultProvider returns the top-level `provider` value config.toml sets, or "" when the file does not set one.
func DefaultThinkingLevel ¶ added in v1.4.2
DefaultThinkingLevel returns the top-level `thinking_level` value, or "".
func DefaultThinkingLevelFor ¶ added in v1.5.2
DefaultThinkingLevelFor returns the reasoning level saved for one provider/model pair, or "" when none is saved. Unlike DefaultThinkingLevel it never falls back to the shared top-level value: a level set for one model must not become another model's default.
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
func SetDefaultModel ¶ added in v1.4.2
SetDefaultModel writes the default model, reasoning level and (when non-empty) the provider that serves it. An empty model or level removes its key. The provider key is left alone when providerName is empty, so clearing a model does not also forget which gateway a new session should open with.
func SetDefaultModelFor ¶ added in v1.4.2
SetDefaultModelFor writes the per-provider default model and, for a non-empty model, the top-level provider/model pair so a new session starts there. An empty model removes only this provider's entry (and the top-level model when it pointed at this provider). A non-empty level is saved for this exact provider/model pair, never as a shared default.
func SetDefaultProvider ¶ added in v1.3.6
SetDefaultProvider writes the top-level provider key, and — when model is non-empty and the file already pins a model — rewrites that line too, because a model id belongs to the gateway that serves it. An empty name removes the key. It reports whether the model line changed.
Comments, table bodies and every other key survive untouched: only the two lines are replaced, and a missing key is appended to the top-level block.
func SetDefaultThinkingLevel ¶ added in v1.4.2
SetDefaultThinkingLevel writes only the reasoning level, leaving the model and provider untouched. It backs the level picker's default key.
func SetDefaultThinkingLevelFor ¶ added in v1.5.2
SetDefaultThinkingLevelFor writes (or removes, when level is empty) the reasoning level for one provider/model pair. The model, the provider and every other pair's level stay untouched.
func SetMemoryRecall ¶ added in v1.3.7
SetMemoryRecall writes `recall = <bool>` under [memory] in config.toml.
Like the default-provider writer, this edits the two or three lines it owns instead of re-encoding the file: config.toml is hand-written, and a decode/encode round trip would drop every comment in it. The [memory] table is created when it is missing, and the key is inserted right after its header so the section reads as a unit.
func SetProviderDefaults ¶ added in v1.5.49
func SetProviderDefaults(s ProviderDefaults) error
SetProviderDefaults updates the provider-facing top-level keys in one atomic write while preserving comments, unrelated keys and tables. Saving a named credential removes a legacy literal api_key line so the secret has one home.
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"`
// Redact is the [redact] table: golder's embedded DLP layer. It is applied
// in-process before text reaches the provider, so there is no proxy to run.
Redact RedactConfig `toml:"redact"`
}
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"`
// Recall is the per-turn memory reminder. Absent means on.
Recall *bool `toml:"recall"`
// RecallMinUnits is how many query units a reminder query must have before
// the store is even searched; a unit is a word or a CJK bigram, so one
// "继续"/"ok" is not a query.
RecallMinUnits *int `toml:"recall_min_units"`
// RecallMinOverlap is how many distinct query units a hit must contain to
// be injected.
RecallMinOverlap *int `toml:"recall_min_overlap"`
// RecallReconcileSeconds throttles the index reconcile the reminder runs:
// the walk is linear in the number of memory files and used to run on every
// turn. 0 reconciles every turn; negative disables it here (the tool path
// still reconciles on demand).
RecallReconcileSeconds *int `toml:"recall_reconcile_seconds"`
}
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 enabled=true, reconcile_on_search=true, score floor 0.15, cc_index=false, and recall=OFF (the per-turn reminder is the one piece that ships dark: it costs a prompt injection on every turn it fires, so it is opted into rather than out of). 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 ProviderDefaults ¶ added in v1.5.49
type ProviderDefaults struct {
Provider string
Model string
BaseURL string
Protocol string
Credential string
ThinkingLevel string
}
ProviderDefaults is the non-secret provider configuration a settings view edits. Credential is a named reference; API key values never belong here.
type ProxyConfig ¶
type ProxyConfig struct {
URL string `toml:"url"`
Browser bool `toml:"browser"`
Providers []string `toml:"providers"`
}
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)
type RedactConfig ¶ added in v1.4.0
type RedactConfig struct {
// Mode is off | observe | redact | block. Empty means redact (the safe
// default); observe records findings without changing text.
Mode string `toml:"mode"`
// Entropy is the minimum Shannon entropy for generic NAME=value matches.
// Zero means the engine default (3.5).
Entropy float64 `toml:"entropy"`
// Audit is the JSONL audit path. Empty means $GOLDER_HOME/redact-audit.jsonl.
Audit string `toml:"audit"`
// Allow lists exact values that must never be redacted.
Allow []string `toml:"allow"`
}
RedactConfig is the [redact] TOML table.
type ResolvedMemory ¶
type ResolvedMemory struct {
Enabled bool
ReconcileOnSearch bool
SearchScoreFloor float64
CCIndex bool
Recall bool
RecallMinUnits int
RecallMinOverlap int
RecallReconcile time.Duration
}
ResolvedMemory is MemoryConfig with defaults applied and the score floor clamped to [0,1]. It is the shape downstream memory wiring consumes.
func ResolveMemoryRecall ¶ added in v1.3.7
func ResolveMemoryRecall() ResolvedMemory
ResolveMemoryRecall reads config.toml and resolves the [memory] policy. A config that cannot be read falls back to the shipped defaults (recall off), because an unreadable preference must not quietly turn on prompt injection.