plan mode (/plan, exit_plan shows full plan) #187
No files matched your search
@@ -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<Spawner>,
|
||||
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()))
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user