Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

feat: implement generic permission prompt parser and add support for multiple agent engines

0xken1558edef583720
diff --git a/cli/src/engines/README.md b/cli/src/engines/README.md
index f8f232c75..82908cecb 100644
--- a/cli/src/engines/README.md
+++ b/cli/src/engines/README.md
@@ -280,6 +280,57 @@ than broken — which is the right failure mode, and why they are last.
|---|---|
| `engines/<name>/runtimeProfile.ts` + `lib/runtimeProfile.ts` | The model and effort pickers. Some agents expose neither: Amp has no model list at all, only four agent *modes*, so the mode is reported as the model and the effort axis stays `auto`. Note the engine name also lives inside `PROFILE_RE` — miss it there and the picker vanishes with no error |
| `engines/<name>/askQuestion.ts` + `lib/askQuestion.ts` + `lib/__fixtures__/question-<name>.txt` | Your agent's questions as answerable cards on the device and the web, instead of text in the tool feed. It need not be a question *tool*: Amp has none, and the only thing it blocks a person on is its approval prompt — whose rows are unnumbered, so they are walked with `Down` and committed with `Enter` rather than by pressing a digit |
+| `lib/__fixtures__/permission-<name>.txt` | The same card for your agent's **permission prompt**, which matters more than the question does — see below |
+
+### Permission prompts
+
+Harness does not launch your agent and supplies it no permission flags, so an approval prompt is the
+pane's ordinary state, not an edge case. Left unparsed it is invisible: the turn sits at `Processing`
+until someone walks to the computer. So an approval is modelled as a question whose options are the
+approval choices, and it rides the same `commander_question` / `question_response` round trip — no new
+frame, and the firmware's existing question screen renders it unchanged.
+
+Most engines need **no parser**. `parsePermissionPane` in `lib/askQuestion.ts` reads any dialog that ends
+in numbered rows under a line of key hints, identifying it by the rows rather than the prose: an approval
+always offers a way to say yes and a way to say no. Claude, Command Code, codex, hermes and muse are all
+read that way, and opencode's prompt is the horizontal one kilo inherited from it. Write a parser only
+when your agent's rows are shaped differently — devin's carry no dot after the number, grok's sit in `(●)`
+markers, cursor's are unnumbered and print their own key — and put it beside the question parser in
+`engines/<name>/askQuestion.ts`. If your agent already
+has a question parser, remember the permission prompt is usually a DIFFERENT dialog: muse needs
+`parseMuseQuestionPane(capture) ?? parseQuestionPane(capture)` because only the first of those two
+recognises its questions and only the second recognises its approvals.
+
+Two rules that came out of measuring nine of these:
+
+- **Never drop the row that declines.** A device user given three ways to approve and none to refuse
+ cannot answer the prompt at all.
+- **Drop rows that open a text editor** (`Edit command`, `Describe change to command`) — the device
+ cannot type into them. This is not cosmetic: the firmware shows `OPT_MAX` = 6 options and truncates
+ the rest silently, so on devin's seven-row prompt the row that falls off the end is `No`.
+
+And do not conclude "this agent never asks" from one probe. Muse was filed that way after a single
+sandboxed file write it simply *denied*; its approval is on by default and appears the moment the call is
+one the sandbox allows but policy gates — network egress, in the end. Check the agent's own flags first:
+something like `--yolo`, `--approval-mode` or `--dangerously-skip-permissions` existing at all is proof
+there is a prompt to skip. Only pi has none — no such flag, no permission key in its settings, and
+`curl`, a file write and a plain `rm` all run unprompted.
+
+**Do not wire up the startup trust dialog.** Six engines open with some form of "do you trust this
+directory?" (pi, devin, muse, cursor, codex, commandcode). It is not this feature: harness does not launch
+the engine, so the person already answered it at their own keyboard, and the watcher only polls a pane
+once the session is registered — which is later. Surfacing it would be dead code.
+
+To capture the fixture: start your agent in tmux under its own config, ask it to run
+`curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin`, and while the prompt is up run
+`tmux capture-pane -p -e -t <pane> -S -80 > src/lib/__fixtures__/permission-<name>.txt`. Keep `-e`: the
+existing fixtures carry their SGR codes because that is what `captureTmuxPane` returns. Then press the
+digit and watch what happens. There are three mechanisms in the tree already, so check which one you
+have: a digit that selects **and** submits (claude, commandcode, codex, muse, hermes, devin, grok), an
+unnumbered list walked with arrows (amp, kilo, opencode), or unnumbered rows that each print their own
+key (cursor — `(y)`, `(tab)`, `(shift+tab)`, `(esc or n)`, carried in `number` so `rowKeys` presses it).
+And probe more than one kind of action before deciding your agent has only one prompt: claude gates the
+command *and* the edit, cursor gates only the command.
| `lib/summarize.ts` | The end-of-turn recap. Note the pooling rule: agents that take their recap prompt as argv rather than stdin cannot be pre-warmed, so they opt out of the worker pool. Pick the cheapest setting your agent has for it — this is the one call Harness makes on its own, on every turn |
| `lib/goalCommand.ts` | `/goal` and `/loop` support |
| `cli.ts` | Wire the normalizer into the watcher — the last connection that makes it live |
diff --git a/cli/src/engines/amp/askQuestion.ts b/cli/src/engines/amp/askQuestion.ts
index 504448800..b36af8621 100644
--- a/cli/src/engines/amp/askQuestion.ts
+++ b/cli/src/engines/amp/askQuestion.ts
@@ -110,6 +110,7 @@ export function parseAmpQuestionPane(capture: string): PaneView {
number: String(index),
label,
checked: false,
+ walk: 'down' as const,
}))
// What is being approved. The tool is the line ending in `:` above the JSON; the argument preview is
diff --git a/cli/src/engines/cursor/askQuestion.ts b/cli/src/engines/cursor/askQuestion.ts
new file mode 100644
index 000000000..c435da899
--- /dev/null
+++ b/cli/src/engines/cursor/askQuestion.ts
@@ -0,0 +1,123 @@
+/**
+ * Cursor's permission prompt — the only dialog cursor ever blocks a person on.
+ *
+ * It ships no ask-the-user tool at all (asked to use one, cursor answers that no MCP server provides it),
+ * so unlike every other engine this file has no question parser to sit beside. Captured live from
+ * cursor-agent 2026.08.11 (`__fixtures__/permission-cursor.txt`):
+ *
+ * ────────────────────────────────────────────────
+ * $ curl -s https://example.com in . ← the command, and the directory it runs in
+ *
+ * Run this command?
+ * Not in allowlist: curl ← why it is asking
+ * → Run (once) (y)
+ * Add Shell(curl) to allowlist? (tab)
+ * Run Everything (shift+tab)
+ * Skip & tell the agent what to do instead (esc or n)
+ *
+ * What makes cursor its own parser is the third selection mechanism in this codebase. Claude numbers its
+ * rows and a digit submits; amp and kilo number nothing and are walked with arrows; cursor numbers
+ * nothing either but **every row states its own key in a trailing parenthesis**. So the key is read off
+ * the row and carried in `number`, which is exactly what `rowKeys` presses — no walk, no digit, no engine
+ * branch in the driver.
+ *
+ * Two details worth stating, because both are choices rather than transcriptions:
+ *
+ * - `(esc or n)` becomes **`n`**, never `Escape`. Esc is also the pane's own cancel and on a busy
+ * cursor pane it does more than decline the prompt; the letter only ever answers this dialog.
+ * - `Run Everything` is KEPT, even though it disables approvals for the rest of the session. It is
+ * cursor's own wording for the same escape hatch claude spells "don't ask again" and amp spells
+ * "Allow All for Every Session", and hiding one engine's version of a row the others all offer would
+ * be a silent behaviour difference, not a safety feature. Tapping it stays the person's decision.
+ *
+ * There is no footer under the rows — the pane simply ends at the last option, the way Command Code's
+ * dialog does — so the frame's opening rule is the anchor at both ends.
+ *
+ * One fixture covers cursor because cursor has exactly one gate. Probed on a live pane: editing a file in
+ * the workspace, and even writing one OUTSIDE it (`/private/tmp/…`), both run unprompted once the
+ * workspace is trusted. Only a shell command absent from the allowlist stops for a person — so unlike
+ * claude, there is no second `Edit file` shape waiting to be missed.
+ */
+
+import type { PaneView, QuestionRow } from '../../lib/askQuestion.js'
+
+/** The row's own key hint, always the LAST parenthesis on the line. `[^()]` keeps `Shell(curl)` out. */
+const ROW_RE = /^\s*(?:[→▶>›]\s*)?(\S.*?)\s*\(([^()]{1,14})\)\s*$/
+/** The line that opens the frame. Cursor draws no box, just a rule. */
+const RULE_RE = /^\s*[─━═]{6,}\s*$/
+/** `Run this command?` — cursor states what it is asking before it lists the rows. */
+const PROMPT_RE = /^\s*(run|apply|allow|execute|edit|delete|write)\b.*\?\s*$/i
+/** Measured on this dialog: `Run (once)` approves, `Skip & tell the agent …` declines. */
+const APPROVE_RE = /^(run|allow|add|yes|approve|accept|proceed|continue)\b/i
+const REJECT_RE = /^(skip|no|reject|deny|decline|cancel|stop)\b/i
+
+function stripAnsi(value: string): string {
+ return value.replace(/\[[0-9;:]*[A-Za-z]/g, '')
+}
+
+/**
+ * The tmux key name for one of cursor's hints, or null when the row cannot be answered by keystroke.
+ *
+ * Measured hints: `y`, `tab`, `shift+tab`, `esc or n`.
+ */
+export function cursorRowKey(hint: string): string | null {
+ const h = hint.trim().toLowerCase()
+ if (/^shift\s*\+\s*tab$/.test(h)) return 'BTab'
+ if (/^tab$/.test(h)) return 'Tab'
+ if (/^enter$/.test(h)) return 'Enter'
+ // "esc or n" offers two keys for one row; take the letter, never Escape (see the docblock).
+ const letter = /(?:^|\bor\s+)([a-z0-9])$/.exec(h)
+ return letter ? letter[1] : null
+}
+
+export function parseCursorPermissionPane(capture: string): PaneView {
+ const lines = stripAnsi(capture).replace(/ /g, ' ').split('\n')
+
+ // The rows are the last contiguous run of key-hinted lines on the pane. Nothing follows them: cursor
+ // paints no footer, so walking up from the bottom-most row is the only anchor available.
+ let end = -1
+ for (let i = lines.length - 1; i >= 0; i--) {
+ if (ROW_RE.test(lines[i])) { end = i; break }
+ }
+ if (end < 0) return null
+
+ const rows: QuestionRow[] = []
+ let start = end + 1
+ for (let i = end; i >= 0 && end - i < 10; i--) {
+ const match = ROW_RE.exec(lines[i])
+ if (!match) break
+ const key = cursorRowKey(match[2])
+ // A row whose hint is not a single keystroke cannot be answered from a device; drop it rather than
+ // offer a choice that would do nothing.
+ if (key) rows.unshift({ number: key, label: match[1].trim(), checked: false })
+ start = i
+ }
+ if (rows.length < 2) return null
+ if (!rows.some((row) => APPROVE_RE.test(row.label)) || !rows.some((row) => REJECT_RE.test(row.label))) return null
+
+ // Above the rows: the prompt, then the frame's rule with the command just under it.
+ let prompt = -1
+ for (let i = start - 1; i >= 0 && start - i <= 6; i--) {
+ if (PROMPT_RE.test(lines[i])) { prompt = i; break }
+ }
+ if (prompt < 0) return null
+
+ let command = ''
+ for (let i = prompt - 1; i >= 0 && prompt - i <= 8; i--) {
+ if (!RULE_RE.test(lines[i])) continue
+ for (let j = i + 1; j < prompt; j++) {
+ const line = lines[j].trim().replace(/^\$\s*/, '').replace(/\s+/g, ' ')
+ // `… in .` just means the workspace root; a real subdirectory is worth keeping.
+ if (line) { command = line.replace(/\s+in\s+\.$/, ''); break }
+ }
+ break
+ }
+
+ return {
+ kind: 'question',
+ question: command ? `Approve ${command}` : lines[prompt].trim(),
+ rows,
+ multi: false,
+ typeRow: null,
+ }
+}
diff --git a/cli/src/engines/devin/askQuestion.ts b/cli/src/engines/devin/askQuestion.ts
index 7e57b590a..eec33e6c6 100644
--- a/cli/src/engines/devin/askQuestion.ts
+++ b/cli/src/engines/devin/askQuestion.ts
@@ -84,3 +84,71 @@ export function parseDevinQuestionPane(capture: string): PaneView {
if (/\(multi-select\)/i.test(question)) multi = true
return { kind: 'question', question: question.replace(/\s*\(multi-select\)\s*$/i, '').trim(), rows, multi, typeRow: null }
}
+
+/**
+ * Devin's PERMISSION prompt, which reuses the row syntax above and nothing else — no titled rule opens
+ * it and its footer drops the word `navigate`, so neither anchor of the parser above can see it.
+ * Captured live (`__fixtures__/permission-devin.txt`):
+ *
+ * ⏺ Running command
+ * └ $ curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin
+ *
+ * ❭ 1 Yes (Approve once)
+ * · 2 Yes, allow `curl` commands
+ * · 3 Yes, always allow `curl` commands in `work-devin`
+ * · 4 Yes, always allow `curl` commands in all projects
+ * · 5 Edit command
+ * · 6 Describe change to command
+ * · 7 No
+ * ↑↓ select · ↵ confirm · esc cancel
+ *
+ * Two measured properties shape this:
+ *
+ * - **Seven rows, and the device shows six.** `OPT_MAX` is 6 in the firmware, so a verbatim list would
+ * silently drop the LAST row — which is `No`, the only way to decline. Keeping just the rows that
+ * approve or reject brings it to five and puts `No` back on screen. The two dropped rows are
+ * `Edit command` and `Describe change to command`, which open a text editor the device cannot type
+ * into, so they were never answerable from there anyway.
+ * - **A digit selects AND submits**, despite a footer advertising only arrows — verified by pressing
+ * `7` on a live prompt and watching devin report `Tool execution was rejected by the user`. So these
+ * rows carry no `walk` and are keyed exactly like the ask dialog's.
+ *
+ * Anchored on `↵ confirm`, which the ask dialog spells `↵ select` — the one word that separates the two
+ * footers, and the reason this is a sibling function rather than another branch inside the parser above.
+ */
+const PERMISSION_FOOTER_RE = /↵\s*confirm/i
+/** The command under `⏺ Running command`, minus devin's box-drawing and shell decoration. */
+const COMMAND_RE = /^\s*[└├│]?\s*\$\s*(\S.*?)\s*$/
+const APPROVE_RE = /^(yes|allow|approve|accept|proceed|run|continue)\b/i
+const REJECT_RE = /^(no|reject|deny|decline|cancel|don'?t|stop)\b/i
+
+export function parseDevinPermissionPane(capture: string): PaneView {
+ const lines = stripAnsi(capture).replace(/ /g, ' ').split('\n')
+ const footer = lines.findLastIndex((line) => PERMISSION_FOOTER_RE.test(line))
+ if (footer < 0) return null
+
+ // The rows sit directly above the footer, back to the one numbered 1.
+ const rows: QuestionRow[] = []
+ let start = -1
+ for (let i = footer - 1; i >= 0 && footer - i <= 20; i--) {
+ const match = ROW_RE.exec(lines[i])
+ if (!match) continue
+ const [, , number, label] = match
+ if (!number) continue
+ rows.unshift({ number, label: label.replace(/\s{2,}/g, ' ').trim(), checked: false })
+ if (number === '1') { start = i; break }
+ }
+ if (start < 0 || rows.length < 2) return null
+
+ const answerable = rows.filter((row) => APPROVE_RE.test(row.label) || REJECT_RE.test(row.label))
+ if (!answerable.length || !answerable.some((row) => REJECT_RE.test(row.label))) return null
+
+ // What is being approved: the `$ …` line above the rows. Best-effort, like every other engine's — the
+ // row list is what the answer actually depends on.
+ let command = ''
+ for (let i = start - 1; i >= 0 && start - i <= 8; i--) {
+ const match = COMMAND_RE.exec(lines[i])
+ if (match) { command = match[1]; break }
+ }
+ return { kind: 'question', question: command ? `Approve ${command}` : 'Approval required', rows: answerable, multi: false, typeRow: null }
+}
diff --git a/cli/src/engines/grok/askQuestion.ts b/cli/src/engines/grok/askQuestion.ts
index f55750b5f..57986b994 100644
--- a/cli/src/engines/grok/askQuestion.ts
+++ b/cli/src/engines/grok/askQuestion.ts
@@ -16,10 +16,27 @@ function stripAnsi(value: string): string {
*
* Descriptions share the row with labels, separated by 2+ spaces. The `z` row opens free text and must
* not be offered as an option. Digits select and submit directly (verified by pressing `2`).
+ *
+ * Grok's PERMISSION prompt reuses this exact row syntax and only reworded the footer, so it needs a
+ * second footer alternative rather than a second parser (`__fixtures__/permission-grok.txt`):
+ *
+ * \u2503 Fetch Bitcoin price from CoinGecko
+ * \u2503 curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin
+ * \u2503
+ * \u2503 1 (\u25cf) Yes, and don't ask again for anything (always-approve mode)
+ * \u2503 2 (\u25cb) Yes, proceed
+ * \u2503 3 (\u25cb) No, reject (type to add feedback)
+ *
+ * 1/3:select \u2502 Tab:next option \u2502 Ctrl+o:always-approve \u2502 Ctrl+c:cancel \u2502 Esc:scrollback
+ *
+ * `1/3:select` is the range of digits the dialog accepts, and pressing one both selects AND submits here
+ * too \u2014 verified by pressing `2` on a live prompt and watching the command run. The question line the
+ * parser lands on is the COMMAND rather than grok's own one-line summary above it, which is the more
+ * useful of the two on a device screen.
*/
export function parseGrokQuestionPane(capture: string): PaneView {
const lines = stripAnsi(capture).replace(/\u00a0/g, ' ').split('\n')
- const footer = lines.findLastIndex((line) => /enter\s*:\s*submit/i.test(line))
+ const footer = lines.findLastIndex((line) => /enter\s*:\s*submit|\d+\/\d+\s*:\s*select/i.test(line))
if (footer < 0) return null
const rows: QuestionRow[] = []
diff --git a/cli/src/engines/kilo/askQuestion.ts b/cli/src/engines/kilo/askQuestion.ts
index cd9869f03..dbef166be 100644
--- a/cli/src/engines/kilo/askQuestion.ts
+++ b/cli/src/engines/kilo/askQuestion.ts
@@ -106,10 +106,14 @@ export function parseKiloQuestionPane(capture: string): PaneView {
}
if (labels.length < 2) return null
+ // `walk` travels with the row because this same dialog is opencode's — kilo is its fork — and opencode
+ // numbers its OTHER dialog. Without it, an opencode permission row would be answered with a digit that
+ // the horizontal list does not respond to.
const rows: QuestionRow[] = labels.map((label, index) => ({
number: String(index),
label,
checked: false,
+ walk: 'right' as const,
}))
// What is being permitted: the first content line under the title, minus the `←` bullet kilo draws on
diff --git a/cli/src/lib/__fixtures__/permission-claude-edit.txt b/cli/src/lib/__fixtures__/permission-claude-edit.txt
new file mode 100644
index 000000000..9a04a9a54
--- /dev/null
+++ b/cli/src/lib/__fixtures__/permission-claude-edit.txt
@@ -0,0 +1,51 @@
+
+
+╭─── Claude Code v2.1.232 ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
+│ │ Tips for getting started │
+│ Welcome back zon! │ Run /init to create a CLAUDE.md file with instructions for Claude │
+│ │ ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── │
+│  ▐▛███▜▌ │ What's new │
+│ ▝▜█████▛▘ │ Subagent forking is now on by default: a `subagent_type: "fork"` subagent inherits the full conversation and prompt cache, and non-teammate ag… │
+│  ▘▘ ▝▝  │ Type `@` in the prompt to mention another Claude session by name; Claude then uses `SendMessage` to reach that session directly │
+│ Sonnet 5 with xhigh effort · Claude Max ·  │ `SendMessage` now delivers to a bare name that exactly matches one live session, instead of asking to confirm with a ref first │
+│ [38;5;[email protected]'s Organization │ /release-notes for more │
+│ /…/scratchpad/permcap/work │ │
+╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
+
+
+❯ Run this exact command with Bash, nothing else: curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin
+
+ Ran 1 shell command 
+
+✻ Churned for 1m 16s
+
+❯ Use the Edit tool to change the word hello to world in README.md. Nothing else.
+
+ Read 1 file 
+
+⏺ Update(]8;id=ffutpc;file:///private/tmp/claude-502/-Users-example-work/00000000-0000-0000-0000-000000000000/scratchpad/permcap/work/README.md\README.md]8;;\)
+
+────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
+ Edit file
+ README.md
+╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌
+ 1 -hello
+ 1 +world
+╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌
+ Do you want to make this edit to README.md?
+ ❯ 1. Yes
+ 2. Yes, allow all edits during this session (shift+tab)
+ 3. No
+
+ Esc to cancel · Tab to amend
+
+
+
+
+
+
+
+
+
+
+
diff --git a/cli/src/lib/__fixtures__/permission-claude.txt b/cli/src/lib/__fixtures__/permission-claude.txt
new file mode 100644
index 000000000..21bc3e353
--- /dev/null
+++ b/cli/src/lib/__fixtures__/permission-claude.txt
@@ -0,0 +1,51 @@
+
+
+╭─── Claude Code v2.1.232 ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
+│ │ Tips for getting started │
+│ Welcome back zon! │ Run /init to create a CLAUDE.md file with instructions for Claude │
+│ │ ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── │
+│  ▐▛███▜▌ │ What's new │
+│ ▝▜█████▛▘ │ Subagent forking is now on by default: a `subagent_type: "fork"` subagent inherits the full conversation and prompt cache, and non-teammate ag… │
+│  ▘▘ ▝▝  │ Type `@` in the prompt to mention another Claude session by name; Claude then uses `SendMessage` to reach that session directly │
+│ Sonnet 5 with xhigh effort · Claude Max ·  │ `SendMessage` now delivers to a bare name that exactly matches one live session, instead of asking to confirm with a ref first │
+│ [38;5;[email protected]'s Organization │ /release-notes for more │
+│ /…/scratchpad/permcap/work │ │
+╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
+
+
+❯ Run this exact command with Bash, nothing else: curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin
+
+⏺ Fetching Bitcoin price from CoinGecko API
+ ⎿ $ curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin
+
+────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
+ Bash command
+
+ curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin
+ Fetch Bitcoin price from CoinGecko API
+
+ This command requires approval
+
+ Do you want to proceed?
+ ❯ 1. Yes
+ 2. Yes, and don’t ask again for: curl *
+ 3. No
+
+ Esc to cancel · Tab to amend · ctrl+e to explain
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/cli/src/lib/__fixtures__/permission-codex.txt b/cli/src/lib/__fixtures__/permission-codex.txt
new file mode 100644
index 000000000..d8e36a10f
--- /dev/null
+++ b/cli/src/lib/__fixtures__/permission-codex.txt
@@ -0,0 +1,74 @@
+codex
+example@mac work-codex % codex
+> You are in /private/tmp/claude-502/-Users-example-work/00000000-0000-0000-0000-000000000000/scratchpad/permcap/work-codex
+
+ Do you trust the contents of this directory? Working with untrusted contents comes with higher risk of prompt injection. Trusting the directory allows project-local config, hooks, and exec policies
+ to load.
+
+› 1. Yes, continue
+ 2. No, quit
+
+ Press enter to continue
+
+╭─────────────────────────────────────────────────────────╮
+│ >_ OpenAI Codex (v0.147.0) │
+│ │
+│ model: loading /model to change │
+│ directory: /private/tmp/claude-502/…/permcap/work-codex │
+╰─────────────────────────────────────────────────────────╯
+
+
+› Explain this codebase
+
+ gpt-5.6-sol default · /private/tmp/claude-502/-Users-example-work/00000000-0000-0000-0000-000000000000/scratchpad/permcap/work-codex
+
+╭─────────────────────────────────────────────────────────╮
+│ >_ OpenAI Codex (v0.147.0) │
+│ │
+│ model: gpt-5.6-sol high /model to change │
+│ directory: /private/tmp/claude-502/…/permcap/work-codex │
+╰─────────────────────────────────────────────────────────╯
+
+ Tip: New Use /fast to enable our fastest inference with increased plan usage.
+
+
+› Run this exact command in the shell, nothing else: curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin
+
+
+• Ran curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin
+ └ zsh:1: no matches found: https://api.coingecko.com/api/v3/simple/price?ids=bitcoin
+
+────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
+
+• zsh:1: no matches found: ]8;;https://api.coingecko.com/api/v3/simple/price?ids=bitcoin\https://api.coingecko.com/api/v3/simple/price?ids=bitcoin]8;;\
+
+────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
+
+
+› Create the file /private/etc/harness-probe.txt containing the word hi. Use the shell.
+
+
+• I’ll create that exact file via the shell; writing under /private/etc requires your approval.
+
+• Running printf 'hi\n' > /private/etc/harness-probe.txt
+
+
+ Would you like to run the following command?
+
+ Environment: local
+
+ Reason: Allow creating /private/etc/harness-probe.txt containing the word hi?
+
+ $ printf 'hi\n' > /private/etc/harness-probe.txt
+
+› 1. Yes, proceed (y)
+ 2. Yes, and don't ask again for commands that start with `printf 'hi\n' > /private/etc/harness-probe.txt` (p)
+ 3. No, and tell Codex what to do differently (esc)
+
+ Press enter to confirm or esc to cancel
+
+
+
+
+
+
diff --git a/cli/src/lib/__fixtures__/permission-commandcode.txt b/cli/src/lib/__fixtures__/permission-commandcode.txt
new file mode 100644
index 000000000..664451702
--- /dev/null
+++ b/cli/src/lib/__fixtures__/permission-commandcode.txt
@@ -0,0 +1,50 @@
+commandcode
+example@mac work-commandcode % commandcode
+
+ 
+ ███████ ███████ ███████████ ███████████ ███████ ████████ ████ 
+ ███ ███ ██ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███████ 
+ ███ ██ ███ ███ ███ ███ ███ ███ ███ ███████ ███ ███ ███ ███ 
+ ███ ███ ██ ███ ███ ███ ███ ███ ███ ███ ███████ ███ ███ ███ ███ 
+ ███████ ███████ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███████ 
+ 
+
+# Command Code v1.24.0
+# models: deepseek-v4-flash-(latest) · taste-1
+# /private/tmp/claude-502/-Users-example-work/00000000-0000-0000-0000-000000000000/scratchpad/permcap/work-commandcode
+
+◼ Ran 1 session start hook
+
+❯ Run this exact command in the shell, nothing else: curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin 
+
+✻ Thought for 1 second [ctrl+o to expand]
+
+
+────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
+
+Execute Shell Command
+Command Code needs to execute curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin.
+
+Press [ctrl+e] to explain this command
+
+❯ 1. Yes
+  2. Yes, don't ask again for this exact command in this project
+  3. No, tell Command Code what to do differently
+
+↑/↓ navigate · enter select · ctrl+e explain · Run cmd --yolo to bypass all permissions (]8;;https://commandcode.ai/docs/permissions#permission-modes\Docs ↗]8;;\)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/cli/src/lib/__fixtures__/permission-cursor.txt b/cli/src/lib/__fixtures__/permission-cursor.txt
new file mode 100644
index 000000000..ae298cfa7
--- /dev/null
+++ b/cli/src/lib/__fixtures__/permission-cursor.txt
@@ -0,0 +1,50 @@
+cursor-agent
+example@mac work-cursorcap % cursor-agent
+
+ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
+ │ │
+ │ ⚠ Workspace Trust Required │
+ │ │
+ │ Cursor Agent can execute code and access files in this directory. │
+ │ │
+ │ Do you trust the contents of this directory? │
+ │ │
+ │ /private/tmp/claude-502/-Users-example-work/00000000-0000-0000-0000-000000000000/scratchpad/permcap/work-cursorcap │
+ │ │
+ │ │
+ │  [a] Trust this workspace │
+ │  [q] Quit │
+ │ │
+ │ ⏳ Trusting workspace... │
+ │ │
+ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
+
+
+ Cursor Agent
+ v2026.08.11-e8db854
+ Tip: Use /plan to plan execution and reach the right outcome faster.
+
+  
+  Run this exact command in the shell, nothing else: curl -s https://example.com 
+  
+
+ $ curl -s https://example.com Waiting for approval...
+
+────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
+ $ curl -s https://example.com in .
+
+ Run this command?
+ Not in allowlist: curl
+ → Run (once) (y)
+ Add Shell(curl) to allowlist? (tab)
+ Run Everything (shift+tab)
+ Skip & tell the agent what to do instead (esc or n)
+
+
+
+
+
+
+
+
+
diff --git a/cli/src/lib/__fixtures__/permission-devin.txt b/cli/src/lib/__fixtures__/permission-devin.txt
new file mode 100644
index 000000000..2db7ef763
--- /dev/null
+++ b/cli/src/lib/__fixtures__/permission-devin.txt
@@ -0,0 +1,50 @@
+devin
+example@mac work-devin % devin
+◆ Trust /private/tmp/claude-502/-Users-example-work/00000000-0000-0000-0000-000000000000/scratchpad/permcap/work-devin? Yes, trust /private/tmp/claude-502/-
+Users-example-go-src-github-com-autonomous-ai-autonomous-code/00000000-0000-0000-0000-000000000000/scratchpad/permcap/work-devin
+⠀⣴⣾⣶⡄⠀⠀⠀⠀
+⠀⠛⠿⠟⠻⣶⣾⣶⡄ Devin CLI
+⠀⣤⣶⣦⣴⠿⢿⠿⠃ v3000.4.16
+⠀⠻⢿⠿⠃⠀⠀⠀⠀
+ ┌────────────────────────────────────────────────────────────────────────┐
+ │ │
+ │ Welcome to Devin CLI! │
+ │ │
+ │ We have a few tips to help you get the most out of this tool: │
+ │ │
+ │ 1. Devin can set itself up (e.g. Skills and MCPs). Just ask! │
+ │ │
+ │ 2. Confused by all the /models? Here are ]8;;https://cli.devin.ai/docs/models#model-selection-tips\our tips to pick]8;;\  │
+ │ (https://cli.devin.ai/docs/models#model-selection-tips). │
+ │ │
+ │ 3. If you want to see what Devin is up to, Control + O and the │
+ │ down arrow key can be useful. │
+ │ │
+ │ You won't see this message again but you can talk to us at │
+ │ ]8;;https://x.com/cognition\x.com/cognition]8;;\ (https://x.com/cognition). │
+ │ │
+ └────────────────────────────────────────────────────────────────────────┘
+
+Free plan, use /upgrade to access better models · 100% remaining (resets in 29m)
+
+❭ Run this exact command in the shell, nothing else: curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin
+
+⏺ Running command
+ └ $ curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin
+
+❭ 1 Yes (Approve once)
+· 2 Yes, allow `curl` commands
+· 3 Yes, always allow `curl` commands in `work-devin`
+· 4 Yes, always allow `curl` commands in all projects
+· 5 Edit command
+· 6 Describe change to command
+· 7 No
+↑↓ select · ↵ confirm · esc cancel
+
+
+
+
+
+
+
+
diff --git a/cli/src/lib/__fixtures__/permission-grok.txt b/cli/src/lib/__fixtures__/permission-grok.txt
new file mode 100644
index 000000000..bd013a2bc
--- /dev/null
+++ b/cli/src/lib/__fixtures__/permission-grok.txt
@@ -0,0 +1,50 @@
+
+ /private/tmp/claude-502/-Users-example-work/00000000-0000-0000-0000-000000000000/scratchpad/permcap/work-grok ]8;;https://grok.com/supergrok?referrer=grok-build\[Click here to Upgrade]]8;;\ 15K / 500K
+
+  
+  ❯ Run this exact command in the shell, nothing else: curl -s ]8;;https://api.coingecko.com/api/v3/simple/price?ids=bitcoin\https://api.coingecko.com/api/v3/simple/price?ids=bitcoin]8;;\  2:31 PM 
+  
+
+ ◆ user_prompt_submit [hooks: 2]
+ ◆ Thought for 0.1s
+
+ I'll run that exact curl command now.  2:31 PM
+
+ ┃ ◆ Run Fetch Bitcoin price from CoinGecko
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ◆ Fetch Bitcoin price from CoinGecko… 1m33s 1m36s ⇣15.2k [↓][stop]
+
+ ]8;;https://grok.com/supergrok?referrer=grok-build\[Click here to Upgrade]]8;;\
+
+ ┃ 
+ ┃ Fetch Bitcoin price from CoinGecko 
+ ┃ curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin 
+ ┃ 
+ ┃ 1 (●) Yes, and don't ask again for anything (always-approve mode)  
+ ┃ 2 (○) Yes, proceed 
+ ┃ 3 (○) No, reject (type to add feedback) 
+ ┃ 
+
+ 1/3:select │ Tab:next option │ Ctrl+o:always-approve │ Ctrl+c:cancel │ Esc:scrollback 
+
diff --git a/cli/src/lib/__fixtures__/permission-hermes.txt b/cli/src/lib/__fixtures__/permission-hermes.txt
new file mode 100644
index 000000000..40f899cdd
--- /dev/null
+++ b/cli/src/lib/__fixtures__/permission-hermes.txt
@@ -0,0 +1,74 @@
+hermes
+example@mac work-hermes % hermes
+
+██╗ ██╗███████╗██████╗ ███╗ ███╗███████╗███████╗ █████╗ ██████╗ ███████╗███╗ ██╗████████╗
+██║ ██║██╔════╝██╔══██╗████╗ ████║██╔════╝██╔════╝ ██╔══██╗██╔════╝ ██╔════╝████╗ ██║╚══██╔══╝
+███████║█████╗ ██████╔╝██╔████╔██║█████╗ ███████╗█████╗███████║██║ ███╗█████╗ ██╔██╗ ██║ ██║
+██╔══██║██╔══╝ ██╔══██╗██║╚██╔╝██║██╔══╝ ╚════██║╚════╝██╔══██║██║ ██║██╔══╝ ██║╚██╗██║ ██║
+██║ ██║███████╗██║ ██║██║ ╚═╝ ██║███████╗███████║ ██║ ██║╚██████╔╝███████╗██║ ╚████║ ██║
+╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝
+
+╭──────────────────────────────────────────────────────────────────────── Hermes Agent v0.19.0 (2026.7.20) · upstream d71033a4 ────────────────────────────────────────────────────────────────────────╮
+│ Available Tools │
+│ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⡀⠀⣀⣀⠀⢀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ browser: browser_back, browser_click, ... │
+│ ⠀⠀⠀⠀⠀⠀⢀⣠⣴⣾⣿⣿⣇⠸⣿⣿⠇⣸⣿⣿⣷⣦⣄⡀⠀⠀⠀⠀⠀⠀ clarify: clarify │
+│ ⠀⢀⣠⣴⣶⠿⠋⣩⡿⣿⡿⠻⣿⡇⢠⡄⢸⣿⠟⢿⣿⢿⣍⠙⠿⣶⣦⣄⡀⠀ code_execution: execute_code │
+│ ⠀⠀⠉⠉⠁⠶⠟⠋⠀⠉⠀⢀⣈⣁⡈⢁⣈⣁⡀⠀⠉⠀⠙⠻⠶⠈⠉⠉⠀⠀ computer_use: computer_use │
+│ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣴⣿⡿⠛⢁⡈⠛⢿⣿⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ cronjob: cronjob │
+│ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠿⣿⣦⣤⣈⠁⢠⣴⣿⠿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ delegation: delegate_task │
+│ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠻⢿⣿⣦⡉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ file: patch, read_file, search_files, write_file │
+│ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢷⣦⣈⠛⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ image_gen: image_generate │
+│ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣴⠦⠈⠙⠿⣦⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ (and 9 more toolsets...) │
+│ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⣿⣤⡈⠁⢤⣿⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ │
+│ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠷⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ Available Skills │
+│ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⠑⢶⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ apple: apple-notes, apple-reminders, findmy, imessage │
+│ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠁⢰⡆⠈⡿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ autonomous-ai-agents: claude-code, codex, computer-use, hermes-agent, opencode │
+│ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠳⠈⣡⠞⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ creative: architecture-diagram, ascii-art, ascii-video, baoyu-infographic, claude-design,  │
+│ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ comfyui, +10 more │
+│ email: himalaya │
+│ auto · Nous Research general: grid-chart, grid-host, grid-research, grid-serve, grid-web, vietnamese-fx-rates │
+│ /private/tmp/claude-502/-Users-example-work/763aa3… github: codebase-inspection, github-auth, github-code-review, github-issues, github-pr-workflow,  │
+│ Session: 20260814_143002_ca7d86 +1 more │
+│ media: gif-search, songsee, youtube-content │
+│ mlops: evaluating-llms-harness, huggingface-hub, llama-cpp, serving-llms-vllm, weights-and-biases │
+│ note-taking: obsidian │
+│ productivity: airtable, docx, google-workspace, maps, nano-pdf, notion, ocr-and-documents, pdf,  │
+│ +3 more │
+│ research: arxiv, blogwatcher, llm-wiki, polymarket, research-paper-writing │
+│ smart-home: openhue │
+│ social-media: xurl │
+│ software-development: dogfood, hermes-agent-skill-authoring, node-inspect-debugger, plan, +6 more │
+│ │
+│ 28 tools · 75 skills · /help for commands │
+│ ⚠ 1 commit behind — run hermes update to update │
+╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
+
+Welcome to Hermes Agent! Type your message or /help for commands.
+✦ Tip: The terminal tool supports 6 backends: local, Docker, SSH, Modal, Daytona, and Singularity.
+
+
+────────────────────────────────────────
+● Run this exact command in the shell, nothing else: curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin
+Initializing agent...
+
+────────────────────────────────────────
+╭──────────────────────────────────────────────────────────────────╮
+│ ⚠️ Dangerous Command  │
+│ │
+│ curl -s  │
+│ https://api.coingecko.com/api/v3/simple/price?ids=bitcoin  │
+│ │
+│ ❯ 1. Allow once  │
+│  2. Allow for this session  │
+│  3. Deny  │
+│ │
+│ Security scan — [MEDIUM] Python package from non-PyPI source:  │
+│ Package URL points to 'api.coingecko.com' instead of PyPI  │
+╰──────────────────────────────────────────────────────────────────╯
+
+ 💻 curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin (01m30s · ↓ 82 tok)
+ ↑/↓ to select, Enter to confirm (212s)
+ ⚕ auto │ 18.5K/256K │ [█░░░░░░░░░] 7% │ 3m │ ⏱ 1m 37s 
+────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
+⚠ ❯ 
+────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
diff --git a/cli/src/lib/__fixtures__/permission-muse.txt b/cli/src/lib/__fixtures__/permission-muse.txt
new file mode 100644
index 000000000..44b1f54cf
--- /dev/null
+++ b/cli/src/lib/__fixtures__/permission-muse.txt
@@ -0,0 +1,50 @@
+muse --approval-mode untrusted
+example@mac work-muse2 % muse --approval-mode untrusted
+ 
+ Muse Code 0.1.0
+
+ Model set to muse-spark-1.2-contributor
+ ⎿ Discounted tokens: your content may be used for product improvement.
+
+⟩ Run this exact command in the shell, nothing else: curl -s https://example.com
+
+◆ Backgrounded · Run curl to example.com · 13s · ctrl+o
+
+ (↓ to view terminals)
+
+◆ Command executed. Output will be returned when available.
+
+◇ Calling tools (21s · esc to interrupt)
+
+── Voice input (⌥ + v to start) ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
+Would you like to allow this network access?
+
+ network: example.com:443 https
+ requested by:
+ $ curl -s https://example.com
+
+› 1. Yes, proceed (y)
+ 2. Yes, don't ask again this session (p) example.com:443 (https)
+ 3. No, and tell Muse Code what to do differently (esc)
+ Press enter to confirm or esc to cancel
+────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
+main · ↓ to select
+└ ⠼ curl -s https://example.com running 13s
+ muse-spark-1.2-contributor · medium · /private/tmp/claude-502/-Users-example-work/00000000-0000-0000-0000-000000000000/scratchpad/permcap/work-muse2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/cli/src/lib/__fixtures__/permission-opencode.txt b/cli/src/lib/__fixtures__/permission-opencode.txt
new file mode 100644
index 000000000..777507d15
--- /dev/null
+++ b/cli/src/lib/__fixtures__/permission-opencode.txt
@@ -0,0 +1,50 @@
+ 
+ ┃   Fetch Bitcoin price from CoinGecko
+ ┃ Run this exact command in the shell, nothing else: curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin  
+ ┃   Context
+  8,776 tokens
+ + Thought: 117ms  2% used
+  $0.00 spent
+ ┃  
+ ┃ $ curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin   LSP
+ ┃   LSPs are disabled
+ ┃ zsh:1: no matches found: https://api.coingecko.com/api/v3/simple/price?ids=bitcoin  
+ ┃  
+ 
+ + Thought: 100ms 
+ 
+ The command failed: zsh interpreted the ? in the URL as a glob pattern. Wrap the URL in quotes or escape it: 
+ 
+ curl -s "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin" 
+ 
+ ▣  Build · MiniMax M3 (vibe) · 4.2s 
+ 
+ ┃  
+ ┃ Read the file /private/etc/hosts and show me its first line.  
+ ┃  
+ 
+ + Thought: 569ms 
+ 
+ ⠹ Read /private/etc/hosts [limit=1] 
+ 
+ ▣  Build · MiniMax M3 (vibe) 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ ┃  
+ ┃ △ Permission required  
+ ┃ ← Access external directory /private/etc  
+ ┃  
+ ┃ Patterns   /private/tmp/claude-502/-Users-
+ ┃   example-go-src-github-com-autonomous-
+ ┃ - /private/etc/*   ai-autonomous-code/00000000-0000-0000-
+ ┃   aff2-411a82689b17/scratchpad/permcap/
+ ┃   work-opencode
+ ┃  Allow once  Allow always Reject ctrl+f fullscreen ⇆ select enter confirm  
+ ┃   • OpenCode 1.18.18
+ 
diff --git a/cli/src/lib/askQuestion.spec.ts b/cli/src/lib/askQuestion.spec.ts
index a0699bfac..c2ee3b515 100644
--- a/cli/src/lib/askQuestion.spec.ts
+++ b/cli/src/lib/askQuestion.spec.ts
@@ -160,12 +160,12 @@ interface Machine {
controller: AskQuestionController
}
-function machine(captures: string[]): Machine {
+function machine(captures: string[], engine?: string): Machine {
const keys: string[] = []
const texts: string[] = []
let i = 0
const controller = new AskQuestionController({
- getSession: () => ({ sessionId: 's1', tmuxPane: '%1' } as RegisteredSession),
+ getSession: () => ({ sessionId: 's1', tmuxPane: '%1', ...(engine ? { engine } : {}) } as RegisteredSession),
capture: async () => captures[Math.min(i++, captures.length - 1)],
sendText: async (_pane, text) => { texts.push(text); return true },
sendKey: async (_pane, key) => { keys.push(key); return true },
@@ -405,3 +405,215 @@ describe('the Command Code review screen', () => {
expect(view?.kind).not.toBe('question')
})
})
+
+/**
+ * Permission prompts — the reason this whole bridge matters on a remote machine.
+ *
+ * The CLI attaches to an agent the USER started, under the user's own config and with no permission flag
+ * of ours, so a blocking approval is the pane's normal state rather than an edge case. Every fixture below
+ * is a real `tmux capture-pane -e` of a live prompt, triggered by asking the engine to run a curl (or, for
+ * opencode, to read outside its workspace) — never hand-written, per `engines/README.md`'s one rule.
+ *
+ * Four engines needed nothing: codex and hermes already fall out of the shared parser (their footers are
+ * its anchor), opencode's is kilo's horizontal prompt, and amp/kilo shipped theirs earlier. Muse and pi
+ * are absent because they have no such prompt at all — both sandbox the shell and refuse outright rather
+ * than ask (measured: muse answers "the shell is sandboxed to the workspace", pi reports the denial and
+ * offers alternatives). Cursor is absent because its free-request limit blocked a capture, and a parser
+ * written without one would be exactly the silent failure the one rule exists to prevent.
+ */
+const permission = (name: string): string =>
+ readFileSync(join(__dirname, '__fixtures__', `permission-${name}.txt`), 'utf8')
+
+describe('permission prompts, per engine', () => {
+ const cases: Array<{ engine: string; fixture: string; question: string; rows: string[] }> = [
+ {
+ engine: 'claude', fixture: 'claude',
+ question: 'Approve Bash command: curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin',
+ // Note the TYPOGRAPHIC apostrophe: Claude writes "don’t", not "don't".
+ rows: ['Yes', 'Yes, and don’t ask again for: curl *', 'No'],
+ },
+ {
+ engine: 'claude', fixture: 'claude-edit',
+ question: 'Approve Edit file: README.md',
+ rows: ['Yes', 'Yes, allow all edits during this session (shift+tab)', 'No'],
+ },
+ {
+ engine: 'commandcode', fixture: 'commandcode',
+ question: 'Approve Execute Shell Command: Command Code needs to execute curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin.',
+ rows: ['Yes', "Yes, don't ask again for this exact command in this project", 'No, tell Command Code what to do differently'],
+ },
+ {
+ engine: 'codex', fixture: 'codex',
+ question: "$ printf 'hi\\n' > /private/etc/harness-probe.txt",
+ rows: [
+ 'Yes, proceed (y)',
+ "Yes, and don't ask again for commands that start with `printf 'hi\\n' > /private/etc/harness-probe.txt` (p)",
+ 'No, and tell Codex what to do differently (esc)',
+ ],
+ },
+ {
+ engine: 'devin', fixture: 'devin',
+ question: 'Approve curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin',
+ rows: ['Yes (Approve once)', 'Yes, allow `curl` commands', 'Yes, always allow `curl` commands in `work-devin`', 'Yes, always allow `curl` commands in all projects', 'No'],
+ },
+ {
+ engine: 'grok', fixture: 'grok',
+ question: 'curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin',
+ rows: ["Yes, and don't ask again for anything (always-approve mode)", 'Yes, proceed', 'No, reject (type to add feedback)'],
+ },
+ {
+ // Muse gates the NETWORK, not the command: its prompt names the host, and it only appears at all
+ // because `--approval-mode` defaults to `on-request`. A first sweep that only tried a sandboxed
+ // file write concluded muse never asks — it does.
+ engine: 'muse', fixture: 'muse',
+ question: '$ curl -s https://example.com',
+ rows: ['Yes, proceed (y)', "Yes, don't ask again this session (p) example.com:443 (https)", 'No, and tell Muse Code what to do differently (esc)'],
+ },
+ {
+ engine: 'hermes', fixture: 'hermes',
+ question: 'https://api.coingecko.com/api/v3/simple/price?ids=bitcoin',
+ rows: ['Allow once', 'Allow for this session', 'Deny'],
+ },
+ {
+ // Cursor is the third selection mechanism: it numbers nothing and walks nothing — each row states
+ // its own key, so `number` carries `y` / `Tab` / `BTab` / `n` instead of a digit or an index.
+ engine: 'cursor', fixture: 'cursor',
+ question: 'Approve curl -s https://example.com',
+ rows: ['Run (once)', 'Add Shell(curl) to allowlist?', 'Run Everything', 'Skip & tell the agent what to do instead'],
+ },
+ {
+ engine: 'opencode', fixture: 'opencode',
+ question: 'Access external directory /private/etc',
+ rows: ['Allow once', 'Allow always', 'Reject'],
+ },
+ ]
+
+ for (const c of cases) {
+ describe(`${c.engine} (${c.fixture})`, () => {
+ const view = (): QuestionView => asQuestion(parseEngineQuestionPane(c.engine as never, permission(c.fixture)))
+
+ it('reads the prompt and every option off the pane', () => {
+ expect(view().question).toBe(c.question)
+ expect(view().rows.map((row) => row.label)).toEqual(c.rows)
+ })
+
+ it('keeps a way to say no', () => {
+ // Amp's rule, and the reason its "Reject with feedback" row survives: a device user offered three
+ // ways to approve and none to decline cannot answer the prompt at all. The word varies more than
+ // it looks — cursor says "Skip", hermes says "Deny" — which is why the shared REJECT_RE lists all
+ // of them rather than assuming "no".
+ expect(view().rows.some((row) => /^(no|reject|deny|skip|cancel)\b/i.test(row.label))).toBe(true)
+ })
+
+ it('is single-select with nothing to type into', () => {
+ // The device answers a question by TAPPING (ui_screens.c) and an approval has no free-text row,
+ // so a typeRow here would offer a choice the device can never make.
+ expect(view().multi).toBe(false)
+ expect(view().typeRow).toBeNull()
+ })
+
+ it('fits the device screen', () => {
+ // Firmware caps: Q_MAX 4 questions, OPT_MAX 6 options. Overflow is dropped SILENTLY, and the row
+ // that would fall off the end is the last one — which on devin is "No".
+ expect(view().rows.length).toBeLessThanOrEqual(6)
+ })
+ })
+ }
+})
+
+describe('permission prompts vs the ask dialog', () => {
+ // Both anchors can be on one capture, because a pane keeps its scrollback. Whichever sits LOWER is the
+ // live dialog; getting this backwards shows the user a prompt they already answered, or answers the
+ // wrong dialog with the digit meant for the other.
+ it('takes the permission prompt when it is below an answered question', () => {
+ const view = asQuestion(parseQuestionPane(fixture('single') + permission('claude')))
+ expect(view.rows.map((r) => r.label)).toEqual(['Yes', 'Yes, and don’t ask again for: curl *', 'No'])
+ })
+
+ it('takes the question when IT is the lower of the two', () => {
+ const view = asQuestion(parseQuestionPane(permission('claude') + fixture('single')))
+ expect(view.question).toBe('Which drink would you like?')
+ expect(view.rows.map((r) => r.label)).toEqual(['Tea', 'Coffee'])
+ })
+
+ it('does not read an ordinary numbered list as an approval', () => {
+ // The rows are what identify a permission prompt — a list that offers no way to decline is prose.
+ const prose = [
+ 'Here is the plan:',
+ ' 1. Yes we should refactor the parser',
+ ' 2. Then update the fixtures',
+ '',
+ 'Esc to cancel',
+ ].join('\n')
+ expect(parseQuestionPane(prose)).toBeNull()
+ })
+
+ it('does not read a numbered block with no key hints under it as an approval', () => {
+ const orphan = [' 1. Yes', ' 2. No', '', '', '', '', '', ''].join('\n')
+ expect(parseQuestionPane(orphan)).toBeNull()
+ })
+})
+
+describe('answering a permission prompt from the device', () => {
+ it('presses the digit that declines, on an engine whose rows are numbered', () => {
+ // Verified on a live claude pane: one digit selects AND submits, so no Enter follows it.
+ const h = machine([permission('claude'), CLOSED])
+ const answers = { 'Approve Bash command: curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin': 'No' }
+ return h.controller.answer({ requestId: 'r1', sessionId: 's1', answers }).then((ok) => {
+ expect(ok).toBe(true)
+ expect(h.keys).toEqual(['3'])
+ })
+ })
+
+ it('presses devin\'s real row number, not its position in the shortened list', () => {
+ // Devin's "No" is row 7 of 7; two unanswerable editor rows are dropped from what the device shows, so
+ // the label→digit mapping must survive that filter.
+ const h = machine([permission('devin'), CLOSED], 'devin')
+ return h.controller.answer({ requestId: 'r1', sessionId: 's1', answers: { 'Approve curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin': 'No' } }).then((ok) => {
+ expect(ok).toBe(true)
+ expect(h.keys).toEqual(['7'])
+ })
+ })
+
+ it('walks to the row on opencode, whose permission prompt numbers nothing', () => {
+ // opencode draws BOTH a numbered ask dialog and kilo's horizontal prompt, so the direction travels on
+ // the ROW. Keying "2" here would select nothing at all.
+ const h = machine([permission('opencode'), CLOSED], 'opencode')
+ return h.controller.answer({ requestId: 'r1', sessionId: 's1', answers: { 'Access external directory /private/etc': 'Reject' } }).then((ok) => {
+ expect(ok).toBe(true)
+ expect(h.keys).toEqual(['Right', 'Right', 'Enter'])
+ })
+ })
+
+ it('matches an option the device truncated to its 80-byte buffer', () => {
+ const h = machine([permission('codex'), CLOSED], 'codex')
+ const truncated = "Yes, and don't ask again for commands that start with `printf 'hi\\n' > /priva"
+ return h.controller.answer({ requestId: 'r1', sessionId: 's1', answers: { "$ printf 'hi\\n' > /private/etc/harness-probe.txt": truncated } }).then((ok) => {
+ expect(ok).toBe(true)
+ expect(h.keys).toEqual(['2'])
+ })
+ })
+})
+
+describe('QuestionWatcher on a permission prompt', () => {
+ it('announces it exactly like a question, so the firmware renders it unchanged', async () => {
+ const seen: Array<{ requestId: string; questions: Array<{ key: string; q: string; options: string[]; multi: boolean }> }> = []
+ const w = new QuestionWatcher({
+ getSession: () => ({ sessionId: 's1', tmuxPane: '%1', engine: 'claude' } as RegisteredSession),
+ capture: async () => permission('claude'),
+ hasDevice: () => true,
+ onQuestion: (_s, requestId, questions) => { seen.push({ requestId, questions }) },
+ })
+ const tick = (): Promise<void> => (w as unknown as { tick: (s: string) => Promise<void> }).tick('s1')
+ await tick()
+ expect(seen).toHaveLength(1)
+ expect(seen[0].questions[0]).toMatchObject({
+ q: 'Approve Bash command: curl -s https://api.coingecko.com/api/v3/simple/price?ids=bitcoin',
+ options: ['Yes', 'Yes, and don’t ask again for: curl *', 'No'],
+ multi: false,
+ })
+ // Same prompt still on screen ⇒ announced once, not every 1.5s tick.
+ await tick()
+ expect(seen).toHaveLength(1)
+ })
+})
diff --git a/cli/src/lib/askQuestion.ts b/cli/src/lib/askQuestion.ts
index cc6d67a02..f939654f3 100644
--- a/cli/src/lib/askQuestion.ts
+++ b/cli/src/lib/askQuestion.ts
@@ -26,7 +26,8 @@ import type { AgentEngine } from '../engines/types.js'
import { parseMuseQuestionPane } from '../engines/muse/askQuestion.js'
import { ampSelectionKeys, parseAmpQuestionPane } from '../engines/amp/askQuestion.js'
import { kiloSelectionKeys, parseKiloQuestionPane } from '../engines/kilo/askQuestion.js'
-import { parseDevinQuestionPane } from '../engines/devin/askQuestion.js'
+import { parseCursorPermissionPane } from '../engines/cursor/askQuestion.js'
+import { parseDevinPermissionPane, parseDevinQuestionPane } from '../engines/devin/askQuestion.js'
import { parseGrokQuestionPane } from '../engines/grok/askQuestion.js'
/** Device-facing question shape — byte-for-byte the hosted runtime’s `commanderQuestions()` output. */
@@ -43,6 +44,15 @@ export interface QuestionRow {
/** Option text with any `[ ]` checkbox prefix removed. */
label: string
checked: boolean
+ /**
+ * Set only when the dialog does NOT number its rows: the row is then reached by walking to it and
+ * pressing Enter, and `number` carries its INDEX rather than a key.
+ *
+ * The direction is a property of the DIALOG, not of the engine. OpenCode draws BOTH a numbered ask
+ * dialog and — for permissions — the horizontal prompt kilo inherited from it, so keying by engine
+ * would send digits into a dialog that numbers nothing and select nothing at all.
+ */
+ walk?: 'right' | 'down'
}
export interface QuestionView {
@@ -117,10 +127,18 @@ export function shapeQuestions(questions: unknown): ShapedQuestion[] {
* its own parser rather than more branches in here.
*/
export function parseEngineQuestionPane(engine: AgentEngine, capture: string): PaneView {
- if (engine === 'devin') return parseDevinQuestionPane(capture)
+ // Devin's two dialogs are told apart by one word in the footer (`↵ select` vs `↵ confirm`), so they can
+ // never both match. Only one can be on screen anyway: answering either replaces it with a summary line.
+ if (engine === 'devin') return parseDevinQuestionPane(capture) ?? parseDevinPermissionPane(capture)
+ // Cursor has no ask-the-user tool, so its permission prompt is the ONLY dialog it ever draws — and it
+ // numbers nothing, stating each row's key in the row instead.
+ if (engine === 'cursor') return parseCursorPermissionPane(capture)
// Muse pairs each option with a description on the same line and floats a live Preview box above the
- // rows — both confuse the shared parser, so it reads its own.
- if (engine === 'muse') return parseMuseQuestionPane(capture)
+ // rows — both confuse the shared parser, so it reads its own. Its PERMISSION prompt is a different
+ // dialog entirely (`Would you like to allow this network access?` over `1. Yes, proceed (y)` rows under
+ // a `Press enter to confirm` footer, `__fixtures__/permission-muse.txt`) and that one the shared parser
+ // reads exactly, so it falls through rather than getting a parser of its own.
+ if (engine === 'muse') return parseMuseQuestionPane(capture) ?? parseQuestionPane(capture)
// Amp's is a permission prompt with unnumbered rows — nothing the shared parser can anchor on.
if (engine === 'amp') return parseAmpQuestionPane(capture)
// Kilo's is the same kind of prompt but laid out HORIZONTALLY, sharing its line with the key hints —
@@ -130,6 +148,13 @@ export function parseEngineQuestionPane(engine: AgentEngine, capture: string): P
// Hermes and OpenCode paint Claude's dialog inside a box; peel the border and the shared parser fits.
if (engine === 'hermes') return parseQuestionPane(unframe(capture))
if (engine === 'opencode') {
+ // OpenCode's PERMISSION prompt is the horizontal one kilo inherited from it — same `△ Permission
+ // required` title, same `⇆ select · enter confirm` footer, same unnumbered rows. Measured: the live
+ // capture in `permission-opencode.txt` parses through kilo's parser unchanged, so it is shared rather
+ // than copied. Tried FIRST because that dialog numbers nothing: the shared parser would still match
+ // its `enter confirm` footer and then walk up into whatever numbered rows the scrollback holds.
+ const permission = parseKiloQuestionPane(capture)
+ if (permission) return permission
const plain = unframe(capture)
return opencodeReview(plain) ?? parseQuestionPane(plain)
}
@@ -252,6 +277,149 @@ function parseDownward(lines: string[], tabBar: number): PaneView {
}
}
+// \u2500\u2500 permission prompts \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
+
+/**
+ * A permission prompt is a QUESTION whose options are the approval choices \u2014 the shape amp and kilo
+ * already ship (`engines/amp/askQuestion.ts`, `engines/kilo/askQuestion.ts`). It matters far more on a
+ * remote machine than a question does: the CLI attaches to an agent the USER started, under the user's
+ * own config and with no permission flag of ours (`engines/README.md`), so a blocking approval is the
+ * normal state of a pane, not an edge case. Unparsed, the turn simply sits at `Processing` until someone
+ * walks to the computer.
+ *
+ * Claude and Command Code draw it as a framed block ending in numbered rows, and it carries NONE of the
+ * three anchors `parseQuestionPane` knows. Captured live (`__fixtures__/permission-claude.txt`):
+ *
+ * \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
+ * Bash command \u2190 the header: what kind of approval this is
+ *
+ * curl -s https://api.coingecko.com/\u2026 \u2190 the argument, then a one-line description
+ * Fetch Bitcoin price from CoinGecko API
+ *
+ * This command requires approval
+ *
+ * Do you want to proceed?
+ * \u276f 1. Yes
+ * 2. Yes, and don\u2019t ask again for: curl *
+ * 3. No
+ *
+ * Esc to cancel \u00b7 Tab to amend \u00b7 ctrl+e to explain
+ *
+ * Command Code differs only in wording (`permission-commandcode.txt`): header `Execute Shell Command`,
+ * a sentence for the body, footer `\u2191/\u2193 navigate \u00b7 enter select \u00b7 ctrl+e explain`. Same frame, same rows \u2014
+ * which is why one parser covers both instead of two near-copies that would drift apart.
+ *
+ * **The prose is not the anchor.** Every engine words it differently and Claude alone writes at least
+ * three ("Do you want to proceed?", "Do you want to make this edit to README.md?", "Do you want to create
+ * \u2026?"). The ROWS are: an approval always offers a way to say yes and a way to say no. That pair is the
+ * signal, guarded by the dialog's own key hints so an ordinary numbered list in assistant output can never
+ * be read as a prompt.
+ */
+
+/** The first row of an approval, measured across claude, commandcode, codex, devin, grok, amp and kilo. */
+const APPROVE_RE = /^(yes|allow|approve|accept|proceed|run|continue)\b/i
+/** \u2026and the row that declines it. Never dropped \u2014 see the rule amp's parser states: a device user given
+ * three ways to say yes and none to say no cannot answer the prompt at all. */
+// `skip` is here because cursor's decline row is "Skip & tell the agent what to do instead" — an engine
+// whose only way to refuse says neither "no" nor "reject" would otherwise fail the yes/no guard and its
+// whole prompt would go unread.
+const REJECT_RE = /^(no|reject|deny|decline|cancel|skip|don'?t|stop)\b/i
+/** The key hints a permission dialog prints under its rows: claude `Esc to cancel \u00b7 Tab to amend`,
+ * Command Code `\u2191/\u2193 navigate \u00b7 enter select \u00b7 ctrl+e explain`. Proximity to the rows is what makes this
+ * a guard and not a search \u2014 it must sit within a few lines UNDER them. */
+const PERMISSION_FOOTER_RE = /\besc\b|enter\s+select|ctrl\+e/i
+/** The solid rule that opens the frame. Deliberately NOT the dashed one (`\u254c`) that brackets an edit diff,
+ * which sits BELOW the header and would cost the title. */
+const FRAME_RULE_RE = /^\s*[\u2500\u2501\u2550]{6,}\s*$/
+/** Any rule, solid or dashed \u2014 used to skip them while reading the frame's contents. */
+const ANY_RULE_RE = /^\s*[\u2500\u2501\u2550\u254c\u2504\u2508-]{6,}\s*$/
+/** The dialog's own question line, and Command Code's `Press [ctrl+e] \u2026` hint: both sit between the
+ * header and the rows, and neither says what is being approved. */
+const PERMISSION_PROSE_RE = /^((do|would) you\b|press \[)/i
+
+/** Keep a synthesised title inside the device's `text[200]` buffer, with the tail marked as cut. */
+function clipTitle(value: string): string {
+ return value.length <= 160 ? value : `${value.slice(0, 159)}\u2026`
+}
+
+/**
+ * What is being approved, as one line: `Approve <header>: <argument>`, the form amp's parser already
+ * produces so the two read alike on the device.
+ *
+ * The frame's opening rule is the only reliable top \u2014 the prose under it varies per engine AND per tool.
+ * Below the rule sit the header (`Bash command`, `Edit file`, `Execute Shell Command`) and then the
+ * argument: the command, the file, or the sentence naming it.
+ */
+function permissionTitle(lines: string[], start: number): string {
+ let top = -1
+ for (let i = start - 1; i >= 0 && start - i <= 25; i--) {
+ if (FRAME_RULE_RE.test(lines[i])) { top = i; break }
+ }
+ // No frame above the rows (codex draws none): the nearest text is the dialog's own question, which
+ // names the command outright. Better than inventing a header that is not on screen.
+ if (top < 0) {
+ for (let i = start - 1; i >= 0 && start - i <= 4; i--) {
+ const line = lines[i].trim()
+ if (line) return clipTitle(line)
+ }
+ return 'Approval required'
+ }
+ let header = ''
+ let arg = ''
+ for (let i = top + 1; i < start; i++) {
+ const line = lines[i].trim()
+ if (!line || ANY_RULE_RE.test(line)) continue
+ if (!header) { header = line; continue }
+ if (PERMISSION_PROSE_RE.test(line)) continue
+ arg = line
+ break
+ }
+ if (!header) return 'Approval required'
+ return clipTitle(arg ? `Approve ${header}: ${arg}` : `Approve ${header}`)
+}
+
+/**
+ * The permission prompt on screen, with the index of its first row so the caller can rank it against the
+ * other anchors.
+ *
+ * Only the LOWEST numbered block on the pane is considered, and it is rejected outright if it is not an
+ * approval. Digging further up would find an answered prompt in the scrollback and re-announce it \u2014 the
+ * live dialog is always the bottom-most thing on screen, so there is nothing below it to miss.
+ */
+export function parsePermissionPane(lines: string[]): { view: QuestionView; index: number } | null {
+ let end = -1
+ for (let i = lines.length - 1; i >= 0; i--) {
+ if (parseRow(lines[i])) { end = i; break }
+ }
+ if (end < 0) return null
+
+ // Walk up through CONTIGUOUS rows to the one numbered 1. Contiguity is the point: a permission dialog
+ // never interleaves prose with its options, while assistant output that happens to be numbered does.
+ const rows: QuestionRow[] = []
+ let start = -1
+ for (let i = end; i >= 0 && end - i < 12; i--) {
+ const row = parseRow(lines[i])
+ if (!row) break
+ rows.unshift(row)
+ if (row.number === '1') { start = i; break }
+ }
+ if (start < 0 || rows.length < 2) return null
+ if (!APPROVE_RE.test(rows[0].label) || !rows.some((row) => REJECT_RE.test(row.label))) return null
+
+ let hinted = false
+ for (let i = end + 1; i < lines.length && i - end <= 4; i++) {
+ if (PERMISSION_FOOTER_RE.test(lines[i])) { hinted = true; break }
+ }
+ if (!hinted) return null
+
+ // Single-select, and no free-text row: every option here is a choice to be TAPPED. Verified on live
+ // panes for claude, codex, devin and grok \u2014 one digit selects and submits, exactly as `rowKeys` assumes.
+ return {
+ view: { kind: 'question', question: permissionTitle(lines, start), rows, multi: false, typeRow: null },
+ index: start,
+ }
+}
+
export function parseQuestionPane(capture: string): PaneView {
const lines = stripAnsi(capture).replace(/\u00a0/g, ' ').split('\n')
// Each CLI words its own footer, and OpenCode rewords it PER SCREEN — `enter submit` on a single
@@ -261,6 +429,19 @@ export function parseQuestionPane(capture: string): PaneView {
// The review screen paints no footer and puts its rows BELOW the prompt, so it needs its own anchor.
// Whichever anchor is LOWER on screen is the live one (the other is scrollback from an earlier step).
const review = lines.findLastIndex((l) => /Ready to submit your answers/i.test(l))
+ // Command Code's review screen has neither Claude's "Ready to submit your answers" line nor a footer:
+ // it is a "Submit"/"Cancel" pair under a summary that is itself numbered. Anchor on that PAIR — the two
+ // rows adjacent, in that order — because the summary lines above are numbered too and reading them as
+ // options is how the device answered everything and then sat there, never submitting.
+ const submit = findSubmitPair(lines)
+ // A permission prompt is a FOURTH anchor and gets ranked exactly like the other three: whichever sits
+ // lowest on screen is the live dialog. That ordering is what keeps the two apart in both directions —
+ // codex and hermes draw an approval whose footer the question anchor also matches, and there the footer
+ // is BELOW the rows, so the question path (which reads a better title off the same block) still wins.
+ const permission = parsePermissionPane(lines)
+ if (permission && permission.index > footer && permission.index > review && permission.index > (submit?.index ?? -1)) {
+ return permission.view
+ }
if (review > footer) {
for (let i = review + 1; i < lines.length && i - review <= 10; i++) {
const row = parseRow(lines[i])
@@ -268,11 +449,6 @@ export function parseQuestionPane(capture: string): PaneView {
}
return null
}
- // Command Code's review screen has neither Claude's "Ready to submit your answers" line nor a footer:
- // it is a "Submit"/"Cancel" pair under a summary that is itself numbered. Anchor on that PAIR — the two
- // rows adjacent, in that order — because the summary lines above are numbered too and reading them as
- // options is how the device answered everything and then sat there, never submitting.
- const submit = findSubmitPair(lines)
if (submit && submit.index > footer) return { kind: 'review', submitRow: submit.row }
// Command Code paints the SAME dialog with no footer at all — the pane simply ends at the last option.
// Its tab bar is the only thing above the rows that is unmistakably part of the dialog, so anchor on
@@ -332,6 +508,10 @@ function rowKeys(engine: AgentEngine, row: QuestionRow): string[] {
if (engine === 'amp') return ampSelectionKeys(row)
// Kilo's rows sit side by side, so its walk is horizontal — see engines/kilo/askQuestion.ts.
if (engine === 'kilo') return kiloSelectionKeys(row)
+ // Same dialog, different engine: opencode numbers its ask dialog but not its permission prompt, so the
+ // ROW says how it is reached and a per-engine rule would break one of the two.
+ if (row.walk === 'right') return kiloSelectionKeys(row)
+ if (row.walk === 'down') return ampSelectionKeys(row)
return [row.number]
}
@@ -513,9 +693,13 @@ export interface QuestionWatcherDeps {
}
const POLL_MS = 1500
-// Amp is here for its PERMISSION prompt, not a question tool — it has none. That prompt is drawn only in
-// the pane and recorded nowhere, so polling the pane is the only way it is ever seen.
-const QUESTION_ENGINES = new Set<AgentEngine>(['claude', 'commandcode', 'devin', 'hermes', 'opencode', 'muse', 'amp', 'kilo', 'grok'])
+// Amp and codex are here for their PERMISSION prompt, not a question tool — neither has one. That prompt
+// is drawn only in the pane and recorded nowhere, so polling the pane is the only way it is ever seen.
+// Codex needs no parser of its own: it draws numbered rows under a `Press enter to confirm or esc to
+// cancel` footer, which is the shared parser's anchor exactly (`__fixtures__/permission-codex.txt`), and
+// the question it lands on is the command itself. Membership in this set is what starts the poll, so an
+// engine belongs here only once something can actually read its pane.
+const QUESTION_ENGINES = new Set<AgentEngine>(['claude', 'commandcode', 'codex', 'cursor', 'devin', 'hermes', 'opencode', 'muse', 'amp', 'kilo', 'grok'])
/** Does this engine ever paint a question dialog? Callers use it to decide whether to watch its pane. */
export function pollsQuestions(engine: AgentEngine): boolean {