spark-hive
Multi-agent swarm coordination and peer routing engine
Brought by drakestapleton
spark-hive / src / emission.rs
| 1 | use crate::store::{CombStore, HiveComb, HiveError, PlaceCombInput}; |
| 2 | |
| 3 | /// Emits a comb onto the hexagonal honeycomb lattice when an agent or subagent completes a task. |
| 4 | pub fn emit_subagent_comb( |
| 5 | store: &CombStore, |
| 6 | role: &str, |
| 7 | summary: &str, |
| 8 | parent_id: Option<&str>, |
| 9 | ) -> Result<HiveComb, HiveError> { |
| 10 | let author = format!("AIEN ยท {}", role); |
| 11 | let input = PlaceCombInput { |
| 12 | q: None, |
| 13 | r: None, |
| 14 | author, |
| 15 | role: Some(role.to_string()), |
| 16 | content: summary.to_string(), |
| 17 | intent: Some("join".to_string()), |
| 18 | parent_id: parent_id.map(|s| s.to_string()), |
| 19 | }; |
| 20 | store.place_comb(input) |
| 21 | } |
| 22 | |
| 23 | /// Emits a comb onto the hexagonal honeycomb lattice when Socratic inquiry is triggered. |
| 24 | pub fn emit_socratic_comb( |
| 25 | store: &CombStore, |
| 26 | question: &str, |
| 27 | parent_id: Option<&str>, |
| 28 | ) -> Result<HiveComb, HiveError> { |
| 29 | let author = "AIEN (Socratic)".to_string(); |
| 30 | let input = PlaceCombInput { |
| 31 | q: None, |
| 32 | r: None, |
| 33 | author, |
| 34 | role: Some("socratic".to_string()), |
| 35 | content: question.to_string(), |
| 36 | intent: Some("branch".to_string()), |
| 37 | parent_id: parent_id.map(|s| s.to_string()), |
| 38 | }; |
| 39 | store.place_comb(input) |
| 40 | } |
| 41 | |
| 42 | #[cfg(test)] |
| 43 | mod tests { |
| 44 | use super::*; |
| 45 | |
| 46 | #[test] |
| 47 | fn test_subagent_and_socratic_emission() { |
| 48 | let store = CombStore::open_in_memory().expect("in memory store"); |
| 49 | |
| 50 | // 1. Emit socratic inquiry comb |
| 51 | let socratic = emit_socratic_comb( |
| 52 | &store, |
| 53 | "What is the foundational invariant of this sovereign workspace?", |
| 54 | Some("comb-genesis-00000000"), |
| 55 | ).expect("socratic emission"); |
| 56 | |
| 57 | assert_eq!(socratic.role, "socratic"); |
| 58 | assert_eq!(socratic.intent, "branch"); |
| 59 | assert_eq!(socratic.parent_id, Some("comb-genesis-00000000".to_string())); |
| 60 | |
| 61 | // 2. Emit subagent completed comb |
| 62 | let sub = emit_subagent_comb( |
| 63 | &store, |
| 64 | "researcher", |
| 65 | "Synthesized hexagonal honeycomb topology specifications.", |
| 66 | Some(&socratic.id), |
| 67 | ).expect("subagent emission"); |
| 68 | |
| 69 | assert_eq!(sub.role, "researcher"); |
| 70 | assert_eq!(sub.intent, "join"); |
| 71 | assert_eq!(sub.parent_id, Some(socratic.id.clone())); |
| 72 | |
| 73 | // Verify total count on lattice |
| 74 | let (cells, bounds) = store.get_cells().expect("get cells"); |
| 75 | assert_eq!(cells.len(), 3); |
| 76 | assert_eq!(bounds.count, 3); |
| 77 | } |
| 78 | } |