@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,2861 @@
1
+ import {
2
+ defaultConversationTarget
3
+ } from "../chunks/chunk-W3FRE4VI.js";
4
+ import {
5
+ conversationFooter
6
+ } from "../chunks/chunk-UTR3I23Z.js";
7
+ import {
8
+ getConversationHost
9
+ } from "../chunks/chunk-5SU3YXBS.js";
10
+ import {
11
+ highlightCode
12
+ } from "../chunks/chunk-ZZ4LHQYJ.js";
13
+ import {
14
+ isActiveStatus
15
+ } from "../chunks/chunk-AAHHYDTO.js";
16
+ import {
17
+ safeText
18
+ } from "../chunks/chunk-ARLYAW2A.js";
19
+ import {
20
+ terminalSafe,
21
+ unwrapActorEnvelopeText
22
+ } from "../chunks/chunk-DLXPTBPL.js";
23
+ import "../chunks/chunk-OKOHRXGF.js";
24
+
25
+ // src/ui/conversation.ts
26
+ import {
27
+ CURSOR_MARKER,
28
+ fuzzyFilter,
29
+ getKeybindings as getKeybindings2,
30
+ Input,
31
+ Key as Key2,
32
+ Text,
33
+ matchesKey as matchesKey2,
34
+ truncateToWidth as truncateToWidth3,
35
+ visibleWidth as visibleWidth3
36
+ } from "@earendil-works/pi-tui";
37
+
38
+ // src/ui/border-status-editor.ts
39
+ import {
40
+ Editor,
41
+ Loader,
42
+ truncateToWidth,
43
+ visibleWidth
44
+ } from "@earendil-works/pi-tui";
45
+ var BorderWorkingIndicator = class extends Loader {
46
+ constructor(ui, colorFn, message = "Working", indicator) {
47
+ super(ui, colorFn, colorFn, message, indicator);
48
+ }
49
+ renderInBorder(width) {
50
+ const line = this.render(width + 2)[1] ?? "";
51
+ return truncateToWidth(line.startsWith(" ") ? line.slice(1).trimEnd() : line.trimEnd(), width, "");
52
+ }
53
+ renderSpinnerInBorder(width) {
54
+ return truncateToWidth(this.getRenderedIndicator(), width, "");
55
+ }
56
+ };
57
+ var BorderStatusEditor = class extends Editor {
58
+ workingStatusIndicator;
59
+ setWorkingStatusIndicator(indicator) {
60
+ this.workingStatusIndicator = indicator;
61
+ }
62
+ renderTopBorder(width, hiddenLineCount) {
63
+ const indicator = this.workingStatusIndicator;
64
+ if (!indicator || width <= 0) return super.renderTopBorder(width, hiddenLineCount);
65
+ let status = indicator.renderInBorder(Math.max(1, width - 5));
66
+ let statusWidth = visibleWidth(status);
67
+ if (statusWidth === 0) return super.renderTopBorder(width, hiddenLineCount);
68
+ const overflowLabel = hiddenLineCount > 0 ? ` \u2191 ${hiddenLineCount} more ` : void 0;
69
+ const overflowLabelWidth = overflowLabel ? visibleWidth(overflowLabel) : 0;
70
+ const overflowStart = Math.floor((width - overflowLabelWidth) / 2);
71
+ const canFitOverflow = () => overflowLabel !== void 0 && overflowLabelWidth + 2 <= width && overflowStart - (3 + statusWidth + 1) >= 1;
72
+ if (overflowLabel && !canFitOverflow()) {
73
+ status = indicator.renderSpinnerInBorder(width);
74
+ statusWidth = visibleWidth(status);
75
+ }
76
+ if (canFitOverflow()) {
77
+ const leftBlockWidth = 3 + statusWidth + 1;
78
+ return this.borderColor("\u2500\u2500 ") + status + this.borderColor(
79
+ ` ${"\u2500".repeat(overflowStart - leftBlockWidth)}${overflowLabel}${"\u2500".repeat(width - overflowStart - overflowLabelWidth)}`
80
+ );
81
+ }
82
+ if (width >= statusWidth + 5) {
83
+ return this.borderColor("\u2500\u2500 ") + status + this.borderColor(` ${"\u2500".repeat(width - statusWidth - 4)}`);
84
+ }
85
+ status = indicator.renderSpinnerInBorder(width);
86
+ statusWidth = visibleWidth(status);
87
+ const prefixWidth = Math.min(3, Math.max(0, width - statusWidth));
88
+ return this.borderColor("\u2500".repeat(prefixWidth)) + status + this.borderColor("\u2500".repeat(Math.max(0, width - prefixWidth - statusWidth)));
89
+ }
90
+ };
91
+
92
+ // src/ui/conversation-render.ts
93
+ import { wrapTextWithAnsi } from "@earendil-works/pi-tui";
94
+ var DEFAULT_IMAGE_WIDTH_CELLS = 60;
95
+ var stableKey = (value) => {
96
+ if (value === void 0) return "undefined";
97
+ try {
98
+ return JSON.stringify(value) ?? "undefined";
99
+ } catch {
100
+ return `unserializable:${String(value)}`;
101
+ }
102
+ };
103
+ var FabricConversationTranscriptRenderer = class {
104
+ constructor(tui, theme, rendererOptions = {}) {
105
+ this.tui = tui;
106
+ this.theme = theme;
107
+ this.rendererOptions = rendererOptions;
108
+ this.highlightInvalidate = () => {
109
+ if (this.disposed) return;
110
+ this.invalidate();
111
+ this.tui.requestRender();
112
+ };
113
+ }
114
+ toolComponents = /* @__PURE__ */ new Map();
115
+ messageComponents = /* @__PURE__ */ new Map();
116
+ assistantComponents = /* @__PURE__ */ new Map();
117
+ markdownThemeCache = /* @__PURE__ */ new Map();
118
+ highlightInvalidate;
119
+ disposed = false;
120
+ currentTargetId = "";
121
+ rendererStates = /* @__PURE__ */ new Map();
122
+ liveStates = /* @__PURE__ */ new WeakSet();
123
+ messageRows = /* @__PURE__ */ new Map();
124
+ toolRows = /* @__PURE__ */ new Map();
125
+ toolTokens = /* @__PURE__ */ new Map();
126
+ messageIds = /* @__PURE__ */ new WeakMap();
127
+ nextMessageId = 0;
128
+ rows = [];
129
+ lastMessages = [];
130
+ lastTools = [];
131
+ lastPartial;
132
+ lastVersion;
133
+ sourceKey = "";
134
+ optionsKey = "";
135
+ lastRendererHooks = [];
136
+ lastWidth = 0;
137
+ frameLines;
138
+ frameFlags = "";
139
+ planDirty = true;
140
+ /** Drop cached components; stray renderer timers/invalidations become no-ops. */
141
+ invalidate() {
142
+ this.toolTokens.clear();
143
+ for (const key of this.rendererStates.keys()) this.releaseRendererStates(key);
144
+ this.toolComponents.clear();
145
+ this.messageComponents.clear();
146
+ this.assistantComponents.clear();
147
+ this.markdownThemeCache.clear();
148
+ this.messageRows.clear();
149
+ this.toolRows.clear();
150
+ this.rows = [];
151
+ this.lastMessages = [];
152
+ this.lastTools = [];
153
+ this.lastPartial = void 0;
154
+ this.frameLines = void 0;
155
+ this.planDirty = true;
156
+ }
157
+ /** Finalize: live spinner/timing intervals may still fire once; guarded. */
158
+ dispose() {
159
+ this.disposed = true;
160
+ this.invalidate();
161
+ }
162
+ render(transcript, width, options) {
163
+ if (this.disposed || width <= 0) return [];
164
+ width = Math.max(1, width);
165
+ const sourceKey = stableKey([
166
+ options.target.id,
167
+ options.target.cwd ?? process.cwd(),
168
+ transcript.sourceId,
169
+ transcript.sessionId,
170
+ transcript.sessionFile,
171
+ transcript.eventsFile
172
+ ]);
173
+ const optionsKey = stableKey([
174
+ options.toolsExpanded,
175
+ options.outputPad,
176
+ options.codeBlockIndent,
177
+ options.hideThinking,
178
+ options.showImages,
179
+ options.codePreviewSettings,
180
+ this.rendererOptions.hiddenThinkingLabel,
181
+ this.rendererOptions.imageWidthCells
182
+ ]);
183
+ const hooks = [
184
+ this.rendererOptions.getToolDefinition,
185
+ this.rendererOptions.getMessageRenderer,
186
+ ...this.rendererOptions.markdownTransformers ?? []
187
+ ];
188
+ if (sourceKey !== this.sourceKey || optionsKey !== this.optionsKey || !sameItems(hooks, this.lastRendererHooks)) {
189
+ this.invalidate();
190
+ this.sourceKey = sourceKey;
191
+ this.optionsKey = optionsKey;
192
+ this.lastRendererHooks = hooks;
193
+ }
194
+ this.currentTargetId = options.target.id;
195
+ const version = transcript.contentVersion ?? transcript.revision;
196
+ const streaming = transcript.streaming;
197
+ if (this.planDirty || version !== this.lastVersion || !sameItems(transcript.messages, this.lastMessages) || !sameItems(streaming.tools, this.lastTools) || streaming.partialAssistant !== this.lastPartial) {
198
+ this.reconcileRows(transcript, options);
199
+ this.lastVersion = version;
200
+ }
201
+ if (width !== this.lastWidth) {
202
+ this.lastWidth = width;
203
+ for (const row of this.rows) row.lines = void 0;
204
+ this.frameLines = void 0;
205
+ }
206
+ for (const row of this.rows) {
207
+ if (row.lines && !row.dynamic) continue;
208
+ row.lines = row.render(width);
209
+ this.frameLines = void 0;
210
+ }
211
+ const flags = `${transcript.hasMore}:${transcript.hasNewer}`;
212
+ if (!this.frameLines || flags !== this.frameFlags) {
213
+ const lines = [];
214
+ if (!transcript.messages.length && !streaming.partialAssistant && !streaming.tools.length) {
215
+ lines.push(this.theme.fg("dim", "No retained transcript yet; new agent activity will appear here."));
216
+ } else {
217
+ if (transcript.hasMore) {
218
+ lines.push(this.theme.fg("dim", "\u2191 older activity available \xB7 ctrl+\u2191 past the top to load"));
219
+ }
220
+ for (const row of this.rows) {
221
+ if (!row.lines?.length) continue;
222
+ if (row.spacer && lines.length) lines.push("");
223
+ for (const line of row.lines) lines.push(line);
224
+ }
225
+ if (transcript.hasNewer) {
226
+ lines.push(this.theme.fg("dim", "\u2193 newer activity available \xB7 ctrl+\u2193 past the bottom to load"));
227
+ }
228
+ }
229
+ this.frameLines = lines;
230
+ this.frameFlags = flags;
231
+ }
232
+ return this.frameLines.slice();
233
+ }
234
+ reconcileRows(transcript, options) {
235
+ const rows = [];
236
+ const messages = /* @__PURE__ */ new Set();
237
+ const keys = /* @__PURE__ */ new Set();
238
+ const tools = /* @__PURE__ */ new Set();
239
+ const results = /* @__PURE__ */ new Map();
240
+ const streaming = new Map(transcript.streaming.tools.map((tool) => [tool.toolCallId, tool]));
241
+ for (const message of transcript.messages) {
242
+ if (message.role === "toolResult") results.set(message.toolCallId, message);
243
+ }
244
+ const addTool = (id, name, args, error) => {
245
+ if (tools.has(id)) return;
246
+ tools.add(id);
247
+ rows.push(this.reconcileTool(id, name, args, results.get(id), streaming.get(id), error, options));
248
+ };
249
+ const addMessage = (message, partial = false) => {
250
+ if (message.role === "toolResult") return;
251
+ messages.add(message);
252
+ const key = partial ? ":streaming" : this.messageKey(message);
253
+ keys.add(key);
254
+ let row = this.messageRows.get(message);
255
+ const input = shallowInput(message);
256
+ if (!row || row.partial !== partial || !sameItems(row.input ?? [], input)) {
257
+ if (row) {
258
+ this.assistantComponents.delete(key);
259
+ this.messageComponents.delete(key);
260
+ }
261
+ row = {
262
+ input,
263
+ partial,
264
+ spacer: message.role !== "assistant",
265
+ // A custom component can read time or external state in render(width).
266
+ dynamic: message.role === "custom" && message.display,
267
+ render: (width) => {
268
+ const lines = [];
269
+ if (partial && message.role === "assistant") {
270
+ this.renderAssistantContent(message, key, true, width, options, lines);
271
+ } else {
272
+ this.renderMessage(message, width, options, lines);
273
+ }
274
+ return lines;
275
+ }
276
+ };
277
+ this.messageRows.set(message, row);
278
+ }
279
+ rows.push(row);
280
+ if (message.role === "assistant") {
281
+ const error = message.stopReason === "error" || message.stopReason === "aborted" ? message.errorMessage || "Error" : void 0;
282
+ for (const call of message.content) {
283
+ if (call.type === "toolCall") addTool(call.id, call.name, call.arguments, error);
284
+ }
285
+ }
286
+ };
287
+ for (const message of transcript.messages) addMessage(message);
288
+ if (transcript.streaming.partialAssistant) addMessage(transcript.streaming.partialAssistant, true);
289
+ for (const tool of transcript.streaming.tools) addTool(tool.toolCallId, tool.toolName, tool.args);
290
+ for (const message of this.messageRows.keys()) if (!messages.has(message)) this.messageRows.delete(message);
291
+ for (const cache of [this.messageComponents, this.assistantComponents]) {
292
+ for (const key of cache.keys()) if (!keys.has(key)) cache.delete(key);
293
+ }
294
+ for (const key of this.toolComponents.keys()) {
295
+ const id = key.slice(this.currentTargetId.length + 1);
296
+ if (!tools.has(id)) this.releaseTool(key);
297
+ }
298
+ this.rows = rows;
299
+ this.lastMessages = transcript.messages.slice();
300
+ this.lastTools = transcript.streaming.tools.slice();
301
+ this.lastPartial = transcript.streaming.partialAssistant;
302
+ this.planDirty = false;
303
+ this.frameLines = void 0;
304
+ }
305
+ messageKey(message) {
306
+ let id = this.messageIds.get(message);
307
+ if (id === void 0) {
308
+ id = ++this.nextMessageId;
309
+ this.messageIds.set(message, id);
310
+ }
311
+ return `${this.currentTargetId}\0${id}`;
312
+ }
313
+ markdownTheme(options) {
314
+ const key = options.codeBlockIndent ?? "";
315
+ let markdownTheme = this.markdownThemeCache.get(key);
316
+ if (!markdownTheme) {
317
+ markdownTheme = {
318
+ ...options.codeBlockIndent !== void 0 ? { codeBlockIndent: options.codeBlockIndent } : {},
319
+ heading: (text) => this.theme.fg("mdHeading", text),
320
+ link: (text) => this.theme.fg("mdLink", text),
321
+ linkUrl: (text) => this.theme.fg("mdLinkUrl", text),
322
+ code: (text) => this.theme.fg("mdCode", text),
323
+ codeBlock: (text) => this.theme.fg("mdCodeBlock", text),
324
+ codeBlockBorder: (text) => this.theme.fg("mdCodeBlockBorder", text),
325
+ quote: (text) => this.theme.fg("mdQuote", text),
326
+ quoteBorder: (text) => this.theme.fg("mdQuoteBorder", text),
327
+ hr: (text) => this.theme.fg("mdHr", text),
328
+ listBullet: (text) => this.theme.fg("mdListBullet", text),
329
+ bold: (text) => this.theme.bold(text),
330
+ italic: (text) => this.theme.italic(text),
331
+ underline: (text) => this.theme.underline(text),
332
+ strikethrough: (text) => this.theme.strikethrough(text),
333
+ highlightCode: (code, lang) => highlightCode(code, lang ?? "", this.highlightInvalidate) ?? code.split("\n").map((line) => this.theme.fg("mdCodeBlock", line))
334
+ };
335
+ this.markdownThemeCache.set(key, markdownTheme);
336
+ }
337
+ return markdownTheme;
338
+ }
339
+ renderMessage(message, width, options, lines) {
340
+ switch (message.role) {
341
+ case "user":
342
+ this.renderUserMessage(message, width, options, lines);
343
+ return;
344
+ case "assistant":
345
+ this.renderAssistantContent(message, this.messageKey(message), false, width, options, lines);
346
+ return;
347
+ case "toolResult":
348
+ return;
349
+ case "bashExecution":
350
+ this.pushSpacer(lines);
351
+ this.renderBashExecution(message, width, options, lines);
352
+ return;
353
+ case "custom":
354
+ if (!message.display) return;
355
+ this.pushSpacer(lines);
356
+ this.renderCustomMessage(message, width, options, lines);
357
+ return;
358
+ case "compactionSummary":
359
+ this.pushSpacer(lines);
360
+ this.renderBoxedMessage(this.messageKey(message), message, getConversationHost().CompactionSummaryMessageComponent, width, options, lines);
361
+ return;
362
+ case "branchSummary":
363
+ this.pushSpacer(lines);
364
+ this.renderBoxedMessage(this.messageKey(message), message, getConversationHost().BranchSummaryMessageComponent, width, options, lines);
365
+ return;
366
+ default:
367
+ return;
368
+ }
369
+ }
370
+ renderUserMessage(message, width, options, lines) {
371
+ const text = userMessageText(message);
372
+ if (!text) return;
373
+ this.pushSpacer(lines);
374
+ const skillBlock = getConversationHost().parseSkillBlock(text);
375
+ if (skillBlock) {
376
+ const record = this.messageRecord(this.messageKey(message), () => new (getConversationHost()).SkillInvocationMessageComponent(skillBlock, this.markdownTheme(options)));
377
+ record.component.setExpanded(options.toolsExpanded);
378
+ lines.push(...safeRender(record.component, width, () => this.plainTextFallback(text, width)));
379
+ if (skillBlock.userMessage) {
380
+ this.pushSpacer(lines);
381
+ lines.push(...this.userComponentLines(skillBlock.userMessage, width, options));
382
+ }
383
+ return;
384
+ }
385
+ lines.push(...this.userComponentLines(text, width, options));
386
+ }
387
+ userComponentLines(text, width, options) {
388
+ const component = new (getConversationHost()).UserMessageComponent(
389
+ terminalSafe(text, false),
390
+ this.markdownTheme(options),
391
+ options.outputPad ?? 1,
392
+ this.rendererOptions.markdownTransformers
393
+ );
394
+ return safeRender(component, width, () => this.plainTextFallback(text, width));
395
+ }
396
+ renderAssistantContent(message, key, streaming, width, options, lines) {
397
+ const record = this.assistantRecord(key, options);
398
+ if (record.message !== message || record.streaming !== streaming) {
399
+ record.component.updateContent(message, streaming);
400
+ record.message = message;
401
+ record.streaming = streaming;
402
+ }
403
+ lines.push(...safeRender(record.component, width, () => this.plainTextFallback(assistantText(message), width)));
404
+ }
405
+ reconcileTool(id, name, callArgs, result, tool, error, options) {
406
+ const key = `${this.currentTargetId}\0${id}`;
407
+ const args = tool?.args ?? callArgs;
408
+ const value = result ?? tool?.result ?? tool?.partial;
409
+ const isPartial = !result && !tool?.result && !error;
410
+ const isError = result?.isError ?? tool?.isError ?? !!error;
411
+ const started = tool ? tool.executionStarted ?? true : false;
412
+ const argsComplete = !!result || !!tool?.result || !!tool?.argsComplete;
413
+ let record = this.toolComponents.get(key);
414
+ const images = record?.result === value ? void 0 : value?.content?.filter(
415
+ (block) => !!block && typeof block === "object" && block.type === "image"
416
+ );
417
+ const imageKey = record && record.result === value ? record.imageKey : stableKey(images?.length ? images : void 0);
418
+ if (record && (record.name !== name || record.imageKey !== imageKey || !record.isPartial && isPartial || record.argsComplete && !argsComplete || record.started && !started && !result)) {
419
+ this.releaseTool(key);
420
+ record = void 0;
421
+ }
422
+ let row = this.toolRows.get(key);
423
+ if (!record) {
424
+ const token = {};
425
+ this.toolTokens.set(key, token);
426
+ const definition = this.definitionFor(name, key, token);
427
+ const ui = Object.create(this.tui, {
428
+ requestRender: {
429
+ configurable: true,
430
+ enumerable: true,
431
+ writable: true,
432
+ value: () => {
433
+ if (this.disposed || this.toolTokens.get(key) !== token) return;
434
+ const current = this.toolRows.get(key);
435
+ if (current) current.lines = void 0;
436
+ this.frameLines = void 0;
437
+ this.tui.requestRender();
438
+ }
439
+ }
440
+ });
441
+ const component2 = new (getConversationHost()).ToolExecutionComponent(
442
+ name,
443
+ id,
444
+ args,
445
+ { showImages: options.showImages ?? true, imageWidthCells: this.imageWidthCells() },
446
+ definition,
447
+ ui,
448
+ options.target.cwd ?? process.cwd()
449
+ );
450
+ if (options.toolsExpanded) component2.setExpanded(true);
451
+ record = {
452
+ component: component2,
453
+ name,
454
+ dynamicRenderer: !!definition?.renderCall || !!definition?.renderResult,
455
+ started: false,
456
+ argsComplete: false,
457
+ args,
458
+ argsKey: "0",
459
+ result: void 0,
460
+ resultKey: void 0,
461
+ partialKey: void 0,
462
+ imageKey,
463
+ isPartial: true,
464
+ isError: false,
465
+ error: void 0
466
+ };
467
+ this.toolComponents.set(key, record);
468
+ row = {
469
+ spacer: false,
470
+ dynamic: !!definition?.renderCall || !!definition?.renderResult || isPartial || imageKey !== "undefined",
471
+ render: (width) => safeRender(component2, width, () => this.plainTextFallback(name, width))
472
+ };
473
+ this.toolRows.set(key, row);
474
+ }
475
+ const { component } = record;
476
+ let changed = false;
477
+ if (record.args !== args) {
478
+ component.updateArgs(args);
479
+ changed = true;
480
+ record.args = args;
481
+ record.argsKey = String(Number(record.argsKey) + 1);
482
+ }
483
+ if (started && !record.started) {
484
+ record.started = true;
485
+ component.markExecutionStarted();
486
+ changed = true;
487
+ }
488
+ if (argsComplete && !record.argsComplete) {
489
+ record.argsComplete = true;
490
+ component.setArgsComplete();
491
+ changed = true;
492
+ }
493
+ if (record.result !== value || record.isPartial !== isPartial || record.isError !== isError || record.error !== error) {
494
+ const resultKey = String(Number(record.resultKey ?? 0) + 1);
495
+ if (value !== void 0 || error !== void 0) {
496
+ component.updateResult({
497
+ content: error && !value ? [{ type: "text", text: error }] : value?.content ?? [],
498
+ ...value?.details !== void 0 ? { details: value.details } : {},
499
+ isError
500
+ }, isPartial);
501
+ changed = true;
502
+ }
503
+ record.result = value;
504
+ record.resultKey = resultKey;
505
+ record.partialKey = isPartial ? resultKey : void 0;
506
+ record.isPartial = isPartial;
507
+ record.isError = isError;
508
+ record.error = error;
509
+ }
510
+ row.dynamic = record.dynamicRenderer || isPartial || imageKey !== "undefined";
511
+ if (changed) row.lines = void 0;
512
+ return row;
513
+ }
514
+ releaseTool(key) {
515
+ this.toolTokens.delete(key);
516
+ this.releaseRendererStates(key);
517
+ this.toolComponents.delete(key);
518
+ this.toolRows.delete(key);
519
+ }
520
+ renderBashExecution(message, width, options, lines) {
521
+ const key = this.messageKey(message);
522
+ const record = this.messageRecord(key, () => {
523
+ const component = new (getConversationHost()).BashExecutionComponent(message.command, this.tui, message.excludeFromContext);
524
+ component.appendOutput(terminalSafe(message.output ?? "", false));
525
+ const truncation = message.truncated ? { truncated: true } : void 0;
526
+ component.setComplete(message.exitCode, message.cancelled, truncation, message.fullOutputPath);
527
+ return component;
528
+ });
529
+ record.component.setExpanded(options.toolsExpanded);
530
+ lines.push(...safeRender(record.component, width, () => this.plainTextFallback(message.command, width)));
531
+ }
532
+ renderCustomMessage(message, width, options, lines) {
533
+ const record = this.messageRecord(this.messageKey(message), () => new (getConversationHost()).CustomMessageComponent(
534
+ message,
535
+ this.rendererOptions.getMessageRenderer?.(message.customType),
536
+ this.markdownTheme(options),
537
+ options.outputPad ?? 1
538
+ ));
539
+ record.component.setExpanded(options.toolsExpanded);
540
+ lines.push(...safeRender(record.component, width, () => this.plainTextFallback(customText(message), width)));
541
+ }
542
+ renderBoxedMessage(key, message, create, width, options, lines) {
543
+ const record = this.messageRecord(key, () => new create(message, this.markdownTheme(options)));
544
+ record.component.setExpanded(options.toolsExpanded);
545
+ lines.push(...safeRender(record.component, width, () => this.plainTextFallback(message.summary, width)));
546
+ }
547
+ /**
548
+ * Registered definition with wrapped renderer callbacks: the render context
549
+ * invalidate becomes a no-op once disposed, so a live spinner/timing timer
550
+ * firing after dispose cannot touch the TUI. ToolExecutionComponent has no
551
+ * dispose; this finalizes its renderer subscriptions instead.
552
+ */
553
+ definitionFor(toolName, key, token) {
554
+ const definition = this.rendererOptions.getToolDefinition?.(toolName);
555
+ if (!definition) return definition;
556
+ const live = () => !this.disposed && this.toolTokens.get(key) === token;
557
+ const guard = (context) => {
558
+ const states = this.rendererStates.get(key) ?? /* @__PURE__ */ new Set();
559
+ states.add(context.state);
560
+ this.rendererStates.set(key, states);
561
+ this.liveStates.add(context.state);
562
+ return {
563
+ ...context,
564
+ invalidate: () => {
565
+ if (!live() || !this.liveStates.has(context.state)) return;
566
+ context.invalidate();
567
+ }
568
+ };
569
+ };
570
+ const empty = { render: () => [], invalidate: () => {
571
+ } };
572
+ return {
573
+ ...definition,
574
+ ...definition.renderCall ? { renderCall: (args, theme, context) => live() ? definition.renderCall(args, theme, guard(context)) : empty } : {},
575
+ ...definition.renderResult ? { renderResult: (result, options, theme, context) => live() ? definition.renderResult(result, options, theme, guard(context)) : empty } : {}
576
+ };
577
+ }
578
+ assistantRecord(key, options) {
579
+ const cacheKey = key;
580
+ const hideThinking = options.hideThinking ?? false;
581
+ let record = this.assistantComponents.get(cacheKey);
582
+ if (!record || record.hideThinking !== hideThinking) {
583
+ record = {
584
+ hideThinking,
585
+ component: new (getConversationHost()).AssistantMessageComponent(
586
+ void 0,
587
+ hideThinking,
588
+ this.markdownTheme(options),
589
+ this.rendererOptions.hiddenThinkingLabel,
590
+ options.outputPad ?? 1,
591
+ this.rendererOptions.markdownTransformers
592
+ )
593
+ };
594
+ this.assistantComponents.set(cacheKey, record);
595
+ }
596
+ return record;
597
+ }
598
+ messageRecord(key, create) {
599
+ const cacheKey = key;
600
+ let record = this.messageComponents.get(cacheKey);
601
+ if (!record) {
602
+ record = { component: create() };
603
+ this.messageComponents.set(cacheKey, record);
604
+ }
605
+ return record;
606
+ }
607
+ releaseRendererStates(key) {
608
+ for (const state of this.rendererStates.get(key) ?? []) {
609
+ this.liveStates.delete(state);
610
+ if (state.codePreviewTimingInterval) {
611
+ clearInterval(state.codePreviewTimingInterval);
612
+ delete state.codePreviewTimingInterval;
613
+ }
614
+ const spinner = state.fabricSpinner;
615
+ if (spinner?.timer) {
616
+ clearTimeout(spinner.timer);
617
+ delete spinner.timer;
618
+ }
619
+ }
620
+ this.rendererStates.delete(key);
621
+ }
622
+ imageWidthCells() {
623
+ return Math.max(1, Math.floor(this.rendererOptions.imageWidthCells ?? DEFAULT_IMAGE_WIDTH_CELLS));
624
+ }
625
+ plainTextFallback(text, width) {
626
+ const safe = terminalSafe(text, false);
627
+ return safe.split("\n").flatMap(
628
+ (paragraph) => wrapTextWithAnsi(paragraph, Math.max(1, width)).map((line) => this.theme.fg("text", line))
629
+ );
630
+ }
631
+ pushSpacer(lines) {
632
+ if (lines.length > 0) lines.push("");
633
+ }
634
+ };
635
+ var shallowInput = (value) => [...Object.keys(value), ...Object.values(value)];
636
+ var sameItems = (a, b) => a.length === b.length && a.every((item, index) => item === b[index]);
637
+ var userMessageText = (message) => {
638
+ const blocks = typeof message.content === "string" ? [{ type: "text", text: message.content }] : message.content.filter((block) => block.type === "text");
639
+ const text = blocks.map((block) => block.text).join("");
640
+ return unwrapActorEnvelopeText(text) ?? text;
641
+ };
642
+ var assistantText = (message) => Array.isArray(message.content) ? message.content.filter((block) => typeof block === "object" && block !== null && block.type === "text").map((block) => block.text).join("\n") : "";
643
+ var customText = (message) => typeof message.content === "string" ? message.content : message.content.filter((block) => block.type === "text").map((block) => block.text).join("\n");
644
+ var safeRender = (component, width, fallback) => {
645
+ try {
646
+ return component.render(width);
647
+ } catch {
648
+ return fallback();
649
+ }
650
+ };
651
+
652
+ // src/ui/conversation-selection.ts
653
+ import { sliceByColumn, stripTerminalSequences, visibleWidth as visibleWidth2 } from "@earendil-works/pi-tui";
654
+ var graphemes = new Intl.Segmenter(void 0, { granularity: "grapheme" });
655
+ var ConversationTextSelection = class {
656
+ source;
657
+ anchor;
658
+ focus;
659
+ dragging = false;
660
+ clear() {
661
+ this.source = void 0;
662
+ this.anchor = this.focus = void 0;
663
+ this.dragging = false;
664
+ }
665
+ start(source, row, col) {
666
+ this.source = source;
667
+ this.anchor = this.point(row, col);
668
+ this.focus = this.anchor;
669
+ this.dragging = true;
670
+ }
671
+ move(row, col) {
672
+ if (this.dragging) this.focus = this.point(row, col);
673
+ }
674
+ finish(row, col) {
675
+ this.move(row, col);
676
+ this.dragging = false;
677
+ if (!this.bounds()) this.clear();
678
+ }
679
+ get active() {
680
+ return this.bounds() !== void 0;
681
+ }
682
+ point(row, col) {
683
+ row = Math.max(0, Math.min(this.source.length - 1, row));
684
+ let boundary = 0;
685
+ for (const { segment } of graphemes.segment(stripTerminalSequences(this.source[row] ?? ""))) {
686
+ const next = boundary + visibleWidth2(segment);
687
+ if (next > col) break;
688
+ boundary = next;
689
+ }
690
+ return { row, col: boundary };
691
+ }
692
+ bounds() {
693
+ const a = this.anchor;
694
+ const b = this.focus;
695
+ if (!a || !b || a.row === b.row && a.col === b.col) return void 0;
696
+ return a.row < b.row || a.row === b.row && a.col < b.col ? { start: a, end: b } : { start: b, end: a };
697
+ }
698
+ text() {
699
+ const bounds = this.bounds();
700
+ if (!bounds || !this.source) return void 0;
701
+ const lines = [];
702
+ for (let row = bounds.start.row; row <= bounds.end.row; row++) {
703
+ const line = this.source[row] ?? "";
704
+ const start = row === bounds.start.row ? bounds.start.col : 0;
705
+ const end = row === bounds.end.row ? bounds.end.col : visibleWidth2(line);
706
+ lines.push(stripTerminalSequences(sliceByColumn(line, start, end - start, true)).trimEnd());
707
+ }
708
+ return lines.join("\n") || void 0;
709
+ }
710
+ highlight(line, row, theme) {
711
+ const bounds = this.bounds();
712
+ if (!bounds || row < bounds.start.row || row > bounds.end.row) return line;
713
+ if (/\x1b(?:_G|\]1337;File=|P)/.test(line)) return line;
714
+ const width = visibleWidth2(line);
715
+ const start = row === bounds.start.row ? bounds.start.col : 0;
716
+ const end = row === bounds.end.row ? bounds.end.col : width;
717
+ if (end <= start) return line;
718
+ const selected = stripTerminalSequences(sliceByColumn(line, start, end - start, true));
719
+ return sliceByColumn(line, 0, start, true) + theme.bg("selectedBg", theme.fg("text", selected)) + sliceByColumn(line, end, Math.max(0, width - end), true);
720
+ }
721
+ };
722
+
723
+ // src/ui/conversation-history.ts
724
+ var PROMPT_HISTORY_LIMIT = 100;
725
+ function appendConversationPrompt(history, text) {
726
+ const prompt = text.trim();
727
+ if (!prompt || history.at(-1) === prompt) return;
728
+ history.push(prompt);
729
+ if (history.length > PROMPT_HISTORY_LIMIT) history.shift();
730
+ }
731
+ function conversationPromptHistory(transcript) {
732
+ const newest = [];
733
+ for (let index = transcript.messages.length - 1; index >= 0 && newest.length < PROMPT_HISTORY_LIMIT; index--) {
734
+ const message = transcript.messages[index];
735
+ if (message.role !== "user") continue;
736
+ const raw = typeof message.content === "string" ? message.content : message.content.filter((part) => part.type === "text").map((part) => part.text).join("");
737
+ const text = (unwrapActorEnvelopeText(raw) ?? raw).trim();
738
+ if (text && newest.at(-1) !== text) newest.push(text);
739
+ }
740
+ return newest.reverse();
741
+ }
742
+
743
+ // src/ui/conversation-commands.ts
744
+ var CONVERSATION_COMMANDS = [
745
+ { value: "/copy", label: "/copy", description: "Copy the last assistant response" },
746
+ { value: "/copy selection", label: "/copy selection", description: "Copy selected transcript text" },
747
+ { value: "/latest", label: "/latest", description: "Clear selection and follow latest output" },
748
+ { value: "/agents", label: "/agents", description: "Choose a conversation" },
749
+ { value: "/back", label: "/back", description: "Return to Main" },
750
+ { value: "/stop", label: "/stop", description: "Confirm stopping this participant" },
751
+ { value: "/help", label: "/help", description: "Show preview commands" }
752
+ ];
753
+ var CONVERSATION_COMMAND_HELP = "Commands: /copy [selection] \xB7 /latest \xB7 /agents \xB7 /back \xB7 /stop \xB7 /help";
754
+ function conversationCommandCompletion(enabled) {
755
+ return {
756
+ triggerCharacters: ["/"],
757
+ async getSuggestions(lines, row, col, options) {
758
+ if (!enabled() || options.signal.aborted || row !== 0 || lines.length !== 1) return null;
759
+ const prefix = lines[0].slice(0, col);
760
+ if (col !== lines[0].length || !/^\/[a-z]*(?: +[a-z]*)?$/.test(prefix)) return null;
761
+ const items = CONVERSATION_COMMANDS.filter((item) => item.value.startsWith(prefix));
762
+ return items.length ? { items, prefix } : null;
763
+ },
764
+ applyCompletion(lines, row, _col, item) {
765
+ const next = [...lines];
766
+ next[row] = `${item.value} `;
767
+ return { lines: next, cursorLine: row, cursorCol: next[row].length };
768
+ }
769
+ };
770
+ }
771
+ function conversationAssistantText(transcript) {
772
+ for (let index = transcript.messages.length - 1; index >= 0; index--) {
773
+ const message = transcript.messages[index];
774
+ if (message.role !== "assistant" || message.stopReason === "aborted" && message.content.length === 0) continue;
775
+ const text = message.content.filter((block) => block.type === "text").map((block) => block.text).join("").trim();
776
+ return text || void 0;
777
+ }
778
+ return void 0;
779
+ }
780
+
781
+ // src/ui/conversation-queue-store.ts
782
+ import { createHash } from "node:crypto";
783
+
784
+ // src/ui/conversation-queue.ts
785
+ import {
786
+ Key,
787
+ getKeybindings,
788
+ matchesKey,
789
+ truncateToWidth as truncateToWidth2
790
+ } from "@earendil-works/pi-tui";
791
+ var QUEUE_STEER_CONVERSATION_QUEUE_REQUEST_EVENT = "queue-steer:conversation-queue:request:v1";
792
+ var DEQUEUE_FALLBACK = "alt+up";
793
+ var REMOVE_ROW_KEY = "alt+x";
794
+ var PAUSE_ROW_KEY = "alt+p";
795
+ var INDENT_ROW_KEY = "alt+right";
796
+ var OUTDENT_ROW_KEY = "alt+left";
797
+ var TOGGLE_LANE_KEY = "alt+t";
798
+ var NATIVE_LANE_LABEL = {
799
+ steer: "Steering",
800
+ followUp: "Follow-up"
801
+ };
802
+ var NativeQueueState = class {
803
+ items = [];
804
+ nextIdNumber = 1;
805
+ nextSequence = 1;
806
+ enqueue(lane, text, images = []) {
807
+ const prefix = lane === "steer" ? "steer" : "follow-up";
808
+ const item = {
809
+ id: `${prefix}-${this.nextIdNumber++}`,
810
+ lane,
811
+ text,
812
+ images: [...images],
813
+ sequence: this.nextSequence++,
814
+ paused: false
815
+ };
816
+ this.items.push(item);
817
+ return { ...item, images: [...item.images] };
818
+ }
819
+ enqueueSteer(text, images = []) {
820
+ const item = this.enqueue("steer", text, images);
821
+ const firstRoot = this.items.findIndex((candidate) => candidate.lane === "followUp");
822
+ if (firstRoot !== -1) {
823
+ const inserted = this.items.pop();
824
+ this.items.splice(firstRoot, 0, inserted);
825
+ }
826
+ return item;
827
+ }
828
+ snapshot() {
829
+ return this.items.map((item) => ({ ...item, images: [...item.images] }));
830
+ }
831
+ peek() {
832
+ const item = this.items[0];
833
+ return item ? { ...item, images: [...item.images] } : void 0;
834
+ }
835
+ get(id) {
836
+ const item = this.items.find((candidate) => candidate.id === id);
837
+ return item ? { ...item, images: [...item.images] } : void 0;
838
+ }
839
+ remove(id) {
840
+ const index = this.items.findIndex((candidate) => candidate.id === id);
841
+ if (index === -1) return void 0;
842
+ const [item] = this.items.splice(index, 1);
843
+ return item ? { ...item, images: [...item.images] } : void 0;
844
+ }
845
+ prepend(item) {
846
+ this.items.unshift({ ...item, images: [...item.images] });
847
+ }
848
+ prependMany(items) {
849
+ for (let index = items.length - 1; index >= 0; index -= 1) {
850
+ const item = items[index];
851
+ if (item) this.items.unshift({ ...item, images: [...item.images] });
852
+ }
853
+ }
854
+ update(id, text) {
855
+ const item = this.items.find((candidate) => candidate.id === id);
856
+ if (!item) return false;
857
+ item.text = text;
858
+ return true;
859
+ }
860
+ setLane(id, lane) {
861
+ const item = this.items.find((candidate) => candidate.id === id);
862
+ if (!item || item.lane === lane) return false;
863
+ item.lane = lane;
864
+ return true;
865
+ }
866
+ setPaused(id, paused) {
867
+ const item = this.items.find((candidate) => candidate.id === id);
868
+ if (!item || (item.paused ?? false) === paused) return false;
869
+ item.paused = paused;
870
+ return true;
871
+ }
872
+ clear() {
873
+ this.items = [];
874
+ }
875
+ get length() {
876
+ return this.items.length;
877
+ }
878
+ };
879
+ var NativeEditSession = class {
880
+ composerDraft;
881
+ currentId;
882
+ drafts = /* @__PURE__ */ new Map();
883
+ constructor(item, composerDraft) {
884
+ this.currentId = item.id;
885
+ this.composerDraft = composerDraft;
886
+ this.drafts.set(item.id, {
887
+ text: item.text,
888
+ lane: item.lane,
889
+ removed: false,
890
+ paused: item.paused ?? false
891
+ });
892
+ }
893
+ get selectedId() {
894
+ return this.currentId;
895
+ }
896
+ capture(text) {
897
+ const draft = this.drafts.get(this.currentId);
898
+ if (draft) draft.text = text;
899
+ }
900
+ select(item, currentText) {
901
+ this.capture(currentText);
902
+ if (!this.drafts.has(item.id)) {
903
+ this.drafts.set(item.id, {
904
+ text: item.text,
905
+ lane: item.lane,
906
+ removed: false,
907
+ paused: item.paused ?? false
908
+ });
909
+ }
910
+ this.currentId = item.id;
911
+ return this.drafts.get(item.id)?.text ?? item.text;
912
+ }
913
+ toggleRemoved(id) {
914
+ const draft = this.drafts.get(id);
915
+ if (!draft) return void 0;
916
+ draft.removed = !draft.removed;
917
+ return draft.removed;
918
+ }
919
+ togglePaused(id) {
920
+ const draft = this.drafts.get(id);
921
+ if (!draft) return void 0;
922
+ draft.paused = !draft.paused;
923
+ return draft.paused;
924
+ }
925
+ setLane(id, lane) {
926
+ const draft = this.drafts.get(id);
927
+ if (!draft) return void 0;
928
+ draft.lane = lane;
929
+ return draft.lane;
930
+ }
931
+ commit(queue, currentText) {
932
+ this.capture(currentText);
933
+ let updated = 0;
934
+ let removed = 0;
935
+ let moved = 0;
936
+ let held = 0;
937
+ let released = 0;
938
+ for (const [id, draft] of this.drafts.entries()) {
939
+ if (draft.removed || !draft.text.trim()) {
940
+ if (queue.remove(id)) removed += 1;
941
+ continue;
942
+ }
943
+ if (queue.update(id, draft.text)) updated += 1;
944
+ if (queue.setLane(id, draft.lane)) moved += 1;
945
+ if (queue.setPaused(id, draft.paused)) {
946
+ if (draft.paused) held += 1;
947
+ else released += 1;
948
+ }
949
+ }
950
+ return { updated, removed, moved, held, released };
951
+ }
952
+ rollbackPositions() {
953
+ }
954
+ laneFor(id) {
955
+ return this.drafts.get(id)?.lane;
956
+ }
957
+ textFor(id) {
958
+ return this.drafts.get(id)?.text;
959
+ }
960
+ pausedFor(id) {
961
+ return this.drafts.get(id)?.paused;
962
+ }
963
+ isRemoved(id) {
964
+ return this.drafts.get(id)?.removed ?? false;
965
+ }
966
+ };
967
+ var errorText = (error) => error instanceof Error ? error.message : String(error ?? "");
968
+ var controlInputRe = /^[/!]/;
969
+ function createConversationQueue(options) {
970
+ const { piEvents, targetId, theme } = options;
971
+ const notify = (text, kind = "info") => {
972
+ options.onNotify?.(text, kind);
973
+ };
974
+ const requestRender = () => options.requestRender?.();
975
+ const targetLabel = options.targetName ?? targetId;
976
+ let bridge;
977
+ let queue;
978
+ let mode = "native";
979
+ let disposed = false;
980
+ const dispatched = [];
981
+ let externalPending = [];
982
+ let lastSendError;
983
+ let editSession;
984
+ const seenIds = /* @__PURE__ */ new Set();
985
+ const consumedIds = /* @__PURE__ */ new Set();
986
+ const liveTextCounts = /* @__PURE__ */ new Map();
987
+ const emitHandshake = (action) => {
988
+ let claimed = false;
989
+ let settled = false;
990
+ let result;
991
+ const request = {
992
+ version: 1,
993
+ action,
994
+ targetId,
995
+ claim: () => {
996
+ if (claimed) return false;
997
+ claimed = true;
998
+ return true;
999
+ },
1000
+ respond: (response) => {
1001
+ if (settled) return;
1002
+ settled = true;
1003
+ result = response;
1004
+ }
1005
+ };
1006
+ piEvents.emit(QUEUE_STEER_CONVERSATION_QUEUE_REQUEST_EVENT, request);
1007
+ return { claimed, result };
1008
+ };
1009
+ const acquisition = emitHandshake("acquire");
1010
+ if (acquisition.claimed && acquisition.result?.ok && acquisition.result.bridge?.version === 1 && acquisition.result.bridge.targetId === targetId) {
1011
+ bridge = acquisition.result.bridge;
1012
+ mode = "extension";
1013
+ } else if (acquisition.claimed && acquisition.result && !acquisition.result.ok) {
1014
+ notify(`pi-queue-steer refused the conversation queue for ${targetLabel}: ${acquisition.result.error ?? "unknown error"}`, "error");
1015
+ }
1016
+ queue = bridge ? bridge.createQueue() : new NativeQueueState();
1017
+ const laneLabel = (lane) => bridge ? bridge.laneLabel(lane) : lane === "steer" ? "steer" : "follow-up";
1018
+ const isQueueable = (text) => bridge ? bridge.isQueueableSubmission(text) : !controlInputRe.test(text.trim()) && text.trim() !== "";
1019
+ const decoratedRow = (item) => ({
1020
+ id: item.id,
1021
+ lane: editSession?.laneFor?.(item.id) ?? item.lane,
1022
+ text: editSession?.textFor?.(item.id) ?? item.text,
1023
+ state: "queued",
1024
+ paused: editSession?.pausedFor?.(item.id) ?? (item.paused ?? false),
1025
+ selected: editSession?.selectedId === item.id,
1026
+ removed: editSession?.isRemoved?.(item.id) ?? false
1027
+ });
1028
+ const orderedRows = () => {
1029
+ const held = queue.snapshot().map(decoratedRow);
1030
+ const asDispatched = (row) => ({
1031
+ id: row.id,
1032
+ lane: row.lane,
1033
+ text: row.text,
1034
+ state: "dispatched",
1035
+ paused: false,
1036
+ selected: false,
1037
+ removed: false
1038
+ });
1039
+ return [...dispatched.map(asDispatched), ...held, ...externalPending.map(asDispatched)];
1040
+ };
1041
+ const headBatch = (lane) => {
1042
+ const items = queue.snapshot();
1043
+ const head = items[0];
1044
+ if (!head || head.lane !== lane) return [];
1045
+ const batch = [];
1046
+ for (const item of items) {
1047
+ if (item.lane !== lane) break;
1048
+ if (item.paused) break;
1049
+ batch.push(item);
1050
+ }
1051
+ return batch;
1052
+ };
1053
+ const dequeueKeys = () => {
1054
+ const manager = options.keybindings ?? getKeybindings();
1055
+ const keys = manager.getKeys("app.message.dequeue");
1056
+ return keys.filter((key) => /up$/i.test(key)).map(
1057
+ (key) => key.endsWith("Up") ? `${key.slice(0, -2)}Down` : `${key.slice(0, -2)}down`
1058
+ );
1059
+ };
1060
+ const actionMatches = (data, action, fallback) => {
1061
+ const manager = options.keybindings;
1062
+ if (manager) {
1063
+ const keys = manager.getKeys(action);
1064
+ if (keys.length === 0) return false;
1065
+ return manager.matches(data, action);
1066
+ }
1067
+ const global = getKeybindings();
1068
+ if (global.getKeys(action).length > 0) return global.matches(data, action);
1069
+ return fallback(data);
1070
+ };
1071
+ const startEditing = () => {
1072
+ if (!options.editor) {
1073
+ notify("Editing queued rows requires the shared editor", "error");
1074
+ return false;
1075
+ }
1076
+ const items = queue.snapshot();
1077
+ if (items.length === 0) {
1078
+ notify("No queued messages to edit", "info");
1079
+ return false;
1080
+ }
1081
+ const mostRecent = items.reduce((newest, item) => item.sequence > newest.sequence ? item : newest, items[0]);
1082
+ editSession = bridge ? bridge.createEditSession(mostRecent, options.editor.getText()) : new NativeEditSession(mostRecent, options.editor.getText());
1083
+ options.editor.setText(mostRecent.text);
1084
+ notify(`Editing queued ${laneLabel(mostRecent.lane)} row \xB7 enter saves, escape rolls back`, "info");
1085
+ requestRender();
1086
+ return true;
1087
+ };
1088
+ const finishEditing = (save) => {
1089
+ const session = editSession;
1090
+ const editor = options.editor;
1091
+ if (!session || !editor) return false;
1092
+ const currentText = editor.getText();
1093
+ editSession = void 0;
1094
+ if (save) {
1095
+ const result = session.commit(queue, currentText);
1096
+ if (result.removed > 0) notify(`Removed ${result.removed} queued row${result.removed === 1 ? "" : "s"}`, "info");
1097
+ if (result.moved > 0) notify(`Changed delivery depth for ${result.moved} row${result.moved === 1 ? "" : "s"}`, "info");
1098
+ if (result.held > 0) notify(`Paused ${result.held} row${result.held === 1 ? "" : "s"} \u2014 dispatch stops there until resumed`, "info");
1099
+ if (result.released > 0) notify(`Resumed ${result.released} row${result.released === 1 ? "" : "s"}`, "info");
1100
+ } else {
1101
+ notify("Row edits rolled back", "info");
1102
+ }
1103
+ editor.setText(session.composerDraft);
1104
+ requestRender();
1105
+ return true;
1106
+ };
1107
+ const matchesOptionArrow = (data, direction) => {
1108
+ const arrow = direction === "left" ? OUTDENT_ROW_KEY : INDENT_ROW_KEY;
1109
+ const wordAlias = direction === "left" ? "alt+b" : "alt+f";
1110
+ return matchesKey(data, arrow) && !matchesKey(data, wordAlias);
1111
+ };
1112
+ const inlineEditorRenderer = () => {
1113
+ const editor = options.editor;
1114
+ if (!editor?.render) return void 0;
1115
+ return (width) => {
1116
+ const lines = editor.render(width);
1117
+ if (bridge?.extractInlineEditorLines) {
1118
+ return bridge.extractInlineEditorLines(lines, editor.paddingX ?? 0);
1119
+ }
1120
+ return [...lines];
1121
+ };
1122
+ };
1123
+ return {
1124
+ targetId,
1125
+ get mode() {
1126
+ return mode;
1127
+ },
1128
+ get active() {
1129
+ return !disposed && (queue.length > 0 || dispatched.length > 0);
1130
+ },
1131
+ get editingActive() {
1132
+ return editSession !== void 0;
1133
+ },
1134
+ stage(text, lane) {
1135
+ if (disposed) return { ok: false, error: "Queue is disposed" };
1136
+ const trimmed = text.trim();
1137
+ if (!trimmed) return { ok: false, error: "Nothing to queue" };
1138
+ if (!isQueueable(trimmed) || controlInputRe.test(trimmed)) {
1139
+ return {
1140
+ ok: false,
1141
+ error: "Control input (/ commands, ! bash) is Main-only and is not queued from a focused conversation"
1142
+ };
1143
+ }
1144
+ const row = lane === "steer" && typeof queue.enqueueSteer === "function" ? queue.enqueueSteer(text) : queue.enqueue(lane, text);
1145
+ notify(`Queued ${laneLabel(lane)} \u2192 ${targetLabel}`, "info");
1146
+ requestRender();
1147
+ return { ok: true, id: row.id };
1148
+ },
1149
+ async submit(lane) {
1150
+ if (disposed) return false;
1151
+ if (editSession) {
1152
+ notify("Finish or cancel row editing before dispatching the queue", "info");
1153
+ return false;
1154
+ }
1155
+ const batch = headBatch(lane);
1156
+ if (batch.length === 0) {
1157
+ const head = queue.peek();
1158
+ if (head?.paused) notify(`The next ${laneLabel(lane)} row is paused \u2014 dispatch holds there`, "info");
1159
+ else notify(`No dispatchable queued ${laneLabel(lane)} rows at the timeline head`, "info");
1160
+ return false;
1161
+ }
1162
+ let sent = 0;
1163
+ lastSendError = void 0;
1164
+ for (const item of batch) {
1165
+ if (disposed) return false;
1166
+ queue.remove(item.id);
1167
+ const pending = { id: item.id, lane, text: item.text };
1168
+ dispatched.push(pending);
1169
+ requestRender();
1170
+ let expectedId;
1171
+ try {
1172
+ const result = await options.send(item.text, lane);
1173
+ const candidate = result;
1174
+ const reported = candidate?.messageId ?? candidate?.id;
1175
+ if (typeof reported === "string" && reported !== "") expectedId = reported;
1176
+ } catch (error) {
1177
+ lastSendError = error;
1178
+ const pendingIndex = dispatched.indexOf(pending);
1179
+ if (pendingIndex < 0 || disposed) return !disposed;
1180
+ dispatched.splice(pendingIndex, 1);
1181
+ queue.prepend({ ...item });
1182
+ notify(`Send failed for ${targetLabel} (${laneLabel(lane)}); row restored to the queue head: ${errorText(error)}`, "error");
1183
+ requestRender();
1184
+ return false;
1185
+ }
1186
+ if (expectedId) pending.expectedId = expectedId;
1187
+ sent += 1;
1188
+ }
1189
+ notify(`Accepted ${sent} queued ${laneLabel(lane)} row${sent === 1 ? "" : "s"} \u2192 ${targetLabel} \xB7 awaiting delivery`, "info");
1190
+ requestRender();
1191
+ return true;
1192
+ },
1193
+ async dispatch(text, lane) {
1194
+ const row = this.stage(text, lane);
1195
+ if (!row.ok || !row.id) throw new Error(row.error ?? "Unable to queue input");
1196
+ if (!await this.submit(lane)) {
1197
+ queue.remove(row.id);
1198
+ throw lastSendError ?? new Error("The queue head is paused or held; edit or resume it before sending");
1199
+ }
1200
+ },
1201
+ park(text, lane) {
1202
+ const result = this.stage(text, lane);
1203
+ if (result.id) queue.setPaused(result.id, true);
1204
+ return result;
1205
+ },
1206
+ cancelEditing() {
1207
+ if (editSession) finishEditing(false);
1208
+ },
1209
+ syncPending(pending) {
1210
+ externalPending = [];
1211
+ if (!pending) return;
1212
+ const own = [...queue.snapshot(), ...dispatched];
1213
+ for (const [lane, messages] of [["steer", pending.steering], ["followUp", pending.followUp]]) {
1214
+ const remaining = own.filter((row) => row.lane === lane).map((row) => row.text);
1215
+ messages.forEach((text, index) => {
1216
+ const match = remaining.indexOf(text);
1217
+ if (match >= 0) remaining.splice(match, 1);
1218
+ else externalPending.push({ id: `native:${lane}:${index}`, lane, text });
1219
+ });
1220
+ }
1221
+ },
1222
+ rows: orderedRows,
1223
+ render(width) {
1224
+ if (disposed || width <= 0) return [];
1225
+ const rows = orderedRows();
1226
+ if (rows.length === 0) return [];
1227
+ if (bridge?.createTimelineWidget && bridge.buildTimelineItems) {
1228
+ const visibleRows = [
1229
+ ...dispatched.map((row, index) => ({ id: row.id, lane: row.lane, text: row.text, images: [], sequence: index - dispatched.length })),
1230
+ ...queue.snapshot(),
1231
+ ...externalPending.map((row, index) => ({ id: row.id, lane: row.lane, text: row.text, images: [], sequence: queue.snapshot().length + index + 1 }))
1232
+ ];
1233
+ const displayQueue = new Proxy(queue, { get(target, key) {
1234
+ if (key === "snapshot") return () => visibleRows;
1235
+ const value = Reflect.get(target, key, target);
1236
+ return typeof value === "function" ? value.bind(target) : value;
1237
+ } });
1238
+ const items = bridge.buildTimelineItems(displayQueue, editSession);
1239
+ const inline = editSession ? inlineEditorRenderer() : void 0;
1240
+ const editingId = editSession?.selectedId;
1241
+ const widget = bridge.createTimelineWidget(
1242
+ {
1243
+ items,
1244
+ ...editingId !== void 0 ? { editingId } : {},
1245
+ paused: false,
1246
+ idle: options.isIdle?.() ?? false,
1247
+ ...inline ? { renderInlineEditor: inline } : {}
1248
+ },
1249
+ theme
1250
+ );
1251
+ const lines2 = widget.render(width);
1252
+ if (dispatched.length > 0) lines2.push(theme.fg("dim", truncateToWidth2("Sent rows await child delivery; they cannot be edited locally.", width, "")));
1253
+ return lines2;
1254
+ }
1255
+ const lines = [""];
1256
+ const innerWidth = Math.max(0, width - 2);
1257
+ const dequeueHint = (options.keybindings ?? getKeybindings()).getKeys("app.message.dequeue").join("/") || DEQUEUE_FALLBACK;
1258
+ for (const row of rows) {
1259
+ const label = bridge ? bridge.laneLabel(row.lane) : NATIVE_LANE_LABEL[row.lane];
1260
+ const marker = row.selected ? "\u203A " : row.paused ? "\u23F8 " : "";
1261
+ const note = row.removed ? " \xB7 removed on save" : row.paused ? " \xB7 paused" : "";
1262
+ const color = row.state === "dispatched" ? "dim" : bridge ? bridge.laneColor(row.lane) : "dim";
1263
+ lines.push(
1264
+ ` ${theme.fg(color, truncateToWidth2(`${marker}${label}: ${row.text.replace(/\n/g, " ")}${note}`, innerWidth, "\u2026"))} `
1265
+ );
1266
+ }
1267
+ const hint = queue.length > 0 ? `\u21B3 ${dequeueHint} to edit queued messages` : "\u21B3 Waiting for child delivery";
1268
+ lines.push(` ${theme.fg("dim", truncateToWidth2(hint, innerWidth, "\u2026"))} `);
1269
+ return lines;
1270
+ },
1271
+ handleInput(data) {
1272
+ if (disposed) return false;
1273
+ if (!editSession) {
1274
+ if (queue.length === 0) return false;
1275
+ if (!options.editor?.getText().trim() && matchesKey(data, Key.enter)) {
1276
+ const head = queue.peek();
1277
+ if (head) {
1278
+ queue.setPaused(head.id, false);
1279
+ void this.submit(head.lane);
1280
+ }
1281
+ return true;
1282
+ }
1283
+ if (actionMatches(data, "app.message.dequeue", (input) => matchesKey(input, DEQUEUE_FALLBACK))) {
1284
+ return startEditing();
1285
+ }
1286
+ return false;
1287
+ }
1288
+ const session = editSession;
1289
+ const editor = options.editor;
1290
+ if (actionMatches(data, "app.message.dequeue", (input) => matchesKey(input, DEQUEUE_FALLBACK)) && editor) {
1291
+ const ordered = queue.snapshot();
1292
+ const index = ordered.findIndex((item) => item.id === session.selectedId);
1293
+ const target = index <= 0 ? ordered.at(-1) : ordered[index - 1];
1294
+ if (target) editor.setText(session.select(target, editor.getText()));
1295
+ requestRender();
1296
+ return true;
1297
+ }
1298
+ const nextKeys = dequeueKeys();
1299
+ if (nextKeys.length > 0 && nextKeys.some((key) => matchesKey(data, key)) && editor) {
1300
+ const ordered = queue.snapshot();
1301
+ const index = ordered.findIndex((item) => item.id === session.selectedId);
1302
+ const target = index === -1 || index === ordered.length - 1 ? ordered[0] : ordered[index + 1];
1303
+ if (target) editor.setText(session.select(target, editor.getText()));
1304
+ requestRender();
1305
+ return true;
1306
+ }
1307
+ if (matchesKey(data, REMOVE_ROW_KEY)) {
1308
+ session.toggleRemoved(session.selectedId);
1309
+ requestRender();
1310
+ return true;
1311
+ }
1312
+ if (matchesKey(data, PAUSE_ROW_KEY)) {
1313
+ session.togglePaused(session.selectedId);
1314
+ requestRender();
1315
+ return true;
1316
+ }
1317
+ if (matchesOptionArrow(data, "left")) {
1318
+ session.setLane(session.selectedId, "followUp");
1319
+ requestRender();
1320
+ return true;
1321
+ }
1322
+ if (matchesOptionArrow(data, "right")) {
1323
+ session.setLane(session.selectedId, "steer");
1324
+ requestRender();
1325
+ return true;
1326
+ }
1327
+ if (matchesKey(data, TOGGLE_LANE_KEY)) {
1328
+ const current = queue.get(session.selectedId)?.lane;
1329
+ if (current) session.setLane(session.selectedId, current === "steer" ? "followUp" : "steer");
1330
+ requestRender();
1331
+ return true;
1332
+ }
1333
+ if (actionMatches(data, "tui.input.submit", (input) => matchesKey(input, Key.enter)) || actionMatches(data, "app.message.followUp", () => false)) {
1334
+ return finishEditing(true);
1335
+ }
1336
+ if (actionMatches(data, "app.interrupt", (input) => matchesKey(input, Key.escape))) {
1337
+ return finishEditing(false);
1338
+ }
1339
+ editor?.handleInput?.(data);
1340
+ return true;
1341
+ },
1342
+ syncSnapshot(entries) {
1343
+ if (disposed || dispatched.length === 0) {
1344
+ for (const entry of entries) {
1345
+ if (!seenIds.has(entry.id)) seenIds.add(entry.id);
1346
+ }
1347
+ return 0;
1348
+ }
1349
+ for (const entry of entries) {
1350
+ if (seenIds.has(entry.id)) continue;
1351
+ seenIds.add(entry.id);
1352
+ if (entry.historical) continue;
1353
+ const key = entry.text.trim();
1354
+ liveTextCounts.set(key, (liveTextCounts.get(key) ?? 0) + 1);
1355
+ }
1356
+ let retired = 0;
1357
+ const consume = (entry) => {
1358
+ consumedIds.add(entry.id);
1359
+ if (!entry.historical) {
1360
+ const key = entry.text.trim();
1361
+ const remaining = (liveTextCounts.get(key) ?? 0) - 1;
1362
+ if (remaining > 0) liveTextCounts.set(key, remaining);
1363
+ else liveTextCounts.delete(key);
1364
+ }
1365
+ };
1366
+ const frontierEntry = (row) => {
1367
+ if (row.expectedId) {
1368
+ const match = entries.find((entry) => entry.id === row.expectedId && !consumedIds.has(entry.id));
1369
+ if (match) return match;
1370
+ }
1371
+ for (const entry of entries) {
1372
+ if (entry.historical || consumedIds.has(entry.id)) continue;
1373
+ if (entry.text.trim() === row.text.trim() && (liveTextCounts.get(entry.text.trim()) ?? 0) > 0) {
1374
+ return { id: entry.id, text: entry.text.trim() };
1375
+ }
1376
+ }
1377
+ return void 0;
1378
+ };
1379
+ for (let index = dispatched.length - 1; index >= 0; index -= 1) {
1380
+ const row = dispatched[index];
1381
+ if (!row) continue;
1382
+ const confirmed = frontierEntry(row);
1383
+ if (!confirmed) continue;
1384
+ consume(confirmed);
1385
+ dispatched.splice(index, 1);
1386
+ retired += 1;
1387
+ }
1388
+ if (retired > 0) {
1389
+ notify(`${retired} queued row${retired === 1 ? "" : "s"} confirmed delivered \u2192 ${targetLabel}`, "info");
1390
+ requestRender();
1391
+ }
1392
+ return retired;
1393
+ },
1394
+ retireAll(reason) {
1395
+ if (disposed) return 0;
1396
+ const count = queue.length + dispatched.length;
1397
+ queue.clear();
1398
+ dispatched.length = 0;
1399
+ editSession = void 0;
1400
+ if (count > 0) {
1401
+ const suffix = reason ? ` (${reason})` : "";
1402
+ notify(`Retired ${count} queued row${count === 1 ? "" : "s"} for ${targetLabel}${suffix}`, "info");
1403
+ requestRender();
1404
+ }
1405
+ return count;
1406
+ },
1407
+ pendingCount() {
1408
+ if (disposed) return 0;
1409
+ return queue.length + dispatched.length;
1410
+ },
1411
+ dispose({ retain = false } = {}) {
1412
+ if (disposed) return;
1413
+ disposed = true;
1414
+ editSession = void 0;
1415
+ if (retain) {
1416
+ return;
1417
+ }
1418
+ queue.clear();
1419
+ dispatched.length = 0;
1420
+ if (bridge) emitHandshake("release");
1421
+ }
1422
+ };
1423
+ }
1424
+
1425
+ // src/ui/conversation-queue-store.ts
1426
+ var ConversationQueueStore = class {
1427
+ slots = /* @__PURE__ */ new Map();
1428
+ userIdentities = /* @__PURE__ */ new WeakMap();
1429
+ attach(options) {
1430
+ const existing = this.slots.get(options.targetId);
1431
+ if (existing) {
1432
+ existing.attached = options;
1433
+ return existing.queue;
1434
+ }
1435
+ const slot = { queue: void 0, attached: options, initialized: false, frontier: 0 };
1436
+ const attached = () => slot.attached;
1437
+ slot.queue = createConversationQueue({
1438
+ ...options,
1439
+ send: (text, lane) => {
1440
+ const current = attached();
1441
+ if (!current) return Promise.reject(new Error("Open this conversation to send its queued messages"));
1442
+ return current.send(text, lane);
1443
+ },
1444
+ editor: {
1445
+ getText: () => attached()?.editor?.getText() ?? "",
1446
+ setText: (text) => attached()?.editor?.setText(text),
1447
+ handleInput: (data) => attached()?.editor?.handleInput?.(data),
1448
+ render: (width) => attached()?.editor?.render?.(width) ?? [],
1449
+ get paddingX() {
1450
+ return attached()?.editor?.paddingX ?? 0;
1451
+ }
1452
+ },
1453
+ isIdle: () => attached()?.isIdle?.() ?? true,
1454
+ onNotify: (text, kind) => attached()?.onNotify?.(text, kind),
1455
+ requestRender: () => attached()?.requestRender?.()
1456
+ });
1457
+ this.slots.set(options.targetId, slot);
1458
+ return slot.queue;
1459
+ }
1460
+ get(id) {
1461
+ return this.slots.get(id)?.queue;
1462
+ }
1463
+ detach(id) {
1464
+ const slot = this.slots.get(id);
1465
+ if (!slot) return;
1466
+ slot.queue.cancelEditing();
1467
+ slot.attached = void 0;
1468
+ slot.projection = void 0;
1469
+ }
1470
+ sync(id, transcript) {
1471
+ const slot = this.slots.get(id);
1472
+ if (!slot) return;
1473
+ let projection = slot.projection;
1474
+ const changed = !projection || projection.messages !== transcript.messages || projection.messageCount !== transcript.messages.length || projection.revision !== transcript.revision || projection.sourceId !== transcript.sourceId || projection.sessionFile !== transcript.sessionFile || projection.eventsFile !== transcript.eventsFile || projection.leafId !== transcript.leafId;
1475
+ if (changed) {
1476
+ let frontier = slot.frontier;
1477
+ const occurrences = /* @__PURE__ */ new Map();
1478
+ const entries = [];
1479
+ for (const message of transcript.messages) {
1480
+ if (Number.isFinite(message.timestamp)) frontier = Math.max(frontier, message.timestamp);
1481
+ if (message.role !== "user") continue;
1482
+ const { id: identity, text } = this.userIdentity(message);
1483
+ const occurrence = occurrences.get(identity) ?? 0;
1484
+ occurrences.set(identity, occurrence + 1);
1485
+ entries.push({
1486
+ id: occurrence === 0 ? identity : `${identity}:${occurrence}`,
1487
+ text,
1488
+ historical: !slot.initialized || message.timestamp < slot.frontier
1489
+ });
1490
+ }
1491
+ projection = {
1492
+ messages: transcript.messages,
1493
+ messageCount: transcript.messages.length,
1494
+ revision: transcript.revision,
1495
+ sourceId: transcript.sourceId,
1496
+ sessionFile: transcript.sessionFile,
1497
+ eventsFile: transcript.eventsFile,
1498
+ leafId: transcript.leafId,
1499
+ entries
1500
+ };
1501
+ slot.projection = slot.attached ? projection : void 0;
1502
+ slot.frontier = frontier;
1503
+ slot.initialized = true;
1504
+ }
1505
+ if (projection && (changed || slot.queue.pendingCount() > 0)) slot.queue.syncSnapshot(projection.entries);
1506
+ slot.queue.syncPending(transcript.pendingMessages);
1507
+ }
1508
+ userIdentity(message) {
1509
+ const cached = this.userIdentities.get(message);
1510
+ if (cached && cached.content === message.content && cached.timestamp === message.timestamp) return cached;
1511
+ const raw = typeof message.content === "string" ? message.content : message.content.filter((part) => part.type === "text").map((part) => part.text).join("");
1512
+ const text = unwrapActorEnvelopeText(raw) ?? raw;
1513
+ let id;
1514
+ if (text !== raw) {
1515
+ try {
1516
+ const envelope = JSON.parse(raw.trim().slice("Fabric actor message from direct:".length));
1517
+ if (typeof envelope.id === "string") id = envelope.id;
1518
+ } catch {
1519
+ }
1520
+ }
1521
+ id ||= createHash("sha256").update(JSON.stringify([message.timestamp, message.content])).digest("hex");
1522
+ const identity = { id, text };
1523
+ if (typeof message.content === "string") {
1524
+ this.userIdentities.set(message, { ...identity, content: message.content, timestamp: message.timestamp });
1525
+ }
1526
+ return identity;
1527
+ }
1528
+ clear() {
1529
+ for (const slot of this.slots.values()) {
1530
+ slot.queue.cancelEditing();
1531
+ slot.attached = void 0;
1532
+ slot.projection = void 0;
1533
+ slot.queue.dispose();
1534
+ }
1535
+ this.slots.clear();
1536
+ }
1537
+ };
1538
+
1539
+ // src/ui/conversation.ts
1540
+ var STATE_ENTRY_LIMIT = 128;
1541
+ var FabricConversationState = class {
1542
+ queues = new ConversationQueueStore();
1543
+ selectedId;
1544
+ epochCounter = 0;
1545
+ entries = /* @__PURE__ */ new Map();
1546
+ pendingSends = /* @__PURE__ */ new Set();
1547
+ get epoch() {
1548
+ return this.epochCounter;
1549
+ }
1550
+ hasPendingSend(id, message) {
1551
+ for (const pending of this.pendingSends) {
1552
+ if (pending.id === id && pending.message === message) return true;
1553
+ }
1554
+ return false;
1555
+ }
1556
+ addPendingSend(pending) {
1557
+ this.pendingSends.add(pending);
1558
+ }
1559
+ /** Acknowledged: drop the pending marker and clear only the exact accepted draft. */
1560
+ resolvePendingSend(id, message) {
1561
+ for (const pending of this.pendingSends) {
1562
+ if (pending.id !== id || pending.message !== message) continue;
1563
+ this.pendingSends.delete(pending);
1564
+ const entry = this.entries.get(id);
1565
+ if (entry && entry.draft === message) entry.draft = "";
1566
+ return;
1567
+ }
1568
+ }
1569
+ /** Rejected: drop the pending marker; the raw draft stays untouched. */
1570
+ failPendingSend(id, message) {
1571
+ for (const pending of this.pendingSends) {
1572
+ if (pending.id !== id || pending.message !== message) continue;
1573
+ this.pendingSends.delete(pending);
1574
+ return;
1575
+ }
1576
+ }
1577
+ /** Live view state for a target; creates (and may evict empty) entries. */
1578
+ view(id) {
1579
+ const existing = this.entries.get(id);
1580
+ if (existing) {
1581
+ this.entries.delete(id);
1582
+ this.entries.set(id, existing);
1583
+ return existing;
1584
+ }
1585
+ const created = {
1586
+ draft: "",
1587
+ following: true,
1588
+ scroll: 0,
1589
+ pageAnchor: void 0,
1590
+ toolsExpanded: false,
1591
+ lastSeenUpdatedAt: 0
1592
+ };
1593
+ this.entries.set(id, created);
1594
+ this.enforceLimit();
1595
+ return created;
1596
+ }
1597
+ /** Non-mutating lookup; unread checks must never create or evict drafts. */
1598
+ peek(id) {
1599
+ return this.entries.get(id);
1600
+ }
1601
+ clear() {
1602
+ this.queues.clear();
1603
+ this.entries.clear();
1604
+ this.pendingSends.clear();
1605
+ this.selectedId = void 0;
1606
+ this.epochCounter++;
1607
+ }
1608
+ enforceLimit() {
1609
+ while (this.entries.size > STATE_ENTRY_LIMIT) {
1610
+ let evicted = false;
1611
+ for (const key of this.entries.keys()) {
1612
+ if (key === this.selectedId) continue;
1613
+ const entry = this.entries.get(key);
1614
+ if (entry && entry.draft === "" && entry.following && !entry.pageAnchor && !entry.toolsExpanded && entry.hideThinking === void 0 && !this.queues.get(key) && ![...this.pendingSends].some((pending) => pending.id === key)) {
1615
+ this.entries.delete(key);
1616
+ evicted = true;
1617
+ break;
1618
+ }
1619
+ }
1620
+ if (!evicted) break;
1621
+ }
1622
+ }
1623
+ };
1624
+ var FEEDBACK_TTL_MS = 8e3;
1625
+ var FOLLOW_UP_FALLBACK = ["alt+enter", "ctrl+q"];
1626
+ var TOOLS_EXPAND_FALLBACK = ["ctrl+o"];
1627
+ var conversationEditorTheme = (theme, thinking) => ({
1628
+ borderColor: (value) => {
1629
+ const level = thinking();
1630
+ const color = level === "minimal" ? "thinkingMinimal" : level === "low" ? "thinkingLow" : level === "medium" ? "thinkingMedium" : level === "high" ? "thinkingHigh" : level === "xhigh" ? "thinkingXhigh" : level === "max" ? "thinkingMax" : "borderMuted";
1631
+ return theme.fg(color, value);
1632
+ },
1633
+ selectList: {
1634
+ selectedPrefix: (text) => theme.fg("accent", text),
1635
+ selectedText: (text) => theme.fg("accent", text),
1636
+ description: (text) => theme.fg("muted", text),
1637
+ scrollInfo: (text) => theme.fg("muted", text),
1638
+ noMatch: (text) => theme.fg("muted", text)
1639
+ }
1640
+ });
1641
+ var errorText2 = (error) => {
1642
+ if (error instanceof Error) return error.message;
1643
+ return String(error ?? "");
1644
+ };
1645
+ var isMainTarget = (target) => target?.kind === "main";
1646
+ var FabricConversationView = class {
1647
+ focusState = true;
1648
+ tui;
1649
+ theme;
1650
+ options;
1651
+ state;
1652
+ renderer;
1653
+ editor;
1654
+ suspendedEditor;
1655
+ editorEpoch = -1;
1656
+ pickerInput;
1657
+ pickerRows = [];
1658
+ pickerSelectedId;
1659
+ mode = "conversation";
1660
+ currentId;
1661
+ feedback;
1662
+ commandNotification;
1663
+ notificationScope = 0;
1664
+ stopConfirmId;
1665
+ disposed = false;
1666
+ lastBodyLength = 0;
1667
+ lastBody = [];
1668
+ lastBodyBudget = 1;
1669
+ editorTop = 0;
1670
+ editorHeight = 0;
1671
+ ownsMouseMode = false;
1672
+ targets = [];
1673
+ targetsKey = "";
1674
+ targetsById = /* @__PURE__ */ new Map();
1675
+ nonMain = [];
1676
+ main;
1677
+ observationKey = "";
1678
+ observedTranscript;
1679
+ pickerKey = "";
1680
+ working;
1681
+ workingTargetId;
1682
+ textSelection = new ConversationTextSelection();
1683
+ selectionWidth = 0;
1684
+ selectionWasFollowing = false;
1685
+ bodyTop = 0;
1686
+ bodyHeight = 0;
1687
+ copyVersion = 0;
1688
+ copyTask = Promise.resolve();
1689
+ constructor(tui, theme, options) {
1690
+ this.tui = tui;
1691
+ this.theme = theme;
1692
+ this.options = options;
1693
+ this.state = options.state;
1694
+ this.updateTargets();
1695
+ this.renderer = new FabricConversationTranscriptRenderer(tui, theme, {
1696
+ ...options.rendererOptions,
1697
+ imageWidthCells: options.appearance?.imageWidthCells
1698
+ });
1699
+ this.editor = this.createEditor();
1700
+ this.editorEpoch = this.state.epoch;
1701
+ const nonMain = this.nonMainTargets();
1702
+ const requested = options.initialTargetId ?? defaultConversationTarget(nonMain, options.state.selectedId)?.id;
1703
+ const requestedTarget = requested ? this.targetById(requested) : void 0;
1704
+ const resolved = requested && requestedTarget && !isMainTarget(requestedTarget) ? requested : nonMain[0]?.id;
1705
+ if (resolved) this.applySelection(resolved, false);
1706
+ if (!this.currentId) this.currentId = nonMain[0]?.id;
1707
+ if (tui.mode === "regular") {
1708
+ tui.terminal.write("\x1B[?1000h\x1B[?1002h\x1B[?1006h");
1709
+ this.ownsMouseMode = true;
1710
+ }
1711
+ }
1712
+ createEditor(withHistory = true) {
1713
+ const editorTui = Object.create(this.tui, { requestRender: { value: () => {
1714
+ if (!this.disposed && this.editor === editor) this.tui.requestRender();
1715
+ } } });
1716
+ const editor = new BorderStatusEditor(editorTui, conversationEditorTheme(this.theme, () => this.currentTarget()?.thinking), {
1717
+ paddingX: this.options.appearance?.editorPaddingX ?? 0
1718
+ });
1719
+ editor.setWorkingStatusIndicator(this.working);
1720
+ editor.focused = this.focusState && this.mode === "conversation";
1721
+ if (!withHistory) return editor;
1722
+ editor.setAutocompleteProvider(conversationCommandCompletion(() => !this.disposed && this.editor === editor && this.mode === "conversation" && !this.state.queues.get(this.currentId ?? "")?.editingActive));
1723
+ editor.onSubmit = (text) => {
1724
+ if (this.disposed || this.editor !== editor) return;
1725
+ editor.setText(text);
1726
+ this.submit("steer");
1727
+ };
1728
+ editor.onChange = (text) => {
1729
+ if (this.editor === editor && this.currentId && !this.state.queues.get(this.currentId)?.editingActive) this.state.view(this.currentId).draft = text;
1730
+ };
1731
+ for (const text of this.currentId ? this.state.peek(this.currentId)?.promptHistory ?? [] : []) editor.addToHistory(text);
1732
+ return editor;
1733
+ }
1734
+ releaseEditor(editor) {
1735
+ if (!editor) return;
1736
+ editor.setAutocompleteProvider(conversationCommandCompletion(() => false));
1737
+ editor.focused = false;
1738
+ delete editor.onSubmit;
1739
+ delete editor.onChange;
1740
+ }
1741
+ resetEditor() {
1742
+ this.releaseEditor(this.editor);
1743
+ this.releaseEditor(this.suspendedEditor);
1744
+ this.suspendedEditor = void 0;
1745
+ this.editor = this.createEditor();
1746
+ this.editorEpoch = this.state.epoch;
1747
+ }
1748
+ ensureEditorEpoch() {
1749
+ if (this.editorEpoch === this.state.epoch) return;
1750
+ this.observedTranscript = void 0;
1751
+ this.observationKey = "";
1752
+ this.resetEditor();
1753
+ if (this.currentId) this.editor?.setText(this.state.view(this.currentId).draft);
1754
+ }
1755
+ initializePromptHistory() {
1756
+ if (!this.currentId || !this.editor || this.suspendedEditor) return;
1757
+ const entry = this.state.view(this.currentId);
1758
+ if (entry.promptHistory !== void 0) return;
1759
+ const transcript = this.observedTranscript ?? this.options.transcript(this.currentId, entry.following);
1760
+ if (transcript.unavailable) return;
1761
+ entry.promptHistory = conversationPromptHistory(transcript);
1762
+ for (const text of entry.promptHistory) this.editor.addToHistory(text);
1763
+ }
1764
+ rememberPrompt(text) {
1765
+ if (!this.currentId) return;
1766
+ this.initializePromptHistory();
1767
+ const entry = this.state.view(this.currentId);
1768
+ appendConversationPrompt(entry.promptHistory ??= [], text);
1769
+ this.editor?.addToHistory(text);
1770
+ }
1771
+ setQueueEditorText(text) {
1772
+ let restoredText = text;
1773
+ const editing = this.currentId && this.state.queues.get(this.currentId)?.editingActive;
1774
+ if (editing && !this.suspendedEditor) {
1775
+ this.suspendedEditor = this.editor;
1776
+ if (this.suspendedEditor) this.suspendedEditor.focused = false;
1777
+ this.editor = this.createEditor(false);
1778
+ } else if (!editing && this.suspendedEditor) {
1779
+ this.releaseEditor(this.editor);
1780
+ this.editor = this.suspendedEditor;
1781
+ this.suspendedEditor = void 0;
1782
+ this.editor.focused = this.focusState && this.mode === "conversation";
1783
+ this.attachWorkingIndicator();
1784
+ restoredText = this.currentId ? this.state.view(this.currentId).draft : text;
1785
+ }
1786
+ this.editor?.setText(restoredText);
1787
+ }
1788
+ get focused() {
1789
+ return this.focusState;
1790
+ }
1791
+ set focused(value) {
1792
+ this.focusState = value;
1793
+ if (this.mode === "picker") {
1794
+ if (this.pickerInput) this.pickerInput.focused = value;
1795
+ if (this.editor) this.editor.focused = false;
1796
+ return;
1797
+ }
1798
+ if (this.editor) this.editor.focused = value;
1799
+ }
1800
+ /** Re-focus a target while the view is open; selecting Main closes to the native session. */
1801
+ selectTarget(id) {
1802
+ this.updateTargets();
1803
+ this.applySelection(id, true);
1804
+ }
1805
+ handleInput(data) {
1806
+ if (this.disposed) return;
1807
+ this.ensureEditorEpoch();
1808
+ this.updateTargets();
1809
+ const mouse = /^\x1b\[<(\d+);(\d+);(\d+)([Mm])$/.exec(data);
1810
+ if (mouse) {
1811
+ const button = Number(mouse[1]);
1812
+ const wheel = (button & 64) !== 0;
1813
+ const release = mouse[4] === "m" || !wheel && (button & 3) === 3 && !(button & 32);
1814
+ this.handleMouse({
1815
+ type: wheel ? "wheel" : release ? "release" : button & 32 ? "drag" : "press",
1816
+ button: wheel ? "none" : (button & 3) === 0 ? "left" : (button & 3) === 1 ? "middle" : (button & 3) === 2 ? "right" : "none",
1817
+ ...wheel ? { wheelDelta: (button & 1) === 0 ? -3 : 3 } : {},
1818
+ x: Number(mouse[2]) - 1,
1819
+ y: Number(mouse[3]) - 1,
1820
+ screenX: Number(mouse[2]) - 1,
1821
+ screenY: Number(mouse[3]) - 1,
1822
+ width: this.tui.terminal.columns,
1823
+ height: this.terminalRows(),
1824
+ shift: !!(button & 4),
1825
+ alt: !!(button & 8),
1826
+ ctrl: !!(button & 16)
1827
+ });
1828
+ return;
1829
+ }
1830
+ if (this.mode === "picker") {
1831
+ this.handlePickerInput(data);
1832
+ this.tui.requestRender();
1833
+ return;
1834
+ }
1835
+ this.handleConversationInput(data);
1836
+ this.tui.requestRender();
1837
+ }
1838
+ handleMouse(event) {
1839
+ if (this.disposed) return void 0;
1840
+ this.ensureEditorEpoch();
1841
+ this.updateTargets();
1842
+ if (event.type === "wheel") {
1843
+ if (this.mode === "picker") this.movePickerSelection((event.wheelDelta ?? 0) < 0 ? -1 : 1);
1844
+ else this.scrollBy(event.wheelDelta ?? 0);
1845
+ this.tui.requestRender();
1846
+ return { handled: true };
1847
+ }
1848
+ if (this.mode !== "conversation" || !this.currentId) return { handled: true };
1849
+ const entry = this.state.view(this.currentId);
1850
+ const inBody = event.y >= this.bodyTop && event.y < this.bodyTop + this.bodyHeight;
1851
+ const row = entry.scroll + Math.max(0, Math.min(this.bodyHeight - 1, event.y - this.bodyTop));
1852
+ if (event.type === "press" && event.button === "left" && inBody) {
1853
+ this.selectionWasFollowing = entry.following;
1854
+ entry.following = false;
1855
+ this.textSelection.start(this.lastBody, row, event.x);
1856
+ this.tui.requestRender();
1857
+ return { handled: true, capture: true };
1858
+ }
1859
+ if (this.textSelection.dragging && (event.type === "drag" || event.type === "release")) {
1860
+ if (event.type === "drag") this.textSelection.move(row, event.x);
1861
+ else {
1862
+ this.textSelection.finish(row, event.x);
1863
+ if (!this.textSelection.active && this.selectionWasFollowing) entry.following = true;
1864
+ if (this.textSelection.active && (this.options.appearance?.copyOnSelect ?? true)) this.copySelection();
1865
+ }
1866
+ this.tui.requestRender();
1867
+ return { handled: true, render: true };
1868
+ }
1869
+ if (event.type === "press") this.textSelection.clear();
1870
+ if (event.y >= this.editorTop && event.y < this.editorTop + this.editorHeight) {
1871
+ return this.editor?.handleMouse({ ...event, y: event.y - this.editorTop, height: this.editorHeight }) ?? { handled: true };
1872
+ }
1873
+ return { handled: true };
1874
+ }
1875
+ render(width) {
1876
+ if (this.disposed || width <= 0) return [];
1877
+ this.updateTargets();
1878
+ if (width !== this.selectionWidth) {
1879
+ this.textSelection.clear();
1880
+ this.selectionWidth = width;
1881
+ }
1882
+ const rows = Math.max(1, this.terminalRows());
1883
+ this.markCurrentTargetSeen();
1884
+ this.reconcileEditor();
1885
+ const target = this.currentTarget();
1886
+ const queue = this.mode === "conversation" ? this.currentQueue() : void 0;
1887
+ this.observe();
1888
+ const liveTranscriptLines = this.mode === "conversation" ? this.transcriptLines(width) : [];
1889
+ const transcriptLines = this.textSelection.source ?? liveTranscriptLines;
1890
+ let queueLines = queue?.render(width) ?? [];
1891
+ let editorLines = this.mode === "conversation" && !(queue?.editingActive && queue.mode === "extension") ? this.renderEditorLines(width) : [];
1892
+ const editorBudget = Math.min(editorLines.length, Math.max(1, rows - (rows >= 6 ? 3 : 0)));
1893
+ let editorShowsTopBorder = editorLines.length > 0;
1894
+ if (editorLines.length > editorBudget) {
1895
+ const cursor = Math.max(0, editorLines.findIndex((line) => line.includes(CURSOR_MARKER)));
1896
+ const start = Math.max(0, Math.min(cursor - Math.floor(editorBudget / 2), editorLines.length - editorBudget));
1897
+ editorShowsTopBorder = start === 0;
1898
+ editorLines = editorLines.slice(start, start + editorBudget);
1899
+ }
1900
+ let remaining = rows - editorLines.length;
1901
+ const footer = this.mode === "conversation" ? conversationFooter(target, this.theme, width).slice(0, Math.max(0, remaining - 1)) : [];
1902
+ remaining -= footer.length;
1903
+ const head = [];
1904
+ if (remaining > 0) {
1905
+ head.push(this.breadcrumbLine(width));
1906
+ remaining--;
1907
+ }
1908
+ const feedback = this.currentFeedbackLine(width);
1909
+ if (feedback !== void 0 && remaining > 1) {
1910
+ head.push(feedback);
1911
+ remaining--;
1912
+ }
1913
+ const hints = this.mode === "conversation" && remaining > 2 ? [this.hintsLine(width)] : [];
1914
+ remaining -= hints.length;
1915
+ const queueBudget = Math.max(0, remaining - 1);
1916
+ if (queueLines.length > queueBudget) {
1917
+ const cursor = queueLines.findIndex((line) => line.includes(CURSOR_MARKER));
1918
+ const start = Math.max(0, Math.min(cursor < 0 ? 0 : cursor - Math.floor(queueBudget / 2), queueLines.length - queueBudget));
1919
+ queueLines = queueLines.slice(start, start + queueBudget);
1920
+ }
1921
+ remaining -= queueLines.length;
1922
+ this.editorTop = rows - editorLines.length - footer.length - hints.length;
1923
+ this.editorHeight = editorLines.length;
1924
+ const body = remaining <= 0 ? [] : this.mode === "picker" ? this.pickerLines(width, remaining) : this.windowBody(transcriptLines, remaining, this.transcriptTail(width, remaining, editorShowsTopBorder));
1925
+ this.bodyTop = head.length;
1926
+ const scroll = this.currentId ? this.state.view(this.currentId).scroll : 0;
1927
+ this.bodyHeight = this.mode === "conversation" ? Math.max(0, Math.min(remaining, this.lastBody.length - scroll)) : 0;
1928
+ if (this.textSelection.active) {
1929
+ for (let row = 0; row < this.bodyHeight; row++) body[row] = this.textSelection.highlight(body[row], scroll + row, this.theme);
1930
+ }
1931
+ while (body.length < remaining) body.push("");
1932
+ return [...head, ...body.slice(0, remaining), ...queueLines, ...editorLines, ...footer, ...hints].slice(0, rows).map((line) => visibleWidth3(line) <= width ? line : truncateToWidth3(line, width, ""));
1933
+ }
1934
+ /** Observe files without rendering native history; true means a visible change
1935
+ * or a live animation still needs the normal TUI render path. */
1936
+ refresh() {
1937
+ if (this.disposed) return false;
1938
+ this.updateTargets();
1939
+ const changed = this.observe();
1940
+ return changed || this.mode === "conversation" && this.selectedTargetIsWorking();
1941
+ }
1942
+ observe() {
1943
+ const entry = this.currentId ? this.state.view(this.currentId) : void 0;
1944
+ const transcript = this.mode === "conversation" && this.currentTarget() && this.currentId && entry ? this.options.transcript(this.currentId, entry.following) : void 0;
1945
+ if (transcript && this.currentId) this.state.queues.sync(this.currentId, transcript);
1946
+ const key = JSON.stringify([
1947
+ this.targetsKey,
1948
+ this.currentId,
1949
+ this.mode,
1950
+ entry?.draft,
1951
+ this.feedback && Date.now() - this.feedback.at <= FEEDBACK_TTL_MS ? this.feedback : void 0,
1952
+ transcript && [
1953
+ transcript.sourceId,
1954
+ transcript.sessionId,
1955
+ transcript.sessionFile,
1956
+ transcript.eventsFile,
1957
+ transcript.revision,
1958
+ transcript.status,
1959
+ transcript.leafId,
1960
+ transcript.historyComplete,
1961
+ transcript.hasMore,
1962
+ transcript.hasNewer,
1963
+ transcript.unavailable,
1964
+ transcript.error,
1965
+ transcript.pendingMessages
1966
+ ]
1967
+ ]);
1968
+ const previous = this.observedTranscript;
1969
+ const changed = key !== this.observationKey || previous?.messages !== transcript?.messages || previous?.entries !== transcript?.entries || previous?.streaming !== transcript?.streaming;
1970
+ this.observationKey = key;
1971
+ this.observedTranscript = transcript;
1972
+ this.syncWorkingIndicator();
1973
+ return changed;
1974
+ }
1975
+ selectedTargetIsWorking() {
1976
+ const target = this.currentTarget();
1977
+ if (!target || target.stale) return false;
1978
+ return isActiveStatus(target.status);
1979
+ }
1980
+ syncWorkingIndicator() {
1981
+ const active = !this.disposed && this.mode === "conversation" && this.currentId && this.selectedTargetIsWorking();
1982
+ if (!active) {
1983
+ this.stopWorkingIndicator();
1984
+ return;
1985
+ }
1986
+ if (this.working && this.workingTargetId === this.currentId) return;
1987
+ this.stopWorkingIndicator();
1988
+ const id = this.currentId;
1989
+ this.workingTargetId = id;
1990
+ const color = (text) => this.editor?.borderColor(text) ?? this.theme.fg("borderMuted", text);
1991
+ this.working = new BorderWorkingIndicator({ requestRender: () => {
1992
+ if (!this.disposed && this.mode === "conversation" && this.currentId === id) this.tui.requestRender();
1993
+ } }, color, "Working");
1994
+ this.attachWorkingIndicator();
1995
+ }
1996
+ /** Every editor instance that can be mounted (composer, suspended queue-row
1997
+ * composer) carries the live indicator, and nothing keeps a stale one. */
1998
+ attachWorkingIndicator() {
1999
+ this.editor?.setWorkingStatusIndicator(this.working);
2000
+ this.suspendedEditor?.setWorkingStatusIndicator(this.working);
2001
+ }
2002
+ stopWorkingIndicator() {
2003
+ this.working?.stop();
2004
+ this.working = void 0;
2005
+ this.workingTargetId = void 0;
2006
+ this.attachWorkingIndicator();
2007
+ }
2008
+ invalidate() {
2009
+ this.working?.invalidate();
2010
+ this.commandNotification?.component.invalidate();
2011
+ this.commandNotification?.pendingResult?.invalidate();
2012
+ this.renderer.invalidate();
2013
+ this.editor?.invalidate();
2014
+ this.pickerInput?.invalidate();
2015
+ }
2016
+ dispose() {
2017
+ if (this.currentId) this.state.queues.detach(this.currentId);
2018
+ this.disposed = true;
2019
+ this.clearCommandNotification();
2020
+ this.copyVersion++;
2021
+ this.textSelection.clear();
2022
+ this.stopWorkingIndicator();
2023
+ this.releaseEditor(this.editor);
2024
+ this.releaseEditor(this.suspendedEditor);
2025
+ this.suspendedEditor = void 0;
2026
+ this.editor = void 0;
2027
+ this.pickerInput = void 0;
2028
+ this.observedTranscript = void 0;
2029
+ this.lastBody = [];
2030
+ this.renderer.dispose();
2031
+ if (this.ownsMouseMode) {
2032
+ this.ownsMouseMode = false;
2033
+ this.tui.terminal.write("\x1B[?1002l\x1B[?1000l\x1B[?1006l");
2034
+ }
2035
+ }
2036
+ /** Keep the editor in sync with the shared session draft (e.g. after an ack
2037
+ * that landed while a previous view instance was disposed). */
2038
+ reconcileEditor() {
2039
+ this.ensureEditorEpoch();
2040
+ if (this.mode !== "conversation" || !this.editor || !this.currentId) return;
2041
+ if (this.state.queues.get(this.currentId)?.editingActive) return;
2042
+ if (this.state.hasPendingSend(this.currentId, this.editor.getText())) return;
2043
+ const draft = this.state.view(this.currentId).draft;
2044
+ if (this.editor.getText() !== draft) this.editor.setText(draft);
2045
+ }
2046
+ applySelection(id, requestRender) {
2047
+ if (this.currentId && this.currentId !== id) this.state.queues.detach(this.currentId);
2048
+ const target = this.targetById(id);
2049
+ if (!target) {
2050
+ this.feedback = {
2051
+ text: `Unknown target ${safeText(id)}`,
2052
+ kind: "error",
2053
+ at: Date.now()
2054
+ };
2055
+ if (requestRender) this.tui.requestRender();
2056
+ return;
2057
+ }
2058
+ if (isMainTarget(target)) {
2059
+ this.options.close();
2060
+ return;
2061
+ }
2062
+ const changed = this.currentId !== id;
2063
+ if (changed) {
2064
+ this.clearCommandNotification();
2065
+ this.copyVersion++;
2066
+ this.textSelection.clear();
2067
+ this.stopWorkingIndicator();
2068
+ this.observedTranscript = void 0;
2069
+ this.observationKey = "";
2070
+ this.lastBody = [];
2071
+ this.lastBodyLength = 0;
2072
+ this.renderer.invalidate();
2073
+ this.options.onTargetChange?.(id);
2074
+ }
2075
+ this.currentId = id;
2076
+ this.state.selectedId = id;
2077
+ if (changed) this.resetEditor();
2078
+ const entry = this.state.view(id);
2079
+ entry.lastSeenUpdatedAt = target.updatedAt ?? Date.now();
2080
+ this.stopConfirmId = void 0;
2081
+ this.closePicker();
2082
+ this.feedback = void 0;
2083
+ this.editor?.setText(entry.draft);
2084
+ if (requestRender) this.tui.requestRender();
2085
+ }
2086
+ markCurrentTargetSeen() {
2087
+ if (!this.currentId) return;
2088
+ const target = this.targetById(this.currentId);
2089
+ if (!target?.updatedAt) return;
2090
+ const entry = this.state.view(this.currentId);
2091
+ if (entry.lastSeenUpdatedAt < target.updatedAt) entry.lastSeenUpdatedAt = target.updatedAt;
2092
+ }
2093
+ updateTargets() {
2094
+ const targets = this.options.targets();
2095
+ const key = JSON.stringify(targets);
2096
+ if (key === this.targetsKey) return;
2097
+ this.targetsKey = key;
2098
+ this.targets = targets;
2099
+ this.targetsById.clear();
2100
+ for (const target of targets) {
2101
+ if (!this.targetsById.has(target.id)) this.targetsById.set(target.id, target);
2102
+ }
2103
+ this.nonMain = targets.filter((target) => !isMainTarget(target));
2104
+ this.main = targets.find(isMainTarget);
2105
+ }
2106
+ currentTargets() {
2107
+ return this.targets;
2108
+ }
2109
+ nonMainTargets() {
2110
+ return this.nonMain;
2111
+ }
2112
+ currentTarget() {
2113
+ return this.currentId ? this.targetById(this.currentId) : void 0;
2114
+ }
2115
+ mainTarget() {
2116
+ return this.main;
2117
+ }
2118
+ targetById(id) {
2119
+ return this.targetsById.get(id);
2120
+ }
2121
+ terminalRows() {
2122
+ return this.tui.terminal?.rows ?? process.stdout.rows ?? 28;
2123
+ }
2124
+ /**
2125
+ * Respects a configured binding; when an injected manager reports no keys
2126
+ * the binding is unbound (never falls back), and only the default global
2127
+ * manager (no injection) falls back to hard-coded keys.
2128
+ */
2129
+ bindingMatches(data, binding, fallbackKeys) {
2130
+ if (this.options.keybindings) {
2131
+ const keys2 = this.options.keybindings.getKeys(binding);
2132
+ return keys2.length > 0 && this.options.keybindings.matches(data, binding);
2133
+ }
2134
+ const global = getKeybindings2();
2135
+ const keys = global.getKeys(binding);
2136
+ if (keys.length > 0) return global.matches(data, binding);
2137
+ return fallbackKeys.some((key) => matchesKey2(data, key));
2138
+ }
2139
+ bindingHint(binding, fallbackLabel) {
2140
+ const manager = this.options.keybindings ?? getKeybindings2();
2141
+ const keys = manager.getKeys(binding);
2142
+ if (keys.length > 0) return keys.join("/");
2143
+ return this.options.keybindings ? "unbound" : fallbackLabel;
2144
+ }
2145
+ handleConversationInput(data) {
2146
+ const editor = this.editor;
2147
+ if (!editor) return;
2148
+ this.feedback = void 0;
2149
+ if (this.stopConfirmId === void 0 && this.bindingMatches(data, "app.message.copy", ["ctrl+shift+c"])) {
2150
+ this.copyResponse(void 0, true);
2151
+ return;
2152
+ }
2153
+ if (this.stopConfirmId === void 0 && this.textSelection.active && matchesKey2(data, Key2.ctrl("c"))) {
2154
+ this.copySelection();
2155
+ return;
2156
+ }
2157
+ if (this.stopConfirmId === void 0 && this.textSelection.source && matchesKey2(data, Key2.escape)) {
2158
+ this.textSelection.clear();
2159
+ return;
2160
+ }
2161
+ const queue = this.currentQueue();
2162
+ if (this.stopConfirmId === void 0 && !queue?.editingActive && editor.isShowingAutocomplete() && [Key2.enter, Key2.tab, Key2.up, Key2.down, Key2.escape].some((key) => matchesKey2(data, key))) {
2163
+ editor.handleInput(data);
2164
+ return;
2165
+ }
2166
+ if (this.stopConfirmId === void 0 && queue?.handleInput(data)) return;
2167
+ if (this.stopConfirmId !== void 0) {
2168
+ if (matchesKey2(data, Key2.enter)) {
2169
+ const target = this.targetById(this.stopConfirmId);
2170
+ this.stopConfirmId = void 0;
2171
+ if (target) this.dispatchStop(target);
2172
+ return;
2173
+ }
2174
+ if (matchesKey2(data, Key2.escape)) {
2175
+ this.stopConfirmId = void 0;
2176
+ this.notifyCommand("Stop cancelled");
2177
+ return;
2178
+ }
2179
+ this.stopConfirmId = void 0;
2180
+ this.notifyCommand("Stop cancelled");
2181
+ }
2182
+ if (this.bindingMatches(data, "app.message.followUp", FOLLOW_UP_FALLBACK)) {
2183
+ this.submit("followUp");
2184
+ return;
2185
+ }
2186
+ if (matchesKey2(data, Key2.enter)) {
2187
+ this.submit("steer");
2188
+ return;
2189
+ }
2190
+ if (matchesKey2(data, Key2.ctrl("c"))) {
2191
+ if (editor.getText().length > 0) editor.setText("");
2192
+ return;
2193
+ }
2194
+ if (matchesKey2(data, Key2.escape)) {
2195
+ this.options.close();
2196
+ return;
2197
+ }
2198
+ if (matchesKey2(data, Key2.ctrl("n"))) {
2199
+ this.openPicker();
2200
+ return;
2201
+ }
2202
+ if (matchesKey2(data, "ctrl+tab")) {
2203
+ this.cycleTarget(1);
2204
+ return;
2205
+ }
2206
+ if (matchesKey2(data, "shift+ctrl+tab")) {
2207
+ this.cycleTarget(-1);
2208
+ return;
2209
+ }
2210
+ if (matchesKey2(data, "ctrl+shift+left")) {
2211
+ this.navigateParent();
2212
+ return;
2213
+ }
2214
+ if (matchesKey2(data, "ctrl+shift+right")) {
2215
+ this.navigateFirstChild();
2216
+ return;
2217
+ }
2218
+ if (matchesKey2(data, "alt+left") && editor.getText().length === 0) {
2219
+ this.navigateParent();
2220
+ return;
2221
+ }
2222
+ if (matchesKey2(data, "alt+right") && editor.getText().length === 0) {
2223
+ this.navigateFirstChild();
2224
+ return;
2225
+ }
2226
+ const viewportKeys = getKeybindings2();
2227
+ if (viewportKeys.matches(data, "tui.altScreen.previousPrompt")) {
2228
+ this.scrollPrompt(-1);
2229
+ return;
2230
+ }
2231
+ if (viewportKeys.matches(data, "tui.altScreen.nextPrompt")) {
2232
+ this.scrollPrompt(1);
2233
+ return;
2234
+ }
2235
+ if (viewportKeys.matches(data, "tui.altScreen.lineUp")) {
2236
+ this.scrollBy(-1);
2237
+ return;
2238
+ }
2239
+ if (viewportKeys.matches(data, "tui.altScreen.lineDown")) {
2240
+ this.scrollBy(1);
2241
+ return;
2242
+ }
2243
+ if (viewportKeys.matches(data, "tui.altScreen.pageUp")) {
2244
+ this.scrollBy(-Math.max(1, this.lastBodyBudget - 2));
2245
+ return;
2246
+ }
2247
+ if (viewportKeys.matches(data, "tui.altScreen.pageDown")) {
2248
+ this.scrollBy(Math.max(1, this.lastBodyBudget - 2));
2249
+ return;
2250
+ }
2251
+ if (viewportKeys.matches(data, "tui.altScreen.halfPageUp")) {
2252
+ this.scrollBy(-Math.max(1, Math.floor(this.lastBodyBudget / 2)));
2253
+ return;
2254
+ }
2255
+ if (viewportKeys.matches(data, "tui.altScreen.halfPageDown")) {
2256
+ this.scrollBy(Math.max(1, Math.floor(this.lastBodyBudget / 2)));
2257
+ return;
2258
+ }
2259
+ if (viewportKeys.matches(data, "tui.altScreen.top")) {
2260
+ this.scrollToTop();
2261
+ return;
2262
+ }
2263
+ if (viewportKeys.matches(data, "tui.altScreen.bottom")) {
2264
+ this.followLatest();
2265
+ return;
2266
+ }
2267
+ if (this.bindingMatches(data, "app.thinking.toggle", ["ctrl+t"])) {
2268
+ this.textSelection.clear();
2269
+ if (this.currentId) {
2270
+ const entry = this.state.view(this.currentId);
2271
+ entry.hideThinking = !(entry.hideThinking ?? this.options.appearance?.hideThinkingBlock ?? false);
2272
+ }
2273
+ return;
2274
+ }
2275
+ if (this.bindingMatches(data, "app.tools.expand", TOOLS_EXPAND_FALLBACK)) {
2276
+ this.textSelection.clear();
2277
+ if (this.currentId) {
2278
+ const entry = this.state.view(this.currentId);
2279
+ entry.toolsExpanded = !entry.toolsExpanded;
2280
+ }
2281
+ return;
2282
+ }
2283
+ if (viewportKeys.matches(data, "tui.editor.cursorUp") || viewportKeys.matches(data, "tui.editor.cursorDown") || viewportKeys.matches(data, "tui.editor.historyPrevious") || viewportKeys.matches(data, "tui.editor.historyNext")) this.initializePromptHistory();
2284
+ editor.handleInput(data);
2285
+ }
2286
+ clearCommandNotification() {
2287
+ this.commandNotification = void 0;
2288
+ this.notificationScope++;
2289
+ }
2290
+ notifyCommand(message, kind = "info", options = {}) {
2291
+ if (this.disposed || this.mode !== "conversation" || !this.currentId || !this.currentTarget()) return;
2292
+ this.feedback = void 0;
2293
+ const text = safeText(message).slice(0, 4096);
2294
+ this.commandNotification = {
2295
+ component: new Text(
2296
+ this.theme.fg(kind === "error" ? "error" : "dim", kind === "error" ? `Error: ${text}` : text),
2297
+ kind === "error" ? this.options.appearance?.outputPad ?? 1 : 1,
2298
+ 0
2299
+ ),
2300
+ epoch: this.state.epoch,
2301
+ ...options.reserve !== void 0 ? { pendingResult: new Text(this.theme.fg("dim", safeText(options.reserve).slice(0, 4096)), 1, 0) } : {}
2302
+ };
2303
+ if (options.reveal !== false) {
2304
+ const entry = this.state.view(this.currentId);
2305
+ entry.pageAnchor = entry.following ? void 0 : "end";
2306
+ entry.anchorLength = void 0;
2307
+ }
2308
+ this.tui.requestRender();
2309
+ }
2310
+ copyFeedback(text, kind, command, reveal = true) {
2311
+ if (command !== void 0) this.notifyCommand(text, kind, { reveal });
2312
+ else {
2313
+ if (this.commandNotification?.pendingResult) this.clearCommandNotification();
2314
+ this.feedback = { text: safeText(text), kind, at: Date.now() };
2315
+ }
2316
+ }
2317
+ copySelection(command) {
2318
+ const text = this.textSelection.text();
2319
+ if (!text) {
2320
+ this.copyFeedback("No transcript text selected. Drag to select first.", "error", command);
2321
+ return;
2322
+ }
2323
+ this.copyText(text, "Copied selected transcript text", command);
2324
+ }
2325
+ copyResponse(command, preferSelection = false) {
2326
+ if (preferSelection && this.textSelection.active) {
2327
+ this.copySelection(command);
2328
+ return;
2329
+ }
2330
+ if (!this.currentId) return;
2331
+ const transcript = this.options.transcript(this.currentId, false);
2332
+ if (transcript.hasNewer) {
2333
+ this.copyFeedback("Use /latest before /copy to load the latest response.", "error", command);
2334
+ return;
2335
+ }
2336
+ const text = conversationAssistantText(transcript);
2337
+ if (!text) {
2338
+ this.copyFeedback("No assistant response to copy yet.", "error", command);
2339
+ return;
2340
+ }
2341
+ this.copyText(text, "Copied last assistant response", command);
2342
+ }
2343
+ copyText(text, message, command) {
2344
+ const id = this.currentId;
2345
+ const epoch = this.state.epoch;
2346
+ const version = ++this.copyVersion;
2347
+ const editor = this.editor;
2348
+ if (command !== void 0) this.notifyCommand("Copying\u2026", "info", { reserve: message });
2349
+ const notification = this.commandNotification;
2350
+ const current = () => !this.disposed && this.currentId === id && this.state.epoch === epoch && this.copyVersion === version;
2351
+ const currentResult = () => current() && (command === void 0 || this.commandNotification === notification);
2352
+ this.copyTask = this.copyTask.then(() => {
2353
+ if (current()) return (this.options.copyToClipboard ?? getConversationHost().copyToClipboard)(text);
2354
+ }).then(() => {
2355
+ if (!currentResult()) return;
2356
+ if (command !== void 0 && id) {
2357
+ if (this.state.peek(id)?.draft === command) this.state.view(id).draft = "";
2358
+ if (editor?.getText() === command) editor.setText("");
2359
+ }
2360
+ this.copyFeedback(message, "info", command, false);
2361
+ this.tui.requestRender();
2362
+ }, (error) => {
2363
+ if (!currentResult()) return;
2364
+ this.copyFeedback(`Copy failed: ${errorText2(error)}`, "error", command, false);
2365
+ this.tui.requestRender();
2366
+ });
2367
+ }
2368
+ submit(delivery) {
2369
+ const editor = this.editor;
2370
+ const target = this.currentTarget();
2371
+ if (!editor || !target || isMainTarget(target)) return;
2372
+ const raw = editor.getText();
2373
+ const message = editor.getExpandedText();
2374
+ if (!message.trim()) return;
2375
+ const command = message.trim().replace(/[\t ]+/g, " ");
2376
+ if (command.startsWith("/")) this.rememberPrompt(message);
2377
+ if (command === "/copy") {
2378
+ this.copyResponse(raw);
2379
+ return;
2380
+ }
2381
+ if (command === "/copy selection") {
2382
+ this.copySelection(raw);
2383
+ return;
2384
+ }
2385
+ if (command === "/help") {
2386
+ editor.setText("");
2387
+ this.notifyCommand(CONVERSATION_COMMAND_HELP);
2388
+ return;
2389
+ }
2390
+ if (command === "/latest") {
2391
+ editor.setText("");
2392
+ this.followLatest();
2393
+ this.notifyCommand("Following latest output");
2394
+ return;
2395
+ }
2396
+ if (command === "/back") {
2397
+ this.options.close();
2398
+ return;
2399
+ }
2400
+ if (command === "/agents") {
2401
+ this.openPicker();
2402
+ return;
2403
+ }
2404
+ if (command === "/stop") {
2405
+ if (!target.canStop) {
2406
+ this.notifyCommand(`Stop unavailable for ${target.name}: the selected target cannot be stopped from here.`, "error");
2407
+ return;
2408
+ }
2409
+ this.stopConfirmId = target.id;
2410
+ this.notifyCommand(`Press enter again to stop ${target.name} \xB7 esc cancels`);
2411
+ return;
2412
+ }
2413
+ if (message.trim().startsWith("/") || message.trim().startsWith("!")) {
2414
+ this.notifyCommand(`Unsupported command "${message.trim()}" is not forwarded from this view. Use /help for preview commands.`, "error");
2415
+ return;
2416
+ }
2417
+ if (target.readOnlyReason) {
2418
+ this.feedback = {
2419
+ text: safeText(`${target.name} is read-only: ${target.readOnlyReason}`),
2420
+ kind: "error",
2421
+ at: Date.now()
2422
+ };
2423
+ return;
2424
+ }
2425
+ if (delivery === "steer" && !target.canSteer) {
2426
+ this.feedback = {
2427
+ text: safeText(`${target.name} does not accept steering messages right now.`),
2428
+ kind: "error",
2429
+ at: Date.now()
2430
+ };
2431
+ return;
2432
+ }
2433
+ if (delivery === "followUp" && !target.canFollowUp) {
2434
+ this.feedback = {
2435
+ text: safeText(`${target.name} does not accept follow-up messages right now.`),
2436
+ kind: "error",
2437
+ at: Date.now()
2438
+ };
2439
+ return;
2440
+ }
2441
+ const queue = this.currentQueue();
2442
+ if (!queue) return;
2443
+ this.textSelection.clear();
2444
+ this.state.queues.sync(target.id, this.options.transcript(target.id, true));
2445
+ if (queue.mode === "extension" && delivery === "followUp" && !isActiveStatus(target.status)) {
2446
+ const parked = queue.park(message, delivery);
2447
+ if (parked.ok) {
2448
+ this.rememberPrompt(message);
2449
+ this.state.view(target.id).draft = "";
2450
+ editor.setText("");
2451
+ }
2452
+ return;
2453
+ }
2454
+ if (this.state.hasPendingSend(target.id, raw)) return;
2455
+ this.rememberPrompt(message);
2456
+ const pending = { id: target.id, message: raw, delivery };
2457
+ this.state.addPendingSend(pending);
2458
+ const epoch = this.state.epoch;
2459
+ this.feedback = {
2460
+ text: safeText(`Sending ${delivery} \u2192 ${target.name}\u2026`),
2461
+ kind: "info",
2462
+ at: Date.now()
2463
+ };
2464
+ void Promise.resolve().then(() => queue.dispatch(message, delivery)).then(() => {
2465
+ if (this.state.epoch !== epoch) return;
2466
+ this.state.resolvePendingSend(target.id, raw);
2467
+ if (this.disposed) return;
2468
+ if (this.currentId === target.id && this.editor === editor && editor.getText() === raw) {
2469
+ editor.setText("");
2470
+ }
2471
+ this.feedback = {
2472
+ text: safeText(`Queued ${delivery} \u2192 ${target.name}`),
2473
+ kind: "info",
2474
+ at: Date.now()
2475
+ };
2476
+ this.tui.requestRender();
2477
+ }).catch((error) => {
2478
+ if (this.state.epoch !== epoch) return;
2479
+ this.state.failPendingSend(target.id, raw);
2480
+ if (this.disposed) return;
2481
+ this.feedback = {
2482
+ text: safeText(
2483
+ `Send failed for ${target.name} (${delivery}): ${errorText2(error)}`
2484
+ ),
2485
+ kind: "error",
2486
+ at: Date.now()
2487
+ };
2488
+ this.tui.requestRender();
2489
+ });
2490
+ }
2491
+ dispatchStop(target) {
2492
+ const epoch = this.state.epoch;
2493
+ const scope = this.notificationScope;
2494
+ const current = () => !this.disposed && epoch === this.state.epoch && scope === this.notificationScope && this.currentId === target.id;
2495
+ this.notifyCommand(`Stopping ${target.name}\u2026`);
2496
+ void Promise.resolve().then(() => this.options.stop(target.id)).then(() => {
2497
+ if (current()) this.notifyCommand(`Stop requested for ${target.name}`);
2498
+ }).catch((error) => {
2499
+ if (current()) this.notifyCommand(`Stop failed for ${target.name}: ${errorText2(error)}`, "error");
2500
+ });
2501
+ }
2502
+ navigateParent() {
2503
+ const target = this.currentTarget();
2504
+ if (!target) return;
2505
+ const parent = target.parentId ? this.targetById(target.parentId) : void 0;
2506
+ if (parent && !isMainTarget(parent)) {
2507
+ this.applySelection(parent.id, true);
2508
+ return;
2509
+ }
2510
+ this.options.close();
2511
+ }
2512
+ navigateFirstChild() {
2513
+ const target = this.currentTarget();
2514
+ if (!target) return;
2515
+ const child = this.currentTargets().find((candidate) => candidate.parentId === target.id);
2516
+ if (child && !isMainTarget(child)) this.applySelection(child.id, true);
2517
+ }
2518
+ cycleTarget(direction) {
2519
+ const targets = this.nonMainTargets();
2520
+ if (targets.length === 0) return;
2521
+ const index = targets.findIndex((target) => target.id === this.currentId);
2522
+ const nextIndex = index < 0 ? 0 : (index + direction + targets.length) % targets.length;
2523
+ const next = targets[nextIndex];
2524
+ if (next) this.applySelection(next.id, true);
2525
+ }
2526
+ scrollBy(delta) {
2527
+ if (!this.currentId || !Number.isFinite(delta) || delta === 0) return;
2528
+ if (!this.textSelection.dragging) this.textSelection.clear();
2529
+ const entry = this.state.view(this.currentId);
2530
+ const maxScroll = Math.max(0, this.lastBodyLength - this.lastBodyBudget);
2531
+ const position = entry.following ? maxScroll : entry.scroll;
2532
+ if (entry.pageAnchor === "end") entry.pageAnchor = void 0;
2533
+ if (entry.following && delta > 0) return;
2534
+ const next = position + Math.trunc(delta);
2535
+ entry.following = false;
2536
+ if (next < 0 && !this.textSelection.dragging && this.options.loadOlder(this.currentId)) {
2537
+ entry.pageAnchor = "prepend";
2538
+ entry.anchorLength = this.lastBody.length;
2539
+ entry.scroll = next;
2540
+ return;
2541
+ }
2542
+ if (next > maxScroll && !this.textSelection.dragging && this.options.loadNewer(this.currentId)) {
2543
+ entry.scroll = next;
2544
+ return;
2545
+ }
2546
+ entry.scroll = Math.max(0, Math.min(next, maxScroll));
2547
+ if (delta > 0 && entry.scroll === maxScroll) entry.following = true;
2548
+ }
2549
+ scrollPrompt(direction) {
2550
+ if (!this.currentId) return;
2551
+ const entry = this.state.view(this.currentId);
2552
+ const position = entry.following ? Math.max(0, this.lastBodyLength - this.lastBodyBudget) : entry.scroll;
2553
+ const prompts = this.lastBody.flatMap((line, index) => line.includes("\x1B]133;A") ? [index] : []);
2554
+ const target = direction < 0 ? prompts.filter((row) => row < position).at(-1) : prompts.find((row) => row > position);
2555
+ this.scrollBy(target === void 0 ? direction * Math.max(1, this.lastBodyBudget) : target - position);
2556
+ }
2557
+ scrollToTop() {
2558
+ if (!this.currentId) return;
2559
+ this.textSelection.clear();
2560
+ const entry = this.state.view(this.currentId);
2561
+ entry.following = false;
2562
+ entry.scroll = 0;
2563
+ if (this.options.loadOlder(this.currentId)) entry.pageAnchor = "start";
2564
+ }
2565
+ followLatest() {
2566
+ this.textSelection.clear();
2567
+ if (!this.currentId) return;
2568
+ this.options.loadLatest(this.currentId);
2569
+ const entry = this.state.view(this.currentId);
2570
+ entry.following = true;
2571
+ entry.pageAnchor = void 0;
2572
+ entry.anchorLength = void 0;
2573
+ }
2574
+ openPicker() {
2575
+ this.clearCommandNotification();
2576
+ this.copyVersion++;
2577
+ this.textSelection.clear();
2578
+ this.stopWorkingIndicator();
2579
+ this.mode = "picker";
2580
+ this.pickerInput = new Input({ prompt: "search targets: " });
2581
+ this.pickerInput.focused = this.focusState;
2582
+ this.pickerInput.onSubmit = () => this.pickSelected();
2583
+ if (this.editor) this.editor.focused = false;
2584
+ this.pickerSelectedId = this.currentId ?? this.nonMainTargets()[0]?.id;
2585
+ this.refreshPicker();
2586
+ }
2587
+ closePicker() {
2588
+ this.mode = "conversation";
2589
+ this.pickerInput = void 0;
2590
+ this.pickerRows = [];
2591
+ this.pickerKey = "";
2592
+ this.pickerSelectedId = void 0;
2593
+ if (this.editor) this.editor.focused = this.focusState;
2594
+ }
2595
+ refreshPicker() {
2596
+ const search = this.pickerInput?.getValue() ?? "";
2597
+ const key = JSON.stringify([this.targetsKey, search]);
2598
+ if (key === this.pickerKey) return;
2599
+ this.pickerKey = key;
2600
+ const rows = [];
2601
+ const targets = this.currentTargets();
2602
+ const children = /* @__PURE__ */ new Map();
2603
+ for (const target of targets) {
2604
+ if (!target.parentId) continue;
2605
+ const siblings = children.get(target.parentId) ?? [];
2606
+ siblings.push(target);
2607
+ children.set(target.parentId, siblings);
2608
+ }
2609
+ const roots = targets.filter(
2610
+ (target) => !target.parentId || !this.targetsById.has(target.parentId)
2611
+ );
2612
+ roots.sort(
2613
+ (left, right) => Number(isMainTarget(right)) - Number(isMainTarget(left))
2614
+ );
2615
+ const visited = /* @__PURE__ */ new Set();
2616
+ const pushTree = (target, depth) => {
2617
+ if (visited.has(target.id)) return;
2618
+ visited.add(target.id);
2619
+ rows.push({ target, depth });
2620
+ for (const child of children.get(target.id) ?? []) pushTree(child, depth + 1);
2621
+ };
2622
+ for (const root of roots) pushTree(root, 0);
2623
+ for (const orphan of targets) {
2624
+ if (!visited.has(orphan.id)) rows.push({ target: orphan, depth: 0 });
2625
+ }
2626
+ const filtered = search.trim() ? fuzzyFilter(rows, search, (row) => `${row.target.kind} ${row.target.name} ${row.target.id}`) : rows;
2627
+ this.pickerRows = filtered;
2628
+ if (!filtered.some((row) => row.target.id === this.pickerSelectedId)) {
2629
+ this.pickerSelectedId = filtered[0]?.target.id;
2630
+ }
2631
+ }
2632
+ pickerSelectedIndex() {
2633
+ const index = this.pickerRows.findIndex((row) => row.target.id === this.pickerSelectedId);
2634
+ return index >= 0 ? index : 0;
2635
+ }
2636
+ movePickerSelection(direction) {
2637
+ if (this.pickerRows.length === 0) return;
2638
+ const index = this.pickerSelectedIndex();
2639
+ const next = (index + direction + this.pickerRows.length) % this.pickerRows.length;
2640
+ this.pickerSelectedId = this.pickerRows[next]?.target.id;
2641
+ }
2642
+ pickSelected() {
2643
+ const row = this.pickerRows.find((candidate) => candidate.target.id === this.pickerSelectedId) ?? this.pickerRows[0];
2644
+ if (!row) {
2645
+ this.closePicker();
2646
+ return;
2647
+ }
2648
+ if (isMainTarget(row.target)) {
2649
+ this.options.close();
2650
+ return;
2651
+ }
2652
+ this.applySelection(row.target.id, true);
2653
+ }
2654
+ handlePickerInput(data) {
2655
+ const input = this.pickerInput;
2656
+ if (!input) {
2657
+ this.closePicker();
2658
+ return;
2659
+ }
2660
+ if (matchesKey2(data, Key2.escape)) {
2661
+ this.closePicker();
2662
+ return;
2663
+ }
2664
+ if (matchesKey2(data, Key2.up)) {
2665
+ this.movePickerSelection(-1);
2666
+ return;
2667
+ }
2668
+ if (matchesKey2(data, Key2.down)) {
2669
+ this.movePickerSelection(1);
2670
+ return;
2671
+ }
2672
+ if (matchesKey2(data, Key2.enter)) {
2673
+ this.pickSelected();
2674
+ return;
2675
+ }
2676
+ input.handleInput(data);
2677
+ this.refreshPicker();
2678
+ }
2679
+ isUnread(target) {
2680
+ if (target.updatedAt === void 0 || target.id === this.currentId) return false;
2681
+ const seen = this.state.peek(target.id)?.lastSeenUpdatedAt ?? 0;
2682
+ return target.updatedAt > seen;
2683
+ }
2684
+ breadcrumbLine(width) {
2685
+ const chain = [];
2686
+ let cursor = this.currentTarget();
2687
+ const guard = /* @__PURE__ */ new Set();
2688
+ while (cursor && !guard.has(cursor.id)) {
2689
+ guard.add(cursor.id);
2690
+ chain.unshift(cursor);
2691
+ cursor = cursor.parentId ? this.targetById(cursor.parentId) : void 0;
2692
+ }
2693
+ if (chain.length === 0) {
2694
+ const main = this.mainTarget();
2695
+ if (main) chain.push(main);
2696
+ }
2697
+ if (chain.length === 0) return truncateToWidth3(this.theme.fg("dim", "Fabric"), width, "");
2698
+ const last = chain[chain.length - 1];
2699
+ const parts = chain.map((target, index) => {
2700
+ const isCurrent = target.id === this.currentId;
2701
+ const name = isMainTarget(target) ? "Main" : safeText(target.name) || target.id;
2702
+ const styled = isCurrent ? this.theme.fg("accent", name) : this.theme.fg("muted", name);
2703
+ return last && index === chain.length - 1 && this.isUnread(last) ? `${styled} \u25CF` : styled;
2704
+ });
2705
+ return truncateToWidth3(parts.join(this.theme.fg("dim", " > ")), width, "");
2706
+ }
2707
+ currentFeedbackLine(width) {
2708
+ if (this.mode === "picker") return void 0;
2709
+ if (!this.feedback) return void 0;
2710
+ if (Date.now() - this.feedback.at > FEEDBACK_TTL_MS) return void 0;
2711
+ const color = this.feedback.kind === "error" ? "error" : "accent";
2712
+ return truncateToWidth3(this.theme.fg(color, this.feedback.text), width, "");
2713
+ }
2714
+ hintsLine(width) {
2715
+ const followUpKeys = this.bindingHint("app.message.followUp", "alt+enter");
2716
+ const toolsKeys = this.bindingHint("app.tools.expand", "ctrl+o");
2717
+ const hints = this.stopConfirmId !== void 0 ? [this.theme.fg("warning", safeText("enter confirms stop \xB7 esc cancels"))] : [
2718
+ this.theme.fg("dim", "enter"),
2719
+ "steer",
2720
+ this.theme.fg("dim", followUpKeys),
2721
+ "follow-up",
2722
+ this.theme.fg("dim", "ctrl+n"),
2723
+ "targets",
2724
+ this.theme.fg("dim", "pgup/pgdn"),
2725
+ "scroll \xB7 drag select \xB7 /help",
2726
+ this.theme.fg("dim", "esc"),
2727
+ "close"
2728
+ ];
2729
+ const full = [...hints, this.theme.fg("dim", toolsKeys), "tools"].join(" ");
2730
+ return truncateToWidth3(full, width, "");
2731
+ }
2732
+ renderEditorLines(innerWidth) {
2733
+ const editor = this.editor;
2734
+ if (!editor) return [];
2735
+ return editor.render(innerWidth);
2736
+ }
2737
+ currentQueue() {
2738
+ const target = this.currentTarget();
2739
+ if (!target || target.kind === "main" || !this.editor || this.disposed) return void 0;
2740
+ return this.state.queues.attach({
2741
+ targetId: target.id,
2742
+ targetName: target.name,
2743
+ piEvents: this.options.queueEvents ?? { emit() {
2744
+ } },
2745
+ theme: this.theme,
2746
+ send: (message, delivery) => {
2747
+ if (message.trimStart().startsWith("/") || message.trimStart().startsWith("!")) {
2748
+ return Promise.reject(new Error("Commands cannot be sent from queued edits; use the preview composer."));
2749
+ }
2750
+ return this.options.send(target.id, message, delivery);
2751
+ },
2752
+ editor: {
2753
+ getText: () => this.editor?.getText() ?? "",
2754
+ setText: (text) => this.setQueueEditorText(text),
2755
+ handleInput: (data) => this.editor?.handleInput(data),
2756
+ render: (width) => this.editor?.render(width) ?? [],
2757
+ paddingX: this.options.appearance?.editorPaddingX ?? 0
2758
+ },
2759
+ ...this.options.keybindings ? { keybindings: this.options.keybindings } : {},
2760
+ isIdle: () => !isActiveStatus(this.targetById(target.id)?.status ?? "stopped"),
2761
+ onNotify: (text, kind) => {
2762
+ if (kind === "error" && !this.disposed && this.currentId === target.id) this.feedback = { text: safeText(text), kind, at: Date.now() };
2763
+ },
2764
+ requestRender: () => {
2765
+ if (!this.disposed && this.currentId === target.id) this.tui.requestRender();
2766
+ }
2767
+ });
2768
+ }
2769
+ transcriptLines(innerWidth) {
2770
+ const target = this.currentTarget();
2771
+ if (!target || !this.currentId) return [this.theme.fg("dim", "No target selected.")];
2772
+ const entry = this.state.view(this.currentId);
2773
+ const transcript = this.observedTranscript ?? this.options.transcript(this.currentId, entry.following);
2774
+ return this.renderer.render(transcript, innerWidth, {
2775
+ target,
2776
+ toolsExpanded: entry.toolsExpanded,
2777
+ hideThinking: entry.hideThinking ?? this.options.appearance?.hideThinkingBlock ?? false,
2778
+ showImages: this.options.appearance?.showImages ?? true,
2779
+ outputPad: this.options.appearance?.outputPad ?? 1,
2780
+ ...this.options.appearance?.codeBlockIndent !== void 0 ? { codeBlockIndent: this.options.appearance.codeBlockIndent } : {},
2781
+ codePreviewSettings: this.options.codePreviewSettings
2782
+ });
2783
+ }
2784
+ transcriptTail(width, budget, editorVisible) {
2785
+ if (this.commandNotification && this.commandNotification.epoch !== this.state.epoch) this.clearCommandNotification();
2786
+ const notification = this.commandNotification;
2787
+ if (this.observedTranscript?.hasNewer && !notification) return [];
2788
+ const tail = notification ? ["", ...notification.component.render(width)] : [];
2789
+ if (notification?.pendingResult) {
2790
+ const reserved = 1 + notification.pendingResult.render(width).length;
2791
+ while (tail.length < reserved) tail.push("");
2792
+ }
2793
+ if (!editorVisible && !this.observedTranscript?.hasNewer) tail.push(...this.working?.render(width) ?? []);
2794
+ if (budget > 1) tail.push("");
2795
+ return tail;
2796
+ }
2797
+ windowBody(body, budget, tail) {
2798
+ this.lastBodyLength = body.length + tail.length;
2799
+ this.lastBody = body;
2800
+ this.lastBodyBudget = budget;
2801
+ const entry = this.currentId ? this.state.view(this.currentId) : void 0;
2802
+ const maxScroll = Math.max(0, this.lastBodyLength - budget);
2803
+ if (entry) {
2804
+ if (entry.following) {
2805
+ entry.scroll = maxScroll;
2806
+ } else if (entry.pageAnchor) {
2807
+ entry.scroll = entry.pageAnchor === "prepend" ? entry.scroll + Math.max(0, body.length - (entry.anchorLength ?? body.length)) : entry.pageAnchor === "end" ? maxScroll : 0;
2808
+ entry.pageAnchor = void 0;
2809
+ entry.anchorLength = void 0;
2810
+ }
2811
+ entry.scroll = Math.max(0, Math.min(entry.scroll, maxScroll));
2812
+ }
2813
+ const start = entry?.scroll ?? 0;
2814
+ const end = start + budget;
2815
+ const lines = body.slice(start, end);
2816
+ if (end > body.length) lines.push(...tail.slice(Math.max(0, start - body.length), end - body.length));
2817
+ return lines;
2818
+ }
2819
+ pickerLines(innerWidth, budget) {
2820
+ this.refreshPicker();
2821
+ const lines = [this.theme.fg("accent", "Targets \xB7 enter select \xB7 esc cancel")];
2822
+ const input = this.pickerInput;
2823
+ if (input) {
2824
+ for (const line of input.render(innerWidth)) lines.push(line);
2825
+ }
2826
+ const rows = this.pickerRows;
2827
+ const selectedIndex = this.pickerSelectedIndex();
2828
+ const listBudget = Math.max(1, budget - lines.length - 1);
2829
+ const startIndex = Math.max(
2830
+ 0,
2831
+ Math.min(selectedIndex - Math.floor(listBudget / 2), rows.length - listBudget)
2832
+ );
2833
+ const endIndex = Math.min(startIndex + listBudget, rows.length);
2834
+ if (rows.length === 0) lines.push(this.theme.fg("muted", " no matching targets"));
2835
+ for (let i = startIndex; i < endIndex; i++) {
2836
+ const row = rows[i];
2837
+ if (!row) continue;
2838
+ const selected = row.target.id === this.pickerSelectedId;
2839
+ const indent = " ".repeat(row.depth + 1);
2840
+ const marker = selected ? this.theme.fg("accent", "\u2192 ") : " ";
2841
+ const unread = this.isUnread(row.target) ? this.theme.fg("accent", " \u25CF") : "";
2842
+ const label = isMainTarget(row.target) ? "Main (native session)" : `${safeText(row.target.name)} ${this.theme.fg("muted", `(${row.target.kind} \xB7 ${row.target.status})`)}`;
2843
+ lines.push(
2844
+ truncateToWidth3(
2845
+ `${indent}${marker}${selected ? this.theme.fg("accent", label) : label}${unread}`,
2846
+ innerWidth,
2847
+ ""
2848
+ )
2849
+ );
2850
+ }
2851
+ if (rows.length > listBudget) {
2852
+ lines.push(this.theme.fg("muted", ` (${selectedIndex + 1}/${rows.length})`));
2853
+ }
2854
+ return lines.slice(0, budget);
2855
+ }
2856
+ };
2857
+ export {
2858
+ FabricConversationState,
2859
+ FabricConversationView
2860
+ };
2861
+ //# sourceMappingURL=conversation.js.map