Documentation
¶
Overview ¶
Package watcher implements incremental graph updates via filesystem events. When a source file changes, only that file's nodes and edges are removed and re-parsed — the rest of the graph is untouched. This keeps context fresh without the cost of a full re-index on every save.
Index ¶
- type BrainCrossProjectTracker
- type ChangeEvent
- type ConfigChangeHandler
- type CrossProjectTracker
- type NameMatcherRunner
- type PacketCacheInvalidator
- type Watcher
- func (w *Watcher) IsAlive() bool
- func (w *Watcher) RecentChanges(windowMinutes int) []ChangeEvent
- func (w *Watcher) SetAfterRebuildHook(fn func())
- func (w *Watcher) SetBrainClient(bc *brain.Client)
- func (w *Watcher) SetBrainCrossProjectTracker(tracker BrainCrossProjectTracker)
- func (w *Watcher) SetConfig(cfg *config.Config)
- func (w *Watcher) SetConfigChangeHandler(fn ConfigChangeHandler)
- func (w *Watcher) SetCrossProjectTracker(tracker CrossProjectTracker)
- func (w *Watcher) SetNameMatcher(nm NameMatcherRunner)
- func (w *Watcher) SetNodeEmbedder(e embed.Embedder)
- func (w *Watcher) SetPacketInvalidator(pi PacketCacheInvalidator)
- func (w *Watcher) SetProjectID(id string)
- func (w *Watcher) SetPulseClient(pc *pulse.Client)
- func (w *Watcher) Start(root string) error
- func (w *Watcher) Stop()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BrainCrossProjectTracker ¶
type BrainCrossProjectTracker interface {
// DetectAndStoreBrain reads the file content, calls the brain LLM for
// cross-project dependency detection, validates results against sibling
// stores, and persists any new deps not already found by Tier 1.
// Runs fire-and-forget — errors are logged, never propagated.
DetectAndStoreBrain(ctx context.Context, filePath string, localStore *store.Store)
}
BrainCrossProjectTracker provides Tier 2 brain-enhanced cross-project dependency detection for languages that Tier 1 can't handle well. Runs asynchronously after Tier 1 detection. Implemented by a wrapper that calls federation.BrainDetector + DeterministicDetector.ResolveBrainDeps.
type ChangeEvent ¶
type ChangeEvent struct {
Timestamp time.Time `json:"at"`
File string `json:"file"` // repo-relative when graph root is set
NodesAdded int `json:"nodes_added"`
NodesRemoved int `json:"nodes_removed"`
EdgesAdded int `json:"edges_added"`
}
ChangeEvent records a single file modification processed by the watcher.
type ConfigChangeHandler ¶
ConfigChangeHandler is called when synapses.json changes on disk. The argument is the new parsed config. Implementations should reconnect any clients (scout, brain) whose settings may have changed.
type CrossProjectTracker ¶
type CrossProjectTracker interface {
// DetectAndStore scans a file for cross-project imports, resolves entities
// against sibling stores, and persists the results. Errors are logged and
// skipped (fail-open). ctx controls cancellation and timeout.
DetectAndStore(ctx context.Context, filePath string, localStore *store.Store)
}
CrossProjectTracker detects cross-project dependencies in parsed files. Implemented by federation.DeterministicDetector.
type NameMatcherRunner ¶
type NameMatcherRunner interface {
// RunAsync scans g for cross-domain name matches and persists MENTIONS edges
// to st. changedFiles is the list of files in the triggering batch; pass nil
// to indicate a full re-walk (all domains affected — always run).
// Must respect ctx cancellation. Never blocks — errors are logged.
RunAsync(ctx context.Context, g *graph.Graph, st *store.Store, changedFiles []string)
}
NameMatcherRunner runs the cross-domain name-matching pass after each reindex. Implemented by namematcher.Matcher. Runs fire-and-forget in a tracked goroutine.
type PacketCacheInvalidator ¶
type PacketCacheInvalidator interface {
InvalidatePacketCache()
// InvalidatePacketCacheForFile is like InvalidatePacketCache but also triggers
// MCP resource notifications and proactive brain cache warming for the given file.
InvalidatePacketCacheForFile(changedFile string)
}
PacketCacheInvalidator is implemented by types that cache brain context packets and need to be notified when file changes make cached packets stale.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher watches a directory tree and keeps a Graph current as files change.
func New ¶
New creates a Watcher. store may be nil; if provided the cache is updated after each incremental re-parse.
func (*Watcher) IsAlive ¶
IsAlive reports whether the file-watching event loop is still running. Returns false if the loop has exhausted all restart attempts after panics or if Start() was never called.
func (*Watcher) RecentChanges ¶
func (w *Watcher) RecentChanges(windowMinutes int) []ChangeEvent
RecentChanges returns all ChangeEvents recorded within the last windowMinutes. If windowMinutes is <= 0 all recorded events are returned.
func (*Watcher) SetAfterRebuildHook ¶
func (w *Watcher) SetAfterRebuildHook(fn func())
SetAfterRebuildHook registers a callback invoked after each RebuildIndex call completes. Used to keep secondary structures (e.g. FlatGraph CSR) in sync.
func (*Watcher) SetBrainClient ¶
SetBrainClient wires a *brain.Client into the watcher so that changed files are incrementally ingested to the intelligence sidecar.
func (*Watcher) SetBrainCrossProjectTracker ¶
func (w *Watcher) SetBrainCrossProjectTracker(tracker BrainCrossProjectTracker)
SetBrainCrossProjectTracker wires a Tier 2 brain-enhanced dependency tracker. When set, after Tier 1 detection, the watcher runs brain detection in a fire-and-forget goroutine for files whose language isn't well-covered by Tier 1. Must be called before Start. tracker may be nil to disable.
func (*Watcher) SetConfig ¶
SetConfig wires the project config into the watcher so that rule violations are checked after each incremental re-parse and emitted to the event log. Must be called before Start. cfg may be nil to disable violation checking.
func (*Watcher) SetConfigChangeHandler ¶
func (w *Watcher) SetConfigChangeHandler(fn ConfigChangeHandler)
SetConfigChangeHandler registers a callback that is invoked whenever synapses.json changes on disk. The callback receives the newly parsed config. This enables hot-reload of brain/scout client settings without restarting.
func (*Watcher) SetCrossProjectTracker ¶
func (w *Watcher) SetCrossProjectTracker(tracker CrossProjectTracker)
SetCrossProjectTracker wires a federation dependency tracker into the watcher. When set, every file re-parse triggers cross-project import detection and stores discovered dependencies for drift checking by session_init. Must be called before Start. tracker may be nil to disable.
func (*Watcher) SetNameMatcher ¶
func (w *Watcher) SetNameMatcher(nm NameMatcherRunner)
SetNameMatcher wires the cross-domain name-matching pass into the watcher.
func (*Watcher) SetNodeEmbedder ¶
SetNodeEmbedder wires an embedder for Tier 1 embedding-based entity resolution and for the background node embedding pass. Pass nil to disable (name-match only).
func (*Watcher) SetPacketInvalidator ¶
func (w *Watcher) SetPacketInvalidator(pi PacketCacheInvalidator)
SetPacketInvalidator wires a PacketCacheInvalidator (typically the MCP Server) into the watcher. On every file change the packet cache is cleared so that stale brain context packets are not returned to agents.
func (*Watcher) SetProjectID ¶
SetProjectID sets the stable project identifier used when ingesting nodes to brain.
func (*Watcher) SetPulseClient ¶
SetPulseClient wires a pulse.Client into the watcher for pipeline instrumentation.
func (*Watcher) Start ¶
Start begins watching root recursively. It returns immediately; the event loop runs in a background goroutine. Call Stop to shut it down.
func (*Watcher) Stop ¶
func (w *Watcher) Stop()
Stop shuts down the watcher and releases resources. It blocks until all fire-and-forget goroutines (persistAsync, ingestToBrain, brain summary write-back, cross-project brain detection, index rebuild) have returned, preventing writes to a closed SQLite store after Stop returns.