Skip to main content

agentmux_mcp/tools/browser/
granted.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! What `request_auto_approve` tells an agent when its grant is made.
5
6use serde_json::Value;
7
8/// What `request_auto_approve` tells the agent when it was granted: for how long
9/// (a standing grant has no clock: it stands until the user revokes it) and what
10/// the grant lets it do.
11pub(super) fn granted_text(d: &Value) -> String {
12    let sites: Vec<&str> = d["origins"].as_array().map(|a| a.iter().filter_map(|v| v.as_str()).collect()).unwrap_or_default();
13    let has = |p: &str| d["powers"].as_array().is_some_and(|a| a.iter().any(|v| v.as_str() == Some(p)));
14    // Asking about each line is the stricter of the two, so it wins when both are there.
15    let (terminal, per_line) = (has("terminal") && !has("terminal_ask"), has("terminal_ask"));
16    let how_long = if d["always"].as_bool() == Some(true) {
17        "until the user revokes it".to_string()
18    } else {
19        format!("for {} more min", d["minutes_left"].as_u64().unwrap_or(0))
20    };
21    // With the power, Enter and Space are taken as the click they are; a key whose click can't be named is refused.
22    let keys = if has("enter_space") {
23        "eval stays refused, and Enter and Space (action key) are taken as the click they are: a form's default button, \
24         a button, a link or a checkbox, checked like any click; on anything else they are refused, so click by ref"
25    } else {
26        "eval and Enter/Space stay refused"
27    };
28    // An auto-approve already on this pane, with more time than the ask, was cut to the ask.
29    let cut = match (d["cut_from"].as_u64(), d["minutes"].as_u64()) {
30        (Some(was), Some(now)) => format!(" Auto-approve was already on this pane with {was} more min; it was cut to the {now} you asked for."),
31        _ => String::new(),
32    };
33    format!(
34        "Auto-approve on {how_long} on {}: committing clicks (action click) run without asking. Nobody \
35         checks them now, so check each one yourself. A payment still asks, {keys}, and on any other site clicks ask as \
36         before.{}{}{} Stop it with action stop_auto_approve when the job is done.",
37        sites.join(", "),
38        if terminal {
39            " You may also type and run commands in a web terminal on these sites with action terminal: \
40             nobody checks each line, the user can Stop or Pause you, and a password or code prompt is theirs to type."
41        } else if per_line {
42            " You may also use a web terminal on these sites with action terminal, one line per call: the user is shown \
43             each line (give a `reason`) and presses Run it or Don't run; a password or code prompt is theirs to type."
44        } else {
45            ""
46        },
47        if has("uploads") {
48            " When a page opens its file chooser, AgentMux keeps it for 30 seconds: fill it with action set_files, chooser true and \
49             paths (files in your own workspace); a chooser nobody fills in time is cancelled."
50        } else {
51            ""
52        },
53        cut
54    )
55}