Documentation
¶
Overview ¶
Package state persists per-project dump records in the user's application data directory so delta dumps can know the last commit a project was dumped from, without polluting the repository itself.
Index ¶
- func CanonicalRoot(rootDir string) (string, error)
- func EffectiveTheme(p Preferences) string
- func GetProjectKey(absPath string) string
- func LockPath() (string, error)
- func MutateState(fn func(st *AppState) error) error
- func RecordRecent(root string)
- func RemoveRecent(root string) error
- func SavePreferences(prefs Preferences) error
- func SetTheme(id string) error
- func StatePath() (string, error)
- type AppState
- type DumpRecord
- type Preferences
- type Recent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CanonicalRoot ¶ added in v1.3.0
CanonicalRoot resolves rootDir to the absolute, cleaned path every state-key site must use. Writers (record) and readers (delta, diff, picker) share this helper so a dump recorded as "." is found again as ".", an absolute path, or any equivalent spelling.
func EffectiveTheme ¶ added in v1.4.0
func EffectiveTheme(p Preferences) string
EffectiveTheme resolves the single shared theme id: Theme wins, with the legacy UITheme as fallback for files written before unification. Empty means the default theme; "system" means follow the OS (web only, the TUI falls back to its default).
func GetProjectKey ¶
GetProjectKey returns a stable 16-hex-char key for an absolute project path.
func LockPath ¶ added in v1.3.0
LockPath returns the advisory lock file alongside state.json. It must be held across every read-modify-write so concurrent processes (e.g. a watch session and a manual dump) cannot clobber each other's records.
func MutateState ¶ added in v1.3.0
MutateState runs fn inside a cross-process file lock plus the in-process mutex, loading the state, applying fn, and saving atomically. All state mutations must go through here; Load/Save remain for lock-free reads and single-shot writes.
func RecordRecent ¶ added in v1.4.0
func RecordRecent(root string)
RecordRecent moves root to the front of the shared recents list, refreshing its branch and timestamp. It never fails the caller: state bookkeeping must not break a project open.
func RemoveRecent ¶ added in v1.4.0
RemoveRecent drops root from the shared recents list.
func SavePreferences ¶
func SavePreferences(prefs Preferences) error
SavePreferences writes user preferences atomically, sanitizing first.
Types ¶
type AppState ¶
type AppState struct {
Projects map[string]DumpRecord `json:"projects"`
}
AppState holds the dump record of every project that has been dumped, keyed by GetProjectKey.
func (*AppState) Get ¶
func (s *AppState) Get(key string) (DumpRecord, bool)
Get returns the dump record for a project key, if present.
type DumpRecord ¶
type DumpRecord struct {
LastCommitHash string `json:"last_commit_hash"`
LastCommitMsg string `json:"last_commit_msg"`
DumpTimestamp time.Time `json:"dump_timestamp"`
FilesDumped int `json:"files_dumped"`
TokensDumped int `json:"tokens_dumped"`
}
DumpRecord describes the most recent dump of a project.
type Preferences ¶
type Preferences struct {
UITheme string `json:"ui_theme,omitempty"`
// Theme is the web UI theme id ([a-z0-9-]{1,32}); "system" follows the OS.
Theme string `json:"theme,omitempty"`
// DefaultStyle is the default output style (xml, markdown, plain).
DefaultStyle string `json:"default_style,omitempty"`
// DefaultBudget is the default token budget for fresh sessions.
DefaultBudget int `json:"default_budget,omitempty"`
// ShowHidden reveals dotfiles in the serve folder browser. Default hides them.
ShowHidden bool `json:"show_hidden,omitempty"`
// FileSort orders the serve folder browser: "name" (default) or "updated".
FileSort string `json:"file_sort,omitempty"`
}
Preferences contains user-level interactive preferences that should survive picker sessions but do not belong to a project's dump history. The TUI and `sift serve` share this file: theme ids and defaults set in either surface take effect in both.
func LoadPreferences ¶
func LoadPreferences() (Preferences, error)
LoadPreferences loads user preferences. Missing preferences are normal and return the zero-value preference set.
func SanitizePreferences ¶ added in v1.4.0
func SanitizePreferences(p Preferences) Preferences
type Recent ¶ added in v1.4.0
type Recent struct {
Root string `json:"root"`
Name string `json:"name"`
LastOpened string `json:"last_opened"`
Branch string `json:"branch,omitempty"`
}
Recent is one entry in the shared recent-projects list.
func ListRecents ¶ added in v1.4.0
ListRecents returns the shared recent-projects list, most recent first. A corrupt file resets to empty so one bad write never wedges the UI.