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_scrub.rs

50 lines · 2473 bytes Raw Blame History
1//! Turn a qualification capture (`qualification/captures/**.json`, as written by the live probe
2//! work) into a sanitized replay fixture. Scrubs first, scans second, and refuses to write if the
3//! scan still finds anything. The golden `expect` is bootstrapped from the current parser and
4//! MUST be reviewed by a human before commit.
5//!
6//! usage: replay_scrub <capture.json> <out.json> <provider> <source_commit> <captured_on>
7use interplane_lenshift::replay::{replay, scan, scrub_value, Capture};
8use serde_json::{json, Value};
9
10fn main() {
11 let a: Vec<String> = std::env::args().collect();
12 if a.len() != 6 {
13 eprintln!("usage: replay_scrub <capture.json> <out.json> <provider> <source_commit> <captured_on>");
14 std::process::exit(2);
15 }
16 let src: Value =
17 serde_json::from_str(&std::fs::read_to_string(&a[1]).expect("read")).expect("json");
18 let stream = src["request"]["stream"].as_bool().unwrap_or(false);
19 let body = src["response"].as_str().expect("response body is text");
20 let chunks: Vec<String> = if stream {
21 body.split_inclusive("\n\n").map(String::from).collect()
22 } else {
23 vec![body.to_string()]
24 };
25 let mut fx = json!({
26 "format": "interplane-replay/1",
27 "name": src["name"],
28 "provider": a[3],
29 "model": src["request"]["model"],
30 "endpoint_kind": if stream { "chat_completions_stream" } else { "chat_completions" },
31 "provenance": {"origin": "recorded", "source_commit": a[4], "captured_on": a[5],
32 "note": format!("scrubbed from a qualification capture named {}", src["name"].as_str().unwrap_or("unnamed"))},
33 "request": {"method": "POST", "path": src["endpoint"], "header_names": ["Content-Type"],
34 "body": src["request"]},
35 "response": {"status": 200, "header_names": ["Content-Type"], "chunks": chunks},
36 "expect": {"class": "parsed", "text": "", "tool_calls": [], "rejected": [], "partial": false}
37 });
38 scrub_value(&mut fx);
39 let cap: Capture = serde_json::from_value(fx.clone()).expect("shape");
40 fx["expect"] = serde_json::to_value(replay(&cap)).unwrap();
41 let findings = scan(&fx);
42 if !findings.is_empty() {
43 eprintln!(
44 "refusing to write, still sensitive after scrub:\n{}",
45 findings.join("\n")
46 );
47 std::process::exit(1);
48 }
49 std::fs::write(&a[2], serde_json::to_string_pretty(&fx).unwrap() + "\n").expect("write");
50}