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

410 lines · 13973 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 clap::{Parser, Subcommand};
17use colored::*;
18use spark_inquisitor::{
19 generate_inquisitor_interview, generate_pr_review, triage_issue, DiffAuditor,
20 TestimonyEvaluator, REPORT_FORMAT,
21};
22use std::fs;
23use std::path::PathBuf;
24
25#[derive(Parser, Debug)]
26#[command(name = "spark-inquisitor")]
27#[command(author = "Drake Stapleton <drake@aienos.com> & AIEN <aien@aienos.com>")]
28#[command(version = "0.2.0")]
29#[command(about = "Autonomous Sovereign Inquisitor & Pull Request Alignment Gatekeeper")]
30struct Cli {
31 #[command(subcommand)]
32 command: Commands,
33}
34
35#[derive(Subcommand, Debug)]
36enum Commands {
37 /// Review a PR diff and generate unified code review markdown comment
38 Review {
39 #[arg(long, help = "GitHub username of PR author")]
40 author: String,
41
42 #[arg(long, help = "Pull Request number")]
43 pr: u64,
44
45 #[arg(
46 long,
47 default_value = "External Contribution",
48 help = "Pull Request title"
49 )]
50 title: String,
51
52 #[arg(long, help = "Path to diff file")]
53 diff: PathBuf,
54
55 #[arg(long, help = "Path to write comment markdown")]
56 output: Option<PathBuf>,
57
58 #[arg(long, help = "Path to write labels text (comma-separated)")]
59 output_labels: Option<PathBuf>,
60 },
61
62 /// Triage an issue (bug report, complaint, feature request, inquiry)
63 TriageIssue {
64 #[arg(long, help = "GitHub username of issue author")]
65 author: String,
66
67 #[arg(long, help = "Issue number")]
68 issue: u64,
69
70 #[arg(long, default_value = "Issue Report", help = "Issue title")]
71 title: String,
72
73 #[arg(long, help = "Path to issue body text file")]
74 body: PathBuf,
75
76 #[arg(long, help = "Path to write comment markdown")]
77 output_comment: Option<PathBuf>,
78
79 #[arg(long, help = "Path to write labels text (comma-separated)")]
80 output_labels: Option<PathBuf>,
81 },
82
83 /// Generate the Sovereign Alignment Interview comment for a Pull Request
84 Interview {
85 #[arg(long, help = "GitHub username of PR author")]
86 author: String,
87
88 #[arg(long, help = "Pull Request number")]
89 pr: u64,
90
91 #[arg(
92 long,
93 default_value = "External Contribution",
94 help = "Pull Request title"
95 )]
96 title: String,
97 },
98
99 /// Audit a git diff for telemetry, surveillance, and unslop violations
100 Audit {
101 #[arg(long, help = "Path to diff file")]
102 diff: PathBuf,
103
104 #[arg(
105 long,
106 help = "Accepted for compatibility. Since report format 2 style findings are always advisory; only secrets, .env files and telemetry fail the audit"
107 )]
108 advisory_style: bool,
109 },
110
111 /// Automatically sanitize unslop formatting (em dashes, en dashes) in specified file
112 Fix {
113 #[arg(long, help = "Path to file to fix")]
114 file: PathBuf,
115 },
116
117 /// Evaluate contributor testimony against the project standards
118 Evaluate {
119 #[arg(long, help = "Path to testimony text file")]
120 testimony: PathBuf,
121
122 #[arg(
123 long,
124 default_value = "contributor",
125 help = "GitHub username of author"
126 )]
127 author: String,
128
129 #[arg(long, help = "Path to write comment markdown")]
130 output_comment: Option<PathBuf>,
131
132 #[arg(long, help = "Path to write labels text (comma-separated)")]
133 output_labels: Option<PathBuf>,
134 },
135
136 /// Run internal self-diagnostics
137 Doctor,
138}
139
140fn main() {
141 let cli = Cli::parse();
142
143 match cli.command {
144 Commands::Review {
145 author,
146 pr,
147 title,
148 diff,
149 output,
150 output_labels,
151 } => {
152 let content = match fs::read_to_string(&diff) {
153 Ok(c) => c,
154 Err(e) => {
155 eprintln!(
156 "{} Failed to read diff file {}: {}",
157 "error:".red().bold(),
158 diff.display(),
159 e
160 );
161 std::process::exit(1);
162 }
163 };
164
165 let review = generate_pr_review(&author, pr, &title, &content);
166
167 if let Some(out_path) = output {
168 if let Err(e) = fs::write(&out_path, &review.markdown) {
169 eprintln!(
170 "{} Failed to write review markdown to {}: {}",
171 "error:".red().bold(),
172 out_path.display(),
173 e
174 );
175 std::process::exit(1);
176 }
177 }
178
179 if let Some(lbl_path) = output_labels {
180 let labels_str = review.labels.join(",");
181 if let Err(e) = fs::write(&lbl_path, &labels_str) {
182 eprintln!(
183 "{} Failed to write labels to {}: {}",
184 "error:".red().bold(),
185 lbl_path.display(),
186 e
187 );
188 std::process::exit(1);
189 }
190 }
191
192 println!("{}", review.markdown);
193
194 // Report format 2 (DRA-99): exit 1 only for blocking findings (plaintext
195 // secrets, .env files, telemetry hooks). Style findings are advisory.
196 if review.report.has_blocking_findings() {
197 std::process::exit(1);
198 }
199 }
200 Commands::TriageIssue {
201 author,
202 issue,
203 title,
204 body,
205 output_comment,
206 output_labels,
207 } => {
208 let body_content = fs::read_to_string(&body).unwrap_or_default();
209
210 let result = triage_issue(&author, issue, &title, &body_content);
211
212 if let Some(out_path) = output_comment {
213 if let Err(e) = fs::write(&out_path, &result.markdown) {
214 eprintln!(
215 "{} Failed to write triage comment to {}: {}",
216 "error:".red().bold(),
217 out_path.display(),
218 e
219 );
220 std::process::exit(1);
221 }
222 }
223
224 if let Some(lbl_path) = output_labels {
225 let labels_str = result.labels.join(",");
226 if let Err(e) = fs::write(&lbl_path, &labels_str) {
227 eprintln!(
228 "{} Failed to write labels to {}: {}",
229 "error:".red().bold(),
230 lbl_path.display(),
231 e
232 );
233 std::process::exit(1);
234 }
235 }
236
237 println!("{}", result.markdown);
238 }
239 Commands::Interview { author, pr, title } => {
240 let comment = generate_inquisitor_interview(&author, pr, &title);
241 println!("{}", comment);
242 }
243 Commands::Audit {
244 diff,
245 advisory_style: _,
246 } => {
247 let content = match fs::read_to_string(&diff) {
248 Ok(c) => c,
249 Err(e) => {
250 eprintln!(
251 "{} Failed to read diff file {}: {}",
252 "error:".red().bold(),
253 diff.display(),
254 e
255 );
256 std::process::exit(1);
257 }
258 };
259 let report = DiffAuditor::audit_text(&content);
260
261 if report.clean {
262 println!(
263 "{} Diff is clean: zero telemetry, zero unslop violations.",
264 "success:".green().bold()
265 );
266 } else if !report.has_blocking_findings() {
267 println!(
268 "{} Diff passed critical security invariants.",
269 "success:".green().bold()
270 );
271 println!(
272 "{} Stylistic recommendations (non-blocking, {}):",
273 "advisory:".yellow().bold(),
274 REPORT_FORMAT
275 );
276 for u in &report.unslop_violations {
277 println!(" * {}", u.yellow());
278 }
279 } else {
280 eprintln!("{} Doctrine audit failed:", "failure:".red().bold());
281 for v in &report.violations {
282 eprintln!(" * {}", v.red());
283 }
284 for s in &report.secret_violations {
285 eprintln!(" * {}", s.red());
286 }
287 if !report.unslop_violations.is_empty() {
288 eprintln!(
289 "{} Stylistic recommendations (non-blocking, {}):",
290 "advisory:".yellow().bold(),
291 REPORT_FORMAT
292 );
293 for u in &report.unslop_violations {
294 eprintln!(" * {}", u.yellow());
295 }
296 }
297 std::process::exit(1);
298 }
299 }
300 Commands::Fix { file } => match fs::read_to_string(&file) {
301 Ok(content) => {
302 let fixed = content
303 .replace(" \u{2014} ", ": ")
304 .replace('\u{2014}', ", ")
305 .replace('\u{2013}', "-");
306 if fixed != content {
307 if let Err(e) = fs::write(&file, &fixed) {
308 eprintln!(
309 "{} Failed to write to {}: {}",
310 "error:".red().bold(),
311 file.display(),
312 e
313 );
314 std::process::exit(1);
315 }
316 println!(
317 "{} Sanitized em/en dashes in {}",
318 "success:".green().bold(),
319 file.display()
320 );
321 } else {
322 println!(
323 "{} File {} is already clean.",
324 "notice:".cyan().bold(),
325 file.display()
326 );
327 }
328 }
329 Err(e) => {
330 eprintln!(
331 "{} Failed to read file {}: {}",
332 "error:".red().bold(),
333 file.display(),
334 e
335 );
336 std::process::exit(1);
337 }
338 },
339 Commands::Evaluate {
340 testimony,
341 author,
342 output_comment,
343 output_labels,
344 } => {
345 let content = match fs::read_to_string(&testimony) {
346 Ok(c) => c,
347 Err(e) => {
348 eprintln!(
349 "{} Failed to read testimony file {}: {}",
350 "error:".red().bold(),
351 testimony.display(),
352 e
353 );
354 std::process::exit(1);
355 }
356 };
357 let verdict = TestimonyEvaluator::evaluate(&content);
358 let markdown = verdict.generate_markdown_verdict(&author);
359
360 if let Some(out_path) = output_comment {
361 if let Err(e) = fs::write(&out_path, &markdown) {
362 eprintln!(
363 "{} Failed to write verdict comment to {}: {}",
364 "error:".red().bold(),
365 out_path.display(),
366 e
367 );
368 std::process::exit(1);
369 }
370 }
371
372 if let Some(lbl_path) = output_labels {
373 let labels_str = if verdict.approved {
374 "sovereign-aligned".to_string()
375 } else {
376 "needs-testimony".to_string()
377 };
378 if let Err(e) = fs::write(&lbl_path, &labels_str) {
379 eprintln!(
380 "{} Failed to write labels to {}: {}",
381 "error:".red().bold(),
382 lbl_path.display(),
383 e
384 );
385 std::process::exit(1);
386 }
387 }
388
389 println!("{}", markdown);
390
391 if verdict.approved {
392 println!("{} {}", "PASS:".green().bold(), verdict.reason);
393 println!("Score: {:.2}/1.00", verdict.score);
394 } else {
395 eprintln!("{} {}", "FAIL:".red().bold(), verdict.reason);
396 eprintln!("Score: {:.2}/1.00", verdict.score);
397 std::process::exit(1);
398 }
399 }
400 Commands::Doctor => {
401 println!("⚖️ Sovereign Inquisitor Diagnostics: OK");
402 println!(" - Invariant rules: Active");
403 println!(" - Telemetry scanner: Active");
404 println!(" - Unslop scanner: Active");
405 println!(" - Contributor certification evaluator: Active");
406 println!(" - Unified PR Reviewer: Active");
407 println!(" - Issue Triage Engine: Active");
408 }
409 }
410}