Agentfs Diff
Streaming
Streaming diff in `agentfs-diff` — incremental diff results emitted as a stream, suitable for large filesystems.
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.rsDiff— local/agentfs-diff/src/diff.rsDiffEngine— local/agentfs-diff/src/engine.rsDiffOptions— local/agentfs-diff/src/engine.rsDiffStream— local/agentfs-diff/src/stream.rsDiffWatcher— local/agentfs-diff/src/watcher.rsDirectoryDiff— local/agentfs-diff/src/diff.rsEntryInfo— local/agentfs-diff/src/comparison.rsFileDiff— local/agentfs-diff/src/diff.rsMetadataDiff— local/agentfs-diff/src/diff.rsSymlinkDiff— local/agentfs-diff/src/diff.rsWatchOptions— local/agentfs-diff/src/watcher.rs
Example shape
use agentfs_diff::{DiffEvent, DiffOptions, DiffStream, FileSystem};
use futures::StreamExt;
use std::sync::Arc;
#[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());
// DiffStream spawns the comparison on a Tokio task and surfaces DiffEvent
// values as they happen — Started, Progress, DiffFound, Completed, Error.
let mut stream = DiffStream::new(source, target, DiffOptions::default());
let mut diffs = 0usize;
while let Some(event) = stream.next().await {
match event {
DiffEvent::Started { source_type, target_type } => {
println!("compare {source_type} -> {target_type}");
}
DiffEvent::DiffFound(_) => diffs += 1,
DiffEvent::Progress { files_compared, .. } => {
println!("progress: {files_compared} files compared");
}
DiffEvent::Completed { total_diffs, duration_ms } => {
println!("done in {duration_ms} ms with {total_diffs} diffs");
break;
}
DiffEvent::Error(msg) => {
eprintln!("stream error: {msg}");
break;
}
}
}
let _ = diffs;
Ok(())
}
# fn my_fs_source() -> impl agentfs_diff::FileSystem { unimplemented!() }
# fn my_fs_target() -> impl agentfs_diff::FileSystem { unimplemented!() }