Documentation
¶
Overview ¶
Package settings is the extension-settings registry and service: runtime-adjustable knobs (prompts, thresholds, exclusion lists) stored in the database instead of config.yaml, so a change applies immediately without restarting the server.
Design: docs/design/2026-10-20-work-noise-and-db-settings-design.md. The split from config.yaml is deliberate and not to be blurred: what affects startup, security boundaries, connectivity or permissions stays in the configuration file; what only changes an agent's wording, a threshold or a list belongs here, because it must take effect at once and a bad edit must be revertible at once.
Every key is registered in this package (name, type, default, description, validation and bounds, whether it is multiline). The registry is the single source of truth: a value that is not registered cannot be stored, and the HTTP / CLI entry points render the registry as-is (the web settings page is generated from it). The service reads "the database value, else the default" and caches the snapshot by generation:
- a write of THIS process is visible to the next read at once (the cache is refreshed on the write path),
- a write of ANOTHER process is picked up within the cache TTL (5s by default), the same contract the authorization cache has (auth_meta.grants_version).
Index ¶
- Constants
- Variables
- func ChoosePrompt(def, replacement string) string
- func ComposePrompt(lang i18n.Lang, body, extra string) string
- func ExtraHeadingIn(lang i18n.Lang) string
- type Change
- type Definition
- type ImportResult
- type Item
- type Kind
- type Service
- func (s *Service) Export() ([]byte, error)
- func (s *Service) Get(key string) (any, error)
- func (s *Service) GetBool(key string) (bool, error)
- func (s *Service) GetInt(key string) (int, error)
- func (s *Service) GetString(key string) (string, error)
- func (s *Service) GetStrings(key string) ([]string, error)
- func (s *Service) Import(document []byte, dryRun bool, by string) (ImportResult, error)
- func (s *Service) List() ([]Item, error)
- func (s *Service) ListIn(lang i18n.Lang) ([]Item, error)
- func (s *Service) Patterns(key string) ([]*regexp.Regexp, error)
- func (s *Service) Reset(key string) (bool, error)
- func (s *Service) Set(key string, v any, by string) (Item, int64, error)
- func (s *Service) SetCacheTTL(d time.Duration)
- func (s *Service) SetClock(fn func() time.Time)
- func (s *Service) SetIn(lang i18n.Lang, key string, v any, by string) (Item, int64, error)
- type ValidationError
Constants ¶
const ( GroupWork = "work" GroupPrompt = "prompt" GroupWeb = "web" )
Groups group the keys by subsystem in the listings (the web page renders one section per group).
const ( // The four work.draft.* keys have no consumer since sessions stopped creating work items // (design 2026-11-01 §4.2); they stay readable so an old settings export still imports. // DEPRECATED(v0.208): remove in v0.211 KeyWorkDraftMinPrompts = "work.draft.min_prompts" KeyWorkDraftExcludeProjects = "work.draft.exclude_projects" KeyWorkDraftExcludeCwds = "work.draft.exclude_cwds" KeyWorkDraftExcludeTitlePatterns = "work.draft.exclude_title_patterns" KeyWorkShortSessionMaxMinutes = "work.short_session.max_minutes" KeyWorkShortSessionMaxPrompts = "work.short_session.max_prompts" KeyStewardActProactively = "steward.act_proactively" KeyPromptStewardRole = "prompt.steward.role" KeyPromptStewardRoleExtra = "prompt.steward.role.extra" KeyPromptStewardReview = "prompt.steward.review" KeyPromptStewardReviewExtra = "prompt.steward.review.extra" KeyPromptWorkSummarizer = "prompt.work.summarizer" KeyPromptWorkSummarizerExtra = "prompt.work.summarizer.extra" )
Registry keys. Handlers, planners and tests spell keys through these constants rather than repeating string literals (the names are published, they never change).
const MaxPromptLen = 32 * 1024
MaxPromptLen caps a prompt setting (32 KiB): a prompt is sent with every summarize / steward run, so a runaway paste must not bloat every job.
Variables ¶
var ErrUnknownKey = errors.New("settings: unknown key")
ErrUnknownKey is returned for a key that is not registered.
Functions ¶
func ChoosePrompt ¶
ChoosePrompt returns replacement when it holds anything but whitespace, else def. The replacement is kept verbatim (an empty key means "use the default").
func ComposePrompt ¶
ComposePrompt appends extra to body under ExtraHeadingIn(lang). A blank extra returns body unchanged, so a default prompt is byte-for-byte what the code wrote.
func ExtraHeadingIn ¶ added in v0.206.0
ExtraHeadingIn separates the instruction (the code default or the replacement) from the operator's extra text, so the model can tell whose words are whose. It is in lang, the language of the prompt it sits in (catalog key settings.prompt.extra_heading).
Types ¶
type Change ¶
type Change struct {
Key string `json:"key"`
// Action is "set", "reset" (the file removes the key / leaves it empty and the key is
// currently modified) or "unchanged".
Action string `json:"action"`
Old any `json:"old"`
New any `json:"new"`
Error string `json:"error,omitempty"`
}
Change is one key of an import: what the file asks for and what the store says.
type Definition ¶
type Definition struct {
// Key is `<subsystem>.<name>`, e.g. `work.draft.min_prompts`.
Key string
// Group is the subsystem the key is listed under.
Group string
// Kind is the value type.
Kind Kind
// Default is the value used when the key has no database row (same Go type as Kind:
// string, int, bool, []string).
Default any
// Min / Max bound an int setting (inclusive).
Min int
Max int
// MaxLen bounds a string setting in bytes.
MaxLen int
// Multiline marks a long text (a prompt) the editors open in a textarea.
Multiline bool
}
Definition registers one setting. It is the single description of a key: the default, the validation, and everything the listings show.
func Definitions ¶
func Definitions() []Definition
Definitions returns the registry in listing order (a copy: callers may sort it).
func (Definition) DescriptionIn ¶ added in v0.207.0
func (d Definition) DescriptionIn(lang i18n.Lang) string
DescriptionIn says what the setting does, in one sentence, in lang (the catalog's settings.desc.*: the key with its dots written as underscores).
type ImportResult ¶
type ImportResult struct {
DryRun bool `json:"dry_run"`
Applied bool `json:"applied"`
Changes []Change `json:"changes"`
// Errors counts the refused keys (they are also marked in Changes).
Errors int `json:"errors"`
}
ImportResult is the answer of Import: the per-key differences and whether they were written (dry run leaves everything untouched, including the ones that failed validation).
type Item ¶
type Item struct {
Key string `json:"key"`
Group string `json:"group"`
Kind Kind `json:"kind"`
Description string `json:"description"`
Default any `json:"default"`
// Value is the effective value: the stored one, else the default.
Value any `json:"value"`
// Modified reports whether the key has a stored value (that is, it was changed from —
// or explicitly set to — the default).
Modified bool `json:"modified"`
Multiline bool `json:"multiline,omitempty"`
Min *int `json:"min,omitempty"`
Max *int `json:"max,omitempty"`
MaxLen int `json:"max_len,omitempty"`
// UpdatedBy / UpdatedAt describe the last write of a modified key.
UpdatedBy string `json:"updated_by,omitempty"`
UpdatedAt int64 `json:"updated_at,omitempty"`
}
Item is one key as a listing shows it: the definition plus the effective and stored values.
type Kind ¶
type Kind string
Kind is the type of a setting's value. The kind decides how the value is stored (its text form) and what Set accepts.
const ( // KindString is free text. max_len bounds it; Multiline marks the prompt keys the web // editor opens in a textarea. KindString Kind = "string" // KindInt is an integer in [Min, Max]. KindInt Kind = "int" // KindBool is true / false. KindBool Kind = "bool" // KindStrings is a list of strings (project keys, cwd prefixes, …). KindStrings Kind = "strings" // KindPatterns is a list of regular expressions, compiled on save: an expression that // does not compile is refused with the compiler's reason. KindPatterns Kind = "patterns" )
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service reads and writes the settings through a job store, with a generation-keyed cache.
func NewService ¶
NewService builds the service over store. store may be nil for a server without a database (MCP / bare tests): reads answer with the defaults and writes fail.
func (*Service) Export ¶
Export renders the MODIFIED keys as YAML, one `key: <value>` line per key (a value in JSON form, which is valid YAML too). Only modified keys are exported, so an export / import round trip carries the operator's changes and nothing that is the code default — the defaults follow the binary, exactly like a key nobody touched.
func (*Service) GetStrings ¶
GetStrings returns the effective list value of key (string and regex lists alike).
func (*Service) Import ¶
Import applies (or, with dryRun, only reports) the keys of a YAML document. Every key is validated on its own: a refused key is reported and left alone, the others still apply. A key whose value is null or an empty string is reset to the default.
func (*Service) List ¶
List returns every registered key with its effective and stored values, in registry order.
func (*Service) ListIn ¶ added in v0.207.0
ListIn is List with the descriptions in lang (the request language of the settings page).
func (*Service) Patterns ¶
Patterns returns the compiled regular expressions of a KindPatterns key. Saving already refused anything that does not compile, so an error here means a stored value was edited outside the service.
func (*Service) Reset ¶
Reset deletes the stored value of key, so the registry default applies again. It reports whether a value was stored (a reset of an unmodified key is a no-op).
func (*Service) Set ¶
Set validates v against key's definition and stores it. It returns the item as a listing shows it (effective value, modified=true) and the new generation.
func (*Service) SetCacheTTL ¶
SetCacheTTL overrides the cross-process freshness window (tests shrink it).
type ValidationError ¶
ValidationError is a refused value, with the reason a person can act on.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string