@graphrefly/graphrefly 0.45.0 → 0.47.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (714) hide show
  1. package/README.md +1 -2
  2. package/dist/_internal-B23BagFd.d.cts +33 -0
  3. package/dist/_internal-B23BagFd.d.ts +33 -0
  4. package/dist/adaptive-rate-limiter-Dch_xYIi.d.cts +111 -0
  5. package/dist/adaptive-rate-limiter-Dch_xYIi.d.ts +111 -0
  6. package/dist/agents-C0Ji9ldU.d.cts +629 -0
  7. package/dist/agents-C9zexT7I.d.ts +629 -0
  8. package/dist/audit-BAXb3VOg.d.ts +246 -0
  9. package/dist/audit-C_bPfkqS.d.cts +246 -0
  10. package/dist/backoff-7KIK3WQW.js +24 -0
  11. package/dist/backoff-7KIK3WQW.js.map +1 -0
  12. package/dist/backoff-Bnb9OoPh.d.cts +6 -0
  13. package/dist/backoff-Bnb9OoPh.d.ts +6 -0
  14. package/dist/base/composition/index.cjs +865 -0
  15. package/dist/base/composition/index.cjs.map +1 -0
  16. package/dist/base/composition/index.d.cts +468 -0
  17. package/dist/base/composition/index.d.ts +468 -0
  18. package/dist/base/composition/index.js +40 -0
  19. package/dist/base/composition/index.js.map +1 -0
  20. package/dist/base/index.cjs +6390 -0
  21. package/dist/base/index.cjs.map +1 -0
  22. package/dist/base/index.d.cts +21 -0
  23. package/dist/base/index.d.ts +21 -0
  24. package/dist/base/index.js +259 -0
  25. package/dist/base/index.js.map +1 -0
  26. package/dist/base/io/index.cjs +3270 -0
  27. package/dist/base/io/index.cjs.map +1 -0
  28. package/dist/base/io/index.d.cts +2245 -0
  29. package/dist/base/io/index.d.ts +2245 -0
  30. package/dist/base/io/index.js +117 -0
  31. package/dist/base/io/index.js.map +1 -0
  32. package/dist/base/meta/index.cjs +43 -0
  33. package/dist/base/meta/index.cjs.map +1 -0
  34. package/dist/base/meta/index.d.cts +45 -0
  35. package/dist/base/meta/index.d.ts +45 -0
  36. package/dist/base/meta/index.js +13 -0
  37. package/dist/base/meta/index.js.map +1 -0
  38. package/dist/base/mutation/index.cjs +200 -0
  39. package/dist/base/mutation/index.cjs.map +1 -0
  40. package/dist/base/mutation/index.d.cts +177 -0
  41. package/dist/base/mutation/index.d.ts +177 -0
  42. package/dist/base/mutation/index.js +22 -0
  43. package/dist/base/mutation/index.js.map +1 -0
  44. package/dist/base/render/index.cjs +1120 -0
  45. package/dist/base/render/index.cjs.map +1 -0
  46. package/dist/base/render/index.d.cts +227 -0
  47. package/dist/base/render/index.d.ts +227 -0
  48. package/dist/base/render/index.js +24 -0
  49. package/dist/base/render/index.js.map +1 -0
  50. package/dist/base/sources/browser/index.cjs +172 -0
  51. package/dist/base/sources/browser/index.cjs.map +1 -0
  52. package/dist/base/sources/browser/index.d.cts +84 -0
  53. package/dist/base/sources/browser/index.d.ts +84 -0
  54. package/dist/base/sources/browser/index.js +151 -0
  55. package/dist/base/sources/browser/index.js.map +1 -0
  56. package/dist/base/sources/event/index.cjs +98 -0
  57. package/dist/base/sources/event/index.cjs.map +1 -0
  58. package/dist/base/sources/event/index.d.cts +91 -0
  59. package/dist/base/sources/event/index.d.ts +91 -0
  60. package/dist/base/sources/event/index.js +13 -0
  61. package/dist/base/sources/event/index.js.map +1 -0
  62. package/dist/base/sources/index.cjs +755 -0
  63. package/dist/base/sources/index.cjs.map +1 -0
  64. package/dist/base/sources/index.d.cts +357 -0
  65. package/dist/base/sources/index.d.ts +357 -0
  66. package/dist/base/sources/index.js +42 -0
  67. package/dist/base/sources/index.js.map +1 -0
  68. package/dist/base/sources/node/index.cjs +320 -0
  69. package/dist/base/sources/node/index.cjs.map +1 -0
  70. package/dist/base/sources/node/index.d.cts +185 -0
  71. package/dist/base/sources/node/index.d.ts +185 -0
  72. package/dist/base/sources/node/index.js +306 -0
  73. package/dist/base/sources/node/index.js.map +1 -0
  74. package/dist/base/utils/index.cjs +37 -0
  75. package/dist/base/utils/index.cjs.map +1 -0
  76. package/dist/base/utils/index.d.cts +37 -0
  77. package/dist/base/utils/index.d.ts +37 -0
  78. package/dist/base/utils/index.js +11 -0
  79. package/dist/base/utils/index.js.map +1 -0
  80. package/dist/base/worker/index.cjs +548 -0
  81. package/dist/base/worker/index.cjs.map +1 -0
  82. package/dist/base/worker/index.d.cts +207 -0
  83. package/dist/base/worker/index.d.ts +207 -0
  84. package/dist/base/worker/index.js +20 -0
  85. package/dist/base/worker/index.js.map +1 -0
  86. package/dist/breaker-C9skL3d8.d.ts +175 -0
  87. package/dist/breaker-ugSdq54q.d.cts +175 -0
  88. package/dist/cascading-CSSbKGrJ.d.ts +199 -0
  89. package/dist/cascading-baGkiihI.d.cts +199 -0
  90. package/dist/chunk-22SG74BD.js +207 -0
  91. package/dist/chunk-22SG74BD.js.map +1 -0
  92. package/dist/chunk-255UCBG4.js +58 -0
  93. package/dist/chunk-255UCBG4.js.map +1 -0
  94. package/dist/chunk-2LO3EL4W.js +1 -0
  95. package/dist/chunk-2LO3EL4W.js.map +1 -0
  96. package/dist/chunk-2OB3CEJS.js +1065 -0
  97. package/dist/chunk-2OB3CEJS.js.map +1 -0
  98. package/dist/chunk-36NMM65U.js +144 -0
  99. package/dist/chunk-36NMM65U.js.map +1 -0
  100. package/dist/chunk-3CEXCBN6.js +1 -0
  101. package/dist/chunk-3CEXCBN6.js.map +1 -0
  102. package/dist/chunk-3MUSLI6E.js +105 -0
  103. package/dist/chunk-3MUSLI6E.js.map +1 -0
  104. package/dist/chunk-3PSLNJDU.js +884 -0
  105. package/dist/chunk-3PSLNJDU.js.map +1 -0
  106. package/dist/chunk-42FQ27MQ.js +594 -0
  107. package/dist/chunk-42FQ27MQ.js.map +1 -0
  108. package/dist/chunk-4GYMCUDZ.js +1085 -0
  109. package/dist/chunk-4GYMCUDZ.js.map +1 -0
  110. package/dist/chunk-4S53H2KR.js +382 -0
  111. package/dist/chunk-4S53H2KR.js.map +1 -0
  112. package/dist/chunk-4XCHZRUJ.js +128 -0
  113. package/dist/chunk-4XCHZRUJ.js.map +1 -0
  114. package/dist/chunk-5IMMNARC.js +1153 -0
  115. package/dist/chunk-5IMMNARC.js.map +1 -0
  116. package/dist/chunk-6XZYT4SW.js +256 -0
  117. package/dist/chunk-6XZYT4SW.js.map +1 -0
  118. package/dist/chunk-7EGRP2VX.js +76 -0
  119. package/dist/chunk-7EGRP2VX.js.map +1 -0
  120. package/dist/chunk-A7KV5UK4.js +150 -0
  121. package/dist/chunk-A7KV5UK4.js.map +1 -0
  122. package/dist/chunk-APY2SS5X.js +156 -0
  123. package/dist/chunk-APY2SS5X.js.map +1 -0
  124. package/dist/chunk-AZDQPQ3V.js +66 -0
  125. package/dist/chunk-AZDQPQ3V.js.map +1 -0
  126. package/dist/chunk-BU3SEFA5.js +90 -0
  127. package/dist/chunk-BU3SEFA5.js.map +1 -0
  128. package/dist/chunk-BXGZFGZ4.js +189 -0
  129. package/dist/chunk-BXGZFGZ4.js.map +1 -0
  130. package/dist/chunk-CGHORL6G.js +579 -0
  131. package/dist/chunk-CGHORL6G.js.map +1 -0
  132. package/dist/chunk-CXANAIZU.js +530 -0
  133. package/dist/chunk-CXANAIZU.js.map +1 -0
  134. package/dist/chunk-CZQHCKKG.js +1 -0
  135. package/dist/chunk-CZQHCKKG.js.map +1 -0
  136. package/dist/chunk-DKNHAICT.js +133 -0
  137. package/dist/chunk-DKNHAICT.js.map +1 -0
  138. package/dist/chunk-DM4OMPWK.js +584 -0
  139. package/dist/chunk-DM4OMPWK.js.map +1 -0
  140. package/dist/chunk-DMSNO6ZB.js +452 -0
  141. package/dist/chunk-DMSNO6ZB.js.map +1 -0
  142. package/dist/chunk-E5OZPDIW.js +229 -0
  143. package/dist/chunk-E5OZPDIW.js.map +1 -0
  144. package/dist/chunk-EHRRQ4IC.js +211 -0
  145. package/dist/chunk-EHRRQ4IC.js.map +1 -0
  146. package/dist/chunk-EVYY4X5A.js +509 -0
  147. package/dist/chunk-EVYY4X5A.js.map +1 -0
  148. package/dist/chunk-FDFD67UO.js +1 -0
  149. package/dist/chunk-FDFD67UO.js.map +1 -0
  150. package/dist/chunk-FMPF42Q4.js +13 -0
  151. package/dist/chunk-FMPF42Q4.js.map +1 -0
  152. package/dist/chunk-FW23JYNQ.js +454 -0
  153. package/dist/chunk-FW23JYNQ.js.map +1 -0
  154. package/dist/chunk-GWRNLJNW.js +2508 -0
  155. package/dist/chunk-GWRNLJNW.js.map +1 -0
  156. package/dist/chunk-HL7HUJIX.js +1 -0
  157. package/dist/chunk-HL7HUJIX.js.map +1 -0
  158. package/dist/chunk-IHTWQEDR.js +169 -0
  159. package/dist/chunk-IHTWQEDR.js.map +1 -0
  160. package/dist/chunk-IJRR6YAI.js +128 -0
  161. package/dist/chunk-IJRR6YAI.js.map +1 -0
  162. package/dist/chunk-JGFRAFDL.js +221 -0
  163. package/dist/chunk-JGFRAFDL.js.map +1 -0
  164. package/dist/chunk-JKTC747G.js +725 -0
  165. package/dist/chunk-JKTC747G.js.map +1 -0
  166. package/dist/chunk-KN3H5CNT.js +11 -0
  167. package/dist/chunk-KN3H5CNT.js.map +1 -0
  168. package/dist/chunk-KPG3DGLA.js +1 -0
  169. package/dist/chunk-KPG3DGLA.js.map +1 -0
  170. package/dist/chunk-KRNQ6RGQ.js +1 -0
  171. package/dist/chunk-KRNQ6RGQ.js.map +1 -0
  172. package/dist/chunk-MLTPJMH6.js +417 -0
  173. package/dist/chunk-MLTPJMH6.js.map +1 -0
  174. package/dist/chunk-N3SZ7BMH.js +95 -0
  175. package/dist/chunk-N3SZ7BMH.js.map +1 -0
  176. package/dist/chunk-NDUD3IMO.js +540 -0
  177. package/dist/chunk-NDUD3IMO.js.map +1 -0
  178. package/dist/chunk-NY2PYHNC.js +873 -0
  179. package/dist/chunk-NY2PYHNC.js.map +1 -0
  180. package/dist/chunk-O3MT7DYI.js +225 -0
  181. package/dist/chunk-O3MT7DYI.js.map +1 -0
  182. package/dist/chunk-OCUDSN63.js +2386 -0
  183. package/dist/chunk-OCUDSN63.js.map +1 -0
  184. package/dist/chunk-OIWU3NYV.js +199 -0
  185. package/dist/chunk-OIWU3NYV.js.map +1 -0
  186. package/dist/chunk-OQUIJT7A.js +1 -0
  187. package/dist/chunk-OQUIJT7A.js.map +1 -0
  188. package/dist/chunk-P5LBT622.js +105 -0
  189. package/dist/chunk-P5LBT622.js.map +1 -0
  190. package/dist/chunk-PKGQG5QQ.js +519 -0
  191. package/dist/chunk-PKGQG5QQ.js.map +1 -0
  192. package/dist/chunk-PKPO3JTZ.js +561 -0
  193. package/dist/chunk-PKPO3JTZ.js.map +1 -0
  194. package/dist/chunk-PL5UDIQ5.js +118 -0
  195. package/dist/chunk-PL5UDIQ5.js.map +1 -0
  196. package/dist/chunk-PZWISPIQ.js +432 -0
  197. package/dist/chunk-PZWISPIQ.js.map +1 -0
  198. package/dist/chunk-Q3EYOCZB.js +510 -0
  199. package/dist/chunk-Q3EYOCZB.js.map +1 -0
  200. package/dist/chunk-QMBYUVRL.js +15 -0
  201. package/dist/chunk-QMBYUVRL.js.map +1 -0
  202. package/dist/chunk-RAGGHLCV.js +200 -0
  203. package/dist/chunk-RAGGHLCV.js.map +1 -0
  204. package/dist/chunk-RJOG4IJU.js +1039 -0
  205. package/dist/chunk-RJOG4IJU.js.map +1 -0
  206. package/dist/chunk-SOOKUYVM.js +403 -0
  207. package/dist/chunk-SOOKUYVM.js.map +1 -0
  208. package/dist/chunk-T5BN5KG7.js +1 -0
  209. package/dist/chunk-T5BN5KG7.js.map +1 -0
  210. package/dist/chunk-TNX5ZGDJ.js +574 -0
  211. package/dist/chunk-TNX5ZGDJ.js.map +1 -0
  212. package/dist/chunk-TP7244Y6.js +207 -0
  213. package/dist/chunk-TP7244Y6.js.map +1 -0
  214. package/dist/chunk-TSBFTJKM.js +57 -0
  215. package/dist/chunk-TSBFTJKM.js.map +1 -0
  216. package/dist/chunk-URQ2CBBF.js +143 -0
  217. package/dist/chunk-URQ2CBBF.js.map +1 -0
  218. package/dist/chunk-VLAGJZSL.js +1079 -0
  219. package/dist/chunk-VLAGJZSL.js.map +1 -0
  220. package/dist/chunk-W2BOPXTI.js +1 -0
  221. package/dist/chunk-W2BOPXTI.js.map +1 -0
  222. package/dist/chunk-Y52CS6YA.js +88 -0
  223. package/dist/chunk-Y52CS6YA.js.map +1 -0
  224. package/dist/chunk-YCBUWK77.js +92 -0
  225. package/dist/chunk-YCBUWK77.js.map +1 -0
  226. package/dist/chunk-YJ4U2D2C.js +314 -0
  227. package/dist/chunk-YJ4U2D2C.js.map +1 -0
  228. package/dist/chunk-Z4YXAUDN.js +239 -0
  229. package/dist/chunk-Z4YXAUDN.js.map +1 -0
  230. package/dist/chunk-Z65DVDEQ.js +146 -0
  231. package/dist/chunk-Z65DVDEQ.js.map +1 -0
  232. package/dist/chunk-Z6EGP5D7.js +92 -0
  233. package/dist/chunk-Z6EGP5D7.js.map +1 -0
  234. package/dist/chunk-ZT4WMQW4.js +1575 -0
  235. package/dist/chunk-ZT4WMQW4.js.map +1 -0
  236. package/dist/chunk-ZVXXDWIB.js +1282 -0
  237. package/dist/chunk-ZVXXDWIB.js.map +1 -0
  238. package/dist/compat/index.cjs +3150 -6
  239. package/dist/compat/index.cjs.map +1 -1
  240. package/dist/compat/index.d.cts +116 -1
  241. package/dist/compat/index.d.ts +116 -1
  242. package/dist/compat/index.js +175 -2
  243. package/dist/compat/index.js.map +1 -1
  244. package/dist/compat/jotai/index.cjs +130 -2
  245. package/dist/compat/jotai/index.cjs.map +1 -1
  246. package/dist/compat/jotai/index.d.cts +2 -1
  247. package/dist/compat/jotai/index.d.ts +2 -1
  248. package/dist/compat/jotai/index.js +7 -2
  249. package/dist/compat/jotai/index.js.map +1 -1
  250. package/dist/compat/nanostores/index.cjs +186 -2
  251. package/dist/compat/nanostores/index.cjs.map +1 -1
  252. package/dist/compat/nanostores/index.d.cts +2 -1
  253. package/dist/compat/nanostores/index.d.ts +2 -1
  254. package/dist/compat/nanostores/index.js +21 -2
  255. package/dist/compat/nanostores/index.js.map +1 -1
  256. package/dist/compat/nestjs/index.cjs +2291 -6
  257. package/dist/compat/nestjs/index.cjs.map +1 -1
  258. package/dist/compat/nestjs/index.d.cts +10 -1
  259. package/dist/compat/nestjs/index.d.ts +10 -1
  260. package/dist/compat/nestjs/index.js +76 -2
  261. package/dist/compat/nestjs/index.js.map +1 -1
  262. package/dist/compat/react/index.cjs +95 -2
  263. package/dist/compat/react/index.cjs.map +1 -1
  264. package/dist/compat/react/index.d.cts +2 -1
  265. package/dist/compat/react/index.d.ts +2 -1
  266. package/dist/compat/react/index.js +11 -2
  267. package/dist/compat/react/index.js.map +1 -1
  268. package/dist/compat/solid/index.cjs +82 -2
  269. package/dist/compat/solid/index.cjs.map +1 -1
  270. package/dist/compat/solid/index.d.cts +2 -1
  271. package/dist/compat/solid/index.d.ts +2 -1
  272. package/dist/compat/solid/index.js +11 -2
  273. package/dist/compat/solid/index.js.map +1 -1
  274. package/dist/compat/svelte/index.cjs +85 -2
  275. package/dist/compat/svelte/index.cjs.map +1 -1
  276. package/dist/compat/svelte/index.d.cts +2 -1
  277. package/dist/compat/svelte/index.d.ts +2 -1
  278. package/dist/compat/svelte/index.js +11 -2
  279. package/dist/compat/svelte/index.js.map +1 -1
  280. package/dist/compat/vue/index.cjs +100 -2
  281. package/dist/compat/vue/index.cjs.map +1 -1
  282. package/dist/compat/vue/index.d.cts +3 -1
  283. package/dist/compat/vue/index.d.ts +3 -1
  284. package/dist/compat/vue/index.js +11 -2
  285. package/dist/compat/vue/index.js.map +1 -1
  286. package/dist/compat/zustand/index.cjs +50 -2
  287. package/dist/compat/zustand/index.cjs.map +1 -1
  288. package/dist/compat/zustand/index.d.cts +2 -1
  289. package/dist/compat/zustand/index.d.ts +2 -1
  290. package/dist/compat/zustand/index.js +7 -2
  291. package/dist/compat/zustand/index.js.map +1 -1
  292. package/dist/distill-De6Rnn15.d.cts +48 -0
  293. package/dist/distill-De6Rnn15.d.ts +48 -0
  294. package/dist/external-register-CWyroXb_.d.cts +138 -0
  295. package/dist/external-register-CWyroXb_.d.ts +138 -0
  296. package/dist/fallback-Bx46zqky.d.cts +243 -0
  297. package/dist/fallback-pIWW8A2d.d.ts +243 -0
  298. package/dist/guarded-execution-BcdtxeBk.d.ts +207 -0
  299. package/dist/guarded-execution-C-3hnP6A.d.cts +207 -0
  300. package/dist/index-B6pxYJzO.d.cts +36 -0
  301. package/dist/index-B6pxYJzO.d.ts +36 -0
  302. package/dist/index-BFsng6v1.d.cts +44 -0
  303. package/dist/index-BFsng6v1.d.ts +44 -0
  304. package/dist/index-B_p8tnvf.d.cts +770 -0
  305. package/dist/index-Bg-LwEt-.d.cts +45 -0
  306. package/dist/index-Bg-LwEt-.d.ts +45 -0
  307. package/dist/index-Brp888t0.d.cts +127 -0
  308. package/dist/index-Brp888t0.d.ts +127 -0
  309. package/dist/index-CDfk6jHN.d.cts +37 -0
  310. package/dist/index-CDfk6jHN.d.ts +37 -0
  311. package/dist/index-DLAxYaN5.d.cts +169 -0
  312. package/dist/index-DLAxYaN5.d.ts +169 -0
  313. package/dist/index-DeWbQzMe.d.cts +34 -0
  314. package/dist/index-DeWbQzMe.d.ts +34 -0
  315. package/dist/index-_HDSmPyp.d.ts +770 -0
  316. package/dist/index-dX9IzPqj.d.cts +86 -0
  317. package/dist/index-dX9IzPqj.d.ts +86 -0
  318. package/dist/index.cjs +26009 -0
  319. package/dist/index.cjs.map +1 -1
  320. package/dist/index.d.cts +55 -42
  321. package/dist/index.d.ts +55 -42
  322. package/dist/index.js +849 -0
  323. package/dist/index.js.map +1 -1
  324. package/dist/layout-types-B5aiHYgk.d.cts +72 -0
  325. package/dist/layout-types-B5aiHYgk.d.ts +72 -0
  326. package/dist/memory-composers-BryDrRBX.d.cts +529 -0
  327. package/dist/memory-composers-CVQqPYEV.d.ts +529 -0
  328. package/dist/observable-B25XqCbZ.d.cts +59 -0
  329. package/dist/observable-B25XqCbZ.d.ts +59 -0
  330. package/dist/pipeline-graph-Ce47CB6Y.d.cts +145 -0
  331. package/dist/pipeline-graph-DXCwY9vG.d.ts +145 -0
  332. package/dist/presets/ai/index.cjs +4377 -0
  333. package/dist/presets/ai/index.cjs.map +1 -0
  334. package/dist/presets/ai/index.d.cts +98 -0
  335. package/dist/presets/ai/index.d.ts +98 -0
  336. package/dist/presets/ai/index.js +54 -0
  337. package/dist/presets/ai/index.js.map +1 -0
  338. package/dist/presets/harness/index.cjs +5929 -0
  339. package/dist/presets/harness/index.cjs.map +1 -0
  340. package/dist/presets/harness/index.d.cts +566 -0
  341. package/dist/presets/harness/index.d.ts +566 -0
  342. package/dist/presets/harness/index.js +71 -0
  343. package/dist/presets/harness/index.js.map +1 -0
  344. package/dist/presets/index.cjs +9782 -0
  345. package/dist/presets/index.cjs.map +1 -0
  346. package/dist/presets/index.d.cts +28 -0
  347. package/dist/presets/index.d.ts +28 -0
  348. package/dist/presets/index.js +129 -0
  349. package/dist/presets/index.js.map +1 -0
  350. package/dist/presets/inspect/index.cjs +1087 -0
  351. package/dist/presets/inspect/index.cjs.map +1 -0
  352. package/dist/presets/inspect/index.d.cts +172 -0
  353. package/dist/presets/inspect/index.d.ts +172 -0
  354. package/dist/presets/inspect/index.js +21 -0
  355. package/dist/presets/inspect/index.js.map +1 -0
  356. package/dist/presets/resilience/index.cjs +1593 -0
  357. package/dist/presets/resilience/index.cjs.map +1 -0
  358. package/dist/presets/resilience/index.d.cts +205 -0
  359. package/dist/presets/resilience/index.d.ts +205 -0
  360. package/dist/presets/resilience/index.js +18 -0
  361. package/dist/presets/resilience/index.js.map +1 -0
  362. package/dist/rate-limiter-CEALq4N1.d.ts +559 -0
  363. package/dist/rate-limiter-DpVbSYdH.d.cts +559 -0
  364. package/dist/reactive-layout-fswlBUvX.d.cts +195 -0
  365. package/dist/reactive-layout-fswlBUvX.d.ts +195 -0
  366. package/dist/retry-BDbRZ_gx.d.ts +125 -0
  367. package/dist/retry-DWuhjvsA.d.cts +125 -0
  368. package/dist/solutions/index.cjs +8200 -0
  369. package/dist/solutions/index.cjs.map +1 -0
  370. package/dist/solutions/index.d.cts +23 -0
  371. package/dist/solutions/index.d.ts +23 -0
  372. package/dist/solutions/index.js +55 -0
  373. package/dist/solutions/index.js.map +1 -0
  374. package/dist/spawnable-5mDY501F.d.cts +746 -0
  375. package/dist/spawnable-D3lR0oQu.d.ts +746 -0
  376. package/dist/status-U-rUI79b.d.cts +84 -0
  377. package/dist/status-U-rUI79b.d.ts +84 -0
  378. package/dist/timeout-U5O4ESK3.js +12 -0
  379. package/dist/timeout-U5O4ESK3.js.map +1 -0
  380. package/dist/types-BB5Lw-pB.d.cts +442 -0
  381. package/dist/types-BB5Lw-pB.d.ts +442 -0
  382. package/dist/types-CJWIMJiZ.d.ts +548 -0
  383. package/dist/types-vCq7ShIm.d.cts +548 -0
  384. package/dist/utils/ai/browser.cjs +2169 -0
  385. package/dist/utils/ai/browser.cjs.map +1 -0
  386. package/dist/utils/ai/browser.d.cts +129 -0
  387. package/dist/utils/ai/browser.d.ts +129 -0
  388. package/dist/utils/ai/browser.js +255 -0
  389. package/dist/utils/ai/browser.js.map +1 -0
  390. package/dist/utils/ai/index.cjs +8468 -0
  391. package/dist/utils/ai/index.cjs.map +1 -0
  392. package/dist/utils/ai/index.d.cts +1777 -0
  393. package/dist/utils/ai/index.d.ts +1777 -0
  394. package/dist/utils/ai/index.js +173 -0
  395. package/dist/utils/ai/index.js.map +1 -0
  396. package/dist/utils/ai/node.cjs +648 -0
  397. package/dist/utils/ai/node.cjs.map +1 -0
  398. package/dist/utils/ai/node.d.cts +57 -0
  399. package/dist/utils/ai/node.d.ts +57 -0
  400. package/dist/utils/ai/node.js +84 -0
  401. package/dist/utils/ai/node.js.map +1 -0
  402. package/dist/utils/cqrs/index.cjs +1036 -0
  403. package/dist/utils/cqrs/index.cjs.map +1 -0
  404. package/dist/utils/cqrs/index.d.cts +438 -0
  405. package/dist/utils/cqrs/index.d.ts +438 -0
  406. package/dist/utils/cqrs/index.js +18 -0
  407. package/dist/utils/cqrs/index.js.map +1 -0
  408. package/dist/utils/demo-shell/index.cjs +865 -0
  409. package/dist/utils/demo-shell/index.cjs.map +1 -0
  410. package/dist/utils/demo-shell/index.d.cts +90 -0
  411. package/dist/utils/demo-shell/index.d.ts +90 -0
  412. package/dist/utils/demo-shell/index.js +13 -0
  413. package/dist/utils/demo-shell/index.js.map +1 -0
  414. package/dist/utils/domain-templates/index.cjs +732 -0
  415. package/dist/utils/domain-templates/index.cjs.map +1 -0
  416. package/dist/utils/domain-templates/index.d.cts +214 -0
  417. package/dist/utils/domain-templates/index.d.ts +214 -0
  418. package/dist/utils/domain-templates/index.js +17 -0
  419. package/dist/utils/domain-templates/index.js.map +1 -0
  420. package/dist/utils/graphspec/index.cjs +1174 -0
  421. package/dist/utils/graphspec/index.cjs.map +1 -0
  422. package/dist/utils/graphspec/index.d.cts +449 -0
  423. package/dist/utils/graphspec/index.d.ts +449 -0
  424. package/dist/utils/graphspec/index.js +35 -0
  425. package/dist/utils/graphspec/index.js.map +1 -0
  426. package/dist/utils/harness/index.cjs +656 -0
  427. package/dist/utils/harness/index.cjs.map +1 -0
  428. package/dist/utils/harness/index.d.cts +542 -0
  429. package/dist/utils/harness/index.d.ts +542 -0
  430. package/dist/utils/harness/index.js +56 -0
  431. package/dist/utils/harness/index.js.map +1 -0
  432. package/dist/utils/index.cjs +17614 -0
  433. package/dist/utils/index.cjs.map +1 -0
  434. package/dist/utils/index.d.cts +96 -0
  435. package/dist/utils/index.d.ts +96 -0
  436. package/dist/utils/index.js +514 -0
  437. package/dist/utils/index.js.map +1 -0
  438. package/dist/utils/inspect/index.cjs +807 -0
  439. package/dist/utils/inspect/index.cjs.map +1 -0
  440. package/dist/utils/inspect/index.d.cts +123 -0
  441. package/dist/utils/inspect/index.d.ts +123 -0
  442. package/dist/utils/inspect/index.js +30 -0
  443. package/dist/utils/inspect/index.js.map +1 -0
  444. package/dist/utils/job-queue/index.cjs +717 -0
  445. package/dist/utils/job-queue/index.cjs.map +1 -0
  446. package/dist/utils/job-queue/index.d.cts +200 -0
  447. package/dist/utils/job-queue/index.d.ts +200 -0
  448. package/dist/utils/job-queue/index.js +18 -0
  449. package/dist/utils/job-queue/index.js.map +1 -0
  450. package/dist/utils/memory/index.cjs +1456 -0
  451. package/dist/utils/memory/index.cjs.map +1 -0
  452. package/dist/utils/memory/index.d.cts +660 -0
  453. package/dist/utils/memory/index.d.ts +660 -0
  454. package/dist/utils/memory/index.js +19 -0
  455. package/dist/utils/memory/index.js.map +1 -0
  456. package/dist/utils/messaging/index.cjs +666 -0
  457. package/dist/utils/messaging/index.cjs.map +1 -0
  458. package/dist/utils/messaging/index.d.cts +562 -0
  459. package/dist/utils/messaging/index.d.ts +562 -0
  460. package/dist/utils/messaging/index.js +50 -0
  461. package/dist/utils/messaging/index.js.map +1 -0
  462. package/dist/utils/orchestration/index.cjs +876 -0
  463. package/dist/utils/orchestration/index.cjs.map +1 -0
  464. package/dist/utils/orchestration/index.d.cts +233 -0
  465. package/dist/utils/orchestration/index.d.ts +233 -0
  466. package/dist/utils/orchestration/index.js +19 -0
  467. package/dist/utils/orchestration/index.js.map +1 -0
  468. package/dist/utils/process/index.cjs +743 -0
  469. package/dist/utils/process/index.cjs.map +1 -0
  470. package/dist/utils/process/index.d.cts +411 -0
  471. package/dist/utils/process/index.d.ts +411 -0
  472. package/dist/utils/process/index.js +14 -0
  473. package/dist/utils/process/index.js.map +1 -0
  474. package/dist/utils/reactive-layout/index.cjs +1607 -0
  475. package/dist/utils/reactive-layout/index.cjs.map +1 -0
  476. package/dist/utils/reactive-layout/index.d.cts +492 -0
  477. package/dist/utils/reactive-layout/index.d.ts +492 -0
  478. package/dist/utils/reactive-layout/index.js +52 -0
  479. package/dist/utils/reactive-layout/index.js.map +1 -0
  480. package/dist/utils/reduction/index.cjs +203 -0
  481. package/dist/utils/reduction/index.cjs.map +1 -0
  482. package/dist/utils/reduction/index.d.cts +102 -0
  483. package/dist/utils/reduction/index.d.ts +102 -0
  484. package/dist/utils/reduction/index.js +14 -0
  485. package/dist/utils/reduction/index.js.map +1 -0
  486. package/dist/utils/resilience/index.cjs +1617 -0
  487. package/dist/utils/resilience/index.cjs.map +1 -0
  488. package/dist/utils/resilience/index.d.cts +9 -0
  489. package/dist/utils/resilience/index.d.ts +9 -0
  490. package/dist/utils/resilience/index.js +44 -0
  491. package/dist/utils/resilience/index.js.map +1 -0
  492. package/dist/utils/surface/index.cjs +1070 -0
  493. package/dist/utils/surface/index.cjs.map +1 -0
  494. package/dist/utils/surface/index.d.cts +240 -0
  495. package/dist/utils/surface/index.d.ts +240 -0
  496. package/dist/utils/surface/index.js +30 -0
  497. package/dist/utils/surface/index.js.map +1 -0
  498. package/dist/utils/topology-view/index.cjs +620 -0
  499. package/dist/utils/topology-view/index.cjs.map +1 -0
  500. package/dist/utils/topology-view/index.d.cts +68 -0
  501. package/dist/utils/topology-view/index.d.ts +68 -0
  502. package/dist/utils/topology-view/index.js +11 -0
  503. package/dist/utils/topology-view/index.js.map +1 -0
  504. package/package.json +293 -241
  505. package/dist/core/index.cjs +0 -21
  506. package/dist/core/index.cjs.map +0 -1
  507. package/dist/core/index.d.cts +0 -1
  508. package/dist/core/index.d.ts +0 -1
  509. package/dist/core/index.js +0 -3
  510. package/dist/core/index.js.map +0 -1
  511. package/dist/extra/browser.cjs +0 -21
  512. package/dist/extra/browser.cjs.map +0 -1
  513. package/dist/extra/browser.d.cts +0 -1
  514. package/dist/extra/browser.d.ts +0 -1
  515. package/dist/extra/browser.js +0 -3
  516. package/dist/extra/browser.js.map +0 -1
  517. package/dist/extra/index.cjs +0 -21
  518. package/dist/extra/index.cjs.map +0 -1
  519. package/dist/extra/index.d.cts +0 -1
  520. package/dist/extra/index.d.ts +0 -1
  521. package/dist/extra/index.js +0 -3
  522. package/dist/extra/index.js.map +0 -1
  523. package/dist/extra/node.cjs +0 -21
  524. package/dist/extra/node.cjs.map +0 -1
  525. package/dist/extra/node.d.cts +0 -1
  526. package/dist/extra/node.d.ts +0 -1
  527. package/dist/extra/node.js +0 -3
  528. package/dist/extra/node.js.map +0 -1
  529. package/dist/extra/operators.cjs +0 -21
  530. package/dist/extra/operators.cjs.map +0 -1
  531. package/dist/extra/operators.d.cts +0 -1
  532. package/dist/extra/operators.d.ts +0 -1
  533. package/dist/extra/operators.js +0 -3
  534. package/dist/extra/operators.js.map +0 -1
  535. package/dist/extra/reactive.cjs +0 -21
  536. package/dist/extra/reactive.cjs.map +0 -1
  537. package/dist/extra/reactive.d.cts +0 -1
  538. package/dist/extra/reactive.d.ts +0 -1
  539. package/dist/extra/reactive.js +0 -3
  540. package/dist/extra/reactive.js.map +0 -1
  541. package/dist/extra/render/index.cjs +0 -21
  542. package/dist/extra/render/index.cjs.map +0 -1
  543. package/dist/extra/render/index.d.cts +0 -1
  544. package/dist/extra/render/index.d.ts +0 -1
  545. package/dist/extra/render/index.js +0 -3
  546. package/dist/extra/render/index.js.map +0 -1
  547. package/dist/extra/sources.cjs +0 -21
  548. package/dist/extra/sources.cjs.map +0 -1
  549. package/dist/extra/sources.d.cts +0 -1
  550. package/dist/extra/sources.d.ts +0 -1
  551. package/dist/extra/sources.js +0 -3
  552. package/dist/extra/sources.js.map +0 -1
  553. package/dist/extra/storage-browser.cjs +0 -21
  554. package/dist/extra/storage-browser.cjs.map +0 -1
  555. package/dist/extra/storage-browser.d.cts +0 -1
  556. package/dist/extra/storage-browser.d.ts +0 -1
  557. package/dist/extra/storage-browser.js +0 -3
  558. package/dist/extra/storage-browser.js.map +0 -1
  559. package/dist/extra/storage-core.cjs +0 -21
  560. package/dist/extra/storage-core.cjs.map +0 -1
  561. package/dist/extra/storage-core.d.cts +0 -1
  562. package/dist/extra/storage-core.d.ts +0 -1
  563. package/dist/extra/storage-core.js +0 -3
  564. package/dist/extra/storage-core.js.map +0 -1
  565. package/dist/extra/storage-node.cjs +0 -21
  566. package/dist/extra/storage-node.cjs.map +0 -1
  567. package/dist/extra/storage-node.d.cts +0 -1
  568. package/dist/extra/storage-node.d.ts +0 -1
  569. package/dist/extra/storage-node.js +0 -3
  570. package/dist/extra/storage-node.js.map +0 -1
  571. package/dist/extra/storage-tiers-browser.cjs +0 -21
  572. package/dist/extra/storage-tiers-browser.cjs.map +0 -1
  573. package/dist/extra/storage-tiers-browser.d.cts +0 -1
  574. package/dist/extra/storage-tiers-browser.d.ts +0 -1
  575. package/dist/extra/storage-tiers-browser.js +0 -3
  576. package/dist/extra/storage-tiers-browser.js.map +0 -1
  577. package/dist/extra/storage-tiers-node.cjs +0 -21
  578. package/dist/extra/storage-tiers-node.cjs.map +0 -1
  579. package/dist/extra/storage-tiers-node.d.cts +0 -1
  580. package/dist/extra/storage-tiers-node.d.ts +0 -1
  581. package/dist/extra/storage-tiers-node.js +0 -3
  582. package/dist/extra/storage-tiers-node.js.map +0 -1
  583. package/dist/extra/storage-tiers.cjs +0 -21
  584. package/dist/extra/storage-tiers.cjs.map +0 -1
  585. package/dist/extra/storage-tiers.d.cts +0 -1
  586. package/dist/extra/storage-tiers.d.ts +0 -1
  587. package/dist/extra/storage-tiers.js +0 -3
  588. package/dist/extra/storage-tiers.js.map +0 -1
  589. package/dist/extra/storage-wal.cjs +0 -21
  590. package/dist/extra/storage-wal.cjs.map +0 -1
  591. package/dist/extra/storage-wal.d.cts +0 -1
  592. package/dist/extra/storage-wal.d.ts +0 -1
  593. package/dist/extra/storage-wal.js +0 -3
  594. package/dist/extra/storage-wal.js.map +0 -1
  595. package/dist/graph/index.cjs +0 -21
  596. package/dist/graph/index.cjs.map +0 -1
  597. package/dist/graph/index.d.cts +0 -1
  598. package/dist/graph/index.d.ts +0 -1
  599. package/dist/graph/index.js +0 -3
  600. package/dist/graph/index.js.map +0 -1
  601. package/dist/patterns/ai/browser.cjs +0 -21
  602. package/dist/patterns/ai/browser.cjs.map +0 -1
  603. package/dist/patterns/ai/browser.d.cts +0 -1
  604. package/dist/patterns/ai/browser.d.ts +0 -1
  605. package/dist/patterns/ai/browser.js +0 -3
  606. package/dist/patterns/ai/browser.js.map +0 -1
  607. package/dist/patterns/ai/index.cjs +0 -21
  608. package/dist/patterns/ai/index.cjs.map +0 -1
  609. package/dist/patterns/ai/index.d.cts +0 -1
  610. package/dist/patterns/ai/index.d.ts +0 -1
  611. package/dist/patterns/ai/index.js +0 -3
  612. package/dist/patterns/ai/index.js.map +0 -1
  613. package/dist/patterns/ai/node.cjs +0 -21
  614. package/dist/patterns/ai/node.cjs.map +0 -1
  615. package/dist/patterns/ai/node.d.cts +0 -1
  616. package/dist/patterns/ai/node.d.ts +0 -1
  617. package/dist/patterns/ai/node.js +0 -3
  618. package/dist/patterns/ai/node.js.map +0 -1
  619. package/dist/patterns/cqrs/index.cjs +0 -21
  620. package/dist/patterns/cqrs/index.cjs.map +0 -1
  621. package/dist/patterns/cqrs/index.d.cts +0 -1
  622. package/dist/patterns/cqrs/index.d.ts +0 -1
  623. package/dist/patterns/cqrs/index.js +0 -3
  624. package/dist/patterns/cqrs/index.js.map +0 -1
  625. package/dist/patterns/demo-shell/index.cjs +0 -21
  626. package/dist/patterns/demo-shell/index.cjs.map +0 -1
  627. package/dist/patterns/demo-shell/index.d.cts +0 -1
  628. package/dist/patterns/demo-shell/index.d.ts +0 -1
  629. package/dist/patterns/demo-shell/index.js +0 -3
  630. package/dist/patterns/demo-shell/index.js.map +0 -1
  631. package/dist/patterns/domain-templates/index.cjs +0 -21
  632. package/dist/patterns/domain-templates/index.cjs.map +0 -1
  633. package/dist/patterns/domain-templates/index.d.cts +0 -1
  634. package/dist/patterns/domain-templates/index.d.ts +0 -1
  635. package/dist/patterns/domain-templates/index.js +0 -3
  636. package/dist/patterns/domain-templates/index.js.map +0 -1
  637. package/dist/patterns/graphspec/index.cjs +0 -21
  638. package/dist/patterns/graphspec/index.cjs.map +0 -1
  639. package/dist/patterns/graphspec/index.d.cts +0 -1
  640. package/dist/patterns/graphspec/index.d.ts +0 -1
  641. package/dist/patterns/graphspec/index.js +0 -3
  642. package/dist/patterns/graphspec/index.js.map +0 -1
  643. package/dist/patterns/harness/index.cjs +0 -21
  644. package/dist/patterns/harness/index.cjs.map +0 -1
  645. package/dist/patterns/harness/index.d.cts +0 -1
  646. package/dist/patterns/harness/index.d.ts +0 -1
  647. package/dist/patterns/harness/index.js +0 -3
  648. package/dist/patterns/harness/index.js.map +0 -1
  649. package/dist/patterns/inspect/index.cjs +0 -21
  650. package/dist/patterns/inspect/index.cjs.map +0 -1
  651. package/dist/patterns/inspect/index.d.cts +0 -1
  652. package/dist/patterns/inspect/index.d.ts +0 -1
  653. package/dist/patterns/inspect/index.js +0 -3
  654. package/dist/patterns/inspect/index.js.map +0 -1
  655. package/dist/patterns/job-queue/index.cjs +0 -21
  656. package/dist/patterns/job-queue/index.cjs.map +0 -1
  657. package/dist/patterns/job-queue/index.d.cts +0 -1
  658. package/dist/patterns/job-queue/index.d.ts +0 -1
  659. package/dist/patterns/job-queue/index.js +0 -3
  660. package/dist/patterns/job-queue/index.js.map +0 -1
  661. package/dist/patterns/memory/index.cjs +0 -21
  662. package/dist/patterns/memory/index.cjs.map +0 -1
  663. package/dist/patterns/memory/index.d.cts +0 -1
  664. package/dist/patterns/memory/index.d.ts +0 -1
  665. package/dist/patterns/memory/index.js +0 -3
  666. package/dist/patterns/memory/index.js.map +0 -1
  667. package/dist/patterns/messaging/index.cjs +0 -21
  668. package/dist/patterns/messaging/index.cjs.map +0 -1
  669. package/dist/patterns/messaging/index.d.cts +0 -1
  670. package/dist/patterns/messaging/index.d.ts +0 -1
  671. package/dist/patterns/messaging/index.js +0 -3
  672. package/dist/patterns/messaging/index.js.map +0 -1
  673. package/dist/patterns/orchestration/index.cjs +0 -21
  674. package/dist/patterns/orchestration/index.cjs.map +0 -1
  675. package/dist/patterns/orchestration/index.d.cts +0 -1
  676. package/dist/patterns/orchestration/index.d.ts +0 -1
  677. package/dist/patterns/orchestration/index.js +0 -3
  678. package/dist/patterns/orchestration/index.js.map +0 -1
  679. package/dist/patterns/process/index.cjs +0 -21
  680. package/dist/patterns/process/index.cjs.map +0 -1
  681. package/dist/patterns/process/index.d.cts +0 -1
  682. package/dist/patterns/process/index.d.ts +0 -1
  683. package/dist/patterns/process/index.js +0 -3
  684. package/dist/patterns/process/index.js.map +0 -1
  685. package/dist/patterns/reactive-layout/index.cjs +0 -21
  686. package/dist/patterns/reactive-layout/index.cjs.map +0 -1
  687. package/dist/patterns/reactive-layout/index.d.cts +0 -1
  688. package/dist/patterns/reactive-layout/index.d.ts +0 -1
  689. package/dist/patterns/reactive-layout/index.js +0 -3
  690. package/dist/patterns/reactive-layout/index.js.map +0 -1
  691. package/dist/patterns/reduction/index.cjs +0 -21
  692. package/dist/patterns/reduction/index.cjs.map +0 -1
  693. package/dist/patterns/reduction/index.d.cts +0 -1
  694. package/dist/patterns/reduction/index.d.ts +0 -1
  695. package/dist/patterns/reduction/index.js +0 -3
  696. package/dist/patterns/reduction/index.js.map +0 -1
  697. package/dist/patterns/surface/index.cjs +0 -21
  698. package/dist/patterns/surface/index.cjs.map +0 -1
  699. package/dist/patterns/surface/index.d.cts +0 -1
  700. package/dist/patterns/surface/index.d.ts +0 -1
  701. package/dist/patterns/surface/index.js +0 -3
  702. package/dist/patterns/surface/index.js.map +0 -1
  703. package/dist/patterns/topology-view/index.cjs +0 -21
  704. package/dist/patterns/topology-view/index.cjs.map +0 -1
  705. package/dist/patterns/topology-view/index.d.cts +0 -1
  706. package/dist/patterns/topology-view/index.d.ts +0 -1
  707. package/dist/patterns/topology-view/index.js +0 -3
  708. package/dist/patterns/topology-view/index.js.map +0 -1
  709. package/dist/testing/index.cjs +0 -21
  710. package/dist/testing/index.cjs.map +0 -1
  711. package/dist/testing/index.d.cts +0 -1
  712. package/dist/testing/index.d.ts +0 -1
  713. package/dist/testing/index.js +0 -3
  714. package/dist/testing/index.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/process/index.ts","../../../src/base/mutation/index.ts","../../../src/base/sources/settled.ts"],"sourcesContent":["/**\n * Process Manager pattern (Phase 7 — roadmap §4.6, Audit 3 — locked 2026-04-24).\n *\n * Reactive long-running workflow primitive over CQRS event nodes.\n * Correlates events across aggregates, tracks per-instance state, supports\n * retries with backoff, and runs compensation on failure or explicit cancel.\n *\n * ## Architecture\n *\n * - Per-instance state lives in a `Map<correlationId, TState>` closure (in-memory).\n * The `_process_<name>_started` synthetic event is dispatched per `start()`\n * for an event-sourced audit trail using `correlationId` as `aggregateId`.\n * Cross-restart state recovery is opt-in via\n * `opts.persistence.stateStorage` (kv-tier per-correlationId snapshot,\n * Tier 6.5 3.5) plus an explicit `restore()` call after construction.\n * - Watched-event subscriptions are imperative (coordinator role) — each\n * watched CQRS event type is subscribed to via `entries.subscribe(...)`.\n * These are NOT reactive node edges; the process manager is intentionally\n * a coordinator that bridges reactive CQRS events into imperative instance logic.\n * - Step execution uses `fromAny` to uniformly handle sync and async handlers.\n * - Retry delays use `setTimeout` (same sanctioned pattern as `extra/resilience.ts`\n * retry helper — this primitive is a coordinator, not a reactive pipeline stage).\n * - Timer scheduling uses `fromTimer` from `extra/sources.ts` per spec §5.8.\n * - Audit log uses `createAuditLog` per Audit 2.\n *\n * @module\n */\n\nimport {\n\tbatch,\n\tCOMPLETE,\n\tDATA,\n\tERROR,\n\ttype Messages,\n\ttype Node,\n\tnode,\n\twallClockNs,\n} from \"@graphrefly/pure-ts/core\";\nimport type {\n\tAppendLogStorageTier,\n\tKvStorageTier,\n\tReactiveLogBundle,\n} from \"@graphrefly/pure-ts/extra\";\nimport {\n\tfromAny,\n\tfromIter,\n\tfromTimer,\n\tmergeMap,\n\ttype NodeInput,\n\tvalve,\n} from \"@graphrefly/pure-ts/extra\";\nimport { Graph } from \"@graphrefly/pure-ts/graph\";\nimport {\n\ttype BaseAuditRecord,\n\tcreateAuditLog,\n\tmutate,\n\tregisterCursor,\n} from \"../../base/mutation/index.js\";\nimport type { StatusValue } from \"../../base/resilience/status.js\";\nimport { firstWhere } from \"../../base/sources/settled.js\";\nimport type { CqrsEvent, CqrsEventMap, CqrsGraph } from \"../cqrs/index.js\";\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\n/**\n * Discriminated union returned by each step handler.\n *\n * - `\"success\"` — step ran cleanly; update state, optionally emit\n * side-effect events and schedule a future synthetic event. The process\n * instance stays `\"running\"`.\n * - `\"terminate\"` — workflow complete; instance moves to `\"completed\"`.\n * Process-specific extension to the canonical outcome enum.\n * - `\"failure\"` — triggers compensation; instance moves to `\"cancelled\"` /\n * `\"errored\"`.\n *\n * Field name is `outcome` (matching `cqrs.DispatchRecord.outcome` and the\n * canonical Tier 1.6.2 / 2.3 enum). `\"success\"` and `\"failure\"` are the\n * canonical values; `\"terminate\"` is the process-specific extension for\n * \"early-return success\".\n */\nexport type ProcessStepResult<TState> =\n\t| {\n\t\t\toutcome: \"success\";\n\t\t\tstate: TState;\n\t\t\temit?: readonly { type: string; payload: unknown }[];\n\t\t\tschedule?: ProcessSchedule;\n\t }\n\t| {\n\t\t\toutcome: \"terminate\";\n\t\t\tstate: TState;\n\t\t\temit?: readonly { type: string; payload: unknown }[];\n\t\t\treason?: string;\n\t }\n\t| { outcome: \"failure\"; error: unknown };\n\n/**\n * Schedule a synthetic timer event after `afterMs` milliseconds.\n * When the timer fires, the synthetic event of `eventType` is routed to the\n * matching step (if one is registered) for this correlationId.\n */\nexport type ProcessSchedule = { afterMs: number; eventType: string };\n\n/**\n * Step handler signature.\n *\n * Receives the current instance state and the triggering CQRS event.\n * Returns a {@link ProcessStepResult} — sync value, Promise, or any\n * {@link NodeInput} consumed via `fromAny`.\n */\nexport type ProcessStep<TState, EM extends CqrsEventMap, K extends keyof EM & string> = (\n\tstate: TState,\n\tevent: CqrsEvent<EM[K]>,\n) => NodeInput<ProcessStepResult<TState>>;\n\n/**\n * Compensation handler. Runs when a step returns `outcome: \"failure\"`, throws, or\n * when `cancel(correlationId)` is called on a running instance.\n *\n * Should undo any side effects performed by prior steps (refund, cancel\n * reservation, etc.). Errors thrown inside compensate are swallowed and\n * recorded in the audit log with `status: \"errored\"` to prevent cascading\n * failure loops.\n */\nexport type ProcessCompensate<TState> = (state: TState, error: unknown) => NodeInput<void>;\n\n/**\n * Audit record for a single process instance state transition.\n *\n * Every status change (start → running → completed / errored / cancelled)\n * appends one record. `correlationId` is the stable process key.\n *\n * Extends {@link BaseAuditRecord} so records carry `t_ns` / `seq` /\n * `handlerVersion` from the cross-cutting Audit 2 schema.\n */\nexport interface ProcessInstance<TState> extends BaseAuditRecord {\n\t/** Stable correlation key that identifies this process instance. */\n\treadonly correlationId: string;\n\t/** Most-recent instance state at this transition. */\n\treadonly state: TState;\n\t/** Current lifecycle status after this transition. */\n\treadonly status: \"running\" | \"completed\" | \"errored\" | \"cancelled\";\n\t/** Wall-clock nanoseconds when `start()` was called. */\n\treadonly startedAt: number;\n\t/** Wall-clock nanoseconds of this transition. */\n\treadonly updatedAt: number;\n\t/** Handler version stamped at transition time (Audit 5). */\n\treadonly handlerVersion?: { id: string; version: string | number };\n\t/** Optional human-readable reason for cancellation. Present only on `\"cancelled\"` records produced by `cancel()`. */\n\treadonly reason?: string;\n}\n\n/**\n * Recommended `keyOf` for storage tiers keyed by correlationId (Audit 2).\n */\nexport const processInstanceKeyOf = <TState>(i: ProcessInstance<TState>): string => i.correlationId;\n\n/**\n * Per-correlationId state snapshot persisted via\n * {@link ProcessManagerOpts.persistence.stateStorage} (Tier 6.5 3.5,\n * 2026-04-29). Captures the running instance's current state plus\n * lifecycle metadata so a fresh `processManager` can resume in-flight\n * workflows after restart via {@link ProcessManagerResult.restore}.\n *\n * Terminal records (`status` ∈ `\"completed\" | \"errored\" | \"cancelled\"`)\n * are deleted from the kv tier on transition — only running instances\n * persist between restarts.\n */\nexport interface ProcessStateSnapshot<TState> {\n\treadonly correlationId: string;\n\treadonly state: TState;\n\treadonly status: \"running\" | \"completed\" | \"errored\" | \"cancelled\";\n\treadonly startedAt: number;\n\treadonly updatedAt: number;\n\treadonly handlerVersion?: { id: string; version: string | number };\n}\n\n/** Recommended `keyOf` for `KvStorageTier<ProcessStateSnapshot<...>>`. */\nexport const processStateKeyOf = <TState>(s: ProcessStateSnapshot<TState>): string =>\n\ts.correlationId;\n\n/**\n * Options for {@link processManager}.\n */\nexport interface ProcessManagerOpts<TState, EM extends CqrsEventMap> {\n\t/** Initial state value for every new process instance. */\n\treadonly initial: TState;\n\t/** CQRS event types to watch for correlation routing. */\n\treadonly watching: readonly (keyof EM & string)[];\n\t/**\n\t * Per-event-type step handlers. A step is invoked when a watched event's\n\t * `correlationId` matches a running instance and the event type is in\n\t * `steps`. Events with no matching step are silently ignored.\n\t */\n\treadonly steps: { [K in keyof EM & string]?: ProcessStep<TState, EM, K> };\n\t/**\n\t * Optional compensation handler. Runs on step `outcome: \"failure\"` / step throw\n\t * and on explicit `cancel()`. If omitted, instances fail silently with\n\t * status `\"errored\"` instead of `\"cancelled\"`.\n\t */\n\treadonly compensate?: ProcessCompensate<TState>;\n\t/**\n\t * Optional predicate called after each `\"success\"` step. When it returns\n\t * `true`, the instance is moved to `\"completed\"` immediately without\n\t * waiting for a `\"terminate\"` step result.\n\t */\n\treadonly isTerminal?: (state: TState) => boolean;\n\t/**\n\t * Maximum number of retry attempts after a step throws (not counting the\n\t * first attempt). Default: `0` (no retry — fail immediately on throw).\n\t */\n\treadonly retryMax?: number;\n\t/**\n\t * Per-retry backoff delays in milliseconds. `backoffMs[i]` is the delay\n\t * before attempt `i + 1`. If fewer entries than `retryMax`, the last entry\n\t * is repeated. Default: `[0]` (no delay).\n\t *\n\t * **Implementation note:** retry delays are implemented with `setTimeout`\n\t * (same sanctioned exception as `extra/resilience.ts`). This is a\n\t * coordinator-layer primitive — `fromTimer` would require subscribing to\n\t * an additional node per attempt, which would leak timer nodes without a\n\t * clear disposal scope.\n\t */\n\treadonly backoffMs?: readonly number[];\n\t/** Handler version tag stamped onto audit records (Audit 5). */\n\treadonly handlerVersion?: { id: string; version: string | number };\n\t/**\n\t * When `true`, do NOT auto-restore on construction. The caller must invoke\n\t * {@link ProcessManagerResult.restore} explicitly to load persisted\n\t * snapshots and arm watch dispatch.\n\t *\n\t * **Default `false`:** the factory kicks off restoration immediately so\n\t * watch dispatch arms as soon as snapshots have loaded (or instantly when\n\t * no `stateStorage` tier is configured). Until restoration completes,\n\t * watched events accumulate at the source but are valve-blocked from\n\t * reaching the per-instance step pipeline (B5 — locked 2026-05-01).\n\t */\n\treadonly deferRestore?: boolean;\n\t/**\n\t * Maximum number of concurrent `tier.load(key)` calls during restore.\n\t *\n\t * The restore pipeline streams keys from `tier.list()` through\n\t * `mergeMap`, which by default subscribes to inner sources unbounded\n\t * (parallel up to the number of keys). For storage tiers with large\n\t * persisted-instance counts (10K+), unbounded concurrency can exhaust\n\t * file handles, connection pools, or the backend's concurrent-request\n\t * budget. This option caps the in-flight load count.\n\t *\n\t * **Default `8`** (D2 lock 2026-05-01). Set higher for backends with\n\t * generous concurrency budgets; set to `Number.POSITIVE_INFINITY` for\n\t * the prior unbounded behavior.\n\t */\n\treadonly restoreConcurrency?: number;\n\t/** Optional persistence wiring (Audit 4). */\n\treadonly persistence?: {\n\t\t/**\n\t\t * Wire the per-process synthetic state event stream to append-log tiers.\n\t\t * Reuses `CqrsGraph.attachEventStorage` so events persist across restarts.\n\t\t */\n\t\teventStorage?: readonly AppendLogStorageTier<CqrsEvent>[];\n\t\t/**\n\t\t * Wire per-correlationId state snapshots to kv tiers (Tier 6.5 3.5,\n\t\t * 2026-04-29). Each `start()` and step transition writes the running\n\t\t * instance's state under its `correlationId`; terminal transitions\n\t\t * (`completed` / `errored` / `cancelled`) `delete` the key. After\n\t\t * restart, callers invoke {@link ProcessManagerResult.restore} to\n\t\t * reload running instances from the first tier.\n\t\t *\n\t\t * Uses {@link KvStorageTier} (not snapshot tier) because per-instance\n\t\t * state is N records keyed by correlationId, not a single global\n\t\t * snapshot. {@link processStateKeyOf} is the recommended `keyOf`\n\t\t * (already aligned with the kv tier's `save(key, value)` shape).\n\t\t *\n\t\t * Terminal records are NOT preserved — historical lifecycle is the\n\t\t * audit log's job. State persistence covers crash-recovery only.\n\t\t */\n\t\tstateStorage?: readonly KvStorageTier<ProcessStateSnapshot<TState>>[];\n\t};\n}\n\n/**\n * Result handle returned by {@link processManager}.\n */\nexport interface ProcessManagerResult<TState> {\n\t/**\n\t * Reactive audit log of every process instance state transition.\n\t * Every `start()`, step result, retry, cancellation, and compensation\n\t * appends a {@link ProcessInstance} record.\n\t */\n\treadonly instances: ReactiveLogBundle<ProcessInstance<TState>>;\n\t/**\n\t * Alias for {@link instances} (Audit 2 `.audit` duplication convention).\n\t */\n\treadonly audit: ReactiveLogBundle<ProcessInstance<TState>>;\n\t/**\n\t * Start a new process instance identified by `correlationId`.\n\t *\n\t * Emits a synthetic `_process_<name>_started` event into the CQRS graph\n\t * with `correlationId` as `aggregateId` so per-aggregate streams record\n\t * the process lifecycle. If the correlationId already has an active\n\t * (running) instance, this call is a no-op (idempotent).\n\t *\n\t * @param correlationId - Stable key for this workflow instance.\n\t * @param initialPayload - Optional payload carried on the start event.\n\t */\n\tstart(correlationId: string, initialPayload?: unknown): void;\n\t/**\n\t * Cancel a running instance by correlationId.\n\t *\n\t * Triggers the `compensate` handler (if configured), then marks the\n\t * instance as `\"cancelled\"`. If the instance is not running, this is\n\t * a no-op.\n\t *\n\t * @param correlationId - Instance to cancel.\n\t * @param reason - Optional human-readable reason recorded in the audit log.\n\t */\n\tcancel(correlationId: string, reason?: string): void;\n\t/**\n\t * Synchronous read of the current in-memory state for a correlationId.\n\t * Returns `undefined` if the instance does not exist or has terminated.\n\t */\n\tgetState(correlationId: string): TState | undefined;\n\t/**\n\t * Reactive lifecycle of the restore pipeline. Typed as the central\n\t * {@link StatusValue} enum (`\"pending\" | \"running\" | \"completed\" | \"errored\"`);\n\t * the process-manager restore state machine currently emits the `\"pending\"`\n\t * and `\"completed\"` literals only — `\"running\"` / `\"errored\"` reserved\n\t * for future fine-grained restore observability. Starts at `\"pending\"`,\n\t * flips to `\"completed\"` once snapshot loads complete (or immediately when\n\t * no `stateStorage` is configured). On {@link dispose}, the node receives\n\t * TEARDOWN via the standard subgraph teardown cascade — there is no\n\t * `\"disposed\"` literal; consumers detect tear-down via subscription\n\t * COMPLETE on {@link dispose}. Watched events are valve-gated on this\n\t * node: dispatch is blocked while `restoreState !== \"completed\"`.\n\t *\n\t * Exposed for observability and tests. Subscribers can compose\n\t * `derived([restoreState], …)` to build their own gates / readouts.\n\t */\n\treadonly restoreState: Node<StatusValue>;\n\t/**\n\t * Trigger restoration of running instances from the first\n\t * {@link ProcessManagerOpts.persistence.stateStorage} tier (Tier 6.5\n\t * 3.5, 2026-04-29). Loads every record in the tier reactively and\n\t * re-hydrates `instanceStates` / `activeInstances` / `startedAt` for\n\t * any record whose `status === \"running\"`. Terminal records, if any\n\t * persisted before delete fired, are silently skipped.\n\t *\n\t * **Reactive composition (B5 — locked 2026-05-01):** internally,\n\t * `tier.list()` and `tier.load()` are wrapped in `fromAny` sources\n\t * (handles sync values, Promises, async iterables, and existing Nodes\n\t * uniformly per `~/src/graphrefly/COMPOSITION-GUIDE.md` §3 source\n\t * bridging); a `mergeMap` flattens per-key load results; an `effect`\n\t * populates closure state and flips {@link restoreState} to\n\t * `\"completed\"` on the `COMPLETE` boundary. No `await` inside the\n\t * reactive interior — the single async boundary is the returned\n\t * `Promise<void>`, which resolves when {@link restoreState} transitions\n\t * to `\"completed\"` OR when {@link dispose} tears down the restore node\n\t * (in which case `firstWhere`'s COMPLETE-rejection is swallowed and\n\t * the promise resolves to `undefined`).\n\t *\n\t * Idempotent — calling twice subscribes to the same restore pipeline\n\t * and resolves on the same gate flip. No-op when no `stateStorage`\n\t * tier is configured OR the first tier lacks a `list?` method:\n\t * `restoreState` flips to `\"completed\"` immediately so watches can arm.\n\t *\n\t * **Auto-restore default.** With `deferRestore: false` (the default),\n\t * the factory invokes `restore()` once at construction so callers do\n\t * not need to remember to wire it. Pass `deferRestore: true` to\n\t * suppress auto-restore and call `restore()` manually.\n\t */\n\trestore(): Promise<void>;\n\t/**\n\t * Release all watched-event subscriptions and stop processing new events.\n\t *\n\t * After `dispose()`, subsequent `start()` and `cancel()` calls are no-ops.\n\t * In-flight async steps complete naturally; no new steps are dispatched.\n\t *\n\t * Tears down the {@link restoreState} node via the standard subgraph\n\t * teardown cascade. Any pending `restore()` Promise resolves (the\n\t * COMPLETE-rejection from `firstWhere` is swallowed at the API edge);\n\t * the watch valve closes via TEARDOWN propagation; no further dispatch\n\t * even if a `fromAny(tier.load…)` would resolve later (the per-key\n\t * load source's cleanup sets `settled = true`, dropping the late DATA).\n\t */\n\tdispose(): void;\n}\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Materialise a `NodeInput<T>` into a Promise.\n * Uses `fromAny` to normalise Node / Promise / iterable / scalar, then\n * collects the first DATA message.\n *\n * - If `input` is `null` or `undefined`, resolves immediately with `undefined`\n * (skips constructing a `fromAny` source).\n * - On COMPLETE without prior DATA, resolves with `undefined` (supports `void`\n * compensate handlers whose `NodeInput<void>` delivers COMPLETE only).\n *\n * Implementation note: `fromAny` over a scalar (e.g. `void` / `undefined`) or\n * sync iterable delivers DATA synchronously inside `n.subscribe()`, BEFORE the\n * `subscribe()` call returns. We therefore use `let unsub` (not `const`) and\n * avoid calling `unsub()` until after `subscribe()` has returned — deferring\n * the cleanup to a microtask via `Promise.resolve().then(unsub)` to sidestep\n * the Temporal Dead Zone.\n */\nfunction toPromise<T>(input: NodeInput<T>): Promise<T> {\n\t// Short-circuit: null/undefined input resolves immediately.\n\tif (input == null) return Promise.resolve(undefined as T);\n\n\tconst n = fromAny<T>(input);\n\treturn new Promise<T>((resolve, reject) => {\n\t\tlet settled = false;\n\t\t// `let` instead of `const` so that synchronous DATA delivery during\n\t\t// n.subscribe() (before the assignment completes) doesn't hit TDZ.\n\t\tlet unsub: (() => void) | undefined;\n\t\tconst cleanup = () => {\n\t\t\tif (unsub) {\n\t\t\t\tunsub();\n\t\t\t}\n\t\t};\n\t\tunsub = n.subscribe((msgs) => {\n\t\t\tif (settled) return;\n\t\t\tfor (const m of msgs) {\n\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\tsettled = true;\n\t\t\t\t\t// Defer cleanup to after the subscribe() call returns (TDZ-safe).\n\t\t\t\t\tPromise.resolve().then(cleanup);\n\t\t\t\t\tresolve(m[1] as T);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (m[0] === ERROR) {\n\t\t\t\t\tsettled = true;\n\t\t\t\t\tPromise.resolve().then(cleanup);\n\t\t\t\t\treject(m[1] as unknown);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (m[0] === COMPLETE) {\n\t\t\t\t\t// COMPLETE without prior DATA — resolve with undefined.\n\t\t\t\t\t// Supports void compensate handlers that return without emitting DATA.\n\t\t\t\t\tsettled = true;\n\t\t\t\t\tPromise.resolve().then(cleanup);\n\t\t\t\t\tresolve(undefined as T);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t});\n}\n\n/** Run `step(state, event)` with retry logic. Returns the step result. */\nasync function runWithRetry<TState>(\n\tstep: (state: TState, event: CqrsEvent) => NodeInput<ProcessStepResult<TState>>,\n\tstate: TState,\n\tevent: CqrsEvent,\n\tretryMax: number,\n\tbackoffMs: readonly number[],\n): Promise<ProcessStepResult<TState>> {\n\tlet lastError: unknown;\n\tfor (let attempt = 0; attempt <= retryMax; attempt++) {\n\t\tif (attempt > 0) {\n\t\t\t// Sanctioned setTimeout for retry backoff in coordinator primitives.\n\t\t\t// Same pattern as extra/resilience.ts retry implementation.\n\t\t\tconst delayMs = backoffMs[Math.min(attempt - 1, backoffMs.length - 1)] ?? 0;\n\t\t\tif (delayMs > 0) {\n\t\t\t\tawait new Promise<void>((r) => setTimeout(r, delayMs));\n\t\t\t}\n\t\t}\n\t\ttry {\n\t\t\tconst result = await toPromise(step(state, event));\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tlastError = err;\n\t\t\t// If we've exhausted retries, fall through to return a fail result.\n\t\t}\n\t}\n\treturn { outcome: \"failure\", error: lastError };\n}\n\n// ---------------------------------------------------------------------------\n// processManager factory\n// ---------------------------------------------------------------------------\n\n/**\n * Create a process manager that coordinates long-running reactive workflows\n * over a {@link CqrsGraph}.\n *\n * Process instances are identified by `correlationId`. Events from the watched\n * event types are routed to per-instance step handlers when the event's\n * `correlationId` matches a running instance.\n *\n * ```ts\n * const app = cqrs<{ orderPlaced: { orderId: string }; paymentReceived: { amount: number } }>(\"orders\");\n *\n * const pm = processManager(app, \"fulfillment\", {\n * initial: { step: \"awaiting-payment\", total: 0 },\n * watching: [\"orderPlaced\", \"paymentReceived\"],\n * steps: {\n * orderPlaced(state, event) {\n * return { outcome: \"success\", state: { ...state, orderId: event.payload.orderId } };\n * },\n * paymentReceived(state, event) {\n * return { outcome: \"terminate\", state: { ...state, total: event.payload.amount } };\n * },\n * },\n * compensate(state, _error) {\n * // undo reservation, issue refund, etc.\n * },\n * retryMax: 2,\n * backoffMs: [100, 500],\n * });\n *\n * pm.start(\"order-123\");\n * app.dispatch(\"orderPlaced\", { orderId: \"order-123\" }, { correlationId: \"order-123\" });\n * ```\n *\n * @param cqrsGraph - The CQRS graph whose event streams the manager watches.\n * @param name - Stable identifier for this process type; used for the\n * synthetic event-type prefix `_process_<name>_*`. Currently emits\n * `_process_<name>_started` per `start()`; the prefix is reserved for\n * future `_state` / `_timer` channels.\n * @param opts - Configuration: initial state, watched events, steps, retry,\n * compensation, and optional persistence.\n * @returns {@link ProcessManagerResult} with `instances` audit log and\n * `start`, `cancel`, `getState` imperative controls.\n *\n * @category patterns\n */\nexport function processManager<TState, EM extends CqrsEventMap = Record<string, unknown>>(\n\tcqrsGraph: CqrsGraph<EM>,\n\tname: string,\n\topts: ProcessManagerOpts<TState, EM>,\n): ProcessManagerResult<TState> {\n\tconst retryMax = opts.retryMax ?? 0;\n\tconst backoffMs: readonly number[] = opts.backoffMs ?? [0];\n\tconst retainedLimit = 1024;\n\n\t// ── Per-instance in-memory state ──────────────────────────────────────\n\t// Map from correlationId → current TState for running instances.\n\t// Imperative coordinator state — documented pattern for this primitive.\n\tconst instanceStates = new Map<string, TState>();\n\t// Track which instances are \"active\" (running) to prevent double-start\n\t// and to gate step delivery.\n\tconst activeInstances = new Set<string>();\n\t// Track startedAt per instance.\n\tconst startedAt = new Map<string, number>();\n\n\t// ── Audit log + seq cursor ────────────────────────────────────────────\n\t// EH-16 (Tier 6.5 3.3, 2026-04-29): the audit log + seq cursor are\n\t// mounted under a per-instance child Graph (`__processManagers__/<name>`)\n\t// rather than directly under `cqrsGraph._nodes`. `dispose()` then calls\n\t// `cqrsGraph.remove(...)` to unmount the subgraph cleanly via the\n\t// existing mount/removeMount lifecycle — no leaked nodes after repeated\n\t// create/dispose cycles. Pre-1.0 path-schema change: paths shift from\n\t// `${name}_process_instances` / `${name}_process_seq` (top-level) to\n\t// `__processManagers__/${name}::instances` / `::seq` (mounted).\n\tconst mountName = `__processManagers__/${name}`;\n\tconst subgraph = new Graph(name);\n\ttry {\n\t\tcqrsGraph.mount(mountName, subgraph);\n\t} catch (err) {\n\t\t// `Graph.mount` throws if the mount name is in use; surface a\n\t\t// processManager-specific message so callers see actionable context.\n\t\tconst detail = err instanceof Error ? err.message : String(err);\n\t\tthrow new Error(\n\t\t\t`processManager: name \"${name}\" is already in use on this CQRS graph ` +\n\t\t\t\t`(mount path \"${mountName}\" collides). Call .dispose() on the prior ` +\n\t\t\t\t`manager OR pick a different name before re-creating. (${detail})`,\n\t\t);\n\t}\n\n\tconst instances = createAuditLog<ProcessInstance<TState>>({\n\t\tname: \"instances\",\n\t\tretainedLimit,\n\t\tgraph: subgraph,\n\t});\n\n\t// Tier 8 γ-7-A (2026-04-28): seq cursor promoted from `let seq = 0` closure\n\t// to a `state(0)` node mounted on the per-process subgraph (visible in\n\t// `describe()` at `__processManagers__/<name>::seq`). The audit-record\n\t// stamping routes through `mutate` for centralized freeze + seq\n\t// advance + `handlerVersion` stamping + batch-frame rollback. The batch\n\t// frame closes EH-17 (re-entrancy hazard).\n\tconst seqCursor = registerCursor(subgraph, \"seq\", 0);\n\n\t// D4 (qa lock): `freeze: true` so step-handler-supplied state values\n\t// captured into audit records cannot be mutated post-record. Process\n\t// states are typically small workflow records (an order ID + a few\n\t// flags), so the `deepFreeze` tax is negligible — the safety vs. mutation\n\t// trade-off favors freeze. (The 768-dim-vector concern that motivates\n\t// `freeze: false` in memory primitives doesn't apply here.)\n\tconst appendRecord = mutate<\n\t\t[string, TState, ProcessInstance<TState>[\"status\"], string | undefined],\n\t\tvoid,\n\t\tProcessInstance<TState>\n\t>(\n\t\t// No closure-state mutation in the action — the audit-record append IS\n\t\t// the effect, performed by the framework via `onSuccessRecord`.\n\t\t() => undefined,\n\t\t{\n\t\t\tframe: \"transactional\",\n\t\t\tlog: instances,\n\t\t\tseq: seqCursor,\n\t\t\tfreeze: true,\n\t\t\t...(opts.handlerVersion !== undefined ? { handlerVersion: opts.handlerVersion } : {}),\n\t\t\tonSuccessRecord: ([correlationId, state, status, reason], _r, { t_ns, seq }) => ({\n\t\t\t\tcorrelationId,\n\t\t\t\tstate,\n\t\t\t\tstatus,\n\t\t\t\tstartedAt: startedAt.get(correlationId) ?? t_ns,\n\t\t\t\tupdatedAt: t_ns,\n\t\t\t\tt_ns,\n\t\t\t\tseq: seq ?? 0,\n\t\t\t\t...(reason !== undefined ? { reason } : {}),\n\t\t\t}),\n\t\t},\n\t);\n\n\t// ── State-snapshot persistence (Tier 6.5 3.5) ─────────────────────────\n\tconst stateStorageTiers = opts.persistence?.stateStorage ?? [];\n\n\t/**\n\t * Build the snapshot payload + iterate tiers. Returns the iterator over\n\t * tiers so the caller decides whether sync throws propagate (B4 — start\n\t * path inside mutate) or are swallowed (step path, fire-and-forget).\n\t */\n\tconst buildSnapshot = (\n\t\tcorrelationId: string,\n\t\tstatus: ProcessStateSnapshot<TState>[\"status\"],\n\t): ProcessStateSnapshot<TState> | undefined => {\n\t\tconst stateValue = instanceStates.get(correlationId);\n\t\tif (stateValue === undefined) return undefined;\n\t\treturn {\n\t\t\tcorrelationId,\n\t\t\tstate: stateValue,\n\t\t\tstatus,\n\t\t\tstartedAt: startedAt.get(correlationId) ?? wallClockNs(),\n\t\t\tupdatedAt: wallClockNs(),\n\t\t\t...(opts.handlerVersion !== undefined ? { handlerVersion: opts.handlerVersion } : {}),\n\t\t};\n\t};\n\n\t/**\n\t * Best-effort persistence (used by step transitions). Sync throws are\n\t * swallowed so persistence failures do NOT poison reactive step dispatch.\n\t * Async rejections are caught at the Promise boundary.\n\t */\n\tconst persistState = (\n\t\tcorrelationId: string,\n\t\tstatus: ProcessStateSnapshot<TState>[\"status\"],\n\t): void => {\n\t\tif (stateStorageTiers.length === 0) return;\n\t\tconst snapshot = buildSnapshot(correlationId, status);\n\t\tif (snapshot === undefined) return;\n\t\tfor (const tier of stateStorageTiers) {\n\t\t\ttry {\n\t\t\t\tconst r = tier.save(correlationId, snapshot);\n\t\t\t\t// Tier may return Promise — fire-and-forget. Storage errors\n\t\t\t\t// surface via the tier's own onError plumbing (Tier 4 storage).\n\t\t\t\tif (r != null && typeof (r as Promise<void>).then === \"function\") {\n\t\t\t\t\t(r as Promise<void>).catch(() => undefined);\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// best-effort; persistence failures don't block step execution\n\t\t\t}\n\t\t}\n\t};\n\n\t/**\n\t * Throwing variant (B4 — used inside `startInternal`'s mutate\n\t * action body so a sync-throwing tier rolls back the audit-log append +\n\t * seq cursor advance). Async rejections from `tier.save()` still cannot\n\t * unwind the synchronous batch frame — that's a known limitation of\n\t * Promise-returning storage; sync-throwing tiers (the actual D2 hazard)\n\t * are fully covered.\n\t */\n\tconst persistStateThrowing = (\n\t\tcorrelationId: string,\n\t\tstatus: ProcessStateSnapshot<TState>[\"status\"],\n\t): void => {\n\t\tif (stateStorageTiers.length === 0) return;\n\t\tconst snapshot = buildSnapshot(correlationId, status);\n\t\tif (snapshot === undefined) return;\n\t\tfor (const tier of stateStorageTiers) {\n\t\t\tconst r = tier.save(correlationId, snapshot);\n\t\t\tif (r != null && typeof (r as Promise<void>).then === \"function\") {\n\t\t\t\t(r as Promise<void>).catch(() => undefined);\n\t\t\t}\n\t\t}\n\t};\n\tconst removeState = (correlationId: string): void => {\n\t\tif (stateStorageTiers.length === 0) return;\n\t\tfor (const tier of stateStorageTiers) {\n\t\t\tif (!tier.delete) continue;\n\t\t\ttry {\n\t\t\t\tconst r = tier.delete(correlationId);\n\t\t\t\tif (r != null && typeof (r as Promise<void>).then === \"function\") {\n\t\t\t\t\t(r as Promise<void>).catch(() => undefined);\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// best-effort\n\t\t\t}\n\t\t}\n\t};\n\n\t// ── Synthetic event helpers ───────────────────────────────────────────\n\tconst startedEventType = `_process_${name}_started`;\n\n\t// Pre-register the started event stream so it appears in describe().\n\t// Side-effect events (result.emit) dispatch using their own declared event type\n\t// via _appendEvent directly — no separate state event stream needed.\n\tcqrsGraph.event(startedEventType);\n\n\t// Wire persistence: event storage for synthetic state stream.\n\tif (opts.persistence?.eventStorage) {\n\t\tcqrsGraph.attachEventStorage(opts.persistence.eventStorage);\n\t}\n\n\t// ── Compensation helper ───────────────────────────────────────────────\n\tasync function runCompensate(\n\t\tcorrelationId: string,\n\t\tstate: TState,\n\t\terror: unknown,\n\t\treason?: string,\n\t): Promise<void> {\n\t\t// Eagerly remove from active state BEFORE any await so that concurrent\n\t\t// cancel() calls or in-flight step completions that arrive while we are\n\t\t// awaiting the compensate handler find the instance already gone and\n\t\t// exit early (C1 — double-compensation race fix).\n\t\tactiveInstances.delete(correlationId);\n\t\tinstanceStates.delete(correlationId);\n\t\tstartedAt.delete(correlationId);\n\n\t\tif (opts.compensate) {\n\t\t\ttry {\n\t\t\t\tawait toPromise(opts.compensate(state, error) as NodeInput<void>);\n\t\t\t\tappendRecord(correlationId, state, \"cancelled\", reason);\n\t\t\t\tremoveState(correlationId);\n\t\t\t} catch (_compErr) {\n\t\t\t\t// Compensation itself failed — still mark as errored so instance\n\t\t\t\t// doesn't stay in limbo. Swallow error to prevent cascading.\n\t\t\t\tappendRecord(correlationId, state, \"errored\", undefined);\n\t\t\t\tremoveState(correlationId);\n\t\t\t}\n\t\t} else {\n\t\t\tappendRecord(correlationId, state, \"errored\", undefined);\n\t\t\tremoveState(correlationId);\n\t\t}\n\t}\n\n\t// ── Step result handler ───────────────────────────────────────────────\n\tasync function handleStepResult(\n\t\tcorrelationId: string,\n\t\tresult: ProcessStepResult<TState>,\n\t): Promise<void> {\n\t\tif (!activeInstances.has(correlationId)) return; // cancelled during async step\n\n\t\tif (result.outcome === \"failure\") {\n\t\t\t// Capture state before eager delete (C1 — step-fail eager-delete).\n\t\t\tconst state = instanceStates.get(correlationId) ?? opts.initial;\n\t\t\t// runCompensate handles the eager delete; the early-exit guard above\n\t\t\t// ensures we won't double-compensate for an already-inactive instance.\n\t\t\tawait runCompensate(correlationId, state, result.error);\n\t\t\treturn;\n\t\t}\n\n\t\tif (result.outcome === \"success\") {\n\t\t\tinstanceStates.set(correlationId, result.state);\n\n\t\t\t// Emit side-effect CQRS events.\n\t\t\tif (result.emit) {\n\t\t\t\tfor (const ev of result.emit) {\n\t\t\t\t\t// Dispatch via _appendEvent is internal. Use a synthetic command\n\t\t\t\t\t// channel via the public `dispatch` API by pre-registering a\n\t\t\t\t\t// passthrough command, OR emit directly via an internal event.\n\t\t\t\t\t// Strategy: use event stream directly — the process manager is\n\t\t\t\t\t// an internal coordinator allowed to call internal CQRS APIs.\n\t\t\t\t\t// We use the synthetic stateEventType to carry side-effect events\n\t\t\t\t\t// so they appear in the aggregate stream.\n\t\t\t\t\ttry {\n\t\t\t\t\t\t// Emit side-effect events using the process state event stream with\n\t\t\t\t\t\t// the correlationId as aggregateId, but use the declared event type\n\t\t\t\t\t\t// as the type field for downstream sagas/projections to react to.\n\t\t\t\t\t\t// We do this by directly dispatching into the CQRS graph via the\n\t\t\t\t\t\t// dedicated per-process synthetic event channel.\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tcqrsGraph as unknown as {\n\t\t\t\t\t\t\t\t_appendEvent(\n\t\t\t\t\t\t\t\t\tname: string,\n\t\t\t\t\t\t\t\t\tpayload: unknown,\n\t\t\t\t\t\t\t\t\textra?: { correlationId?: string; aggregateId?: string },\n\t\t\t\t\t\t\t\t): void;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t)._appendEvent(ev.type, ev.payload, {\n\t\t\t\t\t\t\tcorrelationId,\n\t\t\t\t\t\t\taggregateId: correlationId,\n\t\t\t\t\t\t});\n\t\t\t\t\t} catch (_emitErr) {\n\t\t\t\t\t\t// Non-fatal: side-effect event emission failures are not\n\t\t\t\t\t\t// step-fatal (they are fire-and-forget coordination signals).\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tappendRecord(correlationId, result.state, \"running\", undefined);\n\t\t\tpersistState(correlationId, \"running\");\n\n\t\t\t// Check isTerminal predicate.\n\t\t\tif (opts.isTerminal?.(result.state)) {\n\t\t\t\tactiveInstances.delete(correlationId);\n\t\t\t\tinstanceStates.delete(correlationId);\n\t\t\t\tstartedAt.delete(correlationId); // M3 — cleanup startedAt on isTerminal terminate\n\t\t\t\tappendRecord(correlationId, result.state, \"completed\", undefined);\n\t\t\t\tremoveState(correlationId);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Handle schedule: fire synthetic event after delay via fromTimer.\n\t\t\tif (result.schedule) {\n\t\t\t\tconst { afterMs, eventType } = result.schedule;\n\t\t\t\t// fromTimer per spec §5.8 — reactive timer source.\n\t\t\t\t// Subscribe to fire once and deliver the synthetic event.\n\t\t\t\t// M6: use `let timerUnsub` + TDZ guard to avoid referencing the\n\t\t\t\t// variable before its assignment if the callback fires synchronously.\n\t\t\t\tlet timerUnsub: (() => void) | undefined;\n\t\t\t\tconst timerNode = fromTimer(afterMs);\n\t\t\t\tconst timerCb: Parameters<typeof timerNode.subscribe>[0] = (msgs) => {\n\t\t\t\t\tfor (const m of msgs) {\n\t\t\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\t\t\t// TDZ guard: if subscribe() hasn't returned yet, defer cleanup.\n\t\t\t\t\t\t\tif (timerUnsub) {\n\t\t\t\t\t\t\t\ttimerUnsub();\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// fromTimer is async (setTimeout-backed) so this path is\n\t\t\t\t\t\t\t\t// never hit in practice, but guard for safety.\n\t\t\t\t\t\t\t\tqueueMicrotask(() => timerUnsub?.());\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (!activeInstances.has(correlationId)) return;\n\t\t\t\t\t\t\tconst currentState = instanceStates.get(correlationId);\n\t\t\t\t\t\t\tif (currentState === undefined) return;\n\t\t\t\t\t\t\tconst step = (\n\t\t\t\t\t\t\t\topts.steps as unknown as Record<string, ProcessStep<TState, EM, string>>\n\t\t\t\t\t\t\t)[eventType];\n\t\t\t\t\t\t\tif (!step) return;\n\t\t\t\t\t\t\tconst syntheticEvent: CqrsEvent = {\n\t\t\t\t\t\t\t\ttype: eventType,\n\t\t\t\t\t\t\t\t// m5: null payload (not undefined) to avoid soft §1.2 risk.\n\t\t\t\t\t\t\t\t// seq: Number.NaN — sentinel for synthetic events that do not\n\t\t\t\t\t\t\t\t// participate in cross-event ordering.\n\t\t\t\t\t\t\t\tpayload: null,\n\t\t\t\t\t\t\t\ttimestampNs: wallClockNs(),\n\t\t\t\t\t\t\t\tseq: Number.NaN,\n\t\t\t\t\t\t\t\tcorrelationId,\n\t\t\t\t\t\t\t\taggregateId: correlationId,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tdispatchStep(correlationId, step, currentState, syntheticEvent);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\ttimerUnsub = timerNode.subscribe(timerCb);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (result.outcome === \"terminate\") {\n\t\t\tinstanceStates.set(correlationId, result.state);\n\t\t\t// Emit side-effect events.\n\t\t\tif (result.emit) {\n\t\t\t\tfor (const ev of result.emit) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tcqrsGraph as unknown as {\n\t\t\t\t\t\t\t\t_appendEvent(\n\t\t\t\t\t\t\t\t\tname: string,\n\t\t\t\t\t\t\t\t\tpayload: unknown,\n\t\t\t\t\t\t\t\t\textra?: { correlationId?: string; aggregateId?: string },\n\t\t\t\t\t\t\t\t): void;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t)._appendEvent(ev.type, ev.payload, {\n\t\t\t\t\t\t\tcorrelationId,\n\t\t\t\t\t\t\taggregateId: correlationId,\n\t\t\t\t\t\t});\n\t\t\t\t\t} catch (_emitErr) {\n\t\t\t\t\t\t// non-fatal\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tactiveInstances.delete(correlationId);\n\t\t\tinstanceStates.delete(correlationId);\n\t\t\tstartedAt.delete(correlationId); // M3 — cleanup startedAt on terminate\n\t\t\tappendRecord(correlationId, result.state, \"completed\", undefined);\n\t\t\tremoveState(correlationId);\n\t\t}\n\t}\n\n\t// ── Step dispatch ─────────────────────────────────────────────────────\n\t// C2: Per-correlationId in-flight serialization map.\n\t// Multiple events for the same correlationId in one DATA wave both read the\n\t// same instanceStates snapshot if dispatched concurrently. Serializing via a\n\t// promise chain ensures the second step sees the first step's written state.\n\t// Cross-correlationId events still parallelize (separate map entries).\n\tconst inFlight = new Map<string, Promise<void>>();\n\n\tfunction dispatchStep(\n\t\tcorrelationId: string,\n\t\tstep: ProcessStep<TState, EM, string>,\n\t\t_state: TState, // C2: state is re-read inside the serialized closure; this param is kept for call-site clarity\n\t\tevent: CqrsEvent,\n\t): void {\n\t\tconst prior = inFlight.get(correlationId) ?? Promise.resolve();\n\t\tconst next = prior.then(async () => {\n\t\t\t// Re-read current state at execution time (prior steps may have updated it).\n\t\t\tconst currentState = instanceStates.get(correlationId);\n\t\t\tif (currentState === undefined) return; // instance was cancelled/terminated in prior step\n\t\t\tif (!activeInstances.has(correlationId)) return;\n\t\t\tlet result: ProcessStepResult<TState>;\n\t\t\ttry {\n\t\t\t\tresult = await runWithRetry(\n\t\t\t\t\tstep as (s: TState, e: CqrsEvent) => NodeInput<ProcessStepResult<TState>>,\n\t\t\t\t\tcurrentState,\n\t\t\t\t\tevent,\n\t\t\t\t\tretryMax,\n\t\t\t\t\tbackoffMs,\n\t\t\t\t);\n\t\t\t} catch (err) {\n\t\t\t\t// runWithRetry itself should not throw (it returns fail on exhaustion),\n\t\t\t\t// but guard against unexpected errors.\n\t\t\t\tawait runCompensate(correlationId, instanceStates.get(correlationId) ?? opts.initial, err);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait handleStepResult(correlationId, result);\n\t\t});\n\t\tinFlight.set(correlationId, next);\n\t\tnext.finally(() => {\n\t\t\tif (inFlight.get(correlationId) === next) inFlight.delete(correlationId);\n\t\t});\n\t}\n\n\t// C3: disposal flag — set true by dispose(); gates start() and cancel().\n\t// Synchronous liveness check used by start() / cancel() to avoid\n\t// reaching into the reactive layer (and to short-circuit before the\n\t// teardown cascade has propagated through restoreState).\n\tlet _disposed = false;\n\n\t// ── Restore lifecycle state (B5 — locked 2026-05-01; post-fix using\n\t// central StatusValue enum 2026-05-01) ───────────────────────────────\n\t// Reactive lifecycle node typed as the central StatusValue enum\n\t// (`\"pending\" | \"running\" | \"completed\" | \"errored\"`). Currently emits\n\t// the \"pending\" → \"completed\" subset only:\n\t// \"pending\" → constructed; restore not yet finished. Watched events\n\t// arrive at the source but are valve-blocked from\n\t// reaching step dispatch.\n\t// \"completed\" → restoration complete. Watch valve is open; events\n\t// accumulated during \"pending\" are delivered as the\n\t// latest cumulative cqrs log array; the per-watch\n\t// cursor catches up to that array in one step.\n\t// (\"running\" / \"errored\" reserved for future fine-grained restore\n\t// observability; not emitted today.)\n\t// Disposal: no \"disposed\" literal — dispose() unmounts the subgraph\n\t// which TEARDOWNs restoreState; the gateOpen valve closes via standard\n\t// cascade; pending restore() Promise resolves via the .catch at the\n\t// public API edge.\n\tconst restoreState = node<StatusValue>([], {\n\t\tinitial: \"pending\",\n\t\tname: \"restoreState\",\n\t\tdescribeKind: \"state\",\n\t});\n\tsubgraph.add(restoreState, { name: \"restoreState\" });\n\n\t// `gateOpen` is the valve control: true only while\n\t// restoreState === \"completed\". Lazy: activates when the first valve\n\t// subscribes.\n\tconst gateOpen = node<boolean>(\n\t\t[restoreState as Node],\n\t\t(data, a, ctx) => {\n\t\t\tconst batch0 = data[0];\n\t\t\tconst v = (batch0 != null && batch0.length > 0 ? batch0.at(-1) : ctx.prevData[0]) as\n\t\t\t\t| StatusValue\n\t\t\t\t| undefined;\n\t\t\ta.emit(v === \"completed\");\n\t\t},\n\t\t{ name: \"gateOpen\", describeKind: \"derived\" },\n\t);\n\tsubgraph.add(gateOpen, { name: \"gateOpen\" });\n\n\t// ── Watched event subscriptions (valve-gated) ────────────────────────\n\t// COMPOSITION-GUIDE §28 cursor pattern + valve(eventNode, gateOpen):\n\t// per watched event type, subscribe to a valve over the cqrs event\n\t// stream. While restoreState !== \"completed\", valve emits RESOLVED so\n\t// no DATA reaches the cursor — events are NOT lost; the cqrs event\n\t// log retains them. When the gate flips open, valve re-emits the\n\t// latest cumulative event array (control-only wave path inside\n\t// `valve`); the cursor processes everything from `lastCount` (still\n\t// 0 at that point) in one shot.\n\tconst watchDisposers: Array<() => void> = [];\n\n\tfor (const eventType of opts.watching) {\n\t\tconst eventNode = cqrsGraph.event(eventType as string);\n\t\tconst gated = valve(eventNode, gateOpen, { name: `gatedEvent:${eventType as string}` });\n\n\t\t// Cursor starts at 0 — pre-restore events are NOT pre-counted because\n\t\t// they may be pre-restart events that the persisted snapshot already\n\t\t// consumed. The restore pipeline's job is to seed instanceStates /\n\t\t// activeInstances; events for instances NOT in activeInstances after\n\t\t// restore drop on the floor (the per-event activeInstances.has guard).\n\t\tlet lastCount = 0;\n\n\t\tconst unsub = gated.subscribe((msgs: Messages) => {\n\t\t\tfor (const m of msgs) {\n\t\t\t\tif (m[0] !== DATA) continue;\n\t\t\t\tconst events = m[1] as readonly CqrsEvent[];\n\t\t\t\tif (events.length <= lastCount) continue;\n\t\t\t\tconst newEvents = events.slice(lastCount);\n\t\t\t\tlastCount = events.length;\n\n\t\t\t\tfor (const ev of newEvents) {\n\t\t\t\t\tconst corrId = ev.correlationId;\n\t\t\t\t\tif (corrId === undefined) continue;\n\t\t\t\t\tif (!activeInstances.has(corrId)) continue;\n\n\t\t\t\t\tconst step = (opts.steps as unknown as Record<string, ProcessStep<TState, EM, string>>)[\n\t\t\t\t\t\teventType as string\n\t\t\t\t\t];\n\t\t\t\t\tif (!step) continue;\n\n\t\t\t\t\tconst state = instanceStates.get(corrId);\n\t\t\t\t\tif (state === undefined) continue;\n\n\t\t\t\t\tdispatchStep(corrId, step, state, ev);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\twatchDisposers.push(unsub);\n\t}\n\n\t// ── Public API ────────────────────────────────────────────────────────\n\n\t// Tier 8 γ-7-A (2026-04-28): `start()` body is mutate-wrapped so the\n\t// synthetic-start-event emit + the running audit record commit in one\n\t// batch frame. If `_appendEvent` throws (e.g. event stream terminated),\n\t// mutate rolls back the in-band batch (audit append discarded, seq\n\t// cursor advance discarded) and re-throws to the caller. Pre-1.0 behavior\n\t// change vs. γ-7-B: the previous form silently swallowed `_appendEvent`\n\t// failures and still appended the running record. Per COMPOSITION-GUIDE\n\t// §35, closure mutations are NOT rolled back — so they are deferred to\n\t// after `_appendEvent` succeeds inside the action body.\n\t//\n\t// B4 (D2 — locked 2026-05-01): `persistState(...)` lives INSIDE the action\n\t// body (after the closure mutations that seed `instanceStates`) so a\n\t// sync-throwing `stateStorage` tier rolls back the in-band batch the same\n\t// way `_appendEvent` failures do — neither the audit log entry nor the\n\t// state snapshot ends up in the \"running\" record store. Per §35 the\n\t// closure mutations stay (instanceStates / activeInstances / startedAt\n\t// are already set), but the audit-log + persisted-snapshot are coherent\n\t// with each other: both absent on throw, both present on success.\n\tconst startInternal = mutate<[string, unknown], void, ProcessInstance<TState>>(\n\t\t(correlationId, initialPayload) => {\n\t\t\t// Synthetic start event first (potentially throws). Closure\n\t\t\t// mutations below only run if this call succeeds — per §35,\n\t\t\t// rollback does not undo them, so they must come after the\n\t\t\t// throwing work.\n\t\t\t(\n\t\t\t\tcqrsGraph as unknown as {\n\t\t\t\t\t_appendEvent(\n\t\t\t\t\t\tname: string,\n\t\t\t\t\t\tpayload: unknown,\n\t\t\t\t\t\textra?: { correlationId?: string; aggregateId?: string },\n\t\t\t\t\t): void;\n\t\t\t\t}\n\t\t\t)._appendEvent(startedEventType, initialPayload ?? null, {\n\t\t\t\tcorrelationId,\n\t\t\t\taggregateId: correlationId,\n\t\t\t});\n\t\t\tstartedAt.set(correlationId, wallClockNs());\n\t\t\tinstanceStates.set(correlationId, opts.initial);\n\t\t\tactiveInstances.add(correlationId);\n\t\t\t// B4: inside the rollback boundary so a sync-throwing tier\n\t\t\t// discards the audit-log append + seq cursor advance.\n\t\t\tpersistStateThrowing(correlationId, \"running\");\n\t\t},\n\t\t{\n\t\t\tframe: \"transactional\",\n\t\t\tlog: instances,\n\t\t\tseq: seqCursor,\n\t\t\tfreeze: true,\n\t\t\t...(opts.handlerVersion !== undefined ? { handlerVersion: opts.handlerVersion } : {}),\n\t\t\tonSuccessRecord: ([correlationId], _r, { t_ns, seq }) => ({\n\t\t\t\tcorrelationId,\n\t\t\t\tstate: opts.initial,\n\t\t\t\tstatus: \"running\",\n\t\t\t\tstartedAt: startedAt.get(correlationId) ?? t_ns,\n\t\t\t\tupdatedAt: t_ns,\n\t\t\t\tt_ns,\n\t\t\t\tseq: seq ?? 0,\n\t\t\t}),\n\t\t},\n\t);\n\n\t/**\n\t * Start a new process instance.\n\t *\n\t * Idempotent: if a running instance with the same `correlationId` already\n\t * exists, the call is a no-op. Also a no-op after `dispose()`.\n\t *\n\t * **Throws** if the synthetic `_process_<name>_started` event stream is\n\t * terminated (γ-7-A, 2026-04-28). The audit log is not appended in that\n\t * case — the in-band batch rolls back so the seq cursor and audit log\n\t * stay consistent with the pre-call state.\n\t */\n\tfunction start(correlationId: string, initialPayload?: unknown): void {\n\t\tif (_disposed) return;\n\t\tif (activeInstances.has(correlationId)) return;\n\t\t// B4 (D2): persistState now lives INSIDE `startInternal`'s mutate\n\t\t// action body so sync-throwing tiers roll back the audit-log entry too.\n\t\tstartInternal(correlationId, initialPayload);\n\t}\n\n\t/**\n\t * Cancel a running instance and trigger compensation.\n\t *\n\t * No-op if the instance is not currently running (or after `dispose()`).\n\t */\n\tfunction cancel(correlationId: string, reason?: string): void {\n\t\tif (_disposed) return;\n\t\tif (!activeInstances.has(correlationId)) return;\n\n\t\t// Capture state before the async compensate path.\n\t\tconst state = instanceStates.get(correlationId) ?? opts.initial;\n\t\t// Run compensation asynchronously (fire-and-forget from caller perspective).\n\t\t// C1: runCompensate does the eager activeInstances.delete before any await,\n\t\t// so concurrent calls or in-flight steps that complete concurrently find the\n\t\t// instance already removed and exit early.\n\t\t// M4: pass reason through so it lands on the audit record.\n\t\trunCompensate(\n\t\t\tcorrelationId,\n\t\t\tstate,\n\t\t\tnew Error(`cancelled: ${reason ?? \"no reason given\"}`),\n\t\t\treason,\n\t\t);\n\t}\n\n\t/**\n\t * Read the current in-memory state for a correlationId.\n\t *\n\t * Returns `undefined` if the instance does not exist or has terminated.\n\t */\n\tfunction getState(correlationId: string): TState | undefined {\n\t\treturn instanceStates.get(correlationId);\n\t}\n\n\t/**\n\t * Reactive restore pipeline (B5 — locked 2026-05-01; post-fix using\n\t * fromAny + StatusValue 2026-05-01).\n\t *\n\t * `restoreSubscription` is the single keepalive over the snapshot-load\n\t * effect. Set on first `restore()` call (or on construction when\n\t * `deferRestore !== true`). The effect:\n\t *\n\t * 1. Subscribes to `mergeMap(fromAny(tier.list()), keys =>\n\t * mergeMap(fromIter(keys), key => fromAny(tier.load(key))))` —\n\t * a fully reactive chain whose only async boundaries are the source\n\t * `fromAny` nodes (spec §5.10). `fromAny` accepts sync values,\n\t * Promises, async iterables, and existing Nodes — future-proof\n\t * against tier impls that decide to expose paginated/streaming\n\t * `list()` or batched `load()`.\n\t * 2. On each per-key load DATA, populates `instanceStates` /\n\t * `activeInstances` / `startedAt` for `status === \"running\"` records.\n\t * 3. On `COMPLETE` (all loads finished), flips `restoreState` to\n\t * `\"completed\"` — the watch valve opens, queued cqrs events become\n\t * deliverable, and any `firstWhere(restoreState …)` awaiter resolves.\n\t *\n\t * Idempotent: subsequent calls reuse the same subscription and resolve\n\t * on the same gate flip.\n\t */\n\tlet restoreSubscription: (() => void) | undefined;\n\n\tfunction startRestorePipeline(): void {\n\t\tif (restoreSubscription !== undefined) return;\n\t\tconst tier = stateStorageTiers[0];\n\t\tif (tier == null || tier.list == null || tier.load == null) {\n\t\t\t// No snapshot tier — flip immediately so watches can arm.\n\t\t\t// `restoreState` is a state node so write directly.\n\t\t\tif (!_disposed) restoreState.emit(\"completed\");\n\t\t\trestoreSubscription = () => undefined;\n\t\t\treturn;\n\t\t}\n\t\tconst tierLoad = tier.load.bind(tier);\n\t\tconst tierList = tier.list.bind(tier);\n\n\t\t// Reactive source chain. `tier.list()` and `tier.load(key)` are the\n\t\t// only async boundaries. Bridged via `fromAny`, which (post DS-13.5\n\t\t// follow-up, 2026-05-01) treats sync iterables as single DATA values\n\t\t// by default — `tier.list()`'s `readonly string[]` flows through as\n\t\t// ONE DATA carrying the whole list, not as a per-key stream. Sync\n\t\t// tier returns emit immediately at subscribe time; async tier\n\t\t// returns emit on resolve.\n\t\tconst listSource = fromAny<readonly string[]>(tierList());\n\t\tconst flattened = mergeMap(listSource, (keys: readonly string[]) => {\n\t\t\tif (keys.length === 0) {\n\t\t\t\t// fromIter([]) emits no DATA, only COMPLETE — which\n\t\t\t\t// propagates up through mergeMap so the effect sees its\n\t\t\t\t// own COMPLETE.\n\t\t\t\treturn fromIter<ProcessStateSnapshot<TState> | undefined>([]);\n\t\t\t}\n\t\t\t// Inner: per-key load via fromAny, flattened across keys.\n\t\t\t// Outer fromIter(keys) DOES want per-element emission here —\n\t\t\t// each key triggers a fresh load via mergeMap.\n\t\t\treturn mergeMap(\n\t\t\t\tfromIter(keys),\n\t\t\t\t(key: string) => fromAny(tierLoad(key)) as Node<ProcessStateSnapshot<TState> | undefined>,\n\t\t\t\t// Bound concurrent in-flight loads (D2, 2026-05-01) so a\n\t\t\t\t// large persisted-instance count doesn't exhaust file\n\t\t\t\t// handles / connection pools on the storage backend.\n\t\t\t\t{ concurrent: opts.restoreConcurrency ?? 8 },\n\t\t\t);\n\t\t});\n\n\t\t// Effect node: populate closure state on each load, flip the gate on\n\t\t// COMPLETE. Reactive — no awaits.\n\t\t//\n\t\t// Re-entrancy guard (A3, 2026-05-01): wrap the closure-mutation loop\n\t\t// + the gate flip in a single `batch()`. Without it, the synchronous\n\t\t// `restoreState.emit(\"completed\")` mid-fn-body would cascade through\n\t\t// gateOpen → valves → cqrs cursors → step dispatch BEFORE the\n\t\t// snapshot loop returns — external observers would see a half-\n\t\t// populated `instanceStates` map.\n\t\t//\n\t\t// Mid-iteration dispose hoisting (A4, 2026-05-01): the `_disposed`\n\t\t// check is hoisted to BEFORE the snapshot loop. The previous per-\n\t\t// snapshot check leaked state when `dispose()` fired between\n\t\t// snapshots N and N+1: snapshots 0..N populated `instanceStates`,\n\t\t// then dispose flipped `_disposed`, the terminalDeps branch\n\t\t// short-circuited the gate flip, and the cleanup path tore down the\n\t\t// watch valve — leaving orphan entries that subsequent `start()`\n\t\t// calls would treat as \"already active\" via `activeInstances.has`.\n\t\tconst restoreEffect = node(\n\t\t\t[flattened as Node],\n\t\t\t(data, _a, ctx) => {\n\t\t\t\tif (_disposed) return;\n\t\t\t\tconst batch0 = data[0];\n\t\t\t\tconst hasSnapshots = batch0 != null && batch0.length > 0;\n\t\t\t\tconst allDone = ctx.terminalDeps[0] === true;\n\t\t\t\tif (!hasSnapshots && !allDone) return;\n\t\t\t\tbatch(() => {\n\t\t\t\t\tif (hasSnapshots) {\n\t\t\t\t\t\tfor (const snap of batch0 as readonly (ProcessStateSnapshot<TState> | undefined)[]) {\n\t\t\t\t\t\t\tif (snap == null) continue;\n\t\t\t\t\t\t\tif (snap.status !== \"running\") continue;\n\t\t\t\t\t\t\tinstanceStates.set(snap.correlationId, snap.state);\n\t\t\t\t\t\t\tactiveInstances.add(snap.correlationId);\n\t\t\t\t\t\t\tstartedAt.set(snap.correlationId, snap.startedAt);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (allDone) restoreState.emit(\"completed\");\n\t\t\t\t});\n\t\t\t},\n\t\t\t{ name: \"restoreEffect\", describeKind: \"effect\" },\n\t\t);\n\t\tsubgraph.add(restoreEffect, { name: \"restoreEffect\" });\n\t\trestoreSubscription = restoreEffect.subscribe(() => undefined);\n\t}\n\n\t/**\n\t * Trigger restoration (idempotent) and return a Promise that resolves\n\t * when `restoreState` transitions to `\"completed\"` OR when {@link dispose}\n\t * tears down the restore node (firstWhere's COMPLETE-rejection is\n\t * swallowed at the API edge so the caller's promise settles cleanly).\n\t */\n\tfunction restore(): Promise<void> {\n\t\tstartRestorePipeline();\n\t\tif (_disposed) return Promise.resolve();\n\t\tif (restoreState.cache === \"completed\") return Promise.resolve();\n\t\t// firstWhere is the canonical reactive→Promise bridge (spec §5.10);\n\t\t// async boundary lives at the public API edge, not in the graph.\n\t\t// .catch distinguishes the COMPLETE-without-match shape (which is\n\t\t// the dispose-tears-down case — swallow + resolve undefined) from\n\t\t// any other rejection (re-throw — caller sees a real failure).\n\t\treturn firstWhere(restoreState, (s) => s === \"completed\")\n\t\t\t.then(() => undefined)\n\t\t\t.catch((err: unknown) => {\n\t\t\t\tif (err instanceof Error && err.message === \"completed without matching value\") {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t\tthrow err;\n\t\t\t});\n\t}\n\n\tfunction dispose(): void {\n\t\tif (_disposed) return;\n\t\t_disposed = true;\n\t\t// Pending `firstWhere(restoreState, ...)` awaiters (i.e. a `restore()`\n\t\t// Promise still waiting on the gate flip) settle via the framework's\n\t\t// DS-13.5.A Q16 auto-precede rule: TEARDOWN delivery on a non-terminal\n\t\t// node automatically prepends [COMPLETE] in `_frameBatch`, so sinks\n\t\t// see [[COMPLETE], [TEARDOWN]] in order. firstWhere rejects on\n\t\t// COMPLETE-without-match; the .catch in `restore()` swallows that\n\t\t// rejection and the public Promise resolves cleanly.\n\t\t// Tear down the restore pipeline keepalive. fromAny.cleanup sets\n\t\t// `settled = true`, so when the underlying tier.list/load promises\n\t\t// finally resolve, the DATA never propagates — the closure mutations\n\t\t// in `restoreEffect` are never invoked (D5 belt + suspenders).\n\t\tif (restoreSubscription) {\n\t\t\ttry {\n\t\t\t\trestoreSubscription();\n\t\t\t} catch {\n\t\t\t\t// non-fatal\n\t\t\t}\n\t\t\trestoreSubscription = undefined;\n\t\t}\n\t\t// Release all watched-event subscriptions (C3 — watchDisposers leak fix).\n\t\tfor (const unsub of watchDisposers) {\n\t\t\ttry {\n\t\t\t\tunsub();\n\t\t\t} catch (_err) {\n\t\t\t\t// non-fatal: best-effort teardown\n\t\t\t}\n\t\t}\n\t\twatchDisposers.length = 0;\n\t\t// EH-16 (Tier 6.5 3.3): unmount the per-instance subgraph so the\n\t\t// audit log + seq cursor nodes are removed from the CQRS graph and\n\t\t// don't leak across repeated create/dispose cycles. `Graph.remove`\n\t\t// fires TEARDOWN through the subtree.\n\t\ttry {\n\t\t\tcqrsGraph.remove(mountName);\n\t\t} catch (_err) {\n\t\t\t// non-fatal: best-effort teardown (e.g. cqrsGraph already destroyed)\n\t\t}\n\t}\n\n\t// Auto-restore on construction unless explicitly deferred (B5).\n\tif (opts.deferRestore !== true) {\n\t\tstartRestorePipeline();\n\t}\n\n\treturn {\n\t\tinstances,\n\t\taudit: instances,\n\t\trestoreState,\n\t\tstart,\n\t\tcancel,\n\t\tgetState,\n\t\trestore,\n\t\tdispose,\n\t};\n}\n","/**\n * Universal mutation framework (Phase 14 — DS-14 locked 2026-05-05).\n *\n * Single `mutate(act, opts)` factory replaces the prior `lightMutation` +\n * `wrapMutation` two-tier split (pre-1.0 break per Q-O2).\n *\n * Two frames:\n * - `\"inline\"` — no batch; up() runs raw. Seq bumps before action; persists\n * on throw. Hot-path-friendly for atomic single-write mutations.\n * - `\"transactional\"` — opens `batch(() => up(...))`. On throw: batch discards\n * deferred deliveries, then `down()` runs (if provided), then failure record.\n *\n * Phase-4 primitives share the same shape: imperative mutation methods +\n * closure state + reactive audit log + freeze-at-entry + rollback-on-throw.\n * This module factors out the common machinery so each primitive becomes\n * declarative wiring over typed audit records.\n */\n\nimport {\n\tbatch,\n\tDATA,\n\tDIRTY,\n\ttype Node,\n\ttype NodeGuard,\n\tnode,\n\tpolicy,\n\twallClockNs,\n} from \"@graphrefly/pure-ts/core\";\nimport {\n\ttype ReactiveLogBundle,\n\ttype ReactiveLogOptions,\n\treactiveLog,\n} from \"@graphrefly/pure-ts/extra\";\nimport { Graph } from \"@graphrefly/pure-ts/graph\";\n\n// ── tryIncrementBounded ──────────────────────────────────────────────────\n\n/**\n * Bounded increment for a self-owned counter state node.\n *\n * Reads `counter.cache`, bumps by `by` (default 1) if `cur + by <= cap`,\n * writes back. Returns `false` when the cap would be exceeded (no-op write).\n * Documented P3 exception: the counter is not a declared dep of the caller —\n * it's a private budget read+written from a single call site. This helper\n * keeps the `.cache` access in one named place so caller bodies (which may\n * be inside reactive fn execution paths) stay free of cross-node `.cache`\n * reads.\n *\n * **Safety today:**\n * 1. Single-threaded JS runner never invokes the caller concurrently.\n * 2. `counter.down` writes the cache synchronously before returning, so\n * synchronous re-entry through a downstream publish reads the\n * freshly-incremented value — no double-count.\n *\n * **Future risk:** under a free-threaded runner (PY no-GIL or hypothetical\n * concurrent TS runner), two concurrent firings could still race. Revisit\n * when that surfaces.\n *\n * @param counter - Self-owned counter Node. Caller is the sole writer.\n * @param cap - Upper bound (inclusive). Pass `Number.MAX_SAFE_INTEGER` for\n * \"effectively unbounded\" use cases (e.g. token meters).\n * @param by - Delta to add (default `1`). Must be a finite non-negative\n * number; callers should pre-validate. Overflow-safe via\n * `by > cap - cur` check rather than `cur + by >= cap`.\n */\nexport function tryIncrementBounded(counter: Node<number>, cap: number, by = 1): boolean {\n\tconst cur = (counter.cache as number | undefined) ?? 0;\n\tif (by > cap - cur) return false;\n\tcounter.down([[DIRTY], [DATA, cur + by]]);\n\treturn true;\n}\n\n// ── Audit record schema ──────────────────────────────────────────────────\n\n/** Shared base shape for every audit record. Per-primitive types extend this. */\nexport interface BaseAuditRecord {\n\treadonly t_ns: number;\n\treadonly seq?: number;\n\treadonly handlerVersion?: { id: string; version: string | number };\n}\n\n// ── Default audit guard ──────────────────────────────────────────────────\n\n/**\n * Allow `observe` and `signal`; deny external `write` on the audit log so\n * consumers can subscribe + signal-bridge but cannot inject fake records.\n */\nexport const DEFAULT_AUDIT_GUARD: NodeGuard = policy((allow, deny) => {\n\tallow(\"observe\");\n\tallow(\"signal\");\n\tdeny(\"write\");\n});\n\n// ── createAuditLog ───────────────────────────────────────────────────────\n\nexport type AuditLogOpts<R extends BaseAuditRecord> = {\n\tname: string;\n\t/** Bounded retention; default 1024 per Audit 2 / cross-cutting bounded-default policy. */\n\tretainedLimit?: number;\n\t/** Override the default audit guard. */\n\tguard?: NodeGuard;\n\t/** Mount the audit `entries` Node under this graph (and activate withLatest). */\n\tgraph?: Graph;\n\t/** Pass-through to {@link reactiveLog}. */\n\tversioning?: ReactiveLogOptions<R>[\"versioning\"];\n};\n\n/**\n * Build a reactive audit log with sane defaults: bounded retention, deny-write\n * guard, `withLatest()` companions activated. Returns the {@link ReactiveLogBundle}\n * directly — primitives expose this as `<primitive>.events` / `.decisions` /\n * `.dispatches` / `.invocations` and alias it as `.audit`.\n *\n * @category internal\n */\nexport function createAuditLog<R extends BaseAuditRecord>(\n\topts: AuditLogOpts<R>,\n): ReactiveLogBundle<R> {\n\tconst log = reactiveLog<R>([], {\n\t\tname: opts.name,\n\t\tmaxSize: opts.retainedLimit ?? 1024,\n\t\tguard: opts.guard ?? DEFAULT_AUDIT_GUARD,\n\t\t...(opts.versioning != null ? { versioning: opts.versioning } : {}),\n\t});\n\t// Lazy companion activation up-front so `bundle.lastValue` / `hasLatest`\n\t// are queryable without an explicit `withLatest()` call.\n\tlog.withLatest();\n\tif (opts.graph) {\n\t\topts.graph.add(log.entries, { name: opts.name });\n\t}\n\treturn log;\n}\n\n// ── Universal mutation factory (Phase 14 — DS-14 lock Q-O2/Q-O3) ────────\n//\n// Single `mutate(act, opts)` factory. Two frames:\n//\n// - `\"inline\"` — no batch frame; up() runs raw. Seq bumps before action;\n// persists on throw. Hot-path-friendly for atomic single-write mutations.\n//\n// - `\"transactional\"` — opens `batch(() => up(...))`. On throw: batch discards\n// deferred deliveries, then `down()` runs, then failure record persists.\n//\n// **Heuristic:** if your imperative method's body is one or two lines (mutate\n// state, emit), use `frame: \"inline\"`. If it runs a user-supplied handler or\n// has multiple steps that could leave inconsistent state mid-throw, use\n// `frame: \"transactional\"`.\n\nexport type FailureMeta = {\n\tt_ns: number;\n\tseq?: number;\n\terrorType: string;\n};\n\nexport type SuccessMeta = {\n\tt_ns: number;\n\tseq?: number;\n};\n\n/**\n * Mutation action shape. Plain function shorthand auto-wraps as `{ up: fn }`.\n *\n * - `up` — the mutation action (the \"up migration\").\n * - `down` — optional rollback for closure mutations that `batch()` can't\n * reach. Receives the SAME frozen args as `up`. Runs AFTER batch reactive\n * rollback, BEFORE the failure record. Throws inside `down` are\n * console.error'd without masking the original error. Only meaningful\n * with `frame: \"transactional\"`.\n */\nexport type MutationAct<TArgs extends readonly unknown[], TResult> = {\n\tup: (...args: TArgs) => TResult;\n\tdown?: (...args: TArgs) => void;\n};\n\nexport type MutationFrame = \"inline\" | \"transactional\";\n\nexport type MutateOpts<TArgs extends readonly unknown[], TResult, R extends BaseAuditRecord> = {\n\t/** Frame mode. `\"inline\"` = no batch; `\"transactional\"` = batch + rollback. */\n\tframe: MutationFrame;\n\t/**\n\t * Optional log to append records to. When omitted, the wrapper still\n\t * provides freeze / seq-advance / rollback-on-throw but skips record\n\t * emission — useful for primitives that want centralized mutation\n\t * semantics without a dedicated log surface (e.g. `Topic.publish`).\n\t */\n\tlog?: ReactiveLogBundle<R>;\n\t/** Build the success record from the action's args + result + meta. */\n\tonSuccessRecord?: (args: TArgs, result: TResult, meta: SuccessMeta) => R | undefined;\n\t/** Build the failure record from the args + error + meta. */\n\tonFailureRecord?: (args: TArgs, error: unknown, meta: FailureMeta) => R | undefined;\n\t/** Deep-freeze args at entry (default `true`). Opt out for hot paths. */\n\tfreeze?: boolean;\n\t/** Optional sequence cursor — auto-advanced and stamped onto records. */\n\tseq?: Node<number>;\n\t/** Optional handler version — stamped per Audit 5. */\n\thandlerVersion?: { id: string; version: string | number };\n};\n\nfunction deepFreeze<T>(value: T): T {\n\tif (value === null || typeof value !== \"object\" || Object.isFrozen(value)) return value;\n\tfor (const k of Object.keys(value as Record<string, unknown>)) {\n\t\tdeepFreeze((value as Record<string, unknown>)[k]);\n\t}\n\treturn Object.freeze(value);\n}\n\n/**\n * Universal mutation factory (Phase 14 — DS-14 Q-O2).\n *\n * Replaces the prior `lightMutation` + `wrapMutation` two-tier split.\n * Single factory with `frame: \"inline\" | \"transactional\"` discriminant.\n *\n * @param act - The mutation action. Either a plain function (auto-wrapped as\n * `{ up: fn }`) or a `{ up, down? }` object for explicit rollback.\n * @param opts - Configuration: frame, log, record builders, freeze, seq.\n * @returns A typed wrapper function with the same signature as `act.up`.\n */\nexport function mutate<TArgs extends readonly unknown[], TResult, R extends BaseAuditRecord>(\n\tact: MutationAct<TArgs, TResult> | ((...args: TArgs) => TResult),\n\topts: MutateOpts<TArgs, TResult, R>,\n): (...args: TArgs) => TResult {\n\tconst { up, down } = typeof act === \"function\" ? { up: act, down: undefined } : act;\n\tconst freeze = opts.freeze ?? true;\n\n\tif (opts.frame === \"inline\") {\n\t\treturn function wrapped(...args: TArgs): TResult {\n\t\t\tconst sealed = freeze ? (args.map(deepFreeze) as unknown as TArgs) : args;\n\t\t\tconst t_ns = wallClockNs();\n\t\t\tconst seq = opts.seq ? bumpCursor(opts.seq) : undefined;\n\t\t\ttry {\n\t\t\t\tconst result = up(...sealed);\n\t\t\t\tif (opts.log && opts.onSuccessRecord) {\n\t\t\t\t\tappendAudit<TArgs, TResult, R, SuccessMeta>(\n\t\t\t\t\t\topts.log,\n\t\t\t\t\t\topts.onSuccessRecord,\n\t\t\t\t\t\tsealed,\n\t\t\t\t\t\tresult,\n\t\t\t\t\t\t{ t_ns, seq },\n\t\t\t\t\t\topts.handlerVersion,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tif (opts.log && opts.onFailureRecord) {\n\t\t\t\t\tconst errorType = err instanceof Error ? err.name : typeof err;\n\t\t\t\t\tappendAudit<TArgs, unknown, R, FailureMeta>(\n\t\t\t\t\t\topts.log,\n\t\t\t\t\t\topts.onFailureRecord,\n\t\t\t\t\t\tsealed,\n\t\t\t\t\t\terr,\n\t\t\t\t\t\t{ t_ns, seq, errorType },\n\t\t\t\t\t\topts.handlerVersion,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t};\n\t}\n\n\t// frame === \"transactional\"\n\treturn function wrapped(...args: TArgs): TResult {\n\t\tconst sealed = freeze ? (args.map(deepFreeze) as unknown as TArgs) : args;\n\t\tconst t_ns = wallClockNs();\n\t\tlet result: TResult;\n\t\tlet captured: unknown;\n\t\tlet captureSet = false;\n\t\tlet seq: number | undefined;\n\t\ttry {\n\t\t\tbatch(() => {\n\t\t\t\tif (opts.seq) seq = bumpCursor(opts.seq);\n\t\t\t\ttry {\n\t\t\t\t\tresult = up(...sealed);\n\t\t\t\t\tif (opts.log && opts.onSuccessRecord) {\n\t\t\t\t\t\tappendAudit<TArgs, TResult, R, SuccessMeta>(\n\t\t\t\t\t\t\topts.log,\n\t\t\t\t\t\t\topts.onSuccessRecord,\n\t\t\t\t\t\t\tsealed,\n\t\t\t\t\t\t\tresult,\n\t\t\t\t\t\t\t{ t_ns, seq },\n\t\t\t\t\t\t\topts.handlerVersion,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} catch (err) {\n\t\t\t\t\tcaptured = err;\n\t\t\t\t\tcaptureSet = true;\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t});\n\t\t} catch (outerErr) {\n\t\t\t// Fire `down` AFTER batch's reactive rollback, BEFORE failure record.\n\t\t\t// Gate on `captureSet` — if the throw came from outside the inner try\n\t\t\t// (framework-level batch error before action ran), don't fire down.\n\t\t\tif (captureSet && down) {\n\t\t\t\ttry {\n\t\t\t\t\tdown(...sealed);\n\t\t\t\t} catch (downErr) {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`mutate: down hook threw — original action error preserved (${\n\t\t\t\t\t\t\tcaptured instanceof Error ? captured.name : typeof captured\n\t\t\t\t\t\t}). Down error:`,\n\t\t\t\t\t\tdownErr,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (captureSet && opts.log && opts.onFailureRecord) {\n\t\t\t\tconst errorType = captured instanceof Error ? captured.name : typeof captured;\n\t\t\t\tappendAudit<TArgs, unknown, R, FailureMeta>(\n\t\t\t\t\topts.log,\n\t\t\t\t\topts.onFailureRecord,\n\t\t\t\t\tsealed,\n\t\t\t\t\tcaptured,\n\t\t\t\t\t{ t_ns, seq, errorType },\n\t\t\t\t\topts.handlerVersion,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow captureSet ? captured : outerErr;\n\t\t}\n\t\treturn result!;\n\t};\n}\n\n/**\n * Advance a cursor node and return the new value. Emits `[DIRTY], [DATA, next]`\n * directly on the cursor — atomic outside a batch, rollback-discardable inside.\n *\n * Resets to `0` if the cursor cache is missing, non-numeric, `NaN`, or\n * non-finite (e.g. corrupted by `restore()` from a malformed snapshot, or\n * by a misbehaving codec). `??` alone would let `NaN` and `\"\"` pass through\n * and silently corrupt audit ordering downstream.\n *\n * **Silent reset diagnostic (EH-12).** When the cache holds a non-numeric\n * value at bump time, the cursor restarts at 0 and the next bump returns 1\n * — colliding with the seq stamped on the very first record after construct.\n * To make seq-monotonicity violations after a restore visible to operators,\n * the helper emits a one-shot `console.warn` per cursor instance describing\n * the offending value. The cursor is identified by a `WeakSet<Node<number>>`\n * so the warning fires exactly once per node — repeat malformed bumps stay\n * quiet to avoid log spam. Production callers wanting to suppress can swap\n * the global `console` (universal-safe code path; no Node-only API used).\n *\n * Works whether or not the cursor has any subscribers — `down` updates the\n * cache regardless, so primitives that bump before consumers attach (e.g.\n * `JobQueueGraph.enqueue`) still see a coherent sequence.\n *\n * @category internal\n */\nconst _bumpCursorWarned = new WeakSet<Node<number>>();\nexport function bumpCursor(seq: Node<number>): number {\n\tconst raw = seq.cache;\n\tconst valid = typeof raw === \"number\" && Number.isFinite(raw);\n\tif (!valid && raw !== undefined && !_bumpCursorWarned.has(seq)) {\n\t\t_bumpCursorWarned.add(seq);\n\t\tconsole.warn(\n\t\t\t`bumpCursor: cursor cache held a non-numeric value (${String(raw)}); resetting to 0. ` +\n\t\t\t\t\"Causes include: a snapshot codec round-tripping the cursor as a string / null / NaN, \" +\n\t\t\t\t\"OR a malformed initial seed (e.g. state<number>(NaN)). \" +\n\t\t\t\t\"Audit consumers may see colliding seq values after this point.\",\n\t\t);\n\t}\n\tconst cur = valid ? raw : 0;\n\tconst next = cur + 1;\n\tseq.down([[DIRTY], [DATA, next]]);\n\treturn next;\n}\n\n/**\n * Build a record via the supplied builder, stamp `handlerVersion` if present,\n * and append it to the audit log. `undefined` records are skipped (callers\n * pass an `onSuccess` / `onFailure` that returns `undefined` to opt out per\n * call).\n *\n * @category internal\n */\nexport function appendAudit<\n\tTArgs extends readonly unknown[],\n\tTValue,\n\tR extends BaseAuditRecord,\n\tM extends SuccessMeta | FailureMeta,\n>(\n\taudit: ReactiveLogBundle<R>,\n\tbuilder: (args: TArgs, value: TValue, meta: M) => R | undefined,\n\targs: TArgs,\n\tvalue: TValue,\n\tmeta: M,\n\thandlerVersion?: { id: string; version: string | number },\n): void {\n\tconst record = builder(args, value, meta);\n\tif (record === undefined) return;\n\tconst stamped = handlerVersion != null ? ({ ...record, handlerVersion } as R) : record;\n\taudit.append(stamped);\n}\n\n// ── registerCursor / registerCursorMap ───────────────────────────────────\n\n/**\n * Promote a closure counter to a state node mounted under `graph`.\n * Replaces ad-hoc `let _seq = 0` patterns with a node observable in\n * `describe()` and persistable via storage tiers.\n *\n * @category internal\n */\nexport function registerCursor(graph: Graph, name: string, initial = 0): Node<number> {\n\tconst cursor = node<number>([], { initial, name, describeKind: \"state\" });\n\tgraph.add(cursor, { name });\n\treturn cursor;\n}\n\n/**\n * Promote a closure `Map<K, number>` to N state nodes (one per key) mounted\n * under `<graph>::<name>::<key>`. Used by saga (per-event-type cursor).\n *\n * @category internal\n */\nexport function registerCursorMap<K extends string>(\n\tgraph: Graph,\n\tname: string,\n\tkeys: readonly K[],\n\tinitial = 0,\n): { readonly [P in K]: Node<number> } {\n\tconst out = {} as { [P in K]: Node<number> };\n\t// Mount cursors under a child plain-Graph so per-key node names stay flat\n\t// (path-separator `::` is reserved by Graph.add). Using `Graph` directly\n\t// rather than `graph.constructor` avoids spawning a typed subclass with\n\t// an incompatible constructor signature (e.g., CqrsGraph(name, opts)).\n\tconst sub = new Graph(name);\n\tfor (const k of keys) {\n\t\tconst cursor = node<number>([], {\n\t\t\tinitial,\n\t\t\tname: k,\n\t\t\tdescribeKind: \"state\",\n\t\t});\n\t\tsub.add(cursor, { name: k });\n\t\tout[k] = cursor;\n\t}\n\tgraph.mount(name, sub);\n\treturn out;\n}\n","/**\n * Settled/signal helpers.\n *\n * Moved from extra/sources/settled.ts during cleave A2.\n * `keepalive` is substrate — it lives at `@graphrefly/pure-ts`\n * (`packages/pure-ts/src/extra/sources/_keepalive.ts`), not here.\n */\n\n/**\n * Settled / signal helpers — boundary primitives for converting reactive\n * sources into Promise/AbortSignal endpoints.\n *\n * - {@link firstValueFrom} / {@link firstWhere} — Promise of the first\n * matching DATA.\n * - {@link awaitSettled} — composition over `firstWhere` + reactive\n * `timeout` from `extra/resilience` (lazy import to avoid a\n * resilience → sources cycle).\n * - {@link nodeSignal} — `Node<boolean>` → `AbortSignal` bridge.\n * - {@link reactiveCounter} — capped counter exposed as a `Node<number>`.\n */\n\nimport {\n\tCOMPLETE,\n\tDATA,\n\tDIRTY,\n\tERROR,\n\ttype Messages,\n\ttype Node,\n\tnode,\n} from \"@graphrefly/pure-ts/core\";\n\n/**\n * Converts the first `DATA` on `source` into a Promise; rejects on `ERROR` or `COMPLETE` without data.\n *\n * **Important:** This subscribes and waits for a **future** emission. Data that\n * has already flowed is gone and will not be seen. Call this *before* the upstream\n * emits, or use `source.cache` / `source.status` for already-cached state.\n * See COMPOSITION-GUIDE §2 (subscription ordering).\n *\n * @param source - Node to read once.\n * @returns Promise of the first value.\n *\n * @example\n * ```ts\n * import { firstValueFrom, of } from \"@graphrefly/graphrefly-ts\";\n *\n * await firstValueFrom(of(42));\n * ```\n *\n * @category extra\n */\nexport function firstValueFrom<T>(source: Node<T>): Promise<T> {\n\treturn new Promise<T>((resolve, reject) => {\n\t\tlet settled = false;\n\t\tlet shouldUnsub = false;\n\t\tlet unsub: (() => void) | undefined;\n\t\tunsub = source.subscribe((msgs) => {\n\t\t\tfor (const m of msgs) {\n\t\t\t\tif (settled) return;\n\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\tsettled = true;\n\t\t\t\t\tresolve(m[1] as T);\n\t\t\t\t\tif (unsub) {\n\t\t\t\t\t\tunsub();\n\t\t\t\t\t\tunsub = undefined;\n\t\t\t\t\t} else shouldUnsub = true;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (m[0] === ERROR) {\n\t\t\t\t\tsettled = true;\n\t\t\t\t\treject(m[1]);\n\t\t\t\t\tif (unsub) {\n\t\t\t\t\t\tunsub();\n\t\t\t\t\t\tunsub = undefined;\n\t\t\t\t\t} else shouldUnsub = true;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (m[0] === COMPLETE) {\n\t\t\t\t\tsettled = true;\n\t\t\t\t\treject(new Error(\"completed without DATA\"));\n\t\t\t\t\tif (unsub) {\n\t\t\t\t\t\tunsub();\n\t\t\t\t\t\tunsub = undefined;\n\t\t\t\t\t} else shouldUnsub = true;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tif (shouldUnsub) {\n\t\t\tunsub?.();\n\t\t\tunsub = undefined;\n\t\t}\n\t});\n}\n\n/**\n * Wait for the first DATA value from `source` that satisfies `predicate`.\n *\n * Subscribes directly and resolves on the first DATA value where\n * `predicate` returns true. Reactive, no polling. Use in tests and\n * bridging code where you need a single matching value as a Promise.\n *\n * **Important:** This only captures **future** emissions — data that has\n * already flowed through the node is gone. Call this *before* the upstream\n * emits. For already-cached values, use `source.cache` / `source.status`.\n * See COMPOSITION-GUIDE §2 (subscription ordering).\n *\n * ```ts\n * const val = await firstWhere(strategy.snapshot, snap => snap.size > 0);\n * ```\n *\n * @param source - Upstream node to observe.\n * @param predicate - Returns `true` for the value to resolve on.\n * @param opts - `{ skipCurrent?: boolean }`. When `skipCurrent: true`, any DATA\n * delivered during the synchronous `subscribe()` call (push-on-subscribe §2.2\n * replay of the cached value) is ignored — the promise resolves only on the\n * next future emission. Useful when the caller wants to await the next\n * settlement event after an imperative action (e.g. `run()` minting a new\n * runVersion, where the currently-cached value belongs to the previous run).\n *\n * @category extra\n */\nexport function firstWhere<T>(\n\tsource: Node<T>,\n\tpredicate: (value: T) => boolean,\n\topts?: { skipCurrent?: boolean; kick?: () => void },\n): Promise<T> {\n\t// Lock 3.A (Phase 13.6.B): subscribe synchronously inside the function\n\t// body — NOT inside the Promise executor. Subscribing inside the\n\t// executor would defer the subscription past any synchronous `kick()`\n\t// the caller fires after the call returns, race-losing the very wave\n\t// the caller wants to observe.\n\t//\n\t// To bridge sync-subscribe with the async Promise contract, we record\n\t// any settlement that fires *before* the Promise constructor runs, and\n\t// the executor immediately resolves/rejects with the recorded value.\n\t// Settlements after the executor runs go straight through resolve/reject.\n\ttype Pending =\n\t\t| { kind: \"data\"; value: T }\n\t\t| { kind: \"error\"; err: unknown }\n\t\t| { kind: \"complete\" };\n\tlet pending: Pending | undefined;\n\tlet resolveFn: ((value: T) => void) | undefined;\n\tlet rejectFn: ((err: unknown) => void) | undefined;\n\tlet settled = false;\n\tlet shouldUnsub = false;\n\tlet unsub: (() => void) | undefined;\n\tlet inInitialSyncPhase = opts?.skipCurrent === true;\n\n\t// QA P1: every settler short-circuits when `settled === true` so a\n\t// later settle attempt (e.g. `kick()` throwing AFTER it synchronously\n\t// fired matching DATA, OR a `[DATA matched, ERROR]` wave during\n\t// push-on-subscribe) cannot overwrite an earlier `pending` outcome.\n\t// Without this gate, a kick that races sink-callback settlement could\n\t// reject a Promise the user already has resolved-DATA for.\n\tconst settleData = (v: T): void => {\n\t\tif (settled) return;\n\t\tsettled = true;\n\t\tif (resolveFn != null) resolveFn(v);\n\t\telse pending = { kind: \"data\", value: v };\n\t};\n\tconst settleError = (err: unknown): void => {\n\t\tif (settled) return;\n\t\tsettled = true;\n\t\tif (rejectFn != null) rejectFn(err);\n\t\telse pending = { kind: \"error\", err };\n\t};\n\tconst settleComplete = (): void => {\n\t\tif (settled) return;\n\t\tsettled = true;\n\t\tconst err = new Error(\"completed without matching value\");\n\t\tif (rejectFn != null) rejectFn(err);\n\t\telse pending = { kind: \"complete\" };\n\t};\n\tconst detach = (): void => {\n\t\tif (unsub) {\n\t\t\tunsub();\n\t\t\tunsub = undefined;\n\t\t} else shouldUnsub = true;\n\t};\n\n\tconst sink: (msgs: Messages) => void = (msgs) => {\n\t\tif (settled) return;\n\t\tfor (const m of msgs) {\n\t\t\tif (settled) return;\n\t\t\t// During the initial sync phase, swallow only cached DATA\n\t\t\t// (push-on-subscribe §2.2). Terminal ERROR / COMPLETE must\n\t\t\t// still reject the promise — otherwise an already-terminated\n\t\t\t// source synchronously delivering `[[ERROR, ...]]` or\n\t\t\t// `[[COMPLETE]]` during `subscribe()` would hang forever\n\t\t\t// under `skipCurrent: true`.\n\t\t\tif (inInitialSyncPhase && m[0] === DATA) continue;\n\t\t\tif (m[0] === DATA) {\n\t\t\t\tconst v = m[1] as T;\n\t\t\t\tif (predicate(v)) {\n\t\t\t\t\tsettleData(v);\n\t\t\t\t\tdetach();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (m[0] === ERROR) {\n\t\t\t\tsettleError(m[1]);\n\t\t\t\tdetach();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (m[0] === COMPLETE) {\n\t\t\t\tsettleComplete();\n\t\t\t\tdetach();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t};\n\tunsub = source.subscribe(sink);\n\tinInitialSyncPhase = false;\n\t// Lock 3.A: fire `kick` AFTER subscribe is in place. With sync\n\t// subscribe + sync kick, the resulting wave reaches `sink` before\n\t// control returns — making subscribe-before-kick ordering structurally\n\t// impossible to misuse.\n\tif (opts?.kick != null && !settled) {\n\t\ttry {\n\t\t\topts.kick();\n\t\t} catch (err) {\n\t\t\tsettleError(err);\n\t\t\tdetach();\n\t\t}\n\t}\n\tif (shouldUnsub) {\n\t\tunsub?.();\n\t\tunsub = undefined;\n\t}\n\n\treturn new Promise<T>((resolve, reject) => {\n\t\t// If a settlement landed synchronously before the executor runs,\n\t\t// flush it through immediately.\n\t\tif (pending != null) {\n\t\t\tif (pending.kind === \"data\") resolve(pending.value);\n\t\t\telse if (pending.kind === \"error\") reject(pending.err);\n\t\t\telse reject(new Error(\"completed without matching value\"));\n\t\t\treturn;\n\t\t}\n\t\tresolveFn = resolve;\n\t\trejectFn = reject;\n\t});\n}\n\n/**\n * Await the first non-nullish DATA value from `source`, with optional\n * timeout. Composition sugar over `firstWhere` + reactive timeout.\n *\n * Designed as the CLI/boundary sink for reactive pipelines that end in a\n * nullable node (e.g. `promptNode` — per COMPOSITION-GUIDE §8, it emits\n * `null` before it settles with a real value). Replaces the common pattern\n * `firstValueFrom(filter(source, v => v != null))` with a deadline.\n *\n * - Rejects with `TimeoutError` (from `extra/resilience`) if no matching\n * value arrives within `timeoutMs`. Omit `timeoutMs` for unbounded wait.\n * - `predicate` defaults to `v => v != null`. Pass a custom predicate to\n * gate on a stronger condition (e.g. `v => typeof v === \"string\"`).\n * - Pass `skipCurrent: true` to ignore the currently-cached value delivered\n * synchronously via push-on-subscribe and resolve only on the *next*\n * matching emission. Useful after an imperative action that should produce\n * a fresh settlement (e.g. `run()` minting a new version — the stale\n * cached value from the previous run must not resolve the new caller).\n *\n * ```ts\n * const brief = await awaitSettled(briefNode, { timeoutMs: 120_000 });\n * // or with a predicate:\n * const rich = await awaitSettled(node, {\n * predicate: (v): v is MyShape => typeof v === \"object\" && v != null && \"key\" in v,\n * timeoutMs: 60_000,\n * });\n * // or after kicking off a fresh run:\n * kickOff();\n * const fresh = await awaitSettled(resultNode, { skipCurrent: true });\n * ```\n *\n * Reactive inside, sync propagation — the one async boundary is the\n * returned `Promise<T>` (spec §5.10: async belongs at sources and\n * boundaries, not in the graph).\n *\n * @param source - Upstream node to observe.\n * @param opts - `{ predicate?, timeoutMs?, skipCurrent? }`.\n * @returns Promise that resolves with the first matching value, or rejects on timeout / ERROR / COMPLETE-without-DATA.\n *\n * @category extra\n */\n// Lazy module-cache for the `withTimeout` resilience operator. The dynamic\n// import keeps `settled` free of an eager edge into the resilience family;\n// first call pays the one-shot import, subsequent calls hit cached refs.\nlet _timeoutOp: typeof import(\"../resilience/timeout.js\").withTimeout | undefined;\nlet _nsPerMs: number | undefined;\n\nexport async function awaitSettled<T>(\n\tsource: Node<T>,\n\topts?: {\n\t\tpredicate?: (value: T) => boolean;\n\t\ttimeoutMs?: number;\n\t\tskipCurrent?: boolean;\n\t\t/**\n\t\t * Lock 3.A (Phase 13.6.B): fired AFTER subscribe is in place but\n\t\t * BEFORE the helper's async boundary is exposed to the caller.\n\t\t * Subscribe-before-kick is structurally enforced — the kick's\n\t\t * synchronous wave reaches `sink` before control returns. Replaces\n\t\t * the prior load-bearing-comment pattern (M.20-load-bearing) with\n\t\t * a misuse-impossible API shape.\n\t\t *\n\t\t * Common pattern:\n\t\t * await awaitSettled(node, {\n\t\t * skipCurrent: true,\n\t\t * kick: () => producer.emit(value),\n\t\t * });\n\t\t *\n\t\t * Omit `kick` for external-trigger cases where the wave is fired\n\t\t * by code outside the helper's caller; subscribe still lands\n\t\t * synchronously inside the helper body so the next external wave\n\t\t * is not lost.\n\t\t */\n\t\tkick?: () => void;\n\t},\n): Promise<NonNullable<T>> {\n\tconst predicate = opts?.predicate ?? ((v: T) => v != null);\n\tconst skipCurrent = opts?.skipCurrent;\n\tconst kick = opts?.kick;\n\tif (opts?.timeoutMs == null || opts.timeoutMs <= 0) {\n\t\treturn (await firstWhere(source, predicate, { skipCurrent, kick })) as NonNullable<T>;\n\t}\n\t// Reactive composition: `timeout()` wraps the source as a Node that\n\t// emits ERROR(TimeoutError) on deadline. `firstWhere` then resolves on\n\t// the first matching DATA or rejects on that ERROR. One async boundary\n\t// (the returned Promise), everything inside is sync reactive.\n\tif (_timeoutOp === undefined) {\n\t\tconst [timeoutMod, backoff] = await Promise.all([\n\t\t\timport(\"../resilience/timeout.js\"),\n\t\t\timport(\"../resilience/backoff.js\"),\n\t\t]);\n\t\t_timeoutOp = timeoutMod.withTimeout;\n\t\t_nsPerMs = backoff.NS_PER_MS;\n\t}\n\tconst guarded = _timeoutOp(source, { ns: opts.timeoutMs * (_nsPerMs as number) }).node;\n\treturn (await firstWhere(guarded, predicate, { skipCurrent, kick })) as NonNullable<T>;\n}\n\n/**\n * Converts a reactive `Node<boolean>` into a browser-standard `AbortSignal`\n * that fires when the node settles on `true`. Useful for threading a reactive\n * \"cancel\" flag into any async boundary that accepts a signal (fetch, LLM SDK\n * calls, child-process APIs, timers).\n *\n * **Contract.**\n * - `signal.abort(reason)` fires exactly once, on the first DATA emission with\n * a truthy value. Subsequent emissions are ignored (AbortSignal is\n * single-shot).\n * - Null / `false` / sentinel values are ignored. Push-on-subscribe will\n * check the currently-cached value on subscribe and abort immediately if\n * it's already `true`.\n * - `reason` defaults to `\"cancelled via nodeSignal\"`; pass `opts.reason` to\n * override (`DOMException`, `Error`, or any value accepted by\n * `AbortController.abort`).\n *\n * **Lifecycle.**\n * - Returns a `{signal, dispose}` bundle. Call `dispose()` when you're done\n * with the signal (e.g. in a `finally` after the async operation completes).\n * `dispose()` unsubscribes from the node and is a no-op once the signal has\n * fired.\n * - **Memory note:** without `dispose()` the subscription keeps the reactive\n * node alive for the lifetime of the process. For bridge calls inside a\n * `switchMap` project fn, the switchMap supersede tears the inner subgraph\n * down, which is usually the right lifetime — but still call `dispose()`\n * from the caller's `finally` for clarity.\n *\n * @example\n * ```ts\n * const aborted = state(false);\n * const { signal, dispose } = nodeSignal(aborted);\n * try {\n * const resp = await adapter.invoke(msgs, { signal });\n * return resp;\n * } finally {\n * dispose();\n * }\n * ```\n *\n * @category extra\n */\nexport function nodeSignal(\n\tsource: Node<boolean>,\n\topts?: { reason?: unknown },\n): { signal: AbortSignal; dispose: () => void } {\n\tconst ctrl = new AbortController();\n\tconst reason = opts?.reason ?? new Error(\"cancelled via nodeSignal\");\n\tlet unsub: (() => void) | undefined;\n\tlet shouldUnsub = false;\n\tconst done = () => {\n\t\tif (unsub) {\n\t\t\tunsub();\n\t\t\tunsub = undefined;\n\t\t} else shouldUnsub = true;\n\t};\n\tunsub = source.subscribe((msgs) => {\n\t\tif (ctrl.signal.aborted) return;\n\t\tfor (const m of msgs) {\n\t\t\tif (m[0] === DATA && m[1] === true) {\n\t\t\t\tctrl.abort(reason);\n\t\t\t\tdone();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (m[0] === ERROR) {\n\t\t\t\t// Treat an ERROR on the abort source as a cancel signal too —\n\t\t\t\t// a broken control channel should fail closed, not leak the\n\t\t\t\t// in-flight call. Use the error as the abort reason.\n\t\t\t\tctrl.abort(m[1]);\n\t\t\t\tdone();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (m[0] === COMPLETE) {\n\t\t\t\t// Source completed without aborting — no-op. `done()` already\n\t\t\t\t// released the subscription here, so a later `dispose()` call\n\t\t\t\t// from the caller is a no-op (safe / idempotent).\n\t\t\t\tdone();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t});\n\tif (shouldUnsub) {\n\t\tunsub?.();\n\t\tunsub = undefined;\n\t}\n\treturn {\n\t\tsignal: ctrl.signal,\n\t\tdispose: () => {\n\t\t\tif (unsub) {\n\t\t\t\tunsub();\n\t\t\t\tunsub = undefined;\n\t\t\t}\n\t\t},\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// reactiveCounter\n// ---------------------------------------------------------------------------\n\n/** Bundle returned by {@link reactiveCounter}. */\nexport type ReactiveCounterBundle = {\n\t/** Reactive node holding the current count. */\n\treadonly node: Node<number>;\n\t/** Increment by 1. Returns `false` if cap would be exceeded. */\n\tincrement(): boolean;\n\t/** Current count (synchronous read). */\n\tget(): number;\n\t/** Whether the counter has reached its cap. */\n\tatCap(): boolean;\n};\n\n/**\n * Reactive counter with a cap — the building block for circuit breakers.\n *\n * Wraps a `state(0)` node with `increment()` that respects a maximum.\n * The `node` is subscribable and composable like any reactive node. When\n * the cap is reached, `increment()` returns `false`.\n *\n * ```ts\n * const retries = reactiveCounter(10);\n * retries.increment(); // true — count is now 1\n * retries.node.subscribe(...); // reactive updates\n * retries.atCap(); // false\n * ```\n *\n * @param cap - Maximum value (inclusive). 0 = no increments allowed.\n * @category extra\n */\nexport function reactiveCounter(cap: number): ReactiveCounterBundle {\n\tconst counter = node([], { initial: 0 });\n\treturn {\n\t\tnode: counter,\n\t\tincrement() {\n\t\t\tconst current = counter.cache ?? 0;\n\t\t\tif (current >= cap) return false;\n\t\t\tcounter.down([[DIRTY], [DATA, current + 1]]);\n\t\t\treturn true;\n\t\t},\n\t\tget() {\n\t\t\treturn counter.cache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