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

363 lines · 14118 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 CLI Entrypoint
17// Sovereign Defensive Boundary and Containment Engine
18
19use anyhow::Result;
20use clap::{Parser, Subcommand};
21use serde_json::json;
22use spark_aegis::{
23 audit, containment,
24 doctrine::{all_invariants, DOCTRINE_STATEMENT},
25 pr_triage, scanner,
26};
27use std::path::{Path, PathBuf};
28
29#[derive(Parser)]
30#[command(
31 name = "spark-aegis",
32 about = "Sovereign defensive boundary and containment engine",
33 version = "0.1.0"
34)]
35struct Cli {
36 #[command(subcommand)]
37 command: Commands,
38}
39
40#[derive(Subcommand)]
41enum Commands {
42 /// Deep scan a file or directory for secrets, slop, and dangerous commands
43 Scan {
44 /// Target file or directory path
45 path: PathBuf,
46 },
47 /// Autonomous PR review and diff triage
48 ReviewPr {
49 /// Path to diff file (or - for stdin)
50 diff_file: PathBuf,
51 },
52 /// Live system and workspace confinement audit
53 Audit,
54 /// Execute defensive containment actions on session, process, or path
55 Contain {
56 /// Target identifier (process ID, session ID, or filesystem path)
57 target: String,
58 /// Explicitly treat target as a process ID to isolate
59 #[arg(long)]
60 pid: Option<u32>,
61 /// Explicitly treat target as a session ID to cut
62 #[arg(long)]
63 session: Option<String>,
64 /// Explicitly treat target as a filesystem path to close and quarantine
65 #[arg(long)]
66 close: Option<PathBuf>,
67 },
68 /// Display sovereign doctrine and invariant definitions
69 Doctrine,
70}
71
72#[tokio::main]
73async fn main() -> Result<()> {
74 let cli = Cli::parse();
75
76 match cli.command {
77 Commands::Scan { path } => {
78 println!("SPARK-AEGIS DEEP SCAN");
79 println!("Target: {}", path.display());
80 println!("------------------------------------------------------------");
81
82 let report = scanner::scan_path(&path)?;
83 println!("Files scanned: {}", report.scanned_files_count);
84 println!("Duration: {:.2} ms", report.elapsed_ms);
85 println!("Blake3 hash: {}", report.blake3_hash);
86 println!(
87 "Status: {}",
88 if report.passed {
89 "CLEAN"
90 } else {
91 "VIOLATIONS_FOUND"
92 }
93 );
94
95 if !report.violations.is_empty() {
96 println!("\nVIOLATION REPORT ({} items):", report.violations.len());
97 for (idx, v) in report.violations.iter().enumerate() {
98 println!("\n[{}] {:?} ({:?})", idx + 1, v.rule, v.severity);
99 println!(" Path: {}", v.file_path.display());
100 if let Some(line) = v.line_number {
101 println!(" Line: {}", line);
102 }
103 println!(" Match: {}", v.matched_text);
104 println!(" Remediation: {}", v.remediation);
105 }
106 std::process::exit(1);
107 } else {
108 println!("\nZero violations detected. Target conforms to sovereign invariants.");
109 }
110 }
111
112 Commands::ReviewPr { diff_file } => {
113 println!("SPARK-AEGIS AUTONOMOUS PR TRIAGE");
114 println!("------------------------------------------------------------");
115
116 let content = if diff_file == Path::new("-") {
117 use std::io::Read;
118 let mut buffer = String::new();
119 std::io::stdin().read_to_string(&mut buffer)?;
120 buffer
121 } else {
122 std::fs::read_to_string(&diff_file)?
123 };
124
125 let pr_name = diff_file.display().to_string();
126 let verdict = pr_triage::review_pr_diff(&content, &pr_name)?;
127
128 println!("PR Identifier: {}", verdict.pr_id);
129 println!("Blake3 Proof: {}", verdict.blake3_proof);
130 println!("Status: {:?}", verdict.status);
131 println!(
132 "Zero Disk Secrets: {}",
133 if verdict.zero_disk_secrets_certified {
134 "CERTIFIED"
135 } else {
136 "FAILED"
137 }
138 );
139 println!(
140 "Unslop Compliance: {}",
141 if verdict.unslop_certified {
142 "CERTIFIED"
143 } else {
144 "FAILED"
145 }
146 );
147 println!(
148 "Safe Execution: {}",
149 if verdict.safe_execution_certified {
150 "CERTIFIED"
151 } else {
152 "FAILED"
153 }
154 );
155 println!("Summary: {}", verdict.summary);
156
157 if !verdict.violations.is_empty() {
158 println!("\nViolations List:");
159 for (i, v) in verdict.violations.iter().enumerate() {
160 println!(
161 " {}. [{:?}] {} at line {:?}",
162 i + 1,
163 v.category,
164 v.rule,
165 v.line_number
166 );
167 println!(" Remediation: {}", v.remediation);
168 }
169 std::process::exit(1);
170 }
171 }
172
173 Commands::Audit => {
174 println!("SPARK-AEGIS LIVE HOST & WORKSPACE CONFINEMENT AUDIT");
175 println!("------------------------------------------------------------");
176
177 let report = audit::audit_system().await?;
178 println!("Timestamp: {}", report.timestamp.to_rfc3339());
179 println!("Blake3 Audit Digest: {}", report.blake3_digest);
180 println!(
181 "Cortex Memory Service: {}",
182 if report.cortex_online {
183 "ONLINE"
184 } else {
185 "OFFLINE"
186 }
187 );
188 if let Some(v) = report.cortex_version {
189 println!("Cortex Engine Version: {}", v);
190 }
191 println!(
192 "Workspace Path: {}",
193 report.workspace.path.display()
194 );
195 println!(
196 "Workspace Status: {}",
197 if report.workspace.secure_tpm_only {
198 "SECURE_TPM_ONLY (PASS)"
199 } else {
200 "FAILED (INSECURE)"
201 }
202 );
203
204 if !report.workspace.dot_env_found.is_empty() {
205 println!("\nWARNING: Unencrypted .env files detected:");
206 for p in &report.workspace.dot_env_found {
207 println!(" - {}", p.display());
208 }
209 }
210
211 println!("\nListening Sockets Count: {}", report.sockets.len());
212 println!(
213 "Non-Loopback Sockets: {}",
214 report.non_loopback_sockets_count
215 );
216 for s in report.sockets.iter().take(10) {
217 let exposure = if s.is_loopback {
218 "LOOPBACK"
219 } else {
220 "EXPOSED_LAN/WAN"
221 };
222 println!(
223 " {} {:<25} [{}] proc: {:?}",
224 s.protocol, s.local_address, exposure, s.process_name
225 );
226 }
227
228 println!(
229 "\nOverall Confinement: {}",
230 if report.overall_safe {
231 "PASS"
232 } else {
233 "REJECT"
234 }
235 );
236 }
237
238 Commands::Contain {
239 target,
240 pid,
241 session,
242 close,
243 } => {
244 println!("SPARK-AEGIS CONTAINMENT DISPATCH");
245 println!("Doctrine: {}", DOCTRINE_STATEMENT);
246 println!("------------------------------------------------------------");
247
248 if let Some(target_pid) = pid {
249 let receipt = containment::isolate_host(target_pid)?;
250 println!("Action: {}", receipt.action);
251 println!("Target: PID {}", receipt.target);
252 println!("Status: {}", receipt.status);
253 println!("Details: {}", receipt.details);
254 println!("Blake3: {}", receipt.blake3_digest);
255
256 let incident = containment::IncidentReport::new(
257 "manual_pid_containment",
258 "HIGH",
259 json!({"pid": target_pid, "receipt": receipt}),
260 );
261 let audit_receipt = containment::keep_evidence(&incident).await?;
262 println!("Evidence: Cortex recorded: {}", audit_receipt.recorded);
263 return Ok(());
264 }
265
266 if let Some(sess_id) = session {
267 let receipt = containment::cut_session(&sess_id)?;
268 println!("Action: {}", receipt.action);
269 println!("Target: Session {}", receipt.target);
270 println!("Status: {}", receipt.status);
271 println!("Details: {}", receipt.details);
272 println!("Blake3: {}", receipt.blake3_digest);
273
274 let incident = containment::IncidentReport::new(
275 "manual_session_containment",
276 "HIGH",
277 json!({"session": sess_id, "receipt": receipt}),
278 );
279 let audit_receipt = containment::keep_evidence(&incident).await?;
280 println!("Evidence: Cortex recorded: {}", audit_receipt.recorded);
281 return Ok(());
282 }
283
284 if let Some(close_path) = close {
285 let receipt = containment::close_door(&close_path)?;
286 println!("Action: {}", receipt.action);
287 println!("Target: Path {}", receipt.target);
288 println!("Status: {}", receipt.status);
289 println!("Details: {}", receipt.details);
290 println!("Blake3: {}", receipt.blake3_digest);
291
292 let incident = containment::IncidentReport::new(
293 "manual_path_containment",
294 "HIGH",
295 json!({"path": close_path, "receipt": receipt}),
296 );
297 let audit_receipt = containment::keep_evidence(&incident).await?;
298 println!("Evidence: Cortex recorded: {}", audit_receipt.recorded);
299 return Ok(());
300 }
301
302 // Automatic target deduction: numeric PID, path, or session string
303 if let Ok(parsed_pid) = target.parse::<u32>() {
304 println!("Auto-detected numeric PID target: {}", parsed_pid);
305 let receipt = containment::isolate_host(parsed_pid)?;
306 println!("Status: {}", receipt.status);
307 println!("Details: {}", receipt.details);
308 println!("Blake3: {}", receipt.blake3_digest);
309
310 let incident = containment::IncidentReport::new(
311 "auto_pid_containment",
312 "HIGH",
313 json!({"pid": parsed_pid, "receipt": receipt}),
314 );
315 let audit_receipt = containment::keep_evidence(&incident).await?;
316 println!("Evidence: Cortex recorded: {}", audit_receipt.recorded);
317 } else if Path::new(&target).exists() {
318 println!("Auto-detected filesystem target: {}", target);
319 let receipt = containment::close_door(Path::new(&target))?;
320 println!("Status: {}", receipt.status);
321 println!("Details: {}", receipt.details);
322 println!("Blake3: {}", receipt.blake3_digest);
323
324 let incident = containment::IncidentReport::new(
325 "auto_path_containment",
326 "HIGH",
327 json!({"path": target, "receipt": receipt}),
328 );
329 let audit_receipt = containment::keep_evidence(&incident).await?;
330 println!("Evidence: Cortex recorded: {}", audit_receipt.recorded);
331 } else {
332 println!(
333 "Auto-detected interactive/socket session target: {}",
334 target
335 );
336 let receipt = containment::cut_session(&target)?;
337 println!("Status: {}", receipt.status);
338 println!("Details: {}", receipt.details);
339 println!("Blake3: {}", receipt.blake3_digest);
340
341 let incident = containment::IncidentReport::new(
342 "auto_session_containment",
343 "HIGH",
344 json!({"session": target, "receipt": receipt}),
345 );
346 let audit_receipt = containment::keep_evidence(&incident).await?;
347 println!("Evidence: Cortex recorded: {}", audit_receipt.recorded);
348 }
349 }
350
351 Commands::Doctrine => {
352 println!("SPARK-AEGIS SOVEREIGN DEFENSIVE DOCTRINE");
353 println!("============================================================");
354 println!("Doctrine: \"{}\"\n", DOCTRINE_STATEMENT);
355 println!("Invariants:");
356 for inv in all_invariants() {
357 println!("- [{}] {}", inv.code(), inv.description());
358 }
359 }
360 }
361
362 Ok(())
363}