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
aien-sovereign-core-mv / crates / spark-debugger / src / main.rs
| 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 | use aien_localhttp::Client; |
| 17 | use clap::{Parser, Subcommand}; |
| 18 | use std::time::Duration; |
| 19 | use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; |
| 20 | |
| 21 | mod audit; |
| 22 | mod daemon; |
| 23 | mod mcp; |
| 24 | mod reporter; |
| 25 | |
| 26 | use audit::run_full_audit; |
| 27 | use daemon::run_watchdog_daemon; |
| 28 | use mcp::run_mcp_server; |
| 29 | |
| 30 | #[derive(Parser, Debug)] |
| 31 | #[command( |
| 32 | name = "spark-debugger", |
| 33 | about = "Autonomous Continuous Watchdog and MCP Debugger for SparkOS" |
| 34 | )] |
| 35 | struct Cli { |
| 36 | #[arg(long, default_value_t = default_debugger_workspace())] |
| 37 | workspace: String, |
| 38 | |
| 39 | #[arg(long)] |
| 40 | daemon: bool, |
| 41 | |
| 42 | #[arg(long)] |
| 43 | mcp: bool, |
| 44 | |
| 45 | #[arg(long, default_value_t = 30)] |
| 46 | interval: u64, |
| 47 | |
| 48 | #[command(subcommand)] |
| 49 | command: Option<Commands>, |
| 50 | } |
| 51 | |
| 52 | #[derive(Subcommand, Debug)] |
| 53 | enum Commands { |
| 54 | Check, |
| 55 | Daemon, |
| 56 | Mcp, |
| 57 | } |
| 58 | |
| 59 | fn default_debugger_workspace() -> String { |
| 60 | let home = std::env::var("HOME") |
| 61 | .or_else(|_| std::env::var("USERPROFILE")) |
| 62 | .unwrap_or_else(|_| ".".to_string()); |
| 63 | format!("{}/workspace/aien-sovereign-core", home) |
| 64 | } |
| 65 | |
| 66 | #[tokio::main] |
| 67 | async fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 68 | let cli = Cli::parse(); |
| 69 | |
| 70 | // aien-localhttp always sets TCP_NODELAY, so the old tcp_nodelay(true) is kept. |
| 71 | let client = Client::builder().timeout(Duration::from_secs(5)).build(); |
| 72 | |
| 73 | if cli.mcp || matches!(cli.command, Some(Commands::Mcp)) { |
| 74 | // Run MCP server over stdio without standard logging interfering with stdout |
| 75 | tracing_subscriber::registry() |
| 76 | .with(tracing_subscriber::fmt::layer().with_writer(std::io::stderr)) |
| 77 | .init(); |
| 78 | return run_mcp_server(client, cli.workspace).await; |
| 79 | } |
| 80 | |
| 81 | tracing_subscriber::registry() |
| 82 | .with( |
| 83 | tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into()), |
| 84 | ) |
| 85 | .with(tracing_subscriber::fmt::layer()) |
| 86 | .init(); |
| 87 | |
| 88 | if cli.daemon || matches!(cli.command, Some(Commands::Daemon)) { |
| 89 | return run_watchdog_daemon(client, cli.workspace, cli.interval).await; |
| 90 | } |
| 91 | |
| 92 | // Default: one-shot check |
| 93 | println!(); |
| 94 | println!("=== SparkOS Sovereign Watchdog: System Diagnostic Audit ==="); |
| 95 | let report = run_full_audit(&client, &cli.workspace).await; |
| 96 | |
| 97 | println!( |
| 98 | "{:<22} {:<38} {:<10} {:<10}", |
| 99 | "SERVICE", "ENDPOINT", "STATUS", "LATENCY" |
| 100 | ); |
| 101 | println!("{}", "-".repeat(82)); |
| 102 | for s in &report.services { |
| 103 | let status_str = if s.reachable { "ONLINE" } else { "OFFLINE" }; |
| 104 | let code_str = s |
| 105 | .status_code |
| 106 | .map(|c| c.to_string()) |
| 107 | .unwrap_or_else(|| "-".into()); |
| 108 | println!( |
| 109 | "{:<22} {:<38} {:<10} {:<10}", |
| 110 | s.name, |
| 111 | s.endpoint, |
| 112 | format!("{} ({})", status_str, code_str), |
| 113 | format!("{}ms", s.latency_ms) |
| 114 | ); |
| 115 | } |
| 116 | println!("{}", "-".repeat(82)); |
| 117 | |
| 118 | println!( |
| 119 | " |
| 120 | --- Invariant Checks ---" |
| 121 | ); |
| 122 | println!( |
| 123 | "TPM Vault Clean (Zero .env files): {}", |
| 124 | if report.invariants.plaintext_env_files_found.is_empty() { |
| 125 | "PASSED" |
| 126 | } else { |
| 127 | "FAILED" |
| 128 | } |
| 129 | ); |
| 130 | if !report.invariants.plaintext_env_files_found.is_empty() { |
| 131 | for f in &report.invariants.plaintext_env_files_found { |
| 132 | println!(" Leaked file: {}", f); |
| 133 | } |
| 134 | } |
| 135 | println!( |
| 136 | "Unslop Standard (Zero em/en dashes): {}", |
| 137 | if report.invariants.unslop_violations.is_empty() { |
| 138 | "PASSED" |
| 139 | } else { |
| 140 | "FAILED" |
| 141 | } |
| 142 | ); |
| 143 | |
| 144 | println!( |
| 145 | " |
| 146 | --- Workspace Compile Check ---" |
| 147 | ); |
| 148 | println!( |
| 149 | "Cargo Check: {}", |
| 150 | if report.build.passed { |
| 151 | "PASSED" |
| 152 | } else { |
| 153 | "FAILED" |
| 154 | } |
| 155 | ); |
| 156 | if !report.build.errors.is_empty() { |
| 157 | for e in &report.build.errors { |
| 158 | println!(" {}", e); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | println!( |
| 163 | " |
| 164 | Overall Diagnostic Status: {}", |
| 165 | if report.overall_healthy { |
| 166 | "ALL SYSTEMS GREEN" |
| 167 | } else { |
| 168 | "ATTENTION REQUIRED" |
| 169 | } |
| 170 | ); |
| 171 | println!(); |
| 172 | |
| 173 | Ok(()) |
| 174 | } |