Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/computer-use.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions rustcode/engine/src/acp/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions rustcode/engine/src/computer_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value> {
if !settings.enabled {
return vec![];
Expand Down
5 changes: 4 additions & 1 deletion rustcode/engine/src/network/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
Expand Down
9 changes: 9 additions & 0 deletions rustcode/engine/src/raw_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 9 additions & 1 deletion rustcode/engine/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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::*;
Expand Down
2 changes: 2 additions & 0 deletions rustcode/engine/src/tools/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
53 changes: 53 additions & 0 deletions rustcode/engine/src/tools/tests/browser_approval.rs
Original file line number Diff line number Diff line change
@@ -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}"
);
}
}
Loading