Agentfs Watch
Internals
Internals of `agentfs-watch` — event batching pipeline, debounce windows, overflow handling, and restartable state.
Purpose
Restartable filesystem watcher with event batches, backpressure policy, debouncing, and overflow handling.
This page follows the real source shape for Agentfs Watch and explains the workflow a developer is likely to use first.
Developer workflow
Start from the smallest constructor or builder, perform one meaningful operation, inspect the returned state, then add the relevant policy, storage, or network integration. The examples below should be expanded whenever the crate API changes.
Primary types to know
EventBatch— local/agentfs-watch/src/lib.rsRestartConfig— local/agentfs-watch/src/lib.rsWatchConfig— local/agentfs-watch/src/lib.rsWatcher— local/agentfs-watch/src/lib.rsWatcherBuilder— local/agentfs-watch/src/lib.rsWatchEvent— local/agentfs-watch/src/lib.rsBackpressurePolicy— local/agentfs-watch/src/lib.rsEventType— local/agentfs-watch/src/lib.rsWatchError— local/agentfs-watch/src/lib.rs
Example shape
use agentfs_watch::{
BackpressurePolicy, EventType, RestartConfig, WatchConfig, Watcher,
};
use std::path::PathBuf;
use std::time::Duration;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// WatchConfig captures every knob the runtime exposes: globs, debounce,
// coalescing, queue depth, backpressure, and notify-restart behavior.
let config = WatchConfig {
roots: vec![PathBuf::from("/tmp/observed")],
debounce_ms: 50,
coalesce_window_ms: 200,
batch_max_items: 32,
batch_max_ms: 250,
queue_capacity: 512,
backpressure: BackpressurePolicy::DropOldest,
recursive: true,
restart: RestartConfig {
max_attempts: 5,
initial_backoff: Duration::from_millis(100),
max_backoff: Duration::from_secs(5),
},
..WatchConfig::default()
};
let watcher = Watcher::new(config)?;
let event_types = [EventType::Created, EventType::Modified, EventType::Deleted];
println!(
"watcher_recursive={} interesting_kinds={}",
watcher.config().recursive,
event_types.len(),
);
Ok(())
}