shellpuppet 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (232) hide show
  1. package/README.md +63 -16
  2. package/dist/agents/agy/index.d.ts +2 -0
  3. package/dist/agents/agy/index.js +11 -0
  4. package/dist/agents/agy/index.js.map +1 -0
  5. package/dist/agents/agy/nudge.d.ts +2 -0
  6. package/dist/agents/agy/nudge.js +29 -0
  7. package/dist/agents/agy/nudge.js.map +1 -0
  8. package/dist/agents/agy/reading.d.ts +2 -0
  9. package/dist/agents/agy/reading.js +28 -0
  10. package/dist/agents/agy/reading.js.map +1 -0
  11. package/dist/agents/barNudge.d.ts +9 -0
  12. package/dist/agents/barNudge.js +21 -0
  13. package/dist/agents/barNudge.js.map +1 -0
  14. package/dist/agents/claude/index.d.ts +2 -0
  15. package/dist/agents/claude/index.js +31 -0
  16. package/dist/agents/claude/index.js.map +1 -0
  17. package/dist/agents/claude/nudge.d.ts +2 -0
  18. package/dist/agents/claude/nudge.js +38 -0
  19. package/dist/agents/claude/nudge.js.map +1 -0
  20. package/dist/agents/claude/prompts.d.ts +9 -0
  21. package/dist/agents/claude/prompts.js +16 -0
  22. package/dist/agents/claude/prompts.js.map +1 -0
  23. package/dist/agents/claude/reading.d.ts +2 -0
  24. package/dist/agents/claude/reading.js +25 -0
  25. package/dist/agents/claude/reading.js.map +1 -0
  26. package/dist/agents/codex/index.d.ts +2 -0
  27. package/dist/agents/codex/index.js +28 -0
  28. package/dist/agents/codex/index.js.map +1 -0
  29. package/dist/agents/codex/nudge.d.ts +2 -0
  30. package/dist/agents/codex/nudge.js +35 -0
  31. package/dist/agents/codex/nudge.js.map +1 -0
  32. package/dist/agents/codex/prompts.d.ts +9 -0
  33. package/dist/agents/codex/prompts.js +14 -0
  34. package/dist/agents/codex/prompts.js.map +1 -0
  35. package/dist/agents/codex/reading.d.ts +2 -0
  36. package/dist/agents/codex/reading.js +22 -0
  37. package/dist/agents/codex/reading.js.map +1 -0
  38. package/dist/agents/generic/index.d.ts +3 -0
  39. package/dist/agents/generic/index.js +9 -0
  40. package/dist/agents/generic/index.js.map +1 -0
  41. package/dist/agents/generic/prompts.d.ts +2 -0
  42. package/dist/agents/generic/prompts.js +10 -0
  43. package/dist/agents/generic/prompts.js.map +1 -0
  44. package/dist/agents/grok/actionBox.d.ts +13 -0
  45. package/dist/agents/grok/actionBox.js +127 -0
  46. package/dist/agents/grok/actionBox.js.map +1 -0
  47. package/dist/agents/grok/index.d.ts +2 -0
  48. package/dist/agents/grok/index.js +20 -0
  49. package/dist/agents/grok/index.js.map +1 -0
  50. package/dist/agents/grok/nudge.d.ts +2 -0
  51. package/dist/agents/grok/nudge.js +76 -0
  52. package/dist/agents/grok/nudge.js.map +1 -0
  53. package/dist/agents/grok/prompts.d.ts +4 -0
  54. package/dist/agents/grok/prompts.js +89 -0
  55. package/dist/agents/grok/prompts.js.map +1 -0
  56. package/dist/agents/grok/reading.d.ts +2 -0
  57. package/dist/agents/grok/reading.js +49 -0
  58. package/dist/agents/grok/reading.js.map +1 -0
  59. package/dist/agents/grok/readingRules.d.ts +2 -0
  60. package/dist/agents/grok/readingRules.js +44 -0
  61. package/dist/agents/grok/readingRules.js.map +1 -0
  62. package/dist/agents/index.d.ts +28 -0
  63. package/dist/agents/index.js +46 -0
  64. package/dist/agents/index.js.map +1 -0
  65. package/dist/agents/input.d.ts +2 -0
  66. package/dist/agents/input.js +9 -0
  67. package/dist/agents/input.js.map +1 -0
  68. package/dist/agents/mimo/index.d.ts +2 -0
  69. package/dist/agents/mimo/index.js +13 -0
  70. package/dist/agents/mimo/index.js.map +1 -0
  71. package/dist/agents/mimo/nudge.d.ts +3 -0
  72. package/dist/agents/mimo/nudge.js +59 -0
  73. package/dist/agents/mimo/nudge.js.map +1 -0
  74. package/dist/agents/mimo/prompts.d.ts +2 -0
  75. package/dist/agents/mimo/prompts.js +40 -0
  76. package/dist/agents/mimo/prompts.js.map +1 -0
  77. package/dist/agents/mimo/reading.d.ts +2 -0
  78. package/dist/agents/mimo/reading.js +31 -0
  79. package/dist/agents/mimo/reading.js.map +1 -0
  80. package/dist/agents/mimo/readingRules.d.ts +2 -0
  81. package/dist/agents/mimo/readingRules.js +79 -0
  82. package/dist/agents/mimo/readingRules.js.map +1 -0
  83. package/dist/agents/mimo/stalls.d.ts +2 -0
  84. package/dist/agents/mimo/stalls.js +81 -0
  85. package/dist/agents/mimo/stalls.js.map +1 -0
  86. package/dist/agents/muse/index.d.ts +2 -0
  87. package/dist/agents/muse/index.js +20 -0
  88. package/dist/agents/muse/index.js.map +1 -0
  89. package/dist/agents/muse/input.d.ts +3 -0
  90. package/dist/agents/muse/input.js +7 -0
  91. package/dist/agents/muse/input.js.map +1 -0
  92. package/dist/agents/muse/nudge.d.ts +2 -0
  93. package/dist/agents/muse/nudge.js +33 -0
  94. package/dist/agents/muse/nudge.js.map +1 -0
  95. package/dist/agents/muse/prompts.d.ts +14 -0
  96. package/dist/agents/muse/prompts.js +132 -0
  97. package/dist/agents/muse/prompts.js.map +1 -0
  98. package/dist/agents/muse/reading.d.ts +2 -0
  99. package/dist/agents/muse/reading.js +33 -0
  100. package/dist/agents/muse/reading.js.map +1 -0
  101. package/dist/agents/muse/readingRules.d.ts +2 -0
  102. package/dist/agents/muse/readingRules.js +49 -0
  103. package/dist/agents/muse/readingRules.js.map +1 -0
  104. package/dist/agents/nudgeReading.d.ts +74 -0
  105. package/dist/agents/nudgeReading.js +262 -0
  106. package/dist/agents/nudgeReading.js.map +1 -0
  107. package/dist/agents/opencode/index.d.ts +2 -0
  108. package/dist/agents/opencode/index.js +21 -0
  109. package/dist/agents/opencode/index.js.map +1 -0
  110. package/dist/agents/opencode/nudge.d.ts +6 -0
  111. package/dist/agents/opencode/nudge.js +187 -0
  112. package/dist/agents/opencode/nudge.js.map +1 -0
  113. package/dist/agents/opencode/prompts.d.ts +6 -0
  114. package/dist/agents/opencode/prompts.js +198 -0
  115. package/dist/agents/opencode/prompts.js.map +1 -0
  116. package/dist/agents/opencode/reading.d.ts +2 -0
  117. package/dist/agents/opencode/reading.js +29 -0
  118. package/dist/agents/opencode/reading.js.map +1 -0
  119. package/dist/agents/opencode/stalls.d.ts +3 -0
  120. package/dist/agents/opencode/stalls.js +14 -0
  121. package/dist/agents/opencode/stalls.js.map +1 -0
  122. package/dist/agents/qoder/index.d.ts +2 -0
  123. package/dist/agents/qoder/index.js +12 -0
  124. package/dist/agents/qoder/index.js.map +1 -0
  125. package/dist/agents/qoder/nudge.d.ts +2 -0
  126. package/dist/agents/qoder/nudge.js +16 -0
  127. package/dist/agents/qoder/nudge.js.map +1 -0
  128. package/dist/agents/qoder/prompts.d.ts +2 -0
  129. package/dist/agents/qoder/prompts.js +6 -0
  130. package/dist/agents/qoder/prompts.js.map +1 -0
  131. package/dist/agents/qoder/reading.d.ts +2 -0
  132. package/dist/agents/qoder/reading.js +41 -0
  133. package/dist/agents/qoder/reading.js.map +1 -0
  134. package/dist/agents/types.d.ts +187 -0
  135. package/dist/agents/types.js +2 -0
  136. package/dist/agents/types.js.map +1 -0
  137. package/dist/cli/index.js +185 -19
  138. package/dist/cli/index.js.map +1 -1
  139. package/dist/client/http.d.ts +5 -1
  140. package/dist/client/http.js +39 -9
  141. package/dist/client/http.js.map +1 -1
  142. package/dist/core/dialogs.d.ts +2 -4
  143. package/dist/core/dialogs.js +6 -12
  144. package/dist/core/dialogs.js.map +1 -1
  145. package/dist/core/mailbox.d.ts +222 -0
  146. package/dist/core/mailbox.js +545 -0
  147. package/dist/core/mailbox.js.map +1 -0
  148. package/dist/core/manager.d.ts +3 -0
  149. package/dist/core/manager.js +37 -2
  150. package/dist/core/manager.js.map +1 -1
  151. package/dist/core/messageText.d.ts +2 -0
  152. package/dist/core/messageText.js +6 -0
  153. package/dist/core/messageText.js.map +1 -0
  154. package/dist/core/nudge.d.ts +37 -0
  155. package/dist/core/nudge.js +57 -0
  156. package/dist/core/nudge.js.map +1 -0
  157. package/dist/core/promptDetector.d.ts +14 -12
  158. package/dist/core/promptDetector.js +113 -363
  159. package/dist/core/promptDetector.js.map +1 -1
  160. package/dist/core/promptText.d.ts +1 -0
  161. package/dist/core/promptText.js +4 -0
  162. package/dist/core/promptText.js.map +1 -0
  163. package/dist/core/readiness.d.ts +14 -0
  164. package/dist/core/readiness.js +95 -0
  165. package/dist/core/readiness.js.map +1 -0
  166. package/dist/core/reasoning.d.ts +68 -7
  167. package/dist/core/reasoning.js +572 -325
  168. package/dist/core/reasoning.js.map +1 -1
  169. package/dist/core/renderer.d.ts +63 -3
  170. package/dist/core/renderer.js +368 -42
  171. package/dist/core/renderer.js.map +1 -1
  172. package/dist/core/selection.d.ts +1 -1
  173. package/dist/core/selection.js +3 -3
  174. package/dist/core/selection.js.map +1 -1
  175. package/dist/core/session.d.ts +165 -13
  176. package/dist/core/session.js +998 -84
  177. package/dist/core/session.js.map +1 -1
  178. package/dist/core/types.d.ts +60 -4
  179. package/dist/core/types.js +41 -0
  180. package/dist/core/types.js.map +1 -1
  181. package/dist/core/waiter.d.ts +9 -2
  182. package/dist/core/waiter.js +35 -10
  183. package/dist/core/waiter.js.map +1 -1
  184. package/dist/daemon/audit.d.ts +1 -1
  185. package/dist/daemon/audit.js +2 -1
  186. package/dist/daemon/audit.js.map +1 -1
  187. package/dist/daemon/config.d.ts +42 -0
  188. package/dist/daemon/config.js +159 -4
  189. package/dist/daemon/config.js.map +1 -1
  190. package/dist/daemon/folderPicker.js +21 -2
  191. package/dist/daemon/folderPicker.js.map +1 -1
  192. package/dist/daemon/homeOwner.d.ts +15 -0
  193. package/dist/daemon/homeOwner.js +106 -0
  194. package/dist/daemon/homeOwner.js.map +1 -0
  195. package/dist/daemon/index.js +10 -6
  196. package/dist/daemon/index.js.map +1 -1
  197. package/dist/daemon/launchProfiles.d.ts +5 -0
  198. package/dist/daemon/launchProfiles.js +42 -40
  199. package/dist/daemon/launchProfiles.js.map +1 -1
  200. package/dist/daemon/nudgeScheduler.d.ts +21 -0
  201. package/dist/daemon/nudgeScheduler.js +61 -0
  202. package/dist/daemon/nudgeScheduler.js.map +1 -0
  203. package/dist/daemon/paths.d.ts +20 -16
  204. package/dist/daemon/paths.js +137 -49
  205. package/dist/daemon/paths.js.map +1 -1
  206. package/dist/daemon/restartSource.d.ts +7 -0
  207. package/dist/daemon/restartSource.js +89 -0
  208. package/dist/daemon/restartSource.js.map +1 -0
  209. package/dist/daemon/screenshot.d.ts +4 -1
  210. package/dist/daemon/screenshot.js +45 -7
  211. package/dist/daemon/screenshot.js.map +1 -1
  212. package/dist/daemon/server.d.ts +70 -13
  213. package/dist/daemon/server.js +1596 -294
  214. package/dist/daemon/server.js.map +1 -1
  215. package/dist/daemon/sessionFeed.js +4 -1
  216. package/dist/daemon/sessionFeed.js.map +1 -1
  217. package/dist/mcp/config.js +2 -1
  218. package/dist/mcp/config.js.map +1 -1
  219. package/dist/mcp/index.js +12 -2
  220. package/dist/mcp/index.js.map +1 -1
  221. package/dist/mcp/tools.d.ts +21 -1
  222. package/dist/mcp/tools.js +213 -28
  223. package/dist/mcp/tools.js.map +1 -1
  224. package/dist/viewer/dashboard-folders.js +7 -1
  225. package/dist/viewer/dashboard-layout.js +6 -52
  226. package/dist/viewer/dashboard.css +20 -4
  227. package/dist/viewer/dashboard.html +12 -3
  228. package/dist/viewer/dashboard.js +549 -382
  229. package/dist/viewer/pane.js +744 -136
  230. package/dist/viewer/viewer.css +1 -1
  231. package/dist/viewer/viewer.js +3 -1
  232. package/package.json +1 -1
@@ -21,12 +21,14 @@
21
21
  * letter lists, and the steps `@clack/prompts` draws for the scaffolding
22
22
  * wizards of create-vite, `sv create` and others: a select, a multi-select or
23
23
  * a confirm under a `◆` headline, or `▲` while the step shows a validation
24
- * error. MiMo Code's folder-trust question is a clack select too. Two rules
24
+ * error. MiMo Code's folder-trust question is a clack select too. Several rules
25
25
  * keep out FALSE positives: a numbered findings list an agent printed above
26
26
  * its composer, under a line that happens to end in a question mark; and a
27
27
  * message Claude Code echoes into its transcript or holds in its composer,
28
28
  * whose `❯` and aligned lines look like a pointer chooser under a question
29
- * from an earlier message.
29
+ * from an earlier message. Qoder's composer, identified by its surrounding
30
+ * chrome, is excluded from chooser blocks, and keyboard hints cannot supply
31
+ * their question.
30
32
  *
31
33
  * A permission dialog drawn with its choices as one row of buttons
32
34
  * (OpenCode, MiMo Code) is recognised by its signature (`dialogs.ts`),
@@ -34,43 +36,22 @@
34
36
  * its fixed controls and custom-answer choice here.
35
37
  */
36
38
  import { dialogPrompt } from './dialogs.js';
37
- /** A plain Muse heading can precede the moment its keys become active. */
38
- export const MUSE_MENU_SETTLE_MS = 1_500;
39
- /**
40
- * A numbered option row, in either of the two shapes real CLIs draw. Dot
41
- * form: `❯ 1. Allow once` / `› 1. Yes, proceed (y)` / `>1. Sign in
42
- * with ChatGPT` (Codex draws the sign-in marker TIGHT against the digit) /
43
- * `2. Don't trust and exit`. Radio form: `│ 1 (○) Yes, and don't ask
44
- * again` / `│ 2 (•) Yes, proceed` (Grok: box border, no dot, the radio IS
45
- * the selection state). The capture group is the option number, used to keep
46
- * wrap-interleaved rows in one block.
47
- */
48
- const OPTION_ROW = /^\s*(?:│\s*)?(?:[❯›]\s*|>\s*)?(\d+)(?:\.\s+|\s+\([○•●]\)\s+)\S/;
39
+ import { AGENT_MODULES, moduleFor, promptShapesFor, MuseMenuSettler } from '../agents/index.js';
40
+ import { reading as qoderReading } from '../agents/qoder/reading.js';
41
+ import { normalise } from './promptText.js';
42
+ export { MUSE_MENU_SETTLE_MS } from '../agents/index.js';
43
+ /** Compatibility entry point; session readers obtain their settler from the module. */
44
+ export class MusePromptSettler extends MuseMenuSettler {
45
+ detect(screen, now = Date.now(), styled) {
46
+ return this.settle(detectPrompt(screen), screen, now, styled);
47
+ }
48
+ }
49
49
  /**
50
50
  * A letter-keyed row: `[Y] Yes`, `(a) Apply the change`,
51
51
  * optionally pointed. The capture is the key, used to keep a block to rows
52
52
  * with DISTINCT keys, because a markdown checkbox list repeats `[x]`.
53
53
  */
54
54
  const LETTER_ROW = /^\s*(?:│\s*)?(?:[❯›]\s*|>\s*)?[[(]([a-z])[\])]\s+\S/i;
55
- /**
56
- * An option with its key after it, as Grok's folder-trust question draws
57
- * them: `Yes, proceed y`. The label, two or more spaces, then a single
58
- * letter ending the line. Captures indent, label and key.
59
- */
60
- const KEY_HINT_ROW = /^(\s*)(\S.*?)\s{2,}([a-z])$/i;
61
- /**
62
- * A pointer against plain text: `❯ npm`, `> minimal`. It is the
63
- * inquirer.js shape, and Claude Code's own folder-trust prompt. Captures
64
- * indent, pointer and text. `›` is deliberately absent: Codex draws it on
65
- * its composer line, and every `›` chooser seen so far numbers its rows.
66
- */
67
- const POINTER_ROW = /^(\s*)([❯>])\s+(\S.*)$/;
68
- /**
69
- * Focus markers TUIs draw on the selected option: `❯`/`›` anywhere,
70
- * line-leading `>` only before a numbered or letter-keyed row (tight or
71
- * spaced) or a FILLED radio `(•)`/`(●)`, Grok's selected-row marker.
72
- */
73
- const MARKER_LINE = /[❯›]|^\s*(?:│\s*)?>\s*(?:\d+\.|[[(][a-z][\])])|\([•●]\)/i;
74
55
  /**
75
56
  * A step headline as `@clack/prompts` draws it: the step glyph, two spaces,
76
57
  * the message. Only a step still waiting matches: `◆`, or `▲` while it shows
@@ -81,8 +62,6 @@ const MARKER_LINE = /[❯›]|^\s*(?:│\s*)?>\s*(?:\d+\.|[[(][a-z][\])])|\([•
81
62
  * folder-trust question in a message it logs above such a step.
82
63
  */
83
64
  const CLACK_HEADLINE = /^[◆▲](?: {2}(\S.*))?$/;
84
- /** The first line of a message clack logs: `● Accessing workspace:`. */
85
- const CLACK_LOG = /^[●◆◇▲■] {2}(\S.*)$/;
86
65
  /**
87
66
  * A choice row in the `│` gutter clack draws down the left of a step. A
88
67
  * select draws radios (`●` for the selected option, `○` for the rest), a
@@ -113,32 +92,13 @@ const YES_NO_TAIL = /(\(y\/n\)|\[y\/n\]|\(yes\/no\)|\(y\)es\s*[/,|]?\s*\(n\)o|\[
113
92
  * counts (see `isYesNo`): `(a/b)` in prose is a ratio, not a question.
114
93
  */
115
94
  const LETTER_LIST_TAIL = /[[(]\s*([a-z?](?:\s*[/,|]\s*[a-z?])+)\s*[\])]\s*[?:]?\s*$/i;
116
- /**
117
- * `Press enter to continue` / `…to confirm or esc to cancel`: the footer
118
- * both Codex prompt classes draw, and a wait state in its own right on the
119
- * onboarding screens that have no option list at all. `Enter to confirm ·
120
- * Esc to cancel`, without "press", is Claude Code's.
121
- */
122
- const PRESS_ENTER = /(?:press\s+)?\benter to (confirm|continue|select)/i;
123
- /**
124
- * Lines that mean the program is WORKING, not waiting. Spinner verbs with
125
- * their ellipsis only. A bare `esc to cancel` must NOT count as busy, since
126
- * Codex's `Press enter to confirm or esc to cancel` footer sits BELOW the
127
- * option block and would veto the very prompt it belongs to. `Waiting for
128
- * response…` is Grok's response spinner: it appears BELOW a just-answered
129
- * option block while the block is still in the tail, and without the veto
130
- * the stale block would go on alerting until it scrolled away. The ellipsis
131
- * is REQUIRED, matching the verbs: plain prose that happens to say
132
- * "waiting for response" must not veto a live prompt (a false negative here
133
- * is an unalerted stall, the costly direction). Claude Code's spinner is busy
134
- * whatever verb it shows: a spinner glyph at the start of the line, the verb
135
- * or the task in hand, the ellipsis and often the time so far
136
- * (`✻ Calculating… (14s · thinking)`). The line it leaves when a turn ends
137
- * has no ellipsis (`✻ Cooked for 19m 12s · done 20:31`).
138
- */
139
- const BUSY_LINE = /(generating|thinking|running|working|waiting for response)(\.{3}|…)|^\s*[·✢✳✶✻✽*] [^…]+…(?: \(.*\))?\s*$/i;
140
95
  /** Horizontal rules and box-drawing rows (U+2500 to U+257F) carry no text content. */
141
96
  const RULE_LINE = /^[\s─-╿-]*$/;
97
+ /** A keyboard hint is chrome, even when it sits directly below a question. */
98
+ const KEY_HELP_HINT = /^\s*(?:press\s+)?\?\s+(?:for|to show)\s+(?:shortcuts|help|keybindings)\s*$/i;
99
+ const QODER_COMPOSER = new RegExp(qoderReading.composer.text);
100
+ const QODER_MODE = /\bAuto Mode\b.*\bShift\+Tab\b|\bShift\+Tab to Accept Edits\b/i;
101
+ const QODER_STATUS = /\bModel\s*·\s*ctx\b/i;
142
102
  /**
143
103
  * How far up from the bottom of the screen a live prompt can plausibly sit.
144
104
  * Codex's wrapped option text plus footers span a dozen lines on their own,
@@ -154,39 +114,11 @@ const TAIL_WINDOW = 20;
154
114
  * misattribute ordinary transcript text.
155
115
  */
156
116
  const QUESTION_SEARCH_BUDGET = 8;
157
- /**
158
- * Grok's permission question row: two spaces, the bar, two spaces, `>`,
159
- * then a space. With or without a question mark, that row is the question
160
- * the box is asking. The composer is `│ >` with one space and does not match.
161
- */
162
- const GROK_BOX_QUESTION = /^ {2}│ {2}> /;
163
- /** Bar text in that same box: two spaces, the bar, two spaces, a word. */
164
- const GROK_BAR_TEXT = /^ {2}│ {2}\S/;
165
- /** The bare bar row that closes a command off from the reasoning above it. */
166
- const GROK_BARE_BAR = /^ {2}│\s*$/;
167
- /**
168
- * A line that starts Grok's reasoning. The command walk does not see the
169
- * signature. The thinking header is itself bar text, so the walk would
170
- * otherwise take it; the spinner is not bar text, and a run below it is
171
- * still closed off by it.
172
- */
173
- const GROK_REASONING_START = /^ {2}│ {2}♦ Thinking|^ {3}[|/\\-] \S/;
174
- /** A `$` on a command row, or a `:` continuation of one. */
175
- const GROK_COMMAND_MARK = /\$|^ {2}│ {2}:/;
176
- /** The fixed controls at the foot of OpenCode and MiMo Code's question menu. */
177
- const QUESTION_MENU_FOOTER = /^ *┃ {2}↑↓ select {2}enter submit {2}esc dismiss\s*$/u;
178
- const QUESTION_MENU_OPTION = /^ *┃ {2}([1-4])\. (\S.*)$/u;
179
- const QUESTION_MENU_DESCRIPTION = /^ *┃ {5}\S/u;
180
- const QUESTION_MENU_TEXT = /^ *┃ {2}(\S.*)$/u;
181
- const QUESTION_MENU_BAR = /^ *┃\s*$/u;
182
117
  function contentLines(raw) {
183
118
  return raw
184
119
  .map((text, index) => ({ text: text.trimEnd(), index }))
185
120
  .filter((line) => line.text.trim() !== '');
186
121
  }
187
- function normalise(text) {
188
- return text.replace(/\s+/g, ' ').trim();
189
- }
190
122
  function stripMarkers(text) {
191
123
  return normalise(text.replace(/^[\s│❯›>]+/, ''));
192
124
  }
@@ -205,233 +137,97 @@ function isYesNo(text) {
205
137
  * Returns null when the screen looks busy or shows no prompt shape.
206
138
  */
207
139
  export const SELECTED_OPTION_MARKER = '⟦SP:selected⟧ ';
208
- export function detectPrompt(screen) {
140
+ export function detectPrompt(screen, agent = 'generic', viewportRows, styled) {
209
141
  const original = screen.split('\n');
210
142
  const plain = original.map((line) => line.replace(/^⟦SP:selected⟧ /, ''));
211
- const prompt = detectPlainPrompt(plain.join('\n'));
143
+ const prompt = detectPlainPrompt(plain.join('\n'), agent, viewportRows, styled);
212
144
  if (prompt?.optionRows === undefined)
213
145
  return prompt;
214
146
  const selected = prompt.optionRows.flatMap((row, index) => original[row]?.startsWith(SELECTED_OPTION_MARKER) ? [index] : []);
215
147
  return selected.length === 1 ? { ...prompt, selectedOption: selected[0] } : prompt;
216
148
  }
217
- function detectPlainPrompt(screen) {
149
+ function detectPlainPrompt(screen, agent, viewportRows, styled) {
218
150
  const raw = screen.split('\n');
219
151
  const lines = contentLines(raw);
220
152
  if (lines.length === 0)
221
153
  return null;
222
154
  const tail = lines.slice(-TAIL_WINDOW);
223
- const muse = musePrompt(raw, tail);
224
- if (muse !== null)
225
- return muse;
226
- const questionMenu = openCodeQuestionMenu(raw, lines);
227
- if (questionMenu !== null)
228
- return questionMenu;
155
+ const composerSpans = qoderComposerSpans(raw);
156
+ const shapes = promptShapesFor(agent);
157
+ const rows = shapes.filter((shape) => shape.kind === 'rows');
158
+ const busy = (text) => rows.some(shape => shape.busy?.test(text));
159
+ for (const shape of shapes) {
160
+ if (shape.kind !== 'menu')
161
+ continue;
162
+ const prompt = shape.detect(raw, lines, tail, busy, viewportRows, styled);
163
+ if (prompt !== null)
164
+ return prompt;
165
+ }
229
166
  // A dialog a program draws on its own screen, recognised by its signature
230
167
  // (`dialogs.ts`): the most specific test there is, so it goes first.
231
- const dialog = dialogPrompt(raw);
168
+ const dialog = dialogPrompt(raw, undefined, undefined, agent);
232
169
  if (dialog !== null)
233
170
  return dialog;
234
171
  // A clack step draws its own frame, and the frame alone says whether the
235
172
  // step is waiting.
236
- const clack = clackPrompt(tail, raw);
173
+ const clack = clackPrompt(tail, raw, rows, busy);
237
174
  if (clack !== null)
238
175
  return clack;
239
176
  // Four chooser shapes, most specific first. A block that is found but
240
177
  // not LIVE (a numbered list in the transcript, say) does not end the
241
178
  // search: the shapes below it, and the single-line tails after, may be.
179
+ // Builders never see Qoder's composer rows, so a draft drawn like a menu
180
+ // cannot displace a real menu above it as the latest block.
181
+ const inComposer = (index) => composerSpans.some(([start, end]) => index >= start && index <= end);
182
+ const chooserTail = composerSpans.length === 0 ? tail : tail.filter((line) => !inComposer(line.index));
242
183
  const blocks = [
243
- numberedBlock(tail),
244
- letterBlock(tail),
245
- keyHintBlock(tail),
246
- pointerBlock(tail, raw),
184
+ numberedBlock(chooserTail, rows),
185
+ letterBlock(chooserTail),
186
+ keyHintBlock(chooserTail, rows),
187
+ pointerBlock(chooserTail, raw, rows),
247
188
  ];
248
189
  for (const block of blocks) {
249
190
  if (block === null)
250
191
  continue;
251
- const prompt = livePrompt(block, tail, raw);
192
+ if (block.rows.some(({ line }) => inComposer(line.index)))
193
+ continue;
194
+ const prompt = livePrompt(block, tail, raw, rows, busy);
252
195
  if (prompt !== null)
253
196
  return prompt;
254
197
  }
255
198
  // No live option block: a y/n tail on the LAST content line is still a prompt.
256
199
  const last = lines[lines.length - 1];
257
- if (isYesNo(last.text) && !BUSY_LINE.test(last.text)) {
200
+ if (isYesNo(last.text) && !busy(last.text)) {
258
201
  const question = normalise(last.text);
259
202
  return { question, options: [], signature: question, rows: [last.index, last.index], basis: 'frame' };
260
203
  }
261
204
  // A bare press-enter wait (the Codex onboarding screens): the last content
262
205
  // line asks for enter and nothing below it can contradict that.
263
- if (PRESS_ENTER.test(last.text)) {
206
+ if (rows.some(shape => shape.footer?.test(last.text))) {
264
207
  const question = normalise(last.text);
265
208
  return { question, options: [], signature: question, rows: [last.index, last.index], basis: 'frame' };
266
209
  }
267
210
  return null;
268
211
  }
269
- function museQuestion(text) {
270
- return /^Would .+ like to run the following command\?$/.test(text) || text === 'Do you trust this workspace?';
271
- }
272
- /** Muse's approval and trust menus use ⟩ with numbered rows and no composer. */
273
- function musePrompt(raw, tail) {
274
- const selected = [...tail].reverse().find((line) => /^⟩ [1-3](?:\. | {2})/.test(line.text));
275
- if (selected === undefined)
276
- return null;
277
- const marker = /^⟩ ([1-3])(\. | {2})/.exec(selected.text);
278
- if (marker === null)
279
- return null;
280
- const selectedOption = Number(marker[1]) - 1;
281
- const approval = marker[2] === '. ';
282
- const first = selected.index - selectedOption;
283
- // Muse omits the workspace-wide choice for script blocks and some commands.
284
- // The second row identifies that form even when the heading stays plain.
285
- const twoOptionApproval = approval && /^(?:⟩ | {2})2\. Abort the entire command\s*\(esc\)/.test(raw[first + 1] ?? '');
286
- const count = approval && !twoOptionApproval ? 3 : 2;
287
- if (selectedOption >= count)
288
- return null;
289
- const options = [];
290
- const optionRows = [];
291
- for (let offset = 0; offset < count; offset++) {
292
- const row = first + offset;
293
- const text = (raw[row] ?? '').trimEnd();
294
- const prefix = `${offset === selectedOption ? '⟩ ' : ' '}${String(offset + 1)}${approval ? '. ' : ' '}`;
295
- if (!text.startsWith(prefix) || text.slice(prefix.length).trim() === '')
296
- return null;
297
- options.push(normalise(text.replace(/^⟩ /, '')));
298
- optionRows.push(row);
299
- }
300
- // Walk the visible menu itself: a long wrapped command can put the heading
301
- // beyond the tail and more than ten rows above the first choice. The first
302
- // transcript or composer boundary prevents borrowing an answered question.
303
- let question;
304
- for (let index = first - 1; index >= 0 && first - index <= 60; index--) {
305
- const text = (raw[index] ?? '').trimEnd();
306
- if (museQuestion(text)) {
307
- question = { text, index };
308
- break;
309
- }
310
- if (/^\s*(?:[◆◇◈]|❯(?:\s|$)|[─━═]{2,})/u.test(text))
311
- break;
312
- }
313
- if (question === undefined)
314
- return null;
315
- if (approval !== question.text.startsWith('Would '))
316
- return null;
317
- // A quoted menu inside an answer has no new Muse input border before it.
318
- const before = raw.slice(0, question.index);
319
- let border = -1;
320
- for (let index = before.length - 1; index >= 0; index--) {
321
- if (/^\s*── .*Voice input/.test(before[index])) {
322
- border = index;
323
- break;
324
- }
325
- }
326
- if (before.slice(border + 1).some((line) => /^\s*◆/.test(line)))
327
- return null;
328
- const stage = approval ? raw.slice(question.index, first).find((line) => /^ {2}Stage \d+\/\d+$/.test(line.trimEnd())) : undefined;
329
- // Only this menu's hint and footer, blank rows and Muse's status footer
330
- // belong below its options. Other output means the menu is historical.
331
- if (raw.slice(optionRows[optionRows.length - 1] + 1).some((line) => {
332
- const text = line.trimEnd();
333
- return text.trim() !== '' && !/^Change approval defaults in \/permissions$/.test(text) &&
334
- (approval || !/^Use Up\/Down or 1\/2, then Enter\. Esc quits\.$/.test(text)) &&
335
- !/^\s*[─━═]{2,}$/.test(text) &&
336
- !/^ {2}\S[^·]* · [^·]+ · [^·]+ · Launch overrides$/u.test(text);
337
- }))
338
- return null;
339
- return {
340
- question: question.text,
341
- options,
342
- selectedOption,
343
- optionRows,
344
- signature: [question.text, stage ?? '', ...options].join(' | '),
345
- rows: [question.index, optionRows[optionRows.length - 1]],
346
- basis: 'marker',
347
- };
348
- }
349
- /** Tracks the visible menu block, independently of activity above it. */
350
- export class MusePromptSettler {
351
- menu = null;
352
- since = 0;
353
- detect(screen, now = Date.now(), styled) {
354
- const prompt = detectPrompt(screen);
355
- if (prompt === null) {
356
- this.menu = null;
357
- return null;
358
- }
359
- if (!prompt.question.startsWith('Would ') || !prompt.signature.includes('Stage ') ||
360
- prompt.optionRows === undefined) {
361
- this.menu = null;
362
- return prompt;
363
- }
364
- const atRow = styled?.[prompt.rows[0]];
365
- const heading = atRow?.text === prompt.question ? atRow :
366
- [...(styled ?? [])].reverse().find((line) => line.text === prompt.question);
367
- const bold = heading !== undefined && heading.spans.some((span) => span.bold && span.to - span.from >= prompt.question.length / 2);
368
- if (bold) {
369
- this.menu = null;
370
- return prompt;
371
- }
372
- // The heading to the last option row: a status footer below may tick.
373
- const block = screen.split('\n').slice(prompt.rows[0], prompt.rows[1] + 1).join('\n');
374
- if (block !== this.menu) {
375
- this.menu = block;
376
- this.since = now;
377
- }
378
- return now - this.since >= MUSE_MENU_SETTLE_MS ? prompt : null;
212
+ /** Qoder's input starts with ` > `; wrapped rows keep the text in column 4.
213
+ * Its mode line above or model status below distinguishes this input from a
214
+ * chooser with the same pointer. A key-help hint alone is shared with other
215
+ * choosers, so it cannot establish the composer frame.
216
+ */
217
+ function qoderComposerSpans(raw) {
218
+ const spans = [];
219
+ for (let start = 0; start < raw.length; start++) {
220
+ if (!QODER_COMPOSER.test(raw[start] ?? ''))
221
+ continue;
222
+ let end = start;
223
+ while (!QODER_STATUS.test(raw[end + 1] ?? '') && /^ {3}\S/.test(raw[end + 1] ?? ''))
224
+ end++;
225
+ const modeAbove = raw.slice(Math.max(0, start - 3), start).some((line) => QODER_MODE.test(line));
226
+ const statusBelow = QODER_STATUS.test(raw[end + 1] ?? '');
227
+ if (modeAbove || statusBelow)
228
+ spans.push([start, end]);
379
229
  }
380
- }
381
- /** A live left-ruled question menu with its fixed footer and custom-answer choice. */
382
- function openCodeQuestionMenu(raw, lines) {
383
- const footer = [...lines].reverse().find((line) => QUESTION_MENU_FOOTER.test(line.text));
384
- if (footer === undefined)
385
- return null;
386
- const after = lines.filter((line) => line.index > footer.index);
387
- // The programme may draw a status line below the menu, but another input
388
- // box or a resumed transcript means this menu is no longer waiting.
389
- if (after.length > 2 || after.some((line) => BUSY_LINE.test(line.text) || /[╭╰│❯›]/u.test(line.text)))
390
- return null;
391
- let cursor = footer.index - 1;
392
- while (QUESTION_MENU_BAR.test(raw[cursor] ?? ''))
393
- cursor--;
394
- const options = [];
395
- for (let count = 0; count < 4 && cursor >= 0; count++) {
396
- while (QUESTION_MENU_DESCRIPTION.test(raw[cursor] ?? ''))
397
- cursor--;
398
- const row = QUESTION_MENU_OPTION.exec(raw[cursor] ?? '');
399
- if (row === null)
400
- break;
401
- options.unshift(row[2]);
402
- cursor--;
403
- }
404
- // The walk above collects option rows from the bottom. Their numbers must
405
- // be consecutive, with the final row offering the custom answer.
406
- if (options.length < 2 || options.length > 4 || options.at(-1) !== 'Type your own answer')
407
- return null;
408
- const firstOption = cursor + 1;
409
- const numbered = raw.slice(firstOption, footer.index).map((line) => QUESTION_MENU_OPTION.exec(line)?.[1]);
410
- if (numbered.filter((value) => value !== undefined).join(',') !== options.map((_, i) => String(i + 1)).join(','))
411
- return null;
412
- if (!QUESTION_MENU_BAR.test(raw[cursor] ?? ''))
413
- return null;
414
- while (QUESTION_MENU_BAR.test(raw[cursor] ?? ''))
415
- cursor--;
416
- const question = [];
417
- while (cursor >= 0 && question.length < 8) {
418
- const row = QUESTION_MENU_TEXT.exec(raw[cursor] ?? '');
419
- if (row === null || QUESTION_MENU_OPTION.test(raw[cursor] ?? ''))
420
- break;
421
- question.unshift(row[1]);
422
- cursor--;
423
- }
424
- if (question.length === 0)
425
- return null;
426
- const first = cursor + 1;
427
- return {
428
- question: normalise(question.join(' ')),
429
- options,
430
- optionRows: raw.slice(firstOption, footer.index).map((line, index) => QUESTION_MENU_OPTION.test(line) ? firstOption + index : -1).filter((index) => index >= 0),
431
- signature: normalise(raw.slice(first, footer.index + 1).join(' ')),
432
- rows: [first, footer.index],
433
- basis: 'footer',
434
- };
230
+ return spans;
435
231
  }
436
232
  /**
437
233
  * A clack step waiting on its answer: a `◆` or `▲` headline, choice rows in
@@ -444,7 +240,7 @@ function openCodeQuestionMenu(raw, lines) {
444
240
  * validation message may sit there, directly under the `└` that carries it and
445
241
  * indented as clack indents it (VALIDATION_REST).
446
242
  */
447
- function clackPrompt(tail, raw) {
243
+ function clackPrompt(tail, raw, shapes, busy) {
448
244
  const text = (index) => (raw[index] ?? '').trimEnd();
449
245
  let lastRow = null;
450
246
  for (const line of tail) {
@@ -468,7 +264,7 @@ function clackPrompt(tail, raw) {
468
264
  end++;
469
265
  if (!CLACK_BAR_END.test(text(end)))
470
266
  return null;
471
- if (raw.slice(lastRow.index + 1).some((line) => BUSY_LINE.test(line)))
267
+ if (raw.slice(lastRow.index + 1).some((line) => busy(line)))
472
268
  return null;
473
269
  let after = end + 1;
474
270
  if (/^└ {2}\S/.test(text(end)))
@@ -479,7 +275,7 @@ function clackPrompt(tail, raw) {
479
275
  // The message runs from the headline down to the first row, less the
480
276
  // `...` clack draws where it has scrolled rows out of view. A step with no
481
277
  // message of its own is asked by the message logged just above it.
482
- const message = headline[1] === undefined ? loggedAbove(raw, top - 1) : [headline[1]];
278
+ const message = headline[1] === undefined ? (shapes.find(shape => shape.clackMessage)?.clackMessage?.(raw, top - 1) ?? []) : [headline[1]];
483
279
  const options = [];
484
280
  const optionRows = [];
485
281
  let radios = 0;
@@ -519,40 +315,6 @@ function clackPrompt(tail, raw) {
519
315
  basis: 'frame',
520
316
  };
521
317
  }
522
- /**
523
- * The message clack logged directly above the line at `index`: its first
524
- * line (`● Accessing workspace:`) and the lines in the gutter under it.
525
- * Empty when what is above is not a logged message.
526
- *
527
- * A line longer than the terminal is wide goes on at the start of the next
528
- * row, out of the gutter. Such a row is joined to the row above it as it
529
- * stands, since the break can fall inside a word, but only when the row above
530
- * fills the screen's width as far as the screen shows it (its longest line, or
531
- * one short where the break trimmed a space). Any other line out of the gutter
532
- * is not part of the message.
533
- */
534
- function loggedAbove(raw, index) {
535
- const width = Math.max(...raw.map((line) => line.trimEnd().length));
536
- const lines = [];
537
- let wrapped = '';
538
- for (let at = index - 1; at >= 0; at--) {
539
- const line = (raw[at] ?? '').trimEnd();
540
- const first = CLACK_LOG.exec(line);
541
- if (first !== null)
542
- return [`${first[1] ?? ''}${wrapped}`, ...lines];
543
- if (CLACK_GUTTER.test(line)) {
544
- lines.unshift(`${line.slice(1).trim()}${wrapped}`);
545
- wrapped = '';
546
- continue;
547
- }
548
- if (line.trim() === '')
549
- return [];
550
- if ((raw[at - 1] ?? '').trimEnd().length < width - 1)
551
- return [];
552
- wrapped = `${line}${wrapped}`;
553
- }
554
- return [];
555
- }
556
318
  /**
557
319
  * Numbered option rows anywhere in the tail, wrap-tolerant: Codex wraps a
558
320
  * long option's text across several lines, so consecutive-row detection
@@ -560,11 +322,11 @@ function loggedAbove(raw, index) {
560
322
  * DECREASE belong to one chooser; a decrease means a new list started and
561
323
  * only the newest can be live.
562
324
  */
563
- function numberedBlock(tail) {
325
+ function numberedBlock(tail, shapes) {
564
326
  let rows = [];
565
327
  let previousNumber = 0;
566
328
  for (const line of tail) {
567
- const match = OPTION_ROW.exec(line.text);
329
+ const match = firstMatch(shapes.map(shape => shape.numbered), line.text);
568
330
  if (match === null)
569
331
  continue;
570
332
  const number = Number(match[1]);
@@ -607,13 +369,13 @@ function letterBlock(tail) {
607
369
  * both y and n. A table of y/n flags fails the first test and a list of
608
370
  * keyboard shortcuts the second.
609
371
  */
610
- function keyHintBlock(tail) {
372
+ function keyHintBlock(tail, shapes) {
611
373
  let rows = [];
612
374
  let keys = [];
613
375
  let layout = '';
614
376
  let lastIndex = -1;
615
377
  for (const line of tail) {
616
- const match = KEY_HINT_ROW.exec(line.text);
378
+ const match = firstMatch(shapes.map(shape => shape.keyHint), line.text);
617
379
  if (match === null)
618
380
  continue;
619
381
  const label = match[2] ?? '';
@@ -642,12 +404,13 @@ function keyHintBlock(tail) {
642
404
  * means adjacent: a blank line or a rule ends the block, which is what keeps
643
405
  * a composer line (`❯ Try "…"`) apart from the status lines drawn under its
644
406
  * rule. Claude Code's idle screen would otherwise read as a three-option
645
- * chooser.
407
+ * chooser. The Qoder composer is excluded when a block overlaps its framed
408
+ * span, along with the other chooser shapes.
646
409
  */
647
- function pointerBlock(tail, raw) {
410
+ function pointerBlock(tail, raw, shapes) {
648
411
  let pointer = null;
649
412
  for (const line of tail) {
650
- const match = POINTER_ROW.exec(line.text);
413
+ const match = firstMatch(shapes.map(shape => shape.pointer), line.text);
651
414
  if (match === null)
652
415
  continue;
653
416
  const text = match[3] ?? '';
@@ -666,7 +429,7 @@ function pointerBlock(tail, raw) {
666
429
  return null;
667
430
  if (/\s/.test(text.charAt(textCol)))
668
431
  return null;
669
- if (POINTER_ROW.test(text))
432
+ if (shapes.some(shape => shape.pointer?.test(text)))
670
433
  return null;
671
434
  return { text, index };
672
435
  };
@@ -689,45 +452,11 @@ function pointerBlock(tail, raw) {
689
452
  return null;
690
453
  return { rows: all.map((line) => ({ line, option: stripMarkers(line.text) })), kind: 'pointer' };
691
454
  }
692
- /**
693
- * Where an older Grok box's command starts. The command is plain bar text
694
- * above the radios. The walk may cross the one bare bar between that text
695
- * and the radios. It stops at the next bare bar, or at a line that starts
696
- * Grok's reasoning (`♦ Thinking`, or the spinner). The run is taken only
697
- * when a line in it is command evidence: the box's `│ > ` question row,
698
- * a `$`, or a `:` continuation. Otherwise the run is the same shape as
699
- * reasoning, and the radios stay the start.
700
- */
701
- function commandAboveRadios(raw, firstOption) {
702
- const text = (index) => (raw[index] ?? '').trimEnd();
703
- if (!/^ {2}│ {2}\d+ \([○•●]\) /.test(text(firstOption)))
704
- return firstOption;
705
- const above = firstOption - 1;
706
- // The one bare bar between the command and the radios may be crossed.
707
- // Text sitting directly on the radios is the command itself.
708
- const gap = GROK_BARE_BAR.test(text(above));
709
- let cursor = gap ? above - 1 : above;
710
- let start = firstOption;
711
- let sawText = false;
712
- let sawEvidence = false;
713
- while (cursor >= 0 && GROK_BAR_TEXT.test(text(cursor)) && !GROK_REASONING_START.test(text(cursor))) {
714
- sawText = true;
715
- if (GROK_BOX_QUESTION.test(text(cursor)) || GROK_COMMAND_MARK.test(text(cursor)))
716
- sawEvidence = true;
717
- start = cursor;
718
- cursor--;
719
- }
720
- if (!sawText || !sawEvidence)
721
- return firstOption;
722
- if (GROK_BARE_BAR.test(text(cursor)) || GROK_REASONING_START.test(text(cursor)))
723
- return start;
724
- return firstOption;
725
- }
726
455
  /**
727
456
  * Whether a block is a prompt the program is WAITING on, and if so the
728
457
  * prompt as the consumer should see it.
729
458
  */
730
- function livePrompt(block, tail, raw) {
459
+ function livePrompt(block, tail, raw, shapes, busy) {
731
460
  const { rows, kind } = block;
732
461
  const blockStart = rows[0].line.index;
733
462
  const blockEnd = rows[rows.length - 1].line.index;
@@ -735,15 +464,15 @@ function livePrompt(block, tail, raw) {
735
464
  // the block is history. (The `Press enter…` footer below the block is
736
465
  // the opposite: it confirms the prompt is live.)
737
466
  const below = tail.filter((line) => line.index > blockEnd);
738
- if (below.some((line) => BUSY_LINE.test(line.text)))
467
+ if (below.some((line) => busy(line.text)))
739
468
  return null;
740
- const hasMarker = tail.some((line) => line.index >= blockStart && line.index <= blockEnd && MARKER_LINE.test(line.text));
741
- const hasPressEnter = below.some((line) => PRESS_ENTER.test(line.text));
469
+ const hasMarker = tail.some((line) => line.index >= blockStart && line.index <= blockEnd && shapes.some(shape => shape.marker?.test(line.text)));
470
+ const hasPressEnter = below.some((line) => shapes.some(shape => shape.footer?.test(line.text)));
742
471
  const nothingBelow = below.every((line) => RULE_LINE.test(line.text));
743
472
  // A question mark above the bare bar that closes an older Grok command is
744
473
  // reasoning. The command below that bar is claimed on its own, further down.
745
- const commandStart = commandAboveRadios(raw, blockStart);
746
- let question = findQuestion(tail, blockStart);
474
+ const commandStart = (shapes.find(shape => shape.commandStart)?.commandStart?.(raw, blockStart) ?? blockStart);
475
+ let question = findQuestion(tail, blockStart, shapes);
747
476
  if (question !== null && commandStart < blockStart && question.index < commandStart)
748
477
  question = null;
749
478
  let live;
@@ -835,8 +564,8 @@ export class StalePromptGuard {
835
564
  signatureAtInput = null;
836
565
  cleared = false;
837
566
  /** Input is being written; `screen` is what the program showed at that moment. */
838
- noteInput(screen) {
839
- this.signatureAtInput = detectPrompt(screen)?.signature ?? null;
567
+ noteInput(screen, agent = 'generic', styled) {
568
+ this.signatureAtInput = detectPrompt(screen, agent, undefined, styled)?.signature ?? null;
840
569
  this.cleared = false;
841
570
  }
842
571
  /** A look at the screen found this prompt (or none, when null). */
@@ -860,22 +589,24 @@ export class StalePromptGuard {
860
589
  * misattribute ordinary transcript text. A question mark anywhere counts,
861
590
  * not only at the end: Claude Code's trust prompt asks "…one you trust?
862
591
  * (Like your own code…" and inquirer's `? Select a template: (Use arrow keys)`
863
- * leads with it. Returns the line, its text normalised.
592
+ * leads with it. Keyboard-help hints are skipped. Returns the line, its
593
+ * text normalised.
864
594
  */
865
- function findQuestion(tail, blockStart) {
595
+ function findQuestion(tail, blockStart, shapes) {
866
596
  const above = tail.filter((line) => line.index < blockStart);
867
597
  let inspected = 0;
868
598
  for (let i = above.length - 1; i >= 0 && inspected < QUESTION_SEARCH_BUDGET; i--) {
869
599
  const line = above[i];
870
600
  if (RULE_LINE.test(line.text))
871
601
  continue;
602
+ if (KEY_HELP_HINT.test(line.text))
603
+ continue;
872
604
  inspected++;
873
605
  // Only Grok's exact box prefix is chrome. A question may itself begin
874
606
  // with `>` or a box character, so leave everything after that prefix.
875
- const cleaned = normalise(GROK_BOX_QUESTION.test(line.text)
876
- ? line.text.replace(GROK_BOX_QUESTION, '')
877
- : line.text);
878
- if (GROK_BOX_QUESTION.test(line.text) ||
607
+ const prefix = shapes.find(shape => shape.questionPrefix?.test(line.text))?.questionPrefix;
608
+ const cleaned = normalise(prefix === undefined ? line.text : line.text.replace(prefix, ''));
609
+ if (prefix !== undefined ||
879
610
  /\?/.test(cleaned) ||
880
611
  /permission required/i.test(cleaned) ||
881
612
  /^allow\b/i.test(cleaned) ||
@@ -894,4 +625,23 @@ function findQuestion(tail, blockStart) {
894
625
  function drawnTogether(tail, upper, lower) {
895
626
  return tail.filter((line) => line.index > upper && line.index < lower).length === lower - upper - 1;
896
627
  }
628
+ function firstMatch(patterns, text) {
629
+ for (const pattern of patterns) {
630
+ const match = pattern?.exec(text);
631
+ if (match !== undefined && match !== null)
632
+ return match;
633
+ }
634
+ return null;
635
+ }
636
+ /** Each session owns its own settling clocks. A bare wait target retains the shared fallback. */
637
+ export function createPromptReader(agent = 'generic', settleAll = false) {
638
+ const modules = settleAll ? AGENT_MODULES : [moduleFor(agent)];
639
+ const settlers = modules.flatMap(module => module?.createPromptSettler === undefined ? [] : [module.createPromptSettler()]);
640
+ return (screen, now = Date.now(), styled, viewportRows) => {
641
+ let prompt = detectPrompt(screen, agent, viewportRows, styled);
642
+ for (const settler of settlers)
643
+ prompt = settler.settle(prompt, screen, now, styled);
644
+ return prompt;
645
+ };
646
+ }
897
647
  //# sourceMappingURL=promptDetector.js.map