watcher

package
v0.53.1 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package watcher provides a general-purpose file watcher that monitors directories for changes to files matching specified extensions. It uses fsnotify for kernel-level notifications with debouncing to coalesce rapid editor writes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectDirs

func CollectDirs(standardDirs []string, extraPaths []string) []string

CollectDirs returns the directories to watch for a given set of standard directories and extra paths. Directories are deduplicated by absolute path and verified to exist. For explicit file paths, the parent directory is watched instead.

Types

type ContentWatcher

type ContentWatcher struct {
	// contains filtered or unexported fields
}

ContentWatcher monitors directories for file changes matching a set of extensions and triggers a reload callback when changes are detected. It uses fsnotify for kernel-level file notifications (inotify on Linux, kqueue on macOS) with debouncing to coalesce rapid editor writes.

func New

func New(opts Options) (*ContentWatcher, error)

New creates a ContentWatcher that monitors the given directories for file changes matching the specified extensions. When a change is detected (after debouncing), onReload is called. The watcher must be started with Start() and stopped with Close().

func (*ContentWatcher) Close

func (w *ContentWatcher) Close() error

Close stops the watcher and releases resources.

func (*ContentWatcher) Start

func (w *ContentWatcher) Start(ctx context.Context)

Start begins watching for file changes. It blocks until the context is cancelled or Close() is called. Typically called in a goroutine.

type Options

type Options struct {
	// Dirs are the directories to watch.
	Dirs []string
	// Extensions are the file extensions to watch for (e.g. ".md", ".txt").
	// Include the leading dot.
	Extensions []string
	// OnReload is called when a matching file changes (after debouncing).
	OnReload func()
	// Label is a human-readable name for logging (e.g. "prompts", "skills").
	Label string
	// Debounce is the debounce duration. Defaults to 300ms if zero.
	Debounce time.Duration
}

Options configures a ContentWatcher.

Jump to

Keyboard shortcuts

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