@logixjs/core 0.0.1 → 0.0.2

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 (300) hide show
  1. package/LICENSE +201 -0
  2. package/dist/{Bound-BN1DQ_lM.d.ts → Bound-CEa1ihvH.d.ts} +2 -2
  3. package/dist/{Bound-BPIfH9SS.d.cts → Bound-CNLNkC7c.d.cts} +2 -2
  4. package/dist/Bound.cjs +620 -163
  5. package/dist/Bound.cjs.map +1 -1
  6. package/dist/Bound.d.cts +3 -3
  7. package/dist/Bound.d.ts +3 -3
  8. package/dist/Bound.js +14 -14
  9. package/dist/{Debug-Bq8Sqjcr.d.cts → Debug-BhMYr-1i.d.cts} +3 -3
  10. package/dist/{Debug-B5q5Bkzx.d.ts → Debug-ByM7m4Ft.d.ts} +3 -3
  11. package/dist/Debug.cjs +553 -32
  12. package/dist/Debug.cjs.map +1 -1
  13. package/dist/Debug.d.cts +10 -8
  14. package/dist/Debug.d.ts +10 -8
  15. package/dist/Debug.js +12 -10
  16. package/dist/EffectOp.cjs.map +1 -1
  17. package/dist/EffectOp.js +2 -3
  18. package/dist/EffectOp.js.map +1 -1
  19. package/dist/Env.cjs +664 -6
  20. package/dist/Env.cjs.map +1 -1
  21. package/dist/Env.js +5 -2
  22. package/dist/ExternalStore-BAz83PVq.d.cts +60 -0
  23. package/dist/ExternalStore-BYWPbYs8.d.ts +60 -0
  24. package/dist/ExternalStore.cjs +746 -0
  25. package/dist/ExternalStore.cjs.map +1 -0
  26. package/dist/ExternalStore.d.cts +4 -0
  27. package/dist/ExternalStore.d.ts +4 -0
  28. package/dist/ExternalStore.js +19 -0
  29. package/dist/ExternalStore.js.map +1 -0
  30. package/dist/{Flow-1fZT8MpX.d.cts → Flow-BlSoMmhV.d.cts} +2 -2
  31. package/dist/{Flow-BhpjE22E.d.ts → Flow-CQSGve5c.d.ts} +2 -2
  32. package/dist/Flow.cjs +2 -2
  33. package/dist/Flow.cjs.map +1 -1
  34. package/dist/Flow.d.cts +4 -4
  35. package/dist/Flow.d.ts +4 -4
  36. package/dist/Flow.js +7 -8
  37. package/dist/{Handle-D_cLW1Z3.d.ts → Handle-B7PSmsrY.d.ts} +1 -1
  38. package/dist/{Handle-D8D1zPb_.d.cts → Handle-ByovhL-c.d.cts} +1 -1
  39. package/dist/Handle.d.cts +3 -3
  40. package/dist/Handle.d.ts +3 -3
  41. package/dist/{Kernel-CnGE1Fyk.d.ts → Kernel-DGSpS4GM.d.ts} +2 -2
  42. package/dist/{Kernel-8kC-jOda.d.cts → Kernel-DZAk-Mrn.d.cts} +2 -2
  43. package/dist/Kernel.cjs +680 -22
  44. package/dist/Kernel.cjs.map +1 -1
  45. package/dist/Kernel.d.cts +10 -8
  46. package/dist/Kernel.d.ts +10 -8
  47. package/dist/Kernel.js +7 -4
  48. package/dist/{Link-Db7975nU.d.ts → Link-Cm4eR9n0.d.ts} +10 -3
  49. package/dist/{Link-fX8x1eCK.d.cts → Link-DF8i8iWR.d.cts} +10 -3
  50. package/dist/Link.cjs +1128 -86
  51. package/dist/Link.cjs.map +1 -1
  52. package/dist/Link.d.cts +3 -3
  53. package/dist/Link.d.ts +3 -3
  54. package/dist/Link.js +30 -25
  55. package/dist/{Logic-DRh4sDZj.d.cts → Logic-BcQA0AvE.d.cts} +1 -1
  56. package/dist/{Logic-BRjEMr-W.d.ts → Logic-OotSE1xw.d.ts} +1 -1
  57. package/dist/Logic.d.cts +3 -3
  58. package/dist/Logic.d.ts +3 -3
  59. package/dist/{MatchBuilder-CJk5oCkR.d.cts → MatchBuilder-BNDJ8waF.d.ts} +1 -1
  60. package/dist/{MatchBuilder-0QOc-nlU.d.ts → MatchBuilder-CvZ5WY1B.d.cts} +1 -1
  61. package/dist/MatchBuilder.d.cts +4 -4
  62. package/dist/MatchBuilder.d.ts +4 -4
  63. package/dist/Middleware-D8tUDLv_.d.cts +100 -0
  64. package/dist/Middleware-DS7CbTTN.d.ts +100 -0
  65. package/dist/Middleware.cjs +461 -13
  66. package/dist/Middleware.cjs.map +1 -1
  67. package/dist/Middleware.d.cts +2 -86
  68. package/dist/Middleware.d.ts +2 -86
  69. package/dist/Middleware.js +13 -11
  70. package/dist/{Module-DnzluX2J.d.ts → Module-CFj0I2yE.d.ts} +45 -18
  71. package/dist/{Module-B_0xRDMR.d.cts → Module-DpXPW9EQ.d.cts} +45 -18
  72. package/dist/Module.cjs +8583 -5741
  73. package/dist/Module.cjs.map +1 -1
  74. package/dist/Module.d.cts +5 -4
  75. package/dist/Module.d.ts +5 -4
  76. package/dist/Module.js +32 -27
  77. package/dist/ModuleTag-BcVF6z7B.d.ts +113 -0
  78. package/dist/ModuleTag-DuZXo_NS.d.cts +113 -0
  79. package/dist/ModuleTag.cjs +2609 -1232
  80. package/dist/ModuleTag.cjs.map +1 -1
  81. package/dist/ModuleTag.d.cts +4 -4
  82. package/dist/ModuleTag.d.ts +4 -4
  83. package/dist/ModuleTag.js +28 -25
  84. package/dist/{Observability-cY4kLn0S.d.ts → Observability-D-ZWeEVb.d.ts} +22 -15
  85. package/dist/{Observability-COqEvp2C.d.cts → Observability-V7sRMYTh.d.cts} +22 -15
  86. package/dist/Observability.cjs +1938 -640
  87. package/dist/Observability.cjs.map +1 -1
  88. package/dist/Observability.d.cts +4 -4
  89. package/dist/Observability.d.ts +4 -4
  90. package/dist/Observability.js +21 -19
  91. package/dist/{Process-mL8fHDSB.d.cts → Process-B55aJMFk.d.cts} +29 -4
  92. package/dist/{Process-CM9xbMdP.d.ts → Process-DvhFEwUS.d.ts} +29 -4
  93. package/dist/Process.cjs +1122 -85
  94. package/dist/Process.cjs.map +1 -1
  95. package/dist/Process.d.cts +4 -3
  96. package/dist/Process.d.ts +4 -3
  97. package/dist/Process.js +27 -22
  98. package/dist/{ReadQuery-BlMwhe-F.d.ts → ReadQuery-C4vZ8Prc.d.ts} +2 -2
  99. package/dist/{ReadQuery-SinbStGF.d.ts → ReadQuery-CafjlJQo.d.cts} +1 -1
  100. package/dist/{ReadQuery-SinbStGF.d.cts → ReadQuery-CafjlJQo.d.ts} +1 -1
  101. package/dist/{ReadQuery-CL5XlXts.d.cts → ReadQuery-mc0NgrFV.d.cts} +2 -2
  102. package/dist/ReadQuery.cjs +3 -3
  103. package/dist/ReadQuery.cjs.map +1 -1
  104. package/dist/ReadQuery.d.cts +2 -2
  105. package/dist/ReadQuery.d.ts +2 -2
  106. package/dist/ReadQuery.js +3 -3
  107. package/dist/{Reflection-CQnKwPXj.d.ts → Reflection-C8xZ267q.d.ts} +88 -7
  108. package/dist/{Reflection-Kabo1mlU.d.cts → Reflection-DP7Vsv3f.d.cts} +88 -7
  109. package/dist/Reflection.cjs +2934 -1553
  110. package/dist/Reflection.cjs.map +1 -1
  111. package/dist/Reflection.d.cts +14 -11
  112. package/dist/Reflection.d.ts +14 -11
  113. package/dist/Reflection.js +26 -21
  114. package/dist/Resource.cjs +670 -12
  115. package/dist/Resource.cjs.map +1 -1
  116. package/dist/Resource.js +6 -3
  117. package/dist/Root.cjs +675 -17
  118. package/dist/Root.cjs.map +1 -1
  119. package/dist/Root.js +7 -3
  120. package/dist/{Runtime-CtyzZG4i.d.ts → Runtime-BWc9YfUB.d.ts} +37 -7
  121. package/dist/{Runtime-B-aL-f29.d.cts → Runtime-PShIC4DW.d.cts} +37 -7
  122. package/dist/Runtime.cjs +1899 -809
  123. package/dist/Runtime.cjs.map +1 -1
  124. package/dist/Runtime.d.cts +14 -11
  125. package/dist/Runtime.d.ts +14 -11
  126. package/dist/Runtime.js +33 -28
  127. package/dist/ScopeRegistry.cjs +668 -10
  128. package/dist/ScopeRegistry.cjs.map +1 -1
  129. package/dist/ScopeRegistry.js +6 -3
  130. package/dist/{StateTrait-OWhbj12c.d.cts → StateTrait-CQsDlXJm.d.cts} +23 -6
  131. package/dist/{StateTrait-BGsZghTz.d.ts → StateTrait-YvJzVDKl.d.ts} +23 -6
  132. package/dist/StateTrait.cjs +1475 -370
  133. package/dist/StateTrait.cjs.map +1 -1
  134. package/dist/StateTrait.d.cts +7 -5
  135. package/dist/StateTrait.d.ts +7 -5
  136. package/dist/StateTrait.js +17 -14
  137. package/dist/{TraitLifecycle-LdIWmKlg.d.ts → TraitLifecycle-CjIBICAA.d.ts} +2 -2
  138. package/dist/{TraitLifecycle-CwV5WPFX.d.cts → TraitLifecycle-NmqGiXPC.d.cts} +2 -2
  139. package/dist/TraitLifecycle.cjs +489 -32
  140. package/dist/TraitLifecycle.cjs.map +1 -1
  141. package/dist/TraitLifecycle.d.cts +4 -4
  142. package/dist/TraitLifecycle.d.ts +4 -4
  143. package/dist/TraitLifecycle.js +7 -7
  144. package/dist/Workflow-BlFG_20_.d.cts +414 -0
  145. package/dist/Workflow-CW9S_aAP.d.ts +414 -0
  146. package/dist/Workflow.cjs +2977 -0
  147. package/dist/Workflow.cjs.map +1 -0
  148. package/dist/Workflow.d.cts +7 -0
  149. package/dist/Workflow.d.ts +7 -0
  150. package/dist/Workflow.js +55 -0
  151. package/dist/Workflow.js.map +1 -0
  152. package/dist/{chunk-G5ZBFPNU.js → chunk-2A4UKO2D.js} +2 -2
  153. package/dist/chunk-2DE6D42I.js +248 -0
  154. package/dist/chunk-2DE6D42I.js.map +1 -0
  155. package/dist/{chunk-ANLBCBDC.js → chunk-2DVLMSOE.js} +6 -6
  156. package/dist/{chunk-BE3HW4FY.js → chunk-34CF6OGE.js} +14 -16
  157. package/dist/chunk-34CF6OGE.js.map +1 -0
  158. package/dist/{chunk-ZFY7U2FR.js → chunk-3LPIXG56.js} +43 -3
  159. package/dist/chunk-3LPIXG56.js.map +1 -0
  160. package/dist/chunk-3VZYDNXZ.js +10 -0
  161. package/dist/chunk-3VZYDNXZ.js.map +1 -0
  162. package/dist/{chunk-3TMODYZV.js → chunk-3XO4HR6V.js} +2 -2
  163. package/dist/chunk-46FGVWRF.js +817 -0
  164. package/dist/chunk-46FGVWRF.js.map +1 -0
  165. package/dist/chunk-4LODUXFI.js +288 -0
  166. package/dist/chunk-4LODUXFI.js.map +1 -0
  167. package/dist/{chunk-GMPEOUP2.js → chunk-4MZ7BT3R.js} +2 -2
  168. package/dist/chunk-4MZ7BT3R.js.map +1 -0
  169. package/dist/{chunk-TKZ7MEIA.js → chunk-53GVPGSM.js} +2 -2
  170. package/dist/{chunk-KP7MUZNX.js → chunk-5W2V2NVJ.js} +2 -2
  171. package/dist/chunk-5W2V2NVJ.js.map +1 -0
  172. package/dist/chunk-6DACKW3D.js +613 -0
  173. package/dist/chunk-6DACKW3D.js.map +1 -0
  174. package/dist/chunk-AQ7L2QZ5.js +1395 -0
  175. package/dist/chunk-AQ7L2QZ5.js.map +1 -0
  176. package/dist/{chunk-NZJKFF45.js → chunk-C2UZZQ76.js} +2 -2
  177. package/dist/chunk-CCKP5Z6F.js +701 -0
  178. package/dist/chunk-CCKP5Z6F.js.map +1 -0
  179. package/dist/chunk-CUKM2XUW.js +27 -0
  180. package/dist/{chunk-QCHIQWAJ.js.map → chunk-CUKM2XUW.js.map} +1 -1
  181. package/dist/{chunk-M2RGJPXX.js → chunk-DBD6Q6JH.js} +3 -3
  182. package/dist/{chunk-ZGDVUPTM.js → chunk-EB4RGQO3.js} +2 -2
  183. package/dist/{chunk-PAYXCY6A.js → chunk-G7ESIQTI.js} +12 -14
  184. package/dist/chunk-G7ESIQTI.js.map +1 -0
  185. package/dist/chunk-GPBAZQ23.js +348 -0
  186. package/dist/chunk-GPBAZQ23.js.map +1 -0
  187. package/dist/{chunk-OFADUJWJ.js → chunk-I4LCE5OY.js} +3 -5
  188. package/dist/{chunk-OFADUJWJ.js.map → chunk-I4LCE5OY.js.map} +1 -1
  189. package/dist/{chunk-DFNM3WX2.js → chunk-IMCC6TBN.js} +158 -39
  190. package/dist/chunk-IMCC6TBN.js.map +1 -0
  191. package/dist/{chunk-76WT3HOR.js → chunk-IROZNQAF.js} +22 -21
  192. package/dist/chunk-IROZNQAF.js.map +1 -0
  193. package/dist/{chunk-TAAPQVZN.js → chunk-ISKNULNH.js} +2 -2
  194. package/dist/chunk-J3CWXIPV.js +242 -0
  195. package/dist/chunk-J3CWXIPV.js.map +1 -0
  196. package/dist/{chunk-PYOE4VSI.js → chunk-JBKYRTCS.js} +224 -161
  197. package/dist/chunk-JBKYRTCS.js.map +1 -0
  198. package/dist/{chunk-66ALHVEX.js → chunk-KKIAYH4X.js} +3 -3
  199. package/dist/{chunk-3RMKLXHX.js → chunk-KLDVG3SY.js} +2 -2
  200. package/dist/{chunk-BABLDP24.js → chunk-KSZQYSEH.js} +3 -3
  201. package/dist/chunk-KSZQYSEH.js.map +1 -0
  202. package/dist/{chunk-CW6T36TN.js → chunk-M3M7JFAH.js} +4 -4
  203. package/dist/chunk-M3M7JFAH.js.map +1 -0
  204. package/dist/{chunk-THATMZXD.js → chunk-MLB253V2.js} +2 -2
  205. package/dist/{chunk-THATMZXD.js.map → chunk-MLB253V2.js.map} +1 -1
  206. package/dist/{chunk-JGIWG6SR.js → chunk-MS77U77X.js} +664 -550
  207. package/dist/chunk-MS77U77X.js.map +1 -0
  208. package/dist/chunk-MW4FA3MW.js +23 -0
  209. package/dist/chunk-MW4FA3MW.js.map +1 -0
  210. package/dist/chunk-MYKNINNN.js +228 -0
  211. package/dist/chunk-MYKNINNN.js.map +1 -0
  212. package/dist/{chunk-4CQAV7YB.js → chunk-O6TTQXTY.js} +2 -2
  213. package/dist/{chunk-NBD3KUOZ.js → chunk-OJDJ4VDQ.js} +35 -24
  214. package/dist/chunk-OJDJ4VDQ.js.map +1 -0
  215. package/dist/{chunk-NQZ2OSGR.js → chunk-PVZEMNJY.js} +9 -9
  216. package/dist/chunk-PVZEMNJY.js.map +1 -0
  217. package/dist/chunk-RN26DV2M.js +271 -0
  218. package/dist/chunk-RN26DV2M.js.map +1 -0
  219. package/dist/{chunk-JCXGZRMU.js → chunk-RQQW3IQC.js} +3 -3
  220. package/dist/chunk-RQQW3IQC.js.map +1 -0
  221. package/dist/{chunk-24VULZ7A.js → chunk-TKOGZDD6.js} +3 -3
  222. package/dist/{chunk-EGK3KN7B.js → chunk-TQYLVXGY.js} +70 -39
  223. package/dist/chunk-TQYLVXGY.js.map +1 -0
  224. package/dist/{chunk-QMM6O4CD.js → chunk-UACD2CL2.js} +15 -3
  225. package/dist/{chunk-QMM6O4CD.js.map → chunk-UACD2CL2.js.map} +1 -1
  226. package/dist/{chunk-M3WTHJHJ.js → chunk-VH575UTV.js} +30 -34
  227. package/dist/chunk-VH575UTV.js.map +1 -0
  228. package/dist/{chunk-AUIR5O6W.js → chunk-WWBMC24F.js} +9 -15
  229. package/dist/chunk-WWBMC24F.js.map +1 -0
  230. package/dist/{chunk-JWOYLO27.js → chunk-WYJUJV4L.js} +80 -7
  231. package/dist/chunk-WYJUJV4L.js.map +1 -0
  232. package/dist/{chunk-EY4NZKDR.js → chunk-XFMMPYNU.js} +2 -2
  233. package/dist/chunk-Y4VRBIS6.js +35 -0
  234. package/dist/chunk-Y4VRBIS6.js.map +1 -0
  235. package/dist/{chunk-DMBALCE2.js → chunk-ZC7MSQ5U.js} +77 -4
  236. package/dist/chunk-ZC7MSQ5U.js.map +1 -0
  237. package/dist/{chunk-OGWBVHB3.js → chunk-ZCK6SCOE.js} +67 -8
  238. package/dist/chunk-ZCK6SCOE.js.map +1 -0
  239. package/dist/{chunk-IHVBV5C2.js → chunk-ZTFTABXV.js} +2 -1
  240. package/dist/chunk-ZTFTABXV.js.map +1 -0
  241. package/dist/index.cjs +9532 -5017
  242. package/dist/index.cjs.map +1 -1
  243. package/dist/index.d.cts +163 -27
  244. package/dist/index.d.ts +163 -27
  245. package/dist/index.js +119 -56
  246. package/dist/index.js.map +1 -1
  247. package/dist/{ir-BMP7yxJJ.d.cts → ir-C-Zm_GlZ.d.cts} +1 -1
  248. package/dist/{ir-DUOz6H-5.d.ts → ir-DGyGiwVe.d.ts} +1 -1
  249. package/dist/{module-k7m3txak.d.ts → module-DqQ1U-Me.d.ts} +129 -100
  250. package/dist/{module-B8CBqIZ_.d.cts → module-doenaCsZ.d.cts} +129 -100
  251. package/package.json +12 -1
  252. package/dist/ModuleTag-C8FHY_sY.d.ts +0 -93
  253. package/dist/ModuleTag-EGbgBMpZ.d.cts +0 -93
  254. package/dist/chunk-3QMIVH35.js +0 -43
  255. package/dist/chunk-3QMIVH35.js.map +0 -1
  256. package/dist/chunk-76WT3HOR.js.map +0 -1
  257. package/dist/chunk-AUIR5O6W.js.map +0 -1
  258. package/dist/chunk-BABLDP24.js.map +0 -1
  259. package/dist/chunk-BE3HW4FY.js.map +0 -1
  260. package/dist/chunk-CW6T36TN.js.map +0 -1
  261. package/dist/chunk-DFNM3WX2.js.map +0 -1
  262. package/dist/chunk-DMBALCE2.js.map +0 -1
  263. package/dist/chunk-EGK3KN7B.js.map +0 -1
  264. package/dist/chunk-GMPEOUP2.js.map +0 -1
  265. package/dist/chunk-IHVBV5C2.js.map +0 -1
  266. package/dist/chunk-JCXGZRMU.js.map +0 -1
  267. package/dist/chunk-JGIWG6SR.js.map +0 -1
  268. package/dist/chunk-JWOYLO27.js.map +0 -1
  269. package/dist/chunk-KIXAU3GM.js +0 -137
  270. package/dist/chunk-KIXAU3GM.js.map +0 -1
  271. package/dist/chunk-KP7MUZNX.js.map +0 -1
  272. package/dist/chunk-M3WTHJHJ.js.map +0 -1
  273. package/dist/chunk-M7IYCTJV.js +0 -79
  274. package/dist/chunk-M7IYCTJV.js.map +0 -1
  275. package/dist/chunk-NBD3KUOZ.js.map +0 -1
  276. package/dist/chunk-NQZ2OSGR.js.map +0 -1
  277. package/dist/chunk-OGWBVHB3.js.map +0 -1
  278. package/dist/chunk-PAYXCY6A.js.map +0 -1
  279. package/dist/chunk-PYOE4VSI.js.map +0 -1
  280. package/dist/chunk-QCHIQWAJ.js +0 -21
  281. package/dist/chunk-VZB726PE.js +0 -93
  282. package/dist/chunk-VZB726PE.js.map +0 -1
  283. package/dist/chunk-W3TEWHLO.js +0 -568
  284. package/dist/chunk-W3TEWHLO.js.map +0 -1
  285. package/dist/chunk-ZFLHVFUC.js +0 -192
  286. package/dist/chunk-ZFLHVFUC.js.map +0 -1
  287. package/dist/chunk-ZFY7U2FR.js.map +0 -1
  288. /package/dist/{chunk-G5ZBFPNU.js.map → chunk-2A4UKO2D.js.map} +0 -0
  289. /package/dist/{chunk-ANLBCBDC.js.map → chunk-2DVLMSOE.js.map} +0 -0
  290. /package/dist/{chunk-3TMODYZV.js.map → chunk-3XO4HR6V.js.map} +0 -0
  291. /package/dist/{chunk-TKZ7MEIA.js.map → chunk-53GVPGSM.js.map} +0 -0
  292. /package/dist/{chunk-NZJKFF45.js.map → chunk-C2UZZQ76.js.map} +0 -0
  293. /package/dist/{chunk-M2RGJPXX.js.map → chunk-DBD6Q6JH.js.map} +0 -0
  294. /package/dist/{chunk-ZGDVUPTM.js.map → chunk-EB4RGQO3.js.map} +0 -0
  295. /package/dist/{chunk-TAAPQVZN.js.map → chunk-ISKNULNH.js.map} +0 -0
  296. /package/dist/{chunk-66ALHVEX.js.map → chunk-KKIAYH4X.js.map} +0 -0
  297. /package/dist/{chunk-3RMKLXHX.js.map → chunk-KLDVG3SY.js.map} +0 -0
  298. /package/dist/{chunk-4CQAV7YB.js.map → chunk-O6TTQXTY.js.map} +0 -0
  299. /package/dist/{chunk-24VULZ7A.js.map → chunk-TKOGZDD6.js.map} +0 -0
  300. /package/dist/{chunk-EY4NZKDR.js.map → chunk-XFMMPYNU.js.map} +0 -0
package/dist/Runtime.cjs CHANGED
@@ -35,6 +35,7 @@ __export(Runtime_exports, {
35
35
  DisposeTimeoutError: () => DisposeTimeoutError,
36
36
  MainError: () => MainError,
37
37
  applyTransactionSnapshot: () => applyTransactionSnapshot,
38
+ batch: () => batch,
38
39
  concurrencyPolicyOverridesLayer: () => concurrencyPolicyOverridesLayer,
39
40
  make: () => make7,
40
41
  openProgram: () => openProgram2,
@@ -44,51 +45,281 @@ __export(Runtime_exports, {
44
45
  stateTransactionOverridesLayer: () => stateTransactionOverridesLayer
45
46
  });
46
47
  module.exports = __toCommonJS(Runtime_exports);
47
- var import_effect58 = require("effect");
48
+ var import_effect61 = require("effect");
48
49
 
49
50
  // src/internal/runtime/AppRuntime.ts
50
- var import_effect9 = require("effect");
51
+ var import_effect12 = require("effect");
51
52
 
52
53
  // src/internal/runtime/core/env.ts
53
- var import_effect = require("effect");
54
- var getNodeEnv = () => {
54
+ var import_effect8 = require("effect");
55
+
56
+ // src/internal/runtime/core/HostScheduler.ts
57
+ var noopCancel = () => {
58
+ };
59
+ var safeNowMs = () => {
60
+ const perf = globalThis.performance;
61
+ if (perf && typeof perf.now === "function") {
62
+ try {
63
+ const v = perf.now();
64
+ if (typeof v === "number" && Number.isFinite(v)) return v;
65
+ } catch {
66
+ }
67
+ }
68
+ return Date.now();
69
+ };
70
+ var safeQueueMicrotask = (cb) => {
71
+ const qm = globalThis.queueMicrotask;
72
+ if (typeof qm === "function") {
73
+ try {
74
+ qm(cb);
75
+ return;
76
+ } catch {
77
+ }
78
+ }
55
79
  try {
56
- const env = globalThis?.process?.env;
57
- return typeof env?.NODE_ENV === "string" ? env.NODE_ENV : void 0;
80
+ Promise.resolve().then(cb);
58
81
  } catch {
59
- return void 0;
82
+ setTimeout(cb, 0);
60
83
  }
61
84
  };
62
- var isDevEnv = () => getNodeEnv() !== "production";
63
- var StateTransactionConfigTagImpl = class extends import_effect.Context.Tag("@logixjs/core/StateTransactionRuntimeConfig")() {
64
- };
65
- var StateTransactionConfigTag = StateTransactionConfigTagImpl;
66
- var ReadQueryStrictGateConfigTagImpl = class extends import_effect.Context.Tag("@logixjs/core/ReadQueryStrictGateRuntimeConfig")() {
85
+ var safeSetTimeout = (ms, cb) => {
86
+ const id = setTimeout(cb, ms);
87
+ return () => {
88
+ try {
89
+ clearTimeout(id);
90
+ } catch {
91
+ }
92
+ };
67
93
  };
68
- var ReadQueryStrictGateConfigTag = ReadQueryStrictGateConfigTagImpl;
69
- var ReplayModeConfigTagImpl = class extends import_effect.Context.Tag("@logixjs/core/ReplayModeConfig")() {
94
+ var makeMessageChannelMacrotask = () => {
95
+ const MC = globalThis.MessageChannel;
96
+ if (typeof MC !== "function") return void 0;
97
+ let channel;
98
+ try {
99
+ channel = new MC();
100
+ } catch {
101
+ return void 0;
102
+ }
103
+ const queue = [];
104
+ let scheduled = false;
105
+ const flush = () => {
106
+ scheduled = false;
107
+ const tasks = queue.splice(0, queue.length);
108
+ for (const t of tasks) {
109
+ if (t.canceled) continue;
110
+ try {
111
+ t.cb();
112
+ } catch {
113
+ }
114
+ }
115
+ };
116
+ try {
117
+ channel.port1.onmessage = flush;
118
+ } catch {
119
+ return void 0;
120
+ }
121
+ const schedule = (cb) => {
122
+ const task = { canceled: false, cb };
123
+ queue.push(task);
124
+ if (!scheduled) {
125
+ scheduled = true;
126
+ try {
127
+ channel.port2.postMessage(void 0);
128
+ } catch {
129
+ scheduled = false;
130
+ return safeSetTimeout(0, cb);
131
+ }
132
+ }
133
+ return () => {
134
+ task.canceled = true;
135
+ };
136
+ };
137
+ return schedule;
138
+ };
139
+ var makeSetImmediateMacrotask = () => {
140
+ const si = globalThis.setImmediate;
141
+ const ci = globalThis.clearImmediate;
142
+ if (typeof si !== "function") return void 0;
143
+ return (cb) => {
144
+ let id;
145
+ try {
146
+ id = si(cb);
147
+ } catch {
148
+ return safeSetTimeout(0, cb);
149
+ }
150
+ return () => {
151
+ if (typeof ci !== "function") return;
152
+ try {
153
+ ci(id);
154
+ } catch {
155
+ }
156
+ };
157
+ };
70
158
  };
71
- var StateTransactionOverridesTagImpl = class extends import_effect.Context.Tag("@logixjs/core/StateTransactionOverrides")() {
159
+ var makeRaf = () => {
160
+ const raf = globalThis.requestAnimationFrame;
161
+ const cancel = globalThis.cancelAnimationFrame;
162
+ if (typeof raf !== "function") return void 0;
163
+ return (cb) => {
164
+ let id;
165
+ try {
166
+ id = raf(cb);
167
+ } catch {
168
+ return noopCancel;
169
+ }
170
+ return () => {
171
+ if (typeof cancel !== "function") return;
172
+ try {
173
+ cancel(id);
174
+ } catch {
175
+ }
176
+ };
177
+ };
72
178
  };
73
- var StateTransactionOverridesTag = StateTransactionOverridesTagImpl;
74
- var ConcurrencyPolicyTagImpl = class extends import_effect.Context.Tag("@logixjs/core/ConcurrencyPolicy")() {
179
+ var makeDefaultHostScheduler = () => {
180
+ const macrotask = makeSetImmediateMacrotask() ?? makeMessageChannelMacrotask() ?? ((cb) => safeSetTimeout(0, cb));
181
+ const raf = makeRaf();
182
+ return {
183
+ nowMs: safeNowMs,
184
+ scheduleMicrotask: safeQueueMicrotask,
185
+ scheduleMacrotask: macrotask,
186
+ scheduleAnimationFrame: (cb) => raf?.(cb) ?? macrotask(cb),
187
+ scheduleTimeout: safeSetTimeout
188
+ };
75
189
  };
76
- var ConcurrencyPolicyTag = ConcurrencyPolicyTagImpl;
77
- var ConcurrencyPolicyOverridesTagImpl = class extends import_effect.Context.Tag("@logixjs/core/ConcurrencyPolicyOverrides")() {
190
+ var globalHostScheduler;
191
+ var getGlobalHostScheduler = () => {
192
+ globalHostScheduler ?? (globalHostScheduler = makeDefaultHostScheduler());
193
+ return globalHostScheduler;
78
194
  };
79
- var ConcurrencyPolicyOverridesTag = ConcurrencyPolicyOverridesTagImpl;
80
195
 
81
- // src/internal/runtime/core/RootContext.ts
82
- var import_effect2 = require("effect");
83
- var RootContextTagImpl = class extends import_effect2.Context.Tag("@logixjs/core/RootContext")() {
196
+ // src/internal/runtime/core/RuntimeStore.ts
197
+ var makeReadQueryTopicKey = (moduleInstanceKey, selectorId) => `${moduleInstanceKey}::rq:${selectorId}`;
198
+ var parseTopicKey = (topicKey) => {
199
+ const idx = topicKey.indexOf("::");
200
+ if (idx <= 0) return void 0;
201
+ const moduleId = topicKey.slice(0, idx);
202
+ const rest = topicKey.slice(idx + 2);
203
+ if (rest.length === 0) return void 0;
204
+ const idx2 = rest.indexOf("::");
205
+ if (idx2 < 0) {
206
+ return { kind: "module", moduleInstanceKey: `${moduleId}::${rest}` };
207
+ }
208
+ const instanceId = rest.slice(0, idx2);
209
+ const suffix = rest.slice(idx2 + 2);
210
+ if (suffix.startsWith("rq:")) {
211
+ const selectorId = suffix.slice("rq:".length);
212
+ if (selectorId.length === 0) return void 0;
213
+ return {
214
+ kind: "readQuery",
215
+ moduleInstanceKey: `${moduleId}::${instanceId}`,
216
+ selectorId
217
+ };
218
+ }
219
+ return { kind: "module", moduleInstanceKey: `${moduleId}::${instanceId}` };
220
+ };
221
+ var makeRuntimeStore = () => {
222
+ let tickSeq = 0;
223
+ const moduleStates = /* @__PURE__ */ new Map();
224
+ const topicVersions = /* @__PURE__ */ new Map();
225
+ const topicPriorities = /* @__PURE__ */ new Map();
226
+ const listenersByTopic = /* @__PURE__ */ new Map();
227
+ const subscriberCountByModule = /* @__PURE__ */ new Map();
228
+ const getTopicVersion = (topicKey) => topicVersions.get(topicKey) ?? 0;
229
+ const getTopicPriority = (topicKey) => topicPriorities.get(topicKey) ?? "normal";
230
+ const commitTopicBump = (topicKey, priority) => {
231
+ const prev = topicVersions.get(topicKey) ?? 0;
232
+ topicVersions.set(topicKey, prev + 1);
233
+ topicPriorities.set(topicKey, priority);
234
+ };
235
+ const subscribeTopic = (topicKey, listener) => {
236
+ const info = parseTopicKey(topicKey);
237
+ const existing = listenersByTopic.get(topicKey);
238
+ const set = existing ?? /* @__PURE__ */ new Set();
239
+ const alreadyHas = set.has(listener);
240
+ if (!alreadyHas) {
241
+ set.add(listener);
242
+ }
243
+ if (!existing) {
244
+ listenersByTopic.set(topicKey, set);
245
+ }
246
+ if (!alreadyHas && info) {
247
+ const prev = subscriberCountByModule.get(info.moduleInstanceKey) ?? 0;
248
+ subscriberCountByModule.set(info.moduleInstanceKey, prev + 1);
249
+ }
250
+ return () => {
251
+ const current = listenersByTopic.get(topicKey);
252
+ if (!current) return;
253
+ const deleted = current.delete(listener);
254
+ if (deleted && info) {
255
+ const prev = subscriberCountByModule.get(info.moduleInstanceKey) ?? 0;
256
+ const next = prev - 1;
257
+ if (next <= 0) {
258
+ subscriberCountByModule.delete(info.moduleInstanceKey);
259
+ } else {
260
+ subscriberCountByModule.set(info.moduleInstanceKey, next);
261
+ }
262
+ }
263
+ if (current.size === 0) {
264
+ listenersByTopic.delete(topicKey);
265
+ }
266
+ };
267
+ };
268
+ const getTopicSubscriberCount = (topicKey) => listenersByTopic.get(topicKey)?.size ?? 0;
269
+ const getModuleSubscriberCount = (moduleInstanceKey) => subscriberCountByModule.get(moduleInstanceKey) ?? 0;
270
+ const registerModuleInstance = (args) => {
271
+ moduleStates.set(args.moduleInstanceKey, args.initialState);
272
+ if (!topicVersions.has(args.moduleInstanceKey)) {
273
+ topicVersions.set(args.moduleInstanceKey, 0);
274
+ topicPriorities.set(args.moduleInstanceKey, "normal");
275
+ }
276
+ };
277
+ const unregisterModuleInstance = (moduleInstanceKey) => {
278
+ moduleStates.delete(moduleInstanceKey);
279
+ };
280
+ const commitTick = (args) => {
281
+ tickSeq = args.tickSeq;
282
+ for (const [key, commit2] of args.accepted.modules) {
283
+ moduleStates.set(key, commit2.state);
284
+ }
285
+ const changedTopics = /* @__PURE__ */ new Map();
286
+ for (const [topicKey, priority] of args.accepted.dirtyTopics) {
287
+ commitTopicBump(topicKey, priority);
288
+ const listeners2 = Array.from(listenersByTopic.get(topicKey) ?? []);
289
+ if (listeners2.length > 0) {
290
+ changedTopics.set(topicKey, { priority, listeners: listeners2 });
291
+ }
292
+ }
293
+ return { changedTopics };
294
+ };
295
+ const getModuleState = (moduleInstanceKey) => moduleStates.get(moduleInstanceKey);
296
+ const dispose = () => {
297
+ moduleStates.clear();
298
+ topicVersions.clear();
299
+ topicPriorities.clear();
300
+ listenersByTopic.clear();
301
+ subscriberCountByModule.clear();
302
+ };
303
+ return {
304
+ getTickSeq: () => tickSeq,
305
+ getModuleState,
306
+ getTopicVersion,
307
+ getTopicPriority,
308
+ subscribeTopic,
309
+ getTopicSubscriberCount,
310
+ getModuleSubscriberCount,
311
+ registerModuleInstance,
312
+ unregisterModuleInstance,
313
+ commitTick,
314
+ dispose
315
+ };
84
316
  };
85
- var RootContextTag = RootContextTagImpl;
86
317
 
87
- // src/internal/runtime/core/process/ProcessRuntime.ts
88
- var import_effect8 = require("effect");
318
+ // src/internal/runtime/core/TickScheduler.ts
319
+ var import_effect6 = require("effect");
89
320
 
90
- // src/internal/runtime/core/DebugSink.ts
91
- var import_effect5 = require("effect");
321
+ // src/internal/runtime/core/DebugSink.record.ts
322
+ var import_effect3 = require("effect");
92
323
 
93
324
  // src/internal/observability/jsonValue.ts
94
325
  var defaultOptions = {
@@ -179,11 +410,12 @@ var toJsonValueInternal = (input, options, stats, seen, depth) => {
179
410
  stats.nonSerializable += 1;
180
411
  return truncateString(String(input), options.maxStringLength, stats);
181
412
  }
182
- const entries = Object.entries(input);
183
- const limit = Math.min(entries.length, options.maxObjectKeys);
413
+ const keys = Object.keys(input).sort();
414
+ const limit = Math.min(keys.length, options.maxObjectKeys);
184
415
  const out = {};
185
416
  for (let i = 0; i < limit; i++) {
186
- const [rawKey, rawValue] = entries[i];
417
+ const rawKey = keys[i];
418
+ const rawValue = input[rawKey];
187
419
  const key = truncateString(rawKey, options.maxStringLength, stats);
188
420
  if (rawValue === void 0) {
189
421
  stats.dropped += 1;
@@ -191,9 +423,9 @@ var toJsonValueInternal = (input, options, stats, seen, depth) => {
191
423
  }
192
424
  out[key] = toJsonValueInternal(rawValue, options, stats, seen, depth + 1);
193
425
  }
194
- if (entries.length > limit) {
426
+ if (keys.length > limit) {
195
427
  stats.oversized += 1;
196
- out.__truncatedKeys = entries.length - limit;
428
+ out.__truncatedKeys = keys.length - limit;
197
429
  }
198
430
  return out;
199
431
  };
@@ -252,7 +484,7 @@ var projectJsonValue = (input, options) => {
252
484
  };
253
485
 
254
486
  // src/internal/runtime/core/errorSummary.ts
255
- var import_effect3 = require("effect");
487
+ var import_effect = require("effect");
256
488
  var truncate = (value, maxLen) => {
257
489
  if (value.length <= maxLen) return { value, truncated: false };
258
490
  return { value: value.slice(0, maxLen), truncated: true };
@@ -272,7 +504,7 @@ var getMessageFromUnknown = (cause) => {
272
504
  return cause.message;
273
505
  }
274
506
  try {
275
- const pretty = import_effect3.Cause.pretty(cause, { renderErrorCause: true });
507
+ const pretty = import_effect.Cause.pretty(cause, { renderErrorCause: true });
276
508
  if (typeof pretty === "string" && pretty.length > 0) return pretty;
277
509
  } catch {
278
510
  }
@@ -325,9 +557,9 @@ var toSerializableErrorSummary = (cause, options) => {
325
557
  };
326
558
 
327
559
  // src/internal/runtime/core/EffectOpCore.ts
328
- var import_effect4 = require("effect");
329
- var currentLinkId = import_effect4.FiberRef.unsafeMake(void 0);
330
- var EffectOpMiddlewareTag = class extends import_effect4.Context.Tag("Logix/EffectOpMiddleware")() {
560
+ var import_effect2 = require("effect");
561
+ var currentLinkId = import_effect2.FiberRef.unsafeMake(void 0);
562
+ var EffectOpMiddlewareTag = class extends import_effect2.Context.Tag("Logix/EffectOpMiddleware")() {
331
563
  };
332
564
  var composeMiddleware = (stack) => {
333
565
  return (op) => stack.reduceRight(
@@ -336,8 +568,8 @@ var composeMiddleware = (stack) => {
336
568
  );
337
569
  };
338
570
  var runWithMiddleware = (op, stack) => {
339
- return import_effect4.Effect.gen(function* () {
340
- const existing = yield* import_effect4.FiberRef.get(currentLinkId);
571
+ return import_effect2.Effect.gen(function* () {
572
+ const existing = yield* import_effect2.FiberRef.get(currentLinkId);
341
573
  const metaLinkId = op.meta?.linkId;
342
574
  const linkId = typeof metaLinkId === "string" && metaLinkId.length > 0 ? metaLinkId : existing ?? op.id;
343
575
  const nextOp = {
@@ -348,21 +580,21 @@ var runWithMiddleware = (op, stack) => {
348
580
  }
349
581
  };
350
582
  const program = stack.length ? composeMiddleware(stack)(nextOp) : nextOp.effect;
351
- return yield* import_effect4.Effect.locally(currentLinkId, linkId)(program);
583
+ return yield* import_effect2.Effect.locally(currentLinkId, linkId)(program);
352
584
  });
353
585
  };
354
586
 
355
- // src/internal/runtime/core/DebugSink.ts
356
- var currentDebugSinks = import_effect5.FiberRef.unsafeMake([]);
357
- var currentRuntimeLabel = import_effect5.FiberRef.unsafeMake(void 0);
358
- var currentTxnId = import_effect5.FiberRef.unsafeMake(void 0);
359
- var currentOpSeq = import_effect5.FiberRef.unsafeMake(void 0);
360
- var currentDiagnosticsLevel = import_effect5.FiberRef.unsafeMake("off");
361
- var currentTraitConvergeDiagnosticsSampling = import_effect5.FiberRef.unsafeMake({
587
+ // src/internal/runtime/core/DebugSink.record.ts
588
+ var currentDebugSinks = import_effect3.FiberRef.unsafeMake([]);
589
+ var currentRuntimeLabel = import_effect3.FiberRef.unsafeMake(void 0);
590
+ var currentTxnId = import_effect3.FiberRef.unsafeMake(void 0);
591
+ var currentOpSeq = import_effect3.FiberRef.unsafeMake(void 0);
592
+ var currentDiagnosticsLevel = import_effect3.FiberRef.unsafeMake("off");
593
+ var currentTraitConvergeDiagnosticsSampling = import_effect3.FiberRef.unsafeMake({
362
594
  sampleEveryN: 32,
363
595
  topK: 3
364
596
  });
365
- var traitConvergeDiagnosticsSampling = (config) => import_effect5.Layer.fiberRefLocallyScopedWith(currentTraitConvergeDiagnosticsSampling, () => config);
597
+ var traitConvergeDiagnosticsSampling = (config) => import_effect3.Layer.fiberRefLocallyScopedWith(currentTraitConvergeDiagnosticsSampling, () => config);
366
598
  var nextGlobalEventSeq = 0;
367
599
  var nextEventSeq = () => {
368
600
  nextGlobalEventSeq += 1;
@@ -412,7 +644,7 @@ var lifecycleErrorLog = (event) => {
412
644
  const moduleId = event.moduleId ?? "unknown";
413
645
  const causePretty = (() => {
414
646
  try {
415
- return import_effect5.Cause.pretty(event.cause, {
647
+ return import_effect3.Cause.pretty(event.cause, {
416
648
  renderErrorCause: true
417
649
  });
418
650
  } catch {
@@ -425,8 +657,8 @@ var lifecycleErrorLog = (event) => {
425
657
  })();
426
658
  const message = `[Logix][module=${moduleId}] lifecycle:error
427
659
  ${causePretty}`;
428
- return import_effect5.Effect.logError(message).pipe(
429
- import_effect5.Effect.annotateLogs({
660
+ return import_effect3.Effect.logError(message).pipe(
661
+ import_effect3.Effect.annotateLogs({
430
662
  "logix.moduleId": moduleId,
431
663
  "logix.event": "lifecycle:error",
432
664
  "logix.cause": causePretty
@@ -440,7 +672,7 @@ var diagnosticLog = (event) => {
440
672
  hint: ${event.hint}` : ""}`;
441
673
  const msg = `${header}
442
674
  ${detail}`;
443
- const base = event.severity === "warning" ? import_effect5.Effect.logWarning(msg) : event.severity === "info" ? import_effect5.Effect.logInfo(msg) : import_effect5.Effect.logError(msg);
675
+ const base = event.severity === "warning" ? import_effect3.Effect.logWarning(msg) : event.severity === "info" ? import_effect3.Effect.logInfo(msg) : import_effect3.Effect.logError(msg);
444
676
  const annotations = {
445
677
  "logix.moduleId": moduleId,
446
678
  "logix.event": `diagnostic(${event.severity})`,
@@ -453,24 +685,24 @@ ${detail}`;
453
685
  if (event.actionTag) {
454
686
  annotations["logix.diagnostic.actionTag"] = event.actionTag;
455
687
  }
456
- return base.pipe(import_effect5.Effect.annotateLogs(annotations));
688
+ return base.pipe(import_effect3.Effect.annotateLogs(annotations));
457
689
  };
458
- var noopLayer = import_effect5.Layer.locallyScoped(currentDebugSinks, []);
690
+ var noopLayer = import_effect3.Layer.locallyScoped(currentDebugSinks, []);
459
691
  var errorOnlySink = {
460
- record: (event) => event.type === "lifecycle:error" ? lifecycleErrorLog(event) : event.type === "diagnostic" && event.severity !== "info" ? diagnosticLog(event) : import_effect5.Effect.void
692
+ record: (event) => event.type === "lifecycle:error" ? lifecycleErrorLog(event) : event.type === "diagnostic" && event.severity !== "info" ? diagnosticLog(event) : import_effect3.Effect.void
461
693
  };
462
- var errorOnlyLayer = import_effect5.Layer.locallyScoped(currentDebugSinks, [errorOnlySink]);
694
+ var errorOnlyLayer = import_effect3.Layer.locallyScoped(currentDebugSinks, [errorOnlySink]);
463
695
  var isErrorOnlyOnlySinks = (sinks) => sinks.length === 1 && sinks[0] === errorOnlySink;
464
696
  var consoleSink = {
465
- record: (event) => event.type === "lifecycle:error" ? lifecycleErrorLog(event) : event.type === "diagnostic" ? diagnosticLog(event) : import_effect5.Effect.logDebug({ debugEvent: event })
697
+ record: (event) => event.type === "lifecycle:error" ? lifecycleErrorLog(event) : event.type === "diagnostic" ? diagnosticLog(event) : import_effect3.Effect.logDebug({ debugEvent: event })
466
698
  };
467
- var consoleLayer = import_effect5.Layer.locallyScoped(currentDebugSinks, [consoleSink]);
699
+ var consoleLayer = import_effect3.Layer.locallyScoped(currentDebugSinks, [consoleSink]);
468
700
  var isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
469
701
  var renderBrowserConsoleEvent = (event) => {
470
702
  if (typeof event.type === "string" && event.type.startsWith("trace:")) {
471
703
  const moduleId = event.moduleId ?? "unknown";
472
704
  const type = event.type;
473
- return import_effect5.Effect.sync(() => {
705
+ return import_effect3.Effect.sync(() => {
474
706
  console.groupCollapsed(
475
707
  "%c[Logix]%c trace %c" + moduleId + "%c " + String(type),
476
708
  "color:#6b7280;font-weight:bold",
@@ -490,7 +722,7 @@ var renderBrowserConsoleEvent = (event) => {
490
722
  const moduleId = event.moduleId ?? "unknown";
491
723
  const causePretty = (() => {
492
724
  try {
493
- return import_effect5.Cause.pretty(event.cause, { renderErrorCause: true });
725
+ return import_effect3.Cause.pretty(event.cause, { renderErrorCause: true });
494
726
  } catch {
495
727
  try {
496
728
  return JSON.stringify(event.cause, null, 2);
@@ -501,10 +733,10 @@ var renderBrowserConsoleEvent = (event) => {
501
733
  })();
502
734
  const key = `${moduleId}|${causePretty}`;
503
735
  if (browserLifecycleSeen.has(key)) {
504
- return import_effect5.Effect.void;
736
+ return import_effect3.Effect.void;
505
737
  }
506
738
  browserLifecycleSeen.add(key);
507
- return import_effect5.Effect.sync(() => {
739
+ return import_effect3.Effect.sync(() => {
508
740
  console.groupCollapsed(
509
741
  "%c[Logix]%c lifecycle:error %c" + moduleId,
510
742
  "color:#ef4444;font-weight:bold",
@@ -526,10 +758,10 @@ hint: ${event.hint}` : ""}`;
526
758
  const label = event.severity === "warning" ? "diagnostic(warning)" : event.severity === "info" ? "diagnostic(info)" : "diagnostic(error)";
527
759
  const key = `${moduleId}|${event.code}|${event.message}`;
528
760
  if (browserDiagnosticSeen.has(key)) {
529
- return import_effect5.Effect.void;
761
+ return import_effect3.Effect.void;
530
762
  }
531
763
  browserDiagnosticSeen.add(key);
532
- return import_effect5.Effect.sync(() => {
764
+ return import_effect3.Effect.sync(() => {
533
765
  console.groupCollapsed(
534
766
  "%c[Logix]%c " + label + "%c module=" + moduleId,
535
767
  "color:#6b7280;font-weight:bold",
@@ -546,32 +778,32 @@ hint: ${event.hint}` : ""}`;
546
778
  console.groupEnd();
547
779
  });
548
780
  }
549
- return import_effect5.Effect.void;
781
+ return import_effect3.Effect.void;
550
782
  };
551
783
  var browserConsoleSink = {
552
784
  record: (event) => {
553
785
  if (!isBrowser) {
554
- return event.type === "lifecycle:error" ? lifecycleErrorLog(event) : event.type === "diagnostic" ? diagnosticLog(event) : import_effect5.Effect.logDebug({ debugEvent: event });
786
+ return event.type === "lifecycle:error" ? lifecycleErrorLog(event) : event.type === "diagnostic" ? diagnosticLog(event) : import_effect3.Effect.logDebug({ debugEvent: event });
555
787
  }
556
788
  return renderBrowserConsoleEvent(event);
557
789
  }
558
790
  };
559
- var browserConsoleLayer = import_effect5.Layer.locallyScoped(currentDebugSinks, [browserConsoleSink]);
791
+ var browserConsoleLayer = import_effect3.Layer.locallyScoped(currentDebugSinks, [browserConsoleSink]);
560
792
  var browserDiagnosticConsoleSink = {
561
793
  record: (event) => {
562
794
  if (!isBrowser) {
563
- return event.type === "lifecycle:error" ? lifecycleErrorLog(event) : event.type === "diagnostic" && event.severity !== "info" ? diagnosticLog(event) : import_effect5.Effect.void;
795
+ return event.type === "lifecycle:error" ? lifecycleErrorLog(event) : event.type === "diagnostic" && event.severity !== "info" ? diagnosticLog(event) : import_effect3.Effect.void;
564
796
  }
565
- return event.type === "lifecycle:error" || event.type === "diagnostic" && event.severity !== "info" ? renderBrowserConsoleEvent(event) : import_effect5.Effect.void;
797
+ return event.type === "lifecycle:error" || event.type === "diagnostic" && event.severity !== "info" ? renderBrowserConsoleEvent(event) : import_effect3.Effect.void;
566
798
  }
567
799
  };
568
- var browserDiagnosticConsoleLayer = import_effect5.Layer.locallyScoped(currentDebugSinks, [browserDiagnosticConsoleSink]);
569
- var browserPrettyLoggerLayer = import_effect5.Logger.replace(
570
- import_effect5.Logger.defaultLogger,
571
- import_effect5.Logger.prettyLogger({ mode: "browser", colors: true })
800
+ var browserDiagnosticConsoleLayer = import_effect3.Layer.locallyScoped(currentDebugSinks, [browserDiagnosticConsoleSink]);
801
+ var browserPrettyLoggerLayer = import_effect3.Logger.replace(
802
+ import_effect3.Logger.defaultLogger,
803
+ import_effect3.Logger.prettyLogger({ mode: "browser", colors: true })
572
804
  );
573
- var record = (event) => import_effect5.Effect.gen(function* () {
574
- const sinks = yield* import_effect5.FiberRef.get(currentDebugSinks);
805
+ var record = (event) => import_effect3.Effect.gen(function* () {
806
+ const sinks = yield* import_effect3.FiberRef.get(currentDebugSinks);
575
807
  if (isErrorOnlyOnlySinks(sinks)) {
576
808
  if (event.type === "lifecycle:error") {
577
809
  yield* lifecycleErrorLog(event);
@@ -581,11 +813,11 @@ var record = (event) => import_effect5.Effect.gen(function* () {
581
813
  if (event.severity !== "info") {
582
814
  yield* diagnosticLog(event);
583
815
  } else {
584
- yield* import_effect5.Effect.void;
816
+ yield* import_effect3.Effect.void;
585
817
  }
586
818
  return;
587
819
  }
588
- yield* import_effect5.Effect.void;
820
+ yield* import_effect3.Effect.void;
589
821
  return;
590
822
  }
591
823
  if (sinks.length === 0) {
@@ -594,7 +826,7 @@ var record = (event) => import_effect5.Effect.gen(function* () {
594
826
  yield* renderBrowserConsoleEvent(event);
595
827
  return;
596
828
  }
597
- yield* import_effect5.Effect.void;
829
+ yield* import_effect3.Effect.void;
598
830
  return;
599
831
  }
600
832
  if (event.type === "lifecycle:error") {
@@ -605,11 +837,11 @@ var record = (event) => import_effect5.Effect.gen(function* () {
605
837
  yield* diagnosticLog(event);
606
838
  return;
607
839
  }
608
- yield* import_effect5.Effect.void;
840
+ yield* import_effect3.Effect.void;
609
841
  return;
610
842
  }
611
843
  const enriched = event;
612
- const diagnosticsLevel2 = yield* import_effect5.FiberRef.get(currentDiagnosticsLevel);
844
+ const diagnosticsLevel2 = yield* import_effect3.FiberRef.get(currentDiagnosticsLevel);
613
845
  let now;
614
846
  const getNow = () => {
615
847
  if (now === void 0) now = Date.now();
@@ -620,21 +852,21 @@ var record = (event) => import_effect5.Effect.gen(function* () {
620
852
  enriched.timestamp = getNow();
621
853
  }
622
854
  if (diagnosticsLevel2 !== "off" && enriched.runtimeLabel === void 0) {
623
- const runtimeLabel2 = yield* import_effect5.FiberRef.get(currentRuntimeLabel);
855
+ const runtimeLabel2 = yield* import_effect3.FiberRef.get(currentRuntimeLabel);
624
856
  if (runtimeLabel2) {
625
857
  ;
626
858
  enriched.runtimeLabel = runtimeLabel2;
627
859
  }
628
860
  }
629
861
  if (enriched.type === "diagnostic" && enriched.txnId === void 0) {
630
- const txnId = yield* import_effect5.FiberRef.get(currentTxnId);
862
+ const txnId = yield* import_effect3.FiberRef.get(currentTxnId);
631
863
  if (txnId) {
632
864
  ;
633
865
  enriched.txnId = txnId;
634
866
  }
635
867
  }
636
868
  if (diagnosticsLevel2 !== "off" && enriched.type === "trace:effectop" && enriched.linkId === void 0) {
637
- const linkId = yield* import_effect5.FiberRef.get(currentLinkId);
869
+ const linkId = yield* import_effect3.FiberRef.get(currentLinkId);
638
870
  if (linkId) {
639
871
  ;
640
872
  enriched.linkId = linkId;
@@ -644,7 +876,7 @@ var record = (event) => import_effect5.Effect.gen(function* () {
644
876
  yield* sinks[0].record(enriched);
645
877
  return;
646
878
  }
647
- yield* import_effect5.Effect.forEach(sinks, (sink) => sink.record(enriched), { discard: true });
879
+ yield* import_effect3.Effect.forEach(sinks, (sink) => sink.record(enriched), { discard: true });
648
880
  });
649
881
  var toRuntimeDebugEventRef = (event, options) => {
650
882
  const diagnosticsLevel2 = options?.diagnosticsLevel ?? "full";
@@ -907,10 +1139,83 @@ var toRuntimeDebugEventRef = (event, options) => {
907
1139
  meta: metaProjection.value
908
1140
  });
909
1141
  }
1142
+ case "warn:priority-inversion": {
1143
+ const e = event;
1144
+ const metaInput = isLightLike ? {
1145
+ tickSeq: e.tickSeq,
1146
+ reason: e.reason,
1147
+ selectorId: e.selectorId
1148
+ } : {
1149
+ tickSeq: e.tickSeq,
1150
+ reason: e.reason,
1151
+ selectorId: e.selectorId
1152
+ };
1153
+ const metaProjection = projectJsonValue(metaInput);
1154
+ options?.onMetaProjection?.({
1155
+ stats: metaProjection.stats,
1156
+ downgrade: metaProjection.downgrade
1157
+ });
1158
+ downgrade = mergeDowngrade2(downgrade, metaProjection.downgrade);
1159
+ return withDowngrade({
1160
+ ...base,
1161
+ kind: "diagnostic",
1162
+ label: e.type,
1163
+ meta: metaProjection.value
1164
+ });
1165
+ }
1166
+ case "warn:microtask-starvation": {
1167
+ const e = event;
1168
+ const metaInput = isLightLike ? {
1169
+ tickSeq: e.tickSeq,
1170
+ microtaskChainDepth: e.microtaskChainDepth
1171
+ } : {
1172
+ tickSeq: e.tickSeq,
1173
+ microtaskChainDepth: e.microtaskChainDepth
1174
+ };
1175
+ const metaProjection = projectJsonValue(metaInput);
1176
+ options?.onMetaProjection?.({
1177
+ stats: metaProjection.stats,
1178
+ downgrade: metaProjection.downgrade
1179
+ });
1180
+ downgrade = mergeDowngrade2(downgrade, metaProjection.downgrade);
1181
+ return withDowngrade({
1182
+ ...base,
1183
+ kind: "diagnostic",
1184
+ label: e.type,
1185
+ meta: metaProjection.value
1186
+ });
1187
+ }
910
1188
  default: {
911
1189
  if (typeof event.type !== "string" || !event.type.startsWith("trace:")) {
912
1190
  return void 0;
913
1191
  }
1192
+ if (event.type === "trace:tick") {
1193
+ const data = event.data;
1194
+ const metaInput = isLightLike ? {
1195
+ tickSeq: data?.tickSeq,
1196
+ phase: data?.phase,
1197
+ schedule: data?.schedule,
1198
+ triggerSummary: data?.triggerSummary,
1199
+ anchors: data?.anchors,
1200
+ budget: data?.budget,
1201
+ backlog: data?.backlog,
1202
+ result: data?.result
1203
+ } : {
1204
+ data
1205
+ };
1206
+ const metaProjection2 = projectJsonValue(metaInput);
1207
+ options?.onMetaProjection?.({
1208
+ stats: metaProjection2.stats,
1209
+ downgrade: metaProjection2.downgrade
1210
+ });
1211
+ downgrade = mergeDowngrade2(downgrade, metaProjection2.downgrade);
1212
+ return withDowngrade({
1213
+ ...base,
1214
+ kind: "devtools",
1215
+ label: event.type,
1216
+ meta: metaProjection2.value
1217
+ });
1218
+ }
914
1219
  if (event.type === "trace:txn-lane") {
915
1220
  const data = event.data;
916
1221
  const evidence = data?.evidence ?? data;
@@ -1276,13 +1581,270 @@ var toRuntimeDebugEventRef = (event, options) => {
1276
1581
  meta: metaProjection.value
1277
1582
  });
1278
1583
  }
1279
- }
1584
+ }
1585
+ };
1586
+
1587
+ // src/internal/runtime/core/DevtoolsHub.ts
1588
+ var import_effect4 = require("effect");
1589
+ var instances = /* @__PURE__ */ new Map();
1590
+ var latestStates = /* @__PURE__ */ new Map();
1591
+ var latestTraitSummaries = /* @__PURE__ */ new Map();
1592
+ var instanceLabels = /* @__PURE__ */ new Map();
1593
+ var convergeStaticIrByDigest = /* @__PURE__ */ new Map();
1594
+ var liveInstanceKeys = /* @__PURE__ */ new Set();
1595
+ var exportBudget = {
1596
+ dropped: 0,
1597
+ oversized: 0
1598
+ };
1599
+ var lastRunTs = 0;
1600
+ var lastRunTsSeq = 0;
1601
+ var nextRunId = () => {
1602
+ const ts = Date.now();
1603
+ if (ts === lastRunTs) {
1604
+ lastRunTsSeq += 1;
1605
+ } else {
1606
+ lastRunTs = ts;
1607
+ lastRunTsSeq = 0;
1608
+ }
1609
+ return lastRunTsSeq === 0 ? `run-${ts}` : `run-${ts}.${lastRunTsSeq}`;
1610
+ };
1611
+ var currentRunId = nextRunId();
1612
+ var nextSeq = 1;
1613
+ var bufferSize = 500;
1614
+ var ringBuffer = [];
1615
+ var ringBufferSeq = [];
1616
+ var snapshotToken = 0;
1617
+ var ensureRingBufferSize = () => {
1618
+ if (bufferSize <= 0) {
1619
+ ringBuffer.length = 0;
1620
+ ringBufferSeq.length = 0;
1621
+ return;
1622
+ }
1623
+ if (ringBuffer.length <= bufferSize) return;
1624
+ const excess = ringBuffer.length - bufferSize;
1625
+ ringBuffer.splice(0, excess);
1626
+ ringBufferSeq.splice(0, excess);
1627
+ };
1628
+ var trimRingBufferIfNeeded = () => {
1629
+ if (bufferSize <= 0) {
1630
+ ringBuffer.length = 0;
1631
+ ringBufferSeq.length = 0;
1632
+ return;
1633
+ }
1634
+ if (bufferSize <= 64) {
1635
+ ensureRingBufferSize();
1636
+ return;
1637
+ }
1638
+ const slack = Math.min(1024, Math.floor(bufferSize / 2));
1639
+ const threshold = bufferSize + Math.max(1, slack);
1640
+ if (ringBuffer.length <= threshold) return;
1641
+ const excess = ringBuffer.length - bufferSize;
1642
+ ringBuffer.splice(0, excess);
1643
+ ringBufferSeq.splice(0, excess);
1644
+ };
1645
+ var currentSnapshot = {
1646
+ snapshotToken,
1647
+ instances,
1648
+ events: ringBuffer,
1649
+ latestStates,
1650
+ latestTraitSummaries,
1651
+ exportBudget
1652
+ };
1653
+ var listeners = /* @__PURE__ */ new Set();
1654
+ var notifyScheduled = false;
1655
+ var scheduleNotify = () => {
1656
+ if (listeners.size === 0) return;
1657
+ if (notifyScheduled) return;
1658
+ notifyScheduled = true;
1659
+ getGlobalHostScheduler().scheduleMicrotask(() => {
1660
+ notifyScheduled = false;
1661
+ for (const listener of listeners) {
1662
+ listener();
1663
+ }
1664
+ });
1665
+ };
1666
+ var devtoolsEnabled = false;
1667
+ var bumpSnapshotToken = () => {
1668
+ snapshotToken += 1;
1669
+ currentSnapshot.snapshotToken = snapshotToken;
1670
+ };
1671
+ var markSnapshotChanged = () => {
1672
+ bumpSnapshotToken();
1673
+ scheduleNotify();
1674
+ };
1675
+ var configureDevtoolsHub = (options) => {
1676
+ devtoolsEnabled = true;
1677
+ if (typeof options?.bufferSize === "number" && Number.isFinite(options.bufferSize)) {
1678
+ const next = Math.floor(options.bufferSize);
1679
+ const nextBufferSize = next >= 0 ? next : 0;
1680
+ if (nextBufferSize !== bufferSize) {
1681
+ bufferSize = nextBufferSize;
1682
+ ensureRingBufferSize();
1683
+ markSnapshotChanged();
1684
+ }
1685
+ }
1686
+ };
1687
+ var isDevtoolsEnabled = () => devtoolsEnabled;
1688
+ var registerConvergeStaticIr = (ir) => {
1689
+ convergeStaticIrByDigest.set(ir.staticIrDigest, ir);
1690
+ };
1691
+ var devtoolsHubConvergeStaticIrCollector = {
1692
+ register: registerConvergeStaticIr
1693
+ };
1694
+ var devtoolsHubSink = {
1695
+ record: (event) => import_effect4.Effect.gen(function* () {
1696
+ const level = yield* import_effect4.FiberRef.get(currentDiagnosticsLevel);
1697
+ let changed = false;
1698
+ if (event.type === "trace:instanceLabel") {
1699
+ const instanceId = event.instanceId;
1700
+ const data = event.data;
1701
+ const label = data && typeof data === "object" && "label" in data ? String(data.label) : void 0;
1702
+ if (instanceId && label) {
1703
+ instanceLabels.set(instanceId, label);
1704
+ changed = true;
1705
+ }
1706
+ }
1707
+ if (event.type === "module:init" || event.type === "module:destroy") {
1708
+ const moduleId = event.moduleId ?? "unknown";
1709
+ const runtimeLabel2 = event.runtimeLabel ?? "unknown";
1710
+ const instanceId = event.instanceId;
1711
+ const key = `${runtimeLabel2}::${moduleId}`;
1712
+ const prev = instances.get(key) ?? 0;
1713
+ if (event.type === "module:init") {
1714
+ instances.set(key, prev + 1);
1715
+ changed = true;
1716
+ if (instanceId) {
1717
+ const instanceKey = `${runtimeLabel2}::${moduleId}::${instanceId}`;
1718
+ liveInstanceKeys.add(instanceKey);
1719
+ if (latestStates.delete(instanceKey)) changed = true;
1720
+ if (latestTraitSummaries.delete(instanceKey)) changed = true;
1721
+ }
1722
+ } else {
1723
+ const next = prev - 1;
1724
+ if (next <= 0) {
1725
+ if (instances.delete(key)) changed = true;
1726
+ } else {
1727
+ instances.set(key, next);
1728
+ changed = true;
1729
+ }
1730
+ if (instanceId) {
1731
+ const instanceKey = `${runtimeLabel2}::${moduleId}::${instanceId}`;
1732
+ liveInstanceKeys.delete(instanceKey);
1733
+ if (latestStates.delete(instanceKey)) changed = true;
1734
+ if (latestTraitSummaries.delete(instanceKey)) changed = true;
1735
+ if (instanceLabels.delete(instanceId)) changed = true;
1736
+ changed = true;
1737
+ }
1738
+ }
1739
+ }
1740
+ let exportBudgetChanged = false;
1741
+ const ref = toRuntimeDebugEventRef(event, {
1742
+ diagnosticsLevel: level,
1743
+ resolveConvergeStaticIr: (staticIrDigest) => convergeStaticIrByDigest.get(staticIrDigest),
1744
+ onMetaProjection: ({ stats }) => {
1745
+ if (stats.dropped !== 0 || stats.oversized !== 0) {
1746
+ exportBudgetChanged = true;
1747
+ }
1748
+ exportBudget.dropped += stats.dropped;
1749
+ exportBudget.oversized += stats.oversized;
1750
+ }
1751
+ });
1752
+ if (exportBudgetChanged) {
1753
+ changed = true;
1754
+ }
1755
+ if (!ref) {
1756
+ if (changed) {
1757
+ markSnapshotChanged();
1758
+ }
1759
+ return;
1760
+ }
1761
+ if (ref.kind === "state" && ref.label === "state:update") {
1762
+ const runtimeLabel2 = ref.runtimeLabel ?? "unknown";
1763
+ const key = `${runtimeLabel2}::${ref.moduleId}::${ref.instanceId}`;
1764
+ if (liveInstanceKeys.has(key)) {
1765
+ if (ref.meta && typeof ref.meta === "object" && !Array.isArray(ref.meta)) {
1766
+ const anyMeta = ref.meta;
1767
+ if ("state" in anyMeta) {
1768
+ latestStates.set(key, anyMeta.state);
1769
+ changed = true;
1770
+ }
1771
+ if ("traitSummary" in anyMeta && anyMeta.traitSummary !== void 0) {
1772
+ latestTraitSummaries.set(key, anyMeta.traitSummary);
1773
+ changed = true;
1774
+ }
1775
+ }
1776
+ }
1777
+ }
1778
+ if (bufferSize > 0) {
1779
+ const seq = nextSeq++;
1780
+ ringBuffer.push(ref);
1781
+ ringBufferSeq.push(seq);
1782
+ trimRingBufferIfNeeded();
1783
+ changed = true;
1784
+ }
1785
+ if (changed) {
1786
+ markSnapshotChanged();
1787
+ }
1788
+ })
1789
+ };
1790
+
1791
+ // src/internal/runtime/core/JobQueue.ts
1792
+ var maxPriority = (a, b) => a === "normal" || b === "normal" ? "normal" : "low";
1793
+ var makeJobQueue = () => {
1794
+ let pendingModules = /* @__PURE__ */ new Map();
1795
+ let pendingDirtyTopics = /* @__PURE__ */ new Map();
1796
+ const hasPending = () => pendingModules.size > 0 || pendingDirtyTopics.size > 0;
1797
+ const enqueueModuleCommit = (commit2) => {
1798
+ const prev = pendingModules.get(commit2.moduleInstanceKey);
1799
+ if (!prev) {
1800
+ pendingModules.set(commit2.moduleInstanceKey, commit2);
1801
+ return false;
1802
+ }
1803
+ pendingModules.set(commit2.moduleInstanceKey, {
1804
+ ...commit2,
1805
+ meta: {
1806
+ ...commit2.meta,
1807
+ priority: maxPriority(prev.meta.priority, commit2.meta.priority)
1808
+ }
1809
+ });
1810
+ return true;
1811
+ };
1812
+ const markTopicDirty = (topicKey, priority) => {
1813
+ const prev = pendingDirtyTopics.get(topicKey);
1814
+ pendingDirtyTopics.set(topicKey, prev ? maxPriority(prev, priority) : priority);
1815
+ return prev != null;
1816
+ };
1817
+ const drain = () => {
1818
+ if (!hasPending()) return void 0;
1819
+ const drained = {
1820
+ modules: pendingModules,
1821
+ dirtyTopics: pendingDirtyTopics
1822
+ };
1823
+ pendingModules = /* @__PURE__ */ new Map();
1824
+ pendingDirtyTopics = /* @__PURE__ */ new Map();
1825
+ return drained;
1826
+ };
1827
+ const requeue = (drain2) => {
1828
+ for (const [, commit2] of drain2.modules) {
1829
+ enqueueModuleCommit(commit2);
1830
+ }
1831
+ for (const [k, p] of drain2.dirtyTopics) {
1832
+ markTopicDirty(k, p);
1833
+ }
1834
+ };
1835
+ return {
1836
+ hasPending,
1837
+ enqueueModuleCommit,
1838
+ markTopicDirty,
1839
+ drain,
1840
+ requeue
1841
+ };
1280
1842
  };
1281
1843
 
1282
1844
  // src/internal/runtime/core/TaskRunner.ts
1283
- var import_effect6 = require("effect");
1284
- var inSyncTransactionFiber = import_effect6.FiberRef.unsafeMake(false);
1285
- var forceSourceRefresh = import_effect6.FiberRef.unsafeMake(false);
1845
+ var import_effect5 = require("effect");
1846
+ var inSyncTransactionFiber = import_effect5.FiberRef.unsafeMake(false);
1847
+ var forceSourceRefresh = import_effect5.FiberRef.unsafeMake(false);
1286
1848
  var inSyncTransactionGlobalDepth = 0;
1287
1849
  var isInSyncTransaction = () => inSyncTransactionGlobalDepth > 0;
1288
1850
  var resolve = (eff, payload) => typeof eff === "function" ? eff(payload) : eff;
@@ -1300,8 +1862,8 @@ var defaultOrigins = (triggerName) => ({
1300
1862
  name: "task:failure"
1301
1863
  }
1302
1864
  });
1303
- var shouldNoopInSyncTransactionFiber = (options) => import_effect6.Effect.gen(function* () {
1304
- const inTxn = yield* import_effect6.FiberRef.get(inSyncTransactionFiber);
1865
+ var shouldNoopInSyncTransactionFiber = (options) => import_effect5.Effect.gen(function* () {
1866
+ const inTxn = yield* import_effect5.FiberRef.get(inSyncTransactionFiber);
1305
1867
  if (!inTxn) {
1306
1868
  return false;
1307
1869
  }
@@ -1320,8 +1882,8 @@ var shouldNoopInSyncTransactionFiber = (options) => import_effect6.Effect.gen(fu
1320
1882
  }
1321
1883
  return true;
1322
1884
  });
1323
- var resolveConcurrencyLimit = (runtime) => runtime.resolveConcurrencyPolicy ? runtime.resolveConcurrencyPolicy().pipe(import_effect6.Effect.map((p) => p.concurrencyLimit)) : import_effect6.Effect.succeed(16);
1324
- var runTaskLifecycle = (payload, runtime, config, getCanWriteBack) => import_effect6.Effect.gen(function* () {
1885
+ var resolveConcurrencyLimit = (runtime) => runtime.resolveConcurrencyPolicy ? runtime.resolveConcurrencyPolicy().pipe(import_effect5.Effect.map((p) => p.concurrencyLimit)) : import_effect5.Effect.succeed(16);
1886
+ var runTaskLifecycle = (payload, runtime, config, getCanWriteBack) => import_effect5.Effect.gen(function* () {
1325
1887
  const noop = yield* shouldNoopInSyncTransactionFiber({
1326
1888
  moduleId: runtime.moduleId,
1327
1889
  instanceId: runtime.instanceId,
@@ -1342,12 +1904,12 @@ var runTaskLifecycle = (payload, runtime, config, getCanWriteBack) => import_eff
1342
1904
  };
1343
1905
  const pending = config.pending;
1344
1906
  if (pending) {
1345
- yield* import_effect6.Effect.uninterruptible(
1346
- runtime.runWithStateTransaction(origins.pending, () => import_effect6.Effect.asVoid(resolve(pending, payload)))
1907
+ yield* import_effect5.Effect.uninterruptible(
1908
+ runtime.runWithStateTransaction(origins.pending, () => import_effect5.Effect.asVoid(resolve(pending, payload)))
1347
1909
  );
1348
1910
  }
1349
1911
  const io = resolve(config.effect, payload);
1350
- const exit = yield* import_effect6.Effect.exit(io);
1912
+ const exit = yield* import_effect5.Effect.exit(io);
1351
1913
  if (getCanWriteBack) {
1352
1914
  const ok = yield* getCanWriteBack;
1353
1915
  if (!ok) {
@@ -1357,21 +1919,21 @@ var runTaskLifecycle = (payload, runtime, config, getCanWriteBack) => import_eff
1357
1919
  if (exit._tag === "Success") {
1358
1920
  const success = config.success;
1359
1921
  if (success) {
1360
- yield* runtime.runWithStateTransaction(origins.success, () => import_effect6.Effect.asVoid(success(exit.value, payload)));
1922
+ yield* runtime.runWithStateTransaction(origins.success, () => import_effect5.Effect.asVoid(success(exit.value, payload)));
1361
1923
  }
1362
1924
  return;
1363
1925
  }
1364
1926
  const cause = exit.cause;
1365
- if (import_effect6.Cause.isInterrupted(cause)) {
1927
+ if (import_effect5.Cause.isInterrupted(cause)) {
1366
1928
  return;
1367
1929
  }
1368
1930
  const failure = config.failure;
1369
1931
  if (failure) {
1370
- yield* runtime.runWithStateTransaction(origins.failure, () => import_effect6.Effect.asVoid(failure(cause, payload)));
1932
+ yield* runtime.runWithStateTransaction(origins.failure, () => import_effect5.Effect.asVoid(failure(cause, payload)));
1371
1933
  }
1372
1934
  }).pipe(
1373
1935
  // Watchers must not crash as a whole due to a single task failure: swallow errors, but keep them diagnosable.
1374
- import_effect6.Effect.catchAllCause(
1936
+ import_effect5.Effect.catchAllCause(
1375
1937
  (cause) => record({
1376
1938
  type: "diagnostic",
1377
1939
  moduleId: runtime.moduleId,
@@ -1386,35 +1948,35 @@ var runTaskLifecycle = (payload, runtime, config, getCanWriteBack) => import_eff
1386
1948
  kind: "task",
1387
1949
  name: config.triggerName
1388
1950
  }
1389
- }).pipe(import_effect6.Effect.zipRight(import_effect6.Effect.logError("TaskRunner error", cause)))
1951
+ }).pipe(import_effect5.Effect.zipRight(import_effect5.Effect.logError("TaskRunner error", cause)))
1390
1952
  )
1391
1953
  );
1392
1954
  var makeTaskRunner = (stream, mode, runtime, config) => {
1393
1955
  if (mode === "latest") {
1394
- return import_effect6.Effect.gen(function* () {
1395
- const taskIdRef = yield* import_effect6.Ref.make(0);
1396
- const currentFiberRef = yield* import_effect6.Ref.make(void 0);
1397
- const start = (payload) => import_effect6.Effect.gen(function* () {
1398
- const taskId = yield* import_effect6.Ref.updateAndGet(taskIdRef, (n) => n + 1);
1399
- const prev = yield* import_effect6.Ref.get(currentFiberRef);
1956
+ return import_effect5.Effect.gen(function* () {
1957
+ const taskIdRef = yield* import_effect5.Ref.make(0);
1958
+ const currentFiberRef = yield* import_effect5.Ref.make(void 0);
1959
+ const start = (payload) => import_effect5.Effect.gen(function* () {
1960
+ const taskId = yield* import_effect5.Ref.updateAndGet(taskIdRef, (n) => n + 1);
1961
+ const prev = yield* import_effect5.Ref.get(currentFiberRef);
1400
1962
  if (prev) {
1401
- yield* import_effect6.Fiber.interruptFork(prev);
1963
+ yield* import_effect5.Fiber.interruptFork(prev);
1402
1964
  }
1403
- const canWriteBack = import_effect6.Ref.get(taskIdRef).pipe(import_effect6.Effect.map((current) => current === taskId));
1404
- const fiber = yield* import_effect6.Effect.fork(
1965
+ const canWriteBack = import_effect5.Ref.get(taskIdRef).pipe(import_effect5.Effect.map((current) => current === taskId));
1966
+ const fiber = yield* import_effect5.Effect.fork(
1405
1967
  runTaskLifecycle(payload, runtime, config, canWriteBack)
1406
1968
  );
1407
- yield* import_effect6.Ref.set(currentFiberRef, fiber);
1969
+ yield* import_effect5.Ref.set(currentFiberRef, fiber);
1408
1970
  });
1409
- return yield* import_effect6.Stream.runForEach(stream, start);
1971
+ return yield* import_effect5.Stream.runForEach(stream, start);
1410
1972
  });
1411
1973
  }
1412
1974
  if (mode === "exhaust") {
1413
- return import_effect6.Effect.gen(function* () {
1975
+ return import_effect5.Effect.gen(function* () {
1414
1976
  const concurrency = yield* resolveConcurrencyLimit(runtime);
1415
- const busyRef = yield* import_effect6.Ref.make(false);
1416
- const mapper = (payload) => import_effect6.Effect.gen(function* () {
1417
- const acquired = yield* import_effect6.Ref.modify(
1977
+ const busyRef = yield* import_effect5.Ref.make(false);
1978
+ const mapper = (payload) => import_effect5.Effect.gen(function* () {
1979
+ const acquired = yield* import_effect5.Ref.modify(
1418
1980
  busyRef,
1419
1981
  (busy) => busy ? [false, busy] : [true, true]
1420
1982
  );
@@ -1424,30 +1986,725 @@ var makeTaskRunner = (stream, mode, runtime, config) => {
1424
1986
  try {
1425
1987
  yield* runTaskLifecycle(payload, runtime, config);
1426
1988
  } finally {
1427
- yield* import_effect6.Ref.set(busyRef, false);
1989
+ yield* import_effect5.Ref.set(busyRef, false);
1428
1990
  }
1429
1991
  });
1430
- return yield* import_effect6.Stream.runDrain(stream.pipe(import_effect6.Stream.mapEffect(mapper, { concurrency })));
1992
+ return yield* import_effect5.Stream.runDrain(stream.pipe(import_effect5.Stream.mapEffect(mapper, { concurrency })));
1431
1993
  });
1432
1994
  }
1433
1995
  if (mode === "parallel") {
1434
- return import_effect6.Effect.gen(function* () {
1996
+ return import_effect5.Effect.gen(function* () {
1435
1997
  const concurrency = yield* resolveConcurrencyLimit(runtime);
1436
- return yield* import_effect6.Stream.runDrain(
1998
+ return yield* import_effect5.Stream.runDrain(
1437
1999
  stream.pipe(
1438
- import_effect6.Stream.mapEffect((payload) => runTaskLifecycle(payload, runtime, config), {
2000
+ import_effect5.Stream.mapEffect((payload) => runTaskLifecycle(payload, runtime, config), {
1439
2001
  concurrency
1440
2002
  })
1441
2003
  )
1442
2004
  );
1443
2005
  });
1444
2006
  }
1445
- return import_effect6.Stream.runForEach(
2007
+ return import_effect5.Stream.runForEach(
1446
2008
  stream,
1447
2009
  (payload) => runTaskLifecycle(payload, runtime, config)
1448
2010
  );
1449
2011
  };
1450
2012
 
2013
+ // src/internal/runtime/core/TickScheduler.ts
2014
+ var batchDepth = 0;
2015
+ var batchWaiters = /* @__PURE__ */ new Set();
2016
+ var enterRuntimeBatch = () => {
2017
+ batchDepth += 1;
2018
+ };
2019
+ var exitRuntimeBatch = () => {
2020
+ batchDepth = Math.max(0, batchDepth - 1);
2021
+ if (batchDepth !== 0) return;
2022
+ const waiters = Array.from(batchWaiters);
2023
+ batchWaiters.clear();
2024
+ for (const w of waiters) {
2025
+ try {
2026
+ w.resolve();
2027
+ } catch {
2028
+ }
2029
+ }
2030
+ };
2031
+ var waitForBatchEndIfNeeded = () => batchDepth === 0 ? import_effect6.Effect.void : import_effect6.Effect.async((resume, signal) => {
2032
+ let done = false;
2033
+ const cleanup = () => {
2034
+ if (done) return;
2035
+ done = true;
2036
+ batchWaiters.delete(waiter);
2037
+ try {
2038
+ signal.removeEventListener("abort", onAbort);
2039
+ } catch {
2040
+ }
2041
+ };
2042
+ const onAbort = () => {
2043
+ cleanup();
2044
+ };
2045
+ const waiter = {
2046
+ resolve: () => {
2047
+ cleanup();
2048
+ resume(import_effect6.Effect.void);
2049
+ }
2050
+ };
2051
+ batchWaiters.add(waiter);
2052
+ try {
2053
+ signal.addEventListener("abort", onAbort, { once: true });
2054
+ } catch {
2055
+ }
2056
+ });
2057
+ var clampSampleRate = (sampleRate) => {
2058
+ if (typeof sampleRate !== "number" || !Number.isFinite(sampleRate)) return 0;
2059
+ if (sampleRate <= 0) return 0;
2060
+ if (sampleRate >= 1) return 1;
2061
+ return sampleRate;
2062
+ };
2063
+ var shouldSampleTick = (tickSeq, sampleRate) => {
2064
+ if (sampleRate <= 0) return false;
2065
+ if (sampleRate >= 1) return true;
2066
+ const x = tickSeq >>> 0;
2067
+ const h = Math.imul(x ^ 2654435769, 2246822507) >>> 0;
2068
+ return h / 4294967295 < sampleRate;
2069
+ };
2070
+ var toTriggerKind = (originKind) => {
2071
+ if (originKind === "action") return "dispatch";
2072
+ if (originKind === "trait-external-store") return "externalStore";
2073
+ if (originKind?.includes("timer")) return "timer";
2074
+ return "unknown";
2075
+ };
2076
+ var toLane = (priority) => priority === "low" ? "nonUrgent" : "urgent";
2077
+ var maxPriority2 = (a, b) => a === "normal" || b === "normal" ? "normal" : "low";
2078
+ var mergeDrain = (base, next) => {
2079
+ const modules = new Map(base.modules);
2080
+ for (const [k, commit2] of next.modules) {
2081
+ const prev = modules.get(k);
2082
+ if (!prev) {
2083
+ modules.set(k, commit2);
2084
+ } else {
2085
+ modules.set(k, {
2086
+ ...commit2,
2087
+ meta: {
2088
+ ...commit2.meta,
2089
+ priority: maxPriority2(prev.meta.priority, commit2.meta.priority)
2090
+ }
2091
+ });
2092
+ }
2093
+ }
2094
+ const dirtyTopics = new Map(base.dirtyTopics);
2095
+ for (const [k, p] of next.dirtyTopics) {
2096
+ const prev = dirtyTopics.get(k);
2097
+ dirtyTopics.set(k, prev ? maxPriority2(prev, p) : p);
2098
+ }
2099
+ return { modules, dirtyTopics };
2100
+ };
2101
+ var emptyDrain = () => ({ modules: /* @__PURE__ */ new Map(), dirtyTopics: /* @__PURE__ */ new Map() });
2102
+ var makeTickScheduler = (args) => {
2103
+ const store = args.runtimeStore;
2104
+ const hostScheduler = args.hostScheduler;
2105
+ const declarativeLinks = args.declarativeLinkRuntime;
2106
+ const queue = args.queue ?? makeJobQueue();
2107
+ const config = {
2108
+ maxSteps: args.config?.maxSteps ?? 64,
2109
+ urgentStepCap: args.config?.urgentStepCap ?? 512,
2110
+ maxDrainRounds: args.config?.maxDrainRounds ?? 8,
2111
+ microtaskChainDepthLimit: args.config?.microtaskChainDepthLimit ?? 32
2112
+ };
2113
+ const telemetry = args.config?.telemetry;
2114
+ const telemetrySampleRate = clampSampleRate(telemetry?.sampleRate);
2115
+ let tickSeq = 0;
2116
+ let scheduled = false;
2117
+ let microtaskChainDepth = 0;
2118
+ let nextForcedReason;
2119
+ let coalescedModules = 0;
2120
+ let coalescedTopics = 0;
2121
+ const yieldMicrotask = import_effect6.Effect.async((resume) => {
2122
+ hostScheduler.scheduleMicrotask(() => resume(import_effect6.Effect.void));
2123
+ });
2124
+ const yieldMacrotask = import_effect6.Effect.async((resume, signal) => {
2125
+ const cancel = hostScheduler.scheduleMacrotask(() => resume(import_effect6.Effect.void));
2126
+ try {
2127
+ signal.addEventListener(
2128
+ "abort",
2129
+ () => {
2130
+ cancel();
2131
+ },
2132
+ { once: true }
2133
+ );
2134
+ } catch {
2135
+ }
2136
+ });
2137
+ const scheduleTick = () => import_effect6.Effect.gen(function* () {
2138
+ if (scheduled) return;
2139
+ scheduled = true;
2140
+ const waitedForBatch = batchDepth > 0;
2141
+ const forcedReason = nextForcedReason;
2142
+ nextForcedReason = void 0;
2143
+ const shouldYieldForStarvation = forcedReason == null && microtaskChainDepth >= Math.max(1, config.microtaskChainDepthLimit);
2144
+ const reason = forcedReason ?? (shouldYieldForStarvation ? "microtask_starvation" : void 0);
2145
+ const boundary = reason ? "macrotask" : "microtask";
2146
+ const startedAs = waitedForBatch ? "batch" : boundary;
2147
+ const depthAtSchedule = microtaskChainDepth;
2148
+ yield* import_effect6.Effect.forkDaemon(
2149
+ import_effect6.Effect.locally(inSyncTransactionFiber, false)(
2150
+ import_effect6.Effect.gen(function* () {
2151
+ try {
2152
+ yield* waitForBatchEndIfNeeded();
2153
+ if (boundary === "microtask") {
2154
+ yield* yieldMicrotask;
2155
+ microtaskChainDepth += 1;
2156
+ } else {
2157
+ yield* yieldMacrotask;
2158
+ microtaskChainDepth = 0;
2159
+ }
2160
+ const schedule = {
2161
+ startedAs,
2162
+ microtaskChainDepth: boundary === "macrotask" ? depthAtSchedule : microtaskChainDepth,
2163
+ ...boundary === "macrotask" ? { forcedMacrotask: true, reason: reason ?? "unknown" } : {}
2164
+ };
2165
+ const outcome = yield* flushTick(schedule);
2166
+ if (!outcome.stable) {
2167
+ nextForcedReason = outcome.degradeReason === "budget_steps" ? "budget" : outcome.degradeReason === "cycle_detected" ? "cycle_detected" : "unknown";
2168
+ }
2169
+ } finally {
2170
+ scheduled = false;
2171
+ if (queue.hasPending()) {
2172
+ yield* scheduleTick();
2173
+ } else {
2174
+ microtaskChainDepth = 0;
2175
+ }
2176
+ }
2177
+ })
2178
+ )
2179
+ );
2180
+ });
2181
+ const flushTick = (schedule) => import_effect6.Effect.gen(function* () {
2182
+ if (!queue.hasPending()) {
2183
+ return { stable: true };
2184
+ }
2185
+ tickSeq += 1;
2186
+ const currentTickSeq = tickSeq;
2187
+ const diagnosticsLevel2 = yield* import_effect6.FiberRef.get(currentDiagnosticsLevel);
2188
+ const shouldEmitTrace = isDevtoolsEnabled() && diagnosticsLevel2 !== "off";
2189
+ const captured = {
2190
+ drainRounds: 0,
2191
+ stable: true,
2192
+ accepted: emptyDrain()
2193
+ };
2194
+ while (captured.drainRounds < config.maxDrainRounds) {
2195
+ const drained = queue.drain();
2196
+ if (!drained) break;
2197
+ captured.drainRounds += 1;
2198
+ captured.accepted = mergeDrain(captured.accepted, drained);
2199
+ if (declarativeLinks && drained.modules.size > 0) {
2200
+ const changedModuleInstanceKeys = Array.from(drained.modules.keys());
2201
+ yield* declarativeLinks.applyForSources({
2202
+ tickSeq: currentTickSeq,
2203
+ acceptedModules: captured.accepted.modules,
2204
+ changedModuleInstanceKeys
2205
+ });
2206
+ }
2207
+ }
2208
+ if (queue.hasPending()) {
2209
+ captured.stable = false;
2210
+ captured.degradeReason = "cycle_detected";
2211
+ }
2212
+ const urgentModules = [];
2213
+ const nonUrgentModules = [];
2214
+ for (const commit2 of captured.accepted.modules.values()) {
2215
+ if (toLane(commit2.meta.priority) === "urgent") {
2216
+ urgentModules.push(commit2);
2217
+ } else {
2218
+ nonUrgentModules.push(commit2);
2219
+ }
2220
+ }
2221
+ const urgentCapExceeded = urgentModules.length > config.urgentStepCap;
2222
+ const urgentAccepted = urgentCapExceeded ? urgentModules.slice(0, config.urgentStepCap) : urgentModules;
2223
+ const urgentDeferred = urgentCapExceeded ? urgentModules.slice(config.urgentStepCap) : [];
2224
+ const nonUrgentBudget = Math.max(0, config.maxSteps);
2225
+ const nonUrgentAccepted = urgentCapExceeded ? [] : nonUrgentModules.slice(0, nonUrgentBudget);
2226
+ const nonUrgentDeferred = urgentCapExceeded ? nonUrgentModules : nonUrgentModules.slice(nonUrgentBudget);
2227
+ if (urgentCapExceeded) {
2228
+ captured.stable = false;
2229
+ captured.degradeReason = "cycle_detected";
2230
+ } else if (nonUrgentDeferred.length > 0) {
2231
+ captured.stable = false;
2232
+ captured.degradeReason = captured.degradeReason ?? "budget_steps";
2233
+ }
2234
+ const acceptedModules = /* @__PURE__ */ new Map();
2235
+ const deferredModules = /* @__PURE__ */ new Map();
2236
+ for (const c of urgentAccepted) acceptedModules.set(c.moduleInstanceKey, c);
2237
+ for (const c of nonUrgentAccepted) acceptedModules.set(c.moduleInstanceKey, c);
2238
+ for (const c of urgentDeferred) deferredModules.set(c.moduleInstanceKey, c);
2239
+ for (const c of nonUrgentDeferred) deferredModules.set(c.moduleInstanceKey, c);
2240
+ const acceptedTopics = /* @__PURE__ */ new Map();
2241
+ const deferredTopics = /* @__PURE__ */ new Map();
2242
+ for (const [topicKey, priority] of captured.accepted.dirtyTopics) {
2243
+ const info = storeTopicToModuleInstanceKey(topicKey);
2244
+ if (!info) continue;
2245
+ if (acceptedModules.has(info)) {
2246
+ acceptedTopics.set(topicKey, priority);
2247
+ } else if (deferredModules.has(info)) {
2248
+ deferredTopics.set(topicKey, priority);
2249
+ } else {
2250
+ acceptedTopics.set(topicKey, priority);
2251
+ }
2252
+ }
2253
+ const acceptedDrain = {
2254
+ modules: acceptedModules,
2255
+ dirtyTopics: acceptedTopics
2256
+ };
2257
+ const deferredDrain = deferredModules.size > 0 || deferredTopics.size > 0 ? {
2258
+ modules: deferredModules,
2259
+ dirtyTopics: deferredTopics
2260
+ } : void 0;
2261
+ captured.deferred = deferredDrain;
2262
+ let startedAtMs;
2263
+ let triggerSummary;
2264
+ let anchor;
2265
+ let backlog;
2266
+ let result;
2267
+ if (shouldEmitTrace) {
2268
+ startedAtMs = Date.now();
2269
+ triggerSummary = (() => {
2270
+ const triggers = Array.from(captured.accepted.modules.values());
2271
+ const counts = /* @__PURE__ */ new Map();
2272
+ let primary = void 0;
2273
+ for (const t of triggers) {
2274
+ const kind = toTriggerKind(t.meta.originKind);
2275
+ counts.set(kind, (counts.get(kind) ?? 0) + 1);
2276
+ if (!primary) {
2277
+ primary = {
2278
+ kind,
2279
+ moduleId: t.moduleId,
2280
+ instanceId: t.instanceId,
2281
+ fieldPath: kind === "externalStore" ? t.meta.originName : void 0,
2282
+ actionTag: kind === "dispatch" ? t.meta.originName : void 0
2283
+ };
2284
+ }
2285
+ }
2286
+ return {
2287
+ total: triggers.length,
2288
+ kinds: Array.from(counts.entries()).map(([kind, count]) => ({ kind, count })),
2289
+ primary,
2290
+ coalescedCount: {
2291
+ modules: coalescedModules,
2292
+ topics: coalescedTopics
2293
+ }
2294
+ };
2295
+ })();
2296
+ anchor = (() => {
2297
+ const first = captured.accepted.modules.values().next().value;
2298
+ if (!first) return void 0;
2299
+ return {
2300
+ moduleId: first.moduleId,
2301
+ instanceId: first.instanceId,
2302
+ txnSeq: first.meta.txnSeq,
2303
+ txnId: first.meta.txnId,
2304
+ ...typeof first.opSeq === "number" ? { opSeq: first.opSeq } : null
2305
+ };
2306
+ })();
2307
+ backlog = (() => {
2308
+ const deferredWork = captured.deferred;
2309
+ if (!deferredWork) return void 0;
2310
+ const pendingDeferredWork = deferredWork.modules.size + deferredWork.dirtyTopics.size;
2311
+ const deferredModulesList = Array.from(deferredWork.modules.values());
2312
+ const pendingExternalInputs = deferredModulesList.filter((m) => toTriggerKind(m.meta.originKind) === "externalStore").length;
2313
+ const primaryDeferred = deferredModulesList.find((m) => toTriggerKind(m.meta.originKind) === "externalStore") ?? deferredModulesList[0];
2314
+ const kind = primaryDeferred ? toTriggerKind(primaryDeferred.meta.originKind) : "unknown";
2315
+ const deferredPrimary = primaryDeferred != null ? {
2316
+ kind: kind === "externalStore" ? "externalStore" : "unknown",
2317
+ moduleId: primaryDeferred.moduleId,
2318
+ instanceId: primaryDeferred.instanceId,
2319
+ fieldPath: kind === "externalStore" ? primaryDeferred.meta.originName : void 0,
2320
+ storeId: void 0
2321
+ } : void 0;
2322
+ return {
2323
+ pendingExternalInputs,
2324
+ pendingDeferredWork,
2325
+ deferredPrimary
2326
+ };
2327
+ })();
2328
+ result = {
2329
+ stable: captured.stable,
2330
+ ...captured.stable ? null : { degradeReason: captured.degradeReason ?? "unknown" }
2331
+ };
2332
+ }
2333
+ if (shouldEmitTrace && schedule.forcedMacrotask && schedule.reason === "microtask_starvation") {
2334
+ yield* record({
2335
+ type: "warn:microtask-starvation",
2336
+ moduleId: anchor?.moduleId,
2337
+ instanceId: anchor?.instanceId,
2338
+ tickSeq: currentTickSeq,
2339
+ microtaskChainDepth: schedule.microtaskChainDepth
2340
+ });
2341
+ }
2342
+ if (shouldEmitTrace) {
2343
+ yield* record({
2344
+ type: "trace:tick",
2345
+ moduleId: anchor?.moduleId,
2346
+ instanceId: anchor?.instanceId,
2347
+ data: {
2348
+ tickSeq: currentTickSeq,
2349
+ phase: "start",
2350
+ timestampMs: startedAtMs,
2351
+ schedule,
2352
+ triggerSummary,
2353
+ anchors: anchor,
2354
+ budget: {
2355
+ maxSteps: config.maxSteps,
2356
+ elapsedMs: 0,
2357
+ steps: 0,
2358
+ txnCount: acceptedModules.size
2359
+ }
2360
+ }
2361
+ });
2362
+ }
2363
+ if (!captured.stable && shouldEmitTrace) {
2364
+ yield* record({
2365
+ type: "trace:tick",
2366
+ moduleId: anchor?.moduleId,
2367
+ instanceId: anchor?.instanceId,
2368
+ data: {
2369
+ tickSeq: currentTickSeq,
2370
+ phase: "budgetExceeded",
2371
+ timestampMs: Date.now(),
2372
+ schedule,
2373
+ triggerSummary,
2374
+ anchors: anchor,
2375
+ budget: {
2376
+ maxSteps: config.maxSteps,
2377
+ elapsedMs: Math.max(0, Date.now() - startedAtMs),
2378
+ steps: config.maxSteps,
2379
+ txnCount: acceptedModules.size
2380
+ },
2381
+ backlog,
2382
+ result
2383
+ }
2384
+ });
2385
+ }
2386
+ if (deferredDrain) {
2387
+ queue.requeue(deferredDrain);
2388
+ }
2389
+ const committed = store.commitTick({
2390
+ tickSeq: currentTickSeq,
2391
+ accepted: acceptedDrain
2392
+ });
2393
+ for (const { listeners: listeners2 } of committed.changedTopics.values()) {
2394
+ for (const listener of listeners2) {
2395
+ try {
2396
+ listener();
2397
+ } catch {
2398
+ }
2399
+ }
2400
+ }
2401
+ if (!captured.stable && shouldEmitTrace && backlog?.deferredPrimary) {
2402
+ const primary = backlog.deferredPrimary;
2403
+ if (primary.kind === "externalStore") {
2404
+ const moduleInstanceKey = primary.moduleId && primary.instanceId ? `${primary.moduleId}::${primary.instanceId}` : void 0;
2405
+ if (moduleInstanceKey && store.getModuleSubscriberCount(moduleInstanceKey) > 0) {
2406
+ yield* record({
2407
+ type: "warn:priority-inversion",
2408
+ moduleId: primary.moduleId,
2409
+ instanceId: primary.instanceId,
2410
+ tickSeq: currentTickSeq,
2411
+ reason: "deferredBacklog"
2412
+ });
2413
+ }
2414
+ }
2415
+ }
2416
+ if (shouldEmitTrace) {
2417
+ yield* record({
2418
+ type: "trace:tick",
2419
+ moduleId: anchor?.moduleId,
2420
+ instanceId: anchor?.instanceId,
2421
+ data: {
2422
+ tickSeq: currentTickSeq,
2423
+ phase: "settled",
2424
+ timestampMs: Date.now(),
2425
+ schedule,
2426
+ triggerSummary,
2427
+ anchors: anchor,
2428
+ budget: {
2429
+ maxSteps: config.maxSteps,
2430
+ elapsedMs: Math.max(0, Date.now() - startedAtMs),
2431
+ steps: acceptedModules.size,
2432
+ txnCount: acceptedModules.size
2433
+ },
2434
+ backlog,
2435
+ result
2436
+ }
2437
+ });
2438
+ }
2439
+ if (telemetry?.onTickDegraded && (schedule.forcedMacrotask || !captured.stable) && shouldSampleTick(currentTickSeq, telemetrySampleRate)) {
2440
+ try {
2441
+ telemetry.onTickDegraded({
2442
+ tickSeq: currentTickSeq,
2443
+ stable: captured.stable,
2444
+ degradeReason: captured.stable ? void 0 : captured.degradeReason ?? "unknown",
2445
+ forcedMacrotask: schedule.forcedMacrotask,
2446
+ scheduleReason: schedule.reason,
2447
+ microtaskChainDepth: schedule.microtaskChainDepth,
2448
+ deferredWorkCount: deferredDrain ? deferredDrain.modules.size + deferredDrain.dirtyTopics.size : 0
2449
+ });
2450
+ } catch {
2451
+ }
2452
+ }
2453
+ coalescedModules = 0;
2454
+ coalescedTopics = 0;
2455
+ return { stable: captured.stable, degradeReason: captured.degradeReason };
2456
+ });
2457
+ const flushNow = flushTick({ startedAs: "unknown" }).pipe(import_effect6.Effect.asVoid);
2458
+ const storeTopicToModuleInstanceKey = (topicKey) => {
2459
+ const idx = topicKey.indexOf("::rq:");
2460
+ if (idx > 0) {
2461
+ return topicKey.slice(0, idx);
2462
+ }
2463
+ if (topicKey.includes("::")) {
2464
+ return topicKey;
2465
+ }
2466
+ return void 0;
2467
+ };
2468
+ const onSelectorChanged = ({ moduleInstanceKey, selectorId, priority }) => {
2469
+ const coalesced = queue.markTopicDirty(makeReadQueryTopicKey(moduleInstanceKey, selectorId), priority);
2470
+ if (coalesced) coalescedTopics += 1;
2471
+ };
2472
+ const onModuleCommit = (commit2) => import_effect6.Effect.gen(function* () {
2473
+ const coalescedCommit = queue.enqueueModuleCommit(commit2);
2474
+ if (coalescedCommit) coalescedModules += 1;
2475
+ const coalescedTopic = queue.markTopicDirty(commit2.moduleInstanceKey, commit2.meta.priority);
2476
+ if (coalescedTopic) coalescedTopics += 1;
2477
+ yield* scheduleTick();
2478
+ });
2479
+ return {
2480
+ getTickSeq: () => tickSeq,
2481
+ onModuleCommit,
2482
+ onSelectorChanged,
2483
+ flushNow
2484
+ };
2485
+ };
2486
+
2487
+ // src/internal/runtime/core/DeclarativeLinkRuntime.ts
2488
+ var import_effect7 = require("effect");
2489
+ var makeDeclarativeLinkRuntime = () => {
2490
+ const moduleAsSourceById = /* @__PURE__ */ new Map();
2491
+ const moduleAsSourceIdsBySource = /* @__PURE__ */ new Map();
2492
+ const declarativeById = /* @__PURE__ */ new Map();
2493
+ const declarativeReadNodesBySource = /* @__PURE__ */ new Map();
2494
+ const registerModuleAsSourceLink = (link) => {
2495
+ const stored = {
2496
+ ...link,
2497
+ hasValue: false,
2498
+ lastValue: void 0
2499
+ };
2500
+ moduleAsSourceById.set(link.id, stored);
2501
+ const set = moduleAsSourceIdsBySource.get(link.sourceModuleInstanceKey) ?? /* @__PURE__ */ new Set();
2502
+ set.add(link.id);
2503
+ moduleAsSourceIdsBySource.set(link.sourceModuleInstanceKey, set);
2504
+ return () => {
2505
+ moduleAsSourceById.delete(link.id);
2506
+ const current = moduleAsSourceIdsBySource.get(link.sourceModuleInstanceKey);
2507
+ if (!current) return;
2508
+ current.delete(link.id);
2509
+ if (current.size === 0) {
2510
+ moduleAsSourceIdsBySource.delete(link.sourceModuleInstanceKey);
2511
+ }
2512
+ };
2513
+ };
2514
+ const registerDeclarativeLink = (link) => {
2515
+ const readNodeById = /* @__PURE__ */ new Map();
2516
+ for (const n of link.readNodes) {
2517
+ readNodeById.set(n.nodeId, n);
2518
+ }
2519
+ const dispatchNodeById = /* @__PURE__ */ new Map();
2520
+ for (const n of link.dispatchNodes) {
2521
+ dispatchNodeById.set(n.nodeId, n);
2522
+ }
2523
+ const incomingByDispatch = /* @__PURE__ */ new Map();
2524
+ for (const e of link.ir.edges) {
2525
+ const to = e.to;
2526
+ const isDispatch = dispatchNodeById.has(to);
2527
+ if (!isDispatch) continue;
2528
+ incomingByDispatch.set(to, (incomingByDispatch.get(to) ?? 0) + 1);
2529
+ const count = incomingByDispatch.get(to) ?? 0;
2530
+ if (count > 1) {
2531
+ throw new Error(
2532
+ `[DeclarativeLinkRuntime] Invalid DeclarativeLinkIR: dispatch node has multiple incoming edges (linkId=${link.linkId}, nodeId=${to}).`
2533
+ );
2534
+ }
2535
+ }
2536
+ const dispatchTargetsByReadNode = /* @__PURE__ */ new Map();
2537
+ for (const e of link.ir.edges) {
2538
+ const from = e.from;
2539
+ const to = e.to;
2540
+ if (!readNodeById.has(from)) continue;
2541
+ if (!dispatchNodeById.has(to)) continue;
2542
+ const list = dispatchTargetsByReadNode.get(from) ?? [];
2543
+ list.push(to);
2544
+ dispatchTargetsByReadNode.set(from, list);
2545
+ }
2546
+ const stored = {
2547
+ ...link,
2548
+ readNodeById,
2549
+ dispatchNodeById,
2550
+ dispatchTargetsByReadNode,
2551
+ readNodeState: /* @__PURE__ */ new Map()
2552
+ };
2553
+ declarativeById.set(link.linkId, stored);
2554
+ for (const n of link.readNodes) {
2555
+ const list = declarativeReadNodesBySource.get(n.moduleInstanceKey) ?? [];
2556
+ list.push({ linkId: link.linkId, nodeId: n.nodeId });
2557
+ declarativeReadNodesBySource.set(n.moduleInstanceKey, list);
2558
+ }
2559
+ return () => {
2560
+ declarativeById.delete(link.linkId);
2561
+ for (const n of link.readNodes) {
2562
+ const list = declarativeReadNodesBySource.get(n.moduleInstanceKey);
2563
+ if (!list) continue;
2564
+ const next = list.filter((x) => !(x.linkId === link.linkId && x.nodeId === n.nodeId));
2565
+ if (next.length === 0) {
2566
+ declarativeReadNodesBySource.delete(n.moduleInstanceKey);
2567
+ } else {
2568
+ declarativeReadNodesBySource.set(n.moduleInstanceKey, next);
2569
+ }
2570
+ }
2571
+ };
2572
+ };
2573
+ const applyForSources = (args) => import_effect7.Effect.gen(function* () {
2574
+ let scheduled = false;
2575
+ for (const sourceKey of args.changedModuleInstanceKeys) {
2576
+ const ids = moduleAsSourceIdsBySource.get(sourceKey);
2577
+ if (!ids || ids.size === 0) continue;
2578
+ const commit2 = args.acceptedModules.get(sourceKey);
2579
+ if (!commit2) continue;
2580
+ for (const id of ids) {
2581
+ const link = moduleAsSourceById.get(id);
2582
+ if (!link) continue;
2583
+ let selected;
2584
+ try {
2585
+ selected = link.readQuery.select(commit2.state);
2586
+ } catch {
2587
+ continue;
2588
+ }
2589
+ const nextValue = link.computeValue(selected);
2590
+ if (link.hasValue && link.equalsValue(link.lastValue, nextValue)) {
2591
+ continue;
2592
+ }
2593
+ link.hasValue = true;
2594
+ link.lastValue = nextValue;
2595
+ scheduled = true;
2596
+ yield* link.applyValue(nextValue);
2597
+ }
2598
+ }
2599
+ for (const sourceKey of args.changedModuleInstanceKeys) {
2600
+ const refs = declarativeReadNodesBySource.get(sourceKey);
2601
+ if (!refs || refs.length === 0) continue;
2602
+ const commit2 = args.acceptedModules.get(sourceKey);
2603
+ if (!commit2) continue;
2604
+ for (const ref of refs) {
2605
+ const link = declarativeById.get(ref.linkId);
2606
+ if (!link) continue;
2607
+ const readNode = link.readNodeById.get(ref.nodeId);
2608
+ if (!readNode) continue;
2609
+ let value;
2610
+ try {
2611
+ value = readNode.readQuery.select(commit2.state);
2612
+ } catch {
2613
+ continue;
2614
+ }
2615
+ const state = link.readNodeState.get(ref.nodeId) ?? { hasValue: false, lastValue: void 0 };
2616
+ const changed = !state.hasValue || !Object.is(state.lastValue, value);
2617
+ if (!changed) continue;
2618
+ state.hasValue = true;
2619
+ state.lastValue = value;
2620
+ link.readNodeState.set(ref.nodeId, state);
2621
+ const targets = link.dispatchTargetsByReadNode.get(ref.nodeId) ?? [];
2622
+ for (const dispatchNodeId of targets) {
2623
+ const node = link.dispatchNodeById.get(dispatchNodeId);
2624
+ if (!node) continue;
2625
+ scheduled = true;
2626
+ yield* node.dispatch(value);
2627
+ }
2628
+ }
2629
+ }
2630
+ return { scheduled };
2631
+ });
2632
+ return {
2633
+ registerModuleAsSourceLink,
2634
+ registerDeclarativeLink,
2635
+ applyForSources
2636
+ };
2637
+ };
2638
+
2639
+ // src/internal/runtime/core/env.ts
2640
+ var getNodeEnv = () => {
2641
+ try {
2642
+ const env = globalThis?.process?.env;
2643
+ return typeof env?.NODE_ENV === "string" ? env.NODE_ENV : void 0;
2644
+ } catch {
2645
+ return void 0;
2646
+ }
2647
+ };
2648
+ var isDevEnv = () => getNodeEnv() !== "production";
2649
+ var StateTransactionConfigTagImpl = class extends import_effect8.Context.Tag("@logixjs/core/StateTransactionRuntimeConfig")() {
2650
+ };
2651
+ var StateTransactionConfigTag = StateTransactionConfigTagImpl;
2652
+ var ReadQueryStrictGateConfigTagImpl = class extends import_effect8.Context.Tag("@logixjs/core/ReadQueryStrictGateRuntimeConfig")() {
2653
+ };
2654
+ var ReadQueryStrictGateConfigTag = ReadQueryStrictGateConfigTagImpl;
2655
+ var ReplayModeConfigTagImpl = class extends import_effect8.Context.Tag("@logixjs/core/ReplayModeConfig")() {
2656
+ };
2657
+ var StateTransactionOverridesTagImpl = class extends import_effect8.Context.Tag("@logixjs/core/StateTransactionOverrides")() {
2658
+ };
2659
+ var StateTransactionOverridesTag = StateTransactionOverridesTagImpl;
2660
+ var ConcurrencyPolicyTagImpl = class extends import_effect8.Context.Tag("@logixjs/core/ConcurrencyPolicy")() {
2661
+ };
2662
+ var ConcurrencyPolicyTag = ConcurrencyPolicyTagImpl;
2663
+ var ConcurrencyPolicyOverridesTagImpl = class extends import_effect8.Context.Tag("@logixjs/core/ConcurrencyPolicyOverrides")() {
2664
+ };
2665
+ var ConcurrencyPolicyOverridesTag = ConcurrencyPolicyOverridesTagImpl;
2666
+ var RuntimeStoreTag = class extends import_effect8.Context.Tag("@logixjs/core/RuntimeStore")() {
2667
+ };
2668
+ var runtimeStoreLayer = import_effect8.Layer.scoped(
2669
+ RuntimeStoreTag,
2670
+ import_effect8.Effect.acquireRelease(
2671
+ import_effect8.Effect.sync(() => makeRuntimeStore()),
2672
+ (store) => import_effect8.Effect.sync(() => store.dispose())
2673
+ )
2674
+ );
2675
+ var HostSchedulerTag = class extends import_effect8.Context.Tag("@logixjs/core/HostScheduler")() {
2676
+ };
2677
+ var hostSchedulerLayer = import_effect8.Layer.succeed(
2678
+ HostSchedulerTag,
2679
+ getGlobalHostScheduler()
2680
+ );
2681
+ var DeclarativeLinkRuntimeTag = class extends import_effect8.Context.Tag("@logixjs/core/DeclarativeLinkRuntime")() {
2682
+ };
2683
+ var declarativeLinkRuntimeLayer = import_effect8.Layer.succeed(
2684
+ DeclarativeLinkRuntimeTag,
2685
+ makeDeclarativeLinkRuntime()
2686
+ );
2687
+ var TickSchedulerTag = class extends import_effect8.Context.Tag("@logixjs/core/TickScheduler")() {
2688
+ };
2689
+ var tickSchedulerLayer = (config) => import_effect8.Layer.effect(
2690
+ TickSchedulerTag,
2691
+ import_effect8.Effect.gen(function* () {
2692
+ const store = yield* RuntimeStoreTag;
2693
+ const declarativeLinkRuntime = yield* DeclarativeLinkRuntimeTag;
2694
+ const hostScheduler = yield* HostSchedulerTag;
2695
+ return makeTickScheduler({ runtimeStore: store, declarativeLinkRuntime, hostScheduler, config });
2696
+ })
2697
+ );
2698
+
2699
+ // src/internal/runtime/core/RootContext.ts
2700
+ var import_effect9 = require("effect");
2701
+ var RootContextTagImpl = class extends import_effect9.Context.Tag("@logixjs/core/RootContext")() {
2702
+ };
2703
+ var RootContextTag = RootContextTagImpl;
2704
+
2705
+ // src/internal/runtime/core/process/ProcessRuntime.make.ts
2706
+ var import_effect11 = require("effect");
2707
+
1451
2708
  // src/internal/runtime/core/runtimeInternalsAccessor.ts
1452
2709
  var RUNTIME_INTERNALS = /* @__PURE__ */ Symbol.for("@logixjs/core/runtimeInternals");
1453
2710
  var BOUND_INTERNALS = /* @__PURE__ */ Symbol.for("@logixjs/core/boundInternals");
@@ -1511,7 +2768,7 @@ var processInstanceIdFromIdentity = (identity) => {
1511
2768
  };
1512
2769
 
1513
2770
  // src/internal/runtime/core/process/concurrency.ts
1514
- var import_effect7 = require("effect");
2771
+ var import_effect10 = require("effect");
1515
2772
  var DEFAULT_SERIAL_QUEUE_GUARD_LIMIT = 4096;
1516
2773
  var DEFAULT_PARALLEL_LIMIT = 16;
1517
2774
  var resolveQueueLimit = (maxQueue, options) => {
@@ -1522,37 +2779,37 @@ var resolveQueueLimit = (maxQueue, options) => {
1522
2779
  guard: configured === "unbounded" ? defaultGuard : configured
1523
2780
  };
1524
2781
  };
1525
- var runProcessTriggerStream = (args) => import_effect7.Effect.gen(function* () {
2782
+ var runProcessTriggerStream = (args) => import_effect10.Effect.gen(function* () {
1526
2783
  const policy = args.policy;
1527
2784
  const defaultQueueGuard = args.defaultQueueGuard ?? DEFAULT_SERIAL_QUEUE_GUARD_LIMIT;
1528
2785
  if (policy.mode === "latest") {
1529
- const stateRef = yield* import_effect7.Ref.make({ fiber: void 0, runningId: 0, nextId: 0 });
1530
- const onTrigger2 = (trigger0) => import_effect7.Effect.gen(function* () {
2786
+ const stateRef = yield* import_effect10.Ref.make({ fiber: void 0, runningId: 0, nextId: 0 });
2787
+ const onTrigger2 = (trigger0) => import_effect10.Effect.gen(function* () {
1531
2788
  const trigger = args.assignTriggerSeq(trigger0);
1532
- const [prevFiber, prevRunningId, runId] = yield* import_effect7.Ref.modify(stateRef, (s) => {
2789
+ const [prevFiber, prevRunningId, runId] = yield* import_effect10.Ref.modify(stateRef, (s) => {
1533
2790
  const nextId = s.nextId + 1;
1534
2791
  return [[s.fiber, s.runningId, nextId], { ...s, nextId, runningId: nextId }];
1535
2792
  });
1536
2793
  if (prevFiber && prevRunningId !== 0) {
1537
- const done = yield* import_effect7.Fiber.poll(prevFiber);
1538
- if (import_effect7.Option.isNone(done)) {
1539
- yield* import_effect7.Fiber.interruptFork(prevFiber);
2794
+ const done = yield* import_effect10.Fiber.poll(prevFiber);
2795
+ if (import_effect10.Option.isNone(done)) {
2796
+ yield* import_effect10.Fiber.interruptFork(prevFiber);
1540
2797
  }
1541
2798
  }
1542
- const fiber = yield* import_effect7.Effect.forkScoped(
1543
- args.run(trigger).pipe(import_effect7.Effect.ensuring(import_effect7.Ref.update(stateRef, (s) => s.runningId === runId ? { ...s, runningId: 0 } : s)))
2799
+ const fiber = yield* import_effect10.Effect.forkScoped(
2800
+ args.run(trigger).pipe(import_effect10.Effect.ensuring(import_effect10.Ref.update(stateRef, (s) => s.runningId === runId ? { ...s, runningId: 0 } : s)))
1544
2801
  );
1545
- yield* import_effect7.Ref.update(stateRef, (s) => ({ ...s, fiber }));
2802
+ yield* import_effect10.Ref.update(stateRef, (s) => ({ ...s, fiber }));
1546
2803
  });
1547
- return yield* import_effect7.Stream.runForEach(args.stream, onTrigger2);
2804
+ return yield* import_effect10.Stream.runForEach(args.stream, onTrigger2);
1548
2805
  }
1549
- const busyRef = yield* import_effect7.Ref.make(false);
1550
- const serialStateRef = yield* import_effect7.Ref.make({
2806
+ const busyRef = yield* import_effect10.Ref.make(false);
2807
+ const serialStateRef = yield* import_effect10.Ref.make({
1551
2808
  running: false,
1552
2809
  queue: [],
1553
2810
  peak: 0
1554
2811
  });
1555
- const parallelStateRef = yield* import_effect7.Ref.make({
2812
+ const parallelStateRef = yield* import_effect10.Ref.make({
1556
2813
  active: 0,
1557
2814
  queue: [],
1558
2815
  peak: 0
@@ -1560,57 +2817,57 @@ var runProcessTriggerStream = (args) => import_effect7.Effect.gen(function* () {
1560
2817
  const serialQueueLimit = resolveQueueLimit(policy.maxQueue, { defaultGuard: defaultQueueGuard });
1561
2818
  const parallelQueueLimit = resolveQueueLimit(void 0, { defaultGuard: defaultQueueGuard });
1562
2819
  const parallelLimit = typeof policy.maxParallel === "number" && Number.isFinite(policy.maxParallel) && policy.maxParallel >= 1 ? Math.floor(policy.maxParallel) : args.defaultParallelLimit ?? DEFAULT_PARALLEL_LIMIT;
1563
- const drainSerial = () => import_effect7.Effect.suspend(
1564
- () => import_effect7.Ref.modify(serialStateRef, (state) => {
2820
+ const drainSerial = () => import_effect10.Effect.suspend(
2821
+ () => import_effect10.Ref.modify(serialStateRef, (state) => {
1565
2822
  if (state.running || state.queue.length === 0) {
1566
- return [import_effect7.Option.none(), state];
2823
+ return [import_effect10.Option.none(), state];
1567
2824
  }
1568
2825
  const [next, ...rest] = state.queue;
1569
- return [import_effect7.Option.some(next), { ...state, running: true, queue: rest }];
2826
+ return [import_effect10.Option.some(next), { ...state, running: true, queue: rest }];
1570
2827
  }).pipe(
1571
- import_effect7.Effect.flatMap(
1572
- (next) => import_effect7.Option.match(next, {
1573
- onNone: () => import_effect7.Effect.void,
1574
- onSome: (trigger) => import_effect7.Effect.forkScoped(
2828
+ import_effect10.Effect.flatMap(
2829
+ (next) => import_effect10.Option.match(next, {
2830
+ onNone: () => import_effect10.Effect.void,
2831
+ onSome: (trigger) => import_effect10.Effect.forkScoped(
1575
2832
  args.run(trigger).pipe(
1576
- import_effect7.Effect.ensuring(import_effect7.Ref.update(serialStateRef, (s) => ({ ...s, running: false }))),
1577
- import_effect7.Effect.zipRight(drainSerial())
2833
+ import_effect10.Effect.ensuring(import_effect10.Ref.update(serialStateRef, (s) => ({ ...s, running: false }))),
2834
+ import_effect10.Effect.zipRight(drainSerial())
1578
2835
  )
1579
- ).pipe(import_effect7.Effect.asVoid)
2836
+ ).pipe(import_effect10.Effect.asVoid)
1580
2837
  })
1581
2838
  )
1582
2839
  )
1583
2840
  );
1584
- const drainParallel = () => import_effect7.Effect.suspend(
1585
- () => import_effect7.Ref.modify(parallelStateRef, (state) => {
2841
+ const drainParallel = () => import_effect10.Effect.suspend(
2842
+ () => import_effect10.Ref.modify(parallelStateRef, (state) => {
1586
2843
  if (state.active >= parallelLimit || state.queue.length === 0) {
1587
- return [import_effect7.Option.none(), state];
2844
+ return [import_effect10.Option.none(), state];
1588
2845
  }
1589
2846
  const [next, ...rest] = state.queue;
1590
- return [import_effect7.Option.some(next), { ...state, active: state.active + 1, queue: rest }];
2847
+ return [import_effect10.Option.some(next), { ...state, active: state.active + 1, queue: rest }];
1591
2848
  }).pipe(
1592
- import_effect7.Effect.flatMap(
1593
- (next) => import_effect7.Option.match(next, {
1594
- onNone: () => import_effect7.Effect.void,
1595
- onSome: (trigger) => import_effect7.Effect.forkScoped(
2849
+ import_effect10.Effect.flatMap(
2850
+ (next) => import_effect10.Option.match(next, {
2851
+ onNone: () => import_effect10.Effect.void,
2852
+ onSome: (trigger) => import_effect10.Effect.forkScoped(
1596
2853
  args.run(trigger).pipe(
1597
- import_effect7.Effect.ensuring(
1598
- import_effect7.Ref.update(parallelStateRef, (s) => ({
2854
+ import_effect10.Effect.ensuring(
2855
+ import_effect10.Ref.update(parallelStateRef, (s) => ({
1599
2856
  ...s,
1600
2857
  active: Math.max(0, s.active - 1)
1601
2858
  }))
1602
2859
  ),
1603
- import_effect7.Effect.zipRight(drainParallel())
2860
+ import_effect10.Effect.zipRight(drainParallel())
1604
2861
  )
1605
- ).pipe(import_effect7.Effect.asVoid, import_effect7.Effect.zipRight(drainParallel()))
2862
+ ).pipe(import_effect10.Effect.asVoid, import_effect10.Effect.zipRight(drainParallel()))
1606
2863
  })
1607
2864
  )
1608
2865
  )
1609
2866
  );
1610
- const onTrigger = (trigger0) => import_effect7.Effect.gen(function* () {
2867
+ const onTrigger = (trigger0) => import_effect10.Effect.gen(function* () {
1611
2868
  const trigger = args.assignTriggerSeq(trigger0);
1612
2869
  if (policy.mode === "drop") {
1613
- const acquired = yield* import_effect7.Ref.modify(
2870
+ const acquired = yield* import_effect10.Ref.modify(
1614
2871
  busyRef,
1615
2872
  (busy) => busy ? [false, busy] : [true, true]
1616
2873
  );
@@ -1618,16 +2875,16 @@ var runProcessTriggerStream = (args) => import_effect7.Effect.gen(function* () {
1618
2875
  yield* args.onDrop(trigger);
1619
2876
  return;
1620
2877
  }
1621
- yield* import_effect7.Effect.forkScoped(args.run(trigger).pipe(import_effect7.Effect.ensuring(import_effect7.Ref.set(busyRef, false))));
2878
+ yield* import_effect10.Effect.forkScoped(args.run(trigger).pipe(import_effect10.Effect.ensuring(import_effect10.Ref.set(busyRef, false))));
1622
2879
  return;
1623
2880
  }
1624
2881
  if (policy.mode === "parallel") {
1625
- const nextSize2 = yield* import_effect7.Ref.modify(parallelStateRef, (state) => {
2882
+ const nextSize2 = yield* import_effect10.Ref.modify(parallelStateRef, (state) => {
1626
2883
  const queue = [...state.queue, trigger];
1627
2884
  return [queue.length, { ...state, queue, peak: Math.max(state.peak, queue.length) }];
1628
2885
  });
1629
2886
  if (nextSize2 > parallelQueueLimit.guard) {
1630
- const state = yield* import_effect7.Ref.get(parallelStateRef);
2887
+ const state = yield* import_effect10.Ref.get(parallelStateRef);
1631
2888
  yield* args.onQueueOverflow({
1632
2889
  mode: "parallel",
1633
2890
  currentLength: nextSize2,
@@ -1640,12 +2897,12 @@ var runProcessTriggerStream = (args) => import_effect7.Effect.gen(function* () {
1640
2897
  yield* drainParallel();
1641
2898
  return;
1642
2899
  }
1643
- const nextSize = yield* import_effect7.Ref.modify(serialStateRef, (state) => {
2900
+ const nextSize = yield* import_effect10.Ref.modify(serialStateRef, (state) => {
1644
2901
  const queue = [...state.queue, trigger];
1645
2902
  return [queue.length, { ...state, queue, peak: Math.max(state.peak, queue.length) }];
1646
2903
  });
1647
2904
  if (nextSize > serialQueueLimit.guard) {
1648
- const state = yield* import_effect7.Ref.get(serialStateRef);
2905
+ const state = yield* import_effect10.Ref.get(serialStateRef);
1649
2906
  yield* args.onQueueOverflow({
1650
2907
  mode: "serial",
1651
2908
  currentLength: nextSize,
@@ -1657,7 +2914,7 @@ var runProcessTriggerStream = (args) => import_effect7.Effect.gen(function* () {
1657
2914
  }
1658
2915
  yield* drainSerial();
1659
2916
  });
1660
- return yield* import_effect7.Stream.runForEach(args.stream, onTrigger);
2917
+ return yield* import_effect10.Stream.runForEach(args.stream, onTrigger);
1661
2918
  });
1662
2919
 
1663
2920
  // src/internal/runtime/core/process/events.ts
@@ -2032,11 +3289,11 @@ var onFailure = (policy, state, nowMs3) => {
2032
3289
  };
2033
3290
  };
2034
3291
 
2035
- // src/internal/runtime/core/process/ProcessRuntime.ts
2036
- var ProcessRuntimeTag = class extends import_effect8.Context.Tag("@logixjs/core/ProcessRuntime")() {
3292
+ // src/internal/runtime/core/process/ProcessRuntime.make.ts
3293
+ var ProcessRuntimeTag = class extends import_effect11.Context.Tag("@logixjs/core/ProcessRuntime")() {
2037
3294
  };
2038
- var currentProcessTrigger = import_effect8.FiberRef.unsafeMake(void 0);
2039
- var currentProcessEventBudget = import_effect8.FiberRef.unsafeMake(
3295
+ var currentProcessTrigger = import_effect11.FiberRef.unsafeMake(void 0);
3296
+ var currentProcessEventBudget = import_effect11.FiberRef.unsafeMake(
2040
3297
  void 0
2041
3298
  );
2042
3299
  var RUNTIME_BOOT_EVENT = "runtime:boot";
@@ -2095,13 +3352,13 @@ var actionIdFromUnknown = (action) => {
2095
3352
  if (typeof anyAction.type === "string" && anyAction.type.length > 0) return anyAction.type;
2096
3353
  return void 0;
2097
3354
  };
2098
- var make = (options) => import_effect8.Effect.gen(function* () {
2099
- const runtimeScope = yield* import_effect8.Effect.scope;
3355
+ var make = (options) => import_effect11.Effect.gen(function* () {
3356
+ const runtimeScope = yield* import_effect11.Effect.scope;
2100
3357
  const maxEventHistory = typeof options?.maxEventHistory === "number" && Number.isFinite(options.maxEventHistory) && options.maxEventHistory >= 0 ? Math.floor(options.maxEventHistory) : 500;
2101
3358
  const installations = /* @__PURE__ */ new Map();
2102
3359
  const instances2 = /* @__PURE__ */ new Map();
2103
3360
  const eventsBuffer = [];
2104
- const eventsHub = yield* import_effect8.PubSub.sliding(Math.max(1, Math.min(2048, maxEventHistory)));
3361
+ const eventsHub = yield* import_effect11.PubSub.sliding(Math.max(1, Math.min(2048, maxEventHistory)));
2105
3362
  const trimEvents = () => {
2106
3363
  if (maxEventHistory <= 0) {
2107
3364
  eventsBuffer.length = 0;
@@ -2111,8 +3368,8 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2111
3368
  const excess = eventsBuffer.length - maxEventHistory;
2112
3369
  eventsBuffer.splice(0, excess);
2113
3370
  };
2114
- const recordDebugEvent = (event) => import_effect8.Effect.gen(function* () {
2115
- const diagnosticsLevel2 = yield* import_effect8.FiberRef.get(currentDiagnosticsLevel);
3371
+ const recordDebugEvent = (event) => import_effect11.Effect.gen(function* () {
3372
+ const diagnosticsLevel2 = yield* import_effect11.FiberRef.get(currentDiagnosticsLevel);
2116
3373
  if (diagnosticsLevel2 === "off") {
2117
3374
  return;
2118
3375
  }
@@ -2135,16 +3392,16 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2135
3392
  txnId
2136
3393
  });
2137
3394
  });
2138
- const publishEvent = (event) => import_effect8.Effect.gen(function* () {
3395
+ const publishEvent = (event) => import_effect11.Effect.gen(function* () {
2139
3396
  eventsBuffer.push(event);
2140
3397
  trimEvents();
2141
- yield* import_effect8.PubSub.publish(eventsHub, event);
3398
+ yield* import_effect11.PubSub.publish(eventsHub, event);
2142
3399
  yield* recordDebugEvent(event);
2143
3400
  });
2144
- const emit = (event) => import_effect8.Effect.gen(function* () {
2145
- const budgetRef = yield* import_effect8.FiberRef.get(currentProcessEventBudget);
3401
+ const emit = (event) => import_effect11.Effect.gen(function* () {
3402
+ const budgetRef = yield* import_effect11.FiberRef.get(currentProcessEventBudget);
2146
3403
  if (budgetRef) {
2147
- const decision = yield* import_effect8.Ref.modify(budgetRef, (state) => {
3404
+ const decision = yield* import_effect11.Ref.modify(budgetRef, (state) => {
2148
3405
  const [nextDecision, nextState] = applyProcessRunEventBudget(state, event);
2149
3406
  return [nextDecision, nextState];
2150
3407
  });
@@ -2158,7 +3415,7 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2158
3415
  });
2159
3416
  const emitErrorDiagnostic = (scope, processId, code, message, hint) => {
2160
3417
  if (!isDevEnv()) {
2161
- return import_effect8.Effect.void;
3418
+ return import_effect11.Effect.void;
2162
3419
  }
2163
3420
  const moduleId = scope.type === "moduleInstance" ? scope.moduleId : void 0;
2164
3421
  const instanceId = scope.type === "moduleInstance" ? scope.instanceId : void 0;
@@ -2187,15 +3444,15 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2187
3444
  const missing = [];
2188
3445
  for (const dep of requires) {
2189
3446
  if (typeof dep !== "string" || dep.length === 0) continue;
2190
- const tag = import_effect8.Context.Tag(`@logixjs/Module/${dep}`)();
2191
- const found = import_effect8.Context.getOption(installation.env, tag);
2192
- if (import_effect8.Option.isNone(found)) {
3447
+ const tag = import_effect11.Context.Tag(`@logixjs/Module/${dep}`)();
3448
+ const found = import_effect11.Context.getOption(installation.env, tag);
3449
+ if (import_effect11.Option.isNone(found)) {
2193
3450
  missing.push(dep);
2194
3451
  }
2195
3452
  }
2196
3453
  return missing;
2197
3454
  };
2198
- const stopInstance = (instance, reason) => import_effect8.Effect.gen(function* () {
3455
+ const stopInstance = (instance, reason) => import_effect11.Effect.gen(function* () {
2199
3456
  if (instance.status.status === "stopped" || instance.status.status === "failed" || instance.status.status === "stopping") {
2200
3457
  return;
2201
3458
  }
@@ -2206,9 +3463,9 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2206
3463
  stoppedReason: reason
2207
3464
  };
2208
3465
  if (fiber) {
2209
- yield* import_effect8.Fiber.interrupt(fiber);
3466
+ yield* import_effect11.Fiber.interrupt(fiber);
2210
3467
  }
2211
- yield* import_effect8.Queue.shutdown(instance.platformTriggersQueue);
3468
+ yield* import_effect11.Queue.shutdown(instance.platformTriggersQueue);
2212
3469
  instance.status = {
2213
3470
  ...instance.status,
2214
3471
  status: "stopped",
@@ -2229,7 +3486,7 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2229
3486
  yield* startInstallation(instance.installationKey);
2230
3487
  }
2231
3488
  });
2232
- const startInstallation = (installationKey) => import_effect8.Effect.gen(function* () {
3489
+ const startInstallation = (installationKey) => import_effect11.Effect.gen(function* () {
2233
3490
  const installation = installations.get(installationKey);
2234
3491
  if (!installation) return;
2235
3492
  installation.pendingStart = void 0;
@@ -2248,7 +3505,7 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2248
3505
  runSeq
2249
3506
  };
2250
3507
  const processInstanceId = processInstanceIdFromIdentity(identity);
2251
- const platformTriggersQueue = yield* import_effect8.Queue.sliding(64);
3508
+ const platformTriggersQueue = yield* import_effect11.Queue.sliding(64);
2252
3509
  const instanceState = {
2253
3510
  installationKey,
2254
3511
  processInstanceId,
@@ -2267,15 +3524,15 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2267
3524
  instances2.set(processInstanceId, instanceState);
2268
3525
  installation.currentInstanceId = processInstanceId;
2269
3526
  if (installation.forkScope !== runtimeScope) {
2270
- yield* import_effect8.Scope.addFinalizer(
3527
+ yield* import_effect11.Scope.addFinalizer(
2271
3528
  installation.forkScope,
2272
- import_effect8.Effect.suspend(() => {
3529
+ import_effect11.Effect.suspend(() => {
2273
3530
  const status = instanceState.status.status;
2274
3531
  if (status === "stopped" || status === "failed" || status === "stopping") {
2275
- return import_effect8.Effect.void;
3532
+ return import_effect11.Effect.void;
2276
3533
  }
2277
3534
  return stopInstance(instanceState, "scopeDisposed");
2278
- }).pipe(import_effect8.Effect.catchAllCause(() => import_effect8.Effect.void))
3535
+ }).pipe(import_effect11.Effect.catchAllCause(() => import_effect11.Effect.void))
2279
3536
  );
2280
3537
  }
2281
3538
  yield* emit({
@@ -2338,12 +3595,12 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2338
3595
  let nextEnv = baseEnv;
2339
3596
  for (const moduleId of ids) {
2340
3597
  if (typeof moduleId !== "string" || moduleId.length === 0) continue;
2341
- const tag = import_effect8.Context.Tag(`@logixjs/Module/${moduleId}`)();
2342
- const found = import_effect8.Context.getOption(baseEnv, tag);
2343
- if (import_effect8.Option.isNone(found)) continue;
3598
+ const tag = import_effect11.Context.Tag(`@logixjs/Module/${moduleId}`)();
3599
+ const found = import_effect11.Context.getOption(baseEnv, tag);
3600
+ if (import_effect11.Option.isNone(found)) continue;
2344
3601
  const runtime = found.value;
2345
- const recordDispatch = (action) => import_effect8.Effect.gen(function* () {
2346
- const trigger = yield* import_effect8.FiberRef.get(currentProcessTrigger);
3602
+ const recordDispatch = (action) => import_effect11.Effect.gen(function* () {
3603
+ const trigger = yield* import_effect11.FiberRef.get(currentProcessTrigger);
2347
3604
  if (!trigger) return;
2348
3605
  const actionId = actionIdFromUnknown(action) ?? "unknown";
2349
3606
  const dispatchModuleId = typeof runtime.moduleId === "string" ? runtime.moduleId : moduleId;
@@ -2365,27 +3622,27 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2365
3622
  });
2366
3623
  const wrapped = {
2367
3624
  ...runtime,
2368
- dispatch: (action) => runtime.dispatch(action).pipe(import_effect8.Effect.tap(() => recordDispatch(action))),
2369
- dispatchLowPriority: (action) => runtime.dispatchLowPriority(action).pipe(import_effect8.Effect.tap(() => recordDispatch(action))),
2370
- dispatchBatch: (actions) => runtime.dispatchBatch(actions).pipe(import_effect8.Effect.tap(() => import_effect8.Effect.forEach(actions, recordDispatch, { discard: true })))
3625
+ dispatch: (action) => runtime.dispatch(action).pipe(import_effect11.Effect.tap(() => recordDispatch(action))),
3626
+ dispatchLowPriority: (action) => runtime.dispatchLowPriority(action).pipe(import_effect11.Effect.tap(() => recordDispatch(action))),
3627
+ dispatchBatch: (actions) => runtime.dispatchBatch(actions).pipe(import_effect11.Effect.tap(() => import_effect11.Effect.forEach(actions, recordDispatch, { discard: true })))
2371
3628
  };
2372
- nextEnv = import_effect8.Context.add(tag, wrapped)(nextEnv);
3629
+ nextEnv = import_effect11.Context.add(tag, wrapped)(nextEnv);
2373
3630
  }
2374
3631
  return nextEnv;
2375
3632
  };
2376
3633
  const wrappedEnv = makeWrappedEnv();
2377
- const providedProcess = import_effect8.Effect.provide(installation.process, wrappedEnv);
2378
- const makeTriggerStream = (spec) => import_effect8.Effect.gen(function* () {
3634
+ const providedProcess = import_effect11.Effect.provide(installation.process, wrappedEnv);
3635
+ const makeTriggerStream = (spec) => import_effect11.Effect.gen(function* () {
2379
3636
  if (spec.kind === "timer") {
2380
- const interval = import_effect8.Duration.decodeUnknown(spec.timerId);
2381
- if (import_effect8.Option.isNone(interval)) {
3637
+ const interval = import_effect11.Duration.decodeUnknown(spec.timerId);
3638
+ if (import_effect11.Option.isNone(interval)) {
2382
3639
  const err = new Error(`[ProcessRuntime] invalid timerId (expected DurationInput): ${spec.timerId}`);
2383
3640
  err.code = "process::invalid_timer_id";
2384
3641
  err.hint = "timerId must be a valid DurationInput string, e.g. '10 millis', '1 seconds', '5 minutes'.";
2385
- return yield* import_effect8.Effect.fail(err);
3642
+ return yield* import_effect11.Effect.fail(err);
2386
3643
  }
2387
- return import_effect8.Stream.tick(interval.value).pipe(
2388
- import_effect8.Stream.map(
3644
+ return import_effect11.Stream.tick(interval.value).pipe(
3645
+ import_effect11.Stream.map(
2389
3646
  () => ({
2390
3647
  kind: "timer",
2391
3648
  name: spec.name,
@@ -2395,10 +3652,10 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2395
3652
  );
2396
3653
  }
2397
3654
  if (spec.kind === "moduleAction") {
2398
- const tag2 = import_effect8.Context.Tag(`@logixjs/Module/${spec.moduleId}`)();
2399
- const found2 = import_effect8.Context.getOption(baseEnv, tag2);
2400
- if (import_effect8.Option.isNone(found2)) {
2401
- return yield* import_effect8.Effect.fail(new Error(`Missing module runtime in scope: ${spec.moduleId}`));
3655
+ const tag2 = import_effect11.Context.Tag(`@logixjs/Module/${spec.moduleId}`)();
3656
+ const found2 = import_effect11.Context.getOption(baseEnv, tag2);
3657
+ if (import_effect11.Option.isNone(found2)) {
3658
+ return yield* import_effect11.Effect.fail(new Error(`Missing module runtime in scope: ${spec.moduleId}`));
2402
3659
  }
2403
3660
  const runtime2 = found2.value;
2404
3661
  if (!shouldRecordChainEvents) {
@@ -2407,11 +3664,11 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2407
3664
  const err = new Error("ModuleRuntime does not provide actions$ (required for moduleAction trigger).");
2408
3665
  err.code = "process::missing_action_stream";
2409
3666
  err.hint = `moduleId=${spec.moduleId}`;
2410
- return yield* import_effect8.Effect.fail(err);
3667
+ return yield* import_effect11.Effect.fail(err);
2411
3668
  }
2412
3669
  return stream2.pipe(
2413
- import_effect8.Stream.filter((action) => actionIdFromUnknown(action) === spec.actionId),
2414
- import_effect8.Stream.map(
3670
+ import_effect11.Stream.filter((action) => actionIdFromUnknown(action) === spec.actionId),
3671
+ import_effect11.Stream.map(
2415
3672
  () => ({
2416
3673
  kind: "moduleAction",
2417
3674
  name: spec.name,
@@ -2430,11 +3687,11 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2430
3687
  );
2431
3688
  err.code = "process::missing_action_meta_stream";
2432
3689
  err.hint = `moduleId=${spec.moduleId}`;
2433
- return yield* import_effect8.Effect.fail(err);
3690
+ return yield* import_effect11.Effect.fail(err);
2434
3691
  }
2435
3692
  return stream.pipe(
2436
- import_effect8.Stream.filter((evt) => actionIdFromUnknown(evt.value) === spec.actionId),
2437
- import_effect8.Stream.map((evt) => {
3693
+ import_effect11.Stream.filter((evt) => actionIdFromUnknown(evt.value) === spec.actionId),
3694
+ import_effect11.Stream.map((evt) => {
2438
3695
  const txnSeq = evt?.meta?.txnSeq;
2439
3696
  return {
2440
3697
  kind: "moduleAction",
@@ -2447,21 +3704,21 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2447
3704
  })
2448
3705
  );
2449
3706
  }
2450
- const tag = import_effect8.Context.Tag(`@logixjs/Module/${spec.moduleId}`)();
2451
- const found = import_effect8.Context.getOption(baseEnv, tag);
2452
- if (import_effect8.Option.isNone(found)) {
2453
- return yield* import_effect8.Effect.fail(new Error(`Missing module runtime in scope: ${spec.moduleId}`));
3707
+ const tag = import_effect11.Context.Tag(`@logixjs/Module/${spec.moduleId}`)();
3708
+ const found = import_effect11.Context.getOption(baseEnv, tag);
3709
+ if (import_effect11.Option.isNone(found)) {
3710
+ return yield* import_effect11.Effect.fail(new Error(`Missing module runtime in scope: ${spec.moduleId}`));
2454
3711
  }
2455
3712
  const runtime = found.value;
2456
3713
  const schemaAst = resolveRuntimeStateSchemaAst(runtime);
2457
3714
  const selectorResult = makeSchemaSelector(spec.path, schemaAst);
2458
3715
  if (!selectorResult.ok) {
2459
- return yield* import_effect8.Effect.fail(withModuleHint(selectorResult.error, spec.moduleId));
3716
+ return yield* import_effect11.Effect.fail(withModuleHint(selectorResult.error, spec.moduleId));
2460
3717
  }
2461
3718
  const selectorBase = selectorResult.selector;
2462
- const prevRef = yield* import_effect8.Ref.make(import_effect8.Option.none());
3719
+ const prevRef = yield* import_effect11.Ref.make(import_effect11.Option.none());
2463
3720
  const enableSelectorDiagnostics = shouldRecordChainEvents;
2464
- const selectorDiagnosticsRef = enableSelectorDiagnostics ? yield* import_effect8.Ref.make({
3721
+ const selectorDiagnosticsRef = enableSelectorDiagnostics ? yield* import_effect11.Ref.make({
2465
3722
  windowStartedMs: Date.now(),
2466
3723
  triggersInWindow: 0,
2467
3724
  lastWarningAtMs: 0
@@ -2500,11 +3757,11 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2500
3757
  } : selectorBase;
2501
3758
  const maybeWarnSelector = (trigger) => {
2502
3759
  if (!selectorDiagnosticsRef) {
2503
- return import_effect8.Effect.void;
3760
+ return import_effect11.Effect.void;
2504
3761
  }
2505
- return import_effect8.Effect.gen(function* () {
3762
+ return import_effect11.Effect.gen(function* () {
2506
3763
  const now = Date.now();
2507
- const decision = yield* import_effect8.Ref.modify(selectorDiagnosticsRef, (s) => {
3764
+ const decision = yield* import_effect11.Ref.modify(selectorDiagnosticsRef, (s) => {
2508
3765
  const windowExpired = now - s.windowStartedMs >= triggerWindowMs;
2509
3766
  const windowStartedMs = windowExpired ? now : s.windowStartedMs;
2510
3767
  const triggersInWindow = windowExpired ? 1 : s.triggersInWindow + 1;
@@ -2572,18 +3829,18 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2572
3829
  });
2573
3830
  };
2574
3831
  const baseStream = runtime.changesWithMeta(selector).pipe(
2575
- import_effect8.Stream.mapEffect(
2576
- (evt) => import_effect8.Ref.get(prevRef).pipe(
2577
- import_effect8.Effect.flatMap((prev) => {
2578
- if (import_effect8.Option.isSome(prev) && Object.is(prev.value, evt.value)) {
2579
- return import_effect8.Effect.succeed(import_effect8.Option.none());
3832
+ import_effect11.Stream.mapEffect(
3833
+ (evt) => import_effect11.Ref.get(prevRef).pipe(
3834
+ import_effect11.Effect.flatMap((prev) => {
3835
+ if (import_effect11.Option.isSome(prev) && Object.is(prev.value, evt.value)) {
3836
+ return import_effect11.Effect.succeed(import_effect11.Option.none());
2580
3837
  }
2581
- return import_effect8.Ref.set(prevRef, import_effect8.Option.some(evt.value)).pipe(import_effect8.Effect.as(import_effect8.Option.some(evt)));
3838
+ return import_effect11.Ref.set(prevRef, import_effect11.Option.some(evt.value)).pipe(import_effect11.Effect.as(import_effect11.Option.some(evt)));
2582
3839
  })
2583
3840
  )
2584
3841
  ),
2585
- import_effect8.Stream.filterMap((opt) => opt),
2586
- import_effect8.Stream.map((evt) => {
3842
+ import_effect11.Stream.filterMap((opt) => opt),
3843
+ import_effect11.Stream.map((evt) => {
2587
3844
  const txnSeq = evt?.meta?.txnSeq;
2588
3845
  return {
2589
3846
  kind: "moduleStateChange",
@@ -2595,20 +3852,20 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2595
3852
  };
2596
3853
  })
2597
3854
  );
2598
- return enableSelectorDiagnostics ? baseStream.pipe(import_effect8.Stream.tap(maybeWarnSelector)) : baseStream;
3855
+ return enableSelectorDiagnostics ? baseStream.pipe(import_effect11.Stream.tap(maybeWarnSelector)) : baseStream;
2599
3856
  });
2600
- const makeRun = (trigger, fatal) => import_effect8.Effect.locally(
3857
+ const makeRun = (trigger, fatal) => import_effect11.Effect.locally(
2601
3858
  currentProcessTrigger,
2602
3859
  trigger
2603
3860
  )(
2604
3861
  providedProcess.pipe(
2605
- import_effect8.Effect.catchAllCause((cause) => {
2606
- if (import_effect8.Cause.isInterruptedOnly(cause)) {
2607
- return import_effect8.Effect.void;
3862
+ import_effect11.Effect.catchAllCause((cause) => {
3863
+ if (import_effect11.Cause.isInterruptedOnly(cause)) {
3864
+ return import_effect11.Effect.void;
2608
3865
  }
2609
- return import_effect8.Deferred.succeed(fatal, cause).pipe(
2610
- import_effect8.Effect.asVoid,
2611
- import_effect8.Effect.catchAll(() => import_effect8.Effect.void)
3866
+ return import_effect11.Deferred.succeed(fatal, cause).pipe(
3867
+ import_effect11.Effect.asVoid,
3868
+ import_effect11.Effect.catchAll(() => import_effect11.Effect.void)
2612
3869
  );
2613
3870
  })
2614
3871
  )
@@ -2617,12 +3874,12 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2617
3874
  if (!shouldRecordChainEvents) {
2618
3875
  return makeRun(trigger, fatal);
2619
3876
  }
2620
- return import_effect8.Effect.gen(function* () {
2621
- const budgetRef = yield* import_effect8.Ref.make(makeProcessRunEventBudgetState());
2622
- return yield* import_effect8.Effect.locally(
3877
+ return import_effect11.Effect.gen(function* () {
3878
+ const budgetRef = yield* import_effect11.Ref.make(makeProcessRunEventBudgetState());
3879
+ return yield* import_effect11.Effect.locally(
2623
3880
  currentProcessEventBudget,
2624
3881
  budgetRef
2625
- )(emitTriggerEvent(trigger, "info").pipe(import_effect8.Effect.zipRight(makeRun(trigger, fatal))));
3882
+ )(emitTriggerEvent(trigger, "info").pipe(import_effect11.Effect.zipRight(makeRun(trigger, fatal))));
2626
3883
  });
2627
3884
  };
2628
3885
  const assignTriggerSeq = (trigger) => {
@@ -2636,7 +3893,7 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2636
3893
  };
2637
3894
  const emitTriggerEvent = (trigger, severity) => {
2638
3895
  if (!shouldRecordChainEvents) {
2639
- return import_effect8.Effect.void;
3896
+ return import_effect11.Effect.void;
2640
3897
  }
2641
3898
  const evt = {
2642
3899
  type: "process:trigger",
@@ -2655,16 +3912,16 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2655
3912
  const bootTriggerSpec = installation.definition.triggers.find(
2656
3913
  (t) => t.kind === "platformEvent" && t.platformEvent === RUNTIME_BOOT_EVENT
2657
3914
  );
2658
- const instanceProgram = import_effect8.Effect.gen(function* () {
2659
- const fatal = yield* import_effect8.Deferred.make();
2660
- const platformEventStream = import_effect8.Stream.fromQueue(
3915
+ const instanceProgram = import_effect11.Effect.gen(function* () {
3916
+ const fatal = yield* import_effect11.Deferred.make();
3917
+ const platformEventStream = import_effect11.Stream.fromQueue(
2661
3918
  instanceState.platformTriggersQueue
2662
3919
  );
2663
3920
  const nonPlatformTriggers = installation.definition.triggers.filter(
2664
3921
  (t) => t.kind !== "platformEvent"
2665
3922
  );
2666
- const streams = yield* import_effect8.Effect.forEach(nonPlatformTriggers, makeTriggerStream);
2667
- const triggerStream = import_effect8.Stream.mergeAll([platformEventStream, ...streams], {
3923
+ const streams = yield* import_effect11.Effect.forEach(nonPlatformTriggers, makeTriggerStream);
3924
+ const triggerStream = import_effect11.Stream.mergeAll([platformEventStream, ...streams], {
2668
3925
  concurrency: "unbounded"
2669
3926
  });
2670
3927
  const reportQueueOverflow = (info) => {
@@ -2679,12 +3936,12 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2679
3936
  "fix:",
2680
3937
  "- Configure concurrency.maxQueue (serial) to a finite value, or switch to mode=latest/drop to avoid unbounded backlog."
2681
3938
  ].join("\n");
2682
- return import_effect8.Deferred.succeed(fatal, import_effect8.Cause.fail(err)).pipe(
2683
- import_effect8.Effect.asVoid,
2684
- import_effect8.Effect.catchAll(() => import_effect8.Effect.void)
3939
+ return import_effect11.Deferred.succeed(fatal, import_effect11.Cause.fail(err)).pipe(
3940
+ import_effect11.Effect.asVoid,
3941
+ import_effect11.Effect.catchAll(() => import_effect11.Effect.void)
2685
3942
  );
2686
3943
  };
2687
- const runnerFiber = yield* import_effect8.Effect.forkScoped(
3944
+ const runnerFiber = yield* import_effect11.Effect.forkScoped(
2688
3945
  runProcessTriggerStream({
2689
3946
  stream: triggerStream,
2690
3947
  policy,
@@ -2695,21 +3952,21 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2695
3952
  })
2696
3953
  );
2697
3954
  if (autoStart) {
2698
- yield* import_effect8.Queue.offer(instanceState.platformTriggersQueue, {
3955
+ yield* import_effect11.Queue.offer(instanceState.platformTriggersQueue, {
2699
3956
  kind: "platformEvent",
2700
3957
  name: bootTriggerSpec?.name,
2701
3958
  platformEvent: RUNTIME_BOOT_EVENT
2702
3959
  });
2703
3960
  }
2704
- const cause = yield* import_effect8.Deferred.await(fatal);
2705
- yield* import_effect8.Fiber.interrupt(runnerFiber);
2706
- return yield* import_effect8.Effect.failCause(cause);
3961
+ const cause = yield* import_effect11.Deferred.await(fatal);
3962
+ yield* import_effect11.Fiber.interrupt(runnerFiber);
3963
+ return yield* import_effect11.Effect.failCause(cause);
2707
3964
  });
2708
- const fiber = yield* import_effect8.Effect.forkIn(installation.forkScope)(
2709
- import_effect8.Effect.scoped(instanceProgram).pipe(
2710
- import_effect8.Effect.catchAllCause(
2711
- (cause) => import_effect8.Effect.gen(function* () {
2712
- if (import_effect8.Cause.isInterruptedOnly(cause)) {
3965
+ const fiber = yield* import_effect11.Effect.forkIn(installation.forkScope)(
3966
+ import_effect11.Effect.scoped(instanceProgram).pipe(
3967
+ import_effect11.Effect.catchAllCause(
3968
+ (cause) => import_effect11.Effect.gen(function* () {
3969
+ if (import_effect11.Cause.isInterruptedOnly(cause)) {
2713
3970
  if (instanceState.status.status === "stopping") {
2714
3971
  return;
2715
3972
  }
@@ -2719,7 +3976,7 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2719
3976
  stoppedReason: "scopeDisposed"
2720
3977
  };
2721
3978
  instanceState.fiber = void 0;
2722
- yield* import_effect8.Effect.uninterruptible(
3979
+ yield* import_effect11.Effect.uninterruptible(
2723
3980
  emit({
2724
3981
  type: "process:stop",
2725
3982
  identity,
@@ -2735,9 +3992,9 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2735
3992
  }
2736
3993
  return;
2737
3994
  }
2738
- const primary = import_effect8.Option.getOrElse(
2739
- import_effect8.Cause.failureOption(cause),
2740
- () => import_effect8.Option.getOrElse(import_effect8.Cause.dieOption(cause), () => cause)
3995
+ const primary = import_effect11.Option.getOrElse(
3996
+ import_effect11.Cause.failureOption(cause),
3997
+ () => import_effect11.Option.getOrElse(import_effect11.Cause.dieOption(cause), () => cause)
2741
3998
  );
2742
3999
  const summary = toSerializableErrorSummary(primary);
2743
4000
  const error = summary.errorSummary;
@@ -2789,16 +4046,16 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2789
4046
  ...instanceState.status,
2790
4047
  status: "running"
2791
4048
  };
2792
- yield* import_effect8.Effect.yieldNow();
4049
+ yield* import_effect11.Effect.yieldNow();
2793
4050
  });
2794
- const install = (process, options2) => import_effect8.Effect.gen(function* () {
4051
+ const install = (process, options2) => import_effect11.Effect.gen(function* () {
2795
4052
  const meta = getMeta(process);
2796
4053
  if (!meta) {
2797
4054
  return void 0;
2798
4055
  }
2799
- const env = yield* import_effect8.Effect.context();
2800
- const forkScopeOpt = yield* import_effect8.Effect.serviceOption(import_effect8.Scope.Scope);
2801
- const forkScope = import_effect8.Option.isSome(forkScopeOpt) ? forkScopeOpt.value : runtimeScope;
4056
+ const env = yield* import_effect11.Effect.context();
4057
+ const forkScopeOpt = yield* import_effect11.Effect.serviceOption(import_effect11.Scope.Scope);
4058
+ const forkScope = import_effect11.Option.isSome(forkScopeOpt) ? forkScopeOpt.value : runtimeScope;
2802
4059
  const scopeKey = scopeKeyFromScope(options2.scope);
2803
4060
  const identity = {
2804
4061
  processId: meta.definition.processId,
@@ -2826,9 +4083,9 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2826
4083
  const mode = options2.mode ?? "switch";
2827
4084
  if (mode === "switch" && current && current.forkScope !== forkScope) {
2828
4085
  existing.pendingStart = { forkScope };
2829
- yield* import_effect8.Scope.addFinalizer(
4086
+ yield* import_effect11.Scope.addFinalizer(
2830
4087
  forkScope,
2831
- import_effect8.Effect.sync(() => {
4088
+ import_effect11.Effect.sync(() => {
2832
4089
  const installation2 = installations.get(installationKey);
2833
4090
  if (!installation2) return;
2834
4091
  if (installation2.pendingStart?.forkScope === forkScope) {
@@ -2849,9 +4106,9 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2849
4106
  const mode = options2.mode ?? "switch";
2850
4107
  if (mode === "switch") {
2851
4108
  existing.pendingStart = { forkScope };
2852
- yield* import_effect8.Scope.addFinalizer(
4109
+ yield* import_effect11.Scope.addFinalizer(
2853
4110
  forkScope,
2854
- import_effect8.Effect.sync(() => {
4111
+ import_effect11.Effect.sync(() => {
2855
4112
  const installation2 = installations.get(installationKey);
2856
4113
  if (!installation2) return;
2857
4114
  if (installation2.pendingStart?.forkScope === forkScope) {
@@ -2876,7 +4133,7 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2876
4133
  installedAt: existing.installedAt
2877
4134
  };
2878
4135
  }
2879
- const derived = import_effect8.Effect.suspend(() => process);
4136
+ const derived = import_effect11.Effect.suspend(() => process);
2880
4137
  attachMeta(derived, {
2881
4138
  ...meta,
2882
4139
  installationScope: options2.scope
@@ -2905,7 +4162,7 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2905
4162
  installedAt: installation.installedAt
2906
4163
  };
2907
4164
  });
2908
- const listInstallations = (filter) => import_effect8.Effect.sync(() => {
4165
+ const listInstallations = (filter) => import_effect11.Effect.sync(() => {
2909
4166
  const scopeType = filter?.scopeType;
2910
4167
  const scopeKey = filter?.scopeKey;
2911
4168
  const out = [];
@@ -2920,26 +4177,26 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2920
4177
  }
2921
4178
  return out;
2922
4179
  });
2923
- const getInstanceStatus = (processInstanceId) => import_effect8.Effect.sync(() => instances2.get(processInstanceId)?.status);
2924
- const controlInstance = (processInstanceId, request) => import_effect8.Effect.suspend(() => {
4180
+ const getInstanceStatus = (processInstanceId) => import_effect11.Effect.sync(() => instances2.get(processInstanceId)?.status);
4181
+ const controlInstance = (processInstanceId, request) => import_effect11.Effect.suspend(() => {
2925
4182
  const instance = instances2.get(processInstanceId);
2926
4183
  if (!instance) {
2927
- return import_effect8.Effect.void;
4184
+ return import_effect11.Effect.void;
2928
4185
  }
2929
4186
  return shouldNoopDueToSyncTxn(instance.scope, "process_control_in_transaction").pipe(
2930
- import_effect8.Effect.flatMap((noop) => {
4187
+ import_effect11.Effect.flatMap((noop) => {
2931
4188
  if (noop) {
2932
- return import_effect8.Effect.void;
4189
+ return import_effect11.Effect.void;
2933
4190
  }
2934
4191
  if (request.action === "stop") {
2935
4192
  return stopInstance(instance, "manualStop");
2936
4193
  }
2937
4194
  if (request.action === "restart") {
2938
4195
  return stopInstance(instance, "manualStop").pipe(
2939
- import_effect8.Effect.flatMap(() => {
4196
+ import_effect11.Effect.flatMap(() => {
2940
4197
  const installation = installations.get(instance.installationKey);
2941
4198
  if (!installation) {
2942
- return import_effect8.Effect.void;
4199
+ return import_effect11.Effect.void;
2943
4200
  }
2944
4201
  installation.currentInstanceId = void 0;
2945
4202
  return startInstallation(instance.installationKey);
@@ -2948,20 +4205,20 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2948
4205
  }
2949
4206
  if (request.action === "start") {
2950
4207
  if (instance.status.status === "running" || instance.status.status === "starting") {
2951
- return import_effect8.Effect.void;
4208
+ return import_effect11.Effect.void;
2952
4209
  }
2953
4210
  const installation = installations.get(instance.installationKey);
2954
4211
  if (!installation) {
2955
- return import_effect8.Effect.void;
4212
+ return import_effect11.Effect.void;
2956
4213
  }
2957
4214
  installation.currentInstanceId = void 0;
2958
4215
  return startInstallation(instance.installationKey);
2959
4216
  }
2960
- return import_effect8.Effect.void;
4217
+ return import_effect11.Effect.void;
2961
4218
  })
2962
4219
  );
2963
4220
  });
2964
- const deliverPlatformEvent = (event) => import_effect8.Effect.gen(function* () {
4221
+ const deliverPlatformEvent = (event) => import_effect11.Effect.gen(function* () {
2965
4222
  const noop = yield* shouldNoopInSyncTransactionFiber({
2966
4223
  code: "process::invalid_usage",
2967
4224
  severity: "error",
@@ -2972,25 +4229,25 @@ var make = (options) => import_effect8.Effect.gen(function* () {
2972
4229
  if (noop) return;
2973
4230
  const targets = Array.from(instances2.values());
2974
4231
  const eventName = event.eventName;
2975
- yield* import_effect8.Effect.forEach(
4232
+ yield* import_effect11.Effect.forEach(
2976
4233
  targets,
2977
- (instance) => import_effect8.Effect.suspend(() => {
4234
+ (instance) => import_effect11.Effect.suspend(() => {
2978
4235
  if (instance.status.status !== "starting" && instance.status.status !== "running") {
2979
- return import_effect8.Effect.void;
4236
+ return import_effect11.Effect.void;
2980
4237
  }
2981
4238
  const installation = installations.get(instance.installationKey);
2982
4239
  if (!installation) {
2983
- return import_effect8.Effect.void;
4240
+ return import_effect11.Effect.void;
2984
4241
  }
2985
4242
  const specs = installation.definition.triggers.filter(
2986
4243
  (t) => t.kind === "platformEvent" && t.platformEvent === eventName
2987
4244
  );
2988
4245
  if (specs.length === 0) {
2989
- return import_effect8.Effect.void;
4246
+ return import_effect11.Effect.void;
2990
4247
  }
2991
- return import_effect8.Effect.forEach(
4248
+ return import_effect11.Effect.forEach(
2992
4249
  specs,
2993
- (spec) => import_effect8.Queue.offer(instance.platformTriggersQueue, {
4250
+ (spec) => import_effect11.Queue.offer(instance.platformTriggersQueue, {
2994
4251
  kind: "platformEvent",
2995
4252
  name: spec.name,
2996
4253
  platformEvent: spec.platformEvent
@@ -3001,10 +4258,10 @@ var make = (options) => import_effect8.Effect.gen(function* () {
3001
4258
  { discard: true }
3002
4259
  );
3003
4260
  });
3004
- const eventsStream = import_effect8.Stream.fromPubSub(eventsHub);
3005
- const getEventsSnapshot = () => import_effect8.Effect.sync(() => eventsBuffer.slice());
3006
- yield* import_effect8.Effect.addFinalizer(
3007
- () => import_effect8.Effect.gen(function* () {
4261
+ const eventsStream = import_effect11.Stream.fromPubSub(eventsHub);
4262
+ const getEventsSnapshot = () => import_effect11.Effect.sync(() => eventsBuffer.slice());
4263
+ yield* import_effect11.Effect.addFinalizer(
4264
+ () => import_effect11.Effect.gen(function* () {
3008
4265
  for (const installation of installations.values()) {
3009
4266
  installation.pendingStart = void 0;
3010
4267
  }
@@ -3014,10 +4271,10 @@ var make = (options) => import_effect8.Effect.gen(function* () {
3014
4271
  }
3015
4272
  }
3016
4273
  }).pipe(
3017
- import_effect8.Effect.catchAllCause(
3018
- (cause) => import_effect8.Effect.sync(() => {
4274
+ import_effect11.Effect.catchAllCause(
4275
+ (cause) => import_effect11.Effect.sync(() => {
3019
4276
  if (isDevEnv()) {
3020
- console.warn("[ProcessRuntime] finalizer failed", import_effect8.Cause.pretty(cause));
4277
+ console.warn("[ProcessRuntime] finalizer failed", import_effect11.Cause.pretty(cause));
3021
4278
  }
3022
4279
  })
3023
4280
  )
@@ -3033,7 +4290,7 @@ var make = (options) => import_effect8.Effect.gen(function* () {
3033
4290
  getEventsSnapshot
3034
4291
  };
3035
4292
  });
3036
- var layer = (options) => import_effect8.Layer.scoped(ProcessRuntimeTag, make(options));
4293
+ var layer = (options) => import_effect11.Layer.scoped(ProcessRuntimeTag, make(options));
3037
4294
 
3038
4295
  // src/internal/runtime/AppRuntime.ts
3039
4296
  var getTagKey = (tag) => {
@@ -3129,95 +4386,113 @@ Ensure all modules in the application Runtime have unique IDs.`
3129
4386
  seenIds.add(id);
3130
4387
  }
3131
4388
  validateTags(config.modules);
3132
- const stateTxnLayer = config.stateTransaction ? import_effect9.Layer.succeed(StateTransactionConfigTag, config.stateTransaction) : import_effect9.Layer.empty;
3133
- const concurrencyPolicyLayer = config.concurrencyPolicy ? import_effect9.Layer.succeed(ConcurrencyPolicyTag, config.concurrencyPolicy) : import_effect9.Layer.empty;
3134
- const readQueryStrictGateLayer = config.readQueryStrictGate ? import_effect9.Layer.succeed(ReadQueryStrictGateConfigTag, config.readQueryStrictGate) : import_effect9.Layer.empty;
4389
+ const stateTxnLayer = config.stateTransaction ? import_effect12.Layer.succeed(StateTransactionConfigTag, config.stateTransaction) : import_effect12.Layer.empty;
4390
+ const concurrencyPolicyLayer = config.concurrencyPolicy ? import_effect12.Layer.succeed(ConcurrencyPolicyTag, config.concurrencyPolicy) : import_effect12.Layer.empty;
4391
+ const readQueryStrictGateLayer = config.readQueryStrictGate ? import_effect12.Layer.succeed(ReadQueryStrictGateConfigTag, config.readQueryStrictGate) : import_effect12.Layer.empty;
3135
4392
  const appModuleIds = config.modules.map((entry) => String(entry.module.id));
3136
4393
  const appId = appModuleIds.length === 1 ? appModuleIds[0] : appModuleIds.slice().sort().join("~");
3137
- const baseLayer = import_effect9.Layer.mergeAll(
3138
- config.layer,
4394
+ const pinnedHostSchedulerLayer = config.hostScheduler !== void 0 ? import_effect12.Layer.succeed(HostSchedulerTag, config.hostScheduler) : void 0;
4395
+ const tickServicesLayer = import_effect12.Layer.provideMerge(pinnedHostSchedulerLayer ?? hostSchedulerLayer)(
4396
+ import_effect12.Layer.provideMerge(runtimeStoreLayer)(import_effect12.Layer.provideMerge(declarativeLinkRuntimeLayer)(tickSchedulerLayer()))
4397
+ );
4398
+ const appLayer = config.layer.pipe(import_effect12.Layer.provide(tickServicesLayer));
4399
+ const baseLayer = import_effect12.Layer.mergeAll(
4400
+ tickServicesLayer,
4401
+ appLayer,
4402
+ // If a HostScheduler override is requested, pin it as the final HostSchedulerTag value to avoid accidental divergence.
4403
+ // (Build-time capture is handled above by injecting it into tickServicesLayer.)
4404
+ pinnedHostSchedulerLayer ?? import_effect12.Layer.empty,
3139
4405
  stateTxnLayer,
3140
4406
  concurrencyPolicyLayer,
3141
4407
  readQueryStrictGateLayer,
3142
4408
  layer(),
3143
- import_effect9.Layer.effect(
4409
+ import_effect12.Layer.effect(
3144
4410
  RootContextTag,
3145
- import_effect9.Effect.gen(function* () {
3146
- const ready = yield* import_effect9.Deferred.make();
4411
+ import_effect12.Effect.gen(function* () {
4412
+ const ready = yield* import_effect12.Deferred.make();
3147
4413
  return { context: void 0, ready, appId, appModuleIds };
3148
4414
  })
3149
4415
  )
3150
4416
  );
3151
- const moduleLayers = config.modules.map(
3152
- (entry) => (
3153
- // Ensure each module layer can see the app Env (baseLayer) to avoid missing root env during initialization.
3154
- import_effect9.Layer.provide(entry.layer, baseLayer)
3155
- )
3156
- );
3157
- const envLayer = moduleLayers.length > 0 ? import_effect9.Layer.mergeAll(baseLayer, ...moduleLayers) : baseLayer;
3158
- const finalLayer = import_effect9.Layer.unwrapScoped(
3159
- import_effect9.Effect.gen(function* () {
3160
- const scope = yield* import_effect9.Effect.scope;
3161
- const [patch, env] = yield* import_effect9.Effect.diffFiberRefs(import_effect9.Layer.buildWithScope(envLayer, scope));
3162
- const rootContext = import_effect9.Context.get(env, RootContextTag);
3163
- rootContext.context = env;
3164
- yield* import_effect9.Deferred.succeed(rootContext.ready, env);
3165
- const processRuntime = import_effect9.Context.get(
3166
- env,
3167
- ProcessRuntimeTag
3168
- );
3169
- yield* import_effect9.Effect.forEach(
3170
- config.processes,
3171
- (process) => import_effect9.Effect.gen(function* () {
3172
- const installation = yield* import_effect9.Effect.provide(
3173
- processRuntime.install(process, {
3174
- scope: { type: "app", appId },
3175
- enabled: true,
3176
- installedAt: "appRuntime"
4417
+ const finalLayer = import_effect12.Layer.unwrapScoped(
4418
+ import_effect12.Effect.gen(function* () {
4419
+ const scope = yield* import_effect12.Effect.scope;
4420
+ const [patch, env] = yield* import_effect12.Effect.diffFiberRefs(
4421
+ import_effect12.Effect.gen(function* () {
4422
+ const baseEnv = yield* import_effect12.Layer.buildWithScope(baseLayer, scope);
4423
+ const moduleEnv = config.modules.length > 0 ? yield* import_effect12.Effect.provide(
4424
+ import_effect12.Layer.buildWithScope(
4425
+ config.modules.length === 1 ? config.modules[0].layer : config.modules.slice(1).reduce((acc, entry) => import_effect12.Layer.merge(acc, entry.layer), config.modules[0].layer),
4426
+ scope
4427
+ ),
4428
+ baseEnv
4429
+ ) : void 0;
4430
+ const mergedEnv = moduleEnv ? import_effect12.Context.merge(baseEnv, moduleEnv) : baseEnv;
4431
+ const rootContext = import_effect12.Context.get(mergedEnv, RootContextTag);
4432
+ rootContext.context = mergedEnv;
4433
+ yield* import_effect12.Deferred.succeed(rootContext.ready, mergedEnv);
4434
+ const processRuntime = import_effect12.Context.get(
4435
+ mergedEnv,
4436
+ ProcessRuntimeTag
4437
+ );
4438
+ yield* import_effect12.Effect.forEach(
4439
+ config.processes,
4440
+ (process) => import_effect12.Effect.gen(function* () {
4441
+ const installation = yield* import_effect12.Effect.provide(
4442
+ processRuntime.install(process, {
4443
+ scope: { type: "app", appId },
4444
+ enabled: true,
4445
+ installedAt: "appRuntime"
4446
+ }),
4447
+ mergedEnv
4448
+ );
4449
+ if (installation === void 0) {
4450
+ yield* import_effect12.Effect.forkScoped(
4451
+ import_effect12.Effect.provide(
4452
+ config.onError ? import_effect12.Effect.catchAllCause(process, config.onError) : process,
4453
+ mergedEnv
4454
+ )
4455
+ );
4456
+ }
3177
4457
  }),
3178
- env
4458
+ { discard: true }
3179
4459
  );
3180
- if (installation === void 0) {
3181
- yield* import_effect9.Effect.forkScoped(
3182
- import_effect9.Effect.provide(config.onError ? import_effect9.Effect.catchAllCause(process, config.onError) : process, env)
3183
- );
3184
- }
3185
- }),
3186
- { discard: true }
4460
+ return mergedEnv;
4461
+ })
3187
4462
  );
3188
- const fiberRefsLayer = import_effect9.Layer.scopedDiscard(import_effect9.Effect.patchFiberRefs(patch));
3189
- return import_effect9.Layer.mergeAll(import_effect9.Layer.succeedContext(env), fiberRefsLayer);
4463
+ const fiberRefsLayer = import_effect12.Layer.scopedDiscard(import_effect12.Effect.patchFiberRefs(patch));
4464
+ return import_effect12.Layer.mergeAll(import_effect12.Layer.succeedContext(env), fiberRefsLayer);
3190
4465
  })
3191
4466
  );
3192
4467
  return {
3193
4468
  definition: config,
3194
4469
  layer: finalLayer,
3195
- makeRuntime: () => import_effect9.ManagedRuntime.make(finalLayer)
4470
+ makeRuntime: () => import_effect12.ManagedRuntime.make(finalLayer)
3196
4471
  };
3197
4472
  };
3198
4473
  var provide = (module2, resource) => {
3199
- const layer4 = isLayer(resource) ? resource : import_effect9.Layer.succeed(module2, resource);
4474
+ const layer4 = isLayer(resource) ? resource : import_effect12.Layer.succeed(module2, resource);
3200
4475
  return { module: module2, layer: layer4 };
3201
4476
  };
3202
- var isLayer = (value) => typeof value === "object" && value !== null && import_effect9.Layer.LayerTypeId in value;
4477
+ var isLayer = (value) => typeof value === "object" && value !== null && import_effect12.Layer.LayerTypeId in value;
3203
4478
 
3204
- // src/internal/runtime/core/ModuleRuntime.ts
3205
- var import_effect43 = require("effect");
4479
+ // src/internal/runtime/core/ModuleRuntime.impl.ts
4480
+ var import_effect47 = require("effect");
3206
4481
 
3207
4482
  // src/internal/runtime/core/Lifecycle.ts
3208
- var import_effect10 = require("effect");
3209
- var LifecycleContext = import_effect10.Context.GenericTag("@logixjs/LifecycleManager");
4483
+ var import_effect13 = require("effect");
4484
+ var LifecycleContext = import_effect13.Context.GenericTag("@logixjs/LifecycleManager");
3210
4485
 
3211
4486
  // src/internal/runtime/core/ConvergeStaticIrCollector.ts
3212
- var import_effect11 = require("effect");
3213
- var currentConvergeStaticIrCollectors = import_effect11.FiberRef.unsafeMake([]);
3214
- var appendConvergeStaticIrCollectors = (collectors) => import_effect11.Layer.fiberRefLocallyScopedWith(currentConvergeStaticIrCollectors, (current) => [
4487
+ var import_effect14 = require("effect");
4488
+ var currentConvergeStaticIrCollectors = import_effect14.FiberRef.unsafeMake([]);
4489
+ var appendConvergeStaticIrCollectors = (collectors) => import_effect14.Layer.fiberRefLocallyScopedWith(currentConvergeStaticIrCollectors, (current) => [
3215
4490
  ...current,
3216
4491
  ...collectors
3217
4492
  ]);
3218
4493
 
3219
4494
  // src/internal/runtime/core/StateTransaction.ts
3220
- var import_effect12 = require("effect");
4495
+ var import_effect15 = require("effect");
3221
4496
 
3222
4497
  // src/internal/field-path.ts
3223
4498
  var isFieldPathSegment = (seg) => {
@@ -3229,26 +4504,26 @@ var isFieldPathSegment = (seg) => {
3229
4504
  };
3230
4505
 
3231
4506
  // src/internal/runtime/core/RuntimeKernel.ts
3232
- var import_effect13 = require("effect");
3233
- var RuntimeServicesRuntimeConfigTagImpl = class extends import_effect13.Context.Tag("@logixjs/core/RuntimeServicesRuntimeConfig")() {
4507
+ var import_effect16 = require("effect");
4508
+ var RuntimeServicesRuntimeConfigTagImpl = class extends import_effect16.Context.Tag("@logixjs/core/RuntimeServicesRuntimeConfig")() {
3234
4509
  };
3235
- var RuntimeServicesProviderOverridesTagImpl = class extends import_effect13.Context.Tag("@logixjs/core/RuntimeServicesProviderOverrides")() {
4510
+ var RuntimeServicesProviderOverridesTagImpl = class extends import_effect16.Context.Tag("@logixjs/core/RuntimeServicesProviderOverrides")() {
3236
4511
  };
3237
- var RuntimeServicesInstanceOverridesTagImpl = class extends import_effect13.Context.Tag("@logixjs/core/RuntimeServicesInstanceOverrides")() {
4512
+ var RuntimeServicesInstanceOverridesTagImpl = class extends import_effect16.Context.Tag("@logixjs/core/RuntimeServicesInstanceOverrides")() {
3238
4513
  };
3239
- var FullCutoverGateModeTagImpl = class extends import_effect13.Context.Tag("@logixjs/core/FullCutoverGateMode")() {
4514
+ var FullCutoverGateModeTagImpl = class extends import_effect16.Context.Tag("@logixjs/core/FullCutoverGateMode")() {
3240
4515
  };
3241
- var RuntimeServicesRegistryTagImpl = class extends import_effect13.Context.Tag("@logixjs/core/RuntimeServicesRegistry")() {
4516
+ var RuntimeServicesRegistryTagImpl = class extends import_effect16.Context.Tag("@logixjs/core/RuntimeServicesRegistry")() {
3242
4517
  };
3243
4518
 
3244
4519
  // src/internal/runtime/core/KernelRef.ts
3245
- var import_effect14 = require("effect");
3246
- var KernelImplementationRefTagImpl = class extends import_effect14.Context.Tag("@logixjs/core/KernelImplementationRef")() {
4520
+ var import_effect17 = require("effect");
4521
+ var KernelImplementationRefTagImpl = class extends import_effect17.Context.Tag("@logixjs/core/KernelImplementationRef")() {
3247
4522
  };
3248
4523
 
3249
4524
  // src/internal/runtime/core/RuntimeServiceBuiltins.ts
3250
- var import_effect15 = require("effect");
3251
- var RuntimeServiceBuiltinsTag = class extends import_effect15.Context.Tag("@logixjs/core/RuntimeServiceBuiltins")() {
4525
+ var import_effect18 = require("effect");
4526
+ var RuntimeServiceBuiltinsTag = class extends import_effect18.Context.Tag("@logixjs/core/RuntimeServiceBuiltins")() {
3252
4527
  };
3253
4528
 
3254
4529
  // src/internal/runtime/core/normalize.ts
@@ -3258,11 +4533,11 @@ var normalizeNonNegativeNumber = (value) => typeof value === "number" && Number.
3258
4533
  var normalizeBoolean = (value) => typeof value === "boolean" ? value : void 0;
3259
4534
 
3260
4535
  // src/internal/observability/evidenceCollector.ts
3261
- var import_effect17 = require("effect");
4536
+ var import_effect20 = require("effect");
3262
4537
 
3263
4538
  // src/internal/observability/runSession.ts
3264
- var import_effect16 = require("effect");
3265
- var RunSessionTagImpl = class extends import_effect16.Context.Tag("@logixjs/core/RunSession")() {
4539
+ var import_effect19 = require("effect");
4540
+ var RunSessionTagImpl = class extends import_effect19.Context.Tag("@logixjs/core/RunSession")() {
3266
4541
  };
3267
4542
  var RunSessionTag = RunSessionTagImpl;
3268
4543
  var NEXT_RUN_SEQ_KEY = /* @__PURE__ */ Symbol.for("@logixjs/core/runSession/nextRunSeq");
@@ -3312,17 +4587,17 @@ var makeRunSession = (options) => {
3312
4587
  local: options?.local ?? makeRunSessionLocalState()
3313
4588
  };
3314
4589
  };
3315
- var runSessionLayer = (session) => import_effect16.Layer.succeed(RunSessionTag, session ?? makeRunSession());
4590
+ var runSessionLayer = (session) => import_effect19.Layer.succeed(RunSessionTag, session ?? makeRunSession());
3316
4591
 
3317
4592
  // src/internal/observability/evidenceCollector.ts
3318
- var EvidenceCollectorTagImpl = class extends import_effect17.Context.Tag("@logixjs/core/EvidenceCollector")() {
4593
+ var EvidenceCollectorTagImpl = class extends import_effect20.Context.Tag("@logixjs/core/EvidenceCollector")() {
3319
4594
  };
3320
4595
 
3321
4596
  // src/internal/runtime/core/ModuleRuntime.operation.ts
3322
- var import_effect19 = require("effect");
4597
+ var import_effect22 = require("effect");
3323
4598
 
3324
4599
  // src/internal/effect-op.ts
3325
- var import_effect18 = require("effect");
4600
+ var import_effect21 = require("effect");
3326
4601
  var nextGlobalOpSeq = 0;
3327
4602
  var nextOpSeq = () => {
3328
4603
  nextGlobalOpSeq += 1;
@@ -3347,33 +4622,37 @@ var make2 = (params) => ({
3347
4622
  var run = (op, stack) => runWithMiddleware(op, stack);
3348
4623
 
3349
4624
  // src/internal/runtime/core/ModuleRuntime.dispatch.ts
3350
- var import_effect21 = require("effect");
4625
+ var import_effect25 = require("effect");
3351
4626
 
3352
4627
  // src/internal/runtime/core/ReducerDiagnostics.ts
3353
- var import_effect20 = require("effect");
4628
+ var import_effect23 = require("effect");
4629
+
4630
+ // src/internal/runtime/core/TxnOriginOverride.ts
4631
+ var import_effect24 = require("effect");
4632
+ var currentTxnOriginOverride = import_effect24.FiberRef.unsafeMake(void 0);
3354
4633
 
3355
4634
  // src/internal/runtime/core/ModuleRuntime.effects.ts
3356
- var import_effect22 = require("effect");
4635
+ var import_effect26 = require("effect");
3357
4636
 
3358
4637
  // src/internal/runtime/core/ModuleRuntime.transaction.ts
3359
- var import_effect31 = require("effect");
4638
+ var import_effect35 = require("effect");
3360
4639
 
3361
- // src/internal/state-trait/converge-in-transaction.ts
3362
- var import_effect26 = require("effect");
4640
+ // src/internal/state-trait/converge-in-transaction.impl.ts
4641
+ var import_effect30 = require("effect");
3363
4642
 
3364
4643
  // src/internal/state-trait/converge-diagnostics.ts
3365
- var import_effect23 = require("effect");
4644
+ var import_effect27 = require("effect");
3366
4645
  var SchemaAST2 = __toESM(require("effect/SchemaAST"), 1);
3367
4646
 
3368
4647
  // src/internal/state-trait/exec-vm-mode.ts
3369
- var import_effect24 = require("effect");
3370
- var currentExecVmMode = import_effect24.FiberRef.unsafeMake(false);
4648
+ var import_effect28 = require("effect");
4649
+ var currentExecVmMode = import_effect28.FiberRef.unsafeMake(false);
3371
4650
 
3372
4651
  // src/internal/state-trait/converge-step.ts
3373
- var import_effect25 = require("effect");
4652
+ var import_effect29 = require("effect");
3374
4653
 
3375
- // src/internal/state-trait/validate.ts
3376
- var import_effect27 = require("effect");
4654
+ // src/internal/state-trait/validate.impl.ts
4655
+ var import_effect31 = require("effect");
3377
4656
  var import_mutative = require("mutative");
3378
4657
  var nowMs = (() => {
3379
4658
  const perf = globalThis.performance;
@@ -3383,42 +4662,42 @@ var nowMs = (() => {
3383
4662
  return () => Date.now();
3384
4663
  })();
3385
4664
 
3386
- // src/internal/state-trait/source.ts
3387
- var import_effect30 = require("effect");
4665
+ // src/internal/state-trait/source.impl.ts
4666
+ var import_effect34 = require("effect");
3388
4667
  var import_mutative2 = require("mutative");
3389
4668
 
3390
4669
  // src/internal/resource.ts
3391
- var import_effect28 = require("effect");
3392
- var ResourceRegistryTag = class extends import_effect28.Context.Tag("@logixjs/core/ResourceRegistry")() {
4670
+ var import_effect32 = require("effect");
4671
+ var ResourceRegistryTag = class extends import_effect32.Context.Tag("@logixjs/core/ResourceRegistry")() {
3393
4672
  };
3394
4673
 
3395
4674
  // src/internal/runtime/core/ReplayLog.ts
3396
- var import_effect29 = require("effect");
3397
- var ReplayLog = class extends import_effect29.Context.Tag("@logixjs/core/ReplayLog")() {
4675
+ var import_effect33 = require("effect");
4676
+ var ReplayLog = class extends import_effect33.Context.Tag("@logixjs/core/ReplayLog")() {
3398
4677
  };
3399
- var snapshot = import_effect29.Effect.gen(function* () {
4678
+ var snapshot = import_effect33.Effect.gen(function* () {
3400
4679
  const log = yield* ReplayLog;
3401
4680
  return yield* log.snapshot;
3402
4681
  });
3403
- var resetCursor = import_effect29.Effect.gen(function* () {
4682
+ var resetCursor = import_effect33.Effect.gen(function* () {
3404
4683
  const log = yield* ReplayLog;
3405
4684
  yield* log.resetCursor;
3406
4685
  });
3407
4686
 
3408
4687
  // src/internal/runtime/core/ModuleRuntime.concurrencyPolicy.ts
3409
- var import_effect32 = require("effect");
4688
+ var import_effect36 = require("effect");
3410
4689
 
3411
4690
  // src/internal/runtime/core/ModuleRuntime.txnLanePolicy.ts
3412
- var import_effect33 = require("effect");
4691
+ var import_effect37 = require("effect");
3413
4692
 
3414
4693
  // src/internal/runtime/core/ModuleRuntime.traitConvergeConfig.ts
3415
- var import_effect34 = require("effect");
4694
+ var import_effect38 = require("effect");
3416
4695
 
3417
4696
  // src/internal/state-trait/build.ts
3418
4697
  var SchemaAST3 = __toESM(require("effect/SchemaAST"), 1);
3419
4698
 
3420
4699
  // src/internal/runtime/core/ModuleRuntime.internalHooks.ts
3421
- var import_effect35 = require("effect");
4700
+ var import_effect39 = require("effect");
3422
4701
 
3423
4702
  // src/internal/runtime/core/ReadQuery.ts
3424
4703
  function isReadQuery(input) {
@@ -3428,25 +4707,25 @@ function isReadQuery(input) {
3428
4707
  }
3429
4708
 
3430
4709
  // src/internal/runtime/core/SelectorGraph.ts
3431
- var import_effect36 = require("effect");
4710
+ var import_effect40 = require("effect");
3432
4711
 
3433
4712
  // src/internal/runtime/core/ModuleRuntime.registry.ts
3434
4713
  var runtimeByInstanceKey = /* @__PURE__ */ new Map();
3435
4714
  var getRuntimeByModuleAndInstance = (moduleId, instanceId) => runtimeByInstanceKey.get(`${moduleId}::${instanceId}`);
3436
4715
 
3437
4716
  // src/internal/runtime/core/ModuleRuntime.txnQueue.ts
3438
- var import_effect37 = require("effect");
4717
+ var import_effect41 = require("effect");
3439
4718
 
3440
4719
  // src/internal/runtime/core/ModuleRuntime.logics.ts
3441
- var import_effect41 = require("effect");
4720
+ var import_effect45 = require("effect");
3442
4721
 
3443
4722
  // src/internal/runtime/core/LifecycleDiagnostics.ts
3444
- var import_effect38 = require("effect");
4723
+ var import_effect42 = require("effect");
3445
4724
 
3446
4725
  // src/internal/runtime/core/LogicDiagnostics.ts
3447
- var import_effect39 = require("effect");
3448
- var LogicPhaseServiceTag = import_effect39.Context.GenericTag("@logixjs/LogicPhaseService");
3449
- var LogicUnitServiceTag = class extends import_effect39.Context.Tag("@logixjs/LogicUnitService")() {
4726
+ var import_effect43 = require("effect");
4727
+ var LogicPhaseServiceTag = import_effect43.Context.GenericTag("@logixjs/LogicPhaseService");
4728
+ var LogicUnitServiceTag = class extends import_effect43.Context.Tag("@logixjs/LogicUnitService")() {
3450
4729
  };
3451
4730
  var makeLogicPhaseError = (kind, api, phase, moduleId) => Object.assign(new Error(`[LogicPhaseError] ${api} is not allowed in ${phase} phase (kind=${kind}).`), {
3452
4731
  _tag: "LogicPhaseError",
@@ -3457,219 +4736,15 @@ var makeLogicPhaseError = (kind, api, phase, moduleId) => Object.assign(new Erro
3457
4736
  });
3458
4737
 
3459
4738
  // src/internal/runtime/core/Platform.ts
3460
- var import_effect40 = require("effect");
3461
- var Tag = import_effect40.Context.GenericTag("@logixjs/Platform");
4739
+ var import_effect44 = require("effect");
4740
+ var Tag = import_effect44.Context.GenericTag("@logixjs/Platform");
3462
4741
 
3463
4742
  // src/internal/runtime/core/ConcurrencyDiagnostics.ts
3464
- var import_effect42 = require("effect");
3465
- var nowMs2 = import_effect42.Effect.clockWith((clock) => clock.currentTimeMillis);
3466
-
3467
- // src/Debug.ts
3468
- var import_effect45 = require("effect");
3469
-
3470
- // src/internal/runtime/core/DevtoolsHub.ts
3471
- var import_effect44 = require("effect");
3472
- var instances = /* @__PURE__ */ new Map();
3473
- var latestStates = /* @__PURE__ */ new Map();
3474
- var latestTraitSummaries = /* @__PURE__ */ new Map();
3475
- var instanceLabels = /* @__PURE__ */ new Map();
3476
- var convergeStaticIrByDigest = /* @__PURE__ */ new Map();
3477
- var liveInstanceKeys = /* @__PURE__ */ new Set();
3478
- var exportBudget = {
3479
- dropped: 0,
3480
- oversized: 0
3481
- };
3482
- var lastRunTs = 0;
3483
- var lastRunTsSeq = 0;
3484
- var nextRunId = () => {
3485
- const ts = Date.now();
3486
- if (ts === lastRunTs) {
3487
- lastRunTsSeq += 1;
3488
- } else {
3489
- lastRunTs = ts;
3490
- lastRunTsSeq = 0;
3491
- }
3492
- return lastRunTsSeq === 0 ? `run-${ts}` : `run-${ts}.${lastRunTsSeq}`;
3493
- };
3494
- var currentRunId = nextRunId();
3495
- var nextSeq = 1;
3496
- var bufferSize = 500;
3497
- var ringBuffer = [];
3498
- var ringBufferSeq = [];
3499
- var snapshotToken = 0;
3500
- var ensureRingBufferSize = () => {
3501
- if (bufferSize <= 0) {
3502
- ringBuffer.length = 0;
3503
- ringBufferSeq.length = 0;
3504
- return;
3505
- }
3506
- if (ringBuffer.length <= bufferSize) return;
3507
- const excess = ringBuffer.length - bufferSize;
3508
- ringBuffer.splice(0, excess);
3509
- ringBufferSeq.splice(0, excess);
3510
- };
3511
- var trimRingBufferIfNeeded = () => {
3512
- if (bufferSize <= 0) {
3513
- ringBuffer.length = 0;
3514
- ringBufferSeq.length = 0;
3515
- return;
3516
- }
3517
- if (bufferSize <= 64) {
3518
- ensureRingBufferSize();
3519
- return;
3520
- }
3521
- const slack = Math.min(1024, Math.floor(bufferSize / 2));
3522
- const threshold = bufferSize + Math.max(1, slack);
3523
- if (ringBuffer.length <= threshold) return;
3524
- const excess = ringBuffer.length - bufferSize;
3525
- ringBuffer.splice(0, excess);
3526
- ringBufferSeq.splice(0, excess);
3527
- };
3528
- var currentSnapshot = {
3529
- snapshotToken,
3530
- instances,
3531
- events: ringBuffer,
3532
- latestStates,
3533
- latestTraitSummaries,
3534
- exportBudget
3535
- };
3536
- var listeners = /* @__PURE__ */ new Set();
3537
- var notifyScheduled = false;
3538
- var scheduleNotify = () => {
3539
- if (notifyScheduled) return;
3540
- notifyScheduled = true;
3541
- queueMicrotask(() => {
3542
- notifyScheduled = false;
3543
- for (const listener of listeners) {
3544
- listener();
3545
- }
3546
- });
3547
- };
3548
- var devtoolsEnabled = false;
3549
- var bumpSnapshotToken = () => {
3550
- snapshotToken += 1;
3551
- currentSnapshot.snapshotToken = snapshotToken;
3552
- };
3553
- var markSnapshotChanged = () => {
3554
- bumpSnapshotToken();
3555
- scheduleNotify();
3556
- };
3557
- var configureDevtoolsHub = (options) => {
3558
- devtoolsEnabled = true;
3559
- if (typeof options?.bufferSize === "number" && Number.isFinite(options.bufferSize)) {
3560
- const next = Math.floor(options.bufferSize);
3561
- const nextBufferSize = next >= 0 ? next : 0;
3562
- if (nextBufferSize !== bufferSize) {
3563
- bufferSize = nextBufferSize;
3564
- ensureRingBufferSize();
3565
- markSnapshotChanged();
3566
- }
3567
- }
3568
- };
3569
- var registerConvergeStaticIr = (ir) => {
3570
- convergeStaticIrByDigest.set(ir.staticIrDigest, ir);
3571
- };
3572
- var devtoolsHubConvergeStaticIrCollector = {
3573
- register: registerConvergeStaticIr
3574
- };
3575
- var devtoolsHubSink = {
3576
- record: (event) => import_effect44.Effect.gen(function* () {
3577
- const level = yield* import_effect44.FiberRef.get(currentDiagnosticsLevel);
3578
- let changed = false;
3579
- if (event.type === "trace:instanceLabel") {
3580
- const instanceId = event.instanceId;
3581
- const data = event.data;
3582
- const label = data && typeof data === "object" && "label" in data ? String(data.label) : void 0;
3583
- if (instanceId && label) {
3584
- instanceLabels.set(instanceId, label);
3585
- changed = true;
3586
- }
3587
- }
3588
- if (event.type === "module:init" || event.type === "module:destroy") {
3589
- const moduleId = event.moduleId ?? "unknown";
3590
- const runtimeLabel2 = event.runtimeLabel ?? "unknown";
3591
- const instanceId = event.instanceId;
3592
- const key = `${runtimeLabel2}::${moduleId}`;
3593
- const prev = instances.get(key) ?? 0;
3594
- if (event.type === "module:init") {
3595
- instances.set(key, prev + 1);
3596
- changed = true;
3597
- if (instanceId) {
3598
- const instanceKey = `${runtimeLabel2}::${moduleId}::${instanceId}`;
3599
- liveInstanceKeys.add(instanceKey);
3600
- if (latestStates.delete(instanceKey)) changed = true;
3601
- if (latestTraitSummaries.delete(instanceKey)) changed = true;
3602
- }
3603
- } else {
3604
- const next = prev - 1;
3605
- if (next <= 0) {
3606
- if (instances.delete(key)) changed = true;
3607
- } else {
3608
- instances.set(key, next);
3609
- changed = true;
3610
- }
3611
- if (instanceId) {
3612
- const instanceKey = `${runtimeLabel2}::${moduleId}::${instanceId}`;
3613
- liveInstanceKeys.delete(instanceKey);
3614
- if (latestStates.delete(instanceKey)) changed = true;
3615
- if (latestTraitSummaries.delete(instanceKey)) changed = true;
3616
- if (instanceLabels.delete(instanceId)) changed = true;
3617
- changed = true;
3618
- }
3619
- }
3620
- }
3621
- let exportBudgetChanged = false;
3622
- const ref = toRuntimeDebugEventRef(event, {
3623
- diagnosticsLevel: level,
3624
- resolveConvergeStaticIr: (staticIrDigest) => convergeStaticIrByDigest.get(staticIrDigest),
3625
- onMetaProjection: ({ stats }) => {
3626
- if (stats.dropped !== 0 || stats.oversized !== 0) {
3627
- exportBudgetChanged = true;
3628
- }
3629
- exportBudget.dropped += stats.dropped;
3630
- exportBudget.oversized += stats.oversized;
3631
- }
3632
- });
3633
- if (exportBudgetChanged) {
3634
- changed = true;
3635
- }
3636
- if (!ref) {
3637
- if (changed) {
3638
- markSnapshotChanged();
3639
- }
3640
- return;
3641
- }
3642
- if (ref.kind === "state" && ref.label === "state:update") {
3643
- const runtimeLabel2 = ref.runtimeLabel ?? "unknown";
3644
- const key = `${runtimeLabel2}::${ref.moduleId}::${ref.instanceId}`;
3645
- if (liveInstanceKeys.has(key)) {
3646
- if (ref.meta && typeof ref.meta === "object" && !Array.isArray(ref.meta)) {
3647
- const anyMeta = ref.meta;
3648
- if ("state" in anyMeta) {
3649
- latestStates.set(key, anyMeta.state);
3650
- changed = true;
3651
- }
3652
- if ("traitSummary" in anyMeta && anyMeta.traitSummary !== void 0) {
3653
- latestTraitSummaries.set(key, anyMeta.traitSummary);
3654
- changed = true;
3655
- }
3656
- }
3657
- }
3658
- }
3659
- if (bufferSize > 0) {
3660
- const seq = nextSeq++;
3661
- ringBuffer.push(ref);
3662
- ringBufferSeq.push(seq);
3663
- trimRingBufferIfNeeded();
3664
- changed = true;
3665
- }
3666
- if (changed) {
3667
- markSnapshotChanged();
3668
- }
3669
- })
3670
- };
4743
+ var import_effect46 = require("effect");
4744
+ var nowMs2 = import_effect46.Effect.clockWith((clock) => clock.currentTimeMillis);
3671
4745
 
3672
4746
  // src/Debug.ts
4747
+ var import_effect48 = require("effect");
3673
4748
  var internal2 = {
3674
4749
  currentDebugSinks,
3675
4750
  currentRuntimeLabel,
@@ -3677,7 +4752,7 @@ var internal2 = {
3677
4752
  currentTraitConvergeDiagnosticsSampling,
3678
4753
  toRuntimeDebugEventRef
3679
4754
  };
3680
- var diagnosticsLevel = (level) => import_effect45.Layer.fiberRefLocallyScopedWith(currentDiagnosticsLevel, () => level);
4755
+ var diagnosticsLevel = (level) => import_effect48.Layer.fiberRefLocallyScopedWith(currentDiagnosticsLevel, () => level);
3681
4756
  var traitConvergeDiagnosticsSampling2 = (config) => traitConvergeDiagnosticsSampling(config);
3682
4757
  var record2 = record;
3683
4758
  var resolveMode = (mode) => {
@@ -3702,16 +4777,16 @@ var layer2 = (options) => {
3702
4777
  }
3703
4778
  }
3704
4779
  })();
3705
- return diagnostics ? import_effect45.Layer.mergeAll(sinks, diagnosticsLevel(diagnostics)) : sinks;
4780
+ return diagnostics ? import_effect48.Layer.mergeAll(sinks, diagnosticsLevel(diagnostics)) : sinks;
3706
4781
  };
3707
- var appendSinks = (sinks) => import_effect45.Layer.fiberRefLocallyScopedWith(currentDebugSinks, (current) => [
4782
+ var appendSinks = (sinks) => import_effect48.Layer.fiberRefLocallyScopedWith(currentDebugSinks, (current) => [
3708
4783
  ...current,
3709
4784
  ...sinks
3710
4785
  ]);
3711
4786
  function devtoolsHubLayer(baseOrOptions, maybeOptions) {
3712
4787
  const isLayerValue = (value) => typeof value === "object" && value !== null && "_op_layer" in value;
3713
4788
  const hasBase = isLayerValue(baseOrOptions);
3714
- const base = hasBase ? baseOrOptions : import_effect45.Layer.empty;
4789
+ const base = hasBase ? baseOrOptions : import_effect48.Layer.empty;
3715
4790
  const options = hasBase ? maybeOptions : baseOrOptions;
3716
4791
  configureDevtoolsHub(options);
3717
4792
  const append = appendSinks([devtoolsHubSink]);
@@ -3719,24 +4794,24 @@ function devtoolsHubLayer(baseOrOptions, maybeOptions) {
3719
4794
  devtoolsHubConvergeStaticIrCollector
3720
4795
  ]);
3721
4796
  const enableExportableDiagnostics = diagnosticsLevel(options?.diagnosticsLevel ?? "light");
3722
- const convergeSamplingLayer = options?.traitConvergeDiagnosticsSampling ? traitConvergeDiagnosticsSampling2(options.traitConvergeDiagnosticsSampling) : import_effect45.Layer.empty;
3723
- return import_effect45.Layer.provideMerge(
3724
- import_effect45.Layer.mergeAll(append, enableExportableDiagnostics, convergeSamplingLayer, appendConvergeStaticIr),
4797
+ const convergeSamplingLayer = options?.traitConvergeDiagnosticsSampling ? traitConvergeDiagnosticsSampling2(options.traitConvergeDiagnosticsSampling) : import_effect48.Layer.empty;
4798
+ return import_effect48.Layer.provideMerge(
4799
+ import_effect48.Layer.mergeAll(append, enableExportableDiagnostics, convergeSamplingLayer, appendConvergeStaticIr),
3725
4800
  base
3726
4801
  );
3727
4802
  }
3728
- var runtimeLabel = (label) => import_effect45.Layer.fiberRefLocallyScopedWith(internal2.currentRuntimeLabel, () => label);
4803
+ var runtimeLabel = (label) => import_effect48.Layer.fiberRefLocallyScopedWith(internal2.currentRuntimeLabel, () => label);
3729
4804
 
3730
4805
  // src/Middleware.ts
3731
- var import_effect46 = require("effect");
3732
- var makeDebugLogger = (config) => (op) => import_effect46.Effect.gen(function* () {
4806
+ var import_effect49 = require("effect");
4807
+ var makeDebugLogger = (config) => (op) => import_effect49.Effect.gen(function* () {
3733
4808
  if (op.meta?.policy?.disableObservers) {
3734
4809
  return yield* op.effect;
3735
4810
  }
3736
4811
  if (config?.logger) {
3737
4812
  config.logger(op);
3738
4813
  } else {
3739
- yield* import_effect46.Effect.logDebug(`[EffectOp] kind=${op.kind} name=${op.name}`);
4814
+ yield* import_effect49.Effect.logDebug(`[EffectOp] kind=${op.kind} name=${op.name}`);
3740
4815
  }
3741
4816
  return yield* op.effect;
3742
4817
  });
@@ -3744,7 +4819,7 @@ var applyDebug = (stack, config) => [
3744
4819
  ...stack,
3745
4820
  makeDebugLogger(config)
3746
4821
  ];
3747
- var makeDebugObserver = (config) => (op) => import_effect46.Effect.gen(function* () {
4822
+ var makeDebugObserver = (config) => (op) => import_effect49.Effect.gen(function* () {
3748
4823
  if (op.meta?.policy?.disableObservers) {
3749
4824
  return yield* op.effect;
3750
4825
  }
@@ -3787,15 +4862,15 @@ var withDebug = (stack, options) => {
3787
4862
  };
3788
4863
 
3789
4864
  // src/ScopeRegistry.ts
3790
- var import_effect47 = require("effect");
4865
+ var import_effect50 = require("effect");
3791
4866
 
3792
4867
  // src/Env.ts
3793
4868
  var isDevEnv2 = () => isDevEnv();
3794
4869
 
3795
4870
  // src/ScopeRegistry.ts
3796
- var ScopeRegistryTag = class extends import_effect47.Context.Tag("@logixjs/core/ScopeRegistry")() {
4871
+ var ScopeRegistryTag = class extends import_effect50.Context.Tag("@logixjs/core/ScopeRegistry")() {
3797
4872
  };
3798
- var ScopedRuntimeTag = class extends import_effect47.Context.Tag("@logixjs/core/ScopeRegistry/ScopedRuntime")() {
4873
+ var ScopedRuntimeTag = class extends import_effect50.Context.Tag("@logixjs/core/ScopeRegistry/ScopedRuntime")() {
3799
4874
  };
3800
4875
  var makeRegistry = () => {
3801
4876
  let nextLeaseId = 0;
@@ -3874,15 +4949,15 @@ var makeRegistry = () => {
3874
4949
  };
3875
4950
  return { register, get, clearToken, clearScope, clearAll };
3876
4951
  };
3877
- var layer3 = () => import_effect47.Layer.succeed(ScopeRegistryTag, makeRegistry());
4952
+ var layer3 = () => import_effect50.Layer.succeed(ScopeRegistryTag, makeRegistry());
3878
4953
 
3879
4954
  // src/internal/runtime/core/configValidation.ts
3880
- var import_effect48 = require("effect");
3881
- var PositiveIntSchema = import_effect48.Schema.Int.pipe(import_effect48.Schema.positive());
3882
- var PositiveNumberSchema = import_effect48.Schema.Number.pipe(import_effect48.Schema.positive());
3883
- var ConvergeModeSchema = import_effect48.Schema.Union(import_effect48.Schema.Literal("auto"), import_effect48.Schema.Literal("full"), import_effect48.Schema.Literal("dirty"));
3884
- var InstrumentationSchema = import_effect48.Schema.Union(import_effect48.Schema.Literal("full"), import_effect48.Schema.Literal("light"));
3885
- var ConcurrencyLimitSchema = import_effect48.Schema.Union(import_effect48.Schema.Literal("unbounded"), PositiveIntSchema);
4955
+ var import_effect51 = require("effect");
4956
+ var PositiveIntSchema = import_effect51.Schema.Int.pipe(import_effect51.Schema.positive());
4957
+ var PositiveNumberSchema = import_effect51.Schema.Number.pipe(import_effect51.Schema.positive());
4958
+ var ConvergeModeSchema = import_effect51.Schema.Union(import_effect51.Schema.Literal("auto"), import_effect51.Schema.Literal("full"), import_effect51.Schema.Literal("dirty"));
4959
+ var InstrumentationSchema = import_effect51.Schema.Union(import_effect51.Schema.Literal("full"), import_effect51.Schema.Literal("light"));
4960
+ var ConcurrencyLimitSchema = import_effect51.Schema.Union(import_effect51.Schema.Literal("unbounded"), PositiveIntSchema);
3886
4961
  var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
3887
4962
  var warnDevOnly = (label, issues) => {
3888
4963
  if (!isDevEnv()) return;
@@ -3903,7 +4978,7 @@ var collectUnknownKeys = (obj, allowed, prefix) => {
3903
4978
  var validateConcurrencyPolicyPatch = (obj, prefix) => {
3904
4979
  const issues = [];
3905
4980
  if ("concurrencyLimit" in obj && obj.concurrencyLimit != null) {
3906
- if (!import_effect48.Schema.is(ConcurrencyLimitSchema)(obj.concurrencyLimit)) {
4981
+ if (!import_effect51.Schema.is(ConcurrencyLimitSchema)(obj.concurrencyLimit)) {
3907
4982
  issues.push(`${prefix}concurrencyLimit: expected positive int | "unbounded"`);
3908
4983
  }
3909
4984
  }
@@ -4025,7 +5100,7 @@ var warnInvalidConcurrencyPolicyPatchDevOnly = (value, label) => {
4025
5100
  var validateStateTransactionTraitOverrides = (obj, prefix) => {
4026
5101
  const issues = [];
4027
5102
  if ("traitConvergeMode" in obj && obj.traitConvergeMode != null) {
4028
- if (!import_effect48.Schema.is(ConvergeModeSchema)(obj.traitConvergeMode)) {
5103
+ if (!import_effect51.Schema.is(ConvergeModeSchema)(obj.traitConvergeMode)) {
4029
5104
  issues.push(`${prefix}traitConvergeMode: expected "auto" | "full" | "dirty"`);
4030
5105
  }
4031
5106
  }
@@ -4154,7 +5229,7 @@ var warnInvalidStateTransactionRuntimeConfigDevOnly = (value, label) => {
4154
5229
  )
4155
5230
  );
4156
5231
  if ("instrumentation" in value && value.instrumentation != null) {
4157
- if (!import_effect48.Schema.is(InstrumentationSchema)(value.instrumentation)) {
5232
+ if (!import_effect51.Schema.is(InstrumentationSchema)(value.instrumentation)) {
4158
5233
  issues.push(`instrumentation: expected "full" | "light"`);
4159
5234
  }
4160
5235
  }
@@ -4331,14 +5406,14 @@ var warnInvalidStateTransactionOverridesDevOnly = (value, label) => {
4331
5406
  };
4332
5407
 
4333
5408
  // src/internal/runtime/core/runner/ProgramRunner.ts
4334
- var import_effect57 = require("effect");
5409
+ var import_effect60 = require("effect");
4335
5410
 
4336
5411
  // src/internal/runtime/core/BoundApiRuntime.ts
4337
- var import_effect53 = require("effect");
5412
+ var import_effect56 = require("effect");
4338
5413
 
4339
5414
  // src/internal/action.ts
4340
- var import_effect49 = require("effect");
4341
- var isActionToken = (value) => typeof value === "function" && value._kind === "ActionToken" && typeof value.tag === "string" && import_effect49.Schema.isSchema(value.schema);
5415
+ var import_effect52 = require("effect");
5416
+ var isActionToken = (value) => typeof value === "function" && value._kind === "ActionToken" && typeof value.tag === "string" && import_effect52.Schema.isSchema(value.schema);
4342
5417
 
4343
5418
  // src/internal/runtime/core/mutativePatches.ts
4344
5419
  var import_mutative3 = require("mutative");
@@ -4384,9 +5459,9 @@ var mutateWithPatchPaths = (base, mutator) => {
4384
5459
  };
4385
5460
 
4386
5461
  // src/internal/runtime/core/FlowRuntime.ts
4387
- var import_effect50 = require("effect");
4388
- var getMiddlewareStack2 = () => import_effect50.Effect.serviceOption(EffectOpMiddlewareTag).pipe(
4389
- import_effect50.Effect.map((maybe) => import_effect50.Option.isSome(maybe) ? maybe.value.stack : [])
5462
+ var import_effect53 = require("effect");
5463
+ var getMiddlewareStack2 = () => import_effect53.Effect.serviceOption(EffectOpMiddlewareTag).pipe(
5464
+ import_effect53.Effect.map((maybe) => import_effect53.Option.isSome(maybe) ? maybe.value.stack : [])
4390
5465
  );
4391
5466
  var getRuntimeScope = (runtime) => {
4392
5467
  if (!runtime) return {};
@@ -4400,8 +5475,8 @@ var getRuntimeScope = (runtime) => {
4400
5475
  var resolveEffect = (eff, payload) => typeof eff === "function" ? eff(payload) : eff;
4401
5476
  var make5 = (runtime, runtimeInternals) => {
4402
5477
  const scope = getRuntimeScope(runtime);
4403
- const resolveConcurrencyLimit2 = () => runtimeInternals ? runtimeInternals.concurrency.resolveConcurrencyPolicy().pipe(import_effect50.Effect.map((p) => p.concurrencyLimit)) : import_effect50.Effect.succeed(16);
4404
- const runAsFlowOp = (name, payload, eff, options) => import_effect50.Effect.gen(function* () {
5478
+ const resolveConcurrencyLimit2 = () => runtimeInternals ? runtimeInternals.concurrency.resolveConcurrencyPolicy().pipe(import_effect53.Effect.map((p) => p.concurrencyLimit)) : import_effect53.Effect.succeed(16);
5479
+ const runAsFlowOp = (name, payload, eff, options) => import_effect53.Effect.gen(function* () {
4405
5480
  const stack = yield* getMiddlewareStack2();
4406
5481
  const meta = {
4407
5482
  ...options?.meta ?? {},
@@ -4412,8 +5487,8 @@ var make5 = (runtime, runtimeInternals) => {
4412
5487
  instanceId: scope.instanceId
4413
5488
  };
4414
5489
  if (!(typeof meta.opSeq === "number" && Number.isFinite(meta.opSeq))) {
4415
- const sessionOpt = yield* import_effect50.Effect.serviceOption(RunSessionTag);
4416
- if (import_effect50.Option.isSome(sessionOpt)) {
5490
+ const sessionOpt = yield* import_effect53.Effect.serviceOption(RunSessionTag);
5491
+ if (import_effect53.Option.isSome(sessionOpt)) {
4417
5492
  const key = meta.instanceId ?? "global";
4418
5493
  meta.opSeq = sessionOpt.value.local.nextSeq("opSeq", key);
4419
5494
  }
@@ -4428,21 +5503,21 @@ var make5 = (runtime, runtimeInternals) => {
4428
5503
  return yield* run(op, stack);
4429
5504
  });
4430
5505
  const runEffect = (eff) => (payload) => resolveEffect(eff, payload);
4431
- const runStreamSequential = (eff, options) => (stream) => import_effect50.Stream.runForEach(
5506
+ const runStreamSequential = (eff, options) => (stream) => import_effect53.Stream.runForEach(
4432
5507
  stream,
4433
5508
  (payload) => runAsFlowOp("flow.run", payload, runEffect(eff)(payload), options)
4434
5509
  );
4435
- const runStreamParallel = (eff, options) => (stream) => import_effect50.Effect.gen(function* () {
5510
+ const runStreamParallel = (eff, options) => (stream) => import_effect53.Effect.gen(function* () {
4436
5511
  const concurrency = yield* resolveConcurrencyLimit2();
4437
- return yield* import_effect50.Stream.runDrain(
5512
+ return yield* import_effect53.Stream.runDrain(
4438
5513
  stream.pipe(
4439
- import_effect50.Stream.mapEffect(
5514
+ import_effect53.Stream.mapEffect(
4440
5515
  (payload) => runAsFlowOp("flow.runParallel", payload, runEffect(eff)(payload), options),
4441
5516
  { concurrency }
4442
5517
  )
4443
5518
  )
4444
5519
  ).pipe(
4445
- import_effect50.Effect.catchAllCause(
5520
+ import_effect53.Effect.catchAllCause(
4446
5521
  (cause) => record({
4447
5522
  type: "diagnostic",
4448
5523
  moduleId: scope.moduleId,
@@ -4456,25 +5531,25 @@ var make5 = (runtime, runtimeInternals) => {
4456
5531
  kind: "flow",
4457
5532
  name: "runParallel"
4458
5533
  }
4459
- }).pipe(import_effect50.Effect.zipRight(import_effect50.Effect.failCause(cause)))
5534
+ }).pipe(import_effect53.Effect.zipRight(import_effect53.Effect.failCause(cause)))
4460
5535
  )
4461
5536
  );
4462
5537
  });
4463
5538
  return {
4464
- fromAction: (predicate) => runtime.actions$.pipe(import_effect50.Stream.filter(predicate)),
5539
+ fromAction: (predicate) => runtime.actions$.pipe(import_effect53.Stream.filter(predicate)),
4465
5540
  fromState: (selectorOrQuery) => runtime.changes(isReadQuery(selectorOrQuery) ? selectorOrQuery.select : selectorOrQuery),
4466
- debounce: (ms) => (stream) => import_effect50.Stream.debounce(stream, ms),
4467
- throttle: (ms) => (stream) => import_effect50.Stream.throttle(stream, {
5541
+ debounce: (ms) => (stream) => import_effect53.Stream.debounce(stream, ms),
5542
+ throttle: (ms) => (stream) => import_effect53.Stream.throttle(stream, {
4468
5543
  cost: () => 1,
4469
5544
  units: 1,
4470
5545
  duration: ms,
4471
5546
  strategy: "enforce"
4472
5547
  }),
4473
- filter: (predicate) => (stream) => import_effect50.Stream.filter(stream, predicate),
5548
+ filter: (predicate) => (stream) => import_effect53.Stream.filter(stream, predicate),
4474
5549
  run: (eff, options) => (stream) => runStreamSequential(eff, options)(stream),
4475
5550
  runParallel: (eff, options) => (stream) => runStreamParallel(eff, options)(stream),
4476
- runLatest: (eff, options) => (stream) => import_effect50.Stream.runDrain(
4477
- import_effect50.Stream.map(
5551
+ runLatest: (eff, options) => (stream) => import_effect53.Stream.runDrain(
5552
+ import_effect53.Stream.map(
4478
5553
  stream,
4479
5554
  (payload) => runAsFlowOp(
4480
5555
  "flow.runLatest",
@@ -4483,16 +5558,16 @@ var make5 = (runtime, runtimeInternals) => {
4483
5558
  options
4484
5559
  )
4485
5560
  ).pipe(
4486
- import_effect50.Stream.flatMap((effect) => import_effect50.Stream.fromEffect(effect), {
5561
+ import_effect53.Stream.flatMap((effect) => import_effect53.Stream.fromEffect(effect), {
4487
5562
  switch: true
4488
5563
  })
4489
5564
  )
4490
5565
  ),
4491
- runExhaust: (eff, options) => (stream) => import_effect50.Effect.gen(function* () {
5566
+ runExhaust: (eff, options) => (stream) => import_effect53.Effect.gen(function* () {
4492
5567
  const concurrency = yield* resolveConcurrencyLimit2();
4493
- const busyRef = yield* import_effect50.Ref.make(false);
4494
- const mapper = (payload) => import_effect50.Effect.gen(function* () {
4495
- const acquired = yield* import_effect50.Ref.modify(
5568
+ const busyRef = yield* import_effect53.Ref.make(false);
5569
+ const mapper = (payload) => import_effect53.Effect.gen(function* () {
5570
+ const acquired = yield* import_effect53.Ref.modify(
4496
5571
  busyRef,
4497
5572
  (busy) => busy ? [false, busy] : [true, true]
4498
5573
  );
@@ -4507,16 +5582,16 @@ var make5 = (runtime, runtimeInternals) => {
4507
5582
  options
4508
5583
  );
4509
5584
  } finally {
4510
- yield* import_effect50.Ref.set(busyRef, false);
5585
+ yield* import_effect53.Ref.set(busyRef, false);
4511
5586
  }
4512
5587
  });
4513
- return yield* import_effect50.Stream.runDrain(stream.pipe(import_effect50.Stream.mapEffect(mapper, { concurrency })));
5588
+ return yield* import_effect53.Stream.runDrain(stream.pipe(import_effect53.Stream.mapEffect(mapper, { concurrency })));
4514
5589
  })
4515
5590
  };
4516
5591
  };
4517
5592
 
4518
5593
  // src/internal/runtime/core/MatchBuilder.ts
4519
- var import_effect51 = require("effect");
5594
+ var import_effect54 = require("effect");
4520
5595
  var makeMatch = (value) => {
4521
5596
  let result;
4522
5597
  const chain = {
@@ -4535,7 +5610,7 @@ var makeMatch = (value) => {
4535
5610
  if (result) {
4536
5611
  return result;
4537
5612
  }
4538
- return import_effect51.Effect.dieMessage("[FluentMatch] Non-exhaustive match: no pattern matched value");
5613
+ return import_effect54.Effect.dieMessage("[FluentMatch] Non-exhaustive match: no pattern matched value");
4539
5614
  }
4540
5615
  };
4541
5616
  return chain;
@@ -4558,14 +5633,14 @@ var makeMatchTag = (value) => {
4558
5633
  if (result) {
4559
5634
  return result;
4560
5635
  }
4561
- return import_effect51.Effect.dieMessage("[FluentMatchTag] Non-exhaustive match: no tag handler matched value");
5636
+ return import_effect54.Effect.dieMessage("[FluentMatchTag] Non-exhaustive match: no tag handler matched value");
4562
5637
  }
4563
5638
  };
4564
5639
  return chain;
4565
5640
  };
4566
5641
 
4567
5642
  // src/internal/root.ts
4568
- var import_effect52 = require("effect");
5643
+ var import_effect55 = require("effect");
4569
5644
  var tagIdOf = (tag) => typeof tag?.id === "string" ? String(tag.id) : typeof tag?.key === "string" ? String(tag.key) : "<unknown tag>";
4570
5645
  var makeMissingRootProviderError = (tag, entrypoint, extra) => {
4571
5646
  const dev = isDevEnv();
@@ -4596,19 +5671,19 @@ ${extra}` : "",
4596
5671
  err.fix = fix;
4597
5672
  return err;
4598
5673
  };
4599
- var resolve2 = (tag, options) => import_effect52.Effect.gen(function* () {
5674
+ var resolve2 = (tag, options) => import_effect55.Effect.gen(function* () {
4600
5675
  const entrypoint = options?.entrypoint ?? "logic.root.resolve";
4601
5676
  const root = yield* RootContextTag;
4602
5677
  const rootContext = root.context ?? (options?.waitForReady ? yield* root.ready : void 0);
4603
5678
  if (!rootContext) {
4604
- return yield* import_effect52.Effect.die(
5679
+ return yield* import_effect55.Effect.die(
4605
5680
  makeMissingRootProviderError(tag, entrypoint, "reason: rootContextNotReady")
4606
5681
  );
4607
5682
  }
4608
5683
  try {
4609
- return import_effect52.Context.get(rootContext, tag);
5684
+ return import_effect55.Context.get(rootContext, tag);
4610
5685
  } catch {
4611
- return yield* import_effect52.Effect.die(makeMissingRootProviderError(tag, entrypoint));
5686
+ return yield* import_effect55.Effect.die(makeMissingRootProviderError(tag, entrypoint));
4612
5687
  }
4613
5688
  });
4614
5689
 
@@ -4627,7 +5702,7 @@ var LogicBuilderFactory = (runtime, runtimeInternals) => {
4627
5702
  debounce: (ms) => LogicBuilderFactory(runtime, runtimeInternals)(flowApi.debounce(ms)(stream), triggerName),
4628
5703
  throttle: (ms) => LogicBuilderFactory(runtime, runtimeInternals)(flowApi.throttle(ms)(stream), triggerName),
4629
5704
  filter: (predicate) => LogicBuilderFactory(runtime, runtimeInternals)(flowApi.filter(predicate)(stream), triggerName),
4630
- map: (f) => LogicBuilderFactory(runtime, runtimeInternals)(stream.pipe(import_effect53.Stream.map(f)), triggerName),
5705
+ map: (f) => LogicBuilderFactory(runtime, runtimeInternals)(stream.pipe(import_effect56.Stream.map(f)), triggerName),
4631
5706
  run(eff, options) {
4632
5707
  return flowApi.run(eff, options)(stream);
4633
5708
  },
@@ -4640,8 +5715,8 @@ var LogicBuilderFactory = (runtime, runtimeInternals) => {
4640
5715
  runParallel(eff, options) {
4641
5716
  return flowApi.runParallel(eff, options)(stream);
4642
5717
  },
4643
- runFork: (eff) => import_effect53.Effect.forkScoped(flowApi.run(eff)(stream)).pipe(import_effect53.Effect.asVoid),
4644
- runParallelFork: (eff) => import_effect53.Effect.forkScoped(flowApi.runParallel(eff)(stream)).pipe(import_effect53.Effect.asVoid),
5718
+ runFork: (eff) => import_effect56.Effect.forkScoped(flowApi.run(eff)(stream)).pipe(import_effect56.Effect.asVoid),
5719
+ runParallelFork: (eff) => import_effect56.Effect.forkScoped(flowApi.runParallel(eff)(stream)).pipe(import_effect56.Effect.asVoid),
4645
5720
  runTask: (config) => makeTaskRunner(stream, "task", taskRunnerRuntime, {
4646
5721
  ...config,
4647
5722
  triggerName: config.triggerName ?? triggerName
@@ -4659,20 +5734,20 @@ var LogicBuilderFactory = (runtime, runtimeInternals) => {
4659
5734
  triggerName: config.triggerName ?? triggerName
4660
5735
  }),
4661
5736
  toStream: () => stream,
4662
- update: (reducer) => import_effect53.Stream.runForEach(
5737
+ update: (reducer) => import_effect56.Stream.runForEach(
4663
5738
  stream,
4664
5739
  (payload) => taskRunnerRuntime.runWithStateTransaction(
4665
5740
  {
4666
5741
  kind: "watcher:update",
4667
5742
  name: triggerName
4668
5743
  },
4669
- () => import_effect53.Effect.gen(function* () {
5744
+ () => import_effect56.Effect.gen(function* () {
4670
5745
  const prev = yield* runtime.getState;
4671
5746
  const next = reducer(prev, payload);
4672
- if (import_effect53.Effect.isEffect(next)) {
4673
- const exit = yield* import_effect53.Effect.exit(next);
5747
+ if (import_effect56.Effect.isEffect(next)) {
5748
+ const exit = yield* import_effect56.Effect.exit(next);
4674
5749
  if (exit._tag === "Failure") {
4675
- yield* import_effect53.Effect.logError("Flow error", exit.cause);
5750
+ yield* import_effect56.Effect.logError("Flow error", exit.cause);
4676
5751
  return;
4677
5752
  }
4678
5753
  yield* runtime.setState(exit.value);
@@ -4681,15 +5756,15 @@ var LogicBuilderFactory = (runtime, runtimeInternals) => {
4681
5756
  yield* runtime.setState(next);
4682
5757
  })
4683
5758
  )
4684
- ).pipe(import_effect53.Effect.catchAllCause((cause) => import_effect53.Effect.logError("Flow error", cause))),
4685
- mutate: (reducer) => import_effect53.Stream.runForEach(
5759
+ ).pipe(import_effect56.Effect.catchAllCause((cause) => import_effect56.Effect.logError("Flow error", cause))),
5760
+ mutate: (reducer) => import_effect56.Stream.runForEach(
4686
5761
  stream,
4687
5762
  (payload) => taskRunnerRuntime.runWithStateTransaction(
4688
5763
  {
4689
5764
  kind: "watcher:mutate",
4690
5765
  name: triggerName
4691
5766
  },
4692
- () => import_effect53.Effect.gen(function* () {
5767
+ () => import_effect56.Effect.gen(function* () {
4693
5768
  const prev = yield* runtime.getState;
4694
5769
  const recordPatch2 = runtimeInternals.txn.recordStatePatch;
4695
5770
  const updateDraft2 = runtimeInternals.txn.updateDraft;
@@ -4702,7 +5777,7 @@ var LogicBuilderFactory = (runtime, runtimeInternals) => {
4702
5777
  updateDraft2(nextState);
4703
5778
  })
4704
5779
  )
4705
- ).pipe(import_effect53.Effect.catchAllCause((cause) => import_effect53.Effect.logError("Flow error", cause)))
5780
+ ).pipe(import_effect56.Effect.catchAllCause((cause) => import_effect56.Effect.logError("Flow error", cause)))
4706
5781
  };
4707
5782
  const pipe = function() {
4708
5783
  const fns = arguments;
@@ -4732,19 +5807,19 @@ function make6(shape, runtime, options) {
4732
5807
  };
4733
5808
  const flowApi = make5(runtime, runtimeInternals);
4734
5809
  const makeIntentBuilder = (runtime_) => LogicBuilderFactory(runtime_, runtimeInternals);
4735
- const withLifecycle = (available, missing) => import_effect53.Effect.serviceOption(LifecycleContext).pipe(
4736
- import_effect53.Effect.flatMap(
4737
- (maybe) => import_effect53.Option.match(maybe, {
5810
+ const withLifecycle = (available, missing) => import_effect56.Effect.serviceOption(LifecycleContext).pipe(
5811
+ import_effect56.Effect.flatMap(
5812
+ (maybe) => import_effect56.Option.match(maybe, {
4738
5813
  onSome: available,
4739
5814
  onNone: missing
4740
5815
  })
4741
5816
  )
4742
5817
  );
4743
- const withPlatform = (invoke) => import_effect53.Effect.serviceOption(Tag).pipe(
4744
- import_effect53.Effect.flatMap(
4745
- (maybe) => import_effect53.Option.match(maybe, {
5818
+ const withPlatform = (invoke) => import_effect56.Effect.serviceOption(Tag).pipe(
5819
+ import_effect56.Effect.flatMap(
5820
+ (maybe) => import_effect56.Option.match(maybe, {
4746
5821
  onSome: invoke,
4747
- onNone: () => import_effect53.Effect.void
5822
+ onNone: () => import_effect56.Effect.void
4748
5823
  })
4749
5824
  )
4750
5825
  );
@@ -4759,12 +5834,12 @@ function make6(shape, runtime, options) {
4759
5834
  kind: "lifecycle_in_run"
4760
5835
  });
4761
5836
  const createIntentBuilder = (stream, triggerName) => makeIntentBuilder(runtime)(stream, triggerName);
4762
- const onceInRunSession2 = (key) => import_effect53.Effect.serviceOption(RunSessionTag).pipe(
4763
- import_effect53.Effect.map((maybe) => import_effect53.Option.isSome(maybe) ? maybe.value.local.once(key) : true)
5837
+ const onceInRunSession2 = (key) => import_effect56.Effect.serviceOption(RunSessionTag).pipe(
5838
+ import_effect56.Effect.map((maybe) => import_effect56.Option.isSome(maybe) ? maybe.value.local.once(key) : true)
4764
5839
  );
4765
5840
  let cachedDiagnosticsLevel;
4766
5841
  const isModuleLike = (value) => Boolean(
4767
- value && typeof value === "object" && (value._kind === "ModuleDef" || value._kind === "Module") && "tag" in value && import_effect53.Context.isTag(value.tag)
5842
+ value && typeof value === "object" && (value._kind === "ModuleDef" || value._kind === "Module") && "tag" in value && import_effect56.Context.isTag(value.tag)
4768
5843
  );
4769
5844
  const buildModuleHandle = (tag, rt) => {
4770
5845
  const actionsProxy = new Proxy(
@@ -4777,7 +5852,7 @@ function make6(shape, runtime, options) {
4777
5852
  }
4778
5853
  );
4779
5854
  const handle = {
4780
- read: (selector) => import_effect53.Effect.map(rt.getState, selector),
5855
+ read: (selector) => import_effect56.Effect.map(rt.getState, selector),
4781
5856
  changes: rt.changes,
4782
5857
  dispatch: rt.dispatch,
4783
5858
  actions$: rt.actions$,
@@ -4787,7 +5862,7 @@ function make6(shape, runtime, options) {
4787
5862
  const extend = tag?.[EXTEND_HANDLE];
4788
5863
  return typeof extend === "function" ? extend(rt, handle) ?? handle : handle;
4789
5864
  };
4790
- const emitModuleDescriptorOnce = (module2, rt) => import_effect53.Effect.gen(function* () {
5865
+ const emitModuleDescriptorOnce = (module2, rt) => import_effect56.Effect.gen(function* () {
4791
5866
  if (cachedDiagnosticsLevel === "off") return;
4792
5867
  const key = `module_descriptor:${String(rt.instanceId ?? "unknown")}`;
4793
5868
  const shouldEmit = yield* onceInRunSession2(key);
@@ -4827,7 +5902,7 @@ function make6(shape, runtime, options) {
4827
5902
  data
4828
5903
  });
4829
5904
  });
4830
- const resolveModuleRuntime = (tag) => import_effect53.Effect.gen(function* () {
5905
+ const resolveModuleRuntime = (tag) => import_effect56.Effect.gen(function* () {
4831
5906
  const requestedModuleId = typeof tag?.id === "string" ? tag.id : void 0;
4832
5907
  const fromModuleId = typeof options?.moduleId === "string" ? options.moduleId : runtime.moduleId;
4833
5908
  if (requestedModuleId && requestedModuleId === runtime.moduleId) {
@@ -4838,8 +5913,8 @@ function make6(shape, runtime, options) {
4838
5913
  return fromImports;
4839
5914
  }
4840
5915
  if (typeof options?.moduleId !== "string") {
4841
- const fromEnv = yield* import_effect53.Effect.serviceOption(tag);
4842
- if (import_effect53.Option.isSome(fromEnv)) {
5916
+ const fromEnv = yield* import_effect56.Effect.serviceOption(tag);
5917
+ if (import_effect56.Option.isSome(fromEnv)) {
4843
5918
  return fromEnv.value;
4844
5919
  }
4845
5920
  }
@@ -4874,23 +5949,23 @@ function make6(shape, runtime, options) {
4874
5949
  };
4875
5950
  err.fix = fix;
4876
5951
  err.name = "MissingModuleRuntimeError";
4877
- return yield* import_effect53.Effect.die(err);
5952
+ return yield* import_effect56.Effect.die(err);
4878
5953
  });
4879
5954
  const stateApi = {
4880
5955
  read: runtime.getState,
4881
- update: (f) => import_effect53.Effect.gen(function* () {
4882
- const inTxn = yield* import_effect53.FiberRef.get(inSyncTransactionFiber);
5956
+ update: (f) => import_effect56.Effect.gen(function* () {
5957
+ const inTxn = yield* import_effect56.FiberRef.get(inSyncTransactionFiber);
4883
5958
  if (inTxn) {
4884
5959
  const prev = yield* runtime.getState;
4885
5960
  return yield* runtime.setState(f(prev));
4886
5961
  }
4887
- const body = () => import_effect53.Effect.flatMap(runtime.getState, (prev) => runtime.setState(f(prev)));
5962
+ const body = () => import_effect56.Effect.flatMap(runtime.getState, (prev) => runtime.setState(f(prev)));
4888
5963
  return yield* runtimeInternals ? runtimeInternals.txn.runWithStateTransaction({ kind: "state", name: "update" }, body) : body();
4889
5964
  }),
4890
- mutate: (f) => import_effect53.Effect.gen(function* () {
5965
+ mutate: (f) => import_effect56.Effect.gen(function* () {
4891
5966
  const recordPatch2 = runtimeInternals?.txn.recordStatePatch;
4892
5967
  const updateDraft2 = runtimeInternals?.txn.updateDraft;
4893
- const inTxn = yield* import_effect53.FiberRef.get(inSyncTransactionFiber);
5968
+ const inTxn = yield* import_effect56.FiberRef.get(inSyncTransactionFiber);
4894
5969
  if (inTxn) {
4895
5970
  const prev = yield* runtime.getState;
4896
5971
  const { nextState, patchPaths } = mutateWithPatchPaths(prev, (draft) => {
@@ -4902,7 +5977,7 @@ function make6(shape, runtime, options) {
4902
5977
  updateDraft2?.(nextState);
4903
5978
  return;
4904
5979
  }
4905
- const body = () => import_effect53.Effect.gen(function* () {
5980
+ const body = () => import_effect56.Effect.gen(function* () {
4906
5981
  const prev = yield* runtime.getState;
4907
5982
  const { nextState, patchPaths } = mutateWithPatchPaths(prev, (draft) => {
4908
5983
  f(draft);
@@ -4951,13 +6026,13 @@ function make6(shape, runtime, options) {
4951
6026
  const matchApi = (value) => makeMatch(value);
4952
6027
  const matchTagApi = (value) => makeMatchTag(value);
4953
6028
  const reducer = (tag, fn) => {
4954
- return import_effect53.Effect.sync(() => {
6029
+ return import_effect56.Effect.sync(() => {
4955
6030
  runtimeInternals.txn.registerReducer(String(tag), fn);
4956
6031
  });
4957
6032
  };
4958
- const effect = (token, handler) => import_effect53.Effect.gen(function* () {
6033
+ const effect = (token, handler) => import_effect56.Effect.gen(function* () {
4959
6034
  if (!isActionToken(token)) {
4960
- return yield* import_effect53.Effect.dieMessage("[BoundApi.effect] token must be an ActionToken");
6035
+ return yield* import_effect56.Effect.dieMessage("[BoundApi.effect] token must be an ActionToken");
4961
6036
  }
4962
6037
  const phase = getCurrentPhase();
4963
6038
  const logicUnit = options?.logicUnit;
@@ -4997,56 +6072,56 @@ function make6(shape, runtime, options) {
4997
6072
  return emitSetupOnlyViolation("$.lifecycle.onInitRequired");
4998
6073
  }
4999
6074
  runtimeInternals.lifecycle.registerInitRequired(eff);
5000
- return import_effect53.Effect.void;
6075
+ return import_effect56.Effect.void;
5001
6076
  },
5002
6077
  onStart: (eff) => {
5003
6078
  if (getCurrentPhase() === "run") {
5004
6079
  return emitSetupOnlyViolation("$.lifecycle.onStart");
5005
6080
  }
5006
6081
  runtimeInternals.lifecycle.registerStart(eff);
5007
- return import_effect53.Effect.void;
6082
+ return import_effect56.Effect.void;
5008
6083
  },
5009
6084
  onInit: (eff) => {
5010
6085
  if (getCurrentPhase() === "run") {
5011
6086
  return emitSetupOnlyViolation("$.lifecycle.onInit");
5012
6087
  }
5013
6088
  runtimeInternals.lifecycle.registerInitRequired(eff);
5014
- return import_effect53.Effect.void;
6089
+ return import_effect56.Effect.void;
5015
6090
  },
5016
6091
  onDestroy: (eff) => {
5017
6092
  if (getCurrentPhase() === "run") {
5018
6093
  return emitSetupOnlyViolation("$.lifecycle.onDestroy");
5019
6094
  }
5020
6095
  runtimeInternals.lifecycle.registerDestroy(eff);
5021
- return import_effect53.Effect.void;
6096
+ return import_effect56.Effect.void;
5022
6097
  },
5023
6098
  onError: (handler) => {
5024
6099
  if (getCurrentPhase() === "run") {
5025
6100
  return emitSetupOnlyViolation("$.lifecycle.onError");
5026
6101
  }
5027
6102
  runtimeInternals.lifecycle.registerOnError(handler);
5028
- return import_effect53.Effect.void;
6103
+ return import_effect56.Effect.void;
5029
6104
  },
5030
6105
  onSuspend: (eff) => {
5031
6106
  if (getCurrentPhase() === "run") {
5032
6107
  return emitSetupOnlyViolation("$.lifecycle.onSuspend");
5033
6108
  }
5034
- runtimeInternals.lifecycle.registerPlatformSuspend(import_effect53.Effect.asVoid(eff));
5035
- return import_effect53.Effect.void;
6109
+ runtimeInternals.lifecycle.registerPlatformSuspend(import_effect56.Effect.asVoid(eff));
6110
+ return import_effect56.Effect.void;
5036
6111
  },
5037
6112
  onResume: (eff) => {
5038
6113
  if (getCurrentPhase() === "run") {
5039
6114
  return emitSetupOnlyViolation("$.lifecycle.onResume");
5040
6115
  }
5041
- runtimeInternals.lifecycle.registerPlatformResume(import_effect53.Effect.asVoid(eff));
5042
- return import_effect53.Effect.void;
6116
+ runtimeInternals.lifecycle.registerPlatformResume(import_effect56.Effect.asVoid(eff));
6117
+ return import_effect56.Effect.void;
5043
6118
  },
5044
6119
  onReset: (eff) => {
5045
6120
  if (getCurrentPhase() === "run") {
5046
6121
  return emitSetupOnlyViolation("$.lifecycle.onReset");
5047
6122
  }
5048
- runtimeInternals.lifecycle.registerPlatformReset(import_effect53.Effect.asVoid(eff));
5049
- return import_effect53.Effect.void;
6123
+ runtimeInternals.lifecycle.registerPlatformReset(import_effect56.Effect.asVoid(eff));
6124
+ return import_effect56.Effect.void;
5050
6125
  }
5051
6126
  },
5052
6127
  traits: {
@@ -5080,14 +6155,14 @@ function make6(shape, runtime, options) {
5080
6155
  });
5081
6156
  },
5082
6157
  source: {
5083
- refresh: (fieldPath, options2) => import_effect53.Effect.gen(function* () {
6158
+ refresh: (fieldPath, options2) => import_effect56.Effect.gen(function* () {
5084
6159
  const handler = runtimeInternals.traits.getSourceRefreshHandler(fieldPath);
5085
6160
  if (!handler) {
5086
- return yield* import_effect53.Effect.void;
6161
+ return yield* import_effect56.Effect.void;
5087
6162
  }
5088
6163
  const force = options2?.force === true;
5089
- const runHandler = (state) => force ? import_effect53.Effect.locally(forceSourceRefresh, true)(handler(state)) : handler(state);
5090
- const inTxn = yield* import_effect53.FiberRef.get(inSyncTransactionFiber);
6164
+ const runHandler = (state) => force ? import_effect56.Effect.locally(forceSourceRefresh, true)(handler(state)) : handler(state);
6165
+ const inTxn = yield* import_effect56.FiberRef.get(inSyncTransactionFiber);
5091
6166
  if (inTxn) {
5092
6167
  const state = yield* runtime.getState;
5093
6168
  return yield* runHandler(state);
@@ -5097,7 +6172,7 @@ function make6(shape, runtime, options) {
5097
6172
  kind: "source-refresh",
5098
6173
  name: fieldPath
5099
6174
  },
5100
- () => import_effect53.Effect.gen(function* () {
6175
+ () => import_effect56.Effect.gen(function* () {
5101
6176
  const state = yield* runtime.getState;
5102
6177
  return yield* runHandler(state);
5103
6178
  })
@@ -5114,18 +6189,18 @@ function make6(shape, runtime, options) {
5114
6189
  if (isModuleLike(arg)) {
5115
6190
  const domain = arg;
5116
6191
  const tag = domain.tag;
5117
- const resolveAndBuild = resolveModuleRuntime(tag).pipe(import_effect53.Effect.map((rt) => buildModuleHandle(tag, rt)));
6192
+ const resolveAndBuild = resolveModuleRuntime(tag).pipe(import_effect56.Effect.map((rt) => buildModuleHandle(tag, rt)));
5118
6193
  const resolveWithDescriptor = resolveModuleRuntime(tag).pipe(
5119
- import_effect53.Effect.tap((rt) => emitModuleDescriptorOnce(domain, rt)),
5120
- import_effect53.Effect.map((rt) => buildModuleHandle(tag, rt))
6194
+ import_effect56.Effect.tap((rt) => emitModuleDescriptorOnce(domain, rt)),
6195
+ import_effect56.Effect.map((rt) => buildModuleHandle(tag, rt))
5121
6196
  );
5122
- const detectAndSelect = import_effect53.FiberRef.get(currentDiagnosticsLevel).pipe(
5123
- import_effect53.Effect.tap((level) => {
6197
+ const detectAndSelect = import_effect56.FiberRef.get(currentDiagnosticsLevel).pipe(
6198
+ import_effect56.Effect.tap((level) => {
5124
6199
  cachedDiagnosticsLevel = level;
5125
6200
  }),
5126
- import_effect53.Effect.flatMap((level) => level === "off" ? resolveAndBuild : resolveWithDescriptor)
6201
+ import_effect56.Effect.flatMap((level) => level === "off" ? resolveAndBuild : resolveWithDescriptor)
5127
6202
  );
5128
- return import_effect53.Effect.suspend(() => {
6203
+ return import_effect56.Effect.suspend(() => {
5129
6204
  if (cachedDiagnosticsLevel === "off") {
5130
6205
  return resolveAndBuild;
5131
6206
  }
@@ -5135,16 +6210,16 @@ function make6(shape, runtime, options) {
5135
6210
  return detectAndSelect;
5136
6211
  });
5137
6212
  }
5138
- if (import_effect53.Context.isTag(arg)) {
6213
+ if (import_effect56.Context.isTag(arg)) {
5139
6214
  const candidate = arg;
5140
6215
  if (candidate._kind === "ModuleTag") {
5141
6216
  return resolveModuleRuntime(arg).pipe(
5142
- import_effect53.Effect.map((rt) => buildModuleHandle(arg, rt))
6217
+ import_effect56.Effect.map((rt) => buildModuleHandle(arg, rt))
5143
6218
  );
5144
6219
  }
5145
6220
  return arg;
5146
6221
  }
5147
- return import_effect53.Effect.die("BoundApi.use: unsupported argument");
6222
+ return import_effect56.Effect.die("BoundApi.use: unsupported argument");
5148
6223
  }
5149
6224
  }),
5150
6225
  onAction: new Proxy(() => {
@@ -5156,33 +6231,33 @@ function make6(shape, runtime, options) {
5156
6231
  const tag = arg.tag;
5157
6232
  return createIntentBuilder(
5158
6233
  runtime.actions$.pipe(
5159
- import_effect53.Stream.filter((a) => a._tag === tag || a.type === tag),
5160
- import_effect53.Stream.map((a) => a.payload)
6234
+ import_effect56.Stream.filter((a) => a._tag === tag || a.type === tag),
6235
+ import_effect56.Stream.map((a) => a.payload)
5161
6236
  ),
5162
6237
  tag
5163
6238
  );
5164
6239
  }
5165
6240
  if (typeof arg === "function") {
5166
- return createIntentBuilder(runtime.actions$.pipe(import_effect53.Stream.filter(arg)));
6241
+ return createIntentBuilder(runtime.actions$.pipe(import_effect56.Stream.filter(arg)));
5167
6242
  }
5168
6243
  if (typeof arg === "string") {
5169
6244
  return createIntentBuilder(
5170
- runtime.actions$.pipe(import_effect53.Stream.filter((a) => a._tag === arg || a.type === arg)),
6245
+ runtime.actions$.pipe(import_effect56.Stream.filter((a) => a._tag === arg || a.type === arg)),
5171
6246
  arg
5172
6247
  );
5173
6248
  }
5174
6249
  if (typeof arg === "object" && arg !== null) {
5175
6250
  if ("_tag" in arg) {
5176
6251
  return createIntentBuilder(
5177
- runtime.actions$.pipe(import_effect53.Stream.filter((a) => a._tag === arg._tag)),
6252
+ runtime.actions$.pipe(import_effect56.Stream.filter((a) => a._tag === arg._tag)),
5178
6253
  String(arg._tag)
5179
6254
  );
5180
6255
  }
5181
- if (import_effect53.Schema.isSchema(arg)) {
6256
+ if (import_effect56.Schema.isSchema(arg)) {
5182
6257
  return createIntentBuilder(
5183
6258
  runtime.actions$.pipe(
5184
- import_effect53.Stream.filter((a) => {
5185
- const result = import_effect53.Schema.decodeUnknownSync(arg)(a);
6259
+ import_effect56.Stream.filter((a) => {
6260
+ const result = import_effect56.Schema.decodeUnknownSync(arg)(a);
5186
6261
  return !!result;
5187
6262
  })
5188
6263
  )
@@ -5195,7 +6270,7 @@ function make6(shape, runtime, options) {
5195
6270
  guardRunOnly("use_in_setup", "$.onAction");
5196
6271
  if (typeof prop === "string") {
5197
6272
  return createIntentBuilder(
5198
- runtime.actions$.pipe(import_effect53.Stream.filter((a) => a._tag === prop || a.type === prop)),
6273
+ runtime.actions$.pipe(import_effect56.Stream.filter((a) => a._tag === prop || a.type === prop)),
5199
6274
  prop
5200
6275
  );
5201
6276
  }
@@ -5216,7 +6291,7 @@ function make6(shape, runtime, options) {
5216
6291
  }
5217
6292
 
5218
6293
  // src/internal/runtime/core/runner/ProgramRunner.closeScope.ts
5219
- var import_effect54 = require("effect");
6294
+ var import_effect57 = require("effect");
5220
6295
 
5221
6296
  // src/internal/runtime/core/runner/ProgramRunner.errors.ts
5222
6297
  var summarizeCause = (cause) => {
@@ -5323,17 +6398,22 @@ var DisposeTimeoutError = class extends ProgramRunnerErrorBase {
5323
6398
 
5324
6399
  // src/internal/runtime/core/runner/ProgramRunner.closeScope.ts
5325
6400
  var closeProgramScope = (params) => {
5326
- return import_effect54.Effect.gen(function* () {
6401
+ return import_effect57.Effect.gen(function* () {
5327
6402
  const start = Date.now();
5328
- const fiber = yield* import_effect54.Effect.forkDaemon(import_effect54.Scope.close(params.scope, import_effect54.Exit.void));
6403
+ const hostSchedulerOpt = yield* import_effect57.Effect.serviceOption(HostSchedulerTag);
6404
+ const hostScheduler = import_effect57.Option.isSome(hostSchedulerOpt) ? hostSchedulerOpt.value : getGlobalHostScheduler();
6405
+ const yieldMicrotask = import_effect57.Effect.async((resume) => {
6406
+ hostScheduler.scheduleMicrotask(() => resume(import_effect57.Effect.void));
6407
+ });
6408
+ const fiber = yield* import_effect57.Effect.forkDaemon(import_effect57.Scope.close(params.scope, import_effect57.Exit.void));
5329
6409
  while (true) {
5330
- const exitOpt = yield* import_effect54.Fiber.poll(fiber);
5331
- if (import_effect54.Option.isSome(exitOpt)) {
6410
+ const exitOpt = yield* import_effect57.Fiber.poll(fiber);
6411
+ if (import_effect57.Option.isSome(exitOpt)) {
5332
6412
  const exit = exitOpt.value;
5333
6413
  if (exit._tag === "Success") {
5334
6414
  return;
5335
6415
  }
5336
- return yield* import_effect54.Effect.die(new DisposeError(params.identity, exit.cause));
6416
+ return yield* import_effect57.Effect.die(new DisposeError(params.identity, exit.cause));
5337
6417
  }
5338
6418
  const elapsedMs = Date.now() - start;
5339
6419
  if (elapsedMs >= params.timeoutMs) {
@@ -5342,12 +6422,12 @@ var closeProgramScope = (params) => {
5342
6422
  elapsedMs
5343
6423
  });
5344
6424
  if (typeof params.onError === "function") {
5345
- yield* params.onError(import_effect54.Cause.die(error)).pipe(import_effect54.Effect.catchAllCause(() => import_effect54.Effect.void));
6425
+ yield* params.onError(import_effect57.Cause.die(error)).pipe(import_effect57.Effect.catchAllCause(() => import_effect57.Effect.void));
5346
6426
  }
5347
- yield* import_effect54.Fiber.interruptFork(fiber);
5348
- return yield* import_effect54.Effect.die(error);
6427
+ yield* import_effect57.Fiber.interruptFork(fiber);
6428
+ return yield* import_effect57.Effect.die(error);
5349
6429
  }
5350
- yield* import_effect54.Effect.promise(() => new Promise((r) => queueMicrotask(r)));
6430
+ yield* yieldMicrotask;
5351
6431
  }
5352
6432
  });
5353
6433
  };
@@ -5374,7 +6454,7 @@ var reportErrorIfEnabled = (enabled, error) => {
5374
6454
  };
5375
6455
 
5376
6456
  // src/internal/runtime/core/runner/ProgramRunner.signals.ts
5377
- var import_effect55 = require("effect");
6457
+ var import_effect58 = require("effect");
5378
6458
  var getProcess2 = () => globalThis.process;
5379
6459
  var isNodeProcess = (value) => typeof value === "object" && value !== null && typeof value.on === "function";
5380
6460
  var removeListener = (proc, event, handler) => {
@@ -5388,24 +6468,24 @@ var removeListener = (proc, event, handler) => {
5388
6468
  };
5389
6469
  var installGracefulShutdownHandlers = (params) => {
5390
6470
  if (!params.enabled) {
5391
- return import_effect55.Effect.void;
6471
+ return import_effect58.Effect.void;
5392
6472
  }
5393
6473
  const proc = getProcess2();
5394
6474
  if (!isNodeProcess(proc)) {
5395
- return import_effect55.Effect.void;
6475
+ return import_effect58.Effect.void;
5396
6476
  }
5397
6477
  const handler = () => {
5398
- void import_effect55.Effect.runPromise(import_effect55.Scope.close(params.scope, import_effect55.Exit.void));
6478
+ void import_effect58.Effect.runPromise(import_effect58.Scope.close(params.scope, import_effect58.Exit.void));
5399
6479
  };
5400
- return import_effect55.Effect.gen(function* () {
5401
- yield* import_effect55.Scope.addFinalizer(
6480
+ return import_effect58.Effect.gen(function* () {
6481
+ yield* import_effect58.Scope.addFinalizer(
5402
6482
  params.scope,
5403
- import_effect55.Effect.sync(() => {
6483
+ import_effect58.Effect.sync(() => {
5404
6484
  removeListener(proc, "SIGINT", handler);
5405
6485
  removeListener(proc, "SIGTERM", handler);
5406
6486
  })
5407
6487
  );
5408
- yield* import_effect55.Effect.sync(() => {
6488
+ yield* import_effect58.Effect.sync(() => {
5409
6489
  proc.on("SIGINT", handler);
5410
6490
  proc.on("SIGTERM", handler);
5411
6491
  });
@@ -5413,15 +6493,15 @@ var installGracefulShutdownHandlers = (params) => {
5413
6493
  };
5414
6494
 
5415
6495
  // src/internal/runtime/core/runner/ProgramRunner.kernel.ts
5416
- var import_effect56 = require("effect");
5417
- var makeProgramRunnerKernel = (makeRuntime, rootImpl, options) => import_effect56.Effect.gen(function* () {
6496
+ var import_effect59 = require("effect");
6497
+ var makeProgramRunnerKernel = (makeRuntime, rootImpl, options) => import_effect59.Effect.gen(function* () {
5418
6498
  const identity = {
5419
6499
  moduleId: String(rootImpl.module.id),
5420
6500
  instanceId: "unknown"
5421
6501
  };
5422
- const scope = yield* import_effect56.Scope.make();
6502
+ const scope = yield* import_effect59.Scope.make();
5423
6503
  const runtime = makeRuntime(rootImpl, options);
5424
- yield* import_effect56.Scope.addFinalizer(scope, import_effect56.Effect.promise(() => runtime.dispose()).pipe(import_effect56.Effect.asVoid));
6504
+ yield* import_effect59.Scope.addFinalizer(scope, import_effect59.Effect.promise(() => runtime.dispose()).pipe(import_effect59.Effect.asVoid));
5425
6505
  const setInstanceId = (value) => {
5426
6506
  identity.instanceId = typeof value === "string" && value.length > 0 ? value : String(value ?? "unknown");
5427
6507
  };
@@ -5468,23 +6548,23 @@ var resolveProgramRunnerOptions = (options) => {
5468
6548
  };
5469
6549
 
5470
6550
  // src/internal/runtime/core/runner/ProgramRunner.ts
5471
- var openProgram = (makeRuntime, rootImpl, options) => import_effect57.Effect.gen(function* () {
5472
- const inTxn = yield* import_effect57.FiberRef.get(inSyncTransactionFiber);
6551
+ var openProgram = (makeRuntime, rootImpl, options) => import_effect60.Effect.gen(function* () {
6552
+ const inTxn = yield* import_effect60.FiberRef.get(inSyncTransactionFiber);
5473
6553
  if (inTxn) {
5474
- return yield* import_effect57.Effect.dieMessage(
6554
+ return yield* import_effect60.Effect.dieMessage(
5475
6555
  "[Logix] Runtime.openProgram/runProgram is not allowed inside a synchronous StateTransaction body"
5476
6556
  );
5477
6557
  }
5478
6558
  const runnerOptions = resolveProgramRunnerOptions(options);
5479
6559
  const kernel = yield* makeProgramRunnerKernel(makeRuntime, rootImpl, options);
5480
- yield* import_effect57.Effect.addFinalizer(
6560
+ yield* import_effect60.Effect.addFinalizer(
5481
6561
  () => kernel.close({
5482
6562
  timeoutMs: runnerOptions.closeScopeTimeout,
5483
6563
  onError: options?.onError
5484
6564
  })
5485
6565
  );
5486
6566
  yield* kernel.installSignals(runnerOptions.handleSignals);
5487
- const moduleRuntime = yield* import_effect57.Effect.tryPromise({
6567
+ const moduleRuntime = yield* import_effect60.Effect.tryPromise({
5488
6568
  try: () => kernel.runtime.runPromise(rootImpl.module),
5489
6569
  catch: (error) => new BootError(kernel.identity, error)
5490
6570
  });
@@ -5500,16 +6580,16 @@ var runProgram = async (makeRuntime, rootImpl, main, options) => {
5500
6580
  moduleId: String(rootImpl.module.id),
5501
6581
  instanceId: "unknown"
5502
6582
  };
5503
- const scope = import_effect57.Effect.runSync(import_effect57.Scope.make());
6583
+ const scope = import_effect60.Effect.runSync(import_effect60.Scope.make());
5504
6584
  const runtime = makeRuntime(rootImpl, options);
5505
6585
  let ctx;
5506
6586
  let mainError;
5507
6587
  let closeError;
5508
6588
  let result;
5509
6589
  try {
5510
- import_effect57.Effect.runSync(import_effect57.Scope.addFinalizer(scope, import_effect57.Effect.promise(() => runtime.dispose()).pipe(import_effect57.Effect.asVoid)));
6590
+ import_effect60.Effect.runSync(import_effect60.Scope.addFinalizer(scope, import_effect60.Effect.promise(() => runtime.dispose()).pipe(import_effect60.Effect.asVoid)));
5511
6591
  if (runnerOptions.handleSignals) {
5512
- import_effect57.Effect.runSync(
6592
+ import_effect60.Effect.runSync(
5513
6593
  installGracefulShutdownHandlers({
5514
6594
  scope,
5515
6595
  enabled: true
@@ -5549,7 +6629,7 @@ var runProgram = async (makeRuntime, rootImpl, main, options) => {
5549
6629
  }
5550
6630
  }
5551
6631
  } finally {
5552
- const exit = await import_effect57.Effect.runPromiseExit(
6632
+ const exit = await import_effect60.Effect.runPromiseExit(
5553
6633
  closeProgramScope({
5554
6634
  scope,
5555
6635
  timeoutMs: runnerOptions.closeScopeTimeout,
@@ -5558,16 +6638,16 @@ var runProgram = async (makeRuntime, rootImpl, main, options) => {
5558
6638
  })
5559
6639
  );
5560
6640
  if (exit._tag === "Failure") {
5561
- const failureOpt = import_effect57.Cause.failureOption(exit.cause);
5562
- if (import_effect57.Option.isSome(failureOpt)) {
6641
+ const failureOpt = import_effect60.Cause.failureOption(exit.cause);
6642
+ if (import_effect60.Option.isSome(failureOpt)) {
5563
6643
  const error = failureOpt.value;
5564
6644
  if (mainError !== void 0 && error && typeof error === "object") {
5565
6645
  error.mainError = mainError;
5566
6646
  }
5567
6647
  closeError = error;
5568
6648
  } else {
5569
- const defectOpt = import_effect57.Cause.dieOption(exit.cause);
5570
- if (import_effect57.Option.isSome(defectOpt) && defectOpt.value instanceof Error) {
6649
+ const defectOpt = import_effect60.Cause.dieOption(exit.cause);
6650
+ if (import_effect60.Option.isSome(defectOpt) && defectOpt.value instanceof Error) {
5571
6651
  const error = defectOpt.value;
5572
6652
  if (mainError !== void 0 && error && typeof error === "object") {
5573
6653
  error.mainError = mainError;
@@ -5600,9 +6680,9 @@ var make7 = (root, options) => {
5600
6680
  const rootImpl = resolveRootImpl(root);
5601
6681
  warnInvalidConcurrencyPolicyDevOnly(options?.concurrencyPolicy, "Runtime.make options.concurrencyPolicy");
5602
6682
  warnInvalidStateTransactionRuntimeConfigDevOnly(options?.stateTransaction, "Runtime.make options.stateTransaction");
5603
- const debugLayer = options?.debug === true ? layer2() : options?.debug ? layer2(options.debug) : import_effect58.Layer.empty;
5604
- const userLayer = options?.layer ?? import_effect58.Layer.empty;
5605
- const userWithDebug = options?.debug ? import_effect58.Layer.mergeAll(userLayer, debugLayer) : userLayer;
6683
+ const debugLayer = options?.debug === true ? layer2() : options?.debug ? layer2(options.debug) : import_effect61.Layer.empty;
6684
+ const userLayer = options?.layer ?? import_effect61.Layer.empty;
6685
+ const userWithDebug = options?.debug ? import_effect61.Layer.mergeAll(userLayer, debugLayer) : userLayer;
5606
6686
  let middlewareStack = options?.middleware ?? [];
5607
6687
  const devtoolsOptions = options?.devtools === true ? {} : options?.devtools;
5608
6688
  if (options?.devtools) {
@@ -5612,16 +6692,16 @@ var make7 = (root, options) => {
5612
6692
  observer: observerConfig
5613
6693
  });
5614
6694
  }
5615
- const effectOpLayer = middlewareStack.length > 0 ? import_effect58.Layer.succeed(EffectOpMiddlewareTag, {
6695
+ const effectOpLayer = middlewareStack.length > 0 ? import_effect61.Layer.succeed(EffectOpMiddlewareTag, {
5616
6696
  stack: middlewareStack
5617
- }) : import_effect58.Layer.empty;
5618
- const baseLayer = options?.label != null ? import_effect58.Layer.mergeAll(runtimeLabel(options.label), userWithDebug) : userWithDebug;
6697
+ }) : import_effect61.Layer.empty;
6698
+ const baseLayer = options?.label != null ? import_effect61.Layer.mergeAll(runtimeLabel(options.label), userWithDebug) : userWithDebug;
5619
6699
  const baseWithDevtools = options?.devtools ? devtoolsHubLayer(baseLayer, {
5620
6700
  bufferSize: devtoolsOptions?.bufferSize,
5621
6701
  diagnosticsLevel: devtoolsOptions?.diagnosticsLevel,
5622
6702
  traitConvergeDiagnosticsSampling: devtoolsOptions?.traitConvergeDiagnosticsSampling
5623
6703
  }) : baseLayer;
5624
- const appLayer = import_effect58.Layer.mergeAll(
6704
+ const appLayer = import_effect61.Layer.mergeAll(
5625
6705
  runSessionLayer(),
5626
6706
  layer3(),
5627
6707
  baseWithDevtools,
@@ -5643,6 +6723,7 @@ var make7 = (root, options) => {
5643
6723
  modules: [provide(rootImpl.module, rootImpl.layer)],
5644
6724
  processes: rootImpl.processes ?? [],
5645
6725
  onError: options?.onError,
6726
+ hostScheduler: options?.hostScheduler,
5646
6727
  stateTransaction: options?.stateTransaction,
5647
6728
  concurrencyPolicy: options?.concurrencyPolicy,
5648
6729
  readQueryStrictGate
@@ -5650,6 +6731,14 @@ var make7 = (root, options) => {
5650
6731
  const app = makeApp(appConfig);
5651
6732
  return app.makeRuntime();
5652
6733
  };
6734
+ var batch = (fn) => {
6735
+ enterRuntimeBatch();
6736
+ try {
6737
+ return fn();
6738
+ } finally {
6739
+ exitRuntimeBatch();
6740
+ }
6741
+ };
5653
6742
  var openProgram2 = (root, options) => openProgram(
5654
6743
  (rootImpl, runtimeOptions) => make7(rootImpl, runtimeOptions),
5655
6744
  resolveRootImpl(root),
@@ -5663,18 +6752,18 @@ var runProgram2 = async (root, main, options) => runProgram(
5663
6752
  );
5664
6753
  var stateTransactionOverridesLayer = (overrides) => {
5665
6754
  warnInvalidStateTransactionOverridesDevOnly(overrides, "Runtime.stateTransactionOverridesLayer");
5666
- return import_effect58.Layer.succeed(StateTransactionOverridesTag, overrides);
6755
+ return import_effect61.Layer.succeed(StateTransactionOverridesTag, overrides);
5667
6756
  };
5668
6757
  var concurrencyPolicyOverridesLayer = (overrides) => {
5669
6758
  warnInvalidConcurrencyPolicyDevOnly(overrides, "Runtime.concurrencyPolicyOverridesLayer");
5670
- return import_effect58.Layer.succeed(ConcurrencyPolicyOverridesTag, overrides);
6759
+ return import_effect61.Layer.succeed(ConcurrencyPolicyOverridesTag, overrides);
5671
6760
  };
5672
6761
  var setTraitConvergeOverride = (runtime, moduleId, overrides) => {
5673
6762
  warnInvalidStateTransactionTraitConvergeOverridesDevOnly(overrides, `Runtime.setTraitConvergeOverride(${moduleId})`);
5674
6763
  runtime.runSync(
5675
- import_effect58.Effect.gen(function* () {
5676
- const runtimeConfigOpt = yield* import_effect58.Effect.serviceOption(StateTransactionConfigTag);
5677
- if (import_effect58.Option.isNone(runtimeConfigOpt)) {
6764
+ import_effect61.Effect.gen(function* () {
6765
+ const runtimeConfigOpt = yield* import_effect61.Effect.serviceOption(StateTransactionConfigTag);
6766
+ if (import_effect61.Option.isNone(runtimeConfigOpt)) {
5678
6767
  return;
5679
6768
  }
5680
6769
  const runtimeConfig = runtimeConfigOpt.value;
@@ -5693,9 +6782,9 @@ var setTraitConvergeOverride = (runtime, moduleId, overrides) => {
5693
6782
  var setConcurrencyPolicyOverride = (runtime, moduleId, patch) => {
5694
6783
  warnInvalidConcurrencyPolicyPatchDevOnly(patch, `Runtime.setConcurrencyPolicyOverride(${moduleId})`);
5695
6784
  runtime.runSync(
5696
- import_effect58.Effect.gen(function* () {
5697
- const runtimeConfigOpt = yield* import_effect58.Effect.serviceOption(ConcurrencyPolicyTag);
5698
- if (import_effect58.Option.isNone(runtimeConfigOpt)) {
6785
+ import_effect61.Effect.gen(function* () {
6786
+ const runtimeConfigOpt = yield* import_effect61.Effect.serviceOption(ConcurrencyPolicyTag);
6787
+ if (import_effect61.Option.isNone(runtimeConfigOpt)) {
5699
6788
  return;
5700
6789
  }
5701
6790
  const runtimeConfig = runtimeConfigOpt.value;
@@ -5711,7 +6800,7 @@ var setConcurrencyPolicyOverride = (runtime, moduleId, patch) => {
5711
6800
  })
5712
6801
  );
5713
6802
  };
5714
- var applyTransactionSnapshot = (moduleId, instanceId, txnId, mode) => import_effect58.Effect.gen(function* () {
6803
+ var applyTransactionSnapshot = (moduleId, instanceId, txnId, mode) => import_effect61.Effect.gen(function* () {
5715
6804
  const runtime = getRuntimeByModuleAndInstance(moduleId, instanceId);
5716
6805
  if (!runtime) {
5717
6806
  return;
@@ -5729,6 +6818,7 @@ var applyTransactionSnapshot = (moduleId, instanceId, txnId, mode) => import_eff
5729
6818
  DisposeTimeoutError,
5730
6819
  MainError,
5731
6820
  applyTransactionSnapshot,
6821
+ batch,
5732
6822
  concurrencyPolicyOverridesLayer,
5733
6823
  make,
5734
6824
  openProgram,