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
aien-sovereign-core-mv / crates / aien-cli / src / hive.rs
| 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 serde_json::{json, Value}; |
| 17 | use std::process::Command; |
| 18 | |
| 19 | fn get_hive_bin() -> std::path::PathBuf { |
| 20 | let platform = crate::platform::PlatformContext::detect(); |
| 21 | let local = platform.home_dir.join("aien-hive/target/release/aien-hive"); |
| 22 | if local.exists() { |
| 23 | local |
| 24 | } else { |
| 25 | std::path::PathBuf::from("aien-hive") |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | pub fn hive_roster() -> String { |
| 30 | let out = Command::new(get_hive_bin()).arg("roster").output(); |
| 31 | match out { |
| 32 | Ok(o) => String::from_utf8_lossy(&o.stdout).to_string(), |
| 33 | Err(e) => format!("Failed to run aien-hive roster: {}", e), |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | pub fn hive_spawn(role: &str, task: &str) -> String { |
| 38 | let out = Command::new(get_hive_bin()) |
| 39 | .args(["spawn", role, task]) |
| 40 | .output(); |
| 41 | match out { |
| 42 | Ok(o) => String::from_utf8_lossy(&o.stdout).to_string(), |
| 43 | Err(e) => format!("Failed to spawn cell: {}", e), |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | pub fn hive_swarm(task: &str, n: usize) -> String { |
| 48 | let out = Command::new(get_hive_bin()) |
| 49 | .args(["swarm", "--task", task, "--n", &n.to_string()]) |
| 50 | .output(); |
| 51 | match out { |
| 52 | Ok(o) => String::from_utf8_lossy(&o.stdout).to_string(), |
| 53 | Err(e) => format!("Failed to run swarm: {}", e), |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | pub fn hive_read(name: &str) -> String { |
| 58 | let out = Command::new(get_hive_bin()).args(["read", name]).output(); |
| 59 | match out { |
| 60 | Ok(o) => String::from_utf8_lossy(&o.stdout).to_string(), |
| 61 | Err(e) => format!("Failed to read cell {}: {}", name, e), |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | pub fn hive_kill(name: &str) -> String { |
| 66 | let out = Command::new(get_hive_bin()).args(["kill", name]).output(); |
| 67 | match out { |
| 68 | Ok(o) => String::from_utf8_lossy(&o.stdout).to_string(), |
| 69 | Err(e) => format!("Failed to kill cell {}: {}", name, e), |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | pub fn hive_sense(text: &str) -> String { |
| 74 | let out = Command::new(get_hive_bin()).args(["sense", text]).output(); |
| 75 | match out { |
| 76 | Ok(o) => String::from_utf8_lossy(&o.stdout).to_string(), |
| 77 | Err(e) => format!("Failed to sense: {}", e), |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | pub fn hive_dispatch_tool(args: &Value) -> Value { |
| 82 | let action = args |
| 83 | .get("action") |
| 84 | .and_then(Value::as_str) |
| 85 | .unwrap_or("roster"); |
| 86 | match action { |
| 87 | "roster" => json!({"roster": hive_roster()}), |
| 88 | "spawn" => { |
| 89 | let role = args |
| 90 | .get("role") |
| 91 | .and_then(Value::as_str) |
| 92 | .unwrap_or("researcher"); |
| 93 | let task = args.get("task").and_then(Value::as_str).unwrap_or(""); |
| 94 | json!({"result": hive_spawn(role, task)}) |
| 95 | } |
| 96 | "swarm" => { |
| 97 | let task = args.get("task").and_then(Value::as_str).unwrap_or(""); |
| 98 | let n = args.get("n").and_then(Value::as_u64).unwrap_or(2) as usize; |
| 99 | json!({"result": hive_swarm(task, n)}) |
| 100 | } |
| 101 | "read" => { |
| 102 | let name = args.get("name").and_then(Value::as_str).unwrap_or(""); |
| 103 | json!({"output": hive_read(name)}) |
| 104 | } |
| 105 | "kill" => { |
| 106 | let name = args.get("name").and_then(Value::as_str).unwrap_or(""); |
| 107 | json!({"result": hive_kill(name)}) |
| 108 | } |
| 109 | "sense" => { |
| 110 | let text = args.get("text").and_then(Value::as_str).unwrap_or(""); |
| 111 | json!({"salience": hive_sense(text)}) |
| 112 | } |
| 113 | other => json!({"error": format!("Unknown hive action: {}", other)}), |
| 114 | } |
| 115 | } |