settings

package
v0.11.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0, MIT Imports: 8 Imported by: 0

Documentation

Overview

Package settings provides a declarative, reflection-based settings system for Overkill, inspired by Warp's define_settings_group! macro.

Settings groups are Go structs with struct tags that describe each field's TOML key, default value, validation bounds, and UI metadata. The package provides runtime helpers for applying defaults, validating, and generating UI schemas — no code generation required (v1).

Struct tags:

setting:"key"       — TOML key name
default:"val"       — default value (parsed to field type)
desc:"help text"    — human-readable description for UI
min:"0"             — minimum value (int/float only)
max:"100"           — maximum value (int/float only)
required:"true"     — must be non-zero

Example:

type AISettings struct {
    Model       string  `setting:"model" default:"claude-sonnet-4-20250514" desc:"AI model"`
    Temperature float64 `setting:"temperature" default:"0.7" min:"0" max:"2"`
    MaxTokens   int     `setting:"max_tokens" default:"4096" min:"1" max:"200000"`
}

Register it with Register("ai", &AISettings{}), then call LoadAll(path) to populate from TOML, apply defaults, and validate.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyDefaults

func ApplyDefaults(ptr any) error

ApplyDefaults sets zero-value fields on the struct to their default values as declared in struct tags. Recurses into nested structs.

func LoadAll

func LoadAll(path string) error

LoadAll is the convenience function on the default registry.

func Register

func Register(key string, ptr any)

Register adds a named settings group to the default registry. ptr must be a pointer to a struct (e.g. &MySettings{}).

func ValidateStruct

func ValidateStruct(ptr any) error

ValidateStruct checks all struct tags on the given pointer for constraint violations. Recurses into nested structs. Returns nil if everything is valid.

Types

type Group

type Group struct {
	Key  string
	Ptr  any // pointer to the settings struct
	Type reflect.Type
}

Group describes a named settings group registered with the system.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry holds all registered settings groups.

func (*Registry) Groups

func (r *Registry) Groups() []Group

Groups returns all registered groups (for UI schema generation, etc.).

func (*Registry) LoadAll

func (r *Registry) LoadAll(path string) error

LoadAll reads a TOML file (or a directory containing settings.toml), applies defaults, and validates all registered groups. The TOML file should have top-level keys matching group keys.

func (*Registry) Register

func (r *Registry) Register(key string, ptr any)

Register adds a settings group to this registry.

func (*Registry) UISchema

func (r *Registry) UISchema() map[string][]SettingUI

UISchema returns UI metadata for all registered settings.

type SettingUI

type SettingUI struct {
	Name        string `json:"name"`
	Key         string `json:"key"`
	Type        string `json:"type"` // "string", "bool", "int", "float"
	Default     string `json:"default"`
	Description string `json:"description"`
	Min         string `json:"min,omitempty"`
	Max         string `json:"max,omitempty"`
	Required    bool   `json:"required"`
}

SettingUI is the metadata for a single setting, used by the settings UI.

func UISchema

func UISchema(ptr any) []SettingUI

UISchema returns UI metadata for a single settings struct. Recurses into nested structs, prefixing keys with the parent field name.

type ThinkingSettings

type ThinkingSettings struct {
	// Level controls how much internal reasoning the model exposes.
	// Supported values: off, minimal, low, medium, high, x-high.
	Level string `setting:"level" default:"off" desc:"Extended thinking budget for the model"`
}

ThinkingSettings defines the UI-editable thinking level configuration. Registered with the settings registry so the TUI settings pane can display it without hardcoding field names.

Jump to

Keyboard shortcuts

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