@bubblebrain-ai/bubble 0.0.63 → 0.0.65

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 (912) hide show
  1. package/README.md +437 -11
  2. package/dist/agent/abort-errors.d.ts +18 -0
  3. package/dist/agent/abort-errors.js +51 -0
  4. package/dist/agent/budget-ledger.d.ts +20 -0
  5. package/dist/agent/budget-ledger.js +45 -0
  6. package/dist/agent/categories.d.ts +100 -0
  7. package/dist/agent/categories.js +203 -0
  8. package/dist/agent/change-tracker.d.ts +40 -0
  9. package/dist/agent/change-tracker.js +89 -0
  10. package/dist/agent/child-runner.d.ts +64 -0
  11. package/dist/agent/child-runner.js +405 -0
  12. package/dist/agent/input-controller.d.ts +14 -0
  13. package/dist/agent/input-controller.js +43 -0
  14. package/dist/agent/internal-reminder-sanitizer.d.ts +25 -0
  15. package/dist/agent/internal-reminder-sanitizer.js +297 -0
  16. package/dist/agent/profiles.d.ts +76 -0
  17. package/dist/agent/profiles.js +526 -0
  18. package/dist/agent/provider-fingerprint.d.ts +6 -0
  19. package/dist/agent/provider-fingerprint.js +89 -0
  20. package/dist/agent/resident-history.d.ts +7 -0
  21. package/dist/agent/resident-history.js +61 -0
  22. package/dist/agent/result-integrator.d.ts +22 -0
  23. package/dist/agent/result-integrator.js +50 -0
  24. package/dist/agent/routing-catalog.d.ts +131 -0
  25. package/dist/agent/routing-catalog.js +260 -0
  26. package/dist/agent/structured-output.d.ts +37 -0
  27. package/dist/agent/structured-output.js +193 -0
  28. package/dist/agent/subagent/router.d.ts +65 -0
  29. package/dist/agent/subagent/router.js +203 -0
  30. package/dist/agent/subagent/runtime.d.ts +235 -0
  31. package/dist/agent/subagent/runtime.js +835 -0
  32. package/dist/agent/subagent-control.d.ts +100 -0
  33. package/dist/agent/subagent-control.js +70 -0
  34. package/dist/agent/subagent-lifecycle-reminder.d.ts +3 -0
  35. package/dist/agent/subagent-lifecycle-reminder.js +112 -0
  36. package/dist/agent/subagent-route-format.d.ts +8 -0
  37. package/dist/agent/subagent-route-format.js +18 -0
  38. package/dist/agent/subagent-scheduler.d.ts +105 -0
  39. package/dist/agent/subagent-scheduler.js +287 -0
  40. package/dist/agent/subagent-store.d.ts +57 -0
  41. package/dist/agent/subagent-store.js +180 -0
  42. package/dist/agent/subagent-summary.d.ts +30 -0
  43. package/dist/agent/subagent-summary.js +74 -0
  44. package/dist/agent/subagent-wait-guidance.d.ts +2 -0
  45. package/dist/agent/subagent-wait-guidance.js +8 -0
  46. package/dist/agent/subtask-policy.d.ts +13 -0
  47. package/dist/agent/subtask-policy.js +56 -0
  48. package/dist/agent/task-lifecycle-reminder.d.ts +26 -0
  49. package/dist/agent/task-lifecycle-reminder.js +59 -0
  50. package/dist/agent/tool-intent.d.ts +45 -0
  51. package/dist/agent/tool-intent.js +318 -0
  52. package/dist/agent/tool-visibility.d.ts +10 -0
  53. package/dist/agent/tool-visibility.js +6 -0
  54. package/dist/agent/transcript-helpers.d.ts +20 -0
  55. package/dist/agent/transcript-helpers.js +63 -0
  56. package/dist/agent/update-queue.d.ts +13 -0
  57. package/dist/agent/update-queue.js +69 -0
  58. package/dist/agent/workflow/control.d.ts +60 -0
  59. package/dist/agent/workflow/control.js +62 -0
  60. package/dist/agent/workflow/errors.d.ts +16 -0
  61. package/dist/agent/workflow/errors.js +24 -0
  62. package/dist/agent/workflow/runs.d.ts +73 -0
  63. package/dist/agent/workflow/runs.js +160 -0
  64. package/dist/agent/workflow/runtime.d.ts +88 -0
  65. package/dist/agent/workflow/runtime.js +319 -0
  66. package/dist/agent/worktree.d.ts +29 -0
  67. package/dist/agent/worktree.js +73 -0
  68. package/dist/agent.d.ts +460 -0
  69. package/dist/agent.js +2210 -0
  70. package/dist/anthropic-thinking.d.ts +4 -0
  71. package/dist/anthropic-thinking.js +11 -0
  72. package/dist/approval/controller.d.ts +71 -0
  73. package/dist/approval/controller.js +286 -0
  74. package/dist/approval/danger.d.ts +13 -0
  75. package/dist/approval/danger.js +55 -0
  76. package/dist/approval/diff-hunks.d.ts +12 -0
  77. package/dist/approval/diff-hunks.js +32 -0
  78. package/dist/approval/protected-paths.d.ts +1 -0
  79. package/dist/approval/protected-paths.js +35 -0
  80. package/dist/approval/session-cache.d.ts +21 -0
  81. package/dist/approval/session-cache.js +38 -0
  82. package/dist/approval/tool-helper.d.ts +14 -0
  83. package/dist/approval/tool-helper.js +47 -0
  84. package/dist/approval/types.d.ts +146 -0
  85. package/dist/approval/types.js +8 -0
  86. package/dist/bin.d.ts +2 -0
  87. package/dist/bin.js +3 -0
  88. package/dist/bubble-home.d.ts +8 -0
  89. package/dist/bubble-home.js +19 -0
  90. package/dist/checkpoints.d.ts +57 -0
  91. package/dist/checkpoints.js +0 -0
  92. package/dist/cli.d.ts +37 -0
  93. package/dist/cli.js +175 -0
  94. package/dist/clipboard.d.ts +14 -0
  95. package/dist/clipboard.js +132 -0
  96. package/dist/config.d.ts +96 -0
  97. package/dist/config.js +287 -0
  98. package/dist/context/budget.d.ts +28 -0
  99. package/dist/context/budget.js +130 -0
  100. package/dist/context/checkpoint.d.ts +18 -0
  101. package/dist/context/checkpoint.js +117 -0
  102. package/dist/context/compact-llm.d.ts +25 -0
  103. package/dist/context/compact-llm.js +175 -0
  104. package/dist/context/compact.d.ts +124 -0
  105. package/dist/context/compact.js +635 -0
  106. package/dist/context/compaction-files.d.ts +44 -0
  107. package/dist/context/compaction-files.js +148 -0
  108. package/dist/context/llm-compactor.d.ts +53 -0
  109. package/dist/context/llm-compactor.js +424 -0
  110. package/dist/context/overflow.d.ts +9 -0
  111. package/dist/context/overflow.js +50 -0
  112. package/dist/context/projector.d.ts +34 -0
  113. package/dist/context/projector.js +251 -0
  114. package/dist/context/prune.d.ts +26 -0
  115. package/dist/context/prune.js +171 -0
  116. package/dist/context/session-write-lock.d.ts +20 -0
  117. package/dist/context/session-write-lock.js +162 -0
  118. package/dist/context/token-estimator.d.ts +14 -0
  119. package/dist/context/token-estimator.js +106 -0
  120. package/dist/context/tool-images.d.ts +3 -0
  121. package/dist/context/tool-images.js +35 -0
  122. package/dist/context/tool-output-truncate.d.ts +24 -0
  123. package/dist/context/tool-output-truncate.js +181 -0
  124. package/dist/context/usage.d.ts +34 -0
  125. package/dist/context/usage.js +230 -0
  126. package/dist/debug-trace.d.ts +27 -0
  127. package/dist/debug-trace.js +401 -0
  128. package/dist/diff-stats.d.ts +5 -0
  129. package/dist/diff-stats.js +21 -0
  130. package/dist/external-runtime/grok-acp.d.ts +56 -0
  131. package/dist/external-runtime/grok-acp.js +386 -0
  132. package/dist/external-runtime/grok-binary.d.ts +25 -0
  133. package/dist/external-runtime/grok-binary.js +108 -0
  134. package/dist/external-runtime/grok-errors.d.ts +7 -0
  135. package/dist/external-runtime/grok-errors.js +15 -0
  136. package/dist/external-runtime/grok-input-policy.d.ts +58 -0
  137. package/dist/external-runtime/grok-input-policy.js +52 -0
  138. package/dist/external-runtime/grok-ndjson.d.ts +14 -0
  139. package/dist/external-runtime/grok-ndjson.js +193 -0
  140. package/dist/external-runtime/grok-network.d.ts +15 -0
  141. package/dist/external-runtime/grok-network.js +81 -0
  142. package/dist/external-runtime/grok-preflight.d.ts +28 -0
  143. package/dist/external-runtime/grok-preflight.js +194 -0
  144. package/dist/external-runtime/grok-process.d.ts +26 -0
  145. package/dist/external-runtime/grok-process.js +184 -0
  146. package/dist/external-runtime/grok-profile.d.ts +32 -0
  147. package/dist/external-runtime/grok-profile.js +419 -0
  148. package/dist/external-runtime/grok-provider.d.ts +31 -0
  149. package/dist/external-runtime/grok-provider.js +41 -0
  150. package/dist/external-runtime/grok-runtime.d.ts +91 -0
  151. package/dist/external-runtime/grok-runtime.js +882 -0
  152. package/dist/external-runtime/index.d.ts +13 -0
  153. package/dist/external-runtime/index.js +13 -0
  154. package/dist/external-runtime/session-policy.d.ts +11 -0
  155. package/dist/external-runtime/session-policy.js +30 -0
  156. package/dist/external-runtime/types.d.ts +65 -0
  157. package/dist/external-runtime/types.js +1 -0
  158. package/dist/feedback/collect.d.ts +7 -0
  159. package/dist/feedback/collect.js +119 -0
  160. package/dist/feedback/config.d.ts +14 -0
  161. package/dist/feedback/config.js +16 -0
  162. package/dist/feedback/redact.d.ts +1 -0
  163. package/dist/feedback/redact.js +25 -0
  164. package/dist/feedback/submit.d.ts +6 -0
  165. package/dist/feedback/submit.js +43 -0
  166. package/dist/feedback/types.d.ts +22 -0
  167. package/dist/feedback/types.js +1 -0
  168. package/dist/feishu/agent-host/approval-card.d.ts +11 -0
  169. package/dist/feishu/agent-host/approval-card.js +85 -0
  170. package/dist/feishu/agent-host/approval-ui.d.ts +59 -0
  171. package/dist/feishu/agent-host/approval-ui.js +214 -0
  172. package/dist/feishu/agent-host/run-driver.d.ts +51 -0
  173. package/dist/feishu/agent-host/run-driver.js +397 -0
  174. package/dist/feishu/agent-host/runtime-deps.d.ts +33 -0
  175. package/dist/feishu/agent-host/runtime-deps.js +8 -0
  176. package/dist/feishu/card/budget.d.ts +40 -0
  177. package/dist/feishu/card/budget.js +134 -0
  178. package/dist/feishu/card/renderer.d.ts +29 -0
  179. package/dist/feishu/card/renderer.js +245 -0
  180. package/dist/feishu/card/run-state-types.d.ts +49 -0
  181. package/dist/feishu/card/run-state-types.js +15 -0
  182. package/dist/feishu/card/run-state.d.ts +21 -0
  183. package/dist/feishu/card/run-state.js +223 -0
  184. package/dist/feishu/channel/channel.d.ts +52 -0
  185. package/dist/feishu/channel/channel.js +74 -0
  186. package/dist/feishu/config.d.ts +24 -0
  187. package/dist/feishu/config.js +97 -0
  188. package/dist/feishu/format.d.ts +6 -0
  189. package/dist/feishu/format.js +14 -0
  190. package/dist/feishu/index.d.ts +4 -0
  191. package/dist/feishu/index.js +4 -0
  192. package/dist/feishu/logger.d.ts +31 -0
  193. package/dist/feishu/logger.js +62 -0
  194. package/dist/feishu/paths.d.ts +12 -0
  195. package/dist/feishu/paths.js +38 -0
  196. package/dist/feishu/process-registry.d.ts +29 -0
  197. package/dist/feishu/process-registry.js +90 -0
  198. package/dist/feishu/router/commands.d.ts +38 -0
  199. package/dist/feishu/router/commands.js +286 -0
  200. package/dist/feishu/router/event-router.d.ts +40 -0
  201. package/dist/feishu/router/event-router.js +208 -0
  202. package/dist/feishu/router/whitelist.d.ts +23 -0
  203. package/dist/feishu/router/whitelist.js +20 -0
  204. package/dist/feishu/runtime/active-runs.d.ts +32 -0
  205. package/dist/feishu/runtime/active-runs.js +84 -0
  206. package/dist/feishu/runtime/pending-queue.d.ts +36 -0
  207. package/dist/feishu/runtime/pending-queue.js +98 -0
  208. package/dist/feishu/runtime/process-pool.d.ts +29 -0
  209. package/dist/feishu/runtime/process-pool.js +49 -0
  210. package/dist/feishu/schema.d.ts +17 -0
  211. package/dist/feishu/schema.js +252 -0
  212. package/dist/feishu/scope/scope-registry.d.ts +39 -0
  213. package/dist/feishu/scope/scope-registry.js +148 -0
  214. package/dist/feishu/scope/session-binder.d.ts +44 -0
  215. package/dist/feishu/scope/session-binder.js +100 -0
  216. package/dist/feishu/scope/session-store.d.ts +24 -0
  217. package/dist/feishu/scope/session-store.js +73 -0
  218. package/dist/feishu/secrets.d.ts +37 -0
  219. package/dist/feishu/secrets.js +129 -0
  220. package/dist/feishu/serve.d.ts +12 -0
  221. package/dist/feishu/serve.js +302 -0
  222. package/dist/feishu/types.d.ts +75 -0
  223. package/dist/feishu/types.js +23 -0
  224. package/dist/feishu/wizard.d.ts +24 -0
  225. package/dist/feishu/wizard.js +121 -0
  226. package/dist/goal/command.d.ts +20 -0
  227. package/dist/goal/command.js +76 -0
  228. package/dist/goal/engine.d.ts +33 -0
  229. package/dist/goal/engine.js +65 -0
  230. package/dist/goal/format.d.ts +18 -0
  231. package/dist/goal/format.js +112 -0
  232. package/dist/goal/prompts.d.ts +13 -0
  233. package/dist/goal/prompts.js +84 -0
  234. package/dist/goal/store.d.ts +64 -0
  235. package/dist/goal/store.js +174 -0
  236. package/dist/goal/tools.d.ts +13 -0
  237. package/dist/goal/tools.js +67 -0
  238. package/dist/goal/usage.d.ts +2 -0
  239. package/dist/goal/usage.js +3 -0
  240. package/dist/hooks/config.d.ts +9 -0
  241. package/dist/hooks/config.js +278 -0
  242. package/dist/hooks/controller.d.ts +24 -0
  243. package/dist/hooks/controller.js +254 -0
  244. package/dist/hooks/index.d.ts +6 -0
  245. package/dist/hooks/index.js +4 -0
  246. package/dist/hooks/log.d.ts +14 -0
  247. package/dist/hooks/log.js +54 -0
  248. package/dist/hooks/runner.d.ts +5 -0
  249. package/dist/hooks/runner.js +225 -0
  250. package/dist/hooks/trust.d.ts +37 -0
  251. package/dist/hooks/trust.js +143 -0
  252. package/dist/hooks/types.d.ts +173 -0
  253. package/dist/hooks/types.js +46 -0
  254. package/dist/loop/engine.d.ts +29 -0
  255. package/dist/loop/engine.js +63 -0
  256. package/dist/lsp/config.d.ts +18 -0
  257. package/dist/lsp/config.js +58 -0
  258. package/dist/lsp/diagnostics.d.ts +24 -0
  259. package/dist/lsp/diagnostics.js +103 -0
  260. package/dist/lsp/index.d.ts +3 -0
  261. package/dist/lsp/index.js +3 -0
  262. package/dist/lsp/service.d.ts +97 -0
  263. package/dist/lsp/service.js +815 -0
  264. package/dist/main.d.ts +5 -0
  265. package/dist/main.js +984 -0
  266. package/dist/mcp/client.d.ts +68 -0
  267. package/dist/mcp/client.js +177 -0
  268. package/dist/mcp/config.d.ts +30 -0
  269. package/dist/mcp/config.js +144 -0
  270. package/dist/mcp/manager.d.ts +67 -0
  271. package/dist/mcp/manager.js +328 -0
  272. package/dist/mcp/name.d.ts +26 -0
  273. package/dist/mcp/name.js +40 -0
  274. package/dist/mcp/transports.d.ts +54 -0
  275. package/dist/mcp/transports.js +267 -0
  276. package/dist/mcp/types.d.ts +111 -0
  277. package/dist/mcp/types.js +14 -0
  278. package/dist/memory/db.d.ts +65 -0
  279. package/dist/memory/db.js +332 -0
  280. package/dist/memory/index.d.ts +10 -0
  281. package/dist/memory/index.js +10 -0
  282. package/dist/memory/paths.d.ts +18 -0
  283. package/dist/memory/paths.js +38 -0
  284. package/dist/memory/phase1.d.ts +23 -0
  285. package/dist/memory/phase1.js +292 -0
  286. package/dist/memory/phase2.d.ts +19 -0
  287. package/dist/memory/phase2.js +119 -0
  288. package/dist/memory/prompts.d.ts +19 -0
  289. package/dist/memory/prompts.js +104 -0
  290. package/dist/memory/reset.d.ts +1 -0
  291. package/dist/memory/reset.js +13 -0
  292. package/dist/memory/session-policy.d.ts +25 -0
  293. package/dist/memory/session-policy.js +55 -0
  294. package/dist/memory/start.d.ts +24 -0
  295. package/dist/memory/start.js +50 -0
  296. package/dist/memory/storage.d.ts +11 -0
  297. package/dist/memory/storage.js +95 -0
  298. package/dist/memory/store.d.ts +43 -0
  299. package/dist/memory/store.js +193 -0
  300. package/dist/memory/usage.d.ts +1 -0
  301. package/dist/memory/usage.js +38 -0
  302. package/dist/model-catalog.d.ts +65 -0
  303. package/dist/model-catalog.js +399 -0
  304. package/dist/model-config.d.ts +40 -0
  305. package/dist/model-config.js +74 -0
  306. package/dist/model-data.generated.d.ts +16 -0
  307. package/dist/model-data.generated.js +275 -0
  308. package/dist/model-pricing.d.ts +54 -0
  309. package/dist/model-pricing.js +256 -0
  310. package/dist/model-selection.d.ts +7 -0
  311. package/dist/model-selection.js +18 -0
  312. package/dist/network/chatgpt-transport.d.ts +16 -0
  313. package/dist/network/chatgpt-transport.js +232 -0
  314. package/dist/network/errors.d.ts +47 -0
  315. package/dist/network/errors.js +48 -0
  316. package/dist/network/provider-transport-log.d.ts +12 -0
  317. package/dist/network/provider-transport-log.js +32 -0
  318. package/dist/network/provider-transport.d.ts +37 -0
  319. package/dist/network/provider-transport.js +256 -0
  320. package/dist/network/retry.d.ts +34 -0
  321. package/dist/network/retry.js +97 -0
  322. package/dist/network/system-proxy.d.ts +18 -0
  323. package/dist/network/system-proxy.js +175 -0
  324. package/dist/oauth/grok.d.ts +26 -0
  325. package/dist/oauth/grok.js +251 -0
  326. package/dist/oauth/index.d.ts +4 -0
  327. package/dist/oauth/index.js +3 -0
  328. package/dist/oauth/openai-codex.d.ts +15 -0
  329. package/dist/oauth/openai-codex.js +193 -0
  330. package/dist/oauth/refresh-control.d.ts +12 -0
  331. package/dist/oauth/refresh-control.js +42 -0
  332. package/dist/oauth/storage.d.ts +88 -0
  333. package/dist/oauth/storage.js +357 -0
  334. package/dist/oauth/types.d.ts +15 -0
  335. package/dist/oauth/types.js +1 -0
  336. package/dist/orchestrator/default-hooks.d.ts +22 -0
  337. package/dist/orchestrator/default-hooks.js +127 -0
  338. package/dist/orchestrator/hooks.d.ts +69 -0
  339. package/dist/orchestrator/hooks.js +52 -0
  340. package/dist/permission/mode.d.ts +19 -0
  341. package/dist/permission/mode.js +16 -0
  342. package/dist/permissions/rule.d.ts +42 -0
  343. package/dist/permissions/rule.js +293 -0
  344. package/dist/permissions/settings.d.ts +97 -0
  345. package/dist/permissions/settings.js +289 -0
  346. package/dist/permissions/shell-command.d.ts +36 -0
  347. package/dist/permissions/shell-command.js +226 -0
  348. package/dist/permissions/trust-prompt.d.ts +10 -0
  349. package/dist/permissions/trust-prompt.js +34 -0
  350. package/dist/permissions/trust.d.ts +26 -0
  351. package/dist/permissions/trust.js +113 -0
  352. package/dist/permissions/types.d.ts +61 -0
  353. package/dist/permissions/types.js +14 -0
  354. package/dist/print-output.d.ts +98 -0
  355. package/dist/print-output.js +117 -0
  356. package/dist/prompt/compose.d.ts +19 -0
  357. package/dist/prompt/compose.js +110 -0
  358. package/dist/prompt/delegation.d.ts +14 -0
  359. package/dist/prompt/delegation.js +100 -0
  360. package/dist/prompt/environment.d.ts +12 -0
  361. package/dist/prompt/environment.js +55 -0
  362. package/dist/prompt/provider-prompts/anthropic.d.ts +1 -0
  363. package/dist/prompt/provider-prompts/anthropic.js +5 -0
  364. package/dist/prompt/provider-prompts/codex.d.ts +1 -0
  365. package/dist/prompt/provider-prompts/codex.js +5 -0
  366. package/dist/prompt/provider-prompts/deepseek.d.ts +1 -0
  367. package/dist/prompt/provider-prompts/deepseek.js +7 -0
  368. package/dist/prompt/provider-prompts/default.d.ts +1 -0
  369. package/dist/prompt/provider-prompts/default.js +6 -0
  370. package/dist/prompt/provider-prompts/gemini.d.ts +1 -0
  371. package/dist/prompt/provider-prompts/gemini.js +5 -0
  372. package/dist/prompt/provider-prompts/glm.d.ts +1 -0
  373. package/dist/prompt/provider-prompts/glm.js +7 -0
  374. package/dist/prompt/provider-prompts/gpt.d.ts +1 -0
  375. package/dist/prompt/provider-prompts/gpt.js +5 -0
  376. package/dist/prompt/provider-prompts/kimi.d.ts +1 -0
  377. package/dist/prompt/provider-prompts/kimi.js +8 -0
  378. package/dist/prompt/reminders.d.ts +33 -0
  379. package/dist/prompt/reminders.js +135 -0
  380. package/dist/prompt/routing.d.ts +14 -0
  381. package/dist/prompt/routing.js +71 -0
  382. package/dist/prompt/runtime.d.ts +12 -0
  383. package/dist/prompt/runtime.js +40 -0
  384. package/dist/prompt/task-reminders.d.ts +12 -0
  385. package/dist/prompt/task-reminders.js +64 -0
  386. package/dist/provider-ai-sdk.d.ts +59 -0
  387. package/dist/provider-ai-sdk.js +584 -0
  388. package/dist/provider-anthropic.d.ts +126 -0
  389. package/dist/provider-anthropic.js +940 -0
  390. package/dist/provider-ark-responses.d.ts +29 -0
  391. package/dist/provider-ark-responses.js +518 -0
  392. package/dist/provider-artifacts.d.ts +7 -0
  393. package/dist/provider-artifacts.js +60 -0
  394. package/dist/provider-error-record.d.ts +43 -0
  395. package/dist/provider-error-record.js +213 -0
  396. package/dist/provider-grok.d.ts +50 -0
  397. package/dist/provider-grok.js +110 -0
  398. package/dist/provider-model-policy.d.ts +16 -0
  399. package/dist/provider-model-policy.js +33 -0
  400. package/dist/provider-openai-codex.d.ts +66 -0
  401. package/dist/provider-openai-codex.js +781 -0
  402. package/dist/provider-registry.d.ts +197 -0
  403. package/dist/provider-registry.js +1194 -0
  404. package/dist/provider-transform.d.ts +12 -0
  405. package/dist/provider-transform.js +293 -0
  406. package/dist/provider-zen-errors.d.ts +9 -0
  407. package/dist/provider-zen-errors.js +36 -0
  408. package/dist/provider.d.ts +85 -0
  409. package/dist/provider.js +925 -0
  410. package/dist/question/controller.d.ts +22 -0
  411. package/dist/question/controller.js +98 -0
  412. package/dist/question/index.d.ts +2 -0
  413. package/dist/question/index.js +2 -0
  414. package/dist/question/normalize.d.ts +6 -0
  415. package/dist/question/normalize.js +11 -0
  416. package/dist/question/types.d.ts +42 -0
  417. package/dist/question/types.js +6 -0
  418. package/dist/reasoning-debug.d.ts +7 -0
  419. package/dist/reasoning-debug.js +33 -0
  420. package/dist/rewind.d.ts +20 -0
  421. package/dist/rewind.js +29 -0
  422. package/dist/sdk/index.d.ts +319 -0
  423. package/dist/sdk/index.js +1068 -0
  424. package/dist/sdk/replay-event-log.d.ts +26 -0
  425. package/dist/sdk/replay-event-log.js +122 -0
  426. package/dist/sdk/session-turn-coordinator.d.ts +45 -0
  427. package/dist/sdk/session-turn-coordinator.js +227 -0
  428. package/dist/session-context-fence.d.ts +16 -0
  429. package/dist/session-context-fence.js +26 -0
  430. package/dist/session-log.d.ts +25 -0
  431. package/dist/session-log.js +444 -0
  432. package/dist/session-title.d.ts +16 -0
  433. package/dist/session-title.js +131 -0
  434. package/dist/session-types.d.ts +86 -0
  435. package/dist/session-types.js +1 -0
  436. package/dist/session.d.ts +135 -0
  437. package/dist/session.js +664 -0
  438. package/dist/skills/discovery.d.ts +12 -0
  439. package/dist/skills/discovery.js +166 -0
  440. package/dist/skills/format.d.ts +32 -0
  441. package/dist/skills/format.js +68 -0
  442. package/dist/skills/frontmatter.d.ts +5 -0
  443. package/dist/skills/frontmatter.js +60 -0
  444. package/dist/skills/invocation.d.ts +8 -0
  445. package/dist/skills/invocation.js +33 -0
  446. package/dist/skills/registry.d.ts +28 -0
  447. package/dist/skills/registry.js +79 -0
  448. package/dist/skills/types.d.ts +34 -0
  449. package/dist/skills/types.js +1 -0
  450. package/dist/slash-commands/commands.d.ts +10 -0
  451. package/dist/slash-commands/commands.js +1251 -0
  452. package/dist/slash-commands/feishu.d.ts +17 -0
  453. package/dist/slash-commands/feishu.js +400 -0
  454. package/dist/slash-commands/index.d.ts +4 -0
  455. package/dist/slash-commands/index.js +8 -0
  456. package/dist/slash-commands/registry.d.ts +32 -0
  457. package/dist/slash-commands/registry.js +73 -0
  458. package/dist/slash-commands/types.d.ts +109 -0
  459. package/dist/slash-commands/types.js +1 -0
  460. package/dist/slash-commands/unified.d.ts +38 -0
  461. package/dist/slash-commands/unified.js +38 -0
  462. package/dist/stats/usage.d.ts +59 -0
  463. package/dist/stats/usage.js +485 -0
  464. package/dist/stream-json.d.ts +13 -0
  465. package/dist/stream-json.js +74 -0
  466. package/dist/system-prompt.d.ts +40 -0
  467. package/dist/system-prompt.js +7 -0
  468. package/dist/tasks/manager.d.ts +145 -0
  469. package/dist/tasks/manager.js +634 -0
  470. package/dist/tasks/process-utils.d.ts +10 -0
  471. package/dist/tasks/process-utils.js +49 -0
  472. package/dist/tasks/promotion.d.ts +17 -0
  473. package/dist/tasks/promotion.js +30 -0
  474. package/dist/tasks/wake.d.ts +53 -0
  475. package/dist/tasks/wake.js +125 -0
  476. package/dist/text-display.d.ts +3 -0
  477. package/dist/text-display.js +25 -0
  478. package/dist/tools/agent-lifecycle.d.ts +30 -0
  479. package/dist/tools/agent-lifecycle.js +790 -0
  480. package/dist/tools/bash.d.ts +23 -0
  481. package/dist/tools/bash.js +443 -0
  482. package/dist/tools/child-tools.d.ts +41 -0
  483. package/dist/tools/child-tools.js +122 -0
  484. package/dist/tools/edit-apply.d.ts +25 -0
  485. package/dist/tools/edit-apply.js +274 -0
  486. package/dist/tools/edit.d.ts +18 -0
  487. package/dist/tools/edit.js +200 -0
  488. package/dist/tools/exa-mcp.d.ts +3 -0
  489. package/dist/tools/exa-mcp.js +74 -0
  490. package/dist/tools/exit-plan-mode.d.ts +22 -0
  491. package/dist/tools/exit-plan-mode.js +79 -0
  492. package/dist/tools/file-mutation-queue.d.ts +2 -0
  493. package/dist/tools/file-mutation-queue.js +43 -0
  494. package/dist/tools/file-state.d.ts +48 -0
  495. package/dist/tools/file-state.js +76 -0
  496. package/dist/tools/grep.d.ts +9 -0
  497. package/dist/tools/grep.js +387 -0
  498. package/dist/tools/index.d.ts +63 -0
  499. package/dist/tools/index.js +76 -0
  500. package/dist/tools/ls.d.ts +3 -0
  501. package/dist/tools/ls.js +85 -0
  502. package/dist/tools/lsp.d.ts +4 -0
  503. package/dist/tools/lsp.js +95 -0
  504. package/dist/tools/memory.d.ts +8 -0
  505. package/dist/tools/memory.js +77 -0
  506. package/dist/tools/path-utils.d.ts +8 -0
  507. package/dist/tools/path-utils.js +53 -0
  508. package/dist/tools/prompt-metadata.d.ts +3 -0
  509. package/dist/tools/prompt-metadata.js +17 -0
  510. package/dist/tools/question.d.ts +3 -0
  511. package/dist/tools/question.js +177 -0
  512. package/dist/tools/read.d.ts +8 -0
  513. package/dist/tools/read.js +309 -0
  514. package/dist/tools/sensitive-paths.d.ts +11 -0
  515. package/dist/tools/sensitive-paths.js +106 -0
  516. package/dist/tools/server-manager.d.ts +6 -0
  517. package/dist/tools/server-manager.js +6 -0
  518. package/dist/tools/server.d.ts +6 -0
  519. package/dist/tools/server.js +249 -0
  520. package/dist/tools/skill-search.d.ts +10 -0
  521. package/dist/tools/skill-search.js +134 -0
  522. package/dist/tools/skill.d.ts +7 -0
  523. package/dist/tools/skill.js +81 -0
  524. package/dist/tools/task-tools.d.ts +10 -0
  525. package/dist/tools/task-tools.js +133 -0
  526. package/dist/tools/tool-search.d.ts +23 -0
  527. package/dist/tools/tool-search.js +145 -0
  528. package/dist/tools/web-fetch.d.ts +6 -0
  529. package/dist/tools/web-fetch.js +76 -0
  530. package/dist/tools/web-search.d.ts +5 -0
  531. package/dist/tools/web-search.js +50 -0
  532. package/dist/tools/write.d.ts +10 -0
  533. package/dist/tools/write.js +155 -0
  534. package/dist/tui/animation-clock.d.ts +14 -0
  535. package/dist/tui/animation-clock.js +34 -0
  536. package/dist/tui/app.d.ts +176 -0
  537. package/dist/tui/app.js +1659 -0
  538. package/dist/tui/components/approval-dialog.d.ts +43 -0
  539. package/dist/tui/components/approval-dialog.js +212 -0
  540. package/dist/tui/components/bottom-sheet.d.ts +9 -0
  541. package/dist/tui/components/bottom-sheet.js +32 -0
  542. package/dist/tui/components/context-info.d.ts +54 -0
  543. package/dist/tui/components/context-info.js +388 -0
  544. package/dist/tui/components/feedback-dialog.d.ts +56 -0
  545. package/dist/tui/components/feedback-dialog.js +262 -0
  546. package/dist/tui/components/feishu-setup-dialog.d.ts +65 -0
  547. package/dist/tui/components/feishu-setup-dialog.js +332 -0
  548. package/dist/tui/components/image-preview.d.ts +32 -0
  549. package/dist/tui/components/image-preview.js +130 -0
  550. package/dist/tui/components/plan-dialog.d.ts +34 -0
  551. package/dist/tui/components/plan-dialog.js +196 -0
  552. package/dist/tui/components/provider-key-input.d.ts +18 -0
  553. package/dist/tui/components/provider-key-input.js +49 -0
  554. package/dist/tui/components/question-dialog.d.ts +25 -0
  555. package/dist/tui/components/question-dialog.js +263 -0
  556. package/dist/tui/components/responsive-transcript.d.ts +31 -0
  557. package/dist/tui/components/responsive-transcript.js +77 -0
  558. package/dist/tui/components/rewind-picker.d.ts +62 -0
  559. package/dist/tui/components/rewind-picker.js +317 -0
  560. package/dist/tui/components/session-picker.d.ts +49 -0
  561. package/dist/tui/components/session-picker.js +303 -0
  562. package/dist/tui/components/skills-panel.d.ts +63 -0
  563. package/dist/tui/components/skills-panel.js +582 -0
  564. package/dist/tui/components/stats-panel.d.ts +40 -0
  565. package/dist/tui/components/stats-panel.js +301 -0
  566. package/dist/tui/components/streaming-message.d.ts +69 -0
  567. package/dist/tui/components/streaming-message.js +398 -0
  568. package/dist/tui/components/subagent-inspector.d.ts +28 -0
  569. package/dist/tui/components/subagent-inspector.js +127 -0
  570. package/dist/tui/components/task-inspector.d.ts +26 -0
  571. package/dist/tui/components/task-inspector.js +70 -0
  572. package/dist/tui/components/tasks-pane.d.ts +126 -0
  573. package/dist/tui/components/tasks-pane.js +566 -0
  574. package/dist/tui/components/transcript.d.ts +103 -0
  575. package/dist/tui/components/transcript.js +858 -0
  576. package/dist/tui/components/welcome.d.ts +20 -0
  577. package/dist/tui/components/welcome.js +133 -0
  578. package/dist/tui/components/workflow-inspector.d.ts +30 -0
  579. package/dist/tui/components/workflow-inspector.js +136 -0
  580. package/dist/tui/composer-autocomplete.d.ts +76 -0
  581. package/dist/tui/composer-autocomplete.js +465 -0
  582. package/dist/tui/composer-style.d.ts +7 -0
  583. package/dist/tui/composer-style.js +29 -0
  584. package/dist/tui/controller/agent-event-reducer.d.ts +75 -0
  585. package/dist/tui/controller/agent-event-reducer.js +239 -0
  586. package/dist/tui/controller/composer-controller.d.ts +95 -0
  587. package/dist/tui/controller/composer-controller.js +502 -0
  588. package/dist/tui/controller/controller.d.ts +199 -0
  589. package/dist/tui/controller/controller.js +1034 -0
  590. package/dist/tui/controller/effects.d.ts +71 -0
  591. package/dist/tui/controller/effects.js +1 -0
  592. package/dist/tui/controller/goal-runtime-controller.d.ts +47 -0
  593. package/dist/tui/controller/goal-runtime-controller.js +202 -0
  594. package/dist/tui/controller/input-queue-machine.d.ts +71 -0
  595. package/dist/tui/controller/input-queue-machine.js +121 -0
  596. package/dist/tui/controller/intents.d.ts +56 -0
  597. package/dist/tui/controller/intents.js +6 -0
  598. package/dist/tui/controller/overlay-controller.d.ts +64 -0
  599. package/dist/tui/controller/overlay-controller.js +129 -0
  600. package/dist/tui/controller/ports.d.ts +57 -0
  601. package/dist/tui/controller/ports.js +9 -0
  602. package/dist/tui/controller/session-transition.d.ts +54 -0
  603. package/dist/tui/controller/session-transition.js +68 -0
  604. package/dist/tui/controller/state.d.ts +14 -0
  605. package/dist/tui/controller/state.js +36 -0
  606. package/dist/tui/controller/task-runtime-controller.d.ts +66 -0
  607. package/dist/tui/controller/task-runtime-controller.js +158 -0
  608. package/dist/tui/detect-theme.d.ts +4 -0
  609. package/dist/tui/detect-theme.js +116 -0
  610. package/dist/tui/display-history.d.ts +64 -0
  611. package/dist/tui/display-history.js +283 -0
  612. package/dist/tui/display-sanitizer.d.ts +3 -0
  613. package/dist/tui/display-sanitizer.js +38 -0
  614. package/dist/tui/edit-diff.d.ts +11 -0
  615. package/dist/tui/edit-diff.js +57 -0
  616. package/dist/tui/file-mentions.d.ts +29 -0
  617. package/dist/tui/file-mentions.js +174 -0
  618. package/dist/tui/footer.d.ts +37 -0
  619. package/dist/tui/footer.js +80 -0
  620. package/dist/tui/formatting/edit-diff.d.ts +11 -0
  621. package/dist/tui/formatting/edit-diff.js +52 -0
  622. package/dist/tui/formatting/summary.d.ts +43 -0
  623. package/dist/tui/formatting/summary.js +150 -0
  624. package/dist/tui/fullscreen.d.ts +48 -0
  625. package/dist/tui/fullscreen.js +256 -0
  626. package/dist/tui/image-display.d.ts +23 -0
  627. package/dist/tui/image-display.js +92 -0
  628. package/dist/tui/image-paste.d.ts +113 -0
  629. package/dist/tui/image-paste.js +565 -0
  630. package/dist/tui/input-history.d.ts +47 -0
  631. package/dist/tui/input-history.js +250 -0
  632. package/dist/tui/markdown-style.d.ts +5 -0
  633. package/dist/tui/markdown-style.js +23 -0
  634. package/dist/tui/model/composer-buffer.d.ts +55 -0
  635. package/dist/tui/model/composer-buffer.js +317 -0
  636. package/dist/tui/model/composer-types.d.ts +17 -0
  637. package/dist/tui/model/composer-types.js +1 -0
  638. package/dist/tui/model/display-history.d.ts +78 -0
  639. package/dist/tui/model/display-history.js +124 -0
  640. package/dist/tui/model/display-reconstruct.d.ts +3 -0
  641. package/dist/tui/model/display-reconstruct.js +130 -0
  642. package/dist/tui/model/file-mentions.d.ts +31 -0
  643. package/dist/tui/model/file-mentions.js +178 -0
  644. package/dist/tui/model/image-attachment.d.ts +15 -0
  645. package/dist/tui/model/image-attachment.js +1 -0
  646. package/dist/tui/model/image-paste.d.ts +119 -0
  647. package/dist/tui/model/image-paste.js +610 -0
  648. package/dist/tui/model/input-history.d.ts +1 -0
  649. package/dist/tui/model/input-history.js +1 -0
  650. package/dist/tui/model/input-queue.d.ts +12 -0
  651. package/dist/tui/model/input-queue.js +17 -0
  652. package/dist/tui/model/key-events.d.ts +9 -0
  653. package/dist/tui/model/key-events.js +8 -0
  654. package/dist/tui/model/paste-operation-tracker.d.ts +13 -0
  655. package/dist/tui/model/paste-operation-tracker.js +25 -0
  656. package/dist/tui/model/recent-activity.d.ts +8 -0
  657. package/dist/tui/model/recent-activity.js +71 -0
  658. package/dist/tui/model/subagent-view.d.ts +87 -0
  659. package/dist/tui/model/subagent-view.js +336 -0
  660. package/dist/tui/model/submit-dedupe.d.ts +5 -0
  661. package/dist/tui/model/submit-dedupe.js +25 -0
  662. package/dist/tui/model/sync-output.d.ts +17 -0
  663. package/dist/tui/model/sync-output.js +35 -0
  664. package/dist/tui/model/task-lifecycle.d.ts +57 -0
  665. package/dist/tui/model/task-lifecycle.js +124 -0
  666. package/dist/tui/model/terminal-env.d.ts +15 -0
  667. package/dist/tui/model/terminal-env.js +22 -0
  668. package/dist/tui/model/terminal-mouse.d.ts +28 -0
  669. package/dist/tui/model/terminal-mouse.js +82 -0
  670. package/dist/tui/model/theme-style.d.ts +10 -0
  671. package/dist/tui/model/theme-style.js +79 -0
  672. package/dist/tui/model/theme.d.ts +72 -0
  673. package/dist/tui/model/theme.js +121 -0
  674. package/dist/tui/model/trace-groups.d.ts +45 -0
  675. package/dist/tui/model/trace-groups.js +558 -0
  676. package/dist/tui/model/trace-interaction.d.ts +63 -0
  677. package/dist/tui/model/trace-interaction.js +87 -0
  678. package/dist/tui/model/width.d.ts +18 -0
  679. package/dist/tui/model/width.js +130 -0
  680. package/dist/tui/model-picker-data.d.ts +9 -0
  681. package/dist/tui/model-picker-data.js +39 -0
  682. package/dist/tui/model-switch.d.ts +49 -0
  683. package/dist/tui/model-switch.js +67 -0
  684. package/dist/tui/paste-placeholder.d.ts +11 -0
  685. package/dist/tui/paste-placeholder.js +52 -0
  686. package/dist/tui/recent-activity.d.ts +8 -0
  687. package/dist/tui/recent-activity.js +71 -0
  688. package/dist/tui/run-session-picker.d.ts +9 -0
  689. package/dist/tui/run-session-picker.js +64 -0
  690. package/dist/tui/run.d.ts +72 -0
  691. package/dist/tui/run.js +139 -0
  692. package/dist/tui/session-display.d.ts +6 -0
  693. package/dist/tui/session-display.js +12 -0
  694. package/dist/tui/session-picker-data.d.ts +18 -0
  695. package/dist/tui/session-picker-data.js +21 -0
  696. package/dist/tui/terminal/multiplexer.d.ts +5 -0
  697. package/dist/tui/terminal/multiplexer.js +14 -0
  698. package/dist/tui/testing/fake-agent.d.ts +24 -0
  699. package/dist/tui/testing/fake-agent.js +22 -0
  700. package/dist/tui/testing/spy-host.d.ts +21 -0
  701. package/dist/tui/testing/spy-host.js +55 -0
  702. package/dist/tui/trace-groups.d.ts +43 -0
  703. package/dist/tui/trace-groups.js +554 -0
  704. package/dist/tui/wordmark.d.ts +18 -0
  705. package/dist/tui/wordmark.js +208 -0
  706. package/dist/types.d.ts +503 -0
  707. package/dist/types.js +4 -0
  708. package/dist/update/index.d.ts +61 -0
  709. package/dist/update/index.js +267 -0
  710. package/dist/variant/thinking-level.d.ts +5 -0
  711. package/dist/variant/thinking-level.js +26 -0
  712. package/dist/variant/variant-resolver.d.ts +28 -0
  713. package/dist/variant/variant-resolver.js +62 -0
  714. package/node_modules/@bubblebrain-ai/pi-tui/LICENSE +21 -0
  715. package/node_modules/@bubblebrain-ai/pi-tui/README.md +854 -0
  716. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/alt-screen-search.d.ts +26 -0
  717. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/alt-screen-search.d.ts.map +1 -0
  718. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/alt-screen-search.js +121 -0
  719. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/alt-screen-search.js.map +1 -0
  720. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/autocomplete.d.ts +86 -0
  721. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/autocomplete.d.ts.map +1 -0
  722. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/autocomplete.js +649 -0
  723. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/autocomplete.js.map +1 -0
  724. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/alt-screen-flash.d.ts +13 -0
  725. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/alt-screen-flash.d.ts.map +1 -0
  726. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/alt-screen-flash.js +36 -0
  727. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/alt-screen-flash.js.map +1 -0
  728. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/box.d.ts +22 -0
  729. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/box.d.ts.map +1 -0
  730. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/box.js +99 -0
  731. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/box.js.map +1 -0
  732. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/cancellable-loader.d.ts +22 -0
  733. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/cancellable-loader.d.ts.map +1 -0
  734. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/cancellable-loader.js +36 -0
  735. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/cancellable-loader.js.map +1 -0
  736. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/editor.d.ts +330 -0
  737. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/editor.d.ts.map +1 -0
  738. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/editor.js +2344 -0
  739. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/editor.js.map +1 -0
  740. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/h-stack.d.ts +7 -0
  741. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/h-stack.d.ts.map +1 -0
  742. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/h-stack.js +43 -0
  743. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/h-stack.js.map +1 -0
  744. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/image.d.ts +28 -0
  745. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/image.d.ts.map +1 -0
  746. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/image.js +82 -0
  747. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/image.js.map +1 -0
  748. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/input.d.ts +48 -0
  749. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/input.d.ts.map +1 -0
  750. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/input.js +390 -0
  751. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/input.js.map +1 -0
  752. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/loader.d.ts +31 -0
  753. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/loader.d.ts.map +1 -0
  754. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/loader.js +67 -0
  755. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/loader.js.map +1 -0
  756. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/markdown.d.ts +103 -0
  757. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/markdown.d.ts.map +1 -0
  758. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/markdown.js +797 -0
  759. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/markdown.js.map +1 -0
  760. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/scroll-view.d.ts +56 -0
  761. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/scroll-view.d.ts.map +1 -0
  762. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/scroll-view.js +179 -0
  763. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/scroll-view.js.map +1 -0
  764. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/select-list.d.ts +53 -0
  765. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/select-list.d.ts.map +1 -0
  766. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/select-list.js +175 -0
  767. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/select-list.js.map +1 -0
  768. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/settings-list.d.ts +50 -0
  769. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/settings-list.d.ts.map +1 -0
  770. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/settings-list.js +174 -0
  771. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/settings-list.js.map +1 -0
  772. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/spacer.d.ts +12 -0
  773. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/spacer.d.ts.map +1 -0
  774. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/spacer.js +22 -0
  775. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/spacer.js.map +1 -0
  776. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/stack.d.ts +32 -0
  777. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/stack.d.ts.map +1 -0
  778. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/stack.js +109 -0
  779. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/stack.js.map +1 -0
  780. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/text.d.ts +19 -0
  781. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/text.d.ts.map +1 -0
  782. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/text.js +81 -0
  783. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/text.js.map +1 -0
  784. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/truncated-text.d.ts +13 -0
  785. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/truncated-text.d.ts.map +1 -0
  786. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/truncated-text.js +48 -0
  787. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/truncated-text.js.map +1 -0
  788. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/v-stack.d.ts +8 -0
  789. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/v-stack.d.ts.map +1 -0
  790. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/v-stack.js +26 -0
  791. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/v-stack.js.map +1 -0
  792. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/editor-component.d.ts +39 -0
  793. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/editor-component.d.ts.map +1 -0
  794. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/editor-component.js +2 -0
  795. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/editor-component.js.map +1 -0
  796. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/fuzzy.d.ts +16 -0
  797. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/fuzzy.d.ts.map +1 -0
  798. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/fuzzy.js +110 -0
  799. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/fuzzy.js.map +1 -0
  800. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/index.d.ts +31 -0
  801. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/index.d.ts.map +1 -0
  802. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/index.js +42 -0
  803. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/index.js.map +1 -0
  804. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keybindings.d.ts +273 -0
  805. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keybindings.d.ts.map +1 -0
  806. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keybindings.js +231 -0
  807. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keybindings.js.map +1 -0
  808. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keys.d.ts +184 -0
  809. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keys.d.ts.map +1 -0
  810. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keys.js +1174 -0
  811. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keys.js.map +1 -0
  812. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/kill-ring.d.ts +28 -0
  813. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/kill-ring.d.ts.map +1 -0
  814. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/kill-ring.js +46 -0
  815. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/kill-ring.js.map +1 -0
  816. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/latex.d.ts +10 -0
  817. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/latex.d.ts.map +1 -0
  818. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/latex.js +1268 -0
  819. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/latex.js.map +1 -0
  820. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout-node.d.ts +40 -0
  821. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout-node.d.ts.map +1 -0
  822. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout-node.js +6 -0
  823. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout-node.js.map +1 -0
  824. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout.d.ts +42 -0
  825. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout.d.ts.map +1 -0
  826. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout.js +335 -0
  827. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout.js.map +1 -0
  828. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/native-modifiers.d.ts +3 -0
  829. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/native-modifiers.d.ts.map +1 -0
  830. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/native-modifiers.js +60 -0
  831. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/native-modifiers.js.map +1 -0
  832. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/stdin-buffer.d.ts +56 -0
  833. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/stdin-buffer.d.ts.map +1 -0
  834. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/stdin-buffer.js +363 -0
  835. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/stdin-buffer.js.map +1 -0
  836. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-colors.d.ts +10 -0
  837. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-colors.d.ts.map +1 -0
  838. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-colors.js +59 -0
  839. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-colors.js.map +1 -0
  840. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-image.d.ts +116 -0
  841. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-image.d.ts.map +1 -0
  842. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-image.js +518 -0
  843. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-image.js.map +1 -0
  844. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal.d.ts +142 -0
  845. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal.d.ts.map +1 -0
  846. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal.js +544 -0
  847. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal.js.map +1 -0
  848. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/testing.d.ts +11 -0
  849. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/testing.d.ts.map +1 -0
  850. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/testing.js +11 -0
  851. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/testing.js.map +1 -0
  852. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-alt-screen.d.ts +141 -0
  853. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-alt-screen.d.ts.map +1 -0
  854. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-alt-screen.js +1340 -0
  855. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-alt-screen.js.map +1 -0
  856. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-main-screen.d.ts +39 -0
  857. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-main-screen.d.ts.map +1 -0
  858. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-main-screen.js +536 -0
  859. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-main-screen.js.map +1 -0
  860. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui.d.ts +340 -0
  861. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui.d.ts.map +1 -0
  862. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui.js +1020 -0
  863. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui.js.map +1 -0
  864. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/undo-stack.d.ts +17 -0
  865. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/undo-stack.d.ts.map +1 -0
  866. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/undo-stack.js +27 -0
  867. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/undo-stack.js.map +1 -0
  868. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/utils.d.ts +96 -0
  869. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/utils.d.ts.map +1 -0
  870. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/utils.js +1193 -0
  871. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/utils.js.map +1 -0
  872. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/word-navigation.d.ts +25 -0
  873. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/word-navigation.d.ts.map +1 -0
  874. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/word-navigation.js +96 -0
  875. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/word-navigation.js.map +1 -0
  876. package/node_modules/@bubblebrain-ai/pi-tui/dist/test/virtual-terminal.d.ts +73 -0
  877. package/node_modules/@bubblebrain-ai/pi-tui/dist/test/virtual-terminal.d.ts.map +1 -0
  878. package/node_modules/@bubblebrain-ai/pi-tui/dist/test/virtual-terminal.js +188 -0
  879. package/node_modules/@bubblebrain-ai/pi-tui/dist/test/virtual-terminal.js.map +1 -0
  880. package/node_modules/@bubblebrain-ai/pi-tui/native/darwin/README.md +20 -0
  881. package/node_modules/@bubblebrain-ai/pi-tui/native/darwin/build.sh +62 -0
  882. package/node_modules/@bubblebrain-ai/pi-tui/native/darwin/prebuilds/darwin-arm64/darwin-modifiers.node +0 -0
  883. package/node_modules/@bubblebrain-ai/pi-tui/native/darwin/prebuilds/darwin-x64/darwin-modifiers.node +0 -0
  884. package/node_modules/@bubblebrain-ai/pi-tui/native/darwin/src/darwin-modifiers.c +70 -0
  885. package/node_modules/@bubblebrain-ai/pi-tui/native/win32/README.md +22 -0
  886. package/node_modules/@bubblebrain-ai/pi-tui/native/win32/build.mjs +229 -0
  887. package/node_modules/@bubblebrain-ai/pi-tui/native/win32/prebuilds/win32-arm64/win32-console-mode.node +0 -0
  888. package/node_modules/@bubblebrain-ai/pi-tui/native/win32/prebuilds/win32-x64/win32-console-mode.node +0 -0
  889. package/node_modules/@bubblebrain-ai/pi-tui/native/win32/src/win32-console-mode.c +119 -0
  890. package/node_modules/@bubblebrain-ai/pi-tui/package.json +66 -0
  891. package/node_modules/get-east-asian-width/index.d.ts +60 -0
  892. package/node_modules/get-east-asian-width/index.js +30 -0
  893. package/node_modules/get-east-asian-width/license +9 -0
  894. package/node_modules/get-east-asian-width/lookup-data.js +21 -0
  895. package/node_modules/get-east-asian-width/lookup.js +138 -0
  896. package/node_modules/get-east-asian-width/package.json +71 -0
  897. package/node_modules/get-east-asian-width/readme.md +65 -0
  898. package/node_modules/get-east-asian-width/utilities.js +24 -0
  899. package/node_modules/marked/LICENSE +44 -0
  900. package/node_modules/marked/README.md +115 -0
  901. package/node_modules/marked/bin/main.js +284 -0
  902. package/node_modules/marked/bin/marked.js +16 -0
  903. package/node_modules/marked/lib/marked.d.ts +760 -0
  904. package/node_modules/marked/lib/marked.esm.js +77 -0
  905. package/node_modules/marked/lib/marked.esm.js.map +7 -0
  906. package/node_modules/marked/lib/marked.umd.js +79 -0
  907. package/node_modules/marked/lib/marked.umd.js.map +7 -0
  908. package/node_modules/marked/man/marked.1 +113 -0
  909. package/node_modules/marked/man/marked.1.md +93 -0
  910. package/node_modules/marked/package.json +103 -0
  911. package/package.json +96 -17
  912. package/bin/bubble.js +0 -39
@@ -0,0 +1,1034 @@
1
+ import { SessionManager } from "../../session.js";
2
+ import { tokenUsageTotal } from "../../goal/usage.js";
3
+ import { ControllerState } from "./state.js";
4
+ import { buildAssistantMessage, createRunState, reduceAgentEvent, reduceRunFinish, STREAMING_FLUSH_INTERVAL_MS, } from "./agent-event-reducer.js";
5
+ import { beginSteer, createInputQueueState, drainLeftoverSteers, purgeForSessionSwitch, } from "./input-queue-machine.js";
6
+ import { AgentRunInputQueue } from "../../agent/input-controller.js";
7
+ import { OverlayRequestController } from "./overlay-controller.js";
8
+ import { SessionTransitionController } from "./session-transition.js";
9
+ import { moveStatusMessageToEnd, nextDisplayMessageKey, setUserInputStatus, snapshotDisplayParts, } from "../model/display-history.js";
10
+ import { applySubagentUpdateToMessages, collectSubagentGroups, mergeSubagentSnapshotsIntoMessages, } from "../model/subagent-view.js";
11
+ import { reconstructDisplayMessages } from "../model/display-reconstruct.js";
12
+ import { applyTaskLifecycleToMessages, landTaskLifecycles, mergeTaskLifecycleIntoLiveTools, taskLifecycleDisplayMessage, UNMATCHED_LAUNCH, } from "../model/task-lifecycle.js";
13
+ import { buildImageContentParts, buildImageContentPartsFromDisplayText } from "../model/image-paste.js";
14
+ import { displayImagesFromPayload, formatImageUserDisplayText } from "../image-display.js";
15
+ import { GoalRuntimeController } from "./goal-runtime-controller.js";
16
+ import { TaskRuntimeController } from "./task-runtime-controller.js";
17
+ import { formatInternalContextBlock } from "../../agent/internal-reminder-sanitizer.js";
18
+ import { executeRewind } from "../../rewind.js";
19
+ function isSubmitPayload(value) {
20
+ if (!value || typeof value !== "object")
21
+ return false;
22
+ const payload = value;
23
+ return typeof payload.text === "string" && Array.isArray(payload.images);
24
+ }
25
+ export class BubbleTuiController {
26
+ deps;
27
+ state = new ControllerState();
28
+ listeners = new Set();
29
+ overlays;
30
+ queue = createInputQueueState();
31
+ sessionTransition;
32
+ startedAtMs;
33
+ turnStartedAt;
34
+ goalRuntime;
35
+ taskRuntime;
36
+ pendingTaskAnnouncements = new Map();
37
+ sessionManager;
38
+ transcript = [];
39
+ runActive = false;
40
+ runState = null;
41
+ /** Provider-turn accumulators for true child-session inspection. */
42
+ childRuns = new Map();
43
+ activeInputController = null;
44
+ activeAbortController = null;
45
+ commandActivity = null;
46
+ /** False after a provider turn commits, so settled and live rows never coexist. */
47
+ liveStreamVisible = false;
48
+ backgroundTaskUnsubscribe;
49
+ disposed = false;
50
+ constructor(deps) {
51
+ this.deps = deps;
52
+ this.sessionManager = deps.sessionManager;
53
+ this.transcript = landTaskLifecycles(reconstructDisplayMessages([...deps.agent.messages]), restoredTaskLifecycles(this.sessionManager));
54
+ this.overlays = new OverlayRequestController();
55
+ this.startedAtMs = Date.now();
56
+ this.sessionTransition = new SessionTransitionController({
57
+ host: deps.ports.sessionHost,
58
+ state: this.state,
59
+ overlays: this.overlays,
60
+ queue: this.queue,
61
+ agent: {
62
+ getMessages: () => deps.agent.messages,
63
+ setSessionID: (file) => deps.agent.setSessionID(file),
64
+ },
65
+ bumpExternalGeneration: () => {
66
+ this.externalGeneration += 1;
67
+ },
68
+ clearLiveSubagentTools: () => {
69
+ this.childRuns.clear();
70
+ },
71
+ commit: (manager, transcript) => {
72
+ this.sessionManager = manager;
73
+ this.deps.ports.flush.cancelFlush();
74
+ this.transcript = landTaskLifecycles(transcript, restoredTaskLifecycles(manager));
75
+ this.queue.queued.length = 0;
76
+ this.liveStreamVisible = false;
77
+ this.runState = null;
78
+ // Session-scoped: the restored session has not started a run, so none
79
+ // of its subagents or tasks belong to a "current turn".
80
+ this.turnStartedAt = undefined;
81
+ this.activeInputController = null;
82
+ this.activeAbortController = null;
83
+ this.commandActivity = null;
84
+ this.state.touch();
85
+ },
86
+ });
87
+ this.overlays.onChange(() => this.state.touch());
88
+ if (deps.goalStore) {
89
+ this.goalRuntime = new GoalRuntimeController({
90
+ store: deps.goalStore,
91
+ getSessionManager: () => this.sessionManager,
92
+ isRunActive: () => this.isBusy(),
93
+ queuedInputs: () => this.queue.queued.length,
94
+ isDisposed: () => this.disposed,
95
+ startRun: (input, cwd) => {
96
+ void this.runTurn(input, cwd, { goalRun: true });
97
+ },
98
+ appendMessage: (role, content) => {
99
+ this.appendDisplayMessage({
100
+ key: nextDisplayMessageKey(role === "user" ? "user" : role === "error" ? "error" : "notice"),
101
+ role,
102
+ content,
103
+ syntheticKind: role === "assistant" ? "ui_notice" : undefined,
104
+ });
105
+ },
106
+ onStateChanged: () => {
107
+ this.state.touch();
108
+ this.notify();
109
+ },
110
+ });
111
+ }
112
+ if (deps.processManager) {
113
+ this.taskRuntime = new TaskRuntimeController({
114
+ processManager: deps.processManager,
115
+ getSessionFile: () => this.sessionManager.getSessionFile(),
116
+ appendMarker: (file, marker, payload) => this.appendTaskMarker(file, marker, payload),
117
+ announceCompletion: (task) => this.announceTaskCompletion(task),
118
+ submitTaskWake: (summary) => {
119
+ const cwd = this.sessionManager.getMetadata().cwd ?? deps.workspaceCwd ?? process.cwd();
120
+ void this.runTurn(formatInternalContextBlock("background-task", summary), cwd);
121
+ },
122
+ tasksAutoResume: deps.tasksAutoResume !== false,
123
+ gates: () => ({
124
+ turnRunning: this.isBusy(),
125
+ queuedInputs: this.queue.queued.length,
126
+ exiting: this.disposed,
127
+ goalActive: this.goalRuntime?.snapshot()?.status === "active",
128
+ }),
129
+ });
130
+ this.taskRuntime.start();
131
+ }
132
+ this.backgroundTaskUnsubscribe = (deps.processManager
133
+ ? deps.processManager.onChange(() => {
134
+ this.state.touch();
135
+ this.notify();
136
+ })
137
+ : deps.agent.backgroundTasks?.subscribe?.(() => {
138
+ this.state.touch();
139
+ this.notify();
140
+ }));
141
+ }
142
+ externalGeneration = 0;
143
+ subscribe(listener) {
144
+ this.listeners.add(listener);
145
+ return () => this.listeners.delete(listener);
146
+ }
147
+ getSnapshotVersion() {
148
+ return this.state.version;
149
+ }
150
+ getTranscript() {
151
+ return this.transcript;
152
+ }
153
+ getSessionManager() {
154
+ return this.sessionManager;
155
+ }
156
+ getGoalIndicator() {
157
+ return this.goalRuntime?.indicatorLine();
158
+ }
159
+ handleGoalCommand(input, cwd) {
160
+ if (!this.goalRuntime) {
161
+ this.appendDisplayMessage({
162
+ key: nextDisplayMessageKey("error"),
163
+ role: "error",
164
+ content: "Goals are not available in this session.",
165
+ });
166
+ return;
167
+ }
168
+ this.goalRuntime.handleCommand(input, cwd);
169
+ }
170
+ getSubagentGroups() {
171
+ // Launches from earlier rounds live in the transcript (kept current by
172
+ // applySubagentUpdateToMessages); this round's launches are still in the
173
+ // streaming accumulator until turn_end commits them.
174
+ const streamingTools = this.runActive && this.runState ? this.runState.accumulator.toolCalls : [];
175
+ const fromTrace = collectSubagentGroups(this.transcript, streamingTools);
176
+ const claimed = new Set(fromTrace.flatMap((group) => group.members.map((member) => member.subAgentId).filter(Boolean)));
177
+ const direct = this.deps.agent.listSubAgents()
178
+ .filter((snapshot) => !claimed.has(snapshot.agentId))
179
+ .map((snapshot) => ({
180
+ id: `single:${snapshot.agentId}`,
181
+ runId: snapshot.runId,
182
+ kind: "single",
183
+ label: snapshot.nickname,
184
+ members: [{
185
+ subAgentId: snapshot.agentId,
186
+ agentName: snapshot.agentName,
187
+ nickname: snapshot.nickname,
188
+ status: snapshot.status,
189
+ category: snapshot.category,
190
+ phase: snapshot.phase,
191
+ route: snapshot.route,
192
+ profileSource: snapshot.profileSource,
193
+ task: snapshot.task,
194
+ summary: snapshot.summary,
195
+ toolNotes: snapshot.toolNotes,
196
+ error: snapshot.error,
197
+ usage: snapshot.usage,
198
+ createdAt: snapshot.createdAt,
199
+ updatedAt: snapshot.updatedAt,
200
+ }],
201
+ }));
202
+ return [...fromTrace, ...direct];
203
+ }
204
+ /**
205
+ * Start of the current (or, when idle, the latest) agent run. The tasks pane
206
+ * keeps finished work that was launched since then; wall clock on purpose,
207
+ * it is compared with subagent/task/workflow creation stamps.
208
+ */
209
+ getTurnStartedAt() {
210
+ return this.turnStartedAt;
211
+ }
212
+ getWorkflows() {
213
+ return this.deps.agent.listWorkflows();
214
+ }
215
+ getBackgroundTasks() {
216
+ return this.deps.processManager?.listTasks(this.sessionManager.getSessionFile())
217
+ ?? this.deps.agent.backgroundTasks?.list()
218
+ ?? [];
219
+ }
220
+ getChildTranscript(agentId) {
221
+ return reconstructDisplayMessages(this.deps.agent.getSubAgentMessages(agentId));
222
+ }
223
+ getChildStreamingTail(agentId) {
224
+ const child = this.childRuns.get(agentId);
225
+ if (!child?.visible)
226
+ return null;
227
+ const acc = child.state.accumulator;
228
+ return {
229
+ content: acc.content,
230
+ reasoning: acc.reasoning,
231
+ tools: acc.toolCalls.map((tool) => ({
232
+ ...tool,
233
+ args: { ...tool.args },
234
+ metadata: tool.metadata ? { ...tool.metadata } : undefined,
235
+ })),
236
+ parts: snapshotDisplayParts(acc.parts),
237
+ };
238
+ }
239
+ stopSubagent(agentId) {
240
+ void this.deps.agent.closeSubAgent(agentId);
241
+ }
242
+ stopWorkflow(runId) {
243
+ this.deps.agent.closeWorkflow(runId);
244
+ }
245
+ stopBackgroundTask(id) {
246
+ if (this.deps.processManager)
247
+ void this.deps.processManager.killTask(id);
248
+ else
249
+ void this.deps.agent.backgroundTasks?.kill?.(id);
250
+ }
251
+ getBackgroundTaskOutput(id) {
252
+ return this.deps.processManager?.taskOutputTail(id) ?? this.deps.agent.backgroundTasks?.outputTail(id) ?? "";
253
+ }
254
+ /** Called by the host after graceful task reaping on TUI exit. */
255
+ persistFinalTaskMarkers() {
256
+ this.taskRuntime?.persistTerminalSnapshot();
257
+ }
258
+ appendTaskMarker(file, marker, payload) {
259
+ try {
260
+ const manager = this.sessionManager.getSessionFile() === file
261
+ ? this.sessionManager
262
+ : new SessionManager(file);
263
+ manager.appendMarker(marker, payload);
264
+ }
265
+ catch {
266
+ // Lifecycle persistence is best-effort; it must never break the child.
267
+ }
268
+ }
269
+ announceTaskCompletion(task) {
270
+ // Switching back to the owner session reconstructs terminal task rows
271
+ // from its persisted marker before held completions are released. Treat
272
+ // that row as the same lifecycle event instead of appending a duplicate.
273
+ // Task ids repeat across processes, so the row must be this very run.
274
+ if (this.transcript.some((message) => message.toolCalls?.some((tool) => tool.metadata?.taskId === task.id
275
+ && tool.metadata?.taskLifecycle !== undefined
276
+ && tool.metadata?.endedAt === task.endedAt))) {
277
+ return;
278
+ }
279
+ const output = this.deps.processManager?.taskOutputTail(task.id, 12_000);
280
+ // Land the outcome on the launch row: this round's launches are still in
281
+ // the streaming accumulator, earlier rounds' have committed.
282
+ if (this.runActive && this.runState
283
+ && mergeTaskLifecycleIntoLiveTools(this.runState.accumulator.toolCalls, task, output)) {
284
+ this.state.touch();
285
+ this.notify();
286
+ return;
287
+ }
288
+ const landed = applyTaskLifecycleToMessages(this.transcript, task, output);
289
+ if (landed.merged) {
290
+ this.transcript = landed.messages;
291
+ this.state.touch();
292
+ this.notify();
293
+ return;
294
+ }
295
+ if (this.runActive) {
296
+ // Launch row not settled yet (or absent): retry on the next tool_end,
297
+ // and fall back to a detached row when the round commits.
298
+ this.pendingTaskAnnouncements.set(task.id, task);
299
+ this.state.touch();
300
+ this.notify();
301
+ return;
302
+ }
303
+ this.appendDisplayMessage(taskLifecycleDisplayMessage(task, output));
304
+ }
305
+ /** Pending completions whose launch row has settled since they arrived. */
306
+ landPendingTaskAnnouncementsInLiveRound() {
307
+ if (!this.runState || this.pendingTaskAnnouncements.size === 0)
308
+ return;
309
+ for (const [id, task] of this.pendingTaskAnnouncements) {
310
+ const output = this.deps.processManager?.taskOutputTail(task.id, 12_000);
311
+ if (mergeTaskLifecycleIntoLiveTools(this.runState.accumulator.toolCalls, task, output)) {
312
+ this.pendingTaskAnnouncements.delete(id);
313
+ }
314
+ }
315
+ }
316
+ /** Move the newest live Bash Execute into the unified task manager. */
317
+ promoteActiveBash() {
318
+ const channel = this.deps.promotionChannel;
319
+ if (!channel || !this.runState)
320
+ return undefined;
321
+ const tool = [...this.runState.accumulator.toolCalls]
322
+ .reverse()
323
+ .find((candidate) => candidate.name === "bash"
324
+ && candidate.status === "running"
325
+ && channel.hasPromotable(candidate.id));
326
+ return tool ? channel.requestPromotion(tool.id) : undefined;
327
+ }
328
+ /** Drop every transcript row (/clear). */
329
+ clearTranscript() {
330
+ this.transcript = [];
331
+ this.childRuns.clear();
332
+ this.state.touch();
333
+ this.notify();
334
+ }
335
+ /** Re-project the visible transcript after a non-controller command rewrites Agent history. */
336
+ rebuildTranscriptFromAgent() {
337
+ this.state.withTransaction(() => {
338
+ this.transcript = landTaskLifecycles(reconstructDisplayMessages([...this.deps.agent.messages]), restoredTaskLifecycles(this.sessionManager));
339
+ this.childRuns.clear();
340
+ this.state.touch();
341
+ });
342
+ this.notify();
343
+ }
344
+ /**
345
+ * Rewind persistence and every renderer-facing mirror as one observable
346
+ * transition. File restoration can take time, but no partial transcript is
347
+ * published while it runs.
348
+ */
349
+ async rewindToTurn(targetId, scope) {
350
+ if (this.runActive)
351
+ throw new Error("Cancel the active turn before rewinding.");
352
+ const result = await executeRewind(this.sessionManager, this.deps.agent, targetId, scope);
353
+ if (scope !== "code") {
354
+ this.state.withTransaction(() => {
355
+ purgeForSessionSwitch(this.queue);
356
+ this.queue.queued.length = 0;
357
+ this.transcript = landTaskLifecycles(reconstructDisplayMessages([...this.deps.agent.messages]), restoredTaskLifecycles(this.sessionManager));
358
+ this.childRuns.clear();
359
+ this.liveStreamVisible = false;
360
+ this.runState = null;
361
+ this.state.touch();
362
+ });
363
+ this.notify();
364
+ }
365
+ return result;
366
+ }
367
+ /** Host-side row injection (user echo, notices) — single append point. */
368
+ appendDisplayMessage(message) {
369
+ this.transcript = [...this.transcript, message];
370
+ this.state.touch();
371
+ this.notify();
372
+ }
373
+ isRunning() {
374
+ return this.runActive;
375
+ }
376
+ /** A slash command that owns the activity lane without masquerading as an
377
+ * Agent turn. This keeps streaming/steering state separate while still
378
+ * giving Escape and Ctrl+C one cancellation boundary. */
379
+ beginCommandActivity(kind) {
380
+ if (this.runActive || this.commandActivity) {
381
+ throw new Error("Another operation is already running.");
382
+ }
383
+ const abortController = new AbortController();
384
+ this.commandActivity = {
385
+ kind,
386
+ status: "running",
387
+ startedAt: this.deps.ports.clock.now(),
388
+ abortController,
389
+ };
390
+ this.state.touch();
391
+ this.notify();
392
+ return abortController.signal;
393
+ }
394
+ finishCommandActivity(kind, event) {
395
+ if (this.commandActivity?.kind !== kind)
396
+ return;
397
+ this.state.withTransaction(() => {
398
+ if (event)
399
+ this.transcript = [...this.transcript, event];
400
+ this.commandActivity = null;
401
+ this.state.touch();
402
+ });
403
+ this.notify();
404
+ this.taskRuntime?.onIdle();
405
+ }
406
+ getCommandActivity() {
407
+ const activity = this.commandActivity;
408
+ if (!activity)
409
+ return null;
410
+ return {
411
+ kind: activity.kind,
412
+ status: activity.status,
413
+ startedAt: activity.startedAt,
414
+ };
415
+ }
416
+ isBusy() {
417
+ return this.runActive || this.commandActivity !== null;
418
+ }
419
+ /** Queue composer input while a command owns the pane. Grok keeps the
420
+ * composer available during Compact; the message starts after the command
421
+ * reaches its terminal event instead of racing the history rewrite. */
422
+ queueAfterCommand(input) {
423
+ if (!this.commandActivity)
424
+ return false;
425
+ this.queueInput(input);
426
+ return true;
427
+ }
428
+ /** Queue a complete composer payload for the next provider turn. */
429
+ queueInput(input) {
430
+ const payload = typeof input === "string" ? { text: input, images: [] } : input;
431
+ const displayKey = nextDisplayMessageKey("queued");
432
+ this.queue.queued.push({
433
+ payload,
434
+ displayKey,
435
+ sessionFile: this.sessionManager.getSessionFile(),
436
+ });
437
+ this.transcript = [...this.transcript, {
438
+ key: displayKey,
439
+ role: "user",
440
+ content: this.submitDisplayText(payload),
441
+ images: displayImagesFromPayload(payload),
442
+ inputStatus: "queued",
443
+ }];
444
+ this.state.touch();
445
+ this.notify();
446
+ }
447
+ async drainQueuedInputs(cwd, agentOptions = {}) {
448
+ if (this.isBusy())
449
+ return;
450
+ const next = this.queue.queued.shift();
451
+ if (!next || this.disposed)
452
+ return;
453
+ if (next.displayKey) {
454
+ this.transcript = moveStatusMessageToEnd(this.transcript, next.displayKey);
455
+ }
456
+ this.state.touch();
457
+ this.notify();
458
+ await this.runTurn(next.payload, cwd, agentOptions);
459
+ }
460
+ pendingSteerCount() {
461
+ return this.queue.pendingSteers.size;
462
+ }
463
+ queuedInputCount() {
464
+ return this.queue.queued.length;
465
+ }
466
+ submitDisplayText(payload) {
467
+ return formatImageUserDisplayText(payload.displayText ?? payload.text, payload.images.length, payload.imageDisplayStart);
468
+ }
469
+ submitAgentInput(payload) {
470
+ if (payload.images.length === 0)
471
+ return payload.text;
472
+ return payload.displayText
473
+ ? buildImageContentPartsFromDisplayText(payload.displayText, payload.text, payload.images, payload.imageDisplayStart)
474
+ : buildImageContentParts(payload.text, payload.images);
475
+ }
476
+ /** Add input to the current Agent run without creating a second run that
477
+ * would overwrite the shared streaming accumulator. */
478
+ steer(content) {
479
+ if (!this.runActive || !this.activeInputController)
480
+ return false;
481
+ const input = this.activeInputController.tryEnqueue(content);
482
+ if (!input)
483
+ return false;
484
+ const displayKey = nextDisplayMessageKey("steer");
485
+ beginSteer(this.queue, {
486
+ id: input.id,
487
+ content,
488
+ displayKey,
489
+ sessionFile: this.sessionManager.getSessionFile(),
490
+ });
491
+ this.transcript = [...this.transcript, {
492
+ key: displayKey,
493
+ clientId: input.id,
494
+ role: "user",
495
+ content,
496
+ inputStatus: "pending_steer",
497
+ }];
498
+ this.state.touch();
499
+ this.notify();
500
+ return true;
501
+ }
502
+ cancelActiveRun(reason = "Interrupted by user") {
503
+ if (this.activeAbortController && !this.activeAbortController.signal.aborted) {
504
+ this.activeAbortController.abort(Object.assign(new Error(reason), { name: "AgentAbortError" }));
505
+ return true;
506
+ }
507
+ if (this.commandActivity && !this.commandActivity.abortController.signal.aborted) {
508
+ this.commandActivity.status = "cancelling";
509
+ this.commandActivity.abortController.abort(Object.assign(new Error(reason), { name: "AgentAbortError" }));
510
+ this.state.touch();
511
+ this.notify();
512
+ return true;
513
+ }
514
+ return false;
515
+ }
516
+ /**
517
+ * Live streaming tail for the render loop: the in-flight accumulator's
518
+ * content/reasoning/tool summary. Renderers draw it in the live region
519
+ * (never committed to scrollback) until the turn commits.
520
+ */
521
+ getStreamingTail() {
522
+ if (!this.runActive || !this.runState || !this.liveStreamVisible)
523
+ return null;
524
+ const acc = this.runState.accumulator;
525
+ const parts = snapshotDisplayParts(acc.parts);
526
+ return {
527
+ content: acc.content,
528
+ // Ink kept the current provider turn's reasoning visible even after
529
+ // answer/tool bytes arrived. Never hide it based on another live field.
530
+ reasoning: acc.reasoning,
531
+ // Return a render-safe snapshot: reducer events continue mutating the
532
+ // accumulator in place while the TUI may still hold the previous tail.
533
+ tools: acc.toolCalls.map((tool) => ({
534
+ ...tool,
535
+ args: { ...tool.args },
536
+ metadata: tool.metadata ? { ...tool.metadata } : undefined,
537
+ })),
538
+ // Parts are the canonical commentary/tool/commentary timeline. Without
539
+ // them a live renderer necessarily moves every tool before all text.
540
+ parts,
541
+ // Phase is provider-turn local, matching Ink's clearAssistantStream().
542
+ // A tool in an earlier committed turn must not suppress fresh Thinking.
543
+ phase: acc.toolCalls.length > 0 ? "working" : "thinking",
544
+ };
545
+ }
546
+ pendingOverlayCount() {
547
+ return this.overlays.pendingCount();
548
+ }
549
+ /**
550
+ * Drive one agent run: reduce the event stream, apply effects, and finish.
551
+ * Mirrors runAgentInput (app.tsx:1438-1958) minus the rendering.
552
+ */
553
+ async runTurn(input, cwd, options) {
554
+ if (this.disposed)
555
+ throw new Error("controller disposed");
556
+ if (this.commandActivity) {
557
+ throw new Error("A command is already running.");
558
+ }
559
+ if (this.runActive) {
560
+ if (typeof input === "string") {
561
+ if (!this.steer(input))
562
+ this.queueInput(input);
563
+ }
564
+ else if (isSubmitPayload(input)) {
565
+ if (input.images.length === 0) {
566
+ if (!this.steer(input.text))
567
+ this.queueInput(input);
568
+ }
569
+ else
570
+ this.queueInput(input);
571
+ }
572
+ return;
573
+ }
574
+ const agentInput = isSubmitPayload(input) ? this.submitAgentInput(input) : input;
575
+ this.runActive = true;
576
+ this.liveStreamVisible = true;
577
+ this.turnStartedAt = Date.now();
578
+ this.runState = createRunState(Date.now());
579
+ const inputController = new AgentRunInputQueue(`run-${this.runState.accumulator.runId}`);
580
+ const abortController = new AbortController();
581
+ const goalStatusAtStart = this.goalRuntime?.snapshot()?.status;
582
+ const goalRun = options?.goalRun === true;
583
+ const agentOptions = { ...options };
584
+ delete agentOptions.goalRun;
585
+ if (isSubmitPayload(input) && input.images.length > 0 && input.displayText) {
586
+ agentOptions.userMessageUi = {
587
+ displayText: input.displayText,
588
+ ...(input.imageDisplayStart !== undefined
589
+ ? { imageDisplayStart: input.imageDisplayStart }
590
+ : {}),
591
+ };
592
+ }
593
+ let runUsageTokens = 0;
594
+ let runUsageReported = false;
595
+ let taskResultsForNextTurn = this.taskRuntime?.captureCurrentUndeliveredIds() ?? [];
596
+ this.activeInputController = inputController;
597
+ this.activeAbortController = abortController;
598
+ const upstreamAbort = () => abortController.abort(options?.abortSignal?.reason);
599
+ if (options?.abortSignal?.aborted)
600
+ upstreamAbort();
601
+ else
602
+ options?.abortSignal?.addEventListener("abort", upstreamAbort, { once: true });
603
+ this.state.touch();
604
+ this.notify();
605
+ const ctx = {
606
+ external: false,
607
+ isCurrentRun: () => !this.disposed,
608
+ now: () => this.deps.ports.clock.now(),
609
+ runStartedAt: this.deps.ports.clock.now(),
610
+ pendingSteers: this.queue.pendingSteers,
611
+ };
612
+ let runError;
613
+ let cancelled = false;
614
+ try {
615
+ for await (const event of this.deps.agent.run(agentInput, cwd, {
616
+ ...agentOptions,
617
+ abortSignal: abortController.signal,
618
+ inputController,
619
+ })) {
620
+ if (event.type === "turn_start") {
621
+ this.taskRuntime?.markResultsDelivered(taskResultsForNextTurn);
622
+ taskResultsForNextTurn = [];
623
+ }
624
+ if (event.type === "turn_end" && event.usage) {
625
+ runUsageReported = true;
626
+ runUsageTokens += tokenUsageTotal(event.usage);
627
+ }
628
+ const { state, effects } = reduceAgentEvent(this.runState, event, ctx);
629
+ this.runState = state;
630
+ if (event.type === "tool_end")
631
+ this.landPendingTaskAnnouncementsInLiveRound();
632
+ const subagentMetadata = event.type === "tool_update"
633
+ ? event.update.metadata
634
+ : event.type === "tool_end"
635
+ ? event.result.metadata
636
+ : undefined;
637
+ if (event.type === "tool_update"
638
+ && subagentMetadata?.kind === "subagent"
639
+ && effects.some((effect) => effect.kind === "live-subagent-changed")) {
640
+ // The launching call already committed: merge the update into its
641
+ // transcript entry so the settled row stays the single source of
642
+ // truth for live and settled rendering alike.
643
+ this.transcript = applySubagentUpdateToMessages(this.transcript, {
644
+ id: event.id,
645
+ name: event.name,
646
+ metadata: subagentMetadata,
647
+ });
648
+ }
649
+ else if (subagentMetadata?.kind === "subagent") {
650
+ this.transcript = mergeSubagentSnapshotsIntoMessages(this.transcript, subagentMetadata);
651
+ }
652
+ if (event.type === "tool_update" && event.update.childEvent) {
653
+ this.reduceChildEvent(event.update.subAgentId, event.update.childEvent);
654
+ }
655
+ if (event.type === "input_rejected") {
656
+ const steer = this.queue.pendingSteers.get(event.id);
657
+ if (steer) {
658
+ this.queue.pendingSteers.delete(event.id);
659
+ this.queue.queued.push({
660
+ payload: { text: event.content, images: [] },
661
+ displayKey: steer.displayKey,
662
+ sessionFile: steer.sessionFile ?? this.sessionManager.getSessionFile(),
663
+ });
664
+ this.transcript = this.transcript.map((message) => (message.key === steer.displayKey ? setUserInputStatus(message, "queued") : message));
665
+ }
666
+ }
667
+ else if (event.type === "input_applied") {
668
+ this.queue.pendingSteers.delete(event.id);
669
+ }
670
+ // Visibility is an event-boundary concern, not a generic consequence
671
+ // of clearing the accumulator. A provider turn_start/retry must keep
672
+ // the empty waiting spinner mounted; only turn_end hides the live tail
673
+ // in the same transaction that commits its settled replacement.
674
+ if (event.type === "turn_end") {
675
+ if (event.willContinue) {
676
+ taskResultsForNextTurn = this.taskRuntime?.captureCurrentUndeliveredIds() ?? [];
677
+ }
678
+ this.liveStreamVisible = !!event.willContinue;
679
+ }
680
+ else if (event.type === "turn_start"
681
+ || event.type === "text_delta"
682
+ || event.type === "reasoning_delta"
683
+ || event.type === "tool_call_start"
684
+ || event.type === "tool_start") {
685
+ this.liveStreamVisible = true;
686
+ }
687
+ if (event.type === "turn_end") {
688
+ // Commit the provider turn and replace its accumulator in the same
689
+ // observable frame. For a continuation, keep an empty waiting tail;
690
+ // for a final boundary, keep it hidden. Clearing the accumulator at
691
+ // BOTH boundaries is important: Agent still performs cleanup after
692
+ // final turn_end, and an error there must not commit the settled
693
+ // answer a second time from the stale accumulator.
694
+ this.state.withTransaction(() => {
695
+ for (const effect of effects)
696
+ this.applyEffectMutation(effect);
697
+ this.runState = createRunState(this.runState?.accumulator.runId ?? Date.now());
698
+ this.liveStreamVisible = !!event.willContinue;
699
+ this.state.touch();
700
+ });
701
+ this.notify();
702
+ }
703
+ else {
704
+ this.applyEffects(effects);
705
+ }
706
+ const hasDirty = Object.values(this.runState.dirty).some(Boolean);
707
+ // Streamed text, reasoning, and tool arguments share one 40ms paint.
708
+ // Repainting each argument chunk can starve input/timers while a
709
+ // buffered response drains, especially with a long reasoning preview.
710
+ // Tool lifecycle events still notify immediately through their effects.
711
+ // Dirty means "paint pending", not
712
+ // "this run has ever changed", and must never remain latched forever.
713
+ if (hasDirty && (event.type === "text_delta" || event.type === "reasoning_delta" || event.type === "tool_call_delta")) {
714
+ this.deps.ports.flush.scheduleFlush(STREAMING_FLUSH_INTERVAL_MS, () => {
715
+ if (this.disposed || !this.runActive)
716
+ return;
717
+ this.state.touch();
718
+ this.notify();
719
+ });
720
+ }
721
+ if (hasDirty) {
722
+ this.runState = {
723
+ ...this.runState,
724
+ dirty: { content: false, reasoning: false, parts: false, tools: false },
725
+ };
726
+ }
727
+ }
728
+ }
729
+ catch (error) {
730
+ runError = error;
731
+ cancelled = this.isAbortLike(error);
732
+ // Legacy catch (app.tsx:1855-1861): commit the partial answer before
733
+ // surfacing the interrupt/error so streamed content is not lost.
734
+ const partial = this.runState ? buildAssistantMessage(this.runState) : null;
735
+ // The partial commit, error effect, and live-tail removal are one frame.
736
+ // Publishing the partial first used to expose {settled, live:true}, then
737
+ // finally removed the tail in a second frame (visible duplication).
738
+ this.state.withTransaction(() => {
739
+ if (partial)
740
+ this.transcript = [...this.transcript, partial];
741
+ this.liveStreamVisible = false;
742
+ this.applyEffectMutation({ kind: "run-error", error });
743
+ this.state.touch();
744
+ });
745
+ this.notify();
746
+ }
747
+ finally {
748
+ const leftoverSteers = inputController.closePendingInputs();
749
+ // The signal is the source of truth. A provider may observe cancellation
750
+ // and end its iterator without throwing, but the user's pending steers
751
+ // must still be dropped exactly as they are in the Ink implementation.
752
+ cancelled ||= abortController.signal.aborted;
753
+ for (const leftover of leftoverSteers) {
754
+ const steer = this.queue.pendingSteers.get(leftover.id);
755
+ if (!steer)
756
+ continue;
757
+ this.queue.pendingSteers.delete(leftover.id);
758
+ if (cancelled) {
759
+ this.transcript = this.transcript.filter((message) => message.key !== steer.displayKey);
760
+ }
761
+ else {
762
+ this.queue.queued.push({
763
+ payload: { text: leftover.content, images: [] },
764
+ displayKey: steer.displayKey,
765
+ sessionFile: steer.sessionFile ?? this.sessionManager.getSessionFile(),
766
+ });
767
+ this.transcript = this.transcript.map((message) => (message.key === steer.displayKey ? setUserInputStatus(message, "queued") : message));
768
+ }
769
+ }
770
+ const finish = reduceRunFinish(this.runState ?? createRunState(0), {
771
+ cancelled,
772
+ errored: runError != null && !cancelled,
773
+ // Leftovers were already applied above while their display metadata
774
+ // was still available. Do not ask the reducer to emit a second drain.
775
+ leftoverSteers: [],
776
+ ownsCurrentGeneration: true,
777
+ });
778
+ this.state.withTransaction(() => {
779
+ for (const effect of finish.effects)
780
+ this.applyEffectMutation(effect);
781
+ this.deps.ports.flush.cancelFlush();
782
+ this.runActive = false;
783
+ this.liveStreamVisible = false;
784
+ this.runState = null;
785
+ this.activeInputController = null;
786
+ this.activeAbortController = null;
787
+ if (this.pendingTaskAnnouncements.size > 0) {
788
+ this.transcript = landTaskLifecycles(this.transcript, [...this.pendingTaskAnnouncements.values()].map((task) => ({
789
+ task,
790
+ output: this.deps.processManager?.taskOutputTail(task.id, 12_000),
791
+ })));
792
+ this.pendingTaskAnnouncements.clear();
793
+ }
794
+ this.state.touch();
795
+ });
796
+ this.notify();
797
+ options?.abortSignal?.removeEventListener("abort", upstreamAbort);
798
+ }
799
+ this.goalRuntime?.afterRun({
800
+ goalRun,
801
+ goalStatusAtStart,
802
+ cancelled,
803
+ errored: runError != null && !cancelled,
804
+ usageTokens: runUsageTokens,
805
+ usageReported: runUsageReported,
806
+ }, cwd);
807
+ this.taskRuntime?.onIdle();
808
+ await this.drainQueuedInputs(cwd, agentOptions);
809
+ }
810
+ /** Apply one reducer transition and publish exactly one observable snapshot. */
811
+ applyEffects(effects) {
812
+ if (effects.length === 0)
813
+ return;
814
+ this.state.withTransaction(() => {
815
+ for (const effect of effects)
816
+ this.applyEffectMutation(effect);
817
+ });
818
+ this.notify();
819
+ }
820
+ /** Mutate for one effect; callers own the surrounding transaction + notify. */
821
+ applyEffectMutation(effect) {
822
+ this.deps.onEffect?.(effect);
823
+ switch (effect.kind) {
824
+ case "stream-cleared":
825
+ this.deps.ports.flush.cancelFlush();
826
+ break;
827
+ case "assistant-committed": {
828
+ const message = this.runState ? buildAssistantMessage(this.runState, effect.taskElapsedMs) : null;
829
+ if (message)
830
+ this.transcript = [...this.transcript, message];
831
+ break;
832
+ }
833
+ case "transcript-append":
834
+ this.transcript = [...this.transcript, effect.message];
835
+ break;
836
+ case "notice":
837
+ this.transcript = [...this.transcript, {
838
+ key: `notice-${this.transcript.length}`,
839
+ role: effect.role === "error" ? "error" : "assistant",
840
+ content: effect.text,
841
+ syntheticKind: effect.role === "error" ? undefined : "ui_notice",
842
+ }];
843
+ break;
844
+ case "queue-updated":
845
+ void effect.pending;
846
+ break;
847
+ case "steer-applied":
848
+ this.transcript = moveStatusMessageToEnd(this.transcript, effect.displayKey);
849
+ break;
850
+ case "steer-requeued":
851
+ // The event loop records the rejected content and queued badge.
852
+ break;
853
+ case "run-error": {
854
+ const message = effect.error instanceof Error ? effect.error.message : String(effect.error);
855
+ if (this.isAbortLike(effect.error)) {
856
+ this.transcript = [...this.transcript, {
857
+ key: nextDisplayMessageKey("interrupt"),
858
+ role: "assistant",
859
+ content: message || "Interrupted by user",
860
+ syntheticKind: "ui_interrupt",
861
+ }];
862
+ }
863
+ else {
864
+ this.transcript = [...this.transcript, {
865
+ key: nextDisplayMessageKey("error"),
866
+ role: "error",
867
+ content: message || "Agent run failed",
868
+ }];
869
+ }
870
+ break;
871
+ }
872
+ default:
873
+ break;
874
+ }
875
+ this.state.touch();
876
+ }
877
+ notify() {
878
+ for (const listener of this.listeners)
879
+ listener(this.state.version);
880
+ }
881
+ reduceChildEvent(agentId, event) {
882
+ const current = this.childRuns.get(agentId) ?? {
883
+ state: createRunState(Date.now()),
884
+ visible: true,
885
+ updatedAt: Date.now(),
886
+ };
887
+ const reduced = reduceAgentEvent(current.state, event, {
888
+ external: false,
889
+ isCurrentRun: () => !this.disposed,
890
+ now: () => this.deps.ports.clock.now(),
891
+ runStartedAt: current.state.accumulator.runId,
892
+ pendingSteers: new Map(),
893
+ });
894
+ let state = reduced.state;
895
+ let visible = current.visible;
896
+ if (event.type === "turn_start")
897
+ visible = true;
898
+ if (event.type === "turn_end") {
899
+ state = createRunState(current.state.accumulator.runId);
900
+ visible = !!event.willContinue;
901
+ }
902
+ this.childRuns.set(agentId, { state, visible, updatedAt: Date.now() });
903
+ }
904
+ isAbortLike(error) {
905
+ return error instanceof Error && (error.name === "AbortError" || error.name === "AgentAbortError");
906
+ }
907
+ /** Drain leftover steers at run end (cancelled drops, normal requeues). */
908
+ drainLeftovers(leftovers, cancelled) {
909
+ drainLeftoverSteers(this.queue, leftovers, { cancelled });
910
+ this.state.touch();
911
+ }
912
+ /** Atomic session switch through the two-phase transaction. */
913
+ switchSession(plan) {
914
+ if (this.isBusy())
915
+ return { ok: false, error: "Stop the current run before switching sessions." };
916
+ const outcome = this.sessionTransition.switchTo(plan);
917
+ if (outcome.ok && outcome.manager) {
918
+ this.goalRuntime?.loadCurrentSession();
919
+ this.taskRuntime?.releaseHeldCompletions(outcome.manager.getSessionFile());
920
+ this.notify();
921
+ }
922
+ return outcome.ok ? { ok: true } : { ok: false, error: outcome.error };
923
+ }
924
+ /** Start an empty native session using the same atomic lifecycle as resume. */
925
+ createFreshSession(cwd, notice) {
926
+ if (this.isBusy())
927
+ return { ok: false, error: "Stop the current run before starting a new session." };
928
+ const outcome = this.sessionTransition.createFresh(cwd, notice);
929
+ if (outcome.ok && outcome.manager) {
930
+ this.goalRuntime?.loadCurrentSession();
931
+ this.taskRuntime?.releaseHeldCompletions(outcome.manager.getSessionFile());
932
+ this.notify();
933
+ }
934
+ return outcome.ok ? { ok: true } : { ok: false, error: outcome.error };
935
+ }
936
+ /**
937
+ * Shutdown: settle overlays, cancel any run, and report the exit summary.
938
+ * Idempotent — a second call is a no-op.
939
+ */
940
+ shutdown(reason) {
941
+ if (this.disposed) {
942
+ return { reason, wallMs: Date.now() - this.startedAtMs };
943
+ }
944
+ this.disposed = true;
945
+ this.cancelActiveRun(reason);
946
+ this.goalRuntime?.dispose();
947
+ this.taskRuntime?.dispose();
948
+ this.overlays.dispose();
949
+ this.backgroundTaskUnsubscribe?.();
950
+ this.deps.ports.flush.cancelFlush();
951
+ return { reason, wallMs: Date.now() - this.startedAtMs };
952
+ }
953
+ }
954
+ function restoredTaskLifecycles(manager) {
955
+ let entries;
956
+ try {
957
+ entries = manager.getEntries();
958
+ }
959
+ catch {
960
+ return [];
961
+ }
962
+ let startIndex = 0;
963
+ for (let index = entries.length - 1; index >= 0; index -= 1) {
964
+ const entry = entries[index];
965
+ if (entry?.type === "marker" && entry.kind === "conversation_clear") {
966
+ startIndex = index + 1;
967
+ break;
968
+ }
969
+ }
970
+ const starts = new Map();
971
+ // Ids restart at task_0001 per process: count launches per id so each
972
+ // terminal marker lands on the launch row it belongs to.
973
+ const launches = new Map();
974
+ const terminals = [];
975
+ for (let index = startIndex; index < entries.length; index += 1) {
976
+ const entry = entries[index];
977
+ if (entry?.type !== "marker" || !entry.value)
978
+ continue;
979
+ let payload;
980
+ try {
981
+ payload = JSON.parse(entry.value);
982
+ }
983
+ catch {
984
+ continue;
985
+ }
986
+ const id = typeof payload.id === "string" ? payload.id : undefined;
987
+ if (!id)
988
+ continue;
989
+ if (entry.kind === "task_started") {
990
+ starts.set(id, payload);
991
+ launches.set(id, (launches.get(id) ?? 0) + 1);
992
+ continue;
993
+ }
994
+ if (entry.kind !== "task_finished" && entry.kind !== "task_killed")
995
+ continue;
996
+ const start = starts.get(id) ?? {};
997
+ const status = entry.kind === "task_killed"
998
+ ? "killed"
999
+ : payload.status === "failed"
1000
+ ? "failed"
1001
+ : "completed";
1002
+ const startedAt = numeric(payload.startedAt) ?? numeric(start.startedAt) ?? entry.timestamp;
1003
+ const endedAt = numeric(payload.endedAt) ?? entry.timestamp;
1004
+ const seen = launches.get(id) ?? 0;
1005
+ terminals.push({
1006
+ // A start persisted before conversation_clear is out of scope: keep its
1007
+ // terminal state detached rather than landing it on a later reuse.
1008
+ occurrence: seen > 0 ? seen - 1 : UNMATCHED_LAUNCH,
1009
+ task: {
1010
+ kind: "task",
1011
+ id,
1012
+ command: stringValue(payload.command) ?? stringValue(start.command) ?? id,
1013
+ description: stringValue(payload.description) ?? stringValue(start.description),
1014
+ cwd: manager.getMetadata().cwd ?? process.cwd(),
1015
+ pid: numeric(start.pid),
1016
+ status,
1017
+ exitCode: typeof payload.exitCode === "number" ? payload.exitCode : null,
1018
+ startedAt,
1019
+ endedAt,
1020
+ outputTruncated: false,
1021
+ outputLines: numeric(payload.outputLines) ?? 0,
1022
+ ownerSessionId: manager.getSessionFile(),
1023
+ },
1024
+ output: stringValue(payload.output),
1025
+ });
1026
+ }
1027
+ return terminals;
1028
+ }
1029
+ function numeric(value) {
1030
+ return typeof value === "number" && Number.isFinite(value) ? value : undefined;
1031
+ }
1032
+ function stringValue(value) {
1033
+ return typeof value === "string" && value.length > 0 ? value : undefined;
1034
+ }