agentmux_srv/backend/fs_watch/mod.rs
1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Shared filesystem-watcher framework.
5//!
6//! Before this module, three independent `notify`-based watchers
7//! (`config_watcher_fs.rs`, `editor_file_watcher.rs`, `media_file_watcher.rs`)
8//! each hand-rolled the same ~80 lines of plumbing — `notify` construction,
9//! sync-callback-to-async bridging, refcounted watch/unwatch, and the
10//! correctness-critical "watch the parent directory, not the file itself, so
11//! an atomic rename-over-target save is still detected" rule. None of the
12//! three (nor `subagent_watcher/`, the fourth) had any recovery if a watch
13//! failed to start or silently died later — see
14//! `docs/specs/SPEC_SHARED_FS_WATCHER_FRAMEWORK_2026_08_07.md` for the full
15//! audit and design rationale this module implements.
16//!
17//! `FsWatchPool` owns exactly the shared plumbing plus the new recovery
18//! layer (retry-with-backoff, a `PollWatcher` fallback, and a periodic
19//! self-healing sweep). It does NOT own domain-specific debounce or event
20//! payload/publish logic — callers subscribe, get a broadcast stream of raw
21//! change events, and apply their own filtering/debounce on top, the same
22//! way `editor_file_watcher.rs`/`media_file_watcher.rs` already do internally
23//! today (that part is genuinely domain-specific: editor wants per-path
24//! debounce, media wants per-directory+extension filtering).
25//!
26//! This is a pure addition in its first PR — no existing watcher has been
27//! migrated onto it yet. See the spec's §5 migration path.
28
29mod pool;
30mod recovery;
31
32pub use pool::{FsWatchEvent, FsWatchEventKind, FsWatchPool, Subscription};