watch

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 14 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckCmd

func CheckCmd(ctx context.Context, f *Fingerprinter, baseRef string, workingTree bool) tea.Cmd

CheckCmd returns a tea.Cmd that computes the fingerprint asynchronously. The provided context allows cancellation on app shutdown.

func ShouldRefresh

func ShouldRefresh(state *model.AppState, newFingerprint string) bool

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.

func TickCmd

func TickCmd(interval time.Duration) tea.Cmd

TickCmd returns a tea.Cmd that sends a TickMsg after the given interval.

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

func NewDebouncer(interval time.Duration, callback func()) *Debouncer

NewDebouncer creates a debouncer that fires callback after interval of quiet.

func (*Debouncer) Stop added in v0.3.0

func (d *Debouncer) Stop()

Stop cancels any pending callback.

func (*Debouncer) Trigger added in v0.3.0

func (d *Debouncer) Trigger()

Trigger resets the debounce timer. The callback fires 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

func NewFSWatcher(repoRoot, gitDir string, onRefresh func()) *FSWatcher

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.

func (*FSWatcher) Close added in v0.3.0

func (fw *FSWatcher) Close()

Close shuts down the watcher and debouncer. Safe to call multiple times. Waits for both the background walk and event loop goroutines to finish.

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

type Fingerprinter struct {
	Runner gitexec.GitRunner
}

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.

type TickMsg

type TickMsg struct {
	At time.Time
}

TickMsg is sent on each watch interval to trigger a fingerprint check.

Jump to

Keyboard shortcuts

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