Skip to repository content172 lines · 6.4 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T03:00:59.543Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
evidence_chain.rs
1use serde_json::Value;
2use workroom_receipts::{InspectorField, PublicRef};
3
4#[derive(Clone, Debug, PartialEq, Eq)]
5pub struct FullAutoEvidenceView {
6 pub fields: Vec<InspectorField>,
7}
8
9impl FullAutoEvidenceView {
10 pub fn from_records(report: &Value, receipt: &Value) -> Option<Self> {
11 let report_run = public_ref(report, "runRef")?;
12 let receipt_run = public_ref(receipt, "runRef")?;
13 if report_run != receipt_run {
14 return None;
15 }
16 let evidence = report.get("evidence")?;
17 let objective_ref = public_ref(evidence, "objectiveRef")?;
18 let turn_ref = public_ref(evidence, "turnRef")?;
19 let change_ref = public_ref(evidence, "changeRef")?;
20 let project_generation = public_ref(evidence, "projectGeneration")?;
21 let verification_ref = public_ref(evidence, "verificationRef")?;
22 let test_outcome = public_ref(evidence, "testOutcome")?;
23 let test_command = bounded_public_command(evidence.get("testCommand")?.as_str()?)?;
24 let diff_summary = bounded_public_text(evidence.get("diffSummary")?.as_str()?)?;
25 if evidence.get("hostExecuted").and_then(Value::as_bool) != Some(true) {
26 return None;
27 }
28
29 for (field, expected) in [
30 ("objectiveRef", &objective_ref),
31 ("turnRef", &turn_ref),
32 ("changeRef", &change_ref),
33 ("verificationRef", &verification_ref),
34 ] {
35 if public_ref(receipt, field).as_ref() != Some(expected) {
36 return None;
37 }
38 }
39 let authority_receipt_ref = public_ref(receipt, "authorityReceiptRef")?;
40 let decision_ref = public_ref(receipt, "decisionRef")?;
41 let authority_allowed = receipt.get("allowed").and_then(Value::as_bool)?;
42
43 Some(Self {
44 fields: vec![
45 InspectorField::new("objective_ref", objective_ref.as_str()),
46 InspectorField::new("turn_ref", turn_ref.as_str()),
47 InspectorField::new("change_ref", change_ref.as_str()),
48 InspectorField::new("project_generation", project_generation.as_str()),
49 InspectorField::new("diff", diff_summary),
50 InspectorField::new("test_command", test_command),
51 InspectorField::new("test_outcome", test_outcome.as_str()),
52 InspectorField::new("verification_ref", verification_ref.as_str()),
53 InspectorField::new("host_executed", "true"),
54 InspectorField::new("authority_receipt_ref", authority_receipt_ref.as_str()),
55 InspectorField::new("decision_ref", decision_ref.as_str()),
56 InspectorField::new(
57 "authority_allowed",
58 if authority_allowed { "true" } else { "false" },
59 ),
60 ],
61 })
62 }
63}
64
65fn public_ref(value: &Value, field: &str) -> Option<PublicRef> {
66 PublicRef::new(value.get(field)?.as_str()?)
67}
68
69fn bounded_public_command(value: &str) -> Option<String> {
70 bounded_text(value, 256)
71}
72
73fn bounded_public_text(value: &str) -> Option<String> {
74 bounded_text(value, 512)
75}
76
77fn bounded_text(value: &str, maximum_length: usize) -> Option<String> {
78 let value = value.trim();
79 let lower = value.to_ascii_lowercase();
80 if value.is_empty()
81 || value.len() > maximum_length
82 || value.contains('\0')
83 || value.contains("/Users/")
84 || value.contains("/home/")
85 || lower.contains("bearer ")
86 || lower.contains("auth.json")
87 || lower.contains("access_token")
88 || lower.contains("refresh_token")
89 || lower.contains("private_key")
90 {
91 return None;
92 }
93 Some(value.to_string())
94}
95
96#[cfg(test)]
97mod tests {
98 use super::*;
99 use serde_json::json;
100
101 fn records() -> (Value, Value) {
102 (
103 json!({
104 "runRef":"run.fa.1",
105 "evidence":{
106 "objectiveRef":"objective.fa.1",
107 "turnRef":"turn.fa.4",
108 "changeRef":"change.fa.4",
109 "projectGeneration":"project.generation.7",
110 "diffSummary":"2 files changed, 18 insertions, 3 deletions",
111 "testCommand":"cargo test -p full_auto_ui",
112 "testOutcome":"passed",
113 "verificationRef":"verification.host.fa.4",
114 "hostExecuted":true
115 }
116 }),
117 json!({
118 "runRef":"run.fa.1",
119 "objectiveRef":"objective.fa.1",
120 "turnRef":"turn.fa.4",
121 "changeRef":"change.fa.4",
122 "verificationRef":"verification.host.fa.4",
123 "authorityReceiptRef":"receipt.authority.fa.4",
124 "decisionRef":"decision.authority.fa.4",
125 "allowed":true
126 }),
127 )
128 }
129
130 #[test]
131 fn renders_one_linked_object_in_inspector_grammar() {
132 let (report, receipt) = records();
133 let view = FullAutoEvidenceView::from_records(&report, &receipt).unwrap();
134 let labels: Vec<_> = view.fields.iter().map(|field| field.label).collect();
135 assert_eq!(
136 labels,
137 [
138 "objective_ref",
139 "turn_ref",
140 "change_ref",
141 "project_generation",
142 "diff",
143 "test_command",
144 "test_outcome",
145 "verification_ref",
146 "host_executed",
147 "authority_receipt_ref",
148 "decision_ref",
149 "authority_allowed"
150 ]
151 );
152 }
153
154 #[test]
155 fn mismatched_hops_or_self_reported_verification_fail_closed() {
156 let (report, mut receipt) = records();
157 receipt["changeRef"] = json!("change.other");
158 assert!(FullAutoEvidenceView::from_records(&report, &receipt).is_none());
159
160 let (mut report, receipt) = records();
161 report["evidence"]["hostExecuted"] = json!(false);
162 assert!(FullAutoEvidenceView::from_records(&report, &receipt).is_none());
163 }
164
165 #[test]
166 fn secret_or_private_material_never_reaches_the_view() {
167 let (mut report, receipt) = records();
168 report["evidence"]["testCommand"] = json!("cat /Users/owner/.codex/auth.json");
169 assert!(FullAutoEvidenceView::from_records(&report, &receipt).is_none());
170 }
171}
172