permissions: auto mode refuses dangerous calls (rules + cheap-model judge)

This commit is contained in:
hermes committed 2026-11-12 13:44:25 +00:00
1 parent 63b286efaf
commit 02144d4176
11 files changed
+791 -30

No files matched your search

+39 -1
View File
@@ -59,6 +59,8 @@ pub struct Setup {
pub mouse: bool,
/// No permission prompts (`--yolo`).
pub yolo: bool,
/// Auto permission mode from the start (`--auto`, `permissions = "auto"`).
pub auto: bool,
/// MCP servers for the side panel: (name, connected).
pub mcp: Vec<(String, bool)>,
}
@@ -269,6 +271,7 @@ pub async fn run(setup: Setup) -> std::io::Result<()> {
open_sessions,
mouse,
yolo,
auto,
mcp,
} = setup;
// asked before the alternate screen; terminals that do not answer return false
@@ -328,6 +331,13 @@ pub async fn run(setup: Setup) -> std::io::Result<()> {
.allow
.lock()
.unwrap_or_else(|e| e.into_inner()) = hx_core::permit::Allow::load(&cwd);
agent
.cx
.state
.allow
.lock()
.unwrap_or_else(|e| e.into_inner())
.set_auto(auto && !yolo);
let mut app = App {
t: Transcript::default(),
ed: Editor::default(),
@@ -1315,7 +1325,7 @@ async fn submit(app: &mut App, mut line: String, c: &Ctx<'_>) {
let (c, arg) = cmd
.split_once(' ')
.map_or((cmd, ""), |(a, b)| (a, b.trim()));
if app.busy && !matches!(c, "quit" | "btw" | "yolo") {
if app.busy && !matches!(c, "quit" | "btw" | "yolo" | "auto") {
app.t.push(Item::Error("busy; esc to abort first".into()));
return;
}
@@ -1439,6 +1449,34 @@ async fn submit(app: &mut App, mut line: String, c: &Ctx<'_>) {
Err(e) => Item::Error(e),
});
}
"auto" => {
let mut al = app.state.allow.lock().unwrap_or_else(|e| e.into_inner());
let m = match arg {
"log" => {
let b = al.blocks();
if b.is_empty() {
"auto: nothing blocked yet".to_string()
} else {
format!("auto blocked (newest last):\n{}", b.join("\n"))
}
}
_ => {
let on = match arg {
"on" => true,
"off" => false,
_ => !al.auto_on(),
};
al.set_auto(on);
if on {
"auto on: dangerous calls are refused, routine ones run, unclear ones are judged or asked (/auto log lists blocks)".into()
} else {
"auto off: everything unknown asks".into()
}
}
};
drop(al);
app.t.push(Item::Info(m));
}
"yolo" => {
let on = app
.state