plan mode: /plan makes bash/write/edit read-only; exit_plan shows the full plan for approval

This commit is contained in:
hermes committed 2026-11-14 10:43:07 +00:00
1 parent 7e0031da2f
commit 1c3b861fde
7 files changed
+135 -3

No files matched your search

+31
View File
@@ -93,6 +93,16 @@ pub async fn gate_why(cx: &ToolCtx, req: crate::permit::Request) -> Result<(), S
use crate::danger::{Verdict, classify};
use crate::permit::Decision;
const DENIED: &str = "denied by the user; do not retry, ask what to do instead";
if matches!(req.tool.as_str(), "bash" | "write" | "edit")
&& cx
.state
.allow
.lock()
.unwrap_or_else(|e| e.into_inner())
.plan_on()
{
return Err("blocked by plan mode: read-only until the plan is approved. Explore with read/grep/ls, then call exit_plan with the full plan.".into());
}
let Some(ask) = cx.state.permit.get() else {
return Ok(());
};
@@ -263,6 +273,27 @@ mod tests {
assert!(d.is_error && d.content.contains("denied"));
}
#[tokio::test]
async fn plan_mode_blocks_writes_even_without_prompt() {
let c = cx();
c.state.allow.lock().unwrap().set_plan(true);
let e = gate_why(
&c,
crate::permit::request("bash", &json!({"command":"touch x"})),
)
.await;
assert!(e.unwrap_err().contains("plan mode"));
c.state.allow.lock().unwrap().set_plan(false);
assert!(
gate_why(
&c,
crate::permit::request("bash", &json!({"command":"touch x"}))
)
.await
.is_ok()
);
}
#[tokio::test]
async fn auto_mode_blocks_allows_judges_without_prompting() {
use crate::danger::Judge;