use std::path::Path;
pub fn handle(action: &str, project_root: &Path) -> String {
match action {
"status" => {
crate::core::index_orchestrator::status_json(project_root.to_string_lossy().as_ref())
}
"build" => {
crate::core::index_orchestrator::ensure_all_background(
project_root.to_string_lossy().as_ref(),
);
"started".to_string()
}
"build-full" => {
// Force rebuild by deleting existing on-disk indexes first.
let bm25 = crate::core::bm25_index::BM25Index::index_file_path(project_root);
let _ = std::fs::remove_file(&bm25);
// #696 C4: purge the property graph (graph.db + wal/shm + meta) and
// any retired JSON/call-graph artifacts so the rebuild starts clean.
crate::core::graph_index::purge_index(project_root.to_string_lossy().as_ref());
crate::core::index_orchestrator::ensure_all_background(
project_root.to_string_lossy().as_ref(),
);
// #420: a forced rebuild must drop the in-process call-graph cache so
// ctx_impact/graph reads re-derive from the fresh on-disk index
// instead of the pre-rebuild snapshot (the CLI path does the same).
crate::core::graph_cache::invalidate(Some(project_root.to_string_lossy().as_ref()));
"started".to_string()
}
_ => "Unknown action. Use: status, build, build-full".to_string(),
}
}