interplane.Get Omega
Read in your language

interplane-mv

INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority.

Brought by drakestapleton

branch main Branches Tags History

interplane-mv / rust / crates / interplane-lenshift / examples / replay_scan.rs

44 lines · 1523 bytes Raw Blame History
1//! Standalone scanner: `replay_scan <dir-or-file>...` scans every `.json` file below each path,
2//! recursively, and exits non-zero if any file has a finding. Run it on anything you plan to
3//! commit as a replay fixture (including drafts outside `dialects/replay`).
4use interplane_lenshift::replay::scan;
5use serde_json::Value;
6use std::path::Path;
7
8fn walk(p: &Path, bad: &mut usize, n: &mut usize) {
9 if p.is_dir() {
10 let mut es: Vec<_> = std::fs::read_dir(p)
11 .expect("read dir")
12 .map(|e| e.unwrap().path())
13 .collect();
14 es.sort();
15 for e in es {
16 walk(&e, bad, n);
17 }
18 } else if p.extension().and_then(|e| e.to_str()) == Some("json") {
19 *n += 1;
20 let t = std::fs::read_to_string(p).expect("read");
21 let found = match serde_json::from_str::<Value>(&t) {
22 Ok(v) => scan(&v),
23 Err(e) => vec![format!("not JSON: {e}")],
24 };
25 if !found.is_empty() {
26 *bad += 1;
27 eprintln!("{}:\n {}", p.display(), found.join("\n "));
28 }
29 }
30}
31
32fn main() {
33 let (mut bad, mut n) = (0, 0);
34 let args: Vec<String> = std::env::args().skip(1).collect();
35 if args.is_empty() {
36 eprintln!("usage: replay_scan <dir-or-file>...");
37 std::process::exit(2);
38 }
39 for a in &args {
40 walk(Path::new(a), &mut bad, &mut n);
41 }
42 println!("scanned {n} files, {bad} with findings");
43 std::process::exit(if bad == 0 && n > 0 { 0 } else { 1 });
44}