pub mod agent; pub mod approve; pub mod command; pub mod compact; pub mod consult; pub mod context; pub mod danger; pub mod ext; pub mod herdr; pub mod hook; mod mask; pub mod memory; pub mod nudge; pub mod permit; pub mod route; pub mod sandbox; pub mod session; pub mod stats; pub mod subagent; pub mod switch; pub mod tool; pub mod window; use std::collections::HashMap; use std::path::PathBuf; use std::sync::Mutex; use std::time::SystemTime; pub type Ask = std::sync::Arc< dyn Fn(String) -> std::pin::Pin + Send>> + Send + Sync, >; #[derive(Debug, Clone, PartialEq)] pub struct Question { pub text: String, pub options: Vec<(String, String)>, pub multi: bool, pub other: bool, pub plan: Option, } pub type Choose = std::sync::Arc< dyn Fn( Question, ) -> std::pin::Pin>> + Send>> + Send + Sync, >; #[derive(Default)] pub struct State { pub seen: Mutex>>, pub ask: std::sync::OnceLock, pub permit: std::sync::OnceLock, pub judge: std::sync::OnceLock, pub allow: Mutex, pub asking: tokio::sync::Mutex<()>, pub edits: Mutex>, pub choose: std::sync::OnceLock, pub abort: std::sync::OnceLock>, pub sub_usage: Mutex, pub subs: subagent::Subs, pub consult: std::sync::OnceLock>, pub live: Mutex>, pub claude_seen: Mutex>, pub lens: Mutex, pub nested: Mutex>>, pub codemode_store: Mutex>, } #[derive(Debug, Clone, Default, PartialEq)] pub struct LensView { pub diags: Vec, pub tests: Option>, } #[derive(Debug, Clone, PartialEq)] pub struct Diag { pub file: String, pub line: u32, pub col: u32, pub error: bool, pub message: String, } impl State { pub async fn confirm(&self, question: String) -> bool { match self.ask.get() { Some(a) => a(question).await, None => false, } } pub async fn choose(&self, q: Question) -> Result>, &'static str> { match self.choose.get() { Some(c) => Ok(c(q).await), None => Err("no interactive user attached; decide yourself or state your assumption"), } } pub fn log_edit(&self, p: &std::path::Path, old: Option, new: &str) { self.edits .lock() .unwrap_or_else(|e| e.into_inner()) .push(permit::FileEdit { path: p.to_path_buf(), old, new: new.into(), }); } pub fn mark_seen(&self, p: &std::path::Path) { let m = std::fs::metadata(p).and_then(|m| m.modified()).ok(); self.seen .lock() .unwrap_or_else(|e| e.into_inner()) .insert(p.to_path_buf(), m); } pub fn is_fresh(&self, p: &std::path::Path) -> bool { let now = std::fs::metadata(p).and_then(|m| m.modified()).ok(); self.seen .lock() .unwrap_or_else(|e| e.into_inner()) .get(p) .is_some_and(|m| *m == now) } }