use std::path::Path; use crate::config::{self, Config, KeySource}; use crate::provider; use crate::session; /// Prints the state of everything the harness needs, and checks the things that /// are cheap to check but expensive to discover mid-turn. pub fn run(cfg: &Config) -> i32 { let mut failed = false; println!( "agent686 {} · {} · {}", env!("CARGO_PKG_VERSION"), std::env::consts::ARCH, std::env::consts::OS ); println!(); match config::key_source() { KeySource::Env => row(true, "key", "present in OPENCODE_API_KEY"), KeySource::File(path) => row(true, "key", &format!("present in {}", path.display())), KeySource::Missing => { row( false, "key", "missing — set OPENCODE_API_KEY or write ~/.config/agent686/key", ); failed = true; } } let sessions = session::sessions_dir(); match probe_dir(&sessions) { Ok(()) => row(true, "sessions", &sessions.display().to_string()), Err(error) => { row(false, "sessions", &format!("{}: {error}", sessions.display())); failed = true; } } let history = session::data_root().join("history"); match std::fs::read_to_string(&history) { Ok(text) => row( true, "history", &format!("{} ({} entries)", history.display(), text.lines().count()), ), Err(_) => row(true, "history", &format!("{} (new)", history.display())), } row(true, "provider", &cfg.base_url); row(true, "model", &cfg.model); if cfg.api_key.is_empty() { row(false, "auth", "skipped: no key"); failed = true; } else { match provider::models(cfg) { Ok(models) => { row(true, "auth", &format!("ok — {} models visible", models.len())); if models.iter().any(|id| id == &cfg.model) { row(true, "model known", "yes"); } else { row( false, "model known", "no — the provider does not list this id; pick another with --model", ); failed = true; } } Err(error) => { row(false, "auth", &error.to_string()); failed = true; } } } println!(); if failed { println!("some checks failed"); 1 } else { println!("all checks passed"); 0 } } fn row(ok: bool, label: &str, detail: &str) { println!("{:<13} {:<4} {detail}", label, if ok { "ok" } else { "FAIL" }); } fn probe_dir(dir: &Path) -> std::io::Result<()> { std::fs::create_dir_all(dir)?; let probe = dir.join(".doctor-probe"); std::fs::write(&probe, b"ok")?; std::fs::remove_file(probe) }