spark-dream
Idle-cycle neural memory consolidator and vectorizer
Brought by drakestapleton
spark-dream / src / main.rs
| 1 | use clap::{Parser, Subcommand}; |
| 2 | use spark_dream::DreamEngine; |
| 3 | use std::path::PathBuf; |
| 4 | use std::time::Duration; |
| 5 | use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; |
| 6 | |
| 7 | #[derive(Parser, Debug)] |
| 8 | #[command(name = "spark-dream", about = "Native Rust Dynamic Dream Cycle Engine for SparkOS")] |
| 9 | struct Cli { |
| 10 | #[arg(long, default_value = "/home/drakestapleton/basecamp")] |
| 11 | basecamp: PathBuf, |
| 12 | |
| 13 | #[arg(long)] |
| 14 | daemon: bool, |
| 15 | |
| 16 | #[arg(long, default_value_t = 900)] |
| 17 | idle_threshold: u64, |
| 18 | |
| 19 | #[command(subcommand)] |
| 20 | command: Option<Commands>, |
| 21 | } |
| 22 | |
| 23 | #[derive(Subcommand, Debug)] |
| 24 | enum Commands { |
| 25 | /// Execute one immediate dream consolidation cycle |
| 26 | Cycle, |
| 27 | /// Run as continuous background daemon |
| 28 | Daemon, |
| 29 | /// Check current dream cycle status and telemetry |
| 30 | Status, |
| 31 | } |
| 32 | |
| 33 | #[tokio::main] |
| 34 | async fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 35 | tracing_subscriber::registry() |
| 36 | .with(tracing_subscriber::EnvFilter::new("info")) |
| 37 | .with(tracing_subscriber::fmt::layer()) |
| 38 | .init(); |
| 39 | |
| 40 | let cli = Cli::parse(); |
| 41 | let engine = DreamEngine::new(cli.basecamp.clone()); |
| 42 | |
| 43 | let command = cli.command.unwrap_or_else(|| { |
| 44 | if cli.daemon { |
| 45 | Commands::Daemon |
| 46 | } else { |
| 47 | Commands::Cycle |
| 48 | } |
| 49 | }); |
| 50 | |
| 51 | match command { |
| 52 | Commands::Cycle => { |
| 53 | println!("🌌 Executing immediate sovereign dream consolidation cycle on DGX Spark..."); |
| 54 | let start = std::time::Instant::now(); |
| 55 | let state = engine.execute_dream_cycle().await?; |
| 56 | let elapsed = start.elapsed(); |
| 57 | println!("✅ Dream Cycle Completed in {:.2?}:", elapsed); |
| 58 | println!(" - Facts Committed: {}", state.facts_committed); |
| 59 | println!(" - Proposals Staged: {}", state.proposals_staged); |
| 60 | println!(" - Rejected: {}", state.facts_rejected); |
| 61 | } |
| 62 | |
| 63 | Commands::Status => { |
| 64 | let state_file = cli.basecamp.join("aien-dream/state.json"); |
| 65 | if state_file.exists() { |
| 66 | let content = std::fs::read_to_string(&state_file)?; |
| 67 | println!("{}", content); |
| 68 | } else { |
| 69 | println!("No dream cycle state found at {:?}", state_file); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | Commands::Daemon => { |
| 74 | println!("🌌 Starting native sovereign dream daemon (idle threshold: {}s)...", cli.idle_threshold); |
| 75 | let mut ticker = tokio::time::interval(Duration::from_secs(60)); |
| 76 | |
| 77 | loop { |
| 78 | ticker.tick().await; |
| 79 | |
| 80 | // 1. Check GPU utilization |
| 81 | let gpu_util = engine.get_gpu_utilization().await; |
| 82 | if gpu_util > 5 { |
| 83 | // Operator or training load is active, skip cycle |
| 84 | continue; |
| 85 | } |
| 86 | |
| 87 | // 2. Check operator idle time |
| 88 | if let Some(last_act) = engine.get_last_session_activity() { |
| 89 | let now = chrono::Utc::now(); |
| 90 | let idle_secs = (now - last_act).num_seconds().max(0) as u64; |
| 91 | |
| 92 | if idle_secs >= cli.idle_threshold { |
| 93 | tracing::info!("Operator idle for {}s with 0% GPU load. Initiating dream cycle.", idle_secs); |
| 94 | if let Err(e) = engine.execute_dream_cycle().await { |
| 95 | tracing::warn!("Dream cycle error: {}", e); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | Ok(()) |
| 104 | } |