@e4779/pi-fabric 0.92.17-fork.3

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 (1044) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +181 -0
  3. package/THIRD_PARTY_NOTICES.md +33 -0
  4. package/dist/activity/store.d.ts +33 -0
  5. package/dist/activity/store.d.ts.map +1 -0
  6. package/dist/activity/types.d.ts +104 -0
  7. package/dist/activity/types.d.ts.map +1 -0
  8. package/dist/actors/binding-store.d.ts +17 -0
  9. package/dist/actors/binding-store.d.ts.map +1 -0
  10. package/dist/actors/context.d.ts +13 -0
  11. package/dist/actors/context.d.ts.map +1 -0
  12. package/dist/actors/delivery-policy.d.ts +8 -0
  13. package/dist/actors/delivery-policy.d.ts.map +1 -0
  14. package/dist/actors/directory.d.ts +47 -0
  15. package/dist/actors/directory.d.ts.map +1 -0
  16. package/dist/actors/global-registry.d.ts +47 -0
  17. package/dist/actors/global-registry.d.ts.map +1 -0
  18. package/dist/actors/host-event-observer.d.ts +5 -0
  19. package/dist/actors/host-event-observer.d.ts.map +1 -0
  20. package/dist/actors/host-event-payload.d.ts +14 -0
  21. package/dist/actors/host-event-payload.d.ts.map +1 -0
  22. package/dist/actors/log-store.d.ts +22 -0
  23. package/dist/actors/log-store.d.ts.map +1 -0
  24. package/dist/actors/manager.d.ts +175 -0
  25. package/dist/actors/manager.d.ts.map +1 -0
  26. package/dist/actors/mesh-monitor.d.ts +22 -0
  27. package/dist/actors/mesh-monitor.d.ts.map +1 -0
  28. package/dist/actors/predicate.d.ts +7 -0
  29. package/dist/actors/predicate.d.ts.map +1 -0
  30. package/dist/actors/registry-store.d.ts +15 -0
  31. package/dist/actors/registry-store.d.ts.map +1 -0
  32. package/dist/actors/types.d.ts +218 -0
  33. package/dist/actors/types.d.ts.map +1 -0
  34. package/dist/agents/bash-worktree-add.d.ts +24 -0
  35. package/dist/agents/bash-worktree-add.d.ts.map +1 -0
  36. package/dist/agents/budget-ledger.d.ts +88 -0
  37. package/dist/agents/budget-ledger.d.ts.map +1 -0
  38. package/dist/agents/claude-cli.d.ts +32 -0
  39. package/dist/agents/claude-cli.d.ts.map +1 -0
  40. package/dist/agents/claude-cli.js +17 -0
  41. package/dist/agents/claude-cli.js.map +7 -0
  42. package/dist/agents/clone-first-worktree.d.ts +17 -0
  43. package/dist/agents/clone-first-worktree.d.ts.map +1 -0
  44. package/dist/agents/compact-control.d.ts +32 -0
  45. package/dist/agents/compact-control.d.ts.map +1 -0
  46. package/dist/agents/compact-control.js +129 -0
  47. package/dist/agents/compact-control.js.map +7 -0
  48. package/dist/agents/constants.d.ts +9 -0
  49. package/dist/agents/constants.d.ts.map +1 -0
  50. package/dist/agents/cow-clone.d.ts +8 -0
  51. package/dist/agents/cow-clone.d.ts.map +1 -0
  52. package/dist/agents/handoff-completion.d.ts +4 -0
  53. package/dist/agents/handoff-completion.d.ts.map +1 -0
  54. package/dist/agents/handoff.d.ts +19 -0
  55. package/dist/agents/handoff.d.ts.map +1 -0
  56. package/dist/agents/lifecycle.d.ts +32 -0
  57. package/dist/agents/lifecycle.d.ts.map +1 -0
  58. package/dist/agents/manager.d.ts +75 -0
  59. package/dist/agents/manager.d.ts.map +1 -0
  60. package/dist/agents/pi-binary.d.ts +7 -0
  61. package/dist/agents/pi-binary.d.ts.map +1 -0
  62. package/dist/agents/request.d.ts +13 -0
  63. package/dist/agents/request.d.ts.map +1 -0
  64. package/dist/agents/result.d.ts +8 -0
  65. package/dist/agents/result.d.ts.map +1 -0
  66. package/dist/agents/result.js +9 -0
  67. package/dist/agents/result.js.map +7 -0
  68. package/dist/agents/rm.d.ts +15 -0
  69. package/dist/agents/rm.d.ts.map +1 -0
  70. package/dist/agents/semaphore.d.ts +7 -0
  71. package/dist/agents/semaphore.d.ts.map +1 -0
  72. package/dist/agents/service-provider.d.ts +9 -0
  73. package/dist/agents/service-provider.d.ts.map +1 -0
  74. package/dist/agents/service-schema.d.ts +6 -0
  75. package/dist/agents/service-schema.d.ts.map +1 -0
  76. package/dist/agents/service-types.d.ts +192 -0
  77. package/dist/agents/service-types.d.ts.map +1 -0
  78. package/dist/agents/service.d.ts +36 -0
  79. package/dist/agents/service.d.ts.map +1 -0
  80. package/dist/agents/session-export.d.ts +39 -0
  81. package/dist/agents/session-export.d.ts.map +1 -0
  82. package/dist/agents/session-pins.d.ts +24 -0
  83. package/dist/agents/session-pins.d.ts.map +1 -0
  84. package/dist/agents/thinking-transfer.d.ts +39 -0
  85. package/dist/agents/thinking-transfer.d.ts.map +1 -0
  86. package/dist/agents/transports/herdr-transport.d.ts +10 -0
  87. package/dist/agents/transports/herdr-transport.d.ts.map +1 -0
  88. package/dist/agents/transports/localterm-transport.d.ts +7 -0
  89. package/dist/agents/transports/localterm-transport.d.ts.map +1 -0
  90. package/dist/agents/transports/process-transport.d.ts +7 -0
  91. package/dist/agents/transports/process-transport.d.ts.map +1 -0
  92. package/dist/agents/transports/process-utils.d.ts +33 -0
  93. package/dist/agents/transports/process-utils.d.ts.map +1 -0
  94. package/dist/agents/transports/screen-transport.d.ts +7 -0
  95. package/dist/agents/transports/screen-transport.d.ts.map +1 -0
  96. package/dist/agents/transports/tmux-transport.d.ts +7 -0
  97. package/dist/agents/transports/tmux-transport.d.ts.map +1 -0
  98. package/dist/agents/types.d.ts +280 -0
  99. package/dist/agents/types.d.ts.map +1 -0
  100. package/dist/agents/veda-cli.d.ts +22 -0
  101. package/dist/agents/veda-cli.d.ts.map +1 -0
  102. package/dist/agents/veda-cli.js +13 -0
  103. package/dist/agents/veda-cli.js.map +7 -0
  104. package/dist/agents/worktree-manager.d.ts +14 -0
  105. package/dist/agents/worktree-manager.d.ts.map +1 -0
  106. package/dist/agents/worktree-paths.d.ts +5 -0
  107. package/dist/agents/worktree-paths.d.ts.map +1 -0
  108. package/dist/agents.d.ts +8 -0
  109. package/dist/agents.d.ts.map +1 -0
  110. package/dist/agents.js +761 -0
  111. package/dist/agents.js.map +7 -0
  112. package/dist/async-settlement.d.ts +4 -0
  113. package/dist/async-settlement.d.ts.map +1 -0
  114. package/dist/audit/details.d.ts +86 -0
  115. package/dist/audit/details.d.ts.map +1 -0
  116. package/dist/audit/index.d.ts +4 -0
  117. package/dist/audit/index.d.ts.map +1 -0
  118. package/dist/audit/projection.d.ts +20 -0
  119. package/dist/audit/projection.d.ts.map +1 -0
  120. package/dist/audit/trace.d.ts +99 -0
  121. package/dist/audit/trace.d.ts.map +1 -0
  122. package/dist/capture/catalog.d.ts +30 -0
  123. package/dist/capture/catalog.d.ts.map +1 -0
  124. package/dist/capture/interceptor.d.ts +20 -0
  125. package/dist/capture/interceptor.d.ts.map +1 -0
  126. package/dist/capture/wrapper.d.ts +15 -0
  127. package/dist/capture/wrapper.d.ts.map +1 -0
  128. package/dist/chunks/chunk-2DMJ7MEI.js +1984 -0
  129. package/dist/chunks/chunk-2DMJ7MEI.js.map +7 -0
  130. package/dist/chunks/chunk-2PZWDVJB.js +738 -0
  131. package/dist/chunks/chunk-2PZWDVJB.js.map +7 -0
  132. package/dist/chunks/chunk-2UQV52II.js +440 -0
  133. package/dist/chunks/chunk-2UQV52II.js.map +7 -0
  134. package/dist/chunks/chunk-32BNQ75J.js +1445 -0
  135. package/dist/chunks/chunk-32BNQ75J.js.map +7 -0
  136. package/dist/chunks/chunk-3H7SDWZI.js +467 -0
  137. package/dist/chunks/chunk-3H7SDWZI.js.map +7 -0
  138. package/dist/chunks/chunk-3MEHEH6B.js +41 -0
  139. package/dist/chunks/chunk-3MEHEH6B.js.map +7 -0
  140. package/dist/chunks/chunk-3QECYQGA.js +70 -0
  141. package/dist/chunks/chunk-3QECYQGA.js.map +7 -0
  142. package/dist/chunks/chunk-3WIGAX56.js +644 -0
  143. package/dist/chunks/chunk-3WIGAX56.js.map +7 -0
  144. package/dist/chunks/chunk-3YZUQESG.js +16 -0
  145. package/dist/chunks/chunk-3YZUQESG.js.map +7 -0
  146. package/dist/chunks/chunk-4JETKRFE.js +287 -0
  147. package/dist/chunks/chunk-4JETKRFE.js.map +7 -0
  148. package/dist/chunks/chunk-4SSMGBF4.js +93 -0
  149. package/dist/chunks/chunk-4SSMGBF4.js.map +7 -0
  150. package/dist/chunks/chunk-5SU3YXBS.js +15 -0
  151. package/dist/chunks/chunk-5SU3YXBS.js.map +7 -0
  152. package/dist/chunks/chunk-656HWVFU.js +409 -0
  153. package/dist/chunks/chunk-656HWVFU.js.map +7 -0
  154. package/dist/chunks/chunk-7A6NVHB5.js +1242 -0
  155. package/dist/chunks/chunk-7A6NVHB5.js.map +7 -0
  156. package/dist/chunks/chunk-7TB7NXSL.js +58 -0
  157. package/dist/chunks/chunk-7TB7NXSL.js.map +7 -0
  158. package/dist/chunks/chunk-AAHHYDTO.js +24 -0
  159. package/dist/chunks/chunk-AAHHYDTO.js.map +7 -0
  160. package/dist/chunks/chunk-ARLYAW2A.js +95 -0
  161. package/dist/chunks/chunk-ARLYAW2A.js.map +7 -0
  162. package/dist/chunks/chunk-AYBIR4YV.js +210 -0
  163. package/dist/chunks/chunk-AYBIR4YV.js.map +7 -0
  164. package/dist/chunks/chunk-BOTRGFQQ.js +87 -0
  165. package/dist/chunks/chunk-BOTRGFQQ.js.map +7 -0
  166. package/dist/chunks/chunk-CGPK5WHX.js +96 -0
  167. package/dist/chunks/chunk-CGPK5WHX.js.map +7 -0
  168. package/dist/chunks/chunk-CI56CW53.js +470 -0
  169. package/dist/chunks/chunk-CI56CW53.js.map +7 -0
  170. package/dist/chunks/chunk-CPSW2GW4.js +1466 -0
  171. package/dist/chunks/chunk-CPSW2GW4.js.map +7 -0
  172. package/dist/chunks/chunk-CQFP2RCP.js +64 -0
  173. package/dist/chunks/chunk-CQFP2RCP.js.map +7 -0
  174. package/dist/chunks/chunk-D5WKZONW.js +797 -0
  175. package/dist/chunks/chunk-D5WKZONW.js.map +7 -0
  176. package/dist/chunks/chunk-DLXPTBPL.js +151 -0
  177. package/dist/chunks/chunk-DLXPTBPL.js.map +7 -0
  178. package/dist/chunks/chunk-G4LADAYY.js +287 -0
  179. package/dist/chunks/chunk-G4LADAYY.js.map +7 -0
  180. package/dist/chunks/chunk-GXNR6NRU.js +447 -0
  181. package/dist/chunks/chunk-GXNR6NRU.js.map +7 -0
  182. package/dist/chunks/chunk-IGVDD2HT.js +10 -0
  183. package/dist/chunks/chunk-IGVDD2HT.js.map +7 -0
  184. package/dist/chunks/chunk-J2HV2URQ.js +1125 -0
  185. package/dist/chunks/chunk-J2HV2URQ.js.map +7 -0
  186. package/dist/chunks/chunk-KAD7UWT2.js +99 -0
  187. package/dist/chunks/chunk-KAD7UWT2.js.map +7 -0
  188. package/dist/chunks/chunk-KYXZJNV6.js +227 -0
  189. package/dist/chunks/chunk-KYXZJNV6.js.map +7 -0
  190. package/dist/chunks/chunk-LMAVZN7J.js +8 -0
  191. package/dist/chunks/chunk-LMAVZN7J.js.map +7 -0
  192. package/dist/chunks/chunk-M3S7XITB.js +110 -0
  193. package/dist/chunks/chunk-M3S7XITB.js.map +7 -0
  194. package/dist/chunks/chunk-MGDLRV2R.js +112 -0
  195. package/dist/chunks/chunk-MGDLRV2R.js.map +7 -0
  196. package/dist/chunks/chunk-MGWQOKBV.js +30 -0
  197. package/dist/chunks/chunk-MGWQOKBV.js.map +7 -0
  198. package/dist/chunks/chunk-N5GUXC6F.js +184 -0
  199. package/dist/chunks/chunk-N5GUXC6F.js.map +7 -0
  200. package/dist/chunks/chunk-NQOEHX62.js +215 -0
  201. package/dist/chunks/chunk-NQOEHX62.js.map +7 -0
  202. package/dist/chunks/chunk-OKOHRXGF.js +100 -0
  203. package/dist/chunks/chunk-OKOHRXGF.js.map +7 -0
  204. package/dist/chunks/chunk-OP2KTYQB.js +286 -0
  205. package/dist/chunks/chunk-OP2KTYQB.js.map +7 -0
  206. package/dist/chunks/chunk-OTCASLY2.js +52 -0
  207. package/dist/chunks/chunk-OTCASLY2.js.map +7 -0
  208. package/dist/chunks/chunk-PAN6C3JM.js +42 -0
  209. package/dist/chunks/chunk-PAN6C3JM.js.map +7 -0
  210. package/dist/chunks/chunk-PH7ZJ27F.js +6873 -0
  211. package/dist/chunks/chunk-PH7ZJ27F.js.map +7 -0
  212. package/dist/chunks/chunk-PM5I335G.js +225 -0
  213. package/dist/chunks/chunk-PM5I335G.js.map +7 -0
  214. package/dist/chunks/chunk-PSNXUZMY.js +218 -0
  215. package/dist/chunks/chunk-PSNXUZMY.js.map +7 -0
  216. package/dist/chunks/chunk-PXAICAUT.js +24 -0
  217. package/dist/chunks/chunk-PXAICAUT.js.map +7 -0
  218. package/dist/chunks/chunk-RERA6YWA.js +359 -0
  219. package/dist/chunks/chunk-RERA6YWA.js.map +7 -0
  220. package/dist/chunks/chunk-RNOPHITP.js +1720 -0
  221. package/dist/chunks/chunk-RNOPHITP.js.map +7 -0
  222. package/dist/chunks/chunk-RRGTKHXZ.js +931 -0
  223. package/dist/chunks/chunk-RRGTKHXZ.js.map +7 -0
  224. package/dist/chunks/chunk-SWB2OHYW.js +93 -0
  225. package/dist/chunks/chunk-SWB2OHYW.js.map +7 -0
  226. package/dist/chunks/chunk-T3A5GNCW.js +19 -0
  227. package/dist/chunks/chunk-T3A5GNCW.js.map +7 -0
  228. package/dist/chunks/chunk-TPLMVELH.js +118 -0
  229. package/dist/chunks/chunk-TPLMVELH.js.map +7 -0
  230. package/dist/chunks/chunk-TSRKCXNI.js +17 -0
  231. package/dist/chunks/chunk-TSRKCXNI.js.map +7 -0
  232. package/dist/chunks/chunk-U5FYOMG5.js +119 -0
  233. package/dist/chunks/chunk-U5FYOMG5.js.map +7 -0
  234. package/dist/chunks/chunk-U6CTHPZC.js +1924 -0
  235. package/dist/chunks/chunk-U6CTHPZC.js.map +7 -0
  236. package/dist/chunks/chunk-UDFDF7IY.js +1572 -0
  237. package/dist/chunks/chunk-UDFDF7IY.js.map +7 -0
  238. package/dist/chunks/chunk-UKMQK5VP.js +231 -0
  239. package/dist/chunks/chunk-UKMQK5VP.js.map +7 -0
  240. package/dist/chunks/chunk-UQ4LTUH4.js +2181 -0
  241. package/dist/chunks/chunk-UQ4LTUH4.js.map +7 -0
  242. package/dist/chunks/chunk-UTR3I23Z.js +65 -0
  243. package/dist/chunks/chunk-UTR3I23Z.js.map +7 -0
  244. package/dist/chunks/chunk-VPPIJRNZ.js +50 -0
  245. package/dist/chunks/chunk-VPPIJRNZ.js.map +7 -0
  246. package/dist/chunks/chunk-VRYEGVHR.js +195 -0
  247. package/dist/chunks/chunk-VRYEGVHR.js.map +7 -0
  248. package/dist/chunks/chunk-VRZNFNPB.js +4218 -0
  249. package/dist/chunks/chunk-VRZNFNPB.js.map +7 -0
  250. package/dist/chunks/chunk-VXZZJ44D.js +295 -0
  251. package/dist/chunks/chunk-VXZZJ44D.js.map +7 -0
  252. package/dist/chunks/chunk-W3FRE4VI.js +297 -0
  253. package/dist/chunks/chunk-W3FRE4VI.js.map +7 -0
  254. package/dist/chunks/chunk-WVH324VF.js +60 -0
  255. package/dist/chunks/chunk-WVH324VF.js.map +7 -0
  256. package/dist/chunks/chunk-X7G62ZGH.js +151 -0
  257. package/dist/chunks/chunk-X7G62ZGH.js.map +7 -0
  258. package/dist/chunks/chunk-XB3RJVT4.js +17 -0
  259. package/dist/chunks/chunk-XB3RJVT4.js.map +7 -0
  260. package/dist/chunks/chunk-XT4346N7.js +651 -0
  261. package/dist/chunks/chunk-XT4346N7.js.map +7 -0
  262. package/dist/chunks/chunk-Y7KNRAFL.js +1180 -0
  263. package/dist/chunks/chunk-Y7KNRAFL.js.map +7 -0
  264. package/dist/chunks/chunk-YK5AZ7CZ.js +692 -0
  265. package/dist/chunks/chunk-YK5AZ7CZ.js.map +7 -0
  266. package/dist/chunks/chunk-YU4O6SWQ.js +246 -0
  267. package/dist/chunks/chunk-YU4O6SWQ.js.map +7 -0
  268. package/dist/chunks/chunk-YU62DDKK.js +22 -0
  269. package/dist/chunks/chunk-YU62DDKK.js.map +7 -0
  270. package/dist/chunks/chunk-Z63R5GVN.js +121 -0
  271. package/dist/chunks/chunk-Z63R5GVN.js.map +7 -0
  272. package/dist/chunks/chunk-ZDNGXLEC.js +221 -0
  273. package/dist/chunks/chunk-ZDNGXLEC.js.map +7 -0
  274. package/dist/chunks/chunk-ZZ4LHQYJ.js +777 -0
  275. package/dist/chunks/chunk-ZZ4LHQYJ.js.map +7 -0
  276. package/dist/commands/fabric.d.ts +17 -0
  277. package/dist/commands/fabric.d.ts.map +1 -0
  278. package/dist/compaction/bounds.d.ts +23 -0
  279. package/dist/compaction/bounds.d.ts.map +1 -0
  280. package/dist/compaction/branch-details.d.ts +83 -0
  281. package/dist/compaction/branch-details.d.ts.map +1 -0
  282. package/dist/compaction/branch-summary.d.ts +9 -0
  283. package/dist/compaction/branch-summary.d.ts.map +1 -0
  284. package/dist/compaction/enrichers.d.ts +10 -0
  285. package/dist/compaction/enrichers.d.ts.map +1 -0
  286. package/dist/compaction/hook.d.ts +99 -0
  287. package/dist/compaction/hook.d.ts.map +1 -0
  288. package/dist/compaction/hook.js +22 -0
  289. package/dist/compaction/hook.js.map +7 -0
  290. package/dist/compaction/instructions.d.ts +38 -0
  291. package/dist/compaction/instructions.d.ts.map +1 -0
  292. package/dist/compaction/normalize.d.ts +83 -0
  293. package/dist/compaction/normalize.d.ts.map +1 -0
  294. package/dist/compaction/projections.d.ts +31 -0
  295. package/dist/compaction/projections.d.ts.map +1 -0
  296. package/dist/compaction/qa.d.ts +27 -0
  297. package/dist/compaction/qa.d.ts.map +1 -0
  298. package/dist/compaction/render.d.ts +10 -0
  299. package/dist/compaction/render.d.ts.map +1 -0
  300. package/dist/compaction/threshold.d.ts +5 -0
  301. package/dist/compaction/threshold.d.ts.map +1 -0
  302. package/dist/compaction/trace-events.d.ts +23 -0
  303. package/dist/compaction/trace-events.d.ts.map +1 -0
  304. package/dist/components/catalog.d.ts +25 -0
  305. package/dist/components/catalog.d.ts.map +1 -0
  306. package/dist/components/effect-policy.d.ts +21 -0
  307. package/dist/components/effect-policy.d.ts.map +1 -0
  308. package/dist/components/effect-scope.d.ts +31 -0
  309. package/dist/components/effect-scope.d.ts.map +1 -0
  310. package/dist/components/loader.d.ts +27 -0
  311. package/dist/components/loader.d.ts.map +1 -0
  312. package/dist/components/model-guidance.d.ts +48 -0
  313. package/dist/components/model-guidance.d.ts.map +1 -0
  314. package/dist/components/provider-component.d.ts +31 -0
  315. package/dist/components/provider-component.d.ts.map +1 -0
  316. package/dist/components/supervisor.d.ts +29 -0
  317. package/dist/components/supervisor.d.ts.map +1 -0
  318. package/dist/components/types.d.ts +140 -0
  319. package/dist/components/types.d.ts.map +1 -0
  320. package/dist/config-migrations.d.ts +11 -0
  321. package/dist/config-migrations.d.ts.map +1 -0
  322. package/dist/config.d.ts +282 -0
  323. package/dist/config.d.ts.map +1 -0
  324. package/dist/core/action-arguments.d.ts +12 -0
  325. package/dist/core/action-arguments.d.ts.map +1 -0
  326. package/dist/core/action-registry.d.ts +170 -0
  327. package/dist/core/action-registry.d.ts.map +1 -0
  328. package/dist/core/action-registry.js +20 -0
  329. package/dist/core/action-registry.js.map +7 -0
  330. package/dist/core/action-repair.d.ts +15 -0
  331. package/dist/core/action-repair.d.ts.map +1 -0
  332. package/dist/core/action-result.d.ts +13 -0
  333. package/dist/core/action-result.d.ts.map +1 -0
  334. package/dist/core/agent-dir.d.ts +2 -0
  335. package/dist/core/agent-dir.d.ts.map +1 -0
  336. package/dist/core/approval-controller.d.ts +31 -0
  337. package/dist/core/approval-controller.d.ts.map +1 -0
  338. package/dist/core/atomic-write.d.ts +15 -0
  339. package/dist/core/atomic-write.d.ts.map +1 -0
  340. package/dist/core/auto-approval-classifier.d.ts +17 -0
  341. package/dist/core/auto-approval-classifier.d.ts.map +1 -0
  342. package/dist/core/call-preview.d.ts +8 -0
  343. package/dist/core/call-preview.d.ts.map +1 -0
  344. package/dist/core/child-tool-allowlist.d.ts +3 -0
  345. package/dist/core/child-tool-allowlist.d.ts.map +1 -0
  346. package/dist/core/compact-controller.d.ts +42 -0
  347. package/dist/core/compact-controller.d.ts.map +1 -0
  348. package/dist/core/core-override-guidance.d.ts +7 -0
  349. package/dist/core/core-override-guidance.d.ts.map +1 -0
  350. package/dist/core/damaged-file.d.ts +6 -0
  351. package/dist/core/damaged-file.d.ts.map +1 -0
  352. package/dist/core/direct-tool-approval.d.ts +19 -0
  353. package/dist/core/direct-tool-approval.d.ts.map +1 -0
  354. package/dist/core/effect-conflict.d.ts +3 -0
  355. package/dist/core/effect-conflict.d.ts.map +1 -0
  356. package/dist/core/file-lock.d.ts +12 -0
  357. package/dist/core/file-lock.d.ts.map +1 -0
  358. package/dist/core/kernel-skills.d.ts +3 -0
  359. package/dist/core/kernel-skills.d.ts.map +1 -0
  360. package/dist/core/model-resolution.d.ts +62 -0
  361. package/dist/core/model-resolution.d.ts.map +1 -0
  362. package/dist/core/model-usage.d.ts +8 -0
  363. package/dist/core/model-usage.d.ts.map +1 -0
  364. package/dist/core/pi-arguments.d.ts +3 -0
  365. package/dist/core/pi-arguments.d.ts.map +1 -0
  366. package/dist/core/pi-bash-error.d.ts +9 -0
  367. package/dist/core/pi-bash-error.d.ts.map +1 -0
  368. package/dist/core/pi-tools.d.ts +9 -0
  369. package/dist/core/pi-tools.d.ts.map +1 -0
  370. package/dist/core/provider-bindings.d.ts +47 -0
  371. package/dist/core/provider-bindings.d.ts.map +1 -0
  372. package/dist/core/proxy-contract.d.ts +18 -0
  373. package/dist/core/proxy-contract.d.ts.map +1 -0
  374. package/dist/core/session-context.d.ts +14 -0
  375. package/dist/core/session-context.d.ts.map +1 -0
  376. package/dist/core/shell-jobs.d.ts +99 -0
  377. package/dist/core/shell-jobs.d.ts.map +1 -0
  378. package/dist/core/skill-block.d.ts +10 -0
  379. package/dist/core/skill-block.d.ts.map +1 -0
  380. package/dist/core/skill-dir.d.ts +4 -0
  381. package/dist/core/skill-dir.d.ts.map +1 -0
  382. package/dist/core/skill-prompt.d.ts +3 -0
  383. package/dist/core/skill-prompt.d.ts.map +1 -0
  384. package/dist/core/skill-references.d.ts +7 -0
  385. package/dist/core/skill-references.d.ts.map +1 -0
  386. package/dist/core/stable-hash.d.ts +3 -0
  387. package/dist/core/stable-hash.d.ts.map +1 -0
  388. package/dist/core/system-guidance.d.ts +13 -0
  389. package/dist/core/system-guidance.d.ts.map +1 -0
  390. package/dist/core/token-math.d.ts +16 -0
  391. package/dist/core/token-math.d.ts.map +1 -0
  392. package/dist/core/tool-ownership.d.ts +47 -0
  393. package/dist/core/tool-ownership.d.ts.map +1 -0
  394. package/dist/core/tool-result-proxy.d.ts +18 -0
  395. package/dist/core/tool-result-proxy.d.ts.map +1 -0
  396. package/dist/entropy/active.d.ts +9 -0
  397. package/dist/entropy/active.d.ts.map +1 -0
  398. package/dist/entropy/compiled-store.d.ts +16 -0
  399. package/dist/entropy/compiled-store.d.ts.map +1 -0
  400. package/dist/entropy/compiled-surface.d.ts +57 -0
  401. package/dist/entropy/compiled-surface.d.ts.map +1 -0
  402. package/dist/entropy/compiler.d.ts +27 -0
  403. package/dist/entropy/compiler.d.ts.map +1 -0
  404. package/dist/entropy/corpus.d.ts +22 -0
  405. package/dist/entropy/corpus.d.ts.map +1 -0
  406. package/dist/entropy/fingerprint.d.ts +9 -0
  407. package/dist/entropy/fingerprint.d.ts.map +1 -0
  408. package/dist/entropy/index.d.ts +16 -0
  409. package/dist/entropy/index.d.ts.map +1 -0
  410. package/dist/entropy/index.js +194 -0
  411. package/dist/entropy/index.js.map +7 -0
  412. package/dist/entropy/meter.d.ts +10 -0
  413. package/dist/entropy/meter.d.ts.map +1 -0
  414. package/dist/entropy/normal-form.d.ts +40 -0
  415. package/dist/entropy/normal-form.d.ts.map +1 -0
  416. package/dist/entropy/passes.d.ts +13 -0
  417. package/dist/entropy/passes.d.ts.map +1 -0
  418. package/dist/entropy/pool-store.d.ts +15 -0
  419. package/dist/entropy/pool-store.d.ts.map +1 -0
  420. package/dist/entropy/pool.d.ts +41 -0
  421. package/dist/entropy/pool.d.ts.map +1 -0
  422. package/dist/entropy/presentation.d.ts +12 -0
  423. package/dist/entropy/presentation.d.ts.map +1 -0
  424. package/dist/entropy/sessions.d.ts +47 -0
  425. package/dist/entropy/sessions.d.ts.map +1 -0
  426. package/dist/entropy/surface.d.ts +30 -0
  427. package/dist/entropy/surface.d.ts.map +1 -0
  428. package/dist/entropy/trial.d.ts +38 -0
  429. package/dist/entropy/trial.d.ts.map +1 -0
  430. package/dist/entropy/types.d.ts +181 -0
  431. package/dist/entropy/types.d.ts.map +1 -0
  432. package/dist/execution-service.d.ts +66 -0
  433. package/dist/execution-service.d.ts.map +1 -0
  434. package/dist/fabric-exec-arguments.d.ts +7 -0
  435. package/dist/fabric-exec-arguments.d.ts.map +1 -0
  436. package/dist/fabric-exec-tool.d.ts +8 -0
  437. package/dist/fabric-exec-tool.d.ts.map +1 -0
  438. package/dist/fabric-runtime-state.d.ts +96 -0
  439. package/dist/fabric-runtime-state.d.ts.map +1 -0
  440. package/dist/fabric-runtime-state.js +11928 -0
  441. package/dist/fabric-runtime-state.js.map +7 -0
  442. package/dist/fabric-state.d.ts +95 -0
  443. package/dist/fabric-state.d.ts.map +1 -0
  444. package/dist/failure-progress.d.ts +3 -0
  445. package/dist/failure-progress.d.ts.map +1 -0
  446. package/dist/host-compatibility.d.ts +5 -0
  447. package/dist/host-compatibility.d.ts.map +1 -0
  448. package/dist/index.d.ts +11 -0
  449. package/dist/index.d.ts.map +1 -0
  450. package/dist/index.js +6094 -0
  451. package/dist/index.js.map +7 -0
  452. package/dist/jev/auth.d.ts +5 -0
  453. package/dist/jev/auth.d.ts.map +1 -0
  454. package/dist/jev/browser.d.ts +37 -0
  455. package/dist/jev/browser.d.ts.map +1 -0
  456. package/dist/jev/browser.js +13 -0
  457. package/dist/jev/browser.js.map +7 -0
  458. package/dist/jev/client.d.ts +29 -0
  459. package/dist/jev/client.d.ts.map +1 -0
  460. package/dist/jev/client.js +11 -0
  461. package/dist/jev/client.js.map +7 -0
  462. package/dist/jev/config.d.ts +17 -0
  463. package/dist/jev/config.d.ts.map +1 -0
  464. package/dist/jev/guest-types.d.ts +2 -0
  465. package/dist/jev/guest-types.d.ts.map +1 -0
  466. package/dist/jev/manager.d.ts +36 -0
  467. package/dist/jev/manager.d.ts.map +1 -0
  468. package/dist/jev/observation.d.ts +59 -0
  469. package/dist/jev/observation.d.ts.map +1 -0
  470. package/dist/jev/observation.js +20 -0
  471. package/dist/jev/observation.js.map +7 -0
  472. package/dist/jev/types.d.ts +142 -0
  473. package/dist/jev/types.d.ts.map +1 -0
  474. package/dist/jev/validation.d.ts +8 -0
  475. package/dist/jev/validation.d.ts.map +1 -0
  476. package/dist/jev.d.ts +9 -0
  477. package/dist/jev.d.ts.map +1 -0
  478. package/dist/jev.js +49 -0
  479. package/dist/jev.js.map +7 -0
  480. package/dist/lifecycle/broker.d.ts +30 -0
  481. package/dist/lifecycle/broker.d.ts.map +1 -0
  482. package/dist/lifecycle/delivery-scheduler.d.ts +30 -0
  483. package/dist/lifecycle/delivery-scheduler.d.ts.map +1 -0
  484. package/dist/lifecycle/types.d.ts +91 -0
  485. package/dist/lifecycle/types.d.ts.map +1 -0
  486. package/dist/log-tail.d.ts +11 -0
  487. package/dist/log-tail.d.ts.map +1 -0
  488. package/dist/main-agent.d.ts +70 -0
  489. package/dist/main-agent.d.ts.map +1 -0
  490. package/dist/managed-host.d.ts +22 -0
  491. package/dist/managed-host.d.ts.map +1 -0
  492. package/dist/mcp.d.ts +9 -0
  493. package/dist/mcp.d.ts.map +1 -0
  494. package/dist/mcp.js +21 -0
  495. package/dist/mcp.js.map +7 -0
  496. package/dist/memory/client.d.ts +31 -0
  497. package/dist/memory/client.d.ts.map +1 -0
  498. package/dist/memory/context.d.ts +114 -0
  499. package/dist/memory/context.d.ts.map +1 -0
  500. package/dist/memory/digest.d.ts +48 -0
  501. package/dist/memory/digest.d.ts.map +1 -0
  502. package/dist/memory/digest.js +7 -0
  503. package/dist/memory/digest.js.map +7 -0
  504. package/dist/memory/discovery.d.ts +43 -0
  505. package/dist/memory/discovery.d.ts.map +1 -0
  506. package/dist/memory/discovery.js +25 -0
  507. package/dist/memory/discovery.js.map +7 -0
  508. package/dist/memory/expand-service.d.ts +4 -0
  509. package/dist/memory/expand-service.d.ts.map +1 -0
  510. package/dist/memory/host-source.d.ts +60 -0
  511. package/dist/memory/host-source.d.ts.map +1 -0
  512. package/dist/memory/index.d.ts +113 -0
  513. package/dist/memory/index.d.ts.map +1 -0
  514. package/dist/memory/lineage.d.ts +25 -0
  515. package/dist/memory/lineage.d.ts.map +1 -0
  516. package/dist/memory/normalize.d.ts +188 -0
  517. package/dist/memory/normalize.d.ts.map +1 -0
  518. package/dist/memory/normalize.js +26 -0
  519. package/dist/memory/normalize.js.map +7 -0
  520. package/dist/memory/portable.d.ts +66 -0
  521. package/dist/memory/portable.d.ts.map +1 -0
  522. package/dist/memory/provider.d.ts +15 -0
  523. package/dist/memory/provider.d.ts.map +1 -0
  524. package/dist/memory/recall-service.d.ts +5 -0
  525. package/dist/memory/recall-service.d.ts.map +1 -0
  526. package/dist/memory/regex.d.ts +19 -0
  527. package/dist/memory/regex.d.ts.map +1 -0
  528. package/dist/memory/request-cache.d.ts +49 -0
  529. package/dist/memory/request-cache.d.ts.map +1 -0
  530. package/dist/memory/request-context.d.ts +57 -0
  531. package/dist/memory/request-context.d.ts.map +1 -0
  532. package/dist/memory/request-limits.d.ts +8 -0
  533. package/dist/memory/request-limits.d.ts.map +1 -0
  534. package/dist/memory/search.d.ts +98 -0
  535. package/dist/memory/search.d.ts.map +1 -0
  536. package/dist/memory/search.js +24 -0
  537. package/dist/memory/search.js.map +7 -0
  538. package/dist/memory/sessions-service.d.ts +3 -0
  539. package/dist/memory/sessions-service.d.ts.map +1 -0
  540. package/dist/memory/source-observation.d.ts +28 -0
  541. package/dist/memory/source-observation.d.ts.map +1 -0
  542. package/dist/memory/tokenize.d.ts +24 -0
  543. package/dist/memory/tokenize.d.ts.map +1 -0
  544. package/dist/memory.d.ts +8 -0
  545. package/dist/memory.d.ts.map +1 -0
  546. package/dist/memory.js +119 -0
  547. package/dist/memory.js.map +7 -0
  548. package/dist/mesh/store.d.ts +78 -0
  549. package/dist/mesh/store.d.ts.map +1 -0
  550. package/dist/output-budget.d.ts +12 -0
  551. package/dist/output-budget.d.ts.map +1 -0
  552. package/dist/prewalk/arm.d.ts +8 -0
  553. package/dist/prewalk/arm.d.ts.map +1 -0
  554. package/dist/prewalk/controller.d.ts +66 -0
  555. package/dist/prewalk/controller.d.ts.map +1 -0
  556. package/dist/prewalk/fs-drift.d.ts +19 -0
  557. package/dist/prewalk/fs-drift.d.ts.map +1 -0
  558. package/dist/prewalk/handoff.d.ts +46 -0
  559. package/dist/prewalk/handoff.d.ts.map +1 -0
  560. package/dist/protocol.d.ts +275 -0
  561. package/dist/protocol.d.ts.map +1 -0
  562. package/dist/protocol.js +46 -0
  563. package/dist/protocol.js.map +7 -0
  564. package/dist/providers/agents-actions.d.ts +3 -0
  565. package/dist/providers/agents-actions.d.ts.map +1 -0
  566. package/dist/providers/agents-message-router.d.ts +29 -0
  567. package/dist/providers/agents-message-router.d.ts.map +1 -0
  568. package/dist/providers/agents-progress.d.ts +18 -0
  569. package/dist/providers/agents-progress.d.ts.map +1 -0
  570. package/dist/providers/agents-provider.d.ts +51 -0
  571. package/dist/providers/agents-provider.d.ts.map +1 -0
  572. package/dist/providers/arg-normalization.d.ts +15 -0
  573. package/dist/providers/arg-normalization.d.ts.map +1 -0
  574. package/dist/providers/captured-tools-provider.d.ts +23 -0
  575. package/dist/providers/captured-tools-provider.d.ts.map +1 -0
  576. package/dist/providers/compact-provider.d.ts +14 -0
  577. package/dist/providers/compact-provider.d.ts.map +1 -0
  578. package/dist/providers/components-provider.d.ts +12 -0
  579. package/dist/providers/components-provider.d.ts.map +1 -0
  580. package/dist/providers/jev-provider.d.ts +70 -0
  581. package/dist/providers/jev-provider.d.ts.map +1 -0
  582. package/dist/providers/jev-provider.js +28 -0
  583. package/dist/providers/jev-provider.js.map +7 -0
  584. package/dist/providers/mcp-descriptor-cache.d.ts +47 -0
  585. package/dist/providers/mcp-descriptor-cache.d.ts.map +1 -0
  586. package/dist/providers/mcp-provider.d.ts +47 -0
  587. package/dist/providers/mcp-provider.d.ts.map +1 -0
  588. package/dist/providers/memory-provider.d.ts +32 -0
  589. package/dist/providers/memory-provider.d.ts.map +1 -0
  590. package/dist/providers/memory-provider.js +23 -0
  591. package/dist/providers/memory-provider.js.map +7 -0
  592. package/dist/providers/mesh-provider.d.ts +17 -0
  593. package/dist/providers/mesh-provider.d.ts.map +1 -0
  594. package/dist/providers/pi-bash-cwd.d.ts +49 -0
  595. package/dist/providers/pi-bash-cwd.d.ts.map +1 -0
  596. package/dist/providers/pi-tools-provider.d.ts +25 -0
  597. package/dist/providers/pi-tools-provider.d.ts.map +1 -0
  598. package/dist/providers/schema-provider.d.ts +15 -0
  599. package/dist/providers/schema-provider.d.ts.map +1 -0
  600. package/dist/providers/state-provider.d.ts +16 -0
  601. package/dist/providers/state-provider.d.ts.map +1 -0
  602. package/dist/providers/write-diff-limits.d.ts +5 -0
  603. package/dist/providers/write-diff-limits.d.ts.map +1 -0
  604. package/dist/providers/write-preview.d.ts +3 -0
  605. package/dist/providers/write-preview.d.ts.map +1 -0
  606. package/dist/ref-names.d.ts +2 -0
  607. package/dist/ref-names.d.ts.map +1 -0
  608. package/dist/repairs/active.d.ts +7 -0
  609. package/dist/repairs/active.d.ts.map +1 -0
  610. package/dist/repairs/apply.d.ts +7 -0
  611. package/dist/repairs/apply.d.ts.map +1 -0
  612. package/dist/repairs/catalog-digest.d.ts +5 -0
  613. package/dist/repairs/catalog-digest.d.ts.map +1 -0
  614. package/dist/repairs/classify.d.ts +10 -0
  615. package/dist/repairs/classify.d.ts.map +1 -0
  616. package/dist/repairs/compiler.d.ts +33 -0
  617. package/dist/repairs/compiler.d.ts.map +1 -0
  618. package/dist/repairs/promote.d.ts +4 -0
  619. package/dist/repairs/promote.d.ts.map +1 -0
  620. package/dist/repairs/store.d.ts +10 -0
  621. package/dist/repairs/store.d.ts.map +1 -0
  622. package/dist/repairs/types.d.ts +49 -0
  623. package/dist/repairs/types.d.ts.map +1 -0
  624. package/dist/repeat-guard.d.ts +25 -0
  625. package/dist/repeat-guard.d.ts.map +1 -0
  626. package/dist/residency/actor-client.d.ts +16 -0
  627. package/dist/residency/actor-client.d.ts.map +1 -0
  628. package/dist/residency/actor-client.js +9 -0
  629. package/dist/residency/actor-client.js.map +7 -0
  630. package/dist/residency/client.d.ts +44 -0
  631. package/dist/residency/client.d.ts.map +1 -0
  632. package/dist/residency/host.d.ts +3 -0
  633. package/dist/residency/host.d.ts.map +1 -0
  634. package/dist/residency/host.js +32 -0
  635. package/dist/residency/host.js.map +7 -0
  636. package/dist/residency/launcher-owner.d.ts +7 -0
  637. package/dist/residency/launcher-owner.d.ts.map +1 -0
  638. package/dist/residency/launcher.d.ts +3 -0
  639. package/dist/residency/launcher.d.ts.map +1 -0
  640. package/dist/residency/launcher.js +154 -0
  641. package/dist/residency/launcher.js.map +7 -0
  642. package/dist/residency/pi-entry.d.ts +3 -0
  643. package/dist/residency/pi-entry.d.ts.map +1 -0
  644. package/dist/residency/pi-entry.js +48 -0
  645. package/dist/residency/pi-entry.js.map +7 -0
  646. package/dist/residency/protocol.d.ts +122 -0
  647. package/dist/residency/protocol.d.ts.map +1 -0
  648. package/dist/run-display.d.ts +3 -0
  649. package/dist/run-display.d.ts.map +1 -0
  650. package/dist/runtime/core-override-guest-types.d.ts +15 -0
  651. package/dist/runtime/core-override-guest-types.d.ts.map +1 -0
  652. package/dist/runtime/core-override-guest-types.js +9 -0
  653. package/dist/runtime/core-override-guest-types.js.map +7 -0
  654. package/dist/runtime/core-tool-properties.d.ts +6 -0
  655. package/dist/runtime/core-tool-properties.d.ts.map +1 -0
  656. package/dist/runtime/cpython-child-source.d.ts +2 -0
  657. package/dist/runtime/cpython-child-source.d.ts.map +1 -0
  658. package/dist/runtime/cpython-linux-sandbox.d.ts +2 -0
  659. package/dist/runtime/cpython-linux-sandbox.d.ts.map +1 -0
  660. package/dist/runtime/cpython-runtime.d.ts +9 -0
  661. package/dist/runtime/cpython-runtime.d.ts.map +1 -0
  662. package/dist/runtime/cpython-runtime.js +677 -0
  663. package/dist/runtime/cpython-runtime.js.map +7 -0
  664. package/dist/runtime/dynamic-guest-types.d.ts +3 -0
  665. package/dist/runtime/dynamic-guest-types.d.ts.map +1 -0
  666. package/dist/runtime/dynamic-guest-types.js +8 -0
  667. package/dist/runtime/dynamic-guest-types.js.map +7 -0
  668. package/dist/runtime/guest-code-repair.d.ts +2 -0
  669. package/dist/runtime/guest-code-repair.d.ts.map +1 -0
  670. package/dist/runtime/guest-stack-map.d.ts +11 -0
  671. package/dist/runtime/guest-stack-map.d.ts.map +1 -0
  672. package/dist/runtime/guest-types.d.ts +40 -0
  673. package/dist/runtime/guest-types.d.ts.map +1 -0
  674. package/dist/runtime/guest-types.js +13 -0
  675. package/dist/runtime/guest-types.js.map +7 -0
  676. package/dist/runtime/kernel.d.ts +30 -0
  677. package/dist/runtime/kernel.d.ts.map +1 -0
  678. package/dist/runtime/monty-bridge.d.ts +4 -0
  679. package/dist/runtime/monty-bridge.d.ts.map +1 -0
  680. package/dist/runtime/monty-runtime.d.ts +6 -0
  681. package/dist/runtime/monty-runtime.d.ts.map +1 -0
  682. package/dist/runtime/monty-runtime.js +485 -0
  683. package/dist/runtime/monty-runtime.js.map +7 -0
  684. package/dist/runtime/monty-source.d.ts +10 -0
  685. package/dist/runtime/monty-source.d.ts.map +1 -0
  686. package/dist/runtime/monty-values.d.ts +7 -0
  687. package/dist/runtime/monty-values.d.ts.map +1 -0
  688. package/dist/runtime/node-process-child-source.d.ts +2 -0
  689. package/dist/runtime/node-process-child-source.d.ts.map +1 -0
  690. package/dist/runtime/node-process-runtime.d.ts +10 -0
  691. package/dist/runtime/node-process-runtime.d.ts.map +1 -0
  692. package/dist/runtime/node-process-runtime.js +16 -0
  693. package/dist/runtime/node-process-runtime.js.map +7 -0
  694. package/dist/runtime/orchestration.d.ts +3 -0
  695. package/dist/runtime/orchestration.d.ts.map +1 -0
  696. package/dist/runtime/python-arguments.d.ts +2 -0
  697. package/dist/runtime/python-arguments.d.ts.map +1 -0
  698. package/dist/runtime/python-error-guidance.d.ts +6 -0
  699. package/dist/runtime/python-error-guidance.d.ts.map +1 -0
  700. package/dist/runtime/quickjs-runtime.d.ts +8 -0
  701. package/dist/runtime/quickjs-runtime.d.ts.map +1 -0
  702. package/dist/runtime/quickjs-runtime.js +15 -0
  703. package/dist/runtime/quickjs-runtime.js.map +7 -0
  704. package/dist/runtime/type-checker.d.ts +18 -0
  705. package/dist/runtime/type-checker.d.ts.map +1 -0
  706. package/dist/runtime/type-checker.js +11 -0
  707. package/dist/runtime/type-checker.js.map +7 -0
  708. package/dist/runtime/typescript-kernel.d.ts +14 -0
  709. package/dist/runtime/typescript-kernel.d.ts.map +1 -0
  710. package/dist/runtime/typescript-kernel.js +53 -0
  711. package/dist/runtime/typescript-kernel.js.map +7 -0
  712. package/dist/runtime-paths.d.ts +7 -0
  713. package/dist/runtime-paths.d.ts.map +1 -0
  714. package/dist/runtime-state-builtins.d.ts +26 -0
  715. package/dist/runtime-state-builtins.d.ts.map +1 -0
  716. package/dist/runtime-state-speculation.d.ts +16 -0
  717. package/dist/runtime-state-speculation.d.ts.map +1 -0
  718. package/dist/schema/controller.d.ts +35 -0
  719. package/dist/schema/controller.d.ts.map +1 -0
  720. package/dist/schema/policy.d.ts +2 -0
  721. package/dist/schema/policy.d.ts.map +1 -0
  722. package/dist/schema/types.d.ts +86 -0
  723. package/dist/schema/types.d.ts.map +1 -0
  724. package/dist/schema/workspace.d.ts +19 -0
  725. package/dist/schema/workspace.d.ts.map +1 -0
  726. package/dist/speculation/eligibility.d.ts +22 -0
  727. package/dist/speculation/eligibility.d.ts.map +1 -0
  728. package/dist/speculation/freshness.d.ts +10 -0
  729. package/dist/speculation/freshness.d.ts.map +1 -0
  730. package/dist/speculation/partial-json.d.ts +9 -0
  731. package/dist/speculation/partial-json.d.ts.map +1 -0
  732. package/dist/speculation/python-scanner.d.ts +7 -0
  733. package/dist/speculation/python-scanner.d.ts.map +1 -0
  734. package/dist/speculation/python-scanner.js +166 -0
  735. package/dist/speculation/python-scanner.js.map +7 -0
  736. package/dist/speculation/scanner.d.ts +13 -0
  737. package/dist/speculation/scanner.d.ts.map +1 -0
  738. package/dist/speculation/scanner.js +182 -0
  739. package/dist/speculation/scanner.js.map +7 -0
  740. package/dist/speculation/store.d.ts +41 -0
  741. package/dist/speculation/store.d.ts.map +1 -0
  742. package/dist/speculation/stream-tap.d.ts +30 -0
  743. package/dist/speculation/stream-tap.d.ts.map +1 -0
  744. package/dist/speculation/types.d.ts +44 -0
  745. package/dist/speculation/types.d.ts.map +1 -0
  746. package/dist/state/complexity.d.ts +13 -0
  747. package/dist/state/complexity.d.ts.map +1 -0
  748. package/dist/state/evidence-runner.d.ts +17 -0
  749. package/dist/state/evidence-runner.d.ts.map +1 -0
  750. package/dist/state/store.d.ts +76 -0
  751. package/dist/state/store.d.ts.map +1 -0
  752. package/dist/state/types.d.ts +165 -0
  753. package/dist/state/types.d.ts.map +1 -0
  754. package/dist/storage/retention.d.ts +22 -0
  755. package/dist/storage/retention.d.ts.map +1 -0
  756. package/dist/thinking.d.ts +19 -0
  757. package/dist/thinking.d.ts.map +1 -0
  758. package/dist/topology/control-plane.d.ts +58 -0
  759. package/dist/topology/control-plane.d.ts.map +1 -0
  760. package/dist/topology/participant-directory.d.ts +33 -0
  761. package/dist/topology/participant-directory.d.ts.map +1 -0
  762. package/dist/topology/peer-settle.d.ts +51 -0
  763. package/dist/topology/peer-settle.d.ts.map +1 -0
  764. package/dist/topology/records.d.ts +6 -0
  765. package/dist/topology/records.d.ts.map +1 -0
  766. package/dist/topology/types.d.ts +89 -0
  767. package/dist/topology/types.d.ts.map +1 -0
  768. package/dist/type-error-guidance.d.ts +3 -0
  769. package/dist/type-error-guidance.d.ts.map +1 -0
  770. package/dist/ui/arc-group.d.ts +17 -0
  771. package/dist/ui/arc-group.d.ts.map +1 -0
  772. package/dist/ui/border-status-editor.d.ts +22 -0
  773. package/dist/ui/border-status-editor.d.ts.map +1 -0
  774. package/dist/ui/code-preview-shell.d.ts +11 -0
  775. package/dist/ui/code-preview-shell.d.ts.map +1 -0
  776. package/dist/ui/code-preview.d.ts +53 -0
  777. package/dist/ui/code-preview.d.ts.map +1 -0
  778. package/dist/ui/controller.d.ts +20 -0
  779. package/dist/ui/controller.d.ts.map +1 -0
  780. package/dist/ui/conversation-chrome.d.ts +16 -0
  781. package/dist/ui/conversation-chrome.d.ts.map +1 -0
  782. package/dist/ui/conversation-chrome.js +11 -0
  783. package/dist/ui/conversation-chrome.js.map +7 -0
  784. package/dist/ui/conversation-commands.d.ts +12 -0
  785. package/dist/ui/conversation-commands.d.ts.map +1 -0
  786. package/dist/ui/conversation-history.d.ts +6 -0
  787. package/dist/ui/conversation-history.d.ts.map +1 -0
  788. package/dist/ui/conversation-host.d.ts +7 -0
  789. package/dist/ui/conversation-host.d.ts.map +1 -0
  790. package/dist/ui/conversation-host.js +9 -0
  791. package/dist/ui/conversation-host.js.map +7 -0
  792. package/dist/ui/conversation-native-reader-checkpoint.d.ts +8 -0
  793. package/dist/ui/conversation-native-reader-checkpoint.d.ts.map +1 -0
  794. package/dist/ui/conversation-native-reader-replay.d.ts +10 -0
  795. package/dist/ui/conversation-native-reader-replay.d.ts.map +1 -0
  796. package/dist/ui/conversation-native-reader.d.ts +110 -0
  797. package/dist/ui/conversation-native-reader.d.ts.map +1 -0
  798. package/dist/ui/conversation-native-reader.js +1050 -0
  799. package/dist/ui/conversation-native-reader.js.map +7 -0
  800. package/dist/ui/conversation-queue-store.d.ts +14 -0
  801. package/dist/ui/conversation-queue-store.d.ts.map +1 -0
  802. package/dist/ui/conversation-queue.d.ts +244 -0
  803. package/dist/ui/conversation-queue.d.ts.map +1 -0
  804. package/dist/ui/conversation-render.d.ts +104 -0
  805. package/dist/ui/conversation-render.d.ts.map +1 -0
  806. package/dist/ui/conversation-selection.d.ts +18 -0
  807. package/dist/ui/conversation-selection.d.ts.map +1 -0
  808. package/dist/ui/conversation-shortcut.d.ts +3 -0
  809. package/dist/ui/conversation-shortcut.d.ts.map +1 -0
  810. package/dist/ui/conversation-targets.d.ts +7 -0
  811. package/dist/ui/conversation-targets.d.ts.map +1 -0
  812. package/dist/ui/conversation-targets.js +12 -0
  813. package/dist/ui/conversation-targets.js.map +7 -0
  814. package/dist/ui/conversation-transcript.d.ts +25 -0
  815. package/dist/ui/conversation-transcript.d.ts.map +1 -0
  816. package/dist/ui/conversation.d.ts +219 -0
  817. package/dist/ui/conversation.d.ts.map +1 -0
  818. package/dist/ui/conversation.js +2861 -0
  819. package/dist/ui/conversation.js.map +7 -0
  820. package/dist/ui/core-tool-render.d.ts +20 -0
  821. package/dist/ui/core-tool-render.d.ts.map +1 -0
  822. package/dist/ui/dashboard-detail.d.ts +68 -0
  823. package/dist/ui/dashboard-detail.d.ts.map +1 -0
  824. package/dist/ui/dashboard-fabric-graph.d.ts +50 -0
  825. package/dist/ui/dashboard-fabric-graph.d.ts.map +1 -0
  826. package/dist/ui/dashboard-graph-controller.d.ts +52 -0
  827. package/dist/ui/dashboard-graph-controller.d.ts.map +1 -0
  828. package/dist/ui/dashboard-modal-controller.d.ts +36 -0
  829. package/dist/ui/dashboard-modal-controller.d.ts.map +1 -0
  830. package/dist/ui/dashboard-model.d.ts +111 -0
  831. package/dist/ui/dashboard-model.d.ts.map +1 -0
  832. package/dist/ui/dashboard-presentation.d.ts +6 -0
  833. package/dist/ui/dashboard-presentation.d.ts.map +1 -0
  834. package/dist/ui/dashboard.d.ts +156 -0
  835. package/dist/ui/dashboard.d.ts.map +1 -0
  836. package/dist/ui/dashboard.js +4622 -0
  837. package/dist/ui/dashboard.js.map +7 -0
  838. package/dist/ui/diff-background.d.ts +12 -0
  839. package/dist/ui/diff-background.d.ts.map +1 -0
  840. package/dist/ui/dynamic-border.d.ts +8 -0
  841. package/dist/ui/dynamic-border.d.ts.map +1 -0
  842. package/dist/ui/escape-halt.d.ts +11 -0
  843. package/dist/ui/escape-halt.d.ts.map +1 -0
  844. package/dist/ui/fabric-actor-delivery-selector.d.ts +17 -0
  845. package/dist/ui/fabric-actor-delivery-selector.d.ts.map +1 -0
  846. package/dist/ui/fabric-actor-tool-selector.d.ts +22 -0
  847. package/dist/ui/fabric-actor-tool-selector.d.ts.map +1 -0
  848. package/dist/ui/fabric-code-parser.d.ts +9 -0
  849. package/dist/ui/fabric-code-parser.d.ts.map +1 -0
  850. package/dist/ui/fabric-host-event-selector.d.ts +29 -0
  851. package/dist/ui/fabric-host-event-selector.d.ts.map +1 -0
  852. package/dist/ui/fabric-model-selector.d.ts +64 -0
  853. package/dist/ui/fabric-model-selector.d.ts.map +1 -0
  854. package/dist/ui/fabric-render.d.ts +113 -0
  855. package/dist/ui/fabric-render.d.ts.map +1 -0
  856. package/dist/ui/fabric-thinking-selector.d.ts +26 -0
  857. package/dist/ui/fabric-thinking-selector.d.ts.map +1 -0
  858. package/dist/ui/fabric-title-hint.d.ts +3 -0
  859. package/dist/ui/fabric-title-hint.d.ts.map +1 -0
  860. package/dist/ui/format.d.ts +9 -0
  861. package/dist/ui/format.d.ts.map +1 -0
  862. package/dist/ui/handoff-completion.d.ts +3 -0
  863. package/dist/ui/handoff-completion.d.ts.map +1 -0
  864. package/dist/ui/highlight.d.ts +69 -0
  865. package/dist/ui/highlight.d.ts.map +1 -0
  866. package/dist/ui/model-picker.d.ts +46 -0
  867. package/dist/ui/model-picker.d.ts.map +1 -0
  868. package/dist/ui/model-picker.js +17 -0
  869. package/dist/ui/model-picker.js.map +7 -0
  870. package/dist/ui/preview-lines.d.ts +16 -0
  871. package/dist/ui/preview-lines.d.ts.map +1 -0
  872. package/dist/ui/row-balance.d.ts +29 -0
  873. package/dist/ui/row-balance.d.ts.map +1 -0
  874. package/dist/ui/settings-component.d.ts +26 -0
  875. package/dist/ui/settings-component.d.ts.map +1 -0
  876. package/dist/ui/settings-rpc.d.ts +15 -0
  877. package/dist/ui/settings-rpc.d.ts.map +1 -0
  878. package/dist/ui/settings-section-context.d.ts +18 -0
  879. package/dist/ui/settings-section-context.d.ts.map +1 -0
  880. package/dist/ui/settings-sections-agents.d.ts +5 -0
  881. package/dist/ui/settings-sections-agents.d.ts.map +1 -0
  882. package/dist/ui/settings-sections-execution.d.ts +8 -0
  883. package/dist/ui/settings-sections-execution.d.ts.map +1 -0
  884. package/dist/ui/settings-sections-lifecycle.d.ts +6 -0
  885. package/dist/ui/settings-sections-lifecycle.d.ts.map +1 -0
  886. package/dist/ui/settings-sections-presentation.d.ts +6 -0
  887. package/dist/ui/settings-sections-presentation.d.ts.map +1 -0
  888. package/dist/ui/settings-sections.d.ts +12 -0
  889. package/dist/ui/settings-sections.d.ts.map +1 -0
  890. package/dist/ui/settings-submenus.d.ts +74 -0
  891. package/dist/ui/settings-submenus.d.ts.map +1 -0
  892. package/dist/ui/settings-values.d.ts +63 -0
  893. package/dist/ui/settings-values.d.ts.map +1 -0
  894. package/dist/ui/settings.d.ts +21 -0
  895. package/dist/ui/settings.d.ts.map +1 -0
  896. package/dist/ui/settings.js +1985 -0
  897. package/dist/ui/settings.js.map +7 -0
  898. package/dist/ui/shell-hang-keys.d.ts +11 -0
  899. package/dist/ui/shell-hang-keys.d.ts.map +1 -0
  900. package/dist/ui/shiki-language.d.ts +7 -0
  901. package/dist/ui/shiki-language.d.ts.map +1 -0
  902. package/dist/ui/shiki-theme.d.ts +7 -0
  903. package/dist/ui/shiki-theme.d.ts.map +1 -0
  904. package/dist/ui/snapshot.d.ts +17 -0
  905. package/dist/ui/snapshot.d.ts.map +1 -0
  906. package/dist/ui/spinner.d.ts +6 -0
  907. package/dist/ui/spinner.d.ts.map +1 -0
  908. package/dist/ui/state-file-preview.d.ts +13 -0
  909. package/dist/ui/state-file-preview.d.ts.map +1 -0
  910. package/dist/ui/structured.d.ts +9 -0
  911. package/dist/ui/structured.d.ts.map +1 -0
  912. package/dist/ui/tool-call-timing.d.ts +2 -0
  913. package/dist/ui/tool-call-timing.d.ts.map +1 -0
  914. package/dist/ui/tool-display.d.ts +8 -0
  915. package/dist/ui/tool-display.d.ts.map +1 -0
  916. package/dist/ui/topology.d.ts +162 -0
  917. package/dist/ui/topology.d.ts.map +1 -0
  918. package/dist/ui/transcript-parser.d.ts +18 -0
  919. package/dist/ui/transcript-parser.d.ts.map +1 -0
  920. package/dist/ui/transcript-reader.d.ts +10 -0
  921. package/dist/ui/transcript-reader.d.ts.map +1 -0
  922. package/dist/ui/transcript-sanitization.d.ts +14 -0
  923. package/dist/ui/transcript-sanitization.d.ts.map +1 -0
  924. package/dist/ui/transcript.d.ts +52 -0
  925. package/dist/ui/transcript.d.ts.map +1 -0
  926. package/dist/ui/types.d.ts +84 -0
  927. package/dist/ui/types.d.ts.map +1 -0
  928. package/dist/ui/widget.d.ts +16 -0
  929. package/dist/ui/widget.d.ts.map +1 -0
  930. package/dist/ui/word-diff/alignment.d.ts +6 -0
  931. package/dist/ui/word-diff/alignment.d.ts.map +1 -0
  932. package/dist/ui/word-diff/change-block.d.ts +18 -0
  933. package/dist/ui/word-diff/change-block.d.ts.map +1 -0
  934. package/dist/ui/word-diff/changed-line.d.ts +14 -0
  935. package/dist/ui/word-diff/changed-line.d.ts.map +1 -0
  936. package/dist/ui/word-diff/emphasis.d.ts +9 -0
  937. package/dist/ui/word-diff/emphasis.d.ts.map +1 -0
  938. package/dist/ui/word-diff/line-emphasis.d.ts +7 -0
  939. package/dist/ui/word-diff/line-emphasis.d.ts.map +1 -0
  940. package/dist/ui/word-diff/line-matching.d.ts +10 -0
  941. package/dist/ui/word-diff/line-matching.d.ts.map +1 -0
  942. package/dist/ui/word-diff/line-similarity.d.ts +16 -0
  943. package/dist/ui/word-diff/line-similarity.d.ts.map +1 -0
  944. package/dist/ui/word-diff/normalize.d.ts +3 -0
  945. package/dist/ui/word-diff/normalize.d.ts.map +1 -0
  946. package/dist/ui/word-diff/parse.d.ts +17 -0
  947. package/dist/ui/word-diff/parse.d.ts.map +1 -0
  948. package/dist/ui/word-diff/range-refinement.d.ts +5 -0
  949. package/dist/ui/word-diff/range-refinement.d.ts.map +1 -0
  950. package/dist/ui/word-diff/ranges.d.ts +11 -0
  951. package/dist/ui/word-diff/ranges.d.ts.map +1 -0
  952. package/dist/ui/word-diff/smart-filter.d.ts +3 -0
  953. package/dist/ui/word-diff/smart-filter.d.ts.map +1 -0
  954. package/dist/ui/word-diff/sparse-line-matching.d.ts +25 -0
  955. package/dist/ui/word-diff/sparse-line-matching.d.ts.map +1 -0
  956. package/dist/ui/word-diff/text-boundaries.d.ts +11 -0
  957. package/dist/ui/word-diff/text-boundaries.d.ts.map +1 -0
  958. package/dist/ui/word-diff/token-alignment.d.ts +9 -0
  959. package/dist/ui/word-diff/token-alignment.d.ts.map +1 -0
  960. package/dist/ui/word-diff/token-text-refinement.d.ts +4 -0
  961. package/dist/ui/word-diff/token-text-refinement.d.ts.map +1 -0
  962. package/dist/ui/word-diff/tokens.d.ts +16 -0
  963. package/dist/ui/word-diff/tokens.d.ts.map +1 -0
  964. package/dist/ui/word-diff/types.d.ts +10 -0
  965. package/dist/ui/word-diff/types.d.ts.map +1 -0
  966. package/dist/util.d.ts +3 -0
  967. package/dist/util.d.ts.map +1 -0
  968. package/dist/worker/model-control.d.ts +14 -0
  969. package/dist/worker/model-control.d.ts.map +1 -0
  970. package/dist/worker/model-control.js +118 -0
  971. package/dist/worker/model-control.js.map +7 -0
  972. package/dist/worker/options.d.ts +3 -0
  973. package/dist/worker/options.d.ts.map +1 -0
  974. package/dist/worker/options.js +156 -0
  975. package/dist/worker/options.js.map +7 -0
  976. package/dist/worker/run-record.d.ts +22 -0
  977. package/dist/worker/run-record.d.ts.map +1 -0
  978. package/dist/worker/run-record.js +124 -0
  979. package/dist/worker/run-record.js.map +7 -0
  980. package/dist/worker/session-export.d.ts +45 -0
  981. package/dist/worker/session-export.d.ts.map +1 -0
  982. package/dist/worker/session-export.js +91 -0
  983. package/dist/worker/session-export.js.map +7 -0
  984. package/dist/worker.d.ts +3 -0
  985. package/dist/worker.d.ts.map +1 -0
  986. package/dist/worker.js +1074 -0
  987. package/dist/worker.js.map +7 -0
  988. package/docs/agents.md +618 -0
  989. package/docs/architecture.md +141 -0
  990. package/docs/audit-trace.md +116 -0
  991. package/docs/certification.md +166 -0
  992. package/docs/compaction.md +345 -0
  993. package/docs/component-calculus.md +191 -0
  994. package/docs/components.md +330 -0
  995. package/docs/configuration.md +529 -0
  996. package/docs/entropy.md +214 -0
  997. package/docs/interface.md +210 -0
  998. package/docs/jev.md +289 -0
  999. package/docs/kernels.md +186 -0
  1000. package/docs/memory-recall.md +664 -0
  1001. package/docs/programmatic-compaction.md +205 -0
  1002. package/docs/provider-component-calculus.md +378 -0
  1003. package/docs/providers.md +163 -0
  1004. package/docs/repairs.md +90 -0
  1005. package/docs/residency-runtime.md +82 -0
  1006. package/docs/schema-enforcement.md +166 -0
  1007. package/docs/skills.md +50 -0
  1008. package/docs/speculation.md +171 -0
  1009. package/docs/state-layer.md +197 -0
  1010. package/package.json +135 -0
  1011. package/skillsets/python/fabric-advisor/SKILL.md +29 -0
  1012. package/skillsets/python/fabric-ambient/SKILL.md +44 -0
  1013. package/skillsets/python/fabric-ambient/references/setup.md +67 -0
  1014. package/skillsets/python/fabric-council/SKILL.md +54 -0
  1015. package/skillsets/python/fabric-exec/SKILL.md +74 -0
  1016. package/skillsets/python/fabric-exec/references/agents.md +65 -0
  1017. package/skillsets/python/fabric-exec/references/mcp.md +23 -0
  1018. package/skillsets/python/fabric-exec/references/mesh.md +27 -0
  1019. package/skillsets/python/fabric-fusion/SKILL.md +112 -0
  1020. package/skillsets/python/fabric-guide/SKILL.md +29 -0
  1021. package/skillsets/python/fabric-jev/SKILL.md +162 -0
  1022. package/skillsets/python/fabric-rlm/SKILL.md +120 -0
  1023. package/skillsets/python/fabric-schema/SKILL.md +55 -0
  1024. package/skillsets/python/fabric-spec/SKILL.md +42 -0
  1025. package/skillsets/python/fabric-supervisor/SKILL.md +37 -0
  1026. package/skillsets/python/fabric-swarm/SKILL.md +40 -0
  1027. package/skillsets/python/fabric-workflow/SKILL.md +62 -0
  1028. package/skillsets/typescript/fabric-advisor/SKILL.md +29 -0
  1029. package/skillsets/typescript/fabric-ambient/SKILL.md +44 -0
  1030. package/skillsets/typescript/fabric-ambient/references/setup.md +90 -0
  1031. package/skillsets/typescript/fabric-council/SKILL.md +94 -0
  1032. package/skillsets/typescript/fabric-exec/SKILL.md +142 -0
  1033. package/skillsets/typescript/fabric-exec/references/agents.md +218 -0
  1034. package/skillsets/typescript/fabric-exec/references/mcp.md +49 -0
  1035. package/skillsets/typescript/fabric-exec/references/mesh.md +51 -0
  1036. package/skillsets/typescript/fabric-fusion/SKILL.md +332 -0
  1037. package/skillsets/typescript/fabric-guide/SKILL.md +29 -0
  1038. package/skillsets/typescript/fabric-jev/SKILL.md +159 -0
  1039. package/skillsets/typescript/fabric-rlm/SKILL.md +284 -0
  1040. package/skillsets/typescript/fabric-schema/SKILL.md +121 -0
  1041. package/skillsets/typescript/fabric-spec/SKILL.md +42 -0
  1042. package/skillsets/typescript/fabric-supervisor/SKILL.md +37 -0
  1043. package/skillsets/typescript/fabric-swarm/SKILL.md +80 -0
  1044. package/skillsets/typescript/fabric-workflow/SKILL.md +133 -0
@@ -0,0 +1,4622 @@
1
+ import {
2
+ FabricModelSelector
3
+ } from "../chunks/chunk-VRYEGVHR.js";
4
+ import {
5
+ INHERIT_VALUE
6
+ } from "../chunks/chunk-CQFP2RCP.js";
7
+ import {
8
+ coreToolTitle,
9
+ formatJsonAsYaml,
10
+ nestedEditDiff,
11
+ renderBoundedLines,
12
+ renderCoreToolBody,
13
+ spinnerFrame
14
+ } from "../chunks/chunk-VRZNFNPB.js";
15
+ import {
16
+ highlightCode,
17
+ highlightFileLines,
18
+ languageFromPath
19
+ } from "../chunks/chunk-ZZ4LHQYJ.js";
20
+ import {
21
+ isActiveStatus,
22
+ orderAgentsByCreation
23
+ } from "../chunks/chunk-AAHHYDTO.js";
24
+ import {
25
+ formatActorDataPreview,
26
+ formatClock,
27
+ formatDuration,
28
+ formatTokens,
29
+ padToWidth,
30
+ safeText,
31
+ wrapPlainText
32
+ } from "../chunks/chunk-ARLYAW2A.js";
33
+ import "../chunks/chunk-J2HV2URQ.js";
34
+ import "../chunks/chunk-DLXPTBPL.js";
35
+ import {
36
+ formatFabricEffectConflict
37
+ } from "../chunks/chunk-LMAVZN7J.js";
38
+ import "../chunks/chunk-CGPK5WHX.js";
39
+ import "../chunks/chunk-OKOHRXGF.js";
40
+ import "../chunks/chunk-656HWVFU.js";
41
+ import {
42
+ FABRIC_ACTOR_HOST_EVENTS
43
+ } from "../chunks/chunk-OTCASLY2.js";
44
+ import {
45
+ THINKING_LEVELS,
46
+ isFabricThinking,
47
+ thinkingLabel
48
+ } from "../chunks/chunk-MGWQOKBV.js";
49
+
50
+ // src/ui/dashboard.ts
51
+ import {
52
+ getKeybindings as getKeybindings4,
53
+ Key,
54
+ matchesKey,
55
+ truncateToWidth as truncateToWidth4,
56
+ visibleWidth as visibleWidth4
57
+ } from "@earendil-works/pi-tui";
58
+
59
+ // src/ui/topology.ts
60
+ import { createHash } from "node:crypto";
61
+ var UNPHASED = Symbol("fabric-run-topology-unphased");
62
+ var SYSTEM_TOPICS = /* @__PURE__ */ new Set([
63
+ "fabric.actor.input",
64
+ "fabric.actor.output",
65
+ "fabric.actor.lifecycle",
66
+ "fabric.compact",
67
+ "fabric.participant.lifecycle",
68
+ "fabric.steer",
69
+ "fabric.control.command",
70
+ "fabric.control.ack"
71
+ ]);
72
+ var IGNORED_ROUTE_TOPICS = /* @__PURE__ */ new Set([
73
+ "fabric.actor.lifecycle",
74
+ "fabric.compact",
75
+ "fabric.control.ack"
76
+ ]);
77
+ var eventData = (event) => typeof event.data === "object" && event.data !== null && !Array.isArray(event.data) ? event.data : void 0;
78
+ var failureEventKinds = /* @__PURE__ */ new Set([
79
+ "error",
80
+ "failed",
81
+ "failure",
82
+ "blocked",
83
+ "reject",
84
+ "rejected"
85
+ ]);
86
+ var routeStatus = (kind) => kind.toLowerCase().split(/[.:/_-]+/).some((part) => failureEventKinds.has(part)) ? "failed" : "completed";
87
+ var projectMeshRoutes = (main, actors, agents, events) => {
88
+ const actorByKey = /* @__PURE__ */ new Map();
89
+ for (const actor of actors) {
90
+ actorByKey.set(actor.id, actor);
91
+ actorByKey.set(actor.name, actor);
92
+ }
93
+ const agentByKey = /* @__PURE__ */ new Map();
94
+ for (const agent of agents) {
95
+ agentByKey.set(agent.id, agent);
96
+ agentByKey.set(agent.name, agent);
97
+ }
98
+ const mainByKey = /* @__PURE__ */ new Map([
99
+ [main.id, main.name],
100
+ [main.name, main.name],
101
+ ["main", main.name]
102
+ ]);
103
+ for (const event of events) {
104
+ if (event.from.kind !== "main") continue;
105
+ mainByKey.set(event.from.id, event.from.name);
106
+ mainByKey.set(event.from.name, event.from.name);
107
+ }
108
+ const routes = /* @__PURE__ */ new Map();
109
+ for (const event of events) {
110
+ if (IGNORED_ROUTE_TOPICS.has(event.topic)) continue;
111
+ const data = eventData(event);
112
+ let targetId;
113
+ let targetName;
114
+ let targetKind;
115
+ const actorInputId = event.topic === "fabric.actor.input" && typeof data?.actorId === "string" ? data.actorId : void 0;
116
+ const controlTarget = event.topic === "fabric.control.command" && typeof data?.targetId === "string" ? data.targetId : void 0;
117
+ const addressed = controlTarget ?? event.to ?? actorInputId;
118
+ const targetMain = addressed ? mainByKey.get(addressed) : void 0;
119
+ const targetActor = addressed ? actorByKey.get(addressed) : void 0;
120
+ const targetAgent = addressed ? agentByKey.get(addressed) : void 0;
121
+ if (targetMain) {
122
+ targetId = addressed;
123
+ targetName = targetMain;
124
+ targetKind = "main";
125
+ } else if (targetActor) {
126
+ targetId = targetActor.id;
127
+ targetName = targetActor.name;
128
+ targetKind = "actor";
129
+ } else if (targetAgent) {
130
+ targetId = targetAgent.id;
131
+ targetName = targetAgent.name;
132
+ targetKind = "agent";
133
+ } else if (addressed) {
134
+ targetId = addressed;
135
+ targetName = addressed;
136
+ targetKind = "agent";
137
+ } else if (event.topic === "fabric.actor.output") {
138
+ targetId = main.id;
139
+ targetName = main.name;
140
+ targetKind = "main";
141
+ } else {
142
+ targetId = event.topic;
143
+ targetName = event.topic;
144
+ targetKind = "topic";
145
+ }
146
+ const key = JSON.stringify([
147
+ event.from.id,
148
+ event.from.kind,
149
+ targetKind,
150
+ targetId,
151
+ event.topic,
152
+ event.kind
153
+ ]);
154
+ const existing = routes.get(key);
155
+ if (existing) {
156
+ existing.count++;
157
+ if (event.createdAt >= existing.lastAt) {
158
+ existing.lastAt = event.createdAt;
159
+ if (event.text) existing.text = event.text;
160
+ else delete existing.text;
161
+ }
162
+ if (routeStatus(event.kind) === "failed") existing.status = "failed";
163
+ continue;
164
+ }
165
+ routes.set(key, {
166
+ id: `route:${createHash("sha256").update(key).digest("hex").slice(0, 20)}`,
167
+ fromId: event.from.id,
168
+ fromName: event.from.name,
169
+ fromKind: event.from.kind,
170
+ targetId,
171
+ targetName,
172
+ targetKind,
173
+ topic: event.topic,
174
+ kind: event.kind,
175
+ status: routeStatus(event.kind),
176
+ count: 1,
177
+ lastAt: event.createdAt,
178
+ ...event.text ? { text: event.text } : {}
179
+ });
180
+ }
181
+ return [...routes.values()].sort((left, right) => right.lastAt - left.lastAt);
182
+ };
183
+ var projectMeshParticipants = (agents, routes, directoryParticipants) => {
184
+ const agentByKey = /* @__PURE__ */ new Map();
185
+ for (const agent of agents) {
186
+ agentByKey.set(agent.id, agent);
187
+ agentByKey.set(agent.name, agent);
188
+ }
189
+ const observed = /* @__PURE__ */ new Map();
190
+ const touch = (id, name, lastSeenAt, participant) => {
191
+ const existing = observed.get(id);
192
+ if (!existing) {
193
+ observed.set(id, {
194
+ id,
195
+ name,
196
+ lastSeenAt,
197
+ ...participant ? { participant } : {}
198
+ });
199
+ return;
200
+ }
201
+ if (lastSeenAt >= existing.lastSeenAt) {
202
+ existing.name = name;
203
+ existing.lastSeenAt = lastSeenAt;
204
+ }
205
+ if (participant) existing.participant = participant;
206
+ };
207
+ for (const participant of directoryParticipants) {
208
+ const name = participant.kind === "root" && participant.sessionId ? `Peer ${participant.sessionId.slice(0, 8)}` : participant.name;
209
+ touch(participant.id, name, participant.updatedAt, participant);
210
+ }
211
+ for (const route of routes) {
212
+ if (route.fromKind === "agent") touch(route.fromId, route.fromName, route.lastAt);
213
+ if (route.targetKind === "agent") touch(route.targetId, route.targetName, route.lastAt);
214
+ }
215
+ return [...observed.values()].map((identity) => {
216
+ const agent = agentByKey.get(identity.id) ?? agentByKey.get(identity.name);
217
+ const routesForParticipant = routes.reduce(
218
+ (count, route) => count + (route.fromKind === "agent" && route.fromId === identity.id || route.targetKind === "agent" && route.targetId === identity.id ? route.count : 0),
219
+ 0
220
+ );
221
+ return {
222
+ id: identity.id,
223
+ entityId: agent ? `agent:${agent.id}` : `participant:${identity.id}`,
224
+ name: agent?.name ?? identity.name,
225
+ status: agent?.status ?? "idle",
226
+ routes: routesForParticipant,
227
+ lastSeenAt: identity.lastSeenAt,
228
+ ...agent ? { agent } : {},
229
+ ...identity.participant ? { participant: identity.participant } : {}
230
+ };
231
+ }).sort(
232
+ (left, right) => Number(isActiveStatus(right.status)) - Number(isActiveStatus(left.status)) || left.name.localeCompare(right.name)
233
+ );
234
+ };
235
+ var projectParticipantTree = (participants) => {
236
+ const byId = new Map(participants.map((participant) => [participant.id, participant]));
237
+ const children = /* @__PURE__ */ new Map();
238
+ const roots = [];
239
+ for (const participant of participants) {
240
+ const parentId = participant.participant?.parentId ?? participant.agent?.parentId;
241
+ if (!parentId || !byId.has(parentId) || parentId === participant.id) {
242
+ roots.push(participant);
243
+ continue;
244
+ }
245
+ const entries = children.get(parentId) ?? [];
246
+ entries.push(participant);
247
+ children.set(parentId, entries);
248
+ }
249
+ const rows = [];
250
+ const visited = /* @__PURE__ */ new Set();
251
+ const visit = (participant, ancestorLast, isLast) => {
252
+ if (visited.has(participant.id)) return;
253
+ visited.add(participant.id);
254
+ rows.push({ participant, ancestorLast, isLast });
255
+ const descendants = (children.get(participant.id) ?? []).filter(
256
+ (candidate) => !visited.has(candidate.id)
257
+ );
258
+ for (let index = 0; index < descendants.length; index++) {
259
+ const descendant = descendants[index];
260
+ if (descendant) {
261
+ visit(descendant, [...ancestorLast, isLast], index === descendants.length - 1);
262
+ }
263
+ }
264
+ };
265
+ for (let index = 0; index < roots.length; index++) {
266
+ const root = roots[index];
267
+ if (root) visit(root, [], index === roots.length - 1);
268
+ }
269
+ for (const participant of participants) {
270
+ if (!visited.has(participant.id)) visit(participant, [], true);
271
+ }
272
+ return rows;
273
+ };
274
+ var projectMeshTopics = (actors, events, now) => {
275
+ const names = /* @__PURE__ */ new Set();
276
+ for (const actor of actors) {
277
+ for (const topic of actor.topics) names.add(topic);
278
+ }
279
+ for (const event of events) {
280
+ if (!SYSTEM_TOPICS.has(event.topic)) names.add(event.topic);
281
+ }
282
+ return [...names].sort((left, right) => left.localeCompare(right)).map((name) => {
283
+ const topicEvents = events.filter((event) => event.topic === name);
284
+ const lastEventAt = topicEvents.reduce(
285
+ (latest, event) => Math.max(latest, event.createdAt),
286
+ 0
287
+ );
288
+ const subscribers = actors.filter((actor) => actor.topics.includes(name)).map((actor) => ({ id: actor.id, name: actor.name, status: actor.status }));
289
+ return {
290
+ id: `topic:${name}`,
291
+ name,
292
+ status: lastEventAt > 0 && now - lastEventAt <= 1e4 ? "running" : "idle",
293
+ system: SYSTEM_TOPICS.has(name),
294
+ subscribers,
295
+ recentEvents: topicEvents.length,
296
+ ...lastEventAt > 0 ? { lastEventAt } : {}
297
+ };
298
+ });
299
+ };
300
+ var buildProjectMeshTopology = (input) => {
301
+ const topics = projectMeshTopics(input.actors, input.events, input.now);
302
+ const routes = projectMeshRoutes(input.main, input.actors, input.agents, input.events);
303
+ const localActorIds = new Set(input.actors.map((actor) => actor.id));
304
+ const directoryParticipants = (input.participants ?? []).filter(
305
+ (participant) => participant.id !== input.main.id && !(participant.kind === "actor" && localActorIds.has(participant.id))
306
+ );
307
+ const participants = projectMeshParticipants(input.agents, routes, directoryParticipants);
308
+ const rows = [
309
+ {
310
+ kind: "meshRoot",
311
+ entityId: `main:${input.main.id}`,
312
+ main: input.main,
313
+ actors: input.actors.length,
314
+ agents: participants.length,
315
+ topics: topics.length,
316
+ state: input.state.length,
317
+ routes: routes.length
318
+ }
319
+ ];
320
+ if (input.actors.length > 0) {
321
+ rows.push({ kind: "meshSection", label: "Persistent actors", count: input.actors.length });
322
+ for (const actor of input.actors) {
323
+ rows.push({ kind: "meshActor", entityId: `actor:${actor.id}`, actor });
324
+ }
325
+ }
326
+ if (participants.length > 0) {
327
+ rows.push({
328
+ kind: "meshSection",
329
+ label: "Project participants",
330
+ count: participants.length
331
+ });
332
+ for (const entry of projectParticipantTree(participants)) {
333
+ rows.push({
334
+ kind: "meshAgent",
335
+ entityId: entry.participant.entityId,
336
+ participant: entry.participant,
337
+ ancestorLast: entry.ancestorLast,
338
+ isLast: entry.isLast
339
+ });
340
+ }
341
+ }
342
+ if (topics.length > 0) {
343
+ rows.push({ kind: "meshSection", label: "Topics", count: topics.length });
344
+ for (const topic of topics) {
345
+ rows.push({ kind: "meshTopic", entityId: topic.id, topic });
346
+ for (let index = 0; index < topic.subscribers.length; index++) {
347
+ const subscriber = topic.subscribers[index];
348
+ if (!subscriber) continue;
349
+ rows.push({
350
+ kind: "meshLink",
351
+ relation: "subscribes",
352
+ sourceId: subscriber.id,
353
+ sourceName: subscriber.name,
354
+ targetId: topic.id,
355
+ targetName: topic.name,
356
+ status: subscriber.status,
357
+ isLast: index === topic.subscribers.length - 1
358
+ });
359
+ }
360
+ }
361
+ }
362
+ if (input.state.length > 0) {
363
+ rows.push({ kind: "meshSection", label: "Shared state", count: input.state.length });
364
+ for (const state of input.state) {
365
+ rows.push({ kind: "meshState", entityId: `state:${state.key}`, state });
366
+ }
367
+ }
368
+ if (routes.length > 0) {
369
+ rows.push({ kind: "meshSection", label: "Recent routes", count: routes.length });
370
+ for (const route of routes) {
371
+ rows.push({ kind: "meshRoute", entityId: route.id, route });
372
+ }
373
+ }
374
+ const entityOrder = rows.flatMap(
375
+ (row) => "entityId" in row ? [row.entityId] : []
376
+ );
377
+ return { participants, topics, routes, rows, entityOrder };
378
+ };
379
+
380
+ // src/ui/dashboard-model.ts
381
+ var entityGroupOrder = [
382
+ "agent",
383
+ "peer",
384
+ "actor",
385
+ "globalActor",
386
+ "tool",
387
+ "extension",
388
+ "mcp",
389
+ "mesh",
390
+ "task",
391
+ "custom",
392
+ "state",
393
+ "component",
394
+ "meshParticipant",
395
+ "meshTopic",
396
+ "meshRoute"
397
+ ];
398
+ var entityGroupLabels = {
399
+ agent: "Agents",
400
+ peer: "Peers",
401
+ actor: "Actors",
402
+ globalActor: "Global templates",
403
+ tool: "Tools",
404
+ extension: "Extensions",
405
+ mcp: "MCP",
406
+ mesh: "Mesh",
407
+ task: "Tasks",
408
+ custom: "Custom items",
409
+ state: "Shared state",
410
+ component: "Components",
411
+ meshParticipant: "Project participants",
412
+ meshTopic: "Topics",
413
+ meshRoute: "Recent routes"
414
+ };
415
+ var entityGroupKind = (entity) => {
416
+ if (entity.kind === "main" || entity.kind === "agent") return "agent";
417
+ if (entity.kind === "peer") return "peer";
418
+ if (entity.kind === "actor") return "actor";
419
+ if (entity.kind === "globalActor") return "globalActor";
420
+ if (entity.kind === "state") return "state";
421
+ if (entity.kind === "component") return "component";
422
+ if (entity.kind === "meshParticipant") return "meshParticipant";
423
+ if (entity.kind === "meshTopic") return "meshTopic";
424
+ if (entity.kind === "meshRoute") return "meshRoute";
425
+ if (entity.kind === "call") return entity.value.entityKind ?? entity.value.kind;
426
+ return entity.value.kind;
427
+ };
428
+ var entityGroupRanks = new Map(
429
+ entityGroupOrder.map((kind, index) => [kind, index])
430
+ );
431
+ var orderEntitiesByGroup = (entities) => entities.map((entity, index) => ({ entity, index })).sort(
432
+ (left, right) => (entityGroupRanks.get(entityGroupKind(left.entity)) ?? Number.MAX_SAFE_INTEGER) - (entityGroupRanks.get(entityGroupKind(right.entity)) ?? Number.MAX_SAFE_INTEGER) || left.index - right.index
433
+ ).map(({ entity }) => entity);
434
+ var groupEntities = (entities) => {
435
+ const indexed = entities.map((entity, index) => ({ entity, index }));
436
+ return entityGroupOrder.flatMap((kind) => {
437
+ const entries = indexed.filter(({ entity }) => entityGroupKind(entity) === kind);
438
+ return entries.length > 0 ? [{ kind, label: entityGroupLabels[kind], entries }] : [];
439
+ });
440
+ };
441
+ var filters = ["all", "active", "completed", "failed"];
442
+ var linkedEntityId = (entityId, id) => Boolean(entityId && (id.startsWith(entityId) || entityId.startsWith(id)));
443
+ var linkedAgent = (call, agent) => linkedEntityId(call.entityId, agent.id);
444
+ var agentLaunchRefs = /* @__PURE__ */ new Set(["agents.run", "agents.spawn"]);
445
+ var mainEntity = (snapshot) => ({
446
+ id: `main:${snapshot.main.id}`,
447
+ kind: "main",
448
+ label: "Main",
449
+ status: snapshot.main.status,
450
+ value: snapshot.main
451
+ });
452
+ var UNPHASED_PANEL_ID = "__fabric_unphased";
453
+ var SESSION_PANEL_ID = "__fabric_session";
454
+ var callsForPanel = (run, panel) => {
455
+ if (!run || panel.kind === "session") return [];
456
+ return run.calls.filter(
457
+ (call) => panel.kind === "unphased" ? !call.phaseId : call.phaseId === panel.id
458
+ );
459
+ };
460
+ var itemsForPanel = (run, panel) => {
461
+ if (!run || panel.kind === "session") return [];
462
+ return run.items.filter(
463
+ (item) => panel.kind === "unphased" ? !item.phaseId : item.phaseId === panel.id
464
+ );
465
+ };
466
+ var entitiesFor = (snapshot, run, panel) => {
467
+ if (!panel || panel.kind === "session") {
468
+ const unlinkedAgents = orderAgentsByCreation(snapshot.agents).filter((agent) => agent.runId !== run?.id && isActiveStatus(agent.status)).map((agent) => ({
469
+ id: `agent:${agent.id}`,
470
+ kind: "agent",
471
+ label: agent.name,
472
+ status: agent.status,
473
+ value: agent
474
+ }));
475
+ const peers = snapshot.peers.map((peer) => ({
476
+ id: `peer:${peer.id}`,
477
+ kind: "peer",
478
+ label: peer.name,
479
+ status: peer.status,
480
+ value: peer
481
+ }));
482
+ const actors = snapshot.actors.map((actor) => ({
483
+ id: `actor:${actor.id}`,
484
+ kind: "actor",
485
+ label: actor.name,
486
+ status: actor.lastError ? "failed" : actor.status,
487
+ value: actor
488
+ }));
489
+ const globalActors = snapshot.globalActors.map((definition) => ({
490
+ id: `globalActor:${definition.id}`,
491
+ kind: "globalActor",
492
+ label: definition.name,
493
+ status: "global",
494
+ value: definition
495
+ }));
496
+ const components = snapshot.componentGraph.components.map((component) => ({
497
+ id: `component:${component.id}`,
498
+ kind: "component",
499
+ label: component.id,
500
+ status: component.state,
501
+ value: component
502
+ }));
503
+ const state = snapshot.state.map((entry) => ({
504
+ id: `state:${entry.key}`,
505
+ kind: "state",
506
+ label: entry.label,
507
+ status: entry.status,
508
+ value: entry
509
+ }));
510
+ return orderEntitiesByGroup([
511
+ mainEntity(snapshot),
512
+ ...unlinkedAgents,
513
+ ...peers,
514
+ ...actors,
515
+ ...globalActors,
516
+ ...components,
517
+ ...state
518
+ ]);
519
+ }
520
+ const calls = callsForPanel(run, panel);
521
+ const panelAgents = orderAgentsByCreation(snapshot.agents).filter((agent) => {
522
+ const ownedByPanel = agent.runId === run?.id && (panel.kind === "unphased" ? !agent.phaseId : agent.phaseId === panel.id);
523
+ return ownedByPanel || !agent.runId && calls.some((call) => linkedAgent(call, agent));
524
+ });
525
+ const linkedAgents = panelAgents.map((agent) => ({
526
+ id: `agent:${agent.id}`,
527
+ kind: "agent",
528
+ label: agent.name,
529
+ status: agent.status,
530
+ value: agent
531
+ }));
532
+ const visibleCalls = calls.filter((call) => {
533
+ const representedAgentLaunch = call.kind === "agent" && agentLaunchRefs.has(call.ref) && panelAgents.some((agent) => linkedAgent(call, agent));
534
+ const representedActorCreation = call.kind === "actor" && call.ref === "agents.create" && snapshot.actors.some((actor) => linkedEntityId(call.entityId, actor.id));
535
+ return !representedAgentLaunch && !representedActorCreation;
536
+ }).map((call) => ({
537
+ id: `call:${call.id}`,
538
+ kind: "call",
539
+ label: call.label,
540
+ status: call.status,
541
+ value: call
542
+ }));
543
+ const items = itemsForPanel(run, panel).map((item) => ({
544
+ id: `item:${item.id}`,
545
+ kind: "item",
546
+ label: item.label,
547
+ status: item.status,
548
+ value: item
549
+ }));
550
+ return orderEntitiesByGroup([
551
+ mainEntity(snapshot),
552
+ ...linkedAgents,
553
+ ...visibleCalls,
554
+ ...items
555
+ ]);
556
+ };
557
+ var projectMeshEntitiesFor = (snapshot, topology) => {
558
+ const model = topology ?? buildProjectMeshTopology({
559
+ main: snapshot.main,
560
+ actors: snapshot.actors,
561
+ agents: snapshot.agents,
562
+ state: snapshot.state,
563
+ events: snapshot.events,
564
+ ...snapshot.participants ? { participants: snapshot.participants } : {},
565
+ now: snapshot.now
566
+ });
567
+ const entities = model.rows.flatMap((row) => {
568
+ if (row.kind === "meshRoot") return [mainEntity(snapshot)];
569
+ if (row.kind === "meshActor") {
570
+ return [{
571
+ id: row.entityId,
572
+ kind: "actor",
573
+ label: row.actor.name,
574
+ status: row.actor.lastError ? "failed" : row.actor.status,
575
+ value: row.actor
576
+ }];
577
+ }
578
+ if (row.kind === "meshAgent") {
579
+ if (row.participant.agent) {
580
+ return [{
581
+ id: row.entityId,
582
+ kind: "agent",
583
+ label: row.participant.agent.name,
584
+ status: row.participant.agent.status,
585
+ value: row.participant.agent
586
+ }];
587
+ }
588
+ return [{
589
+ id: row.entityId,
590
+ kind: "meshParticipant",
591
+ label: row.participant.name,
592
+ status: row.participant.status,
593
+ value: row.participant
594
+ }];
595
+ }
596
+ if (row.kind === "meshTopic") {
597
+ return [{
598
+ id: row.entityId,
599
+ kind: "meshTopic",
600
+ label: row.topic.name,
601
+ status: row.topic.status,
602
+ value: row.topic
603
+ }];
604
+ }
605
+ if (row.kind === "meshState") {
606
+ return [{
607
+ id: row.entityId,
608
+ kind: "state",
609
+ label: row.state.label,
610
+ status: row.state.status,
611
+ value: row.state
612
+ }];
613
+ }
614
+ if (row.kind === "meshRoute") {
615
+ return [{
616
+ id: row.entityId,
617
+ kind: "meshRoute",
618
+ label: `${row.route.fromName} \u2192 ${row.route.targetName}`,
619
+ status: row.route.status,
620
+ value: row.route
621
+ }];
622
+ }
623
+ return [];
624
+ });
625
+ return [
626
+ ...entities,
627
+ ...snapshot.componentGraph.components.map((component) => ({
628
+ id: `component:${component.id}`,
629
+ kind: "component",
630
+ label: component.id,
631
+ status: component.state,
632
+ value: component
633
+ }))
634
+ ];
635
+ };
636
+ var unifiedTopologyEntitiesFor = (snapshot, run, topology) => {
637
+ const orderedAgents = orderAgentsByCreation(snapshot.agents).sort(
638
+ (left, right) => Number(right.runId === run?.id) - Number(left.runId === run?.id) || Number(isActiveStatus(right.status)) - Number(isActiveStatus(left.status))
639
+ );
640
+ const canonical = [
641
+ mainEntity(snapshot),
642
+ ...orderedAgents.map((agent) => ({
643
+ id: `agent:${agent.id}`,
644
+ kind: "agent",
645
+ label: agent.name,
646
+ status: agent.status,
647
+ value: agent
648
+ })),
649
+ ...snapshot.actors.map((actor) => ({
650
+ id: `actor:${actor.id}`,
651
+ kind: "actor",
652
+ label: actor.name,
653
+ status: actor.lastError ? "failed" : actor.status,
654
+ value: actor
655
+ })),
656
+ ...snapshot.peers.map((peer) => ({
657
+ id: `peer:${peer.id}`,
658
+ kind: "peer",
659
+ label: peer.name,
660
+ status: peer.status,
661
+ value: peer
662
+ }))
663
+ ];
664
+ const seen = new Set(canonical.map((entity) => entity.id));
665
+ const seenParticipantIds = /* @__PURE__ */ new Set([
666
+ snapshot.main.id,
667
+ ...snapshot.agents.map((agent) => agent.id),
668
+ ...snapshot.actors.map((actor) => actor.id),
669
+ ...snapshot.peers.map((peer) => peer.id)
670
+ ]);
671
+ for (const entity of projectMeshEntitiesFor(snapshot, topology)) {
672
+ if (seen.has(entity.id)) continue;
673
+ if (entity.kind === "meshParticipant" && seenParticipantIds.has(entity.value.id)) continue;
674
+ seen.add(entity.id);
675
+ canonical.push(entity);
676
+ }
677
+ return canonical;
678
+ };
679
+ var entitiesForOverview = (snapshot, run, panel, view, projectMesh) => {
680
+ if (view === "topology") return unifiedTopologyEntitiesFor(snapshot, run, projectMesh);
681
+ return entitiesFor(snapshot, run, panel);
682
+ };
683
+ var panelStatus = (entities, fallback) => {
684
+ if (entities.some((entity) => ["failed", "timed_out", "error"].includes(entity.status))) {
685
+ return "failed";
686
+ }
687
+ if (entities.some((entity) => entity.status === "blocked")) return "blocked";
688
+ if (entities.some((entity) => isActiveStatus(entity.status))) return "running";
689
+ if (entities.length > 0 && entities.every(
690
+ (entity) => ["completed", "done", "stopped", "cancelled", "global", "idle", "state"].includes(
691
+ entity.status
692
+ )
693
+ )) {
694
+ return "completed";
695
+ }
696
+ return fallback;
697
+ };
698
+ var withPanelProgress = (snapshot, run, panel, projectedEntities) => {
699
+ const entities = projectedEntities ?? entitiesFor(snapshot, run, panel);
700
+ const progressEntities = panel.kind === "session" ? entities : entities.filter((entity) => entity.kind !== "main");
701
+ const status = panel.kind === "session" ? progressEntities.some(
702
+ (entity) => ["failed", "timed_out", "error"].includes(entity.status)
703
+ ) ? "failed" : progressEntities.some((entity) => isActiveStatus(entity.status)) ? "running" : "idle" : panelStatus(progressEntities, panel.status);
704
+ const agents = progressEntities.filter((entity) => entity.kind === "agent");
705
+ const tokens = agents.reduce(
706
+ (sum, entity) => sum + (entity.kind === "agent" && entity.value.usage ? entity.value.usage.input + entity.value.usage.output : 0),
707
+ 0
708
+ );
709
+ const starts = progressEntities.flatMap((entity) => {
710
+ if (entity.kind === "agent" || entity.kind === "call") return [entity.value.startedAt ?? 0];
711
+ if (entity.kind === "item") return [entity.value.createdAt];
712
+ return [];
713
+ }).filter((value) => value > 0);
714
+ const startedAt = starts.length > 0 ? Math.min(...starts) : void 0;
715
+ const hasActive = progressEntities.some((entity) => isActiveStatus(entity.status));
716
+ const finishes = progressEntities.flatMap((entity) => {
717
+ if (entity.kind === "agent" || entity.kind === "call") return [entity.value.finishedAt ?? 0];
718
+ if (entity.kind === "item") return [entity.value.finishedAt ?? 0];
719
+ return [];
720
+ }).filter((value) => value > 0);
721
+ const finishedAt = hasActive ? snapshot.now : finishes.length > 0 ? Math.max(...finishes) : void 0;
722
+ return {
723
+ ...panel,
724
+ status,
725
+ completed: progressEntities.filter(
726
+ (entity) => entity.status === "completed" || entity.status === "done"
727
+ ).length,
728
+ total: Math.max(panel.total, progressEntities.length),
729
+ ...agents.length > 0 ? { agents: agents.length } : {},
730
+ ...tokens > 0 ? { tokens } : {},
731
+ ...startedAt && finishedAt ? { elapsedMs: Math.max(0, finishedAt - startedAt) } : {}
732
+ };
733
+ };
734
+ var activityEntitiesByPanel = (snapshot, run) => {
735
+ const calls = /* @__PURE__ */ new Map();
736
+ const items = /* @__PURE__ */ new Map();
737
+ const agents = /* @__PURE__ */ new Map();
738
+ const keyFor = (phaseId) => phaseId ?? UNPHASED_PANEL_ID;
739
+ for (const call of run.calls) {
740
+ const key = keyFor(call.phaseId);
741
+ const bucket = calls.get(key) ?? [];
742
+ bucket.push(call);
743
+ calls.set(key, bucket);
744
+ }
745
+ for (const item of run.items) {
746
+ const key = keyFor(item.phaseId);
747
+ const bucket = items.get(key) ?? [];
748
+ bucket.push(item);
749
+ items.set(key, bucket);
750
+ }
751
+ const detachedAgents = [];
752
+ for (const agent of snapshot.agents) {
753
+ if (agent.runId === run.id) {
754
+ const key = keyFor(agent.phaseId);
755
+ const bucket = agents.get(key) ?? /* @__PURE__ */ new Map();
756
+ bucket.set(agent.id, agent);
757
+ agents.set(key, bucket);
758
+ } else if (!agent.runId) {
759
+ detachedAgents.push(agent);
760
+ }
761
+ }
762
+ if (detachedAgents.length > 0) {
763
+ for (const [key, panelCalls] of calls) {
764
+ for (const call of panelCalls) {
765
+ for (const agent of detachedAgents) {
766
+ if (!linkedAgent(call, agent)) continue;
767
+ const bucket = agents.get(key) ?? /* @__PURE__ */ new Map();
768
+ bucket.set(agent.id, agent);
769
+ agents.set(key, bucket);
770
+ }
771
+ }
772
+ }
773
+ }
774
+ const keys = /* @__PURE__ */ new Set([
775
+ UNPHASED_PANEL_ID,
776
+ ...run.phases.map((phase) => phase.id)
777
+ ]);
778
+ const projected = /* @__PURE__ */ new Map();
779
+ for (const key of keys) {
780
+ const panelAgents = [...agents.get(key)?.values() ?? []];
781
+ const agentEntities = panelAgents.map((agent) => ({
782
+ id: `agent:${agent.id}`,
783
+ kind: "agent",
784
+ label: agent.name,
785
+ status: agent.status,
786
+ value: agent
787
+ }));
788
+ const callEntities = (calls.get(key) ?? []).filter((call) => {
789
+ const representedAgentLaunch = call.kind === "agent" && agentLaunchRefs.has(call.ref) && panelAgents.some((agent) => linkedAgent(call, agent));
790
+ const representedActorCreation = call.kind === "actor" && call.ref === "agents.create" && snapshot.actors.some((actor) => linkedEntityId(call.entityId, actor.id));
791
+ return !representedAgentLaunch && !representedActorCreation;
792
+ }).map((call) => ({
793
+ id: `call:${call.id}`,
794
+ kind: "call",
795
+ label: call.label,
796
+ status: call.status,
797
+ value: call
798
+ }));
799
+ const itemEntities = (items.get(key) ?? []).map((item) => ({
800
+ id: `item:${item.id}`,
801
+ kind: "item",
802
+ label: item.label,
803
+ status: item.status,
804
+ value: item
805
+ }));
806
+ projected.set(key, [...agentEntities, ...callEntities, ...itemEntities]);
807
+ }
808
+ return projected;
809
+ };
810
+ var phasePanels = (snapshot, run) => {
811
+ const panels = [];
812
+ const activityEntities = run ? activityEntitiesByPanel(snapshot, run) : /* @__PURE__ */ new Map();
813
+ if (run) {
814
+ const runActivity = {
815
+ id: UNPHASED_PANEL_ID,
816
+ name: "Run activity",
817
+ status: run.status,
818
+ completed: 0,
819
+ total: 0,
820
+ kind: "unphased"
821
+ };
822
+ if ((activityEntities.get(UNPHASED_PANEL_ID)?.length ?? 0) > 0) panels.push(runActivity);
823
+ }
824
+ panels.push(
825
+ ...run?.phases.map((phase) => ({
826
+ id: phase.id,
827
+ name: phase.name,
828
+ status: phase.status,
829
+ completed: 0,
830
+ total: phase.total ?? 0,
831
+ phase,
832
+ kind: "phase"
833
+ })) ?? []
834
+ );
835
+ const session = {
836
+ id: SESSION_PANEL_ID,
837
+ name: "Project participants & shared state",
838
+ status: "idle",
839
+ completed: 0,
840
+ total: 0,
841
+ kind: "session"
842
+ };
843
+ const sessionEntities = entitiesFor(snapshot, run, session);
844
+ if (sessionEntities.length > 0 || panels.length === 0) panels.push(session);
845
+ return panels.map(
846
+ (panel) => withPanelProgress(
847
+ snapshot,
848
+ run,
849
+ panel,
850
+ panel.kind === "session" ? sessionEntities : activityEntities.get(panel.id) ?? []
851
+ )
852
+ );
853
+ };
854
+ var matchesFilter = (status, filter) => {
855
+ if (filter === "all") return true;
856
+ if (filter === "active") return isActiveStatus(status);
857
+ if (filter === "completed") return status === "completed" || status === "done";
858
+ return status === "failed" || status === "timed_out" || status === "blocked" || status === "error";
859
+ };
860
+ var tokensFor = (snapshot, run) => snapshot.agents.filter((agent) => !run || agent.runId === run.id).reduce(
861
+ (sum, agent) => sum + (agent.usage ? agent.usage.input + agent.usage.output : 0),
862
+ 0
863
+ );
864
+
865
+ // src/ui/dashboard-presentation.ts
866
+ var statusGlyph = (status) => {
867
+ if (status === "completed" || status === "done") return "\u2713";
868
+ if (status === "failed" || status === "timed_out" || status === "error") return "\u2717";
869
+ if (status === "blocked") return "!";
870
+ if (status === "stopped" || status === "cancelled") return "\u25A0";
871
+ if (status === "queued" || status === "pending" || status === "ready") return "\u25CB";
872
+ if (status === "idle" || status === "state") return "\xB7";
873
+ if (status === "global") return "\u25C7";
874
+ return spinnerFrame();
875
+ };
876
+ var colorStatus = (theme, status, value) => {
877
+ if (status === "completed" || status === "done") return theme.fg("success", value);
878
+ if (status === "failed" || status === "timed_out" || status === "error") {
879
+ return theme.fg("error", value);
880
+ }
881
+ if (status === "blocked" || status === "warning") return theme.fg("warning", value);
882
+ if (status === "running" || status === "in_progress") return theme.fg("accent", value);
883
+ if (status === "global") return theme.fg("muted", value);
884
+ return theme.fg("dim", value);
885
+ };
886
+ var entityTail = (entity, now) => {
887
+ if (entity.kind === "main") {
888
+ const main = entity.value;
889
+ return [
890
+ "host Pi",
891
+ main.model,
892
+ main.thinking,
893
+ main.pendingMessages ? "messages queued" : void 0,
894
+ main.local ? void 0 : "remote"
895
+ ].filter((value) => Boolean(value)).join(" \xB7 ");
896
+ }
897
+ if (entity.kind === "agent") {
898
+ const agent = entity.value;
899
+ const narrative = safeText(agent.error ?? agent.text).slice(0, 140);
900
+ const summary = agent.status === "blocked" && narrative ? `needs input: ${narrative}` : (agent.status === "failed" || agent.status === "timed_out") && narrative ? `error: ${narrative}` : agent.status === "completed" && narrative ? `result: ${narrative}` : agent.currentTool ?? (agent.status === "running" ? "thinking" : void 0);
901
+ const parts = [
902
+ summary,
903
+ agent.runner,
904
+ agent.model,
905
+ agent.usage ? `${formatTokens(agent.usage.input + agent.usage.output)} tok` : void 0,
906
+ agent.toolCalls !== void 0 ? `${agent.toolCalls} tools` : void 0,
907
+ agent.startedAt ? formatDuration((agent.finishedAt ?? now) - agent.startedAt) : void 0
908
+ ];
909
+ return parts.filter((value) => Boolean(value)).join(" \xB7 ");
910
+ }
911
+ if (entity.kind === "actor") {
912
+ const actor = entity.value;
913
+ return [
914
+ actor.runner,
915
+ actor.model ?? actor.worker?.model,
916
+ actor.worker?.currentTool,
917
+ actor.worker?.usage ? `${formatTokens(actor.worker.usage.input + actor.worker.usage.output)} tok` : void 0,
918
+ `${actor.messages} msg`,
919
+ actor.queued > 0 ? `q:${actor.queued}` : void 0
920
+ ].filter((value) => Boolean(value)).join(" \xB7 ");
921
+ }
922
+ if (entity.kind === "globalActor") {
923
+ const def = entity.value;
924
+ return [
925
+ "global template",
926
+ def.runner,
927
+ def.model ?? "inherit",
928
+ def.responseMode === "directive" ? "directive" : void 0,
929
+ def.delivery !== "mailbox" ? def.delivery : void 0
930
+ ].filter((value) => Boolean(value)).join(" \xB7 ");
931
+ }
932
+ if (entity.kind === "call") {
933
+ const call = entity.value;
934
+ return [
935
+ call.ref,
936
+ call.progress,
937
+ call.metrics?.tokens !== void 0 ? `${formatTokens(call.metrics.tokens)} tok` : void 0,
938
+ call.metrics?.toolCalls !== void 0 ? `${call.metrics.toolCalls} tools` : void 0,
939
+ formatDuration((call.finishedAt ?? now) - call.startedAt)
940
+ ].filter((value) => Boolean(value)).join(" \xB7 ");
941
+ }
942
+ if (entity.kind === "item") {
943
+ const item = entity.value;
944
+ return [
945
+ item.current ?? item.detail,
946
+ item.total !== void 0 ? `${item.completed ?? 0}/${item.total}` : void 0
947
+ ].filter((value) => Boolean(value)).join(" \xB7 ");
948
+ }
949
+ if (entity.kind === "peer") {
950
+ const peer = entity.value;
951
+ return [peer.sessionId, peer.model, `${formatDuration(Math.max(0, now - peer.updatedAt))} ago`].filter((value) => Boolean(value)).join(" \xB7 ");
952
+ }
953
+ if (entity.kind === "meshParticipant") {
954
+ const participant = entity.value;
955
+ return [
956
+ participant.participant ? `project ${participant.participant.kind}` : "observed mesh agent",
957
+ `${participant.routes} route${participant.routes === 1 ? "" : "s"}`,
958
+ `${formatDuration(Math.max(0, now - participant.lastSeenAt))} ago`
959
+ ].join(" \xB7 ");
960
+ }
961
+ if (entity.kind === "meshTopic") {
962
+ const topic = entity.value;
963
+ return [
964
+ `${topic.subscribers.length} subscriber${topic.subscribers.length === 1 ? "" : "s"}`,
965
+ topic.recentEvents > 0 ? `${topic.recentEvents} recent event${topic.recentEvents === 1 ? "" : "s"}` : void 0,
966
+ topic.lastEventAt ? `${formatDuration(Math.max(0, now - topic.lastEventAt))} ago` : void 0
967
+ ].filter((value) => Boolean(value)).join(" \xB7 ");
968
+ }
969
+ if (entity.kind === "meshRoute") {
970
+ const route = entity.value;
971
+ return [
972
+ route.kind,
973
+ route.topic,
974
+ route.count > 1 ? `\xD7${route.count}` : void 0,
975
+ `${formatDuration(Math.max(0, now - route.lastAt))} ago`
976
+ ].filter((value) => Boolean(value)).join(" \xB7 ");
977
+ }
978
+ if (entity.kind === "component") {
979
+ return [
980
+ entity.value.guarantee,
981
+ entity.value.parentId ? `child of ${entity.value.parentId}` : void 0,
982
+ (entity.value.effects?.length ?? 0) > 0 ? `${entity.value.effects.length} effects` : void 0,
983
+ entity.value.requirements.length > 0 ? `${entity.value.requirements.length} requirements` : void 0,
984
+ entity.value.provisions.length > 0 ? `${entity.value.provisions.length} provisions` : void 0
985
+ ].filter((value) => Boolean(value)).join(" \xB7 ");
986
+ }
987
+ return [entity.value.owner, entity.value.detail, `v${entity.value.version}`].filter((value) => Boolean(value)).join(" \xB7 ");
988
+ };
989
+
990
+ // src/ui/dashboard-detail.ts
991
+ import {
992
+ Markdown,
993
+ truncateToWidth as truncateToWidth2,
994
+ wrapTextWithAnsi,
995
+ visibleWidth as visibleWidth2
996
+ } from "@earendil-works/pi-tui";
997
+
998
+ // src/ui/state-file-preview.ts
999
+ import fs from "node:fs";
1000
+ import path from "node:path";
1001
+ import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
1002
+ var MAX_FILE_BYTES = 64 * 1024;
1003
+ var MAX_FILE_LINES = 240;
1004
+ var CACHE_LIMIT = 64;
1005
+ var cache = /* @__PURE__ */ new Map();
1006
+ var candidatePath = (entry) => {
1007
+ const value = entry.value;
1008
+ if (value && typeof value === "object" && !Array.isArray(value)) {
1009
+ const record = value;
1010
+ const candidate = record.file ?? record.path;
1011
+ if (typeof candidate === "string" && candidate.trim()) return candidate.trim();
1012
+ }
1013
+ return entry.key.startsWith("state/complexity/") ? entry.key.slice("state/complexity/".length) : void 0;
1014
+ };
1015
+ var inside = (root, candidate) => {
1016
+ const relative = path.relative(root, candidate);
1017
+ return relative === "" || !relative.startsWith(`..${path.sep}`) && relative !== "..";
1018
+ };
1019
+ var loadStateFilePreview = (entry, cwd) => {
1020
+ const candidate = candidatePath(entry);
1021
+ if (!candidate || path.isAbsolute(candidate) || !cwd) return void 0;
1022
+ try {
1023
+ const root = fs.realpathSync(cwd);
1024
+ const absolute = fs.realpathSync(path.resolve(root, candidate));
1025
+ if (!inside(root, absolute)) return void 0;
1026
+ const stat = fs.statSync(absolute);
1027
+ if (!stat.isFile()) return void 0;
1028
+ const cacheKey = `${absolute}\0${stat.mtimeMs}\0${stat.size}`;
1029
+ const cached = cache.get(cacheKey);
1030
+ if (cached) {
1031
+ cache.delete(cacheKey);
1032
+ cache.set(cacheKey, cached);
1033
+ return cached;
1034
+ }
1035
+ const bytes = Math.min(stat.size, MAX_FILE_BYTES);
1036
+ const descriptor = fs.openSync(absolute, "r");
1037
+ const buffer = Buffer.alloc(bytes);
1038
+ try {
1039
+ if (bytes > 0) fs.readSync(descriptor, buffer, 0, bytes, 0);
1040
+ } finally {
1041
+ fs.closeSync(descriptor);
1042
+ }
1043
+ if (buffer.includes(0)) return void 0;
1044
+ const decoded = buffer.toString("utf8").replace(/\r\n?/g, "\n");
1045
+ const allLines = decoded.split("\n");
1046
+ const boundedLines = allLines.slice(0, MAX_FILE_LINES);
1047
+ const preview = {
1048
+ path: (path.relative(root, absolute) || path.basename(absolute)).split(path.sep).join("/"),
1049
+ absolutePath: absolute,
1050
+ language: languageFromPath(absolute) ?? "text",
1051
+ content: boundedLines.join("\n"),
1052
+ lines: boundedLines,
1053
+ truncated: stat.size > bytes || allLines.length > boundedLines.length
1054
+ };
1055
+ cache.set(cacheKey, preview);
1056
+ while (cache.size > CACHE_LIMIT) cache.delete(cache.keys().next().value);
1057
+ return preview;
1058
+ } catch {
1059
+ return void 0;
1060
+ }
1061
+ };
1062
+ var renderStateFilePreview = (preview, theme, width, maxLines, invalidate) => {
1063
+ if (width <= 0 || maxLines <= 0) return [];
1064
+ const shown = preview.lines.slice(0, maxLines);
1065
+ const fileLines = highlightFileLines(
1066
+ preview.absolutePath,
1067
+ preview.language,
1068
+ 0,
1069
+ shown.length,
1070
+ invalidate
1071
+ );
1072
+ const fileVerified = fileLines !== null && fileLines.every((line, index) => line.raw === (shown[index] ?? "").replace(/\t/g, " "));
1073
+ const highlighted = fileVerified ? fileLines.map((line) => line.ansi || " ") : highlightCode(shown.join("\n"), preview.language, invalidate) ?? shown.map((line) => theme.fg("mdCodeBlock", safeText(line) || " "));
1074
+ const digits = String(Math.max(1, shown.length)).length;
1075
+ const output = highlighted.map((line, index) => {
1076
+ const gutter = theme.fg("dim", `${String(index + 1).padStart(digits)} \u2502 `);
1077
+ return truncateToWidth(gutter + line, width, "");
1078
+ });
1079
+ if ((preview.truncated || preview.lines.length > shown.length) && output.length < maxLines) {
1080
+ const omitted = Math.max(0, preview.lines.length - shown.length);
1081
+ const label = omitted > 0 ? `\u2026 ${omitted}+ lines omitted` : "\u2026 file truncated";
1082
+ output.push(truncateToWidth(theme.fg("dim", label), width, ""));
1083
+ }
1084
+ return output.filter((line) => visibleWidth(line) <= width);
1085
+ };
1086
+
1087
+ // src/ui/dashboard-detail.ts
1088
+ var transcriptMarkdownTheme = (theme, invalidate) => ({
1089
+ heading: (text) => theme.fg("mdHeading", text),
1090
+ link: (text) => theme.fg("mdLink", text),
1091
+ linkUrl: (text) => theme.fg("mdLinkUrl", text),
1092
+ code: (text) => theme.fg("mdCode", text),
1093
+ codeBlock: (text) => theme.fg("mdCodeBlock", text),
1094
+ codeBlockBorder: (text) => theme.fg("mdCodeBlockBorder", text),
1095
+ quote: (text) => theme.fg("mdQuote", text),
1096
+ quoteBorder: (text) => theme.fg("mdQuoteBorder", text),
1097
+ hr: (text) => theme.fg("mdHr", text),
1098
+ listBullet: (text) => theme.fg("mdListBullet", text),
1099
+ bold: (text) => theme.bold(text),
1100
+ italic: (text) => theme.italic(text),
1101
+ underline: (text) => theme.underline(text),
1102
+ strikethrough: (text) => theme.strikethrough(text),
1103
+ highlightCode: (code, lang) => highlightCode(code, lang ?? "", invalidate) ?? code.split("\n").map((line) => theme.fg("mdCodeBlock", line))
1104
+ });
1105
+ var TRANSCRIPT_EXPANDED_TOOL_LINES = 40;
1106
+ var TRANSCRIPT_STRUCTURED_LINES = 40;
1107
+ var safeMarkdownText = (value) => value.replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, "").replace(/\r\n?/g, "\n").replace(/[\u0000-\u0008\u000b-\u000c\u000e-\u001f\u007f-\u009f]/g, " ");
1108
+ var DashboardDetailRenderer = class {
1109
+ constructor(tui, theme, snapshot, options) {
1110
+ this.tui = tui;
1111
+ this.theme = theme;
1112
+ this.snapshot = snapshot;
1113
+ this.agentTranscript = options.agentTranscript;
1114
+ this.actorTranscript = options.actorTranscript;
1115
+ this.codePreviewSettings = options.codePreviewSettings;
1116
+ this.actorDefaultTools = options.actorDefaultTools;
1117
+ }
1118
+ detailView = "summary";
1119
+ detailScroll = 0;
1120
+ detailMaxScroll = 0;
1121
+ transcriptPageAnchor;
1122
+ transcriptFollowing = true;
1123
+ transcriptToolsExpanded = false;
1124
+ actionHint = "";
1125
+ toolToggleHint = "";
1126
+ transcriptMarkdown = /* @__PURE__ */ new Map();
1127
+ highlightInvalidate = () => this.tui.requestRender();
1128
+ agentTranscript;
1129
+ actorTranscript;
1130
+ codePreviewSettings;
1131
+ actorDefaultTools;
1132
+ render(width, snapshot, entity, state, actionHint, toolToggleHint) {
1133
+ this.detailView = state.view;
1134
+ this.detailScroll = state.scroll;
1135
+ this.transcriptPageAnchor = state.pageAnchor;
1136
+ this.transcriptFollowing = state.transcriptFollowing;
1137
+ this.transcriptToolsExpanded = state.transcriptToolsExpanded;
1138
+ this.actionHint = actionHint;
1139
+ this.toolToggleHint = toolToggleHint;
1140
+ const lines = this.renderDetail(width, snapshot, entity);
1141
+ return {
1142
+ lines,
1143
+ scroll: this.detailScroll,
1144
+ maxScroll: this.detailMaxScroll,
1145
+ pageAnchor: this.transcriptPageAnchor
1146
+ };
1147
+ }
1148
+ invalidate() {
1149
+ this.transcriptMarkdown.clear();
1150
+ }
1151
+ detailActionHint(_entity) {
1152
+ return this.actionHint;
1153
+ }
1154
+ transcriptToolToggleHint() {
1155
+ return this.toolToggleHint;
1156
+ }
1157
+ transcriptTarget(entity) {
1158
+ if (entity.kind === "agent" || entity.kind === "actor") return entity.value;
1159
+ return void 0;
1160
+ }
1161
+ hasTranscript(entity) {
1162
+ return entity.kind === "agent" && this.agentTranscript !== void 0 || entity.kind === "actor" && this.actorTranscript !== void 0;
1163
+ }
1164
+ transcriptFor(entity) {
1165
+ if (entity.kind === "agent") {
1166
+ return this.agentTranscript?.(entity.value, this.transcriptFollowing);
1167
+ }
1168
+ if (entity.kind === "actor") {
1169
+ return this.actorTranscript?.(entity.value, this.transcriptFollowing);
1170
+ }
1171
+ return void 0;
1172
+ }
1173
+ renderDetail(width, snapshot, entity) {
1174
+ if (width < 24) return this.renderNarrowDetail(width, snapshot, entity);
1175
+ const innerWidth = width - 2;
1176
+ const transcriptView = (entity.kind === "agent" || entity.kind === "actor") && this.detailView === "transcript";
1177
+ const actionLines = wrapPlainText(this.detailActionHint(entity), Math.max(1, innerWidth - 2), 3);
1178
+ const viewLabel = transcriptView ? ` \xB7 transcript \xB7 ${isActiveStatus(entity.status) ? "live" : entity.status}` : "";
1179
+ const kindLabel = entity.kind === "main" ? "main agent" : entity.kind === "peer" ? "peer session" : entity.kind === "meshParticipant" ? "project participant" : entity.kind === "meshTopic" ? "topic" : entity.kind === "meshRoute" ? "route" : entity.kind;
1180
+ const lines = [this.topBorder(width, `${kindLabel} \xB7 ${entity.label}${viewLabel}`)];
1181
+ const content = transcriptView ? this.transcriptLines(entity, innerWidth) : this.detailLines(entity, innerWidth, snapshot.now, snapshot.main.cwd ?? process.cwd());
1182
+ const terminalRows = this.tui.terminal?.rows ?? process.stdout.rows ?? 28;
1183
+ const maxBody = Math.max(1, Math.min(24, terminalRows - 8 - actionLines.length));
1184
+ const maxScroll = Math.max(0, content.length - maxBody);
1185
+ this.detailMaxScroll = maxScroll;
1186
+ if (transcriptView && this.transcriptFollowing) {
1187
+ this.detailScroll = maxScroll;
1188
+ } else if (transcriptView && this.transcriptPageAnchor) {
1189
+ this.detailScroll = this.transcriptPageAnchor === "end" ? maxScroll : 0;
1190
+ this.transcriptPageAnchor = void 0;
1191
+ } else {
1192
+ this.detailScroll = Math.max(0, Math.min(this.detailScroll, maxScroll));
1193
+ }
1194
+ const visible = content.slice(this.detailScroll, this.detailScroll + maxBody);
1195
+ for (const line of visible) lines.push(this.row(width, line));
1196
+ while (lines.length < maxBody + 1) lines.push(this.row(width, ""));
1197
+ lines.push(this.middleBorder(width));
1198
+ const range = content.length > maxBody ? ` \xB7 ${this.detailScroll + 1}-${Math.min(content.length, this.detailScroll + maxBody)}/${content.length}` : "";
1199
+ const navigation = transcriptView ? `\u2191\u2193/jk lazy scroll \xB7 ${this.transcriptToolToggleHint()} \xB7 g page top \xB7 G follow:${this.transcriptFollowing ? "on" : "off"}/live tail \xB7 t summary \xB7 esc back${range}` : `\u2191\u2193/jk scroll \xB7 ${this.hasTranscript(entity) ? "t transcript \xB7 " : ""}esc back${range}`;
1200
+ lines.push(this.row(width, this.theme.fg("dim", navigation)));
1201
+ for (const actionLine of actionLines) {
1202
+ lines.push(this.row(width, this.theme.fg("muted", ` ${actionLine}`)));
1203
+ }
1204
+ lines.push(this.bottomBorder(width));
1205
+ return lines.map((line) => truncateToWidth2(line, width, ""));
1206
+ }
1207
+ transcriptLines(entity, width) {
1208
+ const transcript = this.transcriptFor(entity);
1209
+ const transcriptCwd = entity.kind === "agent" ? entity.value.cwd : entity.kind === "actor" ? entity.value.worker?.cwd : void 0;
1210
+ if (!transcript || transcript.entries.length === 0) {
1211
+ return [
1212
+ this.theme.fg(
1213
+ "dim",
1214
+ isActiveStatus(entity.status) ? "Waiting for streamed agent activity\u2026" : "No retained transcript is available for this agent or actor."
1215
+ )
1216
+ ];
1217
+ }
1218
+ const lines = [];
1219
+ if (transcript.hasMore ?? transcript.truncated) {
1220
+ lines.push(this.theme.fg("dim", "\u2191 older activity available \xB7 scroll past the top to load"));
1221
+ }
1222
+ let firstTool = true;
1223
+ for (const entry of transcript.entries) {
1224
+ if (entry.kind === "tool") {
1225
+ if (this.transcriptToolsExpanded && !firstTool) lines.push("");
1226
+ firstTool = false;
1227
+ lines.push(...this.transcriptToolLines(entry, width, transcriptCwd));
1228
+ continue;
1229
+ }
1230
+ const glyph = entry.kind === "assistant" ? this.theme.fg("accent", "\u25C6") : entry.kind === "user" ? this.theme.fg("muted", "\u203A") : entry.kind === "error" ? this.theme.fg("error", "\u2717") : colorStatus(
1231
+ this.theme,
1232
+ entry.status ?? "completed",
1233
+ statusGlyph(entry.status ?? "completed")
1234
+ );
1235
+ lines.push(
1236
+ truncateToWidth2(
1237
+ `${glyph} ${this.theme.fg(
1238
+ entry.kind === "assistant" ? "accent" : "muted",
1239
+ safeText(entry.label)
1240
+ )}`,
1241
+ width,
1242
+ ""
1243
+ )
1244
+ );
1245
+ if (!entry.text) continue;
1246
+ if (entry.kind === "assistant" || entry.kind === "user") {
1247
+ lines.push(
1248
+ ...this.markdownTranscriptLines(
1249
+ this.transcriptTarget(entity)?.id ?? entity.id,
1250
+ entry.id,
1251
+ entry.text,
1252
+ width
1253
+ )
1254
+ );
1255
+ continue;
1256
+ }
1257
+ for (const paragraph of entry.text.split("\n")) {
1258
+ const wrapped = wrapPlainText(paragraph, Math.max(1, width - 2), 1e4);
1259
+ for (const line of wrapped) lines.push(truncateToWidth2(` ${line}`, width, ""));
1260
+ }
1261
+ }
1262
+ if (transcript.hasNewer) {
1263
+ lines.push(this.theme.fg("dim", "\u2193 newer activity available \xB7 scroll past the bottom to load"));
1264
+ }
1265
+ return lines;
1266
+ }
1267
+ transcriptToolLines(entry, width, transcriptCwd) {
1268
+ const depth = Math.max(0, entry.depth ?? 0);
1269
+ const padding = " ".repeat(depth);
1270
+ const bodyPadding = `${padding} `;
1271
+ const glyph = colorStatus(
1272
+ this.theme,
1273
+ entry.status ?? "completed",
1274
+ statusGlyph(entry.status ?? "completed")
1275
+ );
1276
+ const status = entry.status === "running" ? " \xB7 running" : entry.status === "failed" ? " \xB7 failed" : "";
1277
+ const audit = this.transcriptToolAudit(entry);
1278
+ const context = this.codePreviewSettings ? {
1279
+ cwd: transcriptCwd ?? this.snapshot().main.cwd ?? process.cwd(),
1280
+ settings: this.codePreviewSettings,
1281
+ invalidate: this.highlightInvalidate
1282
+ } : void 0;
1283
+ const title = context ? coreToolTitle(audit, this.theme, context) : null;
1284
+ const headline = title ?? this.theme.fg("toolTitle", this.theme.bold(entry.toolName ?? entry.label));
1285
+ const collapsedSummary = !this.transcriptToolsExpanded && entry.text ? ` \xB7 ${safeText(entry.text).replace(/\s+/g, " ").trim()}` : "";
1286
+ const lines = [
1287
+ truncateToWidth2(
1288
+ `${padding}${glyph} ${headline}${this.theme.fg("dim", `${status}${collapsedSummary}`)}`,
1289
+ width,
1290
+ ""
1291
+ )
1292
+ ];
1293
+ if (!this.transcriptToolsExpanded) return lines;
1294
+ const rendered = context ? renderCoreToolBody(audit, this.theme, {
1295
+ ...context,
1296
+ expanded: true,
1297
+ maxLines: TRANSCRIPT_EXPANDED_TOOL_LINES
1298
+ }) : null;
1299
+ if (rendered) {
1300
+ for (const row of renderBoundedLines(
1301
+ rendered.lines,
1302
+ this.theme,
1303
+ this.codePreviewSettings?.diffIntensity ?? "off"
1304
+ ).render(Math.max(1, width - visibleWidth2(bodyPadding)))) {
1305
+ lines.push(truncateToWidth2(`${bodyPadding}${row}`, width, ""));
1306
+ }
1307
+ if (rendered.hidden > 0) {
1308
+ lines.push(this.theme.fg("dim", `${bodyPadding}\u2026 ${rendered.hidden} more lines`));
1309
+ }
1310
+ return lines;
1311
+ }
1312
+ if (entry.args && Object.keys(entry.args).length > 0) {
1313
+ lines.push(...this.transcriptStructuredLines("input", entry.args, width, bodyPadding));
1314
+ } else if (entry.text) {
1315
+ for (const row of wrapPlainText(
1316
+ entry.text,
1317
+ Math.max(1, width - visibleWidth2(bodyPadding)),
1318
+ 1e4
1319
+ )) {
1320
+ lines.push(truncateToWidth2(`${bodyPadding}${row}`, width, ""));
1321
+ }
1322
+ }
1323
+ if (entry.result !== void 0) {
1324
+ lines.push(...this.transcriptStructuredLines("result", entry.result, width, bodyPadding));
1325
+ }
1326
+ return lines;
1327
+ }
1328
+ transcriptToolAudit(entry) {
1329
+ const rawName = entry.toolName ?? entry.label;
1330
+ const normalizedName = rawName.toLowerCase();
1331
+ const tool = normalizedName === "glob" ? "find" : ["read", "write", "edit", "bash", "powershell", "grep", "find", "ls"].includes(normalizedName) ? normalizedName : rawName;
1332
+ const rawArgs = entry.args ?? {};
1333
+ const args = { ...rawArgs };
1334
+ if (typeof rawArgs.file_path === "string" && typeof args.path !== "string") {
1335
+ args.path = rawArgs.file_path;
1336
+ }
1337
+ if (tool === "edit" && !Array.isArray(args.edits)) {
1338
+ const oldText = typeof rawArgs.old_string === "string" ? rawArgs.old_string : void 0;
1339
+ const newText = typeof rawArgs.new_string === "string" ? rawArgs.new_string : void 0;
1340
+ if (oldText !== void 0 && newText !== void 0) args.edits = [{ oldText, newText }];
1341
+ }
1342
+ return {
1343
+ ref: typeof tool === "string" ? `pi.${tool}` : `tool.${rawName}`,
1344
+ provider: "pi",
1345
+ tool,
1346
+ ...Object.keys(args).length > 0 ? { args } : {},
1347
+ ...entry.result !== void 0 ? { result: entry.result } : {},
1348
+ ...entry.status !== "running" ? { success: entry.status !== "failed" } : {}
1349
+ };
1350
+ }
1351
+ transcriptStructuredLines(label, value, width, padding) {
1352
+ const yaml = formatJsonAsYaml(value) ?? safeText(value);
1353
+ if (!yaml) return [];
1354
+ const yamlLines = yaml.split("\n");
1355
+ const shownYamlLines = yamlLines.slice(0, TRANSCRIPT_STRUCTURED_LINES);
1356
+ const highlighted = highlightCode(shownYamlLines.join("\n"), "yaml", this.highlightInvalidate) ?? shownYamlLines.map((line) => this.theme.fg("mdCodeBlock", line || " "));
1357
+ const lines = [truncateToWidth2(`${padding}${this.theme.fg("dim", `${label}:`)}`, width, "")];
1358
+ const nestedPadding = `${padding} `;
1359
+ for (const row of highlighted) {
1360
+ for (const wrapped of wrapTextWithAnsi(row, Math.max(1, width - visibleWidth2(nestedPadding)))) {
1361
+ lines.push(truncateToWidth2(`${nestedPadding}${wrapped}`, width, ""));
1362
+ if (lines.length > TRANSCRIPT_STRUCTURED_LINES) break;
1363
+ }
1364
+ if (lines.length > TRANSCRIPT_STRUCTURED_LINES) break;
1365
+ }
1366
+ const hiddenLines = Math.max(0, yamlLines.length - shownYamlLines.length);
1367
+ if (hiddenLines > 0) {
1368
+ lines.push(this.theme.fg("dim", `${nestedPadding}\u2026 ${hiddenLines} more lines`));
1369
+ }
1370
+ return lines;
1371
+ }
1372
+ markdownTranscriptLines(agentId, entryId, text, width) {
1373
+ return this.markdownLines(`transcript:${agentId}:${entryId}`, text, width);
1374
+ }
1375
+ markdownLines(key, text, width, indent = 2) {
1376
+ const markdown = safeMarkdownText(text);
1377
+ if (!markdown.trim()) return [];
1378
+ let cached = this.transcriptMarkdown.get(key);
1379
+ if (!cached || cached.text !== markdown) {
1380
+ cached = {
1381
+ text: markdown,
1382
+ component: new Markdown(
1383
+ markdown,
1384
+ 0,
1385
+ 0,
1386
+ transcriptMarkdownTheme(this.theme, () => {
1387
+ this.transcriptMarkdown.delete(key);
1388
+ this.tui.requestRender();
1389
+ })
1390
+ )
1391
+ };
1392
+ this.transcriptMarkdown.delete(key);
1393
+ this.transcriptMarkdown.set(key, cached);
1394
+ while (this.transcriptMarkdown.size > 128) {
1395
+ const oldest = this.transcriptMarkdown.keys().next().value;
1396
+ if (!oldest) break;
1397
+ this.transcriptMarkdown.delete(oldest);
1398
+ }
1399
+ }
1400
+ const padding = " ".repeat(Math.max(0, indent));
1401
+ return cached.component.render(Math.max(1, width - visibleWidth2(padding))).map((line) => truncateToWidth2(`${padding}${line}`, width, ""));
1402
+ }
1403
+ detailLines(entity, width, now, cwd) {
1404
+ const lines = [];
1405
+ const field = (label, value) => {
1406
+ const text = safeText(value);
1407
+ if (!text) return;
1408
+ const prefix = `${this.theme.fg("dim", `${label}:`)} `;
1409
+ const wrapped = wrapPlainText(text, Math.max(1, width - visibleWidth2(prefix)), 12);
1410
+ if (wrapped[0]) lines.push(truncateToWidth2(prefix + wrapped[0], width));
1411
+ for (const continuation of wrapped.slice(1)) {
1412
+ lines.push(truncateToWidth2(" ".repeat(visibleWidth2(prefix)) + continuation, width));
1413
+ }
1414
+ };
1415
+ const markdownField = (label, value, key) => {
1416
+ if (!value?.trim()) return;
1417
+ lines.push(this.theme.fg("dim", `${label}:`));
1418
+ lines.push(...this.markdownLines(`detail:${entity.id}:${key}`, value, width));
1419
+ };
1420
+ const structuredField = (label, value) => {
1421
+ if (value === void 0) return;
1422
+ const yaml = formatJsonAsYaml(value);
1423
+ if (yaml === void 0) {
1424
+ field(label, value);
1425
+ return;
1426
+ }
1427
+ lines.push(this.theme.fg("dim", `${label}:`));
1428
+ const highlighted = highlightCode(yaml, "yaml", this.highlightInvalidate) ?? yaml.split("\n").map((line) => this.theme.fg("mdCodeBlock", line || " "));
1429
+ for (const highlightedLine of highlighted) {
1430
+ for (const wrapped of wrapTextWithAnsi(highlightedLine, Math.max(1, width - 2))) {
1431
+ lines.push(truncateToWidth2(` ${wrapped}`, width, ""));
1432
+ }
1433
+ }
1434
+ };
1435
+ const stringOutputField = (label, value) => {
1436
+ if (typeof value !== "string") return;
1437
+ markdownField(label, value, label.toLowerCase());
1438
+ };
1439
+ const objectOutputField = (label, value) => {
1440
+ if (typeof value.output === "string" || typeof value.text === "string" || typeof value.content === "string") {
1441
+ stringOutputField(label, value.output ?? value.text ?? value.content);
1442
+ return;
1443
+ }
1444
+ structuredField(label, value);
1445
+ };
1446
+ const outputField = (label, value) => {
1447
+ if (value === void 0) return;
1448
+ if (typeof value === "string") {
1449
+ stringOutputField(label, value);
1450
+ return;
1451
+ }
1452
+ if (value !== null && typeof value === "object" && !Array.isArray(value)) {
1453
+ objectOutputField(label, value);
1454
+ return;
1455
+ }
1456
+ structuredField(label, value);
1457
+ };
1458
+ const coreCallPreview = (call) => {
1459
+ const settings = this.codePreviewSettings;
1460
+ const tool = call.ref.startsWith("pi.") ? call.ref.slice(3) : "";
1461
+ if (!settings || !["bash", "powershell", "read", "write", "edit", "grep", "find", "ls"].includes(tool)) {
1462
+ return false;
1463
+ }
1464
+ const success = call.status === "completed" ? true : call.status === "failed" ? false : void 0;
1465
+ const audit = {
1466
+ ref: call.ref,
1467
+ provider: "pi",
1468
+ tool,
1469
+ ...call.args !== void 0 ? { args: call.args } : {},
1470
+ ...call.result !== void 0 ? { result: call.result } : {},
1471
+ ...call.preview !== void 0 ? { preview: call.preview } : {},
1472
+ ...success !== void 0 ? { success } : {},
1473
+ startedAt: call.startedAt,
1474
+ ...call.finishedAt !== void 0 ? { endedAt: call.finishedAt } : {}
1475
+ };
1476
+ const context = {
1477
+ cwd: this.snapshot().main.cwd ?? process.cwd(),
1478
+ settings,
1479
+ invalidate: this.highlightInvalidate
1480
+ };
1481
+ const title = coreToolTitle(audit, this.theme, context);
1482
+ const rendered = renderCoreToolBody(audit, this.theme, {
1483
+ ...context,
1484
+ expanded: true,
1485
+ maxLines: 200
1486
+ });
1487
+ if (!rendered) return false;
1488
+ lines.push(this.theme.fg("dim", "Preview:"));
1489
+ const body = renderBoundedLines(
1490
+ [...title ? [title] : [], ...rendered.lines],
1491
+ this.theme,
1492
+ settings.diffIntensity
1493
+ ).render(Math.max(1, width - 2));
1494
+ for (const row of body) lines.push(truncateToWidth2(` ${row}`, width, ""));
1495
+ if (rendered.hidden > 0) {
1496
+ lines.push(this.theme.fg("muted", ` \u2026 ${rendered.hidden} more lines`));
1497
+ }
1498
+ return true;
1499
+ };
1500
+ const argumentField = (call) => {
1501
+ const args = call.args;
1502
+ if (!args || Object.keys(args).length === 0) return;
1503
+ const stringValue = (key) => typeof args[key] === "string" ? args[key] : void 0;
1504
+ if (call.ref === "pi.bash" || call.ref === "pi.powershell") {
1505
+ const command = stringValue("command");
1506
+ const language = call.ref === "pi.powershell" ? "powershell" : "bash";
1507
+ if (command) {
1508
+ markdownField("Command", `\`\`\`${language}
1509
+ ${command}
1510
+ \`\`\``, "command");
1511
+ }
1512
+ }
1513
+ const edits = Array.isArray(args.edits) ? args.edits : [];
1514
+ if (call.ref === "pi.edit" && edits.length > 0) {
1515
+ lines.push(this.theme.fg("dim", "Edits:"));
1516
+ const diff = nestedEditDiff(
1517
+ {
1518
+ ref: call.ref,
1519
+ tool: call.ref.split(".")[1] ?? call.ref,
1520
+ args
1521
+ },
1522
+ this.theme,
1523
+ this.highlightInvalidate
1524
+ );
1525
+ if (diff) {
1526
+ for (const line of diff) lines.push(truncateToWidth2(` ${line}`, width, ""));
1527
+ } else {
1528
+ structuredField("Edits", edits);
1529
+ }
1530
+ }
1531
+ const content = stringValue("content");
1532
+ if (call.ref === "pi.write" && content !== void 0) {
1533
+ const path2 = stringValue("path") ?? "";
1534
+ const extension = path2.includes(".") ? path2.split(".").at(-1) : "";
1535
+ markdownField("Content", "```" + (extension || "text") + "\n" + content + "\n```", "content");
1536
+ }
1537
+ const renderedKeys = /* @__PURE__ */ new Set(["command", "edits", "content"]);
1538
+ const remaining = Object.fromEntries(
1539
+ Object.entries(args).filter(([key]) => !renderedKeys.has(key))
1540
+ );
1541
+ if (Object.keys(remaining).length > 0) structuredField("Input", remaining);
1542
+ };
1543
+ field("Status", entity.status);
1544
+ if (entity.kind === "main") {
1545
+ const main = entity.value;
1546
+ field("ID", main.id);
1547
+ field("Scope", "user-facing Pi session");
1548
+ field("Runner", main.runner);
1549
+ field("Model", main.model);
1550
+ field("Thinking", main.thinking);
1551
+ field("Transport", main.transport);
1552
+ field("Session", main.sessionId);
1553
+ field("Working directory", main.cwd);
1554
+ field("Pending messages", main.pendingMessages ? "yes" : "no");
1555
+ field("Local owner", main.local ? "yes" : "no");
1556
+ field(
1557
+ "Elapsed",
1558
+ main.startedAt ? formatDuration(Math.max(0, now - main.startedAt)) : void 0
1559
+ );
1560
+ } else if (entity.kind === "peer") {
1561
+ const peer = entity.value;
1562
+ field("ID", peer.id);
1563
+ field("Scope", "concurrent root Pi session");
1564
+ field("Runner", peer.runner);
1565
+ field("Model", peer.model);
1566
+ field("Thinking", peer.thinking);
1567
+ field("Transport", peer.transport);
1568
+ field("Session", peer.sessionId);
1569
+ field("Working directory", peer.cwd);
1570
+ field("Pending messages", peer.pendingMessages ? "yes" : "no");
1571
+ field("Last heartbeat", new Date(peer.updatedAt).toLocaleString());
1572
+ field("Elapsed", formatDuration(Math.max(0, now - peer.startedAt)));
1573
+ } else if (entity.kind === "agent") {
1574
+ const agent = entity.value;
1575
+ field("ID", agent.id);
1576
+ field("Runner", agent.runner);
1577
+ field("Residency", agent.residency ?? "session");
1578
+ field("Model", agent.model);
1579
+ field("Thinking", agent.thinking);
1580
+ field("Transport", agent.transport);
1581
+ field("Activity", agent.currentTool);
1582
+ field("Elapsed", agent.startedAt ? formatDuration((agent.finishedAt ?? now) - agent.startedAt) : void 0);
1583
+ field("Usage", agent.usage ? `${formatTokens(agent.usage.input + agent.usage.output)} tokens \xB7 ${agent.toolCalls ?? 0} tools \xB7 ${agent.turns ?? 0} turns \xB7 $${agent.usage.cost.toFixed(4)}` : void 0);
1584
+ markdownField("Task", agent.task, "task");
1585
+ field("Branch", agent.branch);
1586
+ field("Worktree", agent.worktree);
1587
+ field("Attach", agent.attachCommand);
1588
+ field("Error", agent.error);
1589
+ markdownField("Result", agent.text, "result");
1590
+ structuredField("Value", agent.value);
1591
+ } else if (entity.kind === "actor") {
1592
+ const actor = entity.value;
1593
+ field("ID", actor.id);
1594
+ field("Runner", actor.runner);
1595
+ field("Residency", actor.residency ?? "session");
1596
+ field("Execution owner", actor.ownerHostId);
1597
+ field("Runtime", actor.local === false ? "remote shared owner" : "local owner");
1598
+ field("Session model", actor.binding?.model ?? "inherit project");
1599
+ field("Project model", actor.projectDefaults?.model ?? "inherit Fabric");
1600
+ field("Effective model", actor.model ?? "Fabric default");
1601
+ field("Active worker model", actor.worker?.model);
1602
+ field("Session thinking", actor.binding?.thinking ?? "inherit project");
1603
+ field("Project thinking", actor.projectDefaults?.thinking ?? "inherit Fabric");
1604
+ field("Effective reasoning", actor.thinking ?? "Fabric default");
1605
+ field("Active worker thinking", actor.worker?.thinking);
1606
+ field("Delivery", `${actor.delivery} \xB7 ${actor.responseMode}`);
1607
+ field("Trigger turn", actor.triggerTurn ? "yes" : "no");
1608
+ field("Activity", actor.worker?.currentTool);
1609
+ field("Transport", actor.worker?.transport);
1610
+ field(
1611
+ "Usage",
1612
+ actor.worker?.usage ? `${formatTokens(actor.worker.usage.input + actor.worker.usage.output)} tokens \xB7 ${actor.worker.toolCalls ?? 0} tools` : void 0
1613
+ );
1614
+ field("Host events", actor.events.join(", "));
1615
+ field("Tools", actor.tools?.join(", ") ?? `inherited (${this.actorDefaultTools.join(", ")})`);
1616
+ field("Topics", actor.topics.join(", "));
1617
+ field("Queue", actor.queued);
1618
+ field("Last error", actor.lastError);
1619
+ field("Instructions", actor.instructions);
1620
+ if (actor.recentMessages.length > 0) {
1621
+ lines.push("");
1622
+ lines.push(this.theme.fg("accent", "Recent mailbox"));
1623
+ for (const message of actor.recentMessages) {
1624
+ const text = message.text ?? message.error ?? message.action ?? formatActorDataPreview(message.data) ?? "data";
1625
+ field(
1626
+ `${message.direction === "in" ? "\u2192" : "\u2190"} ${formatClock(message.createdAt)} ${message.source}`,
1627
+ text
1628
+ );
1629
+ }
1630
+ }
1631
+ } else if (entity.kind === "call") {
1632
+ const call = entity.value;
1633
+ field("Reference", call.ref);
1634
+ field("ID", call.id);
1635
+ field("Kind", call.entityKind ?? call.kind);
1636
+ field("Progress", call.progress);
1637
+ field("Elapsed", formatDuration((call.finishedAt ?? now) - call.startedAt));
1638
+ field("Tokens", call.metrics?.tokens);
1639
+ field("Tool calls", call.metrics?.toolCalls);
1640
+ field("Cost", call.metrics?.cost);
1641
+ field("Entity", call.entityId);
1642
+ const renderedCorePreview = coreCallPreview(call);
1643
+ if (!renderedCorePreview) argumentField(call);
1644
+ field("Error", call.error);
1645
+ if (!renderedCorePreview) outputField("Output", call.result);
1646
+ } else if (entity.kind === "item") {
1647
+ const item = entity.value;
1648
+ field("ID", item.id);
1649
+ field("Kind", item.kind);
1650
+ field("Progress", item.total !== void 0 ? `${item.completed ?? 0}/${item.total}` : void 0);
1651
+ field("Current", item.current);
1652
+ field("Detail", item.detail);
1653
+ structuredField("Data", item.data);
1654
+ } else if (entity.kind === "globalActor") {
1655
+ const def = entity.value;
1656
+ field("Scope", "global template");
1657
+ field("ID", def.id);
1658
+ field("Runner", def.runner);
1659
+ field("Residency", def.residency ?? "session");
1660
+ field("Delivery", `${def.delivery} \xB7 ${def.responseMode}`);
1661
+ field("Model", def.model ?? "inherit");
1662
+ field("Thinking", def.thinking ?? "inherit");
1663
+ field("Host events", def.events.join(", "));
1664
+ field("Topics", def.topics.join(", "));
1665
+ field("Trigger turn", def.triggerTurn ? "yes" : "no");
1666
+ field("Coalesce", def.coalesce ? "yes" : "no");
1667
+ field("Created", new Date(def.createdAt).toLocaleString());
1668
+ field("Updated", new Date(def.updatedAt).toLocaleString());
1669
+ field("Instructions", def.instructions);
1670
+ } else if (entity.kind === "meshParticipant") {
1671
+ const participant = entity.value;
1672
+ const canonical = participant.participant;
1673
+ field("Scope", canonical ? `project ${canonical.kind}` : "observed mesh agent");
1674
+ field("Identity", participant.id);
1675
+ field("Root", canonical?.rootId);
1676
+ field("Parent", canonical?.parentId);
1677
+ field("Owner host", canonical?.ownerHostId);
1678
+ field("Owner identity", canonical?.ownerIdentityId);
1679
+ field("Residency", canonical?.residency ?? "session");
1680
+ field("Runner", canonical?.runner);
1681
+ field("Transport", canonical?.transport);
1682
+ field("Capabilities", canonical?.capabilities.join(", "));
1683
+ field("Local", canonical ? canonical.local ? "yes" : "no" : void 0);
1684
+ field("Observed routes", participant.routes);
1685
+ field("Last activity", new Date(participant.lastSeenAt).toLocaleString());
1686
+ field("Current work", canonical?.currentTool);
1687
+ } else if (entity.kind === "meshTopic") {
1688
+ const topic = entity.value;
1689
+ field("Scope", "project mesh topic");
1690
+ field("ID", topic.id);
1691
+ field("System topic", topic.system ? "yes" : "no");
1692
+ field("Subscribers", topic.subscribers.map((subscriber) => subscriber.name).join(", "));
1693
+ field("Recent events", topic.recentEvents);
1694
+ field(
1695
+ "Last activity",
1696
+ topic.lastEventAt ? new Date(topic.lastEventAt).toLocaleString() : void 0
1697
+ );
1698
+ } else if (entity.kind === "meshRoute") {
1699
+ const route = entity.value;
1700
+ field("Scope", "recent project mesh route");
1701
+ field("From", `${route.fromName} (${route.fromKind}:${route.fromId})`);
1702
+ field("To", `${route.targetName} (${route.targetKind}:${route.targetId})`);
1703
+ field("Topic", route.topic);
1704
+ field("Event kind", route.kind);
1705
+ field("Deliveries", route.count);
1706
+ field("Last activity", new Date(route.lastAt).toLocaleString());
1707
+ markdownField("Payload text", route.text, "route-text");
1708
+ } else if (entity.kind === "component") {
1709
+ const component = entity.value;
1710
+ field("Definition", component.component);
1711
+ field("Parent", component.parentId);
1712
+ field("Guarantee", component.guarantee);
1713
+ const componentEffects = component.effects ?? [];
1714
+ const visibleEffects = componentEffects.slice(0, 8).map(
1715
+ (effect) => `${effect.label}: ${effect.kind}/${effect.ordering} [${effect.resources.join(", ")}]`
1716
+ );
1717
+ if (componentEffects.length > visibleEffects.length) {
1718
+ visibleEffects.push(`+${componentEffects.length - visibleEffects.length} more`);
1719
+ }
1720
+ field("Effects", visibleEffects.join("; "));
1721
+ field("Effect conflicts", component.effectConflicts?.map(
1722
+ (conflict) => formatFabricEffectConflict(
1723
+ conflict.withComponent,
1724
+ conflict.resources,
1725
+ conflict.reason
1726
+ )
1727
+ ).join("; "));
1728
+ field("Requirements", component.requirements.join(", "));
1729
+ field("Provisions", component.provisions.join(", "));
1730
+ field("Missing", component.missing.join(", "));
1731
+ field("Optional missing", component.optionalMissing.join(", "));
1732
+ field("Target digest", component.targetDigest);
1733
+ field("Error", component.error);
1734
+ field("Updated", new Date(component.updatedAt).toLocaleString());
1735
+ } else {
1736
+ const entry = entity.value;
1737
+ field("Key", entry.key);
1738
+ field("Owner", entry.owner);
1739
+ field("Version", entry.version);
1740
+ field("Updated", new Date(entry.updatedAt).toLocaleString());
1741
+ field("Detail", entry.detail);
1742
+ const filePreview = loadStateFilePreview(entry, cwd);
1743
+ if (filePreview) {
1744
+ field("File", filePreview.path);
1745
+ lines.push(this.theme.fg("dim", "Preview:"));
1746
+ lines.push(...renderStateFilePreview(
1747
+ filePreview,
1748
+ this.theme,
1749
+ width,
1750
+ 120,
1751
+ this.highlightInvalidate
1752
+ ));
1753
+ }
1754
+ structuredField("Value", entry.value);
1755
+ }
1756
+ return lines.length > 0 ? lines : [this.theme.fg("dim", "No details")];
1757
+ }
1758
+ renderNarrowDetail(width, snapshot, entity) {
1759
+ const transcriptView = (entity.kind === "agent" || entity.kind === "actor") && this.detailView === "transcript";
1760
+ const content = transcriptView ? this.transcriptLines(entity, width) : this.detailLines(entity, width, snapshot.now, snapshot.main.cwd ?? process.cwd());
1761
+ const terminalRows = this.tui.terminal?.rows ?? process.stdout.rows ?? 28;
1762
+ const maxBody = Math.max(1, terminalRows - 2);
1763
+ this.detailMaxScroll = Math.max(0, content.length - maxBody);
1764
+ if (transcriptView && this.transcriptFollowing) {
1765
+ this.detailScroll = this.detailMaxScroll;
1766
+ } else if (transcriptView && this.transcriptPageAnchor) {
1767
+ this.detailScroll = this.transcriptPageAnchor === "end" ? this.detailMaxScroll : 0;
1768
+ this.transcriptPageAnchor = void 0;
1769
+ } else {
1770
+ this.detailScroll = Math.max(0, Math.min(this.detailScroll, this.detailMaxScroll));
1771
+ }
1772
+ const title = `${entity.label}${transcriptView ? " \xB7 transcript" : ""}`;
1773
+ const hint = transcriptView ? `${this.transcriptToolToggleHint()} \xB7 g page top \xB7 G follow:${this.transcriptFollowing ? "on" : "off"}/tail \xB7 t summary \xB7 esc` : `${this.hasTranscript(entity) ? "t transcript \xB7 " : ""}esc`;
1774
+ return [title, ...content.slice(this.detailScroll, this.detailScroll + maxBody), hint].map((line) => truncateToWidth2(line, width, "")).filter((line) => visibleWidth2(line) > 0);
1775
+ }
1776
+ topBorder(width, title) {
1777
+ const border = (value) => this.theme.fg("borderMuted", value);
1778
+ const safeTitle = truncateToWidth2(safeText(title), Math.max(0, width - 6));
1779
+ const styledTitle = ` ${this.theme.fg("accent", safeTitle)} `;
1780
+ const remaining = Math.max(0, width - 2 - visibleWidth2(styledTitle));
1781
+ const left = Math.floor(remaining / 2);
1782
+ const right = remaining - left;
1783
+ return `${border(`\u256D${"\u2500".repeat(left)}`)}${styledTitle}${border(`${"\u2500".repeat(right)}\u256E`)}`;
1784
+ }
1785
+ middleBorder(width) {
1786
+ return this.theme.fg("borderMuted", `\u251C${"\u2500".repeat(Math.max(0, width - 2))}\u2524`);
1787
+ }
1788
+ bottomBorder(width) {
1789
+ return this.theme.fg("borderMuted", `\u2570${"\u2500".repeat(Math.max(0, width - 2))}\u256F`);
1790
+ }
1791
+ row(width, content) {
1792
+ const innerWidth = Math.max(0, width - 2);
1793
+ return `${this.theme.fg("borderMuted", "\u2502")}${padToWidth(content, innerWidth)}${this.theme.fg(
1794
+ "borderMuted",
1795
+ "\u2502"
1796
+ )}`;
1797
+ }
1798
+ };
1799
+
1800
+ // src/ui/dashboard-fabric-graph.ts
1801
+ import { truncateToWidth as truncateToWidth3, visibleWidth as visibleWidth3 } from "@earendil-works/pi-tui";
1802
+ var kindRank = {
1803
+ agent: 0,
1804
+ actor: 1,
1805
+ participant: 2,
1806
+ component: 3,
1807
+ peer: 4,
1808
+ group: 5,
1809
+ topic: 6,
1810
+ state: 7,
1811
+ route: 8,
1812
+ main: 9
1813
+ };
1814
+ var activeRank = (status) => isActiveStatus(status) && status !== "blocked" ? 0 : status === "blocked" ? 1 : 2;
1815
+ var nodeKind = (entity) => {
1816
+ if (entity.kind === "component") return "component";
1817
+ if (entity.kind === "meshParticipant") return "participant";
1818
+ if (entity.kind === "meshTopic") return "topic";
1819
+ if (entity.kind === "meshRoute") return "route";
1820
+ if (entity.kind === "globalActor" || entity.kind === "call" || entity.kind === "item") {
1821
+ return "state";
1822
+ }
1823
+ return entity.kind;
1824
+ };
1825
+ var rawIdentity = (entity) => {
1826
+ if (entity.kind === "main" || entity.kind === "peer" || entity.kind === "agent" || entity.kind === "actor") {
1827
+ return [entity.value.id, entity.value.name];
1828
+ }
1829
+ if (entity.kind === "meshParticipant") {
1830
+ return [entity.value.id, entity.value.name, entity.value.participant?.sessionId];
1831
+ }
1832
+ if (entity.kind === "meshTopic") return [entity.value.id, entity.value.name];
1833
+ if (entity.kind === "state") return [entity.value.key, entity.value.label];
1834
+ if (entity.kind === "meshRoute") return [entity.value.id];
1835
+ if (entity.kind === "component") {
1836
+ return [entity.value.id, entity.id];
1837
+ }
1838
+ return [entity.id, entity.label];
1839
+ };
1840
+ var graphLabel = (value, maxWidth) => {
1841
+ let output = "";
1842
+ let width = 0;
1843
+ for (const char of value) {
1844
+ const charWidth = visibleWidth3(char);
1845
+ if (width + charWidth > maxWidth) {
1846
+ while (width + 1 > maxWidth && output.length > 0) {
1847
+ const parts = [...output];
1848
+ const removed = parts.pop();
1849
+ output = parts.join("");
1850
+ width -= removed ? visibleWidth3(removed) : 0;
1851
+ }
1852
+ return output + "\u2026";
1853
+ }
1854
+ output += char;
1855
+ width += charWidth;
1856
+ }
1857
+ return output;
1858
+ };
1859
+ var graphGlyph = (node, animation) => {
1860
+ if (node.stale) return animation.reducedMotion ? "\xB7" : ["\u25A7", "\u25AB", "\xB7", " "][Math.floor(animation.now / 240) % 4];
1861
+ const frame = Math.floor(animation.now / 160);
1862
+ const active = isActiveStatus(node.status);
1863
+ if (node.kind === "main") return active && !animation.reducedMotion ? ["\u25C7", "\u25C8", "\u25C6", "\u25C8"][frame % 4] : "\u25C6";
1864
+ if (node.kind === "actor") {
1865
+ if ((node.queued ?? 0) > 0 && !animation.reducedMotion) return ["\u25C7", "\u25C8", "\u25C6", "\u25C8"][frame % 4];
1866
+ return "\u25C7";
1867
+ }
1868
+ if (node.kind === "peer") return "\u25C8";
1869
+ if (node.kind === "group") return "\u25B1";
1870
+ if (node.kind === "topic") {
1871
+ const hot = node.activityAt !== void 0 && animation.now - node.activityAt <= 1e4;
1872
+ return hot && !animation.reducedMotion ? ["\u25CE", "\u25C9", "\u29BF", "\u25C9"][frame % 4] : "\u25CE";
1873
+ }
1874
+ if (node.kind === "state") {
1875
+ if (/certified|committed|complete/.test(node.status) && !animation.reducedMotion) {
1876
+ return ["\u25EB", "\u25A3", "\u2726", "\u25A3"][Math.floor(animation.now / 280) % 4];
1877
+ }
1878
+ return "\u25EB";
1879
+ }
1880
+ if (node.kind === "participant") return "\u25A7";
1881
+ if (node.kind === "component") return "\u2B21";
1882
+ if (node.kind === "agent" && !animation.reducedMotion) {
1883
+ const spawnAge = node.startedAt === void 0 ? Number.POSITIVE_INFINITY : animation.now - node.startedAt;
1884
+ if (spawnAge >= 0 && spawnAge <= 1600) {
1885
+ return ["\xB7", "\u25AA", "\u25AB", "\u25A3", "\u25A0"][Math.min(4, Math.floor(spawnAge / 320))];
1886
+ }
1887
+ if (active) return ["\u25A0", "\u25A3", "\u25AA", "\u25A3"][frame % 4];
1888
+ }
1889
+ return "\u25A0";
1890
+ };
1891
+ var PARTICIPANTS_GROUP_ID = "group:participants";
1892
+ var MESH_GROUP_ID = "group:mesh";
1893
+ var TOPICS_GROUP_ID = "group:mesh:topics";
1894
+ var STATE_GROUP_ID = "group:mesh:state";
1895
+ var COMPONENTS_GROUP_ID = "group:components";
1896
+ var topologyParticipantGroup = (kind) => {
1897
+ if (kind === "actor") return { id: "actors", label: "Actors", order: 2 };
1898
+ if (kind === "agent") return { id: "agents", label: "Agents", order: 1 };
1899
+ return { id: "sessions", label: "Sessions", order: 0 };
1900
+ };
1901
+ var titleSegment = (value) => value.length === 0 ? value : value[0].toUpperCase() + value.slice(1);
1902
+ var namespaceParts = (value) => value.split(/[.:/]+/).map((part) => part.trim()).filter(Boolean);
1903
+ var topologyTopicGroupPath = (name) => {
1904
+ const parts = namespaceParts(name);
1905
+ if (parts[0] === "fabric") {
1906
+ return [
1907
+ { id: "fabric", label: "Fabric" },
1908
+ ...parts.length > 2 && parts[1] ? [{ id: `fabric:${parts[1]}`, label: titleSegment(parts[1]) }] : []
1909
+ ];
1910
+ }
1911
+ return [
1912
+ { id: "project", label: "Project topics" },
1913
+ ...parts.length > 1 && parts[0] ? [{ id: `project:${parts[0]}`, label: parts[0] }] : []
1914
+ ];
1915
+ };
1916
+ var topologyStateGroupPath = (key) => {
1917
+ const parts = key.split("/").map((part) => part.trim()).filter(Boolean);
1918
+ if (parts[0] === "state") {
1919
+ const path3 = [{ id: "world", label: "World state" }];
1920
+ if (parts[1] === "complexity") {
1921
+ let prefix2 = "world:complexity";
1922
+ path3.push({ id: prefix2, label: "Complexity" });
1923
+ for (const directory of parts.slice(2, -1)) {
1924
+ prefix2 += `:${directory}`;
1925
+ path3.push({ id: prefix2, label: directory });
1926
+ }
1927
+ } else {
1928
+ let prefix2 = "world";
1929
+ for (const directory of parts.slice(1, -1)) {
1930
+ prefix2 += `:${directory}`;
1931
+ path3.push({ id: prefix2, label: titleSegment(directory) });
1932
+ }
1933
+ }
1934
+ return path3;
1935
+ }
1936
+ if (parts[0] === "schema") {
1937
+ const path3 = [{ id: "schema", label: "Schema" }];
1938
+ const family = parts[1];
1939
+ if (family === "hypothesis") path3.push({ id: "schema:hypotheses", label: "Hypotheses" });
1940
+ else if (family === "certificate") path3.push({ id: "schema:certificates", label: "Certificates" });
1941
+ else {
1942
+ let prefix2 = "schema";
1943
+ for (const directory of parts.slice(1, -1)) {
1944
+ prefix2 += `:${directory}`;
1945
+ path3.push({ id: prefix2, label: titleSegment(directory) });
1946
+ }
1947
+ }
1948
+ return path3;
1949
+ }
1950
+ const path2 = [{ id: "project", label: "Project state" }];
1951
+ let prefix = "project";
1952
+ for (const directory of parts.slice(0, -1)) {
1953
+ prefix += `:${directory}`;
1954
+ path2.push({ id: prefix, label: directory });
1955
+ }
1956
+ return path2;
1957
+ };
1958
+ var parentReference = (entity) => {
1959
+ if (entity.kind === "agent") return entity.value.parentId ?? entity.value.actorId;
1960
+ if (entity.kind === "meshParticipant") return entity.value.participant?.parentId;
1961
+ if (entity.kind === "meshRoute") return entity.value.fromId;
1962
+ return void 0;
1963
+ };
1964
+ var buildLayout = (snapshot, entities, selectedRun, mesh) => {
1965
+ const aliases = /* @__PURE__ */ new Map();
1966
+ const entityById = new Map(entities.map((entity) => [entity.id, entity]));
1967
+ for (const entity of entities) {
1968
+ for (const identity of rawIdentity(entity)) {
1969
+ if (identity) aliases.set(identity, entity.id);
1970
+ }
1971
+ }
1972
+ const mainId = entities.find((entity) => entity.kind === "main")?.id ?? `main:${snapshot.main.id}`;
1973
+ aliases.set(snapshot.main.id, mainId);
1974
+ aliases.set(snapshot.main.name, mainId);
1975
+ aliases.set("main", mainId);
1976
+ const groups = /* @__PURE__ */ new Map();
1977
+ const ensureGroup = (id, label, parentId, order) => {
1978
+ if (!groups.has(id)) {
1979
+ groups.set(id, {
1980
+ id,
1981
+ label,
1982
+ status: "idle",
1983
+ kind: "group",
1984
+ parentId,
1985
+ order,
1986
+ x: 0,
1987
+ y: 0
1988
+ });
1989
+ }
1990
+ return id;
1991
+ };
1992
+ const ensurePath = (rootId, path2) => {
1993
+ let parentId = rootId;
1994
+ for (let index = 0; index < path2.length; index++) {
1995
+ const segment = path2[index];
1996
+ const id = `${rootId}:${segment.id}`;
1997
+ parentId = ensureGroup(id, segment.label, parentId, index);
1998
+ }
1999
+ return parentId;
2000
+ };
2001
+ const participantCategory = (entity) => {
2002
+ if (entity.kind === "actor") return topologyParticipantGroup("actor");
2003
+ if (entity.kind === "agent") return topologyParticipantGroup("agent");
2004
+ if (entity.kind === "peer") return topologyParticipantGroup("peer");
2005
+ return topologyParticipantGroup(
2006
+ entity.kind === "meshParticipant" ? entity.value.participant?.kind ?? "root" : "root"
2007
+ );
2008
+ };
2009
+ const nodes = entities.filter((entity) => entity.kind !== "meshRoute").map((entity) => {
2010
+ const parentRef = parentReference(entity);
2011
+ const explicitParentId = parentRef ? aliases.get(parentRef) : void 0;
2012
+ let parentId = explicitParentId;
2013
+ if (entity.kind !== "main") {
2014
+ if (entity.kind === "component") {
2015
+ parentId = ensureGroup(COMPONENTS_GROUP_ID, "Components", mainId, 2);
2016
+ } else if (["agent", "actor", "peer", "meshParticipant"].includes(entity.kind) && (!parentId || parentId === mainId)) {
2017
+ ensureGroup(PARTICIPANTS_GROUP_ID, "Participants", mainId, 0);
2018
+ const category = participantCategory(entity);
2019
+ parentId = ensureGroup(
2020
+ `${PARTICIPANTS_GROUP_ID}:${category.id}`,
2021
+ category.label,
2022
+ PARTICIPANTS_GROUP_ID,
2023
+ category.order
2024
+ );
2025
+ } else if (entity.kind === "meshTopic") {
2026
+ ensureGroup(MESH_GROUP_ID, "Mesh", mainId, 1);
2027
+ ensureGroup(TOPICS_GROUP_ID, "Topics", MESH_GROUP_ID, 0);
2028
+ parentId = ensurePath(TOPICS_GROUP_ID, topologyTopicGroupPath(entity.value.name));
2029
+ } else if (entity.kind === "state") {
2030
+ ensureGroup(MESH_GROUP_ID, "Mesh", mainId, 1);
2031
+ ensureGroup(STATE_GROUP_ID, "State", MESH_GROUP_ID, 1);
2032
+ parentId = ensurePath(STATE_GROUP_ID, topologyStateGroupPath(entity.value.key));
2033
+ } else if (!parentId) {
2034
+ parentId = mainId;
2035
+ }
2036
+ }
2037
+ const activityAt = entity.kind === "meshTopic" ? entity.value.lastEventAt : void 0;
2038
+ const startedAt = entity.kind === "agent" ? entity.value.startedAt : void 0;
2039
+ const queued = entity.kind === "actor" ? entity.value.queued : void 0;
2040
+ const stale = entity.kind === "meshParticipant" ? entity.value.participant?.stale : entity.kind === "agent" ? entity.value.stale : void 0;
2041
+ return {
2042
+ id: entity.id,
2043
+ label: entity.kind === "main" ? "Main" : entity.kind === "state" && entity.value.label === entity.value.key ? entity.value.key.split("/").at(-1) ?? entity.value.label : entity.label,
2044
+ status: entity.status,
2045
+ kind: nodeKind(entity),
2046
+ ...parentId ? { parentId } : {},
2047
+ ...activityAt !== void 0 ? { activityAt } : {},
2048
+ ...startedAt !== void 0 ? { startedAt } : {},
2049
+ ...queued !== void 0 ? { queued } : {},
2050
+ ...stale !== void 0 ? { stale } : {},
2051
+ x: 0,
2052
+ y: 0
2053
+ };
2054
+ });
2055
+ nodes.push(...groups.values());
2056
+ const nodeById = new Map(nodes.map((node) => [node.id, node]));
2057
+ const children = /* @__PURE__ */ new Map();
2058
+ for (const node of nodes) {
2059
+ if (!node.parentId || node.parentId === node.id || !nodeById.has(node.parentId)) continue;
2060
+ const bucket = children.get(node.parentId) ?? [];
2061
+ bucket.push(node);
2062
+ children.set(node.parentId, bucket);
2063
+ }
2064
+ const inSelectedRun = (node) => {
2065
+ const entity = entityById.get(node.id);
2066
+ return Boolean(selectedRun && entity?.kind === "agent" && entity.value.runId === selectedRun.id);
2067
+ };
2068
+ for (const bucket of children.values()) {
2069
+ bucket.sort(
2070
+ (left, right) => activeRank(left.status) - activeRank(right.status) || Number(inSelectedRun(right)) - Number(inSelectedRun(left)) || (left.order ?? 0) - (right.order ?? 0) || kindRank[left.kind] - kindRank[right.kind] || left.label.localeCompare(right.label)
2071
+ );
2072
+ }
2073
+ let nextLeafY = 0;
2074
+ const visited = /* @__PURE__ */ new Set();
2075
+ const place = (node, depth) => {
2076
+ if (visited.has(node.id)) return node.y;
2077
+ visited.add(node.id);
2078
+ node.x = depth * 20;
2079
+ const descendants = (children.get(node.id) ?? []).filter((child) => !visited.has(child.id));
2080
+ if (descendants.length === 0) {
2081
+ node.y = nextLeafY;
2082
+ nextLeafY += 2;
2083
+ return node.y;
2084
+ }
2085
+ const childRows = descendants.map((child) => place(child, depth + 1));
2086
+ node.y = (childRows[0] + childRows[childRows.length - 1]) / 2;
2087
+ return node.y;
2088
+ };
2089
+ const main = nodeById.get(mainId);
2090
+ if (main) place(main, 0);
2091
+ for (const node of nodes) {
2092
+ if (!visited.has(node.id)) place(node, 1);
2093
+ }
2094
+ const mainY = main?.y ?? 0;
2095
+ for (const node of nodes) node.y = Math.round(node.y - mainY);
2096
+ const edges = [];
2097
+ for (const node of nodes) {
2098
+ if (node.parentId && nodeById.has(node.parentId) && node.parentId !== node.id) {
2099
+ edges.push({ from: node.parentId, to: node.id, kind: node.kind === "route" ? "route" : "structure" });
2100
+ }
2101
+ }
2102
+ for (const topic of mesh.topics) {
2103
+ const target = aliases.get(topic.id) ?? aliases.get(topic.name);
2104
+ if (!target) continue;
2105
+ for (const subscriber of topic.subscribers) {
2106
+ const source = aliases.get(subscriber.id) ?? aliases.get(subscriber.name);
2107
+ if (source && source !== target) edges.push({ from: source, to: target, kind: "subscription" });
2108
+ }
2109
+ }
2110
+ for (const entity of entities) {
2111
+ if (entity.kind !== "state" || !entity.value.owner) continue;
2112
+ const owner = aliases.get(entity.value.owner);
2113
+ const target = aliases.get(entity.value.key) ?? aliases.get(entity.value.label);
2114
+ if (owner && target && owner !== target) {
2115
+ edges.push({ from: owner, to: target, kind: "subscription" });
2116
+ }
2117
+ }
2118
+ for (const dependency of snapshot.componentGraph.edges) {
2119
+ const source = aliases.get(dependency.from);
2120
+ const target = aliases.get(dependency.to);
2121
+ if (source && target && source !== target) {
2122
+ edges.push({ from: source, to: target, kind: "subscription" });
2123
+ }
2124
+ }
2125
+ for (const route of mesh.routes) {
2126
+ const source = aliases.get(route.fromId) ?? aliases.get(route.fromName);
2127
+ const target = aliases.get(route.targetId) ?? aliases.get(route.targetName) ?? aliases.get(route.topic);
2128
+ if (source && target && source !== target) {
2129
+ edges.push({ from: source, to: target, kind: "route", route });
2130
+ }
2131
+ }
2132
+ const positions = new Map(nodes.map((node) => [node.id, { x: node.x, y: node.y }]));
2133
+ for (const edge of edges) {
2134
+ if (!edge.route) continue;
2135
+ const from = nodeById.get(edge.from);
2136
+ const to = nodeById.get(edge.to);
2137
+ if (!from || !to) continue;
2138
+ positions.set(edge.route.id, {
2139
+ x: Math.round((from.x + to.x) / 2),
2140
+ y: Math.round((from.y + to.y) / 2)
2141
+ });
2142
+ }
2143
+ return { nodes, edges, positions };
2144
+ };
2145
+ var lineChar = (mask) => {
2146
+ const chars = {
2147
+ 1: "\u2502",
2148
+ 2: "\u2500",
2149
+ 3: "\u2514",
2150
+ 4: "\u2502",
2151
+ 5: "\u2502",
2152
+ 6: "\u250C",
2153
+ 7: "\u251C",
2154
+ 8: "\u2500",
2155
+ 9: "\u2518",
2156
+ 10: "\u2500",
2157
+ 11: "\u2534",
2158
+ 12: "\u2510",
2159
+ 13: "\u2524",
2160
+ 14: "\u252C",
2161
+ 15: "\u253C"
2162
+ };
2163
+ return chars[mask] ?? "\xB7";
2164
+ };
2165
+ var styleForStatus = (status) => {
2166
+ if (["failed", "timed_out", "error", "quarantined"].includes(status)) return "error";
2167
+ if (["blocked", "waiting"].includes(status)) return "warning";
2168
+ if (isActiveStatus(status)) return "success";
2169
+ return "dim";
2170
+ };
2171
+ var topologyTreeRouteNodeIds = (nodes, fromId, toId) => {
2172
+ if (fromId === toId) return [fromId];
2173
+ const ancestry = (start) => {
2174
+ const path2 = [];
2175
+ const seen = /* @__PURE__ */ new Set();
2176
+ let current = start;
2177
+ while (current && !seen.has(current)) {
2178
+ path2.push(current);
2179
+ seen.add(current);
2180
+ current = nodes.get(current)?.parentId;
2181
+ }
2182
+ return path2;
2183
+ };
2184
+ const fromAncestors = ancestry(fromId);
2185
+ const fromSet = new Set(fromAncestors);
2186
+ const toAncestors = ancestry(toId);
2187
+ const common = toAncestors.find((id) => fromSet.has(id));
2188
+ if (!common) return [fromId, toId];
2189
+ return [
2190
+ ...fromAncestors.slice(0, fromAncestors.indexOf(common) + 1),
2191
+ ...toAncestors.slice(0, toAncestors.indexOf(common)).reverse()
2192
+ ];
2193
+ };
2194
+ var routeGlyph = (route) => {
2195
+ if (route.status === "failed") return "!";
2196
+ const kind = route.kind.toLowerCase();
2197
+ if (kind.includes("certif")) return "\u2726";
2198
+ if (kind.includes("commit")) return "\u25C6";
2199
+ if (kind.includes("control") || kind.includes("steer")) return "\u21AF";
2200
+ if (kind.includes("message") || kind.includes("directive")) return "\u2709";
2201
+ return "\u2022";
2202
+ };
2203
+ var routeStyle = (route) => route.status === "failed" ? "error" : route.kind.toLowerCase().includes("certif") ? "warning" : "accent";
2204
+ var renderCanvas = (theme, layout, selectedEntityId, width, height, camera, animation) => {
2205
+ const originX = Math.round(camera.x - width / 2);
2206
+ const originY = Math.round(camera.y - height / 2);
2207
+ const cells = Array.from(
2208
+ { length: height },
2209
+ () => Array.from({ length: width }, () => ({ char: " ", style: "plain" }))
2210
+ );
2211
+ const masks = Array.from({ length: height }, () => Array(width).fill(0));
2212
+ const nodeById = new Map(layout.nodes.map((node) => [node.id, node]));
2213
+ const selectedRoute = layout.edges.find((edge) => edge.route?.id === selectedEntityId)?.route;
2214
+ const related = new Set(selectedEntityId ? [selectedEntityId] : []);
2215
+ for (const edge of layout.edges) {
2216
+ if (edge.from === selectedEntityId || edge.to === selectedEntityId || edge.route?.id === selectedEntityId) {
2217
+ related.add(edge.from);
2218
+ related.add(edge.to);
2219
+ if (edge.route) related.add(edge.route.id);
2220
+ }
2221
+ }
2222
+ const setCell = (x, y, char, style) => {
2223
+ const sx = x - originX;
2224
+ const sy = y - originY;
2225
+ if (sx < 0 || sx >= width || sy < 0 || sy >= height) return;
2226
+ cells[sy][sx] = { char, style };
2227
+ };
2228
+ const addMask = (x, y, mask) => {
2229
+ const sx = x - originX;
2230
+ const sy = y - originY;
2231
+ if (sx < 0 || sx >= width || sy < 0 || sy >= height) return;
2232
+ masks[sy][sx] = (masks[sy][sx] ?? 0) | mask;
2233
+ };
2234
+ const horizontal = (x1, x2, y) => {
2235
+ if (y < originY || y >= originY + height) return;
2236
+ const worldStart = Math.min(x1, x2);
2237
+ const worldEnd = Math.max(x1, x2);
2238
+ const start = Math.max(worldStart, originX);
2239
+ const end = Math.min(worldEnd, originX + width - 1);
2240
+ for (let x = start; x <= end; x++) {
2241
+ addMask(x, y, (x > worldStart ? 8 : 0) | (x < worldEnd ? 2 : 0));
2242
+ }
2243
+ };
2244
+ const vertical = (x, y1, y2) => {
2245
+ if (x < originX || x >= originX + width) return;
2246
+ const worldStart = Math.min(y1, y2);
2247
+ const worldEnd = Math.max(y1, y2);
2248
+ const start = Math.max(worldStart, originY);
2249
+ const end = Math.min(worldEnd, originY + height - 1);
2250
+ for (let y = start; y <= end; y++) {
2251
+ addMask(x, y, (y > worldStart ? 1 : 0) | (y < worldEnd ? 4 : 0));
2252
+ }
2253
+ };
2254
+ const edgePathPoints = (from, to) => {
2255
+ const fromEnd = from.x + Math.min(16, visibleWidth3(safeText(from.label)) + 3);
2256
+ const toStart = to.x - 2;
2257
+ const bend = Math.max(fromEnd + 1, Math.floor((fromEnd + toStart) / 2));
2258
+ const points = [];
2259
+ const appendLine = (x1, y1, x2, y2) => {
2260
+ const dx = Math.sign(x2 - x1);
2261
+ const dy = Math.sign(y2 - y1);
2262
+ const steps = Math.max(Math.abs(x2 - x1), Math.abs(y2 - y1));
2263
+ for (let step = points.length === 0 ? 0 : 1; step <= steps; step++) {
2264
+ points.push({ x: x1 + dx * step, y: y1 + dy * step });
2265
+ }
2266
+ };
2267
+ appendLine(fromEnd, from.y, bend, from.y);
2268
+ appendLine(bend, from.y, bend, to.y);
2269
+ appendLine(bend, to.y, toStart, to.y);
2270
+ return points;
2271
+ };
2272
+ const treePathPoints = (from, to) => {
2273
+ const ids = topologyTreeRouteNodeIds(nodeById, from.id, to.id);
2274
+ const points = [];
2275
+ for (let index = 0; index < ids.length - 1; index++) {
2276
+ const left = nodeById.get(ids[index]);
2277
+ const right = nodeById.get(ids[index + 1]);
2278
+ if (!left || !right) continue;
2279
+ const segment = right.parentId === left.id ? edgePathPoints(left, right) : left.parentId === right.id ? edgePathPoints(right, left).reverse() : edgePathPoints(left, right);
2280
+ const previous = points.at(-1);
2281
+ const first = segment[0];
2282
+ if (previous && first && previous.x === first.x && previous.y === first.y) segment.shift();
2283
+ points.push(...segment);
2284
+ }
2285
+ return points;
2286
+ };
2287
+ for (const edge of layout.edges) {
2288
+ if (edge.kind !== "structure") continue;
2289
+ const from = nodeById.get(edge.from);
2290
+ const to = nodeById.get(edge.to);
2291
+ if (!from || !to) continue;
2292
+ const fromEnd = from.x + Math.min(16, visibleWidth3(safeText(from.label)) + 3);
2293
+ const toStart = to.x - 2;
2294
+ const bend = Math.max(fromEnd + 1, Math.floor((fromEnd + toStart) / 2));
2295
+ horizontal(fromEnd, bend, from.y);
2296
+ vertical(bend, from.y, to.y);
2297
+ horizontal(bend, toStart, to.y);
2298
+ }
2299
+ for (let y = 0; y < height; y++) {
2300
+ for (let x = 0; x < width; x++) {
2301
+ const mask = masks[y]?.[x] ?? 0;
2302
+ if (mask) cells[y][x] = { char: lineChar(mask), style: "edge" };
2303
+ }
2304
+ }
2305
+ const traffic = /* @__PURE__ */ new Map();
2306
+ for (const edge of layout.edges) {
2307
+ if (edge.kind === "structure") continue;
2308
+ const from = nodeById.get(edge.from);
2309
+ const to = nodeById.get(edge.to);
2310
+ if (!from || !to) continue;
2311
+ if (!edge.route) {
2312
+ if (edge.from !== selectedEntityId && edge.to !== selectedEntityId) continue;
2313
+ const points = treePathPoints(from, to);
2314
+ for (let index = 0; index < points.length; index += 2) {
2315
+ const point = points[index];
2316
+ setCell(point.x, point.y, "\xB7", "accent");
2317
+ }
2318
+ continue;
2319
+ }
2320
+ const key = `${edge.from}\0${edge.to}`;
2321
+ const group = traffic.get(key) ?? { from, to, routes: [] };
2322
+ group.routes.push(edge.route);
2323
+ traffic.set(key, group);
2324
+ }
2325
+ for (const group of traffic.values()) {
2326
+ const points = treePathPoints(group.from, group.to);
2327
+ if (points.length === 0) continue;
2328
+ const selected = group.routes.find((route2) => route2.id === selectedEntityId);
2329
+ const replay = group.routes.find((route2) => route2.id === animation.replayRouteId);
2330
+ const newest = group.routes.reduce((latest, route2) => route2.lastAt > latest.lastAt ? route2 : latest);
2331
+ const route = replay ?? selected ?? newest;
2332
+ const age = Math.max(0, animation.now - route.lastAt);
2333
+ const connected = group.from.id === selectedEntityId || group.to.id === selectedEntityId;
2334
+ const visible = Boolean(replay || selected || connected || animation.showHistory || age <= 6e4);
2335
+ if (!visible) continue;
2336
+ const fresh = Boolean(replay || age <= 1e4);
2337
+ const style = selected || replay ? routeStyle(route) : fresh ? "accent" : "dim";
2338
+ const stride = fresh ? 1 : 2;
2339
+ for (let index = 0; index < points.length; index += stride) {
2340
+ const point = points[index];
2341
+ const trail = fresh && !animation.reducedMotion && index % 3 === 0 ? "\u2501" : fresh ? "\xB7" : "\u254C";
2342
+ setCell(point.x, point.y, trail, style);
2343
+ }
2344
+ const packetActive = !animation.reducedMotion && Boolean(replay || age <= 2e3);
2345
+ if (packetActive) {
2346
+ const duration = 1200;
2347
+ const phase = replay ? animation.now % duration / duration : Math.min(0.999, age / 2e3);
2348
+ const packetIndex = Math.min(points.length - 1, Math.floor(phase * points.length));
2349
+ const point = points[packetIndex];
2350
+ setCell(point.x, point.y, routeGlyph(route), routeStyle(route));
2351
+ if (route.kind.toLowerCase().includes("certif")) {
2352
+ const ripple = points[Math.max(0, points.length - 1 - packetIndex)];
2353
+ setCell(ripple.x, ripple.y, "\u2726", "warning");
2354
+ } else if (route.status === "failed") {
2355
+ const impact = points.at(-1);
2356
+ setCell(impact.x, impact.y, Math.floor(animation.now / 120) % 2 === 0 ? "\u2573" : "!", "error");
2357
+ }
2358
+ const label = graphLabel(animation.replayLabel ?? route.kind, 18);
2359
+ let offset = 2;
2360
+ for (const char of label) {
2361
+ setCell(point.x + offset, point.y, char, routeStyle(route));
2362
+ offset += visibleWidth3(char);
2363
+ }
2364
+ } else {
2365
+ const count = group.routes.reduce((total, candidate) => total + candidate.count, 0);
2366
+ if (count > 1) {
2367
+ const point = points[Math.floor(points.length / 2)];
2368
+ const label = `\xD7${count}`;
2369
+ for (let index = 0; index < label.length; index++) {
2370
+ setCell(point.x + index, point.y, label[index], style);
2371
+ }
2372
+ }
2373
+ }
2374
+ }
2375
+ for (const node of layout.nodes) {
2376
+ const selected = node.id === selectedEntityId;
2377
+ const spotlighted = !selectedRoute || related.has(node.id);
2378
+ const glyph = selected ? "\u25A3" : graphGlyph(node, animation);
2379
+ const label = graphLabel(safeText(node.label), 14);
2380
+ const nodeStyle = selected ? "accent" : !spotlighted ? "dim" : styleForStatus(node.status);
2381
+ setCell(node.x, node.y, glyph, nodeStyle);
2382
+ setCell(node.x + 1, node.y, " ", "plain");
2383
+ let offset = 0;
2384
+ for (const char of label) {
2385
+ setCell(node.x + 2 + offset, node.y, char, selected ? "accent" : spotlighted ? "muted" : "dim");
2386
+ offset += visibleWidth3(char);
2387
+ }
2388
+ }
2389
+ const apply = (style, value) => {
2390
+ if (style === "edge") return theme.fg("borderMuted", value);
2391
+ if (style === "dim") return theme.fg("dim", value);
2392
+ if (style === "muted") return theme.fg("muted", value);
2393
+ if (style === "accent") return theme.fg("accent", theme.bold(value));
2394
+ if (style === "success") return theme.fg("success", value);
2395
+ if (style === "warning") return theme.fg("warning", value);
2396
+ if (style === "error") return theme.fg("error", value);
2397
+ return value;
2398
+ };
2399
+ return cells.map((row) => {
2400
+ let rendered = "";
2401
+ let style = row[0]?.style ?? "plain";
2402
+ let run = "";
2403
+ for (const cell of row) {
2404
+ if (cell.style !== style) {
2405
+ rendered += apply(style, run);
2406
+ style = cell.style;
2407
+ run = "";
2408
+ }
2409
+ run += cell.char;
2410
+ }
2411
+ rendered += apply(style, run);
2412
+ return truncateToWidth3(rendered, width, "");
2413
+ });
2414
+ };
2415
+ var wrapInspector = (theme, label, value, width) => {
2416
+ const clean = safeText(value);
2417
+ const first = truncateToWidth3(clean, Math.max(1, width - label.length - 1), "\u2026");
2418
+ return [theme.fg("muted", `${label} ${first}`)];
2419
+ };
2420
+ var inspectorLines = (theme, entity, snapshot, run, width, height, invalidate) => {
2421
+ const inner = Math.max(1, width - 2);
2422
+ const border = (value) => theme.fg("borderMuted", value);
2423
+ const content = [];
2424
+ if (entity) {
2425
+ content.push(theme.fg("accent", theme.bold(truncateToWidth3(safeText(entity.label), inner - 2, "\u2026"))));
2426
+ content.push(colorStatus(theme, entity.status, `${statusGlyph(entity.status)} ${entity.kind} \xB7 ${entity.status}`));
2427
+ content.push("");
2428
+ content.push(theme.fg("dim", truncateToWidth3(safeText(entityTail(entity, snapshot.now)), inner - 2, "\u2026")));
2429
+ if (entity.kind === "agent") {
2430
+ const agentRun = snapshot.runs.find((candidate) => candidate.id === entity.value.runId) ?? run;
2431
+ const phase = agentRun?.phases.find((candidate) => candidate.id === entity.value.phaseId);
2432
+ if (agentRun) content.push(theme.fg("muted", `run ${safeText(agentRun.name)}`));
2433
+ if (phase) content.push(theme.fg("muted", `phase ${safeText(phase.name)}`));
2434
+ if (entity.value.currentTool) content.push(theme.fg("muted", `tool ${safeText(entity.value.currentTool)}`));
2435
+ if (entity.value.model) content.push(theme.fg("muted", `model ${safeText(entity.value.model)}`));
2436
+ if (entity.value.task) content.push(...wrapInspector(theme, "task", entity.value.task, inner - 2));
2437
+ } else if (entity.kind === "actor") {
2438
+ content.push(theme.fg("muted", `runner ${entity.value.runner}`));
2439
+ content.push(theme.fg("muted", `queue ${entity.value.queued}`));
2440
+ if (entity.value.topics.length > 0) content.push(theme.fg("muted", `${entity.value.topics.length} subscriptions`));
2441
+ } else if (entity.kind === "component") {
2442
+ content.push(theme.fg("muted", `definition ${safeText(entity.value.component)}`));
2443
+ content.push(theme.fg("muted", `guarantee ${entity.value.guarantee}`));
2444
+ if (entity.value.parentId) {
2445
+ content.push(theme.fg("muted", `parent ${safeText(entity.value.parentId)}`));
2446
+ }
2447
+ if (entity.value.effects?.length) {
2448
+ content.push(theme.fg("muted", `effects ${entity.value.effects.length}`));
2449
+ }
2450
+ if (entity.value.effectConflicts?.length) {
2451
+ content.push(theme.fg("warning", `conflicts ${entity.value.effectConflicts.length}`));
2452
+ }
2453
+ if (entity.value.requirements.length > 0) {
2454
+ content.push(theme.fg("muted", `requires ${entity.value.requirements.join(", ")}`));
2455
+ }
2456
+ if (entity.value.provisions.length > 0) {
2457
+ content.push(theme.fg("muted", `provides ${entity.value.provisions.join(", ")}`));
2458
+ }
2459
+ const cycles = snapshot.componentGraph.cycles.filter(
2460
+ (cycle) => cycle.includes(entity.value.id)
2461
+ );
2462
+ if (cycles.length > 0) {
2463
+ content.push(theme.fg("warning", `cycles ${cycles.map((cycle) => cycle.join(" \u2192 ")).join("; ")}`));
2464
+ }
2465
+ if (entity.value.error) content.push(theme.fg("error", safeText(entity.value.error)));
2466
+ } else if (entity.kind === "meshTopic") {
2467
+ content.push(theme.fg("muted", `${entity.value.subscribers.length} subscribers`));
2468
+ content.push(theme.fg("muted", `${entity.value.recentEvents} recent events`));
2469
+ } else if (entity.kind === "meshRoute") {
2470
+ content.push(theme.fg("muted", `${safeText(entity.value.fromName)} \u2192 ${safeText(entity.value.targetName)}`));
2471
+ content.push(theme.fg("muted", `kind ${safeText(entity.value.kind)}`));
2472
+ content.push(theme.fg("muted", `topic ${safeText(entity.value.topic)}`));
2473
+ content.push(theme.fg("muted", `count ${entity.value.count}`));
2474
+ } else if (entity.kind === "state") {
2475
+ content.push(theme.fg("muted", `version ${entity.value.version}`));
2476
+ if (entity.value.owner) content.push(theme.fg("muted", `owner ${safeText(entity.value.owner)}`));
2477
+ const filePreview = loadStateFilePreview(entity.value, snapshot.main.cwd ?? process.cwd());
2478
+ if (filePreview) {
2479
+ content.push("");
2480
+ content.push(theme.fg("muted", `file ${safeText(filePreview.path)}`));
2481
+ content.push(...renderStateFilePreview(
2482
+ filePreview,
2483
+ theme,
2484
+ Math.max(1, inner - 2),
2485
+ Math.max(0, height - content.length - 3),
2486
+ invalidate
2487
+ ));
2488
+ }
2489
+ }
2490
+ } else {
2491
+ content.push(theme.fg("dim", "No node selected"));
2492
+ }
2493
+ const title = " selected ";
2494
+ const rows = [border(`\u256D${title}${"\u2500".repeat(Math.max(0, inner - visibleWidth3(title)))}\u256E`)];
2495
+ for (let index = 0; index < height - 2; index++) {
2496
+ rows.push(`${border("\u2502")}${padToWidth(` ${content[index] ?? ""}`, inner)}${border("\u2502")}`);
2497
+ }
2498
+ rows.push(border(`\u2570${"\u2500".repeat(inner)}\u256F`));
2499
+ return rows.slice(0, height);
2500
+ };
2501
+ var graphContextEntities = (allEntities, entities) => {
2502
+ const byRawId = /* @__PURE__ */ new Map();
2503
+ for (const entity of allEntities) {
2504
+ for (const identity of rawIdentity(entity)) {
2505
+ if (identity) byRawId.set(identity, entity);
2506
+ }
2507
+ }
2508
+ const visible = new Map(entities.map((entity) => [entity.id, entity]));
2509
+ for (const entity of entities) {
2510
+ let parentRef = parentReference(entity);
2511
+ const visited = /* @__PURE__ */ new Set();
2512
+ while (parentRef && !visited.has(parentRef)) {
2513
+ visited.add(parentRef);
2514
+ const parent = byRawId.get(parentRef);
2515
+ if (!parent) break;
2516
+ visible.set(parent.id, parent);
2517
+ parentRef = parentReference(parent);
2518
+ }
2519
+ }
2520
+ return allEntities.filter((entity) => visible.has(entity.id));
2521
+ };
2522
+ var renderFabricTopologyPanel = ({
2523
+ theme,
2524
+ filter,
2525
+ selectedEntityId,
2526
+ snapshot,
2527
+ run,
2528
+ mesh,
2529
+ allEntities,
2530
+ entities,
2531
+ width,
2532
+ height,
2533
+ camera,
2534
+ animation,
2535
+ invalidate
2536
+ }) => {
2537
+ const graphEntities = graphContextEntities(allEntities, entities);
2538
+ const layout = buildLayout(snapshot, graphEntities, run, mesh);
2539
+ const selectableIds = new Set(entities.map((entity) => entity.id));
2540
+ const selected = entities.find((entity) => entity.id === selectedEntityId) ?? entities[0];
2541
+ const inspectorWidth = width >= 92 ? Math.min(36, Math.max(30, Math.floor(width * 0.3))) : 0;
2542
+ const graphWidth = Math.max(1, width - inspectorWidth);
2543
+ const graph = renderCanvas(theme, layout, selected?.id, graphWidth, height, camera, animation);
2544
+ const inspector = inspectorWidth > 0 ? inspectorLines(theme, selected, snapshot, run, inspectorWidth, height, invalidate) : [];
2545
+ const lines = inspectorWidth > 0 ? graph.map(
2546
+ (line, index) => `${padToWidth(line, graphWidth)}${inspector[index] ?? ""}`
2547
+ ) : graph;
2548
+ const active = entities.filter((entity) => isActiveStatus(entity.status)).length;
2549
+ const originX = Math.round(camera.x - graphWidth / 2);
2550
+ const originY = Math.round(camera.y - height / 2);
2551
+ const hiddenLeft = layout.nodes.filter((node) => node.x < originX).length;
2552
+ const hiddenRight = layout.nodes.filter((node) => node.x + 2 > originX + graphWidth).length;
2553
+ const hiddenUp = layout.nodes.filter((node) => node.y < originY).length;
2554
+ const hiddenDown = layout.nodes.filter((node) => node.y >= originY + height).length;
2555
+ const offCanvas = new Set(
2556
+ layout.nodes.filter(
2557
+ (node) => node.x < originX || node.x + 2 > originX + graphWidth || node.y < originY || node.y >= originY + height
2558
+ ).map((node) => node.id)
2559
+ ).size;
2560
+ const directions = [
2561
+ hiddenLeft > 0 ? "\u2190" : "",
2562
+ hiddenRight > 0 ? "\u2192" : "",
2563
+ hiddenUp > 0 ? "\u2191" : "",
2564
+ hiddenDown > 0 ? "\u2193" : ""
2565
+ ].join("");
2566
+ if (lines.length > 0 && height > 1) {
2567
+ const legend = [
2568
+ offCanvas > 0 ? `${directions} ${offCanvas} off-canvas` : void 0,
2569
+ `${active} active`,
2570
+ "\u25C6 Main",
2571
+ "\u25A0 agent",
2572
+ "\u25C7 actor",
2573
+ "\u25CE topic",
2574
+ "\u25B1 group",
2575
+ animation.replayRouteId ? "\u25B6 replay" : animation.showHistory ? "history" : "live decay",
2576
+ "\u2B21 component",
2577
+ animation.reducedMotion ? "reduced motion" : void 0,
2578
+ filter !== "all" ? `${entities.length}/${allEntities.length} ${filter}` : void 0
2579
+ ].filter((value) => Boolean(value)).join(" \xB7 ");
2580
+ const graphLegend = padToWidth(theme.fg("dim", truncateToWidth3(legend, graphWidth, "")), graphWidth);
2581
+ lines[0] = truncateToWidth3(
2582
+ graphLegend + (inspectorWidth > 0 ? inspector[0] ?? "" : ""),
2583
+ width,
2584
+ ""
2585
+ );
2586
+ }
2587
+ const selectedPosition = selected ? layout.positions.get(selected.id) : void 0;
2588
+ return {
2589
+ lines,
2590
+ positions: new Map(
2591
+ [...layout.positions].filter(([id]) => selectableIds.has(id))
2592
+ ),
2593
+ ...selectedPosition ? { selectedPosition } : {}
2594
+ };
2595
+ };
2596
+ var directionalGraphTarget = (positions, currentId, direction) => {
2597
+ const current = currentId ? positions.get(currentId) : void 0;
2598
+ if (!current) return positions.keys().next().value;
2599
+ let best;
2600
+ for (const [id, point] of positions) {
2601
+ if (id === currentId) continue;
2602
+ const dx = point.x - current.x;
2603
+ const dy = point.y - current.y;
2604
+ const primary = direction === "left" ? -dx : direction === "right" ? dx : direction === "up" ? -dy : dy;
2605
+ if (primary <= 0) continue;
2606
+ const secondary = direction === "left" || direction === "right" ? Math.abs(dy) : Math.abs(dx);
2607
+ const score = primary + secondary * 2.4;
2608
+ if (!best || score < best.score) best = { id, score };
2609
+ }
2610
+ return best?.id;
2611
+ };
2612
+
2613
+ // src/ui/dashboard-graph-controller.ts
2614
+ var DashboardGraphController = class {
2615
+ constructor(requestRender) {
2616
+ this.requestRender = requestRender;
2617
+ }
2618
+ _positions = /* @__PURE__ */ new Map();
2619
+ _camera = { x: 0, y: 0 };
2620
+ _cameraTarget = { x: 0, y: 0 };
2621
+ _velocity = { x: 0, y: 0 };
2622
+ _cameraInitialized = false;
2623
+ _animation;
2624
+ _animationAt = 0;
2625
+ _effectsAnimation;
2626
+ _reducedMotion = false;
2627
+ _showHistory = false;
2628
+ _replayIndex;
2629
+ _replayPlaying = false;
2630
+ _replaySpeed = 1;
2631
+ _replayAdvancedAt = 0;
2632
+ _replayLength = 0;
2633
+ _replayLabel;
2634
+ togglePlayback() {
2635
+ this._replayPlaying = !this._replayPlaying;
2636
+ this._replayAdvancedAt = Date.now();
2637
+ }
2638
+ changeReplaySpeed(direction) {
2639
+ const speeds = [0.5, 1, 2, 4];
2640
+ const current = speeds.indexOf(this._replaySpeed);
2641
+ this._replaySpeed = speeds[Math.max(0, Math.min(speeds.length - 1, current + direction))] ?? 1;
2642
+ this._replayAdvancedAt = Date.now();
2643
+ }
2644
+ toggleHistory() {
2645
+ this._showHistory = !this._showHistory;
2646
+ }
2647
+ toggleReducedMotion() {
2648
+ this._reducedMotion = !this._reducedMotion;
2649
+ }
2650
+ directionalTarget(selectedId, direction) {
2651
+ return directionalGraphTarget(this._positions, selectedId, direction);
2652
+ }
2653
+ setPositions(positions) {
2654
+ this._positions = positions;
2655
+ }
2656
+ replayFrame(events, routes) {
2657
+ const frames = this.replayFrames(events, routes);
2658
+ this._replayLength = frames.length;
2659
+ if (this._replayIndex !== void 0 && frames.length === 0) {
2660
+ this._replayIndex = void 0;
2661
+ this._replayPlaying = false;
2662
+ } else if (this._replayIndex !== void 0) {
2663
+ this._replayIndex = Math.min(this._replayIndex, frames.length - 1);
2664
+ }
2665
+ const frame = this._replayIndex === void 0 ? void 0 : frames[this._replayIndex];
2666
+ this._replayLabel = frame?.event.kind;
2667
+ return frame;
2668
+ }
2669
+ get camera() {
2670
+ return this._camera;
2671
+ }
2672
+ get cameraInitialized() {
2673
+ return this._cameraInitialized;
2674
+ }
2675
+ get reducedMotion() {
2676
+ return this._reducedMotion;
2677
+ }
2678
+ get showHistory() {
2679
+ return this._showHistory;
2680
+ }
2681
+ get replayIndex() {
2682
+ return this._replayIndex;
2683
+ }
2684
+ get replayPlaying() {
2685
+ return this._replayPlaying;
2686
+ }
2687
+ get replaySpeed() {
2688
+ return this._replaySpeed;
2689
+ }
2690
+ get replayLength() {
2691
+ return this._replayLength;
2692
+ }
2693
+ get replayLabel() {
2694
+ return this._replayLabel;
2695
+ }
2696
+ replayFrames(events, routes) {
2697
+ return events.flatMap((event) => {
2698
+ const route = routes.find(
2699
+ (candidate) => candidate.topic === event.topic && candidate.kind === event.kind && (candidate.fromId === event.from.id || candidate.fromName === event.from.name)
2700
+ );
2701
+ return route ? [{ event, route }] : [];
2702
+ });
2703
+ }
2704
+ startEffectsAnimation() {
2705
+ if (this._effectsAnimation) return;
2706
+ this._replayAdvancedAt = Date.now();
2707
+ this._effectsAnimation = setInterval(() => {
2708
+ const now = Date.now();
2709
+ if (this._replayPlaying && this._replayIndex !== void 0 && this._replayLength > 0 && now - this._replayAdvancedAt >= 850 / this._replaySpeed) {
2710
+ if (this._replayIndex < this._replayLength - 1) {
2711
+ this._replayIndex++;
2712
+ this._replayAdvancedAt = now;
2713
+ } else {
2714
+ this._replayPlaying = false;
2715
+ }
2716
+ }
2717
+ this.requestRender();
2718
+ }, 80);
2719
+ this._effectsAnimation.unref?.();
2720
+ }
2721
+ stopEffectsAnimation() {
2722
+ if (this._effectsAnimation) clearInterval(this._effectsAnimation);
2723
+ this._effectsAnimation = void 0;
2724
+ this._replayPlaying = false;
2725
+ }
2726
+ toggleReplay(events, routes) {
2727
+ const frames = this.replayFrames(events, routes);
2728
+ this._replayLength = frames.length;
2729
+ if (frames.length === 0) return;
2730
+ if (this._replayIndex === void 0) {
2731
+ this._replayIndex = 0;
2732
+ this._replayPlaying = true;
2733
+ } else {
2734
+ this._replayIndex = void 0;
2735
+ this._replayPlaying = false;
2736
+ }
2737
+ this._replayAdvancedAt = Date.now();
2738
+ }
2739
+ stepReplay(delta) {
2740
+ if (this._replayIndex === void 0 || this._replayLength === 0) return;
2741
+ this._replayIndex = Math.max(
2742
+ 0,
2743
+ Math.min(this._replayLength - 1, this._replayIndex + delta)
2744
+ );
2745
+ this._replayPlaying = false;
2746
+ this._replayAdvancedAt = Date.now();
2747
+ }
2748
+ setCameraTarget(point) {
2749
+ if (!this._cameraInitialized) {
2750
+ this._camera = { ...point };
2751
+ this._cameraTarget = { ...point };
2752
+ this._cameraInitialized = true;
2753
+ return;
2754
+ }
2755
+ if (this._cameraTarget.x === point.x && this._cameraTarget.y === point.y) return;
2756
+ this._cameraTarget = { ...point };
2757
+ this._animationAt = Date.now();
2758
+ if (this._animation) return;
2759
+ this._animation = setInterval(() => this.stepCamera(), 16);
2760
+ this._animation.unref?.();
2761
+ }
2762
+ stopCameraAnimation() {
2763
+ if (this._animation) clearInterval(this._animation);
2764
+ this._animation = void 0;
2765
+ this._animationAt = 0;
2766
+ this._velocity = { x: 0, y: 0 };
2767
+ this._cameraTarget = { ...this._camera };
2768
+ }
2769
+ stepCamera() {
2770
+ const now = Date.now();
2771
+ const elapsed = this._animationAt > 0 ? (now - this._animationAt) / 1e3 : 0.016;
2772
+ const dt = Math.max(8e-3, Math.min(0.032, elapsed));
2773
+ this._animationAt = now;
2774
+ const stiffness = 115;
2775
+ const damping = 19;
2776
+ const stepAxis = (position, target, velocity) => {
2777
+ const acceleration = stiffness * (target - position) - damping * velocity;
2778
+ const nextVelocity = velocity + acceleration * dt;
2779
+ return [position + nextVelocity * dt, nextVelocity];
2780
+ };
2781
+ [this._camera.x, this._velocity.x] = stepAxis(
2782
+ this._camera.x,
2783
+ this._cameraTarget.x,
2784
+ this._velocity.x
2785
+ );
2786
+ [this._camera.y, this._velocity.y] = stepAxis(
2787
+ this._camera.y,
2788
+ this._cameraTarget.y,
2789
+ this._velocity.y
2790
+ );
2791
+ const distance = Math.hypot(
2792
+ this._cameraTarget.x - this._camera.x,
2793
+ this._cameraTarget.y - this._camera.y
2794
+ );
2795
+ const speed = Math.hypot(this._velocity.x, this._velocity.y);
2796
+ if (distance < 0.025 && speed < 0.025) {
2797
+ this._camera = { ...this._cameraTarget };
2798
+ this._velocity = { x: 0, y: 0 };
2799
+ if (this._animation) clearInterval(this._animation);
2800
+ this._animation = void 0;
2801
+ }
2802
+ this.requestRender();
2803
+ }
2804
+ };
2805
+
2806
+ // src/ui/dashboard-modal-controller.ts
2807
+ import { Editor, getKeybindings } from "@earendil-works/pi-tui";
2808
+ var editorTheme = (theme) => ({
2809
+ borderColor: (value) => theme.fg("borderMuted", value),
2810
+ selectList: {
2811
+ selectedPrefix: (text) => theme.fg("accent", text),
2812
+ selectedText: (text) => theme.fg("accent", text),
2813
+ description: (text) => theme.fg("muted", text),
2814
+ scrollInfo: (text) => theme.fg("muted", text),
2815
+ noMatch: (text) => theme.fg("muted", text)
2816
+ }
2817
+ });
2818
+ var DashboardModalController = class {
2819
+ constructor(tui, theme) {
2820
+ this.tui = tui;
2821
+ this.theme = theme;
2822
+ }
2823
+ active;
2824
+ openPicker(kind, name, create, onClose) {
2825
+ const child = create(() => this.close());
2826
+ this.open("picker", child, {
2827
+ title: `actor \xB7 ${name} \xB7 ${kind}`,
2828
+ narrowTitle: `actor \xB7 ${name}`,
2829
+ hint: ` Enter to select \xB7 Esc to cancel${kind === "model" ? " \xB7 type to filter" : ""}`
2830
+ }, onClose);
2831
+ }
2832
+ openInstructions(name, instructions, onSubmit, onClose) {
2833
+ this.openEditor({
2834
+ title: `instructions \xB7 ${name}`,
2835
+ narrowTitle: `instructions \xB7 ${name}`,
2836
+ hint: " enter submit \xB7 shift+enter newline \xB7 esc cancel"
2837
+ }, instructions, (text) => {
2838
+ onSubmit(text);
2839
+ return true;
2840
+ }, onClose);
2841
+ }
2842
+ openMessage(target, delivery, onSubmit, onClose) {
2843
+ const label = target.kind === "actor" ? "queue actor message" : delivery === "steer" ? target.kind === "main" ? "message or steer Main" : "steer now" : "queue follow-up";
2844
+ this.openEditor({
2845
+ title: `${label} \xB7 ${target.name}`,
2846
+ narrowTitle: `${delivery} \xB7 ${target.name}`,
2847
+ hint: " enter send \xB7 shift+enter newline \xB7 esc cancel"
2848
+ }, void 0, (text) => {
2849
+ const message = text.trim();
2850
+ if (!message) return false;
2851
+ onSubmit(message);
2852
+ return true;
2853
+ }, onClose);
2854
+ }
2855
+ /** Returns true even when this input closes the modal: never leak it to navigation. */
2856
+ handleInput(data) {
2857
+ const active = this.active;
2858
+ if (!active) return false;
2859
+ if (active.kind === "editor" && getKeybindings().matches(data, "tui.select.cancel")) {
2860
+ this.close();
2861
+ } else {
2862
+ active.child.handleInput(data);
2863
+ }
2864
+ this.tui.requestRender();
2865
+ return true;
2866
+ }
2867
+ render(width, frame) {
2868
+ if (!this.active) return void 0;
2869
+ return width <= 0 ? [] : frame(width, this.active.content);
2870
+ }
2871
+ /** Disposal releases the child without running a navigation callback. */
2872
+ dispose() {
2873
+ this.active = void 0;
2874
+ }
2875
+ close() {
2876
+ const active = this.active;
2877
+ this.active = void 0;
2878
+ active?.onClose();
2879
+ }
2880
+ openEditor(content, text, onSubmit, onClose) {
2881
+ const editor = new Editor(this.tui, editorTheme(this.theme));
2882
+ if (text !== void 0) editor.setText(text);
2883
+ editor.onSubmit = (value) => {
2884
+ if (onSubmit(value)) this.close();
2885
+ };
2886
+ this.open("editor", editor, content, onClose);
2887
+ }
2888
+ open(kind, child, content, onClose) {
2889
+ child.focused = true;
2890
+ this.active = {
2891
+ kind,
2892
+ child,
2893
+ content: { ...content, render: (width) => child.render(width) },
2894
+ onClose
2895
+ };
2896
+ }
2897
+ };
2898
+
2899
+ // src/ui/fabric-host-event-selector.ts
2900
+ import { Container, getKeybindings as getKeybindings2, Spacer, Text } from "@earendil-works/pi-tui";
2901
+ var COMMON_HOST_EVENTS = [
2902
+ "input",
2903
+ "turn_end",
2904
+ "agent_settled",
2905
+ "tool_error",
2906
+ "session_compact"
2907
+ ];
2908
+ var commonHostEvents = new Set(COMMON_HOST_EVENTS);
2909
+ var MAX_VISIBLE_HOST_EVENTS = 12;
2910
+ var HOST_EVENT_ORDER = [
2911
+ ...COMMON_HOST_EVENTS,
2912
+ ...FABRIC_ACTOR_HOST_EVENTS.filter((event) => !commonHostEvents.has(event))
2913
+ ];
2914
+ var EVENT_LABELS = {
2915
+ input: "raw user or extension input",
2916
+ turn_end: "each completed LLM turn",
2917
+ agent_settled: "host fully idle after a run",
2918
+ tool_error: "synthetic notification for a failed tool",
2919
+ session_compact: "context was compacted",
2920
+ session_compact_failed: "context compaction failed or was aborted",
2921
+ resources_discover: "skills, prompts, and themes are discovered",
2922
+ session_start: "a session starts, reloads, or is restored",
2923
+ session_info_changed: "session metadata or name changed",
2924
+ session_before_switch: "before a new or resumed session replaces this one",
2925
+ session_before_fork: "before a session fork or clone",
2926
+ session_before_compact: "before context compaction",
2927
+ session_shutdown: "before this session runtime shuts down",
2928
+ session_before_tree: "before session-tree navigation",
2929
+ session_tree: "after session-tree navigation",
2930
+ before_agent_start: "expanded prompt and system context before the agent loop",
2931
+ agent_start: "a low-level agent run started",
2932
+ agent_end: "a low-level agent run ended",
2933
+ turn_start: "an LLM turn started",
2934
+ message_start: "a user, assistant, or tool message started",
2935
+ message_update: "an assistant streaming update",
2936
+ message_end: "a user, assistant, or tool message completed",
2937
+ ui_prompt_start: "a blocking user-facing UI prompt opened",
2938
+ ui_prompt_end: "a blocking user-facing UI prompt closed",
2939
+ context: "assembled messages before an LLM request",
2940
+ before_provider_headers: "outbound provider headers assembled; secrets redacted",
2941
+ before_provider_request: "provider payload assembled before sending",
2942
+ after_provider_response: "provider response status and headers received",
2943
+ tool_execution_start: "tool execution started",
2944
+ tool_call: "validated tool call before execution",
2945
+ tool_execution_update: "streaming tool progress",
2946
+ tool_result: "final tool result before message persistence",
2947
+ tool_execution_end: "tool execution completed",
2948
+ model_select: "the active model changed",
2949
+ thinking_level_select: "the active thinking level changed",
2950
+ user_bash: "a user ! or !! shell command was submitted"
2951
+ };
2952
+ var FabricHostEventSelector = class extends Container {
2953
+ theme;
2954
+ onSelectCallback;
2955
+ onCancelCallback;
2956
+ listContainer = new Container();
2957
+ enabled;
2958
+ selectedIndex = 0;
2959
+ focused = false;
2960
+ constructor(options) {
2961
+ super();
2962
+ this.theme = options.theme;
2963
+ this.onSelectCallback = options.onSelect;
2964
+ this.onCancelCallback = options.onCancel;
2965
+ this.enabled = new Set(options.currentValue);
2966
+ this.addChild(
2967
+ new Text(
2968
+ this.theme.fg(
2969
+ "muted",
2970
+ options.headerText ?? "Toggle the host events this actor subscribes to."
2971
+ ),
2972
+ 0,
2973
+ 0
2974
+ )
2975
+ );
2976
+ this.addChild(new Spacer(1));
2977
+ this.addChild(this.listContainer);
2978
+ this.addChild(new Spacer(1));
2979
+ this.updateList();
2980
+ }
2981
+ handleInput(keyData) {
2982
+ const kb = getKeybindings2();
2983
+ if (kb.matches(keyData, "tui.select.up")) {
2984
+ this.selectedIndex = this.selectedIndex === 0 ? HOST_EVENT_ORDER.length - 1 : this.selectedIndex - 1;
2985
+ this.updateList();
2986
+ } else if (kb.matches(keyData, "tui.select.down")) {
2987
+ this.selectedIndex = this.selectedIndex === HOST_EVENT_ORDER.length - 1 ? 0 : this.selectedIndex + 1;
2988
+ this.updateList();
2989
+ } else if (keyData === " ") {
2990
+ const event = HOST_EVENT_ORDER[this.selectedIndex];
2991
+ if (event) {
2992
+ if (this.enabled.has(event)) this.enabled.delete(event);
2993
+ else this.enabled.add(event);
2994
+ this.updateList();
2995
+ }
2996
+ } else if (kb.matches(keyData, "tui.select.confirm")) {
2997
+ this.onSelectCallback(HOST_EVENT_ORDER.filter((event) => this.enabled.has(event)));
2998
+ } else if (kb.matches(keyData, "tui.select.cancel")) {
2999
+ this.onCancelCallback();
3000
+ }
3001
+ }
3002
+ updateList() {
3003
+ this.listContainer.clear();
3004
+ const total = HOST_EVENT_ORDER.length;
3005
+ const startIndex = Math.max(
3006
+ 0,
3007
+ Math.min(
3008
+ this.selectedIndex - Math.floor(MAX_VISIBLE_HOST_EVENTS / 2),
3009
+ total - MAX_VISIBLE_HOST_EVENTS
3010
+ )
3011
+ );
3012
+ const endIndex = Math.min(startIndex + MAX_VISIBLE_HOST_EVENTS, total);
3013
+ if (startIndex > 0) {
3014
+ this.listContainer.addChild(
3015
+ new Text(this.theme.fg("dim", ` \u2191 ${startIndex} earlier events`), 0, 0)
3016
+ );
3017
+ }
3018
+ for (let index = startIndex; index < endIndex; index++) {
3019
+ const event = HOST_EVENT_ORDER[index];
3020
+ const selected = index === this.selectedIndex;
3021
+ const checked = this.enabled.has(event);
3022
+ const box = checked ? this.theme.fg("success", "[x]") : this.theme.fg("dim", "[ ]");
3023
+ const label = `${box} ${event} \xB7 ${this.theme.fg("muted", EVENT_LABELS[event])}`;
3024
+ const line = selected ? `${this.theme.fg("accent", "\u2192 ")}${this.theme.fg("accent", label)}` : ` ${label}`;
3025
+ this.listContainer.addChild(new Text(line, 0, 0));
3026
+ }
3027
+ if (endIndex < total) {
3028
+ this.listContainer.addChild(
3029
+ new Text(this.theme.fg("dim", ` \u2193 ${total - endIndex} later events`), 0, 0)
3030
+ );
3031
+ }
3032
+ this.listContainer.addChild(new Spacer(1));
3033
+ this.listContainer.addChild(
3034
+ new Text(this.theme.fg("muted", " space toggle \xB7 enter apply \xB7 esc cancel"), 0, 0)
3035
+ );
3036
+ }
3037
+ };
3038
+
3039
+ // src/ui/fabric-actor-delivery-selector.ts
3040
+ import {
3041
+ Container as Container2,
3042
+ SelectList,
3043
+ Spacer as Spacer2,
3044
+ Text as Text2
3045
+ } from "@earendil-works/pi-tui";
3046
+ var LAYOUT = {
3047
+ minPrimaryColumnWidth: 18,
3048
+ maxPrimaryColumnWidth: 34
3049
+ };
3050
+ var POLICIES = [
3051
+ { value: "mailbox", label: "Mailbox only", description: "keep output in actor history", delivery: "mailbox", triggerTurn: false },
3052
+ { value: "steer-passive", label: "Steer \xB7 passive", description: "deliver now without starting idle Main", delivery: "steer", triggerTurn: false },
3053
+ { value: "steer-active", label: "Steer \xB7 resume Main", description: "deliver now and start Main when idle", delivery: "steer", triggerTurn: true },
3054
+ { value: "followUp-passive", label: "Follow-up \xB7 passive", description: "deliver after the run without starting idle Main", delivery: "followUp", triggerTurn: false },
3055
+ { value: "followUp-active", label: "Follow-up \xB7 resume Main", description: "deliver after the run and start Main when idle", delivery: "followUp", triggerTurn: true },
3056
+ { value: "next-turn", label: "Next user turn", description: "defer until the next user prompt", delivery: "nextTurn", triggerTurn: false }
3057
+ ];
3058
+ var selectListTheme = (theme) => ({
3059
+ selectedPrefix: (text) => theme.fg("accent", text),
3060
+ selectedText: (text) => theme.fg("accent", text),
3061
+ description: (text) => theme.fg("muted", text),
3062
+ scrollInfo: (text) => theme.fg("muted", text),
3063
+ noMatch: (text) => theme.fg("muted", text)
3064
+ });
3065
+ var FabricActorDeliverySelector = class extends Container2 {
3066
+ selectList;
3067
+ focused = false;
3068
+ constructor(options) {
3069
+ super();
3070
+ const current = POLICIES.find(
3071
+ (policy) => policy.delivery === options.currentValue.delivery && policy.triggerTurn === options.currentValue.triggerTurn
3072
+ )?.value;
3073
+ const items = POLICIES.map((policy) => ({
3074
+ value: policy.value,
3075
+ label: `${policy.label}${policy.value === current ? " \u2713" : ""}`,
3076
+ description: policy.description
3077
+ }));
3078
+ this.addChild(
3079
+ new Text2(
3080
+ options.theme.fg(
3081
+ "muted",
3082
+ options.headerText ?? "Choose how actor output enters Main and whether it starts a turn."
3083
+ ),
3084
+ 0,
3085
+ 0
3086
+ )
3087
+ );
3088
+ this.addChild(new Spacer2(1));
3089
+ this.selectList = new SelectList(items, items.length, selectListTheme(options.theme), LAYOUT);
3090
+ const startIndex = items.findIndex((item) => item.value === current);
3091
+ if (startIndex >= 0) this.selectList.setSelectedIndex(startIndex);
3092
+ this.selectList.onSelect = (item) => {
3093
+ const policy = POLICIES.find((candidate) => candidate.value === item.value);
3094
+ if (policy) options.onSelect({ delivery: policy.delivery, triggerTurn: policy.triggerTurn });
3095
+ };
3096
+ this.selectList.onCancel = options.onCancel;
3097
+ this.addChild(this.selectList);
3098
+ this.addChild(new Spacer2(1));
3099
+ }
3100
+ handleInput(data) {
3101
+ this.selectList.handleInput(data);
3102
+ }
3103
+ };
3104
+
3105
+ // src/ui/fabric-actor-tool-selector.ts
3106
+ import { Container as Container3, getKeybindings as getKeybindings3, Spacer as Spacer3, Text as Text3 } from "@earendil-works/pi-tui";
3107
+ var ACTOR_TOOL_ORDER = ["read", "grep", "find", "ls", "bash", "powershell", "edit", "write"];
3108
+ var TOOL_LABELS = {
3109
+ read: "read files",
3110
+ grep: "search file contents",
3111
+ find: "find files by name",
3112
+ ls: "list directories",
3113
+ bash: "execute shell commands",
3114
+ powershell: "execute PowerShell commands",
3115
+ edit: "edit existing files",
3116
+ write: "write files"
3117
+ };
3118
+ var FabricActorToolSelector = class extends Container3 {
3119
+ theme;
3120
+ onSelectCallback;
3121
+ onCancelCallback;
3122
+ listContainer = new Container3();
3123
+ enabled;
3124
+ selectedIndex = 0;
3125
+ focused = false;
3126
+ constructor(options) {
3127
+ super();
3128
+ this.theme = options.theme;
3129
+ this.onSelectCallback = options.onSelect;
3130
+ this.onCancelCallback = options.onCancel;
3131
+ this.enabled = new Set(options.currentValue);
3132
+ this.addChild(
3133
+ new Text3(
3134
+ this.theme.fg("muted", options.headerText ?? "Select the optional tools available to this actor."),
3135
+ 0,
3136
+ 0
3137
+ )
3138
+ );
3139
+ this.addChild(new Spacer3(1));
3140
+ this.addChild(this.listContainer);
3141
+ this.addChild(new Spacer3(1));
3142
+ this.updateList();
3143
+ }
3144
+ handleInput(keyData) {
3145
+ const kb = getKeybindings3();
3146
+ if (kb.matches(keyData, "tui.select.up")) {
3147
+ this.selectedIndex = this.selectedIndex === 0 ? ACTOR_TOOL_ORDER.length - 1 : this.selectedIndex - 1;
3148
+ this.updateList();
3149
+ } else if (kb.matches(keyData, "tui.select.down")) {
3150
+ this.selectedIndex = this.selectedIndex === ACTOR_TOOL_ORDER.length - 1 ? 0 : this.selectedIndex + 1;
3151
+ this.updateList();
3152
+ } else if (keyData === " ") {
3153
+ const tool = ACTOR_TOOL_ORDER[this.selectedIndex];
3154
+ if (tool) {
3155
+ if (this.enabled.has(tool)) this.enabled.delete(tool);
3156
+ else this.enabled.add(tool);
3157
+ this.updateList();
3158
+ }
3159
+ } else if (kb.matches(keyData, "tui.select.confirm")) {
3160
+ const selected = ACTOR_TOOL_ORDER.filter((tool) => this.enabled.has(tool));
3161
+ const custom = [...this.enabled].filter(
3162
+ (tool) => !ACTOR_TOOL_ORDER.includes(tool)
3163
+ );
3164
+ this.onSelectCallback([...selected, ...custom]);
3165
+ } else if (kb.matches(keyData, "tui.select.cancel")) {
3166
+ this.onCancelCallback();
3167
+ }
3168
+ }
3169
+ updateList() {
3170
+ this.listContainer.clear();
3171
+ for (let index = 0; index < ACTOR_TOOL_ORDER.length; index++) {
3172
+ const tool = ACTOR_TOOL_ORDER[index];
3173
+ const selected = index === this.selectedIndex;
3174
+ const checked = this.enabled.has(tool);
3175
+ const box = checked ? this.theme.fg("success", "[x]") : this.theme.fg("dim", "[ ]");
3176
+ const label = `${box} ${tool} \xB7 ${this.theme.fg("muted", TOOL_LABELS[tool])}`;
3177
+ const line = selected ? `${this.theme.fg("accent", "\u2192 ")}${this.theme.fg("accent", label)}` : ` ${label}`;
3178
+ this.listContainer.addChild(new Text3(line, 0, 0));
3179
+ }
3180
+ this.listContainer.addChild(new Spacer3(1));
3181
+ this.listContainer.addChild(
3182
+ new Text3(this.theme.fg("muted", " space toggle \xB7 enter apply \xB7 esc cancel"), 0, 0)
3183
+ );
3184
+ }
3185
+ };
3186
+
3187
+ // src/ui/fabric-thinking-selector.ts
3188
+ import {
3189
+ Container as Container4,
3190
+ SelectList as SelectList2,
3191
+ Spacer as Spacer4,
3192
+ Text as Text4
3193
+ } from "@earendil-works/pi-tui";
3194
+ var LAYOUT2 = {
3195
+ minPrimaryColumnWidth: 8,
3196
+ maxPrimaryColumnWidth: 24
3197
+ };
3198
+ var selectListTheme2 = (theme) => ({
3199
+ selectedPrefix: (text) => theme.fg("accent", text),
3200
+ selectedText: (text) => theme.fg("accent", text),
3201
+ description: (text) => theme.fg("muted", text),
3202
+ scrollInfo: (text) => theme.fg("muted", text),
3203
+ noMatch: (text) => theme.fg("muted", text)
3204
+ });
3205
+ var FabricThinkingSelector = class extends Container4 {
3206
+ selectList;
3207
+ onSelectCallback;
3208
+ focused = false;
3209
+ constructor(options) {
3210
+ super();
3211
+ this.onSelectCallback = options.onSelect;
3212
+ const headerText = options.headerText ?? "Thinking level for this actor. Pick Inherit to use the Fabric default.";
3213
+ const inheritName = options.inheritName ?? "Use the Fabric default thinking level";
3214
+ const items = [
3215
+ {
3216
+ value: INHERIT_VALUE,
3217
+ label: `Inherit${options.currentValue === INHERIT_VALUE ? " \u2713" : ""}`,
3218
+ description: inheritName
3219
+ },
3220
+ ...THINKING_LEVELS.map((level) => ({
3221
+ value: level,
3222
+ label: `${thinkingLabel(level)}${options.currentValue === level ? " \u2713" : ""}`
3223
+ }))
3224
+ ];
3225
+ const startIndex = items.findIndex((item) => item.value === options.currentValue);
3226
+ this.addChild(new Text4(options.theme.fg("muted", headerText), 0, 0));
3227
+ this.addChild(new Spacer4(1));
3228
+ this.selectList = new SelectList2(items, items.length, selectListTheme2(options.theme), LAYOUT2);
3229
+ if (startIndex >= 0) this.selectList.setSelectedIndex(startIndex);
3230
+ this.selectList.onSelect = (item) => this.onSelectCallback(item.value);
3231
+ this.selectList.onCancel = options.onCancel;
3232
+ this.addChild(this.selectList);
3233
+ this.addChild(new Spacer4(1));
3234
+ }
3235
+ handleInput(data) {
3236
+ this.selectList.handleInput(data);
3237
+ }
3238
+ };
3239
+
3240
+ // src/ui/dashboard.ts
3241
+ var DASHBOARD_OVERLAY_HEIGHT_PERCENT = 90;
3242
+ var DASHBOARD_OVERLAY_VERTICAL_MARGIN = 1;
3243
+ var dashboardOverlayRows = (terminalRows) => Math.max(
3244
+ 1,
3245
+ Math.min(
3246
+ Math.floor(terminalRows * DASHBOARD_OVERLAY_HEIGHT_PERCENT / 100),
3247
+ terminalRows - DASHBOARD_OVERLAY_VERTICAL_MARGIN * 2
3248
+ )
3249
+ );
3250
+ var FabricDashboard = class {
3251
+ constructor(tui, theme, snapshot, done, options = {}) {
3252
+ this.tui = tui;
3253
+ this.theme = theme;
3254
+ this.snapshot = snapshot;
3255
+ this.done = done;
3256
+ this.focused = true;
3257
+ this.modal = new DashboardModalController(tui, theme);
3258
+ this.modelSource = options.modelSource;
3259
+ this.codePreviewSettings = options.codePreviewSettings;
3260
+ this.keybindings = options.keybindings;
3261
+ this.claudeModelSource = options.claudeModelSource;
3262
+ this.onAgentSteer = options.onAgentSteer;
3263
+ this.onAgentFollowUp = options.onAgentFollowUp;
3264
+ this.onAgentStop = options.onAgentStop;
3265
+ this.onConversation = options.onConversation;
3266
+ this.onTargetMessage = options.onTargetMessage;
3267
+ this.agentTranscript = options.agentTranscript;
3268
+ this.actorTranscript = options.actorTranscript;
3269
+ this.loadOlderTranscript = options.loadOlderTranscript;
3270
+ this.loadNewerTranscript = options.loadNewerTranscript;
3271
+ this.loadLatestTranscript = options.loadLatestTranscript;
3272
+ this.onActorModel = options.onActorModel;
3273
+ this.onActorThinking = options.onActorThinking;
3274
+ this.onActorEvents = options.onActorEvents;
3275
+ this.onActorDeliveryPolicy = options.onActorDeliveryPolicy;
3276
+ this.onGlobalDeliveryPolicy = options.onGlobalDeliveryPolicy;
3277
+ this.onActorTools = options.onActorTools;
3278
+ this.actorDefaultTools = options.actorDefaultTools ?? [];
3279
+ this.onClearMessages = options.onClearMessages;
3280
+ this.onActorInstructions = options.onActorInstructions;
3281
+ this.onGlobalInstructions = options.onGlobalInstructions;
3282
+ this.onImportActor = options.onImportActor;
3283
+ this.onExportActor = options.onExportActor;
3284
+ this.onRemoveGlobalActor = options.onRemoveGlobalActor;
3285
+ this.detailRenderer = new DashboardDetailRenderer(tui, theme, snapshot, {
3286
+ agentTranscript: this.agentTranscript,
3287
+ actorTranscript: this.actorTranscript,
3288
+ codePreviewSettings: this.codePreviewSettings,
3289
+ actorDefaultTools: this.actorDefaultTools
3290
+ });
3291
+ }
3292
+ focused = false;
3293
+ pane = "phases";
3294
+ overviewView = "activity";
3295
+ graph = new DashboardGraphController(() => this.tui.requestRender());
3296
+ phaseIndex = 0;
3297
+ entityIndex = 0;
3298
+ runIndex = 0;
3299
+ selectedRunId;
3300
+ runSelectionTouched = false;
3301
+ selectedEntityId;
3302
+ filter = "all";
3303
+ phaseSelectionTouched = false;
3304
+ selectedPhaseId;
3305
+ detailId;
3306
+ detailScroll = 0;
3307
+ detailMaxScroll = 0;
3308
+ transcriptPageAnchor;
3309
+ transcriptToolsExpanded = false;
3310
+ detailSelectionRestore;
3311
+ detailView = "summary";
3312
+ transcriptFollowing = true;
3313
+ detailRenderer;
3314
+ highlightInvalidate = () => this.tui.requestRender();
3315
+ mode = "overview";
3316
+ modal;
3317
+ pendingStop;
3318
+ modelSource;
3319
+ claudeModelSource;
3320
+ onAgentSteer;
3321
+ onAgentFollowUp;
3322
+ onAgentStop;
3323
+ onConversation;
3324
+ onTargetMessage;
3325
+ agentTranscript;
3326
+ actorTranscript;
3327
+ loadOlderTranscript;
3328
+ loadNewerTranscript;
3329
+ loadLatestTranscript;
3330
+ onActorModel;
3331
+ onActorThinking;
3332
+ onActorEvents;
3333
+ onActorDeliveryPolicy;
3334
+ onGlobalDeliveryPolicy;
3335
+ onActorTools;
3336
+ actorDefaultTools;
3337
+ onClearMessages;
3338
+ onActorInstructions;
3339
+ onGlobalInstructions;
3340
+ onImportActor;
3341
+ onExportActor;
3342
+ onRemoveGlobalActor;
3343
+ codePreviewSettings;
3344
+ keybindings;
3345
+ handleInput(data) {
3346
+ if (this.mode === "help") {
3347
+ if (data === "?" || matchesKey(data, Key.escape) || matchesKey(data, Key.ctrl("c"))) {
3348
+ this.mode = this.detailId ? "detail" : "overview";
3349
+ }
3350
+ this.tui.requestRender();
3351
+ return;
3352
+ }
3353
+ if (this.modal.handleInput(data)) return;
3354
+ const snapshot = this.snapshot();
3355
+ const run = this.selectRun(snapshot);
3356
+ const panels = phasePanels(snapshot, run);
3357
+ this.syncPhase(run, panels);
3358
+ const panel = panels[this.phaseIndex];
3359
+ const projectMesh = this.projectMesh(snapshot);
3360
+ const allEntities = entitiesForOverview(
3361
+ snapshot,
3362
+ run,
3363
+ panel,
3364
+ this.overviewView,
3365
+ projectMesh
3366
+ );
3367
+ const entities = allEntities.filter(
3368
+ (entity) => entity.kind === "main" || matchesFilter(entity.status, this.filter)
3369
+ );
3370
+ this.syncEntitySelection(entities, this.overviewView !== "activity");
3371
+ if (data === "C" && this.onConversation) {
3372
+ const entity = this.detailId ? allEntities.find((candidate) => candidate.id === this.detailId) : entities[this.entityIndex];
3373
+ const target = entity ? this.messageTarget(entity) : void 0;
3374
+ if (target) this.onConversation(target.id);
3375
+ return;
3376
+ }
3377
+ if (data === "?") {
3378
+ this.mode = "help";
3379
+ this.tui.requestRender();
3380
+ return;
3381
+ }
3382
+ if (this.detailId) {
3383
+ if (matchesKey(data, Key.escape) || matchesKey(data, Key.ctrl("c")) || matchesKey(data, Key.left) || data === "h") {
3384
+ this.closeDetail();
3385
+ } else if (data === "t") {
3386
+ const detail = allEntities.find((entity) => entity.id === this.detailId);
3387
+ if (detail && this.hasTranscript(detail)) {
3388
+ this.detailView = this.detailView === "summary" ? "transcript" : "summary";
3389
+ this.detailScroll = 0;
3390
+ this.transcriptPageAnchor = void 0;
3391
+ this.transcriptFollowing = true;
3392
+ }
3393
+ } else if (this.detailView === "transcript" && this.matchesTranscriptToolToggle(data)) {
3394
+ this.transcriptToolsExpanded = !this.transcriptToolsExpanded;
3395
+ } else if (matchesKey(data, Key.up) || data === "k") {
3396
+ if (this.detailScroll > 0) {
3397
+ if (this.detailView === "transcript") this.transcriptFollowing = false;
3398
+ this.detailScroll--;
3399
+ } else if (this.detailView === "transcript") {
3400
+ const detail = allEntities.find((entity) => entity.id === this.detailId);
3401
+ const target = detail ? this.transcriptTarget(detail) : void 0;
3402
+ if (target && this.loadOlderTranscript?.(target)) {
3403
+ this.transcriptPageAnchor = "end";
3404
+ this.transcriptFollowing = false;
3405
+ }
3406
+ }
3407
+ } else if (matchesKey(data, Key.down) || data === "j") {
3408
+ if (this.detailScroll < this.detailMaxScroll) {
3409
+ if (this.detailView === "transcript") this.transcriptFollowing = false;
3410
+ this.detailScroll++;
3411
+ } else if (this.detailView === "transcript") {
3412
+ const detail = allEntities.find((entity) => entity.id === this.detailId);
3413
+ const target = detail ? this.transcriptTarget(detail) : void 0;
3414
+ if (target && this.loadNewerTranscript?.(target)) {
3415
+ this.transcriptPageAnchor = "start";
3416
+ this.transcriptFollowing = false;
3417
+ }
3418
+ }
3419
+ } else if (data === "G" && this.detailView === "transcript") {
3420
+ const detail = allEntities.find((entity) => entity.id === this.detailId);
3421
+ const target = detail ? this.transcriptTarget(detail) : void 0;
3422
+ if (target) this.loadLatestTranscript?.(target);
3423
+ this.transcriptPageAnchor = void 0;
3424
+ this.transcriptFollowing = true;
3425
+ this.detailScroll = this.detailMaxScroll;
3426
+ } else if (matchesKey(data, Key.home) || data === "g") {
3427
+ if (this.detailView === "transcript") {
3428
+ this.transcriptPageAnchor = void 0;
3429
+ this.transcriptFollowing = false;
3430
+ }
3431
+ this.detailScroll = 0;
3432
+ } else if (data === "s" || data === "u") {
3433
+ const detail = allEntities.find((entity) => entity.id === this.detailId);
3434
+ const delivery = data === "s" ? "steer" : "followUp";
3435
+ if (detail && this.canMessage(detail, delivery)) {
3436
+ this.openAgentMessageEditor(detail, delivery);
3437
+ }
3438
+ } else if (data === "m" || data === "M") {
3439
+ const detail = allEntities.find((entity) => entity.id === this.detailId);
3440
+ if (detail && detail.kind === "actor" && detail.status !== "stopped" && (data === "m" || detail.value.local !== false)) {
3441
+ this.openModelPicker(detail, data === "M" ? "project" : "session");
3442
+ }
3443
+ } else if (data === "e" || data === "E") {
3444
+ const detail = allEntities.find((entity) => entity.id === this.detailId);
3445
+ if (detail && detail.kind === "actor" && detail.status !== "stopped" && (data === "e" || detail.value.local !== false)) {
3446
+ this.openThinkingPicker(detail, data === "E" ? "project" : "session");
3447
+ }
3448
+ } else if (data === "y") {
3449
+ const detail = allEntities.find((entity) => entity.id === this.detailId);
3450
+ if (detail && (detail.kind === "globalActor" || detail.kind === "actor" && detail.value.local !== false)) {
3451
+ this.openDeliveryPicker(detail);
3452
+ }
3453
+ } else if (data === "v") {
3454
+ const detail = allEntities.find((entity) => entity.id === this.detailId);
3455
+ if (detail && detail.kind === "actor" && detail.status !== "stopped" && detail.value.local !== false) {
3456
+ this.openEventsPicker(detail);
3457
+ }
3458
+ } else if (data === "o") {
3459
+ const detail = allEntities.find((entity) => entity.id === this.detailId);
3460
+ if (detail && detail.kind === "actor" && detail.status !== "stopped" && detail.value.local !== false) {
3461
+ this.openToolsPicker(detail);
3462
+ }
3463
+ } else if (data === "c") {
3464
+ const detail = allEntities.find((entity) => entity.id === this.detailId);
3465
+ if (detail && detail.kind === "actor" && detail.status !== "stopped" && detail.value.local !== false && this.onClearMessages) {
3466
+ this.onClearMessages(detail.value.id);
3467
+ }
3468
+ } else if (data === "i") {
3469
+ const detail = allEntities.find((entity) => entity.id === this.detailId);
3470
+ if (detail && (detail.kind === "globalActor" || detail.kind === "actor" && detail.value.local !== false)) {
3471
+ this.openInstructionsEditor(detail);
3472
+ }
3473
+ } else if (data === "x") {
3474
+ const detail = allEntities.find((entity) => entity.id === this.detailId);
3475
+ if (detail && this.canStop(detail)) {
3476
+ this.requestParticipantStop(detail);
3477
+ } else if (detail && detail.kind === "actor" && detail.status !== "stopped" && this.onExportActor) {
3478
+ this.onExportActor(detail.value.id);
3479
+ }
3480
+ } else if (data === "p") {
3481
+ const detail = allEntities.find((entity) => entity.id === this.detailId);
3482
+ if (detail && detail.kind === "globalActor" && this.onImportActor) {
3483
+ this.onImportActor(detail.value.id);
3484
+ }
3485
+ } else if (data === "d") {
3486
+ const detail = allEntities.find((entity) => entity.id === this.detailId);
3487
+ if (detail && detail.kind === "globalActor" && this.onRemoveGlobalActor) {
3488
+ this.onRemoveGlobalActor(detail.value.id);
3489
+ }
3490
+ }
3491
+ this.tui.requestRender();
3492
+ return;
3493
+ }
3494
+ if (data === "1" || data === "2") {
3495
+ const nextOverview = data === "1" ? "activity" : "topology";
3496
+ if (nextOverview !== this.overviewView) {
3497
+ if (nextOverview === "activity") {
3498
+ this.graph.stopCameraAnimation();
3499
+ this.graph.stopEffectsAnimation();
3500
+ }
3501
+ this.overviewView = nextOverview;
3502
+ this.pane = nextOverview === "activity" ? "phases" : "entities";
3503
+ this.entityIndex = 0;
3504
+ this.selectedEntityId = void 0;
3505
+ this.pendingStop = void 0;
3506
+ }
3507
+ this.tui.requestRender();
3508
+ return;
3509
+ }
3510
+ if (matchesKey(data, Key.escape) || matchesKey(data, Key.ctrl("c"))) {
3511
+ if (this.overviewView === "activity" && this.pane === "entities") {
3512
+ this.pane = "phases";
3513
+ } else {
3514
+ this.done();
3515
+ return;
3516
+ }
3517
+ } else if (this.overviewView === "topology" && data === "r") {
3518
+ this.graph.toggleReplay(snapshot.events, (projectMesh ?? this.projectMesh(snapshot))?.routes ?? []);
3519
+ this.graph.startEffectsAnimation();
3520
+ this.tui.requestRender();
3521
+ return;
3522
+ } else if (this.overviewView === "topology" && this.graph.replayIndex !== void 0 && data === " ") {
3523
+ this.graph.togglePlayback();
3524
+ this.graph.startEffectsAnimation();
3525
+ this.tui.requestRender();
3526
+ return;
3527
+ } else if (this.overviewView === "topology" && this.graph.replayIndex !== void 0 && (matchesKey(data, Key.left) || matchesKey(data, Key.right))) {
3528
+ this.graph.stepReplay(matchesKey(data, Key.left) ? -1 : 1);
3529
+ this.tui.requestRender();
3530
+ return;
3531
+ } else if (this.overviewView === "topology" && (data === "+" || data === "=" || data === "-")) {
3532
+ this.graph.changeReplaySpeed(data === "-" ? -1 : 1);
3533
+ this.tui.requestRender();
3534
+ return;
3535
+ } else if (this.overviewView === "topology" && data === "H") {
3536
+ this.graph.toggleHistory();
3537
+ this.tui.requestRender();
3538
+ return;
3539
+ } else if (this.overviewView === "topology" && data === "M") {
3540
+ const selected = this.pane === "entities" ? entities[this.entityIndex] : void 0;
3541
+ if (selected?.kind === "actor" && selected.status !== "stopped" && selected.value.local !== false && this.modelSourceForActor(selected.value) && this.onActorModel) {
3542
+ this.detailId = selected.id;
3543
+ this.openModelPicker(selected, "project");
3544
+ } else {
3545
+ this.graph.toggleReducedMotion();
3546
+ }
3547
+ this.tui.requestRender();
3548
+ return;
3549
+ } else if (this.overviewView === "topology" && (matchesKey(data, Key.left) || matchesKey(data, Key.right) || matchesKey(data, Key.up) || matchesKey(data, Key.down) || data === "h" || data === "l")) {
3550
+ const direction = matchesKey(data, Key.left) || data === "h" ? "left" : matchesKey(data, Key.right) || data === "l" ? "right" : matchesKey(data, Key.up) ? "up" : "down";
3551
+ const target = this.graph.directionalTarget(this.selectedEntityId, direction);
3552
+ const targetIndex = target ? entities.findIndex((entity) => entity.id === target) : -1;
3553
+ if (targetIndex >= 0) {
3554
+ this.entityIndex = targetIndex;
3555
+ this.selectedEntityId = target;
3556
+ this.pendingStop = void 0;
3557
+ }
3558
+ this.tui.requestRender();
3559
+ return;
3560
+ } else if (matchesKey(data, Key.tab) && this.overviewView === "topology") {
3561
+ this.entityIndex = entities.length > 0 ? (this.entityIndex + 1) % entities.length : 0;
3562
+ this.selectedEntityId = entities[this.entityIndex]?.id;
3563
+ this.pendingStop = void 0;
3564
+ this.tui.requestRender();
3565
+ return;
3566
+ } else if (matchesKey(data, Key.tab) && this.overviewView === "activity") {
3567
+ this.pane = this.pane === "phases" ? "entities" : "phases";
3568
+ } else if (this.overviewView === "activity" && (matchesKey(data, Key.left) || data === "h")) {
3569
+ this.pane = "phases";
3570
+ } else if (this.overviewView === "activity" && (matchesKey(data, Key.right) || data === "l")) {
3571
+ this.pane = "entities";
3572
+ } else if (matchesKey(data, Key.up) || data === "k") {
3573
+ if (this.overviewView === "activity" && this.pane === "phases") {
3574
+ this.phaseIndex = Math.max(0, this.phaseIndex - 1);
3575
+ this.phaseSelectionTouched = true;
3576
+ this.entityIndex = 0;
3577
+ this.selectedEntityId = void 0;
3578
+ } else {
3579
+ this.entityIndex = Math.max(0, this.entityIndex - 1);
3580
+ }
3581
+ } else if (matchesKey(data, Key.down) || data === "j") {
3582
+ if (this.overviewView === "activity" && this.pane === "phases") {
3583
+ this.phaseIndex = Math.min(Math.max(0, panels.length - 1), this.phaseIndex + 1);
3584
+ this.phaseSelectionTouched = true;
3585
+ this.entityIndex = 0;
3586
+ this.selectedEntityId = void 0;
3587
+ } else {
3588
+ this.entityIndex = Math.min(Math.max(0, entities.length - 1), this.entityIndex + 1);
3589
+ }
3590
+ } else if (["m", "M", "e", "E", "y", "v", "o", "i", "c", "s", "u", "x", "p", "d"].includes(data) && this.pane === "entities") {
3591
+ const selected = entities[this.entityIndex];
3592
+ if (selected) {
3593
+ if ((data === "s" || data === "u") && this.canMessage(selected, data === "s" ? "steer" : "followUp")) {
3594
+ this.detailId = selected.id;
3595
+ this.openAgentMessageEditor(selected, data === "s" ? "steer" : "followUp");
3596
+ } else if (data === "x" && this.canStop(selected)) {
3597
+ this.requestParticipantStop(selected);
3598
+ } else if (data === "x" && selected.kind === "actor" && selected.status !== "stopped" && this.onExportActor) {
3599
+ this.onExportActor(selected.value.id);
3600
+ } else if ((data === "m" || data === "M") && selected.kind === "actor" && selected.status !== "stopped" && (data === "m" || selected.value.local !== false)) {
3601
+ this.detailId = selected.id;
3602
+ this.openModelPicker(selected, data === "M" ? "project" : "session");
3603
+ } else if ((data === "e" || data === "E") && selected.kind === "actor" && selected.status !== "stopped" && (data === "e" || selected.value.local !== false)) {
3604
+ this.detailId = selected.id;
3605
+ this.openThinkingPicker(selected, data === "E" ? "project" : "session");
3606
+ } else if (data === "y" && (selected.kind === "globalActor" || selected.kind === "actor" && selected.status !== "stopped" && selected.value.local !== false)) {
3607
+ this.detailId = selected.id;
3608
+ this.openDeliveryPicker(selected);
3609
+ } else if (data === "v" && selected.kind === "actor" && selected.status !== "stopped" && selected.value.local !== false) {
3610
+ this.detailId = selected.id;
3611
+ this.openEventsPicker(selected);
3612
+ } else if (data === "o" && selected.kind === "actor" && selected.status !== "stopped" && selected.value.local !== false) {
3613
+ this.detailId = selected.id;
3614
+ this.openToolsPicker(selected);
3615
+ } else if (data === "c" && selected.kind === "actor" && selected.status !== "stopped" && selected.value.local !== false && this.onClearMessages) {
3616
+ this.onClearMessages(selected.value.id);
3617
+ } else if (data === "i" && (selected.kind === "globalActor" || selected.kind === "actor" && selected.value.local !== false)) {
3618
+ this.detailId = selected.id;
3619
+ this.openInstructionsEditor(selected);
3620
+ } else if (data === "p" && selected.kind === "globalActor" && this.onImportActor) {
3621
+ this.onImportActor(selected.value.id);
3622
+ } else if (data === "d" && selected.kind === "globalActor" && this.onRemoveGlobalActor) {
3623
+ this.onRemoveGlobalActor(selected.value.id);
3624
+ }
3625
+ }
3626
+ } else if (data === " " && this.pane === "entities") {
3627
+ const selected = entities[this.entityIndex];
3628
+ if (selected && this.hasTranscript(selected)) {
3629
+ this.detailId = selected.id;
3630
+ this.detailView = "transcript";
3631
+ this.detailScroll = 0;
3632
+ this.transcriptPageAnchor = void 0;
3633
+ this.transcriptFollowing = true;
3634
+ }
3635
+ } else if (matchesKey(data, Key.enter)) {
3636
+ if (this.overviewView === "activity" && this.pane === "phases") {
3637
+ this.pane = "entities";
3638
+ } else {
3639
+ const selected = entities[this.entityIndex];
3640
+ if (selected) {
3641
+ this.detailId = selected.id;
3642
+ this.detailView = "summary";
3643
+ this.detailScroll = 0;
3644
+ this.transcriptFollowing = true;
3645
+ }
3646
+ }
3647
+ } else if (data === "f") {
3648
+ const next = (filters.indexOf(this.filter) + 1) % filters.length;
3649
+ this.filter = filters[next] ?? "all";
3650
+ this.entityIndex = 0;
3651
+ this.selectedEntityId = void 0;
3652
+ this.tui.requestRender();
3653
+ return;
3654
+ } else if (data === "[") {
3655
+ this.runIndex = Math.min(Math.max(0, snapshot.runs.length - 1), this.runIndex + 1);
3656
+ this.selectedRunId = snapshot.runs[this.runIndex]?.id;
3657
+ this.runSelectionTouched = true;
3658
+ this.resetSelection();
3659
+ this.tui.requestRender();
3660
+ return;
3661
+ } else if (data === "]") {
3662
+ this.runIndex = Math.max(0, this.runIndex - 1);
3663
+ this.selectedRunId = snapshot.runs[this.runIndex]?.id;
3664
+ this.runSelectionTouched = true;
3665
+ this.resetSelection();
3666
+ this.tui.requestRender();
3667
+ return;
3668
+ } else if (data === "G") {
3669
+ if (this.overviewView === "activity" && this.pane === "phases") {
3670
+ this.phaseIndex = Math.max(0, panels.length - 1);
3671
+ this.phaseSelectionTouched = true;
3672
+ this.entityIndex = 0;
3673
+ this.selectedEntityId = void 0;
3674
+ } else {
3675
+ this.entityIndex = Math.max(0, entities.length - 1);
3676
+ }
3677
+ } else if (data === "g") {
3678
+ if (this.overviewView === "activity" && this.pane === "phases") {
3679
+ this.phaseIndex = 0;
3680
+ this.phaseSelectionTouched = true;
3681
+ this.entityIndex = 0;
3682
+ this.selectedEntityId = void 0;
3683
+ } else {
3684
+ this.entityIndex = 0;
3685
+ }
3686
+ }
3687
+ if (this.phaseSelectionTouched) this.selectedPhaseId = panels[this.phaseIndex]?.id;
3688
+ if (this.detailId) {
3689
+ this.pinDetailSelection(run, panel, this.overviewView === "activity");
3690
+ }
3691
+ if (this.pane === "entities") {
3692
+ this.selectedEntityId = entities[this.entityIndex]?.id;
3693
+ }
3694
+ this.tui.requestRender();
3695
+ }
3696
+ render(width) {
3697
+ if (width <= 0) return [];
3698
+ if (this.mode === "help") return this.renderHelp(width);
3699
+ const modal = this.modal.render(width, (w, content) => this.renderModal(w, content));
3700
+ if (modal) return modal;
3701
+ const snapshot = this.snapshot();
3702
+ const run = this.selectRun(snapshot);
3703
+ const panels = phasePanels(snapshot, run);
3704
+ this.syncPhase(run, panels);
3705
+ const panel = panels[this.phaseIndex];
3706
+ const projectMesh = this.projectMesh(snapshot);
3707
+ const allEntities = entitiesForOverview(
3708
+ snapshot,
3709
+ run,
3710
+ panel,
3711
+ this.overviewView,
3712
+ projectMesh
3713
+ );
3714
+ const entities = allEntities.filter(
3715
+ (entity) => entity.kind === "main" || matchesFilter(entity.status, this.filter)
3716
+ );
3717
+ this.syncEntitySelection(entities, this.overviewView !== "activity");
3718
+ if (this.detailId) {
3719
+ const detail = allEntities.find((entity) => entity.id === this.detailId);
3720
+ if (detail) return this.renderDetail(width, snapshot, detail);
3721
+ this.closeDetail();
3722
+ }
3723
+ return this.renderOverview(
3724
+ width,
3725
+ snapshot,
3726
+ run,
3727
+ panels,
3728
+ entities,
3729
+ allEntities,
3730
+ projectMesh
3731
+ );
3732
+ }
3733
+ invalidate() {
3734
+ this.detailRenderer.invalidate();
3735
+ }
3736
+ dispose() {
3737
+ this.modal.dispose();
3738
+ this.pendingStop = void 0;
3739
+ this.graph.stopCameraAnimation();
3740
+ this.graph.stopEffectsAnimation();
3741
+ this.detailRenderer.invalidate();
3742
+ this.mode = "overview";
3743
+ }
3744
+ transcriptTarget(entity) {
3745
+ if (entity.kind === "agent" || entity.kind === "actor") return entity.value;
3746
+ return void 0;
3747
+ }
3748
+ hasTranscript(entity) {
3749
+ return entity.kind === "agent" && this.agentTranscript !== void 0 || entity.kind === "actor" && this.actorTranscript !== void 0;
3750
+ }
3751
+ matchesTranscriptToolToggle(data) {
3752
+ if (this.keybindings) return this.keybindings.matches(data, "app.tools.expand");
3753
+ const keybindings = getKeybindings4();
3754
+ const keys = keybindings.getKeys("app.tools.expand");
3755
+ return keys.length > 0 ? keybindings.matches(data, "app.tools.expand") : matchesKey(data, Key.ctrl("o"));
3756
+ }
3757
+ transcriptToolToggleHint() {
3758
+ const keys = (this.keybindings ?? getKeybindings4()).getKeys("app.tools.expand");
3759
+ const key = keys.length > 0 ? keys.join("/") : this.keybindings ? "unbound" : "ctrl+o";
3760
+ return `${key} ${this.transcriptToolsExpanded ? "collapse" : "expand"} tools`;
3761
+ }
3762
+ messageTarget(entity) {
3763
+ if (entity.kind === "main") {
3764
+ return { id: entity.value.id, name: "Main", kind: "main" };
3765
+ }
3766
+ if (entity.kind === "peer") {
3767
+ return { id: entity.value.id, name: entity.value.name, kind: "peer" };
3768
+ }
3769
+ if (entity.kind === "agent") {
3770
+ return { id: entity.value.id, name: entity.value.name, kind: "agent" };
3771
+ }
3772
+ if (entity.kind === "actor") {
3773
+ return { id: entity.value.id, name: entity.value.name, kind: "actor" };
3774
+ }
3775
+ if (entity.kind === "meshParticipant") {
3776
+ return { id: entity.value.id, name: entity.value.name, kind: "meshParticipant" };
3777
+ }
3778
+ return void 0;
3779
+ }
3780
+ canMessage(entity, delivery) {
3781
+ const target = this.messageTarget(entity);
3782
+ if (!target) return false;
3783
+ if (target.kind === "agent") {
3784
+ if (!isActiveStatus(entity.status)) return false;
3785
+ if (entity.kind === "agent" && entity.value.capabilities && !entity.value.capabilities.includes(delivery)) {
3786
+ return false;
3787
+ }
3788
+ return Boolean(
3789
+ this.onTargetMessage || (delivery === "steer" ? this.onAgentSteer : this.onAgentFollowUp)
3790
+ );
3791
+ }
3792
+ if (!this.onTargetMessage) return false;
3793
+ if (target.kind === "actor") return entity.status !== "stopped" && delivery === "steer";
3794
+ if (target.kind === "meshParticipant" && entity.kind === "meshParticipant") {
3795
+ const participant = entity.value.participant;
3796
+ return participant ? !participant.stale && participant.capabilities.includes(delivery) : true;
3797
+ }
3798
+ return true;
3799
+ }
3800
+ openAgentMessageEditor(entity, delivery) {
3801
+ const target = this.messageTarget(entity);
3802
+ if (!target || !this.canMessage(entity, delivery)) return;
3803
+ this.modal.openMessage(target, delivery, (message) => {
3804
+ if (this.onTargetMessage) {
3805
+ this.onTargetMessage(target, message, delivery);
3806
+ } else if (target.kind === "agent") {
3807
+ if (delivery === "steer") this.onAgentSteer?.(target.id, message);
3808
+ else this.onAgentFollowUp?.(target.id, message);
3809
+ }
3810
+ }, () => {
3811
+ this.mode = this.detailId ? "detail" : "overview";
3812
+ });
3813
+ }
3814
+ canStop(entity) {
3815
+ if (!this.onAgentStop) return false;
3816
+ if (entity.kind === "agent") {
3817
+ return isActiveStatus(entity.status) && (!entity.value.capabilities || entity.value.capabilities.includes("stop"));
3818
+ }
3819
+ if (entity.kind === "meshParticipant") {
3820
+ const participant = entity.value.participant;
3821
+ return Boolean(
3822
+ participant && !participant.stale && participant.capabilities.includes("stop")
3823
+ );
3824
+ }
3825
+ return false;
3826
+ }
3827
+ requestParticipantStop(entity) {
3828
+ if (!this.onAgentStop || !this.canStop(entity)) return;
3829
+ const now = Date.now();
3830
+ if (this.pendingStop?.id === entity.value.id && this.pendingStop.expiresAt > now) {
3831
+ this.pendingStop = void 0;
3832
+ this.onAgentStop(entity.value.id);
3833
+ return;
3834
+ }
3835
+ this.pendingStop = { id: entity.value.id, expiresAt: now + 2e3 };
3836
+ }
3837
+ renderModal(width, content) {
3838
+ if (width < 24) return this.renderNarrowFallback(width, content.narrowTitle, "esc cancel");
3839
+ const lines = [this.topBorder(width, content.title)];
3840
+ for (const line of content.render(width - 2)) lines.push(this.row(width, line));
3841
+ lines.push(this.middleBorder(width));
3842
+ lines.push(this.row(width, this.theme.fg("dim", content.hint)));
3843
+ lines.push(this.bottomBorder(width));
3844
+ return lines.map((line) => truncateToWidth4(line, width, ""));
3845
+ }
3846
+ renderHelp(width) {
3847
+ if (width < 24) return this.renderNarrowFallback(width, "dashboard help", "? or esc close");
3848
+ const lines = [this.topBorder(width, "Fabric dashboard help")];
3849
+ const mainActions = [
3850
+ this.onTargetMessage ? "s message/steer" : void 0,
3851
+ this.onTargetMessage ? "u queue follow-up" : void 0,
3852
+ "enter details"
3853
+ ].filter((value) => Boolean(value));
3854
+ const agentActions = [
3855
+ this.agentTranscript ? "space transcript peek" : void 0,
3856
+ this.onTargetMessage || this.onAgentSteer ? "s steer now" : void 0,
3857
+ this.onTargetMessage || this.onAgentFollowUp ? "u queue follow-up" : void 0,
3858
+ this.onAgentStop ? "x twice stop" : void 0,
3859
+ "enter details"
3860
+ ].filter((value) => Boolean(value));
3861
+ const actorActions = [
3862
+ this.actorTranscript ? "space transcript peek" : void 0,
3863
+ this.onTargetMessage ? "s queue message" : void 0,
3864
+ (this.modelSource || this.claudeModelSource) && this.onActorModel ? "m session model \xB7 M pin model" : void 0,
3865
+ this.onActorThinking ? "e session thinking \xB7 E pin thinking" : void 0,
3866
+ this.onActorDeliveryPolicy ? "y delivery policy" : void 0,
3867
+ this.onActorEvents ? "v events" : void 0,
3868
+ this.onActorTools ? "o tools" : void 0,
3869
+ this.onActorInstructions ? "i instructions" : void 0,
3870
+ this.onClearMessages ? "c clear mailbox" : void 0,
3871
+ this.onExportActor ? "x export" : void 0
3872
+ ].filter((value) => Boolean(value));
3873
+ const templateActions = [
3874
+ this.onGlobalDeliveryPolicy ? "y delivery policy" : void 0,
3875
+ this.onGlobalInstructions ? "i instructions" : void 0,
3876
+ this.onImportActor ? "p import" : void 0,
3877
+ this.onRemoveGlobalActor ? "d delete" : void 0
3878
+ ].filter((value) => Boolean(value));
3879
+ const help = [
3880
+ ["Navigate", "Topology: arrows/h/l move spatially \xB7 j/k ordered selection \xB7 tab next \xB7 enter inspect \xB7 esc back"],
3881
+ ["Views", "1 Activity \xB7 2 unified Topology"],
3882
+ ...this.onConversation ? [["Chat", "Shift+C opens the selected participant conversation \xB7 Esc returns to Main"]] : [],
3883
+ ["Topology", "Main branches into Participants (sessions, agents, actors) and Mesh (namespaced topics and hierarchical state); traffic travels on decaying edges"],
3884
+ ["Motion", "r replay/live \xB7 space pause/play \xB7 \u2190/\u2192 step \xB7 +/- speed \xB7 H history \xB7 M reduced motion"],
3885
+ ["Runs", "[ older \xB7 ] newer \xB7 f cycle status filter"],
3886
+ ...mainActions.length > 1 ? [["Main", mainActions.join(" \xB7 ")]] : [],
3887
+ ...agentActions.length > 1 ? [["Agents", agentActions.join(" \xB7 ")]] : [],
3888
+ ...actorActions.length > 0 ? [["Actors", actorActions.join(" \xB7 ")]] : [],
3889
+ ...templateActions.length > 0 ? [["Templates", templateActions.join(" \xB7 ")]] : [],
3890
+ [
3891
+ "Details",
3892
+ `\u2191\u2193/jk lazy scroll \xB7 g page top \xB7 G live tail \xB7 ${this.transcriptToolToggleHint()} \xB7 t transcript/summary \xB7 ? close help`
3893
+ ]
3894
+ ];
3895
+ for (const [label, value] of help) {
3896
+ const prefix = `${this.theme.fg("accent", `${label}:`)} `;
3897
+ const wrapped = wrapPlainText(value ?? "", Math.max(1, width - 2 - visibleWidth4(prefix)), 3);
3898
+ if (wrapped[0]) lines.push(this.row(width, prefix + wrapped[0]));
3899
+ for (const continuation of wrapped.slice(1)) {
3900
+ lines.push(this.row(width, " ".repeat(visibleWidth4(prefix)) + continuation));
3901
+ }
3902
+ }
3903
+ lines.push(this.middleBorder(width));
3904
+ lines.push(this.row(width, this.theme.fg("dim", " ? or esc close")));
3905
+ lines.push(this.bottomBorder(width));
3906
+ return lines.map((line) => truncateToWidth4(line, width, ""));
3907
+ }
3908
+ modelSourceForActor(actor) {
3909
+ return actor.runner === "claude" ? this.claudeModelSource : this.modelSource;
3910
+ }
3911
+ openModelPicker(entity, scope = "session") {
3912
+ if (entity.kind !== "actor" || !this.onActorModel) return;
3913
+ const actor = entity.value;
3914
+ if (scope === "project" && actor.local === false) return;
3915
+ const source = this.modelSourceForActor(actor);
3916
+ if (!source) return;
3917
+ const projectModel = actor.projectDefaults?.model ?? (actor.binding ? void 0 : actor.model);
3918
+ const currentValue = scope === "session" ? actor.binding?.model : projectModel;
3919
+ const runtimeDefault = actor.runner === "claude" ? "Fabric Claude model (or Claude Code runtime default)" : "Fabric Pi model (or host default)";
3920
+ this.modal.openPicker("model", actor.name, (close) => new FabricModelSelector({
3921
+ theme: this.theme,
3922
+ source,
3923
+ currentValue: currentValue ?? INHERIT_VALUE,
3924
+ headerText: scope === "session" ? actor.runner === "claude" ? `Model for Claude actor "${actor.name}" \xB7 session binding. Inherit uses the project default.` : `Model for actor "${actor.name}" \xB7 session binding. Inherit uses the project default.` : `Project model default for actor "${actor.name}". This pin is shared by every session.`,
3925
+ inheritName: scope === "session" ? `Use project default (${projectModel ?? runtimeDefault})` : `Clear project pin; use ${runtimeDefault}`,
3926
+ onSelect: (value) => {
3927
+ const model = value === INHERIT_VALUE ? void 0 : value;
3928
+ this.onActorModel(actor.id, model, scope);
3929
+ close();
3930
+ },
3931
+ onCancel: () => close()
3932
+ }), () => {
3933
+ this.mode = "detail";
3934
+ });
3935
+ }
3936
+ openThinkingPicker(entity, scope = "session") {
3937
+ if (entity.kind !== "actor" || !this.onActorThinking) return;
3938
+ const actor = entity.value;
3939
+ if (scope === "project" && actor.local === false) return;
3940
+ const projectThinking = actor.projectDefaults?.thinking ?? (actor.binding ? void 0 : actor.thinking);
3941
+ const currentValue = scope === "session" ? actor.binding?.thinking : projectThinking;
3942
+ this.modal.openPicker("thinking", actor.name, (close) => new FabricThinkingSelector({
3943
+ theme: this.theme,
3944
+ currentValue: currentValue ?? INHERIT_VALUE,
3945
+ headerText: scope === "session" ? `Thinking level for actor "${actor.name}" \xB7 session binding. Inherit uses the project default.` : `Project thinking default for actor "${actor.name}". This pin is shared by every session.`,
3946
+ inheritName: scope === "session" ? `Use project default (${projectThinking ?? "Fabric default"})` : "Clear project pin; use the Fabric default thinking level",
3947
+ onSelect: (value) => {
3948
+ const thinking = value === INHERIT_VALUE ? void 0 : value;
3949
+ this.onActorThinking(
3950
+ actor.id,
3951
+ isFabricThinking(thinking) ? thinking : void 0,
3952
+ scope
3953
+ );
3954
+ close();
3955
+ },
3956
+ onCancel: () => close()
3957
+ }), () => {
3958
+ this.mode = "detail";
3959
+ });
3960
+ }
3961
+ openDeliveryPicker(entity) {
3962
+ if (entity.kind !== "actor" && entity.kind !== "globalActor") return;
3963
+ const target = entity.value;
3964
+ const callback = entity.kind === "actor" ? this.onActorDeliveryPolicy : this.onGlobalDeliveryPolicy;
3965
+ if (!callback || entity.kind === "actor" && (entity.status === "stopped" || entity.value.local === false)) return;
3966
+ this.modal.openPicker("delivery", target.name, (close) => new FabricActorDeliverySelector({
3967
+ theme: this.theme,
3968
+ currentValue: { delivery: target.delivery, triggerTurn: target.triggerTurn },
3969
+ headerText: `Delivery policy for ${entity.kind === "actor" ? "actor" : "template"} "${target.name}". Active delivery requires an explicit resume choice.`,
3970
+ onSelect: (policy) => {
3971
+ callback(target.id, policy.delivery, policy.triggerTurn);
3972
+ close();
3973
+ },
3974
+ onCancel: () => close()
3975
+ }), () => {
3976
+ this.mode = "detail";
3977
+ });
3978
+ }
3979
+ openEventsPicker(entity) {
3980
+ if (entity.kind !== "actor" || entity.value.local === false || !this.onActorEvents) return;
3981
+ const actor = entity.value;
3982
+ this.modal.openPicker("events", actor.name, (close) => new FabricHostEventSelector({
3983
+ theme: this.theme,
3984
+ currentValue: actor.events,
3985
+ headerText: `Host events for actor "${actor.name}". Toggle with space, Enter to apply, Esc to cancel.`,
3986
+ onSelect: (events) => {
3987
+ this.onActorEvents(actor.id, events);
3988
+ close();
3989
+ },
3990
+ onCancel: () => close()
3991
+ }), () => {
3992
+ this.mode = "detail";
3993
+ });
3994
+ }
3995
+ openToolsPicker(entity) {
3996
+ if (entity.kind !== "actor" || entity.value.local === false || !this.onActorTools) return;
3997
+ const actor = entity.value;
3998
+ this.modal.openPicker("tools", actor.name, (close) => new FabricActorToolSelector({
3999
+ theme: this.theme,
4000
+ currentValue: actor.tools ?? this.actorDefaultTools,
4001
+ headerText: `Tools for actor "${actor.name}". Toggle with space, Enter to apply, Esc to cancel. Pi actors always retain fabric_exec.`,
4002
+ onSelect: (tools) => {
4003
+ this.onActorTools(actor.id, tools);
4004
+ close();
4005
+ },
4006
+ onCancel: () => close()
4007
+ }), () => {
4008
+ this.mode = "detail";
4009
+ });
4010
+ }
4011
+ /**
4012
+ * Open the embedded multi-line editor for an actor's default instruction.
4013
+ * Matches Pi's editor dialog convention (Enter submit, Shift+Enter newline,
4014
+ * Esc/Ctrl+C cancel) so a steering user edits the persona with the same
4015
+ * muscle memory as the chat input. Works for both live project actors and
4016
+ * global templates; the submit routes to the scope-appropriate callback.
4017
+ */
4018
+ openInstructionsEditor(entity) {
4019
+ let kind;
4020
+ let id;
4021
+ let name;
4022
+ let instructions;
4023
+ if (entity.kind === "actor") {
4024
+ if (entity.status === "stopped" || entity.value.local === false || !this.onActorInstructions) return;
4025
+ kind = "actor";
4026
+ id = entity.value.id;
4027
+ name = entity.value.name;
4028
+ instructions = entity.value.instructions;
4029
+ } else if (entity.kind === "globalActor") {
4030
+ if (!this.onGlobalInstructions) return;
4031
+ kind = "globalActor";
4032
+ id = entity.value.id;
4033
+ name = entity.value.name;
4034
+ instructions = entity.value.instructions;
4035
+ } else {
4036
+ return;
4037
+ }
4038
+ this.modal.openInstructions(name, instructions, (text) => {
4039
+ if (kind === "actor") this.onActorInstructions?.(id, text);
4040
+ else this.onGlobalInstructions?.(id, text);
4041
+ }, () => {
4042
+ this.mode = "detail";
4043
+ });
4044
+ }
4045
+ projectMesh(snapshot) {
4046
+ if (this.overviewView !== "topology") return void 0;
4047
+ return buildProjectMeshTopology({
4048
+ main: snapshot.main,
4049
+ actors: snapshot.actors,
4050
+ agents: snapshot.agents,
4051
+ state: snapshot.state,
4052
+ events: snapshot.events,
4053
+ ...snapshot.participants ? { participants: snapshot.participants } : {},
4054
+ now: snapshot.now
4055
+ });
4056
+ }
4057
+ renderOverview(width, snapshot, run, panels, entities, allEntities, meshModel) {
4058
+ if (width < 24) {
4059
+ return [truncateToWidth4("too narrow \xB7 need 24 cols", width)];
4060
+ }
4061
+ const innerWidth = width - 2;
4062
+ const terminalRows = Math.max(
4063
+ 1,
4064
+ this.tui.terminal?.rows ?? process.stdout.rows ?? 28
4065
+ );
4066
+ const overlayRows = dashboardOverlayRows(terminalRows);
4067
+ const lines = [];
4068
+ const title = this.overviewView === "activity" ? `Fabric \xB7 ${run?.name ?? "session"} \xB7 Activity` : "Fabric \xB7 Topology";
4069
+ lines.push(this.topBorder(width, title));
4070
+ const runAgents = run ? snapshot.agents.filter((agent) => agent.runId === run.id) : snapshot.agents;
4071
+ const activeAgents = runAgents.filter((agent) => isActiveStatus(agent.status)).length;
4072
+ const hasDetachedWork = activeAgents > 0;
4073
+ const runTokens = tokensFor(snapshot, run);
4074
+ const largeRun = runAgents.length > 25 || runTokens > 15e5;
4075
+ const elapsed = run ? formatDuration(((hasDetachedWork ? snapshot.now : run.finishedAt) ?? snapshot.now) - run.startedAt) : void 0;
4076
+ const activeActors = snapshot.actors.filter((actor) => isActiveStatus(actor.status)).length;
4077
+ const summary = (meshModel ? [
4078
+ run?.name ? `focus ${run.name}` : void 0,
4079
+ run?.currentPhaseId ? `current ${run.phases.find((phase) => phase.id === run.currentPhaseId)?.name ?? run.currentPhaseId}` : void 0,
4080
+ `Participants ${snapshot.agents.filter((agent) => isActiveStatus(agent.status)).length}/${snapshot.agents.length} agents \xB7 ${activeActors}/${snapshot.actors.length} actors \xB7 ${meshModel.participants.length} remote`,
4081
+ `Mesh ${meshModel.topics.length} topics \xB7 ${snapshot.state.length} state`,
4082
+ this.graph.replayIndex !== void 0 ? `${this.graph.replayPlaying ? "\u25B6" : "\u2161"} replay ${this.graph.replayIndex + 1}/${Math.max(1, this.graph.replayLength)} \xB7 ${this.graph.replaySpeed}\xD7` : void 0,
4083
+ snapshot.runs.length > 1 ? `run ${this.runIndex + 1}/${snapshot.runs.length}` : void 0
4084
+ ] : [
4085
+ this.overviewView === "topology" ? run?.name : void 0,
4086
+ run?.status,
4087
+ largeRun ? "\u26A0 large run" : void 0,
4088
+ `${activeAgents}/${runAgents.length} run agents active`,
4089
+ `${snapshot.actors.length} actors`,
4090
+ runTokens > 0 ? `${formatTokens(runTokens)} tok` : void 0,
4091
+ elapsed,
4092
+ snapshot.runs.length > 1 ? `run ${this.runIndex + 1}/${snapshot.runs.length}` : void 0
4093
+ ]).filter((value) => Boolean(value)).join(" \xB7 ");
4094
+ const summaryText = safeText(summary);
4095
+ let headerLine = summaryText;
4096
+ if (run?.description && this.overviewView === "activity") {
4097
+ const gap = " ";
4098
+ const availableDescription = innerWidth - visibleWidth4(summaryText) - gap.length;
4099
+ headerLine = availableDescription >= 12 ? `${padToWidth(
4100
+ this.theme.fg("muted", safeText(run.description)),
4101
+ availableDescription
4102
+ )}${gap}${this.theme.fg("dim", summaryText)}` : this.theme.fg("dim", summaryText);
4103
+ } else if (summaryText) {
4104
+ headerLine = this.theme.fg("dim", summaryText);
4105
+ }
4106
+ const minimumRows = 8;
4107
+ if (overlayRows < minimumRows) {
4108
+ return [
4109
+ title,
4110
+ this.theme.fg("dim", summaryText || "No Fabric activity yet"),
4111
+ this.theme.fg("dim", "1 activity \xB7 2 topology \xB7 arrows move \xB7 esc close")
4112
+ ].slice(0, overlayRows).map((line) => truncateToWidth4(line, width, ""));
4113
+ }
4114
+ lines.push(this.row(width, headerLine || this.theme.fg("muted", "No Fabric activity yet")));
4115
+ lines.push(this.middleBorder(width));
4116
+ const desiredRunEvents = run?.events.slice(-2) ?? [];
4117
+ const desiredMeshEventCount = Math.max(0, 2 - desiredRunEvents.length);
4118
+ const desiredMeshEvents = desiredMeshEventCount > 0 ? snapshot.events.slice(-desiredMeshEventCount) : [];
4119
+ const optionalEventRoom = Math.max(0, overlayRows - minimumRows);
4120
+ const eventRows = optionalEventRoom >= 2 ? Math.min(2, optionalEventRoom - 1) : 0;
4121
+ const runEventRows = Math.min(desiredRunEvents.length, eventRows);
4122
+ const meshEventRows = Math.max(0, eventRows - runEventRows);
4123
+ const runEvents = runEventRows > 0 ? desiredRunEvents.slice(-runEventRows) : [];
4124
+ const meshEvents = meshEventRows > 0 ? desiredMeshEvents.slice(-meshEventRows) : [];
4125
+ const eventChromeRows = eventRows > 0 ? eventRows + 1 : 0;
4126
+ const maxBody = Math.max(
4127
+ 1,
4128
+ Math.min(this.overviewView === "topology" ? 30 : 22, overlayRows - 7 - eventChromeRows)
4129
+ );
4130
+ if (this.overviewView === "topology") {
4131
+ const topology = meshModel ?? buildProjectMeshTopology({
4132
+ main: snapshot.main,
4133
+ actors: snapshot.actors,
4134
+ agents: snapshot.agents,
4135
+ state: snapshot.state,
4136
+ events: snapshot.events,
4137
+ ...snapshot.participants ? { participants: snapshot.participants } : {},
4138
+ now: snapshot.now
4139
+ });
4140
+ this.graph.startEffectsAnimation();
4141
+ const replayFrame = this.graph.replayFrame(snapshot.events, topology.routes);
4142
+ const renderGraph = () => renderFabricTopologyPanel({
4143
+ theme: this.theme,
4144
+ filter: this.filter,
4145
+ selectedEntityId: this.selectedEntityId,
4146
+ snapshot,
4147
+ run,
4148
+ mesh: topology,
4149
+ allEntities,
4150
+ entities,
4151
+ width: innerWidth,
4152
+ height: maxBody,
4153
+ camera: this.graph.camera,
4154
+ invalidate: this.highlightInvalidate,
4155
+ animation: {
4156
+ now: Date.now(),
4157
+ reducedMotion: this.graph.reducedMotion,
4158
+ showHistory: this.graph.showHistory,
4159
+ ...replayFrame ? { replayRouteId: replayFrame.route.id, replayLabel: replayFrame.event.kind } : {}
4160
+ }
4161
+ });
4162
+ const cameraWasInitialized = this.graph.cameraInitialized;
4163
+ let rendered = renderGraph();
4164
+ this.graph.setPositions(rendered.positions);
4165
+ if (rendered.selectedPosition) this.graph.setCameraTarget(rendered.selectedPosition);
4166
+ if (!cameraWasInitialized && this.graph.cameraInitialized) rendered = renderGraph();
4167
+ for (const line of rendered.lines) lines.push(this.row(width, line));
4168
+ } else if (innerWidth >= 88) {
4169
+ const leftWidth = Math.min(38, Math.max(28, Math.floor((innerWidth - 1) * 0.34)));
4170
+ const rightWidth = innerWidth - leftWidth - 1;
4171
+ const leftLines = this.renderPhasePanel(panels, leftWidth, maxBody);
4172
+ const rightLines = this.renderEntityPanel(entities, rightWidth, maxBody, snapshot.now);
4173
+ for (let index = 0; index < maxBody; index++) {
4174
+ const left = leftLines[index] ?? "";
4175
+ const right = rightLines[index] ?? "";
4176
+ lines.push(
4177
+ this.row(
4178
+ width,
4179
+ `${padToWidth(left, leftWidth)}${this.theme.fg("borderMuted", "\u2502")}${padToWidth(
4180
+ right,
4181
+ rightWidth
4182
+ )}`
4183
+ )
4184
+ );
4185
+ }
4186
+ } else {
4187
+ const panelRows = Math.max(2, maxBody - 1);
4188
+ const phaseHeight = Math.max(1, Math.min(panels.length + 1, Math.floor(panelRows * 0.45)));
4189
+ const entityHeight = Math.max(1, panelRows - phaseHeight);
4190
+ for (const line of this.renderPhasePanel(panels, innerWidth, phaseHeight)) {
4191
+ lines.push(this.row(width, line));
4192
+ }
4193
+ lines.push(this.row(width, this.theme.fg("borderMuted", "\u2500".repeat(innerWidth))));
4194
+ for (const line of this.renderEntityPanel(entities, innerWidth, entityHeight, snapshot.now)) {
4195
+ lines.push(this.row(width, line));
4196
+ }
4197
+ }
4198
+ if (eventRows > 0) {
4199
+ lines.push(this.middleBorder(width));
4200
+ let renderedEventRows = 0;
4201
+ for (const event of runEvents) {
4202
+ lines.push(
4203
+ this.row(
4204
+ width,
4205
+ colorStatus(
4206
+ this.theme,
4207
+ event.level === "success" ? "completed" : event.level,
4208
+ `[${formatClock(event.createdAt)}] ${safeText(event.message)}`
4209
+ )
4210
+ )
4211
+ );
4212
+ renderedEventRows++;
4213
+ }
4214
+ for (const event of meshEvents) {
4215
+ const target = event.to ? ` \u2192 ${event.to}` : "";
4216
+ const text = event.text ? ` \xB7 ${safeText(event.text)}` : "";
4217
+ lines.push(
4218
+ this.row(
4219
+ width,
4220
+ this.theme.fg(
4221
+ "dim",
4222
+ `[${formatClock(event.createdAt)}] ${event.topic} \xB7 ${event.from.name}${target}${text}`
4223
+ )
4224
+ )
4225
+ );
4226
+ renderedEventRows++;
4227
+ }
4228
+ while (renderedEventRows < eventRows) {
4229
+ lines.push(this.row(width, ""));
4230
+ renderedEventRows++;
4231
+ }
4232
+ }
4233
+ lines.push(this.middleBorder(width));
4234
+ const navigationHint = this.overviewView === "topology" ? this.graph.replayIndex !== void 0 ? `replay ${this.graph.replayIndex + 1}/${Math.max(1, this.graph.replayLength)}${this.graph.replayLabel ? ` \xB7 ${safeText(this.graph.replayLabel)}` : ""} \xB7 r live \xB7 space ${this.graph.replayPlaying ? "pause" : "play"} \xB7 \u2190/\u2192 step \xB7 +/- speed:${this.graph.replaySpeed}\xD7 \xB7 H history \xB7 M motion:${this.graph.reducedMotion ? "reduced" : "full"} \xB7 ? help` : `arrows/h/l move \xB7 j/k order \xB7 r replay \xB7 H history \xB7 M motion:${this.graph.reducedMotion ? "reduced" : "full"} \xB7 f filter:${this.filter} \xB7 1 activity \xB7 ? help` : `\u2191\u2193/jk select \xB7 \u2190\u2192/tab pane \xB7 enter inspect \xB7 f filter:${this.filter} \xB7 2 topology \xB7 [ older \xB7 ] newer \xB7 ? help`;
4235
+ lines.push(this.row(width, this.theme.fg("dim", navigationHint)));
4236
+ const selectedEntity = entities[this.entityIndex];
4237
+ const actionHint = this.pane === "entities" && selectedEntity ? this.theme.fg("muted", ` ${this.overviewActionHint(selectedEntity)}`) : "";
4238
+ lines.push(this.row(width, actionHint));
4239
+ lines.push(this.bottomBorder(width));
4240
+ return lines.map((line) => truncateToWidth4(line, width, ""));
4241
+ }
4242
+ overviewActionHint(entity) {
4243
+ if (entity.kind === "main") {
4244
+ const actions = [
4245
+ this.canMessage(entity, "steer") ? "s message/steer" : void 0,
4246
+ this.canMessage(entity, "followUp") ? "u queue follow-up" : void 0,
4247
+ "enter details"
4248
+ ].filter((value) => Boolean(value));
4249
+ return `Main actions: ${actions.join(" \xB7 ")}`;
4250
+ }
4251
+ if (entity.kind === "peer") {
4252
+ const actions = [
4253
+ this.canMessage(entity, "steer") ? "s steer" : void 0,
4254
+ this.canMessage(entity, "followUp") ? "u follow-up" : void 0,
4255
+ "enter details"
4256
+ ].filter((value) => Boolean(value));
4257
+ return `peer actions: ${actions.join(" \xB7 ")}`;
4258
+ }
4259
+ if (entity.kind === "actor" && entity.status !== "stopped") {
4260
+ const owned = entity.value.local !== false;
4261
+ const actions = [
4262
+ this.actorTranscript ? `space ${isActiveStatus(entity.status) ? "live " : ""}transcript peek` : void 0,
4263
+ this.canMessage(entity, "steer") ? "s queue message" : void 0,
4264
+ this.modelSourceForActor(entity.value) && this.onActorModel ? `m session model${owned ? " \xB7 M pin model" : ""}` : void 0,
4265
+ this.onActorThinking ? `e session thinking${owned ? " \xB7 E pin thinking" : ""}` : void 0,
4266
+ owned && this.onActorDeliveryPolicy ? "y delivery policy" : void 0,
4267
+ owned && this.onActorEvents ? "v events" : void 0,
4268
+ owned && this.onActorTools ? "o tools" : void 0,
4269
+ owned && this.onActorInstructions ? "i instructions" : void 0,
4270
+ owned && this.onClearMessages ? "c clear mailbox" : void 0,
4271
+ this.onExportActor ? "x export" : void 0,
4272
+ "enter details"
4273
+ ].filter((value) => Boolean(value));
4274
+ return `actor actions: ${actions.join(" \xB7 ")}`;
4275
+ }
4276
+ if (entity.kind === "globalActor") {
4277
+ const actions = [
4278
+ this.onGlobalDeliveryPolicy ? "y delivery policy" : void 0,
4279
+ this.onGlobalInstructions ? "i instructions" : void 0,
4280
+ this.onImportActor ? "p import" : void 0,
4281
+ this.onRemoveGlobalActor ? "d delete" : void 0,
4282
+ "enter details"
4283
+ ].filter((value) => Boolean(value));
4284
+ return `template actions: ${actions.join(" \xB7 ")}`;
4285
+ }
4286
+ if (entity.kind === "agent") {
4287
+ const armed = this.pendingStop?.id === entity.value.id && this.pendingStop.expiresAt > Date.now();
4288
+ const actions = [
4289
+ this.agentTranscript ? `space ${isActiveStatus(entity.status) ? "live " : ""}transcript peek` : void 0,
4290
+ this.canMessage(entity, "steer") ? "s steer" : void 0,
4291
+ this.canMessage(entity, "followUp") ? "u follow-up" : void 0,
4292
+ this.canStop(entity) ? armed ? "x again to stop" : "x stop" : void 0,
4293
+ "enter details"
4294
+ ].filter((value) => Boolean(value));
4295
+ return `agent actions: ${actions.join(" \xB7 ")}`;
4296
+ }
4297
+ if (entity.kind === "meshParticipant") {
4298
+ const actions = [
4299
+ this.canMessage(entity, "steer") ? "s steer" : void 0,
4300
+ this.canMessage(entity, "followUp") ? "u follow-up" : void 0,
4301
+ this.canStop(entity) ? "x twice to stop" : void 0,
4302
+ "enter details"
4303
+ ].filter((value) => Boolean(value));
4304
+ return `participant actions: ${actions.join(" \xB7 ")}`;
4305
+ }
4306
+ return "enter details";
4307
+ }
4308
+ renderPhasePanel(panels, width, height) {
4309
+ const lines = [
4310
+ truncateToWidth4(
4311
+ `${this.pane === "phases" ? this.theme.fg("accent", "\u25B8 ") : " "}${this.theme.fg(
4312
+ "accent",
4313
+ "Activity"
4314
+ )}`,
4315
+ width
4316
+ )
4317
+ ];
4318
+ const available = Math.max(0, height - 1);
4319
+ const start = Math.max(
4320
+ 0,
4321
+ Math.min(this.phaseIndex - Math.floor(available / 2), Math.max(0, panels.length - available))
4322
+ );
4323
+ for (let index = start; index < Math.min(panels.length, start + available); index++) {
4324
+ const panel = panels[index];
4325
+ if (!panel) continue;
4326
+ const selected = index === this.phaseIndex;
4327
+ const prefix = selected ? "\u203A " : " ";
4328
+ const count = panel.total > 0 ? `${panel.completed}/${panel.total}` : "";
4329
+ const raw = `${prefix}${colorStatus(this.theme, panel.status, statusGlyph(panel.status))} ${this.theme.fg("muted", safeText(
4330
+ panel.name
4331
+ ))}`;
4332
+ const countWidth = visibleWidth4(count);
4333
+ const contentWidth = Math.max(0, width - countWidth - (count ? 1 : 0));
4334
+ let line = `${padToWidth(raw, contentWidth)}${count ? ` ${this.theme.fg("dim", count)}` : ""}`;
4335
+ if (selected && this.pane === "phases") {
4336
+ line = this.theme.bg("selectedBg", padToWidth(line, width));
4337
+ }
4338
+ lines.push(truncateToWidth4(line, width, ""));
4339
+ }
4340
+ while (lines.length < height) lines.push("");
4341
+ return lines.slice(0, height);
4342
+ }
4343
+ renderEntityPanel(entities, width, height, now) {
4344
+ const lines = [];
4345
+ const available = Math.max(0, height);
4346
+ const groupedRows = [];
4347
+ const groups = groupEntities(entities);
4348
+ for (let groupIndex = 0; groupIndex < groups.length; groupIndex++) {
4349
+ const group = groups[groupIndex];
4350
+ if (groupIndex > 0) groupedRows.push({ type: "spacer" });
4351
+ groupedRows.push({ type: "group", group });
4352
+ for (const entry of group.entries) {
4353
+ groupedRows.push({ type: "entity", entity: entry.entity, entityIndex: entry.index });
4354
+ }
4355
+ }
4356
+ const selectedRow = Math.max(
4357
+ 0,
4358
+ groupedRows.findIndex(
4359
+ (row) => row.type === "entity" && row.entityIndex === this.entityIndex
4360
+ )
4361
+ );
4362
+ const start = Math.max(
4363
+ 0,
4364
+ Math.min(
4365
+ selectedRow - Math.floor(available / 2),
4366
+ Math.max(0, groupedRows.length - available)
4367
+ )
4368
+ );
4369
+ for (let index = start; index < Math.min(groupedRows.length, start + available); index++) {
4370
+ const row = groupedRows[index];
4371
+ if (!row) continue;
4372
+ if (row.type === "spacer") {
4373
+ lines.push("");
4374
+ continue;
4375
+ }
4376
+ if (row.type === "group") {
4377
+ lines.push(
4378
+ truncateToWidth4(
4379
+ this.theme.fg(
4380
+ "muted",
4381
+ ` ${this.theme.bold(row.group.label)} (${row.group.entries.length})`
4382
+ ),
4383
+ width,
4384
+ ""
4385
+ )
4386
+ );
4387
+ continue;
4388
+ }
4389
+ const entity = row.entity;
4390
+ const selected = row.entityIndex === this.entityIndex;
4391
+ const prefix = selected ? "\u203A " : " ";
4392
+ const lead = `${prefix}${colorStatus(this.theme, entity.status, statusGlyph(entity.status))} ${this.theme.fg("muted", safeText(
4393
+ entity.label
4394
+ ))}`;
4395
+ const tail = safeText(entityTail(entity, now));
4396
+ let line = tail ? `${lead} ${this.theme.fg("dim", tail)}` : lead;
4397
+ if (selected && this.pane === "entities") {
4398
+ line = this.theme.bg("selectedBg", padToWidth(line, width));
4399
+ }
4400
+ lines.push(truncateToWidth4(line, width, ""));
4401
+ }
4402
+ if (entities.length === 0 && available > 0) {
4403
+ const label = this.filter === "all" ? "activity" : `${this.filter} activity`;
4404
+ lines.push(this.theme.fg("dim", ` (no ${label}; press f to change filter)`));
4405
+ }
4406
+ while (lines.length < height) lines.push("");
4407
+ return lines.slice(0, height);
4408
+ }
4409
+ renderDetail(width, snapshot, entity) {
4410
+ const result = this.detailRenderer.render(
4411
+ width,
4412
+ snapshot,
4413
+ entity,
4414
+ {
4415
+ view: this.detailView,
4416
+ scroll: this.detailScroll,
4417
+ pageAnchor: this.transcriptPageAnchor,
4418
+ transcriptFollowing: this.transcriptFollowing,
4419
+ transcriptToolsExpanded: this.transcriptToolsExpanded
4420
+ },
4421
+ this.detailActionHint(entity),
4422
+ (entity.kind === "agent" || entity.kind === "actor") && this.detailView === "transcript" ? this.transcriptToolToggleHint() : ""
4423
+ );
4424
+ this.detailScroll = result.scroll;
4425
+ this.detailMaxScroll = result.maxScroll;
4426
+ this.transcriptPageAnchor = result.pageAnchor;
4427
+ return result.lines;
4428
+ }
4429
+ detailActionHint(entity) {
4430
+ if (entity.kind === "main") {
4431
+ const actions = [
4432
+ this.canMessage(entity, "steer") ? "s message/steer now" : void 0,
4433
+ this.canMessage(entity, "followUp") ? "u queue follow-up" : void 0
4434
+ ].filter((value) => Boolean(value));
4435
+ return actions.length > 0 ? `Main Pi agent actions: ${actions.join(" \xB7 ")}` : "Main Pi agent controls are unavailable in this session.";
4436
+ }
4437
+ if (entity.kind === "peer") {
4438
+ const actions = [
4439
+ this.canMessage(entity, "steer") ? "s steer over mesh" : void 0,
4440
+ this.canMessage(entity, "followUp") ? "u queue follow-up over mesh" : void 0
4441
+ ].filter((value) => Boolean(value));
4442
+ return actions.length > 0 ? `Peer session actions: ${actions.join(" \xB7 ")}` : "Peer session is read-only.";
4443
+ }
4444
+ if (entity.kind === "agent") {
4445
+ const armed = this.pendingStop?.id === entity.value.id && this.pendingStop.expiresAt > Date.now();
4446
+ const actions = [
4447
+ this.canMessage(entity, "steer") ? "s steer now" : void 0,
4448
+ this.canMessage(entity, "followUp") ? "u queue follow-up" : void 0,
4449
+ this.canStop(entity) ? armed ? "x again to confirm stop" : "x stop" : void 0
4450
+ ].filter((value) => Boolean(value));
4451
+ const controls = actions.length > 0 ? `One-shot agent actions: ${actions.join(" \xB7 ")}. ` : "One-shot agent. ";
4452
+ return `${controls}Model and thinking are fixed at spawn; use a persistent actor for editable runtime settings.`;
4453
+ }
4454
+ if (entity.kind === "actor" && entity.status !== "stopped") {
4455
+ const owned = entity.value.local !== false;
4456
+ const actions = [
4457
+ this.canMessage(entity, "steer") ? "s queue message" : void 0,
4458
+ this.modelSourceForActor(entity.value) && this.onActorModel ? `m session model${owned ? " \xB7 M pin model" : ""}` : void 0,
4459
+ this.onActorThinking ? `e session thinking${owned ? " \xB7 E pin thinking" : ""}` : void 0,
4460
+ owned && this.onActorDeliveryPolicy ? "y delivery policy" : void 0,
4461
+ owned && this.onActorEvents ? "v events" : void 0,
4462
+ owned && this.onActorTools ? "o tools" : void 0,
4463
+ owned && this.onClearMessages ? "c clear mailbox" : void 0,
4464
+ owned && this.onActorInstructions ? "i instructions" : void 0,
4465
+ this.onExportActor ? "x export\u2192global" : void 0
4466
+ ].filter((value) => Boolean(value));
4467
+ return actions.length > 0 ? `Actor actions: ${actions.join(" \xB7 ")}` : "Actor settings are read-only in this session.";
4468
+ }
4469
+ if (entity.kind === "meshParticipant") {
4470
+ const actions = [
4471
+ this.canMessage(entity, "steer") ? "s steer over mesh" : void 0,
4472
+ this.canMessage(entity, "followUp") ? "u queue follow-up over mesh" : void 0,
4473
+ this.canStop(entity) ? "x twice to stop" : void 0
4474
+ ].filter((value) => Boolean(value));
4475
+ return actions.length > 0 ? `Remote participant actions: ${actions.join(" \xB7 ")}` : "Remote participant is read-only.";
4476
+ }
4477
+ if (entity.kind === "globalActor") {
4478
+ const actions = [
4479
+ this.onGlobalDeliveryPolicy ? "y delivery policy" : void 0,
4480
+ this.onGlobalInstructions ? "i instructions" : void 0,
4481
+ this.onImportActor ? "p import" : void 0,
4482
+ this.onRemoveGlobalActor ? "d delete" : void 0
4483
+ ].filter((value) => Boolean(value));
4484
+ return actions.length > 0 ? `Template actions: ${actions.join(" \xB7 ")}` : "Global template is read-only in this session.";
4485
+ }
4486
+ return "Read-only detail.";
4487
+ }
4488
+ syncEntitySelection(entities, preferAttention = false) {
4489
+ if (entities.length === 0) {
4490
+ this.entityIndex = 0;
4491
+ this.selectedEntityId = void 0;
4492
+ return;
4493
+ }
4494
+ const retainedIndex = this.selectedEntityId ? entities.findIndex((entity) => entity.id === this.selectedEntityId) : -1;
4495
+ const failedIndex = preferAttention ? entities.findIndex(
4496
+ (entity) => entity.kind !== "main" && ["failed", "timed_out", "error"].includes(entity.status)
4497
+ ) : -1;
4498
+ const blockedIndex = preferAttention ? entities.findIndex(
4499
+ (entity) => entity.kind !== "main" && entity.status === "blocked"
4500
+ ) : -1;
4501
+ const activeIndex = preferAttention ? entities.findIndex(
4502
+ (entity) => entity.kind !== "main" && isActiveStatus(entity.status)
4503
+ ) : -1;
4504
+ const attentionIndex = failedIndex >= 0 ? failedIndex : blockedIndex >= 0 ? blockedIndex : activeIndex;
4505
+ const firstWorkIndex = entities.findIndex((entity) => entity.kind !== "main");
4506
+ this.entityIndex = retainedIndex >= 0 ? retainedIndex : attentionIndex >= 0 ? attentionIndex : firstWorkIndex >= 0 ? firstWorkIndex : Math.max(0, Math.min(this.entityIndex, entities.length - 1));
4507
+ this.selectedEntityId = entities[this.entityIndex]?.id;
4508
+ }
4509
+ selectRun(snapshot) {
4510
+ if (snapshot.runs.length === 0) {
4511
+ this.runIndex = 0;
4512
+ this.selectedRunId = void 0;
4513
+ return void 0;
4514
+ }
4515
+ if (!this.runSelectionTouched) {
4516
+ this.runIndex = 0;
4517
+ this.selectedRunId = snapshot.runs[0]?.id;
4518
+ return snapshot.runs[0];
4519
+ }
4520
+ const retainedIndex = this.selectedRunId ? snapshot.runs.findIndex((run) => run.id === this.selectedRunId) : -1;
4521
+ this.runIndex = retainedIndex >= 0 ? retainedIndex : Math.max(0, Math.min(this.runIndex, snapshot.runs.length - 1));
4522
+ this.selectedRunId = snapshot.runs[this.runIndex]?.id;
4523
+ return snapshot.runs[this.runIndex];
4524
+ }
4525
+ syncPhase(run, panels) {
4526
+ if (panels.length === 0) {
4527
+ this.phaseIndex = 0;
4528
+ this.selectedPhaseId = void 0;
4529
+ return;
4530
+ }
4531
+ if (!this.phaseSelectionTouched) {
4532
+ const current = run?.currentPhaseId ? panels.findIndex((panel) => panel.id === run.currentPhaseId) : -1;
4533
+ const activeRunActivity = panels.findIndex(
4534
+ (panel) => panel.kind === "unphased" && isActiveStatus(panel.status)
4535
+ );
4536
+ if (current >= 0 && isActiveStatus(panels[current].status)) {
4537
+ this.phaseIndex = current;
4538
+ } else if (activeRunActivity >= 0) {
4539
+ this.phaseIndex = activeRunActivity;
4540
+ } else if (current >= 0) {
4541
+ this.phaseIndex = current;
4542
+ } else {
4543
+ this.phaseIndex = 0;
4544
+ }
4545
+ } else {
4546
+ const retainedIndex = this.selectedPhaseId ? panels.findIndex((panel) => panel.id === this.selectedPhaseId) : -1;
4547
+ this.phaseIndex = retainedIndex >= 0 ? retainedIndex : Math.max(0, Math.min(this.phaseIndex, panels.length - 1));
4548
+ }
4549
+ this.phaseIndex = Math.max(0, Math.min(this.phaseIndex, panels.length - 1));
4550
+ this.selectedPhaseId = panels[this.phaseIndex]?.id;
4551
+ }
4552
+ resetSelection() {
4553
+ this.phaseIndex = 0;
4554
+ this.entityIndex = 0;
4555
+ this.selectedEntityId = void 0;
4556
+ this.phaseSelectionTouched = false;
4557
+ this.selectedPhaseId = void 0;
4558
+ this.detailId = void 0;
4559
+ this.detailScroll = 0;
4560
+ this.detailMaxScroll = 0;
4561
+ this.transcriptPageAnchor = void 0;
4562
+ this.detailSelectionRestore = void 0;
4563
+ this.detailView = "summary";
4564
+ this.transcriptFollowing = true;
4565
+ this.pane = this.overviewView === "activity" ? "phases" : "entities";
4566
+ }
4567
+ pinDetailSelection(run, panel, pinPhase) {
4568
+ this.detailSelectionRestore ??= {
4569
+ runSelectionTouched: this.runSelectionTouched,
4570
+ phaseSelectionTouched: this.phaseSelectionTouched
4571
+ };
4572
+ this.runSelectionTouched = true;
4573
+ this.selectedRunId = run?.id;
4574
+ if (pinPhase) {
4575
+ this.phaseSelectionTouched = true;
4576
+ this.selectedPhaseId = panel?.id;
4577
+ }
4578
+ }
4579
+ closeDetail() {
4580
+ const restore = this.detailSelectionRestore;
4581
+ if (restore) {
4582
+ this.runSelectionTouched = restore.runSelectionTouched;
4583
+ this.phaseSelectionTouched = restore.phaseSelectionTouched;
4584
+ }
4585
+ this.detailSelectionRestore = void 0;
4586
+ this.detailId = void 0;
4587
+ this.detailScroll = 0;
4588
+ this.detailMaxScroll = 0;
4589
+ this.transcriptPageAnchor = void 0;
4590
+ this.detailView = "summary";
4591
+ this.transcriptFollowing = true;
4592
+ }
4593
+ renderNarrowFallback(width, label, hint) {
4594
+ return [safeText(label), hint].map((line) => truncateToWidth4(line, width, "")).filter((line) => visibleWidth4(line) > 0);
4595
+ }
4596
+ topBorder(width, title) {
4597
+ const border = (value) => this.theme.fg("borderMuted", value);
4598
+ const safeTitle = truncateToWidth4(safeText(title), Math.max(0, width - 6));
4599
+ const styledTitle = ` ${this.theme.fg("accent", safeTitle)} `;
4600
+ const remaining = Math.max(0, width - 2 - visibleWidth4(styledTitle));
4601
+ const left = Math.floor(remaining / 2);
4602
+ const right = remaining - left;
4603
+ return `${border(`\u256D${"\u2500".repeat(left)}`)}${styledTitle}${border(`${"\u2500".repeat(right)}\u256E`)}`;
4604
+ }
4605
+ middleBorder(width) {
4606
+ return this.theme.fg("borderMuted", `\u251C${"\u2500".repeat(Math.max(0, width - 2))}\u2524`);
4607
+ }
4608
+ bottomBorder(width) {
4609
+ return this.theme.fg("borderMuted", `\u2570${"\u2500".repeat(Math.max(0, width - 2))}\u256F`);
4610
+ }
4611
+ row(width, content) {
4612
+ const innerWidth = Math.max(0, width - 2);
4613
+ return `${this.theme.fg("borderMuted", "\u2502")}${padToWidth(content, innerWidth)}${this.theme.fg(
4614
+ "borderMuted",
4615
+ "\u2502"
4616
+ )}`;
4617
+ }
4618
+ };
4619
+ export {
4620
+ FabricDashboard
4621
+ };
4622
+ //# sourceMappingURL=dashboard.js.map