Skip to main content

lean_ctx/tools/
ctx_index.rs

1use std::path::Path;
2
3pub fn handle(action: &str, project_root: &Path) -> String {
4    match action {
5        "status" => {
6            crate::core::index_orchestrator::status_json(project_root.to_string_lossy().as_ref())
7        }
8        "build" => {
9            crate::core::index_orchestrator::ensure_all_background(
10                project_root.to_string_lossy().as_ref(),
11            );
12            "started".to_string()
13        }
14        "build-full" => {
15            // Force rebuild by deleting existing on-disk indexes first.
16            let bm25 = crate::core::bm25_index::BM25Index::index_file_path(project_root);
17            let _ = std::fs::remove_file(&bm25);
18            if let Some(dir) = crate::core::graph_index::ProjectIndex::index_dir(
19                project_root.to_string_lossy().as_ref(),
20            ) {
21                let _ = std::fs::remove_file(dir.join("index.json"));
22            }
23            crate::core::index_orchestrator::ensure_all_background(
24                project_root.to_string_lossy().as_ref(),
25            );
26            "started".to_string()
27        }
28        _ => "Unknown action. Use: status, build, build-full".to_string(),
29    }
30}