llmwiki_tooling/cmd/
mod.rs1pub mod agent;
2pub mod frontmatter_cmd;
3pub mod init;
4pub mod links;
5pub mod lint;
6pub mod refs;
7pub mod rename;
8pub mod sections;
9
10use std::collections::{HashMap, HashSet};
11use std::ops::Range;
12use std::path::{Path, PathBuf};
13
14pub(crate) type FileEdits = Vec<(PathBuf, String, Vec<(Range<usize>, String)>)>;
16
17#[derive(Default)]
19pub(crate) struct DirStats {
20 pub file_count: usize,
21 pub frontmatter_fields: HashMap<String, usize>,
22 pub section_headings: HashMap<String, usize>,
23}
24
25pub(crate) fn is_markdown_file(path: &Path) -> bool {
27 path.extension().is_some_and(|ext| ext == "md") && path.is_file()
28}
29
30pub(crate) fn share_name_component(a: &str, b: &str) -> bool {
32 let a_parts: HashSet<&str> = a.split('/').collect();
33 let b_parts: HashSet<&str> = b.split('/').collect();
34 !a_parts.is_disjoint(&b_parts)
35}
36
37pub(crate) fn detect_mirror_candidates(dirs: &[(String, usize)]) -> Vec<(&str, &str, usize)> {
39 let mut candidates = Vec::new();
40 for i in 0..dirs.len() {
41 for j in (i + 1)..dirs.len() {
42 let (dir_a, count_a) = &dirs[i];
43 let (dir_b, count_b) = &dirs[j];
44 if count_a == count_b && *count_a > 0 && share_name_component(dir_a, dir_b) {
45 candidates.push((dir_a.as_str(), dir_b.as_str(), *count_a));
46 }
47 }
48 }
49 candidates
50}