Skip to main content

text_mirror/
report.rs

1//! JSON summary types the CLI verbs emit.
2
3use serde::{Deserialize, Serialize};
4
5use crate::manifest::Record;
6
7/// Inventory of one detected format in a scan.
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct FormatCount {
10    /// Format id.
11    pub format: String,
12    /// Number of files.
13    pub files: u64,
14    /// Total size in bytes.
15    pub bytes: u64,
16}
17
18/// A file whose size stands out from the rest of the tree.
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct SizeOutlier {
21    /// Path relative to the scanned root.
22    pub path: String,
23    /// Size in bytes.
24    pub bytes: u64,
25    /// Detected format id.
26    pub format: String,
27}
28
29/// The `scan` verb output. A dry-run inventory of a division root.
30#[derive(Debug, Clone, Serialize, Deserialize)]
31pub struct ScanReport {
32    /// The scanned root.
33    pub root: String,
34    /// Version of the rules files used for detection.
35    pub rules_version: String,
36    /// Total number of files.
37    pub files: u64,
38    /// Total size in bytes.
39    pub bytes: u64,
40    /// Per-format counts, sorted by format id.
41    pub formats: Vec<FormatCount>,
42    /// Size outliers, largest first.
43    pub outliers: Vec<SizeOutlier>,
44}
45
46/// Terminal record counts by status.
47#[derive(Debug, Clone, Default, Serialize, Deserialize)]
48pub struct StatusCounts {
49    /// Sources with a fresh text artifact.
50    pub converted: u64,
51    /// Sources whose conversion failed.
52    pub failed: u64,
53    /// Sources no converter claims.
54    pub unsupported: u64,
55    /// Sources skipped because the checkpoint key matched.
56    pub skipped_unchanged: u64,
57    /// Sources deduplicated against an identical source.
58    pub dedup: u64,
59}
60
61/// The `run` verb output.
62#[derive(Debug, Clone, Serialize, Deserialize)]
63pub struct RunReport {
64    /// The division that ran.
65    pub division: String,
66    /// The division root.
67    pub root: String,
68    /// Number of walked sources that received a manifest record.
69    pub sources: u64,
70    /// Walked entries with no manifest representation yet, meaning
71    /// FIFOs, sockets, and other special files.
72    pub special_entries: u64,
73    /// Outcome counts for this run.
74    pub counts: StatusCounts,
75    /// Non-fatal findings, such as a discarded torn manifest line.
76    pub warnings: Vec<String>,
77}
78
79/// Coverage for one division, computed over terminal records.
80#[derive(Debug, Clone, Serialize, Deserialize)]
81pub struct DivisionStatus {
82    /// Division name, from the shard file name.
83    pub division: String,
84    /// Number of distinct source paths.
85    pub sources: u64,
86    /// Sources whose terminal record carries a text artifact.
87    pub with_text: u64,
88    /// `with_text` over `sources`, 0.0 for an empty shard.
89    pub coverage: f64,
90    /// Terminal record counts by status.
91    pub counts: StatusCounts,
92    /// Non-fatal reader findings for this shard.
93    pub warnings: Vec<String>,
94}
95
96/// The `status` verb output.
97#[derive(Debug, Clone, Serialize, Deserialize)]
98pub struct StatusReport {
99    /// One entry per division shard, sorted by division name.
100    pub divisions: Vec<DivisionStatus>,
101}
102
103/// One manifest record with the division shard it came from.
104#[derive(Debug, Clone, Serialize, Deserialize)]
105pub struct ExplainEntry {
106    /// Division name, from the shard file name.
107    pub division: String,
108    /// The record as written.
109    pub record: Record,
110}