@esso0428/pi-subagents 0.17.16 → 0.17.18

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 (359) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/ROADMAP.md +87 -0
  3. package/docs/post-0.17.6-agents-roster-viewer-spec.md +42 -0
  4. package/docs/post-0.17.6-durable-history-spec.md +41 -0
  5. package/docs/post-0.17.6-feature-specs.md +50 -0
  6. package/docs/post-0.17.6-nested-agents-spec.md +38 -0
  7. package/docs/post-0.17.6-recovery-shutdown-spec.md +46 -0
  8. package/docs/post-0.17.6-ui-latency-baseline-spec.md +46 -0
  9. package/docs/post-0.17.6-workflow-rpc-lifecycle-spec.md +54 -0
  10. package/package.json +1 -1
  11. package/src/agent-history.ts +2 -54
  12. package/src/agent-manager.ts +406 -1288
  13. package/src/agent-runner.ts +27 -251
  14. package/src/agent-types.ts +32 -188
  15. package/src/cross-extension-rpc.ts +20 -96
  16. package/src/custom-agents.ts +13 -170
  17. package/src/index.ts +480 -1920
  18. package/src/invocation-config.ts +3 -118
  19. package/src/model-resolver.ts +0 -18
  20. package/src/output-file.ts +6 -61
  21. package/src/prompts.ts +2 -45
  22. package/src/schedule.ts +14 -35
  23. package/src/settings.ts +2 -301
  24. package/src/status-note.ts +1 -66
  25. package/src/types.ts +10 -177
  26. package/src/ui/agent-widget.ts +57 -278
  27. package/src/ui/conversation-blocks.ts +0 -6
  28. package/src/ui/conversation-timeline.ts +25 -139
  29. package/src/ui/conversation-viewer.ts +48 -212
  30. package/src/ui/schedule-menu.ts +8 -9
  31. package/src/usage.ts +2 -109
  32. package/src/worktree.ts +55 -69
  33. package/dist/abortable.d.ts +0 -13
  34. package/dist/abortable.d.ts.map +0 -1
  35. package/dist/abortable.js +0 -43
  36. package/dist/abortable.js.map +0 -1
  37. package/dist/agent-color.d.ts +0 -36
  38. package/dist/agent-color.d.ts.map +0 -1
  39. package/dist/agent-color.js +0 -124
  40. package/dist/agent-color.js.map +0 -1
  41. package/dist/agent-file-toggle.d.ts +0 -126
  42. package/dist/agent-file-toggle.d.ts.map +0 -1
  43. package/dist/agent-file-toggle.js +0 -259
  44. package/dist/agent-file-toggle.js.map +0 -1
  45. package/dist/agent-history-list.d.ts +0 -19
  46. package/dist/agent-history-list.d.ts.map +0 -1
  47. package/dist/agent-history-list.js +0 -69
  48. package/dist/agent-history-list.js.map +0 -1
  49. package/dist/agent-history.d.ts +0 -35
  50. package/dist/agent-history.d.ts.map +0 -1
  51. package/dist/agent-history.js +0 -188
  52. package/dist/agent-history.js.map +0 -1
  53. package/dist/agent-manager.d.ts +0 -503
  54. package/dist/agent-manager.d.ts.map +0 -1
  55. package/dist/agent-manager.js +0 -1572
  56. package/dist/agent-manager.js.map +0 -1
  57. package/dist/agent-recovery.d.ts +0 -37
  58. package/dist/agent-recovery.d.ts.map +0 -1
  59. package/dist/agent-recovery.js +0 -171
  60. package/dist/agent-recovery.js.map +0 -1
  61. package/dist/agent-runner.d.ts +0 -303
  62. package/dist/agent-runner.d.ts.map +0 -1
  63. package/dist/agent-runner.js +0 -1003
  64. package/dist/agent-runner.js.map +0 -1
  65. package/dist/agent-types.d.ts +0 -120
  66. package/dist/agent-types.d.ts.map +0 -1
  67. package/dist/agent-types.js +0 -301
  68. package/dist/agent-types.js.map +0 -1
  69. package/dist/child-context.d.ts +0 -3
  70. package/dist/child-context.d.ts.map +0 -1
  71. package/dist/child-context.js +0 -13
  72. package/dist/child-context.js.map +0 -1
  73. package/dist/context.d.ts +0 -13
  74. package/dist/context.d.ts.map +0 -1
  75. package/dist/context.js +0 -57
  76. package/dist/context.js.map +0 -1
  77. package/dist/cross-extension-rpc.d.ts +0 -67
  78. package/dist/cross-extension-rpc.d.ts.map +0 -1
  79. package/dist/cross-extension-rpc.js +0 -139
  80. package/dist/cross-extension-rpc.js.map +0 -1
  81. package/dist/custom-agents.d.ts +0 -55
  82. package/dist/custom-agents.d.ts.map +0 -1
  83. package/dist/custom-agents.js +0 -309
  84. package/dist/custom-agents.js.map +0 -1
  85. package/dist/default-agents.d.ts +0 -8
  86. package/dist/default-agents.d.ts.map +0 -1
  87. package/dist/default-agents.js +0 -123
  88. package/dist/default-agents.js.map +0 -1
  89. package/dist/enabled-models.d.ts +0 -50
  90. package/dist/enabled-models.d.ts.map +0 -1
  91. package/dist/enabled-models.js +0 -146
  92. package/dist/enabled-models.js.map +0 -1
  93. package/dist/env.d.ts +0 -7
  94. package/dist/env.d.ts.map +0 -1
  95. package/dist/env.js +0 -29
  96. package/dist/env.js.map +0 -1
  97. package/dist/group-join.d.ts +0 -33
  98. package/dist/group-join.d.ts.map +0 -1
  99. package/dist/group-join.js +0 -117
  100. package/dist/group-join.js.map +0 -1
  101. package/dist/index.d.ts +0 -51
  102. package/dist/index.d.ts.map +0 -1
  103. package/dist/index.js +0 -3687
  104. package/dist/index.js.map +0 -1
  105. package/dist/invocation-config.d.ts +0 -108
  106. package/dist/invocation-config.d.ts.map +0 -1
  107. package/dist/invocation-config.js +0 -84
  108. package/dist/invocation-config.js.map +0 -1
  109. package/dist/memory.d.ts +0 -54
  110. package/dist/memory.d.ts.map +0 -1
  111. package/dist/memory.js +0 -166
  112. package/dist/memory.js.map +0 -1
  113. package/dist/mention-clone.d.ts +0 -88
  114. package/dist/mention-clone.d.ts.map +0 -1
  115. package/dist/mention-clone.js +0 -154
  116. package/dist/mention-clone.js.map +0 -1
  117. package/dist/mention.d.ts +0 -82
  118. package/dist/mention.d.ts.map +0 -1
  119. package/dist/mention.js +0 -132
  120. package/dist/mention.js.map +0 -1
  121. package/dist/model-resolver.d.ts +0 -37
  122. package/dist/model-resolver.d.ts.map +0 -1
  123. package/dist/model-resolver.js +0 -96
  124. package/dist/model-resolver.js.map +0 -1
  125. package/dist/model-scope.d.ts +0 -50
  126. package/dist/model-scope.d.ts.map +0 -1
  127. package/dist/model-scope.js +0 -49
  128. package/dist/model-scope.js.map +0 -1
  129. package/dist/nested-tools.d.ts +0 -57
  130. package/dist/nested-tools.d.ts.map +0 -1
  131. package/dist/nested-tools.js +0 -301
  132. package/dist/nested-tools.js.map +0 -1
  133. package/dist/nico-overrides.d.ts +0 -54
  134. package/dist/nico-overrides.d.ts.map +0 -1
  135. package/dist/nico-overrides.js +0 -170
  136. package/dist/nico-overrides.js.map +0 -1
  137. package/dist/output-file.d.ts +0 -44
  138. package/dist/output-file.d.ts.map +0 -1
  139. package/dist/output-file.js +0 -156
  140. package/dist/output-file.js.map +0 -1
  141. package/dist/prompts.d.ts +0 -56
  142. package/dist/prompts.d.ts.map +0 -1
  143. package/dist/prompts.js +0 -92
  144. package/dist/prompts.js.map +0 -1
  145. package/dist/schedule-store.d.ts +0 -39
  146. package/dist/schedule-store.d.ts.map +0 -1
  147. package/dist/schedule-store.js +0 -156
  148. package/dist/schedule-store.js.map +0 -1
  149. package/dist/schedule.d.ts +0 -110
  150. package/dist/schedule.d.ts.map +0 -1
  151. package/dist/schedule.js +0 -360
  152. package/dist/schedule.js.map +0 -1
  153. package/dist/settings.d.ts +0 -354
  154. package/dist/settings.d.ts.map +0 -1
  155. package/dist/settings.js +0 -247
  156. package/dist/settings.js.map +0 -1
  157. package/dist/skill-loader.d.ts +0 -25
  158. package/dist/skill-loader.d.ts.map +0 -1
  159. package/dist/skill-loader.js +0 -94
  160. package/dist/skill-loader.js.map +0 -1
  161. package/dist/status-note.d.ts +0 -62
  162. package/dist/status-note.d.ts.map +0 -1
  163. package/dist/status-note.js +0 -86
  164. package/dist/status-note.js.map +0 -1
  165. package/dist/structured-output.d.ts +0 -62
  166. package/dist/structured-output.d.ts.map +0 -1
  167. package/dist/structured-output.js +0 -113
  168. package/dist/structured-output.js.map +0 -1
  169. package/dist/types.d.ts +0 -372
  170. package/dist/types.d.ts.map +0 -1
  171. package/dist/types.js +0 -6
  172. package/dist/types.js.map +0 -1
  173. package/dist/ui/agent-mention.d.ts +0 -83
  174. package/dist/ui/agent-mention.d.ts.map +0 -1
  175. package/dist/ui/agent-mention.js +0 -188
  176. package/dist/ui/agent-mention.js.map +0 -1
  177. package/dist/ui/agent-widget.d.ts +0 -241
  178. package/dist/ui/agent-widget.d.ts.map +0 -1
  179. package/dist/ui/agent-widget.js +0 -992
  180. package/dist/ui/agent-widget.js.map +0 -1
  181. package/dist/ui/ccstyle/diff/ansi-utils.d.ts +0 -11
  182. package/dist/ui/ccstyle/diff/ansi-utils.d.ts.map +0 -1
  183. package/dist/ui/ccstyle/diff/ansi-utils.js +0 -145
  184. package/dist/ui/ccstyle/diff/ansi-utils.js.map +0 -1
  185. package/dist/ui/ccstyle/diff/diff-presentation.d.ts +0 -12
  186. package/dist/ui/ccstyle/diff/diff-presentation.d.ts.map +0 -1
  187. package/dist/ui/ccstyle/diff/diff-presentation.js +0 -48
  188. package/dist/ui/ccstyle/diff/diff-presentation.js.map +0 -1
  189. package/dist/ui/ccstyle/diff/diff-renderer.d.ts +0 -46
  190. package/dist/ui/ccstyle/diff/diff-renderer.d.ts.map +0 -1
  191. package/dist/ui/ccstyle/diff/diff-renderer.js +0 -2049
  192. package/dist/ui/ccstyle/diff/diff-renderer.js.map +0 -1
  193. package/dist/ui/ccstyle/diff/line-width-safety.d.ts +0 -12
  194. package/dist/ui/ccstyle/diff/line-width-safety.d.ts.map +0 -1
  195. package/dist/ui/ccstyle/diff/line-width-safety.js +0 -58
  196. package/dist/ui/ccstyle/diff/line-width-safety.js.map +0 -1
  197. package/dist/ui/ccstyle/diff/render-utils.d.ts +0 -6
  198. package/dist/ui/ccstyle/diff/render-utils.d.ts.map +0 -1
  199. package/dist/ui/ccstyle/diff/render-utils.js +0 -25
  200. package/dist/ui/ccstyle/diff/render-utils.js.map +0 -1
  201. package/dist/ui/ccstyle/diff/shiki-highlight.d.ts +0 -19
  202. package/dist/ui/ccstyle/diff/shiki-highlight.d.ts.map +0 -1
  203. package/dist/ui/ccstyle/diff/shiki-highlight.js +0 -85
  204. package/dist/ui/ccstyle/diff/shiki-highlight.js.map +0 -1
  205. package/dist/ui/ccstyle/diff/types.d.ts +0 -22
  206. package/dist/ui/ccstyle/diff/types.d.ts.map +0 -1
  207. package/dist/ui/ccstyle/diff/types.js +0 -10
  208. package/dist/ui/ccstyle/diff/types.js.map +0 -1
  209. package/dist/ui/ccstyle/diff/write-display-utils.d.ts +0 -2
  210. package/dist/ui/ccstyle/diff/write-display-utils.d.ts.map +0 -1
  211. package/dist/ui/ccstyle/diff/write-display-utils.js +0 -12
  212. package/dist/ui/ccstyle/diff/write-display-utils.js.map +0 -1
  213. package/dist/ui/ccstyle/tool-renderer.d.ts +0 -17
  214. package/dist/ui/ccstyle/tool-renderer.d.ts.map +0 -1
  215. package/dist/ui/ccstyle/tool-renderer.js +0 -74
  216. package/dist/ui/ccstyle/tool-renderer.js.map +0 -1
  217. package/dist/ui/ccstyle/tool-result.d.ts +0 -44
  218. package/dist/ui/ccstyle/tool-result.d.ts.map +0 -1
  219. package/dist/ui/ccstyle/tool-result.js +0 -423
  220. package/dist/ui/ccstyle/tool-result.js.map +0 -1
  221. package/dist/ui/conversation-blocks.d.ts +0 -46
  222. package/dist/ui/conversation-blocks.d.ts.map +0 -1
  223. package/dist/ui/conversation-blocks.js +0 -313
  224. package/dist/ui/conversation-blocks.js.map +0 -1
  225. package/dist/ui/conversation-nvim.d.ts +0 -8
  226. package/dist/ui/conversation-nvim.d.ts.map +0 -1
  227. package/dist/ui/conversation-nvim.js +0 -117
  228. package/dist/ui/conversation-nvim.js.map +0 -1
  229. package/dist/ui/conversation-role.d.ts +0 -13
  230. package/dist/ui/conversation-role.d.ts.map +0 -1
  231. package/dist/ui/conversation-role.js +0 -39
  232. package/dist/ui/conversation-role.js.map +0 -1
  233. package/dist/ui/conversation-search.d.ts +0 -39
  234. package/dist/ui/conversation-search.d.ts.map +0 -1
  235. package/dist/ui/conversation-search.js +0 -124
  236. package/dist/ui/conversation-search.js.map +0 -1
  237. package/dist/ui/conversation-timeline.d.ts +0 -102
  238. package/dist/ui/conversation-timeline.d.ts.map +0 -1
  239. package/dist/ui/conversation-timeline.js +0 -555
  240. package/dist/ui/conversation-timeline.js.map +0 -1
  241. package/dist/ui/conversation-viewer.d.ts +0 -138
  242. package/dist/ui/conversation-viewer.d.ts.map +0 -1
  243. package/dist/ui/conversation-viewer.js +0 -1175
  244. package/dist/ui/conversation-viewer.js.map +0 -1
  245. package/dist/ui/schedule-menu.d.ts +0 -17
  246. package/dist/ui/schedule-menu.d.ts.map +0 -1
  247. package/dist/ui/schedule-menu.js +0 -95
  248. package/dist/ui/schedule-menu.js.map +0 -1
  249. package/dist/ui/select-item.d.ts +0 -28
  250. package/dist/ui/select-item.d.ts.map +0 -1
  251. package/dist/ui/select-item.js +0 -35
  252. package/dist/ui/select-item.js.map +0 -1
  253. package/dist/ui/viewer-keys.d.ts +0 -21
  254. package/dist/ui/viewer-keys.d.ts.map +0 -1
  255. package/dist/ui/viewer-keys.js +0 -18
  256. package/dist/ui/viewer-keys.js.map +0 -1
  257. package/dist/ui/workflow-card.d.ts +0 -176
  258. package/dist/ui/workflow-card.d.ts.map +0 -1
  259. package/dist/ui/workflow-card.js +0 -333
  260. package/dist/ui/workflow-card.js.map +0 -1
  261. package/dist/ui/workflow-dialog.d.ts +0 -306
  262. package/dist/ui/workflow-dialog.d.ts.map +0 -1
  263. package/dist/ui/workflow-dialog.js +0 -844
  264. package/dist/ui/workflow-dialog.js.map +0 -1
  265. package/dist/ui/workflow-menu.d.ts +0 -42
  266. package/dist/ui/workflow-menu.d.ts.map +0 -1
  267. package/dist/ui/workflow-menu.js +0 -127
  268. package/dist/ui/workflow-menu.js.map +0 -1
  269. package/dist/usage.d.ts +0 -136
  270. package/dist/usage.d.ts.map +0 -1
  271. package/dist/usage.js +0 -121
  272. package/dist/usage.js.map +0 -1
  273. package/dist/workflow/collisions.d.ts +0 -96
  274. package/dist/workflow/collisions.d.ts.map +0 -1
  275. package/dist/workflow/collisions.js +0 -89
  276. package/dist/workflow/collisions.js.map +0 -1
  277. package/dist/workflow/entry.d.ts +0 -33
  278. package/dist/workflow/entry.d.ts.map +0 -1
  279. package/dist/workflow/entry.js +0 -30
  280. package/dist/workflow/entry.js.map +0 -1
  281. package/dist/workflow/host.d.ts +0 -63
  282. package/dist/workflow/host.d.ts.map +0 -1
  283. package/dist/workflow/host.js +0 -363
  284. package/dist/workflow/host.js.map +0 -1
  285. package/dist/workflow/journal.d.ts +0 -98
  286. package/dist/workflow/journal.d.ts.map +0 -1
  287. package/dist/workflow/journal.js +0 -121
  288. package/dist/workflow/journal.js.map +0 -1
  289. package/dist/workflow/json-schema.d.ts +0 -52
  290. package/dist/workflow/json-schema.d.ts.map +0 -1
  291. package/dist/workflow/json-schema.js +0 -112
  292. package/dist/workflow/json-schema.js.map +0 -1
  293. package/dist/workflow/meta.d.ts +0 -68
  294. package/dist/workflow/meta.d.ts.map +0 -1
  295. package/dist/workflow/meta.js +0 -318
  296. package/dist/workflow/meta.js.map +0 -1
  297. package/dist/workflow/progress.d.ts +0 -225
  298. package/dist/workflow/progress.d.ts.map +0 -1
  299. package/dist/workflow/progress.js +0 -362
  300. package/dist/workflow/progress.js.map +0 -1
  301. package/dist/workflow/runtime.d.ts +0 -335
  302. package/dist/workflow/runtime.d.ts.map +0 -1
  303. package/dist/workflow/runtime.js +0 -831
  304. package/dist/workflow/runtime.js.map +0 -1
  305. package/dist/workflow/saved.d.ts +0 -91
  306. package/dist/workflow/saved.d.ts.map +0 -1
  307. package/dist/workflow/saved.js +0 -204
  308. package/dist/workflow/saved.js.map +0 -1
  309. package/dist/workflow/task.d.ts +0 -137
  310. package/dist/workflow/task.d.ts.map +0 -1
  311. package/dist/workflow/task.js +0 -208
  312. package/dist/workflow/task.js.map +0 -1
  313. package/dist/workflow/tool-description.d.ts +0 -39
  314. package/dist/workflow/tool-description.d.ts.map +0 -1
  315. package/dist/workflow/tool-description.js +0 -200
  316. package/dist/workflow/tool-description.js.map +0 -1
  317. package/dist/workflow/worker-source.d.ts +0 -48
  318. package/dist/workflow/worker-source.d.ts.map +0 -1
  319. package/dist/workflow/worker-source.js +0 -779
  320. package/dist/workflow/worker-source.js.map +0 -1
  321. package/dist/worktree.d.ts +0 -53
  322. package/dist/worktree.d.ts.map +0 -1
  323. package/dist/worktree.js +0 -165
  324. package/dist/worktree.js.map +0 -1
  325. package/dist/write-execution.d.ts +0 -42
  326. package/dist/write-execution.d.ts.map +0 -1
  327. package/dist/write-execution.js +0 -138
  328. package/dist/write-execution.js.map +0 -1
  329. package/dist/xml.d.ts +0 -11
  330. package/dist/xml.d.ts.map +0 -1
  331. package/dist/xml.js +0 -13
  332. package/dist/xml.js.map +0 -1
  333. package/src/abortable.ts +0 -43
  334. package/src/agent-color.ts +0 -161
  335. package/src/agent-file-toggle.ts +0 -269
  336. package/src/child-context.ts +0 -15
  337. package/src/mention-clone.ts +0 -196
  338. package/src/mention.ts +0 -141
  339. package/src/model-scope.ts +0 -70
  340. package/src/nested-tools.ts +0 -424
  341. package/src/structured-output.ts +0 -130
  342. package/src/ui/agent-mention.ts +0 -216
  343. package/src/ui/select-item.ts +0 -45
  344. package/src/ui/workflow-card.ts +0 -470
  345. package/src/ui/workflow-dialog.ts +0 -1115
  346. package/src/ui/workflow-menu.ts +0 -166
  347. package/src/workflow/collisions.ts +0 -123
  348. package/src/workflow/entry.ts +0 -47
  349. package/src/workflow/host.ts +0 -403
  350. package/src/workflow/journal.ts +0 -164
  351. package/src/workflow/json-schema.ts +0 -128
  352. package/src/workflow/meta.ts +0 -325
  353. package/src/workflow/progress.ts +0 -550
  354. package/src/workflow/runtime.ts +0 -1219
  355. package/src/workflow/saved.ts +0 -217
  356. package/src/workflow/task.ts +0 -302
  357. package/src/workflow/tool-description.ts +0 -200
  358. package/src/workflow/worker-source.ts +0 -781
  359. package/src/xml.ts +0 -13
@@ -1,470 +0,0 @@
1
- /**
2
- * workflow-card.ts — the inline transcript card for a running workflow.
3
- *
4
- * ```
5
- * ▸ Workflow review-changes 3/7 agents · 1m12s
6
- * Review changed files across dimensions, verify each finding
7
- * ╭─ Review
8
- * │ ├─ ✔ review:bugs · Explore · haiku · 18.4k · 12 tool calls · 42s
9
- * │ ├─ ⟳ review:perf · Explore · 8 tool calls · 21s
10
- * │ └─ ⟳ review:security
11
- * ╰─ Verify
12
- * └─ ⟳ verify:auth.ts · Plan · 3 tool calls · 9s
13
- * ⎿ scanned 41 changed files
14
- * ```
15
- *
16
- * Two things about this file are easy to get wrong.
17
- *
18
- * **The glyphs are not the dialog's glyphs.** The inline row keys off the *raw*
19
- * entry `state` (start | progress | done | error), not the derived display
20
- * state, so a skipped or blocked agent renders as a plain ✘ here while the
21
- * workflows dialog distinguishes them. `displayState` is deliberately not
22
- * consulted below.
23
- *
24
- * **The layout is pure.** `layoutWorkflowCard` returns coloured segments and
25
- * never touches a theme or a terminal, so the same layout drives the `Workflow`
26
- * tool's `renderResult` and a standalone session entry (a workflow launched from
27
- * a CLI flag has no tool call to attach to). Theme application is the thin
28
- * `styleWorkflowCardLines` wrapper on top.
29
- *
30
- * All state derivation lives in `src/workflow/progress.ts`; this file only
31
- * arranges what that module returns.
32
- */
33
-
34
- import { stripTerminalSequences, Text, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
35
- import type { WorkflowEntryData } from "../workflow/entry.js";
36
- import type { WorkflowMeta } from "../workflow/meta.js";
37
- import {
38
- buildPhaseGroups,
39
- collapse,
40
- formatDuration,
41
- header,
42
- sizeWarning,
43
- stats,
44
- type WorkflowAgentEntry,
45
- type WorkflowEntry,
46
- type WorkflowRunStatus,
47
- } from "../workflow/progress.js";
48
- import type { Theme } from "./agent-widget.js";
49
-
50
- /**
51
- * Header re-render cadence. Claude Code ticks the workflow clock once a second,
52
- * not at the 80ms spinner cadence — the running glyph is static, so there is
53
- * nothing to animate faster than the elapsed time changes.
54
- */
55
- export const WORKFLOW_TICK_MS = 1000;
56
-
57
- /** Widest label column before stats stop being aligned and just follow the label. */
58
- const LABEL_COLUMN_MAX = 28;
59
-
60
- /** Fallback width when the caller does not know the terminal's. */
61
- const DEFAULT_WIDTH = 80;
62
-
63
- /* ------------------------------------------------------------------------- *
64
- * Glyphs
65
- * ------------------------------------------------------------------------- */
66
-
67
- export interface WorkflowGlyphs {
68
- /** Tool-title pointer, matching the Agent tool's `▸`. */
69
- pointer: string;
70
- tick: string;
71
- cross: string;
72
- /** Running/queued. A static glyph, hence no spinner inline. */
73
- running: string;
74
- /** First and subsequent phase groups. */
75
- groupTop: string;
76
- /** A group that is neither the first nor the last. */
77
- groupMid: string;
78
- /** The last phase group. */
79
- groupBottom: string;
80
- /** Continuation rail under a non-final group. */
81
- vertical: string;
82
- branch: string;
83
- lastBranch: string;
84
- /** Log-line prefix, matching the Agent tool's result lines. */
85
- log: string;
86
- warning: string;
87
- }
88
-
89
- export const UNICODE_GLYPHS: WorkflowGlyphs = {
90
- pointer: "▸",
91
- tick: "✔",
92
- cross: "✘",
93
- running: "⟳",
94
- groupTop: "╭─",
95
- groupMid: "├─",
96
- groupBottom: "╰─",
97
- vertical: "│",
98
- branch: "├─",
99
- lastBranch: "└─",
100
- log: "⎿",
101
- warning: "⚠",
102
- };
103
-
104
- /**
105
- * The `figures` ASCII tier, for terminals that cannot draw the box set. Every
106
- * glyph keeps its unicode counterpart's column width so the tree stays aligned
107
- * either way.
108
- */
109
- export const ASCII_GLYPHS: WorkflowGlyphs = {
110
- pointer: ">",
111
- tick: "√",
112
- cross: "×",
113
- running: "*",
114
- groupTop: ",-",
115
- groupMid: "|-",
116
- groupBottom: "`-",
117
- vertical: "|",
118
- branch: "|-",
119
- lastBranch: "`-",
120
- log: "\\",
121
- warning: "!",
122
- };
123
-
124
- /* ------------------------------------------------------------------------- *
125
- * Lines
126
- * ------------------------------------------------------------------------- */
127
-
128
- /**
129
- * pi theme keys. Claude Code's palette maps as success→success, error→error,
130
- * subtle→dim, permission→warning for a blocked row and accent for selection;
131
- * an undefined colour means "leave it at the terminal default", which is what
132
- * the recovered inline mapping asks for on a running row.
133
- *
134
- * `accent` is unused by the card and exists for the workflows dialog, which
135
- * shares these segment types.
136
- */
137
- export type WorkflowCardColor = "success" | "error" | "warning" | "dim" | "muted" | "toolTitle" | "accent";
138
-
139
- export interface WorkflowCardSegment {
140
- text: string;
141
- color?: WorkflowCardColor;
142
- bold?: boolean;
143
- }
144
-
145
- export type WorkflowCardLine = WorkflowCardSegment[];
146
-
147
- /** The subset of the task record the card reads. */
148
- export interface WorkflowCardTask {
149
- status: WorkflowRunStatus;
150
- workflowName?: string;
151
- summary?: string;
152
- description?: string;
153
- startTime: number;
154
- endTime?: number;
155
- totalPausedMs?: number;
156
- }
157
-
158
- export interface WorkflowCardInput {
159
- progress: readonly WorkflowEntry[];
160
- task: WorkflowCardTask;
161
- meta?: WorkflowMeta;
162
- /** Agents the runtime has scheduled, which can exceed those that have reported. */
163
- agentCount?: number;
164
- /** Total tokens for the size warning; summed from the entries when omitted. */
165
- totalTokens?: number;
166
- agentCap?: number;
167
- tokenCap?: number;
168
- now?: number;
169
- width?: number;
170
- /** Swap in the ASCII glyph tier for terminals without unicode. */
171
- ascii?: boolean;
172
- /**
173
- * Lead with `▸ SubagentWorkflow`.
174
- *
175
- * True where the card stands alone — the session entry a flag-launched run
176
- * writes, which has no tool call above it to say what it is. False as a tool
177
- * result, where the call line directly above already does.
178
- */
179
- showToolTitle?: boolean;
180
- }
181
-
182
- /* ------------------------------------------------------------------------- *
183
- * Formatting
184
- * ------------------------------------------------------------------------- */
185
-
186
- /** `18.4k` / `1.2M` — bare magnitude, since the row already reads as a stat. */
187
- export function formatCompactTokens(count: number): string {
188
- if (count >= 1_000_000) return `${(count / 1_000_000).toFixed(1)}M`;
189
- if (count >= 1_000) return `${(count / 1_000).toFixed(1)}k`;
190
- return `${count}`;
191
- }
192
-
193
- /**
194
- * One label for the model pair. A fallback that never differed from the primary
195
- * would just be noise, so it only shows when the run actually has two models in
196
- * play.
197
- */
198
- export function formatModel(
199
- entry: WorkflowAgentEntry,
200
- opts?: { canonical?: boolean },
201
- ): string | undefined {
202
- const { fallbackModel, requestedModel } = entry;
203
- // `canonical` is for surfaces with the width for `provider/model-id`; the
204
- // tight rows take the short label. Chosen here rather than by the caller
205
- // swapping fields, which would leave `fallbackModel` in the other spelling.
206
- const model = opts?.canonical ? entry.modelId ?? entry.model : entry.model;
207
- const primary = model && fallbackModel && model !== fallbackModel ? `${model}→${fallbackModel}` : model ?? fallbackModel;
208
- if (primary === undefined) return undefined;
209
- // Disclosed rather than substituted: a model an agent file pinned over the
210
- // script's is still a model the script did not get (#182). Same rule as
211
- // `buildInvocationTags`' `asked()` — only when the two actually differ, so a
212
- // request that was honoured says nothing.
213
- return requestedModel !== undefined && requestedModel !== primary
214
- ? `${primary} (asked ${requestedModel})`
215
- : primary;
216
- }
217
-
218
- /**
219
- * The thinking level, and what was asked for when it was not honoured.
220
- *
221
- * Separate from {@link formatModel} because a row can have one without the
222
- * other: an `agent()` that named no model still runs at some level, and a level
223
- * pi clamped is worth saying so about even when the model is unremarkable.
224
- */
225
- export function formatThinking(entry: WorkflowAgentEntry): string | undefined {
226
- const { thinking, requestedThinking } = entry;
227
- if (!thinking) return undefined;
228
- return requestedThinking !== undefined && requestedThinking !== thinking
229
- ? `thinking: ${thinking} (asked ${requestedThinking})`
230
- : `thinking: ${thinking}`;
231
- }
232
-
233
- /**
234
- * What a row replayed from a resume journal says instead of a duration.
235
- *
236
- * Shared with the dialog so both views name the same thing the same way — the
237
- * card shows it inline while the run happens, the dialog on the agent's row.
238
- */
239
- export const REPLAYED_ANNOTATION = "from resume journal";
240
-
241
- /**
242
- * The `·`-separated tail of an agent row, in the recovered order: agentType,
243
- * model, tokens, toolCalls, durationMs. Absent values drop out entirely rather
244
- * than rendering a placeholder.
245
- */
246
- export function agentStatSegments(entry: WorkflowAgentEntry): string[] {
247
- const parts: string[] = [];
248
- if (entry.agentType) parts.push(entry.agentType);
249
- const model = formatModel(entry);
250
- if (model) parts.push(model);
251
- if (entry.tokens) parts.push(formatCompactTokens(entry.tokens));
252
- if (entry.toolCalls) parts.push(`${entry.toolCalls} tool call${entry.toolCalls === 1 ? "" : "s"}`);
253
- if (entry.durationMs) parts.push(formatDuration(entry.durationMs));
254
- return parts;
255
- }
256
-
257
- /**
258
- * The recovered inline mapping — keyed on the raw entry state. `skipped` and
259
- * `blocked` are not distinguished here; that is the dialog's job.
260
- */
261
- function rowGlyph(entry: WorkflowAgentEntry, glyphs: WorkflowGlyphs): WorkflowCardSegment {
262
- if (entry.state === "done") return { text: glyphs.tick, color: "success" };
263
- if (entry.state === "error") return { text: glyphs.cross, color: "error" };
264
- return { text: glyphs.running };
265
- }
266
-
267
- /* ------------------------------------------------------------------------- *
268
- * Layout
269
- * ------------------------------------------------------------------------- */
270
-
271
- /** Trim a line to `width`, cutting inside whichever segment crosses the edge. */
272
- export function clampLine(line: WorkflowCardLine, width: number): WorkflowCardLine {
273
- const clamped: WorkflowCardLine = [];
274
- let used = 0;
275
- for (const segment of line) {
276
- const segmentWidth = visibleWidth(segment.text);
277
- if (used + segmentWidth <= width) {
278
- clamped.push(segment);
279
- used += segmentWidth;
280
- continue;
281
- }
282
- const room = width - used;
283
- // truncateToWidth wraps its ellipsis in resets, which would leak escape
284
- // codes into a layout that is supposed to be plain text until it is themed.
285
- if (room > 0) {
286
- clamped.push({ ...segment, text: stripTerminalSequences(truncateToWidth(segment.text, room, "…")) });
287
- }
288
- return clamped;
289
- }
290
- return clamped;
291
- }
292
-
293
- const lineWidth = (line: WorkflowCardLine) => line.reduce((sum, s) => sum + visibleWidth(s.text), 0);
294
-
295
- /**
296
- * Build the card.
297
- *
298
- * Everything derived — the phase tree, the header counts, the logs, the size
299
- * warning — comes from `progress.ts`; what happens here is purely arrangement.
300
- */
301
- export function layoutWorkflowCard(input: WorkflowCardInput): WorkflowCardLine[] {
302
- const glyphs = input.ascii ? ASCII_GLYPHS : UNICODE_GLYPHS;
303
- const width = Math.max(1, input.width ?? DEFAULT_WIDTH);
304
- const now = input.now ?? Date.now();
305
-
306
- const groups = buildPhaseGroups(input.progress, input.meta?.phases);
307
- const { agents, logs } = collapse(input.progress);
308
- const totals = stats(input.progress, input.agentCount ?? 0);
309
- const head = header(input.task, input.meta, groups, input.agentCount ?? 0, now);
310
-
311
- const lines: WorkflowCardLine[] = [];
312
-
313
- // ---- Header: `<name>` with the stats flush right ----
314
- // The tool name appears only when nothing above the card already carries it.
315
- // As a tool result there is a `▸ SubagentWorkflow …` call line directly above,
316
- // and repeating it put two near-identical pointer lines back to back.
317
- const left: WorkflowCardLine = input.showToolTitle
318
- ? [
319
- { text: `${glyphs.pointer} `, color: "toolTitle" },
320
- { text: "SubagentWorkflow", color: "toolTitle", bold: true },
321
- { text: " " },
322
- { text: head.name, color: "muted" },
323
- ]
324
- : [{ text: " " }, { text: head.name, color: "toolTitle", bold: true }];
325
- const statsWidth = visibleWidth(head.stats);
326
- const clampedLeft = clampLine(left, Math.max(0, width - statsWidth - 1));
327
- const gap = Math.max(1, width - lineWidth(clampedLeft) - statsWidth);
328
- lines.push([...clampedLeft, { text: " ".repeat(gap) }, { text: head.stats, color: "dim" }]);
329
-
330
- if (head.subtext) lines.push(clampLine([{ text: ` ${head.subtext}`, color: "dim" }], width));
331
-
332
- // ---- Phase tree ----
333
- // Stats line up in one column across the whole card, not per group, so the
334
- // eye can scan them; a label past the cap just pushes its own stats along.
335
- const labelColumn = Math.min(
336
- LABEL_COLUMN_MAX,
337
- Math.max(0, ...groups.flatMap(group => group.agents.map(a => visibleWidth(a.label)))),
338
- );
339
-
340
- groups.forEach((group, groupIndex) => {
341
- const lastGroup = groupIndex === groups.length - 1;
342
- lines.push(
343
- clampLine(
344
- [
345
- { text: " " },
346
- // One box, not a stack of them: only the first group opens it and
347
- // only the last closes it. Everything between branches off the side,
348
- // or three phases read as three half-drawn boxes.
349
- {
350
- text: `${
351
- lastGroup ? glyphs.groupBottom
352
- : groupIndex === 0 ? glyphs.groupTop
353
- : glyphs.groupMid
354
- } `,
355
- color: "dim",
356
- },
357
- { text: group.title },
358
- ],
359
- width,
360
- ),
361
- );
362
-
363
- const rail = lastGroup ? " " : `${glyphs.vertical} `;
364
- group.agents.forEach((entry, agentIndex) => {
365
- const lastAgent = agentIndex === group.agents.length - 1;
366
- const segments: WorkflowCardLine = [
367
- { text: " " },
368
- { text: rail, color: "dim" },
369
- { text: `${lastAgent ? glyphs.lastBranch : glyphs.branch} `, color: "dim" },
370
- rowGlyph(entry, glyphs),
371
- { text: " " },
372
- ];
373
-
374
- // Prepended rather than folded into `agentStatSegments`, which is the
375
- // ported stat tail in its recovered order. A replayed agent otherwise
376
- // renders as a tick with no tokens and no duration — indistinguishable
377
- // from one that somehow did the work for free.
378
- const statParts = entry.cached
379
- ? [REPLAYED_ANNOTATION, ...agentStatSegments(entry)]
380
- : agentStatSegments(entry);
381
- const pad = Math.max(0, labelColumn - visibleWidth(entry.label));
382
- segments.push({ text: statParts.length > 0 ? entry.label + " ".repeat(pad) : entry.label });
383
- for (const part of statParts) {
384
- segments.push({ text: " · ", color: "dim" }, { text: part, color: "dim" });
385
- }
386
- lines.push(clampLine(segments, width));
387
- });
388
- });
389
-
390
- // ---- log() output, below the tree ----
391
- for (const message of logs) {
392
- const [first, ...rest] = message.split("\n");
393
- lines.push(clampLine([{ text: ` ${glyphs.log} ${first}`, color: "dim" }], width));
394
- for (const continuation of rest) {
395
- lines.push(clampLine([{ text: ` ${continuation}`, color: "dim" }], width));
396
- }
397
- }
398
-
399
- // ---- Size warning ----
400
- const totalTokens =
401
- input.totalTokens ?? agents.reduce((sum, entry) => sum + (entry.tokens ?? 0), 0);
402
- const warning = sizeWarning({
403
- scheduledAgents: Math.max(input.agentCount ?? 0, totals.total),
404
- startedAgents: totals.started,
405
- totalTokens,
406
- agentCap: input.agentCap,
407
- tokenCap: input.tokenCap,
408
- });
409
- if (warning) {
410
- lines.push(
411
- clampLine([{ text: ` ${glyphs.warning} Large workflow · /agents → Workflows to stop`, color: "warning" }], width),
412
- );
413
- }
414
-
415
- return lines;
416
- }
417
-
418
- /* ------------------------------------------------------------------------- *
419
- * Rendering
420
- * ------------------------------------------------------------------------- */
421
-
422
- /** The card as plain text — what the layout tests assert against. */
423
- export function plainWorkflowCardLines(lines: readonly WorkflowCardLine[]): string[] {
424
- return lines.map(line => line.map(segment => segment.text).join(""));
425
- }
426
-
427
- /** Apply the theme. Nothing here changes the layout, only its colours. */
428
- export function styleWorkflowCardLines(lines: readonly WorkflowCardLine[], theme: Theme): string[] {
429
- return lines.map(line =>
430
- line
431
- .map(segment => {
432
- const text = segment.bold ? theme.bold(segment.text) : segment.text;
433
- return segment.color ? theme.fg(segment.color, text) : text;
434
- })
435
- .join(""),
436
- );
437
- }
438
-
439
- /** The card as a component, for a tool result or a session entry renderer. */
440
- export function renderWorkflowCard(input: WorkflowCardInput, theme: Theme): Text {
441
- return new Text(styleWorkflowCardLines(layoutWorkflowCard(input), theme).join("\n"), 0, 0);
442
- }
443
-
444
- /**
445
- * The card for a session entry, from the JSON a flag-launched run persisted.
446
- *
447
- * The same layout the tool result uses, not a second one — the only difference
448
- * is `showToolTitle`, because a session entry stands alone and nothing above it
449
- * says what it is. Returns undefined for an entry with no data, which is what
450
- * pi's renderer contract wants for "nothing to draw".
451
- */
452
- export function renderWorkflowEntryCard(data: WorkflowEntryData | undefined, theme: Theme): Text | undefined {
453
- if (!data) return undefined;
454
- return renderWorkflowCard(
455
- {
456
- progress: data.progress,
457
- task: {
458
- status: data.status,
459
- workflowName: data.name,
460
- startTime: data.startTime,
461
- endTime: data.endTime,
462
- },
463
- meta: data.meta,
464
- agentCount: data.agentCount,
465
- totalTokens: data.totalTokens,
466
- showToolTitle: true,
467
- },
468
- theme,
469
- );
470
- }