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.
Files changed (283) hide show
  1. package/README.md +65 -18
  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/liveResumeId.d.ts +6 -0
  18. package/dist/agents/claude/liveResumeId.js +101 -0
  19. package/dist/agents/claude/liveResumeId.js.map +1 -0
  20. package/dist/agents/claude/nudge.d.ts +2 -0
  21. package/dist/agents/claude/nudge.js +38 -0
  22. package/dist/agents/claude/nudge.js.map +1 -0
  23. package/dist/agents/claude/prompts.d.ts +9 -0
  24. package/dist/agents/claude/prompts.js +16 -0
  25. package/dist/agents/claude/prompts.js.map +1 -0
  26. package/dist/agents/claude/reading.d.ts +2 -0
  27. package/dist/agents/claude/reading.js +25 -0
  28. package/dist/agents/claude/reading.js.map +1 -0
  29. package/dist/agents/codex/draft.d.ts +3 -0
  30. package/dist/agents/codex/draft.js +88 -0
  31. package/dist/agents/codex/draft.js.map +1 -0
  32. package/dist/agents/codex/index.d.ts +2 -0
  33. package/dist/agents/codex/index.js +30 -0
  34. package/dist/agents/codex/index.js.map +1 -0
  35. package/dist/agents/codex/lineBreaks.d.ts +6 -0
  36. package/dist/agents/codex/lineBreaks.js +105 -0
  37. package/dist/agents/codex/lineBreaks.js.map +1 -0
  38. package/dist/agents/codex/nudge.d.ts +2 -0
  39. package/dist/agents/codex/nudge.js +34 -0
  40. package/dist/agents/codex/nudge.js.map +1 -0
  41. package/dist/agents/codex/prompts.d.ts +9 -0
  42. package/dist/agents/codex/prompts.js +14 -0
  43. package/dist/agents/codex/prompts.js.map +1 -0
  44. package/dist/agents/codex/reading.d.ts +2 -0
  45. package/dist/agents/codex/reading.js +22 -0
  46. package/dist/agents/codex/reading.js.map +1 -0
  47. package/dist/agents/generic/index.d.ts +3 -0
  48. package/dist/agents/generic/index.js +9 -0
  49. package/dist/agents/generic/index.js.map +1 -0
  50. package/dist/agents/generic/prompts.d.ts +2 -0
  51. package/dist/agents/generic/prompts.js +10 -0
  52. package/dist/agents/generic/prompts.js.map +1 -0
  53. package/dist/agents/grok/actionBox.d.ts +13 -0
  54. package/dist/agents/grok/actionBox.js +127 -0
  55. package/dist/agents/grok/actionBox.js.map +1 -0
  56. package/dist/agents/grok/index.d.ts +2 -0
  57. package/dist/agents/grok/index.js +20 -0
  58. package/dist/agents/grok/index.js.map +1 -0
  59. package/dist/agents/grok/nudge.d.ts +2 -0
  60. package/dist/agents/grok/nudge.js +81 -0
  61. package/dist/agents/grok/nudge.js.map +1 -0
  62. package/dist/agents/grok/prompts.d.ts +4 -0
  63. package/dist/agents/grok/prompts.js +89 -0
  64. package/dist/agents/grok/prompts.js.map +1 -0
  65. package/dist/agents/grok/reading.d.ts +2 -0
  66. package/dist/agents/grok/reading.js +49 -0
  67. package/dist/agents/grok/reading.js.map +1 -0
  68. package/dist/agents/grok/readingRules.d.ts +2 -0
  69. package/dist/agents/grok/readingRules.js +44 -0
  70. package/dist/agents/grok/readingRules.js.map +1 -0
  71. package/dist/agents/hermes/frame.d.ts +25 -0
  72. package/dist/agents/hermes/frame.js +145 -0
  73. package/dist/agents/hermes/frame.js.map +1 -0
  74. package/dist/agents/hermes/index.d.ts +2 -0
  75. package/dist/agents/hermes/index.js +20 -0
  76. package/dist/agents/hermes/index.js.map +1 -0
  77. package/dist/agents/hermes/nudge.d.ts +5 -0
  78. package/dist/agents/hermes/nudge.js +76 -0
  79. package/dist/agents/hermes/nudge.js.map +1 -0
  80. package/dist/agents/hermes/prompts.d.ts +7 -0
  81. package/dist/agents/hermes/prompts.js +101 -0
  82. package/dist/agents/hermes/prompts.js.map +1 -0
  83. package/dist/agents/hermes/reading.d.ts +7 -0
  84. package/dist/agents/hermes/reading.js +102 -0
  85. package/dist/agents/hermes/reading.js.map +1 -0
  86. package/dist/agents/index.d.ts +28 -0
  87. package/dist/agents/index.js +48 -0
  88. package/dist/agents/index.js.map +1 -0
  89. package/dist/agents/input.d.ts +2 -0
  90. package/dist/agents/input.js +9 -0
  91. package/dist/agents/input.js.map +1 -0
  92. package/dist/agents/mimo/index.d.ts +2 -0
  93. package/dist/agents/mimo/index.js +13 -0
  94. package/dist/agents/mimo/index.js.map +1 -0
  95. package/dist/agents/mimo/nudge.d.ts +3 -0
  96. package/dist/agents/mimo/nudge.js +60 -0
  97. package/dist/agents/mimo/nudge.js.map +1 -0
  98. package/dist/agents/mimo/prompts.d.ts +2 -0
  99. package/dist/agents/mimo/prompts.js +40 -0
  100. package/dist/agents/mimo/prompts.js.map +1 -0
  101. package/dist/agents/mimo/reading.d.ts +2 -0
  102. package/dist/agents/mimo/reading.js +31 -0
  103. package/dist/agents/mimo/reading.js.map +1 -0
  104. package/dist/agents/mimo/readingRules.d.ts +2 -0
  105. package/dist/agents/mimo/readingRules.js +79 -0
  106. package/dist/agents/mimo/readingRules.js.map +1 -0
  107. package/dist/agents/mimo/stalls.d.ts +2 -0
  108. package/dist/agents/mimo/stalls.js +81 -0
  109. package/dist/agents/mimo/stalls.js.map +1 -0
  110. package/dist/agents/muse/index.d.ts +2 -0
  111. package/dist/agents/muse/index.js +20 -0
  112. package/dist/agents/muse/index.js.map +1 -0
  113. package/dist/agents/muse/input.d.ts +3 -0
  114. package/dist/agents/muse/input.js +7 -0
  115. package/dist/agents/muse/input.js.map +1 -0
  116. package/dist/agents/muse/nudge.d.ts +2 -0
  117. package/dist/agents/muse/nudge.js +33 -0
  118. package/dist/agents/muse/nudge.js.map +1 -0
  119. package/dist/agents/muse/prompts.d.ts +14 -0
  120. package/dist/agents/muse/prompts.js +132 -0
  121. package/dist/agents/muse/prompts.js.map +1 -0
  122. package/dist/agents/muse/reading.d.ts +2 -0
  123. package/dist/agents/muse/reading.js +33 -0
  124. package/dist/agents/muse/reading.js.map +1 -0
  125. package/dist/agents/muse/readingRules.d.ts +2 -0
  126. package/dist/agents/muse/readingRules.js +49 -0
  127. package/dist/agents/muse/readingRules.js.map +1 -0
  128. package/dist/agents/nudgeReading.d.ts +74 -0
  129. package/dist/agents/nudgeReading.js +252 -0
  130. package/dist/agents/nudgeReading.js.map +1 -0
  131. package/dist/agents/opencode/index.d.ts +2 -0
  132. package/dist/agents/opencode/index.js +21 -0
  133. package/dist/agents/opencode/index.js.map +1 -0
  134. package/dist/agents/opencode/nudge.d.ts +6 -0
  135. package/dist/agents/opencode/nudge.js +189 -0
  136. package/dist/agents/opencode/nudge.js.map +1 -0
  137. package/dist/agents/opencode/prompts.d.ts +6 -0
  138. package/dist/agents/opencode/prompts.js +198 -0
  139. package/dist/agents/opencode/prompts.js.map +1 -0
  140. package/dist/agents/opencode/reading.d.ts +2 -0
  141. package/dist/agents/opencode/reading.js +29 -0
  142. package/dist/agents/opencode/reading.js.map +1 -0
  143. package/dist/agents/opencode/stalls.d.ts +3 -0
  144. package/dist/agents/opencode/stalls.js +14 -0
  145. package/dist/agents/opencode/stalls.js.map +1 -0
  146. package/dist/agents/qoder/index.d.ts +2 -0
  147. package/dist/agents/qoder/index.js +12 -0
  148. package/dist/agents/qoder/index.js.map +1 -0
  149. package/dist/agents/qoder/nudge.d.ts +2 -0
  150. package/dist/agents/qoder/nudge.js +16 -0
  151. package/dist/agents/qoder/nudge.js.map +1 -0
  152. package/dist/agents/qoder/prompts.d.ts +2 -0
  153. package/dist/agents/qoder/prompts.js +6 -0
  154. package/dist/agents/qoder/prompts.js.map +1 -0
  155. package/dist/agents/qoder/reading.d.ts +2 -0
  156. package/dist/agents/qoder/reading.js +41 -0
  157. package/dist/agents/qoder/reading.js.map +1 -0
  158. package/dist/agents/types.d.ts +202 -0
  159. package/dist/agents/types.js +2 -0
  160. package/dist/agents/types.js.map +1 -0
  161. package/dist/cli/index.js +220 -21
  162. package/dist/cli/index.js.map +1 -1
  163. package/dist/client/http.d.ts +8 -2
  164. package/dist/client/http.js +179 -56
  165. package/dist/client/http.js.map +1 -1
  166. package/dist/core/cron.d.ts +6 -0
  167. package/dist/core/cron.js +63 -0
  168. package/dist/core/cron.js.map +1 -0
  169. package/dist/core/dialogs.d.ts +2 -4
  170. package/dist/core/dialogs.js +6 -12
  171. package/dist/core/dialogs.js.map +1 -1
  172. package/dist/core/environment.d.ts +6 -0
  173. package/dist/core/environment.js +35 -0
  174. package/dist/core/environment.js.map +1 -0
  175. package/dist/core/mailbox.d.ts +223 -0
  176. package/dist/core/mailbox.js +549 -0
  177. package/dist/core/mailbox.js.map +1 -0
  178. package/dist/core/manager.d.ts +4 -0
  179. package/dist/core/manager.js +40 -2
  180. package/dist/core/manager.js.map +1 -1
  181. package/dist/core/messageText.d.ts +2 -0
  182. package/dist/core/messageText.js +6 -0
  183. package/dist/core/messageText.js.map +1 -0
  184. package/dist/core/nudge.d.ts +37 -0
  185. package/dist/core/nudge.js +60 -0
  186. package/dist/core/nudge.js.map +1 -0
  187. package/dist/core/promptDetector.d.ts +14 -12
  188. package/dist/core/promptDetector.js +115 -363
  189. package/dist/core/promptDetector.js.map +1 -1
  190. package/dist/core/promptText.d.ts +1 -0
  191. package/dist/core/promptText.js +4 -0
  192. package/dist/core/promptText.js.map +1 -0
  193. package/dist/core/readiness.d.ts +14 -0
  194. package/dist/core/readiness.js +95 -0
  195. package/dist/core/readiness.js.map +1 -0
  196. package/dist/core/reasoning.d.ts +68 -7
  197. package/dist/core/reasoning.js +584 -328
  198. package/dist/core/reasoning.js.map +1 -1
  199. package/dist/core/renderer.d.ts +63 -3
  200. package/dist/core/renderer.js +370 -42
  201. package/dist/core/renderer.js.map +1 -1
  202. package/dist/core/selection.d.ts +1 -1
  203. package/dist/core/selection.js +3 -3
  204. package/dist/core/selection.js.map +1 -1
  205. package/dist/core/session.d.ts +175 -13
  206. package/dist/core/session.js +1030 -93
  207. package/dist/core/session.js.map +1 -1
  208. package/dist/core/stringWidth.d.ts +2 -0
  209. package/dist/core/stringWidth.js +13 -0
  210. package/dist/core/stringWidth.js.map +1 -0
  211. package/dist/core/types.d.ts +62 -4
  212. package/dist/core/types.js +41 -0
  213. package/dist/core/types.js.map +1 -1
  214. package/dist/core/waiter.d.ts +9 -2
  215. package/dist/core/waiter.js +35 -10
  216. package/dist/core/waiter.js.map +1 -1
  217. package/dist/daemon/audit.d.ts +1 -1
  218. package/dist/daemon/audit.js +2 -1
  219. package/dist/daemon/audit.js.map +1 -1
  220. package/dist/daemon/config.d.ts +44 -0
  221. package/dist/daemon/config.js +166 -4
  222. package/dist/daemon/config.js.map +1 -1
  223. package/dist/daemon/folderPicker.js +21 -2
  224. package/dist/daemon/folderPicker.js.map +1 -1
  225. package/dist/daemon/homeOwner.d.ts +15 -0
  226. package/dist/daemon/homeOwner.js +106 -0
  227. package/dist/daemon/homeOwner.js.map +1 -0
  228. package/dist/daemon/index.js +14 -6
  229. package/dist/daemon/index.js.map +1 -1
  230. package/dist/daemon/launchProfiles.d.ts +5 -0
  231. package/dist/daemon/launchProfiles.js +54 -48
  232. package/dist/daemon/launchProfiles.js.map +1 -1
  233. package/dist/daemon/logger.js +1 -1
  234. package/dist/daemon/logger.js.map +1 -1
  235. package/dist/daemon/nudgeScheduler.d.ts +21 -0
  236. package/dist/daemon/nudgeScheduler.js +61 -0
  237. package/dist/daemon/nudgeScheduler.js.map +1 -0
  238. package/dist/daemon/paths.d.ts +20 -16
  239. package/dist/daemon/paths.js +181 -50
  240. package/dist/daemon/paths.js.map +1 -1
  241. package/dist/daemon/restartHold.js +16 -15
  242. package/dist/daemon/restartHold.js.map +1 -1
  243. package/dist/daemon/restartSource.d.ts +7 -0
  244. package/dist/daemon/restartSource.js +89 -0
  245. package/dist/daemon/restartSource.js.map +1 -0
  246. package/dist/daemon/schedules.d.ts +57 -0
  247. package/dist/daemon/schedules.js +181 -0
  248. package/dist/daemon/schedules.js.map +1 -0
  249. package/dist/daemon/screenshot.d.ts +4 -1
  250. package/dist/daemon/screenshot.js +45 -7
  251. package/dist/daemon/screenshot.js.map +1 -1
  252. package/dist/daemon/server.d.ts +82 -13
  253. package/dist/daemon/server.js +1737 -330
  254. package/dist/daemon/server.js.map +1 -1
  255. package/dist/daemon/sessionFeed.js +4 -1
  256. package/dist/daemon/sessionFeed.js.map +1 -1
  257. package/dist/daemon/viewerLauncher.js +3 -2
  258. package/dist/daemon/viewerLauncher.js.map +1 -1
  259. package/dist/daemon/wrappedLaunch.d.ts +1 -0
  260. package/dist/daemon/wrappedLaunch.js +38 -0
  261. package/dist/daemon/wrappedLaunch.js.map +1 -0
  262. package/dist/daemon/wrappedStart.d.ts +13 -0
  263. package/dist/daemon/wrappedStart.js +113 -0
  264. package/dist/daemon/wrappedStart.js.map +1 -0
  265. package/dist/daemon/wrappedSupervisor.d.ts +1 -0
  266. package/dist/daemon/wrappedSupervisor.js +55 -0
  267. package/dist/daemon/wrappedSupervisor.js.map +1 -0
  268. package/dist/mcp/config.js +2 -1
  269. package/dist/mcp/config.js.map +1 -1
  270. package/dist/mcp/index.js +28 -2
  271. package/dist/mcp/index.js.map +1 -1
  272. package/dist/mcp/tools.d.ts +21 -1
  273. package/dist/mcp/tools.js +216 -29
  274. package/dist/mcp/tools.js.map +1 -1
  275. package/dist/viewer/dashboard-folders.js +7 -1
  276. package/dist/viewer/dashboard-layout.js +6 -52
  277. package/dist/viewer/dashboard.css +20 -4
  278. package/dist/viewer/dashboard.html +12 -3
  279. package/dist/viewer/dashboard.js +549 -382
  280. package/dist/viewer/pane.js +744 -136
  281. package/dist/viewer/viewer.css +1 -1
  282. package/dist/viewer/viewer.js +3 -1
  283. package/package.json +1 -1
@@ -37,262 +37,10 @@
37
37
  * The prompt detector times its dialog signatures the same way; its own
38
38
  * patterns are not timed.
39
39
  */
40
+ import { BUILT_IN_SIGNATURES, claimsProgram, moduleFor, programName, resolveAgent } from '../agents/index.js';
40
41
  import { RegexBudgetError, SET_ASIDE_MS, withRegexBudget } from './regexBudget.js';
41
42
  import { detectPrompt } from './promptDetector.js';
42
- // ---------------------------------------------------------------- built in
43
- const RULE = '^[─━]{10,}$';
44
- const RULE_INDENTED = '^\\s*[─━]{10,}';
45
- /**
46
- * Grok draws its permission box behind the same bar as its reasoning: a
47
- * question row (`> `), a command's rows (`│` starts one, `:` continues it)
48
- * and option rows (`1 (○)`). No Grok reasoning rule starts or continues on
49
- * them, so a permission box keeps every row of its own, whatever wording
50
- * its question is asked in.
51
- */
52
- const GROK_BOX_ROW = ' {2}(?:> |\\d+ \\([○•●]\\) |[│:])';
53
- /**
54
- * Built-in signatures. Each comment names the screens its fixtures come from.
55
- */
56
- export const BUILT_IN_SIGNATURES = [
57
- {
58
- // Claude Code 2.1.312, default view and the ctrl+o transcript: no
59
- // reasoning text is drawn in either, only a spinner line while the model
60
- // thinks ("✻ Pondering… (2s · thinking with xhigh effort)"). The answer
61
- // is a `●` in the text colour; tool calls get a grey or coloured `●`.
62
- name: 'claude',
63
- programs: ['claude'],
64
- measured: 'Claude Code 2.1.312',
65
- // The composer's prompt glyph is followed by a non-breaking space once
66
- // something is typed; the echo of a sent prompt by an ordinary one.
67
- composer: { text: '^❯( |\\xa0|$)' },
68
- typed: { text: '^❯[ \\xa0]\\S', word: { dim: false } },
69
- chrome: [{ text: RULE }, { text: '/effort\\s*$' }],
70
- frame: { text: RULE },
71
- busy: [{ text: '^[✻✽✶✢✳·*] \\S+…' }],
72
- turn: { text: '^❯ \\S' },
73
- answer: {
74
- start: { text: '^● ', lead: { fg: ['default', '#ffffff', '#000000'] } },
75
- continues: { text: '^ {2}' },
76
- },
77
- trailer: { text: '^✻ \\S' },
78
- requireTrailer: true,
79
- },
80
- {
81
- // Codex CLI 0.165.0 (GPT-6-Sol, high effort), default view. The answer is
82
- // a dim "•" with plain text after it; a tool group is a dim "•" with a
83
- // bold heading ("Explored"), a command a bold green "•" ("Ran"). While a
84
- // turn runs, "Working (Ns • esc to interrupt)" sits above the composer.
85
- name: 'codex',
86
- programs: ['codex'],
87
- measured: 'Codex CLI 0.165.0',
88
- composer: { text: '^› ' },
89
- // The placeholder ("Ask Codex to do anything") is dim; typed text is not.
90
- typed: { text: '^› \\S', word: { dim: false } },
91
- chrome: [{ text: 'esc to interrupt' }],
92
- busy: [{ text: 'esc to interrupt' }],
93
- turn: { text: '^› \\S' },
94
- answer: {
95
- start: { text: '^• ', lead: { dim: true }, word: { bold: false, italic: false } },
96
- continues: { text: '^ {2}(?!Worked for )[^\\s└]' },
97
- },
98
- trailer: { text: '^ {2}Worked for ' },
99
- requireTrailer: true,
100
- },
101
- {
102
- // Antigravity CLI 1.4.10 (Gemini 3.8 Flash, high effort). A summary of
103
- // the model's reasoning stays on screen as one line, "○ Thought for 4.2s
104
- // (Create the file, then…)"; while it works, the spinner's label is the
105
- // subject of what it is thinking about. "▸ Thought for 5s, 228 tokens"
106
- // carries no text. Tool calls are a green "●"; the answer is plain text
107
- // indented two spaces. While a turn runs, "esc to cancel" is under the
108
- // composer.
109
- name: 'agy',
110
- programs: ['agy', 'antigravity'],
111
- measured: 'Antigravity CLI 1.4.10',
112
- composer: { text: '^>' },
113
- chrome: [{ text: RULE_INDENTED }, { text: '^[⠀-⣿] {2}' }, { text: '^└ ' }],
114
- frame: { text: RULE_INDENTED },
115
- busy: [{ text: '^[⠀-⣿] {2}\\S' }, { text: '^esc to cancel' }],
116
- turn: { text: '^> \\S' },
117
- reasoning: [
118
- { start: { text: '^○ Thought for ' } },
119
- { start: { text: '^[⠀-⣿] {2}\\S' } },
120
- ],
121
- answer: {
122
- start: { text: '^ {2}\\S', lead: { fg: ['default', '#ffffff', '#000000', 'p7', 'p15'] } },
123
- continues: { text: '^ {2}\\S', lead: { fg: ['default', '#ffffff', '#000000', 'p7', 'p15'] } },
124
- upward: true,
125
- },
126
- },
127
- {
128
- // Grok Build 1.0.70 (grok-4.7, xhigh effort). While the model thinks, its
129
- // reasoning streams into a block behind a fading "│" bar, headed
130
- // "♦ Thinking…"; once it is done the block collapses to "♦ Thought for
131
- // Ns" with nothing under it. Messages and the answer are plain text
132
- // indented five spaces; tool work is a "♦" line ("♦ Edited primes.py, ran
133
- // 1 command"); "Worked for Ns" closes the turn. While a turn runs, a
134
- // spinner line ("| Thinking… 3.1s") sits above the composer's box.
135
- name: 'grok',
136
- programs: ['grok'],
137
- measured: 'Grok Build 1.0.70',
138
- composer: { text: '^ {2}│ >' },
139
- chrome: [{ text: '^ {2}╭' }, { text: '^ {3}[|/\\\\-] \\S' }, { text: '^ {3}\\S.*shift\\+tab', }],
140
- frame: { text: '^ {2}[╭╰]' },
141
- busy: [{ text: '^ {3}[|/\\\\-] .* \\d+(?:\\.\\d+)?s\\s*$' }, { text: '♦ Thinking…' }],
142
- turn: { text: '^ {5}> \\S' },
143
- reasoning: [
144
- {
145
- start: { text: '^ {2}│ {2}♦ Thinking' },
146
- continues: { text: `^ {2}│(?!${GROK_BOX_ROW})` },
147
- },
148
- // The spinner's label can be the model's own words about what it is
149
- // doing; it goes too, and the busy state still shows in the result.
150
- { start: { text: '^ {3}[|/\\\\-] \\S' } },
151
- // The bar on its own: the heading may have scrolled away.
152
- {
153
- start: { text: `^ {2}│(?!${GROK_BOX_ROW}) {2}\\S` },
154
- continues: { text: `^ {2}│(?!${GROK_BOX_ROW})` },
155
- },
156
- ],
157
- answer: {
158
- start: { text: '^ {5}(?!Worked for )[^\\s♦>]', lead: { fg: ['default', '#c8c8c8', '#ffffff', '#000000'] } },
159
- continues: { text: '^ {5}(?!Worked for )[^\\s♦>]', lead: { fg: ['default', '#c8c8c8', '#ffffff', '#000000'] } },
160
- upward: true,
161
- },
162
- trailer: { text: '^ {5}Worked for ' },
163
- requireTrailer: true,
164
- // A right-aligned time on each message row.
165
- tidy: ' {2,}\\d{1,2}:\\d{2}(?: ?[A-Za-z]{2})?\\s*$',
166
- },
167
- {
168
- // OpenCode 2.0.26 (GLM-5.3): no reasoning text is drawn. While the model
169
- // thinks it shows "⠇ Thinking"; afterwards a collapsed "+ Thought · Ns"
170
- // with nothing under it. The answer is plain paragraphs, in the same
171
- // colour and indent as any other text, closed by a footer naming the
172
- // agent, the model and the time ("Build · GLM-5.3 · 7.0s"). A sidebar
173
- // can share the rows on the right.
174
- name: 'opencode',
175
- programs: ['opencode'],
176
- measured: 'OpenCode 2.0.26',
177
- composer: { text: '^ {2}[┃╹]' },
178
- chrome: [{ text: '^ {2}┃' }, { text: '^\\s{60,}\\S' }],
179
- busy: [
180
- { text: '\\besc interrupt\\b' },
181
- { text: '^ {3,}[⠀-⣿] ' },
182
- { text: '^ {3,}\\+ Thought\\s*$' },
183
- ],
184
- turn: { text: '^ {2}┃ {2}\\S' },
185
- answer: {
186
- start: { text: '^ {5}[^\\s→+⠀-⣿]', lead: { fg: ['default', '#eeeeee', '#ffffff', '#000000'] } },
187
- continues: { text: '^ {5}[^\\s→+⠀-⣿]', lead: { fg: ['default', '#eeeeee', '#ffffff', '#000000'] } },
188
- upward: true,
189
- },
190
- trailer: { text: '^ {5}\\S+ · [^·]+ · \\d[\\d.]*m?s\\b' },
191
- requireTrailer: true,
192
- // The sidebar, on the same rows to the right.
193
- tidy: ' {20,}\\S.*$',
194
- },
195
- {
196
- // MiMoCode 0.1.16 (MiMo-V2.6-Pro), built from OpenCode: no reasoning text
197
- // is drawn. A collapsed "+ Thought: Ns" sits before each tool group and
198
- // before the answer; tool calls are boxes behind a bar drawn in the
199
- // background colour, the person's prompt and the composer behind one in
200
- // the agent's colour. The answer is plain paragraphs closed by "▣ Build ·
201
- // MiMo-V2.6-Pro · Ns", which carries no time while the turn runs. A side
202
- // panel on the right shares the rows (the session's title, context and
203
- // cost). The composer can hold a suggestion of its own after a turn.
204
- name: 'mimo',
205
- programs: ['mimo', 'mimocode', 'mimo-code'],
206
- measured: 'MiMoCode 0.1.16',
207
- composer: { text: '^ {2}[┃╹]' },
208
- chrome: [{ text: '^ {2}┃' }, { text: '^\\s{60,}\\S' }],
209
- busy: [
210
- { text: '\\besc (?:to )?interrupt\\b' },
211
- { text: '^ {5}▣ {2}\\S+ · [^·]+?\\s*(?:[⎘█].*)?$' },
212
- { text: '^ {3,}[⠀-⣿] ' },
213
- ],
214
- turn: { text: '^ {2}┃ {2}\\S', lead: { notFg: ['#0a0a0a'] } },
215
- answer: {
216
- start: { text: '^ {5}[^\\s→+⠀-⣿▣]' },
217
- continues: { text: '^ {5}[^\\s→+⠀-⣿▣]' },
218
- upward: true,
219
- },
220
- trailer: { text: '^ {5}▣ {2}\\S+ · [^·]+ · \\d' },
221
- requireTrailer: true,
222
- // The scrollbar, the side panel and the copy button, on the same rows.
223
- tidy: '\\s+[⎘█].*$',
224
- },
225
- {
226
- // Qoder CLI 1.1.80 (GLM-5.3), default thinking: a "Thinking" heading in
227
- // italics, then the reasoning behind a grey "│" bar in grey italics, as
228
- // the model works and after it has answered. Messages start with a "▪"
229
- // in the text colour, tool calls with a green one. While a turn runs, a
230
- // braille spinner line says "(esc to cancel, Ns)".
231
- name: 'qoder',
232
- programs: ['qodercli', 'qoder'],
233
- measured: 'Qoder CLI 1.1.80',
234
- composer: { text: '^ > ' },
235
- // The placeholder ("Type your message or @path/to/file") is grey; typed text is not.
236
- typed: { text: '^ > ', word: { notFg: ['#95958f'] } },
237
- chrome: [
238
- { text: RULE_INDENTED },
239
- { text: 'Shift\\+Tab' },
240
- { text: '\\? for shortcuts\\s*$' },
241
- { text: '\\(esc to cancel' },
242
- ],
243
- frame: { text: RULE_INDENTED },
244
- busy: [{ text: '\\(esc to cancel' }],
245
- turn: { text: '^ > \\S' },
246
- reasoning: [
247
- // The bar by its text alone: a code span or a table inside the
248
- // reasoning is drawn upright, and an upright line is still reasoning.
249
- {
250
- start: { text: '^ Thinking\\s*$', lead: { italic: true } },
251
- continues: { text: '^ │( |$)' },
252
- },
253
- // The same bar on its own: the heading may have scrolled away.
254
- {
255
- start: { text: '^ │ ' },
256
- continues: { text: '^ │( |$)' },
257
- },
258
- ],
259
- answer: {
260
- start: { text: '^ ▪ ', lead: { fg: ['default', '#eeeeeb', '#ffffff', '#000000'] } },
261
- continues: { text: '^ {3}[^\\s└│]' },
262
- },
263
- },
264
- {
265
- // Muse Code 1.4.14. A completed answer is a bold ◆ block. Tool calls
266
- // use a green ◆, and the live reasoning summary uses a grey ◆. The
267
- // composer is the last ❯ row followed only by chrome, with or without
268
- // typed text. Submitted turns sit above it. The Muse Code banner
269
- // sits above the transcript, and the status line ending in Launch overrides
270
- // sits below the composer. A
271
- // finished turn may have no Worked for line.
272
- name: 'muse',
273
- programs: ['muse', 'muse-bin-*'],
274
- measured: 'Muse Code 1.4.14',
275
- composer: { text: '^❯(?:\\s*$| \\S)' },
276
- typed: { text: '^❯ \\S', body: { dim: false, fg: ['#ccd3db'] } },
277
- chrome: [{ text: '^── Voice input \\(Alt\\+V to start\\)' }, { text: RULE }],
278
- frame: { text: RULE },
279
- busy: [
280
- { text: '^[◇◈◆] .*esc to interrupt\\)' },
281
- { text: '^└ (?:Hooks running|last event|Meta Model )' },
282
- ],
283
- turn: { text: '^❯ \\S' },
284
- reasoning: [{
285
- start: { text: '^◆ (?!Worked for )', lead: { fg: ['#676c74'] } },
286
- continues: { text: '^ {2}(?![◆◇◈❯])\\S', lead: { fg: ['#676c74', '#8a9098'] } },
287
- }],
288
- answer: {
289
- start: { text: '^◆ (?!Worked for |(?:Wrote|Ran command|Write)\\b)', lead: { bold: true, fg: ['#ccd3db'] } },
290
- continues: { text: '^ {2}\\S', lead: { fg: ['#ccd3db'] } },
291
- upward: true,
292
- },
293
- trailer: { text: '^◆ Worked for ' },
294
- },
295
- ];
43
+ export { BUILT_IN_SIGNATURES } from '../agents/index.js';
296
44
  export { SET_ASIDE_MS };
297
45
  /** Whether a signature is set aside for running past its time budget just now. */
298
46
  export function setAside(signature, now = Date.now()) {
@@ -472,20 +220,15 @@ export function useAgentSignatures(extra, onOverBudget = () => undefined) {
472
220
  reportOverBudget = onOverBudget;
473
221
  return problems;
474
222
  }
223
+ /** Resolve identity once, independently of a reading pattern's temporary time budget. */
224
+ export function resolveSessionAgent(agent, command) {
225
+ return resolveAgent(agent, command, active);
226
+ }
475
227
  /** The names `terminal_start`'s `agent` accepts. */
476
228
  export function agentNames() {
477
229
  return active.map((s) => s.name).sort();
478
230
  }
479
- /** A program's name from its start command: `C:\x\Claude.EXE` is `claude`. */
480
- export function programName(command) {
481
- const base = command.split(/[\\/]/).pop() ?? command;
482
- return base.replace(/\.(exe|cmd|bat|ps1|com)$/i, '').toLowerCase();
483
- }
484
- /** A versioned Muse executable has a changing suffix after muse-bin-. */
485
- function claimsProgram(signature, program) {
486
- return signature.programs.includes(program) ||
487
- (signature.programs.includes('muse-bin-*') && /^muse-bin-\d+(?:\.\d+)*(?:[-+][a-z0-9]+(?:[.-][a-z0-9]+)*)?$/.test(program));
488
- }
231
+ export { programName } from '../agents/index.js';
489
232
  /**
490
233
  * The agent a session runs as, by name: the one it was started as, or the one
491
234
  * whose programs include its start command. The signatures are compiled and
@@ -511,12 +254,16 @@ export function agentNameFor(agent, command, extra = []) {
511
254
  * The signature for a session: the agent it was started as, or the one whose
512
255
  * programs include its start command. Null when neither names one.
513
256
  */
514
- export function signatureFor(agent, command) {
257
+ export function signatureFor(agent, command = '') {
515
258
  if (agent !== undefined)
516
259
  return active.find((s) => s.name === agent && !setAside(s)) ?? null;
517
260
  const program = programName(command);
518
261
  return active.find((s) => !setAside(s) && claimsProgram(s, program)) ?? null;
519
262
  }
263
+ /** A fallback identity must not select a configured reading named generic. */
264
+ export function signatureForSession(session) {
265
+ return session.agentSource === 'fallback' ? null : signatureFor(session.agent);
266
+ }
520
267
  // ---------------------------------------------------------------- matching
521
268
  /** A row that holds nothing but whitespace and box drawing: border, not text. */
522
269
  const BORDER_ROW = /^[\s─-╿-]*$/u;
@@ -556,6 +303,11 @@ function lineFits(line, test) {
556
303
  return false;
557
304
  if (test.lead === undefined && test.body === undefined && test.word === undefined)
558
305
  return true;
306
+ if (test.lead !== undefined && test.body === undefined && test.word === undefined) {
307
+ const first = line.text.search(/\S/u);
308
+ const style = line.spans.find(span => span.from <= first && span.to > first);
309
+ return style !== undefined && styleFits(style, test.lead);
310
+ }
559
311
  const ink = inkStyles(line);
560
312
  if (ink.length === 0)
561
313
  return false;
@@ -631,32 +383,10 @@ function guarded(signature, body) {
631
383
  function composerAt(lines, signature) {
632
384
  for (let i = lines.length - 1; i >= 0; i--) {
633
385
  const candidate = lines[i];
634
- // A full-width rule above Muse's composer can leave its row marked as a
635
- // continuation. The voice bar still anchors that row as the composer.
636
- const wrappedMuseComposer = signature.name === 'muse' && candidate.wrapped === true &&
637
- signature.composer.text?.test(candidate.text) === true &&
638
- lines.slice(Math.max(0, i - 2), i).some((line) => /^── Voice input \(Alt\+V to start\)/.test(line.text));
639
- if (!lineFits(candidate, signature.composer) && !wrappedMuseComposer)
386
+ const composerRule = moduleFor(signature.name)?.readingRules?.composer;
387
+ if (!(composerRule === undefined ? lineFits(candidate, signature.composer) :
388
+ composerRule(lines, i, signature, readingContext)))
640
389
  continue;
641
- if (signature.name === 'muse') {
642
- let inComposerBody = true;
643
- const tailIsChrome = lines.slice(i + 1).every((line) => {
644
- if (line.text.trim() === '')
645
- return true;
646
- if (/^[─━]{10,}$/.test(line.text)) {
647
- inComposerBody = false;
648
- return true;
649
- }
650
- if (/· Launch overrides\s*$/.test(line.text))
651
- return true;
652
- // Muse indents later rows of a typed composer. Their text keeps the
653
- // ordinary foreground, unlike the grey hint or status line.
654
- return inComposerBody && /^ {2}\S/.test(line.text) &&
655
- inkStyles(line).every((style) => style.fg === '#ccd3db');
656
- });
657
- if (!tailIsChrome)
658
- continue;
659
- }
660
390
  // Reasoning is never drawn below the composer. A line with reasoning under
661
391
  // it is the echo of the person's prompt, taken for the composer while a
662
392
  // dialog stands in its place: no composer is found, so the filter reads
@@ -702,17 +432,20 @@ function enclosedByReasoning(lines, signature, first, last) {
702
432
  * stays reasoning too.
703
433
  */
704
434
  function claimedRows(lines, signature, prompt) {
705
- if (prompt === null)
435
+ if (prompt?.basis === 'question' && enclosedByReasoning(lines, signature, ...prompt.rows))
706
436
  return null;
707
- const [first, last] = prompt.rows;
708
- if (prompt.basis === 'question' && enclosedByReasoning(lines, signature, first, last))
437
+ const claim = moduleFor(signature.name)?.readingRules?.claimPromptRows?.(lines, prompt);
438
+ const bounds = prompt?.rows ?? claim;
439
+ if (!bounds)
709
440
  return null;
710
- let top = first;
711
- while (top > 0 && BORDER_ROW.test(lines[top - 1].text))
712
- top--;
713
- let bottom = last;
714
- while (bottom + 1 < lines.length && BORDER_ROW.test(lines[bottom + 1].text))
715
- bottom++;
441
+ const [first, last] = bounds;
442
+ let [top, bottom] = claim ?? bounds;
443
+ if (!claim) {
444
+ while (top > 0 && BORDER_ROW.test(lines[top - 1].text))
445
+ top--;
446
+ while (bottom + 1 < lines.length && BORDER_ROW.test(lines[bottom + 1].text))
447
+ bottom++;
448
+ }
716
449
  const rows = new Set();
717
450
  for (let i = top; i <= bottom; i++) {
718
451
  // A one-line reasoning summary drawn between the question and the last
@@ -735,6 +468,9 @@ function claimedRows(lines, signature, prompt) {
735
468
  }
736
469
  /** `[from, to)` ranges of reasoning above `limit`. */
737
470
  function reasoningRanges(lines, signature, limit, claimed) {
471
+ const framed = signature.builtIn && moduleFor(signature.name)?.readingRules?.hiddenRanges;
472
+ if (framed)
473
+ return framed(lines, limit);
738
474
  const ranges = [];
739
475
  let i = 0;
740
476
  // The parent may have left the retained scrollback. There is no safe way
@@ -778,7 +514,7 @@ export function hideReasoning(lines, signature, firstVisible = 0) {
778
514
  // no reasoning rules can hide nothing, so the detector is not run. Dialog
779
515
  // signatures are the only patterns the detector times (`dialogs.ts`); its
780
516
  // own patterns are not.
781
- const detected = signature.reasoning.length === 0 ? null : detectPrompt(lines.map((line) => line.wrapped ? '' : line.text).join('\n'));
517
+ const detected = signature.reasoning.length === 0 ? null : detectPrompt(lines.map((line) => line.wrapped ? '' : line.text).join('\n'), signature.name);
782
518
  return guarded(signature, () => {
783
519
  const claimed = claimedRows(lines, signature, detected);
784
520
  // Everything above the composer's own line, the chrome over it included:
@@ -838,11 +574,12 @@ export function resultRefusal(reason) {
838
574
  * reasoning block; nothing else is ever returned in its place.
839
575
  */
840
576
  export function latestResult(lines, signature) {
577
+ lines = moduleFor(signature.name)?.readingRules?.contentRegion?.(lines) ?? lines;
841
578
  const result = guarded(signature, () => {
842
579
  const composer = composerAt(lines, signature);
843
580
  if (composer === null) {
844
- const museBusy = signature.name === 'muse' && lines.some((line) => signature.busy.some((test) => lineFits(line, test)));
845
- return { found: false, reason: museBusy ? 'busy' : 'no-composer', status: [] };
581
+ const busy = moduleFor(signature.name)?.readingRules?.busyWithoutComposer === true && lines.some((line) => signature.busy.some((test) => lineFits(line, test)));
582
+ return { found: false, reason: busy ? 'busy' : 'no-composer', status: [] };
846
583
  }
847
584
  const status = lines
848
585
  .slice(composer.line + 1)
@@ -861,30 +598,8 @@ export function latestResult(lines, signature) {
861
598
  }
862
599
  // A spinner can be drawn in the latest turn or the chrome under it;
863
600
  // a stale copy in the scrollback above says nothing.
864
- const current = lines.slice(turnStart);
865
- if (signature.name !== 'muse' && signature.busy.some((test) => current.some((line) => lineFits(line, test)))) {
866
- return { found: false, reason: 'busy', status };
867
- }
868
- let lastBusy = -1;
869
- if (signature.name === 'muse') {
870
- for (let i = lines.length - 1; i >= turnStart; i--) {
871
- if (signature.busy.some((test) => lineFits(lines[i], test))) {
872
- lastBusy = i;
873
- break;
874
- }
875
- }
876
- }
877
- // Muse can retain an activity row above a finished answer. Only a later
878
- // answer before the composer makes that row historical.
879
- let museAnswerAfterBusy = false;
880
- if (signature.name === 'muse' && lastBusy >= 0) {
881
- const ranges = reasoningRanges(lines, signature, composer.chrome);
882
- const inReasoning = (i) => ranges.some(([from, to]) => i >= from && i < to);
883
- museAnswerAfterBusy = lines.slice(lastBusy + 1, composer.chrome).some((line, offset) => !inReasoning(lastBusy + 1 + offset) && lineFits(line, signature.answer.start));
884
- }
885
- if (lastBusy >= 0 && !museAnswerAfterBusy) {
601
+ if (turnBusy(lines, signature, turnStart, composer.chrome))
886
602
  return { found: false, reason: 'busy', status };
887
- }
888
603
  if (signature.typed !== undefined) {
889
604
  for (let i = composer.chrome; i <= composer.line; i++) {
890
605
  if (lineFits(lines[i], signature.typed))
@@ -893,8 +608,10 @@ export function latestResult(lines, signature) {
893
608
  }
894
609
  const ranges = reasoningRanges(lines, signature, composer.chrome);
895
610
  const inReasoning = (i) => ranges.some(([from, to]) => i >= from && i < to);
611
+ const floor = signature.builtIn ? moduleFor(signature.name)?.readingRules?.answerFloor?.(lines, composer.chrome) : undefined;
612
+ const answerFloor = Math.max(turnStart, floor ?? turnStart);
896
613
  let start = -1;
897
- for (let i = composer.chrome - 1; i >= turnStart; i--) {
614
+ for (let i = composer.chrome - 1; i >= answerFloor; i--) {
898
615
  if (!inReasoning(i) && lineFits(lines[i], signature.answer.start)) {
899
616
  start = i;
900
617
  break;
@@ -906,9 +623,13 @@ export function latestResult(lines, signature) {
906
623
  if (signature.answer.upward) {
907
624
  for (;;) {
908
625
  let above = start - 1;
909
- while (above >= turnStart && blank(lines[above], signature.tidy))
626
+ while (above >= answerFloor && blank(lines[above], signature.tidy))
627
+ above--;
628
+ // Judge the previous paragraph at its first physical row. Its last
629
+ // wrapped row cannot independently identify an answer.
630
+ while (above >= answerFloor && lines[above].wrapped && !inReasoning(above))
910
631
  above--;
911
- if (above < turnStart || inReasoning(above) || !lineFits(lines[above], signature.answer.start))
632
+ if (above < answerFloor || inReasoning(above) || !lineFits(lines[above], signature.answer.start))
912
633
  break;
913
634
  start = above;
914
635
  }
@@ -930,4 +651,539 @@ export function latestResult(lines, signature) {
930
651
  });
931
652
  return result ?? { found: false, reason: 'over-budget', status: [] };
932
653
  }
654
+ const readingContext = { matches: lineFits, ink: inkStyles, ranges: reasoningRanges };
655
+ /** Shared turn boundary and busy rules for result reading and stall detection. */
656
+ function turnBusy(lines, signature, turnStart, chrome) {
657
+ const rule = moduleFor(signature.name)?.readingRules?.busy;
658
+ return rule === undefined
659
+ ? signature.busy.some(test => lines.slice(turnStart).some(line => lineFits(line, test)))
660
+ : rule(lines, turnStart, chrome, signature, readingContext);
661
+ }
662
+ export const STALL_SETTLE_MS = 1000;
663
+ /** The same candidate must survive settling; input suppresses old refusal screens. */
664
+ export class StallTracker {
665
+ candidate = null;
666
+ since = 0;
667
+ suppressed = null;
668
+ state;
669
+ /** A candidate has been recognised and may still be settling. */
670
+ get tracking() { return this.candidate !== null; }
671
+ /** Includes a recognised candidate that has not yet settled. */
672
+ get reason() { return this.candidate?.reason ?? this.state?.reason; }
673
+ matchesBlock(candidate) {
674
+ return candidate !== null && this.candidate?.blockIdentity === candidate.blockIdentity;
675
+ }
676
+ /** Changed rendered content ends this observation, without undoing input suppression. */
677
+ invalidate() {
678
+ this.candidate = null;
679
+ this.state = undefined;
680
+ }
681
+ noteInput() {
682
+ if (this.reason === 'server-lost')
683
+ return;
684
+ this.suppressed = this.candidate?.blockIdentity ?? this.suppressed;
685
+ this.candidate = null;
686
+ this.state = undefined;
687
+ }
688
+ observe(candidate, now = Date.now()) {
689
+ // Discovery needs the complete user turn. Once established, its text is
690
+ // layout-sensitive: only the validated refusal and footer identify it.
691
+ // Input suppression uses that same block across user-text redraws.
692
+ if (this.state !== undefined && this.matchesBlock(candidate))
693
+ return this.state;
694
+ if (candidate !== null && 'inconclusive' in candidate) {
695
+ // Missing context cannot discover or finish settling a new refusal.
696
+ this.invalidate();
697
+ return undefined;
698
+ }
699
+ if (candidate === null)
700
+ this.suppressed = null;
701
+ if (candidate === null || candidate.blockIdentity === this.suppressed) {
702
+ this.candidate = null;
703
+ this.state = undefined;
704
+ return undefined;
705
+ }
706
+ if (this.candidate?.identity !== candidate.identity) {
707
+ this.candidate = candidate;
708
+ this.since = now;
709
+ this.state = undefined;
710
+ }
711
+ if (now - this.since >= STALL_SETTLE_MS) {
712
+ this.state ??= { reason: candidate.reason, description: candidate.description, since: new Date(this.since).toISOString() };
713
+ }
714
+ return this.state;
715
+ }
716
+ remaining(now = Date.now()) {
717
+ return this.candidate === null || this.state !== undefined ? null : Math.max(1, this.since + STALL_SETTLE_MS - now);
718
+ }
719
+ }
720
+ const compiledStalls = new WeakMap();
721
+ function stallTests(shape) {
722
+ let tests = compiledStalls.get(shape);
723
+ if (tests === undefined) {
724
+ tests = {
725
+ before: compileLine(shape.before, 'stall.before'),
726
+ rows: shape.rows.map(row => compileLine(row, 'stall.rows')),
727
+ footer: compileLine(shape.footer, 'stall.footer'),
728
+ composer: compileLine(shape.composer, 'stall.composer'),
729
+ composerStatus: shape.composerStatus === undefined ? undefined : compileLine(shape.composerStatus, 'stall.composerStatus'),
730
+ chrome: shape.chrome.map(row => compileLine(row, 'stall.chrome')),
731
+ idle: shape.idle.map(row => compileLine(row, 'stall.idle')),
732
+ idleClipped: shape.idleClipped === undefined ? undefined : compileLine(shape.idleClipped.row, 'stall.idleClipped'),
733
+ bottom: shape.bottom.map(row => compileLine(row, 'stall.bottom')),
734
+ };
735
+ compiledStalls.set(shape, tests);
736
+ }
737
+ return tests;
738
+ }
739
+ /** Cheap viewport comparison; cursor, styles and known controls are not output. */
740
+ function stallScreenFrame(lines, shapes) {
741
+ const framed = stallRegion(lines, shapes);
742
+ const composer = stallComposer(framed, shapes);
743
+ let footer = (composer?.chrome ?? 0) - 1;
744
+ while (footer >= 0 && blank(framed[footer]))
745
+ footer--;
746
+ const content = framed.map((row, index) => {
747
+ let line = row.text;
748
+ for (const shape of shapes) {
749
+ if (index === footer && shape.cosmetic !== undefined)
750
+ line = line.replace(shape.cosmetic, '$1');
751
+ }
752
+ return line.trimEnd();
753
+ }).join('\n').trimEnd();
754
+ return { content, footer: framed.length === lines.length ? footer : -1 };
755
+ }
756
+ export function stallScreenContent(lines, shapes) {
757
+ return stallScreenFrame(lines, shapes).content;
758
+ }
759
+ /** Cache physical semantic rows; a repaint usually changes only a control. */
760
+ export class StallScreenCache {
761
+ lines = [];
762
+ shapes;
763
+ footer = -1;
764
+ semantic = '';
765
+ content(lines, shapes) {
766
+ if (shapes === this.shapes && lines.length === this.lines.length) {
767
+ let changed = -1;
768
+ for (let i = 0; i < lines.length; i++) {
769
+ if (lines[i] === this.lines[i])
770
+ continue;
771
+ if (changed !== -1) {
772
+ changed = -2;
773
+ break;
774
+ }
775
+ changed = i;
776
+ }
777
+ if (changed === -1)
778
+ return this.semantic;
779
+ if (changed >= 0 && changed === this.footer) {
780
+ const normalise = (line) => {
781
+ for (const shape of shapes)
782
+ line = line.replace(shape.cosmetic ?? /$^/u, '$1');
783
+ return line.trimEnd();
784
+ };
785
+ // The composer, its gutter run and any panel dividers are unchanged.
786
+ // Only a control on the already framed footer may skip that walk.
787
+ // All other row changes, including a moved footer, re-establish it.
788
+ if (normalise(lines[changed]) === normalise(this.lines[changed])) {
789
+ this.lines[changed] = lines[changed];
790
+ return this.semantic;
791
+ }
792
+ }
793
+ }
794
+ const frame = stallScreenFrame(lines, shapes);
795
+ this.lines = [...lines];
796
+ this.shapes = shapes;
797
+ this.footer = frame.footer;
798
+ this.semantic = frame.content;
799
+ return this.semantic;
800
+ }
801
+ }
802
+ function stallRegion(lines, shapes) {
803
+ let rows = lines.map(line => typeof line === 'string' ? { text: line, spans: [] } : line);
804
+ const applied = new Set();
805
+ for (const shape of shapes) {
806
+ if (shape.contentRegion !== undefined && !applied.has(shape.contentRegion)) {
807
+ rows = shape.contentRegion(rows);
808
+ applied.add(shape.contentRegion);
809
+ }
810
+ }
811
+ return rows;
812
+ }
813
+ function stallComposer(lines, shapes, partial = false) {
814
+ for (let line = lines.length - 1; line >= 0; line--) {
815
+ const complete = shapes.some(shape => shape.overlay === undefined && lineFits(lines[line], stallTests(shape).composer));
816
+ // A native redraw may replace the closing edge with one gutter row. The
817
+ // independently styled mode row and preceding input gutter still establish
818
+ // ownership, but never prove a complete composer for discovery.
819
+ if (!complete && !(partial && line > 1 && shapes.some(shape => {
820
+ if (shape.overlay !== undefined)
821
+ return false;
822
+ const tests = stallTests(shape);
823
+ return tests.composerStatus !== undefined && lineFits(lines[line - 1], tests.composerStatus) &&
824
+ tests.chrome.some(test => lineFits(lines[line - 2], test)) &&
825
+ (blank(lines[line]) || tests.chrome.some(test => lineFits(lines[line], test)));
826
+ })))
827
+ continue;
828
+ let chrome = line;
829
+ // Use the owning module's reading walk, with no broad tidy expression.
830
+ while (chrome > 0 && (blank(lines[chrome - 1]) ||
831
+ shapes.some(shape => shape.overlay === undefined && stallTests(shape).chrome.some(test => {
832
+ const above = lines[chrome - 1];
833
+ // Unstyled rows serve only the cosmetic cache and suggestion hint.
834
+ // Validation and transcript ownership always supply gutter ink.
835
+ return lineFits(above, above.spans.length === 0 ? { text: test.text } : test);
836
+ }))))
837
+ chrome--;
838
+ return { line, chrome };
839
+ }
840
+ return null;
841
+ }
842
+ /**
843
+ * Cheap evidence of new transcript text, using the module's presentation rules.
844
+ * Text that could be idle chrome is left for styled validation, never accepted
845
+ * as proof of an idle composer here. The caller supplies joined terminal wraps.
846
+ */
847
+ export function stallTranscriptContent(lines, shapes, signature) {
848
+ const content = stallRegion(lines, shapes);
849
+ // The modal owns the busy screen beneath it. Its animated title is not new
850
+ // transcript output; loss of the modal is checked on the next frame.
851
+ if (shapes.some(shape => shape.overlay !== undefined && content.some(line => stallMarker(line.text, shape))))
852
+ return '';
853
+ const composer = stallComposer(content, shapes, true);
854
+ const omitted = new Set();
855
+ const limit = composer?.chrome ?? content.length;
856
+ let turnStart = 0;
857
+ if (signature?.turn !== undefined)
858
+ for (let i = limit - 1; i >= 0; i--) {
859
+ if (lineFits(content[i], signature.turn)) {
860
+ turnStart = i + 1;
861
+ break;
862
+ }
863
+ }
864
+ for (const shape of shapes) {
865
+ if (shape.overlay !== undefined)
866
+ continue;
867
+ const tests = stallTests(shape);
868
+ // Only the error-ink gutter run immediately before the completed footer
869
+ // owns these rows. The same words elsewhere remain transcript output.
870
+ let footer = limit - 1;
871
+ while (footer >= turnStart && blank(content[footer]))
872
+ footer--;
873
+ let end = footer;
874
+ let completed = false;
875
+ if (footer >= turnStart) {
876
+ const text = content[footer].text.replace(shape.cosmetic ?? /$^/u, '$1');
877
+ if (tests.footer.text?.test(text)) {
878
+ completed = true;
879
+ omitted.add(footer);
880
+ end--;
881
+ }
882
+ }
883
+ while (end >= turnStart && blank(content[end]))
884
+ end--;
885
+ let start = end;
886
+ const lead = tests.rows[0]?.lead;
887
+ while (start >= turnStart) {
888
+ const row = content[start];
889
+ if (row.text.trim() !== '' && !(lead !== undefined && lineFits(row, { text: signature?.chrome[0]?.text, lead })))
890
+ break;
891
+ start--;
892
+ }
893
+ if (start < end) {
894
+ for (let i = start + 1; i <= end; i++)
895
+ omitted.add(i);
896
+ // The gutter still owns its block when the footer is temporarily gone.
897
+ // Its introduction is the preceding paragraph, not a phrase elsewhere.
898
+ if (start >= turnStart)
899
+ omitted.add(start);
900
+ }
901
+ else if (completed && end >= turnStart && footer - end - 1 >= tests.rows.length &&
902
+ lineFits(content[end], tests.before)) {
903
+ // Erasure can leave the introduction above the now-empty error slots.
904
+ // The completed footer and those module-sized slots retain ownership;
905
+ // full validation still confirms the missing ink. A new paragraph after
906
+ // a surviving error block leaves that block in the comparison and clears.
907
+ omitted.add(end);
908
+ }
909
+ if (composer !== null) {
910
+ for (let i = composer.chrome; i <= composer.line; i++) {
911
+ const row = content[i];
912
+ // Suggestion ink belongs to the framed input row, including its
913
+ // terminal wraps. Physical-row text equality cannot establish that.
914
+ const presentation = tests.idle.some(test => test.body !== undefined &&
915
+ lineFits(row, { lead: test.lead, body: test.body }));
916
+ if (tests.idle.some(test => test.text?.test(row.text)) || presentation || blank(row))
917
+ omitted.add(i);
918
+ }
919
+ for (let n = 0; n < tests.bottom.length; n++) {
920
+ const i = composer.line + 1 + n;
921
+ if (content[i] !== undefined && lineFits(content[i], tests.bottom[n]))
922
+ omitted.add(i);
923
+ }
924
+ }
925
+ }
926
+ return content.slice(turnStart).filter((_, index) => !omitted.has(index + turnStart))
927
+ .map(line => line.text.trimEnd()).filter(text => text !== '').join('\n');
928
+ }
929
+ /** A clipped viewport cannot prove that a changed transcript is new output. */
930
+ export function stallTurnVisible(lines, shapes, signature) {
931
+ if (signature.turn === undefined)
932
+ return true;
933
+ const content = stallRegion(lines, shapes);
934
+ const limit = stallComposer(content, shapes, true)?.chrome ?? content.length;
935
+ return content.slice(0, limit).some(line => lineFits(line, signature.turn));
936
+ }
937
+ /** Reject ordinary screens before styled context and prompt detection. */
938
+ export function possibleStall(lines, signature) {
939
+ if (setAside(signature))
940
+ return false;
941
+ const shapes = moduleFor(signature.name)?.stalls;
942
+ // This hint uses only module-owned marker and closing-edge rules. No
943
+ // configured pattern runs here; full validation retains its regex budget.
944
+ if (!shapes?.some(shape => lines.some(line => stallMarker(line, shape))))
945
+ return false;
946
+ if (shapes.some(shape => shape.overlay !== undefined && lines.some(line => stallMarker(line, shape))))
947
+ return true;
948
+ // Busy rules run within the turn during validation. Testing the entire
949
+ // viewport here would also reject an ordinary user echo quoting a rule.
950
+ return shapes.some(shape => {
951
+ if (!lines.some(line => stallMarker(line, shape)))
952
+ return false;
953
+ // Stall closing edges are narrower than the reading composer's rule.
954
+ const test = stallTests(shape).composer;
955
+ return test.text !== undefined && lines.some(line => test.text.test(line));
956
+ });
957
+ }
958
+ function stallMarker(line, shape) {
959
+ const text = line.trimEnd();
960
+ return typeof shape.marker.text === 'string' ? text === shape.marker.text : shape.marker.text.test(text);
961
+ }
962
+ /** Keep the physical origin for visibility, but match soft wraps as one line. */
963
+ function logicalStallLines(physical, shapes) {
964
+ const lines = [];
965
+ const starts = [];
966
+ for (let i = 0; i < physical.length; i++) {
967
+ const row = physical[i];
968
+ const previous = lines.at(-1);
969
+ // A captured full-width MiMo footer makes xterm mark subsequent, separately
970
+ // painted interface rows as wraps. Their own styled anchors restore the
971
+ // boundaries; ordinary wrapped transcript text is still joined.
972
+ const frameAnchor = /^ {2}[┃╹]/u.test(row.text);
973
+ const footerAnchor = /^ {5}▣ {2}Build · /u.test(row.text);
974
+ const first = frameAnchor ? 2 : footerAnchor ? 5 : -1;
975
+ const firstInk = first < 0 ? undefined : row.spans.find(span => span.from <= first && span.to > first)?.fg;
976
+ const framed = frameAnchor && (firstInk === '#fb8147' || firstInk === '#ff8040');
977
+ const footer = footerAnchor && firstInk === '#fb8147';
978
+ const belowEdge = previous !== undefined &&
979
+ (/^ {2}╹▀+/u.test(previous.text) || shapes.some(shape => stallTests(shape).bottom.some(test => test.text?.test(previous.text)))) &&
980
+ shapes.some(shape => stallTests(shape).bottom.some(test => test.text?.test(row.text)));
981
+ const busyBelowFooter = previous !== undefined && /^ {5}▣ {2}Build · /u.test(previous.text) &&
982
+ /^ {3}esc (?:to )?interrupt\s*$/u.test(row.text);
983
+ const ownRow = shapes.length > 0 && (framed || footer || belowEdge || busyBelowFooter);
984
+ if (row.wrapped && previous !== undefined && !ownRow) {
985
+ const offset = previous.text.length + (physical[i - 1].wrapPadding ?? 0);
986
+ previous.text = previous.text.padEnd(offset) + row.text;
987
+ previous.spans.push(...row.spans.map(span => ({ ...span, from: span.from + offset, to: span.to + offset })));
988
+ }
989
+ else {
990
+ lines.push({ ...row, ...(ownRow ? { wrapped: false } : {}), spans: [...row.spans] });
991
+ starts.push(i);
992
+ }
993
+ }
994
+ return { lines, starts };
995
+ }
996
+ /** Discovery requires the complete live-turn context. */
997
+ export function detectStall(physical, signature, prompt, firstVisible = 0) {
998
+ const result = validateStall(physical, signature, prompt, firstVisible);
999
+ return result === null || 'inconclusive' in result ? null : result;
1000
+ }
1001
+ /** Validate the visible shape independently of whether the turn boundary is available. */
1002
+ export function validateStall(physical, signature, prompt, firstVisible = 0) {
1003
+ const signatures = moduleFor(signature.name)?.stalls;
1004
+ if (signatures === undefined || setAside(signature))
1005
+ return null;
1006
+ return guarded(signature, () => {
1007
+ for (const shape of signatures) {
1008
+ if (shape.overlay === undefined)
1009
+ continue;
1010
+ const candidate = validateOverlayStall(physical, shape, firstVisible);
1011
+ if (candidate !== null && (!prompt || candidate.reason === 'server-lost'))
1012
+ return candidate;
1013
+ }
1014
+ if (prompt)
1015
+ return null;
1016
+ if (signatures.every(shape => shape.overlay !== undefined))
1017
+ return null;
1018
+ const logical = logicalStallLines(physical, signatures);
1019
+ const lines = stallRegion(logical.lines, signatures);
1020
+ const starts = logical.starts;
1021
+ const composer = stallComposer(lines, signatures);
1022
+ if (composer === null || starts[composer.line] < firstVisible)
1023
+ return null;
1024
+ let turnStart = 0;
1025
+ for (let i = composer.chrome - 1; i >= 0; i--) {
1026
+ if (signature.turn !== undefined && lineFits(lines[i], signature.turn)) {
1027
+ turnStart = i + 1;
1028
+ break;
1029
+ }
1030
+ }
1031
+ let lastOutput = composer.chrome - 1;
1032
+ while (lastOutput >= turnStart && blank(lines[lastOutput]))
1033
+ lastOutput--;
1034
+ const completedFooter = lastOutput >= turnStart && signatures.some(shape => {
1035
+ const row = lines[lastOutput];
1036
+ return lineFits({ ...row, text: row.text.replace(shape.cosmetic ?? /$^/u, '$1') }, stallTests(shape).footer);
1037
+ });
1038
+ const busyInComposer = lines.slice(composer.chrome).some(line => signature.busy.some(test => lineFits(line, test)));
1039
+ if (turnBusy(lines, signature, turnStart, composer.chrome) && (!completedFooter || busyInComposer))
1040
+ return null;
1041
+ for (const shape of signatures) {
1042
+ if (shape.overlay !== undefined)
1043
+ continue;
1044
+ const tests = stallTests(shape);
1045
+ if (!lineFits(lines[composer.line], tests.composer))
1046
+ continue;
1047
+ if (lines.slice(composer.line + 1).some((line, index) => !blank(line) && (tests.bottom[index] === undefined || !lineFits(line, tests.bottom[index]))))
1048
+ continue;
1049
+ const rules = moduleFor(signature.name)?.readingRules;
1050
+ const rawInput = lines.slice(composer.chrome, composer.line + 1);
1051
+ const input = rules?.inputRegion?.(rawInput, rawInput.length - 1) ?? rawInput;
1052
+ const clipped = shape.idleClipped;
1053
+ const rightEdge = lines[composer.line].text.length - (clipped?.rightInset ?? 0);
1054
+ // A row cut off at the edge after a space renders without that space,
1055
+ // one cell short; it counts when the restored space completes the rule.
1056
+ const clippedAtEdge = (line) => tests.idleClipped !== undefined && ((line.text.length === rightEdge && lineFits(line, tests.idleClipped)) ||
1057
+ (line.text.length === rightEdge - 1 && lineFits({ ...line, text: `${line.text} ` }, tests.idleClipped)));
1058
+ if (input.some(line => !blank(line) && !tests.idle.some(test => lineFits(line, test)) && !clippedAtEdge(line)))
1059
+ continue;
1060
+ let end = composer.chrome - 1;
1061
+ while (end >= turnStart && blank(lines[end]))
1062
+ end--;
1063
+ const footer = end < turnStart ? undefined : { ...lines[end],
1064
+ text: lines[end].text.replace(shape.cosmetic ?? /$^/u, '$1') };
1065
+ if (footer === undefined || !lineFits(footer, tests.footer))
1066
+ continue;
1067
+ if (shape.clippedBody) {
1068
+ // A marker that has scrolled away cannot establish a new turn boundary.
1069
+ // Require the red block to run from the top of the available history
1070
+ // straight to the completed recovery footer.
1071
+ if (turnStart !== 0 || !lines[end].text.includes('↻ /recover'))
1072
+ continue;
1073
+ let top = end - 1;
1074
+ while (top >= 0 && blank(lines[top]))
1075
+ top--;
1076
+ let messages = 0;
1077
+ while (top >= 0 && /^ {2}┃(?: {3,}.*)?$/u.test(lines[top].text) &&
1078
+ lines[top].spans.some(span => span.from <= 2 && span.to > 2 && span.fg === '#fb7185' && span.bg === '#141414')) {
1079
+ if (lines[top].text.length > 3)
1080
+ messages++;
1081
+ top--;
1082
+ }
1083
+ if (top >= 0 || messages < 2 || !/^ {2}┃ {3,}.+/u.test(lines[0].text))
1084
+ continue;
1085
+ const block = lines.slice(0, end).map(line => line.text.trim().replace(/\s+/gu, ' ')).filter(Boolean);
1086
+ const blockIdentity = JSON.stringify([shape.reason, block, footer.text.trim()]);
1087
+ return { reason: shape.reason, description: shape.description, blockIdentity, identity: blockIdentity };
1088
+ }
1089
+ let row = end - 1;
1090
+ while (row >= turnStart && blank(lines[row]))
1091
+ row--;
1092
+ let matches = true;
1093
+ if (shape.flexibleMessage) {
1094
+ if (row < turnStart || !lineFits(lines[row], tests.rows[4]))
1095
+ matches = false;
1096
+ else {
1097
+ row--;
1098
+ let messages = 0;
1099
+ let startFound = false;
1100
+ for (let checked = 0; row >= turnStart && checked < 32; checked++, row--) {
1101
+ if (row >= turnStart + 2 && lineFits(lines[row], tests.rows[2]) &&
1102
+ lineFits(lines[row - 1], tests.rows[1]) && lineFits(lines[row - 2], tests.rows[0])) {
1103
+ row -= 3;
1104
+ startFound = true;
1105
+ break;
1106
+ }
1107
+ if (lineFits(lines[row], tests.rows[3])) {
1108
+ messages++;
1109
+ continue;
1110
+ }
1111
+ if (!lineFits(lines[row], tests.rows[2]))
1112
+ break;
1113
+ }
1114
+ if (!startFound || messages === 0)
1115
+ matches = false;
1116
+ }
1117
+ }
1118
+ else
1119
+ for (let n = tests.rows.length - 1; n >= 0; n--, row--) {
1120
+ if (row < turnStart || !lineFits(lines[row], tests.rows[n])) {
1121
+ matches = false;
1122
+ break;
1123
+ }
1124
+ }
1125
+ if (!matches)
1126
+ continue;
1127
+ const errorStart = row + 1;
1128
+ while (row >= turnStart && blank(lines[row]))
1129
+ row--;
1130
+ const hasBefore = row >= turnStart && lineFits(lines[row], tests.before);
1131
+ if (!hasBefore && !shape.beforeOptional)
1132
+ continue;
1133
+ const blockStart = hasBefore ? row : errorStart;
1134
+ const live = rules?.liveContent?.(lines, turnStart, blockStart, readingContext);
1135
+ if (live !== true && live !== 'inconclusive')
1136
+ continue;
1137
+ // The same semantic identity drives both settlement and suppression.
1138
+ // Styles prove the shape above, but do not identify an occurrence.
1139
+ const semantic = (line) => {
1140
+ const text = line.text;
1141
+ return (line === lines[end] ? footer.text : text).trim().replace(/\s+/gu, ' ');
1142
+ };
1143
+ const block = lines.slice(blockStart, end + 1).map(semantic).filter(Boolean);
1144
+ const blockIdentity = JSON.stringify([shape.reason, block]);
1145
+ if (live === 'inconclusive' && !(firstVisible === 0 && lines[0]?.text.startsWith(' ┃') &&
1146
+ inkStyles(lines[0])[0]?.fg === '#0a0a0a'))
1147
+ return { inconclusive: true, blockIdentity };
1148
+ return { reason: shape.reason, description: shape.description, blockIdentity,
1149
+ identity: JSON.stringify([shape.reason, turnStart > 0 ? semantic(lines[turnStart - 1]) : '',
1150
+ block]) };
1151
+ }
1152
+ return null;
1153
+ });
1154
+ }
1155
+ function validateOverlayStall(lines, shape, firstVisible) {
1156
+ const overlay = shape.overlay;
1157
+ if (overlay === undefined || !(shape.marker.text instanceof RegExp))
1158
+ return null;
1159
+ const message = compileLine(overlay.message, 'stall.overlay.message').text;
1160
+ const styleAt = (line, column) => line.spans.find(span => span.from <= column && span.to > column);
1161
+ const visibleRows = lines.length - firstVisible;
1162
+ const visibleWidth = Math.max(...lines.slice(firstVisible).map(line => line.text.length));
1163
+ for (let i = firstVisible; i + 3 < lines.length; i++) {
1164
+ const title = lines[i];
1165
+ if (!shape.marker.text.test(title.text))
1166
+ continue;
1167
+ if (Math.abs(i - firstVisible - (Math.floor((visibleRows + 1) / 2) + overlay.centreOffset)) > 1)
1168
+ continue;
1169
+ const column = title.text.indexOf('Connection lost…') - 2;
1170
+ if (column < 18 || title.text[column - 2] !== ' ' || title.text[column - 1] !== ' ')
1171
+ continue;
1172
+ if (Math.abs(column - 2 - (Math.floor((visibleWidth + 1) / 2) - 24)) > 2)
1173
+ continue;
1174
+ const detail = lines[i + 2];
1175
+ // The dialog gutter can remain in the blank modal row; blank background
1176
+ // cells themselves have no spans after the renderer trims the row.
1177
+ if (!/^\s*(?:┃)?$/u.test(lines[i + 1].text) || !message?.test(detail.text.slice(column)))
1178
+ continue;
1179
+ const background = overlay.background;
1180
+ if (styleAt(title, column - 2)?.bg !== background || styleAt(title, column)?.fg !== shape.marker.fg[0] ||
1181
+ styleAt(title, column)?.bg !== background || styleAt(detail, column - 2)?.bg !== background ||
1182
+ styleAt(detail, column)?.fg !== '#808080' || styleAt(detail, column)?.bg !== background)
1183
+ continue;
1184
+ const identity = JSON.stringify([shape.reason, 'live-overlay']);
1185
+ return { reason: shape.reason, description: shape.description, identity, blockIdentity: identity };
1186
+ }
1187
+ return null;
1188
+ }
933
1189
  //# sourceMappingURL=reasoning.js.map