vyctor 0.1.0

A fast CLI tool for semantic file search using vector embeddings
Documentation
//! Implementation of the `vyctor sync` command

use crate::cli::ensure_daemon_running;
use crate::config::{find_vyctor_root, load_config};
use crate::indexer::Indexer;
use anyhow::Result;
use colored::Colorize;

/// Run the sync command
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()
    );

    // Auto-start daemon if configured
    ensure_daemon_running(&root, &config)?;

    Ok(())
}