omp-fabric 0.85.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (772) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +170 -0
  3. package/THIRD_PARTY_NOTICES.md +33 -0
  4. package/dist/activity/store.d.ts +32 -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/manager.d.ts +175 -0
  23. package/dist/actors/manager.d.ts.map +1 -0
  24. package/dist/actors/predicate.d.ts +7 -0
  25. package/dist/actors/predicate.d.ts.map +1 -0
  26. package/dist/actors/types.d.ts +211 -0
  27. package/dist/actors/types.d.ts.map +1 -0
  28. package/dist/agents/bash-worktree-add.d.ts +24 -0
  29. package/dist/agents/bash-worktree-add.d.ts.map +1 -0
  30. package/dist/agents/budget-ledger.d.ts +88 -0
  31. package/dist/agents/budget-ledger.d.ts.map +1 -0
  32. package/dist/agents/claude-cli.d.ts +32 -0
  33. package/dist/agents/claude-cli.d.ts.map +1 -0
  34. package/dist/agents/claude-cli.js +17 -0
  35. package/dist/agents/claude-cli.js.map +7 -0
  36. package/dist/agents/clone-first-worktree.d.ts +17 -0
  37. package/dist/agents/clone-first-worktree.d.ts.map +1 -0
  38. package/dist/agents/compact-control.d.ts +32 -0
  39. package/dist/agents/compact-control.d.ts.map +1 -0
  40. package/dist/agents/compact-control.js +127 -0
  41. package/dist/agents/compact-control.js.map +7 -0
  42. package/dist/agents/constants.d.ts +5 -0
  43. package/dist/agents/constants.d.ts.map +1 -0
  44. package/dist/agents/cow-clone.d.ts +8 -0
  45. package/dist/agents/cow-clone.d.ts.map +1 -0
  46. package/dist/agents/handoff.d.ts +19 -0
  47. package/dist/agents/handoff.d.ts.map +1 -0
  48. package/dist/agents/manager.d.ts +68 -0
  49. package/dist/agents/manager.d.ts.map +1 -0
  50. package/dist/agents/omp-binary.d.ts +7 -0
  51. package/dist/agents/omp-binary.d.ts.map +1 -0
  52. package/dist/agents/rm.d.ts +15 -0
  53. package/dist/agents/rm.d.ts.map +1 -0
  54. package/dist/agents/semaphore.d.ts +7 -0
  55. package/dist/agents/semaphore.d.ts.map +1 -0
  56. package/dist/agents/session-export.d.ts +9 -0
  57. package/dist/agents/session-export.d.ts.map +1 -0
  58. package/dist/agents/thinking-transfer.d.ts +39 -0
  59. package/dist/agents/thinking-transfer.d.ts.map +1 -0
  60. package/dist/agents/transports/herdr-transport.d.ts +10 -0
  61. package/dist/agents/transports/herdr-transport.d.ts.map +1 -0
  62. package/dist/agents/transports/localterm-transport.d.ts +7 -0
  63. package/dist/agents/transports/localterm-transport.d.ts.map +1 -0
  64. package/dist/agents/transports/process-transport.d.ts +7 -0
  65. package/dist/agents/transports/process-transport.d.ts.map +1 -0
  66. package/dist/agents/transports/process-utils.d.ts +29 -0
  67. package/dist/agents/transports/process-utils.d.ts.map +1 -0
  68. package/dist/agents/transports/screen-transport.d.ts +7 -0
  69. package/dist/agents/transports/screen-transport.d.ts.map +1 -0
  70. package/dist/agents/transports/tmux-transport.d.ts +7 -0
  71. package/dist/agents/transports/tmux-transport.d.ts.map +1 -0
  72. package/dist/agents/types.d.ts +251 -0
  73. package/dist/agents/types.d.ts.map +1 -0
  74. package/dist/agents/veda-cli.d.ts +22 -0
  75. package/dist/agents/veda-cli.d.ts.map +1 -0
  76. package/dist/agents/veda-cli.js +13 -0
  77. package/dist/agents/veda-cli.js.map +7 -0
  78. package/dist/agents/worktree-manager.d.ts +14 -0
  79. package/dist/agents/worktree-manager.d.ts.map +1 -0
  80. package/dist/agents/worktree-paths.d.ts +5 -0
  81. package/dist/agents/worktree-paths.d.ts.map +1 -0
  82. package/dist/async-settlement.d.ts +4 -0
  83. package/dist/async-settlement.d.ts.map +1 -0
  84. package/dist/audit/details.d.ts +82 -0
  85. package/dist/audit/details.d.ts.map +1 -0
  86. package/dist/audit/index.d.ts +4 -0
  87. package/dist/audit/index.d.ts.map +1 -0
  88. package/dist/audit/projection.d.ts +20 -0
  89. package/dist/audit/projection.d.ts.map +1 -0
  90. package/dist/audit/trace.d.ts +95 -0
  91. package/dist/audit/trace.d.ts.map +1 -0
  92. package/dist/capture/catalog.d.ts +29 -0
  93. package/dist/capture/catalog.d.ts.map +1 -0
  94. package/dist/capture/interceptor.d.ts +21 -0
  95. package/dist/capture/interceptor.d.ts.map +1 -0
  96. package/dist/capture/wrapper.d.ts +15 -0
  97. package/dist/capture/wrapper.d.ts.map +1 -0
  98. package/dist/chunks/chunk-2GQC324T.js +5001 -0
  99. package/dist/chunks/chunk-2GQC324T.js.map +7 -0
  100. package/dist/chunks/chunk-2KEWFW56.js +1229 -0
  101. package/dist/chunks/chunk-2KEWFW56.js.map +7 -0
  102. package/dist/chunks/chunk-3J7BKUNG.js +354 -0
  103. package/dist/chunks/chunk-3J7BKUNG.js.map +7 -0
  104. package/dist/chunks/chunk-4A4MVZQW.js +253 -0
  105. package/dist/chunks/chunk-4A4MVZQW.js.map +7 -0
  106. package/dist/chunks/chunk-4HQDSTHN.js +221 -0
  107. package/dist/chunks/chunk-4HQDSTHN.js.map +7 -0
  108. package/dist/chunks/chunk-4LEDA76O.js +688 -0
  109. package/dist/chunks/chunk-4LEDA76O.js.map +7 -0
  110. package/dist/chunks/chunk-5GTPD4BA.js +1318 -0
  111. package/dist/chunks/chunk-5GTPD4BA.js.map +7 -0
  112. package/dist/chunks/chunk-5IWFSDU5.js +87 -0
  113. package/dist/chunks/chunk-5IWFSDU5.js.map +7 -0
  114. package/dist/chunks/chunk-6N4XGAZY.js +21 -0
  115. package/dist/chunks/chunk-6N4XGAZY.js.map +7 -0
  116. package/dist/chunks/chunk-6QBPSZJ5.js +647 -0
  117. package/dist/chunks/chunk-6QBPSZJ5.js.map +7 -0
  118. package/dist/chunks/chunk-6X6WUU2K.js +73 -0
  119. package/dist/chunks/chunk-6X6WUU2K.js.map +7 -0
  120. package/dist/chunks/chunk-7363CD5A.js +38 -0
  121. package/dist/chunks/chunk-7363CD5A.js.map +7 -0
  122. package/dist/chunks/chunk-77FQHHZD.js +231 -0
  123. package/dist/chunks/chunk-77FQHHZD.js.map +7 -0
  124. package/dist/chunks/chunk-7BIA5BJN.js +112 -0
  125. package/dist/chunks/chunk-7BIA5BJN.js.map +7 -0
  126. package/dist/chunks/chunk-7BOAOKWH.js +64 -0
  127. package/dist/chunks/chunk-7BOAOKWH.js.map +7 -0
  128. package/dist/chunks/chunk-7TB7NXSL.js +58 -0
  129. package/dist/chunks/chunk-7TB7NXSL.js.map +7 -0
  130. package/dist/chunks/chunk-7VIQNUPS.js +17 -0
  131. package/dist/chunks/chunk-7VIQNUPS.js.map +7 -0
  132. package/dist/chunks/chunk-CT2AJ2UI.js +225 -0
  133. package/dist/chunks/chunk-CT2AJ2UI.js.map +7 -0
  134. package/dist/chunks/chunk-DLXPTBPL.js +151 -0
  135. package/dist/chunks/chunk-DLXPTBPL.js.map +7 -0
  136. package/dist/chunks/chunk-ED3BRM6P.js +17 -0
  137. package/dist/chunks/chunk-ED3BRM6P.js.map +7 -0
  138. package/dist/chunks/chunk-G2IBGGBM.js +42 -0
  139. package/dist/chunks/chunk-G2IBGGBM.js.map +7 -0
  140. package/dist/chunks/chunk-GKOFZ76R.js +1596 -0
  141. package/dist/chunks/chunk-GKOFZ76R.js.map +7 -0
  142. package/dist/chunks/chunk-HDJBUXDX.js +1102 -0
  143. package/dist/chunks/chunk-HDJBUXDX.js.map +7 -0
  144. package/dist/chunks/chunk-IGVDD2HT.js +10 -0
  145. package/dist/chunks/chunk-IGVDD2HT.js.map +7 -0
  146. package/dist/chunks/chunk-JHKOG5GS.js +187 -0
  147. package/dist/chunks/chunk-JHKOG5GS.js.map +7 -0
  148. package/dist/chunks/chunk-JP4LIZFT.js +1334 -0
  149. package/dist/chunks/chunk-JP4LIZFT.js.map +7 -0
  150. package/dist/chunks/chunk-JSBTB3P6.js +127 -0
  151. package/dist/chunks/chunk-JSBTB3P6.js.map +7 -0
  152. package/dist/chunks/chunk-KAD7UWT2.js +99 -0
  153. package/dist/chunks/chunk-KAD7UWT2.js.map +7 -0
  154. package/dist/chunks/chunk-KIH3KLZU.js +95 -0
  155. package/dist/chunks/chunk-KIH3KLZU.js.map +7 -0
  156. package/dist/chunks/chunk-KIREBD2V.js +2208 -0
  157. package/dist/chunks/chunk-KIREBD2V.js.map +7 -0
  158. package/dist/chunks/chunk-LMAVZN7J.js +8 -0
  159. package/dist/chunks/chunk-LMAVZN7J.js.map +7 -0
  160. package/dist/chunks/chunk-NCPJZXLM.js +57 -0
  161. package/dist/chunks/chunk-NCPJZXLM.js.map +7 -0
  162. package/dist/chunks/chunk-OJZNMROB.js +195 -0
  163. package/dist/chunks/chunk-OJZNMROB.js.map +7 -0
  164. package/dist/chunks/chunk-OPTP4PSE.js +469 -0
  165. package/dist/chunks/chunk-OPTP4PSE.js.map +7 -0
  166. package/dist/chunks/chunk-QPXSCMTG.js +24 -0
  167. package/dist/chunks/chunk-QPXSCMTG.js.map +7 -0
  168. package/dist/chunks/chunk-ROKMBLGN.js +1265 -0
  169. package/dist/chunks/chunk-ROKMBLGN.js.map +7 -0
  170. package/dist/chunks/chunk-SXMWV447.js +2445 -0
  171. package/dist/chunks/chunk-SXMWV447.js.map +7 -0
  172. package/dist/chunks/chunk-T5ZA5YRU.js +786 -0
  173. package/dist/chunks/chunk-T5ZA5YRU.js.map +7 -0
  174. package/dist/chunks/chunk-T6OAX4FO.js +1835 -0
  175. package/dist/chunks/chunk-T6OAX4FO.js.map +7 -0
  176. package/dist/chunks/chunk-U5FYOMG5.js +119 -0
  177. package/dist/chunks/chunk-U5FYOMG5.js.map +7 -0
  178. package/dist/chunks/chunk-UOSJZXJV.js +142 -0
  179. package/dist/chunks/chunk-UOSJZXJV.js.map +7 -0
  180. package/dist/chunks/chunk-UPCARIJP.js +6627 -0
  181. package/dist/chunks/chunk-UPCARIJP.js.map +7 -0
  182. package/dist/chunks/chunk-VPPIJRNZ.js +50 -0
  183. package/dist/chunks/chunk-VPPIJRNZ.js.map +7 -0
  184. package/dist/chunks/chunk-XU5Z4JCQ.js +297 -0
  185. package/dist/chunks/chunk-XU5Z4JCQ.js.map +7 -0
  186. package/dist/chunks/chunk-YWEXP724.js +427 -0
  187. package/dist/chunks/chunk-YWEXP724.js.map +7 -0
  188. package/dist/chunks/chunk-YZZIKJX6.js +60 -0
  189. package/dist/chunks/chunk-YZZIKJX6.js.map +7 -0
  190. package/dist/chunks/chunk-ZNAJDPT7.js +2203 -0
  191. package/dist/chunks/chunk-ZNAJDPT7.js.map +7 -0
  192. package/dist/chunks/chunk-ZTM45GH5.js +163 -0
  193. package/dist/chunks/chunk-ZTM45GH5.js.map +7 -0
  194. package/dist/commands/fabric.d.ts +17 -0
  195. package/dist/commands/fabric.d.ts.map +1 -0
  196. package/dist/compaction/bounds.d.ts +23 -0
  197. package/dist/compaction/bounds.d.ts.map +1 -0
  198. package/dist/compaction/branch-details.d.ts +83 -0
  199. package/dist/compaction/branch-details.d.ts.map +1 -0
  200. package/dist/compaction/branch-summary.d.ts +9 -0
  201. package/dist/compaction/branch-summary.d.ts.map +1 -0
  202. package/dist/compaction/enrichers.d.ts +10 -0
  203. package/dist/compaction/enrichers.d.ts.map +1 -0
  204. package/dist/compaction/hook.d.ts +98 -0
  205. package/dist/compaction/hook.d.ts.map +1 -0
  206. package/dist/compaction/hook.js +19 -0
  207. package/dist/compaction/hook.js.map +7 -0
  208. package/dist/compaction/instructions.d.ts +38 -0
  209. package/dist/compaction/instructions.d.ts.map +1 -0
  210. package/dist/compaction/normalize.d.ts +83 -0
  211. package/dist/compaction/normalize.d.ts.map +1 -0
  212. package/dist/compaction/projections.d.ts +31 -0
  213. package/dist/compaction/projections.d.ts.map +1 -0
  214. package/dist/compaction/qa.d.ts +27 -0
  215. package/dist/compaction/qa.d.ts.map +1 -0
  216. package/dist/compaction/render.d.ts +10 -0
  217. package/dist/compaction/render.d.ts.map +1 -0
  218. package/dist/compaction/threshold.d.ts +5 -0
  219. package/dist/compaction/threshold.d.ts.map +1 -0
  220. package/dist/compaction/trace-events.d.ts +23 -0
  221. package/dist/compaction/trace-events.d.ts.map +1 -0
  222. package/dist/components/catalog.d.ts +25 -0
  223. package/dist/components/catalog.d.ts.map +1 -0
  224. package/dist/components/effect-scope.d.ts +31 -0
  225. package/dist/components/effect-scope.d.ts.map +1 -0
  226. package/dist/components/loader.d.ts +27 -0
  227. package/dist/components/loader.d.ts.map +1 -0
  228. package/dist/components/model-guidance.d.ts +48 -0
  229. package/dist/components/model-guidance.d.ts.map +1 -0
  230. package/dist/components/provider-component.d.ts +31 -0
  231. package/dist/components/provider-component.d.ts.map +1 -0
  232. package/dist/components/supervisor.d.ts +29 -0
  233. package/dist/components/supervisor.d.ts.map +1 -0
  234. package/dist/components/types.d.ts +140 -0
  235. package/dist/components/types.d.ts.map +1 -0
  236. package/dist/config-migrations.d.ts +11 -0
  237. package/dist/config-migrations.d.ts.map +1 -0
  238. package/dist/config.d.ts +269 -0
  239. package/dist/config.d.ts.map +1 -0
  240. package/dist/core/action-registry.d.ts +159 -0
  241. package/dist/core/action-registry.d.ts.map +1 -0
  242. package/dist/core/action-registry.js +17 -0
  243. package/dist/core/action-registry.js.map +7 -0
  244. package/dist/core/action-repair.d.ts +20 -0
  245. package/dist/core/action-repair.d.ts.map +1 -0
  246. package/dist/core/agent-dir.d.ts +2 -0
  247. package/dist/core/agent-dir.d.ts.map +1 -0
  248. package/dist/core/approval-controller.d.ts +30 -0
  249. package/dist/core/approval-controller.d.ts.map +1 -0
  250. package/dist/core/atomic-write.d.ts +15 -0
  251. package/dist/core/atomic-write.d.ts.map +1 -0
  252. package/dist/core/auto-approval-classifier.d.ts +13 -0
  253. package/dist/core/auto-approval-classifier.d.ts.map +1 -0
  254. package/dist/core/call-preview.d.ts +8 -0
  255. package/dist/core/call-preview.d.ts.map +1 -0
  256. package/dist/core/child-tool-allowlist.d.ts +3 -0
  257. package/dist/core/child-tool-allowlist.d.ts.map +1 -0
  258. package/dist/core/compact-controller.d.ts +42 -0
  259. package/dist/core/compact-controller.d.ts.map +1 -0
  260. package/dist/core/core-override-guidance.d.ts +7 -0
  261. package/dist/core/core-override-guidance.d.ts.map +1 -0
  262. package/dist/core/direct-tool-approval.d.ts +19 -0
  263. package/dist/core/direct-tool-approval.d.ts.map +1 -0
  264. package/dist/core/effect-conflict.d.ts +3 -0
  265. package/dist/core/effect-conflict.d.ts.map +1 -0
  266. package/dist/core/file-lock.d.ts +12 -0
  267. package/dist/core/file-lock.d.ts.map +1 -0
  268. package/dist/core/model-resolution.d.ts +62 -0
  269. package/dist/core/model-resolution.d.ts.map +1 -0
  270. package/dist/core/model-usage.d.ts +8 -0
  271. package/dist/core/model-usage.d.ts.map +1 -0
  272. package/dist/core/omp-bash-error.d.ts +11 -0
  273. package/dist/core/omp-bash-error.d.ts.map +1 -0
  274. package/dist/core/omp-tools.d.ts +9 -0
  275. package/dist/core/omp-tools.d.ts.map +1 -0
  276. package/dist/core/provider-bindings.d.ts +47 -0
  277. package/dist/core/provider-bindings.d.ts.map +1 -0
  278. package/dist/core/proxy-contract.d.ts +18 -0
  279. package/dist/core/proxy-contract.d.ts.map +1 -0
  280. package/dist/core/session-context.d.ts +6 -0
  281. package/dist/core/session-context.d.ts.map +1 -0
  282. package/dist/core/skill-block.d.ts +10 -0
  283. package/dist/core/skill-block.d.ts.map +1 -0
  284. package/dist/core/skill-dir.d.ts +4 -0
  285. package/dist/core/skill-dir.d.ts.map +1 -0
  286. package/dist/core/skill-prompt.d.ts +3 -0
  287. package/dist/core/skill-prompt.d.ts.map +1 -0
  288. package/dist/core/skill-references.d.ts +7 -0
  289. package/dist/core/skill-references.d.ts.map +1 -0
  290. package/dist/core/stable-hash.d.ts +3 -0
  291. package/dist/core/stable-hash.d.ts.map +1 -0
  292. package/dist/core/system-guidance.d.ts +12 -0
  293. package/dist/core/system-guidance.d.ts.map +1 -0
  294. package/dist/core/token-math.d.ts +16 -0
  295. package/dist/core/token-math.d.ts.map +1 -0
  296. package/dist/core/tool-ownership.d.ts +52 -0
  297. package/dist/core/tool-ownership.d.ts.map +1 -0
  298. package/dist/core/tool-result-proxy.d.ts +18 -0
  299. package/dist/core/tool-result-proxy.d.ts.map +1 -0
  300. package/dist/entropy/active.d.ts +7 -0
  301. package/dist/entropy/active.d.ts.map +1 -0
  302. package/dist/entropy/compiled-store.d.ts +16 -0
  303. package/dist/entropy/compiled-store.d.ts.map +1 -0
  304. package/dist/entropy/compiled-surface.d.ts +51 -0
  305. package/dist/entropy/compiled-surface.d.ts.map +1 -0
  306. package/dist/entropy/compiler.d.ts +28 -0
  307. package/dist/entropy/compiler.d.ts.map +1 -0
  308. package/dist/entropy/corpus.d.ts +22 -0
  309. package/dist/entropy/corpus.d.ts.map +1 -0
  310. package/dist/entropy/fingerprint.d.ts +9 -0
  311. package/dist/entropy/fingerprint.d.ts.map +1 -0
  312. package/dist/entropy/index.d.ts +15 -0
  313. package/dist/entropy/index.d.ts.map +1 -0
  314. package/dist/entropy/index.js +172 -0
  315. package/dist/entropy/index.js.map +7 -0
  316. package/dist/entropy/meter.d.ts +10 -0
  317. package/dist/entropy/meter.d.ts.map +1 -0
  318. package/dist/entropy/passes.d.ts +13 -0
  319. package/dist/entropy/passes.d.ts.map +1 -0
  320. package/dist/entropy/pool-store.d.ts +15 -0
  321. package/dist/entropy/pool-store.d.ts.map +1 -0
  322. package/dist/entropy/pool.d.ts +41 -0
  323. package/dist/entropy/pool.d.ts.map +1 -0
  324. package/dist/entropy/presentation.d.ts +13 -0
  325. package/dist/entropy/presentation.d.ts.map +1 -0
  326. package/dist/entropy/sessions.d.ts +47 -0
  327. package/dist/entropy/sessions.d.ts.map +1 -0
  328. package/dist/entropy/surface.d.ts +30 -0
  329. package/dist/entropy/surface.d.ts.map +1 -0
  330. package/dist/entropy/trial.d.ts +35 -0
  331. package/dist/entropy/trial.d.ts.map +1 -0
  332. package/dist/entropy/types.d.ts +158 -0
  333. package/dist/entropy/types.d.ts.map +1 -0
  334. package/dist/execution-service.d.ts +63 -0
  335. package/dist/execution-service.d.ts.map +1 -0
  336. package/dist/fabric-exec-arguments.d.ts +5 -0
  337. package/dist/fabric-exec-arguments.d.ts.map +1 -0
  338. package/dist/fabric-exec-tool.d.ts +8 -0
  339. package/dist/fabric-exec-tool.d.ts.map +1 -0
  340. package/dist/fabric-runtime-state.d.ts +90 -0
  341. package/dist/fabric-runtime-state.d.ts.map +1 -0
  342. package/dist/fabric-runtime-state.js +13060 -0
  343. package/dist/fabric-runtime-state.js.map +7 -0
  344. package/dist/fabric-state.d.ts +89 -0
  345. package/dist/fabric-state.d.ts.map +1 -0
  346. package/dist/failure-progress.d.ts +3 -0
  347. package/dist/failure-progress.d.ts.map +1 -0
  348. package/dist/host-compatibility.d.ts +5 -0
  349. package/dist/host-compatibility.d.ts.map +1 -0
  350. package/dist/index.d.ts +6 -0
  351. package/dist/index.d.ts.map +1 -0
  352. package/dist/index.js +5719 -0
  353. package/dist/index.js.map +7 -0
  354. package/dist/lifecycle/broker.d.ts +30 -0
  355. package/dist/lifecycle/broker.d.ts.map +1 -0
  356. package/dist/lifecycle/delivery-scheduler.d.ts +30 -0
  357. package/dist/lifecycle/delivery-scheduler.d.ts.map +1 -0
  358. package/dist/lifecycle/types.d.ts +91 -0
  359. package/dist/lifecycle/types.d.ts.map +1 -0
  360. package/dist/log-tail.d.ts +11 -0
  361. package/dist/log-tail.d.ts.map +1 -0
  362. package/dist/main-agent.d.ts +70 -0
  363. package/dist/main-agent.d.ts.map +1 -0
  364. package/dist/memory/context.d.ts +112 -0
  365. package/dist/memory/context.d.ts.map +1 -0
  366. package/dist/memory/digest.d.ts +48 -0
  367. package/dist/memory/digest.d.ts.map +1 -0
  368. package/dist/memory/digest.js +7 -0
  369. package/dist/memory/digest.js.map +7 -0
  370. package/dist/memory/discovery.d.ts +43 -0
  371. package/dist/memory/discovery.d.ts.map +1 -0
  372. package/dist/memory/discovery.js +23 -0
  373. package/dist/memory/discovery.js.map +7 -0
  374. package/dist/memory/index.d.ts +107 -0
  375. package/dist/memory/index.d.ts.map +1 -0
  376. package/dist/memory/lineage.d.ts +20 -0
  377. package/dist/memory/lineage.d.ts.map +1 -0
  378. package/dist/memory/normalize.d.ts +170 -0
  379. package/dist/memory/normalize.d.ts.map +1 -0
  380. package/dist/memory/normalize.js +22 -0
  381. package/dist/memory/normalize.js.map +7 -0
  382. package/dist/memory/regex.d.ts +19 -0
  383. package/dist/memory/regex.d.ts.map +1 -0
  384. package/dist/memory/search.d.ts +98 -0
  385. package/dist/memory/search.d.ts.map +1 -0
  386. package/dist/memory/search.js +22 -0
  387. package/dist/memory/search.js.map +7 -0
  388. package/dist/memory/tokenize.d.ts +24 -0
  389. package/dist/memory/tokenize.d.ts.map +1 -0
  390. package/dist/mesh/store.d.ts +78 -0
  391. package/dist/mesh/store.d.ts.map +1 -0
  392. package/dist/output-budget.d.ts +12 -0
  393. package/dist/output-budget.d.ts.map +1 -0
  394. package/dist/prewalk/arm.d.ts +8 -0
  395. package/dist/prewalk/arm.d.ts.map +1 -0
  396. package/dist/prewalk/controller.d.ts +60 -0
  397. package/dist/prewalk/controller.d.ts.map +1 -0
  398. package/dist/prewalk/fs-drift.d.ts +19 -0
  399. package/dist/prewalk/fs-drift.d.ts.map +1 -0
  400. package/dist/prewalk/handoff.d.ts +45 -0
  401. package/dist/prewalk/handoff.d.ts.map +1 -0
  402. package/dist/protocol.d.ts +273 -0
  403. package/dist/protocol.d.ts.map +1 -0
  404. package/dist/protocol.js +46 -0
  405. package/dist/protocol.js.map +7 -0
  406. package/dist/providers/agents-actions.d.ts +3 -0
  407. package/dist/providers/agents-actions.d.ts.map +1 -0
  408. package/dist/providers/agents-provider.d.ts +59 -0
  409. package/dist/providers/agents-provider.d.ts.map +1 -0
  410. package/dist/providers/arg-normalization.d.ts +15 -0
  411. package/dist/providers/arg-normalization.d.ts.map +1 -0
  412. package/dist/providers/captured-tools-provider.d.ts +23 -0
  413. package/dist/providers/captured-tools-provider.d.ts.map +1 -0
  414. package/dist/providers/compact-provider.d.ts +14 -0
  415. package/dist/providers/compact-provider.d.ts.map +1 -0
  416. package/dist/providers/components-provider.d.ts +12 -0
  417. package/dist/providers/components-provider.d.ts.map +1 -0
  418. package/dist/providers/mcp-descriptor-cache.d.ts +47 -0
  419. package/dist/providers/mcp-descriptor-cache.d.ts.map +1 -0
  420. package/dist/providers/mcp-provider.d.ts +27 -0
  421. package/dist/providers/mcp-provider.d.ts.map +1 -0
  422. package/dist/providers/memory-provider.d.ts +35 -0
  423. package/dist/providers/memory-provider.d.ts.map +1 -0
  424. package/dist/providers/memory-provider.js +16 -0
  425. package/dist/providers/memory-provider.js.map +7 -0
  426. package/dist/providers/mesh-provider.d.ts +17 -0
  427. package/dist/providers/mesh-provider.d.ts.map +1 -0
  428. package/dist/providers/omp-bash-cwd.d.ts +31 -0
  429. package/dist/providers/omp-bash-cwd.d.ts.map +1 -0
  430. package/dist/providers/omp-tools-provider.d.ts +15 -0
  431. package/dist/providers/omp-tools-provider.d.ts.map +1 -0
  432. package/dist/providers/schema-provider.d.ts +15 -0
  433. package/dist/providers/schema-provider.d.ts.map +1 -0
  434. package/dist/providers/state-provider.d.ts +16 -0
  435. package/dist/providers/state-provider.d.ts.map +1 -0
  436. package/dist/providers/write-diff-limits.d.ts +5 -0
  437. package/dist/providers/write-diff-limits.d.ts.map +1 -0
  438. package/dist/providers/write-preview.d.ts +3 -0
  439. package/dist/providers/write-preview.d.ts.map +1 -0
  440. package/dist/ref-names.d.ts +2 -0
  441. package/dist/ref-names.d.ts.map +1 -0
  442. package/dist/repairs/active.d.ts +7 -0
  443. package/dist/repairs/active.d.ts.map +1 -0
  444. package/dist/repairs/apply.d.ts +7 -0
  445. package/dist/repairs/apply.d.ts.map +1 -0
  446. package/dist/repairs/catalog-digest.d.ts +5 -0
  447. package/dist/repairs/catalog-digest.d.ts.map +1 -0
  448. package/dist/repairs/classify.d.ts +10 -0
  449. package/dist/repairs/classify.d.ts.map +1 -0
  450. package/dist/repairs/compiler.d.ts +33 -0
  451. package/dist/repairs/compiler.d.ts.map +1 -0
  452. package/dist/repairs/promote.d.ts +4 -0
  453. package/dist/repairs/promote.d.ts.map +1 -0
  454. package/dist/repairs/store.d.ts +10 -0
  455. package/dist/repairs/store.d.ts.map +1 -0
  456. package/dist/repairs/types.d.ts +49 -0
  457. package/dist/repairs/types.d.ts.map +1 -0
  458. package/dist/residency/actor-client.d.ts +16 -0
  459. package/dist/residency/actor-client.d.ts.map +1 -0
  460. package/dist/residency/actor-client.js +9 -0
  461. package/dist/residency/actor-client.js.map +7 -0
  462. package/dist/residency/client.d.ts +44 -0
  463. package/dist/residency/client.d.ts.map +1 -0
  464. package/dist/residency/host.d.ts +3 -0
  465. package/dist/residency/host.d.ts.map +1 -0
  466. package/dist/residency/host.js +25 -0
  467. package/dist/residency/host.js.map +7 -0
  468. package/dist/residency/launcher-owner.d.ts +7 -0
  469. package/dist/residency/launcher-owner.d.ts.map +1 -0
  470. package/dist/residency/launcher.d.ts +3 -0
  471. package/dist/residency/launcher.d.ts.map +1 -0
  472. package/dist/residency/launcher.js +152 -0
  473. package/dist/residency/launcher.js.map +7 -0
  474. package/dist/residency/omp-entry.d.ts +3 -0
  475. package/dist/residency/omp-entry.d.ts.map +1 -0
  476. package/dist/residency/omp-entry.js +41 -0
  477. package/dist/residency/omp-entry.js.map +7 -0
  478. package/dist/residency/protocol.d.ts +119 -0
  479. package/dist/residency/protocol.d.ts.map +1 -0
  480. package/dist/run-display.d.ts +3 -0
  481. package/dist/run-display.d.ts.map +1 -0
  482. package/dist/runtime/core-override-guest-types.d.ts +15 -0
  483. package/dist/runtime/core-override-guest-types.d.ts.map +1 -0
  484. package/dist/runtime/core-override-guest-types.js +291 -0
  485. package/dist/runtime/core-override-guest-types.js.map +7 -0
  486. package/dist/runtime/core-tool-properties.d.ts +6 -0
  487. package/dist/runtime/core-tool-properties.d.ts.map +1 -0
  488. package/dist/runtime/dynamic-guest-types.d.ts +3 -0
  489. package/dist/runtime/dynamic-guest-types.d.ts.map +1 -0
  490. package/dist/runtime/dynamic-guest-types.js +226 -0
  491. package/dist/runtime/dynamic-guest-types.js.map +7 -0
  492. package/dist/runtime/guest-code-repair.d.ts +2 -0
  493. package/dist/runtime/guest-code-repair.d.ts.map +1 -0
  494. package/dist/runtime/guest-stack-map.d.ts +11 -0
  495. package/dist/runtime/guest-stack-map.d.ts.map +1 -0
  496. package/dist/runtime/guest-types.d.ts +35 -0
  497. package/dist/runtime/guest-types.d.ts.map +1 -0
  498. package/dist/runtime/guest-types.js +13 -0
  499. package/dist/runtime/guest-types.js.map +7 -0
  500. package/dist/runtime/node-process-child-source.d.ts +2 -0
  501. package/dist/runtime/node-process-child-source.d.ts.map +1 -0
  502. package/dist/runtime/node-process-runtime.d.ts +10 -0
  503. package/dist/runtime/node-process-runtime.d.ts.map +1 -0
  504. package/dist/runtime/node-process-runtime.js +319 -0
  505. package/dist/runtime/node-process-runtime.js.map +7 -0
  506. package/dist/runtime/orchestration.d.ts +3 -0
  507. package/dist/runtime/orchestration.d.ts.map +1 -0
  508. package/dist/runtime/quickjs-runtime.d.ts +24 -0
  509. package/dist/runtime/quickjs-runtime.d.ts.map +1 -0
  510. package/dist/runtime/quickjs-runtime.js +12 -0
  511. package/dist/runtime/quickjs-runtime.js.map +7 -0
  512. package/dist/runtime/type-checker.d.ts +21 -0
  513. package/dist/runtime/type-checker.d.ts.map +1 -0
  514. package/dist/runtime/type-checker.js +15 -0
  515. package/dist/runtime/type-checker.js.map +7 -0
  516. package/dist/runtime-paths.d.ts +7 -0
  517. package/dist/runtime-paths.d.ts.map +1 -0
  518. package/dist/schema/controller.d.ts +35 -0
  519. package/dist/schema/controller.d.ts.map +1 -0
  520. package/dist/schema/types.d.ts +86 -0
  521. package/dist/schema/types.d.ts.map +1 -0
  522. package/dist/schema/workspace.d.ts +19 -0
  523. package/dist/schema/workspace.d.ts.map +1 -0
  524. package/dist/speculation/eligibility.d.ts +22 -0
  525. package/dist/speculation/eligibility.d.ts.map +1 -0
  526. package/dist/speculation/freshness.d.ts +10 -0
  527. package/dist/speculation/freshness.d.ts.map +1 -0
  528. package/dist/speculation/partial-json.d.ts +9 -0
  529. package/dist/speculation/partial-json.d.ts.map +1 -0
  530. package/dist/speculation/scanner.d.ts +13 -0
  531. package/dist/speculation/scanner.d.ts.map +1 -0
  532. package/dist/speculation/scanner.js +182 -0
  533. package/dist/speculation/scanner.js.map +7 -0
  534. package/dist/speculation/store.d.ts +39 -0
  535. package/dist/speculation/store.d.ts.map +1 -0
  536. package/dist/speculation/stream-tap.d.ts +27 -0
  537. package/dist/speculation/stream-tap.d.ts.map +1 -0
  538. package/dist/speculation/types.d.ts +44 -0
  539. package/dist/speculation/types.d.ts.map +1 -0
  540. package/dist/state/complexity.d.ts +13 -0
  541. package/dist/state/complexity.d.ts.map +1 -0
  542. package/dist/state/evidence-runner.d.ts +17 -0
  543. package/dist/state/evidence-runner.d.ts.map +1 -0
  544. package/dist/state/store.d.ts +76 -0
  545. package/dist/state/store.d.ts.map +1 -0
  546. package/dist/state/types.d.ts +165 -0
  547. package/dist/state/types.d.ts.map +1 -0
  548. package/dist/storage/retention.d.ts +22 -0
  549. package/dist/storage/retention.d.ts.map +1 -0
  550. package/dist/thinking.d.ts +19 -0
  551. package/dist/thinking.d.ts.map +1 -0
  552. package/dist/topology/control-plane.d.ts +58 -0
  553. package/dist/topology/control-plane.d.ts.map +1 -0
  554. package/dist/topology/participant-directory.d.ts +33 -0
  555. package/dist/topology/participant-directory.d.ts.map +1 -0
  556. package/dist/topology/peer-settle.d.ts +51 -0
  557. package/dist/topology/peer-settle.d.ts.map +1 -0
  558. package/dist/topology/records.d.ts +6 -0
  559. package/dist/topology/records.d.ts.map +1 -0
  560. package/dist/topology/types.d.ts +89 -0
  561. package/dist/topology/types.d.ts.map +1 -0
  562. package/dist/type-error-guidance.d.ts +3 -0
  563. package/dist/type-error-guidance.d.ts.map +1 -0
  564. package/dist/ui/arc-group.d.ts +17 -0
  565. package/dist/ui/arc-group.d.ts.map +1 -0
  566. package/dist/ui/code-preview-shell.d.ts +26 -0
  567. package/dist/ui/code-preview-shell.d.ts.map +1 -0
  568. package/dist/ui/code-preview.d.ts +53 -0
  569. package/dist/ui/code-preview.d.ts.map +1 -0
  570. package/dist/ui/controller.d.ts +20 -0
  571. package/dist/ui/controller.d.ts.map +1 -0
  572. package/dist/ui/conversation-chrome.d.ts +15 -0
  573. package/dist/ui/conversation-chrome.d.ts.map +1 -0
  574. package/dist/ui/conversation-chrome.js +10 -0
  575. package/dist/ui/conversation-chrome.js.map +7 -0
  576. package/dist/ui/conversation-native-reader.d.ts +106 -0
  577. package/dist/ui/conversation-native-reader.d.ts.map +1 -0
  578. package/dist/ui/conversation-native-reader.js +784 -0
  579. package/dist/ui/conversation-native-reader.js.map +7 -0
  580. package/dist/ui/conversation-queue-store.d.ts +12 -0
  581. package/dist/ui/conversation-queue-store.d.ts.map +1 -0
  582. package/dist/ui/conversation-queue.d.ts +242 -0
  583. package/dist/ui/conversation-queue.d.ts.map +1 -0
  584. package/dist/ui/conversation-render.d.ts +45 -0
  585. package/dist/ui/conversation-render.d.ts.map +1 -0
  586. package/dist/ui/conversation-shortcut.d.ts +3 -0
  587. package/dist/ui/conversation-shortcut.d.ts.map +1 -0
  588. package/dist/ui/conversation-targets.d.ts +7 -0
  589. package/dist/ui/conversation-targets.d.ts.map +1 -0
  590. package/dist/ui/conversation-targets.js +12 -0
  591. package/dist/ui/conversation-targets.js.map +7 -0
  592. package/dist/ui/conversation-transcript.d.ts +25 -0
  593. package/dist/ui/conversation-transcript.d.ts.map +1 -0
  594. package/dist/ui/conversation.d.ts +170 -0
  595. package/dist/ui/conversation.d.ts.map +1 -0
  596. package/dist/ui/conversation.js +1868 -0
  597. package/dist/ui/conversation.js.map +7 -0
  598. package/dist/ui/core-tool-render.d.ts +20 -0
  599. package/dist/ui/core-tool-render.d.ts.map +1 -0
  600. package/dist/ui/dashboard-detail.d.ts +68 -0
  601. package/dist/ui/dashboard-detail.d.ts.map +1 -0
  602. package/dist/ui/dashboard-fabric-graph.d.ts +50 -0
  603. package/dist/ui/dashboard-fabric-graph.d.ts.map +1 -0
  604. package/dist/ui/dashboard-model.d.ts +111 -0
  605. package/dist/ui/dashboard-model.d.ts.map +1 -0
  606. package/dist/ui/dashboard-presentation.d.ts +6 -0
  607. package/dist/ui/dashboard-presentation.d.ts.map +1 -0
  608. package/dist/ui/dashboard.d.ts +188 -0
  609. package/dist/ui/dashboard.d.ts.map +1 -0
  610. package/dist/ui/dashboard.js +4604 -0
  611. package/dist/ui/dashboard.js.map +7 -0
  612. package/dist/ui/diff-background.d.ts +12 -0
  613. package/dist/ui/diff-background.d.ts.map +1 -0
  614. package/dist/ui/dynamic-border.d.ts +8 -0
  615. package/dist/ui/dynamic-border.d.ts.map +1 -0
  616. package/dist/ui/escape-halt.d.ts +11 -0
  617. package/dist/ui/escape-halt.d.ts.map +1 -0
  618. package/dist/ui/fabric-actor-delivery-selector.d.ts +17 -0
  619. package/dist/ui/fabric-actor-delivery-selector.d.ts.map +1 -0
  620. package/dist/ui/fabric-actor-tool-selector.d.ts +22 -0
  621. package/dist/ui/fabric-actor-tool-selector.d.ts.map +1 -0
  622. package/dist/ui/fabric-code-parser.d.ts +8 -0
  623. package/dist/ui/fabric-code-parser.d.ts.map +1 -0
  624. package/dist/ui/fabric-host-event-selector.d.ts +29 -0
  625. package/dist/ui/fabric-host-event-selector.d.ts.map +1 -0
  626. package/dist/ui/fabric-model-selector.d.ts +64 -0
  627. package/dist/ui/fabric-model-selector.d.ts.map +1 -0
  628. package/dist/ui/fabric-render.d.ts +113 -0
  629. package/dist/ui/fabric-render.d.ts.map +1 -0
  630. package/dist/ui/fabric-thinking-selector.d.ts +26 -0
  631. package/dist/ui/fabric-thinking-selector.d.ts.map +1 -0
  632. package/dist/ui/fabric-title-hint.d.ts +2 -0
  633. package/dist/ui/fabric-title-hint.d.ts.map +1 -0
  634. package/dist/ui/format.d.ts +9 -0
  635. package/dist/ui/format.d.ts.map +1 -0
  636. package/dist/ui/highlight.d.ts +69 -0
  637. package/dist/ui/highlight.d.ts.map +1 -0
  638. package/dist/ui/model-picker.d.ts +46 -0
  639. package/dist/ui/model-picker.d.ts.map +1 -0
  640. package/dist/ui/model-picker.js +17 -0
  641. package/dist/ui/model-picker.js.map +7 -0
  642. package/dist/ui/preview-lines.d.ts +16 -0
  643. package/dist/ui/preview-lines.d.ts.map +1 -0
  644. package/dist/ui/row-balance.d.ts +29 -0
  645. package/dist/ui/row-balance.d.ts.map +1 -0
  646. package/dist/ui/settings.d.ts +57 -0
  647. package/dist/ui/settings.d.ts.map +1 -0
  648. package/dist/ui/settings.js +1908 -0
  649. package/dist/ui/settings.js.map +7 -0
  650. package/dist/ui/shiki-language.d.ts +7 -0
  651. package/dist/ui/shiki-language.d.ts.map +1 -0
  652. package/dist/ui/shiki-theme.d.ts +7 -0
  653. package/dist/ui/shiki-theme.d.ts.map +1 -0
  654. package/dist/ui/snapshot.d.ts +7 -0
  655. package/dist/ui/snapshot.d.ts.map +1 -0
  656. package/dist/ui/spinner.d.ts +6 -0
  657. package/dist/ui/spinner.d.ts.map +1 -0
  658. package/dist/ui/state-file-preview.d.ts +13 -0
  659. package/dist/ui/state-file-preview.d.ts.map +1 -0
  660. package/dist/ui/structured.d.ts +9 -0
  661. package/dist/ui/structured.d.ts.map +1 -0
  662. package/dist/ui/symbol-theme.d.ts +3 -0
  663. package/dist/ui/symbol-theme.d.ts.map +1 -0
  664. package/dist/ui/tool-call-timing.d.ts +2 -0
  665. package/dist/ui/tool-call-timing.d.ts.map +1 -0
  666. package/dist/ui/tool-display.d.ts +8 -0
  667. package/dist/ui/tool-display.d.ts.map +1 -0
  668. package/dist/ui/topology.d.ts +162 -0
  669. package/dist/ui/topology.d.ts.map +1 -0
  670. package/dist/ui/transcript-parser.d.ts +18 -0
  671. package/dist/ui/transcript-parser.d.ts.map +1 -0
  672. package/dist/ui/transcript-reader.d.ts +10 -0
  673. package/dist/ui/transcript-reader.d.ts.map +1 -0
  674. package/dist/ui/transcript-sanitization.d.ts +14 -0
  675. package/dist/ui/transcript-sanitization.d.ts.map +1 -0
  676. package/dist/ui/transcript.d.ts +52 -0
  677. package/dist/ui/transcript.d.ts.map +1 -0
  678. package/dist/ui/types.d.ts +84 -0
  679. package/dist/ui/types.d.ts.map +1 -0
  680. package/dist/ui/widget.d.ts +16 -0
  681. package/dist/ui/widget.d.ts.map +1 -0
  682. package/dist/ui/word-diff/alignment.d.ts +6 -0
  683. package/dist/ui/word-diff/alignment.d.ts.map +1 -0
  684. package/dist/ui/word-diff/change-block.d.ts +18 -0
  685. package/dist/ui/word-diff/change-block.d.ts.map +1 -0
  686. package/dist/ui/word-diff/changed-line.d.ts +14 -0
  687. package/dist/ui/word-diff/changed-line.d.ts.map +1 -0
  688. package/dist/ui/word-diff/emphasis.d.ts +9 -0
  689. package/dist/ui/word-diff/emphasis.d.ts.map +1 -0
  690. package/dist/ui/word-diff/line-emphasis.d.ts +7 -0
  691. package/dist/ui/word-diff/line-emphasis.d.ts.map +1 -0
  692. package/dist/ui/word-diff/line-matching.d.ts +10 -0
  693. package/dist/ui/word-diff/line-matching.d.ts.map +1 -0
  694. package/dist/ui/word-diff/line-similarity.d.ts +16 -0
  695. package/dist/ui/word-diff/line-similarity.d.ts.map +1 -0
  696. package/dist/ui/word-diff/normalize.d.ts +3 -0
  697. package/dist/ui/word-diff/normalize.d.ts.map +1 -0
  698. package/dist/ui/word-diff/parse.d.ts +17 -0
  699. package/dist/ui/word-diff/parse.d.ts.map +1 -0
  700. package/dist/ui/word-diff/range-refinement.d.ts +5 -0
  701. package/dist/ui/word-diff/range-refinement.d.ts.map +1 -0
  702. package/dist/ui/word-diff/ranges.d.ts +11 -0
  703. package/dist/ui/word-diff/ranges.d.ts.map +1 -0
  704. package/dist/ui/word-diff/smart-filter.d.ts +3 -0
  705. package/dist/ui/word-diff/smart-filter.d.ts.map +1 -0
  706. package/dist/ui/word-diff/sparse-line-matching.d.ts +25 -0
  707. package/dist/ui/word-diff/sparse-line-matching.d.ts.map +1 -0
  708. package/dist/ui/word-diff/text-boundaries.d.ts +11 -0
  709. package/dist/ui/word-diff/text-boundaries.d.ts.map +1 -0
  710. package/dist/ui/word-diff/token-alignment.d.ts +9 -0
  711. package/dist/ui/word-diff/token-alignment.d.ts.map +1 -0
  712. package/dist/ui/word-diff/token-text-refinement.d.ts +4 -0
  713. package/dist/ui/word-diff/token-text-refinement.d.ts.map +1 -0
  714. package/dist/ui/word-diff/tokens.d.ts +16 -0
  715. package/dist/ui/word-diff/tokens.d.ts.map +1 -0
  716. package/dist/ui/word-diff/types.d.ts +10 -0
  717. package/dist/ui/word-diff/types.d.ts.map +1 -0
  718. package/dist/util.d.ts +3 -0
  719. package/dist/util.d.ts.map +1 -0
  720. package/dist/worker/options.d.ts +3 -0
  721. package/dist/worker/options.d.ts.map +1 -0
  722. package/dist/worker/options.js +104 -0
  723. package/dist/worker/options.js.map +7 -0
  724. package/dist/worker/run-record.d.ts +22 -0
  725. package/dist/worker/run-record.d.ts.map +1 -0
  726. package/dist/worker/run-record.js +123 -0
  727. package/dist/worker/run-record.js.map +7 -0
  728. package/dist/worker/session-export.d.ts +45 -0
  729. package/dist/worker/session-export.d.ts.map +1 -0
  730. package/dist/worker/session-export.js +91 -0
  731. package/dist/worker/session-export.js.map +7 -0
  732. package/dist/worker.d.ts +3 -0
  733. package/dist/worker.d.ts.map +1 -0
  734. package/dist/worker.js +1061 -0
  735. package/dist/worker.js.map +7 -0
  736. package/docs/agents.md +564 -0
  737. package/docs/architecture.md +139 -0
  738. package/docs/audit-trace.md +116 -0
  739. package/docs/certification.md +134 -0
  740. package/docs/compaction.md +332 -0
  741. package/docs/component-calculus.md +191 -0
  742. package/docs/components.md +329 -0
  743. package/docs/configuration.md +478 -0
  744. package/docs/entropy.md +396 -0
  745. package/docs/interface.md +149 -0
  746. package/docs/memory-recall.md +614 -0
  747. package/docs/programmatic-compaction.md +207 -0
  748. package/docs/provider-component-calculus.md +378 -0
  749. package/docs/providers.md +109 -0
  750. package/docs/repairs.md +69 -0
  751. package/docs/residency-runtime.md +82 -0
  752. package/docs/schema-enforcement.md +166 -0
  753. package/docs/skills.md +48 -0
  754. package/docs/speculation.md +132 -0
  755. package/docs/state-layer.md +197 -0
  756. package/package.json +116 -0
  757. package/skills/fabric-advisor/SKILL.md +29 -0
  758. package/skills/fabric-ambient/SKILL.md +44 -0
  759. package/skills/fabric-ambient/references/setup.md +90 -0
  760. package/skills/fabric-council/SKILL.md +94 -0
  761. package/skills/fabric-exec/SKILL.md +123 -0
  762. package/skills/fabric-exec/references/agents.md +211 -0
  763. package/skills/fabric-exec/references/mcp.md +49 -0
  764. package/skills/fabric-exec/references/mesh.md +51 -0
  765. package/skills/fabric-fusion/SKILL.md +332 -0
  766. package/skills/fabric-guide/SKILL.md +28 -0
  767. package/skills/fabric-rlm/SKILL.md +284 -0
  768. package/skills/fabric-schema/SKILL.md +121 -0
  769. package/skills/fabric-spec/SKILL.md +42 -0
  770. package/skills/fabric-supervisor/SKILL.md +37 -0
  771. package/skills/fabric-swarm/SKILL.md +80 -0
  772. package/skills/fabric-workflow/SKILL.md +133 -0
@@ -0,0 +1,2208 @@
1
+ import {
2
+ fabricExecTitleHint
3
+ } from "./chunk-3J7BKUNG.js";
4
+ import {
5
+ FABRIC_BRANCH_RUN_DESCRIPTION_MAX_BYTES,
6
+ FABRIC_BRANCH_RUN_NAME_MAX_BYTES,
7
+ FABRIC_BRANCH_SUMMARY_KIND,
8
+ FABRIC_BRANCH_SUMMARY_MAX_BYTES,
9
+ FABRIC_BRANCH_SUMMARY_MAX_FACTS,
10
+ FABRIC_BRANCH_SUMMARY_VERSION,
11
+ readFabricBranchSummaryDetails,
12
+ readFabricProjectionTrace
13
+ } from "./chunk-4HQDSTHN.js";
14
+
15
+ // src/compaction/hook.ts
16
+ import "@oh-my-pi/pi-coding-agent";
17
+
18
+ // src/core/token-math.ts
19
+ var ESTIMATED_IMAGE_CHARS = 4800;
20
+ var DEFAULT_COMPACTION_SETTINGS = {
21
+ enabled: true,
22
+ reserveTokens: 16384,
23
+ keepRecentTokens: 2e4
24
+ };
25
+ var contentParts = (content) => {
26
+ if (typeof content !== "string") return content ?? [];
27
+ return [];
28
+ };
29
+ var blockTokens = (chars) => chars > 0 ? Math.ceil(chars / 4) : 0;
30
+ var textLength = (value) => typeof value === "string" ? value.length : 0;
31
+ var imageTokens = () => blockTokens(ESTIMATED_IMAGE_CHARS);
32
+ var estimateTokens = (message) => {
33
+ let tokens = 0;
34
+ switch (message.role) {
35
+ case "user": {
36
+ if (typeof message.content === "string") return blockTokens(message.content.length);
37
+ for (const block of contentParts(message.content)) {
38
+ if (block.type === "text") tokens += blockTokens(textLength(block.text));
39
+ }
40
+ return tokens;
41
+ }
42
+ case "assistant": {
43
+ for (const block of contentParts(message.content)) {
44
+ if (block.type === "text") {
45
+ tokens += blockTokens(textLength(block.text));
46
+ } else if (block.type === "thinking") {
47
+ tokens += blockTokens(textLength(block.thinking));
48
+ } else if (block.type === "toolCall") {
49
+ tokens += blockTokens(textLength(block.name));
50
+ tokens += blockTokens((JSON.stringify(block.arguments) ?? "null").length);
51
+ }
52
+ }
53
+ return tokens;
54
+ }
55
+ case "custom":
56
+ return 0;
57
+ case "toolResult": {
58
+ if (typeof message.content === "string") return blockTokens(message.content.length);
59
+ for (const block of contentParts(message.content)) {
60
+ if (block.type === "text") tokens += blockTokens(textLength(block.text));
61
+ else if (block.type === "image") tokens += imageTokens();
62
+ }
63
+ return tokens;
64
+ }
65
+ case "bashExecution":
66
+ return blockTokens(textLength(message.command)) + blockTokens(textLength(message.output));
67
+ case "branchSummary":
68
+ case "compactionSummary":
69
+ return blockTokens(textLength(message.summary));
70
+ }
71
+ return 0;
72
+ };
73
+ var calculateContextTokens = (usage) => {
74
+ if (typeof usage !== "object" || usage === null) return 0;
75
+ const record = usage;
76
+ const totalTokens = record.totalTokens;
77
+ if (typeof totalTokens === "number" && totalTokens > 0) return totalTokens;
78
+ const count = (value) => typeof value === "number" ? value : 0;
79
+ return count(record.input) + count(record.output) + count(record.cacheRead) + count(record.cacheWrite);
80
+ };
81
+
82
+ // src/core/session-context.ts
83
+ import { buildSessionContext as buildOmpSessionContext } from "@oh-my-pi/pi-coding-agent/session/session-context";
84
+ var sessionEntryToContextMessages = (entry) => buildOmpSessionContext([entry], entry.id, /* @__PURE__ */ new Map([[entry.id, entry]]), {
85
+ transcript: true,
86
+ keepDanglingToolCalls: true
87
+ }).messages;
88
+ var buildSessionContext = (entries, leafId, byId) => buildOmpSessionContext([...entries], leafId, byId);
89
+
90
+ // src/compaction/bounds.ts
91
+ var MAX_SUMMARY_BYTES = 32 * 1024;
92
+ var MAX_REQUEST_SOURCE_BYTES = 8 * 1024;
93
+ var encoder = new TextEncoder();
94
+ var utf8Bytes = (text) => encoder.encode(text).byteLength;
95
+ var clipUtf8 = (text, maxBytes, suffix = "\u2026") => {
96
+ if (maxBytes <= 0) return "";
97
+ if (utf8Bytes(text) <= maxBytes) return text;
98
+ const suffixBytes = utf8Bytes(suffix);
99
+ if (suffixBytes >= maxBytes) return "";
100
+ let output = "";
101
+ let used = 0;
102
+ const available = maxBytes - suffixBytes;
103
+ for (const character of text) {
104
+ const bytes = utf8Bytes(character);
105
+ if (used + bytes > available) break;
106
+ output += character;
107
+ used += bytes;
108
+ }
109
+ return `${output}${suffix}`;
110
+ };
111
+ var canonicalizeText = (input, maxBytes = MAX_REQUEST_SOURCE_BYTES) => {
112
+ const canonical = input.trim().split(/\s+/u).filter(Boolean).join(" ");
113
+ const sourceBytes = utf8Bytes(canonical);
114
+ return {
115
+ text: clipUtf8(canonical, maxBytes),
116
+ truncated: sourceBytes > maxBytes,
117
+ sourceBytes
118
+ };
119
+ };
120
+ var sampleAddressedFrom = (source, maxValues) => {
121
+ const earliestLimit = Math.ceil(maxValues / 2);
122
+ const latestLimit = Math.floor(maxValues / 2);
123
+ const earliest = [];
124
+ const latest = [];
125
+ let omitted = 0;
126
+ let omittedFirstEntryId;
127
+ let omittedLastEntryId;
128
+ for (const value of source) {
129
+ if (earliest.length < earliestLimit) {
130
+ earliest.push(value);
131
+ continue;
132
+ }
133
+ latest.push(value);
134
+ if (latest.length <= latestLimit) continue;
135
+ const displaced = latest.shift();
136
+ omitted += 1;
137
+ omittedFirstEntryId ??= displaced.entryId;
138
+ omittedLastEntryId = displaced.entryId;
139
+ }
140
+ return {
141
+ values: [...earliest, ...latest],
142
+ omitted,
143
+ ...omittedFirstEntryId !== void 0 ? { omittedFirstEntryId } : {},
144
+ ...omittedLastEntryId !== void 0 ? { omittedLastEntryId } : {},
145
+ splitIndex: earliest.length
146
+ };
147
+ };
148
+ var sampleAddressed = (values, maxValues) => sampleAddressedFrom(values, maxValues);
149
+ var omissionLine = (count, firstEntryId, lastEntryId, noun) => {
150
+ const range = firstEntryId || lastEntryId ? `${firstEntryId || "(start)"} \u2192 ${lastEntryId || "(end)"}` : "(unknown range)";
151
+ return `\u2026 omitted ${count} ${noun}; source entries ${range}`;
152
+ };
153
+
154
+ // src/compaction/threshold.ts
155
+ var modelCompactionKey = (model) => model ? `${model.provider}/${model.id}` : void 0;
156
+ var configuredCompactionTokenThreshold = (config, modelKey) => modelKey === void 0 ? void 0 : config.compaction.tokenThresholds[modelKey];
157
+ var configuredCompactionThreshold = (config, modelKey) => modelKey === void 0 ? void 0 : config.compaction.thresholds[modelKey];
158
+ var runThresholdCompact = async (context) => {
159
+ try {
160
+ await context.compact();
161
+ return true;
162
+ } catch (error) {
163
+ if (context.hasUI) {
164
+ context.ui.notify(`Fabric threshold compaction failed: ${error instanceof Error ? error.message : String(error)}`, "warning");
165
+ }
166
+ return false;
167
+ }
168
+ };
169
+ var compactAtConfiguredThreshold = async (context, config) => {
170
+ const modelKey = modelCompactionKey(context.model);
171
+ const usage = context.getContextUsage();
172
+ if (usage === void 0) return false;
173
+ const tokenThreshold = configuredCompactionTokenThreshold(config, modelKey);
174
+ if (tokenThreshold !== void 0) {
175
+ if (usage.tokens === null || usage.tokens < tokenThreshold) return false;
176
+ return runThresholdCompact(context);
177
+ }
178
+ const threshold = configuredCompactionThreshold(config, modelKey);
179
+ if (threshold === void 0 || usage.percent === null) return false;
180
+ if (usage.percent / 100 < threshold) return false;
181
+ return runThresholdCompact(context);
182
+ };
183
+
184
+ // src/compaction/enrichers.ts
185
+ var NO_BUILTIN_ENRICHERS = Object.freeze([]);
186
+ var runEnrichers = (enrichers, events, sections) => {
187
+ for (const enricher of enrichers) {
188
+ if (!enricher.applies(events)) continue;
189
+ enricher.contribute(events, sections);
190
+ }
191
+ };
192
+
193
+ // src/compaction/instructions.ts
194
+ var FABRIC_COMPACTION_REQUEST_PREFIX = "__omp_fabric_compact_request_v1__:";
195
+ var MAX_COMPACTION_INSTRUCTIONS_CHARS = 8 * 1024;
196
+ var MAX_COMPACTION_INSTRUCTIONS_BYTES = 8 * 1024;
197
+ var MAX_PRESERVE_ITEMS = 16;
198
+ var MAX_PRESERVE_ITEM_CHARS = 2 * 1024;
199
+ var MAX_PRESERVE_ITEM_BYTES = 2 * 1024;
200
+ var MAX_TYPED_COMPACTION_SOURCE_BYTES = 16 * 1024;
201
+ var rejection = (code, message, sourceBytes) => ({
202
+ ok: false,
203
+ requestLines: [],
204
+ error: { code, message, sourceBytes }
205
+ });
206
+ var isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
207
+ var hasPairedSurrogates = (value) => {
208
+ for (let index = 0; index < value.length; index++) {
209
+ const unit = value.charCodeAt(index);
210
+ if (unit >= 55296 && unit <= 56319) {
211
+ const next = value.charCodeAt(index + 1);
212
+ if (!(next >= 56320 && next <= 57343)) return false;
213
+ index += 1;
214
+ } else if (unit >= 56320 && unit <= 57343) {
215
+ return false;
216
+ }
217
+ }
218
+ return true;
219
+ };
220
+ var compactionRequestBoundsError = (request) => {
221
+ if (request.instructions !== void 0) {
222
+ if (!hasPairedSurrogates(request.instructions)) {
223
+ return {
224
+ code: "invalid-unicode",
225
+ message: "typed compaction instructions contain an unpaired UTF-16 surrogate"
226
+ };
227
+ }
228
+ if (request.instructions.length > MAX_COMPACTION_INSTRUCTIONS_CHARS || utf8Bytes(request.instructions) > MAX_COMPACTION_INSTRUCTIONS_BYTES) {
229
+ return {
230
+ code: "instructions-too-large",
231
+ message: `typed compaction instructions exceed ${MAX_COMPACTION_INSTRUCTIONS_CHARS} characters or ${MAX_COMPACTION_INSTRUCTIONS_BYTES} UTF-8 bytes`
232
+ };
233
+ }
234
+ }
235
+ if (request.preserve !== void 0) {
236
+ if (request.preserve.length > MAX_PRESERVE_ITEMS) {
237
+ return {
238
+ code: "preserve-too-many",
239
+ message: `typed compaction preserve exceeds ${MAX_PRESERVE_ITEMS} items`
240
+ };
241
+ }
242
+ for (const item of request.preserve) {
243
+ if (!hasPairedSurrogates(item)) {
244
+ return {
245
+ code: "invalid-unicode",
246
+ message: "typed compaction preserve item contains an unpaired UTF-16 surrogate"
247
+ };
248
+ }
249
+ if (item.length > MAX_PRESERVE_ITEM_CHARS || utf8Bytes(item) > MAX_PRESERVE_ITEM_BYTES) {
250
+ return {
251
+ code: "preserve-item-too-large",
252
+ message: `typed compaction preserve item exceeds ${MAX_PRESERVE_ITEM_CHARS} characters or ${MAX_PRESERVE_ITEM_BYTES} UTF-8 bytes`
253
+ };
254
+ }
255
+ }
256
+ }
257
+ return void 0;
258
+ };
259
+ var encodeCompactionRequest = (request) => {
260
+ const boundsError = compactionRequestBoundsError(request);
261
+ if (boundsError) throw new Error(boundsError.message);
262
+ const payload = {
263
+ version: 1,
264
+ ...request.instructions !== void 0 ? { instructions: request.instructions } : {},
265
+ ...request.preserve !== void 0 ? { preserve: request.preserve } : {}
266
+ };
267
+ const encoded = `${FABRIC_COMPACTION_REQUEST_PREFIX}${JSON.stringify(payload)}`;
268
+ if (utf8Bytes(encoded) > MAX_TYPED_COMPACTION_SOURCE_BYTES) {
269
+ throw new Error(`typed compaction request exceeds ${MAX_TYPED_COMPACTION_SOURCE_BYTES} encoded UTF-8 bytes`);
270
+ }
271
+ return encoded;
272
+ };
273
+ var plainInstructions = (source) => {
274
+ const canonical = canonicalizeText(source);
275
+ return {
276
+ ok: true,
277
+ requestLines: canonical.text ? [canonical.text] : [],
278
+ policy: {
279
+ mode: "plain",
280
+ canonicalized: canonical.text !== source,
281
+ sourceBytes: canonical.sourceBytes,
282
+ truncated: canonical.truncated,
283
+ preserveCount: 0,
284
+ omittedPreserveCount: 0
285
+ }
286
+ };
287
+ };
288
+ var StrictJsonError = class extends Error {
289
+ constructor(code, message) {
290
+ super(message);
291
+ this.code = code;
292
+ }
293
+ };
294
+ var MAX_TYPED_JSON_DEPTH = 32;
295
+ var MAX_TYPED_JSON_NODES = 4096;
296
+ var StrictJsonParser = class {
297
+ constructor(source) {
298
+ this.source = source;
299
+ }
300
+ index = 0;
301
+ nodes = 0;
302
+ parse() {
303
+ this.skipWhitespace();
304
+ const value = this.parseValue(0);
305
+ this.skipWhitespace();
306
+ if (this.index !== this.source.length) this.malformed();
307
+ return value;
308
+ }
309
+ parseValue(depth) {
310
+ if (depth > MAX_TYPED_JSON_DEPTH) {
311
+ throw new StrictJsonError("structure-too-complex", "typed compaction JSON exceeds the structural depth limit");
312
+ }
313
+ this.nodes += 1;
314
+ if (this.nodes > MAX_TYPED_JSON_NODES) {
315
+ throw new StrictJsonError("structure-too-complex", "typed compaction JSON exceeds the structural node limit");
316
+ }
317
+ const character = this.source[this.index];
318
+ if (character === "{") return this.parseObject(depth + 1);
319
+ if (character === "[") return this.parseArray(depth + 1);
320
+ if (character === '"') return this.parseString();
321
+ if (character === "t") return this.parseLiteral("true", true);
322
+ if (character === "f") return this.parseLiteral("false", false);
323
+ if (character === "n") return this.parseLiteral("null", null);
324
+ if (character === "-" || character !== void 0 && character >= "0" && character <= "9") {
325
+ return this.parseNumber();
326
+ }
327
+ return this.malformed();
328
+ }
329
+ parseObject(depth) {
330
+ this.index += 1;
331
+ this.skipWhitespace();
332
+ const output = /* @__PURE__ */ Object.create(null);
333
+ const keys = /* @__PURE__ */ new Set();
334
+ if (this.source[this.index] === "}") {
335
+ this.index += 1;
336
+ return output;
337
+ }
338
+ while (this.index < this.source.length) {
339
+ if (this.source[this.index] !== '"') this.malformed();
340
+ const key = this.parseString();
341
+ if (keys.has(key)) {
342
+ throw new StrictJsonError("duplicate-field", `typed compaction request contains duplicate field ${JSON.stringify(key)}`);
343
+ }
344
+ keys.add(key);
345
+ this.skipWhitespace();
346
+ if (this.source[this.index] !== ":") this.malformed();
347
+ this.index += 1;
348
+ this.skipWhitespace();
349
+ output[key] = this.parseValue(depth);
350
+ this.skipWhitespace();
351
+ const delimiter = this.source[this.index];
352
+ if (delimiter === "}") {
353
+ this.index += 1;
354
+ return output;
355
+ }
356
+ if (delimiter !== ",") this.malformed();
357
+ this.index += 1;
358
+ this.skipWhitespace();
359
+ }
360
+ return this.malformed();
361
+ }
362
+ parseArray(depth) {
363
+ this.index += 1;
364
+ this.skipWhitespace();
365
+ const output = [];
366
+ if (this.source[this.index] === "]") {
367
+ this.index += 1;
368
+ return output;
369
+ }
370
+ while (this.index < this.source.length) {
371
+ output.push(this.parseValue(depth));
372
+ this.skipWhitespace();
373
+ const delimiter = this.source[this.index];
374
+ if (delimiter === "]") {
375
+ this.index += 1;
376
+ return output;
377
+ }
378
+ if (delimiter !== ",") this.malformed();
379
+ this.index += 1;
380
+ this.skipWhitespace();
381
+ }
382
+ return this.malformed();
383
+ }
384
+ parseString() {
385
+ this.index += 1;
386
+ let output = "";
387
+ while (this.index < this.source.length) {
388
+ const unit = this.source.charCodeAt(this.index);
389
+ if (unit === 34) {
390
+ this.index += 1;
391
+ if (!hasPairedSurrogates(output)) {
392
+ throw new StrictJsonError("invalid-unicode", "typed compaction JSON string contains an unpaired UTF-16 surrogate");
393
+ }
394
+ return output;
395
+ }
396
+ if (unit <= 31) this.malformed();
397
+ if (unit !== 92) {
398
+ output += this.source[this.index];
399
+ this.index += 1;
400
+ continue;
401
+ }
402
+ this.index += 1;
403
+ const escape = this.source[this.index];
404
+ this.index += 1;
405
+ if (escape === '"' || escape === "\\" || escape === "/") output += escape;
406
+ else if (escape === "b") output += "\b";
407
+ else if (escape === "f") output += "\f";
408
+ else if (escape === "n") output += "\n";
409
+ else if (escape === "r") output += "\r";
410
+ else if (escape === "t") output += " ";
411
+ else if (escape === "u") {
412
+ let value = 0;
413
+ for (let offset = 0; offset < 4; offset++) {
414
+ const digit = this.hexValue(this.source.charCodeAt(this.index + offset));
415
+ if (digit < 0) this.malformed();
416
+ value = value * 16 + digit;
417
+ }
418
+ this.index += 4;
419
+ output += String.fromCharCode(value);
420
+ } else {
421
+ this.malformed();
422
+ }
423
+ }
424
+ return this.malformed();
425
+ }
426
+ parseNumber() {
427
+ const start = this.index;
428
+ if (this.source[this.index] === "-") this.index += 1;
429
+ if (this.source[this.index] === "0") {
430
+ this.index += 1;
431
+ if (this.isDigit(this.source.charCodeAt(this.index))) this.malformed();
432
+ } else {
433
+ if (!this.isDigitOneToNine(this.source.charCodeAt(this.index))) this.malformed();
434
+ while (this.isDigit(this.source.charCodeAt(this.index))) this.index += 1;
435
+ }
436
+ if (this.source[this.index] === ".") {
437
+ this.index += 1;
438
+ if (!this.isDigit(this.source.charCodeAt(this.index))) this.malformed();
439
+ while (this.isDigit(this.source.charCodeAt(this.index))) this.index += 1;
440
+ }
441
+ const exponent = this.source[this.index];
442
+ if (exponent === "e" || exponent === "E") {
443
+ this.index += 1;
444
+ const sign = this.source[this.index];
445
+ if (sign === "+" || sign === "-") this.index += 1;
446
+ if (!this.isDigit(this.source.charCodeAt(this.index))) this.malformed();
447
+ while (this.isDigit(this.source.charCodeAt(this.index))) this.index += 1;
448
+ }
449
+ const value = Number(this.source.slice(start, this.index));
450
+ if (!Number.isFinite(value)) this.malformed();
451
+ return value;
452
+ }
453
+ parseLiteral(literal, value) {
454
+ if (!this.source.startsWith(literal, this.index)) this.malformed();
455
+ this.index += literal.length;
456
+ return value;
457
+ }
458
+ skipWhitespace() {
459
+ while (this.index < this.source.length) {
460
+ const unit = this.source.charCodeAt(this.index);
461
+ if (unit !== 32 && unit !== 9 && unit !== 10 && unit !== 13) return;
462
+ this.index += 1;
463
+ }
464
+ }
465
+ hexValue(unit) {
466
+ if (unit >= 48 && unit <= 57) return unit - 48;
467
+ if (unit >= 65 && unit <= 70) return unit - 65 + 10;
468
+ if (unit >= 97 && unit <= 102) return unit - 97 + 10;
469
+ return -1;
470
+ }
471
+ isDigit(unit) {
472
+ return unit >= 48 && unit <= 57;
473
+ }
474
+ isDigitOneToNine(unit) {
475
+ return unit >= 49 && unit <= 57;
476
+ }
477
+ malformed() {
478
+ throw new StrictJsonError("malformed-json", "typed compaction request contains malformed JSON");
479
+ }
480
+ };
481
+ var decodeCompactionInstructions = (source) => {
482
+ if (source === void 0 || source === "") {
483
+ return {
484
+ ok: true,
485
+ requestLines: [],
486
+ policy: {
487
+ mode: "none",
488
+ canonicalized: false,
489
+ sourceBytes: 0,
490
+ truncated: false,
491
+ preserveCount: 0,
492
+ omittedPreserveCount: 0
493
+ }
494
+ };
495
+ }
496
+ if (!source.startsWith(FABRIC_COMPACTION_REQUEST_PREFIX)) return plainInstructions(source);
497
+ const encodedSourceBytes = utf8Bytes(source);
498
+ if (encodedSourceBytes > MAX_TYPED_COMPACTION_SOURCE_BYTES) {
499
+ return rejection(
500
+ "encoded-source-too-large",
501
+ `typed compaction request exceeds ${MAX_TYPED_COMPACTION_SOURCE_BYTES} encoded UTF-8 bytes`,
502
+ encodedSourceBytes
503
+ );
504
+ }
505
+ let parsed;
506
+ try {
507
+ parsed = new StrictJsonParser(source.slice(FABRIC_COMPACTION_REQUEST_PREFIX.length)).parse();
508
+ } catch (error) {
509
+ if (error instanceof StrictJsonError) {
510
+ return rejection(error.code, error.message, encodedSourceBytes);
511
+ }
512
+ return rejection("malformed-json", "typed compaction request contains malformed JSON", encodedSourceBytes);
513
+ }
514
+ if (!isRecord(parsed)) {
515
+ return rejection("invalid-object", "typed compaction request must be a JSON object", encodedSourceBytes);
516
+ }
517
+ const keys = Object.keys(parsed);
518
+ const unknownField = keys.find((key) => key !== "version" && key !== "instructions" && key !== "preserve");
519
+ if (unknownField !== void 0) {
520
+ return rejection("unknown-field", `typed compaction request contains unknown field ${JSON.stringify(unknownField)}`, encodedSourceBytes);
521
+ }
522
+ if (parsed.version !== 1) {
523
+ return rejection("unsupported-version", "typed compaction request version must be 1", encodedSourceBytes);
524
+ }
525
+ if (parsed.instructions !== void 0 && typeof parsed.instructions !== "string") {
526
+ return rejection("invalid-type", "typed compaction request instructions must be a string", encodedSourceBytes);
527
+ }
528
+ if (parsed.preserve !== void 0 && !Array.isArray(parsed.preserve)) {
529
+ return rejection("invalid-type", "typed compaction request preserve must be an array", encodedSourceBytes);
530
+ }
531
+ const preserve = parsed.preserve;
532
+ if (preserve !== void 0 && preserve.length > MAX_PRESERVE_ITEMS) {
533
+ return rejection(
534
+ "preserve-too-many",
535
+ `typed compaction preserve exceeds ${MAX_PRESERVE_ITEMS} items`,
536
+ encodedSourceBytes
537
+ );
538
+ }
539
+ if (preserve !== void 0 && !preserve.every((item) => typeof item === "string")) {
540
+ return rejection("invalid-type", "typed compaction preserve items must be strings", encodedSourceBytes);
541
+ }
542
+ const request = {
543
+ ...parsed.instructions !== void 0 ? { instructions: parsed.instructions } : {},
544
+ ...preserve !== void 0 ? { preserve } : {}
545
+ };
546
+ const boundsError = compactionRequestBoundsError(request);
547
+ if (boundsError) return rejection(boundsError.code, boundsError.message, encodedSourceBytes);
548
+ const requestLines = [];
549
+ let valueSourceBytes = 0;
550
+ let truncated = false;
551
+ let canonicalized = false;
552
+ if (request.instructions !== void 0) {
553
+ const instructions = canonicalizeText(request.instructions, MAX_COMPACTION_INSTRUCTIONS_BYTES);
554
+ valueSourceBytes += instructions.sourceBytes;
555
+ truncated ||= instructions.truncated;
556
+ canonicalized ||= instructions.text !== request.instructions;
557
+ if (instructions.text) requestLines.push(instructions.text);
558
+ }
559
+ for (let index = 0; index < (request.preserve?.length ?? 0); index++) {
560
+ const sourceItem = request.preserve[index];
561
+ const item = canonicalizeText(sourceItem, MAX_PRESERVE_ITEM_BYTES);
562
+ valueSourceBytes += item.sourceBytes;
563
+ truncated ||= item.truncated;
564
+ canonicalized ||= item.text !== sourceItem;
565
+ if (item.text) requestLines.push(`- ${item.text} [preserve:${index}]`);
566
+ }
567
+ return {
568
+ ok: true,
569
+ requestLines,
570
+ policy: {
571
+ mode: "typed-v1",
572
+ canonicalized,
573
+ sourceBytes: valueSourceBytes,
574
+ truncated,
575
+ preserveCount: request.preserve?.length ?? 0,
576
+ omittedPreserveCount: 0
577
+ }
578
+ };
579
+ };
580
+
581
+ // src/run-display.ts
582
+ var recordDisplay = (record) => {
583
+ const display = {};
584
+ if (typeof record.name === "string") display.name = record.name;
585
+ if (typeof record.description === "string") display.description = record.description;
586
+ return display.name !== void 0 || display.description !== void 0 ? display : void 0;
587
+ };
588
+ var parseObjectString = (text) => {
589
+ if (!text.startsWith("{") || !text.endsWith("}")) return void 0;
590
+ try {
591
+ const parsed = JSON.parse(text);
592
+ return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : void 0;
593
+ } catch {
594
+ return void 0;
595
+ }
596
+ };
597
+ var normalizeRunDisplay = (input) => {
598
+ if (typeof input === "string") {
599
+ const text = input.trim();
600
+ if (!text) return void 0;
601
+ const parsed = text.startsWith("{") ? parseObjectString(text) : void 0;
602
+ return (parsed && recordDisplay(parsed)) ?? { name: input };
603
+ }
604
+ if (typeof input === "object" && input !== null && !Array.isArray(input)) {
605
+ return recordDisplay(input);
606
+ }
607
+ return void 0;
608
+ };
609
+
610
+ // src/ui/fabric-title-hint.ts
611
+ var TITLE_HINT_CACHE_MAX = 256;
612
+ var titleHintCache = /* @__PURE__ */ new Map();
613
+ var fabricExecTitleHintCached = (code) => {
614
+ const hit = titleHintCache.get(code);
615
+ if (hit !== void 0 || titleHintCache.has(code)) return hit;
616
+ const hint = fabricExecTitleHint(code);
617
+ if (titleHintCache.size >= TITLE_HINT_CACHE_MAX) {
618
+ const oldest = titleHintCache.keys().next().value;
619
+ if (oldest !== void 0) titleHintCache.delete(oldest);
620
+ }
621
+ titleHintCache.set(code, hint);
622
+ return hint;
623
+ };
624
+
625
+ // src/compaction/normalize.ts
626
+ var isMessageEntry = (entry) => entry.type === "message";
627
+ var MAX_CUSTOM_DETAILS_DEPTH = 12;
628
+ var MAX_CUSTOM_DETAILS_NODES = 256;
629
+ var MAX_CUSTOM_DETAILS_COLLECTION = 64;
630
+ var MAX_CUSTOM_DETAILS_STRING_BYTES = 1024;
631
+ var MAX_CUSTOM_DETAILS_BYTES = 8 * 1024;
632
+ var boundedJsonValue = (value, state, depth = 0) => {
633
+ state.nodes += 1;
634
+ if (state.nodes > MAX_CUSTOM_DETAILS_NODES) return void 0;
635
+ if (value === null || typeof value === "boolean") return value;
636
+ if (typeof value === "string") return clipUtf8(value, MAX_CUSTOM_DETAILS_STRING_BYTES);
637
+ if (typeof value === "number") return Number.isFinite(value) ? value : void 0;
638
+ if (typeof value !== "object" || depth > MAX_CUSTOM_DETAILS_DEPTH || state.ancestors.has(value)) return void 0;
639
+ state.ancestors.add(value);
640
+ try {
641
+ if (Array.isArray(value)) {
642
+ const output2 = [];
643
+ for (const item of value.slice(0, MAX_CUSTOM_DETAILS_COLLECTION)) {
644
+ const sanitized = boundedJsonValue(item, state, depth + 1);
645
+ if (sanitized === void 0) return void 0;
646
+ output2.push(sanitized);
647
+ }
648
+ return output2;
649
+ }
650
+ const output = /* @__PURE__ */ Object.create(null);
651
+ const keys = Object.keys(value).sort().slice(0, MAX_CUSTOM_DETAILS_COLLECTION);
652
+ for (const key of keys) {
653
+ const sanitized = boundedJsonValue(value[key], state, depth + 1);
654
+ if (sanitized === void 0) return void 0;
655
+ output[key] = sanitized;
656
+ }
657
+ return output;
658
+ } finally {
659
+ state.ancestors.delete(value);
660
+ }
661
+ };
662
+ var customDetails = (value) => {
663
+ if (value === void 0) return void 0;
664
+ try {
665
+ const sanitized = boundedJsonValue(value, { nodes: 0, ancestors: /* @__PURE__ */ new Set() });
666
+ if (sanitized === void 0 || utf8Bytes(JSON.stringify(sanitized)) > MAX_CUSTOM_DETAILS_BYTES) return void 0;
667
+ return sanitized;
668
+ } catch {
669
+ return void 0;
670
+ }
671
+ };
672
+ var isTypedCustomContent = (content) => {
673
+ if (typeof content === "string") return true;
674
+ if (!Array.isArray(content)) return false;
675
+ return content.every((part) => {
676
+ if (part === null || typeof part !== "object") return false;
677
+ const candidate = part;
678
+ if (candidate.type === "text") return typeof candidate.text === "string";
679
+ return candidate.type === "image";
680
+ });
681
+ };
682
+ var isOmpCustomMessageEntry = (entry) => {
683
+ try {
684
+ if (entry.type !== "custom_message") return false;
685
+ const candidate = entry;
686
+ return typeof candidate.customType === "string" && typeof candidate.display === "boolean" && isTypedCustomContent(candidate.content);
687
+ } catch {
688
+ return false;
689
+ }
690
+ };
691
+ var textOfContent = (content) => {
692
+ if (typeof content === "string") return content;
693
+ if (!Array.isArray(content)) return "";
694
+ const parts = [];
695
+ for (const part of content) {
696
+ if (part && typeof part === "object" && "type" in part) {
697
+ if (part.type === "text" && typeof part.text === "string") parts.push(part.text);
698
+ }
699
+ }
700
+ return parts.join("\n");
701
+ };
702
+ var firstLine = (text) => {
703
+ const trimmed = text.trimStart();
704
+ const nl = trimmed.indexOf("\n");
705
+ return nl < 0 ? trimmed : trimmed.slice(0, nl);
706
+ };
707
+ var fabricRunIntent = (call) => {
708
+ if (!call || call.name !== "fabric_exec") return void 0;
709
+ const display = normalizeRunDisplay(call.args.display);
710
+ const intentName = display?.name?.trim() ? display.name : typeof call.args.code === "string" ? fabricExecTitleHintCached(call.args.code) : void 0;
711
+ if (intentName === void 0) return void 0;
712
+ const name = clipUtf8(intentName.trim(), FABRIC_BRANCH_RUN_NAME_MAX_BYTES);
713
+ if (!name) return void 0;
714
+ const description = display?.description !== void 0 ? clipUtf8(display.description.trim(), FABRIC_BRANCH_RUN_DESCRIPTION_MAX_BYTES) : "";
715
+ return { name, ...description ? { description } : {} };
716
+ };
717
+ var normalizeEntries = (entries) => {
718
+ const events = [];
719
+ const calls = /* @__PURE__ */ new Map();
720
+ let index = 0;
721
+ const push = (event) => {
722
+ index += 1;
723
+ events.push({ ...event, index });
724
+ };
725
+ const pushBranchFacts = (entry) => {
726
+ const details = readFabricBranchSummaryDetails(entry.details);
727
+ if (!details) return;
728
+ for (const fact of details.facts) {
729
+ if (fact.kind === "user") {
730
+ push({ kind: "user", entryId: fact.entryId, sourceEntryId: entry.id, text: fact.text });
731
+ } else if (fact.kind === "customMessage") {
732
+ push({
733
+ kind: "customMessage",
734
+ entryId: fact.entryId,
735
+ sourceEntryId: entry.id,
736
+ customType: fact.customType,
737
+ text: fact.text,
738
+ display: fact.display,
739
+ ...fact.details !== void 0 ? { details: fact.details } : {}
740
+ });
741
+ } else if (fact.kind === "phase") {
742
+ push({
743
+ kind: "fabricPhase",
744
+ entryId: fact.entryId,
745
+ sourceEntryId: entry.id,
746
+ subordinal: fact.subordinal,
747
+ address: fact.address,
748
+ phase: fact.phase
749
+ });
750
+ } else if (fact.kind === "fabricRun") {
751
+ push({
752
+ kind: "fabricRun",
753
+ entryId: fact.entryId,
754
+ sourceEntryId: entry.id,
755
+ toolCallId: fact.subordinal.startsWith("call:") ? fact.subordinal.slice("call:".length) : fact.subordinal,
756
+ subordinal: fact.subordinal,
757
+ address: fact.address,
758
+ name: fact.name,
759
+ ...fact.description !== void 0 ? { description: fact.description } : {},
760
+ outcome: fact.outcome,
761
+ source: "branch"
762
+ });
763
+ } else {
764
+ push({
765
+ kind: "fabricOperation",
766
+ entryId: fact.entryId,
767
+ sourceEntryId: entry.id,
768
+ subordinal: fact.subordinal,
769
+ address: fact.address,
770
+ ref: fact.ref,
771
+ ...fact.provider ? { provider: fact.provider } : {},
772
+ ...fact.action ? { action: fact.action } : {},
773
+ tool: fact.tool,
774
+ args: fact.args,
775
+ outcome: fact.outcome,
776
+ ...fact.error !== void 0 ? { error: fact.error } : {},
777
+ ...fact.result !== void 0 ? { result: fact.result } : {},
778
+ source: "branch"
779
+ });
780
+ }
781
+ }
782
+ };
783
+ for (const entry of entries) {
784
+ if (entry.type === "branch_summary") {
785
+ pushBranchFacts(entry);
786
+ continue;
787
+ }
788
+ if (entry.type === "custom_message") {
789
+ try {
790
+ if (!isOmpCustomMessageEntry(entry)) continue;
791
+ const details = customDetails(entry.details);
792
+ push({
793
+ kind: "customMessage",
794
+ entryId: entry.id,
795
+ sourceEntryId: entry.id,
796
+ customType: entry.customType,
797
+ text: textOfContent(entry.content),
798
+ display: entry.display,
799
+ ...details !== void 0 ? { details } : {}
800
+ });
801
+ } catch {
802
+ }
803
+ continue;
804
+ }
805
+ if (!isMessageEntry(entry)) continue;
806
+ const message = entry.message;
807
+ if (!message || typeof message !== "object") continue;
808
+ const role = message.role;
809
+ const entryId = entry.id;
810
+ if (role === "user") {
811
+ push({ kind: "user", entryId, sourceEntryId: entryId, text: textOfContent(message.content) });
812
+ continue;
813
+ }
814
+ if (role === "assistant") {
815
+ const content = message.content;
816
+ if (!Array.isArray(content)) continue;
817
+ for (const part of content) {
818
+ if (!part || typeof part !== "object" || !("type" in part)) continue;
819
+ if (part.type === "text" && typeof part.text === "string") {
820
+ push({ kind: "assistantText", entryId, sourceEntryId: entryId, text: part.text });
821
+ } else if (part.type === "toolCall" && typeof part.id === "string" && typeof part.name === "string") {
822
+ const args = part.arguments ?? {};
823
+ calls.set(part.id, { entryId, name: part.name, args });
824
+ push({ kind: "toolCall", entryId, sourceEntryId: entryId, toolCallId: part.id, name: part.name, args });
825
+ }
826
+ }
827
+ continue;
828
+ }
829
+ if (role === "toolResult") {
830
+ const toolResult = message;
831
+ const toolCallId = typeof toolResult.toolCallId === "string" ? toolResult.toolCallId : "";
832
+ const toolName = typeof toolResult.toolName === "string" ? toolResult.toolName : "";
833
+ const isError = toolResult.isError === true;
834
+ const text = textOfContent(toolResult.content);
835
+ const pending = toolCallId ? calls.get(toolCallId) : void 0;
836
+ if (toolName === "bash") {
837
+ const command = pending && typeof pending.args.command === "string" ? pending.args.command : "";
838
+ push({
839
+ kind: "bash",
840
+ entryId,
841
+ sourceEntryId: entryId,
842
+ toolCallId,
843
+ command,
844
+ isError,
845
+ exitCode: null,
846
+ ...isError && text ? { error: text } : {}
847
+ });
848
+ } else {
849
+ push({ kind: "toolResult", entryId, sourceEntryId: entryId, toolCallId, toolName, isError, text });
850
+ }
851
+ if (toolName === "fabric_exec") {
852
+ const nested = readFabricProjectionTrace(toolResult.details);
853
+ const intent = fabricRunIntent(pending);
854
+ if (intent && pending) {
855
+ const subordinal = `call:${toolCallId}`;
856
+ push({
857
+ kind: "fabricRun",
858
+ entryId: pending.entryId,
859
+ sourceEntryId: entryId,
860
+ toolCallId,
861
+ subordinal,
862
+ address: `${pending.entryId}/${subordinal}`,
863
+ name: intent.name,
864
+ ...intent.description !== void 0 ? { description: intent.description } : {},
865
+ outcome: nested?.outcome ?? (isError ? "failed" : "succeeded"),
866
+ source: nested?.source ?? "result"
867
+ });
868
+ }
869
+ if (nested) {
870
+ for (let phaseIndex = 0; phaseIndex < nested.phases.length; phaseIndex++) {
871
+ const subordinal = `phase:${phaseIndex}`;
872
+ push({
873
+ kind: "fabricPhase",
874
+ entryId,
875
+ sourceEntryId: entryId,
876
+ subordinal,
877
+ address: `${entryId}/${subordinal}`,
878
+ phase: nested.phases[phaseIndex]
879
+ });
880
+ }
881
+ for (const operation of nested.operations) {
882
+ const subordinal = String(operation.sequence);
883
+ push({
884
+ kind: "fabricOperation",
885
+ entryId,
886
+ sourceEntryId: entryId,
887
+ subordinal,
888
+ address: `${entryId}/${subordinal}`,
889
+ ref: operation.ref,
890
+ ...operation.provider ? { provider: operation.provider } : {},
891
+ ...operation.action ? { action: operation.action } : {},
892
+ tool: operation.tool,
893
+ args: operation.args,
894
+ outcome: operation.outcome,
895
+ ...operation.error !== void 0 ? { error: operation.error } : {},
896
+ ...operation.result !== void 0 ? { result: operation.result } : {},
897
+ source: operation.source
898
+ });
899
+ }
900
+ }
901
+ }
902
+ continue;
903
+ }
904
+ if (role === "bashExecution") {
905
+ const bash = message;
906
+ const exitCode = typeof bash.exitCode === "number" ? bash.exitCode : null;
907
+ const isError = exitCode !== null && exitCode !== 0;
908
+ push({
909
+ kind: "bash",
910
+ entryId,
911
+ sourceEntryId: entryId,
912
+ toolCallId: "",
913
+ command: typeof bash.command === "string" ? bash.command : "",
914
+ isError,
915
+ exitCode,
916
+ ...isError && typeof bash.output === "string" && bash.output ? { error: bash.output } : {}
917
+ });
918
+ continue;
919
+ }
920
+ }
921
+ return events;
922
+ };
923
+ var countErasedThinkingBlocks = (entries) => {
924
+ let count = 0;
925
+ for (const entry of entries) {
926
+ if (!isMessageEntry(entry)) continue;
927
+ const message = entry.message;
928
+ if (message.role !== "assistant" || !Array.isArray(message.content)) continue;
929
+ for (const part of message.content) {
930
+ if (!part || typeof part !== "object" || !("type" in part)) continue;
931
+ if (part.type === "thinking" && typeof part.thinking === "string") count += 1;
932
+ }
933
+ }
934
+ return count;
935
+ };
936
+
937
+ // src/compaction/projections.ts
938
+ var MAX_LINE = 140;
939
+ var FILE_TOOLS = /* @__PURE__ */ new Set(["read", "edit", "write", "grep", "find", "ls"]);
940
+ var MODIFYING_TOOLS = /* @__PURE__ */ new Set(["edit", "write"]);
941
+ var MAX_USER_GOAL_LINES = 3;
942
+ var MAX_USER_GOAL_LINE = 1024;
943
+ var MAX_USER_ONELINER = 120;
944
+ var MAX_EARLIER_USER = 80;
945
+ var MAX_STATUS_LINE = 140;
946
+ var MAX_TRANSCRIPT_LINE = 100;
947
+ var MAX_TRANSCRIPT_CMD = 80;
948
+ var MAX_FABRIC_RUN_NAME = 80;
949
+ var MAX_FABRIC_RUN_DESCRIPTION = 180;
950
+ var MAX_FABRIC_RUN_TRANSCRIPT_NAME = 60;
951
+ var MAX_FABRIC_RUN_EARLIER_NAME = 48;
952
+ var MAX_FABRIC_RUN_STATUS_NAME = 96;
953
+ var MAX_LATER_GOALS = 24;
954
+ var MAX_FILES_PER_KIND = 24;
955
+ var MAX_OUTSTANDING = 32;
956
+ var MAX_ACTIVITY = 48;
957
+ var MAX_UNRESOLVED = 24;
958
+ var MAX_RESOLVED = MAX_OUTSTANDING - MAX_UNRESOLVED;
959
+ var MAX_EARLIER_TURNS = 32;
960
+ var TRANSCRIPT_WINDOW = 40;
961
+ var truncate = (text, max) => {
962
+ const flat = text.replace(/\s+/g, " ").trim();
963
+ return flat.length > max ? `${flat.slice(0, max - 1)}\u2026` : flat;
964
+ };
965
+ var quoted = (text, max) => JSON.stringify(truncate(text, max));
966
+ var customDetailsSuffix = (details, max = 160) => {
967
+ if (details === void 0) return "";
968
+ try {
969
+ return ` details=${truncate(JSON.stringify(details), max)}`;
970
+ } catch {
971
+ return "";
972
+ }
973
+ };
974
+ var customMessageLine = (event, maxText) => {
975
+ const visibility = event.display ? "visible" : "hidden";
976
+ return `custom ${quoted(event.customType, 80)} (${visibility}): ${quoted(event.text, maxText)}${customDetailsSuffix(event.details)}`;
977
+ };
978
+ var trailingEllipsis = (lines, max) => {
979
+ if (lines.length <= max) return lines;
980
+ return [...lines.slice(0, max), "\u2026"];
981
+ };
982
+ var pathOf = (args) => {
983
+ const value = args.path ?? args.file ?? args.dir;
984
+ return typeof value === "string" && value.trim() ? value : void 0;
985
+ };
986
+ var collectOperations = (events) => {
987
+ const calls = /* @__PURE__ */ new Map();
988
+ for (const event of events) {
989
+ if (event.kind === "toolCall") calls.set(event.toolCallId, event);
990
+ }
991
+ const operations = [];
992
+ for (const event of events) {
993
+ if (event.kind === "fabricOperation") {
994
+ operations.push({
995
+ index: event.index,
996
+ entryId: event.entryId,
997
+ address: event.address,
998
+ tool: event.tool,
999
+ ref: event.ref,
1000
+ ...event.provider ? { provider: event.provider } : {},
1001
+ ...event.action ? { action: event.action } : {},
1002
+ args: event.args,
1003
+ outcome: event.outcome,
1004
+ ...event.error !== void 0 ? { error: event.error } : {},
1005
+ ...event.result !== void 0 ? { result: event.result } : {},
1006
+ nested: true
1007
+ });
1008
+ continue;
1009
+ }
1010
+ if (event.kind === "toolResult" && event.toolName !== "bash") {
1011
+ const call = event.toolCallId ? calls.get(event.toolCallId) : void 0;
1012
+ if (!call) continue;
1013
+ operations.push({
1014
+ index: event.index,
1015
+ entryId: call.entryId,
1016
+ address: call.entryId,
1017
+ tool: call.name,
1018
+ ref: call.name,
1019
+ args: call.args,
1020
+ outcome: event.isError ? "failed" : "succeeded",
1021
+ ...event.isError && event.text ? { error: event.text } : {},
1022
+ nested: false
1023
+ });
1024
+ continue;
1025
+ }
1026
+ if (event.kind === "bash") {
1027
+ operations.push({
1028
+ index: event.index,
1029
+ entryId: event.entryId,
1030
+ address: event.entryId,
1031
+ tool: "bash",
1032
+ ref: "bash",
1033
+ args: { command: event.command },
1034
+ outcome: event.isError ? "failed" : "succeeded",
1035
+ ...event.error ? { error: event.error } : {},
1036
+ nested: false
1037
+ });
1038
+ }
1039
+ }
1040
+ return operations.sort((left, right) => left.index - right.index);
1041
+ };
1042
+ var isFileOperation = (operation) => FILE_TOOLS.has(operation.tool) && (operation.ref === operation.tool || operation.ref === `omp.${operation.tool}`);
1043
+ var isBashOperation = (operation) => operation.tool === "bash" && (operation.ref === "bash" || operation.ref === "omp.bash");
1044
+ var resultProvesCreation = (result) => {
1045
+ if (!result || typeof result !== "object" || Array.isArray(result)) return false;
1046
+ const record = result;
1047
+ if (record.created === true) return true;
1048
+ const details = record.details;
1049
+ return Boolean(details && typeof details === "object" && !Array.isArray(details) && details.created === true);
1050
+ };
1051
+ var commonRoot = (paths) => {
1052
+ if (paths.length === 0) return "";
1053
+ const split = paths.map((p) => p.split(/[\\/]/).filter(Boolean));
1054
+ let common = 0;
1055
+ const first = split[0];
1056
+ loop: while (common < first.length) {
1057
+ const segment = first[common];
1058
+ for (let i = 1; i < split.length; i++) {
1059
+ if (split[i].length <= common || split[i][common] !== segment) break loop;
1060
+ }
1061
+ common += 1;
1062
+ }
1063
+ if (common === 0) return "";
1064
+ return `${first.slice(0, common).join("/")}/`;
1065
+ };
1066
+ var stripRoot = (root, path) => root ? path.replace(root, "") : path;
1067
+ var projectGoal = (events) => {
1068
+ const first = events.find(
1069
+ (event) => event.kind === "user"
1070
+ );
1071
+ if (!first) return { lines: [], omitted: 0 };
1072
+ const firstLines = first.text.split("\n").filter(
1073
+ (line, i, arr) => line.trim() !== "" || i === 0 && arr.length === 1
1074
+ ).map((line) => truncate(line, MAX_USER_GOAL_LINE));
1075
+ const lines = [...trailingEllipsis(firstLines, MAX_USER_GOAL_LINES)];
1076
+ function* laterUsers() {
1077
+ let skippedFirst = false;
1078
+ for (const event of events) {
1079
+ if (event.kind !== "user") continue;
1080
+ if (!skippedFirst) {
1081
+ skippedFirst = true;
1082
+ continue;
1083
+ }
1084
+ yield event;
1085
+ }
1086
+ }
1087
+ const sampled = sampleAddressedFrom(laterUsers(), MAX_LATER_GOALS);
1088
+ for (let index = 0; index < sampled.values.length; index++) {
1089
+ if (sampled.omitted > 0 && index === sampled.splitIndex) {
1090
+ lines.push(omissionLine(
1091
+ sampled.omitted,
1092
+ sampled.omittedFirstEntryId,
1093
+ sampled.omittedLastEntryId,
1094
+ "user scope changes"
1095
+ ));
1096
+ }
1097
+ const user = sampled.values[index];
1098
+ const line = truncate(firstLine(user.text), MAX_USER_ONELINER);
1099
+ if (line) lines.push(`- ${line} [entry ${user.entryId}]`);
1100
+ }
1101
+ return { lines, omitted: sampled.omitted };
1102
+ };
1103
+ var projectFiles = (events) => {
1104
+ const read = /* @__PURE__ */ new Map();
1105
+ const modified = /* @__PURE__ */ new Map();
1106
+ const written = /* @__PURE__ */ new Map();
1107
+ const created = /* @__PURE__ */ new Map();
1108
+ for (const operation of collectOperations(events)) {
1109
+ if (!isFileOperation(operation) || operation.outcome !== "succeeded") continue;
1110
+ const path = pathOf(operation.args);
1111
+ if (!path) continue;
1112
+ const address = { path, entryId: operation.address };
1113
+ if (operation.tool === "write") {
1114
+ const target = resultProvesCreation(operation.result) ? created : written;
1115
+ if (!target.has(path)) target.set(path, address);
1116
+ } else if (operation.tool === "edit") {
1117
+ if (!modified.has(path)) modified.set(path, address);
1118
+ } else if (!read.has(path)) {
1119
+ read.set(path, address);
1120
+ }
1121
+ }
1122
+ const modifiedSet = /* @__PURE__ */ new Set();
1123
+ for (const path of modified.keys()) modifiedSet.add(path);
1124
+ for (const path of written.keys()) modifiedSet.add(path);
1125
+ for (const path of created.keys()) modifiedSet.add(path);
1126
+ function* filteredRead() {
1127
+ for (const item of read.values()) {
1128
+ if (!modifiedSet.has(item.path)) yield item;
1129
+ }
1130
+ }
1131
+ const sampledCreated = sampleAddressedFrom(created.values(), MAX_FILES_PER_KIND);
1132
+ const sampledWritten = sampleAddressedFrom(written.values(), MAX_FILES_PER_KIND);
1133
+ const sampledModified = sampleAddressedFrom(modified.values(), MAX_FILES_PER_KIND);
1134
+ const sampledRead = sampleAddressedFrom(filteredRead(), MAX_FILES_PER_KIND);
1135
+ const allSampled = [
1136
+ ...sampledCreated.values,
1137
+ ...sampledWritten.values,
1138
+ ...sampledModified.values,
1139
+ ...sampledRead.values
1140
+ ];
1141
+ if (allSampled.length === 0) return { lines: [], omitted: 0 };
1142
+ const root = commonRoot(allSampled.map((item) => item.path));
1143
+ const lines = [];
1144
+ let omitted = 0;
1145
+ if (root) lines.push(`(under ${root})`);
1146
+ const appendKind = (header, sampled) => {
1147
+ if (sampled.values.length === 0 && sampled.omitted === 0) return;
1148
+ lines.push(header);
1149
+ omitted += sampled.omitted;
1150
+ for (let index = 0; index < sampled.values.length; index++) {
1151
+ if (sampled.omitted > 0 && index === sampled.splitIndex) {
1152
+ lines.push(` ${omissionLine(
1153
+ sampled.omitted,
1154
+ sampled.omittedFirstEntryId,
1155
+ sampled.omittedLastEntryId,
1156
+ "file addresses"
1157
+ )}`);
1158
+ }
1159
+ const item = sampled.values[index];
1160
+ lines.push(` ${stripRoot(root, item.path)} [entry ${item.entryId}]`);
1161
+ }
1162
+ };
1163
+ appendKind("Created:", sampledCreated);
1164
+ appendKind("Written:", sampledWritten);
1165
+ appendKind("Modified:", sampledModified);
1166
+ appendKind("Read:", sampledRead);
1167
+ return { lines, omitted };
1168
+ };
1169
+ var fabricRunPointer = (event) => event.source === "branch" ? event.address : event.entryId;
1170
+ var projectActivity = (events) => {
1171
+ const items = [];
1172
+ for (const event of events) {
1173
+ if (event.kind === "fabricRun") {
1174
+ const name = clipUtf8(truncate(event.name, MAX_FABRIC_RUN_NAME), 192);
1175
+ const description = event.description ? clipUtf8(truncate(event.description, MAX_FABRIC_RUN_DESCRIPTION), 512) : "";
1176
+ items.push({
1177
+ entryId: fabricRunPointer(event),
1178
+ line: `- ${name}${description ? ` \u2014 ${description}` : ""} \u2192 ${event.outcome}`
1179
+ });
1180
+ } else if (event.kind === "fabricPhase") {
1181
+ items.push({ entryId: event.address, line: `- Phase: ${truncate(event.phase, MAX_LINE)}` });
1182
+ } else if (event.kind === "fabricOperation") {
1183
+ if (FILE_TOOLS.has(event.tool) && (event.ref === event.tool || event.ref === `omp.${event.tool}`)) continue;
1184
+ const bash = event.tool === "bash" && (event.ref === "bash" || event.ref === "omp.bash");
1185
+ const primary = bash ? event.args.command : event.args.id ?? event.args.name ?? event.args.query ?? event.args.action;
1186
+ const detail = typeof primary === "string" && primary.trim() ? ` (${truncate(firstLine(primary), 72)})` : "";
1187
+ items.push({
1188
+ entryId: event.address,
1189
+ line: `- ${event.ref}${detail} \u2192 ${event.outcome}`
1190
+ });
1191
+ }
1192
+ }
1193
+ const sampled = sampleAddressed(items, MAX_ACTIVITY);
1194
+ const lines = [];
1195
+ for (let index = 0; index < sampled.values.length; index++) {
1196
+ if (sampled.omitted > 0 && index === sampled.splitIndex) {
1197
+ lines.push(omissionLine(
1198
+ sampled.omitted,
1199
+ sampled.omittedFirstEntryId,
1200
+ sampled.omittedLastEntryId,
1201
+ "Fabric activity records"
1202
+ ));
1203
+ }
1204
+ const item = sampled.values[index];
1205
+ lines.push(`${item.line} [entry ${item.entryId}]`);
1206
+ }
1207
+ return { lines, omitted: sampled.omitted };
1208
+ };
1209
+ var projectOutstandingWithMetadata = (events) => {
1210
+ const operations = collectOperations(events);
1211
+ const keyOf = (operation) => {
1212
+ const path = isFileOperation(operation) ? pathOf(operation.args) : void 0;
1213
+ if (path) return `file\0${operation.tool}\0${path}`;
1214
+ const command = isBashOperation(operation) && typeof operation.args.command === "string" ? operation.args.command : void 0;
1215
+ if (command !== void 0) return `bash\0${operation.tool}\0${command}`;
1216
+ return `generic\0${operation.ref}\0${JSON.stringify(operation.args)}`;
1217
+ };
1218
+ const successes = operations.filter((operation) => operation.outcome === "succeeded").map((operation) => ({ index: operation.index, key: keyOf(operation) }));
1219
+ const items = [];
1220
+ for (const operation of operations) {
1221
+ if (operation.outcome === "succeeded") continue;
1222
+ const path = isFileOperation(operation) ? pathOf(operation.args) : void 0;
1223
+ const command = isBashOperation(operation) && typeof operation.args.command === "string" ? operation.args.command : void 0;
1224
+ const subject = path ? `${operation.ref} ${path}` : command !== void 0 ? `${operation.ref}: ${truncate(firstLine(command), MAX_LINE)}` : operation.ref;
1225
+ const error = operation.error ? `: ${truncate(firstLine(operation.error), MAX_LINE)}` : `: ${operation.outcome}`;
1226
+ const key = keyOf(operation);
1227
+ const resolved2 = successes.some((success) => success.index > operation.index && success.key === key);
1228
+ items.push({
1229
+ index: operation.index,
1230
+ entryId: operation.address,
1231
+ description: `${subject}${error}`,
1232
+ resolved: resolved2
1233
+ });
1234
+ }
1235
+ if (items.length === 0) return { lines: [], omitted: 0 };
1236
+ const unresolved = items.filter((i) => !i.resolved).sort((a, b) => a.index - b.index);
1237
+ const resolved = items.filter((i) => i.resolved).sort((a, b) => a.index - b.index);
1238
+ const sampledUnresolved = sampleAddressed(unresolved, MAX_UNRESOLVED);
1239
+ const sampledResolved = sampleAddressed(resolved, MAX_RESOLVED);
1240
+ const lines = [];
1241
+ const append = (sampled, noun) => {
1242
+ for (let index = 0; index < sampled.values.length; index++) {
1243
+ if (sampled.omitted > 0 && index === sampled.splitIndex) {
1244
+ lines.push(omissionLine(
1245
+ sampled.omitted,
1246
+ sampled.omittedFirstEntryId,
1247
+ sampled.omittedLastEntryId,
1248
+ noun
1249
+ ));
1250
+ }
1251
+ const item = sampled.values[index];
1252
+ lines.push(`- ${item.description}${item.resolved ? " [RESOLVED]" : ""} [entry ${item.entryId}]`);
1253
+ }
1254
+ };
1255
+ append(sampledUnresolved, "open error records");
1256
+ append(sampledResolved, "resolved error records");
1257
+ return { lines, omitted: sampledUnresolved.omitted + sampledResolved.omitted };
1258
+ };
1259
+ var projectEarlierTurns = (events) => {
1260
+ function* earlierTurns() {
1261
+ let currentContext;
1262
+ let counts = /* @__PURE__ */ new Map();
1263
+ let order = [];
1264
+ let lastRun;
1265
+ const completed = () => {
1266
+ if (!currentContext) return void 0;
1267
+ return {
1268
+ entryId: currentContext.entryId,
1269
+ contextLine: currentContext.kind === "user" ? quoted(firstLine(currentContext.text), MAX_EARLIER_USER) : customMessageLine(currentContext, MAX_EARLIER_USER),
1270
+ tools: order.map((name) => `${name}:${counts.get(name) ?? 0}`).join(" "),
1271
+ run: lastRun ? `fabric:${quoted(clipUtf8(lastRun.name, 128), MAX_FABRIC_RUN_EARLIER_NAME)}\u2192${lastRun.outcome}` : ""
1272
+ };
1273
+ };
1274
+ for (const event of events) {
1275
+ if (event.kind === "user" || event.kind === "customMessage") {
1276
+ const turn = completed();
1277
+ if (turn) yield turn;
1278
+ currentContext = event;
1279
+ counts = /* @__PURE__ */ new Map();
1280
+ order = [];
1281
+ lastRun = void 0;
1282
+ continue;
1283
+ }
1284
+ if (!currentContext) continue;
1285
+ if (event.kind === "fabricRun") lastRun = event;
1286
+ const name = event.kind === "toolCall" ? event.name === "fabric_exec" ? void 0 : event.name : event.kind === "bash" ? "bash" : event.kind === "fabricOperation" ? event.tool : void 0;
1287
+ if (!name) continue;
1288
+ if (!counts.has(name)) order.push(name);
1289
+ counts.set(name, (counts.get(name) ?? 0) + 1);
1290
+ }
1291
+ }
1292
+ const sampled = sampleAddressedFrom(earlierTurns(), MAX_EARLIER_TURNS);
1293
+ const lines = [];
1294
+ for (let index = 0; index < sampled.values.length; index++) {
1295
+ if (sampled.omitted > 0 && index === sampled.splitIndex) {
1296
+ lines.push(omissionLine(
1297
+ sampled.omitted,
1298
+ sampled.omittedFirstEntryId,
1299
+ sampled.omittedLastEntryId,
1300
+ "earlier turns"
1301
+ ));
1302
+ }
1303
+ const turn = sampled.values[index];
1304
+ const metadata = [turn.tools, turn.run].filter(Boolean).join(" | ");
1305
+ lines.push(`${turn.contextLine}${metadata ? ` | ${metadata}` : ""} [entry ${turn.entryId}]`);
1306
+ }
1307
+ return { lines, omitted: sampled.omitted };
1308
+ };
1309
+ var projectStatus = (events) => {
1310
+ const lastContext = [...events].reverse().find(
1311
+ (event) => event.kind === "user" || event.kind === "customMessage"
1312
+ );
1313
+ const lines = [];
1314
+ if (lastContext?.kind === "user") {
1315
+ lines.push(`Last request: ${truncate(firstLine(lastContext.text), MAX_STATUS_LINE)}`);
1316
+ } else if (lastContext) {
1317
+ lines.push(`Last context: ${customMessageLine(lastContext, MAX_STATUS_LINE)}`);
1318
+ }
1319
+ let lastModify;
1320
+ for (const operation of collectOperations(events)) {
1321
+ if (isFileOperation(operation) && MODIFYING_TOOLS.has(operation.tool)) lastModify = operation;
1322
+ }
1323
+ if (lastModify) {
1324
+ const path = pathOf(lastModify.args) ?? "";
1325
+ lines.push(`Last change: ${lastModify.tool}${path ? ` ${path}` : ""}`);
1326
+ }
1327
+ const lastRun = [...events].reverse().find((event) => event.kind === "fabricRun");
1328
+ if (lastRun) {
1329
+ lines.push(
1330
+ `Last execution: ${clipUtf8(truncate(lastRun.name, MAX_FABRIC_RUN_STATUS_NAME), 256)} \u2192 ${lastRun.outcome} [entry ${fabricRunPointer(lastRun)}]`
1331
+ );
1332
+ }
1333
+ const lastAssistant = [...events].reverse().find((e) => e.kind === "assistantText");
1334
+ if (lastAssistant) {
1335
+ const text = truncate(firstLine(lastAssistant.text), MAX_STATUS_LINE);
1336
+ if (text) lines.push(`Last note: ${text}`);
1337
+ }
1338
+ return lines;
1339
+ };
1340
+ var summarizeArgs = (name, args) => {
1341
+ if (name === "fabric_exec") return "structured execution";
1342
+ const primary = name === "bash" ? args.command ?? args.cmd ?? args.shell : name === "grep" ? args.pattern ?? args.query ?? args.regex : name === "find" ? args.pattern : pathOf(args);
1343
+ if (typeof primary === "string" && primary.trim()) {
1344
+ return truncate(firstLine(primary), MAX_TRANSCRIPT_CMD);
1345
+ }
1346
+ const entries = Object.entries(args).slice(0, 2);
1347
+ return entries.map(([key, value]) => `${key}=${truncate(String(value), 40)}`).join(" ");
1348
+ };
1349
+ var projectTranscript = (events) => {
1350
+ const completedFabricCalls = new Set(
1351
+ events.filter((event) => event.kind === "fabricRun").map((event) => event.toolCallId)
1352
+ );
1353
+ const transcriptEvents = events.filter((event) => {
1354
+ if (event.kind === "toolCall") {
1355
+ return event.name !== "fabric_exec" || !completedFabricCalls.has(event.toolCallId);
1356
+ }
1357
+ if (event.kind === "toolResult") {
1358
+ return event.toolName !== "fabric_exec" || !completedFabricCalls.has(event.toolCallId);
1359
+ }
1360
+ return true;
1361
+ });
1362
+ const window = transcriptEvents.slice(-TRANSCRIPT_WINDOW);
1363
+ const lines = [];
1364
+ const omitted = transcriptEvents.length - window.length;
1365
+ if (omitted > 0) {
1366
+ lines.push(omissionLine(
1367
+ omitted,
1368
+ transcriptEvents[0]?.entryId,
1369
+ transcriptEvents[omitted - 1]?.entryId,
1370
+ "transcript events"
1371
+ ));
1372
+ }
1373
+ for (const e of window) {
1374
+ const ref = `(#${e.index})`;
1375
+ if (e.kind === "user") {
1376
+ lines.push(`${ref} user: ${truncate(firstLine(e.text), MAX_TRANSCRIPT_LINE)}`);
1377
+ } else if (e.kind === "assistantText") {
1378
+ lines.push(`${ref} assistant: ${truncate(firstLine(e.text), MAX_TRANSCRIPT_LINE)}`);
1379
+ } else if (e.kind === "customMessage") {
1380
+ lines.push(`${ref} ${customMessageLine(e, MAX_TRANSCRIPT_LINE)}`);
1381
+ } else if (e.kind === "toolCall") {
1382
+ lines.push(`${ref} ${e.name}(${summarizeArgs(e.name, e.args)})`);
1383
+ } else if (e.kind === "toolResult") {
1384
+ const status = e.isError ? "error" : "ok";
1385
+ lines.push(`${ref} \u2192 ${status}: ${truncate(firstLine(e.text), MAX_TRANSCRIPT_LINE)}`);
1386
+ } else if (e.kind === "bash") {
1387
+ const status = e.isError ? "error" : "ok";
1388
+ lines.push(`${ref} bash(${truncate(firstLine(e.command), MAX_TRANSCRIPT_CMD)}) \u2192 ${status}`);
1389
+ } else if (e.kind === "fabricRun") {
1390
+ lines.push(
1391
+ `${ref} fabric_exec ${quoted(clipUtf8(e.name, 160), MAX_FABRIC_RUN_TRANSCRIPT_NAME)} \u2192 ${e.outcome} [entry ${fabricRunPointer(e)}]`
1392
+ );
1393
+ } else if (e.kind === "fabricPhase") {
1394
+ lines.push(`${ref} phase(${truncate(e.phase, MAX_TRANSCRIPT_CMD)}) [${e.address}]`);
1395
+ } else if (e.kind === "fabricOperation") {
1396
+ lines.push(`${ref} ${e.ref}(${summarizeArgs(e.tool, e.args)}) \u2192 ${e.outcome} [${e.address}]`);
1397
+ }
1398
+ }
1399
+ return { lines, omitted };
1400
+ };
1401
+ var projectWithMetadata = (events) => {
1402
+ const goal = projectGoal(events);
1403
+ const files = projectFiles(events);
1404
+ const activity = projectActivity(events);
1405
+ const outstanding = projectOutstandingWithMetadata(events);
1406
+ const earlierTurns = projectEarlierTurns(events);
1407
+ const transcript = projectTranscript(events);
1408
+ return {
1409
+ sections: {
1410
+ goal: goal.lines,
1411
+ files: files.lines,
1412
+ activity: activity.lines,
1413
+ outstanding: outstanding.lines,
1414
+ earlierTurns: earlierTurns.lines,
1415
+ status: projectStatus(events),
1416
+ transcript: transcript.lines
1417
+ },
1418
+ omittedCounts: {
1419
+ goal: goal.omitted,
1420
+ files: files.omitted,
1421
+ activity: activity.omitted,
1422
+ outstanding: outstanding.omitted,
1423
+ earlierTurns: earlierTurns.omitted,
1424
+ transcript: transcript.omitted
1425
+ }
1426
+ };
1427
+ };
1428
+
1429
+ // src/compaction/render.ts
1430
+ var SECTION_ORDER = [
1431
+ { key: "goal", header: "[Session Goal]", maxBytes: 4096 },
1432
+ { key: "files", header: "[Files And Changes]", maxBytes: 4608 },
1433
+ { key: "activity", header: "[Fabric Activity]", maxBytes: 2048 },
1434
+ { key: "outstanding", header: "[Outstanding Context]", maxBytes: 4608 },
1435
+ { key: "earlierTurns", header: "[Earlier Turns]", maxBytes: 3072 },
1436
+ { key: "status", header: "[Current Status]", maxBytes: 2048 }
1437
+ ];
1438
+ var REQUEST_MAX_BYTES = 3072;
1439
+ var TRANSCRIPT_MAX_BYTES = 5120;
1440
+ var FOOTER_MAX_BYTES = 1536;
1441
+ var MAX_INPUT_LINES_PER_SECTION = 128;
1442
+ var MAX_RENDERED_LINE_BYTES = 1024;
1443
+ var POINTER_LINE = "For exact pre-summary history, use memory.recall on this range, then memory.expand by stable entry or operation address.";
1444
+ var sampledLines = (lines, keep) => {
1445
+ if (lines.length <= keep) return [...lines];
1446
+ const earliest = Math.ceil(keep / 2);
1447
+ const latest = Math.floor(keep / 2);
1448
+ return [
1449
+ ...lines.slice(0, earliest),
1450
+ `\u2026 omitted ${lines.length - keep} rendered lines`,
1451
+ ...lines.slice(lines.length - latest)
1452
+ ];
1453
+ };
1454
+ var boundedBlock = (header, sourceLines, maxBytes) => {
1455
+ const clipped = sourceLines.map((line) => clipUtf8(line, MAX_RENDERED_LINE_BYTES));
1456
+ const capped = sampledLines(clipped, Math.min(clipped.length, MAX_INPUT_LINES_PER_SECTION));
1457
+ for (let keep = capped.length; keep >= 0; keep--) {
1458
+ const lines = sampledLines(capped, keep);
1459
+ const block = [header, ...lines].join("\n");
1460
+ if (utf8Bytes(block) <= maxBytes) return block;
1461
+ }
1462
+ return clipUtf8(header, maxBytes);
1463
+ };
1464
+ var renderSummary = (sections, options) => {
1465
+ const blocks = [];
1466
+ for (const { key, header, maxBytes } of SECTION_ORDER) {
1467
+ const lines = sections[key];
1468
+ if (lines.length === 0) continue;
1469
+ blocks.push(boundedBlock(header, lines, maxBytes));
1470
+ if (key === "goal" && options.requestLines && options.requestLines.length > 0) {
1471
+ blocks.push(boundedBlock("[Compaction Request]", options.requestLines, REQUEST_MAX_BYTES));
1472
+ }
1473
+ }
1474
+ if (sections.goal.length === 0 && options.requestLines && options.requestLines.length > 0) {
1475
+ blocks.unshift(boundedBlock("[Compaction Request]", options.requestLines, REQUEST_MAX_BYTES));
1476
+ }
1477
+ if (sections.transcript.length > 0) {
1478
+ blocks.push(boundedBlock("---", sections.transcript, TRANSCRIPT_MAX_BYTES));
1479
+ }
1480
+ const timestamp = options.lastTimestamp || "(unknown time)";
1481
+ const range = options.firstEntryId || options.lastEntryId ? `${options.firstEntryId || "(start)"} \u2192 ${options.lastEntryId || "(end)"}` : "(no entries)";
1482
+ const footer = options.summaryKind === "branch" ? `[branch summarized ${timestamp}; structural source entries ${range}]` : `[compacted ${timestamp}; cumulative source entries ${range}]`;
1483
+ blocks.push(boundedBlock("---", [footer, POINTER_LINE], FOOTER_MAX_BYTES));
1484
+ const summary = `${blocks.join("\n\n")}
1485
+ `;
1486
+ if (utf8Bytes(summary) <= MAX_SUMMARY_BYTES) return summary;
1487
+ return `${clipUtf8(summary, MAX_SUMMARY_BYTES - 1, "")}
1488
+ `;
1489
+ };
1490
+
1491
+ // src/compaction/branch-summary.ts
1492
+ var SECTION_HEADERS = [
1493
+ { key: "goal", header: "[Session Goal]" },
1494
+ { key: "files", header: "[Files And Changes]" },
1495
+ { key: "activity", header: "[Fabric Activity]" },
1496
+ { key: "outstanding", header: "[Outstanding Context]" },
1497
+ { key: "earlierTurns", header: "[Earlier Turns]" },
1498
+ { key: "status", header: "[Current Status]" }
1499
+ ];
1500
+ var asJsonObject = (value) => {
1501
+ try {
1502
+ const cloned = JSON.parse(JSON.stringify(value));
1503
+ return cloned && typeof cloned === "object" && !Array.isArray(cloned) ? cloned : void 0;
1504
+ } catch {
1505
+ return void 0;
1506
+ }
1507
+ };
1508
+ var directOperationFact = (call, outcome, error) => {
1509
+ if (call.name === "fabric_exec") return void 0;
1510
+ const args = asJsonObject(call.args);
1511
+ if (!args) return void 0;
1512
+ const subordinal = `call:${call.toolCallId}`;
1513
+ return {
1514
+ kind: "operation",
1515
+ entryId: call.entryId,
1516
+ subordinal,
1517
+ address: `${call.entryId}/${subordinal}`,
1518
+ ref: call.name,
1519
+ action: call.name,
1520
+ tool: call.name,
1521
+ args,
1522
+ outcome,
1523
+ ...error ? { error: clipUtf8(error, 8 * 1024) } : {}
1524
+ };
1525
+ };
1526
+ var factsFromEvents = (events) => {
1527
+ const facts = [];
1528
+ const calls = /* @__PURE__ */ new Map();
1529
+ for (const event of events) {
1530
+ if (event.kind === "toolCall") calls.set(event.toolCallId, event);
1531
+ }
1532
+ for (const event of events) {
1533
+ if (event.kind === "user") {
1534
+ facts.push({
1535
+ kind: "user",
1536
+ entryId: event.entryId,
1537
+ subordinal: "user",
1538
+ address: `${event.entryId}/user`,
1539
+ text: clipUtf8(event.text, 2 * 1024)
1540
+ });
1541
+ } else if (event.kind === "customMessage") {
1542
+ facts.push({
1543
+ kind: "customMessage",
1544
+ entryId: event.entryId,
1545
+ subordinal: "custom-message",
1546
+ address: `${event.entryId}/custom-message`,
1547
+ customType: clipUtf8(event.customType, 256),
1548
+ text: clipUtf8(event.text, 4 * 1024),
1549
+ display: event.display,
1550
+ ...event.details !== void 0 ? { details: event.details } : {}
1551
+ });
1552
+ } else if (event.kind === "fabricPhase") {
1553
+ facts.push({
1554
+ kind: "phase",
1555
+ entryId: event.entryId,
1556
+ subordinal: event.subordinal,
1557
+ address: event.address,
1558
+ phase: event.phase
1559
+ });
1560
+ } else if (event.kind === "fabricRun") {
1561
+ facts.push({
1562
+ kind: "fabricRun",
1563
+ entryId: event.entryId,
1564
+ subordinal: event.subordinal,
1565
+ address: event.address,
1566
+ name: clipUtf8(event.name, FABRIC_BRANCH_RUN_NAME_MAX_BYTES),
1567
+ ...event.description !== void 0 ? { description: clipUtf8(event.description, FABRIC_BRANCH_RUN_DESCRIPTION_MAX_BYTES) } : {},
1568
+ outcome: event.outcome
1569
+ });
1570
+ } else if (event.kind === "fabricOperation") {
1571
+ facts.push({
1572
+ kind: "operation",
1573
+ entryId: event.entryId,
1574
+ subordinal: event.subordinal,
1575
+ address: event.address,
1576
+ ref: event.ref,
1577
+ ...event.provider ? { provider: event.provider } : {},
1578
+ ...event.action ? { action: event.action } : {},
1579
+ tool: event.tool,
1580
+ args: event.args,
1581
+ outcome: event.outcome,
1582
+ ...event.error !== void 0 ? { error: event.error } : {},
1583
+ ...event.result !== void 0 ? { result: event.result } : {}
1584
+ });
1585
+ } else if (event.kind === "toolResult" && event.toolName !== "bash") {
1586
+ const call = event.toolCallId ? calls.get(event.toolCallId) : void 0;
1587
+ if (!call) continue;
1588
+ const fact = directOperationFact(call, event.isError ? "failed" : "succeeded", event.isError ? event.text : void 0);
1589
+ if (fact) facts.push(fact);
1590
+ } else if (event.kind === "bash") {
1591
+ const call = event.toolCallId ? calls.get(event.toolCallId) : void 0;
1592
+ if (call) {
1593
+ const fact = directOperationFact(call, event.isError ? "failed" : "succeeded", event.error);
1594
+ if (fact) facts.push(fact);
1595
+ } else {
1596
+ const subordinal = "bash";
1597
+ facts.push({
1598
+ kind: "operation",
1599
+ entryId: event.entryId,
1600
+ subordinal,
1601
+ address: `${event.entryId}/${subordinal}`,
1602
+ ref: "bash",
1603
+ action: "bash",
1604
+ tool: "bash",
1605
+ args: { command: event.command },
1606
+ outcome: event.isError ? "failed" : "succeeded",
1607
+ ...event.error ? { error: clipUtf8(event.error, 8 * 1024) } : {}
1608
+ });
1609
+ }
1610
+ }
1611
+ }
1612
+ return facts;
1613
+ };
1614
+ var serializedBytes = (value) => Buffer.byteLength(JSON.stringify(value), "utf8");
1615
+ var boundedDetails = (sourceEntries, facts, sections, request, oldLeafId) => {
1616
+ const sampled = sampleAddressed(facts, FABRIC_BRANCH_SUMMARY_MAX_FACTS);
1617
+ const details = {
1618
+ kind: FABRIC_BRANCH_SUMMARY_KIND,
1619
+ version: FABRIC_BRANCH_SUMMARY_VERSION,
1620
+ source: {
1621
+ firstEntryId: sourceEntries[0]?.id ?? "",
1622
+ lastEntryId: sourceEntries.at(-1)?.id ?? "",
1623
+ entryCount: sourceEntries.length,
1624
+ oldLeafId
1625
+ },
1626
+ facts: sampled.values,
1627
+ omittedFacts: sampled.omitted,
1628
+ sections,
1629
+ request: {
1630
+ text: request.text,
1631
+ sourceBytes: request.sourceBytes,
1632
+ truncated: request.truncated
1633
+ }
1634
+ };
1635
+ for (let index = details.facts.length - 1; serializedBytes(details) > FABRIC_BRANCH_SUMMARY_MAX_BYTES && index >= 0; index--) {
1636
+ const fact = details.facts[index];
1637
+ if (fact.kind === "operation" && fact.result !== void 0) delete fact.result;
1638
+ }
1639
+ while (serializedBytes(details) > FABRIC_BRANCH_SUMMARY_MAX_BYTES && details.facts.length > 0) {
1640
+ const middle = Math.floor(details.facts.length / 2);
1641
+ details.facts.splice(middle, 1);
1642
+ details.omittedFacts += 1;
1643
+ }
1644
+ return details;
1645
+ };
1646
+ var compileFabricBranchSummary = (entriesToSummarize, customInstructions, enrichers = NO_BUILTIN_ENRICHERS, oldLeafId = null) => {
1647
+ const instructions = decodeCompactionInstructions(customInstructions);
1648
+ if (!instructions.ok) return void 0;
1649
+ const events = normalizeEntries(entriesToSummarize);
1650
+ if (events.length === 0) return void 0;
1651
+ const projected = projectWithMetadata(events);
1652
+ runEnrichers(enrichers, events, projected.sections);
1653
+ const request = {
1654
+ text: instructions.requestLines.join("\n"),
1655
+ sourceBytes: instructions.policy.sourceBytes,
1656
+ truncated: instructions.policy.truncated
1657
+ };
1658
+ const sections = SECTION_HEADERS.filter(({ key }) => projected.sections[key].length > 0).map(({ header }) => header);
1659
+ if (request.text) sections.splice(1, 0, "[Compaction Request]");
1660
+ const summary = renderSummary(projected.sections, {
1661
+ firstEntryId: entriesToSummarize[0]?.id ?? "",
1662
+ lastEntryId: entriesToSummarize.at(-1)?.id ?? "",
1663
+ lastTimestamp: entriesToSummarize.at(-1)?.timestamp ?? "",
1664
+ ...instructions.requestLines.length > 0 ? { requestLines: instructions.requestLines } : {},
1665
+ summaryKind: "branch"
1666
+ });
1667
+ return {
1668
+ summary,
1669
+ details: boundedDetails(entriesToSummarize, factsFromEvents(events), sections, request, oldLeafId)
1670
+ };
1671
+ };
1672
+
1673
+ // src/compaction/hook.ts
1674
+ var SUMMARY_RAW_TOKEN_BUDGET = Math.ceil(MAX_SUMMARY_BYTES / 4);
1675
+ var HARD_CEILING_SAFETY_RATIO = 0.9;
1676
+ var MAX_PRECOMPACTION_RATIO = 0.95;
1677
+ var isMessageEntry2 = (entry) => entry.type === "message";
1678
+ var isHiddenEmptyCustom = (message) => {
1679
+ if (!message || typeof message !== "object") return false;
1680
+ const candidate = message;
1681
+ if (candidate.role !== "custom" || candidate.display !== false) return false;
1682
+ const content = candidate.content;
1683
+ return content === "" || Array.isArray(content) && content.length === 0;
1684
+ };
1685
+ var toolCallIdsOf = (message) => {
1686
+ const content = message.content;
1687
+ if (!Array.isArray(content)) return [];
1688
+ const ids = [];
1689
+ for (const part of content) {
1690
+ if (!part || typeof part !== "object" || !("type" in part) || part.type !== "toolCall") continue;
1691
+ const id = part.id;
1692
+ if (typeof id === "string") ids.push(id);
1693
+ }
1694
+ return ids;
1695
+ };
1696
+ var contextMessages = (entry) => {
1697
+ try {
1698
+ return sessionEntryToContextMessages(entry);
1699
+ } catch {
1700
+ return [];
1701
+ }
1702
+ };
1703
+ var findLastCompaction = (entries) => {
1704
+ for (let index = entries.length - 1; index >= 0; index--) {
1705
+ const entry = entries[index];
1706
+ if (entry.type === "compaction") {
1707
+ return { index, firstKeptEntryId: entry.firstKeptEntryId };
1708
+ }
1709
+ }
1710
+ return void 0;
1711
+ };
1712
+ var collectContextEntries = (entries, startIndex) => {
1713
+ const contextEntries = [];
1714
+ for (let index = Math.max(0, startIndex); index < entries.length; index++) {
1715
+ const entry = entries[index];
1716
+ if (entry.type === "compaction") continue;
1717
+ if (entry.type === "custom_message" && !isOmpCustomMessageEntry(entry)) continue;
1718
+ if (isMessageEntry2(entry) && isHiddenEmptyCustom(entry.message)) continue;
1719
+ const messages = contextMessages(entry);
1720
+ if (messages.length === 0) continue;
1721
+ const roles = messages.map((message) => message.role);
1722
+ const rawMessage = isMessageEntry2(entry) ? entry.message : void 0;
1723
+ contextEntries.push({
1724
+ entry,
1725
+ branchIndex: index,
1726
+ turnBoundary: roles.some((role) => role === "user" || role === "custom" || role === "bashExecution" || role === "branchSummary" || role === "compactionSummary"),
1727
+ cutPoint: roles.some((role) => role !== "toolResult"),
1728
+ estimatedTokens: messages.reduce((total, message) => total + estimateTokens(message), 0),
1729
+ ...rawMessage ? { message: rawMessage } : {}
1730
+ });
1731
+ }
1732
+ return contextEntries;
1733
+ };
1734
+ var collectLive = (entries) => {
1735
+ const last = findLastCompaction(entries);
1736
+ if (!last) return collectContextEntries(entries, 0);
1737
+ if (last.firstKeptEntryId) {
1738
+ const keptIndex = entries.findIndex((entry) => entry.id === last.firstKeptEntryId);
1739
+ if (keptIndex >= 0) return collectContextEntries(entries, keptIndex);
1740
+ }
1741
+ return collectContextEntries(entries, last.index + 1);
1742
+ };
1743
+ var previousBoundaryAtOrBefore = (live, branchIndex) => {
1744
+ for (let index = live.length - 1; index >= 0; index--) {
1745
+ const item = live[index];
1746
+ if (item.branchIndex <= branchIndex && item.turnBoundary) return index;
1747
+ }
1748
+ return -1;
1749
+ };
1750
+ var lastBoundaryIndex = (live) => {
1751
+ for (let index = live.length - 1; index >= 0; index--) {
1752
+ if (live[index].turnBoundary) return index;
1753
+ }
1754
+ return -1;
1755
+ };
1756
+ var callResultSpans = (entries) => {
1757
+ const spans = /* @__PURE__ */ new Map();
1758
+ const record = (id, index, kind) => {
1759
+ if (!id) return;
1760
+ const span = spans.get(id) ?? {
1761
+ first: index,
1762
+ last: index,
1763
+ hasCall: false,
1764
+ hasResult: false
1765
+ };
1766
+ span.first = Math.min(span.first, index);
1767
+ span.last = Math.max(span.last, index);
1768
+ if (kind === "call") span.hasCall = true;
1769
+ else span.hasResult = true;
1770
+ spans.set(id, span);
1771
+ };
1772
+ for (let index = 0; index < entries.length; index++) {
1773
+ const entry = entries[index];
1774
+ if (!isMessageEntry2(entry)) continue;
1775
+ const message = entry.message;
1776
+ for (const id of toolCallIdsOf(message)) record(id, index, "call");
1777
+ if (message.role === "toolResult" && typeof message.toolCallId === "string") {
1778
+ record(message.toolCallId, index, "result");
1779
+ }
1780
+ }
1781
+ return spans;
1782
+ };
1783
+ var spanCrosses = (span, boundaryIndex) => span.hasCall && span.hasResult && span.first < boundaryIndex && span.last >= boundaryIndex;
1784
+ var closureSafe = (spans, boundaryIndex) => [...spans.values()].every((span) => !spanCrosses(span, boundaryIndex));
1785
+ var closeCut = (branchEntries, live, candidateLiveIndex) => {
1786
+ const spans = callResultSpans(branchEntries);
1787
+ let liveIndex = candidateLiveIndex;
1788
+ while (liveIndex > 0) {
1789
+ const boundaryIndex = live[liveIndex].branchIndex;
1790
+ let earliestCrossing = boundaryIndex;
1791
+ for (const span of spans.values()) {
1792
+ if (spanCrosses(span, boundaryIndex)) {
1793
+ earliestCrossing = Math.min(earliestCrossing, span.first);
1794
+ }
1795
+ }
1796
+ if (earliestCrossing === boundaryIndex) return liveIndex;
1797
+ const closed = previousBoundaryAtOrBefore(live, earliestCrossing);
1798
+ if (closed < 0 || closed >= liveIndex) return 0;
1799
+ liveIndex = closed;
1800
+ }
1801
+ return 0;
1802
+ };
1803
+ var rawContextTokens = (branchEntries) => buildSessionContext(branchEntries).messages.reduce(
1804
+ (total, message) => total + estimateTokens(message),
1805
+ 0
1806
+ );
1807
+ var usageCheckpoints = (branchEntries) => {
1808
+ const lastCompaction = findLastCompaction(branchEntries);
1809
+ const startIndex = lastCompaction ? lastCompaction.index + 1 : 0;
1810
+ let rawTokens = lastCompaction ? rawContextTokens(branchEntries.slice(0, lastCompaction.index + 1)) : 0;
1811
+ const checkpoints = [];
1812
+ for (let index = startIndex; index < branchEntries.length; index++) {
1813
+ for (const message of contextMessages(branchEntries[index])) {
1814
+ rawTokens += estimateTokens(message);
1815
+ if (message.role !== "assistant") continue;
1816
+ const contextTokens = calculateContextTokens(message.usage);
1817
+ if (Number.isFinite(contextTokens) && contextTokens > 0) {
1818
+ checkpoints.push({ rawTokens, contextTokens });
1819
+ }
1820
+ }
1821
+ }
1822
+ return checkpoints;
1823
+ };
1824
+ var tokenCalibration = (branchEntries, tokensBefore, rawTokensBefore) => {
1825
+ const minimumDelta = Math.max(4096, Math.floor(rawTokensBefore * 0.1));
1826
+ const checkpoints = usageCheckpoints(branchEntries).filter(
1827
+ (checkpoint) => checkpoint.rawTokens < rawTokensBefore && checkpoint.contextTokens <= tokensBefore
1828
+ );
1829
+ const slopes = checkpoints.flatMap((checkpoint) => {
1830
+ const rawDelta = rawTokensBefore - checkpoint.rawTokens;
1831
+ const contextDelta = tokensBefore - checkpoint.contextTokens;
1832
+ return rawDelta >= minimumDelta && contextDelta >= 0 ? [contextDelta / rawDelta] : [];
1833
+ }).filter((slope) => Number.isFinite(slope) && slope >= 0);
1834
+ if (slopes.length === 0) {
1835
+ return {
1836
+ tokenScale: 1,
1837
+ fixedOverheadTokens: Math.max(0, tokensBefore - rawTokensBefore)
1838
+ };
1839
+ }
1840
+ const tokenScale = Math.max(1, ...slopes);
1841
+ const fixedOverheadTokens = Math.max(
1842
+ 0,
1843
+ tokensBefore - tokenScale * rawTokensBefore,
1844
+ ...checkpoints.map(
1845
+ (checkpoint) => checkpoint.contextTokens - tokenScale * checkpoint.rawTokens
1846
+ )
1847
+ );
1848
+ return { tokenScale, fixedOverheadTokens };
1849
+ };
1850
+ var continuityCutPlan = (branchEntries, tokensBefore, budget) => {
1851
+ if (!Number.isFinite(budget.contextWindow) || budget.contextWindow <= 0) return void 0;
1852
+ const contextWindow = Math.floor(budget.contextWindow);
1853
+ const reserveTokens = Math.max(0, Math.floor(budget.reserveTokens));
1854
+ const keepRecentTokens = Math.max(0, Math.floor(budget.keepRecentTokens));
1855
+ const targetContextRatio = Math.max(0.25, Math.min(0.85, budget.targetContextRatio));
1856
+ const rawTokensBefore = rawContextTokens(branchEntries);
1857
+ const { tokenScale, fixedOverheadTokens } = tokenCalibration(
1858
+ branchEntries,
1859
+ tokensBefore,
1860
+ rawTokensBefore
1861
+ );
1862
+ const continuityTargetTokens = Math.max(1, Math.ceil(
1863
+ fixedOverheadTokens + (keepRecentTokens + SUMMARY_RAW_TOKEN_BUDGET) * tokenScale
1864
+ ));
1865
+ const occupancyCeilingTokens = Math.max(1, Math.floor(contextWindow * targetContextRatio));
1866
+ const hardCeiling = Math.max(1, contextWindow - reserveTokens);
1867
+ const safeCeilingTokens = Math.max(1, Math.floor(hardCeiling * HARD_CEILING_SAFETY_RATIO));
1868
+ const reductionCeilingTokens = Math.max(1, Math.floor(tokensBefore * MAX_PRECOMPACTION_RATIO));
1869
+ const constraints = [
1870
+ { binding: "continuity", tokens: continuityTargetTokens },
1871
+ { binding: "occupancy", tokens: occupancyCeilingTokens },
1872
+ { binding: "reserve", tokens: safeCeilingTokens },
1873
+ { binding: "reduction", tokens: reductionCeilingTokens }
1874
+ ];
1875
+ const targetContextTokens = Math.min(...constraints.map(({ tokens }) => tokens));
1876
+ const bindingConstraint = constraints.find(
1877
+ ({ tokens }) => tokens === targetContextTokens
1878
+ ).binding;
1879
+ const rawPostBudget = Math.max(
1880
+ 0,
1881
+ Math.floor((targetContextTokens - fixedOverheadTokens) / tokenScale)
1882
+ );
1883
+ return {
1884
+ contextWindow,
1885
+ targetContextRatio,
1886
+ targetContextTokens,
1887
+ reserveTokens,
1888
+ keepRecentTokens,
1889
+ rawTokensBefore,
1890
+ tokenScale,
1891
+ fixedOverheadTokens,
1892
+ continuityTargetTokens,
1893
+ occupancyCeilingTokens,
1894
+ safeCeilingTokens,
1895
+ reductionCeilingTokens,
1896
+ rawTailTokenBudget: Math.max(0, rawPostBudget - SUMMARY_RAW_TOKEN_BUDGET),
1897
+ bindingConstraint
1898
+ };
1899
+ };
1900
+ var boundary = (summarized, firstKeptEntryId, budget) => {
1901
+ if (summarized.length === 0) return { ok: false, reason: "empty" };
1902
+ const first = summarized[0];
1903
+ const last = summarized.at(-1);
1904
+ return {
1905
+ ok: true,
1906
+ summarized,
1907
+ firstKeptEntryId,
1908
+ firstSummarizedEntryId: first.id,
1909
+ lastSummarizedEntryId: last.id,
1910
+ lastTimestamp: last.timestamp,
1911
+ ...budget ? { budget } : {}
1912
+ };
1913
+ };
1914
+ var computeContinuityCut = (branchEntries, live, plan) => {
1915
+ const suffixTokens = new Array(live.length + 1).fill(0);
1916
+ for (let index = live.length - 1; index >= 0; index--) {
1917
+ suffixTokens[index] = suffixTokens[index + 1] + live[index].estimatedTokens;
1918
+ }
1919
+ const spans = callResultSpans(branchEntries);
1920
+ const previousCompactionIndex = findLastCompaction(branchEntries)?.index ?? -1;
1921
+ let cutIndex = live.length;
1922
+ for (let index = 1; index < live.length; index++) {
1923
+ const item = live[index];
1924
+ if (item.branchIndex <= previousCompactionIndex) continue;
1925
+ if (!item.cutPoint || suffixTokens[index] > plan.rawTailTokenBudget) continue;
1926
+ if (!closureSafe(spans, item.branchIndex)) continue;
1927
+ cutIndex = index;
1928
+ break;
1929
+ }
1930
+ const retainedRawTokens = suffixTokens[cutIndex] ?? 0;
1931
+ const details = {
1932
+ strategy: "continuity",
1933
+ contextWindow: plan.contextWindow,
1934
+ targetContextRatio: plan.targetContextRatio,
1935
+ targetContextTokens: plan.targetContextTokens,
1936
+ reserveTokens: plan.reserveTokens,
1937
+ keepRecentTokens: plan.keepRecentTokens,
1938
+ rawTokensBefore: plan.rawTokensBefore,
1939
+ tokenScale: plan.tokenScale,
1940
+ fixedOverheadTokens: plan.fixedOverheadTokens,
1941
+ retainedRawTokens,
1942
+ continuityTargetTokens: plan.continuityTargetTokens,
1943
+ occupancyCeilingTokens: plan.occupancyCeilingTokens,
1944
+ safeCeilingTokens: plan.safeCeilingTokens,
1945
+ reductionCeilingTokens: plan.reductionCeilingTokens,
1946
+ rawTailTokenBudget: plan.rawTailTokenBudget,
1947
+ bindingConstraint: plan.bindingConstraint
1948
+ };
1949
+ if (cutIndex >= live.length) {
1950
+ return boundary(live.map((item) => item.entry), "", details);
1951
+ }
1952
+ return boundary(
1953
+ live.slice(0, cutIndex).map((item) => item.entry),
1954
+ live[cutIndex].entry.id,
1955
+ details
1956
+ );
1957
+ };
1958
+ var computeCut = (branchEntries, options) => {
1959
+ const live = collectLive(branchEntries);
1960
+ if (live.length === 0) return { ok: false, reason: "empty" };
1961
+ if (options) {
1962
+ const plan = continuityCutPlan(branchEntries, options.tokensBefore, options.budget);
1963
+ if (plan) return computeContinuityCut(branchEntries, live, plan);
1964
+ }
1965
+ const lastBoundary = lastBoundaryIndex(live);
1966
+ if (lastBoundary <= 0) return boundary(live.map((item) => item.entry), "");
1967
+ const closed = closeCut(branchEntries, live, lastBoundary);
1968
+ const previousCompactionIndex = findLastCompaction(branchEntries)?.index ?? -1;
1969
+ if (closed <= 0 || live[closed].branchIndex <= previousCompactionIndex) {
1970
+ return boundary(live.map((item) => item.entry), "");
1971
+ }
1972
+ return boundary(
1973
+ live.slice(0, closed).map((item) => item.entry),
1974
+ live[closed].entry.id
1975
+ );
1976
+ };
1977
+ var isRecord2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
1978
+ var isEntryRange = (value) => isRecord2(value) && typeof value.first === "string" && typeof value.last === "string";
1979
+ var isStringArray = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
1980
+ var isFabricV1Details = (value) => isStringArray(value.sections) && isEntryRange(value.summarizedEntryRange) && typeof value.sourceEntryCount === "number" && Number.isFinite(value.sourceEntryCount) && typeof value.firstKeptEntryId === "string" && typeof value.timestamp === "string";
1981
+ var hasFiniteNumbers = (value, keys) => keys.every((key) => typeof value[key] === "number" && Number.isFinite(value[key]));
1982
+ var isCompactionBudgetDetails = (value) => {
1983
+ if (!isRecord2(value) || value.strategy !== "adaptive" && value.strategy !== "continuity") {
1984
+ return false;
1985
+ }
1986
+ if (!hasFiniteNumbers(value, [
1987
+ "contextWindow",
1988
+ "targetContextRatio",
1989
+ "targetContextTokens",
1990
+ "reserveTokens",
1991
+ "keepRecentTokens",
1992
+ "rawTokensBefore",
1993
+ "tokenScale",
1994
+ "fixedOverheadTokens",
1995
+ "retainedRawTokens",
1996
+ "projectedTokensAfter"
1997
+ ])) {
1998
+ return false;
1999
+ }
2000
+ if (value.strategy === "adaptive") return true;
2001
+ return hasFiniteNumbers(value, [
2002
+ "continuityTargetTokens",
2003
+ "occupancyCeilingTokens",
2004
+ "safeCeilingTokens",
2005
+ "reductionCeilingTokens",
2006
+ "rawTailTokenBudget"
2007
+ ]) && (value.bindingConstraint === "continuity" || value.bindingConstraint === "occupancy" || value.bindingConstraint === "reserve" || value.bindingConstraint === "reduction");
2008
+ };
2009
+ var isFabricV2Details = (value) => {
2010
+ if (!isStringArray(value.sections) || !isRecord2(value.coverage) || !isRecord2(value.counts)) return false;
2011
+ if (!isRecord2(value.omittedCounts) || !isRecord2(value.instructionPolicy) || !isRecord2(value.stableAddresses)) {
2012
+ return false;
2013
+ }
2014
+ const instructionModes = /* @__PURE__ */ new Set(["none", "plain", "typed-v1", "malformed-typed-prefix"]);
2015
+ return isEntryRange(value.coverage.cumulativeSourceRange) && isEntryRange(value.coverage.liveCutRange) && hasFiniteNumbers(value.counts, [
2016
+ "branchEntries",
2017
+ "cumulativeSourceEntries",
2018
+ "sourceEvents",
2019
+ "liveCutEntries",
2020
+ "priorFabricV1",
2021
+ "priorFabricV2"
2022
+ ]) && hasFiniteNumbers(value.omittedCounts, [
2023
+ "goal",
2024
+ "files",
2025
+ "outstanding",
2026
+ "earlierTurns",
2027
+ "transcript",
2028
+ "preserve"
2029
+ ]) && (value.omittedCounts.activity === void 0 || typeof value.omittedCounts.activity === "number" && Number.isFinite(value.omittedCounts.activity)) && (value.omittedCounts.commits === void 0 || typeof value.omittedCounts.commits === "number" && Number.isFinite(value.omittedCounts.commits)) && (value.omittedCounts.thinking === void 0 || typeof value.omittedCounts.thinking === "number" && Number.isFinite(value.omittedCounts.thinking)) && typeof value.instructionPolicy.mode === "string" && instructionModes.has(value.instructionPolicy.mode) && typeof value.instructionPolicy.canonicalized === "boolean" && typeof value.instructionPolicy.truncated === "boolean" && hasFiniteNumbers(value.instructionPolicy, [
2030
+ "sourceBytes",
2031
+ "preserveCount",
2032
+ "omittedPreserveCount"
2033
+ ]) && typeof value.stableAddresses.firstKeptEntryId === "string" && isEntryRange(value.stableAddresses.cumulativeSourceRange) && value.stableAddresses.recall === "session-entry-id-range" && (value.budget === void 0 || isCompactionBudgetDetails(value.budget)) && typeof value.timestamp === "string";
2034
+ };
2035
+ var fabricCompactionVersion = (details) => {
2036
+ if (!isRecord2(details) || details.compactor !== "fabric") return void 0;
2037
+ if (details.version === 1 && isFabricV1Details(details)) return 1;
2038
+ if (details.version === 2 && isFabricV2Details(details)) return 2;
2039
+ return void 0;
2040
+ };
2041
+ var cumulativeSource = (branchEntries, firstKeptEntryId) => {
2042
+ const boundaryIndex = firstKeptEntryId ? branchEntries.findIndex((entry) => entry.id === firstKeptEntryId) : branchEntries.length;
2043
+ const prefix = branchEntries.slice(0, boundaryIndex >= 0 ? boundaryIndex : branchEntries.length);
2044
+ const events = normalizeEntries(prefix);
2045
+ const contentEntryIds = new Set(events.map((event) => event.sourceEntryId));
2046
+ const entries = prefix.filter((entry) => contentEntryIds.has(entry.id));
2047
+ return {
2048
+ entries,
2049
+ prefixEntries: prefix,
2050
+ events,
2051
+ range: {
2052
+ first: entries[0]?.id ?? "",
2053
+ last: entries.at(-1)?.id ?? ""
2054
+ },
2055
+ timestamp: entries.at(-1)?.timestamp ?? ""
2056
+ };
2057
+ };
2058
+ var priorFabricVersions = (entries) => {
2059
+ let v1 = 0;
2060
+ let v2 = 0;
2061
+ for (const entry of entries) {
2062
+ if (entry.type !== "compaction") continue;
2063
+ const version = fabricCompactionVersion(entry.details);
2064
+ if (version === 1) v1 += 1;
2065
+ if (version === 2) v2 += 1;
2066
+ }
2067
+ return { v1, v2 };
2068
+ };
2069
+ var compileFabricSummary = (branchEntries, tokensBefore, enrichers = NO_BUILTIN_ENRICHERS, customInstructions, budget) => {
2070
+ const instructions = decodeCompactionInstructions(customInstructions);
2071
+ if (!instructions.ok) {
2072
+ return {
2073
+ cancel: true,
2074
+ reason: `fabric: ${instructions.error.code}: ${instructions.error.message}`,
2075
+ instructionError: instructions.error
2076
+ };
2077
+ }
2078
+ const cut = computeCut(
2079
+ branchEntries,
2080
+ budget ? { tokensBefore, budget } : void 0
2081
+ );
2082
+ if (!cut.ok) return { cancel: true, reason: "fabric: nothing to compact" };
2083
+ const source = cumulativeSource(branchEntries, cut.firstKeptEntryId);
2084
+ if (source.events.length === 0) return { cancel: true, reason: "fabric: no raw cumulative source" };
2085
+ const projected = projectWithMetadata(source.events);
2086
+ const sections = projected.sections;
2087
+ runEnrichers(enrichers, source.events, sections);
2088
+ const summary = renderSummary(sections, {
2089
+ firstEntryId: source.range.first,
2090
+ lastEntryId: source.range.last,
2091
+ lastTimestamp: source.timestamp,
2092
+ requestLines: instructions.requestLines
2093
+ });
2094
+ const projectedTokensAfter = cut.budget ? Math.ceil(
2095
+ cut.budget.fixedOverheadTokens + (cut.budget.retainedRawTokens + Math.ceil(summary.length / 4)) * cut.budget.tokenScale
2096
+ ) : void 0;
2097
+ const budgetDetails = cut.budget && projectedTokensAfter !== void 0 ? { ...cut.budget, projectedTokensAfter } : void 0;
2098
+ if (budgetDetails && budgetDetails.projectedTokensAfter > budgetDetails.targetContextTokens) {
2099
+ return {
2100
+ cancel: true,
2101
+ reason: "fabric: no deterministic summary fits the continuity context target"
2102
+ };
2103
+ }
2104
+ const versions = priorFabricVersions(branchEntries);
2105
+ const sectionHeaders = SECTION_HEADERS2.filter(({ key }) => sections[key].length > 0).map(({ header }) => header);
2106
+ if (instructions.requestLines.length > 0) sectionHeaders.splice(1, 0, "[Compaction Request]");
2107
+ const details = {
2108
+ compactor: "fabric",
2109
+ version: 2,
2110
+ sections: sectionHeaders,
2111
+ coverage: {
2112
+ cumulativeSourceRange: source.range,
2113
+ liveCutRange: {
2114
+ first: cut.firstSummarizedEntryId,
2115
+ last: cut.lastSummarizedEntryId
2116
+ }
2117
+ },
2118
+ counts: {
2119
+ branchEntries: branchEntries.length,
2120
+ cumulativeSourceEntries: source.entries.length,
2121
+ sourceEvents: source.events.length,
2122
+ liveCutEntries: cut.summarized.length,
2123
+ priorFabricV1: versions.v1,
2124
+ priorFabricV2: versions.v2
2125
+ },
2126
+ omittedCounts: {
2127
+ ...projected.omittedCounts,
2128
+ preserve: instructions.policy.omittedPreserveCount,
2129
+ // Thinking parts never survive normalization into a rendered summary;
2130
+ // the structural count keeps that erasure auditable against the raw
2131
+ // prefix instead of letting deliberation vanish untracked.
2132
+ thinking: countErasedThinkingBlocks(source.prefixEntries)
2133
+ },
2134
+ instructionPolicy: instructions.policy,
2135
+ stableAddresses: {
2136
+ firstKeptEntryId: cut.firstKeptEntryId,
2137
+ cumulativeSourceRange: source.range,
2138
+ recall: "session-entry-id-range"
2139
+ },
2140
+ ...budgetDetails ? { budget: budgetDetails } : {},
2141
+ timestamp: source.timestamp
2142
+ };
2143
+ return {
2144
+ compaction: {
2145
+ summary,
2146
+ firstKeptEntryId: cut.firstKeptEntryId,
2147
+ tokensBefore,
2148
+ details
2149
+ }
2150
+ };
2151
+ };
2152
+ var SECTION_HEADERS2 = [
2153
+ { key: "goal", header: "[Session Goal]" },
2154
+ { key: "files", header: "[Files And Changes]" },
2155
+ { key: "activity", header: "[Fabric Activity]" },
2156
+ { key: "outstanding", header: "[Outstanding Context]" },
2157
+ { key: "earlierTurns", header: "[Earlier Turns]" },
2158
+ { key: "status", header: "[Current Status]" }
2159
+ ];
2160
+ var notifyInstructionError = (context, error) => {
2161
+ if (!context?.hasUI) return;
2162
+ context.ui.notify(clipUtf8(`Fabric compaction rejected: ${error.code}: ${error.message}`, 512), "error");
2163
+ };
2164
+ var registerCompactionHook = (omp, options) => {
2165
+ omp.on("session_before_compact", (event, context) => {
2166
+ if (options.getEngine() !== "fabric") return;
2167
+ const { preparation, branchEntries } = event;
2168
+ const contextWindow = context?.model?.contextWindow;
2169
+ const targetContextRatio = options.getTargetContextRatio?.();
2170
+ const settings = preparation.settings ?? DEFAULT_COMPACTION_SETTINGS;
2171
+ const budget = typeof contextWindow === "number" && Number.isFinite(contextWindow) && contextWindow > 0 && typeof targetContextRatio === "number" && Number.isFinite(targetContextRatio) ? { contextWindow, targetContextRatio, reserveTokens: settings.reserveTokens ?? DEFAULT_COMPACTION_SETTINGS.reserveTokens, keepRecentTokens: settings.keepRecentTokens } : void 0;
2172
+ const result = compileFabricSummary(branchEntries ?? [], preparation.tokensBefore, options.enrichers, event.customInstructions, budget);
2173
+ if ("cancel" in result) {
2174
+ if (result.instructionError) {
2175
+ notifyInstructionError(context, result.instructionError);
2176
+ return { cancel: true };
2177
+ }
2178
+ return { cancel: true };
2179
+ }
2180
+ event._fabricCompaction = true;
2181
+ return { compaction: result.compaction };
2182
+ });
2183
+ omp.on("session_before_tree", (event, context) => {
2184
+ if (options.getEngine() !== "fabric") return;
2185
+ const { preparation } = event;
2186
+ if (!preparation.userWantsSummary) return;
2187
+ const compiled = compileFabricBranchSummary(preparation.entriesToSummarize, void 0, options.enrichers, preparation.oldLeafId);
2188
+ if (!compiled) return;
2189
+ return { summary: compiled };
2190
+ });
2191
+ };
2192
+
2193
+ export {
2194
+ compactAtConfiguredThreshold,
2195
+ MAX_COMPACTION_INSTRUCTIONS_CHARS,
2196
+ MAX_PRESERVE_ITEMS,
2197
+ MAX_PRESERVE_ITEM_CHARS,
2198
+ compactionRequestBoundsError,
2199
+ encodeCompactionRequest,
2200
+ normalizeRunDisplay,
2201
+ fabricExecTitleHintCached,
2202
+ rawContextTokens,
2203
+ computeCut,
2204
+ fabricCompactionVersion,
2205
+ compileFabricSummary,
2206
+ registerCompactionHook
2207
+ };
2208
+ //# sourceMappingURL=chunk-KIREBD2V.js.map