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
- Variables
- func Answer(r *http.Request, status int, v any, h http.Header) (int, any, http.Header)
- func AnswerRaw(r *http.Request, status int, contentType string, body []byte, h http.Header) (int, any, http.Header)
- func Guarded(refusal func(*http.Request) (int, any, http.Header, bool), h Handler) func(*http.Request) (int, any, http.Header)
- func HashPassword(plain string) string
- func IsHashedPassword(v any) bool
- func Query(r *http.Request, name string) jscompat.Param
- func Routes(cfg Config) []gate.JSONRoute
- func Spread(o *jsvalue.Object, v any)
- func VerifyPassword(plain, stored string) bool
- type Config
- type Handler
- type Store
- func (s *Store) AddMessage(wsID, message string) (*jsvalue.Object, error)
- func (s *Store) AutomationToken() (any, error)
- func (s *Store) ChangeConfig(change func(*jsvalue.Object)) error
- func (s *Store) Config() any
- func (s *Store) ConfigObject() *jsvalue.Object
- func (s *Store) DeleteMessage(wsID string, id any) error
- func (s *Store) HashPassword(plain string) string
- func (s *Store) Keybindings() *jsvalue.Object
- func (s *Store) MessageHistory(wsID string) []any
- func (s *Store) QuickPrompts() *jsvalue.Object
- func (s *Store) ReadConfig() any
- func (s *Store) ResetAllKeybindings() (*jsvalue.Object, error)
- func (s *Store) ResetKeybinding(id string) (*jsvalue.Object, error)
- func (s *Store) Secret() string
- func (s *Store) SetKeybinding(id string, key any) (*jsvalue.Object, error)
- func (s *Store) SidebarItems() *jsvalue.Object
- func (s *Store) UpdateConfig(updates *jsvalue.Object) error
- func (s *Store) ValidWorkspace(wsID string) bool
- func (s *Store) WriteQuickPrompts(body any) error
- func (s *Store) WriteSidebarItems(body any) error
Constants ¶
const Slice = "state"
Slice is the gate slice of these routes.
Variables ¶
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.
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 ¶
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 ¶
HashPassword is a stored password for plain with a random salt.
func IsHashedPassword ¶
IsHashedPassword says whether a stored password is a hash this runtime can check.
func Spread ¶
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 ¶
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 ¶
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 ¶
AddMessage puts a sent message first (the same text sent before moves up) and returns its entry.
func (*Store) AutomationToken ¶
AutomationToken is getOrCreateAutomationApiToken: the config's token (whatever value a truthy one is), made and saved on first use.
func (*Store) ChangeConfig ¶
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 ¶
Config is getConfig: the file, or a fresh one stamped now when there is none.
func (*Store) ConfigObject ¶
ConfigObject is the config as an object; a config that is not one has no fields.
func (*Store) DeleteMessage ¶
DeleteMessage drops the entries with that id (an id of another kind than the entries' matches none).
func (*Store) HashPassword ¶
HashPassword is a stored password for plain, salted from the store's randomness.
func (*Store) Keybindings ¶
Keybindings is readKeybindings: the file sanitized, or no overrides.
func (*Store) MessageHistory ¶
MessageHistory is a workspace's sent messages as the file holds them.
func (*Store) QuickPrompts ¶
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 ¶
ReadConfig is the config file as JSON.parse read it; nil when it is missing, does not parse, or holds null.
func (*Store) ResetAllKeybindings ¶
ResetAllKeybindings drops every override.
func (*Store) ResetKeybinding ¶
ResetKeybinding drops one action's override.
func (*Store) SetKeybinding ¶
SetKeybinding sets one action's key (null: no key) and returns the file written.
func (*Store) SidebarItems ¶
SidebarItems is readSidebarItems: the file's view, or defaults.
func (*Store) UpdateConfig ¶
UpdateConfig is updateConfig: under the config lock, the file's fields with the updates assigned over them.
func (*Store) ValidWorkspace ¶
ValidWorkspace says whether a workspace id names a folder inside the workspaces folder.
func (*Store) WriteQuickPrompts ¶
WriteQuickPrompts writes what the page sent, as it sent it.
func (*Store) WriteSidebarItems ¶
WriteSidebarItems writes what the page sent, as it sent it.