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

+5
View File
@@ -82,6 +82,11 @@ pub fn builtins(models: &[&str]) -> Vec<CmdSpec> {
"auto permissions: refuse dangerous calls, run safe ones",
Enum(vec!["on".into(), "off".into(), "log".into()]),
),
b(
"plan",
"plan mode: read-only research, then the full plan for approval",
Enum(vec!["on".into(), "off".into()]),
),
b("yolo", "toggle: run every tool without asking", None),
b(
"sandbox",
+11
View File
@@ -328,6 +328,8 @@ pub struct Allow {
all_edits: bool,
yolo: bool,
auto: bool,
/// Plan mode: read-only until the user approves a plan.
plan: bool,
/// Last calls auto mode refused (newest last), for `/auto`.
blocks: Vec<String>,
file: Option<PathBuf>,
@@ -345,6 +347,7 @@ impl Allow {
all_edits: false,
yolo: false,
auto: false,
plan: false,
blocks: Vec::new(),
file: Some(file),
}
@@ -381,6 +384,14 @@ impl Allow {
self.yolo
}
pub fn plan_on(&self) -> bool {
self.plan
}
pub fn set_plan(&mut self, on: bool) {
self.plan = on;
}
pub fn auto_on(&self) -> bool {
self.auto
}
+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;