//! Turn-scoped state and active turn metadata scaffolding. use std::collections::HashMap; use std::sync::Arc; use tokio::sync::Mutex; use codex_protocol::models::ResponseInputItem; use tokio::sync::oneshot; use crate::protocol::ReviewDecision; /// Metadata about the currently running turn. #[derive(Default)] pub(crate) struct ActiveTurn { pub(crate) sub_id: String, pub(crate) turn_state: Arc>, } /// Mutable state for a single turn. #[derive(Default)] pub(crate) struct TurnState { pending_approvals: HashMap>, pending_input: Vec, } impl TurnState { pub(crate) fn insert_pending_approval( &mut self, key: String, tx: oneshot::Sender, ) -> Option> { self.pending_approvals.insert(key, tx) } pub(crate) fn remove_pending_approval( &mut self, key: &str, ) -> Option> { self.pending_approvals.remove(key) } pub(crate) fn clear_pending(&mut self) { self.pending_approvals.clear(); self.pending_input.clear(); } pub(crate) fn push_pending_input(&mut self, input: ResponseInputItem) { self.pending_input.push(input); } pub(crate) fn take_pending_input(&mut self) -> Vec { if self.pending_input.is_empty() { Vec::with_capacity(0) } else { let mut ret = Vec::new(); std::mem::swap(&mut ret, &mut self.pending_input); ret } } }