Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
rust-use is a Rust library of UI behaviors that agents use to build and drive user interfaces. Selection, focus, toggles, lists, popups and drag-and-drop are written once as behaviors. You compose them into components with a derive macro, and every component you mount is something an agent can see and operate by name, with no screenshots, accessibility-tree crawling or pixel clicks.
It is built for GPUI, the GPU-accelerated UI framework behind Zed, and the core has no UI dependency at all.
[!WARNING] rust-use is in beta. It is pre-1.0, and APIs, the compact format and the set of behaviors may change between minor releases (0.1 → 0.2) while the design settles. Pin a minor version, read the changelog before upgrading, and please report what breaks.
Why rust-use
- 🎯 Behaviors, not pixels. An agent calls
board move e2e4, not "find the square, click it, find the other square, click it". - 🪶 Token-lean by design. The compact snapshot uses one line per component. After an action, the agent gets back only the lines that changed, not the whole screen again.
- ⚡ In-process and native. The bridge runs inside your app. Agents reach it over a local
socket through the
rust-useCLI, with no MCP server process in between. An MCP shim is there for clients that need it. - 🛡️ Every agent change is marked and can be vetoed. Changes carry
ChangeSource::Agentand pass through yourallowhook first. - 🧩 One derive, zero boilerplate.
#[derive(Primitive)]plus#[actions]turns a plain struct and its methods into an agent-drivable component. The doc comments become what the agent reads. - 📦 One crate to add. Run
cargo add rust-useand importrust_use::prelude::*. Features stay additive andunsafeis forbidden.
Getting started
Needs Rust 1.88+.
With the GPUI adapter:
| Feature | Default | What it adds |
|---|---|---|
macros |
✓ | #[derive(Primitive)] and #[actions] |
agent |
✓ | The agent bridge: snapshot, diff, act, query, allow |
gpui |
The GPUI adapter | |
ipc |
A local socket server so the rust-use CLI can drive a running app |
|
mcp |
The same three tools served over MCP | |
tauri |
A Tauri v2 plugin that serves the Ui to the webview and to agents |
|
testing |
Mount components in tests, drive them as a person or agent, and check snapshots |
Usage
use *;
/// A button that mutes audio.
let ui = new;
ui.mount.label;
let agent = ui.agent;
println!;
// rev 2
// @1 mute-button "Mute" =false !toggle
agent.act?;
Behaviors
Behaviors embed into a component with #[behavior]. Their state and actions merge into the
component's own.
- Input:
Press,Toggle,Field,Range(a bounded number or a span),TextInput(text with validation),InlineEdit(edit a label in place) - Choosing:
Selection,Tabs,Combobox(pick from a long list, or type your own),Menu(choose an item by path) - Collections:
List(reorder withmove, search withquery),Transfer(items between named lists, like a kanban board),Tree(addressed by path:select src/agent/format.rs),Viewport(track visible rows and scroll to an item) - Focus and keys:
RovingFocus(lists and 2-D grids),Typeahead - Overlays:
Popup,Dialog(confirm or cancel),Toast(read or dismiss notifications) - Layout:
Resize(set the size of a pane) - Pointer:
DragDrop
examples/agent_tour.rs mounts eight of them on one
settings screen. It sets the email and chooses a menu item in the same act as the other settings,
then cancels a dialog opened by the app.
Coming next
| Release | Behaviors | Also |
|---|---|---|
| 0.4 | Canvas, CellRange |
opening closed tabs on the way to a target, keyboard pattern checks in tests, staged changes, separate keyboard and pointer change sources |
| Later | Calendar, Area, Form, Shortcuts, Clipboard |
a GPUI component kit, a model inside the app, more adapters, hardware, 1.0 |
Every one is operated by an agent in a single direct action, such as select A1:C4 for a block of cells.
See ROADMAP.md for what each will do, and
request a behavior
to change the order.
Agents
An agent needs three tools, whichever way it connects:
| Tool | What it does |
|---|---|
snapshot |
Lists components, up to 100 at a time: ref, kind, label, value and the actions available right now |
act |
Runs one or more steps in order and returns only what changed; atomic rolls every step back if one fails |
query |
Pages through a long option list, such as a country picker, or finds components by kind or text |
It can connect three ways:
- In process:
ui.agent(), for tests and for embedding a model in your app. - CLI over a local socket:
rust-use snapshot,rust-use act "board move e2e4". Any coding agent that can run a shell command can use it, including Claude Code, Codex and Cursor. - MCP:
rust-use mcpserves the same tools to any MCP client.
Undo. The app enables undo with ui.record_history(&history) and keeps the returned
subscription alive while the agent works. undo restores everything the agent's last
act changed, on components marked #[primitive(checkpoint)]. Run rust-use undo after a batch. It refuses the whole undo if a person
changed any of those components since the batch.
let ui = new;
let history = new;
let _recording = ui.record_history;
Wait. rust-use wait blocks until the app changes, then returns a diff. It returns
immediately if changes are already available, or returns the current revision after the timeout.
Sections and labels. Use handle.section("Settings") to group a component. An agent can
qualify a label with its section or match labels by whole words, ignoring case and accents.
For example, cafe finds “Café”.
Pending approvals and errors. A snapshot shows pending= while an action awaits a person's
approval. It shows error= after an agent action fails, until a successful action or direct
update. A component's own error, such as an email validation message, takes precedence.
@1 account "Account" pending=close !!close
@2 email "Email" =jane error="Enter an email address" !set(text)
Keeping agents safe
An agent sees and does only what you allow:
/// Account settings.
#[agent(secret)]shows a field as[redacted]to every agent.#[primitive(hidden)]orhandle.hide_from_agents()makes a component invisible and unreachable for agents. To an agent it doesn't exist.#[action(confirm = "…")]marks an action that needs a person. An agent sees it as!!close, and it fails with "needs a person" unless the app installsApprovals. WithApprovals, the agent's step waits until someone approves or denies it, or it times out:
let approvals = new;
let _guard = ui.require_approval;
// In your UI: list approvals.pending(), then approvals.approve(id) or approvals.deny(id, "not now").
allowvetoes any agent action by rule, such as.allow(|r| r.action != "delete").
Testing your components
The testing kit mounts components without a window. Run the same scripts an agent would run and
check the resulting snapshot line with assert_line!. A failed assertion prints the full snapshot.
[]
= { = "0.3", = ["testing"] }
use *;
use ;
Adding rust-use to an existing GPUI app
You don't rewrite your app. You move the state an agent should be able to operate into primitives, one component at a time, and your views keep rendering as they do today.
1. Make the state a primitive. The struct your view already keeps becomes the primitive, and the methods your click handlers call become actions:
use *;
/// The playlist in the sidebar.
2. Mount it, and keep the view in sync. Hold one Ui for the app. In the view, keep the
handle, bind to the Ui so the view re-renders on every change from any source, and read state in
render:
let ui = new;
let playlist = ui
.mount
.label;
// In your view's constructor: re-render whenever an agent (or anything else) changes the Ui.
let binding = ui.bind;
// In render: read state through the handle, and send input through the same actions an agent uses.
let playing = playlist.read.flatten;
div.id.on_click
3. Let agents in. Serve the Ui over the local socket when the app starts. Use allow to
say what an agent may do:
let _server = new
.endpoint
.allow
.spawn?;
From then on, rust-use --app my-app snapshot shows the playlist to any agent, and rust-use --app my-app mcp serves it to MCP clients.
[!NOTE] Which gpui?
rust-use-gpuidepends ongpuifrom crates.io (0.2). Many GPUI apps, Zed included, use gpui from Zed's git repository instead, and two gpui versions in one build don't mix. If your app is on git gpui, point both at the same source with a[patch.crates-io]entry forgpuiin your workspaceCargo.toml. Or skip thegpuifeature:rust-useitself has no UI dependency, andui.subscribe(..)plus your owncx.notify()is all the adapter does.
Tauri apps
let ui = new;
// … mount your primitives …
default
.plugin
.run?;
The plugin gives the webview snapshot, snapshot_json, act, invoke and query commands, and
emits rust-use://changed whenever the Ui changes, so the page re-renders whether a person or an
agent changed it. The page's buttons call invoke, which runs as a user action, so people and
agents go through the same actions and the same allow checks. Add "rust-use:default" to your
window's capability. The crate README has a complete
plain-JavaScript page.
Benchmark
Claude Code (Sonnet 5.5) plays a complete chess game, the 33-ply Opera Game, in the running GPUI chess demo. It plays the same app, the same board and the same prompt through each interface. Every run below ended in checkmate on the expected position. Values are medians of 3 runs.
| Tool calls | Input tokens | Time | Cost | |
|---|---|---|---|---|
| Generic UI automation (MCP: UI tree + click) | 70 | 139,838 | 31 s | $0.161 |
| rust-use (MCP) | 3 | 19,179 | 8 s | $0.027 |
| rust-use (CLI over a local socket) | 3 | 24,147 | 8 s | $0.028 |
That is 23× fewer tool calls, 7.3× fewer input tokens, 3.9× faster and 6× cheaper for the same
finished game. rust-use over MCP and rust-use over the CLI land in the same place, so the saving
comes from the interface, not the transport. The agent sees one line for the board, and every
act returns only what changed.
On the wire, with no model involved, replaying the game through generic automation moves 43×
more tokens than rust-use with one act per move, and 208× more than a single batched act.
Method, fairness notes and the commands to reproduce all of this are in
bench/README.md. The numbers are self-reported, from one machine.
Example: the chess demo
A GPUI chess board that Claude Code plays move by move, in three ways: a generic MCP automation server, the rust-use CLI, and rust-use over MCP. It is the benchmark above, and a working example of every layer of the library.
Contributing
Contributions are welcome. The crates live in crates/, the chess demo in
demos/chess and the benchmark in bench/.
Read CONTRIBUTING.md before opening a pull request, and please follow the Code of Conduct.
Community
- Report a bug or request a behavior
- Ask a question in Discussions
- Star the repo if rust-use is useful to you. Stars are how other people find it.
- Sponsor the project to keep it moving
Contributors
Thank you to everyone who has shipped something here. If you would like to join them, CONTRIBUTING.md is the place to start.
License
MIT © Khalid Abdi