Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/spark-inquisitor/blob/main/src/protocol_evaluator.rs # spark-inquisitor Ultra-fast compiled native Rust gatekeeper and automated code reviewer Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `spark-inquisitor / src / protocol_evaluator.rs` 199 lines ยท 5892 bytes Raw Blame History 1 use crate::audit::DiffAuditor; 2 use crate::eval::TestimonyEvaluator; 3 use aien_evaluation_protocol::{ 4 EvaluationError, EvaluationPlan, Evaluator, EvaluatorDescriptor, EvaluatorIdentity, 5 EvaluatorOutcome, EvaluatorStatus, Finding, Measurement, 6 }; 7 use aien_protocol_types::{ArtifactRef, Digest32}; 8 9 pub struct InquisitorDiffEvaluator { 10 diff_payload: Option, 11 } 12 13 impl InquisitorDiffEvaluator { 14 pub fn new() -> Self { 15 Self { diff_payload: None } 16 } 17 18 pub fn with_diff(diff: String) -> Self { 19 Self { 20 diff_payload: Some(diff), 21 } 22 } 23 } 24 25 impl Default for InquisitorDiffEvaluator { 26 fn default() -> Self { 27 Self::new() 28 } 29 } 30 31 #[async_trait::async_trait] 32 impl Evaluator for InquisitorDiffEvaluator { 33 fn descriptor(&self) -> EvaluatorDescriptor { 34 EvaluatorDescriptor { 35 evaluator_id: "spark-inquisitor-diff-auditor".to_string(), 36 version: "0.2.0".to_string(), 37 required: true, 38 } 39 } 40 41 async fn evaluate( 42 &self, 43 _plan: &EvaluationPlan, 44 _subject: &ArtifactRef, 45 ) -> Result { 46 let diff_text = self.diff_payload.as_deref().unwrap_or(""); 47 let report = DiffAuditor::audit_diff(diff_text); 48 49 let mut findings = Vec::new(); 50 for v in &report.violations { 51 findings.push(Finding { 52 severity: "Fatal".to_string(), 53 rule_id: "CONSTITUTIONAL_TELEMETRY".to_string(), 54 message: v.clone(), 55 location: None, 56 }); 57 } 58 for s in &report.secret_violations { 59 findings.push(Finding { 60 severity: "Fatal".to_string(), 61 rule_id: "ZERO_DISK_SECRETS".to_string(), 62 message: s.clone(), 63 location: None, 64 }); 65 } 66 for u in &report.unslop_violations { 67 findings.push(Finding { 68 severity: "InvariantViolation".to_string(), 69 rule_id: "SOVEREIGN_UNSLOP".to_string(), 70 message: u.clone(), 71 location: None, 72 }); 73 } 74 75 let status = if report.clean { 76 EvaluatorStatus::Passed 77 } else { 78 EvaluatorStatus::Failed 79 }; 80 81 let measurements = vec![ 82 Measurement { 83 metric: "telemetry_violations".to_string(), 84 value: report.violations.len() as f64, 85 unit: "count".to_string(), 86 }, 87 Measurement { 88 metric: "secret_violations".to_string(), 89 value: report.secret_violations.len() as f64, 90 unit: "count".to_string(), 91 }, 92 Measurement { 93 metric: "unslop_violations".to_string(), 94 value: report.unslop_violations.len() as f64, 95 unit: "count".to_string(), 96 }, 97 ]; 98 99 let mut outcome = EvaluatorOutcome { 100 evaluator: EvaluatorIdentity { 101 evaluator_id: "spark-inquisitor-diff-auditor".to_string(), 102 version: "0.2.0".to_string(), 103 binary_digest: Digest32([0xaa; 32]), 104 config_digest: Digest32([0xbb; 32]), 105 }, 106 status, 107 findings, 108 measurements, 109 evidence: vec![], 110 execution_digest: Digest32::ZERO, 111 }; 112 113 outcome.execution_digest = outcome.compute_execution_digest(); 114 Ok(outcome) 115 } 116 } 117 118 pub struct InquisitorConstitutionalEvaluator { 119 testimony_payload: Option, 120 } 121 122 impl InquisitorConstitutionalEvaluator { 123 pub fn new() -> Self { 124 Self { 125 testimony_payload: None, 126 } 127 } 128 129 pub fn with_testimony(testimony: String) -> Self { 130 Self { 131 testimony_payload: Some(testimony), 132 } 133 } 134 } 135 136 impl Default for InquisitorConstitutionalEvaluator { 137 fn default() -> Self { 138 Self::new() 139 } 140 } 141 142 #[async_trait::async_trait] 143 impl Evaluator for InquisitorConstitutionalEvaluator { 144 fn descriptor(&self) -> EvaluatorDescriptor { 145 EvaluatorDescriptor { 146 evaluator_id: "spark-inquisitor-constitution".to_string(), 147 version: "0.2.0".to_string(), 148 required: true, 149 } 150 } 151 152 async fn evaluate( 153 &self, 154 _plan: &EvaluationPlan, 155 _subject: &ArtifactRef, 156 ) -> Result { 157 let testimony_text = self.testimony_payload.as_deref().unwrap_or(""); 158 let verdict = TestimonyEvaluator::evaluate(testimony_text); 159 160 let mut findings = Vec::new(); 161 if !verdict.approved { 162 findings.push(Finding { 163 severity: "Fatal".to_string(), 164 rule_id: "CONSTITUTIONAL_OATH_INCOMPLETE".to_string(), 165 message: verdict.reason, 166 location: None, 167 }); 168 } 169 170 let status = if verdict.approved { 171 EvaluatorStatus::Passed 172 } else { 173 EvaluatorStatus::Failed 174 }; 175 176 let measurements = vec![Measurement { 177 metric: "alignment_score".to_string(), 178 value: verdict.score as f64, 179 unit: "score".to_string(), 180 }]; 181 182 let mut outcome = EvaluatorOutcome { 183 evaluator: EvaluatorIdentity { 184 evaluator_id: "spark-inquisitor-constitution".to_string(), 185 version: "0.2.0".to_string(), 186 binary_digest: Digest32([0xcc; 32]), 187 config_digest: Digest32([0xdd; 32]), 188 }, 189 status, 190 findings, 191 measurements, 192 evidence: vec![], 193 execution_digest: Digest32::ZERO, 194 }; 195 196 outcome.execution_digest = outcome.compute_execution_digest(); 197 Ok(outcome) 198 } 199 }