Skip to main content

active_core/
diag.rs

1//! Structured diagnostics and repair records
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct Diagnostic {
7    pub severity: Severity,
8    pub code: String,
9    pub message: String,
10    pub path: Option<String>,
11    pub span: Option<Span>,
12    pub repair: Option<Repair>,
13    /// 0.0 – 1.0
14    pub confidence: f64,
15    /// Source file the diagnostic came from. Set for multi-file documents
16    /// (includes, C-025); unset for single-file parses, where tools fall
17    /// back to the input filename.
18    #[serde(default)]
19    pub file: Option<String>,
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
23#[serde(rename_all = "lowercase")]
24pub enum Severity {
25    Error,
26    Warning,
27    Info,
28    Hint,
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
32pub struct Span {
33    pub line: u32,
34    pub column: u32,
35    pub end_line: u32,
36    pub end_column: u32,
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
40pub struct Repair {
41    pub original: String,
42    pub suggested: String,
43    pub kind: RepairKind,
44    /// If true, safe to auto-apply
45    pub safe: bool,
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(rename_all = "snake_case")]
50pub enum RepairKind {
51    InsertQuote,
52    RemoveTrailingComma,
53    KeyTypo,
54    TypeCoercion,
55    MissingDefault,
56    UnitNormalization,
57    Other(String),
58}
59
60/// Official confidence thresholds used by the healer
61pub mod thresholds {
62    pub const AUTO_APPLY: f64 = 0.95;
63    pub const HIGH: f64 = 0.85;
64    pub const MEDIUM: f64 = 0.70;
65    // below MEDIUM → never auto-apply
66}