Documentation
¶
Overview ¶
Package watch provides fingerprint calculation and tick scheduling for watch mode. It detects repository state changes by computing fingerprints and comparing them across ticks.
Index ¶
- func CheckCmd(ctx context.Context, f *Fingerprinter, baseRef string, workingTree bool) tea.Cmd
- func ShouldRefresh(state *model.AppState, newFingerprint string) bool
- func TickCmd(interval time.Duration) tea.Cmd
- type Debouncer
- type FSEventMsg
- type FSWatcher
- type FingerprintMsg
- type Fingerprinter
- type TickMsg
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckCmd ¶
CheckCmd returns a tea.Cmd that computes the fingerprint asynchronously. The provided context allows cancellation on app shutdown.
func ShouldRefresh ¶
ShouldRefresh returns true when the fingerprint has changed and no refresh is already in flight. This implements the debounce/in-flight rule: skip refresh while one is running, reevaluate on next tick.
Types ¶
type Debouncer ¶ added in v0.3.0
type Debouncer struct {
// contains filtered or unexported fields
}
Debouncer collapses rapid events into a single callback after a quiet period.
func NewDebouncer ¶ added in v0.3.0
NewDebouncer creates a debouncer that fires callback after interval of quiet.
type FSEventMsg ¶ added in v0.3.0
type FSEventMsg struct{}
FSEventMsg is sent by the fsnotify watcher when file changes are detected. It triggers an immediate fingerprint check, bypassing the polling timer.
type FSWatcher ¶ added in v0.3.0
type FSWatcher struct {
// contains filtered or unexported fields
}
FSWatcher wraps fsnotify to watch a repo root for file changes. It debounces events and calls onRefresh when changes settle.
func NewFSWatcher ¶ added in v0.3.0
NewFSWatcher creates an fsnotify watcher on the repo root and git directory. gitDir should be the resolved per-worktree git dir (from RepoContext.GitDir). Returns nil if the watcher cannot be initialized (caller falls back to polling). The recursive directory walk runs asynchronously to avoid blocking startup.
type FingerprintMsg ¶
type FingerprintMsg struct {
Fingerprint string
Err error
FromFS bool // true when triggered by fsnotify (don't reschedule polling tick)
Gen int // monotonic generation; stale results (Gen != current) are discarded
}
FingerprintMsg carries the result of a fingerprint check.
type Fingerprinter ¶
Fingerprinter computes a change fingerprint for the current repo state. The fingerprint is compare-mode aware:
- Committed-ref mode: concatenates rev-parse of HEAD and base ref.
- Working-tree mode: additionally hashes the full patch output to detect any content change, including edits to already-dirty files.
func (*Fingerprinter) Fingerprint ¶
func (f *Fingerprinter) Fingerprint(ctx context.Context, baseRef string, workingTree bool) (string, error)
Fingerprint returns a string that changes whenever the repository state relevant to the current compare changes. baseRef must be a symbolic ref (e.g., "origin/main") so that rev-parse resolves it live on each tick. Passing an already-resolved SHA would make the base half of the fingerprint static.