@graphrefly/ts 0.0.0 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +135 -0
- package/dist/actions-types-CSC3NMDl.d.ts +657 -0
- package/dist/actions-types-wl9Mgkmr.d.cts +657 -0
- package/dist/adapters/index.cjs +5219 -2974
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +204 -192
- package/dist/adapters/index.d.ts +204 -192
- package/dist/adapters/index.js +3685 -1833
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/nestjs/microservices.cjs +841 -0
- package/dist/adapters/nestjs/microservices.cjs.map +1 -0
- package/dist/adapters/nestjs/microservices.d.cts +45 -0
- package/dist/adapters/nestjs/microservices.d.ts +45 -0
- package/dist/adapters/nestjs/microservices.js +206 -0
- package/dist/adapters/nestjs/microservices.js.map +1 -0
- package/dist/adapters/nestjs/native.cjs +1391 -0
- package/dist/adapters/nestjs/native.cjs.map +1 -0
- package/dist/adapters/nestjs/native.d.cts +111 -0
- package/dist/adapters/nestjs/native.d.ts +111 -0
- package/dist/adapters/nestjs/native.js +577 -0
- package/dist/adapters/nestjs/native.js.map +1 -0
- package/dist/adapters/nestjs/websockets.cjs +924 -0
- package/dist/adapters/nestjs/websockets.cjs.map +1 -0
- package/dist/adapters/nestjs/websockets.d.cts +47 -0
- package/dist/adapters/nestjs/websockets.d.ts +47 -0
- package/dist/adapters/nestjs/websockets.js +286 -0
- package/dist/adapters/nestjs/websockets.js.map +1 -0
- package/dist/adapters/nestjs.cjs +1085 -0
- package/dist/adapters/nestjs.cjs.map +1 -0
- package/dist/adapters/nestjs.d.cts +385 -0
- package/dist/adapters/nestjs.d.ts +385 -0
- package/dist/adapters/nestjs.js +112 -0
- package/dist/adapters/nestjs.js.map +1 -0
- package/dist/adapters/observe-storage.d.cts +4 -4
- package/dist/adapters/observe-storage.d.ts +4 -4
- package/dist/adapters/observe-storage.js +5 -4
- package/dist/adapters/observe-storage.js.map +1 -1
- package/dist/adapters/react.cjs +166 -0
- package/dist/adapters/react.cjs.map +1 -0
- package/dist/adapters/react.d.cts +31 -0
- package/dist/adapters/react.d.ts +31 -0
- package/dist/adapters/react.js +51 -0
- package/dist/adapters/react.js.map +1 -0
- package/dist/adapters/solid.cjs +157 -0
- package/dist/adapters/solid.cjs.map +1 -0
- package/dist/adapters/solid.d.cts +26 -0
- package/dist/adapters/solid.d.ts +26 -0
- package/dist/adapters/solid.js +48 -0
- package/dist/adapters/solid.js.map +1 -0
- package/dist/adapters/svelte.cjs +148 -0
- package/dist/adapters/svelte.cjs.map +1 -0
- package/dist/adapters/svelte.d.cts +31 -0
- package/dist/adapters/svelte.d.ts +31 -0
- package/dist/adapters/svelte.js +46 -0
- package/dist/adapters/svelte.js.map +1 -0
- package/dist/adapters/vue.cjs +155 -0
- package/dist/adapters/vue.cjs.map +1 -0
- package/dist/adapters/vue.d.cts +26 -0
- package/dist/adapters/vue.d.ts +26 -0
- package/dist/adapters/vue.js +46 -0
- package/dist/adapters/vue.js.map +1 -0
- package/dist/agent-runtime-types-core-CaXfKNtY.d.cts +406 -0
- package/dist/agent-runtime-types-core-hU299uIC.d.ts +406 -0
- package/dist/agent-runtime-types-tool-BEpSINol.d.ts +695 -0
- package/dist/agent-runtime-types-tool-DninPEzk.d.cts +695 -0
- package/dist/agentic-memory-retention-BmGX368S.d.ts +14 -0
- package/dist/agentic-memory-retention-Ih1qhX9Z.d.cts +14 -0
- package/dist/agentic-memory-types-CVSUS6XR.d.ts +473 -0
- package/dist/agentic-memory-types-FnnYlVUs.d.cts +473 -0
- package/dist/capability-admission-BW2CziT6.d.ts +102 -0
- package/dist/capability-admission-lwSecxXs.d.cts +102 -0
- package/dist/chunk-2KUAG2GZ.js +9693 -0
- package/dist/chunk-2KUAG2GZ.js.map +1 -0
- package/dist/chunk-2NJP6GO4.js +1320 -0
- package/dist/chunk-2NJP6GO4.js.map +1 -0
- package/dist/{chunk-GDL26N2T.js → chunk-3KN7NJDR.js} +2 -2
- package/dist/{chunk-COHO25CZ.js → chunk-4NWSNI4K.js} +2232 -1672
- package/dist/chunk-4NWSNI4K.js.map +1 -0
- package/dist/{chunk-Z2ANQ6JW.js → chunk-4Q77MMJY.js} +2 -2
- package/dist/chunk-6E76H4OU.js +132 -0
- package/dist/chunk-6E76H4OU.js.map +1 -0
- package/dist/chunk-7GOTIIQ7.js +819 -0
- package/dist/chunk-7GOTIIQ7.js.map +1 -0
- package/dist/{chunk-D6BG7U6A.js → chunk-7HZRJMN6.js} +3 -3
- package/dist/{chunk-SCRFRCGR.js → chunk-BSQGE5PS.js} +1 -1
- package/dist/{chunk-PKVBHGBM.js → chunk-CJIFGJQG.js} +7 -7
- package/dist/{chunk-G4M3NHRJ.js → chunk-CX6B6PO2.js} +93 -10
- package/dist/chunk-CX6B6PO2.js.map +1 -0
- package/dist/chunk-DGUM43GV.js +11 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/dist/{chunk-JIMUDQN3.js → chunk-E4QCH32M.js} +449 -447
- package/dist/chunk-E4QCH32M.js.map +1 -0
- package/dist/{chunk-RIIOUTGM.js → chunk-ECURQ3HD.js} +19 -129
- package/dist/chunk-ECURQ3HD.js.map +1 -0
- package/dist/{chunk-2ILL7HQI.js → chunk-EOKT4QFF.js} +134 -128
- package/dist/chunk-EOKT4QFF.js.map +1 -0
- package/dist/{chunk-K3FXTC3I.js → chunk-HJACH5PU.js} +3 -3
- package/dist/{chunk-GTPCOEOZ.js → chunk-IDMLXLLG.js} +3 -3
- package/dist/{chunk-DKP56CSW.js → chunk-JKAYLDQV.js} +2 -2
- package/dist/{chunk-4VLAQHZI.js → chunk-K7FB3JTD.js} +17 -1
- package/dist/chunk-K7FB3JTD.js.map +1 -0
- package/dist/chunk-L6LDXRWE.js +219 -0
- package/dist/chunk-L6LDXRWE.js.map +1 -0
- package/dist/chunk-M7J6Z4IJ.js +1930 -0
- package/dist/chunk-M7J6Z4IJ.js.map +1 -0
- package/dist/chunk-MQEQMS7B.js +1009 -0
- package/dist/chunk-MQEQMS7B.js.map +1 -0
- package/dist/chunk-MTELVIYR.js +1421 -0
- package/dist/chunk-MTELVIYR.js.map +1 -0
- package/dist/chunk-PVC7WDKI.js +885 -0
- package/dist/chunk-PVC7WDKI.js.map +1 -0
- package/dist/chunk-RAHNUYA5.js +368 -0
- package/dist/chunk-RAHNUYA5.js.map +1 -0
- package/dist/{chunk-DK554R7P.js → chunk-S6HXABGL.js} +2 -1
- package/dist/chunk-S6HXABGL.js.map +1 -0
- package/dist/{chunk-I3IHOHCJ.js → chunk-SHZDP2MQ.js} +1181 -1001
- package/dist/chunk-SHZDP2MQ.js.map +1 -0
- package/dist/{chunk-Y3ZLRGHC.js → chunk-SIDJO2T4.js} +16 -16
- package/dist/chunk-STXRMPW4.js +4131 -0
- package/dist/chunk-STXRMPW4.js.map +1 -0
- package/dist/{chunk-JR4IKCR2.js → chunk-TPND5MJS.js} +5 -5
- package/dist/chunk-TQPCAIQI.js +612 -0
- package/dist/chunk-TQPCAIQI.js.map +1 -0
- package/dist/chunk-UT3MHJCW.js +49 -0
- package/dist/chunk-UT3MHJCW.js.map +1 -0
- package/dist/{chunk-TEW47IVR.js → chunk-VPEFSDME.js} +2 -2
- package/dist/{chunk-SWTLEQL6.js → chunk-WQIA3GFB.js} +2 -2
- package/dist/chunk-WQIA3GFB.js.map +1 -0
- package/dist/{chunk-DJC4CHLQ.js → chunk-YDWBXXQZ.js} +5 -5
- package/dist/{chunk-6PHB5CJS.js → chunk-ZLFRB6FI.js} +2 -2
- package/dist/composition/index.cjs +1256 -1059
- package/dist/composition/index.cjs.map +1 -1
- package/dist/composition/index.d.cts +4 -4
- package/dist/composition/index.d.ts +4 -4
- package/dist/composition/index.js +7 -6
- package/dist/core/index.cjs +1218 -1021
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +5 -4
- package/dist/cqrs/index.cjs.map +1 -1
- package/dist/cqrs/index.d.cts +4 -4
- package/dist/cqrs/index.d.ts +4 -4
- package/dist/cqrs/index.js +3 -2
- package/dist/cqrs/index.js.map +1 -1
- package/dist/cqrs/messaging.cjs +312 -0
- package/dist/cqrs/messaging.cjs.map +1 -0
- package/dist/cqrs/messaging.d.cts +57 -0
- package/dist/cqrs/messaging.d.ts +57 -0
- package/dist/cqrs/messaging.js +274 -0
- package/dist/cqrs/messaging.js.map +1 -0
- package/dist/cqrs/work-queue.cjs +329 -0
- package/dist/cqrs/work-queue.cjs.map +1 -0
- package/dist/cqrs/work-queue.d.cts +90 -0
- package/dist/cqrs/work-queue.d.ts +90 -0
- package/dist/cqrs/work-queue.js +292 -0
- package/dist/cqrs/work-queue.js.map +1 -0
- package/dist/data/index.cjs +19 -0
- package/dist/data/index.cjs.map +1 -0
- package/dist/data/index.d.cts +36 -0
- package/dist/data/index.d.ts +36 -0
- package/dist/data/index.js +1 -0
- package/dist/data/index.js.map +1 -0
- package/dist/data-structures/index.cjs +1252 -1052
- package/dist/data-structures/index.cjs.map +1 -1
- package/dist/data-structures/index.d.cts +9 -8
- package/dist/data-structures/index.d.ts +9 -8
- package/dist/data-structures/index.js +9 -7
- package/dist/{describe-BZb7AS2y.d.ts → describe-B_A5fbXH.d.ts} +1 -1
- package/dist/{describe-Ciu8SUnN.d.cts → describe-CQRrkv-Q.d.cts} +1 -1
- package/dist/executors/tool-provider-adapters.cjs +3091 -0
- package/dist/executors/tool-provider-adapters.cjs.map +1 -0
- package/dist/executors/tool-provider-adapters.d.cts +174 -0
- package/dist/executors/tool-provider-adapters.d.ts +174 -0
- package/dist/executors/tool-provider-adapters.js +1336 -0
- package/dist/executors/tool-provider-adapters.js.map +1 -0
- package/dist/executors/tool-provider-runtime.cjs +5178 -0
- package/dist/executors/tool-provider-runtime.cjs.map +1 -0
- package/dist/executors/tool-provider-runtime.d.cts +17 -0
- package/dist/executors/tool-provider-runtime.d.ts +17 -0
- package/dist/executors/tool-provider-runtime.js +15 -0
- package/dist/executors/tool-provider-runtime.js.map +1 -0
- package/dist/executors/tool-provider.cjs +6392 -0
- package/dist/executors/tool-provider.cjs.map +1 -0
- package/dist/executors/tool-provider.d.cts +60 -0
- package/dist/executors/tool-provider.d.ts +60 -0
- package/dist/executors/tool-provider.js +89 -0
- package/dist/executors/tool-provider.js.map +1 -0
- package/dist/executors/work-queue.cjs +342 -0
- package/dist/executors/work-queue.cjs.map +1 -0
- package/dist/executors/work-queue.d.cts +90 -0
- package/dist/executors/work-queue.d.ts +90 -0
- package/dist/executors/work-queue.js +306 -0
- package/dist/executors/work-queue.js.map +1 -0
- package/dist/graph/index.cjs +1536 -1324
- package/dist/graph/index.cjs.map +1 -1
- package/dist/graph/index.d.cts +10 -9
- package/dist/graph/index.d.ts +10 -9
- package/dist/graph/index.js +22 -20
- package/dist/{graph-s23RbbFO.d.cts → graph-CWK3HLPB.d.cts} +134 -132
- package/dist/{graph-DfdF9zy4.d.ts → graph-ho5sotHP.d.ts} +134 -132
- package/dist/{index-SnzZu3x7.d.ts → index-CQWcE0Dw.d.ts} +18 -4
- package/dist/{index-CAEmLCYF.d.cts → index-DHA1i67c.d.cts} +18 -4
- package/dist/index.cjs +3331 -3020
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -10
- package/dist/index.d.ts +14 -10
- package/dist/index.js +114 -108
- package/dist/inspection/boundary.cjs +98 -0
- package/dist/inspection/boundary.cjs.map +1 -0
- package/dist/inspection/boundary.d.cts +61 -0
- package/dist/inspection/boundary.d.ts +61 -0
- package/dist/inspection/boundary.js +75 -0
- package/dist/inspection/boundary.js.map +1 -0
- package/dist/measurements-C0mAvWU1.d.cts +164 -0
- package/dist/measurements-OMpCeBwh.d.ts +164 -0
- package/dist/{messages-BZqrGGm1.d.ts → messages-CAzUPPJM.d.cts} +10 -5
- package/dist/{messages-BZqrGGm1.d.cts → messages-CAzUPPJM.d.ts} +10 -5
- package/dist/messaging/index.cjs +756 -619
- package/dist/messaging/index.cjs.map +1 -1
- package/dist/messaging/index.d.cts +17 -226
- package/dist/messaging/index.d.ts +17 -226
- package/dist/messaging/index.js +19 -749
- package/dist/messaging/index.js.map +1 -1
- package/dist/operators/index.cjs +1256 -1059
- package/dist/operators/index.cjs.map +1 -1
- package/dist/operators/index.d.cts +6 -6
- package/dist/operators/index.d.ts +6 -6
- package/dist/operators/index.js +9 -8
- package/dist/orchestration/index.cjs +8664 -2617
- package/dist/orchestration/index.cjs.map +1 -1
- package/dist/orchestration/index.d.cts +171 -221
- package/dist/orchestration/index.d.ts +171 -221
- package/dist/orchestration/index.js +74 -982
- package/dist/orchestration/index.js.map +1 -1
- package/dist/orchestration/messaging.cjs +314 -0
- package/dist/orchestration/messaging.cjs.map +1 -0
- package/dist/orchestration/messaging.d.cts +56 -0
- package/dist/orchestration/messaging.d.ts +56 -0
- package/dist/orchestration/messaging.js +276 -0
- package/dist/orchestration/messaging.js.map +1 -0
- package/dist/orchestration/work-queue.cjs +1500 -0
- package/dist/orchestration/work-queue.cjs.map +1 -0
- package/dist/orchestration/work-queue.d.cts +196 -0
- package/dist/orchestration/work-queue.d.ts +196 -0
- package/dist/orchestration/work-queue.js +1289 -0
- package/dist/orchestration/work-queue.js.map +1 -0
- package/dist/patterns/event-flow.cjs +433 -0
- package/dist/patterns/event-flow.cjs.map +1 -0
- package/dist/patterns/event-flow.d.cts +115 -0
- package/dist/patterns/event-flow.d.ts +115 -0
- package/dist/patterns/event-flow.js +14 -0
- package/dist/patterns/event-flow.js.map +1 -0
- package/dist/patterns/index.cjs +748 -355
- package/dist/patterns/index.cjs.map +1 -1
- package/dist/patterns/index.d.cts +9 -5
- package/dist/patterns/index.d.ts +9 -5
- package/dist/patterns/index.js +13 -4
- package/dist/process-types-C9uMYz3i.d.ts +200 -0
- package/dist/process-types-h3uRlzDc.d.cts +200 -0
- package/dist/{reactive-collection-BxBqtIOE.d.cts → reactive-collection-B9R0Bl1P.d.cts} +11 -41
- package/dist/{reactive-collection-Cb1II1Fi.d.ts → reactive-collection-BXFrH0U2.d.ts} +11 -41
- package/dist/{reactive-collection-storage-D-KmjE0J.d.cts → reactive-collection-storage-BLGv8Xp8.d.cts} +5 -5
- package/dist/{reactive-collection-storage-BNiEc-Gd.d.ts → reactive-collection-storage-a4zD3665.d.ts} +5 -5
- package/dist/{reactive-map-BcB4KsQR.d.ts → reactive-map-C_8sOfdS.d.cts} +7 -6
- package/dist/{reactive-map-D-g3dv8I.d.cts → reactive-map-jle5dnok.d.ts} +7 -6
- package/dist/render/index.d.cts +3 -3
- package/dist/render/index.d.ts +3 -3
- package/dist/render/index.js +1 -0
- package/dist/scheduled-readiness-5rwQlyjV.d.ts +91 -0
- package/dist/scheduled-readiness-DpRY8jI0.d.cts +91 -0
- package/dist/semantic-memory-graph-C2ZUwIlq.d.ts +30 -0
- package/dist/semantic-memory-graph-DlZBD_Eu.d.cts +30 -0
- package/dist/{semantic-memory-graph-BYoIlP35.d.cts → semantic-memory-graph-types-BvzdqmkY.d.cts} +2 -28
- package/dist/{semantic-memory-graph-CxyXLms3.d.ts → semantic-memory-graph-types-Ci-OtahO.d.ts} +2 -28
- package/dist/solutions/index.cjs +6788 -2128
- package/dist/solutions/index.cjs.map +1 -1
- package/dist/solutions/index.d.cts +15 -519
- package/dist/solutions/index.d.ts +15 -519
- package/dist/solutions/index.js +91 -7
- package/dist/solutions/reactive-layout/browser/index.cjs +457 -0
- package/dist/solutions/reactive-layout/browser/index.cjs.map +1 -0
- package/dist/solutions/reactive-layout/browser/index.d.cts +44 -0
- package/dist/solutions/reactive-layout/browser/index.d.ts +44 -0
- package/dist/solutions/reactive-layout/browser/index.js +69 -0
- package/dist/solutions/reactive-layout/browser/index.js.map +1 -0
- package/dist/solutions/reactive-layout/index.cjs +4494 -0
- package/dist/solutions/reactive-layout/index.cjs.map +1 -0
- package/dist/solutions/reactive-layout/index.d.cts +37 -0
- package/dist/solutions/reactive-layout/index.d.ts +37 -0
- package/dist/solutions/reactive-layout/index.js +146 -0
- package/dist/solutions/reactive-layout/index.js.map +1 -0
- package/dist/solutions/reactive-layout/node-canvas/index.cjs +555 -0
- package/dist/solutions/reactive-layout/node-canvas/index.cjs.map +1 -0
- package/dist/solutions/reactive-layout/node-canvas/index.d.cts +54 -0
- package/dist/solutions/reactive-layout/node-canvas/index.d.ts +54 -0
- package/dist/solutions/reactive-layout/node-canvas/index.js +131 -0
- package/dist/solutions/reactive-layout/node-canvas/index.js.map +1 -0
- package/dist/solutions/reactive-layout/react-native/index.cjs +504 -0
- package/dist/solutions/reactive-layout/react-native/index.cjs.map +1 -0
- package/dist/solutions/reactive-layout/react-native/index.d.cts +51 -0
- package/dist/solutions/reactive-layout/react-native/index.d.ts +51 -0
- package/dist/solutions/reactive-layout/react-native/index.js +77 -0
- package/dist/solutions/reactive-layout/react-native/index.js.map +1 -0
- package/dist/solutions/reactive-layout/skia/index.cjs +557 -0
- package/dist/solutions/reactive-layout/skia/index.cjs.map +1 -0
- package/dist/solutions/reactive-layout/skia/index.d.cts +64 -0
- package/dist/solutions/reactive-layout/skia/index.d.ts +64 -0
- package/dist/solutions/reactive-layout/skia/index.js +70 -0
- package/dist/solutions/reactive-layout/skia/index.js.map +1 -0
- package/dist/solutions/work-item/actions.cjs +2345 -0
- package/dist/solutions/work-item/actions.cjs.map +1 -0
- package/dist/solutions/work-item/actions.d.cts +40 -0
- package/dist/solutions/work-item/actions.d.ts +40 -0
- package/dist/solutions/work-item/actions.js +2078 -0
- package/dist/solutions/work-item/actions.js.map +1 -0
- package/dist/solutions/work-item/scheduling.cjs +9797 -0
- package/dist/solutions/work-item/scheduling.cjs.map +1 -0
- package/dist/solutions/work-item/scheduling.d.cts +1868 -0
- package/dist/solutions/work-item/scheduling.d.ts +1868 -0
- package/dist/solutions/work-item/scheduling.js +146 -0
- package/dist/solutions/work-item/scheduling.js.map +1 -0
- package/dist/solutions/work-item/work-queue.cjs +306 -0
- package/dist/solutions/work-item/work-queue.cjs.map +1 -0
- package/dist/solutions/work-item/work-queue.d.cts +71 -0
- package/dist/solutions/work-item/work-queue.d.ts +71 -0
- package/dist/solutions/work-item/work-queue.js +270 -0
- package/dist/solutions/work-item/work-queue.js.map +1 -0
- package/dist/sources/browser.cjs +1399 -1052
- package/dist/sources/browser.cjs.map +1 -1
- package/dist/sources/browser.d.cts +33 -6
- package/dist/sources/browser.d.ts +33 -6
- package/dist/sources/browser.js +73 -6
- package/dist/sources/browser.js.map +1 -1
- package/dist/sources/index.cjs +1345 -1065
- package/dist/sources/index.cjs.map +1 -1
- package/dist/sources/index.d.cts +5 -5
- package/dist/sources/index.d.ts +5 -5
- package/dist/sources/index.js +7 -6
- package/dist/sources/node.cjs.map +1 -1
- package/dist/sources/node.d.cts +4 -4
- package/dist/sources/node.d.ts +4 -4
- package/dist/sources/node.js +2 -1
- package/dist/sources/node.js.map +1 -1
- package/dist/storage/browser.cjs +16 -0
- package/dist/storage/browser.cjs.map +1 -1
- package/dist/storage/browser.js +4 -3
- package/dist/storage/browser.js.map +1 -1
- package/dist/storage/index.cjs +16 -0
- package/dist/storage/index.cjs.map +1 -1
- package/dist/storage/index.d.cts +6 -5
- package/dist/storage/index.d.ts +6 -5
- package/dist/storage/index.js +10 -9
- package/dist/storage/node.cjs +16 -0
- package/dist/storage/node.cjs.map +1 -1
- package/dist/storage/node.js +4 -3
- package/dist/storage/node.js.map +1 -1
- package/dist/store-BmtEs9mG.d.ts +123 -0
- package/dist/store-PAAsYvML.d.cts +123 -0
- package/dist/testing/index.cjs +1 -0
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.d.cts +1 -1
- package/dist/testing/index.d.ts +1 -1
- package/dist/testing/index.js +3 -2
- package/dist/types-BRNKoFHj.d.ts +357 -0
- package/dist/{types-h12mNYbq.d.ts → types-BS6CyR-x.d.cts} +49 -130
- package/dist/types-BWK2ay3e.d.cts +457 -0
- package/dist/types-BXKSAoE1.d.cts +357 -0
- package/dist/types-BaPpZItj.d.ts +457 -0
- package/dist/types-BhveCMg5.d.cts +274 -0
- package/dist/{types-bNMSWKqF.d.cts → types-C9NOgNJw.d.ts} +49 -130
- package/dist/types-CTsQ8Ww4.d.ts +274 -0
- package/dist/types-DL_05n2M.d.ts +34 -0
- package/dist/types-XDoqxYO9.d.cts +34 -0
- package/dist/work-item-runtime-types-BqtWnSCS.d.ts +138 -0
- package/dist/work-item-runtime-types-CHO03AKh.d.cts +138 -0
- package/dist/work-queue/index.cjs +1136 -0
- package/dist/work-queue/index.cjs.map +1 -0
- package/dist/work-queue/index.d.cts +21 -0
- package/dist/work-queue/index.d.ts +21 -0
- package/dist/work-queue/index.js +1082 -0
- package/dist/work-queue/index.js.map +1 -0
- package/package.json +603 -249
- package/dist/chunk-2ILL7HQI.js.map +0 -1
- package/dist/chunk-4VLAQHZI.js.map +0 -1
- package/dist/chunk-COHO25CZ.js.map +0 -1
- package/dist/chunk-DK554R7P.js.map +0 -1
- package/dist/chunk-G4M3NHRJ.js.map +0 -1
- package/dist/chunk-I3IHOHCJ.js.map +0 -1
- package/dist/chunk-JIMUDQN3.js.map +0 -1
- package/dist/chunk-RIIOUTGM.js.map +0 -1
- package/dist/chunk-SWTLEQL6.js.map +0 -1
- /package/dist/{chunk-GDL26N2T.js.map → chunk-3KN7NJDR.js.map} +0 -0
- /package/dist/{chunk-Z2ANQ6JW.js.map → chunk-4Q77MMJY.js.map} +0 -0
- /package/dist/{chunk-D6BG7U6A.js.map → chunk-7HZRJMN6.js.map} +0 -0
- /package/dist/{chunk-SCRFRCGR.js.map → chunk-BSQGE5PS.js.map} +0 -0
- /package/dist/{chunk-PKVBHGBM.js.map → chunk-CJIFGJQG.js.map} +0 -0
- /package/dist/{chunk-K3FXTC3I.js.map → chunk-HJACH5PU.js.map} +0 -0
- /package/dist/{chunk-GTPCOEOZ.js.map → chunk-IDMLXLLG.js.map} +0 -0
- /package/dist/{chunk-DKP56CSW.js.map → chunk-JKAYLDQV.js.map} +0 -0
- /package/dist/{chunk-Y3ZLRGHC.js.map → chunk-SIDJO2T4.js.map} +0 -0
- /package/dist/{chunk-JR4IKCR2.js.map → chunk-TPND5MJS.js.map} +0 -0
- /package/dist/{chunk-TEW47IVR.js.map → chunk-VPEFSDME.js.map} +0 -0
- /package/dist/{chunk-DJC4CHLQ.js.map → chunk-YDWBXXQZ.js.map} +0 -0
- /package/dist/{chunk-6PHB5CJS.js.map → chunk-ZLFRB6FI.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/patterns/index.ts","../../src/patterns/inspection.ts","../../src/patterns/semantic-memory.ts","../../src/protocol/messages.ts","../../src/ctx/types.ts","../../src/patterns/semantic-memory-graph.ts"],"sourcesContent":["/**\n * Horizontal reusable graph patterns.\n *\n * Former preset material lands here only when it is not a vertical solution\n * and has been re-derived onto clean-slate APIs.\n */\n\nexport {\n\ttype ProfileSummary,\n\ttype ProfileSummaryNode,\n\tprofileSummary,\n} from \"./inspection.js\";\nexport {\n\ttype AdmissionFilter,\n\ttype AdmissionScore3DOptions,\n\ttype AdmissionScoredOptions,\n\ttype AdmissionScores,\n\ttype AdmissionThresholds,\n\tadmissionFilter3D,\n\tadmissionScored,\n\ttype CollectionEntry,\n\ttype CollectionScoreFn,\n\tcosineSimilarity,\n\ttype DecayPolicy,\n\ttype FactId,\n\ttype FactStore,\n\tfilterMemoryFragments,\n\tisMemoryFragment,\n\ttype KnowledgeAssertion,\n\ttype KnowledgeAssertionObject,\n\ttype KnowledgeAssertionStrictJsonValue,\n\ttype KnowledgeAssertionSubject,\n\ttype MemoryAnswer,\n\ttype MemoryFragment,\n\ttype MemoryFragmentValidation,\n\ttype MemoryQuery,\n\tmemoryFragmentMatchesQuery,\n\tmemoryFragmentValidAt,\n\ttype OutcomeSignal,\n\ttype RankedCollectionEntry,\n\ttype RetrievalEntry,\n\ttype RetrievalQuery,\n\ttype RetrievalTrace,\n\ttype ScoringPolicy,\n\ttype ShardByTenantConfig,\n\ttype ShardByTenantOptions,\n\ttype ShardKey,\n\ttype StoreReadHandle,\n\tshardByTenant,\n\ttype VectorSearchResult,\n\tvalidateMemoryFragment,\n} from \"./semantic-memory.js\";\nexport {\n\ttype KnowledgeGraphCursor,\n\ttype KnowledgeGraphEntity,\n\ttype KnowledgeGraphError,\n\ttype KnowledgeGraphErrorCode,\n\ttype KnowledgeGraphIndex,\n\ttype KnowledgeGraphPolicy,\n\ttype KnowledgeGraphReducerBundle,\n\ttype KnowledgeGraphReducerBundleOptions,\n\ttype KnowledgeGraphRelation,\n\ttype KnowledgeGraphSnapshot,\n\ttype KnowledgeGraphStatus,\n\ttype KnowledgeGraphStatusState,\n\ttype KnowledgeGraphTopic,\n\tknowledgeGraphReducerBundle,\n\ttype MemoryRetrievalBundle,\n\ttype MemoryRetrievalBundleOptions,\n\ttype MemoryRetrievalCursor,\n\ttype MemoryRetrievalError,\n\ttype MemoryRetrievalErrorCode,\n\ttype MemoryRetrievalFact,\n\ttype MemoryRetrievalIndex,\n\ttype MemoryRetrievalQuery,\n\ttype MemoryRetrievalSnapshot,\n\ttype MemoryRetrievalStatus,\n\ttype MemoryRetrievalStatusState,\n\tmemoryRetrievalBundle,\n} from \"./semantic-memory-graph.js\";\n","/**\n * Horizontal inspection patterns re-derived from old presets (B62 / D125).\n *\n * These helpers compose the clean-slate graph inspection egresses. They do not\n * add graph nodes, hidden subscriptions, policy gates, or storage ownership.\n */\n\nimport type { Graph } from \"../graph/graph.js\";\nimport type { NodeProfile } from \"../graph/inspect.js\";\n\nexport interface ProfileSummaryNode {\n\tpath: string;\n\tinvokes: number;\n\ttotalDurationNs: number;\n\tlastDurationNs: number;\n\tstatus: NodeProfile[\"status\"];\n}\n\nexport interface ProfileSummary {\n\t/** Number of nodes in describe(), including nodes with zero invokes. */\n\tnodeCount: number;\n\ttotalInvokes: number;\n\tbyStatus: Partial<Record<NodeProfile[\"status\"], number>>;\n\t/** Nodes sorted by invokes desc, then path asc. */\n\thotNodes: ProfileSummaryNode[];\n}\n\n/**\n * Summarize an opt-in Graph.profile() snapshot while keeping describe() as the\n * source of node cardinality. No counters are stored on nodes (R-profile).\n */\nexport function profileSummary(graph: Graph, opts: { limit?: number } = {}): ProfileSummary {\n\tconst profile = graph.profile();\n\tconst described = graph.describe();\n\tconst nodeIds = new Set(described.nodes.map((node) => node.id));\n\tfor (const id of Object.keys(profile.nodes)) nodeIds.add(id);\n\n\tconst byStatus: Partial<Record<NodeProfile[\"status\"], number>> = {};\n\tconst hotNodes: ProfileSummaryNode[] = [];\n\tfor (const path of [...nodeIds].sort()) {\n\t\tconst nodeProfile = profile.nodes[path];\n\t\tif (nodeProfile === undefined) continue;\n\t\tbyStatus[nodeProfile.status] = (byStatus[nodeProfile.status] ?? 0) + 1;\n\t\thotNodes.push({\n\t\t\tpath,\n\t\t\tinvokes: nodeProfile.invokes,\n\t\t\ttotalDurationNs: nodeProfile.totalDurationNs,\n\t\t\tlastDurationNs: nodeProfile.lastDurationNs,\n\t\t\tstatus: nodeProfile.status,\n\t\t});\n\t}\n\thotNodes.sort((a, b) => b.invokes - a.invokes || a.path.localeCompare(b.path));\n\treturn {\n\t\tnodeCount: nodeIds.size,\n\t\ttotalInvokes: profile.totalInvokes,\n\t\tbyStatus,\n\t\thotNodes: hotNodes.slice(0, opts.limit ?? hotNodes.length),\n\t};\n}\n","/**\n * Passive semantic-memory vocabulary and deterministic helpers.\n *\n * D158 splits semantic memory into horizontal patterns and vertical solutions.\n * This module intentionally owns no graph nodes, storage restore, timers,\n * subscriptions, vector indexes, knowledge graphs, or agentic runtime.\n */\n\nimport type { StrictJsonValue } from \"../json/codec.js\";\n\n/** Stable identity for a semantic-memory fact. */\nexport type FactId = string;\n\n/** Shard partition key used by passive sharding helpers. */\nexport type ShardKey = string | number;\n\n/**\n * A single semantic-memory fact. Pattern convention only: this is not a\n * protocol message, storage record owner, restore contract, or graph runtime.\n */\nexport interface MemoryFragment<T = unknown> {\n\treadonly id: FactId;\n\treadonly payload: T;\n\t/** Transaction time, typically monotonic nanoseconds. */\n\treadonly tNs: bigint;\n\t/** Valid-time start. Undefined means unbounded past. */\n\treadonly validFrom?: bigint;\n\t/** Valid-time end. Undefined means currently valid. */\n\treadonly validTo?: bigint;\n\t/** Confidence score in the closed interval [0, 1]. */\n\treadonly confidence: number;\n\treadonly tags: readonly string[];\n\t/** Fact ids this fragment derives from or depends on. */\n\treadonly sources: readonly FactId[];\n\treadonly embedding?: readonly number[];\n\treadonly parentFragmentId?: FactId;\n\treadonly provenance?: string;\n}\n\n/** Columnar passive store vocabulary for callers that keep memory facts outside GraphReFly. */\nexport interface FactStore<T = unknown> {\n\treadonly byId: ReadonlyMap<FactId, MemoryFragment<T>>;\n}\n\n/** Read-only projection passed to scoring policies; it exposes no mutation surface. */\nexport interface StoreReadHandle<T = unknown> {\n\tget(id: FactId): MemoryFragment<T> | undefined;\n\thas(id: FactId): boolean;\n\treadonly size: number;\n\tvalues(): IterableIterator<MemoryFragment<T>>;\n}\n\nexport type ScoringPolicy<T = unknown> = (\n\tfragment: MemoryFragment<T>,\n\tstore: StoreReadHandle<T>,\n) => number;\nexport type DecayPolicy = (confidence: number, ageNs: bigint) => number;\nexport type AdmissionFilter<T = unknown> = (fragment: MemoryFragment<T>) => boolean;\n\n/** Outcome signal for policy learning. This is an application fact, not a protocol event. */\nexport interface OutcomeSignal {\n\treadonly factId: FactId;\n\treadonly reward: number;\n}\n\n/** Passive structured query over semantic-memory facts. */\nexport interface MemoryQuery {\n\treadonly tags?: readonly string[];\n\treadonly asOf?: bigint;\n\treadonly minConfidence?: number;\n\treadonly limit?: number;\n}\n\nexport interface MemoryAnswer<T = unknown> {\n\treadonly query: MemoryQuery;\n\treadonly results: readonly MemoryFragment<T>[];\n}\n\nexport type KnowledgeAssertionStrictJsonValue = StrictJsonValue;\n\n/** Passive KG endpoint vocabulary. Entity ids are DATA keys, not graph node ids. */\nexport interface KnowledgeAssertionSubject {\n\treadonly id: FactId;\n\treadonly type?: string;\n}\n\n/** Passive KG object/value vocabulary. */\nexport type KnowledgeAssertionObject =\n\t| {\n\t\t\treadonly kind: \"entity\";\n\t\t\treadonly id: FactId;\n\t\t\treadonly type?: string;\n\t }\n\t| {\n\t\t\treadonly kind: \"value\";\n\t\t\treadonly value: KnowledgeAssertionStrictJsonValue;\n\t\t\treadonly valueType?: string;\n\t };\n\n/** Passive KG assertion fact consumed by lower semantic-memory graph patterns. */\nexport interface KnowledgeAssertion {\n\treadonly id: FactId;\n\treadonly recordId?: FactId;\n\treadonly fragmentId?: FactId;\n\treadonly subject: KnowledgeAssertionSubject;\n\treadonly predicate: string;\n\treadonly object: KnowledgeAssertionObject;\n\treadonly confidence?: number;\n\treadonly sources?: readonly FactId[];\n\treadonly provenance?: string;\n}\n\n/** Entry vocabulary for ranked collection-like memory views. */\nexport interface CollectionEntry<T = unknown> {\n\treadonly id: string;\n\treadonly value: T;\n\treadonly createdAtNs: bigint;\n\treadonly lastAccessNs: bigint;\n\treadonly baseScore: number;\n}\n\nexport type RankedCollectionEntry<T = unknown> = CollectionEntry<T> & {\n\treadonly score: number;\n};\n\nexport type CollectionScoreFn<T = unknown> = (value: T) => number;\n\n/** Query shape shared by passive retrieval/ranking helpers. */\nexport interface RetrievalQuery {\n\treadonly text?: string;\n\treadonly vector?: readonly number[];\n\treadonly entityIds?: readonly string[];\n\treadonly context?: readonly string[];\n}\n\nexport interface VectorSearchResult<TMeta = unknown> {\n\treadonly id: string;\n\treadonly score: number;\n\treadonly meta?: TMeta;\n}\n\nexport interface RetrievalEntry<TMem = unknown> {\n\treadonly key: string;\n\treadonly value: TMem;\n\treadonly score: number;\n\treadonly sources: ReadonlyArray<\"vector\" | \"graph\" | \"store\">;\n\treadonly context?: readonly string[];\n}\n\nexport interface RetrievalTrace<TMem = unknown> {\n\treadonly vectorCandidates: ReadonlyArray<VectorSearchResult<TMem>>;\n\treadonly graphExpanded: ReadonlyArray<string>;\n\treadonly ranked: ReadonlyArray<RetrievalEntry<TMem>>;\n\treadonly packed: ReadonlyArray<RetrievalEntry<TMem>>;\n}\n\n/** Generic per-dimension thresholds. Any configured dimension below threshold is rejected. */\nexport type AdmissionThresholds<Dims extends string> = Partial<Record<Dims, number>>;\n\nexport interface AdmissionScoredOptions<Dims extends string, TRaw = unknown> {\n\treadonly scoreFn: (raw: TRaw) => Readonly<Record<Dims, number>>;\n\treadonly thresholds?: AdmissionThresholds<Dims>;\n}\n\nexport interface AdmissionScores {\n\treadonly persistence: number;\n\treadonly structure: number;\n\treadonly personalValue: number;\n}\n\nexport interface AdmissionScore3DOptions {\n\treadonly scoreFn: (raw: unknown) => AdmissionScores;\n\treadonly persistenceThreshold?: number;\n\treadonly personalValueThreshold?: number;\n\treadonly requireStructured?: boolean;\n}\n\nexport interface ShardByTenantOptions {\n\treadonly tenants?: readonly string[];\n\treadonly shardCount?: number;\n}\n\nexport interface ShardByTenantConfig<T = unknown> {\n\treadonly shardBy: (fragment: MemoryFragment<T>) => ShardKey;\n\treadonly shardCount: number;\n}\n\nexport interface MemoryFragmentValidation {\n\treadonly ok: boolean;\n\treadonly errors: readonly string[];\n}\n\n/** Cosine similarity over zero-padded vectors. Non-finite results normalize to 0. */\nexport function cosineSimilarity(a: readonly number[], b: readonly number[]): number {\n\tconst n = Math.max(a.length, b.length);\n\tlet dot = 0;\n\tlet na = 0;\n\tlet nb = 0;\n\tfor (let i = 0; i < n; i += 1) {\n\t\tconst av = a[i] ?? 0;\n\t\tconst bv = b[i] ?? 0;\n\t\tdot += av * bv;\n\t\tna += av * av;\n\t\tnb += bv * bv;\n\t}\n\tif (na === 0 || nb === 0) return 0;\n\tconst score = dot / Math.sqrt(na * nb);\n\treturn Number.isFinite(score) ? score : 0;\n}\n\n/**\n * Returns true when a fragment is valid at `asOf`.\n *\n * Omitted `asOf` has no clock to compare against, so it admits only fragments\n * that are live and not valid-time delayed.\n */\nexport function memoryFragmentValidAt(fragment: MemoryFragment, asOf?: bigint): boolean {\n\tif (asOf === undefined) return fragment.validTo === undefined && fragment.validFrom === undefined;\n\tif (fragment.validFrom !== undefined && fragment.validFrom > asOf) return false;\n\tif (fragment.validTo !== undefined && fragment.validTo <= asOf) return false;\n\treturn true;\n}\n\n/** Pure structured-query predicate over a single fragment. */\nexport function memoryFragmentMatchesQuery(\n\tfragment: MemoryFragment,\n\tquery: MemoryQuery = {},\n): boolean {\n\tif (!memoryFragmentValidAt(fragment, query.asOf)) return false;\n\tif (query.minConfidence !== undefined && fragment.confidence < query.minConfidence) return false;\n\tif (\n\t\tquery.tags &&\n\t\tquery.tags.length > 0 &&\n\t\t!query.tags.some((tag) => fragment.tags.includes(tag))\n\t) {\n\t\treturn false;\n\t}\n\treturn true;\n}\n\n/** Filter and rank fragments by confidence desc, then transaction time desc. */\nexport function filterMemoryFragments<T>(\n\tfragments: Iterable<MemoryFragment<T>>,\n\tquery: MemoryQuery = {},\n): readonly MemoryFragment<T>[] {\n\tconst results = [...fragments].filter((fragment) => memoryFragmentMatchesQuery(fragment, query));\n\tresults.sort((a, b) => b.confidence - a.confidence || compareBigIntDesc(a.tNs, b.tNs));\n\treturn query.limit === undefined ? results : results.slice(0, Math.max(0, query.limit));\n}\n\n/** Validate the passive MemoryFragment shape without throwing. */\nexport function validateMemoryFragment(value: unknown): MemoryFragmentValidation {\n\tconst errors: string[] = [];\n\tif (typeof value !== \"object\" || value === null) {\n\t\treturn { ok: false, errors: [\"fragment must be an object\"] };\n\t}\n\tconst fragment = value as Partial<MemoryFragment>;\n\tif (typeof fragment.id !== \"string\" || fragment.id.length === 0) {\n\t\terrors.push(\"id must be a non-empty string\");\n\t}\n\tif (!Object.hasOwn(fragment, \"payload\")) {\n\t\terrors.push(\"payload must be present\");\n\t}\n\tif (typeof fragment.tNs !== \"bigint\") {\n\t\terrors.push(\"tNs must be a bigint\");\n\t}\n\tconst confidence = fragment.confidence;\n\tif (\n\t\t!Number.isFinite(confidence) ||\n\t\tconfidence === undefined ||\n\t\tconfidence < 0 ||\n\t\tconfidence > 1\n\t) {\n\t\terrors.push(\"confidence must be a finite number in [0, 1]\");\n\t}\n\tif (!isDenseArrayOf(fragment.tags, (tag): tag is string => typeof tag === \"string\")) {\n\t\terrors.push(\"tags must be a readonly string array\");\n\t}\n\tif (!isDenseArrayOf(fragment.sources, (source): source is string => typeof source === \"string\")) {\n\t\terrors.push(\"sources must be a readonly string array\");\n\t}\n\tif (fragment.validFrom !== undefined && typeof fragment.validFrom !== \"bigint\") {\n\t\terrors.push(\"validFrom must be a bigint when present\");\n\t}\n\tif (fragment.validTo !== undefined && typeof fragment.validTo !== \"bigint\") {\n\t\terrors.push(\"validTo must be a bigint when present\");\n\t}\n\tif (\n\t\ttypeof fragment.validFrom === \"bigint\" &&\n\t\ttypeof fragment.validTo === \"bigint\" &&\n\t\tfragment.validFrom >= fragment.validTo\n\t) {\n\t\terrors.push(\"validFrom must be earlier than validTo\");\n\t}\n\tif (\n\t\tfragment.embedding !== undefined &&\n\t\t!isDenseArrayOf(fragment.embedding, (component): component is number =>\n\t\t\tNumber.isFinite(component),\n\t\t)\n\t) {\n\t\terrors.push(\"embedding must be a finite number array when present\");\n\t}\n\tif (fragment.parentFragmentId !== undefined && typeof fragment.parentFragmentId !== \"string\") {\n\t\terrors.push(\"parentFragmentId must be a string when present\");\n\t}\n\tif (fragment.provenance !== undefined && typeof fragment.provenance !== \"string\") {\n\t\terrors.push(\"provenance must be a string when present\");\n\t}\n\treturn { ok: errors.length === 0, errors };\n}\n\nexport function isMemoryFragment(value: unknown): value is MemoryFragment {\n\treturn validateMemoryFragment(value).ok;\n}\n\n/**\n * Generic N-dimension admission filter. Missing or non-finite thresholded scores reject.\n */\nexport function admissionScored<Dims extends string, TRaw = unknown>(\n\topts: AdmissionScoredOptions<Dims, TRaw>,\n): (raw: TRaw) => boolean {\n\tconst thresholds = opts.thresholds ?? ({} as AdmissionThresholds<Dims>);\n\treturn (raw: TRaw): boolean => {\n\t\tconst scores = opts.scoreFn(raw);\n\t\tfor (const dim of Object.keys(thresholds) as Dims[]) {\n\t\t\tconst min = thresholds[dim];\n\t\t\tif (min === undefined) continue;\n\t\t\tconst score = scores[dim];\n\t\t\tconst safe = Number.isFinite(score) ? (score as number) : Number.NEGATIVE_INFINITY;\n\t\t\tif (safe < min) return false;\n\t\t}\n\t\treturn true;\n\t};\n}\n\n/** Three-axis admission sugar for persistence / structure / personal-value scoring. */\nexport function admissionFilter3D(opts: AdmissionScore3DOptions): (raw: unknown) => boolean {\n\treturn (raw: unknown): boolean => {\n\t\tconst scores = opts.scoreFn(raw);\n\t\tif (!scoreAtLeast(scores.persistence, opts.persistenceThreshold ?? 0.3)) return false;\n\t\tif (!scoreAtLeast(scores.personalValue, opts.personalValueThreshold ?? 0.3)) return false;\n\t\tif (!opts.requireStructured) return true;\n\t\treturn scoreAtLeast(scores.structure, Number.MIN_VALUE);\n\t};\n}\n\n/** Build a passive `{ shardBy, shardCount }` pair for tenant-isolated sharding. */\nexport function shardByTenant<T>(\n\ttenantOf: (fragment: MemoryFragment<T>) => string,\n\topts: ShardByTenantOptions = {},\n): ShardByTenantConfig<T> {\n\tif (opts.tenants && opts.tenants.length > 0) {\n\t\tconst tenants = [...new Set(opts.tenants)];\n\t\tconst index = new Map(tenants.map((tenant, i) => [tenant, i] as const));\n\t\tconst overflow = tenants.length;\n\t\treturn {\n\t\t\tshardBy: (fragment) => index.get(tenantOf(fragment)) ?? overflow,\n\t\t\tshardCount: tenants.length + 1,\n\t\t};\n\t}\n\tconst configuredShardCount = opts.shardCount ?? 4;\n\tconst shardCount = Number.isSafeInteger(configuredShardCount)\n\t\t? Math.max(1, configuredShardCount)\n\t\t: 4;\n\treturn { shardBy: (fragment) => tenantOf(fragment), shardCount };\n}\n\nfunction compareBigIntDesc(a: bigint, b: bigint): number {\n\tif (a === b) return 0;\n\treturn a > b ? -1 : 1;\n}\n\nfunction isDenseArrayOf<T>(value: unknown, predicate: (item: unknown) => item is T): value is T[] {\n\tif (!Array.isArray(value)) return false;\n\tfor (let i = 0; i < value.length; i += 1) {\n\t\tif (!Object.hasOwn(value, i) || !predicate(value[i])) return false;\n\t}\n\treturn true;\n}\n\nfunction scoreAtLeast(score: number, min: number): boolean {\n\treturn Number.isFinite(score) && score >= min;\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 identifier (R-pause-lockset). */\nexport type LockId = string | symbol;\n\n/**\n * The CLOSED set of 10 message types (R-msg-closed-set / D9 + 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\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\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 tiers only (R-ctx-up / DR-5): DIRTY, PAUSE, RESUME,\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, 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([[RESUME, pullId]])` — but for a SELF-demand (demanding a dep this fn also\n\t * 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/**\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([[RESUME, pullId]])` to demand a pull dep it\n\t * ALSO reads — the cone-routed RESUME 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","/**\n * Graph-visible semantic-memory retrieval patterns.\n *\n * D158 allows horizontal semantic-memory patterns when they are ordinary graph\n * nodes with declared deps and graph-visible facts. This file intentionally\n * owns no storage restore/hydration, scheduler, hidden subscription, vector DB,\n * retention loop, consolidation loop, Graph subclass, or protocol behavior.\n */\n\nimport { depBatch, depLatest } from \"../ctx/types.js\";\nimport type { Graph } from \"../graph/graph.js\";\nimport type { Node } from \"../node/node.js\";\nimport {\n\tcosineSimilarity,\n\ttype FactId,\n\tfilterMemoryFragments,\n\ttype KnowledgeAssertion,\n\ttype KnowledgeAssertionObject,\n\ttype KnowledgeAssertionSubject,\n\ttype MemoryAnswer,\n\ttype MemoryFragment,\n\ttype MemoryQuery,\n\tmemoryFragmentMatchesQuery,\n\tvalidateMemoryFragment,\n} from \"./semantic-memory.js\";\n\n/** Query shape for the first graph-visible retrieval bundle. */\nexport interface MemoryRetrievalQuery extends MemoryQuery {\n\t/** Optional dense embedding used only for deterministic in-memory ranking. */\n\treadonly vector?: readonly number[];\n}\n\nexport interface MemoryRetrievalCursor {\n\treadonly evaluation: number;\n\treadonly validFragments: number;\n\treadonly invalidFragments: number;\n\treadonly resultCount: number;\n}\n\nexport type MemoryRetrievalStatusState = \"ready\" | \"empty\" | \"partial\" | \"error\";\n\nexport interface MemoryRetrievalStatus {\n\treadonly state: MemoryRetrievalStatusState;\n\treadonly query: MemoryRetrievalQuery;\n\treadonly cursor: MemoryRetrievalCursor;\n}\n\nexport interface MemoryRetrievalIndex<T = unknown> {\n\treadonly ids: readonly FactId[];\n\treadonly byId: Readonly<Record<FactId, MemoryFragment<T>>>;\n\treadonly cursor: MemoryRetrievalCursor;\n}\n\nexport type MemoryRetrievalErrorCode =\n\t| \"duplicate-fragment-id\"\n\t| \"invalid-fragments-input\"\n\t| \"invalid-fragment\"\n\t| \"invalid-query\"\n\t| \"invalid-query-vector\";\n\nexport interface MemoryRetrievalError {\n\treadonly code: MemoryRetrievalErrorCode;\n\treadonly message: string;\n\treadonly index?: number;\n\treadonly fragment?: unknown;\n\treadonly validationErrors?: readonly string[];\n\treadonly cursor: MemoryRetrievalCursor;\n}\n\nexport interface MemoryRetrievalSnapshot<T = unknown> {\n\treadonly fragments: readonly MemoryFragment<T>[];\n\treadonly indexed: MemoryRetrievalIndex<T>;\n\treadonly ranked: MemoryAnswer<T>;\n\treadonly status: MemoryRetrievalStatus;\n\treadonly errors: readonly MemoryRetrievalError[];\n\treadonly cursor: MemoryRetrievalCursor;\n}\n\nexport type MemoryRetrievalFact<T = unknown> = MemoryRetrievalSnapshot<T>;\n\nexport interface KnowledgeGraphEntity {\n\treadonly id: FactId;\n\treadonly type?: string;\n\treadonly assertionIds: readonly FactId[];\n\treadonly subjectAssertionIds: readonly FactId[];\n\treadonly objectAssertionIds: readonly FactId[];\n}\n\nexport interface KnowledgeGraphRelation {\n\treadonly assertionId: FactId;\n\treadonly subject: KnowledgeAssertionSubject;\n\treadonly predicate: string;\n\treadonly object: KnowledgeAssertionObject;\n\treadonly confidence?: number;\n\treadonly sources: readonly FactId[];\n\treadonly provenance?: string;\n}\n\nexport interface KnowledgeGraphTopic {\n\treadonly predicate: string;\n\treadonly assertionIds: readonly FactId[];\n\treadonly entityIds: readonly FactId[];\n}\n\nexport interface KnowledgeGraphIndex {\n\treadonly assertionIds: readonly FactId[];\n\treadonly entityIds: readonly FactId[];\n\treadonly relationIds: readonly FactId[];\n\treadonly predicates: readonly string[];\n}\n\nexport interface KnowledgeGraphPolicy {\n\treadonly allowedPredicates?: readonly string[];\n\treadonly requireEntityTypes?: boolean;\n}\n\nexport interface KnowledgeGraphCursor {\n\treadonly evaluation: number;\n\treadonly validAssertions: number;\n\treadonly invalidAssertions: number;\n\treadonly entityCount: number;\n\treadonly relationCount: number;\n\treadonly predicateCount: number;\n}\n\nexport type KnowledgeGraphStatusState = \"ready\" | \"empty\" | \"partial\" | \"error\";\n\nexport interface KnowledgeGraphStatus {\n\treadonly state: KnowledgeGraphStatusState;\n\treadonly cursor: KnowledgeGraphCursor;\n}\n\nexport type KnowledgeGraphErrorCode =\n\t| \"invalid-assertions-input\"\n\t| \"invalid-assertion\"\n\t| \"duplicate-assertion-id\"\n\t| \"invalid-policy\"\n\t| \"policy-conflict\";\n\nexport interface KnowledgeGraphError {\n\treadonly code: KnowledgeGraphErrorCode;\n\treadonly message: string;\n\treadonly index?: number;\n\treadonly assertionId?: FactId;\n\treadonly assertion?: unknown;\n\treadonly validationErrors?: readonly string[];\n\treadonly cursor: KnowledgeGraphCursor;\n}\n\nexport interface KnowledgeGraphSnapshot {\n\treadonly assertions: readonly KnowledgeAssertion[];\n\treadonly entities: readonly KnowledgeGraphEntity[];\n\treadonly relations: readonly KnowledgeGraphRelation[];\n\treadonly topics: readonly KnowledgeGraphTopic[];\n\treadonly index: KnowledgeGraphIndex;\n\treadonly status: KnowledgeGraphStatus;\n\treadonly errors: readonly KnowledgeGraphError[];\n\treadonly cursor: KnowledgeGraphCursor;\n}\n\nexport interface KnowledgeGraphReducerBundle {\n\treadonly input: {\n\t\treadonly assertions: Node<readonly unknown[]>;\n\t\treadonly policy?: Node<KnowledgeGraphPolicy>;\n\t};\n\treadonly snapshot: Node<KnowledgeGraphSnapshot>;\n\treadonly assertions: Node<readonly KnowledgeAssertion[]>;\n\treadonly entities: Node<readonly KnowledgeGraphEntity[]>;\n\treadonly relations: Node<readonly KnowledgeGraphRelation[]>;\n\treadonly topics: Node<readonly KnowledgeGraphTopic[]>;\n\treadonly index: Node<KnowledgeGraphIndex>;\n\treadonly status: Node<KnowledgeGraphStatus>;\n\treadonly errors: Node<readonly KnowledgeGraphError[]>;\n\treadonly cursor: Node<KnowledgeGraphCursor>;\n}\n\nexport interface KnowledgeGraphReducerBundleOptions {\n\treadonly name?: string;\n\treadonly assertions: Node<readonly unknown[]>;\n\treadonly policy?: Node<KnowledgeGraphPolicy>;\n}\n\nexport interface MemoryRetrievalBundle<T = unknown> {\n\treadonly input: {\n\t\treadonly fragments: Node<readonly unknown[]>;\n\t\treadonly query: Node<MemoryRetrievalQuery>;\n\t};\n\treadonly snapshot: Node<MemoryRetrievalSnapshot<T>>;\n\treadonly fragments: Node<readonly MemoryFragment<T>[]>;\n\treadonly indexed: Node<MemoryRetrievalIndex<T>>;\n\treadonly ranked: Node<MemoryAnswer<T>>;\n\treadonly status: Node<MemoryRetrievalStatus>;\n\treadonly errors: Node<readonly MemoryRetrievalError[]>;\n\treadonly cursor: Node<MemoryRetrievalCursor>;\n}\n\nexport interface MemoryRetrievalBundleOptions {\n\treadonly name?: string;\n\treadonly fragments: Node<readonly unknown[]>;\n\treadonly query: Node<MemoryRetrievalQuery>;\n}\n\ninterface MemoryRetrievalRuntimeState {\n\tevaluation: number;\n}\n\ninterface MemoryRetrievalQueryValidation {\n\treadonly ok: boolean;\n\treadonly query: MemoryRetrievalQuery;\n\treadonly errors: readonly Omit<MemoryRetrievalError, \"cursor\">[];\n}\n\ninterface FragmentValidationResult<T> {\n\treadonly fragment?: MemoryFragment<T>;\n\treadonly error?: Omit<MemoryRetrievalError, \"cursor\">;\n}\n\n/**\n * Build a graph-visible memory retrieval bundle from explicit fragment/query deps.\n *\n * Invalid fragments and ranking status are emitted as ordinary DATA facts. The\n * bundle never owns storage restore or hidden mutation; callers that need\n * persistence compose D161 collection/storage sidecars outside this pattern.\n */\nexport function memoryRetrievalBundle<T = unknown>(\n\tgraph: Graph,\n\topts: MemoryRetrievalBundleOptions,\n): MemoryRetrievalBundle<T> {\n\tconst name = opts.name ?? \"memoryRetrieval\";\n\tconst { fragments, query } = opts;\n\tconst snapshot = graph.node<MemoryRetrievalSnapshot<T>>(\n\t\t[fragments, query],\n\t\t(ctx) => {\n\t\t\tconst state =\n\t\t\t\tctx.state.get<MemoryRetrievalRuntimeState>() ??\n\t\t\t\t({ evaluation: 0 } satisfies MemoryRetrievalRuntimeState);\n\t\t\tstate.evaluation += 1;\n\t\t\tconst rawFragments = depLatest(ctx, 0);\n\t\t\tconst rawQuery = depLatest(ctx, 1);\n\t\t\tconst queryValidation = validateMemoryRetrievalQuery(rawQuery);\n\t\t\tconst currentQuery = queryValidation.query;\n\t\t\tconst valid: MemoryFragment<T>[] = [];\n\t\t\tconst seenIds = new Set<FactId>();\n\t\t\tconst errors: Omit<MemoryRetrievalError, \"cursor\">[] = [...queryValidation.errors];\n\n\t\t\tif (!Array.isArray(rawFragments)) {\n\t\t\t\terrors.push({\n\t\t\t\t\tcode: \"invalid-fragments-input\",\n\t\t\t\t\tmessage: \"memoryRetrievalBundle: fragments input must be an array\",\n\t\t\t\t\tfragment: rawFragments,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tconst length = safeArrayLength(rawFragments);\n\t\t\t\tif (length === undefined) {\n\t\t\t\t\terrors.push({\n\t\t\t\t\t\tcode: \"invalid-fragments-input\",\n\t\t\t\t\t\tmessage: \"memoryRetrievalBundle: fragments input length could not be read\",\n\t\t\t\t\t\tfragment: rawFragments,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tfor (let i = 0; i < (length ?? 0); i += 1) {\n\t\t\t\t\tconst result = validateAndSnapshotFragment<T>(rawFragments, i);\n\t\t\t\t\tif (result.error !== undefined) {\n\t\t\t\t\t\terrors.push(result.error);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst fragment = result.fragment as MemoryFragment<T>;\n\t\t\t\t\tif (seenIds.has(fragment.id)) {\n\t\t\t\t\t\terrors.push({\n\t\t\t\t\t\t\tcode: \"duplicate-fragment-id\",\n\t\t\t\t\t\t\tmessage: \"memoryRetrievalBundle: duplicate fragment id\",\n\t\t\t\t\t\t\tindex: i,\n\t\t\t\t\t\t\tfragment,\n\t\t\t\t\t\t\tvalidationErrors: [`duplicate fragment id '${fragment.id}'`],\n\t\t\t\t\t\t});\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tseenIds.add(fragment.id);\n\t\t\t\t\tvalid.push(fragment);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst ranked = errors.some((error) => !isRecoverableFragmentError(error))\n\t\t\t\t? []\n\t\t\t\t: rankFragments(valid, currentQuery);\n\t\t\tconst cursor: MemoryRetrievalCursor = Object.freeze({\n\t\t\t\tevaluation: state.evaluation,\n\t\t\t\tvalidFragments: valid.length,\n\t\t\t\tinvalidFragments: errors.filter(\n\t\t\t\t\t(error) => error.code === \"invalid-fragment\" || error.code === \"duplicate-fragment-id\",\n\t\t\t\t).length,\n\t\t\t\tresultCount: ranked.length,\n\t\t\t});\n\t\t\tctx.state.set(state);\n\t\t\tconst answer: MemoryAnswer<T> = Object.freeze({\n\t\t\t\tquery: currentQuery,\n\t\t\t\tresults: Object.freeze(ranked),\n\t\t\t});\n\t\t\tconst status: MemoryRetrievalStatus = Object.freeze({\n\t\t\t\tstate: statusState(errors, ranked.length),\n\t\t\t\tquery: currentQuery,\n\t\t\t\tcursor,\n\t\t\t});\n\t\t\tconst indexed: MemoryRetrievalIndex<T> = Object.freeze({\n\t\t\t\tids: Object.freeze(valid.map((fragment) => fragment.id)),\n\t\t\t\tbyId: indexById(valid),\n\t\t\t\tcursor,\n\t\t\t});\n\t\t\tconst errorFacts = Object.freeze(\n\t\t\t\terrors.map((error) =>\n\t\t\t\t\tObject.freeze({\n\t\t\t\t\t\t...error,\n\t\t\t\t\t\t...(error.validationErrors === undefined\n\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t: { validationErrors: Object.freeze([...error.validationErrors]) }),\n\t\t\t\t\t\tcursor,\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t);\n\n\t\t\tctx.down([\n\t\t\t\t[\n\t\t\t\t\t\"DATA\",\n\t\t\t\t\tObject.freeze({\n\t\t\t\t\t\tfragments: Object.freeze([...valid]),\n\t\t\t\t\t\tindexed,\n\t\t\t\t\t\tranked: answer,\n\t\t\t\t\t\tstatus,\n\t\t\t\t\t\terrors: errorFacts,\n\t\t\t\t\t\tcursor,\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t]);\n\t\t},\n\t\t{\n\t\t\tname: `${name}/snapshot`,\n\t\t\tfactory: \"memoryRetrievalSnapshot\",\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\treturn {\n\t\tinput: { fragments, query },\n\t\tsnapshot,\n\t\tfragments: retrievalProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/fragments`,\n\t\t\t\"memoryRetrievalFragments\",\n\t\t\t(fact) => fact.fragments,\n\t\t),\n\t\tindexed: retrievalProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/indexed`,\n\t\t\t\"memoryRetrievalIndexed\",\n\t\t\t(fact) => fact.indexed,\n\t\t),\n\t\tranked: retrievalProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/ranked`,\n\t\t\t\"memoryRetrievalRanked\",\n\t\t\t(fact) => fact.ranked,\n\t\t),\n\t\tstatus: retrievalProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/status`,\n\t\t\t\"memoryRetrievalStatus\",\n\t\t\t(fact) => fact.status,\n\t\t),\n\t\terrors: retrievalProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/errors`,\n\t\t\t\"memoryRetrievalErrors\",\n\t\t\t(fact) => fact.errors,\n\t\t),\n\t\tcursor: retrievalProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/cursor`,\n\t\t\t\"memoryRetrievalCursor\",\n\t\t\t(fact) => fact.cursor,\n\t\t),\n\t};\n}\n\n/**\n * D170 lower semantic-memory KG materializer.\n *\n * Assertion, entity, relation, and topic ids remain DATA keys. The bundle has\n * static describe-visible topology and owns no storage, LLM extraction,\n * scheduler, agent runtime, or dynamic graph node lifecycle.\n */\nexport function knowledgeGraphReducerBundle(\n\tgraph: Graph,\n\topts: KnowledgeGraphReducerBundleOptions,\n): KnowledgeGraphReducerBundle {\n\tconst name = opts.name ?? \"knowledgeGraph\";\n\tconst deps = opts.policy === undefined ? [opts.assertions] : [opts.assertions, opts.policy];\n\tconst snapshot = graph.node<KnowledgeGraphSnapshot>(\n\t\tdeps,\n\t\t(ctx) => {\n\t\t\tconst state =\n\t\t\t\tctx.state.get<{ evaluation: number }>() ??\n\t\t\t\t({ evaluation: 0 } satisfies { evaluation: number });\n\t\t\tstate.evaluation += 1;\n\t\t\tconst policy = validateKnowledgeGraphPolicy(\n\t\t\t\topts.policy === undefined ? undefined : depLatest(ctx, 1),\n\t\t\t);\n\t\t\tconst reduced = reduceKnowledgeAssertions(depLatest(ctx, 0), policy.policy);\n\t\t\tconst pendingErrors = [...policy.errors, ...reduced.errors];\n\t\t\tconst cursor: KnowledgeGraphCursor = Object.freeze({\n\t\t\t\tevaluation: state.evaluation,\n\t\t\t\tvalidAssertions: reduced.assertions.length,\n\t\t\t\tinvalidAssertions: reduced.invalidAssertions,\n\t\t\t\tentityCount: reduced.entities.length,\n\t\t\t\trelationCount: reduced.relations.length,\n\t\t\t\tpredicateCount: reduced.topics.length,\n\t\t\t});\n\t\t\tconst errors = Object.freeze(\n\t\t\t\tpendingErrors.map((error) =>\n\t\t\t\t\tObject.freeze({\n\t\t\t\t\t\t...error,\n\t\t\t\t\t\t...(error.validationErrors === undefined\n\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t: { validationErrors: Object.freeze([...error.validationErrors]) }),\n\t\t\t\t\t\tcursor,\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t);\n\t\t\tconst status: KnowledgeGraphStatus = Object.freeze({\n\t\t\t\tstate:\n\t\t\t\t\treduced.assertions.length === 0 && errors.length === 0\n\t\t\t\t\t\t? \"empty\"\n\t\t\t\t\t\t: errors.length === 0\n\t\t\t\t\t\t\t? \"ready\"\n\t\t\t\t\t\t\t: reduced.assertions.length > 0\n\t\t\t\t\t\t\t\t? \"partial\"\n\t\t\t\t\t\t\t\t: \"error\",\n\t\t\t\tcursor,\n\t\t\t});\n\t\t\tctx.state.set(state);\n\t\t\tctx.down([\n\t\t\t\t[\n\t\t\t\t\t\"DATA\",\n\t\t\t\t\tObject.freeze({\n\t\t\t\t\t\tassertions: Object.freeze(reduced.assertions),\n\t\t\t\t\t\tentities: Object.freeze(reduced.entities),\n\t\t\t\t\t\trelations: Object.freeze(reduced.relations),\n\t\t\t\t\t\ttopics: Object.freeze(reduced.topics),\n\t\t\t\t\t\tindex: reduced.index,\n\t\t\t\t\t\tstatus,\n\t\t\t\t\t\terrors,\n\t\t\t\t\t\tcursor,\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t]);\n\t\t},\n\t\t{\n\t\t\tname: `${name}/snapshot`,\n\t\t\tfactory: \"knowledgeGraphReducerSnapshot\",\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\treturn {\n\t\tinput: {\n\t\t\tassertions: opts.assertions,\n\t\t\t...(opts.policy === undefined ? {} : { policy: opts.policy }),\n\t\t},\n\t\tsnapshot,\n\t\tassertions: kgProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/assertions`,\n\t\t\t\"knowledgeGraphAssertions\",\n\t\t\t(fact) => fact.assertions,\n\t\t),\n\t\tentities: kgProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/entities`,\n\t\t\t\"knowledgeGraphEntities\",\n\t\t\t(fact) => fact.entities,\n\t\t),\n\t\trelations: kgProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/relations`,\n\t\t\t\"knowledgeGraphRelations\",\n\t\t\t(fact) => fact.relations,\n\t\t),\n\t\ttopics: kgProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/topics`,\n\t\t\t\"knowledgeGraphTopics\",\n\t\t\t(fact) => fact.topics,\n\t\t),\n\t\tindex: kgProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/index`,\n\t\t\t\"knowledgeGraphIndex\",\n\t\t\t(fact) => fact.index,\n\t\t),\n\t\tstatus: kgProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/status`,\n\t\t\t\"knowledgeGraphStatus\",\n\t\t\t(fact) => fact.status,\n\t\t),\n\t\terrors: kgProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/errors`,\n\t\t\t\"knowledgeGraphErrors\",\n\t\t\t(fact) => fact.errors,\n\t\t),\n\t\tcursor: kgProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/cursor`,\n\t\t\t\"knowledgeGraphCursor\",\n\t\t\t(fact) => fact.cursor,\n\t\t),\n\t};\n}\n\nfunction retrievalProjection<TFact, T>(\n\tgraph: Graph,\n\tsnapshot: Node<MemoryRetrievalSnapshot<T>>,\n\tname: string,\n\tfactory: string,\n\tselect: (fact: MemoryRetrievalSnapshot<T>) => TFact | undefined,\n): Node<TFact> {\n\treturn graph.node<TFact>(\n\t\t[snapshot],\n\t\t(ctx) => {\n\t\t\tfor (const raw of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst fact = raw as MemoryRetrievalSnapshot<T>;\n\t\t\t\tconst selected = select(fact);\n\t\t\t\tif (selected !== undefined) ctx.down([[\"DATA\", selected]]);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname,\n\t\t\tfactory,\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n}\n\nfunction kgProjection<TFact>(\n\tgraph: Graph,\n\tsnapshot: Node<KnowledgeGraphSnapshot>,\n\tname: string,\n\tfactory: string,\n\tselect: (fact: KnowledgeGraphSnapshot) => TFact,\n): Node<TFact> {\n\treturn graph.node<TFact>(\n\t\t[snapshot],\n\t\t(ctx) => {\n\t\t\tfor (const raw of depBatch(ctx, 0) ?? []) {\n\t\t\t\tctx.down([[\"DATA\", select(raw as KnowledgeGraphSnapshot)]]);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname,\n\t\t\tfactory,\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n}\n\nfunction validateKnowledgeGraphPolicy(value: unknown): {\n\treadonly policy?: KnowledgeGraphPolicy;\n\treadonly errors: readonly Omit<KnowledgeGraphError, \"cursor\">[];\n} {\n\tif (value === undefined) return { policy: undefined, errors: [] };\n\tif (!isPlainObject(value)) {\n\t\treturn {\n\t\t\terrors: [\n\t\t\t\t{\n\t\t\t\t\tcode: \"invalid-policy\",\n\t\t\t\t\tmessage: \"knowledgeGraphReducerBundle: policy must be an object\",\n\t\t\t\t\tassertion: value,\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\t}\n\tconst errors: string[] = [];\n\tconst policy = value as Partial<KnowledgeGraphPolicy>;\n\tif (\n\t\tpolicy.allowedPredicates !== undefined &&\n\t\t!isDenseArrayOf(policy.allowedPredicates, (item): item is string => typeof item === \"string\")\n\t) {\n\t\terrors.push(\"allowedPredicates must be a readonly string array\");\n\t}\n\tif (policy.requireEntityTypes !== undefined && typeof policy.requireEntityTypes !== \"boolean\") {\n\t\terrors.push(\"requireEntityTypes must be a boolean when present\");\n\t}\n\tif (errors.length > 0) {\n\t\treturn {\n\t\t\terrors: [\n\t\t\t\t{\n\t\t\t\t\tcode: \"invalid-policy\",\n\t\t\t\t\tmessage: \"knowledgeGraphReducerBundle: policy is invalid\",\n\t\t\t\t\tassertion: value,\n\t\t\t\t\tvalidationErrors: Object.freeze(errors),\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\t}\n\treturn {\n\t\tpolicy: Object.freeze({\n\t\t\t...(policy.allowedPredicates === undefined\n\t\t\t\t? {}\n\t\t\t\t: { allowedPredicates: Object.freeze([...policy.allowedPredicates]) }),\n\t\t\t...(policy.requireEntityTypes === undefined\n\t\t\t\t? {}\n\t\t\t\t: { requireEntityTypes: policy.requireEntityTypes }),\n\t\t}),\n\t\terrors: [],\n\t};\n}\n\nfunction reduceKnowledgeAssertions(\n\tvalue: unknown,\n\tpolicy?: KnowledgeGraphPolicy,\n): {\n\treadonly assertions: readonly KnowledgeAssertion[];\n\treadonly entities: readonly KnowledgeGraphEntity[];\n\treadonly relations: readonly KnowledgeGraphRelation[];\n\treadonly topics: readonly KnowledgeGraphTopic[];\n\treadonly index: KnowledgeGraphIndex;\n\treadonly errors: readonly Omit<KnowledgeGraphError, \"cursor\">[];\n\treadonly invalidAssertions: number;\n} {\n\tconst assertions: KnowledgeAssertion[] = [];\n\tconst errors: Omit<KnowledgeGraphError, \"cursor\">[] = [];\n\tconst seenAssertions = new Set<FactId>();\n\tif (!Array.isArray(value)) {\n\t\treturn {\n\t\t\tassertions,\n\t\t\tentities: [],\n\t\t\trelations: [],\n\t\t\ttopics: [],\n\t\t\tindex: emptyKnowledgeGraphIndex(),\n\t\t\terrors: [\n\t\t\t\t{\n\t\t\t\t\tcode: \"invalid-assertions-input\",\n\t\t\t\t\tmessage: \"knowledgeGraphReducerBundle: assertions input must be an array\",\n\t\t\t\t\tassertion: value,\n\t\t\t\t},\n\t\t\t],\n\t\t\tinvalidAssertions: 0,\n\t\t};\n\t}\n\tconst length = safeArrayLength(value);\n\tif (length === undefined) {\n\t\treturn {\n\t\t\tassertions,\n\t\t\tentities: [],\n\t\t\trelations: [],\n\t\t\ttopics: [],\n\t\t\tindex: emptyKnowledgeGraphIndex(),\n\t\t\terrors: [\n\t\t\t\t{\n\t\t\t\t\tcode: \"invalid-assertions-input\",\n\t\t\t\t\tmessage: \"knowledgeGraphReducerBundle: assertions input length could not be read\",\n\t\t\t\t\tassertion: value,\n\t\t\t\t},\n\t\t\t],\n\t\t\tinvalidAssertions: 0,\n\t\t};\n\t}\n\tfor (let i = 0; i < length; i += 1) {\n\t\tconst result = validateKnowledgeAssertion(value[i], i, policy);\n\t\tif (result.error !== undefined) {\n\t\t\terrors.push(result.error);\n\t\t\tcontinue;\n\t\t}\n\t\tconst assertion = result.assertion as KnowledgeAssertion;\n\t\tif (seenAssertions.has(assertion.id)) {\n\t\t\terrors.push({\n\t\t\t\tcode: \"duplicate-assertion-id\",\n\t\t\t\tmessage: \"knowledgeGraphReducerBundle: duplicate assertion id\",\n\t\t\t\tindex: i,\n\t\t\t\tassertionId: assertion.id,\n\t\t\t\tassertion,\n\t\t\t\tvalidationErrors: Object.freeze([`duplicate assertion id '${assertion.id}'`]),\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tseenAssertions.add(assertion.id);\n\t\tassertions.push(assertion);\n\t}\n\tconst materialized = materializeKnowledgeGraph(assertions);\n\treturn {\n\t\tassertions: Object.freeze(assertions),\n\t\t...materialized,\n\t\terrors,\n\t\tinvalidAssertions: errors.filter((error) => error.code !== \"invalid-policy\").length,\n\t};\n}\n\nfunction validateKnowledgeAssertion(\n\tvalue: unknown,\n\tindex: number,\n\tpolicy?: KnowledgeGraphPolicy,\n): {\n\treadonly assertion?: KnowledgeAssertion;\n\treadonly error?: Omit<KnowledgeGraphError, \"cursor\">;\n} {\n\tif (!isPlainObject(value)) {\n\t\treturn invalidKnowledgeAssertion(index, value, [\"assertion must be an object\"]);\n\t}\n\tconst raw = value as Partial<KnowledgeAssertion>;\n\tconst errors: string[] = [];\n\tif (!isNonEmptyString(raw.id)) errors.push(\"id must be a non-empty string\");\n\tif (!isKnowledgeSubject(raw.subject)) errors.push(\"subject.id must be a non-empty string\");\n\tif (!isNonEmptyString(raw.predicate)) errors.push(\"predicate must be a non-empty string\");\n\tif (!isKnowledgeObject(raw.object)) errors.push(\"object shape is invalid\");\n\tif (\n\t\traw.confidence !== undefined &&\n\t\t(!Number.isFinite(raw.confidence) || raw.confidence < 0 || raw.confidence > 1)\n\t) {\n\t\terrors.push(\"confidence must be a finite number in [0, 1] when present\");\n\t}\n\tif (raw.sources !== undefined && !isDenseArrayOf(raw.sources, isNonEmptyString)) {\n\t\terrors.push(\"sources must be a readonly non-empty string array when present\");\n\t}\n\tif (\n\t\tpolicy?.allowedPredicates !== undefined &&\n\t\t!policy.allowedPredicates.includes(raw.predicate ?? \"\")\n\t) {\n\t\terrors.push(`predicate '${String(raw.predicate)}' is not allowed by policy`);\n\t}\n\tif (policy?.requireEntityTypes === true) {\n\t\tif (isKnowledgeSubject(raw.subject) && raw.subject.type === undefined) {\n\t\t\terrors.push(\"subject.type is required by policy\");\n\t\t}\n\t\tif (\n\t\t\tisKnowledgeObject(raw.object) &&\n\t\t\traw.object.kind === \"entity\" &&\n\t\t\traw.object.type === undefined\n\t\t) {\n\t\t\terrors.push(\"object.type is required by policy for entity objects\");\n\t\t}\n\t}\n\tif (errors.length > 0) {\n\t\treturn invalidKnowledgeAssertion(index, value, errors, raw.id);\n\t}\n\treturn {\n\t\tassertion: Object.freeze({\n\t\t\tid: raw.id as FactId,\n\t\t\t...(raw.recordId === undefined ? {} : { recordId: raw.recordId }),\n\t\t\t...(raw.fragmentId === undefined ? {} : { fragmentId: raw.fragmentId }),\n\t\t\tsubject: snapshotSubject(raw.subject as KnowledgeAssertionSubject),\n\t\t\tpredicate: raw.predicate as string,\n\t\t\tobject: snapshotObject(raw.object as KnowledgeAssertionObject),\n\t\t\t...(raw.confidence === undefined ? {} : { confidence: raw.confidence }),\n\t\t\tsources: Object.freeze([...(raw.sources ?? [])]),\n\t\t\t...(raw.provenance === undefined ? {} : { provenance: raw.provenance }),\n\t\t}),\n\t};\n}\n\nfunction invalidKnowledgeAssertion(\n\tindex: number,\n\tassertion: unknown,\n\tvalidationErrors: readonly string[],\n\tassertionId?: unknown,\n): { readonly error: Omit<KnowledgeGraphError, \"cursor\"> } {\n\treturn {\n\t\terror: {\n\t\t\tcode: \"invalid-assertion\",\n\t\t\tmessage: \"knowledgeGraphReducerBundle: assertion is invalid\",\n\t\t\tindex,\n\t\t\tassertionId: typeof assertionId === \"string\" ? assertionId : undefined,\n\t\t\tassertion,\n\t\t\tvalidationErrors: Object.freeze([...validationErrors]),\n\t\t},\n\t};\n}\n\nfunction materializeKnowledgeGraph(assertions: readonly KnowledgeAssertion[]): {\n\treadonly entities: readonly KnowledgeGraphEntity[];\n\treadonly relations: readonly KnowledgeGraphRelation[];\n\treadonly topics: readonly KnowledgeGraphTopic[];\n\treadonly index: KnowledgeGraphIndex;\n} {\n\tconst entityAssertions = new Map<\n\t\tFactId,\n\t\t{\n\t\t\ttype?: string;\n\t\t\tassertionIds: Set<FactId>;\n\t\t\tsubjectAssertionIds: Set<FactId>;\n\t\t\tobjectAssertionIds: Set<FactId>;\n\t\t}\n\t>();\n\tconst topics = new Map<FactId, { assertionIds: Set<FactId>; entityIds: Set<FactId> }>();\n\tconst relations: KnowledgeGraphRelation[] = [];\n\tfor (const assertion of assertions) {\n\t\tconst subject = touchEntity(entityAssertions, assertion.subject.id, assertion.subject.type);\n\t\tsubject.assertionIds.add(assertion.id);\n\t\tsubject.subjectAssertionIds.add(assertion.id);\n\t\tlet topic = topics.get(assertion.predicate);\n\t\tif (topic === undefined) {\n\t\t\ttopic = { assertionIds: new Set(), entityIds: new Set() };\n\t\t\ttopics.set(assertion.predicate, topic);\n\t\t}\n\t\ttopic.assertionIds.add(assertion.id);\n\t\ttopic.entityIds.add(assertion.subject.id);\n\t\tif (assertion.object.kind === \"entity\") {\n\t\t\tconst object = touchEntity(entityAssertions, assertion.object.id, assertion.object.type);\n\t\t\tobject.assertionIds.add(assertion.id);\n\t\t\tobject.objectAssertionIds.add(assertion.id);\n\t\t\ttopic.entityIds.add(assertion.object.id);\n\t\t}\n\t\trelations.push(\n\t\t\tObject.freeze({\n\t\t\t\tassertionId: assertion.id,\n\t\t\t\tsubject: assertion.subject,\n\t\t\t\tpredicate: assertion.predicate,\n\t\t\t\tobject: assertion.object,\n\t\t\t\t...(assertion.confidence === undefined ? {} : { confidence: assertion.confidence }),\n\t\t\t\tsources: Object.freeze([...(assertion.sources ?? [])]),\n\t\t\t\t...(assertion.provenance === undefined ? {} : { provenance: assertion.provenance }),\n\t\t\t}),\n\t\t);\n\t}\n\tconst entities = [...entityAssertions.entries()].map(([id, entity]) =>\n\t\tObject.freeze({\n\t\t\tid,\n\t\t\t...(entity.type === undefined ? {} : { type: entity.type }),\n\t\t\tassertionIds: freezeSortedSet(entity.assertionIds),\n\t\t\tsubjectAssertionIds: freezeSortedSet(entity.subjectAssertionIds),\n\t\t\tobjectAssertionIds: freezeSortedSet(entity.objectAssertionIds),\n\t\t}),\n\t);\n\tentities.sort((a, b) => compareString(a.id, b.id));\n\trelations.sort((a, b) => compareString(a.assertionId, b.assertionId));\n\tconst topicFacts = [...topics.entries()].map(([predicate, topic]) =>\n\t\tObject.freeze({\n\t\t\tpredicate,\n\t\t\tassertionIds: freezeSortedSet(topic.assertionIds),\n\t\t\tentityIds: freezeSortedSet(topic.entityIds),\n\t\t}),\n\t);\n\ttopicFacts.sort((a, b) => compareString(a.predicate, b.predicate));\n\tconst index: KnowledgeGraphIndex = Object.freeze({\n\t\tassertionIds: Object.freeze(assertions.map((assertion) => assertion.id).sort(compareString)),\n\t\tentityIds: Object.freeze(entities.map((entity) => entity.id)),\n\t\trelationIds: Object.freeze(relations.map((relation) => relation.assertionId)),\n\t\tpredicates: Object.freeze(topicFacts.map((topic) => topic.predicate)),\n\t});\n\treturn {\n\t\tentities: Object.freeze(entities),\n\t\trelations: Object.freeze(relations),\n\t\ttopics: Object.freeze(topicFacts),\n\t\tindex,\n\t};\n}\n\nfunction touchEntity(\n\tentities: Map<\n\t\tFactId,\n\t\t{\n\t\t\ttype?: string;\n\t\t\tassertionIds: Set<FactId>;\n\t\t\tsubjectAssertionIds: Set<FactId>;\n\t\t\tobjectAssertionIds: Set<FactId>;\n\t\t}\n\t>,\n\tid: FactId,\n\ttype?: string,\n) {\n\tlet entity = entities.get(id);\n\tif (entity === undefined) {\n\t\tentity = {\n\t\t\t...(type === undefined ? {} : { type }),\n\t\t\tassertionIds: new Set(),\n\t\t\tsubjectAssertionIds: new Set(),\n\t\t\tobjectAssertionIds: new Set(),\n\t\t};\n\t\tentities.set(id, entity);\n\t} else if (entity.type === undefined && type !== undefined) {\n\t\tentity.type = type;\n\t}\n\treturn entity;\n}\n\nfunction emptyKnowledgeGraphIndex(): KnowledgeGraphIndex {\n\treturn Object.freeze({\n\t\tassertionIds: Object.freeze([]),\n\t\tentityIds: Object.freeze([]),\n\t\trelationIds: Object.freeze([]),\n\t\tpredicates: Object.freeze([]),\n\t});\n}\n\nfunction snapshotSubject(subject: KnowledgeAssertionSubject): KnowledgeAssertionSubject {\n\treturn Object.freeze({\n\t\tid: subject.id,\n\t\t...(subject.type === undefined ? {} : { type: subject.type }),\n\t});\n}\n\nfunction snapshotObject(object: KnowledgeAssertionObject): KnowledgeAssertionObject {\n\treturn object.kind === \"entity\"\n\t\t? Object.freeze({\n\t\t\t\tkind: \"entity\",\n\t\t\t\tid: object.id,\n\t\t\t\t...(object.type === undefined ? {} : { type: object.type }),\n\t\t\t})\n\t\t: Object.freeze({\n\t\t\t\tkind: \"value\",\n\t\t\t\tvalue: object.value,\n\t\t\t\t...(object.valueType === undefined ? {} : { valueType: object.valueType }),\n\t\t\t});\n}\n\nfunction isKnowledgeSubject(value: unknown): value is KnowledgeAssertionSubject {\n\treturn (\n\t\tisPlainObject(value) &&\n\t\tisNonEmptyString(value.id) &&\n\t\t(value.type === undefined || isNonEmptyString(value.type))\n\t);\n}\n\nfunction isKnowledgeObject(value: unknown): value is KnowledgeAssertionObject {\n\tif (!isPlainObject(value)) return false;\n\tif (value.kind === \"entity\") {\n\t\treturn isNonEmptyString(value.id) && (value.type === undefined || isNonEmptyString(value.type));\n\t}\n\tif (value.kind !== \"value\") return false;\n\treturn (\n\t\tisStrictJsonValue(value.value) &&\n\t\t(value.valueType === undefined || isNonEmptyString(value.valueType))\n\t);\n}\n\nfunction isStrictJsonValue(value: unknown): boolean {\n\tif (value === null || typeof value === \"string\" || typeof value === \"boolean\") return true;\n\tif (typeof value === \"number\") return Number.isFinite(value);\n\tif (Array.isArray(value)) {\n\t\tfor (let i = 0; i < value.length; i += 1) {\n\t\t\tif (!Object.hasOwn(value, i) || !isStrictJsonValue(value[i])) return false;\n\t\t}\n\t\treturn true;\n\t}\n\tif (!isPlainObject(value)) return false;\n\tfor (const key of Object.keys(value)) {\n\t\tif (!isStrictJsonValue(value[key])) return false;\n\t}\n\treturn Object.getOwnPropertySymbols(value).length === 0;\n}\n\nfunction freezeSortedSet(value: ReadonlySet<FactId>): readonly FactId[] {\n\treturn Object.freeze([...value].sort(compareString));\n}\n\nfunction rankFragments<T>(\n\tfragments: readonly MemoryFragment<T>[],\n\tquery: MemoryRetrievalQuery,\n): readonly MemoryFragment<T>[] {\n\tif (query.vector === undefined) return filterMemoryFragments(fragments, query);\n\tconst ranked = fragments.filter((fragment) => memoryFragmentMatchesQuery(fragment, query));\n\tranked.sort((a, b) => {\n\t\tconst vectorDelta = vectorScore(b, query) - vectorScore(a, query);\n\t\tif (vectorDelta !== 0) return vectorDelta;\n\t\tconst confidenceDelta = b.confidence - a.confidence;\n\t\tif (confidenceDelta !== 0) return confidenceDelta;\n\t\treturn compareBigIntDesc(a.tNs, b.tNs);\n\t});\n\treturn query.limit === undefined ? ranked : ranked.slice(0, Math.max(0, query.limit));\n}\n\nfunction vectorScore(fragment: MemoryFragment, query: MemoryRetrievalQuery): number {\n\tif (query.vector === undefined || fragment.embedding === undefined) return 0;\n\treturn cosineSimilarity(query.vector, fragment.embedding);\n}\n\nfunction statusState(\n\terrors: readonly Omit<MemoryRetrievalError, \"cursor\">[],\n\tresultCount: number,\n): MemoryRetrievalStatusState {\n\tif (errors.some((error) => !isRecoverableFragmentError(error))) return \"error\";\n\tif (errors.length > 0) return \"partial\";\n\treturn resultCount > 0 ? \"ready\" : \"empty\";\n}\n\nfunction isRecoverableFragmentError(error: Omit<MemoryRetrievalError, \"cursor\">): boolean {\n\treturn error.code === \"invalid-fragment\" || error.code === \"duplicate-fragment-id\";\n}\n\nfunction indexById<T>(\n\tfragments: readonly MemoryFragment<T>[],\n): Readonly<Record<FactId, MemoryFragment<T>>> {\n\tconst byId = Object.create(null) as Record<FactId, MemoryFragment<T>>;\n\tfor (const fragment of fragments) byId[fragment.id] = fragment;\n\treturn Object.freeze(byId);\n}\n\nfunction isFiniteVector(value: unknown): value is readonly number[] {\n\tif (!Array.isArray(value)) return false;\n\tfor (let i = 0; i < value.length; i += 1) {\n\t\tif (!Object.hasOwn(value, i) || !Number.isFinite(value[i])) return false;\n\t}\n\treturn true;\n}\n\nfunction validateMemoryRetrievalQuery(value: unknown): MemoryRetrievalQueryValidation {\n\ttry {\n\t\treturn validateMemoryRetrievalQueryInner(value);\n\t} catch (error) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\tquery: {},\n\t\t\terrors: [\n\t\t\t\t{\n\t\t\t\t\tcode: \"invalid-query\",\n\t\t\t\t\tmessage: `memoryRetrievalBundle: query access failed: ${errorMessage(error)}`,\n\t\t\t\t\tfragment: value,\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\t}\n}\n\nfunction validateMemoryRetrievalQueryInner(value: unknown): MemoryRetrievalQueryValidation {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n\t\treturn invalidQuery(value, \"memoryRetrievalBundle: query must be an object\");\n\t}\n\tconst query = value as Partial<MemoryRetrievalQuery>;\n\tconst errors: Omit<MemoryRetrievalError, \"cursor\">[] = [];\n\tif (\n\t\tquery.tags !== undefined &&\n\t\t!isDenseArrayOf(query.tags, (tag): tag is string => typeof tag === \"string\")\n\t) {\n\t\terrors.push({\n\t\t\tcode: \"invalid-query\",\n\t\t\tmessage: \"memoryRetrievalBundle: query.tags must be a readonly string array\",\n\t\t\tfragment: value,\n\t\t\tvalidationErrors: [\"tags must be a readonly string array\"],\n\t\t});\n\t}\n\tif (query.asOf !== undefined && typeof query.asOf !== \"bigint\") {\n\t\terrors.push({\n\t\t\tcode: \"invalid-query\",\n\t\t\tmessage: \"memoryRetrievalBundle: query.asOf must be a bigint\",\n\t\t\tfragment: value,\n\t\t\tvalidationErrors: [\"asOf must be a bigint when present\"],\n\t\t});\n\t}\n\tif (\n\t\tquery.minConfidence !== undefined &&\n\t\t(!Number.isFinite(query.minConfidence) || query.minConfidence < 0 || query.minConfidence > 1)\n\t) {\n\t\terrors.push({\n\t\t\tcode: \"invalid-query\",\n\t\t\tmessage: \"memoryRetrievalBundle: query.minConfidence must be a finite number in [0, 1]\",\n\t\t\tfragment: value,\n\t\t\tvalidationErrors: [\"minConfidence must be a finite number in [0, 1]\"],\n\t\t});\n\t}\n\tif (query.limit !== undefined && (!Number.isSafeInteger(query.limit) || query.limit < 0)) {\n\t\terrors.push({\n\t\t\tcode: \"invalid-query\",\n\t\t\tmessage: \"memoryRetrievalBundle: query.limit must be a non-negative safe integer\",\n\t\t\tfragment: value,\n\t\t\tvalidationErrors: [\"limit must be a non-negative safe integer\"],\n\t\t});\n\t}\n\tif (query.vector !== undefined && !isFiniteVector(query.vector)) {\n\t\terrors.push({\n\t\t\tcode: \"invalid-query-vector\",\n\t\t\tmessage: \"memoryRetrievalBundle: query.vector must be a finite number array\",\n\t\t\tfragment: value,\n\t\t\tvalidationErrors: [\"vector must be a finite number array\"],\n\t\t});\n\t}\n\tif (errors.length > 0) return { ok: false, query: {}, errors };\n\treturn { ok: true, query: snapshotQuery(query), errors };\n}\n\nfunction invalidQuery(value: unknown, message: string): MemoryRetrievalQueryValidation {\n\treturn {\n\t\tok: false,\n\t\tquery: {},\n\t\terrors: [\n\t\t\t{\n\t\t\t\tcode: \"invalid-query\",\n\t\t\t\tmessage,\n\t\t\t\tfragment: value,\n\t\t\t},\n\t\t],\n\t};\n}\n\nfunction snapshotQuery(query: Partial<MemoryRetrievalQuery>): MemoryRetrievalQuery {\n\treturn Object.freeze({\n\t\t...(query.tags === undefined ? {} : { tags: Object.freeze([...query.tags]) }),\n\t\t...(query.asOf === undefined ? {} : { asOf: query.asOf }),\n\t\t...(query.minConfidence === undefined ? {} : { minConfidence: query.minConfidence }),\n\t\t...(query.limit === undefined ? {} : { limit: query.limit }),\n\t\t...(query.vector === undefined ? {} : { vector: Object.freeze([...query.vector]) }),\n\t});\n}\n\nfunction safeArrayLength(value: readonly unknown[]): number | undefined {\n\ttry {\n\t\treturn value.length;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction validateAndSnapshotFragment<T>(\n\trawFragments: readonly unknown[],\n\tindex: number,\n): FragmentValidationResult<T> {\n\tlet raw: unknown;\n\ttry {\n\t\traw = rawFragments[index];\n\t\tconst validation = validateMemoryFragment(raw);\n\t\tif (!validation.ok) {\n\t\t\treturn {\n\t\t\t\terror: {\n\t\t\t\t\tcode: \"invalid-fragment\",\n\t\t\t\t\tmessage: \"memoryRetrievalBundle: invalid memory fragment\",\n\t\t\t\t\tindex,\n\t\t\t\t\tfragment: raw,\n\t\t\t\t\tvalidationErrors: Object.freeze([...validation.errors]),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\treturn { fragment: snapshotFragment(raw as MemoryFragment<T>) };\n\t} catch (error) {\n\t\treturn {\n\t\t\terror: {\n\t\t\t\tcode: \"invalid-fragment\",\n\t\t\t\tmessage: `memoryRetrievalBundle: fragment access failed: ${errorMessage(error)}`,\n\t\t\t\tindex,\n\t\t\t\tfragment: raw,\n\t\t\t\tvalidationErrors: Object.freeze([\"fragment access failed\"]),\n\t\t\t},\n\t\t};\n\t}\n}\n\nfunction snapshotFragment<T>(fragment: MemoryFragment<T>): MemoryFragment<T> {\n\treturn Object.freeze({\n\t\tid: fragment.id,\n\t\tpayload: fragment.payload,\n\t\ttNs: fragment.tNs,\n\t\t...(fragment.validFrom === undefined ? {} : { validFrom: fragment.validFrom }),\n\t\t...(fragment.validTo === undefined ? {} : { validTo: fragment.validTo }),\n\t\tconfidence: fragment.confidence,\n\t\ttags: Object.freeze([...fragment.tags]),\n\t\tsources: Object.freeze([...fragment.sources]),\n\t\t...(fragment.embedding === undefined\n\t\t\t? {}\n\t\t\t: { embedding: Object.freeze([...fragment.embedding]) }),\n\t\t...(fragment.parentFragmentId === undefined\n\t\t\t? {}\n\t\t\t: { parentFragmentId: fragment.parentFragmentId }),\n\t\t...(fragment.provenance === undefined ? {} : { provenance: fragment.provenance }),\n\t});\n}\n\nfunction isDenseArrayOf<T>(value: unknown, predicate: (item: unknown) => item is T): value is T[] {\n\tif (!Array.isArray(value)) return false;\n\tfor (let i = 0; i < value.length; i += 1) {\n\t\tif (!Object.hasOwn(value, i) || !predicate(value[i])) return false;\n\t}\n\treturn true;\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n\treturn value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n\treturn typeof value === \"string\" && value.length > 0;\n}\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction compareString(a: string, b: string): number {\n\treturn a < b ? -1 : a > b ? 1 : 0;\n}\n\nfunction compareBigIntDesc(a: bigint, b: bigint): number {\n\tif (a === b) return 0;\n\treturn a > b ? -1 : 1;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC+BO,SAAS,eAAe,OAAc,OAA2B,CAAC,GAAmB;AAC3F,QAAM,UAAU,MAAM,QAAQ;AAC9B,QAAM,YAAY,MAAM,SAAS;AACjC,QAAM,UAAU,IAAI,IAAI,UAAU,MAAM,IAAI,CAAC,SAAS,KAAK,EAAE,CAAC;AAC9D,aAAW,MAAM,OAAO,KAAK,QAAQ,KAAK,EAAG,SAAQ,IAAI,EAAE;AAE3D,QAAM,WAA2D,CAAC;AAClE,QAAM,WAAiC,CAAC;AACxC,aAAW,QAAQ,CAAC,GAAG,OAAO,EAAE,KAAK,GAAG;AACvC,UAAM,cAAc,QAAQ,MAAM,IAAI;AACtC,QAAI,gBAAgB,OAAW;AAC/B,aAAS,YAAY,MAAM,KAAK,SAAS,YAAY,MAAM,KAAK,KAAK;AACrE,aAAS,KAAK;AAAA,MACb;AAAA,MACA,SAAS,YAAY;AAAA,MACrB,iBAAiB,YAAY;AAAA,MAC7B,gBAAgB,YAAY;AAAA,MAC5B,QAAQ,YAAY;AAAA,IACrB,CAAC;AAAA,EACF;AACA,WAAS,KAAK,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,cAAc,EAAE,IAAI,CAAC;AAC7E,SAAO;AAAA,IACN,WAAW,QAA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AAI,IAAI;AACjC;AAEA,SAASC,mBAAkB,GAAW,GAAmB;AACxD,MAAI,MAAM,EAAG,QAAO;AACpB,SAAO,IAAI,IAAI,KAAK;AACrB;","names":["isDenseArrayOf","compareBigIntDesc"]}
|
|
1
|
+
{"version":3,"sources":["../../src/patterns/index.ts","../../src/protocol/messages.ts","../../src/ctx/types.ts","../../src/messaging/utils.ts","../../src/messaging/event-message.ts","../../src/patterns/event-flow.ts","../../src/patterns/inspection.ts","../../src/patterns/semantic-memory.ts","../../src/patterns/semantic-memory-graph-utils.ts","../../src/patterns/semantic-memory-graph.ts"],"sourcesContent":["/**\n * Horizontal reusable graph patterns.\n *\n * Former preset material lands here only when it is not a vertical solution\n * and has been re-derived onto clean-slate APIs.\n */\n\nexport {\n\ttype EventFlowAuditRecord,\n\ttype EventFlowBundle,\n\ttype EventFlowHighWater,\n\ttype EventFlowOptions,\n\ttype EventFlowProjectionBundle,\n\ttype EventFlowProjectionFrame,\n\ttype EventFlowProjectionOptions,\n\ttype EventFlowProjectionStatus,\n\ttype EventFlowRecord,\n\ttype EventFlowSource,\n\ttype EventFlowSourceHighWater,\n\ttype EventFlowSourceInput,\n\ttype EventFlowSourceRef,\n\ttype EventFlowStatus,\n\teventFlow,\n\teventFlowProjection,\n} from \"./event-flow.js\";\nexport {\n\ttype ProfileSummary,\n\ttype ProfileSummaryNode,\n\tprofileSummary,\n} from \"./inspection.js\";\nexport {\n\ttype AdmissionFilter,\n\ttype AdmissionScore3DOptions,\n\ttype AdmissionScoredOptions,\n\ttype AdmissionScores,\n\ttype AdmissionThresholds,\n\tadmissionFilter3D,\n\tadmissionScored,\n\ttype CollectionEntry,\n\ttype CollectionScoreFn,\n\tcosineSimilarity,\n\ttype DecayPolicy,\n\ttype FactId,\n\ttype FactStore,\n\tfilterMemoryFragments,\n\tisMemoryFragment,\n\ttype KnowledgeAssertion,\n\ttype KnowledgeAssertionObject,\n\ttype KnowledgeAssertionStrictJsonValue,\n\ttype KnowledgeAssertionSubject,\n\ttype MemoryAnswer,\n\ttype MemoryFragment,\n\ttype MemoryFragmentValidation,\n\ttype MemoryQuery,\n\tmemoryFragmentMatchesQuery,\n\tmemoryFragmentValidAt,\n\ttype OutcomeSignal,\n\ttype RankedCollectionEntry,\n\ttype RetrievalEntry,\n\ttype RetrievalQuery,\n\ttype RetrievalTrace,\n\ttype ScoringPolicy,\n\ttype ShardByTenantConfig,\n\ttype ShardByTenantOptions,\n\ttype ShardKey,\n\ttype StoreReadHandle,\n\tshardByTenant,\n\ttype VectorSearchResult,\n\tvalidateMemoryFragment,\n} from \"./semantic-memory.js\";\nexport {\n\ttype KnowledgeGraphCursor,\n\ttype KnowledgeGraphEntity,\n\ttype KnowledgeGraphError,\n\ttype KnowledgeGraphErrorCode,\n\ttype KnowledgeGraphIndex,\n\ttype KnowledgeGraphPolicy,\n\ttype KnowledgeGraphReducerBundle,\n\ttype KnowledgeGraphReducerBundleOptions,\n\ttype KnowledgeGraphRelation,\n\ttype KnowledgeGraphSnapshot,\n\ttype KnowledgeGraphStatus,\n\ttype KnowledgeGraphStatusState,\n\ttype KnowledgeGraphTopic,\n\tknowledgeGraphReducerBundle,\n\ttype MemoryRetrievalBundle,\n\ttype MemoryRetrievalBundleOptions,\n\ttype MemoryRetrievalCursor,\n\ttype MemoryRetrievalError,\n\ttype MemoryRetrievalErrorCode,\n\ttype MemoryRetrievalFact,\n\ttype MemoryRetrievalIndex,\n\ttype MemoryRetrievalQuery,\n\ttype MemoryRetrievalSnapshot,\n\ttype MemoryRetrievalStatus,\n\ttype MemoryRetrievalStatusState,\n\tmemoryRetrievalBundle,\n} from \"./semantic-memory-graph.js\";\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 { Node } from \"../node/node.js\";\nimport type { PullDemand } from \"../protocol/messages.js\";\nimport type { MessageBusCommand } from \"./types.js\";\n\nexport function pullParams<T>(pull: PullDemand | undefined): T {\n\treturn (isObjectRecord(pull?.params) ? pull.params : {}) as T;\n}\n\nexport function publishCommand<T extends MessageBusCommand>(\n\tcommandNode: Node<MessageBusCommand>,\n\tcommand: T,\n): T {\n\tcommandNode.down([[\"DATA\", command]]);\n\treturn command;\n}\n\nexport function makeTopicState(): {\n\tclosed: boolean;\n\theadSeq: number;\n\tnextSeq: number;\n\tmessages: [];\n} {\n\treturn { closed: false, headSeq: 1, nextSeq: 1, messages: [] };\n}\n\nexport function uniqueTopics(topics: readonly string[]): readonly string[] {\n\tconst unique = [...new Set(topics)];\n\tif (unique.length !== topics.length) throw new Error(\"messageBus: duplicate topic\");\n\tfor (const topic of unique) assertTopicKey(topic, \"messageBus\");\n\treturn Object.freeze(unique.sort());\n}\n\nexport function assertTopicKey(topic: string, owner: string): void {\n\tconst error = validateTopicKey(topic, owner);\n\tif (error !== undefined) throw new Error(error);\n}\n\nexport function validateTopicKey(topic: string, owner: string): string | undefined {\n\tif (typeof topic !== \"string\" || topic.length === 0)\n\t\treturn `${owner}: topic must be a non-empty string`;\n\treturn undefined;\n}\n\nexport function assertNonEmpty(value: string, owner: string): void {\n\tif (typeof value !== \"string\" || value.length === 0)\n\t\tthrow new Error(`${owner}: must be a non-empty string`);\n}\n\nexport function positiveLimit(limit: number | undefined): number {\n\tif (limit === undefined) return 100;\n\tif (!Number.isInteger(limit) || limit < 1)\n\t\tthrow new Error(\"messageBus: limit must be a positive integer\");\n\treturn limit;\n}\n\nexport function isPositiveSeq(value: unknown): value is number {\n\treturn Number.isInteger(value) && (value as number) >= 1;\n}\n\nexport function isObjectRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nexport function commandTopic(command: unknown): string | undefined {\n\treturn isObjectRecord(command) && typeof command.topic === \"string\" ? command.topic : undefined;\n}\n\nexport function commandIdOf(command: unknown): string | undefined {\n\treturn isObjectRecord(command) && typeof command.commandId === \"string\"\n\t\t? command.commandId\n\t\t: undefined;\n}\n\nexport function idempotencyKey(topic: string, key: string): string {\n\treturn `${topic}\\u0000${key}`;\n}\n","import type { DataIssue } from \"../data/index.js\";\nimport type { EventMessage, EventMessageOptions } from \"./types.js\";\nimport { assertNonEmpty, isObjectRecord } from \"./utils.js\";\n\nexport function eventMessage<T>(\n\ttype: string,\n\tpayload: T,\n\topts: EventMessageOptions,\n): EventMessage<T> {\n\tassertNonEmpty(type, \"eventMessage.type\");\n\tassertNonEmpty(opts.id, \"eventMessage.id\");\n\treturn {\n\t\tid: opts.id,\n\t\ttype,\n\t\tpayload,\n\t\t...(opts.key === undefined ? {} : { key: opts.key }),\n\t\t...(opts.subjectId === undefined ? {} : { subjectId: opts.subjectId }),\n\t\t...(opts.correlationId === undefined ? {} : { correlationId: opts.correlationId }),\n\t\t...(opts.causationId === undefined ? {} : { causationId: opts.causationId }),\n\t\t...(opts.occurredAtMs === undefined ? {} : { occurredAtMs: opts.occurredAtMs }),\n\t\t...(opts.actor === undefined ? {} : { actor: opts.actor }),\n\t\t...(opts.evidenceRefs === undefined ? {} : { evidenceRefs: opts.evidenceRefs }),\n\t\t...(opts.schema === undefined ? {} : { schema: opts.schema }),\n\t\t...(opts.metadata === undefined ? {} : { metadata: opts.metadata }),\n\t};\n}\n\nexport function isEventMessage(value: unknown): value is EventMessage {\n\treturn eventMessageIssue(value) === undefined;\n}\n\nexport function eventMessageIssue(value: unknown): DataIssue | undefined {\n\tif (!isObjectRecord(value)) {\n\t\treturn eventIssue(\"event message must be an object\");\n\t}\n\tif (typeof value.id !== \"string\" || value.id.length === 0) {\n\t\treturn eventIssue(\"event message id must be a non-empty string\");\n\t}\n\tif (typeof value.type !== \"string\" || value.type.length === 0) {\n\t\treturn eventIssue(\"event message type must be a non-empty string\");\n\t}\n\tif (!(\"payload\" in value)) {\n\t\treturn eventIssue(\"event message payload field is required\");\n\t}\n\treturn undefined;\n}\n\nfunction eventIssue(message: string): DataIssue {\n\treturn {\n\t\tkind: \"issue\",\n\t\tcode: \"malformed-event-message\",\n\t\tmessage,\n\t\tseverity: \"error\",\n\t\tsource: \"messageBus.eventMessage\",\n\t};\n}\n","/**\n * Event-flow projector helpers (D326/D329/D331).\n *\n * eventFlow consumes declared graph sources that emit EventMessage or\n * MessageEnvelope<EventMessage>. It records projection facts and high-water over\n * source coordinates; it does not own topics, subscriptions, cursors, retention,\n * ack/seek/close, queues, workers, or dead-letter policy.\n */\n\nimport { depBatch } from \"../ctx/types.js\";\nimport type { DataIssue } from \"../data/index.js\";\nimport type { Graph } from \"../graph/graph.js\";\nimport type { EventMessage, MessageEnvelope } from \"../messaging/index.js\";\nimport { eventMessageIssue } from \"../messaging/index.js\";\nimport type { Node } from \"../node/node.js\";\n\nexport interface EventFlowSource<T = unknown> {\n\treadonly source: string;\n\treadonly node: Node<EventMessage<T> | MessageEnvelope<EventMessage<T>> | unknown>;\n}\n\nexport type EventFlowSourceInput<T = unknown> =\n\t| Node<EventMessage<T> | MessageEnvelope<EventMessage<T>> | unknown>\n\t| EventFlowSource<T>;\n\nexport interface EventFlowSourceRef {\n\treadonly source: string;\n\treadonly topic?: string;\n\treadonly seq?: number;\n\treadonly messageId?: string;\n\treadonly idempotencyKey?: string;\n}\n\nexport interface EventFlowRecord<T = unknown> {\n\treadonly recordSeq: number;\n\treadonly flowId: string;\n\treadonly event: EventMessage<T>;\n\treadonly source: EventFlowSourceRef;\n\treadonly observedAtMs: number;\n\treadonly correlationId?: string;\n\treadonly causationId?: string;\n}\n\nexport interface EventFlowStatus {\n\treadonly kind: \"recorded\" | \"rejected\" | \"projection-ready\" | \"projection-stale\";\n\treadonly flowId: string;\n\treadonly recordSeq?: number;\n\treadonly eventId?: string;\n\treadonly eventType?: string;\n\treadonly source?: EventFlowSourceRef;\n\treadonly issueCode?: string;\n\treadonly timestampMs: number;\n}\n\nexport interface EventFlowAuditRecord {\n\treadonly seq: number;\n\treadonly flowId: string;\n\treadonly outcome: \"recorded\" | \"rejected\";\n\treadonly eventId?: string;\n\treadonly eventType?: string;\n\treadonly issueCode?: string;\n\treadonly source?: EventFlowSourceRef;\n\treadonly highWater: EventFlowHighWater;\n\treadonly timestampMs: number;\n}\n\nexport interface EventFlowSourceHighWater {\n\treadonly source: string;\n\treadonly topic?: string;\n\treadonly seq?: number;\n\treadonly messageId?: string;\n\treadonly recordSeq: number;\n}\n\nexport interface EventFlowHighWater {\n\treadonly flowId: string;\n\treadonly recordSeq: number;\n\treadonly auditSeq: number;\n\treadonly sources: readonly EventFlowSourceHighWater[];\n}\n\nexport interface EventFlowOptions<T = unknown> {\n\treadonly flowId?: string;\n\treadonly name?: string;\n\treadonly sources: readonly EventFlowSourceInput<T>[];\n\treadonly now?: () => number;\n}\n\nexport interface EventFlowBundle<T = unknown> {\n\treadonly records: Node<EventFlowRecord<T>>;\n\treadonly status: Node<EventFlowStatus>;\n\treadonly issues: Node<DataIssue>;\n\treadonly audit: Node<EventFlowAuditRecord>;\n\treadonly highWater: Node<EventFlowHighWater>;\n}\n\nexport interface EventFlowProjectionFrame<TState> {\n\treadonly state: TState;\n\treadonly highWater: EventFlowHighWater;\n}\n\nexport interface EventFlowProjectionStatus {\n\treadonly kind: \"projected\" | \"rejected\";\n\treadonly projectionId: string;\n\treadonly recordSeq?: number;\n\treadonly issueCode?: string;\n\treadonly timestampMs: number;\n}\n\nexport interface EventFlowProjectionOptions<TState, TPayload = unknown> {\n\treadonly projectionId?: string;\n\treadonly name?: string;\n\treadonly initial: TState;\n\treadonly reduce: (state: TState, record: EventFlowRecord<TPayload>) => TState;\n\treadonly now?: () => number;\n}\n\nexport interface EventFlowProjectionBundle<TState> {\n\treadonly snapshot: Node<TState>;\n\treadonly frames: Node<EventFlowProjectionFrame<TState>>;\n\treadonly status: Node<EventFlowProjectionStatus>;\n\treadonly issues: Node<DataIssue>;\n\treadonly highWater: Node<EventFlowHighWater>;\n}\n\ntype EventFlowRuntimeFact<T = unknown> =\n\t| { readonly kind: \"record\"; readonly record: EventFlowRecord<T> }\n\t| { readonly kind: \"status\"; readonly status: EventFlowStatus }\n\t| { readonly kind: \"issue\"; readonly issue: DataIssue }\n\t| { readonly kind: \"audit\"; readonly audit: EventFlowAuditRecord }\n\t| { readonly kind: \"high-water\"; readonly highWater: EventFlowHighWater };\n\ninterface EventFlowRuntimeState {\n\trecordSeq: number;\n\tauditSeq: number;\n\thighWater: Map<string, EventFlowSourceHighWater>;\n}\n\nexport function eventFlow<T = unknown>(\n\tgraph: Graph,\n\topts: EventFlowOptions<T>,\n): EventFlowBundle<T> {\n\tconst name = opts.name ?? opts.flowId ?? \"eventFlow\";\n\tconst flowId = opts.flowId ?? name;\n\tconst now = opts.now ?? Date.now;\n\tconst sources = normalizeSources(opts.sources);\n\tconst runtime = graph.node<EventFlowRuntimeFact<T>>(\n\t\tsources.map((source) => source.node),\n\t\t(ctx) => {\n\t\t\tconst state =\n\t\t\t\tctx.state.get<EventFlowRuntimeState>() ??\n\t\t\t\t({\n\t\t\t\t\trecordSeq: 0,\n\t\t\t\t\tauditSeq: 0,\n\t\t\t\t\thighWater: new Map(),\n\t\t\t\t} satisfies EventFlowRuntimeState);\n\t\t\tctx.state.persist(true);\n\t\t\tfor (let i = 0; i < sources.length; i++) {\n\t\t\t\tconst source = sources[i];\n\t\t\t\tfor (const raw of depBatch(ctx, i) ?? []) {\n\t\t\t\t\treduceEventSource(raw, source.source, flowId, now(), state, (fact) =>\n\t\t\t\t\t\tctx.down([[\"DATA\", fact as EventFlowRuntimeFact<T>]]),\n\t\t\t\t\t);\n\t\t\t\t}\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: \"eventFlowRuntime\",\n\t\t\tmeta: { flowId, sources: sources.map((source) => source.source) },\n\t\t\tpartial: true,\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\treturn {\n\t\trecords: runtimeProjection(graph, runtime, \"record\", `${name}/records`, \"eventFlowRecords\"),\n\t\tstatus: runtimeProjection(graph, runtime, \"status\", `${name}/status`, \"eventFlowStatus\"),\n\t\tissues: runtimeProjection(graph, runtime, \"issue\", `${name}/issues`, \"eventFlowIssues\"),\n\t\taudit: runtimeProjection(graph, runtime, \"audit\", `${name}/audit`, \"eventFlowAudit\"),\n\t\thighWater: runtimeProjection(\n\t\t\tgraph,\n\t\t\truntime,\n\t\t\t\"high-water\",\n\t\t\t`${name}/highWater`,\n\t\t\t\"eventFlowHighWater\",\n\t\t),\n\t};\n}\n\nexport function eventFlowProjection<TState, TPayload = unknown>(\n\tgraph: Graph,\n\tflowOrRecords: EventFlowBundle<TPayload> | Node<EventFlowRecord<TPayload>>,\n\topts: EventFlowProjectionOptions<TState, TPayload>,\n): EventFlowProjectionBundle<TState> {\n\tconst records = isEventFlowBundle(flowOrRecords) ? flowOrRecords.records : flowOrRecords;\n\tconst name = opts.name ?? opts.projectionId ?? \"eventFlowProjection\";\n\tconst projectionId = opts.projectionId ?? name;\n\tconst now = opts.now ?? Date.now;\n\tconst runtime = graph.node<\n\t\t| { readonly kind: \"frame\"; readonly frame: EventFlowProjectionFrame<TState> }\n\t\t| { readonly kind: \"status\"; readonly status: EventFlowProjectionStatus }\n\t\t| { readonly kind: \"issue\"; readonly issue: DataIssue }\n\t\t| { readonly kind: \"high-water\"; readonly highWater: EventFlowHighWater }\n\t>(\n\t\t[records],\n\t\t(ctx) => {\n\t\t\tconst state = ctx.state.get<{\n\t\t\t\tvalue: TState;\n\t\t\t\thighWater: EventFlowHighWater;\n\t\t\t\tsourceHighWater: Map<string, EventFlowSourceHighWater>;\n\t\t\t}>() ?? {\n\t\t\t\tvalue: opts.initial,\n\t\t\t\thighWater: emptyHighWater(projectionId),\n\t\t\t\tsourceHighWater: new Map(),\n\t\t\t};\n\t\t\tctx.state.persist(true);\n\t\t\tfor (const raw of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst record = raw as EventFlowRecord<TPayload>;\n\t\t\t\ttry {\n\t\t\t\t\tstate.value = opts.reduce(state.value, record);\n\t\t\t\t\tstate.highWater = projectionHighWater(projectionId, record, state.sourceHighWater);\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\"DATA\", { kind: \"frame\", frame: { state: state.value, highWater: state.highWater } }],\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tkind: \"status\",\n\t\t\t\t\t\t\t\tstatus: {\n\t\t\t\t\t\t\t\t\tkind: \"projected\",\n\t\t\t\t\t\t\t\t\tprojectionId,\n\t\t\t\t\t\t\t\t\trecordSeq: record.recordSeq,\n\t\t\t\t\t\t\t\t\ttimestampMs: now(),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\t[\"DATA\", { kind: \"high-water\", highWater: state.highWater }],\n\t\t\t\t\t]);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconst issue = dataIssue(\n\t\t\t\t\t\t\"event-flow-projection-threw\",\n\t\t\t\t\t\terror instanceof Error ? error.message : \"eventFlowProjection reducer threw\",\n\t\t\t\t\t\t{ projectionId, record },\n\t\t\t\t\t);\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\"DATA\", { kind: \"issue\", issue }],\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tkind: \"status\",\n\t\t\t\t\t\t\t\tstatus: {\n\t\t\t\t\t\t\t\t\tkind: \"rejected\",\n\t\t\t\t\t\t\t\t\tprojectionId,\n\t\t\t\t\t\t\t\t\trecordSeq: record.recordSeq,\n\t\t\t\t\t\t\t\t\tissueCode: issue.code,\n\t\t\t\t\t\t\t\t\ttimestampMs: now(),\n\t\t\t\t\t\t\t\t},\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}\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: \"eventFlowProjectionRuntime\",\n\t\t\tmeta: { projectionId },\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\treturn {\n\t\tframes: projectionRuntime(\n\t\t\tgraph,\n\t\t\truntime,\n\t\t\t\"frame\",\n\t\t\t`${name}/frames`,\n\t\t\t\"eventFlowProjectionFrames\",\n\t\t),\n\t\tsnapshot: projectionRuntime(\n\t\t\tgraph,\n\t\t\truntime,\n\t\t\t\"frame\",\n\t\t\t`${name}/snapshot`,\n\t\t\t\"eventFlowProjectionSnapshot\",\n\t\t\t(fact) => (fact as { readonly frame: EventFlowProjectionFrame<TState> }).frame.state,\n\t\t),\n\t\tstatus: projectionRuntime(\n\t\t\tgraph,\n\t\t\truntime,\n\t\t\t\"status\",\n\t\t\t`${name}/status`,\n\t\t\t\"eventFlowProjectionStatus\",\n\t\t),\n\t\tissues: projectionRuntime(\n\t\t\tgraph,\n\t\t\truntime,\n\t\t\t\"issue\",\n\t\t\t`${name}/issues`,\n\t\t\t\"eventFlowProjectionIssues\",\n\t\t),\n\t\thighWater: projectionRuntime(\n\t\t\tgraph,\n\t\t\truntime,\n\t\t\t\"high-water\",\n\t\t\t`${name}/highWater`,\n\t\t\t\"eventFlowProjectionHighWater\",\n\t\t),\n\t};\n}\n\nfunction reduceEventSource<T>(\n\traw: unknown,\n\tsource: string,\n\tflowId: string,\n\ttimestampMs: number,\n\tstate: EventFlowRuntimeState,\n\temit: (fact: EventFlowRuntimeFact<T>) => void,\n): void {\n\tconst normalized = normalizeInput(raw, source);\n\tif (normalized.issue !== undefined) {\n\t\tconst status: EventFlowStatus = {\n\t\t\tkind: \"rejected\",\n\t\t\tflowId,\n\t\t\tsource: normalized.source,\n\t\t\tissueCode: normalized.issue.code,\n\t\t\ttimestampMs,\n\t\t};\n\t\tconst audit = auditRecord(flowId, state, \"rejected\", timestampMs, {\n\t\t\tsource: normalized.source,\n\t\t\tissueCode: normalized.issue.code,\n\t\t});\n\t\temit({ kind: \"issue\", issue: normalized.issue });\n\t\temit({ kind: \"status\", status });\n\t\temit({ kind: \"audit\", audit });\n\t\temit({ kind: \"high-water\", highWater: highWaterSnapshot(flowId, state) });\n\t\treturn;\n\t}\n\n\tconst recordSeq = ++state.recordSeq;\n\tconst record: EventFlowRecord<T> = {\n\t\trecordSeq,\n\t\tflowId,\n\t\tevent: normalized.event as EventMessage<T>,\n\t\tsource: normalized.source,\n\t\tobservedAtMs: timestampMs,\n\t\t...(normalized.event.correlationId === undefined\n\t\t\t? {}\n\t\t\t: { correlationId: normalized.event.correlationId }),\n\t\t...(normalized.event.causationId === undefined\n\t\t\t? {}\n\t\t\t: { causationId: normalized.event.causationId }),\n\t};\n\tstate.highWater.set(sourceKey(normalized.source), {\n\t\tsource: normalized.source.source,\n\t\t...(normalized.source.topic === undefined ? {} : { topic: normalized.source.topic }),\n\t\t...(normalized.source.seq === undefined ? {} : { seq: normalized.source.seq }),\n\t\tmessageId: normalized.event.id,\n\t\trecordSeq,\n\t});\n\tconst audit = auditRecord(flowId, state, \"recorded\", timestampMs, {\n\t\tsource: normalized.source,\n\t\teventId: normalized.event.id,\n\t\teventType: normalized.event.type,\n\t});\n\tconst highWater = highWaterSnapshot(flowId, state);\n\tconst status: EventFlowStatus = {\n\t\tkind: \"recorded\",\n\t\tflowId,\n\t\trecordSeq,\n\t\teventId: normalized.event.id,\n\t\teventType: normalized.event.type,\n\t\tsource: normalized.source,\n\t\ttimestampMs,\n\t};\n\temit({ kind: \"record\", record });\n\temit({ kind: \"status\", status });\n\temit({ kind: \"audit\", audit });\n\temit({ kind: \"high-water\", highWater });\n}\n\nfunction normalizeInput(\n\traw: unknown,\n\tsource: string,\n):\n\t| {\n\t\t\treadonly event: EventMessage;\n\t\t\treadonly source: EventFlowSourceRef;\n\t\t\treadonly issue?: undefined;\n\t }\n\t| { readonly source: EventFlowSourceRef; readonly issue: DataIssue } {\n\tconst envelope = messageEnvelopeOf(raw);\n\tconst value = envelope?.payload ?? raw;\n\tconst sourceRef: EventFlowSourceRef =\n\t\tenvelope === undefined\n\t\t\t? { source, ...(eventIdOf(value) === undefined ? {} : { messageId: eventIdOf(value) }) }\n\t\t\t: {\n\t\t\t\t\tsource,\n\t\t\t\t\ttopic: envelope.topic,\n\t\t\t\t\tseq: envelope.seq,\n\t\t\t\t\tmessageId: envelope.payload.id,\n\t\t\t\t\t...(envelope.idempotencyKey === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: { idempotencyKey: envelope.idempotencyKey }),\n\t\t\t\t};\n\tconst issue = eventMessageIssue(value);\n\tif (issue !== undefined) {\n\t\treturn {\n\t\t\tsource: sourceRef,\n\t\t\tissue: dataIssue(issue.code, issue.message, { source: sourceRef, value }),\n\t\t};\n\t}\n\treturn { event: value as EventMessage, source: sourceRef };\n}\n\nfunction messageEnvelopeOf(value: unknown): MessageEnvelope<EventMessage> | undefined {\n\tif (!isRecord(value)) return undefined;\n\tif (\n\t\ttypeof value.topic !== \"string\" ||\n\t\t!Number.isInteger(value.seq) ||\n\t\ttypeof value.timestampMs !== \"number\" ||\n\t\t!(\"payload\" in value)\n\t) {\n\t\treturn undefined;\n\t}\n\tconst payloadIssue = eventMessageIssue(value.payload);\n\treturn payloadIssue === undefined\n\t\t? (value as unknown as MessageEnvelope<EventMessage>)\n\t\t: undefined;\n}\n\nfunction normalizeSources<T>(\n\tsources: readonly EventFlowSourceInput<T>[],\n): readonly EventFlowSource[] {\n\tif (sources.length === 0) throw new Error(\"eventFlow: sources must be non-empty\");\n\treturn sources.map((source, index) => {\n\t\tif (isRecord(source) && \"node\" in source) {\n\t\t\tif (typeof source.source !== \"string\" || source.source.length === 0) {\n\t\t\t\tthrow new Error(\"eventFlow: source name must be non-empty\");\n\t\t\t}\n\t\t\treturn source as EventFlowSource;\n\t\t}\n\t\treturn { source: `source-${index}`, node: source as EventFlowSource[\"node\"] };\n\t});\n}\n\nfunction runtimeProjection<TOut, T>(\n\tgraph: Graph,\n\truntime: Node<EventFlowRuntimeFact<T>>,\n\tkind: EventFlowRuntimeFact<T>[\"kind\"],\n\tname: string,\n\tfactory: string,\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 EventFlowRuntimeFact<T>;\n\t\t\t\tif (typed.kind === kind) ctx.down([[\"DATA\", valueOfRuntimeFact(typed) as TOut]]);\n\t\t\t}\n\t\t},\n\t\t{ name, factory, completeWhenDepsComplete: false, errorWhenDepsError: false },\n\t);\n}\n\nfunction projectionRuntime<TOut, TFact extends { readonly kind: string }>(\n\tgraph: Graph,\n\truntime: Node<TFact>,\n\tkind: TFact[\"kind\"],\n\tname: string,\n\tfactory: string,\n\tmap: (fact: Extract<TFact, { readonly kind: typeof kind }>) => TOut = valueOfRuntimeFact as never,\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 TFact;\n\t\t\t\tif (typed.kind === kind) ctx.down([[\"DATA\", map(typed as never)]]);\n\t\t\t}\n\t\t},\n\t\t{ name, factory, completeWhenDepsComplete: false, errorWhenDepsError: false },\n\t);\n}\n\nfunction valueOfRuntimeFact(fact: { readonly kind: string }): unknown {\n\tif (\"record\" in fact) return fact.record;\n\tif (\"status\" in fact) return fact.status;\n\tif (\"issue\" in fact) return fact.issue;\n\tif (\"audit\" in fact) return fact.audit;\n\tif (\"highWater\" in fact) return fact.highWater;\n\tif (\"frame\" in fact) return fact.frame;\n\treturn undefined;\n}\n\nfunction auditRecord(\n\tflowId: string,\n\tstate: EventFlowRuntimeState,\n\toutcome: \"recorded\" | \"rejected\",\n\ttimestampMs: number,\n\topts: {\n\t\treadonly source?: EventFlowSourceRef;\n\t\treadonly eventId?: string;\n\t\treadonly eventType?: string;\n\t\treadonly issueCode?: string;\n\t},\n): EventFlowAuditRecord {\n\treturn {\n\t\tseq: ++state.auditSeq,\n\t\tflowId,\n\t\toutcome,\n\t\t...(opts.eventId === undefined ? {} : { eventId: opts.eventId }),\n\t\t...(opts.eventType === undefined ? {} : { eventType: opts.eventType }),\n\t\t...(opts.issueCode === undefined ? {} : { issueCode: opts.issueCode }),\n\t\t...(opts.source === undefined ? {} : { source: opts.source }),\n\t\thighWater: highWaterSnapshot(flowId, state),\n\t\ttimestampMs,\n\t};\n}\n\nfunction highWaterSnapshot(flowId: string, state: EventFlowRuntimeState): EventFlowHighWater {\n\treturn {\n\t\tflowId,\n\t\trecordSeq: state.recordSeq,\n\t\tauditSeq: state.auditSeq,\n\t\tsources: [...state.highWater.values()].sort(\n\t\t\t(a, b) => a.source.localeCompare(b.source) || (a.topic ?? \"\").localeCompare(b.topic ?? \"\"),\n\t\t),\n\t};\n}\n\nfunction emptyHighWater(flowId: string): EventFlowHighWater {\n\treturn { flowId, recordSeq: 0, auditSeq: 0, sources: [] };\n}\n\nfunction projectionHighWater(\n\tflowId: string,\n\trecord: EventFlowRecord,\n\tsourceHighWater: Map<string, EventFlowSourceHighWater>,\n): EventFlowHighWater {\n\tsourceHighWater.set(sourceKey(record.source), {\n\t\tsource: record.source.source,\n\t\t...(record.source.topic === undefined ? {} : { topic: record.source.topic }),\n\t\t...(record.source.seq === undefined ? {} : { seq: record.source.seq }),\n\t\tmessageId: record.event.id,\n\t\trecordSeq: record.recordSeq,\n\t});\n\treturn {\n\t\tflowId,\n\t\trecordSeq: record.recordSeq,\n\t\tauditSeq: 0,\n\t\tsources: [...sourceHighWater.values()].sort(\n\t\t\t(a, b) => a.source.localeCompare(b.source) || (a.topic ?? \"\").localeCompare(b.topic ?? \"\"),\n\t\t),\n\t};\n}\n\nfunction sourceKey(source: EventFlowSourceRef): string {\n\treturn `${source.source}\\u0000${source.topic ?? \"\"}`;\n}\n\nfunction eventIdOf(value: unknown): string | undefined {\n\treturn isRecord(value) && typeof value.id === \"string\" ? value.id : undefined;\n}\n\nfunction dataIssue(code: string, message: string, details?: unknown): DataIssue {\n\treturn {\n\t\tkind: \"issue\",\n\t\tcode,\n\t\tmessage,\n\t\tseverity: \"error\",\n\t\tsource: \"eventFlow\",\n\t\t...(details === undefined ? {} : { details }),\n\t};\n}\n\nfunction isEventFlowBundle<T>(value: unknown): value is EventFlowBundle<T> {\n\treturn isRecord(value) && \"records\" in value && \"highWater\" in value;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n","/**\n * Horizontal inspection patterns re-derived from old presets (B62 / D125).\n *\n * These helpers compose the clean-slate graph inspection egresses. They do not\n * add graph nodes, hidden subscriptions, policy gates, or storage ownership.\n */\n\nimport type { Graph } from \"../graph/graph.js\";\nimport type { NodeProfile } from \"../graph/inspect.js\";\n\nexport interface ProfileSummaryNode {\n\tpath: string;\n\tinvokes: number;\n\ttotalDurationNs: number;\n\tlastDurationNs: number;\n\tstatus: NodeProfile[\"status\"];\n}\n\nexport interface ProfileSummary {\n\t/** Number of nodes in describe(), including nodes with zero invokes. */\n\tnodeCount: number;\n\ttotalInvokes: number;\n\tbyStatus: Partial<Record<NodeProfile[\"status\"], number>>;\n\t/** Nodes sorted by invokes desc, then path asc. */\n\thotNodes: ProfileSummaryNode[];\n}\n\n/**\n * Summarize an opt-in Graph.profile() snapshot while keeping describe() as the\n * source of node cardinality. No counters are stored on nodes (R-profile).\n */\nexport function profileSummary(graph: Graph, opts: { limit?: number } = {}): ProfileSummary {\n\tconst profile = graph.profile();\n\tconst described = graph.describe();\n\tconst nodeIds = new Set(described.nodes.map((node) => node.id));\n\tfor (const id of Object.keys(profile.nodes)) nodeIds.add(id);\n\n\tconst byStatus: Partial<Record<NodeProfile[\"status\"], number>> = {};\n\tconst hotNodes: ProfileSummaryNode[] = [];\n\tfor (const path of [...nodeIds].sort()) {\n\t\tconst nodeProfile = profile.nodes[path];\n\t\tif (nodeProfile === undefined) continue;\n\t\tbyStatus[nodeProfile.status] = (byStatus[nodeProfile.status] ?? 0) + 1;\n\t\thotNodes.push({\n\t\t\tpath,\n\t\t\tinvokes: nodeProfile.invokes,\n\t\t\ttotalDurationNs: nodeProfile.totalDurationNs,\n\t\t\tlastDurationNs: nodeProfile.lastDurationNs,\n\t\t\tstatus: nodeProfile.status,\n\t\t});\n\t}\n\thotNodes.sort((a, b) => b.invokes - a.invokes || a.path.localeCompare(b.path));\n\treturn {\n\t\tnodeCount: nodeIds.size,\n\t\ttotalInvokes: profile.totalInvokes,\n\t\tbyStatus,\n\t\thotNodes: hotNodes.slice(0, opts.limit ?? hotNodes.length),\n\t};\n}\n","/**\n * Passive semantic-memory vocabulary and deterministic helpers.\n *\n * D158 splits semantic memory into horizontal patterns and vertical solutions.\n * This module intentionally owns no graph nodes, storage restore, timers,\n * subscriptions, vector indexes, knowledge graphs, or agentic runtime.\n */\n\nimport type { StrictJsonValue } from \"../json/codec.js\";\n\n/** Stable identity for a semantic-memory fact. */\nexport type FactId = string;\n\n/** Shard partition key used by passive sharding helpers. */\nexport type ShardKey = string | number;\n\n/**\n * A single semantic-memory fact. Pattern convention only: this is not a\n * protocol message, storage record owner, restore contract, or graph runtime.\n */\nexport interface MemoryFragment<T = unknown> {\n\treadonly id: FactId;\n\treadonly payload: T;\n\t/** Transaction time, typically monotonic nanoseconds. */\n\treadonly tNs: bigint;\n\t/** Valid-time start. Undefined means unbounded past. */\n\treadonly validFrom?: bigint;\n\t/** Valid-time end. Undefined means currently valid. */\n\treadonly validTo?: bigint;\n\t/** Confidence score in the closed interval [0, 1]. */\n\treadonly confidence: number;\n\treadonly tags: readonly string[];\n\t/** Fact ids this fragment derives from or depends on. */\n\treadonly sources: readonly FactId[];\n\treadonly embedding?: readonly number[];\n\treadonly parentFragmentId?: FactId;\n\treadonly provenance?: string;\n}\n\n/** Columnar passive store vocabulary for callers that keep memory facts outside GraphReFly. */\nexport interface FactStore<T = unknown> {\n\treadonly byId: ReadonlyMap<FactId, MemoryFragment<T>>;\n}\n\n/** Read-only projection passed to scoring policies; it exposes no mutation surface. */\nexport interface StoreReadHandle<T = unknown> {\n\tget(id: FactId): MemoryFragment<T> | undefined;\n\thas(id: FactId): boolean;\n\treadonly size: number;\n\tvalues(): IterableIterator<MemoryFragment<T>>;\n}\n\nexport type ScoringPolicy<T = unknown> = (\n\tfragment: MemoryFragment<T>,\n\tstore: StoreReadHandle<T>,\n) => number;\nexport type DecayPolicy = (confidence: number, ageNs: bigint) => number;\nexport type AdmissionFilter<T = unknown> = (fragment: MemoryFragment<T>) => boolean;\n\n/** Outcome signal for policy learning. This is an application fact, not a protocol event. */\nexport interface OutcomeSignal {\n\treadonly factId: FactId;\n\treadonly reward: number;\n}\n\n/** Passive structured query over semantic-memory facts. */\nexport interface MemoryQuery {\n\treadonly tags?: readonly string[];\n\treadonly asOf?: bigint;\n\treadonly minConfidence?: number;\n\treadonly limit?: number;\n}\n\nexport interface MemoryAnswer<T = unknown> {\n\treadonly query: MemoryQuery;\n\treadonly results: readonly MemoryFragment<T>[];\n}\n\nexport type KnowledgeAssertionStrictJsonValue = StrictJsonValue;\n\n/** Passive KG endpoint vocabulary. Entity ids are DATA keys, not graph node ids. */\nexport interface KnowledgeAssertionSubject {\n\treadonly id: FactId;\n\treadonly type?: string;\n}\n\n/** Passive KG object/value vocabulary. */\nexport type KnowledgeAssertionObject =\n\t| {\n\t\t\treadonly kind: \"entity\";\n\t\t\treadonly id: FactId;\n\t\t\treadonly type?: string;\n\t }\n\t| {\n\t\t\treadonly kind: \"value\";\n\t\t\treadonly value: KnowledgeAssertionStrictJsonValue;\n\t\t\treadonly valueType?: string;\n\t };\n\n/** Passive KG assertion fact consumed by lower semantic-memory graph patterns. */\nexport interface KnowledgeAssertion {\n\treadonly id: FactId;\n\treadonly recordId?: FactId;\n\treadonly fragmentId?: FactId;\n\treadonly subject: KnowledgeAssertionSubject;\n\treadonly predicate: string;\n\treadonly object: KnowledgeAssertionObject;\n\treadonly confidence?: number;\n\treadonly sources?: readonly FactId[];\n\treadonly provenance?: string;\n}\n\n/** Entry vocabulary for ranked collection-like memory views. */\nexport interface CollectionEntry<T = unknown> {\n\treadonly id: string;\n\treadonly value: T;\n\treadonly createdAtNs: bigint;\n\treadonly lastAccessNs: bigint;\n\treadonly baseScore: number;\n}\n\nexport type RankedCollectionEntry<T = unknown> = CollectionEntry<T> & {\n\treadonly score: number;\n};\n\nexport type CollectionScoreFn<T = unknown> = (value: T) => number;\n\n/** Query shape shared by passive retrieval/ranking helpers. */\nexport interface RetrievalQuery {\n\treadonly text?: string;\n\treadonly vector?: readonly number[];\n\treadonly entityIds?: readonly string[];\n\treadonly context?: readonly string[];\n}\n\nexport interface VectorSearchResult<TMeta = unknown> {\n\treadonly id: string;\n\treadonly score: number;\n\treadonly meta?: TMeta;\n}\n\nexport interface RetrievalEntry<TMem = unknown> {\n\treadonly key: string;\n\treadonly value: TMem;\n\treadonly score: number;\n\treadonly sources: ReadonlyArray<\"vector\" | \"graph\" | \"store\">;\n\treadonly context?: readonly string[];\n}\n\nexport interface RetrievalTrace<TMem = unknown> {\n\treadonly vectorCandidates: ReadonlyArray<VectorSearchResult<TMem>>;\n\treadonly graphExpanded: ReadonlyArray<string>;\n\treadonly ranked: ReadonlyArray<RetrievalEntry<TMem>>;\n\treadonly packed: ReadonlyArray<RetrievalEntry<TMem>>;\n}\n\n/** Generic per-dimension thresholds. Any configured dimension below threshold is rejected. */\nexport type AdmissionThresholds<Dims extends string> = Partial<Record<Dims, number>>;\n\nexport interface AdmissionScoredOptions<Dims extends string, TRaw = unknown> {\n\treadonly scoreFn: (raw: TRaw) => Readonly<Record<Dims, number>>;\n\treadonly thresholds?: AdmissionThresholds<Dims>;\n}\n\nexport interface AdmissionScores {\n\treadonly persistence: number;\n\treadonly structure: number;\n\treadonly personalValue: number;\n}\n\nexport interface AdmissionScore3DOptions {\n\treadonly scoreFn: (raw: unknown) => AdmissionScores;\n\treadonly persistenceThreshold?: number;\n\treadonly personalValueThreshold?: number;\n\treadonly requireStructured?: boolean;\n}\n\nexport interface ShardByTenantOptions {\n\treadonly tenants?: readonly string[];\n\treadonly shardCount?: number;\n}\n\nexport interface ShardByTenantConfig<T = unknown> {\n\treadonly shardBy: (fragment: MemoryFragment<T>) => ShardKey;\n\treadonly shardCount: number;\n}\n\nexport interface MemoryFragmentValidation {\n\treadonly ok: boolean;\n\treadonly errors: readonly string[];\n}\n\n/** Cosine similarity over zero-padded vectors. Non-finite results normalize to 0. */\nexport function cosineSimilarity(a: readonly number[], b: readonly number[]): number {\n\tconst n = Math.max(a.length, b.length);\n\tlet dot = 0;\n\tlet na = 0;\n\tlet nb = 0;\n\tfor (let i = 0; i < n; i += 1) {\n\t\tconst av = a[i] ?? 0;\n\t\tconst bv = b[i] ?? 0;\n\t\tdot += av * bv;\n\t\tna += av * av;\n\t\tnb += bv * bv;\n\t}\n\tif (na === 0 || nb === 0) return 0;\n\tconst score = dot / Math.sqrt(na * nb);\n\treturn Number.isFinite(score) ? score : 0;\n}\n\n/**\n * Returns true when a fragment is valid at `asOf`.\n *\n * Omitted `asOf` has no clock to compare against, so it admits only fragments\n * that are live and not valid-time delayed.\n */\nexport function memoryFragmentValidAt(fragment: MemoryFragment, asOf?: bigint): boolean {\n\tif (asOf === undefined) return fragment.validTo === undefined && fragment.validFrom === undefined;\n\tif (fragment.validFrom !== undefined && fragment.validFrom > asOf) return false;\n\tif (fragment.validTo !== undefined && fragment.validTo <= asOf) return false;\n\treturn true;\n}\n\n/** Pure structured-query predicate over a single fragment. */\nexport function memoryFragmentMatchesQuery(\n\tfragment: MemoryFragment,\n\tquery: MemoryQuery = {},\n): boolean {\n\tif (!memoryFragmentValidAt(fragment, query.asOf)) return false;\n\tif (query.minConfidence !== undefined && fragment.confidence < query.minConfidence) return false;\n\tif (\n\t\tquery.tags &&\n\t\tquery.tags.length > 0 &&\n\t\t!query.tags.some((tag) => fragment.tags.includes(tag))\n\t) {\n\t\treturn false;\n\t}\n\treturn true;\n}\n\n/** Filter and rank fragments by confidence desc, then transaction time desc. */\nexport function filterMemoryFragments<T>(\n\tfragments: Iterable<MemoryFragment<T>>,\n\tquery: MemoryQuery = {},\n): readonly MemoryFragment<T>[] {\n\tconst results = [...fragments].filter((fragment) => memoryFragmentMatchesQuery(fragment, query));\n\tresults.sort((a, b) => b.confidence - a.confidence || compareBigIntDesc(a.tNs, b.tNs));\n\treturn query.limit === undefined ? results : results.slice(0, Math.max(0, query.limit));\n}\n\n/** Validate the passive MemoryFragment shape without throwing. */\nexport function validateMemoryFragment(value: unknown): MemoryFragmentValidation {\n\tconst errors: string[] = [];\n\tif (typeof value !== \"object\" || value === null) {\n\t\treturn { ok: false, errors: [\"fragment must be an object\"] };\n\t}\n\tconst fragment = value as Partial<MemoryFragment>;\n\tif (typeof fragment.id !== \"string\" || fragment.id.length === 0) {\n\t\terrors.push(\"id must be a non-empty string\");\n\t}\n\tif (!Object.hasOwn(fragment, \"payload\")) {\n\t\terrors.push(\"payload must be present\");\n\t}\n\tif (typeof fragment.tNs !== \"bigint\") {\n\t\terrors.push(\"tNs must be a bigint\");\n\t}\n\tconst confidence = fragment.confidence;\n\tif (\n\t\t!Number.isFinite(confidence) ||\n\t\tconfidence === undefined ||\n\t\tconfidence < 0 ||\n\t\tconfidence > 1\n\t) {\n\t\terrors.push(\"confidence must be a finite number in [0, 1]\");\n\t}\n\tif (!isDenseArrayOf(fragment.tags, (tag): tag is string => typeof tag === \"string\")) {\n\t\terrors.push(\"tags must be a readonly string array\");\n\t}\n\tif (!isDenseArrayOf(fragment.sources, (source): source is string => typeof source === \"string\")) {\n\t\terrors.push(\"sources must be a readonly string array\");\n\t}\n\tif (fragment.validFrom !== undefined && typeof fragment.validFrom !== \"bigint\") {\n\t\terrors.push(\"validFrom must be a bigint when present\");\n\t}\n\tif (fragment.validTo !== undefined && typeof fragment.validTo !== \"bigint\") {\n\t\terrors.push(\"validTo must be a bigint when present\");\n\t}\n\tif (\n\t\ttypeof fragment.validFrom === \"bigint\" &&\n\t\ttypeof fragment.validTo === \"bigint\" &&\n\t\tfragment.validFrom >= fragment.validTo\n\t) {\n\t\terrors.push(\"validFrom must be earlier than validTo\");\n\t}\n\tif (\n\t\tfragment.embedding !== undefined &&\n\t\t!isDenseArrayOf(fragment.embedding, (component): component is number =>\n\t\t\tNumber.isFinite(component),\n\t\t)\n\t) {\n\t\terrors.push(\"embedding must be a finite number array when present\");\n\t}\n\tif (fragment.parentFragmentId !== undefined && typeof fragment.parentFragmentId !== \"string\") {\n\t\terrors.push(\"parentFragmentId must be a string when present\");\n\t}\n\tif (fragment.provenance !== undefined && typeof fragment.provenance !== \"string\") {\n\t\terrors.push(\"provenance must be a string when present\");\n\t}\n\treturn { ok: errors.length === 0, errors };\n}\n\nexport function isMemoryFragment(value: unknown): value is MemoryFragment {\n\treturn validateMemoryFragment(value).ok;\n}\n\n/**\n * Generic N-dimension admission filter. Missing or non-finite thresholded scores reject.\n */\nexport function admissionScored<Dims extends string, TRaw = unknown>(\n\topts: AdmissionScoredOptions<Dims, TRaw>,\n): (raw: TRaw) => boolean {\n\tconst thresholds = opts.thresholds ?? ({} as AdmissionThresholds<Dims>);\n\treturn (raw: TRaw): boolean => {\n\t\tconst scores = opts.scoreFn(raw);\n\t\tfor (const dim of Object.keys(thresholds) as Dims[]) {\n\t\t\tconst min = thresholds[dim];\n\t\t\tif (min === undefined) continue;\n\t\t\tconst score = scores[dim];\n\t\t\tconst safe = Number.isFinite(score) ? (score as number) : Number.NEGATIVE_INFINITY;\n\t\t\tif (safe < min) return false;\n\t\t}\n\t\treturn true;\n\t};\n}\n\n/** Three-axis admission sugar for persistence / structure / personal-value scoring. */\nexport function admissionFilter3D(opts: AdmissionScore3DOptions): (raw: unknown) => boolean {\n\treturn (raw: unknown): boolean => {\n\t\tconst scores = opts.scoreFn(raw);\n\t\tif (!scoreAtLeast(scores.persistence, opts.persistenceThreshold ?? 0.3)) return false;\n\t\tif (!scoreAtLeast(scores.personalValue, opts.personalValueThreshold ?? 0.3)) return false;\n\t\tif (!opts.requireStructured) return true;\n\t\treturn scoreAtLeast(scores.structure, Number.MIN_VALUE);\n\t};\n}\n\n/** Build a passive `{ shardBy, shardCount }` pair for tenant-isolated sharding. */\nexport function shardByTenant<T>(\n\ttenantOf: (fragment: MemoryFragment<T>) => string,\n\topts: ShardByTenantOptions = {},\n): ShardByTenantConfig<T> {\n\tif (opts.tenants && opts.tenants.length > 0) {\n\t\tconst tenants = [...new Set(opts.tenants)];\n\t\tconst index = new Map(tenants.map((tenant, i) => [tenant, i] as const));\n\t\tconst overflow = tenants.length;\n\t\treturn {\n\t\t\tshardBy: (fragment) => index.get(tenantOf(fragment)) ?? overflow,\n\t\t\tshardCount: tenants.length + 1,\n\t\t};\n\t}\n\tconst configuredShardCount = opts.shardCount ?? 4;\n\tconst shardCount = Number.isSafeInteger(configuredShardCount)\n\t\t? Math.max(1, configuredShardCount)\n\t\t: 4;\n\treturn { shardBy: (fragment) => tenantOf(fragment), shardCount };\n}\n\nfunction compareBigIntDesc(a: bigint, b: bigint): number {\n\tif (a === b) return 0;\n\treturn a > b ? -1 : 1;\n}\n\nfunction isDenseArrayOf<T>(value: unknown, predicate: (item: unknown) => item is T): value is T[] {\n\tif (!Array.isArray(value)) return false;\n\tfor (let i = 0; i < value.length; i += 1) {\n\t\tif (!Object.hasOwn(value, i) || !predicate(value[i])) return false;\n\t}\n\treturn true;\n}\n\nfunction scoreAtLeast(score: number, min: number): boolean {\n\treturn Number.isFinite(score) && score >= min;\n}\n","/**\n * Graph-visible semantic-memory retrieval patterns.\n *\n * D158 allows horizontal semantic-memory patterns when they are ordinary graph\n * nodes with declared deps and graph-visible facts. This file intentionally\n * owns no storage restore/hydration, scheduler, hidden subscription, vector DB,\n * retention loop, consolidation loop, Graph subclass, or protocol behavior.\n */\n\nimport {\n\tcosineSimilarity,\n\ttype FactId,\n\tfilterMemoryFragments,\n\ttype KnowledgeAssertion,\n\ttype KnowledgeAssertionObject,\n\ttype KnowledgeAssertionSubject,\n\ttype MemoryFragment,\n\tmemoryFragmentMatchesQuery,\n\tvalidateMemoryFragment,\n} from \"./semantic-memory.js\";\nimport type {\n\tKnowledgeGraphEntity,\n\tKnowledgeGraphError,\n\tKnowledgeGraphIndex,\n\tKnowledgeGraphPolicy,\n\tKnowledgeGraphRelation,\n\tKnowledgeGraphTopic,\n\tMemoryRetrievalError,\n\tMemoryRetrievalQuery,\n\tMemoryRetrievalStatusState,\n} from \"./semantic-memory-graph-types.js\";\n\ninterface MemoryRetrievalQueryValidation {\n\treadonly ok: boolean;\n\treadonly query: MemoryRetrievalQuery;\n\treadonly errors: readonly Omit<MemoryRetrievalError, \"cursor\">[];\n}\n\ninterface FragmentValidationResult<T> {\n\treadonly fragment?: MemoryFragment<T>;\n\treadonly error?: Omit<MemoryRetrievalError, \"cursor\">;\n}\n\nexport function validateKnowledgeGraphPolicy(value: unknown): {\n\treadonly policy?: KnowledgeGraphPolicy;\n\treadonly errors: readonly Omit<KnowledgeGraphError, \"cursor\">[];\n} {\n\tif (value === undefined) return { policy: undefined, errors: [] };\n\tif (!isPlainObject(value)) {\n\t\treturn {\n\t\t\terrors: [\n\t\t\t\t{\n\t\t\t\t\tcode: \"invalid-policy\",\n\t\t\t\t\tmessage: \"knowledgeGraphReducerBundle: policy must be an object\",\n\t\t\t\t\tassertion: value,\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\t}\n\tconst errors: string[] = [];\n\tconst policy = value as Partial<KnowledgeGraphPolicy>;\n\tif (\n\t\tpolicy.allowedPredicates !== undefined &&\n\t\t!isDenseArrayOf(policy.allowedPredicates, (item): item is string => typeof item === \"string\")\n\t) {\n\t\terrors.push(\"allowedPredicates must be a readonly string array\");\n\t}\n\tif (policy.requireEntityTypes !== undefined && typeof policy.requireEntityTypes !== \"boolean\") {\n\t\terrors.push(\"requireEntityTypes must be a boolean when present\");\n\t}\n\tif (errors.length > 0) {\n\t\treturn {\n\t\t\terrors: [\n\t\t\t\t{\n\t\t\t\t\tcode: \"invalid-policy\",\n\t\t\t\t\tmessage: \"knowledgeGraphReducerBundle: policy is invalid\",\n\t\t\t\t\tassertion: value,\n\t\t\t\t\tvalidationErrors: Object.freeze(errors),\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\t}\n\treturn {\n\t\tpolicy: Object.freeze({\n\t\t\t...(policy.allowedPredicates === undefined\n\t\t\t\t? {}\n\t\t\t\t: { allowedPredicates: Object.freeze([...policy.allowedPredicates]) }),\n\t\t\t...(policy.requireEntityTypes === undefined\n\t\t\t\t? {}\n\t\t\t\t: { requireEntityTypes: policy.requireEntityTypes }),\n\t\t}),\n\t\terrors: [],\n\t};\n}\n\nexport function reduceKnowledgeAssertions(\n\tvalue: unknown,\n\tpolicy?: KnowledgeGraphPolicy,\n): {\n\treadonly assertions: readonly KnowledgeAssertion[];\n\treadonly entities: readonly KnowledgeGraphEntity[];\n\treadonly relations: readonly KnowledgeGraphRelation[];\n\treadonly topics: readonly KnowledgeGraphTopic[];\n\treadonly index: KnowledgeGraphIndex;\n\treadonly errors: readonly Omit<KnowledgeGraphError, \"cursor\">[];\n\treadonly invalidAssertions: number;\n} {\n\tconst assertions: KnowledgeAssertion[] = [];\n\tconst errors: Omit<KnowledgeGraphError, \"cursor\">[] = [];\n\tconst seenAssertions = new Set<FactId>();\n\tif (!Array.isArray(value)) {\n\t\treturn {\n\t\t\tassertions,\n\t\t\tentities: [],\n\t\t\trelations: [],\n\t\t\ttopics: [],\n\t\t\tindex: emptyKnowledgeGraphIndex(),\n\t\t\terrors: [\n\t\t\t\t{\n\t\t\t\t\tcode: \"invalid-assertions-input\",\n\t\t\t\t\tmessage: \"knowledgeGraphReducerBundle: assertions input must be an array\",\n\t\t\t\t\tassertion: value,\n\t\t\t\t},\n\t\t\t],\n\t\t\tinvalidAssertions: 0,\n\t\t};\n\t}\n\tconst length = safeArrayLength(value);\n\tif (length === undefined) {\n\t\treturn {\n\t\t\tassertions,\n\t\t\tentities: [],\n\t\t\trelations: [],\n\t\t\ttopics: [],\n\t\t\tindex: emptyKnowledgeGraphIndex(),\n\t\t\terrors: [\n\t\t\t\t{\n\t\t\t\t\tcode: \"invalid-assertions-input\",\n\t\t\t\t\tmessage: \"knowledgeGraphReducerBundle: assertions input length could not be read\",\n\t\t\t\t\tassertion: value,\n\t\t\t\t},\n\t\t\t],\n\t\t\tinvalidAssertions: 0,\n\t\t};\n\t}\n\tfor (let i = 0; i < length; i += 1) {\n\t\tconst result = validateKnowledgeAssertion(value[i], i, policy);\n\t\tif (result.error !== undefined) {\n\t\t\terrors.push(result.error);\n\t\t\tcontinue;\n\t\t}\n\t\tconst assertion = result.assertion as KnowledgeAssertion;\n\t\tif (seenAssertions.has(assertion.id)) {\n\t\t\terrors.push({\n\t\t\t\tcode: \"duplicate-assertion-id\",\n\t\t\t\tmessage: \"knowledgeGraphReducerBundle: duplicate assertion id\",\n\t\t\t\tindex: i,\n\t\t\t\tassertionId: assertion.id,\n\t\t\t\tassertion,\n\t\t\t\tvalidationErrors: Object.freeze([`duplicate assertion id '${assertion.id}'`]),\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tseenAssertions.add(assertion.id);\n\t\tassertions.push(assertion);\n\t}\n\tconst materialized = materializeKnowledgeGraph(assertions);\n\treturn {\n\t\tassertions: Object.freeze(assertions),\n\t\t...materialized,\n\t\terrors,\n\t\tinvalidAssertions: errors.filter((error) => error.code !== \"invalid-policy\").length,\n\t};\n}\n\nfunction validateKnowledgeAssertion(\n\tvalue: unknown,\n\tindex: number,\n\tpolicy?: KnowledgeGraphPolicy,\n): {\n\treadonly assertion?: KnowledgeAssertion;\n\treadonly error?: Omit<KnowledgeGraphError, \"cursor\">;\n} {\n\tif (!isPlainObject(value)) {\n\t\treturn invalidKnowledgeAssertion(index, value, [\"assertion must be an object\"]);\n\t}\n\tconst raw = value as Partial<KnowledgeAssertion>;\n\tconst errors: string[] = [];\n\tif (!isNonEmptyString(raw.id)) errors.push(\"id must be a non-empty string\");\n\tif (!isKnowledgeSubject(raw.subject)) errors.push(\"subject.id must be a non-empty string\");\n\tif (!isNonEmptyString(raw.predicate)) errors.push(\"predicate must be a non-empty string\");\n\tif (!isKnowledgeObject(raw.object)) errors.push(\"object shape is invalid\");\n\tif (\n\t\traw.confidence !== undefined &&\n\t\t(!Number.isFinite(raw.confidence) || raw.confidence < 0 || raw.confidence > 1)\n\t) {\n\t\terrors.push(\"confidence must be a finite number in [0, 1] when present\");\n\t}\n\tif (raw.sources !== undefined && !isDenseArrayOf(raw.sources, isNonEmptyString)) {\n\t\terrors.push(\"sources must be a readonly non-empty string array when present\");\n\t}\n\tif (\n\t\tpolicy?.allowedPredicates !== undefined &&\n\t\t!policy.allowedPredicates.includes(raw.predicate ?? \"\")\n\t) {\n\t\terrors.push(`predicate '${String(raw.predicate)}' is not allowed by policy`);\n\t}\n\tif (policy?.requireEntityTypes === true) {\n\t\tif (isKnowledgeSubject(raw.subject) && raw.subject.type === undefined) {\n\t\t\terrors.push(\"subject.type is required by policy\");\n\t\t}\n\t\tif (\n\t\t\tisKnowledgeObject(raw.object) &&\n\t\t\traw.object.kind === \"entity\" &&\n\t\t\traw.object.type === undefined\n\t\t) {\n\t\t\terrors.push(\"object.type is required by policy for entity objects\");\n\t\t}\n\t}\n\tif (errors.length > 0) {\n\t\treturn invalidKnowledgeAssertion(index, value, errors, raw.id);\n\t}\n\treturn {\n\t\tassertion: Object.freeze({\n\t\t\tid: raw.id as FactId,\n\t\t\t...(raw.recordId === undefined ? {} : { recordId: raw.recordId }),\n\t\t\t...(raw.fragmentId === undefined ? {} : { fragmentId: raw.fragmentId }),\n\t\t\tsubject: snapshotSubject(raw.subject as KnowledgeAssertionSubject),\n\t\t\tpredicate: raw.predicate as string,\n\t\t\tobject: snapshotObject(raw.object as KnowledgeAssertionObject),\n\t\t\t...(raw.confidence === undefined ? {} : { confidence: raw.confidence }),\n\t\t\tsources: Object.freeze([...(raw.sources ?? [])]),\n\t\t\t...(raw.provenance === undefined ? {} : { provenance: raw.provenance }),\n\t\t}),\n\t};\n}\n\nfunction invalidKnowledgeAssertion(\n\tindex: number,\n\tassertion: unknown,\n\tvalidationErrors: readonly string[],\n\tassertionId?: unknown,\n): { readonly error: Omit<KnowledgeGraphError, \"cursor\"> } {\n\treturn {\n\t\terror: {\n\t\t\tcode: \"invalid-assertion\",\n\t\t\tmessage: \"knowledgeGraphReducerBundle: assertion is invalid\",\n\t\t\tindex,\n\t\t\tassertionId: typeof assertionId === \"string\" ? assertionId : undefined,\n\t\t\tassertion,\n\t\t\tvalidationErrors: Object.freeze([...validationErrors]),\n\t\t},\n\t};\n}\n\nfunction materializeKnowledgeGraph(assertions: readonly KnowledgeAssertion[]): {\n\treadonly entities: readonly KnowledgeGraphEntity[];\n\treadonly relations: readonly KnowledgeGraphRelation[];\n\treadonly topics: readonly KnowledgeGraphTopic[];\n\treadonly index: KnowledgeGraphIndex;\n} {\n\tconst entityAssertions = new Map<\n\t\tFactId,\n\t\t{\n\t\t\ttype?: string;\n\t\t\tassertionIds: Set<FactId>;\n\t\t\tsubjectAssertionIds: Set<FactId>;\n\t\t\tobjectAssertionIds: Set<FactId>;\n\t\t}\n\t>();\n\tconst topics = new Map<FactId, { assertionIds: Set<FactId>; entityIds: Set<FactId> }>();\n\tconst relations: KnowledgeGraphRelation[] = [];\n\tfor (const assertion of assertions) {\n\t\tconst subject = touchEntity(entityAssertions, assertion.subject.id, assertion.subject.type);\n\t\tsubject.assertionIds.add(assertion.id);\n\t\tsubject.subjectAssertionIds.add(assertion.id);\n\t\tlet topic = topics.get(assertion.predicate);\n\t\tif (topic === undefined) {\n\t\t\ttopic = { assertionIds: new Set(), entityIds: new Set() };\n\t\t\ttopics.set(assertion.predicate, topic);\n\t\t}\n\t\ttopic.assertionIds.add(assertion.id);\n\t\ttopic.entityIds.add(assertion.subject.id);\n\t\tif (assertion.object.kind === \"entity\") {\n\t\t\tconst object = touchEntity(entityAssertions, assertion.object.id, assertion.object.type);\n\t\t\tobject.assertionIds.add(assertion.id);\n\t\t\tobject.objectAssertionIds.add(assertion.id);\n\t\t\ttopic.entityIds.add(assertion.object.id);\n\t\t}\n\t\trelations.push(\n\t\t\tObject.freeze({\n\t\t\t\tassertionId: assertion.id,\n\t\t\t\tsubject: assertion.subject,\n\t\t\t\tpredicate: assertion.predicate,\n\t\t\t\tobject: assertion.object,\n\t\t\t\t...(assertion.confidence === undefined ? {} : { confidence: assertion.confidence }),\n\t\t\t\tsources: Object.freeze([...(assertion.sources ?? [])]),\n\t\t\t\t...(assertion.provenance === undefined ? {} : { provenance: assertion.provenance }),\n\t\t\t}),\n\t\t);\n\t}\n\tconst entities = [...entityAssertions.entries()].map(([id, entity]) =>\n\t\tObject.freeze({\n\t\t\tid,\n\t\t\t...(entity.type === undefined ? {} : { type: entity.type }),\n\t\t\tassertionIds: freezeSortedSet(entity.assertionIds),\n\t\t\tsubjectAssertionIds: freezeSortedSet(entity.subjectAssertionIds),\n\t\t\tobjectAssertionIds: freezeSortedSet(entity.objectAssertionIds),\n\t\t}),\n\t);\n\tentities.sort((a, b) => compareString(a.id, b.id));\n\trelations.sort((a, b) => compareString(a.assertionId, b.assertionId));\n\tconst topicFacts = [...topics.entries()].map(([predicate, topic]) =>\n\t\tObject.freeze({\n\t\t\tpredicate,\n\t\t\tassertionIds: freezeSortedSet(topic.assertionIds),\n\t\t\tentityIds: freezeSortedSet(topic.entityIds),\n\t\t}),\n\t);\n\ttopicFacts.sort((a, b) => compareString(a.predicate, b.predicate));\n\tconst index: KnowledgeGraphIndex = Object.freeze({\n\t\tassertionIds: Object.freeze(assertions.map((assertion) => assertion.id).sort(compareString)),\n\t\tentityIds: Object.freeze(entities.map((entity) => entity.id)),\n\t\trelationIds: Object.freeze(relations.map((relation) => relation.assertionId)),\n\t\tpredicates: Object.freeze(topicFacts.map((topic) => topic.predicate)),\n\t});\n\treturn {\n\t\tentities: Object.freeze(entities),\n\t\trelations: Object.freeze(relations),\n\t\ttopics: Object.freeze(topicFacts),\n\t\tindex,\n\t};\n}\n\nfunction touchEntity(\n\tentities: Map<\n\t\tFactId,\n\t\t{\n\t\t\ttype?: string;\n\t\t\tassertionIds: Set<FactId>;\n\t\t\tsubjectAssertionIds: Set<FactId>;\n\t\t\tobjectAssertionIds: Set<FactId>;\n\t\t}\n\t>,\n\tid: FactId,\n\ttype?: string,\n) {\n\tlet entity = entities.get(id);\n\tif (entity === undefined) {\n\t\tentity = {\n\t\t\t...(type === undefined ? {} : { type }),\n\t\t\tassertionIds: new Set(),\n\t\t\tsubjectAssertionIds: new Set(),\n\t\t\tobjectAssertionIds: new Set(),\n\t\t};\n\t\tentities.set(id, entity);\n\t} else if (entity.type === undefined && type !== undefined) {\n\t\tentity.type = type;\n\t}\n\treturn entity;\n}\n\nfunction emptyKnowledgeGraphIndex(): KnowledgeGraphIndex {\n\treturn Object.freeze({\n\t\tassertionIds: Object.freeze([]),\n\t\tentityIds: Object.freeze([]),\n\t\trelationIds: Object.freeze([]),\n\t\tpredicates: Object.freeze([]),\n\t});\n}\n\nfunction snapshotSubject(subject: KnowledgeAssertionSubject): KnowledgeAssertionSubject {\n\treturn Object.freeze({\n\t\tid: subject.id,\n\t\t...(subject.type === undefined ? {} : { type: subject.type }),\n\t});\n}\n\nfunction snapshotObject(object: KnowledgeAssertionObject): KnowledgeAssertionObject {\n\treturn object.kind === \"entity\"\n\t\t? Object.freeze({\n\t\t\t\tkind: \"entity\",\n\t\t\t\tid: object.id,\n\t\t\t\t...(object.type === undefined ? {} : { type: object.type }),\n\t\t\t})\n\t\t: Object.freeze({\n\t\t\t\tkind: \"value\",\n\t\t\t\tvalue: object.value,\n\t\t\t\t...(object.valueType === undefined ? {} : { valueType: object.valueType }),\n\t\t\t});\n}\n\nfunction isKnowledgeSubject(value: unknown): value is KnowledgeAssertionSubject {\n\treturn (\n\t\tisPlainObject(value) &&\n\t\tisNonEmptyString(value.id) &&\n\t\t(value.type === undefined || isNonEmptyString(value.type))\n\t);\n}\n\nfunction isKnowledgeObject(value: unknown): value is KnowledgeAssertionObject {\n\tif (!isPlainObject(value)) return false;\n\tif (value.kind === \"entity\") {\n\t\treturn isNonEmptyString(value.id) && (value.type === undefined || isNonEmptyString(value.type));\n\t}\n\tif (value.kind !== \"value\") return false;\n\treturn (\n\t\tisStrictJsonValue(value.value) &&\n\t\t(value.valueType === undefined || isNonEmptyString(value.valueType))\n\t);\n}\n\nfunction isStrictJsonValue(value: unknown): boolean {\n\tif (value === null || typeof value === \"string\" || typeof value === \"boolean\") return true;\n\tif (typeof value === \"number\") return Number.isFinite(value);\n\tif (Array.isArray(value)) {\n\t\tfor (let i = 0; i < value.length; i += 1) {\n\t\t\tif (!Object.hasOwn(value, i) || !isStrictJsonValue(value[i])) return false;\n\t\t}\n\t\treturn true;\n\t}\n\tif (!isPlainObject(value)) return false;\n\tfor (const key of Object.keys(value)) {\n\t\tif (!isStrictJsonValue(value[key])) return false;\n\t}\n\treturn Object.getOwnPropertySymbols(value).length === 0;\n}\n\nfunction freezeSortedSet(value: ReadonlySet<FactId>): readonly FactId[] {\n\treturn Object.freeze([...value].sort(compareString));\n}\n\nexport function rankFragments<T>(\n\tfragments: readonly MemoryFragment<T>[],\n\tquery: MemoryRetrievalQuery,\n): readonly MemoryFragment<T>[] {\n\tif (query.vector === undefined) return filterMemoryFragments(fragments, query);\n\tconst ranked = fragments.filter((fragment) => memoryFragmentMatchesQuery(fragment, query));\n\tranked.sort((a, b) => {\n\t\tconst vectorDelta = vectorScore(b, query) - vectorScore(a, query);\n\t\tif (vectorDelta !== 0) return vectorDelta;\n\t\tconst confidenceDelta = b.confidence - a.confidence;\n\t\tif (confidenceDelta !== 0) return confidenceDelta;\n\t\treturn compareBigIntDesc(a.tNs, b.tNs);\n\t});\n\treturn query.limit === undefined ? ranked : ranked.slice(0, Math.max(0, query.limit));\n}\n\nfunction vectorScore(fragment: MemoryFragment, query: MemoryRetrievalQuery): number {\n\tif (query.vector === undefined || fragment.embedding === undefined) return 0;\n\treturn cosineSimilarity(query.vector, fragment.embedding);\n}\n\nexport function statusState(\n\terrors: readonly Omit<MemoryRetrievalError, \"cursor\">[],\n\tresultCount: number,\n): MemoryRetrievalStatusState {\n\tif (errors.some((error) => !isRecoverableFragmentError(error))) return \"error\";\n\tif (errors.length > 0) return \"partial\";\n\treturn resultCount > 0 ? \"ready\" : \"empty\";\n}\n\nexport function isRecoverableFragmentError(error: Omit<MemoryRetrievalError, \"cursor\">): boolean {\n\treturn error.code === \"invalid-fragment\" || error.code === \"duplicate-fragment-id\";\n}\n\nexport function indexById<T>(\n\tfragments: readonly MemoryFragment<T>[],\n): Readonly<Record<FactId, MemoryFragment<T>>> {\n\tconst byId = Object.create(null) as Record<FactId, MemoryFragment<T>>;\n\tfor (const fragment of fragments) byId[fragment.id] = fragment;\n\treturn Object.freeze(byId);\n}\n\nfunction isFiniteVector(value: unknown): value is readonly number[] {\n\tif (!Array.isArray(value)) return false;\n\tfor (let i = 0; i < value.length; i += 1) {\n\t\tif (!Object.hasOwn(value, i) || !Number.isFinite(value[i])) return false;\n\t}\n\treturn true;\n}\n\nexport function validateMemoryRetrievalQuery(value: unknown): MemoryRetrievalQueryValidation {\n\ttry {\n\t\treturn validateMemoryRetrievalQueryInner(value);\n\t} catch (error) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\tquery: {},\n\t\t\terrors: [\n\t\t\t\t{\n\t\t\t\t\tcode: \"invalid-query\",\n\t\t\t\t\tmessage: `memoryRetrievalBundle: query access failed: ${errorMessage(error)}`,\n\t\t\t\t\tfragment: value,\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\t}\n}\n\nfunction validateMemoryRetrievalQueryInner(value: unknown): MemoryRetrievalQueryValidation {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n\t\treturn invalidQuery(value, \"memoryRetrievalBundle: query must be an object\");\n\t}\n\tconst query = value as Partial<MemoryRetrievalQuery>;\n\tconst errors: Omit<MemoryRetrievalError, \"cursor\">[] = [];\n\tif (\n\t\tquery.tags !== undefined &&\n\t\t!isDenseArrayOf(query.tags, (tag): tag is string => typeof tag === \"string\")\n\t) {\n\t\terrors.push({\n\t\t\tcode: \"invalid-query\",\n\t\t\tmessage: \"memoryRetrievalBundle: query.tags must be a readonly string array\",\n\t\t\tfragment: value,\n\t\t\tvalidationErrors: [\"tags must be a readonly string array\"],\n\t\t});\n\t}\n\tif (query.asOf !== undefined && typeof query.asOf !== \"bigint\") {\n\t\terrors.push({\n\t\t\tcode: \"invalid-query\",\n\t\t\tmessage: \"memoryRetrievalBundle: query.asOf must be a bigint\",\n\t\t\tfragment: value,\n\t\t\tvalidationErrors: [\"asOf must be a bigint when present\"],\n\t\t});\n\t}\n\tif (\n\t\tquery.minConfidence !== undefined &&\n\t\t(!Number.isFinite(query.minConfidence) || query.minConfidence < 0 || query.minConfidence > 1)\n\t) {\n\t\terrors.push({\n\t\t\tcode: \"invalid-query\",\n\t\t\tmessage: \"memoryRetrievalBundle: query.minConfidence must be a finite number in [0, 1]\",\n\t\t\tfragment: value,\n\t\t\tvalidationErrors: [\"minConfidence must be a finite number in [0, 1]\"],\n\t\t});\n\t}\n\tif (query.limit !== undefined && (!Number.isSafeInteger(query.limit) || query.limit < 0)) {\n\t\terrors.push({\n\t\t\tcode: \"invalid-query\",\n\t\t\tmessage: \"memoryRetrievalBundle: query.limit must be a non-negative safe integer\",\n\t\t\tfragment: value,\n\t\t\tvalidationErrors: [\"limit must be a non-negative safe integer\"],\n\t\t});\n\t}\n\tif (query.vector !== undefined && !isFiniteVector(query.vector)) {\n\t\terrors.push({\n\t\t\tcode: \"invalid-query-vector\",\n\t\t\tmessage: \"memoryRetrievalBundle: query.vector must be a finite number array\",\n\t\t\tfragment: value,\n\t\t\tvalidationErrors: [\"vector must be a finite number array\"],\n\t\t});\n\t}\n\tif (errors.length > 0) return { ok: false, query: {}, errors };\n\treturn { ok: true, query: snapshotQuery(query), errors };\n}\n\nfunction invalidQuery(value: unknown, message: string): MemoryRetrievalQueryValidation {\n\treturn {\n\t\tok: false,\n\t\tquery: {},\n\t\terrors: [\n\t\t\t{\n\t\t\t\tcode: \"invalid-query\",\n\t\t\t\tmessage,\n\t\t\t\tfragment: value,\n\t\t\t},\n\t\t],\n\t};\n}\n\nfunction snapshotQuery(query: Partial<MemoryRetrievalQuery>): MemoryRetrievalQuery {\n\treturn Object.freeze({\n\t\t...(query.tags === undefined ? {} : { tags: Object.freeze([...query.tags]) }),\n\t\t...(query.asOf === undefined ? {} : { asOf: query.asOf }),\n\t\t...(query.minConfidence === undefined ? {} : { minConfidence: query.minConfidence }),\n\t\t...(query.limit === undefined ? {} : { limit: query.limit }),\n\t\t...(query.vector === undefined ? {} : { vector: Object.freeze([...query.vector]) }),\n\t});\n}\n\nexport function safeArrayLength(value: readonly unknown[]): number | undefined {\n\ttry {\n\t\treturn value.length;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport function validateAndSnapshotFragment<T>(\n\trawFragments: readonly unknown[],\n\tindex: number,\n): FragmentValidationResult<T> {\n\tlet raw: unknown;\n\ttry {\n\t\traw = rawFragments[index];\n\t\tconst validation = validateMemoryFragment(raw);\n\t\tif (!validation.ok) {\n\t\t\treturn {\n\t\t\t\terror: {\n\t\t\t\t\tcode: \"invalid-fragment\",\n\t\t\t\t\tmessage: \"memoryRetrievalBundle: invalid memory fragment\",\n\t\t\t\t\tindex,\n\t\t\t\t\tfragment: raw,\n\t\t\t\t\tvalidationErrors: Object.freeze([...validation.errors]),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\treturn { fragment: snapshotFragment(raw as MemoryFragment<T>) };\n\t} catch (error) {\n\t\treturn {\n\t\t\terror: {\n\t\t\t\tcode: \"invalid-fragment\",\n\t\t\t\tmessage: `memoryRetrievalBundle: fragment access failed: ${errorMessage(error)}`,\n\t\t\t\tindex,\n\t\t\t\tfragment: raw,\n\t\t\t\tvalidationErrors: Object.freeze([\"fragment access failed\"]),\n\t\t\t},\n\t\t};\n\t}\n}\n\nfunction snapshotFragment<T>(fragment: MemoryFragment<T>): MemoryFragment<T> {\n\treturn Object.freeze({\n\t\tid: fragment.id,\n\t\tpayload: fragment.payload,\n\t\ttNs: fragment.tNs,\n\t\t...(fragment.validFrom === undefined ? {} : { validFrom: fragment.validFrom }),\n\t\t...(fragment.validTo === undefined ? {} : { validTo: fragment.validTo }),\n\t\tconfidence: fragment.confidence,\n\t\ttags: Object.freeze([...fragment.tags]),\n\t\tsources: Object.freeze([...fragment.sources]),\n\t\t...(fragment.embedding === undefined\n\t\t\t? {}\n\t\t\t: { embedding: Object.freeze([...fragment.embedding]) }),\n\t\t...(fragment.parentFragmentId === undefined\n\t\t\t? {}\n\t\t\t: { parentFragmentId: fragment.parentFragmentId }),\n\t\t...(fragment.provenance === undefined ? {} : { provenance: fragment.provenance }),\n\t});\n}\n\nfunction isDenseArrayOf<T>(value: unknown, predicate: (item: unknown) => item is T): value is T[] {\n\tif (!Array.isArray(value)) return false;\n\tfor (let i = 0; i < value.length; i += 1) {\n\t\tif (!Object.hasOwn(value, i) || !predicate(value[i])) return false;\n\t}\n\treturn true;\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n\treturn value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n\treturn typeof value === \"string\" && value.length > 0;\n}\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction compareString(a: string, b: string): number {\n\treturn a < b ? -1 : a > b ? 1 : 0;\n}\n\nfunction compareBigIntDesc(a: bigint, b: bigint): number {\n\tif (a === b) return 0;\n\treturn a > b ? -1 : 1;\n}\n","/**\n * Graph-visible semantic-memory retrieval patterns.\n *\n * D158 allows horizontal semantic-memory patterns when they are ordinary graph\n * nodes with declared deps and graph-visible facts. This file intentionally\n * owns no storage restore/hydration, scheduler, hidden subscription, vector DB,\n * retention loop, consolidation loop, Graph subclass, or protocol behavior.\n */\n\nimport { depBatch, depLatest } from \"../ctx/types.js\";\nimport type { Graph } from \"../graph/graph.js\";\nimport type { Node } from \"../node/node.js\";\nimport type { FactId, MemoryAnswer, MemoryFragment } from \"./semantic-memory.js\";\nimport type {\n\tKnowledgeGraphCursor,\n\tKnowledgeGraphReducerBundle,\n\tKnowledgeGraphReducerBundleOptions,\n\tKnowledgeGraphSnapshot,\n\tKnowledgeGraphStatus,\n\tMemoryRetrievalBundle,\n\tMemoryRetrievalBundleOptions,\n\tMemoryRetrievalCursor,\n\tMemoryRetrievalError,\n\tMemoryRetrievalIndex,\n\tMemoryRetrievalSnapshot,\n\tMemoryRetrievalStatus,\n} from \"./semantic-memory-graph-types.js\";\nimport {\n\tindexById,\n\tisRecoverableFragmentError,\n\trankFragments,\n\treduceKnowledgeAssertions,\n\tsafeArrayLength,\n\tstatusState,\n\tvalidateAndSnapshotFragment,\n\tvalidateKnowledgeGraphPolicy,\n\tvalidateMemoryRetrievalQuery,\n} from \"./semantic-memory-graph-utils.js\";\n\nexport type {\n\tKnowledgeGraphCursor,\n\tKnowledgeGraphEntity,\n\tKnowledgeGraphError,\n\tKnowledgeGraphErrorCode,\n\tKnowledgeGraphIndex,\n\tKnowledgeGraphPolicy,\n\tKnowledgeGraphReducerBundle,\n\tKnowledgeGraphReducerBundleOptions,\n\tKnowledgeGraphRelation,\n\tKnowledgeGraphSnapshot,\n\tKnowledgeGraphStatus,\n\tKnowledgeGraphStatusState,\n\tKnowledgeGraphTopic,\n\tMemoryRetrievalBundle,\n\tMemoryRetrievalBundleOptions,\n\tMemoryRetrievalCursor,\n\tMemoryRetrievalError,\n\tMemoryRetrievalErrorCode,\n\tMemoryRetrievalFact,\n\tMemoryRetrievalIndex,\n\tMemoryRetrievalQuery,\n\tMemoryRetrievalSnapshot,\n\tMemoryRetrievalStatus,\n\tMemoryRetrievalStatusState,\n} from \"./semantic-memory-graph-types.js\";\n\ninterface MemoryRetrievalRuntimeState {\n\tevaluation: number;\n}\n\n/**\n * Build a graph-visible memory retrieval bundle from explicit fragment/query deps.\n *\n * Invalid fragments and ranking status are emitted as ordinary DATA facts. The\n * bundle never owns storage restore or hidden mutation; callers that need\n * persistence compose D161 collection/storage sidecars outside this pattern.\n */\nexport function memoryRetrievalBundle<T = unknown>(\n\tgraph: Graph,\n\topts: MemoryRetrievalBundleOptions,\n): MemoryRetrievalBundle<T> {\n\tconst name = opts.name ?? \"memoryRetrieval\";\n\tconst { fragments, query } = opts;\n\tconst snapshot = graph.node<MemoryRetrievalSnapshot<T>>(\n\t\t[fragments, query],\n\t\t(ctx) => {\n\t\t\tconst state =\n\t\t\t\tctx.state.get<MemoryRetrievalRuntimeState>() ??\n\t\t\t\t({ evaluation: 0 } satisfies MemoryRetrievalRuntimeState);\n\t\t\tstate.evaluation += 1;\n\t\t\tconst rawFragments = depLatest(ctx, 0);\n\t\t\tconst rawQuery = depLatest(ctx, 1);\n\t\t\tconst queryValidation = validateMemoryRetrievalQuery(rawQuery);\n\t\t\tconst currentQuery = queryValidation.query;\n\t\t\tconst valid: MemoryFragment<T>[] = [];\n\t\t\tconst seenIds = new Set<FactId>();\n\t\t\tconst errors: Omit<MemoryRetrievalError, \"cursor\">[] = [...queryValidation.errors];\n\n\t\t\tif (!Array.isArray(rawFragments)) {\n\t\t\t\terrors.push({\n\t\t\t\t\tcode: \"invalid-fragments-input\",\n\t\t\t\t\tmessage: \"memoryRetrievalBundle: fragments input must be an array\",\n\t\t\t\t\tfragment: rawFragments,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tconst length = safeArrayLength(rawFragments);\n\t\t\t\tif (length === undefined) {\n\t\t\t\t\terrors.push({\n\t\t\t\t\t\tcode: \"invalid-fragments-input\",\n\t\t\t\t\t\tmessage: \"memoryRetrievalBundle: fragments input length could not be read\",\n\t\t\t\t\t\tfragment: rawFragments,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tfor (let i = 0; i < (length ?? 0); i += 1) {\n\t\t\t\t\tconst result = validateAndSnapshotFragment<T>(rawFragments, i);\n\t\t\t\t\tif (result.error !== undefined) {\n\t\t\t\t\t\terrors.push(result.error);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst fragment = result.fragment as MemoryFragment<T>;\n\t\t\t\t\tif (seenIds.has(fragment.id)) {\n\t\t\t\t\t\terrors.push({\n\t\t\t\t\t\t\tcode: \"duplicate-fragment-id\",\n\t\t\t\t\t\t\tmessage: \"memoryRetrievalBundle: duplicate fragment id\",\n\t\t\t\t\t\t\tindex: i,\n\t\t\t\t\t\t\tfragment,\n\t\t\t\t\t\t\tvalidationErrors: [`duplicate fragment id '${fragment.id}'`],\n\t\t\t\t\t\t});\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tseenIds.add(fragment.id);\n\t\t\t\t\tvalid.push(fragment);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst ranked = errors.some((error) => !isRecoverableFragmentError(error))\n\t\t\t\t? []\n\t\t\t\t: rankFragments(valid, currentQuery);\n\t\t\tconst cursor: MemoryRetrievalCursor = Object.freeze({\n\t\t\t\tevaluation: state.evaluation,\n\t\t\t\tvalidFragments: valid.length,\n\t\t\t\tinvalidFragments: errors.filter(\n\t\t\t\t\t(error) => error.code === \"invalid-fragment\" || error.code === \"duplicate-fragment-id\",\n\t\t\t\t).length,\n\t\t\t\tresultCount: ranked.length,\n\t\t\t});\n\t\t\tctx.state.set(state);\n\t\t\tconst answer: MemoryAnswer<T> = Object.freeze({\n\t\t\t\tquery: currentQuery,\n\t\t\t\tresults: Object.freeze(ranked),\n\t\t\t});\n\t\t\tconst status: MemoryRetrievalStatus = Object.freeze({\n\t\t\t\tstate: statusState(errors, ranked.length),\n\t\t\t\tquery: currentQuery,\n\t\t\t\tcursor,\n\t\t\t});\n\t\t\tconst indexed: MemoryRetrievalIndex<T> = Object.freeze({\n\t\t\t\tids: Object.freeze(valid.map((fragment) => fragment.id)),\n\t\t\t\tbyId: indexById(valid),\n\t\t\t\tcursor,\n\t\t\t});\n\t\t\tconst errorFacts = Object.freeze(\n\t\t\t\terrors.map((error) =>\n\t\t\t\t\tObject.freeze({\n\t\t\t\t\t\t...error,\n\t\t\t\t\t\t...(error.validationErrors === undefined\n\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t: { validationErrors: Object.freeze([...error.validationErrors]) }),\n\t\t\t\t\t\tcursor,\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t);\n\n\t\t\tctx.down([\n\t\t\t\t[\n\t\t\t\t\t\"DATA\",\n\t\t\t\t\tObject.freeze({\n\t\t\t\t\t\tfragments: Object.freeze([...valid]),\n\t\t\t\t\t\tindexed,\n\t\t\t\t\t\tranked: answer,\n\t\t\t\t\t\tstatus,\n\t\t\t\t\t\terrors: errorFacts,\n\t\t\t\t\t\tcursor,\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t]);\n\t\t},\n\t\t{\n\t\t\tname: `${name}/snapshot`,\n\t\t\tfactory: \"memoryRetrievalSnapshot\",\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\treturn {\n\t\tinput: { fragments, query },\n\t\tsnapshot,\n\t\tfragments: retrievalProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/fragments`,\n\t\t\t\"memoryRetrievalFragments\",\n\t\t\t(fact) => fact.fragments,\n\t\t),\n\t\tindexed: retrievalProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/indexed`,\n\t\t\t\"memoryRetrievalIndexed\",\n\t\t\t(fact) => fact.indexed,\n\t\t),\n\t\tranked: retrievalProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/ranked`,\n\t\t\t\"memoryRetrievalRanked\",\n\t\t\t(fact) => fact.ranked,\n\t\t),\n\t\tstatus: retrievalProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/status`,\n\t\t\t\"memoryRetrievalStatus\",\n\t\t\t(fact) => fact.status,\n\t\t),\n\t\terrors: retrievalProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/errors`,\n\t\t\t\"memoryRetrievalErrors\",\n\t\t\t(fact) => fact.errors,\n\t\t),\n\t\tcursor: retrievalProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/cursor`,\n\t\t\t\"memoryRetrievalCursor\",\n\t\t\t(fact) => fact.cursor,\n\t\t),\n\t};\n}\n\n/**\n * D170 lower semantic-memory KG materializer.\n *\n * Assertion, entity, relation, and topic ids remain DATA keys. The bundle has\n * static describe-visible topology and owns no storage, LLM extraction,\n * scheduler, agent runtime, or dynamic graph node lifecycle.\n */\nexport function knowledgeGraphReducerBundle(\n\tgraph: Graph,\n\topts: KnowledgeGraphReducerBundleOptions,\n): KnowledgeGraphReducerBundle {\n\tconst name = opts.name ?? \"knowledgeGraph\";\n\tconst deps = opts.policy === undefined ? [opts.assertions] : [opts.assertions, opts.policy];\n\tconst snapshot = graph.node<KnowledgeGraphSnapshot>(\n\t\tdeps,\n\t\t(ctx) => {\n\t\t\tconst state =\n\t\t\t\tctx.state.get<{ evaluation: number }>() ??\n\t\t\t\t({ evaluation: 0 } satisfies { evaluation: number });\n\t\t\tstate.evaluation += 1;\n\t\t\tconst policy = validateKnowledgeGraphPolicy(\n\t\t\t\topts.policy === undefined ? undefined : depLatest(ctx, 1),\n\t\t\t);\n\t\t\tconst reduced = reduceKnowledgeAssertions(depLatest(ctx, 0), policy.policy);\n\t\t\tconst pendingErrors = [...policy.errors, ...reduced.errors];\n\t\t\tconst cursor: KnowledgeGraphCursor = Object.freeze({\n\t\t\t\tevaluation: state.evaluation,\n\t\t\t\tvalidAssertions: reduced.assertions.length,\n\t\t\t\tinvalidAssertions: reduced.invalidAssertions,\n\t\t\t\tentityCount: reduced.entities.length,\n\t\t\t\trelationCount: reduced.relations.length,\n\t\t\t\tpredicateCount: reduced.topics.length,\n\t\t\t});\n\t\t\tconst errors = Object.freeze(\n\t\t\t\tpendingErrors.map((error) =>\n\t\t\t\t\tObject.freeze({\n\t\t\t\t\t\t...error,\n\t\t\t\t\t\t...(error.validationErrors === undefined\n\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t: { validationErrors: Object.freeze([...error.validationErrors]) }),\n\t\t\t\t\t\tcursor,\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t);\n\t\t\tconst status: KnowledgeGraphStatus = Object.freeze({\n\t\t\t\tstate:\n\t\t\t\t\treduced.assertions.length === 0 && errors.length === 0\n\t\t\t\t\t\t? \"empty\"\n\t\t\t\t\t\t: errors.length === 0\n\t\t\t\t\t\t\t? \"ready\"\n\t\t\t\t\t\t\t: reduced.assertions.length > 0\n\t\t\t\t\t\t\t\t? \"partial\"\n\t\t\t\t\t\t\t\t: \"error\",\n\t\t\t\tcursor,\n\t\t\t});\n\t\t\tctx.state.set(state);\n\t\t\tctx.down([\n\t\t\t\t[\n\t\t\t\t\t\"DATA\",\n\t\t\t\t\tObject.freeze({\n\t\t\t\t\t\tassertions: Object.freeze(reduced.assertions),\n\t\t\t\t\t\tentities: Object.freeze(reduced.entities),\n\t\t\t\t\t\trelations: Object.freeze(reduced.relations),\n\t\t\t\t\t\ttopics: Object.freeze(reduced.topics),\n\t\t\t\t\t\tindex: reduced.index,\n\t\t\t\t\t\tstatus,\n\t\t\t\t\t\terrors,\n\t\t\t\t\t\tcursor,\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t]);\n\t\t},\n\t\t{\n\t\t\tname: `${name}/snapshot`,\n\t\t\tfactory: \"knowledgeGraphReducerSnapshot\",\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\treturn {\n\t\tinput: {\n\t\t\tassertions: opts.assertions,\n\t\t\t...(opts.policy === undefined ? {} : { policy: opts.policy }),\n\t\t},\n\t\tsnapshot,\n\t\tassertions: kgProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/assertions`,\n\t\t\t\"knowledgeGraphAssertions\",\n\t\t\t(fact) => fact.assertions,\n\t\t),\n\t\tentities: kgProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/entities`,\n\t\t\t\"knowledgeGraphEntities\",\n\t\t\t(fact) => fact.entities,\n\t\t),\n\t\trelations: kgProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/relations`,\n\t\t\t\"knowledgeGraphRelations\",\n\t\t\t(fact) => fact.relations,\n\t\t),\n\t\ttopics: kgProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/topics`,\n\t\t\t\"knowledgeGraphTopics\",\n\t\t\t(fact) => fact.topics,\n\t\t),\n\t\tindex: kgProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/index`,\n\t\t\t\"knowledgeGraphIndex\",\n\t\t\t(fact) => fact.index,\n\t\t),\n\t\tstatus: kgProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/status`,\n\t\t\t\"knowledgeGraphStatus\",\n\t\t\t(fact) => fact.status,\n\t\t),\n\t\terrors: kgProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/errors`,\n\t\t\t\"knowledgeGraphErrors\",\n\t\t\t(fact) => fact.errors,\n\t\t),\n\t\tcursor: kgProjection(\n\t\t\tgraph,\n\t\t\tsnapshot,\n\t\t\t`${name}/cursor`,\n\t\t\t\"knowledgeGraphCursor\",\n\t\t\t(fact) => fact.cursor,\n\t\t),\n\t};\n}\n\nfunction retrievalProjection<TFact, T>(\n\tgraph: Graph,\n\tsnapshot: Node<MemoryRetrievalSnapshot<T>>,\n\tname: string,\n\tfactory: string,\n\tselect: (fact: MemoryRetrievalSnapshot<T>) => TFact | undefined,\n): Node<TFact> {\n\treturn graph.node<TFact>(\n\t\t[snapshot],\n\t\t(ctx) => {\n\t\t\tfor (const raw of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst fact = raw as MemoryRetrievalSnapshot<T>;\n\t\t\t\tconst selected = select(fact);\n\t\t\t\tif (selected !== undefined) ctx.down([[\"DATA\", selected]]);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname,\n\t\t\tfactory,\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n}\n\nfunction kgProjection<TFact>(\n\tgraph: Graph,\n\tsnapshot: Node<KnowledgeGraphSnapshot>,\n\tname: string,\n\tfactory: string,\n\tselect: (fact: KnowledgeGraphSnapshot) => TFact,\n): Node<TFact> {\n\treturn graph.node<TFact>(\n\t\t[snapshot],\n\t\t(ctx) => {\n\t\t\tfor (const raw of depBatch(ctx, 0) ?? []) {\n\t\t\t\tctx.down([[\"DATA\", select(raw as KnowledgeGraphSnapshot)]]);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname,\n\t\t\tfactory,\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC2CO,IAAM,WAAW;;;AClBjB,IAAM,gBAA+B,uBAAO,yBAAyB;AAsIrE,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,IAAI,CAAC,IAAI;AACtC;AAGO,SAAS,UAAU,KAAU,UAA2B;AAC9D,SAAO,IAAI,aAAa,GAAG,OAAO,QAAQ;AAC3C;;;ACnHO,SAAS,eAAe,OAAkD;AAChF,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC3E;;;AC9BO,SAAS,kBAAkB,OAAuC;AACxE,MAAI,CAAC,eAAe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,GAAG,IAAI;AAAA,MACP;AAAA,MACA,CAAC,SAAS,KAAK;AAAA,IAChB;AAAA,EACD;AACD;AAEA,SAAS,oBACR,OACA,UACA,MACA,SACA,QACc;AACd,SAAO,MAAM;AAAA,IACZ,CAAC,QAAQ;AAAA,IACT,CAAC,QAAQ;AACR,iBAAW,OAAO,SAAS,KAAK,CAAC,KAAK,CAAC,GAAG;AACzC,cAAM,OAAO;AACb,cAAM,WAAW,OAAO,IAAI;AAC5B,YAAI,aAAa,OAAW,KAAI,KAAK,CAAC,CAAC,QAAQ,QAAQ,CAAC,CAAC;AAAA,MAC1D;AAAA,IACD;AAAA,IACA;AAAA,MACC;AAAA,MACA;AAAA,MACA,0BAA0B;AAAA,MAC1B,oBAAoB;AAAA,IACrB;AAAA,EACD;AACD;AAEA,SAAS,aACR,OACA,UACA,MACA,SACA,QACc;AACd,SAAO,MAAM;AAAA,IACZ,CAAC,QAAQ;AAAA,IACT,CAAC,QAAQ;AACR,iBAAW,OAAO,SAAS,KAAK,CAAC,KAAK,CAAC,GAAG;AACzC,YAAI,KAAK,CAAC,CAAC,QAAQ,OAAO,GAA6B,CAAC,CAAC,CAAC;AAAA,MAC3D;AAAA,IACD;AAAA,IACA;AAAA,MACC;AAAA,MACA;AAAA,MACA,0BAA0B;AAAA,MAC1B,oBAAoB;AAAA,IACrB;AAAA,EACD;AACD;","names":["status","audit","isDenseArrayOf","compareBigIntDesc"]}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export { EventFlowAuditRecord, EventFlowBundle, EventFlowHighWater, EventFlowOptions, EventFlowProjectionBundle, EventFlowProjectionFrame, EventFlowProjectionOptions, EventFlowProjectionStatus, EventFlowRecord, EventFlowSource, EventFlowSourceHighWater, EventFlowSourceInput, EventFlowSourceRef, EventFlowStatus, eventFlow, eventFlowProjection } from './event-flow.cjs';
|
|
2
|
+
import { N as NodeProfile, d as Graph } from '../graph-CWK3HLPB.cjs';
|
|
3
|
+
export { A as AdmissionFilter, q as AdmissionScore3DOptions, r as AdmissionScoredOptions, s as AdmissionScores, t as AdmissionThresholds, C as CollectionEntry, u as CollectionScoreFn, D as DecayPolicy, F as FactId, v as FactStore, K as KnowledgeAssertion, a as KnowledgeAssertionObject, b as KnowledgeAssertionStrictJsonValue, c as KnowledgeAssertionSubject, d as KnowledgeGraphCursor, e as KnowledgeGraphEntity, f as KnowledgeGraphError, g as KnowledgeGraphErrorCode, h as KnowledgeGraphIndex, i as KnowledgeGraphPolicy, j as KnowledgeGraphReducerBundle, k as KnowledgeGraphReducerBundleOptions, l as KnowledgeGraphRelation, m as KnowledgeGraphSnapshot, n as KnowledgeGraphStatus, o as KnowledgeGraphStatusState, p as KnowledgeGraphTopic, M as MemoryAnswer, w as MemoryFragment, x as MemoryFragmentValidation, y as MemoryQuery, z as MemoryRetrievalBundle, B as MemoryRetrievalBundleOptions, E as MemoryRetrievalCursor, G as MemoryRetrievalError, H as MemoryRetrievalErrorCode, I as MemoryRetrievalFact, J as MemoryRetrievalIndex, L as MemoryRetrievalQuery, N as MemoryRetrievalSnapshot, O as MemoryRetrievalStatus, P as MemoryRetrievalStatusState, Q as OutcomeSignal, R as RankedCollectionEntry, S as RetrievalEntry, T as RetrievalQuery, U as RetrievalTrace, V as ScoringPolicy, W as ShardByTenantConfig, X as ShardByTenantOptions, Y as ShardKey, Z as StoreReadHandle, _ as VectorSearchResult, $ as admissionFilter3D, a0 as admissionScored, a1 as cosineSimilarity, a2 as filterMemoryFragments, a3 as isMemoryFragment, a4 as memoryFragmentMatchesQuery, a5 as memoryFragmentValidAt, a6 as shardByTenant, a7 as validateMemoryFragment } from '../semantic-memory-graph-types-BvzdqmkY.cjs';
|
|
4
|
+
export { k as knowledgeGraphReducerBundle, m as memoryRetrievalBundle } from '../semantic-memory-graph-DlZBD_Eu.cjs';
|
|
5
|
+
import '../data/index.cjs';
|
|
6
|
+
import '../types-BS6CyR-x.cjs';
|
|
7
|
+
import '../messages-CAzUPPJM.cjs';
|
|
8
|
+
import '../types-BhveCMg5.cjs';
|
|
3
9
|
import '../core/index.cjs';
|
|
4
|
-
import '../types-bNMSWKqF.cjs';
|
|
5
|
-
import '../messages-BZqrGGm1.cjs';
|
|
6
10
|
import '../codec-BB7p8fJc.cjs';
|
|
7
|
-
import '../describe-
|
|
11
|
+
import '../describe-CQRrkv-Q.cjs';
|
|
8
12
|
|
|
9
13
|
/**
|
|
10
14
|
* Horizontal inspection patterns re-derived from old presets (B62 / D125).
|
package/dist/patterns/index.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export { EventFlowAuditRecord, EventFlowBundle, EventFlowHighWater, EventFlowOptions, EventFlowProjectionBundle, EventFlowProjectionFrame, EventFlowProjectionOptions, EventFlowProjectionStatus, EventFlowRecord, EventFlowSource, EventFlowSourceHighWater, EventFlowSourceInput, EventFlowSourceRef, EventFlowStatus, eventFlow, eventFlowProjection } from './event-flow.js';
|
|
2
|
+
import { N as NodeProfile, d as Graph } from '../graph-ho5sotHP.js';
|
|
3
|
+
export { A as AdmissionFilter, q as AdmissionScore3DOptions, r as AdmissionScoredOptions, s as AdmissionScores, t as AdmissionThresholds, C as CollectionEntry, u as CollectionScoreFn, D as DecayPolicy, F as FactId, v as FactStore, K as KnowledgeAssertion, a as KnowledgeAssertionObject, b as KnowledgeAssertionStrictJsonValue, c as KnowledgeAssertionSubject, d as KnowledgeGraphCursor, e as KnowledgeGraphEntity, f as KnowledgeGraphError, g as KnowledgeGraphErrorCode, h as KnowledgeGraphIndex, i as KnowledgeGraphPolicy, j as KnowledgeGraphReducerBundle, k as KnowledgeGraphReducerBundleOptions, l as KnowledgeGraphRelation, m as KnowledgeGraphSnapshot, n as KnowledgeGraphStatus, o as KnowledgeGraphStatusState, p as KnowledgeGraphTopic, M as MemoryAnswer, w as MemoryFragment, x as MemoryFragmentValidation, y as MemoryQuery, z as MemoryRetrievalBundle, B as MemoryRetrievalBundleOptions, E as MemoryRetrievalCursor, G as MemoryRetrievalError, H as MemoryRetrievalErrorCode, I as MemoryRetrievalFact, J as MemoryRetrievalIndex, L as MemoryRetrievalQuery, N as MemoryRetrievalSnapshot, O as MemoryRetrievalStatus, P as MemoryRetrievalStatusState, Q as OutcomeSignal, R as RankedCollectionEntry, S as RetrievalEntry, T as RetrievalQuery, U as RetrievalTrace, V as ScoringPolicy, W as ShardByTenantConfig, X as ShardByTenantOptions, Y as ShardKey, Z as StoreReadHandle, _ as VectorSearchResult, $ as admissionFilter3D, a0 as admissionScored, a1 as cosineSimilarity, a2 as filterMemoryFragments, a3 as isMemoryFragment, a4 as memoryFragmentMatchesQuery, a5 as memoryFragmentValidAt, a6 as shardByTenant, a7 as validateMemoryFragment } from '../semantic-memory-graph-types-Ci-OtahO.js';
|
|
4
|
+
export { k as knowledgeGraphReducerBundle, m as memoryRetrievalBundle } from '../semantic-memory-graph-C2ZUwIlq.js';
|
|
5
|
+
import '../data/index.js';
|
|
6
|
+
import '../types-C9NOgNJw.js';
|
|
7
|
+
import '../messages-CAzUPPJM.js';
|
|
8
|
+
import '../types-CTsQ8Ww4.js';
|
|
3
9
|
import '../core/index.js';
|
|
4
|
-
import '../types-h12mNYbq.js';
|
|
5
|
-
import '../messages-BZqrGGm1.js';
|
|
6
10
|
import '../codec-BB7p8fJc.js';
|
|
7
|
-
import '../describe-
|
|
11
|
+
import '../describe-B_A5fbXH.js';
|
|
8
12
|
|
|
9
13
|
/**
|
|
10
14
|
* Horizontal inspection patterns re-derived from old presets (B62 / D125).
|