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
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
//! Clap argument definitions: CLI struct, subcommand enum, output types.
use clap::{Parser, Subcommand};
use super::args;
// EX-4: Verify clap default_value strings match the actual constants.
// Integer constants can use compile-time assert; f32 checked in tests below.
const _: () = assert!(crate::cli::config::DEFAULT_LIMIT == 5);
/// Output format for commands that support text/json/mermaid
#[derive(Clone, Debug, clap::ValueEnum)]
pub enum OutputFormat {
Text,
Json,
Mermaid,
}
/// Parse an `OutputFormat` that only allows text or json (rejects mermaid at parse time).
///
/// Used by `review` and `ci` commands which accept `--format` but don't support mermaid output.
/// Catches the error at argument parsing rather than failing at runtime.
fn parse_text_or_json_format(s: &str) -> std::result::Result<OutputFormat, String> {
match s.to_ascii_lowercase().as_str() {
"text" => Ok(OutputFormat::Text),
"json" => Ok(OutputFormat::Json),
"mermaid" => {
Err("mermaid output is not supported for this command — use text or json".into())
}
other => Err(format!("invalid format '{other}' — expected text or json")),
}
}
impl std::fmt::Display for OutputFormat {
/// Formats the enum variant as a human-readable string representation.
///
/// # Arguments
///
/// * `f` - The formatter to write the output to
///
/// # Returns
///
/// A `std::fmt::Result` indicating success or formatting error
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Text => write!(f, "text"),
Self::Json => write!(f, "json"),
Self::Mermaid => write!(f, "mermaid"),
}
}
}
/// AD-49: Common output format arguments shared across commands that support text/json/mermaid.
#[derive(Clone, Debug, clap::Args)]
pub struct OutputArgs {
/// Output format: text, json, mermaid (use --json as shorthand for --format json)
#[arg(long, default_value = "text")]
pub format: OutputFormat,
/// Shorthand for --format json
#[arg(long, conflicts_with = "format")]
pub json: bool,
}
impl OutputArgs {
/// Resolve the effective format (--json overrides --format).
pub fn effective_format(&self) -> OutputFormat {
if self.json {
OutputFormat::Json
} else {
self.format.clone()
}
}
}
/// AD-49: Output format arguments for commands that only support text/json (no mermaid).
#[derive(Clone, Debug, clap::Args)]
pub struct TextJsonArgs {
/// Output format: text, json (use --json as shorthand for --format json; mermaid not supported)
#[arg(long, default_value = "text", value_parser = parse_text_or_json_format)]
pub format: OutputFormat,
/// Shorthand for --format json
#[arg(long, conflicts_with = "format")]
pub json: bool,
}
impl TextJsonArgs {
/// Resolve the effective format (--json overrides --format).
pub fn effective_format(&self) -> OutputFormat {
if self.json {
OutputFormat::Json
} else {
self.format.clone()
}
}
}
/// Re-export `GateThreshold` so CLI and batch code can reference it directly.
pub use cqs::ci::GateThreshold;
/// Audit mode state for the audit-mode command
#[derive(Clone, Debug, clap::ValueEnum)]
pub enum AuditModeState {
/// Enable audit mode
On,
/// Disable audit mode
Off,
}
/// Parse a non-zero usize for --tokens validation
pub(crate) fn parse_nonzero_usize(s: &str) -> std::result::Result<usize, String> {
let val: usize = s.parse().map_err(|e| format!("{e}"))?;
if val == 0 {
return Err("value must be at least 1".to_string());
}
Ok(val)
}
/// Validate that a float parameter is finite (not NaN or Infinity).
pub(crate) fn validate_finite_f32(val: f32, name: &str) -> anyhow::Result<f32> {
if val.is_finite() {
Ok(val)
} else {
anyhow::bail!("Invalid {name}: {val} (must be a finite number)")
}
}
#[derive(Parser)]
#[command(name = "cqs")]
#[command(about = "Semantic code search with local embeddings")]
#[command(version)]
pub struct Cli {
#[command(subcommand)]
pub(super) command: Option<Commands>,
/// Search query (quote multi-word queries)
pub query: Option<String>,
/// Max results
#[arg(short = 'n', long, default_value = "5")]
pub limit: usize,
/// Min similarity threshold
///
/// NOTE: `-t` is intentionally overloaded across subcommands.
/// In search/similar (here and top-level), it means "min similarity threshold" (default 0.3).
/// In diff/drift, it means "match threshold" for identity (default 0.95).
/// The semantics differ because the baseline similarity differs: search returns
/// low-similarity results worth filtering, while diff/drift compare known pairs
/// where 0.95+ means "unchanged".
#[arg(short = 't', long, default_value = "0.3")]
pub threshold: f32,
/// Weight for name matching in hybrid search (0.0-1.0)
#[arg(long, default_value = "0.2")]
pub name_boost: f32,
/// Filter by language
#[arg(short = 'l', long)]
pub lang: Option<String>,
/// Include only these chunk types in results (e.g., function, struct, test, endpoint)
#[arg(long, alias = "chunk-type")]
pub include_type: Option<Vec<String>>,
/// Exclude these chunk types from results (e.g., test, variable, configkey)
#[arg(long)]
pub exclude_type: Option<Vec<String>>,
/// Filter by path pattern (glob)
#[arg(short = 'p', long)]
pub path: Option<String>,
/// Filter by structural pattern (builder, error_swallow, async, mutex, unsafe, recursion)
#[arg(long)]
pub pattern: Option<String>,
/// Definition search: find by name only, skip embedding (faster)
#[arg(long)]
pub name_only: bool,
/// Pure semantic similarity, disable RRF hybrid search (deprecated — RRF now off by default)
#[arg(long)]
pub semantic_only: bool,
/// Enable RRF hybrid search (keyword + semantic fusion). Off by default — pure cosine is faster and scores higher on expanded eval.
#[arg(long)]
pub rrf: bool,
/// Include documentation, markdown, and config chunks in search results. Default: code only.
#[arg(long)]
pub include_docs: bool,
/// Re-rank results with cross-encoder (slower, more accurate)
#[arg(long)]
pub rerank: bool,
/// Enable SPLADE sparse-dense hybrid search (requires SPLADE model)
#[arg(long)]
pub splade: bool,
/// SPLADE fusion weight: 1.0 = pure cosine, 0.0 = pure sparse (default: 0.7)
#[arg(long, default_value = "0.7")]
pub splade_alpha: f32,
/// Output as JSON
#[arg(long)]
pub json: bool,
/// Show only file:line, no code
#[arg(long)]
pub no_content: bool,
/// Show N lines of context before/after the chunk
#[arg(short = 'C', long)]
pub context: Option<usize>,
/// Expand results with parent context (small-to-big retrieval)
#[arg(long)]
pub expand: bool,
/// Search only this reference index (skip project index)
#[arg(long = "ref")]
pub ref_name: Option<String>,
/// Include reference indexes in search results (default: project only)
#[arg(long)]
pub include_refs: bool,
/// Maximum token budget for results (packs highest-scoring into budget)
#[arg(long, value_parser = parse_nonzero_usize)]
pub tokens: Option<usize>,
/// Suppress progress output
#[arg(short, long)]
pub quiet: bool,
/// Disable staleness checks (skip per-file mtime comparison)
#[arg(long)]
pub no_stale_check: bool,
/// Disable search-time demotion of test functions and underscore-prefixed names
#[arg(long)]
pub no_demote: bool,
/// Embedding model: bge-large (default), e5-base, or custom
#[arg(long)]
pub model: Option<String>,
/// Show debug info (sets RUST_LOG=debug)
#[arg(short, long)]
pub verbose: bool,
/// Resolved model config (set by dispatch, not CLI).
#[arg(skip)]
pub resolved_model: Option<cqs::embedder::ModelConfig>,
}
impl Cli {
/// Get the resolved model config, returning an error if not yet resolved.
///
/// Prefer this over [`model_config`] in new code — it propagates a proper
/// error instead of panicking.
pub fn try_model_config(&self) -> anyhow::Result<&cqs::embedder::ModelConfig> {
self.resolved_model
.as_ref()
.ok_or_else(|| anyhow::anyhow!("ModelConfig not resolved — call resolve_model() first"))
}
/// Get the resolved model config. Panics if called before dispatch resolves it.
///
/// **Deprecated:** Use [`try_model_config`] instead — it returns `Result`
/// rather than panicking on unresolved config.
#[deprecated(note = "use try_model_config() which returns Result instead of panicking")]
pub fn model_config(&self) -> &cqs::embedder::ModelConfig {
self.resolved_model
.as_ref()
.expect("BUG: ModelConfig not resolved — dispatch() must call resolve_model() first")
}
}
#[derive(Subcommand)]
pub(super) enum Commands {
/// Download model and create .cqs/
Init,
/// One-line-per-function summary for a file
Brief {
/// File path (as stored in index, e.g. src/lib.rs)
path: String,
#[command(flatten)]
output: TextJsonArgs,
},
/// Check model, index, hardware
Doctor {
/// Auto-fix detected issues (stale→index, schema→migrate)
#[arg(long)]
fix: bool,
},
/// Index current project
Index {
#[command(flatten)]
args: args::IndexArgs,
},
/// Show index statistics
Stats {
#[command(flatten)]
output: TextJsonArgs,
},
/// Watch for changes and reindex
Watch {
/// Debounce interval in milliseconds
#[arg(long, default_value = "500")]
debounce: u64,
/// Index files ignored by .gitignore
#[arg(long)]
no_ignore: bool,
/// Use polling instead of inotify (reliable on WSL /mnt/ paths)
#[arg(long)]
poll: bool,
},
/// What functions, callers, and tests are affected by current diff
Affected {
/// Git ref to diff against (default: unstaged changes)
#[arg(long)]
base: Option<String>,
#[command(flatten)]
output: TextJsonArgs,
},
/// Batch mode: read commands from stdin, output JSONL
Batch,
/// Semantic git blame: who changed a function, when, and why
Blame {
#[command(flatten)]
args: args::BlameArgs,
#[command(flatten)]
output: TextJsonArgs,
},
/// Interactive REPL for cqs commands
Chat,
/// Generate shell completions
Completions {
/// Shell to generate completions for
#[arg(value_enum)]
shell: clap_complete::Shell,
},
/// Show type dependencies: who uses a type, or what types a function uses
Deps {
/// Type name (forward) or function name (with --reverse)
name: String,
/// Reverse: show types used by a function instead of type users
#[arg(long)]
reverse: bool,
/// Query across all configured reference projects
#[arg(long)]
cross_project: bool,
#[command(flatten)]
output: TextJsonArgs,
},
/// Find functions that call a given function
Callers {
/// Function name to search for
name: String,
/// Query callers across all configured reference projects
#[arg(long)]
cross_project: bool,
#[command(flatten)]
output: TextJsonArgs,
},
/// Find functions called by a given function
Callees {
/// Function name to search for
name: String,
/// Query callees across all configured reference projects
#[arg(long)]
cross_project: bool,
#[command(flatten)]
output: TextJsonArgs,
},
/// Guided codebase tour: entry point → call chain → types → tests
Onboard {
/// Concept or query to explore
query: String,
/// Callee expansion depth
#[arg(short = 'd', long, default_value = "3")]
depth: usize,
#[command(flatten)]
output: TextJsonArgs,
/// Maximum token budget
#[arg(long, value_parser = parse_nonzero_usize)]
tokens: Option<usize>,
},
/// Brute-force nearest neighbors for a function by cosine similarity
Neighbors {
/// Function name or file:function
name: String,
/// Max neighbors to return
#[arg(short = 'n', long, default_value = "5")]
limit: usize,
#[command(flatten)]
output: TextJsonArgs,
},
/// List and manage notes
Notes {
#[command(subcommand)]
subcmd: NotesCommand,
},
/// Manage reference indexes for multi-index search
Ref {
#[command(subcommand)]
subcmd: RefCommand,
},
/// Semantic diff between indexed snapshots
Diff {
/// Reference name to compare from
source: String,
/// Reference name or "project" (default: project)
target: Option<String>,
/// Similarity threshold for "modified" (default: 0.95)
///
/// `-t` here means "match threshold" — pairs above this are "unchanged",
/// below are "modified". Different from search's `-t` (min similarity 0.3).
/// See top-level threshold doc for rationale.
#[arg(short = 't', long, default_value = "0.95")]
threshold: f32,
/// Filter by language
#[arg(short = 'l', long)]
lang: Option<String>,
#[command(flatten)]
output: TextJsonArgs,
},
/// Detect semantic drift between a reference and the project
Drift {
/// Reference name to compare against
reference: String,
/// Similarity threshold (default: 0.95)
///
/// See Diff's `-t` doc — same overload rationale applies.
#[arg(short = 't', long, default_value = "0.95")]
threshold: f32,
/// Minimum drift to show (default: 0.0)
#[arg(long, default_value = "0.0")]
min_drift: f32,
/// Filter by language
#[arg(short = 'l', long)]
lang: Option<String>,
/// Maximum entries to show
#[arg(short = 'n', long)]
limit: Option<usize>,
#[command(flatten)]
output: TextJsonArgs,
},
/// Generate a function card (signature, callers, callees, similar)
Explain {
/// Function name or file:function
name: String,
#[command(flatten)]
output: TextJsonArgs,
/// Maximum token budget (includes source content within budget)
#[arg(long, value_parser = parse_nonzero_usize)]
tokens: Option<usize>,
},
/// Find code similar to a given function
Similar {
#[command(flatten)]
args: args::SimilarArgs,
#[command(flatten)]
output: TextJsonArgs,
},
/// Impact analysis: what breaks if you change a function
Impact {
#[command(flatten)]
args: args::ImpactArgs,
#[command(flatten)]
output: OutputArgs,
},
/// Impact analysis from a git diff — what callers and tests are affected
#[command(name = "impact-diff")]
ImpactDiff {
/// Git ref to diff against (default: unstaged changes)
#[arg(long)]
base: Option<String>,
/// Read diff from stdin instead of running git
#[arg(long)]
stdin: bool,
#[command(flatten)]
output: TextJsonArgs,
},
/// Comprehensive diff review: impact + notes + risk scoring
Review {
/// Git ref to diff against (default: unstaged changes)
#[arg(long)]
base: Option<String>,
/// Read diff from stdin instead of running git
#[arg(long)]
stdin: bool,
#[command(flatten)]
output: TextJsonArgs,
/// Maximum token budget for output (truncates callers/tests lists)
#[arg(long, value_parser = parse_nonzero_usize)]
tokens: Option<usize>,
},
/// CI pipeline analysis: impact + risk + dead code + gate
Ci {
/// Git ref to diff against (default: unstaged changes)
#[arg(long)]
base: Option<String>,
/// Read diff from stdin instead of running git
#[arg(long)]
stdin: bool,
#[command(flatten)]
output: TextJsonArgs,
/// Gate threshold: high, medium, off (default: high)
#[arg(long, default_value = "high")]
gate: GateThreshold,
/// Maximum token budget for output
#[arg(long, value_parser = parse_nonzero_usize)]
tokens: Option<usize>,
},
/// Trace call chain between two functions
Trace {
#[command(flatten)]
args: args::TraceArgs,
#[command(flatten)]
output: OutputArgs,
},
/// Find tests that exercise a function
TestMap {
/// Function name or file:function
name: String,
/// Max call chain depth to search
#[arg(long, default_value = "5")]
depth: usize,
/// Search for tests across all configured reference projects
#[arg(long)]
cross_project: bool,
#[command(flatten)]
output: TextJsonArgs,
},
/// What do I need to know to work on this file
Context {
#[command(flatten)]
args: args::ContextArgs,
#[command(flatten)]
output: TextJsonArgs,
},
/// Find functions with no callers (dead code detection)
Dead {
#[command(flatten)]
args: args::DeadArgs,
#[command(flatten)]
output: TextJsonArgs,
},
/// Gather minimal code context to answer a question
Gather {
#[command(flatten)]
args: args::GatherArgs,
#[command(flatten)]
output: TextJsonArgs,
},
/// Manage cross-project search registry
Project {
#[command(subcommand)]
subcmd: ProjectCommand,
},
/// Remove stale chunks and rebuild index
Gc {
#[command(flatten)]
output: TextJsonArgs,
},
/// Codebase quality snapshot — dead code, staleness, hotspots, coverage
Health {
#[command(flatten)]
output: TextJsonArgs,
},
/// Toggle audit mode (exclude notes from search/read)
#[command(name = "audit-mode")]
AuditMode {
/// State: on or off (omit to query current state)
state: Option<AuditModeState>,
/// Expiry duration (e.g., "30m", "1h", "2h30m")
#[arg(long, default_value = "30m")]
expires: String,
#[command(flatten)]
output: TextJsonArgs,
},
/// Usage telemetry dashboard — command frequency, categories, sessions
Telemetry {
/// Reset: archive current telemetry and start fresh
#[arg(long)]
reset: bool,
/// Reason for reset (used in the reset event)
#[arg(long, requires = "reset")]
reason: Option<String>,
/// Include archived telemetry files
#[arg(long)]
all: bool,
#[command(flatten)]
output: TextJsonArgs,
},
/// Check index freshness — list stale and missing files
Stale {
#[command(flatten)]
output: TextJsonArgs,
/// Show counts only, skip file list
#[arg(long)]
count_only: bool,
},
/// Auto-suggest notes from codebase patterns (dead code, untested hotspots)
Suggest {
#[command(flatten)]
output: TextJsonArgs,
/// Apply suggestions (add notes to docs/notes.toml)
#[arg(long)]
apply: bool,
},
/// Read a file with notes injected as comments
Read {
/// File path relative to project root
path: String,
/// Focus on a specific function (returns only that function + type deps)
#[arg(long)]
focus: Option<String>,
#[command(flatten)]
output: TextJsonArgs,
},
/// Reconstruct source file from index (works without source on disk)
Reconstruct {
/// File path (as indexed)
path: String,
#[command(flatten)]
output: TextJsonArgs,
},
/// Find functions related by shared callers, callees, or types
Related {
/// Function name or file:function
name: String,
/// Max results per category
#[arg(short = 'n', long, default_value = "5")]
limit: usize,
#[command(flatten)]
output: TextJsonArgs,
},
/// Suggest where to add new code matching a description
Where {
/// Description of the code to add
description: String,
/// Max file suggestions
#[arg(short = 'n', long, default_value = "3")]
limit: usize,
#[command(flatten)]
output: TextJsonArgs,
},
/// Pre-investigation dashboard: search, group, count callers/tests, check staleness
Scout {
#[command(flatten)]
args: args::ScoutArgs,
#[command(flatten)]
output: TextJsonArgs,
},
/// Task planning with template classification: classify + scout + checklist
Plan {
/// Task description to plan
description: String,
/// Max scout file groups
#[arg(short = 'n', long, default_value = "5")]
limit: usize,
#[command(flatten)]
output: TextJsonArgs,
/// Maximum token budget
#[arg(long, value_parser = parse_nonzero_usize)]
tokens: Option<usize>,
},
/// One-shot implementation context: scout + code + impact + placement + notes
Task {
/// Task description
description: String,
/// Max file groups to return
#[arg(short = 'n', long, default_value = "5")]
limit: usize,
#[command(flatten)]
output: TextJsonArgs,
/// Maximum token budget (waterfall across sections)
#[arg(long, value_parser = parse_nonzero_usize)]
tokens: Option<usize>,
/// Compact output (~200 tokens): files, at-risk functions, test coverage
#[arg(long)]
brief: bool,
},
/// Convert documents (PDF, HTML, CHM) to Markdown
#[cfg(feature = "convert")]
Convert {
/// File or directory to convert
path: String,
/// Output directory for .md files [default: same as input]
#[arg(short = 'o', long)]
output: Option<String>,
/// Overwrite existing .md files
#[arg(long)]
overwrite: bool,
/// Preview conversions without writing files
#[arg(long)]
dry_run: bool,
/// Cleaning rule tags (comma-separated, e.g. "aveva,generic") [default: all]
#[arg(long)]
clean_tags: Option<String>,
},
/// Export a HuggingFace model to ONNX format for use with cqs
ExportModel {
/// HuggingFace model repo ID
#[arg(long)]
repo: String,
/// Output directory
#[arg(long, default_value = ".")]
output: std::path::PathBuf,
/// Embedding dimension override (auto-detected from config.json if omitted)
#[arg(long)]
dim: Option<u64>,
},
/// Generate training data for fine-tuning from git history
TrainData {
/// Paths to git repositories to process
#[arg(long, required = true, num_args = 1..)]
repos: Vec<std::path::PathBuf>,
/// Output JSONL file path
#[arg(long)]
output: std::path::PathBuf,
/// Maximum commits to process per repo (0 = unlimited)
#[arg(long, default_value = "0")]
max_commits: usize,
/// Minimum commit message length to include
#[arg(long, default_value = "15")]
min_msg_len: usize,
/// Maximum files changed per commit to include
#[arg(long, default_value = "20")]
max_files: usize,
/// Maximum identical-query triplets (dedup cap)
#[arg(long, default_value = "5")]
dedup_cap: usize,
/// Resume from checkpoint
#[arg(long)]
resume: bool,
/// Verbose output
#[arg(long)]
verbose: bool,
},
/// Extract (NL, code) training pairs from index as JSONL
TrainPairs {
/// Output JSONL file path
#[arg(long)]
output: String,
/// Max pairs to extract
#[arg(long)]
limit: Option<usize>,
/// Filter by language (e.g., "Rust", "Python")
#[arg(long)]
language: Option<String>,
/// Add contrastive prefixes from call graph callees
#[arg(long)]
contrastive: bool,
},
/// Manage global embedding cache (stats, clear, prune)
Cache {
#[command(subcommand)]
subcmd: CacheCommand,
},
}
// Re-export the subcommand types used in Commands variants
pub(super) use super::commands::{CacheCommand, NotesCommand, ProjectCommand, RefCommand};
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn validate_finite_f32_normal_values() {
assert!(validate_finite_f32(0.0, "test").is_ok());
assert!(validate_finite_f32(1.0, "test").is_ok());
assert!(validate_finite_f32(-1.0, "test").is_ok());
assert!(validate_finite_f32(0.5, "test").is_ok());
}
#[test]
fn validate_finite_f32_rejects_nan() {
let result = validate_finite_f32(f32::NAN, "threshold");
assert!(result.is_err());
assert!(result.unwrap_err().to_string().contains("threshold"));
}
#[test]
fn validate_finite_f32_rejects_infinity() {
assert!(validate_finite_f32(f32::INFINITY, "test").is_err());
assert!(validate_finite_f32(f32::NEG_INFINITY, "test").is_err());
}
#[test]
fn validate_finite_f32_returns_value_on_success() {
assert_eq!(validate_finite_f32(0.42, "x").unwrap(), 0.42);
}
/// EX-4: Verify clap default_value strings match the f32 constants.
/// f32 can't be used in const assert, so we check at test time.
#[test]
fn clap_defaults_match_constants() {
use crate::cli::config::{DEFAULT_LIMIT, DEFAULT_NAME_BOOST, DEFAULT_THRESHOLD};
// default_value = "5"
assert_eq!(DEFAULT_LIMIT, 5);
// default_value = "0.3"
assert!((DEFAULT_THRESHOLD - 0.3).abs() < f32::EPSILON);
// default_value = "0.2"
assert!((DEFAULT_NAME_BOOST - 0.2).abs() < f32::EPSILON);
}
}