diff --git a/crates/hx-ai/src/claude_cli.rs b/crates/hx-ai/src/claude_cli.rs index d1c8dd2..416f66b 100644 --- a/crates/hx-ai/src/claude_cli.rs +++ b/crates/hx-ai/src/claude_cli.rs @@ -25,6 +25,14 @@ pub type Spawner = Arc< + Sync, >; +/// hx plan mode is on: claude runs with `--permission-mode plan`, else its `ExitPlanMode` is rejected. +// ponytail: process-wide flag; make it per-provider if two claude providers ever run at once. +static PLAN: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); + +pub fn set_plan(on: bool) { + PLAN.store(on, std::sync::atomic::Ordering::Relaxed); +} + pub struct ClaudeCli { spawner: Option, bin: String, @@ -205,6 +213,9 @@ impl Provider for ClaudeCli { ]); } } + if PLAN.load(std::sync::atomic::Ordering::Relaxed) { + cmd.args(["--permission-mode", "plan"]); + } cmd.args(&self.args) .arg("--") .arg(prompt(&req.messages, sid.is_some())) diff --git a/crates/hx-core/src/permit.rs b/crates/hx-core/src/permit.rs index ef5a011..2d176ae 100644 --- a/crates/hx-core/src/permit.rs +++ b/crates/hx-core/src/permit.rs @@ -390,6 +390,7 @@ impl Allow { pub fn set_plan(&mut self, on: bool) { self.plan = on; + hx_ai::claude_cli::set_plan(on); } pub fn auto_on(&self) -> bool { diff --git a/crates/hx-tui/src/lib.rs b/crates/hx-tui/src/lib.rs index 96de950..0e7da51 100644 --- a/crates/hx-tui/src/lib.rs +++ b/crates/hx-tui/src/lib.rs @@ -1709,6 +1709,21 @@ async fn submit(app: &mut App, mut line: String, c: &Ctx<'_>) { ))); line = r.prompt; } + // a prompt starting with the word `plan` turns plan mode on + if line + .split_whitespace() + .next() + .is_some_and(|w| w.eq_ignore_ascii_case("plan")) + { + let mut al = app.state.allow.lock().unwrap_or_else(|e| e.into_inner()); + if !al.plan_on() { + al.set_plan(true); + drop(al); + app.t.push(Item::Info( + "plan on (prompt starts with `plan`): read-only until the plan is approved".into(), + )); + } + } if app .state .allow