# Cursor CLI Provider ## Overview The Cursor CLI provider enables CLI Agent Orchestrator (CAO) to work with the **[Cursor CLI](https://cursor.com/cli)** (primary command: `agent`, historical alias: `cursor-agent`) — Anysphere's terminal-native AI coding assistant. Use it to drive Cursor alongside Claude Code, Kiro CLI, and the other providers already supported by CAO. The provider implements the [BaseProvider](https://github.com/awslabs/cli-agent-orchestrator) interface, so it inherits support for handoff, assign, and send_message orchestration flows. ## Quick Start ### Prerequisites 1. **Cursor subscription or API key** — required by `agent login`. 2. **Cursor CLI** — install the `agent` (or legacy `cursor-agent`) binary on your `$PATH`. 3. **tmux** — required for terminal management. ```bash # Install Cursor CLI (see https://cursor.com/cli for the current method) curl https://cursor.com/install -fsS | bash # Authenticate agent login ``` ### Using the Cursor CLI Provider with CAO ```bash # Start the CAO server cao-server # Launch a Cursor-backed session cao launch --agents developer --provider cursor_cli ``` Via HTTP API: ```bash curl -X POST "http://localhost:9889/sessions?provider=cursor_cli&agent_profile=developer" ``` ## Features ### Status Detection The Cursor CLI provider detects terminal states by analyzing output patterns. Cursor CLI v2026.06.15 runs a full Ink/TUI in interactive mode, so the detection targets both the legacy text-mode REPL and the modern TUI: - **IDLE / COMPLETED (v2026+ TUI)**: The TUI has finished rendering, and the `ctrl+c to stop` hint is absent from the input-box line. The input box is back to the placeholder (`Plan, search, build anything` on a fresh launch, `Add a follow-up` after the first turn). - **PROCESSING (v2026+ TUI)**: The TUI has finished rendering AND the `ctrl+c to stop` hint is present on the input-box line. Cursor renders this every frame the agent is working on a turn; it disappears once the response is fully delivered. - **IDLE / COMPLETED (older text-mode)**: Terminal shows a `❯` (or `>`) REPL prompt on its own line, ready for input. - **PROCESSING (older text-mode)**: Spinner characters (`⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏✶✢✽✻✳·`) with ellipsis on a line immediately before the `──────────────────────` separator. - **WAITING_USER_ANSWER**: TUI selection widget (mode picker, model picker) showing the `↑/↓ to navigate` footer, or an active workspace-trust / tool-permission dialog, including `Workspace Trust Required`. - **UNKNOWN**: No recognizable state. For modern TUI frames, active selection and trust/permission dialogs are checked before PROCESSING or IDLE/COMPLETED. Older text-mode spinner checks run before those dialog checks. Unrecognized output is UNKNOWN. A recognized `Cursor Agent` version banner marks the end of the startup prefix. Status detection ignores scrollback before the last such banner, so a resolved startup trust dialog does not keep a ready session blocked. A trust or permission dialog after that banner still requires user input; detecting it does not accept it. The newer workspace-trust prompt is recognized by its complete dialog structure: the `Workspace Trust Required` title, the directory-trust question and the `[a] Trust this workspace` / `[q] Quit` choices. Quoting the title or question in an ordinary request or response does not by itself indicate a pending dialog. A quoted dialog followed by a newer composer is also treated as transcript content rather than a request for approval. The PROCESSING check is **structural** — for older text-mode builds it walks backwards from the last separator looking for a spinner line, so stale spinner text from a previously completed turn does not trigger a false positive (the same approach used by the Claude Code provider). For v2026+ TUI detection, the tail of the rolling state buffer (last ~1KB) is consulted. That window is well below the buffer cap (`state_buffer_max` server setting, 32KB by default). Detection **assumes** Cursor redraws the input box on every TUI frame, so the current input-box line is expected to always be inside that window; this is not independently verified against a live Cursor CLI and is a stated assumption, not a guarantee. If a build ever emits a partial redraw that updates only the status bar or progress line and leaves the input-box line alone, the newest input-box line in the tail is still the previous (working) frame's, and the terminal stays PROCESSING until a frame redraws the input box. Within that window the `ctrl+c to stop` check is **anchored structurally to the last input-box line**: a line is only treated as an input-box line if it carries Cursor's input arrow (`→`) immediately before the placeholder phrase, not merely the placeholder phrase appearing anywhere in a line — ordinary response prose can contain "Add a follow-up" or "Plan, search, build anything" with no arrow, and matching on phrase alone would let that prose impersonate the input box. The search then covers the tail **from the start of that last structural match to the end of the buffer**, not just that single line, so an indicator that wraps onto the line immediately after the placeholder (e.g. in a narrow pane) is still found. The buffer is an append-only stream of every TUI redraw and a finished Cursor frame is only a few hundred bytes, so a window-wide search would keep seeing the last working frame's indicator after the turn had ended and the terminal would never leave PROCESSING. Builds that render no placeholder have no input-box line to anchor to and fall back to the window-wide search. "The TUI has finished rendering" means the input-box placeholder is in the tail, **or** the status bar (`Composer …` / `Run Everything`) appears in the buffer. The status bar alone is not sufficient: it renders the active model name, and a Cursor **Free** plan cannot select a named model (`Free plans can only use Auto`), so on those accounts the bar reads `Auto` and matches no known model string. The placeholder is model- and plan-independent, which is why it is the primary signal. ### Message Extraction Cursor CLI does not emit a single canonical response marker (unlike Claude Code's `⏺`). The provider first tries the **coloured-panel layout measured on 2026.10.22**, then the older **separator + trailing prompt** format. For the coloured-panel layout, extraction retains ANSI colour information until the boundaries are identified: the latest submitted request has a distinct background from the following idle composer (`→ Add a follow-up` or `→ Plan, search, build anything`). Only the response region between them is returned. The request echo, composer padding and compact tool-badge rows are excluded; response indentation and visible text following tool badges are preserved. A `ctrl+c to stop` hint at or below the composer rejects publication of a still-running response. An empty response or a missing following composer also reports an extraction error. The panel colours are specific to the measured build/theme. When no submitted panel is recognized, extraction tries the existing separator grammar: 1. Find the last `──────────────────────` separator that precedes a trailing `❯` idle prompt. 2. Find the separator before that one (or the start of the buffer). 3. Extract the content between them and strip full ECMA-48 escape sequences (CSI, OSC, 2-byte ESC). If neither format supplies a reliable boundary, extraction raises an error. An unknown layout or theme is not guessed: `allow_raw_transcript_fallback` is `False`, so CAO does not return the entire raw transcript as an answer. This also prevents a failed extraction from returning the user's echoed request. Use the `get_output` API, which extracts from rendered `capture-pane` history with ANSI colours preserved. The raw pipe-pane stream contains redraws rather than a reliable rendered transcript and is not the extraction input. Synchronous `cao session send` reports an answer-fetch failure and exits **1** instead of silently succeeding. Ctrl-C while waiting still exits **130**. ### Permission Bypass By default, CAO launches Cursor CLI with the following flags to skip the interactive dialogs that would otherwise block headless orchestration: - `--force` — auto-approves every tool call (Bash, file writes, etc.). - `--approve-mcps` — pre-approves MCP servers declared via `--plugin-dir`. `--trust` is **not** passed because Cursor CLI v2026+ rejects it in interactive REPL mode with `Error: --trust can only be used with --print/headless mode`. Cursor can still display its own `Workspace Trust Required` dialog. CAO reports **WAITING_USER_ANSWER** and does not answer that dialog automatically; the operator must handle it in the terminal. During startup, it must be resolved before the configured `provider_init_timeout` expires: initialization waits for IDLE or COMPLETED and fails on timeout rather than waiting indefinitely at the trust prompt. CAO's confirmation during `cao launch` ("Do you trust all the actions in this folder?") authorizes the launch and its tool-approval flags. It does not replace Cursor's separate workspace-trust decision. The flags above reduce tool/MCP approval prompts during handoff/assign; they are not a guarantee that no interactive dialog will appear. ## Configuration ### Agent Profile Integration When launched with an agent profile (e.g., `--agents code_supervisor`), CAO: 1. Loads the profile from the agent store (`~/.aws/cli-agent-orchestrator/agent-store`). 2. Honors the profile's `model` field by passing `--model ` at launch (overridable via the constructor). 3. For MCP servers: writes a synthetic Cursor plugin manifest under `~/.aws/cli-agent-orchestrator/tmp/-cursor-plugins/plugin.json` and passes the directory via `--plugin-dir`. The manifest's `mcpServers` map carries the `CAO_TERMINAL_ID` env var so MCP tools can identify the current terminal for handoff/assign operations. `--approve-mcps` is added so the REPL does not block on a per-server approval dialog. 4. **Does not** pass the profile body via `--system-prompt` in v2026.06.15: the backend rejects every request that carries a `--system-prompt ` payload with `[invalid_argument] unknown option '--system-prompt'` regardless of the file's contents (the bug is reproducible with a 3-character file). The CAO role context still reaches the agent via the `cao-mcp-server` MCP tool's handoff/assign payloads, so the agent has the right capabilities and the right inbox tools; only the role body is not pre-loaded as a system prompt. The preserved `_write_system_prompt_file` helper is ready to re-enable this path when Cursor ships a fixed client. ### Launch Command The provider builds the command via `_build_cursor_command()`. The provider prefers the unambiguous `cursor-agent` alias (which only the Cursor CLI ships) and falls back to the documented primary `agent` name when only that is installed. When `agent` is selected the provider runs an `agent --version` probe to confirm the resolved binary is the Cursor CLI (a number of unrelated tools also install an `agent` binary on `$PATH`). ``` cursor-agent --force [--model ] [--plugin-dir --approve-mcps] ``` The `--print` flag is intentionally **not** passed: CAO drives the interactive REPL so the inbox service can stream follow-up prompts via MCP handoff. Print mode is a one-shot CLI flag that exits after the first response and is therefore incompatible with multi-turn CAO sessions. ### Model Override The provider forwards a model selection in the following order of precedence: 1. The profile's `model` field (when set on the agent profile). 2. The constructor-provided `model` argument (e.g., from `cao launch --model gpt-5`). 3. No `--model` flag (Cursor uses the user's default model). ## Tool Restrictions Cursor CLI v2026 does not expose a `--disallowedTools` (or equivalent) flag for hard tool enforcement, and the soft-enforcement path the provider used in earlier builds (prepending `SECURITY_PROMPT` + an allowlist to the system prompt) is **not available in v2026** because the provider no longer passes `--system-prompt` (see "Agent Profile Integration" above). The recommended path for restricted tool access on Cursor v2026 is to choose a provider that supports a native enforcement mechanism: - **Hard enforcement**: prefer Claude Code, Copilot CLI, Grok Build CLI, or OpenCode CLI, which enforce the deny list natively. Kiro CLI does not: CAO launches it `--trust-all-tools`, so `allowedTools` only suppresses approval prompts there. - **OpenCode**: the OpenCode CLI frontmatter mechanism lets the supervisor restrict per-agent capabilities. - **Advisory only on Cursor v2026**: if you must use `cursor_cli` with restricted tools, configure a dedicated free-tier account + workspace and use Cursor's own permission UI to scope what the agent can do. The CAO `allowed_tools` argument is currently ignored on `cursor_cli` for v2026 and is documented as such. See `docs/tool-restrictions.md` and `skills/cao-provider/references/lessons-learnt.md` #13 for the three enforcement approaches. ## End-to-End Testing The E2E test suite validates the full orchestration matrix (handoff, assign, send_message, allowedTools, supervisor orchestration) for every supported provider. The 11 core e2e tests for Cursor CLI are added under the `TestCursorCli*` test classes in `test/e2e/` and follow the same `_run_*_test()` helpers used by the other providers. ### Prerequisites 1. **Cursor CLI** (`agent` or `cursor-agent`) installed and authenticated. 2. **CAO server** running (`uv run cao-server`). 3. **Agent profiles** installed for the cursor_cli provider (the profiles shipped in `examples/assign/` are provider-agnostic; you can pin them to `cursor_cli` either at install time or via frontmatter `provider: cursor_cli`): ```bash cao install examples/assign/data_analyst.md --provider cursor_cli cao install examples/assign/report_generator.md --provider cursor_cli cao install developer --provider cursor_cli # for handoff / send_message tests ``` 4. **tmux** available on `$PATH`. ### Running Cursor CLI E2E Tests The default pytest `addopts` excludes the `e2e` marker, so the `-o "addopts="` override is required to enable them: ```bash # Start CAO server uv run cao-server # All Cursor CLI e2e tests uv run pytest -m e2e test/e2e/ -v -k cursor_cli -o "addopts=" # Individual flow files uv run pytest -m e2e test/e2e/test_handoff.py -v -k cursor_cli -o "addopts=" uv run pytest -m e2e test/e2e/test_assign.py -v -k cursor_cli -o "addopts=" uv run pytest -m e2e test/e2e/test_send_message.py -v -k cursor_cli -o "addopts=" uv run pytest -m e2e test/e2e/test_allowed_tools.py -v -k cursor_cli -o "addopts=" uv run pytest -m e2e test/e2e/test_supervisor_orchestration.py -v -k cursor_cli -o "addopts=" ``` ### The 11 Core E2E Tests | # | Test class | What it validates | |---|------------|-------------------| | 1 | `TestCursorCliHandoff::test_handoff_simple_function` | Worker creates a Python function, returns extractable output | | 2 | `TestCursorCliHandoff::test_handoff_second_task` | Same terminal handles a second task with no state leakage | | 3 | `TestCursorCliAssign::test_assign_data_analyst` | `data_analyst` profile produces statistical analysis on a dataset | | 4 | `TestCursorCliAssign::test_assign_report_generator` | `report_generator` profile creates a structured report template | | 5 | `TestCursorCliAssign::test_assign_with_callback` | Worker completes → inbox callback → supervisor receives result | | 6 | `TestCursorCliSendMessage::test_send_message_to_inbox` | One terminal sends a message to another's inbox; delivery verified | | 7 | `TestCursorCliAllowedTools::test_restricted_supervisor_cannot_bash` | **Marked `xfail`** — Cursor CLI lacks a native `--disallowedTools` flag; soft enforcement via `SECURITY_PROMPT` is advisory only. Tracked under "Tool Restrictions" above. | | 8 | `TestCursorCliAllowedTools::test_unrestricted_developer_can_bash` | Developer with `--yolo` (allowedTools=`["*"]`) can execute bash | | 9 | `TestCursorCliAllowedTools::test_allowed_tools_stored_in_metadata` | `allowedTools` is persisted and returned by `GET /terminals/{id}` | | 10 | `TestCursorCliSupervisorOrchestration::test_supervisor_handoff` | Supervisor agent autonomously calls the `handoff()` MCP tool to delegate to `report_generator` | | 11 | `TestCursorCliSupervisorOrchestration::test_supervisor_assign_three_analysts` | **The canonical `examples/assign/` smoke test.** Supervisor parallel-assigns 3x data analysts, sequential-handoffs the report generator, receives all 3 inbox callbacks, and finalizes the report without doing the analysis work itself. The supervisor must NOT complete the jobs itself — the test asserts the final output references delegated results. | ### Manual `examples/assign/` Smoke Test For a quick interactive validation outside the pytest harness: ```bash cao install examples/assign/analysis_supervisor.md --provider cursor_cli cao install examples/assign/data_analyst.md --provider cursor_cli cao install examples/assign/report_generator.md --provider cursor_cli cao launch --agents analysis_supervisor --provider cursor_cli ``` Then in the supervisor terminal, paste the example task from `examples/assign/README.md` (3 datasets, calculate mean/median/stdev, generate a report). The supervisor should: 1. Use `assign()` to dispatch 3x data analysts in parallel 2. Use `handoff()` to get a report template from the report generator 3. Finish its turn (no sleep/echo loops — they block inbox delivery) 4. Receive all 3 inbox callbacks and combine template + results into the final report If the supervisor completes the analysis work itself, the per-directory lock or status detection is broken — see `skills/cao-provider/references/lessons-learnt.md` #19 (per-directory locks) and #16 (alt-screen detection). ## Troubleshooting ### Common Issues 1. **Trust Dialog Blocking** - The provider does **not** launch with `--trust` in v2026+ (Cursor rejects the flag in interactive REPL mode). CAO's launch confirmation does not dismiss Cursor's own workspace-trust dialog. - If the full `Workspace Trust Required` dialog appears, the terminal reports **WAITING_USER_ANSWER**. Attach to its tmux session and make the trust decision there; CAO does not automatically accept it. A startup dialog must be resolved within `provider_init_timeout` or initialization fails. - A resolved startup dialog above the latest recognized `Cursor Agent` version banner is ignored by status detection; a current dialog after it still blocks. 2. **MCP Approval Dialog Blocking** - The provider launches with `--approve-mcps` when the profile declares `mcpServers`, and the MCP servers are written into a `--plugin-dir` manifest. - If MCP servers still prompt, check the synthesised `plugin.json` under `~/.aws/cli-agent-orchestrator/tmp/-cursor-plugins/`. 3. **Authentication Issues** ```bash agent login # Or set CURSOR_API_KEY environment variable ``` 4. **Status Stuck on UNKNOWN** - Attach to the tmux session (`tmux attach -t `) and check terminal output. - Verify Cursor CLI starts correctly in a regular terminal first: `agent --print "hello"`. - For v2026+ the detector expects the TUI to be rendered (you should see the `→ Add a follow-up` placeholder, or a status bar with `Composer 2.5 Fast` / `Run Everything`). Older text-mode builds classify via `❯` prompt + `─────` separator. 5. **`agent` Not Found on `$PATH`** - The provider does not prefix the command with an absolute path — install the binary where your shell can find it. - The provider prefers `cursor-agent` when both names are installed; `agent` is only used when the legacy alias is missing, and even then the version banner is probed to confirm the resolved binary is the Cursor CLI. - On Linux, the recommended install method is `curl https://cursor.com/install -fsS | bash`. 6. **`[invalid_argument] unknown option '--system-prompt'` from the Cursor backend** - This is a confirmed v2026.06.15 backend bug. The provider deliberately omits `--system-prompt` to avoid it. If you see this error, the agent was likely launched by another tool (e.g. `agent --print` directly). See issue #299 for the investigation. 7. **E2E tests skip with "Cursor CLI (agent / cursor-agent) not installed"** - Install Cursor CLI and ensure the `agent` (or legacy `cursor-agent`) binary is on `$PATH`. - The `require_cursor` fixture auto-skips when the binary is absent; no failure, just no coverage. ## References - [Cursor CLI Overview](https://cursor.com/docs/cli/overview) - [Cursor CLI Parameters](https://cursor.com/docs/cli/reference/parameters) - [Issue #264: Add support for Cursor CLI as a provider](https://github.com/awslabs/cli-agent-orchestrator/issues/264) ### Agent-plugin MCP working directory Its MCP config format has no working-directory key (checked against the vendor's own MCP documentation, 2026-09-16), so CAO carries an agent plugin's declared `cwd` by launching the server through `/bin/sh -c 'cd -- "$1" && shift && exec "$@"'`. `exec` replaces the shell, the environment passes through, and argument boundaries survive because each argument stays a separate argv element. On a host with no `/bin/sh` such a server is skipped with `mcp.cwd_unsupported` rather than started in the wrong directory. See [Agent Plugins](agent-plugins.md) for the full per-provider table.