om_context/
lib.rs

1pub mod git;
2pub mod ignore;
3pub mod scorer;
4pub mod session;
5
6pub use git::{ls_files, repo_root};
7pub use ignore::IgnorePatterns;
8pub use scorer::{score_file, score_files, ScoredFile};
9pub use session::Session;
10
11use std::path::Path;
12
13pub fn get_context(
14    root: &Path,
15    min_score: i32,
16) -> Result<Vec<ScoredFile>, Box<dyn std::error::Error>> {
17    let files = ls_files(root)?;
18    let ignore = IgnorePatterns::load(root);
19
20    let file_strs: Vec<String> = files
21        .into_iter()
22        .filter_map(|p| p.to_str().map(String::from))
23        .filter(|p| !ignore.is_ignored(p))
24        .collect();
25
26    let mut scored = score_files(file_strs);
27    scored.retain(|f| f.score >= min_score);
28    scored.sort_by(|a, b| b.score.cmp(&a.score).then(a.path.cmp(&b.path)));
29
30    Ok(scored)
31}