TUI: permission prompt, /diff review, /stats dashboard, lens/context/MCP side panel
ci / check (pull_request) Canceled after 0s
ci / check (push) Canceled after 0s

This commit is contained in:
hermes authored and Johannes Kresner committed 2026-10-02 23:31:55 +02:00
1 parent 4a8e920ab8
commit 5fd7044a2f
15 files changed
+945 -2

No files matched your search

+81
View File
@@ -105,6 +105,34 @@ impl Registry {
if let Err(e) = validate(&t.spec().input_schema, &args) {
return ToolResult::err(e);
}
if crate::permit::gated(name)
&& 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())
.has(&req.rule);
if !known {
let rule = req.rule.clone();
match ask(req).await {
crate::permit::Decision::Once => {}
crate::permit::Decision::Always => cx
.state
.allow
.lock()
.unwrap_or_else(|e| e.into_inner())
.add(&rule),
crate::permit::Decision::Deny => {
return ToolResult::err(
"denied by the user; do not retry, ask what to do instead",
);
}
}
}
}
t.call(args, cx).await
}
@@ -149,6 +177,59 @@ mod tests {
}
}
#[tokio::test]
async fn gate_asks_remembers_and_denies() {
use crate::permit::{Decision, Permit};
struct Nop;
#[async_trait]
impl Tool for Nop {
fn spec(&self) -> ToolSpec {
ToolSpec {
name: "bash".into(),
description: String::new(),
input_schema: json!({"type":"object"}),
}
}
async fn call(&self, _: Value, _: &ToolCtx) -> ToolResult {
ToolResult::ok("ran")
}
}
let mut r = Registry::default();
r.add(Nop);
let c = cx();
// no frontend: runs
assert_eq!(
r.call("bash", json!({"command": "ls"}), &c).await.content,
"ran"
);
let asked = Arc::new(std::sync::Mutex::new(0));
let (n, next) = (
asked.clone(),
Arc::new(std::sync::Mutex::new(Decision::Always)),
);
let p: Permit = Arc::new(move |_| {
*n.lock().unwrap() += 1;
let d = *next.lock().unwrap();
*next.lock().unwrap() = Decision::Deny;
Box::pin(async move { d })
});
let _ = c.state.permit.set(p);
assert_eq!(
r.call("bash", json!({"command": "ls -l"}), &c)
.await
.content,
"ran"
);
// rule bash:ls remembered: no second prompt
assert_eq!(
r.call("bash", json!({"command": "ls"}), &c).await.content,
"ran"
);
assert_eq!(*asked.lock().unwrap(), 1);
let d = r.call("bash", json!({"command": "rm x"}), &c).await;
assert!(d.is_error && d.content.contains("denied"));
}
#[tokio::test]
async fn registry_validation_parallel() {
let mut r = Registry::default();