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 ¶
New constructs a Watcher rooted at projectRoot. The constructor only validates the root exists; Run starts the actual fsnotify goroutine.
func (*Watcher) Run ¶
Run starts the watch loop and blocks until ctx is done. Returns nil on graceful cancellation; error otherwise.
func (*Watcher) SetDebounce ¶
SetDebounce overrides the coalescing window. Values <= 0 fall back to the default.
func (*Watcher) SetLogger ¶
SetLogger overrides the slog.Logger watcher events emit on. Nil clears the logger so the watcher runs silently — useful in tests.
func (*Watcher) Subscribe ¶
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.