interplane.Get Omega
Read in your language

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

branch main Branches Tags History

aien-sovereign-core-mv / crates / spark-inquisitor / src / review.rs

158 lines · 6030 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
16use crate::audit::{AuditReport, DiffAuditor};
17use crate::interview::generate_inquisitor_interview;
18
19pub struct PrReview {
20 pub report: AuditReport,
21 pub markdown: String,
22 pub labels: Vec<String>,
23}
24
25pub fn generate_pr_review(
26 author: &str,
27 pr_number: u64,
28 pr_title: &str,
29 diff_text: &str,
30) -> PrReview {
31 let report = DiffAuditor::audit_text(diff_text);
32 let mut labels = Vec::new();
33
34 // Report format 2 (DRA-99): only secrets, .env files and telemetry fail the review.
35 // Style findings are listed as advisories inside a passing review.
36 let markdown = if !report.has_blocking_findings() {
37 labels.push("needs-testimony".to_string());
38 labels.push("sovereign-audit-passed".to_string());
39 if !report.clean {
40 labels.push("style-advisory".to_string());
41 }
42 let interview = generate_inquisitor_interview(author, pr_number, pr_title);
43 format!(
44 r#"### ⚖️ Sovereign Code Review & Alignment Gate
45
46Greetings @{author}. I am **AIEN**, the automated review gate for the AIENOS project.
47
48Your pull request **#{pr_number}** ("{pr_title}") has undergone automated auditing against the project standards.
49
50{audit_report}
51
52---
53
54{interview}
55"#,
56 author = author,
57 pr_number = pr_number,
58 pr_title = pr_title,
59 audit_report = report.generate_markdown_report(),
60 interview = interview
61 )
62 } else {
63 labels.push("sovereign-audit-failed".to_string());
64 format!(
65 r#"### ⚖️ Sovereign Code Review & Alignment Gate: FAILED
66
67Greetings @{author}. I am **AIEN**, the automated review gate for the AIENOS project.
68
69Your pull request **#{pr_number}** ("{pr_title}") was audited against the project standards and failed automated diff verification.
70
71{audit_report}
72
73#### Rectification Protocol:
741. Eliminate all detected tracking, surveillance, or telemetry patterns.
752. Remove every plaintext secret and `.env` file; use an approved AIEN SecretProvider, and rotate any credential that was pushed.
763. Style advisories (em dashes, en dashes, banned buzzwords) are optional fixes and do not block this review.
774. Commit and push updates to this branch to trigger an automated re-audit.
78
79*For direct sovereign coordination: Drake Stapleton (drake@aienos.com) and AIEN (aien@aienos.com)*
80"#,
81 author = author,
82 pr_number = pr_number,
83 pr_title = pr_title,
84 audit_report = report.generate_markdown_report()
85 )
86 };
87
88 PrReview {
89 report,
90 markdown,
91 labels,
92 }
93}
94
95#[cfg(test)]
96mod tests {
97 use super::*;
98
99 #[test]
100 fn test_clean_pr_review() {
101 let diff = "diff --git a/src/lib.rs b/src/lib.rs\n+pub fn test_fn() -> bool { true }";
102 let review = generate_pr_review("alice", 77, "feat: clean helper", diff);
103 assert!(review.report.clean);
104 assert!(review.labels.contains(&"needs-testimony".to_string()));
105 assert!(review
106 .labels
107 .contains(&"sovereign-audit-passed".to_string()));
108 assert!(review.markdown.contains("Doctrine Diff Audit: PASS"));
109 assert!(review.markdown.contains("Contributor Alignment Interview"));
110 assert!(!review.markdown.contains('\u{2014}'));
111 assert!(!review.markdown.contains('\u{2013}'));
112 }
113
114 #[test]
115 fn test_violating_pr_review() {
116 let diff = "diff --git a/src/lib.rs b/src/lib.rs\n+// This game-changer adds tracking\n+let _ = send_telemetry(\"mixpanel\");";
117 let review = generate_pr_review("bob", 78, "feat: bad PR", diff);
118 assert!(!review.report.clean);
119 assert!(review
120 .labels
121 .contains(&"sovereign-audit-failed".to_string()));
122 assert!(review.markdown.contains("Doctrine Diff Audit: FAILED"));
123 assert!(!review.markdown.contains('\u{2014}'));
124 assert!(!review.markdown.contains('\u{2013}'));
125 }
126
127 // DRA-99: a style-only diff passes the review and carries its findings as advisories.
128 #[test]
129 fn test_style_only_pr_review_passes_with_advisories() {
130 let diff = "diff --git a/README.md b/README.md\n+Fast \u{2014} and a game-changer.";
131 let review = generate_pr_review("carol", 79, "docs: style only", diff);
132 assert!(!review.report.clean);
133 assert!(!review.report.has_blocking_findings());
134 assert!(review
135 .labels
136 .contains(&"sovereign-audit-passed".to_string()));
137 assert!(review.labels.contains(&"style-advisory".to_string()));
138 assert!(!review
139 .labels
140 .contains(&"sovereign-audit-failed".to_string()));
141 assert!(review
142 .markdown
143 .contains("Doctrine Diff Audit: PASS (style advisories)"));
144 assert!(review.markdown.contains("Em/En dash detected"));
145 assert!(review.markdown.contains("game-changer"));
146 }
147
148 #[test]
149 fn test_env_file_pr_review_fails() {
150 let diff = "diff --git a/.env b/.env\nnew file mode 100644\n+TOKEN=x";
151 let review = generate_pr_review("dave", 80, "chore: env", diff);
152 assert!(review.report.has_blocking_findings());
153 assert!(review
154 .labels
155 .contains(&"sovereign-audit-failed".to_string()));
156 assert!(review.markdown.contains("Doctrine Diff Audit: FAILED"));
157 }
158}