WeaveDocs
Agentfs Diff

Comparison

Comparison modes in `agentfs-diff` — file content, metadata-only, and hybrid comparisons across two contexts.

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::{ComparisonMode, DiffEngine, DiffOptions, FileSystem};
use std::sync::Arc;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // The DiffEngine compares two `Arc<dyn FileSystem>` sources. ComparisonMode
    // selects the strategy: Fast (size+mtime), Content (hash), or Full (both).
    let engine = DiffEngine::with_parallel(4);

    let options = DiffOptions::default()
        .with_mode(ComparisonMode::Content)
        .with_content_comparison(true)
        .with_metadata_comparison(true);

    // Substitute real FileSystem trait objects (e.g. AgentFSWrapper or a remote
    // implementation) in production. Here we sketch the call shape.
    let source: Arc<dyn FileSystem> = Arc::new(my_fs_source());
    let target: Arc<dyn FileSystem> = Arc::new(my_fs_target());

    let diffs = engine.compare(source, target, options).await?;
    let content_changes = diffs.iter().filter(|d| d.is_content_change()).count();
    let metadata_changes = diffs.iter().filter(|d| d.is_metadata_only()).count();

    println!(
        "total_diffs={} content_changes={} metadata_only={}",
        diffs.len(),
        content_changes,
        metadata_changes,
    );
    Ok(())
}

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