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 DefaultProvider() (string, error)
- func FileConfigPath() string
- func GenericBaseURLEnvVar(providerName string) string
- func NetworkConfigPath() string
- func NetworkFollowEnabled() bool
- func ParseThresholdFraction(s string) (float64, bool)
- func ProxyConfigPath() string
- func SaveNetworkConfig(cfg NetworkConfig) error
- func SaveProxyConfig(cfg ProxyConfig) error
- func SetDefaultProvider(name, model string) (bool, error)
- func SetMemoryRecall(on bool) error
- func SetNetworkFollowEnabled(on bool) error
- type CheckpointConfig
- type CompactionConfig
- type DreamConfig
- type FileConfig
- type IntOrString
- type MaxContext
- type MemoryConfig
- type MemorySettings
- type NetworkConfig
- 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 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 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 NetworkConfigPath ¶ added in v1.3.5
func NetworkConfigPath() string
NetworkConfigPath is the network policy file beside config.toml, kept separate for the same reason proxy.toml is: /network must never rewrite credentials or unrelated settings.
func NetworkFollowEnabled ¶ added in v1.3.7
func NetworkFollowEnabled() bool
NetworkFollowEnabled resolves the policy: unset means on, and an explicit false means off. A config that cannot be read also means on — the setting is a convenience, and failing to read a preference must not turn into a silent change of how much gets asked.
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 SaveNetworkConfig ¶ added in v1.3.5
func SaveNetworkConfig(cfg NetworkConfig) error
SaveNetworkConfig writes network.toml atomically.
func SaveProxyConfig ¶
func SaveProxyConfig(cfg ProxyConfig) error
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 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 SetNetworkFollowEnabled ¶ added in v1.3.7
SetNetworkFollowEnabled writes an explicit value, so "off" survives a restart.
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 NetworkConfig ¶ added in v1.3.5
type NetworkConfig struct {
Follow *bool `toml:"follow"`
}
NetworkConfig is the optional policy for the network capability.
Follow is ON by default, which is why it is a pointer: an absent key means "the default", while `follow = false` is a decision the user made. Under the default, an auto-mode Allow carries the network bit with it instead of asking a second question — the call's own review already settled the risk; a remembered denial still wins, and ask mode keeps its own question.
func LoadNetworkConfig ¶ added in v1.3.5
func LoadNetworkConfig() (NetworkConfig, error)
LoadNetworkConfig reads network.toml. A missing file is the default policy.
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)
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.