use std::path::Path;
pub use comindly_api::doctor::Check;
pub fn run(
team: &crate::team::TeamSettings,
server: Option<&crate::server::Server>,
root: &str,
) -> Vec<Check> {
let resolved = crate::context::Settings::resolve(team, crate::config::env);
let set = |k: &str| std::env::var(k).is_ok_and(|v| !v.is_empty());
let mut out = Vec::new();
let mut check = |good: bool, optional: bool, ok: &str, bad: &str| {
out.push(Check {
ok: good,
optional,
message: if good { ok } else { bad }.to_string(),
})
};
let graph = format!("{}/_graph", root.trim_end_matches('/'));
match crate::index::graph_versions_blocking(&graph) {
Ok(v) if !v.is_empty() => {
let (_, _, at) = v.last().cloned().unwrap_or_default();
let latest = chrono::DateTime::parse_from_rfc3339(&at)
.map(|t| t.to_utc().format("%-d %b %Y, %H:%M UTC").to_string())
.unwrap_or(at);
let msg = format!(
"index readable: {}, latest {latest}",
plural(v.len(), "version")
);
check(true, false, &msg, "");
}
_ => check(
false,
false,
"",
"no index here yet: run `comindly link <repos> --index-dir …`",
),
}
match crate::ledger::all_blocking(root) {
Ok(r) => check(
true,
false,
&format!("ledger readable: {}", plural(r.len(), "record")),
"",
),
Err(e) => check(false, false, "", &format!("ledger not readable: {e:#}")),
}
if crate::cache::is_remote(root) {
let fresh = crate::cache::dir(root).is_some_and(|d| d.join("_graph").is_dir());
check(
fresh,
false,
"local mirror present (hooks read it)",
"no local mirror yet: `comindly cache refresh` (hooks create it on first use)",
);
}
let settings = std::env::var_os("HOME")
.map(|h| Path::new(&h).join(".claude/settings.json"))
.and_then(|p| std::fs::read_to_string(p).ok())
.unwrap_or_default();
let local = std::fs::read_to_string(".claude/settings.json").unwrap_or_default();
check(
settings.contains("comindly hook") || local.contains("comindly hook"),
true,
"Claude Code hooks configured",
"Claude Code hooks not found: `comindly init-hooks claude`",
);
check(
set("OPENAI_API_KEY")
|| resolved.llm_base_url.is_some()
|| crate::credentials::llm_key(team.name.as_deref(), server)
.0
.is_some(),
true,
&format!("LLM configured (model {})", resolved.llm_model),
"no LLM key: summaries, flows and style guides are off (indexing works without)",
);
check(
crate::config::local_signing_key().is_some(),
true,
"ledger records are signed",
"records are unsigned (optional: `signing_key` or git SSH signing)",
);
check(
crate::config::local_allowed_signers().is_some(),
true,
"signatures are verified against `allowed_signers`",
"no `allowed_signers`: signatures are not checked (optional)",
);
let indexers: Vec<&str> = [
"scip-python",
"scip-typescript",
"scip-go",
"rust-analyzer",
"scip-java",
]
.into_iter()
.filter(|b| crate::scip::which(b).is_some())
.collect();
check(
!indexers.is_empty(),
true,
&format!("SCIP indexers on PATH: {}", indexers.join(", ")),
"no SCIP indexers on PATH (optional: compiler-grade edges)",
);
out
}
pub use comindly_api::agents::agents;
pub(crate) fn plural(n: usize, noun: &str) -> String {
format!("{n} {noun}{}", if n == 1 { "" } else { "s" })
}