rookery-agent 0.3.1 → 0.4.1

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 (743) hide show
  1. package/README.md +9 -3
  2. package/docs/updates.md +12 -0
  3. package/package.json +1 -2
  4. package/packages/cli/dist/commands/chat.d.ts.map +1 -1
  5. package/packages/cli/dist/commands/chat.js +37 -74
  6. package/packages/cli/dist/commands/chat.js.map +1 -1
  7. package/packages/cli/dist/commands/config.js +4 -4
  8. package/packages/cli/dist/commands/config.js.map +1 -1
  9. package/packages/cli/dist/commands/doctor.d.ts.map +1 -1
  10. package/packages/cli/dist/commands/doctor.js +113 -91
  11. package/packages/cli/dist/commands/doctor.js.map +1 -1
  12. package/packages/cli/dist/commands/memory.d.ts.map +1 -1
  13. package/packages/cli/dist/commands/memory.js +28 -31
  14. package/packages/cli/dist/commands/memory.js.map +1 -1
  15. package/packages/cli/dist/commands/org.d.ts.map +1 -1
  16. package/packages/cli/dist/commands/org.js +36 -103
  17. package/packages/cli/dist/commands/org.js.map +1 -1
  18. package/packages/cli/dist/commands/serve.d.ts.map +1 -1
  19. package/packages/cli/dist/commands/serve.js +8 -6
  20. package/packages/cli/dist/commands/serve.js.map +1 -1
  21. package/packages/cli/dist/commands/sessions.d.ts.map +1 -1
  22. package/packages/cli/dist/commands/sessions.js +18 -17
  23. package/packages/cli/dist/commands/sessions.js.map +1 -1
  24. package/packages/cli/dist/commands/shared.d.ts +26 -5
  25. package/packages/cli/dist/commands/shared.d.ts.map +1 -1
  26. package/packages/cli/dist/commands/shared.js +85 -63
  27. package/packages/cli/dist/commands/shared.js.map +1 -1
  28. package/packages/cli/dist/commands/slash.d.ts +51 -0
  29. package/packages/cli/dist/commands/slash.d.ts.map +1 -0
  30. package/packages/cli/dist/commands/slash.js +110 -0
  31. package/packages/cli/dist/commands/slash.js.map +1 -0
  32. package/packages/cli/dist/commands/tasks.d.ts.map +1 -1
  33. package/packages/cli/dist/commands/tasks.js +74 -115
  34. package/packages/cli/dist/commands/tasks.js.map +1 -1
  35. package/packages/cli/dist/commands/tools.d.ts.map +1 -1
  36. package/packages/cli/dist/commands/tools.js +51 -34
  37. package/packages/cli/dist/commands/tools.js.map +1 -1
  38. package/packages/cli/dist/index.js +42 -52
  39. package/packages/cli/dist/index.js.map +1 -1
  40. package/packages/cli/dist/repl.d.ts +1 -25
  41. package/packages/cli/dist/repl.d.ts.map +1 -1
  42. package/packages/cli/dist/repl.js +165 -726
  43. package/packages/cli/dist/repl.js.map +1 -1
  44. package/packages/cli/dist/replInput.d.ts +33 -0
  45. package/packages/cli/dist/replInput.d.ts.map +1 -0
  46. package/packages/cli/dist/replInput.js +97 -0
  47. package/packages/cli/dist/replInput.js.map +1 -0
  48. package/packages/cli/dist/replOutput.d.ts +11 -0
  49. package/packages/cli/dist/replOutput.d.ts.map +1 -0
  50. package/packages/cli/dist/replOutput.js +22 -0
  51. package/packages/cli/dist/replOutput.js.map +1 -0
  52. package/packages/cli/dist/replQuestions.d.ts +32 -0
  53. package/packages/cli/dist/replQuestions.d.ts.map +1 -0
  54. package/packages/cli/dist/replQuestions.js +122 -0
  55. package/packages/cli/dist/replQuestions.js.map +1 -0
  56. package/packages/cli/dist/replSlash.d.ts +24 -0
  57. package/packages/cli/dist/replSlash.d.ts.map +1 -0
  58. package/packages/cli/dist/replSlash.js +311 -0
  59. package/packages/cli/dist/replSlash.js.map +1 -0
  60. package/packages/cli/dist/replState.d.ts +56 -0
  61. package/packages/cli/dist/replState.d.ts.map +1 -0
  62. package/packages/cli/dist/replState.js +89 -0
  63. package/packages/cli/dist/replState.js.map +1 -0
  64. package/packages/cli/dist/tui/App.d.ts +7 -24
  65. package/packages/cli/dist/tui/App.d.ts.map +1 -1
  66. package/packages/cli/dist/tui/App.js +139 -513
  67. package/packages/cli/dist/tui/App.js.map +1 -1
  68. package/packages/cli/dist/tui/LiveRegion.d.ts +16 -0
  69. package/packages/cli/dist/tui/LiveRegion.d.ts.map +1 -0
  70. package/packages/cli/dist/tui/LiveRegion.js +37 -0
  71. package/packages/cli/dist/tui/LiveRegion.js.map +1 -0
  72. package/packages/cli/dist/tui/boot.d.ts +34 -0
  73. package/packages/cli/dist/tui/boot.d.ts.map +1 -0
  74. package/packages/cli/dist/tui/boot.js +133 -0
  75. package/packages/cli/dist/tui/boot.js.map +1 -0
  76. package/packages/cli/dist/tui/commands.d.ts +3 -4
  77. package/packages/cli/dist/tui/commands.d.ts.map +1 -1
  78. package/packages/cli/dist/tui/commands.js +339 -405
  79. package/packages/cli/dist/tui/commands.js.map +1 -1
  80. package/packages/cli/dist/tui/components/ActivityLine.d.ts +1 -1
  81. package/packages/cli/dist/tui/components/ActivityLine.d.ts.map +1 -1
  82. package/packages/cli/dist/tui/components/ActivityLine.js +2 -2
  83. package/packages/cli/dist/tui/components/ActivityLine.js.map +1 -1
  84. package/packages/cli/dist/tui/components/AssignmentsView.d.ts.map +1 -1
  85. package/packages/cli/dist/tui/components/AssignmentsView.js +34 -20
  86. package/packages/cli/dist/tui/components/AssignmentsView.js.map +1 -1
  87. package/packages/cli/dist/tui/components/Logo.d.ts +3 -19
  88. package/packages/cli/dist/tui/components/Logo.d.ts.map +1 -1
  89. package/packages/cli/dist/tui/components/Logo.js +13 -13
  90. package/packages/cli/dist/tui/components/Logo.js.map +1 -1
  91. package/packages/cli/dist/tui/components/Markdown.d.ts.map +1 -1
  92. package/packages/cli/dist/tui/components/Markdown.js +201 -146
  93. package/packages/cli/dist/tui/components/Markdown.js.map +1 -1
  94. package/packages/cli/dist/tui/components/QuestionView.d.ts +0 -2
  95. package/packages/cli/dist/tui/components/QuestionView.d.ts.map +1 -1
  96. package/packages/cli/dist/tui/components/QuestionView.js +21 -12
  97. package/packages/cli/dist/tui/components/QuestionView.js.map +1 -1
  98. package/packages/cli/dist/tui/components/Scrollback.d.ts.map +1 -1
  99. package/packages/cli/dist/tui/components/Scrollback.js +6 -3
  100. package/packages/cli/dist/tui/components/Scrollback.js.map +1 -1
  101. package/packages/cli/dist/tui/components/SlashPalette.d.ts.map +1 -1
  102. package/packages/cli/dist/tui/components/SlashPalette.js +14 -9
  103. package/packages/cli/dist/tui/components/SlashPalette.js.map +1 -1
  104. package/packages/cli/dist/tui/components/StatusLine.d.ts.map +1 -1
  105. package/packages/cli/dist/tui/components/StatusLine.js +45 -22
  106. package/packages/cli/dist/tui/components/StatusLine.js.map +1 -1
  107. package/packages/cli/dist/tui/components/ToolGroup.d.ts.map +1 -1
  108. package/packages/cli/dist/tui/components/ToolGroup.js +12 -7
  109. package/packages/cli/dist/tui/components/ToolGroup.js.map +1 -1
  110. package/packages/cli/dist/tui/components/WatchView.d.ts.map +1 -1
  111. package/packages/cli/dist/tui/components/WatchView.js +28 -17
  112. package/packages/cli/dist/tui/components/WatchView.js.map +1 -1
  113. package/packages/cli/dist/tui/highlight.d.ts +0 -2
  114. package/packages/cli/dist/tui/highlight.d.ts.map +1 -1
  115. package/packages/cli/dist/tui/highlight.js +8 -6
  116. package/packages/cli/dist/tui/highlight.js.map +1 -1
  117. package/packages/cli/dist/tui/history.d.ts +30 -4
  118. package/packages/cli/dist/tui/history.d.ts.map +1 -1
  119. package/packages/cli/dist/tui/history.js +100 -75
  120. package/packages/cli/dist/tui/history.js.map +1 -1
  121. package/packages/cli/dist/tui/hooks/coalescer.d.ts +18 -0
  122. package/packages/cli/dist/tui/hooks/coalescer.d.ts.map +1 -0
  123. package/packages/cli/dist/tui/hooks/coalescer.js +36 -0
  124. package/packages/cli/dist/tui/hooks/coalescer.js.map +1 -0
  125. package/packages/cli/dist/tui/hooks/useColumns.d.ts +2 -7
  126. package/packages/cli/dist/tui/hooks/useColumns.d.ts.map +1 -1
  127. package/packages/cli/dist/tui/hooks/useColumns.js +6 -11
  128. package/packages/cli/dist/tui/hooks/useColumns.js.map +1 -1
  129. package/packages/cli/dist/tui/hooks/useHistory.d.ts +7 -4
  130. package/packages/cli/dist/tui/hooks/useHistory.d.ts.map +1 -1
  131. package/packages/cli/dist/tui/hooks/useHistory.js +21 -18
  132. package/packages/cli/dist/tui/hooks/useHistory.js.map +1 -1
  133. package/packages/cli/dist/tui/hooks/usePrompt.d.ts +27 -0
  134. package/packages/cli/dist/tui/hooks/usePrompt.d.ts.map +1 -0
  135. package/packages/cli/dist/tui/hooks/usePrompt.js +169 -0
  136. package/packages/cli/dist/tui/hooks/usePrompt.js.map +1 -0
  137. package/packages/cli/dist/tui/hooks/useQuestion.d.ts +23 -0
  138. package/packages/cli/dist/tui/hooks/useQuestion.d.ts.map +1 -0
  139. package/packages/cli/dist/tui/hooks/useQuestion.js +43 -0
  140. package/packages/cli/dist/tui/hooks/useQuestion.js.map +1 -0
  141. package/packages/cli/dist/tui/hooks/useScrollback.d.ts +18 -0
  142. package/packages/cli/dist/tui/hooks/useScrollback.d.ts.map +1 -0
  143. package/packages/cli/dist/tui/hooks/useScrollback.js +29 -0
  144. package/packages/cli/dist/tui/hooks/useScrollback.js.map +1 -0
  145. package/packages/cli/dist/tui/hooks/useSession.d.ts +25 -0
  146. package/packages/cli/dist/tui/hooks/useSession.d.ts.map +1 -0
  147. package/packages/cli/dist/tui/hooks/useSession.js +36 -0
  148. package/packages/cli/dist/tui/hooks/useSession.js.map +1 -0
  149. package/packages/cli/dist/tui/hooks/useSlash.d.ts +0 -2
  150. package/packages/cli/dist/tui/hooks/useSlash.d.ts.map +1 -1
  151. package/packages/cli/dist/tui/hooks/useSlash.js +0 -1
  152. package/packages/cli/dist/tui/hooks/useSlash.js.map +1 -1
  153. package/packages/cli/dist/tui/hooks/useSpeech.d.ts +19 -0
  154. package/packages/cli/dist/tui/hooks/useSpeech.d.ts.map +1 -0
  155. package/packages/cli/dist/tui/hooks/useSpeech.js +33 -0
  156. package/packages/cli/dist/tui/hooks/useSpeech.js.map +1 -0
  157. package/packages/cli/dist/tui/hooks/useTicker.d.ts +13 -0
  158. package/packages/cli/dist/tui/hooks/useTicker.d.ts.map +1 -0
  159. package/packages/cli/dist/tui/hooks/useTicker.js +24 -0
  160. package/packages/cli/dist/tui/hooks/useTicker.js.map +1 -0
  161. package/packages/cli/dist/tui/hooks/useTurn.d.ts +4 -4
  162. package/packages/cli/dist/tui/hooks/useTurn.d.ts.map +1 -1
  163. package/packages/cli/dist/tui/hooks/useTurn.js +167 -289
  164. package/packages/cli/dist/tui/hooks/useTurn.js.map +1 -1
  165. package/packages/cli/dist/tui/hooks/useWatch.d.ts.map +1 -1
  166. package/packages/cli/dist/tui/hooks/useWatch.js +15 -48
  167. package/packages/cli/dist/tui/hooks/useWatch.js.map +1 -1
  168. package/packages/cli/dist/tui/inkTheme.d.ts.map +1 -1
  169. package/packages/cli/dist/tui/inkTheme.js +9 -11
  170. package/packages/cli/dist/tui/inkTheme.js.map +1 -1
  171. package/packages/cli/dist/tui/theme.d.ts +7 -13
  172. package/packages/cli/dist/tui/theme.d.ts.map +1 -1
  173. package/packages/cli/dist/tui/theme.js +18 -15
  174. package/packages/cli/dist/tui/theme.js.map +1 -1
  175. package/packages/cli/dist/tui/types.d.ts +10 -23
  176. package/packages/cli/dist/tui/types.d.ts.map +1 -1
  177. package/packages/cli/dist/tui/types.js +13 -31
  178. package/packages/cli/dist/tui/types.js.map +1 -1
  179. package/packages/cli/dist/ui/modelNames.d.ts.map +1 -1
  180. package/packages/cli/dist/ui/modelNames.js +45 -37
  181. package/packages/cli/dist/ui/modelNames.js.map +1 -1
  182. package/packages/cli/dist/ui/render.d.ts +32 -14
  183. package/packages/cli/dist/ui/render.d.ts.map +1 -1
  184. package/packages/cli/dist/ui/render.js +155 -98
  185. package/packages/cli/dist/ui/render.js.map +1 -1
  186. package/packages/cli/dist/ui/speech.d.ts +4 -7
  187. package/packages/cli/dist/ui/speech.d.ts.map +1 -1
  188. package/packages/cli/dist/ui/speech.js +37 -51
  189. package/packages/cli/dist/ui/speech.js.map +1 -1
  190. package/packages/cli/dist/ui/spinner.d.ts +1 -4
  191. package/packages/cli/dist/ui/spinner.d.ts.map +1 -1
  192. package/packages/cli/dist/ui/spinner.js +1 -12
  193. package/packages/cli/dist/ui/spinner.js.map +1 -1
  194. package/packages/cli/package.json +1 -1
  195. package/packages/core/dist/agents/persona.d.ts.map +1 -1
  196. package/packages/core/dist/agents/persona.js +27 -11
  197. package/packages/core/dist/agents/persona.js.map +1 -1
  198. package/packages/core/dist/assistant/board-watch.d.ts +72 -0
  199. package/packages/core/dist/assistant/board-watch.d.ts.map +1 -0
  200. package/packages/core/dist/assistant/board-watch.js +224 -0
  201. package/packages/core/dist/assistant/board-watch.js.map +1 -0
  202. package/packages/core/dist/assistant/chat-turn.d.ts +14 -0
  203. package/packages/core/dist/assistant/chat-turn.d.ts.map +1 -0
  204. package/packages/core/dist/assistant/chat-turn.js +159 -0
  205. package/packages/core/dist/assistant/chat-turn.js.map +1 -0
  206. package/packages/core/dist/assistant/dream-recorder.d.ts +74 -0
  207. package/packages/core/dist/assistant/dream-recorder.d.ts.map +1 -0
  208. package/packages/core/dist/assistant/dream-recorder.js +282 -0
  209. package/packages/core/dist/assistant/dream-recorder.js.map +1 -0
  210. package/packages/core/dist/assistant/headless-turn.d.ts +17 -0
  211. package/packages/core/dist/assistant/headless-turn.d.ts.map +1 -0
  212. package/packages/core/dist/assistant/headless-turn.js +330 -0
  213. package/packages/core/dist/assistant/headless-turn.js.map +1 -0
  214. package/packages/core/dist/assistant/journalled-turn.d.ts +39 -0
  215. package/packages/core/dist/assistant/journalled-turn.d.ts.map +1 -0
  216. package/packages/core/dist/assistant/journalled-turn.js +75 -0
  217. package/packages/core/dist/assistant/journalled-turn.js.map +1 -0
  218. package/packages/core/dist/assistant/memory-learning.d.ts +27 -0
  219. package/packages/core/dist/assistant/memory-learning.d.ts.map +1 -0
  220. package/packages/core/dist/assistant/memory-learning.js +82 -0
  221. package/packages/core/dist/assistant/memory-learning.js.map +1 -0
  222. package/packages/core/dist/assistant/promotion-notice.d.ts +14 -0
  223. package/packages/core/dist/assistant/promotion-notice.d.ts.map +1 -0
  224. package/packages/core/dist/assistant/promotion-notice.js +33 -0
  225. package/packages/core/dist/assistant/promotion-notice.js.map +1 -0
  226. package/packages/core/dist/assistant/scheduled-runs.d.ts +30 -0
  227. package/packages/core/dist/assistant/scheduled-runs.d.ts.map +1 -0
  228. package/packages/core/dist/assistant/scheduled-runs.js +184 -0
  229. package/packages/core/dist/assistant/scheduled-runs.js.map +1 -0
  230. package/packages/core/dist/assistant/sessions.d.ts +44 -0
  231. package/packages/core/dist/assistant/sessions.d.ts.map +1 -0
  232. package/packages/core/dist/assistant/sessions.js +75 -0
  233. package/packages/core/dist/assistant/sessions.js.map +1 -0
  234. package/packages/core/dist/assistant/terminal-turn.d.ts +18 -0
  235. package/packages/core/dist/assistant/terminal-turn.d.ts.map +1 -0
  236. package/packages/core/dist/assistant/terminal-turn.js +228 -0
  237. package/packages/core/dist/assistant/terminal-turn.js.map +1 -0
  238. package/packages/core/dist/assistant/terminals.d.ts +91 -0
  239. package/packages/core/dist/assistant/terminals.d.ts.map +1 -0
  240. package/packages/core/dist/assistant/terminals.js +266 -0
  241. package/packages/core/dist/assistant/terminals.js.map +1 -0
  242. package/packages/core/dist/assistant/turn-support.d.ts +109 -0
  243. package/packages/core/dist/assistant/turn-support.d.ts.map +1 -0
  244. package/packages/core/dist/assistant/turn-support.js +80 -0
  245. package/packages/core/dist/assistant/turn-support.js.map +1 -0
  246. package/packages/core/dist/assistant/turn-transcript.d.ts +44 -0
  247. package/packages/core/dist/assistant/turn-transcript.d.ts.map +1 -0
  248. package/packages/core/dist/assistant/turn-transcript.js +82 -0
  249. package/packages/core/dist/assistant/turn-transcript.js.map +1 -0
  250. package/packages/core/dist/assistant/types.d.ts +120 -0
  251. package/packages/core/dist/assistant/types.d.ts.map +1 -0
  252. package/packages/core/dist/assistant/types.js +2 -0
  253. package/packages/core/dist/assistant/types.js.map +1 -0
  254. package/packages/core/dist/computer/accessibility.d.ts.map +1 -1
  255. package/packages/core/dist/computer/accessibility.js +40 -35
  256. package/packages/core/dist/computer/accessibility.js.map +1 -1
  257. package/packages/core/dist/computer/mcp-server.js +426 -364
  258. package/packages/core/dist/computer/mcp-server.js.map +1 -1
  259. package/packages/core/dist/computer/powershell.d.ts.map +1 -1
  260. package/packages/core/dist/computer/powershell.js +25 -16
  261. package/packages/core/dist/computer/powershell.js.map +1 -1
  262. package/packages/core/dist/computer/screen-text.d.ts.map +1 -1
  263. package/packages/core/dist/computer/screen-text.js +54 -34
  264. package/packages/core/dist/computer/screen-text.js.map +1 -1
  265. package/packages/core/dist/computer/sketch.d.ts.map +1 -1
  266. package/packages/core/dist/computer/sketch.js +185 -128
  267. package/packages/core/dist/computer/sketch.js.map +1 -1
  268. package/packages/core/dist/computer/tools.d.ts +2 -0
  269. package/packages/core/dist/computer/tools.d.ts.map +1 -1
  270. package/packages/core/dist/computer/tools.js +31 -27
  271. package/packages/core/dist/computer/tools.js.map +1 -1
  272. package/packages/core/dist/computer/validation.d.ts +16 -16
  273. package/packages/core/dist/computer/validation.d.ts.map +1 -1
  274. package/packages/core/dist/computer/validation.js +28 -20
  275. package/packages/core/dist/computer/validation.js.map +1 -1
  276. package/packages/core/dist/config.d.ts +10 -1
  277. package/packages/core/dist/config.d.ts.map +1 -1
  278. package/packages/core/dist/config.js +81 -26
  279. package/packages/core/dist/config.js.map +1 -1
  280. package/packages/core/dist/cron/parse.d.ts.map +1 -1
  281. package/packages/core/dist/cron/parse.js +90 -77
  282. package/packages/core/dist/cron/parse.js.map +1 -1
  283. package/packages/core/dist/cron/scheduler.d.ts.map +1 -1
  284. package/packages/core/dist/cron/scheduler.js +99 -65
  285. package/packages/core/dist/cron/scheduler.js.map +1 -1
  286. package/packages/core/dist/cron/script.d.ts.map +1 -1
  287. package/packages/core/dist/cron/script.js +72 -42
  288. package/packages/core/dist/cron/script.js.map +1 -1
  289. package/packages/core/dist/external/claude-code.d.ts.map +1 -1
  290. package/packages/core/dist/external/claude-code.js +41 -28
  291. package/packages/core/dist/external/claude-code.js.map +1 -1
  292. package/packages/core/dist/external/discovery.d.ts.map +1 -1
  293. package/packages/core/dist/external/discovery.js +14 -11
  294. package/packages/core/dist/external/discovery.js.map +1 -1
  295. package/packages/core/dist/external/shared.d.ts +20 -0
  296. package/packages/core/dist/external/shared.d.ts.map +1 -1
  297. package/packages/core/dist/external/shared.js +97 -81
  298. package/packages/core/dist/external/shared.js.map +1 -1
  299. package/packages/core/dist/gateway/policy.d.ts.map +1 -1
  300. package/packages/core/dist/gateway/policy.js +5 -2
  301. package/packages/core/dist/gateway/policy.js.map +1 -1
  302. package/packages/core/dist/logger.d.ts.map +1 -1
  303. package/packages/core/dist/logger.js +11 -11
  304. package/packages/core/dist/logger.js.map +1 -1
  305. package/packages/core/dist/memory/db.d.ts.map +1 -1
  306. package/packages/core/dist/memory/db.js +175 -226
  307. package/packages/core/dist/memory/db.js.map +1 -1
  308. package/packages/core/dist/memory/dream/admission.d.ts +5 -0
  309. package/packages/core/dist/memory/dream/admission.d.ts.map +1 -1
  310. package/packages/core/dist/memory/dream/admission.js +8 -14
  311. package/packages/core/dist/memory/dream/admission.js.map +1 -1
  312. package/packages/core/dist/memory/dream/candidate.d.ts.map +1 -1
  313. package/packages/core/dist/memory/dream/candidate.js +119 -92
  314. package/packages/core/dist/memory/dream/candidate.js.map +1 -1
  315. package/packages/core/dist/memory/dream/evaluate.d.ts +13 -4
  316. package/packages/core/dist/memory/dream/evaluate.d.ts.map +1 -1
  317. package/packages/core/dist/memory/dream/evaluate.js +264 -288
  318. package/packages/core/dist/memory/dream/evaluate.js.map +1 -1
  319. package/packages/core/dist/memory/dream/frame.d.ts +6 -0
  320. package/packages/core/dist/memory/dream/frame.d.ts.map +1 -1
  321. package/packages/core/dist/memory/dream/frame.js +137 -91
  322. package/packages/core/dist/memory/dream/frame.js.map +1 -1
  323. package/packages/core/dist/memory/dream/label.d.ts.map +1 -1
  324. package/packages/core/dist/memory/dream/label.js +6 -9
  325. package/packages/core/dist/memory/dream/label.js.map +1 -1
  326. package/packages/core/dist/memory/dream/measure.d.ts +4 -0
  327. package/packages/core/dist/memory/dream/measure.d.ts.map +1 -1
  328. package/packages/core/dist/memory/dream/measure.js +13 -58
  329. package/packages/core/dist/memory/dream/measure.js.map +1 -1
  330. package/packages/core/dist/memory/dream/policy.d.ts.map +1 -1
  331. package/packages/core/dist/memory/dream/policy.js +4 -2
  332. package/packages/core/dist/memory/dream/policy.js.map +1 -1
  333. package/packages/core/dist/memory/dream/probe.d.ts +31 -4
  334. package/packages/core/dist/memory/dream/probe.d.ts.map +1 -1
  335. package/packages/core/dist/memory/dream/probe.js +290 -289
  336. package/packages/core/dist/memory/dream/probe.js.map +1 -1
  337. package/packages/core/dist/memory/dream/promote.d.ts.map +1 -1
  338. package/packages/core/dist/memory/dream/promote.js +10 -11
  339. package/packages/core/dist/memory/dream/promote.js.map +1 -1
  340. package/packages/core/dist/memory/dream/score.d.ts +9 -0
  341. package/packages/core/dist/memory/dream/score.d.ts.map +1 -1
  342. package/packages/core/dist/memory/dream/score.js +6 -7
  343. package/packages/core/dist/memory/dream/score.js.map +1 -1
  344. package/packages/core/dist/memory/dream/slots.d.ts.map +1 -1
  345. package/packages/core/dist/memory/dream/slots.js +0 -0
  346. package/packages/core/dist/memory/dream/slots.js.map +1 -1
  347. package/packages/core/dist/memory/dream/trajectory.d.ts.map +1 -1
  348. package/packages/core/dist/memory/dream/trajectory.js +76 -53
  349. package/packages/core/dist/memory/dream/trajectory.js.map +1 -1
  350. package/packages/core/dist/memory/dream/util.d.ts +44 -0
  351. package/packages/core/dist/memory/dream/util.d.ts.map +1 -0
  352. package/packages/core/dist/memory/dream/util.js +83 -0
  353. package/packages/core/dist/memory/dream/util.js.map +1 -0
  354. package/packages/core/dist/memory/extractor.d.ts.map +1 -1
  355. package/packages/core/dist/memory/extractor.js +67 -46
  356. package/packages/core/dist/memory/extractor.js.map +1 -1
  357. package/packages/core/dist/memory/gate.d.ts.map +1 -1
  358. package/packages/core/dist/memory/gate.js +55 -44
  359. package/packages/core/dist/memory/gate.js.map +1 -1
  360. package/packages/core/dist/memory/recall.d.ts +1 -1
  361. package/packages/core/dist/memory/recall.d.ts.map +1 -1
  362. package/packages/core/dist/memory/recall.js +55 -43
  363. package/packages/core/dist/memory/recall.js.map +1 -1
  364. package/packages/core/dist/memory/sleep-dream.d.ts +210 -0
  365. package/packages/core/dist/memory/sleep-dream.d.ts.map +1 -0
  366. package/packages/core/dist/memory/sleep-dream.js +1109 -0
  367. package/packages/core/dist/memory/sleep-dream.js.map +1 -0
  368. package/packages/core/dist/memory/sleep-frames.d.ts +40 -0
  369. package/packages/core/dist/memory/sleep-frames.d.ts.map +1 -0
  370. package/packages/core/dist/memory/sleep-frames.js +127 -0
  371. package/packages/core/dist/memory/sleep-frames.js.map +1 -0
  372. package/packages/core/dist/memory/sleep-limits.d.ts +18 -0
  373. package/packages/core/dist/memory/sleep-limits.d.ts.map +1 -0
  374. package/packages/core/dist/memory/sleep-limits.js +34 -0
  375. package/packages/core/dist/memory/sleep-limits.js.map +1 -0
  376. package/packages/core/dist/memory/sleep-model.d.ts +36 -0
  377. package/packages/core/dist/memory/sleep-model.d.ts.map +1 -0
  378. package/packages/core/dist/memory/sleep-model.js +80 -0
  379. package/packages/core/dist/memory/sleep-model.js.map +1 -0
  380. package/packages/core/dist/memory/sleep-policy.d.ts +19 -0
  381. package/packages/core/dist/memory/sleep-policy.d.ts.map +1 -0
  382. package/packages/core/dist/memory/sleep-policy.js +79 -0
  383. package/packages/core/dist/memory/sleep-policy.js.map +1 -0
  384. package/packages/core/dist/memory/sleep-prompts.d.ts +15 -0
  385. package/packages/core/dist/memory/sleep-prompts.d.ts.map +1 -0
  386. package/packages/core/dist/memory/sleep-prompts.js +212 -0
  387. package/packages/core/dist/memory/sleep-prompts.js.map +1 -0
  388. package/packages/core/dist/memory/sleep-report.d.ts +63 -0
  389. package/packages/core/dist/memory/sleep-report.d.ts.map +1 -0
  390. package/packages/core/dist/memory/sleep-report.js +97 -0
  391. package/packages/core/dist/memory/sleep-report.js.map +1 -0
  392. package/packages/core/dist/memory/sleep-verdicts.d.ts +77 -0
  393. package/packages/core/dist/memory/sleep-verdicts.d.ts.map +1 -0
  394. package/packages/core/dist/memory/sleep-verdicts.js +198 -0
  395. package/packages/core/dist/memory/sleep-verdicts.js.map +1 -0
  396. package/packages/core/dist/memory/sleep.d.ts +6 -61
  397. package/packages/core/dist/memory/sleep.d.ts.map +1 -1
  398. package/packages/core/dist/memory/sleep.js +1099 -2458
  399. package/packages/core/dist/memory/sleep.js.map +1 -1
  400. package/packages/core/dist/memory/store-rows.d.ts +43 -0
  401. package/packages/core/dist/memory/store-rows.d.ts.map +1 -0
  402. package/packages/core/dist/memory/store-rows.js +330 -0
  403. package/packages/core/dist/memory/store-rows.js.map +1 -0
  404. package/packages/core/dist/memory/store.d.ts +34 -20
  405. package/packages/core/dist/memory/store.d.ts.map +1 -1
  406. package/packages/core/dist/memory/store.js +634 -861
  407. package/packages/core/dist/memory/store.js.map +1 -1
  408. package/packages/core/dist/migration-cron.d.ts +2 -1
  409. package/packages/core/dist/migration-cron.d.ts.map +1 -1
  410. package/packages/core/dist/migration-cron.js +197 -154
  411. package/packages/core/dist/migration-cron.js.map +1 -1
  412. package/packages/core/dist/migration-scripts.d.ts +11 -3
  413. package/packages/core/dist/migration-scripts.d.ts.map +1 -1
  414. package/packages/core/dist/migration-scripts.js +81 -61
  415. package/packages/core/dist/migration-scripts.js.map +1 -1
  416. package/packages/core/dist/migration-shared.d.ts +9 -0
  417. package/packages/core/dist/migration-shared.d.ts.map +1 -0
  418. package/packages/core/dist/migration-shared.js +16 -0
  419. package/packages/core/dist/migration-shared.js.map +1 -0
  420. package/packages/core/dist/migration.d.ts.map +1 -1
  421. package/packages/core/dist/migration.js +150 -111
  422. package/packages/core/dist/migration.js.map +1 -1
  423. package/packages/core/dist/org/assignment-log.d.ts +28 -0
  424. package/packages/core/dist/org/assignment-log.d.ts.map +1 -0
  425. package/packages/core/dist/org/assignment-log.js +86 -0
  426. package/packages/core/dist/org/assignment-log.js.map +1 -0
  427. package/packages/core/dist/org/bridge.d.ts.map +1 -1
  428. package/packages/core/dist/org/bridge.js +32 -30
  429. package/packages/core/dist/org/bridge.js.map +1 -1
  430. package/packages/core/dist/org/controller.d.ts +18 -21
  431. package/packages/core/dist/org/controller.d.ts.map +1 -1
  432. package/packages/core/dist/org/controller.js +2042 -1848
  433. package/packages/core/dist/org/controller.js.map +1 -1
  434. package/packages/core/dist/org/json-reply.d.ts +6 -0
  435. package/packages/core/dist/org/json-reply.d.ts.map +1 -0
  436. package/packages/core/dist/org/json-reply.js +23 -0
  437. package/packages/core/dist/org/json-reply.js.map +1 -0
  438. package/packages/core/dist/org/mcp-bridge.js +34 -26
  439. package/packages/core/dist/org/mcp-bridge.js.map +1 -1
  440. package/packages/core/dist/org/planner.d.ts.map +1 -1
  441. package/packages/core/dist/org/planner.js +38 -42
  442. package/packages/core/dist/org/planner.js.map +1 -1
  443. package/packages/core/dist/org/project-mcp.d.ts.map +1 -1
  444. package/packages/core/dist/org/project-mcp.js +2 -5
  445. package/packages/core/dist/org/project-mcp.js.map +1 -1
  446. package/packages/core/dist/org/prompts.d.ts.map +1 -1
  447. package/packages/core/dist/org/prompts.js +176 -156
  448. package/packages/core/dist/org/prompts.js.map +1 -1
  449. package/packages/core/dist/org/questions.d.ts.map +1 -1
  450. package/packages/core/dist/org/questions.js +19 -14
  451. package/packages/core/dist/org/questions.js.map +1 -1
  452. package/packages/core/dist/org/review.d.ts.map +1 -1
  453. package/packages/core/dist/org/review.js +27 -43
  454. package/packages/core/dist/org/review.js.map +1 -1
  455. package/packages/core/dist/org/store.d.ts +19 -32
  456. package/packages/core/dist/org/store.d.ts.map +1 -1
  457. package/packages/core/dist/org/store.js +250 -206
  458. package/packages/core/dist/org/store.js.map +1 -1
  459. package/packages/core/dist/org/tool-args.d.ts +54 -0
  460. package/packages/core/dist/org/tool-args.d.ts.map +1 -0
  461. package/packages/core/dist/org/tool-args.js +104 -0
  462. package/packages/core/dist/org/tool-args.js.map +1 -0
  463. package/packages/core/dist/org/tools.d.ts.map +1 -1
  464. package/packages/core/dist/org/tools.js +238 -443
  465. package/packages/core/dist/org/tools.js.map +1 -1
  466. package/packages/core/dist/profile.d.ts.map +1 -1
  467. package/packages/core/dist/profile.js +114 -57
  468. package/packages/core/dist/profile.js.map +1 -1
  469. package/packages/core/dist/providers/catalogue.d.ts.map +1 -1
  470. package/packages/core/dist/providers/catalogue.js +89 -60
  471. package/packages/core/dist/providers/catalogue.js.map +1 -1
  472. package/packages/core/dist/providers/claude-code.d.ts.map +1 -1
  473. package/packages/core/dist/providers/claude-code.js +418 -357
  474. package/packages/core/dist/providers/claude-code.js.map +1 -1
  475. package/packages/core/dist/providers/claude-tui.d.ts +13 -9
  476. package/packages/core/dist/providers/claude-tui.d.ts.map +1 -1
  477. package/packages/core/dist/providers/claude-tui.js +568 -396
  478. package/packages/core/dist/providers/claude-tui.js.map +1 -1
  479. package/packages/core/dist/providers/codex-auth.d.ts +3 -0
  480. package/packages/core/dist/providers/codex-auth.d.ts.map +1 -1
  481. package/packages/core/dist/providers/codex-auth.js +9 -7
  482. package/packages/core/dist/providers/codex-auth.js.map +1 -1
  483. package/packages/core/dist/providers/codex-bridge.d.ts +24 -7
  484. package/packages/core/dist/providers/codex-bridge.d.ts.map +1 -1
  485. package/packages/core/dist/providers/codex-bridge.js +128 -168
  486. package/packages/core/dist/providers/codex-bridge.js.map +1 -1
  487. package/packages/core/dist/providers/codex-translate.d.ts.map +1 -1
  488. package/packages/core/dist/providers/codex-translate.js +195 -197
  489. package/packages/core/dist/providers/codex-translate.js.map +1 -1
  490. package/packages/core/dist/providers/loopback-server.d.ts +33 -0
  491. package/packages/core/dist/providers/loopback-server.d.ts.map +1 -0
  492. package/packages/core/dist/providers/loopback-server.js +104 -0
  493. package/packages/core/dist/providers/loopback-server.js.map +1 -0
  494. package/packages/core/dist/providers/model-gateway.d.ts +2 -4
  495. package/packages/core/dist/providers/model-gateway.d.ts.map +1 -1
  496. package/packages/core/dist/providers/model-gateway.js +39 -75
  497. package/packages/core/dist/providers/model-gateway.js.map +1 -1
  498. package/packages/core/dist/providers/process.d.ts.map +1 -1
  499. package/packages/core/dist/providers/process.js +32 -23
  500. package/packages/core/dist/providers/process.js.map +1 -1
  501. package/packages/core/dist/providers/provider-catalog.d.ts.map +1 -1
  502. package/packages/core/dist/providers/provider-catalog.js +21 -23
  503. package/packages/core/dist/providers/provider-catalog.js.map +1 -1
  504. package/packages/core/dist/providers/quota.d.ts.map +1 -1
  505. package/packages/core/dist/providers/quota.js +37 -37
  506. package/packages/core/dist/providers/quota.js.map +1 -1
  507. package/packages/core/dist/providers/registry.d.ts.map +1 -1
  508. package/packages/core/dist/providers/registry.js +3 -1
  509. package/packages/core/dist/providers/registry.js.map +1 -1
  510. package/packages/core/dist/providers/user-settings-guard.d.ts.map +1 -1
  511. package/packages/core/dist/providers/user-settings-guard.js +7 -2
  512. package/packages/core/dist/providers/user-settings-guard.js.map +1 -1
  513. package/packages/core/dist/runtime.d.ts +45 -158
  514. package/packages/core/dist/runtime.d.ts.map +1 -1
  515. package/packages/core/dist/runtime.js +184 -1701
  516. package/packages/core/dist/runtime.js.map +1 -1
  517. package/packages/core/dist/skills/import.d.ts.map +1 -1
  518. package/packages/core/dist/skills/import.js +52 -36
  519. package/packages/core/dist/skills/import.js.map +1 -1
  520. package/packages/core/dist/skills/shelf.d.ts +14 -0
  521. package/packages/core/dist/skills/shelf.d.ts.map +1 -1
  522. package/packages/core/dist/skills/shelf.js +2 -3
  523. package/packages/core/dist/skills/shelf.js.map +1 -1
  524. package/packages/core/dist/skills/store.d.ts +2 -0
  525. package/packages/core/dist/skills/store.d.ts.map +1 -1
  526. package/packages/core/dist/skills/store.js +17 -12
  527. package/packages/core/dist/skills/store.js.map +1 -1
  528. package/packages/core/dist/tools/catalog.d.ts +13 -0
  529. package/packages/core/dist/tools/catalog.d.ts.map +1 -1
  530. package/packages/core/dist/tools/catalog.js +20 -5
  531. package/packages/core/dist/tools/catalog.js.map +1 -1
  532. package/packages/core/dist/tools/hub.d.ts +4 -1
  533. package/packages/core/dist/tools/hub.d.ts.map +1 -1
  534. package/packages/core/dist/tools/hub.js +114 -83
  535. package/packages/core/dist/tools/hub.js.map +1 -1
  536. package/packages/core/dist/turns/journal.d.ts.map +1 -1
  537. package/packages/core/dist/turns/journal.js +12 -18
  538. package/packages/core/dist/turns/journal.js.map +1 -1
  539. package/packages/core/dist/types.d.ts +25 -3
  540. package/packages/core/dist/types.d.ts.map +1 -1
  541. package/packages/core/dist/types.js.map +1 -1
  542. package/packages/core/dist/util/blocks.d.ts.map +1 -1
  543. package/packages/core/dist/util/blocks.js +14 -22
  544. package/packages/core/dist/util/blocks.js.map +1 -1
  545. package/packages/core/dist/util/queue.d.ts +0 -2
  546. package/packages/core/dist/util/queue.d.ts.map +1 -1
  547. package/packages/core/dist/util/queue.js +0 -6
  548. package/packages/core/dist/util/queue.js.map +1 -1
  549. package/packages/core/package.json +1 -1
  550. package/packages/server/dist/auth.d.ts +27 -9
  551. package/packages/server/dist/auth.d.ts.map +1 -1
  552. package/packages/server/dist/auth.js +73 -15
  553. package/packages/server/dist/auth.js.map +1 -1
  554. package/packages/server/dist/env.d.ts.map +1 -1
  555. package/packages/server/dist/env.js +18 -15
  556. package/packages/server/dist/env.js.map +1 -1
  557. package/packages/server/dist/errors.d.ts +3 -0
  558. package/packages/server/dist/errors.d.ts.map +1 -0
  559. package/packages/server/dist/errors.js +5 -0
  560. package/packages/server/dist/errors.js.map +1 -0
  561. package/packages/server/dist/gateways/attachments.d.ts.map +1 -1
  562. package/packages/server/dist/gateways/attachments.js +38 -21
  563. package/packages/server/dist/gateways/attachments.js.map +1 -1
  564. package/packages/server/dist/gateways/markdown.d.ts.map +1 -1
  565. package/packages/server/dist/gateways/markdown.js +30 -12
  566. package/packages/server/dist/gateways/markdown.js.map +1 -1
  567. package/packages/server/dist/gateways/push.d.ts +6 -6
  568. package/packages/server/dist/gateways/push.d.ts.map +1 -1
  569. package/packages/server/dist/gateways/push.js +101 -74
  570. package/packages/server/dist/gateways/push.js.map +1 -1
  571. package/packages/server/dist/gateways/telegram-api.d.ts.map +1 -1
  572. package/packages/server/dist/gateways/telegram-api.js +61 -44
  573. package/packages/server/dist/gateways/telegram-api.js.map +1 -1
  574. package/packages/server/dist/gateways/telegram.d.ts +5 -0
  575. package/packages/server/dist/gateways/telegram.d.ts.map +1 -1
  576. package/packages/server/dist/gateways/telegram.js +985 -753
  577. package/packages/server/dist/gateways/telegram.js.map +1 -1
  578. package/packages/server/dist/gateways/threads.d.ts.map +1 -1
  579. package/packages/server/dist/gateways/threads.js +144 -130
  580. package/packages/server/dist/gateways/threads.js.map +1 -1
  581. package/packages/server/dist/listeners/imap.d.ts.map +1 -1
  582. package/packages/server/dist/listeners/imap.js +0 -0
  583. package/packages/server/dist/listeners/imap.js.map +1 -1
  584. package/packages/server/dist/listeners/registry.d.ts.map +1 -1
  585. package/packages/server/dist/listeners/registry.js +15 -15
  586. package/packages/server/dist/listeners/registry.js.map +1 -1
  587. package/packages/server/dist/main.js +3 -2
  588. package/packages/server/dist/main.js.map +1 -1
  589. package/packages/server/dist/routes/chat.d.ts.map +1 -1
  590. package/packages/server/dist/routes/chat.js +5 -8
  591. package/packages/server/dist/routes/chat.js.map +1 -1
  592. package/packages/server/dist/routes/config.d.ts +6 -0
  593. package/packages/server/dist/routes/config.d.ts.map +1 -1
  594. package/packages/server/dist/routes/config.js +34 -31
  595. package/packages/server/dist/routes/config.js.map +1 -1
  596. package/packages/server/dist/routes/cron.d.ts.map +1 -1
  597. package/packages/server/dist/routes/cron.js +33 -23
  598. package/packages/server/dist/routes/cron.js.map +1 -1
  599. package/packages/server/dist/routes/dream.d.ts +1 -1
  600. package/packages/server/dist/routes/dream.d.ts.map +1 -1
  601. package/packages/server/dist/routes/dream.js +16 -34
  602. package/packages/server/dist/routes/dream.js.map +1 -1
  603. package/packages/server/dist/routes/gateways.d.ts.map +1 -1
  604. package/packages/server/dist/routes/gateways.js +8 -13
  605. package/packages/server/dist/routes/gateways.js.map +1 -1
  606. package/packages/server/dist/routes/memories.d.ts.map +1 -1
  607. package/packages/server/dist/routes/memories.js +16 -29
  608. package/packages/server/dist/routes/memories.js.map +1 -1
  609. package/packages/server/dist/routes/night.d.ts +31 -0
  610. package/packages/server/dist/routes/night.d.ts.map +1 -0
  611. package/packages/server/dist/routes/night.js +28 -0
  612. package/packages/server/dist/routes/night.js.map +1 -0
  613. package/packages/server/dist/routes/org.d.ts.map +1 -1
  614. package/packages/server/dist/routes/org.js +125 -119
  615. package/packages/server/dist/routes/org.js.map +1 -1
  616. package/packages/server/dist/routes/profile.d.ts.map +1 -1
  617. package/packages/server/dist/routes/profile.js +5 -6
  618. package/packages/server/dist/routes/profile.js.map +1 -1
  619. package/packages/server/dist/routes/providers.d.ts.map +1 -1
  620. package/packages/server/dist/routes/providers.js +1 -3
  621. package/packages/server/dist/routes/providers.js.map +1 -1
  622. package/packages/server/dist/routes/query.d.ts +10 -0
  623. package/packages/server/dist/routes/query.d.ts.map +1 -0
  624. package/packages/server/dist/routes/query.js +17 -0
  625. package/packages/server/dist/routes/query.js.map +1 -0
  626. package/packages/server/dist/routes/questions.d.ts.map +1 -1
  627. package/packages/server/dist/routes/questions.js +5 -11
  628. package/packages/server/dist/routes/questions.js.map +1 -1
  629. package/packages/server/dist/routes/sessions.d.ts.map +1 -1
  630. package/packages/server/dist/routes/sessions.js +20 -28
  631. package/packages/server/dist/routes/sessions.js.map +1 -1
  632. package/packages/server/dist/routes/sleep.d.ts.map +1 -1
  633. package/packages/server/dist/routes/sleep.js +21 -36
  634. package/packages/server/dist/routes/sleep.js.map +1 -1
  635. package/packages/server/dist/routes/stats.d.ts.map +1 -1
  636. package/packages/server/dist/routes/stats.js +2 -7
  637. package/packages/server/dist/routes/stats.js.map +1 -1
  638. package/packages/server/dist/routes/terminals.d.ts.map +1 -1
  639. package/packages/server/dist/routes/terminals.js +19 -14
  640. package/packages/server/dist/routes/terminals.js.map +1 -1
  641. package/packages/server/dist/routes/tools.d.ts.map +1 -1
  642. package/packages/server/dist/routes/tools.js +9 -5
  643. package/packages/server/dist/routes/tools.js.map +1 -1
  644. package/packages/server/dist/routes/ws.d.ts.map +1 -1
  645. package/packages/server/dist/routes/ws.js +235 -207
  646. package/packages/server/dist/routes/ws.js.map +1 -1
  647. package/packages/server/dist/schemas.d.ts +30 -21
  648. package/packages/server/dist/schemas.d.ts.map +1 -1
  649. package/packages/server/dist/schemas.js +3 -2
  650. package/packages/server/dist/schemas.js.map +1 -1
  651. package/packages/server/dist/server.d.ts.map +1 -1
  652. package/packages/server/dist/server.js +257 -238
  653. package/packages/server/dist/server.js.map +1 -1
  654. package/packages/server/dist/services/stream.d.ts.map +1 -1
  655. package/packages/server/dist/services/stream.js +6 -4
  656. package/packages/server/dist/services/stream.js.map +1 -1
  657. package/packages/server/dist/services/stt.d.ts +1 -1
  658. package/packages/server/dist/services/stt.d.ts.map +1 -1
  659. package/packages/server/dist/services/stt.js +175 -124
  660. package/packages/server/dist/services/stt.js.map +1 -1
  661. package/packages/server/dist/services/tts.d.ts.map +1 -1
  662. package/packages/server/dist/services/tts.js +82 -54
  663. package/packages/server/dist/services/tts.js.map +1 -1
  664. package/packages/server/dist/services/turns.d.ts +8 -6
  665. package/packages/server/dist/services/turns.d.ts.map +1 -1
  666. package/packages/server/dist/services/turns.js +36 -32
  667. package/packages/server/dist/services/turns.js.map +1 -1
  668. package/packages/server/dist/services/updates.d.ts +1 -0
  669. package/packages/server/dist/services/updates.d.ts.map +1 -1
  670. package/packages/server/dist/services/updates.js +150 -91
  671. package/packages/server/dist/services/updates.js.map +1 -1
  672. package/packages/server/dist/services/voice-keys.d.ts.map +1 -1
  673. package/packages/server/dist/services/voice-keys.js +4 -2
  674. package/packages/server/dist/services/voice-keys.js.map +1 -1
  675. package/packages/server/dist/static.d.ts +1 -1
  676. package/packages/server/dist/static.d.ts.map +1 -1
  677. package/packages/server/dist/static.js +7 -7
  678. package/packages/server/dist/static.js.map +1 -1
  679. package/packages/server/package.json +1 -1
  680. package/packages/web/dist/assets/{abnfDiagram-O67JEVCF-D7YyFndQ.js → abnfDiagram-O67JEVCF-BmjzYusK.js} +1 -1
  681. package/packages/web/dist/assets/{arc-C_Zgk2dJ.js → arc-n9TPu3wY.js} +1 -1
  682. package/packages/web/dist/assets/{architectureDiagram-NJMV4G6O-eI0adu1B.js → architectureDiagram-NJMV4G6O-Cx9TKHMG.js} +1 -1
  683. package/packages/web/dist/assets/{blockDiagram-BEXU5L5S-WAoOFUA9.js → blockDiagram-BEXU5L5S-Cu2lqO0u.js} +1 -1
  684. package/packages/web/dist/assets/{c4Diagram-YGBWAQC7-DE8Zyhng.js → c4Diagram-YGBWAQC7-C0lage7M.js} +1 -1
  685. package/packages/web/dist/assets/channel-Cx64mAod.js +1 -0
  686. package/packages/web/dist/assets/{chunk-2Q5K7J3B-bnqLP2XD.js → chunk-2Q5K7J3B-D3aVQoie.js} +1 -1
  687. package/packages/web/dist/assets/{chunk-3FUC2YCW-Ck1_SVe0.js → chunk-3FUC2YCW-Cmrvpp5I.js} +2 -2
  688. package/packages/web/dist/assets/{chunk-5VM5RSS4-hDmC41gD.js → chunk-5VM5RSS4-Bk7nd1Or.js} +1 -1
  689. package/packages/web/dist/assets/{chunk-GTNCS2PH-PoWvfCrT.js → chunk-GTNCS2PH--_-V13S9.js} +1 -1
  690. package/packages/web/dist/assets/{chunk-GWA4HPMP-D3V0IG43.js → chunk-GWA4HPMP-B2iN_iAC.js} +1 -1
  691. package/packages/web/dist/assets/{chunk-JWPE2WC7-BryfpHM5.js → chunk-JWPE2WC7-BCQEdHBw.js} +1 -1
  692. package/packages/web/dist/assets/{chunk-NETBCI7D-8ic1iEdT.js → chunk-NETBCI7D-lKrFsR6g.js} +1 -1
  693. package/packages/web/dist/assets/{chunk-WEXAMYUT-nM8tmQT2.js → chunk-WEXAMYUT-Bl4c2a1n.js} +1 -1
  694. package/packages/web/dist/assets/{chunk-XXDRQBXY-Do28F482.js → chunk-XXDRQBXY-xvPIGObD.js} +1 -1
  695. package/packages/web/dist/assets/{classDiagram-v2-NBCMYWYE-Bop9oNNO.js → classDiagram-v2-NBCMYWYE-DjX85RUY.js} +1 -1
  696. package/packages/web/dist/assets/{cose-bilkent-JH36ORCC-a7f_bpnt.js → cose-bilkent-JH36ORCC-Dn5oYBNs.js} +1 -1
  697. package/packages/web/dist/assets/{cynefin-OW5HDTMX-DnArcis_.js → cynefin-OW5HDTMX-D1zN_crx.js} +1 -1
  698. package/packages/web/dist/assets/{cynefinDiagram-VND7K2PF-vEuTb1GD.js → cynefinDiagram-VND7K2PF-B-GwPS_J.js} +1 -1
  699. package/packages/web/dist/assets/{dagre-6A5THRUB-BgG4MynJ.js → dagre-6A5THRUB-C2wUvKaS.js} +1 -1
  700. package/packages/web/dist/assets/{diagram-22UHCM2B-DRCQpafv.js → diagram-22UHCM2B-DnZ3T6JG.js} +1 -1
  701. package/packages/web/dist/assets/{diagram-3UASUU5V-BKgmAXde.js → diagram-3UASUU5V-DR8pK0Yb.js} +1 -1
  702. package/packages/web/dist/assets/{diagram-ATOU4E4O-B6Hsy36X.js → diagram-ATOU4E4O-olswvjNy.js} +1 -1
  703. package/packages/web/dist/assets/{diagram-CDSNMT55-JflyfyoB.js → diagram-CDSNMT55-CkbrgFGH.js} +1 -1
  704. package/packages/web/dist/assets/{diagram-MLGK6HIB-Dd2QPJjT.js → diagram-MLGK6HIB-DiNLsh9k.js} +1 -1
  705. package/packages/web/dist/assets/{diagram-MPIPVDR6-DE5QU60x.js → diagram-MPIPVDR6-DY0eRCo8.js} +1 -1
  706. package/packages/web/dist/assets/{ebnfDiagram-ZINNZB2B-D7AQ741b.js → ebnfDiagram-ZINNZB2B-BwyYBste.js} +1 -1
  707. package/packages/web/dist/assets/{elk-276RUBZZ-CeewBVLF.js → elk-276RUBZZ-BOkb2Unt.js} +1 -1
  708. package/packages/web/dist/assets/{erDiagram-OPXOYQCR-mLLYkZ5c.js → erDiagram-OPXOYQCR-Bopm0hOe.js} +1 -1
  709. package/packages/web/dist/assets/{flowDiagram-KWPJA3E3-DtpSpsQN.js → flowDiagram-KWPJA3E3-CB8O7Rey.js} +1 -1
  710. package/packages/web/dist/assets/{ganttDiagram-FUAMR5RP-1_lh-3ky.js → ganttDiagram-FUAMR5RP-BMoBwxn3.js} +1 -1
  711. package/packages/web/dist/assets/{gitGraphDiagram-X574FWY7-DoPXZuT5.js → gitGraphDiagram-X574FWY7-r9EVynuW.js} +1 -1
  712. package/packages/web/dist/assets/index-BJFGaq8t.js +646 -0
  713. package/packages/web/dist/assets/index-BMYKZrup.css +32 -0
  714. package/packages/web/dist/assets/{infoDiagram-VRGFBTTK-DQpRGGiD.js → infoDiagram-VRGFBTTK-4NICTzD4.js} +1 -1
  715. package/packages/web/dist/assets/{ishikawaDiagram-OU5B5YK6-gH5C9Q2e.js → ishikawaDiagram-OU5B5YK6-qmYHkSam.js} +1 -1
  716. package/packages/web/dist/assets/{journeyDiagram-ZHPQQLJL-Bg-oeFjb.js → journeyDiagram-ZHPQQLJL-BSb6Qa2c.js} +1 -1
  717. package/packages/web/dist/assets/{kanban-definition-PNTS6WVX-BnpI4VH8.js → kanban-definition-PNTS6WVX-B0cwMsip.js} +1 -1
  718. package/packages/web/dist/assets/{mermaid.core-BwBKxlRA.js → mermaid.core-CTl4Qse1.js} +4 -4
  719. package/packages/web/dist/assets/{mindmap-definition-NLK3R4M7-NBnnxEoO.js → mindmap-definition-NLK3R4M7-tbJ4AKr2.js} +1 -1
  720. package/packages/web/dist/assets/{pegDiagram-GJSIUBJH-RrXXbIvO.js → pegDiagram-GJSIUBJH-BD50Xatx.js} +1 -1
  721. package/packages/web/dist/assets/{pieDiagram-5QR66LMP-B27q6Gso.js → pieDiagram-5QR66LMP-C52DU0dU.js} +1 -1
  722. package/packages/web/dist/assets/{quadrantDiagram-O4NWA36T-DGDsdur2.js → quadrantDiagram-O4NWA36T-Dmf0Relz.js} +1 -1
  723. package/packages/web/dist/assets/{railroadDiagram-XR7U4H2S-GdjkE3mI.js → railroadDiagram-XR7U4H2S-q1rW0LBx.js} +1 -1
  724. package/packages/web/dist/assets/{requirementDiagram-PLB6GJNP-DjK0GfgO.js → requirementDiagram-PLB6GJNP-ChTty00B.js} +1 -1
  725. package/packages/web/dist/assets/{sankeyDiagram-IPEJSGJF-BG_AIkwF.js → sankeyDiagram-IPEJSGJF-vRhUUtR0.js} +1 -1
  726. package/packages/web/dist/assets/scene-DUzELcJR.js +4620 -0
  727. package/packages/web/dist/assets/{sequenceDiagram-PO4LG4MO-CIQwUb4y.js → sequenceDiagram-PO4LG4MO-CJ37i6X7.js} +1 -1
  728. package/packages/web/dist/assets/{sizeCapture-INFHLROL-bpIoPxdJ.js → sizeCapture-INFHLROL-CUwB5IU5.js} +1 -1
  729. package/packages/web/dist/assets/{stateDiagram-v2-GCMORJYK-8hYXvPPv.js → stateDiagram-v2-GCMORJYK-CbmUCHZz.js} +1 -1
  730. package/packages/web/dist/assets/{swimlanes-2SLR337P-gfflUMF9.js → swimlanes-2SLR337P-BH1ix14-.js} +1 -1
  731. package/packages/web/dist/assets/swimlanesDiagram-TC7HE7FX-D1P54_6D.js +8 -0
  732. package/packages/web/dist/assets/{timeline-definition-EJHVYXUP-PHMNoGTZ.js → timeline-definition-EJHVYXUP-h73o8wo_.js} +1 -1
  733. package/packages/web/dist/assets/{usecaseDiagram-POWQR4AR-B2j5iteO.js → usecaseDiagram-POWQR4AR-BmrG9VWs.js} +1 -1
  734. package/packages/web/dist/assets/{vennDiagram-UO4OBE2U-BzxtZ-_2.js → vennDiagram-UO4OBE2U-Bax-03xB.js} +1 -1
  735. package/packages/web/dist/assets/{wardleyDiagram-VNRHLVJA-DL7YbMpY.js → wardleyDiagram-VNRHLVJA-A2y6258q.js} +1 -1
  736. package/packages/web/dist/assets/{xychartDiagram-PMCCYNJV-CisgP1cT.js → xychartDiagram-PMCCYNJV-BSiMaGgj.js} +1 -1
  737. package/packages/web/dist/index.html +2 -2
  738. package/packages/web/package.json +1 -1
  739. package/packages/web/dist/assets/channel-egZxcyUK.js +0 -1
  740. package/packages/web/dist/assets/index-Cw2Opmx7.js +0 -648
  741. package/packages/web/dist/assets/index-j0zBRCgT.css +0 -32
  742. package/packages/web/dist/assets/scene-D4LPicHk.js +0 -4620
  743. package/packages/web/dist/assets/swimlanesDiagram-TC7HE7FX-9wdzGXU-.js +0 -8
@@ -1,17 +1,26 @@
1
1
  import { EventEmitter } from 'node:events';
2
- import { existsSync } from 'node:fs';
3
- import { open, readdir, readFile, writeFile } from 'node:fs/promises';
2
+ import { access, open, readdir, readFile, stat, writeFile } from 'node:fs/promises';
4
3
  import { homedir } from 'node:os';
5
4
  import { join } from 'node:path';
6
5
  import { quoteForCmd } from './process.js';
7
6
  import { userSettingsGuard } from './user-settings-guard.js';
7
+ const MINUTE_MS = 60_000;
8
8
  /** How much screen output a late viewer gets replayed, in characters. */
9
9
  const REPLAY_LIMIT = 1_000_000;
10
10
  /** How long a finished agent's terminal stays open before it is killed. */
11
- export const TUI_LINGER_MS = 10 * 60 * 1000;
11
+ export const TUI_LINGER_MS = 10 * MINUTE_MS;
12
12
  /** A size that fits the run page; the browser resizes to its own right away. */
13
13
  const DEFAULT_COLS = 120;
14
14
  const DEFAULT_ROWS = 34;
15
+ /** What a browser may resize the terminal to. */
16
+ const MIN_COLS = 20;
17
+ const MAX_COLS = 400;
18
+ const MIN_ROWS = 5;
19
+ const MAX_ROWS = 200;
20
+ /** Lines of history the screen mirror keeps above the visible screen. */
21
+ const MIRROR_SCROLLBACK_LINES = 5000;
22
+ /** The terminal type the child is told it runs in. */
23
+ const TERM = 'xterm-256color';
15
24
  /** Longer prompts go to a file: argv on Windows ends at 32 767 characters. */
16
25
  const INLINE_PROMPT_LIMIT = 12_000;
17
26
  /**
@@ -20,10 +29,21 @@ const INLINE_PROMPT_LIMIT = 12_000;
20
29
  * was interrupted with Esc and never told what to do next. Until then a
21
30
  * person can still answer it from the run page.
22
31
  */
23
- const IDLE_LIMIT_MS = 15 * 60 * 1000;
32
+ const IDLE_LIMIT_MS = 15 * MINUTE_MS;
24
33
  /** How long the transcript may trail the Stop hook before it is read as is. */
25
34
  const SETTLE_LIMIT_MS = 3000;
26
35
  const POLL_MS = 250;
36
+ /** How long after a Stop the transcript is watched for work a blocking hook set going again. */
37
+ const HOOK_BLOCK_GRACE_MS = 4 * POLL_MS;
38
+ /** The slower pace at which a lingering terminal's transcript is followed. */
39
+ const LATE_POLL_MS = 4 * POLL_MS;
40
+ const ESC = String.fromCharCode(27);
41
+ /** The TUI switches bracketed paste on and off with these; see `PASTE_START`. */
42
+ const PASTE_ON = ESC + '[?2004h';
43
+ const PASTE_OFF = ESC + '[?2004l';
44
+ /** Bracketed paste: the TUI takes the text between these as one paste, newlines and all. */
45
+ const PASTE_START = ESC + '[200~';
46
+ const PASTE_END = ESC + '[201~';
27
47
  let ptyModule;
28
48
  /**
29
49
  * The native pty binding, or `null` where it cannot load (a platform without
@@ -36,6 +56,37 @@ export function loadPty() {
36
56
  return ptyModule;
37
57
  }
38
58
  let mirrorModule;
59
+ /** A package export by name; some loaders only expose it under `default`. */
60
+ function exportOf(loaded, name) {
61
+ // A dynamically imported package, whose shape is only known by name.
62
+ const members = loaded;
63
+ const fallback = members.default;
64
+ return (members[name] ?? fallback[name]);
65
+ }
66
+ function mirrorFactory(Terminal, SerializeAddon) {
67
+ return (cols, rows) => {
68
+ const term = new Terminal({ cols, rows, scrollback: MIRROR_SCROLLBACK_LINES, allowProposedApi: true });
69
+ const addon = new SerializeAddon();
70
+ term.loadAddon(addon);
71
+ return {
72
+ write: (data, done) => term.write(data, done),
73
+ // Queued behind what is still waiting to be parsed: a write is
74
+ // processed later, a resize at once, and bytes painted for the old
75
+ // width then landed on the new one - overlapping, skewed lines.
76
+ resize: (c, r) => term.write('', () => term.resize(c, r)),
77
+ serialize: () => addon.serialize(),
78
+ text: () => {
79
+ const buffer = term.buffer.active;
80
+ const lines = [];
81
+ for (let y = buffer.viewportY; y < buffer.viewportY + term.rows; y += 1) {
82
+ lines.push(buffer.getLine(y)?.translateToString(true) ?? '');
83
+ }
84
+ return lines.join('\n');
85
+ },
86
+ dispose: () => term.dispose(),
87
+ };
88
+ };
89
+ }
39
90
  /**
40
91
  * A terminal emulator with no screen, fed the same bytes as the browser.
41
92
  *
@@ -49,36 +100,7 @@ let mirrorModule;
49
100
  */
50
101
  function loadMirror() {
51
102
  mirrorModule ??= Promise.all([import('@xterm/headless'), import('@xterm/addon-serialize')])
52
- .then(([headless, serialize]) => {
53
- const Terminal = headless.Terminal ??
54
- headless.default.Terminal;
55
- const SerializeAddon = serialize.SerializeAddon ??
56
- serialize.default.SerializeAddon;
57
- return (cols, rows) => {
58
- const TerminalClass = Terminal;
59
- const SerializeClass = SerializeAddon;
60
- const term = new TerminalClass({ cols, rows, scrollback: 5000, allowProposedApi: true });
61
- const addon = new SerializeClass();
62
- term.loadAddon(addon);
63
- return {
64
- write: (data, done) => term.write(data, done),
65
- // Queued behind what is still waiting to be parsed: a write is
66
- // processed later, a resize at once, and bytes painted for the old
67
- // width then landed on the new one - overlapping, skewed lines.
68
- resize: (c, r) => term.write('', () => term.resize(c, r)),
69
- serialize: () => addon.serialize(),
70
- text: () => {
71
- const buffer = term.buffer.active;
72
- const lines = [];
73
- for (let y = buffer.viewportY; y < buffer.viewportY + term.rows; y += 1) {
74
- lines.push(buffer.getLine(y)?.translateToString(true) ?? '');
75
- }
76
- return lines.join('\n');
77
- },
78
- dispose: () => term.dispose(),
79
- };
80
- };
81
- })
103
+ .then(([headless, serialize]) => mirrorFactory(exportOf(headless, 'Terminal'), exportOf(serialize, 'SerializeAddon')))
82
104
  .catch(() => null);
83
105
  return mirrorModule;
84
106
  }
@@ -87,25 +109,52 @@ function loadMirror() {
87
109
  // took its time on first use, a browser could resize the process in between,
88
110
  // and the early bytes were then replayed at the wrong width.
89
111
  void loadMirror();
90
- const PASTE_ON = String.fromCharCode(27) + '[?2004h';
91
- const PASTE_OFF = String.fromCharCode(27) + '[?2004l';
112
+ const clamp = (value, min, max) => Math.max(min, Math.min(max, Math.floor(value)));
92
113
  class TuiSession {
93
114
  info;
94
115
  pty;
95
116
  cleanup;
96
117
  lingerMs;
97
118
  buffer = '';
98
- lingerTimer;
99
119
  /** The screen as it is, for late viewers; unset where the emulator cannot load. */
100
120
  mirror;
101
121
  /** Whether the TUI has bracketed paste switched on right now. */
102
122
  pasteMode = false;
123
+ #lingerTimer;
103
124
  constructor(info, pty, cleanup, lingerMs) {
104
125
  this.info = info;
105
126
  this.pty = pty;
106
127
  this.cleanup = cleanup;
107
128
  this.lingerMs = lingerMs;
108
129
  }
130
+ infoCopy() {
131
+ return { ...this.info };
132
+ }
133
+ /** What the process painted: kept for late viewers, fed to the mirror, scanned for paste mode. */
134
+ receive(data) {
135
+ this.buffer = (this.buffer + data).slice(-REPLAY_LIMIT);
136
+ this.mirror?.write(data);
137
+ const on = data.lastIndexOf(PASTE_ON);
138
+ const off = data.lastIndexOf(PASTE_OFF);
139
+ if (on !== off)
140
+ this.pasteMode = on > off;
141
+ }
142
+ /** (Re)starts the countdown after which `expire` runs; it never keeps the process alive. */
143
+ startLinger(expire) {
144
+ clearTimeout(this.#lingerTimer);
145
+ this.#lingerTimer = setTimeout(expire, this.lingerMs);
146
+ this.#lingerTimer.unref?.();
147
+ }
148
+ stopLinger() {
149
+ clearTimeout(this.#lingerTimer);
150
+ }
151
+ /** The process is gone: no countdown, no screen mirror, and the owner's cleanup runs. */
152
+ end() {
153
+ this.stopLinger();
154
+ this.mirror?.dispose();
155
+ this.mirror = undefined;
156
+ this.cleanup();
157
+ }
109
158
  }
110
159
  /**
111
160
  * Every terminal that is still open, by assignment id.
@@ -121,55 +170,25 @@ export class TuiSessionRegistry extends EventEmitter {
121
170
  this.kill(key);
122
171
  const session = new TuiSession({ key, providerSessionId, state: 'running', startedAt: Date.now(), cols: DEFAULT_COLS, rows: DEFAULT_ROWS }, pty, cleanup, lingerMs);
123
172
  this.#sessions.set(key, session);
124
- // Everything painted before the emulator was ready is still in the raw
125
- // buffer; it goes in first, and every later chunk after it.
126
- void loadMirror().then((create) => {
127
- if (!create || this.#sessions.get(key) !== session)
128
- return;
129
- const mirror = create(session.info.cols, session.info.rows);
130
- mirror.write(session.buffer);
131
- session.mirror = mirror;
132
- });
133
- pty.onData((data) => {
134
- if (this.#sessions.get(key) !== session)
135
- return;
136
- session.buffer = (session.buffer + data).slice(-REPLAY_LIMIT);
137
- session.mirror?.write(data);
138
- const on = data.lastIndexOf(PASTE_ON);
139
- const off = data.lastIndexOf(PASTE_OFF);
140
- if (on !== off)
141
- session.pasteMode = on > off;
142
- this.emit('data', key, data);
143
- });
144
- pty.onExit(() => {
145
- clearTimeout(session.lingerTimer);
146
- session.mirror?.dispose();
147
- session.mirror = undefined;
148
- session.cleanup();
149
- if (this.#sessions.get(key) !== session)
150
- return;
151
- this.#sessions.delete(key);
152
- session.info.state = 'exited';
153
- this.emit('state', { ...session.info });
154
- this.emit('exit', key);
155
- });
156
- this.emit('state', { ...session.info });
173
+ this.#startMirror(key, session);
174
+ pty.onData((data) => this.#received(key, session, data));
175
+ pty.onExit(() => this.#exited(key, session));
176
+ this.#announce(session);
157
177
  }
158
178
  /** Terminals currently attached, whether their run is working or waiting. */
159
179
  get size() {
160
180
  return this.#sessions.size;
161
181
  }
162
182
  info(key) {
163
- const session = this.#sessions.get(key);
164
- return session ? { ...session.info } : null;
183
+ return this.#sessions.get(key)?.infoCopy() ?? null;
165
184
  }
166
185
  list() {
167
- return [...this.#sessions.values()].map((session) => ({ ...session.info }));
186
+ return [...this.#sessions.values()].map((session) => session.infoCopy());
168
187
  }
169
188
  /** The raw output so far - what the process wrote, not what the screen shows. */
170
189
  snapshot(key) {
171
190
  const session = this.#sessions.get(key);
172
- return session ? { info: { ...session.info }, data: session.buffer } : null;
191
+ return session ? { info: session.infoCopy(), data: session.buffer } : null;
173
192
  }
174
193
  /**
175
194
  * The screen as it is now, for a viewer that opens the terminal late:
@@ -182,12 +201,12 @@ export class TuiSessionRegistry extends EventEmitter {
182
201
  return null;
183
202
  const mirror = session.mirror;
184
203
  if (!mirror)
185
- return { info: { ...session.info }, data: session.buffer };
204
+ return this.snapshot(key);
186
205
  // Parsing is asynchronous; wait until what has arrived is on the screen.
187
206
  await new Promise((resolve) => mirror.write('', resolve));
188
207
  if (session.mirror !== mirror)
189
208
  return this.snapshot(key);
190
- return { info: { ...session.info }, data: mirror.serialize() };
209
+ return { info: session.infoCopy(), data: mirror.serialize() };
191
210
  }
192
211
  /** What the screen shows right now as plain text, or null without an emulator. */
193
212
  screenText(key) {
@@ -211,8 +230,8 @@ export class TuiSessionRegistry extends EventEmitter {
211
230
  const session = this.#sessions.get(key);
212
231
  if (!session)
213
232
  return;
214
- const c = Math.max(20, Math.min(400, Math.floor(cols)));
215
- const r = Math.max(5, Math.min(200, Math.floor(rows)));
233
+ const c = clamp(cols, MIN_COLS, MAX_COLS);
234
+ const r = clamp(rows, MIN_ROWS, MAX_ROWS);
216
235
  if (c === session.info.cols && r === session.info.rows)
217
236
  return;
218
237
  try {
@@ -222,7 +241,7 @@ export class TuiSessionRegistry extends EventEmitter {
222
241
  session.info.rows = r;
223
242
  // Every other viewer of this terminal follows the new size instead of
224
243
  // fighting it with its own (run-terminal.tsx).
225
- this.emit('state', { ...session.info });
244
+ this.#announce(session);
226
245
  }
227
246
  catch {
228
247
  // A pty that is exiting refuses a resize; nothing to keep.
@@ -236,31 +255,22 @@ export class TuiSessionRegistry extends EventEmitter {
236
255
  const session = this.#sessions.get(key);
237
256
  if (!session)
238
257
  return;
239
- clearTimeout(session.lingerTimer);
240
- if (session.info.state === 'running')
241
- return;
242
- session.info.state = 'running';
243
- this.emit('state', { ...session.info });
258
+ session.stopLinger();
259
+ this.#setState(session, 'running');
244
260
  }
245
261
  /** The work is over: the terminal stays open, then goes. */
246
262
  linger(key) {
247
263
  const session = this.#sessions.get(key);
248
264
  if (!session)
249
265
  return;
250
- const ms = session.lingerMs;
251
- clearTimeout(session.lingerTimer);
252
- if (session.info.state !== 'idle') {
253
- session.info.state = 'idle';
254
- this.emit('state', { ...session.info });
255
- }
256
- session.lingerTimer = setTimeout(() => this.kill(key), ms);
257
- session.lingerTimer.unref?.();
266
+ this.#setState(session, 'idle');
267
+ session.startLinger(() => this.kill(key));
258
268
  }
259
269
  kill(key) {
260
270
  const session = this.#sessions.get(key);
261
271
  if (!session)
262
272
  return false;
263
- clearTimeout(session.lingerTimer);
273
+ session.stopLinger();
264
274
  try {
265
275
  session.pty.kill();
266
276
  }
@@ -274,12 +284,56 @@ export class TuiSessionRegistry extends EventEmitter {
274
284
  for (const key of [...this.#sessions.keys()])
275
285
  this.kill(key);
276
286
  }
287
+ /**
288
+ * Everything painted before the emulator was ready is still in the raw
289
+ * buffer; it goes in first, and every later chunk after it.
290
+ */
291
+ #startMirror(key, session) {
292
+ void loadMirror().then((create) => {
293
+ if (!create || this.#sessions.get(key) !== session)
294
+ return;
295
+ const mirror = create(session.info.cols, session.info.rows);
296
+ mirror.write(session.buffer);
297
+ session.mirror = mirror;
298
+ });
299
+ }
300
+ #received(key, session, data) {
301
+ if (this.#sessions.get(key) !== session)
302
+ return;
303
+ session.receive(data);
304
+ this.emit('data', key, data);
305
+ }
306
+ #exited(key, session) {
307
+ try {
308
+ session.end();
309
+ }
310
+ finally {
311
+ // A session replaced under its key (see `attach`) is not the registry's to announce.
312
+ if (this.#sessions.get(key) === session) {
313
+ this.#sessions.delete(key);
314
+ this.#setState(session, 'exited');
315
+ this.emit('exit', key);
316
+ }
317
+ }
318
+ }
319
+ #setState(session, state) {
320
+ if (session.info.state === state)
321
+ return;
322
+ session.info.state = state;
323
+ this.#announce(session);
324
+ }
325
+ #announce(session) {
326
+ this.emit('state', session.infoCopy());
327
+ }
277
328
  }
278
329
  export const tuiSessions = new TuiSessionRegistry();
330
+ const forwardSlashes = (path) => path.replace(/\\/g, '/');
331
+ /** A file path as it sits inside a single-quoted string of a hook command. */
332
+ const quotedInScript = (file) => forwardSlashes(file).replace(/'/g, "\\'");
279
333
  /** The Stop hook's command: the payload on stdin, verbatim into the marker file. */
280
334
  export function stopHookCommand(markerFile) {
281
- const node = process.execPath.replace(/\\/g, '/');
282
- const target = markerFile.replace(/\\/g, '/').replace(/'/g, "\\'");
335
+ const node = forwardSlashes(process.execPath);
336
+ const target = quotedInScript(markerFile);
283
337
  return `"${node}" -e "require('fs').writeFileSync('${target}', require('fs').readFileSync(0))"`;
284
338
  }
285
339
  /**
@@ -301,11 +355,10 @@ function childEnv(extra) {
301
355
  if (value !== undefined)
302
356
  env[name] = value;
303
357
  }
304
- env.TERM = 'xterm-256color';
358
+ env.TERM = TERM;
305
359
  env.COLORTERM = 'truecolor';
306
360
  return env;
307
361
  }
308
- const ESC = String.fromCharCode(27);
309
362
  /** Screen text without escape sequences and whitespace, for spotting a dialog. */
310
363
  function flatten(screen) {
311
364
  return screen
@@ -314,15 +367,20 @@ function flatten(screen) {
314
367
  .replace(/\[[0-9;?]*[ -/]*[@-~]/g, '')
315
368
  .replace(/\s+/g, '');
316
369
  }
370
+ const ARROW_DOWN = ESC + '[B';
317
371
  /**
318
372
  * First-run dialogs a print run never shows, and the answer a person would
319
373
  * give. The folder is one Rookery already works in; the bypass warning only
320
374
  * appears for a `full` agent, which is a setting somebody chose.
321
375
  */
322
376
  const STARTUP_DIALOGS = [
323
- { marker: 'Yes,Itrustthisfolder', keys: ESC + '[B' },
324
- { marker: 'Yes,Iaccept', keys: ESC + '[B' },
377
+ { marker: 'Yes,Itrustthisfolder', keys: ARROW_DOWN },
378
+ { marker: 'Yes,Iaccept', keys: ARROW_DOWN },
325
379
  ];
380
+ /** How much recent screen output is searched for a dialog, in characters. */
381
+ const DIALOG_SCREEN_TAIL = 20_000;
382
+ /** A beat before each key of a dialog answer, as a person would take it. */
383
+ const DIALOG_KEY_DELAY_MS = 150;
326
384
  function configDir(env) {
327
385
  return env.CLAUDE_CONFIG_DIR || process.env.CLAUDE_CONFIG_DIR || join(homedir(), '.claude');
328
386
  }
@@ -338,16 +396,20 @@ async function findTranscript(root, sessionId) {
338
396
  }
339
397
  for (const folder of folders) {
340
398
  const candidate = join(projects, folder, sessionId + '.jsonl');
341
- if (existsSync(candidate))
399
+ const found = await access(candidate).then(() => true, () => false);
400
+ if (found)
342
401
  return candidate;
343
402
  }
344
403
  return null;
345
404
  }
405
+ const LINE_FEED = 0x0a;
406
+ const NO_BYTES = Buffer.alloc(0);
346
407
  /** Reads a growing JSONL file from where the last call stopped. */
347
408
  class TranscriptTail {
348
409
  path;
349
410
  #offset = 0;
350
- #partial = '';
411
+ /** Bytes after the last newline: a line still being written. */
412
+ #partial = NO_BYTES;
351
413
  #seen = new Set();
352
414
  constructor(path) {
353
415
  this.path = path;
@@ -355,60 +417,71 @@ class TranscriptTail {
355
417
  /** Starts at the current end: a resumed session's history is not news. */
356
418
  async skipToEnd() {
357
419
  try {
358
- const handle = await open(this.path, 'r');
359
- try {
360
- this.#offset = (await handle.stat()).size;
361
- }
362
- finally {
363
- await handle.close();
364
- }
420
+ this.#offset = (await stat(this.path)).size;
365
421
  }
366
422
  catch {
367
423
  // Not there yet: then everything in it will be new.
368
424
  }
369
425
  }
370
426
  async read() {
371
- let handle;
372
- try {
373
- handle = await open(this.path, 'r');
374
- }
375
- catch {
427
+ const appended = await this.#readAppended();
428
+ if (appended.length === 0)
429
+ return [];
430
+ const bytes = Buffer.concat([this.#partial, appended]);
431
+ const lastLineEnd = bytes.lastIndexOf(LINE_FEED);
432
+ // Split on bytes, not on decoded text: a torn line is completed by the
433
+ // next read, and so is a multi-byte character cut in half.
434
+ this.#partial = bytes.subarray(lastLineEnd + 1);
435
+ if (lastLineEnd === -1)
376
436
  return [];
437
+ const entries = [];
438
+ for (const line of bytes.toString('utf8', 0, lastLineEnd).split('\n')) {
439
+ const entry = this.#parse(line);
440
+ if (entry)
441
+ entries.push(entry);
377
442
  }
443
+ return entries;
444
+ }
445
+ /** What the file grew by since the last call; nothing where there is none or no file yet. */
446
+ async #readAppended() {
447
+ const handle = await open(this.path, 'r').catch(() => null);
448
+ if (!handle)
449
+ return NO_BYTES;
378
450
  try {
379
451
  const { size } = await handle.stat();
380
452
  if (size <= this.#offset)
381
- return [];
453
+ return NO_BYTES;
382
454
  const buffer = Buffer.alloc(size - this.#offset);
383
- await handle.read(buffer, 0, buffer.length, this.#offset);
384
- this.#offset = size;
385
- const text = this.#partial + buffer.toString('utf8');
386
- const lines = text.split('\n');
387
- this.#partial = lines.pop() ?? '';
388
- const entries = [];
389
- for (const line of lines) {
390
- if (!line.trim())
391
- continue;
392
- try {
393
- const entry = JSON.parse(line);
394
- const id = typeof entry.uuid === 'string' ? entry.uuid : undefined;
395
- if (id) {
396
- if (this.#seen.has(id))
397
- continue;
398
- this.#seen.add(id);
399
- }
400
- entries.push(entry);
401
- }
402
- catch {
403
- // A torn line is completed by the next read; a broken one is skipped.
404
- }
405
- }
406
- return entries;
455
+ const { bytesRead } = await handle.read(buffer, 0, buffer.length, this.#offset);
456
+ this.#offset += bytesRead;
457
+ return buffer.subarray(0, bytesRead);
407
458
  }
408
459
  finally {
409
460
  await handle.close();
410
461
  }
411
462
  }
463
+ /** The entry on one line, or null for a blank line, a broken one, or an entry seen before. */
464
+ #parse(line) {
465
+ if (!line.trim())
466
+ return null;
467
+ let entry;
468
+ try {
469
+ entry = JSON.parse(line);
470
+ }
471
+ catch {
472
+ // A torn line never gets here (see `read`); a broken one is skipped.
473
+ return null;
474
+ }
475
+ if (typeof entry !== 'object' || entry === null)
476
+ return null;
477
+ const record = entry;
478
+ if (typeof record.uuid === 'string') {
479
+ if (this.#seen.has(record.uuid))
480
+ return null;
481
+ this.#seen.add(record.uuid);
482
+ }
483
+ return record;
484
+ }
412
485
  }
413
486
  /**
414
487
  * What a person typed, out of one `user` transcript entry - or `null` for
@@ -434,6 +507,35 @@ function typedPrompt(entry) {
434
507
  return null;
435
508
  return text;
436
509
  }
510
+ /** What the model's prompt tokens add up to for one assistant entry, or undefined where it reports none. */
511
+ function contextTokensOf(usage) {
512
+ const parts = [usage.input_tokens, usage.cache_read_input_tokens, usage.cache_creation_input_tokens].filter((value) => typeof value === 'number');
513
+ return parts.length ? parts.reduce((sum, value) => sum + value, 0) : undefined;
514
+ }
515
+ const API_ERROR_FALLBACK = 'The API returned an error.';
516
+ /** The text of an assistant entry Claude Code wrote for an API error. */
517
+ function apiErrorText(message) {
518
+ const content = Array.isArray(message?.content) ? message.content : [];
519
+ return (content
520
+ .map((block) => (typeof block.text === 'string' ? block.text : ''))
521
+ .join(' ')
522
+ .trim() || API_ERROR_FALLBACK);
523
+ }
524
+ /** A text block as the result of a turn: without the blank lines Claude Code leads it with. */
525
+ const withoutLeadingBreak = (text) => text.replace(/^\n\n/, '');
526
+ /** The text a turn ended with - what a print run reports as its result. */
527
+ function lastTextBlock(events) {
528
+ let last = '';
529
+ for (const event of events)
530
+ if (event.type === 'text')
531
+ last = withoutLeadingBreak(event.delta);
532
+ return last;
533
+ }
534
+ /** What the Stop hook reported the agent said last, or an empty string. */
535
+ function reportedMessage(payload) {
536
+ return typeof payload.last_assistant_message === 'string' ? payload.last_assistant_message.trim() : '';
537
+ }
538
+ const fatalError = (message) => ({ type: 'error', message, fatal: true });
437
539
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
438
540
  /** A spawned terminal, and what its transcript has said so far. */
439
541
  class TerminalWatch {
@@ -452,6 +554,8 @@ class TerminalWatch {
452
554
  /** The model of the newest assistant entry - `/model` can change it mid-session. */
453
555
  model;
454
556
  #tail = null;
557
+ /** The read in flight, if any; the next one starts when it is over. */
558
+ #reading = Promise.resolve();
455
559
  #root;
456
560
  constructor(spec,
457
561
  /** A resumed session: its transcript already has a history to skip. */
@@ -460,22 +564,35 @@ class TerminalWatch {
460
564
  this.resumed = resumed;
461
565
  this.#root = configDir(spec.env);
462
566
  }
567
+ /** The process painted something. */
568
+ screenPainted() {
569
+ this.lastActivity = Date.now();
570
+ this.lastScreen = this.lastActivity;
571
+ }
572
+ /** How long the work has gone on, and how much context it holds. */
573
+ usage(startedAt) {
574
+ return {
575
+ durationMs: Date.now() - startedAt,
576
+ ...(this.contextTokens !== undefined ? { contextTokens: this.contextTokens } : {}),
577
+ };
578
+ }
463
579
  /**
464
580
  * New transcript entries, as the events a print run would have streamed.
465
581
  * What a person typed comes out as a `status` event labelled `input`, in
466
- * its place between the answers.
582
+ * its place between the answers. Reads never overlap - two at once would
583
+ * both take the same bytes - so a caller waits for the one before it.
467
584
  */
468
- async read() {
469
- if (!this.#tail) {
470
- const path = await findTranscript(this.#root, this.spec.sessionId);
471
- if (!path)
472
- return [];
473
- this.#tail = new TranscriptTail(path);
474
- if (this.resumed)
475
- await this.#tail.skipToEnd();
476
- }
585
+ read() {
586
+ const result = this.#reading.then(() => this.#readNow());
587
+ this.#reading = result.catch(() => undefined);
588
+ return result;
589
+ }
590
+ async #readNow() {
591
+ const tail = await this.#transcript();
592
+ if (!tail)
593
+ return [];
477
594
  const events = [];
478
- for (const entry of await this.#tail.read()) {
595
+ for (const entry of await tail.read()) {
479
596
  this.lastActivity = Date.now();
480
597
  if (entry.isSidechain === true)
481
598
  continue;
@@ -485,35 +602,42 @@ class TerminalWatch {
485
602
  continue;
486
603
  }
487
604
  if (entry.type === 'assistant') {
488
- this.assistantEntries += 1;
489
- const message = entry.message;
490
- if (typeof message?.model === 'string' && message.model !== '<synthetic>')
491
- this.model = message.model;
492
- const usage = message?.usage;
493
- if (usage) {
494
- const parts = [usage.input_tokens, usage.cache_read_input_tokens, usage.cache_creation_input_tokens].filter((value) => typeof value === 'number');
495
- if (parts.length)
496
- this.contextTokens = parts.reduce((sum, value) => sum + value, 0);
497
- }
605
+ this.#recordAssistant(entry);
498
606
  if (entry.isApiErrorMessage === true) {
499
- const content = Array.isArray(message?.content) ? message.content : [];
500
- this.apiError =
501
- content
502
- .map((block) => (typeof block.text === 'string' ? block.text : ''))
503
- .join(' ')
504
- .trim() || 'The API returned an error.';
607
+ this.apiError = apiErrorText(entry.message);
505
608
  continue;
506
609
  }
507
610
  this.apiError = null;
508
611
  }
509
612
  for (const event of this.spec.mapEntry(entry)) {
510
613
  if (event.type === 'text')
511
- this.lastBlock = event.delta.replace(/^\n\n/, '');
614
+ this.lastBlock = withoutLeadingBreak(event.delta);
512
615
  events.push(event);
513
616
  }
514
617
  }
515
618
  return events;
516
619
  }
620
+ async #transcript() {
621
+ if (this.#tail)
622
+ return this.#tail;
623
+ const path = await findTranscript(this.#root, this.spec.sessionId);
624
+ if (!path)
625
+ return null;
626
+ this.#tail = new TranscriptTail(path);
627
+ if (this.resumed)
628
+ await this.#tail.skipToEnd();
629
+ return this.#tail;
630
+ }
631
+ #recordAssistant(entry) {
632
+ this.assistantEntries += 1;
633
+ const message = entry.message;
634
+ if (typeof message?.model === 'string' && message.model !== '<synthetic>')
635
+ this.model = message.model;
636
+ const usage = message?.usage;
637
+ const tokens = usage ? contextTokensOf(usage) : undefined;
638
+ if (tokens !== undefined)
639
+ this.contextTokens = tokens;
640
+ }
517
641
  /** The Stop hook's payload, once it has written one. */
518
642
  async marker() {
519
643
  try {
@@ -521,10 +645,12 @@ class TerminalWatch {
521
645
  return raw.trim() ? JSON.parse(raw) : null;
522
646
  }
523
647
  catch {
648
+ // Not written yet, or caught halfway through the write: asked again next poll.
524
649
  return null;
525
650
  }
526
651
  }
527
652
  async clearMarker() {
653
+ // The folder goes with the process; without it there is nothing left to clear.
528
654
  await writeFile(this.spec.markerFile, '').catch(() => undefined);
529
655
  }
530
656
  /**
@@ -542,73 +668,97 @@ class TerminalWatch {
542
668
  await sleep(POLL_MS);
543
669
  }
544
670
  const before = this.assistantEntries;
545
- await sleep(4 * POLL_MS);
671
+ await sleep(HOOK_BLOCK_GRACE_MS);
546
672
  events.push(...(await this.read()));
547
673
  return { events, holds: this.assistantEntries === before };
548
674
  }
549
675
  }
550
- /** Starts Claude Code in a pty and registers it. Throws only before the process exists. */
551
- async function spawnTerminal(spec, resumed) {
552
- const pty = await loadPty();
553
- if (!pty)
554
- throw new Error('Terminal support is not available on this system.');
555
- // Through a `.cmd` shim the whole command line is cmd.exe's to parse, and
556
- // a task is outside text - a mail can carry quotes, `&` or `%VAR%`. It
557
- // never goes on that line: the file holds it, the line only points there.
558
- let prompt = spec.prompt;
559
- if (prompt !== undefined && (prompt.length > INLINE_PROMPT_LIMIT || spec.binary.isShim)) {
560
- const file = join(spec.workDir, 'task.md');
561
- await writeFile(file, prompt);
562
- prompt =
563
- 'Your task is written down in the file ' +
564
- file.replace(/\\/g, '/') +
565
- ' - read all of it first, then do exactly what it says.';
566
- }
676
+ /**
677
+ * The prompt as it goes on the command line. Through a `.cmd` shim the whole
678
+ * command line is cmd.exe's to parse, and a task is outside text - a mail can
679
+ * carry quotes, `&` or `%VAR%`. It never goes on that line: the file holds
680
+ * it, the line only points there. Long prompts take the same way out.
681
+ */
682
+ async function promptArgument(spec) {
683
+ const { prompt } = spec;
684
+ if (prompt === undefined)
685
+ return undefined;
686
+ if (prompt.length <= INLINE_PROMPT_LIMIT && !spec.binary.isShim)
687
+ return prompt;
688
+ const file = join(spec.workDir, 'task.md');
689
+ await writeFile(file, prompt);
690
+ return ('Your task is written down in the file ' +
691
+ forwardSlashes(file) +
692
+ ' - read all of it first, then do exactly what it says.');
693
+ }
694
+ function spawnPty(pty, spec, argv) {
567
695
  const env = childEnv(spec.env);
568
- const argv = prompt !== undefined ? [...spec.args, prompt] : spec.args;
569
696
  const options = {
570
- name: 'xterm-256color',
697
+ name: TERM,
571
698
  cols: DEFAULT_COLS,
572
699
  rows: DEFAULT_ROWS,
573
700
  ...(spec.cwd ? { cwd: spec.cwd } : {}),
574
701
  env,
575
702
  };
703
+ return spec.binary.isShim
704
+ ? pty.spawn(env.COMSPEC ?? 'cmd.exe', '/d /s /c ' + quoteForCmd([spec.binary.path, ...argv]), options)
705
+ : pty.spawn(spec.binary.path, argv, options);
706
+ }
707
+ /** Down to "Yes", then Enter - the same two keys a person presses. */
708
+ function answerDialog(child, watch, keys) {
709
+ // The process may be gone by the time a key is due; a write to it would throw.
710
+ const press = (data) => {
711
+ if (watch.exitCode === null)
712
+ child.write(data);
713
+ };
714
+ setTimeout(() => {
715
+ press(keys);
716
+ setTimeout(() => press('\r'), DIALOG_KEY_DELAY_MS);
717
+ }, DIALOG_KEY_DELAY_MS);
718
+ }
719
+ /** A listener for the child's output that answers each first-run dialog once, when it shows up. */
720
+ function startupDialogAnswerer(child, watch) {
721
+ let screen = '';
722
+ const answered = new Set();
723
+ return (data) => {
724
+ if (answered.size === STARTUP_DIALOGS.length)
725
+ return;
726
+ screen = (screen + data).slice(-DIALOG_SCREEN_TAIL);
727
+ const flat = flatten(screen);
728
+ for (const dialog of STARTUP_DIALOGS) {
729
+ if (answered.has(dialog.marker) || !flat.includes(dialog.marker))
730
+ continue;
731
+ answered.add(dialog.marker);
732
+ answerDialog(child, watch, dialog.keys);
733
+ }
734
+ };
735
+ }
736
+ /** Starts Claude Code in a pty and registers it. Throws only before the process exists. */
737
+ async function spawnTerminal(spec, resumed) {
738
+ const pty = await loadPty();
739
+ if (!pty)
740
+ throw new Error('Terminal support is not available on this system.');
741
+ const prompt = await promptArgument(spec);
742
+ const argv = prompt !== undefined ? [...spec.args, prompt] : spec.args;
576
743
  // This is Rookery's terminal, not the person's own `claude`: a model picked
577
744
  // here with Enter must not become their global default.
578
745
  const release = userSettingsGuard.acquire(configDir(spec.env));
579
746
  let child;
580
747
  try {
581
- child = spec.binary.isShim
582
- ? pty.spawn(env.COMSPEC ?? 'cmd.exe', '/d /s /c ' + quoteForCmd([spec.binary.path, ...argv]), options)
583
- : pty.spawn(spec.binary.path, argv, options);
748
+ child = spawnPty(pty, spec, argv);
584
749
  }
585
750
  catch (error) {
586
751
  release();
587
752
  throw error;
588
753
  }
589
754
  const watch = new TerminalWatch(spec, resumed);
590
- let screen = '';
591
- const answered = new Set();
755
+ const answerDialogs = startupDialogAnswerer(child, watch);
592
756
  child.onExit((event) => {
593
757
  watch.exitCode = event.exitCode;
594
758
  });
595
759
  child.onData((data) => {
596
- watch.lastActivity = Date.now();
597
- watch.lastScreen = watch.lastActivity;
598
- if (answered.size === STARTUP_DIALOGS.length)
599
- return;
600
- screen = (screen + data).slice(-20_000);
601
- const flat = flatten(screen);
602
- for (const dialog of STARTUP_DIALOGS) {
603
- if (answered.has(dialog.marker) || !flat.includes(dialog.marker))
604
- continue;
605
- answered.add(dialog.marker);
606
- // Down to "Yes", then Enter - the same two keys a person presses.
607
- setTimeout(() => {
608
- child.write(dialog.keys);
609
- setTimeout(() => child.write('\r'), 150);
610
- }, 150);
611
- }
760
+ watch.screenPainted();
761
+ answerDialogs(data);
612
762
  });
613
763
  tuiSessions.attach(spec.key, child, spec.sessionId, () => {
614
764
  release();
@@ -636,12 +786,15 @@ async function followLate(watch, onEvent) {
636
786
  }
637
787
  };
638
788
  while (stillOpen(watch)) {
639
- await sleep(4 * POLL_MS);
789
+ await sleep(LATE_POLL_MS);
640
790
  await deliver();
641
791
  }
642
- await sleep(4 * POLL_MS);
792
+ await sleep(LATE_POLL_MS);
643
793
  await deliver();
644
794
  }
795
+ const IDLE_MESSAGE = 'The terminal showed no activity for ' +
796
+ IDLE_LIMIT_MS / MINUTE_MS +
797
+ ' minutes - it was most likely waiting for an answer nobody gave.';
645
798
  /**
646
799
  * Runs Claude Code in a pty and yields what a print run would have yielded.
647
800
  * Throws only before the process exists; afterwards failures are events.
@@ -659,7 +812,7 @@ export async function* runTui(spec) {
659
812
  yield* await watch.read();
660
813
  const payload = await watch.marker();
661
814
  if (payload) {
662
- const reported = typeof payload.last_assistant_message === 'string' ? payload.last_assistant_message.trim() : '';
815
+ const reported = reportedMessage(payload);
663
816
  const { events, holds } = await watch.settle(reported);
664
817
  yield* events;
665
818
  if (!holds) {
@@ -667,7 +820,7 @@ export async function* runTui(spec) {
667
820
  continue;
668
821
  }
669
822
  if (watch.apiError) {
670
- yield { type: 'error', message: watch.apiError, fatal: true };
823
+ yield fatalError(watch.apiError);
671
824
  return;
672
825
  }
673
826
  finished = true;
@@ -675,28 +828,17 @@ export async function* runTui(spec) {
675
828
  type: 'done',
676
829
  text: reported || watch.lastBlock,
677
830
  providerSessionId: spec.sessionId,
678
- usage: {
679
- durationMs: Date.now() - started,
680
- ...(watch.contextTokens !== undefined ? { contextTokens: watch.contextTokens } : {}),
681
- },
831
+ usage: watch.usage(started),
682
832
  };
683
833
  return;
684
834
  }
685
835
  if (Date.now() - watch.lastActivity > IDLE_LIMIT_MS) {
686
- yield {
687
- type: 'error',
688
- message: 'The terminal showed no activity for 15 minutes - it was most likely waiting for an answer nobody gave.',
689
- fatal: true,
690
- };
836
+ yield fatalError(IDLE_MESSAGE);
691
837
  return;
692
838
  }
693
839
  if (watch.exitCode !== null) {
694
840
  yield* await watch.read();
695
- yield {
696
- type: 'error',
697
- message: watch.apiError ?? 'Claude Code closed its terminal (exit code ' + watch.exitCode + ') before finishing.',
698
- fatal: true,
699
- };
841
+ yield fatalError(watch.apiError ?? 'Claude Code closed its terminal (exit code ' + watch.exitCode + ') before finishing.');
700
842
  return;
701
843
  }
702
844
  }
@@ -716,24 +858,43 @@ export async function* runTui(spec) {
716
858
  }
717
859
  }
718
860
  /** A conversation terminal nobody has used for this long is closed. */
719
- const CONVERSATION_IDLE_MS = 60 * 60 * 1000;
861
+ const CONVERSATION_IDLE_MS = 60 * MINUTE_MS;
862
+ /** How long `whenIdle` waits for the work to end before it gives up waiting. */
863
+ const WHEN_IDLE_LIMIT_MS = 10 * MINUTE_MS;
720
864
  /** Screen silence that means the TUI sits at its prompt, ready for keys. */
721
865
  const READY_QUIET_MS = 800;
866
+ /** A terminal younger than this is still setting up, however quiet it looks. */
867
+ const SETUP_MS = 1500;
722
868
  /** A fresh terminal paints, answers its dialogs and settles within this. */
723
869
  const READY_LIMIT_MS = 30_000;
724
- /** How long a typed message may take to show up in the transcript. */
870
+ /** How many times a panel left open is closed with Esc before the wait goes on regardless. */
871
+ const MAX_PANEL_CLOSES = 3;
872
+ /** How long a slash command may stay out of the transcript before it counts as the terminal's own business. */
725
873
  const ACCEPT_LIMIT_MS = 15_000;
874
+ /** How long a typed message may take to show up in the transcript before it is an error. */
875
+ const ACCEPT_DEADLINE_MS = 2 * ACCEPT_LIMIT_MS;
726
876
  /** How often an unconfirmed message is looked after: Enter again, or typed again. */
727
877
  const ACCEPT_RETRY_MS = 3000;
878
+ /** How much of a message identifies it on the screen. */
879
+ const SNIPPET_LENGTH = 24;
880
+ /** A command that ran this long, with the screen quiet for the next, has said all it will say. */
881
+ const COMMAND_MIN_RUN_MS = 2500;
882
+ const COMMAND_QUIET_MS = 1500;
883
+ const COMMAND_POLL_MS = 2 * POLL_MS;
884
+ /** How long an interrupted turn gets to write what it had before it is read as is. */
885
+ const INTERRUPT_SETTLE_MS = 1500;
886
+ /** Enter comes on its own write, this long after the message. */
887
+ const ENTER_DELAY_MS = 200;
888
+ const FIRST_RUN_DIALOG_HINT = /trust this folder|yes, i accept/i;
889
+ const PANEL_HINT = /esc to (cancel|close|exit)/i;
728
890
  /**
729
891
  * A panel or menu is open and waiting for Esc. Not the first-run dialogs:
730
892
  * Esc there declines the folder and Claude Code quits.
731
893
  */
732
894
  function hasOpenPanel(screen) {
733
- const lower = screen.toLowerCase();
734
- if (lower.includes('trust this folder') || lower.includes('yes, i accept'))
895
+ if (FIRST_RUN_DIALOG_HINT.test(screen))
735
896
  return false;
736
- return lower.includes('esc to cancel') || lower.includes('esc to close') || lower.includes('esc to exit');
897
+ return PANEL_HINT.test(screen);
737
898
  }
738
899
  /** The screen a command left, as text for the chat: without the hint lines and the empty tail. */
739
900
  function commandOutput(screen, command) {
@@ -742,18 +903,13 @@ function commandOutput(screen, command) {
742
903
  const at = lines.map((line) => line.includes(command)).lastIndexOf(true);
743
904
  return lines
744
905
  .slice(at + 1)
745
- .filter((line) => !/esc to (cancel|close|exit)/i.test(line))
906
+ .filter((line) => !PANEL_HINT.test(line))
746
907
  .join('\n')
747
908
  .replace(/\s+$/, '')
748
909
  .replace(/^\s*\n/, '');
749
910
  }
750
911
  /** Lines Claude Code draws under its input box, and only there. */
751
- const INPUT_FOOTERS = ['shift+tab to cycle', '? for shortcuts', 'for shortcuts'];
752
- /** How long an interrupted turn gets to write what it had before it is read as is. */
753
- const INTERRUPT_SETTLE_MS = 1500;
754
- /** Bracketed paste: the TUI takes the text as one paste, newlines and all. */
755
- const PASTE_START = ESC + '[200~';
756
- const PASTE_END = ESC + '[201~';
912
+ const INPUT_FOOTERS = ['shift+tab to cycle', 'for shortcuts'];
757
913
  /**
758
914
  * The `UserPromptSubmit` hook of a conversation terminal: whatever Rookery
759
915
  * wrote into the context file for this one message goes to Claude Code as
@@ -762,8 +918,8 @@ const PASTE_END = ESC + '[201~';
762
918
  * the command runs through whichever shell Claude Code picks.
763
919
  */
764
920
  export function promptContextHookCommand(contextFile) {
765
- const node = process.execPath.replace(/\\/g, '/');
766
- const target = contextFile.replace(/\\/g, '/').replace(/'/g, "\\'");
921
+ const node = forwardSlashes(process.execPath);
922
+ const target = quotedInScript(contextFile);
767
923
  const script = "const fs=require('fs');const f='" + target + "';let t='';" +
768
924
  "try{t=fs.readFileSync(f,'utf8');fs.writeFileSync(f,'')}catch(e){}" +
769
925
  "if(t.trim())process.stdout.write(JSON.stringify({hookSpecificOutput:{hookEventName:'UserPromptSubmit',additionalContext:t}}))";
@@ -814,11 +970,10 @@ export class ConversationTerminal {
814
970
  tuiSessions.kill(this.key);
815
971
  }
816
972
  /** Nothing being answered right now, neither a submitted message nor a typed one. */
817
- async whenIdle(limitMs = 10 * 60 * 1000) {
973
+ async whenIdle(limitMs = WHEN_IDLE_LIMIT_MS) {
818
974
  const deadline = Date.now() + limitMs;
819
975
  while (Date.now() < deadline && this.alive()) {
820
- const working = this.#pending !== null || this.#typed.length > 0 || tuiSessions.info(this.key)?.state === 'running';
821
- if (!working)
976
+ if (this.#pending === null && !this.#working())
822
977
  return;
823
978
  await sleep(POLL_MS);
824
979
  }
@@ -835,25 +990,48 @@ export class ConversationTerminal {
835
990
  return run;
836
991
  }
837
992
  async #submit(input) {
838
- const failed = (error) => ({
839
- prompt: input.prompt,
840
- answer: '',
841
- events: [],
842
- providerSessionId: this.providerSessionId,
843
- usage: { durationMs: 0 },
844
- error,
845
- });
846
993
  if (!this.alive())
847
- return failed('The terminal is closed.');
994
+ return this.#refused(input, 'The terminal is closed.');
848
995
  await this.#ready(input.signal);
849
996
  if (input.signal?.aborted)
850
- return failed('Cancelled before it was sent.');
997
+ return this.#refused(input, 'Cancelled before it was sent.');
851
998
  if (!this.alive())
852
- return failed('The terminal closed before the message could be sent.');
999
+ return this.#refused(input, 'The terminal closed before the message could be sent.');
853
1000
  await writeFile(contextFileFor(this.watch.spec.workDir), input.context ?? '').catch(() => undefined);
854
1001
  // A turn started while the Stop marker still holds the last answer would
855
1002
  // end the moment it began.
856
1003
  await this.watch.clearMarker();
1004
+ const { pending, ended } = this.#begin(input);
1005
+ tuiSessions.markRunning(this.key);
1006
+ this.#type(input.prompt);
1007
+ const stopListening = this.#interruptOnAbort(pending, input.signal);
1008
+ // A slash command or a `!` shell line is the terminal's own business: it
1009
+ // may never reach the model, so no Stop hook comes. Once the screen has
1010
+ // settled without a model turn starting, it is done - whatever it showed
1011
+ // is on the terminal, which is where a command's output lives anyway.
1012
+ if (/^[/!]/.test(input.prompt.trim()))
1013
+ void this.#settleCommand(pending);
1014
+ else
1015
+ void this.#ensureAccepted(pending);
1016
+ try {
1017
+ return await ended;
1018
+ }
1019
+ finally {
1020
+ stopListening();
1021
+ }
1022
+ }
1023
+ #refused(input, error) {
1024
+ return {
1025
+ prompt: input.prompt,
1026
+ answer: '',
1027
+ events: [],
1028
+ providerSessionId: this.providerSessionId,
1029
+ usage: { durationMs: 0 },
1030
+ error,
1031
+ };
1032
+ }
1033
+ /** Makes the turn the one being answered; `ended` resolves when it is settled. */
1034
+ #begin(input) {
857
1035
  let pending;
858
1036
  const ended = new Promise((resolve) => {
859
1037
  pending = {
@@ -865,83 +1043,78 @@ export class ConversationTerminal {
865
1043
  done: resolve,
866
1044
  };
867
1045
  });
868
- if (!pending)
869
- return failed('The terminal could not take the message.');
870
- const mine = pending;
871
- this.#pending = mine;
872
- tuiSessions.markRunning(this.key);
873
- this.#type(input.prompt);
1046
+ this.#pending = pending;
1047
+ return { pending, ended };
1048
+ }
1049
+ /** Aborting presses Esc for the turn; the returned function stops listening. */
1050
+ #interruptOnAbort(pending, signal) {
874
1051
  const onAbort = () => {
875
1052
  // Esc is what a person presses: Claude Code stops, keeps what it had,
876
1053
  // and writes no Stop payload - so the turn is closed here instead.
877
1054
  tuiSessions.write(this.key, ESC);
878
- setTimeout(() => void this.#interrupted(mine), INTERRUPT_SETTLE_MS);
1055
+ setTimeout(() => void this.#interrupted(pending), INTERRUPT_SETTLE_MS);
879
1056
  };
880
- if (input.signal?.aborted)
1057
+ if (signal?.aborted)
881
1058
  onAbort();
882
1059
  else
883
- input.signal?.addEventListener('abort', onAbort, { once: true });
884
- // A slash command or a `!` shell line is the terminal's own business: it
885
- // may never reach the model, so no Stop hook comes. Once the screen has
886
- // settled without a model turn starting, it is done - whatever it showed
887
- // is on the terminal, which is where a command's output lives anyway.
888
- const command = /^[/!]/.test(input.prompt.trim());
889
- if (command) {
890
- void (async () => {
891
- const typedAt = Date.now();
892
- while (this.#pending === mine && !mine.accepted && Date.now() - typedAt < ACCEPT_LIMIT_MS) {
893
- await sleep(POLL_MS * 2);
894
- if (Date.now() - typedAt > 2500 && Date.now() - this.watch.lastScreen > 1500 && !mine.accepted) {
895
- // What the command put on the screen is its answer - the chat
896
- // cannot see the terminal, so `/cost` there shows the costs. A
897
- // panel it opened is closed again, or the next message would be
898
- // typed into it.
899
- const screen = tuiSessions.screenText(this.key) ?? '';
900
- const output = commandOutput(screen, input.prompt.trim());
901
- // Fenced: a panel is laid out in columns, and markdown would reflow it.
902
- this.#settle(mine, { answer: output ? '```\n' + output + '\n```' : '' });
903
- if (hasOpenPanel(screen))
904
- tuiSessions.write(this.key, ESC);
905
- return;
906
- }
907
- }
908
- // Still running past the limit (a command that started real work
909
- // settles through the Stop hook instead): never leave it hanging.
910
- if (this.#pending === mine && !mine.accepted)
911
- this.#settle(mine, { answer: '' });
912
- })();
1060
+ signal?.addEventListener('abort', onAbort, { once: true });
1061
+ return () => signal?.removeEventListener('abort', onAbort);
1062
+ }
1063
+ /** Ends a slash command's turn once its screen has gone quiet, or when it has run too long to be one. */
1064
+ async #settleCommand(pending) {
1065
+ const command = pending.prompt.trim();
1066
+ const typedAt = Date.now();
1067
+ while (this.#pending === pending && !pending.accepted && Date.now() - typedAt < ACCEPT_LIMIT_MS) {
1068
+ await sleep(COMMAND_POLL_MS);
1069
+ const ranFor = Date.now() - typedAt;
1070
+ const quietFor = Date.now() - this.watch.lastScreen;
1071
+ if (ranFor <= COMMAND_MIN_RUN_MS || quietFor <= COMMAND_QUIET_MS || pending.accepted)
1072
+ continue;
1073
+ // What the command put on the screen is its answer - the chat
1074
+ // cannot see the terminal, so `/cost` there shows the costs. A
1075
+ // panel it opened is closed again, or the next message would be
1076
+ // typed into it.
1077
+ const screen = tuiSessions.screenText(this.key) ?? '';
1078
+ const output = commandOutput(screen, command);
1079
+ // Fenced: a panel is laid out in columns, and markdown would reflow it.
1080
+ this.#settle(pending, { answer: output ? '```\n' + output + '\n```' : '' });
1081
+ if (hasOpenPanel(screen))
1082
+ tuiSessions.write(this.key, ESC);
1083
+ return;
913
1084
  }
914
- // The message has to arrive. Every few seconds without it in the
915
- // transcript, the screen says why: the text sits in the input box (a
916
- // paste the TUI held on to) and gets another Enter, or it is not there at
917
- // all (keys swallowed while the TUI was still setting up) and is typed
918
- // again. Past the limit it is an error, not a turn waiting for ever.
919
- void (async () => {
920
- if (command)
921
- return;
922
- const typedAt = Date.now();
923
- const snippet = input.prompt.replace(/\s+/g, ' ').trim().slice(0, 24);
924
- while (Date.now() - typedAt < ACCEPT_LIMIT_MS * 2) {
925
- await sleep(ACCEPT_RETRY_MS);
926
- if (this.#pending !== mine || mine.accepted)
927
- return;
928
- const screen = tuiSessions.screenText(this.key);
929
- const waiting = screen === null || screen.includes('[Pasted text') || screen.replace(/\s+/g, ' ').includes(snippet);
930
- if (waiting)
931
- tuiSessions.write(this.key, '\r');
932
- else
933
- this.#type(input.prompt);
934
- }
935
- if (this.#pending !== mine || mine.accepted)
1085
+ // Still running past the limit (a command that started real work
1086
+ // settles through the Stop hook instead): never leave it hanging.
1087
+ if (this.#pending === pending && !pending.accepted)
1088
+ this.#settle(pending, { answer: '' });
1089
+ }
1090
+ /**
1091
+ * The message has to arrive. Every few seconds without it in the
1092
+ * transcript, the screen says why: the text sits in the input box (a
1093
+ * paste the TUI held on to) and gets another Enter, or it is not there at
1094
+ * all (keys swallowed while the TUI was still setting up) and is typed
1095
+ * again. Past the limit it is an error, not a turn waiting for ever.
1096
+ */
1097
+ async #ensureAccepted(pending) {
1098
+ const typedAt = Date.now();
1099
+ const snippet = pending.prompt.replace(/\s+/g, ' ').trim().slice(0, SNIPPET_LENGTH);
1100
+ while (Date.now() - typedAt < ACCEPT_DEADLINE_MS) {
1101
+ await sleep(ACCEPT_RETRY_MS);
1102
+ if (this.#pending !== pending || pending.accepted)
936
1103
  return;
937
- this.#settle(mine, { error: 'The terminal did not take the message.' });
938
- })();
939
- try {
940
- return await ended;
941
- }
942
- finally {
943
- input.signal?.removeEventListener('abort', onAbort);
1104
+ const screen = tuiSessions.screenText(this.key);
1105
+ const waiting = screen === null || screen.includes('[Pasted text') || screen.replace(/\s+/g, ' ').includes(snippet);
1106
+ if (waiting)
1107
+ tuiSessions.write(this.key, '\r');
1108
+ else
1109
+ this.#type(pending.prompt);
944
1110
  }
1111
+ if (this.#pending !== pending || pending.accepted)
1112
+ return;
1113
+ this.#settle(pending, { error: 'The terminal did not take the message.' });
1114
+ }
1115
+ /** Claude Code is working: its terminal says so, or a person's message awaits its answer. */
1116
+ #working() {
1117
+ return tuiSessions.info(this.key)?.state === 'running' || this.#typed.length > 0;
945
1118
  }
946
1119
  /**
947
1120
  * Wait until the TUI sits at its prompt: not working, quiet for a moment,
@@ -954,15 +1127,16 @@ export class ConversationTerminal {
954
1127
  const deadline = Date.now() + READY_LIMIT_MS;
955
1128
  let closed = 0;
956
1129
  while (Date.now() < deadline && !signal?.aborted && this.alive()) {
957
- const working = tuiSessions.info(this.key)?.state === 'running' || this.#typed.length > 0;
958
- const quiet = Date.now() - this.#spawned > 1500 && Date.now() - this.watch.lastScreen > READY_QUIET_MS;
1130
+ const resting = !this.#working() &&
1131
+ Date.now() - this.#spawned > SETUP_MS &&
1132
+ Date.now() - this.watch.lastScreen > READY_QUIET_MS;
959
1133
  const screen = tuiSessions.screenText(this.key);
960
- const prompt = screen === null || INPUT_FOOTERS.some((footer) => screen.includes(footer));
961
- if (!working && quiet && prompt)
1134
+ const atPrompt = screen === null || INPUT_FOOTERS.some((footer) => screen.includes(footer));
1135
+ if (resting && atPrompt)
962
1136
  return;
963
1137
  // A panel left open - by a command typed in the terminal, say - sits
964
1138
  // where the input box would be. Esc closes it, as a person would.
965
- if (!working && quiet && screen !== null && hasOpenPanel(screen) && closed < 3) {
1139
+ if (resting && screen !== null && hasOpenPanel(screen) && closed < MAX_PANEL_CLOSES) {
966
1140
  closed += 1;
967
1141
  tuiSessions.write(this.key, ESC);
968
1142
  await sleep(READY_QUIET_MS);
@@ -976,7 +1150,7 @@ export class ConversationTerminal {
976
1150
  tuiSessions.write(this.key, body);
977
1151
  // Enter on its own write, a beat later: in the same chunk the TUI can read
978
1152
  // it as part of the paste rather than as the key that sends it.
979
- setTimeout(() => tuiSessions.write(this.key, '\r'), 200);
1153
+ setTimeout(() => tuiSessions.write(this.key, '\r'), ENTER_DELAY_MS);
980
1154
  }
981
1155
  async #interrupted(pending) {
982
1156
  if (this.#pending !== pending)
@@ -989,52 +1163,51 @@ export class ConversationTerminal {
989
1163
  if (this.#pending !== pending)
990
1164
  return;
991
1165
  this.#pending = null;
992
- let lastText = '';
993
- for (const event of pending.events)
994
- if (event.type === 'text')
995
- lastText = event.delta.replace(/^\n\n/, '');
996
1166
  pending.done({
997
- prompt: pending.prompt,
998
- answer: extra.answer ?? lastText,
999
- events: pending.events,
1000
- ...(this.watch.model ? { model: this.watch.model } : {}),
1001
- providerSessionId: this.providerSessionId,
1002
- usage: {
1003
- durationMs: Date.now() - pending.started,
1004
- ...(this.watch.contextTokens !== undefined ? { contextTokens: this.watch.contextTokens } : {}),
1005
- },
1167
+ ...this.#turn(pending.prompt, extra.answer ?? lastTextBlock(pending.events), pending.events, pending.started),
1006
1168
  ...(extra.interrupted ? { interrupted: true } : {}),
1007
1169
  ...(extra.error ? { error: extra.error } : {}),
1008
1170
  });
1009
1171
  tuiSessions.linger(this.key);
1010
1172
  }
1173
+ #turn(prompt, answer, events, startedAt) {
1174
+ return {
1175
+ prompt,
1176
+ answer,
1177
+ events,
1178
+ ...(this.watch.model ? { model: this.watch.model } : {}),
1179
+ providerSessionId: this.providerSessionId,
1180
+ usage: this.watch.usage(startedAt),
1181
+ };
1182
+ }
1011
1183
  /** From the read loop: one transcript event, for the submitted turn if there is one. */
1012
1184
  take(event) {
1013
- const pending = this.#pending;
1014
1185
  if (event.type === 'status' && event.label === 'input' && event.detail) {
1015
- // The first message after a submission is the one Rookery typed.
1016
- if (pending && !pending.accepted) {
1017
- pending.accepted = true;
1018
- return;
1019
- }
1020
- if (!pending) {
1021
- if (this.#typed.length === 0 && this.#typedEvents.length === 0)
1022
- this.#typedStarted = Date.now();
1023
- this.#typed.push(event.detail);
1024
- tuiSessions.markRunning(this.key);
1025
- }
1186
+ this.#takeInput(event.detail);
1026
1187
  return;
1027
1188
  }
1028
1189
  if (event.type !== 'text' && event.type !== 'thinking' && event.type !== 'tool')
1029
1190
  return;
1191
+ const pending = this.#pending;
1192
+ if (!pending) {
1193
+ this.#typedEvents.push(event);
1194
+ return;
1195
+ }
1196
+ pending.accepted = true;
1197
+ pending.events.push(event);
1198
+ pending.onEvent(event);
1199
+ }
1200
+ #takeInput(text) {
1201
+ const pending = this.#pending;
1030
1202
  if (pending) {
1203
+ // The first message after a submission is the one Rookery typed.
1031
1204
  pending.accepted = true;
1032
- pending.events.push(event);
1033
- pending.onEvent(event);
1034
- }
1035
- else {
1036
- this.#typedEvents.push(event);
1205
+ return;
1037
1206
  }
1207
+ if (this.#typed.length === 0 && this.#typedEvents.length === 0)
1208
+ this.#typedStarted = Date.now();
1209
+ this.#typed.push(text);
1210
+ tuiSessions.markRunning(this.key);
1038
1211
  }
1039
1212
  /** From the read loop: the Stop hook fired and the transcript caught up. */
1040
1213
  stopped(reported) {
@@ -1048,17 +1221,7 @@ export class ConversationTerminal {
1048
1221
  }
1049
1222
  const answer = reported || this.watch.lastBlock;
1050
1223
  if (this.#typed.length || answer) {
1051
- this.handlers.onTurn({
1052
- prompt: this.#typed.join('\n\n'),
1053
- answer,
1054
- events: this.#typedEvents,
1055
- ...(this.watch.model ? { model: this.watch.model } : {}),
1056
- providerSessionId: this.providerSessionId,
1057
- usage: {
1058
- durationMs: Date.now() - this.#typedStarted,
1059
- ...(this.watch.contextTokens !== undefined ? { contextTokens: this.watch.contextTokens } : {}),
1060
- },
1061
- });
1224
+ this.handlers.onTurn(this.#turn(this.#typed.join('\n\n'), answer, this.#typedEvents, this.#typedStarted));
1062
1225
  }
1063
1226
  this.#typed = [];
1064
1227
  this.#typedEvents = [];
@@ -1072,6 +1235,43 @@ export class ConversationTerminal {
1072
1235
  this.#settle(pending, { error: this.watch.apiError ?? 'Claude Code closed its terminal before answering.' });
1073
1236
  }
1074
1237
  }
1238
+ /**
1239
+ * Reads a conversation terminal's transcript and Stop marker until the
1240
+ * process is gone, handing everything to `terminal`.
1241
+ */
1242
+ async function followConversation(watch, terminal, handlers) {
1243
+ try {
1244
+ while (stillOpen(watch)) {
1245
+ await sleep(POLL_MS);
1246
+ for (const event of await watch.read())
1247
+ terminal.take(event);
1248
+ const payload = await watch.marker();
1249
+ if (payload) {
1250
+ const reported = reportedMessage(payload);
1251
+ const settled = await watch.settle(reported);
1252
+ for (const event of settled.events)
1253
+ terminal.take(event);
1254
+ await watch.clearMarker();
1255
+ if (!settled.holds)
1256
+ continue;
1257
+ terminal.stopped(reported);
1258
+ }
1259
+ if (Date.now() - watch.lastActivity > CONVERSATION_IDLE_MS)
1260
+ tuiSessions.kill(watch.spec.key);
1261
+ }
1262
+ }
1263
+ catch {
1264
+ // A read that throws past its own guards ends the watch, not the server.
1265
+ }
1266
+ finally {
1267
+ // With no watch nobody reads the answers: the process goes with it, so
1268
+ // `onExit` below tells the truth.
1269
+ if (stillOpen(watch))
1270
+ tuiSessions.kill(watch.spec.key);
1271
+ terminal.exited();
1272
+ handlers.onExit();
1273
+ }
1274
+ }
1075
1275
  /**
1076
1276
  * Opens a conversation in Claude Code's own terminal. There is no task and
1077
1277
  * no end: a person or Rookery types, Claude answers. It runs until somebody
@@ -1084,35 +1284,7 @@ export async function startConversationTerminal(spec, resumed, handlers) {
1084
1284
  // A conversation terminal waits for its person first - idle, not working,
1085
1285
  // and closed by itself after an hour of nobody typing.
1086
1286
  tuiSessions.linger(spec.key);
1087
- void (async () => {
1088
- try {
1089
- while (stillOpen(watch)) {
1090
- await sleep(POLL_MS);
1091
- for (const event of await watch.read())
1092
- terminal.take(event);
1093
- const payload = await watch.marker();
1094
- if (payload) {
1095
- const reported = typeof payload.last_assistant_message === 'string' ? payload.last_assistant_message.trim() : '';
1096
- const settled = await watch.settle(reported);
1097
- for (const event of settled.events)
1098
- terminal.take(event);
1099
- await watch.clearMarker();
1100
- if (!settled.holds)
1101
- continue;
1102
- terminal.stopped(reported);
1103
- }
1104
- if (Date.now() - watch.lastActivity > CONVERSATION_IDLE_MS)
1105
- tuiSessions.kill(spec.key);
1106
- }
1107
- }
1108
- catch {
1109
- // A read that throws past its own guards ends the watch, not the server.
1110
- }
1111
- finally {
1112
- terminal.exited();
1113
- handlers.onExit();
1114
- }
1115
- })();
1287
+ void followConversation(watch, terminal, handlers);
1116
1288
  return terminal;
1117
1289
  }
1118
1290
  //# sourceMappingURL=claude-tui.js.map