use std::path::Path;
#[must_use]
pub fn handle(action: &str, project_root: &Path) -> String {
match action {
"status" => {
lean_ctx::core::index_orchestrator::status_json(project_root.to_string_lossy().as_ref())
}
"build" => {
lean_ctx::core::index_orchestrator::ensure_all_background(
project_root.to_string_lossy().as_ref(),
);
"started".to_string()
}
"build-full" => {
let bm25 = lean_ctx::core::bm25_index::BM25Index::index_file_path(project_root);
let _ = std::fs::remove_file(&bm25);
lean_ctx::core::graph_index::purge_index(project_root.to_string_lossy().as_ref());
let vectors_dir = lean_ctx::core::index_namespace::vectors_dir(project_root);
let _ = std::fs::remove_file(vectors_dir.join("embeddings.bin"));
let _ = std::fs::remove_file(vectors_dir.join("embeddings.json"));
lean_ctx::core::index_orchestrator::ensure_all_background(
project_root.to_string_lossy().as_ref(),
);
lean_ctx::core::index_orchestrator::build_semantic_background(
project_root.to_string_lossy().as_ref(),
);
lean_ctx::core::graph_cache::invalidate(Some(project_root.to_string_lossy().as_ref()));
"started".to_string()
}
"build-semantic" => {
lean_ctx::core::index_orchestrator::build_semantic_background(
project_root.to_string_lossy().as_ref(),
);
"semantic index build started in the background; progress is saved as it goes — \
check with ctx_index action=status"
.to_string()
}
_ => "Unknown action. Use: status, build, build-full, build-semantic, why".to_string(),
}
}