Agents and the debug bridge
A command “yields its agent surface” (CREDO): unless it says otherwise, every command an application declares can be run by an agent through the debug bridge, with the arguments its spec describes, and the run is marked as the agent’s. This page says what that bridge is, how an agent reaches it, what it can and cannot do, and what is not protected today.
In short: the bridge is a Rust API inside the application’s process.
egui-pop opens no socket and no port for it unless the application turns
on the opt-in agent socket (egui-pop-agent). An
agent is code that holds the App (a test, a harness, a transport such
as the agent socket); it discovers the collectors and commands as JSON, runs the
commands offered to agents, reads every collector’s state, and calls
the collector actions offered to agents. What keeps an action away from
it is the command’s or the collector action’s agent flag, the
command’s when clause, step hooks (debug.call for every collector
action) and the host; the known gaps list what nothing
checks.
What an agent connects to
In the process, or over the agent socket. The bridge
(egui_pop::core::debug::DebugBridge) is a list of collectors held by
each App. By default nothing listens for it: no TCP port, no socket,
no pipe. An application that wants agents outside its process adds the
opt-in crate egui-pop-agent, which serves the calls below as JSON-RPC
over a private local socket (The agent socket); never
TCP. In the process, it is reached by Rust calls:
| Call | What it does |
|---|---|
AppHandle::debug_describe() | every collector: name, description, actions (each with mutates, agent, an example of its arguments, and its JSON Schemas when given) |
AppHandle::debug_capabilities() | every collector action and command as one list, protocol 1 (bridge.describe, Capabilities) |
AppHandle::debug_snapshot() | every collector’s snapshot, by name, as one JSON object |
AppHandle::debug_call(collector, action, args) | calls an action as the agent (debug-bridge); always returns a Feedback; commands.run is queued for the next frame |
App::debug_call(collector, action, args) | the same, but commands.run runs at once and its result is in the feedback |
AppHandle::debug_call_as(collector, action, args, origin), App::debug_call_as | the same for another caller: the user’s calls (the devtools panel, a debug page) pass Origin::User |
AppHandle::debug_log() | the last 64 feedback blocks, refusals included |
Always there, on, read-only or off. Every App builds its bridge
with the core collectors and registers its own and its plugins’ when it
is built, in release builds as in debug builds. What it lets anyone but
the user do is the application’s choice, AppBuilder::debug_bridge:
| Mode | Agents (any origin but the user) |
|---|---|
BridgeMode::On (default) | every action and command offered to them |
BridgeMode::ReadOnly | only calls that change nothing: actions with mutates: false, and commands.run of a command declared read_only |
BridgeMode::Off | nothing: every call is refused (“the debug bridge is off”) |
The user’s calls (the devtools panel, debug_call_as with
Origin::User) are never refused by the mode. Refusals go on the
journal (debug.call.refused).
Devtools is a view, not a gate. DevtoolsPlugin (opt-in) shows the
same collectors in a panel, opened with Shift+F12 once the
developer.devtools setting is on (off by default). The setting gates
the panel only; the bridge answers Rust calls whatever its value. The
panel is the user’s: an action run from it goes through the
devtools.call step, then, as the user, through the debug.call step
every collector action goes through; a plugin may veto either, and a
veto of debug.call covers the panel and agents alike. See
Debugging.
Reaching it from another process takes a transport that turns
requests into debug_calls on the UI thread. egui-pop’s is the opt-in
agent socket (egui-pop-agent): the bridge as
JSON-RPC over a private local socket, held by the bridge’s mode, each
agent’s grants and the input lock, with an MCP server on top
(egui-pop-agent-mcp), its ui method for the accessibility tree
and input, and inspect, egui’s inspection protocol (screenshots,
drags) without its TCP port, which the MCP server’s widget_* tools
(Rerun’s egui_inspection_tools) drive for testing by pointer and
pixels. An application may write its own transport (stdin, another
protocol) over the same calls. The other ways out of the process are
not the bridge:
- the gallery’s
--dump-debugprints the bridge’s snapshot as one JSON line on stdout when it quits by--quit-after(read only, the gallery only; see tools/wbox); - tools/wbox drives a real gallery window in a nested, headless compositor: screenshots, clicks and keys, as a person would;
- the gallery’s opt-in
inspectionfeature serves egui’segui_inspectionprotocol on loopback, without authentication, for Rerun’segui-mcp: the accessibility tree, clicks and keys by role or label, screenshots and a wait, as a person would, not the bridge (Driving the gallery with egui-mcp). Development builds only: the endpoint is an unauthenticated TCP port on loopback. It bypasses egui-pop’s bridge mode, the agent socket’s grants and its input lock: an agent behind it acts as the user, and can click a destructive call’s confirmation or a pairing dialog itself. It is for development builds only, never for an application you ship. - the single-instance plugin of
egui-pop-platform(instance.md) listens on a local socket for later launches of the same application; what they hand over (arguments, working directory, links) reaches theinstance.second_launchanddeeplink.opensteps, not the bridge.
What it can do
Discover
debug_describe() lists the collectors. One entry, as the gallery
answers it:
{
"name": "store",
"description": "The value store: every path, its value, its owner, who may write it and who changed it.",
"actions": [
{ "name": "get", "description": "Reads a value with its descriptor.", "mutates": false, "agent": true, "args": { "path": "settings/x" } },
{ "name": "set", "description": "Writes a value (`path`, `value`) as its caller: the user through the framework, anyone else as itself, held to the value's writers (`Origin::writer`); for the user only unless offered (agents run the `value.set` command).", "mutates": true, "agent": false, "args": { "path": "settings/x", "value": 1 } },
{ "name": "undo", "description": "Undoes the last change of values as its caller, refused when it may not write one of them; for the user only unless offered (agents run the `value.undo` command).", "mutates": true, "agent": false, "args": null }
]
}
The commands collector’s snapshot lists every command with what an
agent needs to run it: id, title, category, description, when
(where it applies), keys, agent (offered to agents or not), args
(its arguments: a JSON Schema, enforced, or a free description such as
an example, null when it takes none), running, owner and its icons; beside
them, the context (the context keys in force) and history (the last
runs). In the gallery:
{
"id": "about.read",
"title": "Read about the application",
"category": "Help",
"description": "The application's name, version, description, licences, authors and links, egui-pop's and egui's versions, the platform, the renderer and the version info as text.",
"when": "",
"keys": [],
"agent": true,
"args": null,
"running": false,
"owner": "egui_pop.about",
"icon": null,
"icon_on": null,
"icon_set_by": null,
"unknown_icons": []
}
Run a command
commands.run takes { "id", "args" }. The bridge checks that the
command exists and is offered to agents, then runs it with
Origin::Agent("debug-bridge"). A collector action acts as its caller:
called by the user (the devtools panel, debug_call_as with
Origin::User), commands.run runs the command as the user, a command
kept from agents included. The reply is a Feedback, the same
shape for every call, success or not:
| Field | Meaning |
|---|---|
ok | the call succeeded |
collector, action | what was called |
mutates | the call is one that changes the application (whether or not it did): the action’s flag, and for commands.run the command’s (false for a command declared read_only) |
message | what happened, in a sentence |
data | the result, null on failure |
Through App::debug_call, about.read in the gallery answers:
{
"ok": true,
"collector": "commands",
"action": "run",
"mutates": false,
"message": "`about.read` ran; the application may have changed",
"data": {
"authors": ["The egui-pop contributors"],
"description": "egui-pop's components in every variant, state, theme and density.",
"egui": "0.37",
"egui_pop": "0.2.0",
"licences": ["MIT OR Apache-2.0"],
"links": {
"docs": "https://quazardous.github.io/egui-pop/docs/",
"issues": "https://github.com/quazardous/egui-pop/issues",
"repository": "https://github.com/quazardous/egui-pop",
"website": "https://quazardous.github.io/egui-pop/"
},
"name": "egui-pop gallery",
"platform": "linux x86_64",
"renderer": null,
"version": "0.2.0 (59ba7f9f)",
"version_info": "egui-pop gallery 0.2.0 (59ba7f9f)\negui-pop 0.2.0\negui 0.37\nPlatform: linux x86_64\n"
}
}
Through AppHandle::debug_call the run is only queued:
{ "ok": true, "collector": "commands", "action": "run", "mutates": false, "message": "`commands.run` done; nothing changed", "data": { "queued": true } }
A command whose host answers later (Reply::Later) gives
"data": { "pending": true } and the message “<id> is running; its
result goes to the journal”.
Read state and results
- Every collector’s snapshot: focus and the focus chain, overlays, fields (each input’s label, kind and state), indicators, the announcements made to screen readers, the theme, the store (every path, value, owner, writers, last writer), the context stack, dialogs, file choices, jobs, the workbench, the windows’ scale, and those of the plugins connected (about 50 in the gallery).
- The value store also as commands:
value.list,value.get,value.set,value.reset,value.undo,value.redo. - The journal:
journal.sincewith{ "seq": n }returns the events aftern. Each run of a command leaves acommand.dispatchedevent and acommand.done(orcommand.failed) event whosecauseis the dispatch:
[
{ "seq": 1, "source": "agent:debug-bridge", "cause": null, "name": "command.dispatched", "data": { "command": "about.read", "args": null } },
{ "seq": 2, "source": "agent:debug-bridge", "cause": 1, "name": "command.done", "data": { "command": "about.read", "result": { "name": "egui-pop gallery" } } }
]
(The second event’s result is cut here; it is the whole answer shown
above.)
A plugin’s disconnection is a plugin.disconnected event, and a run of
a command whose plugin went is a command.refused event saying so
(Plugins).
Act through collector actions
Besides commands.run, collectors offer actions of their own. Each
says whether agents may call it (agent): by default those that only
read, and none that writes. In the gallery, agents may call
commands.run (the command’s own agent flag is checked) and the
read-only actions: state.slot, fonts.check, icons.search,
journal.since, store.get, mounts.where_can, mounts.check,
frame.hit and the gallery’s gallery.viewport.wait_idle. The actions
that write are the user’s (the devtools panel, a debug page):
screen.set_interface_zoom, focus.clear, overlays.close_top,
announcements.announce, plugins.set_enabled, store.set,
store.undo, i18n.set_locale, i18n.clear_missing,
contexts.request, contexts.hold, contexts.release,
dialogs.answer, files.answer, the jobs actions (cancel, pause,
resume, retry, dismiss, clear), toasts.dismiss,
viewport.set_view and the gallery’s gallery.tree.hold_loads. Most have a command an agent runs instead
(value.set, value.undo, job.cancel, context.hold…).
An agent’s call to an action not offered to it is refused before anything runs, in the bridge’s log and on the journal:
{ "ok": false, "collector": "store", "action": "set", "mutates": true, "message": "`store.set` refused: it is not offered to agents; only the user may call it", "data": null }
{ "seq": 7, "source": "agent:debug-bridge", "cause": null, "name": "debug.call.refused", "data": { "collector": "store", "action": "set", "args": { "path": "settings/x", "value": 1 }, "reason": "it is not offered to agents; only the user may call it" } }
Every other call, the user’s included, runs through the debug.call
step ({ "collector", "action", "args", "origin" }), whose
before-hooks may veto it (“journal.since vetoed by kiosk: …”,
debug.call.vetoed on the journal). A call that writes is published as
debug.call; one that only reads (a read-only command’s
commands.run included) is published and traced only when vetoed or
failed, so polling fills neither the journal nor the steps’ traces. A
refused commands.run (a command not offered to agents, or unknown) is
on the journal once, as a failed debug.call with the reason.
An application may offer a writing action to agents it trusts with it
(a test harness, its own automation): AppBuilder::offer_to_agents
("dialogs.answer"); a name that matches no action is reported
(agent-offer-unknown). A collector declares its own with
FnCollector::agent.
Wait
bridge.wait checks a condition: a journal event after since
({ "event": "command.done", "cause": 42 }), the application settled
({ "settled": true }: no command queued or running, every job idle,
no repaint asked for), or the first of several ({ "any": [..] }). It
answers { "met", "by", "event", "last" }; last is the next check’s
since. In-process the call answers at once, it never blocks the UI
thread: whoever waits checks again after each frame. A transport holds
the call until it is met or its deadline_ms passes.
In Rust, AppHandle::wait_met(&WaitFor, since) is the same check
(egui_pop::api::wait), and a test steps frames until it holds with
egui_pop_test::wait::wait_until(&mut harness, &until, since, Deadline::default()), or settle (Testing). The
steps collector still gives the last runs of each step, and an
application may add its own waits (the gallery’s
gallery.viewport.wait_idle).
Capabilities
bridge.describe (AppHandle::debug_capabilities()) lists everything
an agent may name as one list, under protocol: 1: every collector
action (kind: "action", name as collector.action) and every
command (kind: "command", run through commands.run), each with
description, mutates, agent, destructive (the user confirms an
agent’s call; an action’s without arguments), private (a command’s
result is private data an agent may be refused), args (a JSON Schema
when the author gives one, else null), example (example arguments), result (a JSON
Schema of the result, or null) and call (how to call it). A
collector gives its schemas with FnCollector::schema and
FnCollector::result_schema; a command whose args is a JSON Schema
(CommandSpec::schema) is listed with it, and its runs are checked
against it. The protocol number changes only when a field changes
meaning: a client calls only names the list gives, so adding
capabilities breaks none.
Screenshots and the accessibility tree
Not through the bridge’s calls. Out of the process, the agent socket’s
ui method reads the accessibility tree and acts on it, and its
inspect method takes screenshots and sends any egui event, under the
bridge’s mode, the ui grant and the input lock
(The agent socket). Over MCP, the widget_* tools
(widget_screenshot, widget_click, widget_drag, widget_type_text,
widget_press_key, widget_scroll, widget_batch, widget_wait_for,
widget_resize, widget_tree) are Rerun’s egui_inspection_tools
served over inspect, under the same mode, grants and lock: for testing
by pointer and pixels, not the way an agent acts on the application
(its commands are). In tests, egui_kittest renders
frames and egui_pop_test::a11y_tree prints the accessibility tree
(Testing); for a real window, wbox takes screenshots, and
the gallery built with --features inspection gives both to egui-mcp
(inspection.md), in development builds only (it opens
an unauthenticated port that bypasses the grants). The bridge gives the
same information as data: the fields, focus, indicators and
announcements collectors.
Watched. kittest_inspector (Rerun), a GUI to step a kittest test
frame by frame: watched; revisit when egui_kittest ships an inspector.
An example, end to end
An application with two commands, one kept off the agent surface. The
agent discovers the bridge, lists the commands offered to it, runs one,
reads its result and the journal, and is refused the other. This block
is compiled and run with the guides (cargo test -p consumer-smoke --doc).
use egui_pop::egui;
use egui_pop::prelude::*;
use serde_json::{Value as Json, json};
struct Notes;
impl Plugin for Notes {
fn id(&self) -> PluginId {
PluginId::from_static("notes")
}
fn connect(&mut self, ctx: &mut Ctx<'_>) -> Result<(), PluginError> {
ctx.command(
CommandSpec::new(CommandId::from_static("notes.count"), "Count notes", "Notes")
.description("How many notes a folder holds (`folder`).")
.args(json!({ "folder": "inbox" })),
|call| Ok(json!({ "folder": call.args["folder"], "count": 3 })),
)?;
// Never run by an agent.
ctx.command(
CommandSpec::new(CommandId::from_static("notes.purge"), "Purge notes", "Notes")
.no_agent(),
|_| Ok(Json::Null),
)?;
Ok(())
}
}
let ctx = egui::Context::default();
let mut app = App::builder()
.plugins(DefaultPlugins)
.plugin(Notes)
.build(&ctx)
.unwrap();
// 1. Discover the collectors and their actions.
let described = app.handle().debug_describe();
let commands = described
.as_array()
.unwrap()
.iter()
.find(|c| c["name"] == "commands")
.unwrap();
assert_eq!(commands["actions"][0]["name"], "run");
assert_eq!(commands["actions"][0]["mutates"], true);
// 2. The commands offered to agents, with their arguments.
let snapshot = app.handle().debug_snapshot();
let offered: Vec<&Json> = snapshot["commands"]["commands"]
.as_array()
.unwrap()
.iter()
.filter(|c| c["agent"] == true)
.collect();
let count = offered.iter().find(|c| c["id"] == "notes.count").unwrap();
assert_eq!(count["args"], json!({ "folder": "inbox" }));
assert!(!offered.iter().any(|c| c["id"] == "notes.purge"));
// 3. Run one: `App::debug_call` runs it now and returns its result.
let before = app.handle().last_event();
let f = app.debug_call(
"commands",
"run",
&json!({ "id": "notes.count", "args": { "folder": "inbox" } }),
);
assert!(f.ok, "{}", f.message);
assert_eq!(f.data, json!({ "folder": "inbox", "count": 3 }));
// 4. The journal says the agent did it.
let events = app.debug_call("journal", "since", &json!({ "seq": before }));
let done = events
.data
.as_array()
.unwrap()
.iter()
.find(|e| e["name"] == "command.done")
.unwrap();
assert_eq!(done["source"], "agent:debug-bridge");
assert_eq!(done["data"]["result"]["count"], 3);
// 5. The command kept off the surface is refused, and says why.
let f = app.debug_call("commands", "run", &json!({ "id": "notes.purge" }));
assert!(!f.ok);
assert_eq!(
f.message,
"`commands.run` failed: `notes.purge` is not offered to agents"
);
The JSON replies shown on this page were captured from the gallery
itself, headless: a test built it with Gallery::new on a plain
egui::Context (no window, no GPU), ran one frame of App::logic, and
printed debug_describe, the commands snapshot and the feedback of
commands.run (about.read, app.quit), journal.since, store.get
and store.set.
What it cannot do, and the trust model
The bridge has one caller identity: every command it runs is
Origin::Agent("debug-bridge"), and the journal’s source is
agent:debug-bridge. What is checked:
- Collector actions’
agentflag. An action that writes is the user’s unless it says otherwise (onlycommands.rundoes) or the application offers it (AppBuilder::offer_to_agents): the agent’s call is refused and journaled (debug.call.refused). Every call that goes on, the agent’s and the user’s, runs through thedebug.callstep a plugin may veto (a kiosk build). - Typing into a terminal.
terminal.sendwrites to a terminal’s program, in a pseudo-terminal shell (theeditors-ptyfeature, as in the gallery) any command the user could run: it is not offered to agents. An application whose agent should type offers it (AppBuilder::offer_command_to_agents(CMD_SEND), see Editors), and the input still goes throughterminal.inputwith the agent’s origin, where a hook can narrow or veto it. - The
agentflag.commands.runrefuses a command declared withCommandSpec::no_agent()(and an unknown one) with “<id>is not offered to agents”. In egui-pop and the gallery: quitting, the window’s close, minimise, maximise and menu, opening devtools,deeplink.open,links.confirmed(the confirmed link), the pointer gestures,viewer.load_images, and a few gallery commands. 31 of the gallery’s 259 commands are not offered. - Where a command applies. A command whose
whenclause does not hold in the current context is refused (“does not apply here”), for an agent as for a key. - Destructive commands. A command declared
CommandSpec::destructive()(it deletes files, empties a trash, drops unsaved work), or an action its collector says is destructive (Collector::destructive), waits for the user’s confirmation when an agent calls it through the agent socket: a dialog names the agent, the command and its arguments, and a decline or a deadline refuses it (command.refused,by: "pop.agent.confirm") and cancels the dialog. While it is open, agents’uiactions are refused, so an agent cannot click its own confirmation. The user’s own runs are never asked (The agent socket). - Argument schemas. A command whose
argsis a JSON Schema (CommandSpec::schema) is held to it: a run whose arguments do not match is refused before its handler, whoever asks it, the user included (command.refused,by: "pop.command.args", the reason naming where and why:/factor: expected a number, got a string). A destructive command’s run refused so is never asked about. A command whose arguments are only described (an example, a text) checks nothing (The agent socket). - Grants per agent. Over the agent socket, each agent is held to a
grant the application sets (commands, read-only, values,
uiactions; presets read-only, editor, full): a client that does not sayhelloreads only unless the application allows unpaired writes, and thepop.agent.grantslistener refuses onpop.command.runwhat a grant does not allow (command.refused,by: "pop.agent.grants"), before the application’s own listeners (The agent socket). - Private data. A command declared
CommandSpec::private()(places, people, absolute file paths) is refused to an agent whose grant withholds private data; a read only partly private leaves those fields out whengrants::reads_private(app, origin)isfalse. Every preset reads it until the user turns it off on the Agents page. An application with its own switch lifts it for every agent through a host hook,AgentGrantsExt::agent_private_allowed, read at each request (The agent socket). - The user’s say. Settings › Developer › Agents lists the paired agents (connected now, last seen), sets each one’s access and the defaults to a preset, and private data shown or withheld, live, and revokes a pairing: its token stops pairing and its connections close. Agents cannot change any of it (The Agents page).
- Links. A link an agent asks to open (
links.open,files.reveal,viewer.open_outside) is always confirmed by the user, and the links plugin vetoes any answer to that confirmation but the user’s: an agent may cancel it, not accept it (Links). - The clipboard. An agent copies and pastes in its own slot
(
agent:debug-bridge): it neither reads nor overwrites what the user copied unless the owner allows it (The clipboard). - The chain of commands. A command’s handler runs for its origin
(
Call::origin,AppHandle::acting_origin), and the commands it starts withAppHandle::runrun for the same origin: an agent’s command starts the agent’s commands. While a command runs for anyone but the user, its handler may not run another as the user (AppHandle::run_aswithOrigin::Useris refused,command.refusedon the journal); one running for an agent may only name an agent. To act for the user, the handler asks the user: a dialog whose answer, the user’s, runs its command as the user.App::runandAppHandle::run_asrefuse a command not offered to agents to an agent origin, wherever it comes from (command.refused). - Deep links. A link that comes with a launch, the first one’s or a
later one’s through the single-instance socket, runs the
application’s links command as
Origin::Remote("deeplink")(instance::deeplink_origin), not as the user: any program of the user’s may launch the application with a link. The handler sees it, what it starts inherits it, it may not claim the user, and its writes are held to the values’ writers. A handler that changes anything on a link asks the user first (Instance). - Dialogs and file choices.
dialogs.answerandfiles.answeranswer as their caller. Accepting a dialog runs its command with the caller’s origin, and an answer that would run a command not offered to agents is refused to anyone but the user, even when the application offersdialogs.answer(dialog.answer.refusedon the journal); an agent may still cancel it. A file choice carries its origin to its consumer (files::chosen_origin). - The value store. An agent writes as itself
(
agent:debug-bridge,Origin::writer), throughvalue.set,value.reset,value.undo,value.redoand, when offered,store.setandstore.undo: a value’s declared writers (ADR 0016) apply, so it is refused a setting only its owner writes (settings/developer.devtools) and the undo of a change to one. To let it write a value, name it among the value’s writers (Descriptor::writers). The user writes through the framework, as the settings form does. A write is also refused when the value is held by someone else’s gesture, changed sinceif_seq, or invalid for its type; past the soft range only withforce. - Steps. Every step’s before-hooks see its arguments and may veto
it; steps that carry an
origin(dialog.answer,terminal.inputamong them) let a hook refuse agents only. - The host. Every command goes through the host’s dispatch with its
origin (
Dispatch::origin), those that run in the interface too (Dispatch::deferred): a host may refuse agents there, in one place. An agent’s undo, redo, jump, restore or out-of-order undo, throughedit.undoorhistory.*, is held to the values’ writers as a write is, all or nothing.
Keeping an action off the agent surface
- Declare the command with
.no_agent(); it stays in menus, keys and the palette. - A dialog whose command is declared
.no_agent()is accepted by the user only, even when the application offersdialogs.answerto agents. When a dialog confirms an action whose command agents may run otherwise, veto thedialog.answerstep unless itsoriginisuser, as the links plugin does. - To refuse a collector action to everyone, the user’s devtools panel
included, veto the
debug.callstep for it. - When a step does the work, veto it from a before-hook for agents (the origin is in the arguments when the step carries it).
- In the host’s
dispatch, refuseOrigin::Agentfor the commands it should never run for one. Every command goes through it, undo and redo,history.*, the context stack’s and the clipboard’s commands included: their handler calls the host itself, so it runs once the dispatch has approved it (Dispatch::deferred; the dispatch’srun_localanswersnullat once). A host refuses one by answering an error without callingrun_local.
use egui_pop::api::dialogs::STEP_ANSWER;
use egui_pop::api::host::{Dispatch, Host, Journal, LocalHost, Reply, Waker};
use egui_pop::egui;
use egui_pop::prelude::*;
use serde_json::{Value as Json, json};
/// The default host, refusing agents the `notes.` commands.
struct Guarded(LocalHost);
impl Host for Guarded {
fn dispatch(&mut self, d: &Dispatch<'_>) -> Reply {
if matches!(d.origin, Origin::Agent(_)) && d.command.as_str().starts_with("notes.") {
return Reply::Done(Err(format!("`{}` is not for agents", d.command)));
}
self.0.dispatch(d)
}
fn journal(&self) -> Option<&Journal> {
self.0.journal()
}
fn journal_mut(&mut self) -> Option<&mut Journal> {
self.0.journal_mut()
}
fn store(&self) -> SharedStore {
self.0.store()
}
fn set_waker(&mut self, waker: Waker) {
self.0.set_waker(waker);
}
fn layout_document(&self) -> Option<String> {
self.0.layout_document()
}
}
struct Notes;
impl Plugin for Notes {
fn id(&self) -> PluginId {
PluginId::from_static("notes")
}
fn connect(&mut self, ctx: &mut Ctx<'_>) -> Result<(), PluginError> {
ctx.command(
CommandSpec::new(CommandId::from_static("notes.count"), "Count notes", "Notes"),
|_| Ok(json!(3)),
)?;
// Only the user accepts a dialog; an agent may still cancel one.
ctx.before(STEP_ANSWER, |_, args| {
let cancel = args["answer"]["answer"] == "cancel";
if !cancel && args["origin"] != "user" {
Before::Veto("only the user answers dialogs".into())
} else {
Before::Go
}
});
Ok(())
}
}
let mut app = App::builder()
.host(Guarded(LocalHost::new(SharedStore::default())))
.plugins(DefaultPlugins)
.plugin(Notes)
.build(&egui::Context::default())
.unwrap();
let count = CommandId::from_static("notes.count");
let f = app.debug_call("commands", "run", &json!({ "id": "notes.count" }));
assert!(!f.ok);
assert!(f.message.contains("is not for agents"), "{}", f.message);
// The user still runs it.
assert_eq!(app.run(&count, Json::Null, Origin::User).now(), Some(Ok(json!(3))));
Known gaps
What is not protected today. None of these is fixed by documenting it.
- No authentication beyond the socket’s owner. Every call through
the bridge in the process is
debug-bridge; through the agent socket,agent-socketuntil the client sayshello, its paired id after, and a pairing token attributes, it does not isolate. The socket is a Unix socket of mode 0600 in a directory only the user may write to (a named pipe on Windows, with the system’s default access), so any process of the same user that reaches it is an agent, with what the bridge’s mode allows (read-only unless the application offers more). - Code in the process is the user if it says so. The bridge’s mode
holds anyone but the user; code in the process (a plugin included)
that calls
debug_call_aswithOrigin::Useris not held. Turning the bridge off keeps out agents, not in-process code. - An offered
files.answeranswers a choice with any paths. The origin goes with the choice (files::chosen_originon its result,originin thefile.chosenstep,byin thefilescollector’s last choices), but nothing refuses it: a consumer that acts only on a person’s choice checks it, or a hook onfile.chosenvetoes it. - Origin is a label, not a credential. Code in the process names
any
Originoutside a command’s handler: a plugin’s own code, a step’s hook or a timer may still run a command as the user. Only the chain from a command running for someone else is held (above). The origin is not carried into work a handler leaves for later (a thread, a host’sReply::Laterthat starts other commands): code there names the origin itself, withAppHandle::run_as. - A new command is offered by default. Every command an application
or a plugin declares is offered to agents until it says
.no_agent(): one that reaches the system must say so itself. - What is not a command does not reach the host’s dispatch.
Collector actions (
store.set,contexts.hold… thedebug.callstep covers them), code calling a step orAppHandle::undodirectly (the step’s hooks cover it), and a text field’s own undo inside egui are not dispatched. - Snapshots are not redacted. Every value in the store, the file
choices and their folders, the terminal steps with their arguments
(
terminal_io), the journal’s arguments and results are readable through the bridge. - A command’s read-only flag is its author’s word.
commands.runreportsmutatesfrom the command’sread_onlyflag, and a read-only bridge runs only those; a command that says it only reads and writes all the same is not caught. - No rate limit, and no blocking wait in-process.
bridge.waitanswers at once; holding a call until it is met is the transport’s (oregui_pop_test::wait’s, stepping frames). Nothing limits how often an agent calls: a transport that exposes the bridge limits the rate itself.