use super::checks::{
check_api_config, check_config_file, check_environment_variables, check_git_repository,
check_required_tools, check_working_directory,
};
use super::types::CheckStatus;
use crate::console::CliConsole;
use colored::*;
use sage_core::config::load_config_from_file;
use sage_core::error::SageResult;
pub async fn doctor(config_file: &str) -> SageResult<()> {
let console = CliConsole::new(true);
println!();
println!("{}", "Sage Agent Health Check".bold().underline());
println!("{}", "=".repeat(50).dimmed());
println!();
let mut checks = Vec::new();
checks.push(check_config_file(config_file));
checks.extend(check_environment_variables());
checks.extend(check_required_tools().await);
if let Ok(config) = load_config_from_file(config_file) {
checks.extend(check_api_config(&config));
}
checks.push(check_working_directory());
checks.push(check_git_repository());
let mut pass_count = 0;
let mut warn_count = 0;
let mut fail_count = 0;
for check in &checks {
println!("{} {} - {}", check.icon(), check.name.bold(), check.message);
if let Some(hint) = &check.hint {
println!(" {} {}", "→".dimmed(), hint.dimmed());
}
match check.status {
CheckStatus::Pass => pass_count += 1,
CheckStatus::Warn => warn_count += 1,
CheckStatus::Fail => fail_count += 1,
}
}
println!();
println!("{}", "-".repeat(50).dimmed());
println!(
"Summary: {} passed, {} warnings, {} failed",
pass_count.to_string().green(),
warn_count.to_string().yellow(),
fail_count.to_string().red()
);
if fail_count > 0 {
println!();
console.error("Some checks failed. Please fix the issues above.");
} else if warn_count > 0 {
println!();
console.warn("Some checks have warnings. Consider addressing them.");
} else {
println!();
console.success("All checks passed! Sage Agent is ready to use.");
}
Ok(())
}