@logixjs/core 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (345) hide show
  1. package/dist/Action-BkRHy2vg.d.cts +10 -0
  2. package/dist/Action-mqVvtEHt.d.ts +10 -0
  3. package/dist/Action.cjs +57 -0
  4. package/dist/Action.cjs.map +1 -0
  5. package/dist/Action.d.cts +2 -0
  6. package/dist/Action.d.ts +2 -0
  7. package/dist/Action.js +9 -0
  8. package/dist/Action.js.map +1 -0
  9. package/dist/Actions-AsQ07yTP.d.cts +22 -0
  10. package/dist/Actions-AsQ07yTP.d.ts +22 -0
  11. package/dist/Actions.cjs +19 -0
  12. package/dist/Actions.cjs.map +1 -0
  13. package/dist/Actions.d.cts +2 -0
  14. package/dist/Actions.d.ts +2 -0
  15. package/dist/Actions.js +2 -0
  16. package/dist/Actions.js.map +1 -0
  17. package/dist/Bound-BN1DQ_lM.d.ts +23 -0
  18. package/dist/Bound-BPIfH9SS.d.cts +23 -0
  19. package/dist/Bound.cjs +1532 -0
  20. package/dist/Bound.cjs.map +1 -0
  21. package/dist/Bound.d.cts +7 -0
  22. package/dist/Bound.d.ts +7 -0
  23. package/dist/Bound.js +25 -0
  24. package/dist/Bound.js.map +1 -0
  25. package/dist/Debug-B5q5Bkzx.d.ts +320 -0
  26. package/dist/Debug-Bq8Sqjcr.d.cts +320 -0
  27. package/dist/Debug.cjs +1821 -0
  28. package/dist/Debug.cjs.map +1 -0
  29. package/dist/Debug.d.cts +13 -0
  30. package/dist/Debug.d.ts +13 -0
  31. package/dist/Debug.js +76 -0
  32. package/dist/Debug.js.map +1 -0
  33. package/dist/EffectOp.cjs +169 -0
  34. package/dist/EffectOp.cjs.map +1 -0
  35. package/dist/EffectOp.d.cts +118 -0
  36. package/dist/EffectOp.d.ts +118 -0
  37. package/dist/EffectOp.js +28 -0
  38. package/dist/EffectOp.js.map +1 -0
  39. package/dist/Env-DuJ6JrU2.d.cts +10 -0
  40. package/dist/Env-DuJ6JrU2.d.ts +10 -0
  41. package/dist/Env.cjs +60 -0
  42. package/dist/Env.cjs.map +1 -0
  43. package/dist/Env.d.cts +1 -0
  44. package/dist/Env.d.ts +1 -0
  45. package/dist/Env.js +11 -0
  46. package/dist/Env.js.map +1 -0
  47. package/dist/Flow-1fZT8MpX.d.cts +152 -0
  48. package/dist/Flow-BhpjE22E.d.ts +152 -0
  49. package/dist/Flow.cjs +504 -0
  50. package/dist/Flow.cjs.map +1 -0
  51. package/dist/Flow.d.cts +8 -0
  52. package/dist/Flow.d.ts +8 -0
  53. package/dist/Flow.js +15 -0
  54. package/dist/Flow.js.map +1 -0
  55. package/dist/Handle-D8D1zPb_.d.cts +30 -0
  56. package/dist/Handle-D_cLW1Z3.d.ts +30 -0
  57. package/dist/Handle.cjs +42 -0
  58. package/dist/Handle.cjs.map +1 -0
  59. package/dist/Handle.d.cts +7 -0
  60. package/dist/Handle.d.ts +7 -0
  61. package/dist/Handle.js +10 -0
  62. package/dist/Handle.js.map +1 -0
  63. package/dist/Kernel-8kC-jOda.d.cts +171 -0
  64. package/dist/Kernel-CnGE1Fyk.d.ts +171 -0
  65. package/dist/Kernel.cjs +284 -0
  66. package/dist/Kernel.cjs.map +1 -0
  67. package/dist/Kernel.d.cts +14 -0
  68. package/dist/Kernel.d.ts +14 -0
  69. package/dist/Kernel.js +36 -0
  70. package/dist/Kernel.js.map +1 -0
  71. package/dist/Link-Db7975nU.d.ts +45 -0
  72. package/dist/Link-fX8x1eCK.d.cts +45 -0
  73. package/dist/Link.cjs +542 -0
  74. package/dist/Link.cjs.map +1 -0
  75. package/dist/Link.d.cts +7 -0
  76. package/dist/Link.d.ts +7 -0
  77. package/dist/Link.js +35 -0
  78. package/dist/Link.js.map +1 -0
  79. package/dist/Logic-BRjEMr-W.d.ts +38 -0
  80. package/dist/Logic-DRh4sDZj.d.cts +38 -0
  81. package/dist/Logic.cjs +37 -0
  82. package/dist/Logic.cjs.map +1 -0
  83. package/dist/Logic.d.cts +7 -0
  84. package/dist/Logic.d.ts +7 -0
  85. package/dist/Logic.js +10 -0
  86. package/dist/Logic.js.map +1 -0
  87. package/dist/MatchBuilder-0QOc-nlU.d.ts +14 -0
  88. package/dist/MatchBuilder-CJk5oCkR.d.cts +14 -0
  89. package/dist/MatchBuilder.cjs +85 -0
  90. package/dist/MatchBuilder.cjs.map +1 -0
  91. package/dist/MatchBuilder.d.cts +8 -0
  92. package/dist/MatchBuilder.d.ts +8 -0
  93. package/dist/MatchBuilder.js +11 -0
  94. package/dist/MatchBuilder.js.map +1 -0
  95. package/dist/Middleware.cjs +411 -0
  96. package/dist/Middleware.cjs.map +1 -0
  97. package/dist/Middleware.d.cts +88 -0
  98. package/dist/Middleware.d.ts +88 -0
  99. package/dist/Middleware.js +27 -0
  100. package/dist/Middleware.js.map +1 -0
  101. package/dist/Module-B_0xRDMR.d.cts +203 -0
  102. package/dist/Module-DnzluX2J.d.ts +203 -0
  103. package/dist/Module.cjs +13512 -0
  104. package/dist/Module.cjs.map +1 -0
  105. package/dist/Module.d.cts +8 -0
  106. package/dist/Module.d.ts +8 -0
  107. package/dist/Module.js +53 -0
  108. package/dist/Module.js.map +1 -0
  109. package/dist/ModuleTag-C8FHY_sY.d.ts +93 -0
  110. package/dist/ModuleTag-EGbgBMpZ.d.cts +93 -0
  111. package/dist/ModuleTag.cjs +12231 -0
  112. package/dist/ModuleTag.cjs.map +1 -0
  113. package/dist/ModuleTag.d.cts +8 -0
  114. package/dist/ModuleTag.d.ts +8 -0
  115. package/dist/ModuleTag.js +39 -0
  116. package/dist/ModuleTag.js.map +1 -0
  117. package/dist/Observability-COqEvp2C.d.cts +713 -0
  118. package/dist/Observability-cY4kLn0S.d.ts +713 -0
  119. package/dist/Observability.cjs +5865 -0
  120. package/dist/Observability.cjs.map +1 -0
  121. package/dist/Observability.d.cts +9 -0
  122. package/dist/Observability.d.ts +9 -0
  123. package/dist/Observability.js +41 -0
  124. package/dist/Observability.js.map +1 -0
  125. package/dist/Platform-C49Pv956.d.cts +21 -0
  126. package/dist/Platform-C49Pv956.d.ts +21 -0
  127. package/dist/Platform-CHX8o-U4.d.ts +51 -0
  128. package/dist/Platform-CVlv0xLQ.d.cts +51 -0
  129. package/dist/Platform.cjs +58 -0
  130. package/dist/Platform.cjs.map +1 -0
  131. package/dist/Platform.d.cts +4 -0
  132. package/dist/Platform.d.ts +4 -0
  133. package/dist/Platform.js +15 -0
  134. package/dist/Platform.js.map +1 -0
  135. package/dist/Process-CM9xbMdP.d.ts +92 -0
  136. package/dist/Process-mL8fHDSB.d.cts +92 -0
  137. package/dist/Process.cjs +575 -0
  138. package/dist/Process.cjs.map +1 -0
  139. package/dist/Process.d.cts +8 -0
  140. package/dist/Process.d.ts +8 -0
  141. package/dist/Process.js +42 -0
  142. package/dist/Process.js.map +1 -0
  143. package/dist/ReadQuery-BlMwhe-F.d.ts +30 -0
  144. package/dist/ReadQuery-CL5XlXts.d.cts +30 -0
  145. package/dist/ReadQuery-SinbStGF.d.cts +38 -0
  146. package/dist/ReadQuery-SinbStGF.d.ts +38 -0
  147. package/dist/ReadQuery.cjs +377 -0
  148. package/dist/ReadQuery.cjs.map +1 -0
  149. package/dist/ReadQuery.d.cts +2 -0
  150. package/dist/ReadQuery.d.ts +2 -0
  151. package/dist/ReadQuery.js +14 -0
  152. package/dist/ReadQuery.js.map +1 -0
  153. package/dist/Reflection-CQnKwPXj.d.ts +182 -0
  154. package/dist/Reflection-Kabo1mlU.d.cts +182 -0
  155. package/dist/Reflection.cjs +2954 -0
  156. package/dist/Reflection.cjs.map +1 -0
  157. package/dist/Reflection.d.cts +17 -0
  158. package/dist/Reflection.d.ts +17 -0
  159. package/dist/Reflection.js +40 -0
  160. package/dist/Reflection.js.map +1 -0
  161. package/dist/Resource-Dy1xD_DG.d.cts +75 -0
  162. package/dist/Resource-Dy1xD_DG.d.ts +75 -0
  163. package/dist/Resource.cjs +166 -0
  164. package/dist/Resource.cjs.map +1 -0
  165. package/dist/Resource.d.cts +3 -0
  166. package/dist/Resource.d.ts +3 -0
  167. package/dist/Resource.js +21 -0
  168. package/dist/Resource.js.map +1 -0
  169. package/dist/Root-7ADUMk4t.d.cts +29 -0
  170. package/dist/Root-7ADUMk4t.d.ts +29 -0
  171. package/dist/Root.cjs +125 -0
  172. package/dist/Root.cjs.map +1 -0
  173. package/dist/Root.d.cts +4 -0
  174. package/dist/Root.d.ts +4 -0
  175. package/dist/Root.js +12 -0
  176. package/dist/Root.js.map +1 -0
  177. package/dist/Runtime-B-aL-f29.d.cts +274 -0
  178. package/dist/Runtime-CtyzZG4i.d.ts +274 -0
  179. package/dist/Runtime.cjs +5740 -0
  180. package/dist/Runtime.cjs.map +1 -0
  181. package/dist/Runtime.d.cts +19 -0
  182. package/dist/Runtime.d.ts +19 -0
  183. package/dist/Runtime.js +62 -0
  184. package/dist/Runtime.js.map +1 -0
  185. package/dist/ScopeRegistry-D1owDNSm.d.cts +61 -0
  186. package/dist/ScopeRegistry-D1owDNSm.d.ts +61 -0
  187. package/dist/ScopeRegistry.cjs +152 -0
  188. package/dist/ScopeRegistry.cjs.map +1 -0
  189. package/dist/ScopeRegistry.d.cts +2 -0
  190. package/dist/ScopeRegistry.d.ts +2 -0
  191. package/dist/ScopeRegistry.js +16 -0
  192. package/dist/ScopeRegistry.js.map +1 -0
  193. package/dist/State-CU50R26M.d.cts +19 -0
  194. package/dist/State-CU50R26M.d.ts +19 -0
  195. package/dist/State.cjs +19 -0
  196. package/dist/State.cjs.map +1 -0
  197. package/dist/State.d.cts +2 -0
  198. package/dist/State.d.ts +2 -0
  199. package/dist/State.js +2 -0
  200. package/dist/State.js.map +1 -0
  201. package/dist/StateTrait-BGsZghTz.d.ts +122 -0
  202. package/dist/StateTrait-OWhbj12c.d.cts +122 -0
  203. package/dist/StateTrait.cjs +2737 -0
  204. package/dist/StateTrait.cjs.map +1 -0
  205. package/dist/StateTrait.d.cts +9 -0
  206. package/dist/StateTrait.d.ts +9 -0
  207. package/dist/StateTrait.js +39 -0
  208. package/dist/StateTrait.js.map +1 -0
  209. package/dist/TraitLifecycle-CwV5WPFX.d.cts +88 -0
  210. package/dist/TraitLifecycle-LdIWmKlg.d.ts +88 -0
  211. package/dist/TraitLifecycle.cjs +581 -0
  212. package/dist/TraitLifecycle.cjs.map +1 -0
  213. package/dist/TraitLifecycle.d.cts +8 -0
  214. package/dist/TraitLifecycle.d.ts +8 -0
  215. package/dist/TraitLifecycle.js +24 -0
  216. package/dist/TraitLifecycle.js.map +1 -0
  217. package/dist/action-DiMDD_0v.d.cts +35 -0
  218. package/dist/action-DiMDD_0v.d.ts +35 -0
  219. package/dist/chunk-24VULZ7A.js +76 -0
  220. package/dist/chunk-24VULZ7A.js.map +1 -0
  221. package/dist/chunk-3IYZ5IGG.js +17 -0
  222. package/dist/chunk-3IYZ5IGG.js.map +1 -0
  223. package/dist/chunk-3QMIVH35.js +43 -0
  224. package/dist/chunk-3QMIVH35.js.map +1 -0
  225. package/dist/chunk-3RMKLXHX.js +83 -0
  226. package/dist/chunk-3RMKLXHX.js.map +1 -0
  227. package/dist/chunk-3TMODYZV.js +111 -0
  228. package/dist/chunk-3TMODYZV.js.map +1 -0
  229. package/dist/chunk-3VG5TWQR.js +27 -0
  230. package/dist/chunk-3VG5TWQR.js.map +1 -0
  231. package/dist/chunk-4CQAV7YB.js +37 -0
  232. package/dist/chunk-4CQAV7YB.js.map +1 -0
  233. package/dist/chunk-4SO6JMZL.js +7 -0
  234. package/dist/chunk-4SO6JMZL.js.map +1 -0
  235. package/dist/chunk-66ALHVEX.js +40 -0
  236. package/dist/chunk-66ALHVEX.js.map +1 -0
  237. package/dist/chunk-76WT3HOR.js +397 -0
  238. package/dist/chunk-76WT3HOR.js.map +1 -0
  239. package/dist/chunk-ANLBCBDC.js +285 -0
  240. package/dist/chunk-ANLBCBDC.js.map +1 -0
  241. package/dist/chunk-AUIR5O6W.js +75 -0
  242. package/dist/chunk-AUIR5O6W.js.map +1 -0
  243. package/dist/chunk-BABLDP24.js +445 -0
  244. package/dist/chunk-BABLDP24.js.map +1 -0
  245. package/dist/chunk-BE3HW4FY.js +1099 -0
  246. package/dist/chunk-BE3HW4FY.js.map +1 -0
  247. package/dist/chunk-BZ2SHDN2.js +54 -0
  248. package/dist/chunk-BZ2SHDN2.js.map +1 -0
  249. package/dist/chunk-CW6T36TN.js +393 -0
  250. package/dist/chunk-CW6T36TN.js.map +1 -0
  251. package/dist/chunk-DFNM3WX2.js +632 -0
  252. package/dist/chunk-DFNM3WX2.js.map +1 -0
  253. package/dist/chunk-DMBALCE2.js +1034 -0
  254. package/dist/chunk-DMBALCE2.js.map +1 -0
  255. package/dist/chunk-EGK3KN7B.js +406 -0
  256. package/dist/chunk-EGK3KN7B.js.map +1 -0
  257. package/dist/chunk-EY4NZKDR.js +19 -0
  258. package/dist/chunk-EY4NZKDR.js.map +1 -0
  259. package/dist/chunk-G5ZBFPNU.js +23 -0
  260. package/dist/chunk-G5ZBFPNU.js.map +1 -0
  261. package/dist/chunk-GMPEOUP2.js +31 -0
  262. package/dist/chunk-GMPEOUP2.js.map +1 -0
  263. package/dist/chunk-IHVBV5C2.js +279 -0
  264. package/dist/chunk-IHVBV5C2.js.map +1 -0
  265. package/dist/chunk-IPF7E66P.js +23 -0
  266. package/dist/chunk-IPF7E66P.js.map +1 -0
  267. package/dist/chunk-JCXGZRMU.js +204 -0
  268. package/dist/chunk-JCXGZRMU.js.map +1 -0
  269. package/dist/chunk-JGIWG6SR.js +6359 -0
  270. package/dist/chunk-JGIWG6SR.js.map +1 -0
  271. package/dist/chunk-JWOYLO27.js +241 -0
  272. package/dist/chunk-JWOYLO27.js.map +1 -0
  273. package/dist/chunk-KIXAU3GM.js +137 -0
  274. package/dist/chunk-KIXAU3GM.js.map +1 -0
  275. package/dist/chunk-KL5ACTCT.js +8 -0
  276. package/dist/chunk-KL5ACTCT.js.map +1 -0
  277. package/dist/chunk-KP7MUZNX.js +83 -0
  278. package/dist/chunk-KP7MUZNX.js.map +1 -0
  279. package/dist/chunk-LEU6UA5J.js +1 -0
  280. package/dist/chunk-LEU6UA5J.js.map +1 -0
  281. package/dist/chunk-M2RGJPXX.js +35 -0
  282. package/dist/chunk-M2RGJPXX.js.map +1 -0
  283. package/dist/chunk-M3BFQ7HK.js +13 -0
  284. package/dist/chunk-M3BFQ7HK.js.map +1 -0
  285. package/dist/chunk-M3WTHJHJ.js +1051 -0
  286. package/dist/chunk-M3WTHJHJ.js.map +1 -0
  287. package/dist/chunk-M7IYCTJV.js +79 -0
  288. package/dist/chunk-M7IYCTJV.js.map +1 -0
  289. package/dist/chunk-NBD3KUOZ.js +838 -0
  290. package/dist/chunk-NBD3KUOZ.js.map +1 -0
  291. package/dist/chunk-NQZ2OSGR.js +151 -0
  292. package/dist/chunk-NQZ2OSGR.js.map +1 -0
  293. package/dist/chunk-NZJKFF45.js +106 -0
  294. package/dist/chunk-NZJKFF45.js.map +1 -0
  295. package/dist/chunk-OFADUJWJ.js +175 -0
  296. package/dist/chunk-OFADUJWJ.js.map +1 -0
  297. package/dist/chunk-OGWBVHB3.js +461 -0
  298. package/dist/chunk-OGWBVHB3.js.map +1 -0
  299. package/dist/chunk-PAYXCY6A.js +1696 -0
  300. package/dist/chunk-PAYXCY6A.js.map +1 -0
  301. package/dist/chunk-PYOE4VSI.js +1924 -0
  302. package/dist/chunk-PYOE4VSI.js.map +1 -0
  303. package/dist/chunk-PZ5AY32C.js +10 -0
  304. package/dist/chunk-PZ5AY32C.js.map +1 -0
  305. package/dist/chunk-QCHIQWAJ.js +21 -0
  306. package/dist/chunk-QCHIQWAJ.js.map +1 -0
  307. package/dist/chunk-QMM6O4CD.js +71 -0
  308. package/dist/chunk-QMM6O4CD.js.map +1 -0
  309. package/dist/chunk-RNFE3ML2.js +22 -0
  310. package/dist/chunk-RNFE3ML2.js.map +1 -0
  311. package/dist/chunk-TAAPQVZN.js +23 -0
  312. package/dist/chunk-TAAPQVZN.js.map +1 -0
  313. package/dist/chunk-THATMZXD.js +21 -0
  314. package/dist/chunk-THATMZXD.js.map +1 -0
  315. package/dist/chunk-TKZ7MEIA.js +27 -0
  316. package/dist/chunk-TKZ7MEIA.js.map +1 -0
  317. package/dist/chunk-TQOBJYDP.js +7 -0
  318. package/dist/chunk-TQOBJYDP.js.map +1 -0
  319. package/dist/chunk-VZB726PE.js +93 -0
  320. package/dist/chunk-VZB726PE.js.map +1 -0
  321. package/dist/chunk-W3TEWHLO.js +568 -0
  322. package/dist/chunk-W3TEWHLO.js.map +1 -0
  323. package/dist/chunk-YS3AZQ2G.js +52 -0
  324. package/dist/chunk-YS3AZQ2G.js.map +1 -0
  325. package/dist/chunk-ZDTRWK5F.js +40 -0
  326. package/dist/chunk-ZDTRWK5F.js.map +1 -0
  327. package/dist/chunk-ZFLHVFUC.js +192 -0
  328. package/dist/chunk-ZFLHVFUC.js.map +1 -0
  329. package/dist/chunk-ZFY7U2FR.js +133 -0
  330. package/dist/chunk-ZFY7U2FR.js.map +1 -0
  331. package/dist/chunk-ZGDVUPTM.js +270 -0
  332. package/dist/chunk-ZGDVUPTM.js.map +1 -0
  333. package/dist/index.cjs +19700 -0
  334. package/dist/index.cjs.map +1 -0
  335. package/dist/index.d.cts +195 -0
  336. package/dist/index.d.ts +195 -0
  337. package/dist/index.js +286 -0
  338. package/dist/index.js.map +1 -0
  339. package/dist/ir-BMP7yxJJ.d.cts +39 -0
  340. package/dist/ir-DUOz6H-5.d.ts +39 -0
  341. package/dist/module-B8CBqIZ_.d.cts +1191 -0
  342. package/dist/module-k7m3txak.d.ts +1191 -0
  343. package/dist/protocol-g_1897M2.d.cts +127 -0
  344. package/dist/protocol-g_1897M2.d.ts +127 -0
  345. package/package.json +162 -0
@@ -0,0 +1,1191 @@
1
+ import * as effect from 'effect';
2
+ import { Schema, Cause, Effect, Stream, Context, SubscriptionRef, Layer } from 'effect';
3
+ import { Draft as Draft$1 } from 'mutative';
4
+ import { S as Service } from './Platform-C49Pv956.cjs';
5
+ import { c as AnyActionToken, a as ActionToken } from './action-DiMDD_0v.cjs';
6
+ import { d as ReadQuery, f as ReadQueryInput } from './ReadQuery-SinbStGF.cjs';
7
+
8
+ interface SerializableErrorSummary {
9
+ readonly message: string;
10
+ readonly name?: string;
11
+ readonly code?: string;
12
+ readonly hint?: string;
13
+ }
14
+
15
+ type Phase = 'init' | 'run' | 'destroy' | 'platform';
16
+ type Hook = 'initRequired' | 'start' | 'destroy' | 'suspend' | 'resume' | 'reset' | 'unknown';
17
+ interface ErrorContext {
18
+ readonly phase: Phase;
19
+ readonly hook: Hook;
20
+ readonly moduleId: string;
21
+ readonly instanceId: string;
22
+ readonly taskId?: string;
23
+ readonly txnSeq?: number;
24
+ readonly opSeq?: number;
25
+ /**
26
+ * For diagnostics only: an implementation-side marker indicating where the error originated,
27
+ * e.g. "logic.fork" / "initRequired" / "start".
28
+ *
29
+ * Note: this field must be serializable and must not become a protocol anchor.
30
+ */
31
+ readonly origin?: string;
32
+ }
33
+ interface ModuleRuntimeIdentity {
34
+ readonly moduleId: string;
35
+ readonly instanceId: string;
36
+ readonly runtimeLabel?: string;
37
+ }
38
+ type InstanceStatus = 'creating' | 'initializing' | 'ready' | 'failed' | 'terminating' | 'terminated';
39
+ interface InitProgress {
40
+ readonly total: number;
41
+ readonly completed: number;
42
+ readonly current?: number;
43
+ readonly startedAt?: number;
44
+ }
45
+ type LifecycleOutcome = {
46
+ readonly status: 'success';
47
+ } | {
48
+ readonly status: 'failure';
49
+ readonly error: SerializableErrorSummary;
50
+ };
51
+ interface LifecycleStatus {
52
+ readonly identity: ModuleRuntimeIdentity;
53
+ readonly status: InstanceStatus;
54
+ readonly initOutcome?: LifecycleOutcome;
55
+ readonly initProgress?: InitProgress;
56
+ }
57
+
58
+ type FieldPath = ReadonlyArray<string>;
59
+ type FieldPathId = number;
60
+ type DirtyAllReason = 'unknownWrite' | 'customMutation' | 'nonTrackablePatch' | 'fallbackPolicy';
61
+ type PatchReason = 'reducer' | 'trait-computed' | 'trait-link' | 'source-refresh' | 'devtools' | 'perf' | 'unknown';
62
+ interface DirtySet {
63
+ readonly dirtyAll: boolean;
64
+ /**
65
+ * When dirtyAll=true, a stable reason code must be provided; when dirtyAll=false, it should be omitted.
66
+ */
67
+ readonly reason?: DirtyAllReason;
68
+ /**
69
+ * FieldPathId (Static IR table index).
70
+ * - When dirtyAll=true, must be an empty array;
71
+ * - When dirtyAll=false, roots are deduped / prefix-free / stably sorted.
72
+ */
73
+ readonly rootIds: ReadonlyArray<FieldPathId>;
74
+ readonly rootCount: number;
75
+ readonly keySize: number;
76
+ readonly keyHash: number;
77
+ /**
78
+ * Optional: mark when the output is TopK-truncated (light/full).
79
+ * Note: truncation does not affect the definition of keyHash/keySize/rootCount (they still refer to full roots).
80
+ */
81
+ readonly rootIdsTruncated?: boolean;
82
+ }
83
+ interface FieldPathTrieNode {
84
+ id?: FieldPathId;
85
+ children: Map<string, FieldPathTrieNode>;
86
+ }
87
+ interface FieldPathIdRegistry {
88
+ readonly fieldPaths: ReadonlyArray<FieldPath>;
89
+ readonly root: FieldPathTrieNode;
90
+ /**
91
+ * Fast path: direct lookup for common string inputs (e.g. 'a.b').
92
+ *
93
+ * Note: This map is only safe for "dot-separated" paths. If a schema key itself contains '.',
94
+ * it is ambiguous with nested paths and should not rely on string-path APIs.
95
+ */
96
+ readonly pathStringToId?: ReadonlyMap<string, FieldPathId>;
97
+ }
98
+ declare const normalizeFieldPath: (input: string | FieldPath) => FieldPath | undefined;
99
+
100
+ type StatePatchPath = string | FieldPath | FieldPathId;
101
+ interface StateTxnOrigin {
102
+ readonly kind: string;
103
+ readonly name?: string;
104
+ readonly details?: unknown;
105
+ }
106
+
107
+ type Primitive = string | number | boolean | bigint | symbol | null | undefined | Date | RegExp | Function;
108
+ type NonNull<T> = Exclude<T, null | undefined>;
109
+ type IsPlainObject<T> = [NonNull<T>] extends [Primitive] ? false : [NonNull<T>] extends [readonly any[]] ? false : [NonNull<T>] extends [Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any>] ? false : [NonNull<T>] extends [object] ? true : false;
110
+ type Join<K, P> = K extends string | number ? (P extends string ? `${K}.${P}` : never) : never;
111
+ type PrevDepth<D extends number> = D extends 4 ? 3 : D extends 3 ? 2 : D extends 2 ? 1 : D extends 1 ? 0 : 0;
112
+ type FieldPathInner<S, Depth extends number> = Depth extends 0 ? never : S extends object ? {
113
+ [K in keyof S & string]: K | (IsPlainObject<S[K]> extends true ? Join<K, FieldPathInner<S[K], PrevDepth<Depth>>> : never);
114
+ }[keyof S & string] : never;
115
+ /**
116
+ * StateFieldPath<S>:
117
+ * - Enumerate all field paths on S that can be annotated by Traits at the type level.
118
+ * - Uses a max recursion depth of 4 to avoid TS Server performance issues.
119
+ */
120
+ type StateFieldPath<S> = FieldPathInner<S, 4>;
121
+ /**
122
+ * StateAtPath<S, P>:
123
+ * - Given a State type S and path P, derive the field type at that path.
124
+ * - Returns never for non-existent paths, used to trigger type errors in tests.
125
+ */
126
+ type StateAtPath<S, P> = S extends object ? P extends `${infer K}.${infer Rest}` ? K extends keyof S ? StateAtPath<S[K], Rest> : never : P extends keyof S ? S[P] : never : never;
127
+
128
+ type TraitMeta = Readonly<{
129
+ readonly label?: string;
130
+ readonly description?: string;
131
+ readonly tags?: ReadonlyArray<string>;
132
+ readonly group?: string;
133
+ readonly docsUrl?: string;
134
+ readonly cacheGroup?: string;
135
+ /**
136
+ * Extension annotations: only accepts `x-*` keys (anchors for capabilities like Phantom Source / Drift Detection).
137
+ *
138
+ * Constraints:
139
+ * - Must be serializable (JSON values).
140
+ * - Must be slim (keep only a few key hints; don't stuff large objects).
141
+ */
142
+ readonly annotations?: Readonly<Record<string, JsonValue>>;
143
+ /**
144
+ * Semantic hint: when the same entity (e.g. the same resourceId) has multiple inconsistent meta declarations,
145
+ * the one with canonical=true becomes the "display canonical", and others are recorded as conflicts.
146
+ */
147
+ readonly canonical?: boolean;
148
+ }>;
149
+ type TraitMetaConflict = Readonly<{
150
+ readonly origin: string;
151
+ readonly meta: TraitMeta;
152
+ }>;
153
+ type JsonPrimitive = string | number | boolean | null;
154
+ type JsonValue = JsonPrimitive | ReadonlyArray<JsonValue> | {
155
+ readonly [key: string]: JsonValue;
156
+ };
157
+
158
+ type ConvergeStepId = number;
159
+ /**
160
+ * ConvergeStaticIrRegistry:
161
+ * - Converge-only static IR generated during build/load (stable within a generation).
162
+ * - Hot paths prefer integer-backed structures; keep only the necessary tables for evidence export and explainability.
163
+ */
164
+ interface ConvergeStaticIrRegistry {
165
+ readonly generation: number;
166
+ /**
167
+ * writerKey/depsKey:
168
+ * - Used to determine "structural changes" of Converge Static IR (bump generation++ and invalidate strictly).
169
+ * - Does not include generation itself.
170
+ */
171
+ readonly writersKey: string;
172
+ readonly depsKey: string;
173
+ /**
174
+ * fieldPathsKey:
175
+ * - Incorporates FieldPathId semantics (fieldPaths table) into the stable definition of staticIrDigest;
176
+ * - Precomputed at build time to avoid repeatedly stringifying large tables at runtime.
177
+ */
178
+ readonly fieldPathsKey: string;
179
+ readonly fieldPaths: ReadonlyArray<FieldPath>;
180
+ readonly fieldPathIdRegistry: FieldPathIdRegistry;
181
+ readonly configError?: {
182
+ readonly code: 'CYCLE_DETECTED' | 'MULTIPLE_WRITERS';
183
+ readonly message: string;
184
+ readonly fields: ReadonlyArray<string>;
185
+ };
186
+ /**
187
+ * stepsById:
188
+ * - StepId -> writer entry (currently computed/link only).
189
+ * - Numbered by topo order by default (so topoOrder is usually 0..stepCount-1).
190
+ */
191
+ readonly stepsById: ReadonlyArray<StateTraitEntry<any, string>>;
192
+ readonly stepOutFieldPathIdByStepId: ReadonlyArray<FieldPathId>;
193
+ readonly stepDepsFieldPathIdsByStepId: ReadonlyArray<ReadonlyArray<FieldPathId>>;
194
+ readonly stepSchedulingByStepId: ReadonlyArray<TraitConvergeScheduling>;
195
+ readonly topoOrder: ReadonlyArray<ConvergeStepId>;
196
+ readonly buildDurationMs: number;
197
+ }
198
+ interface ConvergeStaticIrExport {
199
+ readonly staticIrDigest: string;
200
+ readonly moduleId: string;
201
+ readonly instanceId: string;
202
+ readonly generation: number;
203
+ readonly fieldPaths: ReadonlyArray<FieldPath>;
204
+ readonly stepOutFieldPathIdByStepId: ReadonlyArray<number>;
205
+ readonly stepSchedulingByStepId: ReadonlyArray<TraitConvergeScheduling>;
206
+ readonly topoOrder?: ReadonlyArray<number>;
207
+ readonly buildDurationMs?: number;
208
+ }
209
+
210
+ declare class DenseIdBitSet {
211
+ readonly size: number;
212
+ private readonly words;
213
+ private readonly touchedWords;
214
+ private readonly touchedFlags;
215
+ private touchedCount;
216
+ constructor(size: number, options?: {
217
+ readonly clearStrategy?: 'fill' | 'touched-words';
218
+ });
219
+ clear(): void;
220
+ has(id: number): boolean;
221
+ add(id: number): void;
222
+ }
223
+
224
+ interface ConvergeExecIr {
225
+ readonly generation: number;
226
+ readonly fieldPathsById: ReadonlyArray<FieldPath>;
227
+ readonly prefixFieldPathIdsByPathId: Int32Array;
228
+ readonly prefixOffsetsByPathId: Int32Array;
229
+ /**
230
+ * Reachability triggers (059):
231
+ * - prefixPathId -> stepIds that should run when this prefix becomes dirty
232
+ * - includes prefixes of step outPath and depsPaths
233
+ */
234
+ readonly triggerStepIdsByFieldPathId: Int32Array;
235
+ readonly triggerStepOffsetsByFieldPathId: Int32Array;
236
+ readonly topoOrderInt32: Int32Array;
237
+ readonly topoOrderImmediateInt32: Int32Array;
238
+ readonly topoOrderDeferredInt32: Int32Array;
239
+ /**
240
+ * 0=immediate, 1=deferred(043)
241
+ */
242
+ readonly stepSchedulingByStepId: Uint8Array;
243
+ readonly stepLabelByStepId: ReadonlyArray<string>;
244
+ readonly stepOutFieldPathIdByStepId: Int32Array;
245
+ readonly stepFromFieldPathIdByStepId: Int32Array;
246
+ readonly allOutPathsShallow: boolean;
247
+ readonly stepDepsFieldPathIds: Int32Array;
248
+ readonly stepDepsOffsetsByStepId: Int32Array;
249
+ readonly scratch: {
250
+ readonly dirtyPrefixBitSet: DenseIdBitSet;
251
+ readonly reachableStepBitSet: DenseIdBitSet;
252
+ readonly dirtyPrefixQueue: Int32Array;
253
+ readonly planStepIds: Int32Array;
254
+ };
255
+ }
256
+
257
+ /**
258
+ * StateTraitSpec<S>:
259
+ * - The standard shape for the `traits` slot in a Module blueprint.
260
+ * - Keys are constrained by StateFieldPath<S>; values are declarations for the corresponding scope (Entry / Node / List).
261
+ */
262
+ type StateTraitSpec<S> = S extends object ? {
263
+ [Path in StateFieldPath<S> | '$root']?: StateTraitSpecValue<S, Path>;
264
+ } : never;
265
+ type StateTraitKind = 'computed' | 'source' | 'link' | 'check';
266
+ /**
267
+ * TraitConvergeScheduling:
268
+ * - Scheduling semantics for converge/dirty-check (043): decides whether a step must converge within each transaction window.
269
+ * - Default `immediate` (keeps legacy behavior); `deferred` takes effect only with explicit declaration + time-slicing enabled.
270
+ */
271
+ type TraitConvergeScheduling = 'immediate' | 'deferred';
272
+ interface ComputedMeta<S, P> {
273
+ /**
274
+ * Explicit dependency field paths (required):
275
+ *
276
+ * - deps is the single source of truth for dependencies: Graph/ReverseClosure/incremental scheduling/perf optimizations rely on deps only.
277
+ * - In the DSL, `StateTrait.computed({ deps, get })` uses deps-as-args; it does not expose `(state) => ...`.
278
+ * - During build, `get(...depsValues)` is lowered into `derive(state)` for runtime execution, but the dependency read-set remains deps-based.
279
+ * - In dev-mode, if actual reads in `derive(state)` disagree with deps, a `deps_mismatch` diagnostic warning is emitted.
280
+ *
281
+ * - For root scope: deps are StateFieldPath<State>.
282
+ * - For list.item scope: deps are StateFieldPath<Item> (relative paths; build will prefix them).
283
+ */
284
+ readonly deps: ReadonlyArray<StateFieldPath<S>>;
285
+ readonly derive: (state: Readonly<S>) => StateAtPath<S, P>;
286
+ /**
287
+ * Optional: equality predicate (used to skip no-op writebacks).
288
+ */
289
+ readonly equals?: (prev: StateAtPath<S, P>, next: StateAtPath<S, P>) => boolean;
290
+ /**
291
+ * Converge scheduling (043): defaults to immediate.
292
+ */
293
+ readonly scheduling?: TraitConvergeScheduling;
294
+ }
295
+ interface SourceMeta<S, P> {
296
+ readonly deps: ReadonlyArray<StateFieldPath<S>>;
297
+ /**
298
+ * Logical resource identifier (e.g. "user/profile").
299
+ *
300
+ * - In the StateTrait.source DSL, `resource` is stored here during build.
301
+ * - data-model.md calls it resourceId; we keep the DSL naming here to avoid confusion.
302
+ */
303
+ readonly resource: string;
304
+ /**
305
+ * Rule for computing the key required to access the resource.
306
+ *
307
+ * - deps is the single source of truth for dependencies: Graph/ReverseClosure/incremental scheduling/perf optimizations rely on deps only.
308
+ * - In the DSL, `StateTrait.source({ deps, key })` uses deps-as-args; it does not expose `(state) => ...`.
309
+ * - During build, `key(...depsValues)` is lowered into `key(state)` for runtime execution, but the dependency read-set remains deps-based.
310
+ *
311
+ * - Returning undefined means the resource is inactive under the current state (should be recycled to idle).
312
+ */
313
+ readonly key: (state: Readonly<S>) => unknown;
314
+ readonly triggers?: ReadonlyArray<'onMount' | 'onKeyChange' | 'manual'>;
315
+ readonly debounceMs?: number;
316
+ readonly concurrency?: 'switch' | 'exhaust-trailing';
317
+ /**
318
+ * Serializable metadata for devtools/docs (whitelisted fields).
319
+ */
320
+ readonly meta?: TraitMeta;
321
+ /**
322
+ * Reserved: build may populate the field path this trait is attached to, for easier debugging.
323
+ */
324
+ readonly _fieldPath?: P;
325
+ }
326
+ interface LinkMeta<S> {
327
+ /**
328
+ * Source field path (also constrained by StateFieldPath<S>).
329
+ */
330
+ readonly from: StateFieldPath<S>;
331
+ /**
332
+ * Converge scheduling (043): defaults to immediate.
333
+ */
334
+ readonly scheduling?: TraitConvergeScheduling;
335
+ }
336
+ type CheckRule<Input = unknown, Ctx = unknown> = {
337
+ readonly deps: ReadonlyArray<string>;
338
+ /**
339
+ * validateOn:
340
+ * - Affects only auto validation phases (onChange/onBlur); submit/manual always run.
341
+ * - Empty array disables auto validation (only submit/manual run).
342
+ */
343
+ readonly validateOn?: ReadonlyArray<'onChange' | 'onBlur'>;
344
+ readonly validate: (input: Input, ctx: Ctx) => unknown;
345
+ readonly meta?: TraitMeta;
346
+ };
347
+ interface CheckMeta<Input = unknown, Ctx = unknown> {
348
+ /**
349
+ * Named rule set (used for deterministic merge and diagnostics display).
350
+ */
351
+ readonly rules: Readonly<Record<string, CheckRule<Input, Ctx>>>;
352
+ /**
353
+ * Error-tree writeback (Phase 2: structure only; concrete writeback semantics land in later phases).
354
+ */
355
+ readonly writeback?: {
356
+ readonly kind: 'errors';
357
+ readonly path?: string;
358
+ };
359
+ }
360
+ /**
361
+ * StateTraitEntry<S, P>:
362
+ * - A single Trait configuration attached to a field path P.
363
+ * - kind and meta always come together and are used to dispatch behavior during build/install.
364
+ */
365
+ type StateTraitEntry<S = unknown, P extends string = StateFieldPath<S>> = {
366
+ readonly fieldPath: P;
367
+ readonly kind: 'computed';
368
+ readonly meta: ComputedMeta<S, P>;
369
+ } | {
370
+ readonly fieldPath: P;
371
+ readonly kind: 'source';
372
+ readonly meta: SourceMeta<S, P>;
373
+ } | {
374
+ readonly fieldPath: P;
375
+ readonly kind: 'link';
376
+ readonly meta: LinkMeta<S>;
377
+ } | {
378
+ readonly fieldPath: P;
379
+ readonly kind: 'check';
380
+ readonly meta: CheckMeta<unknown, unknown>;
381
+ };
382
+ interface StateTraitNode<Input = unknown, Ctx = unknown> {
383
+ readonly _tag: 'StateTraitNode';
384
+ readonly computed?: StateTraitEntry<Input, any> | Readonly<Record<string, StateTraitEntry<Input, any>>>;
385
+ readonly source?: StateTraitEntry<Input, any> | Readonly<Record<string, StateTraitEntry<Input, any>>>;
386
+ readonly link?: StateTraitEntry<Input, any> | Readonly<Record<string, StateTraitEntry<Input, any>>>;
387
+ readonly check?: Readonly<Record<string, CheckRule<Input, Ctx>>>;
388
+ readonly meta?: TraitMeta;
389
+ }
390
+ interface StateTraitList<Item = unknown> {
391
+ readonly _tag: 'StateTraitList';
392
+ readonly item?: StateTraitNode<Item, any>;
393
+ readonly list?: StateTraitNode<ReadonlyArray<Item>, any>;
394
+ readonly identityHint?: {
395
+ readonly trackBy?: string;
396
+ };
397
+ }
398
+ type StateTraitSpecValue<S, P extends string> = StateTraitEntry<S, P> | StateTraitNode<any, any> | StateTraitList<any>;
399
+ /**
400
+ * StateTraitField:
401
+ * - Represents a field node in State (whether or not traits are attached).
402
+ * - Normalized from StateTraitSpec during build.
403
+ */
404
+ interface StateTraitField {
405
+ readonly id: string;
406
+ readonly path: string;
407
+ readonly displayName?: string;
408
+ readonly valueType?: string;
409
+ readonly traits: ReadonlyArray<StateTraitFieldTrait>;
410
+ }
411
+ /**
412
+ * StateTraitFieldTrait:
413
+ * - A structured description of a field trait (computed / source / link).
414
+ * - meta matches StateTraitEntry.meta; deps is the set of field paths this trait depends on.
415
+ */
416
+ interface StateTraitFieldTrait {
417
+ readonly fieldId: string;
418
+ readonly kind: StateTraitKind;
419
+ readonly meta: ComputedMeta<unknown, string> | SourceMeta<unknown, string> | LinkMeta<unknown> | CheckMeta<unknown, unknown>;
420
+ readonly deps: ReadonlyArray<string>;
421
+ }
422
+ /**
423
+ * StateTraitResource:
424
+ * - Describes the logical resource metadata that a source trait depends on.
425
+ * - Concrete ResourceSpec implementation lives in the Resource namespace; this keeps only trait-perspective dependency info.
426
+ */
427
+ interface StateTraitResource {
428
+ readonly resourceId: string;
429
+ readonly keySelector: string;
430
+ readonly keyExample?: unknown;
431
+ readonly ownerFields: ReadonlyArray<string>;
432
+ readonly meta?: TraitMeta;
433
+ readonly metaOrigin?: string;
434
+ readonly metaConflicts?: ReadonlyArray<TraitMetaConflict>;
435
+ }
436
+ /**
437
+ * Graph Node / Edge:
438
+ * - Nodes typically correspond to fields.
439
+ * - Edges represent dependencies between fields, or between fields and resources.
440
+ */
441
+ interface StateTraitGraphNode {
442
+ readonly id: string;
443
+ readonly field: StateTraitField;
444
+ readonly traits: ReadonlyArray<StateTraitFieldTrait>;
445
+ readonly meta?: TraitMeta;
446
+ }
447
+ interface StateTraitGraphEdge {
448
+ readonly id: string;
449
+ readonly from: string;
450
+ readonly to: string;
451
+ readonly kind: 'computed' | 'link' | 'source-dep' | 'check-dep';
452
+ }
453
+ /**
454
+ * StateTraitGraph:
455
+ * - Structural view of the StateTrait engine: a graph of nodes and dependency edges.
456
+ * - Used by Devtools / Studio / Runtime for structural analysis and visualization.
457
+ */
458
+ interface StateTraitGraph {
459
+ readonly _tag: 'StateTraitGraph';
460
+ readonly nodes: ReadonlyArray<StateTraitGraphNode>;
461
+ readonly edges: ReadonlyArray<StateTraitGraphEdge>;
462
+ readonly resources: ReadonlyArray<StateTraitResource>;
463
+ readonly meta?: {
464
+ readonly moduleId?: string;
465
+ readonly version?: string;
466
+ };
467
+ }
468
+ /**
469
+ * StateTraitPlanStep:
470
+ * - The smallest instruction unit used by StateTrait.install / Runtime execution.
471
+ * - Derived from the graph; used at runtime to install watchers or trigger external calls.
472
+ */
473
+ interface StateTraitPlanStep {
474
+ readonly id: string;
475
+ readonly kind: 'computed-update' | 'link-propagate' | 'source-refresh' | 'check-validate';
476
+ readonly targetFieldPath?: string;
477
+ readonly sourceFieldPaths?: ReadonlyArray<string>;
478
+ readonly resourceId?: string;
479
+ readonly keySelectorId?: string;
480
+ readonly debugInfo?: {
481
+ readonly graphNodeId?: string;
482
+ readonly graphEdgeId?: string;
483
+ };
484
+ }
485
+ /**
486
+ * StateTraitPlan:
487
+ * - Execution plan summarizing all trait behaviors for a module.
488
+ * - install mounts behaviors onto Bound API / EffectOp pipelines according to the plan.
489
+ */
490
+ interface StateTraitPlan {
491
+ readonly _tag: 'StateTraitPlan';
492
+ readonly moduleId?: string;
493
+ readonly steps: ReadonlyArray<StateTraitPlanStep>;
494
+ readonly meta?: Record<string, unknown>;
495
+ }
496
+ type StateTraitSchemaPathKind = 'fieldPath' | 'dep' | 'link_from' | 'check_writeback';
497
+ interface StateTraitSchemaPathRef {
498
+ readonly kind: StateTraitSchemaPathKind;
499
+ readonly entryKind: StateTraitKind;
500
+ readonly entryFieldPath: string;
501
+ readonly path: string;
502
+ readonly ruleName?: string;
503
+ }
504
+ /**
505
+ * StateTraitProgram<S>:
506
+ * - Program output of the StateTrait engine; the unified entrypoint for Runtime / Devtools.
507
+ * - stateSchema and spec preserve original inputs; graph/plan are internal IR.
508
+ */
509
+ interface StateTraitProgram<S> {
510
+ readonly stateSchema: Schema.Schema<S, any>;
511
+ readonly spec: StateTraitSpec<S>;
512
+ /**
513
+ * Program.entries:
514
+ * - Minimal rule set normalized from spec (including node/list/$root) during build.
515
+ * - Phase 2 focuses on a readable/diagnosable structure; later phases add execution and converge semantics.
516
+ */
517
+ readonly entries: ReadonlyArray<StateTraitEntry<any, string>>;
518
+ readonly graph: StateTraitGraph;
519
+ readonly plan: StateTraitPlan;
520
+ readonly convergeIr?: ConvergeStaticIrRegistry;
521
+ readonly convergeExecIr?: ConvergeExecIr;
522
+ /**
523
+ * schemaPaths:
524
+ * - Path references that must exist in stateSchema, collected from entries during build; dev-only diagnostics (e.g. schema_mismatch).
525
+ * - When diagnostics=off, validation can be skipped entirely to keep near-zero cost.
526
+ */
527
+ readonly schemaPaths?: ReadonlyArray<StateTraitSchemaPathRef>;
528
+ }
529
+ type TraitConvergeRequestedMode = 'auto' | 'full' | 'dirty';
530
+
531
+ type StateTransactionInstrumentation = 'full' | 'light';
532
+ interface StateTransactionTraitConvergeOverrides {
533
+ readonly traitConvergeMode?: TraitConvergeRequestedMode;
534
+ readonly traitConvergeBudgetMs?: number;
535
+ readonly traitConvergeDecisionBudgetMs?: number;
536
+ readonly traitConvergeTimeSlicing?: TraitConvergeTimeSlicingPatch;
537
+ }
538
+ interface TxnLanesPatch {
539
+ /**
540
+ * enabled: whether Txn Lanes is enabled (default on since 062).
541
+ * - undefined: default enabled (when not explicitly configured)
542
+ * - false: disabled (returns to baseline behavior)
543
+ * - true: enabled (only affects scheduling of follow-up work outside the transaction; transactions remain synchronous)
544
+ */
545
+ readonly enabled?: boolean;
546
+ /**
547
+ * overrideMode: runtime temporary override (for debugging/rollback/comparison).
548
+ * - forced_off: forcibly disables Txn Lanes (returns to baseline behavior).
549
+ * - forced_sync: forces fully synchronous execution (ignores non-urgent deferral and time-slicing; used for comparisons).
550
+ *
551
+ * Notes:
552
+ * - Override precedence follows StateTransactionOverrides: provider > runtime_module > runtime_default > builtin.
553
+ * - Overrides must be explainable by evidence (see 060 LaneEvidence reasons).
554
+ */
555
+ readonly overrideMode?: 'forced_off' | 'forced_sync';
556
+ /** non-urgent work loop slice budget (ms). */
557
+ readonly budgetMs?: number;
558
+ /** Non-urgent backlog coalescing window (ms). */
559
+ readonly debounceMs?: number;
560
+ /** Max lag upper bound (ms): exceeding it triggers an explainable starvation protection (forced catch-up). */
561
+ readonly maxLagMs?: number;
562
+ /** Whether to allow coalescing/canceling intermediate non-urgent work (must preserve eventual consistency). */
563
+ readonly allowCoalesce?: boolean;
564
+ /**
565
+ * Yield strategy for the non-urgent work loop (progressive enhancement).
566
+ * - baseline: uses only time budget + hard upper bound
567
+ * - inputPending: when supported by browsers, also consults `navigator.scheduling.isInputPending`
568
+ */
569
+ readonly yieldStrategy?: 'baseline' | 'inputPending';
570
+ }
571
+ interface TraitConvergeTimeSlicingPatch {
572
+ /**
573
+ * enabled:
574
+ * - false/undefined: disabled (default)
575
+ * - true: enables time-slicing (only affects computed/link explicitly marked as deferred)
576
+ */
577
+ readonly enabled?: boolean;
578
+ /**
579
+ * debounceMs: coalescing interval (ms) for the deferral window; merges high-frequency inputs into one deferred flush.
580
+ */
581
+ readonly debounceMs?: number;
582
+ /**
583
+ * maxLagMs: max lag upper bound (ms); exceeding it triggers an explainable forced flush (starvation protection).
584
+ */
585
+ readonly maxLagMs?: number;
586
+ }
587
+ /**
588
+ * Provider-scoped StateTransactionOverrides (delta overrides):
589
+ * - Used to inject more local overrides into a Provider subtree on top of inherited global runtime config.
590
+ * - Override precedence: provider > runtime_module > runtime_default > builtin.
591
+ */
592
+ interface StateTransactionOverrides {
593
+ readonly traitConvergeMode?: TraitConvergeRequestedMode;
594
+ readonly traitConvergeBudgetMs?: number;
595
+ readonly traitConvergeDecisionBudgetMs?: number;
596
+ readonly traitConvergeTimeSlicing?: TraitConvergeTimeSlicingPatch;
597
+ readonly traitConvergeOverridesByModuleId?: Readonly<Record<string, StateTransactionTraitConvergeOverrides>>;
598
+ /** 060: Txn Lanes provider-level overrides (delta overrides). */
599
+ readonly txnLanes?: TxnLanesPatch;
600
+ /** 060: Txn Lanes provider_module overrides (by moduleId). */
601
+ readonly txnLanesOverridesByModuleId?: Readonly<Record<string, TxnLanesPatch>>;
602
+ }
603
+ type ConcurrencyLimit = number | 'unbounded';
604
+ interface ConcurrencyPolicyPatch {
605
+ readonly concurrencyLimit?: ConcurrencyLimit;
606
+ readonly losslessBackpressureCapacity?: number;
607
+ readonly allowUnbounded?: boolean;
608
+ readonly pressureWarningThreshold?: {
609
+ readonly backlogCount?: number;
610
+ readonly backlogDurationMs?: number;
611
+ };
612
+ readonly warningCooldownMs?: number;
613
+ }
614
+ /**
615
+ * Runtime-level ConcurrencyPolicy:
616
+ * - Provided at the app layer by Logix.Runtime.make / AppRuntime.makeApp.
617
+ * - ModuleRuntime merges sources via a resolver (builtin/runtime_module/provider, etc.).
618
+ *
619
+ * Notes:
620
+ * - overridesByModuleId is used for runtime_module hot-switching (hotfix / gradual tuning) and is lower priority than provider overrides.
621
+ */
622
+ interface ConcurrencyPolicy extends ConcurrencyPolicyPatch {
623
+ readonly overridesByModuleId?: Readonly<Record<string, ConcurrencyPolicyPatch>>;
624
+ }
625
+ /**
626
+ * Provider-scoped ConcurrencyPolicyOverrides (delta overrides):
627
+ * - Used to inject more local overrides into a Provider subtree on top of inherited global runtime config.
628
+ * - Override precedence: provider > runtime_module > runtime_default > builtin.
629
+ */
630
+ interface ConcurrencyPolicyOverrides extends ConcurrencyPolicyPatch {
631
+ readonly overridesByModuleId?: Readonly<Record<string, ConcurrencyPolicyPatch>>;
632
+ }
633
+
634
+ type TraitId = string;
635
+ type TraitOriginType = 'module' | 'logicUnit';
636
+ type TraitOriginIdKind = 'explicit' | 'derived';
637
+ interface TraitProvenance {
638
+ readonly originType: TraitOriginType;
639
+ readonly originId: string;
640
+ readonly originIdKind: TraitOriginIdKind;
641
+ /**
642
+ * Human-readable label for Devtools/error messages (e.g. "logicUnit:Profile#1").
643
+ */
644
+ readonly originLabel: string;
645
+ /**
646
+ * Optional location summary (e.g. file path / callsite); for navigation only and not used for semantic decisions.
647
+ */
648
+ readonly path?: string;
649
+ }
650
+ /**
651
+ * TraitSpec:
652
+ * - Minimal representation of "trait declarations": a record keyed by traitId.
653
+ * - The concrete value shape is defined by the specific trait system (e.g. StateTraitSpec).
654
+ * - Value serializability is not constrained here (runtime install may depend on functions), but snapshots/evidence exports
655
+ * must only include serializable subsets.
656
+ */
657
+ type TraitSpec = object;
658
+ interface TraitContribution {
659
+ readonly traits: TraitSpec;
660
+ readonly provenance: TraitProvenance;
661
+ }
662
+ interface ModuleTraitItem {
663
+ readonly traitId: TraitId;
664
+ readonly name: string;
665
+ readonly description?: string;
666
+ }
667
+ interface ModuleTraitsSnapshot {
668
+ readonly moduleId: string;
669
+ readonly digest: string;
670
+ readonly traits: ReadonlyArray<ModuleTraitItem>;
671
+ readonly provenanceIndex: Record<TraitId, TraitProvenance>;
672
+ }
673
+
674
+ interface TaskRunnerOrigins {
675
+ readonly pending?: StateTxnOrigin;
676
+ readonly success?: StateTxnOrigin;
677
+ readonly failure?: StateTxnOrigin;
678
+ }
679
+ type TaskHandler<Payload, Sh extends AnyModuleShape, R> = Of<Sh, R, void, never> | ((payload: Payload) => Of<Sh, R, void, never>);
680
+ type TaskEffect<Payload, Sh extends AnyModuleShape, R, A, E> = Of<Sh, R, A, E> | ((payload: Payload) => Of<Sh, R, A, E>);
681
+ interface TaskRunnerConfig<Payload, Sh extends AnyModuleShape, R, A = void, E = never> {
682
+ /**
683
+ * Optional: trigger source name (e.g. actionTag / fieldPath), used as the default pending origin.name.
684
+ * - BoundApiRuntime may fill this in for onAction("xxx") / traits.source.refresh("field"), etc.
685
+ * - Other callers are not required to provide it.
686
+ */
687
+ readonly triggerName?: string;
688
+ /**
689
+ * pending: synchronous state writes (loading=true / clearing errors, etc.), always a separate transaction entry.
690
+ * - Only executed for tasks that are accepted and actually started (ignored triggers in runExhaustTask do not run pending).
691
+ */
692
+ readonly pending?: TaskHandler<Payload, Sh, R>;
693
+ /**
694
+ * effect: real IO / async work (must run outside the transaction window).
695
+ */
696
+ readonly effect: TaskEffect<Payload, Sh, R, A, E>;
697
+ /**
698
+ * success: success writeback (separate transaction entry).
699
+ */
700
+ readonly success?: (result: A, payload: Payload) => Of<Sh, R, void, never>;
701
+ /**
702
+ * failure: failure writeback (separate transaction entry).
703
+ *
704
+ * Note: takes a Cause to preserve defect/interrupt semantics; interrupts do not trigger failure writeback by default.
705
+ */
706
+ readonly failure?: (cause: Cause.Cause<E>, payload: Payload) => Of<Sh, R, void, never>;
707
+ /**
708
+ * origin: optional override for the three transaction origins.
709
+ * - Default: pending.kind="task:pending"; success/failure.kind="service-callback".
710
+ */
711
+ readonly origin?: TaskRunnerOrigins;
712
+ /**
713
+ * priority: reserved for future debugging/sorting; does not change transaction boundaries or concurrency semantics.
714
+ */
715
+ readonly priority?: number;
716
+ }
717
+
718
+ type Env<Sh extends AnyModuleShape, R> = ModuleRuntimeTag<Sh> | Service | R;
719
+ type Of<Sh extends AnyModuleShape, R = never, A = void, E = never> = Effect.Effect<A, E, Env<Sh, R>>;
720
+ type Draft<T> = Draft$1<T>;
721
+ interface IntentBuilder<Payload, Sh extends AnyModuleShape, R = never> {
722
+ readonly debounce: (ms: number) => IntentBuilder<Payload, Sh, R>;
723
+ readonly throttle: (ms: number) => IntentBuilder<Payload, Sh, R>;
724
+ readonly filter: (predicate: (value: Payload) => boolean) => IntentBuilder<Payload, Sh, R>;
725
+ readonly map: <U>(f: (value: Payload) => U) => IntentBuilder<U, Sh, R>;
726
+ readonly run: <A = void, E = never, R2 = unknown>(effect: Of<Sh, R & R2, A, E> | ((p: Payload) => Of<Sh, R & R2, A, E>), options?: OperationOptions) => Of<Sh, R & R2, void, E>;
727
+ readonly runParallel: <A = void, E = never, R2 = unknown>(effect: Of<Sh, R & R2, A, E> | ((p: Payload) => Of<Sh, R & R2, A, E>), options?: OperationOptions) => Of<Sh, R & R2, void, E>;
728
+ readonly runLatest: <A = void, E = never, R2 = unknown>(effect: Of<Sh, R & R2, A, E> | ((p: Payload) => Of<Sh, R & R2, A, E>), options?: OperationOptions) => Of<Sh, R & R2, void, E>;
729
+ readonly runExhaust: <A = void, E = never, R2 = unknown>(effect: Of<Sh, R & R2, A, E> | ((p: Payload) => Of<Sh, R & R2, A, E>), options?: OperationOptions) => Of<Sh, R & R2, void, E>;
730
+ /**
731
+ * run*Task: long-chain TaskRunner sugar (pending → IO → success/failure), automatically split into multiple entries/transactions.
732
+ *
733
+ * Concurrency semantics mirror run/runLatest/runExhaust/runParallel.
734
+ */
735
+ readonly runTask: <A = void, E = never, R2 = unknown>(config: TaskRunnerConfig<Payload, Sh, R & R2, A, E>) => Of<Sh, R & R2, void, never>;
736
+ readonly runParallelTask: <A = void, E = never, R2 = unknown>(config: TaskRunnerConfig<Payload, Sh, R & R2, A, E>) => Of<Sh, R & R2, void, never>;
737
+ readonly runLatestTask: <A = void, E = never, R2 = unknown>(config: TaskRunnerConfig<Payload, Sh, R & R2, A, E>) => Of<Sh, R & R2, void, never>;
738
+ readonly runExhaustTask: <A = void, E = never, R2 = unknown>(config: TaskRunnerConfig<Payload, Sh, R & R2, A, E>) => Of<Sh, R & R2, void, never>;
739
+ /** Fork a watcher that runs in the ModuleRuntime Scope (equivalent to Effect.forkScoped + run) */
740
+ readonly runFork: <A = void, E = never, R2 = unknown>(effect: Of<Sh, R & R2, A, E> | ((p: Payload) => Of<Sh, R & R2, A, E>)) => Of<Sh, R & R2, void, E>;
741
+ /** Fork a watcher with parallel event processing (equivalent to Effect.forkScoped + runParallel) */
742
+ readonly runParallelFork: <A = void, E = never, R2 = unknown>(effect: Of<Sh, R & R2, A, E> | ((p: Payload) => Of<Sh, R & R2, A, E>)) => Of<Sh, R & R2, void, E>;
743
+ readonly update: (reducer: (prev: StateOf<Sh>, payload: Payload) => StateOf<Sh> | Effect.Effect<StateOf<Sh>, any, any>) => Of<Sh, R, void, never>;
744
+ readonly mutate: (reducer: (draft: Draft<StateOf<Sh>>, payload: Payload) => void) => Of<Sh, R, void, never>;
745
+ readonly pipe: (...fns: ReadonlyArray<(self: IntentBuilder<Payload, Sh, R>) => IntentBuilder<Payload, Sh, R>>) => IntentBuilder<Payload, Sh, R>;
746
+ readonly toStream: () => Stream.Stream<Payload>;
747
+ }
748
+ interface FluentMatch<V> {
749
+ readonly with: <A>(pattern: (value: V) => boolean, handler: (value: V) => A) => FluentMatch<V>;
750
+ readonly otherwise: <A>(handler: (value: V) => A) => A;
751
+ /**
752
+ * Requires at least one branch to match:
753
+ * - If a with branch matches, returns that branch's result (usually an Effect).
754
+ * - If no branch matches, returns a failing Effect.
755
+ *
756
+ * Convention: only use when handlers return an Effect.
757
+ */
758
+ readonly exhaustive: () => Effect.Effect<any, any, any>;
759
+ }
760
+ interface FluentMatchTag<V extends {
761
+ _tag: string;
762
+ }> {
763
+ readonly with: <K extends V['_tag'], A>(tag: K, handler: (value: Extract<V, {
764
+ _tag: K;
765
+ }>) => A) => FluentMatchTag<V>;
766
+ readonly otherwise: <A>(handler: (value: V) => A) => A;
767
+ readonly exhaustive: () => Effect.Effect<any, any, any>;
768
+ }
769
+ interface LogicMeta {
770
+ readonly name: string;
771
+ readonly storeId?: string;
772
+ readonly action?: unknown;
773
+ readonly tags?: string[];
774
+ readonly [key: string]: unknown;
775
+ }
776
+ /**
777
+ * OperationOptions:
778
+ * - Attaches local annotations to a single boundary operation when running Flow/Intent.
779
+ * - Intent-only (e.g. disabling observation-only capabilities); does not carry rule logic itself.
780
+ */
781
+ interface OperationOptions {
782
+ readonly policy?: {
783
+ readonly disableObservers?: boolean;
784
+ };
785
+ readonly tags?: ReadonlyArray<string>;
786
+ readonly trace?: ReadonlyArray<string>;
787
+ readonly meta?: Readonly<Record<string, unknown>>;
788
+ }
789
+ type Middleware<Sh extends AnyModuleShape, R, A, E> = (effect: Effect.Effect<A, E, Env<Sh, R>>, meta: LogicMeta) => Effect.Effect<A, E, Env<Sh, R>>;
790
+
791
+ interface Api<Sh extends ModuleShape<any, any>, R = never> {
792
+ readonly fromAction: <T extends ActionOf<Sh>>(predicate: (a: ActionOf<Sh>) => a is T) => Stream.Stream<T>;
793
+ readonly fromState: {
794
+ <V>(selector: (s: StateOf<Sh>) => V): Stream.Stream<V>;
795
+ <V>(query: ReadQuery<StateOf<Sh>, V>): Stream.Stream<V>;
796
+ };
797
+ readonly debounce: <V>(ms: number) => (stream: Stream.Stream<V>) => Stream.Stream<V>;
798
+ readonly throttle: <V>(ms: number) => (stream: Stream.Stream<V>) => Stream.Stream<V>;
799
+ readonly filter: <V>(predicate: (value: V) => boolean) => (stream: Stream.Stream<V>) => Stream.Stream<V>;
800
+ readonly run: <V, A = void, E = never, R2 = unknown>(eff: Of<Sh, R & R2, A, E> | ((payload: V) => Of<Sh, R & R2, A, E>), options?: OperationOptions) => (stream: Stream.Stream<V>) => Effect.Effect<void, E, Env<Sh, R & R2>>;
801
+ readonly runParallel: <V, A = void, E = never, R2 = unknown>(eff: Of<Sh, R & R2, A, E> | ((payload: V) => Of<Sh, R & R2, A, E>), options?: OperationOptions) => (stream: Stream.Stream<V>) => Effect.Effect<void, E, Env<Sh, R & R2>>;
802
+ readonly runLatest: <V, A = void, E = never, R2 = unknown>(eff: Of<Sh, R & R2, A, E> | ((payload: V) => Of<Sh, R & R2, A, E>), options?: OperationOptions) => (stream: Stream.Stream<V>) => Effect.Effect<void, E, Env<Sh, R & R2>>;
803
+ readonly runExhaust: <V, A = void, E = never, R2 = unknown>(eff: Of<Sh, R & R2, A, E> | ((payload: V) => Of<Sh, R & R2, A, E>), options?: OperationOptions) => (stream: Stream.Stream<V>) => Effect.Effect<void, E, Env<Sh, R & R2>>;
804
+ }
805
+
806
+ /**
807
+ * Convenience constraint: any Effect Schema.
808
+ * We intentionally use `any` to bypass Schema invariance constraints, so that
809
+ * ModuleShape<SpecificSchema> can extend AnyModuleShape.
810
+ */
811
+ type AnySchema = any;
812
+ /**
813
+ * The "schema shape" of a Module: only cares about stateSchema / actionSchema,
814
+ * not runtime configuration details (initialState / services / logic, etc.).
815
+ */
816
+ interface ModuleShape<SSchema extends AnySchema, ASchema extends AnySchema, AMap extends Record<string, AnyActionToken> = Record<string, never>> {
817
+ readonly stateSchema: SSchema;
818
+ readonly actionSchema: ASchema;
819
+ readonly actionMap: AMap;
820
+ }
821
+ /**
822
+ * Convenience constraint: any ModuleShape.
823
+ */
824
+ type AnyModuleShape = ModuleShape<any, any, any>;
825
+ type StateOf<Sh extends AnyModuleShape> = Schema.Schema.Type<Sh['stateSchema']>;
826
+ type ActionOf<Sh extends AnyModuleShape> = Schema.Schema.Type<Sh['actionSchema']>;
827
+ type ActionArgs<P> = [P] extends [void] ? [] | [P] : [P];
828
+ type ActionFn<P, Out> = (...args: ActionArgs<P>) => Out;
829
+ type ActionPayload<T> = T extends ActionToken<any, infer P, any> ? P : never;
830
+ interface ModuleImplementStateTransactionOptions {
831
+ readonly instrumentation?: StateTransactionInstrumentation;
832
+ /** 060: Txn Lanes (instance-level opt-in / tuning). */
833
+ readonly txnLanes?: TxnLanesPatch;
834
+ }
835
+ type StateCommitMode = 'normal' | 'batch' | 'lowPriority';
836
+ type StateCommitPriority = 'normal' | 'low';
837
+ interface StateCommitMeta {
838
+ readonly txnSeq: number;
839
+ readonly txnId: string;
840
+ readonly commitMode: StateCommitMode;
841
+ readonly priority: StateCommitPriority;
842
+ readonly originKind?: string;
843
+ readonly originName?: string;
844
+ }
845
+ interface StateChangeWithMeta<V> {
846
+ readonly value: V;
847
+ readonly meta: StateCommitMeta;
848
+ }
849
+ /**
850
+ * The runtime interface of a Module (similar to "Store as Context" in docs),
851
+ * exposing read/write, subscription, and dispatch capabilities to Logic / Flow.
852
+ */
853
+ interface ModuleRuntime<S, A> {
854
+ /**
855
+ * Associated module identifier:
856
+ * - Injected by ModuleRuntime.make from options.moduleId at construction time.
857
+ * - Primarily used by Devtools / debugging to align runtime instances with module-level information.
858
+ */
859
+ readonly moduleId: string;
860
+ /**
861
+ * Stable instance anchor (single source of truth), aligned with 009/011/016.
862
+ *
863
+ * - Must be injectable/derivable; never default to randomness/time.
864
+ * - Do not expose a "second anchor" field to avoid multiple sources of truth.
865
+ */
866
+ readonly instanceId: string;
867
+ /**
868
+ * Lifecycle status (serializable and consumable by Devtools/Sandbox).
869
+ * - initProgress is updated during initRequired.
870
+ * - initOutcome.failure is populated when initialization fails.
871
+ */
872
+ readonly lifecycleStatus?: Effect.Effect<LifecycleStatus>;
873
+ readonly getState: Effect.Effect<S>;
874
+ readonly setState: (next: S) => Effect.Effect<void>;
875
+ readonly dispatch: (action: A) => Effect.Effect<void>;
876
+ readonly dispatchBatch: (actions: ReadonlyArray<A>) => Effect.Effect<void>;
877
+ readonly dispatchLowPriority: (action: A) => Effect.Effect<void>;
878
+ readonly actions$: Stream.Stream<A>;
879
+ readonly actionsWithMeta$: Stream.Stream<StateChangeWithMeta<A>>;
880
+ /**
881
+ * Subscribe to changes of a selector.
882
+ * Note: an implementation may be based on state$ + distinctUntilChanged.
883
+ */
884
+ readonly changes: <V>(selector: (s: S) => V) => Stream.Stream<V>;
885
+ /**
886
+ * Subscribe to changes of a selector, including commit meta of the current commit (commitMode/priority, etc.).
887
+ */
888
+ readonly changesWithMeta: <V>(selector: (s: S) => V) => Stream.Stream<StateChangeWithMeta<V>>;
889
+ /**
890
+ * Subscribe to ReadQuery (SelectorSpec) changes, including commit meta of the current commit.
891
+ *
892
+ * - static lane: driven by SelectorGraph (precise recompute + cache + precise notifications)
893
+ * - dynamic lane: may fall back to per-commit recompute (legacy)
894
+ */
895
+ readonly changesReadQueryWithMeta: <V>(readQuery: ReadQueryInput<S, V>) => Stream.Stream<StateChangeWithMeta<V>>;
896
+ /**
897
+ * Provide a SubscriptionRef for long-running / fine-grained logic to borrow state directly.
898
+ * The current implementation only exposes a ref for the whole state; selector views are up to the caller to wrap.
899
+ */
900
+ readonly ref: {
901
+ <V = S>(selector?: (s: S) => V): SubscriptionRef.SubscriptionRef<V>;
902
+ };
903
+ }
904
+ /**
905
+ * v3: strongly-typed Module Tag for type-safe constraints in Logic.forShape / collaborative logic.
906
+ *
907
+ * Notes:
908
+ * - The Id type is not important for this PoC, so we use `any`.
909
+ * - The Service type is fixed to the Runtime for the current Shape.
910
+ */
911
+ type ModuleRuntimeTag<Sh extends AnyModuleShape> = Context.Tag<any, ModuleRuntime<StateOf<Sh>, ActionOf<Sh>>>;
912
+ /**
913
+ * Module handle union:
914
+ * - Used by the React adapter / higher-level integrations to accept either a tag or a runtime instance.
915
+ * - As Env/DI: typically put ModuleTag<Sh> into Layer / Runtime environment.
916
+ * - As local ownership: typically pass a runtime instance directly in a component or a logic program.
917
+ *
918
+ * Higher-level APIs may accept ModuleHandle<Sh> and branch internally on tag vs instance.
919
+ */
920
+ type ModuleHandleUnion<Sh extends AnyModuleShape> = ModuleRuntime<StateOf<Sh>, ActionOf<Sh>> | ModuleRuntimeTag<Sh>;
921
+ /**
922
+ * v3: a read-only handle view exposed to Logic for cross-module access.
923
+ *
924
+ * - read: read a snapshot value via selector.
925
+ * - changes: subscribe to changes of the selector view.
926
+ * - dispatch: dispatch an Action to the module.
927
+ *
928
+ * The runtime may wrap an implementation based on ModuleRuntime, but the type does not expose any direct State write API.
929
+ */
930
+ interface ModuleHandle<Sh extends AnyModuleShape> {
931
+ readonly read: <V>(selector: (s: StateOf<Sh>) => V) => Effect.Effect<V, never, never>;
932
+ readonly changes: <V>(selector: (s: StateOf<Sh>) => V) => Stream.Stream<V, never, never>;
933
+ readonly dispatch: (action: ActionOf<Sh>) => Effect.Effect<void, never, never>;
934
+ readonly actions: {
935
+ [K in keyof Sh['actionMap']]: ActionFn<ActionPayload<Sh['actionMap'][K]>, Effect.Effect<void, never, never>>;
936
+ };
937
+ readonly actions$: Stream.Stream<ActionOf<Sh>, never, never>;
938
+ }
939
+ /**
940
+ * ModuleLogic: a logic program that runs on a specific class of Module.
941
+ *
942
+ * - Convention: Env is Logic.Env<Sh, R>.
943
+ * - The return value is treated as void; errors and dependencies are expressed via E/R.
944
+ */
945
+ type ModuleLogic<Sh extends AnyModuleShape, R = unknown, E = unknown> = Of<Sh, R, unknown, E> | LogicPlan<Sh, R, E>;
946
+ declare const MODULE_EXT: unique symbol;
947
+ /**
948
+ * ModuleLike: the minimal runtime/type contract for a Module (definition object / wrapped module),
949
+ * used by $.use(module).
950
+ *
951
+ * - Must be an explicit contract; no duck-typing / magic fields.
952
+ * - `tag` is the identity anchor (ModuleTag/Context.Tag) used for Env resolution.
953
+ * - Other reflection fields (schemas/meta/services/dev.source) are not strictly constrained here.
954
+ */
955
+ interface ModuleLike<Id extends string, Sh extends AnyModuleShape, Ext extends object = {}> {
956
+ readonly _kind: 'ModuleDef' | 'Module';
957
+ readonly id: Id;
958
+ readonly tag: ModuleTag<Id, Sh>;
959
+ /**
960
+ * Type-only extension carrier for `$.use(module)` return typing.
961
+ * - Must not be required at runtime (optional + unique symbol).
962
+ * - Enables extracting `Ext` even though ModuleLike is otherwise structural.
963
+ */
964
+ readonly [MODULE_EXT]?: Ext;
965
+ }
966
+ type ModuleShapeOf<M> = M extends ModuleLike<any, infer Sh, any> ? Sh : never;
967
+ type ModuleExtOf<M> = M extends ModuleLike<any, any, infer Ext> ? Ext : never;
968
+ /**
969
+ * LogicPlan: an internal two-phase logic abstraction (setup + run).
970
+ *
971
+ * - setup: runs during Module instance startup, used to register reducers / lifecycle / Debug and other structural behavior.
972
+ * - run: the main logic program, running as a long-lived fiber after Env is fully ready.
973
+ *
974
+ * Notes:
975
+ * - In the current implementation, Runtime still treats Logic as a single-phase program, equivalent to
976
+ * `setup = Effect.void` and `run = Logic`.
977
+ * - After the runtime-logix L4 drafts converge, we will gradually adopt a real two-phase execution model.
978
+ */
979
+ interface LogicPlan<Sh extends AnyModuleShape, R = unknown, E = unknown> {
980
+ readonly setup: Of<Sh, R, void, never>;
981
+ readonly run: Of<Sh, R, unknown, E>;
982
+ }
983
+ /**
984
+ * Bound API: creates pre-bound accessors for a given Store shape + Env.
985
+ *
986
+ * - The runtime implementation lives in internal/runtime/BoundApiRuntime.
987
+ * - The public Bound.ts exports a same-named type alias to keep the public API consistent.
988
+ */
989
+ interface BoundApi<Sh extends AnyModuleShape, R = never> {
990
+ readonly root: {
991
+ readonly resolve: <Svc, Id = unknown>(tag: Context.Tag<Id, Svc>) => Of<Sh, R, Svc, never>;
992
+ };
993
+ readonly state: {
994
+ readonly read: Of<Sh, R, StateOf<Sh>, never>;
995
+ readonly update: (f: (prev: StateOf<Sh>) => StateOf<Sh>) => Of<Sh, R, void, never>;
996
+ readonly mutate: (f: (draft: Draft<StateOf<Sh>>) => void) => Of<Sh, R, void, never>;
997
+ readonly ref: {
998
+ <V = StateOf<Sh>>(selector?: (s: StateOf<Sh>) => V): SubscriptionRef.SubscriptionRef<V>;
999
+ };
1000
+ };
1001
+ readonly actions: Sh['actionMap'];
1002
+ readonly dispatchers: {
1003
+ readonly [K in keyof Sh['actionMap']]: ActionFn<ActionPayload<Sh['actionMap'][K]>, Of<Sh, R, void, never>>;
1004
+ };
1005
+ readonly dispatch: {
1006
+ (action: ActionOf<Sh>): Of<Sh, R, void, never>;
1007
+ <K extends keyof Sh['actionMap']>(token: Sh['actionMap'][K], ...args: ActionArgs<ActionPayload<Sh['actionMap'][K]>>): Of<Sh, R, void, never>;
1008
+ <K extends keyof Sh['actionMap']>(tag: K, ...args: ActionArgs<ActionPayload<Sh['actionMap'][K]>>): Of<Sh, R, void, never>;
1009
+ };
1010
+ /**
1011
+ * effect:
1012
+ * - Register a side-effect handler for a specific Action token.
1013
+ * - Setup registration is the primary path; run-phase dynamic registration is allowed but emits diagnostics and only affects future actions.
1014
+ *
1015
+ * Constraints:
1016
+ * - Handlers must run outside the transaction window (FR-012); never perform IO inside reducers/transactions.
1017
+ * - The runtime de-duplicates by `(actionTag, sourceKey)` (sourceKey is derived automatically).
1018
+ */
1019
+ readonly effect: <K extends keyof Sh['actionMap']>(token: Sh['actionMap'][K], handler: (payload: ActionPayload<Sh['actionMap'][K]>) => Of<Sh, R, void, any>) => Of<Sh, R, void, never>;
1020
+ readonly flow: Api<Sh, R>;
1021
+ readonly match: <V>(value: V) => FluentMatch<V>;
1022
+ readonly matchTag: <V extends {
1023
+ _tag: string;
1024
+ }>(value: V) => FluentMatchTag<V>;
1025
+ readonly lifecycle: {
1026
+ readonly onInitRequired: (eff: Of<Sh, R, void, never>) => Of<Sh, R, void, never>;
1027
+ readonly onStart: (eff: Of<Sh, R, void, never>) => Of<Sh, R, void, never>;
1028
+ readonly onInit: (eff: Of<Sh, R, void, never>) => Of<Sh, R, void, never>;
1029
+ readonly onDestroy: (eff: Of<Sh, R, void, never>) => Of<Sh, R, void, never>;
1030
+ readonly onError: (handler: (cause: effect.Cause.Cause<unknown>, context: ErrorContext) => Effect.Effect<void, never, R>) => Of<Sh, R, void, never>;
1031
+ readonly onSuspend: (eff: Of<Sh, R, void, never>) => Of<Sh, R, void, never>;
1032
+ readonly onResume: (eff: Of<Sh, R, void, never>) => Of<Sh, R, void, never>;
1033
+ readonly onReset: (eff: Of<Sh, R, void, never>) => Of<Sh, R, void, never>;
1034
+ };
1035
+ readonly use: {
1036
+ <M extends ModuleLike<string, AnyModuleShape, any>>(module: M): Of<Sh, R, ModuleHandle<ModuleShapeOf<M>> & ModuleExtOf<M>, never>;
1037
+ <Sh2 extends AnyModuleShape>(module: ModuleTag<string, Sh2>): Of<Sh, R, ModuleHandle<Sh2>, never>;
1038
+ <Svc, Id = unknown>(tag: Context.Tag<Id, Svc>): Of<Sh, R, Svc, never>;
1039
+ };
1040
+ readonly onAction: {
1041
+ <T extends ActionOf<Sh>>(predicate: (a: ActionOf<Sh>) => a is T): IntentBuilder<T, Sh, R>;
1042
+ <K extends keyof Sh['actionMap']>(tag: K): IntentBuilder<Extract<ActionOf<Sh>, {
1043
+ _tag: K;
1044
+ } | {
1045
+ type: K;
1046
+ }>, Sh, R>;
1047
+ <A extends ActionOf<Sh> & ({
1048
+ _tag: string;
1049
+ } | {
1050
+ type: string;
1051
+ })>(value: A): IntentBuilder<A, Sh, R>;
1052
+ <Sc extends AnySchema>(schema: Sc): IntentBuilder<Extract<ActionOf<Sh>, Schema.Schema.Type<Sc>>, Sh, R>;
1053
+ <K extends keyof Sh['actionMap']>(token: Sh['actionMap'][K]): IntentBuilder<ActionPayload<Sh['actionMap'][K]>, Sh, R>;
1054
+ } & {
1055
+ [K in keyof Sh['actionMap']]: IntentBuilder<Extract<ActionOf<Sh>, {
1056
+ _tag: K;
1057
+ } | {
1058
+ type: K;
1059
+ }>, Sh, R>;
1060
+ };
1061
+ readonly onState: <V>(selector: (s: StateOf<Sh>) => V) => IntentBuilder<V, Sh, R>;
1062
+ readonly on: <V>(source: Stream.Stream<V>) => IntentBuilder<V, Sh, R>;
1063
+ /**
1064
+ * traits: runtime entrypoints reserved for features like StateTrait.
1065
+ *
1066
+ * - source.refresh(fieldPath): trigger an explicit refresh of a source field.
1067
+ * - Concrete behavior is mounted at runtime by StateTrait.install.
1068
+ */
1069
+ readonly traits: {
1070
+ /**
1071
+ * declare:
1072
+ * - setup-only: contributes trait declarations during the Logic setup phase (pure data/declarative).
1073
+ * - Final merge / conflict detection / freezing is done during Runtime initialization (023).
1074
+ */
1075
+ readonly declare: (traits: TraitSpec) => void;
1076
+ readonly source: {
1077
+ readonly refresh: (fieldPath: string, options?: {
1078
+ /**
1079
+ * Forced refresh: re-fetch even if keyHash is unchanged and a non-idle snapshot already exists.
1080
+ * - Used for explicit refresh / invalidate where "same key still re-fetch" is desired.
1081
+ * - Auto-trigger chains SHOULD keep the default (false/undefined) to avoid duplicate IO and meaningless writebacks.
1082
+ */
1083
+ readonly force?: boolean;
1084
+ }) => Of<Sh, R, void, never>;
1085
+ };
1086
+ };
1087
+ /**
1088
+ * Primary reducer definition entrypoint:
1089
+ * - Semantics: register a synchronous, pure state transform reducer for an Action tag.
1090
+ * - Implementation: writes directly into the Runtime's `_tag -> (state, action) => state` map, not watcher / Flow.
1091
+ *
1092
+ * Constraints:
1093
+ * - At most one primary reducer per Action tag; duplicate registration is an error.
1094
+ * - The reducer must be pure: no Env, no Effect.
1095
+ */
1096
+ readonly reducer: <K extends keyof Sh['actionMap'], A extends Extract<ActionOf<Sh>, {
1097
+ _tag: K;
1098
+ } | {
1099
+ type: K;
1100
+ }>>(tag: K, reducer: (state: StateOf<Sh>, action: A) => StateOf<Sh>) => Of<Sh, R, void, never>;
1101
+ }
1102
+ /**
1103
+ * ModuleTag: identity anchor (Context.Tag).
1104
+ *
1105
+ * - Also acts as a Context.Tag; usable as an argument to `$.use(Module)`.
1106
+ * - Exposes `logic` and `live` factories for mounting logic programs and building the live Layer.
1107
+ */
1108
+ interface ModuleTag<Id extends string, Sh extends AnyModuleShape> extends Context.Tag<any, ModuleRuntime<StateOf<Sh>, ActionOf<Sh>>> {
1109
+ readonly _kind: 'ModuleTag';
1110
+ readonly id: Id;
1111
+ readonly shape: Sh;
1112
+ readonly stateSchema: Sh['stateSchema'];
1113
+ readonly actionSchema: Sh['actionSchema'];
1114
+ /**
1115
+ * Raw ActionToken map (actionTag -> token).
1116
+ * - Mainly for DX/reflection; runtime contract is still based on shape/actionSchema.
1117
+ */
1118
+ readonly actions: Sh['actionMap'];
1119
+ /**
1120
+ * Raw reducers (if provided by the definition).
1121
+ * - Mainly for DX/reflection; runtime normalizes them into a `_tag -> (state, action) => state` map inside ModuleFactory.
1122
+ */
1123
+ readonly reducers?: ReducersFromMap<Sh['stateSchema'], Sh['actionMap']>;
1124
+ readonly logic: <R = never, E = unknown>(build: (api: BoundApi<Sh, R>) => ModuleLogic<Sh, R, E>) => ModuleLogic<Sh, R, E>;
1125
+ readonly live: <R = never, E = never>(initial: StateOf<Sh>, ...logics: Array<ModuleLogic<Sh, R, E>>) => Layer.Layer<ModuleRuntime<StateOf<Sh>, ActionOf<Sh>>, E, R>;
1126
+ /**
1127
+ * implement: build a ModuleImpl blueprint from Module definition + initial state + a set of logics.
1128
+ *
1129
+ * - R represents the Env required by the logics.
1130
+ * - The returned ModuleImpl.layer carries R as its input environment.
1131
+ * - withLayer/withLayers can progressively narrow R to a more concrete Env (even `never`).
1132
+ */
1133
+ readonly implement: <R = never>(config: {
1134
+ initial: StateOf<Sh>;
1135
+ logics?: Array<ModuleLogic<Sh, R, any>>;
1136
+ imports?: ReadonlyArray<Layer.Layer<any, any, any> | ModuleImpl<any, AnyModuleShape, any>>;
1137
+ processes?: ReadonlyArray<Effect.Effect<void, any, any>>;
1138
+ stateTransaction?: ModuleImplementStateTransactionOptions;
1139
+ }) => ModuleImpl<Id, Sh, R>;
1140
+ }
1141
+ /**
1142
+ * ModuleImpl: a concrete Module implementation unit (blueprint + initial state + mounted logics).
1143
+ *
1144
+ * - It's a "configured module" that can be consumed directly by React hooks or app composition.
1145
+ * - It carries the Env dependency type R required by the implementation.
1146
+ */
1147
+ interface ModuleImpl<Id extends string, Sh extends AnyModuleShape, REnv = any> {
1148
+ readonly _tag: 'ModuleImpl';
1149
+ readonly module: ModuleTag<Id, Sh>;
1150
+ readonly layer: Layer.Layer<ModuleRuntime<StateOf<Sh>, ActionOf<Sh>>, never, REnv>;
1151
+ readonly processes?: ReadonlyArray<Effect.Effect<void, any, any>>;
1152
+ readonly stateTransaction?: ModuleImplementStateTransactionOptions;
1153
+ readonly withLayer: (layer: Layer.Layer<any, never, any>) => ModuleImpl<Id, Sh, REnv>;
1154
+ readonly withLayers: (...layers: ReadonlyArray<Layer.Layer<any, never, any>>) => ModuleImpl<Id, Sh, REnv>;
1155
+ }
1156
+ /**
1157
+ * Helper type: convert an Action Map into a union type.
1158
+ */
1159
+ type PayloadOfActionDef<V> = V extends Schema.Schema<any, any, any> ? Schema.Schema.Type<V> : V extends ActionToken<any, infer P, any> ? P : never;
1160
+ type ActionsFromMap<M extends Record<string, AnySchema>> = {
1161
+ [K in keyof M]: M[K] extends Schema.Schema<any, any, any> ? PayloadOfActionDef<M[K]> extends void ? {
1162
+ readonly _tag: K;
1163
+ readonly payload?: PayloadOfActionDef<M[K]>;
1164
+ } : {
1165
+ readonly _tag: K;
1166
+ readonly payload: PayloadOfActionDef<M[K]>;
1167
+ } : M[K] extends ActionToken<any, any, any> ? ReturnType<M[K]> : never;
1168
+ }[keyof M];
1169
+ /**
1170
+ * Derive a tag-keyed "draft-style reducer (mutator) map" from an Action Map:
1171
+ * - Each Action tag may optionally declare a `(draftState, payload) => void`.
1172
+ * - Higher-level APIs wrap it into a pure reducer via `Module.Reducer.mutate` / `Module.Reducer.mutateMap`.
1173
+ */
1174
+ type MutatorsFromMap<SSchema extends AnySchema, AMap extends Record<string, AnySchema>> = {
1175
+ readonly [K in keyof AMap]?: (draft: Draft<Schema.Schema.Type<SSchema>>, payload: PayloadOfActionDef<AMap[K]>) => void;
1176
+ };
1177
+ /**
1178
+ * Derive a tag-keyed reducer map from an Action Map:
1179
+ * - Each Action tag may optionally declare a primary reducer `(state, actionOfThisTag) => nextState`.
1180
+ */
1181
+ type ReducersFromMap<SSchema extends AnySchema, AMap extends Record<string, AnySchema>> = {
1182
+ readonly [K in keyof AMap]?: (state: Schema.Schema.Type<SSchema>, action: AMap[K] extends ActionToken<any, any, any> ? ReturnType<AMap[K]> : PayloadOfActionDef<AMap[K]> extends void ? {
1183
+ readonly _tag: K;
1184
+ readonly payload?: PayloadOfActionDef<AMap[K]>;
1185
+ } : {
1186
+ readonly _tag: K;
1187
+ readonly payload: PayloadOfActionDef<AMap[K]>;
1188
+ }, sink?: (path: string | FieldPath) => void) => Schema.Schema.Type<SSchema>;
1189
+ };
1190
+
1191
+ export { type OperationOptions as $, type AnySchema as A, type BoundApi as B, type ConcurrencyLimit as C, type DirtyAllReason as D, type ErrorContext as E, type FieldPath as F, type ModuleHandleUnion as G, type TraitConvergeTimeSlicingPatch as H, type TxnLanesPatch as I, type StateTransactionTraitConvergeOverrides as J, type StateTransactionOverrides as K, type ConvergeStaticIrExport as L, type ModuleTag as M, type TraitProvenance as N, type ModuleImplementStateTransactionOptions as O, type PatchReason as P, type Env as Q, type ReducersFromMap as R, type StateTransactionInstrumentation as S, type TraitContribution as T, type Of as U, type Draft as V, type IntentBuilder as W, type FluentMatch as X, type FluentMatchTag as Y, type LogicMeta as Z, type Middleware as _, type StatePatchPath as a, type SerializableErrorSummary as a0, type StateTraitProgram as a1, type StateTraitGraph as a2, type StateTraitPlan as a3, type StateTraitSpec as a4, type StateTraitEntry as a5, type StateTraitNode as a6, type StateTraitList as a7, type CheckRule as a8, type StateFieldPath as a9, type StateAtPath as aa, type TraitConvergeScheduling as ab, type DirtySet as b, type FieldPathId as c, type ModuleRuntimeTag as d, type ConcurrencyPolicy as e, type ConcurrencyPolicyOverrides as f, type ConcurrencyPolicyPatch as g, type AnyModuleShape as h, type ModuleShape as i, type ModuleLogic as j, type ModuleImpl as k, type ModuleRuntime as l, type ModuleHandle as m, normalizeFieldPath as n, type StateOf as o, type ActionOf as p, type ActionsFromMap as q, type MutatorsFromMap as r, type StateCommitMode as s, type StateCommitPriority as t, type StateCommitMeta as u, type StateChangeWithMeta as v, type StateTxnOrigin as w, type ModuleTraitsSnapshot as x, type Api as y, type ModuleLike as z };