Documentation
¶
Overview ¶
Package settings provides a single-source-of-truth reader for <configDir>/config.json. All packages that need to extract a key from the user's settings file should use ReadBytes or Field rather than implementing their own open+read+unmarshal pattern.
ReadBytes returns the raw bytes with mtime-based caching and size capping (1 MiB). Field extracts a single typed key via generics.
Index ¶
- Constants
- Variables
- func DefaultAgentIgnoreFiles() []string
- func DefaultSettings() map[string]any
- func Field[T any](ctx context.Context, configDir, key, tag string) (T, bool)
- func FieldInto(ctx context.Context, configDir, key, tag string, out any) bool
- func ReadBytes(ctx context.Context, configDir string) ([]byte, error)
- func ServerManagedKeys() []string
- func WarnUnknownKeys(keys []string, source string) []string
Constants ¶
const ( KeyAgentIgnoreFiles = "agent_ignore_files" KeyChatRetentionDays = "chat_retention_days" KeyDebugLogs = "debug_logs" KeyLastModel = "last_model" KeyModelEffort = "model_effort" KeyNotificationsEnabled = "notifications_enabled" KeyNotifyAgentFinished = "notify_agent_finished" KeyNotifyPermission = "notify_permission" KeySupervisedDefault = "supervised_default" )
Exported constants for settings key names. All consumers should reference these instead of bare string literals to prevent drift.
const DefaultChatRetentionDays = 1
DefaultChatRetentionDays is the seeded default for chat_retention_days.
vibekit owns chat retention end to end (kiro-cli's own cleanup.periodDays is pinned to 0/never so the two systems never both purge). The value is a day count with two sentinels:
-1 = forever — closing a tab archives to History; never purged ("backups").
0 = off — closing a tab deletes the chat (ephemeral); History hidden.
N = keep N days — archive on close; the purge scheduler removes after N days.
The server purge scheduler treats <= 0 as "no purge" (off AND forever); the client decides archive-vs-delete on close from the same value (enabled when != 0). Default 1 preserves the prior 1-day behavior.
const Filename = filename
Filename is the on-disk basename of vibekit's primary config file (vibekit-managed settings — debug_logs, agent_ignore_files, supervised_default, etc.). Distinct from kiro-cli's settings.json which lives under $KIRO_HOME/settings/. Exported so callers across the codebase (tests, server handler, ignore reader) reference the same canonical name and can't drift.
const MaxBytes = 1 << 20
MaxBytes caps config.json reads. Real settings files are well under 100 KB; 1 MiB is generous headroom and matches the HTTP PUT path's api.MaxJSONBody limit.
Variables ¶
var KnownKeys = map[string]struct{}{ KeyAgentIgnoreFiles: {}, KeyChatRetentionDays: {}, KeyDebugLogs: {}, KeyLastModel: {}, KeyModelEffort: {}, KeyNotificationsEnabled: {}, KeyNotifyAgentFinished: {}, KeyNotifyPermission: {}, KeySupervisedDefault: {}, }
KnownKeys is the set of vibekit-managed config.json keys. PATCH handlers warn (but do not reject) keys outside this set so a typo or stray field surfaces in operator logs without breaking forward compatibility with newer frontend versions that introduce new keys before this list is updated. Add new keys here when the frontend's `AppSettings` interface grows.
Note: kiro-cli's own settings (cleanup.periodDays, chat.enable*, etc.) live in a separate file ($KIRO_HOME/settings/settings.json) and are not part of this set.
Functions ¶
func DefaultAgentIgnoreFiles ¶ added in v0.1.165
func DefaultAgentIgnoreFiles() []string
DefaultAgentIgnoreFiles is the seeded default for the agent_ignore_files setting: the ignore-file basenames the agent read filter (internal/ignore, wired into the fs/read_text_file A→C path) applies, each resolved against the workspace root. A fresh install — no config.json, or a config.json that predates the key — uses this list so gitignored secrets (.env.dec, anything under a gitignored secrets/ dir) are refused from agent reads out of the box instead of the filter being opt-in.
The names track the Kiro IDE's recognized ignore-file set (its context walker keys on .gitignore/.continueignore/.kiroignore/.cursorignore). We seed the two relevant to this stack — .gitignore (the universal exclude file) and .kiroignore (Kiro's own) — and skip the competitor-tool files. This is deliberately MORE protective than the IDE's own out-of-box behavior: the IDE's kiroAgent.agentIgnoreFiles setting is undeclared and read as `get("agentIgnoreFiles") ?? []`, so the IDE filters agent reads only through the always-on user-global ~/.kiro/settings/kiroignore + git global excludes, not workspace .gitignore. Turning the workspace filter ON by default is the settled vibekit decision.
Returns a fresh slice so callers can resolve/append without mutating the shared default. An explicit [] in config.json is honoured as an opt-out (see internal/ignore).
func DefaultSettings ¶
DefaultSettings returns the canonical defaults the GET /api/settings handler emits when config.json is missing or unreadable. Every key it emits must also be in KnownKeys (enforced by TestDefaultSettings_OnlyKnownKeys) so a fresh GET response round-tripped back as a PATCH never trips the unknown-key warning.
agent_ignore_files carries a real default (DefaultAgentIgnoreFiles) so the agent read filter is ON out of the box and the GET-when-missing wire shape advertises it. Preferences NOT listed here apply their default in-process near their consumer (e.g. logctl.go's false for debug_logs) because the consumer owns the fail-mode policy; those need not ride this wire shape.
func Field ¶
Field reads config.json, extracts the named key, and json-unmarshals it into the target type T. Returns the zero value and false when the file is missing, the key is absent, or parsing fails. Parse failures are logged at Warn level with the provided tag for diagnostics.
func FieldInto ¶
FieldInto reads config.json, extracts the named key, and json-unmarshals it into the value pointed to by out. Returns true on success. This is the pointer-based variant of Field for callers that need to unmarshal into an existing variable.
func ReadBytes ¶
ReadBytes returns the raw config.json content for configDir with mtime-based caching. Returns (nil, nil) when the file is missing or configDir is empty.
func ServerManagedKeys ¶ added in v0.1.165
func ServerManagedKeys() []string
ServerManagedKeys are settings keys owned by flows other than a full-file PUT of the settings object: agent_ignore_files (written by the Settings→Permissions UI) and model_effort (written by the model switcher), both via PATCH. A PUT whose body omits them must not silently wipe them, so handleSettingsWrite carries any omitted managed key over from the existing file. Kept beside KnownKeys so the managed-key set stays in the settings domain and references the same key constants (no drift).
func WarnUnknownKeys ¶
WarnUnknownKeys logs a warning for each top-level key in keys that isn't recognized by KnownKeys. Returns the slice of unknown keys for callers that want to surface them in HTTP responses or telemetry; the slice is sorted-stable nil when every key is known. source identifies the call site for log correlation (e.g. "PATCH /api/settings", "PUT /api/settings").
Types ¶
This section is empty.