shellpuppet 0.2.1 → 0.4.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.
- package/README.md +65 -18
- package/dist/agents/agy/index.d.ts +2 -0
- package/dist/agents/agy/index.js +11 -0
- package/dist/agents/agy/index.js.map +1 -0
- package/dist/agents/agy/nudge.d.ts +2 -0
- package/dist/agents/agy/nudge.js +29 -0
- package/dist/agents/agy/nudge.js.map +1 -0
- package/dist/agents/agy/reading.d.ts +2 -0
- package/dist/agents/agy/reading.js +28 -0
- package/dist/agents/agy/reading.js.map +1 -0
- package/dist/agents/barNudge.d.ts +9 -0
- package/dist/agents/barNudge.js +21 -0
- package/dist/agents/barNudge.js.map +1 -0
- package/dist/agents/claude/index.d.ts +2 -0
- package/dist/agents/claude/index.js +31 -0
- package/dist/agents/claude/index.js.map +1 -0
- package/dist/agents/claude/liveResumeId.d.ts +6 -0
- package/dist/agents/claude/liveResumeId.js +101 -0
- package/dist/agents/claude/liveResumeId.js.map +1 -0
- package/dist/agents/claude/nudge.d.ts +2 -0
- package/dist/agents/claude/nudge.js +38 -0
- package/dist/agents/claude/nudge.js.map +1 -0
- package/dist/agents/claude/prompts.d.ts +9 -0
- package/dist/agents/claude/prompts.js +16 -0
- package/dist/agents/claude/prompts.js.map +1 -0
- package/dist/agents/claude/reading.d.ts +2 -0
- package/dist/agents/claude/reading.js +25 -0
- package/dist/agents/claude/reading.js.map +1 -0
- package/dist/agents/codex/draft.d.ts +3 -0
- package/dist/agents/codex/draft.js +88 -0
- package/dist/agents/codex/draft.js.map +1 -0
- package/dist/agents/codex/index.d.ts +2 -0
- package/dist/agents/codex/index.js +30 -0
- package/dist/agents/codex/index.js.map +1 -0
- package/dist/agents/codex/lineBreaks.d.ts +6 -0
- package/dist/agents/codex/lineBreaks.js +105 -0
- package/dist/agents/codex/lineBreaks.js.map +1 -0
- package/dist/agents/codex/nudge.d.ts +2 -0
- package/dist/agents/codex/nudge.js +34 -0
- package/dist/agents/codex/nudge.js.map +1 -0
- package/dist/agents/codex/prompts.d.ts +9 -0
- package/dist/agents/codex/prompts.js +14 -0
- package/dist/agents/codex/prompts.js.map +1 -0
- package/dist/agents/codex/reading.d.ts +2 -0
- package/dist/agents/codex/reading.js +22 -0
- package/dist/agents/codex/reading.js.map +1 -0
- package/dist/agents/generic/index.d.ts +3 -0
- package/dist/agents/generic/index.js +9 -0
- package/dist/agents/generic/index.js.map +1 -0
- package/dist/agents/generic/prompts.d.ts +2 -0
- package/dist/agents/generic/prompts.js +10 -0
- package/dist/agents/generic/prompts.js.map +1 -0
- package/dist/agents/grok/actionBox.d.ts +13 -0
- package/dist/agents/grok/actionBox.js +127 -0
- package/dist/agents/grok/actionBox.js.map +1 -0
- package/dist/agents/grok/index.d.ts +2 -0
- package/dist/agents/grok/index.js +20 -0
- package/dist/agents/grok/index.js.map +1 -0
- package/dist/agents/grok/nudge.d.ts +2 -0
- package/dist/agents/grok/nudge.js +81 -0
- package/dist/agents/grok/nudge.js.map +1 -0
- package/dist/agents/grok/prompts.d.ts +4 -0
- package/dist/agents/grok/prompts.js +89 -0
- package/dist/agents/grok/prompts.js.map +1 -0
- package/dist/agents/grok/reading.d.ts +2 -0
- package/dist/agents/grok/reading.js +49 -0
- package/dist/agents/grok/reading.js.map +1 -0
- package/dist/agents/grok/readingRules.d.ts +2 -0
- package/dist/agents/grok/readingRules.js +44 -0
- package/dist/agents/grok/readingRules.js.map +1 -0
- package/dist/agents/hermes/frame.d.ts +25 -0
- package/dist/agents/hermes/frame.js +145 -0
- package/dist/agents/hermes/frame.js.map +1 -0
- package/dist/agents/hermes/index.d.ts +2 -0
- package/dist/agents/hermes/index.js +20 -0
- package/dist/agents/hermes/index.js.map +1 -0
- package/dist/agents/hermes/nudge.d.ts +5 -0
- package/dist/agents/hermes/nudge.js +76 -0
- package/dist/agents/hermes/nudge.js.map +1 -0
- package/dist/agents/hermes/prompts.d.ts +7 -0
- package/dist/agents/hermes/prompts.js +101 -0
- package/dist/agents/hermes/prompts.js.map +1 -0
- package/dist/agents/hermes/reading.d.ts +7 -0
- package/dist/agents/hermes/reading.js +102 -0
- package/dist/agents/hermes/reading.js.map +1 -0
- package/dist/agents/index.d.ts +28 -0
- package/dist/agents/index.js +48 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/input.d.ts +2 -0
- package/dist/agents/input.js +9 -0
- package/dist/agents/input.js.map +1 -0
- package/dist/agents/mimo/index.d.ts +2 -0
- package/dist/agents/mimo/index.js +13 -0
- package/dist/agents/mimo/index.js.map +1 -0
- package/dist/agents/mimo/nudge.d.ts +3 -0
- package/dist/agents/mimo/nudge.js +60 -0
- package/dist/agents/mimo/nudge.js.map +1 -0
- package/dist/agents/mimo/prompts.d.ts +2 -0
- package/dist/agents/mimo/prompts.js +40 -0
- package/dist/agents/mimo/prompts.js.map +1 -0
- package/dist/agents/mimo/reading.d.ts +2 -0
- package/dist/agents/mimo/reading.js +31 -0
- package/dist/agents/mimo/reading.js.map +1 -0
- package/dist/agents/mimo/readingRules.d.ts +2 -0
- package/dist/agents/mimo/readingRules.js +79 -0
- package/dist/agents/mimo/readingRules.js.map +1 -0
- package/dist/agents/mimo/stalls.d.ts +2 -0
- package/dist/agents/mimo/stalls.js +81 -0
- package/dist/agents/mimo/stalls.js.map +1 -0
- package/dist/agents/muse/index.d.ts +2 -0
- package/dist/agents/muse/index.js +20 -0
- package/dist/agents/muse/index.js.map +1 -0
- package/dist/agents/muse/input.d.ts +3 -0
- package/dist/agents/muse/input.js +7 -0
- package/dist/agents/muse/input.js.map +1 -0
- package/dist/agents/muse/nudge.d.ts +2 -0
- package/dist/agents/muse/nudge.js +33 -0
- package/dist/agents/muse/nudge.js.map +1 -0
- package/dist/agents/muse/prompts.d.ts +14 -0
- package/dist/agents/muse/prompts.js +132 -0
- package/dist/agents/muse/prompts.js.map +1 -0
- package/dist/agents/muse/reading.d.ts +2 -0
- package/dist/agents/muse/reading.js +33 -0
- package/dist/agents/muse/reading.js.map +1 -0
- package/dist/agents/muse/readingRules.d.ts +2 -0
- package/dist/agents/muse/readingRules.js +49 -0
- package/dist/agents/muse/readingRules.js.map +1 -0
- package/dist/agents/nudgeReading.d.ts +74 -0
- package/dist/agents/nudgeReading.js +252 -0
- package/dist/agents/nudgeReading.js.map +1 -0
- package/dist/agents/opencode/index.d.ts +2 -0
- package/dist/agents/opencode/index.js +21 -0
- package/dist/agents/opencode/index.js.map +1 -0
- package/dist/agents/opencode/nudge.d.ts +6 -0
- package/dist/agents/opencode/nudge.js +189 -0
- package/dist/agents/opencode/nudge.js.map +1 -0
- package/dist/agents/opencode/prompts.d.ts +6 -0
- package/dist/agents/opencode/prompts.js +198 -0
- package/dist/agents/opencode/prompts.js.map +1 -0
- package/dist/agents/opencode/reading.d.ts +2 -0
- package/dist/agents/opencode/reading.js +29 -0
- package/dist/agents/opencode/reading.js.map +1 -0
- package/dist/agents/opencode/stalls.d.ts +3 -0
- package/dist/agents/opencode/stalls.js +14 -0
- package/dist/agents/opencode/stalls.js.map +1 -0
- package/dist/agents/qoder/index.d.ts +2 -0
- package/dist/agents/qoder/index.js +12 -0
- package/dist/agents/qoder/index.js.map +1 -0
- package/dist/agents/qoder/nudge.d.ts +2 -0
- package/dist/agents/qoder/nudge.js +16 -0
- package/dist/agents/qoder/nudge.js.map +1 -0
- package/dist/agents/qoder/prompts.d.ts +2 -0
- package/dist/agents/qoder/prompts.js +6 -0
- package/dist/agents/qoder/prompts.js.map +1 -0
- package/dist/agents/qoder/reading.d.ts +2 -0
- package/dist/agents/qoder/reading.js +41 -0
- package/dist/agents/qoder/reading.js.map +1 -0
- package/dist/agents/types.d.ts +202 -0
- package/dist/agents/types.js +2 -0
- package/dist/agents/types.js.map +1 -0
- package/dist/cli/index.js +220 -21
- package/dist/cli/index.js.map +1 -1
- package/dist/client/http.d.ts +8 -2
- package/dist/client/http.js +179 -56
- package/dist/client/http.js.map +1 -1
- package/dist/core/cron.d.ts +6 -0
- package/dist/core/cron.js +63 -0
- package/dist/core/cron.js.map +1 -0
- package/dist/core/dialogs.d.ts +2 -4
- package/dist/core/dialogs.js +6 -12
- package/dist/core/dialogs.js.map +1 -1
- package/dist/core/environment.d.ts +6 -0
- package/dist/core/environment.js +35 -0
- package/dist/core/environment.js.map +1 -0
- package/dist/core/mailbox.d.ts +223 -0
- package/dist/core/mailbox.js +549 -0
- package/dist/core/mailbox.js.map +1 -0
- package/dist/core/manager.d.ts +4 -0
- package/dist/core/manager.js +40 -2
- package/dist/core/manager.js.map +1 -1
- package/dist/core/messageText.d.ts +2 -0
- package/dist/core/messageText.js +6 -0
- package/dist/core/messageText.js.map +1 -0
- package/dist/core/nudge.d.ts +37 -0
- package/dist/core/nudge.js +60 -0
- package/dist/core/nudge.js.map +1 -0
- package/dist/core/promptDetector.d.ts +14 -12
- package/dist/core/promptDetector.js +115 -363
- package/dist/core/promptDetector.js.map +1 -1
- package/dist/core/promptText.d.ts +1 -0
- package/dist/core/promptText.js +4 -0
- package/dist/core/promptText.js.map +1 -0
- package/dist/core/readiness.d.ts +14 -0
- package/dist/core/readiness.js +95 -0
- package/dist/core/readiness.js.map +1 -0
- package/dist/core/reasoning.d.ts +68 -7
- package/dist/core/reasoning.js +584 -328
- package/dist/core/reasoning.js.map +1 -1
- package/dist/core/renderer.d.ts +63 -3
- package/dist/core/renderer.js +370 -42
- package/dist/core/renderer.js.map +1 -1
- package/dist/core/selection.d.ts +1 -1
- package/dist/core/selection.js +3 -3
- package/dist/core/selection.js.map +1 -1
- package/dist/core/session.d.ts +175 -13
- package/dist/core/session.js +1030 -93
- package/dist/core/session.js.map +1 -1
- package/dist/core/stringWidth.d.ts +2 -0
- package/dist/core/stringWidth.js +13 -0
- package/dist/core/stringWidth.js.map +1 -0
- package/dist/core/types.d.ts +62 -4
- package/dist/core/types.js +41 -0
- package/dist/core/types.js.map +1 -1
- package/dist/core/waiter.d.ts +9 -2
- package/dist/core/waiter.js +35 -10
- package/dist/core/waiter.js.map +1 -1
- package/dist/daemon/audit.d.ts +1 -1
- package/dist/daemon/audit.js +2 -1
- package/dist/daemon/audit.js.map +1 -1
- package/dist/daemon/config.d.ts +44 -0
- package/dist/daemon/config.js +166 -4
- package/dist/daemon/config.js.map +1 -1
- package/dist/daemon/folderPicker.js +21 -2
- package/dist/daemon/folderPicker.js.map +1 -1
- package/dist/daemon/homeOwner.d.ts +15 -0
- package/dist/daemon/homeOwner.js +106 -0
- package/dist/daemon/homeOwner.js.map +1 -0
- package/dist/daemon/index.js +14 -6
- package/dist/daemon/index.js.map +1 -1
- package/dist/daemon/launchProfiles.d.ts +5 -0
- package/dist/daemon/launchProfiles.js +54 -48
- package/dist/daemon/launchProfiles.js.map +1 -1
- package/dist/daemon/logger.js +1 -1
- package/dist/daemon/logger.js.map +1 -1
- package/dist/daemon/nudgeScheduler.d.ts +21 -0
- package/dist/daemon/nudgeScheduler.js +61 -0
- package/dist/daemon/nudgeScheduler.js.map +1 -0
- package/dist/daemon/paths.d.ts +20 -16
- package/dist/daemon/paths.js +181 -50
- package/dist/daemon/paths.js.map +1 -1
- package/dist/daemon/restartHold.js +16 -15
- package/dist/daemon/restartHold.js.map +1 -1
- package/dist/daemon/restartSource.d.ts +7 -0
- package/dist/daemon/restartSource.js +89 -0
- package/dist/daemon/restartSource.js.map +1 -0
- package/dist/daemon/schedules.d.ts +57 -0
- package/dist/daemon/schedules.js +181 -0
- package/dist/daemon/schedules.js.map +1 -0
- package/dist/daemon/screenshot.d.ts +4 -1
- package/dist/daemon/screenshot.js +45 -7
- package/dist/daemon/screenshot.js.map +1 -1
- package/dist/daemon/server.d.ts +82 -13
- package/dist/daemon/server.js +1737 -330
- package/dist/daemon/server.js.map +1 -1
- package/dist/daemon/sessionFeed.js +4 -1
- package/dist/daemon/sessionFeed.js.map +1 -1
- package/dist/daemon/viewerLauncher.js +3 -2
- package/dist/daemon/viewerLauncher.js.map +1 -1
- package/dist/daemon/wrappedLaunch.d.ts +1 -0
- package/dist/daemon/wrappedLaunch.js +38 -0
- package/dist/daemon/wrappedLaunch.js.map +1 -0
- package/dist/daemon/wrappedStart.d.ts +13 -0
- package/dist/daemon/wrappedStart.js +113 -0
- package/dist/daemon/wrappedStart.js.map +1 -0
- package/dist/daemon/wrappedSupervisor.d.ts +1 -0
- package/dist/daemon/wrappedSupervisor.js +55 -0
- package/dist/daemon/wrappedSupervisor.js.map +1 -0
- package/dist/mcp/config.js +2 -1
- package/dist/mcp/config.js.map +1 -1
- package/dist/mcp/index.js +28 -2
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/tools.d.ts +21 -1
- package/dist/mcp/tools.js +216 -29
- package/dist/mcp/tools.js.map +1 -1
- package/dist/viewer/dashboard-folders.js +7 -1
- package/dist/viewer/dashboard-layout.js +6 -52
- package/dist/viewer/dashboard.css +20 -4
- package/dist/viewer/dashboard.html +12 -3
- package/dist/viewer/dashboard.js +549 -382
- package/dist/viewer/pane.js +744 -136
- package/dist/viewer/viewer.css +1 -1
- package/dist/viewer/viewer.js +3 -1
- 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.
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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,99 @@ 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
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
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;
|
|
171
|
+
if (moduleFor(agent)?.incompleteMenu?.(raw))
|
|
172
|
+
return null;
|
|
234
173
|
// A clack step draws its own frame, and the frame alone says whether the
|
|
235
174
|
// step is waiting.
|
|
236
|
-
const clack = clackPrompt(tail, raw);
|
|
175
|
+
const clack = clackPrompt(tail, raw, rows, busy);
|
|
237
176
|
if (clack !== null)
|
|
238
177
|
return clack;
|
|
239
178
|
// Four chooser shapes, most specific first. A block that is found but
|
|
240
179
|
// not LIVE (a numbered list in the transcript, say) does not end the
|
|
241
180
|
// search: the shapes below it, and the single-line tails after, may be.
|
|
181
|
+
// Builders never see Qoder's composer rows, so a draft drawn like a menu
|
|
182
|
+
// cannot displace a real menu above it as the latest block.
|
|
183
|
+
const inComposer = (index) => composerSpans.some(([start, end]) => index >= start && index <= end);
|
|
184
|
+
const chooserTail = composerSpans.length === 0 ? tail : tail.filter((line) => !inComposer(line.index));
|
|
242
185
|
const blocks = [
|
|
243
|
-
numberedBlock(
|
|
244
|
-
letterBlock(
|
|
245
|
-
keyHintBlock(
|
|
246
|
-
pointerBlock(
|
|
186
|
+
numberedBlock(chooserTail, rows),
|
|
187
|
+
letterBlock(chooserTail),
|
|
188
|
+
keyHintBlock(chooserTail, rows),
|
|
189
|
+
pointerBlock(chooserTail, raw, rows),
|
|
247
190
|
];
|
|
248
191
|
for (const block of blocks) {
|
|
249
192
|
if (block === null)
|
|
250
193
|
continue;
|
|
251
|
-
|
|
194
|
+
if (block.rows.some(({ line }) => inComposer(line.index)))
|
|
195
|
+
continue;
|
|
196
|
+
const prompt = livePrompt(block, tail, raw, rows, busy);
|
|
252
197
|
if (prompt !== null)
|
|
253
198
|
return prompt;
|
|
254
199
|
}
|
|
255
200
|
// No live option block: a y/n tail on the LAST content line is still a prompt.
|
|
256
201
|
const last = lines[lines.length - 1];
|
|
257
|
-
if (isYesNo(last.text) && !
|
|
202
|
+
if (isYesNo(last.text) && !busy(last.text)) {
|
|
258
203
|
const question = normalise(last.text);
|
|
259
204
|
return { question, options: [], signature: question, rows: [last.index, last.index], basis: 'frame' };
|
|
260
205
|
}
|
|
261
206
|
// A bare press-enter wait (the Codex onboarding screens): the last content
|
|
262
207
|
// line asks for enter and nothing below it can contradict that.
|
|
263
|
-
if (
|
|
208
|
+
if (rows.some(shape => shape.footer?.test(last.text))) {
|
|
264
209
|
const question = normalise(last.text);
|
|
265
210
|
return { question, options: [], signature: question, rows: [last.index, last.index], basis: 'frame' };
|
|
266
211
|
}
|
|
267
212
|
return null;
|
|
268
213
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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;
|
|
214
|
+
/** Qoder's input starts with ` > `; wrapped rows keep the text in column 4.
|
|
215
|
+
* Its mode line above or model status below distinguishes this input from a
|
|
216
|
+
* chooser with the same pointer. A key-help hint alone is shared with other
|
|
217
|
+
* choosers, so it cannot establish the composer frame.
|
|
218
|
+
*/
|
|
219
|
+
function qoderComposerSpans(raw) {
|
|
220
|
+
const spans = [];
|
|
221
|
+
for (let start = 0; start < raw.length; start++) {
|
|
222
|
+
if (!QODER_COMPOSER.test(raw[start] ?? ''))
|
|
223
|
+
continue;
|
|
224
|
+
let end = start;
|
|
225
|
+
while (!QODER_STATUS.test(raw[end + 1] ?? '') && /^ {3}\S/.test(raw[end + 1] ?? ''))
|
|
226
|
+
end++;
|
|
227
|
+
const modeAbove = raw.slice(Math.max(0, start - 3), start).some((line) => QODER_MODE.test(line));
|
|
228
|
+
const statusBelow = QODER_STATUS.test(raw[end + 1] ?? '');
|
|
229
|
+
if (modeAbove || statusBelow)
|
|
230
|
+
spans.push([start, end]);
|
|
379
231
|
}
|
|
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
|
-
};
|
|
232
|
+
return spans;
|
|
435
233
|
}
|
|
436
234
|
/**
|
|
437
235
|
* A clack step waiting on its answer: a `◆` or `▲` headline, choice rows in
|
|
@@ -444,7 +242,7 @@ function openCodeQuestionMenu(raw, lines) {
|
|
|
444
242
|
* validation message may sit there, directly under the `└` that carries it and
|
|
445
243
|
* indented as clack indents it (VALIDATION_REST).
|
|
446
244
|
*/
|
|
447
|
-
function clackPrompt(tail, raw) {
|
|
245
|
+
function clackPrompt(tail, raw, shapes, busy) {
|
|
448
246
|
const text = (index) => (raw[index] ?? '').trimEnd();
|
|
449
247
|
let lastRow = null;
|
|
450
248
|
for (const line of tail) {
|
|
@@ -468,7 +266,7 @@ function clackPrompt(tail, raw) {
|
|
|
468
266
|
end++;
|
|
469
267
|
if (!CLACK_BAR_END.test(text(end)))
|
|
470
268
|
return null;
|
|
471
|
-
if (raw.slice(lastRow.index + 1).some((line) =>
|
|
269
|
+
if (raw.slice(lastRow.index + 1).some((line) => busy(line)))
|
|
472
270
|
return null;
|
|
473
271
|
let after = end + 1;
|
|
474
272
|
if (/^└ {2}\S/.test(text(end)))
|
|
@@ -479,7 +277,7 @@ function clackPrompt(tail, raw) {
|
|
|
479
277
|
// The message runs from the headline down to the first row, less the
|
|
480
278
|
// `...` clack draws where it has scrolled rows out of view. A step with no
|
|
481
279
|
// message of its own is asked by the message logged just above it.
|
|
482
|
-
const message = headline[1] === undefined ?
|
|
280
|
+
const message = headline[1] === undefined ? (shapes.find(shape => shape.clackMessage)?.clackMessage?.(raw, top - 1) ?? []) : [headline[1]];
|
|
483
281
|
const options = [];
|
|
484
282
|
const optionRows = [];
|
|
485
283
|
let radios = 0;
|
|
@@ -519,40 +317,6 @@ function clackPrompt(tail, raw) {
|
|
|
519
317
|
basis: 'frame',
|
|
520
318
|
};
|
|
521
319
|
}
|
|
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
320
|
/**
|
|
557
321
|
* Numbered option rows anywhere in the tail, wrap-tolerant: Codex wraps a
|
|
558
322
|
* long option's text across several lines, so consecutive-row detection
|
|
@@ -560,11 +324,11 @@ function loggedAbove(raw, index) {
|
|
|
560
324
|
* DECREASE belong to one chooser; a decrease means a new list started and
|
|
561
325
|
* only the newest can be live.
|
|
562
326
|
*/
|
|
563
|
-
function numberedBlock(tail) {
|
|
327
|
+
function numberedBlock(tail, shapes) {
|
|
564
328
|
let rows = [];
|
|
565
329
|
let previousNumber = 0;
|
|
566
330
|
for (const line of tail) {
|
|
567
|
-
const match =
|
|
331
|
+
const match = firstMatch(shapes.map(shape => shape.numbered), line.text);
|
|
568
332
|
if (match === null)
|
|
569
333
|
continue;
|
|
570
334
|
const number = Number(match[1]);
|
|
@@ -607,13 +371,13 @@ function letterBlock(tail) {
|
|
|
607
371
|
* both y and n. A table of y/n flags fails the first test and a list of
|
|
608
372
|
* keyboard shortcuts the second.
|
|
609
373
|
*/
|
|
610
|
-
function keyHintBlock(tail) {
|
|
374
|
+
function keyHintBlock(tail, shapes) {
|
|
611
375
|
let rows = [];
|
|
612
376
|
let keys = [];
|
|
613
377
|
let layout = '';
|
|
614
378
|
let lastIndex = -1;
|
|
615
379
|
for (const line of tail) {
|
|
616
|
-
const match =
|
|
380
|
+
const match = firstMatch(shapes.map(shape => shape.keyHint), line.text);
|
|
617
381
|
if (match === null)
|
|
618
382
|
continue;
|
|
619
383
|
const label = match[2] ?? '';
|
|
@@ -642,12 +406,13 @@ function keyHintBlock(tail) {
|
|
|
642
406
|
* means adjacent: a blank line or a rule ends the block, which is what keeps
|
|
643
407
|
* a composer line (`❯ Try "…"`) apart from the status lines drawn under its
|
|
644
408
|
* rule. Claude Code's idle screen would otherwise read as a three-option
|
|
645
|
-
* chooser.
|
|
409
|
+
* chooser. The Qoder composer is excluded when a block overlaps its framed
|
|
410
|
+
* span, along with the other chooser shapes.
|
|
646
411
|
*/
|
|
647
|
-
function pointerBlock(tail, raw) {
|
|
412
|
+
function pointerBlock(tail, raw, shapes) {
|
|
648
413
|
let pointer = null;
|
|
649
414
|
for (const line of tail) {
|
|
650
|
-
const match =
|
|
415
|
+
const match = firstMatch(shapes.map(shape => shape.pointer), line.text);
|
|
651
416
|
if (match === null)
|
|
652
417
|
continue;
|
|
653
418
|
const text = match[3] ?? '';
|
|
@@ -666,7 +431,7 @@ function pointerBlock(tail, raw) {
|
|
|
666
431
|
return null;
|
|
667
432
|
if (/\s/.test(text.charAt(textCol)))
|
|
668
433
|
return null;
|
|
669
|
-
if (
|
|
434
|
+
if (shapes.some(shape => shape.pointer?.test(text)))
|
|
670
435
|
return null;
|
|
671
436
|
return { text, index };
|
|
672
437
|
};
|
|
@@ -689,45 +454,11 @@ function pointerBlock(tail, raw) {
|
|
|
689
454
|
return null;
|
|
690
455
|
return { rows: all.map((line) => ({ line, option: stripMarkers(line.text) })), kind: 'pointer' };
|
|
691
456
|
}
|
|
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
457
|
/**
|
|
727
458
|
* Whether a block is a prompt the program is WAITING on, and if so the
|
|
728
459
|
* prompt as the consumer should see it.
|
|
729
460
|
*/
|
|
730
|
-
function livePrompt(block, tail, raw) {
|
|
461
|
+
function livePrompt(block, tail, raw, shapes, busy) {
|
|
731
462
|
const { rows, kind } = block;
|
|
732
463
|
const blockStart = rows[0].line.index;
|
|
733
464
|
const blockEnd = rows[rows.length - 1].line.index;
|
|
@@ -735,15 +466,15 @@ function livePrompt(block, tail, raw) {
|
|
|
735
466
|
// the block is history. (The `Press enter…` footer below the block is
|
|
736
467
|
// the opposite: it confirms the prompt is live.)
|
|
737
468
|
const below = tail.filter((line) => line.index > blockEnd);
|
|
738
|
-
if (below.some((line) =>
|
|
469
|
+
if (below.some((line) => busy(line.text)))
|
|
739
470
|
return null;
|
|
740
|
-
const hasMarker = tail.some((line) => line.index >= blockStart && line.index <= blockEnd &&
|
|
741
|
-
const hasPressEnter = below.some((line) =>
|
|
471
|
+
const hasMarker = tail.some((line) => line.index >= blockStart && line.index <= blockEnd && shapes.some(shape => shape.marker?.test(line.text)));
|
|
472
|
+
const hasPressEnter = below.some((line) => shapes.some(shape => shape.footer?.test(line.text)));
|
|
742
473
|
const nothingBelow = below.every((line) => RULE_LINE.test(line.text));
|
|
743
474
|
// A question mark above the bare bar that closes an older Grok command is
|
|
744
475
|
// reasoning. The command below that bar is claimed on its own, further down.
|
|
745
|
-
const commandStart =
|
|
746
|
-
let question = findQuestion(tail, blockStart);
|
|
476
|
+
const commandStart = (shapes.find(shape => shape.commandStart)?.commandStart?.(raw, blockStart) ?? blockStart);
|
|
477
|
+
let question = findQuestion(tail, blockStart, shapes);
|
|
747
478
|
if (question !== null && commandStart < blockStart && question.index < commandStart)
|
|
748
479
|
question = null;
|
|
749
480
|
let live;
|
|
@@ -835,8 +566,8 @@ export class StalePromptGuard {
|
|
|
835
566
|
signatureAtInput = null;
|
|
836
567
|
cleared = false;
|
|
837
568
|
/** Input is being written; `screen` is what the program showed at that moment. */
|
|
838
|
-
noteInput(screen) {
|
|
839
|
-
this.signatureAtInput = detectPrompt(screen)?.signature ?? null;
|
|
569
|
+
noteInput(screen, agent = 'generic', styled) {
|
|
570
|
+
this.signatureAtInput = detectPrompt(screen, agent, undefined, styled)?.signature ?? null;
|
|
840
571
|
this.cleared = false;
|
|
841
572
|
}
|
|
842
573
|
/** A look at the screen found this prompt (or none, when null). */
|
|
@@ -860,22 +591,24 @@ export class StalePromptGuard {
|
|
|
860
591
|
* misattribute ordinary transcript text. A question mark anywhere counts,
|
|
861
592
|
* not only at the end: Claude Code's trust prompt asks "…one you trust?
|
|
862
593
|
* (Like your own code…" and inquirer's `? Select a template: (Use arrow keys)`
|
|
863
|
-
* leads with it. Returns the line, its
|
|
594
|
+
* leads with it. Keyboard-help hints are skipped. Returns the line, its
|
|
595
|
+
* text normalised.
|
|
864
596
|
*/
|
|
865
|
-
function findQuestion(tail, blockStart) {
|
|
597
|
+
function findQuestion(tail, blockStart, shapes) {
|
|
866
598
|
const above = tail.filter((line) => line.index < blockStart);
|
|
867
599
|
let inspected = 0;
|
|
868
600
|
for (let i = above.length - 1; i >= 0 && inspected < QUESTION_SEARCH_BUDGET; i--) {
|
|
869
601
|
const line = above[i];
|
|
870
602
|
if (RULE_LINE.test(line.text))
|
|
871
603
|
continue;
|
|
604
|
+
if (KEY_HELP_HINT.test(line.text))
|
|
605
|
+
continue;
|
|
872
606
|
inspected++;
|
|
873
607
|
// Only Grok's exact box prefix is chrome. A question may itself begin
|
|
874
608
|
// with `>` or a box character, so leave everything after that prefix.
|
|
875
|
-
const
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
if (GROK_BOX_QUESTION.test(line.text) ||
|
|
609
|
+
const prefix = shapes.find(shape => shape.questionPrefix?.test(line.text))?.questionPrefix;
|
|
610
|
+
const cleaned = normalise(prefix === undefined ? line.text : line.text.replace(prefix, ''));
|
|
611
|
+
if (prefix !== undefined ||
|
|
879
612
|
/\?/.test(cleaned) ||
|
|
880
613
|
/permission required/i.test(cleaned) ||
|
|
881
614
|
/^allow\b/i.test(cleaned) ||
|
|
@@ -894,4 +627,23 @@ function findQuestion(tail, blockStart) {
|
|
|
894
627
|
function drawnTogether(tail, upper, lower) {
|
|
895
628
|
return tail.filter((line) => line.index > upper && line.index < lower).length === lower - upper - 1;
|
|
896
629
|
}
|
|
630
|
+
function firstMatch(patterns, text) {
|
|
631
|
+
for (const pattern of patterns) {
|
|
632
|
+
const match = pattern?.exec(text);
|
|
633
|
+
if (match !== undefined && match !== null)
|
|
634
|
+
return match;
|
|
635
|
+
}
|
|
636
|
+
return null;
|
|
637
|
+
}
|
|
638
|
+
/** Each session owns its own settling clocks. A bare wait target retains the shared fallback. */
|
|
639
|
+
export function createPromptReader(agent = 'generic', settleAll = false) {
|
|
640
|
+
const modules = settleAll ? AGENT_MODULES : [moduleFor(agent)];
|
|
641
|
+
const settlers = modules.flatMap(module => module?.createPromptSettler === undefined ? [] : [module.createPromptSettler()]);
|
|
642
|
+
return (screen, now = Date.now(), styled, viewportRows) => {
|
|
643
|
+
let prompt = detectPrompt(screen, agent, viewportRows, styled);
|
|
644
|
+
for (const settler of settlers)
|
|
645
|
+
prompt = settler.settle(prompt, screen, now, styled);
|
|
646
|
+
return prompt;
|
|
647
|
+
};
|
|
648
|
+
}
|
|
897
649
|
//# sourceMappingURL=promptDetector.js.map
|