settings

package
v0.191.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 12 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 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

View Source
const (
	GroupWork   = "work"
	GroupPrompt = "prompt"
)

Groups group the keys by subsystem in the listings (the web page renders one section per group).

View Source
const (
	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"
	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).

View Source
const ExtraHeading = "## 使用者补充"

ExtraHeading separates the instruction (the code default or the replacement) from the operator's extra text, so the model can tell whose words are whose.

View Source
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

View Source
var ErrUnknownKey = errors.New("settings: unknown key")

ErrUnknownKey is returned for a key that is not registered.

Functions

func ChoosePrompt

func ChoosePrompt(def, replacement string) string

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

func ComposePrompt(body, extra string) string

ComposePrompt appends extra to body under ExtraHeading. A blank extra returns body unchanged, so a default prompt is byte-for-byte what the code wrote.

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
	// Description says what the setting does, in Chinese, in one sentence.
	Description string
	// 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 Lookup

func Lookup(key string) (Definition, bool)

Lookup returns the definition of key.

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"
)

func (Kind) Valid

func (k Kind) Valid() bool

Valid reports whether k is a kind the registry may use.

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

func NewService(store *jobstore.Store) *Service

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

func (s *Service) Export() ([]byte, error)

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) Get

func (s *Service) Get(key string) (any, error)

Get returns the effective value of key (string, int, bool or []string).

func (*Service) GetBool

func (s *Service) GetBool(key string) (bool, error)

GetBool returns the effective bool value of key.

func (*Service) GetInt

func (s *Service) GetInt(key string) (int, error)

GetInt returns the effective int value of key.

func (*Service) GetString

func (s *Service) GetString(key string) (string, error)

GetString returns the effective string value of key.

func (*Service) GetStrings

func (s *Service) GetStrings(key string) ([]string, error)

GetStrings returns the effective list value of key (string and regex lists alike).

func (*Service) Import

func (s *Service) Import(document []byte, dryRun bool, by string) (ImportResult, error)

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

func (s *Service) List() ([]Item, error)

List returns every registered key with its effective and stored values, in registry order.

func (*Service) Patterns

func (s *Service) Patterns(key string) ([]*regexp.Regexp, error)

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

func (s *Service) Reset(key string) (bool, error)

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

func (s *Service) Set(key string, v any, by string) (Item, int64, error)

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

func (s *Service) SetCacheTTL(d time.Duration)

SetCacheTTL overrides the cross-process freshness window (tests shrink it).

func (*Service) SetClock

func (s *Service) SetClock(fn func() time.Time)

SetClock overrides the clock (tests).

type ValidationError

type ValidationError struct {
	Key    string
	Reason string
}

ValidationError is a refused value, with the reason a person can act on.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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