From 4d14466dc06490b2462c18c2161004fd45d425e7 Mon Sep 17 00:00:00 2001 From: LHaghfoss Date: Wed, 25 Nov 2026 23:33:09 +0100 Subject: [PATCH] fix(engine): always ask before browser tools on the built-in harness --- docs/computer-use.md | 5 +- rustcode/engine/src/acp/permissions.rs | 8 ++- rustcode/engine/src/computer_use.rs | 4 ++ rustcode/engine/src/network/policy.rs | 5 +- rustcode/engine/src/raw_cli.rs | 9 ++++ rustcode/engine/src/tools/mod.rs | 10 +++- rustcode/engine/src/tools/tests.rs | 2 + .../src/tools/tests/browser_approval.rs | 53 +++++++++++++++++++ 8 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 rustcode/engine/src/tools/tests/browser_approval.rs diff --git a/docs/computer-use.md b/docs/computer-use.md index a142c5d03..eb95ce96c 100644 --- a/docs/computer-use.md +++ b/docs/computer-use.md @@ -28,7 +28,10 @@ allowed_domains = ["example.com", "*.example.org"] Start a new thread after changing the setting. Ask it to open an allowed URL, approve the action in RustCode, then read, click a CSS selector, or type into a CSS selector. Each step asks for approval, including reads and -screenshots. Turn `enabled` off to refuse subsequent calls. No browser is +screenshots. Auto-approve does not skip these cards on any harness, +and a headless `rc` run, which has nobody to ask, refuses the tools. Plan mode +refuses `browser_open`, `browser_click` and `browser_type`; reads and +screenshots still ask. Turn `enabled` off to refuse subsequent calls. No browser is installed or launched until the first approved action. Exact domain entries match only that host; `*.example.org` matches subdomains, diff --git a/rustcode/engine/src/acp/permissions.rs b/rustcode/engine/src/acp/permissions.rs index 266d88d7e..97a4fbd84 100644 --- a/rustcode/engine/src/acp/permissions.rs +++ b/rustcode/engine/src/acp/permissions.rs @@ -403,7 +403,11 @@ impl crate::network::policy::TurnPolicy for AcpPolicy { { return false; } - if auto_approve { + if auto_approve + && !tool_calls + .iter() + .any(|call| crate::tools::always_asks(&call.name)) + { return true; } @@ -412,7 +416,7 @@ impl crate::network::policy::TurnPolicy for AcpPolicy { &call.name, &call.arguments, mode, - false, + auto_approve, false, ) { crate::tools::AuthorizationDecision::Allow => continue, diff --git a/rustcode/engine/src/computer_use.rs b/rustcode/engine/src/computer_use.rs index 8491784b3..a80cb0967 100644 --- a/rustcode/engine/src/computer_use.rs +++ b/rustcode/engine/src/computer_use.rs @@ -132,6 +132,10 @@ const NAMES: [&str; 5] = [ pub fn is_tool(name: &str) -> bool { NAMES.contains(&name) } +/// Tools that change a page or what it loads, refused in Plan mode. +pub fn acts_on_pages(name: &str) -> bool { + matches!(name, "browser_open" | "browser_click" | "browser_type") +} pub fn tools(settings: &Settings) -> Vec { if !settings.enabled { return vec![]; diff --git a/rustcode/engine/src/network/policy.rs b/rustcode/engine/src/network/policy.rs index c92de2877..6780757ad 100644 --- a/rustcode/engine/src/network/policy.rs +++ b/rustcode/engine/src/network/policy.rs @@ -85,8 +85,11 @@ impl InteractivePolicy { }) { return false; } - if !auto_confirm { + { for call in tool_calls { + if auto_confirm && !tools::always_asks(&call.name) { + continue; + } let requested_filesystem_path = if let Some(requested) = call.arguments.get("filesystem_write_path") { diff --git a/rustcode/engine/src/raw_cli.rs b/rustcode/engine/src/raw_cli.rs index 2f368c4d1..b9b4692f0 100644 --- a/rustcode/engine/src/raw_cli.rs +++ b/rustcode/engine/src/raw_cli.rs @@ -474,6 +474,15 @@ impl crate::network::policy::TurnPolicy for HeadlessPolicy { } return false; } + if crate::tools::always_asks(&call.name) { + if !quiet { + println!( + "[Headless] Rejected: {} asks before every call and nobody can answer", + call.name + ); + } + return false; + } if !quiet { println!("\n[Headless] Executing Tool: {}", call.name); } diff --git a/rustcode/engine/src/tools/mod.rs b/rustcode/engine/src/tools/mod.rs index c16584bbe..901d2d19b 100644 --- a/rustcode/engine/src/tools/mod.rs +++ b/rustcode/engine/src/tools/mod.rs @@ -1336,6 +1336,13 @@ pub fn authorize_tool( authorize_tool_with_args(name, &Value::Null, mode, auto_confirm, bypass_confirmation) } +/// Tools that ask before every call even when auto-approve is on: the +/// browser tools act outside the workspace (docs/computer-use.md). Only an +/// approval already given for the call (`bypass_confirmation`) skips the card. +pub fn always_asks(name: &str) -> bool { + crate::computer_use::is_tool(name) +} + pub fn authorize_tool_with_args( name: &str, args: &Value, @@ -1349,6 +1356,7 @@ pub fn authorize_tool_with_args( .to_string(), ); } + let auto_confirm = auto_confirm && !always_asks(name); let command_is_destructive = name == "run_command" && command_requires_confirmation(args); let requires_confirmation = if name == "run_command" { command_is_destructive @@ -1384,7 +1392,7 @@ pub fn tool_capabilities(name: &str) -> &'static [ToolCapability] { /// Plan mode is intentionally deny-by-default for tools not explicitly known /// to be read-only or user-facing. pub fn allowed_in_plan_mode(name: &str) -> bool { - if name == crate::desktop_control::TOOL_NAME { + if name == crate::desktop_control::TOOL_NAME || crate::computer_use::acts_on_pages(name) { return false; } use ToolCapability::*; diff --git a/rustcode/engine/src/tools/tests.rs b/rustcode/engine/src/tools/tests.rs index 31937d023..59d745dd8 100644 --- a/rustcode/engine/src/tools/tests.rs +++ b/rustcode/engine/src/tools/tests.rs @@ -2876,5 +2876,7 @@ fn skills_are_control_plane_and_isolated() { assert_eq!(deferred, 1); } +#[path = "tests/browser_approval.rs"] +mod browser_approval; #[path = "tests/protocol.rs"] mod protocol; diff --git a/rustcode/engine/src/tools/tests/browser_approval.rs b/rustcode/engine/src/tools/tests/browser_approval.rs new file mode 100644 index 000000000..209de9164 --- /dev/null +++ b/rustcode/engine/src/tools/tests/browser_approval.rs @@ -0,0 +1,53 @@ +//! Browser tools ask before every call and stay out of Plan mode's page actions. + +use super::*; +use crate::config::AgentMode; +use serde_json::json; + +#[test] +fn browser_tools_ask_even_with_auto_approve() { + for name in [ + "browser_open", + "browser_read", + "browser_screenshot", + "browser_click", + "browser_type", + ] { + assert_eq!( + authorize_tool_with_args(name, &json!({}), AgentMode::Build, true, false), + AuthorizationDecision::RequireConfirmation, + "{name}" + ); + assert_eq!( + authorize_tool_with_args(name, &json!({}), AgentMode::Build, false, true), + AuthorizationDecision::Allow, + "{name}: an approval already given for this call runs it" + ); + assert!(always_asks(name)); + } + assert!(!always_asks("read_file")); + assert_eq!( + authorize_tool_with_args("read_file", &json!({}), AgentMode::Build, true, false), + AuthorizationDecision::Allow + ); +} + +#[test] +fn plan_mode_refuses_browser_actions_but_still_asks_for_reads() { + for name in ["browser_open", "browser_click", "browser_type"] { + assert!(!allowed_in_plan_mode(name), "{name}"); + let decision = authorize_tool_with_args(name, &json!({}), AgentMode::Plan, true, true); + assert!( + matches!(&decision, AuthorizationDecision::Deny(reason) if reason.contains("Plan mode")), + "{name}: {decision:?}" + ); + } + for name in ["browser_read", "browser_screenshot"] { + assert!(allowed_in_plan_mode(name), "{name}"); + assert_eq!( + authorize_tool_with_args(name, &json!({}), AgentMode::Plan, true, false), + AuthorizationDecision::RequireConfirmation, + "{name}" + ); + } +}