@e4779/pi-fabric 0.102.0-fork.16 → 0.105.0-fork.22
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 +44 -13
- package/THIRD_PARTY_NOTICES.md +10 -2
- package/dist/activity/store.d.ts +3 -0
- package/dist/activity/store.d.ts.map +1 -1
- package/dist/activity/workflow-items.d.ts +33 -0
- package/dist/activity/workflow-items.d.ts.map +1 -0
- package/dist/actors/binding-store.d.ts.map +1 -1
- package/dist/actors/manager.d.ts +6 -0
- package/dist/actors/manager.d.ts.map +1 -1
- package/dist/actors/mesh-monitor.d.ts +2 -2
- package/dist/actors/mesh-monitor.d.ts.map +1 -1
- package/dist/actors/registry-store.d.ts.map +1 -1
- package/dist/actors/types.d.ts +11 -0
- package/dist/actors/types.d.ts.map +1 -1
- package/dist/agents/child-env.d.ts +29 -0
- package/dist/agents/child-env.d.ts.map +1 -0
- package/dist/agents/fork-seed.d.ts +21 -0
- package/dist/agents/fork-seed.d.ts.map +1 -0
- package/dist/agents/handoff.d.ts +7 -1
- package/dist/agents/handoff.d.ts.map +1 -1
- package/dist/agents/hosted-run.d.ts +63 -0
- package/dist/agents/hosted-run.d.ts.map +1 -0
- package/dist/agents/manager.d.ts +21 -1
- package/dist/agents/manager.d.ts.map +1 -1
- package/dist/agents/request.d.ts.map +1 -1
- package/dist/agents/runner-notice.d.ts +7 -0
- package/dist/agents/runner-notice.d.ts.map +1 -0
- package/dist/agents/runner-protocol.d.ts +158 -0
- package/dist/agents/runner-protocol.d.ts.map +1 -0
- package/dist/agents/runner-registry.d.ts +223 -0
- package/dist/agents/runner-registry.d.ts.map +1 -0
- package/dist/agents/transports/process-transport.d.ts.map +1 -1
- package/dist/agents/transports/process-utils.d.ts +4 -1
- package/dist/agents/transports/process-utils.d.ts.map +1 -1
- package/dist/agents/types.d.ts +89 -4
- package/dist/agents/types.d.ts.map +1 -1
- package/dist/agents/worktree-manager.d.ts +21 -0
- package/dist/agents/worktree-manager.d.ts.map +1 -1
- package/dist/agents/write-guard.d.ts +16 -0
- package/dist/agents/write-guard.d.ts.map +1 -0
- package/dist/agents/write-guard.js +13 -0
- package/dist/agents/write-guard.js.map +7 -0
- package/dist/agents.js +13 -12
- package/dist/agents.js.map +1 -1
- package/dist/assessment.d.ts +3 -0
- package/dist/assessment.d.ts.map +1 -0
- package/dist/assessment.js +15 -0
- package/dist/assessment.js.map +7 -0
- package/dist/audit/assessment.d.ts +74 -0
- package/dist/audit/assessment.d.ts.map +1 -0
- package/dist/audit/details.d.ts +4 -0
- package/dist/audit/details.d.ts.map +1 -1
- package/dist/audit/index.d.ts +1 -0
- package/dist/audit/index.d.ts.map +1 -1
- package/dist/audit/projection.d.ts +2 -1
- package/dist/audit/projection.d.ts.map +1 -1
- package/dist/audit/trace.d.ts +16 -1
- package/dist/audit/trace.d.ts.map +1 -1
- package/dist/cache/leases.d.ts +2 -1
- package/dist/cache/leases.d.ts.map +1 -1
- package/dist/capture/interceptor.d.ts.map +1 -1
- package/dist/chunks/chunk-2USMWEE6.js +81 -0
- package/dist/chunks/chunk-2USMWEE6.js.map +7 -0
- package/dist/chunks/chunk-2Y24ML7H.js +115 -0
- package/dist/chunks/chunk-2Y24ML7H.js.map +7 -0
- package/dist/chunks/chunk-3GJJG2FV.js +1329 -0
- package/dist/chunks/chunk-3GJJG2FV.js.map +7 -0
- package/dist/chunks/{chunk-5VTBHJN3.js → chunk-3KDUMDPZ.js} +153 -29
- package/dist/chunks/chunk-3KDUMDPZ.js.map +7 -0
- package/dist/chunks/chunk-4RTHQGES.js +189 -0
- package/dist/chunks/chunk-4RTHQGES.js.map +7 -0
- package/dist/chunks/{chunk-ZZ66L3W5.js → chunk-5MNLVHF5.js} +30 -7
- package/dist/chunks/chunk-5MNLVHF5.js.map +7 -0
- package/dist/chunks/{chunk-RAO6TQFP.js → chunk-5XBYFSI5.js} +26 -6
- package/dist/chunks/chunk-5XBYFSI5.js.map +7 -0
- package/dist/chunks/{chunk-J2HV2URQ.js → chunk-7EYJE4TW.js} +1 -1
- package/dist/chunks/{chunk-J2HV2URQ.js.map → chunk-7EYJE4TW.js.map} +2 -2
- package/dist/chunks/{chunk-57CMH4SW.js → chunk-7JU7Z4XQ.js} +2 -2
- package/dist/chunks/chunk-7QKKLBHJ.js +33 -0
- package/dist/chunks/chunk-7QKKLBHJ.js.map +7 -0
- package/dist/chunks/chunk-7XRUMDV7.js +235 -0
- package/dist/chunks/chunk-7XRUMDV7.js.map +7 -0
- package/dist/chunks/{chunk-DUJ46TIP.js → chunk-ABJCSNZO.js} +4 -4
- package/dist/chunks/chunk-B2Y4364O.js +78 -0
- package/dist/chunks/chunk-B2Y4364O.js.map +7 -0
- package/dist/chunks/{chunk-4TKPBEPB.js → chunk-BVJBYFHD.js} +9 -3
- package/dist/chunks/{chunk-4TKPBEPB.js.map → chunk-BVJBYFHD.js.map} +2 -2
- package/dist/chunks/{chunk-KP4ANT6L.js → chunk-C7EEG6SM.js} +2 -2
- package/dist/chunks/{chunk-NHMICIEU.js → chunk-CCHZXF6K.js} +3 -3
- package/dist/chunks/{chunk-W63E3WEO.js → chunk-CXTTLBUV.js} +3 -2
- package/dist/chunks/chunk-CXTTLBUV.js.map +7 -0
- package/dist/chunks/{chunk-HOX6VW45.js → chunk-CYMDX3XP.js} +1 -1
- package/dist/chunks/{chunk-HOX6VW45.js.map → chunk-CYMDX3XP.js.map} +1 -1
- package/dist/chunks/chunk-DK35W6U7.js +259 -0
- package/dist/chunks/chunk-DK35W6U7.js.map +7 -0
- package/dist/chunks/{chunk-5JN5AWNV.js → chunk-DZ4WN5XJ.js} +3 -3
- package/dist/chunks/chunk-EXWS4ZS3.js +6490 -0
- package/dist/chunks/chunk-EXWS4ZS3.js.map +7 -0
- package/dist/chunks/{chunk-QHYBSIIO.js → chunk-FB24AOIJ.js} +39 -37
- package/dist/chunks/{chunk-QHYBSIIO.js.map → chunk-FB24AOIJ.js.map} +1 -1
- package/dist/chunks/chunk-FSB2VIRZ.js +435 -0
- package/dist/chunks/chunk-FSB2VIRZ.js.map +7 -0
- package/dist/chunks/{chunk-PNDYFU64.js → chunk-GJVPP3NN.js} +81 -11
- package/dist/chunks/chunk-GJVPP3NN.js.map +7 -0
- package/dist/chunks/{chunk-B5D6GA77.js → chunk-GYPDGW27.js} +100 -92
- package/dist/chunks/chunk-GYPDGW27.js.map +7 -0
- package/dist/chunks/{chunk-LEFBW2GK.js → chunk-IAFI4A2I.js} +44 -2
- package/dist/chunks/{chunk-LEFBW2GK.js.map → chunk-IAFI4A2I.js.map} +3 -3
- package/dist/chunks/{chunk-PWS2OXLV.js → chunk-IIPKG52D.js} +1 -1
- package/dist/chunks/chunk-IIPKG52D.js.map +7 -0
- package/dist/chunks/chunk-ITVLKXCI.js +266 -0
- package/dist/chunks/chunk-ITVLKXCI.js.map +7 -0
- package/dist/chunks/chunk-JKQARSWR.js +265 -0
- package/dist/chunks/chunk-JKQARSWR.js.map +7 -0
- package/dist/chunks/{chunk-AYBIR4YV.js → chunk-KJZAOENY.js} +6 -4
- package/dist/chunks/chunk-KJZAOENY.js.map +7 -0
- package/dist/chunks/{chunk-74BA4VSX.js → chunk-KQ6R5EWR.js} +1462 -1405
- package/dist/chunks/chunk-KQ6R5EWR.js.map +7 -0
- package/dist/chunks/chunk-L22K5BWU.js +180 -0
- package/dist/chunks/chunk-L22K5BWU.js.map +7 -0
- package/dist/chunks/{chunk-7XJB2USB.js → chunk-LOLCTWJF.js} +4 -4
- package/dist/chunks/{chunk-QETG2GVX.js → chunk-M5IN6DMF.js} +34 -31
- package/dist/chunks/chunk-M5IN6DMF.js.map +7 -0
- package/dist/chunks/{chunk-64O5L7EW.js → chunk-M6IRQ3QT.js} +2 -2
- package/dist/chunks/{chunk-TX6E5W7H.js → chunk-NTC2MCB6.js} +1 -1
- package/dist/chunks/chunk-NTC2MCB6.js.map +7 -0
- package/dist/chunks/{chunk-EPYLZWJV.js → chunk-OVBKQCYL.js} +2 -2
- package/dist/chunks/{chunk-YV2PHCDB.js → chunk-PYFJW3HC.js} +16 -2
- package/dist/chunks/{chunk-YV2PHCDB.js.map → chunk-PYFJW3HC.js.map} +3 -3
- package/dist/chunks/{chunk-Z5Y65YBX.js → chunk-PYQM7KPL.js} +3 -2
- package/dist/chunks/{chunk-BEJF2JX2.js → chunk-QLFDPXK7.js} +33 -2
- package/dist/chunks/chunk-QLFDPXK7.js.map +7 -0
- package/dist/chunks/chunk-QUWC6YCN.js +125 -0
- package/dist/chunks/chunk-QUWC6YCN.js.map +7 -0
- package/dist/chunks/{chunk-DKVJREDI.js → chunk-QY7YK7M6.js} +2 -2
- package/dist/chunks/{chunk-WMJ2AVQQ.js → chunk-R5F6CHW2.js} +34 -18
- package/dist/chunks/chunk-R5F6CHW2.js.map +7 -0
- package/dist/chunks/chunk-S3IRPDSO.js +57 -0
- package/dist/chunks/chunk-S3IRPDSO.js.map +7 -0
- package/dist/chunks/{chunk-7BG5COXB.js → chunk-SVDHQUTM.js} +21 -4
- package/dist/chunks/chunk-SVDHQUTM.js.map +7 -0
- package/dist/chunks/{chunk-HG4DMARW.js → chunk-T5CU2GPZ.js} +116 -26
- package/dist/chunks/chunk-T5CU2GPZ.js.map +7 -0
- package/dist/chunks/{chunk-RIFG4HS6.js → chunk-TFFZVLR2.js} +141 -9
- package/dist/chunks/chunk-TFFZVLR2.js.map +7 -0
- package/dist/chunks/{chunk-BUQZBG6O.js → chunk-U2UBUKNQ.js} +136 -136
- package/dist/chunks/chunk-U2UBUKNQ.js.map +7 -0
- package/dist/chunks/chunk-U366I5K2.js +363 -0
- package/dist/chunks/chunk-U366I5K2.js.map +7 -0
- package/dist/chunks/{chunk-4NF3S3NM.js → chunk-UTOBAZ5T.js} +1 -1
- package/dist/chunks/chunk-UTOBAZ5T.js.map +7 -0
- package/dist/chunks/chunk-V73NIH6B.js +127 -0
- package/dist/chunks/chunk-V73NIH6B.js.map +7 -0
- package/dist/chunks/{chunk-PN4EKNRE.js → chunk-VON4TSO3.js} +132 -12
- package/dist/chunks/chunk-VON4TSO3.js.map +7 -0
- package/dist/chunks/{chunk-5ZJV4LAX.js → chunk-VPRJOD4Y.js} +4 -4
- package/dist/chunks/{chunk-FDIEQEXS.js → chunk-VSDUSNIA.js} +4 -4
- package/dist/chunks/chunk-VSDUSNIA.js.map +7 -0
- package/dist/chunks/{chunk-RG22JKIC.js → chunk-W7X4XEQU.js} +2 -2
- package/dist/chunks/{chunk-LV4IT75S.js → chunk-WLLXKS6I.js} +2 -2
- package/dist/chunks/chunk-WOLUDZVR.js +197 -0
- package/dist/chunks/chunk-WOLUDZVR.js.map +7 -0
- package/dist/chunks/{chunk-YVDBHS4C.js → chunk-WREA4RNR.js} +3 -3
- package/dist/chunks/{chunk-QE2JFB7F.js → chunk-WYUV6WL3.js} +16 -6
- package/dist/chunks/chunk-WYUV6WL3.js.map +7 -0
- package/dist/chunks/{chunk-NGGI6LDC.js → chunk-X2TRSE7D.js} +2 -2
- package/dist/chunks/{chunk-VRAGOMN4.js → chunk-YRDCJZZW.js} +34 -1
- package/dist/chunks/chunk-YRDCJZZW.js.map +7 -0
- package/dist/chunks/{chunk-CC63CY6R.js → chunk-YYSZBD7S.js} +17 -261
- package/dist/chunks/chunk-YYSZBD7S.js.map +7 -0
- package/dist/chunks/{chunk-A4VP7HDF.js → chunk-ZLNJDTCN.js} +2 -2
- package/dist/chunks/{chunk-G4CSXNBT.js → chunk-ZXKYU6CH.js} +42 -5
- package/dist/chunks/chunk-ZXKYU6CH.js.map +7 -0
- package/dist/cli/decisions.d.ts +8 -0
- package/dist/cli/decisions.d.ts.map +1 -0
- package/dist/cli/decisions.js +131 -0
- package/dist/cli/decisions.js.map +7 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +56 -0
- package/dist/cli/index.js.map +7 -0
- package/dist/cli/mesh.d.ts +3 -0
- package/dist/cli/mesh.d.ts.map +1 -0
- package/dist/cli/mesh.js +126 -0
- package/dist/cli/mesh.js.map +7 -0
- package/dist/commands/fabric.d.ts.map +1 -1
- package/dist/compaction/carry.d.ts +23 -0
- package/dist/compaction/carry.d.ts.map +1 -0
- package/dist/compaction/hook.d.ts +9 -0
- package/dist/compaction/hook.d.ts.map +1 -1
- package/dist/compaction/hook.js +6 -6
- package/dist/compaction/orphan-repair.d.ts +11 -0
- package/dist/compaction/orphan-repair.d.ts.map +1 -0
- package/dist/compaction/orphan-repair.js +75 -0
- package/dist/compaction/orphan-repair.js.map +7 -0
- package/dist/compaction/owner.d.ts +26 -0
- package/dist/compaction/owner.d.ts.map +1 -0
- package/dist/compaction/owner.js +26 -0
- package/dist/compaction/owner.js.map +7 -0
- package/dist/compaction/pressure.d.ts +19 -0
- package/dist/compaction/pressure.d.ts.map +1 -0
- package/dist/compaction/render.d.ts +4 -0
- package/dist/compaction/render.d.ts.map +1 -1
- package/dist/compaction/threshold.d.ts +6 -1
- package/dist/compaction/threshold.d.ts.map +1 -1
- package/dist/components/configuration.js +6 -6
- package/dist/components/provider-component.d.ts +1 -1
- package/dist/components/provider-component.d.ts.map +1 -1
- package/dist/config.d.ts +45 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/core/action-registry.d.ts +5 -1
- package/dist/core/action-registry.d.ts.map +1 -1
- package/dist/core/action-registry.js +8 -8
- package/dist/core/approval-controller.d.ts +5 -1
- package/dist/core/approval-controller.d.ts.map +1 -1
- package/dist/core/approval-overrides.d.ts +11 -0
- package/dist/core/approval-overrides.d.ts.map +1 -0
- package/dist/core/atomic-write.d.ts +77 -0
- package/dist/core/atomic-write.d.ts.map +1 -1
- package/dist/core/compact-controller.d.ts +8 -0
- package/dist/core/compact-controller.d.ts.map +1 -1
- package/dist/core/file-lock.d.ts.map +1 -1
- package/dist/core/foreground-tools.d.ts +45 -0
- package/dist/core/foreground-tools.d.ts.map +1 -0
- package/dist/core/provider-bindings.d.ts +10 -1
- package/dist/core/provider-bindings.d.ts.map +1 -1
- package/dist/core/provider-operations.js.map +1 -1
- package/dist/core/tool-ownership.d.ts +18 -2
- package/dist/core/tool-ownership.d.ts.map +1 -1
- package/dist/decisions/command.d.ts +5 -0
- package/dist/decisions/command.d.ts.map +1 -0
- package/dist/decisions/command.js +74 -0
- package/dist/decisions/command.js.map +7 -0
- package/dist/decisions/host.d.ts +24 -0
- package/dist/decisions/host.d.ts.map +1 -0
- package/dist/decisions/store.d.ts +147 -0
- package/dist/decisions/store.d.ts.map +1 -0
- package/dist/durable.d.ts +38 -0
- package/dist/durable.d.ts.map +1 -0
- package/dist/durable.js +274 -0
- package/dist/durable.js.map +7 -0
- package/dist/entropy/index.js +10 -9
- package/dist/execution-service.d.ts +41 -1
- package/dist/execution-service.d.ts.map +1 -1
- package/dist/extension-bootstrap.d.ts +7 -0
- package/dist/extension-bootstrap.d.ts.map +1 -0
- package/dist/extension-bootstrap.js +51 -0
- package/dist/extension-bootstrap.js.map +7 -0
- package/dist/extension.d.ts +8 -0
- package/dist/extension.d.ts.map +1 -0
- package/dist/fabric-exec-tool.d.ts.map +1 -1
- package/dist/fabric-runtime-state.d.ts +8 -0
- package/dist/fabric-runtime-state.d.ts.map +1 -1
- package/dist/fabric-runtime-state.js +2432 -346
- package/dist/fabric-runtime-state.js.map +4 -4
- package/dist/fabric-state.d.ts +22 -0
- package/dist/fabric-state.d.ts.map +1 -1
- package/dist/host-compatibility.d.ts +1 -1
- package/dist/host-compatibility.d.ts.map +1 -1
- package/dist/index.d.ts +5 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +68 -6250
- package/dist/index.js.map +4 -4
- package/dist/jev/observation.js +5 -5
- package/dist/jev-fabric/bridge.d.ts +15 -0
- package/dist/jev-fabric/bridge.d.ts.map +1 -1
- package/dist/jev-fabric/client.js +1 -1
- package/dist/jev-fabric/client.js.map +2 -2
- package/dist/jev-fabric/operations.d.ts +2 -0
- package/dist/jev-fabric/operations.d.ts.map +1 -1
- package/dist/jev-fabric/operations.js +1 -1
- package/dist/jev-fabric/operations.js.map +2 -2
- package/dist/jev-fabric/resolve.js +1 -1
- package/dist/jev-fabric/resolve.js.map +2 -2
- package/dist/jev.js +9 -9
- package/dist/lifecycle/types.d.ts.map +1 -1
- package/dist/memory/client.d.ts +3 -0
- package/dist/memory/client.d.ts.map +1 -1
- package/dist/memory/digest.js +2 -2
- package/dist/memory/discovery.js +6 -6
- package/dist/memory/expand-service.d.ts.map +1 -1
- package/dist/memory/file-worker.d.ts.map +1 -1
- package/dist/memory/file-worker.js +10 -9
- package/dist/memory/file-worker.js.map +2 -2
- package/dist/memory/host-source.d.ts +2 -1
- package/dist/memory/host-source.d.ts.map +1 -1
- package/dist/memory/normalize.js +5 -5
- package/dist/memory/portable.d.ts +3 -1
- package/dist/memory/portable.d.ts.map +1 -1
- package/dist/memory/request-cache.d.ts +4 -2
- package/dist/memory/request-cache.d.ts.map +1 -1
- package/dist/memory/request-context.d.ts +3 -0
- package/dist/memory/request-context.d.ts.map +1 -1
- package/dist/memory/search.js +7 -7
- package/dist/memory/worker-provider.d.ts.map +1 -1
- package/dist/memory/worker-provider.js +10 -10
- package/dist/memory.js +14 -13
- package/dist/memory.js.map +2 -2
- package/dist/mesh/grants.d.ts +86 -0
- package/dist/mesh/grants.d.ts.map +1 -0
- package/dist/mesh/store.d.ts +89 -0
- package/dist/mesh/store.d.ts.map +1 -1
- package/dist/programs/host.d.ts +22 -0
- package/dist/programs/host.d.ts.map +1 -0
- package/dist/programs/host.js +171 -0
- package/dist/programs/host.js.map +7 -0
- package/dist/programs/source.d.ts +16 -0
- package/dist/programs/source.d.ts.map +1 -0
- package/dist/programs/store.d.ts +81 -0
- package/dist/programs/store.d.ts.map +1 -0
- package/dist/protocol.d.ts +153 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +15 -1
- package/dist/providers/agents-actions.d.ts.map +1 -1
- package/dist/providers/agents-message-router.d.ts.map +1 -1
- package/dist/providers/agents-progress.d.ts.map +1 -1
- package/dist/providers/agents-provider.d.ts +3 -0
- package/dist/providers/agents-provider.d.ts.map +1 -1
- package/dist/providers/cache-provider.d.ts +1 -1
- package/dist/providers/cache-provider.d.ts.map +1 -1
- package/dist/providers/compact-provider.d.ts +13 -1
- package/dist/providers/compact-provider.d.ts.map +1 -1
- package/dist/providers/decisions-provider.d.ts +17 -0
- package/dist/providers/decisions-provider.d.ts.map +1 -0
- package/dist/providers/jev-provider.js +9 -9
- package/dist/providers/memory-provider.d.ts.map +1 -1
- package/dist/providers/memory-provider.js +9 -9
- package/dist/providers/mesh-provider.d.ts +4 -0
- package/dist/providers/mesh-provider.d.ts.map +1 -1
- package/dist/providers/pi-native-mcp.d.ts.map +1 -1
- package/dist/providers/pi-tools-provider.d.ts.map +1 -1
- package/dist/providers/programs-provider.d.ts +18 -0
- package/dist/providers/programs-provider.d.ts.map +1 -0
- package/dist/providers/state-provider.d.ts +4 -1
- package/dist/providers/state-provider.d.ts.map +1 -1
- package/dist/providers/thinking-provider.d.ts +15 -0
- package/dist/providers/thinking-provider.d.ts.map +1 -0
- package/dist/residency/actor-client.js +3 -3
- package/dist/residency/client.d.ts.map +1 -1
- package/dist/residency/host.d.ts +21 -0
- package/dist/residency/host.d.ts.map +1 -1
- package/dist/residency/host.js +28 -22
- package/dist/residency/launcher-owner.d.ts +2 -0
- package/dist/residency/launcher-owner.d.ts.map +1 -1
- package/dist/residency/launcher.js +35 -20
- package/dist/residency/launcher.js.map +3 -3
- package/dist/residency/pi-entry.js +26 -22
- package/dist/residency/pi-entry.js.map +1 -1
- package/dist/residency/protocol.d.ts +12 -2
- package/dist/residency/protocol.d.ts.map +1 -1
- package/dist/runners.d.ts +9 -0
- package/dist/runners.d.ts.map +1 -0
- package/dist/runners.js +182 -0
- package/dist/runners.js.map +7 -0
- package/dist/runtime/core-override-guest-types.js +2 -2
- package/dist/runtime/cpython-child-source.d.ts.map +1 -1
- package/dist/runtime/cpython-runtime.d.ts.map +1 -1
- package/dist/runtime/cpython-runtime.js +35 -7
- package/dist/runtime/cpython-runtime.js.map +2 -2
- package/dist/runtime/deadline-pause.d.ts +26 -0
- package/dist/runtime/deadline-pause.d.ts.map +1 -0
- package/dist/runtime/guest-types.d.ts +1 -1
- package/dist/runtime/guest-types.d.ts.map +1 -1
- package/dist/runtime/guest-types.js +1 -1
- package/dist/runtime/kernel.d.ts +3 -0
- package/dist/runtime/kernel.d.ts.map +1 -1
- package/dist/runtime/monty-runtime.d.ts.map +1 -1
- package/dist/runtime/monty-runtime.js +33 -12
- package/dist/runtime/monty-runtime.js.map +2 -2
- package/dist/runtime/node-process-runtime.d.ts.map +1 -1
- package/dist/runtime/node-process-runtime.js +4 -3
- package/dist/runtime/orchestration.d.ts.map +1 -1
- package/dist/runtime/quickjs-runtime.d.ts.map +1 -1
- package/dist/runtime/quickjs-runtime.js +2 -1
- package/dist/runtime/typescript-kernel.js +8 -7
- package/dist/runtime/typescript-kernel.js.map +1 -1
- package/dist/runtime-state-builtins.d.ts.map +1 -1
- package/dist/schema/controller.d.ts.map +1 -1
- package/dist/schema/policy.d.ts.map +1 -1
- package/dist/scope.d.ts +69 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +37 -0
- package/dist/scope.js.map +7 -0
- package/dist/speculation/eligibility.d.ts.map +1 -1
- package/dist/speculation/python-scanner.js +1 -1
- package/dist/speculation/python-scanner.js.map +2 -2
- package/dist/speculation/scanner.js +1 -1
- package/dist/speculation/scanner.js.map +2 -2
- package/dist/state/binding.d.ts +17 -0
- package/dist/state/binding.d.ts.map +1 -0
- package/dist/state/store.d.ts +8 -2
- package/dist/state/store.d.ts.map +1 -1
- package/dist/state/types.d.ts +23 -2
- package/dist/state/types.d.ts.map +1 -1
- package/dist/storage/retention.d.ts +7 -0
- package/dist/storage/retention.d.ts.map +1 -1
- package/dist/storage/scratch.d.ts.map +1 -1
- package/dist/thinking-control.d.ts +64 -0
- package/dist/thinking-control.d.ts.map +1 -0
- package/dist/thinking-control.js +15 -0
- package/dist/thinking-control.js.map +7 -0
- package/dist/thinking.d.ts +61 -0
- package/dist/thinking.d.ts.map +1 -1
- package/dist/topology/control-plane.d.ts +13 -0
- package/dist/topology/control-plane.d.ts.map +1 -1
- package/dist/topology/participant-directory.d.ts +2 -0
- package/dist/topology/participant-directory.d.ts.map +1 -1
- package/dist/topology/provider-participants.d.ts +72 -0
- package/dist/topology/provider-participants.d.ts.map +1 -0
- package/dist/topology/records.d.ts.map +1 -1
- package/dist/topology/types.d.ts +13 -3
- package/dist/topology/types.d.ts.map +1 -1
- package/dist/type-error-guidance.js +170 -0
- package/dist/type-error-guidance.js.map +7 -0
- package/dist/ui/controller.d.ts.map +1 -1
- package/dist/ui/conversation-chrome.d.ts +2 -0
- package/dist/ui/conversation-chrome.d.ts.map +1 -1
- package/dist/ui/conversation-chrome.js +1 -1
- package/dist/ui/conversation-latest.d.ts +10 -0
- package/dist/ui/conversation-latest.d.ts.map +1 -0
- package/dist/ui/conversation-native-reader.js +2 -1
- package/dist/ui/conversation-native-reader.js.map +1 -1
- package/dist/ui/conversation-render.d.ts +2 -1
- package/dist/ui/conversation-render.d.ts.map +1 -1
- package/dist/ui/conversation-scrollbar.d.ts +22 -0
- package/dist/ui/conversation-scrollbar.d.ts.map +1 -0
- package/dist/ui/conversation-selection.d.ts +2 -2
- package/dist/ui/conversation-selection.d.ts.map +1 -1
- package/dist/ui/conversation-targets.d.ts.map +1 -1
- package/dist/ui/conversation-targets.js +2 -2
- package/dist/ui/conversation.d.ts +3 -0
- package/dist/ui/conversation.d.ts.map +1 -1
- package/dist/ui/conversation.js +253 -34
- package/dist/ui/conversation.js.map +4 -4
- package/dist/ui/dashboard-fabric-graph.d.ts.map +1 -1
- package/dist/ui/dashboard.js +14 -15
- package/dist/ui/dashboard.js.map +2 -2
- package/dist/ui/image-overlays.d.ts +16 -0
- package/dist/ui/image-overlays.d.ts.map +1 -0
- package/dist/ui/image-overlays.js +10 -0
- package/dist/ui/image-overlays.js.map +7 -0
- package/dist/ui/kitty-viewport.d.ts +24 -0
- package/dist/ui/kitty-viewport.d.ts.map +1 -0
- package/dist/ui/retention.d.ts +14 -0
- package/dist/ui/retention.d.ts.map +1 -0
- package/dist/ui/settings-sections-execution.d.ts.map +1 -1
- package/dist/ui/settings.d.ts.map +1 -1
- package/dist/ui/settings.js +27 -16
- package/dist/ui/settings.js.map +2 -2
- package/dist/ui/transcript.d.ts +2 -1
- package/dist/ui/transcript.d.ts.map +1 -1
- package/dist/ui/types.d.ts +2 -1
- package/dist/ui/types.d.ts.map +1 -1
- package/dist/ui/widget.d.ts +4 -2
- package/dist/ui/widget.d.ts.map +1 -1
- package/dist/verified/generated/authority-kernel.js +1 -1
- package/dist/verified/generated/kernel.js +1 -1
- package/dist/verified/generated/lifecycle-kernel.js +1 -1
- package/dist/verified/generated/manifest.json +7 -7
- package/dist/verified/generated/provider-kernel.js +1 -1
- package/dist/verified/generated/storage-kernel.js +1 -1
- package/dist/worker/options.d.ts.map +1 -1
- package/dist/worker/options.js +14 -0
- package/dist/worker/options.js.map +2 -2
- package/dist/worker/questions.d.ts +46 -0
- package/dist/worker/questions.d.ts.map +1 -0
- package/dist/worker/questions.js +87 -0
- package/dist/worker/questions.js.map +7 -0
- package/dist/worker/result.d.ts +3 -0
- package/dist/worker/result.d.ts.map +1 -0
- package/dist/worker/result.js +7493 -0
- package/dist/worker/result.js.map +7 -0
- package/dist/worker/run-record.js +10 -113
- package/dist/worker/run-record.js.map +3 -3
- package/dist/worker/startup.d.ts +8 -0
- package/dist/worker/startup.d.ts.map +1 -0
- package/dist/worker.js +111 -22
- package/dist/worker.js.map +4 -4
- package/docs/agents.md +197 -3
- package/docs/architecture.md +8 -1
- package/docs/audit-trace.md +36 -1
- package/docs/background-tasks.md +25 -1
- package/docs/certification.md +1 -1
- package/docs/compaction.md +64 -0
- package/docs/components.md +1 -0
- package/docs/configuration.md +105 -10
- package/docs/decisions.md +144 -0
- package/docs/durable-pi.md +186 -0
- package/docs/interface.md +10 -1
- package/docs/kitty-images.md +89 -0
- package/docs/licenses/typebox-mit.txt +23 -0
- package/docs/memory-recall.md +5 -3
- package/docs/programmatic-compaction.md +67 -11
- package/docs/programs.md +137 -0
- package/docs/provider-capabilities.md +23 -1
- package/docs/providers.md +158 -0
- package/docs/residency-runtime.md +64 -0
- package/docs/schema-enforcement.md +5 -3
- package/docs/shell-composition.md +6 -6
- package/docs/skills.md +2 -1
- package/docs/speculation.md +2 -1
- package/docs/state-layer.md +26 -4
- package/docs/thinking.md +48 -0
- package/docs/verified-kernels.md +1 -1
- package/package.json +48 -12
- package/scripts/test-verified-kernels.mjs +1 -1
- package/scripts/verified-kernels.mjs +1 -1
- package/skillsets/python/fabric-exec/SKILL.md +2 -2
- package/skillsets/python/fabric-exec/references/agents.md +9 -4
- package/skillsets/python/fabric-exec/references/mesh.md +9 -0
- package/skillsets/python/fabric-graph/SKILL.md +109 -0
- package/skillsets/python/fabric-guide/SKILL.md +2 -1
- package/skillsets/typescript/fabric-exec/SKILL.md +20 -2
- package/skillsets/typescript/fabric-exec/references/agents.md +10 -4
- package/skillsets/typescript/fabric-exec/references/mesh.md +10 -0
- package/skillsets/typescript/fabric-graph/SKILL.md +112 -0
- package/skillsets/typescript/fabric-guide/SKILL.md +2 -1
- package/skillsets/typescript/fabric-workflow/SKILL.md +1 -1
- package/dist/chunks/chunk-4NF3S3NM.js.map +0 -7
- package/dist/chunks/chunk-5VTBHJN3.js.map +0 -7
- package/dist/chunks/chunk-74BA4VSX.js.map +0 -7
- package/dist/chunks/chunk-7BG5COXB.js.map +0 -7
- package/dist/chunks/chunk-AYBIR4YV.js.map +0 -7
- package/dist/chunks/chunk-B5D6GA77.js.map +0 -7
- package/dist/chunks/chunk-BEJF2JX2.js.map +0 -7
- package/dist/chunks/chunk-BUQZBG6O.js.map +0 -7
- package/dist/chunks/chunk-CC63CY6R.js.map +0 -7
- package/dist/chunks/chunk-FDIEQEXS.js.map +0 -7
- package/dist/chunks/chunk-G4CSXNBT.js.map +0 -7
- package/dist/chunks/chunk-HG4DMARW.js.map +0 -7
- package/dist/chunks/chunk-KAD7UWT2.js +0 -99
- package/dist/chunks/chunk-KAD7UWT2.js.map +0 -7
- package/dist/chunks/chunk-MGWQOKBV.js +0 -30
- package/dist/chunks/chunk-MGWQOKBV.js.map +0 -7
- package/dist/chunks/chunk-PN4EKNRE.js.map +0 -7
- package/dist/chunks/chunk-PNDYFU64.js.map +0 -7
- package/dist/chunks/chunk-PWS2OXLV.js.map +0 -7
- package/dist/chunks/chunk-QE2JFB7F.js.map +0 -7
- package/dist/chunks/chunk-QETG2GVX.js.map +0 -7
- package/dist/chunks/chunk-RAO6TQFP.js.map +0 -7
- package/dist/chunks/chunk-RIFG4HS6.js.map +0 -7
- package/dist/chunks/chunk-TX6E5W7H.js.map +0 -7
- package/dist/chunks/chunk-VRAGOMN4.js.map +0 -7
- package/dist/chunks/chunk-W63E3WEO.js.map +0 -7
- package/dist/chunks/chunk-WMJ2AVQQ.js.map +0 -7
- package/dist/chunks/chunk-ZZ66L3W5.js.map +0 -7
- /package/dist/chunks/{chunk-57CMH4SW.js.map → chunk-7JU7Z4XQ.js.map} +0 -0
- /package/dist/chunks/{chunk-DUJ46TIP.js.map → chunk-ABJCSNZO.js.map} +0 -0
- /package/dist/chunks/{chunk-KP4ANT6L.js.map → chunk-C7EEG6SM.js.map} +0 -0
- /package/dist/chunks/{chunk-NHMICIEU.js.map → chunk-CCHZXF6K.js.map} +0 -0
- /package/dist/chunks/{chunk-5JN5AWNV.js.map → chunk-DZ4WN5XJ.js.map} +0 -0
- /package/dist/chunks/{chunk-7XJB2USB.js.map → chunk-LOLCTWJF.js.map} +0 -0
- /package/dist/chunks/{chunk-64O5L7EW.js.map → chunk-M6IRQ3QT.js.map} +0 -0
- /package/dist/chunks/{chunk-EPYLZWJV.js.map → chunk-OVBKQCYL.js.map} +0 -0
- /package/dist/chunks/{chunk-Z5Y65YBX.js.map → chunk-PYQM7KPL.js.map} +0 -0
- /package/dist/chunks/{chunk-DKVJREDI.js.map → chunk-QY7YK7M6.js.map} +0 -0
- /package/dist/chunks/{chunk-5ZJV4LAX.js.map → chunk-VPRJOD4Y.js.map} +0 -0
- /package/dist/chunks/{chunk-RG22JKIC.js.map → chunk-W7X4XEQU.js.map} +0 -0
- /package/dist/chunks/{chunk-LV4IT75S.js.map → chunk-WLLXKS6I.js.map} +0 -0
- /package/dist/chunks/{chunk-YVDBHS4C.js.map → chunk-WREA4RNR.js.map} +0 -0
- /package/dist/chunks/{chunk-NGGI6LDC.js.map → chunk-X2TRSE7D.js.map} +0 -0
- /package/dist/chunks/{chunk-A4VP7HDF.js.map → chunk-ZLNJDTCN.js.map} +0 -0
|
@@ -0,0 +1,1329 @@
|
|
|
1
|
+
import {
|
|
2
|
+
processSender
|
|
3
|
+
} from "./chunk-JKQARSWR.js";
|
|
4
|
+
import {
|
|
5
|
+
readJsonlPage
|
|
6
|
+
} from "./chunk-CGPK5WHX.js";
|
|
7
|
+
import {
|
|
8
|
+
SHORT_LOCK_MAX_HOLD_MS,
|
|
9
|
+
encodeOwnerIdentityLine,
|
|
10
|
+
lockOwnerLiveness,
|
|
11
|
+
writeFileAtomic
|
|
12
|
+
} from "./chunk-ITVLKXCI.js";
|
|
13
|
+
|
|
14
|
+
// src/mesh/store.ts
|
|
15
|
+
import { randomUUID } from "node:crypto";
|
|
16
|
+
import fs from "node:fs";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
|
|
19
|
+
// src/verified/generated/storage-kernel.js
|
|
20
|
+
function d(e, t) {
|
|
21
|
+
return { $: e < t ? "LT" : e === t ? "EQ" : "GT" };
|
|
22
|
+
}
|
|
23
|
+
function y(e) {
|
|
24
|
+
if (e > 281474976710655)
|
|
25
|
+
throw "bend: a Nat past the largest immediate 2^48-1";
|
|
26
|
+
return e;
|
|
27
|
+
}
|
|
28
|
+
function c(e) {
|
|
29
|
+
return (typeof e == "bigint" || Number.isInteger(e)) && e >= 0 && e <= 2 ** 53 ? Number(e) : { [Symbol.toPrimitive]() {
|
|
30
|
+
throw "bend: a Nat past the largest immediate 2^48-1";
|
|
31
|
+
} };
|
|
32
|
+
}
|
|
33
|
+
function D(e) {
|
|
34
|
+
for (; e !== null && typeof e == "object" && e.$ === "$JMP"; )
|
|
35
|
+
e = e.f(...e.x);
|
|
36
|
+
return e;
|
|
37
|
+
}
|
|
38
|
+
function m(e, t) {
|
|
39
|
+
return (...a) => a.length < t ? m((...s) => e(...a, ...s), t - a.length) : e(...a);
|
|
40
|
+
}
|
|
41
|
+
function C(e, t) {
|
|
42
|
+
let a = e.high, s = e.low, n = t.high, r = t.low;
|
|
43
|
+
return u(p(a, n), p(s, r));
|
|
44
|
+
}
|
|
45
|
+
function q(e, t) {
|
|
46
|
+
if (e.$ === "storage-plans.Any")
|
|
47
|
+
return true;
|
|
48
|
+
{
|
|
49
|
+
let a = e.version;
|
|
50
|
+
return C(a, t);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function k(e) {
|
|
54
|
+
let t = e.high, a = e.low, s = t < 2097151, n = a < 4294967295;
|
|
55
|
+
return u(u(R(t, 2097151), R(a, 4294967295)), s || n);
|
|
56
|
+
}
|
|
57
|
+
function E(e, t, a) {
|
|
58
|
+
return e ? { $: "storage-plans.Revision", high: y(t + 1), low: 0 } : { $: "storage-plans.Revision", high: t, low: y(a + 1) };
|
|
59
|
+
}
|
|
60
|
+
function h(e) {
|
|
61
|
+
let t = e.high, a = e.low;
|
|
62
|
+
return E(p(a, 4294967295), t, a);
|
|
63
|
+
}
|
|
64
|
+
function x(e, t, a) {
|
|
65
|
+
return e ? t : a;
|
|
66
|
+
}
|
|
67
|
+
function b(e, t) {
|
|
68
|
+
return u(k(e), k(t));
|
|
69
|
+
}
|
|
70
|
+
function N(e, t, a, s, n) {
|
|
71
|
+
if (e)
|
|
72
|
+
if (a.$ === "storage-plans.Put") {
|
|
73
|
+
let r = a.value, o = a.identity;
|
|
74
|
+
return { $: "storage-plans.PutNext", key: t, value: r, identity: o, version: h(s), highWater: h(n) };
|
|
75
|
+
} else
|
|
76
|
+
return { $: "storage-plans.DeleteNext", key: t, version: h(s), highWater: h(n) };
|
|
77
|
+
else
|
|
78
|
+
return { $: "storage-plans.Exhausted" };
|
|
79
|
+
}
|
|
80
|
+
function S(e, t, a, s, n) {
|
|
81
|
+
if (t.$ === "storage-plans.Delete")
|
|
82
|
+
return a ? N(b(s, n), e, { $: "storage-plans.Delete" }, s, n) : { $: "storage-plans.Unchanged" };
|
|
83
|
+
{
|
|
84
|
+
let r = t.value, o = t.identity;
|
|
85
|
+
return N(b(x(a, s, n), n), e, { $: "storage-plans.Put", value: r, identity: o }, x(a, s, n), n);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function U(e, t, a, s, n, r) {
|
|
89
|
+
return e ? S(t, a, s, n, r) : { $: "storage-plans.Conflict" };
|
|
90
|
+
}
|
|
91
|
+
function T(e, t) {
|
|
92
|
+
let a = e.key, s = e.expected, n = e.change, r = t.present, o = t.version, l = t.highWater;
|
|
93
|
+
return U(q(s, o), a, n, r, o, l);
|
|
94
|
+
}
|
|
95
|
+
function W(e, t) {
|
|
96
|
+
return T(e, t);
|
|
97
|
+
}
|
|
98
|
+
function u(e, t) {
|
|
99
|
+
return e ? t : false;
|
|
100
|
+
}
|
|
101
|
+
function p(e, t) {
|
|
102
|
+
return B(d(e, t));
|
|
103
|
+
}
|
|
104
|
+
function R(e, t) {
|
|
105
|
+
return I(d(e, t));
|
|
106
|
+
}
|
|
107
|
+
function B(e) {
|
|
108
|
+
return e.$ === "EQ";
|
|
109
|
+
}
|
|
110
|
+
function I(e) {
|
|
111
|
+
return e.$ !== "GT";
|
|
112
|
+
}
|
|
113
|
+
function $(e) {
|
|
114
|
+
let t = [e];
|
|
115
|
+
for (let a = t, s = 0; ; )
|
|
116
|
+
switch (e.$) {
|
|
117
|
+
case "storage-plans.Revision":
|
|
118
|
+
return a = a[s] = { ...e, high: c(e.high), low: c(e.low) }, t[0];
|
|
119
|
+
default:
|
|
120
|
+
throw "bend: storage-plans.Revision has no tag " + e?.$ + " (its tags: storage-plans.Revision); a tag names its constructor as the loading file sees it, which a later version will make the same everywhere (#1105)";
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function i(e) {
|
|
124
|
+
let t = [e];
|
|
125
|
+
for (let a = t, s = 0; ; )
|
|
126
|
+
switch (e.$) {
|
|
127
|
+
case "storage-plans.Revision":
|
|
128
|
+
return a = a[s] = { ...e, high: BigInt(e.high), low: BigInt(e.low) }, t[0];
|
|
129
|
+
default:
|
|
130
|
+
throw "bend: storage-plans.Revision has no tag " + e?.$ + " (its tags: storage-plans.Revision); a tag names its constructor as the loading file sees it, which a later version will make the same everywhere (#1105)";
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function j(e) {
|
|
134
|
+
let t = [e];
|
|
135
|
+
for (let a = t, s = 0; ; )
|
|
136
|
+
switch (e.$) {
|
|
137
|
+
case "storage-plans.Any":
|
|
138
|
+
return a[s] = e, t[0];
|
|
139
|
+
case "storage-plans.At":
|
|
140
|
+
return a = a[s] = { ...e, version: $(e.version) }, t[0];
|
|
141
|
+
default:
|
|
142
|
+
throw "bend: storage-plans.Expectation has no tag " + e?.$ + " (its tags: storage-plans.Any, storage-plans.At); a tag names its constructor as the loading file sees it, which a later version will make the same everywhere (#1105)";
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function G(e) {
|
|
146
|
+
let t = [e];
|
|
147
|
+
for (let a = t, s = 0; ; )
|
|
148
|
+
switch (e.$) {
|
|
149
|
+
case "storage-plans.Any":
|
|
150
|
+
return a[s] = e, t[0];
|
|
151
|
+
case "storage-plans.At":
|
|
152
|
+
return a = a[s] = { ...e, version: i(e.version) }, t[0];
|
|
153
|
+
default:
|
|
154
|
+
throw "bend: storage-plans.Expectation has no tag " + e?.$ + " (its tags: storage-plans.Any, storage-plans.At); a tag names its constructor as the loading file sees it, which a later version will make the same everywhere (#1105)";
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function f(e) {
|
|
158
|
+
let t = [e];
|
|
159
|
+
for (let a = t, s = 0; ; )
|
|
160
|
+
switch (e.$) {
|
|
161
|
+
case "Nil":
|
|
162
|
+
return a[s] = e, t[0];
|
|
163
|
+
case "Con":
|
|
164
|
+
a = a[s] = { ...e, head: c(e.head) }, s = "tail", e = e[s];
|
|
165
|
+
continue;
|
|
166
|
+
default:
|
|
167
|
+
throw "bend: List has no tag " + e?.$ + " (its tags: Nil, Con); a tag names its constructor as the loading file sees it, which a later version will make the same everywhere (#1105)";
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function L(e) {
|
|
171
|
+
let t = [e];
|
|
172
|
+
for (let a = t, s = 0; ; )
|
|
173
|
+
switch (e.$) {
|
|
174
|
+
case "storage-plans.Put":
|
|
175
|
+
return a = a[s] = { ...e, value: f(e.value), identity: f(e.identity) }, t[0];
|
|
176
|
+
case "storage-plans.Delete":
|
|
177
|
+
return a[s] = e, t[0];
|
|
178
|
+
default:
|
|
179
|
+
throw "bend: storage-plans.Change has no tag " + e?.$ + " (its tags: storage-plans.Put, storage-plans.Delete); a tag names its constructor as the loading file sees it, which a later version will make the same everywhere (#1105)";
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function g(e) {
|
|
183
|
+
let t = [e];
|
|
184
|
+
for (let a = t, s = 0; ; )
|
|
185
|
+
switch (e.$) {
|
|
186
|
+
case "Nil":
|
|
187
|
+
return a[s] = e, t[0];
|
|
188
|
+
case "Con":
|
|
189
|
+
a = a[s] = { ...e, head: BigInt(e.head) }, s = "tail", e = e[s];
|
|
190
|
+
continue;
|
|
191
|
+
default:
|
|
192
|
+
throw "bend: List has no tag " + e?.$ + " (its tags: Nil, Con); a tag names its constructor as the loading file sees it, which a later version will make the same everywhere (#1105)";
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function M(e) {
|
|
196
|
+
let t = [e];
|
|
197
|
+
for (let a = t, s = 0; ; )
|
|
198
|
+
switch (e.$) {
|
|
199
|
+
case "storage-plans.Put":
|
|
200
|
+
return a = a[s] = { ...e, value: g(e.value), identity: g(e.identity) }, t[0];
|
|
201
|
+
case "storage-plans.Delete":
|
|
202
|
+
return a[s] = e, t[0];
|
|
203
|
+
default:
|
|
204
|
+
throw "bend: storage-plans.Change has no tag " + e?.$ + " (its tags: storage-plans.Put, storage-plans.Delete); a tag names its constructor as the loading file sees it, which a later version will make the same everywhere (#1105)";
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function Q(e) {
|
|
208
|
+
let t = [e];
|
|
209
|
+
for (let a = t, s = 0; ; )
|
|
210
|
+
switch (e.$) {
|
|
211
|
+
case "storage-plans.Conflict":
|
|
212
|
+
return a[s] = e, t[0];
|
|
213
|
+
case "storage-plans.Exhausted":
|
|
214
|
+
return a[s] = e, t[0];
|
|
215
|
+
case "storage-plans.Unchanged":
|
|
216
|
+
return a[s] = e, t[0];
|
|
217
|
+
case "storage-plans.PutNext":
|
|
218
|
+
return a = a[s] = { ...e, key: g(e.key), value: g(e.value), identity: g(e.identity), version: i(e.version), highWater: i(e.highWater) }, t[0];
|
|
219
|
+
case "storage-plans.DeleteNext":
|
|
220
|
+
return a = a[s] = { ...e, key: g(e.key), version: i(e.version), highWater: i(e.highWater) }, t[0];
|
|
221
|
+
default:
|
|
222
|
+
throw "bend: storage-plans.Plan has no tag " + e?.$ + " (its tags: storage-plans.Conflict, storage-plans.Exhausted, storage-plans.Unchanged, storage-plans.PutNext, storage-plans.DeleteNext); a tag names its constructor as the loading file sees it, which a later version will make the same everywhere (#1105)";
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
function J(e) {
|
|
226
|
+
let t = [e];
|
|
227
|
+
for (let a = t, s = 0; ; )
|
|
228
|
+
switch (e.$) {
|
|
229
|
+
case "storage-plans.Request":
|
|
230
|
+
return a = a[s] = { ...e, key: f(e.key), expected: j(e.expected), change: L(e.change) }, t[0];
|
|
231
|
+
default:
|
|
232
|
+
throw "bend: storage-plans.Request has no tag " + e?.$ + " (its tags: storage-plans.Request); a tag names its constructor as the loading file sees it, which a later version will make the same everywhere (#1105)";
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function O(e) {
|
|
236
|
+
let t = [e];
|
|
237
|
+
for (let a = t, s = 0; ; )
|
|
238
|
+
switch (e.$) {
|
|
239
|
+
case "storage-plans.Slot":
|
|
240
|
+
return a = a[s] = { ...e, version: $(e.version), highWater: $(e.highWater) }, t[0];
|
|
241
|
+
default:
|
|
242
|
+
throw "bend: storage-plans.Slot has no tag " + e?.$ + " (its tags: storage-plans.Slot); a tag names its constructor as the loading file sees it, which a later version will make the same everywhere (#1105)";
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function z(e) {
|
|
246
|
+
let t = [e];
|
|
247
|
+
for (let a = t, s = 0; ; )
|
|
248
|
+
switch (e.$) {
|
|
249
|
+
case "storage-plans.Request":
|
|
250
|
+
return a = a[s] = { ...e, key: g(e.key), expected: G(e.expected), change: M(e.change) }, t[0];
|
|
251
|
+
default:
|
|
252
|
+
throw "bend: storage-plans.Request has no tag " + e?.$ + " (its tags: storage-plans.Request); a tag names its constructor as the loading file sees it, which a later version will make the same everywhere (#1105)";
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function F(e) {
|
|
256
|
+
let t = [e];
|
|
257
|
+
for (let a = t, s = 0; ; )
|
|
258
|
+
switch (e.$) {
|
|
259
|
+
case "storage-plans.Slot":
|
|
260
|
+
return a = a[s] = { ...e, version: i(e.version), highWater: i(e.highWater) }, t[0];
|
|
261
|
+
default:
|
|
262
|
+
throw "bend: storage-plans.Slot has no tag " + e?.$ + " (its tags: storage-plans.Slot); a tag names its constructor as the loading file sees it, which a later version will make the same everywhere (#1105)";
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
var P = /* @__PURE__ */ new Map([["Any", "storage-plans.Any"], ["Revision", "storage-plans.Revision"], ["Exhausted", "storage-plans.Exhausted"], ["Put", "storage-plans.Put"], ["PutNext", "storage-plans.PutNext"], ["DeleteNext", "storage-plans.DeleteNext"], ["Delete", "storage-plans.Delete"], ["Unchanged", "storage-plans.Unchanged"], ["Conflict", "storage-plans.Conflict"], ["At", "storage-plans.At"], ["Request", "storage-plans.Request"], ["Slot", "storage-plans.Slot"]]);
|
|
266
|
+
var H = /* @__PURE__ */ new Map([["storage-plans.Any", "Any"], ["storage-plans.Revision", "Revision"], ["storage-plans.Exhausted", "Exhausted"], ["storage-plans.Put", "Put"], ["storage-plans.PutNext", "PutNext"], ["storage-plans.DeleteNext", "DeleteNext"], ["storage-plans.Delete", "Delete"], ["storage-plans.Unchanged", "Unchanged"], ["storage-plans.Conflict", "Conflict"], ["storage-plans.At", "At"], ["storage-plans.Request", "Request"], ["storage-plans.Slot", "Slot"]]);
|
|
267
|
+
function w(e, t) {
|
|
268
|
+
let a = [e];
|
|
269
|
+
for (let s = [[a, 0]]; s.length > 0; ) {
|
|
270
|
+
let [n, r] = s.pop(), o = n[r];
|
|
271
|
+
if (o === null || typeof o != "object") continue;
|
|
272
|
+
let l = Array.isArray(o) ? [...o] : { ...o };
|
|
273
|
+
typeof l.$ == "string" && (l.$ = t.get(l.$) ?? l.$), n[r] = l;
|
|
274
|
+
for (let A of Object.keys(l)) s.push([l, A]);
|
|
275
|
+
}
|
|
276
|
+
return a[0];
|
|
277
|
+
}
|
|
278
|
+
var K = /* @__PURE__ */ m((e, t) => {
|
|
279
|
+
let a = Q(D(W(J(e), O(t))));
|
|
280
|
+
return z(e), F(t), a;
|
|
281
|
+
}, 2);
|
|
282
|
+
var V = (e, t) => w(K(w(e, P), w(t, P)), H);
|
|
283
|
+
|
|
284
|
+
// src/verified/storage.ts
|
|
285
|
+
var RADIX = 4294967296n;
|
|
286
|
+
var encode = (text) => {
|
|
287
|
+
let result = { $: "Nil" };
|
|
288
|
+
for (let index = text.length - 1; index >= 0; index--) {
|
|
289
|
+
result = { $: "Con", head: BigInt(text.charCodeAt(index)), tail: result };
|
|
290
|
+
}
|
|
291
|
+
return result;
|
|
292
|
+
};
|
|
293
|
+
var decode = (text) => {
|
|
294
|
+
const units = [];
|
|
295
|
+
for (let node = text; node.$ === "Con"; node = node.tail) {
|
|
296
|
+
if (node.head < 0n || node.head > 65535n) throw new Error("Invalid storage code unit");
|
|
297
|
+
units.push(String.fromCharCode(Number(node.head)));
|
|
298
|
+
}
|
|
299
|
+
return units.join("");
|
|
300
|
+
};
|
|
301
|
+
var storageRevision = (value) => {
|
|
302
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
|
|
303
|
+
throw new Error("Invalid Fabric mesh revision: expected a nonnegative safe integer");
|
|
304
|
+
}
|
|
305
|
+
return value;
|
|
306
|
+
};
|
|
307
|
+
var encodeRevision = (value) => {
|
|
308
|
+
const exact = BigInt(storageRevision(value));
|
|
309
|
+
return { $: "Revision", high: exact / RADIX, low: exact % RADIX };
|
|
310
|
+
};
|
|
311
|
+
var decodeRevision = (value) => {
|
|
312
|
+
if (value.high < 0n || value.high > 2097151n || value.low < 0n || value.low >= RADIX) {
|
|
313
|
+
throw new Error("Invalid verified storage revision limbs");
|
|
314
|
+
}
|
|
315
|
+
return storageRevision(Number(value.high * RADIX + value.low));
|
|
316
|
+
};
|
|
317
|
+
var serialize = (value) => {
|
|
318
|
+
const json = JSON.stringify(value);
|
|
319
|
+
if (json === void 0) throw new Error("Mesh values must be JSON-serializable");
|
|
320
|
+
return json;
|
|
321
|
+
};
|
|
322
|
+
var capture = (key, ifVersion, payload) => {
|
|
323
|
+
const expected = ifVersion === void 0 ? void 0 : storageRevision(ifVersion);
|
|
324
|
+
const request = {
|
|
325
|
+
$: "Request",
|
|
326
|
+
key: encode(key),
|
|
327
|
+
expected: expected === void 0 ? { $: "Any" } : { $: "At", version: encodeRevision(expected) },
|
|
328
|
+
change: payload === void 0 ? { $: "Delete" } : {
|
|
329
|
+
$: "Put",
|
|
330
|
+
value: encode(payload.value),
|
|
331
|
+
identity: encode(payload.identity)
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
return Object.freeze({
|
|
335
|
+
key,
|
|
336
|
+
transition(present, actualVersion, highWater) {
|
|
337
|
+
const actual = storageRevision(actualVersion);
|
|
338
|
+
const clock = storageRevision(highWater);
|
|
339
|
+
if (clock < actual) throw new Error("Inconsistent Fabric mesh high-water revision");
|
|
340
|
+
const plan = V(
|
|
341
|
+
request,
|
|
342
|
+
{ $: "Slot", present, version: encodeRevision(actual), highWater: encodeRevision(clock) }
|
|
343
|
+
);
|
|
344
|
+
switch (plan.$) {
|
|
345
|
+
case "Conflict":
|
|
346
|
+
throw new Error(`Mesh compare-and-swap failed for ${key}: expected version ${expected}, found ${actual}`);
|
|
347
|
+
case "Exhausted":
|
|
348
|
+
throw new Error(`Fabric mesh revision exhausted for ${key}`);
|
|
349
|
+
case "Unchanged":
|
|
350
|
+
return { kind: "unchanged" };
|
|
351
|
+
case "PutNext":
|
|
352
|
+
return {
|
|
353
|
+
kind: "put",
|
|
354
|
+
key: decode(plan.key),
|
|
355
|
+
value: JSON.parse(decode(plan.value)),
|
|
356
|
+
identity: JSON.parse(decode(plan.identity)),
|
|
357
|
+
version: decodeRevision(plan.version),
|
|
358
|
+
highWater: decodeRevision(plan.highWater)
|
|
359
|
+
};
|
|
360
|
+
case "DeleteNext":
|
|
361
|
+
return { kind: "delete", key: decode(plan.key), version: decodeRevision(plan.version), highWater: decodeRevision(plan.highWater) };
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
};
|
|
366
|
+
var captureStoragePut = (input, maxValueBytes = Number.POSITIVE_INFINITY) => {
|
|
367
|
+
const { key, ifVersion, value, identity } = input;
|
|
368
|
+
if (ifVersion !== void 0) storageRevision(ifVersion);
|
|
369
|
+
const identityJson = serialize(identity);
|
|
370
|
+
const valueJson = serialize(value);
|
|
371
|
+
if (Buffer.byteLength(valueJson, "utf8") > maxValueBytes) {
|
|
372
|
+
throw new Error(`Mesh state value exceeds ${maxValueBytes} bytes`);
|
|
373
|
+
}
|
|
374
|
+
return capture(key, ifVersion, { value: valueJson, identity: identityJson });
|
|
375
|
+
};
|
|
376
|
+
var captureStorageDelete = (input) => {
|
|
377
|
+
const { key, ifVersion } = input;
|
|
378
|
+
return capture(key, ifVersion);
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
// src/mesh/store.ts
|
|
382
|
+
var TOPIC_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,127}$/;
|
|
383
|
+
var KEY_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,255}$/;
|
|
384
|
+
var validateMeshTopic = (topic) => {
|
|
385
|
+
if (!TOPIC_PATTERN.test(topic)) throw new Error(`Invalid Fabric mesh topic: ${topic}`);
|
|
386
|
+
};
|
|
387
|
+
var LOCK_TIMEOUT_MS = 1e4;
|
|
388
|
+
var STALE_LOCK_MS = 3e4;
|
|
389
|
+
var DEFAULT_MAX_EVENT_LOG_BYTES = 64 * 1024 * 1024;
|
|
390
|
+
var DEFAULT_RETAINED_EVENT_LOG_BYTES = 16 * 1024 * 1024;
|
|
391
|
+
var DEFAULT_MAX_STATE_BYTES = 32 * 1024 * 1024;
|
|
392
|
+
var DEFAULT_MAX_STATE_TOMBSTONES = 1e4;
|
|
393
|
+
var EVENT_READ_PAGE_BYTES = 4 * 1024 * 1024;
|
|
394
|
+
var EVENT_READ_CHUNK_BYTES = 64 * 1024;
|
|
395
|
+
var CURSOR_OFFSET_BASE = 2 ** 32;
|
|
396
|
+
var MESH_MAX_PENDING_SCHEDULES = 1e3;
|
|
397
|
+
var MESH_MAX_SCHEDULE_AHEAD_MS = 366 * 24 * 60 * 60 * 1e3;
|
|
398
|
+
var MAX_SCHEDULE_FILE_BYTES = 16 * 1024 * 1024;
|
|
399
|
+
var SCHEDULE_KEY_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,127}$/;
|
|
400
|
+
var delay = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
401
|
+
var errorCode = (error) => error instanceof Error && "code" in error && typeof error.code === "string" ? error.code : void 0;
|
|
402
|
+
var processAlive = (pid) => {
|
|
403
|
+
if (!Number.isSafeInteger(pid) || pid <= 0) return false;
|
|
404
|
+
try {
|
|
405
|
+
process.kill(pid, 0);
|
|
406
|
+
return true;
|
|
407
|
+
} catch {
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
var jsonClone = (value) => {
|
|
412
|
+
const serialized = JSON.stringify(value);
|
|
413
|
+
if (serialized === void 0) throw new Error("Mesh values must be JSON-serializable");
|
|
414
|
+
return JSON.parse(serialized);
|
|
415
|
+
};
|
|
416
|
+
var isMeshStateFile = (value) => {
|
|
417
|
+
if (typeof value !== "object" || value === null || Array.isArray(value) || ![1, 2].includes(value.format)) {
|
|
418
|
+
return false;
|
|
419
|
+
}
|
|
420
|
+
const entries = value.entries;
|
|
421
|
+
return typeof entries === "object" && entries !== null && !Array.isArray(entries);
|
|
422
|
+
};
|
|
423
|
+
var recoverConcatenatedState = (serialized) => {
|
|
424
|
+
const snapshots = [];
|
|
425
|
+
let documents = 0;
|
|
426
|
+
let start = -1;
|
|
427
|
+
let depth = 0;
|
|
428
|
+
let inString = false;
|
|
429
|
+
let escaped = false;
|
|
430
|
+
for (let index = 0; index < serialized.length; index += 1) {
|
|
431
|
+
const character = serialized[index];
|
|
432
|
+
if (start < 0) {
|
|
433
|
+
if (/\s/.test(character)) continue;
|
|
434
|
+
if (character !== "{") return void 0;
|
|
435
|
+
start = index;
|
|
436
|
+
depth = 1;
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
if (inString) {
|
|
440
|
+
if (escaped) escaped = false;
|
|
441
|
+
else if (character === "\\") escaped = true;
|
|
442
|
+
else if (character === '"') inString = false;
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
if (character === '"') inString = true;
|
|
446
|
+
else if (character === "{") depth += 1;
|
|
447
|
+
else if (character === "}") {
|
|
448
|
+
depth -= 1;
|
|
449
|
+
if (depth !== 0) continue;
|
|
450
|
+
try {
|
|
451
|
+
const parsed = JSON.parse(serialized.slice(start, index + 1));
|
|
452
|
+
documents += 1;
|
|
453
|
+
if (isMeshStateFile(parsed)) snapshots.push(parsed);
|
|
454
|
+
} catch {
|
|
455
|
+
return void 0;
|
|
456
|
+
}
|
|
457
|
+
start = -1;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return start < 0 && documents > 1 ? snapshots.at(-1) : void 0;
|
|
461
|
+
};
|
|
462
|
+
var compareSchedules = (left, right) => left.dueAt - right.dueAt || left.createdAt - right.createdAt || left.id.localeCompare(right.id);
|
|
463
|
+
var isMeshSchedule = (value) => {
|
|
464
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
465
|
+
const entry = value;
|
|
466
|
+
return typeof entry.id === "string" && typeof entry.topic === "string" && typeof entry.kind === "string" && typeof entry.from === "object" && entry.from !== null && Number.isSafeInteger(entry.dueAt) && Number.isSafeInteger(entry.createdAt) && (entry.key === void 0 || typeof entry.key === "string");
|
|
467
|
+
};
|
|
468
|
+
var emptyState = () => ({ format: 1, revisionFormat: 2, entries: {}, highWater: 0 });
|
|
469
|
+
var readState = (filePath, maxBytes, recoverDamage = true) => {
|
|
470
|
+
let serialized;
|
|
471
|
+
try {
|
|
472
|
+
const stat = fs.statSync(filePath);
|
|
473
|
+
if (stat.size > maxBytes) throw new Error(`state exceeds ${maxBytes} bytes`);
|
|
474
|
+
if (stat.size === 0 && recoverDamage) return emptyState();
|
|
475
|
+
serialized = fs.readFileSync(filePath, "utf8");
|
|
476
|
+
} catch (error) {
|
|
477
|
+
if (errorCode(error) === "ENOENT") return emptyState();
|
|
478
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
479
|
+
throw new Error(`Failed to read Fabric mesh state: ${message}`);
|
|
480
|
+
}
|
|
481
|
+
if (!serialized.trim() && recoverDamage) return emptyState();
|
|
482
|
+
try {
|
|
483
|
+
const parsed = JSON.parse(serialized);
|
|
484
|
+
if (isMeshStateFile(parsed)) return parsed;
|
|
485
|
+
throw new Error("invalid state format");
|
|
486
|
+
} catch (error) {
|
|
487
|
+
const recovered = recoverConcatenatedState(serialized);
|
|
488
|
+
if (recovered) return recovered;
|
|
489
|
+
if (!recoverDamage) throw new Error("Failed to read Fabric mesh state: invalid state format");
|
|
490
|
+
return emptyState();
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
var atomicWrite = (filePath, value, maxBytes = Number.POSITIVE_INFINITY) => {
|
|
494
|
+
const serialized = JSON.stringify(value, null, 2);
|
|
495
|
+
if (Buffer.byteLength(serialized, "utf8") > maxBytes) {
|
|
496
|
+
throw new Error(`Fabric mesh state exceeds ${maxBytes} bytes`);
|
|
497
|
+
}
|
|
498
|
+
writeFileAtomic(filePath, serialized);
|
|
499
|
+
};
|
|
500
|
+
var stateSlot = (state, key) => {
|
|
501
|
+
if (state.versions !== void 0 && (typeof state.versions !== "object" || state.versions === null || Array.isArray(state.versions))) {
|
|
502
|
+
throw new Error("Invalid Fabric mesh revision table");
|
|
503
|
+
}
|
|
504
|
+
let retainedMaximum = 0;
|
|
505
|
+
for (const revision of Object.values(state.versions ?? {})) {
|
|
506
|
+
retainedMaximum = Math.max(retainedMaximum, storageRevision(revision));
|
|
507
|
+
}
|
|
508
|
+
for (const [entryKey, entry] of Object.entries(state.entries)) {
|
|
509
|
+
if (typeof entry !== "object" || entry === null || entry.key !== entryKey) {
|
|
510
|
+
throw new Error("Invalid Fabric mesh state entry");
|
|
511
|
+
}
|
|
512
|
+
const version2 = storageRevision(entry.version);
|
|
513
|
+
const retained = state.versions !== void 0 && Object.hasOwn(state.versions, entryKey) ? state.versions[entryKey] : void 0;
|
|
514
|
+
if (version2 === 0 || retained !== void 0 && retained !== version2) {
|
|
515
|
+
throw new Error("Inconsistent Fabric mesh revision");
|
|
516
|
+
}
|
|
517
|
+
retainedMaximum = Math.max(retainedMaximum, version2);
|
|
518
|
+
}
|
|
519
|
+
if (Object.hasOwn(state, "revisionFormat") && state.revisionFormat !== 2) {
|
|
520
|
+
throw new Error("Unsupported Fabric mesh revision protocol");
|
|
521
|
+
}
|
|
522
|
+
if ((state.format === 2 || state.revisionFormat === 2) && !Object.hasOwn(state, "highWater")) {
|
|
523
|
+
throw new Error("Missing Fabric mesh high-water revision");
|
|
524
|
+
}
|
|
525
|
+
const highWater = Object.hasOwn(state, "highWater") ? storageRevision(state.highWater) : retainedMaximum;
|
|
526
|
+
if (highWater < retainedMaximum) throw new Error("Inconsistent Fabric mesh high-water revision");
|
|
527
|
+
const present = Object.hasOwn(state.entries, key);
|
|
528
|
+
const version = present ? state.entries[key].version : state.versions !== void 0 && Object.hasOwn(state.versions, key) ? state.versions[key] : 0;
|
|
529
|
+
return { present, version, highWater };
|
|
530
|
+
};
|
|
531
|
+
var compactStateTombstones = (state, maxTombstones) => {
|
|
532
|
+
state.versions ??= {};
|
|
533
|
+
const orderedKeys = [];
|
|
534
|
+
const seen = /* @__PURE__ */ new Set();
|
|
535
|
+
for (const key of state.tombstoneOrder ?? []) {
|
|
536
|
+
if (Object.hasOwn(state.entries, key) || !Object.hasOwn(state.versions, key) || seen.has(key)) continue;
|
|
537
|
+
seen.add(key);
|
|
538
|
+
orderedKeys.push(key);
|
|
539
|
+
}
|
|
540
|
+
for (const key of Object.keys(state.versions)) {
|
|
541
|
+
if (Object.hasOwn(state.entries, key) || seen.has(key)) continue;
|
|
542
|
+
seen.add(key);
|
|
543
|
+
orderedKeys.push(key);
|
|
544
|
+
}
|
|
545
|
+
const retainedKeys = orderedKeys.slice(-maxTombstones);
|
|
546
|
+
const retained = new Set(retainedKeys);
|
|
547
|
+
for (const key of Object.keys(state.versions)) {
|
|
548
|
+
if (!Object.hasOwn(state.entries, key) && !retained.has(key)) delete state.versions[key];
|
|
549
|
+
}
|
|
550
|
+
state.tombstoneOrder = retainedKeys;
|
|
551
|
+
};
|
|
552
|
+
var MeshStore = class {
|
|
553
|
+
constructor(root, maxEventBytes, maxReadEvents, options = {}) {
|
|
554
|
+
this.root = root;
|
|
555
|
+
this.maxEventBytes = maxEventBytes;
|
|
556
|
+
this.maxReadEvents = maxReadEvents;
|
|
557
|
+
this.#eventsPath = path.join(root, "events.jsonl");
|
|
558
|
+
this.#statePath = path.join(root, "state.json");
|
|
559
|
+
this.#counterPath = path.join(root, "sequence");
|
|
560
|
+
this.#generationPath = path.join(root, "generation");
|
|
561
|
+
this.#lockPath = path.join(root, ".lock");
|
|
562
|
+
this.#schedulesPath = path.join(root, "schedules.json");
|
|
563
|
+
this.#maxEventLogBytes = Math.min(
|
|
564
|
+
CURSOR_OFFSET_BASE - 1,
|
|
565
|
+
Math.max(maxEventBytes + 2, Math.floor(options.maxEventLogBytes ?? DEFAULT_MAX_EVENT_LOG_BYTES))
|
|
566
|
+
);
|
|
567
|
+
this.#retainedEventLogBytes = Math.min(
|
|
568
|
+
this.#maxEventLogBytes - 1,
|
|
569
|
+
Math.max(
|
|
570
|
+
maxEventBytes + 1,
|
|
571
|
+
Math.floor(options.retainedEventLogBytes ?? DEFAULT_RETAINED_EVENT_LOG_BYTES)
|
|
572
|
+
)
|
|
573
|
+
);
|
|
574
|
+
this.#maxStateBytes = Math.max(
|
|
575
|
+
maxEventBytes * 2,
|
|
576
|
+
Math.floor(options.maxStateBytes ?? DEFAULT_MAX_STATE_BYTES)
|
|
577
|
+
);
|
|
578
|
+
this.#maxStateTombstones = Math.max(
|
|
579
|
+
1,
|
|
580
|
+
Math.floor(options.maxStateTombstones ?? DEFAULT_MAX_STATE_TOMBSTONES)
|
|
581
|
+
);
|
|
582
|
+
this.#lockTimeoutMs = Math.max(100, Math.floor(options.lockTimeoutMs ?? LOCK_TIMEOUT_MS));
|
|
583
|
+
this.#staleLockMs = Math.max(100, Math.floor(options.staleLockMs ?? STALE_LOCK_MS));
|
|
584
|
+
fs.mkdirSync(root, { recursive: true, mode: 448 });
|
|
585
|
+
}
|
|
586
|
+
#eventsPath;
|
|
587
|
+
#statePath;
|
|
588
|
+
#counterPath;
|
|
589
|
+
#generationPath;
|
|
590
|
+
#lockPath;
|
|
591
|
+
#maxEventLogBytes;
|
|
592
|
+
#retainedEventLogBytes;
|
|
593
|
+
#maxStateBytes;
|
|
594
|
+
#maxStateTombstones;
|
|
595
|
+
#lockTimeoutMs;
|
|
596
|
+
#staleLockMs;
|
|
597
|
+
#stateCache;
|
|
598
|
+
#schedulesPath;
|
|
599
|
+
#scheduleCache;
|
|
600
|
+
async publish(input) {
|
|
601
|
+
this.#validateTopic(input.topic);
|
|
602
|
+
if (input.to !== void 0 && !input.to.trim()) throw new Error("Mesh recipient is empty");
|
|
603
|
+
const eventData = input.data === void 0 ? void 0 : jsonClone(input.data);
|
|
604
|
+
const sender = input.sender ?? processSender();
|
|
605
|
+
return this.#withLock(() => {
|
|
606
|
+
try {
|
|
607
|
+
this.#releaseDueLocked(Date.now());
|
|
608
|
+
} catch {
|
|
609
|
+
}
|
|
610
|
+
return this.#appendLocked({ ...input, ...eventData !== void 0 ? { data: eventData } : {}, sender });
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Host-internal: runs `operation` under the mesh lock with an append
|
|
615
|
+
* capability, for side stores (grants) that must commit with an event.
|
|
616
|
+
*/
|
|
617
|
+
async transact(operation) {
|
|
618
|
+
return this.#withLock(() => {
|
|
619
|
+
try {
|
|
620
|
+
this.#releaseDueLocked(Date.now());
|
|
621
|
+
} catch {
|
|
622
|
+
}
|
|
623
|
+
return operation((input) => {
|
|
624
|
+
this.#validateTopic(input.topic);
|
|
625
|
+
return this.#appendLocked(input);
|
|
626
|
+
});
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
#appendLocked(input) {
|
|
630
|
+
this.#repairEventLog();
|
|
631
|
+
const sequence = Math.max(this.#readSequence(), this.#readLastEventSequence()) + 1;
|
|
632
|
+
const event = {
|
|
633
|
+
id: input.id ?? randomUUID(),
|
|
634
|
+
sequence,
|
|
635
|
+
topic: input.topic,
|
|
636
|
+
kind: input.kind?.trim() || "message",
|
|
637
|
+
from: jsonClone(input.from),
|
|
638
|
+
...input.to ? { to: input.to } : {},
|
|
639
|
+
...input.text !== void 0 ? { text: input.text } : {},
|
|
640
|
+
...input.data !== void 0 ? { data: jsonClone(input.data) } : {},
|
|
641
|
+
createdAt: Date.now(),
|
|
642
|
+
...input.origin ? { origin: input.origin } : {},
|
|
643
|
+
...input.untrusted ? { untrusted: true } : {},
|
|
644
|
+
...input.grantId ? { grantId: input.grantId } : {},
|
|
645
|
+
...input.scheduled ? { scheduled: { ...input.scheduled } } : {},
|
|
646
|
+
...input.sender ? { sender: jsonClone(input.sender) } : {}
|
|
647
|
+
};
|
|
648
|
+
const line = JSON.stringify(event);
|
|
649
|
+
const limit = Math.min(this.maxEventBytes, input.maxEventBytes ?? this.maxEventBytes);
|
|
650
|
+
if (Buffer.byteLength(line, "utf8") > limit) {
|
|
651
|
+
throw new Error(`Mesh event exceeds ${limit} bytes`);
|
|
652
|
+
}
|
|
653
|
+
fs.appendFileSync(this.#eventsPath, `${line}
|
|
654
|
+
`, { encoding: "utf8", mode: 384 });
|
|
655
|
+
atomicWrite(this.#counterPath, sequence);
|
|
656
|
+
this.#compactEventLog();
|
|
657
|
+
return event;
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Stores a pending event released into `topic` once `dueAt` passes. A `key`
|
|
661
|
+
* replaces any pending schedule with that key in the same locked write, so
|
|
662
|
+
* concurrent publishers never leave two schedules for one key.
|
|
663
|
+
*/
|
|
664
|
+
async schedule(input, now = Date.now()) {
|
|
665
|
+
this.#validateTopic(input.topic);
|
|
666
|
+
if (input.to !== void 0 && !input.to.trim()) throw new Error("Mesh recipient is empty");
|
|
667
|
+
if (input.key !== void 0 && !SCHEDULE_KEY_PATTERN.test(input.key)) {
|
|
668
|
+
throw new Error(`Invalid Fabric mesh schedule key: ${input.key}`);
|
|
669
|
+
}
|
|
670
|
+
if (!Number.isSafeInteger(input.dueAt) || input.dueAt < 0) {
|
|
671
|
+
throw new Error("Mesh schedule due time must be a nonnegative epoch millisecond integer");
|
|
672
|
+
}
|
|
673
|
+
if (input.dueAt > now + MESH_MAX_SCHEDULE_AHEAD_MS) {
|
|
674
|
+
throw new Error("Mesh schedules may be at most 366 days ahead");
|
|
675
|
+
}
|
|
676
|
+
const schedule = {
|
|
677
|
+
id: randomUUID(),
|
|
678
|
+
...input.key !== void 0 ? { key: input.key } : {},
|
|
679
|
+
topic: input.topic,
|
|
680
|
+
kind: input.kind?.trim() || "message",
|
|
681
|
+
from: jsonClone(input.from),
|
|
682
|
+
...input.to ? { to: input.to } : {},
|
|
683
|
+
...input.text !== void 0 ? { text: input.text } : {},
|
|
684
|
+
...input.data !== void 0 ? { data: jsonClone(input.data) } : {},
|
|
685
|
+
dueAt: input.dueAt,
|
|
686
|
+
createdAt: now,
|
|
687
|
+
sender: processSender()
|
|
688
|
+
};
|
|
689
|
+
const released = {
|
|
690
|
+
id: schedule.id,
|
|
691
|
+
sequence: Number.MAX_SAFE_INTEGER,
|
|
692
|
+
topic: schedule.topic,
|
|
693
|
+
kind: schedule.kind,
|
|
694
|
+
from: schedule.from,
|
|
695
|
+
...schedule.to ? { to: schedule.to } : {},
|
|
696
|
+
...schedule.text !== void 0 ? { text: schedule.text } : {},
|
|
697
|
+
...schedule.data !== void 0 ? { data: schedule.data } : {},
|
|
698
|
+
createdAt: Number.MAX_SAFE_INTEGER,
|
|
699
|
+
scheduled: { dueAt: schedule.dueAt, ...schedule.key !== void 0 ? { key: schedule.key } : {} },
|
|
700
|
+
...schedule.sender ? { sender: schedule.sender } : {}
|
|
701
|
+
};
|
|
702
|
+
if (Buffer.byteLength(JSON.stringify(released), "utf8") > this.maxEventBytes) {
|
|
703
|
+
throw new Error(`Mesh event exceeds ${this.maxEventBytes} bytes`);
|
|
704
|
+
}
|
|
705
|
+
return this.#withLock(() => {
|
|
706
|
+
const file = this.#readSchedules(false);
|
|
707
|
+
const pending = file.schedules.filter((entry) => input.key === void 0 || entry.key !== input.key);
|
|
708
|
+
if (pending.length >= MESH_MAX_PENDING_SCHEDULES) {
|
|
709
|
+
throw new Error(`At most ${MESH_MAX_PENDING_SCHEDULES} mesh schedules may be pending`);
|
|
710
|
+
}
|
|
711
|
+
pending.push(schedule);
|
|
712
|
+
this.#writeSchedules(pending);
|
|
713
|
+
this.#releaseDueLocked(now);
|
|
714
|
+
return jsonClone(schedule);
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
/** Removes the pending schedule with `key`, if any. */
|
|
718
|
+
async unschedule(key) {
|
|
719
|
+
if (!SCHEDULE_KEY_PATTERN.test(key)) throw new Error(`Invalid Fabric mesh schedule key: ${key}`);
|
|
720
|
+
return this.#withLock(() => {
|
|
721
|
+
const file = this.#readSchedules(false);
|
|
722
|
+
const pending = file.schedules.filter((entry) => entry.key !== key);
|
|
723
|
+
if (pending.length === file.schedules.length) return { removed: false };
|
|
724
|
+
this.#writeSchedules(pending);
|
|
725
|
+
return { removed: true };
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
/** Pending schedules by due time; a due one stays listed until a releaser appends it. */
|
|
729
|
+
scheduled(input = {}) {
|
|
730
|
+
if (input.topic !== void 0) this.#validateTopic(input.topic);
|
|
731
|
+
const limit = Math.max(1, Math.min(Math.floor(input.limit ?? 100), MESH_MAX_PENDING_SCHEDULES));
|
|
732
|
+
return this.#readSchedules(true).schedules.filter((entry) => input.topic === void 0 || entry.topic === input.topic).sort(compareSchedules).slice(0, limit).map((entry) => jsonClone(entry));
|
|
733
|
+
}
|
|
734
|
+
/** Earliest pending due time, read without the lock (one stat when unchanged). */
|
|
735
|
+
nextScheduleDueAt() {
|
|
736
|
+
let next;
|
|
737
|
+
for (const entry of this.#readSchedules(true).schedules) {
|
|
738
|
+
if (next === void 0 || entry.dueAt < next) next = entry.dueAt;
|
|
739
|
+
}
|
|
740
|
+
return next;
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* Appends every due schedule to its topic and removes it, under the mesh
|
|
744
|
+
* lock, so concurrent releasers (monitors, resident hosts, CLI posts) append
|
|
745
|
+
* each schedule once. The lock is taken only when something is due.
|
|
746
|
+
*/
|
|
747
|
+
async releaseDueSchedules(now = Date.now()) {
|
|
748
|
+
const next = this.nextScheduleDueAt();
|
|
749
|
+
if (next === void 0 || next > now) return [];
|
|
750
|
+
return this.#withLock(() => this.#releaseDueLocked(now));
|
|
751
|
+
}
|
|
752
|
+
#releaseDueLocked(now) {
|
|
753
|
+
if (!fs.existsSync(this.#schedulesPath)) return [];
|
|
754
|
+
const file = this.#readSchedules(false);
|
|
755
|
+
const due = file.schedules.filter((entry) => entry.dueAt <= now).sort(compareSchedules);
|
|
756
|
+
if (due.length === 0) return [];
|
|
757
|
+
const released = [];
|
|
758
|
+
const releasedIds = /* @__PURE__ */ new Set();
|
|
759
|
+
try {
|
|
760
|
+
for (const entry of due) {
|
|
761
|
+
released.push(this.#appendLocked({
|
|
762
|
+
id: entry.id,
|
|
763
|
+
topic: entry.topic,
|
|
764
|
+
kind: entry.kind,
|
|
765
|
+
from: entry.from,
|
|
766
|
+
...entry.to ? { to: entry.to } : {},
|
|
767
|
+
...entry.text !== void 0 ? { text: entry.text } : {},
|
|
768
|
+
...entry.data !== void 0 ? { data: entry.data } : {},
|
|
769
|
+
scheduled: { dueAt: entry.dueAt, ...entry.key !== void 0 ? { key: entry.key } : {} },
|
|
770
|
+
// Older schedules stay unstamped: the releasing host never lends its own authority.
|
|
771
|
+
...entry.sender ? { sender: entry.sender } : {}
|
|
772
|
+
}));
|
|
773
|
+
releasedIds.add(entry.id);
|
|
774
|
+
}
|
|
775
|
+
} finally {
|
|
776
|
+
if (releasedIds.size > 0) {
|
|
777
|
+
this.#writeSchedules(file.schedules.filter((entry) => !releasedIds.has(entry.id)));
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
return released;
|
|
781
|
+
}
|
|
782
|
+
#readSchedules(lenient) {
|
|
783
|
+
let stat;
|
|
784
|
+
try {
|
|
785
|
+
stat = fs.statSync(this.#schedulesPath);
|
|
786
|
+
} catch (error) {
|
|
787
|
+
this.#scheduleCache = void 0;
|
|
788
|
+
if (errorCode(error) === "ENOENT") return { format: 1, schedules: [] };
|
|
789
|
+
throw error;
|
|
790
|
+
}
|
|
791
|
+
const cached = lenient ? this.#scheduleCache : void 0;
|
|
792
|
+
if (cached && cached.inode === stat.ino && cached.size === stat.size && cached.modifiedAt === stat.mtimeMs) {
|
|
793
|
+
return cached.error === void 0 ? cached.file : { format: 1, schedules: [] };
|
|
794
|
+
}
|
|
795
|
+
let file = { format: 1, schedules: [] };
|
|
796
|
+
let damage;
|
|
797
|
+
try {
|
|
798
|
+
if (stat.size > MAX_SCHEDULE_FILE_BYTES) throw new Error(`exceeds ${MAX_SCHEDULE_FILE_BYTES} bytes`);
|
|
799
|
+
const parsed = JSON.parse(fs.readFileSync(this.#schedulesPath, "utf8"));
|
|
800
|
+
if (parsed?.format !== 1 || !Array.isArray(parsed.schedules) || !parsed.schedules.every(isMeshSchedule)) {
|
|
801
|
+
throw new Error("invalid format");
|
|
802
|
+
}
|
|
803
|
+
file = { format: 1, schedules: parsed.schedules };
|
|
804
|
+
} catch (error) {
|
|
805
|
+
damage = error instanceof Error ? error.message : String(error);
|
|
806
|
+
}
|
|
807
|
+
this.#scheduleCache = {
|
|
808
|
+
inode: stat.ino,
|
|
809
|
+
size: stat.size,
|
|
810
|
+
modifiedAt: stat.mtimeMs,
|
|
811
|
+
file,
|
|
812
|
+
...damage !== void 0 ? { error: damage } : {}
|
|
813
|
+
};
|
|
814
|
+
if (damage === void 0) return file;
|
|
815
|
+
if (lenient) return { format: 1, schedules: [] };
|
|
816
|
+
throw new Error(`Failed to read Fabric mesh schedules: ${damage}`);
|
|
817
|
+
}
|
|
818
|
+
#writeSchedules(schedules) {
|
|
819
|
+
if (schedules.length === 0) {
|
|
820
|
+
fs.rmSync(this.#schedulesPath, { force: true });
|
|
821
|
+
this.#scheduleCache = void 0;
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
atomicWrite(this.#schedulesPath, { format: 1, schedules }, MAX_SCHEDULE_FILE_BYTES);
|
|
825
|
+
this.#scheduleCache = void 0;
|
|
826
|
+
}
|
|
827
|
+
read(input = {}) {
|
|
828
|
+
if (input.topic !== void 0) this.#validateTopic(input.topic);
|
|
829
|
+
const limit = Math.max(1, Math.min(Math.floor(input.limit ?? 100), this.maxReadEvents));
|
|
830
|
+
const events = input.after === void 0 ? this.#readRecentEvents(input, limit) : this.#readEventsAfter(Math.max(0, Math.floor(input.after)), input, limit);
|
|
831
|
+
return events.map((event) => jsonClone(event));
|
|
832
|
+
}
|
|
833
|
+
latestSequence() {
|
|
834
|
+
return Math.max(this.#readSequence(), this.#readLastEventSequence());
|
|
835
|
+
}
|
|
836
|
+
latestOffset() {
|
|
837
|
+
const generation = this.#readGeneration();
|
|
838
|
+
let descriptor;
|
|
839
|
+
let completeOffset = 0;
|
|
840
|
+
try {
|
|
841
|
+
descriptor = fs.openSync(this.#eventsPath, "r");
|
|
842
|
+
const size = fs.fstatSync(descriptor).size;
|
|
843
|
+
if (size > 0) {
|
|
844
|
+
const lastByte = Buffer.allocUnsafe(1);
|
|
845
|
+
fs.readSync(descriptor, lastByte, 0, 1, size - 1);
|
|
846
|
+
if (lastByte[0] === 10) {
|
|
847
|
+
completeOffset = size;
|
|
848
|
+
} else {
|
|
849
|
+
const readBytes = Math.min(size, this.maxEventBytes + 1);
|
|
850
|
+
const tail = Buffer.allocUnsafe(readBytes);
|
|
851
|
+
fs.readSync(descriptor, tail, 0, readBytes, size - readBytes);
|
|
852
|
+
const newline = tail.lastIndexOf(10);
|
|
853
|
+
completeOffset = newline >= 0 ? size - readBytes + newline + 1 : 0;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
} catch (error) {
|
|
857
|
+
if (errorCode(error) !== "ENOENT") throw error;
|
|
858
|
+
} finally {
|
|
859
|
+
if (descriptor !== void 0) fs.closeSync(descriptor);
|
|
860
|
+
}
|
|
861
|
+
return this.#encodeCursor(generation, completeOffset);
|
|
862
|
+
}
|
|
863
|
+
tail(cursor, limit = 100) {
|
|
864
|
+
const boundedLimit = Math.max(1, Math.min(Math.floor(limit), this.maxReadEvents));
|
|
865
|
+
const generation = this.#readGeneration();
|
|
866
|
+
const decoded = this.#decodeCursor(cursor);
|
|
867
|
+
let descriptor;
|
|
868
|
+
try {
|
|
869
|
+
descriptor = fs.openSync(this.#eventsPath, "r");
|
|
870
|
+
const size = fs.fstatSync(descriptor).size;
|
|
871
|
+
let position = decoded.generation === generation ? Math.min(decoded.offset, size) : 0;
|
|
872
|
+
if (position > 0) {
|
|
873
|
+
const previousByte = Buffer.allocUnsafe(1);
|
|
874
|
+
fs.readSync(descriptor, previousByte, 0, 1, position - 1);
|
|
875
|
+
if (previousByte[0] !== 10) position = 0;
|
|
876
|
+
}
|
|
877
|
+
if (position >= size) {
|
|
878
|
+
return { events: [], nextOffset: this.#encodeCursor(generation, position) };
|
|
879
|
+
}
|
|
880
|
+
const chunkBytes = Math.min(
|
|
881
|
+
size - position,
|
|
882
|
+
Math.max(this.maxEventBytes + 1, EVENT_READ_PAGE_BYTES)
|
|
883
|
+
);
|
|
884
|
+
const buffer = Buffer.allocUnsafe(chunkBytes);
|
|
885
|
+
const bytesRead = fs.readSync(descriptor, buffer, 0, chunkBytes, position);
|
|
886
|
+
const events = [];
|
|
887
|
+
let lineStart = 0;
|
|
888
|
+
let consumed = 0;
|
|
889
|
+
for (let index = 0; index < bytesRead; index++) {
|
|
890
|
+
if (buffer[index] !== 10) continue;
|
|
891
|
+
const line = buffer.subarray(lineStart, index).toString("utf8").trim();
|
|
892
|
+
lineStart = index + 1;
|
|
893
|
+
consumed = lineStart;
|
|
894
|
+
if (line) {
|
|
895
|
+
try {
|
|
896
|
+
const event = JSON.parse(line);
|
|
897
|
+
if (typeof event.sequence === "number") events.push(event);
|
|
898
|
+
} catch {
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
if (events.length >= boundedLimit) break;
|
|
902
|
+
}
|
|
903
|
+
return {
|
|
904
|
+
events: events.map((event) => jsonClone(event)),
|
|
905
|
+
nextOffset: this.#encodeCursor(generation, position + consumed)
|
|
906
|
+
};
|
|
907
|
+
} catch (error) {
|
|
908
|
+
if (errorCode(error) === "ENOENT") {
|
|
909
|
+
return { events: [], nextOffset: this.#encodeCursor(generation, 0) };
|
|
910
|
+
}
|
|
911
|
+
throw error;
|
|
912
|
+
} finally {
|
|
913
|
+
if (descriptor !== void 0) fs.closeSync(descriptor);
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
#readRecentEvents(input, limit) {
|
|
917
|
+
let events = [];
|
|
918
|
+
let before;
|
|
919
|
+
while (events.length < limit) {
|
|
920
|
+
const page = readJsonlPage(
|
|
921
|
+
this.#eventsPath,
|
|
922
|
+
this.maxReadEvents,
|
|
923
|
+
before,
|
|
924
|
+
Math.max(this.maxEventBytes + 1, EVENT_READ_PAGE_BYTES)
|
|
925
|
+
);
|
|
926
|
+
const pageEvents = [];
|
|
927
|
+
for (const line of page.lines) {
|
|
928
|
+
const parsed = line.parsed;
|
|
929
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) continue;
|
|
930
|
+
const event = parsed;
|
|
931
|
+
if (typeof event.sequence !== "number" || !this.#eventMatches(event, input)) continue;
|
|
932
|
+
pageEvents.push(event);
|
|
933
|
+
}
|
|
934
|
+
events = [...pageEvents, ...events].slice(-limit);
|
|
935
|
+
if (!page.hasMore || page.before === void 0 || page.before === before) break;
|
|
936
|
+
before = page.before;
|
|
937
|
+
}
|
|
938
|
+
return events;
|
|
939
|
+
}
|
|
940
|
+
#readEventsAfter(after, input, limit) {
|
|
941
|
+
let descriptor;
|
|
942
|
+
try {
|
|
943
|
+
descriptor = fs.openSync(this.#eventsPath, "r");
|
|
944
|
+
const size = fs.fstatSync(descriptor).size;
|
|
945
|
+
const events = [];
|
|
946
|
+
let position = 0;
|
|
947
|
+
let lineChunks = [];
|
|
948
|
+
let lineBytes = 0;
|
|
949
|
+
let skippingOversizedLine = false;
|
|
950
|
+
let reachedLimit = false;
|
|
951
|
+
const emitLine = () => {
|
|
952
|
+
if (!skippingOversizedLine && lineBytes > 0) {
|
|
953
|
+
const decoded = Buffer.concat(lineChunks, lineBytes).toString("utf8");
|
|
954
|
+
const line = decoded.endsWith(String.fromCharCode(13)) ? decoded.slice(0, -1) : decoded;
|
|
955
|
+
try {
|
|
956
|
+
const event = JSON.parse(line);
|
|
957
|
+
if (typeof event.sequence === "number" && event.sequence > after && this.#eventMatches(event, input)) {
|
|
958
|
+
events.push(event);
|
|
959
|
+
reachedLimit = events.length >= limit;
|
|
960
|
+
}
|
|
961
|
+
} catch {
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
lineChunks = [];
|
|
965
|
+
lineBytes = 0;
|
|
966
|
+
skippingOversizedLine = false;
|
|
967
|
+
};
|
|
968
|
+
while (position < size && !reachedLimit) {
|
|
969
|
+
const readLength = Math.min(EVENT_READ_CHUNK_BYTES, size - position);
|
|
970
|
+
const chunk = Buffer.allocUnsafe(readLength);
|
|
971
|
+
const bytesRead = fs.readSync(descriptor, chunk, 0, readLength, position);
|
|
972
|
+
if (bytesRead <= 0) break;
|
|
973
|
+
position += bytesRead;
|
|
974
|
+
const captured = chunk.subarray(0, bytesRead);
|
|
975
|
+
let segmentStart = 0;
|
|
976
|
+
while (segmentStart < captured.length && !reachedLimit) {
|
|
977
|
+
const newline = captured.indexOf(10, segmentStart);
|
|
978
|
+
const segmentEnd = newline < 0 ? captured.length : newline;
|
|
979
|
+
const segment = captured.subarray(segmentStart, segmentEnd);
|
|
980
|
+
if (!skippingOversizedLine) {
|
|
981
|
+
if (lineBytes + segment.length <= this.maxEventBytes) {
|
|
982
|
+
if (segment.length > 0) lineChunks.push(segment);
|
|
983
|
+
lineBytes += segment.length;
|
|
984
|
+
} else {
|
|
985
|
+
lineChunks = [];
|
|
986
|
+
lineBytes = 0;
|
|
987
|
+
skippingOversizedLine = true;
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
if (newline < 0) break;
|
|
991
|
+
emitLine();
|
|
992
|
+
segmentStart = newline + 1;
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
if (!reachedLimit && (lineBytes > 0 || skippingOversizedLine)) emitLine();
|
|
996
|
+
return events;
|
|
997
|
+
} catch (error) {
|
|
998
|
+
if (errorCode(error) === "ENOENT") return [];
|
|
999
|
+
throw error;
|
|
1000
|
+
} finally {
|
|
1001
|
+
if (descriptor !== void 0) fs.closeSync(descriptor);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
#eventMatches(event, input) {
|
|
1005
|
+
if (input.topic !== void 0 && event.topic !== input.topic) return false;
|
|
1006
|
+
if (input.to !== void 0 && event.to !== input.to) return false;
|
|
1007
|
+
return true;
|
|
1008
|
+
}
|
|
1009
|
+
get(key) {
|
|
1010
|
+
this.#validateKey(key);
|
|
1011
|
+
const entries = this.#readCachedState().entries;
|
|
1012
|
+
return Object.hasOwn(entries, key) ? jsonClone(entries[key]) : void 0;
|
|
1013
|
+
}
|
|
1014
|
+
list(prefix = "", limit = 100) {
|
|
1015
|
+
const boundedLimit = Math.max(1, Math.min(Math.floor(limit), this.maxReadEvents));
|
|
1016
|
+
return this.listAll(prefix).slice(0, boundedLimit);
|
|
1017
|
+
}
|
|
1018
|
+
/** Internal project-state scan for host-managed indexes that must reconcile every key. */
|
|
1019
|
+
listAll(prefix = "") {
|
|
1020
|
+
if (prefix) this.#validateKey(prefix);
|
|
1021
|
+
return Object.values(this.#readCachedState().entries).filter((entry) => !prefix || entry.key.startsWith(prefix)).sort((left, right) => left.key.localeCompare(right.key)).map((entry) => jsonClone(entry));
|
|
1022
|
+
}
|
|
1023
|
+
async put(input) {
|
|
1024
|
+
const { key, value, identity, ifVersion } = input;
|
|
1025
|
+
this.#validateKey(key);
|
|
1026
|
+
const request = captureStoragePut({ key, value, identity, ifVersion }, this.maxEventBytes);
|
|
1027
|
+
return this.#withLock(() => {
|
|
1028
|
+
const state = readState(this.#statePath, this.#maxStateBytes, false);
|
|
1029
|
+
const slot = stateSlot(state, request.key);
|
|
1030
|
+
const plan = request.transition(slot.present, slot.version, slot.highWater);
|
|
1031
|
+
if (plan.kind !== "put") throw new Error("Invalid verified storage put plan");
|
|
1032
|
+
const entry = {
|
|
1033
|
+
key: plan.key,
|
|
1034
|
+
value: plan.value,
|
|
1035
|
+
version: plan.version,
|
|
1036
|
+
updatedAt: Date.now(),
|
|
1037
|
+
updatedBy: plan.identity
|
|
1038
|
+
};
|
|
1039
|
+
state.entries[plan.key] = entry;
|
|
1040
|
+
state.versions ??= {};
|
|
1041
|
+
state.versions[plan.key] = plan.version;
|
|
1042
|
+
state.format = 1;
|
|
1043
|
+
state.revisionFormat = 2;
|
|
1044
|
+
state.highWater = plan.highWater;
|
|
1045
|
+
state.tombstoneOrder = (state.tombstoneOrder ?? []).filter((key2) => key2 !== plan.key);
|
|
1046
|
+
compactStateTombstones(state, this.#maxStateTombstones);
|
|
1047
|
+
atomicWrite(this.#statePath, state, this.#maxStateBytes);
|
|
1048
|
+
this.#cacheState(state);
|
|
1049
|
+
return jsonClone(entry);
|
|
1050
|
+
});
|
|
1051
|
+
}
|
|
1052
|
+
async delete(input) {
|
|
1053
|
+
const { key, ifVersion } = input;
|
|
1054
|
+
this.#validateKey(key);
|
|
1055
|
+
const request = captureStorageDelete({ key, ifVersion });
|
|
1056
|
+
return this.#withLock(() => {
|
|
1057
|
+
const state = readState(this.#statePath, this.#maxStateBytes, false);
|
|
1058
|
+
const slot = stateSlot(state, request.key);
|
|
1059
|
+
const plan = request.transition(slot.present, slot.version, slot.highWater);
|
|
1060
|
+
if (plan.kind === "unchanged") {
|
|
1061
|
+
this.#cacheState(state);
|
|
1062
|
+
return { deleted: false };
|
|
1063
|
+
}
|
|
1064
|
+
if (plan.kind !== "delete") throw new Error("Invalid verified storage delete plan");
|
|
1065
|
+
delete state.entries[plan.key];
|
|
1066
|
+
state.versions ??= {};
|
|
1067
|
+
state.versions[plan.key] = plan.version;
|
|
1068
|
+
state.format = 1;
|
|
1069
|
+
state.revisionFormat = 2;
|
|
1070
|
+
state.highWater = plan.highWater;
|
|
1071
|
+
state.tombstoneOrder = [
|
|
1072
|
+
...(state.tombstoneOrder ?? []).filter((key2) => key2 !== plan.key),
|
|
1073
|
+
plan.key
|
|
1074
|
+
];
|
|
1075
|
+
compactStateTombstones(state, this.#maxStateTombstones);
|
|
1076
|
+
atomicWrite(this.#statePath, state, this.#maxStateBytes);
|
|
1077
|
+
this.#cacheState(state);
|
|
1078
|
+
return { deleted: true, version: plan.version };
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
#readCachedState() {
|
|
1082
|
+
try {
|
|
1083
|
+
const stat = fs.statSync(this.#statePath);
|
|
1084
|
+
const cached = this.#stateCache;
|
|
1085
|
+
if (cached && cached.device === stat.dev && cached.inode === stat.ino && cached.size === stat.size && cached.modifiedAt === stat.mtimeMs) {
|
|
1086
|
+
return cached.state;
|
|
1087
|
+
}
|
|
1088
|
+
} catch (error) {
|
|
1089
|
+
this.#stateCache = void 0;
|
|
1090
|
+
if (errorCode(error) === "ENOENT") return emptyState();
|
|
1091
|
+
throw error;
|
|
1092
|
+
}
|
|
1093
|
+
const state = readState(this.#statePath, this.#maxStateBytes);
|
|
1094
|
+
this.#cacheState(state);
|
|
1095
|
+
return state;
|
|
1096
|
+
}
|
|
1097
|
+
#cacheState(state) {
|
|
1098
|
+
try {
|
|
1099
|
+
const stat = fs.statSync(this.#statePath);
|
|
1100
|
+
this.#stateCache = {
|
|
1101
|
+
device: stat.dev,
|
|
1102
|
+
inode: stat.ino,
|
|
1103
|
+
size: stat.size,
|
|
1104
|
+
modifiedAt: stat.mtimeMs,
|
|
1105
|
+
state
|
|
1106
|
+
};
|
|
1107
|
+
} catch {
|
|
1108
|
+
this.#stateCache = void 0;
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
async #withLock(operation) {
|
|
1112
|
+
fs.mkdirSync(this.root, { recursive: true, mode: 448 });
|
|
1113
|
+
const deadline = Date.now() + this.#lockTimeoutMs;
|
|
1114
|
+
const token = randomUUID();
|
|
1115
|
+
const ownerPath = path.join(this.#lockPath, "owner");
|
|
1116
|
+
while (true) {
|
|
1117
|
+
try {
|
|
1118
|
+
fs.mkdirSync(this.#lockPath, { mode: 448 });
|
|
1119
|
+
fs.writeFileSync(ownerPath, `${token}
|
|
1120
|
+
${process.pid}
|
|
1121
|
+
${Date.now()}
|
|
1122
|
+
${encodeOwnerIdentityLine()}
|
|
1123
|
+
`, {
|
|
1124
|
+
encoding: "utf8",
|
|
1125
|
+
mode: 384
|
|
1126
|
+
});
|
|
1127
|
+
break;
|
|
1128
|
+
} catch (error) {
|
|
1129
|
+
if (errorCode(error) !== "EEXIST") throw error;
|
|
1130
|
+
if (this.#clearStaleLock(ownerPath)) continue;
|
|
1131
|
+
if (Date.now() >= deadline) throw new Error("Timed out waiting for the Fabric mesh lock");
|
|
1132
|
+
await delay(10);
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
try {
|
|
1136
|
+
return operation();
|
|
1137
|
+
} finally {
|
|
1138
|
+
try {
|
|
1139
|
+
const owner = fs.readFileSync(ownerPath, "utf8");
|
|
1140
|
+
if (owner.startsWith(`${token}
|
|
1141
|
+
`)) {
|
|
1142
|
+
fs.rmSync(this.#lockPath, { recursive: true, force: true });
|
|
1143
|
+
}
|
|
1144
|
+
} catch {
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
// Returns true when a stale lock was removed and acquisition should retry.
|
|
1149
|
+
// A lock is stale when it outlived the stale window without a live owner:
|
|
1150
|
+
// either the owner file names a dead process, or the owner file is missing
|
|
1151
|
+
// or corrupt — the owner crashed between creating the lock directory and
|
|
1152
|
+
// writing the owner file — and the untouched lock directory itself is
|
|
1153
|
+
// stale. Removal re-reads the state it judged stale so a freshly rotated
|
|
1154
|
+
// owner is never deleted mid-check.
|
|
1155
|
+
#clearStaleLock(ownerPath) {
|
|
1156
|
+
let lockModifiedAt;
|
|
1157
|
+
let owner;
|
|
1158
|
+
try {
|
|
1159
|
+
owner = fs.readFileSync(ownerPath, "utf8");
|
|
1160
|
+
} catch {
|
|
1161
|
+
try {
|
|
1162
|
+
lockModifiedAt = fs.statSync(this.#lockPath).mtimeMs;
|
|
1163
|
+
} catch {
|
|
1164
|
+
return false;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
if (owner !== void 0) {
|
|
1168
|
+
const [, pidText, createdText, identityLine] = owner.trim().split("\n");
|
|
1169
|
+
const createdAt = Number(createdText);
|
|
1170
|
+
if (Number.isFinite(createdAt) && Date.now() - createdAt <= this.#staleLockMs) return false;
|
|
1171
|
+
if (lockOwnerLiveness(Number(pidText), createdAt, identityLine, {
|
|
1172
|
+
legacyAlive: processAlive,
|
|
1173
|
+
maxHoldMs: Math.max(SHORT_LOCK_MAX_HOLD_MS, this.#staleLockMs)
|
|
1174
|
+
}) !== "dead") return false;
|
|
1175
|
+
try {
|
|
1176
|
+
if (fs.readFileSync(ownerPath, "utf8") !== owner) return false;
|
|
1177
|
+
fs.rmSync(this.#lockPath, { recursive: true, force: true });
|
|
1178
|
+
return true;
|
|
1179
|
+
} catch {
|
|
1180
|
+
return false;
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
if (lockModifiedAt === void 0 || Date.now() - lockModifiedAt <= this.#staleLockMs) {
|
|
1184
|
+
return false;
|
|
1185
|
+
}
|
|
1186
|
+
try {
|
|
1187
|
+
if (fs.statSync(this.#lockPath).mtimeMs !== lockModifiedAt) return false;
|
|
1188
|
+
fs.rmSync(this.#lockPath, { recursive: true, force: true });
|
|
1189
|
+
return true;
|
|
1190
|
+
} catch {
|
|
1191
|
+
return false;
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
#readGeneration() {
|
|
1195
|
+
try {
|
|
1196
|
+
const parsed = JSON.parse(fs.readFileSync(this.#generationPath, "utf8"));
|
|
1197
|
+
return typeof parsed === "number" && Number.isSafeInteger(parsed) && parsed >= 0 ? parsed : 0;
|
|
1198
|
+
} catch {
|
|
1199
|
+
return 0;
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
#encodeCursor(generation, offset) {
|
|
1203
|
+
const cursor = generation * CURSOR_OFFSET_BASE + offset;
|
|
1204
|
+
if (!Number.isSafeInteger(cursor) || cursor < 0) {
|
|
1205
|
+
throw new Error("Fabric mesh cursor exhausted its safe integer range");
|
|
1206
|
+
}
|
|
1207
|
+
return cursor;
|
|
1208
|
+
}
|
|
1209
|
+
#decodeCursor(cursor) {
|
|
1210
|
+
if (!Number.isSafeInteger(cursor) || cursor < 0) return { generation: -1, offset: 0 };
|
|
1211
|
+
return {
|
|
1212
|
+
generation: Math.floor(cursor / CURSOR_OFFSET_BASE),
|
|
1213
|
+
offset: cursor % CURSOR_OFFSET_BASE
|
|
1214
|
+
};
|
|
1215
|
+
}
|
|
1216
|
+
#compactEventLog() {
|
|
1217
|
+
let descriptor;
|
|
1218
|
+
try {
|
|
1219
|
+
descriptor = fs.openSync(this.#eventsPath, "r");
|
|
1220
|
+
const size = fs.fstatSync(descriptor).size;
|
|
1221
|
+
if (size <= this.#maxEventLogBytes) return;
|
|
1222
|
+
const readBytes = Math.min(
|
|
1223
|
+
size,
|
|
1224
|
+
this.#retainedEventLogBytes + this.maxEventBytes + 1
|
|
1225
|
+
);
|
|
1226
|
+
const buffer = Buffer.allocUnsafe(readBytes);
|
|
1227
|
+
const bytesRead = fs.readSync(descriptor, buffer, 0, readBytes, size - readBytes);
|
|
1228
|
+
const captured = buffer.subarray(0, bytesRead);
|
|
1229
|
+
const retentionBoundary = Math.max(0, captured.length - this.#retainedEventLogBytes);
|
|
1230
|
+
const newline = retentionBoundary === 0 ? -1 : captured.indexOf(10, retentionBoundary);
|
|
1231
|
+
const retainedStart = retentionBoundary === 0 ? 0 : newline >= 0 ? newline + 1 : captured.length;
|
|
1232
|
+
const retained = captured.subarray(retainedStart);
|
|
1233
|
+
fs.closeSync(descriptor);
|
|
1234
|
+
descriptor = void 0;
|
|
1235
|
+
const temporaryPath = this.#eventsPath + "." + process.pid + "." + randomUUID() + ".tmp";
|
|
1236
|
+
try {
|
|
1237
|
+
fs.writeFileSync(temporaryPath, retained, { mode: 384 });
|
|
1238
|
+
fs.renameSync(temporaryPath, this.#eventsPath);
|
|
1239
|
+
} finally {
|
|
1240
|
+
try {
|
|
1241
|
+
fs.rmSync(temporaryPath, { force: true });
|
|
1242
|
+
} catch {
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
atomicWrite(this.#generationPath, this.#readGeneration() + 1);
|
|
1246
|
+
} catch (error) {
|
|
1247
|
+
if (errorCode(error) !== "ENOENT") throw error;
|
|
1248
|
+
} finally {
|
|
1249
|
+
if (descriptor !== void 0) fs.closeSync(descriptor);
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
#repairEventLog() {
|
|
1253
|
+
let descriptor;
|
|
1254
|
+
try {
|
|
1255
|
+
descriptor = fs.openSync(this.#eventsPath, "r+");
|
|
1256
|
+
const size = fs.fstatSync(descriptor).size;
|
|
1257
|
+
if (size === 0) return;
|
|
1258
|
+
const lastByte = Buffer.allocUnsafe(1);
|
|
1259
|
+
fs.readSync(descriptor, lastByte, 0, 1, size - 1);
|
|
1260
|
+
if (lastByte[0] === 10) return;
|
|
1261
|
+
const readBytes = Math.min(size, this.maxEventBytes + 1);
|
|
1262
|
+
const tail = Buffer.allocUnsafe(readBytes);
|
|
1263
|
+
fs.readSync(descriptor, tail, 0, readBytes, size - readBytes);
|
|
1264
|
+
const newline = tail.lastIndexOf(10);
|
|
1265
|
+
fs.ftruncateSync(descriptor, newline >= 0 ? size - readBytes + newline + 1 : 0);
|
|
1266
|
+
} catch (error) {
|
|
1267
|
+
if (errorCode(error) !== "ENOENT") throw error;
|
|
1268
|
+
} finally {
|
|
1269
|
+
if (descriptor !== void 0) fs.closeSync(descriptor);
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
#readLastEventSequence() {
|
|
1273
|
+
let descriptor;
|
|
1274
|
+
try {
|
|
1275
|
+
descriptor = fs.openSync(this.#eventsPath, "r");
|
|
1276
|
+
const size = fs.fstatSync(descriptor).size;
|
|
1277
|
+
if (size === 0) return 0;
|
|
1278
|
+
const readBytes = Math.min(size, this.maxEventBytes + 1);
|
|
1279
|
+
const tail = Buffer.allocUnsafe(readBytes);
|
|
1280
|
+
fs.readSync(descriptor, tail, 0, readBytes, size - readBytes);
|
|
1281
|
+
const lines = tail.toString("utf8").trim().split("\n");
|
|
1282
|
+
for (let index = lines.length - 1; index >= 0; index--) {
|
|
1283
|
+
const line = lines[index];
|
|
1284
|
+
if (!line) continue;
|
|
1285
|
+
try {
|
|
1286
|
+
const parsed = JSON.parse(line);
|
|
1287
|
+
if (typeof parsed.sequence === "number" && Number.isSafeInteger(parsed.sequence)) {
|
|
1288
|
+
return parsed.sequence;
|
|
1289
|
+
}
|
|
1290
|
+
} catch {
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
return 0;
|
|
1294
|
+
} catch (error) {
|
|
1295
|
+
if (errorCode(error) === "ENOENT") return 0;
|
|
1296
|
+
throw error;
|
|
1297
|
+
} finally {
|
|
1298
|
+
if (descriptor !== void 0) fs.closeSync(descriptor);
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
#readSequence() {
|
|
1302
|
+
try {
|
|
1303
|
+
const parsed = JSON.parse(fs.readFileSync(this.#counterPath, "utf8"));
|
|
1304
|
+
return typeof parsed === "number" && Number.isSafeInteger(parsed) && parsed >= 0 ? parsed : 0;
|
|
1305
|
+
} catch (error) {
|
|
1306
|
+
if (errorCode(error) === "ENOENT") return 0;
|
|
1307
|
+
return 0;
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
#validateTopic(topic) {
|
|
1311
|
+
validateMeshTopic(topic);
|
|
1312
|
+
}
|
|
1313
|
+
#validateKey(key) {
|
|
1314
|
+
const unsafeSegment = key.split(/[/:]/).some(
|
|
1315
|
+
(segment) => segment === "__proto__" || segment === "prototype" || segment === "constructor"
|
|
1316
|
+
);
|
|
1317
|
+
if (!KEY_PATTERN.test(key) || unsafeSegment) {
|
|
1318
|
+
throw new Error(`Invalid Fabric mesh key: ${key}`);
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
};
|
|
1322
|
+
|
|
1323
|
+
export {
|
|
1324
|
+
validateMeshTopic,
|
|
1325
|
+
MESH_MAX_PENDING_SCHEDULES,
|
|
1326
|
+
MESH_MAX_SCHEDULE_AHEAD_MS,
|
|
1327
|
+
MeshStore
|
|
1328
|
+
};
|
|
1329
|
+
//# sourceMappingURL=chunk-3GJJG2FV.js.map
|