bob-reasoning / magmad /src /main.rs
SNAPKITTYWEST's picture
Add magmad: Rust sovereign agentic daemon β€” HTTP, gRPC, CLI, BOB/MAGMA routing
4ae5926 verified
Raw
History Blame Contribute Delete
5.53 kB
// main.rs β€” magmad sovereign agentic daemon
//
// Starts REST + SSE on :3000 (primary interface).
// gRPC on :50051 is defined in grpc/mod.rs and will be wired when protoc
// becomes available (install protoc, re-add tonic_build to build.rs).
//
// Usage:
// magmad # start with defaults
// MAGMA_HTTP_PORT=8080 magmad # override HTTP port
// MAGMA_NATS_URL=nats://... magmad
//
// Ahmad Ali Parr Β· SnapKitty Collective Β· 2026
mod bob;
mod config;
mod errant_ffi;
mod grpc;
mod http;
mod nats_bus;
use std::sync::Arc;
use anyhow::Result;
use tracing::{info, warn, error};
#[tokio::main]
async fn main() -> Result<()> {
let cfg = config::Config::from_env();
// ── Tracing ───────────────────────────────────────────────────────────
tracing_subscriber::fmt()
.with_env_filter(&cfg.log_level)
.json()
.init();
print_banner(&cfg);
// ── Verify liberrant is linked and working ────────────────────────────
{
let check = errant_ffi::verify_named(&["PUSH_UN", "SEAL"]);
if check.ok {
info!("liberrant {} online Β· FIPS SHA-256 verified", errant_ffi::version());
} else {
error!("liberrant self-check FAILED: {}", check.error);
std::process::exit(1);
}
}
// ── NATS connection (optional β€” daemon runs without it) ───────────────
let nats = match nats_bus::NatsBus::connect(&cfg.nats_url).await {
Ok(bus) => {
info!("NATS connected: {}", cfg.nats_url);
Some(Arc::new(bus))
}
Err(e) => {
warn!("NATS unavailable ({}): running in local mode", e);
None
}
};
// ── Build shared HTTP state ───────────────────────────────────────────
let http_state = http::AppState {
config: Arc::new(cfg.clone()),
nats: nats.clone(),
worm_url: format!("{}/api/labs/ledge/seal", cfg.os_url),
};
// ── REST + SSE server (primary interface) ─────────────────────────────
let http_addr: std::net::SocketAddr = cfg.http_addr().parse()?;
let app = http::router(http_state)
.layer(tower_http::cors::CorsLayer::permissive())
.layer(tower_http::trace::TraceLayer::new_for_http());
info!("REST/SSE listening on http://{}", http_addr);
info!("gRPC endpoint defined at :{} (enable: install protoc, run cargo build)", cfg.grpc_port);
info!("magmad online Β· EVIDENCE OR SILENCE Β· Ξ©β†ΊΞ¨β†ΊΞ”β†ΊΞ›β†ΊΞ£β†ΊΞ¦β†ΊΞ±");
let listener = tokio::net::TcpListener::bind(http_addr).await?;
tokio::select! {
r = axum::serve(listener, app) => {
if let Err(e) = r { error!("HTTP server error: {e}"); }
}
_ = tokio::signal::ctrl_c() => {
info!("Ξ© β€” magmad shutting down");
}
}
Ok(())
}
fn print_banner(cfg: &config::Config) {
eprintln!(r#"
╔══════════════════════════════════════════════════════════════╗
β•‘ β–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β•‘
β•‘ β–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β•β• β–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•— β•‘
β•‘ β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘ β•‘
β•‘ β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘ β•‘
β•‘ β–ˆβ–ˆβ•‘ β•šβ•β• β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘ β•šβ•β• β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β• β•‘
β•‘ β•šβ•β• β•šβ•β•β•šβ•β• β•šβ•β• β•šβ•β•β•β•β•β• β•šβ•β• β•šβ•β•β•šβ•β• β•šβ•β•β•šβ•β•β•β•β•β• β•‘
╠══════════════════════════════════════════════════════════════╣
β•‘ Sovereign Agentic Daemon v{} β•‘
β•‘ BOB: TRUST-DEED-GATE β†’ MAMBA β†’ WATSON β†’ PROLOG β†’ SEAL β•‘
╠══════════════════════════════════════════════════════════════╣
β•‘ REST/SSE http://0.0.0.0:{} β•‘
β•‘ gRPC :{} (stub β€” install protoc to activate) β•‘
β•‘ NATS {}
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
"#,
env!("CARGO_PKG_VERSION"),
cfg.http_port,
cfg.grpc_port,
cfg.nats_url,
);
}