(
config: &Config,
threshold: f64,
min_count: usize,
limit: usize,
show_variants: bool,
sort: &str,
min_length: usize,
format: OutputFormat,
)
| 483 | |
| 484 | #[allow(clippy::too_many_arguments)] |
| 485 | pub async fn duplicates( |
| 486 | config: &Config, |
| 487 | threshold: f64, |
| 488 | min_count: usize, |
| 489 | limit: usize, |
| 490 | show_variants: bool, |
| 491 | sort: &str, |
| 492 | min_length: usize, |
| 493 | format: OutputFormat, |
| 494 | ) -> Result<()> { |
| 495 | use crate::dedup::FuzzyDeduper; |
| 496 | |
| 497 | let history = HistoryDataSource::new(config.clone()); |
| 498 | let entries = history.filter_prompts().await?; |
| 499 | |
| 500 | // Include timestamps for sorting |
| 501 | let prompts: Vec<(String, i64)> = entries |
| 502 | .iter() |
| 503 | .map(|e| (e.display.clone(), e.timestamp)) |
| 504 | .collect(); |
| 505 | |
| 506 | let deduper = FuzzyDeduper::new(threshold, min_length); |
| 507 | let mut clusters = deduper.cluster(prompts); |
| 508 | |
| 509 | // Sort based on user preference |
| 510 | match sort { |
| 511 | "latest" => FuzzyDeduper::sort_by_latest(&mut clusters), |
| 512 | _ => FuzzyDeduper::sort_by_count(&mut clusters), |
| 513 | } |
| 514 | |
| 515 | let filtered: Vec<_> = clusters |
| 516 | .into_iter() |
| 517 | .filter(|c| c.count >= min_count) |
| 518 | .take(limit) |
| 519 | .collect(); |
| 520 | |
| 521 | let mut writer = OutputWriter::new(std::io::stdout(), format); |
| 522 | |
| 523 | match format { |
| 524 | OutputFormat::Json => { |
| 525 | let data: Vec<_> = filtered |
| 526 | .iter() |
| 527 | .map(|c| { |
| 528 | serde_json::json!({ |
| 529 | "prompt": c.canonical, |
| 530 | "count": c.count, |
| 531 | "latest": c.latest_timestamp, |
| 532 | "variants": c.variants |
| 533 | }) |
| 534 | }) |
| 535 | .collect(); |
| 536 | writer.write_json(&data)?; |
| 537 | } |
| 538 | OutputFormat::Raw | OutputFormat::Jsonl => { |
| 539 | for cluster in &filtered { |
| 540 | writer.write_json(&serde_json::json!({ |
| 541 | "prompt": cluster.canonical, |
| 542 | "count": cluster.count, |
no test coverage detected