Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

docs: flatten navigation, add Agents section (CUA-2074) (#5739)

Francesco Bonacci6b302b41845d
diff --git a/docs/content/docs/cua-driver/guides/claude-code.mdx b/docs/content/docs/cua-driver/guides/claude-code.mdx
new file mode 100644
index 0000000000..6d24854e15
--- /dev/null
+++ b/docs/content/docs/cua-driver/guides/claude-code.mdx
@@ -0,0 +1,30 @@
+---
+title: Claude Code
+description: Give Claude Code Cua Driver to use the apps on your computer, and Cua Spaces to work in computers you can watch.
+---
+
+Claude Code can use both Cua products: Cua Driver for the apps on the computer it runs on, and Cua Spaces for other computers.
+
+## Cua Driver
+
+Register Cua Driver as an MCP server, then restart Claude Code:
+
+```bash skip="third-party-cli"
+claude mcp add --transport stdio cua-driver -- cua-driver mcp
+```
+
+Use `cua-driver mcp-config --client claude` instead for the computer-use compatibility profile. Both install the agent skill for native skill activation. See [Connect your agent](/cua-driver/guides/connect-your-agent) for the skill, permissions and the other clients.
+
+## Cua Spaces
+
+`cua agents setup --agents claude-code --yes` adds the `cua` skills and MCP server to Claude Code, and the Cua Spaces app does the same on first run. To add it by hand:
+
+```bash skip="third-party-cli"
+claude mcp add cua -- cua daemon mcp
+```
+
+Then ask Claude Code: "List my Cua Spaces." See [Connect your agent to Cua Spaces](/spaces/guides/connect-your-agent) and [Give your agent Spaces](/cua-cli/guides/mcp-server).
+
+## Run Claude Code in a Space
+
+[Coding agents in a Space](/spaces/guides/coding-agents-in-a-space) covers starting Claude Code inside a Space so it works on a computer you can watch.
diff --git a/docs/content/docs/cua-driver/guides/codex.mdx b/docs/content/docs/cua-driver/guides/codex.mdx
new file mode 100644
index 0000000000..6512395fa6
--- /dev/null
+++ b/docs/content/docs/cua-driver/guides/codex.mdx
@@ -0,0 +1,24 @@
+---
+title: Codex
+description: Give Codex Cua Driver to use the apps on your computer, and Cua Spaces to work in computers you can watch.
+---
+
+Codex (CLI, IDE and app) can use both Cua products: Cua Driver for the apps on the computer it runs on, and Cua Spaces for other computers.
+
+## Cua Driver
+
+`cua-driver mcp-config --client codex` prints the command to register Cua Driver, `codex mcp add cua-driver -- <path> mcp`. Run it, then restart Codex. Codex's own approval policy also applies. See [Connect your agent](/cua-driver/guides/connect-your-agent) for the skill, permissions and the other clients.
+
+## Cua Spaces
+
+`cua agents setup --agents codex --yes` adds the `cua` skills and MCP server to Codex, and the Cua Spaces app does the same on first run. To add it by hand:
+
+```bash skip="third-party-cli"
+codex mcp add cua -- cua daemon mcp
+```
+
+Codex signs in with your ChatGPT account on its own, with `codex login`. Cua never reads or copies that sign-in. See [Connect your agent to Cua Spaces](/spaces/guides/connect-your-agent) and [Give your agent Spaces](/cua-cli/guides/mcp-server).
+
+## Run Codex in a Space
+
+[Coding agents in a Space](/spaces/guides/coding-agents-in-a-space) covers starting Codex inside a Space so it works on a computer you can watch.
diff --git a/docs/content/docs/cua-driver/guides/connect-your-agent.mdx b/docs/content/docs/cua-driver/guides/connect-your-agent.mdx
index 157264e991..4e583e272e 100644
--- a/docs/content/docs/cua-driver/guides/connect-your-agent.mdx
+++ b/docs/content/docs/cua-driver/guides/connect-your-agent.mdx
@@ -4,7 +4,6 @@ description: Register Cua Driver with Claude Code, Codex, Cursor, Hermes, OpenCl
---
import { Callout } from 'fumadocs-ui/components/callout';
-import { Tabs, Tab } from 'fumadocs-ui/components/tabs';
An agent reaches Cua Driver in one of two ways: an MCP client launches
`cua-driver mcp`, or a skill teaches a shell-capable agent to run
@@ -31,7 +30,7 @@ cua-driver mcp-config --client <client>
| Claude Code | `claude mcp add --transport stdio cua-driver -- cua-driver mcp`, or `--client claude` for the computer-use compatibility profile | Install the skill for native skill activation. |
| Codex (CLI, IDE, app) | `--client codex`, which prints `codex mcp add cua-driver -- <path> mcp` | Codex's own approval policy also applies. |
| Cursor | `--client cursor`; paste into `~/.cursor/mcp.json` or `.cursor/mcp.json` | |
-| Antigravity CLI (Gemini) | `--client antigravity`; merge into `~/.gemini/config/mcp_config.json` | `--client gemini` is a legacy alias. Building on the Gemini API directly? See [Gemini](#gemini). |
+| Antigravity CLI (Gemini) | `--client antigravity`; merge into `~/.gemini/config/mcp_config.json` | `--client gemini` is a legacy alias. Building on the Gemini API directly? See [Gemini](/cua-driver/guides/gemini). |
| OpenClaw | `--client openclaw`, which prints `openclaw mcp set cua-driver '{…}'` | On macOS, a gateway-spawned server does not inherit OpenClaw.app's grants. |
| Hermes | Built in: `hermes tools enable computer_use --platform cli`, then `hermes -t computer_use chat` | Repair with `hermes computer-use install` and `doctor`. Do not add a second raw MCP server. |
| Prime Agent | `cua-driver skills install`, then `/reload` and `/skill:cua-driver` | Calls the CLI; no MCP. |
@@ -62,7 +61,7 @@ mcp-config` with no flag):
Model providers map to harnesses: Claude through Claude Code, OpenAI through
Codex, Gemini through Antigravity, Kimi through Kimi
Code, Qwen through Qwen Code. To call Gemini 4 Argon from your own agent
-loop instead, see [Gemini](#gemini). MiniMax documents setups for
+loop instead, see [Gemini](/cua-driver/guides/gemini). MiniMax documents setups for
[Codex](https://platform.minimax.io/docs/token-plan/codex) and
[Claude Code](https://platform.minimax.io/docs/token-plan/claude-code).
@@ -113,344 +112,18 @@ They remove interactive approval prompts: run only trusted tasks.
## Gemini
-Two ways to use Gemini 4 Argon (`gemini-4-argon`) with Cua Driver: add Cua Driver
-to Antigravity and write no code, or call the Gemini API from your own agent
-loop. Both need Cua Driver 0.35.2 or later on a Mac (check with
-`cua-driver --version`) with the permissions from the
-[Quickstart](/cua-driver/quickstart) granted. Windows and Linux use the same MCP
-server and SDKs: change "macOS apps" in the system instruction below to your
-platform.
-
-In each recording, Gemini works in the Mac apps on the left while a person
-types a long message into a chat app on the right with a real keyboard. The bar
-at the bottom counts the keystrokes the chat app received against the ones that
-were typed. The middle of each clip is sped up.
-
-<VideoDemo
- src="https://github.com/user-attachments/assets/70e9cc74-0020-43cd-b974-3fb930288ec9"
- poster="https://github.com/user-attachments/assets/619dc845-2af0-464e-8a03-b7ce945edec4"
- title="Gemini 4 Argon turns a whiteboard photo into a Keynote deck with Cua Driver"
->
- Whiteboard photo to Keynote. Gemini read a photo of a hand-drawn product plan
- in Preview and built a three-slide deck in Keynote: a title slide, the three
- phases (skipping the crossed-out items), and a diagram of the system flow. The
- run took about 8 minutes and 173 tool calls. All 2,541 of the person's
- keystrokes reached the chat app.
-</VideoDemo>
-
-<VideoDemo
- src="https://github.com/user-attachments/assets/28b57899-5681-4a64-8fca-f70762e5c95c"
- poster="https://github.com/user-attachments/assets/84058332-45e0-49dd-a736-428ef4fd93d8"
- title="Gemini 4 Argon summarizes a dashboard into Notes with Cua Driver"
->
- Dashboard to Notes. Gemini read a dense metrics dashboard in Preview, picked
- the three largest changes from the previous period, and wrote them into a new
- note with the old value, the new value, and the change. The run took about a
- minute. All 503 keystrokes reached the chat app.
-</VideoDemo>
-
-<VideoDemo
- src="https://github.com/user-attachments/assets/358b5547-2d38-4868-ba28-91e90b3c41b7"
- poster="https://github.com/user-attachments/assets/38cb5c14-121f-42c5-a642-b4e92d8a59f9"
- title="Gemini 4 Argon enters expenses into a native app with Cua Driver"
->
- Expenses into Ledger, a small native app with no scripting interface. Gemini
- entered eight expenses through the app's form fields, and the app's total
- matched the expected $3,271.29. The run took under two minutes. All 722
- keystrokes reached the chat app.
-</VideoDemo>
-
-### With Antigravity, no code
-
-[Antigravity](https://antigravity.google/docs/home) runs agents on Gemini and
-supports local MCP servers. Gemini 4 Argon in Antigravity is available to Google
-AI Ultra subscribers. These steps use the Antigravity CLI, `agy`; the desktop
-app and IDE read the same MCP configuration.
-
-```bash skip="host-install"
-curl -fsSL https://antigravity.google/cli/install.sh | bash
-```
-
-Add Cua Driver as an MCP server. This writes it to
-`~/.gemini/config/mcp_config.json`.
-
-```bash skip="third-party-cli"
-agy mcp add cua-driver "$(command -v cua-driver)" mcp
-agy mcp list
-```
-
-```text output
-NAME TYPE STATUS COMMAND/URL
-cua-driver stdio enabled /Users/you/.local/bin/cua-driver mcp
-```
-
-To approve Cua Driver's tools once instead of on every call, add an allow rule
-to `~/.gemini/antigravity-cli/settings.json`:
-
-```json test="config" id="gemini-agy-settings"
-{
- "permissions": {
- "allow": ["mcp(cua-driver/*)"]
- }
-}
-```
-
-Start `agy`, choose Gemini 4 Argon, and give it a task. Name the tools you want
-and say that someone is using the computer:
-
-```text output
-Use only the cua-driver tools. In Contacts, open Daniel Reyes and add this note
-to his card: "Met at the Design Systems Meetup booth." Save the card. Work in
-the background; I'm using the computer.
-```
-
-To run without the interactive interface, use print mode. Antigravity cannot
-ask you to approve a tool in print mode, so it denies any tool your allow list
-does not cover, such as shell commands.
-
-```bash skip="third-party-cli"
-agy -p "Use only the cua-driver tools. List the windows that are open right now."
-```
-
-### From your own agent loop
-
-To control the prompt, the tool set, and the loop, call the Gemini
-[Interactions API](https://ai.google.dev/gemini-api/docs/interactions) from your
-own process and run each tool call through Cua Driver. You need a Gemini API key
-from [Google AI Studio](https://aistudio.google.com/apikey) on a paid tier
-(Gemini 4 Argon is not on the free tier), and Python 3.10+ or Node.js 20+.
-
-![The agent loop: your script sends Gemini the task and Cua Driver's tool declarations, runs each function call through Cua Driver, and sends the result back until Gemini answers.](https://github.com/user-attachments/assets/bdfff431-0f7f-440c-867a-2905fbda4a98)
-
-The loop has three parts:
-
-- **Tool declarations.** `list_tools_json()` returns each tool with a JSON
- Schema, which Gemini accepts as a function declaration unchanged.
-- **Tool calls.** `call_tool(name, arguments_json)` runs one tool and returns a
- summary, structured details such as window IDs and element tokens, and
- screenshots.
-- **Results.** Send each result back as a `function_result` with text and image
- parts. Include the structured details: the window IDs and element tokens the
- model needs next are there, not in the summary.
-
-`CuaDriver.connect(None)` attaches to the Cua Driver service you started. That
-service holds the macOS permissions, so the terminal that runs the script does
-not need them, and it draws the agent's own cursor on screen. This Python
-version uses `pip install google-genai "cua-driver>=0.35.2"` and
-`GEMINI_API_KEY`. The TypeScript SDK has the same calls (`listToolsJson`,
-`callTool`) with `@google/genai` and `@trycua/cua-driver`.
-
-```python skip="no-runner"
-import asyncio, json, os, time
-
-from cua_driver import CuaDriver
-from google import genai
-
-MODEL = os.environ.get("GEMINI_MODEL", "gemini-4-argon")
-
-# launch_app and invoke_menu are left out because both can bring an app to the front.
-TOOLS = {"list_apps", "list_windows", "get_window_state", "click", "type_text",
- "set_value", "press_key", "hotkey", "scroll", "verify_state",
- "run_steps", "run_script"}
-
-SYSTEM_INSTRUCTION = """\
-You operate macOS apps through Cua Driver tools while the user keeps working on
-the same computer. Stay in the background: do not bring windows to the front.
-Before acting on a window, call get_window_state(pid, window_id) and use the
-element_token values from that snapshot; take a fresh snapshot after any change.
-Prefer accessibility actions over pixel coordinates. When the task is done,
-reply with a short summary and call no more tools."""
-
-TIMEOUT_S = 20 * 60 # One Gemini call can take several minutes.
-
-
-async def run(task: str, max_turns: int = 200) -> str:
- client = genai.Client()
- driver = CuaDriver.connect(None) # the Cua Driver service started earlier
- session = f"gemini-{int(time.time())}"
-
- async def call_tool(name: str, args: dict):
- return await driver.call_tool(name, json.dumps(args))
-
- try:
- await call_tool("start_session", {"session": session})
- await call_tool("set_agent_cursor_enabled", {"session": session, "enabled": True})
-
- catalog = json.loads(await driver.list_tools_json())["tools"]
- tools = [
- {"type": "function", "name": t["name"], "description": t["description"],
- "parameters": t["inputSchema"]}
- for t in catalog if t["name"] in TOOLS
- ]
- takes_session = {
- t["name"] for t in catalog if "session" in t["inputSchema"].get("properties", {})
- }
- request = dict(
- model=MODEL, tools=tools, system_instruction=SYSTEM_INSTRUCTION,
- generation_config={"thinking_level": "low", "max_output_tokens": 65536},
- timeout=TIMEOUT_S,
- )
- interaction = await client.aio.interactions.create(input=task, **request)
-
- for _ in range(max_turns):
- calls = [s for s in interaction.steps or [] if s.type == "function_call"]
- if not calls:
- return interaction.output_text or ""
-
- results = []
- for call in calls:
- args = dict(call.arguments)
- if call.name in takes_session:
- args["session"] = session
- result = await call_tool(call.name, args)
- content = [{"type": "text", "text": result.text or "ok"}]
- if result.structured_json: # window IDs, element tokens and other details
- content.append({"type": "text", "text": result.structured_json})
- content += [
- {"type": "image", "mime_type": i.mime_type, "data": i.data_base64}
- for i in result.images
- ]
- results.append({"type": "function_result", "name": call.name,
- "call_id": call.id, "result": content,
- "is_error": result.is_error})
-
- interaction = await client.aio.interactions.create(
- input=results, previous_interaction_id=interaction.id, **request
- )
- return f"Stopped after {max_turns} turns."
- finally:
- await call_tool("end_session", {"session": session})
- await driver.shutdown()
-
-
-print(asyncio.run(run("Add each person in signups.pdf (open in Preview) to Contacts")))
-```
-
-Open the apps the task needs before you run it. Keep working in another app
-while it runs.
-
-Settings that follow Google's
-[Gemini 4 Argon guidance](https://ai.google.dev/gemini-api/docs/latest-model):
-
-- **Use `thinking_level`, not `thinking_budget`.** Argon accepts `low`,
- `medium`, and `high`. Most UI steps are routine, so `low` keeps the loop
- responsive. Raise it when a task needs real planning.
-- **Set `max_output_tokens` to 65,536.** A low limit can stop the model before
- it finishes thinking.
-- **Allow long HTTP timeouts.** Google recommends at least 15 minutes per
- request. Give the whole task its own wall-clock budget instead of a short
- per-call limit.
-- **Leave out sampling parameters.** Argon ignores `temperature`, `top_p`, and
- `top_k`.
-- **Pass thought signatures back unchanged.** With `previous_interaction_id`,
- the server keeps them. If you keep history yourself (`store=False`), resend
- every model step exactly as you received it.
-
-Tips for long tasks:
-
-- With `previous_interaction_id`, every snapshot stays in the conversation, and
- a large window can return tens of thousands of tokens per snapshot. For long
- tasks, keep history yourself and drop old snapshots and screenshots.
-- Call `get_window_state` with `include_screenshot: false` when the agent only
- needs fresh element tokens.
-- Offer about a dozen tools, not all 50. Add the `browser_*` tools when the
- task is in a web page.
-- Run unattended agents in a separate macOS user account or a
- [VM](/cua-driver/guides/vms-and-remote), and keep purchases, messages,
- deletions, and credentials out of unattended tasks.
-
-For Google's built-in computer use tool, see the
-[computer use reference](https://ai.google.dev/gemini-api/docs/computer-use).
+Add Cua Driver to Antigravity, or call the Gemini API from your own agent loop:
+see [Computer use with Gemini](/cua-driver/guides/gemini).
## Local models
-Tested: Meta's Muse Glimmer 30B with Claude Code as the harness, served by
-Ollama or by llama.cpp with Unsloth's `UD-Q4_K_XL` GGUF. Every tool schema
-costs context, so hide unused tools with the filter:
-
-```bash skip="host-install"
-curl -fsSL https://cua.ai/docs-assets/examples/local-models/cua-mcp-filter.py \
- -o "$HOME/.local/bin/cua-mcp-filter" && chmod +x "$HOME/.local/bin/cua-mcp-filter"
-```
-
-Save as `muse-cua-mcp.json` (the filter hides tools; it does not authorize):
-
-```json test="config" id="json-config-local-model" schema="mcp-client-config"
-{
- "mcpServers": {
- "cua-computer-use": {
- "command": "cua-mcp-filter",
- "args": [
- "--allow",
- "start_session,end_session,launch_app,list_apps,list_windows,get_window_state,get_accessibility_tree,move_cursor,click,type_text,press_key,hotkey,invoke_menu"
- ]
- }
- }
-}
-```
-
-<Tabs items={['Ollama', 'llama.cpp']}>
- <Tab value="Ollama">
-
-```bash skip="third-party-cli"
-ollama pull muse-glimmer:30b-mlx
-CLAUDE_CODE_MAX_CONTEXT_TOKENS=131072 \
-ollama launch claude --model muse-glimmer:30b-mlx --yes -- \
- --bare --strict-mcp-config --mcp-config ./muse-cua-mcp.json --tools ""
-```
-
- </Tab>
- <Tab value="llama.cpp">
-
-```bash skip="third-party-cli"
-llama-server --hf-repo "unsloth/Muse-Glimmer-30B-GGUF:UD-Q4_K_XL" \
- --alias "muse-glimmer-local" --host 127.0.0.1 --port 8001 \
- --ctx-size 131072 --parallel 1 --temp 1.0 --top-p 0.95 --top-k 64 \
- --jinja --mmproj-auto --fit on --no-webui
-
-# In another terminal, once http://127.0.0.1:8001/health responds:
-ANTHROPIC_BASE_URL=http://127.0.0.1:8001 \
-ANTHROPIC_API_KEY=local-no-key-required \
-CLAUDE_CODE_MAX_CONTEXT_TOKENS=131072 \
-claude --bare --strict-mcp-config --mcp-config ./muse-cua-mcp.json \
- --tools "" --model muse-glimmer-local
-```
-
- </Tab>
-</Tabs>
-
-Keep context small: bound `get_window_state` with `max_elements` and
-`max_depth`, reuse `pid` and `window_id`, and batch text into one `type_text`.
-In the tested Calculator runs this cut uncached input from 71,088 to 12,251
-tokens. Use at least a 64K context window. To target a macOS VM, pass the
-guest's SSH MCP command ([Run in a VM](/cua-driver/guides/vms-and-remote#macos-lume-vm))
-to `cua-mcp-filter --driver`.
-
-### Text-only models
+Run Cua Driver with a model on your own machine, through Ollama or llama.cpp:
+see [Run Cua Driver with local models](/cua-driver/guides/local-models).
-For a model that cannot accept images, such as iFlytek Spark-X2.5 on the
-Astron Token Plan, add `--text-only` to the filter's `args`. The filter then
-requests `get_window_state` without a screenshot and replaces any remaining
-image content with a short text note, so the model works through the
-accessibility tree and its `element_token` values. Leave pixel-only tools such
-as `screenshot` and `zoom` out of the allowlist. Without `--text-only`, a
-provider that rejects images fails every request once a screenshot reaches
-the conversation. Apps that expose no usable accessibility elements (canvas,
-video, custom-drawn surfaces) need a vision model instead.
+## Setup for one agent
-<div className="not-prose my-8 grid gap-5 md:grid-cols-2">
- <VideoDemo
- src="https://cuademo06261324.blob.core.windows.net/artifacts/demos/muse-glimmer/notes-editorial.mp4"
- poster="https://cuademo06261324.blob.core.windows.net/artifacts/demos/muse-glimmer/notes-editorial-poster.jpg"
- title="Create a checklist in Apple Notes"
- >
- Muse Glimmer runs locally and completes the task through Cua Driver.
- </VideoDemo>
- <VideoDemo
- src="https://cuademo06261324.blob.core.windows.net/artifacts/demos/muse-glimmer/reminders-editorial.mp4"
- poster="https://cuademo06261324.blob.core.windows.net/artifacts/demos/muse-glimmer/reminders-editorial-poster.jpg"
- title="Schedule an Apple Reminder"
- >
- Muse Glimmer sets the reminder and verifies the final state.
- </VideoDemo>
-</div>
+[Claude Code](/cua-driver/guides/claude-code), [Codex](/cua-driver/guides/codex),
+[Cursor](/cua-driver/guides/cursor), [Hermes](/cua-driver/guides/hermes) and
+[OpenClaw](/cua-driver/guides/openclaw) each have a short page. To give an agent
+Cua Spaces instead, see [Connect your agent](/spaces/guides/connect-your-agent)
+and [Connect an agent over MCP](/cua-cli/guides/mcp-server).
diff --git a/docs/content/docs/cua-driver/guides/cursor.mdx b/docs/content/docs/cua-driver/guides/cursor.mdx
new file mode 100644
index 0000000000..58714e62b2
--- /dev/null
+++ b/docs/content/docs/cua-driver/guides/cursor.mdx
@@ -0,0 +1,12 @@
+---
+title: Cursor
+description: Give Cursor Cua Driver to use the apps on your computer, and Cua Spaces to work in computers you can watch.
+---
+
+## Cua Driver
+
+`cua-driver mcp-config --client cursor` prints the MCP configuration for Cursor. Paste it into `~/.cursor/mcp.json`, or into `.cursor/mcp.json` in a project, then restart Cursor. See [Connect your agent](/cua-driver/guides/connect-your-agent) for the skill, permissions and the other clients.
+
+## Cua Spaces
+
+`cua agents setup --agents cursor --yes` adds the `cua` skills and MCP server to `~/.cursor/mcp.json`, and the Cua Spaces app does the same on first run. Then ask Cursor: "List my Cua Spaces." See [Connect your agent to Cua Spaces](/spaces/guides/connect-your-agent) and [Give your agent Spaces](/cua-cli/guides/mcp-server).
diff --git a/docs/content/docs/cua-driver/guides/gemini.mdx b/docs/content/docs/cua-driver/guides/gemini.mdx
new file mode 100644
index 0000000000..a75c185d1c
--- /dev/null
+++ b/docs/content/docs/cua-driver/guides/gemini.mdx
@@ -0,0 +1,253 @@
+---
+title: Computer use with Gemini
+description: Use Gemini 4 Argon with Cua Driver through Antigravity, or from your own agent loop on the Gemini API.
+---
+
+Two ways to use Gemini 4 Argon (`gemini-4-argon`) with Cua Driver: add Cua Driver
+to Antigravity and write no code, or call the Gemini API from your own agent
+loop. Both need Cua Driver 0.35.2 or later on a Mac (check with
+`cua-driver --version`) with the permissions from the
+[Quickstart](/cua-driver/quickstart) granted. Windows and Linux use the same MCP
+server and SDKs: change "macOS apps" in the system instruction below to your
+platform.
+
+In each recording, Gemini works in the Mac apps on the left while a person
+types a long message into a chat app on the right with a real keyboard. The bar
+at the bottom counts the keystrokes the chat app received against the ones that
+were typed. The middle of each clip is sped up.
+
+<VideoDemo
+ src="https://github.com/user-attachments/assets/70e9cc74-0020-43cd-b974-3fb930288ec9"
+ poster="https://github.com/user-attachments/assets/619dc845-2af0-464e-8a03-b7ce945edec4"
+ title="Gemini 4 Argon turns a whiteboard photo into a Keynote deck with Cua Driver"
+>
+ Whiteboard photo to Keynote. Gemini read a photo of a hand-drawn product plan
+ in Preview and built a three-slide deck in Keynote: a title slide, the three
+ phases (skipping the crossed-out items), and a diagram of the system flow. The
+ run took about 8 minutes and 173 tool calls. All 2,541 of the person's
+ keystrokes reached the chat app.
+</VideoDemo>
+
+<VideoDemo
+ src="https://github.com/user-attachments/assets/28b57899-5681-4a64-8fca-f70762e5c95c"
+ poster="https://github.com/user-attachments/assets/84058332-45e0-49dd-a736-428ef4fd93d8"
+ title="Gemini 4 Argon summarizes a dashboard into Notes with Cua Driver"
+>
+ Dashboard to Notes. Gemini read a dense metrics dashboard in Preview, picked
+ the three largest changes from the previous period, and wrote them into a new
+ note with the old value, the new value, and the change. The run took about a
+ minute. All 503 keystrokes reached the chat app.
+</VideoDemo>
+
+<VideoDemo
+ src="https://github.com/user-attachments/assets/358b5547-2d38-4868-ba28-91e90b3c41b7"
+ poster="https://github.com/user-attachments/assets/38cb5c14-121f-42c5-a642-b4e92d8a59f9"
+ title="Gemini 4 Argon enters expenses into a native app with Cua Driver"
+>
+ Expenses into Ledger, a small native app with no scripting interface. Gemini
+ entered eight expenses through the app's form fields, and the app's total
+ matched the expected $3,271.29. The run took under two minutes. All 722
+ keystrokes reached the chat app.
+</VideoDemo>
+
+## With Antigravity, no code
+
+[Antigravity](https://antigravity.google/docs/home) runs agents on Gemini and
+supports local MCP servers. Gemini 4 Argon in Antigravity is available to Google
+AI Ultra subscribers. These steps use the Antigravity CLI, `agy`; the desktop
+app and IDE read the same MCP configuration.
+
+```bash skip="host-install"
+curl -fsSL https://antigravity.google/cli/install.sh | bash
+```
+
+Add Cua Driver as an MCP server. This writes it to
+`~/.gemini/config/mcp_config.json`.
+
+```bash skip="third-party-cli"
+agy mcp add cua-driver "$(command -v cua-driver)" mcp
+agy mcp list
+```
+
+```text output
+NAME TYPE STATUS COMMAND/URL
+cua-driver stdio enabled /Users/you/.local/bin/cua-driver mcp
+```
+
+To approve Cua Driver's tools once instead of on every call, add an allow rule
+to `~/.gemini/antigravity-cli/settings.json`:
+
+```json test="config" id="gemini-agy-settings"
+{
+ "permissions": {
+ "allow": ["mcp(cua-driver/*)"]
+ }
+}
+```
+
+Start `agy`, choose Gemini 4 Argon, and give it a task. Name the tools you want
+and say that someone is using the computer:
+
+```text output
+Use only the cua-driver tools. In Contacts, open Daniel Reyes and add this note
+to his card: "Met at the Design Systems Meetup booth." Save the card. Work in
+the background; I'm using the computer.
+```
+
+To run without the interactive interface, use print mode. Antigravity cannot
+ask you to approve a tool in print mode, so it denies any tool your allow list
+does not cover, such as shell commands.
+
+```bash skip="third-party-cli"
+agy -p "Use only the cua-driver tools. List the windows that are open right now."
+```
+
+## From your own agent loop
+
+To control the prompt, the tool set, and the loop, call the Gemini
+[Interactions API](https://ai.google.dev/gemini-api/docs/interactions) from your
+own process and run each tool call through Cua Driver. You need a Gemini API key
+from [Google AI Studio](https://aistudio.google.com/apikey) on a paid tier
+(Gemini 4 Argon is not on the free tier), and Python 3.10+ or Node.js 20+.
+
+![The agent loop: your script sends Gemini the task and Cua Driver's tool declarations, runs each function call through Cua Driver, and sends the result back until Gemini answers.](https://github.com/user-attachments/assets/bdfff431-0f7f-440c-867a-2905fbda4a98)
+
+The loop has three parts:
+
+- **Tool declarations.** `list_tools_json()` returns each tool with a JSON
+ Schema, which Gemini accepts as a function declaration unchanged.
+- **Tool calls.** `call_tool(name, arguments_json)` runs one tool and returns a
+ summary, structured details such as window IDs and element tokens, and
+ screenshots.
+- **Results.** Send each result back as a `function_result` with text and image
+ parts. Include the structured details: the window IDs and element tokens the
+ model needs next are there, not in the summary.
+
+`CuaDriver.connect(None)` attaches to the Cua Driver service you started. That
+service holds the macOS permissions, so the terminal that runs the script does
+not need them, and it draws the agent's own cursor on screen. This Python
+version uses `pip install google-genai "cua-driver>=0.35.2"` and
+`GEMINI_API_KEY`. The TypeScript SDK has the same calls (`listToolsJson`,
+`callTool`) with `@google/genai` and `@trycua/cua-driver`.
+
+```python skip="no-runner"
+import asyncio, json, os, time
+
+from cua_driver import CuaDriver
+from google import genai
+
+MODEL = os.environ.get("GEMINI_MODEL", "gemini-4-argon")
+
+# launch_app and invoke_menu are left out because both can bring an app to the front.
+TOOLS = {"list_apps", "list_windows", "get_window_state", "click", "type_text",
+ "set_value", "press_key", "hotkey", "scroll", "verify_state",
+ "run_steps", "run_script"}
+
+SYSTEM_INSTRUCTION = """\
+You operate macOS apps through Cua Driver tools while the user keeps working on
+the same computer. Stay in the background: do not bring windows to the front.
+Before acting on a window, call get_window_state(pid, window_id) and use the
+element_token values from that snapshot; take a fresh snapshot after any change.
+Prefer accessibility actions over pixel coordinates. When the task is done,
+reply with a short summary and call no more tools."""
+
+TIMEOUT_S = 20 * 60 # One Gemini call can take several minutes.
+
+
+async def run(task: str, max_turns: int = 200) -> str:
+ client = genai.Client()
+ driver = CuaDriver.connect(None) # the Cua Driver service started earlier
+ session = f"gemini-{int(time.time())}"
+
+ async def call_tool(name: str, args: dict):
+ return await driver.call_tool(name, json.dumps(args))
+
+ try:
+ await call_tool("start_session", {"session": session})
+ await call_tool("set_agent_cursor_enabled", {"session": session, "enabled": True})
+
+ catalog = json.loads(await driver.list_tools_json())["tools"]
+ tools = [
+ {"type": "function", "name": t["name"], "description": t["description"],
+ "parameters": t["inputSchema"]}
+ for t in catalog if t["name"] in TOOLS
+ ]
+ takes_session = {
+ t["name"] for t in catalog if "session" in t["inputSchema"].get("properties", {})
+ }
+ request = dict(
+ model=MODEL, tools=tools, system_instruction=SYSTEM_INSTRUCTION,
+ generation_config={"thinking_level": "low", "max_output_tokens": 65536},
+ timeout=TIMEOUT_S,
+ )
+ interaction = await client.aio.interactions.create(input=task, **request)
+
+ for _ in range(max_turns):
+ calls = [s for s in interaction.steps or [] if s.type == "function_call"]
+ if not calls:
+ return interaction.output_text or ""
+
+ results = []
+ for call in calls:
+ args = dict(call.arguments)
+ if call.name in takes_session:
+ args["session"] = session
+ result = await call_tool(call.name, args)
+ content = [{"type": "text", "text": result.text or "ok"}]
+ if result.structured_json: # window IDs, element tokens and other details
+ content.append({"type": "text", "text": result.structured_json})
+ content += [
+ {"type": "image", "mime_type": i.mime_type, "data": i.data_base64}
+ for i in result.images
+ ]
+ results.append({"type": "function_result", "name": call.name,
+ "call_id": call.id, "result": content,
+ "is_error": result.is_error})
+
+ interaction = await client.aio.interactions.create(
+ input=results, previous_interaction_id=interaction.id, **request
+ )
+ return f"Stopped after {max_turns} turns."
+ finally:
+ await call_tool("end_session", {"session": session})
+ await driver.shutdown()
+
+
+print(asyncio.run(run("Add each person in signups.pdf (open in Preview) to Contacts")))
+```
+
+Open the apps the task needs before you run it. Keep working in another app
+while it runs.
+
+Settings that follow Google's
+[Gemini 4 Argon guidance](https://ai.google.dev/gemini-api/docs/latest-model):
+
+- **Use `thinking_level`, not `thinking_budget`.** Argon accepts `low`,
+ `medium`, and `high`. Most UI steps are routine, so `low` keeps the loop
+ responsive. Raise it when a task needs real planning.
+- **Set `max_output_tokens` to 65,536.** A low limit can stop the model before
+ it finishes thinking.
+- **Allow long HTTP timeouts.** Google recommends at least 15 minutes per
+ request. Give the whole task its own wall-clock budget instead of a short
+ per-call limit.
+- **Leave out sampling parameters.** Argon ignores `temperature`, `top_p`, and
+ `top_k`.
+- **Pass thought signatures back unchanged.** With `previous_interaction_id`,
+ the server keeps them. If you keep history yourself (`store=False`), resend
+ every model step exactly as you received it.
+
+Tips for long tasks:
+
+- With `previous_interaction_id`, every snapshot stays in the conversation, and
+ a large window can return tens of thousands of tokens per snapshot. For long
+ tasks, keep history yourself and drop old snapshots and screenshots.
+- Call `get_window_state` with `include_screenshot: false` when the agent only
+ needs fresh element tokens.
+- Offer about a dozen tools, not all 50. Add the `browser_*` tools when the
+ task is in a web page.
+- Run unattended agents in a separate macOS user account or a
+ [VM](/cua-driver/guides/vms-and-remote), and keep purchases, messages,
+ deletions, and credentials out of unattended tasks.
+
+For Google's built-in computer use tool, see the
+[computer use reference](https://ai.google.dev/gemini-api/docs/computer-use).
diff --git a/docs/content/docs/cua-driver/guides/hermes.mdx b/docs/content/docs/cua-driver/guides/hermes.mdx
new file mode 100644
index 0000000000..0a74257199
--- /dev/null
+++ b/docs/content/docs/cua-driver/guides/hermes.mdx
@@ -0,0 +1,19 @@
+---
+title: Hermes
+description: Give Hermes Agent Cua Driver to use the apps on your computer, and Cua Spaces to work in computers you can watch.
+---
+
+## Cua Driver
+
+Hermes has Cua Driver built in. Turn it on, then start a chat with it:
+
+```bash skip="third-party-cli"
+hermes tools enable computer_use --platform cli
+hermes -t computer_use chat
+```
+
+Repair it with `hermes computer-use install` and `doctor`. Do not add a second raw MCP server. See [Connect your agent](/cua-driver/guides/connect-your-agent) for the other clients.
+
+## Cua Spaces
+
+`cua agents setup --agents hermes --yes` adds the `cua` skills and MCP server to `~/.hermes/config.yaml`. Start a new Hermes session, or run `/reload-mcp`, to load the server. On Windows, Hermes lives in `%LOCALAPPDATA%\hermes`. See [Give your agent Spaces](/cua-cli/guides/mcp-server).
diff --git a/docs/content/docs/cua-driver/guides/local-models.mdx b/docs/content/docs/cua-driver/guides/local-models.mdx
new file mode 100644
index 0000000000..1d101db922
--- /dev/null
+++ b/docs/content/docs/cua-driver/guides/local-models.mdx
@@ -0,0 +1,97 @@
+---
+title: Run Cua Driver with local models
+description: Drive apps with a model on your own machine through Ollama or llama.cpp, and keep the tool list small enough for its context window.
+---
+
+import { Tabs, Tab } from 'fumadocs-ui/components/tabs';
+
+Tested: Meta's Muse Glimmer 30B with Claude Code as the harness, served by
+Ollama or by llama.cpp with Unsloth's `UD-Q4_K_XL` GGUF. Every tool schema
+costs context, so hide unused tools with the filter:
+
+```bash skip="host-install"
+curl -fsSL https://cua.ai/docs-assets/examples/local-models/cua-mcp-filter.py \
+ -o "$HOME/.local/bin/cua-mcp-filter" && chmod +x "$HOME/.local/bin/cua-mcp-filter"
+```
+
+Save as `muse-cua-mcp.json` (the filter hides tools; it does not authorize):
+
+```json test="config" id="json-config-local-model" schema="mcp-client-config"
+{
+ "mcpServers": {
+ "cua-computer-use": {
+ "command": "cua-mcp-filter",
+ "args": [
+ "--allow",
+ "start_session,end_session,launch_app,list_apps,list_windows,get_window_state,get_accessibility_tree,move_cursor,click,type_text,press_key,hotkey,invoke_menu"
+ ]
+ }
+ }
+}
+```
+
+<Tabs items={['Ollama', 'llama.cpp']}>
+ <Tab value="Ollama">
+
+```bash skip="third-party-cli"
+ollama pull muse-glimmer:30b-mlx
+CLAUDE_CODE_MAX_CONTEXT_TOKENS=131072 \
+ollama launch claude --model muse-glimmer:30b-mlx --yes -- \
+ --bare --strict-mcp-config --mcp-config ./muse-cua-mcp.json --tools ""
+```
+
+ </Tab>
+ <Tab value="llama.cpp">
+
+```bash skip="third-party-cli"
+llama-server --hf-repo "unsloth/Muse-Glimmer-30B-GGUF:UD-Q4_K_XL" \
+ --alias "muse-glimmer-local" --host 127.0.0.1 --port 8001 \
+ --ctx-size 131072 --parallel 1 --temp 1.0 --top-p 0.95 --top-k 64 \
+ --jinja --mmproj-auto --fit on --no-webui
+
+# In another terminal, once http://127.0.0.1:8001/health responds:
+ANTHROPIC_BASE_URL=http://127.0.0.1:8001 \
+ANTHROPIC_API_KEY=local-no-key-required \
+CLAUDE_CODE_MAX_CONTEXT_TOKENS=131072 \
+claude --bare --strict-mcp-config --mcp-config ./muse-cua-mcp.json \
+ --tools "" --model muse-glimmer-local
+```
+
+ </Tab>
+</Tabs>
+
+Keep context small: bound `get_window_state` with `max_elements` and
+`max_depth`, reuse `pid` and `window_id`, and batch text into one `type_text`.
+In the tested Calculator runs this cut uncached input from 71,088 to 12,251
+tokens. Use at least a 64K context window. To target a macOS VM, pass the
+guest's SSH MCP command ([Run in a VM](/cua-driver/guides/vms-and-remote#macos-lume-vm))
+to `cua-mcp-filter --driver`.
+
+## Text-only models
+
+For a model that cannot accept images, such as iFlytek Spark-X2.5 on the
+Astron Token Plan, add `--text-only` to the filter's `args`. The filter then
+requests `get_window_state` without a screenshot and replaces any remaining
+image content with a short text note, so the model works through the
+accessibility tree and its `element_token` values. Leave pixel-only tools such
+as `screenshot` and `zoom` out of the allowlist. Without `--text-only`, a
+provider that rejects images fails every request once a screenshot reaches
+the conversation. Apps that expose no usable accessibility elements (canvas,
+video, custom-drawn surfaces) need a vision model instead.
+
+<div className="not-prose my-8 grid gap-5 md:grid-cols-2">
+ <VideoDemo
+ src="https://cuademo06261324.blob.core.windows.net/artifacts/demos/muse-glimmer/notes-editorial.mp4"
+ poster="https://cuademo06261324.blob.core.windows.net/artifacts/demos/muse-glimmer/notes-editorial-poster.jpg"
+ title="Create a checklist in Apple Notes"
+ >
+ Muse Glimmer runs locally and completes the task through Cua Driver.
+ </VideoDemo>
+ <VideoDemo
+ src="https://cuademo06261324.blob.core.windows.net/artifacts/demos/muse-glimmer/reminders-editorial.mp4"
+ poster="https://cuademo06261324.blob.core.windows.net/artifacts/demos/muse-glimmer/reminders-editorial-poster.jpg"
+ title="Schedule an Apple Reminder"
+ >
+ Muse Glimmer sets the reminder and verifies the final state.
+ </VideoDemo>
+</div>
diff --git a/docs/content/docs/cua-driver/guides/meta.json b/docs/content/docs/cua-driver/guides/meta.json
deleted file mode 100644
index aec9033f16..0000000000
--- a/docs/content/docs/cua-driver/guides/meta.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "title": "Guides",
- "pages": [
- "connect-your-agent",
- "permissions",
- "browsers",
- "visual-regions",
- "operate",
- "vms-and-remote",
- "use-the-sdk",
- "recipes",
- "troubleshoot"
- ]
-}
diff --git a/docs/content/docs/cua-driver/guides/openclaw.mdx b/docs/content/docs/cua-driver/guides/openclaw.mdx
new file mode 100644
index 0000000000..55d7dfa676
--- /dev/null
+++ b/docs/content/docs/cua-driver/guides/openclaw.mdx
@@ -0,0 +1,14 @@
+---
+title: OpenClaw
+description: Give OpenClaw Cua Driver to use the apps on your computer, and Cua Spaces to work in computers you can watch.
+---
+
+## Cua Driver
+
+`cua-driver mcp-config --client openclaw` prints the command to register Cua Driver, `openclaw mcp set cua-driver '{…}'`. Run it, then restart OpenClaw. On macOS, a server spawned by the OpenClaw gateway does not inherit OpenClaw.app's permissions.
+
+OpenClaw can also install the skill from ClawHub: `clawhub install @cua/driver`. See [Connect your agent](/cua-driver/guides/connect-your-agent) for permissions and the other clients.
+
+## Cua Spaces
+
+`cua agents setup --agents openclaw --yes` adds the `cua` skills and MCP server to `~/.openclaw/openclaw.json`. See [Give your agent Spaces](/cua-cli/guides/mcp-server).
diff --git a/docs/content/docs/cua-driver/meta.json b/docs/content/docs/cua-driver/meta.json
index 288bc8b2e0..459039ab9b 100644
--- a/docs/content/docs/cua-driver/meta.json
+++ b/docs/content/docs/cua-driver/meta.json
@@ -3,9 +3,30 @@
"root": true,
"pages": [
"index",
+ "what-is-computer-use",
"quickstart",
- "guides",
- "concepts",
+ "concepts/platform-support",
+ "concepts/how-cua-driver-works",
+ "---Use with your agent---",
+ "guides/connect-your-agent",
+ "guides/claude-code",
+ "guides/codex",
+ "guides/cursor",
+ "guides/gemini",
+ "guides/hermes",
+ "guides/openclaw",
+ "guides/local-models",
+ "---Set up---",
+ "guides/permissions",
+ "guides/use-the-sdk",
+ "guides/vms-and-remote",
+ "guides/operate",
+ "---Drive apps---",
+ "guides/browsers",
+ "guides/visual-regions",
+ "guides/recipes",
+ "---Fix---",
+ "guides/troubleshoot",
"reference"
]
}
diff --git a/docs/content/docs/cua-driver/what-is-computer-use.mdx b/docs/content/docs/cua-driver/what-is-computer-use.mdx
new file mode 100644
index 0000000000..6146799ad2
--- /dev/null
+++ b/docs/content/docs/cua-driver/what-is-computer-use.mdx
@@ -0,0 +1,42 @@
+---
+title: What is computer use
+description: What computer use is, how a computer-use agent sees and acts on a computer, background versus foreground control, and where Cua Driver and Cua Spaces fit.
+---
+
+**Computer use** means an AI agent works on a computer the way a person does. It looks at what is on the screen, decides what to do next, clicks or types, checks what changed, and keeps going until the job is done.
+
+The model alone does not do this. A **computer-use model** reads an observation and proposes an action. A **computer-use agent** is the program around it: the loop, the instructions, the permissions and the computer it acts on. Claude Code and Codex are examples of agent harnesses. They run the model and the loop, and they call tools to reach the computer.
+
+```text output
+model -> agent harness -> tool layer -> operating system and apps
+```
+
+Cua Driver is the tool layer in that chain. It does not choose or run a model.
+
+## How an agent sees a computer
+
+An agent can read a computer in two ways, and the best results use both:
+
+- **The accessibility tree.** Operating systems describe every window to assistive software such as screen readers: each button, field and menu, with its role and label. This tells the agent what can be acted on, and it is compact text.
+- **Screenshots.** A picture shows what the tree leaves out or gets wrong: a canvas, a video, an app that labels nothing. It also lets a vision model check that the result looks right.
+
+In Cua Driver, one call (`get_window_state`) returns the tree and a screenshot of a window together. Each element in the tree gets a token the agent can act on, so it does not have to guess pixel coordinates.
+
+## How an agent acts
+
+The agent clicks, types, presses keys, scrolls and drags. A good tool layer prefers the most exact route: act on a named element through the accessibility API, and fall back to pixel coordinates only for things the tree does not expose. After each step the agent reads the state again to confirm the step worked before it plans the next one.
+
+Not every task needs the screen. An agent should use the most direct route that works: run code for text-heavy work, call an API or an MCP tool where one exists, and drive the interface for software that offers nothing else.
+
+## Background and foreground control
+
+**Foreground** control moves the real mouse and takes the keyboard. It works everywhere, but the person cannot use the computer at the same time, and a stray click from either side can break the run.
+
+**Background** control sends input to the target app without moving the cursor or bringing its window to the front. You keep working in another app while the agent works in this one. Cua Driver acts in the background by default on macOS, Windows and Linux.
+
+## Where Cua Driver and Cua Spaces fit
+
+- **[Cua Driver](/cua-driver)** lets an agent use the apps on the computer it runs on, in the background. [Install it](/cua-driver/quickstart), then [connect your agent](/cua-driver/guides/connect-your-agent).
+- **[Cua Spaces](/spaces)** gives agents their own computers that you can watch and step into, on machines you own, and share with your team. Start with the [Spaces quickstart](/spaces/quickstart).
+
+To see how the pieces work in detail, read [How Cua Driver works](/cua-driver/concepts/how-cua-driver-works).
diff --git a/docs/content/docs/cua-sdk/meta.json b/docs/content/docs/cua-sdk/meta.json
index 98aae4296d..18b2cdce76 100644
--- a/docs/content/docs/cua-sdk/meta.json
+++ b/docs/content/docs/cua-sdk/meta.json
@@ -4,8 +4,8 @@
"pages": [
"index",
"quickstart",
+ "concepts/how-sandboxes-work",
"guides",
- "concepts",
"reference"
]
}
diff --git a/docs/content/docs/cua-sdk/reference/meta.json b/docs/content/docs/cua-sdk/reference/meta.json
index 4095e7157e..4f0a703bff 100644
--- a/docs/content/docs/cua-sdk/reference/meta.json
+++ b/docs/content/docs/cua-sdk/reference/meta.json
@@ -25,6 +25,11 @@
"typescript",
"rust",
"---Protocol---",
- "protocol"
+ "protocol",
+ "---Telemetry---",
+ "../concepts/telemetry",
+ "../concepts/telemetry-events",
+ "../concepts/telemetry-counting",
+ "../concepts/telemetry-error-kinds"
]
}
diff --git a/docs/content/docs/docs-for-agents.mdx b/docs/content/docs/docs-for-agents.mdx
index 6a336ed524..8acc7ed414 100644
--- a/docs/content/docs/docs-for-agents.mdx
+++ b/docs/content/docs/docs-for-agents.mdx
@@ -9,8 +9,8 @@ description: Give a coding agent Cua's docs and source as Markdown or over MCP.
| --- | --- | --- |
| Cua Spaces | `/docs/spaces` | The app: quickstart, task guides, how it works |
| Cua Driver | `/docs/cua-driver` | Quickstart, guides, every command and tool |
-| Reference | `/docs/cua-cli`, `/docs/cua-sdk` | The `cua` command and the SDK |
-| More tools | `/docs/lume`, `/docs/cua-bench` | Lume virtual machines and Cua Bench |
+| Lume | `/docs/lume` | Lume virtual machines |
+| Developers | `/docs/cua-sdk`, `/docs/cua-cli`, `/docs/cua-bench` | The SDK, the `cua` command and Cua Bench |
Old page URLs redirect to the page that replaced them.
diff --git a/docs/content/docs/index.mdx b/docs/content/docs/index.mdx
index 824f099c07..6f8be00d2b 100644
--- a/docs/content/docs/index.mdx
+++ b/docs/content/docs/index.mdx
@@ -49,15 +49,19 @@ import { Card, Cards } from 'fumadocs-ui/components/card';
## Cua Driver
+- [What is computer use](/cua-driver/what-is-computer-use): how agents see and act on a computer.
- [Quickstart](/cua-driver/quickstart): install Cua Driver and have your agent use a calculator.
- [Connect your agent](/cua-driver/guides/connect-your-agent): add Cua Driver to Claude Code, Codex and other agents.
- [Tool reference](/cua-driver/reference): every command and every tool.
-## More tools
+## Lume
-- [Cua CLI](/cua-cli): the `cua` command for Spaces, sandboxes, sign-in and MCP.
-- [Cua SDK](/cua-sdk): create and drive computers from your own code, in Python, TypeScript and Rust ([no agent layer](/cua-sdk/guides/own-harness)).
- [Lume](/lume): macOS and Linux virtual machines on Apple silicon.
+
+## Developers
+
+- [Cua SDK](/cua-sdk): create and drive computers from your own code, in Python, TypeScript and Rust ([no agent layer](/cua-sdk/guides/own-harness)).
+- [Cua CLI](/cua-cli): the `cua` command for Spaces, sandboxes, sign-in and MCP.
- [Cua Bench](/cua-bench): run and score computer-use tests on your computer.
- [Docs for agents](/docs-for-agents): give a coding agent these docs as Markdown or over MCP.
diff --git a/docs/content/docs/lume/meta.json b/docs/content/docs/lume/meta.json
index 749b462111..b3807b9c0d 100644
--- a/docs/content/docs/lume/meta.json
+++ b/docs/content/docs/lume/meta.json
@@ -4,8 +4,8 @@
"pages": [
"index",
"quickstart",
+ "concepts/how-lume-works",
"guides",
- "concepts",
"reference"
]
}
diff --git a/docs/content/docs/meta.json b/docs/content/docs/meta.json
index 43dfce3867..e8e5ef5312 100644
--- a/docs/content/docs/meta.json
+++ b/docs/content/docs/meta.json
@@ -5,10 +5,9 @@
"index",
"spaces",
"cua-driver",
- "---More tools---",
- "cua-cli",
- "cua-sdk",
"lume",
+ "cua-sdk",
+ "cua-cli",
"cua-bench"
]
}
diff --git a/docs/content/docs/redirects.json b/docs/content/docs/redirects.json
index 0d6e9ffc0d..006007f2a0 100644
--- a/docs/content/docs/redirects.json
+++ b/docs/content/docs/redirects.json
@@ -25,7 +25,7 @@
"concepts/sandbox-lifecycle": "cua-sdk/guides/lifecycle",
"concepts/sdk-mcp-and-hosting": "cua-driver/concepts/how-cua-driver-works",
"concepts/the-no-foreground-contract": "cua-driver/concepts/how-cua-driver-works",
- "concepts/what-is-computer-use": "cua-driver/concepts/how-cua-driver-works",
+ "concepts/what-is-computer-use": "cua-driver/what-is-computer-use",
"concepts/what-is-cua-bench": "cua-bench",
"cua-bench/benchmarks": "cua-bench/guides/benchmarks",
"cua-bench/benchmarks/cua-bench-basic": "cua-bench/guides/benchmarks",
@@ -64,7 +64,7 @@
"cua-driver/concepts/sdk-reference": "cua-driver/guides/use-the-sdk",
"cua-driver/concepts/telemetry": "cua-driver/guides/operate",
"cua-driver/concepts/the-no-foreground-contract": "cua-driver/concepts/how-cua-driver-works",
- "cua-driver/concepts/what-is-computer-use": "cua-driver/concepts/how-cua-driver-works",
+ "cua-driver/concepts/what-is-computer-use": "cua-driver/what-is-computer-use",
"cua-driver/guides/drive-a-web-page": "cua-driver/guides/browsers",
"cua-driver/guides/expose-mcp-from-desktop-app": "cua-driver/guides/use-the-sdk",
"cua-driver/guides/install": "cua-driver/quickstart",
@@ -452,7 +452,6 @@
"start-here/run-in-github-actions": "cua-sdk/guides/test-in-ci",
"start-here/create-a-local-macos-sandbox": "cua-cli/quickstart#macos-sandbox",
"start-here/your-first-cua-bench-task": "cua-bench/quickstart#create-your-own-task",
- "cua-driver/guides/gemini": "cua-driver/guides/connect-your-agent#gemini",
"cua-driver/guides/trajectories": "cua-driver/guides/operate#record-a-trajectory",
"cua-driver/guides/test-in-a-sandbox": "cua-driver/guides/vms-and-remote#test-a-driver-build-in-a-sandbox",
"cua-driver/guides/cursor-motion": "cua-driver/guides/recipes#design-a-cursor-motion",
@@ -636,6 +635,10 @@
"spaces/reference/sharing": "spaces/reference/spaces#sharing",
"spaces/reference/streams-and-display": "spaces/reference/spaces#streams-and-display",
"spaces/reference/teleport": "spaces/reference/agents#session-teleport",
- "spaces/reference/volume": "spaces/reference/agents#cua-volume"
+ "spaces/reference/volume": "spaces/reference/agents#cua-volume",
+ "explanation/the-no-foreground-contract": "cua-driver/concepts/how-cua-driver-works",
+ "how-to-guides/sandbox/create-pool-with-typescript": "cua-sdk/guides/cua-cloud-ended",
+ "use-cua-with/grok-bot": "cua-driver/guides/connect-your-agent",
+ "agents": "cua-driver/guides/connect-your-agent"
}
}
diff --git a/docs/content/docs/spaces/guides/coding-agents-in-a-space.mdx b/docs/content/docs/spaces/guides/coding-agents-in-a-space.mdx
new file mode 100644
index 0000000000..d3aae61d79
--- /dev/null
+++ b/docs/content/docs/spaces/guides/coding-agents-in-a-space.mdx
@@ -0,0 +1,10 @@
+---
+title: Coding agents in a Space
+description: Start Claude Code, Codex and other coding agents inside a Space or sandbox, and follow their work from your own agent, the CLI or code.
+---
+
+A coding agent can run inside a computer of its own, so it works on a copy you can watch and discard instead of on your machine.
+
+- **From an agent you already use.** An agent with the Spaces tools can start other agents inside a Space as long-lived runs: see [Run an agent inside a Space](/spaces/guides/connect-your-agent#run-an-agent-inside-a-space). Add Spaces to your agent first with [Connect your agent to Cua Spaces](/spaces/guides/connect-your-agent).
+- **From code.** `sandbox.agents()` installs a harness (Claude Code, Codex, Gemini CLI, OpenCode, Goose and others) in a sandbox, streams its events, takes follow-ups and collects the result: see [Run a coding agent in a sandbox](/cua-sdk/guides/run-a-coding-agent).
+- **With an agent framework.** [Run agent frameworks in a sandbox](/cua-sdk/guides/agent-frameworks) runs OpenAI Agents, Codex, Cursor and OpenClaw in Cua sandboxes.
diff --git a/docs/content/docs/spaces/guides/meta.json b/docs/content/docs/spaces/guides/meta.json
deleted file mode 100644
index b72d64b62d..0000000000
--- a/docs/content/docs/spaces/guides/meta.json
+++ /dev/null
@@ -1,26 +0,0 @@
-{
- "title": "Guides",
- "pages": [
- "---Get started---",
- "install",
- "connect-your-agent",
- "add-a-space",
- "add-a-computer",
- "---Teams and sharing---",
- "teams",
- "share-a-space",
- "---Work in a Space---",
- "stream-a-desktop",
- "teleport-an-app",
- "keyvault",
- "cua-volume",
- "persistent-agents",
- "create-a-space-with-the-sdk",
- "use-grok-bot-dots-and-pi-with-spaces",
- "---Keep it working---",
- "troubleshoot",
- "uninstall",
- "---Advanced---",
- "relay-security"
- ]
-}
diff --git a/docs/content/docs/spaces/meta.json b/docs/content/docs/spaces/meta.json
index 94e2271d39..c7ef63d108 100644
--- a/docs/content/docs/spaces/meta.json
+++ b/docs/content/docs/spaces/meta.json
@@ -4,9 +4,30 @@
"pages": [
"index",
"quickstart",
- "guides",
+ "concepts/how-spaces-works",
+ "---Get started---",
+ "guides/install",
+ "guides/connect-your-agent",
+ "guides/add-a-space",
+ "guides/add-a-computer",
+ "---Teams and sharing---",
+ "guides/teams",
+ "guides/share-a-space",
+ "---Work in a Space---",
+ "guides/stream-a-desktop",
+ "guides/teleport-an-app",
+ "guides/keyvault",
+ "guides/cua-volume",
+ "guides/persistent-agents",
+ "guides/coding-agents-in-a-space",
+ "guides/create-a-space-with-the-sdk",
+ "guides/use-grok-bot-dots-and-pi-with-spaces",
+ "---Keep it working---",
+ "guides/troubleshoot",
+ "guides/uninstall",
+ "---Advanced---",
+ "guides/relay-security",
"examples",
- "concepts",
"reference"
]
}
diff --git a/docs/redirects-ia-2026-10.csv b/docs/redirects-ia-2026-10.csv
new file mode 100644
index 0000000000..5395474706
--- /dev/null
+++ b/docs/redirects-ia-2026-10.csv
@@ -0,0 +1,52 @@
+old,new
+/docs/concepts/what-is-computer-use,/docs/cua-driver/what-is-computer-use
+/docs/cua-driver/concepts/what-is-computer-use,/docs/cua-driver/what-is-computer-use
+/docs/explanation/the-no-foreground-contract,/docs/cua-driver/concepts/how-cua-driver-works
+/docs/how-to-guides/sandbox/create-pool-with-typescript,/docs/cua-sdk/guides/cua-cloud-ended
+/docs/use-cua-with/grok-bot,/docs/cua-driver/guides/connect-your-agent
+/docs/agents,/docs/cua-driver/guides/connect-your-agent
+/docs/start-here,/docs/spaces/quickstart
+/docs/start-here/your-first-cloud-fleet,/docs/spaces/guides/create-a-space-with-the-sdk
+/docs/start-here/create-a-space-with-the-sdk,/docs/spaces/guides/create-a-space-with-the-sdk
+/docs/cua-sdk/reference/spaces/drive-app-core,/docs/cua-sdk/reference/spaces/volume
+/docs/start-here/drive-your-first-app,/docs/cua-driver/quickstart
+/docs/start-here/run-in-github-actions,/docs/cua-sdk/guides/test-in-ci
+/docs/cua-sdk/reference/spaces/account-app-core,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/agents-app-core,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/about,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/agent-keys,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/cloud,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/creates,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/devices,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/drag-trigger,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/experiments,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/images,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/keyvault,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/keyvault-screens,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/new-space,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/notch,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/onboarding-previews,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/onboarding-settings,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/power,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/run-on,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/share,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/spaces,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/stream,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/telemetry,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/teleport,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/teleport-grid,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/teleport-review,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/teleport-run,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/teleport-transfer,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/this-machine,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/app-core/window,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/machines-app-core,/docs/cua-sdk/reference/spaces
+/docs/cua-sdk/reference/spaces/volume-app-core,/docs/cua-sdk/reference/spaces/volume
+/docs,/docs
+/docs/spaces,/docs/spaces
+/docs/lume,/docs/lume
+/docs/lume/quickstart,/docs/lume/quickstart
+/docs/lume/reference/cli,/docs/lume/reference/cli
+/docs/cua-driver/quickstart,/docs/cua-driver/quickstart
+/docs/cua-driver/guides/connect-your-agent,/docs/cua-driver/guides/connect-your-agent
diff --git a/docs/scripts/product-structure.test.ts b/docs/scripts/product-structure.test.ts
index 0f5c265e36..7fbffcc66e 100644
--- a/docs/scripts/product-structure.test.ts
+++ b/docs/scripts/product-structure.test.ts
@@ -11,30 +11,35 @@ const docs = path.resolve(__dirname, '..');
const repo = path.resolve(docs, '..');
const content = path.join(docs, 'content/docs');
-// In sidebar order: Cua Spaces (the product), Cua Driver, then one More tools
-// group (the CLI, the SDK, Lume and Cua Bench).
+// In sidebar order. The product switcher shows Cua Spaces and Cua Driver; the
+// renderer lists the rest (Lume, SDK, CLI, Bench) under "More docs".
const PRODUCTS: Array<[string, string]> = [
['spaces', 'Cua Spaces'],
['cua-driver', 'Cua Driver'],
- ['cua-cli', 'Cua CLI'],
- ['cua-sdk', 'Cua SDK'],
['lume', 'Lume'],
+ ['cua-sdk', 'Cua SDK'],
+ ['cua-cli', 'Cua CLI'],
['cua-bench', 'Cua Bench'],
];
-// The root meta.json: the products in order, with the More tools separator.
+// The root meta.json: the products in order, no group headings.
const ROOT_ORDER = [
'index',
'spaces',
'cua-driver',
- '---More tools---',
- 'cua-cli',
- 'cua-sdk',
'lume',
+ 'cua-sdk',
+ 'cua-cli',
'cua-bench',
];
-// Sections in their only allowed order; `examples` and `concepts` are optional.
-const SECTIONS = ['index', 'quickstart', 'guides', 'examples', 'concepts', 'reference'];
-const OPTIONAL = new Set(['examples', 'concepts']);
+// Sections in their only allowed order; `examples` is optional. "How X works"
+// pages from `concepts/` are listed by path right after the Overview and
+// Quickstart (no Concepts group in the sidebar); Cua Driver also opens with
+// its "What is computer use" explainer. A product whose guides fall into
+// groups lists them inline instead of `guides` (`---Get started---`,
+// `guides/install`, ...), so each group is a sidebar section of its own.
+const SECTIONS = ['index', 'quickstart', 'guides', 'examples', 'reference'];
+const OPTIONAL = new Set(['examples']);
+const INTRO_PAGES = new Set(['what-is-computer-use']);
const SECTION_TITLES: Record<string, string> = {
guides: 'Guides',
examples: 'Examples',
@@ -76,7 +81,7 @@ function slugs(): Set<string> {
);
}
-test('the root lists the products in order, with the CLI, SDK, Lume and Bench under More tools', () => {
+test('the root lists every product in order, with no group headings', () => {
assert.deepEqual(meta('').pages, ROOT_ORDER);
assert.deepEqual(
ROOT_ORDER.filter((page) => page !== 'index' && !page.startsWith('---')),
@@ -131,20 +136,51 @@ for (const [dir, title] of PRODUCTS) {
const m = meta(dir);
assert.equal(m.title, title);
assert.equal(m.root, true, `${dir}/meta.json must be a root folder (its own sidebar tab)`);
- const pages = m.pages ?? [];
+ const authored = m.pages ?? [];
+ const inline = authored.filter((p) => p.startsWith('guides/'));
+ // Inline guides stand in for the `guides` folder, at its place.
+ const all = authored.flatMap((p, i) =>
+ p.startsWith('guides/') || p.startsWith('---')
+ ? authored.slice(0, i).some((q) => q.startsWith('guides/') || q.startsWith('---'))
+ ? []
+ : ['guides']
+ : [p]
+ );
+ if (inline.length) {
+ assert.ok(!existsSync(path.join(content, dir, 'guides/meta.json')), `${dir}: list guides inline or in guides/meta.json, not both`);
+ const files = readdirSync(path.join(content, dir, 'guides')).filter((f) => f.endsWith('.mdx')).map((f) => `guides/${f.replace(/\.mdx$/, '')}`);
+ assert.deepEqual([...inline].sort(), files.sort(), `${dir}: every guide is listed once`);
+ assert.ok(authored.indexOf(inline[0]) > 0 && authored[authored.indexOf(inline[0]) - 1].startsWith('---'), `${dir}: inline guides start under a ---Section--- heading`);
+ }
+ const concepts = all.filter((p) => p.startsWith('concepts/'));
+ const pages = all.filter((p) => !p.startsWith('concepts/') && !INTRO_PAGES.has(p));
const expected = SECTIONS.filter(
(section) => !OPTIONAL.has(section) || pages.includes(section)
);
assert.deepEqual(pages, expected, `${dir}/meta.json pages must be ${expected.join(', ')}`);
+ // Concept pages sit between the Quickstart and the Guides, and no page is left out.
+ assert.deepEqual(all.slice(all.indexOf('quickstart') + 1, all.indexOf('guides')).filter((p) => !p.startsWith('concepts/')), []);
+ assert.ok(all.indexOf('quickstart') < all.indexOf('guides'));
+ const listed = new Set([...concepts, ...(existsSync(path.join(content, dir, 'reference/meta.json')) ? (meta(path.join(dir, 'reference')).pages ?? []).filter((p) => p.startsWith('../concepts/')).map((p) => p.slice(3)) : [])]);
+ const conceptDir = path.join(content, dir, 'concepts');
+ if (existsSync(conceptDir)) {
+ for (const file of readdirSync(conceptDir).filter((f) => f.endsWith('.mdx'))) {
+ assert.ok(listed.has(`concepts/${file.replace(/\.mdx$/, '')}`), `${dir}/concepts/${file} is not in the sidebar`);
+ }
+ }
assert.ok(existsSync(path.join(content, dir, 'index.mdx')), `${dir}/index.mdx (Overview)`);
assert.ok(existsSync(path.join(content, dir, 'quickstart.mdx')), `${dir}/quickstart.mdx`);
- for (const section of pages.filter((p) => SECTION_TITLES[p])) {
+ for (const page of all.filter((p) => INTRO_PAGES.has(p))) {
+ assert.ok(existsSync(path.join(content, dir, `${page}.mdx`)), `${dir}/${page}.mdx`);
+ }
+ for (const section of pages.filter((p) => SECTION_TITLES[p] && !(p === 'guides' && inline.length))) {
assert.equal(meta(path.join(dir, section)).title, SECTION_TITLES[section]);
}
const extra = readdirSync(path.join(content, dir)).filter(
(name) =>
name !== 'meta.json' &&
- !pages.includes(name.replace(/\.mdx$/, ''))
+ name !== 'concepts' &&
+ !all.includes(name.replace(/\.mdx$/, ''))
);
assert.deepEqual(extra, [], `${dir} has files outside its sections`);
});
@@ -181,5 +217,6 @@ test('redirects point at pages that exist', () => {
let target = to;
for (let hop = 0; hop < 8 && Object.hasOwn(redirects, target); hop++) target = redirects[target];
assert.ok(live.has(target.replace(/#.*$/, '')), `redirect ${from} -> ${to} does not reach a page`);
+ assert.ok(!Object.hasOwn(redirects, to.replace(/#.*$/, '')), `redirect ${from} -> ${to} is a chain: point it at the final page`);
}
});
diff --git a/scripts/docs-generators/cua-sdk.ts b/scripts/docs-generators/cua-sdk.ts
index 4c8a44478a..57562163b6 100644
--- a/scripts/docs-generators/cua-sdk.ts
+++ b/scripts/docs-generators/cua-sdk.ts
@@ -803,6 +803,9 @@ export const MAX_BYTES = 60_000;
export const MAX_FENCES = 150;
export const MAX_TABS = 30;
+/** Concept pages listed at the end of the reference sidebar; they live outside the generated folder, so the index page does not list them. */
+const TELEMETRY_CONCEPTS = ['../concepts/telemetry', '../concepts/telemetry-events', '../concepts/telemetry-counting', '../concepts/telemetry-error-kinds'];
+
/** Groups of the reference sidebar; folders other generators own are listed by name. */
const NAV: Array<[label: string, pages: string[]]> = [
['Sandboxes', ['cua', 'sandbox', 'image', 'os-image-catalog', 'image-software', 'services', 'runtime-support']],
@@ -2030,6 +2033,7 @@ function navFiles(pages: PageSpec[], outputDir: string): Map<string, string> {
// `index` is left out: each folder's index is the folder's own link, not a child.
const root: string[] = [];
for (const [label, slugs] of navGroups(pages)) root.push(`---${label}---`, ...slugs);
+ root.push('---Telemetry---', ...TELEMETRY_CONCEPTS);
files.set(path.join(outputDir, 'meta.json'), metaJson('Reference', root));
for (const folder of pageFolders(pages)) {
const home = pages.find((p) => p.slug === folder);
diff --git a/scripts/docs/check-redirects.mjs b/scripts/docs/check-redirects.mjs
new file mode 100644
index 0000000000..fae6ab461e
--- /dev/null
+++ b/scripts/docs/check-redirects.mjs
@@ -0,0 +1,114 @@
+#!/usr/bin/env node
+// Checks the docs IA redirects against a running site (a preview or production).
+//
+// node scripts/docs/check-redirects.mjs <base-url> [csv]
+//
+// <base-url> is the site origin, for example https://cua.ai or a preview URL.
+// The CSV (default docs/redirects-ia-2026-10.csv) has the header `old,new` and
+// site paths such as /docs/start-here/foo,/docs/spaces/quickstart.
+//
+// For every row it asserts that:
+// 1. (unless old == new) the old URL answers 301 with a Location that is the new URL (a fragment
+// in the new URL is ignored: browsers keep it, servers never see it);
+// 2. the new URL answers 200 directly, with no further redirect (no chains);
+// 3. the new page's <link rel="canonical"> is the new URL.
+//
+// Canonical hosts differ between a preview and production, so only the path is
+// compared unless --canonical-origin <origin> is given.
+//
+// Options:
+// --concurrency <n> parallel requests (default 8)
+// --canonical-origin <url> also require this origin in the canonical URL
+// --accept-308 1 accept 308 as well; for `next dev`, which sends 308 (production must send 301)
+//
+// Exits 1 when any row fails.
+import { readFileSync } from 'node:fs';
+import { dirname, resolve } from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const here = dirname(fileURLToPath(import.meta.url));
+const args = process.argv.slice(2);
+const flags = {};
+const positional = [];
+for (let i = 0; i < args.length; i++) {
+ if (args[i].startsWith('--')) flags[args[i].slice(2)] = args[++i];
+ else positional.push(args[i]);
+}
+const [baseArg, csvArg] = positional;
+if (!baseArg) {
+ console.error('usage: node scripts/docs/check-redirects.mjs <base-url> [csv] [--concurrency n] [--canonical-origin url]');
+ process.exit(2);
+}
+const base = new URL(baseArg.replace(/\/+$/, '') + '/');
+const csvPath = resolve(csvArg ?? resolve(here, '../../docs/redirects-ia-2026-10.csv'));
+const concurrency = Number(flags.concurrency ?? 8);
+const canonicalOrigin = flags['canonical-origin']?.replace(/\/+$/, '');
+
+const rows = readFileSync(csvPath, 'utf8')
+ .split(/\r?\n/)
+ .map((line) => line.trim())
+ .filter(Boolean)
+ .slice(1)
+ .map((line) => {
+ const [old, next] = line.split(',');
+ return { old, next };
+ });
+
+const pathOf = (p) => p.replace(/#.*$/, '').replace(/(.)\/+$/, '$1');
+const urlFor = (p) => new URL(p.replace(/^\/+/, ''), base).href;
+
+async function get(url) {
+ return fetch(url, { redirect: 'manual', headers: { 'user-agent': 'cua-docs-redirect-check' } });
+}
+
+async function check({ old, next }) {
+ const errors = [];
+ // A row with old == new is a page that must keep its URL: only the checks on the new URL run.
+ if (pathOf(old) !== pathOf(next)) {
+ const oldRes = await get(urlFor(pathOf(old)));
+ const location = oldRes.headers.get('location');
+ if (oldRes.status !== 301 && !(flags['accept-308'] !== undefined && oldRes.status === 308)) errors.push(`${old}: expected 301, got ${oldRes.status}`);
+ else if (!location) errors.push(`${old}: 301 without a Location header`);
+ else {
+ const to = new URL(location, urlFor(old));
+ if (pathOf(to.pathname) !== pathOf(next)) errors.push(`${old}: Location is ${to.pathname}, expected ${pathOf(next)}`);
+ }
+ }
+
+ const newRes = await get(urlFor(pathOf(next)));
+ if (newRes.status !== 200) {
+ errors.push(`${next}: expected 200, got ${newRes.status}${newRes.headers.get('location') ? ` (redirects to ${newRes.headers.get('location')})` : ''}`);
+ } else {
+ const html = await newRes.text();
+ const tag = html.match(/<link\b[^>]*\brel=["']canonical["'][^>]*>/i)?.[0];
+ const href = tag?.match(/\bhref=["']([^"']+)["']/i)?.[1];
+ if (!href) errors.push(`${next}: no canonical link`);
+ else {
+ const canonical = new URL(href, urlFor(next));
+ if (pathOf(canonical.pathname) !== pathOf(next)) errors.push(`${next}: canonical is ${canonical.pathname}`);
+ else if (canonicalOrigin && canonical.origin !== canonicalOrigin) errors.push(`${next}: canonical origin is ${canonical.origin}, expected ${canonicalOrigin}`);
+ }
+ }
+ return errors;
+}
+
+const failures = [];
+let next = 0;
+async function worker() {
+ while (next < rows.length) {
+ const row = rows[next++];
+ try {
+ failures.push(...(await check(row)));
+ } catch (error) {
+ failures.push(`${row.old}: ${error.message}`);
+ }
+ }
+}
+await Promise.all(Array.from({ length: concurrency }, worker));
+
+if (failures.length) {
+ console.error(failures.sort().join('\n'));
+ console.error(`\n${failures.length} problem(s) across ${rows.length} redirects (${base.origin})`);
+ process.exit(1);
+}
+console.log(`ok: ${rows.length} redirects 301 to a 200 page with the right canonical (${base.origin})`);