Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-sovereign-core-mv/blob/main/crates/spark-dream/src/main.rs # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-sovereign-core-mv / crates / spark-dream / src / main.rs` 136 lines ยท 4525 bytes Raw Blame History 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 clap::{Parser, Subcommand}; 17 use spark_dream::DreamEngine; 18 use std::path::PathBuf; 19 use std::time::Duration; 20 use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; 21 22 #[derive(Parser, Debug)] 23 #[command( 24 name = "spark-dream", 25 about = "Native Rust Dynamic Dream Cycle Engine for SparkOS" 26 )] 27 struct Cli { 28 #[arg(long, default_value_os_t = default_dream_basecamp())] 29 basecamp: PathBuf, 30 31 #[arg(long)] 32 daemon: bool, 33 34 #[arg(long, default_value_t = 900)] 35 idle_threshold: u64, 36 37 #[command(subcommand)] 38 command: Option, 39 } 40 41 #[derive(Subcommand, Debug)] 42 enum Commands { 43 /// Execute one immediate dream consolidation cycle 44 Cycle, 45 /// Run as continuous background daemon 46 Daemon, 47 /// Check current dream cycle status and telemetry 48 Status, 49 } 50 51 fn default_dream_basecamp() -> PathBuf { 52 let home = std::env::var("HOME") 53 .or_else(|_| std::env::var("USERPROFILE")) 54 .map(PathBuf::from) 55 .unwrap_or_else(|_| PathBuf::from(".")); 56 home.join("basecamp") 57 } 58 59 #[tokio::main] 60 async fn main() -> Result<(), Box> { 61 tracing_subscriber::registry() 62 .with(tracing_subscriber::EnvFilter::new("info")) 63 .with(tracing_subscriber::fmt::layer()) 64 .init(); 65 66 let cli = Cli::parse(); 67 let engine = DreamEngine::new(cli.basecamp.clone()); 68 69 let command = cli.command.unwrap_or({ 70 if cli.daemon { 71 Commands::Daemon 72 } else { 73 Commands::Cycle 74 } 75 }); 76 77 match command { 78 Commands::Cycle => { 79 println!("๐ŸŒŒ Executing immediate sovereign dream consolidation cycle on DGX Spark..."); 80 let start = std::time::Instant::now(); 81 let state = engine.execute_dream_cycle().await?; 82 let elapsed = start.elapsed(); 83 println!("โœ… Dream Cycle Completed in {:.2?}:", elapsed); 84 println!(" - Facts Committed: {}", state.facts_committed); 85 println!(" - Proposals Staged: {}", state.proposals_staged); 86 println!(" - Rejected: {}", state.facts_rejected); 87 } 88 89 Commands::Status => { 90 let state_file = cli.basecamp.join("aien-dream/state.json"); 91 if state_file.exists() { 92 let content = std::fs::read_to_string(&state_file)?; 93 println!("{}", content); 94 } else { 95 println!("No dream cycle state found at {:?}", state_file); 96 } 97 } 98 99 Commands::Daemon => { 100 println!( 101 "๐ŸŒŒ Starting native sovereign dream daemon (idle threshold: {}s)...", 102 cli.idle_threshold 103 ); 104 let mut ticker = tokio::time::interval(Duration::from_secs(60)); 105 106 loop { 107 ticker.tick().await; 108 109 // 1. Check GPU utilization 110 let gpu_util = engine.get_gpu_utilization().await; 111 if gpu_util > 5 { 112 // Operator or training load is active, skip cycle 113 continue; 114 } 115 116 // 2. Check operator idle time 117 if let Some(last_act) = engine.get_last_session_activity() { 118 let now = chrono::Utc::now(); 119 let idle_secs = (now - last_act).num_seconds().max(0) as u64; 120 121 if idle_secs >= cli.idle_threshold { 122 tracing::info!( 123 "Operator idle for {}s with 0% GPU load. Initiating dream cycle.", 124 idle_secs 125 ); 126 if let Err(e) = engine.execute_dream_cycle().await { 127 tracing::warn!("Dream cycle error: {}", e); 128 } 129 } 130 } 131 } 132 } 133 } 134 135 Ok(()) 136 }