//! Loose-ends aggregator. Assembles a `Vec` for a single agent //! (`for_agent`) — always the caller's own. `Request::GetLooseEnds` from //! either the agent or manager socket lands here. Reminders and todos are //! agent-local (in-container `hive-agent` stores) and never sourced from //! here. //! //! Call frequency is low (an agent doing self-introspection between //! turns), so the sweep happens fresh every time — no caching, no //! mutation events. use anyhow::Result; use hive_sh4re::inbox::LooseEnd; use crate::coordinator::Coordinator; /// Open threads pending against `agent`: undelivered inbox messages this /// agent still owes itself a `recv` for, only when the count is non-zero. /// /// # Errors /// /// Propagates errors from `count_pending`. pub fn for_agent(coord: &Coordinator, agent: &str) -> Result> { let mut out = Vec::new(); // Only emitted when non-zero so a clean inbox doesn't add noise. The // wake-message that drove the current turn is already delivered, so // this counts only what's genuinely still queued. let pending_messages = coord.broker.count_pending(agent)?; if pending_messages > 0 { out.push(LooseEnd::PendingMessages { count: pending_messages, }); } Ok(out) }