rch 2.1.18

Remote Compilation Helper - PreToolUse hook CLI
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
//! Response types for CLI command outputs.
//!
//! This module contains all JSON-serializable response types used by CLI commands.
//! These types are separated from the command implementations to improve code organization
//! and enable easier testing.

use rch_common::{
    Classification, ClassificationTier, PlacementPlan, RequiredRuntime, SelectedWorker,
    SelectionDiagnostics, SelectionReason, WorkerCapabilities, WorkerConfig,
};
use schemars::JsonSchema;
use serde::Serialize;

use crate::status_types::WorkerCapabilitiesFromApi;

// =============================================================================
// Worker Response Types
// =============================================================================

/// Disk measurements and the daemon's independently cached pressure assessment.
/// Unknown values remain explicit nulls in both JSON and TOON output.
#[derive(Debug, Clone, Default, Serialize, JsonSchema)]
pub struct WorkerDiskInfo {
    pub disk_free_gb: Option<f64>,
    pub disk_free_ratio: Option<f64>,
    /// Free space on the filesystem holding build trees, which sizes slots.
    /// Null when the worker reports no sample separate from `disk_free_gb`.
    pub build_disk_free_gb: Option<f64>,
    /// `probe` for fresh capability measurements, `daemon` for cached status.
    pub disk_measurement_source: Option<&'static str>,
    pub disk_pressure_state: Option<String>,
    pub disk_pressure_reason: Option<String>,
    /// Pressure policy is evaluated by the daemon, never reconstructed by the CLI.
    pub disk_pressure_source: Option<&'static str>,
}

/// Worker information for JSON output.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct WorkerInfo {
    pub id: String,
    pub host: String,
    pub user: String,
    pub total_slots: u32,
    pub priority: u32,
    pub tags: Vec<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub speedscore: Option<f64>,
    #[serde(flatten)]
    pub disk: WorkerDiskInfo,
}

impl From<&WorkerConfig> for WorkerInfo {
    fn from(w: &WorkerConfig) -> Self {
        Self {
            id: w.id.as_str().to_string(),
            host: w.host.clone(),
            user: w.user.clone(),
            total_slots: w.total_slots,
            priority: w.priority,
            tags: w.tags.clone(),
            speedscore: None,
            disk: WorkerDiskInfo::default(),
        }
    }
}

/// Workers list response.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct WorkersListResponse {
    pub workers: Vec<WorkerInfo>,
    pub count: usize,
}

/// Worker probe result.
#[derive(Debug, Clone, Serialize)]
pub struct WorkerProbeResult {
    pub id: String,
    pub host: String,
    pub status: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub latency_ms: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub error: Option<String>,
    /// Structured error code (e.g. `"RCH-E100"`). Present when `error` is set
    /// and the underlying failure maps to a catalog entry. Lets auto-recovery
    /// agents branch on a stable identifier instead of substring-matching the
    /// human-readable `error` field.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub error_code: Option<String>,
    /// Exact runtime/toolchain capability inventory returned by `rch-wkr`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub capabilities: Option<WorkerCapabilities>,
    /// Project-declared rustup components absent from this worker's matching
    /// toolchain. Non-empty means connectivity succeeded but command admission
    /// must not report the worker as ready.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub missing_components: Vec<String>,
    #[serde(flatten)]
    pub disk: WorkerDiskInfo,
}

/// Per-error-code tally for a batch probe.
#[derive(Debug, Clone, Serialize, Default)]
pub struct WorkerProbeSummary {
    /// Total workers probed.
    pub total: usize,
    /// Workers that answered the health check successfully.
    pub healthy: usize,
    /// Workers that reachable but failed the health check.
    pub unhealthy: usize,
    /// Reachable workers missing a project-declared toolchain component.
    pub capability_missing: usize,
    /// Workers that failed to connect / errored.
    pub failed: usize,
    /// Error-code tally, keyed by `"RCH-Exxx"`. Errors without a mapped code
    /// are counted under `"other"`.
    pub by_error_code: std::collections::BTreeMap<String, usize>,
}

/// Workers probe response envelope.
#[derive(Debug, Clone, Serialize)]
pub struct WorkersProbeResponse {
    pub results: Vec<WorkerProbeResult>,
    pub summary: WorkerProbeSummary,
}

/// Worker capabilities report for JSON output.
#[derive(Debug, Clone, Serialize)]
pub struct WorkersCapabilitiesReport {
    pub workers: Vec<WorkerCapabilitiesFromApi>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub local: Option<WorkerCapabilities>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub required_runtime: Option<RequiredRuntime>,
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub warnings: Vec<String>,
}

/// Worker benchmark result for JSON output.
#[derive(Debug, Clone, Serialize)]
pub struct WorkerBenchmarkResult {
    pub id: String,
    pub host: String,
    pub status: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub duration_ms: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub error: Option<String>,
}

/// Worker action response for JSON output.
#[derive(Debug, Clone, Serialize)]
pub struct WorkerActionResponse {
    pub worker_id: String,
    pub action: String,
    pub success: bool,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message: Option<String>,
}

// =============================================================================
// Daemon Response Types
// =============================================================================

/// Daemon status response.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct DaemonStatusResponse {
    pub running: bool,
    pub socket_path: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub uptime_seconds: Option<u64>,
}

/// System overview response.
///
/// Named `SystemOverview` to distinguish from daemon's `DaemonFullStatus` type.
#[derive(Debug, Clone, Serialize)]
#[allow(dead_code)]
pub struct SystemOverview {
    pub daemon_running: bool,
    pub hook_installed: bool,
    pub workers_count: usize,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub workers: Option<Vec<WorkerInfo>>,
}

/// Daemon action response for JSON output.
#[derive(Debug, Clone, Serialize)]
pub struct DaemonActionResponse {
    pub action: String,
    pub success: bool,
    pub socket_path: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message: Option<String>,
}

/// Daemon reload response for JSON output.
#[derive(Debug, Clone, Serialize)]
pub struct DaemonReloadResponse {
    pub success: bool,
    pub added: usize,
    pub updated: usize,
    pub removed: usize,
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub warnings: Vec<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message: Option<String>,
}

/// Daemon logs response for JSON output.
#[derive(Debug, Clone, Serialize)]
pub struct DaemonLogsResponse {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub log_file: Option<String>,
    pub lines: Vec<String>,
    pub found: bool,
}

// =============================================================================
// Configuration Response Types
// =============================================================================

/// Configuration show response for JSON output.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct ConfigShowResponse {
    pub general: ConfigGeneralSection,
    pub compilation: ConfigCompilationSection,
    pub transfer: ConfigTransferSection,
    pub environment: ConfigEnvironmentSection,
    pub circuit: ConfigCircuitSection,
    pub output: ConfigOutputSection,
    pub self_healing: ConfigSelfHealingSection,
    pub sources: Vec<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub value_sources: Option<Vec<ConfigValueSourceInfo>>,
}

/// Source information for a single configuration value.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct ConfigValueSourceInfo {
    pub key: String,
    pub value: String,
    pub source: String,
}

/// Configuration get response for JSON output.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct ConfigGetResponse {
    pub key: String,
    pub value: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub source: Option<String>,
}

/// Configuration export response for JSON output.
#[derive(Debug, Clone, Serialize)]
#[allow(dead_code)]
pub struct ConfigExportResponse {
    pub format: String,
    pub content: String,
}

/// General configuration section.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct ConfigGeneralSection {
    pub enabled: bool,
    pub force_local: bool,
    pub force_remote: bool,
    pub log_level: String,
    pub socket_path: String,
}

/// Compilation configuration section.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct ConfigCompilationSection {
    pub confidence_threshold: f64,
    pub min_local_time_ms: u64,
    pub remote_speedup_threshold: f64,
    pub build_slots: u32,
    pub test_slots: u32,
    pub check_slots: u32,
    pub build_timeout_sec: u64,
    pub test_timeout_sec: u64,
    pub bun_timeout_sec: u64,
    pub external_timeout_enabled: bool,
    pub allow_local_fallback: bool,
    /// `auto`, `off`, or a fixed job count (see `compilation.remote_build_jobs`).
    pub remote_build_jobs: String,
}

/// Transfer configuration section.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct ConfigTransferSection {
    pub compression_level: u32,
    pub exclude_patterns: Vec<String>,
    pub remote_base: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sync_timeout_ms: Option<u64>,
    // Transfer optimization (bd-3hho)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_transfer_mb: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_transfer_time_ms: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bwlimit_kbps: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub estimated_bandwidth_bps: Option<u64>,
    /// Explicit rsync binary (issue #66); unset lets rch resolve one.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rsync_bin: Option<String>,
    // Adaptive compression (bd-243w)
    pub adaptive_compression: bool,
    pub min_compression_level: u32,
    pub max_compression_level: u32,
    // Artifact verification (bd-377q)
    pub verify_artifacts: bool,
    #[serde(skip_serializing_if = "is_default_verify_size")]
    pub verify_max_size_bytes: u64,
}

/// Helper function for serialization: returns true if value is the default verify size (100 MB).
pub fn is_default_verify_size(val: &u64) -> bool {
    *val == 100 * 1024 * 1024 // 100 MB default
}

/// Environment configuration section.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct ConfigEnvironmentSection {
    pub allowlist: Vec<String>,
}

/// Circuit breaker configuration section.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct ConfigCircuitSection {
    pub failure_threshold: u32,
    pub success_threshold: u32,
    pub error_rate_threshold: f64,
    pub window_secs: u64,
    pub open_cooldown_secs: u64,
    pub half_open_max_probes: u32,
}

/// Output configuration section.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct ConfigOutputSection {
    pub visibility: rch_common::OutputVisibility,
    pub first_run_complete: bool,
}

/// Self-healing configuration section.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct ConfigSelfHealingSection {
    pub hook_starts_daemon: bool,
    pub daemon_installs_hooks: bool,
    pub auto_start_cooldown_secs: u64,
    pub auto_start_timeout_secs: u64,
}

/// Configuration init response for JSON output.
#[derive(Debug, Clone, Serialize)]
pub struct ConfigInitResponse {
    pub created: Vec<String>,
    pub already_existed: Vec<String>,
}

/// Configuration validation response for JSON output.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct ConfigValidationResponse {
    pub errors: Vec<ConfigValidationIssue>,
    pub warnings: Vec<ConfigValidationIssue>,
    pub valid: bool,
}

/// A single validation issue.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct ConfigValidationIssue {
    pub file: String,
    pub message: String,
}

/// Configuration set response for JSON output.
#[derive(Debug, Clone, Serialize)]
pub struct ConfigSetResponse {
    pub key: String,
    pub value: String,
    pub config_path: String,
}

/// Configuration reset response for JSON output.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct ConfigResetResponse {
    pub key: String,
    pub value: String,
    pub config_path: String,
}

/// Issue severity for config lint.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, JsonSchema)]
#[serde(rename_all = "lowercase")]
pub enum LintSeverity {
    Error,
    Warning,
    Info,
}

/// A single lint issue.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct LintIssue {
    pub severity: LintSeverity,
    pub code: String,
    pub message: String,
    pub remediation: String,
}

/// Response for config lint command.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct ConfigLintResponse {
    pub issues: Vec<LintIssue>,
    pub error_count: usize,
    pub warning_count: usize,
    pub info_count: usize,
}

/// A single diff entry showing a non-default value.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct ConfigDiffEntry {
    pub key: String,
    pub current: String,
    pub default: String,
    pub source: String,
}

/// Response for config diff command.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct ConfigDiffResponse {
    pub entries: Vec<ConfigDiffEntry>,
    pub total_changes: usize,
}

// =============================================================================
// Diagnose Response Types
// =============================================================================

/// Diagnose command response for JSON output.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct DiagnoseResponse {
    pub classification: Classification,
    pub tiers: Vec<ClassificationTier>,
    pub command: String,
    pub normalized_command: String,
    pub decision: DiagnoseDecision,
    pub threshold: DiagnoseThreshold,
    pub daemon: DiagnoseDaemonStatus,
    pub required_runtime: RequiredRuntime,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub local_capabilities: Option<WorkerCapabilities>,
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub capabilities_warnings: Vec<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub worker_selection: Option<DiagnoseWorkerSelection>,
    /// Canonical placement control plan resolved from the environment: the
    /// requested/effective worker, strict-remote/queue/visibility/wait-timeout
    /// /target-dir policies, the requested-worker admissibility outcome, and any
    /// control diagnostics. This is the surface agents should read before
    /// forcing local/remote behavior (bd-...remediation-ocv9i.13.5).
    pub placement: PlacementPlan,
    /// Dry-run summary showing the full pipeline (only present when --dry-run is used).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub dry_run: Option<DryRunSummary>,
}

#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct DiagnoseDecision {
    pub would_intercept: bool,
    pub reason: String,
}

#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct DiagnoseThreshold {
    pub value: f64,
    pub source: String,
}

#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct DiagnoseDaemonStatus {
    pub socket_path: String,
    pub socket_exists: bool,
    pub reachable: bool,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub version: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub uptime_seconds: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub error: Option<String>,
}

#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct DiagnoseWorkerSelection {
    pub estimated_cores: u32,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cargo_jobs: Option<u32>,
    pub worker: Option<SelectedWorker>,
    pub reason: SelectionReason,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub diagnostics: Option<SelectionDiagnostics>,
}

/// Pipeline step for dry-run output.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct DryRunPipelineStep {
    /// Step number (1-based).
    pub step: u32,
    /// Step name (e.g., "classify", "select", "sync_up", "exec", "sync_down").
    pub name: String,
    /// Human-readable description of what would happen.
    pub description: String,
    /// Whether this step would be skipped.
    pub skipped: bool,
    /// Reason for skipping (if skipped).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub skip_reason: Option<String>,
    /// Estimated duration in milliseconds (if available).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub estimated_duration_ms: Option<u64>,
}

/// Transfer size estimation for dry-run.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct DryRunTransferEstimate {
    /// Estimated bytes to transfer.
    pub bytes: u64,
    /// Human-readable size (e.g., "12.5 MB").
    pub human_size: String,
    /// Estimated number of files.
    pub files: u32,
    /// Estimated transfer time in milliseconds.
    pub estimated_time_ms: u64,
    /// Whether transfer would be skipped due to size limits.
    pub would_skip: bool,
    /// Reason for skipping (if would_skip is true).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub skip_reason: Option<String>,
}

/// Dry-run summary showing the full pipeline.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct DryRunSummary {
    /// Whether the command would be offloaded remotely.
    pub would_offload: bool,
    /// Reason for the offload decision.
    pub reason: String,
    /// Pipeline steps that would be executed.
    pub pipeline_steps: Vec<DryRunPipelineStep>,
    /// Transfer size estimation (if available).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub transfer_estimate: Option<DryRunTransferEstimate>,
    /// Total estimated time in milliseconds.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub total_estimated_ms: Option<u64>,
}

// =============================================================================
// Hook Response Types
// =============================================================================

/// Hook install/uninstall response for JSON output.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct HookActionResponse {
    pub action: String,
    pub success: bool,
    pub settings_path: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message: Option<String>,
}

/// Hook test response for JSON output.
#[derive(Debug, Clone, Serialize)]
#[allow(dead_code)]
pub struct HookTestResponse {
    pub classification_tests: Vec<ClassificationTestResult>,
    pub daemon_connected: bool,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub daemon_response: Option<String>,
    pub workers_configured: usize,
    pub workers: Vec<WorkerInfo>,
}

/// Classification test result.
#[derive(Debug, Clone, Serialize)]
#[allow(dead_code)]
pub struct ClassificationTestResult {
    pub command: String,
    pub is_compilation: bool,
    pub confidence: f64,
    pub expected_intercept: bool,
    pub passed: bool,
}

// =============================================================================
// Doctor Command Response Types
// =============================================================================

/// Status of a diagnostic check.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, JsonSchema)]
#[serde(rename_all = "lowercase")]
pub enum DoctorCheckStatus {
    Pass,
    Warning,
    Fail,
    Skipped,
}

/// Result of a single diagnostic check.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct DoctorCheck {
    pub category: String,
    pub name: String,
    pub status: DoctorCheckStatus,
    pub message: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub details: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub suggestion: Option<String>,
    /// Whether this issue can be auto-fixed.
    #[serde(default)]
    pub fixable: bool,
    /// Whether a fix was applied during this run.
    #[serde(default)]
    pub fix_applied: bool,
    /// Message about the fix that was applied (if any).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub fix_message: Option<String>,
}

/// Summary of all doctor checks.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct DoctorSummary {
    pub total: usize,
    pub passed: usize,
    pub warnings: usize,
    pub failed: usize,
    pub fixed: usize,
    pub would_fix: usize,
}

/// A fix that was applied during doctor run.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct DoctorFixApplied {
    pub check_name: String,
    pub action: String,
    pub success: bool,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub error: Option<String>,
}

/// Overall doctor command response for JSON output.
///
/// **t05 — envelope harmonization:** carries `schema_version` matching
/// the reliability-mode response. Sourced from the central schema-
/// versions registry so cross-component drift is caught by the
/// registry's pinned-snapshot test.
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct DoctorResponse {
    pub schema_version: String,
    pub checks: Vec<DoctorCheck>,
    pub summary: DoctorSummary,
    pub fixes_applied: Vec<DoctorFixApplied>,
}