Skip to main content

Module desktop_gate

Module desktop_gate 

Source
Expand description

The gate in front of Desktop: an agent clicking and typing in a native app (docs/specs/SPEC_DESKTOP_DRIVING_2026_10_20.md §5.4–5.6, §5.9).

srv decides and remembers; the MCP tool acts. Before any action the tool asks [authorize]-side code (server/app_api/desktop.rs), which uses this module for:

  • grants: the user allows an agent to drive one app, for a time or for the agent’s session. They live in memory only, and are tied to the pane (block_id) that asked, so a new session asks again;
  • the blocklist: apps that are never driven (password managers, web browsers, AgentMux itself, trading and crypto apps), editable in settings;
  • limits: at most two input actions a second and 200 per grant;
  • Stop: the user’s brake. It revokes an agent’s grants, and the agent’s next action is told so once.

The user’s answer to a prompt comes only through the host (POST /api/v1/host/desktop_request), which agents can’t impersonate, so a prompt-injected agent can’t approve its own request.

Gate is plain data with the clock passed in, so every rule below is tested without a UI.

Structs§

DesktopAnswer
The user’s answer, relayed by the host (POST /api/v1/host/desktop_request).
DesktopEvent
app:desktop: prompts waiting for the user, and the grants in force.
DesktopGrantView
An app an agent may drive right now, for the pane’s “Driving” badge.
DesktopRequest
An agent waiting for the user’s yes or no on one app.
Gate

Enums§

Check
What Gate::check found.
Choice
What the user chose.

Constants§

ANSWER_WAIT
How long a prompt waits for the user.
DEFAULT_GRANT_MINUTES
DRIVING_SHOWN_MS
A grant shows as “Driving” this long after its last action.
MAX_ACTIONS_PER_GRANT
Input actions allowed per grant before the user is asked again.
MIN_ACTION_GAP_MS
Two input actions a second.
SETTING_ALLOWLIST
desktop:allowlist: app names removed from the default blocklist.
SETTING_BLOCKLIST
desktop:blocklist: app names added to the default blocklist.
SETTING_ENABLED
desktop:enabled: the tool is off unless this is true.
SETTING_GRANT_MINUTES
desktop:grantminutes: how long “Allow for a while” lasts.

Functions§

app_key
An executable name as the blocklist compares it: file name, no extension, lower case.
audit
Append one line to desktop-audit.log, next to the window-capture audit log. Best effort: failing to write it never stops the tool. Typed text is never in an entry, only its length.
blocked_reason
Why app (an executable name) with window title must not be driven, or None. added extends the defaults; allowed takes names off them. An entry matches the app’s name exactly, or any part of the window title.
with_gate
Run f on the process-wide gate.