From 5eee541e62383ac44c0ef466d1b869e49cbd44e4 Mon Sep 17 00:00:00 2001 From: hermes Date: Tue, 6 Oct 2026 12:41:23 +0000 Subject: [PATCH 1/2] permit: allow all edits per session, drop per-file always, add /yolo --- crates/hx-core/src/command.rs | 1 + crates/hx-core/src/lib.rs | 2 ++ crates/hx-core/src/permit.rs | 31 ++++++++++++++++++++++++++++--- crates/hx-core/src/tool.rs | 25 +++++++++++++++++-------- crates/hx-tui/src/lib.rs | 10 ++++++++++ crates/hx-tui/src/permit_view.rs | 7 +++++++ 6 files changed, 65 insertions(+), 11 deletions(-) diff --git a/crates/hx-core/src/command.rs b/crates/hx-core/src/command.rs index bdff3f9..850a1bd 100644 --- a/crates/hx-core/src/command.rs +++ b/crates/hx-core/src/command.rs @@ -60,6 +60,7 @@ pub fn builtins(models: &[&str]) -> Vec { b("new", "start a new session (old one stays resumable)", None), b("clear", "alias of /new", None), b("sessions", "browse, resume, delete sessions", None), + b("yolo", "toggle: run every tool without asking", None), b("lsp", "language server status", None), b("usage", "subscription limits, resets, credits", None), b( diff --git a/crates/hx-core/src/lib.rs b/crates/hx-core/src/lib.rs index 8bf0f51..af3bfb8 100644 --- a/crates/hx-core/src/lib.rs +++ b/crates/hx-core/src/lib.rs @@ -59,6 +59,8 @@ pub struct State { pub permit: std::sync::OnceLock, /// Rules the user allowed for good. pub allow: Mutex, + /// Serializes permission prompts: parallel tool calls are asked one by one. + pub asking: tokio::sync::Mutex<()>, /// Every write/edit this session, for `/review`. pub edits: Mutex>, /// Same for multiple-choice questions. diff --git a/crates/hx-core/src/permit.rs b/crates/hx-core/src/permit.rs index 93bc467..e15fcb8 100644 --- a/crates/hx-core/src/permit.rs +++ b/crates/hx-core/src/permit.rs @@ -77,6 +77,8 @@ pub struct Request { pub enum Decision { Once, Always, + /// All write/edit calls for the rest of this session (not persisted). + Edits, Deny, } @@ -102,7 +104,7 @@ fn compound(cmd: &str) -> bool { /// Rule for "allow always". Bash: `bash: *` (first word, plus the subcommand when /// there is one, e.g. `bash:cargo test *`); risky or compound commands store the exact command, or /// nothing at all for compound ones (empty rule = the prompt offers no "always"). -/// File tools are covered as a whole by the tool name. +/// File tools have no rule (the prompt offers `allow all edits this session` instead). // ponytail: patterns are `*` globs on the full command line; add argument-aware rules if needed. pub fn request(tool: &str, args: &serde_json::Value) -> Request { let s = |k: &str| args[k].as_str().unwrap_or_default().to_string(); @@ -110,7 +112,7 @@ pub fn request(tool: &str, args: &serde_json::Value) -> Request { return Request { tool: tool.into(), detail: s("path"), - rule: tool.into(), + rule: String::new(), }; } let cmd = s("command"); @@ -161,6 +163,8 @@ fn glob(pat: &str, s: &str) -> bool { #[derive(Default)] pub struct Allow { rules: HashSet, + all_edits: bool, + yolo: bool, file: Option, } @@ -173,12 +177,17 @@ impl Allow { .unwrap_or_default(); Self { rules, + all_edits: false, + yolo: false, file: Some(file), } } /// Is this request covered by a stored rule? `bash:cargo test *` also covers a bare `cargo test`. pub fn allows(&self, r: &Request) -> bool { + if self.yolo || self.all_edits && matches!(r.tool.as_str(), "write" | "edit") { + return true; + } if r.tool != "bash" { return self.rules.contains(&r.rule); } @@ -191,6 +200,17 @@ impl Allow { .any(|p| glob(p, &r.detail) || p.strip_suffix(" *").is_some_and(|b| b == r.detail)) } + /// Toggle: allow everything (not persisted); returns the new state. + pub fn toggle_yolo(&mut self) -> bool { + self.yolo = !self.yolo; + self.yolo + } + + /// Allow every write/edit until the session ends. + pub fn allow_edits(&mut self) { + self.all_edits = true; + } + /// Remember a rule; the file is best effort (the rule holds for this session either way). pub fn add(&mut self, rule: &str) { if rule.is_empty() { @@ -231,7 +251,7 @@ mod tests { assert_eq!(bash("ls -l").rule, "bash:ls *"); assert_eq!(bash("rm -rf target").rule, "bash:rm -rf target"); assert_eq!(bash("cargo test && rm -rf ~").rule, ""); - assert_eq!(request("edit", &json!({"path": "a.rs"})).rule, "edit"); + assert_eq!(request("edit", &json!({"path": "a.rs"})).rule, ""); assert!(gated("bash") && !gated("read")); } @@ -265,5 +285,10 @@ mod tests { assert!(Allow::load(d.path()).allows(&bash("cargo test -q"))); a.add(""); assert!(!a.allows(&bash(""))); + let e = request("edit", &json!({"path": "a.rs"})); + assert!(!a.allows(&e)); + a.allow_edits(); + assert!(a.allows(&e) && !a.allows(&bash("make"))); + assert!(a.toggle_yolo() && a.allows(&bash("rm -rf /")) && !a.toggle_yolo()); } } diff --git a/crates/hx-core/src/tool.rs b/crates/hx-core/src/tool.rs index fdb690c..0157472 100644 --- a/crates/hx-core/src/tool.rs +++ b/crates/hx-core/src/tool.rs @@ -109,15 +109,18 @@ impl Registry { && let Some(ask) = cx.state.permit.get() { let req = crate::permit::request(name, &args); - let known = cx - .state - .allow - .lock() - .unwrap_or_else(|e| e.into_inner()) - .allows(&req); - if !known { + let allowed = || { + cx.state + .allow + .lock() + .unwrap_or_else(|e| e.into_inner()) + .allows(&req) + }; + // One prompt at a time; re-check after waiting, an earlier answer may cover this call. + let _turn = cx.state.asking.lock().await; + if !allowed() { let rule = req.rule.clone(); - match ask(req).await { + match ask(req.clone()).await { crate::permit::Decision::Once => {} crate::permit::Decision::Always => cx .state @@ -125,6 +128,12 @@ impl Registry { .lock() .unwrap_or_else(|e| e.into_inner()) .add(&rule), + crate::permit::Decision::Edits => cx + .state + .allow + .lock() + .unwrap_or_else(|e| e.into_inner()) + .allow_edits(), crate::permit::Decision::Deny => { return ToolResult::err( "denied by the user; do not retry, ask what to do instead", diff --git a/crates/hx-tui/src/lib.rs b/crates/hx-tui/src/lib.rs index a2abbe3..55da172 100644 --- a/crates/hx-tui/src/lib.rs +++ b/crates/hx-tui/src/lib.rs @@ -1027,6 +1027,16 @@ async fn submit(app: &mut App, mut line: String, c: &Ctx<'_>) { let l = skills_list(&app.specs, &dirs); show(app, "skills", l); } + "yolo" => { + let on = app + .state + .allow + .lock() + .unwrap_or_else(|e| e.into_inner()) + .toggle_yolo(); + let m = if on { "yolo on: nothing asks" } else { "yolo off" }; + app.t.push(Item::Info(m.into())); + } "lsp" => { let st = lsp_status().await; let l = if st.is_empty() { diff --git a/crates/hx-tui/src/permit_view.rs b/crates/hx-tui/src/permit_view.rs index d1714e0..81c30e4 100644 --- a/crates/hx-tui/src/permit_view.rs +++ b/crates/hx-tui/src/permit_view.rs @@ -33,6 +33,9 @@ impl Prompt { .unwrap_or(&self.req.rule); v.push((Decision::Always, format!("[a] allow always: {r}"))); } + if matches!(self.req.tool.as_str(), "write" | "edit") { + v.push((Decision::Edits, "[e] allow all edits this session".into())); + } v.push((Decision::Deny, "[n] deny".into())); v } @@ -41,6 +44,9 @@ impl Prompt { match k.code { KeyCode::Char('y' | 'Y') => Some(Decision::Once), KeyCode::Char('a' | 'A') if self.can_always() => Some(Decision::Always), + KeyCode::Char('e' | 'E') if matches!(self.req.tool.as_str(), "write" | "edit") => { + Some(Decision::Edits) + } KeyCode::Char('n' | 'N') | KeyCode::Esc => Some(Decision::Deny), KeyCode::Up | KeyCode::Left => { let n = self.opts().len(); @@ -60,6 +66,7 @@ impl Prompt { match d { Decision::Once => "allowed", Decision::Always => "allowed always", + Decision::Edits => "allowed all edits this session:", Decision::Deny => "denied", } } From b4e9f4da732ad334806b749a457b9bc2e8614c9a Mon Sep 17 00:00:00 2001 From: hermes Date: Tue, 6 Oct 2026 12:50:02 +0000 Subject: [PATCH 2/2] fmt; smoke test expects edits option on write prompt --- crates/hx-tui/src/lib.rs | 6 +++++- tests/tui_smoke.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/hx-tui/src/lib.rs b/crates/hx-tui/src/lib.rs index 55da172..5d4e2ee 100644 --- a/crates/hx-tui/src/lib.rs +++ b/crates/hx-tui/src/lib.rs @@ -1034,7 +1034,11 @@ async fn submit(app: &mut App, mut line: String, c: &Ctx<'_>) { .lock() .unwrap_or_else(|e| e.into_inner()) .toggle_yolo(); - let m = if on { "yolo on: nothing asks" } else { "yolo off" }; + let m = if on { + "yolo on: nothing asks" + } else { + "yolo off" + }; app.t.push(Item::Info(m.into())); } "lsp" => { diff --git a/tests/tui_smoke.py b/tests/tui_smoke.py index 4bf1a3d..14b3947 100644 --- a/tests/tui_smoke.py +++ b/tests/tui_smoke.py @@ -67,7 +67,7 @@ check("tab completion", "es.md") send(b"\x15") # ctrl-u send(b"make hello.txt"); send(b"\r", 2) check("permission prompt", "permission") -check("allow always rule", "allow always: write") +check("allow all edits option", "allow all edits this session") send(b"y", 2) check("second prompt for bash", "allow always: sort *") send(b"y", 3)