session

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Drain

func Drain(dir string) []string

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

func Enqueue(dir string, paths []string) error

Enqueue appends paths to the pending file. One small O_APPEND write per call keeps concurrent writers from interleaving.

func GitToplevel

func GitToplevel(cwd string) string

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

func HasPending(dir string) bool

HasPending reports whether the queue holds anything.

func LoadIndex

func LoadIndex(root string) (*schema.Index, error)

LoadIndex reads stacklit.json under root.

func LockStale

func LockStale() time.Duration

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

func Root(cwd string) string

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 Short

func Short(s string) string

Short trims a commit id for display.

func StateDir

func StateDir(root string) string

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

func StructureHash(idx *schema.Index) string

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

func ReadInjected(dir string) Injected

ReadInjected loads the record; a missing or damaged file reads as empty.

func (Injected) For

func (r Injected) For(sessionID string) string

For returns the hash given to sessionID, or the latest one when id is empty or unknown.

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.

func TryLock

func TryLock(dir string) (*Lock, error)

TryLock returns (nil, nil) when another live process holds the lock.

func (*Lock) Touch

func (l *Lock) Touch()

Touch refreshes the lock mtime so a long run is not mistaken for a crash.

func (*Lock) Unlock

func (l *Lock) Unlock()

Unlock releases the lock.

Jump to

Keyboard shortcuts

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