@hanzo/dev 4.0.1 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (369) hide show
  1. package/LICENSE +21 -0
  2. package/dist/{BinaryViewer-qn8xfPZp.js → BinaryViewer-CmFUK4zZ.js} +2 -2
  3. package/dist/{ChatMarkdown-Cyujn3JJ.js → ChatMarkdown-nvEI7iCv.js} +4 -4
  4. package/dist/{DiffCommentAnnotation-BZu1TP6E.js → DiffCommentAnnotation-BPTN_2a6.js} +1 -1
  5. package/dist/{DiffFileTree-CcJ91zOM.js → DiffFileTree-B_br90vY.js} +2 -2
  6. package/dist/{DiffPanel-BXC88NMs.js → DiffPanel-V5R5TPuK.js} +5 -5
  7. package/dist/{ExpandedImageDialog-BZnGRBJR.js → ExpandedImageDialog-CAorLacL.js} +1 -1
  8. package/dist/{FileExplorerPane-vBJS6V75.js → FileExplorerPane-CeHulcPz.js} +1 -1
  9. package/dist/{FilePreviewPanel-jJHWsMzm.js → FilePreviewPanel-BVNLvWOc.js} +8 -8
  10. package/dist/{MermaidDiagram-paNwQY33.js → MermaidDiagram-CTolIzQD.js} +1 -1
  11. package/dist/{MermaidFilePreview-B9KxfnIN.js → MermaidFilePreview-CP2zP4FU.js} +1 -1
  12. package/dist/{MermaidViewer-CAEGpLyD.js → MermaidViewer-BDfYkS9E.js} +2 -2
  13. package/dist/{NotebookPreview-D01mMCpR.js → NotebookPreview-Cybs5uM0.js} +1 -1
  14. package/dist/{OfficeFilePreview-DWaRgfQU.js → OfficeFilePreview-7JsmSoKU.js} +1 -1
  15. package/dist/{OfficeViewer-BudrZbBA.js → OfficeViewer-CJoojlJK.js} +1 -1
  16. package/dist/{OpenInPicker-Dd3ifHa1.js → OpenInPicker-BIMWUxBP.js} +7 -7
  17. package/dist/{OpenXmlOfficeViewer-CXcKdq7k.js → OpenXmlOfficeViewer-C24Kj8DM.js} +1 -1
  18. package/dist/{PreviewImage-C4Ku4z7v.js → PreviewImage-oY5YnuTr.js} +1 -1
  19. package/dist/{PreviewImageContent-BwOB9Lyd.js → PreviewImageContent-n6eLzY99.js} +1 -1
  20. package/dist/{PullRequestCodeTab-BcwyMk7d.js → PullRequestCodeTab-Dv_0kVad.js} +7 -7
  21. package/dist/{PullRequestReviewAnnotation-BU5t_1fC.js → PullRequestReviewAnnotation-LeuwO-iH.js} +4 -4
  22. package/dist/builder/activity.d.ts +16 -0
  23. package/dist/builder/activity.js +51 -0
  24. package/dist/builder/address.d.ts +11 -0
  25. package/dist/builder/address.js +50 -0
  26. package/dist/builder/ago.d.ts +2 -0
  27. package/dist/builder/ago.js +18 -0
  28. package/dist/builder/api/agents.d.ts +139 -0
  29. package/dist/builder/api/agents.js +253 -0
  30. package/dist/builder/api/auto.d.ts +166 -0
  31. package/dist/builder/api/auto.js +300 -0
  32. package/dist/builder/api/billing.d.ts +263 -0
  33. package/dist/builder/api/billing.js +401 -0
  34. package/dist/builder/api/call.d.ts +53 -0
  35. package/dist/builder/api/call.js +123 -0
  36. package/dist/builder/api/capabilities.d.ts +14 -0
  37. package/dist/builder/api/capabilities.js +41 -0
  38. package/dist/builder/api/changes.d.ts +74 -0
  39. package/dist/builder/api/changes.js +75 -0
  40. package/dist/builder/api/chat.d.ts +12 -0
  41. package/dist/builder/api/chat.js +28 -0
  42. package/dist/builder/api/cli.d.ts +59 -0
  43. package/dist/builder/api/cli.js +133 -0
  44. package/dist/builder/api/codebases.d.ts +46 -0
  45. package/dist/builder/api/codebases.js +100 -0
  46. package/dist/builder/api/coding.d.ts +117 -0
  47. package/dist/builder/api/coding.js +222 -0
  48. package/dist/builder/api/connectors.d.ts +76 -0
  49. package/dist/builder/api/connectors.js +111 -0
  50. package/dist/builder/api/consent.d.ts +22 -0
  51. package/dist/builder/api/consent.js +28 -0
  52. package/dist/builder/api/conversations.d.ts +20 -0
  53. package/dist/builder/api/conversations.js +23 -0
  54. package/dist/builder/api/draft.d.ts +38 -0
  55. package/dist/builder/api/draft.js +87 -0
  56. package/dist/builder/api/environment.d.ts +55 -0
  57. package/dist/builder/api/environment.js +126 -0
  58. package/dist/builder/api/gallery.d.ts +32 -0
  59. package/dist/builder/api/gallery.js +85 -0
  60. package/dist/builder/api/git.d.ts +31 -0
  61. package/dist/builder/api/git.js +47 -0
  62. package/dist/builder/api/github.d.ts +176 -0
  63. package/dist/builder/api/github.js +271 -0
  64. package/dist/builder/api/keys.d.ts +35 -0
  65. package/dist/builder/api/keys.js +72 -0
  66. package/dist/builder/api/library.d.ts +116 -0
  67. package/dist/builder/api/library.js +214 -0
  68. package/dist/builder/api/limits.d.ts +69 -0
  69. package/dist/builder/api/limits.js +86 -0
  70. package/dist/builder/api/links.d.ts +51 -0
  71. package/dist/builder/api/links.js +75 -0
  72. package/dist/builder/api/machines.d.ts +122 -0
  73. package/dist/builder/api/machines.js +238 -0
  74. package/dist/builder/api/mcp.d.ts +10 -0
  75. package/dist/builder/api/mcp.js +47 -0
  76. package/dist/builder/api/members.d.ts +35 -0
  77. package/dist/builder/api/members.js +95 -0
  78. package/dist/builder/api/memory.d.ts +14 -0
  79. package/dist/builder/api/memory.js +35 -0
  80. package/dist/builder/api/models.d.ts +17 -0
  81. package/dist/builder/api/models.js +20 -0
  82. package/dist/builder/api/places.d.ts +32 -0
  83. package/dist/builder/api/places.js +29 -0
  84. package/dist/builder/api/platform.d.ts +68 -0
  85. package/dist/builder/api/platform.js +87 -0
  86. package/dist/builder/api/plugins.d.ts +42 -0
  87. package/dist/builder/api/plugins.js +175 -0
  88. package/dist/builder/api/pref.d.ts +77 -0
  89. package/dist/builder/api/pref.js +93 -0
  90. package/dist/builder/api/profile.d.ts +11 -0
  91. package/dist/builder/api/profile.js +41 -0
  92. package/dist/builder/api/projects.d.ts +99 -0
  93. package/dist/builder/api/projects.js +166 -0
  94. package/dist/builder/api/provider.d.ts +49 -0
  95. package/dist/builder/api/provider.js +96 -0
  96. package/dist/builder/api/sandbox.d.ts +90 -0
  97. package/dist/builder/api/sandbox.js +223 -0
  98. package/dist/builder/api/sessions.d.ts +123 -0
  99. package/dist/builder/api/sessions.js +255 -0
  100. package/dist/builder/api/skills.d.ts +82 -0
  101. package/dist/builder/api/skills.js +117 -0
  102. package/dist/builder/api/sse.d.ts +24 -0
  103. package/dist/builder/api/sse.js +68 -0
  104. package/dist/builder/api/studio.d.ts +59 -0
  105. package/dist/builder/api/studio.js +91 -0
  106. package/dist/builder/api/talk.d.ts +48 -0
  107. package/dist/builder/api/talk.js +81 -0
  108. package/dist/builder/api/tools.d.ts +34 -0
  109. package/dist/builder/api/tools.js +37 -0
  110. package/dist/builder/api/turn.d.ts +202 -0
  111. package/dist/builder/api/turn.js +772 -0
  112. package/dist/builder/api/verdict.d.ts +3 -0
  113. package/dist/builder/api/verdict.js +21 -0
  114. package/dist/builder/api/webhooks.d.ts +47 -0
  115. package/dist/builder/api/webhooks.js +82 -0
  116. package/dist/builder/api/work.d.ts +110 -0
  117. package/dist/builder/api/work.js +218 -0
  118. package/dist/builder/ask.d.ts +51 -0
  119. package/dist/builder/ask.js +147 -0
  120. package/dist/builder/automations.d.ts +33 -0
  121. package/dist/builder/automations.js +453 -0
  122. package/dist/builder/awake.d.ts +24 -0
  123. package/dist/builder/awake.js +68 -0
  124. package/dist/builder/back.d.ts +30 -0
  125. package/dist/builder/back.js +105 -0
  126. package/dist/builder/builder.d.ts +12 -0
  127. package/dist/builder/builder.js +162 -0
  128. package/dist/builder/carry.d.ts +48 -0
  129. package/dist/builder/carry.js +278 -0
  130. package/dist/builder/choice.d.ts +134 -0
  131. package/dist/builder/choice.js +152 -0
  132. package/dist/builder/claims.d.ts +13 -0
  133. package/dist/builder/claims.js +35 -0
  134. package/dist/builder/clipboard.d.ts +2 -0
  135. package/dist/builder/clipboard.js +10 -0
  136. package/dist/builder/customize/agents.d.ts +11 -0
  137. package/dist/builder/customize/agents.js +513 -0
  138. package/dist/builder/customize/connectors.d.ts +2 -0
  139. package/dist/builder/customize/connectors.js +319 -0
  140. package/dist/builder/customize/drafted.d.ts +4 -0
  141. package/dist/builder/customize/drafted.js +92 -0
  142. package/dist/builder/customize/index.d.ts +8 -0
  143. package/dist/builder/customize/index.js +127 -0
  144. package/dist/builder/customize/inventory.d.ts +14 -0
  145. package/dist/builder/customize/inventory.js +127 -0
  146. package/dist/builder/customize/load.d.ts +9 -0
  147. package/dist/builder/customize/load.js +22 -0
  148. package/dist/builder/customize/ocean.d.ts +41 -0
  149. package/dist/builder/customize/ocean.js +332 -0
  150. package/dist/builder/customize/plugins.d.ts +2 -0
  151. package/dist/builder/customize/plugins.js +136 -0
  152. package/dist/builder/customize/roles.d.ts +4 -0
  153. package/dist/builder/customize/roles.js +105 -0
  154. package/dist/builder/customize/say.d.ts +13 -0
  155. package/dist/builder/customize/say.js +32 -0
  156. package/dist/builder/customize/skills.d.ts +2 -0
  157. package/dist/builder/customize/skills.js +208 -0
  158. package/dist/builder/customize/ui.d.ts +152 -0
  159. package/dist/builder/customize/ui.js +208 -0
  160. package/dist/builder/data.d.ts +57 -0
  161. package/dist/builder/data.js +322 -0
  162. package/dist/builder/design.d.ts +140 -0
  163. package/dist/builder/design.js +175 -0
  164. package/dist/builder/desk.d.ts +48 -0
  165. package/dist/builder/desk.js +449 -0
  166. package/dist/builder/dev-mode.d.ts +43 -0
  167. package/dist/builder/dev-mode.js +120 -0
  168. package/dist/builder/door.d.ts +11 -0
  169. package/dist/builder/door.js +126 -0
  170. package/dist/builder/environment.d.ts +23 -0
  171. package/dist/builder/environment.js +193 -0
  172. package/dist/builder/files.d.ts +23 -0
  173. package/dist/builder/files.js +175 -0
  174. package/dist/builder/find.d.ts +7 -0
  175. package/dist/builder/find.js +80 -0
  176. package/dist/builder/foot.d.ts +30 -0
  177. package/dist/builder/foot.js +79 -0
  178. package/dist/builder/forge.d.ts +4 -0
  179. package/dist/builder/forge.js +570 -0
  180. package/dist/builder/gear.d.ts +60 -0
  181. package/dist/builder/gear.js +180 -0
  182. package/dist/builder/git.d.ts +21 -0
  183. package/dist/builder/git.js +118 -0
  184. package/dist/builder/gutter.d.ts +17 -0
  185. package/dist/builder/gutter.js +25 -0
  186. package/dist/builder/handoff.d.ts +8 -0
  187. package/dist/builder/handoff.js +22 -0
  188. package/dist/builder/host.d.ts +189 -0
  189. package/dist/builder/host.js +46 -0
  190. package/dist/builder/index.d.ts +108 -0
  191. package/dist/builder/index.js +99 -0
  192. package/dist/builder/landing.d.ts +34 -0
  193. package/dist/builder/landing.js +725 -0
  194. package/dist/builder/library.d.ts +21 -0
  195. package/dist/builder/library.js +526 -0
  196. package/dist/builder/local.d.ts +80 -0
  197. package/dist/builder/local.js +124 -0
  198. package/dist/builder/make.d.ts +10 -0
  199. package/dist/builder/make.js +120 -0
  200. package/dist/builder/markdown.d.ts +49 -0
  201. package/dist/builder/markdown.js +125 -0
  202. package/dist/builder/marks.d.ts +15 -0
  203. package/dist/builder/marks.js +18 -0
  204. package/dist/builder/merge.d.ts +223 -0
  205. package/dist/builder/merge.js +380 -0
  206. package/dist/builder/meter.d.ts +31 -0
  207. package/dist/builder/meter.js +54 -0
  208. package/dist/builder/mind.d.ts +107 -0
  209. package/dist/builder/mind.js +335 -0
  210. package/dist/builder/names.d.ts +40 -0
  211. package/dist/builder/names.js +189 -0
  212. package/dist/builder/nav.d.ts +28 -0
  213. package/dist/builder/nav.js +218 -0
  214. package/dist/builder/out.d.ts +16 -0
  215. package/dist/builder/out.js +24 -0
  216. package/dist/builder/page.d.ts +55 -0
  217. package/dist/builder/page.js +217 -0
  218. package/dist/builder/pane.d.ts +30 -0
  219. package/dist/builder/pane.js +21 -0
  220. package/dist/builder/panel.d.ts +101 -0
  221. package/dist/builder/panel.js +408 -0
  222. package/dist/builder/pdf.d.ts +139 -0
  223. package/dist/builder/pdf.js +847 -0
  224. package/dist/builder/pick.d.ts +10 -0
  225. package/dist/builder/pick.js +38 -0
  226. package/dist/builder/plain.d.ts +59 -0
  227. package/dist/builder/plain.js +209 -0
  228. package/dist/builder/plan.d.ts +63 -0
  229. package/dist/builder/plan.js +155 -0
  230. package/dist/builder/plans.d.ts +1 -0
  231. package/dist/builder/plans.js +157 -0
  232. package/dist/builder/plugin.d.ts +60 -0
  233. package/dist/builder/plugin.js +1 -0
  234. package/dist/builder/plugins/design.d.ts +8 -0
  235. package/dist/builder/plugins/design.js +71 -0
  236. package/dist/builder/plugins/index.d.ts +46 -0
  237. package/dist/builder/plugins/index.js +117 -0
  238. package/dist/builder/plugins/pdf.d.ts +18 -0
  239. package/dist/builder/plugins/pdf.js +83 -0
  240. package/dist/builder/plugins/project.d.ts +5 -0
  241. package/dist/builder/plugins/project.js +68 -0
  242. package/dist/builder/plugins/research.d.ts +24 -0
  243. package/dist/builder/plugins/research.js +147 -0
  244. package/dist/builder/plugins/sketch.d.ts +9 -0
  245. package/dist/builder/plugins/sketch.js +101 -0
  246. package/dist/builder/plugins/slides.d.ts +14 -0
  247. package/dist/builder/plugins/slides.js +55 -0
  248. package/dist/builder/plugins/template.d.ts +13 -0
  249. package/dist/builder/plugins/template.js +95 -0
  250. package/dist/builder/prefs.d.ts +29 -0
  251. package/dist/builder/prefs.js +91 -0
  252. package/dist/builder/preview-url.d.ts +47 -0
  253. package/dist/builder/preview-url.js +107 -0
  254. package/dist/builder/project.d.ts +18 -0
  255. package/dist/builder/project.js +591 -0
  256. package/dist/builder/prose.d.ts +4 -0
  257. package/dist/builder/prose.js +57 -0
  258. package/dist/builder/publish.d.ts +18 -0
  259. package/dist/builder/publish.js +141 -0
  260. package/dist/builder/question.d.ts +33 -0
  261. package/dist/builder/question.js +64 -0
  262. package/dist/builder/redesign.d.ts +32 -0
  263. package/dist/builder/redesign.js +117 -0
  264. package/dist/builder/removal.d.ts +71 -0
  265. package/dist/builder/removal.js +73 -0
  266. package/dist/builder/reply.d.ts +50 -0
  267. package/dist/builder/reply.js +196 -0
  268. package/dist/builder/roles.d.ts +10 -0
  269. package/dist/builder/roles.js +28 -0
  270. package/dist/builder/route.d.ts +85 -0
  271. package/dist/builder/route.js +126 -0
  272. package/dist/builder/run.d.ts +4 -0
  273. package/dist/builder/run.js +804 -0
  274. package/dist/builder/runmeta.d.ts +16 -0
  275. package/dist/builder/runmeta.js +69 -0
  276. package/dist/builder/say.d.ts +2 -0
  277. package/dist/builder/say.js +7 -0
  278. package/dist/builder/scheduled.d.ts +3 -0
  279. package/dist/builder/scheduled.js +328 -0
  280. package/dist/builder/section.d.ts +27 -0
  281. package/dist/builder/section.js +60 -0
  282. package/dist/builder/settings/account.d.ts +1 -0
  283. package/dist/builder/settings/account.js +111 -0
  284. package/dist/builder/settings/billing.d.ts +1 -0
  285. package/dist/builder/settings/billing.js +210 -0
  286. package/dist/builder/settings/capabilities.d.ts +1 -0
  287. package/dist/builder/settings/capabilities.js +66 -0
  288. package/dist/builder/settings/card.d.ts +31 -0
  289. package/dist/builder/settings/card.js +140 -0
  290. package/dist/builder/settings/code.d.ts +1 -0
  291. package/dist/builder/settings/code.js +70 -0
  292. package/dist/builder/settings/credits.d.ts +10 -0
  293. package/dist/builder/settings/credits.js +123 -0
  294. package/dist/builder/settings/environments.d.ts +1 -0
  295. package/dist/builder/settings/environments.js +60 -0
  296. package/dist/builder/settings/general.d.ts +1 -0
  297. package/dist/builder/settings/general.js +58 -0
  298. package/dist/builder/settings/index.d.ts +4 -0
  299. package/dist/builder/settings/index.js +25 -0
  300. package/dist/builder/settings/integrations.d.ts +8 -0
  301. package/dist/builder/settings/integrations.js +138 -0
  302. package/dist/builder/settings/keys.d.ts +1 -0
  303. package/dist/builder/settings/keys.js +114 -0
  304. package/dist/builder/settings/list.d.ts +10 -0
  305. package/dist/builder/settings/list.js +28 -0
  306. package/dist/builder/settings/machines.d.ts +4 -0
  307. package/dist/builder/settings/machines.js +243 -0
  308. package/dist/builder/settings/members.d.ts +1 -0
  309. package/dist/builder/settings/members.js +77 -0
  310. package/dist/builder/settings/memory.d.ts +1 -0
  311. package/dist/builder/settings/memory.js +62 -0
  312. package/dist/builder/settings/notifications.d.ts +1 -0
  313. package/dist/builder/settings/notifications.js +111 -0
  314. package/dist/builder/settings/plan.d.ts +17 -0
  315. package/dist/builder/settings/plan.js +131 -0
  316. package/dist/builder/settings/privacy.d.ts +1 -0
  317. package/dist/builder/settings/privacy.js +76 -0
  318. package/dist/builder/settings/sections.d.ts +16 -0
  319. package/dist/builder/settings/sections.js +34 -0
  320. package/dist/builder/settings/shared.d.ts +6 -0
  321. package/dist/builder/settings/shared.js +58 -0
  322. package/dist/builder/settings/ui.d.ts +50 -0
  323. package/dist/builder/settings/ui.js +53 -0
  324. package/dist/builder/settings/usage.d.ts +1 -0
  325. package/dist/builder/settings/usage.js +24 -0
  326. package/dist/builder/shared.d.ts +26 -0
  327. package/dist/builder/shared.js +15 -0
  328. package/dist/builder/shelf.d.ts +16 -0
  329. package/dist/builder/shelf.js +219 -0
  330. package/dist/builder/side.d.ts +40 -0
  331. package/dist/builder/side.js +208 -0
  332. package/dist/builder/site.d.ts +75 -0
  333. package/dist/builder/site.js +138 -0
  334. package/dist/builder/spend.d.ts +21 -0
  335. package/dist/builder/spend.js +80 -0
  336. package/dist/builder/standing.d.ts +36 -0
  337. package/dist/builder/standing.js +66 -0
  338. package/dist/builder/suggest.d.ts +238 -0
  339. package/dist/builder/suggest.js +463 -0
  340. package/dist/builder/suggestions.d.ts +49 -0
  341. package/dist/builder/suggestions.js +260 -0
  342. package/dist/builder/summary.d.ts +60 -0
  343. package/dist/builder/summary.js +81 -0
  344. package/dist/builder/sync.d.ts +1 -0
  345. package/dist/builder/sync.js +164 -0
  346. package/dist/builder/tabs.d.ts +85 -0
  347. package/dist/builder/tabs.js +288 -0
  348. package/dist/builder/talk.d.ts +5 -0
  349. package/dist/builder/talk.js +108 -0
  350. package/dist/builder/thread.d.ts +60 -0
  351. package/dist/builder/thread.js +302 -0
  352. package/dist/builder/tools.d.ts +22 -0
  353. package/dist/builder/tools.js +52 -0
  354. package/dist/builder/transcript.d.ts +47 -0
  355. package/dist/builder/transcript.js +108 -0
  356. package/dist/builder/voice.d.ts +8 -0
  357. package/dist/builder/voice.js +24 -0
  358. package/dist/{changedFileKind-DqgCCDUs.js → changedFileKind-D6QYvIez.js} +1 -1
  359. package/dist/core.js +1 -0
  360. package/dist/{decodeImagePreview-CesVZYP4.js → decodeImagePreview-DnfFEjhw.js} +1 -1
  361. package/dist/{embed-DYP-OUlb.js → embed-c030vUqM.js} +11 -11
  362. package/dist/index.d.ts +2 -0
  363. package/dist/index.js +2 -1
  364. package/dist/{micromark-util-decode-string-NQjVkmZH.js → micromark-util-decode-string-C-5AXkOV.js} +5 -3
  365. package/dist/{readBinaryPreview-D2X4Uahu.js → readBinaryPreview-BAQ4fFjm.js} +1 -1
  366. package/dist/{useTextFieldSpeech-CyOZZPrV.js → useTextFieldSpeech-COa9XcRx.js} +1 -1
  367. package/package.json +101 -11
  368. /package/{index.d.ts → dist/core.d.ts} +0 -0
  369. /package/{keymap.d.ts → dist/keymap.d.ts} +0 -0
@@ -0,0 +1,772 @@
1
+ /**
2
+ * What a run's events SAY, as text a person reads.
3
+ *
4
+ * A curated projection, never a dump: an event carries the machinery a run
5
+ * happened on — hosts, paths, whole file bodies — and printing it would put
6
+ * someone's filesystem in front of anyone who can read the run. Each kind gets a
7
+ * sentence built from the few fields that describe the outcome; the rest is
8
+ * dropped by omission, because a projection cannot leak a field it never reads.
9
+ *
10
+ * Every string here is rendered as TEXT by the transcript. Nothing is HTML.
11
+ *
12
+ * The coding plane's vocabulary (apps/coding): `status` for a lifecycle move
13
+ * (started, routed, done, error, stopped, paused), `tool-call` for a step of the
14
+ * run itself, `event` for one line of the agent's own structured narration (the
15
+ * harness's JSON stream: its messages, reasoning, commands, edits, tool calls and
16
+ * plan), and `log` for raw output, which only the Terminal's log shows. A
17
+ * person's steering is a `control` {command, message}. A run on a project with a
18
+ * site ends `done` with `live` when it published what it pushed, or `unpublished`
19
+ * saying why it did not.
20
+ *
21
+ * `cards` is the transcript as it is drawn: the run's steps and the agent's
22
+ * items, never its log.
23
+ *
24
+ * The sentences are this client's, said in the language of the `t` a caller
25
+ * hands (@hanzo/i18n; English without one); what the run and the agent said
26
+ * is drawn as given. A step's name is a name the transcript keys on (`Error`
27
+ * opens itself), so it stays English, marked (`phrase`), and the transcript
28
+ * draws it through `t`.
29
+ */
30
+ import { phrase } from '@hanzo/i18n';
31
+ import { english } from '../say.js';
32
+ import { actions, called, counted, edited, explored, explores, shown } from './cli.js';
33
+ const str = (v) => (typeof v === 'string' ? v : '');
34
+ const obj = (v) => (v && typeof v === 'object' ? v : {});
35
+ /** The payload as an object. A live frame may carry it as a JSON string. */
36
+ export function decode(payload) {
37
+ if (payload && typeof payload === 'object')
38
+ return payload;
39
+ if (typeof payload !== 'string')
40
+ return null;
41
+ const text = payload.trim();
42
+ if (!text.startsWith('{'))
43
+ return payload;
44
+ // JSON that opens with a brace is an object; anything else is prose that opens with one.
45
+ try {
46
+ return JSON.parse(text);
47
+ }
48
+ catch {
49
+ return payload;
50
+ }
51
+ }
52
+ /** A file's name, never the host path it sat at. */
53
+ const base = (path) => {
54
+ const cut = path.replace(/\/+$/, '');
55
+ return cut.slice(cut.lastIndexOf('/') + 1);
56
+ };
57
+ /**
58
+ * A finished run's line, by whether it pushed a branch (Done when it did not),
59
+ * its pull request (none, one that could not be opened, its address) and its
60
+ * site (none, not published and why, published): each a whole line, so a
61
+ * language puts the parts in its own order.
62
+ */
63
+ const FINISHED = {
64
+ pushed: {
65
+ none: { none: phrase('Pushed {branch}'), out: phrase('Pushed {branch} — not published: {why}'), live: phrase('Pushed {branch} — published') },
66
+ broke: {
67
+ none: phrase('Pushed {branch} — the pull request could not be opened'),
68
+ out: phrase('Pushed {branch} — the pull request could not be opened — not published: {why}'),
69
+ live: phrase('Pushed {branch} — the pull request could not be opened — published'),
70
+ },
71
+ pr: { none: phrase('Pushed {branch} — {pr}'), out: phrase('Pushed {branch} — {pr} — not published: {why}'), live: phrase('Pushed {branch} — {pr} — published') },
72
+ },
73
+ done: {
74
+ none: { none: phrase('Done'), out: phrase('Done — not published: {why}'), live: phrase('Done — published') },
75
+ broke: {
76
+ none: phrase('Done — the pull request could not be opened'),
77
+ out: phrase('Done — the pull request could not be opened — not published: {why}'),
78
+ live: phrase('Done — the pull request could not be opened — published'),
79
+ },
80
+ pr: { none: phrase('Done — {pr}'), out: phrase('Done — {pr} — not published: {why}'), live: phrase('Done — {pr} — published') },
81
+ },
82
+ };
83
+ function status(b, mode, t) {
84
+ const branch = str(b.branch);
85
+ switch (str(b.status)) {
86
+ case 'started':
87
+ return branch ? t('Started on {branch}', { branch }) : t('Started');
88
+ case 'routed':
89
+ return t('Sent to a machine');
90
+ case 'done': {
91
+ // A plan's answer IS its final status: the run read and wrote nothing.
92
+ // Whether the run planned is the RECORD's word — any member of the org
93
+ // can append an event saying `mode: plan`, and its text is not an answer.
94
+ // A setup is a plan put to one question, and answers the same way.
95
+ if (mode === 'plan')
96
+ return str(b.plan) || t('Planned — the run answered with no plan');
97
+ if (mode === 'setup')
98
+ return str(b.plan) || t('Set up — the run answered with no environment');
99
+ if (b.changed === false)
100
+ return t('Done — nothing to change');
101
+ const pr = str(b.pr);
102
+ // A run on a project with a site publishes what it pushed, or says why not.
103
+ const why = str(b.unpublished);
104
+ const line = FINISHED[branch ? 'pushed' : 'done'][str(b.prError) ? 'broke' : pr ? 'pr' : 'none'][why ? 'out' : str(b.live) ? 'live' : 'none'];
105
+ return t(line, { branch, pr, why });
106
+ }
107
+ case 'error':
108
+ return plain(str(b.error), t);
109
+ case 'stopped':
110
+ return branch && b.changed ? t('Stopped — work kept on {branch}', { branch }) : t('Stopped');
111
+ case 'paused':
112
+ return branch && b.changed ? t('Paused — work kept on {branch}', { branch }) : t('Paused');
113
+ case 'followed':
114
+ // A run redirected from a chat thread is carried on by a follow-up (apps/coding steer.go).
115
+ return str(b.next) ? t('Continued in a follow-up run') : t('The follow-up run could not start');
116
+ }
117
+ return str(b.status);
118
+ }
119
+ /**
120
+ * Whether an error is a model vendor's own words: a provider's name, its rate
121
+ * headers, a key, or the JSON body it answers with. Those never reach the run
122
+ * page — they say whose model it was and nothing a person can act on — so the
123
+ * run says its plain line alone.
124
+ */
125
+ export function vendor(error) {
126
+ return /open\s?router|anthropic|openai|azure|bedrock|vertex|gemini|mistral|cohere|deepinfra|fireworks|together\.ai|groq|x-ratelimit|upstream|\bprovider\b|\bsk-[A-Za-z0-9_-]{6,}|"(error|code|message)"\s*:/i.test(error);
127
+ }
128
+ /** An error as the run page may show it: its own words, or the plain line when they are a vendor's. */
129
+ export const scrub = (error, t = english) => (vendor(error) ? plain(error, t) : error);
130
+ const OURS_RE = /providers_exhausted|every provider refused|temporarily unavailable/i;
131
+ const FREE_SANDBOXES_RE = /free sandboxes .*are used/i;
132
+ const FUNDS_RE = /\b402 Payment Required|insufficient (credit|balance)|top up/i;
133
+ /** Whether an error message indicates insufficient balance / credit / free-sandbox exhaustion (#363/#364). */
134
+ export function needsFunds(error) {
135
+ if (!error)
136
+ return false;
137
+ if (FREE_SANDBOXES_RE.test(error))
138
+ return true;
139
+ return !OURS_RE.test(error) && FUNDS_RE.test(error);
140
+ }
141
+ /** Extract an error reason from a `log` event payload, or null for ordinary/raw log lines (#363/#364). */
142
+ function logError(b) {
143
+ if (!b)
144
+ return null;
145
+ const err = str(b.error).trim();
146
+ if (str(b.runId)) {
147
+ return str(b.status) === 'error' || err ? err : null;
148
+ }
149
+ // Without runId, exclude raw command/app log shapes so stdout/stderr JSON lines cannot fake a run failure.
150
+ if ('stdout' in b || 'stderr' in b || 'text' in b || 'command' in b || 'level' in b || 'msg' in b)
151
+ return null;
152
+ if (str(b.status) === 'error' || err)
153
+ return err;
154
+ return null;
155
+ }
156
+ /**
157
+ * A run's error as one plain line with what to do, never the log it came from:
158
+ * that goes in the Error step beside it (cards), unless it is a vendor's.
159
+ */
160
+ export function plain(error, t = english) {
161
+ if (!error)
162
+ return t('The run hit an error');
163
+ const ours = OURS_RE.test(error);
164
+ if (FREE_SANDBOXES_RE.test(error))
165
+ return t('This plan’s free sandboxes are used for now. Add credit to keep building, or try again later.');
166
+ if (needsFunds(error))
167
+ return t('Your balance is out of credit. Add credit, then try again.');
168
+ if (ours || /\b(429 Too Many Requests|503 Service Unavailable)|stream disconnected|retries exhausted|rate limit/i.test(error))
169
+ return t('The model did not answer. Try again in a moment, or pick another model.');
170
+ return t('The run stopped with an error. Try again, or follow up with what to change.');
171
+ }
172
+ /**
173
+ * One event's sentence, or '' when it says nothing a person needs. `mode` is
174
+ * the run's, from its record: a plan run's final status says the plan.
175
+ */
176
+ export function said(e, mode = '', t = english) {
177
+ const body = decode(e.payload);
178
+ if (typeof body === 'string')
179
+ return body;
180
+ if (!body)
181
+ return '';
182
+ if (e.kind === 'status')
183
+ return status(body, mode, t);
184
+ for (const key of ['message', 'text', 'content', 'result', 'command']) {
185
+ const v = body[key];
186
+ if (typeof v === 'string' && v)
187
+ return v;
188
+ }
189
+ if (str(body.type) === 'done' && Array.isArray(body.changed)) {
190
+ const names = body.changed.map((f) => base(str(f))).filter(Boolean);
191
+ return names.length === 0
192
+ ? t('Done — no files changed')
193
+ : names.length <= 3
194
+ ? t('Done — changed {files}', { files: names.join(', ') })
195
+ : t('Done — changed {n} files', { n: names.length });
196
+ }
197
+ if (str(body.type) === 'error')
198
+ return scrub(str(body.error), t) || t('The run hit an error');
199
+ if (e.kind === 'log') {
200
+ const err = logError(body);
201
+ if (err !== null)
202
+ return scrub(err, t) || t('The run hit an error');
203
+ }
204
+ return str(body.step) || str(body.name);
205
+ }
206
+ /**
207
+ * The shell beside the transcript. A tool call is the command; a log line, and
208
+ * any stdout or stderr the payload carried, is the output. Status stays in the
209
+ * transcript. Each line is capped so a payload that carried a file body cannot
210
+ * fill the pane.
211
+ */
212
+ export function shell(events) {
213
+ const cap = 4000;
214
+ const clip = (s) => (s.length > cap ? `${s.slice(0, cap)}…` : s);
215
+ const out = [];
216
+ const push = (role, text) => {
217
+ const line = clip(text);
218
+ if (line)
219
+ out.push({ role, text: line });
220
+ };
221
+ for (const e of [...events].sort((a, b) => a.seq - b.seq)) {
222
+ if (e.kind !== 'log' && e.kind !== 'tool-call')
223
+ continue;
224
+ const body = decode(e.payload);
225
+ if (typeof body === 'string') {
226
+ push('out', body);
227
+ continue;
228
+ }
229
+ if (!body)
230
+ continue;
231
+ const step = str(body.step);
232
+ const message = str(body.message) || str(body.text) || str(body.command);
233
+ const stdout = str(body.stdout);
234
+ const stderr = str(body.stderr);
235
+ if (e.kind === 'tool-call' && step)
236
+ push('cmd', step);
237
+ if (message && message !== step)
238
+ push('out', message);
239
+ if (stdout)
240
+ push('out', stdout);
241
+ if (stderr)
242
+ push('out', stderr);
243
+ }
244
+ return out.slice(-400);
245
+ }
246
+ /**
247
+ * Tool calls, in the order they were first named. A later status for the same
248
+ * step wins, and a run's steps follow one another, so a step another has
249
+ * followed is over. `exit` is not a step: it is how the sandbox says one command
250
+ * in it ended (apps/sandbox work.go).
251
+ */
252
+ export function steps(events) {
253
+ const order = [];
254
+ const done = new Map();
255
+ for (const e of [...events].sort((a, b) => a.seq - b.seq)) {
256
+ if (e.kind !== 'tool-call')
257
+ continue;
258
+ const body = decode(e.payload);
259
+ if (!body || typeof body === 'string')
260
+ continue;
261
+ const name = str(body.step);
262
+ if (!name || name === 'exit')
263
+ continue;
264
+ if (!done.has(name))
265
+ order.push(name);
266
+ const status = str(body.status);
267
+ done.set(name, status === 'ok' || status === 'done' || status === 'error');
268
+ }
269
+ return order.map((name, i) => ({ name, done: i < order.length - 1 || done.get(name) === true }));
270
+ }
271
+ /**
272
+ * What the run narrated about how it ended, latest winning. Status text only:
273
+ * the branch and the pull request are read from the run's record (`pull`).
274
+ */
275
+ /** Whether an event starts or progresses a turn after an earlier turn's error (#363/#364). */
276
+ function resumesTurn(kind, b) {
277
+ if (kind === 'progress' || kind === 'spawn')
278
+ return true;
279
+ if (kind === 'message')
280
+ return true;
281
+ if (kind === 'tool-call')
282
+ return true;
283
+ if (kind === 'event' && b) {
284
+ const t = str(b.type);
285
+ return t !== 'error' && t !== 'turn.failed';
286
+ }
287
+ return false;
288
+ }
289
+ export function outcome(events) {
290
+ const out = { status: '', problem: '', published: 0 };
291
+ for (const e of [...events].sort((a, b) => a.seq - b.seq)) {
292
+ const decoded = decode(e.payload);
293
+ const b = decoded && typeof decoded === 'object' ? decoded : null;
294
+ if (e.kind === 'log') {
295
+ if (logError(b) !== null)
296
+ out.status = 'error';
297
+ continue;
298
+ }
299
+ if (e.kind === 'status') {
300
+ if (!b)
301
+ continue;
302
+ out.status = str(b.status) || out.status;
303
+ out.problem = str(b.prError) || out.problem;
304
+ if (str(b.live))
305
+ out.published = e.seq;
306
+ continue;
307
+ }
308
+ if (out.status === 'error' && resumesTurn(e.kind, b))
309
+ out.status = '';
310
+ }
311
+ return out;
312
+ }
313
+ /** Why the run failed, as its last status or error log says it, or '' when that status is not a failure. */
314
+ export function failure(events, t = english) {
315
+ let out = '';
316
+ for (const e of [...events].sort((a, b) => a.seq - b.seq)) {
317
+ const decoded = decode(e.payload);
318
+ const b = decoded && typeof decoded === 'object' ? decoded : null;
319
+ if (e.kind === 'log') {
320
+ const err = logError(b);
321
+ if (err !== null)
322
+ out = scrub(err, t) || t('The run hit an error');
323
+ continue;
324
+ }
325
+ if (e.kind === 'status') {
326
+ if (!b || !str(b.status))
327
+ continue;
328
+ out = str(b.status) === 'error' ? scrub(str(b.error), t) || t('The run hit an error') : '';
329
+ continue;
330
+ }
331
+ if (out && resumesTurn(e.kind, b))
332
+ out = '';
333
+ }
334
+ return out;
335
+ }
336
+ /** The turns, ordered and deduped: a recorded read and the live feed overlap. */
337
+ export function merge(...lists) {
338
+ const seen = new Map();
339
+ for (const list of lists)
340
+ for (const e of list)
341
+ seen.set(e.seq ? `s${e.seq}` : `i${e.id}`, e);
342
+ return [...seen.values()].sort((a, b) => a.seq - b.seq);
343
+ }
344
+ /** The actor, short enough to label a block: `hanzo/2d4d67ab`, not the whole subject. */
345
+ export function who(actor) {
346
+ const cut = actor.indexOf('/');
347
+ if (cut === -1)
348
+ return actor.split('-')[0] || actor;
349
+ const head = actor.slice(cut + 1).split('-')[0];
350
+ return head ? `${actor.slice(0, cut)}/${head}` : actor;
351
+ }
352
+ /**
353
+ * A pull request address the builder will draw as a link: https, on GitHub or
354
+ * the platform's own git, shaped like a pull request, and IN THE RUN'S OWN
355
+ * REPOSITORY (`repo`, `owner/name`). Anything else is ''. Read from the run's
356
+ * record, which the coding service writes — never from an event, which any
357
+ * member of the org can append — and bound to the repository, because a record
358
+ * can be moved into a project it did not work on.
359
+ */
360
+ export function pull(url, repo) {
361
+ const m = /^https:\/\/(?:github\.com|git\.hanzo\.ai)\/([\w.-]+)\/([\w.-]+)\/pulls?\/(\d+)\/?$/.exec(url);
362
+ if (!m || !repo || `${m[1]}/${m[2]}`.toLowerCase() !== repo.toLowerCase())
363
+ return { href: '', label: '' };
364
+ return { href: url, label: `#${m[3]}` };
365
+ }
366
+ /** What the run's own steps are called on a card: English, marked (`phrase`); the transcript draws them through `t`. */
367
+ const NAMES = {
368
+ lease: phrase('Sandbox'),
369
+ workspace: phrase('Workspace'),
370
+ clone: phrase('Clone'),
371
+ branch: phrase('Branch'),
372
+ secrets: phrase('Secrets'),
373
+ install: phrase('Install'),
374
+ start: phrase('Start'),
375
+ skills: phrase('Skills'),
376
+ artifacts: phrase('Save artifacts'),
377
+ push: phrase('Push'),
378
+ kept: phrase('Keep the sandbox'),
379
+ };
380
+ /** Steps another card already says: `leased` finishes the lease, `done` is the final status, `ended` and `exit` are housekeeping. */
381
+ const QUIET = new Set(['leased', 'done', 'ended', 'exit']);
382
+ const ranOf = (status) => (status === 'ok' || status === 'done' ? 'done' : status === 'error' ? 'error' : 'running');
383
+ /** How an agent's item went: in progress, finished, or failed or declined. */
384
+ function itemRan(item) {
385
+ switch (str(item.status)) {
386
+ case 'in_progress':
387
+ return 'running';
388
+ case 'failed':
389
+ return 'error';
390
+ case 'declined':
391
+ return 'cancelled';
392
+ }
393
+ return typeof item.exit_code === 'number' && item.exit_code !== 0 ? 'error' : 'done';
394
+ }
395
+ /** A path in the workspace, without the sandbox's working directory above it. */
396
+ const rel = (path) => path.replace(/^\/work\//, '');
397
+ /**
398
+ * One item of the agent's narration as a card, or null when it says nothing a
399
+ * person reads. `key` is the card's, kept as the item is updated.
400
+ */
401
+ function item(it, key) {
402
+ switch (str(it.type)) {
403
+ case 'agent_message':
404
+ return str(it.text) ? { kind: 'said', key, who: 'agent', text: str(it.text) } : null;
405
+ case 'reasoning':
406
+ return str(it.text) ? { kind: 'think', key, text: str(it.text) } : null;
407
+ case 'command_execution': {
408
+ // What the command did is the agent's own parse of it (cli.ts): exploration, or a command it ran.
409
+ const did = actions(it.command_actions);
410
+ if (explores(did))
411
+ return { kind: 'explore', key, calls: [{ actions: did, exit: typeof it.exit_code === 'number' ? it.exit_code : null }], ran: itemRan(it) };
412
+ return { kind: 'shell', key, command: shown(str(it.command)), output: str(it.aggregated_output), ran: itemRan(it) };
413
+ }
414
+ case 'file_change': {
415
+ const changes = Array.isArray(it.changes) ? it.changes : [];
416
+ const files = changes
417
+ .map((c) => {
418
+ const o = obj(c);
419
+ const kind = o.kind === 'add' || o.kind === 'delete' ? o.kind : 'update';
420
+ const n = (v) => (typeof v === 'number' ? v : null);
421
+ return { path: rel(str(o.path)), kind, added: n(o.added), removed: n(o.removed) };
422
+ })
423
+ .filter((f) => f.path);
424
+ return { kind: 'edit', key, files, ran: itemRan(it) };
425
+ }
426
+ case 'mcp_tool_call': {
427
+ const ran = itemRan(it);
428
+ const said = Array.isArray(obj(it.result).content) ? obj(it.result).content.map((c) => str(obj(c).text)).filter(Boolean).join('\n') : '';
429
+ return {
430
+ kind: 'step',
431
+ key,
432
+ name: ran === 'running' ? phrase('Calling') : phrase('Called'),
433
+ detail: called(str(it.server), str(it.tool), it.arguments),
434
+ output: str(obj(it.error).message) || said,
435
+ ran,
436
+ };
437
+ }
438
+ case 'web_search':
439
+ return { kind: 'step', key, name: phrase('Search'), detail: str(it.query), output: '', ran: 'done' };
440
+ case 'todo_list': {
441
+ const items = Array.isArray(it.items) ? it.items : [];
442
+ return { kind: 'todo', key, items: items.map((x) => ({ text: str(obj(x).text), done: obj(x).completed === true })).filter((x) => x.text) };
443
+ }
444
+ }
445
+ return null;
446
+ }
447
+ /**
448
+ * A run's events, as the cards its transcript draws. `mode` is the run's, from
449
+ * its record: a plan's final status is its plan, and nothing else draws a plan.
450
+ *
451
+ * The run's own steps arrive as `tool-call` {step, message, status}. The agent
452
+ * narrates itself as `event` lines: an item is started, updated and completed
453
+ * under one id, and its card is drawn once and kept current. Ids count from zero
454
+ * in each agent process, so an id is the agent's within the thread it started. A
455
+ * turn that fails is one plain line with the detail folded beneath it, drawn once
456
+ * however many times it is said; an `error` on its own is the agent retrying and
457
+ * is drawn only if the turn then fails. The final status carries the agent's
458
+ * answer, drawn once. `log` is never drawn here.
459
+ */
460
+ export function cards(events, mode = '', t = english) {
461
+ const out = [];
462
+ let seq = 0;
463
+ let n = 0;
464
+ const mint = () => `${seq}.${n++}`;
465
+ let phase = null;
466
+ const items = new Map();
467
+ let thread = 0;
468
+ let said = '';
469
+ const answers = new Set();
470
+ const steered = new Set();
471
+ const person = (text) => {
472
+ const c = { kind: 'said', key: mint(), who: 'person', text };
473
+ out.push(c);
474
+ return c;
475
+ };
476
+ const failures = new Set();
477
+ const spawned = new Set();
478
+ const asked = new Map();
479
+ const failed = (message) => {
480
+ if (failures.has(message))
481
+ return;
482
+ failures.add(message);
483
+ const rawStep = Boolean(message && !vendor(message));
484
+ const noteFunds = !rawStep && needsFunds(message);
485
+ out.push({ kind: 'note', key: mint(), text: plain(message, t), ...(noteFunds ? { funds: true } : {}) });
486
+ // The reason, read whole, when it is the run's own; a vendor's words stay off the page.
487
+ if (rawStep)
488
+ out.push({ kind: 'step', key: mint(), name: phrase('Error'), detail: '', output: message, ran: 'error' });
489
+ };
490
+ for (const e of [...events].sort((a, b) => a.seq - b.seq)) {
491
+ seq = e.seq;
492
+ n = 0;
493
+ const body = decode(e.payload);
494
+ const b = body && typeof body === 'object' ? body : null;
495
+ switch (e.kind) {
496
+ case 'event': {
497
+ if (!b)
498
+ break;
499
+ const type = str(b.type);
500
+ if (type === 'thread.started')
501
+ thread++;
502
+ if (type === 'error')
503
+ said = str(b.message);
504
+ if (type === 'turn.failed')
505
+ failed(str(obj(b.error).message) || said);
506
+ if (type !== 'item.started' && type !== 'item.updated' && type !== 'item.completed')
507
+ break;
508
+ const it = obj(b.item);
509
+ const id = str(it.id) && `${thread}:${str(it.id)}`;
510
+ const at = id ? items.get(id) : undefined;
511
+ const card = item(it, at === undefined ? mint() : out[at].key);
512
+ if (!card)
513
+ break;
514
+ if (at === undefined) {
515
+ if (id)
516
+ items.set(id, out.length);
517
+ out.push(card);
518
+ }
519
+ else
520
+ out[at] = card;
521
+ break;
522
+ }
523
+ case 'tool-call': {
524
+ if (!b)
525
+ break;
526
+ const step = str(b.step);
527
+ const message = str(b.message);
528
+ if (step === 'exit') {
529
+ // One command in the sandbox ended: `exit 0`, `exit 1`, or `ended: …`.
530
+ if (phase && phase.ran === 'running')
531
+ phase.ran = message === 'exit 0' ? 'done' : 'error';
532
+ break;
533
+ }
534
+ if (step === 'leased') {
535
+ const lease = out.find((c) => c.kind === 'step' && c.name === NAMES.lease);
536
+ if (lease)
537
+ lease.ran = 'done';
538
+ }
539
+ if (!step || QUIET.has(step))
540
+ break;
541
+ const name = NAMES[step] ?? step.charAt(0).toUpperCase() + step.slice(1);
542
+ if (phase && phase.name === name) {
543
+ phase.ran = ranOf(str(b.status));
544
+ if (message)
545
+ phase.detail = message;
546
+ break;
547
+ }
548
+ phase = { kind: 'step', key: mint(), name, detail: message, output: '', ran: ranOf(str(b.status)) };
549
+ out.push(phase);
550
+ break;
551
+ }
552
+ case 'status': {
553
+ phase = null;
554
+ if (!b)
555
+ break;
556
+ // A question the run asked its person (apps/agents ask.go), and its answer, drawn on the question.
557
+ if (str(b.status) === 'asked') {
558
+ const options = (Array.isArray(b.options) ? b.options : []).map((o) => str(obj(o).label)).filter(Boolean);
559
+ asked.set(str(b.question), out.length);
560
+ out.push({ kind: 'ask', key: mint(), question: str(b.question), text: str(b.text), options, answer: '' });
561
+ break;
562
+ }
563
+ if (str(b.status) === 'answered') {
564
+ const at = asked.get(str(b.question));
565
+ const card = at === undefined ? undefined : out[at];
566
+ if (card?.kind === 'ask')
567
+ out[at] = { ...card, answer: str(b.answer) };
568
+ break;
569
+ }
570
+ const done = str(b.status) === 'done';
571
+ const text = str(b.plan) || str(b.answer);
572
+ if (done && (mode === 'plan' || mode === 'setup') && text) {
573
+ answers.add(text.trim());
574
+ out.push(mode === 'plan' ? { kind: 'plan', key: mint(), text } : { kind: 'said', key: mint(), who: 'agent', text });
575
+ break;
576
+ }
577
+ const answer = str(b.answer).trim();
578
+ if (answer) {
579
+ answers.add(answer);
580
+ out.push({ kind: 'said', key: mint(), who: 'agent', text: answer });
581
+ }
582
+ if (str(b.status) === 'error') {
583
+ failed(str(b.error));
584
+ break;
585
+ }
586
+ const line = status(b, mode, t);
587
+ const going = str(b.status) === 'started' || str(b.status) === 'routed';
588
+ if (line)
589
+ out.push(going ? { kind: 'note', key: mint(), text: line, step: true } : { kind: 'note', key: mint(), text: line });
590
+ break;
591
+ }
592
+ case 'control': {
593
+ if (!b)
594
+ break;
595
+ const command = str(b.command);
596
+ const said = str(b.message);
597
+ if (command === 'message' && said)
598
+ steered.add(person(said));
599
+ else if (command === 'pause')
600
+ out.push({ kind: 'note', key: mint(), text: t('Pause asked') });
601
+ else if (command === 'resume')
602
+ out.push({ kind: 'note', key: mint(), text: t('Resume asked') });
603
+ else if (command === 'stop')
604
+ out.push({ kind: 'note', key: mint(), text: t('Stop asked') });
605
+ break;
606
+ }
607
+ case 'message': {
608
+ const text = typeof body === 'string' ? body : str(b?.text) || str(b?.content) || str(b?.message);
609
+ if (!text)
610
+ break;
611
+ if (str(b?.role) === 'user')
612
+ person(text);
613
+ else
614
+ out.push({ kind: 'said', key: mint(), who: 'agent', text });
615
+ break;
616
+ }
617
+ case 'spawn': {
618
+ // A conversation's turn started a coding run, or follows the one that carried it on.
619
+ const session = str(b?.session);
620
+ if (!session || spawned.has(session))
621
+ break;
622
+ spawned.add(session);
623
+ out.push({ kind: 'run', key: mint(), session });
624
+ break;
625
+ }
626
+ case 'log': {
627
+ // A conversation's turn or coding run that failed says why on its record of the run.
628
+ // A turn the platform refuses before it starts (no balance) carries the reason and no status.
629
+ const err = logError(b);
630
+ if (err !== null)
631
+ failed(err);
632
+ break;
633
+ }
634
+ }
635
+ }
636
+ // The answer a status carries is also the agent's last message: each is drawn once, as the answer.
637
+ const kept = new Set();
638
+ for (let i = out.length - 1; i >= 0; i--) {
639
+ const c = out[i];
640
+ if (!((c.kind === 'said' && c.who === 'agent') || c.kind === 'plan') || !answers.has(c.text.trim()))
641
+ continue;
642
+ if (kept.has(c.text.trim()))
643
+ out.splice(i, 1);
644
+ kept.add(c.text.trim());
645
+ }
646
+ // The ask opens the conversation, ahead of the steps that set the run up.
647
+ const ask = out.findIndex((c) => c.kind === 'said' && c.who === 'person' && !steered.has(c));
648
+ if (ask > 0)
649
+ out.unshift(...out.splice(ask, 1));
650
+ return gather(out);
651
+ }
652
+ /**
653
+ * Consecutive exploration as the CLI keeps it: one Explored block, open across the
654
+ * reads, listings and searches that follow each other — the agent's reasoning
655
+ * between them included, which stays where it was said, after the block.
656
+ */
657
+ function gather(cards) {
658
+ const out = [];
659
+ let open = null;
660
+ for (const c of cards) {
661
+ if (c.kind === 'explore') {
662
+ if (open) {
663
+ open.calls = [...open.calls, ...c.calls];
664
+ if (c.ran === 'running')
665
+ open.ran = 'running';
666
+ continue;
667
+ }
668
+ open = { ...c, calls: [...c.calls] };
669
+ out.push(open);
670
+ continue;
671
+ }
672
+ if (c.kind !== 'think')
673
+ open = null;
674
+ out.push(c);
675
+ }
676
+ return out;
677
+ }
678
+ /**
679
+ * Cards as the CLI prints them, line for line: what a run's transcript reads as in
680
+ * `dev`'s terminal. The transcript draws the same words (transcript.tsx); this is
681
+ * them as text, which the parity tests hold to the CLI's own.
682
+ */
683
+ export function printed(cards, live = false) {
684
+ const lines = [];
685
+ const under = (first, rest = ' ') => first.map((l, i) => `${i === 0 ? ' └ ' : rest}${l}`);
686
+ for (const c of cards) {
687
+ switch (c.kind) {
688
+ case 'explore':
689
+ lines.push(`• ${c.ran === 'running' && live ? 'Exploring' : 'Explored'}`, ...under(explored(c.calls).map((l) => `${l.title} ${l.text}`)));
690
+ break;
691
+ case 'shell': {
692
+ const output = c.output.replace(/\n+$/, '');
693
+ lines.push(`• ${c.ran === 'running' && live ? 'Running' : 'Ran'} ${c.command}`, ...under(output ? output.split('\n') : ['(no output)']));
694
+ break;
695
+ }
696
+ case 'edit':
697
+ lines.push(`• ${edited(c.files)}`);
698
+ if (c.files.length > 1)
699
+ lines.push(...c.files.map((f) => ` └ ${f.path} ${counted(f)}`.trimEnd()));
700
+ break;
701
+ case 'step':
702
+ if (c.name === 'Called' || c.name === 'Calling')
703
+ lines.push(`• ${c.name} ${c.detail}`);
704
+ break;
705
+ case 'said':
706
+ if (c.who === 'agent')
707
+ lines.push(`• ${c.text}`);
708
+ break;
709
+ }
710
+ }
711
+ return lines.join('\n');
712
+ }
713
+ /** The plan a plan run answered with, from its final status, or ''. */
714
+ export function answer(events) {
715
+ let out = '';
716
+ for (const e of [...events].sort((a, b) => a.seq - b.seq)) {
717
+ if (e.kind !== 'status')
718
+ continue;
719
+ const b = decode(e.payload);
720
+ if (b && typeof b === 'object' && str(b.status) === 'done')
721
+ out = str(b.plan);
722
+ }
723
+ return out;
724
+ }
725
+ /**
726
+ * Whether the run has kept its work yet, and whether that work is on its
727
+ * branch. A stop or a pause commits and pushes AFTER it is asked, and says so
728
+ * in its status (apps/coding coding.go interrupted): until then a follow-up
729
+ * would clone a branch the push has not reached.
730
+ */
731
+ export function settled(events) {
732
+ const out = { settled: false, pushed: false };
733
+ for (const e of [...events].sort((a, b) => a.seq - b.seq)) {
734
+ const decoded = decode(e.payload);
735
+ const b = decoded && typeof decoded === 'object' ? decoded : null;
736
+ if (e.kind === 'log') {
737
+ if (logError(b) !== null) {
738
+ out.settled = true;
739
+ out.pushed = false;
740
+ }
741
+ continue;
742
+ }
743
+ if (e.kind !== 'status') {
744
+ if (out.settled && resumesTurn(e.kind, b))
745
+ out.settled = false;
746
+ continue;
747
+ }
748
+ if (!b)
749
+ continue;
750
+ const s = str(b.status);
751
+ if (s === 'done' || s === 'error' || s === 'stopped' || s === 'paused') {
752
+ out.settled = true;
753
+ out.pushed = b.changed === true;
754
+ }
755
+ else if (s) {
756
+ out.settled = false;
757
+ }
758
+ }
759
+ return out;
760
+ }
761
+ /** The session of the run that carried this one on (its `followed` status), or ''. */
762
+ export function followed(events) {
763
+ let next = '';
764
+ for (const e of [...events].sort((a, b) => a.seq - b.seq)) {
765
+ if (e.kind !== 'status')
766
+ continue;
767
+ const b = decode(e.payload);
768
+ if (b && typeof b !== 'string' && str(b.status) === 'followed')
769
+ next = str(b.next);
770
+ }
771
+ return next;
772
+ }