@xzzpig/pi-subagents 0.21.0 → 0.24.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 (1132) hide show
  1. package/CHANGELOG.md +356 -0
  2. package/README.md +2 -2
  3. package/agents/evidence-auditor.md +1 -0
  4. package/agents/oracle.md +1 -0
  5. package/agents/reviewer.md +1 -0
  6. package/bundle/agent-management.js +16 -0
  7. package/bundle/agents.js +41 -0
  8. package/bundle/background-work.js +16 -0
  9. package/bundle/capability-ceiling.js +22 -0
  10. package/bundle/child-tool-plan.js +11 -0
  11. package/bundle/chunk-355ECEP2.js +1321 -0
  12. package/bundle/chunk-35GII5EF.js +637 -0
  13. package/bundle/chunk-3G4JXNZ4.js +4130 -0
  14. package/bundle/chunk-3U633XDZ.js +749 -0
  15. package/bundle/chunk-4QFZZV3O.js +57 -0
  16. package/bundle/chunk-62OCY2S4.js +14 -0
  17. package/bundle/chunk-7J4ZXMY7.js +18 -0
  18. package/bundle/chunk-7K3Z6DM7.js +276 -0
  19. package/bundle/chunk-BGIYHF2W.js +138 -0
  20. package/bundle/chunk-CTPAE36Y.js +94 -0
  21. package/bundle/chunk-D4EHT5SJ.js +14 -0
  22. package/bundle/chunk-ED55MIC2.js +1681 -0
  23. package/bundle/chunk-F3NSN7UH.js +7331 -0
  24. package/bundle/chunk-FJWI64H7.js +490 -0
  25. package/bundle/chunk-H36HBZB2.js +753 -0
  26. package/bundle/chunk-ICNYIALB.js +7347 -0
  27. package/bundle/chunk-KD2IMFN4.js +1310 -0
  28. package/bundle/chunk-LCDJWBVM.js +57 -0
  29. package/bundle/chunk-LPVUHUZ7.js +5503 -0
  30. package/bundle/chunk-MYCL5QEJ.js +1372 -0
  31. package/bundle/chunk-NCWCVJLT.js +1768 -0
  32. package/bundle/chunk-NIXWDZZV.js +9 -0
  33. package/bundle/chunk-NTRJDXBC.js +4175 -0
  34. package/bundle/chunk-OFGSZBHP.js +16924 -0
  35. package/bundle/chunk-OTLRAB22.js +143 -0
  36. package/bundle/chunk-QXASAHIA.js +173 -0
  37. package/bundle/chunk-RB4GELQA.js +458 -0
  38. package/bundle/chunk-RK2HDPLK.js +1234 -0
  39. package/bundle/chunk-SW2VMNIU.js +526 -0
  40. package/bundle/chunk-T65XRVVM.js +940 -0
  41. package/bundle/chunk-U4ODUYAG.js +235 -0
  42. package/bundle/chunk-UFNSLL5D.js +9796 -0
  43. package/bundle/chunk-UKG4V45O.js +228 -0
  44. package/bundle/chunk-UQDHXMUG.js +264 -0
  45. package/bundle/chunk-V2KFIGFH.js +8774 -0
  46. package/bundle/chunk-VO3G7HI3.js +85 -0
  47. package/bundle/chunk-WPW4V6HM.js +227 -0
  48. package/bundle/chunk-WW76JRIX.js +175 -0
  49. package/bundle/chunk-XA3DY6UG.js +161 -0
  50. package/bundle/chunk-YFCK7H2S.js +129 -0
  51. package/bundle/chunk-YYREO77V.js +137 -0
  52. package/bundle/chunk-Z6TFJ6BR.js +400 -0
  53. package/bundle/control-channel.js +11 -0
  54. package/bundle/delegation.js +14 -0
  55. package/bundle/external-job-provider.js +20 -0
  56. package/bundle/external-runs.js +21 -0
  57. package/bundle/index.js +30 -0
  58. package/bundle/inspectors.js +8 -0
  59. package/bundle/intercom-bridge.js +11 -0
  60. package/bundle/preflight.js +468 -0
  61. package/bundle/project-panes.js +28 -0
  62. package/bundle/required-child-extensions.js +6 -0
  63. package/bundle/shared-types.js +8 -0
  64. package/bundle/supervisor-routing.js +12 -0
  65. package/bundle/workflow-resources.js +7 -0
  66. package/docs/agents.md +42 -10
  67. package/docs/configuration.md +59 -14
  68. package/docs/extension-api.md +61 -9
  69. package/docs/fork-supervisor-routing.md +77 -0
  70. package/docs/missions.md +2 -0
  71. package/docs/observability.md +20 -5
  72. package/docs/standalone-background.md +8 -6
  73. package/docs/tool-reference.md +18 -5
  74. package/docs/workflows.md +25 -7
  75. package/index.d.ts +3 -0
  76. package/index.js +14 -0
  77. package/node_modules/@xzzpig/pi-components/package.json +1 -2
  78. package/package.json +107 -86
  79. package/skills/council-mode/SKILL.md +1 -4
  80. package/skills/pi-subagents/SKILL.md +130 -106
  81. package/skills/pi-subagents/references/orchestration.md +124 -0
  82. package/skills/pi-subagents/references/prompting-and-roles.md +96 -291
  83. package/src/agents/advertised-agent-prompt.d.ts +13 -0
  84. package/src/agents/advertised-agent-prompt.js +68 -0
  85. package/src/agents/agent-eject.d.ts +39 -0
  86. package/src/agents/agent-eject.js +263 -0
  87. package/src/agents/agent-management.d.ts +33 -0
  88. package/src/agents/agent-management.js +1541 -0
  89. package/src/agents/agent-memory.d.ts +48 -0
  90. package/src/agents/agent-memory.js +350 -0
  91. package/src/agents/agent-refinements.d.ts +99 -0
  92. package/src/agents/agent-refinements.js +568 -0
  93. package/src/agents/agent-scope.d.ts +3 -0
  94. package/src/agents/agent-scope.js +8 -0
  95. package/src/agents/agent-selection.d.ts +2 -0
  96. package/src/agents/agent-selection.js +22 -0
  97. package/src/agents/agent-serializer.d.ts +7 -0
  98. package/src/agents/agent-serializer.js +213 -0
  99. package/src/agents/agents.d.ts +352 -0
  100. package/src/agents/agents.js +2817 -0
  101. package/src/agents/builtin-names.d.ts +1 -0
  102. package/src/agents/builtin-names.js +16 -0
  103. package/src/agents/chain-serializer.d.ts +6 -0
  104. package/src/agents/chain-serializer.js +318 -0
  105. package/src/agents/frontmatter.d.ts +19 -0
  106. package/src/agents/frontmatter.js +166 -0
  107. package/src/agents/global-npm-root.d.ts +6 -0
  108. package/src/agents/global-npm-root.js +57 -0
  109. package/src/agents/identity.d.ts +7 -0
  110. package/src/agents/identity.js +29 -0
  111. package/src/agents/proactive-skills.d.ts +35 -0
  112. package/src/agents/proactive-skills.js +155 -0
  113. package/src/agents/runtime-agent-events.d.ts +26 -0
  114. package/src/agents/runtime-agent-events.js +52 -0
  115. package/src/agents/runtime-agent-registry.d.ts +66 -0
  116. package/src/agents/runtime-agent-registry.js +415 -0
  117. package/src/agents/runtime-discovery.d.ts +13 -0
  118. package/src/agents/runtime-discovery.js +27 -0
  119. package/src/agents/skills.d.ts +34 -0
  120. package/src/agents/skills.js +718 -0
  121. package/src/api/agent-management.d.ts +2 -0
  122. package/src/api/agent-management.js +2 -0
  123. package/src/api/agents.d.ts +6 -0
  124. package/src/api/agents.js +3 -0
  125. package/src/api/background-work.d.ts +41 -0
  126. package/src/api/background-work.js +171 -0
  127. package/src/api/capability-ceiling.d.ts +1 -0
  128. package/src/api/capability-ceiling.js +1 -0
  129. package/src/api/child-tool-plan.d.ts +1 -0
  130. package/src/api/child-tool-plan.js +1 -0
  131. package/src/api/control-channel.d.ts +1 -0
  132. package/src/api/control-channel.js +1 -0
  133. package/src/api/delegation.d.ts +132 -0
  134. package/src/api/delegation.js +8 -0
  135. package/src/api/external-job-provider.d.ts +57 -0
  136. package/src/api/external-job-provider.js +139 -0
  137. package/src/api/external-runs.d.ts +47 -0
  138. package/src/api/external-runs.js +245 -0
  139. package/src/api/inspectors.d.ts +20 -0
  140. package/src/api/inspectors.js +11 -0
  141. package/src/api/intercom-bridge.d.ts +1 -0
  142. package/src/api/intercom-bridge.js +1 -0
  143. package/src/api/preflight.d.ts +183 -0
  144. package/src/api/preflight.js +455 -0
  145. package/src/api/project-panes.d.ts +7 -0
  146. package/src/api/project-panes.js +7 -0
  147. package/src/api/required-child-extensions.d.ts +1 -0
  148. package/src/api/required-child-extensions.js +1 -0
  149. package/src/api/shared-types.d.ts +1 -0
  150. package/src/api/shared-types.js +1 -0
  151. package/src/api/supervisor-routing.d.ts +110 -0
  152. package/src/api/supervisor-routing.js +95 -0
  153. package/src/api/workflow-resources.d.ts +2 -0
  154. package/src/api/workflow-resources.js +1 -0
  155. package/src/extension/active-runs-prompt.d.ts +7 -0
  156. package/src/extension/active-runs-prompt.js +29 -0
  157. package/src/extension/config.d.ts +7 -0
  158. package/src/extension/config.js +290 -0
  159. package/src/extension/context-injection.d.ts +52 -0
  160. package/src/extension/context-injection.js +102 -0
  161. package/src/extension/control-notices.d.ts +18 -0
  162. package/src/extension/control-notices.js +29 -0
  163. package/src/extension/declaration-pinning.d.ts +18 -0
  164. package/src/extension/declaration-pinning.js +167 -0
  165. package/src/extension/doctor.d.ts +34 -0
  166. package/src/extension/doctor.js +236 -0
  167. package/src/extension/fanout-child.d.ts +6 -0
  168. package/src/extension/fanout-child.js +278 -0
  169. package/src/extension/herdr-pi-bridge.d.ts +16 -0
  170. package/src/extension/herdr-pi-bridge.js +261 -0
  171. package/src/extension/index.d.ts +18 -0
  172. package/src/extension/index.js +1288 -0
  173. package/src/extension/public-execution.d.ts +71 -0
  174. package/src/extension/public-execution.js +214 -0
  175. package/src/extension/reply-workflow-script.d.ts +11 -0
  176. package/src/extension/reply-workflow-script.js +71 -0
  177. package/src/extension/rpc.d.ts +84 -0
  178. package/src/extension/rpc.js +729 -0
  179. package/src/extension/schemas.d.ts +276 -0
  180. package/src/extension/schemas.js +311 -0
  181. package/src/extension/steering-notices.d.ts +14 -0
  182. package/src/extension/steering-notices.js +22 -0
  183. package/src/extension/subagent-guide.d.ts +4 -0
  184. package/src/extension/subagent-guide.js +114 -0
  185. package/src/extension/subagent-options.d.ts +7 -0
  186. package/src/extension/subagent-options.js +64 -0
  187. package/src/extension/tool-activation.d.ts +7 -0
  188. package/src/extension/tool-activation.js +185 -0
  189. package/src/extension/tool-description.d.ts +19 -0
  190. package/src/extension/tool-description.js +169 -0
  191. package/src/extension/tool-result.d.ts +9 -0
  192. package/src/extension/tool-result.js +16 -0
  193. package/src/extension/upgrade-notice.d.ts +6 -0
  194. package/src/extension/upgrade-notice.js +42 -0
  195. package/src/inspectors/actions.d.ts +24 -0
  196. package/src/inspectors/actions.js +182 -0
  197. package/src/inspectors/ghostty/actions.d.ts +11 -0
  198. package/src/inspectors/ghostty/actions.js +62 -0
  199. package/src/inspectors/ghostty/plugin.d.ts +7 -0
  200. package/src/inspectors/ghostty/plugin.js +23 -0
  201. package/src/inspectors/herdr/actions.d.ts +25 -0
  202. package/src/inspectors/herdr/actions.js +133 -0
  203. package/src/inspectors/herdr/client.d.ts +41 -0
  204. package/src/inspectors/herdr/client.js +129 -0
  205. package/src/inspectors/herdr/focus.d.ts +24 -0
  206. package/src/inspectors/herdr/focus.js +49 -0
  207. package/src/inspectors/herdr/plugin.d.ts +6 -0
  208. package/src/inspectors/herdr/plugin.js +14 -0
  209. package/src/inspectors/herdr/project-panes.d.ts +136 -0
  210. package/src/inspectors/herdr/project-panes.js +610 -0
  211. package/src/inspectors/inspector-runner.d.ts +23 -0
  212. package/src/inspectors/inspector-runner.js +161 -0
  213. package/src/inspectors/plugins.d.ts +8 -0
  214. package/src/inspectors/plugins.js +82 -0
  215. package/src/inspectors/session-roots-codec.d.ts +15 -0
  216. package/src/inspectors/session-roots-codec.js +32 -0
  217. package/src/inspectors/shell-command.d.ts +1 -0
  218. package/src/inspectors/shell-command.js +16 -0
  219. package/src/inspectors/tmux/actions.d.ts +25 -0
  220. package/src/inspectors/tmux/actions.js +181 -0
  221. package/src/inspectors/tmux/client.d.ts +27 -0
  222. package/src/inspectors/tmux/client.js +64 -0
  223. package/src/inspectors/tmux/plugin.d.ts +7 -0
  224. package/src/inspectors/tmux/plugin.js +14 -0
  225. package/src/inspectors/types.d.ts +48 -0
  226. package/src/inspectors/types.js +1 -0
  227. package/src/integrations/herdr-status.d.ts +47 -0
  228. package/src/integrations/herdr-status.js +350 -0
  229. package/src/integrations/pi-web-session-liveness.d.ts +19 -0
  230. package/src/integrations/pi-web-session-liveness.js +53 -0
  231. package/src/integrations/program-status.d.ts +30 -0
  232. package/src/integrations/program-status.js +188 -0
  233. package/src/intercom/fork-supervisor-routing.d.ts +90 -0
  234. package/src/intercom/fork-supervisor-routing.js +392 -0
  235. package/src/intercom/intercom-bridge.d.ts +58 -0
  236. package/src/intercom/intercom-bridge.js +193 -0
  237. package/src/intercom/native-supervisor-channel.d.ts +97 -0
  238. package/src/intercom/native-supervisor-channel.js +1184 -0
  239. package/src/intercom/result-intercom.d.ts +35 -0
  240. package/src/intercom/result-intercom.js +376 -0
  241. package/src/intercom/supervisor-ui.d.ts +29 -0
  242. package/src/intercom/supervisor-ui.js +49 -0
  243. package/src/missions/actions.d.ts +54 -0
  244. package/src/missions/actions.js +400 -0
  245. package/src/missions/goal-driver.d.ts +16 -0
  246. package/src/missions/goal-driver.js +171 -0
  247. package/src/missions/lifecycle.d.ts +50 -0
  248. package/src/missions/lifecycle.js +388 -0
  249. package/src/missions/store.d.ts +21 -0
  250. package/src/missions/store.js +605 -0
  251. package/src/missions/types.d.ts +169 -0
  252. package/src/missions/types.js +9 -0
  253. package/src/missions/workflow-state.d.ts +14 -0
  254. package/src/missions/workflow-state.js +273 -0
  255. package/src/policy/authority.d.ts +9 -0
  256. package/src/policy/authority.js +41 -0
  257. package/src/profiles/profiles.d.ts +134 -0
  258. package/src/profiles/profiles.js +526 -0
  259. package/src/runs/background/active-async-capacity.d.ts +115 -0
  260. package/src/runs/background/active-async-capacity.js +517 -0
  261. package/src/runs/background/active-run-index.d.ts +12 -0
  262. package/src/runs/background/active-run-index.js +157 -0
  263. package/src/runs/background/async-execution.d.ts +304 -0
  264. package/src/runs/background/async-execution.js +2206 -0
  265. package/src/runs/background/async-job-tracker.d.ts +37 -0
  266. package/src/runs/background/async-job-tracker.js +921 -0
  267. package/src/runs/background/async-resume.d.ts +60 -0
  268. package/src/runs/background/async-resume.js +707 -0
  269. package/src/runs/background/async-retention.d.ts +45 -0
  270. package/src/runs/background/async-retention.js +932 -0
  271. package/src/runs/background/async-status-snapshot.d.ts +9 -0
  272. package/src/runs/background/async-status-snapshot.js +26 -0
  273. package/src/runs/background/async-status.d.ts +177 -0
  274. package/src/runs/background/async-status.js +710 -0
  275. package/src/runs/background/auto-drain.d.ts +16 -0
  276. package/src/runs/background/auto-drain.js +71 -0
  277. package/src/runs/background/await-async-run.d.ts +26 -0
  278. package/src/runs/background/await-async-run.js +83 -0
  279. package/src/runs/background/binary-bootstrap.d.ts +8 -0
  280. package/src/runs/background/binary-bootstrap.js +69 -0
  281. package/src/runs/background/boot-id.d.ts +12 -0
  282. package/src/runs/background/boot-id.js +47 -0
  283. package/src/runs/background/calendar-schedule.d.ts +26 -0
  284. package/src/runs/background/calendar-schedule.js +93 -0
  285. package/src/runs/background/chain-append.d.ts +34 -0
  286. package/src/runs/background/chain-append.js +299 -0
  287. package/src/runs/background/chain-root-attachment.d.ts +51 -0
  288. package/src/runs/background/chain-root-attachment.js +186 -0
  289. package/src/runs/background/completion-batcher.d.ts +51 -0
  290. package/src/runs/background/completion-batcher.js +119 -0
  291. package/src/runs/background/completion-dedupe.d.ts +13 -0
  292. package/src/runs/background/completion-dedupe.js +48 -0
  293. package/src/runs/background/completion-replay.d.ts +47 -0
  294. package/src/runs/background/completion-replay.js +266 -0
  295. package/src/runs/background/control-channel.d.ts +170 -0
  296. package/src/runs/background/control-channel.js +610 -0
  297. package/src/runs/background/fleet-view.d.ts +63 -0
  298. package/src/runs/background/fleet-view.js +666 -0
  299. package/src/runs/background/index-segment.d.ts +16 -0
  300. package/src/runs/background/index-segment.js +58 -0
  301. package/src/runs/background/inspect-rpc.d.ts +64 -0
  302. package/src/runs/background/inspect-rpc.js +422 -0
  303. package/src/runs/background/interrupted-elsewhere.d.ts +22 -0
  304. package/src/runs/background/interrupted-elsewhere.js +68 -0
  305. package/src/runs/background/notify.d.ts +214 -0
  306. package/src/runs/background/notify.js +1001 -0
  307. package/src/runs/background/owned-process-tree.d.ts +10 -0
  308. package/src/runs/background/owned-process-tree.js +116 -0
  309. package/src/runs/background/parallel-groups.d.ts +3 -0
  310. package/src/runs/background/parallel-groups.js +46 -0
  311. package/src/runs/background/pid-namespace.d.ts +2 -0
  312. package/src/runs/background/pid-namespace.js +19 -0
  313. package/src/runs/background/process-terminal-candidate.d.ts +17 -0
  314. package/src/runs/background/process-terminal-candidate.js +96 -0
  315. package/src/runs/background/process-terminal.d.ts +21 -0
  316. package/src/runs/background/process-terminal.js +227 -0
  317. package/src/runs/background/result-delivery-ownership.d.ts +14 -0
  318. package/src/runs/background/result-delivery-ownership.js +38 -0
  319. package/src/runs/background/result-files.d.ts +63 -0
  320. package/src/runs/background/result-files.js +629 -0
  321. package/src/runs/background/result-watcher.d.ts +92 -0
  322. package/src/runs/background/result-watcher.js +819 -0
  323. package/src/runs/background/resume-guidance.d.ts +4 -0
  324. package/src/runs/background/resume-guidance.js +57 -0
  325. package/src/runs/background/retained-children.d.ts +24 -0
  326. package/src/runs/background/retained-children.js +128 -0
  327. package/src/runs/background/retained-nested-route-tracker.d.ts +12 -0
  328. package/src/runs/background/retained-nested-route-tracker.js +90 -0
  329. package/src/runs/background/run-child-session.d.ts +123 -0
  330. package/src/runs/background/run-child-session.js +670 -0
  331. package/src/runs/background/run-id-query.d.ts +3 -0
  332. package/src/runs/background/run-id-query.js +6 -0
  333. package/src/runs/background/run-id-resolver.d.ts +22 -0
  334. package/src/runs/background/run-id-resolver.js +172 -0
  335. package/src/runs/background/run-status.d.ts +25 -0
  336. package/src/runs/background/run-status.js +850 -0
  337. package/src/runs/background/runner-aliases.d.ts +17 -0
  338. package/src/runs/background/runner-aliases.js +191 -0
  339. package/src/runs/background/runner-child-launch.d.ts +24 -0
  340. package/src/runs/background/runner-child-launch.js +72 -0
  341. package/src/runs/background/runner-child-sessions.d.ts +6 -0
  342. package/src/runs/background/runner-child-sessions.js +34 -0
  343. package/src/runs/background/runner-http-dispatcher.d.ts +45 -0
  344. package/src/runs/background/runner-http-dispatcher.js +115 -0
  345. package/src/runs/background/runner-startup-failure.d.ts +13 -0
  346. package/src/runs/background/runner-startup-failure.js +46 -0
  347. package/src/runs/background/scheduled-runs.d.ts +127 -0
  348. package/src/runs/background/scheduled-runs.js +1265 -0
  349. package/src/runs/background/stale-run-reconciler.d.ts +62 -0
  350. package/src/runs/background/stale-run-reconciler.js +509 -0
  351. package/src/runs/background/steering.d.ts +51 -0
  352. package/src/runs/background/steering.js +246 -0
  353. package/src/runs/background/subagent-runner-bootstrap.d.ts +13 -0
  354. package/src/runs/background/subagent-runner-bootstrap.js +283 -0
  355. package/src/runs/background/subagent-runner.d.ts +210 -0
  356. package/src/runs/background/subagent-runner.js +4963 -0
  357. package/src/runs/background/subagent-wait.d.ts +124 -0
  358. package/src/runs/background/subagent-wait.js +756 -0
  359. package/src/runs/background/terminal-run-index.d.ts +10 -0
  360. package/src/runs/background/terminal-run-index.js +209 -0
  361. package/src/runs/background/top-level-async.d.ts +7 -0
  362. package/src/runs/background/top-level-async.js +5 -0
  363. package/src/runs/background/wait-completions.d.ts +28 -0
  364. package/src/runs/background/wait-completions.js +264 -0
  365. package/src/runs/background/wait-config.d.ts +8 -0
  366. package/src/runs/background/wait-config.js +46 -0
  367. package/src/runs/background/wait-subscriptions.d.ts +26 -0
  368. package/src/runs/background/wait-subscriptions.js +339 -0
  369. package/src/runs/background/wait-tool.d.ts +6 -0
  370. package/src/runs/background/wait-tool.js +48 -0
  371. package/src/runs/background/workflow-terminal-proof.d.ts +47 -0
  372. package/src/runs/background/workflow-terminal-proof.js +116 -0
  373. package/src/runs/foreground/async-dismiss-action.d.ts +6 -0
  374. package/src/runs/foreground/async-dismiss-action.js +82 -0
  375. package/src/runs/foreground/async-steering-action.d.ts +31 -0
  376. package/src/runs/foreground/async-steering-action.js +294 -0
  377. package/src/runs/foreground/async-stop-action.d.ts +13 -0
  378. package/src/runs/foreground/async-stop-action.js +213 -0
  379. package/src/runs/foreground/command-action.d.ts +12 -0
  380. package/src/runs/foreground/command-action.js +38 -0
  381. package/src/runs/foreground/execution.d.ts +10 -0
  382. package/src/runs/foreground/execution.js +2322 -0
  383. package/src/runs/foreground/foreground-control.d.ts +24 -0
  384. package/src/runs/foreground/foreground-control.js +138 -0
  385. package/src/runs/foreground/foreground-history.d.ts +25 -0
  386. package/src/runs/foreground/foreground-history.js +267 -0
  387. package/src/runs/foreground/prompt-audit.d.ts +32 -0
  388. package/src/runs/foreground/prompt-audit.js +138 -0
  389. package/src/runs/foreground/subagent-executor.d.ts +316 -0
  390. package/src/runs/foreground/subagent-executor.js +7986 -0
  391. package/src/runs/foreground/workflow-detach-reconcile.d.ts +15 -0
  392. package/src/runs/foreground/workflow-detach-reconcile.js +283 -0
  393. package/src/runs/foreground/workflow-foreground-steering.d.ts +43 -0
  394. package/src/runs/foreground/workflow-foreground-steering.js +148 -0
  395. package/src/runs/shared/abort-recovery.d.ts +26 -0
  396. package/src/runs/shared/abort-recovery.js +108 -0
  397. package/src/runs/shared/acceptance.d.ts +144 -0
  398. package/src/runs/shared/acceptance.js +1616 -0
  399. package/src/runs/shared/agent-contract.d.ts +5 -0
  400. package/src/runs/shared/agent-contract.js +35 -0
  401. package/src/runs/shared/async-status-projection.d.ts +100 -0
  402. package/src/runs/shared/async-status-projection.js +566 -0
  403. package/src/runs/shared/background-process-options.d.ts +4 -0
  404. package/src/runs/shared/background-process-options.js +6 -0
  405. package/src/runs/shared/capability-ceiling.d.ts +58 -0
  406. package/src/runs/shared/capability-ceiling.js +179 -0
  407. package/src/runs/shared/chain-outputs.d.ts +18 -0
  408. package/src/runs/shared/chain-outputs.js +104 -0
  409. package/src/runs/shared/child-commands.d.ts +29 -0
  410. package/src/runs/shared/child-commands.js +254 -0
  411. package/src/runs/shared/child-hooks.d.ts +31 -0
  412. package/src/runs/shared/child-hooks.js +173 -0
  413. package/src/runs/shared/child-identity.d.ts +23 -0
  414. package/src/runs/shared/child-identity.js +40 -0
  415. package/src/runs/shared/child-launch-plan.d.ts +70 -0
  416. package/src/runs/shared/child-launch-plan.js +88 -0
  417. package/src/runs/shared/child-launch.d.ts +128 -0
  418. package/src/runs/shared/child-launch.js +262 -0
  419. package/src/runs/shared/child-lifecycle.d.ts +13 -0
  420. package/src/runs/shared/child-lifecycle.js +22 -0
  421. package/src/runs/shared/child-runtime-config.d.ts +111 -0
  422. package/src/runs/shared/child-runtime-config.js +44 -0
  423. package/src/runs/shared/child-session.d.ts +178 -0
  424. package/src/runs/shared/child-session.js +726 -0
  425. package/src/runs/shared/child-tool-plan.d.ts +101 -0
  426. package/src/runs/shared/child-tool-plan.js +430 -0
  427. package/src/runs/shared/claude-code-adapter.d.ts +80 -0
  428. package/src/runs/shared/claude-code-adapter.js +255 -0
  429. package/src/runs/shared/codex-exec-adapter.d.ts +25 -0
  430. package/src/runs/shared/codex-exec-adapter.js +127 -0
  431. package/src/runs/shared/context-mode.d.ts +12 -0
  432. package/src/runs/shared/context-mode.js +38 -0
  433. package/src/runs/shared/cursor-agent-adapter.d.ts +26 -0
  434. package/src/runs/shared/cursor-agent-adapter.js +99 -0
  435. package/src/runs/shared/dynamic-fanout.d.ts +49 -0
  436. package/src/runs/shared/dynamic-fanout.js +273 -0
  437. package/src/runs/shared/effective-system-prompt.d.ts +17 -0
  438. package/src/runs/shared/effective-system-prompt.js +23 -0
  439. package/src/runs/shared/extension-bindings.d.ts +25 -0
  440. package/src/runs/shared/extension-bindings.js +96 -0
  441. package/src/runs/shared/external-cli-contract.d.ts +29 -0
  442. package/src/runs/shared/external-cli-contract.js +145 -0
  443. package/src/runs/shared/external-cli-preflight.d.ts +41 -0
  444. package/src/runs/shared/external-cli-preflight.js +159 -0
  445. package/src/runs/shared/external-cli-runner.d.ts +65 -0
  446. package/src/runs/shared/external-cli-runner.js +425 -0
  447. package/src/runs/shared/external-job-bridge.d.ts +24 -0
  448. package/src/runs/shared/external-job-bridge.js +486 -0
  449. package/src/runs/shared/external-job-runner.d.ts +44 -0
  450. package/src/runs/shared/external-job-runner.js +352 -0
  451. package/src/runs/shared/fast-mode-extension.d.ts +3 -0
  452. package/src/runs/shared/fast-mode-extension.js +8 -0
  453. package/src/runs/shared/fork-placed-env.d.ts +4 -0
  454. package/src/runs/shared/fork-placed-env.js +13 -0
  455. package/src/runs/shared/git-environment.d.ts +2 -0
  456. package/src/runs/shared/git-environment.js +27 -0
  457. package/src/runs/shared/herdr-connection.d.ts +79 -0
  458. package/src/runs/shared/herdr-connection.js +269 -0
  459. package/src/runs/shared/herdr-external-adapters.d.ts +148 -0
  460. package/src/runs/shared/herdr-external-adapters.js +404 -0
  461. package/src/runs/shared/herdr-machine.d.ts +59 -0
  462. package/src/runs/shared/herdr-machine.js +294 -0
  463. package/src/runs/shared/herdr-pane-host.d.ts +88 -0
  464. package/src/runs/shared/herdr-pane-host.js +155 -0
  465. package/src/runs/shared/herdr-pi-protocol.d.ts +21 -0
  466. package/src/runs/shared/herdr-pi-protocol.js +57 -0
  467. package/src/runs/shared/herdr-placed-run.d.ts +144 -0
  468. package/src/runs/shared/herdr-placed-run.js +380 -0
  469. package/src/runs/shared/host-step-status.d.ts +33 -0
  470. package/src/runs/shared/host-step-status.js +244 -0
  471. package/src/runs/shared/lane-metadata.d.ts +23 -0
  472. package/src/runs/shared/lane-metadata.js +126 -0
  473. package/src/runs/shared/launch-cwd.d.ts +1 -0
  474. package/src/runs/shared/launch-cwd.js +16 -0
  475. package/src/runs/shared/local-machine-access.d.ts +5 -0
  476. package/src/runs/shared/local-machine-access.js +28 -0
  477. package/src/runs/shared/long-running-guard.d.ts +34 -0
  478. package/src/runs/shared/long-running-guard.js +256 -0
  479. package/src/runs/shared/mcp-config-sources.d.ts +33 -0
  480. package/src/runs/shared/mcp-config-sources.js +418 -0
  481. package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +86 -0
  482. package/src/runs/shared/mcp-direct-tool-allowlist.js +477 -0
  483. package/src/runs/shared/mcp-direct-tool-grant.d.ts +42 -0
  484. package/src/runs/shared/mcp-direct-tool-grant.js +159 -0
  485. package/src/runs/shared/model-resolution-diagnostic.d.ts +44 -0
  486. package/src/runs/shared/model-resolution-diagnostic.js +116 -0
  487. package/src/runs/shared/model-resolution.d.ts +109 -0
  488. package/src/runs/shared/model-resolution.js +411 -0
  489. package/src/runs/shared/model-scope.d.ts +68 -0
  490. package/src/runs/shared/model-scope.js +171 -0
  491. package/src/runs/shared/mutation-evidence.d.ts +18 -0
  492. package/src/runs/shared/mutation-evidence.js +198 -0
  493. package/src/runs/shared/nested-events.d.ts +135 -0
  494. package/src/runs/shared/nested-events.js +1090 -0
  495. package/src/runs/shared/nested-path.d.ts +8 -0
  496. package/src/runs/shared/nested-path.js +34 -0
  497. package/src/runs/shared/nested-render.d.ts +20 -0
  498. package/src/runs/shared/nested-render.js +115 -0
  499. package/src/runs/shared/orca-progress-tabs.d.ts +31 -0
  500. package/src/runs/shared/orca-progress-tabs.js +503 -0
  501. package/src/runs/shared/parallel-handoff.d.ts +78 -0
  502. package/src/runs/shared/parallel-handoff.js +783 -0
  503. package/src/runs/shared/parallel-utils.d.ts +177 -0
  504. package/src/runs/shared/parallel-utils.js +125 -0
  505. package/src/runs/shared/partial-output.d.ts +24 -0
  506. package/src/runs/shared/partial-output.js +35 -0
  507. package/src/runs/shared/permissions.d.ts +12 -0
  508. package/src/runs/shared/permissions.js +92 -0
  509. package/src/runs/shared/pi-spawn.d.ts +31 -0
  510. package/src/runs/shared/pi-spawn.js +211 -0
  511. package/src/runs/shared/placed-run-owner.d.ts +49 -0
  512. package/src/runs/shared/placed-run-owner.js +93 -0
  513. package/src/runs/shared/placement-host.d.ts +99 -0
  514. package/src/runs/shared/placement-host.js +157 -0
  515. package/src/runs/shared/process-signal.d.ts +15 -0
  516. package/src/runs/shared/process-signal.js +21 -0
  517. package/src/runs/shared/profile-extensions.d.ts +21 -0
  518. package/src/runs/shared/profile-extensions.js +122 -0
  519. package/src/runs/shared/profile-launch-env.d.ts +26 -0
  520. package/src/runs/shared/profile-launch-env.js +90 -0
  521. package/src/runs/shared/readonly-drain-observation.d.ts +25 -0
  522. package/src/runs/shared/readonly-drain-observation.js +50 -0
  523. package/src/runs/shared/rex-machine.d.ts +25 -0
  524. package/src/runs/shared/rex-machine.js +83 -0
  525. package/src/runs/shared/rex-pane-host.d.ts +62 -0
  526. package/src/runs/shared/rex-pane-host.js +327 -0
  527. package/src/runs/shared/run-fanout-budget.d.ts +14 -0
  528. package/src/runs/shared/run-fanout-budget.js +258 -0
  529. package/src/runs/shared/run-ownership.d.ts +3 -0
  530. package/src/runs/shared/run-ownership.js +8 -0
  531. package/src/runs/shared/runner-launcher.d.ts +11 -0
  532. package/src/runs/shared/runner-launcher.js +24 -0
  533. package/src/runs/shared/runtime-acknowledged-extensions.d.ts +7 -0
  534. package/src/runs/shared/runtime-acknowledged-extensions.js +44 -0
  535. package/src/runs/shared/sandbox-profile-guard.d.ts +23 -0
  536. package/src/runs/shared/sandbox-profile-guard.js +106 -0
  537. package/src/runs/shared/sandbox-startup-diagnostics.d.ts +21 -0
  538. package/src/runs/shared/sandbox-startup-diagnostics.js +51 -0
  539. package/src/runs/shared/session-lease.d.ts +69 -0
  540. package/src/runs/shared/session-lease.js +250 -0
  541. package/src/runs/shared/single-output.d.ts +90 -0
  542. package/src/runs/shared/single-output.js +349 -0
  543. package/src/runs/shared/spawn-budget.d.ts +20 -0
  544. package/src/runs/shared/spawn-budget.js +93 -0
  545. package/src/runs/shared/structured-output.d.ts +66 -0
  546. package/src/runs/shared/structured-output.js +483 -0
  547. package/src/runs/shared/subagent-control.d.ts +50 -0
  548. package/src/runs/shared/subagent-control.js +247 -0
  549. package/src/runs/shared/subagent-prompt-runtime.d.ts +90 -0
  550. package/src/runs/shared/subagent-prompt-runtime.js +776 -0
  551. package/src/runs/shared/tool-availability.d.ts +16 -0
  552. package/src/runs/shared/tool-availability.js +29 -0
  553. package/src/runs/shared/tool-budget.d.ts +21 -0
  554. package/src/runs/shared/tool-budget.js +78 -0
  555. package/src/runs/shared/tool-timeout.d.ts +31 -0
  556. package/src/runs/shared/tool-timeout.js +73 -0
  557. package/src/runs/shared/usage-budget.d.ts +7 -0
  558. package/src/runs/shared/usage-budget.js +74 -0
  559. package/src/runs/shared/usage-reconciliation.d.ts +8 -0
  560. package/src/runs/shared/usage-reconciliation.js +71 -0
  561. package/src/runs/shared/workflow-async-child-guidance.d.ts +3 -0
  562. package/src/runs/shared/workflow-async-child-guidance.js +17 -0
  563. package/src/runs/shared/workflow-graph.d.ts +31 -0
  564. package/src/runs/shared/workflow-graph.js +221 -0
  565. package/src/runs/shared/worktree-cleanup-apply.d.ts +36 -0
  566. package/src/runs/shared/worktree-cleanup-apply.js +178 -0
  567. package/src/runs/shared/worktree-cleanup-plan.d.ts +84 -0
  568. package/src/runs/shared/worktree-cleanup-plan.js +803 -0
  569. package/src/runs/shared/worktree-lock.d.ts +5 -0
  570. package/src/runs/shared/worktree-lock.js +40 -0
  571. package/src/runs/shared/worktree-setup-command.d.ts +38 -0
  572. package/src/runs/shared/worktree-setup-command.js +200 -0
  573. package/src/runs/shared/worktree.d.ts +181 -0
  574. package/src/runs/shared/worktree.js +1346 -0
  575. package/src/shared/accessible-dir.d.ts +11 -0
  576. package/src/shared/accessible-dir.js +39 -0
  577. package/src/shared/agent-stream-options.d.ts +5 -0
  578. package/src/shared/agent-stream-options.js +3 -0
  579. package/src/shared/artifacts.d.ts +22 -0
  580. package/src/shared/artifacts.js +272 -0
  581. package/src/shared/atomic-json.d.ts +19 -0
  582. package/src/shared/atomic-json.js +61 -0
  583. package/src/shared/capacity-resilient-json.d.ts +26 -0
  584. package/src/shared/capacity-resilient-json.js +86 -0
  585. package/src/shared/child-cache-retention.d.ts +29 -0
  586. package/src/shared/child-cache-retention.js +40 -0
  587. package/src/shared/child-session-name.d.ts +8 -0
  588. package/src/shared/child-session-name.js +40 -0
  589. package/src/shared/child-transcript.d.ts +37 -0
  590. package/src/shared/child-transcript.js +225 -0
  591. package/src/shared/completion-owner.d.ts +7 -0
  592. package/src/shared/completion-owner.js +13 -0
  593. package/src/shared/disabled-features.d.ts +93 -0
  594. package/src/shared/disabled-features.js +120 -0
  595. package/src/shared/display-text.d.ts +5 -0
  596. package/src/shared/display-text.js +154 -0
  597. package/src/shared/edit-distance.d.ts +4 -0
  598. package/src/shared/edit-distance.js +32 -0
  599. package/src/shared/extension-context.d.ts +21 -0
  600. package/src/shared/extension-context.js +39 -0
  601. package/src/shared/file-coalescer.d.ts +11 -0
  602. package/src/shared/file-coalescer.js +34 -0
  603. package/src/shared/file-lease.d.ts +10 -0
  604. package/src/shared/file-lease.js +106 -0
  605. package/src/shared/file-system-retry.d.ts +31 -0
  606. package/src/shared/file-system-retry.js +84 -0
  607. package/src/shared/fork-context.d.ts +64 -0
  608. package/src/shared/fork-context.js +185 -0
  609. package/src/shared/fork-session-cwd.d.ts +2 -0
  610. package/src/shared/fork-session-cwd.js +23 -0
  611. package/src/shared/formatters.d.ts +35 -0
  612. package/src/shared/formatters.js +137 -0
  613. package/src/shared/jsonl-writer.d.ts +20 -0
  614. package/src/shared/jsonl-writer.js +67 -0
  615. package/src/shared/launch-contract.d.ts +65 -0
  616. package/src/shared/launch-contract.js +145 -0
  617. package/src/shared/model-info.d.ts +55 -0
  618. package/src/shared/model-info.js +103 -0
  619. package/src/shared/model-response-aliases.d.ts +1 -0
  620. package/src/shared/model-response-aliases.js +15 -0
  621. package/src/shared/node-executable.d.ts +1 -0
  622. package/src/shared/node-executable.js +20 -0
  623. package/src/shared/opencode-session-headers.d.ts +12 -0
  624. package/src/shared/opencode-session-headers.js +26 -0
  625. package/src/shared/package-version.d.ts +2 -0
  626. package/src/shared/package-version.js +14 -0
  627. package/src/shared/parent-wake.d.ts +26 -0
  628. package/src/shared/parent-wake.js +68 -0
  629. package/src/shared/permission-profile.d.ts +26 -0
  630. package/src/shared/permission-profile.js +49 -0
  631. package/src/shared/prompt-resources.d.ts +5 -0
  632. package/src/shared/prompt-resources.js +10 -0
  633. package/src/shared/provider-diagnostics.d.ts +9 -0
  634. package/src/shared/provider-diagnostics.js +75 -0
  635. package/src/shared/pruned-fork.d.ts +34 -0
  636. package/src/shared/pruned-fork.js +434 -0
  637. package/src/shared/required-child-extensions.d.ts +34 -0
  638. package/src/shared/required-child-extensions.js +105 -0
  639. package/src/shared/runtime-module-path.d.ts +10 -0
  640. package/src/shared/runtime-module-path.js +16 -0
  641. package/src/shared/sandbox-profile.d.ts +12 -0
  642. package/src/shared/sandbox-profile.js +35 -0
  643. package/src/shared/session-file-trust.d.ts +1 -0
  644. package/src/shared/session-file-trust.js +20 -0
  645. package/src/shared/session-identity.d.ts +8 -0
  646. package/src/shared/session-identity.js +32 -0
  647. package/src/shared/session-succession.d.ts +4 -0
  648. package/src/shared/session-succession.js +24 -0
  649. package/src/shared/session-tokens.d.ts +2 -0
  650. package/src/shared/session-tokens.js +58 -0
  651. package/src/shared/settings-file-lease.d.ts +4 -0
  652. package/src/shared/settings-file-lease.js +38 -0
  653. package/src/shared/settings.d.ts +146 -0
  654. package/src/shared/settings.js +247 -0
  655. package/src/shared/shortcuts.d.ts +1 -0
  656. package/src/shared/shortcuts.js +17 -0
  657. package/src/shared/status-format.d.ts +9 -0
  658. package/src/shared/status-format.js +60 -0
  659. package/src/shared/thinking-ceiling.d.ts +13 -0
  660. package/src/shared/thinking-ceiling.js +37 -0
  661. package/src/shared/types.d.ts +2840 -0
  662. package/src/shared/types.js +276 -0
  663. package/src/shared/utf8.d.ts +5 -0
  664. package/src/shared/utf8.js +12 -0
  665. package/src/shared/utils.d.ts +83 -0
  666. package/src/shared/utils.js +612 -0
  667. package/src/shared/watch-strategy.d.ts +2 -0
  668. package/src/shared/watch-strategy.js +5 -0
  669. package/src/shared/workflow-child-permit.d.ts +58 -0
  670. package/src/shared/workflow-child-permit.js +159 -0
  671. package/src/slash/delegation-adapters.d.ts +154 -0
  672. package/src/slash/delegation-adapters.js +316 -0
  673. package/src/slash/delegation-json.d.ts +10 -0
  674. package/src/slash/delegation-json.js +117 -0
  675. package/src/slash/delegation-request.d.ts +12 -0
  676. package/src/slash/delegation-request.js +174 -0
  677. package/src/slash/prompt-template-bridge.d.ts +29 -0
  678. package/src/slash/prompt-template-bridge.js +399 -0
  679. package/src/slash/prompt-workflows.d.ts +21 -0
  680. package/src/slash/prompt-workflows.js +274 -0
  681. package/src/slash/selector.d.ts +47 -0
  682. package/src/slash/selector.js +117 -0
  683. package/src/slash/slash-bridge.d.ts +30 -0
  684. package/src/slash/slash-bridge.js +132 -0
  685. package/src/slash/slash-commands.d.ts +10 -0
  686. package/src/slash/slash-commands.js +1059 -0
  687. package/src/slash/slash-live-state.d.ts +21 -0
  688. package/src/slash/slash-live-state.js +263 -0
  689. package/src/slash/subagent-cost.d.ts +29 -0
  690. package/src/slash/subagent-cost.js +310 -0
  691. package/src/slash/subagents-admin.d.ts +3 -0
  692. package/src/slash/subagents-admin.js +481 -0
  693. package/src/tui/fleet-layout.d.ts +20 -0
  694. package/src/tui/fleet-layout.js +17 -0
  695. package/src/tui/fleet-native-transcript.d.ts +53 -0
  696. package/src/tui/fleet-native-transcript.js +339 -0
  697. package/src/tui/fleet-status.d.ts +92 -0
  698. package/src/tui/fleet-status.js +1132 -0
  699. package/src/tui/fleet-transcript.d.ts +64 -0
  700. package/src/tui/fleet-transcript.js +544 -0
  701. package/src/tui/fleet-viewport.d.ts +12 -0
  702. package/src/tui/fleet-viewport.js +35 -0
  703. package/src/tui/fleet.d.ts +196 -0
  704. package/src/tui/fleet.js +1588 -0
  705. package/src/tui/mouse-events.d.ts +21 -0
  706. package/src/tui/mouse-events.js +26 -0
  707. package/src/tui/render-helpers.d.ts +23 -0
  708. package/src/tui/render-helpers.js +100 -0
  709. package/src/tui/render.d.ts +66 -0
  710. package/src/tui/render.js +3707 -0
  711. package/src/tui/running-tone.d.ts +10 -0
  712. package/src/tui/running-tone.js +22 -0
  713. package/src/tui/subagent-messages.d.ts +22 -0
  714. package/src/tui/subagent-messages.js +270 -0
  715. package/src/ui-silent-marker.d.ts +20 -0
  716. package/src/ui-silent-marker.js +25 -0
  717. package/src/watchdog/change-signature.d.ts +7 -0
  718. package/src/watchdog/change-signature.js +243 -0
  719. package/src/watchdog/child-status.d.ts +53 -0
  720. package/src/watchdog/child-status.js +187 -0
  721. package/src/watchdog/diff-tool.d.ts +25 -0
  722. package/src/watchdog/diff-tool.js +104 -0
  723. package/src/watchdog/emission-guard.d.ts +36 -0
  724. package/src/watchdog/emission-guard.js +97 -0
  725. package/src/watchdog/guidance.d.ts +3 -0
  726. package/src/watchdog/guidance.js +19 -0
  727. package/src/watchdog/lsp-diagnostics.d.ts +17 -0
  728. package/src/watchdog/lsp-diagnostics.js +489 -0
  729. package/src/watchdog/model-selection.d.ts +24 -0
  730. package/src/watchdog/model-selection.js +167 -0
  731. package/src/watchdog/permission-arbiter.d.ts +20 -0
  732. package/src/watchdog/permission-arbiter.js +135 -0
  733. package/src/watchdog/register-child.d.ts +13 -0
  734. package/src/watchdog/register-child.js +128 -0
  735. package/src/watchdog/register-main.d.ts +11 -0
  736. package/src/watchdog/register-main.js +400 -0
  737. package/src/watchdog/render.d.ts +3 -0
  738. package/src/watchdog/render.js +33 -0
  739. package/src/watchdog/review.d.ts +36 -0
  740. package/src/watchdog/review.js +319 -0
  741. package/src/watchdog/rules.d.ts +21 -0
  742. package/src/watchdog/rules.js +58 -0
  743. package/src/watchdog/runtime.d.ts +195 -0
  744. package/src/watchdog/runtime.js +864 -0
  745. package/src/watchdog/scope.d.ts +14 -0
  746. package/src/watchdog/scope.js +44 -0
  747. package/src/watchdog/settings.d.ts +29 -0
  748. package/src/watchdog/settings.js +480 -0
  749. package/src/watchdog/tool-actions.d.ts +17 -0
  750. package/src/watchdog/tool-actions.js +150 -0
  751. package/src/watchdog/turn-delta.d.ts +15 -0
  752. package/src/watchdog/turn-delta.js +188 -0
  753. package/src/watchdog/types.d.ts +141 -0
  754. package/src/watchdog/types.js +27 -0
  755. package/src/watchdog/warning-format.d.ts +7 -0
  756. package/src/watchdog/warning-format.js +59 -0
  757. package/src/workflows/chat-progress.d.ts +37 -0
  758. package/src/workflows/chat-progress.js +129 -0
  759. package/src/workflows/host-command.d.ts +30 -0
  760. package/src/workflows/host-command.js +227 -0
  761. package/src/workflows/scripted-workflow.d.ts +204 -0
  762. package/src/workflows/scripted-workflow.js +1673 -0
  763. package/src/workflows/structured-workflow-scripts.d.ts +10 -0
  764. package/src/workflows/structured-workflow-scripts.js +179 -0
  765. package/src/workflows/workflow-auto-resume.d.ts +32 -0
  766. package/src/workflows/workflow-auto-resume.js +102 -0
  767. package/src/workflows/workflow-checklist.d.ts +127 -0
  768. package/src/workflows/workflow-checklist.js +314 -0
  769. package/src/workflows/workflow-child-summary.d.ts +24 -0
  770. package/src/workflows/workflow-child-summary.js +195 -0
  771. package/src/workflows/workflow-launch-record.d.ts +27 -0
  772. package/src/workflows/workflow-launch-record.js +48 -0
  773. package/src/workflows/workflow-preflight.d.ts +58 -0
  774. package/src/workflows/workflow-preflight.js +288 -0
  775. package/src/workflows/workflow-receipt.d.ts +34 -0
  776. package/src/workflows/workflow-receipt.js +454 -0
  777. package/src/workflows/workflow-resources.d.ts +55 -0
  778. package/src/workflows/workflow-resources.js +271 -0
  779. package/src/workflows/workflow-resume-claim.d.ts +82 -0
  780. package/src/workflows/workflow-resume-claim.js +210 -0
  781. package/src/workflows/workflow-resume.d.ts +56 -0
  782. package/src/workflows/workflow-resume.js +106 -0
  783. package/src/workflows/workflow-reuse.d.ts +61 -0
  784. package/src/workflows/workflow-reuse.js +186 -0
  785. package/src/workflows/workflow-revival.d.ts +33 -0
  786. package/src/workflows/workflow-revival.js +111 -0
  787. package/src/workflows/workflow-settlement.d.ts +84 -0
  788. package/src/workflows/workflow-settlement.js +203 -0
  789. package/src/workflows/workflow-stop-cause.d.ts +6 -0
  790. package/src/workflows/workflow-stop-cause.js +8 -0
  791. package/workflow-script-worker.cjs +1342 -0
  792. package/index.ts +0 -18
  793. package/node_modules/@xzzpig/pi-components/src/transcript.ts +0 -1878
  794. package/skills/pi-subagents/references/constraints-and-recipes.md +0 -74
  795. package/skills/pi-subagents/references/execution-controls.md +0 -561
  796. package/skills/pi-subagents/references/management-authoring-rpc.md +0 -165
  797. package/skills/pi-subagents/references/multi-lane-orchestration.md +0 -61
  798. package/skills/pi-subagents/references/review-and-validation.md +0 -73
  799. package/src/agents/advertised-agent-prompt.ts +0 -82
  800. package/src/agents/agent-eject.ts +0 -339
  801. package/src/agents/agent-management.ts +0 -1442
  802. package/src/agents/agent-memory.ts +0 -341
  803. package/src/agents/agent-refinements.ts +0 -624
  804. package/src/agents/agent-scope.ts +0 -10
  805. package/src/agents/agent-selection.ts +0 -25
  806. package/src/agents/agent-serializer.ts +0 -195
  807. package/src/agents/agents.ts +0 -3169
  808. package/src/agents/builtin-names.ts +0 -16
  809. package/src/agents/chain-serializer.ts +0 -285
  810. package/src/agents/frontmatter.ts +0 -153
  811. package/src/agents/global-npm-root.ts +0 -58
  812. package/src/agents/identity.ts +0 -30
  813. package/src/agents/proactive-skills.ts +0 -197
  814. package/src/agents/runtime-agent-events.ts +0 -70
  815. package/src/agents/runtime-agent-registry.ts +0 -457
  816. package/src/agents/runtime-discovery.ts +0 -39
  817. package/src/agents/skills.ts +0 -787
  818. package/src/api/agent-management.ts +0 -9
  819. package/src/api/agents.ts +0 -19
  820. package/src/api/background-work.ts +0 -206
  821. package/src/api/capability-ceiling.ts +0 -16
  822. package/src/api/child-tool-plan.ts +0 -5
  823. package/src/api/control-channel.ts +0 -4
  824. package/src/api/delegation.ts +0 -131
  825. package/src/api/external-job-provider.ts +0 -195
  826. package/src/api/external-runs.ts +0 -282
  827. package/src/api/inspectors.ts +0 -27
  828. package/src/api/intercom-bridge.ts +0 -3
  829. package/src/api/preflight.ts +0 -641
  830. package/src/api/project-panes.ts +0 -32
  831. package/src/api/required-child-extensions.ts +0 -6
  832. package/src/api/shared-types.ts +0 -29
  833. package/src/api/workflow-resources.ts +0 -6
  834. package/src/extension/config.ts +0 -262
  835. package/src/extension/context-injection.ts +0 -123
  836. package/src/extension/control-notices.ts +0 -53
  837. package/src/extension/declaration-pinning.ts +0 -164
  838. package/src/extension/doctor.ts +0 -284
  839. package/src/extension/fanout-child.ts +0 -282
  840. package/src/extension/herdr-pi-bridge.ts +0 -166
  841. package/src/extension/index.ts +0 -1185
  842. package/src/extension/public-execution.ts +0 -262
  843. package/src/extension/reply-workflow-script.ts +0 -67
  844. package/src/extension/rpc.ts +0 -881
  845. package/src/extension/schemas.ts +0 -337
  846. package/src/extension/steering-notices.ts +0 -35
  847. package/src/extension/subagent-guide.ts +0 -127
  848. package/src/extension/subagent-options.ts +0 -47
  849. package/src/extension/tool-activation.ts +0 -147
  850. package/src/extension/tool-description.ts +0 -193
  851. package/src/extension/tool-result.ts +0 -19
  852. package/src/extension/upgrade-notice.ts +0 -40
  853. package/src/inspectors/actions.ts +0 -174
  854. package/src/inspectors/ghostty/actions.ts +0 -74
  855. package/src/inspectors/ghostty/plugin.ts +0 -29
  856. package/src/inspectors/herdr/actions.ts +0 -155
  857. package/src/inspectors/herdr/client.ts +0 -130
  858. package/src/inspectors/herdr/focus.ts +0 -55
  859. package/src/inspectors/herdr/plugin.ts +0 -20
  860. package/src/inspectors/herdr/project-panes.ts +0 -733
  861. package/src/inspectors/inspector-runner.ts +0 -153
  862. package/src/inspectors/plugins.ts +0 -76
  863. package/src/inspectors/session-roots-codec.ts +0 -31
  864. package/src/inspectors/shell-command.ts +0 -16
  865. package/src/inspectors/tmux/actions.ts +0 -204
  866. package/src/inspectors/tmux/client.ts +0 -85
  867. package/src/inspectors/tmux/plugin.ts +0 -21
  868. package/src/inspectors/types.ts +0 -51
  869. package/src/integrations/herdr-status.ts +0 -385
  870. package/src/integrations/pi-web-session-liveness.ts +0 -73
  871. package/src/integrations/program-status.ts +0 -215
  872. package/src/intercom/intercom-bridge.ts +0 -235
  873. package/src/intercom/native-supervisor-channel.ts +0 -1000
  874. package/src/intercom/result-intercom.ts +0 -433
  875. package/src/intercom/supervisor-ui.ts +0 -72
  876. package/src/missions/actions.ts +0 -433
  877. package/src/missions/goal-driver.ts +0 -177
  878. package/src/missions/lifecycle.ts +0 -367
  879. package/src/missions/store.ts +0 -613
  880. package/src/missions/types.ts +0 -190
  881. package/src/missions/workflow-state.ts +0 -281
  882. package/src/policy/authority.ts +0 -50
  883. package/src/profiles/profiles.ts +0 -674
  884. package/src/runs/background/active-async-capacity.ts +0 -548
  885. package/src/runs/background/active-run-index.ts +0 -155
  886. package/src/runs/background/async-execution.ts +0 -2479
  887. package/src/runs/background/async-job-tracker.ts +0 -869
  888. package/src/runs/background/async-resume.ts +0 -686
  889. package/src/runs/background/async-retention.ts +0 -953
  890. package/src/runs/background/async-status-snapshot.ts +0 -46
  891. package/src/runs/background/async-status.ts +0 -787
  892. package/src/runs/background/auto-drain.ts +0 -92
  893. package/src/runs/background/await-async-run.ts +0 -83
  894. package/src/runs/background/binary-bootstrap.ts +0 -67
  895. package/src/runs/background/calendar-schedule.ts +0 -90
  896. package/src/runs/background/chain-append.ts +0 -321
  897. package/src/runs/background/chain-root-attachment.ts +0 -263
  898. package/src/runs/background/completion-batcher.ts +0 -168
  899. package/src/runs/background/completion-dedupe.ts +0 -58
  900. package/src/runs/background/completion-replay.ts +0 -287
  901. package/src/runs/background/control-channel.ts +0 -659
  902. package/src/runs/background/fleet-view.ts +0 -692
  903. package/src/runs/background/index-segment.ts +0 -59
  904. package/src/runs/background/inspect-rpc.ts +0 -443
  905. package/src/runs/background/notify.ts +0 -1083
  906. package/src/runs/background/owned-process-tree.ts +0 -131
  907. package/src/runs/background/parallel-groups.ts +0 -45
  908. package/src/runs/background/pid-namespace.ts +0 -18
  909. package/src/runs/background/process-terminal-candidate.ts +0 -98
  910. package/src/runs/background/process-terminal.ts +0 -231
  911. package/src/runs/background/result-delivery-ownership.ts +0 -45
  912. package/src/runs/background/result-files.ts +0 -634
  913. package/src/runs/background/result-watcher.ts +0 -842
  914. package/src/runs/background/resume-guidance.ts +0 -56
  915. package/src/runs/background/retained-children.ts +0 -136
  916. package/src/runs/background/retained-nested-route-tracker.ts +0 -96
  917. package/src/runs/background/run-child-session.ts +0 -725
  918. package/src/runs/background/run-id-query.ts +0 -7
  919. package/src/runs/background/run-id-resolver.ts +0 -183
  920. package/src/runs/background/run-status.ts +0 -803
  921. package/src/runs/background/runner-aliases.ts +0 -183
  922. package/src/runs/background/runner-child-launch.ts +0 -96
  923. package/src/runs/background/runner-child-sessions.ts +0 -32
  924. package/src/runs/background/runner-http-dispatcher.ts +0 -122
  925. package/src/runs/background/runner-startup-failure.ts +0 -56
  926. package/src/runs/background/scheduled-runs.ts +0 -1222
  927. package/src/runs/background/stale-run-reconciler.ts +0 -463
  928. package/src/runs/background/steering.ts +0 -260
  929. package/src/runs/background/subagent-runner-bootstrap.ts +0 -279
  930. package/src/runs/background/subagent-runner.ts +0 -5251
  931. package/src/runs/background/subagent-wait.ts +0 -895
  932. package/src/runs/background/terminal-run-index.ts +0 -183
  933. package/src/runs/background/top-level-async.ts +0 -14
  934. package/src/runs/background/wait-completions.ts +0 -262
  935. package/src/runs/background/wait-config.ts +0 -50
  936. package/src/runs/background/wait-subscriptions.ts +0 -354
  937. package/src/runs/background/wait-tool.ts +0 -57
  938. package/src/runs/background/workflow-terminal-proof.ts +0 -85
  939. package/src/runs/foreground/async-dismiss-action.ts +0 -86
  940. package/src/runs/foreground/async-steering-action.ts +0 -276
  941. package/src/runs/foreground/async-stop-action.ts +0 -216
  942. package/src/runs/foreground/command-action.ts +0 -41
  943. package/src/runs/foreground/execution.ts +0 -2315
  944. package/src/runs/foreground/foreground-control.ts +0 -157
  945. package/src/runs/foreground/foreground-history.ts +0 -164
  946. package/src/runs/foreground/prompt-audit.ts +0 -172
  947. package/src/runs/foreground/subagent-executor.ts +0 -8227
  948. package/src/runs/foreground/workflow-detach-reconcile.ts +0 -304
  949. package/src/runs/foreground/workflow-foreground-steering.ts +0 -169
  950. package/src/runs/shared/abort-recovery.ts +0 -119
  951. package/src/runs/shared/acceptance.ts +0 -1664
  952. package/src/runs/shared/agent-contract.ts +0 -38
  953. package/src/runs/shared/async-status-projection.ts +0 -664
  954. package/src/runs/shared/background-process-options.ts +0 -9
  955. package/src/runs/shared/capability-ceiling.ts +0 -214
  956. package/src/runs/shared/chain-outputs.ts +0 -116
  957. package/src/runs/shared/child-commands.ts +0 -229
  958. package/src/runs/shared/child-hooks.ts +0 -175
  959. package/src/runs/shared/child-identity.ts +0 -62
  960. package/src/runs/shared/child-launch-plan.ts +0 -163
  961. package/src/runs/shared/child-launch.ts +0 -389
  962. package/src/runs/shared/child-lifecycle.ts +0 -28
  963. package/src/runs/shared/child-runtime-config.ts +0 -136
  964. package/src/runs/shared/child-session.ts +0 -699
  965. package/src/runs/shared/child-tool-plan.ts +0 -599
  966. package/src/runs/shared/claude-code-adapter.ts +0 -288
  967. package/src/runs/shared/codex-exec-adapter.ts +0 -129
  968. package/src/runs/shared/context-mode.ts +0 -44
  969. package/src/runs/shared/cursor-agent-adapter.ts +0 -114
  970. package/src/runs/shared/dynamic-fanout.ts +0 -297
  971. package/src/runs/shared/effective-system-prompt.ts +0 -33
  972. package/src/runs/shared/extension-bindings.ts +0 -103
  973. package/src/runs/shared/external-cli-contract.ts +0 -177
  974. package/src/runs/shared/external-cli-preflight.ts +0 -190
  975. package/src/runs/shared/external-cli-runner.ts +0 -437
  976. package/src/runs/shared/external-job-bridge.ts +0 -514
  977. package/src/runs/shared/external-job-runner.ts +0 -389
  978. package/src/runs/shared/fast-mode-extension.ts +0 -10
  979. package/src/runs/shared/fork-command-result.ts +0 -10
  980. package/src/runs/shared/git-environment.ts +0 -29
  981. package/src/runs/shared/herdr-connection.ts +0 -134
  982. package/src/runs/shared/herdr-external-adapters.ts +0 -169
  983. package/src/runs/shared/herdr-machine.ts +0 -279
  984. package/src/runs/shared/herdr-pi-protocol.ts +0 -59
  985. package/src/runs/shared/herdr-placed-run.ts +0 -264
  986. package/src/runs/shared/host-step-status.ts +0 -231
  987. package/src/runs/shared/lane-metadata.ts +0 -126
  988. package/src/runs/shared/launch-cwd.ts +0 -16
  989. package/src/runs/shared/long-running-guard.ts +0 -221
  990. package/src/runs/shared/mcp-config-sources.ts +0 -426
  991. package/src/runs/shared/mcp-direct-tool-allowlist.ts +0 -579
  992. package/src/runs/shared/mcp-direct-tool-grant.ts +0 -210
  993. package/src/runs/shared/model-resolution-diagnostic.ts +0 -101
  994. package/src/runs/shared/model-resolution.ts +0 -503
  995. package/src/runs/shared/model-scope.ts +0 -224
  996. package/src/runs/shared/mutation-evidence.ts +0 -199
  997. package/src/runs/shared/nested-events.ts +0 -1125
  998. package/src/runs/shared/nested-path.ts +0 -38
  999. package/src/runs/shared/nested-render.ts +0 -127
  1000. package/src/runs/shared/orca-progress-tabs.ts +0 -511
  1001. package/src/runs/shared/parallel-handoff.ts +0 -789
  1002. package/src/runs/shared/parallel-utils.ts +0 -292
  1003. package/src/runs/shared/partial-output.ts +0 -48
  1004. package/src/runs/shared/permissions.ts +0 -86
  1005. package/src/runs/shared/pi-spawn.ts +0 -205
  1006. package/src/runs/shared/process-signal.ts +0 -35
  1007. package/src/runs/shared/profile-extensions.ts +0 -134
  1008. package/src/runs/shared/profile-launch-env.ts +0 -121
  1009. package/src/runs/shared/readonly-drain-observation.ts +0 -42
  1010. package/src/runs/shared/run-fanout-budget.ts +0 -267
  1011. package/src/runs/shared/run-history.ts +0 -288
  1012. package/src/runs/shared/runner-launcher.ts +0 -25
  1013. package/src/runs/shared/runtime-acknowledged-extensions.ts +0 -44
  1014. package/src/runs/shared/sandbox-profile-guard.ts +0 -119
  1015. package/src/runs/shared/sandbox-startup-diagnostics.ts +0 -54
  1016. package/src/runs/shared/session-lease.ts +0 -293
  1017. package/src/runs/shared/single-output.ts +0 -366
  1018. package/src/runs/shared/spawn-budget.ts +0 -128
  1019. package/src/runs/shared/structured-output.ts +0 -463
  1020. package/src/runs/shared/subagent-control.ts +0 -295
  1021. package/src/runs/shared/subagent-prompt-runtime.ts +0 -598
  1022. package/src/runs/shared/tool-availability.ts +0 -37
  1023. package/src/runs/shared/tool-budget.ts +0 -87
  1024. package/src/runs/shared/tool-timeout.ts +0 -93
  1025. package/src/runs/shared/usage-budget.ts +0 -65
  1026. package/src/runs/shared/usage-reconciliation.ts +0 -73
  1027. package/src/runs/shared/workflow-async-child-guidance.ts +0 -18
  1028. package/src/runs/shared/workflow-graph.ts +0 -225
  1029. package/src/runs/shared/worktree-cleanup-apply.ts +0 -160
  1030. package/src/runs/shared/worktree-cleanup-plan.ts +0 -891
  1031. package/src/runs/shared/worktree-lock.ts +0 -29
  1032. package/src/runs/shared/worktree-setup-command.ts +0 -213
  1033. package/src/runs/shared/worktree.ts +0 -1554
  1034. package/src/shared/accessible-dir.ts +0 -47
  1035. package/src/shared/agent-stream-options.ts +0 -5
  1036. package/src/shared/artifacts.ts +0 -281
  1037. package/src/shared/atomic-json.ts +0 -85
  1038. package/src/shared/capacity-resilient-json.ts +0 -102
  1039. package/src/shared/child-cache-retention.ts +0 -43
  1040. package/src/shared/child-session-name.ts +0 -48
  1041. package/src/shared/child-transcript.ts +0 -264
  1042. package/src/shared/completion-owner.ts +0 -14
  1043. package/src/shared/disabled-features.ts +0 -123
  1044. package/src/shared/display-text.ts +0 -150
  1045. package/src/shared/edit-distance.ts +0 -33
  1046. package/src/shared/extension-context.ts +0 -37
  1047. package/src/shared/file-coalescer.ts +0 -49
  1048. package/src/shared/file-lease.ts +0 -74
  1049. package/src/shared/file-system-retry.ts +0 -95
  1050. package/src/shared/fork-context.ts +0 -243
  1051. package/src/shared/fork-session-cwd.ts +0 -27
  1052. package/src/shared/formatters.ts +0 -142
  1053. package/src/shared/jsonl-writer.ts +0 -92
  1054. package/src/shared/launch-contract.ts +0 -206
  1055. package/src/shared/model-info.ts +0 -132
  1056. package/src/shared/model-response-aliases.ts +0 -13
  1057. package/src/shared/node-executable.ts +0 -21
  1058. package/src/shared/opencode-session-headers.ts +0 -30
  1059. package/src/shared/package-version.ts +0 -17
  1060. package/src/shared/parent-wake.ts +0 -79
  1061. package/src/shared/permission-profile.ts +0 -56
  1062. package/src/shared/prompt-resources.ts +0 -11
  1063. package/src/shared/pruned-fork.ts +0 -469
  1064. package/src/shared/required-child-extensions.ts +0 -115
  1065. package/src/shared/runtime-module-path.ts +0 -19
  1066. package/src/shared/sandbox-profile.ts +0 -37
  1067. package/src/shared/session-file-trust.ts +0 -19
  1068. package/src/shared/session-identity.ts +0 -10
  1069. package/src/shared/session-tokens.ts +0 -55
  1070. package/src/shared/settings-file-lease.ts +0 -36
  1071. package/src/shared/settings.ts +0 -412
  1072. package/src/shared/shortcuts.ts +0 -13
  1073. package/src/shared/status-format.ts +0 -55
  1074. package/src/shared/thinking-ceiling.ts +0 -46
  1075. package/src/shared/types.ts +0 -3105
  1076. package/src/shared/utf8.ts +0 -11
  1077. package/src/shared/utils.ts +0 -610
  1078. package/src/shared/watch-strategy.ts +0 -12
  1079. package/src/shared/workflow-child-permit.ts +0 -212
  1080. package/src/slash/delegation-adapters.ts +0 -452
  1081. package/src/slash/delegation-json.ts +0 -108
  1082. package/src/slash/delegation-request.ts +0 -176
  1083. package/src/slash/prompt-template-bridge.ts +0 -434
  1084. package/src/slash/prompt-workflows.ts +0 -298
  1085. package/src/slash/selector.ts +0 -147
  1086. package/src/slash/slash-bridge.ts +0 -192
  1087. package/src/slash/slash-commands.ts +0 -1096
  1088. package/src/slash/slash-live-state.ts +0 -310
  1089. package/src/slash/subagent-cost.ts +0 -317
  1090. package/src/slash/subagents-admin.ts +0 -489
  1091. package/src/tui/fleet-native-transcript.ts +0 -424
  1092. package/src/tui/fleet-status.ts +0 -1139
  1093. package/src/tui/fleet-transcript.ts +0 -591
  1094. package/src/tui/fleet.ts +0 -1618
  1095. package/src/tui/mouse-events.ts +0 -42
  1096. package/src/tui/render-helpers.ts +0 -111
  1097. package/src/tui/render.ts +0 -3824
  1098. package/src/tui/running-tone.ts +0 -28
  1099. package/src/tui/subagent-messages.ts +0 -305
  1100. package/src/ui-silent-marker.ts +0 -32
  1101. package/src/watchdog/change-signature.ts +0 -260
  1102. package/src/watchdog/child-status.ts +0 -225
  1103. package/src/watchdog/diff-tool.ts +0 -112
  1104. package/src/watchdog/emission-guard.ts +0 -125
  1105. package/src/watchdog/guidance.ts +0 -20
  1106. package/src/watchdog/lsp-diagnostics.ts +0 -538
  1107. package/src/watchdog/model-selection.ts +0 -187
  1108. package/src/watchdog/permission-arbiter.ts +0 -154
  1109. package/src/watchdog/register-child.ts +0 -136
  1110. package/src/watchdog/register-main.ts +0 -425
  1111. package/src/watchdog/render.ts +0 -31
  1112. package/src/watchdog/review.ts +0 -362
  1113. package/src/watchdog/rules.ts +0 -70
  1114. package/src/watchdog/runtime.ts +0 -927
  1115. package/src/watchdog/scope.ts +0 -51
  1116. package/src/watchdog/settings.ts +0 -520
  1117. package/src/watchdog/tool-actions.ts +0 -156
  1118. package/src/watchdog/turn-delta.ts +0 -190
  1119. package/src/watchdog/types.ts +0 -186
  1120. package/src/watchdog/warning-format.ts +0 -72
  1121. package/src/workflows/chat-progress.ts +0 -152
  1122. package/src/workflows/host-command.ts +0 -235
  1123. package/src/workflows/scripted-workflow.ts +0 -2733
  1124. package/src/workflows/structured-workflow-scripts.ts +0 -177
  1125. package/src/workflows/workflow-checklist.ts +0 -442
  1126. package/src/workflows/workflow-child-summary.ts +0 -172
  1127. package/src/workflows/workflow-preflight.ts +0 -297
  1128. package/src/workflows/workflow-receipt.ts +0 -390
  1129. package/src/workflows/workflow-resources.ts +0 -275
  1130. package/src/workflows/workflow-reuse.ts +0 -120
  1131. package/src/workflows/workflow-revival.ts +0 -123
  1132. package/src/workflows/workflow-settlement.ts +0 -252
package/src/tui/fleet.ts DELETED
@@ -1,1618 +0,0 @@
1
- import * as fs from "node:fs";
2
- import * as path from "node:path";
3
- import type { AgentToolResult } from "@earendil-works/pi-agent-core";
4
- import {
5
- getMarkdownTheme,
6
- type ExtensionAPI,
7
- type ExtensionContext,
8
- } from "@earendil-works/pi-coding-agent";
9
- import { matchesKey, truncateToWidth, visibleWidth, wrapTextWithAnsi, type Component, type MarkdownTheme } from "@earendil-works/pi-tui";
10
- import { snapshotExternalRuns, type ExternalRun } from "../api/external-runs.ts";
11
- import { emitUiSpanSilent, type UiSpanSilentEvents } from "../ui-silent-marker.ts";
12
- import { getArtifactPaths, getArtifactsDir } from "../shared/artifacts.ts";
13
- import { formatDuration, formatModelThinking, formatTokens, formatTokenUsage, shortenPath } from "../shared/formatters.ts";
14
- import { DIRS, type AsyncJobState, type AsyncJobStep, type Details, type FleetKeybindingAction, type FleetKeybindingsConfig, type ForegroundChildControl, type ForegroundResumeChild, type ForegroundResumeRun, type ForegroundRunControl, type SubagentState } from "../shared/types.ts";
15
- import { decodeUtf8Tail } from "../shared/utf8.ts";
16
- import { readStatus } from "../shared/utils.ts";
17
- import { formatAsyncRunTranscript } from "../runs/background/fleet-view.ts";
18
- import { parseMouseWheelEvent } from "./mouse-events.ts";
19
- import { listAsyncRuns, type AsyncRunSummary } from "../runs/background/async-status.ts";
20
- import { steerAsyncRun } from "../runs/foreground/async-steering-action.ts";
21
- import type { SteerDeliveryMode } from "../runs/background/control-channel.ts";
22
- import { stopAsyncRun } from "../runs/foreground/async-stop-action.ts";
23
- import { resolveWorkflowForegroundSteeringTarget, steerWorkflowForegroundTarget } from "../runs/foreground/workflow-foreground-steering.ts";
24
- import { contextModeBadge, contextModeLabel } from "../runs/shared/context-mode.ts";
25
- import { FLEET_STATUS_WIDGET_KEY } from "./fleet-status.ts";
26
- import { readFleetTranscript, renderFleetTranscript, type FleetTranscript } from "./fleet-transcript.ts";
27
- import { buildNativeFleetTranscript, loadNativeTranscriptSupport, type NativeTranscriptModule } from "./fleet-native-transcript.ts";
28
- import { runningTone } from "./running-tone.ts";
29
- import { childThinkingLevel, type ThinkingLevel } from "../shared/model-info.ts";
30
- import { handleInspectorAction } from "../inspectors/actions.ts";
31
- import type { InspectorPlugin } from "../inspectors/types.ts";
32
- import { getLivePromptAudit, type LivePromptAudit, type PromptAuditView } from "../runs/foreground/prompt-audit.ts";
33
-
34
- const REFRESH_MS = 750;
35
- const MIN_REFRESH_MS = 250;
36
- const WHEEL_SCROLL_LINES = 3;
37
- const MAX_RECENT_ASYNC_RUNS = 20;
38
- const MAX_FLEET_HISTORY_CANDIDATES = 100;
39
- const TRANSCRIPT_LINES = 200;
40
- const OUTPUT_TAIL_BYTES = 64 * 1024;
41
- const PROMPT_AUDIT_SUMMARY_WIDTH = 160;
42
-
43
- export const DEFAULT_FLEET_KEYBINDINGS: Record<FleetKeybindingAction, string[]> = {
44
- close: ["escape", "ctrl+c", "q"],
45
- scrollUp: ["K"],
46
- scrollDown: ["J"],
47
- selectUp: ["up", "k"],
48
- selectDown: ["down", "j"],
49
- selectFirst: ["home"],
50
- selectLast: ["end"],
51
- pageUp: ["pageUp"],
52
- pageDown: ["pageDown"],
53
- refresh: ["r", "R"],
54
- steer: ["s"],
55
- inspect: ["return", "H"],
56
- stop: ["D"],
57
- toggleTools: ["x", "X", "ctrl+o"],
58
- toggleThinking: ["t", "T"],
59
- toggleRenderer: ["v", "V"],
60
- };
61
-
62
- type ResolvedFleetKeybindings = Record<FleetKeybindingAction, string[]>;
63
-
64
- export function resolveFleetKeybindings(config: FleetKeybindingsConfig | undefined): ResolvedFleetKeybindings {
65
- return Object.fromEntries(
66
- Object.entries(DEFAULT_FLEET_KEYBINDINGS).map(([action, defaults]) => [action, config?.[action as FleetKeybindingAction] ?? defaults]),
67
- ) as ResolvedFleetKeybindings;
68
- }
69
-
70
- function matchesFleetBinding(data: string, binding: string): boolean {
71
- const key = /^[A-Z]$/.test(binding) ? `shift+${binding.toLowerCase()}` : binding;
72
- return matchesKey(data, key as Parameters<typeof matchesKey>[1]);
73
- }
74
-
75
- function matchesFleetAction(data: string, bindings: ResolvedFleetKeybindings, action: FleetKeybindingAction): boolean {
76
- return bindings[action].some((binding) => matchesFleetBinding(data, binding));
77
- }
78
-
79
- function bindingLabel(bindings: ResolvedFleetKeybindings, action: FleetKeybindingAction): string {
80
- return bindings[action]
81
- .map((binding) => binding === "up" ? "↑" : binding === "down" ? "↓" : binding === "escape" ? "Esc" : binding === "return" ? "Enter" : binding)
82
- .join("/");
83
- }
84
-
85
- type Theme = ExtensionContext["ui"]["theme"];
86
- type FleetTui = {
87
- terminal?: { rows: number };
88
- requestRender(): void;
89
- };
90
- type AsyncStep = AsyncRunSummary["steps"][number];
91
-
92
- export type FleetItem = (
93
- | { key: string; kind: "foreground-active"; runId: string; index?: number; agent: string; state: "running"; updatedAt: number; control: ForegroundRunControl; activeChild?: ForegroundChildControl }
94
- | { key: string; kind: "foreground-recent"; runId: string; index: number; agent: string; state: ForegroundResumeChild["status"]; updatedAt: number; run: ForegroundResumeRun; child: ForegroundResumeChild }
95
- | { key: string; kind: "async"; runId: string; index?: number; agent: string; state: string; updatedAt: number; run: AsyncRunSummary; step?: AsyncStep }
96
- | { key: string; kind: "external"; runId: string; agent: string; state: ExternalRun["state"]; updatedAt: number; run: ExternalRun }
97
- ) & { description?: string };
98
-
99
- export interface FleetSnapshot {
100
- items: FleetItem[];
101
- error?: string;
102
- }
103
-
104
- export interface FleetActionResult {
105
- text: string;
106
- isError?: boolean;
107
- }
108
-
109
- export interface FleetActionHandlers {
110
- steer(input: { runId: string; asyncDir: string; index?: number; message: string; mode: SteerDeliveryMode }): Promise<FleetActionResult>;
111
- stop(input: { runId: string; asyncDir: string; index?: number }): Promise<FleetActionResult> | FleetActionResult;
112
- inspect?(input: { runId: string; asyncDir: string; index?: number }): Promise<FleetActionResult>;
113
- redoPrompt?(input: { runId: string; index: number; guidance: string; control?: ForegroundRunControl }): Promise<FleetActionResult>;
114
- }
115
-
116
- export interface FleetViewOptions {
117
- asyncDirRoot?: string;
118
- resultsDir?: string;
119
- refreshMs?: number;
120
- initialKey?: string;
121
- markdownTheme?: MarkdownTheme;
122
- fleetKeybindings?: FleetKeybindingsConfig;
123
- actions?: FleetActionHandlers;
124
- copyText?: (text: string) => Promise<void> | void;
125
- inspectorPlugins?: () => readonly InspectorPlugin[];
126
- inspectorEnv?: NodeJS.ProcessEnv;
127
- /** Event bus used to claim the fleet dialog as a silent span. */
128
- events?: UiSpanSilentEvents;
129
- }
130
-
131
- function belongsToCurrentSession(sessionId: string | undefined, currentSessionId: string | null): boolean {
132
- return !currentSessionId || sessionId === currentSessionId;
133
- }
134
-
135
- function trackedJobSummary(job: AsyncJobState): AsyncRunSummary {
136
- const startedAt = job.startedAt ?? job.updatedAt ?? Date.now();
137
- return {
138
- id: job.asyncId,
139
- asyncDir: job.asyncDir,
140
- ...(job.sessionId ? { sessionId: job.sessionId } : {}),
141
- state: job.status,
142
- activityState: job.activityState,
143
- lastActivityAt: job.lastActivityAt,
144
- currentTool: job.currentTool,
145
- currentToolStartedAt: job.currentToolStartedAt,
146
- currentPath: job.currentPath,
147
- turnCount: job.turnCount,
148
- toolCount: job.toolCount,
149
- steering: job.steering,
150
- mode: job.mode ?? "single",
151
- ...(job.context ? { context: job.context } : {}),
152
- ...(job.cwd ? { cwd: job.cwd } : {}),
153
- startedAt,
154
- ...(job.updatedAt !== undefined ? { lastUpdate: job.updatedAt } : {}),
155
- ...(job.timeoutMs !== undefined ? { timeoutMs: job.timeoutMs } : {}),
156
- ...(job.deadlineAt !== undefined ? { deadlineAt: job.deadlineAt } : {}),
157
- ...(job.timedOut !== undefined ? { timedOut: job.timedOut } : {}),
158
- ...(job.stopped !== undefined ? { stopped: job.stopped } : {}),
159
- ...(job.turnBudget ? { turnBudget: job.turnBudget } : {}),
160
- ...(job.turnBudgetExceeded !== undefined ? { turnBudgetExceeded: job.turnBudgetExceeded } : {}),
161
- ...(job.wrapUpRequested !== undefined ? { wrapUpRequested: job.wrapUpRequested } : {}),
162
- ...(job.currentStep !== undefined ? { currentStep: job.currentStep } : {}),
163
- ...(job.chainStepCount !== undefined ? { chainStepCount: job.chainStepCount } : {}),
164
- ...(job.parallelGroups?.length ? { parallelGroups: job.parallelGroups } : {}),
165
- ...(job.preflight ? { preflight: job.preflight } : {}),
166
- steps: (job.steps ?? job.agents?.map((agent, index) => ({ agent, index, status: job.status === "queued" ? "pending" as const : job.status })) ?? []).map((step, index) => ({
167
- ...step,
168
- index: step.index ?? index,
169
- })),
170
- ...(job.sessionDir ? { sessionDir: job.sessionDir } : {}),
171
- ...(job.outputFile ? { outputFile: job.outputFile } : {}),
172
- ...(job.totalTokens ? { totalTokens: job.totalTokens } : {}),
173
- ...(job.sessionFile ? { sessionFile: job.sessionFile } : {}),
174
- ...(job.nestedChildren?.length ? { nestedChildren: job.nestedChildren } : {}),
175
- };
176
- }
177
-
178
- function asyncItems(run: AsyncRunSummary, description?: string): FleetItem[] {
179
- const updatedAt = run.lastUpdate ?? run.endedAt ?? run.startedAt;
180
- if (run.steps.length === 0 || run.mode === "workflow") {
181
- return [{ key: `async:${run.id}`, kind: "async", runId: run.id, agent: run.mode, state: run.state, updatedAt, run, ...(description ? { description } : {}) }];
182
- }
183
- return run.steps.map((step) => ({
184
- key: `async:${run.id}:${step.index}`,
185
- kind: "async" as const,
186
- runId: run.id,
187
- index: step.index,
188
- agent: step.label ? `${step.label} (${step.agent})` : step.agent,
189
- state: step.status,
190
- updatedAt: step.lastActivityAt ?? updatedAt,
191
- run,
192
- step,
193
- ...(description ? { description } : {}),
194
- }));
195
- }
196
-
197
- function orderFleetAsyncRuns(runs: AsyncRunSummary[], terminalLimit: number, trackedJobs: Map<string, AsyncJobState>): AsyncRunSummary[] {
198
- const updatedAt = (run: AsyncRunSummary) => run.lastUpdate ?? run.endedAt ?? run.startedAt;
199
- const byNewest = (left: AsyncRunSummary, right: AsyncRunSummary) => updatedAt(right) - updatedAt(left);
200
- // Missing tracked starts must not inherit the summary's heartbeat-based display fallback.
201
- const startedAt = (run: AsyncRunSummary) => {
202
- const job = trackedJobs.get(run.id);
203
- return job ? job.startedAt ?? 0 : run.startedAt;
204
- };
205
- const byStartedAt = (left: AsyncRunSummary, right: AsyncRunSummary) => startedAt(left) - startedAt(right) || left.id.localeCompare(right.id);
206
- const active = runs.filter((run) => run.state === "queued" || run.state === "running").sort(byStartedAt);
207
- const terminal = runs.filter((run) => run.state !== "queued" && run.state !== "running").sort(byNewest);
208
- return [...active, ...terminal.slice(0, terminalLimit)];
209
- }
210
-
211
- export function collectFleetSnapshot(
212
- state: SubagentState,
213
- options: { asyncDirRoot?: string; resultsDir?: string; limit?: number } = {},
214
- ): FleetSnapshot {
215
- const items: FleetItem[] = [];
216
- const activeForegroundIds = new Set<string>();
217
- const trackedJobs = state.fleetJobs ?? state.asyncJobs;
218
- const workflowParentIds = new Set([...trackedJobs.values()]
219
- .filter((job) => job.mode === "workflow" && belongsToCurrentSession(job.sessionId, state.currentSessionId))
220
- .map((job) => job.asyncId));
221
- const workflowForegroundChildCounts = new Map<string, number>();
222
- const liveWorkflowForegroundControls = new Set<ForegroundRunControl>();
223
- for (const control of state.foregroundControls.values()) {
224
- const activeChildCount = control.activeChildren?.size ?? 0;
225
- if (!control.parentWorkflowRunId
226
- || !workflowParentIds.has(control.parentWorkflowRunId)
227
- || !belongsToCurrentSession(control.sessionId, state.currentSessionId)
228
- || activeChildCount === 0) continue;
229
- liveWorkflowForegroundControls.add(control);
230
- workflowForegroundChildCounts.set(control.parentWorkflowRunId, (workflowForegroundChildCounts.get(control.parentWorkflowRunId) ?? 0) + activeChildCount);
231
- }
232
- for (const control of [...state.foregroundControls.values()].sort((left, right) => left.startedAt - right.startedAt || left.runId.localeCompare(right.runId))) {
233
- activeForegroundIds.add(control.runId);
234
- if (control.parentWorkflowRunId && workflowParentIds.has(control.parentWorkflowRunId)
235
- && ((workflowForegroundChildCounts.get(control.parentWorkflowRunId) ?? 0) <= 1 || !liveWorkflowForegroundControls.has(control))) continue;
236
- if (control.activeChildren) {
237
- for (const child of [...control.activeChildren.values()].sort((left, right) => left.index - right.index)) {
238
- items.push({
239
- key: `foreground-active:${control.runId}:${child.index}`,
240
- kind: "foreground-active",
241
- runId: control.runId,
242
- index: child.index,
243
- agent: child.agent,
244
- state: "running",
245
- updatedAt: child.updatedAt,
246
- control,
247
- activeChild: child,
248
- ...(child.description ? { description: child.description } : {}),
249
- });
250
- }
251
- continue;
252
- }
253
- items.push({
254
- key: `foreground-active:${control.runId}:${control.currentIndex ?? 0}`,
255
- kind: "foreground-active",
256
- runId: control.runId,
257
- ...(control.currentIndex !== undefined ? { index: control.currentIndex } : {}),
258
- agent: control.currentAgent ?? control.mode,
259
- state: "running",
260
- updatedAt: control.updatedAt,
261
- control,
262
- ...(control.description ? { description: control.description } : {}),
263
- });
264
- }
265
-
266
- let error: string | undefined;
267
- try {
268
- let runs: AsyncRunSummary[];
269
- const descriptions = new Map<string, string>();
270
- const tracked = [...trackedJobs.values()]
271
- .filter((job) => belongsToCurrentSession(job.sessionId, state.currentSessionId));
272
- const byUpdate = (left: AsyncJobState, right: AsyncJobState) => (right.updatedAt ?? right.startedAt ?? 0) - (left.updatedAt ?? left.startedAt ?? 0);
273
- const active = tracked.filter((job) => job.status === "queued" || job.status === "running");
274
- const recent = tracked.filter((job) => job.status !== "queued" && job.status !== "running").sort(byUpdate).slice(0, options.limit ?? MAX_RECENT_ASYNC_RUNS);
275
- const trackedRuns: AsyncRunSummary[] = [];
276
- for (const job of [...active, ...recent]) {
277
- try {
278
- trackedRuns.push(trackedJobSummary(job));
279
- if (job.description) descriptions.set(job.asyncId, job.description);
280
- } catch (cause) {
281
- error = `Failed to inspect async run '${job.asyncId}': ${cause instanceof Error ? cause.message : String(cause)}`;
282
- }
283
- }
284
- if (options.asyncDirRoot !== undefined) {
285
- const trackedIds = new Set(trackedRuns.map((run) => run.id));
286
- const history = listAsyncRuns(options.asyncDirRoot, {
287
- ...(state.currentSessionId ? { sessionId: state.currentSessionId } : {}),
288
- entryLimit: MAX_FLEET_HISTORY_CANDIDATES,
289
- resultsDir: options.resultsDir ?? DIRS.results,
290
- reconcile: false,
291
- }).filter((run) => !trackedIds.has(run.id));
292
- runs = [...trackedRuns, ...history];
293
- } else {
294
- runs = trackedRuns;
295
- }
296
- for (const run of orderFleetAsyncRuns(runs, options.limit ?? MAX_RECENT_ASYNC_RUNS, trackedJobs)) {
297
- items.push(...asyncItems(run, descriptions.get(run.id)));
298
- }
299
- } catch (cause) {
300
- error = cause instanceof Error ? cause.message : String(cause);
301
- }
302
-
303
- if (state.currentSessionId) {
304
- try {
305
- for (const run of snapshotExternalRuns(state.currentSessionId, { ignoreMalformed: true, onMalformedRecord: (message) => console.warn(`[pi-subagents] Removed ${message}`) })) {
306
- items.push({
307
- key: `external:${run.id}`,
308
- kind: "external",
309
- runId: run.id,
310
- agent: run.label,
311
- state: run.state,
312
- updatedAt: run.updatedAt ?? run.endedAt ?? run.startedAt,
313
- run,
314
- ...(run.currentAction ? { description: run.currentAction } : {}),
315
- });
316
- }
317
- } catch (cause) {
318
- const message = `Failed to inspect external jobs: ${cause instanceof Error ? cause.message : String(cause)}`;
319
- error = error ? `${error}; ${message}` : message;
320
- }
321
- }
322
-
323
- const recentForeground = [...(state.foregroundRuns?.values() ?? [])]
324
- .filter((run) => belongsToCurrentSession(run.sessionId, state.currentSessionId) && !activeForegroundIds.has(run.runId))
325
- .sort((left, right) => right.updatedAt - left.updatedAt);
326
- for (const run of recentForeground) {
327
- for (const child of run.children) {
328
- items.push({
329
- key: `foreground-recent:${run.runId}:${child.index}`,
330
- kind: "foreground-recent",
331
- runId: run.runId,
332
- index: child.index,
333
- agent: child.agent,
334
- state: child.status,
335
- updatedAt: child.updatedAt ?? run.updatedAt,
336
- run,
337
- child,
338
- });
339
- }
340
- }
341
- return { items, ...(error ? { error } : {}) };
342
- }
343
-
344
- function visibleWorkflowParentKeyForForegroundKey(state: SubagentState, key: string, items: FleetItem[]): string | undefined {
345
- for (const control of state.foregroundControls.values()) {
346
- if (!control.parentWorkflowRunId) continue;
347
- let matches = false;
348
- if (control.activeChildren) {
349
- for (const child of control.activeChildren.values()) {
350
- if (`foreground-active:${control.runId}:${child.index}` === key) {
351
- matches = true;
352
- break;
353
- }
354
- }
355
- } else {
356
- matches = `foreground-active:${control.runId}:${control.currentIndex ?? 0}` === key;
357
- }
358
- if (!matches) continue;
359
- const parentKey = `async:${control.parentWorkflowRunId}`;
360
- return items.some((item) => item.key === parentKey) ? parentKey : undefined;
361
- }
362
- return undefined;
363
- }
364
-
365
- /** The recorded level of the one child a running Fleet row stands for; a whole run or an external run has none. */
366
- function fleetItemThinkingLevel(item: FleetItem): ThinkingLevel | undefined {
367
- switch (item.kind) {
368
- case "foreground-active": return childThinkingLevel(item.activeChild ?? item.control);
369
- case "foreground-recent": return childThinkingLevel(item.child);
370
- case "async": return childThinkingLevel(item.step);
371
- case "external": return undefined;
372
- }
373
- }
374
-
375
- function statusGlyph(item: FleetItem, theme: Theme): string {
376
- if (item.state === "running") return runningTone(theme, fleetItemThinkingLevel(item))("●");
377
- if (item.state === "queued" || item.state === "pending") return theme.fg("muted", "◦");
378
- if (item.state === "complete" || item.state === "completed") return theme.fg("success", "✓");
379
- if (item.state === "paused" || item.state === "stopped" || item.state === "detached") return theme.fg("warning", "■");
380
- return theme.fg("error", "✗");
381
- }
382
-
383
- function foregroundPromptAuditCount(item: Extract<FleetItem, { kind: "foreground-active" }>, state: SubagentState): number {
384
- if (!state.currentSessionId || item.control.sessionId !== state.currentSessionId) return 0;
385
- if (!item.control.activeChildren) return getLivePromptAudit(item.control, item.index ?? 0) ? 1 : 0;
386
- return [...item.control.activeChildren.keys()].filter((index) => getLivePromptAudit(item.control, index)).length;
387
- }
388
-
389
- function promptAuditString(value: unknown): string | undefined {
390
- return typeof value === "string" ? value : undefined;
391
- }
392
-
393
- function authoredPromptSummary(text: unknown): string | undefined {
394
- if (typeof text !== "string") return undefined;
395
- const summary = text.replace(/\s+/g, " ").trim();
396
- return summary ? truncateToWidth(summary, PROMPT_AUDIT_SUMMARY_WIDTH, "…") : undefined;
397
- }
398
-
399
- function foregroundAuthoredPromptSummary(item: Extract<FleetItem, { kind: "foreground-active" }>, state: SubagentState): string | undefined {
400
- if (!state.currentSessionId || item.control.sessionId !== state.currentSessionId) return undefined;
401
- const prompt = getLivePromptAudit(item.control, item.index ?? 0);
402
- return prompt ? authoredPromptSummary(prompt.authoredTask) : undefined;
403
- }
404
-
405
- function promptAuditText(prompt: LivePromptAudit, view: PromptAuditView): string | undefined {
406
- switch (view) {
407
- case "authored": return promptAuditString(prompt.authoredTask);
408
- case "runtime": return promptAuditString(prompt.runtimeAdditions);
409
- case "effective": return promptAuditString(prompt.finalEffectivePrompt);
410
- }
411
- }
412
-
413
- function promptAuditViewLabel(view: PromptAuditView): string {
414
- switch (view) {
415
- case "authored": return "[1] Authored task";
416
- case "runtime": return "[2] Runtime additions";
417
- case "effective": return "[3] Final effective prompt";
418
- }
419
- }
420
-
421
- function foregroundActiveDetail(item: Extract<FleetItem, { kind: "foreground-active" }>, state: SubagentState): string[] {
422
- const { control } = item;
423
- const live = item.activeChild ?? control;
424
- const modelThinking = formatModelThinking(live.model, live.thinking);
425
- const promptAuditCount = foregroundPromptAuditCount(item, state);
426
- const promptSummary = foregroundAuthoredPromptSummary(item, state);
427
- const lines = [
428
- `Run: ${item.runId}`,
429
- "Source: foreground",
430
- `State: running`,
431
- `Mode: ${control.mode}`,
432
- control.parentWorkflowRunId ? `Workflow child of: ${control.parentWorkflowRunId}${control.workflowKey ? ` (${control.workflowKey})` : ""}` : undefined,
433
- control.sourceRunId ? `Redo source: ${control.sourceRunId}` : undefined,
434
- control.supersededByRunId ? `Superseded by: ${control.supersededByRunId}` : undefined,
435
- item.index !== undefined ? `Child: ${item.index} (${item.agent})` : `Agent: ${item.agent}`,
436
- modelThinking ? `Model: ${modelThinking}` : undefined,
437
- promptSummary ? `Task: ${promptSummary}` : undefined,
438
- `Started: ${new Date(live.startedAt).toISOString()}`,
439
- live.currentTool ? `Current tool: ${live.currentTool}${live.currentPath ? ` · ${shortenPath(live.currentPath)}` : ""}` : undefined,
440
- live.turnCount !== undefined ? `Turns: ${live.turnCount}` : undefined,
441
- live.toolCount !== undefined ? `Tools: ${live.toolCount}` : undefined,
442
- live.tokens !== undefined
443
- ? `Tokens: ${formatTokenUsage({ input: live.inputTokens ?? 0, output: live.outputTokens ?? 0, total: live.tokens, ...(live.window !== undefined ? { window: live.window } : {}), ...(live.windowPeak !== undefined ? { windowPeak: live.windowPeak } : {}) }, "tokens")}`
444
- : undefined,
445
- promptAuditCount > 0 ? `Prompt audit: ${promptAuditCount} live · 3 views · p opens` : undefined,
446
- "",
447
- "Transcript",
448
- "Live foreground output remains in the expanded subagent tool result. Persisted output and session paths appear here after the child settles.",
449
- ];
450
- return lines.filter((line): line is string => line !== undefined);
451
- }
452
-
453
- function pathWithin(base: string, candidate: string): boolean {
454
- const resolvedBase = path.resolve(base);
455
- const resolvedCandidate = path.resolve(candidate);
456
- return resolvedCandidate === resolvedBase || resolvedCandidate.startsWith(`${resolvedBase}${path.sep}`);
457
- }
458
-
459
- function trustedFileTail(filePath: string, trustedRoots: string[]): { text?: string; warning?: string; unavailable?: string } {
460
- const resolvedPath = path.resolve(filePath);
461
- if (trustedRoots.length === 0 || !trustedRoots.some((root) => pathWithin(root, resolvedPath))) return { warning: `output artifact is outside trusted roots: ${filePath}` };
462
- let stat: fs.Stats;
463
- try {
464
- stat = fs.lstatSync(resolvedPath);
465
- } catch (error) {
466
- if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return { unavailable: `output artifact unavailable: ${filePath}` };
467
- return { warning: `output artifact could not be inspected: ${error instanceof Error ? error.message : String(error)}` };
468
- }
469
- if (stat.isSymbolicLink()) return { warning: `output artifact refused a symlink: ${filePath}` };
470
- if (!stat.isFile()) return { warning: `output artifact is not a file: ${filePath}` };
471
- try {
472
- const realPath = fs.realpathSync(resolvedPath);
473
- const realRoots = trustedRoots.filter((root) => fs.existsSync(root)).map((root) => fs.realpathSync(root));
474
- if (!realRoots.some((root) => pathWithin(root, realPath))) return { warning: `output artifact resolves outside trusted roots: ${filePath}` };
475
- const fd = fs.openSync(realPath, "r");
476
- try {
477
- const bytes = Math.min(stat.size, OUTPUT_TAIL_BYTES);
478
- const buffer = Buffer.alloc(bytes);
479
- fs.readSync(fd, buffer, 0, bytes, stat.size - bytes);
480
- return { text: decodeUtf8Tail(buffer) };
481
- } finally {
482
- fs.closeSync(fd);
483
- }
484
- } catch (error) {
485
- return { warning: `output artifact could not be read: ${error instanceof Error ? error.message : String(error)}` };
486
- }
487
- }
488
-
489
- function foregroundRecentOutputLines(item: Extract<FleetItem, { kind: "foreground-recent" }>, state: SubagentState): string[] {
490
- const outputPath = item.child.artifactPaths?.outputPath ?? item.child.savedOutputPath;
491
- const output = item.child.finalOutput
492
- ? { text: item.child.finalOutput }
493
- : outputPath
494
- ? trustedFileTail(path.isAbsolute(outputPath) ? outputPath : path.resolve(item.run.cwd, outputPath), uniquePaths([
495
- fleetArtifactsRoot(state, item.run.cwd),
496
- fleetArtifactsRoot(state, state.baseCwd),
497
- ]))
498
- : undefined;
499
- if (output?.warning) return [`(${output.warning})`];
500
- if (output?.unavailable) return [`(${output.unavailable})`];
501
- const outputLines = (output?.text ?? "").split(/\r?\n/).filter((line) => line.trim()).slice(-TRANSCRIPT_LINES);
502
- return outputLines.length ? outputLines : ["(no recovered output available)"];
503
- }
504
-
505
- function foregroundRecentDetail(item: Extract<FleetItem, { kind: "foreground-recent" }>, state: SubagentState): string[] {
506
- const { child, run } = item;
507
- const outputPath = child.artifactPaths?.outputPath ?? child.savedOutputPath;
508
- const modelThinking = formatModelThinking(child.model, child.thinking);
509
- const lines = [
510
- `Run: ${item.runId}`,
511
- "Source: foreground",
512
- `State: ${child.status}`,
513
- `Mode: ${run.mode}`,
514
- `Child: ${child.index} (${child.agent})${contextModeLabel(child.context) ? ` ${contextModeLabel(child.context)}` : ""}`,
515
- modelThinking ? `Model: ${modelThinking}` : undefined,
516
- `Updated: ${new Date(child.updatedAt ?? run.updatedAt).toISOString()}`,
517
- outputPath ? `Output: ${outputPath}` : undefined,
518
- child.sessionFile ? `Session: ${child.sessionFile}` : undefined,
519
- child.transcriptPath ? `Transcript file: ${child.transcriptPath}` : undefined,
520
- child.error ? `Error: ${child.error}` : undefined,
521
- child.outputSaveError ? `Output warning: ${child.outputSaveError}` : undefined,
522
- child.transcriptError ? `Transcript warning: ${child.transcriptError}` : undefined,
523
- "",
524
- "Result transcript tail",
525
- ];
526
- lines.push(...foregroundRecentOutputLines(item, state));
527
- return lines.filter((line): line is string => line !== undefined);
528
- }
529
-
530
- function externalElapsedEnd(run: ExternalRun): number {
531
- const terminal = run.state !== "queued" && run.state !== "running";
532
- return terminal ? (run.endedAt ?? run.updatedAt ?? Date.now()) : Date.now();
533
- }
534
-
535
- function workflowStepLabel(step: AsyncJobStep, index: number): string {
536
- const key = step.workflowKey ?? `step ${index + 1}`;
537
- const label = step.label && step.label !== key ? ` · ${step.label}` : "";
538
- const phase = step.phase ? `${step.phase}: ` : "";
539
- return `${phase}${key}${label} (${step.agent})`;
540
- }
541
-
542
- function workflowStepActivity(step: AsyncJobStep): string | undefined {
543
- if (step.currentTool) return `tool ${step.currentTool}`;
544
- if (step.currentPath) return shortenPath(step.currentPath);
545
- if (step.activityState === "needs_attention") return "needs attention";
546
- if (step.activityState === "active_long_running") return "long-running";
547
- if (step.turnCount !== undefined) return `${step.turnCount} turns`;
548
- if (step.toolCount !== undefined) return `${step.toolCount} tools`;
549
- return undefined;
550
- }
551
-
552
- function visibleWorkflowProgressSteps(steps: AsyncJobStep[], visibleLimit: number): Array<{ step: AsyncJobStep; index: number } | { hidden: number }> {
553
- if (steps.length <= visibleLimit) return steps.map((step, index) => ({ step, index }));
554
- const selected = new Set<number>();
555
- for (const [index, step] of steps.entries()) {
556
- if (step.status !== "complete" && step.status !== "completed") selected.add(index);
557
- if (selected.size >= visibleLimit) break;
558
- }
559
- for (let index = steps.length - 1; index >= 0 && selected.size < visibleLimit; index--) selected.add(index);
560
- const visible = [...selected].sort((left, right) => left - right).map((index) => ({ step: steps[index]!, index }));
561
- return [{ hidden: steps.length - visible.length }, ...visible];
562
- }
563
-
564
- function workflowProgressLines(steps: AsyncJobStep[] | undefined): string[] {
565
- if (!steps?.length) return [];
566
- const lines = ["Workflow progress:"];
567
- for (const row of visibleWorkflowProgressSteps(steps, 8)) {
568
- if ("hidden" in row) {
569
- lines.push(` +${row.hidden} hidden workflow steps`);
570
- continue;
571
- }
572
- const activity = workflowStepActivity(row.step);
573
- const context = contextModeLabel(row.step.context);
574
- const details = [row.step.status, activity, context, row.step.tokens ? formatTokenUsage(row.step.tokens) : undefined].filter(Boolean).join(" · ");
575
- lines.push(` ${row.index + 1}. ${workflowStepLabel(row.step, row.index)}${details ? ` — ${details}` : ""}`);
576
- }
577
- return lines;
578
- }
579
-
580
- function asyncDetail(item: Extract<FleetItem, { kind: "async" }>, state: SubagentState): string[] {
581
- const status = readStatus(item.run.asyncDir);
582
- if (status) {
583
- const trackedJob = state.fleetJobs?.get(item.runId) ?? state.asyncJobs.get(item.runId);
584
- const lines = formatAsyncRunTranscript(status, item.run.asyncDir, {
585
- index: item.index,
586
- lines: TRANSCRIPT_LINES,
587
- sessionRoots: uniquePaths([...(state.trustedSessionRoots ?? []), trackedJob?.sessionRoot]),
588
- trustedSessionFiles: [item.step?.sessionFile ?? item.run.sessionFile].filter((value): value is string => Boolean(value)),
589
- trustedSessionFileRoot: state.trustedSessionFileRoot,
590
- }).split("\n");
591
- if (status.mode === "workflow" && item.index === undefined) {
592
- const progress = workflowProgressLines((status.steps ?? item.run.steps) as AsyncJobStep[]);
593
- if (progress.length) {
594
- const modeIndex = lines.findIndex((line) => line.startsWith("Mode:"));
595
- lines.splice(modeIndex >= 0 ? modeIndex + 1 : 0, 0, "", ...progress);
596
- }
597
- }
598
- return lines;
599
- }
600
- const outputPath = item.index !== undefined ? path.join(item.run.asyncDir, `output-${item.index}.log`) : undefined;
601
- return [
602
- `Run: ${item.runId}`,
603
- "Source: async",
604
- `State: ${item.state}`,
605
- `Mode: ${item.run.mode}${contextModeLabel(item.run.context) ? ` ${contextModeLabel(item.run.context)}` : ""}`,
606
- item.index !== undefined ? `Child: ${item.index} (${item.agent})${contextModeLabel(item.step?.context) ? ` ${contextModeLabel(item.step?.context)}` : ""}` : `Agent: ${item.agent}${contextModeLabel(item.run.context) ? ` ${contextModeLabel(item.run.context)}` : ""}`,
607
- outputPath ? `Output: ${outputPath}` : undefined,
608
- item.step?.sessionFile ? `Session: ${item.step.sessionFile}` : item.run.sessionFile ? `Session: ${item.run.sessionFile}` : undefined,
609
- "",
610
- "Transcript",
611
- "(status is no longer available)",
612
- ].filter((line): line is string => line !== undefined);
613
- }
614
-
615
- function externalDetail(item: Extract<FleetItem, { kind: "external" }>): string[] {
616
- return [
617
- `Run: ${item.runId}`,
618
- "Source: external · display-only",
619
- `Owner: ${item.run.source}`,
620
- `State: ${item.state}`,
621
- `Started: ${new Date(item.run.startedAt).toISOString()}`,
622
- item.run.updatedAt !== undefined ? `Updated: ${new Date(item.run.updatedAt).toISOString()}` : undefined,
623
- item.run.endedAt !== undefined ? `Ended: ${new Date(item.run.endedAt).toISOString()}` : undefined,
624
- `Elapsed: ${formatDuration(Math.max(0, externalElapsedEnd(item.run) - item.run.startedAt))}`,
625
- item.run.currentAction ? `Current action: ${item.run.currentAction}` : undefined,
626
- item.run.reportPath ? `Report path: ${item.run.reportPath}` : undefined,
627
- item.run.transcriptPath ? `Transcript path: ${item.run.transcriptPath}` : undefined,
628
- "",
629
- "Preview",
630
- item.run.preview ?? "(no preview supplied)",
631
- "",
632
- "The owning extension controls execution, persistence, cancellation, and results.",
633
- ].filter((line): line is string => line !== undefined);
634
- }
635
-
636
- function detailLines(item: FleetItem | undefined, error: string | undefined, state: SubagentState): string[] {
637
- if (!item) return [error ? `Fleet scan failed: ${error}` : "No current-session Fleet jobs.", "", "New jobs appear here automatically while this inspector remains open."];
638
- const lines = item.kind === "foreground-active"
639
- ? foregroundActiveDetail(item, state)
640
- : item.kind === "foreground-recent"
641
- ? foregroundRecentDetail(item, state)
642
- : item.kind === "external"
643
- ? externalDetail(item)
644
- : asyncDetail(item, state);
645
- if (error) lines.unshift(`Fleet scan warning: ${error}`, "");
646
- return lines;
647
- }
648
-
649
- function isActionableAsyncState(state: string): boolean {
650
- return state === "running" || state === "queued" || state === "pending";
651
- }
652
-
653
- function firstToolResultText(result: AgentToolResult<Details> | null, fallback: string): FleetActionResult {
654
- if (!result) return { text: fallback, isError: true };
655
- const text = result.content.find((item) => item.type === "text")?.text ?? fallback;
656
- return { text, ...(result.isError ? { isError: true } : {}) };
657
- }
658
-
659
- function uniquePaths(values: Array<string | undefined>): string[] {
660
- return [...new Set(values.filter((value): value is string => Boolean(value)).map((value) => path.resolve(value)))];
661
- }
662
-
663
- function fleetArtifactsRoot(state: SubagentState, cwd: string): string {
664
- return getArtifactsDir(
665
- state.parentSessionFile ?? null,
666
- cwd,
667
- state.artifactDirPreference,
668
- );
669
- }
670
-
671
- function transcriptTarget(item: FleetItem, state: SubagentState): { path: string; trustedRoots: string[]; trustedFiles?: string[]; trustedFileRoot?: string } | undefined {
672
- if (item.kind === "external") return undefined;
673
- if (item.kind === "foreground-active") {
674
- const artifactsRoot = fleetArtifactsRoot(state, item.control.cwd ?? state.baseCwd);
675
- return {
676
- path: getArtifactPaths(artifactsRoot, item.runId, item.agent, item.index ?? 0).transcriptPath,
677
- trustedRoots: [artifactsRoot],
678
- };
679
- }
680
- if (item.kind === "foreground-recent") {
681
- if (!item.child.transcriptPath) return undefined;
682
- const transcriptPath = path.isAbsolute(item.child.transcriptPath)
683
- ? item.child.transcriptPath
684
- : path.resolve(item.run.cwd, item.child.transcriptPath);
685
- return {
686
- path: transcriptPath,
687
- trustedRoots: uniquePaths([
688
- fleetArtifactsRoot(state, item.run.cwd),
689
- fleetArtifactsRoot(state, state.baseCwd),
690
- ]),
691
- };
692
- }
693
- const step = item.step ?? (item.run.steps.length === 1 ? item.run.steps[0] : undefined);
694
- // External CLI logs are plain text, not structured session JSONL. Let the
695
- // bounded async detail formatter select final output/stderr/stdout instead.
696
- if (step?.runner?.type === "external-cli") return undefined;
697
- const recordedSessionFile = step?.sessionFile ?? item.run.sessionFile;
698
- const recordedPath = step?.transcriptPath ?? recordedSessionFile;
699
- if (!recordedPath) return undefined;
700
- const transcriptPath = path.isAbsolute(recordedPath)
701
- ? recordedPath
702
- : path.resolve(item.run.asyncDir, recordedPath);
703
- const trackedJob = state.fleetJobs?.get(item.runId) ?? state.asyncJobs.get(item.runId);
704
- return {
705
- path: transcriptPath,
706
- trustedRoots: uniquePaths([
707
- item.run.asyncDir,
708
- fleetArtifactsRoot(state, state.baseCwd),
709
- trackedJob?.cwd ? fleetArtifactsRoot(state, trackedJob.cwd) : undefined,
710
- item.run.sessionFile ? getArtifactsDir(item.run.sessionFile, item.run.cwd ?? state.baseCwd, state.artifactDirPreference) : undefined,
711
- ]),
712
- ...(!step?.transcriptPath && recordedSessionFile ? { trustedFiles: [recordedSessionFile], trustedFileRoot: state.trustedSessionFileRoot } : {}),
713
- };
714
- }
715
-
716
- function itemContext(item: FleetItem): string | undefined {
717
- if (item.kind === "async") return contextModeLabel(item.step?.context ?? item.run.context);
718
- if (item.kind === "foreground-recent") return contextModeLabel(item.child.context);
719
- return undefined;
720
- }
721
-
722
- function itemMode(item: FleetItem): string {
723
- if (item.kind === "external") return "display-only";
724
- return item.kind === "foreground-active" ? item.control.mode : item.run.mode;
725
- }
726
-
727
- function itemSource(item: FleetItem): string {
728
- if (item.kind === "external") return `external · ${item.run.source}`;
729
- if (item.kind === "async") return "background";
730
- return item.kind === "foreground-active" ? "foreground · live" : "foreground · recent";
731
- }
732
-
733
- function itemStats(item: FleetItem): string[] {
734
- let model: string | undefined;
735
- let tokens: number | undefined;
736
- let tokenUsage: AsyncJobStep["tokens"];
737
- let tools: number | undefined;
738
- let durationMs: number | undefined;
739
- if (item.kind === "foreground-active") {
740
- const live = item.activeChild ?? item.control;
741
- model = formatModelThinking(live.model, live.thinking) || undefined;
742
- tokens = live.tokens;
743
- if (tokens !== undefined) tokenUsage = { input: live.inputTokens ?? 0, output: live.outputTokens ?? 0, total: tokens, ...(live.window !== undefined ? { window: live.window } : {}), ...(live.windowPeak !== undefined ? { windowPeak: live.windowPeak } : {}) };
744
- tools = live.toolCount;
745
- durationMs = Math.max(0, Date.now() - live.startedAt);
746
- } else if (item.kind === "foreground-recent") {
747
- model = formatModelThinking(item.child.model, item.child.thinking) || undefined;
748
- tokens = item.child.tokens;
749
- if (tokens !== undefined) tokenUsage = { input: 0, output: 0, total: tokens, ...(item.child.window !== undefined ? { window: item.child.window } : {}), ...(item.child.windowPeak !== undefined ? { windowPeak: item.child.windowPeak } : {}) };
750
- tools = item.child.toolCount;
751
- } else if (item.kind === "external") {
752
- durationMs = Math.max(0, externalElapsedEnd(item.run) - item.run.startedAt);
753
- } else {
754
- model = formatModelThinking(item.step?.model, item.step?.thinking) || undefined;
755
- tokenUsage = item.step?.tokens ?? (item.index === undefined ? item.run.totalTokens : undefined);
756
- tokens = tokenUsage?.total;
757
- tools = item.step?.toolCount ?? (item.index === undefined ? item.run.toolCount : undefined);
758
- const terminalRun = item.state !== "queued" && item.state !== "running" && item.state !== "pending";
759
- const endTime = item.run.endedAt ?? (terminalRun ? item.run.lastUpdate : undefined) ?? Date.now();
760
- durationMs = item.step?.durationMs ?? Math.max(0, endTime - item.run.startedAt);
761
- }
762
- return [
763
- model,
764
- tokenUsage ? formatTokenUsage(tokenUsage) : tokens !== undefined ? `${formatTokens(tokens)} tok` : undefined,
765
- tools !== undefined ? `${tools} tool${tools === 1 ? "" : "s"}` : undefined,
766
- durationMs !== undefined ? formatDuration(durationMs) : undefined,
767
- ].filter((value): value is string => Boolean(value));
768
- }
769
-
770
- function structuredHeader(item: FleetItem, width: number, theme: Theme, conversationState: string, promptSummary?: string): string[] {
771
- const lines: string[] = [];
772
- lines.push(rightAligned(` ${statusGlyph(item, theme)} ${theme.bold(item.agent)}`, theme.fg("dim", item.state), width));
773
- const child = "index" in item && item.index !== undefined ? ` · child ${item.index + 1}` : "";
774
- const context = itemContext(item);
775
- const identity = `${itemSource(item)} · ${item.runId.slice(0, 8)}${child} · ${itemMode(item)}${context ? ` ${context}` : ""}`;
776
- lines.push(` ${theme.fg("dim", identity)}`);
777
- const stats = itemStats(item);
778
- if (stats.length) lines.push(` ${theme.fg("muted", stats.join(" · "))}`);
779
- if (promptSummary) lines.push(` ${theme.fg("muted", `Task: ${promptSummary}`)}`);
780
- lines.push(`${theme.fg("accent", "Conversation")} ${theme.fg("dim", `· ${conversationState}`)}`);
781
- return lines.map((line) => truncateToWidth(line, width));
782
- }
783
-
784
- function fit(text: string, width: number): string {
785
- const clipped = truncateToWidth(text, Math.max(0, width));
786
- return clipped + " ".repeat(Math.max(0, width - visibleWidth(clipped)));
787
- }
788
-
789
- function rightAligned(left: string, right: string, width: number): string {
790
- const rightWidth = visibleWidth(right);
791
- const leftWidth = Math.max(0, width - rightWidth - 1);
792
- return fit(left, leftWidth) + " ".repeat(Math.max(1, width - leftWidth - rightWidth)) + fit(right, rightWidth);
793
- }
794
-
795
- interface FleetDetailSections {
796
- header: string[];
797
- body: string[];
798
- }
799
-
800
- interface FleetTranscriptCache {
801
- mode: "native" | "legacy";
802
- path: string;
803
- fingerprint: string;
804
- width: number;
805
- expandedTools: boolean;
806
- expandedThinking: boolean;
807
- conversationState: string;
808
- hasContent: boolean;
809
- warning?: string;
810
- body: string[];
811
- }
812
-
813
- function transcriptFingerprint(filePath: string): string {
814
- try {
815
- // ino and ctime catch a same-size, same-mtime replacement. Bigint keeps
816
- // Windows file ids, which exceed 2^53, exact.
817
- const stat = fs.statSync(filePath, { bigint: true });
818
- return `${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}`;
819
- } catch {
820
- return "missing";
821
- }
822
- }
823
-
824
- export class SubagentFleetComponent implements Component {
825
- private snapshot: FleetSnapshot = { items: [] };
826
- private selected = 0;
827
- private selectedKey: string | undefined;
828
- private detailScroll = 0;
829
- private detailAutoFollow = true;
830
- private detailLineCount = 0;
831
- private detailViewportHeight = 8;
832
- private bodyHeight = 8;
833
- private lastRosterWidth: number | undefined;
834
- private expandedTools = false;
835
- /** Structured-view thinking visibility; collapsed by default (see spec). */
836
- private expandedThinking = false;
837
- /** Structured-view renderer selection; legacy is the always-available fallback. */
838
- private rendererMode: "native" | "legacy" = "native";
839
- /** undefined = still loading, null = unavailable (permanent for this inspector session). */
840
- private nativeModule: NativeTranscriptModule | null | undefined;
841
- private promptAuditOpen = false;
842
- private promptAuditView: PromptAuditView = "authored";
843
- private actionNotice: FleetActionResult | undefined;
844
- private steerDraft: string | undefined;
845
- private redoGuidanceDraft: string | undefined;
846
- private steerMode: SteerDeliveryMode = "steer";
847
- private stopConfirming = false;
848
- private actionBusy = false;
849
- private transcriptCache: FleetTranscriptCache | undefined;
850
- private disposed = false;
851
- private refreshTimer: ReturnType<typeof setTimeout> | undefined;
852
- private readonly refreshMs: number;
853
- private readonly tui: FleetTui;
854
- private readonly theme: Theme;
855
- private readonly markdownTheme: MarkdownTheme;
856
- private readonly state: SubagentState;
857
- private readonly done: (result: undefined) => void;
858
- private readonly options: FleetViewOptions;
859
- private readonly keybindings: ResolvedFleetKeybindings;
860
-
861
- constructor(
862
- tui: FleetTui,
863
- theme: Theme,
864
- state: SubagentState,
865
- done: (result: undefined) => void,
866
- options: FleetViewOptions = {},
867
- ) {
868
- this.tui = tui;
869
- this.theme = theme;
870
- this.markdownTheme = options.markdownTheme ?? getMarkdownTheme();
871
- this.state = state;
872
- this.done = done;
873
- this.options = options;
874
- this.keybindings = resolveFleetKeybindings(options.fleetKeybindings);
875
- this.refreshMs = Math.max(MIN_REFRESH_MS, options.refreshMs ?? REFRESH_MS);
876
- this.selectedKey = options.initialKey;
877
- this.refresh();
878
- this.scheduleRefresh();
879
- // Resolve native-renderer availability once; until it settles the
880
- // inspector renders through the legacy path (see renderedTranscript).
881
- void loadNativeTranscriptSupport().then((mod) => {
882
- this.nativeModule = mod;
883
- if (!this.disposed && this.rendererMode === "native") this.tui.requestRender();
884
- });
885
- }
886
-
887
- private nativeRenderedOutcome(mod: NativeTranscriptModule, target: { path: string; trustedRoots: string[]; trustedFiles?: string[]; trustedFileRoot?: string }, width: number): { body: string[]; conversationState: string; hasContent: boolean; warning?: string; readFailed?: boolean } {
888
- try {
889
- const built = buildNativeFleetTranscript(mod, {
890
- filePath: target.path,
891
- trustedRoots: target.trustedRoots,
892
- ...(target.trustedFiles ? { trustedFiles: target.trustedFiles } : {}),
893
- ...(target.trustedFileRoot ? { trustedFileRoot: target.trustedFileRoot } : {}),
894
- width,
895
- expandedTools: this.expandedTools,
896
- hideThinkingBlock: !this.expandedThinking,
897
- thinkingLabel: this.thinkingToggleLabel(),
898
- cwd: this.state.baseCwd,
899
- theme: this.theme,
900
- });
901
- return { readFailed: built.readFailed, body: built.lines, conversationState: built.conversationState, hasContent: built.entryCount > 0, ...(built.warning ? { warning: built.warning } : {}) };
902
- } catch {
903
- // A native-render failure must never blank the inspector: degrade to
904
- // the legacy renderer for the rest of this inspector session.
905
- this.nativeModule = null;
906
- return this.legacyRenderedOutcome(target, width);
907
- }
908
- }
909
-
910
- private legacyRenderedOutcome(target: { path: string; trustedRoots: string[]; trustedFiles?: string[]; trustedFileRoot?: string }, width: number): { body: string[]; conversationState: string; hasContent: boolean; warning?: string; readFailed?: boolean } {
911
- const transcript = readFleetTranscript(target.path, {
912
- trustedRoots: target.trustedRoots,
913
- ...(target.trustedFiles ? { trustedFiles: target.trustedFiles } : {}),
914
- ...(target.trustedFileRoot ? { trustedFileRoot: target.trustedFileRoot } : {}),
915
- });
916
- const body = transcript.events.length > 0
917
- ? renderFleetTranscript(transcript, width, this.theme, this.markdownTheme, { expandedTools: this.expandedTools })
918
- : [];
919
- const latest = transcript.events.at(-1);
920
- const conversationState = latest?.kind === "assistant"
921
- ? "assistant response"
922
- : latest?.kind === "user"
923
- ? "supervisor message"
924
- : latest?.kind === "tool"
925
- ? `${latest.name} · ${latest.status}`
926
- : "activity";
927
- return {
928
- body,
929
- conversationState,
930
- hasContent: transcript.events.length > 0,
931
- readFailed: transcript.readFailed,
932
- ...(transcript.warning ? { warning: transcript.warning } : {}),
933
- };
934
- }
935
-
936
- private scheduleRefresh(): void {
937
- if (this.disposed || this.refreshTimer) return;
938
- this.refreshTimer = setTimeout(() => {
939
- this.refreshTimer = undefined;
940
- if (this.disposed) return;
941
- try {
942
- this.refresh();
943
- this.tui.requestRender();
944
- } finally {
945
- this.scheduleRefresh();
946
- }
947
- }, this.refreshMs);
948
- this.refreshTimer.unref?.();
949
- }
950
-
951
- private stopRefresh(): void {
952
- this.disposed = true;
953
- if (this.refreshTimer) clearTimeout(this.refreshTimer);
954
- this.refreshTimer = undefined;
955
- }
956
-
957
- private refresh(): void {
958
- const previousKey = this.snapshot.items[this.selected]?.key ?? this.selectedKey;
959
- this.snapshot = collectFleetSnapshot(this.state, this.options);
960
- let preserved = previousKey ? this.snapshot.items.findIndex((item) => item.key === previousKey) : -1;
961
- if (preserved < 0 && previousKey) {
962
- const parentKey = visibleWorkflowParentKeyForForegroundKey(this.state, previousKey, this.snapshot.items);
963
- if (parentKey) preserved = this.snapshot.items.findIndex((item) => item.key === parentKey);
964
- }
965
- this.selected = preserved >= 0 ? preserved : Math.min(this.selected, Math.max(0, this.snapshot.items.length - 1));
966
- this.selectedKey = this.snapshot.items[this.selected]?.key;
967
- }
968
-
969
- private moveSelection(delta: number): void {
970
- if (this.snapshot.items.length === 0) return;
971
- this.selected = Math.max(0, Math.min(this.snapshot.items.length - 1, this.selected + delta));
972
- this.selectedKey = this.snapshot.items[this.selected]?.key;
973
- this.detailAutoFollow = true;
974
- this.resetActionInput();
975
- this.tui.requestRender();
976
- }
977
-
978
- private selectedPromptAudit(): LivePromptAudit | undefined {
979
- const item = this.snapshot.items[this.selected];
980
- if (item?.kind !== "foreground-active") return undefined;
981
- if (!this.state.currentSessionId || item.control.sessionId !== this.state.currentSessionId) return undefined;
982
- return getLivePromptAudit(item.control, item.index ?? 0);
983
- }
984
-
985
- private promptAuditItems(): Array<{ item: Extract<FleetItem, { kind: "foreground-active" }>; prompt: LivePromptAudit }> {
986
- const selected = this.snapshot.items[this.selected];
987
- if (selected?.kind !== "foreground-active" || !this.state.currentSessionId || selected.control.sessionId !== this.state.currentSessionId) return [];
988
- return this.snapshot.items.flatMap((item) => {
989
- if (item.kind !== "foreground-active" || item.control !== selected.control) return [];
990
- const prompt = getLivePromptAudit(item.control, item.index ?? 0);
991
- return prompt ? [{ item, prompt }] : [];
992
- });
993
- }
994
-
995
- private selectedPromptText(): string | undefined {
996
- const prompt = this.selectedPromptAudit();
997
- return prompt ? promptAuditText(prompt, this.promptAuditView) : undefined;
998
- }
999
-
1000
- private movePromptSelection(delta: number): void {
1001
- const items = this.promptAuditItems();
1002
- if (items.length === 0) return;
1003
- const currentKey = this.snapshot.items[this.selected]?.key;
1004
- const current = Math.max(0, items.findIndex(({ item }) => item.key === currentKey));
1005
- const target = items[Math.max(0, Math.min(items.length - 1, current + delta))]?.item;
1006
- if (!target) return;
1007
- this.selected = this.snapshot.items.findIndex((item) => item.key === target.key);
1008
- this.selectedKey = target.key;
1009
- this.detailScroll = 0;
1010
- this.detailAutoFollow = false;
1011
- this.tui.requestRender();
1012
- }
1013
-
1014
- private resetActionInput(): void {
1015
- this.steerDraft = undefined;
1016
- this.redoGuidanceDraft = undefined;
1017
- this.steerMode = "steer";
1018
- this.stopConfirming = false;
1019
- }
1020
-
1021
- private selectedAsyncAction(): { item: Extract<FleetItem, { kind: "async" }> } | { reason: string } {
1022
- const item = this.snapshot.items[this.selected];
1023
- if (!item) return { reason: "No child is selected." };
1024
- if (item.kind === "external") return { reason: "External jobs are display-only and remain controlled by their owning extension." };
1025
- if (item.kind !== "async") return { reason: "Fleet controls are available for current-session top-level async runs only." };
1026
- if (!isActionableAsyncState(item.run.state) || !isActionableAsyncState(item.state)) return { reason: `Selected child is ${item.state}; controls require a running or queued async child.` };
1027
- return { item };
1028
- }
1029
-
1030
- private selectedSteerAction(): { runId: string; asyncDir: string; index?: number } | { reason: string } {
1031
- const item = this.snapshot.items[this.selected];
1032
- if (item?.kind === "foreground-active" && item.control.parentWorkflowRunId) {
1033
- const parent = this.state.asyncJobs.get(item.control.parentWorkflowRunId) ?? this.state.fleetJobs?.get(item.control.parentWorkflowRunId);
1034
- if (!parent || !isActionableAsyncState(parent.status)) return { reason: "The parent workflow is no longer available for steering." };
1035
- return { runId: item.runId, asyncDir: parent.asyncDir, ...(item.index !== undefined ? { index: item.index } : {}) };
1036
- }
1037
- const target = this.selectedAsyncAction();
1038
- if ("reason" in target) return target;
1039
- return { runId: target.item.runId, asyncDir: target.item.run.asyncDir, ...(target.item.index !== undefined ? { index: target.item.index } : {}) };
1040
- }
1041
-
1042
- private selectedInspectAction(): { runId: string; asyncDir: string; index?: number } | { reason: string } {
1043
- const item = this.snapshot.items[this.selected];
1044
- if (!item) return { reason: "No child is selected." };
1045
- if (item.kind === "external") return { reason: "External jobs are display-only and have no inspector controls." };
1046
- if (item.kind === "async") {
1047
- if (!isActionableAsyncState(item.run.state) || !isActionableAsyncState(item.state)) return { reason: `Selected child is ${item.state}; controls require a running or queued async child.` };
1048
- return { runId: item.runId, asyncDir: item.run.asyncDir, ...(item.index !== undefined ? { index: item.index } : {}) };
1049
- }
1050
- if (item.kind !== "foreground-active" || !item.control.parentWorkflowRunId) return { reason: "Fleet controls are available for current-session top-level async runs only." };
1051
- const parent = this.state.asyncJobs.get(item.control.parentWorkflowRunId) ?? this.state.fleetJobs?.get(item.control.parentWorkflowRunId);
1052
- if (!parent || !isActionableAsyncState(parent.status)) return { reason: "The parent workflow is no longer available for inspection." };
1053
- return { runId: parent.asyncId, asyncDir: parent.asyncDir };
1054
- }
1055
-
1056
- private inspectSelected(): void {
1057
- const target = this.selectedInspectAction();
1058
- if ("reason" in target || !this.options.actions?.inspect) this.setActionNotice({ text: "reason" in target ? target.reason : "Inspector controls are unavailable in this context.", isError: true });
1059
- else this.runAction(() => this.options.actions!.inspect!(target));
1060
- }
1061
-
1062
- private actionLines(): string[] {
1063
- const lines: string[] = [];
1064
- if (this.actionBusy) lines.push(this.theme.fg("accent", "Action pending..."));
1065
- if (this.steerDraft !== undefined) {
1066
- lines.push(this.theme.fg("accent", `Steer message (${this.steerMode}): ${this.steerDraft}${this.theme.fg("dim", "▌")}`));
1067
- lines.push(this.theme.fg("dim", "Enter sends · Tab changes mode · Esc cancels · Backspace edits"));
1068
- } else if (this.redoGuidanceDraft !== undefined) {
1069
- lines.push(this.theme.fg("accent", `Redo guidance: ${this.redoGuidanceDraft}${this.theme.fg("dim", "▌")}`));
1070
- lines.push(this.theme.fg("dim", "Enter rewrites and reruns · Esc cancels · Backspace edits"));
1071
- } else if (this.stopConfirming) {
1072
- const selected = this.snapshot.items[this.selected];
1073
- lines.push(this.theme.fg("warning", `Confirm stop for async run ${selected?.runId ?? "selected run"}?`));
1074
- lines.push(this.theme.fg("dim", "Stop ends the run; use interrupt for a resumable pause. Enter/Y confirms · N returns · Esc cancels"));
1075
- } else if (this.actionNotice) {
1076
- lines.push(this.theme.fg(this.actionNotice.isError ? "error" : "success", this.actionNotice.text));
1077
- }
1078
- return lines;
1079
- }
1080
-
1081
- private withActionLines(body: string[]): string[] {
1082
- const actionLines = this.actionLines();
1083
- return actionLines.length ? [...actionLines, "", ...body] : body;
1084
- }
1085
-
1086
- private setActionNotice(result: FleetActionResult): void {
1087
- this.actionNotice = result;
1088
- this.resetActionInput();
1089
- this.detailAutoFollow = false;
1090
- this.detailScroll = 0;
1091
- this.refresh();
1092
- this.tui.requestRender();
1093
- }
1094
-
1095
- private runAction(action: () => Promise<FleetActionResult>): void {
1096
- if (this.actionBusy) return;
1097
- this.actionBusy = true;
1098
- this.actionNotice = undefined;
1099
- this.tui.requestRender();
1100
- void action()
1101
- .then((result) => this.setActionNotice(result))
1102
- .catch((error) => this.setActionNotice({ text: error instanceof Error ? error.message : String(error), isError: true }))
1103
- .finally(() => {
1104
- this.actionBusy = false;
1105
- if (!this.disposed) this.tui.requestRender();
1106
- });
1107
- }
1108
-
1109
- private scrollDetail(delta: number): void {
1110
- const maxScroll = Math.max(0, this.detailLineCount - this.detailViewportHeight);
1111
- this.detailScroll = Math.max(0, Math.min(maxScroll, this.detailScroll + delta));
1112
- this.detailAutoFollow = this.detailScroll >= maxScroll;
1113
- this.tui.requestRender();
1114
- }
1115
-
1116
- handleInput(data: string): void {
1117
- const wheel = parseMouseWheelEvent(data);
1118
- if (wheel) {
1119
- // While editing draft text, ignore the wheel to avoid surprising scroll jumps.
1120
- if (this.steerDraft !== undefined || this.redoGuidanceDraft !== undefined) return;
1121
- const overRoster = this.lastRosterWidth !== undefined && wheel.x <= this.lastRosterWidth;
1122
- if (this.promptAuditOpen) {
1123
- if (overRoster) this.movePromptSelection(wheel.direction);
1124
- else this.scrollDetail(wheel.direction * WHEEL_SCROLL_LINES);
1125
- } else if (overRoster) {
1126
- this.moveSelection(wheel.direction);
1127
- } else {
1128
- this.scrollDetail(wheel.direction * WHEEL_SCROLL_LINES);
1129
- }
1130
- return;
1131
- }
1132
- if (this.promptAuditOpen && this.redoGuidanceDraft !== undefined) {
1133
- if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c")) {
1134
- this.resetActionInput();
1135
- this.tui.requestRender();
1136
- return;
1137
- }
1138
- if (matchesKey(data, "return") || data === "\r" || data === "\n") {
1139
- const guidance = this.redoGuidanceDraft.trim();
1140
- if (!guidance) {
1141
- this.setActionNotice({ text: "Redo guidance cannot be empty.", isError: true });
1142
- return;
1143
- }
1144
- const selected = this.snapshot.items[this.selected];
1145
- if (selected?.kind !== "foreground-active" || !this.options.actions?.redoPrompt) {
1146
- this.setActionNotice({ text: "Redo is unavailable for this prompt.", isError: true });
1147
- return;
1148
- }
1149
- this.runAction(() => this.options.actions!.redoPrompt!({ runId: selected.runId, index: selected.index ?? 0, guidance, control: selected.control }));
1150
- return;
1151
- }
1152
- if (matchesKey(data, "backspace") || data === "\x7f") {
1153
- this.redoGuidanceDraft = this.redoGuidanceDraft.slice(0, -1);
1154
- this.tui.requestRender();
1155
- return;
1156
- }
1157
- if (data.length === 1 && data >= " " && data !== "\x7f") {
1158
- this.redoGuidanceDraft += data;
1159
- this.tui.requestRender();
1160
- }
1161
- return;
1162
- }
1163
- if (this.promptAuditOpen) {
1164
- if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c")) {
1165
- this.promptAuditOpen = false;
1166
- this.detailAutoFollow = true;
1167
- this.tui.requestRender();
1168
- return;
1169
- }
1170
- if (data === "j") return this.movePromptSelection(1);
1171
- if (data === "k") return this.movePromptSelection(-1);
1172
- if (data === "1" || data === "2" || data === "3") {
1173
- this.promptAuditView = data === "1" ? "authored" : data === "2" ? "runtime" : "effective";
1174
- this.detailScroll = 0;
1175
- this.tui.requestRender();
1176
- return;
1177
- }
1178
- if (data === "g") {
1179
- const prompt = this.selectedPromptAudit();
1180
- if (!prompt) this.setActionNotice({ text: "Prompt Audit is available only for a live child owned by this session.", isError: true });
1181
- else if (!prompt.rerun) this.setActionNotice({ text: "Redo is not safe for this prompt in this slice.", isError: true });
1182
- else if (!this.options.actions?.redoPrompt) this.setActionNotice({ text: "Redo controls are unavailable in this context.", isError: true });
1183
- else {
1184
- this.actionNotice = undefined;
1185
- this.redoGuidanceDraft = "";
1186
- this.detailAutoFollow = false;
1187
- this.detailScroll = 0;
1188
- this.tui.requestRender();
1189
- }
1190
- return;
1191
- }
1192
- if (data === "c") {
1193
- const text = this.selectedPromptText();
1194
- if (!text) this.setActionNotice({ text: "No prompt view is available to copy.", isError: true });
1195
- else if (!this.options.copyText) this.setActionNotice({ text: "Clipboard is unavailable in this context.", isError: true });
1196
- else this.runAction(async () => {
1197
- await this.options.copyText!(text);
1198
- return { text: "Copied visible prompt view." };
1199
- });
1200
- return;
1201
- }
1202
- if (matchesFleetAction(data, this.keybindings, "scrollUp")) return this.scrollDetail(-1);
1203
- if (matchesFleetAction(data, this.keybindings, "scrollDown")) return this.scrollDetail(1);
1204
- if (matchesFleetAction(data, this.keybindings, "pageUp")) return this.scrollDetail(-this.detailViewportHeight);
1205
- if (matchesFleetAction(data, this.keybindings, "pageDown")) return this.scrollDetail(this.detailViewportHeight);
1206
- return;
1207
- }
1208
- if (this.steerDraft !== undefined) {
1209
- if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c")) {
1210
- this.resetActionInput();
1211
- this.tui.requestRender();
1212
- return;
1213
- }
1214
- if (matchesKey(data, "return") || data === "\r" || data === "\n") {
1215
- const message = this.steerDraft.trim();
1216
- if (!message) {
1217
- this.setActionNotice({ text: "Steer message cannot be empty.", isError: true });
1218
- return;
1219
- }
1220
- const target = this.selectedSteerAction();
1221
- if ("reason" in target || !this.options.actions) {
1222
- this.setActionNotice({ text: "reason" in target ? target.reason : "Fleet controls are unavailable in this context.", isError: true });
1223
- return;
1224
- }
1225
- this.runAction(() => this.options.actions!.steer({ ...target, message, mode: this.steerMode }));
1226
- return;
1227
- }
1228
- if (matchesKey(data, "tab") || data === "\t") {
1229
- const modes: SteerDeliveryMode[] = ["steer", "follow_up", "auto"];
1230
- this.steerMode = modes[(modes.indexOf(this.steerMode) + 1) % modes.length]!;
1231
- this.tui.requestRender();
1232
- return;
1233
- }
1234
- if (matchesKey(data, "backspace") || data === "\x7f") {
1235
- this.steerDraft = this.steerDraft.slice(0, -1);
1236
- this.tui.requestRender();
1237
- return;
1238
- }
1239
- if (data.length === 1 && data >= " " && data !== "\x7f") {
1240
- this.steerDraft += data;
1241
- this.tui.requestRender();
1242
- }
1243
- return;
1244
- }
1245
- if (this.stopConfirming) {
1246
- if (matchesKey(data, "return") || data.toLowerCase() === "y") {
1247
- const target = this.selectedAsyncAction();
1248
- if ("reason" in target || !this.options.actions) {
1249
- this.setActionNotice({ text: "reason" in target ? target.reason : "Fleet controls are unavailable in this context.", isError: true });
1250
- return;
1251
- }
1252
- this.runAction(() => Promise.resolve(this.options.actions!.stop({ runId: target.item.runId, asyncDir: target.item.run.asyncDir, ...(target.item.index !== undefined ? { index: target.item.index } : {}) })));
1253
- return;
1254
- }
1255
- if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c") || data.toLowerCase() === "n" || matchesKey(data, "backspace")) {
1256
- this.resetActionInput();
1257
- this.tui.requestRender();
1258
- }
1259
- return;
1260
- }
1261
- if (matchesFleetAction(data, this.keybindings, "close")) {
1262
- this.stopRefresh();
1263
- this.done(undefined);
1264
- return;
1265
- }
1266
- if (matchesFleetAction(data, this.keybindings, "scrollUp")) return this.scrollDetail(-1);
1267
- if (matchesFleetAction(data, this.keybindings, "scrollDown")) return this.scrollDetail(1);
1268
- if (matchesFleetAction(data, this.keybindings, "selectUp")) return this.moveSelection(-1);
1269
- if (matchesFleetAction(data, this.keybindings, "selectDown")) return this.moveSelection(1);
1270
- if (matchesFleetAction(data, this.keybindings, "selectFirst")) return this.moveSelection(-this.snapshot.items.length);
1271
- if (matchesFleetAction(data, this.keybindings, "selectLast")) return this.moveSelection(this.snapshot.items.length);
1272
- if (matchesFleetAction(data, this.keybindings, "pageUp")) return this.scrollDetail(-this.detailViewportHeight);
1273
- if (matchesFleetAction(data, this.keybindings, "pageDown")) return this.scrollDetail(this.detailViewportHeight);
1274
- if (matchesFleetAction(data, this.keybindings, "refresh")) {
1275
- this.transcriptCache = undefined;
1276
- this.refresh();
1277
- this.tui.requestRender();
1278
- return;
1279
- }
1280
- if (data === "p") {
1281
- if (!this.selectedPromptAudit()) this.setActionNotice({ text: "Prompt Audit is available only for a live child owned by this session.", isError: true });
1282
- else {
1283
- this.promptAuditOpen = true;
1284
- this.promptAuditView = "authored";
1285
- this.detailScroll = 0;
1286
- this.detailAutoFollow = false;
1287
- this.actionNotice = undefined;
1288
- this.tui.requestRender();
1289
- }
1290
- return;
1291
- }
1292
- if (matchesFleetAction(data, this.keybindings, "steer")) {
1293
- const target = this.selectedSteerAction();
1294
- if ("reason" in target || !this.options.actions) this.setActionNotice({ text: "reason" in target ? target.reason : "Fleet controls are unavailable in this context.", isError: true });
1295
- else {
1296
- this.actionNotice = undefined;
1297
- this.steerDraft = "";
1298
- this.detailAutoFollow = false;
1299
- this.detailScroll = 0;
1300
- this.tui.requestRender();
1301
- }
1302
- return;
1303
- }
1304
- if (matchesFleetAction(data, this.keybindings, "stop")) {
1305
- const target = this.selectedAsyncAction();
1306
- if ("reason" in target || !this.options.actions) this.setActionNotice({ text: "reason" in target ? target.reason : "Fleet controls are unavailable in this context.", isError: true });
1307
- else {
1308
- this.actionNotice = undefined;
1309
- this.stopConfirming = true;
1310
- this.detailAutoFollow = false;
1311
- this.detailScroll = 0;
1312
- this.tui.requestRender();
1313
- }
1314
- return;
1315
- }
1316
- if (matchesFleetAction(data, this.keybindings, "toggleTools")) {
1317
- this.expandedTools = !this.expandedTools;
1318
- this.transcriptCache = undefined;
1319
- this.tui.requestRender();
1320
- return;
1321
- }
1322
- if (matchesFleetAction(data, this.keybindings, "toggleThinking")) {
1323
- // Structured view only: the legacy rail renderer carries no thinking
1324
- // entries, so the toggle stays inert there instead of erroring.
1325
- this.expandedThinking = !this.expandedThinking;
1326
- this.transcriptCache = undefined;
1327
- this.tui.requestRender();
1328
- return;
1329
- }
1330
- if (matchesFleetAction(data, this.keybindings, "inspect")) {
1331
- this.inspectSelected();
1332
- return;
1333
- }
1334
- if (matchesFleetAction(data, this.keybindings, "toggleRenderer")) {
1335
- if (this.rendererMode === "native" && this.nativeModule === null) {
1336
- this.setActionNotice({ text: "Native transcript renderer unavailable in this host; staying on the text view.", isError: true });
1337
- return;
1338
- }
1339
- if (this.rendererMode === "legacy" && this.nativeModule === undefined) {
1340
- this.setActionNotice({ text: "Native transcript renderer is still loading." });
1341
- return;
1342
- }
1343
- this.rendererMode = this.rendererMode === "native" ? "legacy" : "native";
1344
- this.detailAutoFollow = true;
1345
- this.transcriptCache = undefined;
1346
- this.tui.requestRender();
1347
- return;
1348
- }
1349
- }
1350
-
1351
- private rosterLines(width: number): string[] {
1352
- if (this.snapshot.items.length === 0) return [this.theme.fg("dim", "No tracked children")];
1353
- const start = Math.max(0, Math.min(this.selected - this.bodyHeight + 1, Math.max(0, this.snapshot.items.length - this.bodyHeight)));
1354
- return this.snapshot.items.slice(start, start + this.bodyHeight).map((item, offset) => {
1355
- const index = start + offset;
1356
- const marker = index === this.selected ? this.theme.fg("accent", "›") : " ";
1357
- const context = item.kind === "async" ? contextModeBadge(this.theme, item.step?.context ?? item.run.context) : item.kind === "foreground-recent" ? contextModeBadge(this.theme, item.child.context) : "";
1358
- const agent = index === this.selected ? this.theme.bold(item.agent) : item.agent;
1359
- const identity = item.runId.slice(0, 8);
1360
- const left = `${marker} ${statusGlyph(item, this.theme)} ${agent}${context} ${this.theme.fg("dim", `· ${identity}`)}`;
1361
- return rightAligned(left, this.theme.fg("dim", item.state), width);
1362
- });
1363
- }
1364
-
1365
- private renderedTranscript(target: { path: string; trustedRoots: string[]; trustedFiles?: string[]; trustedFileRoot?: string }, width: number): { body: string[]; conversationState: string; hasContent: boolean; warning?: string; readFailed?: boolean } {
1366
- const fingerprint = `${this.rendererMode}|${target.trustedRoots.join("\0")}|${target.trustedFiles?.join("\0") ?? ""}|${target.trustedFileRoot ?? ""}|${transcriptFingerprint(target.path)}`;
1367
- if (this.transcriptCache
1368
- && this.transcriptCache.mode === this.rendererMode
1369
- && this.transcriptCache.path === target.path
1370
- && this.transcriptCache.fingerprint === fingerprint
1371
- && this.transcriptCache.width === width
1372
- && this.transcriptCache.expandedTools === this.expandedTools
1373
- && this.transcriptCache.expandedThinking === this.expandedThinking) {
1374
- return {
1375
- body: [...this.transcriptCache.body],
1376
- conversationState: this.transcriptCache.conversationState,
1377
- hasContent: this.transcriptCache.hasContent,
1378
- ...(this.transcriptCache.warning ? { warning: this.transcriptCache.warning } : {}),
1379
- };
1380
- }
1381
- // While the native module is still resolving (undefined) or unavailable
1382
- // (null) the legacy rail renderer serves the view; both paths share the
1383
- // same trusted-root read and cache entry.
1384
- const outcome = this.rendererMode === "native" && this.nativeModule
1385
- ? this.nativeRenderedOutcome(this.nativeModule, target, width)
1386
- : this.legacyRenderedOutcome(target, width);
1387
- this.transcriptCache = outcome.readFailed ? undefined : { mode: this.rendererMode, path: target.path, fingerprint, width, expandedTools: this.expandedTools, expandedThinking: this.expandedThinking, ...outcome, body: [...outcome.body] };
1388
- return outcome;
1389
- }
1390
-
1391
- /** Label of a collapsed thinking block, carrying its own expansion hint. */
1392
- private thinkingToggleLabel(): string {
1393
- return `Thinking (${bindingLabel(this.keybindings, "toggleThinking")} to expand)`;
1394
- }
1395
-
1396
- private promptAuditDetail(width: number): FleetDetailSections {
1397
- const selected = this.snapshot.items[this.selected];
1398
- const prompt = this.selectedPromptAudit();
1399
- const items = this.promptAuditItems();
1400
- const selectedPosition = selected ? items.findIndex(({ item }) => item.key === selected.key) : -1;
1401
- const live = selected?.kind === "foreground-active" ? selected.activeChild ?? selected.control : undefined;
1402
- const viewLabel = promptAuditViewLabel(this.promptAuditView);
1403
- const promptText = this.selectedPromptText()
1404
- ?? this.theme.fg("muted", "Selected prompt unavailable.");
1405
- const raw = [
1406
- this.theme.bold("Prompt Audit"),
1407
- this.theme.fg("dim", "Retention: live memory only · no storage"),
1408
- selected?.kind === "foreground-active" ? `Run: ${selected.runId}${selected.index !== undefined ? ` · Child: ${selected.index}` : ""} · Agent: ${selected.agent}` : "Selected prompt unavailable",
1409
- live ? `Started: ${new Date(live.startedAt).toISOString()}` : undefined,
1410
- live ? `Model: ${formatModelThinking(live.model, live.thinking) || "default"}` : undefined,
1411
- prompt?.cwd ? `Cwd: ${prompt.cwd}` : undefined,
1412
- prompt?.outputPath ? `Output: ${prompt.outputPath}` : undefined,
1413
- this.theme.fg("dim", `Live children: ${items.map(({ item }) => item.agent).join(", ") || "none"}`),
1414
- this.theme.fg("dim", selectedPosition >= 0 ? `Selected: ${selectedPosition + 1}/${items.length}` : "Selected prompt unavailable"),
1415
- "",
1416
- this.theme.fg("accent", viewLabel),
1417
- promptText,
1418
- ];
1419
- const body = raw.filter((line): line is string => line !== undefined).flatMap((line) => wrapTextWithAnsi(line, Math.max(1, width)));
1420
- return { header: [], body: this.withActionLines(body) };
1421
- }
1422
-
1423
- private wrappedDetail(width: number): FleetDetailSections {
1424
- if (this.promptAuditOpen) return this.promptAuditDetail(width);
1425
- const selected = this.snapshot.items[this.selected];
1426
- let transcriptWarning: string | undefined;
1427
- if (selected) {
1428
- const target = transcriptTarget(selected, this.state);
1429
- if (target) {
1430
- const rendered = this.renderedTranscript(target, width);
1431
- transcriptWarning = rendered.warning;
1432
- if (rendered.hasContent) {
1433
- const body = rendered.body;
1434
- if (this.snapshot.error) body.unshift(this.theme.fg("warning", `Fleet scan warning: ${this.snapshot.error}`), "");
1435
- const promptSummary = selected.kind === "foreground-active" ? foregroundAuthoredPromptSummary(selected, this.state) : undefined;
1436
- return { header: structuredHeader(selected, width, this.theme, rendered.conversationState, promptSummary), body: this.withActionLines(body) };
1437
- }
1438
- }
1439
- }
1440
-
1441
- const raw = detailLines(selected, this.snapshot.error, this.state);
1442
- if (transcriptWarning) raw.unshift(`Transcript preview warning: ${transcriptWarning}`, "");
1443
- const lines: string[] = [];
1444
- for (const line of raw) {
1445
- const styled = /^(Run|State|Mode|Source|Child|Agent|Model|Task):/.test(line)
1446
- ? this.theme.bold(line)
1447
- : /^(Transcript|Result transcript tail)/.test(line)
1448
- ? this.theme.fg("accent", line)
1449
- : /^(Output|Session|Transcript file|Artifacts):/.test(line)
1450
- ? this.theme.fg("muted", line)
1451
- : /^Transcript preview warning:/.test(line)
1452
- ? this.theme.fg("warning", line)
1453
- : line;
1454
- const wrapped = wrapTextWithAnsi(styled, Math.max(1, width));
1455
- lines.push(...(wrapped.length ? wrapped : [""]));
1456
- }
1457
- return { header: [], body: this.withActionLines(lines) };
1458
- }
1459
-
1460
- render(width: number): string[] {
1461
- if (width < 36) return [truncateToWidth("Subagent fleet needs at least 36 columns. Esc closes.", width)];
1462
- const innerWidth = width - 2;
1463
- const rows = this.tui.terminal?.rows ?? 32;
1464
- this.bodyHeight = Math.max(2, Math.floor(rows * 0.85) - 6);
1465
- const rosterWidth = Math.max(22, Math.min(46, Math.floor((innerWidth - 1) * 0.38)));
1466
- this.lastRosterWidth = rosterWidth;
1467
- const detailWidth = Math.max(1, innerWidth - rosterWidth - 1);
1468
- const roster = this.rosterLines(rosterWidth);
1469
- const detail = this.wrappedDetail(detailWidth);
1470
- const detailHeader = detail.header.slice(0, Math.max(0, this.bodyHeight - 1));
1471
- this.detailViewportHeight = Math.max(1, this.bodyHeight - detailHeader.length);
1472
- this.detailLineCount = detail.body.length;
1473
- const maxDetailScroll = Math.max(0, detail.body.length - this.detailViewportHeight);
1474
- if (this.detailAutoFollow) this.detailScroll = maxDetailScroll;
1475
- else if (this.detailScroll > maxDetailScroll) this.detailScroll = maxDetailScroll;
1476
- const visibleDetails = [
1477
- ...detailHeader,
1478
- ...detail.body.slice(this.detailScroll, this.detailScroll + this.detailViewportHeight),
1479
- ];
1480
- const lines = [this.theme.fg("border", `╭${"─".repeat(innerWidth)}╮`)];
1481
- const selected = this.snapshot.items[this.selected];
1482
- const title = selected?.kind === "external"
1483
- ? ` ${this.theme.bold("Fleet inspector")} ${this.theme.fg("dim", "· external display-only")}`
1484
- : ` ${this.theme.bold("Subagent fleet inspector")} ${this.theme.fg("dim", "· live controls")}`;
1485
- const selectedStatus = selected
1486
- ? `${statusGlyph(selected, this.theme)} ${selected.agent} · ${selected.state} `
1487
- : this.theme.fg("dim", "no children ");
1488
- lines.push(this.theme.fg("border", "│") + rightAligned(title, selectedStatus, innerWidth) + this.theme.fg("border", "│"));
1489
- lines.push(this.theme.fg("border", `├${"─".repeat(rosterWidth)}┬${"─".repeat(detailWidth)}┤`));
1490
- for (let index = 0; index < this.bodyHeight; index++) {
1491
- lines.push(
1492
- this.theme.fg("border", "│")
1493
- + fit(roster[index] ?? "", rosterWidth)
1494
- + this.theme.fg("border", "│")
1495
- + fit(visibleDetails[index] ?? "", detailWidth)
1496
- + this.theme.fg("border", "│"),
1497
- );
1498
- }
1499
- lines.push(this.theme.fg("border", `├${"─".repeat(rosterWidth)}┴${"─".repeat(detailWidth)}┤`));
1500
- const position = this.snapshot.items.length ? `${this.selected + 1}/${this.snapshot.items.length}` : "0/0";
1501
- const footer = this.promptAuditOpen
1502
- ? ` j/k child · 1/2/3 view · g redo with guidance · c copy · wheel ↑↓ · Esc close Prompt Audit · ${position}`
1503
- : selected?.kind === "external"
1504
- ? ` ${bindingLabel(this.keybindings, "selectUp")}/${bindingLabel(this.keybindings, "selectDown")} job · display-only · ${bindingLabel(this.keybindings, "refresh")} refresh · wheel ↑↓ · ${bindingLabel(this.keybindings, "close")} close · ${position}`
1505
- : ` ${bindingLabel(this.keybindings, "selectUp")}/${bindingLabel(this.keybindings, "selectDown")} agent · p Prompt Audit · ${bindingLabel(this.keybindings, "inspect")} Inspect · ${bindingLabel(this.keybindings, "steer")} steer · ${bindingLabel(this.keybindings, "stop")} stop · ${bindingLabel(this.keybindings, "toggleTools")} tools · ${bindingLabel(this.keybindings, "toggleThinking")} thinking · ${bindingLabel(this.keybindings, "toggleRenderer")} view · ${bindingLabel(this.keybindings, "refresh")} refresh · wheel ↑↓ · ${bindingLabel(this.keybindings, "close")} close · ${position}`;
1506
- lines.push(this.theme.fg("border", "│") + fit(this.theme.fg("dim", footer), innerWidth) + this.theme.fg("border", "│"));
1507
- lines.push(this.theme.fg("border", `╰${"─".repeat(innerWidth)}╯`));
1508
- return lines.map((line) => truncateToWidth(line, width));
1509
- }
1510
-
1511
- invalidate(): void {
1512
- this.transcriptCache = undefined;
1513
- this.refresh();
1514
- }
1515
-
1516
- dispose(): void {
1517
- this.stopRefresh();
1518
- }
1519
- }
1520
-
1521
- export async function openSubagentFleet(ctx: ExtensionContext, state: SubagentState, options: FleetViewOptions = {}): Promise<void> {
1522
- const wasOpen = state.fleetInspectorOpen === true;
1523
- state.fleetInspectorOpen = true;
1524
- if (typeof ctx.ui.setWidget === "function") ctx.ui.setWidget(FLEET_STATUS_WIDGET_KEY, undefined);
1525
- const copyText = options.copyText ?? (async (text: string) => {
1526
- const module = await import("@earendil-works/pi-coding-agent");
1527
- const copyToClipboard = (module as { copyToClipboard?: (value: string) => Promise<void> | void }).copyToClipboard;
1528
- if (!copyToClipboard) throw new Error("Clipboard is unavailable in this Pi version.");
1529
- await copyToClipboard(text);
1530
- });
1531
- const actions = options.actions ?? {
1532
- steer: async (input: { runId: string; asyncDir: string; index?: number; message: string; mode: SteerDeliveryMode }) => {
1533
- const status = readStatus(input.asyncDir);
1534
- const liveWorkflowRunId = status?.mode === "workflow" && state.workflowControllers?.has(status.runId || input.runId)
1535
- ? status.runId || input.runId
1536
- : undefined;
1537
- if (liveWorkflowRunId) {
1538
- const route = state.foregroundControls.get(input.runId)?.parentWorkflowRunId === liveWorkflowRunId
1539
- ? resolveWorkflowForegroundSteeringTarget({ state, childRunId: input.runId, asyncDirRoot: options.asyncDirRoot ?? DIRS.async })
1540
- : resolveWorkflowForegroundSteeringTarget({ state, workflowRunId: liveWorkflowRunId, asyncDirRoot: options.asyncDirRoot ?? DIRS.async });
1541
- if (!route.ok) return { text: route.message, isError: true };
1542
- return firstToolResultText(await steerWorkflowForegroundTarget({ target: route.target, message: input.message, mode: input.mode, ...(input.index !== undefined ? { index: input.index } : {}) }), `Failed to steer foreground run ${input.runId}.`);
1543
- }
1544
- return firstToolResultText(await steerAsyncRun({
1545
- state,
1546
- runId: input.runId,
1547
- ...(input.index !== undefined ? { index: input.index } : {}),
1548
- message: input.message,
1549
- mode: input.mode,
1550
- location: { asyncDir: input.asyncDir, resolvedId: input.runId } as Parameters<typeof steerAsyncRun>[0]["location"],
1551
- }), `Failed to steer async run ${input.runId}.`);
1552
- },
1553
- stop: (input: { runId: string; asyncDir: string; index?: number }) => firstToolResultText(stopAsyncRun(state, input.runId, undefined, { asyncDir: input.asyncDir, resolvedId: input.runId }), `Failed to stop async run ${input.runId}.`),
1554
- inspect: async (input: { runId: string; asyncDir: string; index?: number }) => firstToolResultText(await handleInspectorAction("inspector.open", {
1555
- id: input.runId,
1556
- dir: input.asyncDir,
1557
- focus: true,
1558
- ...(input.index !== undefined ? { index: input.index } : {}),
1559
- }, {
1560
- state,
1561
- sessionRoots: state.trustedSessionRoots,
1562
- cwd: state.baseCwd,
1563
- ...(state.authorityPolicy ? { authorityPolicy: state.authorityPolicy } : {}),
1564
- ...(state.missionStoreConfig ? { missions: state.missionStoreConfig } : {}),
1565
- plugins: options.inspectorPlugins?.(),
1566
- ...(options.inspectorEnv ? { env: options.inspectorEnv } : {}),
1567
- }), `Failed to open inspector for async run ${input.runId}.`),
1568
- redoPrompt: async (input: { runId: string; index: number; guidance: string; control?: ForegroundRunControl }) => {
1569
- const control = input.control ?? state.foregroundControls.get(input.runId);
1570
- if (!control?.promptAuditRedo) return { text: "Redo is not available for this live child.", isError: true };
1571
- return control.promptAuditRedo(input.index, input.guidance);
1572
- },
1573
- } satisfies FleetActionHandlers;
1574
- // The fleet inspector is a user-initiated monitoring panel, not an
1575
- // agent-waiting prompt: claim the dialog span as silent.
1576
- emitUiSpanSilent(options.events, "fleet");
1577
- try {
1578
- await ctx.ui.custom<undefined>(
1579
- (tui, theme, _keybindings, done) => new SubagentFleetComponent(tui, theme, state, done, { ...options, actions, copyText }),
1580
- {
1581
- overlay: true,
1582
- overlayOptions: { anchor: "center", width: "95%", minWidth: 60, maxHeight: "85%", margin: 1 },
1583
- },
1584
- );
1585
- } finally {
1586
- state.fleetInspectorOpen = wasOpen;
1587
- }
1588
- }
1589
-
1590
- export interface OpenFleetFromStatusOptions {
1591
- itemKey?: string;
1592
- asyncDirRoot: string;
1593
- resultsDir: string;
1594
- fleetKeybindings?: FleetKeybindingsConfig;
1595
- /** Lazy inspector plugins, when the caller hosts inspector integration. */
1596
- inspectorPlugins?: () => readonly InspectorPlugin[];
1597
- }
1598
-
1599
- /**
1600
- * Opens the fleet inspector from the idle status widget, claiming the
1601
- * dialog as a silent span (pi-notify protocol). Shared by the status-widget
1602
- * path so the marker wiring is testable in one place.
1603
- */
1604
- export function openSubagentFleetFromStatus(
1605
- ctx: ExtensionContext,
1606
- state: SubagentState,
1607
- pi: ExtensionAPI,
1608
- options: OpenFleetFromStatusOptions,
1609
- ): Promise<void> {
1610
- return openSubagentFleet(ctx, state, {
1611
- initialKey: options.itemKey,
1612
- asyncDirRoot: options.asyncDirRoot,
1613
- resultsDir: options.resultsDir,
1614
- fleetKeybindings: options.fleetKeybindings,
1615
- ...(options.inspectorPlugins ? { inspectorPlugins: options.inspectorPlugins } : {}),
1616
- events: pi.events,
1617
- });
1618
- }