Skip to content
Open
44 changes: 44 additions & 0 deletions adapters/local/harnesses/cursor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# cursor: Cursor CLI on the local driver

Login: agent's own login: `agent login` saves it locally (the macOS keychain, or ~/.config/cursor/auth.json on Linux), or the CURSOR_API_KEY the user set for the CLI; the driver never reads or passes it

Effort: none

Live check: #2478

The `cursor` harness row runs Cursor CLI (`agent`) as a builder through the user's own sign-in, under the [harness-row contract](../../harness-row.md). Everything here was read at **Cursor CLI 2026.11.22-e9042b2**, the version [`https://cursor.com/install`](https://cursor.com/install) installed on 2026-11-23, and from Cursor's CLI docs on that day. Its `--help` text was read from that package's own source (`index.js`), never by running the CLI.

## Commands

| Turn | Command line |
| --- | --- |
| Start | `agent --print --output-format stream-json --trust --model <model> <mode's arguments> <prompt>` |
| Wake | `agent --print --output-format stream-json --trust --resume <session id> --model <model> <mode's arguments> <prompt>` |
| Stop | the driver's own stop: it ends the turn's whole process tree |

- **Session id:** the first JSON line with a `session_id` key. In `stream-json` that is the `system`/`init` event, which the CLI prints once at the beginning of the session ([output format](https://cursor.com/docs/cli/reference/output-format#system-initialization)), so the id is known as soon as the run starts.
- **`--trust`:** print mode refuses a workspace the user hasn't trusted with `Workspace Trust Required` and exit 1, unless `--trust`, `--yolo` or `-f` is passed. The driver's clone is a new folder each run, so both lines pass `--trust` ([parameters](https://cursor.com/docs/cli/reference/parameters#global-options): "Trust the workspace without prompting (headless mode only)").
- **Signed out:** in print mode the CLI exits 1 with `Error: Authentication required. Please run 'agent login' first, or set CURSOR_API_KEY environment variable.`, or a server message followed by `Please run 'agent login' to authenticate.` The row's `signed_out` pattern matches the second form too, and `start` then names `agent login` ([authentication](https://cursor.com/docs/cli/reference/authentication#troubleshooting)).
- **Background process:** `agent` runs each shell tool command as its own detached process group under the turn (its bundled `shell-exec` module spawns each one with `detached: true`), and in print mode waits for background shells after its last message before it aborts them (the hidden `--background-shell-timeout` option's help). Stop ends them with the process tree; the fake simulates one such process.

## Modes

| Mode | Arguments | What it does |
| --- | --- | --- |
| `force` | `--force` | "Force allow commands unless explicitly denied": every action runs except what `permissions.deny` and team policies block ([headless](https://cursor.com/docs/cli/headless#file-modification-in-scripts)) |

No `allowlist` mode is offered: Cursor CLI 2026.11.22-e9042b2 has no flag to enforce `allowlist` over an effective `approvalMode: "unrestricted"` from user or merged project config, so omitting `--force` can still run every action in print mode ([headless](https://cursor.com/docs/cli/headless#file-modification-in-scripts), [configuration](https://cursor.com/docs/cli/reference/configuration#optional-fields)). Requiring explicit approval of `force` prevents an owner from approving `allowlist` and getting Run Everything silently.

## The census check: do `-p` and `--resume` work together?

**Yes.** `--print` and `--resume [chatId]` are both global options that "can be used with any command" ([parameters](https://cursor.com/docs/cli/reference/parameters#global-options)), and the CLI's source agrees: its one agent action reads `--resume <chatId>`, then starts the same `resume` session in print mode as interactively. Print mode refuses a resume only when that chat is running inside an `agent persist` session ("Chat … may still be running"), and this row never uses `agent persist`. A bare `--resume` with no id opens an interactive picker, so the wake line always passes the saved id. The census's `--output-format json` is not used: it prints `session_id` only in the one object at the end of a successful run ([output format](https://cursor.com/docs/cli/reference/output-format#json-format)), so a wake during a long first turn would find no session id.

## Effort

The row's effort is `none`. Cursor CLI 2026.11.22-e9042b2 has no effort flag and no effort environment setting: its options list none ([parameters](https://cursor.com/docs/cli/reference/parameters#global-options)), and its own `--model` help says "Parameterized models accept quoted bracket overrides, e.g. 'claude-opus-4-8[context=1m,effort=high,fast=false]'". Effort is part of some model ids, never a separate argument, so a fixed argument can't add it and a start with an effort is refused.

## The fake

`fake` parses the documented global options in any order, as `--name value` or `--name=value`, and exits 2 on anything else: an unknown option, a missing value, a value outside `--output-format`, `--mode` or `--sandbox`'s choices, a `-H` or `--header` value without a non-empty `Name: Value` header, `--stream-partial-output` without `stream-json`, `--resume` with `--continue`, or a bare `--resume` in print mode. It simulates only the start and wake above, exits 3 on any other documented command line (a subcommand, `--api-key`, or a run other than print mode with `stream-json`), and, without `--trust`, `--force` or `--yolo`, exits 1 as the real CLI does. `test_row.py` checks each of these.

Synthetic: `fake` is the only CLI here.
59 changes: 59 additions & 0 deletions adapters/local/harnesses/cursor/evidence/green.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# HR5 #2473 green: the cursor row passes the runner, and its test_row.py (31 refusing agent CLI stubs first on PATH)
$ python3 -I adapters/local/test_harnesses.py
fail claude: row.json harness: claude is built in, and no row may use a built-in name
fail credential-env: row.json env: a value looks like a credential; env holds only fixed settings that are not credentials
fail daemon-survives: daemon: the background process the row declares still runs after stop
pass effort-crowded: the contract, the folder, the kit's five checks, and the session, env, background process and effort checks
fail effort-missing: row.json effort: it has no effort form; give an effort map or "none: <one line why>"
fail effort-unpassed: row.json effort: it maps effort values to arguments, but start has no {effort} to pass them
pass example: the contract, the folder, the kit's five checks, and the session, env, background process and effort checks
pass example-none: the contract, the folder, the kit's five checks, and the session, env, background process and effort checks
fail larger-argument: row.json start: a placeholder sits inside a larger argument; each fills a whole argument
fail row-missing: row.json is missing
fail session-differs: session: the wake turn got a different session id from the start turn
fail signed-out-bad-pattern: row.json signed_out: a pattern does not compile
pass signed-out-json: the contract, the folder, the kit's five checks, and the session, env, background process and effort checks
fail wake-no-session: row.json wake: it has no {session}
pass driver: a broken row's D3 error names its row file and fits the error schema: a row folder with no row.json, a harness that is not a string, and a 60-character harness with a missing field
pass driver: a row's session id and signed_out patterns are read from its first turn's output, never the clone's, and the first line that has the session's JSON path decides it
pass driver: an effort the row can't take is refused before the driver looks for its program, and a row's effort ids are lower-case words of up to 20 characters
pass driver: a row whose fixed arguments in start, wake, modes or effort look like a credential, joined or as a flag and its value, is refused naming only its field
pass driver: a row's env and effort setting reach only the harness, never the turn's supervisor
pass driver: an unknown harness is a D3 error that lists the built-ins and the row folders, and starts nothing
pass driver: a wake before the reported session id is known is a D3 error that starts nothing, whether the first turn has ended or still runs
pass driver: a wake while the first turn runs saves its newly reported session id, and once it is saved answers woke with no state write and starts nothing
rows in adapters/local/harnesses: cursor
pass cursor: the contract, the folder, the kit's five checks, and the session, env, background process and effort checks
exit 0
$ python3 -I adapters/local/harnesses/cursor/test_row.py
pass an unknown option: exit 2
pass the hidden --new-session-id: exit 2
pass a --model with no value: exit 2
pass an --output-format outside its choices: exit 2
pass a --sandbox outside its choices: exit 2
pass a --mode outside its choices: exit 2
pass a --header without a colon: exit 2
pass a -H without a colon: exit 2
pass a --header= without a colon: exit 2
pass a --header with an empty name: exit 2
pass a --header with a blank name: exit 2
pass a --header with whitespace in the name: exit 2
pass a bad second --header after a valid one: exit 2
pass a bad first --header before a valid one: exit 2
pass --stream-partial-output without stream-json: exit 2
pass --resume with --continue: exit 2
pass a bare --resume in print mode: exit 2
pass a wake prompt without --resume: exit 2
pass a start prompt with --resume: exit 2
pass the login command: exit 3
pass a login in argv: exit 3
pass the json output format: exit 3
pass a run without --print: exit 3
pass a run with no --model: exit 3
pass an untrusted workspace: exit 1
pass valid --header and -H reach the turn: exit 1
pass row.json requires explicit force mode: force
pass driver refuses allowlist approval: refused
pass the row's start with mode force reaches the turn: exit 1
pass the row's wake with mode force reaches the turn: exit 1
exit 0
27 changes: 27 additions & 0 deletions adapters/local/harnesses/cursor/evidence/red.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# HR5 #2473 red: an empty cursor row (row.json is {}) fails the runner (31 refusing agent CLI stubs first on PATH)
$ python3 -I adapters/local/test_harnesses.py
fail claude: row.json harness: claude is built in, and no row may use a built-in name
fail credential-env: row.json env: a value looks like a credential; env holds only fixed settings that are not credentials
fail daemon-survives: daemon: the background process the row declares still runs after stop
pass effort-crowded: the contract, the folder, the kit's five checks, and the session, env, background process and effort checks
fail effort-missing: row.json effort: it has no effort form; give an effort map or "none: <one line why>"
fail effort-unpassed: row.json effort: it maps effort values to arguments, but start has no {effort} to pass them
pass example: the contract, the folder, the kit's five checks, and the session, env, background process and effort checks
pass example-none: the contract, the folder, the kit's five checks, and the session, env, background process and effort checks
fail larger-argument: row.json start: a placeholder sits inside a larger argument; each fills a whole argument
fail row-missing: row.json is missing
fail session-differs: session: the wake turn got a different session id from the start turn
fail signed-out-bad-pattern: row.json signed_out: a pattern does not compile
pass signed-out-json: the contract, the folder, the kit's five checks, and the session, env, background process and effort checks
fail wake-no-session: row.json wake: it has no {session}
pass driver: a broken row's D3 error names its row file and fits the error schema: a row folder with no row.json, a harness that is not a string, and a 60-character harness with a missing field
pass driver: a row's session id and signed_out patterns are read from its first turn's output, never the clone's, and the first line that has the session's JSON path decides it
pass driver: an effort the row can't take is refused before the driver looks for its program, and a row's effort ids are lower-case words of up to 20 characters
pass driver: a row whose fixed arguments in start, wake, modes or effort look like a credential, joined or as a flag and its value, is refused naming only its field
pass driver: a row's env and effort setting reach only the harness, never the turn's supervisor
pass driver: an unknown harness is a D3 error that lists the built-ins and the row folders, and starts nothing
pass driver: a wake before the reported session id is known is a D3 error that starts nothing, whether the first turn has ended or still runs
pass driver: a wake while the first turn runs saves its newly reported session id, and once it is saved answers woke with no state write and starts nothing
rows in adapters/local/harnesses: cursor
fail cursor: row.json effort: it has no effort form; give an effort map or "none: <one line why>"
exit 1
95 changes: 95 additions & 0 deletions adapters/local/harnesses/cursor/fake
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env python3
import json, os, sys
sys.dont_write_bytecode = True
sys.path.insert(0, os.environ['FAKE_CLI_LIB'])
import fake_cli

HELP = '''The fake agent (Cursor CLI 2026.11.22-e9042b2). It parses the global options of
https://cursor.com/docs/cli/reference/parameters and exits 2 on anything else. It simulates only:
agent --print --output-format stream-json (--trust | --force | --yolo) [--resume <chatId>] --model <m> <prompt>
in any option order, and exits 3 on a documented command line it does not simulate.'''
FLAGS = {'-p': '--print', '--print': '--print', '-f': '--force', '--force': '--force', '--yolo': '--yolo',
'--stream-partial-output': None, '--continue': None, '--plan': None, '--list-models': None,
'--approve-mcps': None, '--trust': None, '--skip-worktree-setup': None, '-v': '--version',
'--version': '--version', '-h': '--help', '--help': '--help'}
VALUES = {'--api-key': None, '-H': '--header', '--header': '--header', '--output-format': ('text', 'json', 'stream-json'),
'--model': None, '--mode': ('plan', 'ask'), '--sandbox': ('enabled', 'disabled'), '--workspace': None,
'--plugin-dir': None, '--worktree-base': None}
OPTIONAL = {'--resume': None, '-w': '--worktree', '--worktree': '--worktree'}
COMMANDS = ('agent', 'login', 'logout', 'status', 'whoami', 'about', 'models', 'mcp', 'sandbox', 'worker', 'acp',
'update', 'ls', 'resume', 'create-chat', 'generate-rule', 'rule', 'install-shell-integration',
'uninstall-shell-integration', 'help')
SIGNED_OUT = ("Error: Authentication required. Please run 'agent login' first, or set CURSOR_API_KEY "
"environment variable.")


def parse(argv):
seen, words, i = {}, [], 0
while i < len(argv):
a = argv[i]
name, eq, value = a.partition('=') if a.startswith('--') else (a, '', '')
if a == '--':
words += argv[i + 1:]
break
if not a.startswith('-') or a == '-':
words.append(a)
elif name in FLAGS and not eq:
seen[FLAGS[name] or name] = True
elif name in VALUES:
if not eq:
i += 1
if i == len(argv):
fake_cli.refuse()
value = argv[i]
choices = VALUES[name]
if isinstance(choices, tuple) and value not in choices:
fake_cli.refuse()
key = choices if isinstance(choices, str) else name
if key == '--header':
header_name, sep, _ = value.partition(':')
if not sep or '\r' in value or '\n' in value or not header_name.strip() or \
any(c.isspace() or ord(c) < 33 for c in header_name.strip()):
fake_cli.refuse()
seen[key] = value
elif name in OPTIONAL:
if not eq and i + 1 < len(argv) and not argv[i + 1].startswith('-'):
i += 1
value, eq = argv[i], '='
seen[OPTIONAL[name] or name] = value if eq else True
else:
fake_cli.refuse()
i += 1
return seen, words


def not_simulated(why):
print('fake agent: %s is documented, but this fake does not simulate it' % why, file=sys.stderr)
sys.exit(3)


if sys.argv[1:] in (['--help'], ['-h']):
print(HELP)
sys.exit(0)
seen, words = parse(sys.argv[1:])
if seen.get('--stream-partial-output') and seen.get('--output-format') != 'stream-json':
fake_cli.refuse()
if '--resume' in seen and seen.get('--continue'):
fake_cli.refuse()
if seen.get('--print') and seen.get('--resume') is True:
fake_cli.refuse()
if words[:1] and words[0] in COMMANDS:
not_simulated('the %s command' % words[0])
if '--api-key' in seen:
not_simulated('a login in argv (--api-key)')
if not seen.get('--print') or seen.get('--output-format') != 'stream-json' or not seen.get('--model') or not words:
not_simulated('a run other than --print --output-format stream-json with --model and a prompt')
if not (seen.get('--trust') or seen.get('--force') or seen.get('--yolo')):
print('Workspace Trust Required: pass --trust, --yolo, or -f if you trust this directory', file=sys.stderr)
sys.exit(1)
prompt, session = ' '.join(words), seen.get('--resume')
if (session is not None) != prompt.startswith('You were woken'):
fake_cli.refuse()
init = lambda sid: json.dumps({'type': 'system', 'subtype': 'init', 'apiKeySource': 'login',
'cwd': '/synthetic/workspace', 'session_id': sid, 'model': seen['--model'],
'permissionMode': 'default'})
fake_cli.turn(prompt, seen['--model'], session, init, daemon='tree', signed_out=SIGNED_OUT)
44 changes: 44 additions & 0 deletions adapters/local/harnesses/cursor/row.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"harness": "cursor",
"program": "agent",
"start": [
"--print",
"--output-format",
"stream-json",
"--trust",
"--model",
"{model}",
"{mode}",
"{prompt}"
],
"wake": [
"--print",
"--output-format",
"stream-json",
"--trust",
"--resume",
"{session}",
"--model",
"{model}",
"{mode}",
"{prompt}"
],
"session": {
"json": [
"session_id"
]
},
"modes": {
"force": [
"--force"
]
},
"env": {},
"effort": "none: agent (Cursor CLI 2026.11.22-e9042b2) has no effort flag or env setting; its --help puts effort only inside a parameterized model id, such as 'claude-opus-4-8[effort=high]'",
"login": "agent's own login: `agent login` saves it locally (the macOS keychain, or ~/.config/cursor/auth.json on Linux), or the CURSOR_API_KEY the user set for the CLI; the driver never reads or passes it",
"daemon": "agent runs each shell tool command as its own detached process group under the turn, and may keep background shells after its last message; stop ends them with the process tree",
"signed_out": [
"please run '(?:agent|cursor-agent) login'"
],
"login_command": "agent login"
}
Loading