Skip to main content

tokmd_settings/
commands.rs

1//! Clap-free settings for tokmd command modes.
2
3use serde::{Deserialize, Serialize};
4use tokmd_types::{ChildIncludeMode, ChildrenMode, ExportFormat, RedactMode};
5
6/// Settings for language summary (`tokmd lang`).
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct LangSettings {
9    /// Show only the top N rows (0 = all).
10    #[serde(default)]
11    pub top: usize,
12
13    /// Include file counts and average lines per file.
14    #[serde(default)]
15    pub files: bool,
16
17    /// How to handle embedded languages.
18    #[serde(default = "default_children_mode")]
19    pub children: ChildrenMode,
20
21    /// Redaction mode for output.
22    #[serde(default)]
23    pub redact: Option<RedactMode>,
24}
25
26impl Default for LangSettings {
27    fn default() -> Self {
28        Self {
29            top: 0,
30            files: false,
31            children: ChildrenMode::Collapse,
32            redact: None,
33        }
34    }
35}
36
37fn default_children_mode() -> ChildrenMode {
38    ChildrenMode::Collapse
39}
40
41/// Settings for module summary (`tokmd module`).
42#[derive(Debug, Clone, Serialize, Deserialize)]
43pub struct ModuleSettings {
44    /// Show only the top N modules (0 = all).
45    #[serde(default)]
46    pub top: usize,
47
48    /// Top-level directories as "module roots".
49    #[serde(default = "default_module_roots")]
50    pub module_roots: Vec<String>,
51
52    /// Path segments to include for module roots.
53    #[serde(default = "default_module_depth")]
54    pub module_depth: usize,
55
56    /// How to handle embedded languages.
57    #[serde(default = "default_child_include_mode")]
58    pub children: ChildIncludeMode,
59
60    /// Redaction mode for output.
61    #[serde(default)]
62    pub redact: Option<RedactMode>,
63}
64
65fn default_module_roots() -> Vec<String> {
66    vec!["crates".to_string(), "packages".to_string()]
67}
68
69fn default_module_depth() -> usize {
70    2
71}
72
73fn default_child_include_mode() -> ChildIncludeMode {
74    ChildIncludeMode::Separate
75}
76
77impl Default for ModuleSettings {
78    fn default() -> Self {
79        Self {
80            top: 0,
81            module_roots: default_module_roots(),
82            module_depth: default_module_depth(),
83            children: default_child_include_mode(),
84            redact: None,
85        }
86    }
87}
88
89/// Settings for file-level export (`tokmd export`).
90#[derive(Debug, Clone, Serialize, Deserialize)]
91pub struct ExportSettings {
92    /// Output format.
93    #[serde(default = "default_export_format")]
94    pub format: ExportFormat,
95
96    /// Module roots (see `ModuleSettings`).
97    #[serde(default = "default_module_roots")]
98    pub module_roots: Vec<String>,
99
100    /// Module depth (see `ModuleSettings`).
101    #[serde(default = "default_module_depth")]
102    pub module_depth: usize,
103
104    /// How to handle embedded languages.
105    #[serde(default = "default_child_include_mode")]
106    pub children: ChildIncludeMode,
107
108    /// Drop rows with fewer than N code lines.
109    #[serde(default)]
110    pub min_code: usize,
111
112    /// Stop after emitting N rows (0 = unlimited).
113    #[serde(default)]
114    pub max_rows: usize,
115
116    /// Redaction mode.
117    #[serde(default = "default_redact_mode")]
118    pub redact: RedactMode,
119
120    /// Include a meta record.
121    #[serde(default = "default_meta")]
122    pub meta: bool,
123
124    /// Strip this prefix from paths.
125    #[serde(default)]
126    pub strip_prefix: Option<String>,
127}
128
129fn default_redact_mode() -> RedactMode {
130    RedactMode::None
131}
132
133fn default_export_format() -> ExportFormat {
134    ExportFormat::Jsonl
135}
136
137fn default_meta() -> bool {
138    true
139}
140
141impl Default for ExportSettings {
142    fn default() -> Self {
143        Self {
144            format: default_export_format(),
145            module_roots: default_module_roots(),
146            module_depth: default_module_depth(),
147            children: default_child_include_mode(),
148            min_code: 0,
149            max_rows: 0,
150            redact: RedactMode::None,
151            meta: true,
152            strip_prefix: None,
153        }
154    }
155}
156
157/// Settings for analysis (`tokmd analyze`).
158#[derive(Debug, Clone, Serialize, Deserialize)]
159pub struct AnalyzeSettings {
160    /// Analysis preset to run.
161    #[serde(default = "default_preset")]
162    pub preset: String,
163
164    /// Context window size (tokens) for utilization bars.
165    #[serde(default)]
166    pub window: Option<usize>,
167
168    /// Force-enable git-based metrics.
169    #[serde(default)]
170    pub git: Option<bool>,
171
172    /// Limit files walked for asset/deps/content scans.
173    #[serde(default)]
174    pub max_files: Option<usize>,
175
176    /// Limit total bytes read during content scans.
177    #[serde(default)]
178    pub max_bytes: Option<u64>,
179
180    /// Limit bytes per file during content scans.
181    #[serde(default)]
182    pub max_file_bytes: Option<u64>,
183
184    /// Limit commits scanned for git metrics.
185    #[serde(default)]
186    pub max_commits: Option<usize>,
187
188    /// Limit files per commit for git metrics.
189    #[serde(default)]
190    pub max_commit_files: Option<usize>,
191
192    /// Import graph granularity.
193    #[serde(default = "default_granularity")]
194    pub granularity: String,
195
196    /// Effort model for estimate calculations.
197    #[serde(default)]
198    pub effort_model: Option<String>,
199
200    /// Effort report layer.
201    #[serde(default)]
202    pub effort_layer: Option<String>,
203
204    /// Base reference for effort delta computation.
205    #[serde(default)]
206    pub effort_base_ref: Option<String>,
207
208    /// Head reference for effort delta computation.
209    #[serde(default)]
210    pub effort_head_ref: Option<String>,
211
212    /// Enable Monte Carlo uncertainty for effort estimation.
213    #[serde(default)]
214    pub effort_monte_carlo: Option<bool>,
215
216    /// Monte Carlo iterations for effort estimation.
217    #[serde(default)]
218    pub effort_mc_iterations: Option<usize>,
219
220    /// Monte Carlo seed for effort estimation.
221    #[serde(default)]
222    pub effort_mc_seed: Option<u64>,
223}
224
225fn default_preset() -> String {
226    "receipt".to_string()
227}
228
229fn default_granularity() -> String {
230    "module".to_string()
231}
232
233impl Default for AnalyzeSettings {
234    fn default() -> Self {
235        Self {
236            preset: default_preset(),
237            window: None,
238            git: None,
239            max_files: None,
240            max_bytes: None,
241            max_file_bytes: None,
242            max_commits: None,
243            max_commit_files: None,
244            granularity: default_granularity(),
245            effort_model: None,
246            effort_layer: None,
247            effort_base_ref: None,
248            effort_head_ref: None,
249            effort_monte_carlo: None,
250            effort_mc_iterations: None,
251            effort_mc_seed: None,
252        }
253    }
254}
255
256/// Settings for cockpit PR metrics (`tokmd cockpit`).
257#[derive(Debug, Clone, Serialize, Deserialize)]
258pub struct CockpitSettings {
259    /// Base ref to compare from.
260    #[serde(default = "default_cockpit_base")]
261    pub base: String,
262
263    /// Head ref to compare to.
264    #[serde(default = "default_cockpit_head")]
265    pub head: String,
266
267    /// Range mode: "two-dot" or "three-dot".
268    #[serde(default = "default_cockpit_range_mode")]
269    pub range_mode: String,
270
271    /// Optional baseline file path for trend comparison.
272    #[serde(default)]
273    pub baseline: Option<String>,
274}
275
276fn default_cockpit_base() -> String {
277    "main".to_string()
278}
279
280fn default_cockpit_head() -> String {
281    "HEAD".to_string()
282}
283
284fn default_cockpit_range_mode() -> String {
285    "two-dot".to_string()
286}
287
288impl Default for CockpitSettings {
289    fn default() -> Self {
290        Self {
291            base: default_cockpit_base(),
292            head: default_cockpit_head(),
293            range_mode: default_cockpit_range_mode(),
294            baseline: None,
295        }
296    }
297}
298
299/// Settings for diff comparison (`tokmd diff`).
300#[derive(Debug, Clone, Default, Serialize, Deserialize)]
301pub struct DiffSettings {
302    /// Base reference to compare from.
303    pub from: String,
304
305    /// Target reference to compare to.
306    pub to: String,
307}