WeaveDocs
Agentfs Diff

Watching

Live diff watchers in `agentfs-diff` — observe diffs in real time as both filesystems change.

Purpose

Filesystem diff engine with modes, streams, watchers, file metadata comparisons, and change details.

This page follows the real source shape for Agentfs Diff 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

  • AgentFSWrapper — local/agentfs-diff/src/comparison.rs
  • Diff — local/agentfs-diff/src/diff.rs
  • DiffEngine — local/agentfs-diff/src/engine.rs
  • DiffOptions — local/agentfs-diff/src/engine.rs
  • DiffStream — local/agentfs-diff/src/stream.rs
  • DiffWatcher — local/agentfs-diff/src/watcher.rs
  • DirectoryDiff — local/agentfs-diff/src/diff.rs
  • EntryInfo — local/agentfs-diff/src/comparison.rs
  • FileDiff — local/agentfs-diff/src/diff.rs
  • MetadataDiff — local/agentfs-diff/src/diff.rs
  • SymlinkDiff — local/agentfs-diff/src/diff.rs
  • WatchOptions — local/agentfs-diff/src/watcher.rs

Example shape

use agentfs_diff::{DiffWatcher, FileSystem, WatchOptions};
use std::sync::Arc;
use std::time::Duration;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let source: Arc<dyn FileSystem> = Arc::new(my_fs_source());
    let target: Arc<dyn FileSystem> = Arc::new(my_fs_target());

    // WatchOptions wires the diff scheduler: polling interval, debounce window,
    // and the underlying DiffOptions used for each comparison pass.
    let options = WatchOptions {
        interval: Duration::from_secs(2),
        initial_scan: true,
        debounce: Duration::from_millis(250),
        ..WatchOptions::default()
    };

    let mut watcher = DiffWatcher::new(source, target, options);
    let mut rx = watcher.receiver().expect("receiver must be available before start");
    watcher.start().await?;

    if let Some(diff) = rx.recv().await {
        println!("first diff: kind={:?} path={:?}", diff.kind, diff.path());
    }
    watcher.stop();
    Ok(())
}

# fn my_fs_source() -> impl agentfs_diff::FileSystem { unimplemented!() }
# fn my_fs_target() -> impl agentfs_diff::FileSystem { unimplemented!() }