@graphrefly/ts 0.0.1 → 0.0.3

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 (333) hide show
  1. package/README.md +197 -117
  2. package/dist/actions-types-CH-XCU9O.d.cts +657 -0
  3. package/dist/actions-types-w2iPQTkv.d.ts +657 -0
  4. package/dist/adapters/index.cjs +5157 -2951
  5. package/dist/adapters/index.cjs.map +1 -1
  6. package/dist/adapters/index.d.cts +207 -70
  7. package/dist/adapters/index.d.ts +207 -70
  8. package/dist/adapters/index.js +3738 -1688
  9. package/dist/adapters/index.js.map +1 -1
  10. package/dist/adapters/nestjs/microservices.cjs +841 -0
  11. package/dist/adapters/nestjs/microservices.cjs.map +1 -0
  12. package/dist/adapters/nestjs/microservices.d.cts +45 -0
  13. package/dist/adapters/nestjs/microservices.d.ts +45 -0
  14. package/dist/adapters/nestjs/microservices.js +206 -0
  15. package/dist/adapters/nestjs/microservices.js.map +1 -0
  16. package/dist/adapters/nestjs/native.cjs +1391 -0
  17. package/dist/adapters/nestjs/native.cjs.map +1 -0
  18. package/dist/adapters/nestjs/native.d.cts +111 -0
  19. package/dist/adapters/nestjs/native.d.ts +111 -0
  20. package/dist/adapters/nestjs/native.js +577 -0
  21. package/dist/adapters/nestjs/native.js.map +1 -0
  22. package/dist/adapters/nestjs/websockets.cjs +924 -0
  23. package/dist/adapters/nestjs/websockets.cjs.map +1 -0
  24. package/dist/adapters/nestjs/websockets.d.cts +47 -0
  25. package/dist/adapters/nestjs/websockets.d.ts +47 -0
  26. package/dist/adapters/nestjs/websockets.js +286 -0
  27. package/dist/adapters/nestjs/websockets.js.map +1 -0
  28. package/dist/adapters/nestjs.cjs +1085 -0
  29. package/dist/adapters/nestjs.cjs.map +1 -0
  30. package/dist/adapters/nestjs.d.cts +385 -0
  31. package/dist/adapters/nestjs.d.ts +385 -0
  32. package/dist/adapters/nestjs.js +112 -0
  33. package/dist/adapters/nestjs.js.map +1 -0
  34. package/dist/adapters/observe-storage.d.cts +3 -3
  35. package/dist/adapters/observe-storage.d.ts +3 -3
  36. package/dist/adapters/observe-storage.js +4 -4
  37. package/dist/adapters/react.cjs.map +1 -1
  38. package/dist/adapters/react.d.cts +2 -2
  39. package/dist/adapters/react.d.ts +2 -2
  40. package/dist/adapters/react.js +1 -1
  41. package/dist/adapters/solid.cjs.map +1 -1
  42. package/dist/adapters/solid.d.cts +2 -2
  43. package/dist/adapters/solid.d.ts +2 -2
  44. package/dist/adapters/solid.js +1 -1
  45. package/dist/adapters/svelte.cjs.map +1 -1
  46. package/dist/adapters/svelte.d.cts +2 -2
  47. package/dist/adapters/svelte.d.ts +2 -2
  48. package/dist/adapters/svelte.js +1 -1
  49. package/dist/adapters/vue.cjs.map +1 -1
  50. package/dist/adapters/vue.d.cts +2 -2
  51. package/dist/adapters/vue.d.ts +2 -2
  52. package/dist/adapters/vue.js +1 -1
  53. package/dist/{agent-runtime-BesGDZcB.d.ts → agent-runtime-types-core-CKwrBDyi.d.ts} +171 -320
  54. package/dist/{agent-runtime-DZTJ3C-p.d.cts → agent-runtime-types-core-bfl4m0vM.d.cts} +171 -320
  55. package/dist/agent-runtime-types-tool-BLPV3azj.d.cts +695 -0
  56. package/dist/agent-runtime-types-tool-hwqvVqNt.d.ts +695 -0
  57. package/dist/agentic-memory-retention-CLwI76JK.d.ts +14 -0
  58. package/dist/agentic-memory-retention-Cz8GR6ie.d.cts +14 -0
  59. package/dist/{agentic-memory-DfuVZ-lY.d.cts → agentic-memory-types-JDr7MPhh.d.cts} +13 -57
  60. package/dist/{agentic-memory-BmRCvh0d.d.ts → agentic-memory-types-khYJgzKL.d.ts} +13 -57
  61. package/dist/{capability-admission-B0BzqAm5.d.cts → capability-admission-B8RNFyaZ.d.cts} +3 -3
  62. package/dist/{capability-admission-g0mn9hpq.d.ts → capability-admission-Dkw1Xz3r.d.ts} +3 -3
  63. package/dist/chunk-2KUAG2GZ.js +9693 -0
  64. package/dist/chunk-2KUAG2GZ.js.map +1 -0
  65. package/dist/{chunk-CZNV3VXM.js → chunk-3J7UPZL5.js} +11 -11
  66. package/dist/{chunk-HKK2JD7Z.js → chunk-3LYI6ADX.js} +12 -125
  67. package/dist/chunk-3LYI6ADX.js.map +1 -0
  68. package/dist/{chunk-YXMZ2N6J.js → chunk-4M37FH2I.js} +1071 -1025
  69. package/dist/chunk-4M37FH2I.js.map +1 -0
  70. package/dist/{chunk-YDSIVHRR.js → chunk-4NWSNI4K.js} +1598 -1584
  71. package/dist/chunk-4NWSNI4K.js.map +1 -0
  72. package/dist/{chunk-Z2ANQ6JW.js → chunk-4Q77MMJY.js} +2 -2
  73. package/dist/{chunk-SS2A464I.js → chunk-54WPEODM.js} +3 -3
  74. package/dist/chunk-54WPEODM.js.map +1 -0
  75. package/dist/chunk-6E76H4OU.js +132 -0
  76. package/dist/chunk-6E76H4OU.js.map +1 -0
  77. package/dist/chunk-7GOTIIQ7.js +819 -0
  78. package/dist/chunk-7GOTIIQ7.js.map +1 -0
  79. package/dist/{chunk-V7CIJE4B.js → chunk-DKFWDTVY.js} +92 -9
  80. package/dist/chunk-DKFWDTVY.js.map +1 -0
  81. package/dist/{chunk-FBUU43PM.js → chunk-E4QCH32M.js} +448 -446
  82. package/dist/chunk-E4QCH32M.js.map +1 -0
  83. package/dist/{chunk-XKXWK2KP.js → chunk-GXU6WFEJ.js} +1157 -1021
  84. package/dist/chunk-GXU6WFEJ.js.map +1 -0
  85. package/dist/{chunk-K3FXTC3I.js → chunk-HJACH5PU.js} +3 -3
  86. package/dist/{chunk-GTPCOEOZ.js → chunk-IDMLXLLG.js} +3 -3
  87. package/dist/{chunk-DKP56CSW.js → chunk-JKAYLDQV.js} +2 -2
  88. package/dist/{chunk-4VLAQHZI.js → chunk-K7FB3JTD.js} +17 -1
  89. package/dist/chunk-K7FB3JTD.js.map +1 -0
  90. package/dist/{chunk-43BKLFZU.js → chunk-KFURM6FM.js} +10 -10
  91. package/dist/{chunk-H75VXTGT.js → chunk-L6LDXRWE.js} +3 -3
  92. package/dist/{chunk-H75VXTGT.js.map → chunk-L6LDXRWE.js.map} +1 -1
  93. package/dist/chunk-MCOFHMUU.js +4131 -0
  94. package/dist/chunk-MCOFHMUU.js.map +1 -0
  95. package/dist/chunk-MQEQMS7B.js +1009 -0
  96. package/dist/chunk-MQEQMS7B.js.map +1 -0
  97. package/dist/chunk-MTELVIYR.js +1421 -0
  98. package/dist/chunk-MTELVIYR.js.map +1 -0
  99. package/dist/{chunk-3JR3EDB2.js → chunk-NNDIFUKX.js} +121 -115
  100. package/dist/chunk-NNDIFUKX.js.map +1 -0
  101. package/dist/{chunk-2747WN4Y.js → chunk-PUSRRALM.js} +3 -3
  102. package/dist/{chunk-QFY4AFY4.js → chunk-PVC7WDKI.js} +58 -52
  103. package/dist/chunk-PVC7WDKI.js.map +1 -0
  104. package/dist/{chunk-VTHLCFN4.js → chunk-RAHNUYA5.js} +2 -2
  105. package/dist/chunk-TQPCAIQI.js +612 -0
  106. package/dist/chunk-TQPCAIQI.js.map +1 -0
  107. package/dist/{chunk-IXZBUWSP.js → chunk-UEMN5URK.js} +2 -2
  108. package/dist/chunk-WOS7RJYZ.js +1320 -0
  109. package/dist/chunk-WOS7RJYZ.js.map +1 -0
  110. package/dist/{chunk-6PHB5CJS.js → chunk-ZLFRB6FI.js} +2 -2
  111. package/dist/composition/index.cjs +1228 -1076
  112. package/dist/composition/index.cjs.map +1 -1
  113. package/dist/composition/index.d.cts +3 -3
  114. package/dist/composition/index.d.ts +3 -3
  115. package/dist/composition/index.js +4 -4
  116. package/dist/core/index.cjs +1198 -1046
  117. package/dist/core/index.cjs.map +1 -1
  118. package/dist/core/index.d.cts +23 -2
  119. package/dist/core/index.d.ts +23 -2
  120. package/dist/core/index.js +2 -2
  121. package/dist/cqrs/index.d.cts +3 -3
  122. package/dist/cqrs/index.d.ts +3 -3
  123. package/dist/cqrs/messaging.d.cts +4 -4
  124. package/dist/cqrs/messaging.d.ts +4 -4
  125. package/dist/cqrs/work-queue.d.cts +5 -5
  126. package/dist/cqrs/work-queue.d.ts +5 -5
  127. package/dist/data-structures/index.cjs +1226 -1074
  128. package/dist/data-structures/index.cjs.map +1 -1
  129. package/dist/data-structures/index.d.cts +8 -7
  130. package/dist/data-structures/index.d.ts +8 -7
  131. package/dist/data-structures/index.js +6 -5
  132. package/dist/{describe-DYMw_l1C.d.cts → describe-BumQ-3_0.d.cts} +1 -1
  133. package/dist/{describe-BpyJuWkw.d.ts → describe-cYr_Z5zm.d.ts} +1 -1
  134. package/dist/executors/tool-provider-adapters.cjs +3091 -0
  135. package/dist/executors/tool-provider-adapters.cjs.map +1 -0
  136. package/dist/executors/tool-provider-adapters.d.cts +174 -0
  137. package/dist/executors/tool-provider-adapters.d.ts +174 -0
  138. package/dist/executors/tool-provider-adapters.js +1336 -0
  139. package/dist/executors/tool-provider-adapters.js.map +1 -0
  140. package/dist/executors/tool-provider-runtime.cjs +5178 -0
  141. package/dist/executors/tool-provider-runtime.cjs.map +1 -0
  142. package/dist/executors/tool-provider-runtime.d.cts +17 -0
  143. package/dist/executors/tool-provider-runtime.d.ts +17 -0
  144. package/dist/executors/tool-provider-runtime.js +15 -0
  145. package/dist/executors/tool-provider-runtime.js.map +1 -0
  146. package/dist/executors/tool-provider.cjs +6392 -0
  147. package/dist/executors/tool-provider.cjs.map +1 -0
  148. package/dist/executors/tool-provider.d.cts +60 -0
  149. package/dist/executors/tool-provider.d.ts +60 -0
  150. package/dist/executors/tool-provider.js +89 -0
  151. package/dist/executors/tool-provider.js.map +1 -0
  152. package/dist/executors/work-queue.d.cts +6 -6
  153. package/dist/executors/work-queue.d.ts +6 -6
  154. package/dist/graph/index.cjs +1499 -1341
  155. package/dist/graph/index.cjs.map +1 -1
  156. package/dist/graph/index.d.cts +9 -8
  157. package/dist/graph/index.d.ts +9 -8
  158. package/dist/graph/index.js +23 -22
  159. package/dist/{graph-DCEWh4T2.d.cts → graph-C1C-wb0L.d.cts} +266 -137
  160. package/dist/{graph-D-1-SQeC.d.ts → graph-CS0b4V9B.d.ts} +266 -137
  161. package/dist/{index-72VZC0-E.d.cts → index-DLrNopda.d.cts} +151 -10
  162. package/dist/{index-Bmxeu0nK.d.ts → index-DzJni3_6.d.ts} +151 -10
  163. package/dist/index.cjs +3397 -3140
  164. package/dist/index.cjs.map +1 -1
  165. package/dist/index.d.cts +12 -9
  166. package/dist/index.d.ts +12 -9
  167. package/dist/index.js +110 -109
  168. package/dist/inspection/boundary.d.cts +4 -4
  169. package/dist/inspection/boundary.d.ts +4 -4
  170. package/dist/measurements-BWAnochv.d.ts +294 -0
  171. package/dist/measurements-B_gJfD8h.d.cts +294 -0
  172. package/dist/messaging/index.cjs +57 -51
  173. package/dist/messaging/index.cjs.map +1 -1
  174. package/dist/messaging/index.d.cts +11 -276
  175. package/dist/messaging/index.d.ts +11 -276
  176. package/dist/messaging/index.js +1 -1
  177. package/dist/operators/index.cjs +1228 -1076
  178. package/dist/operators/index.cjs.map +1 -1
  179. package/dist/operators/index.d.cts +5 -5
  180. package/dist/operators/index.d.ts +5 -5
  181. package/dist/operators/index.js +5 -5
  182. package/dist/orchestration/index.cjs +8844 -6071
  183. package/dist/orchestration/index.cjs.map +1 -1
  184. package/dist/orchestration/index.d.cts +171 -224
  185. package/dist/orchestration/index.d.ts +171 -224
  186. package/dist/orchestration/index.js +42 -991
  187. package/dist/orchestration/index.js.map +1 -1
  188. package/dist/orchestration/messaging.d.cts +5 -8
  189. package/dist/orchestration/messaging.d.ts +5 -8
  190. package/dist/orchestration/work-queue.cjs +1243 -5
  191. package/dist/orchestration/work-queue.cjs.map +1 -1
  192. package/dist/orchestration/work-queue.d.cts +121 -10
  193. package/dist/orchestration/work-queue.d.ts +121 -10
  194. package/dist/orchestration/work-queue.js +1067 -4
  195. package/dist/orchestration/work-queue.js.map +1 -1
  196. package/dist/patterns/event-flow.cjs +6 -20
  197. package/dist/patterns/event-flow.cjs.map +1 -1
  198. package/dist/patterns/event-flow.d.cts +4 -4
  199. package/dist/patterns/event-flow.d.ts +4 -4
  200. package/dist/patterns/event-flow.js +2 -2
  201. package/dist/patterns/index.cjs +453 -465
  202. package/dist/patterns/index.cjs.map +1 -1
  203. package/dist/patterns/index.d.cts +6 -5
  204. package/dist/patterns/index.d.ts +6 -5
  205. package/dist/patterns/index.js +3 -3
  206. package/dist/process-types-BB7oRhX3.d.cts +200 -0
  207. package/dist/process-types-QNhyoYJ8.d.ts +200 -0
  208. package/dist/{reactive-collection-DNV0-gFi.d.cts → reactive-collection-BYlWvtnp.d.cts} +4 -34
  209. package/dist/{reactive-collection-BAmfrGjd.d.ts → reactive-collection-efOEdGFN.d.ts} +4 -34
  210. package/dist/{reactive-collection-storage-BNEldDyi.d.cts → reactive-collection-storage-BjoLsoiC.d.cts} +5 -5
  211. package/dist/{reactive-collection-storage-YZsAQsWK.d.ts → reactive-collection-storage-DwW6UuK_.d.ts} +5 -5
  212. package/dist/{reactive-map-DRD1LJ2H.d.cts → reactive-map-BHacbIqz.d.cts} +7 -2
  213. package/dist/{reactive-map-EsDiCmJk.d.ts → reactive-map-DN4Jyqnf.d.ts} +7 -2
  214. package/dist/render/index.d.cts +2 -2
  215. package/dist/render/index.d.ts +2 -2
  216. package/dist/scheduled-readiness-BmqXxnzX.d.ts +91 -0
  217. package/dist/scheduled-readiness-CYSw7KDE.d.cts +91 -0
  218. package/dist/semantic-memory-graph-B_LwbM-E.d.cts +30 -0
  219. package/dist/semantic-memory-graph-rsFNNhwn.d.ts +30 -0
  220. package/dist/{semantic-memory-graph-DKuNzuWw.d.cts → semantic-memory-graph-types-Y73bbwVI.d.cts} +2 -28
  221. package/dist/{semantic-memory-graph-uwbwJdhe.d.ts → semantic-memory-graph-types-safmPkuX.d.ts} +2 -28
  222. package/dist/solutions/index.cjs +6353 -6169
  223. package/dist/solutions/index.cjs.map +1 -1
  224. package/dist/solutions/index.d.cts +12 -10
  225. package/dist/solutions/index.d.ts +12 -10
  226. package/dist/solutions/index.js +5 -5
  227. package/dist/solutions/reactive-layout/browser/index.cjs +116 -108
  228. package/dist/solutions/reactive-layout/browser/index.cjs.map +1 -1
  229. package/dist/solutions/reactive-layout/browser/index.d.cts +4 -4
  230. package/dist/solutions/reactive-layout/browser/index.d.ts +4 -4
  231. package/dist/solutions/reactive-layout/browser/index.js +3 -3
  232. package/dist/solutions/reactive-layout/index.cjs +3578 -3350
  233. package/dist/solutions/reactive-layout/index.cjs.map +1 -1
  234. package/dist/solutions/reactive-layout/index.d.cts +32 -576
  235. package/dist/solutions/reactive-layout/index.d.ts +32 -576
  236. package/dist/solutions/reactive-layout/index.js +65 -5
  237. package/dist/solutions/reactive-layout/node-canvas/index.cjs +127 -117
  238. package/dist/solutions/reactive-layout/node-canvas/index.cjs.map +1 -1
  239. package/dist/solutions/reactive-layout/node-canvas/index.d.cts +4 -4
  240. package/dist/solutions/reactive-layout/node-canvas/index.d.ts +4 -4
  241. package/dist/solutions/reactive-layout/node-canvas/index.js +3 -3
  242. package/dist/solutions/reactive-layout/react-native/index.cjs +127 -117
  243. package/dist/solutions/reactive-layout/react-native/index.cjs.map +1 -1
  244. package/dist/solutions/reactive-layout/react-native/index.d.cts +4 -4
  245. package/dist/solutions/reactive-layout/react-native/index.d.ts +4 -4
  246. package/dist/solutions/reactive-layout/react-native/index.js +3 -3
  247. package/dist/solutions/reactive-layout/skia/index.cjs +127 -117
  248. package/dist/solutions/reactive-layout/skia/index.cjs.map +1 -1
  249. package/dist/solutions/reactive-layout/skia/index.d.cts +4 -4
  250. package/dist/solutions/reactive-layout/skia/index.d.ts +4 -4
  251. package/dist/solutions/reactive-layout/skia/index.js +3 -3
  252. package/dist/solutions/work-item/actions.cjs +1609 -1428
  253. package/dist/solutions/work-item/actions.cjs.map +1 -1
  254. package/dist/solutions/work-item/actions.d.cts +23 -184
  255. package/dist/solutions/work-item/actions.d.ts +23 -184
  256. package/dist/solutions/work-item/actions.js +1558 -934
  257. package/dist/solutions/work-item/actions.js.map +1 -1
  258. package/dist/solutions/work-item/scheduling.cjs +9181 -1838
  259. package/dist/solutions/work-item/scheduling.cjs.map +1 -1
  260. package/dist/solutions/work-item/scheduling.d.cts +1763 -328
  261. package/dist/solutions/work-item/scheduling.d.ts +1763 -328
  262. package/dist/solutions/work-item/scheduling.js +117 -3
  263. package/dist/solutions/work-item/work-queue.d.cts +7 -7
  264. package/dist/solutions/work-item/work-queue.d.ts +7 -7
  265. package/dist/sources/browser.cjs +1318 -1083
  266. package/dist/sources/browser.cjs.map +1 -1
  267. package/dist/sources/browser.d.cts +22 -6
  268. package/dist/sources/browser.d.ts +22 -6
  269. package/dist/sources/browser.js +4 -4
  270. package/dist/sources/browser.js.map +1 -1
  271. package/dist/sources/index.cjs +1318 -1083
  272. package/dist/sources/index.cjs.map +1 -1
  273. package/dist/sources/index.d.cts +4 -4
  274. package/dist/sources/index.d.ts +4 -4
  275. package/dist/sources/index.js +4 -4
  276. package/dist/sources/node.d.cts +3 -3
  277. package/dist/sources/node.d.ts +3 -3
  278. package/dist/storage/browser.cjs +16 -0
  279. package/dist/storage/browser.cjs.map +1 -1
  280. package/dist/storage/browser.js +3 -3
  281. package/dist/storage/index.cjs +16 -0
  282. package/dist/storage/index.cjs.map +1 -1
  283. package/dist/storage/index.d.cts +5 -4
  284. package/dist/storage/index.d.ts +5 -4
  285. package/dist/storage/index.js +6 -6
  286. package/dist/storage/node.cjs +16 -0
  287. package/dist/storage/node.cjs.map +1 -1
  288. package/dist/storage/node.js +3 -3
  289. package/dist/{store-C-joM4gh.d.ts → store-6_CHF6Ge.d.ts} +1 -1
  290. package/dist/{store-CNJwmT-h.d.cts → store-BljX8RkQ.d.cts} +1 -1
  291. package/dist/types-BAw2QVVE.d.cts +274 -0
  292. package/dist/types-BUbbbh4f.d.cts +34 -0
  293. package/dist/types-CMnzoL54.d.cts +457 -0
  294. package/dist/{types-CcPIn7sy.d.cts → types-CTN3XoMl.d.cts} +57 -108
  295. package/dist/types-CV_ohy5T.d.cts +357 -0
  296. package/dist/{types-BsJvElYZ.d.ts → types-DChxk1vK.d.ts} +57 -108
  297. package/dist/types-DRu7SnLV.d.ts +274 -0
  298. package/dist/types-DeID_FRl.d.ts +34 -0
  299. package/dist/types-IhKH0hGW.d.ts +357 -0
  300. package/dist/types-ePlD2uyT.d.ts +457 -0
  301. package/dist/{work-item-runtime-qaVgsL0T.d.cts → work-item-runtime-types-BTxLskN5.d.cts} +3 -93
  302. package/dist/{work-item-runtime-C3M79vE9.d.ts → work-item-runtime-types-DAsZbb2y.d.ts} +3 -93
  303. package/dist/work-queue/index.cjs +957 -953
  304. package/dist/work-queue/index.cjs.map +1 -1
  305. package/dist/work-queue/index.d.cts +9 -357
  306. package/dist/work-queue/index.d.ts +9 -357
  307. package/dist/work-queue/index.js +957 -953
  308. package/dist/work-queue/index.js.map +1 -1
  309. package/package.json +611 -513
  310. package/dist/chunk-3JR3EDB2.js.map +0 -1
  311. package/dist/chunk-4VLAQHZI.js.map +0 -1
  312. package/dist/chunk-6XAIOL3X.js +0 -2407
  313. package/dist/chunk-6XAIOL3X.js.map +0 -1
  314. package/dist/chunk-FBUU43PM.js.map +0 -1
  315. package/dist/chunk-HKK2JD7Z.js.map +0 -1
  316. package/dist/chunk-PC3BTTBE.js +0 -3217
  317. package/dist/chunk-PC3BTTBE.js.map +0 -1
  318. package/dist/chunk-QFY4AFY4.js.map +0 -1
  319. package/dist/chunk-SS2A464I.js.map +0 -1
  320. package/dist/chunk-V7CIJE4B.js.map +0 -1
  321. package/dist/chunk-XKXWK2KP.js.map +0 -1
  322. package/dist/chunk-YDSIVHRR.js.map +0 -1
  323. package/dist/chunk-YXMZ2N6J.js.map +0 -1
  324. /package/dist/{chunk-CZNV3VXM.js.map → chunk-3J7UPZL5.js.map} +0 -0
  325. /package/dist/{chunk-Z2ANQ6JW.js.map → chunk-4Q77MMJY.js.map} +0 -0
  326. /package/dist/{chunk-K3FXTC3I.js.map → chunk-HJACH5PU.js.map} +0 -0
  327. /package/dist/{chunk-GTPCOEOZ.js.map → chunk-IDMLXLLG.js.map} +0 -0
  328. /package/dist/{chunk-DKP56CSW.js.map → chunk-JKAYLDQV.js.map} +0 -0
  329. /package/dist/{chunk-43BKLFZU.js.map → chunk-KFURM6FM.js.map} +0 -0
  330. /package/dist/{chunk-2747WN4Y.js.map → chunk-PUSRRALM.js.map} +0 -0
  331. /package/dist/{chunk-VTHLCFN4.js.map → chunk-RAHNUYA5.js.map} +0 -0
  332. /package/dist/{chunk-IXZBUWSP.js.map → chunk-UEMN5URK.js.map} +0 -0
  333. /package/dist/{chunk-6PHB5CJS.js.map → chunk-ZLFRB6FI.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/orchestration/work-queue.ts","../../src/protocol/messages.ts","../../src/ctx/types.ts"],"sourcesContent":["/**\n * Optional orchestration-over-workQueue recipe (D349/D353).\n *\n * Queue lifecycle remains disposition evidence. This module maps visible\n * ProcessEffectRequest facts to queue commands and maps terminal queue records\n * back to graph-visible orchestration evidence/status/issue facts.\n */\n\nimport { type Ctx, depBatch } from \"../ctx/types.js\";\nimport type { DataIssue } from \"../data/index.js\";\nimport type { Graph } from \"../graph/graph.js\";\nimport type { Node } from \"../node/node.js\";\nimport type { ProcessEffectRequest } from \"../orchestration/index.js\";\nimport type { WorkQueueCommand, WorkQueueRecord } from \"../work-queue/index.js\";\n\nexport interface OrchestrationQueuedEffectPayload<TEffect = unknown> {\n\treadonly kind: \"orchestration-queued-effect\";\n\treadonly effect: ProcessEffectRequest<TEffect>;\n\treadonly idempotencyKey?: string;\n\treadonly sourceRefs?: readonly string[];\n\treadonly policyRefs?: readonly string[];\n\treadonly metadata?: Record<string, unknown>;\n}\n\nexport interface OrchestrationQueueEvidence {\n\treadonly kind: \"orchestration-queue-evidence\";\n\treadonly evidenceId: string;\n\treadonly effectId: string;\n\treadonly effectType: string;\n\treadonly workId: string;\n\treadonly queueRecordKind: WorkQueueRecord[\"kind\"];\n\treadonly result?: unknown;\n\treadonly error?: unknown;\n\treadonly recordedAtMs: number;\n}\n\nexport interface OrchestrationQueueStatus {\n\treadonly kind: \"orchestration-queue-status\";\n\treadonly state: \"evidence-recorded\" | \"mapping-issue\";\n\treadonly effectId?: string;\n\treadonly effectType?: string;\n\treadonly workId?: string;\n\treadonly queueRecordKind?: WorkQueueRecord[\"kind\"];\n\treadonly evidenceId?: string;\n\treadonly issues?: readonly DataIssue[];\n}\n\nexport interface OrchestrationQueueAuditRecord {\n\treadonly kind: \"orchestration-queue-audit\";\n\treadonly seq: number;\n\treadonly outcome: \"mapped\" | \"issue\";\n\treadonly effectId?: string;\n\treadonly effectType?: string;\n\treadonly workId?: string;\n\treadonly queueRecordKind?: WorkQueueRecord[\"kind\"];\n\treadonly evidenceId?: string;\n}\n\nexport interface OrchestrationWorkQueueRecipeOptions<TEffect = unknown> {\n\treadonly name?: string;\n\treadonly effectRequests?: Node<ProcessEffectRequest<TEffect>>;\n\treadonly records: Node<WorkQueueRecord<OrchestrationQueuedEffectPayload<TEffect>>>;\n}\n\nexport interface OrchestrationWorkQueueRecipeBundle<TEffect = unknown> {\n\treadonly submitCommands?: Node<WorkQueueCommand<OrchestrationQueuedEffectPayload<TEffect>>>;\n\treadonly evidence: Node<OrchestrationQueueEvidence>;\n\treadonly status: Node<OrchestrationQueueStatus>;\n\treadonly issues: Node<DataIssue>;\n\treadonly audit: Node<OrchestrationQueueAuditRecord>;\n}\n\ntype OrchestrationQueueFact =\n\t| { readonly kind: \"evidence\"; readonly evidence: OrchestrationQueueEvidence }\n\t| { readonly kind: \"status\"; readonly status: OrchestrationQueueStatus }\n\t| { readonly kind: \"issue\"; readonly issue: DataIssue }\n\t| { readonly kind: \"audit\"; readonly audit: OrchestrationQueueAuditRecord };\n\ninterface QueueState<TEffect> {\n\treadonly payloads: Map<string, OrchestrationQueuedEffectPayload<TEffect>>;\n\treadonly terminalRecords: Set<string>;\n\tauditSeq: number;\n}\n\n/** Build the optional D349 orchestration workQueue recipe. */\nexport function orchestrationWorkQueueRecipe<TEffect = unknown>(\n\tgraph: Graph,\n\topts: OrchestrationWorkQueueRecipeOptions<TEffect>,\n): OrchestrationWorkQueueRecipeBundle<TEffect> {\n\tconst name = opts.name ?? \"orchestrationWorkQueue\";\n\tconst submitCommands =\n\t\topts.effectRequests === undefined\n\t\t\t? undefined\n\t\t\t: graph.node<WorkQueueCommand<OrchestrationQueuedEffectPayload<TEffect>>>(\n\t\t\t\t\t[opts.effectRequests],\n\t\t\t\t\t(ctx) => {\n\t\t\t\t\t\tfor (const raw of depBatch(ctx, 0) ?? []) {\n\t\t\t\t\t\t\tctx.down([\n\t\t\t\t\t\t\t\t[\"DATA\", processEffectSubmitCommand(raw as ProcessEffectRequest<TEffect>)],\n\t\t\t\t\t\t\t]);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: `${name}/submitCommands`,\n\t\t\t\t\t\tfactory: \"orchestrationWorkQueueSubmitCommands\",\n\t\t\t\t\t\tcompleteWhenDepsComplete: false,\n\t\t\t\t\t\terrorWhenDepsError: false,\n\t\t\t\t\t},\n\t\t\t\t);\n\tconst runtime = graph.node<OrchestrationQueueFact>(\n\t\t[opts.records],\n\t\t(ctx) => {\n\t\t\tconst state = ctx.state.get<QueueState<TEffect>>() ?? {\n\t\t\t\tpayloads: new Map(),\n\t\t\t\tterminalRecords: new Set(),\n\t\t\t\tauditSeq: 0,\n\t\t\t};\n\t\t\tfor (const raw of depBatch(ctx, 0) ?? []) {\n\t\t\t\treduceRecord(ctx, state, raw as WorkQueueRecord<OrchestrationQueuedEffectPayload<TEffect>>);\n\t\t\t}\n\t\t\tctx.state.set(state);\n\t\t},\n\t\t{\n\t\t\tname: `${name}/runtime`,\n\t\t\tfactory: \"orchestrationWorkQueueRuntime\",\n\t\t\tpartial: true,\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\treturn {\n\t\t...(submitCommands === undefined ? {} : { submitCommands }),\n\t\tevidence: project(\n\t\t\tgraph,\n\t\t\truntime,\n\t\t\t`${name}/evidence`,\n\t\t\t\"orchestrationWorkQueueEvidence\",\n\t\t\t(fact) => (fact.kind === \"evidence\" ? fact.evidence : undefined),\n\t\t),\n\t\tstatus: project(graph, runtime, `${name}/status`, \"orchestrationWorkQueueStatus\", (fact) =>\n\t\t\tfact.kind === \"status\" ? fact.status : undefined,\n\t\t),\n\t\tissues: project(graph, runtime, `${name}/issues`, \"orchestrationWorkQueueIssues\", (fact) =>\n\t\t\tfact.kind === \"issue\" ? fact.issue : undefined,\n\t\t),\n\t\taudit: project(graph, runtime, `${name}/audit`, \"orchestrationWorkQueueAudit\", (fact) =>\n\t\t\tfact.kind === \"audit\" ? fact.audit : undefined,\n\t\t),\n\t};\n}\n\nexport function processEffectSubmitCommand<TEffect>(\n\teffect: ProcessEffectRequest<TEffect>,\n\topts: {\n\t\treadonly workId?: string;\n\t\treadonly commandId?: string;\n\t\treadonly idempotencyKey?: string;\n\t\treadonly sourceRefs?: readonly string[];\n\t\treadonly policyRefs?: readonly string[];\n\t\treadonly metadata?: Record<string, unknown>;\n\t} = {},\n): WorkQueueCommand<OrchestrationQueuedEffectPayload<TEffect>> {\n\tconst payload: OrchestrationQueuedEffectPayload<TEffect> = {\n\t\tkind: \"orchestration-queued-effect\",\n\t\teffect,\n\t\tidempotencyKey: opts.idempotencyKey ?? effect.id,\n\t\tsourceRefs: opts.sourceRefs,\n\t\tpolicyRefs: opts.policyRefs,\n\t\tmetadata: opts.metadata,\n\t};\n\treturn {\n\t\tkind: \"submit\",\n\t\tcommandId: opts.commandId ?? `${effect.id}:orchestration-work-queue-submit`,\n\t\tworkId: opts.workId ?? `process-effect:${effect.id}`,\n\t\tpayload,\n\t\tidempotencyKey: opts.idempotencyKey ?? effect.id,\n\t\tsourceRefs: opts.sourceRefs,\n\t\tpolicyRefs: opts.policyRefs,\n\t};\n}\n\nfunction reduceRecord<TEffect>(\n\tctx: Ctx,\n\tstate: QueueState<TEffect>,\n\trecord: WorkQueueRecord<OrchestrationQueuedEffectPayload<TEffect>>,\n): void {\n\tif (record.kind === \"work-admitted\") {\n\t\tif (isQueuedEffectPayload(record.payload)) {\n\t\t\tstate.payloads.set(record.workId, record.payload);\n\t\t} else {\n\t\t\temitIssue(ctx, state, record, \"orchestration-queue-malformed-payload\");\n\t\t}\n\t\treturn;\n\t}\n\tif (!isTerminalEvidenceRecord(record)) return;\n\tconst key = `${record.kind}:${record.recordSeq}`;\n\tif (state.terminalRecords.has(key)) return;\n\tstate.terminalRecords.add(key);\n\tconst payload = record.workId === undefined ? undefined : state.payloads.get(record.workId);\n\tif (payload === undefined) {\n\t\temitIssue(ctx, state, record, \"orchestration-queue-record-without-payload\");\n\t\treturn;\n\t}\n\tconst evidence = evidenceFromRecord(record, payload);\n\temit(ctx, { kind: \"evidence\", evidence });\n\temit(ctx, { kind: \"status\", status: statusFromEvidence(evidence, payload) });\n\tstate.auditSeq += 1;\n\temit(ctx, { kind: \"audit\", audit: auditFromEvidence(state.auditSeq, evidence, payload) });\n}\n\nfunction isTerminalEvidenceRecord(record: WorkQueueRecord): boolean {\n\treturn (\n\t\trecord.kind === \"work-completed\" ||\n\t\trecord.kind === \"attempt-completed\" ||\n\t\trecord.kind === \"work-canceled\" ||\n\t\trecord.kind === \"work-dead-lettered\" ||\n\t\trecord.kind === \"attempt-failed\"\n\t);\n}\n\nfunction evidenceFromRecord<TEffect>(\n\trecord: WorkQueueRecord<OrchestrationQueuedEffectPayload<TEffect>>,\n\tpayload: OrchestrationQueuedEffectPayload<TEffect>,\n): OrchestrationQueueEvidence {\n\treturn {\n\t\tkind: \"orchestration-queue-evidence\",\n\t\tevidenceId: `work-queue:${record.recordSeq}`,\n\t\teffectId: payload.effect.id,\n\t\teffectType: payload.effect.type,\n\t\tworkId: record.workId ?? `unknown:${record.recordSeq}`,\n\t\tqueueRecordKind: record.kind,\n\t\tresult: \"result\" in record ? record.result : undefined,\n\t\terror: \"error\" in record ? record.error : undefined,\n\t\trecordedAtMs: record.recordedAtMs,\n\t};\n}\n\nfunction statusFromEvidence<TEffect>(\n\tevidence: OrchestrationQueueEvidence,\n\tpayload: OrchestrationQueuedEffectPayload<TEffect>,\n): OrchestrationQueueStatus {\n\treturn {\n\t\tkind: \"orchestration-queue-status\",\n\t\tstate: \"evidence-recorded\",\n\t\teffectId: payload.effect.id,\n\t\teffectType: payload.effect.type,\n\t\tworkId: evidence.workId,\n\t\tqueueRecordKind: evidence.queueRecordKind,\n\t\tevidenceId: evidence.evidenceId,\n\t};\n}\n\nfunction auditFromEvidence<TEffect>(\n\tseq: number,\n\tevidence: OrchestrationQueueEvidence,\n\tpayload: OrchestrationQueuedEffectPayload<TEffect>,\n): OrchestrationQueueAuditRecord {\n\treturn {\n\t\tkind: \"orchestration-queue-audit\",\n\t\tseq,\n\t\toutcome: \"mapped\",\n\t\teffectId: payload.effect.id,\n\t\teffectType: payload.effect.type,\n\t\tworkId: evidence.workId,\n\t\tqueueRecordKind: evidence.queueRecordKind,\n\t\tevidenceId: evidence.evidenceId,\n\t};\n}\n\nfunction auditFromIssue(\n\tseq: number,\n\trecord: WorkQueueRecord<unknown>,\n): OrchestrationQueueAuditRecord {\n\treturn {\n\t\tkind: \"orchestration-queue-audit\",\n\t\tseq,\n\t\toutcome: \"issue\",\n\t\tworkId: record.workId,\n\t\tqueueRecordKind: record.kind,\n\t};\n}\n\nfunction project<T>(\n\tgraph: Graph,\n\truntime: Node<OrchestrationQueueFact>,\n\tname: string,\n\tfactory: string,\n\tpick: (fact: OrchestrationQueueFact) => T | undefined,\n): Node<T> {\n\treturn graph.node<T>(\n\t\t[runtime],\n\t\t(ctx) => {\n\t\t\tfor (const fact of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst value = pick(fact as OrchestrationQueueFact);\n\t\t\t\tif (value !== undefined) ctx.down([[\"DATA\", value]]);\n\t\t\t}\n\t\t},\n\t\t{ name, factory, partial: true, completeWhenDepsComplete: false, errorWhenDepsError: false },\n\t);\n}\n\nfunction emit(ctx: Ctx, fact: OrchestrationQueueFact): void {\n\tctx.down([[\"DATA\", fact]]);\n}\n\nfunction emitIssue(\n\tctx: Ctx,\n\tstate: QueueState<unknown>,\n\trecord: WorkQueueRecord<unknown>,\n\tcode: string,\n): void {\n\tconst issue = queueIssue(record, code);\n\temit(ctx, { kind: \"issue\", issue });\n\tstate.auditSeq += 1;\n\temit(ctx, {\n\t\tkind: \"status\",\n\t\tstatus: {\n\t\t\tkind: \"orchestration-queue-status\",\n\t\t\tstate: \"mapping-issue\",\n\t\t\tworkId: record.workId,\n\t\t\tqueueRecordKind: record.kind,\n\t\t\tissues: [issue],\n\t\t},\n\t});\n\temit(ctx, {\n\t\tkind: \"audit\",\n\t\taudit: auditFromIssue(state.auditSeq, record),\n\t});\n}\n\nfunction queueIssue(record: WorkQueueRecord<unknown>, code: string): DataIssue {\n\treturn {\n\t\tkind: \"issue\",\n\t\tcode,\n\t\tmessage: `Orchestration workQueue recipe could not map record '${record.kind}'`,\n\t\tseverity: \"error\",\n\t\tsource: \"orchestration.workQueue\",\n\t\tdetails: record,\n\t};\n}\n\nfunction isQueuedEffectPayload<TEffect>(\n\tvalue: unknown,\n): value is OrchestrationQueuedEffectPayload<TEffect> {\n\tif (!isObjectRecord(value) || value.kind !== \"orchestration-queued-effect\") return false;\n\tconst effect = value.effect;\n\treturn isObjectRecord(effect) && typeof effect.id === \"string\" && typeof effect.type === \"string\";\n}\n\nfunction isObjectRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n","/**\n * Wave-protocol message types and the tier const table.\n *\n * Canonical authority: ~/src/graphrefly/spec/rules.jsonl\n * R-msg-format, R-msg-closed-set, R-tier (D34), R-data-payload, R-sentinel.\n */\n\n/** Opaque pause-lock / pull identifier (R-pause-lockset, R-pull). */\nexport type LockId = string | symbol;\n\n/** Explicit pull demand payload (D269/D272). Params are holder-visible context, never DATA-up. */\nexport interface PullDemand {\n\treadonly pullId: LockId;\n\treadonly params?: unknown;\n}\n\n/**\n * The CLOSED set of 11 message types (R-msg-closed-set / D9 + D269 + START handshake).\n * No open set, no user-defined custom types. Adding a type is a spec change.\n */\nexport type Message =\n\t| readonly [\"START\"]\n\t| readonly [\"DIRTY\"]\n\t| readonly [\"DATA\", unknown]\n\t| readonly [\"RESOLVED\"]\n\t| readonly [\"INVALIDATE\"]\n\t| readonly [\"COMPLETE\"]\n\t| readonly [\"ERROR\", unknown]\n\t| readonly [\"TEARDOWN\"]\n\t| readonly [\"PAUSE\", LockId]\n\t| readonly [\"RESUME\", LockId]\n\t| readonly [\"PULL\", PullDemand];\n\n/** One array of messages delivered in one call = one Wave (R-wave-boundary). */\nexport type Wave = readonly Message[];\n\n/** The message-type tag (the first tuple element). */\nexport type MessageType = Message[0];\n\n/**\n * SENTINEL = absence-of-DATA (R-sentinel / D16). TS representation is `undefined`.\n * Never a valid DATA payload; `null` IS a valid DATA value (domain-level absence).\n */\nexport const SENTINEL = undefined;\n\n/** R-data-payload: ERROR payloads must not collide with terminal metadata shorthand. */\nexport function isInvalidErrorPayload(v: unknown): boolean {\n\treturn v === SENTINEL || typeof v === \"boolean\";\n}\n\n/** R-data-payload / D78: host-language failures that collide with ctx.terminal shorthand become diagnostics. */\nexport function errorPayload(reason: unknown, fallback = \"error without a valid payload\"): unknown {\n\treturn isInvalidErrorPayload(reason) ? new Error(fallback) : reason;\n}\n\nexport const TIER_START = 0;\nexport const TIER_CONTROL = 1;\nexport const TIER_NOTIFICATION = 2;\nexport const TIER_VALUE = 3;\nexport const TIER_SETTLE = 4;\nexport const TIER_TERMINAL = 5;\nexport const TIER_TEARDOWN = 6;\n\n/**\n * Tier const table (R-tier / D34). Tiers below value dispatch immediately; value\n * and above are batch-deferred. This is a compile-time const table (D18), not runtime config.\n */\nconst TIER: Record<MessageType, number> = {\n\tSTART: TIER_START,\n\tPAUSE: TIER_CONTROL,\n\tRESUME: TIER_CONTROL,\n\tPULL: TIER_CONTROL,\n\tDIRTY: TIER_NOTIFICATION,\n\tDATA: TIER_VALUE,\n\tRESOLVED: TIER_VALUE,\n\tINVALIDATE: TIER_SETTLE,\n\tCOMPLETE: TIER_TERMINAL,\n\tERROR: TIER_TERMINAL,\n\tTEARDOWN: TIER_TEARDOWN,\n};\n\nexport function messageTier(t: MessageType): number {\n\treturn TIER[t];\n}\n\n/** Value and above are deferred inside a batch (DATA/RESOLVED/INVALIDATE/terminal/teardown). */\nexport function isDeferredTier(t: MessageType): boolean {\n\treturn TIER[t] >= TIER_VALUE;\n}\n\n/** Value-tier messages (DATA/RESOLVED) occupy the tier-3 slot. */\nexport function isValueTier(t: MessageType): boolean {\n\treturn TIER[t] === TIER_VALUE;\n}\n\n/** The pause buffer holds the settle slice only: value-tier DATA/RESOLVED plus INVALIDATE. */\nexport function isPauseBufferedTier(t: MessageType): boolean {\n\tconst tier = TIER[t];\n\treturn tier === TIER_VALUE || tier === TIER_SETTLE;\n}\n\n/**\n * A TERMINAL message = tier 5 (COMPLETE | ERROR), R-tier / D34. Detected via the CENTRAL tier\n * table, NOT a per-variant `=== \"COMPLETE\" || === \"ERROR\"` check — so terminal routing stays\n * driven by the one const table (feedback_use_tier_for_signal_routing); discriminate COMPLETE vs\n * ERROR within the tier by the message type only where the handling actually differs.\n */\nexport function isTerminal(t: MessageType): boolean {\n\treturn TIER[t] === TIER_TERMINAL;\n}\n\n/**\n * ctx.up carries control/demand tiers only (R-ctx-up / D269): DIRTY, PAUSE, RESUME, PULL,\n * INVALIDATE, TEARDOWN. DATA/RESOLVED (tier 3) and COMPLETE/ERROR (tier 5) are\n * down-only.\n */\nexport function isUpAllowed(t: MessageType): boolean {\n\tconst tier = TIER[t];\n\treturn tier !== TIER_VALUE && tier !== TIER_TERMINAL;\n}\n","/**\n * The fn-invocation context and per-dep input shapes.\n *\n * Canonical authority: ~/src/graphrefly/spec/rules.jsonl\n * R-fn-contract (D8/D27), R-ctx-state (D23/D29), R-cleanup-hooks (D28), R-ctx-up.\n */\n\nimport type { Dispatcher } from \"../dispatcher/index.js\";\nimport type { EnvironmentDrivers } from \"../graph/environment.js\";\nimport type { Node } from \"../node/node.js\";\nimport { type Message, type PullDemand, SENTINEL, type Wave } from \"../protocol/messages.js\";\n\n/** A downstream sink callback (the only way to connect to a node's output). */\nexport type Sink = (msg: Message, delivery?: DeliveryMeta) => void;\n\n/** Internal delivery metadata used to preserve the upstream `ctx.down(msgs)` wave boundary. */\nexport interface DeliveryMeta {\n\treadonly wave: object;\n\treadonly last: boolean;\n}\n\n/**\n * Internal current-value reader. It is deliberately a symbol-backed implementation detail:\n * raw ctx exposes `waveData` + `terminal`; helpers below derive from that plus this dep cache.\n */\nexport const CTX_DEP_CACHE: unique symbol = Symbol(\"graphrefly.ctx.depCache\");\n\nexport interface CtxDepCache {\n\treadonly latest: readonly unknown[];\n}\n\n/** Internal node-construction binding for graph-local helper-created deps. */\nexport const CTX_NODE_BINDING: unique symbol = Symbol(\"graphrefly.ctx.nodeBinding\");\n\nexport interface CtxNodeBinding {\n\treadonly dispatcher: Dispatcher;\n\tcreate<T>(factory: () => Node<T>): Node<T>;\n}\n\n/** Per-dep wave projections: dep -> waves -> values/SENTINEL markers. */\nexport type WaveData = readonly (readonly (readonly unknown[])[])[];\n\n/** Terminal metadata parallel to `waveData`: false = none, true = COMPLETE, otherwise ERROR payload. */\nexport type TerminalData = readonly unknown[];\n\nexport function isTerminalNone(t: unknown): boolean {\n\treturn t === false || t === undefined;\n}\n\nexport function isTerminalComplete(t: unknown): t is true {\n\treturn t === true;\n}\n\nexport function isTerminalError(t: unknown): boolean {\n\treturn !isTerminalNone(t) && !isTerminalComplete(t);\n}\n\nexport function terminalErrorValue(t: unknown): unknown {\n\treturn isTerminalError(t) ? t : undefined;\n}\n\n/**\n * Per-node private cross-wave state (R-ctx-state / D23,D29). Default fresh-lifecycle\n * wipe; `persist(true)` keeps it across lifecycle transitions.\n */\nexport interface CtxState {\n\tget<S = unknown>(): S | undefined;\n\tset<S = unknown>(v: S): void;\n\tpersist(on?: boolean): void;\n}\n\n/**\n * Deferred SELF-rewire (R-rewire-deferred / D47). A node fn may, DURING its run, request a\n * mutation of its OWN dep set; the request is QUEUED and applied at the committed wave boundary\n * (after the current wave settles / batch commit / final-lock RESUME) as a fresh wave, reusing\n * R-rewire surgical/Option-C semantics (D42). This is the ONLY legal self-triggered rewire — an\n * IMMEDIATE in-fn `node.subscribeDep/unsubscribeDep/replaceDeps` is the D37 mid-fn feedback-cycle ERROR. An\n * added cached dep pushes `[DIRTY,DATA]` on the boundary wave (R-push-subscribe); a removed dep\n * is drained and, if it loses its last subscriber, `_deactivate`s + fires `onDeactivation`\n * (input-side teardown — the basis for higher-order operator cancellation / abortInFlight).\n */\nexport interface RewireNext {\n\t/** Defer subscribing to a dep (paired with the re-supplied fn — positional fn-deps lock, SD-1). */\n\tsubscribeDep(dep: Node<unknown>, fn: NodeFn): void;\n\t/** Defer unsubscribing from a dep (its source is torn down if it loses its last subscriber). */\n\tunsubscribeDep(dep: Node<unknown>, fn: NodeFn): void;\n\t/** Defer replacing the whole dep set (surgical: kept deps untouched, removed drained, added fresh-subscribe). */\n\treplaceDeps(deps: Node<unknown>[], fn: NodeFn): void;\n}\n\n/**\n * The single argument to a node fn: `(ctx) => void` (R-fn-contract / D8). All emission\n * is explicit via `ctx.down`; there is no return-value framing.\n */\nexport interface Ctx {\n\t/**\n\t * Emit upstream toward deps — control tiers only (R-ctx-up). IMMEDIATE. `towardDep` (a dep index)\n\t * routes the wave up ONE declared edge (R-up-routing directed-up); omitted = broadcast up all deps.\n\t * A pull DEMAND is `up([[PULL, { pullId, params }]])` — but for a SELF-demand (demanding a dep\n\t * this fn also reads) use {@link Ctx.upNext} instead, since an immediate demand whose delivery loops back\n\t * re-enters this fn mid-wave (D37 / R-reentrancy).\n\t */\n\tup(msgs: Wave, towardDep?: number): void;\n\t/** Emit downstream toward sinks. */\n\tdown(msgs: Wave): void;\n\t/**\n\t * The single raw dep-value input surface (R-ctx-wave-data / D77): dep -> upstream waves ->\n\t * per-wave DATA payloads and INVALIDATE/SENTINEL markers. `waveData[i] = []` means dep i\n\t * delivered no wave to this invocation; `waveData[i] = [[]]` means RESOLVED-only.\n\t */\n\twaveData: WaveData;\n\t/** Terminal metadata for the same invocation; terminal values never enter `waveData`. */\n\tterminal: TerminalData;\n\tstate: CtxState;\n\t/** Release external resources on deactivation (R-cleanup-hooks). */\n\tonDeactivation(fn: () => void): void;\n\t/** Flush on INVALIDATE (R-cleanup-hooks). */\n\tonInvalidate(fn: () => void): void;\n\t/** Graph-owned environment drivers for source/adapter boundaries (D130/D131). */\n\tenvironment(): EnvironmentDrivers;\n\t/** Holder-visible context for a PULL-caused invocation (D272); absent for ordinary waves. */\n\treadonly pull?: PullDemand;\n\t/**\n\t * Deferred SELF-rewire (R-rewire-deferred / D47) — the substrate affordance higher-order\n\t * operators (switchMap/mergeMap/concatMap/exhaustMap/flatMap) use to grow/shrink their own\n\t * inner-source dep set in response to their own data. Always present; see {@link RewireNext}.\n\t */\n\trewireNext: RewireNext;\n\t/**\n\t * Deferred up — the boundary-deferred form of {@link Ctx.up} (R-up-routing / R-pull / D59). Routes\n\t * `msgs` up from this node at the COMMITTED wave boundary (broadcast, or up the single `towardDep`\n\t * edge), riding the same R-rewire-deferred (D47) drain as {@link RewireNext}. This is the\n\t * SELF-DEMAND path: a consumer issues `ctx.upNext([[PULL, { pullId, params }]])` to demand a pull\n\t * dep it ALSO reads — the cone-routed PULL reaches the pullId-holder, whose delivery loops back as a\n\t * FRESH wave (not a mid-fn re-entry → no D37). The consumer accepts one-wave latency (the\n\t * HTTP-request model). No node reference needed: the author writes the pullId verbatim.\n\t */\n\tupNext(msgs: Wave, towardDep?: number): void;\n\t/**\n\t * Read a dep's latest value by index (dynamicNode only, R-dynamic-node / D35).\n\t * Present only on dynamicNode fns; all declared deps still participate in wave\n\t * tracking. Under D49/R-resolved-undirty an unread dep's change still fires the fn,\n\t * which re-emits its (unchanged) output as a DATA occurrence — there is NO equals-\n\t * absorption; pair with distinctUntilChanged to suppress unchanged re-emits (opt-in).\n\t */\n\ttrack?(depIndex: number): unknown;\n\t[CTX_DEP_CACHE]?: CtxDepCache;\n\t[CTX_NODE_BINDING]?: CtxNodeBinding;\n}\n\n/** A node fn (R-fn-contract). Registered in a dispatcher pool, indexed by Handle. */\nexport type NodeFn = (ctx: Ctx) => void;\n\n/** Number of declared dep slots visible in this invocation. */\nexport function depCount(ctx: Ctx): number {\n\treturn ctx.waveData.length;\n}\n\n/** DATA/SENTINEL projection batches delivered by one dep in this invocation. */\nexport function depWaves(ctx: Ctx, depIndex: number): readonly (readonly unknown[])[] {\n\treturn ctx.waveData[depIndex] ?? [];\n}\n\n/** Flattened DATA projection for old event-counting operator bodies; null = no wave. */\nexport function depBatch(ctx: Ctx, depIndex: number): readonly unknown[] | null {\n\tconst waves = depWaves(ctx, depIndex);\n\tif (waves.length === 0) return null;\n\tconst flattened = waves.flat().filter((v) => v !== SENTINEL);\n\treturn flattened.length === 0 ? [] : flattened;\n}\n\n/** Latest cached DATA for a dep, derived from implementation-owned dep cache. */\nexport function depLatest(ctx: Ctx, depIndex: number): unknown {\n\treturn ctx[CTX_DEP_CACHE]?.latest[depIndex];\n}\n\n/** Terminal metadata for one dep: false = none, true = COMPLETE, otherwise ERROR payload. */\nexport function depTerminal(ctx: Ctx, depIndex: number): unknown {\n\tconst t = ctx.terminal[depIndex];\n\treturn t === undefined ? false : t;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC2CO,IAAM,WAAW;;;ACoHjB,SAAS,SAAS,KAAU,UAAmD;AACrF,SAAO,IAAI,SAAS,QAAQ,KAAK,CAAC;AACnC;AAGO,SAAS,SAAS,KAAU,UAA6C;AAC/E,QAAM,QAAQ,SAAS,KAAK,QAAQ;AACpC,MAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,QAAM,YAAY,MAAM,KAAK,EAAE,OAAO,CAAC,MAAM,MAAM,QAAQ;AAC3D,SAAO,UAAU,WAAW,IAA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AU,MAAM;AAAA,EAC7C,CAAC;AACF;AAEA,SAAS,WAAW,QAAkC,MAAyB;AAC9E,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA,SAAS,wDAAwD,OAAO,IAAI;AAAA,IAC5E,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,SAAS;AAAA,EACV;AACD;AAEA,SAAS,sBACR,OACqD;AACrD,MAAI,CAAC,eAAe,KAAK,KAAK,MAAM,SAAS,8BAA+B,QAAO;AACnF,QAAM,SAAS,MAAM;AACrB,SAAO,eAAe,MAAM,KAAK,OAAO,OAAO,OAAO,YAAY,OAAO,OAAO,SAAS;AAC1F;AAEA,SAAS,eAAe,OAAkD;AACzE,SAAO,OAAO,UAAU,YAAY,UAAU;AAC/C;","names":[]}
1
+ {"version":3,"sources":["../../src/orchestration/work-queue.ts","../../src/protocol/messages.ts","../../src/ctx/types.ts","../../src/orchestration/agent-runtime-common.ts","../../src/orchestration/work-queue-scheduled-readiness.ts"],"sourcesContent":["/**\n * Optional orchestration-over-workQueue recipe (D349/D353).\n *\n * Queue lifecycle remains disposition evidence. This module maps visible\n * ProcessEffectRequest facts to queue commands and maps terminal queue records\n * back to graph-visible orchestration evidence/status/issue facts.\n */\n\nimport { type Ctx, depBatch } from \"../ctx/types.js\";\nimport type { DataIssue } from \"../data/index.js\";\nimport type { Graph } from \"../graph/graph.js\";\nimport type { Node } from \"../node/node.js\";\nimport type { ProcessEffectRequest } from \"../orchestration/index.js\";\nimport type { WorkQueueCommand, WorkQueueRecord } from \"../work-queue/index.js\";\n\nexport type {\n\tWorkQueueLeaseExpirationCommandBundle,\n\tWorkQueueReadinessCandidate,\n\tWorkQueueReadinessCandidateKind,\n\tWorkQueueReadinessHandoffBundle,\n\tWorkQueueReadinessHandoffStatus,\n\tWorkQueueReadinessHandoffStatusState,\n\tWorkQueueReadinessHandoffViews,\n\tWorkQueueScheduledReadinessBundle,\n\tWorkQueueScheduledReadinessScheduleKind,\n\tWorkQueueScheduledReadinessStatus,\n\tWorkQueueScheduledReadinessStatusState,\n\tWorkQueueScheduledReadinessViews,\n} from \"./work-queue-scheduled-readiness.js\";\nexport {\n\tworkQueueLeaseExpirationCommandProjector,\n\tworkQueueReadinessHandoffProjector,\n\tworkQueueScheduledReadinessProjector,\n} from \"./work-queue-scheduled-readiness.js\";\n\nexport interface OrchestrationQueuedEffectPayload<TEffect = unknown> {\n\treadonly kind: \"orchestration-queued-effect\";\n\treadonly effect: ProcessEffectRequest<TEffect>;\n\treadonly idempotencyKey?: string;\n\treadonly sourceRefs?: readonly string[];\n\treadonly policyRefs?: readonly string[];\n\treadonly metadata?: Record<string, unknown>;\n}\n\nexport interface OrchestrationQueueEvidence {\n\treadonly kind: \"orchestration-queue-evidence\";\n\treadonly evidenceId: string;\n\treadonly effectId: string;\n\treadonly effectType: string;\n\treadonly workId: string;\n\treadonly queueRecordKind: WorkQueueRecord[\"kind\"];\n\treadonly result?: unknown;\n\treadonly error?: unknown;\n\treadonly recordedAtMs: number;\n}\n\nexport interface OrchestrationQueueStatus {\n\treadonly kind: \"orchestration-queue-status\";\n\treadonly state: \"evidence-recorded\" | \"mapping-issue\";\n\treadonly effectId?: string;\n\treadonly effectType?: string;\n\treadonly workId?: string;\n\treadonly queueRecordKind?: WorkQueueRecord[\"kind\"];\n\treadonly evidenceId?: string;\n\treadonly issues?: readonly DataIssue[];\n}\n\nexport interface OrchestrationQueueAuditRecord {\n\treadonly kind: \"orchestration-queue-audit\";\n\treadonly seq: number;\n\treadonly outcome: \"mapped\" | \"issue\";\n\treadonly effectId?: string;\n\treadonly effectType?: string;\n\treadonly workId?: string;\n\treadonly queueRecordKind?: WorkQueueRecord[\"kind\"];\n\treadonly evidenceId?: string;\n}\n\nexport interface OrchestrationWorkQueueRecipeOptions<TEffect = unknown> {\n\treadonly name?: string;\n\treadonly effectRequests?: Node<ProcessEffectRequest<TEffect>>;\n\treadonly records: Node<WorkQueueRecord<OrchestrationQueuedEffectPayload<TEffect>>>;\n}\n\nexport interface OrchestrationWorkQueueRecipeBundle<TEffect = unknown> {\n\treadonly submitCommands?: Node<WorkQueueCommand<OrchestrationQueuedEffectPayload<TEffect>>>;\n\treadonly evidence: Node<OrchestrationQueueEvidence>;\n\treadonly status: Node<OrchestrationQueueStatus>;\n\treadonly issues: Node<DataIssue>;\n\treadonly audit: Node<OrchestrationQueueAuditRecord>;\n}\n\ntype OrchestrationQueueFact =\n\t| { readonly kind: \"evidence\"; readonly evidence: OrchestrationQueueEvidence }\n\t| { readonly kind: \"status\"; readonly status: OrchestrationQueueStatus }\n\t| { readonly kind: \"issue\"; readonly issue: DataIssue }\n\t| { readonly kind: \"audit\"; readonly audit: OrchestrationQueueAuditRecord };\n\ninterface QueueState<TEffect> {\n\treadonly payloads: Map<string, OrchestrationQueuedEffectPayload<TEffect>>;\n\treadonly terminalRecords: Set<string>;\n\tauditSeq: number;\n}\n\n/** Build the optional D349 orchestration workQueue recipe. */\nexport function orchestrationWorkQueueRecipe<TEffect = unknown>(\n\tgraph: Graph,\n\topts: OrchestrationWorkQueueRecipeOptions<TEffect>,\n): OrchestrationWorkQueueRecipeBundle<TEffect> {\n\tconst name = opts.name ?? \"orchestrationWorkQueue\";\n\tconst submitCommands =\n\t\topts.effectRequests === undefined\n\t\t\t? undefined\n\t\t\t: graph.node<WorkQueueCommand<OrchestrationQueuedEffectPayload<TEffect>>>(\n\t\t\t\t\t[opts.effectRequests],\n\t\t\t\t\t(ctx) => {\n\t\t\t\t\t\tfor (const raw of depBatch(ctx, 0) ?? []) {\n\t\t\t\t\t\t\tctx.down([\n\t\t\t\t\t\t\t\t[\"DATA\", processEffectSubmitCommand(raw as ProcessEffectRequest<TEffect>)],\n\t\t\t\t\t\t\t]);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: `${name}/submitCommands`,\n\t\t\t\t\t\tfactory: \"orchestrationWorkQueueSubmitCommands\",\n\t\t\t\t\t\tcompleteWhenDepsComplete: false,\n\t\t\t\t\t\terrorWhenDepsError: false,\n\t\t\t\t\t},\n\t\t\t\t);\n\tconst runtime = graph.node<OrchestrationQueueFact>(\n\t\t[opts.records],\n\t\t(ctx) => {\n\t\t\tconst state = ctx.state.get<QueueState<TEffect>>() ?? {\n\t\t\t\tpayloads: new Map(),\n\t\t\t\tterminalRecords: new Set(),\n\t\t\t\tauditSeq: 0,\n\t\t\t};\n\t\t\tfor (const raw of depBatch(ctx, 0) ?? []) {\n\t\t\t\treduceRecord(ctx, state, raw as WorkQueueRecord<OrchestrationQueuedEffectPayload<TEffect>>);\n\t\t\t}\n\t\t\tctx.state.set(state);\n\t\t},\n\t\t{\n\t\t\tname: `${name}/runtime`,\n\t\t\tfactory: \"orchestrationWorkQueueRuntime\",\n\t\t\tpartial: true,\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\treturn {\n\t\t...(submitCommands === undefined ? {} : { submitCommands }),\n\t\tevidence: project(\n\t\t\tgraph,\n\t\t\truntime,\n\t\t\t`${name}/evidence`,\n\t\t\t\"orchestrationWorkQueueEvidence\",\n\t\t\t(fact) => (fact.kind === \"evidence\" ? fact.evidence : undefined),\n\t\t),\n\t\tstatus: project(graph, runtime, `${name}/status`, \"orchestrationWorkQueueStatus\", (fact) =>\n\t\t\tfact.kind === \"status\" ? fact.status : undefined,\n\t\t),\n\t\tissues: project(graph, runtime, `${name}/issues`, \"orchestrationWorkQueueIssues\", (fact) =>\n\t\t\tfact.kind === \"issue\" ? fact.issue : undefined,\n\t\t),\n\t\taudit: project(graph, runtime, `${name}/audit`, \"orchestrationWorkQueueAudit\", (fact) =>\n\t\t\tfact.kind === \"audit\" ? fact.audit : undefined,\n\t\t),\n\t};\n}\n\nexport function processEffectSubmitCommand<TEffect>(\n\teffect: ProcessEffectRequest<TEffect>,\n\topts: {\n\t\treadonly workId?: string;\n\t\treadonly commandId?: string;\n\t\treadonly idempotencyKey?: string;\n\t\treadonly sourceRefs?: readonly string[];\n\t\treadonly policyRefs?: readonly string[];\n\t\treadonly metadata?: Record<string, unknown>;\n\t} = {},\n): WorkQueueCommand<OrchestrationQueuedEffectPayload<TEffect>> {\n\tconst payload: OrchestrationQueuedEffectPayload<TEffect> = {\n\t\tkind: \"orchestration-queued-effect\",\n\t\teffect,\n\t\tidempotencyKey: opts.idempotencyKey ?? effect.id,\n\t\tsourceRefs: opts.sourceRefs,\n\t\tpolicyRefs: opts.policyRefs,\n\t\tmetadata: opts.metadata,\n\t};\n\treturn {\n\t\tkind: \"submit\",\n\t\tcommandId: opts.commandId ?? `${effect.id}:orchestration-work-queue-submit`,\n\t\tworkId: opts.workId ?? `process-effect:${effect.id}`,\n\t\tpayload,\n\t\tidempotencyKey: opts.idempotencyKey ?? effect.id,\n\t\tsourceRefs: opts.sourceRefs,\n\t\tpolicyRefs: opts.policyRefs,\n\t};\n}\n\nfunction reduceRecord<TEffect>(\n\tctx: Ctx,\n\tstate: QueueState<TEffect>,\n\trecord: WorkQueueRecord<OrchestrationQueuedEffectPayload<TEffect>>,\n): void {\n\tif (record.kind === \"work-admitted\") {\n\t\tif (isQueuedEffectPayload(record.payload)) {\n\t\t\tstate.payloads.set(record.workId, record.payload);\n\t\t} else {\n\t\t\temitIssue(ctx, state, record, \"orchestration-queue-malformed-payload\");\n\t\t}\n\t\treturn;\n\t}\n\tif (!isTerminalEvidenceRecord(record)) return;\n\tconst key = `${record.kind}:${record.recordSeq}`;\n\tif (state.terminalRecords.has(key)) return;\n\tstate.terminalRecords.add(key);\n\tconst payload = record.workId === undefined ? undefined : state.payloads.get(record.workId);\n\tif (payload === undefined) {\n\t\temitIssue(ctx, state, record, \"orchestration-queue-record-without-payload\");\n\t\treturn;\n\t}\n\tconst evidence = evidenceFromRecord(record, payload);\n\temit(ctx, { kind: \"evidence\", evidence });\n\temit(ctx, { kind: \"status\", status: statusFromEvidence(evidence, payload) });\n\tstate.auditSeq += 1;\n\temit(ctx, { kind: \"audit\", audit: auditFromEvidence(state.auditSeq, evidence, payload) });\n}\n\nfunction isTerminalEvidenceRecord(record: WorkQueueRecord): boolean {\n\treturn (\n\t\trecord.kind === \"work-completed\" ||\n\t\trecord.kind === \"attempt-completed\" ||\n\t\trecord.kind === \"work-canceled\" ||\n\t\trecord.kind === \"work-dead-lettered\" ||\n\t\trecord.kind === \"attempt-failed\"\n\t);\n}\n\nfunction evidenceFromRecord<TEffect>(\n\trecord: WorkQueueRecord<OrchestrationQueuedEffectPayload<TEffect>>,\n\tpayload: OrchestrationQueuedEffectPayload<TEffect>,\n): OrchestrationQueueEvidence {\n\treturn {\n\t\tkind: \"orchestration-queue-evidence\",\n\t\tevidenceId: `work-queue:${record.recordSeq}`,\n\t\teffectId: payload.effect.id,\n\t\teffectType: payload.effect.type,\n\t\tworkId: record.workId ?? `unknown:${record.recordSeq}`,\n\t\tqueueRecordKind: record.kind,\n\t\tresult: \"result\" in record ? record.result : undefined,\n\t\terror: \"error\" in record ? record.error : undefined,\n\t\trecordedAtMs: record.recordedAtMs,\n\t};\n}\n\nfunction statusFromEvidence<TEffect>(\n\tevidence: OrchestrationQueueEvidence,\n\tpayload: OrchestrationQueuedEffectPayload<TEffect>,\n): OrchestrationQueueStatus {\n\treturn {\n\t\tkind: \"orchestration-queue-status\",\n\t\tstate: \"evidence-recorded\",\n\t\teffectId: payload.effect.id,\n\t\teffectType: payload.effect.type,\n\t\tworkId: evidence.workId,\n\t\tqueueRecordKind: evidence.queueRecordKind,\n\t\tevidenceId: evidence.evidenceId,\n\t};\n}\n\nfunction auditFromEvidence<TEffect>(\n\tseq: number,\n\tevidence: OrchestrationQueueEvidence,\n\tpayload: OrchestrationQueuedEffectPayload<TEffect>,\n): OrchestrationQueueAuditRecord {\n\treturn {\n\t\tkind: \"orchestration-queue-audit\",\n\t\tseq,\n\t\toutcome: \"mapped\",\n\t\teffectId: payload.effect.id,\n\t\teffectType: payload.effect.type,\n\t\tworkId: evidence.workId,\n\t\tqueueRecordKind: evidence.queueRecordKind,\n\t\tevidenceId: evidence.evidenceId,\n\t};\n}\n\nfunction auditFromIssue(\n\tseq: number,\n\trecord: WorkQueueRecord<unknown>,\n): OrchestrationQueueAuditRecord {\n\treturn {\n\t\tkind: \"orchestration-queue-audit\",\n\t\tseq,\n\t\toutcome: \"issue\",\n\t\tworkId: record.workId,\n\t\tqueueRecordKind: record.kind,\n\t};\n}\n\nfunction project<T>(\n\tgraph: Graph,\n\truntime: Node<OrchestrationQueueFact>,\n\tname: string,\n\tfactory: string,\n\tpick: (fact: OrchestrationQueueFact) => T | undefined,\n): Node<T> {\n\treturn graph.node<T>(\n\t\t[runtime],\n\t\t(ctx) => {\n\t\t\tfor (const fact of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst value = pick(fact as OrchestrationQueueFact);\n\t\t\t\tif (value !== undefined) ctx.down([[\"DATA\", value]]);\n\t\t\t}\n\t\t},\n\t\t{ name, factory, partial: true, completeWhenDepsComplete: false, errorWhenDepsError: false },\n\t);\n}\n\nfunction emit(ctx: Ctx, fact: OrchestrationQueueFact): void {\n\tctx.down([[\"DATA\", fact]]);\n}\n\nfunction emitIssue(\n\tctx: Ctx,\n\tstate: QueueState<unknown>,\n\trecord: WorkQueueRecord<unknown>,\n\tcode: string,\n): void {\n\tconst issue = queueIssue(record, code);\n\temit(ctx, { kind: \"issue\", issue });\n\tstate.auditSeq += 1;\n\temit(ctx, {\n\t\tkind: \"status\",\n\t\tstatus: {\n\t\t\tkind: \"orchestration-queue-status\",\n\t\t\tstate: \"mapping-issue\",\n\t\t\tworkId: record.workId,\n\t\t\tqueueRecordKind: record.kind,\n\t\t\tissues: [issue],\n\t\t},\n\t});\n\temit(ctx, {\n\t\tkind: \"audit\",\n\t\taudit: auditFromIssue(state.auditSeq, record),\n\t});\n}\n\nfunction queueIssue(record: WorkQueueRecord<unknown>, code: string): DataIssue {\n\treturn {\n\t\tkind: \"issue\",\n\t\tcode,\n\t\tmessage: `Orchestration workQueue recipe could not map record '${record.kind}'`,\n\t\tseverity: \"error\",\n\t\tsource: \"orchestration.workQueue\",\n\t\tdetails: record,\n\t};\n}\n\nfunction isQueuedEffectPayload<TEffect>(\n\tvalue: unknown,\n): value is OrchestrationQueuedEffectPayload<TEffect> {\n\tif (!isObjectRecord(value) || value.kind !== \"orchestration-queued-effect\") return false;\n\tconst effect = value.effect;\n\treturn isObjectRecord(effect) && typeof effect.id === \"string\" && typeof effect.type === \"string\";\n}\n\nfunction isObjectRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n","/**\n * Wave-protocol message types and the tier const table.\n *\n * Canonical authority: ~/src/graphrefly/spec/rules.jsonl\n * R-msg-format, R-msg-closed-set, R-tier (D34), R-data-payload, R-sentinel.\n */\n\n/** Opaque pause-lock / pull identifier (R-pause-lockset, R-pull). */\nexport type LockId = string | symbol;\n\n/** Explicit pull demand payload (D269/D272). Params are holder-visible context, never DATA-up. */\nexport interface PullDemand {\n\treadonly pullId: LockId;\n\treadonly params?: unknown;\n}\n\n/**\n * The CLOSED set of 11 message types (R-msg-closed-set / D9 + D269 + START handshake).\n * No open set, no user-defined custom types. Adding a type is a spec change.\n */\nexport type Message =\n\t| readonly [\"START\"]\n\t| readonly [\"DIRTY\"]\n\t| readonly [\"DATA\", unknown]\n\t| readonly [\"RESOLVED\"]\n\t| readonly [\"INVALIDATE\"]\n\t| readonly [\"COMPLETE\"]\n\t| readonly [\"ERROR\", unknown]\n\t| readonly [\"TEARDOWN\"]\n\t| readonly [\"PAUSE\", LockId]\n\t| readonly [\"RESUME\", LockId]\n\t| readonly [\"PULL\", PullDemand];\n\n/** One array of messages delivered in one call = one Wave (R-wave-boundary). */\nexport type Wave = readonly Message[];\n\n/** The message-type tag (the first tuple element). */\nexport type MessageType = Message[0];\n\n/**\n * SENTINEL = absence-of-DATA (R-sentinel / D16). TS representation is `undefined`.\n * Never a valid DATA payload; `null` IS a valid DATA value (domain-level absence).\n */\nexport const SENTINEL = undefined;\n\n/** R-data-payload: ERROR payloads must not collide with terminal metadata shorthand. */\nexport function isInvalidErrorPayload(v: unknown): boolean {\n\treturn v === SENTINEL || typeof v === \"boolean\";\n}\n\n/** R-data-payload / D78: host-language failures that collide with ctx.terminal shorthand become diagnostics. */\nexport function errorPayload(reason: unknown, fallback = \"error without a valid payload\"): unknown {\n\treturn isInvalidErrorPayload(reason) ? new Error(fallback) : reason;\n}\n\nexport const TIER_START = 0;\nexport const TIER_CONTROL = 1;\nexport const TIER_NOTIFICATION = 2;\nexport const TIER_VALUE = 3;\nexport const TIER_SETTLE = 4;\nexport const TIER_TERMINAL = 5;\nexport const TIER_TEARDOWN = 6;\n\n/**\n * Tier const table (R-tier / D34). Tiers below value dispatch immediately; value\n * and above are batch-deferred. This is a compile-time const table (D18), not runtime config.\n */\nconst TIER: Record<MessageType, number> = {\n\tSTART: TIER_START,\n\tPAUSE: TIER_CONTROL,\n\tRESUME: TIER_CONTROL,\n\tPULL: TIER_CONTROL,\n\tDIRTY: TIER_NOTIFICATION,\n\tDATA: TIER_VALUE,\n\tRESOLVED: TIER_VALUE,\n\tINVALIDATE: TIER_SETTLE,\n\tCOMPLETE: TIER_TERMINAL,\n\tERROR: TIER_TERMINAL,\n\tTEARDOWN: TIER_TEARDOWN,\n};\n\nexport function messageTier(t: MessageType): number {\n\treturn TIER[t];\n}\n\n/** Value and above are deferred inside a batch (DATA/RESOLVED/INVALIDATE/terminal/teardown). */\nexport function isDeferredTier(t: MessageType): boolean {\n\treturn TIER[t] >= TIER_VALUE;\n}\n\n/** Value-tier messages (DATA/RESOLVED) occupy the tier-3 slot. */\nexport function isValueTier(t: MessageType): boolean {\n\treturn TIER[t] === TIER_VALUE;\n}\n\n/** The pause buffer holds the settle slice only: value-tier DATA/RESOLVED plus INVALIDATE. */\nexport function isPauseBufferedTier(t: MessageType): boolean {\n\tconst tier = TIER[t];\n\treturn tier === TIER_VALUE || tier === TIER_SETTLE;\n}\n\n/**\n * A TERMINAL message = tier 5 (COMPLETE | ERROR), R-tier / D34. Detected via the CENTRAL tier\n * table, NOT a per-variant `=== \"COMPLETE\" || === \"ERROR\"` check — so terminal routing stays\n * driven by the one const table (feedback_use_tier_for_signal_routing); discriminate COMPLETE vs\n * ERROR within the tier by the message type only where the handling actually differs.\n */\nexport function isTerminal(t: MessageType): boolean {\n\treturn TIER[t] === TIER_TERMINAL;\n}\n\n/**\n * ctx.up carries control/demand tiers only (R-ctx-up / D269): DIRTY, PAUSE, RESUME, PULL,\n * INVALIDATE, TEARDOWN. DATA/RESOLVED (tier 3) and COMPLETE/ERROR (tier 5) are\n * down-only.\n */\nexport function isUpAllowed(t: MessageType): boolean {\n\tconst tier = TIER[t];\n\treturn tier !== TIER_VALUE && tier !== TIER_TERMINAL;\n}\n","/**\n * The fn-invocation context and per-dep input shapes.\n *\n * Canonical authority: ~/src/graphrefly/spec/rules.jsonl\n * R-fn-contract (D8/D27), R-ctx-state (D23/D29), R-cleanup-hooks (D28), R-ctx-up.\n */\n\nimport type { Dispatcher } from \"../dispatcher/index.js\";\nimport type { EnvironmentDrivers } from \"../graph/environment.js\";\nimport type { Node } from \"../node/node.js\";\nimport { type Message, type PullDemand, SENTINEL, type Wave } from \"../protocol/messages.js\";\n\n/** A downstream sink callback (the only way to connect to a node's output). */\nexport type Sink = (msg: Message, delivery?: DeliveryMeta) => void;\n\n/** Internal delivery metadata used to preserve the upstream `ctx.down(msgs)` wave boundary. */\nexport interface DeliveryMeta {\n\treadonly wave: object;\n\treadonly last: boolean;\n}\n\n/**\n * Internal current-value reader. It is deliberately a symbol-backed implementation detail:\n * raw ctx exposes `waveData` + `terminal`; helpers below derive from that plus this dep cache.\n */\nexport const CTX_DEP_CACHE: unique symbol = Symbol(\"graphrefly.ctx.depCache\");\n\nexport interface CtxDepCache {\n\treadonly latest: readonly unknown[];\n}\n\n/** Internal node-construction binding for graph-local helper-created deps. */\nexport const CTX_NODE_BINDING: unique symbol = Symbol(\"graphrefly.ctx.nodeBinding\");\n\nexport interface CtxNodeBinding {\n\treadonly dispatcher: Dispatcher;\n\tcreate<T>(factory: () => Node<T>): Node<T>;\n}\n\n/** Per-dep wave projections: dep -> waves -> values/SENTINEL markers. */\nexport type WaveData = readonly (readonly (readonly unknown[])[])[];\n\n/** Terminal metadata parallel to `waveData`: false = none, true = COMPLETE, otherwise ERROR payload. */\nexport type TerminalData = readonly unknown[];\n\nexport function isTerminalNone(t: unknown): boolean {\n\treturn t === false || t === undefined;\n}\n\nexport function isTerminalComplete(t: unknown): t is true {\n\treturn t === true;\n}\n\nexport function isTerminalError(t: unknown): boolean {\n\treturn !isTerminalNone(t) && !isTerminalComplete(t);\n}\n\nexport function terminalErrorValue(t: unknown): unknown {\n\treturn isTerminalError(t) ? t : undefined;\n}\n\n/**\n * Per-node private cross-wave state (R-ctx-state / D23,D29). Default fresh-lifecycle\n * wipe; `persist(true)` keeps it across lifecycle transitions.\n */\nexport interface CtxState {\n\tget<S = unknown>(): S | undefined;\n\tset<S = unknown>(v: S): void;\n\tpersist(on?: boolean): void;\n}\n\n/**\n * Deferred SELF-rewire (R-rewire-deferred / D47). A node fn may, DURING its run, request a\n * mutation of its OWN dep set; the request is QUEUED and applied at the committed wave boundary\n * (after the current wave settles / batch commit / final-lock RESUME) as a fresh wave, reusing\n * R-rewire surgical/Option-C semantics (D42). This is the ONLY legal self-triggered rewire — an\n * IMMEDIATE in-fn `node.subscribeDep/unsubscribeDep/replaceDeps` is the D37 mid-fn feedback-cycle ERROR. An\n * added cached dep pushes `[DIRTY,DATA]` on the boundary wave (R-push-subscribe); a removed dep\n * is drained and, if it loses its last subscriber, `_deactivate`s + fires `onDeactivation`\n * (input-side teardown — the basis for higher-order operator cancellation / abortInFlight).\n */\nexport interface RewireNext {\n\t/** Defer subscribing to a dep (paired with the re-supplied fn — positional fn-deps lock, SD-1). */\n\tsubscribeDep(dep: Node<unknown>, fn: NodeFn): void;\n\t/** Defer unsubscribing from a dep (its source is torn down if it loses its last subscriber). */\n\tunsubscribeDep(dep: Node<unknown>, fn: NodeFn): void;\n\t/** Defer replacing the whole dep set (surgical: kept deps untouched, removed drained, added fresh-subscribe). */\n\treplaceDeps(deps: Node<unknown>[], fn: NodeFn): void;\n}\n\n/**\n * The single argument to a node fn: `(ctx) => void` (R-fn-contract / D8). All emission\n * is explicit via `ctx.down`; there is no return-value framing.\n */\nexport interface Ctx {\n\t/**\n\t * Emit upstream toward deps — control tiers only (R-ctx-up). IMMEDIATE. `towardDep` (a dep index)\n\t * routes the wave up ONE declared edge (R-up-routing directed-up); omitted = broadcast up all deps.\n\t * A pull DEMAND is `up([[PULL, { pullId, params }]])` — but for a SELF-demand (demanding a dep\n\t * this fn also reads) use {@link Ctx.upNext} instead, since an immediate demand whose delivery loops back\n\t * re-enters this fn mid-wave (D37 / R-reentrancy).\n\t */\n\tup(msgs: Wave, towardDep?: number): void;\n\t/** Emit downstream toward sinks. */\n\tdown(msgs: Wave): void;\n\t/**\n\t * The single raw dep-value input surface (R-ctx-wave-data / D77): dep -> upstream waves ->\n\t * per-wave DATA payloads and INVALIDATE/SENTINEL markers. `waveData[i] = []` means dep i\n\t * delivered no wave to this invocation; `waveData[i] = [[]]` means RESOLVED-only.\n\t */\n\twaveData: WaveData;\n\t/** Terminal metadata for the same invocation; terminal values never enter `waveData`. */\n\tterminal: TerminalData;\n\tstate: CtxState;\n\t/** Release external resources on deactivation (R-cleanup-hooks). */\n\tonDeactivation(fn: () => void): void;\n\t/** Flush on INVALIDATE (R-cleanup-hooks). */\n\tonInvalidate(fn: () => void): void;\n\t/** Graph-owned environment drivers for source/adapter boundaries (D130/D131). */\n\tenvironment(): EnvironmentDrivers;\n\t/** Holder-visible context for a PULL-caused invocation (D272); absent for ordinary waves. */\n\treadonly pull?: PullDemand;\n\t/**\n\t * Deferred SELF-rewire (R-rewire-deferred / D47) — the substrate affordance higher-order\n\t * operators (switchMap/mergeMap/concatMap/exhaustMap/flatMap) use to grow/shrink their own\n\t * inner-source dep set in response to their own data. Always present; see {@link RewireNext}.\n\t */\n\trewireNext: RewireNext;\n\t/**\n\t * Deferred up — the boundary-deferred form of {@link Ctx.up} (R-up-routing / R-pull / D59). Routes\n\t * `msgs` up from this node at the COMMITTED wave boundary (broadcast, or up the single `towardDep`\n\t * edge), riding the same R-rewire-deferred (D47) drain as {@link RewireNext}. This is the\n\t * SELF-DEMAND path: a consumer issues `ctx.upNext([[PULL, { pullId, params }]])` to demand a pull\n\t * dep it ALSO reads — the cone-routed PULL reaches the pullId-holder, whose delivery loops back as a\n\t * FRESH wave (not a mid-fn re-entry → no D37). The consumer accepts one-wave latency (the\n\t * HTTP-request model). No node reference needed: the author writes the pullId verbatim.\n\t */\n\tupNext(msgs: Wave, towardDep?: number): void;\n\t/**\n\t * Read a dep's latest value by index (dynamicNode only, R-dynamic-node / D35).\n\t * Present only on dynamicNode fns; all declared deps still participate in wave\n\t * tracking. Under D49/R-resolved-undirty an unread dep's change still fires the fn,\n\t * which re-emits its (unchanged) output as a DATA occurrence — there is NO equals-\n\t * absorption; pair with distinctUntilChanged to suppress unchanged re-emits (opt-in).\n\t */\n\ttrack?(depIndex: number): unknown;\n\t[CTX_DEP_CACHE]?: CtxDepCache;\n\t[CTX_NODE_BINDING]?: CtxNodeBinding;\n}\n\n/** A node fn (R-fn-contract). Registered in a dispatcher pool, indexed by Handle. */\nexport type NodeFn = (ctx: Ctx) => void;\n\n/** Number of declared dep slots visible in this invocation. */\nexport function depCount(ctx: Ctx): number {\n\treturn ctx.waveData.length;\n}\n\n/** DATA/SENTINEL projection batches delivered by one dep in this invocation. */\nexport function depWaves(ctx: Ctx, depIndex: number): readonly (readonly unknown[])[] {\n\treturn ctx.waveData[depIndex] ?? [];\n}\n\n/** Flattened DATA projection for old event-counting operator bodies; null = no wave. */\nexport function depBatch(ctx: Ctx, depIndex: number): readonly unknown[] | null {\n\tconst waves = depWaves(ctx, depIndex);\n\tif (waves.length === 0) return null;\n\tconst flattened = waves.flat().filter((v) => v !== SENTINEL);\n\treturn flattened.length === 0 ? [] : flattened;\n}\n\n/** Latest cached DATA for a dep, derived from implementation-owned dep cache. */\nexport function depLatest(ctx: Ctx, depIndex: number): unknown {\n\treturn ctx[CTX_DEP_CACHE]?.latest[depIndex];\n}\n\n/** Terminal metadata for one dep: false = none, true = COMPLETE, otherwise ERROR payload. */\nexport function depTerminal(ctx: Ctx, depIndex: number): unknown {\n\tconst t = ctx.terminal[depIndex];\n\treturn t === undefined ? false : t;\n}\n","import { type Ctx, depBatch } from \"../ctx/types.js\";\nimport type { DataIssue } from \"../data/index.js\";\nimport type { Graph } from \"../graph/graph.js\";\nimport type { Node } from \"../node/node.js\";\nimport type { AgentNeed } from \"./agent-runtime-types-agent.js\";\nimport type {\n\tAgentOutputEnvelope,\n\tExecutorArtifactMaterial,\n\tSizeCapacityEvidence,\n\tSourceRef,\n} from \"./agent-runtime-types-core.js\";\nimport type {\n\tToolProviderAdapterInput,\n\tToolProviderExecutionPolicy,\n\tToolProviderPublicTextPolicy,\n} from \"./agent-runtime-types-tool.js\";\n\nexport function uniqueSourceRefs(sourceRefs: readonly SourceRef[]): readonly SourceRef[] {\n\tconst seen = new Set<string>();\n\tconst unique: SourceRef[] = [];\n\tfor (const sourceRef of sourceRefs) {\n\t\tconst key = `${sourceRef.kind}:${sourceRef.id}:${JSON.stringify(sourceRef.metadata ?? {})}`;\n\t\tif (seen.has(key)) continue;\n\t\tseen.add(key);\n\t\tunique.push(sourceRef);\n\t}\n\treturn Object.freeze(unique);\n}\n\nexport function stableJsonStringify(value: unknown): string {\n\tconst seen = new WeakSet<object>();\n\treturn JSON.stringify(value, (_key, child) => {\n\t\tif (typeof child === \"bigint\") return child.toString();\n\t\tif (typeof child === \"function\") return \"[Function]\";\n\t\tif (!isRecord(child) && !Array.isArray(child)) return child;\n\t\tif (seen.has(child)) return \"[Circular]\";\n\t\tseen.add(child);\n\t\tif (Array.isArray(child)) return child;\n\t\treturn Object.keys(child)\n\t\t\t.sort()\n\t\t\t.reduce<Record<string, unknown>>((out, key) => {\n\t\t\t\tout[key] = child[key];\n\t\t\t\treturn out;\n\t\t\t}, {});\n\t});\n}\n\nexport function stableStringHash(value: string): string {\n\tlet hash = 0x811c9dc5;\n\tfor (let i = 0; i < value.length; i += 1) {\n\t\thash ^= value.charCodeAt(i);\n\t\thash = Math.imul(hash, 0x01000193);\n\t}\n\treturn (hash >>> 0).toString(36);\n}\n\nexport function cloneGraphVisibleMaterial(value: unknown): unknown {\n\tif (!isRecord(value) && !Array.isArray(value)) return value;\n\tif (Array.isArray(value))\n\t\treturn Object.freeze(value.map((item) => cloneGraphVisibleMaterial(item)));\n\treturn Object.freeze(\n\t\tObject.entries(value).reduce<Record<string, unknown>>((record, [key, child]) => {\n\t\t\trecord[key] = cloneGraphVisibleMaterial(child);\n\t\t\treturn record;\n\t\t}, {}),\n\t);\n}\n\nexport function projectRuntimeFact<T, TOut>(\n\tgraph: Graph,\n\truntime: Node<T>,\n\tname: string,\n\tfactory: string,\n\tpick: (fact: T) => TOut | undefined,\n): Node<TOut> {\n\treturn graph.node<TOut>(\n\t\t[runtime],\n\t\t(ctx) => {\n\t\t\tfor (const fact of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst typed = fact as T;\n\t\t\t\tconst value = pick(typed);\n\t\t\t\tif (value !== undefined) ctx.down([[\"DATA\", value]]);\n\t\t\t}\n\t\t},\n\t\t{ name, factory },\n\t);\n}\n\nexport function forEachDepBatch(\n\tctx: Ctx,\n\tstart: number,\n\tcount: number,\n\tfn: (value: unknown) => void,\n): void {\n\tfor (let i = 0; i < count; i += 1) {\n\t\tfor (const value of depBatch(ctx, start + i) ?? []) fn(value);\n\t}\n}\n\nexport function forbiddenDataKeys(\n\tvalue: unknown,\n\tpath: readonly (string | number)[] = [],\n\tseen: WeakSet<object> = new WeakSet(),\n): readonly { readonly path: readonly (string | number)[]; readonly reason: string }[] {\n\tif (typeof value === \"function\") return [{ path, reason: \"function-value\" }];\n\tif (typeof value === \"symbol\" || typeof value === \"bigint\") {\n\t\treturn [{ path, reason: \"non-graph-visible-primitive\" }];\n\t}\n\tif (!isRecord(value) && !Array.isArray(value)) return [];\n\tif (typeof value === \"object\" && value !== null) {\n\t\tif (seen.has(value)) return [];\n\t\tseen.add(value);\n\t}\n\tconst issues: { readonly path: readonly (string | number)[]; readonly reason: string }[] = [];\n\tif (Array.isArray(value)) {\n\t\tvalue.forEach((item, index) => {\n\t\t\tissues.push(...forbiddenDataKeys(item, [...path, index], seen));\n\t\t});\n\t\treturn issues;\n\t}\n\tif (!isPlainRecord(value)) return [{ path, reason: \"non-plain-runtime-object\" }];\n\tconst symbolKeys = Object.getOwnPropertySymbols(value);\n\tif (symbolKeys.length > 0) {\n\t\tissues.push({ path, reason: \"symbol-key\" });\n\t}\n\tfor (const [key, child] of Object.entries(value)) {\n\t\tconst nextPath = [...path, key];\n\t\tif (\n\t\t\t/^(apiKey|api_key|secret|client|transport|subprocess|sdk|oauth|credential|credentials|accessToken|access_token|refreshToken|refresh_token|idToken|id_token|token|password|passphrase|authorization|authHeader|auth_header|bearer|privateKey|private_key|sessionCookie|session_cookie|cookie)$/i.test(\n\t\t\t\tkey,\n\t\t\t)\n\t\t) {\n\t\t\tissues.push({ path: nextPath, reason: \"forbidden-runtime-key\" });\n\t\t}\n\t\tissues.push(...forbiddenDataKeys(child, nextPath, seen));\n\t}\n\treturn issues;\n}\n\nexport function forbiddenGraphVisibleMaterialIssues(\n\tvalue: unknown,\n\tsubjectRef: SourceRef,\n\tarea: string,\n): readonly DataIssue[] {\n\tif (value === undefined) return [];\n\tconst forbidden = publicMaterialForbiddenKeys(value, \"provider\");\n\tif (forbidden.length === 0) return [];\n\treturn Object.freeze(\n\t\tforbidden.map((entry) =>\n\t\t\tdataIssue(\n\t\t\t\t\"tool-provider-catalog-forbidden-runtime-material\",\n\t\t\t\t\"Tool provider catalog material must not contain runtime-private adapter material.\",\n\t\t\t\t{ subjectId: subjectRef.id, refs: [subjectRef], details: { area, reason: entry.reason } },\n\t\t\t),\n\t\t),\n\t);\n}\n\nexport function forbiddenAdapterInputMaterialIssues(\n\tvalue: unknown,\n\tsubjectRef: SourceRef,\n\tarea: string,\n): readonly DataIssue[] {\n\tif (value === undefined) return [];\n\tconst forbidden = publicMaterialForbiddenKeys(value, \"provider\");\n\tif (forbidden.length === 0) return [];\n\treturn Object.freeze(\n\t\tforbidden.map((entry) =>\n\t\t\tdataIssue(\n\t\t\t\t\"tool-provider-adapter-input-forbidden-runtime-material\",\n\t\t\t\t\"Tool provider adapter input material must not contain runtime-private adapter material.\",\n\t\t\t\t{ subjectId: subjectRef.id, refs: [subjectRef], details: { area, reason: entry.reason } },\n\t\t\t),\n\t\t),\n\t);\n}\n\nexport type PublicMaterialMode = \"graph\" | \"provider\";\n\nexport function sanitizeAdapterInputSourceRefs(\n\tsourceRefs: readonly SourceRef[],\n): readonly SourceRef[] {\n\treturn canonicalPublicSourceRefs(sourceRefs);\n}\n\nexport function sanitizeGraphVisibleRecord<T extends Record<string, unknown> | undefined>(\n\tvalue: T,\n\tpolicy?: ToolProviderPublicTextPolicy,\n): T | undefined {\n\treturn sanitizePublicRecord(value, { mode: \"graph\", policy });\n}\n\nexport function sanitizeProviderGraphVisibleRecord<T extends Record<string, unknown> | undefined>(\n\tvalue: T,\n\tpolicy?: ToolProviderPublicTextPolicy,\n): T | undefined {\n\treturn sanitizePublicRecord(value, { mode: \"provider\", policy });\n}\n\nexport function canonicalPublicSourceRefs(sourceRefs: readonly SourceRef[]): readonly SourceRef[] {\n\treturn uniqueSourceRefs(\n\t\tsourceRefs.map((sourceRef) => {\n\t\t\tconst metadata = sanitizePublicRecord(sourceRef.metadata, { mode: \"provider\" });\n\t\t\treturn metadata === undefined\n\t\t\t\t? { kind: sourceRef.kind, id: sourceRef.id }\n\t\t\t\t: { kind: sourceRef.kind, id: sourceRef.id, metadata };\n\t\t}),\n\t);\n}\n\nexport function sanitizePublicRecord<T extends Record<string, unknown> | undefined>(\n\tvalue: T,\n\topts: {\n\t\treadonly mode: PublicMaterialMode;\n\t\treadonly policy?: ToolProviderPublicTextPolicy;\n\t},\n): T | undefined {\n\tif (value === undefined || publicMaterialForbiddenKeys(value, opts.mode).length > 0) {\n\t\treturn undefined;\n\t}\n\treturn Object.freeze(boundRecordStrings(value, maxPublicMetadataStringChars(opts.policy))) as T;\n}\n\nexport function publicMaterialForbiddenKeys(\n\tvalue: unknown,\n\tmode: PublicMaterialMode,\n): readonly { readonly path: readonly (string | number)[]; readonly reason: string }[] {\n\tconst forbidden = [...forbiddenDataKeys(value)];\n\tif (mode === \"provider\") forbidden.push(...forbiddenProviderRawMaterialKeys(value));\n\treturn forbidden;\n}\n\nexport function unlockedToolProviderPolicyOverrides(\n\toverrides:\n\t\t| Partial<Omit<ToolProviderExecutionPolicy, \"kind\" | \"policyId\" | \"providerId\">>\n\t\t| undefined,\n): Partial<Omit<ToolProviderExecutionPolicy, \"kind\" | \"policyId\" | \"providerId\">> | undefined {\n\tif (overrides === undefined) return undefined;\n\tconst rest = { ...(overrides as Record<string, unknown>) };\n\tdelete rest.kind;\n\tdelete rest.policyId;\n\tdelete rest.providerId;\n\treturn rest as Partial<Omit<ToolProviderExecutionPolicy, \"kind\" | \"policyId\" | \"providerId\">>;\n}\n\nexport function sanitizeAgentOutputEnvelope<T>(\n\tenvelope: AgentOutputEnvelope<T>,\n\tinput: ToolProviderAdapterInput,\n\tpolicy: ToolProviderPublicTextPolicy | undefined,\n\tissues: DataIssue[],\n): AgentOutputEnvelope<T> {\n\tconst summary =\n\t\tenvelope.summary === undefined\n\t\t\t? undefined\n\t\t\t: boundedPublicText(envelope.summary, \"summary\", input, policy, issues);\n\tconst metadata = sanitizeRuntimeMetadata(envelope.metadata, input, policy, issues);\n\tif (metadata === undefined && envelope.metadata !== undefined) {\n\t\tissues.push(\n\t\t\tdataIssue(\n\t\t\t\t\"tool-provider-adapter-runtime-metadata-redacted\",\n\t\t\t\t\"Tool provider adapter runtime metadata was omitted because it contained runtime-private material.\",\n\t\t\t\t{\n\t\t\t\t\tsubjectId: input.requestId,\n\t\t\t\t\trefs: [ref(\"tool-provider-adapter-input\", input.adapterInputId)],\n\t\t\t\t\tseverity: \"warning\",\n\t\t\t\t},\n\t\t\t),\n\t\t);\n\t}\n\tconst value = sanitizeInlineOutputValue(envelope.value, input, policy, issues);\n\treturn Object.freeze({\n\t\tkind: envelope.kind,\n\t\tvalue: value as T | undefined,\n\t\trefs: envelope.refs === undefined ? undefined : sanitizeAdapterInputSourceRefs(envelope.refs),\n\t\tsummary,\n\t\tartifacts:\n\t\t\tenvelope.artifacts === undefined\n\t\t\t\t? undefined\n\t\t\t\t: Object.freeze(\n\t\t\t\t\t\tenvelope.artifacts.map((artifact) =>\n\t\t\t\t\t\t\tsanitizeExecutorArtifactMaterial(artifact, input, policy, issues),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\tmetadata,\n\t} satisfies AgentOutputEnvelope<T>);\n}\n\nexport function sanitizeExecutorArtifactMaterial(\n\tartifact: ExecutorArtifactMaterial,\n\tinput: ToolProviderAdapterInput,\n\tpolicy: ToolProviderPublicTextPolicy | undefined,\n\tissues: DataIssue[],\n): ExecutorArtifactMaterial {\n\tconst metadata = sanitizeRuntimeMetadata(artifact.metadata, input, policy, issues);\n\tconst redaction = sanitizeRuntimeMetadata(artifact.redaction, input, policy, issues);\n\treturn Object.freeze({\n\t\tkind: artifact.kind,\n\t\t...(artifact.format === undefined ? {} : { format: artifact.format }),\n\t\t...(artifact.schemaRef === undefined ? {} : { schemaRef: artifact.schemaRef }),\n\t\t...(artifact.schemaKind === undefined ? {} : { schemaKind: artifact.schemaKind }),\n\t\t...(artifact.mimeType === undefined ? {} : { mimeType: artifact.mimeType }),\n\t\t...(artifact.mediaType === undefined ? {} : { mediaType: artifact.mediaType }),\n\t\t...(artifact.filename === undefined ? {} : { filename: artifact.filename }),\n\t\t...(artifact.byteLength === undefined ? {} : { byteLength: artifact.byteLength }),\n\t\t...(artifact.digest === undefined ? {} : { digest: artifact.digest }),\n\t\t...(artifact.encoding === undefined ? {} : { encoding: artifact.encoding }),\n\t\tdataMode: artifact.dataMode,\n\t\t...(artifact.summary === undefined\n\t\t\t? {}\n\t\t\t: { summary: boundedPublicText(artifact.summary, \"summary\", input, policy, issues) }),\n\t\t...(artifact.value === undefined\n\t\t\t? {}\n\t\t\t: { value: sanitizeInlineOutputValue(artifact.value, input, policy, issues) }),\n\t\t...(artifact.ref === undefined\n\t\t\t? {}\n\t\t\t: { ref: sanitizeAdapterInputSourceRefs([artifact.ref])[0] }),\n\t\t...(artifact.refs === undefined ? {} : { refs: sanitizeAdapterInputSourceRefs(artifact.refs) }),\n\t\t...(artifact.sourceRefs === undefined\n\t\t\t? {}\n\t\t\t: { sourceRefs: sanitizeAdapterInputSourceRefs(artifact.sourceRefs) }),\n\t\t...(artifact.sizeEvidence === undefined\n\t\t\t? {}\n\t\t\t: {\n\t\t\t\t\tsizeEvidence: Object.freeze(\n\t\t\t\t\t\tartifact.sizeEvidence.map((evidence) =>\n\t\t\t\t\t\t\tsanitizeSizeCapacityEvidence(evidence, input, policy, issues),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t}),\n\t\t...(artifact.sensitivity === undefined\n\t\t\t? {}\n\t\t\t: { sensitivity: Object.freeze([...artifact.sensitivity]) }),\n\t\t...(redaction === undefined ? {} : { redaction }),\n\t\t...(metadata === undefined ? {} : { metadata }),\n\t} satisfies ExecutorArtifactMaterial);\n}\n\nfunction sanitizeSizeCapacityEvidence(\n\tevidence: SizeCapacityEvidence,\n\tinput: ToolProviderAdapterInput,\n\tpolicy: ToolProviderPublicTextPolicy | undefined,\n\tissues: DataIssue[],\n): SizeCapacityEvidence {\n\tconst metadata = sanitizeRuntimeMetadata(evidence.metadata, input, policy, issues);\n\tconst redaction = sanitizeRuntimeMetadata(evidence.redaction, input, policy, issues);\n\treturn Object.freeze({\n\t\tkind: \"size-capacity-evidence\",\n\t\tunit: evidence.unit,\n\t\tquantity: evidence.quantity,\n\t\tmeasurementSource: evidence.measurementSource,\n\t\t...(evidence.estimated === undefined ? {} : { estimated: evidence.estimated }),\n\t\t...(evidence.encoding === undefined ? {} : { encoding: evidence.encoding }),\n\t\t...(evidence.mediaType === undefined ? {} : { mediaType: evidence.mediaType }),\n\t\t...(evidence.sourceRefs === undefined\n\t\t\t? {}\n\t\t\t: { sourceRefs: sanitizeAdapterInputSourceRefs(evidence.sourceRefs) }),\n\t\t...(evidence.refs === undefined ? {} : { refs: sanitizeAdapterInputSourceRefs(evidence.refs) }),\n\t\t...(evidence.issues === undefined\n\t\t\t? {}\n\t\t\t: {\n\t\t\t\t\tissues: Object.freeze(evidence.issues.map((issue) => sanitizeAdapterInputIssue(issue))),\n\t\t\t\t}),\n\t\t...(evidence.sensitivity === undefined\n\t\t\t? {}\n\t\t\t: { sensitivity: Object.freeze([...evidence.sensitivity]) }),\n\t\t...(redaction === undefined ? {} : { redaction }),\n\t\t...(metadata === undefined ? {} : { metadata }),\n\t} satisfies SizeCapacityEvidence);\n}\n\nexport function sanitizeAgentNeed(\n\tneed: AgentNeed,\n\tinput: ToolProviderAdapterInput,\n\tpolicy: ToolProviderPublicTextPolicy | undefined,\n\tissues: DataIssue[],\n): AgentNeed {\n\tconst metadata = sanitizeRuntimeMetadata(need.metadata, input, policy, issues);\n\tif (metadata === undefined && need.metadata !== undefined) {\n\t\tissues.push(\n\t\t\tdataIssue(\n\t\t\t\t\"tool-provider-adapter-runtime-metadata-redacted\",\n\t\t\t\t\"Tool provider adapter runtime metadata was omitted because it contained runtime-private material.\",\n\t\t\t\t{\n\t\t\t\t\tsubjectId: input.requestId,\n\t\t\t\t\trefs: [ref(\"tool-provider-adapter-input\", input.adapterInputId)],\n\t\t\t\t\tseverity: \"warning\",\n\t\t\t\t},\n\t\t\t),\n\t\t);\n\t}\n\treturn Object.freeze({\n\t\tkind: need.kind,\n\t\tmessage:\n\t\t\tneed.message === undefined\n\t\t\t\t? undefined\n\t\t\t\t: boundedPublicText(need.message, \"message\", input, policy, issues),\n\t\trefs: need.refs === undefined ? undefined : sanitizeAdapterInputSourceRefs(need.refs),\n\t\tmetadata,\n\t} satisfies AgentNeed);\n}\n\nexport function sanitizeRuntimeMetadata<T extends Record<string, unknown> | undefined>(\n\tvalue: T,\n\tinput: ToolProviderAdapterInput,\n\tpolicy: ToolProviderPublicTextPolicy | undefined,\n\tissues: DataIssue[],\n): T | undefined {\n\tif (value === undefined) return undefined;\n\tconst bounded = sanitizePublicRecordWithEvidence(value, { mode: \"provider\", policy });\n\tif (bounded === undefined) return undefined;\n\tfor (const entry of bounded.truncated) {\n\t\tissues.push(\n\t\t\tdataIssue(\n\t\t\t\t\"tool-provider-adapter-runtime-public-text-truncated\",\n\t\t\t\t\"Tool provider adapter runtime public text was truncated; large/raw material must use artifact summary/ref envelopes.\",\n\t\t\t\t{\n\t\t\t\t\tsubjectId: input.requestId,\n\t\t\t\t\trefs: [ref(\"tool-provider-adapter-input\", input.adapterInputId)],\n\t\t\t\t\tseverity: \"warning\",\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tfield: \"metadata\",\n\t\t\t\t\t\tpath: entry.path.join(\".\"),\n\t\t\t\t\t\toriginalChars: entry.originalChars,\n\t\t\t\t\t\tlimitChars: entry.limitChars,\n\t\t\t\t\t\tunit: \"chars\",\n\t\t\t\t\t\tmeasurementSource: \"js-string-length\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t),\n\t\t);\n\t}\n\treturn Object.freeze(bounded.value) as T;\n}\n\nexport function sanitizePublicRecordWithEvidence(\n\tvalue: Record<string, unknown>,\n\topts: {\n\t\treadonly mode: PublicMaterialMode;\n\t\treadonly policy?: ToolProviderPublicTextPolicy;\n\t},\n):\n\t| {\n\t\t\treadonly value: Record<string, unknown>;\n\t\t\treadonly truncated: readonly {\n\t\t\t\treadonly path: readonly (string | number)[];\n\t\t\t\treadonly originalChars: number;\n\t\t\t\treadonly limitChars: number;\n\t\t\t}[];\n\t }\n\t| undefined {\n\tif (publicMaterialForbiddenKeys(value, opts.mode).length > 0) return undefined;\n\treturn boundRecordStringsWithEvidence(value, maxPublicMetadataStringChars(opts.policy));\n}\n\nexport function sanitizeInlineOutputValue(\n\tvalue: unknown,\n\tinput: ToolProviderAdapterInput,\n\tpolicy: ToolProviderPublicTextPolicy | undefined,\n\tissues: DataIssue[],\n): unknown {\n\tif (value === undefined) return undefined;\n\tconst forbidden = [\n\t\t...publicMaterialForbiddenKeys(value, \"provider\"),\n\t\t...oversizedInlineTextKeys(value, maxPublicSummaryChars(policy)),\n\t];\n\tif (forbidden.length === 0) return cloneGraphVisibleMaterial(value);\n\tfor (const entry of forbidden) {\n\t\tissues.push(\n\t\t\tdataIssue(\n\t\t\t\t\"tool-provider-adapter-runtime-forbidden-runtime-material\",\n\t\t\t\t\"Tool provider adapter runtime output value must not inline runtime-private, raw, or oversized provider material.\",\n\t\t\t\t{\n\t\t\t\t\tsubjectId: input.requestId,\n\t\t\t\t\trefs: [ref(\"tool-provider-adapter-input\", input.adapterInputId)],\n\t\t\t\t\tdetails: { reason: entry.reason },\n\t\t\t\t},\n\t\t\t),\n\t\t);\n\t}\n\treturn undefined;\n}\n\nexport function boundedPublicText(\n\ttext: string,\n\tfield: \"message\" | \"reason\" | \"summary\",\n\tinput: ToolProviderAdapterInput,\n\tpolicy: ToolProviderPublicTextPolicy | undefined,\n\tissues: DataIssue[],\n): string {\n\tconst limit =\n\t\tfield === \"summary\"\n\t\t\t? maxPublicSummaryChars(policy)\n\t\t\t: field === \"reason\"\n\t\t\t\t? maxPublicReasonChars(policy)\n\t\t\t\t: maxPublicMessageChars(policy);\n\tconst bounded = boundPublicText(text, limit);\n\tif (!bounded.truncated) return bounded.text;\n\tissues.push(\n\t\tdataIssue(\n\t\t\t\"tool-provider-adapter-runtime-public-text-truncated\",\n\t\t\t\"Tool provider adapter runtime public text was truncated; large/raw material must use artifact summary/ref envelopes.\",\n\t\t\t{\n\t\t\t\tsubjectId: input.requestId,\n\t\t\t\trefs: [ref(\"tool-provider-adapter-input\", input.adapterInputId)],\n\t\t\t\tseverity: \"warning\",\n\t\t\t\tdetails: {\n\t\t\t\t\tfield,\n\t\t\t\t\toriginalChars: bounded.originalChars,\n\t\t\t\t\tlimitChars: bounded.limitChars,\n\t\t\t\t\tunit: \"chars\",\n\t\t\t\t\tmeasurementSource: \"js-string-length\",\n\t\t\t\t},\n\t\t\t},\n\t\t),\n\t);\n\treturn bounded.text;\n}\n\nexport function boundPublicText(\n\ttext: string,\n\tlimitChars: number,\n): {\n\treadonly text: string;\n\treadonly truncated: boolean;\n\treadonly originalChars: number;\n\treadonly limitChars: number;\n} {\n\tconst limit = Math.max(0, limitChars);\n\tif (text.length <= limit) {\n\t\treturn { text, truncated: false, originalChars: text.length, limitChars: limit };\n\t}\n\tconst bounded =\n\t\tlimit <= 1\n\t\t\t? text.slice(0, limit)\n\t\t\t: limit <= 3\n\t\t\t\t? text.slice(0, limit)\n\t\t\t\t: `${text.slice(0, limit - 3)}...`;\n\treturn { text: bounded, truncated: true, originalChars: text.length, limitChars: limit };\n}\n\nexport function boundRecordStrings(\n\tvalue: Record<string, unknown>,\n\tlimitChars: number,\n\tseen: WeakSet<object> = new WeakSet(),\n): Record<string, unknown> {\n\tif (seen.has(value)) return {};\n\tseen.add(value);\n\treturn Object.entries(value).reduce<Record<string, unknown>>((out, [key, child]) => {\n\t\tif (typeof child === \"string\") {\n\t\t\tout[key] = boundPublicText(child, limitChars).text;\n\t\t} else if (Array.isArray(child)) {\n\t\t\tout[key] = child.map((item) =>\n\t\t\t\ttypeof item === \"string\"\n\t\t\t\t\t? boundPublicText(item, limitChars).text\n\t\t\t\t\t: isPlainRecord(item)\n\t\t\t\t\t\t? boundRecordStrings(item, limitChars, seen)\n\t\t\t\t\t\t: item,\n\t\t\t);\n\t\t} else if (isPlainRecord(child)) {\n\t\t\tout[key] = boundRecordStrings(child, limitChars, seen);\n\t\t} else {\n\t\t\tout[key] = child;\n\t\t}\n\t\treturn out;\n\t}, {});\n}\n\nexport function boundRecordStringsWithEvidence(\n\tvalue: Record<string, unknown>,\n\tlimitChars: number,\n\tpath: readonly (string | number)[] = [],\n\tseen: WeakSet<object> = new WeakSet(),\n): {\n\treadonly value: Record<string, unknown>;\n\treadonly truncated: readonly {\n\t\treadonly path: readonly (string | number)[];\n\t\treadonly originalChars: number;\n\t\treadonly limitChars: number;\n\t}[];\n} {\n\tif (seen.has(value)) return { value: {}, truncated: [] };\n\tseen.add(value);\n\tconst truncated: {\n\t\treadonly path: readonly (string | number)[];\n\t\treadonly originalChars: number;\n\t\treadonly limitChars: number;\n\t}[] = [];\n\tconst out = Object.entries(value).reduce<Record<string, unknown>>((record, [key, child]) => {\n\t\tconst childPath = [...path, key];\n\t\tif (typeof child === \"string\") {\n\t\t\tconst bounded = boundPublicText(child, limitChars);\n\t\t\trecord[key] = bounded.text;\n\t\t\tif (bounded.truncated) {\n\t\t\t\ttruncated.push({\n\t\t\t\t\tpath: childPath,\n\t\t\t\t\toriginalChars: bounded.originalChars,\n\t\t\t\t\tlimitChars: bounded.limitChars,\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (Array.isArray(child)) {\n\t\t\trecord[key] = child.map((item, index) => {\n\t\t\t\tconst itemPath = [...childPath, index];\n\t\t\t\tif (typeof item === \"string\") {\n\t\t\t\t\tconst bounded = boundPublicText(item, limitChars);\n\t\t\t\t\tif (bounded.truncated) {\n\t\t\t\t\t\ttruncated.push({\n\t\t\t\t\t\t\tpath: itemPath,\n\t\t\t\t\t\t\toriginalChars: bounded.originalChars,\n\t\t\t\t\t\t\tlimitChars: bounded.limitChars,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\treturn bounded.text;\n\t\t\t\t}\n\t\t\t\tif (isPlainRecord(item)) {\n\t\t\t\t\tconst nested = boundRecordStringsWithEvidence(item, limitChars, itemPath, seen);\n\t\t\t\t\ttruncated.push(...nested.truncated);\n\t\t\t\t\treturn nested.value;\n\t\t\t\t}\n\t\t\t\treturn item;\n\t\t\t});\n\t\t} else if (isPlainRecord(child)) {\n\t\t\tconst nested = boundRecordStringsWithEvidence(child, limitChars, childPath, seen);\n\t\t\trecord[key] = nested.value;\n\t\t\ttruncated.push(...nested.truncated);\n\t\t} else {\n\t\t\trecord[key] = child;\n\t\t}\n\t\treturn record;\n\t}, {});\n\treturn { value: out, truncated };\n}\n\nexport function sanitizeIssueDetails(\n\tdetails: unknown,\n\tpolicy?: ToolProviderPublicTextPolicy,\n): unknown {\n\tif (details === undefined) return undefined;\n\tif (publicMaterialForbiddenKeys(details, \"provider\").length > 0) {\n\t\treturn { redacted: true, reason: \"forbidden-runtime-material\" };\n\t}\n\tconst bounded = boundUnknownStringsWithEvidence(details, maxPublicMetadataStringChars(policy));\n\tif (bounded.truncated.length === 0) return bounded.value;\n\tconst detailsTruncated = {\n\t\tdetailsTruncated: true,\n\t\tdetailsTruncatedPaths: bounded.truncated.map((entry) => entry.path.join(\".\")),\n\t\tmeasurementSource: \"js-string-length\",\n\t};\n\tif (isPlainRecord(bounded.value)) {\n\t\treturn Object.freeze({ ...bounded.value, ...detailsTruncated });\n\t}\n\treturn Object.freeze({ value: bounded.value, ...detailsTruncated });\n}\n\nexport function boundUnknownStringsWithEvidence(\n\tvalue: unknown,\n\tlimitChars: number,\n\tpath: readonly (string | number)[] = [],\n\tseen: WeakSet<object> = new WeakSet(),\n): {\n\treadonly value: unknown;\n\treadonly truncated: readonly {\n\t\treadonly path: readonly (string | number)[];\n\t\treadonly originalChars: number;\n\t\treadonly limitChars: number;\n\t}[];\n} {\n\tif (typeof value === \"string\") {\n\t\tconst bounded = boundPublicText(value, limitChars);\n\t\treturn {\n\t\t\tvalue: bounded.text,\n\t\t\ttruncated: bounded.truncated\n\t\t\t\t? [{ path, originalChars: bounded.originalChars, limitChars: bounded.limitChars }]\n\t\t\t\t: [],\n\t\t};\n\t}\n\tif (!isRecord(value) && !Array.isArray(value)) return { value, truncated: [] };\n\tif (typeof value === \"object\" && value !== null) {\n\t\tif (seen.has(value)) return { value: Array.isArray(value) ? [] : {}, truncated: [] };\n\t\tseen.add(value);\n\t}\n\tconst truncated: {\n\t\treadonly path: readonly (string | number)[];\n\t\treadonly originalChars: number;\n\t\treadonly limitChars: number;\n\t}[] = [];\n\tif (Array.isArray(value)) {\n\t\tconst out = value.map((item, index) => {\n\t\t\tconst bounded = boundUnknownStringsWithEvidence(item, limitChars, [...path, index], seen);\n\t\t\ttruncated.push(...bounded.truncated);\n\t\t\treturn bounded.value;\n\t\t});\n\t\treturn { value: out, truncated };\n\t}\n\tconst out = Object.entries(value).reduce<Record<string, unknown>>((record, [key, child]) => {\n\t\tconst bounded = boundUnknownStringsWithEvidence(child, limitChars, [...path, key], seen);\n\t\trecord[key] = bounded.value;\n\t\ttruncated.push(...bounded.truncated);\n\t\treturn record;\n\t}, {});\n\treturn { value: out, truncated };\n}\n\nexport function oversizedInlineTextKeys(\n\tvalue: unknown,\n\tlimitChars: number,\n\tpath: readonly (string | number)[] = [],\n\tseen: WeakSet<object> = new WeakSet(),\n): readonly { readonly path: readonly (string | number)[]; readonly reason: string }[] {\n\tif (typeof value === \"string\") {\n\t\treturn value.length > Math.max(0, limitChars)\n\t\t\t? [{ path, reason: \"oversized-inline-text\" }]\n\t\t\t: [];\n\t}\n\tif (!isRecord(value) && !Array.isArray(value)) return [];\n\tif (typeof value === \"object\" && value !== null) {\n\t\tif (seen.has(value)) return [];\n\t\tseen.add(value);\n\t}\n\tconst issues: { readonly path: readonly (string | number)[]; readonly reason: string }[] = [];\n\tif (Array.isArray(value)) {\n\t\tvalue.forEach((item, index) => {\n\t\t\tissues.push(...oversizedInlineTextKeys(item, limitChars, [...path, index], seen));\n\t\t});\n\t\treturn issues;\n\t}\n\tfor (const [key, child] of Object.entries(value)) {\n\t\tissues.push(...oversizedInlineTextKeys(child, limitChars, [...path, key], seen));\n\t}\n\treturn issues;\n}\n\nexport function maxPublicMessageChars(policy?: ToolProviderPublicTextPolicy): number {\n\treturn normalizedPublicTextLimit(policy?.maxMessageChars, 512);\n}\n\nexport function maxPublicSummaryChars(policy?: ToolProviderPublicTextPolicy): number {\n\treturn normalizedPublicTextLimit(policy?.maxSummaryChars, 512);\n}\n\nexport function maxPublicReasonChars(policy?: ToolProviderPublicTextPolicy): number {\n\treturn normalizedPublicTextLimit(policy?.maxReasonChars, 512);\n}\n\nexport function maxPublicMetadataStringChars(policy?: ToolProviderPublicTextPolicy): number {\n\treturn normalizedPublicTextLimit(policy?.maxMetadataStringChars, 256);\n}\n\nexport function normalizedPublicTextLimit(value: number | undefined, fallback: number): number {\n\tif (value === undefined || !Number.isFinite(value)) return fallback;\n\treturn Math.max(0, Math.floor(value));\n}\n\nexport function sanitizeAdapterInputIssue(\n\tissue: DataIssue,\n\tpolicy?: ToolProviderPublicTextPolicy,\n): DataIssue {\n\tconst boundedMessage = boundPublicText(issue.message, maxPublicMessageChars(policy));\n\tconst details = sanitizeIssueDetails(issue.details, policy);\n\tconst metadata = sanitizeProviderGraphVisibleRecord(issue.metadata, policy);\n\tconst refs =\n\t\tissue.refs === undefined\n\t\t\t? undefined\n\t\t\t: Object.freeze(issue.refs.filter((entry): entry is string => typeof entry === \"string\"));\n\treturn Object.freeze({\n\t\tkind: issue.kind,\n\t\tcode: issue.code,\n\t\t...(issue.source === undefined ? {} : { source: issue.source }),\n\t\tmessage: boundedMessage.text,\n\t\tseverity: issue.severity,\n\t\tsubjectId: issue.subjectId,\n\t\t...(issue.correlationId === undefined ? {} : { correlationId: issue.correlationId }),\n\t\t...(issue.causationId === undefined ? {} : { causationId: issue.causationId }),\n\t\t...(issue.path === undefined ? {} : { path: Object.freeze([...issue.path]) }),\n\t\t...(refs === undefined || refs.length === 0 ? {} : { refs }),\n\t\t...(issue.retryable === undefined ? {} : { retryable: issue.retryable }),\n\t\tdetails:\n\t\t\tboundedMessage.truncated || details !== issue.details\n\t\t\t\t? {\n\t\t\t\t\t\t...(isRecord(details) ? details : {}),\n\t\t\t\t\t\t...(boundedMessage.truncated\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\ttruncated: true,\n\t\t\t\t\t\t\t\t\toriginalChars: boundedMessage.originalChars,\n\t\t\t\t\t\t\t\t\tlimitChars: boundedMessage.limitChars,\n\t\t\t\t\t\t\t\t\tmeasurementSource: \"js-string-length\",\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t}\n\t\t\t\t: details,\n\t\t...(metadata === undefined ? {} : { metadata }),\n\t} satisfies DataIssue);\n}\n\nexport function forbiddenProviderRawMaterialKeys(\n\tvalue: unknown,\n\tpath: readonly (string | number)[] = [],\n\tseen: WeakSet<object> = new WeakSet(),\n): readonly { readonly path: readonly (string | number)[]; readonly reason: string }[] {\n\tif (!isRecord(value) && !Array.isArray(value)) return [];\n\tif (typeof value === \"object\" && value !== null) {\n\t\tif (seen.has(value)) return [];\n\t\tseen.add(value);\n\t}\n\tconst issues: { readonly path: readonly (string | number)[]; readonly reason: string }[] = [];\n\tif (Array.isArray(value)) {\n\t\tvalue.forEach((item, index) => {\n\t\t\tissues.push(...forbiddenProviderRawMaterialKeys(item, [...path, index], seen));\n\t\t});\n\t\treturn issues;\n\t}\n\tfor (const [key, child] of Object.entries(value)) {\n\t\tconst nextPath = [...path, key];\n\t\tif (\n\t\t\t/^(stdout|stderr|stack|stackTrace|stack_trace|providerRaw|provider_raw|rawResponse|raw_response|diff|patch|fileContents|file_contents|binary|media)$/i.test(\n\t\t\t\tkey,\n\t\t\t)\n\t\t) {\n\t\t\tissues.push({ path: nextPath, reason: \"raw-provider-material\" });\n\t\t}\n\t\tissues.push(...forbiddenProviderRawMaterialKeys(child, nextPath, seen));\n\t}\n\treturn issues;\n}\n\nexport function dataIssue(\n\tcode: string,\n\tmessage: string,\n\topts: {\n\t\treadonly subjectId?: string;\n\t\treadonly refs?: readonly SourceRef[];\n\t\treadonly severity?: DataIssue[\"severity\"];\n\t\treadonly details?: unknown;\n\t} = {},\n): DataIssue {\n\treturn {\n\t\tkind: \"issue\",\n\t\tcode,\n\t\tmessage,\n\t\tseverity: opts.severity ?? \"error\",\n\t\tsubjectId: opts.subjectId,\n\t\trefs: opts.refs?.map((r) => `${r.kind}:${r.id}`),\n\t\tdetails: opts.details,\n\t};\n}\n\nexport function ref(kind: string, id: string): SourceRef {\n\treturn { kind, id };\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nexport function isPlainRecord(value: unknown): value is Record<string, unknown> {\n\tif (!isRecord(value)) return false;\n\tconst proto = Object.getPrototypeOf(value);\n\treturn proto === Object.prototype || proto === null;\n}\n","import { depBatch } from \"../ctx/types.js\";\nimport type { DataIssue } from \"../data/index.js\";\nimport type { Graph } from \"../graph/graph.js\";\nimport type { Node } from \"../node/node.js\";\nimport type {\n\tWorkQueueCommand,\n\tWorkQueueDerivedState,\n\tWorkQueueRecord,\n} from \"../work-queue/index.js\";\nimport {\n\tcanonicalPublicSourceRefs,\n\tdataIssue,\n\tisRecord,\n\tprojectRuntimeFact,\n\tref,\n\tsanitizeGraphVisibleRecord,\n\tstableJsonStringify,\n\tstableStringHash,\n\tuniqueSourceRefs,\n} from \"./agent-runtime-common.js\";\nimport type { AgentRuntimeAuditRecord } from \"./agent-runtime-types-agent.js\";\nimport type { SourceRef } from \"./agent-runtime-types-core.js\";\nimport type {\n\tScheduledReadinessOverdue,\n\tScheduledReadinessReady,\n\tScheduledReadinessRequested,\n} from \"./scheduled-readiness.js\";\n\nexport type WorkQueueScheduledReadinessScheduleKind =\n\t| \"work-admitted\"\n\t| \"work-scheduled\"\n\t| \"retry-scheduled\"\n\t| \"lease-expiration\";\n\nexport type WorkQueueScheduledReadinessStatusState = \"translated\" | \"issue\";\n\nexport interface WorkQueueScheduledReadinessStatus {\n\treadonly kind: \"work-queue-scheduled-readiness-status\";\n\treadonly statusId: string;\n\treadonly queueId?: string;\n\treadonly workId?: string;\n\treadonly recordSeq?: number;\n\treadonly state: WorkQueueScheduledReadinessStatusState;\n\treadonly scheduleKind?: WorkQueueScheduledReadinessScheduleKind;\n\treadonly scheduleId?: string;\n\treadonly readyAtMs?: number;\n\treadonly deadlineMs?: number;\n\treadonly sourceRefs?: readonly SourceRef[];\n\treadonly issueCodes?: readonly string[];\n\treadonly metadata?: Record<string, unknown>;\n}\n\nexport interface WorkQueueScheduledReadinessViews {\n\treadonly schedulesById: ReadonlyMap<string, ScheduledReadinessRequested>;\n\treadonly statusById: ReadonlyMap<string, WorkQueueScheduledReadinessStatus>;\n}\n\nexport interface WorkQueueScheduledReadinessBundle {\n\treadonly readinessSchedules: Node<ScheduledReadinessRequested>;\n\treadonly status: Node<WorkQueueScheduledReadinessStatus>;\n\treadonly issues: Node<DataIssue>;\n\treadonly audit: Node<AgentRuntimeAuditRecord>;\n\treadonly views: Node<WorkQueueScheduledReadinessViews>;\n}\n\nexport type WorkQueueReadinessCandidateKind = \"claim-eligible\" | \"lease-expiration-eligible\";\n\nexport interface WorkQueueReadinessCandidate {\n\treadonly kind: \"work-queue-readiness-candidate\";\n\treadonly candidateId: string;\n\treadonly candidateKind: WorkQueueReadinessCandidateKind;\n\treadonly queueId: string;\n\treadonly workId: string;\n\treadonly scheduleId: string;\n\treadonly readyAtMs: number;\n\treadonly nowMs: number;\n\treadonly originRecordSeq?: number;\n\treadonly originRecordKind?: string;\n\treadonly leaseId?: string;\n\treadonly attempt?: number;\n\treadonly workerId?: string;\n\treadonly leaseExpiresAtMs?: number;\n\treadonly sourceRefs?: readonly SourceRef[];\n\treadonly metadata?: Record<string, unknown>;\n}\n\nexport type WorkQueueReadinessHandoffStatusState =\n\t| \"candidate\"\n\t| \"ignored-stale\"\n\t| \"ignored-superseded\"\n\t| \"ignored-terminal\"\n\t| \"overdue\"\n\t| \"pending-origin\"\n\t| \"issue\";\n\nexport interface WorkQueueReadinessHandoffStatus {\n\treadonly kind: \"work-queue-readiness-handoff-status\";\n\treadonly statusId: string;\n\treadonly state: WorkQueueReadinessHandoffStatusState;\n\treadonly queueId?: string;\n\treadonly workId?: string;\n\treadonly scheduleId?: string;\n\treadonly candidateId?: string;\n\treadonly candidateKind?: WorkQueueReadinessCandidateKind;\n\treadonly readyAtMs?: number;\n\treadonly nowMs?: number;\n\treadonly currentState?: WorkQueueDerivedState;\n\treadonly sourceRefs?: readonly SourceRef[];\n\treadonly issueCodes?: readonly string[];\n\treadonly metadata?: Record<string, unknown>;\n}\n\nexport interface WorkQueueReadinessHandoffViews {\n\treadonly candidatesById: ReadonlyMap<string, WorkQueueReadinessCandidate>;\n\treadonly statusById: ReadonlyMap<string, WorkQueueReadinessHandoffStatus>;\n}\n\nexport interface WorkQueueReadinessHandoffBundle {\n\treadonly candidates: Node<WorkQueueReadinessCandidate>;\n\treadonly status: Node<WorkQueueReadinessHandoffStatus>;\n\treadonly issues: Node<DataIssue>;\n\treadonly audit: Node<AgentRuntimeAuditRecord>;\n\treadonly views: Node<WorkQueueReadinessHandoffViews>;\n}\n\nexport interface WorkQueueLeaseExpirationCommandBundle<T = unknown> {\n\treadonly commands: Node<WorkQueueCommand<T>>;\n\treadonly status: Node<WorkQueueReadinessHandoffStatus>;\n\treadonly views: Node<WorkQueueReadinessHandoffViews>;\n}\n\nconst MAX_PUBLIC_COORDINATE_ID_CHARS = 160;\nconst MAX_COPIED_PUBLIC_REFS = 16;\nconst PRIVATE_COORDINATE_PATTERN =\n\t/(api[_-]?key|authorization|bearer|credential|oauth|password|private[_-]?key|secret|session[_-]?cookie|token)/i;\n\n/**\n * Translate workQueue-local delayed eligibility records into D432 shared readiness schedules.\n *\n * The projector is intentionally visibility-only: it never claims work, expires leases, cancels,\n * completes, fails, mutates queue records, or starts timers. D433 consumption/materialization stays\n * owned by later workQueue domain projectors.\n */\nexport function workQueueScheduledReadinessProjector<T = unknown>(\n\tgraph: Graph,\n\topts: {\n\t\treadonly name?: string;\n\t\treadonly records: Node<WorkQueueRecord<T>>;\n\t},\n): WorkQueueScheduledReadinessBundle {\n\tconst name = opts.name ?? \"workQueueScheduledReadiness\";\n\tconst runtime = graph.node<WorkQueueScheduledReadinessFact>(\n\t\t[opts.records],\n\t\t(ctx) => {\n\t\t\tconst state = ctx.state.get<WorkQueueScheduledReadinessProjectorState>() ?? initialState();\n\t\t\tfor (const raw of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst translated = translateRecord(raw);\n\t\t\t\tif (translated.kind === \"none\") continue;\n\t\t\t\tif (translated.kind === \"issue\") {\n\t\t\t\t\temitIssue(ctx, state, translated.issue);\n\t\t\t\t\temitStatus(ctx, state, translated.status);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst identity = scheduleIdentity(translated.schedule);\n\t\t\t\tconst recordKey = `${translated.record.queueId}:${translated.record.recordSeq}`;\n\t\t\t\tconst existingRecordIdentity = state.recordScheduleIdentityByKey.get(recordKey);\n\t\t\t\tif (existingRecordIdentity !== undefined) {\n\t\t\t\t\tif (existingRecordIdentity !== identity) emitScheduleConflict(ctx, state, translated);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tstate.recordScheduleIdentityByKey.set(recordKey, identity);\n\t\t\t\tconst existing = state.schedulesById.get(translated.schedule.scheduleId);\n\t\t\t\tif (existing !== undefined) {\n\t\t\t\t\tif (scheduleIdentity(existing) !== identity) {\n\t\t\t\t\t\temitScheduleConflict(ctx, state, translated, existing);\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tstate.schedulesById.set(translated.schedule.scheduleId, translated.schedule);\n\t\t\t\temitSchedule(ctx, state, translated.schedule);\n\t\t\t\temitStatus(ctx, state, translated.status);\n\t\t\t\temitAudit(ctx, state, \"work-queue-scheduled-readiness-translated\", {\n\t\t\t\t\tsubjectId: translated.schedule.scheduleId,\n\t\t\t\t\tsourceRefs: translated.schedule.sourceRefs,\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tqueueId: publicCoordinateId(translated.record.queueId),\n\t\t\t\t\t\tworkId: publicCoordinateId(translated.record.workId),\n\t\t\t\t\t\trecordSeq: translated.record.recordSeq,\n\t\t\t\t\t\trecordKind: translated.record.kind,\n\t\t\t\t\t\treadyAtMs: translated.schedule.readyAtMs,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\tctx.down([[\"DATA\", { kind: \"views\", views: buildViews(state) }]]);\n\t\t\tctx.state.set(state);\n\t\t},\n\t\t{\n\t\t\tname: `${name}/runtime`,\n\t\t\tfactory: \"workQueueScheduledReadinessProjector\",\n\t\t\tpartial: true,\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\treturn {\n\t\treadinessSchedules: projectRuntimeFact(\n\t\t\tgraph,\n\t\t\truntime,\n\t\t\t`${name}/readinessSchedules`,\n\t\t\t\"workQueueScheduledReadinessSchedules\",\n\t\t\t(fact) => (fact.kind === \"readiness-schedule\" ? fact.schedule : undefined),\n\t\t),\n\t\tstatus: projectRuntimeFact(\n\t\t\tgraph,\n\t\t\truntime,\n\t\t\t`${name}/status`,\n\t\t\t\"workQueueScheduledReadinessStatus\",\n\t\t\t(fact) => (fact.kind === \"status\" ? fact.status : undefined),\n\t\t),\n\t\tissues: projectRuntimeFact(\n\t\t\tgraph,\n\t\t\truntime,\n\t\t\t`${name}/issues`,\n\t\t\t\"workQueueScheduledReadinessIssues\",\n\t\t\t(fact) => (fact.kind === \"issue\" ? fact.issue : undefined),\n\t\t),\n\t\taudit: projectRuntimeFact(\n\t\t\tgraph,\n\t\t\truntime,\n\t\t\t`${name}/audit`,\n\t\t\t\"workQueueScheduledReadinessAudit\",\n\t\t\t(fact) => (fact.kind === \"audit\" ? fact.audit : undefined),\n\t\t),\n\t\tviews: projectRuntimeFact(\n\t\t\tgraph,\n\t\t\truntime,\n\t\t\t`${name}/views`,\n\t\t\t\"workQueueScheduledReadinessViews\",\n\t\t\t(fact) => (fact.kind === \"views\" ? fact.views : undefined),\n\t\t),\n\t};\n}\n\n/**\n * Consume D433 shared readiness through workQueue-owned handoff material.\n *\n * Ready facts only produce queue-domain candidates/status. They do not claim work, expire leases,\n * cancel, complete, fail, or append workQueue records. Lease expiration candidates can be lowered\n * separately into the existing mutation-bearing expire-leases command path.\n */\nexport function workQueueReadinessHandoffProjector<T = unknown>(\n\tgraph: Graph,\n\topts: {\n\t\treadonly name?: string;\n\t\treadonly records: Node<WorkQueueRecord<T>>;\n\t\treadonly ready: Node<ScheduledReadinessReady>;\n\t\treadonly overdue?: Node<ScheduledReadinessOverdue>;\n\t},\n): WorkQueueReadinessHandoffBundle {\n\tconst name = opts.name ?? \"workQueueReadinessHandoff\";\n\tconst deps =\n\t\topts.overdue === undefined\n\t\t\t? ([opts.records, opts.ready] as const)\n\t\t\t: ([opts.records, opts.ready, opts.overdue] as const);\n\tconst runtime = graph.node<WorkQueueReadinessHandoffFact>(\n\t\tdeps,\n\t\t(ctx) => {\n\t\t\tconst state = ctx.state.get<WorkQueueReadinessHandoffProjectorState>() ?? handoffState();\n\t\t\tfor (const raw of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst record = raw as WorkQueueRecord<T>;\n\t\t\t\tingestWorkQueueRecord(state, record);\n\t\t\t}\n\t\t\tfor (const raw of depBatch(ctx, 1) ?? []) {\n\t\t\t\tconst ready = raw as ScheduledReadinessReady;\n\t\t\t\tstate.readyByScheduleId.set(ready.scheduleId, ready);\n\t\t\t}\n\t\t\tif (opts.overdue !== undefined) {\n\t\t\t\tfor (const raw of depBatch(ctx, 2) ?? []) {\n\t\t\t\t\temitOverdueHandoffStatus(ctx, state, raw as ScheduledReadinessOverdue);\n\t\t\t\t}\n\t\t\t}\n\t\t\tevaluateReadyHandoffs(ctx, state);\n\t\t\tctx.down([[\"DATA\", { kind: \"views\", views: buildHandoffViews(state) }]]);\n\t\t\tctx.state.set(state);\n\t\t},\n\t\t{\n\t\t\tname: `${name}/runtime`,\n\t\t\tfactory: \"workQueueReadinessHandoffProjector\",\n\t\t\tpartial: true,\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\treturn {\n\t\tcandidates: projectRuntimeFact(\n\t\t\tgraph,\n\t\t\truntime,\n\t\t\t`${name}/candidates`,\n\t\t\t\"workQueueReadinessHandoffCandidates\",\n\t\t\t(fact) => (fact.kind === \"candidate\" ? fact.candidate : undefined),\n\t\t),\n\t\tstatus: projectRuntimeFact(\n\t\t\tgraph,\n\t\t\truntime,\n\t\t\t`${name}/status`,\n\t\t\t\"workQueueReadinessHandoffStatus\",\n\t\t\t(fact) => (fact.kind === \"status\" ? fact.status : undefined),\n\t\t),\n\t\tissues: projectRuntimeFact(\n\t\t\tgraph,\n\t\t\truntime,\n\t\t\t`${name}/issues`,\n\t\t\t\"workQueueReadinessHandoffIssues\",\n\t\t\t(fact) => (fact.kind === \"issue\" ? fact.issue : undefined),\n\t\t),\n\t\taudit: projectRuntimeFact(\n\t\t\tgraph,\n\t\t\truntime,\n\t\t\t`${name}/audit`,\n\t\t\t\"workQueueReadinessHandoffAudit\",\n\t\t\t(fact) => (fact.kind === \"audit\" ? fact.audit : undefined),\n\t\t),\n\t\tviews: projectRuntimeFact(\n\t\t\tgraph,\n\t\t\truntime,\n\t\t\t`${name}/views`,\n\t\t\t\"workQueueReadinessHandoffViews\",\n\t\t\t(fact) => (fact.kind === \"views\" ? fact.views : undefined),\n\t\t),\n\t};\n}\n\n/**\n * Lower only lease-expiration readiness candidates into existing workQueue expire-leases commands.\n */\nexport function workQueueLeaseExpirationCommandProjector<T = unknown>(\n\tgraph: Graph,\n\topts: {\n\t\treadonly name?: string;\n\t\treadonly candidates: Node<WorkQueueReadinessCandidate>;\n\t},\n): WorkQueueLeaseExpirationCommandBundle<T> {\n\tconst name = opts.name ?? \"workQueueLeaseExpirationCommands\";\n\tconst runtime = graph.node<WorkQueueLeaseExpirationCommandFact<T>>(\n\t\t[opts.candidates],\n\t\t(ctx) => {\n\t\t\tconst state =\n\t\t\t\tctx.state.get<WorkQueueLeaseExpirationCommandProjectorState<T>>() ??\n\t\t\t\tleaseExpirationCommandState<T>();\n\t\t\tfor (const raw of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst candidate = raw as WorkQueueReadinessCandidate;\n\t\t\t\tif (candidate.candidateKind !== \"lease-expiration-eligible\") continue;\n\t\t\t\tif (state.commandByCandidateId.has(candidate.candidateId)) continue;\n\t\t\t\tconst command = Object.freeze({\n\t\t\t\t\tkind: \"expire-leases\",\n\t\t\t\t\tcommandId: `${candidate.candidateId}:expire-leases`,\n\t\t\t\t\tqueueId: candidate.queueId,\n\t\t\t\t\tworkIds: [candidate.workId],\n\t\t\t\t\tlimit: 1,\n\t\t\t\t\tnowMs: candidate.nowMs,\n\t\t\t\t\tcausationId: candidate.scheduleId,\n\t\t\t\t\t...(sourceRefStrings(candidate.sourceRefs) === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: { sourceRefs: sourceRefStrings(candidate.sourceRefs) }),\n\t\t\t\t} satisfies WorkQueueCommand<T>);\n\t\t\t\tstate.commandByCandidateId.set(candidate.candidateId, command);\n\t\t\t\tctx.down([[\"DATA\", { kind: \"command\", command }]]);\n\t\t\t\temitLeaseCommandStatus(ctx, state, command, candidate);\n\t\t\t}\n\t\t\tctx.down([[\"DATA\", { kind: \"views\", views: buildLeaseCommandViews(state) }]]);\n\t\t\tctx.state.set(state);\n\t\t},\n\t\t{\n\t\t\tname: `${name}/runtime`,\n\t\t\tfactory: \"workQueueLeaseExpirationCommandProjector\",\n\t\t\tpartial: true,\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\treturn {\n\t\tcommands: projectRuntimeFact(\n\t\t\tgraph,\n\t\t\truntime,\n\t\t\t`${name}/commands`,\n\t\t\t\"workQueueLeaseExpirationCommands\",\n\t\t\t(fact) => (fact.kind === \"command\" ? fact.command : undefined),\n\t\t),\n\t\tstatus: projectRuntimeFact(\n\t\t\tgraph,\n\t\t\truntime,\n\t\t\t`${name}/status`,\n\t\t\t\"workQueueLeaseExpirationCommandStatus\",\n\t\t\t(fact) => (fact.kind === \"status\" ? fact.status : undefined),\n\t\t),\n\t\tviews: projectRuntimeFact(\n\t\t\tgraph,\n\t\t\truntime,\n\t\t\t`${name}/views`,\n\t\t\t\"workQueueLeaseExpirationCommandViews\",\n\t\t\t(fact) => (fact.kind === \"views\" ? fact.views : undefined),\n\t\t),\n\t};\n}\n\ntype WorkQueueScheduledReadinessFact =\n\t| { readonly kind: \"readiness-schedule\"; readonly schedule: ScheduledReadinessRequested }\n\t| { readonly kind: \"status\"; readonly status: WorkQueueScheduledReadinessStatus }\n\t| { readonly kind: \"issue\"; readonly issue: DataIssue }\n\t| { readonly kind: \"audit\"; readonly audit: AgentRuntimeAuditRecord }\n\t| { readonly kind: \"views\"; readonly views: WorkQueueScheduledReadinessViews };\n\ninterface WorkQueueScheduledReadinessProjectorState {\n\trecordScheduleIdentityByKey: Map<string, string>;\n\tschedulesById: Map<string, ScheduledReadinessRequested>;\n\tstatusById: Map<string, WorkQueueScheduledReadinessStatus>;\n\temittedKeys: Set<string>;\n\tissueKeys: Set<string>;\n\tauditSeq: number;\n}\n\ntype WorkQueueRecordWithWorkId = WorkQueueRecord<unknown> & { readonly workId: string };\n\ntype TranslatedRecord =\n\t| { readonly kind: \"none\" }\n\t| {\n\t\t\treadonly kind: \"translated\";\n\t\t\treadonly record: WorkQueueRecordWithWorkId;\n\t\t\treadonly schedule: ScheduledReadinessRequested;\n\t\t\treadonly status: WorkQueueScheduledReadinessStatus;\n\t }\n\t| {\n\t\t\treadonly kind: \"issue\";\n\t\t\treadonly issue: DataIssue;\n\t\t\treadonly status: WorkQueueScheduledReadinessStatus;\n\t };\n\ntype WorkQueueReadinessHandoffFact =\n\t| { readonly kind: \"candidate\"; readonly candidate: WorkQueueReadinessCandidate }\n\t| { readonly kind: \"status\"; readonly status: WorkQueueReadinessHandoffStatus }\n\t| { readonly kind: \"issue\"; readonly issue: DataIssue }\n\t| { readonly kind: \"audit\"; readonly audit: AgentRuntimeAuditRecord }\n\t| { readonly kind: \"views\"; readonly views: WorkQueueReadinessHandoffViews };\n\ninterface WorkQueueReadinessOrigin {\n\treadonly record: WorkQueueRecordWithWorkId;\n\treadonly schedule: ScheduledReadinessRequested;\n\treadonly scheduleKind: WorkQueueScheduledReadinessScheduleKind;\n}\n\ninterface WorkQueueReadinessWorkState {\n\treadonly queueId: string;\n\treadonly workId: string;\n\tstate: WorkQueueDerivedState;\n\tnotBeforeMs?: number;\n\tretryAtMs?: number;\n\tdeadlineMs?: number;\n\tleaseId?: string;\n\tattempt?: number;\n\tworkerId?: string;\n\tleaseExpiresAtMs?: number;\n\tlatestRecordSeq: number;\n}\n\ninterface WorkQueueReadinessHandoffProjectorState {\n\toriginsByScheduleId: Map<string, WorkQueueReadinessOrigin>;\n\tworksById: Map<string, WorkQueueReadinessWorkState>;\n\treadyByScheduleId: Map<string, ScheduledReadinessReady>;\n\tcandidatesById: Map<string, WorkQueueReadinessCandidate>;\n\tstatusById: Map<string, WorkQueueReadinessHandoffStatus>;\n\temittedKeys: Set<string>;\n\tissueKeys: Set<string>;\n\tauditSeq: number;\n}\n\ntype WorkQueueLeaseExpirationCommandFact<T> =\n\t| { readonly kind: \"command\"; readonly command: WorkQueueCommand<T> }\n\t| { readonly kind: \"status\"; readonly status: WorkQueueReadinessHandoffStatus }\n\t| { readonly kind: \"views\"; readonly views: WorkQueueReadinessHandoffViews };\n\ninterface WorkQueueLeaseExpirationCommandProjectorState<T> {\n\tcommandByCandidateId: Map<string, WorkQueueCommand<T>>;\n\tstatusById: Map<string, WorkQueueReadinessHandoffStatus>;\n\temittedKeys: Set<string>;\n}\n\nfunction initialState(): WorkQueueScheduledReadinessProjectorState {\n\treturn {\n\t\trecordScheduleIdentityByKey: new Map(),\n\t\tschedulesById: new Map(),\n\t\tstatusById: new Map(),\n\t\temittedKeys: new Set(),\n\t\tissueKeys: new Set(),\n\t\tauditSeq: 0,\n\t};\n}\n\nfunction handoffState(): WorkQueueReadinessHandoffProjectorState {\n\treturn {\n\t\toriginsByScheduleId: new Map(),\n\t\tworksById: new Map(),\n\t\treadyByScheduleId: new Map(),\n\t\tcandidatesById: new Map(),\n\t\tstatusById: new Map(),\n\t\temittedKeys: new Set(),\n\t\tissueKeys: new Set(),\n\t\tauditSeq: 0,\n\t};\n}\n\nfunction leaseExpirationCommandState<T>(): WorkQueueLeaseExpirationCommandProjectorState<T> {\n\treturn {\n\t\tcommandByCandidateId: new Map(),\n\t\tstatusById: new Map(),\n\t\temittedKeys: new Set(),\n\t};\n}\n\nfunction ingestWorkQueueRecord<T>(\n\tstate: WorkQueueReadinessHandoffProjectorState,\n\trecord: WorkQueueRecord<T>,\n): void {\n\tconst translated = translateRecord(record);\n\tif (translated.kind === \"translated\") {\n\t\tstate.originsByScheduleId.set(translated.schedule.scheduleId, {\n\t\t\trecord: translated.record,\n\t\t\tschedule: translated.schedule,\n\t\t\tscheduleKind: translated.status.scheduleKind as WorkQueueScheduledReadinessScheduleKind,\n\t\t});\n\t}\n\tif (record.workId === undefined) return;\n\tconst recordWithWorkId = record as WorkQueueRecordWithWorkId;\n\tconst existing = state.worksById.get(\n\t\thandoffWorkKey(recordWithWorkId.queueId, recordWithWorkId.workId),\n\t);\n\tif (existing !== undefined && recordWithWorkId.recordSeq < existing.latestRecordSeq) return;\n\tconst work = ensureHandoffWorkState(state, recordWithWorkId);\n\twork.latestRecordSeq = Math.max(work.latestRecordSeq, recordWithWorkId.recordSeq);\n\tswitch (recordWithWorkId.kind) {\n\t\tcase \"work-admitted\":\n\t\t\twork.state = recordWithWorkId.notBeforeMs === undefined ? \"ready\" : \"scheduled\";\n\t\t\twork.notBeforeMs = recordWithWorkId.notBeforeMs;\n\t\t\twork.retryAtMs = undefined;\n\t\t\twork.deadlineMs = recordWithWorkId.deadlineMs;\n\t\t\tclearHandoffLease(work);\n\t\t\tbreak;\n\t\tcase \"work-scheduled\":\n\t\t\twork.state = \"scheduled\";\n\t\t\twork.notBeforeMs = recordWithWorkId.notBeforeMs;\n\t\t\twork.deadlineMs = recordWithWorkId.deadlineMs;\n\t\t\tbreak;\n\t\tcase \"retry-scheduled\":\n\t\t\twork.state =\n\t\t\t\trecordWithWorkId.retryAtMs <= recordWithWorkId.recordedAtMs ? \"ready\" : \"retry-wait\";\n\t\t\twork.retryAtMs = recordWithWorkId.retryAtMs;\n\t\t\twork.notBeforeMs = undefined;\n\t\t\tbreak;\n\t\tcase \"work-claimed\":\n\t\t\twork.state = \"leased\";\n\t\t\twork.leaseId = recordWithWorkId.leaseId;\n\t\t\twork.attempt = recordWithWorkId.attempt;\n\t\t\twork.workerId = recordWithWorkId.workerId;\n\t\t\twork.leaseExpiresAtMs = recordWithWorkId.leaseExpiresAtMs;\n\t\t\tbreak;\n\t\tcase \"lease-renewed\":\n\t\t\twork.state = \"leased\";\n\t\t\twork.leaseId = recordWithWorkId.leaseId;\n\t\t\twork.attempt = recordWithWorkId.attempt;\n\t\t\twork.workerId = recordWithWorkId.workerId;\n\t\t\twork.leaseExpiresAtMs = recordWithWorkId.leaseExpiresAtMs;\n\t\t\tbreak;\n\t\tcase \"work-released\":\n\t\tcase \"lease-expired\":\n\t\t\twork.state = \"ready\";\n\t\t\tclearHandoffLease(work);\n\t\t\tbreak;\n\t\tcase \"work-completed\":\n\t\t\twork.state = \"completed\";\n\t\t\tclearHandoffLease(work);\n\t\t\tbreak;\n\t\tcase \"work-canceled\":\n\t\t\twork.state = \"canceled\";\n\t\t\tclearHandoffLease(work);\n\t\t\tbreak;\n\t\tcase \"work-dead-lettered\":\n\t\t\twork.state = \"dead-lettered\";\n\t\t\tclearHandoffLease(work);\n\t\t\tbreak;\n\t}\n}\n\nfunction ensureHandoffWorkState(\n\tstate: WorkQueueReadinessHandoffProjectorState,\n\trecord: WorkQueueRecordWithWorkId,\n): WorkQueueReadinessWorkState {\n\tconst key = handoffWorkKey(record.queueId, record.workId);\n\tconst existing = state.worksById.get(key);\n\tif (existing !== undefined) return existing;\n\tconst next: WorkQueueReadinessWorkState = {\n\t\tqueueId: record.queueId,\n\t\tworkId: record.workId,\n\t\tstate: \"ready\",\n\t\tlatestRecordSeq: record.recordSeq,\n\t};\n\tstate.worksById.set(key, next);\n\treturn next;\n}\n\nfunction handoffWorkKey(queueId: string, workId: string): string {\n\treturn stableJsonStringify([queueId, workId]);\n}\n\nfunction clearHandoffLease(work: WorkQueueReadinessWorkState): void {\n\twork.leaseId = undefined;\n\twork.attempt = undefined;\n\twork.workerId = undefined;\n\twork.leaseExpiresAtMs = undefined;\n}\n\nfunction evaluateReadyHandoffs(\n\tctx: { down: (msgs: readonly [\"DATA\", WorkQueueReadinessHandoffFact][]) => void },\n\tstate: WorkQueueReadinessHandoffProjectorState,\n): void {\n\tfor (const ready of state.readyByScheduleId.values()) {\n\t\tconst origin = state.originsByScheduleId.get(ready.scheduleId);\n\t\tif (origin === undefined) {\n\t\t\temitHandoffStatus(\n\t\t\t\tctx,\n\t\t\t\tstate,\n\t\t\t\thandoffStatus(\"pending-origin\", {\n\t\t\t\t\tscheduleId: ready.scheduleId,\n\t\t\t\t\treadyAtMs: ready.readyAtMs,\n\t\t\t\t\tnowMs: ready.nowMs,\n\t\t\t\t\tsourceRefs: ready.sourceRefs,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\tconst work = state.worksById.get(handoffWorkKey(origin.record.queueId, origin.record.workId));\n\t\tif (work === undefined) {\n\t\t\temitHandoffStatus(\n\t\t\t\tctx,\n\t\t\t\tstate,\n\t\t\t\thandoffStatus(\"pending-origin\", {\n\t\t\t\t\tqueueId: origin.record.queueId,\n\t\t\t\t\tworkId: origin.record.workId,\n\t\t\t\t\tscheduleId: ready.scheduleId,\n\t\t\t\t\treadyAtMs: ready.readyAtMs,\n\t\t\t\t\tnowMs: ready.nowMs,\n\t\t\t\t\tsourceRefs: ready.sourceRefs,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\tif (origin.record.recordSeq < work.latestRecordSeq) {\n\t\t\temitSuperseded(ctx, state, origin, work, ready, {\n\t\t\t\tlatestRecordSeq: work.latestRecordSeq,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tconst terminal = terminalHandoffState(work.state);\n\t\tif (terminal) {\n\t\t\temitHandoffStatus(\n\t\t\t\tctx,\n\t\t\t\tstate,\n\t\t\t\thandoffStatus(\"ignored-terminal\", {\n\t\t\t\t\tqueueId: work.queueId,\n\t\t\t\t\tworkId: work.workId,\n\t\t\t\t\tscheduleId: ready.scheduleId,\n\t\t\t\t\treadyAtMs: ready.readyAtMs,\n\t\t\t\t\tnowMs: ready.nowMs,\n\t\t\t\t\tcurrentState: work.state,\n\t\t\t\t\tsourceRefs: ready.sourceRefs,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\tif (origin.scheduleKind === \"lease-expiration\") {\n\t\t\tevaluateLeaseExpirationReady(ctx, state, origin, work, ready);\n\t\t\tcontinue;\n\t\t}\n\t\tevaluateClaimEligibilityReady(ctx, state, origin, work, ready);\n\t}\n}\n\nfunction evaluateClaimEligibilityReady(\n\tctx: { down: (msgs: readonly [\"DATA\", WorkQueueReadinessHandoffFact][]) => void },\n\tstate: WorkQueueReadinessHandoffProjectorState,\n\torigin: WorkQueueReadinessOrigin,\n\twork: WorkQueueReadinessWorkState,\n\tready: ScheduledReadinessReady,\n): void {\n\tif (work.state === \"leased\") {\n\t\temitHandoffStatus(\n\t\t\tctx,\n\t\t\tstate,\n\t\t\thandoffStatus(\"ignored-stale\", {\n\t\t\t\tqueueId: work.queueId,\n\t\t\t\tworkId: work.workId,\n\t\t\t\tscheduleId: ready.scheduleId,\n\t\t\t\treadyAtMs: ready.readyAtMs,\n\t\t\t\tnowMs: ready.nowMs,\n\t\t\t\tcurrentState: work.state,\n\t\t\t\tsourceRefs: ready.sourceRefs,\n\t\t\t}),\n\t\t);\n\t\treturn;\n\t}\n\tif (work.notBeforeMs !== undefined && work.notBeforeMs > ready.nowMs) {\n\t\temitSuperseded(ctx, state, origin, work, ready, { notBeforeMs: work.notBeforeMs });\n\t\treturn;\n\t}\n\tif (work.retryAtMs !== undefined && work.retryAtMs > ready.nowMs) {\n\t\temitSuperseded(ctx, state, origin, work, ready, { retryAtMs: work.retryAtMs });\n\t\treturn;\n\t}\n\temitCandidate(ctx, state, candidateFor(origin, ready, \"claim-eligible\"));\n}\n\nfunction evaluateLeaseExpirationReady(\n\tctx: { down: (msgs: readonly [\"DATA\", WorkQueueReadinessHandoffFact][]) => void },\n\tstate: WorkQueueReadinessHandoffProjectorState,\n\torigin: WorkQueueReadinessOrigin,\n\twork: WorkQueueReadinessWorkState,\n\tready: ScheduledReadinessReady,\n): void {\n\tif (origin.record.kind !== \"work-claimed\" && origin.record.kind !== \"lease-renewed\") {\n\t\temitHandoffIssue(\n\t\t\tctx,\n\t\t\tstate,\n\t\t\tdataIssue(\n\t\t\t\t\"work-queue-readiness-handoff-malformed-origin\",\n\t\t\t\t\"Lease-expiration readiness must originate from a lease-bearing workQueue record.\",\n\t\t\t\t{ subjectId: ready.scheduleId, refs: ready.sourceRefs },\n\t\t\t),\n\t\t);\n\t\treturn;\n\t}\n\tif (\n\t\twork.state !== \"leased\" ||\n\t\twork.leaseId !== origin.record.leaseId ||\n\t\twork.attempt !== origin.record.attempt ||\n\t\twork.workerId !== origin.record.workerId\n\t) {\n\t\temitHandoffStatus(\n\t\t\tctx,\n\t\t\tstate,\n\t\t\thandoffStatus(\"ignored-stale\", {\n\t\t\t\tqueueId: work.queueId,\n\t\t\t\tworkId: work.workId,\n\t\t\t\tscheduleId: ready.scheduleId,\n\t\t\t\treadyAtMs: ready.readyAtMs,\n\t\t\t\tnowMs: ready.nowMs,\n\t\t\t\tcurrentState: work.state,\n\t\t\t\tsourceRefs: ready.sourceRefs,\n\t\t\t}),\n\t\t);\n\t\treturn;\n\t}\n\tif (work.leaseExpiresAtMs !== origin.record.leaseExpiresAtMs) {\n\t\temitSuperseded(ctx, state, origin, work, ready, {\n\t\t\tleaseExpiresAtMs: work.leaseExpiresAtMs,\n\t\t});\n\t\treturn;\n\t}\n\tif (work.leaseExpiresAtMs !== undefined && work.leaseExpiresAtMs > ready.nowMs) {\n\t\temitSuperseded(ctx, state, origin, work, ready, {\n\t\t\tleaseExpiresAtMs: work.leaseExpiresAtMs,\n\t\t});\n\t\treturn;\n\t}\n\temitCandidate(ctx, state, candidateFor(origin, ready, \"lease-expiration-eligible\"));\n}\n\nfunction emitSuperseded(\n\tctx: { down: (msgs: readonly [\"DATA\", WorkQueueReadinessHandoffFact][]) => void },\n\tstate: WorkQueueReadinessHandoffProjectorState,\n\torigin: WorkQueueReadinessOrigin,\n\twork: WorkQueueReadinessWorkState,\n\tready: ScheduledReadinessReady,\n\tmetadata: Record<string, unknown>,\n): void {\n\temitHandoffStatus(\n\t\tctx,\n\t\tstate,\n\t\thandoffStatus(\"ignored-superseded\", {\n\t\t\tqueueId: work.queueId,\n\t\t\tworkId: work.workId,\n\t\t\tscheduleId: ready.scheduleId,\n\t\t\treadyAtMs: ready.readyAtMs,\n\t\t\tnowMs: ready.nowMs,\n\t\t\tcurrentState: work.state,\n\t\t\tsourceRefs: ready.sourceRefs,\n\t\t\tmetadata: {\n\t\t\t\toriginRecordSeq: origin.record.recordSeq,\n\t\t\t\toriginRecordKind: origin.record.kind,\n\t\t\t\t...metadata,\n\t\t\t},\n\t\t}),\n\t);\n}\n\nfunction candidateFor(\n\torigin: WorkQueueReadinessOrigin,\n\tready: ScheduledReadinessReady,\n\tcandidateKind: WorkQueueReadinessCandidateKind,\n): WorkQueueReadinessCandidate {\n\tconst lease =\n\t\torigin.record.kind === \"work-claimed\" || origin.record.kind === \"lease-renewed\"\n\t\t\t? {\n\t\t\t\t\tleaseId: origin.record.leaseId,\n\t\t\t\t\tattempt: origin.record.attempt,\n\t\t\t\t\tworkerId: origin.record.workerId,\n\t\t\t\t\tleaseExpiresAtMs: origin.record.leaseExpiresAtMs,\n\t\t\t\t}\n\t\t\t: {};\n\tconst metadata = sanitizeGraphVisibleRecord({\n\t\toriginRecordSeq: origin.record.recordSeq,\n\t\toriginRecordKind: origin.record.kind,\n\t\tscheduleKind: origin.scheduleKind,\n\t});\n\treturn Object.freeze({\n\t\tkind: \"work-queue-readiness-candidate\",\n\t\tcandidateId: `${ready.scheduleId}:work-queue:${candidateKind}`,\n\t\tcandidateKind,\n\t\tqueueId: origin.record.queueId,\n\t\tworkId: origin.record.workId,\n\t\tscheduleId: ready.scheduleId,\n\t\treadyAtMs: ready.readyAtMs,\n\t\tnowMs: ready.nowMs,\n\t\toriginRecordSeq: origin.record.recordSeq,\n\t\toriginRecordKind: origin.record.kind,\n\t\t...lease,\n\t\tsourceRefs: canonicalPublicSourceRefs(\n\t\t\tuniqueSourceRefs([\n\t\t\t\t...(ready.sourceRefs ?? []),\n\t\t\t\tref(\"work-queue-record\", String(origin.record.recordSeq)),\n\t\t\t\tref(\"scheduled-readiness-ready\", ready.scheduleId),\n\t\t\t]),\n\t\t),\n\t\t...(metadata === undefined ? {} : { metadata }),\n\t} satisfies WorkQueueReadinessCandidate);\n}\n\nfunction emitCandidate(\n\tctx: { down: (msgs: readonly [\"DATA\", WorkQueueReadinessHandoffFact][]) => void },\n\tstate: WorkQueueReadinessHandoffProjectorState,\n\tcandidate: WorkQueueReadinessCandidate,\n): void {\n\tconst key = `candidate:${candidate.candidateId}`;\n\tif (!state.emittedKeys.has(key)) {\n\t\tstate.emittedKeys.add(key);\n\t\tstate.candidatesById.set(candidate.candidateId, candidate);\n\t\tctx.down([[\"DATA\", { kind: \"candidate\", candidate }]]);\n\t\temitHandoffAudit(ctx, state, \"work-queue-readiness-candidate\", {\n\t\t\tsubjectId: candidate.candidateId,\n\t\t\tsourceRefs: candidate.sourceRefs,\n\t\t\tmetadata: {\n\t\t\t\tcandidateKind: candidate.candidateKind,\n\t\t\t\tqueueId: candidate.queueId,\n\t\t\t\tworkId: candidate.workId,\n\t\t\t\treadyAtMs: candidate.readyAtMs,\n\t\t\t\tnowMs: candidate.nowMs,\n\t\t\t},\n\t\t});\n\t} else {\n\t\tstate.candidatesById.set(candidate.candidateId, candidate);\n\t}\n\temitHandoffStatus(\n\t\tctx,\n\t\tstate,\n\t\thandoffStatus(\"candidate\", {\n\t\t\tqueueId: candidate.queueId,\n\t\t\tworkId: candidate.workId,\n\t\t\tscheduleId: candidate.scheduleId,\n\t\t\tcandidateId: candidate.candidateId,\n\t\t\tcandidateKind: candidate.candidateKind,\n\t\t\treadyAtMs: candidate.readyAtMs,\n\t\t\tnowMs: candidate.nowMs,\n\t\t\tsourceRefs: candidate.sourceRefs,\n\t\t}),\n\t);\n}\n\nfunction emitOverdueHandoffStatus(\n\tctx: { down: (msgs: readonly [\"DATA\", WorkQueueReadinessHandoffFact][]) => void },\n\tstate: WorkQueueReadinessHandoffProjectorState,\n\toverdue: ScheduledReadinessOverdue,\n): void {\n\tconst origin = state.originsByScheduleId.get(overdue.scheduleId);\n\temitHandoffStatus(\n\t\tctx,\n\t\tstate,\n\t\thandoffStatus(\"overdue\", {\n\t\t\tqueueId: origin?.record.queueId,\n\t\t\tworkId: origin?.record.workId,\n\t\t\tscheduleId: overdue.scheduleId,\n\t\t\treadyAtMs: overdue.readyAtMs,\n\t\t\tnowMs: overdue.nowMs,\n\t\t\tsourceRefs: overdue.sourceRefs,\n\t\t\tmetadata: {\n\t\t\t\tdeadlineMs: overdue.deadlineMs,\n\t\t\t\t...(origin === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: { originRecordSeq: origin.record.recordSeq, originRecordKind: origin.record.kind }),\n\t\t\t},\n\t\t}),\n\t);\n}\n\nfunction handoffStatus(\n\tstate: WorkQueueReadinessHandoffStatusState,\n\topts: {\n\t\treadonly queueId?: string;\n\t\treadonly workId?: string;\n\t\treadonly scheduleId?: string;\n\t\treadonly candidateId?: string;\n\t\treadonly candidateKind?: WorkQueueReadinessCandidateKind;\n\t\treadonly readyAtMs?: number;\n\t\treadonly nowMs?: number;\n\t\treadonly currentState?: WorkQueueDerivedState;\n\t\treadonly sourceRefs?: readonly SourceRef[];\n\t\treadonly issueCodes?: readonly string[];\n\t\treadonly metadata?: Record<string, unknown>;\n\t},\n): WorkQueueReadinessHandoffStatus {\n\tconst subject = opts.candidateId ?? opts.scheduleId ?? \"unknown-work-queue-readiness\";\n\tconst metadata = sanitizeGraphVisibleRecord(opts.metadata);\n\treturn Object.freeze({\n\t\tkind: \"work-queue-readiness-handoff-status\",\n\t\tstatusId: `${subject}:work-queue-readiness-handoff-status:${state}`,\n\t\tstate,\n\t\t...(opts.queueId === undefined ? {} : { queueId: opts.queueId }),\n\t\t...(opts.workId === undefined ? {} : { workId: opts.workId }),\n\t\t...(opts.scheduleId === undefined ? {} : { scheduleId: opts.scheduleId }),\n\t\t...(opts.candidateId === undefined ? {} : { candidateId: opts.candidateId }),\n\t\t...(opts.candidateKind === undefined ? {} : { candidateKind: opts.candidateKind }),\n\t\t...(opts.readyAtMs === undefined ? {} : { readyAtMs: opts.readyAtMs }),\n\t\t...(opts.nowMs === undefined ? {} : { nowMs: opts.nowMs }),\n\t\t...(opts.currentState === undefined ? {} : { currentState: opts.currentState }),\n\t\t...(opts.sourceRefs === undefined\n\t\t\t? {}\n\t\t\t: { sourceRefs: canonicalPublicSourceRefs(opts.sourceRefs) }),\n\t\t...(opts.issueCodes === undefined ? {} : { issueCodes: opts.issueCodes }),\n\t\t...(metadata === undefined ? {} : { metadata }),\n\t} satisfies WorkQueueReadinessHandoffStatus);\n}\n\nfunction emitHandoffStatus(\n\tctx: { down: (msgs: readonly [\"DATA\", WorkQueueReadinessHandoffFact][]) => void },\n\tstate: WorkQueueReadinessHandoffProjectorState,\n\tstatus: WorkQueueReadinessHandoffStatus,\n): void {\n\tstate.statusById.set(status.statusId, status);\n\tconst key = `handoff-status:${status.statusId}:${stableJsonStringify(status)}`;\n\tif (state.emittedKeys.has(key)) return;\n\tstate.emittedKeys.add(key);\n\tctx.down([[\"DATA\", { kind: \"status\", status }]]);\n}\n\nfunction emitHandoffIssue(\n\tctx: { down: (msgs: readonly [\"DATA\", WorkQueueReadinessHandoffFact][]) => void },\n\tstate: WorkQueueReadinessHandoffProjectorState,\n\tissue: DataIssue,\n): void {\n\tconst key = `${issue.code}:${issue.subjectId ?? \"\"}:${JSON.stringify(issue.details ?? {})}`;\n\tif (state.issueKeys.has(key)) return;\n\tstate.issueKeys.add(key);\n\tctx.down([[\"DATA\", { kind: \"issue\", issue }]]);\n\temitHandoffStatus(\n\t\tctx,\n\t\tstate,\n\t\thandoffStatus(\"issue\", {\n\t\t\tscheduleId: issue.subjectId,\n\t\t\tsourceRefs: issue.refs?.map(sourceRefFromIssueRef),\n\t\t\tissueCodes: [issue.code],\n\t\t}),\n\t);\n}\n\nfunction emitHandoffAudit(\n\tctx: { down: (msgs: readonly [\"DATA\", WorkQueueReadinessHandoffFact][]) => void },\n\tstate: WorkQueueReadinessHandoffProjectorState,\n\tkind: string,\n\topts: {\n\t\treadonly subjectId: string;\n\t\treadonly sourceRefs?: readonly SourceRef[];\n\t\treadonly metadata?: Record<string, unknown>;\n\t},\n): void {\n\tstate.auditSeq += 1;\n\tconst metadata = sanitizeGraphVisibleRecord(opts.metadata);\n\tctx.down([\n\t\t[\n\t\t\t\"DATA\",\n\t\t\t{\n\t\t\t\tkind: \"audit\",\n\t\t\t\taudit: Object.freeze({\n\t\t\t\t\tid: `work-queue-readiness-handoff-audit-${state.auditSeq}`,\n\t\t\t\t\tkind,\n\t\t\t\t\tsubjectId: opts.subjectId,\n\t\t\t\t\t...(opts.sourceRefs === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: { sourceRefs: canonicalPublicSourceRefs(opts.sourceRefs) }),\n\t\t\t\t\t...(metadata === undefined ? {} : { metadata }),\n\t\t\t\t} satisfies AgentRuntimeAuditRecord),\n\t\t\t},\n\t\t],\n\t]);\n}\n\nfunction buildHandoffViews(\n\tstate: WorkQueueReadinessHandoffProjectorState,\n): WorkQueueReadinessHandoffViews {\n\treturn Object.freeze({\n\t\tcandidatesById: new Map(state.candidatesById),\n\t\tstatusById: new Map(state.statusById),\n\t});\n}\n\nfunction emitLeaseCommandStatus<T>(\n\tctx: { down: (msgs: readonly [\"DATA\", WorkQueueLeaseExpirationCommandFact<T>][]) => void },\n\tstate: WorkQueueLeaseExpirationCommandProjectorState<T>,\n\tcommand: WorkQueueCommand<T>,\n\tcandidate: WorkQueueReadinessCandidate,\n): void {\n\tconst status = handoffStatus(\"candidate\", {\n\t\tqueueId: candidate.queueId,\n\t\tworkId: candidate.workId,\n\t\tscheduleId: candidate.scheduleId,\n\t\tcandidateId: candidate.candidateId,\n\t\tcandidateKind: candidate.candidateKind,\n\t\treadyAtMs: candidate.readyAtMs,\n\t\tnowMs: candidate.nowMs,\n\t\tsourceRefs: candidate.sourceRefs,\n\t\tmetadata: {\n\t\t\tcommandId: command.commandId,\n\t\t\tcommandKind: command.kind,\n\t\t},\n\t});\n\tstate.statusById.set(status.statusId, status);\n\tconst key = `lease-command-status:${status.statusId}`;\n\tif (state.emittedKeys.has(key)) return;\n\tstate.emittedKeys.add(key);\n\tctx.down([[\"DATA\", { kind: \"status\", status }]]);\n}\n\nfunction buildLeaseCommandViews<T>(\n\tstate: WorkQueueLeaseExpirationCommandProjectorState<T>,\n): WorkQueueReadinessHandoffViews {\n\treturn Object.freeze({\n\t\tcandidatesById: new Map(),\n\t\tstatusById: new Map(state.statusById),\n\t});\n}\n\nfunction sourceRefStrings(\n\tsourceRefs: readonly SourceRef[] | undefined,\n): readonly string[] | undefined {\n\tif (sourceRefs === undefined || sourceRefs.length === 0) return undefined;\n\treturn sourceRefs.map((sourceRef) => `${sourceRef.kind}:${sourceRef.id}`);\n}\n\nfunction sourceRefFromIssueRef(issueRef: string): SourceRef {\n\tconst [kind, ...rest] = issueRef.split(\":\");\n\treturn ref(kind || \"issue-ref\", rest.join(\":\") || issueRef);\n}\n\nfunction terminalHandoffState(state: WorkQueueDerivedState): boolean {\n\treturn state === \"completed\" || state === \"canceled\" || state === \"dead-lettered\";\n}\n\nfunction hasWorkRecordCoordinates(record: Record<string, unknown>): boolean {\n\treturn (\n\t\ttypeof record.queueId === \"string\" &&\n\t\ttypeof record.workId === \"string\" &&\n\t\ttypeof record.recordSeq === \"number\" &&\n\t\tNumber.isFinite(record.recordSeq)\n\t);\n}\n\nfunction hasLeaseRecordCoordinates(record: Record<string, unknown>): boolean {\n\treturn (\n\t\thasWorkRecordCoordinates(record) &&\n\t\ttypeof record.leaseId === \"string\" &&\n\t\ttypeof record.attempt === \"number\" &&\n\t\tNumber.isFinite(record.attempt) &&\n\t\ttypeof record.workerId === \"string\"\n\t);\n}\n\nfunction malformedRecord(record: Record<string, unknown>, message: string): TranslatedRecord {\n\tconst subjectId =\n\t\ttypeof record.kind === \"string\"\n\t\t\t? `work-queue-record:${publicCoordinateId(record.kind)}`\n\t\t\t: \"unknown-work-queue-record\";\n\tconst issue = dataIssue(\"work-queue-scheduled-readiness-malformed-record\", message, {\n\t\tsubjectId,\n\t\trefs: [],\n\t\tdetails: sanitizeGraphVisibleRecord({\n\t\t\trecordKind: typeof record.kind === \"string\" ? record.kind : undefined,\n\t\t\tqueueId: typeof record.queueId === \"string\" ? publicCoordinateId(record.queueId) : undefined,\n\t\t\tworkId: typeof record.workId === \"string\" ? publicCoordinateId(record.workId) : undefined,\n\t\t\trecordSeq:\n\t\t\t\ttypeof record.recordSeq === \"number\" && Number.isFinite(record.recordSeq)\n\t\t\t\t\t? record.recordSeq\n\t\t\t\t\t: undefined,\n\t\t}),\n\t});\n\treturn {\n\t\tkind: \"issue\",\n\t\tissue,\n\t\tstatus: issueStatus(subjectId, [issue]),\n\t};\n}\n\nfunction translateRecord(raw: unknown): TranslatedRecord {\n\tif (!isRecord(raw)) {\n\t\tconst issue = dataIssue(\n\t\t\t\"work-queue-scheduled-readiness-malformed-record\",\n\t\t\t\"WorkQueue scheduled readiness requires a graph-visible workQueue record.\",\n\t\t\t{ subjectId: \"unknown-work-queue-record\", refs: [] },\n\t\t);\n\t\treturn {\n\t\t\tkind: \"issue\",\n\t\t\tissue,\n\t\t\tstatus: issueStatus(\"unknown-work-queue-record\", [issue]),\n\t\t};\n\t}\n\tconst unknownRecord: unknown = raw;\n\tconst rawRecord = unknownRecord as Record<string, unknown>;\n\tswitch (rawRecord.kind) {\n\t\tcase \"work-admitted\": {\n\t\t\tconst notBeforeMs = rawRecord.notBeforeMs;\n\t\t\tif (notBeforeMs === undefined) return { kind: \"none\" };\n\t\t\tif (typeof notBeforeMs !== \"number\") {\n\t\t\t\treturn malformedRecord(rawRecord, \"Delayed work-admitted notBeforeMs must be a number.\");\n\t\t\t}\n\t\t\tif (!hasWorkRecordCoordinates(rawRecord)) {\n\t\t\t\treturn malformedRecord(\n\t\t\t\t\trawRecord,\n\t\t\t\t\t\"Delayed work-admitted records require queueId, workId, and recordSeq.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst admitted = rawRecord as unknown as Extract<\n\t\t\t\tWorkQueueRecord<unknown>,\n\t\t\t\t{ readonly kind: \"work-admitted\" }\n\t\t\t>;\n\t\t\treturn scheduleFromRecord(admitted, {\n\t\t\t\tscheduleKind: \"work-admitted\",\n\t\t\t\tscheduleId: workQueueScheduleId(admitted, \"admission\", admitted.recordSeq),\n\t\t\t\treadyAtMs: notBeforeMs,\n\t\t\t\tdeadlineMs: admitted.deadlineMs,\n\t\t\t\treason: \"work-queue-delayed-admission\",\n\t\t\t});\n\t\t}\n\t\tcase \"work-scheduled\": {\n\t\t\tif (!hasWorkRecordCoordinates(rawRecord)) {\n\t\t\t\treturn malformedRecord(\n\t\t\t\t\trawRecord,\n\t\t\t\t\t\"work-scheduled records require queueId, workId, and recordSeq.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst scheduled = rawRecord as unknown as Extract<\n\t\t\t\tWorkQueueRecord<unknown>,\n\t\t\t\t{ readonly kind: \"work-scheduled\" }\n\t\t\t>;\n\t\t\treturn scheduleFromRecord(scheduled, {\n\t\t\t\tscheduleKind: \"work-scheduled\",\n\t\t\t\tscheduleId: workQueueScheduleId(\n\t\t\t\t\tscheduled,\n\t\t\t\t\t\"schedule\",\n\t\t\t\t\tscheduled.scheduleId ?? scheduled.commandId ?? scheduled.recordSeq,\n\t\t\t\t),\n\t\t\t\treadyAtMs: scheduled.notBeforeMs,\n\t\t\t\tdeadlineMs: scheduled.deadlineMs,\n\t\t\t\treason: scheduled.reason ?? \"work-queue-schedule\",\n\t\t\t});\n\t\t}\n\t\tcase \"retry-scheduled\": {\n\t\t\tif (!hasWorkRecordCoordinates(rawRecord)) {\n\t\t\t\treturn malformedRecord(\n\t\t\t\t\trawRecord,\n\t\t\t\t\t\"retry-scheduled records require queueId, workId, and recordSeq.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst retry = rawRecord as unknown as Extract<\n\t\t\t\tWorkQueueRecord<unknown>,\n\t\t\t\t{ readonly kind: \"retry-scheduled\" }\n\t\t\t>;\n\t\t\treturn scheduleFromRecord(retry, {\n\t\t\t\tscheduleKind: \"retry-scheduled\",\n\t\t\t\tscheduleId: workQueueScheduleId(retry, \"retry\", retry.commandId ?? retry.recordSeq),\n\t\t\t\treadyAtMs: retry.retryAtMs,\n\t\t\t\treason: retry.reason ?? \"work-queue-retry\",\n\t\t\t\tmetadata: { delayMs: retry.delayMs },\n\t\t\t});\n\t\t}\n\t\tcase \"work-claimed\": {\n\t\t\tif (!hasLeaseRecordCoordinates(rawRecord)) {\n\t\t\t\treturn malformedRecord(\n\t\t\t\t\trawRecord,\n\t\t\t\t\t\"work-claimed records require queueId, workId, recordSeq, leaseId, attempt, and workerId.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst claimed = rawRecord as unknown as Extract<\n\t\t\t\tWorkQueueRecord<unknown>,\n\t\t\t\t{ readonly kind: \"work-claimed\" }\n\t\t\t>;\n\t\t\treturn scheduleFromRecord(claimed, {\n\t\t\t\tscheduleKind: \"lease-expiration\",\n\t\t\t\tscheduleId: workQueueLeaseScheduleId(claimed),\n\t\t\t\treadyAtMs: claimed.leaseExpiresAtMs,\n\t\t\t\treason: \"work-queue-lease-expiration\",\n\t\t\t\tleaseId: claimed.leaseId,\n\t\t\t\tmetadata: { attempt: claimed.attempt },\n\t\t\t});\n\t\t}\n\t\tcase \"lease-renewed\": {\n\t\t\tif (!hasLeaseRecordCoordinates(rawRecord)) {\n\t\t\t\treturn malformedRecord(\n\t\t\t\t\trawRecord,\n\t\t\t\t\t\"lease-renewed records require queueId, workId, recordSeq, leaseId, attempt, and workerId.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst renewed = rawRecord as unknown as Extract<\n\t\t\t\tWorkQueueRecord<unknown>,\n\t\t\t\t{ readonly kind: \"lease-renewed\" }\n\t\t\t>;\n\t\t\treturn scheduleFromRecord(renewed, {\n\t\t\t\tscheduleKind: \"lease-expiration\",\n\t\t\t\tscheduleId: workQueueLeaseScheduleId(renewed),\n\t\t\t\treadyAtMs: renewed.leaseExpiresAtMs,\n\t\t\t\treason: \"work-queue-lease-expiration\",\n\t\t\t\tleaseId: renewed.leaseId,\n\t\t\t\tmetadata: {\n\t\t\t\t\tattempt: renewed.attempt,\n\t\t\t\t\tpreviousLeaseExpiresAtMs: renewed.previousLeaseExpiresAtMs,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tdefault:\n\t\t\treturn { kind: \"none\" };\n\t}\n}\n\nfunction scheduleFromRecord(\n\trecord: WorkQueueRecordWithWorkId,\n\topts: {\n\t\treadonly scheduleKind: WorkQueueScheduledReadinessScheduleKind;\n\t\treadonly scheduleId: string;\n\t\treadonly readyAtMs: number;\n\t\treadonly deadlineMs?: number;\n\t\treadonly reason: string;\n\t\treadonly leaseId?: string;\n\t\treadonly metadata?: Record<string, unknown>;\n\t},\n): TranslatedRecord {\n\tif (!Number.isFinite(opts.readyAtMs) || !finiteOrUndefined(opts.deadlineMs)) {\n\t\tconst refs = recordSourceRefs(record, opts.leaseId);\n\t\tconst issue = dataIssue(\n\t\t\t\"work-queue-scheduled-readiness-malformed-record\",\n\t\t\t\"WorkQueue delayed eligibility record must carry finite readiness and deadline coordinates.\",\n\t\t\t{\n\t\t\t\tsubjectId: workQueueRecordSubjectId(record),\n\t\t\t\trefs,\n\t\t\t\tdetails: {\n\t\t\t\t\trecordKind: record.kind,\n\t\t\t\t\treadyAtMs: opts.readyAtMs,\n\t\t\t\t\tdeadlineMs: opts.deadlineMs,\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t\treturn {\n\t\t\tkind: \"issue\",\n\t\t\tissue,\n\t\t\tstatus: issueStatus(opts.scheduleId, [issue], record, refs),\n\t\t};\n\t}\n\tconst subjectRefs = recordSubjectRefs(record, opts.leaseId);\n\tconst sourceRefs = recordSourceRefs(record, opts.leaseId);\n\tconst recordPolicyRefs = policyRefs(record);\n\tconst metadata = sanitizeGraphVisibleRecord({\n\t\tqueueId: publicCoordinateId(record.queueId),\n\t\tworkId: publicCoordinateId(record.workId),\n\t\trecordSeq: record.recordSeq,\n\t\trecordKind: record.kind,\n\t\tscheduleKind: opts.scheduleKind,\n\t\t...(record.commandId === undefined ? {} : { commandId: publicCoordinateId(record.commandId) }),\n\t\t...(opts.leaseId === undefined ? {} : { leaseId: publicCoordinateId(opts.leaseId) }),\n\t\t...(opts.metadata ?? {}),\n\t});\n\tconst schedule = Object.freeze({\n\t\tkind: \"scheduled-readiness-requested\",\n\t\tscheduleId: opts.scheduleId,\n\t\tsubjectRefs,\n\t\treadyAtMs: opts.readyAtMs,\n\t\t...(opts.deadlineMs === undefined ? {} : { deadlineMs: opts.deadlineMs }),\n\t\treason: opts.reason,\n\t\t...(recordPolicyRefs === undefined ? {} : { policyRefs: recordPolicyRefs }),\n\t\tsourceRefs,\n\t\t...(metadata === undefined ? {} : { metadata }),\n\t} satisfies ScheduledReadinessRequested);\n\treturn {\n\t\tkind: \"translated\",\n\t\trecord,\n\t\tschedule,\n\t\tstatus: Object.freeze({\n\t\t\tkind: \"work-queue-scheduled-readiness-status\",\n\t\t\tstatusId: `${opts.scheduleId}:work-queue-scheduled-readiness-status:translated`,\n\t\t\tqueueId: publicCoordinateId(record.queueId),\n\t\t\tworkId: publicCoordinateId(record.workId),\n\t\t\trecordSeq: record.recordSeq,\n\t\t\tstate: \"translated\",\n\t\t\tscheduleKind: opts.scheduleKind,\n\t\t\tscheduleId: opts.scheduleId,\n\t\t\treadyAtMs: opts.readyAtMs,\n\t\t\t...(opts.deadlineMs === undefined ? {} : { deadlineMs: opts.deadlineMs }),\n\t\t\tsourceRefs,\n\t\t\t...(metadata === undefined ? {} : { metadata }),\n\t\t} satisfies WorkQueueScheduledReadinessStatus),\n\t};\n}\n\nfunction recordSubjectRefs<T>(\n\trecord: WorkQueueRecord<T> & { readonly workId: string },\n\tleaseId?: string,\n): readonly SourceRef[] {\n\treturn canonicalPublicSourceRefs(\n\t\tuniqueSourceRefs([\n\t\t\tref(\"work-queue\", publicCoordinateId(record.queueId)),\n\t\t\tref(\"work-queue-work\", publicCoordinateId(record.workId)),\n\t\t\tref(\"work-queue-record\", String(record.recordSeq)),\n\t\t\t...(record.commandId === undefined\n\t\t\t\t? []\n\t\t\t\t: [ref(\"work-queue-command\", publicCoordinateId(record.commandId))]),\n\t\t\t...(leaseId === undefined ? [] : [ref(\"work-queue-lease\", publicCoordinateId(leaseId))]),\n\t\t]),\n\t);\n}\n\nfunction recordSourceRefs<T>(\n\trecord: WorkQueueRecord<T> & { readonly workId?: string },\n\tleaseId?: string,\n): readonly SourceRef[] {\n\treturn canonicalPublicSourceRefs(\n\t\tuniqueSourceRefs([\n\t\t\tref(\"work-queue\", publicCoordinateId(record.queueId)),\n\t\t\tref(\"work-queue-record\", String(record.recordSeq)),\n\t\t\t...(record.workId === undefined\n\t\t\t\t? []\n\t\t\t\t: [ref(\"work-queue-work\", publicCoordinateId(record.workId))]),\n\t\t\t...(record.commandId === undefined\n\t\t\t\t? []\n\t\t\t\t: [ref(\"work-queue-command\", publicCoordinateId(record.commandId))]),\n\t\t\t...(leaseId === undefined ? [] : [ref(\"work-queue-lease\", publicCoordinateId(leaseId))]),\n\t\t\t...copiedPublicRefs(record.sourceRefs, \"work-queue-source-ref\"),\n\t\t]),\n\t);\n}\n\nfunction policyRefs<T>(record: WorkQueueRecord<T>): readonly SourceRef[] | undefined {\n\tif (record.policyRefs === undefined || record.policyRefs.length === 0) return undefined;\n\treturn canonicalPublicSourceRefs(copiedPublicRefs(record.policyRefs, \"work-queue-policy-ref\"));\n}\n\nfunction workQueueScheduleId<T>(\n\trecord: WorkQueueRecord<T> & { readonly workId: string },\n\tpart: \"admission\" | \"retry\" | \"schedule\",\n\tid: string | number,\n): string {\n\treturn `workQueue:${publicCoordinateId(record.queueId)}:${publicCoordinateId(record.workId)}:${part}:${publicCoordinateId(String(id))}`;\n}\n\nfunction workQueueLeaseScheduleId<T>(\n\trecord: WorkQueueRecord<T> & {\n\t\treadonly workId: string;\n\t\treadonly leaseId: string;\n\t\treadonly recordSeq: number;\n\t},\n): string {\n\treturn `workQueue:${publicCoordinateId(record.queueId)}:${publicCoordinateId(record.workId)}:lease:${publicCoordinateId(record.leaseId)}:expires:${record.recordSeq}`;\n}\n\nfunction workQueueRecordSubjectId<T>(\n\trecord: WorkQueueRecord<T> & { readonly workId: string },\n): string {\n\treturn `${publicCoordinateId(record.queueId)}:${publicCoordinateId(record.workId)}:${record.recordSeq}`;\n}\n\nfunction copiedPublicRefs(ids: readonly string[] | undefined, kind: string): readonly SourceRef[] {\n\tif (ids === undefined || ids.length === 0) return [];\n\tconst copied = ids\n\t\t.slice(0, MAX_COPIED_PUBLIC_REFS)\n\t\t.map((id) => ref(kind, publicCoordinateId(id)));\n\tif (ids.length <= MAX_COPIED_PUBLIC_REFS) return copied;\n\treturn [\n\t\t...copied,\n\t\tref(\n\t\t\t`${kind}-overflow`,\n\t\t\t`count:${ids.length}:hash:${stableStringHash(stableJsonStringify(ids))}`,\n\t\t),\n\t];\n}\n\nfunction publicCoordinateId(id: string): string {\n\tif (id.length <= MAX_PUBLIC_COORDINATE_ID_CHARS && !PRIVATE_COORDINATE_PATTERN.test(id)) {\n\t\treturn id;\n\t}\n\treturn `bounded:${stableStringHash(id)}:${id.length}`;\n}\n\nfunction issueStatus<T>(\n\tstatusId: string,\n\tissues: readonly DataIssue[],\n\trecord?: WorkQueueRecord<T>,\n\tsourceRefs?: readonly SourceRef[],\n): WorkQueueScheduledReadinessStatus {\n\treturn Object.freeze({\n\t\tkind: \"work-queue-scheduled-readiness-status\",\n\t\tstatusId: `${statusId}:work-queue-scheduled-readiness-status:issue`,\n\t\t...(record?.queueId === undefined ? {} : { queueId: publicCoordinateId(record.queueId) }),\n\t\t...(record?.workId === undefined ? {} : { workId: publicCoordinateId(record.workId) }),\n\t\t...(record?.recordSeq === undefined ? {} : { recordSeq: record.recordSeq }),\n\t\tstate: \"issue\",\n\t\t...(sourceRefs === undefined ? {} : { sourceRefs }),\n\t\tissueCodes: issues.map((issue) => issue.code),\n\t} satisfies WorkQueueScheduledReadinessStatus);\n}\n\nfunction finiteOrUndefined(value: number | undefined): boolean {\n\treturn value === undefined || Number.isFinite(value);\n}\n\nfunction scheduleIdentity(schedule: ScheduledReadinessRequested): string {\n\treturn stableJsonStringify({\n\t\tscheduleId: schedule.scheduleId,\n\t\tsubjectRefs: schedule.subjectRefs,\n\t\treadyAtMs: schedule.readyAtMs,\n\t\tdeadlineMs: schedule.deadlineMs,\n\t\treason: schedule.reason,\n\t\tpolicyRefs: schedule.policyRefs,\n\t\tsourceRefs: schedule.sourceRefs,\n\t\tmetadata: schedule.metadata,\n\t});\n}\n\nfunction emitScheduleConflict(\n\tctx: { down: (msgs: readonly [\"DATA\", WorkQueueScheduledReadinessFact][]) => void },\n\tstate: WorkQueueScheduledReadinessProjectorState,\n\ttranslated: Extract<TranslatedRecord, { readonly kind: \"translated\" }>,\n\texisting?: ScheduledReadinessRequested,\n): void {\n\tconst issue = dataIssue(\n\t\t\"work-queue-scheduled-readiness-schedule-conflict\",\n\t\t\"WorkQueue delayed eligibility replayed with conflicting scheduled-readiness material; the first schedule was retained.\",\n\t\t{\n\t\t\tsubjectId: translated.schedule.scheduleId,\n\t\t\trefs: translated.schedule.sourceRefs,\n\t\t\tdetails: {\n\t\t\t\texistingReadyAtMs: existing?.readyAtMs,\n\t\t\t\tincomingReadyAtMs: translated.schedule.readyAtMs,\n\t\t\t\texistingDeadlineMs: existing?.deadlineMs,\n\t\t\t\tincomingDeadlineMs: translated.schedule.deadlineMs,\n\t\t\t\trecordSeq: translated.record.recordSeq,\n\t\t\t\trecordKind: translated.record.kind,\n\t\t\t},\n\t\t},\n\t);\n\temitIssue(ctx, state, issue);\n\temitStatus(\n\t\tctx,\n\t\tstate,\n\t\tissueStatus(\n\t\t\t`${translated.schedule.scheduleId}:conflict:${translated.record.recordSeq}`,\n\t\t\t[issue],\n\t\t\ttranslated.record,\n\t\t\ttranslated.schedule.sourceRefs,\n\t\t),\n\t);\n}\n\nfunction emitSchedule(\n\tctx: { down: (msgs: readonly [\"DATA\", WorkQueueScheduledReadinessFact][]) => void },\n\tstate: WorkQueueScheduledReadinessProjectorState,\n\tschedule: ScheduledReadinessRequested,\n): void {\n\tconst key = `schedule:${schedule.scheduleId}`;\n\tif (state.emittedKeys.has(key)) return;\n\tstate.emittedKeys.add(key);\n\tctx.down([[\"DATA\", { kind: \"readiness-schedule\", schedule }]]);\n}\n\nfunction emitStatus(\n\tctx: { down: (msgs: readonly [\"DATA\", WorkQueueScheduledReadinessFact][]) => void },\n\tstate: WorkQueueScheduledReadinessProjectorState,\n\tstatus: WorkQueueScheduledReadinessStatus,\n): void {\n\tstate.statusById.set(status.statusId, status);\n\tconst key = `status:${status.statusId}:${(status.issueCodes ?? []).join(\",\")}`;\n\tif (state.emittedKeys.has(key)) return;\n\tstate.emittedKeys.add(key);\n\tctx.down([[\"DATA\", { kind: \"status\", status }]]);\n}\n\nfunction emitIssue(\n\tctx: { down: (msgs: readonly [\"DATA\", WorkQueueScheduledReadinessFact][]) => void },\n\tstate: WorkQueueScheduledReadinessProjectorState,\n\tissue: DataIssue,\n): void {\n\tconst key = `${issue.code}:${issue.subjectId ?? \"\"}:${JSON.stringify(issue.details ?? {})}`;\n\tif (state.issueKeys.has(key)) return;\n\tstate.issueKeys.add(key);\n\tctx.down([[\"DATA\", { kind: \"issue\", issue }]]);\n}\n\nfunction emitAudit(\n\tctx: { down: (msgs: readonly [\"DATA\", WorkQueueScheduledReadinessFact][]) => void },\n\tstate: WorkQueueScheduledReadinessProjectorState,\n\tkind: string,\n\topts: {\n\t\treadonly subjectId: string;\n\t\treadonly sourceRefs?: readonly SourceRef[];\n\t\treadonly metadata?: Record<string, unknown>;\n\t},\n): void {\n\tstate.auditSeq += 1;\n\tconst metadata = sanitizeGraphVisibleRecord(opts.metadata);\n\tctx.down([\n\t\t[\n\t\t\t\"DATA\",\n\t\t\t{\n\t\t\t\tkind: \"audit\",\n\t\t\t\taudit: Object.freeze({\n\t\t\t\t\tid: `work-queue-scheduled-readiness-audit-${state.auditSeq}`,\n\t\t\t\t\tkind,\n\t\t\t\t\tsubjectId: opts.subjectId,\n\t\t\t\t\t...(opts.sourceRefs === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: { sourceRefs: canonicalPublicSourceRefs(opts.sourceRefs) }),\n\t\t\t\t\t...(metadata === undefined ? {} : { metadata }),\n\t\t\t\t} satisfies AgentRuntimeAuditRecord),\n\t\t\t},\n\t\t],\n\t]);\n}\n\nfunction buildViews(\n\tstate: WorkQueueScheduledReadinessProjectorState,\n): WorkQueueScheduledReadinessViews {\n\treturn Object.freeze({\n\t\tschedulesById: new Map(state.schedulesById),\n\t\tstatusById: new Map(state.statusById),\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC2CO,IAAM,WAAW;;;ACoHjB,SAAS,SAAS,KAAU,UAAmD;AACrF,SAAO,IAAI,SAAS,QAAQ,KAAK,CAAC;AACnC;AAGO,SAAS,SAAS,KAAU,UAA6C;AAC/E,QAAM,QAAQ,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AAwD,OAAO,IAAI;AAAA,IAC5E,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,SAAS;AAAA,EACV;AACD;AAEA,SAAS,sBACR,OACqD;AACrD,MAAI,CAAC,eAAe,KAAK,KAAK,MAAM,SAAS,8BAA+B,QAAO;AACnF,QAAM,SAAS,MAAM;AACrB,SAAO,eAAe,MAAM,KAAK,OAAO,OAAO,OAAO,YAAY,OAAO,OAAO,SAAS;AAC1F;AAEA,SAAS,eAAe,OAAkD;AACzE,SAAO,OAAO,UAAU,YAAY,UAAU;AAC/C;","names":["emitIssue"]}
@@ -1,16 +1,127 @@
1
1
  import { DataIssue } from '../data/index.cjs';
2
- import { d as Graph } from '../graph-DCEWh4T2.cjs';
3
- import { N as Node } from '../types-CcPIn7sy.cjs';
4
- import { ProcessEffectRequest } from './index.cjs';
5
- import { WorkQueueRecord, WorkQueueCommand } from '../work-queue/index.cjs';
2
+ import { d as Graph } from '../graph-C1C-wb0L.cjs';
3
+ import { N as Node } from '../types-CTN3XoMl.cjs';
4
+ import { c as ProcessEffectRequest } from '../process-types-BB7oRhX3.cjs';
5
+ import { W as WorkQueueCommand, j as WorkQueueDerivedState, a as WorkQueueRecord } from '../types-CV_ohy5T.cjs';
6
+ import { S as SourceRef, a as AgentRuntimeAuditRecord } from '../agent-runtime-types-core-bfl4m0vM.cjs';
7
+ import { S as ScheduledReadinessRequested, a as ScheduledReadinessReady, b as ScheduledReadinessOverdue } from '../scheduled-readiness-CYSw7KDE.cjs';
6
8
  import '../core/index.cjs';
7
9
  import '../messages-CAzUPPJM.cjs';
8
10
  import '../codec-BB7p8fJc.cjs';
9
- import '../describe-DYMw_l1C.cjs';
10
- import '../resilience-Dig3Q7n0.cjs';
11
- import '../agent-runtime-DZTJ3C-p.cjs';
12
- import '../work-item-runtime-qaVgsL0T.cjs';
13
- import '../messaging/index.cjs';
11
+ import '../describe-BumQ-3_0.cjs';
12
+ import '../types-BAw2QVVE.cjs';
13
+
14
+ type WorkQueueScheduledReadinessScheduleKind = "work-admitted" | "work-scheduled" | "retry-scheduled" | "lease-expiration";
15
+ type WorkQueueScheduledReadinessStatusState = "translated" | "issue";
16
+ interface WorkQueueScheduledReadinessStatus {
17
+ readonly kind: "work-queue-scheduled-readiness-status";
18
+ readonly statusId: string;
19
+ readonly queueId?: string;
20
+ readonly workId?: string;
21
+ readonly recordSeq?: number;
22
+ readonly state: WorkQueueScheduledReadinessStatusState;
23
+ readonly scheduleKind?: WorkQueueScheduledReadinessScheduleKind;
24
+ readonly scheduleId?: string;
25
+ readonly readyAtMs?: number;
26
+ readonly deadlineMs?: number;
27
+ readonly sourceRefs?: readonly SourceRef[];
28
+ readonly issueCodes?: readonly string[];
29
+ readonly metadata?: Record<string, unknown>;
30
+ }
31
+ interface WorkQueueScheduledReadinessViews {
32
+ readonly schedulesById: ReadonlyMap<string, ScheduledReadinessRequested>;
33
+ readonly statusById: ReadonlyMap<string, WorkQueueScheduledReadinessStatus>;
34
+ }
35
+ interface WorkQueueScheduledReadinessBundle {
36
+ readonly readinessSchedules: Node<ScheduledReadinessRequested>;
37
+ readonly status: Node<WorkQueueScheduledReadinessStatus>;
38
+ readonly issues: Node<DataIssue>;
39
+ readonly audit: Node<AgentRuntimeAuditRecord>;
40
+ readonly views: Node<WorkQueueScheduledReadinessViews>;
41
+ }
42
+ type WorkQueueReadinessCandidateKind = "claim-eligible" | "lease-expiration-eligible";
43
+ interface WorkQueueReadinessCandidate {
44
+ readonly kind: "work-queue-readiness-candidate";
45
+ readonly candidateId: string;
46
+ readonly candidateKind: WorkQueueReadinessCandidateKind;
47
+ readonly queueId: string;
48
+ readonly workId: string;
49
+ readonly scheduleId: string;
50
+ readonly readyAtMs: number;
51
+ readonly nowMs: number;
52
+ readonly originRecordSeq?: number;
53
+ readonly originRecordKind?: string;
54
+ readonly leaseId?: string;
55
+ readonly attempt?: number;
56
+ readonly workerId?: string;
57
+ readonly leaseExpiresAtMs?: number;
58
+ readonly sourceRefs?: readonly SourceRef[];
59
+ readonly metadata?: Record<string, unknown>;
60
+ }
61
+ type WorkQueueReadinessHandoffStatusState = "candidate" | "ignored-stale" | "ignored-superseded" | "ignored-terminal" | "overdue" | "pending-origin" | "issue";
62
+ interface WorkQueueReadinessHandoffStatus {
63
+ readonly kind: "work-queue-readiness-handoff-status";
64
+ readonly statusId: string;
65
+ readonly state: WorkQueueReadinessHandoffStatusState;
66
+ readonly queueId?: string;
67
+ readonly workId?: string;
68
+ readonly scheduleId?: string;
69
+ readonly candidateId?: string;
70
+ readonly candidateKind?: WorkQueueReadinessCandidateKind;
71
+ readonly readyAtMs?: number;
72
+ readonly nowMs?: number;
73
+ readonly currentState?: WorkQueueDerivedState;
74
+ readonly sourceRefs?: readonly SourceRef[];
75
+ readonly issueCodes?: readonly string[];
76
+ readonly metadata?: Record<string, unknown>;
77
+ }
78
+ interface WorkQueueReadinessHandoffViews {
79
+ readonly candidatesById: ReadonlyMap<string, WorkQueueReadinessCandidate>;
80
+ readonly statusById: ReadonlyMap<string, WorkQueueReadinessHandoffStatus>;
81
+ }
82
+ interface WorkQueueReadinessHandoffBundle {
83
+ readonly candidates: Node<WorkQueueReadinessCandidate>;
84
+ readonly status: Node<WorkQueueReadinessHandoffStatus>;
85
+ readonly issues: Node<DataIssue>;
86
+ readonly audit: Node<AgentRuntimeAuditRecord>;
87
+ readonly views: Node<WorkQueueReadinessHandoffViews>;
88
+ }
89
+ interface WorkQueueLeaseExpirationCommandBundle<T = unknown> {
90
+ readonly commands: Node<WorkQueueCommand<T>>;
91
+ readonly status: Node<WorkQueueReadinessHandoffStatus>;
92
+ readonly views: Node<WorkQueueReadinessHandoffViews>;
93
+ }
94
+ /**
95
+ * Translate workQueue-local delayed eligibility records into D432 shared readiness schedules.
96
+ *
97
+ * The projector is intentionally visibility-only: it never claims work, expires leases, cancels,
98
+ * completes, fails, mutates queue records, or starts timers. D433 consumption/materialization stays
99
+ * owned by later workQueue domain projectors.
100
+ */
101
+ declare function workQueueScheduledReadinessProjector<T = unknown>(graph: Graph, opts: {
102
+ readonly name?: string;
103
+ readonly records: Node<WorkQueueRecord<T>>;
104
+ }): WorkQueueScheduledReadinessBundle;
105
+ /**
106
+ * Consume D433 shared readiness through workQueue-owned handoff material.
107
+ *
108
+ * Ready facts only produce queue-domain candidates/status. They do not claim work, expire leases,
109
+ * cancel, complete, fail, or append workQueue records. Lease expiration candidates can be lowered
110
+ * separately into the existing mutation-bearing expire-leases command path.
111
+ */
112
+ declare function workQueueReadinessHandoffProjector<T = unknown>(graph: Graph, opts: {
113
+ readonly name?: string;
114
+ readonly records: Node<WorkQueueRecord<T>>;
115
+ readonly ready: Node<ScheduledReadinessReady>;
116
+ readonly overdue?: Node<ScheduledReadinessOverdue>;
117
+ }): WorkQueueReadinessHandoffBundle;
118
+ /**
119
+ * Lower only lease-expiration readiness candidates into existing workQueue expire-leases commands.
120
+ */
121
+ declare function workQueueLeaseExpirationCommandProjector<T = unknown>(graph: Graph, opts: {
122
+ readonly name?: string;
123
+ readonly candidates: Node<WorkQueueReadinessCandidate>;
124
+ }): WorkQueueLeaseExpirationCommandBundle<T>;
14
125
 
15
126
  /**
16
127
  * Optional orchestration-over-workQueue recipe (D349/D353).
@@ -82,4 +193,4 @@ declare function processEffectSubmitCommand<TEffect>(effect: ProcessEffectReques
82
193
  readonly metadata?: Record<string, unknown>;
83
194
  }): WorkQueueCommand<OrchestrationQueuedEffectPayload<TEffect>>;
84
195
 
85
- export { type OrchestrationQueueAuditRecord, type OrchestrationQueueEvidence, type OrchestrationQueueStatus, type OrchestrationQueuedEffectPayload, type OrchestrationWorkQueueRecipeBundle, type OrchestrationWorkQueueRecipeOptions, orchestrationWorkQueueRecipe, processEffectSubmitCommand };
196
+ export { type OrchestrationQueueAuditRecord, type OrchestrationQueueEvidence, type OrchestrationQueueStatus, type OrchestrationQueuedEffectPayload, type OrchestrationWorkQueueRecipeBundle, type OrchestrationWorkQueueRecipeOptions, type WorkQueueLeaseExpirationCommandBundle, type WorkQueueReadinessCandidate, type WorkQueueReadinessCandidateKind, type WorkQueueReadinessHandoffBundle, type WorkQueueReadinessHandoffStatus, type WorkQueueReadinessHandoffStatusState, type WorkQueueReadinessHandoffViews, type WorkQueueScheduledReadinessBundle, type WorkQueueScheduledReadinessScheduleKind, type WorkQueueScheduledReadinessStatus, type WorkQueueScheduledReadinessStatusState, type WorkQueueScheduledReadinessViews, orchestrationWorkQueueRecipe, processEffectSubmitCommand, workQueueLeaseExpirationCommandProjector, workQueueReadinessHandoffProjector, workQueueScheduledReadinessProjector };