use std::sync::Arc;
use std::sync::atomic::AtomicBool;
pub type SharedPlanMode = Arc<AtomicBool>;
#[must_use]
pub fn new_shared_plan_mode() -> SharedPlanMode {
Arc::new(AtomicBool::new(false))
}
pub const PLAN_MODE_ALLOWLIST: &[&str] = &[
"Read",
"Grep",
"Glob",
"WebFetch",
"Skill",
"EnterPlanMode",
"ExitPlanMode",
];
#[must_use]
pub fn is_allowed_in_plan_mode(name: &str) -> bool {
PLAN_MODE_ALLOWLIST.contains(&name)
}
#[cfg(test)]
mod tests {
use super::*;
use std::sync::atomic::Ordering;
#[test]
fn defaults_to_false() {
let f = new_shared_plan_mode();
assert!(!f.load(Ordering::Relaxed));
}
#[test]
fn store_visible_across_clones() {
let a = new_shared_plan_mode();
let b = Arc::clone(&a);
b.store(true, Ordering::Relaxed);
assert!(a.load(Ordering::Relaxed));
}
#[test]
fn allowlist_includes_expected_tools() {
assert!(is_allowed_in_plan_mode("Read"));
assert!(is_allowed_in_plan_mode("Grep"));
assert!(is_allowed_in_plan_mode("Glob"));
assert!(is_allowed_in_plan_mode("WebFetch"));
assert!(is_allowed_in_plan_mode("Skill"));
assert!(is_allowed_in_plan_mode("EnterPlanMode"));
assert!(is_allowed_in_plan_mode("ExitPlanMode"));
}
#[test]
fn allowlist_excludes_mutating_tools() {
assert!(!is_allowed_in_plan_mode("Bash"));
assert!(!is_allowed_in_plan_mode("Write"));
assert!(!is_allowed_in_plan_mode("Edit"));
assert!(!is_allowed_in_plan_mode("TodoWrite"));
}
}