history

package
v0.19.4 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 6 Imported by: 0

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

func GetMostRecent(historyPath string) (string, error)

GetMostRecent returns the path of the most recently accessed worktree. Returns empty string if no history exists.

func RecordAccess

func RecordAccess(path, repoName, branch, historyPath string) error

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

func Load(path string) (*History, error)

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

func (h *History) FindByPath(path string) *Entry

FindByPath returns the entry matching the given path, or nil if not found.

func (*History) RemoveByPath added in v0.16.0

func (h *History) RemoveByPath(path string) bool

RemoveByPath removes the entry with the given path. Returns true if an entry was removed.

func (*History) RemoveStale added in v0.16.0

func (h *History) RemoveStale() int

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) Save

func (h *History) Save(path string) error

Save writes the history to disk atomically at the given path.

func (*History) SortByRecency added in v0.16.0

func (h *History) SortByRecency()

SortByRecency sorts entries by LastAccess descending (most recent first).

Jump to

Keyboard shortcuts

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