watcher

package
v0.1.0-beta.10 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package watcher recursively watches a project directory for typed-skill source changes and pushes events to subscribers. It extends the fsnotify pattern from pkg/reload/watcher.go with recursive directory descent and a per-extension filter so the IDE wakes only when a `.go` or `.ts` skill file actually changes.

Subscribers receive coalesced events: each directory is tracked separately, but rapid bursts (editor save followed by formatter followed by lint) collapse into one notification per debounce window. The intent is that the IDE refetches the AST exactly once per logical edit even when the editor stages five filesystem operations to make it happen.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	// Path is the absolute on-disk path of the file that changed.
	Path string `json:"path"`

	// Lang is "go", "ts", or empty for SKILL.md / agent.json edits.
	Lang string `json:"lang,omitempty"`

	// Op is the fsnotify Op string ("WRITE", "CREATE", "REMOVE")
	// for diagnostics. The IDE renders no UI off this — Subscribers
	// react identically to all change kinds.
	Op string `json:"op"`

	// Time is the wall-clock time the event was coalesced.
	Time time.Time `json:"time"`
}

Event is one coalesced change notification. The path is absolute; the lang is "go" or "ts" — empty when the change does not match either extension (still surfaced because the IDE may want to invalidate its skill cache for non-source files like SKILL.md).

type Watcher

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

Watcher streams filesystem events to subscribers. One Watcher covers one project root and survives transient subdirectory churn (newly-created directories are added on the fly).

func New

func New(projectRoot string) (*Watcher, error)

New constructs a Watcher rooted at projectRoot. The constructor only validates the root exists; Run starts the actual fsnotify goroutine.

func (*Watcher) Run

func (w *Watcher) Run(ctx context.Context) error

Run starts the watch loop and blocks until ctx is done. Returns nil on graceful cancellation; error otherwise.

func (*Watcher) SetDebounce

func (w *Watcher) SetDebounce(d time.Duration)

SetDebounce overrides the coalescing window. Values <= 0 fall back to the default.

func (*Watcher) SetLogger

func (w *Watcher) SetLogger(l *slog.Logger)

SetLogger overrides the slog.Logger watcher events emit on. Nil clears the logger so the watcher runs silently — useful in tests.

func (*Watcher) Subscribe

func (w *Watcher) Subscribe() (<-chan Event, func())

Subscribe registers a new channel that receives Events. The returned cleanup function unsubscribes and closes the channel; it is safe to call from any goroutine. Subscribers MUST drain or close their channel — Run uses a non-blocking send so a slow reader silently drops events rather than stalling the whole dispatcher.

Jump to

Keyboard shortcuts

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