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 / provenance / src / main.rs

95 lines · 4196 bytes Raw Blame History
1//! `interplane-provenance verify <dir> [--judge-key <file> [--policy-sha256 <hex>]]` prints one verdict line (exit 0 on
2//! PASS*, 1 on FAIL). The judge key file holds the independent judge's SEC1 hex public key.
3//! `interplane-provenance gen-synthetic <dir> [weak|fix-the-test|fix-the-test-native|fix-the-test-stub]` writes the synthetic full-chain fixture
4//! (ledger-slice binding; `weak` writes the record_effect_receipt/1 variant).
5//! `interplane-provenance seal <dir> <skeleton.json>` seals a new COMPANION.json (never overwrites).
6
7use std::path::Path;
8use std::process::ExitCode;
9
10fn report(v: String) -> ExitCode {
11 println!("{v}");
12 if v.starts_with("PASS") {
13 ExitCode::SUCCESS
14 } else {
15 ExitCode::from(1)
16 }
17}
18
19fn main() -> ExitCode {
20 let a: Vec<String> = std::env::args().collect();
21 match (a.get(1).map(String::as_str), a.get(2), a.get(3)) {
22 (Some("verify"), Some(dir), None) => report(interplane_provenance::verify(Path::new(dir))),
23 (Some("verify"), Some(dir), Some(flag)) if flag == "--judge-key" => {
24 // The judge key and the policy pin come from the operator, never from the bundle.
25 let key = a
26 .get(4)
27 .and_then(|p| std::fs::read_to_string(p).ok())
28 .and_then(|t| interplane_provenance::evaluation::parse_judge_key(&t).ok());
29 let pin = match (a.get(5).map(String::as_str), a.get(6), a.get(7)) {
30 (None, _, _) => Ok(None),
31 (Some("--policy-sha256"), Some(h), None)
32 if h.len() == 64 && h.bytes().all(|b| b.is_ascii_hexdigit()) =>
33 {
34 Ok(Some(h.to_ascii_lowercase()))
35 }
36 _ => Err(()),
37 };
38 match (key, pin) {
39 (Some(k), Ok(policy_sha256)) => report(interplane_provenance::verify_with(
40 Path::new(dir),
41 &interplane_provenance::Options {
42 judge_key: Some(k),
43 policy_sha256,
44 },
45 )),
46 _ => {
47 eprintln!("--judge-key needs a file holding the judge's SEC1 hex public key; --policy-sha256 needs 64 hex characters");
48 ExitCode::from(2)
49 }
50 }
51 }
52 (Some("gen-synthetic"), Some(dir), mode @ (None | Some(_))) => {
53 let opts = interplane_provenance::synth::Opts {
54 weak: mode.map(String::as_str) == Some("weak"),
55 fix_the_test: matches!(
56 mode.map(String::as_str),
57 Some("fix-the-test" | "fix-the-test-native" | "fix-the-test-stub")
58 ),
59 native: match mode.map(String::as_str) {
60 Some("fix-the-test-native") => Some(true),
61 Some("fix-the-test-stub") => Some(false),
62 _ => None,
63 },
64 ..Default::default()
65 };
66 match interplane_provenance::synth::write_synthetic(Path::new(dir), &opts) {
67 Ok(()) => ExitCode::SUCCESS,
68 Err(e) => {
69 eprintln!("{e}");
70 ExitCode::from(2)
71 }
72 }
73 }
74 (Some("seal"), Some(dir), Some(sk)) => {
75 let sk = std::fs::read(sk)
76 .ok()
77 .and_then(|b| serde_json::from_slice(&b).ok());
78 match sk.map(|v| interplane_provenance::synth::seal(Path::new(dir), v)) {
79 Some(Ok(())) => ExitCode::SUCCESS,
80 Some(Err(e)) => {
81 eprintln!("{e}");
82 ExitCode::from(2)
83 }
84 None => {
85 eprintln!("unreadable skeleton");
86 ExitCode::from(2)
87 }
88 }
89 }
90 _ => {
91 eprintln!("usage: interplane-provenance verify <dir> [--judge-key <pubkey-hex-file> [--policy-sha256 <hex>]] | gen-synthetic <dir> [weak|fix-the-test|fix-the-test-native|fix-the-test-stub] | seal <dir> <skeleton.json>");
92 ExitCode::from(2)
93 }
94 }
95}