nd_300/actions/fix/mod.rs
1//! Diagnostic-driven fix loop entry point.
2//!
3//! `nd300 fix` (and the legacy `nd300 -f` flag form) lands here. The actual
4//! work is split across:
5//!
6//! - [`action`] — the [`Action`] type system and registry of every fix
7//! primitive available on the current platform.
8//! - [`triage`] — pure planning logic: pick which actions to apply for the
9//! current failure set, ordered by cost/risk.
10//! - [`session`] — per-run state (attempts, effectiveness, snapshots) and the
11//! plain-language Reporter that drives terminal output.
12//! - [`loop_runner`] — the bounded triage → apply → re-test loop that
13//! composes the three above.
14//!
15//! Stages 1 / 2 / 3 of the previous design have been replaced by the
16//! diagnostic-driven loop. The platform-specific primitives the old stages
17//! called still live in [`stages`] and are wrapped as [`Action`]s in
18//! [`action::all_actions`].
19
20pub mod action;
21pub mod adapters;
22pub mod arp;
23pub mod cmd;
24pub mod connectivity;
25pub mod dhcp;
26pub mod dns;
27pub mod loop_runner;
28pub mod report;
29pub mod session;
30pub mod stages;
31pub mod triage;
32pub mod vpn;
33pub mod wifi;
34
35use crate::config::Config;
36use crate::render::color;
37
38use super::{fail_icon, success_icon};
39
40/// Legacy step-result type used by the platform primitives in [`stages`]
41/// (interface bounce, Stage 3 stack reset). Retained during the v3 transition
42/// so we don't have to rewrite every primitive at once. The triage loop
43/// itself does not use this type directly.
44pub struct StepResult {
45 pub name: &'static str,
46 pub success: bool,
47 pub message: String,
48}
49
50/// Legacy step-success printer. Used by primitives in [`stages`]. The new
51/// loop's plain-language output lives in [`session::Reporter`].
52pub fn print_step_ok(label: &str, config: &Config) {
53 println!(
54 " {} {}",
55 color::green(success_icon(config), config),
56 color::green(label, config),
57 );
58}
59
60/// Legacy step-failure printer. See [`print_step_ok`].
61pub fn print_step_fail(label: &str, detail: &str, config: &Config) {
62 println!(
63 " {} {}",
64 color::red(fail_icon(config), config),
65 color::red(label, config),
66 );
67 if !detail.is_empty() {
68 println!(" {}", color::dim(detail, config));
69 }
70}
71
72pub fn warn_icon(config: &Config) -> &'static str {
73 if config.use_unicode {
74 crate::config::status_chars::WARN
75 } else {
76 crate::config::status_chars::WARN_ASCII
77 }
78}
79
80/// Entry point for `nd300 fix` / `nd300 -f`. Dispatches to the diagnostic-
81/// driven triage loop.
82///
83/// `_args` is currently a placeholder — the `--yes` flag lives at the
84/// top-level of `Nd300Cli` (global). Future fix-only options will be threaded
85/// through here.
86pub async fn run(config: &Config, _args: crate::cli::FixArgs) -> i32 {
87 loop_runner::run_and_finalize(config).await
88}