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

58 lines · 2352 bytes Raw Blame History
1use reqwest::Client;
2use rusqlite::params;
3use serde_json::json;
4use std::path::Path;
5use tracing::{error, info};
6use uuid::Uuid;
7
8use crate::audit::SystemAuditReport;
9
10const CORTEX_URL: &str = "http://127.0.0.1:18080";
11const CORTEX_TOKEN_PATH: &str = "/home/drakestapleton/.config/cortex/token";
12const HIVE_DB_PATH: &str = "/home/drakestapleton/.config/cortex/hive.db";
13
14pub async fn report_incident(client: &Client, report: &SystemAuditReport, failure_summary: &str) {
15 info!("[DebuggerReporter] Reporting incident: {}", failure_summary);
16
17 // 1. Commit bug report to Cortex memory
18 if let Ok(token) = std::fs::read_to_string(CORTEX_TOKEN_PATH) {
19 let payload = json!({
20 "space": "atlas-memory",
21 "canonicalName": format!("incident-{}", Uuid::new_v4().to_string()[..8].to_string()),
22 "entityType": "bug_report",
23 "content": format!("Incident detected by spark-debugger: {}
24Report Details: {:?}", failure_summary, report)
25 });
26
27 let write_url = format!("{}/api/cortex/write", CORTEX_URL);
28 if let Err(e) = client.post(&write_url)
29 .header("Authorization", format!("Bearer {}", token.trim()))
30 .json(&payload)
31 .send()
32 .await
33 {
34 error!("[DebuggerReporter] Failed to commit bug report to Cortex: {}", e);
35 } else {
36 info!("[DebuggerReporter] Committed bug report to Cortex.");
37 }
38 }
39
40 // 2. Emit alert comb onto Honeycomb lattice if hive.db exists
41 if Path::new(HIVE_DB_PATH).exists() {
42 if let Ok(conn) = rusqlite::Connection::open(HIVE_DB_PATH) {
43 let comb_id = format!("comb-alert-{}", &Uuid::new_v4().to_string()[..8]);
44 let now = chrono::Utc::now().to_rfc3339();
45 let content = format!("🚨 AUDIT ALERT: {}", failure_summary);
46
47 // Find free coordinate or default to outer ring
48 let res = conn.execute(
49 "INSERT INTO hive_combs (id, q, r, author, role, content, intent, created_at)
50 VALUES (?1, -2, 2, ?2, ?3, ?4, ?5, ?6)",
51 params![comb_id, "spark-debugger", "watchdog", content, "branch", now],
52 );
53 if let Ok(_) = res {
54 info!("[DebuggerReporter] Emitted alert comb to Honeycomb Wall.");
55 }
56 }
57 }
58}