config

package
v1.2.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config implements golder's optional user config file at ~/.config/golder/config.toml (honoring $XDG_CONFIG_HOME when set) 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

View Source
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: $XDG_CONFIG_HOME/golder/config.toml, or ~/.config/golder/config.toml by default. It returns "" when neither can be resolved, so the caller treats the file as absent.

func GenericBaseURLEnvVar

func GenericBaseURLEnvVar(providerName string) string

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

func ParseThresholdFraction(s string) (float64, bool)

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 PermissionsConfigPath added in v1.2.3

func PermissionsConfigPath() string

PermissionsConfigPath returns ~/.config/golder/permissions.toml (honoring $XDG_CONFIG_HOME), or "" when no config directory can be resolved.

func ProxyConfigPath

func ProxyConfigPath() string

func SavePermissionsConfig added in v1.2.3

func SavePermissionsConfig(cfg PermissionsConfig) error

SavePermissionsConfig writes the managed store atomically (temp file + rename) with directory mode 0700, mirroring SaveProxyConfig.

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"`
	// Permissions is the [permissions] TOML table: sandbox path grants applied
	// at startup. It is the hand-edited seed; the managed store the UI writes
	// is permissions.toml (see PermissionsConfig), kept separate so a UI save
	// never rewrites this file's comments or credentials.
	Permissions PermissionsConfig `toml:"permissions"`
}

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

type IntOrString struct {
	Set   bool
	IsInt bool
	Int   int
	Str   string
}

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 PermissionsConfig added in v1.2.3

type PermissionsConfig struct {
	WritableRoots []string `toml:"writable_roots"`
}

PermissionsConfig is the [permissions] table. WritableRoots widens the sandbox whitepaper's write side (and, by construction, its read side) for the listed absolute paths; "~/..." expands against the home directory. Relative paths are ignored with a warning at startup.

func LoadPermissionsConfig added in v1.2.3

func LoadPermissionsConfig() (PermissionsConfig, error)

LoadPermissionsConfig reads the managed store. A missing file (or an empty path) is a zero config with no error; a malformed file is an error the caller warns about rather than aborting.

type ProxyConfig

type ProxyConfig struct {
	URL       string   `toml:"url"`
	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 ResolvedMemory

type ResolvedMemory struct {
	Enabled           bool
	ReconcileOnSearch bool
	SearchScoreFloor  float64
	CCIndex           bool
}

ResolvedMemory is MemoryConfig with defaults applied and the score floor clamped to [0,1]. It is the shape downstream memory wiring consumes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL