Documentation
¶
Overview ¶
Package session holds the per-worktree plumbing shared by the session hooks: root resolution, a state directory, an advisory lock, a pending queue for debounced refreshes and the structure hash.
Index ¶
- func Drain(dir string) []string
- func Enqueue(dir string, paths []string) error
- func GitToplevel(cwd string) string
- func HasPending(dir string) bool
- func LoadIndex(root string) (*schema.Index, error)
- func LockStale() time.Duration
- func RecordInjected(dir, sessionID, hash string)
- func Root(cwd string) string
- func Short(s string) string
- func StateDir(root string) string
- func StructureHash(idx *schema.Index) string
- type Injected
- type Lock
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Drain ¶
Drain takes every queued path, deduplicated and sorted, and empties the queue. The file is renamed first so late writers start a fresh queue.
func Enqueue ¶
Enqueue appends paths to the pending file. One small O_APPEND write per call keeps concurrent writers from interleaving.
func GitToplevel ¶
GitToplevel asks git for the worktree root; "" outside a repo. Slower than Root, used where latency is not critical and to cross-check Root in tests.
func HasPending ¶
HasPending reports whether the queue holds anything.
func LockStale ¶
LockStale is how old a lock file must be before it is treated as left by a crashed process. STACKLIT_LOCK_STALE_SEC overrides it.
func RecordInjected ¶
func RecordInjected(dir, sessionID, hash string)
RecordInjected notes the hash handed to a session.
func Root ¶
Root finds the worktree root for cwd without spawning a process: the nearest ancestor holding stacklit.json, else the nearest holding .git (a directory, or a file in a linked worktree). With neither, cwd itself is used, so a repo with no git still works.
func StateDir ¶
StateDir is the per-worktree state location. It is keyed by the absolute root, so every linked worktree and every clone gets its own files.
func StructureHash ¶
StructureHash covers module names, module edges and exported symbol names, nothing else. Line counts, timestamps, purposes and churn are excluded, so an ordinary edit leaves it unchanged and the injected digest stays byte identical (prompt-cache friendly).
Types ¶
type Injected ¶
type Injected struct {
Latest string `json:"latest"`
Sessions map[string]string `json:"sessions,omitempty"`
}
Injected records which structure hash each session was given.
func ReadInjected ¶
ReadInjected loads the record; a missing or damaged file reads as empty.
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock is an advisory lock held by creating a file with O_EXCL, which is atomic on every platform stacklit builds for.