aien-sovereign-core
Autonomous sovereign intelligence engine and runtime core for NVIDIA DGX Spark
Brought by drakestapleton
aien-sovereign-core / crates / aien-cli / src / hive.rs
| 1 | use std::process::Command; |
| 2 | use serde_json::{json, Value}; |
| 3 | |
| 4 | const HIVE_BIN: &str = "/home/drakestapleton/aien-hive/target/release/aien-hive"; |
| 5 | |
| 6 | pub fn hive_roster() -> String { |
| 7 | let out = Command::new(HIVE_BIN).arg("roster").output(); |
| 8 | match out { |
| 9 | Ok(o) => String::from_utf8_lossy(&o.stdout).to_string(), |
| 10 | Err(e) => format!("Failed to run aien-hive roster: {}", e), |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | pub fn hive_spawn(role: &str, task: &str) -> String { |
| 15 | let out = Command::new(HIVE_BIN) |
| 16 | .args(["spawn", role, task]) |
| 17 | .output(); |
| 18 | match out { |
| 19 | Ok(o) => String::from_utf8_lossy(&o.stdout).to_string(), |
| 20 | Err(e) => format!("Failed to spawn cell: {}", e), |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | pub fn hive_swarm(task: &str, n: usize) -> String { |
| 25 | let out = Command::new(HIVE_BIN) |
| 26 | .args(["swarm", "--task", task, "--n", &n.to_string()]) |
| 27 | .output(); |
| 28 | match out { |
| 29 | Ok(o) => String::from_utf8_lossy(&o.stdout).to_string(), |
| 30 | Err(e) => format!("Failed to run swarm: {}", e), |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | pub fn hive_read(name: &str) -> String { |
| 35 | let out = Command::new(HIVE_BIN) |
| 36 | .args(["read", name]) |
| 37 | .output(); |
| 38 | match out { |
| 39 | Ok(o) => String::from_utf8_lossy(&o.stdout).to_string(), |
| 40 | Err(e) => format!("Failed to read cell {}: {}", name, e), |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | pub fn hive_kill(name: &str) -> String { |
| 45 | let out = Command::new(HIVE_BIN) |
| 46 | .args(["kill", name]) |
| 47 | .output(); |
| 48 | match out { |
| 49 | Ok(o) => String::from_utf8_lossy(&o.stdout).to_string(), |
| 50 | Err(e) => format!("Failed to kill cell {}: {}", name, e), |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | pub fn hive_sense(text: &str) -> String { |
| 55 | let out = Command::new(HIVE_BIN) |
| 56 | .args(["sense", text]) |
| 57 | .output(); |
| 58 | match out { |
| 59 | Ok(o) => String::from_utf8_lossy(&o.stdout).to_string(), |
| 60 | Err(e) => format!("Failed to sense: {}", e), |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | pub fn hive_dispatch_tool(args: &Value) -> Value { |
| 65 | let action = args.get("action").and_then(Value::as_str).unwrap_or("roster"); |
| 66 | match action { |
| 67 | "roster" => json!({"roster": hive_roster()}), |
| 68 | "spawn" => { |
| 69 | let role = args.get("role").and_then(Value::as_str).unwrap_or("researcher"); |
| 70 | let task = args.get("task").and_then(Value::as_str).unwrap_or(""); |
| 71 | json!({"result": hive_spawn(role, task)}) |
| 72 | }, |
| 73 | "swarm" => { |
| 74 | let task = args.get("task").and_then(Value::as_str).unwrap_or(""); |
| 75 | let n = args.get("n").and_then(Value::as_u64).unwrap_or(2) as usize; |
| 76 | json!({"result": hive_swarm(task, n)}) |
| 77 | }, |
| 78 | "read" => { |
| 79 | let name = args.get("name").and_then(Value::as_str).unwrap_or(""); |
| 80 | json!({"output": hive_read(name)}) |
| 81 | }, |
| 82 | "kill" => { |
| 83 | let name = args.get("name").and_then(Value::as_str).unwrap_or(""); |
| 84 | json!({"result": hive_kill(name)}) |
| 85 | }, |
| 86 | "sense" => { |
| 87 | let text = args.get("text").and_then(Value::as_str).unwrap_or(""); |
| 88 | json!({"salience": hive_sense(text)}) |
| 89 | }, |
| 90 | other => json!({"error": format!("Unknown hive action: {}", other)}), |
| 91 | } |
| 92 | } |