@logixjs/core 0.0.1

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 (345) hide show
  1. package/dist/Action-BkRHy2vg.d.cts +10 -0
  2. package/dist/Action-mqVvtEHt.d.ts +10 -0
  3. package/dist/Action.cjs +57 -0
  4. package/dist/Action.cjs.map +1 -0
  5. package/dist/Action.d.cts +2 -0
  6. package/dist/Action.d.ts +2 -0
  7. package/dist/Action.js +9 -0
  8. package/dist/Action.js.map +1 -0
  9. package/dist/Actions-AsQ07yTP.d.cts +22 -0
  10. package/dist/Actions-AsQ07yTP.d.ts +22 -0
  11. package/dist/Actions.cjs +19 -0
  12. package/dist/Actions.cjs.map +1 -0
  13. package/dist/Actions.d.cts +2 -0
  14. package/dist/Actions.d.ts +2 -0
  15. package/dist/Actions.js +2 -0
  16. package/dist/Actions.js.map +1 -0
  17. package/dist/Bound-BN1DQ_lM.d.ts +23 -0
  18. package/dist/Bound-BPIfH9SS.d.cts +23 -0
  19. package/dist/Bound.cjs +1532 -0
  20. package/dist/Bound.cjs.map +1 -0
  21. package/dist/Bound.d.cts +7 -0
  22. package/dist/Bound.d.ts +7 -0
  23. package/dist/Bound.js +25 -0
  24. package/dist/Bound.js.map +1 -0
  25. package/dist/Debug-B5q5Bkzx.d.ts +320 -0
  26. package/dist/Debug-Bq8Sqjcr.d.cts +320 -0
  27. package/dist/Debug.cjs +1821 -0
  28. package/dist/Debug.cjs.map +1 -0
  29. package/dist/Debug.d.cts +13 -0
  30. package/dist/Debug.d.ts +13 -0
  31. package/dist/Debug.js +76 -0
  32. package/dist/Debug.js.map +1 -0
  33. package/dist/EffectOp.cjs +169 -0
  34. package/dist/EffectOp.cjs.map +1 -0
  35. package/dist/EffectOp.d.cts +118 -0
  36. package/dist/EffectOp.d.ts +118 -0
  37. package/dist/EffectOp.js +28 -0
  38. package/dist/EffectOp.js.map +1 -0
  39. package/dist/Env-DuJ6JrU2.d.cts +10 -0
  40. package/dist/Env-DuJ6JrU2.d.ts +10 -0
  41. package/dist/Env.cjs +60 -0
  42. package/dist/Env.cjs.map +1 -0
  43. package/dist/Env.d.cts +1 -0
  44. package/dist/Env.d.ts +1 -0
  45. package/dist/Env.js +11 -0
  46. package/dist/Env.js.map +1 -0
  47. package/dist/Flow-1fZT8MpX.d.cts +152 -0
  48. package/dist/Flow-BhpjE22E.d.ts +152 -0
  49. package/dist/Flow.cjs +504 -0
  50. package/dist/Flow.cjs.map +1 -0
  51. package/dist/Flow.d.cts +8 -0
  52. package/dist/Flow.d.ts +8 -0
  53. package/dist/Flow.js +15 -0
  54. package/dist/Flow.js.map +1 -0
  55. package/dist/Handle-D8D1zPb_.d.cts +30 -0
  56. package/dist/Handle-D_cLW1Z3.d.ts +30 -0
  57. package/dist/Handle.cjs +42 -0
  58. package/dist/Handle.cjs.map +1 -0
  59. package/dist/Handle.d.cts +7 -0
  60. package/dist/Handle.d.ts +7 -0
  61. package/dist/Handle.js +10 -0
  62. package/dist/Handle.js.map +1 -0
  63. package/dist/Kernel-8kC-jOda.d.cts +171 -0
  64. package/dist/Kernel-CnGE1Fyk.d.ts +171 -0
  65. package/dist/Kernel.cjs +284 -0
  66. package/dist/Kernel.cjs.map +1 -0
  67. package/dist/Kernel.d.cts +14 -0
  68. package/dist/Kernel.d.ts +14 -0
  69. package/dist/Kernel.js +36 -0
  70. package/dist/Kernel.js.map +1 -0
  71. package/dist/Link-Db7975nU.d.ts +45 -0
  72. package/dist/Link-fX8x1eCK.d.cts +45 -0
  73. package/dist/Link.cjs +542 -0
  74. package/dist/Link.cjs.map +1 -0
  75. package/dist/Link.d.cts +7 -0
  76. package/dist/Link.d.ts +7 -0
  77. package/dist/Link.js +35 -0
  78. package/dist/Link.js.map +1 -0
  79. package/dist/Logic-BRjEMr-W.d.ts +38 -0
  80. package/dist/Logic-DRh4sDZj.d.cts +38 -0
  81. package/dist/Logic.cjs +37 -0
  82. package/dist/Logic.cjs.map +1 -0
  83. package/dist/Logic.d.cts +7 -0
  84. package/dist/Logic.d.ts +7 -0
  85. package/dist/Logic.js +10 -0
  86. package/dist/Logic.js.map +1 -0
  87. package/dist/MatchBuilder-0QOc-nlU.d.ts +14 -0
  88. package/dist/MatchBuilder-CJk5oCkR.d.cts +14 -0
  89. package/dist/MatchBuilder.cjs +85 -0
  90. package/dist/MatchBuilder.cjs.map +1 -0
  91. package/dist/MatchBuilder.d.cts +8 -0
  92. package/dist/MatchBuilder.d.ts +8 -0
  93. package/dist/MatchBuilder.js +11 -0
  94. package/dist/MatchBuilder.js.map +1 -0
  95. package/dist/Middleware.cjs +411 -0
  96. package/dist/Middleware.cjs.map +1 -0
  97. package/dist/Middleware.d.cts +88 -0
  98. package/dist/Middleware.d.ts +88 -0
  99. package/dist/Middleware.js +27 -0
  100. package/dist/Middleware.js.map +1 -0
  101. package/dist/Module-B_0xRDMR.d.cts +203 -0
  102. package/dist/Module-DnzluX2J.d.ts +203 -0
  103. package/dist/Module.cjs +13512 -0
  104. package/dist/Module.cjs.map +1 -0
  105. package/dist/Module.d.cts +8 -0
  106. package/dist/Module.d.ts +8 -0
  107. package/dist/Module.js +53 -0
  108. package/dist/Module.js.map +1 -0
  109. package/dist/ModuleTag-C8FHY_sY.d.ts +93 -0
  110. package/dist/ModuleTag-EGbgBMpZ.d.cts +93 -0
  111. package/dist/ModuleTag.cjs +12231 -0
  112. package/dist/ModuleTag.cjs.map +1 -0
  113. package/dist/ModuleTag.d.cts +8 -0
  114. package/dist/ModuleTag.d.ts +8 -0
  115. package/dist/ModuleTag.js +39 -0
  116. package/dist/ModuleTag.js.map +1 -0
  117. package/dist/Observability-COqEvp2C.d.cts +713 -0
  118. package/dist/Observability-cY4kLn0S.d.ts +713 -0
  119. package/dist/Observability.cjs +5865 -0
  120. package/dist/Observability.cjs.map +1 -0
  121. package/dist/Observability.d.cts +9 -0
  122. package/dist/Observability.d.ts +9 -0
  123. package/dist/Observability.js +41 -0
  124. package/dist/Observability.js.map +1 -0
  125. package/dist/Platform-C49Pv956.d.cts +21 -0
  126. package/dist/Platform-C49Pv956.d.ts +21 -0
  127. package/dist/Platform-CHX8o-U4.d.ts +51 -0
  128. package/dist/Platform-CVlv0xLQ.d.cts +51 -0
  129. package/dist/Platform.cjs +58 -0
  130. package/dist/Platform.cjs.map +1 -0
  131. package/dist/Platform.d.cts +4 -0
  132. package/dist/Platform.d.ts +4 -0
  133. package/dist/Platform.js +15 -0
  134. package/dist/Platform.js.map +1 -0
  135. package/dist/Process-CM9xbMdP.d.ts +92 -0
  136. package/dist/Process-mL8fHDSB.d.cts +92 -0
  137. package/dist/Process.cjs +575 -0
  138. package/dist/Process.cjs.map +1 -0
  139. package/dist/Process.d.cts +8 -0
  140. package/dist/Process.d.ts +8 -0
  141. package/dist/Process.js +42 -0
  142. package/dist/Process.js.map +1 -0
  143. package/dist/ReadQuery-BlMwhe-F.d.ts +30 -0
  144. package/dist/ReadQuery-CL5XlXts.d.cts +30 -0
  145. package/dist/ReadQuery-SinbStGF.d.cts +38 -0
  146. package/dist/ReadQuery-SinbStGF.d.ts +38 -0
  147. package/dist/ReadQuery.cjs +377 -0
  148. package/dist/ReadQuery.cjs.map +1 -0
  149. package/dist/ReadQuery.d.cts +2 -0
  150. package/dist/ReadQuery.d.ts +2 -0
  151. package/dist/ReadQuery.js +14 -0
  152. package/dist/ReadQuery.js.map +1 -0
  153. package/dist/Reflection-CQnKwPXj.d.ts +182 -0
  154. package/dist/Reflection-Kabo1mlU.d.cts +182 -0
  155. package/dist/Reflection.cjs +2954 -0
  156. package/dist/Reflection.cjs.map +1 -0
  157. package/dist/Reflection.d.cts +17 -0
  158. package/dist/Reflection.d.ts +17 -0
  159. package/dist/Reflection.js +40 -0
  160. package/dist/Reflection.js.map +1 -0
  161. package/dist/Resource-Dy1xD_DG.d.cts +75 -0
  162. package/dist/Resource-Dy1xD_DG.d.ts +75 -0
  163. package/dist/Resource.cjs +166 -0
  164. package/dist/Resource.cjs.map +1 -0
  165. package/dist/Resource.d.cts +3 -0
  166. package/dist/Resource.d.ts +3 -0
  167. package/dist/Resource.js +21 -0
  168. package/dist/Resource.js.map +1 -0
  169. package/dist/Root-7ADUMk4t.d.cts +29 -0
  170. package/dist/Root-7ADUMk4t.d.ts +29 -0
  171. package/dist/Root.cjs +125 -0
  172. package/dist/Root.cjs.map +1 -0
  173. package/dist/Root.d.cts +4 -0
  174. package/dist/Root.d.ts +4 -0
  175. package/dist/Root.js +12 -0
  176. package/dist/Root.js.map +1 -0
  177. package/dist/Runtime-B-aL-f29.d.cts +274 -0
  178. package/dist/Runtime-CtyzZG4i.d.ts +274 -0
  179. package/dist/Runtime.cjs +5740 -0
  180. package/dist/Runtime.cjs.map +1 -0
  181. package/dist/Runtime.d.cts +19 -0
  182. package/dist/Runtime.d.ts +19 -0
  183. package/dist/Runtime.js +62 -0
  184. package/dist/Runtime.js.map +1 -0
  185. package/dist/ScopeRegistry-D1owDNSm.d.cts +61 -0
  186. package/dist/ScopeRegistry-D1owDNSm.d.ts +61 -0
  187. package/dist/ScopeRegistry.cjs +152 -0
  188. package/dist/ScopeRegistry.cjs.map +1 -0
  189. package/dist/ScopeRegistry.d.cts +2 -0
  190. package/dist/ScopeRegistry.d.ts +2 -0
  191. package/dist/ScopeRegistry.js +16 -0
  192. package/dist/ScopeRegistry.js.map +1 -0
  193. package/dist/State-CU50R26M.d.cts +19 -0
  194. package/dist/State-CU50R26M.d.ts +19 -0
  195. package/dist/State.cjs +19 -0
  196. package/dist/State.cjs.map +1 -0
  197. package/dist/State.d.cts +2 -0
  198. package/dist/State.d.ts +2 -0
  199. package/dist/State.js +2 -0
  200. package/dist/State.js.map +1 -0
  201. package/dist/StateTrait-BGsZghTz.d.ts +122 -0
  202. package/dist/StateTrait-OWhbj12c.d.cts +122 -0
  203. package/dist/StateTrait.cjs +2737 -0
  204. package/dist/StateTrait.cjs.map +1 -0
  205. package/dist/StateTrait.d.cts +9 -0
  206. package/dist/StateTrait.d.ts +9 -0
  207. package/dist/StateTrait.js +39 -0
  208. package/dist/StateTrait.js.map +1 -0
  209. package/dist/TraitLifecycle-CwV5WPFX.d.cts +88 -0
  210. package/dist/TraitLifecycle-LdIWmKlg.d.ts +88 -0
  211. package/dist/TraitLifecycle.cjs +581 -0
  212. package/dist/TraitLifecycle.cjs.map +1 -0
  213. package/dist/TraitLifecycle.d.cts +8 -0
  214. package/dist/TraitLifecycle.d.ts +8 -0
  215. package/dist/TraitLifecycle.js +24 -0
  216. package/dist/TraitLifecycle.js.map +1 -0
  217. package/dist/action-DiMDD_0v.d.cts +35 -0
  218. package/dist/action-DiMDD_0v.d.ts +35 -0
  219. package/dist/chunk-24VULZ7A.js +76 -0
  220. package/dist/chunk-24VULZ7A.js.map +1 -0
  221. package/dist/chunk-3IYZ5IGG.js +17 -0
  222. package/dist/chunk-3IYZ5IGG.js.map +1 -0
  223. package/dist/chunk-3QMIVH35.js +43 -0
  224. package/dist/chunk-3QMIVH35.js.map +1 -0
  225. package/dist/chunk-3RMKLXHX.js +83 -0
  226. package/dist/chunk-3RMKLXHX.js.map +1 -0
  227. package/dist/chunk-3TMODYZV.js +111 -0
  228. package/dist/chunk-3TMODYZV.js.map +1 -0
  229. package/dist/chunk-3VG5TWQR.js +27 -0
  230. package/dist/chunk-3VG5TWQR.js.map +1 -0
  231. package/dist/chunk-4CQAV7YB.js +37 -0
  232. package/dist/chunk-4CQAV7YB.js.map +1 -0
  233. package/dist/chunk-4SO6JMZL.js +7 -0
  234. package/dist/chunk-4SO6JMZL.js.map +1 -0
  235. package/dist/chunk-66ALHVEX.js +40 -0
  236. package/dist/chunk-66ALHVEX.js.map +1 -0
  237. package/dist/chunk-76WT3HOR.js +397 -0
  238. package/dist/chunk-76WT3HOR.js.map +1 -0
  239. package/dist/chunk-ANLBCBDC.js +285 -0
  240. package/dist/chunk-ANLBCBDC.js.map +1 -0
  241. package/dist/chunk-AUIR5O6W.js +75 -0
  242. package/dist/chunk-AUIR5O6W.js.map +1 -0
  243. package/dist/chunk-BABLDP24.js +445 -0
  244. package/dist/chunk-BABLDP24.js.map +1 -0
  245. package/dist/chunk-BE3HW4FY.js +1099 -0
  246. package/dist/chunk-BE3HW4FY.js.map +1 -0
  247. package/dist/chunk-BZ2SHDN2.js +54 -0
  248. package/dist/chunk-BZ2SHDN2.js.map +1 -0
  249. package/dist/chunk-CW6T36TN.js +393 -0
  250. package/dist/chunk-CW6T36TN.js.map +1 -0
  251. package/dist/chunk-DFNM3WX2.js +632 -0
  252. package/dist/chunk-DFNM3WX2.js.map +1 -0
  253. package/dist/chunk-DMBALCE2.js +1034 -0
  254. package/dist/chunk-DMBALCE2.js.map +1 -0
  255. package/dist/chunk-EGK3KN7B.js +406 -0
  256. package/dist/chunk-EGK3KN7B.js.map +1 -0
  257. package/dist/chunk-EY4NZKDR.js +19 -0
  258. package/dist/chunk-EY4NZKDR.js.map +1 -0
  259. package/dist/chunk-G5ZBFPNU.js +23 -0
  260. package/dist/chunk-G5ZBFPNU.js.map +1 -0
  261. package/dist/chunk-GMPEOUP2.js +31 -0
  262. package/dist/chunk-GMPEOUP2.js.map +1 -0
  263. package/dist/chunk-IHVBV5C2.js +279 -0
  264. package/dist/chunk-IHVBV5C2.js.map +1 -0
  265. package/dist/chunk-IPF7E66P.js +23 -0
  266. package/dist/chunk-IPF7E66P.js.map +1 -0
  267. package/dist/chunk-JCXGZRMU.js +204 -0
  268. package/dist/chunk-JCXGZRMU.js.map +1 -0
  269. package/dist/chunk-JGIWG6SR.js +6359 -0
  270. package/dist/chunk-JGIWG6SR.js.map +1 -0
  271. package/dist/chunk-JWOYLO27.js +241 -0
  272. package/dist/chunk-JWOYLO27.js.map +1 -0
  273. package/dist/chunk-KIXAU3GM.js +137 -0
  274. package/dist/chunk-KIXAU3GM.js.map +1 -0
  275. package/dist/chunk-KL5ACTCT.js +8 -0
  276. package/dist/chunk-KL5ACTCT.js.map +1 -0
  277. package/dist/chunk-KP7MUZNX.js +83 -0
  278. package/dist/chunk-KP7MUZNX.js.map +1 -0
  279. package/dist/chunk-LEU6UA5J.js +1 -0
  280. package/dist/chunk-LEU6UA5J.js.map +1 -0
  281. package/dist/chunk-M2RGJPXX.js +35 -0
  282. package/dist/chunk-M2RGJPXX.js.map +1 -0
  283. package/dist/chunk-M3BFQ7HK.js +13 -0
  284. package/dist/chunk-M3BFQ7HK.js.map +1 -0
  285. package/dist/chunk-M3WTHJHJ.js +1051 -0
  286. package/dist/chunk-M3WTHJHJ.js.map +1 -0
  287. package/dist/chunk-M7IYCTJV.js +79 -0
  288. package/dist/chunk-M7IYCTJV.js.map +1 -0
  289. package/dist/chunk-NBD3KUOZ.js +838 -0
  290. package/dist/chunk-NBD3KUOZ.js.map +1 -0
  291. package/dist/chunk-NQZ2OSGR.js +151 -0
  292. package/dist/chunk-NQZ2OSGR.js.map +1 -0
  293. package/dist/chunk-NZJKFF45.js +106 -0
  294. package/dist/chunk-NZJKFF45.js.map +1 -0
  295. package/dist/chunk-OFADUJWJ.js +175 -0
  296. package/dist/chunk-OFADUJWJ.js.map +1 -0
  297. package/dist/chunk-OGWBVHB3.js +461 -0
  298. package/dist/chunk-OGWBVHB3.js.map +1 -0
  299. package/dist/chunk-PAYXCY6A.js +1696 -0
  300. package/dist/chunk-PAYXCY6A.js.map +1 -0
  301. package/dist/chunk-PYOE4VSI.js +1924 -0
  302. package/dist/chunk-PYOE4VSI.js.map +1 -0
  303. package/dist/chunk-PZ5AY32C.js +10 -0
  304. package/dist/chunk-PZ5AY32C.js.map +1 -0
  305. package/dist/chunk-QCHIQWAJ.js +21 -0
  306. package/dist/chunk-QCHIQWAJ.js.map +1 -0
  307. package/dist/chunk-QMM6O4CD.js +71 -0
  308. package/dist/chunk-QMM6O4CD.js.map +1 -0
  309. package/dist/chunk-RNFE3ML2.js +22 -0
  310. package/dist/chunk-RNFE3ML2.js.map +1 -0
  311. package/dist/chunk-TAAPQVZN.js +23 -0
  312. package/dist/chunk-TAAPQVZN.js.map +1 -0
  313. package/dist/chunk-THATMZXD.js +21 -0
  314. package/dist/chunk-THATMZXD.js.map +1 -0
  315. package/dist/chunk-TKZ7MEIA.js +27 -0
  316. package/dist/chunk-TKZ7MEIA.js.map +1 -0
  317. package/dist/chunk-TQOBJYDP.js +7 -0
  318. package/dist/chunk-TQOBJYDP.js.map +1 -0
  319. package/dist/chunk-VZB726PE.js +93 -0
  320. package/dist/chunk-VZB726PE.js.map +1 -0
  321. package/dist/chunk-W3TEWHLO.js +568 -0
  322. package/dist/chunk-W3TEWHLO.js.map +1 -0
  323. package/dist/chunk-YS3AZQ2G.js +52 -0
  324. package/dist/chunk-YS3AZQ2G.js.map +1 -0
  325. package/dist/chunk-ZDTRWK5F.js +40 -0
  326. package/dist/chunk-ZDTRWK5F.js.map +1 -0
  327. package/dist/chunk-ZFLHVFUC.js +192 -0
  328. package/dist/chunk-ZFLHVFUC.js.map +1 -0
  329. package/dist/chunk-ZFY7U2FR.js +133 -0
  330. package/dist/chunk-ZFY7U2FR.js.map +1 -0
  331. package/dist/chunk-ZGDVUPTM.js +270 -0
  332. package/dist/chunk-ZGDVUPTM.js.map +1 -0
  333. package/dist/index.cjs +19700 -0
  334. package/dist/index.cjs.map +1 -0
  335. package/dist/index.d.cts +195 -0
  336. package/dist/index.d.ts +195 -0
  337. package/dist/index.js +286 -0
  338. package/dist/index.js.map +1 -0
  339. package/dist/ir-BMP7yxJJ.d.cts +39 -0
  340. package/dist/ir-DUOz6H-5.d.ts +39 -0
  341. package/dist/module-B8CBqIZ_.d.cts +1191 -0
  342. package/dist/module-k7m3txak.d.ts +1191 -0
  343. package/dist/protocol-g_1897M2.d.cts +127 -0
  344. package/dist/protocol-g_1897M2.d.ts +127 -0
  345. package/package.json +162 -0
@@ -0,0 +1,2954 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/Reflection.ts
31
+ var Reflection_exports = {};
32
+ __export(Reflection_exports, {
33
+ diffManifest: () => diffManifest2,
34
+ exportStaticIr: () => exportStaticIr3,
35
+ extractManifest: () => extractManifest2,
36
+ verifyFullCutoverGate: () => verifyFullCutoverGate,
37
+ verifyKernelContract: () => verifyKernelContract2
38
+ });
39
+ module.exports = __toCommonJS(Reflection_exports);
40
+ var import_effect37 = require("effect");
41
+
42
+ // src/internal/reflection/manifest.ts
43
+ var import_effect3 = require("effect");
44
+
45
+ // src/internal/action.ts
46
+ var import_effect = require("effect");
47
+ var isActionToken = (value) => typeof value === "function" && value._kind === "ActionToken" && typeof value.tag === "string" && import_effect.Schema.isSchema(value.schema);
48
+
49
+ // src/internal/digest.ts
50
+ var stableStringify = (value) => {
51
+ if (value === null) return "null";
52
+ const t = typeof value;
53
+ if (t === "string") return JSON.stringify(value);
54
+ if (t === "number") return Number.isFinite(value) ? String(value) : "null";
55
+ if (t === "boolean") return value ? "true" : "false";
56
+ if (Array.isArray(value)) {
57
+ return `[${value.map(stableStringify).join(",")}]`;
58
+ }
59
+ if (t === "object") {
60
+ const record2 = value;
61
+ const keys = Object.keys(record2).sort((a, b) => a.localeCompare(b));
62
+ return `{${keys.map((k) => `${JSON.stringify(k)}:${stableStringify(record2[k])}`).join(",")}}`;
63
+ }
64
+ return "null";
65
+ };
66
+ var fnv1a32 = (input) => {
67
+ let hash = 2166136261;
68
+ for (let i = 0; i < input.length; i++) {
69
+ hash ^= input.charCodeAt(i);
70
+ hash = hash * 16777619 >>> 0;
71
+ }
72
+ return hash.toString(16).padStart(8, "0");
73
+ };
74
+
75
+ // src/internal/observability/jsonValue.ts
76
+ var isJsonValue = (input) => {
77
+ const seen = /* @__PURE__ */ new WeakSet();
78
+ const loop = (value, depth) => {
79
+ if (depth > 64) return false;
80
+ if (value === null) return true;
81
+ switch (typeof value) {
82
+ case "string":
83
+ case "boolean":
84
+ return true;
85
+ case "number":
86
+ return Number.isFinite(value);
87
+ case "object": {
88
+ if (Array.isArray(value)) {
89
+ if (seen.has(value)) return false;
90
+ seen.add(value);
91
+ for (const item of value) {
92
+ if (!loop(item, depth + 1)) return false;
93
+ }
94
+ return true;
95
+ }
96
+ if (!isPlainRecord(value)) return false;
97
+ if (seen.has(value)) return false;
98
+ seen.add(value);
99
+ for (const v of Object.values(value)) {
100
+ if (!loop(v, depth + 1)) return false;
101
+ }
102
+ return true;
103
+ }
104
+ default:
105
+ return false;
106
+ }
107
+ };
108
+ return loop(input, 0);
109
+ };
110
+ var defaultOptions = {
111
+ maxDepth: 6,
112
+ maxObjectKeys: 32,
113
+ maxArrayLength: 32,
114
+ maxStringLength: 256,
115
+ maxJsonBytes: 4 * 1024,
116
+ oversizedPreviewBytes: 256
117
+ };
118
+ var truncateString = (value, maxLen, stats) => {
119
+ if (value.length <= maxLen) return value;
120
+ stats.oversized += 1;
121
+ return value.slice(0, maxLen);
122
+ };
123
+ var mergeDowngrade = (current, next) => {
124
+ if (!current) return next;
125
+ if (current === "non_serializable" || next === "non_serializable") return "non_serializable";
126
+ if (current === "oversized" || next === "oversized") return "oversized";
127
+ return "unknown";
128
+ };
129
+ function isPlainRecord(value) {
130
+ if (typeof value !== "object" || value === null) return false;
131
+ const proto = Object.getPrototypeOf(value);
132
+ return proto === Object.prototype || proto === null;
133
+ }
134
+ var asNumber = (value, stats) => {
135
+ if (Number.isFinite(value)) return value;
136
+ stats.nonSerializable += 1;
137
+ return String(value);
138
+ };
139
+ var toJsonValueInternal = (input, options, stats, seen, depth) => {
140
+ if (input === null) return null;
141
+ switch (typeof input) {
142
+ case "string":
143
+ return truncateString(input, options.maxStringLength, stats);
144
+ case "number":
145
+ return asNumber(input, stats);
146
+ case "boolean":
147
+ return input;
148
+ case "bigint":
149
+ stats.nonSerializable += 1;
150
+ return truncateString(input.toString(), options.maxStringLength, stats);
151
+ case "symbol":
152
+ stats.nonSerializable += 1;
153
+ return truncateString(input.toString(), options.maxStringLength, stats);
154
+ case "function":
155
+ stats.nonSerializable += 1;
156
+ return "[Function]";
157
+ case "undefined":
158
+ stats.dropped += 1;
159
+ return null;
160
+ }
161
+ if (depth >= options.maxDepth) {
162
+ stats.oversized += 1;
163
+ return "[Truncated]";
164
+ }
165
+ if (input instanceof Date) {
166
+ return input.toISOString();
167
+ }
168
+ if (input instanceof Error) {
169
+ stats.nonSerializable += 1;
170
+ return {
171
+ name: truncateString(input.name, options.maxStringLength, stats),
172
+ message: truncateString(input.message, options.maxStringLength, stats)
173
+ };
174
+ }
175
+ if (typeof input === "object") {
176
+ if (seen.has(input)) {
177
+ stats.nonSerializable += 1;
178
+ return "[Circular]";
179
+ }
180
+ seen.add(input);
181
+ }
182
+ if (Array.isArray(input)) {
183
+ const out2 = [];
184
+ const limit2 = Math.min(input.length, options.maxArrayLength);
185
+ for (let i = 0; i < limit2; i++) {
186
+ out2.push(toJsonValueInternal(input[i], options, stats, seen, depth + 1));
187
+ }
188
+ if (input.length > limit2) {
189
+ stats.oversized += 1;
190
+ out2.push(`[...${input.length - limit2} more]`);
191
+ }
192
+ return out2;
193
+ }
194
+ if (!isPlainRecord(input)) {
195
+ stats.nonSerializable += 1;
196
+ return truncateString(String(input), options.maxStringLength, stats);
197
+ }
198
+ const entries = Object.entries(input);
199
+ const limit = Math.min(entries.length, options.maxObjectKeys);
200
+ const out = {};
201
+ for (let i = 0; i < limit; i++) {
202
+ const [rawKey, rawValue] = entries[i];
203
+ const key = truncateString(rawKey, options.maxStringLength, stats);
204
+ if (rawValue === void 0) {
205
+ stats.dropped += 1;
206
+ continue;
207
+ }
208
+ out[key] = toJsonValueInternal(rawValue, options, stats, seen, depth + 1);
209
+ }
210
+ if (entries.length > limit) {
211
+ stats.oversized += 1;
212
+ out.__truncatedKeys = entries.length - limit;
213
+ }
214
+ return out;
215
+ };
216
+ var projectJsonValue = (input, options) => {
217
+ const resolved = { ...defaultOptions, ...options ?? {} };
218
+ const stats = { dropped: 0, oversized: 0, nonSerializable: 0 };
219
+ const seen = /* @__PURE__ */ new WeakSet();
220
+ let downgrade;
221
+ const value = toJsonValueInternal(input, resolved, stats, seen, 0);
222
+ if (stats.nonSerializable > 0) {
223
+ downgrade = mergeDowngrade(downgrade, "non_serializable");
224
+ }
225
+ if (stats.oversized > 0) {
226
+ downgrade = mergeDowngrade(downgrade, "oversized");
227
+ }
228
+ try {
229
+ const json = JSON.stringify(value);
230
+ if (json.length > resolved.maxJsonBytes) {
231
+ downgrade = mergeDowngrade(downgrade, "oversized");
232
+ const preview = json.slice(0, Math.min(resolved.oversizedPreviewBytes, resolved.maxJsonBytes));
233
+ return {
234
+ value: {
235
+ _tag: "oversized",
236
+ bytes: json.length,
237
+ preview
238
+ },
239
+ stats: {
240
+ dropped: stats.dropped,
241
+ oversized: stats.oversized + 1,
242
+ nonSerializable: stats.nonSerializable
243
+ },
244
+ downgrade
245
+ };
246
+ }
247
+ } catch {
248
+ downgrade = mergeDowngrade(downgrade, "non_serializable");
249
+ return {
250
+ value: "[Unserializable]",
251
+ stats: {
252
+ dropped: stats.dropped,
253
+ oversized: stats.oversized,
254
+ nonSerializable: stats.nonSerializable + 1
255
+ },
256
+ downgrade
257
+ };
258
+ }
259
+ return {
260
+ value,
261
+ stats: {
262
+ dropped: stats.dropped,
263
+ oversized: stats.oversized,
264
+ nonSerializable: stats.nonSerializable
265
+ },
266
+ downgrade
267
+ };
268
+ };
269
+
270
+ // src/internal/runtime/core/env.ts
271
+ var import_effect2 = require("effect");
272
+ var getNodeEnv = () => {
273
+ try {
274
+ const env = globalThis?.process?.env;
275
+ return typeof env?.NODE_ENV === "string" ? env.NODE_ENV : void 0;
276
+ } catch {
277
+ return void 0;
278
+ }
279
+ };
280
+ var isDevEnv = () => getNodeEnv() !== "production";
281
+ var StateTransactionConfigTagImpl = class extends import_effect2.Context.Tag("@logixjs/core/StateTransactionRuntimeConfig")() {
282
+ };
283
+ var ReadQueryStrictGateConfigTagImpl = class extends import_effect2.Context.Tag("@logixjs/core/ReadQueryStrictGateRuntimeConfig")() {
284
+ };
285
+ var ReplayModeConfigTagImpl = class extends import_effect2.Context.Tag("@logixjs/core/ReplayModeConfig")() {
286
+ };
287
+ var StateTransactionOverridesTagImpl = class extends import_effect2.Context.Tag("@logixjs/core/StateTransactionOverrides")() {
288
+ };
289
+ var ConcurrencyPolicyTagImpl = class extends import_effect2.Context.Tag("@logixjs/core/ConcurrencyPolicy")() {
290
+ };
291
+ var ConcurrencyPolicyOverridesTagImpl = class extends import_effect2.Context.Tag("@logixjs/core/ConcurrencyPolicyOverrides")() {
292
+ };
293
+
294
+ // src/internal/runtime/core/runtimeInternalsAccessor.ts
295
+ var MODULE_TRAITS_PROGRAM = /* @__PURE__ */ Symbol.for("@logixjs/core/moduleTraitsProgram");
296
+ var getModuleTraitsProgram = (module2) => {
297
+ if (!module2) return void 0;
298
+ if (typeof module2 !== "object" && typeof module2 !== "function") return void 0;
299
+ return module2[MODULE_TRAITS_PROGRAM];
300
+ };
301
+
302
+ // src/internal/field-path.ts
303
+ var isFieldPathSegment = (seg) => {
304
+ if (!seg) return false;
305
+ if (seg === "*") return false;
306
+ if (/^\d+$/.test(seg)) return false;
307
+ if (seg.includes("[") || seg.includes("]")) return false;
308
+ return true;
309
+ };
310
+ var normalizeFieldPath = (input) => {
311
+ if (typeof input === "string") {
312
+ const segs = splitSegments(input);
313
+ if (!segs || segs.length === 0) return void 0;
314
+ const normalized2 = segs.filter(isFieldPathSegment);
315
+ return normalized2.length > 0 ? normalized2 : void 0;
316
+ }
317
+ if (input.length === 0) return void 0;
318
+ let needsFilter = false;
319
+ for (const seg of input) {
320
+ if (!isFieldPathSegment(seg)) {
321
+ needsFilter = true;
322
+ break;
323
+ }
324
+ }
325
+ if (!needsFilter) return input;
326
+ const normalized = input.filter(isFieldPathSegment);
327
+ return normalized.length > 0 ? normalized : void 0;
328
+ };
329
+ var splitSegments = (path) => {
330
+ if (!path) return void 0;
331
+ if (path === "*") return void 0;
332
+ const parts = path.split(".").filter((p) => p.length > 0);
333
+ const segs = [];
334
+ for (const part of parts) {
335
+ if (!part) continue;
336
+ if (part === "*") {
337
+ return void 0;
338
+ }
339
+ if (part.endsWith("[]")) {
340
+ const base = part.slice(0, -2);
341
+ if (base) segs.push(base);
342
+ continue;
343
+ }
344
+ const bracket = /^(.+)\[(\d+)\]$/.exec(part);
345
+ if (bracket) {
346
+ segs.push(bracket[1]);
347
+ continue;
348
+ }
349
+ if (/^\d+$/.test(part)) {
350
+ continue;
351
+ }
352
+ if (part.includes("[") || part.includes("]")) {
353
+ return void 0;
354
+ }
355
+ segs.push(part);
356
+ }
357
+ return segs;
358
+ };
359
+
360
+ // src/internal/state-trait/ir.ts
361
+ var normalizeFieldPaths = (paths) => {
362
+ if (!paths || paths.length === 0) return [];
363
+ const out = [];
364
+ for (const path of paths) {
365
+ const normalized = normalizeFieldPath(path);
366
+ if (normalized) out.push(normalized);
367
+ }
368
+ return out;
369
+ };
370
+ var normalizeFieldPath2 = (path) => path ? normalizeFieldPath(path) : void 0;
371
+ var toNodeKind = (step) => {
372
+ switch (step.kind) {
373
+ case "computed-update":
374
+ return "computed";
375
+ case "link-propagate":
376
+ return "link";
377
+ case "source-refresh":
378
+ return "source";
379
+ case "check-validate":
380
+ return "check";
381
+ }
382
+ };
383
+ var findEntryForStep = (program, step) => {
384
+ const fieldPath = step.targetFieldPath;
385
+ if (!fieldPath) return void 0;
386
+ const kind = toNodeKind(step);
387
+ return program.entries.find(
388
+ (e) => e.fieldPath === fieldPath && (e.kind === kind || kind === "check" && e.kind === "check" || kind === "source" && e.kind === "source" || kind === "link" && e.kind === "link" || kind === "computed" && e.kind === "computed")
389
+ );
390
+ };
391
+ var getReadsForEntry = (entry) => {
392
+ if (!entry) return void 0;
393
+ if (entry.kind === "computed") {
394
+ return entry.meta.deps;
395
+ }
396
+ if (entry.kind === "source") {
397
+ return entry.meta.deps;
398
+ }
399
+ if (entry.kind === "link") {
400
+ const from = entry.meta.from;
401
+ return from ? [from] : [];
402
+ }
403
+ if (entry.kind === "check") {
404
+ const rules = entry.meta?.rules ?? {};
405
+ const out = [];
406
+ for (const name of Object.keys(rules)) {
407
+ const rule = rules[name];
408
+ const deps = rule?.deps;
409
+ if (deps) out.push(...deps);
410
+ }
411
+ return out;
412
+ }
413
+ return void 0;
414
+ };
415
+ var exportStaticIr = (params) => {
416
+ const moduleId = params.moduleId;
417
+ const version = params.version ?? "009";
418
+ const metaByField = /* @__PURE__ */ new Map();
419
+ for (const node of params.program.graph.nodes) {
420
+ const meta = node.meta;
421
+ if (!meta || typeof meta !== "object") continue;
422
+ const label = typeof meta.label === "string" ? meta.label : void 0;
423
+ const description = typeof meta.description === "string" ? meta.description : void 0;
424
+ const tags = Array.isArray(meta.tags) && meta.tags.every((t) => typeof t === "string") ? meta.tags : void 0;
425
+ const group = typeof meta.group === "string" ? meta.group : void 0;
426
+ const docsUrl = typeof meta.docsUrl === "string" ? meta.docsUrl : void 0;
427
+ const cacheGroup = typeof meta.cacheGroup === "string" ? meta.cacheGroup : void 0;
428
+ const annotationsRaw = meta.annotations;
429
+ const annotations = annotationsRaw && typeof annotationsRaw === "object" && !Array.isArray(annotationsRaw) ? annotationsRaw : void 0;
430
+ if (label || description || tags || group || docsUrl || cacheGroup || annotations) {
431
+ metaByField.set(node.id, {
432
+ label,
433
+ description,
434
+ tags,
435
+ group,
436
+ docsUrl,
437
+ cacheGroup,
438
+ annotations
439
+ });
440
+ }
441
+ }
442
+ const nodes = params.program.plan.steps.map((step) => {
443
+ const kind = toNodeKind(step);
444
+ const entry = findEntryForStep(params.program, step);
445
+ const reads = normalizeFieldPaths(getReadsForEntry(entry));
446
+ const target = step.targetFieldPath;
447
+ const write = normalizeFieldPath2(target);
448
+ const writes = write ? [write] : [];
449
+ const meta = target ? metaByField.get(target) : void 0;
450
+ const base2 = {
451
+ nodeId: step.id,
452
+ kind,
453
+ reads,
454
+ writes: kind === "check" ? [] : writes,
455
+ meta
456
+ };
457
+ if (kind !== "check" && target && !write) {
458
+ return { ...base2, writesUnknown: true };
459
+ }
460
+ return base2;
461
+ });
462
+ const edges = params.program.graph.edges.map((edge) => ({
463
+ edgeId: edge.id,
464
+ from: edge.from,
465
+ to: edge.to,
466
+ kind: edge.kind
467
+ }));
468
+ const base = {
469
+ version,
470
+ moduleId,
471
+ nodes,
472
+ edges
473
+ };
474
+ const digest = `stir:${version}:${fnv1a32(stableStringify(base))}`;
475
+ return {
476
+ ...base,
477
+ digest
478
+ };
479
+ };
480
+
481
+ // src/internal/reflection/staticIr.ts
482
+ var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
483
+ var isModuleImpl = (value) => isRecord(value) && value._tag === "ModuleImpl" && isRecord(value.module);
484
+ var resolveModuleId = (input) => {
485
+ if (isModuleImpl(input)) {
486
+ const id = input.module.id;
487
+ return typeof id === "string" && id.length > 0 ? id : "unknown";
488
+ }
489
+ if (isRecord(input)) {
490
+ const id = input.id;
491
+ if (typeof id === "string" && id.length > 0) return id;
492
+ const tag = input.tag;
493
+ if (tag && (typeof tag === "object" || typeof tag === "function")) {
494
+ const tagId = tag.id;
495
+ if (typeof tagId === "string" && tagId.length > 0) return tagId;
496
+ }
497
+ }
498
+ return "unknown";
499
+ };
500
+ var resolveModuleTag = (input) => {
501
+ if (isModuleImpl(input)) return input.module;
502
+ if (isRecord(input) && input.tag) return input.tag;
503
+ return void 0;
504
+ };
505
+ var exportStaticIr2 = (module2) => {
506
+ const tag = resolveModuleTag(module2);
507
+ if (!tag) return void 0;
508
+ const program = getModuleTraitsProgram(tag);
509
+ if (!program) return void 0;
510
+ return exportStaticIr({
511
+ program,
512
+ moduleId: resolveModuleId(module2)
513
+ });
514
+ };
515
+
516
+ // src/internal/reflection/manifest.ts
517
+ var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
518
+ var isModuleImpl2 = (value) => isRecord2(value) && value._tag === "ModuleImpl" && isRecord2(value.module);
519
+ var resolveModuleId2 = (input) => {
520
+ if (isModuleImpl2(input)) {
521
+ const id = input.module.id;
522
+ return typeof id === "string" && id.length > 0 ? id : "unknown";
523
+ }
524
+ if (isRecord2(input)) {
525
+ const id = input.id;
526
+ if (typeof id === "string" && id.length > 0) return id;
527
+ const tag = input.tag;
528
+ if (tag && (typeof tag === "object" || typeof tag === "function")) {
529
+ const tagId = tag.id;
530
+ if (typeof tagId === "string" && tagId.length > 0) return tagId;
531
+ }
532
+ }
533
+ return "unknown";
534
+ };
535
+ var resolveActionKeys = (input) => {
536
+ const tag = isModuleImpl2(input) ? input.module : input?.tag;
537
+ const actionMap = tag?.shape?.actionMap;
538
+ if (!isRecord2(actionMap)) return [];
539
+ return Object.keys(actionMap).sort();
540
+ };
541
+ var resolveDevSource = (input) => {
542
+ if (!isRecord2(input)) return void 0;
543
+ const file = input.file;
544
+ const line = input.line;
545
+ const column = input.column;
546
+ if (typeof file !== "string" || file.length === 0) return void 0;
547
+ if (typeof line !== "number" || !Number.isInteger(line) || line < 1) return void 0;
548
+ if (typeof column !== "number" || !Number.isInteger(column) || column < 1) return void 0;
549
+ return { file, line, column };
550
+ };
551
+ var resolveTokenSource = (token) => {
552
+ if (!token || typeof token !== "object" && typeof token !== "function") return void 0;
553
+ return resolveDevSource(token.source);
554
+ };
555
+ var resolveActions = (input) => {
556
+ const tag = isModuleImpl2(input) ? input.module : input?.tag;
557
+ const actionMap = tag?.shape?.actionMap;
558
+ if (!isRecord2(actionMap)) return [];
559
+ const moduleSource = resolveSource(input);
560
+ const reducers = isRecord2(tag?.reducers) ? tag.reducers : void 0;
561
+ const actionTags = Object.keys(actionMap).sort();
562
+ const out = [];
563
+ for (const actionTag of actionTags) {
564
+ const token = actionMap[actionTag];
565
+ const source = resolveTokenSource(token) ?? moduleSource;
566
+ const payloadKind = isActionToken(token) && import_effect3.Schema.isSchema(token.schema) ? token.schema === import_effect3.Schema.Void ? "void" : "nonVoid" : "unknown";
567
+ const primaryReducer = reducers && typeof reducers[actionTag] === "function" ? { kind: "declared" } : void 0;
568
+ out.push({
569
+ actionTag,
570
+ payload: { kind: payloadKind },
571
+ ...primaryReducer ? { primaryReducer } : {},
572
+ ...source ? { source } : {}
573
+ });
574
+ }
575
+ return out;
576
+ };
577
+ var MODULE_DECLARED_EFFECTS = /* @__PURE__ */ Symbol.for("logix.module.effects.declared");
578
+ var resolveEffects = (input) => {
579
+ const tag = isModuleImpl2(input) ? input.module : input?.tag;
580
+ const actionMap = tag?.shape?.actionMap;
581
+ if (!isRecord2(actionMap)) return void 0;
582
+ const effectsRaw = tag?.[MODULE_DECLARED_EFFECTS];
583
+ if (!isRecord2(effectsRaw)) return void 0;
584
+ const source = resolveSource(input);
585
+ const logicUnitId = "__logix_internal:effects:declared";
586
+ const handlerIds = /* @__PURE__ */ new WeakMap();
587
+ let nextHandlerSeq = 0;
588
+ const out = [];
589
+ for (const actionTag of Object.keys(effectsRaw).sort()) {
590
+ if (!(actionTag in actionMap)) continue;
591
+ const handlers = effectsRaw[actionTag];
592
+ if (!Array.isArray(handlers)) continue;
593
+ for (const handler of handlers) {
594
+ if (typeof handler !== "function") continue;
595
+ let handlerId = handlerIds.get(handler);
596
+ if (!handlerId) {
597
+ nextHandlerSeq += 1;
598
+ handlerId = `h${nextHandlerSeq}`;
599
+ handlerIds.set(handler, handlerId);
600
+ }
601
+ const sourceKey = `${logicUnitId}::${handlerId}`;
602
+ out.push({
603
+ actionTag,
604
+ sourceKey,
605
+ kind: "declared",
606
+ ...source ? { source } : {}
607
+ });
608
+ }
609
+ }
610
+ const seen = /* @__PURE__ */ new Set();
611
+ const deduped = [];
612
+ for (const item of out) {
613
+ const key = `${item.actionTag}\0${item.sourceKey}`;
614
+ if (seen.has(key)) continue;
615
+ seen.add(key);
616
+ deduped.push(item);
617
+ }
618
+ deduped.sort(
619
+ (a, b) => a.actionTag < b.actionTag ? -1 : a.actionTag > b.actionTag ? 1 : a.sourceKey.localeCompare(b.sourceKey)
620
+ );
621
+ return deduped.length > 0 ? deduped : void 0;
622
+ };
623
+ var resolveSchemaKeys = (input) => {
624
+ if (!isRecord2(input)) return void 0;
625
+ const schemas = input.schemas;
626
+ if (!isRecord2(schemas)) return void 0;
627
+ return Object.keys(schemas).sort();
628
+ };
629
+ var resolveSource = (input) => {
630
+ if (!isRecord2(input)) return void 0;
631
+ const dev = input.dev;
632
+ return resolveDevSource(dev?.source);
633
+ };
634
+ var resolveMeta = (input) => {
635
+ if (!isRecord2(input)) return void 0;
636
+ const meta = input.meta;
637
+ if (!isRecord2(meta)) return void 0;
638
+ const out = {};
639
+ for (const key of Object.keys(meta).sort()) {
640
+ const value = meta[key];
641
+ if (isJsonValue(value)) {
642
+ out[key] = value;
643
+ }
644
+ }
645
+ return Object.keys(out).length > 0 ? out : void 0;
646
+ };
647
+ var MODULE_INTERNAL = /* @__PURE__ */ Symbol.for("logix.module.internal");
648
+ var resolveLogicUnits = (input) => {
649
+ if (!isRecord2(input)) return void 0;
650
+ const internal = input[MODULE_INTERNAL];
651
+ const mounted = internal?.mounted;
652
+ if (!Array.isArray(mounted)) return void 0;
653
+ const out = [];
654
+ for (const unit of mounted) {
655
+ if (!isRecord2(unit)) continue;
656
+ const kind = unit.kind;
657
+ const id = unit.id;
658
+ if (typeof kind !== "string" || kind.length === 0) continue;
659
+ if (typeof id !== "string" || id.length === 0) continue;
660
+ const derived = unit.derived === true ? true : void 0;
661
+ const name = typeof unit.name === "string" ? unit.name : void 0;
662
+ out.push({ kind, id, derived, name });
663
+ }
664
+ out.sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : a.kind.localeCompare(b.kind));
665
+ return out.length > 0 ? out : void 0;
666
+ };
667
+ var digestOf = (base) => `manifest:067:${fnv1a32(stableStringify(base))}`;
668
+ var utf8ByteLength = (value) => {
669
+ const json = JSON.stringify(value);
670
+ if (typeof TextEncoder !== "undefined") {
671
+ return new TextEncoder().encode(json).length;
672
+ }
673
+ return json.length;
674
+ };
675
+ var applyMaxBytes = (manifest, maxBytes) => {
676
+ const originalBytes = utf8ByteLength(manifest);
677
+ if (originalBytes <= maxBytes) return manifest;
678
+ const dropped = [];
679
+ const truncatedArrays = [];
680
+ const baseMarker = () => ({
681
+ truncated: true,
682
+ maxBytes,
683
+ originalBytes,
684
+ dropped,
685
+ truncatedArrays
686
+ });
687
+ const withMarker = (next2) => {
688
+ const meta = {
689
+ __logix: baseMarker()
690
+ };
691
+ return { ...next2, meta };
692
+ };
693
+ let next = withMarker(manifest);
694
+ const markTruncatedArray = (name) => {
695
+ if (!truncatedArrays.includes(name)) {
696
+ truncatedArrays.push(name);
697
+ }
698
+ };
699
+ const dropField = (field) => {
700
+ if (next[field] !== void 0) {
701
+ dropped.push(String(field));
702
+ next = withMarker({ ...next, [field]: void 0 });
703
+ }
704
+ };
705
+ dropField("meta");
706
+ if (utf8ByteLength(next) <= maxBytes) return next;
707
+ dropField("source");
708
+ if (utf8ByteLength(next) <= maxBytes) return next;
709
+ dropField("staticIr");
710
+ if (utf8ByteLength(next) <= maxBytes) return next;
711
+ dropField("logicUnits");
712
+ if (utf8ByteLength(next) <= maxBytes) return next;
713
+ dropField("schemaKeys");
714
+ if (utf8ByteLength(next) <= maxBytes) return next;
715
+ dropField("effects");
716
+ if (utf8ByteLength(next) <= maxBytes) return next;
717
+ const truncateActionsToFit = () => {
718
+ const total = next.actions.length;
719
+ if (total <= 1) return;
720
+ let lo = 1;
721
+ let hi = total;
722
+ let best = 1;
723
+ while (lo <= hi) {
724
+ const mid = Math.floor((lo + hi) / 2);
725
+ const candidate = withMarker({
726
+ ...next,
727
+ actions: next.actions.slice(0, mid),
728
+ actionKeys: next.actionKeys.slice(0, mid)
729
+ });
730
+ if (utf8ByteLength(candidate) <= maxBytes) {
731
+ best = mid;
732
+ lo = mid + 1;
733
+ } else {
734
+ hi = mid - 1;
735
+ }
736
+ }
737
+ if (best < total) {
738
+ markTruncatedArray("actions");
739
+ markTruncatedArray("actionKeys");
740
+ next = withMarker({
741
+ ...next,
742
+ actions: next.actions.slice(0, best),
743
+ actionKeys: next.actionKeys.slice(0, best)
744
+ });
745
+ }
746
+ };
747
+ while (utf8ByteLength(next) > maxBytes) {
748
+ const beforeLen = next.actions.length;
749
+ truncateActionsToFit();
750
+ if (next.actions.length === beforeLen) {
751
+ break;
752
+ }
753
+ }
754
+ return next;
755
+ };
756
+ var extractManifest = (module2, options) => {
757
+ const manifestVersion = "067";
758
+ const moduleId = resolveModuleId2(module2);
759
+ const actionKeys = resolveActionKeys(module2);
760
+ const actions = resolveActions(module2);
761
+ const effects = resolveEffects(module2);
762
+ const schemaKeys = resolveSchemaKeys(module2);
763
+ const logicUnits = resolveLogicUnits(module2);
764
+ const source = resolveSource(module2);
765
+ const meta = resolveMeta(module2);
766
+ const staticIr = options?.includeStaticIr ? exportStaticIr2(module2) : void 0;
767
+ const digestBase = {
768
+ manifestVersion,
769
+ moduleId,
770
+ actionKeys,
771
+ actions,
772
+ effects,
773
+ schemaKeys,
774
+ logicUnits,
775
+ staticIrDigest: staticIr?.digest
776
+ };
777
+ const digest = digestOf(digestBase);
778
+ const manifest = {
779
+ manifestVersion,
780
+ moduleId,
781
+ actionKeys,
782
+ actions,
783
+ effects,
784
+ schemaKeys,
785
+ logicUnits,
786
+ source,
787
+ meta,
788
+ staticIr,
789
+ digest
790
+ };
791
+ const maxBytes = options?.budgets?.maxBytes;
792
+ if (typeof maxBytes === "number" && Number.isFinite(maxBytes) && maxBytes > 0) {
793
+ return applyMaxBytes(manifest, maxBytes);
794
+ }
795
+ return manifest;
796
+ };
797
+
798
+ // src/internal/reflection/diff.ts
799
+ var SEVERITY_RANK = {
800
+ BREAKING: 0,
801
+ RISKY: 1,
802
+ INFO: 2
803
+ };
804
+ var uniqSorted = (input) => {
805
+ const out = Array.from(new Set(input.filter((x) => typeof x === "string" && x.length > 0)));
806
+ out.sort((a, b) => a.localeCompare(b));
807
+ return out;
808
+ };
809
+ var diffStringKeys = (before, after) => {
810
+ const beforeSet = new Set(uniqSorted(before ?? []));
811
+ const afterSet = new Set(uniqSorted(after ?? []));
812
+ const removed = [];
813
+ for (const k of beforeSet) {
814
+ if (!afterSet.has(k)) removed.push(k);
815
+ }
816
+ removed.sort((a, b) => a.localeCompare(b));
817
+ const added = [];
818
+ for (const k of afterSet) {
819
+ if (!beforeSet.has(k)) added.push(k);
820
+ }
821
+ added.sort((a, b) => a.localeCompare(b));
822
+ return { removed, added };
823
+ };
824
+ var eqJsonValue = (a, b) => stableStringify(a) === stableStringify(b);
825
+ var indexLogicUnits = (input) => {
826
+ const map = /* @__PURE__ */ new Map();
827
+ for (const unit of input ?? []) {
828
+ if (!unit || typeof unit !== "object") continue;
829
+ const id = unit.id;
830
+ if (typeof id !== "string" || id.length === 0) continue;
831
+ map.set(id, unit);
832
+ }
833
+ return map;
834
+ };
835
+ var diffManifest = (before, after, options) => {
836
+ const changes = [];
837
+ if (before.moduleId !== after.moduleId) {
838
+ changes.push({
839
+ severity: "BREAKING",
840
+ code: "moduleId.changed",
841
+ message: `moduleId changed (${before.moduleId} -> ${after.moduleId})`,
842
+ pointer: "/moduleId",
843
+ details: {
844
+ before: before.moduleId,
845
+ after: after.moduleId
846
+ }
847
+ });
848
+ }
849
+ if (before.manifestVersion !== after.manifestVersion) {
850
+ changes.push({
851
+ severity: "INFO",
852
+ code: "manifestVersion.changed",
853
+ message: `manifestVersion changed (${before.manifestVersion} -> ${after.manifestVersion})`,
854
+ pointer: "/manifestVersion",
855
+ details: {
856
+ before: before.manifestVersion,
857
+ after: after.manifestVersion
858
+ }
859
+ });
860
+ }
861
+ {
862
+ const { removed, added } = diffStringKeys(before.actionKeys, after.actionKeys);
863
+ if (removed.length > 0 || added.length > 0) {
864
+ changes.push({
865
+ severity: removed.length > 0 ? "BREAKING" : "INFO",
866
+ code: "actionKeys.changed",
867
+ message: removed.length > 0 ? `actionKeys removed: ${removed.join(", ")}` : `actionKeys added: ${added.join(", ")}`,
868
+ pointer: "/actionKeys",
869
+ details: { removed, added }
870
+ });
871
+ }
872
+ }
873
+ {
874
+ const { removed, added } = diffStringKeys(before.schemaKeys, after.schemaKeys);
875
+ if (removed.length > 0 || added.length > 0) {
876
+ changes.push({
877
+ severity: removed.length > 0 ? "BREAKING" : "INFO",
878
+ code: "schemaKeys.changed",
879
+ message: removed.length > 0 ? `schemaKeys removed: ${removed.join(", ")}` : `schemaKeys added: ${added.join(", ")}`,
880
+ pointer: "/schemaKeys",
881
+ details: { removed, added }
882
+ });
883
+ }
884
+ }
885
+ {
886
+ const beforeById = indexLogicUnits(before.logicUnits);
887
+ const afterById = indexLogicUnits(after.logicUnits);
888
+ const removed = [];
889
+ const added = [];
890
+ const kindChanged = [];
891
+ const riskyChanged = [];
892
+ for (const id of beforeById.keys()) {
893
+ if (!afterById.has(id)) removed.push(id);
894
+ }
895
+ for (const id of afterById.keys()) {
896
+ if (!beforeById.has(id)) added.push(id);
897
+ }
898
+ removed.sort((a, b) => a.localeCompare(b));
899
+ added.sort((a, b) => a.localeCompare(b));
900
+ for (const id of beforeById.keys()) {
901
+ const b = beforeById.get(id);
902
+ const a = afterById.get(id);
903
+ if (!b || !a) continue;
904
+ const fields = [];
905
+ if (b.kind !== a.kind) {
906
+ kindChanged.push({ id, before: b.kind, after: a.kind });
907
+ continue;
908
+ }
909
+ if (b.name !== a.name) fields.push("name");
910
+ if (b.derived !== a.derived) fields.push("derived");
911
+ if (fields.length > 0) riskyChanged.push({ id, fields });
912
+ }
913
+ kindChanged.sort((x, y) => x.id.localeCompare(y.id));
914
+ riskyChanged.sort((x, y) => x.id.localeCompare(y.id));
915
+ if (removed.length > 0) {
916
+ changes.push({
917
+ severity: "BREAKING",
918
+ code: "logicUnits.removed",
919
+ message: `logicUnits removed: ${removed.join(", ")}`,
920
+ pointer: "/logicUnits",
921
+ details: { removed }
922
+ });
923
+ }
924
+ if (kindChanged.length > 0) {
925
+ changes.push({
926
+ severity: "BREAKING",
927
+ code: "logicUnits.kindChanged",
928
+ message: `logicUnits kind changed: ${kindChanged.map((x) => x.id).join(", ")}`,
929
+ pointer: "/logicUnits",
930
+ details: { kindChanged }
931
+ });
932
+ }
933
+ if (added.length > 0) {
934
+ changes.push({
935
+ severity: "INFO",
936
+ code: "logicUnits.added",
937
+ message: `logicUnits added: ${added.join(", ")}`,
938
+ pointer: "/logicUnits",
939
+ details: { added }
940
+ });
941
+ }
942
+ if (riskyChanged.length > 0) {
943
+ changes.push({
944
+ severity: "RISKY",
945
+ code: "logicUnits.changed",
946
+ message: `logicUnits changed: ${riskyChanged.map((x) => x.id).join(", ")}`,
947
+ pointer: "/logicUnits",
948
+ details: { changed: riskyChanged }
949
+ });
950
+ }
951
+ }
952
+ {
953
+ const beforeDigest = before.staticIr?.digest;
954
+ const afterDigest = after.staticIr?.digest;
955
+ if (beforeDigest !== afterDigest) {
956
+ changes.push({
957
+ severity: "RISKY",
958
+ code: "staticIr.digestChanged",
959
+ message: "staticIr.digest changed",
960
+ pointer: "/staticIr/digest",
961
+ details: {
962
+ before: beforeDigest ?? null,
963
+ after: afterDigest ?? null
964
+ }
965
+ });
966
+ }
967
+ }
968
+ {
969
+ const metaBefore = before.meta ?? {};
970
+ const metaAfter = after.meta ?? {};
971
+ const allowlist = options?.metaAllowlist;
972
+ const keys = allowlist != null ? uniqSorted(allowlist) : uniqSorted([...Object.keys(metaBefore), ...Object.keys(metaAfter)]);
973
+ const changed = [];
974
+ for (const key of keys) {
975
+ const b = key in metaBefore ? metaBefore[key] : void 0;
976
+ const a = key in metaAfter ? metaAfter[key] : void 0;
977
+ if (!eqJsonValue(b, a)) {
978
+ changed.push({
979
+ key,
980
+ before: b ?? null,
981
+ after: a ?? null
982
+ });
983
+ }
984
+ }
985
+ if (changed.length > 0) {
986
+ changes.push({
987
+ severity: "RISKY",
988
+ code: "meta.changed",
989
+ message: "meta changed",
990
+ pointer: "/meta",
991
+ details: {
992
+ keys: changed.map((x) => x.key),
993
+ changed
994
+ }
995
+ });
996
+ }
997
+ }
998
+ {
999
+ const b = before.source;
1000
+ const a = after.source;
1001
+ if (!eqJsonValue(b ?? null, a ?? null)) {
1002
+ changes.push({
1003
+ severity: "INFO",
1004
+ code: "source.changed",
1005
+ message: "source changed",
1006
+ pointer: "/source",
1007
+ details: {
1008
+ before: b ?? null,
1009
+ after: a ?? null
1010
+ }
1011
+ });
1012
+ }
1013
+ }
1014
+ changes.sort((a, b) => {
1015
+ const ra = SEVERITY_RANK[a.severity];
1016
+ const rb = SEVERITY_RANK[b.severity];
1017
+ if (ra !== rb) return ra - rb;
1018
+ const ca = a.code.localeCompare(b.code);
1019
+ if (ca !== 0) return ca;
1020
+ const pa = a.pointer ?? "";
1021
+ const pb = b.pointer ?? "";
1022
+ return pa.localeCompare(pb);
1023
+ });
1024
+ const summary = {
1025
+ breaking: changes.filter((c) => c.severity === "BREAKING").length,
1026
+ risky: changes.filter((c) => c.severity === "RISKY").length,
1027
+ info: changes.filter((c) => c.severity === "INFO").length
1028
+ };
1029
+ const verdict = summary.breaking > 0 ? "FAIL" : summary.risky > 0 ? "WARN" : "PASS";
1030
+ return {
1031
+ version: "025",
1032
+ moduleId: after.moduleId,
1033
+ before: {
1034
+ digest: before.digest,
1035
+ manifestVersion: before.manifestVersion
1036
+ },
1037
+ after: {
1038
+ digest: after.digest,
1039
+ manifestVersion: after.manifestVersion
1040
+ },
1041
+ verdict,
1042
+ changes,
1043
+ summary
1044
+ };
1045
+ };
1046
+
1047
+ // src/internal/reflection/kernelContract.ts
1048
+ var import_effect34 = require("effect");
1049
+
1050
+ // src/internal/observability/trialRun.ts
1051
+ var import_effect33 = require("effect");
1052
+
1053
+ // src/internal/observability/evidenceCollector.ts
1054
+ var import_effect8 = require("effect");
1055
+
1056
+ // src/internal/observability/runSession.ts
1057
+ var import_effect4 = require("effect");
1058
+
1059
+ // src/internal/observability/evidence.ts
1060
+ var OBSERVABILITY_PROTOCOL_VERSION = "v1";
1061
+ var exportEvidencePackage = (options) => {
1062
+ const protocolVersion = options.protocolVersion ?? OBSERVABILITY_PROTOCOL_VERSION;
1063
+ return {
1064
+ protocolVersion,
1065
+ runId: options.runId,
1066
+ createdAt: options.createdAt ?? Date.now(),
1067
+ source: options.source,
1068
+ events: options.events.slice().sort((a, b) => a.seq - b.seq),
1069
+ summary: options.summary
1070
+ };
1071
+ };
1072
+
1073
+ // src/internal/observability/runSession.ts
1074
+ var RunSessionTagImpl = class extends import_effect4.Context.Tag("@logixjs/core/RunSession")() {
1075
+ };
1076
+ var RunSessionTag = RunSessionTagImpl;
1077
+ var NEXT_RUN_SEQ_KEY = /* @__PURE__ */ Symbol.for("@logixjs/core/runSession/nextRunSeq");
1078
+ var fallbackNextRunSeq = 0;
1079
+ var nextRunSeq = () => {
1080
+ try {
1081
+ const g = globalThis;
1082
+ const prev = typeof g[NEXT_RUN_SEQ_KEY] === "number" ? g[NEXT_RUN_SEQ_KEY] : 0;
1083
+ const next = prev + 1;
1084
+ g[NEXT_RUN_SEQ_KEY] = next;
1085
+ return next;
1086
+ } catch {
1087
+ fallbackNextRunSeq += 1;
1088
+ return fallbackNextRunSeq;
1089
+ }
1090
+ };
1091
+ var makeRunId = (startedAt) => `run-${startedAt}.${nextRunSeq()}`;
1092
+ var makeRunSessionLocalState = () => {
1093
+ const onceKeys = /* @__PURE__ */ new Set();
1094
+ const seqByNamespace = /* @__PURE__ */ new Map();
1095
+ return {
1096
+ once: (key) => {
1097
+ if (onceKeys.has(key)) return false;
1098
+ onceKeys.add(key);
1099
+ return true;
1100
+ },
1101
+ nextSeq: (namespace, key) => {
1102
+ const byKey = seqByNamespace.get(namespace) ?? /* @__PURE__ */ new Map();
1103
+ if (!seqByNamespace.has(namespace)) seqByNamespace.set(namespace, byKey);
1104
+ const prev = byKey.get(key) ?? 0;
1105
+ const next = prev + 1;
1106
+ byKey.set(key, next);
1107
+ return next;
1108
+ },
1109
+ clear: () => {
1110
+ onceKeys.clear();
1111
+ seqByNamespace.clear();
1112
+ }
1113
+ };
1114
+ };
1115
+ var makeRunSession = (options) => {
1116
+ const startedAt = options?.startedAt ?? Date.now();
1117
+ return {
1118
+ runId: options?.runId ?? makeRunId(startedAt),
1119
+ source: options?.source ?? { host: "unknown" },
1120
+ startedAt,
1121
+ local: options?.local ?? makeRunSessionLocalState()
1122
+ };
1123
+ };
1124
+ var makeEvidenceSink = (session) => {
1125
+ const events = [];
1126
+ let nextSeq = 1;
1127
+ return {
1128
+ record: (type, payload, options) => {
1129
+ events.push({
1130
+ protocolVersion: OBSERVABILITY_PROTOCOL_VERSION,
1131
+ runId: session.runId,
1132
+ seq: nextSeq++,
1133
+ timestamp: options?.timestamp ?? Date.now(),
1134
+ type,
1135
+ payload
1136
+ });
1137
+ },
1138
+ export: (options) => {
1139
+ const protocolVersion = options?.protocolVersion ?? OBSERVABILITY_PROTOCOL_VERSION;
1140
+ const maxEvents = options?.maxEvents;
1141
+ const selected = typeof maxEvents === "number" && Number.isFinite(maxEvents) && maxEvents > 0 ? events.slice(Math.max(0, events.length - Math.floor(maxEvents))) : events.slice();
1142
+ return exportEvidencePackage({
1143
+ protocolVersion,
1144
+ runId: session.runId,
1145
+ source: session.source,
1146
+ createdAt: options?.createdAt,
1147
+ events: selected,
1148
+ summary: options?.summary
1149
+ });
1150
+ },
1151
+ clear: () => {
1152
+ events.length = 0;
1153
+ nextSeq = 1;
1154
+ }
1155
+ };
1156
+ };
1157
+ var runSessionLayer = (session) => import_effect4.Layer.succeed(RunSessionTag, session ?? makeRunSession());
1158
+
1159
+ // src/internal/runtime/core/DebugSink.ts
1160
+ var import_effect7 = require("effect");
1161
+
1162
+ // src/internal/runtime/core/errorSummary.ts
1163
+ var import_effect5 = require("effect");
1164
+ var truncate = (value, maxLen) => {
1165
+ if (value.length <= maxLen) return { value, truncated: false };
1166
+ return { value: value.slice(0, maxLen), truncated: true };
1167
+ };
1168
+ var safeStringify = (value) => {
1169
+ try {
1170
+ return { ok: true, json: JSON.stringify(value) };
1171
+ } catch {
1172
+ return { ok: false };
1173
+ }
1174
+ };
1175
+ var getMessageFromUnknown = (cause) => {
1176
+ if (typeof cause === "string") return cause;
1177
+ if (typeof cause === "number" || typeof cause === "boolean" || typeof cause === "bigint") return String(cause);
1178
+ if (cause instanceof Error) return cause.message || cause.name || "Error";
1179
+ if (cause && typeof cause === "object" && "message" in cause && typeof cause.message === "string") {
1180
+ return cause.message;
1181
+ }
1182
+ try {
1183
+ const pretty = import_effect5.Cause.pretty(cause, { renderErrorCause: true });
1184
+ if (typeof pretty === "string" && pretty.length > 0) return pretty;
1185
+ } catch {
1186
+ }
1187
+ return "Unknown error";
1188
+ };
1189
+ var toSerializableErrorSummary = (cause, options) => {
1190
+ const maxMessageLength = options?.maxMessageLength ?? 256;
1191
+ const messageRaw = getMessageFromUnknown(cause);
1192
+ const { value: message, truncated } = truncate(messageRaw, maxMessageLength);
1193
+ const summary = {
1194
+ message
1195
+ };
1196
+ if (cause instanceof Error) {
1197
+ if (cause.name && cause.name !== "Error") summary.name = cause.name;
1198
+ const anyCause = cause;
1199
+ if (typeof anyCause.code === "string" && anyCause.code.length > 0) summary.code = anyCause.code;
1200
+ else if (typeof anyCause.code === "number" && Number.isFinite(anyCause.code)) summary.code = String(anyCause.code);
1201
+ if (typeof anyCause.hint === "string" && anyCause.hint.length > 0) summary.hint = anyCause.hint;
1202
+ return {
1203
+ errorSummary: summary,
1204
+ downgrade: truncated ? "oversized" : void 0
1205
+ };
1206
+ }
1207
+ if (cause && typeof cause === "object") {
1208
+ const anyCause = cause;
1209
+ if (typeof anyCause.name === "string" && anyCause.name.length > 0) summary.name = anyCause.name;
1210
+ if (typeof anyCause.code === "string" && anyCause.code.length > 0) summary.code = anyCause.code;
1211
+ if (typeof anyCause.hint === "string" && anyCause.hint.length > 0) summary.hint = anyCause.hint;
1212
+ }
1213
+ const stringifyResult = safeStringify(cause);
1214
+ if (!stringifyResult.ok) {
1215
+ return {
1216
+ errorSummary: summary,
1217
+ downgrade: "non_serializable"
1218
+ };
1219
+ }
1220
+ if (truncated) {
1221
+ return {
1222
+ errorSummary: summary,
1223
+ downgrade: "oversized"
1224
+ };
1225
+ }
1226
+ if (message === "Unknown error") {
1227
+ return {
1228
+ errorSummary: summary,
1229
+ downgrade: "unknown"
1230
+ };
1231
+ }
1232
+ return { errorSummary: summary };
1233
+ };
1234
+
1235
+ // src/internal/runtime/core/EffectOpCore.ts
1236
+ var import_effect6 = require("effect");
1237
+ var currentLinkId = import_effect6.FiberRef.unsafeMake(void 0);
1238
+ var EffectOpMiddlewareTag = class extends import_effect6.Context.Tag("Logix/EffectOpMiddleware")() {
1239
+ };
1240
+
1241
+ // src/internal/runtime/core/DebugSink.ts
1242
+ var currentDebugSinks = import_effect7.FiberRef.unsafeMake([]);
1243
+ var currentRuntimeLabel = import_effect7.FiberRef.unsafeMake(void 0);
1244
+ var currentTxnId = import_effect7.FiberRef.unsafeMake(void 0);
1245
+ var currentOpSeq = import_effect7.FiberRef.unsafeMake(void 0);
1246
+ var currentDiagnosticsLevel = import_effect7.FiberRef.unsafeMake("off");
1247
+ var diagnosticsLevel = (level) => import_effect7.Layer.fiberRefLocallyScopedWith(currentDiagnosticsLevel, () => level);
1248
+ var currentTraitConvergeDiagnosticsSampling = import_effect7.FiberRef.unsafeMake({
1249
+ sampleEveryN: 32,
1250
+ topK: 3
1251
+ });
1252
+ var appendSinks = (sinks) => import_effect7.Layer.fiberRefLocallyScopedWith(currentDebugSinks, (current) => [...current, ...sinks]);
1253
+ var nextGlobalEventSeq = 0;
1254
+ var nextEventSeq = () => {
1255
+ nextGlobalEventSeq += 1;
1256
+ return nextGlobalEventSeq;
1257
+ };
1258
+ var makeEventId = (instanceId, eventSeq) => `${instanceId}::e${eventSeq}`;
1259
+ var mergeDowngrade2 = (current, next) => {
1260
+ if (!current) return next;
1261
+ if (!next) return current;
1262
+ if (current === "non_serializable" || next === "non_serializable") return "non_serializable";
1263
+ if (current === "oversized" || next === "oversized") return "oversized";
1264
+ return "unknown";
1265
+ };
1266
+ var browserLifecycleSeen = /* @__PURE__ */ new Set();
1267
+ var browserDiagnosticSeen = /* @__PURE__ */ new Set();
1268
+ var lastTxnByInstance = /* @__PURE__ */ new Map();
1269
+ var pendingTxnAlignmentByInstance = /* @__PURE__ */ new Map();
1270
+ var enqueuePendingTxnAlignment = (instanceId, ref) => {
1271
+ const list = pendingTxnAlignmentByInstance.get(instanceId);
1272
+ if (!list) {
1273
+ pendingTxnAlignmentByInstance.set(instanceId, [ref]);
1274
+ return;
1275
+ }
1276
+ list.push(ref);
1277
+ if (list.length > 64) {
1278
+ list.shift();
1279
+ }
1280
+ };
1281
+ var backfillPendingTxnAlignment = (instanceId, txn) => {
1282
+ const pending = pendingTxnAlignmentByInstance.get(instanceId);
1283
+ if (!pending || pending.length === 0) {
1284
+ pendingTxnAlignmentByInstance.delete(instanceId);
1285
+ return;
1286
+ }
1287
+ for (const ref of pending) {
1288
+ const anyRef = ref;
1289
+ if (anyRef.txnId == null) {
1290
+ anyRef.txnId = txn.txnId;
1291
+ }
1292
+ if (typeof anyRef.txnSeq !== "number" || anyRef.txnSeq <= 0) {
1293
+ anyRef.txnSeq = txn.txnSeq;
1294
+ }
1295
+ }
1296
+ pendingTxnAlignmentByInstance.delete(instanceId);
1297
+ };
1298
+ var lifecycleErrorLog = (event) => {
1299
+ const moduleId = event.moduleId ?? "unknown";
1300
+ const causePretty = (() => {
1301
+ try {
1302
+ return import_effect7.Cause.pretty(event.cause, {
1303
+ renderErrorCause: true
1304
+ });
1305
+ } catch {
1306
+ try {
1307
+ return JSON.stringify(event.cause, null, 2);
1308
+ } catch {
1309
+ return String(event.cause);
1310
+ }
1311
+ }
1312
+ })();
1313
+ const message = `[Logix][module=${moduleId}] lifecycle:error
1314
+ ${causePretty}`;
1315
+ return import_effect7.Effect.logError(message).pipe(
1316
+ import_effect7.Effect.annotateLogs({
1317
+ "logix.moduleId": moduleId,
1318
+ "logix.event": "lifecycle:error",
1319
+ "logix.cause": causePretty
1320
+ })
1321
+ );
1322
+ };
1323
+ var diagnosticLog = (event) => {
1324
+ const moduleId = event.moduleId ?? "unknown";
1325
+ const header = `[Logix][module=${moduleId}] diagnostic(${event.severity})`;
1326
+ const detail = `code=${event.code} message=${event.message}${event.actionTag ? ` action=${event.actionTag}` : ""}${event.hint ? `
1327
+ hint: ${event.hint}` : ""}`;
1328
+ const msg = `${header}
1329
+ ${detail}`;
1330
+ const base = event.severity === "warning" ? import_effect7.Effect.logWarning(msg) : event.severity === "info" ? import_effect7.Effect.logInfo(msg) : import_effect7.Effect.logError(msg);
1331
+ const annotations = {
1332
+ "logix.moduleId": moduleId,
1333
+ "logix.event": `diagnostic(${event.severity})`,
1334
+ "logix.diagnostic.code": event.code,
1335
+ "logix.diagnostic.message": event.message
1336
+ };
1337
+ if (event.hint) {
1338
+ annotations["logix.diagnostic.hint"] = event.hint;
1339
+ }
1340
+ if (event.actionTag) {
1341
+ annotations["logix.diagnostic.actionTag"] = event.actionTag;
1342
+ }
1343
+ return base.pipe(import_effect7.Effect.annotateLogs(annotations));
1344
+ };
1345
+ var noopLayer = import_effect7.Layer.locallyScoped(currentDebugSinks, []);
1346
+ var errorOnlySink = {
1347
+ record: (event) => event.type === "lifecycle:error" ? lifecycleErrorLog(event) : event.type === "diagnostic" && event.severity !== "info" ? diagnosticLog(event) : import_effect7.Effect.void
1348
+ };
1349
+ var errorOnlyLayer = import_effect7.Layer.locallyScoped(currentDebugSinks, [errorOnlySink]);
1350
+ var isErrorOnlyOnlySinks = (sinks) => sinks.length === 1 && sinks[0] === errorOnlySink;
1351
+ var consoleSink = {
1352
+ record: (event) => event.type === "lifecycle:error" ? lifecycleErrorLog(event) : event.type === "diagnostic" ? diagnosticLog(event) : import_effect7.Effect.logDebug({ debugEvent: event })
1353
+ };
1354
+ var consoleLayer = import_effect7.Layer.locallyScoped(currentDebugSinks, [consoleSink]);
1355
+ var isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
1356
+ var renderBrowserConsoleEvent = (event) => {
1357
+ if (typeof event.type === "string" && event.type.startsWith("trace:")) {
1358
+ const moduleId = event.moduleId ?? "unknown";
1359
+ const type = event.type;
1360
+ return import_effect7.Effect.sync(() => {
1361
+ console.groupCollapsed(
1362
+ "%c[Logix]%c trace %c" + moduleId + "%c " + String(type),
1363
+ "color:#6b7280;font-weight:bold",
1364
+ // tag
1365
+ "color:#3b82f6",
1366
+ // label
1367
+ "color:#9ca3af",
1368
+ // module id
1369
+ "color:#6b7280"
1370
+ // type
1371
+ );
1372
+ console.log(event);
1373
+ console.groupEnd();
1374
+ });
1375
+ }
1376
+ if (event.type === "lifecycle:error") {
1377
+ const moduleId = event.moduleId ?? "unknown";
1378
+ const causePretty = (() => {
1379
+ try {
1380
+ return import_effect7.Cause.pretty(event.cause, { renderErrorCause: true });
1381
+ } catch {
1382
+ try {
1383
+ return JSON.stringify(event.cause, null, 2);
1384
+ } catch {
1385
+ return String(event.cause);
1386
+ }
1387
+ }
1388
+ })();
1389
+ const key = `${moduleId}|${causePretty}`;
1390
+ if (browserLifecycleSeen.has(key)) {
1391
+ return import_effect7.Effect.void;
1392
+ }
1393
+ browserLifecycleSeen.add(key);
1394
+ return import_effect7.Effect.sync(() => {
1395
+ console.groupCollapsed(
1396
+ "%c[Logix]%c lifecycle:error %c" + moduleId,
1397
+ "color:#ef4444;font-weight:bold",
1398
+ // tag
1399
+ "color:#ef4444",
1400
+ // label
1401
+ "color:#9ca3af"
1402
+ // module id
1403
+ );
1404
+ console.error(causePretty);
1405
+ console.groupEnd();
1406
+ });
1407
+ }
1408
+ if (event.type === "diagnostic") {
1409
+ const moduleId = event.moduleId ?? "unknown";
1410
+ const detail = `code=${event.code} message=${event.message}${event.actionTag ? ` action=${event.actionTag}` : ""}${event.hint ? `
1411
+ hint: ${event.hint}` : ""}`;
1412
+ const color = event.severity === "warning" ? "color:#d97706" : event.severity === "info" ? "color:#3b82f6" : "color:#ef4444";
1413
+ const label = event.severity === "warning" ? "diagnostic(warning)" : event.severity === "info" ? "diagnostic(info)" : "diagnostic(error)";
1414
+ const key = `${moduleId}|${event.code}|${event.message}`;
1415
+ if (browserDiagnosticSeen.has(key)) {
1416
+ return import_effect7.Effect.void;
1417
+ }
1418
+ browserDiagnosticSeen.add(key);
1419
+ return import_effect7.Effect.sync(() => {
1420
+ console.groupCollapsed(
1421
+ "%c[Logix]%c " + label + "%c module=" + moduleId,
1422
+ "color:#6b7280;font-weight:bold",
1423
+ color,
1424
+ "color:#9ca3af"
1425
+ );
1426
+ if (event.severity === "warning") {
1427
+ console.warn(detail);
1428
+ } else if (event.severity === "info") {
1429
+ console.info(detail);
1430
+ } else {
1431
+ console.error(detail);
1432
+ }
1433
+ console.groupEnd();
1434
+ });
1435
+ }
1436
+ return import_effect7.Effect.void;
1437
+ };
1438
+ var browserConsoleSink = {
1439
+ record: (event) => {
1440
+ if (!isBrowser) {
1441
+ return event.type === "lifecycle:error" ? lifecycleErrorLog(event) : event.type === "diagnostic" ? diagnosticLog(event) : import_effect7.Effect.logDebug({ debugEvent: event });
1442
+ }
1443
+ return renderBrowserConsoleEvent(event);
1444
+ }
1445
+ };
1446
+ var browserConsoleLayer = import_effect7.Layer.locallyScoped(currentDebugSinks, [browserConsoleSink]);
1447
+ var browserDiagnosticConsoleSink = {
1448
+ record: (event) => {
1449
+ if (!isBrowser) {
1450
+ return event.type === "lifecycle:error" ? lifecycleErrorLog(event) : event.type === "diagnostic" && event.severity !== "info" ? diagnosticLog(event) : import_effect7.Effect.void;
1451
+ }
1452
+ return event.type === "lifecycle:error" || event.type === "diagnostic" && event.severity !== "info" ? renderBrowserConsoleEvent(event) : import_effect7.Effect.void;
1453
+ }
1454
+ };
1455
+ var browserDiagnosticConsoleLayer = import_effect7.Layer.locallyScoped(currentDebugSinks, [browserDiagnosticConsoleSink]);
1456
+ var browserPrettyLoggerLayer = import_effect7.Logger.replace(
1457
+ import_effect7.Logger.defaultLogger,
1458
+ import_effect7.Logger.prettyLogger({ mode: "browser", colors: true })
1459
+ );
1460
+ var record = (event) => import_effect7.Effect.gen(function* () {
1461
+ const sinks = yield* import_effect7.FiberRef.get(currentDebugSinks);
1462
+ if (isErrorOnlyOnlySinks(sinks)) {
1463
+ if (event.type === "lifecycle:error") {
1464
+ yield* lifecycleErrorLog(event);
1465
+ return;
1466
+ }
1467
+ if (event.type === "diagnostic") {
1468
+ if (event.severity !== "info") {
1469
+ yield* diagnosticLog(event);
1470
+ } else {
1471
+ yield* import_effect7.Effect.void;
1472
+ }
1473
+ return;
1474
+ }
1475
+ yield* import_effect7.Effect.void;
1476
+ return;
1477
+ }
1478
+ if (sinks.length === 0) {
1479
+ if (isBrowser) {
1480
+ if (event.type === "lifecycle:error" || event.type === "diagnostic") {
1481
+ yield* renderBrowserConsoleEvent(event);
1482
+ return;
1483
+ }
1484
+ yield* import_effect7.Effect.void;
1485
+ return;
1486
+ }
1487
+ if (event.type === "lifecycle:error") {
1488
+ yield* lifecycleErrorLog(event);
1489
+ return;
1490
+ }
1491
+ if (event.type === "diagnostic") {
1492
+ yield* diagnosticLog(event);
1493
+ return;
1494
+ }
1495
+ yield* import_effect7.Effect.void;
1496
+ return;
1497
+ }
1498
+ const enriched = event;
1499
+ const diagnosticsLevel2 = yield* import_effect7.FiberRef.get(currentDiagnosticsLevel);
1500
+ let now;
1501
+ const getNow = () => {
1502
+ if (now === void 0) now = Date.now();
1503
+ return now;
1504
+ };
1505
+ if (enriched.timestamp === void 0 && (diagnosticsLevel2 !== "off" || enriched.type === "lifecycle:error" || enriched.type === "diagnostic")) {
1506
+ ;
1507
+ enriched.timestamp = getNow();
1508
+ }
1509
+ if (diagnosticsLevel2 !== "off" && enriched.runtimeLabel === void 0) {
1510
+ const runtimeLabel = yield* import_effect7.FiberRef.get(currentRuntimeLabel);
1511
+ if (runtimeLabel) {
1512
+ ;
1513
+ enriched.runtimeLabel = runtimeLabel;
1514
+ }
1515
+ }
1516
+ if (enriched.type === "diagnostic" && enriched.txnId === void 0) {
1517
+ const txnId = yield* import_effect7.FiberRef.get(currentTxnId);
1518
+ if (txnId) {
1519
+ ;
1520
+ enriched.txnId = txnId;
1521
+ }
1522
+ }
1523
+ if (diagnosticsLevel2 !== "off" && enriched.type === "trace:effectop" && enriched.linkId === void 0) {
1524
+ const linkId = yield* import_effect7.FiberRef.get(currentLinkId);
1525
+ if (linkId) {
1526
+ ;
1527
+ enriched.linkId = linkId;
1528
+ }
1529
+ }
1530
+ if (sinks.length === 1) {
1531
+ yield* sinks[0].record(enriched);
1532
+ return;
1533
+ }
1534
+ yield* import_effect7.Effect.forEach(sinks, (sink) => sink.record(enriched), { discard: true });
1535
+ });
1536
+ var toRuntimeDebugEventRef = (event, options) => {
1537
+ const diagnosticsLevel2 = options?.diagnosticsLevel ?? "full";
1538
+ if (diagnosticsLevel2 === "off") {
1539
+ return void 0;
1540
+ }
1541
+ const isLightLike = diagnosticsLevel2 === "light" || diagnosticsLevel2 === "sampled";
1542
+ const timestamp = typeof event.timestamp === "number" && Number.isFinite(event.timestamp) ? event.timestamp : Date.now();
1543
+ const moduleIdRaw = event.moduleId;
1544
+ const moduleId = typeof moduleIdRaw === "string" && moduleIdRaw.length > 0 ? moduleIdRaw : "unknown";
1545
+ const instanceIdRaw = event.instanceId;
1546
+ const instanceId = typeof instanceIdRaw === "string" && instanceIdRaw.length > 0 ? instanceIdRaw : "unknown";
1547
+ const runtimeLabelRaw = event.runtimeLabel;
1548
+ const runtimeLabel = typeof runtimeLabelRaw === "string" && runtimeLabelRaw.length > 0 ? runtimeLabelRaw : void 0;
1549
+ const txnSeqRaw = event.txnSeq;
1550
+ const txnSeq = typeof txnSeqRaw === "number" && Number.isFinite(txnSeqRaw) && txnSeqRaw >= 0 ? Math.floor(txnSeqRaw) : 0;
1551
+ const txnIdRaw = event.txnId;
1552
+ const txnId = typeof txnIdRaw === "string" && txnIdRaw.length > 0 ? txnIdRaw : txnSeq > 0 ? `${instanceId}::t${txnSeq}` : void 0;
1553
+ const linkId = (() => {
1554
+ const linkIdRaw = event.linkId;
1555
+ if (typeof linkIdRaw === "string" && linkIdRaw.length > 0) return linkIdRaw;
1556
+ if (typeof event.type !== "string" || !event.type.startsWith("trace:")) {
1557
+ return void 0;
1558
+ }
1559
+ const data = event.data;
1560
+ const meta = data?.meta;
1561
+ const linkIdFromMeta = meta?.linkId;
1562
+ if (typeof linkIdFromMeta === "string" && linkIdFromMeta.length > 0) return linkIdFromMeta;
1563
+ return void 0;
1564
+ })();
1565
+ const eventSeqRaw = options?.eventSeq;
1566
+ const eventSeq = typeof eventSeqRaw === "number" && Number.isFinite(eventSeqRaw) && eventSeqRaw > 0 ? Math.floor(eventSeqRaw) : nextEventSeq();
1567
+ const eventId = makeEventId(instanceId, eventSeq);
1568
+ const base = {
1569
+ eventId,
1570
+ eventSeq,
1571
+ moduleId,
1572
+ instanceId,
1573
+ runtimeLabel,
1574
+ txnSeq,
1575
+ txnId,
1576
+ linkId,
1577
+ timestamp
1578
+ };
1579
+ let downgrade;
1580
+ const withDowngrade = (ref) => {
1581
+ if (!downgrade) return ref;
1582
+ return { ...ref, downgrade: { reason: downgrade } };
1583
+ };
1584
+ switch (event.type) {
1585
+ case "module:init":
1586
+ return withDowngrade({
1587
+ ...base,
1588
+ kind: "lifecycle",
1589
+ label: "module:init"
1590
+ });
1591
+ case "module:destroy":
1592
+ return withDowngrade({
1593
+ ...base,
1594
+ kind: "lifecycle",
1595
+ label: "module:destroy"
1596
+ });
1597
+ case "lifecycle:phase": {
1598
+ const e = event;
1599
+ const metaInput = isLightLike ? { type: "lifecycle:phase", phase: e.phase, name: e.name } : { type: "lifecycle:phase", phase: e.phase, name: e.name, payload: e.payload };
1600
+ const metaProjection = projectJsonValue(metaInput);
1601
+ options?.onMetaProjection?.({
1602
+ stats: metaProjection.stats,
1603
+ downgrade: metaProjection.downgrade
1604
+ });
1605
+ downgrade = mergeDowngrade2(downgrade, metaProjection.downgrade);
1606
+ return withDowngrade({
1607
+ ...base,
1608
+ kind: "lifecycle",
1609
+ label: e.name,
1610
+ meta: metaProjection.value
1611
+ });
1612
+ }
1613
+ case "action:dispatch": {
1614
+ const action = event.action;
1615
+ const actionTagRaw = event.actionTag;
1616
+ const tag = typeof actionTagRaw === "string" && actionTagRaw.length > 0 ? actionTagRaw : action?._tag ?? action?.type;
1617
+ const label = String(tag ?? "action:dispatch");
1618
+ const labelNormalized = label.length > 0 ? label : "unknown";
1619
+ const unknownAction = event.unknownAction === true ? true : void 0;
1620
+ const metaInput = isLightLike ? { actionTag: labelNormalized, ...unknownAction ? { unknownAction: true } : {} } : { action, ...unknownAction ? { unknownAction: true } : {} };
1621
+ const metaProjection = projectJsonValue(metaInput);
1622
+ options?.onMetaProjection?.({
1623
+ stats: metaProjection.stats,
1624
+ downgrade: metaProjection.downgrade
1625
+ });
1626
+ downgrade = mergeDowngrade2(downgrade, metaProjection.downgrade);
1627
+ if (unknownAction) {
1628
+ downgrade = mergeDowngrade2(downgrade, "unknown");
1629
+ }
1630
+ return withDowngrade({
1631
+ ...base,
1632
+ kind: "action",
1633
+ label: labelNormalized,
1634
+ meta: metaProjection.value
1635
+ });
1636
+ }
1637
+ case "state:update": {
1638
+ const e = event;
1639
+ const resolveDirtySetRootPaths = () => {
1640
+ const resolve2 = options?.resolveConvergeStaticIr;
1641
+ if (!resolve2) return void 0;
1642
+ const digest = e.staticIrDigest;
1643
+ if (typeof digest !== "string" || digest.length === 0) return void 0;
1644
+ const dirtySet = e.dirtySet;
1645
+ if (!dirtySet || typeof dirtySet !== "object" || Array.isArray(dirtySet)) return void 0;
1646
+ const rootIds = dirtySet.rootIds;
1647
+ if (!Array.isArray(rootIds) || rootIds.length === 0) return void 0;
1648
+ const ir = resolve2(digest);
1649
+ const fieldPaths = ir?.fieldPaths;
1650
+ if (!Array.isArray(fieldPaths) || fieldPaths.length === 0) return void 0;
1651
+ const out = [];
1652
+ for (const rawId of rootIds) {
1653
+ if (typeof rawId !== "number" || !Number.isFinite(rawId)) continue;
1654
+ const id = Math.floor(rawId);
1655
+ if (id < 0) continue;
1656
+ const path = fieldPaths[id];
1657
+ if (!Array.isArray(path) || path.length === 0) continue;
1658
+ if (!path.every((seg) => typeof seg === "string" && seg.length > 0)) continue;
1659
+ out.push(path);
1660
+ }
1661
+ return out.length > 0 ? out : void 0;
1662
+ };
1663
+ const dirtySetWithRootPaths = (() => {
1664
+ const rootPaths = resolveDirtySetRootPaths();
1665
+ if (!rootPaths) return e.dirtySet;
1666
+ const dirtySet = e.dirtySet;
1667
+ if (!dirtySet || typeof dirtySet !== "object" || Array.isArray(dirtySet)) return e.dirtySet;
1668
+ return { ...dirtySet, rootPaths };
1669
+ })();
1670
+ const metaInput = isLightLike ? {
1671
+ state: e.state,
1672
+ dirtySet: dirtySetWithRootPaths,
1673
+ patchCount: e.patchCount,
1674
+ patchesTruncated: e.patchesTruncated,
1675
+ patchesTruncatedReason: e.patchesTruncatedReason,
1676
+ staticIrDigest: e.staticIrDigest,
1677
+ commitMode: e.commitMode,
1678
+ priority: e.priority,
1679
+ originKind: e.originKind,
1680
+ originName: e.originName
1681
+ } : {
1682
+ state: e.state,
1683
+ dirtySet: dirtySetWithRootPaths,
1684
+ patchCount: e.patchCount,
1685
+ patchesTruncated: e.patchesTruncated,
1686
+ patchesTruncatedReason: e.patchesTruncatedReason,
1687
+ staticIrDigest: e.staticIrDigest,
1688
+ commitMode: e.commitMode,
1689
+ priority: e.priority,
1690
+ originKind: e.originKind,
1691
+ originName: e.originName,
1692
+ traitSummary: e.traitSummary,
1693
+ replayEvent: e.replayEvent
1694
+ };
1695
+ const metaProjection = projectJsonValue(metaInput);
1696
+ options?.onMetaProjection?.({
1697
+ stats: metaProjection.stats,
1698
+ downgrade: metaProjection.downgrade
1699
+ });
1700
+ downgrade = mergeDowngrade2(downgrade, metaProjection.downgrade);
1701
+ if (txnId) {
1702
+ lastTxnByInstance.set(instanceId, { txnId, txnSeq });
1703
+ backfillPendingTxnAlignment(instanceId, { txnId, txnSeq });
1704
+ }
1705
+ return withDowngrade({
1706
+ ...base,
1707
+ kind: "state",
1708
+ label: "state:update",
1709
+ meta: metaProjection.value
1710
+ });
1711
+ }
1712
+ case "process:start":
1713
+ case "process:stop":
1714
+ case "process:restart":
1715
+ case "process:trigger":
1716
+ case "process:dispatch":
1717
+ case "process:error": {
1718
+ const e = event;
1719
+ const ts2 = typeof e.timestampMs === "number" && Number.isFinite(e.timestampMs) ? e.timestampMs : timestamp;
1720
+ const metaInput = {
1721
+ identity: e.identity,
1722
+ severity: e.severity,
1723
+ eventSeq: e.eventSeq,
1724
+ timestampMs: e.timestampMs,
1725
+ trigger: e.trigger,
1726
+ dispatch: e.dispatch,
1727
+ error: e.error
1728
+ };
1729
+ const metaProjection = projectJsonValue(metaInput);
1730
+ options?.onMetaProjection?.({
1731
+ stats: metaProjection.stats,
1732
+ downgrade: metaProjection.downgrade
1733
+ });
1734
+ downgrade = mergeDowngrade2(downgrade, metaProjection.downgrade);
1735
+ const errorSummary = e.type === "process:error" || e.type === "process:restart" ? e.error : void 0;
1736
+ return withDowngrade({
1737
+ ...base,
1738
+ timestamp: ts2,
1739
+ kind: "process",
1740
+ label: e.type,
1741
+ meta: metaProjection.value,
1742
+ errorSummary
1743
+ });
1744
+ }
1745
+ case "lifecycle:error": {
1746
+ const e = event;
1747
+ const summary = toSerializableErrorSummary(e.cause);
1748
+ downgrade = mergeDowngrade2(downgrade, summary.downgrade);
1749
+ const metaInput = isLightLike ? { type: "lifecycle:error", phase: e.phase, name: e.hook } : {
1750
+ type: "lifecycle:error",
1751
+ phase: e.phase,
1752
+ name: e.hook,
1753
+ hook: e.hook,
1754
+ taskId: e.taskId,
1755
+ origin: e.origin,
1756
+ txnSeq: e.txnSeq,
1757
+ opSeq: e.opSeq
1758
+ };
1759
+ const metaProjection = projectJsonValue(metaInput);
1760
+ options?.onMetaProjection?.({
1761
+ stats: metaProjection.stats,
1762
+ downgrade: metaProjection.downgrade
1763
+ });
1764
+ downgrade = mergeDowngrade2(downgrade, metaProjection.downgrade);
1765
+ return withDowngrade({
1766
+ ...base,
1767
+ kind: "lifecycle",
1768
+ label: "lifecycle:error",
1769
+ meta: metaProjection.value,
1770
+ errorSummary: summary.errorSummary
1771
+ });
1772
+ }
1773
+ case "diagnostic": {
1774
+ const e = event;
1775
+ const metaInput = {
1776
+ code: e.code,
1777
+ severity: e.severity,
1778
+ message: e.message,
1779
+ hint: e.hint,
1780
+ actionTag: e.actionTag,
1781
+ kind: e.kind,
1782
+ trigger: e.trigger
1783
+ };
1784
+ const metaProjection = projectJsonValue(metaInput);
1785
+ options?.onMetaProjection?.({
1786
+ stats: metaProjection.stats,
1787
+ downgrade: metaProjection.downgrade
1788
+ });
1789
+ downgrade = mergeDowngrade2(downgrade, metaProjection.downgrade);
1790
+ return withDowngrade({
1791
+ ...base,
1792
+ kind: "diagnostic",
1793
+ label: e.code,
1794
+ meta: metaProjection.value
1795
+ });
1796
+ }
1797
+ default: {
1798
+ if (typeof event.type !== "string" || !event.type.startsWith("trace:")) {
1799
+ return void 0;
1800
+ }
1801
+ if (event.type === "trace:txn-lane") {
1802
+ const data = event.data;
1803
+ const evidence = data?.evidence ?? data;
1804
+ const metaProjection2 = projectJsonValue(evidence);
1805
+ options?.onMetaProjection?.({
1806
+ stats: metaProjection2.stats,
1807
+ downgrade: metaProjection2.downgrade
1808
+ });
1809
+ downgrade = mergeDowngrade2(downgrade, metaProjection2.downgrade);
1810
+ const label = typeof evidence?.kind === "string" && evidence.kind.length > 0 ? String(evidence.kind) : "txn-lane";
1811
+ return withDowngrade({
1812
+ ...base,
1813
+ kind: "txn-lane",
1814
+ label,
1815
+ meta: metaProjection2.value
1816
+ });
1817
+ }
1818
+ if (event.type === "trace:react-render" || event.type === "trace:react-selector") {
1819
+ const data = event.data;
1820
+ const metaProjection2 = projectJsonValue(
1821
+ isLightLike ? {
1822
+ componentLabel: data?.componentLabel,
1823
+ selectorKey: data?.selectorKey,
1824
+ fieldPaths: data?.fieldPaths,
1825
+ selectorId: data?.selectorId,
1826
+ lane: data?.lane,
1827
+ producer: data?.producer,
1828
+ fallbackReason: data?.fallbackReason,
1829
+ readsDigest: data?.readsDigest,
1830
+ equalsKind: data?.equalsKind,
1831
+ strictModePhase: data?.strictModePhase
1832
+ } : {
1833
+ componentLabel: data?.componentLabel,
1834
+ selectorKey: data?.selectorKey,
1835
+ fieldPaths: data?.fieldPaths,
1836
+ selectorId: data?.selectorId,
1837
+ lane: data?.lane,
1838
+ producer: data?.producer,
1839
+ fallbackReason: data?.fallbackReason,
1840
+ readsDigest: data?.readsDigest,
1841
+ equalsKind: data?.equalsKind,
1842
+ strictModePhase: data?.strictModePhase,
1843
+ meta: data?.meta
1844
+ }
1845
+ );
1846
+ options?.onMetaProjection?.({
1847
+ stats: metaProjection2.stats,
1848
+ downgrade: metaProjection2.downgrade
1849
+ });
1850
+ downgrade = mergeDowngrade2(downgrade, metaProjection2.downgrade);
1851
+ const label = typeof data?.componentLabel === "string" && data.componentLabel.length > 0 ? data.componentLabel : event.type === "trace:react-selector" ? "react-selector" : "react-render";
1852
+ const last = lastTxnByInstance.get(instanceId);
1853
+ const txnSeqFromMeta = typeof data?.meta?.txnSeq === "number" && Number.isFinite(data.meta.txnSeq) && data.meta.txnSeq >= 0 ? Math.floor(data.meta.txnSeq) : void 0;
1854
+ const txnIdFromMeta = typeof data?.meta?.txnId === "string" && data.meta.txnId.length > 0 ? data.meta.txnId : void 0;
1855
+ const txnIdAligned = txnIdFromMeta ?? base.txnId ?? last?.txnId;
1856
+ const txnSeqAligned = txnSeqFromMeta ?? (base.txnSeq > 0 ? base.txnSeq : last?.txnSeq ?? base.txnSeq);
1857
+ const ref = withDowngrade({
1858
+ ...base,
1859
+ txnId: txnIdAligned,
1860
+ txnSeq: txnSeqAligned,
1861
+ kind: event.type === "trace:react-selector" ? "react-selector" : "react-render",
1862
+ label,
1863
+ meta: metaProjection2.value
1864
+ });
1865
+ if (instanceId !== "unknown" && (ref.txnId == null || ref.txnSeq <= 0)) {
1866
+ enqueuePendingTxnAlignment(instanceId, ref);
1867
+ }
1868
+ return ref;
1869
+ }
1870
+ if (event.type === "trace:selector:eval") {
1871
+ const data = event.data;
1872
+ const metaInput = {
1873
+ selectorId: data?.selectorId,
1874
+ lane: data?.lane,
1875
+ producer: data?.producer,
1876
+ fallbackReason: data?.fallbackReason,
1877
+ readsDigest: data?.readsDigest,
1878
+ equalsKind: data?.equalsKind,
1879
+ changed: data?.changed,
1880
+ evalMs: data?.evalMs
1881
+ };
1882
+ const metaProjection2 = projectJsonValue(metaInput);
1883
+ options?.onMetaProjection?.({
1884
+ stats: metaProjection2.stats,
1885
+ downgrade: metaProjection2.downgrade
1886
+ });
1887
+ downgrade = mergeDowngrade2(downgrade, metaProjection2.downgrade);
1888
+ return withDowngrade({
1889
+ ...base,
1890
+ kind: "devtools",
1891
+ label: event.type,
1892
+ meta: metaProjection2.value
1893
+ });
1894
+ }
1895
+ if (event.type === "trace:exec-vm") {
1896
+ const data = event.data;
1897
+ const metaInput = {
1898
+ version: data?.version,
1899
+ stage: data?.stage,
1900
+ hit: data?.hit,
1901
+ reasonCode: data?.reasonCode ?? data?.reason,
1902
+ reasonDetail: data?.reasonDetail,
1903
+ execIrVersion: data?.execIrVersion,
1904
+ execIrHash: data?.execIrHash,
1905
+ serviceId: data?.serviceId,
1906
+ implId: data?.implId
1907
+ };
1908
+ const metaProjection2 = projectJsonValue(metaInput);
1909
+ options?.onMetaProjection?.({
1910
+ stats: metaProjection2.stats,
1911
+ downgrade: metaProjection2.downgrade
1912
+ });
1913
+ downgrade = mergeDowngrade2(downgrade, metaProjection2.downgrade);
1914
+ return withDowngrade({
1915
+ ...base,
1916
+ kind: "devtools",
1917
+ label: event.type,
1918
+ meta: metaProjection2.value
1919
+ });
1920
+ }
1921
+ if (event.type === "trace:trait:converge") {
1922
+ const resolveDirtyRootPaths = (args) => {
1923
+ const resolve2 = options?.resolveConvergeStaticIr;
1924
+ if (!resolve2) return void 0;
1925
+ const digest = args.staticIrDigest;
1926
+ if (typeof digest !== "string" || digest.length === 0) return void 0;
1927
+ const rootIds = args.rootIds;
1928
+ if (!Array.isArray(rootIds) || rootIds.length === 0) return void 0;
1929
+ const ir = resolve2(digest);
1930
+ const fieldPaths = ir?.fieldPaths;
1931
+ if (!Array.isArray(fieldPaths) || fieldPaths.length === 0) return void 0;
1932
+ const out = [];
1933
+ for (const id of rootIds) {
1934
+ if (typeof id !== "number" || !Number.isFinite(id)) continue;
1935
+ const idx = Math.floor(id);
1936
+ if (idx < 0 || idx >= fieldPaths.length) continue;
1937
+ const path = fieldPaths[idx];
1938
+ if (Array.isArray(path)) {
1939
+ out.push(path);
1940
+ }
1941
+ }
1942
+ return out.length > 0 ? out : void 0;
1943
+ };
1944
+ const enrichDirtyRootPaths = (value) => {
1945
+ if (!value || typeof value !== "object" || Array.isArray(value)) return value;
1946
+ const anyValue = value;
1947
+ const dirty = anyValue.dirty;
1948
+ if (!dirty || typeof dirty !== "object" || Array.isArray(dirty)) return value;
1949
+ const dirtyRootPaths = resolveDirtyRootPaths({
1950
+ staticIrDigest: anyValue.staticIrDigest,
1951
+ rootIds: dirty?.rootIds
1952
+ });
1953
+ if (!dirtyRootPaths) return value;
1954
+ return {
1955
+ ...anyValue,
1956
+ dirty: {
1957
+ ...dirty,
1958
+ rootPaths: dirtyRootPaths
1959
+ }
1960
+ };
1961
+ };
1962
+ const stripHeavyLight = (value) => {
1963
+ if (!value || typeof value !== "object" || Array.isArray(value)) return value;
1964
+ const anyValue = value;
1965
+ const dirty = anyValue.dirty;
1966
+ const dirtyRootPaths = resolveDirtyRootPaths({
1967
+ staticIrDigest: anyValue.staticIrDigest,
1968
+ rootIds: dirty?.rootIds
1969
+ });
1970
+ const dirtySlim = dirty && typeof dirty === "object" && !Array.isArray(dirty) ? {
1971
+ dirtyAll: dirty.dirtyAll,
1972
+ ...typeof dirty.reason === "string" ? { reason: dirty.reason } : null,
1973
+ ...Array.isArray(dirty.rootIds) ? { rootIds: dirty.rootIds } : null,
1974
+ ...typeof dirty.rootIdsTruncated === "boolean" ? { rootIdsTruncated: dirty.rootIdsTruncated } : null,
1975
+ ...dirtyRootPaths ? { rootPaths: dirtyRootPaths } : null
1976
+ } : void 0;
1977
+ const { top3, dirtyRoots, ...rest } = anyValue;
1978
+ return dirtySlim ? { ...rest, dirty: dirtySlim } : rest;
1979
+ };
1980
+ const stripHeavySampled = (value) => {
1981
+ if (!value || typeof value !== "object" || Array.isArray(value)) return value;
1982
+ const anyValue = value;
1983
+ const dirty = anyValue.dirty;
1984
+ const dirtySlim = dirty && typeof dirty === "object" && !Array.isArray(dirty) ? {
1985
+ dirtyAll: dirty.dirtyAll,
1986
+ ...typeof dirty.reason === "string" ? { reason: dirty.reason } : null
1987
+ } : void 0;
1988
+ const { dirtyRoots, ...rest } = anyValue;
1989
+ return dirtySlim ? { ...rest, dirty: dirtySlim } : rest;
1990
+ };
1991
+ const data = event.data;
1992
+ const metaInput = diagnosticsLevel2 === "light" ? stripHeavyLight(data) : diagnosticsLevel2 === "sampled" ? stripHeavySampled(data) : enrichDirtyRootPaths(data);
1993
+ const metaProjection2 = projectJsonValue(metaInput);
1994
+ options?.onMetaProjection?.({
1995
+ stats: metaProjection2.stats,
1996
+ downgrade: metaProjection2.downgrade
1997
+ });
1998
+ downgrade = mergeDowngrade2(downgrade, metaProjection2.downgrade);
1999
+ return withDowngrade({
2000
+ ...base,
2001
+ kind: "trait:converge",
2002
+ label: "trait:converge",
2003
+ meta: metaProjection2.value
2004
+ });
2005
+ }
2006
+ if (event.type === "trace:trait:check") {
2007
+ const stripHeavy = (value) => {
2008
+ if (!value || typeof value !== "object" || Array.isArray(value)) return value;
2009
+ const anyValue = value;
2010
+ const degraded = anyValue.degraded;
2011
+ const degradedSlim = degraded && typeof degraded === "object" && !Array.isArray(degraded) ? { kind: degraded.kind } : void 0;
2012
+ const { degraded: _degraded, ...rest } = anyValue;
2013
+ return degradedSlim ? { ...rest, degraded: degradedSlim } : rest;
2014
+ };
2015
+ const data = event.data;
2016
+ const metaInput = isLightLike ? stripHeavy(data) : data;
2017
+ const metaProjection2 = projectJsonValue(metaInput);
2018
+ options?.onMetaProjection?.({
2019
+ stats: metaProjection2.stats,
2020
+ downgrade: metaProjection2.downgrade
2021
+ });
2022
+ downgrade = mergeDowngrade2(downgrade, metaProjection2.downgrade);
2023
+ return withDowngrade({
2024
+ ...base,
2025
+ kind: "trait:check",
2026
+ label: "trait:check",
2027
+ meta: metaProjection2.value
2028
+ });
2029
+ }
2030
+ if (event.type === "trace:trait:validate") {
2031
+ const data = event.data;
2032
+ const metaProjection2 = projectJsonValue(data);
2033
+ options?.onMetaProjection?.({
2034
+ stats: metaProjection2.stats,
2035
+ downgrade: metaProjection2.downgrade
2036
+ });
2037
+ downgrade = mergeDowngrade2(downgrade, metaProjection2.downgrade);
2038
+ return withDowngrade({
2039
+ ...base,
2040
+ kind: "trait:validate",
2041
+ label: "trait:validate",
2042
+ meta: metaProjection2.value
2043
+ });
2044
+ }
2045
+ if (event.type === "trace:module:traits") {
2046
+ const data = event.data;
2047
+ const metaInput = isLightLike ? {
2048
+ digest: data?.digest,
2049
+ count: data?.count
2050
+ } : {
2051
+ digest: data?.digest,
2052
+ count: data?.count,
2053
+ traits: data?.traits,
2054
+ provenanceIndex: data?.provenanceIndex
2055
+ };
2056
+ const metaProjection2 = projectJsonValue(metaInput);
2057
+ options?.onMetaProjection?.({
2058
+ stats: metaProjection2.stats,
2059
+ downgrade: metaProjection2.downgrade
2060
+ });
2061
+ downgrade = mergeDowngrade2(downgrade, metaProjection2.downgrade);
2062
+ return withDowngrade({
2063
+ ...base,
2064
+ kind: "devtools",
2065
+ label: event.type,
2066
+ meta: metaProjection2.value
2067
+ });
2068
+ }
2069
+ if (event.type === "trace:module:traits:conflict") {
2070
+ const data = event.data;
2071
+ const metaInput = isLightLike ? {
2072
+ conflictCount: data?.conflictCount,
2073
+ traitIds: data?.traitIds
2074
+ } : {
2075
+ conflictCount: data?.conflictCount,
2076
+ conflicts: data?.conflicts
2077
+ };
2078
+ const metaProjection2 = projectJsonValue(metaInput);
2079
+ options?.onMetaProjection?.({
2080
+ stats: metaProjection2.stats,
2081
+ downgrade: metaProjection2.downgrade
2082
+ });
2083
+ downgrade = mergeDowngrade2(downgrade, metaProjection2.downgrade);
2084
+ return withDowngrade({
2085
+ ...base,
2086
+ kind: "devtools",
2087
+ label: event.type,
2088
+ meta: metaProjection2.value
2089
+ });
2090
+ }
2091
+ if (event.type === "trace:module:descriptor") {
2092
+ const data = event.data;
2093
+ const metaInput = isLightLike ? {
2094
+ id: data?.id,
2095
+ traits: data?.traits,
2096
+ source: data?.source
2097
+ } : { data };
2098
+ const metaProjection2 = projectJsonValue(metaInput);
2099
+ options?.onMetaProjection?.({
2100
+ stats: metaProjection2.stats,
2101
+ downgrade: metaProjection2.downgrade
2102
+ });
2103
+ downgrade = mergeDowngrade2(downgrade, metaProjection2.downgrade);
2104
+ return withDowngrade({
2105
+ ...base,
2106
+ kind: "devtools",
2107
+ label: event.type,
2108
+ meta: metaProjection2.value
2109
+ });
2110
+ }
2111
+ if (event.type === "trace:effectop") {
2112
+ const data = event.data;
2113
+ const opMeta = data?.meta;
2114
+ const opKind = data?.kind ?? "service";
2115
+ const label = typeof data?.name === "string" ? data.name : "effectop";
2116
+ const moduleId2 = typeof opMeta?.moduleId === "string" ? opMeta.moduleId : moduleId;
2117
+ const txnId2 = typeof opMeta?.txnId === "string" && opMeta.txnId.length > 0 ? opMeta.txnId : base.txnId;
2118
+ const txnSeq2 = typeof opMeta?.txnSeq === "number" && Number.isFinite(opMeta.txnSeq) && opMeta.txnSeq >= 0 ? Math.floor(opMeta.txnSeq) : base.txnSeq;
2119
+ const metaInput = isLightLike ? {
2120
+ id: data?.id,
2121
+ kind: data?.kind,
2122
+ name: data?.name,
2123
+ meta: opMeta
2124
+ } : {
2125
+ id: data?.id,
2126
+ kind: data?.kind,
2127
+ name: data?.name,
2128
+ payload: data?.payload,
2129
+ meta: opMeta
2130
+ };
2131
+ const metaProjection2 = projectJsonValue(metaInput);
2132
+ options?.onMetaProjection?.({
2133
+ stats: metaProjection2.stats,
2134
+ downgrade: metaProjection2.downgrade
2135
+ });
2136
+ downgrade = mergeDowngrade2(downgrade, metaProjection2.downgrade);
2137
+ return withDowngrade({
2138
+ ...base,
2139
+ moduleId: moduleId2,
2140
+ txnId: txnId2,
2141
+ txnSeq: txnSeq2,
2142
+ kind: opKind,
2143
+ label,
2144
+ meta: metaProjection2.value
2145
+ });
2146
+ }
2147
+ const metaProjection = projectJsonValue(
2148
+ isLightLike ? {
2149
+ data: void 0
2150
+ } : {
2151
+ data: event.data
2152
+ }
2153
+ );
2154
+ options?.onMetaProjection?.({
2155
+ stats: metaProjection.stats,
2156
+ downgrade: metaProjection.downgrade
2157
+ });
2158
+ downgrade = mergeDowngrade2(downgrade, metaProjection.downgrade);
2159
+ return withDowngrade({
2160
+ ...base,
2161
+ kind: "devtools",
2162
+ label: event.type,
2163
+ meta: metaProjection.value
2164
+ });
2165
+ }
2166
+ }
2167
+ };
2168
+
2169
+ // src/internal/observability/evidenceCollector.ts
2170
+ var EvidenceCollectorTagImpl = class extends import_effect8.Context.Tag("@logixjs/core/EvidenceCollector")() {
2171
+ };
2172
+ var EvidenceCollectorTag = EvidenceCollectorTagImpl;
2173
+ var evidenceCollectorLayer = (collector) => import_effect8.Layer.succeed(EvidenceCollectorTag, collector);
2174
+ var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
2175
+ var makeEvidenceCollector = (session) => {
2176
+ const sink = makeEvidenceSink(session);
2177
+ const convergeStaticIrByDigest = /* @__PURE__ */ new Map();
2178
+ let kernelImplementationRef;
2179
+ let runtimeServicesEvidence;
2180
+ const exportBudget = {
2181
+ dropped: 0,
2182
+ oversized: 0,
2183
+ nonSerializable: 0
2184
+ };
2185
+ const debugSink = {
2186
+ record: (event) => import_effect8.Effect.gen(function* () {
2187
+ const level = yield* import_effect8.FiberRef.get(currentDiagnosticsLevel);
2188
+ const instanceIdRaw = event.instanceId;
2189
+ const instanceId = typeof instanceIdRaw === "string" && instanceIdRaw.length > 0 ? instanceIdRaw : "unknown";
2190
+ const eventSeq = level === "off" ? void 0 : session.local.nextSeq("eventSeq", instanceId);
2191
+ const ref = toRuntimeDebugEventRef(event, {
2192
+ diagnosticsLevel: level,
2193
+ eventSeq,
2194
+ onMetaProjection: ({ stats }) => {
2195
+ exportBudget.dropped += stats.dropped;
2196
+ exportBudget.oversized += stats.oversized;
2197
+ }
2198
+ });
2199
+ if (!ref) return;
2200
+ const projected = projectJsonValue(ref);
2201
+ exportBudget.dropped += projected.stats.dropped;
2202
+ exportBudget.oversized += projected.stats.oversized;
2203
+ exportBudget.nonSerializable += projected.stats.nonSerializable;
2204
+ sink.record("debug:event", projected.value, {
2205
+ timestamp: ref.timestamp
2206
+ });
2207
+ })
2208
+ };
2209
+ const registerConvergeStaticIr = (staticIr) => {
2210
+ if (!isRecord3(staticIr)) return;
2211
+ const digest = staticIr.staticIrDigest;
2212
+ if (typeof digest !== "string" || digest.length === 0) return;
2213
+ const projected = projectJsonValue(staticIr);
2214
+ exportBudget.dropped += projected.stats.dropped;
2215
+ exportBudget.oversized += projected.stats.oversized;
2216
+ exportBudget.nonSerializable += projected.stats.nonSerializable;
2217
+ convergeStaticIrByDigest.set(digest, projected.value);
2218
+ };
2219
+ const setKernelImplementationRef = (ref) => {
2220
+ const projected = projectJsonValue(ref);
2221
+ exportBudget.dropped += projected.stats.dropped;
2222
+ exportBudget.oversized += projected.stats.oversized;
2223
+ exportBudget.nonSerializable += projected.stats.nonSerializable;
2224
+ kernelImplementationRef = projected.value;
2225
+ };
2226
+ const setRuntimeServicesEvidence = (evidence) => {
2227
+ const projected = projectJsonValue(evidence);
2228
+ exportBudget.dropped += projected.stats.dropped;
2229
+ exportBudget.oversized += projected.stats.oversized;
2230
+ exportBudget.nonSerializable += projected.stats.nonSerializable;
2231
+ runtimeServicesEvidence = projected.value;
2232
+ };
2233
+ const exportEvidencePackage2 = (options) => {
2234
+ const convergeSummary = convergeStaticIrByDigest.size > 0 ? {
2235
+ staticIrByDigest: Object.fromEntries(convergeStaticIrByDigest)
2236
+ } : void 0;
2237
+ const runtimeSummary = kernelImplementationRef != null || runtimeServicesEvidence != null ? {
2238
+ ...kernelImplementationRef != null ? { kernelImplementationRef } : {},
2239
+ ...runtimeServicesEvidence != null ? { services: runtimeServicesEvidence } : {}
2240
+ } : void 0;
2241
+ const summary = convergeSummary != null || runtimeSummary != null ? {
2242
+ ...convergeSummary != null ? { converge: convergeSummary } : {},
2243
+ ...runtimeSummary != null ? { runtime: runtimeSummary } : {}
2244
+ } : void 0;
2245
+ return sink.export({
2246
+ maxEvents: options?.maxEvents,
2247
+ summary
2248
+ });
2249
+ };
2250
+ const clear = () => {
2251
+ sink.clear();
2252
+ convergeStaticIrByDigest.clear();
2253
+ kernelImplementationRef = void 0;
2254
+ runtimeServicesEvidence = void 0;
2255
+ exportBudget.dropped = 0;
2256
+ exportBudget.oversized = 0;
2257
+ exportBudget.nonSerializable = 0;
2258
+ };
2259
+ return {
2260
+ session,
2261
+ debugSink,
2262
+ registerConvergeStaticIr,
2263
+ setKernelImplementationRef,
2264
+ setRuntimeServicesEvidence,
2265
+ exportEvidencePackage: exportEvidencePackage2,
2266
+ clear
2267
+ };
2268
+ };
2269
+
2270
+ // src/internal/runtime/core/RuntimeKernel.ts
2271
+ var import_effect9 = require("effect");
2272
+ var RuntimeServicesRuntimeConfigTagImpl = class extends import_effect9.Context.Tag("@logixjs/core/RuntimeServicesRuntimeConfig")() {
2273
+ };
2274
+ var RuntimeServicesProviderOverridesTagImpl = class extends import_effect9.Context.Tag("@logixjs/core/RuntimeServicesProviderOverrides")() {
2275
+ };
2276
+ var RuntimeServicesInstanceOverridesTagImpl = class extends import_effect9.Context.Tag("@logixjs/core/RuntimeServicesInstanceOverrides")() {
2277
+ };
2278
+ var RuntimeServicesInstanceOverridesTag = RuntimeServicesInstanceOverridesTagImpl;
2279
+ var FullCutoverGateModeTagImpl = class extends import_effect9.Context.Tag("@logixjs/core/FullCutoverGateMode")() {
2280
+ };
2281
+ var RuntimeServicesRegistryTagImpl = class extends import_effect9.Context.Tag("@logixjs/core/RuntimeServicesRegistry")() {
2282
+ };
2283
+ var RUNTIME_SERVICES_EVIDENCE = /* @__PURE__ */ Symbol.for("@logixjs/core/runtimeServicesEvidence");
2284
+ var formatScope = (moduleId, instanceId) => {
2285
+ const m = typeof moduleId === "string" && moduleId.length > 0 ? moduleId : "unknown";
2286
+ const i = typeof instanceId === "string" && instanceId.length > 0 ? instanceId : "unknown";
2287
+ return `moduleId=${m}, instanceId=${i}`;
2288
+ };
2289
+ var getRuntimeServicesEvidence = (runtime) => {
2290
+ const scope = runtime;
2291
+ const evidence = runtime[RUNTIME_SERVICES_EVIDENCE];
2292
+ if (!evidence) {
2293
+ const msg = isDevEnv() ? [
2294
+ "[MissingRuntimeServicesEvidence] Runtime services evidence not installed on ModuleRuntime instance.",
2295
+ `scope: ${formatScope(scope.moduleId, scope.instanceId)}`,
2296
+ "fix:",
2297
+ "- Ensure ModuleRuntime.make assembles RuntimeKernel and attaches evidence (020 US2).",
2298
+ "- If you created a mock runtime for tests, attach evidence or avoid calling evidence-only APIs."
2299
+ ].join("\n") : "Runtime services evidence not installed";
2300
+ throw new Error(msg);
2301
+ }
2302
+ const runtimeInstanceId = scope.instanceId;
2303
+ if (typeof runtimeInstanceId === "string" && runtimeInstanceId.length > 0 && runtimeInstanceId !== evidence.instanceId) {
2304
+ throw new Error(
2305
+ isDevEnv() ? [
2306
+ "[InconsistentRuntimeServicesEvidence] Runtime services evidence instanceId mismatch.",
2307
+ `runtime: ${formatScope(scope.moduleId, runtimeInstanceId)}`,
2308
+ `evidence: ${formatScope(evidence.moduleId, evidence.instanceId)}`
2309
+ ].join("\n") : "Runtime services evidence mismatch"
2310
+ );
2311
+ }
2312
+ return evidence;
2313
+ };
2314
+
2315
+ // src/internal/runtime/core/ConvergeStaticIrCollector.ts
2316
+ var import_effect10 = require("effect");
2317
+ var currentConvergeStaticIrCollectors = import_effect10.FiberRef.unsafeMake([]);
2318
+ var appendConvergeStaticIrCollectors = (collectors) => import_effect10.Layer.fiberRefLocallyScopedWith(currentConvergeStaticIrCollectors, (current) => [
2319
+ ...current,
2320
+ ...collectors
2321
+ ]);
2322
+
2323
+ // src/internal/observability/trialRunModule.ts
2324
+ var import_effect32 = require("effect");
2325
+
2326
+ // src/internal/platform/BuildEnv.ts
2327
+ var import_effect13 = require("effect");
2328
+
2329
+ // src/internal/platform/ConstructionGuard.ts
2330
+ var import_effect11 = require("effect");
2331
+
2332
+ // src/internal/platform/RuntimeHost.ts
2333
+ var import_effect12 = require("effect");
2334
+ var detectKind = () => {
2335
+ const isBrowser2 = typeof window !== "undefined" && typeof document !== "undefined";
2336
+ if (isBrowser2) return "browser";
2337
+ const isNode = typeof process !== "undefined" && typeof process?.versions?.node === "string";
2338
+ if (isNode) return "node";
2339
+ return "unknown";
2340
+ };
2341
+ var make = (kind) => ({
2342
+ kind,
2343
+ isNode: kind === "node",
2344
+ isBrowser: kind === "browser"
2345
+ });
2346
+ var RuntimeHost = class extends import_effect12.Context.Tag("@logixjs/RuntimeHost")() {
2347
+ };
2348
+ var layer = (service) => import_effect12.Layer.succeed(RuntimeHost, service);
2349
+ var defaultLayer = layer(make(detectKind()));
2350
+
2351
+ // src/internal/runtime/core/KernelRef.ts
2352
+ var import_effect14 = require("effect");
2353
+ var isKernelId = (value) => typeof value === "string" && value.length > 0 && /^[a-z0-9-]+$/.test(value);
2354
+ var defaultKernelImplementationRef = {
2355
+ kernelId: "core",
2356
+ packageName: "@logixjs/core"
2357
+ };
2358
+ var normalizeKernelImplementationRef = (value, fallback = defaultKernelImplementationRef) => {
2359
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return fallback;
2360
+ const v = value;
2361
+ if (!isKernelId(v.kernelId)) return fallback;
2362
+ if (typeof v.packageName !== "string" || v.packageName.length === 0) return fallback;
2363
+ return {
2364
+ kernelId: v.kernelId,
2365
+ packageName: v.packageName,
2366
+ ...typeof v.packageVersion === "string" && v.packageVersion.length > 0 ? { packageVersion: v.packageVersion } : {},
2367
+ ...typeof v.buildId === "string" && v.buildId.length > 0 ? { buildId: v.buildId } : {},
2368
+ ...Array.isArray(v.capabilities) && v.capabilities.every((c) => typeof c === "string") ? { capabilities: v.capabilities } : {}
2369
+ };
2370
+ };
2371
+ var KernelImplementationRefTagImpl = class extends import_effect14.Context.Tag("@logixjs/core/KernelImplementationRef")() {
2372
+ };
2373
+ var KERNEL_IMPLEMENTATION_REF = /* @__PURE__ */ Symbol.for("@logixjs/core/kernelImplementationRef");
2374
+ var formatScope2 = (moduleId, instanceId) => {
2375
+ const m = typeof moduleId === "string" && moduleId.length > 0 ? moduleId : "unknown";
2376
+ const i = typeof instanceId === "string" && instanceId.length > 0 ? instanceId : "unknown";
2377
+ return `moduleId=${m}, instanceId=${i}`;
2378
+ };
2379
+ var getKernelImplementationRef = (runtime) => {
2380
+ const scope = runtime;
2381
+ const ref = runtime[KERNEL_IMPLEMENTATION_REF];
2382
+ if (!ref) {
2383
+ const msg = isDevEnv() ? [
2384
+ "[MissingKernelImplementationRef] KernelImplementationRef not installed on ModuleRuntime instance.",
2385
+ `scope: ${formatScope2(scope.moduleId, scope.instanceId)}`,
2386
+ "fix:",
2387
+ "- Ensure ModuleRuntime.make installs KernelImplementationRef (045 kernel contract).",
2388
+ "- If you created a mock runtime for tests, attach KernelImplementationRef or avoid calling kernel-only APIs."
2389
+ ].join("\n") : "KernelImplementationRef not installed";
2390
+ throw new Error(msg);
2391
+ }
2392
+ return ref;
2393
+ };
2394
+
2395
+ // src/internal/runtime/core/runner/ProgramRunner.kernel.ts
2396
+ var import_effect27 = require("effect");
2397
+
2398
+ // src/internal/runtime/core/BoundApiRuntime.ts
2399
+ var import_effect24 = require("effect");
2400
+
2401
+ // src/internal/runtime/core/TaskRunner.ts
2402
+ var import_effect15 = require("effect");
2403
+ var inSyncTransactionFiber = import_effect15.FiberRef.unsafeMake(false);
2404
+ var forceSourceRefresh = import_effect15.FiberRef.unsafeMake(false);
2405
+
2406
+ // src/internal/runtime/core/mutativePatches.ts
2407
+ var import_mutative = require("mutative");
2408
+
2409
+ // src/internal/runtime/core/FlowRuntime.ts
2410
+ var import_effect17 = require("effect");
2411
+
2412
+ // src/internal/effect-op.ts
2413
+ var import_effect16 = require("effect");
2414
+
2415
+ // src/internal/runtime/core/MatchBuilder.ts
2416
+ var import_effect18 = require("effect");
2417
+
2418
+ // src/internal/runtime/core/Platform.ts
2419
+ var import_effect19 = require("effect");
2420
+ var Tag = import_effect19.Context.GenericTag("@logixjs/Platform");
2421
+
2422
+ // src/internal/runtime/core/Lifecycle.ts
2423
+ var import_effect20 = require("effect");
2424
+ var LifecycleContext = import_effect20.Context.GenericTag("@logixjs/LifecycleManager");
2425
+
2426
+ // src/internal/runtime/core/LogicDiagnostics.ts
2427
+ var import_effect21 = require("effect");
2428
+ var LogicPhaseServiceTag = import_effect21.Context.GenericTag("@logixjs/LogicPhaseService");
2429
+ var LogicUnitServiceTag = class extends import_effect21.Context.Tag("@logixjs/LogicUnitService")() {
2430
+ };
2431
+
2432
+ // src/internal/root.ts
2433
+ var import_effect23 = require("effect");
2434
+
2435
+ // src/internal/runtime/core/RootContext.ts
2436
+ var import_effect22 = require("effect");
2437
+ var RootContextTagImpl = class extends import_effect22.Context.Tag("@logixjs/core/RootContext")() {
2438
+ };
2439
+
2440
+ // src/internal/runtime/core/runner/ProgramRunner.closeScope.ts
2441
+ var import_effect25 = require("effect");
2442
+
2443
+ // src/internal/runtime/core/runner/ProgramRunner.signals.ts
2444
+ var import_effect26 = require("effect");
2445
+
2446
+ // src/internal/runtime/Runtime.ts
2447
+ var import_effect31 = require("effect");
2448
+
2449
+ // src/internal/runtime/AppRuntime.ts
2450
+ var import_effect30 = require("effect");
2451
+
2452
+ // src/internal/runtime/core/process/ProcessRuntime.ts
2453
+ var import_effect29 = require("effect");
2454
+
2455
+ // src/internal/runtime/core/process/concurrency.ts
2456
+ var import_effect28 = require("effect");
2457
+
2458
+ // src/internal/runtime/core/process/events.ts
2459
+ var PROCESS_EVENT_MAX_BYTES = 4 * 1024;
2460
+
2461
+ // src/internal/runtime/core/process/selectorSchema.ts
2462
+ var SchemaAST = __toESM(require("effect/SchemaAST"), 1);
2463
+
2464
+ // src/internal/runtime/core/process/ProcessRuntime.ts
2465
+ var ProcessRuntimeTag = class extends import_effect29.Context.Tag("@logixjs/core/ProcessRuntime")() {
2466
+ };
2467
+ var currentProcessTrigger = import_effect29.FiberRef.unsafeMake(void 0);
2468
+ var currentProcessEventBudget = import_effect29.FiberRef.unsafeMake(
2469
+ void 0
2470
+ );
2471
+
2472
+ // src/internal/observability/artifacts/collect.ts
2473
+ var defaultArtifactBudgetBytes = 50 * 1024;
2474
+
2475
+ // src/internal/observability/trialRun.ts
2476
+ var defaultHost = () => {
2477
+ if (typeof window !== "undefined" && typeof document !== "undefined") return "browser";
2478
+ return "node";
2479
+ };
2480
+ var trialRun = (program, options) => import_effect33.Effect.gen(function* () {
2481
+ const session = makeRunSession({
2482
+ runId: options?.runId,
2483
+ source: options?.source ?? { host: defaultHost(), label: "trial-run" },
2484
+ startedAt: options?.startedAt
2485
+ });
2486
+ const collector = makeEvidenceCollector(session);
2487
+ const convergeCollector = {
2488
+ register: (ir) => {
2489
+ collector.registerConvergeStaticIr(ir);
2490
+ }
2491
+ };
2492
+ const sinksLayer = appendSinks([collector.debugSink]);
2493
+ const diagnosticsLayer = diagnosticsLevel(options?.diagnosticsLevel ?? "light");
2494
+ const convergeLayer = appendConvergeStaticIrCollectors([convergeCollector]);
2495
+ const collectorLayer = evidenceCollectorLayer(collector);
2496
+ const sessionLayer = runSessionLayer(session);
2497
+ const overridesLayer = options?.runtimeServicesInstanceOverrides != null ? import_effect33.Layer.succeed(
2498
+ RuntimeServicesInstanceOverridesTag,
2499
+ options.runtimeServicesInstanceOverrides
2500
+ ) : import_effect33.Layer.empty;
2501
+ const trialLayer = import_effect33.Layer.mergeAll(
2502
+ options?.layer ?? import_effect33.Layer.empty,
2503
+ sessionLayer,
2504
+ collectorLayer,
2505
+ overridesLayer,
2506
+ diagnosticsLayer,
2507
+ sinksLayer,
2508
+ convergeLayer
2509
+ );
2510
+ const scope = yield* import_effect33.Scope.make();
2511
+ const exit = yield* import_effect33.Effect.exit(program).pipe(import_effect33.Effect.provideService(import_effect33.Scope.Scope, scope), import_effect33.Effect.provide(trialLayer));
2512
+ yield* import_effect33.Scope.close(scope, exit);
2513
+ const evidence = collector.exportEvidencePackage({
2514
+ maxEvents: options?.maxEvents
2515
+ });
2516
+ return { session, exit, evidence };
2517
+ });
2518
+
2519
+ // src/internal/reflection/kernelContract.ts
2520
+ var resolveRootImpl = (root) => root?._tag === "ModuleImpl" ? root : root?.impl;
2521
+ var asNonEmptyString = (value) => typeof value === "string" && value.length > 0 ? value : void 0;
2522
+ var asNonNegInt = (value, fallback = 0) => {
2523
+ if (typeof value !== "number" || !Number.isFinite(value)) return fallback;
2524
+ const n = Math.floor(value);
2525
+ return n >= 0 ? n : fallback;
2526
+ };
2527
+ var isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
2528
+ var makeTraceEffectOpObserver = () => {
2529
+ return (op) => import_effect34.Effect.gen(function* () {
2530
+ if (op.meta?.policy?.disableObservers) {
2531
+ return yield* op.effect;
2532
+ }
2533
+ const meta = op.meta ?? {};
2534
+ const slimOp = {
2535
+ id: op.id,
2536
+ kind: op.kind,
2537
+ name: op.name,
2538
+ payload: op.payload,
2539
+ meta: op.meta
2540
+ };
2541
+ yield* record({
2542
+ type: "trace:effectop",
2543
+ moduleId: typeof meta.moduleId === "string" ? meta.moduleId : void 0,
2544
+ instanceId: typeof meta.instanceId === "string" ? meta.instanceId : void 0,
2545
+ runtimeLabel: typeof meta.runtimeLabel === "string" ? meta.runtimeLabel : void 0,
2546
+ txnSeq: typeof meta.txnSeq === "number" && Number.isFinite(meta.txnSeq) ? Math.floor(meta.txnSeq) : void 0,
2547
+ data: slimOp
2548
+ });
2549
+ return yield* op.effect;
2550
+ });
2551
+ };
2552
+ var extractRuntimeSummary = (evidence) => {
2553
+ const summary = evidence.summary;
2554
+ const runtime = summary?.runtime;
2555
+ const kernelImplementationRefRaw = runtime?.kernelImplementationRef;
2556
+ const kernelImplementationRef = normalizeKernelImplementationRef(kernelImplementationRefRaw);
2557
+ const services = runtime?.services;
2558
+ return {
2559
+ kernelImplementationRef,
2560
+ runtimeServicesEvidence: services
2561
+ };
2562
+ };
2563
+ var canonicalizeOpMeta = (opMetaRaw) => {
2564
+ if (!isRecord4(opMetaRaw)) return void 0;
2565
+ const out = {};
2566
+ for (const [k, v] of Object.entries(opMetaRaw)) {
2567
+ if (k === "instanceId" || k === "txnId" || k === "runtimeLabel" || k === "linkId") continue;
2568
+ if ((k === "deps" || k === "trace" || k === "tags") && Array.isArray(v) && v.every((x) => typeof x === "string")) {
2569
+ out[k] = v.slice().sort((a, b) => a.localeCompare(b));
2570
+ continue;
2571
+ }
2572
+ out[k] = v;
2573
+ }
2574
+ return out;
2575
+ };
2576
+ var extractKernelContractTraceOps = (evidence) => {
2577
+ const instanceMap = /* @__PURE__ */ new Map();
2578
+ let nextInstanceIndex = 0;
2579
+ const mapInstanceId = (raw) => {
2580
+ if (raw === "unknown") return "unknown";
2581
+ const existing = instanceMap.get(raw);
2582
+ if (existing) return existing;
2583
+ nextInstanceIndex += 1;
2584
+ const next = `i${nextInstanceIndex}`;
2585
+ instanceMap.set(raw, next);
2586
+ return next;
2587
+ };
2588
+ const ops = [];
2589
+ for (const e of evidence.events) {
2590
+ if (e.type !== "debug:event") continue;
2591
+ const payload = e.payload;
2592
+ if (!isRecord4(payload)) continue;
2593
+ const meta = payload.meta;
2594
+ const opMeta = meta?.meta;
2595
+ const opSeq = asNonNegInt(opMeta?.opSeq, -1);
2596
+ if (opSeq < 0) continue;
2597
+ const instanceIdRaw = asNonEmptyString(payload.instanceId) ?? "unknown";
2598
+ const instanceId = mapInstanceId(instanceIdRaw);
2599
+ const txnSeq = asNonNegInt(payload.txnSeq, 0);
2600
+ const moduleId = asNonEmptyString(payload.moduleId) ?? "unknown";
2601
+ const kind = asNonEmptyString(meta?.kind) ?? asNonEmptyString(payload.kind) ?? "unknown";
2602
+ const name = asNonEmptyString(meta?.name) ?? asNonEmptyString(payload.label) ?? "effectop";
2603
+ ops.push({
2604
+ anchor: { instanceId, txnSeq, opSeq },
2605
+ moduleId,
2606
+ kind,
2607
+ name,
2608
+ meta: canonicalizeOpMeta(opMeta)
2609
+ });
2610
+ }
2611
+ ops.sort((a, b) => {
2612
+ if (a.anchor.instanceId !== b.anchor.instanceId) return a.anchor.instanceId.localeCompare(b.anchor.instanceId);
2613
+ if (a.anchor.txnSeq !== b.anchor.txnSeq) return a.anchor.txnSeq - b.anchor.txnSeq;
2614
+ return a.anchor.opSeq - b.anchor.opSeq;
2615
+ });
2616
+ return ops;
2617
+ };
2618
+ var anchorKey = (a) => `${a.instanceId}::t${a.txnSeq}::o${a.opSeq}`;
2619
+ var diffKernelContractTraceOps = (before, after) => {
2620
+ const changes = [];
2621
+ const beforeByKey = /* @__PURE__ */ new Map();
2622
+ const afterByKey = /* @__PURE__ */ new Map();
2623
+ for (const op of before) {
2624
+ beforeByKey.set(anchorKey(op.anchor), op);
2625
+ }
2626
+ for (const op of after) {
2627
+ afterByKey.set(anchorKey(op.anchor), op);
2628
+ }
2629
+ const allKeys = Array.from(/* @__PURE__ */ new Set([...beforeByKey.keys(), ...afterByKey.keys()])).sort((a, b) => a.localeCompare(b));
2630
+ for (const key of allKeys) {
2631
+ const b = beforeByKey.get(key);
2632
+ const a = afterByKey.get(key);
2633
+ if (!b && a) {
2634
+ changes.push({
2635
+ code: "op.added",
2636
+ anchor: a.anchor,
2637
+ after: a
2638
+ });
2639
+ continue;
2640
+ }
2641
+ if (b && !a) {
2642
+ changes.push({
2643
+ code: "op.removed",
2644
+ anchor: b.anchor,
2645
+ before: b
2646
+ });
2647
+ continue;
2648
+ }
2649
+ if (!b || !a) continue;
2650
+ const bJson = stableStringify(b);
2651
+ const aJson = stableStringify(a);
2652
+ if (bJson !== aJson) {
2653
+ changes.push({
2654
+ code: "op.changed",
2655
+ anchor: b.anchor,
2656
+ before: b,
2657
+ after: a
2658
+ });
2659
+ }
2660
+ }
2661
+ const summary = {
2662
+ added: changes.filter((c) => c.code === "op.added").length,
2663
+ removed: changes.filter((c) => c.code === "op.removed").length,
2664
+ changed: changes.filter((c) => c.code === "op.changed").length
2665
+ };
2666
+ return { changes, summary };
2667
+ };
2668
+ var VERSION = "v1";
2669
+ var runOnce = (rootImpl, run2, options) => import_effect34.Effect.gen(function* () {
2670
+ const interaction = run2?.interaction;
2671
+ const program = import_effect34.Effect.gen(function* () {
2672
+ const ctx = yield* rootImpl.layer.pipe(import_effect34.Layer.build);
2673
+ const runtime = import_effect34.Context.get(ctx, rootImpl.module);
2674
+ if (interaction) {
2675
+ yield* interaction(runtime);
2676
+ }
2677
+ return runtime.instanceId;
2678
+ });
2679
+ const traceLayer = import_effect34.Layer.succeed(EffectOpMiddlewareTag, {
2680
+ stack: [makeTraceEffectOpObserver()]
2681
+ });
2682
+ const extraLayer = run2?.layer ? import_effect34.Layer.mergeAll(traceLayer, run2.layer) : traceLayer;
2683
+ const result = yield* trialRun(program, {
2684
+ runId: run2?.runId,
2685
+ diagnosticsLevel: options.diagnosticsLevel ?? "light",
2686
+ maxEvents: options.maxEvents,
2687
+ layer: extraLayer,
2688
+ runtimeServicesInstanceOverrides: run2?.runtimeServicesInstanceOverrides
2689
+ });
2690
+ const ok = import_effect34.Exit.isSuccess(result.exit);
2691
+ const error = import_effect34.Exit.isFailure(result.exit) && result.exit.cause != null ? (() => {
2692
+ const failure = import_effect34.Exit.isFailure(result.exit) ? result.exit.cause : void 0;
2693
+ const err = failure?._tag === "Die" ? failure.defect : failure;
2694
+ if (err instanceof Error) {
2695
+ return { name: err.name, message: err.message };
2696
+ }
2697
+ return { name: "UnknownError", message: String(err ?? "unknown") };
2698
+ })() : void 0;
2699
+ const runtimeSummary = extractRuntimeSummary(result.evidence);
2700
+ const traceOps = extractKernelContractTraceOps(result.evidence);
2701
+ const traceDigest = fnv1a32(stableStringify(traceOps));
2702
+ return {
2703
+ summary: {
2704
+ ok,
2705
+ kernelImplementationRef: runtimeSummary.kernelImplementationRef,
2706
+ runtimeServicesEvidence: runtimeSummary.runtimeServicesEvidence,
2707
+ trace: { digest: traceDigest, opCount: traceOps.length },
2708
+ ...error ? { error } : {}
2709
+ },
2710
+ traceOps
2711
+ };
2712
+ });
2713
+ var verifyKernelContract = (root, options) => import_effect34.Effect.gen(function* () {
2714
+ const rootImpl = resolveRootImpl(root);
2715
+ const beforeRun = yield* runOnce(rootImpl, options?.before, {
2716
+ diagnosticsLevel: options?.diagnosticsLevel,
2717
+ maxEvents: options?.maxEvents
2718
+ });
2719
+ const afterRun = yield* runOnce(rootImpl, options?.after, {
2720
+ diagnosticsLevel: options?.diagnosticsLevel,
2721
+ maxEvents: options?.maxEvents
2722
+ });
2723
+ const hasRunFailure = !beforeRun.summary.ok || !afterRun.summary.ok;
2724
+ const diff = hasRunFailure ? { changes: [{ code: "run.failure" }], summary: { added: 0, removed: 0, changed: 0 } } : diffKernelContractTraceOps(beforeRun.traceOps, afterRun.traceOps);
2725
+ const verdict = hasRunFailure || diff.changes.length > 0 ? "FAIL" : "PASS";
2726
+ return {
2727
+ version: VERSION,
2728
+ verdict,
2729
+ before: beforeRun.summary,
2730
+ after: afterRun.summary,
2731
+ changes: diff.changes,
2732
+ summary: diff.summary
2733
+ };
2734
+ });
2735
+
2736
+ // src/Kernel.ts
2737
+ var import_effect36 = require("effect");
2738
+
2739
+ // src/internal/runtime/core/FullCutoverGate.ts
2740
+ var CutoverCoverageMatrix = {
2741
+ version: "v1",
2742
+ requiredServiceIds: ["txnQueue", "operationRunner", "transaction", "dispatch"]
2743
+ };
2744
+ var expectedImplIdForKernel = (kernelId) => kernelId === "core" ? "builtin" : kernelId;
2745
+ var parseFallbackServiceIds = (overridesApplied) => {
2746
+ const out = /* @__PURE__ */ new Set();
2747
+ for (const entry of overridesApplied) {
2748
+ if (!entry.includes("(fallback=")) continue;
2749
+ const colon = entry.indexOf(":");
2750
+ if (colon < 0) continue;
2751
+ const eq = entry.indexOf("=", colon + 1);
2752
+ if (eq < 0) continue;
2753
+ const serviceId = entry.slice(colon + 1, eq);
2754
+ if (serviceId.length > 0) out.add(serviceId);
2755
+ }
2756
+ return Array.from(out).sort((a, b) => a.localeCompare(b));
2757
+ };
2758
+ var collectMissingServiceIds = (args) => {
2759
+ const bindingByServiceId = /* @__PURE__ */ new Map();
2760
+ for (const b of args.bindings) {
2761
+ bindingByServiceId.set(b.serviceId, b);
2762
+ }
2763
+ const missing = [];
2764
+ for (const serviceId of args.requiredServiceIds) {
2765
+ const binding = bindingByServiceId.get(serviceId);
2766
+ const implId = binding?.implId;
2767
+ if (!implId || implId !== args.expectedImplId) {
2768
+ missing.push(serviceId);
2769
+ }
2770
+ }
2771
+ return missing;
2772
+ };
2773
+ var evaluateFullCutoverGate = (args) => {
2774
+ const expectedImplId = expectedImplIdForKernel(args.requestedKernelId);
2775
+ const matrix = args.coverageMatrix ?? CutoverCoverageMatrix;
2776
+ const fallbackServiceIds = parseFallbackServiceIds(args.runtimeServicesEvidence.overridesApplied);
2777
+ const missingServiceIds = collectMissingServiceIds({
2778
+ expectedImplId,
2779
+ requiredServiceIds: matrix.requiredServiceIds,
2780
+ bindings: args.runtimeServicesEvidence.bindings
2781
+ });
2782
+ const fullyActivated = missingServiceIds.length === 0 && fallbackServiceIds.length === 0;
2783
+ const verdict = args.mode === "fullCutover" ? fullyActivated ? "PASS" : "FAIL" : "PASS";
2784
+ const moduleIdRaw = args.runtimeServicesEvidence.moduleId;
2785
+ const moduleId = typeof moduleIdRaw === "string" && moduleIdRaw.length > 0 ? moduleIdRaw : "unknown";
2786
+ const anchor = {
2787
+ moduleId,
2788
+ instanceId: args.runtimeServicesEvidence.instanceId,
2789
+ txnSeq: 0
2790
+ };
2791
+ const level = args.diagnosticsLevel ?? "off";
2792
+ return {
2793
+ version: "v1",
2794
+ mode: args.mode,
2795
+ requestedKernelId: args.requestedKernelId,
2796
+ verdict,
2797
+ fullyActivated,
2798
+ missingServiceIds,
2799
+ fallbackServiceIds,
2800
+ anchor,
2801
+ ...level === "off" ? {} : {
2802
+ details: {
2803
+ expectedImplId,
2804
+ bindings: args.runtimeServicesEvidence.bindings,
2805
+ overridesApplied: args.runtimeServicesEvidence.overridesApplied
2806
+ }
2807
+ }
2808
+ };
2809
+ };
2810
+
2811
+ // src/internal/runtime/core/RuntimeServiceBuiltins.ts
2812
+ var import_effect35 = require("effect");
2813
+ var RuntimeServiceBuiltinsTag = class extends import_effect35.Context.Tag("@logixjs/core/RuntimeServiceBuiltins")() {
2814
+ };
2815
+
2816
+ // src/Kernel.ts
2817
+ var evaluateFullCutoverGate2 = (args) => {
2818
+ return evaluateFullCutoverGate({
2819
+ mode: args.mode,
2820
+ requestedKernelId: args.requestedKernelId,
2821
+ runtimeServicesEvidence: args.runtimeServicesEvidence,
2822
+ coverageMatrix: args.coverageMatrix,
2823
+ diagnosticsLevel: args.diagnosticsLevel
2824
+ });
2825
+ };
2826
+ var KernelContractMetaAllowlist = [];
2827
+ var getRuntimeServicesEvidence2 = getRuntimeServicesEvidence;
2828
+ var getKernelImplementationRef2 = getKernelImplementationRef;
2829
+
2830
+ // src/Reflection.ts
2831
+ var resolveRootImpl2 = (root) => root?._tag === "ModuleImpl" ? root : root?.impl;
2832
+ var isRecord5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
2833
+ var stableJson = (value) => JSON.stringify(value) ?? "";
2834
+ var diffMetaKeys = (before, after) => {
2835
+ const b = isRecord5(before) ? before : {};
2836
+ const a = isRecord5(after) ? after : {};
2837
+ const keys = Array.from(/* @__PURE__ */ new Set([...Object.keys(b), ...Object.keys(a)])).sort((x, y) => x.localeCompare(y));
2838
+ const changed = [];
2839
+ for (const k of keys) {
2840
+ if (stableJson(b[k]) !== stableJson(a[k])) {
2841
+ changed.push(k);
2842
+ }
2843
+ }
2844
+ return changed;
2845
+ };
2846
+ var tryAllowlistKernelContractDiff = (args) => {
2847
+ if (args.allowlist.length === 0) {
2848
+ return { verdict: args.result.verdict, allowedDiffs: [] };
2849
+ }
2850
+ const allow = /* @__PURE__ */ new Map();
2851
+ for (const item of args.allowlist) {
2852
+ allow.set(item.metaKey, item.reason);
2853
+ }
2854
+ const allowedCounts = /* @__PURE__ */ new Map();
2855
+ for (const change of args.result.changes) {
2856
+ if (change.code !== "op.changed") {
2857
+ return { verdict: "FAIL", allowedDiffs: [] };
2858
+ }
2859
+ const before = change.before;
2860
+ const after = change.after;
2861
+ if (!isRecord5(before) || !isRecord5(after)) {
2862
+ return { verdict: "FAIL", allowedDiffs: [] };
2863
+ }
2864
+ const anchorBefore = before.anchor;
2865
+ const anchorAfter = after.anchor;
2866
+ if (stableJson(anchorBefore) !== stableJson(anchorAfter)) {
2867
+ return { verdict: "FAIL", allowedDiffs: [] };
2868
+ }
2869
+ if (stableJson(before.moduleId) !== stableJson(after.moduleId)) {
2870
+ return { verdict: "FAIL", allowedDiffs: [] };
2871
+ }
2872
+ if (stableJson(before.kind) !== stableJson(after.kind)) {
2873
+ return { verdict: "FAIL", allowedDiffs: [] };
2874
+ }
2875
+ if (stableJson(before.name) !== stableJson(after.name)) {
2876
+ return { verdict: "FAIL", allowedDiffs: [] };
2877
+ }
2878
+ const changed = diffMetaKeys(before.meta, after.meta);
2879
+ for (const metaKey of changed) {
2880
+ if (!allow.has(metaKey)) {
2881
+ return { verdict: "FAIL", allowedDiffs: [] };
2882
+ }
2883
+ allowedCounts.set(metaKey, (allowedCounts.get(metaKey) ?? 0) + 1);
2884
+ }
2885
+ }
2886
+ const allowedDiffs = Array.from(allowedCounts.entries()).map(([metaKey, count]) => ({
2887
+ metaKey,
2888
+ count,
2889
+ ...allow.get(metaKey) ? { reason: allow.get(metaKey) } : {}
2890
+ })).sort((a, b) => a.metaKey.localeCompare(b.metaKey));
2891
+ return { verdict: "PASS", allowedDiffs };
2892
+ };
2893
+ var extractManifest2 = (module2, options) => extractManifest(module2, options);
2894
+ var diffManifest2 = (before, after, options) => diffManifest(before, after, options);
2895
+ var exportStaticIr3 = (module2) => exportStaticIr2(module2);
2896
+ var verifyKernelContract2 = (module2, options) => verifyKernelContract(module2, options);
2897
+ var verifyFullCutoverGate = (module2, options) => import_effect37.Effect.gen(function* () {
2898
+ const rootImpl = resolveRootImpl2(module2);
2899
+ const contractDiagnosticsLevel = options?.diagnosticsLevel === "off" ? "light" : options?.diagnosticsLevel ?? "light";
2900
+ const contract = yield* verifyKernelContract(module2, {
2901
+ ...options,
2902
+ diagnosticsLevel: contractDiagnosticsLevel
2903
+ });
2904
+ const allowlistEnabled = options?.enableContractMetaAllowlist === true;
2905
+ const allowlist = allowlistEnabled ? KernelContractMetaAllowlist : [];
2906
+ const contractAllowed = tryAllowlistKernelContractDiff({ result: contract, allowlist });
2907
+ const contractVerdict = allowlistEnabled ? contractAllowed.verdict : contract.verdict;
2908
+ const gateRun = options?.gateAfter ?? options?.after;
2909
+ const gateProgram = import_effect37.Effect.gen(function* () {
2910
+ const ctx = yield* rootImpl.layer.pipe(import_effect37.Layer.build);
2911
+ const runtime = import_effect37.Context.get(ctx, rootImpl.module);
2912
+ if (gateRun?.interaction) {
2913
+ yield* gateRun.interaction(runtime);
2914
+ }
2915
+ return {
2916
+ kernelImplementationRef: getKernelImplementationRef2(runtime),
2917
+ runtimeServicesEvidence: getRuntimeServicesEvidence2(runtime)
2918
+ };
2919
+ });
2920
+ const gateResult = yield* trialRun(gateProgram, {
2921
+ runId: gateRun?.runId,
2922
+ diagnosticsLevel: options?.gateDiagnosticsLevel ?? "off",
2923
+ layer: gateRun?.layer,
2924
+ runtimeServicesInstanceOverrides: gateRun?.runtimeServicesInstanceOverrides
2925
+ });
2926
+ const gateValue = import_effect37.Exit.isSuccess(gateResult.exit) ? gateResult.exit.value : (() => {
2927
+ const msg = import_effect37.Exit.isFailure(gateResult.exit) ? String(gateResult.exit.cause ?? "trial-run failed") : "trial-run failed";
2928
+ throw new Error(msg);
2929
+ })();
2930
+ const gate = evaluateFullCutoverGate2({
2931
+ mode: options?.mode ?? "fullCutover",
2932
+ requestedKernelId: gateValue.kernelImplementationRef.kernelId,
2933
+ runtimeServicesEvidence: gateValue.runtimeServicesEvidence,
2934
+ diagnosticsLevel: options?.gateDiagnosticsLevel ?? "off"
2935
+ });
2936
+ const verdict = gate.verdict === "PASS" && contractVerdict === "PASS" ? "PASS" : "FAIL";
2937
+ return {
2938
+ version: "v1",
2939
+ verdict,
2940
+ gate,
2941
+ contract,
2942
+ contractVerdict,
2943
+ ...allowlistEnabled ? { allowedDiffs: contractAllowed.allowedDiffs } : {}
2944
+ };
2945
+ });
2946
+ // Annotate the CommonJS export names for ESM import in node:
2947
+ 0 && (module.exports = {
2948
+ diffManifest,
2949
+ exportStaticIr,
2950
+ extractManifest,
2951
+ verifyFullCutoverGate,
2952
+ verifyKernelContract
2953
+ });
2954
+ //# sourceMappingURL=Reflection.cjs.map