Merge pull request 'permit: allow all edits per session, /yolo' (#131) from feat/allow-edits-yolo into main

This commit was merged in pull request #131.
This commit is contained in:
hermes committed 2026-10-06 12:56:59 +00:00
commit 8669c50fb9
4 files changed
+29 -5

No files matched your search

+1
View File
@@ -65,6 +65,7 @@ pub fn builtins(models: &[&str]) -> Vec<CmdSpec> {
b("new", "start a new session (old one stays resumable)", None), b("new", "start a new session (old one stays resumable)", None),
b("clear", "alias of /new", None), b("clear", "alias of /new", None),
b("sessions", "browse, resume, delete sessions", None), b("sessions", "browse, resume, delete sessions", None),
b("yolo", "toggle: run every tool without asking", None),
b("lsp", "language server status", None), b("lsp", "language server status", None),
b("copy", "copy the last answer to the clipboard", None), b("copy", "copy the last answer to the clipboard", None),
b("usage", "subscription limits, resets, credits", None), b("usage", "subscription limits, resets, credits", None),
+13 -4
View File
@@ -104,7 +104,7 @@ fn compound(cmd: &str) -> bool {
/// Rule for "allow always". Bash: `bash:<command words> *` (first word, plus the subcommand when /// Rule for "allow always". Bash: `bash:<command words> *` (first word, plus the subcommand when
/// there is one, e.g. `bash:cargo test *`); risky or compound commands store the exact command, or /// 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"). /// 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. // 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 { pub fn request(tool: &str, args: &serde_json::Value) -> Request {
let s = |k: &str| args[k].as_str().unwrap_or_default().to_string(); let s = |k: &str| args[k].as_str().unwrap_or_default().to_string();
@@ -112,7 +112,7 @@ pub fn request(tool: &str, args: &serde_json::Value) -> Request {
return Request { return Request {
tool: tool.into(), tool: tool.into(),
detail: s("path"), detail: s("path"),
rule: tool.into(), rule: String::new(),
}; };
} }
let cmd = s("command"); let cmd = s("command");
@@ -164,6 +164,7 @@ fn glob(pat: &str, s: &str) -> bool {
pub struct Allow { pub struct Allow {
rules: HashSet<String>, rules: HashSet<String>,
all_edits: bool, all_edits: bool,
yolo: bool,
file: Option<PathBuf>, file: Option<PathBuf>,
} }
@@ -177,13 +178,14 @@ impl Allow {
Self { Self {
rules, rules,
all_edits: false, all_edits: false,
yolo: false,
file: Some(file), file: Some(file),
} }
} }
/// Is this request covered by a stored rule? `bash:cargo test *` also covers a bare `cargo test`. /// Is this request covered by a stored rule? `bash:cargo test *` also covers a bare `cargo test`.
pub fn allows(&self, r: &Request) -> bool { pub fn allows(&self, r: &Request) -> bool {
if self.all_edits && matches!(r.tool.as_str(), "write" | "edit") { if self.yolo || self.all_edits && matches!(r.tool.as_str(), "write" | "edit") {
return true; return true;
} }
if r.tool != "bash" { if r.tool != "bash" {
@@ -198,6 +200,12 @@ impl Allow {
.any(|p| glob(p, &r.detail) || p.strip_suffix(" *").is_some_and(|b| b == r.detail)) .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. /// Allow every write/edit until the session ends.
pub fn allow_edits(&mut self) { pub fn allow_edits(&mut self) {
self.all_edits = true; self.all_edits = true;
@@ -243,7 +251,7 @@ mod tests {
assert_eq!(bash("ls -l").rule, "bash:ls *"); assert_eq!(bash("ls -l").rule, "bash:ls *");
assert_eq!(bash("rm -rf target").rule, "bash:rm -rf target"); assert_eq!(bash("rm -rf target").rule, "bash:rm -rf target");
assert_eq!(bash("cargo test && rm -rf ~").rule, ""); 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")); assert!(gated("bash") && !gated("read"));
} }
@@ -281,5 +289,6 @@ mod tests {
assert!(!a.allows(&e)); assert!(!a.allows(&e));
a.allow_edits(); a.allow_edits();
assert!(a.allows(&e) && !a.allows(&bash("make"))); assert!(a.allows(&e) && !a.allows(&bash("make")));
assert!(a.toggle_yolo() && a.allows(&bash("rm -rf /")) && !a.toggle_yolo());
} }
} }
+14
View File
@@ -1169,6 +1169,20 @@ async fn submit(app: &mut App, mut line: String, c: &Ctx<'_>) {
let l = skills_list(&app.specs, &dirs); let l = skills_list(&app.specs, &dirs);
show(app, "skills", l); 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" => { "lsp" => {
let st = lsp_status().await; let st = lsp_status().await;
let l = if st.is_empty() { let l = if st.is_empty() {
+1 -1
View File
@@ -67,7 +67,7 @@ check("tab completion", "es.md")
send(b"\x15") # ctrl-u send(b"\x15") # ctrl-u
send(b"make hello.txt"); send(b"\r", 2) send(b"make hello.txt"); send(b"\r", 2)
check("permission prompt", "permission") 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) send(b"y", 2)
check("second prompt for bash", "allow always: sort *") check("second prompt for bash", "allow always: sort *")
send(b"y", 3) send(b"y", 3)