settings

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 24 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 keeps the runtime's settings files as the previous runtime did: the person's preferences in the config file (with the pair's secret and the automation token beside them), keyboard shortcuts, quick prompts, sidebar items and each workspace's sent messages. Same files, same bytes, same locks: this package is the one writer of these files in the process.

Index

Constants

View Source
const Slice = "state"

Slice is the gate slice of these routes.

Variables

View Source
var Actions = []string{"workspace.new", "workspace.rename", "workspace.switch", "tab.new", "tab.close", "tab.prev", "tab.next",
	"tab.goto", "pane.split_right", "pane.split_down", "pane.focus_left", "pane.focus_right", "pane.focus_up", "pane.focus_down",
	"pane.clear_screen", "pane.resize_left", "pane.resize_right", "pane.resize_up", "pane.resize_down", "pane.equalize",
	"panel.focus_input", "view.toggle_sidebar", "view.toggle_sidebar_tab", "view.notes", "view.stats", "view.mode_terminal",
	"view.mode_claude", "view.mode_codex", "view.mode_diff", "app.settings", "app.voice_hold", "app.new_window"}

Actions are the ids of the page's keyboard actions.

View Source
var ErrNotObject = errors.New("settings: the config is not an object")

ErrNotObject: the config file holds a string, a number or a boolean: the previous runtime failed to stamp it.

Functions

func Answer

func Answer(r *http.Request, status int, v any, h http.Header) (int, any, http.Header)

Answer is a JSON answer as the previous dispatcher sent it: its ETag, and 304 when the caller holds it already (the 304 keeps the JSON content type the handler had set).

func AnswerRaw

func AnswerRaw(r *http.Request, status int, contentType string, body []byte, h http.Header) (int, any, http.Header)

AnswerRaw is a body the dispatcher sent as bytes: its ETag over them, and 304 when the caller holds it already.

func Guarded

func Guarded(refusal func(*http.Request) (int, any, http.Header, bool), h Handler) func(*http.Request) (int, any, http.Header)

Guarded runs a handler behind the previous dispatcher: the session or cli-token check, then the body (parsed for every method, as the dispatcher did).

func HashPassword

func HashPassword(plain string) string

HashPassword is a stored password for plain with a random salt.

func IsHashedPassword

func IsHashedPassword(v any) bool

IsHashedPassword says whether a stored password is a hash this runtime can check.

func Query

func Query(r *http.Request, name string) jscompat.Param

Query is req.query[name] of the request as sent.

func Routes

func Routes(cfg Config) []gate.JSONRoute

Routes are the slice's routes; their GETs also run in the "state-shadow" slice.

func Spread

func Spread(o *jsvalue.Object, v any)

Spread copies what {...v} copies of a JSON value onto o: an object's keys, an array's or a string's elements under their indices; nothing of a number, a boolean or null.

func VerifyPassword

func VerifyPassword(plain, stored string) bool

VerifyPassword checks plain against a stored hash; anything that is not one never matches.

Types

type Config

type Config struct {
	Store *Store
	// LayoutKey is the config's field of the workspace's column widths, DefaultsKey the one of the remembered launch
	// choices per agent CLI.
	LayoutKey, DefaultsKey string
	// AccessHost is the deployment's explicit access rule (the previous runtime's HOST); "" when there is none.
	AccessHost string
	// BindsLoopback: the previous runtime would have listened on the loopback address only.
	BindsLoopback bool
	// ValidateLaunch checks a launch choice against this machine's catalog (nil when the shape is "Auto").
	ValidateLaunch func(provider string, model, effort any) (*agents.Launch, string)
	APIRefusal     func(*http.Request) (status int, body any, h http.Header, refused bool)
}

Config is what the routes need; product names come from the deployment.

type Handler

type Handler func(r *http.Request, body any) (int, any, http.Header)

Handler is a route's own part, after the dispatcher's authorization and body parsing.

type Store

type Store struct {
	DataDir    string
	ConfigFile string
	Now        func() time.Time
	// RandomBytes are n random bytes (crypto/rand when nil).
	RandomBytes func(n int) []byte
	// NewID is a sent message's id (nanoid's 21 characters when nil).
	NewID func() string
	// contains filtered or unexported fields
}

Store is the settings files of one data folder.

func (*Store) AddMessage

func (s *Store) AddMessage(wsID, message string) (*jsvalue.Object, error)

AddMessage puts a sent message first (the same text sent before moves up) and returns its entry.

func (*Store) AutomationToken

func (s *Store) AutomationToken() (any, error)

AutomationToken is getOrCreateAutomationApiToken: the config's token (whatever value a truthy one is), made and saved on first use.

func (*Store) ChangeConfig

func (s *Store) ChangeConfig(change func(*jsvalue.Object)) error

ChangeConfig reads the config under its lock, lets change edit it and writes it back. A config that is an array is changed as the object it spreads to and written back as the array it is (JavaScript kept the named fields off the JSON); one that is a string or a number takes no change and fails to be stamped, unless there is nothing to write.

func (*Store) Config

func (s *Store) Config() any

Config is getConfig: the file, or a fresh one stamped now when there is none.

func (*Store) ConfigObject

func (s *Store) ConfigObject() *jsvalue.Object

ConfigObject is the config as an object; a config that is not one has no fields.

func (*Store) DeleteMessage

func (s *Store) DeleteMessage(wsID string, id any) error

DeleteMessage drops the entries with that id (an id of another kind than the entries' matches none).

func (*Store) HashPassword

func (s *Store) HashPassword(plain string) string

HashPassword is a stored password for plain, salted from the store's randomness.

func (*Store) Keybindings

func (s *Store) Keybindings() *jsvalue.Object

Keybindings is readKeybindings: the file sanitized, or no overrides.

func (*Store) MessageHistory

func (s *Store) MessageHistory(wsID string) []any

MessageHistory is a workspace's sent messages as the file holds them.

func (*Store) QuickPrompts

func (s *Store) QuickPrompts() *jsvalue.Object

QuickPrompts is readQuickPrompts: the file's view; a flat list is migrated and written back first; defaults when the file is missing or cannot be shown.

func (*Store) ReadConfig

func (s *Store) ReadConfig() any

ReadConfig is the config file as JSON.parse read it; nil when it is missing, does not parse, or holds null.

func (*Store) ResetAllKeybindings

func (s *Store) ResetAllKeybindings() (*jsvalue.Object, error)

ResetAllKeybindings drops every override.

func (*Store) ResetKeybinding

func (s *Store) ResetKeybinding(id string) (*jsvalue.Object, error)

ResetKeybinding drops one action's override.

func (*Store) Secret

func (s *Store) Secret() string

Secret is 32 random bytes in hex, as the previous runtime made its secrets.

func (*Store) SetKeybinding

func (s *Store) SetKeybinding(id string, key any) (*jsvalue.Object, error)

SetKeybinding sets one action's key (null: no key) and returns the file written.

func (*Store) SidebarItems

func (s *Store) SidebarItems() *jsvalue.Object

SidebarItems is readSidebarItems: the file's view, or defaults.

func (*Store) UpdateConfig

func (s *Store) UpdateConfig(updates *jsvalue.Object) error

UpdateConfig is updateConfig: under the config lock, the file's fields with the updates assigned over them.

func (*Store) ValidWorkspace

func (s *Store) ValidWorkspace(wsID string) bool

ValidWorkspace says whether a workspace id names a folder inside the workspaces folder.

func (*Store) WriteQuickPrompts

func (s *Store) WriteQuickPrompts(body any) error

WriteQuickPrompts writes what the page sent, as it sent it.

func (*Store) WriteSidebarItems

func (s *Store) WriteSidebarItems(body any) error

WriteSidebarItems writes what the page sent, as it sent it.

Jump to

Keyboard shortcuts

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