use crate::cli::ensure_daemon_running;
use crate::config::{find_vyctor_root, load_config};
use crate::indexer::Indexer;
use anyhow::Result;
use colored::Colorize;
pub async fn run(force: bool) -> Result<()> {
let root = find_vyctor_root()?;
let config = load_config()?;
if force {
println!("{} Force re-indexing all files...", "→".cyan());
} else {
println!("{} Syncing index with file changes...", "→".cyan());
}
let indexer = Indexer::new(&root, &config)?;
let start = std::time::Instant::now();
let result = if force {
indexer.reindex().await?
} else {
indexer.sync().await?
};
let duration = start.elapsed();
println!();
println!("{}", "Sync complete:".bold());
println!(
" Files indexed: {} ({})",
result.files_indexed.to_string().green(),
format!("{:?}", duration).dimmed()
);
println!(
" Files skipped (unchanged): {}",
result.files_skipped.to_string().yellow()
);
println!(
" Files removed: {}",
result.files_deleted.to_string().red()
);
println!(
" Chunks created: {}",
result.chunks_created.to_string().cyan()
);
ensure_daemon_running(&root, &config)?;
Ok(())
}