Agentfs Mirror
Sync Engine
Sync engine in `agentfs-mirror` — checkpoint-driven sync plans, sparse replication, and resumable mirror sessions.
Purpose
Mirror engine with conflict resolution, sparse sync, progress reporting, checkpoint plans, stats, and watchers.
This page follows the real source shape for Agentfs Mirror 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
Checkpoint— local/agentfs-mirror/src/sync.rsConflict— local/agentfs-mirror/src/conflict.rsConflictResolver— local/agentfs-mirror/src/conflict.rsFileInfo— local/agentfs-mirror/src/conflict.rsFileStats— local/agentfs-mirror/src/stats.rsMirror— local/agentfs-mirror/src/mirror.rsMirrorOptions— local/agentfs-mirror/src/options.rsMirrorWatcher— local/agentfs-mirror/src/watcher.rsPlan— local/agentfs-mirror/src/sync.rsPlanOp— local/agentfs-mirror/src/sync.rsProgressReporter— local/agentfs-mirror/src/progress.rsSparseOptions— local/agentfs-mirror/src/sparse.rs
Example shape
use agentfs_diff::FileSystem;
use agentfs_mirror::{
ConflictResolver, ConflictStrategy, MirrorOptions, ProgressReporter, SparseOptions,
SparseSync, SyncDirection, SyncEngine, SyncMode, SyncState, SyncStats,
};
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());
let options = MirrorOptions::default()
.with_direction(SyncDirection::Push)
.with_mode(SyncMode::Incremental)
.with_sparse(true);
// SyncEngine orchestrates a diff, applies a Plan, and writes Checkpoints
// so an interrupted sync can resume without re-hashing the unchanged files.
let engine = SyncEngine::new(source, target, options);
let reporter = ProgressReporter::new();
let mut state = SyncState {
stats: SyncStats::new(),
sparse: Some(SparseSync::new(SparseOptions::default())),
resolver: ConflictResolver::new(ConflictStrategy::NewerWins),
progress_tx: Some(reporter.sender()),
};
engine.sync(&mut state).await?;
println!(
"synced files={} bytes={} conflicts={}",
state.stats.files_synced, state.stats.bytes_transferred, state.stats.conflicts,
);
Ok(())
}
# fn my_fs_source() -> impl agentfs_diff::FileSystem { unimplemented!() }
# fn my_fs_target() -> impl agentfs_diff::FileSystem { unimplemented!() }