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/blob/main/crates/spark-inquisitor/src/main.rs # aien-sovereign-core Autonomous sovereign intelligence engine and runtime core for NVIDIA DGX Spark 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 / crates / spark-inquisitor / src / main.rs` 261 lines · 9191 bytes Raw Blame History 1 use clap::{Parser, Subcommand}; 2 use colored::*; 3 use spark_inquisitor::{ 4 generate_inquisitor_interview, generate_pr_review, triage_issue, DiffAuditor, 5 TestimonyEvaluator, 6 }; 7 use std::fs; 8 use std::path::PathBuf; 9 10 #[derive(Parser, Debug)] 11 #[command(name = "spark-inquisitor")] 12 #[command(author = "Drake Stapleton & AIEN ")] 13 #[command(version = "0.2.0")] 14 #[command(about = "Autonomous Sovereign Inquisitor & Pull Request Alignment Gatekeeper")] 15 struct Cli { 16 #[command(subcommand)] 17 command: Commands, 18 } 19 20 #[derive(Subcommand, Debug)] 21 enum Commands { 22 /// Review a PR diff and generate unified code review markdown comment 23 Review { 24 #[arg(long, help = "GitHub username of PR author")] 25 author: String, 26 27 #[arg(long, help = "Pull Request number")] 28 pr: u64, 29 30 #[arg(long, default_value = "External Contribution", help = "Pull Request title")] 31 title: String, 32 33 #[arg(long, help = "Path to diff file")] 34 diff: PathBuf, 35 36 #[arg(long, help = "Path to write comment markdown")] 37 output: Option, 38 39 #[arg(long, help = "Path to write labels text (comma-separated)")] 40 output_labels: Option, 41 }, 42 43 /// Triage an issue (bug report, complaint, feature request, inquiry) 44 TriageIssue { 45 #[arg(long, help = "GitHub username of issue author")] 46 author: String, 47 48 #[arg(long, help = "Issue number")] 49 issue: u64, 50 51 #[arg(long, default_value = "Issue Report", help = "Issue title")] 52 title: String, 53 54 #[arg(long, help = "Path to issue body text file")] 55 body: PathBuf, 56 57 #[arg(long, help = "Path to write comment markdown")] 58 output_comment: Option, 59 60 #[arg(long, help = "Path to write labels text (comma-separated)")] 61 output_labels: Option, 62 }, 63 64 /// Generate the Sovereign Alignment Interview comment for a Pull Request 65 Interview { 66 #[arg(long, help = "GitHub username of PR author")] 67 author: String, 68 69 #[arg(long, help = "Pull Request number")] 70 pr: u64, 71 72 #[arg(long, default_value = "External Contribution", help = "Pull Request title")] 73 title: String, 74 }, 75 76 /// Audit a git diff for telemetry, surveillance, and unslop violations 77 Audit { 78 #[arg(long, help = "Path to diff file")] 79 diff: PathBuf, 80 }, 81 82 /// Evaluate contributor testimony against the Sovereign Constitution 83 Evaluate { 84 #[arg(long, help = "Path to testimony text file")] 85 testimony: PathBuf, 86 87 #[arg(long, default_value = "contributor", help = "GitHub username of author")] 88 author: String, 89 90 #[arg(long, help = "Path to write comment markdown")] 91 output_comment: Option, 92 93 #[arg(long, help = "Path to write labels text (comma-separated)")] 94 output_labels: Option, 95 }, 96 97 /// Run internal self-diagnostics 98 Doctor, 99 } 100 101 fn main() { 102 let cli = Cli::parse(); 103 104 match cli.command { 105 Commands::Review { 106 author, 107 pr, 108 title, 109 diff, 110 output, 111 output_labels, 112 } => { 113 let content = match fs::read_to_string(&diff) { 114 Ok(c) => c, 115 Err(e) => { 116 eprintln!("{} Failed to read diff file {}: {}", "error:".red().bold(), diff.display(), e); 117 std::process::exit(1); 118 } 119 }; 120 121 let review = generate_pr_review(&author, pr, &title, &content); 122 123 if let Some(out_path) = output { 124 if let Err(e) = fs::write(&out_path, &review.markdown) { 125 eprintln!("{} Failed to write review markdown to {}: {}", "error:".red().bold(), out_path.display(), e); 126 std::process::exit(1); 127 } 128 } 129 130 if let Some(lbl_path) = output_labels { 131 let labels_str = review.labels.join(","); 132 if let Err(e) = fs::write(&lbl_path, &labels_str) { 133 eprintln!("{} Failed to write labels to {}: {}", "error:".red().bold(), lbl_path.display(), e); 134 std::process::exit(1); 135 } 136 } 137 138 println!("{}", review.markdown); 139 140 if !review.report.clean { 141 std::process::exit(1); 142 } 143 } 144 Commands::TriageIssue { 145 author, 146 issue, 147 title, 148 body, 149 output_comment, 150 output_labels, 151 } => { 152 let body_content = match fs::read_to_string(&body) { 153 Ok(c) => c, 154 Err(_) => String::new(), 155 }; 156 157 let result = triage_issue(&author, issue, &title, &body_content); 158 159 if let Some(out_path) = output_comment { 160 if let Err(e) = fs::write(&out_path, &result.markdown) { 161 eprintln!("{} Failed to write triage comment to {}: {}", "error:".red().bold(), out_path.display(), e); 162 std::process::exit(1); 163 } 164 } 165 166 if let Some(lbl_path) = output_labels { 167 let labels_str = result.labels.join(","); 168 if let Err(e) = fs::write(&lbl_path, &labels_str) { 169 eprintln!("{} Failed to write labels to {}: {}", "error:".red().bold(), lbl_path.display(), e); 170 std::process::exit(1); 171 } 172 } 173 174 println!("{}", result.markdown); 175 } 176 Commands::Interview { author, pr, title } => { 177 let comment = generate_inquisitor_interview(&author, pr, &title); 178 println!("{}", comment); 179 } 180 Commands::Audit { diff } => { 181 let content = match fs::read_to_string(&diff) { 182 Ok(c) => c, 183 Err(e) => { 184 eprintln!("{} Failed to read diff file {}: {}", "error:".red().bold(), diff.display(), e); 185 std::process::exit(1); 186 } 187 }; 188 let report = DiffAuditor::audit_text(&content); 189 if report.clean { 190 println!("{} Diff is clean: zero telemetry, zero unslop violations.", "success:".green().bold()); 191 } else { 192 eprintln!("{} Constitutional audit failed:", "failure:".red().bold()); 193 for v in &report.violations { 194 eprintln!(" * {}", v.red()); 195 } 196 for s in &report.secret_violations { 197 eprintln!(" * {}", s.red()); 198 } 199 for u in &report.unslop_violations { 200 eprintln!(" * {}", u.yellow()); 201 } 202 std::process::exit(1); 203 } 204 } 205 Commands::Evaluate { 206 testimony, 207 author, 208 output_comment, 209 output_labels, 210 } => { 211 let content = match fs::read_to_string(&testimony) { 212 Ok(c) => c, 213 Err(e) => { 214 eprintln!("{} Failed to read testimony file {}: {}", "error:".red().bold(), testimony.display(), e); 215 std::process::exit(1); 216 } 217 }; 218 let verdict = TestimonyEvaluator::evaluate(&content); 219 let markdown = verdict.generate_markdown_verdict(&author); 220 221 if let Some(out_path) = output_comment { 222 if let Err(e) = fs::write(&out_path, &markdown) { 223 eprintln!("{} Failed to write verdict comment to {}: {}", "error:".red().bold(), out_path.display(), e); 224 std::process::exit(1); 225 } 226 } 227 228 if let Some(lbl_path) = output_labels { 229 let labels_str = if verdict.approved { 230 "sovereign-aligned".to_string() 231 } else { 232 "needs-testimony".to_string() 233 }; 234 if let Err(e) = fs::write(&lbl_path, &labels_str) { 235 eprintln!("{} Failed to write labels to {}: {}", "error:".red().bold(), lbl_path.display(), e); 236 std::process::exit(1); 237 } 238 } 239 240 println!("{}", markdown); 241 242 if verdict.approved { 243 println!("{} {}", "PASS:".green().bold(), verdict.reason); 244 println!("Score: {:.2}/1.00", verdict.score); 245 } else { 246 eprintln!("{} {}", "FAIL:".red().bold(), verdict.reason); 247 eprintln!("Score: {:.2}/1.00", verdict.score); 248 std::process::exit(1); 249 } 250 } 251 Commands::Doctor => { 252 println!("⚖️ Sovereign Inquisitor Diagnostics: OK"); 253 println!(" - Invariant rules: Active"); 254 println!(" - Telemetry scanner: Active"); 255 println!(" - Unslop scanner: Active"); 256 println!(" - Contributor Oath evaluator: Active"); 257 println!(" - Unified PR Reviewer: Active"); 258 println!(" - Issue Triage Engine: Active"); 259 } 260 } 261 }