use std::collections::BTreeMap;
use steeldb::dsl_trajectories::{gen, needle_tools_json};
use steeldb::trajectories::synth_corpora;
use steeldb::Corpus;
fn main() {
let args: Vec<String> = std::env::args().collect();
let Some(out_path) = args.get(1).cloned() else {
eprintln!("usage: gen_dsl_trajectories <out.jsonl> [n_synth] [corpus.csv ...]");
std::process::exit(2);
};
let n_synth: usize = args.get(2).and_then(|s| s.parse().ok()).unwrap_or(24);
let mut corpora = synth_corpora(n_synth, 0x51ed270b);
for path in args.iter().skip(3) {
match Corpus::from_csv(std::path::Path::new(path)) {
Ok(c) => corpora.push((path.clone(), c)),
Err(e) => eprintln!("skip {path}: {e}"),
}
}
let mut lines = Vec::new();
let mut cov: BTreeMap<String, usize> = BTreeMap::new();
for (_name, corpus) in &corpora {
let tools = needle_tools_json(corpus);
for t in gen(corpus) {
*cov.entry(t.kind.to_string()).or_default() += 1;
lines.push(t.to_needle_example(&tools).to_string());
}
}
let body: String = lines.iter().map(|l| format!("{l}\n")).collect();
if let Err(e) = std::fs::write(&out_path, body) {
eprintln!("write {out_path}: {e}");
std::process::exit(1);
}
eprintln!("wrote {} verified DSL trajectories from {} corpora → {out_path}", lines.len(), corpora.len());
eprintln!("kind coverage: {}", cov.iter().map(|(k, v)| format!("{k}={v}")).collect::<Vec<_>>().join(" "));
}