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,2203 @@
1
+ import {
2
+ withExclusiveFileLock,
3
+ withExclusiveFileLockAsync
4
+ } from "./chunk-YWEXP724.js";
5
+ import {
6
+ COMPILED_SURFACE_VERSION,
7
+ MAX_COMPILED_SURFACE_PROPOSALS,
8
+ applyCompiledSurface,
9
+ replaySuccessfulCalls,
10
+ replaySuccessfulCallsAsync,
11
+ schemaDigest
12
+ } from "./chunk-4A4MVZQW.js";
13
+ import {
14
+ sessionDirForCwd,
15
+ sessionsDirRoot
16
+ } from "./chunk-7BIA5BJN.js";
17
+ import {
18
+ stableJsonHash,
19
+ stableJsonHashArrayAsync
20
+ } from "./chunk-7363CD5A.js";
21
+ import {
22
+ writeJsonAtomic,
23
+ writeJsonAtomicAsync
24
+ } from "./chunk-KAD7UWT2.js";
25
+ import {
26
+ FABRIC_EXECUTION_TRACE_KIND,
27
+ readFabricExecutionTraceV1
28
+ } from "./chunk-T5ZA5YRU.js";
29
+
30
+ // src/entropy/types.ts
31
+ var ENTROPY_METRIC_VERSION = 2;
32
+ var ENTROPY_WEIGHTS = {
33
+ shape: 1,
34
+ failureStage: 1,
35
+ churn: 4,
36
+ navigation: 4,
37
+ flow: 1,
38
+ lexicon: 2,
39
+ staticFreedom: 0.25
40
+ };
41
+ var ENTROPY_INVOCATION_STAGES = ["resolve", "prepare", "validate"];
42
+
43
+ // src/entropy/fingerprint.ts
44
+ var SIGNATURE_MAX_KEYS = 32;
45
+ var SIGNATURE_MAX_DEPTH = 3;
46
+ var ENUM_SATURATION_BITS = 6;
47
+ var isPlainRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
48
+ var roundMetric = (value) => {
49
+ const rounded = Math.round(value * 1e6) / 1e6;
50
+ return rounded === 0 ? 0 : rounded;
51
+ };
52
+ var compareCodeUnits = (left, right) => left < right ? -1 : left > right ? 1 : 0;
53
+ var typeTag = (value, depth) => {
54
+ if (value === null) return "null";
55
+ if (Array.isArray(value)) return "arr";
56
+ switch (typeof value) {
57
+ case "string":
58
+ return "str";
59
+ case "number":
60
+ return "num";
61
+ case "boolean":
62
+ return "bool";
63
+ case "object": {
64
+ if (depth >= SIGNATURE_MAX_DEPTH) return "obj";
65
+ try {
66
+ const record = value;
67
+ const keys = Object.keys(record).sort();
68
+ const head = keys.slice(0, SIGNATURE_MAX_KEYS).map((key) => `${key}:${typeTag(record[key], depth + 1)}`);
69
+ if (keys.length > SIGNATURE_MAX_KEYS) {
70
+ head.push(`\u2026+${keys.length - SIGNATURE_MAX_KEYS}`);
71
+ }
72
+ return `{${head.join(",")}}`;
73
+ } catch {
74
+ return "obj";
75
+ }
76
+ }
77
+ default:
78
+ return "other";
79
+ }
80
+ };
81
+ var shapeSignature = (args) => {
82
+ const keys = Object.keys(args).sort();
83
+ const head = keys.slice(0, SIGNATURE_MAX_KEYS).map((key) => `${key}:${typeTag(args[key], 1)}`);
84
+ if (keys.length > SIGNATURE_MAX_KEYS) {
85
+ head.push(`\u2026+${keys.length - SIGNATURE_MAX_KEYS}`);
86
+ }
87
+ return `(${head.join(",")})`;
88
+ };
89
+ var signatureDistance = (left, right) => {
90
+ if (left === right) return 0;
91
+ const bound = Math.max(left.length, right.length);
92
+ if (bound === 0) return 0;
93
+ let previous = [];
94
+ for (let index = 0; index <= right.length; index++) {
95
+ previous.push(index);
96
+ }
97
+ for (let index = 1; index <= left.length; index++) {
98
+ const current = [index];
99
+ for (let inner = 1; inner <= right.length; inner++) {
100
+ const substitution = previous[inner - 1] + (left[index - 1] === right[inner - 1] ? 0 : 1);
101
+ const insertion = current[inner - 1] + 1;
102
+ const deletion = previous[inner] + 1;
103
+ current.push(Math.min(substitution, insertion, deletion));
104
+ }
105
+ previous = current;
106
+ }
107
+ return roundMetric(previous[right.length] / bound);
108
+ };
109
+ var shannonEntropyBits = (counts) => {
110
+ const total = counts.reduce((sum, value) => sum + value, 0);
111
+ if (total <= 0) return 0;
112
+ let bits = 0;
113
+ for (const count of counts) {
114
+ if (count <= 0) continue;
115
+ const probability = count / total;
116
+ bits += probability * Math.log2(probability);
117
+ }
118
+ return roundMetric(-bits);
119
+ };
120
+ var schemaFreedom = (schema, depth) => {
121
+ if (depth > SIGNATURE_MAX_DEPTH) return 0.5;
122
+ if (!isPlainRecord(schema)) return 0.5;
123
+ const union = Array.isArray(schema.anyOf) ? schema.anyOf : Array.isArray(schema.oneOf) ? schema.oneOf : void 0;
124
+ if (union) {
125
+ const scores = union.map((branch) => schemaFreedom(branch, depth + 1));
126
+ const widest = scores.length > 0 ? Math.max(...scores) : 0;
127
+ return roundMetric(widest + 0.1 * Math.max(0, union.length - 1));
128
+ }
129
+ if (Array.isArray(schema.enum)) {
130
+ return roundMetric(
131
+ Math.min(1, Math.log2(Math.max(1, schema.enum.length)) / ENUM_SATURATION_BITS)
132
+ );
133
+ }
134
+ if ("const" in schema) return 0;
135
+ const type = schema.type;
136
+ if (typeof type !== "string") return 0.75;
137
+ if (type === "boolean") return 0.1;
138
+ if (type === "number" || type === "integer") return 0.5;
139
+ if (type === "string") return 1;
140
+ if (type === "array") return roundMetric(0.5 + 0.5 * schemaFreedom(schema.items, depth + 1));
141
+ if (type === "object") {
142
+ const properties = schema.properties;
143
+ if (!isPlainRecord(properties)) return 1;
144
+ const keys = Object.keys(properties).sort();
145
+ if (keys.length === 0) return 1;
146
+ const required = Array.isArray(schema.required) ? schema.required.filter((entry) => typeof entry === "string") : [];
147
+ let score = 0;
148
+ for (const key of keys) {
149
+ score += schemaFreedom(properties[key], depth + 1);
150
+ if (!required.includes(key)) score += 0.25;
151
+ }
152
+ if (schema.additionalProperties !== false) score += 0.5;
153
+ return roundMetric(score);
154
+ }
155
+ return 0.75;
156
+ };
157
+ var staticFreedomFromSchema = (schema) => schemaFreedom(schema, 0);
158
+ var trendFromScores = (scores) => {
159
+ const count = scores.length;
160
+ const first = count > 0 ? scores[0] : void 0;
161
+ const last = count > 0 ? scores[count - 1] : void 0;
162
+ let slope = 0;
163
+ if (count >= 2) {
164
+ const meanX = (count - 1) / 2;
165
+ const meanY = scores.reduce((sum, value) => sum + value, 0) / count;
166
+ let numerator = 0;
167
+ let denominator = 0;
168
+ for (let index = 0; index < count; index++) {
169
+ numerator += (index - meanX) * (scores[index] - meanY);
170
+ denominator += (index - meanX) ** 2;
171
+ }
172
+ slope = denominator > 0 ? numerator / denominator : 0;
173
+ }
174
+ return {
175
+ count,
176
+ ...first !== void 0 ? { first: roundMetric(first) } : {},
177
+ ...last !== void 0 ? { last: roundMetric(last) } : {},
178
+ slopePerStep: roundMetric(slope)
179
+ };
180
+ };
181
+
182
+ // src/entropy/meter.ts
183
+ var DISCOVERY_PREFIX = "fabric.discovery.";
184
+ var WORKFLOW_PREFIX = "fabric.workflow.";
185
+ var DEFAULT_TASK_KEY = "(none)";
186
+ var TOP_SIGNATURES = 8;
187
+ var createMeasureState = (input) => {
188
+ const surfaceByRef = /* @__PURE__ */ new Map();
189
+ if (input.surface) {
190
+ for (const action of input.surface.actions) surfaceByRef.set(action.ref, action.inputSchema);
191
+ }
192
+ const lexiconByRef = /* @__PURE__ */ new Map();
193
+ let lexiconRows = 0;
194
+ for (const row of input.repairs ?? []) {
195
+ lexiconByRef.set(row.ref, (lexiconByRef.get(row.ref) ?? 0) + 1);
196
+ lexiconRows += 1;
197
+ }
198
+ return {
199
+ surfaceByRef,
200
+ lexiconByRef,
201
+ lexiconRows,
202
+ totals: {
203
+ traces: input.traces.length,
204
+ operations: 0,
205
+ actionOperations: 0,
206
+ discoveryOperations: 0,
207
+ workflowOperations: 0,
208
+ succeeded: 0,
209
+ failed: 0,
210
+ aborted: 0,
211
+ timedOut: 0,
212
+ invocationRejections: 0,
213
+ invocationRejectionsPer1k: 0
214
+ },
215
+ refs: /* @__PURE__ */ new Map(),
216
+ taskSequences: /* @__PURE__ */ new Map(),
217
+ churnPairs: 0,
218
+ churnSum: 0
219
+ };
220
+ };
221
+ var accumulatorFor = (state, ref) => {
222
+ const existing = state.refs.get(ref);
223
+ if (existing) return existing;
224
+ const created = {
225
+ calls: 0,
226
+ succeeded: 0,
227
+ failed: 0,
228
+ signatures: /* @__PURE__ */ new Map(),
229
+ stages: /* @__PURE__ */ new Map(),
230
+ churnPairs: 0,
231
+ churnSum: 0
232
+ };
233
+ state.refs.set(ref, created);
234
+ return created;
235
+ };
236
+ var accumulateTrace = (state, sourceTrace) => {
237
+ const taskKey = sourceTrace.taskKey ?? DEFAULT_TASK_KEY;
238
+ const sequence = [];
239
+ const pendingFailed = /* @__PURE__ */ new Map();
240
+ for (const operation of sourceTrace.operations) {
241
+ state.totals.operations += 1;
242
+ if (operation.ref.startsWith(DISCOVERY_PREFIX)) {
243
+ state.totals.discoveryOperations += 1;
244
+ continue;
245
+ }
246
+ if (operation.ref.startsWith(WORKFLOW_PREFIX)) {
247
+ state.totals.workflowOperations += 1;
248
+ continue;
249
+ }
250
+ state.totals.actionOperations += 1;
251
+ sequence.push(operation.ref);
252
+ const acc = accumulatorFor(state, operation.ref);
253
+ acc.calls += 1;
254
+ if (operation.outcome === "succeeded") {
255
+ state.totals.succeeded += 1;
256
+ acc.succeeded += 1;
257
+ } else if (operation.outcome === "failed") {
258
+ state.totals.failed += 1;
259
+ acc.failed += 1;
260
+ } else if (operation.outcome === "aborted") {
261
+ state.totals.aborted += 1;
262
+ } else {
263
+ state.totals.timedOut += 1;
264
+ }
265
+ const signature = shapeSignature(operation.args);
266
+ acc.signatures.set(signature, (acc.signatures.get(signature) ?? 0) + 1);
267
+ if (operation.outcome === "failed") {
268
+ const stage = operation.failureStage ?? "unknown";
269
+ acc.stages.set(stage, (acc.stages.get(stage) ?? 0) + 1);
270
+ if (ENTROPY_INVOCATION_STAGES.includes(stage)) state.totals.invocationRejections += 1;
271
+ }
272
+ const pending = pendingFailed.get(operation.ref);
273
+ if (pending !== void 0) {
274
+ const distance = signatureDistance(pending, signature);
275
+ acc.churnPairs += 1;
276
+ acc.churnSum += distance;
277
+ state.churnPairs += 1;
278
+ state.churnSum += distance;
279
+ pendingFailed.delete(operation.ref);
280
+ }
281
+ if (operation.outcome === "failed") pendingFailed.set(operation.ref, signature);
282
+ }
283
+ if (sequence.length > 0) {
284
+ const key = sequence.join("\u2192");
285
+ const perTask = state.taskSequences.get(taskKey) ?? /* @__PURE__ */ new Map();
286
+ perTask.set(key, (perTask.get(key) ?? 0) + 1);
287
+ state.taskSequences.set(taskKey, perTask);
288
+ }
289
+ };
290
+ var finalizeMeasure = (input, state) => {
291
+ const refEntries = [...state.refs.entries()].sort(
292
+ ([left], [right]) => compareCodeUnits(left, right)
293
+ );
294
+ const refReports = [];
295
+ let staticFreedomTotal = 0;
296
+ let staticWeighted = 0;
297
+ let shapeWeighted = 0;
298
+ let failureStageWeighted = 0;
299
+ let scoreSum = 0;
300
+ for (const [ref, acc] of refEntries) {
301
+ const shapeEntropyBits = shannonEntropyBits([...acc.signatures.values()]);
302
+ const failureStageEntropyBits = shannonEntropyBits([...acc.stages.values()]);
303
+ const refChurnRate = acc.churnPairs > 0 ? roundMetric(acc.churnSum / acc.churnPairs) : 0;
304
+ const lexicon = state.lexiconByRef.get(ref) ?? 0;
305
+ const staticFreedom = state.surfaceByRef.has(ref) ? staticFreedomFromSchema(state.surfaceByRef.get(ref)) : 0;
306
+ staticFreedomTotal += staticFreedom;
307
+ staticWeighted += ENTROPY_WEIGHTS.staticFreedom * staticFreedom;
308
+ shapeWeighted += shapeEntropyBits * acc.calls;
309
+ failureStageWeighted += failureStageEntropyBits * acc.failed;
310
+ const score2 = roundMetric(
311
+ ENTROPY_WEIGHTS.shape * shapeEntropyBits + ENTROPY_WEIGHTS.failureStage * failureStageEntropyBits + ENTROPY_WEIGHTS.churn * refChurnRate + ENTROPY_WEIGHTS.lexicon * lexicon + ENTROPY_WEIGHTS.staticFreedom * staticFreedom
312
+ );
313
+ scoreSum += score2;
314
+ const shapeSignatures = [...acc.signatures.entries()].map(([signature, count]) => ({ signature, count })).sort(
315
+ (left, right) => right.count - left.count || compareCodeUnits(left.signature, right.signature)
316
+ ).slice(0, TOP_SIGNATURES);
317
+ refReports.push({
318
+ ref,
319
+ calls: acc.calls,
320
+ succeeded: acc.succeeded,
321
+ failed: acc.failed,
322
+ shapeSignatures,
323
+ shapeEntropyBits,
324
+ failureStageEntropyBits,
325
+ churnRate: refChurnRate,
326
+ lexiconRows: lexicon,
327
+ staticFreedom,
328
+ score: score2
329
+ });
330
+ }
331
+ const navigationRatio = state.totals.actionOperations > 0 ? roundMetric(state.totals.discoveryOperations / state.totals.actionOperations) : 0;
332
+ let flowWeighted = 0;
333
+ let flowOccurrences = 0;
334
+ for (const perTask of state.taskSequences.values()) {
335
+ const counts = [...perTask.values()];
336
+ const occurrences = counts.reduce((sum, value) => sum + value, 0);
337
+ flowWeighted += shannonEntropyBits(counts) * occurrences;
338
+ flowOccurrences += occurrences;
339
+ }
340
+ const flowEntropyBits = flowOccurrences > 0 ? roundMetric(flowWeighted / flowOccurrences) : 0;
341
+ state.totals.invocationRejectionsPer1k = state.totals.actionOperations > 0 ? roundMetric(state.totals.invocationRejections / state.totals.actionOperations * 1e3) : 0;
342
+ const score = roundMetric(
343
+ (scoreSum + ENTROPY_WEIGHTS.navigation * navigationRatio + ENTROPY_WEIGHTS.flow * flowEntropyBits) / Math.max(1, state.totals.succeeded)
344
+ );
345
+ const staticScore = roundMetric(staticWeighted / Math.max(1, state.totals.succeeded));
346
+ const behavioralScore = roundMetric(score - staticScore);
347
+ const sortedRefs = [...refReports].sort(
348
+ (left, right) => right.score - left.score || compareCodeUnits(left.ref, right.ref)
349
+ );
350
+ return {
351
+ metricVersion: ENTROPY_METRIC_VERSION,
352
+ catalogDigest: input.catalogDigest ?? "",
353
+ totals: state.totals,
354
+ shapeEntropyBits: state.totals.actionOperations > 0 ? roundMetric(shapeWeighted / state.totals.actionOperations) : 0,
355
+ failureStageEntropyBits: state.totals.failed > 0 ? roundMetric(failureStageWeighted / state.totals.failed) : 0,
356
+ churnRate: state.churnPairs > 0 ? roundMetric(state.churnSum / state.churnPairs) : 0,
357
+ navigationRatio,
358
+ flowEntropyBits,
359
+ lexiconRows: state.lexiconRows,
360
+ staticFreedom: roundMetric(staticFreedomTotal),
361
+ staticScore,
362
+ behavioralScore,
363
+ score,
364
+ refs: sortedRefs
365
+ };
366
+ };
367
+ var measureOnce = (input) => {
368
+ const state = createMeasureState(input);
369
+ for (const trace of input.traces) accumulateTrace(state, trace);
370
+ return finalizeMeasure(input, state);
371
+ };
372
+ var measureEntropy = (input) => {
373
+ const report = measureOnce(input);
374
+ const groups = /* @__PURE__ */ new Map();
375
+ for (const sourceTrace of input.traces) {
376
+ if (!sourceTrace.model) continue;
377
+ const group = groups.get(sourceTrace.model) ?? [];
378
+ group.push(sourceTrace);
379
+ groups.set(sourceTrace.model, group);
380
+ }
381
+ const byModel = [...groups.entries()].sort(([left], [right]) => compareCodeUnits(left, right)).map(([model, traces]) => {
382
+ const scoped = measureOnce({ ...input, traces });
383
+ return {
384
+ model,
385
+ operations: scoped.totals.operations,
386
+ actionOperations: scoped.totals.actionOperations,
387
+ succeeded: scoped.totals.succeeded,
388
+ invocationRejections: scoped.totals.invocationRejections,
389
+ invocationRejectionsPer1k: scoped.totals.invocationRejectionsPer1k,
390
+ behavioralScore: scoped.behavioralScore
391
+ };
392
+ });
393
+ return { ...report, byModel };
394
+ };
395
+ var yieldToLoop = () => new Promise((resolve) => setImmediate(resolve));
396
+ var COOPERATIVE_TRACE_CHUNK = 64;
397
+ var measureOnceAsync = async (input) => {
398
+ const state = createMeasureState(input);
399
+ await yieldToLoop();
400
+ for (let index = 0; index < input.traces.length; index += 1) {
401
+ accumulateTrace(state, input.traces[index]);
402
+ if ((index + 1) % COOPERATIVE_TRACE_CHUNK === 0) await yieldToLoop();
403
+ }
404
+ return finalizeMeasure(input, state);
405
+ };
406
+ var measureEntropyAsync = async (input) => {
407
+ const report = await measureOnceAsync(input);
408
+ const groups = /* @__PURE__ */ new Map();
409
+ for (const sourceTrace of input.traces) {
410
+ if (!sourceTrace.model) continue;
411
+ const group = groups.get(sourceTrace.model) ?? [];
412
+ group.push(sourceTrace);
413
+ groups.set(sourceTrace.model, group);
414
+ }
415
+ const byModel = [];
416
+ for (const [model, traces] of [...groups.entries()].sort(
417
+ ([left], [right]) => compareCodeUnits(left, right)
418
+ )) {
419
+ const scoped = await measureOnceAsync({ ...input, traces });
420
+ byModel.push({
421
+ model,
422
+ operations: scoped.totals.operations,
423
+ actionOperations: scoped.totals.actionOperations,
424
+ succeeded: scoped.totals.succeeded,
425
+ invocationRejections: scoped.totals.invocationRejections,
426
+ invocationRejectionsPer1k: scoped.totals.invocationRejectionsPer1k,
427
+ behavioralScore: scoped.behavioralScore
428
+ });
429
+ }
430
+ return { ...report, byModel };
431
+ };
432
+
433
+ // src/entropy/passes.ts
434
+ var ENUM_MIN_OBSERVATIONS = 8;
435
+ var ENUM_MAX_DISTINCT = 8;
436
+ var ENUM_MIN_TOP_SHARE = 0.5;
437
+ var SPLIT_MIN_SHAPE_ENTROPY_BITS = 1;
438
+ var SPLIT_MIN_CLUSTER_CALLS = 2;
439
+ var FUSE_MIN_SEQUENCE_LENGTH = 3;
440
+ var FUSE_MAX_SEQUENCE_LENGTH = 6;
441
+ var FUSE_MIN_OCCURRENCES = 3;
442
+ var FUSE_MIN_EXECUTIONS = 3;
443
+ var QUARANTINE_MIN_CALLS = 3;
444
+ var QUARANTINE_MIN_STAGE_ENTROPY_BITS = 1;
445
+ var MAX_PROPOSALS_PER_KIND = 8;
446
+ var ENTROPY_ENUM_CANDIDATE_ANNOTATION = "x-fabric-enum-candidate";
447
+ var isPlainRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
448
+ var valueKey = (value) => `${typeof value}:${String(value)}`;
449
+ var schemaProperties = (schema) => {
450
+ if (!isPlainRecord2(schema)) return void 0;
451
+ const properties = schema.properties;
452
+ return isPlainRecord2(properties) ? properties : void 0;
453
+ };
454
+ var enumKeys = (schema) => {
455
+ if (!isPlainRecord2(schema) || !Array.isArray(schema.enum)) return void 0;
456
+ const keys = /* @__PURE__ */ new Set();
457
+ for (const entry of schema.enum) {
458
+ if (typeof entry === "string" || typeof entry === "number" || typeof entry === "boolean") {
459
+ keys.add(valueKey(entry));
460
+ }
461
+ }
462
+ return keys;
463
+ };
464
+ var contains = (outer, inner) => {
465
+ if (outer.length < inner.length) return false;
466
+ for (let start = 0; start + inner.length <= outer.length; start++) {
467
+ let matches = true;
468
+ for (let index = 0; index < inner.length; index++) {
469
+ if (outer[start + index] !== inner[index]) {
470
+ matches = false;
471
+ break;
472
+ }
473
+ }
474
+ if (matches) return true;
475
+ }
476
+ return false;
477
+ };
478
+ var tightenBeneathDeclaredEnum = (candidate, declaredDomain) => {
479
+ const ranked = candidate.ranked.filter((item) => declaredDomain.has(valueKey(item.value)));
480
+ if (ranked.length === 0 || ranked.length === declaredDomain.size) return void 0;
481
+ return { ...candidate, ranked };
482
+ };
483
+ var proposeEntropyReductions = (input) => {
484
+ const calledRefs = /* @__PURE__ */ new Map();
485
+ for (const ref of input.report.refs) calledRefs.set(ref.ref, ref);
486
+ const surfaceByRef = /* @__PURE__ */ new Map();
487
+ const surfaceRefs = /* @__PURE__ */ new Set();
488
+ if (input.surface) {
489
+ for (const action of input.surface.actions) {
490
+ surfaceByRef.set(action.ref, action.inputSchema);
491
+ surfaceRefs.add(action.ref);
492
+ }
493
+ }
494
+ const proposals = [];
495
+ const observations = /* @__PURE__ */ new Map();
496
+ const observeValue = (ref, key, value, weight = 1) => {
497
+ const id = `${ref}\0${key}`;
498
+ const entry = observations.get(id) ?? {
499
+ ref,
500
+ key,
501
+ counts: /* @__PURE__ */ new Map(),
502
+ total: 0
503
+ };
504
+ const valueId = valueKey(value);
505
+ const existing = entry.counts.get(valueId);
506
+ entry.counts.set(valueId, { value, count: (existing?.count ?? 0) + weight });
507
+ entry.total += weight;
508
+ observations.set(id, entry);
509
+ };
510
+ if (input.valueObservations) {
511
+ for (const observation of input.valueObservations) {
512
+ observeValue(observation.ref, observation.key, observation.value, observation.count ?? 1);
513
+ }
514
+ } else {
515
+ for (const sourceTrace of input.traces) {
516
+ for (const operation of sourceTrace.operations) {
517
+ if (operation.ref.startsWith("fabric.")) continue;
518
+ for (const [key, value] of Object.entries(operation.args)) {
519
+ if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") {
520
+ continue;
521
+ }
522
+ observeValue(operation.ref, key, value);
523
+ }
524
+ }
525
+ }
526
+ }
527
+ const eligibleCandidates = [...observations.values()].filter((entry) => entry.total >= ENUM_MIN_OBSERVATIONS).filter((entry) => entry.counts.size >= 2 && entry.counts.size <= ENUM_MAX_DISTINCT).map((entry) => {
528
+ const ranked = [...entry.counts.values()].sort(
529
+ (left, right) => right.count - left.count || compareCodeUnits(valueKey(left.value), valueKey(right.value))
530
+ );
531
+ return { entry, ranked, topShare: roundMetric(ranked[0].count / entry.total) };
532
+ }).filter((candidate) => candidate.topShare >= ENUM_MIN_TOP_SHARE);
533
+ const closedCandidates = [];
534
+ const openCandidates = [];
535
+ for (const candidate of eligibleCandidates) {
536
+ const properties = input.surface ? schemaProperties(surfaceByRef.get(candidate.entry.ref)) : void 0;
537
+ const target = properties ? properties[candidate.entry.key] : void 0;
538
+ if (isPlainRecord2(target) && target.type === "boolean") continue;
539
+ const declaredDomain = target ? enumKeys(target) : void 0;
540
+ if (declaredDomain) {
541
+ const tightened = tightenBeneathDeclaredEnum(candidate, declaredDomain);
542
+ if (tightened) closedCandidates.push(tightened);
543
+ } else if (isPlainRecord2(target) && target[ENTROPY_ENUM_CANDIDATE_ANNOTATION] === true) {
544
+ openCandidates.push(candidate);
545
+ }
546
+ }
547
+ const byRefKey = (left, right) => compareCodeUnits(
548
+ `${left.entry.ref}\0${left.entry.key}`,
549
+ `${right.entry.ref}\0${right.entry.key}`
550
+ );
551
+ for (const candidate of closedCandidates.sort(byRefKey).slice(0, MAX_PROPOSALS_PER_KIND)) {
552
+ proposals.push({
553
+ kind: "enum-tighten",
554
+ ref: candidate.entry.ref,
555
+ key: candidate.entry.key,
556
+ values: candidate.ranked.map((item) => item.value),
557
+ calls: candidate.entry.total,
558
+ distinct: candidate.ranked.length,
559
+ topShare: candidate.topShare
560
+ });
561
+ }
562
+ for (const candidate of openCandidates.sort(byRefKey).slice(0, MAX_PROPOSALS_PER_KIND)) {
563
+ proposals.push({
564
+ kind: "declare-enum",
565
+ ref: candidate.entry.ref,
566
+ key: candidate.entry.key,
567
+ values: candidate.ranked.map((item) => item.value),
568
+ calls: candidate.entry.total,
569
+ distinct: candidate.entry.counts.size,
570
+ topShare: candidate.topShare
571
+ });
572
+ }
573
+ const overloadRefs = new Set(
574
+ input.report.refs.filter((ref) => ref.shapeEntropyBits >= SPLIT_MIN_SHAPE_ENTROPY_BITS).map((ref) => ref.ref)
575
+ );
576
+ if (overloadRefs.size > 0) {
577
+ const keySets = /* @__PURE__ */ new Map();
578
+ for (const sourceTrace of input.traces) {
579
+ for (const operation of sourceTrace.operations) {
580
+ if (!overloadRefs.has(operation.ref)) continue;
581
+ const keys = Object.keys(operation.args).sort();
582
+ const id = keys.join("\0");
583
+ const perRef = keySets.get(operation.ref) ?? /* @__PURE__ */ new Map();
584
+ const cluster = perRef.get(id) ?? { keys, calls: 0 };
585
+ cluster.calls += 1;
586
+ perRef.set(id, cluster);
587
+ keySets.set(operation.ref, perRef);
588
+ }
589
+ }
590
+ let overloadCount = 0;
591
+ for (const [ref, perRef] of [...keySets.entries()].sort(
592
+ ([left], [right]) => compareCodeUnits(left, right)
593
+ )) {
594
+ if (overloadCount >= MAX_PROPOSALS_PER_KIND) break;
595
+ const clusters = [...perRef.values()].filter((cluster) => cluster.calls >= SPLIT_MIN_CLUSTER_CALLS).sort(
596
+ (left, right) => right.calls - left.calls || compareCodeUnits(left.keys.join(","), right.keys.join(","))
597
+ );
598
+ const disjoint = [];
599
+ for (const cluster of clusters) {
600
+ const keys = new Set(cluster.keys);
601
+ if (disjoint.every((candidate) => candidate.keys.every((key) => !keys.has(key)))) {
602
+ disjoint.push(cluster);
603
+ }
604
+ }
605
+ if (disjoint.length >= 2) {
606
+ overloadCount += 1;
607
+ const report = calledRefs.get(ref);
608
+ proposals.push({
609
+ kind: "overload-split",
610
+ ref,
611
+ shapeEntropyBits: report?.shapeEntropyBits ?? 0,
612
+ clusters: disjoint.slice(0, MAX_PROPOSALS_PER_KIND).map((cluster) => ({
613
+ keys: cluster.keys,
614
+ calls: cluster.calls
615
+ }))
616
+ });
617
+ }
618
+ }
619
+ }
620
+ const sequenceCounts = /* @__PURE__ */ new Map();
621
+ const recordSequenceSegment = (refs, execution) => {
622
+ for (let length = FUSE_MIN_SEQUENCE_LENGTH; length <= Math.min(FUSE_MAX_SEQUENCE_LENGTH, refs.length); length++) {
623
+ for (let start = 0; start + length <= refs.length; start++) {
624
+ const sequence = refs.slice(start, start + length);
625
+ if (new Set(sequence).size !== sequence.length) continue;
626
+ const id = sequence.join("\u2192");
627
+ const entry = sequenceCounts.get(id) ?? {
628
+ sequence,
629
+ occurrences: 0,
630
+ executions: /* @__PURE__ */ new Set()
631
+ };
632
+ entry.occurrences += 1;
633
+ entry.executions.add(execution);
634
+ sequenceCounts.set(id, entry);
635
+ }
636
+ }
637
+ };
638
+ input.traces.forEach((sourceTrace, execution) => {
639
+ let segment = [];
640
+ const flush = () => {
641
+ recordSequenceSegment(segment, execution);
642
+ segment = [];
643
+ };
644
+ for (const operation of sourceTrace.operations) {
645
+ if (operation.outcome !== "succeeded" || operation.ref.startsWith("fabric.") || operation.ref.startsWith("omp.")) {
646
+ flush();
647
+ } else {
648
+ segment.push(operation.ref);
649
+ }
650
+ }
651
+ flush();
652
+ });
653
+ const fuseCandidates = [...sequenceCounts.values()].filter(
654
+ (entry) => entry.occurrences >= FUSE_MIN_OCCURRENCES && entry.executions.size >= FUSE_MIN_EXECUTIONS
655
+ ).sort(
656
+ (left, right) => right.sequence.length - left.sequence.length || right.occurrences - left.occurrences || compareCodeUnits(left.sequence.join("\u2192"), right.sequence.join("\u2192"))
657
+ );
658
+ const selected = [];
659
+ for (const candidate of fuseCandidates) {
660
+ if (selected.length >= MAX_PROPOSALS_PER_KIND) break;
661
+ const redundant = selected.some(
662
+ (chosen) => contains(candidate.sequence, chosen.sequence) || contains(chosen.sequence, candidate.sequence)
663
+ );
664
+ if (redundant) continue;
665
+ selected.push(candidate);
666
+ }
667
+ for (const candidate of selected) {
668
+ proposals.push({
669
+ kind: "sequence-fuse",
670
+ sequence: candidate.sequence,
671
+ occurrences: candidate.occurrences
672
+ });
673
+ }
674
+ const quarantineCandidates = input.report.refs.filter(
675
+ (ref) => ref.calls >= QUARANTINE_MIN_CALLS && ref.failed > ref.succeeded && ref.failureStageEntropyBits >= QUARANTINE_MIN_STAGE_ENTROPY_BITS
676
+ ).filter((ref) => !input.surface || surfaceRefs.has(ref.ref)).slice(0, MAX_PROPOSALS_PER_KIND);
677
+ for (const ref of quarantineCandidates) {
678
+ proposals.push({
679
+ kind: "noise-quarantine",
680
+ ref: ref.ref,
681
+ calls: ref.calls,
682
+ succeeded: ref.succeeded,
683
+ failed: ref.failed,
684
+ failureStageEntropyBits: ref.failureStageEntropyBits
685
+ });
686
+ }
687
+ return proposals;
688
+ };
689
+ var deepCloneJson = (value) => value === void 0 ? {} : JSON.parse(JSON.stringify(value));
690
+ var applyProposalsToSurface = (surface, proposals) => {
691
+ const actions = surface.actions.map((action) => ({
692
+ ref: action.ref,
693
+ inputSchema: deepCloneJson(action.inputSchema)
694
+ }));
695
+ const quarantined = /* @__PURE__ */ new Set();
696
+ for (const proposal of proposals) {
697
+ if (proposal.kind === "noise-quarantine") {
698
+ quarantined.add(proposal.ref);
699
+ continue;
700
+ }
701
+ if (proposal.kind === "enum-tighten") {
702
+ const action = actions.find((candidate) => candidate.ref === proposal.ref);
703
+ if (!action || !isPlainRecord2(action.inputSchema)) continue;
704
+ const properties = schemaProperties(action.inputSchema);
705
+ if (!properties || !isPlainRecord2(properties[proposal.key])) continue;
706
+ properties[proposal.key] = {
707
+ ...properties[proposal.key],
708
+ enum: [...proposal.values]
709
+ };
710
+ }
711
+ }
712
+ const survivors = actions.filter((action) => !quarantined.has(action.ref)).sort((left, right) => compareCodeUnits(left.ref, right.ref));
713
+ return { version: 1, actions: survivors };
714
+ };
715
+ var evaluateGate = (before, after) => {
716
+ const reasons = [];
717
+ if (after.score > before.score) {
718
+ reasons.push(`score increased ${before.score} \u2192 ${after.score}`);
719
+ }
720
+ if (after.totals.succeeded < before.totals.succeeded) {
721
+ reasons.push(
722
+ `successful calls dropped ${before.totals.succeeded} \u2192 ${after.totals.succeeded}`
723
+ );
724
+ }
725
+ return {
726
+ passed: reasons.length === 0,
727
+ beforeScore: before.score,
728
+ afterScore: after.score,
729
+ delta: roundMetric(after.score - before.score),
730
+ reasons
731
+ };
732
+ };
733
+
734
+ // src/entropy/pool.ts
735
+ import { createHash } from "node:crypto";
736
+ var OBSERVATION_POOL_VERSION = 1;
737
+ var POOL_TRACKED_VALUES = 16;
738
+ var POOL_TRACKED_SESSIONS = 16;
739
+ var POOL_BAKED_DIGESTS = 512;
740
+ var SEPARATOR = "\0";
741
+ var observationIdentity = (observation) => `${observation.ref}${SEPARATOR}${observation.key}${SEPARATOR}${typeof observation.value}:${String(observation.value)}`;
742
+ var entryValueKey = (value) => `${typeof value}:${String(value)}`;
743
+ var valueFromKey = (valueKey2) => {
744
+ const separator = valueKey2.indexOf(":");
745
+ const type = valueKey2.slice(0, separator);
746
+ const raw = valueKey2.slice(separator + 1);
747
+ if (type === "number") return Number(raw);
748
+ if (type === "boolean") return raw === "true";
749
+ return raw;
750
+ };
751
+ var parseIdentity = (identity) => {
752
+ const first = identity.indexOf(SEPARATOR);
753
+ const second = identity.indexOf(SEPARATOR, first + 1);
754
+ return {
755
+ ref: identity.slice(0, first),
756
+ key: identity.slice(first + 1, second),
757
+ valueKey: identity.slice(second + 1)
758
+ };
759
+ };
760
+ var digestFromIdentityCounts = (counts) => {
761
+ const hash = createHash("sha256");
762
+ hash.update("[");
763
+ let first = true;
764
+ for (const [identity, count] of Object.entries(counts).sort(
765
+ ([left], [right]) => compareCodeUnits(left, right)
766
+ )) {
767
+ const encoded = JSON.stringify(identity);
768
+ const repeated = Array.from({ length: count }, () => encoded).join(",");
769
+ hash.update(first ? repeated : `,${repeated}`);
770
+ first = false;
771
+ }
772
+ hash.update("]");
773
+ return hash.digest("hex");
774
+ };
775
+ var summarizeObservations = (observations) => {
776
+ const counts = {};
777
+ const digestCounts = {};
778
+ for (const observation of observations) {
779
+ const identity = observationIdentity(observation);
780
+ counts[identity] = (counts[identity] ?? 0) + (observation.count ?? 1);
781
+ digestCounts[identity] = (digestCounts[identity] ?? 0) + 1;
782
+ }
783
+ return { counts, digest: digestFromIdentityCounts(digestCounts) };
784
+ };
785
+ var observationWindowDigest = (observations) => summarizeObservations(observations).digest;
786
+ var COOPERATIVE_OBSERVATION_CHUNK = 256;
787
+ var COOPERATIVE_DIGEST_CHUNK = 512;
788
+ var yieldToLoop2 = () => new Promise((resolve) => setImmediate(resolve));
789
+ var digestFromIdentityCountsAsync = async (counts) => {
790
+ const hash = createHash("sha256");
791
+ hash.update("[");
792
+ let first = true;
793
+ let encodedBatch = [];
794
+ const flush = async () => {
795
+ if (encodedBatch.length === 0) return;
796
+ hash.update(`${first ? "" : ","}${encodedBatch.join(",")}`);
797
+ first = false;
798
+ encodedBatch = [];
799
+ await yieldToLoop2();
800
+ };
801
+ for (const [identity, count] of Object.entries(counts).sort(
802
+ ([left], [right]) => compareCodeUnits(left, right)
803
+ )) {
804
+ const encoded = JSON.stringify(identity);
805
+ for (let occurrence = 0; occurrence < count; occurrence += 1) {
806
+ encodedBatch.push(encoded);
807
+ if (encodedBatch.length >= COOPERATIVE_DIGEST_CHUNK) await flush();
808
+ }
809
+ }
810
+ if (encodedBatch.length > 0) {
811
+ hash.update(`${first ? "" : ","}${encodedBatch.join(",")}`);
812
+ }
813
+ hash.update("]");
814
+ return hash.digest("hex");
815
+ };
816
+ var summarizeObservationsAsync = async (observations) => {
817
+ const counts = {};
818
+ const digestCounts = {};
819
+ for (let index = 0; index < observations.length; index += 1) {
820
+ const observation = observations[index];
821
+ const identity = observationIdentity(observation);
822
+ counts[identity] = (counts[identity] ?? 0) + (observation.count ?? 1);
823
+ digestCounts[identity] = (digestCounts[identity] ?? 0) + 1;
824
+ if ((index + 1) % COOPERATIVE_OBSERVATION_CHUNK === 0) await yieldToLoop2();
825
+ }
826
+ return { counts, digest: await digestFromIdentityCountsAsync(digestCounts) };
827
+ };
828
+ var workingFromPool = (pool) => {
829
+ const working = /* @__PURE__ */ new Map();
830
+ if (!pool) return working;
831
+ for (const entry of pool.entries) {
832
+ const values = /* @__PURE__ */ new Map();
833
+ for (const item of entry.values) {
834
+ values.set(entryValueKey(item.value), { value: item.value, count: item.count });
835
+ }
836
+ working.set(`${entry.ref}${SEPARATOR}${entry.key}`, {
837
+ ref: entry.ref,
838
+ key: entry.key,
839
+ values,
840
+ total: entry.total
841
+ });
842
+ }
843
+ return working;
844
+ };
845
+ var applyEntryDelta = (working, identity, weight) => {
846
+ const { ref, key, valueKey: valueKey2 } = parseIdentity(identity);
847
+ const entryId = `${ref}${SEPARATOR}${key}`;
848
+ let entry = working.get(entryId);
849
+ if (!entry) {
850
+ entry = { ref, key, values: /* @__PURE__ */ new Map(), total: 0 };
851
+ working.set(entryId, entry);
852
+ }
853
+ const current = entry.values.get(valueKey2);
854
+ const nextCount = (current?.count ?? 0) + weight;
855
+ entry.total += weight;
856
+ if (nextCount > 0) {
857
+ entry.values.set(valueKey2, {
858
+ value: current?.value ?? valueFromKey(valueKey2),
859
+ count: nextCount
860
+ });
861
+ } else {
862
+ entry.values.delete(valueKey2);
863
+ }
864
+ if (entry.values.size === 0 && entry.total <= 0) working.delete(entryId);
865
+ return entryId;
866
+ };
867
+ var enforceValueCap = (entry) => {
868
+ while (entry.values.size > POOL_TRACKED_VALUES) {
869
+ let evictKey;
870
+ let evictCount = Number.POSITIVE_INFINITY;
871
+ for (const [valueKey2, item] of entry.values) {
872
+ if (evictKey === void 0 || item.count < evictCount || item.count === evictCount && compareCodeUnits(valueKey2, evictKey) > 0) {
873
+ evictKey = valueKey2;
874
+ evictCount = item.count;
875
+ }
876
+ }
877
+ if (evictKey === void 0) return;
878
+ entry.total -= entry.values.get(evictKey).count;
879
+ entry.values.delete(evictKey);
880
+ }
881
+ };
882
+ var serializePool = (working, tracked, baked) => ({
883
+ version: OBSERVATION_POOL_VERSION,
884
+ entries: [...working.values()].map((entry) => ({
885
+ ref: entry.ref,
886
+ key: entry.key,
887
+ total: entry.total,
888
+ values: [...entry.values.values()].map((item) => ({ value: item.value, count: item.count })).sort(
889
+ (left, right) => right.count - left.count || compareCodeUnits(entryValueKey(left.value), entryValueKey(right.value))
890
+ )
891
+ })).sort(
892
+ (left, right) => compareCodeUnits(
893
+ `${left.ref}${SEPARATOR}${left.key}`,
894
+ `${right.ref}${SEPARATOR}${right.key}`
895
+ )
896
+ ),
897
+ tracked,
898
+ baked
899
+ });
900
+ var mergeObservationSummaries = (pool, windows) => {
901
+ const working = workingFromPool(pool);
902
+ const tracked = [...pool?.tracked ?? []];
903
+ const baked = [...pool?.baked ?? []];
904
+ const bakedSet = new Set(baked);
905
+ const trackedDigests = new Set(tracked.map((session) => session.digest));
906
+ let mergedSessions = 0;
907
+ let skippedSessions = 0;
908
+ for (const window of windows) {
909
+ const { digest, counts: fresh } = window.summary;
910
+ if (bakedSet.has(digest) || trackedDigests.has(digest)) {
911
+ skippedSessions += 1;
912
+ continue;
913
+ }
914
+ const existingIndex = tracked.findIndex((session) => session.file === window.file);
915
+ const existing = existingIndex >= 0 ? tracked[existingIndex] : void 0;
916
+ const delta = { ...fresh };
917
+ if (existing) {
918
+ for (const [identity, count] of Object.entries(existing.counts)) {
919
+ delta[identity] = (delta[identity] ?? 0) - count;
920
+ }
921
+ }
922
+ const touched = /* @__PURE__ */ new Set();
923
+ for (const [identity, weight] of Object.entries(delta)) {
924
+ if (weight === 0) continue;
925
+ touched.add(applyEntryDelta(working, identity, weight));
926
+ }
927
+ for (const entryId of touched) {
928
+ const entry = working.get(entryId);
929
+ if (entry) enforceValueCap(entry);
930
+ }
931
+ const trackedSession = { file: window.file, digest, counts: fresh };
932
+ if (existing) {
933
+ tracked[existingIndex] = trackedSession;
934
+ } else {
935
+ tracked.push(trackedSession);
936
+ if (tracked.length > POOL_TRACKED_SESSIONS) {
937
+ const oldest = tracked.shift();
938
+ if (!bakedSet.has(oldest.digest)) {
939
+ baked.push(oldest.digest);
940
+ bakedSet.add(oldest.digest);
941
+ while (baked.length > POOL_BAKED_DIGESTS) {
942
+ bakedSet.delete(baked.shift());
943
+ }
944
+ }
945
+ }
946
+ }
947
+ trackedDigests.add(digest);
948
+ mergedSessions += 1;
949
+ }
950
+ return {
951
+ file: serializePool(working, tracked, baked),
952
+ mergedSessions,
953
+ skippedSessions
954
+ };
955
+ };
956
+ var mergeObservationWindow = (pool, windows) => mergeObservationSummaries(
957
+ pool,
958
+ windows.map((window) => ({
959
+ file: window.file,
960
+ summary: summarizeObservations(window.observations)
961
+ }))
962
+ );
963
+ var mergeObservationWindowAsync = async (pool, windows) => {
964
+ const summarized = [];
965
+ for (const window of windows) {
966
+ summarized.push({
967
+ file: window.file,
968
+ summary: await summarizeObservationsAsync(window.observations)
969
+ });
970
+ }
971
+ await yieldToLoop2();
972
+ return mergeObservationSummaries(pool, summarized);
973
+ };
974
+ var poolToValueObservations = (pool) => {
975
+ if (!pool) return [];
976
+ const observations = [];
977
+ for (const entry of pool.entries) {
978
+ for (const item of entry.values) {
979
+ observations.push({ ref: entry.ref, key: entry.key, value: item.value, count: item.count });
980
+ }
981
+ }
982
+ return observations;
983
+ };
984
+
985
+ // src/entropy/pool-store.ts
986
+ import fs from "node:fs";
987
+ import path from "node:path";
988
+ var POOL_LOCK_ATTEMPTS = 50;
989
+ var POOL_LOCK_DELAY_MS = 5;
990
+ var POOL_STALE_LOCK_MS = 3e4;
991
+ var POOL_MAX_ENTRIES = 8192;
992
+ var POOL_MAX_VALUES_PER_ENTRY = 64;
993
+ var POOL_MAX_TRACKED = 64;
994
+ var POOL_MAX_BAKED = 2048;
995
+ var observationPoolDirectory = (agentDir) => path.join(agentDir, "fabric", "entropy");
996
+ var poolPath = (directory) => path.join(directory, "observation-pool.json");
997
+ var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
998
+ var errorCode = (error) => isRecord(error) && typeof error.code === "string" ? error.code : void 0;
999
+ var errorText = (error) => (error instanceof Error ? error.message : String(error)).slice(0, 200);
1000
+ var isPrimitive = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean";
1001
+ var parseValueCount = (value) => {
1002
+ if (!isRecord(value) || !isPrimitive(value.value)) return void 0;
1003
+ if (!Number.isSafeInteger(value.count) || value.count < 1) return void 0;
1004
+ return { value: value.value, count: value.count };
1005
+ };
1006
+ var parseEntry = (value) => {
1007
+ if (!isRecord(value) || typeof value.ref !== "string" || !value.ref.trim()) return void 0;
1008
+ if (typeof value.key !== "string" || !value.key.trim()) return void 0;
1009
+ if (!Number.isSafeInteger(value.total) || value.total < 0) return void 0;
1010
+ if (!Array.isArray(value.values) || value.values.length > POOL_MAX_VALUES_PER_ENTRY) {
1011
+ return void 0;
1012
+ }
1013
+ const values = [];
1014
+ for (const item of value.values) {
1015
+ const parsed = parseValueCount(item);
1016
+ if (!parsed) return void 0;
1017
+ values.push(parsed);
1018
+ }
1019
+ const seen = /* @__PURE__ */ new Set();
1020
+ for (const item of values) {
1021
+ const key = `${typeof item.value}:${String(item.value)}`;
1022
+ if (seen.has(key)) return void 0;
1023
+ seen.add(key);
1024
+ }
1025
+ return { ref: value.ref.trim(), key: value.key.trim(), total: value.total, values };
1026
+ };
1027
+ var parseTrackedSession = (value) => {
1028
+ if (!isRecord(value) || typeof value.file !== "string" || !value.file.trim()) return void 0;
1029
+ if (typeof value.digest !== "string" || !value.digest.trim()) return void 0;
1030
+ if (!isRecord(value.counts)) return void 0;
1031
+ const counts = {};
1032
+ for (const [identity, count] of Object.entries(value.counts)) {
1033
+ if (!Number.isSafeInteger(count) || count < 1) return void 0;
1034
+ counts[identity] = count;
1035
+ }
1036
+ return { file: value.file.trim(), digest: value.digest.trim(), counts };
1037
+ };
1038
+ var parsePoolFile = (value) => {
1039
+ if (!isRecord(value) || value.version !== OBSERVATION_POOL_VERSION) return void 0;
1040
+ if (!Array.isArray(value.entries) || value.entries.length > POOL_MAX_ENTRIES) return void 0;
1041
+ if (!Array.isArray(value.tracked) || value.tracked.length > POOL_MAX_TRACKED) return void 0;
1042
+ if (!Array.isArray(value.baked) || value.baked.length > POOL_MAX_BAKED) return void 0;
1043
+ if (!value.baked.every((digest) => typeof digest === "string" && digest.trim())) {
1044
+ return void 0;
1045
+ }
1046
+ const entries = [];
1047
+ for (const entry of value.entries) {
1048
+ const parsed = parseEntry(entry);
1049
+ if (!parsed) return void 0;
1050
+ entries.push(parsed);
1051
+ }
1052
+ const tracked = [];
1053
+ const trackedFiles = /* @__PURE__ */ new Set();
1054
+ for (const session of value.tracked) {
1055
+ const parsed = parseTrackedSession(session);
1056
+ if (!parsed) return void 0;
1057
+ if (trackedFiles.has(parsed.file)) return void 0;
1058
+ trackedFiles.add(parsed.file);
1059
+ tracked.push(parsed);
1060
+ }
1061
+ const entrySeen = /* @__PURE__ */ new Set();
1062
+ for (const entry of entries) {
1063
+ const id = `${entry.ref}\0${entry.key}`;
1064
+ if (entrySeen.has(id)) return void 0;
1065
+ entrySeen.add(id);
1066
+ }
1067
+ return {
1068
+ version: OBSERVATION_POOL_VERSION,
1069
+ entries,
1070
+ tracked,
1071
+ baked: value.baked.map((digest) => digest.trim())
1072
+ };
1073
+ };
1074
+ var loadObservationPool = (agentDir) => {
1075
+ const file = poolPath(observationPoolDirectory(agentDir));
1076
+ let raw;
1077
+ try {
1078
+ raw = fs.readFileSync(file, "utf8");
1079
+ } catch (error) {
1080
+ if (errorCode(error) === "ENOENT") return {};
1081
+ return { error: `observation pool is unreadable: ${errorText(error)}` };
1082
+ }
1083
+ let parsed;
1084
+ try {
1085
+ parsed = JSON.parse(raw);
1086
+ } catch {
1087
+ return { error: "observation pool is malformed JSON" };
1088
+ }
1089
+ const parsedFile = parsePoolFile(parsed);
1090
+ if (!parsedFile) return { error: "observation pool is invalid" };
1091
+ return { file: parsedFile };
1092
+ };
1093
+ var loadObservationPoolAsync = async (agentDir) => {
1094
+ const file = poolPath(observationPoolDirectory(agentDir));
1095
+ let raw;
1096
+ try {
1097
+ raw = await fs.promises.readFile(file, "utf8");
1098
+ } catch (error) {
1099
+ if (errorCode(error) === "ENOENT") return {};
1100
+ return { error: `observation pool is unreadable: ${errorText(error)}` };
1101
+ }
1102
+ let parsed;
1103
+ try {
1104
+ parsed = JSON.parse(raw);
1105
+ } catch {
1106
+ return { error: "observation pool is malformed JSON" };
1107
+ }
1108
+ const parsedFile = parsePoolFile(parsed);
1109
+ return parsedFile ? { file: parsedFile } : { error: "observation pool is invalid" };
1110
+ };
1111
+ var saveObservationPool = (agentDir, file) => withExclusiveFileLock(
1112
+ {
1113
+ directory: observationPoolDirectory(agentDir),
1114
+ lockName: "observation-pool.lock",
1115
+ timeoutMessage: "Timed out waiting for the observation pool lock",
1116
+ attempts: POOL_LOCK_ATTEMPTS,
1117
+ delayMs: POOL_LOCK_DELAY_MS,
1118
+ staleMs: POOL_STALE_LOCK_MS
1119
+ },
1120
+ () => {
1121
+ const loaded = loadObservationPool(agentDir);
1122
+ if (loaded.error) throw new Error(loaded.error);
1123
+ const target = poolPath(observationPoolDirectory(agentDir));
1124
+ const serialized = `${JSON.stringify(file, null, 2)}
1125
+ `;
1126
+ try {
1127
+ if (fs.readFileSync(target, "utf8") === serialized) return { file, written: false };
1128
+ } catch {
1129
+ }
1130
+ writeJsonAtomic(target, file, { space: 2, newline: true, mode: 384, dirMode: 448 });
1131
+ return { file, written: true };
1132
+ }
1133
+ );
1134
+ var saveObservationPoolAsync = async (agentDir, file) => withExclusiveFileLockAsync(
1135
+ {
1136
+ directory: observationPoolDirectory(agentDir),
1137
+ lockName: "observation-pool.lock",
1138
+ timeoutMessage: "Timed out waiting for the observation pool lock",
1139
+ attempts: POOL_LOCK_ATTEMPTS,
1140
+ delayMs: POOL_LOCK_DELAY_MS,
1141
+ staleMs: POOL_STALE_LOCK_MS
1142
+ },
1143
+ async () => {
1144
+ const loaded = await loadObservationPoolAsync(agentDir);
1145
+ if (loaded.error) throw new Error(loaded.error);
1146
+ const target = poolPath(observationPoolDirectory(agentDir));
1147
+ const serialized = `${JSON.stringify(file, null, 2)}
1148
+ `;
1149
+ try {
1150
+ if (await fs.promises.readFile(target, "utf8") === serialized) {
1151
+ return { file, written: false };
1152
+ }
1153
+ } catch {
1154
+ }
1155
+ await writeJsonAtomicAsync(target, file, {
1156
+ space: 2,
1157
+ newline: true,
1158
+ mode: 384,
1159
+ dirMode: 448
1160
+ });
1161
+ return { file, written: true };
1162
+ }
1163
+ );
1164
+
1165
+ // src/entropy/surface.ts
1166
+ var SURFACE_LIST_LIMIT = 1e3;
1167
+ var surfaceInvocationContext = (input) => ({
1168
+ cwd: input.cwd,
1169
+ signal: void 0,
1170
+ parentToolCallId: "fabric-entropy-surface",
1171
+ nestedToolCallId: "fabric-entropy-surface",
1172
+ extensionContext: input.extensionContext,
1173
+ update: () => {
1174
+ }
1175
+ });
1176
+ var liveSurfaceSnapshot = async (input) => {
1177
+ const actions = await input.registry.list(
1178
+ { limit: SURFACE_LIST_LIMIT, declared: true },
1179
+ surfaceInvocationContext(input)
1180
+ );
1181
+ return {
1182
+ version: 1,
1183
+ actions: actions.map((action) => ({ ref: action.ref, inputSchema: action.inputSchema })).sort((left, right) => compareCodeUnits(left.ref, right.ref))
1184
+ };
1185
+ };
1186
+ var entropySurfaceHash = (surface) => stableJsonHash(surface);
1187
+ var surfaceFreedomReport = (surface) => {
1188
+ const actions = surface.actions.map((action) => ({ ref: action.ref, freedom: staticFreedomFromSchema(action.inputSchema) })).sort((left, right) => right.freedom - left.freedom || compareCodeUnits(left.ref, right.ref));
1189
+ const total = roundMetric(actions.reduce((sum, entry) => sum + entry.freedom, 0));
1190
+ return {
1191
+ actions,
1192
+ total,
1193
+ mean: actions.length > 0 ? roundMetric(total / actions.length) : 0
1194
+ };
1195
+ };
1196
+
1197
+ // src/entropy/compiler.ts
1198
+ var AUTO_APPLY_PROPOSAL_KINDS = ["enum-tighten", "noise-quarantine"];
1199
+ var entropyReviewSignals = (input) => proposeEntropyReductions(input).filter(
1200
+ (proposal) => !AUTO_APPLY_PROPOSAL_KINDS.includes(proposal.kind)
1201
+ );
1202
+ var formatEntropyReviewSignal = (proposal) => {
1203
+ if (proposal.kind === "declare-enum") {
1204
+ const values = proposal.values.slice(0, 4).map((value) => String(value)).join(", ");
1205
+ return `declare-enum ${proposal.ref}.${proposal.key} (${values}${proposal.values.length > 4 ? ", ..." : ""})`;
1206
+ }
1207
+ if (proposal.kind === "overload-split") {
1208
+ return `overload-split ${proposal.ref} (${proposal.clusters.length} key-set clusters)`;
1209
+ }
1210
+ if (proposal.kind === "sequence-fuse") {
1211
+ return `sequence-fuse ${proposal.sequence.join(" -> ")}`;
1212
+ }
1213
+ return `${proposal.kind} ${proposal.ref}`;
1214
+ };
1215
+ var proposalDetail = (proposal) => {
1216
+ if (proposal.kind === "enum-tighten") {
1217
+ return { ref: proposal.ref, detail: `${proposal.key}: ${proposal.values.length} observed values` };
1218
+ }
1219
+ if (proposal.kind === "noise-quarantine") {
1220
+ return { ref: proposal.ref, detail: `${proposal.failed} failed vs ${proposal.succeeded} succeeded` };
1221
+ }
1222
+ return { ref: "n/a", detail: "review-only" };
1223
+ };
1224
+ var touchedRefs = (before, after) => {
1225
+ const beforeByRef = new Map(before.actions.map((action) => [action.ref, action.inputSchema]));
1226
+ const touched = /* @__PURE__ */ new Set();
1227
+ for (const action of after.actions) {
1228
+ if (stableJsonHash(beforeByRef.get(action.ref)) !== stableJsonHash(action.inputSchema)) {
1229
+ touched.add(action.ref);
1230
+ }
1231
+ }
1232
+ for (const ref of beforeByRef.keys()) {
1233
+ if (!after.actions.some((action) => action.ref === ref)) touched.add(ref);
1234
+ }
1235
+ return touched;
1236
+ };
1237
+ var artifactFromCandidate = (live, candidate, proposals, gate, evidenceDigest, previous) => {
1238
+ const liveByRef = new Map(live.actions.map((action) => [action.ref, action.inputSchema]));
1239
+ const actions = candidate.actions.filter(
1240
+ (action) => stableJsonHash(action.inputSchema) !== stableJsonHash(liveByRef.get(action.ref))
1241
+ ).map((action) => ({
1242
+ ref: action.ref,
1243
+ inputSchema: action.inputSchema,
1244
+ baseSchemaDigest: schemaDigest(liveByRef.get(action.ref))
1245
+ }));
1246
+ const candidateRefs = new Set(candidate.actions.map((action) => action.ref));
1247
+ const quarantined = live.actions.filter((action) => !candidateRefs.has(action.ref)).map((action) => ({ ref: action.ref, baseSchemaDigest: schemaDigest(action.inputSchema) }));
1248
+ const applied = [...previous?.applied ?? []];
1249
+ const seen = new Set(applied.map((entry) => `${entry.kind}:${entry.ref}:${entry.detail}`));
1250
+ for (const proposal of proposals) {
1251
+ const { ref, detail } = proposalDetail(proposal);
1252
+ const identity = `${proposal.kind}:${ref}:${detail}`;
1253
+ if (seen.has(identity)) continue;
1254
+ seen.add(identity);
1255
+ applied.push({ kind: proposal.kind, ref, detail });
1256
+ }
1257
+ return {
1258
+ version: COMPILED_SURFACE_VERSION,
1259
+ metricVersion: ENTROPY_METRIC_VERSION,
1260
+ actions,
1261
+ quarantined,
1262
+ applied: applied.slice(0, MAX_COMPILED_SURFACE_PROPOSALS),
1263
+ gate,
1264
+ evidenceDigest
1265
+ };
1266
+ };
1267
+ var compileEntropySurface = (input) => {
1268
+ const effective = applyCompiledSurface(input.surface, input.artifact);
1269
+ const report = measureEntropy({
1270
+ traces: input.traces,
1271
+ surface: effective,
1272
+ ...input.repairs ? { repairs: input.repairs } : {},
1273
+ catalogDigest: input.catalogDigest ?? entropySurfaceHash(effective)
1274
+ });
1275
+ const proposals = proposeEntropyReductions({
1276
+ report,
1277
+ traces: input.traces,
1278
+ surface: effective,
1279
+ ...input.repairs ? { repairs: input.repairs } : {},
1280
+ ...input.valueObservations ? { valueObservations: input.valueObservations } : {}
1281
+ });
1282
+ const auto = proposals.filter(
1283
+ (proposal) => AUTO_APPLY_PROPOSAL_KINDS.includes(proposal.kind)
1284
+ );
1285
+ if (auto.length === 0) {
1286
+ return {
1287
+ status: "converged",
1288
+ ...input.artifact ? { artifact: input.artifact } : {},
1289
+ report,
1290
+ proposals
1291
+ };
1292
+ }
1293
+ const candidate = applyProposalsToSurface(effective, auto);
1294
+ const after = measureEntropy({
1295
+ traces: input.traces,
1296
+ surface: candidate,
1297
+ ...input.repairs ? { repairs: input.repairs } : {},
1298
+ catalogDigest: entropySurfaceHash(candidate)
1299
+ });
1300
+ const scoreGate = evaluateGate(report, after);
1301
+ const violations = replaySuccessfulCalls(
1302
+ candidate,
1303
+ effective,
1304
+ input.traces,
1305
+ touchedRefs(effective, candidate),
1306
+ input.auditCalls
1307
+ );
1308
+ const reasons = [
1309
+ ...scoreGate.reasons,
1310
+ ...violations.map((violation) => `${violation.ref}: ${violation.reason}`)
1311
+ ];
1312
+ const gate = {
1313
+ passed: scoreGate.passed && violations.length === 0,
1314
+ beforeScore: report.score,
1315
+ afterScore: after.score,
1316
+ delta: scoreGate.delta,
1317
+ reasons: scoreGate.passed && violations.length === 0 ? [] : reasons
1318
+ };
1319
+ if (gate.passed) {
1320
+ const evidenceDigest = stableJsonHash({
1321
+ traces: input.traces.length,
1322
+ operations: report.totals.operations,
1323
+ succeeded: report.totals.succeeded,
1324
+ failed: report.totals.failed,
1325
+ surface: entropySurfaceHash(effective),
1326
+ repairs: input.repairs?.length ?? 0,
1327
+ valueObservations: stableJsonHash(input.valueObservations ?? []),
1328
+ auditCalls: stableJsonHash(input.auditCalls ?? [])
1329
+ });
1330
+ return {
1331
+ status: "compiled",
1332
+ artifact: artifactFromCandidate(
1333
+ input.surface,
1334
+ candidate,
1335
+ auto,
1336
+ { passed: true, beforeScore: report.score, afterScore: after.score, reasons: [] },
1337
+ evidenceDigest,
1338
+ input.artifact
1339
+ ),
1340
+ report,
1341
+ after,
1342
+ proposals,
1343
+ gate
1344
+ };
1345
+ }
1346
+ return {
1347
+ status: "rejected",
1348
+ ...input.artifact ? { artifact: input.artifact } : {},
1349
+ report,
1350
+ after,
1351
+ proposals,
1352
+ gate
1353
+ };
1354
+ };
1355
+ var yieldToLoop3 = () => new Promise((resolve) => setImmediate(resolve));
1356
+ var compileEntropySurfaceAsync = async (input) => {
1357
+ const effective = applyCompiledSurface(input.surface, input.artifact);
1358
+ const report = await measureEntropyAsync({
1359
+ traces: input.traces,
1360
+ surface: effective,
1361
+ ...input.repairs ? { repairs: input.repairs } : {},
1362
+ catalogDigest: input.catalogDigest ?? entropySurfaceHash(effective)
1363
+ });
1364
+ await yieldToLoop3();
1365
+ const proposals = proposeEntropyReductions({
1366
+ report,
1367
+ traces: input.traces,
1368
+ surface: effective,
1369
+ ...input.repairs ? { repairs: input.repairs } : {},
1370
+ ...input.valueObservations ? { valueObservations: input.valueObservations } : {}
1371
+ });
1372
+ const auto = proposals.filter(
1373
+ (proposal) => AUTO_APPLY_PROPOSAL_KINDS.includes(proposal.kind)
1374
+ );
1375
+ if (auto.length === 0) {
1376
+ return {
1377
+ status: "converged",
1378
+ ...input.artifact ? { artifact: input.artifact } : {},
1379
+ report,
1380
+ proposals
1381
+ };
1382
+ }
1383
+ await yieldToLoop3();
1384
+ const candidate = applyProposalsToSurface(effective, auto);
1385
+ const after = await measureEntropyAsync({
1386
+ traces: input.traces,
1387
+ surface: candidate,
1388
+ ...input.repairs ? { repairs: input.repairs } : {},
1389
+ catalogDigest: entropySurfaceHash(candidate)
1390
+ });
1391
+ const scoreGate = evaluateGate(report, after);
1392
+ await yieldToLoop3();
1393
+ const violations = await replaySuccessfulCallsAsync(
1394
+ candidate,
1395
+ effective,
1396
+ input.traces,
1397
+ touchedRefs(effective, candidate),
1398
+ input.auditCalls
1399
+ );
1400
+ const reasons = [
1401
+ ...scoreGate.reasons,
1402
+ ...violations.map((violation) => `${violation.ref}: ${violation.reason}`)
1403
+ ];
1404
+ const gate = {
1405
+ passed: scoreGate.passed && violations.length === 0,
1406
+ beforeScore: report.score,
1407
+ afterScore: after.score,
1408
+ delta: scoreGate.delta,
1409
+ reasons: scoreGate.passed && violations.length === 0 ? [] : reasons
1410
+ };
1411
+ if (gate.passed) {
1412
+ const [valueObservationsDigest, auditCallsDigest] = await Promise.all([
1413
+ stableJsonHashArrayAsync(input.valueObservations ?? []),
1414
+ stableJsonHashArrayAsync(input.auditCalls ?? [])
1415
+ ]);
1416
+ const evidenceDigest = stableJsonHash({
1417
+ traces: input.traces.length,
1418
+ operations: report.totals.operations,
1419
+ succeeded: report.totals.succeeded,
1420
+ failed: report.totals.failed,
1421
+ surface: entropySurfaceHash(effective),
1422
+ repairs: input.repairs?.length ?? 0,
1423
+ valueObservations: valueObservationsDigest,
1424
+ auditCalls: auditCallsDigest
1425
+ });
1426
+ return {
1427
+ status: "compiled",
1428
+ artifact: artifactFromCandidate(
1429
+ input.surface,
1430
+ candidate,
1431
+ auto,
1432
+ { passed: true, beforeScore: report.score, afterScore: after.score, reasons: [] },
1433
+ evidenceDigest,
1434
+ input.artifact
1435
+ ),
1436
+ report,
1437
+ after,
1438
+ proposals,
1439
+ gate
1440
+ };
1441
+ }
1442
+ return {
1443
+ status: "rejected",
1444
+ ...input.artifact ? { artifact: input.artifact } : {},
1445
+ report,
1446
+ after,
1447
+ proposals,
1448
+ gate
1449
+ };
1450
+ };
1451
+
1452
+ // src/entropy/presentation.ts
1453
+ var METRIC_PRECISION = 6;
1454
+ var MAX_APPLIED_DETAILS = 3;
1455
+ var MAX_VALUE_LENGTH = 32;
1456
+ var ENTROPY_COMMAND_HINTS = [
1457
+ {
1458
+ label: "export",
1459
+ command: "/fabric entropy export [path]",
1460
+ comment: "snapshot the live surface (default <agent dir>/fabric/entropy/surface.json)"
1461
+ },
1462
+ {
1463
+ label: "share",
1464
+ command: "/fabric entropy export-artifact [path]",
1465
+ comment: "write the compiled artifact (default <agent dir>/fabric/entropy/artifact.json)"
1466
+ },
1467
+ {
1468
+ label: "merge",
1469
+ command: "/fabric entropy import <path>",
1470
+ comment: "merge a peer artifact (digest-proven entries only)"
1471
+ }
1472
+ ];
1473
+ var formatEntropyMetric = (value) => value.toFixed(METRIC_PRECISION);
1474
+ var formatEntropyCommandHints = () => {
1475
+ const heads = ENTROPY_COMMAND_HINTS.map((hint) => `${hint.label}: ${hint.command}`);
1476
+ const commentColumn = Math.max(...heads.map((head) => head.length)) + 2;
1477
+ return ENTROPY_COMMAND_HINTS.map(
1478
+ (hint, index) => `${heads[index].padEnd(commentColumn)}# ${hint.comment}`
1479
+ );
1480
+ };
1481
+ var formatDuration = (elapsedMs) => elapsedMs >= 1e3 ? `${(elapsedMs / 1e3).toFixed(1)}s` : `${Math.max(1, Math.round(elapsedMs))}ms`;
1482
+ var formatValue = (value) => {
1483
+ const rendered = typeof value === "string" ? value.replace(/\s+/gu, " ").trim() || '""' : String(value);
1484
+ return rendered.length <= MAX_VALUE_LENGTH ? rendered : `${rendered.slice(0, MAX_VALUE_LENGTH - 1)}\u2026`;
1485
+ };
1486
+ var formatValues = (values) => `{${values.map(formatValue).join(", ")}}`;
1487
+ var autoProposal = (proposal) => proposal.kind === "enum-tighten" || proposal.kind === "noise-quarantine";
1488
+ var formatApplied = (proposal) => {
1489
+ if (proposal.kind === "enum-tighten") {
1490
+ return `tightened ${proposal.ref}.${proposal.key} to ${formatValues(proposal.values)}`;
1491
+ }
1492
+ if (proposal.kind === "noise-quarantine") {
1493
+ return `hid ${proposal.ref} (${proposal.failed} failed, ${proposal.succeeded} succeeded)`;
1494
+ }
1495
+ return proposal.kind;
1496
+ };
1497
+ var scoreChange = (before, after) => {
1498
+ if (before === after) {
1499
+ return `entropy score unchanged at ${formatEntropyMetric(before)} (lower is better)`;
1500
+ }
1501
+ let precision = METRIC_PRECISION;
1502
+ while (precision < 12 && before.toFixed(precision) === after.toFixed(precision)) precision += 1;
1503
+ const delta = after - before;
1504
+ const format = (value) => value.toFixed(precision);
1505
+ const absoluteDelta = format(Math.abs(delta));
1506
+ const renderedDelta = Number(absoluteDelta) === 0 ? Math.abs(delta).toExponential(2) : absoluteDelta;
1507
+ return `entropy score ${delta < 0 ? "improved" : "changed"} ${format(before)} \u2192 ${format(after)} (${delta > 0 ? "+" : "\u2212"}${renderedDelta}; lower is better)`;
1508
+ };
1509
+ var entropyReviewKey = (proposals) => {
1510
+ const identities = proposals.map((proposal) => {
1511
+ if (proposal.kind === "declare-enum") {
1512
+ return JSON.stringify([
1513
+ proposal.kind,
1514
+ proposal.ref,
1515
+ proposal.key,
1516
+ proposal.values.map((value) => [typeof value, value])
1517
+ ]);
1518
+ }
1519
+ if (proposal.kind === "overload-split") {
1520
+ return JSON.stringify([
1521
+ proposal.kind,
1522
+ proposal.ref,
1523
+ proposal.clusters.map((cluster) => cluster.keys)
1524
+ ]);
1525
+ }
1526
+ if (proposal.kind === "sequence-fuse") {
1527
+ return JSON.stringify([proposal.kind, proposal.sequence]);
1528
+ }
1529
+ return JSON.stringify([proposal.kind, proposal.ref]);
1530
+ });
1531
+ identities.sort();
1532
+ return JSON.stringify(identities);
1533
+ };
1534
+ var reviewLabel = (kind, count) => {
1535
+ const noun = kind === "declare-enum" ? "enum declaration" : kind === "overload-split" ? "action split" : kind === "sequence-fuse" ? "sequence fusion" : kind;
1536
+ return `${count} ${noun}${count === 1 ? "" : "s"}`;
1537
+ };
1538
+ var formatEntropyReviewNotice = (proposals) => {
1539
+ const counts = /* @__PURE__ */ new Map();
1540
+ for (const proposal of proposals) counts.set(proposal.kind, (counts.get(proposal.kind) ?? 0) + 1);
1541
+ const summary = [...counts.entries()].map(([kind, count]) => reviewLabel(kind, count)).join(" \xB7 ");
1542
+ return `entropy: ${proposals.length} suggestion${proposals.length === 1 ? "" : "s"} await review${summary ? ` \xB7 ${summary}` : ""} \xB7 inspect with /fabric entropy`;
1543
+ };
1544
+ var formatEntropyCompileNotice = (input) => {
1545
+ const applied = input.proposals.filter(autoProposal);
1546
+ const details = applied.slice(0, MAX_APPLIED_DETAILS).map(formatApplied);
1547
+ if (applied.length > MAX_APPLIED_DETAILS) {
1548
+ details.push(`+${applied.length - MAX_APPLIED_DETAILS} more`);
1549
+ }
1550
+ if (details.length === 0) details.push("surface updated");
1551
+ const review = input.reviewCount ? ` \xB7 ${input.reviewCount} suggestion${input.reviewCount === 1 ? "" : "s"} await review (/fabric entropy)` : "";
1552
+ return `entropy: background optimization complete (${formatDuration(input.elapsedMs)}) \xB7 ${details.join(" \xB7 ")} \xB7 ${scoreChange(input.beforeScore, input.afterScore)} \xB7 safety checks passed${review}`;
1553
+ };
1554
+
1555
+ // src/entropy/corpus.ts
1556
+ var DEFAULT_TASK_KEY2 = "(none)";
1557
+ var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1558
+ var entropyTraceFromFabricTrace = (trace, model) => ({
1559
+ operations: trace.operations.map((operation) => ({
1560
+ ref: operation.ref,
1561
+ args: operation.args,
1562
+ outcome: operation.outcome,
1563
+ ...operation.failureStage !== void 0 ? { failureStage: operation.failureStage } : {}
1564
+ })),
1565
+ taskKey: trace.phases[0] ?? DEFAULT_TASK_KEY2,
1566
+ ...model ? { model } : {}
1567
+ });
1568
+ var MODEL_CHANGE_FILTER = '"type":"model_change"';
1569
+ var ASSISTANT_FILTER = '"role":"assistant"';
1570
+ var modelFromRecord = (parsed) => {
1571
+ if (parsed.type === "model_change") {
1572
+ const provider2 = typeof parsed.provider === "string" ? parsed.provider : "";
1573
+ const modelId2 = typeof parsed.modelId === "string" ? parsed.modelId : "";
1574
+ return provider2 && modelId2 ? `${provider2}/${modelId2}` : void 0;
1575
+ }
1576
+ const message = isRecord2(parsed.message) ? parsed.message : void 0;
1577
+ if (!message || message.role !== "assistant") return void 0;
1578
+ const provider = typeof message.provider === "string" ? message.provider : "";
1579
+ const modelId = typeof message.model === "string" ? message.model : "";
1580
+ return provider && modelId ? `${provider}/${modelId}` : void 0;
1581
+ };
1582
+ var scanSessionLine = (line, state) => {
1583
+ if (line === "") return void 0;
1584
+ const traceLine = line.includes(FABRIC_EXECUTION_TRACE_KIND);
1585
+ const modelLine = !traceLine && (line.includes(MODEL_CHANGE_FILTER) || line.includes(ASSISTANT_FILTER));
1586
+ if (!traceLine && !modelLine) return void 0;
1587
+ let parsed;
1588
+ try {
1589
+ parsed = JSON.parse(line.trim());
1590
+ } catch {
1591
+ return void 0;
1592
+ }
1593
+ if (!isRecord2(parsed)) return void 0;
1594
+ if (modelLine) {
1595
+ const model = modelFromRecord(parsed);
1596
+ if (model) state.currentModel = model;
1597
+ return void 0;
1598
+ }
1599
+ const details = isRecord2(parsed.details) ? parsed.details : isRecord2(parsed.message) && isRecord2(parsed.message.details) ? parsed.message.details : void 0;
1600
+ return isRecord2(details) ? { details, ...state.currentModel ? { model: state.currentModel } : {} } : void 0;
1601
+ };
1602
+ var emptySessionEvidence = () => ({
1603
+ traces: [],
1604
+ valueObservations: [],
1605
+ auditCalls: []
1606
+ });
1607
+ var appendSessionRecord = (evidence, record) => {
1608
+ const trace = readFabricExecutionTraceV1(record.details.trace);
1609
+ if (trace) evidence.traces.push(entropyTraceFromFabricTrace(trace, record.model));
1610
+ const audits = record.details.audits;
1611
+ if (!Array.isArray(audits)) return;
1612
+ for (const audit of audits) {
1613
+ if (!isRecord2(audit)) continue;
1614
+ const ref = typeof audit.ref === "string" ? audit.ref : void 0;
1615
+ const args = isRecord2(audit.args) ? audit.args : void 0;
1616
+ if (!ref || !args) continue;
1617
+ evidence.auditCalls.push({ ref, args });
1618
+ for (const [key, value] of Object.entries(args)) {
1619
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1620
+ evidence.valueObservations.push({ ref, key, value });
1621
+ }
1622
+ }
1623
+ }
1624
+ };
1625
+ var entropySessionEvidenceFromJsonl = (lines) => {
1626
+ const evidence = emptySessionEvidence();
1627
+ const state = {};
1628
+ for (const line of lines) {
1629
+ const record = scanSessionLine(line, state);
1630
+ if (record) appendSessionRecord(evidence, record);
1631
+ }
1632
+ return evidence;
1633
+ };
1634
+ var scanEntropySessionJsonlAsync = async (lines, initialModel) => {
1635
+ const evidence = emptySessionEvidence();
1636
+ const state = {
1637
+ ...initialModel ? { currentModel: initialModel } : {}
1638
+ };
1639
+ for await (const line of lines) {
1640
+ const record = scanSessionLine(line, state);
1641
+ if (record) appendSessionRecord(evidence, record);
1642
+ }
1643
+ return {
1644
+ evidence,
1645
+ ...state.currentModel ? { currentModel: state.currentModel } : {}
1646
+ };
1647
+ };
1648
+ var entropySessionEvidenceFromJsonlAsync = async (lines) => (await scanEntropySessionJsonlAsync(lines)).evidence;
1649
+ var entropyTracesFromSessionJsonl = (lines) => entropySessionEvidenceFromJsonl(lines).traces;
1650
+ var entropyValueObservationsFromSessionJsonl = (lines) => entropySessionEvidenceFromJsonl(lines).valueObservations;
1651
+ var entropyAuditCallsFromSessionJsonl = (lines) => entropySessionEvidenceFromJsonl(lines).auditCalls;
1652
+ var entropyRepairRows = (repairs) => repairs.map(
1653
+ (repair) => repair.kind === "keyAlias" ? { kind: "keyAlias", ref: repair.ref, from: repair.from, to: repair.to } : {
1654
+ kind: "actionAlias",
1655
+ ref: `${repair.provider}.${repair.to}`,
1656
+ from: repair.from,
1657
+ to: repair.to
1658
+ }
1659
+ );
1660
+ var entropyReportHash = (report) => stableJsonHash(report);
1661
+
1662
+ // src/entropy/sessions.ts
1663
+ import fs2 from "node:fs";
1664
+ import path2 from "node:path";
1665
+ import { createInterface } from "node:readline";
1666
+ var DEFAULT_SESSION_WINDOW = 8;
1667
+ var SESSION_STAT_CONCURRENCY = 32;
1668
+ var SESSION_READ_CONCURRENCY = 4;
1669
+ var SESSION_EVIDENCE_CACHE_LIMIT = 16;
1670
+ var asyncEvidenceCache = /* @__PURE__ */ new Map();
1671
+ var mapConcurrent = async (items, limit, fn) => {
1672
+ const results = new Array(items.length);
1673
+ let cursor = 0;
1674
+ const worker = async () => {
1675
+ for (; ; ) {
1676
+ const index = cursor++;
1677
+ if (index >= items.length) return;
1678
+ results[index] = await fn(items[index]);
1679
+ }
1680
+ };
1681
+ await Promise.all(
1682
+ Array.from({ length: Math.min(limit, items.length) }, () => worker())
1683
+ );
1684
+ return results;
1685
+ };
1686
+ var byNewestSession = (left, right) => right.mtime - left.mtime || (left.file < right.file ? -1 : left.file > right.file ? 1 : 0);
1687
+ var stampSessionFiles = async (files) => mapConcurrent(files, SESSION_STAT_CONCURRENCY, async (file) => {
1688
+ let mtime = 0;
1689
+ try {
1690
+ mtime = (await fs2.promises.stat(file)).mtimeMs;
1691
+ } catch {
1692
+ }
1693
+ return { file, mtime };
1694
+ });
1695
+ var projectSessionFiles = (agentDir, cwd, limit = DEFAULT_SESSION_WINDOW) => {
1696
+ const dir = sessionDirForCwd(cwd, agentDir);
1697
+ let entries = [];
1698
+ try {
1699
+ entries = fs2.readdirSync(dir, { withFileTypes: true });
1700
+ } catch {
1701
+ return [];
1702
+ }
1703
+ const stamped = entries.filter((entry) => entry.isFile() && entry.name.endsWith(".jsonl")).map((entry) => {
1704
+ const file = path2.join(dir, entry.name);
1705
+ let mtime = 0;
1706
+ try {
1707
+ mtime = fs2.statSync(file).mtimeMs;
1708
+ } catch {
1709
+ mtime = 0;
1710
+ }
1711
+ return { file, mtime };
1712
+ });
1713
+ stamped.sort(
1714
+ (left, right) => right.mtime - left.mtime || (left.file < right.file ? -1 : left.file > right.file ? 1 : 0)
1715
+ );
1716
+ return stamped.slice(0, Math.max(1, limit)).map((entry) => entry.file);
1717
+ };
1718
+ var machineSessionFiles = (agentDir, cwd, limit = DEFAULT_SESSION_WINDOW) => {
1719
+ const root = sessionsDirRoot(agentDir);
1720
+ let projectDirs = [];
1721
+ try {
1722
+ projectDirs = fs2.readdirSync(root, { withFileTypes: true });
1723
+ } catch {
1724
+ return [];
1725
+ }
1726
+ const byNewest = (left, right) => right.mtime - left.mtime || (left.file < right.file ? -1 : left.file > right.file ? 1 : 0);
1727
+ const stamped = [];
1728
+ const directories = projectDirs.filter((entry) => entry.isDirectory()).sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
1729
+ for (const directory of directories) {
1730
+ let entries = [];
1731
+ try {
1732
+ entries = fs2.readdirSync(path2.join(root, directory.name), { withFileTypes: true });
1733
+ } catch {
1734
+ continue;
1735
+ }
1736
+ for (const entry of entries.filter(
1737
+ (candidate) => candidate.isFile() && candidate.name.endsWith(".jsonl")
1738
+ )) {
1739
+ const file = path2.join(root, directory.name, entry.name);
1740
+ let mtime = 0;
1741
+ try {
1742
+ mtime = fs2.statSync(file).mtimeMs;
1743
+ } catch {
1744
+ mtime = 0;
1745
+ }
1746
+ stamped.push({ file, mtime });
1747
+ }
1748
+ }
1749
+ stamped.sort(byNewest);
1750
+ const window = Math.max(1, limit);
1751
+ let selected = stamped.slice(0, window);
1752
+ if (cwd) {
1753
+ const current = projectSessionFiles(agentDir, cwd, 1)[0];
1754
+ if (current !== void 0 && !selected.some((entry) => entry.file === current)) {
1755
+ const kept = [...selected];
1756
+ if (kept.length >= window) kept.length = window - 1;
1757
+ let mtime = 0;
1758
+ try {
1759
+ mtime = fs2.statSync(current).mtimeMs;
1760
+ } catch {
1761
+ mtime = 0;
1762
+ }
1763
+ kept.push({ file: current, mtime });
1764
+ kept.sort(byNewest);
1765
+ selected = kept;
1766
+ }
1767
+ }
1768
+ return selected.map((entry) => entry.file);
1769
+ };
1770
+ var projectSessionFilesAsync = async (agentDir, cwd, limit = DEFAULT_SESSION_WINDOW) => {
1771
+ const dir = sessionDirForCwd(cwd, agentDir);
1772
+ let entries;
1773
+ try {
1774
+ entries = await fs2.promises.readdir(dir, { withFileTypes: true });
1775
+ } catch {
1776
+ return [];
1777
+ }
1778
+ const files = entries.filter((entry) => entry.isFile() && entry.name.endsWith(".jsonl")).map((entry) => path2.join(dir, entry.name));
1779
+ const stamped = await stampSessionFiles(files);
1780
+ stamped.sort(byNewestSession);
1781
+ return stamped.slice(0, Math.max(1, limit)).map((entry) => entry.file);
1782
+ };
1783
+ var machineSessionFilesAsync = async (agentDir, cwd, limit = DEFAULT_SESSION_WINDOW) => {
1784
+ const root = sessionsDirRoot(agentDir);
1785
+ let projectDirs;
1786
+ try {
1787
+ projectDirs = await fs2.promises.readdir(root, { withFileTypes: true });
1788
+ } catch {
1789
+ return [];
1790
+ }
1791
+ const directories = projectDirs.filter((entry) => entry.isDirectory()).sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
1792
+ const filesByDirectory = await mapConcurrent(
1793
+ directories,
1794
+ SESSION_STAT_CONCURRENCY,
1795
+ async (directory) => {
1796
+ const dir = path2.join(root, directory.name);
1797
+ try {
1798
+ return (await fs2.promises.readdir(dir, { withFileTypes: true })).filter((entry) => entry.isFile() && entry.name.endsWith(".jsonl")).map((entry) => path2.join(dir, entry.name));
1799
+ } catch {
1800
+ return [];
1801
+ }
1802
+ }
1803
+ );
1804
+ const stamped = await stampSessionFiles(filesByDirectory.flat());
1805
+ stamped.sort(byNewestSession);
1806
+ const window = Math.max(1, limit);
1807
+ let selected = stamped.slice(0, window);
1808
+ if (cwd) {
1809
+ const current = (await projectSessionFilesAsync(agentDir, cwd, 1))[0];
1810
+ if (current !== void 0 && !selected.some((entry) => entry.file === current)) {
1811
+ const kept = [...selected];
1812
+ if (kept.length >= window) kept.length = window - 1;
1813
+ const [stampedCurrent] = await stampSessionFiles([current]);
1814
+ if (stampedCurrent) kept.push(stampedCurrent);
1815
+ kept.sort(byNewestSession);
1816
+ selected = kept;
1817
+ }
1818
+ }
1819
+ return selected.map((entry) => entry.file);
1820
+ };
1821
+ var finalizeSessionCorpus = (files, sessions) => {
1822
+ const chronological = [...sessions].reverse();
1823
+ const modelScores = /* @__PURE__ */ new Map();
1824
+ for (const session of chronological) {
1825
+ for (const model of session.report.byModel) {
1826
+ const entry = modelScores.get(model.model) ?? { behavioral: [], latest: model };
1827
+ entry.behavioral.push(model.behavioralScore);
1828
+ entry.latest = model;
1829
+ modelScores.set(model.model, entry);
1830
+ }
1831
+ }
1832
+ const models = [...modelScores.entries()].sort(([left], [right]) => compareCodeUnits(left, right)).map(([model, entry]) => ({
1833
+ model,
1834
+ sessions: entry.behavioral.length,
1835
+ latestBehavioralScore: entry.latest.behavioralScore,
1836
+ slopePerSession: trendFromScores(entry.behavioral).slopePerStep,
1837
+ latestRejectionsPer1k: entry.latest.invocationRejectionsPer1k
1838
+ }));
1839
+ return {
1840
+ files,
1841
+ sessions,
1842
+ ...sessions.length > 0 ? { latest: sessions[0].report } : {},
1843
+ trend: trendFromScores(chronological.map((session) => session.report.score)),
1844
+ models
1845
+ };
1846
+ };
1847
+ var measureSessionCorpus = (input) => {
1848
+ const sessions = [];
1849
+ for (const file of input.files) {
1850
+ let text;
1851
+ try {
1852
+ text = fs2.readFileSync(file, "utf8");
1853
+ } catch {
1854
+ continue;
1855
+ }
1856
+ const traces = entropyTracesFromSessionJsonl(text.split("\n"));
1857
+ if (traces.length === 0) continue;
1858
+ const report = measureEntropy({
1859
+ traces,
1860
+ ...input.surface ? { surface: input.surface } : {},
1861
+ ...input.catalogDigest !== void 0 ? { catalogDigest: input.catalogDigest } : {}
1862
+ });
1863
+ if (report.totals.operations === 0) continue;
1864
+ sessions.push({ file, operations: report.totals.operations, report });
1865
+ }
1866
+ return finalizeSessionCorpus(input.files, sessions);
1867
+ };
1868
+ var sessionMetadata = async (file) => {
1869
+ try {
1870
+ const entry = await fs2.promises.stat(file);
1871
+ return {
1872
+ size: entry.size,
1873
+ mtimeMs: entry.mtimeMs,
1874
+ dev: entry.dev,
1875
+ ino: entry.ino
1876
+ };
1877
+ } catch {
1878
+ return void 0;
1879
+ }
1880
+ };
1881
+ var endsAtLineBoundary = async (file, metadata) => {
1882
+ if (metadata.size === 0) return true;
1883
+ let handle;
1884
+ try {
1885
+ handle = await fs2.promises.open(file, "r");
1886
+ const byte = Buffer.allocUnsafe(1);
1887
+ const { bytesRead } = await handle.read(byte, 0, 1, metadata.size - 1);
1888
+ return bytesRead === 1 && byte[0] === 10;
1889
+ } catch {
1890
+ return false;
1891
+ } finally {
1892
+ await handle?.close().catch(() => void 0);
1893
+ }
1894
+ };
1895
+ var scanSessionRange = async (file, start, end, initialModel) => {
1896
+ const input = fs2.createReadStream(file, { encoding: "utf8", start, end });
1897
+ const lines = createInterface({ input, crlfDelay: Infinity });
1898
+ try {
1899
+ return await scanEntropySessionJsonlAsync(lines, initialModel);
1900
+ } finally {
1901
+ lines.close();
1902
+ input.destroy();
1903
+ }
1904
+ };
1905
+ var evidenceWindow = (file, evidence) => ({
1906
+ traces: evidence.traces,
1907
+ valueObservations: evidence.valueObservations,
1908
+ auditCalls: evidence.auditCalls,
1909
+ observationWindows: [{ file, observations: evidence.valueObservations }]
1910
+ });
1911
+ var cacheSessionEvidence = (file, cached) => {
1912
+ asyncEvidenceCache.delete(file);
1913
+ asyncEvidenceCache.set(file, cached);
1914
+ while (asyncEvidenceCache.size > SESSION_EVIDENCE_CACHE_LIMIT) {
1915
+ asyncEvidenceCache.delete(asyncEvidenceCache.keys().next().value);
1916
+ }
1917
+ };
1918
+ var sameSessionFile = (cached, metadata) => cached.dev === metadata.dev && cached.ino === metadata.ino;
1919
+ var readSessionEvidenceAsync = async (file) => {
1920
+ const metadata = await sessionMetadata(file);
1921
+ if (!metadata) return void 0;
1922
+ const cached = asyncEvidenceCache.get(file);
1923
+ if (cached && sameSessionFile(cached, metadata) && cached.size === metadata.size && Math.abs(cached.mtimeMs - metadata.mtimeMs) <= 1e-6) {
1924
+ cacheSessionEvidence(file, cached);
1925
+ return evidenceWindow(file, cached.evidence);
1926
+ }
1927
+ const append = cached && sameSessionFile(cached, metadata) && metadata.size > cached.size ? cached : void 0;
1928
+ const start = append ? append.size : 0;
1929
+ let scan;
1930
+ try {
1931
+ scan = metadata.size === start ? {
1932
+ evidence: { traces: [], valueObservations: [], auditCalls: [] },
1933
+ ...append?.currentModel ? { currentModel: append.currentModel } : {}
1934
+ } : await scanSessionRange(
1935
+ file,
1936
+ start,
1937
+ metadata.size - 1,
1938
+ append?.currentModel
1939
+ );
1940
+ } catch {
1941
+ return void 0;
1942
+ }
1943
+ const evidence = append ? {
1944
+ traces: [...append.evidence.traces, ...scan.evidence.traces],
1945
+ valueObservations: [
1946
+ ...append.evidence.valueObservations,
1947
+ ...scan.evidence.valueObservations
1948
+ ],
1949
+ auditCalls: [...append.evidence.auditCalls, ...scan.evidence.auditCalls]
1950
+ } : scan.evidence;
1951
+ if (await endsAtLineBoundary(file, metadata)) {
1952
+ cacheSessionEvidence(file, {
1953
+ ...metadata,
1954
+ ...scan.currentModel ? { currentModel: scan.currentModel } : {},
1955
+ evidence
1956
+ });
1957
+ } else {
1958
+ asyncEvidenceCache.delete(file);
1959
+ }
1960
+ return evidenceWindow(file, evidence);
1961
+ };
1962
+ var sessionWindowEvidenceAsync = async (files) => {
1963
+ const windows = await mapConcurrent(files, SESSION_READ_CONCURRENCY, readSessionEvidenceAsync);
1964
+ const traces = [];
1965
+ const valueObservations = [];
1966
+ const auditCalls = [];
1967
+ const observationWindows = [];
1968
+ for (const window of windows) {
1969
+ if (!window) continue;
1970
+ traces.push(...window.traces);
1971
+ valueObservations.push(...window.valueObservations);
1972
+ auditCalls.push(...window.auditCalls);
1973
+ observationWindows.push(...window.observationWindows);
1974
+ }
1975
+ return { traces, valueObservations, auditCalls, observationWindows };
1976
+ };
1977
+ var measureSessionCorpusAsync = async (input) => {
1978
+ const windows = await mapConcurrent(
1979
+ input.files,
1980
+ SESSION_READ_CONCURRENCY,
1981
+ readSessionEvidenceAsync
1982
+ );
1983
+ const sessions = [];
1984
+ for (let index = 0; index < input.files.length; index++) {
1985
+ const window = windows[index];
1986
+ const file = input.files[index];
1987
+ if (!window || !file || window.traces.length === 0) continue;
1988
+ const report = await measureEntropyAsync({
1989
+ traces: window.traces,
1990
+ ...input.surface ? { surface: input.surface } : {},
1991
+ ...input.catalogDigest !== void 0 ? { catalogDigest: input.catalogDigest } : {}
1992
+ });
1993
+ if (report.totals.operations === 0) continue;
1994
+ sessions.push({ file, operations: report.totals.operations, report });
1995
+ }
1996
+ return finalizeSessionCorpus(input.files, sessions);
1997
+ };
1998
+ var sessionWindowEvidence = (files) => {
1999
+ const traces = [];
2000
+ const valueObservations = [];
2001
+ const auditCalls = [];
2002
+ const observationWindows = [];
2003
+ for (const file of files) {
2004
+ let text;
2005
+ try {
2006
+ text = fs2.readFileSync(file, "utf8");
2007
+ } catch {
2008
+ continue;
2009
+ }
2010
+ const evidence = entropySessionEvidenceFromJsonl(text.split("\n"));
2011
+ traces.push(...evidence.traces);
2012
+ valueObservations.push(...evidence.valueObservations);
2013
+ auditCalls.push(...evidence.auditCalls);
2014
+ observationWindows.push({ file, observations: evidence.valueObservations });
2015
+ }
2016
+ return { traces, valueObservations, auditCalls, observationWindows };
2017
+ };
2018
+
2019
+ // src/entropy/trial.ts
2020
+ import { isJsonSchemaValueValid } from "@oh-my-pi/pi-ai/utils/schema";
2021
+ var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
2022
+ var accepts = (schema, args) => {
2023
+ try {
2024
+ return isRecord3(schema) && isJsonSchemaValueValid(schema, args);
2025
+ } catch {
2026
+ return false;
2027
+ }
2028
+ };
2029
+ var trialClassFields = {
2030
+ "both-accept": "bothAccept",
2031
+ "both-reject": "bothReject",
2032
+ "tightening-cost": "tighteningCost",
2033
+ "typed-failure-win": "typedFailureWin",
2034
+ "quarantine-win": "quarantineWin",
2035
+ "quarantine-cost": "quarantineCost"
2036
+ };
2037
+ var trialClassField = (trialClass) => trialClassFields[trialClass];
2038
+ var classify = (operation, declaredAccepts, compiledAccepts, quarantined) => {
2039
+ if (quarantined) {
2040
+ if (!declaredAccepts) return "both-reject";
2041
+ return operation.outcome === "succeeded" ? "quarantine-cost" : "quarantine-win";
2042
+ }
2043
+ if (!declaredAccepts) return "both-reject";
2044
+ if (compiledAccepts) return "both-accept";
2045
+ return operation.outcome === "succeeded" ? "tightening-cost" : "typed-failure-win";
2046
+ };
2047
+ var runEntropyTrial = (input) => {
2048
+ const effective = applyCompiledSurface(input.live, input.artifact);
2049
+ const declaredByRef = new Map(
2050
+ input.live.actions.map((action) => [action.ref, action.inputSchema])
2051
+ );
2052
+ const effectiveByRef = new Map(
2053
+ effective.actions.map((action) => [action.ref, action.inputSchema])
2054
+ );
2055
+ const declaredReport = measureEntropy({
2056
+ traces: input.traces,
2057
+ surface: input.live,
2058
+ catalogDigest: entropySurfaceHash(input.live)
2059
+ });
2060
+ const effectiveReport = measureEntropy({
2061
+ traces: input.traces,
2062
+ surface: effective,
2063
+ catalogDigest: entropySurfaceHash(effective)
2064
+ });
2065
+ const totals = {
2066
+ operations: 0,
2067
+ bothAccept: 0,
2068
+ bothReject: 0,
2069
+ tighteningCost: 0,
2070
+ typedFailureWin: 0,
2071
+ quarantineWin: 0,
2072
+ quarantineCost: 0
2073
+ };
2074
+ const divergenceCounts = /* @__PURE__ */ new Map();
2075
+ const auditedArgsByRef = /* @__PURE__ */ new Map();
2076
+ if (input.auditCalls) {
2077
+ for (const call of input.auditCalls) {
2078
+ if (declaredByRef.get(call.ref) === void 0) continue;
2079
+ const bucket = auditedArgsByRef.get(call.ref) ?? [];
2080
+ bucket.push(call.args);
2081
+ auditedArgsByRef.set(call.ref, bucket);
2082
+ }
2083
+ }
2084
+ for (const trace of input.traces) {
2085
+ for (const operation of trace.operations) {
2086
+ if (operation.ref.startsWith("fabric.")) continue;
2087
+ const declared = declaredByRef.get(operation.ref);
2088
+ if (declared === void 0) continue;
2089
+ if (auditedArgsByRef.has(operation.ref)) continue;
2090
+ const compiled = effectiveByRef.get(operation.ref);
2091
+ const quarantined = compiled === void 0;
2092
+ const trialClass = classify(
2093
+ operation,
2094
+ accepts(declared, operation.args),
2095
+ quarantined ? false : accepts(compiled, operation.args),
2096
+ quarantined
2097
+ );
2098
+ totals.operations++;
2099
+ totals[trialClassField(trialClass)]++;
2100
+ if (trialClass !== "both-accept" && trialClass !== "both-reject") {
2101
+ const key = `${operation.ref}\0${trialClass}`;
2102
+ divergenceCounts.set(key, (divergenceCounts.get(key) ?? 0) + 1);
2103
+ }
2104
+ }
2105
+ }
2106
+ for (const ref of [...auditedArgsByRef.keys()].sort(compareCodeUnits)) {
2107
+ const declared = declaredByRef.get(ref);
2108
+ const compiled = effectiveByRef.get(ref);
2109
+ const quarantined = compiled === void 0;
2110
+ for (const args of auditedArgsByRef.get(ref)) {
2111
+ const declaredAccepts = accepts(declared, args);
2112
+ const trialClass = !declaredAccepts ? "both-reject" : quarantined ? "quarantine-cost" : accepts(compiled, args) ? "both-accept" : "tightening-cost";
2113
+ totals.operations++;
2114
+ totals[trialClassField(trialClass)]++;
2115
+ if (trialClass !== "both-accept" && trialClass !== "both-reject") {
2116
+ const key = `${ref}\0${trialClass}`;
2117
+ divergenceCounts.set(key, (divergenceCounts.get(key) ?? 0) + 1);
2118
+ }
2119
+ }
2120
+ }
2121
+ const hasEntries = (input.artifact?.actions.length ?? 0) + (input.artifact?.quarantined.length ?? 0) > 0;
2122
+ const costs = totals.tighteningCost + totals.quarantineCost;
2123
+ const verdict = !hasEntries || totals.operations === 0 ? "no-evidence" : costs === 0 ? "clean" : "costly";
2124
+ const divergences = [...divergenceCounts.entries()].map(([key, count]) => {
2125
+ const [ref, trialClass] = key.split("\0");
2126
+ return { ref, trialClass, count };
2127
+ }).sort(
2128
+ (left, right) => compareCodeUnits(left.ref, right.ref) || compareCodeUnits(left.trialClass, right.trialClass)
2129
+ );
2130
+ return {
2131
+ verdict,
2132
+ declaredScore: declaredReport.score,
2133
+ effectiveScore: effectiveReport.score,
2134
+ delta: effectiveReport.score - declaredReport.score,
2135
+ totals,
2136
+ divergences
2137
+ };
2138
+ };
2139
+
2140
+ export {
2141
+ ENTROPY_METRIC_VERSION,
2142
+ ENTROPY_WEIGHTS,
2143
+ ENTROPY_INVOCATION_STAGES,
2144
+ roundMetric,
2145
+ compareCodeUnits,
2146
+ shapeSignature,
2147
+ signatureDistance,
2148
+ shannonEntropyBits,
2149
+ staticFreedomFromSchema,
2150
+ trendFromScores,
2151
+ liveSurfaceSnapshot,
2152
+ entropySurfaceHash,
2153
+ surfaceFreedomReport,
2154
+ entropyTraceFromFabricTrace,
2155
+ entropySessionEvidenceFromJsonl,
2156
+ scanEntropySessionJsonlAsync,
2157
+ entropySessionEvidenceFromJsonlAsync,
2158
+ entropyTracesFromSessionJsonl,
2159
+ entropyValueObservationsFromSessionJsonl,
2160
+ entropyAuditCallsFromSessionJsonl,
2161
+ entropyRepairRows,
2162
+ entropyReportHash,
2163
+ measureEntropy,
2164
+ measureEntropyAsync,
2165
+ projectSessionFiles,
2166
+ machineSessionFiles,
2167
+ projectSessionFilesAsync,
2168
+ machineSessionFilesAsync,
2169
+ measureSessionCorpus,
2170
+ sessionWindowEvidenceAsync,
2171
+ measureSessionCorpusAsync,
2172
+ sessionWindowEvidence,
2173
+ ENTROPY_ENUM_CANDIDATE_ANNOTATION,
2174
+ proposeEntropyReductions,
2175
+ applyProposalsToSurface,
2176
+ evaluateGate,
2177
+ AUTO_APPLY_PROPOSAL_KINDS,
2178
+ entropyReviewSignals,
2179
+ formatEntropyReviewSignal,
2180
+ compileEntropySurface,
2181
+ compileEntropySurfaceAsync,
2182
+ OBSERVATION_POOL_VERSION,
2183
+ POOL_TRACKED_VALUES,
2184
+ POOL_TRACKED_SESSIONS,
2185
+ POOL_BAKED_DIGESTS,
2186
+ observationIdentity,
2187
+ observationWindowDigest,
2188
+ mergeObservationWindow,
2189
+ mergeObservationWindowAsync,
2190
+ poolToValueObservations,
2191
+ observationPoolDirectory,
2192
+ loadObservationPool,
2193
+ loadObservationPoolAsync,
2194
+ saveObservationPool,
2195
+ saveObservationPoolAsync,
2196
+ formatEntropyMetric,
2197
+ formatEntropyCommandHints,
2198
+ entropyReviewKey,
2199
+ formatEntropyReviewNotice,
2200
+ formatEntropyCompileNotice,
2201
+ runEntropyTrial
2202
+ };
2203
+ //# sourceMappingURL=chunk-ZNAJDPT7.js.map