From a51e91cb86f9e587d94110ed061450ef291cc828 Mon Sep 17 00:00:00 2001 From: LHaghfoss Date: Wed, 25 Nov 2026 23:38:38 +0100 Subject: [PATCH] feat(cli): report external harness install and sign-in in doctor --- docs/cli.md | 2 +- rustcode/engine/src/doctor.rs | 194 +++++++++++++++++++++++++++++++++- 2 files changed, 194 insertions(+), 2 deletions(-) diff --git a/docs/cli.md b/docs/cli.md index 7d4e4405b..1fbfa2459 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -36,7 +36,7 @@ still works under its old top-level name (`rc mcp list` is | `rustcode init` | Create a project `.rustcode/config.toml` from the global defaults | Project config | | `rustcode acp` | Run as an ACP server over stdio (what an editor starts) | — | | `rc up` | Make this computer pairable in one step: background server from login, remote access on, a connect code | Service, remote access | -| `rustcode doctor` | Check config, binaries and skills | Creates missing folders with `--fix` | +| `rustcode doctor` | Check config, binaries, harnesses (install, version, sign-in, named accounts) and skills | Creates missing folders with `--fix` | | `rustcode bench` | Inspect or compare structured turn telemetry | — | | `rc export []` | Export a thread as a zip (same as `threads export`) | A zip file | | `rustcode discord` | Discord Rich Presence setup and status | Config | diff --git a/rustcode/engine/src/doctor.rs b/rustcode/engine/src/doctor.rs index cff7be9aa..ff4fc76c6 100644 --- a/rustcode/engine/src/doctor.rs +++ b/rustcode/engine/src/doctor.rs @@ -2,7 +2,7 @@ //! //! Checks the local harness prerequisites without network access: //! config directory, config load, required binaries (`git`, `rg`), -//! and skill directories. `--fix` creates missing directories; binaries are +//! external harnesses and their accounts, and skill directories. `--fix` creates missing directories; binaries are //! never auto-installed (we print the install hint instead). use std::path::PathBuf; @@ -224,6 +224,8 @@ pub fn run_checks(fix: bool) -> Vec { ), )); + checks.extend(collect_harness_checks()); + // Skill directories (informational; --fix creates only the one RustCode // owns, never the shared or workspace roots). for root in crate::skills::skill_roots() { @@ -293,6 +295,125 @@ pub fn format_report(checks: &[DoctorCheck]) -> String { out } +type HarnessFinding = ( + crate::harness::ResolvedHarness, + crate::harness::detect::Detection, +); +type AccountFinding = (crate::harness::config::HarnessAccount, &'static str); + +/// Every external harness of the user config, detected the way Settings › +/// Harnesses does, and the named accounts of the enabled ones with their +/// sign-in read by the harness's own status command. +fn collect_harness_checks() -> Vec { + let Ok(dir) = crate::harness::config::config_dir() else { + return Vec::new(); + }; + let (_, entries) = crate::harness::config::load_in(&dir); + let found: Vec = crate::harness::resolve_all(&entries) + .into_iter() + .filter(|harness| harness.kind != crate::harness::HarnessKind::Builtin) + .map(|harness| { + let detection = if harness.enabled { + crate::harness::detect::detect(&harness) + } else { + crate::harness::detect::Detection::default() + }; + (harness, detection) + }) + .collect(); + let accounts: Vec = crate::harness::config::load_accounts_in(&dir) + .into_iter() + .filter(|account| { + found + .iter() + .any(|(harness, _)| harness.enabled && harness.id == account.harness) + }) + .map(|account| { + let auth = crate::harness::detect::account_auth(&account, true); + (account, auth) + }) + .collect(); + harness_checks(&found, &accounts) +} + +fn harness_checks(found: &[HarnessFinding], accounts: &[AccountFinding]) -> Vec { + let mut checks = Vec::new(); + for (harness, detection) in found { + let known = harness.known; + if !harness.enabled { + checks.push(DoctorCheck::pass( + "harness", + format!("{}: turned off", harness.id), + )); + continue; + } + if !detection.installed { + let program = harness.command.first().map_or("", String::as_str); + let detail = detection + .error + .clone() + .unwrap_or_else(|| format!("`{program}` not found on PATH")); + checks.push(DoctorCheck::fail( + "harness", + format!("{}: {detail}", harness.id), + known + .and_then(|known| known.install_hint) + .map(str::to_owned), + )); + continue; + } + let version = detection.version.as_deref().unwrap_or("version unknown"); + match detection.auth { + "needs_login" => checks.push(DoctorCheck::fail( + "harness", + format!("{}: {version}, signed out", harness.id), + known + .and_then(|known| known.login_command) + .map(|login| format!("run `{}` in a terminal", login.join(" "))), + )), + "ok" => checks.push(DoctorCheck::pass( + "harness", + format!("{}: {version}, signed in", harness.id), + )), + _ => checks.push(DoctorCheck::pass( + "harness", + format!("{}: {version}, sign-in not checked", harness.id), + )), + } + } + for (account, auth) in accounts { + let label = format!( + "{} account {} ({})", + account.harness, + account.display_name(), + account.config_dir + ); + match *auth { + "needs_login" => checks.push(DoctorCheck::fail( + "harness-account", + format!("{label}: signed out"), + crate::harness::config::account_layout(&account.harness).map(|layout| { + format!( + "run `{}={} {}` in a terminal", + layout.env_var, + account.config_dir, + layout.login_command.join(" ") + ) + }), + )), + "ok" => checks.push(DoctorCheck::pass( + "harness-account", + format!("{label}: signed in"), + )), + _ => checks.push(DoctorCheck::pass( + "harness-account", + format!("{label}: sign-in not checked"), + )), + } + } + checks +} + /// The config rows: `config-load` fails when the user config could not be /// read (the engine then runs on built-in defaults), and each project file /// that could not be read gets a `project-config` row of its own. @@ -381,6 +502,77 @@ mod tests { assert_eq!(clean[0].detail, "model=m"); } + fn resolved(id: &str, enabled: bool) -> crate::harness::ResolvedHarness { + crate::harness::ResolvedHarness { + id: id.to_owned(), + name: id.to_owned(), + kind: crate::harness::HarnessKind::Acp, + command: vec![format!("{id}-missing-binary")], + env: Vec::new(), + enabled, + known: None, + } + } + + fn detected(installed: bool, auth: &'static str) -> crate::harness::detect::Detection { + crate::harness::detect::Detection { + installed, + version: installed.then(|| "1.2.3".to_owned()), + auth, + error: None, + } + } + + #[test] + fn harness_rows_fail_only_for_enabled_missing_or_signed_out_harnesses() { + let found = vec![ + (resolved("off", false), detected(false, "unknown")), + (resolved("gone", true), detected(false, "unknown")), + (resolved("out", true), detected(true, "needs_login")), + (resolved("fine", true), detected(true, "ok")), + (resolved("quiet", true), detected(true, "unknown")), + ]; + let checks = harness_checks(&found, &[]); + let row = |id: &str| { + checks + .iter() + .find(|check| check.detail.starts_with(&format!("{id}:"))) + .unwrap() + .clone() + }; + assert!(row("off").ok); + assert_eq!(row("off").detail, "off: turned off"); + assert!(!row("gone").ok); + assert!( + row("gone") + .detail + .contains("`gone-missing-binary` not found on PATH") + ); + assert!(!row("out").ok); + assert!(row("fine").ok); + assert_eq!(row("fine").detail, "fine: 1.2.3, signed in"); + assert!(row("quiet").ok); + assert!(row("quiet").detail.ends_with("sign-in not checked")); + } + + #[test] + fn a_signed_out_account_fails_with_its_login_command() { + let account = crate::harness::config::HarnessAccount { + id: "work".to_owned(), + harness: "codex".to_owned(), + name: Some("Work".to_owned()), + config_dir: "~/.codex-work".to_owned(), + }; + let checks = harness_checks(&[], &[(account.clone(), "needs_login"), (account, "ok")]); + assert!(!checks[0].ok); + assert_eq!(checks[0].name, "harness-account"); + assert_eq!( + checks[0].fix_hint.as_deref(), + Some("run `CODEX_HOME=~/.codex-work codex login` in a terminal") + ); + assert!(checks[1].ok); + } + #[test] fn run_checks_does_not_panic() { let checks = run_checks(false);