AnyBot/src/gate.rs

385 lines
24 KiB
Rust
Raw Normal View History

//! 核准關卡的規則: the part of a step's approval that is rules alone, out of the turn loop
//! (agent::spawn) so it can be read in one place and tested as a table. What safety.md's
//! 「每一步的關卡順序」 says, steps 6 and 8:
//!
//! - `by_kind` (step 6): what kind of step it is decides — the Mac's own apps (reading once per
//! app, writing once per app, sending every time), the screen (its own desktop free; looking
//! once; operating once per app; never AnyBot's own window), another computer's screen (seeing
//! and operating once each), the browser (reading a logged-in tab once), everything else by
//! tools::decide_on (commands and files).
//! - `always_ask` (step 8): what is asked every time whatever came before — a click on a target
//! that says paying, sending or deleting; mail and messages; AppleScript outside the sandbox.
//!
//! What stays in the loop: asking the person to turn computer tools or this computer on (steps
//! 3–5, they wait for an answer), and the 自動審核 model call (step 7). Engineering plan E9.
use crate::tools::{self, Decision};
/// 「一律允許」 for this computer's whole screen: what is offered when the desktop can't say
/// which app a step lands in (GNOME / KDE on Wayland never can; wlroots can't for a point).
pub const SCREEN_CONTROL_GRANT: &str = "computer:control";
const LOOKS: [&str; 3] = ["computer_use_screenshot", "computer_use_zoom", "computer_use_show"];
/// What a screen step on this computer asks: (the grant 「一律允許」 keeps, the question). Per app
/// when the desktop names it; for the screen as a whole when it can't — the question then says
/// so. (An empty grant there used to make every click, key and scroll ask with no 「一律允許」.)
pub fn screen_control_ask(app: Option<&str>, via: &str, what: &str) -> (String, String) {
match app.map(str::trim).filter(|a| !a.is_empty()) {
Some(a) => (format!("app:{a}"), format!("讓 {via} 看到「{a}」,並在其中點擊和輸入:{what}")),
None => (SCREEN_CONTROL_GRANT.to_string(), format!("讓 {via} 在這台電腦的螢幕上點擊和輸入:{what}\n(這個桌面看不出是哪個 App;一律允許後,這台電腦的螢幕操作不再逐步詢問,付款、刪除、送出這類動作仍會問。)")),
}
}
/// Where a step runs, as the rules need it.
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Place<'a> {
/// The bot's own desktop (the box).
OwnBox,
/// Another computer of the person's account (by its name).
Device(&'a str),
/// Anywhere else (this computer, an SSH computer…).
Elsewhere,
}
/// Step 6: the decision by what kind of step it is. `what` is the step in words (for the card),
/// `via` the bot's name, `app` finds the app a screen step aims at (computer::target_app: only
/// asked for an operating step on this computer's screen).
#[allow(clippy::too_many_arguments)]
pub fn by_kind(name: &str, args: &str, what: &str, via: &str, target: &tools::Target, place: Place, app: impl FnOnce() -> Option<String>, grants: &[String]) -> Decision {
let has = |g: &str| grants.iter().any(|x| x == g);
if crate::macapps::is_mac_tool(name) {
let app = crate::macapps::app_of(name);
return if crate::macapps::is_send(name) && name == crate::macapps::SEND_MESSAGE && has("messages:no-ask") {
Decision::Allow
} else if crate::macapps::is_send(name) {
Decision::Ask { reason: format!("用你的「{app}」{what}"), grant: String::new() }
} else if crate::macapps::is_write(name) {
let grant = format!("macapp-write:{app}");
if has(&grant) { Decision::Allow } else { Decision::Ask { reason: format!("讓 {via} 修改你的「{app}」:{what}"), grant } }
} else {
let grant = format!("macapp:{app}");
if has(&grant) || has(&format!("macapp-write:{app}")) { Decision::Allow } else { Decision::Ask { reason: format!("讓 {via} 讀取你的「{app}」:{what}"), grant } }
};
}
if crate::computer::is_computer_tool(name) {
if place == Place::OwnBox || name == "computer_use_check_permissions" {
return Decision::Allow;
}
let looks = LOOKS.contains(&name);
if let Place::Device(device) = place {
let grant = if looks { format!("device-see:{device}") } else { format!("device-control:{device}") };
return if has(&grant) { Decision::Allow } else { Decision::Ask { reason: format!("{}「{device}」的螢幕:{what}", if looks { "看" } else { "操作" }), grant } };
}
if looks {
return if has("computer:see") { Decision::Allow } else { Decision::Ask { reason: format!("看你的螢幕畫面:{what}"), grant: "computer:see".into() } };
}
let app = app();
if app.as_deref().is_some_and(|a| crate::computer::is_self_app(a, None)) {
return Decision::Deny("Bot 不能點擊或操作 AnyBot 自己的視窗或核准按鈕。".into());
}
let (grant, reason) = screen_control_ask(app.as_deref(), via, what);
return if has(SCREEN_CONTROL_GRANT) || has(&grant) { Decision::Allow } else { Decision::Ask { reason, grant } };
}
if crate::web::is_web_tool(name) {
return if name == "browser_read" && crate::web::read_needs_permission(args) && !has("browser:read") {
Decision::Ask { reason: "讀取你瀏覽器目前分頁的內容(包含已登入的頁面):目前的分頁".into(), grant: "browser:read".into() }
} else {
Decision::Allow
};
}
tools::decide_on(name, args, target, grants)
}
/// What step 8 found (the decision, and whether it may not be granted away or reviewed).
#[derive(Debug, PartialEq)]
pub struct Always {
pub decision: Decision,
/// Asked by step 8 itself: the review's note doesn't stand.
pub overridden: bool,
/// No 「一律允許」, no review, no direct mode past it.
pub must_ask: bool,
}
/// Step 8: what is asked every time, over whatever steps 6 and 7 said (a refusal stays one).
/// `sensitive_click`: the click's target reads like paying, sending or deleting;
/// `on_persons`: the step runs on this computer or another of the person's.
#[allow(clippy::too_many_arguments)]
pub fn always_ask(name: &str, args: &serde_json::Value, what: &str, via: &str, decision: Decision, sensitive_click: bool, on_persons: bool, grants: &[String]) -> Always {
let has = |g: &str| grants.iter().any(|x| x == g);
if matches!(decision, Decision::Deny(_)) {
return Always { decision, overridden: false, must_ask: false };
}
if sensitive_click {
return Always { decision: Decision::Ask { reason: format!("畫面上的目標說的是敏感操作:{what}(付款、傳送、刪除這類事,每一次都會先問你)"), grant: String::new() }, overridden: true, must_ask: false };
}
let skip_msg_ask = name == crate::macapps::SEND_MESSAGE && has("messages:no-ask");
if crate::macapps::is_mac_tool(name) && crate::macapps::is_send(name) && !skip_msg_ask {
return Always { decision: Decision::Ask { reason: format!("用你的「{}」{what}(每一封都會先問你)", crate::macapps::app_of(name)), grant: String::new() }, overridden: true, must_ask: false };
}
let script = args["command"].as_str().unwrap_or("");
if name == "shell" && on_persons && tools::osascript_outside(script).is_ok() && !has(tools::OSASCRIPT_GRANT) {
let short: String = script.chars().take(200).collect();
return Always { decision: Decision::Ask { reason: format!("讓 {via} 在沙盒外執行 AppleScript(可以指揮你電腦上的 App):{short}"), grant: tools::OSASCRIPT_GRANT.into() }, overridden: true, must_ask: true };
}
Always { decision, overridden: false, must_ask: false }
}
#[cfg(test)]
mod tests {
use super::*;
fn here() -> tools::Target {
tools::Target { name: "這台".into(), place: tools::Place::Local { workdir: std::env::temp_dir() } }
}
fn ask_grant(d: &Decision) -> Option<&str> {
match d {
Decision::Ask { grant, .. } => Some(grant.as_str()),
_ => None,
}
}
/// Step 6 as a table: (tool, place, app, grants) → allowed, asked (with what grant), refused.
#[test]
fn step_six_by_kind() {
let g = |v: &[&str]| v.iter().map(|s| s.to_string()).collect::<Vec<_>>();
let t = here();
let d = |name: &str, args: &str, place: Place, app: Option<&str>, grants: &[String]| by_kind(name, args, "做事", "Bot", &t, place, || app.map(String::from), grants);
// The Mac's apps.
let send = crate::macapps::SEND_MESSAGE;
assert_eq!(ask_grant(&d(send, "{}", Place::Elsewhere, None, &[])), Some(""), "sending: every time, nothing to keep");
assert_eq!(d(send, "{}", Place::Elsewhere, None, &g(&["messages:no-ask"])), Decision::Allow);
// The screen.
assert_eq!(d("computer_use_click", "{}", Place::OwnBox, None, &[]), Decision::Allow, "its own desktop");
assert_eq!(ask_grant(&d("computer_use_screenshot", "{}", Place::Elsewhere, None, &[])), Some("computer:see"));
assert_eq!(d("computer_use_screenshot", "{}", Place::Elsewhere, None, &g(&["computer:see"])), Decision::Allow);
assert_eq!(ask_grant(&d("computer_use_click", "{}", Place::Elsewhere, Some("Safari"), &[])), Some("app:Safari"));
assert_eq!(d("computer_use_click", "{}", Place::Elsewhere, Some("Safari"), &g(&[SCREEN_CONTROL_GRANT])), Decision::Allow);
assert_eq!(ask_grant(&d("computer_use_click", "{}", Place::Elsewhere, None, &[])), Some(SCREEN_CONTROL_GRANT));
assert!(matches!(d("computer_use_click", "{}", Place::Elsewhere, Some("AnyBot"), &g(&[SCREEN_CONTROL_GRANT])), Decision::Deny(_)), "never AnyBot's own window");
// Another computer's screen.
assert_eq!(ask_grant(&d("computer_use_screenshot", "{}", Place::Device("筆電"), None, &[])), Some("device-see:筆電"));
assert_eq!(ask_grant(&d("computer_use_click", "{}", Place::Device("筆電"), None, &g(&["device-see:筆電"]))), Some("device-control:筆電"));
// The browser: opening is free.
assert_eq!(d("browser_open", r#"{"url":"https://example.com"}"#, Place::Elsewhere, None, &[]), Decision::Allow);
// Commands go by the command rules.
assert!(matches!(d("shell", r#"{"command":"sudo rm -rf /"}"#, Place::Elsewhere, None, &[]), Decision::Deny(_)));
assert_eq!(d("shell", r#"{"command":"ls"}"#, Place::Elsewhere, None, &[]), Decision::Allow);
}
/// Step 8 as a table: what is asked every time, over an allow; a refusal stays one.
#[test]
fn step_eight_always_asks() {
let a = |name: &str, args: serde_json::Value, d: Decision, sensitive: bool, persons: bool, grants: &[String]| always_ask(name, &args, "做事", "Bot", d, sensitive, persons, grants);
let none = serde_json::json!({});
let r = a("computer_use_click", none.clone(), Decision::Allow, true, true, &[]);
assert!(r.overridden && !r.must_ask && ask_grant(&r.decision) == Some(""), "a pay/send/delete click");
let r = a(crate::macapps::SEND_MESSAGE, none.clone(), Decision::Allow, false, true, &[]);
assert!(r.overridden && ask_grant(&r.decision) == Some(""), "a message, each one");
let r = a(crate::macapps::SEND_MESSAGE, none.clone(), Decision::Allow, false, true, &["messages:no-ask".into()]);
assert_eq!(r.decision, Decision::Allow, "unless the person said messages may go without asking");
let osa = serde_json::json!({"command": "osascript -e 'tell application \"Music\" to pause'"});
let r = a("shell", osa.clone(), Decision::Allow, false, true, &[]);
assert!(r.must_ask && ask_grant(&r.decision) == Some(tools::OSASCRIPT_GRANT), "AppleScript outside the sandbox: {r:?}");
assert_eq!(a("shell", osa.clone(), Decision::Allow, false, true, &[tools::OSASCRIPT_GRANT.into()]).decision, Decision::Allow);
assert_eq!(a("shell", osa, Decision::Allow, false, false, &[]).decision, Decision::Allow, "not on the person's computer");
let deny = Decision::Deny("不行".into());
assert_eq!(a("computer_use_click", none, deny.clone(), true, true, &[]).decision, deny, "a refusal stays a refusal");
}
}
feat: 自動審核可以寫固定樣式的規則,在模型之前判斷、每次一樣 計畫 R2(grok-build 的 Bash(git *)、deny > ask > allow 在模型之前)。用一般的話寫的規則交給模型判斷,每次可能不一樣,網頁上的字也可能把模型說成「允許」。 - gate.rs:is_pattern、glob(* 任何字、? 一個字;檔案的 * 只在一層、** 跨資料夾)、patterns:shell(…)(允許要每一段都符合,詢問只要一段;藏起來的指令 $()/反引號樣式不允許)、file(…)(讀檔、改檔、列資料夾、搜尋的路徑,~ 換成家目錄)、connector(…)(mcp__server__tool,use_connector_tool 也算)、web(domain:…)(web_fetch、browser_open 的網址,子網域算、example.com.evil.net 不算)、tool(…)。詢問的樣式贏過允許的樣式。 - agent::review_action:先看樣式。符合詢問 → 問(不能一律允許);符合允許 → 允許,但有用話寫的「一律詢問」時先讓模型看那幾條;都不符合 → 只把用話寫的規則交給模型(review_by_model)。直接操作模式下詢問的樣式一樣擋。 - 設定 › 權限 › 自動審核的說明寫樣式怎麼寫;功能地圖 safety.md、FEATURES.md。 已驗證:cargo test 580 全過、clippy -D warnings 過。新測試:glob;樣式的表格(13 種:git status 允許、git status && rm -rf x 不允許、git push 被詢問蓋過、$() 不允許、路徑、連接器、子網域和假網域、工具名);一輪:直接操作 + 一律詢問的 shell(echo *),那一步停下來問、卡上寫是哪一條規則,模型只被問了兩次(沒有額外的審核呼叫),檔案沒建。 未驗證:無。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 04:01:34 +00:00
// ---------- 固定樣式的規則 (R2) ----------
// 「無需詢問直接允許」 and 「一律詢問」 rules may be written as a pattern instead of a sentence:
// shell(git *) a command (every part of `a && b | c` for an allow; any part for an ask)
// file(~/Projects/**) a file or folder a step reads or changes (** any depth, * one name)
// connector(gitlab__*) a connector's tool (server__tool)
// web(domain:example.com) a page opened or fetched on that site (or below it)
// tool(browser_click) a step by its tool's name
// They are decided here, the same every time, before the model reads the sentence rules: an ask
// pattern can't be talked out of by anything the model read (grok-build's deny > ask > allow
// rules, checked before its model).
/// What the pattern rules say about a step.
#[derive(Clone, Debug, PartialEq)]
pub enum PatternVerdict {
Ask(String),
Allow(String),
NoMatch,
}
/// A rule written as a pattern (else it is a sentence for the model).
pub fn is_pattern(rule: &str) -> bool {
let r = rule.trim();
["shell(", "file(", "connector(", "web(", "tool("].iter().any(|p| r.starts_with(p)) && r.ends_with(')')
}
/// `*` any run of characters, `?` one; with `slash_stops`, `*` stays within one path name and
/// `**` crosses folders.
pub fn glob(pat: &str, text: &str, slash_stops: bool) -> bool {
fn go(p: &[char], t: &[char], slash_stops: bool) -> bool {
match p.first() {
None => t.is_empty(),
Some('*') if p.get(1) == Some(&'*') => (0..=t.len()).any(|i| go(&p[2..], &t[i..], slash_stops)),
Some('*') => (0..=t.len()).take_while(|&i| i == 0 || !(slash_stops && t[i - 1] == '/')).any(|i| go(&p[1..], &t[i..], slash_stops)),
Some('?') => !t.is_empty() && go(&p[1..], &t[1..], slash_stops),
Some(c) => t.first() == Some(c) && go(&p[1..], &t[1..], slash_stops),
}
}
let (p, t): (Vec<char>, Vec<char>) = (pat.chars().collect(), text.chars().collect());
go(&p, &t, slash_stops)
}
/// Whether `rule` (a pattern) is about this step; `all` for an allow (every part of a command
/// must match), any part for an ask.
fn pattern_matches(rule: &str, name: &str, args: &serde_json::Value, all: bool) -> bool {
let r = rule.trim();
let Some((kind, inner)) = r.split_once('(').map(|(k, rest)| (k, rest.strip_suffix(')').unwrap_or(rest).trim())) else { return false };
let s = |k: &str| args[k].as_str().unwrap_or("").trim().to_string();
match kind {
"shell" if name == "shell" => {
let cmd = s("command");
match tools::split_commands(&cmd) {
Some(parts) if !parts.is_empty() => {
let hit = |p: &String| glob(inner, p.trim(), false);
if all { parts.iter().all(hit) } else { parts.iter().any(hit) }
}
// Hidden commands ($(), backticks): an allow can't vouch for what it can't see; an
// ask still looks at the whole line.
_ => !all && glob(inner, &cmd, false),
}
}
"file" if matches!(name, "read_file" | "edit_file" | "list_dir" | "search" | "write_file") => {
let path = s("path");
let home = |p: &str| tools::expand_home(p).display().to_string();
fix: 獨立審查找到的問題(二):技能的工具限制、連接器登入、檢查點、監看、目標 技能的 allowed-tools(三個會讓限制失效的): - 用部分名字讀技能時沒有套上限制;靠左寫的清單(- Read)和帶冒號的項目讀成空的;Read(docs/**) 連改檔也放行,而且 docs/../.. 繞得出去。 - 後讀的技能會把限制換掉(現在第一個的限制留著);browser、computer 寫了卻永遠對不上;參數裡的 ' 把後面全吃掉。 連接器登入: - token 只認名字不認網址:改了網址或同名重加,舊 token 會送到新的地方。現在綁登入時的網址;移除就登出;登出後連線也斷。 - 連接器給的登入位址沒有檢查:可以指到雲端中繼資料、Docker 管理端點,或非網頁的位址。現在都要是網頁位址、過安全規則;resource 不能是別的網站。 - 鑰匙圈一時打不開時,存別的連接器會把其他 token 清空。 檢查點:還原失敗還是把檢查點丟掉;同一個 Bot 另一段對話改的檔案也被退;監看、例行任務的訊息被當成可以退回的點;紀錄檔沒有鎖。 監看:輸出滿 4 MB 之後就再也不叫;印很多又馬上結束的指令被說成「太多行停掉」。 目標:數字在動的進度(還差 7 → 還差 6)被當成同一個理由而暫停;使用者說繼續後,下一輪又跟暫停前比;做不到也撒彩帶;沒有電腦時評審連網頁都不能看。 其他:fork 技能在群組裡被吃掉(群組沒有支線,改在聊天裡做)。 已驗證:cargo test 613 通過(技能、連接器、檢查點、目標各補了斷言)、clippy -D warnings 乾淨。 沒修:Box/SSH 上非 UTF-8 的檔案檢查點會存壞(edit_file 本來就只處理文字);引用訊息再打指令不算指令(原本就這樣);Windows 的管理員 hook 檔位置一般使用者可能寫得進去(沒辦法在這裡驗)。 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-17 06:24:12 +00:00
// (A path that climbs out with `..` is not "under" anything a rule names.)
!path.is_empty() && !path.split(['/', '\\']).any(|c| c == "..") && (glob(inner, &path, true) || glob(&home(inner), &home(&path), true))
feat: 自動審核可以寫固定樣式的規則,在模型之前判斷、每次一樣 計畫 R2(grok-build 的 Bash(git *)、deny > ask > allow 在模型之前)。用一般的話寫的規則交給模型判斷,每次可能不一樣,網頁上的字也可能把模型說成「允許」。 - gate.rs:is_pattern、glob(* 任何字、? 一個字;檔案的 * 只在一層、** 跨資料夾)、patterns:shell(…)(允許要每一段都符合,詢問只要一段;藏起來的指令 $()/反引號樣式不允許)、file(…)(讀檔、改檔、列資料夾、搜尋的路徑,~ 換成家目錄)、connector(…)(mcp__server__tool,use_connector_tool 也算)、web(domain:…)(web_fetch、browser_open 的網址,子網域算、example.com.evil.net 不算)、tool(…)。詢問的樣式贏過允許的樣式。 - agent::review_action:先看樣式。符合詢問 → 問(不能一律允許);符合允許 → 允許,但有用話寫的「一律詢問」時先讓模型看那幾條;都不符合 → 只把用話寫的規則交給模型(review_by_model)。直接操作模式下詢問的樣式一樣擋。 - 設定 › 權限 › 自動審核的說明寫樣式怎麼寫;功能地圖 safety.md、FEATURES.md。 已驗證:cargo test 580 全過、clippy -D warnings 過。新測試:glob;樣式的表格(13 種:git status 允許、git status && rm -rf x 不允許、git push 被詢問蓋過、$() 不允許、路徑、連接器、子網域和假網域、工具名);一輪:直接操作 + 一律詢問的 shell(echo *),那一步停下來問、卡上寫是哪一條規則,模型只被問了兩次(沒有額外的審核呼叫),檔案沒建。 未驗證:無。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 04:01:34 +00:00
}
"connector" => {
let tool = if name == crate::mcp::USE_TOOL { s("tool") } else { name.to_string() };
tool.strip_prefix("mcp__").is_some_and(|t| glob(inner, t, false))
}
fix: 網址照瀏覽器的讀法比對(web(domain:…)、內部網址卡);審核員只讀兩端時照樣問;上傳的開關卡不給審核省掉 第三輪審查(6a6d905..4303646)的四個 P1,加上能收的 P2。 P1-1 `web(domain:…)` 比對的不是瀏覽器打開的那個網站:gate.rs 自己切網址,`me@example.com`、 `example.com.`、`example.com\cart`、`browser_tabs` 帶網址開新分頁都對不上(0 張卡)。 P1-2 同一個根:web.rs 的 normalize_url/host_port 用 rsplit('@')、不把 `\` 當 `/`, `http://127.0.0.1\@a.com/`、`http://192.168.1.1\.example.com/` 被當成公開網址,內部網址卡不跳。 修法:web::parse_url 用 WHATWG 的 `url` crate(Cargo.lock 本來就有,改成直接依賴)——`\` 是 `/`、 帳號@ 不是主機、小寫、punycode、結尾的點、各種寫法的 IP;normalize_url、host_port、web::host_of 都用它, gate 的 web(…) 用 host_of 比主機(規則的網域也同樣讀),比對清單加上 browser_tabs 帶網址。 InBotsBrowser 把解析過的網址交給瀏覽器(open、新分頁、web_fetch),檢查的就是打開的;web_fetch 轉址的每一站也照解析過的去要。地圖寫清楚:只比對用網址打開或讀的那一步,點連結、轉址、上一頁不算。 P1-3 審核員只讀長參數的兩端:模型可以把要擋的東西塞在中間,審核員說允許就不跳卡片。修法:參數被截過、 而且這一步真的給模型看了(model_reads,跟 review_action 一樣的判斷)時,審核員的允許、直接操作下的 「都不符合」都改成跳卡片:「參數很長,自動審核只讀了開頭和結尾,所以先問你」(沒有直接操作時照舊可以 一律允許,跟審核失敗一樣)。選這個而不是把上限拉高:上限拉多高,中間都還是可能藏東西。 P1-4 從這台上傳檔案、電腦工具或「在這台電腦上執行」沒開時,那張卡被送進 reviewed(),允許規則就省掉了。 修法:抽成 here_upload_decision——開關沒開的那張卡(工作資料夾內外都是)一律跳、不給審核,別的 yes (樣式卡的允許)也省不掉它;開關開著才照檔案規則和 reviewed()。 P2: - browser.md 的陷阱和自動審核說的對齊(本機網址:一律允許、直接操作、自動審核的允許都可以不問, 「一律詢問」照樣問)。 - 「對不上任何東西」的提醒(gate::rule_warning)擴到 web(…)(沒寫 domain:、用 *、寫了 https:// 或路徑、 不是網站)和 tool(…)(不是哪一步的名字,例如 tool(browser) 要寫 tool(browser_*));featuremap 的 every_tool 搬出測試,提醒用同一份工具清單。 - hook 的「ask」跟瀏覽器的樣式卡放在同一張(run_call 的通用 hook 詢問不再管 InBotsBrowser)。 沒改,記著(略過樣式規則的路):伺服器大腦上的 open_for_person、/goal 評審自己呼叫的 web_fetch、 在使用者自己的瀏覽器 browser_open(OnComputer,不用問的不比對)、別人傳來的訊息那一輪的 web_fetch (沒有自動審核)。vault.rs 的 host_of 也是自己切網址,沒動。沒碰 src/remote.rs、src/botbrowser.rs。 特性表 connector_decisions_are_characterized 多 20 列(38 → 58):審核員說允許、長參數 × 審核員允許/ 都不符合/允許樣式/詢問樣式。tool_specs_are_locked、approval_decisions_are_characterized 沒有 diff。 已驗證: 全部 cargo test 686 通過(不帶金鑰、DOCKER_HOST 指到不存在、ANYBOT_VAULT_KEY_FILE 放暫存、 PATH 前面放假的 security 記下每次呼叫:這次 0 次);把四個修法和 hook 合併各自改回去, addresses_are_read_as_a_browser_reads_them、pattern_rules_decide_before_the_model、an_ask_pattern_stops_the_bots_browser、 connector_decisions_are_characterized、an_upload_with_the_switches_off_always_asks、 a_hook_ask_and_a_rule_make_one_card_for_a_browser_step 都失敗,改回來都過;clippy -D warnings、lint-sh、 verify-approval-routing run.sh --replay(跟基準一樣);verify-anybot:browser 每一步可跑的照 md 原文冷跑全過 (target/verify-anybot/20261118-200336:「在瀏覽器打開 http://127.0.0.1/@a.com/(符合你的「一律詢問」規則: web(domain:127.0.0.1))」,192.168.1.5\.example.com 跳內部網址卡、先給審核員看;全部拒絕、沒有開瀏覽器) 未驗證: 真的瀏覽器打開解析過的網址(scratch 沒有 Docker,這台開會出現真的瀏覽器);直接操作那一半的實機; 電腦設定頁提醒那一行的樣子;--ignored 的瀏覽器實機測試(清單見 4303646) 未簽: 審批路徑、瀏覽器——要人類跑 --ignored 並簽名才能合併,沒有合併、沒有推 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha5sXAsDLzxz6UZJgoC
2026-11-18 12:06:35 +00:00
// Every way a step opens or fetches a page by its address (a new tab with one too): the
// host as the browser reads it (web::host_of — `\`, user@, case, a trailing dot, IDNA,
// IPs in any spelling), the rule's domain read the same way. (Pages reached by a click, a
// redirect or 上一頁 aren't opened by address: no rule sees them.)
"web" if matches!(name, "web_fetch" | "browser_open") || (name == "browser_tabs" && s("action") == "new") => {
let want = inner.strip_prefix("domain:").unwrap_or(inner).trim();
match (crate::web::host_of(&s("url")), crate::web::host_of(want)) {
(Some(host), Some(want)) => host == want || host.ends_with(&format!(".{want}")),
_ => false,
}
feat: 自動審核可以寫固定樣式的規則,在模型之前判斷、每次一樣 計畫 R2(grok-build 的 Bash(git *)、deny > ask > allow 在模型之前)。用一般的話寫的規則交給模型判斷,每次可能不一樣,網頁上的字也可能把模型說成「允許」。 - gate.rs:is_pattern、glob(* 任何字、? 一個字;檔案的 * 只在一層、** 跨資料夾)、patterns:shell(…)(允許要每一段都符合,詢問只要一段;藏起來的指令 $()/反引號樣式不允許)、file(…)(讀檔、改檔、列資料夾、搜尋的路徑,~ 換成家目錄)、connector(…)(mcp__server__tool,use_connector_tool 也算)、web(domain:…)(web_fetch、browser_open 的網址,子網域算、example.com.evil.net 不算)、tool(…)。詢問的樣式贏過允許的樣式。 - agent::review_action:先看樣式。符合詢問 → 問(不能一律允許);符合允許 → 允許,但有用話寫的「一律詢問」時先讓模型看那幾條;都不符合 → 只把用話寫的規則交給模型(review_by_model)。直接操作模式下詢問的樣式一樣擋。 - 設定 › 權限 › 自動審核的說明寫樣式怎麼寫;功能地圖 safety.md、FEATURES.md。 已驗證:cargo test 580 全過、clippy -D warnings 過。新測試:glob;樣式的表格(13 種:git status 允許、git status && rm -rf x 不允許、git push 被詢問蓋過、$() 不允許、路徑、連接器、子網域和假網域、工具名);一輪:直接操作 + 一律詢問的 shell(echo *),那一步停下來問、卡上寫是哪一條規則,模型只被問了兩次(沒有額外的審核呼叫),檔案沒建。 未驗證:無。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 04:01:34 +00:00
}
"tool" => glob(inner, name, false),
_ => false,
}
}
fix: 網址照瀏覽器的讀法比對(web(domain:…)、內部網址卡);審核員只讀兩端時照樣問;上傳的開關卡不給審核省掉 第三輪審查(6a6d905..4303646)的四個 P1,加上能收的 P2。 P1-1 `web(domain:…)` 比對的不是瀏覽器打開的那個網站:gate.rs 自己切網址,`me@example.com`、 `example.com.`、`example.com\cart`、`browser_tabs` 帶網址開新分頁都對不上(0 張卡)。 P1-2 同一個根:web.rs 的 normalize_url/host_port 用 rsplit('@')、不把 `\` 當 `/`, `http://127.0.0.1\@a.com/`、`http://192.168.1.1\.example.com/` 被當成公開網址,內部網址卡不跳。 修法:web::parse_url 用 WHATWG 的 `url` crate(Cargo.lock 本來就有,改成直接依賴)——`\` 是 `/`、 帳號@ 不是主機、小寫、punycode、結尾的點、各種寫法的 IP;normalize_url、host_port、web::host_of 都用它, gate 的 web(…) 用 host_of 比主機(規則的網域也同樣讀),比對清單加上 browser_tabs 帶網址。 InBotsBrowser 把解析過的網址交給瀏覽器(open、新分頁、web_fetch),檢查的就是打開的;web_fetch 轉址的每一站也照解析過的去要。地圖寫清楚:只比對用網址打開或讀的那一步,點連結、轉址、上一頁不算。 P1-3 審核員只讀長參數的兩端:模型可以把要擋的東西塞在中間,審核員說允許就不跳卡片。修法:參數被截過、 而且這一步真的給模型看了(model_reads,跟 review_action 一樣的判斷)時,審核員的允許、直接操作下的 「都不符合」都改成跳卡片:「參數很長,自動審核只讀了開頭和結尾,所以先問你」(沒有直接操作時照舊可以 一律允許,跟審核失敗一樣)。選這個而不是把上限拉高:上限拉多高,中間都還是可能藏東西。 P1-4 從這台上傳檔案、電腦工具或「在這台電腦上執行」沒開時,那張卡被送進 reviewed(),允許規則就省掉了。 修法:抽成 here_upload_decision——開關沒開的那張卡(工作資料夾內外都是)一律跳、不給審核,別的 yes (樣式卡的允許)也省不掉它;開關開著才照檔案規則和 reviewed()。 P2: - browser.md 的陷阱和自動審核說的對齊(本機網址:一律允許、直接操作、自動審核的允許都可以不問, 「一律詢問」照樣問)。 - 「對不上任何東西」的提醒(gate::rule_warning)擴到 web(…)(沒寫 domain:、用 *、寫了 https:// 或路徑、 不是網站)和 tool(…)(不是哪一步的名字,例如 tool(browser) 要寫 tool(browser_*));featuremap 的 every_tool 搬出測試,提醒用同一份工具清單。 - hook 的「ask」跟瀏覽器的樣式卡放在同一張(run_call 的通用 hook 詢問不再管 InBotsBrowser)。 沒改,記著(略過樣式規則的路):伺服器大腦上的 open_for_person、/goal 評審自己呼叫的 web_fetch、 在使用者自己的瀏覽器 browser_open(OnComputer,不用問的不比對)、別人傳來的訊息那一輪的 web_fetch (沒有自動審核)。vault.rs 的 host_of 也是自己切網址,沒動。沒碰 src/remote.rs、src/botbrowser.rs。 特性表 connector_decisions_are_characterized 多 20 列(38 → 58):審核員說允許、長參數 × 審核員允許/ 都不符合/允許樣式/詢問樣式。tool_specs_are_locked、approval_decisions_are_characterized 沒有 diff。 已驗證: 全部 cargo test 686 通過(不帶金鑰、DOCKER_HOST 指到不存在、ANYBOT_VAULT_KEY_FILE 放暫存、 PATH 前面放假的 security 記下每次呼叫:這次 0 次);把四個修法和 hook 合併各自改回去, addresses_are_read_as_a_browser_reads_them、pattern_rules_decide_before_the_model、an_ask_pattern_stops_the_bots_browser、 connector_decisions_are_characterized、an_upload_with_the_switches_off_always_asks、 a_hook_ask_and_a_rule_make_one_card_for_a_browser_step 都失敗,改回來都過;clippy -D warnings、lint-sh、 verify-approval-routing run.sh --replay(跟基準一樣);verify-anybot:browser 每一步可跑的照 md 原文冷跑全過 (target/verify-anybot/20261118-200336:「在瀏覽器打開 http://127.0.0.1/@a.com/(符合你的「一律詢問」規則: web(domain:127.0.0.1))」,192.168.1.5\.example.com 跳內部網址卡、先給審核員看;全部拒絕、沒有開瀏覽器) 未驗證: 真的瀏覽器打開解析過的網址(scratch 沒有 Docker,這台開會出現真的瀏覽器);直接操作那一半的實機; 電腦設定頁提醒那一行的樣子;--ignored 的瀏覽器實機測試(清單見 4303646) 未簽: 審批路徑、瀏覽器——要人類跑 --ignored 並簽名才能合併,沒有合併、沒有推 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha5sXAsDLzxz6UZJgoC
2026-11-18 12:06:35 +00:00
/// Every name a `tool(…)` pattern is compared with: the tools as steps run (the one `browser` and
/// `computer` tools are opened up into browser_click, computer_use_click…), connectors' too.
fn tool_names() -> Vec<String> {
static FIXED: std::sync::OnceLock<Vec<String>> = std::sync::OnceLock::new();
let mut v = FIXED
.get_or_init(|| {
let mut v = crate::featuremap::every_tool();
v.extend(crate::browser::NAMES.iter().chain(crate::computer::NAMES.iter()).chain(crate::web::NAMES.iter()).map(|n| n.to_string()));
v.extend(["browser_fill_login", "browser_fill_card", "browser_fill_contact"].map(String::from));
v.retain(|n| n != crate::browser::TOOL && n != crate::computer::TOOL);
v
})
.clone();
v.extend(crate::mcp::tools().iter().map(|t| crate::mcp::tool_name(&t.server, &t.name)));
v
}
/// What to tell the person adding a rule written as a pattern that nothing it is compared with
/// answers to — said where the rule is added (the settings page, the phone). None: it can match,
/// or it is a sentence for the model, or a shell / file pattern (any command or path may come).
pub fn rule_warning(rule: &str, servers: &[crate::mcp::Server]) -> Option<String> {
let r = rule.trim();
if !is_pattern(r) {
return None;
}
let (kind, inner) = r.split_once('(').map(|(k, rest)| (k, rest.strip_suffix(')').unwrap_or(rest).trim()))?;
match kind {
"connector" => crate::mcp::rule_names_nothing(r, servers),
"web" => {
let Some(domain) = inner.strip_prefix("domain:").map(str::trim) else {
return Some(format!("「{r}」要寫成 web(domain:網站),例如 web(domain:example.com)。"));
};
if domain.contains('*') {
Some(format!("「{r}」不用 *:web(domain:example.com) 已經包含它底下的網址(shop.example.com 也算)。"))
} else if crate::web::host_of(domain).is_none() {
Some(format!("「{r}」的「{domain}」看起來不是網站,例如 web(domain:example.com)。"))
} else if domain.contains('/') || domain.contains('@') {
Some(format!("「{r}」只比對網站,會當成整個 {}(不寫 https://、帳號和路徑)。", crate::web::host_of(domain).unwrap_or_default()))
} else {
None
}
}
"tool" => (!tool_names().iter().any(|n| glob(inner, n, false))).then(|| format!("「{r}」對不上任何工具的名字:比對的是每一步真正的名字,例如 browser_click、browser_open、web_fetch、shell、computer_use_click(瀏覽器的全部寫 tool(browser_*))。")),
_ => None,
}
}
feat: 自動審核可以寫固定樣式的規則,在模型之前判斷、每次一樣 計畫 R2(grok-build 的 Bash(git *)、deny > ask > allow 在模型之前)。用一般的話寫的規則交給模型判斷,每次可能不一樣,網頁上的字也可能把模型說成「允許」。 - gate.rs:is_pattern、glob(* 任何字、? 一個字;檔案的 * 只在一層、** 跨資料夾)、patterns:shell(…)(允許要每一段都符合,詢問只要一段;藏起來的指令 $()/反引號樣式不允許)、file(…)(讀檔、改檔、列資料夾、搜尋的路徑,~ 換成家目錄)、connector(…)(mcp__server__tool,use_connector_tool 也算)、web(domain:…)(web_fetch、browser_open 的網址,子網域算、example.com.evil.net 不算)、tool(…)。詢問的樣式贏過允許的樣式。 - agent::review_action:先看樣式。符合詢問 → 問(不能一律允許);符合允許 → 允許,但有用話寫的「一律詢問」時先讓模型看那幾條;都不符合 → 只把用話寫的規則交給模型(review_by_model)。直接操作模式下詢問的樣式一樣擋。 - 設定 › 權限 › 自動審核的說明寫樣式怎麼寫;功能地圖 safety.md、FEATURES.md。 已驗證:cargo test 580 全過、clippy -D warnings 過。新測試:glob;樣式的表格(13 種:git status 允許、git status && rm -rf x 不允許、git push 被詢問蓋過、$() 不允許、路徑、連接器、子網域和假網域、工具名);一輪:直接操作 + 一律詢問的 shell(echo *),那一步停下來問、卡上寫是哪一條規則,模型只被問了兩次(沒有額外的審核呼叫),檔案沒建。 未驗證:無。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 04:01:34 +00:00
/// The pattern rules' word on a step: any ask pattern about it asks (over any allow); else an
/// allow pattern that covers it allows; else they say nothing (the sentences go to the model).
pub fn patterns(name: &str, args: &str, allow: &[String], ask: &[String]) -> PatternVerdict {
let v = tools::args_of(args);
if let Some(r) = ask.iter().filter(|r| is_pattern(r)).find(|r| pattern_matches(r, name, &v, false)) {
return PatternVerdict::Ask(r.trim().to_string());
}
if let Some(r) = allow.iter().filter(|r| is_pattern(r)).find(|r| pattern_matches(r, name, &v, true)) {
return PatternVerdict::Allow(r.trim().to_string());
}
PatternVerdict::NoMatch
}
#[cfg(test)]
mod pattern_tests {
use super::*;
#[test]
fn globs() {
assert!(glob("git *", "git status", false) && !glob("git *", "gitk", false));
assert!(glob("npm ?un *", "npm run build", false));
assert!(glob("/a/**", "/a/b/c.txt", true) && glob("/a/*", "/a/b", true) && !glob("/a/*", "/a/b/c", true));
}
/// R2 as a table: the same answer every time, an ask over an allow, a chained command allowed
/// only when every part is.
#[test]
fn pattern_rules_decide_before_the_model() {
let rules = |v: &[&str]| v.iter().map(|s| s.to_string()).collect::<Vec<_>>();
let allow = rules(&["shell(git *)", "file(~/Projects/**)", "connector(gitlab__get_*)", "web(domain:example.com)", "只是一句話的規則"]);
let ask = rules(&["shell(git push*)", "tool(browser_click)"]);
let p = |name: &str, args: serde_json::Value| patterns(name, &args.to_string(), &allow, &ask);
let sh = |c: &str| serde_json::json!({"command": c});
assert_eq!(p("shell", sh("git status")), PatternVerdict::Allow("shell(git *)".into()));
assert_eq!(p("shell", sh("git status && git log")), PatternVerdict::Allow("shell(git *)".into()));
assert_eq!(p("shell", sh("git status && rm -rf x")), PatternVerdict::NoMatch, "every part, or no allow");
assert_eq!(p("shell", sh("git add . && git push origin main")), PatternVerdict::Ask("shell(git push*)".into()), "an ask over an allow");
assert_eq!(p("shell", sh("echo $(git status)")), PatternVerdict::NoMatch, "a hidden command is never allowed by a pattern");
assert_eq!(p("read_file", serde_json::json!({"path": "~/Projects/a/b.rs"})), PatternVerdict::Allow("file(~/Projects/**)".into()));
assert_eq!(p("read_file", serde_json::json!({"path": "~/Documents/x"})), PatternVerdict::NoMatch);
assert_eq!(p("mcp__gitlab__get_issue", serde_json::json!({})), PatternVerdict::Allow("connector(gitlab__get_*)".into()));
assert_eq!(p(crate::mcp::USE_TOOL, serde_json::json!({"tool": "mcp__gitlab__delete_project"})), PatternVerdict::NoMatch);
assert_eq!(p("web_fetch", serde_json::json!({"url": "https://docs.example.com/a"})), PatternVerdict::Allow("web(domain:example.com)".into()));
assert_eq!(p("web_fetch", serde_json::json!({"url": "https://example.com.evil.net/"})), PatternVerdict::NoMatch);
fix: 網址照瀏覽器的讀法比對(web(domain:…)、內部網址卡);審核員只讀兩端時照樣問;上傳的開關卡不給審核省掉 第三輪審查(6a6d905..4303646)的四個 P1,加上能收的 P2。 P1-1 `web(domain:…)` 比對的不是瀏覽器打開的那個網站:gate.rs 自己切網址,`me@example.com`、 `example.com.`、`example.com\cart`、`browser_tabs` 帶網址開新分頁都對不上(0 張卡)。 P1-2 同一個根:web.rs 的 normalize_url/host_port 用 rsplit('@')、不把 `\` 當 `/`, `http://127.0.0.1\@a.com/`、`http://192.168.1.1\.example.com/` 被當成公開網址,內部網址卡不跳。 修法:web::parse_url 用 WHATWG 的 `url` crate(Cargo.lock 本來就有,改成直接依賴)——`\` 是 `/`、 帳號@ 不是主機、小寫、punycode、結尾的點、各種寫法的 IP;normalize_url、host_port、web::host_of 都用它, gate 的 web(…) 用 host_of 比主機(規則的網域也同樣讀),比對清單加上 browser_tabs 帶網址。 InBotsBrowser 把解析過的網址交給瀏覽器(open、新分頁、web_fetch),檢查的就是打開的;web_fetch 轉址的每一站也照解析過的去要。地圖寫清楚:只比對用網址打開或讀的那一步,點連結、轉址、上一頁不算。 P1-3 審核員只讀長參數的兩端:模型可以把要擋的東西塞在中間,審核員說允許就不跳卡片。修法:參數被截過、 而且這一步真的給模型看了(model_reads,跟 review_action 一樣的判斷)時,審核員的允許、直接操作下的 「都不符合」都改成跳卡片:「參數很長,自動審核只讀了開頭和結尾,所以先問你」(沒有直接操作時照舊可以 一律允許,跟審核失敗一樣)。選這個而不是把上限拉高:上限拉多高,中間都還是可能藏東西。 P1-4 從這台上傳檔案、電腦工具或「在這台電腦上執行」沒開時,那張卡被送進 reviewed(),允許規則就省掉了。 修法:抽成 here_upload_decision——開關沒開的那張卡(工作資料夾內外都是)一律跳、不給審核,別的 yes (樣式卡的允許)也省不掉它;開關開著才照檔案規則和 reviewed()。 P2: - browser.md 的陷阱和自動審核說的對齊(本機網址:一律允許、直接操作、自動審核的允許都可以不問, 「一律詢問」照樣問)。 - 「對不上任何東西」的提醒(gate::rule_warning)擴到 web(…)(沒寫 domain:、用 *、寫了 https:// 或路徑、 不是網站)和 tool(…)(不是哪一步的名字,例如 tool(browser) 要寫 tool(browser_*));featuremap 的 every_tool 搬出測試,提醒用同一份工具清單。 - hook 的「ask」跟瀏覽器的樣式卡放在同一張(run_call 的通用 hook 詢問不再管 InBotsBrowser)。 沒改,記著(略過樣式規則的路):伺服器大腦上的 open_for_person、/goal 評審自己呼叫的 web_fetch、 在使用者自己的瀏覽器 browser_open(OnComputer,不用問的不比對)、別人傳來的訊息那一輪的 web_fetch (沒有自動審核)。vault.rs 的 host_of 也是自己切網址,沒動。沒碰 src/remote.rs、src/botbrowser.rs。 特性表 connector_decisions_are_characterized 多 20 列(38 → 58):審核員說允許、長參數 × 審核員允許/ 都不符合/允許樣式/詢問樣式。tool_specs_are_locked、approval_decisions_are_characterized 沒有 diff。 已驗證: 全部 cargo test 686 通過(不帶金鑰、DOCKER_HOST 指到不存在、ANYBOT_VAULT_KEY_FILE 放暫存、 PATH 前面放假的 security 記下每次呼叫:這次 0 次);把四個修法和 hook 合併各自改回去, addresses_are_read_as_a_browser_reads_them、pattern_rules_decide_before_the_model、an_ask_pattern_stops_the_bots_browser、 connector_decisions_are_characterized、an_upload_with_the_switches_off_always_asks、 a_hook_ask_and_a_rule_make_one_card_for_a_browser_step 都失敗,改回來都過;clippy -D warnings、lint-sh、 verify-approval-routing run.sh --replay(跟基準一樣);verify-anybot:browser 每一步可跑的照 md 原文冷跑全過 (target/verify-anybot/20261118-200336:「在瀏覽器打開 http://127.0.0.1/@a.com/(符合你的「一律詢問」規則: web(domain:127.0.0.1))」,192.168.1.5\.example.com 跳內部網址卡、先給審核員看;全部拒絕、沒有開瀏覽器) 未驗證: 真的瀏覽器打開解析過的網址(scratch 沒有 Docker,這台開會出現真的瀏覽器);直接操作那一半的實機; 電腦設定頁提醒那一行的樣子;--ignored 的瀏覽器實機測試(清單見 4303646) 未簽: 審批路徑、瀏覽器——要人類跑 --ignored 並簽名才能合併,沒有合併、沒有推 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha5sXAsDLzxz6UZJgoC
2026-11-18 12:06:35 +00:00
// The host as a browser reads it: user@, a trailing dot, case, a backslash, a new tab by address.
for (name, args) in [
("web_fetch", serde_json::json!({"url": "https://x@example.com/"})),
("web_fetch", serde_json::json!({"url": "https://EXAMPLE.com./"})),
("browser_open", serde_json::json!({"url": "https://shop.example.com\\cart"})),
("browser_tabs", serde_json::json!({"action": "new", "url": "https://me@shop.example.com./cart"})),
] {
assert_eq!(p(name, args.clone()), PatternVerdict::Allow("web(domain:example.com)".into()), "{name} {args}");
}
assert_eq!(p("web_fetch", serde_json::json!({"url": "https://example.com@evil.net/"})), PatternVerdict::NoMatch, "evil.net is the host");
assert_eq!(p("browser_tabs", serde_json::json!({"action": "select", "index": 1})), PatternVerdict::NoMatch);
assert_eq!(patterns("browser_open", r#"{"url":"https://xn--bcher-kva.example/"}"#, &[], &["web(domain:Bücher.example)".into()]), PatternVerdict::Ask("web(domain:Bücher.example)".into()), "the rule's domain read the same way");
feat: 自動審核可以寫固定樣式的規則,在模型之前判斷、每次一樣 計畫 R2(grok-build 的 Bash(git *)、deny > ask > allow 在模型之前)。用一般的話寫的規則交給模型判斷,每次可能不一樣,網頁上的字也可能把模型說成「允許」。 - gate.rs:is_pattern、glob(* 任何字、? 一個字;檔案的 * 只在一層、** 跨資料夾)、patterns:shell(…)(允許要每一段都符合,詢問只要一段;藏起來的指令 $()/反引號樣式不允許)、file(…)(讀檔、改檔、列資料夾、搜尋的路徑,~ 換成家目錄)、connector(…)(mcp__server__tool,use_connector_tool 也算)、web(domain:…)(web_fetch、browser_open 的網址,子網域算、example.com.evil.net 不算)、tool(…)。詢問的樣式贏過允許的樣式。 - agent::review_action:先看樣式。符合詢問 → 問(不能一律允許);符合允許 → 允許,但有用話寫的「一律詢問」時先讓模型看那幾條;都不符合 → 只把用話寫的規則交給模型(review_by_model)。直接操作模式下詢問的樣式一樣擋。 - 設定 › 權限 › 自動審核的說明寫樣式怎麼寫;功能地圖 safety.md、FEATURES.md。 已驗證:cargo test 580 全過、clippy -D warnings 過。新測試:glob;樣式的表格(13 種:git status 允許、git status && rm -rf x 不允許、git push 被詢問蓋過、$() 不允許、路徑、連接器、子網域和假網域、工具名);一輪:直接操作 + 一律詢問的 shell(echo *),那一步停下來問、卡上寫是哪一條規則,模型只被問了兩次(沒有額外的審核呼叫),檔案沒建。 未驗證:無。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 04:01:34 +00:00
assert_eq!(p("browser_click", serde_json::json!({})), PatternVerdict::Ask("tool(browser_click)".into()));
assert!(is_pattern("shell(ls)") && !is_pattern("刪除檔案前先問我") && !is_pattern("shell ls"));
}
}