#![allow(clippy::all)]
use super::context::AgentContext;
use super::tool_registry::ToolHandler;
use crate::plan_mode::{
format_notify_entered, format_notify_exited, PlanModeReason, PlanModeState, PriorMode,
};
use async_trait::async_trait;
use dashmap::DashMap;
use nexo_llm::ToolDef;
use serde_json::{json, Value};
use tokio::sync::oneshot;
use tokio::time::Duration;
use uuid::Uuid;
pub const PLAN_MODE_MAX_PLAN_BYTES: usize = 8 * 1024;
#[derive(Debug, Clone)]
pub enum PlanApprovalDecision {
Approve,
Reject { reason: String },
}
#[derive(Default)]
pub struct PlanApprovalRegistry {
pending: DashMap<String, oneshot::Sender<PlanApprovalDecision>>,
}
impl PlanApprovalRegistry {
pub fn install(&self, plan_id: String) -> oneshot::Receiver<PlanApprovalDecision> {
let (tx, rx) = oneshot::channel();
self.pending.insert(plan_id, tx);
rx
}
pub fn resolve(&self, plan_id: &str, decision: PlanApprovalDecision) -> bool {
if let Some((_, tx)) = self.pending.remove(plan_id) {
tx.send(decision).is_ok()
} else {
false
}
}
pub fn drop_waiter(&self, plan_id: &str) {
self.pending.remove(plan_id);
}
#[cfg(test)]
pub fn has_pending(&self, plan_id: &str) -> bool {
self.pending.contains_key(plan_id)
}
#[cfg(test)]
pub fn clear(&self) {
self.pending.clear();
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum PlanModeApprovalCommand {
Approve {
plan_id: String,
},
Reject {
plan_id: String,
reason: Option<String>,
},
}
pub fn parse_plan_mode_approval(body: &str) -> Option<PlanModeApprovalCommand> {
use std::sync::OnceLock;
static RE: OnceLock<regex::Regex> = OnceLock::new();
let re = RE.get_or_init(|| {
regex::Regex::new(
r"^\s*\[plan-mode\]\s+(approve|reject)\s+plan_id=(\S+)(?:\s+reason=(.*?))?\s*$",
)
.expect("plan-mode-approval regex must compile")
});
let caps = re.captures(body.trim())?;
let verb = caps.get(1)?.as_str();
let id = caps.get(2)?.as_str().to_string();
match verb {
"approve" => Some(PlanModeApprovalCommand::Approve { plan_id: id }),
"reject" => {
let reason = caps.get(3).map(|m| m.as_str().trim().to_string());
Some(PlanModeApprovalCommand::Reject {
plan_id: id,
reason,
})
}
_ => None,
}
}
pub struct EnterPlanModeTool;
impl EnterPlanModeTool {
pub fn tool_def() -> ToolDef {
ToolDef {
name: "EnterPlanMode".to_string(),
description: "Enter plan mode for non-trivial implementation tasks. While in plan mode, mutating tools (Bash writes, FileEdit, FileWrite, delegation, scheduling) are refused so the model can explore the codebase and design an approach before writing code. Call ExitPlanMode { final_plan } when ready.".to_string(),
parameters: json!({
"type": "object",
"properties": {
"reason": {
"type": "string",
"description": "Optional one-line reason for entering plan mode."
}
},
"required": []
}),
}
}
}
#[async_trait]
impl ToolHandler for EnterPlanModeTool {
async fn call(&self, ctx: &AgentContext, args: Value) -> anyhow::Result<Value> {
if !ctx.is_interactive() {
anyhow::bail!(
"EnterPlanMode is unavailable in this context (sub-agent, cron, poller, or heartbeat-spawned goal). Plan mode requires an interactive channel that can deliver an approval message."
);
}
let reason_str = args
.get("reason")
.and_then(|v| v.as_str())
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty());
let now = chrono::Utc::now().timestamp();
let plan_mode_reason = PlanModeReason::ModelRequested {
reason: reason_str.clone(),
};
let mut guard = ctx.plan_mode.write().await;
let already_on = guard.is_on();
if !already_on {
*guard = PlanModeState::On {
entered_at: now,
reason: plan_mode_reason.clone(),
prior_mode: PriorMode::default(),
};
}
let entered_at = match &*guard {
PlanModeState::On { entered_at, .. } => *entered_at,
PlanModeState::Off => unreachable!("just set to On"),
};
drop(guard);
if !already_on {
let notify = format_notify_entered(entered_at, &plan_mode_reason);
tracing::info!(
agent_id = %ctx.agent_id,
event = "plan_mode_entered",
"{notify}"
);
}
Ok(json!({
"entered_plan_mode": true,
"already_in_plan_mode": already_on,
"entered_at": entered_at,
"reason": reason_str,
"instructions": "You are in plan mode. Use FileRead, Glob, Grep, WebSearch and any read-only tool to explore. Mutating tools refuse with PlanModeRefusal. When the plan is ready, call ExitPlanMode { final_plan } (≤ 8 KiB)."
}))
}
}
pub struct ExitPlanModeTool;
impl ExitPlanModeTool {
pub fn tool_def() -> ToolDef {
ToolDef {
name: "ExitPlanMode".to_string(),
description: "Submit the final plan and exit plan mode. The plan body is logged to the turn audit log and surfaced to the operator on the pairing channel for approval before mutating tools re-arm. final_plan must be ≤ 8192 bytes (UTF-8).".to_string(),
parameters: json!({
"type": "object",
"properties": {
"final_plan": {
"type": "string",
"description": "The complete plan to submit for approval. Markdown encouraged. Hard cap 8 KiB."
}
},
"required": ["final_plan"]
}),
}
}
}
fn build_reject_followup_prompt(reason: &str) -> String {
format!(
"Plan rejected by operator. Reason: {reason}.\n\
Do not call ExitPlanMode again with the same plan.\n\
Adjust the plan based on the rejection reason and present a revised plan.",
reason = reason.trim()
)
}
#[async_trait]
impl ToolHandler for ExitPlanModeTool {
async fn call(&self, ctx: &AgentContext, args: Value) -> anyhow::Result<Value> {
let final_plan = args
.get("final_plan")
.and_then(|v| v.as_str())
.ok_or_else(|| anyhow::anyhow!("ExitPlanMode requires `final_plan` (string)"))?
.to_string();
let actual = final_plan.len();
if actual > PLAN_MODE_MAX_PLAN_BYTES {
return Err(anyhow::anyhow!(
"PlanTooLarge: actual={actual} max={max}. Trim the plan and retry.",
actual = actual,
max = PLAN_MODE_MAX_PLAN_BYTES
));
}
{
let guard = ctx.plan_mode.read().await;
if guard.is_off() {
return Err(anyhow::anyhow!(
"ExitPlanMode called outside plan mode. Use EnterPlanMode first; the tool is only meaningful when a plan is in progress."
));
}
}
let policy = &ctx.config.plan_mode;
let require_approval = policy.require_approval;
let timeout_secs = policy.approval_timeout_secs;
let plan_id = Uuid::new_v4().to_string();
let now = chrono::Utc::now().timestamp();
if require_approval {
let registry = ctx.plan_approval_registry.clone();
let rx = registry.install(plan_id.clone());
tracing::info!(
agent_id = %ctx.agent_id,
event = "plan_mode_awaiting_approval",
plan_id = %plan_id,
timeout_secs,
"[plan-mode] awaiting approval plan_id={plan_id} (resolve via plan_mode_resolve {{ plan_id, decision: approve|reject }})"
);
let timeout = Duration::from_secs(timeout_secs.max(1));
let outcome = tokio::time::timeout(timeout, rx).await;
match outcome {
Err(_elapsed) => {
registry.drop_waiter(&plan_id);
tracing::warn!(
agent_id = %ctx.agent_id,
event = "plan_mode_approval_timeout",
plan_id = %plan_id,
"[plan-mode] approval timed out plan_id={plan_id}"
);
return Err(anyhow::anyhow!(
"ApprovalTimeout: no operator decision within {timeout_secs}s for plan_id={plan_id}. Plan mode remains active; revisit the plan or reduce scope."
));
}
Ok(Err(_canceled)) => {
return Err(anyhow::anyhow!(
"Plan approval channel closed unexpectedly for plan_id={plan_id}. Plan mode remains active; rebuild the plan and try again."
));
}
Ok(Ok(PlanApprovalDecision::Reject { reason })) => {
let followup = build_reject_followup_prompt(&reason);
tracing::info!(
agent_id = %ctx.agent_id,
event = "plan_mode_rejected",
plan_id = %plan_id,
"[plan-mode] rejected plan_id={plan_id} reason={reason}"
);
return Err(anyhow::anyhow!("{followup}"));
}
Ok(Ok(PlanApprovalDecision::Approve)) => {
tracing::info!(
agent_id = %ctx.agent_id,
event = "plan_mode_approved",
plan_id = %plan_id,
"[plan-mode] approved plan_id={plan_id}"
);
}
}
}
let entered_at = {
let mut guard = ctx.plan_mode.write().await;
let entered_at = match &*guard {
PlanModeState::On { entered_at, .. } => *entered_at,
PlanModeState::Off => {
return Err(anyhow::anyhow!(
"Plan mode flipped Off concurrently — likely an external resolver. Refusing to ack the unlock twice."
));
}
};
*guard = PlanModeState::Off;
entered_at
};
let plan_chars = final_plan.chars().count();
let exit_notify = format_notify_exited(&final_plan, 0); tracing::info!(
agent_id = %ctx.agent_id,
event = "plan_mode_exited",
plan_id = %plan_id,
"{exit_notify}"
);
Ok(json!({
"exited_plan_mode": true,
"unlocked_at": now,
"entered_at": entered_at,
"plan_bytes": actual,
"plan_chars": plan_chars,
"plan_id": plan_id,
"awaiting_acceptance": false,
"approval_required": require_approval,
}))
}
}
pub struct PlanModeResolveTool;
impl PlanModeResolveTool {
pub fn tool_def() -> ToolDef {
ToolDef {
name: "plan_mode_resolve".to_string(),
description: "Operator-side resolver for a pending ExitPlanMode approval. Fires the matching waiter so the goal unlocks (approve) or surfaces the rejection reason to the model (reject).".to_string(),
parameters: json!({
"type": "object",
"properties": {
"plan_id": {
"type": "string",
"description": "Plan id from the ExitPlanMode response (UUID)."
},
"decision": {
"type": "string",
"enum": ["approve", "reject"],
"description": "Operator decision."
},
"reason": {
"type": "string",
"description": "Rejection reason (required when decision=reject)."
}
},
"required": ["plan_id", "decision"]
}),
}
}
}
#[async_trait]
impl ToolHandler for PlanModeResolveTool {
async fn call(&self, ctx: &AgentContext, args: Value) -> anyhow::Result<Value> {
let plan_id = args
.get("plan_id")
.and_then(|v| v.as_str())
.ok_or_else(|| anyhow::anyhow!("plan_mode_resolve requires `plan_id`"))?
.to_string();
let decision_str = args
.get("decision")
.and_then(|v| v.as_str())
.ok_or_else(|| anyhow::anyhow!("plan_mode_resolve requires `decision`"))?;
let decision = match decision_str {
"approve" => PlanApprovalDecision::Approve,
"reject" => {
let reason = args
.get("reason")
.and_then(|v| v.as_str())
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
.ok_or_else(|| {
anyhow::anyhow!("plan_mode_resolve(decision=reject) requires `reason`")
})?;
PlanApprovalDecision::Reject { reason }
}
other => {
return Err(anyhow::anyhow!(
"plan_mode_resolve: unknown decision `{other}` (expected approve|reject)"
));
}
};
let resolved = ctx.plan_approval_registry.resolve(&plan_id, decision);
if !resolved {
return Err(anyhow::anyhow!(
"no pending plan_mode approval for plan_id={plan_id}"
));
}
Ok(json!({ "resolved": true, "plan_id": plan_id }))
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::session::SessionManager;
use nexo_broker::AnyBroker;
use nexo_config::types::agents::{
AgentConfig, AgentRuntimeConfig, DreamingYamlConfig, HeartbeatConfig, ModelConfig,
OutboundAllowlistConfig, WorkspaceGitConfig,
};
use std::sync::Arc;
fn ctx_interactive() -> AgentContext {
let cfg = AgentConfig {
id: "a".into(),
model: ModelConfig {
provider: "x".into(),
model: "y".into(),
},
plugins: Vec::new(),
heartbeat: HeartbeatConfig::default(),
config: AgentRuntimeConfig::default(),
system_prompt: String::new(),
workspace: String::new(),
skills: Vec::new(),
skills_dir: "./skills".into(),
skill_overrides: Default::default(),
transcripts_dir: String::new(),
dreaming: DreamingYamlConfig::default(),
workspace_git: WorkspaceGitConfig::default(),
tool_rate_limits: None,
tool_args_validation: None,
extra_docs: Vec::new(),
inbound_bindings: Vec::new(),
allowed_tools: Vec::new(),
sender_rate_limit: None,
allowed_delegates: Vec::new(),
accept_delegates_from: Vec::new(),
description: String::new(),
google_auth: None,
credentials: Default::default(),
link_understanding: serde_json::Value::Null,
web_search: serde_json::Value::Null,
pairing_policy: serde_json::Value::Null,
language: None,
outbound_allowlist: OutboundAllowlistConfig::default(),
context_optimization: None,
dispatch_policy: Default::default(),
plan_mode: Default::default(),
remote_triggers: Vec::new(),
lsp: nexo_config::types::lsp::LspPolicy::default(),
config_tool: nexo_config::types::config_tool::ConfigToolPolicy::default(),
team: nexo_config::types::team::TeamPolicy::default(),
proactive: Default::default(),
repl: Default::default(),
auto_dream: None,
assistant_mode: None,
away_summary: None,
brief: None,
channels: None,
auto_approve: false,
extract_memories: None,
event_subscribers: Vec::new(),
tenant_id: None,
extensions_config: std::collections::BTreeMap::new(),
active: true,
};
AgentContext::new(
"a",
Arc::new(cfg),
AnyBroker::local(),
Arc::new(SessionManager::new(std::time::Duration::from_secs(60), 8)),
)
.with_inbound_origin("whatsapp", "default", "+1234")
}
fn ctx_non_interactive() -> AgentContext {
let mut c = ctx_interactive();
c.inbound_origin = None;
c
}
#[tokio::test]
async fn enter_plan_mode_flips_state_on() {
let ctx = ctx_interactive();
let tool = EnterPlanModeTool;
let out = tool
.call(&ctx, json!({"reason": "explore auth flow"}))
.await
.unwrap();
assert_eq!(out["entered_plan_mode"], true);
assert_eq!(out["already_in_plan_mode"], false);
assert!(ctx.plan_mode.read().await.is_on());
}
#[tokio::test]
async fn enter_plan_mode_is_idempotent() {
let ctx = ctx_interactive();
let tool = EnterPlanModeTool;
let _ = tool.call(&ctx, json!({})).await.unwrap();
let snap1 = match &*ctx.plan_mode.read().await {
PlanModeState::On { entered_at, .. } => *entered_at,
_ => panic!("expected On"),
};
let _ = tool
.call(&ctx, json!({"reason": "different"}))
.await
.unwrap();
let snap2 = match &*ctx.plan_mode.read().await {
PlanModeState::On { entered_at, .. } => *entered_at,
_ => panic!("expected On"),
};
assert_eq!(snap1, snap2, "entered_at should be sticky");
}
#[tokio::test]
async fn enter_plan_mode_rejects_sub_agent() {
let ctx = ctx_non_interactive();
let tool = EnterPlanModeTool;
let err = tool.call(&ctx, json!({})).await.unwrap_err().to_string();
assert!(
err.contains("unavailable") || err.contains("sub-agent"),
"unexpected error: {err}"
);
assert!(ctx.plan_mode.read().await.is_off());
}
#[tokio::test]
async fn exit_plan_mode_unlocks_state() {
let ctx = ctx_interactive();
EnterPlanModeTool.call(&ctx, json!({})).await.unwrap();
let out = ExitPlanModeTool
.call(
&ctx,
json!({"final_plan": "1. Read auth.rs\n2. Add OAuth handler"}),
)
.await
.unwrap();
assert_eq!(out["exited_plan_mode"], true);
assert!(ctx.plan_mode.read().await.is_off());
}
#[tokio::test]
async fn exit_plan_mode_rejects_oversize_plan() {
let ctx = ctx_interactive();
EnterPlanModeTool.call(&ctx, json!({})).await.unwrap();
let big = "x".repeat(PLAN_MODE_MAX_PLAN_BYTES + 1);
let err = ExitPlanModeTool
.call(&ctx, json!({"final_plan": big}))
.await
.unwrap_err()
.to_string();
assert!(err.contains("PlanTooLarge"), "got: {err}");
assert!(ctx.plan_mode.read().await.is_on());
}
#[tokio::test]
async fn exit_plan_mode_rejects_outside_plan_mode() {
let ctx = ctx_interactive();
let err = ExitPlanModeTool
.call(&ctx, json!({"final_plan": "trivial"}))
.await
.unwrap_err()
.to_string();
assert!(err.contains("outside plan mode"), "got: {err}");
}
#[tokio::test]
async fn exit_plan_mode_requires_final_plan() {
let ctx = ctx_interactive();
EnterPlanModeTool.call(&ctx, json!({})).await.unwrap();
let err = ExitPlanModeTool
.call(&ctx, json!({}))
.await
.unwrap_err()
.to_string();
assert!(err.contains("final_plan"), "got: {err}");
}
fn ctx_with_approval(timeout_secs: u64) -> AgentContext {
let cfg = AgentConfig {
id: "a".into(),
model: ModelConfig {
provider: "x".into(),
model: "y".into(),
},
plugins: Vec::new(),
heartbeat: HeartbeatConfig::default(),
config: AgentRuntimeConfig::default(),
system_prompt: String::new(),
workspace: String::new(),
skills: Vec::new(),
skills_dir: "./skills".into(),
skill_overrides: Default::default(),
transcripts_dir: String::new(),
dreaming: DreamingYamlConfig::default(),
workspace_git: WorkspaceGitConfig::default(),
tool_rate_limits: None,
tool_args_validation: None,
extra_docs: Vec::new(),
inbound_bindings: Vec::new(),
allowed_tools: Vec::new(),
sender_rate_limit: None,
allowed_delegates: Vec::new(),
accept_delegates_from: Vec::new(),
description: String::new(),
google_auth: None,
credentials: Default::default(),
link_understanding: serde_json::Value::Null,
web_search: serde_json::Value::Null,
pairing_policy: serde_json::Value::Null,
language: None,
outbound_allowlist: OutboundAllowlistConfig::default(),
context_optimization: None,
dispatch_policy: Default::default(),
plan_mode: nexo_config::types::plan_mode::PlanModePolicy {
enabled: true,
auto_enter_on_destructive: false,
default_active: None,
approval_timeout_secs: timeout_secs,
require_approval: true,
},
remote_triggers: Vec::new(),
lsp: nexo_config::types::lsp::LspPolicy::default(),
config_tool: nexo_config::types::config_tool::ConfigToolPolicy::default(),
team: nexo_config::types::team::TeamPolicy::default(),
proactive: Default::default(),
repl: Default::default(),
auto_dream: None,
assistant_mode: None,
away_summary: None,
brief: None,
channels: None,
auto_approve: false,
extract_memories: None,
event_subscribers: Vec::new(),
tenant_id: None,
extensions_config: std::collections::BTreeMap::new(),
active: true,
};
AgentContext::new(
"a",
Arc::new(cfg),
AnyBroker::local(),
Arc::new(SessionManager::new(std::time::Duration::from_secs(60), 8)),
)
.with_inbound_origin("whatsapp", "default", "+1234")
}
#[tokio::test]
async fn exit_plan_mode_with_approval_then_approve_unlocks() {
let ctx = ctx_with_approval(5);
EnterPlanModeTool.call(&ctx, json!({})).await.unwrap();
let ctx_for_task = ctx.clone();
let exit_handle = tokio::spawn(async move {
ExitPlanModeTool
.call(
&ctx_for_task,
json!({"final_plan": "1. read auth.rs\n2. patch"}),
)
.await
});
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
let plan_id = {
let reg = ctx.plan_approval_registry.clone();
let mut found = None;
for entry in reg.pending.iter() {
found = Some(entry.key().clone());
break;
}
found.expect("expected exactly one pending plan_id")
};
let resolve = PlanModeResolveTool
.call(
&ctx,
json!({"plan_id": plan_id.clone(), "decision": "approve"}),
)
.await
.unwrap();
assert_eq!(resolve["resolved"], true);
let exit_result = exit_handle.await.unwrap().unwrap();
assert_eq!(exit_result["exited_plan_mode"], true);
assert_eq!(exit_result["approval_required"], true);
assert_eq!(exit_result["plan_id"], plan_id);
assert!(ctx.plan_mode.read().await.is_off());
}
#[tokio::test]
async fn exit_plan_mode_with_approval_then_reject_keeps_state_on() {
let ctx = ctx_with_approval(5);
EnterPlanModeTool.call(&ctx, json!({})).await.unwrap();
let ctx_for_task = ctx.clone();
let exit_handle = tokio::spawn(async move {
ExitPlanModeTool
.call(&ctx_for_task, json!({"final_plan": "trivial plan"}))
.await
});
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
let plan_id = {
let reg = ctx.plan_approval_registry.clone();
let mut found = None;
for entry in reg.pending.iter() {
found = Some(entry.key().clone());
break;
}
found.unwrap()
};
PlanModeResolveTool
.call(
&ctx,
json!({
"plan_id": plan_id,
"decision": "reject",
"reason": "scope too small — research more"
}),
)
.await
.unwrap();
let err = exit_handle.await.unwrap().unwrap_err().to_string();
assert!(err.contains("Plan rejected by operator"), "got: {err}");
assert!(err.contains("scope too small"), "got: {err}");
assert!(ctx.plan_mode.read().await.is_on());
}
#[tokio::test]
async fn exit_plan_mode_with_approval_times_out() {
let ctx = ctx_with_approval(1); EnterPlanModeTool.call(&ctx, json!({})).await.unwrap();
let err = ExitPlanModeTool
.call(&ctx, json!({"final_plan": "trivial"}))
.await
.unwrap_err()
.to_string();
assert!(err.contains("ApprovalTimeout"), "got: {err}");
assert!(ctx.plan_mode.read().await.is_on());
}
#[tokio::test]
async fn plan_mode_resolve_unknown_id_errors() {
let ctx = ctx_interactive();
let err = PlanModeResolveTool
.call(
&ctx,
json!({"plan_id": "deadbeef-no-such-id", "decision": "approve"}),
)
.await
.unwrap_err()
.to_string();
assert!(err.contains("no pending"), "got: {err}");
}
#[tokio::test]
async fn plan_mode_resolve_reject_requires_reason() {
let ctx = ctx_interactive();
let err = PlanModeResolveTool
.call(&ctx, json!({"plan_id": "x", "decision": "reject"}))
.await
.unwrap_err()
.to_string();
assert!(err.contains("requires `reason`"), "got: {err}");
}
#[test]
fn parse_approve_bare() {
let cmd = parse_plan_mode_approval("[plan-mode] approve plan_id=01J7HVK9MWXYZ").unwrap();
assert_eq!(
cmd,
PlanModeApprovalCommand::Approve {
plan_id: "01J7HVK9MWXYZ".into()
}
);
}
#[test]
fn parse_reject_with_reason() {
let cmd =
parse_plan_mode_approval("[plan-mode] reject plan_id=abc123 reason=needs more thought")
.unwrap();
assert_eq!(
cmd,
PlanModeApprovalCommand::Reject {
plan_id: "abc123".into(),
reason: Some("needs more thought".into()),
}
);
}
#[test]
fn parse_reject_no_reason() {
let cmd = parse_plan_mode_approval("[plan-mode] reject plan_id=abc123").unwrap();
assert_eq!(
cmd,
PlanModeApprovalCommand::Reject {
plan_id: "abc123".into(),
reason: None,
}
);
}
#[test]
fn parse_allows_leading_trailing_whitespace() {
let cmd = parse_plan_mode_approval(" [plan-mode] approve plan_id=foo ").unwrap();
assert_eq!(
cmd,
PlanModeApprovalCommand::Approve {
plan_id: "foo".into()
}
);
}
#[test]
fn parse_rejects_extra_text() {
assert!(parse_plan_mode_approval("xx [plan-mode] approve plan_id=foo").is_none());
assert!(parse_plan_mode_approval("[plan-mode] approve plan_id=foo yy").is_none());
}
#[test]
fn parse_rejects_malformed() {
assert!(parse_plan_mode_approval("[plan-mode] plan_id=foo").is_none());
assert!(parse_plan_mode_approval("[plan-mode] approve").is_none());
assert!(parse_plan_mode_approval("not a command").is_none());
assert!(parse_plan_mode_approval("").is_none());
}
#[test]
fn parse_applies_to_empty_body() {
assert!(parse_plan_mode_approval("").is_none());
}
}