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
// CLI argument parsing for OIP
// Following EXTREME TDD: Minimal implementation to make tests compile
use clap::{Parser, Subcommand};
use std::path::PathBuf;
#[derive(Parser, Debug)]
#[command(name = "oip")]
#[command(about = "Organizational Intelligence Plugin - Defect Pattern Analysis", long_about = None)]
#[command(version)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
/// Enable verbose logging
#[arg(long, global = true)]
pub verbose: bool,
/// Configuration file path
#[arg(long, global = true)]
pub config: Option<PathBuf>,
}
#[derive(Subcommand, Debug)]
pub enum Commands {
/// Analyze GitHub organization for defect patterns
Analyze {
/// Organization name
#[arg(long, required = true)]
org: String,
/// Output file path
#[arg(long, short, default_value = "defects.yaml")]
output: PathBuf,
/// Maximum concurrent repository analysis
#[arg(long, default_value = "10")]
max_concurrent: usize,
/// Path to trained ML model (optional, uses rule-based if not provided)
#[arg(long)]
model: Option<PathBuf>,
/// Confidence threshold for ML predictions (0.0-1.0)
#[arg(long, default_value = "0.65")]
ml_confidence: f32,
},
/// Summarize analysis report for AI consumption (Phase 2)
Summarize {
/// Input YAML report from 'analyze' command
#[arg(long, short, required = true)]
input: PathBuf,
/// Output summary file
#[arg(long, short, required = true)]
output: PathBuf,
/// Strip PII (author names, commit hashes, email addresses)
#[arg(long, default_value = "true")]
strip_pii: bool,
/// Top N defect categories to include
#[arg(long, default_value = "10")]
top_n: usize,
/// Minimum frequency to include
#[arg(long, default_value = "5")]
min_frequency: usize,
/// Include anonymized examples (with PII redacted if strip-pii is true)
#[arg(long, default_value = "false")]
include_examples: bool,
},
/// Review PR with organizational context (Phase 3)
ReviewPr {
/// Baseline summary from weekly analysis
#[arg(long, short, required = true)]
baseline: PathBuf,
/// Files changed in PR (comma-separated)
#[arg(long, short, required = true)]
files: String,
/// Output format: markdown, json
#[arg(long, default_value = "markdown")]
format: String,
/// Output file (stdout if not specified)
#[arg(long, short)]
output: Option<PathBuf>,
},
/// Extract training data from Git repository (Phase 2 ML)
ExtractTrainingData {
/// Path to Git repository
#[arg(long, short, required = true)]
repo: PathBuf,
/// Output JSON file
#[arg(long, short, default_value = "training-data.json")]
output: PathBuf,
/// Minimum confidence threshold (0.0-1.0)
#[arg(long, default_value = "0.75")]
min_confidence: f32,
/// Maximum commits to analyze
#[arg(long, default_value = "1000")]
max_commits: usize,
/// Create train/validation/test splits
#[arg(long, default_value = "true")]
create_splits: bool,
/// Show visualization (requires --features viz)
#[arg(long, default_value = "false")]
viz: bool,
},
/// Train ML classifier on extracted training data (Phase 2 ML)
TrainClassifier {
/// Input training data JSON file
#[arg(long, short, required = true)]
input: PathBuf,
/// Output model file (optional)
#[arg(long, short)]
output: Option<PathBuf>,
/// Number of trees in Random Forest
#[arg(long, default_value = "100")]
n_estimators: usize,
/// Maximum tree depth
#[arg(long, default_value = "20")]
max_depth: usize,
/// Maximum TF-IDF features
#[arg(long, default_value = "1500")]
max_features: usize,
},
/// Export CommitFeatures to aprender-compatible format (Issue #2)
Export {
/// Path to Git repository to analyze
#[arg(long, short, required = true)]
repo: PathBuf,
/// Output file path
#[arg(long, short, default_value = "features.json")]
output: PathBuf,
/// Export format: json, binary, parquet
#[arg(long, short, default_value = "json")]
format: String,
/// Maximum commits to analyze
#[arg(long, default_value = "1000")]
max_commits: usize,
/// Minimum confidence threshold for classification (0.0-1.0)
#[arg(long, default_value = "0.70")]
min_confidence: f32,
},
/// Import Depyler CITL corpus for ground-truth training labels (NLP-014)
ImportDepyler {
/// Path to Depyler JSONL export file
#[arg(long, short, required = true)]
input: PathBuf,
/// Output training data JSON file
#[arg(long, short, default_value = "citl-training.json")]
output: PathBuf,
/// Minimum confidence threshold (0.0-1.0)
#[arg(long, default_value = "0.75")]
min_confidence: f32,
/// Merge with existing training data file (optional)
#[arg(long, short)]
merge: Option<PathBuf>,
/// Create train/validation/test splits
#[arg(long, default_value = "true")]
create_splits: bool,
},
/// Localize faults using Tarantula SBFL (Spectrum-Based Fault Localization)
Localize {
/// Path to LCOV coverage file from passing tests
#[arg(long, required = true)]
passed_coverage: PathBuf,
/// Path to LCOV coverage file from failing tests
#[arg(long, required = true)]
failed_coverage: PathBuf,
/// Number of passing tests
#[arg(long, default_value = "1")]
passed_count: usize,
/// Number of failing tests
#[arg(long, default_value = "1")]
failed_count: usize,
/// SBFL formula: tarantula, ochiai, dstar2, dstar3
#[arg(long, default_value = "tarantula")]
formula: String,
/// Top N suspicious statements to report
#[arg(long, default_value = "10")]
top_n: usize,
/// Output file path
#[arg(long, short, default_value = "fault-localization.yaml")]
output: PathBuf,
/// Output format: yaml, json, terminal
#[arg(long, short, default_value = "yaml")]
format: String,
/// Include TDG scores from pmat (requires pmat)
#[arg(long, default_value = "false")]
enrich_tdg: bool,
/// Repository path for TDG enrichment
#[arg(long)]
repo: Option<PathBuf>,
/// Enable RAG-enhanced localization with trueno-rag
#[arg(long, default_value = "false")]
rag: bool,
/// Path to bug knowledge base YAML file (for RAG)
#[arg(long)]
knowledge_base: Option<PathBuf>,
/// Fusion strategy for RAG: rrf, linear, dbsf, sbfl-only
#[arg(long, default_value = "rrf")]
fusion: String,
/// Number of similar bugs to retrieve (for RAG)
#[arg(long, default_value = "5")]
similar_bugs: usize,
/// Enable weighted ensemble model (Phase 6)
#[arg(long, default_value = "false")]
ensemble: bool,
/// Path to trained ensemble model file
#[arg(long)]
ensemble_model: Option<PathBuf>,
/// Include churn metrics from git history (for ensemble)
#[arg(long, default_value = "false")]
include_churn: bool,
/// Enable calibrated probability output (Phase 7)
#[arg(long, default_value = "false")]
calibrated: bool,
/// Path to trained calibration model file
#[arg(long)]
calibration_model: Option<PathBuf>,
/// Confidence threshold for calibrated predictions (0.0-1.0)
#[arg(long, default_value = "0.5")]
confidence_threshold: f32,
},
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_cli_structure_exists() {
// Verify the CLI structure compiles
// This is a sanity check test
let _cli_type_check: Option<Cli> = None;
let _commands_type_check: Option<Commands> = None;
}
}