watch

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package watch keeps a Mesh index live with the vault on disk. It is the local-first, Obsidian-like immediacy of Milestone S0: edit a note in your editor and it is searchable at once, no commit, no manual `mesh index`.

The design mirrors Milestone S's "reconcile-first" principle at local scale. The periodic reconcile is the primary consistency mechanism: it runs the same authoritative content-hash drift check `mesh doctor` uses, so it always converges and a missed or dropped file event never leaves lasting drift. The fsnotify event stream is a best-effort speedup layered on top, debounced so a burst of editor saves collapses into one reindex. The expensive reindex runs single-flight on one goroutine and only rebuilds when retrieval-relevant content actually changed, so an idle vault costs nothing but a cheap scan.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, opt Options) error

Run watches opt.Root until ctx is cancelled, calling opt.OnReindex whenever the vault changes (debounced) and on a periodic safety tick. It reconciles once at startup so the index reflects disk from the first moment. Run blocks; callers typically run it in a goroutine alongside their main loop.

Types

type Options

type Options struct {
	Root      string                                   // vault root to watch
	Debounce  time.Duration                            // quiet window to coalesce a save burst; <=0 uses the default
	Reconcile time.Duration                            // periodic safety-net interval; <=0 disables the tick
	OnReindex func(authoritative bool) (Result, error) // drift-check + reindex, single-flight; authoritative=false on a debounced change (mtime fast path ok), true on startup + the periodic safety tick (full hash check)
	Logf      func(string, ...any)                     // progress sink; nil is silent
	Trigger   <-chan struct{}                          // optional external nudge (e.g. an SSE event); fires OnReindex like a local change
}

Options configure a watch run.

type Result

type Result struct {
	Added     int
	Changed   int
	Removed   int
	Reindexed bool
	Dur       time.Duration
}

Result is what one reconcile did, for the progress log.

Jump to

Keyboard shortcuts

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