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/aien-sovereign-core-mv/blob/main/crates/spark-aegis/src/pr_triage.rs # aien-sovereign-core-mv AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination. 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 `aien-sovereign-core-mv / crates / spark-aegis / src / pr_triage.rs` 157 lines ยท 4920 bytes Raw Blame History 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 // spark-aegis PR Triage and Autonomous Review Engine 17 // Verifies git diffs against sovereign invariants and certifies PR safety 18 19 use crate::scanner::{self, Violation, ViolationCategory}; 20 use anyhow::Result; 21 use chrono::{DateTime, Utc}; 22 use serde::{Deserialize, Serialize}; 23 use std::fs; 24 use std::path::Path; 25 26 #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] 27 pub enum VerdictStatus { 28 PASS, 29 REJECT, 30 } 31 32 #[derive(Debug, Clone, Serialize, Deserialize)] 33 pub struct PrVerdict { 34 pub status: VerdictStatus, 35 pub pr_id: String, 36 pub blake3_proof: String, 37 pub zero_disk_secrets_certified: bool, 38 pub unslop_certified: bool, 39 pub safe_execution_certified: bool, 40 pub violations: Vec, 41 pub summary: String, 42 pub timestamp: DateTime, 43 } 44 45 impl PrVerdict { 46 pub fn is_pass(&self) -> bool { 47 self.status == VerdictStatus::PASS 48 } 49 } 50 51 pub fn review_pr_diff(diff_content: &str, pr_identifier: &str) -> Result { 52 let report = scanner::scan_diff(diff_content)?; 53 let ts = Utc::now(); 54 55 let mut secrets_clean = true; 56 let mut slop_clean = true; 57 let mut safe_clean = true; 58 59 for v in &report.violations { 60 match v.category { 61 ViolationCategory::PlaintextSecret | ViolationCategory::ProhibitedFile => { 62 secrets_clean = false; 63 } 64 ViolationCategory::AntiSlop => { 65 slop_clean = false; 66 } 67 ViolationCategory::DangerousCommand => { 68 safe_clean = false; 69 } 70 } 71 } 72 73 let passed = secrets_clean && slop_clean && safe_clean; 74 let status = if passed { 75 VerdictStatus::PASS 76 } else { 77 VerdictStatus::REJECT 78 }; 79 80 let summary = if passed { 81 format!( 82 "PR {} certified safe. Zero disk secrets, unslop compliant, safe execution verified.", 83 pr_identifier 84 ) 85 } else { 86 format!( 87 "PR {} REJECTED with {} sovereign violation(s). Remediation required before merge.", 88 pr_identifier, 89 report.violations.len() 90 ) 91 }; 92 93 Ok(PrVerdict { 94 status, 95 pr_id: pr_identifier.to_string(), 96 blake3_proof: report.blake3_hash, 97 zero_disk_secrets_certified: secrets_clean, 98 unslop_certified: slop_clean, 99 safe_execution_certified: safe_clean, 100 violations: report.violations, 101 summary, 102 timestamp: ts, 103 }) 104 } 105 106 pub fn review_pr_file>(file_path: P) -> Result { 107 let path = file_path.as_ref(); 108 let content = fs::read_to_string(path)?; 109 let identifier = path 110 .file_stem() 111 .and_then(|s| s.to_str()) 112 .unwrap_or("pr-diff"); 113 review_pr_diff(&content, identifier) 114 } 115 116 #[cfg(test)] 117 mod tests { 118 use super::*; 119 120 #[test] 121 fn test_clean_pr_diff_passes() { 122 let clean_diff = r#" 123 diff --git a/crates/spark-test/src/lib.rs b/crates/spark-test/src/lib.rs 124 index `1111111`..`2222222` 100644 125 --- a/crates/spark-test/src/lib.rs 126 +++ b/crates/spark-test/src/lib.rs 127 @@ -1,3 +1,4 @@ 128 pub fn compute(x: i32) -> i32 { 129 + x * 2 130 } 131 "#; 132 let verdict = review_pr_diff(clean_diff, "PR-101").unwrap(); 133 assert_eq!(verdict.status, VerdictStatus::PASS); 134 assert!(verdict.zero_disk_secrets_certified); 135 assert!(verdict.unslop_certified); 136 assert!(verdict.safe_execution_certified); 137 assert!(verdict.violations.is_empty()); 138 } 139 140 #[test] 141 fn test_slop_pr_diff_rejects() { 142 let bad_diff = 143 "+++ b/README.md\n+This tool elevates developer productivity \u{2014} guaranteed.\n"; 144 let verdict = review_pr_diff(bad_diff, "PR-102").unwrap(); 145 assert_eq!(verdict.status, VerdictStatus::REJECT); 146 assert!(!verdict.unslop_certified); 147 assert_eq!(verdict.violations.len(), 2); // "elevates" and em dash 148 } 149 150 #[test] 151 fn test_secret_pr_diff_rejects() { 152 let secret_diff = "+++ b/config.rs\n+const GITHUB_TOKEN: &str = \"ghp_`123456789012345678901234567890123456`\";\n"; 153 let verdict = review_pr_diff(secret_diff, "PR-103").unwrap(); 154 assert_eq!(verdict.status, VerdictStatus::REJECT); 155 assert!(!verdict.zero_disk_secrets_certified); 156 } 157 }