Documentation
¶
Overview ¶
Package watch implements the --watch filesystem-trigger mode.
A Watcher observes one or more directories via fsnotify, matches new / modified files against a set of rules (glob pattern -> prompt template), and hands the result to a caller-supplied handler. Rapid write bursts against the same path are debounced so an atomic save sequence (truncate + rewrite + rename) doesn't dispatch the handler three times.
The Watcher is intentionally agnostic of the agent loop — callers plug the handler into whatever dispatch mechanism they prefer. promptzero wires it to ai.Run so FS events become natural-language turns.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidatePattern ¶ added in v0.27.0
ValidatePattern returns nil when the pattern is well-formed for filepath.Match, or the underlying ErrBadPattern when not. Useful for config-load-time validation so a typo (e.g. `*[a.sub` with unmatched bracket) fails visibly at startup instead of silently suppressing every event the operator expected.
Types ¶
type Event ¶
Event is a record of one dispatched rule firing. Kept in-memory on the Watcher for the /watch slash command's "last 5 events" view.
type Handler ¶
Handler is the callback invoked when a file matches a rule. Returning an error is non-fatal; the Watcher logs and continues processing events.
type Rule ¶
Rule is a single pattern -> prompt mapping with an optional persona override. Pattern uses filepath.Match semantics against the file basename. Prompt is templated with {{path}}, {{dir}}, {{name}}, {{ext}} when the handler fires.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher debounces and dispatches fsnotify events through the configured rule set. Zero value is not usable — construct via New.
func New ¶
New constructs a Watcher from a list of paths and rules. The slices are copied so the caller can mutate the originals without racing the watcher.
func (*Watcher) Pause ¶
func (w *Watcher) Pause()
Pause silences the watcher without stopping it; queued and subsequent events are still observed but handlers are not invoked until Resume.
func (*Watcher) Recent ¶
Recent returns up to n most-recent events, newest first. Pass a small number (5-20) — history is bounded by eventHistory anyway.