//! Live-state callback builder for the Hive Mind TUI panel. //! //! `build_live` creates a `LiveStateFn` closure that forwards each drone's //! status update to the runtime event queue so LO can watch the Hive work. use crate::app::workflow::engine::{AgentStatus, LiveStateFn}; use std::sync::{Arc, Mutex}; /// Build the live-state callback that forwards each drone's status to the /// TUI panel so LO can watch the Hive work. pub fn build_live( turn_events: Option< &Arc>>, >, ) -> Option { turn_events.map(|events| { let events = events.clone(); let f: LiveStateFn = Arc::new( move |_agent_id: String, agent_name: String, status: AgentStatus| { let display_name = agent_name.chars().take(40).collect::(); if let Ok(mut q) = events.lock() { q.push_back(crate::app::state::runtime::TurnEvent::WorkflowAgentUpdate { agent_id: display_name.clone(), agent_name: display_name, status, }); } }, ); f }) }