interplane.Get Omega
Read in your language

spark-debugger

Native runtime state inspector and execution debugger

Brought by drakestapleton

branch main Branches Tags History

spark-debugger / src / main.rs

107 lines · 3439 bytes Raw Blame History
1use clap::{Parser, Subcommand};
2use reqwest::Client;
3use std::time::Duration;
4use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
5
6mod audit;
7mod daemon;
8mod mcp;
9mod reporter;
10
11use audit::run_full_audit;
12use daemon::run_watchdog_daemon;
13use mcp::run_mcp_server;
14
15#[derive(Parser, Debug)]
16#[command(name = "spark-debugger", about = "Autonomous Continuous Watchdog and MCP Debugger for SparkOS")]
17struct Cli {
18 #[arg(long, default_value = "/home/drakestapleton/workspace/aien-sovereign-core")]
19 workspace: String,
20
21 #[arg(long)]
22 daemon: bool,
23
24 #[arg(long)]
25 mcp: bool,
26
27 #[arg(long, default_value_t = 30)]
28 interval: u64,
29
30 #[command(subcommand)]
31 command: Option<Commands>,
32}
33
34#[derive(Subcommand, Debug)]
35enum Commands {
36 Check,
37 Daemon,
38 Mcp,
39}
40
41#[tokio::main]
42async fn main() -> Result<(), Box<dyn std::error::Error>> {
43 let cli = Cli::parse();
44
45 let client = Client::builder()
46 .tcp_nodelay(true)
47 .timeout(Duration::from_secs(5))
48 .build()
49 .unwrap_or_default();
50
51 if cli.mcp || matches!(cli.command, Some(Commands::Mcp)) {
52 // Run MCP server over stdio without standard logging interfering with stdout
53 tracing_subscriber::registry()
54 .with(tracing_subscriber::fmt::layer().with_writer(std::io::stderr))
55 .init();
56 return run_mcp_server(client, cli.workspace).await;
57 }
58
59 tracing_subscriber::registry()
60 .with(tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into()))
61 .with(tracing_subscriber::fmt::layer())
62 .init();
63
64 if cli.daemon || matches!(cli.command, Some(Commands::Daemon)) {
65 return run_watchdog_daemon(client, cli.workspace, cli.interval).await;
66 }
67
68 // Default: one-shot check
69 println!("");
70 println!("=== SparkOS Sovereign Watchdog: System Diagnostic Audit ===");
71 let report = run_full_audit(&client, &cli.workspace).await;
72
73 println!("{:<22} {:<38} {:<10} {:<10}", "SERVICE", "ENDPOINT", "STATUS", "LATENCY");
74 println!("{}", "-".repeat(82));
75 for s in &report.services {
76 let status_str = if s.reachable { "ONLINE" } else { "OFFLINE" };
77 let code_str = s.status_code.map(|c| c.to_string()).unwrap_or_else(|| "-".into());
78 println!("{:<22} {:<38} {:<10} {:<10}",
79 s.name, s.endpoint, format!("{} ({})", status_str, code_str), format!("{}ms", s.latency_ms));
80 }
81 println!("{}", "-".repeat(82));
82
83 println!("
84--- Invariant Checks ---");
85 println!("TPM Vault Clean (Zero .env files): {}", if report.invariants.plaintext_env_files_found.is_empty() { "PASSED" } else { "FAILED" });
86 if !report.invariants.plaintext_env_files_found.is_empty() {
87 for f in &report.invariants.plaintext_env_files_found {
88 println!(" Leaked file: {}", f);
89 }
90 }
91 println!("Unslop Standard (Zero em/en dashes): {}", if report.invariants.unslop_violations.is_empty() { "PASSED" } else { "FAILED" });
92
93 println!("
94--- Workspace Compile Check ---");
95 println!("Cargo Check: {}", if report.build.passed { "PASSED" } else { "FAILED" });
96 if !report.build.errors.is_empty() {
97 for e in &report.build.errors {
98 println!(" {}", e);
99 }
100 }
101
102 println!("
103Overall Diagnostic Status: {}", if report.overall_healthy { "ALL SYSTEMS GREEN" } else { "ATTENTION REQUIRED" });
104 println!("");
105
106 Ok(())
107}