Documentation
¶
Overview ¶
Package history tracks worktree access for ranking and quick navigation. Entries record path, repo name, branch, access count, and last access time. This enables `wt cd` to return to recent worktrees and `wt cd -i` to sort worktrees by recency.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultPath ¶
func DefaultPath() string
DefaultPath returns the default path to the history file.
func GetMostRecent ¶
GetMostRecent returns the path of the most recently accessed worktree. Returns empty string if no history exists.
func RecordAccess ¶
RecordAccess finds or creates an entry for the given path, increments its AccessCount, and updates LastAccess. Caps entries at maxEntries by evicting the oldest.
Types ¶
type Entry ¶ added in v0.16.0
type Entry struct {
Path string `json:"path"`
RepoName string `json:"repo_name"`
Branch string `json:"branch"`
AccessCount int `json:"access_count"`
LastAccess time.Time `json:"last_access"`
}
Entry tracks a single worktree access.
type History ¶
type History struct {
Entries []Entry `json:"entries"`
}
History stores worktree access entries.
func Load ¶
Load reads the history from disk at the given path. Returns empty history if the file doesn't exist. Unrecognized formats (e.g. the old {"most_recent": "..."} schema) decode into an empty History struct because unknown JSON keys are silently dropped.
func (*History) FindByPath ¶ added in v0.16.0
FindByPath returns the entry matching the given path, or nil if not found.
func (*History) RemoveByPath ¶ added in v0.16.0
RemoveByPath removes the entry with the given path. Returns true if an entry was removed.
func (*History) RemoveStale ¶ added in v0.16.0
RemoveStale removes entries whose paths no longer exist on disk. Only entries with os.IsNotExist errors are removed; other stat errors (permissions, NFS timeouts) are kept to avoid purging temporarily inaccessible paths. Returns the number of entries removed.
func (*History) SortByRecency ¶ added in v0.16.0
func (h *History) SortByRecency()
SortByRecency sorts entries by LastAccess descending (most recent first).