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 GetProjectKey(absPath string) string
- func LockPath() (string, error)
- func MutateState(fn func(st *AppState) error) error
- func SavePreferences(prefs Preferences) error
- func StatePath() (string, error)
- type AppState
- type DumpRecord
- type Preferences
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 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 SavePreferences ¶
func SavePreferences(prefs Preferences) error
SavePreferences writes user preferences atomically.
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"`
}
Preferences contains user-level interactive preferences that should survive picker sessions but do not belong to a project's dump history.
func LoadPreferences ¶
func LoadPreferences() (Preferences, error)
LoadPreferences loads user preferences. Missing preferences are normal and return the zero-value preference set.