@e4779/pi-fabric 0.131.4-fork.33 → 0.138.1-fork.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/dist/actors/context.d.ts.map +1 -1
- package/dist/agents/clone-first-worktree.d.ts +2 -0
- package/dist/agents/clone-first-worktree.d.ts.map +1 -1
- package/dist/agents/completion-inbox.d.ts +2 -1
- package/dist/agents/completion-inbox.d.ts.map +1 -1
- package/dist/agents/handoff.d.ts.map +1 -1
- package/dist/agents/manager.d.ts.map +1 -1
- package/dist/agents/worktree-manager.d.ts +4 -1
- package/dist/agents/worktree-manager.d.ts.map +1 -1
- package/dist/agents/worktree-paths.d.ts +8 -3
- package/dist/agents/worktree-paths.d.ts.map +1 -1
- package/dist/agents.js +6 -1
- package/dist/agents.js.map +1 -1
- package/dist/async-settlement.d.ts +1 -1
- package/dist/async-settlement.d.ts.map +1 -1
- package/dist/audit/details.d.ts.map +1 -1
- package/dist/capture/catalog.d.ts +2 -0
- package/dist/capture/catalog.d.ts.map +1 -1
- package/dist/capture/interceptor.d.ts.map +1 -1
- package/dist/chunks/{chunk-7N7IC3Z2.js → chunk-2CD7HLVP.js} +3 -84
- package/dist/chunks/chunk-2CD7HLVP.js.map +7 -0
- package/dist/chunks/{chunk-7YNE4NB2.js → chunk-2MELFQCQ.js} +2 -2
- package/dist/chunks/{chunk-HSEZPCL5.js → chunk-2OC4YJOL.js} +3 -3
- package/dist/chunks/{chunk-TXCNZCZP.js → chunk-2QJ4MNS6.js} +2 -2
- package/dist/chunks/{chunk-F6A6MQ6G.js → chunk-2WPTD6BI.js} +11 -15
- package/dist/chunks/chunk-2WPTD6BI.js.map +7 -0
- package/dist/chunks/{chunk-QOEOKW2X.js → chunk-3QH6JAE3.js} +2 -2
- package/dist/chunks/chunk-4U47NCP2.js +88 -0
- package/dist/chunks/chunk-4U47NCP2.js.map +7 -0
- package/dist/chunks/{chunk-OJ4HAALD.js → chunk-5VZEAAHD.js} +10 -9
- package/dist/chunks/chunk-5VZEAAHD.js.map +7 -0
- package/dist/chunks/{chunk-LKYLD5SN.js → chunk-6HM4TX7L.js} +10 -8
- package/dist/chunks/chunk-6HM4TX7L.js.map +7 -0
- package/dist/chunks/{chunk-L6H46CPY.js → chunk-6NNL5LOG.js} +2 -2
- package/dist/chunks/{chunk-7TB7NXSL.js → chunk-7CIQQOOD.js} +11 -3
- package/dist/chunks/{chunk-7TB7NXSL.js.map → chunk-7CIQQOOD.js.map} +2 -2
- package/dist/chunks/{chunk-RWKQ5SRW.js → chunk-7ZFPVOV2.js} +2 -2
- package/dist/chunks/{chunk-PUBHBEYO.js → chunk-B2FIGOPI.js} +2 -2
- package/dist/chunks/{chunk-HRDMBGMY.js → chunk-BLT66VHH.js} +331 -22
- package/dist/chunks/chunk-BLT66VHH.js.map +7 -0
- package/dist/chunks/{chunk-4WKD3YM3.js → chunk-C3UPHOJW.js} +3 -3
- package/dist/chunks/{chunk-G2DZJ5LK.js → chunk-CB72SLHB.js} +451 -134
- package/dist/chunks/chunk-CB72SLHB.js.map +7 -0
- package/dist/chunks/{chunk-B5L3X3ID.js → chunk-CCJ6PUZJ.js} +1 -1
- package/dist/chunks/{chunk-B5L3X3ID.js.map → chunk-CCJ6PUZJ.js.map} +1 -1
- package/dist/chunks/{chunk-FK73YJKV.js → chunk-DWM63MAJ.js} +21 -9
- package/dist/chunks/chunk-DWM63MAJ.js.map +7 -0
- package/dist/chunks/{chunk-56NMRVTV.js → chunk-FFJ7TV66.js} +32 -29
- package/dist/chunks/chunk-FFJ7TV66.js.map +7 -0
- package/dist/chunks/{chunk-LRSZFYUC.js → chunk-FUMALXYQ.js} +15 -15
- package/dist/chunks/chunk-FUMALXYQ.js.map +7 -0
- package/dist/chunks/{chunk-TJZYM2SP.js → chunk-G3RQ3HUK.js} +8 -3
- package/dist/chunks/{chunk-TJZYM2SP.js.map → chunk-G3RQ3HUK.js.map} +2 -2
- package/dist/chunks/{chunk-RAA3FAYZ.js → chunk-GNPTDN6K.js} +2 -2
- package/dist/chunks/{chunk-XFOSUGLU.js → chunk-JCGEW5OQ.js} +5 -5
- package/dist/chunks/{chunk-CXYJJ3HZ.js → chunk-LJ2MG6U2.js} +3 -3
- package/dist/chunks/{chunk-3MOY6WIB.js → chunk-LRBDEAKB.js} +3 -3
- package/dist/chunks/{chunk-2RWNVCFD.js → chunk-MPFBOVOD.js} +1 -1
- package/dist/chunks/{chunk-2RWNVCFD.js.map → chunk-MPFBOVOD.js.map} +1 -1
- package/dist/chunks/{chunk-NQ7IWEIF.js → chunk-MQGRQMVM.js} +2 -2
- package/dist/chunks/{chunk-3VK6UGAN.js → chunk-O5SHIUIL.js} +6 -1
- package/dist/chunks/chunk-O5SHIUIL.js.map +7 -0
- package/dist/chunks/{chunk-U6Y6TKJL.js → chunk-OK2EKY3M.js} +15 -11
- package/dist/chunks/chunk-OK2EKY3M.js.map +7 -0
- package/dist/chunks/{chunk-DGUXJSYA.js → chunk-OR44GYXD.js} +70 -3
- package/dist/chunks/chunk-OR44GYXD.js.map +7 -0
- package/dist/chunks/{chunk-DGERP4VL.js → chunk-P4TALNLX.js} +11 -10
- package/dist/chunks/chunk-P4TALNLX.js.map +7 -0
- package/dist/chunks/{chunk-4BYS4ZLY.js → chunk-PHGPOSCP.js} +267 -71
- package/dist/chunks/chunk-PHGPOSCP.js.map +7 -0
- package/dist/chunks/{chunk-3XT5WHSG.js → chunk-QAGEWWCJ.js} +260 -59
- package/dist/chunks/chunk-QAGEWWCJ.js.map +7 -0
- package/dist/chunks/{chunk-WKFRGICG.js → chunk-RBYRHS24.js} +2 -2
- package/dist/chunks/{chunk-ZHROHNEE.js → chunk-RFNYH7S7.js} +8 -8
- package/dist/chunks/{chunk-VGRUWTMG.js → chunk-RPZJVLML.js} +472 -466
- package/dist/chunks/chunk-RPZJVLML.js.map +7 -0
- package/dist/chunks/{chunk-H57KPL3V.js → chunk-S2JWFXW5.js} +2 -2
- package/dist/chunks/{chunk-LZ2ZXOCU.js → chunk-SSB2JN3I.js} +168 -5
- package/dist/chunks/chunk-SSB2JN3I.js.map +7 -0
- package/dist/chunks/{chunk-RKJPBTBB.js → chunk-SVQ7ZHEQ.js} +33 -16
- package/dist/chunks/chunk-SVQ7ZHEQ.js.map +7 -0
- package/dist/chunks/{chunk-MPMEK3IQ.js → chunk-TV5NCPPS.js} +6 -5
- package/dist/chunks/chunk-TV5NCPPS.js.map +7 -0
- package/dist/chunks/{chunk-XOBLUZMB.js → chunk-UIVMSMSQ.js} +10 -1
- package/dist/chunks/chunk-UIVMSMSQ.js.map +7 -0
- package/dist/chunks/{chunk-QGTD3LAZ.js → chunk-UYS5VZUU.js} +9 -3
- package/dist/chunks/chunk-UYS5VZUU.js.map +7 -0
- package/dist/chunks/{chunk-HRVYXRWZ.js → chunk-V5RZK45W.js} +37 -3
- package/dist/chunks/chunk-V5RZK45W.js.map +7 -0
- package/dist/chunks/{chunk-KIFOEBYJ.js → chunk-VEXCD3RA.js} +2 -2
- package/dist/chunks/{chunk-GS67KDMV.js → chunk-VN7AE3EY.js} +2 -2
- package/dist/chunks/{chunk-HFDJWLMS.js → chunk-WFGJUVTH.js} +106 -65
- package/dist/chunks/chunk-WFGJUVTH.js.map +7 -0
- package/dist/chunks/chunk-WMULZZER.js +196 -0
- package/dist/chunks/chunk-WMULZZER.js.map +7 -0
- package/dist/chunks/{chunk-QNMQJNXE.js → chunk-X4HDI7RT.js} +14 -4
- package/dist/chunks/chunk-X4HDI7RT.js.map +7 -0
- package/dist/chunks/{chunk-MX53BRAC.js → chunk-XBAOTA4U.js} +2 -2
- package/dist/chunks/{chunk-MSDL7U6Q.js → chunk-XQCNVH3Y.js} +4 -4
- package/dist/chunks/{chunk-4PBW54I2.js → chunk-YC6NV7FK.js} +88 -54
- package/dist/chunks/chunk-YC6NV7FK.js.map +7 -0
- package/dist/chunks/{chunk-6GWDGTHC.js → chunk-YLO62DWD.js} +4 -4
- package/dist/cli/decisions.js +2 -2
- package/dist/cli/mesh.js +3 -3
- package/dist/commands/fabric-handler.d.ts.map +1 -1
- package/dist/commands/fabric-handler.js +18 -4
- package/dist/commands/fabric-handler.js.map +2 -2
- package/dist/commands/fabric.d.ts.map +1 -1
- package/dist/compaction/branch-summary.d.ts.map +1 -1
- package/dist/compaction/claim-events.js +9 -9
- package/dist/compaction/hook.d.ts.map +1 -1
- package/dist/compaction/hook.js +6 -6
- package/dist/compaction/normalize.d.ts +9 -0
- package/dist/compaction/normalize.d.ts.map +1 -1
- package/dist/compaction/owner.js +7 -7
- package/dist/compaction/projections.d.ts +18 -2
- package/dist/compaction/projections.d.ts.map +1 -1
- package/dist/compaction/qa.d.ts +3 -2
- package/dist/compaction/qa.d.ts.map +1 -1
- package/dist/compaction/render.d.ts +3 -0
- package/dist/compaction/render.d.ts.map +1 -1
- package/dist/compaction/threshold.d.ts.map +1 -1
- package/dist/compaction/user-activity.d.ts +31 -0
- package/dist/compaction/user-activity.d.ts.map +1 -0
- package/dist/components/configuration.js +4 -4
- package/dist/config.d.ts +13 -6
- package/dist/config.d.ts.map +1 -1
- package/dist/core/action-registry.d.ts +1 -1
- package/dist/core/action-registry.d.ts.map +1 -1
- package/dist/core/action-registry.js +10 -9
- package/dist/core/approval-controller.d.ts +3 -0
- package/dist/core/approval-controller.d.ts.map +1 -1
- package/dist/core/atomic-write.d.ts +1 -0
- package/dist/core/atomic-write.d.ts.map +1 -1
- package/dist/core/attached-monitors.d.ts +39 -0
- package/dist/core/attached-monitors.d.ts.map +1 -0
- package/dist/core/control-abort.d.ts +3 -0
- package/dist/core/control-abort.d.ts.map +1 -0
- package/dist/core/crash-guard.d.ts +15 -0
- package/dist/core/crash-guard.d.ts.map +1 -0
- package/dist/core/execution-guidelines.d.ts +6 -0
- package/dist/core/execution-guidelines.d.ts.map +1 -0
- package/dist/core/guidance-delivery.d.ts +19 -0
- package/dist/core/guidance-delivery.d.ts.map +1 -0
- package/dist/core/lifecycle-settlement.d.ts +9 -0
- package/dist/core/lifecycle-settlement.d.ts.map +1 -0
- package/dist/core/observation-actions.d.ts +9 -0
- package/dist/core/observation-actions.d.ts.map +1 -0
- package/dist/core/pasted-images.d.ts +12 -0
- package/dist/core/pasted-images.d.ts.map +1 -0
- package/dist/core/pasted-images.js +139 -0
- package/dist/core/pasted-images.js.map +7 -0
- package/dist/core/permission-queue.d.ts +32 -0
- package/dist/core/permission-queue.d.ts.map +1 -0
- package/dist/core/permission-queue.js +104 -0
- package/dist/core/permission-queue.js.map +7 -0
- package/dist/core/prompt-guidance.d.ts +1 -0
- package/dist/core/prompt-guidance.d.ts.map +1 -1
- package/dist/core/prompt-guidance.js +52 -3
- package/dist/core/prompt-guidance.js.map +3 -3
- package/dist/core/provider-operations.js +1 -1
- package/dist/core/shell-inbox.d.ts +1 -1
- package/dist/core/shell-inbox.d.ts.map +1 -1
- package/dist/core/shell-jobs.d.ts +28 -1
- package/dist/core/shell-jobs.d.ts.map +1 -1
- package/dist/core/shell-monitor.d.ts +1 -0
- package/dist/core/shell-monitor.d.ts.map +1 -1
- package/dist/durable/worker.js +0 -42
- package/dist/durable/worker.js.map +3 -3
- package/dist/durable-extension.d.ts +2 -2
- package/dist/durable-extension.d.ts.map +1 -1
- package/dist/durable-extension.js +215 -1
- package/dist/durable-extension.js.map +3 -3
- package/dist/entropy/index.d.ts +2 -0
- package/dist/entropy/index.d.ts.map +1 -1
- package/dist/entropy/index.js +23 -13
- package/dist/entropy/pool-store.d.ts +8 -1
- package/dist/entropy/pool-store.d.ts.map +1 -1
- package/dist/entropy/pool-worker.d.ts +18 -0
- package/dist/entropy/pool-worker.d.ts.map +1 -0
- package/dist/entropy/pool-writer.d.ts +23 -0
- package/dist/entropy/pool-writer.d.ts.map +1 -0
- package/dist/entropy/pool.d.ts +11 -0
- package/dist/entropy/pool.d.ts.map +1 -1
- package/dist/entropy/sessions.d.ts +5 -0
- package/dist/entropy/sessions.d.ts.map +1 -1
- package/dist/execution-service.d.ts.map +1 -1
- package/dist/extension-bootstrap.d.ts.map +1 -1
- package/dist/extension-bootstrap.js +19 -19
- package/dist/extension.d.ts.map +1 -1
- package/dist/fabric-exec-tool.d.ts.map +1 -1
- package/dist/fabric-runtime-state.d.ts.map +1 -1
- package/dist/fabric-runtime-state.js +534 -261
- package/dist/fabric-runtime-state.js.map +4 -4
- package/dist/fabric-state.d.ts.map +1 -1
- package/dist/index.js +40 -30
- package/dist/index.js.map +1 -1
- package/dist/jev/client.js +2 -2
- package/dist/jev/observation.js +7 -6
- package/dist/jev.js +12 -11
- package/dist/main-agent.d.ts.map +1 -1
- package/dist/managed-host.d.ts +4 -0
- package/dist/managed-host.d.ts.map +1 -1
- package/dist/memory/discovery.js +6 -6
- package/dist/memory/expand-service.d.ts.map +1 -1
- package/dist/memory/file-worker.js +9 -8
- package/dist/memory/file-worker.js.map +1 -1
- package/dist/memory/history-paging.d.ts +9 -0
- package/dist/memory/history-paging.d.ts.map +1 -0
- package/dist/memory/history-paging.js +164 -0
- package/dist/memory/history-paging.js.map +7 -0
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/normalize.js +5 -5
- package/dist/memory/outline-service.d.ts +7 -0
- package/dist/memory/outline-service.d.ts.map +1 -0
- package/dist/memory/request-cache.d.ts +3 -1
- package/dist/memory/request-cache.d.ts.map +1 -1
- package/dist/memory/request-context.d.ts +1 -0
- package/dist/memory/request-context.d.ts.map +1 -1
- package/dist/memory/request-limits.d.ts +2 -0
- package/dist/memory/request-limits.d.ts.map +1 -1
- package/dist/memory/search.js +7 -6
- package/dist/memory/worker-provider.d.ts.map +1 -1
- package/dist/memory/worker-provider.js +10 -9
- package/dist/memory.d.ts +16 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +64 -12
- package/dist/memory.js.map +1 -1
- package/dist/mesh/store.d.ts +2 -1
- package/dist/mesh/store.d.ts.map +1 -1
- package/dist/programs/host.js +2 -2
- package/dist/protocol.d.ts +5 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +1 -1
- package/dist/providers/agents-actions.d.ts.map +1 -1
- package/dist/providers/agents-message-router.d.ts +1 -0
- package/dist/providers/agents-message-router.d.ts.map +1 -1
- package/dist/providers/agents-provider.d.ts +2 -0
- package/dist/providers/agents-provider.d.ts.map +1 -1
- package/dist/providers/jev-provider.js +12 -11
- package/dist/providers/memory-provider.d.ts +4 -0
- package/dist/providers/memory-provider.d.ts.map +1 -1
- package/dist/providers/memory-provider.js +9 -8
- package/dist/providers/pi-read-operations.d.ts +24 -0
- package/dist/providers/pi-read-operations.d.ts.map +1 -0
- package/dist/providers/pi-tools-provider.d.ts +7 -0
- package/dist/providers/pi-tools-provider.d.ts.map +1 -1
- package/dist/providers/sessions-provider.d.ts +1 -1
- package/dist/providers/sessions-provider.d.ts.map +1 -1
- package/dist/providers/tasks-provider.d.ts +3 -1
- package/dist/providers/tasks-provider.d.ts.map +1 -1
- package/dist/residency/actor-client.js +3 -3
- package/dist/residency/client.d.ts.map +1 -1
- package/dist/residency/host.d.ts.map +1 -1
- package/dist/residency/host.js +17 -16
- package/dist/residency/launcher.js +1 -1
- package/dist/residency/pi-entry.js +17 -16
- package/dist/residency/pi-entry.js.map +1 -1
- package/dist/residency/protocol.d.ts +2 -0
- package/dist/residency/protocol.d.ts.map +1 -1
- package/dist/runtime/core-override-guest-types.js +2 -2
- package/dist/runtime/cpython-runtime.d.ts.map +1 -1
- package/dist/runtime/cpython-runtime.js +7 -6
- package/dist/runtime/cpython-runtime.js.map +2 -2
- 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/monty-runtime.d.ts.map +1 -1
- package/dist/runtime/monty-runtime.js +7 -6
- 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 +6 -6
- package/dist/runtime/quickjs-runtime.d.ts.map +1 -1
- package/dist/runtime/quickjs-runtime.js +4 -4
- package/dist/runtime/type-checker.d.ts.map +1 -1
- package/dist/runtime/type-checker.js +1 -1
- package/dist/runtime/typescript-kernel.js +10 -10
- package/dist/runtime-state-builtins.d.ts +2 -0
- package/dist/runtime-state-builtins.d.ts.map +1 -1
- package/dist/schema/policy.d.ts.map +1 -1
- package/dist/speculation/eligibility.d.ts.map +1 -1
- package/dist/speculation/store.d.ts.map +1 -1
- package/dist/topology/participant-directory.d.ts +1 -0
- package/dist/topology/participant-directory.d.ts.map +1 -1
- package/dist/topology/peer-presence.d.ts.map +1 -1
- package/dist/topology/provider-participants.d.ts +1 -0
- package/dist/topology/provider-participants.d.ts.map +1 -1
- package/dist/type-error-guidance.js +1 -1
- package/dist/ui/code-preview-shell.d.ts +1 -0
- package/dist/ui/code-preview-shell.d.ts.map +1 -1
- package/dist/ui/controller.d.ts.map +1 -1
- package/dist/ui/conversation-chrome.d.ts.map +1 -1
- package/dist/ui/conversation-chrome.js +2 -2
- package/dist/ui/conversation-feedback.d.ts +8 -0
- package/dist/ui/conversation-feedback.d.ts.map +1 -0
- package/dist/ui/conversation-latest.d.ts.map +1 -1
- package/dist/ui/conversation-native-reader.d.ts.map +1 -1
- package/dist/ui/conversation-native-reader.js +3 -3
- package/dist/ui/conversation-native-reader.js.map +2 -2
- package/dist/ui/conversation-render.d.ts.map +1 -1
- package/dist/ui/conversation.d.ts +1 -0
- package/dist/ui/conversation.d.ts.map +1 -1
- package/dist/ui/conversation.js +139 -86
- package/dist/ui/conversation.js.map +4 -4
- package/dist/ui/core-tool-render.d.ts.map +1 -1
- package/dist/ui/dashboard-fabric-graph.d.ts.map +1 -1
- package/dist/ui/dashboard.js +47 -48
- package/dist/ui/dashboard.js.map +3 -3
- package/dist/ui/fabric-render.d.ts.map +1 -1
- package/dist/ui/format.d.ts.map +1 -1
- package/dist/ui/highlight.d.ts.map +1 -1
- package/dist/ui/permissions.d.ts +18 -0
- package/dist/ui/permissions.d.ts.map +1 -0
- package/dist/ui/permissions.js +178 -0
- package/dist/ui/permissions.js.map +7 -0
- package/dist/ui/row-balance.d.ts +1 -1
- package/dist/ui/row-balance.d.ts.map +1 -1
- package/dist/ui/settings-sections-execution.d.ts.map +1 -1
- package/dist/ui/settings-values.d.ts.map +1 -1
- package/dist/ui/settings.js +37 -31
- package/dist/ui/settings.js.map +2 -2
- package/dist/ui/shell-hang-keys.d.ts.map +1 -1
- package/dist/ui/shell-tasks.d.ts.map +1 -1
- package/dist/ui/shell-tasks.js +28 -11
- package/dist/ui/shell-tasks.js.map +2 -2
- package/dist/ui/structured.d.ts.map +1 -1
- package/dist/ui/tool-display.d.ts +18 -2
- package/dist/ui/tool-display.d.ts.map +1 -1
- package/dist/ui/truncate.d.ts +3 -0
- package/dist/ui/truncate.d.ts.map +1 -0
- package/dist/ui/widget.d.ts +7 -2
- package/dist/ui/widget.d.ts.map +1 -1
- package/dist/verified/context.d.ts +35 -0
- package/dist/verified/context.d.ts.map +1 -0
- package/dist/verified/execution.d.ts +7 -0
- package/dist/verified/execution.d.ts.map +1 -0
- package/dist/verified/generated/context.d.ts +6 -0
- package/dist/verified/generated/context.js +51 -0
- package/dist/verified/generated/execution.d.ts +5 -0
- package/dist/verified/generated/execution.js +32 -0
- package/dist/verified/generated/manifest.json +34 -3
- package/dist/verified/generated/prompt-guidance.d.ts +4 -0
- package/dist/verified/generated/prompt-guidance.js +17 -0
- package/dist/worker/recovery-watchdog.d.ts +7 -0
- package/dist/worker/recovery-watchdog.d.ts.map +1 -1
- package/dist/worker/recovery-watchdog.js +66 -4
- package/dist/worker/recovery-watchdog.js.map +2 -2
- package/dist/worker.js +22 -3
- package/dist/worker.js.map +2 -2
- package/docs/agents.md +37 -4
- package/docs/architecture.md +13 -0
- package/docs/background-tasks.md +81 -5
- package/docs/benchmarks/cli-resume-2026-11-09.json +1260 -0
- package/docs/benchmarks/interactivity-2026-11-09.json +2280 -0
- package/docs/benchmarks/resume-latency-2026-11-09.json +12105 -0
- package/docs/benchmarks/resume-startup-fix-2026-11-09.json +5452 -0
- package/docs/benchmarks/session-memory-2026-11-09.json +1320 -0
- package/docs/benchmarks/session-memory-fix-2026-11-09.json +280 -0
- package/docs/compaction.md +59 -23
- package/docs/configuration.md +53 -11
- package/docs/entropy.md +4 -1
- package/docs/history-paging.md +99 -0
- package/docs/interactivity-investigation.md +109 -0
- package/docs/interface.md +2 -2
- package/docs/jev.md +1 -1
- package/docs/memory-recall.md +42 -1
- package/docs/providers.md +24 -1
- package/docs/resume-latency-investigation.md +249 -0
- package/docs/session-memory-investigation.md +223 -0
- package/docs/verified-kernels.md +56 -0
- package/package.json +211 -211
- package/proofs/context.ts +139 -0
- package/proofs/execution.ts +48 -0
- package/proofs/index.ts +6 -0
- package/proofs/prompt-guidance.ts +38 -0
- package/scripts/verified-kernels.ts +1 -1
- package/skillsets/python/fabric-council/SKILL.md +31 -21
- package/skillsets/python/fabric-exec/SKILL.md +1 -1
- package/skillsets/python/fabric-exec/references/agents.md +2 -0
- package/skillsets/python/fabric-guide/SKILL.md +1 -0
- package/skillsets/python/fabric-memory/SKILL.md +82 -0
- package/skillsets/typescript/fabric-council/SKILL.md +26 -17
- package/skillsets/typescript/fabric-exec/SKILL.md +3 -2
- package/skillsets/typescript/fabric-exec/references/agents.md +1 -0
- package/skillsets/typescript/fabric-guide/SKILL.md +1 -0
- package/skillsets/typescript/fabric-memory/SKILL.md +87 -0
- package/dist/chunks/chunk-3VK6UGAN.js.map +0 -7
- package/dist/chunks/chunk-3XT5WHSG.js.map +0 -7
- package/dist/chunks/chunk-4BYS4ZLY.js.map +0 -7
- package/dist/chunks/chunk-4PBW54I2.js.map +0 -7
- package/dist/chunks/chunk-56NMRVTV.js.map +0 -7
- package/dist/chunks/chunk-7N7IC3Z2.js.map +0 -7
- package/dist/chunks/chunk-DGERP4VL.js.map +0 -7
- package/dist/chunks/chunk-DGUXJSYA.js.map +0 -7
- package/dist/chunks/chunk-F6A6MQ6G.js.map +0 -7
- package/dist/chunks/chunk-FK73YJKV.js.map +0 -7
- package/dist/chunks/chunk-G2DZJ5LK.js.map +0 -7
- package/dist/chunks/chunk-HFDJWLMS.js.map +0 -7
- package/dist/chunks/chunk-HRDMBGMY.js.map +0 -7
- package/dist/chunks/chunk-HRVYXRWZ.js.map +0 -7
- package/dist/chunks/chunk-LKYLD5SN.js.map +0 -7
- package/dist/chunks/chunk-LRSZFYUC.js.map +0 -7
- package/dist/chunks/chunk-LZ2ZXOCU.js.map +0 -7
- package/dist/chunks/chunk-MPMEK3IQ.js.map +0 -7
- package/dist/chunks/chunk-OJ4HAALD.js.map +0 -7
- package/dist/chunks/chunk-QGTD3LAZ.js.map +0 -7
- package/dist/chunks/chunk-QNMQJNXE.js.map +0 -7
- package/dist/chunks/chunk-RKJPBTBB.js.map +0 -7
- package/dist/chunks/chunk-U6Y6TKJL.js.map +0 -7
- package/dist/chunks/chunk-VGRUWTMG.js.map +0 -7
- package/dist/chunks/chunk-XOBLUZMB.js.map +0 -7
- package/dist/durable/openai-sse-patch.d.ts +0 -21
- package/dist/durable/openai-sse-patch.d.ts.map +0 -1
- /package/dist/chunks/{chunk-7YNE4NB2.js.map → chunk-2MELFQCQ.js.map} +0 -0
- /package/dist/chunks/{chunk-HSEZPCL5.js.map → chunk-2OC4YJOL.js.map} +0 -0
- /package/dist/chunks/{chunk-TXCNZCZP.js.map → chunk-2QJ4MNS6.js.map} +0 -0
- /package/dist/chunks/{chunk-QOEOKW2X.js.map → chunk-3QH6JAE3.js.map} +0 -0
- /package/dist/chunks/{chunk-L6H46CPY.js.map → chunk-6NNL5LOG.js.map} +0 -0
- /package/dist/chunks/{chunk-RWKQ5SRW.js.map → chunk-7ZFPVOV2.js.map} +0 -0
- /package/dist/chunks/{chunk-PUBHBEYO.js.map → chunk-B2FIGOPI.js.map} +0 -0
- /package/dist/chunks/{chunk-4WKD3YM3.js.map → chunk-C3UPHOJW.js.map} +0 -0
- /package/dist/chunks/{chunk-RAA3FAYZ.js.map → chunk-GNPTDN6K.js.map} +0 -0
- /package/dist/chunks/{chunk-XFOSUGLU.js.map → chunk-JCGEW5OQ.js.map} +0 -0
- /package/dist/chunks/{chunk-CXYJJ3HZ.js.map → chunk-LJ2MG6U2.js.map} +0 -0
- /package/dist/chunks/{chunk-3MOY6WIB.js.map → chunk-LRBDEAKB.js.map} +0 -0
- /package/dist/chunks/{chunk-NQ7IWEIF.js.map → chunk-MQGRQMVM.js.map} +0 -0
- /package/dist/chunks/{chunk-WKFRGICG.js.map → chunk-RBYRHS24.js.map} +0 -0
- /package/dist/chunks/{chunk-ZHROHNEE.js.map → chunk-RFNYH7S7.js.map} +0 -0
- /package/dist/chunks/{chunk-H57KPL3V.js.map → chunk-S2JWFXW5.js.map} +0 -0
- /package/dist/chunks/{chunk-KIFOEBYJ.js.map → chunk-VEXCD3RA.js.map} +0 -0
- /package/dist/chunks/{chunk-GS67KDMV.js.map → chunk-VN7AE3EY.js.map} +0 -0
- /package/dist/chunks/{chunk-MX53BRAC.js.map → chunk-XBAOTA4U.js.map} +0 -0
- /package/dist/chunks/{chunk-MSDL7U6Q.js.map → chunk-XQCNVH3Y.js.map} +0 -0
- /package/dist/chunks/{chunk-6GWDGTHC.js.map → chunk-YLO62DWD.js.map} +0 -0
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
currentOwnerIdentity,
|
|
3
3
|
ownerIdentityFields,
|
|
4
4
|
ownerLiveness
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-2WPTD6BI.js";
|
|
6
6
|
|
|
7
7
|
// src/storage/scratch.ts
|
|
8
8
|
import fs from "node:fs";
|
|
@@ -204,4 +204,4 @@ export {
|
|
|
204
204
|
createScratch,
|
|
205
205
|
closeScratch
|
|
206
206
|
};
|
|
207
|
-
//# sourceMappingURL=chunk-
|
|
207
|
+
//# sourceMappingURL=chunk-2MELFQCQ.js.map
|
|
@@ -10,10 +10,10 @@ import {
|
|
|
10
10
|
FABRIC_EXECUTION_TRACE_VERSION,
|
|
11
11
|
FabricTraceSafeError,
|
|
12
12
|
MAX_TRACE_DEPTH
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-B2FIGOPI.js";
|
|
14
14
|
import {
|
|
15
15
|
isNormalFormWitness
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-YLO62DWD.js";
|
|
17
17
|
|
|
18
18
|
// src/audit/projection.ts
|
|
19
19
|
var emptyProjection = (args) => ({
|
|
@@ -772,4 +772,4 @@ export {
|
|
|
772
772
|
FabricExecutionTraceRecorder,
|
|
773
773
|
executionOutcomeFromError
|
|
774
774
|
};
|
|
775
|
-
//# sourceMappingURL=chunk-
|
|
775
|
+
//# sourceMappingURL=chunk-2OC4YJOL.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
applyNormalFormPlan,
|
|
3
3
|
deriveNormalFormPlan
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-YLO62DWD.js";
|
|
5
5
|
|
|
6
6
|
// src/entropy/active.ts
|
|
7
7
|
var active;
|
|
@@ -48,4 +48,4 @@ export {
|
|
|
48
48
|
applyActiveArgRepairs,
|
|
49
49
|
applyActiveActionName
|
|
50
50
|
};
|
|
51
|
-
//# sourceMappingURL=chunk-
|
|
51
|
+
//# sourceMappingURL=chunk-2QJ4MNS6.js.map
|
|
@@ -99,25 +99,20 @@ var mkdirDurableAsync = async (directory, mode, fsync, durabilityRoot) => {
|
|
|
99
99
|
var writeFileAtomic = (filePath, contents, options) => {
|
|
100
100
|
mkdirDurable(path.dirname(filePath), options?.dirMode ?? 448, options?.fsync === true, options?.durabilityRoot);
|
|
101
101
|
const temporary = `${filePath}.${process.pid}.${randomUUID()}.tmp`;
|
|
102
|
+
const descriptor = fs.openSync(temporary, "wx", options?.mode ?? 384);
|
|
103
|
+
let published = false;
|
|
102
104
|
try {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
} finally {
|
|
109
|
-
fs.closeSync(descriptor);
|
|
110
|
-
}
|
|
111
|
-
} else {
|
|
112
|
-
fs.writeFileSync(temporary, contents, {
|
|
113
|
-
encoding: "utf8",
|
|
114
|
-
mode: options?.mode ?? 384
|
|
115
|
-
});
|
|
105
|
+
try {
|
|
106
|
+
fs.writeFileSync(descriptor, contents, "utf8");
|
|
107
|
+
if (options?.fsync) fs.fsyncSync(descriptor);
|
|
108
|
+
} finally {
|
|
109
|
+
fs.closeSync(descriptor);
|
|
116
110
|
}
|
|
117
111
|
renameAtomic(temporary, filePath, options);
|
|
112
|
+
published = true;
|
|
118
113
|
if (options?.fsync) fsyncDirectory(path.dirname(filePath));
|
|
119
114
|
} finally {
|
|
120
|
-
fs.rmSync(temporary, { force: true });
|
|
115
|
+
if (!published) fs.rmSync(temporary, { force: true });
|
|
121
116
|
}
|
|
122
117
|
};
|
|
123
118
|
var writeJsonAtomic = (filePath, value, options) => {
|
|
@@ -594,6 +589,7 @@ export {
|
|
|
594
589
|
mkdirDurable,
|
|
595
590
|
writeFileAtomic,
|
|
596
591
|
writeJsonAtomic,
|
|
592
|
+
writeFileAtomicAsync,
|
|
597
593
|
writeJsonAtomicAsync,
|
|
598
594
|
currentOwnerIdentity,
|
|
599
595
|
ownerIdentityFields,
|
|
@@ -606,4 +602,4 @@ export {
|
|
|
606
602
|
releaseShortLock,
|
|
607
603
|
startOwnerHeartbeat
|
|
608
604
|
};
|
|
609
|
-
//# sourceMappingURL=chunk-
|
|
605
|
+
//# sourceMappingURL=chunk-2WPTD6BI.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/core/atomic-write.ts"],
|
|
4
|
+
"sourcesContent": ["import { randomUUID } from \"node:crypto\";\nimport fs from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\n\nexport interface AtomicWriteOptions {\n // File mode for the committed file (default 0o600) and for mkdir -p of its\n // parent directory (default 0o700).\n mode?: number;\n dirMode?: number;\n // Windows transiently rejects rename() with EPERM/EACCES/EEXIST/EBUSY while\n // an antivirus scan, indexer, or sibling reader probes the destination \u2014\n // milliseconds of contention, not a policy failure. Retry a bounded number\n // of times with linear backoff before surfacing the error.\n renameRetries?: number;\n renameRetryDelayMs?: number;\n // Flush the temporary file before rename, its directory after rename, and\n // the directory's ancestor links. Subject to filesystem/platform support.\n fsync?: boolean;\n // Inclusive directory boundary for ancestor flushing (default: filesystem\n // root). Its parent chain must already be durable and must not be renamed\n // or replaced during the operation. Must contain the target directory.\n // Ignored without fsync. Useful for stores that establish their root once.\n durabilityRoot?: string;\n}\n\nconst RETRYABLE_RENAME_CODES = new Set([\"EPERM\", \"EACCES\", \"EEXIST\", \"EBUSY\"]);\n\nconst errorCode = (error: unknown): string | undefined =>\n typeof error === \"object\" && error !== null && \"code\" in error\n ? String((error as { code?: unknown }).code)\n : undefined;\n\n// Portable synchronous sleep for the retry window (Atomics.wait is legal on\n// the Node main thread). Undefined when SharedArrayBuffer or Atomics is\n// unavailable; callers whose bound is a wait, not an attempt count, must then\n// bound by the clock instead (releaseShortLock).\nconst blockingSleep: ((ms: number) => void) | undefined = (() => {\n try {\n const buffer = new Int32Array(new SharedArrayBuffer(4));\n return (ms: number): void => {\n Atomics.wait(buffer, 0, 0, ms);\n };\n } catch {\n return undefined;\n }\n})();\n\n// Rename retries proceed immediately without a blocking sleep: still correct,\n// just less cooperative under contention.\nconst syncSleep = (ms: number): void => blockingSleep?.(ms);\n\nexport const renameAtomic = (\n source: string,\n target: string,\n options?: AtomicWriteOptions,\n): void => {\n const attempts = Math.max(1, options?.renameRetries ?? 8);\n const delay = options?.renameRetryDelayMs ?? 25;\n for (let attempt = 1; attempt <= attempts; attempt++) {\n try {\n fs.renameSync(source, target);\n return;\n } catch (error) {\n const code = errorCode(error);\n if (attempt === attempts || code === undefined || !RETRYABLE_RENAME_CODES.has(code)) {\n throw error;\n }\n syncSleep(delay * attempt);\n }\n }\n};\n\n// Windows refuses to open or flush a directory with EPERM/EACCES/EISDIR. On\n// POSIX the same EPERM/EACCES means the caller lacks access to a directory it\n// asked to make durable, so it must surface rather than pass as unsupported.\nexport const unsupportedDirectoryFsyncCodes = (platform: NodeJS.Platform): ReadonlySet<string> =>\n new Set([\"EINVAL\", \"ENOTSUP\", \"EISDIR\", ...(platform === \"win32\" ? [\"EPERM\", \"EACCES\"] : [])]);\n\nconst UNSUPPORTED_DIRECTORY_FSYNC_CODES = unsupportedDirectoryFsyncCodes(process.platform);\n\n/**\n * Flushes a directory entry table so a create or rename in it is durable.\n * Platforms that cannot open or flush a directory (Windows, some network\n * filesystems) report an error code that is ignored here; on POSIX a\n * permission error is rethrown.\n */\nexport const fsyncDirectory = (directory: string): void => {\n let descriptor: number | undefined;\n try {\n descriptor = fs.openSync(directory, \"r\");\n fs.fsyncSync(descriptor);\n } catch (error) {\n const code = errorCode(error);\n if (code === undefined || !UNSUPPORTED_DIRECTORY_FSYNC_CODES.has(code)) throw error;\n } finally {\n if (descriptor !== undefined) fs.closeSync(descriptor);\n }\n};\n\n// Never infer durability from existence: another creator (or a failed prior\n// attempt) may have made any of these directories without flushing its parent.\n// No cache is populated before or after a barrier, so retries repeat the work.\nconst directoryBarriers = (directory: string, durabilityRoot?: string): string[] => {\n const resolved = path.resolve(directory);\n const boundary = durabilityRoot === undefined ? path.parse(resolved).root : path.resolve(durabilityRoot);\n const relative = path.relative(boundary, resolved);\n if (relative === \"..\" || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {\n throw new Error(\"durabilityRoot must contain the target directory\");\n }\n const parents: string[] = [];\n for (let current = resolved; ; current = path.dirname(current)) {\n const parent = path.dirname(current);\n if (parents.at(-1) !== parent) parents.push(parent);\n // path.relative also handles case-insensitive drive/root spellings on Windows.\n if (path.relative(boundary, current) === \"\") return parents;\n }\n};\n\n/**\n * mkdir -p plus barriers for every ancestor link, including pre-existing ones.\n * By default the crash boundary is the filesystem root. With an explicit\n * inclusive durabilityRoot, its parent chain must already be durable; require\n * that parent to exist so mkdir cannot silently create above the boundary.\n * Ancestors must not be concurrently renamed/replaced. Concurrent creators\n * and retries after failed mkdir/fsync are safe: all barriers run again.\n */\nexport const mkdirDurable = (\n directory: string,\n mode: number,\n fsync: boolean,\n durabilityRoot?: string,\n): void => {\n if (!fsync) {\n fs.mkdirSync(directory, { recursive: true, mode });\n return;\n }\n const parents = directoryBarriers(directory, durabilityRoot);\n if (durabilityRoot !== undefined && !fs.statSync(parents.at(-1)!).isDirectory()) {\n throw new Error(\"durabilityRoot parent must be an existing durable directory\");\n }\n fs.mkdirSync(directory, { recursive: true, mode });\n for (const parent of parents) fsyncDirectory(parent);\n};\n\nconst fsyncDirectoryAsync = async (directory: string): Promise<void> => {\n let handle: fs.promises.FileHandle | undefined;\n try {\n handle = await fs.promises.open(directory, \"r\");\n await handle.sync();\n } catch (error) {\n const code = errorCode(error);\n if (code === undefined || !UNSUPPORTED_DIRECTORY_FSYNC_CODES.has(code)) throw error;\n } finally {\n await handle?.close();\n }\n};\n\nconst mkdirDurableAsync = async (\n directory: string,\n mode: number,\n fsync: boolean,\n durabilityRoot?: string,\n): Promise<void> => {\n if (!fsync) {\n await fs.promises.mkdir(directory, { recursive: true, mode });\n return;\n }\n const parents = directoryBarriers(directory, durabilityRoot);\n if (durabilityRoot !== undefined && !(await fs.promises.stat(parents.at(-1)!)).isDirectory()) {\n throw new Error(\"durabilityRoot parent must be an existing durable directory\");\n }\n await fs.promises.mkdir(directory, { recursive: true, mode });\n for (const parent of parents) await fsyncDirectoryAsync(parent);\n};\n\nexport const writeFileAtomic = (\n filePath: string,\n contents: string,\n options?: AtomicWriteOptions,\n): void => {\n mkdirDurable(path.dirname(filePath), options?.dirMode ?? 0o700, options?.fsync === true, options?.durabilityRoot);\n const temporary = `${filePath}.${process.pid}.${randomUUID()}.tmp`;\n // A failed exclusive open does not own this pathname and must not unlink it.\n const descriptor = fs.openSync(temporary, \"wx\", options?.mode ?? 0o600);\n let published = false;\n try {\n try {\n fs.writeFileSync(descriptor, contents, \"utf8\");\n if (options?.fsync) fs.fsyncSync(descriptor);\n } finally {\n fs.closeSync(descriptor);\n }\n renameAtomic(temporary, filePath, options);\n published = true;\n if (options?.fsync) fsyncDirectory(path.dirname(filePath));\n } finally {\n if (!published) fs.rmSync(temporary, { force: true });\n }\n};\n\nexport interface AtomicJsonOptions extends AtomicWriteOptions {\n // Pretty-print indent for JSON.stringify (default: compact).\n space?: number;\n // Some on-disk formats expect a trailing newline (schema state files).\n newline?: boolean;\n}\n\nexport const writeJsonAtomic = (\n filePath: string,\n value: unknown,\n options?: AtomicJsonOptions,\n): void => {\n const space = options?.space;\n const serialized =\n JSON.stringify(value, null, space) + (options?.newline === true ? \"\\n\" : \"\");\n writeFileAtomic(filePath, serialized, options);\n};\n\nconst asyncSleep = (ms: number): Promise<void> =>\n new Promise((resolve) => setTimeout(resolve, ms));\n\nconst renameAtomicAsync = async (\n source: string,\n target: string,\n options?: AtomicWriteOptions,\n): Promise<void> => {\n const attempts = Math.max(1, options?.renameRetries ?? 8);\n const delay = options?.renameRetryDelayMs ?? 25;\n for (let attempt = 1; attempt <= attempts; attempt++) {\n try {\n await fs.promises.rename(source, target);\n return;\n } catch (error) {\n const code = errorCode(error);\n if (attempt === attempts || code === undefined || !RETRYABLE_RENAME_CODES.has(code)) {\n throw error;\n }\n await asyncSleep(delay * attempt);\n }\n }\n};\n\nexport const writeFileAtomicAsync = async (\n filePath: string,\n contents: string,\n options?: AtomicWriteOptions,\n): Promise<void> => {\n await mkdirDurableAsync(path.dirname(filePath), options?.dirMode ?? 0o700, options?.fsync === true, options?.durabilityRoot);\n const temporary = `${filePath}.${process.pid}.${randomUUID()}.tmp`;\n try {\n if (options?.fsync) {\n const handle = await fs.promises.open(temporary, \"wx\", options.mode ?? 0o600);\n try {\n await handle.writeFile(contents, \"utf8\");\n await handle.sync();\n } finally {\n await handle.close();\n }\n } else {\n await fs.promises.writeFile(temporary, contents, {\n encoding: \"utf8\",\n mode: options?.mode ?? 0o600,\n });\n }\n await renameAtomicAsync(temporary, filePath, options);\n if (options?.fsync) await fsyncDirectoryAsync(path.dirname(filePath));\n } finally {\n await fs.promises.rm(temporary, { force: true });\n }\n};\n\nexport const writeJsonAtomicAsync = async (\n filePath: string,\n value: unknown,\n options?: AtomicJsonOptions,\n): Promise<void> => {\n const space = options?.space;\n const serialized =\n JSON.stringify(value, null, space) + (options?.newline === true ? \"\\n\" : \"\");\n await writeFileAtomicAsync(filePath, serialized, options);\n};\n\n// ---------------------------------------------------------------------------\n// Namespace-safe owner liveness. It shares this module with the atomic\n// writers whose files it guards: a separate module would become its own\n// shared chunk in the eager startup graph, which is at its file budget.\n//\n// `process.kill(pid, 0)` only answers for the\n// caller's own PID namespace and boot: inside containers the same number can\n// name an unrelated process (or nothing), and after PID reuse it names a\n// stranger. Owners therefore record who they are (host, PID namespace, boot,\n// process start time) and long-lived owners refresh a heartbeat. A probe only\n// trusts the signal answer when the record shares the caller's namespace and\n// boot; otherwise the heartbeat decides. Records without identity fields keep\n// the caller's pre-identity behaviour exactly.\n\n/** Long-lived owners refresh `heartbeatAt` this often. */\nexport const OWNER_HEARTBEAT_INTERVAL_MS = 10_000;\n/** A heartbeat older than this proves the owner dead. */\nexport const OWNER_HEARTBEAT_TTL_MS = 45_000;\n/**\n * Short-lived locks carry no heartbeat. Across namespaces their creation time\n * stands in for one, so a crashed foreign holder cannot strand a lock forever.\n *\n * The ceiling has an inherent cost: a holder suspended past it (SIGSTOP, a\n * laptop sleep, a debugger) is reaped while it still believes it holds the\n * lock, and on resuming it can finish one write after another process took\n * the lock. Its release stays safe: releaseShortLock only removes a lock\n * whose owner file carries its own token, so it never frees the new holder.\n */\nexport const SHORT_LOCK_MAX_HOLD_MS = 10 * 60_000;\n// Linux reports process start in clock ticks since boot; the wall-clock\n// conversion of each side may disagree by up to a btime rounding second.\nconst PID_START_TOLERANCE_MS = 2_000;\n// Linux USER_HZ is 100 on every mainstream architecture. Both sides of a\n// comparison use the same conversion, so only consistency matters.\nconst CLOCK_TICKS_PER_SECOND = 100;\nconst MAX_IDENTITY_JSON_CHARS = 1_024;\n\nexport type OwnerLiveness = \"alive\" | \"dead\" | \"unknown\";\n\nexport interface OwnerIdentity {\n pid: number;\n hostname: string;\n pidNamespace?: string;\n bootId?: string;\n startedAt: number;\n}\n\n/** A persisted owner. Identity fields are optional so old records still parse. */\nexport interface OwnerRecord {\n pid: number;\n hostname?: string;\n pidNamespace?: string;\n bootId?: string;\n startedAt?: number;\n}\n\nexport interface LivenessProbes {\n self?: () => OwnerIdentity;\n /** `kill(pid, 0)`: ESRCH dead, EPERM alive, anything else unknown. */\n signal?: (pid: number) => OwnerLiveness;\n /** Wall-clock start of `pid` when the platform reports it (Linux procfs). */\n processStartedAt?: (pid: number) => number | undefined;\n now?: () => number;\n}\n\nexport interface OwnerLivenessOptions {\n heartbeatAt?: number;\n heartbeatTtlMs?: number;\n /** The caller's exact pre-identity probe, used only for legacy records. */\n legacyAlive?: (pid: number) => boolean;\n probes?: LivenessProbes;\n}\n\nconst readTrimmed = (file: string): string | undefined => {\n try {\n const value = fs.readFileSync(file, \"utf8\").trim();\n return value === \"\" ? undefined : value;\n } catch {\n return undefined;\n }\n};\n\nlet bootTimeSeconds: number | undefined | null = null;\nconst readBootTimeSeconds = (): number | undefined => {\n if (bootTimeSeconds !== null) return bootTimeSeconds;\n const line = readTrimmed(\"/proc/stat\")?.split(\"\\n\").find((entry) => entry.startsWith(\"btime \"));\n const value = Number(line?.slice(\"btime \".length).trim());\n bootTimeSeconds = Number.isSafeInteger(value) && value > 0 ? value : undefined;\n return bootTimeSeconds;\n};\n\n/** Parses `/proc/<pid>/stat` (field 22, starttime) into wall-clock ms. */\nexport const parseProcStartedAt = (stat: string, bootSeconds: number): number | undefined => {\n // The command name is parenthesised and may contain spaces or parentheses.\n const fields = stat.slice(stat.lastIndexOf(\")\") + 2).split(\" \");\n const ticks = Number(fields[19]);\n if (!Number.isSafeInteger(ticks) || ticks < 0) return undefined;\n return bootSeconds * 1_000 + Math.round((ticks * 1_000) / CLOCK_TICKS_PER_SECOND);\n};\n\nconst procStartedAt = (pid: number | \"self\"): number | undefined => {\n if (process.platform !== \"linux\") return undefined;\n const boot = readBootTimeSeconds();\n const stat = readTrimmed(`/proc/${pid}/stat`);\n return boot === undefined || stat === undefined ? undefined : parseProcStartedAt(stat, boot);\n};\n\nconst signalProbe = (pid: number): OwnerLiveness => {\n if (!Number.isSafeInteger(pid) || pid <= 0) return \"dead\";\n try {\n process.kill(pid, 0);\n return \"alive\";\n } catch (error) {\n const code = errorCode(error);\n if (code === \"ESRCH\") return \"dead\";\n return code === \"EPERM\" ? \"alive\" : \"unknown\";\n }\n};\n\nlet cachedIdentity: OwnerIdentity | undefined;\n/** This process's identity, computed once on first use (never at import). */\nexport const currentOwnerIdentity = (): OwnerIdentity => {\n if (cachedIdentity) return { ...cachedIdentity };\n let pidNamespace: string | undefined;\n let bootId: string | undefined;\n let startedAt: number | undefined;\n if (process.platform === \"linux\") {\n try {\n pidNamespace = fs.readlinkSync(\"/proc/self/ns/pid\");\n } catch {\n pidNamespace = undefined;\n }\n bootId = readTrimmed(\"/proc/sys/kernel/random/boot_id\");\n // PID-reuse detection compares procfs start times, so record ours the\n // same way. Without a boot id, readers skip that comparison.\n if (bootId !== undefined) startedAt = procStartedAt(\"self\");\n if (startedAt === undefined) bootId = undefined;\n }\n cachedIdentity = {\n pid: process.pid,\n hostname: os.hostname(),\n ...(pidNamespace === undefined ? {} : { pidNamespace }),\n ...(bootId === undefined ? {} : { bootId }),\n startedAt: startedAt ?? Math.round(performance.timeOrigin),\n };\n return { ...cachedIdentity };\n};\n\nconst boundedString = (value: unknown, max: number): value is string =>\n typeof value === \"string\" && value.length > 0 && value.length <= max;\n\n/** Identity fields of a persisted record, or undefined for legacy/malformed ones. */\nexport const ownerIdentityFields = (\n value: unknown,\n): Omit<OwnerIdentity, \"pid\"> | undefined => {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) return undefined;\n const record = value as Record<string, unknown>;\n if (!boundedString(record.hostname, 255)) return undefined;\n if (record.pidNamespace !== undefined && !boundedString(record.pidNamespace, 128)) return undefined;\n if (record.bootId !== undefined && !boundedString(record.bootId, 128)) return undefined;\n if (typeof record.startedAt !== \"number\" || !Number.isFinite(record.startedAt)) return undefined;\n return {\n hostname: record.hostname,\n ...(record.pidNamespace === undefined ? {} : { pidNamespace: record.pidNamespace as string }),\n ...(record.bootId === undefined ? {} : { bootId: record.bootId as string }),\n startedAt: record.startedAt,\n };\n};\n\n/** One JSON line appended to line-oriented lock owner files. */\nexport const encodeOwnerIdentityLine = (): string => {\n const { pid: _pid, ...identity } = currentOwnerIdentity();\n return JSON.stringify(identity);\n};\n\n/** The identity line of a lock owner file; absent or malformed is legacy. */\nexport const decodeOwnerIdentityLine = (\n line: string | undefined,\n): Omit<OwnerIdentity, \"pid\"> | undefined => {\n if (!line || line.length > MAX_IDENTITY_JSON_CHARS || !line.startsWith(\"{\")) return undefined;\n try {\n return ownerIdentityFields(JSON.parse(line));\n } catch {\n return undefined;\n }\n};\n\n/** Optional heartbeat field of a persisted record. */\nconst heartbeatField = (value: unknown): number | undefined =>\n typeof value === \"object\" && value !== null &&\n typeof (value as { heartbeatAt?: unknown }).heartbeatAt === \"number\" &&\n Number.isFinite((value as { heartbeatAt: number }).heartbeatAt)\n ? (value as { heartbeatAt: number }).heartbeatAt\n : undefined;\n\n/** Additive fields a long-lived JSON owner record carries. */\nexport interface OwnerHeartbeatFields {\n identity?: Omit<OwnerIdentity, \"pid\">;\n heartbeatAt?: number;\n}\n\n/** Identity and first heartbeat for a JSON owner record being acquired. */\nexport const ownerHeartbeatFields = (now = Date.now()): Required<OwnerHeartbeatFields> => {\n const { pid: _pid, ...identity } = currentOwnerIdentity();\n return { identity, heartbeatAt: now };\n};\n\n/**\n * Liveness of a persisted JSON owner record `{ pid, identity?, heartbeatAt? }`.\n * Malformed identity is treated as legacy; a non-numeric pid is dead.\n */\nexport const recordOwnerLiveness = (\n record: unknown,\n options: Omit<OwnerLivenessOptions, \"heartbeatAt\"> = {},\n): OwnerLiveness => {\n if (typeof record !== \"object\" || record === null) return \"dead\";\n const { pid, identity: rawIdentity } = record as { pid?: unknown; identity?: unknown };\n if (typeof pid !== \"number\") return \"dead\";\n const identity = ownerIdentityFields(rawIdentity);\n const heartbeatAt = heartbeatField(record);\n return ownerLiveness(identity ? { ...identity, pid } : { pid }, {\n ...options,\n ...(heartbeatAt === undefined ? {} : { heartbeatAt }),\n });\n};\n\nexport const ownerLiveness = (\n record: OwnerRecord,\n options: OwnerLivenessOptions = {},\n): OwnerLiveness => {\n const probes = options.probes ?? {};\n const signal = probes.signal ?? signalProbe;\n if (typeof record.hostname !== \"string\") {\n return options.legacyAlive\n ? (options.legacyAlive(record.pid) ? \"alive\" : \"dead\")\n : signal(record.pid);\n }\n const self = (probes.self ?? currentOwnerIdentity)();\n const sameHost = record.hostname === self.hostname;\n if (\n sameHost &&\n record.pidNamespace === self.pidNamespace &&\n record.bootId === self.bootId\n ) {\n const answer = signal(record.pid);\n if (answer !== \"alive\") return answer;\n // Same boot: a different start time under the same PID is reuse.\n if (record.bootId !== undefined && record.startedAt !== undefined) {\n const actual = (probes.processStartedAt ?? procStartedAt)(record.pid);\n if (actual !== undefined && Math.abs(actual - record.startedAt) > PID_START_TOLERANCE_MS) {\n return \"dead\";\n }\n }\n return \"alive\";\n }\n // Another namespace, host, or boot: the signal answer means nothing here.\n if (options.heartbeatAt !== undefined) {\n const now = (probes.now ?? Date.now)();\n return now - options.heartbeatAt <= (options.heartbeatTtlMs ?? OWNER_HEARTBEAT_TTL_MS)\n ? \"alive\"\n : \"dead\";\n }\n // No process outlives its kernel boot (containers share the host's boot id).\n if (\n sameHost &&\n record.bootId !== undefined &&\n self.bootId !== undefined &&\n record.bootId !== self.bootId\n ) return \"dead\";\n return \"unknown\";\n};\n\n/**\n * Liveness of a line-oriented lock owner (`[token\\n]pid\\ncreated\\n{identity}`).\n * Short locks never heartbeat, so their creation time is the heartbeat with a\n * generous hold ceiling.\n */\nexport const lockOwnerLiveness = (\n pid: number,\n createdAt: number,\n identityLine: string | undefined,\n options: Pick<OwnerLivenessOptions, \"legacyAlive\" | \"probes\"> & { maxHoldMs?: number } = {},\n): OwnerLiveness => {\n const identity = decodeOwnerIdentityLine(identityLine);\n return ownerLiveness(identity ? { ...identity, pid } : { pid }, {\n ...options,\n ...(Number.isFinite(createdAt) ? { heartbeatAt: createdAt } : {}),\n heartbeatTtlMs: options.maxHoldMs ?? SHORT_LOCK_MAX_HOLD_MS,\n });\n};\n\n/**\n * True only when a line-oriented lock owner is provably gone, whatever the\n * lock's age: its identity line names this host, PID namespace and boot, and\n * its pid is absent or now belongs to a process started at another time.\n * Legacy owners, other hosts, namespaces or boots, unusable pids, and alive or\n * unknown probes prove nothing, so callers keep their stale-age rule for them.\n */\nexport const lockOwnerProvablyDead = (\n pid: number,\n identityLine: string | undefined,\n options: Pick<OwnerLivenessOptions, \"probes\"> = {},\n): boolean => {\n if (!Number.isSafeInteger(pid) || pid <= 0) return false;\n const identity = decodeOwnerIdentityLine(identityLine);\n if (!identity) return false;\n const self = (options.probes?.self ?? currentOwnerIdentity)();\n if (\n identity.hostname !== self.hostname ||\n identity.pidNamespace !== self.pidNamespace ||\n identity.bootId !== self.bootId\n ) return false;\n return ownerLiveness(\n { ...identity, pid },\n options.probes === undefined ? {} : { probes: options.probes },\n ) === \"dead\";\n};\n\n// ---------------------------------------------------------------------------\n// Short-lived directory locks (`mkdir` claim + `owner` file). Four stores share\n// this protocol: the mesh store, the actor registry and binding stores, and\n// the generic file lock. Their critical sections are synchronous or short\n// file I/O, so a lock that outlives SHORT_LOCK_MAX_HOLD_MS has leaked.\n//\n// Owner file: `token\\npid\\ncreatedAt\\n{identity}\\n`. Older readers only\n// consume the first three lines.\n\nconst CLAIM_INFIX = \".reap-\";\n/** How long a release keeps looking for a lock a reaper is holding. */\nexport const SHORT_LOCK_RELEASE_RETRY_MS = 25;\nconst CLAIM_SWEEP_INTERVAL_MS = 1_000;\n// Upper bound on release attempts when no blocking sleep exists.\nconst RELEASE_SPIN_ATTEMPT_CAP = 10_000;\nconst DIGITS = /^\\d+$/;\n\n/** Owner file text for a short lock acquired with `token`. */\nexport const formatShortLockOwner = (token: string): string =>\n `${token}\\n${process.pid}\\n${Date.now()}\\n${encodeOwnerIdentityLine()}\\n`;\n\nexport interface ShortLockOwner {\n token: string;\n /** Absent when the pid line is missing or not a positive decimal pid. */\n pid?: number;\n /** Absent when the creation line is missing or not a decimal number. */\n createdAt?: number;\n identityLine?: string;\n}\n\n/**\n * Parses a short-lock owner file field by field. A missing, empty or partial\n * file yields no pid: such a lock says nothing about its owner and is judged\n * by its age alone, never as a dead owner.\n */\nexport const parseShortLockOwner = (text: string): ShortLockOwner => {\n const [token = \"\", pidText = \"\", createdText = \"\", identityLine] = text.split(\"\\n\").map((line) => line.trim());\n const pid = DIGITS.test(pidText) ? Number(pidText) : Number.NaN;\n const createdAt = DIGITS.test(createdText) ? Number(createdText) : Number.NaN;\n return {\n token,\n ...(Number.isSafeInteger(pid) && pid > 0 ? { pid } : {}),\n ...(Number.isSafeInteger(createdAt) ? { createdAt } : {}),\n ...(identityLine ? { identityLine } : {}),\n };\n};\n\nexport interface ShortLockJudgeOptions {\n staleMs: number;\n /** The store's pre-identity probe for owners without an identity line. */\n legacyAlive?: (pid: number) => boolean;\n probes?: LivenessProbes;\n}\n\n/**\n * True when a short lock may be reaped.\n * - No usable pid (missing, empty or partial owner file): only when the lock\n * is older than the stale window. Its owner may be mid-acquire.\n * - Within the stale window: only when the owner is provably dead.\n * - Older than max(SHORT_LOCK_MAX_HOLD_MS, staleMs): always. A live owner\n * this old has leaked the lock; no critical section runs that long.\n * - Otherwise: when the owner is dead (namespace-safe liveness).\n * A creation time that is missing or in the future falls back to the\n * directory's mtime.\n * The hold ceiling lets a suspended holder finish one write after a reaper\n * took its lock; see SHORT_LOCK_MAX_HOLD_MS.\n */\nexport const shortLockReapable = (\n ownerText: string | undefined,\n lockModifiedAt: number | undefined,\n options: ShortLockJudgeOptions,\n): boolean => {\n const now = (options.probes?.now ?? Date.now)();\n const owner = parseShortLockOwner(ownerText ?? \"\");\n const since = owner.createdAt !== undefined && owner.createdAt <= now\n ? owner.createdAt\n : lockModifiedAt;\n if (since === undefined) return false;\n const age = now - since;\n if (owner.pid === undefined) return age > options.staleMs;\n if (age <= options.staleMs) {\n return lockOwnerProvablyDead(\n owner.pid,\n owner.identityLine,\n options.probes === undefined ? {} : { probes: options.probes },\n );\n }\n const ceiling = Math.max(SHORT_LOCK_MAX_HOLD_MS, options.staleMs);\n if (age > ceiling) return true;\n return lockOwnerLiveness(owner.pid, since, owner.identityLine, {\n ...(options.legacyAlive === undefined ? {} : { legacyAlive: options.legacyAlive }),\n ...(options.probes === undefined ? {} : { probes: options.probes }),\n maxHoldMs: ceiling,\n }) === \"dead\";\n};\n\nconst readOwnerText = (directory: string): string | undefined => {\n try {\n return fs.readFileSync(path.join(directory, \"owner\"), \"utf8\");\n } catch {\n return undefined;\n }\n};\n\nconst modifiedAt = (directory: string): number | undefined => {\n try {\n return fs.statSync(directory).mtimeMs;\n } catch {\n return undefined;\n }\n};\n\nconst ownerToken = (directory: string): string | undefined => readOwnerText(directory)?.split(\"\\n\", 1)[0];\n\n/** Device and inode of a lock directory; bigint so Windows file ids stay exact. */\nexport interface LockInode {\n dev: bigint;\n ino: bigint;\n}\n\nconst lockInode = (directory: string): LockInode | undefined => {\n try {\n const { dev, ino } = fs.lstatSync(directory, { bigint: true });\n return { dev, ino };\n } catch {\n return undefined;\n }\n};\n\nconst sameInode = (left: LockInode, right: LockInode): boolean =>\n left.dev === right.dev && left.ino === right.ino;\n\n// link() is unsupported on some filesystems (FAT/exFAT, some network and\n// FUSE mounts, sandboxes that forbid hard links).\nconst LINK_UNSUPPORTED_CODES = new Set([\"EPERM\", \"ENOTSUP\", \"EXDEV\", \"ENOSYS\"]);\n\n/**\n * Publishes `temporary` as `ownerPath` without replacing an existing owner:\n * link() fails EEXIST where rename() would overwrite. Returns false on EEXIST.\n * Where link() is unsupported, rename() is safe only after checking for an\n * existing owner *with the unique temporary already inside the directory*.\n * That nonempty directory cannot be replaced by a rename-back. If it moves,\n * rename's unique source disappears too, so publication fails with ENOENT.\n * This assumes cooperating clients move whole lock directories, not temps.\n */\nconst publishShortLockOwner = (temporary: string, ownerPath: string): boolean => {\n try {\n fs.linkSync(temporary, ownerPath);\n } catch (error) {\n const code = errorCode(error);\n if (code === \"EEXIST\") return false;\n if (code === undefined || !LINK_UNSUPPORTED_CODES.has(code)) throw error;\n try {\n fs.lstatSync(ownerPath);\n return false;\n } catch (ownerError) {\n if (errorCode(ownerError) !== \"ENOENT\") throw ownerError;\n }\n renameAtomic(temporary, ownerPath);\n return true;\n }\n try {\n fs.unlinkSync(temporary);\n } catch {\n // The lock is held; a leftover temp leaves with the directory.\n }\n return true;\n};\n\n/** A fresh claim path beside `lock`; the `t<ms>` part dates it for sweeps. */\nconst claimPath = (lock: string): string =>\n `${lock}${CLAIM_INFIX}${process.pid}-t${Date.now()}-${randomUUID()}`;\n\n/** Claim directories beside `lock`, as absolute paths. */\nconst listClaims = (lock: string, strict = false): string[] => {\n const prefix = `${path.basename(lock)}${CLAIM_INFIX}`;\n try {\n return fs.readdirSync(path.dirname(lock))\n .filter((name: string) => name.startsWith(prefix))\n .map((name: string) => path.join(path.dirname(lock), name));\n } catch (error) {\n if (strict) throw error;\n return [];\n }\n};\n\n/**\n * Creates the lock directory exclusively and publishes its owner file\n * atomically. `mkdir` stays the canonical claim, as in older versions.\n * Upgraded acquirers additionally refuse in-flight rename claims (see below).\n * The owner is written to a\n * temporary file inside the lock and hard-linked into place: a reader sees no\n * owner (judged by the directory's age) or a complete one, never an empty or\n * partial owner. Returns false on contention.\n *\n * The link refuses to publish over an existing owner. A reaper whose claim\n * held a live lock renames it back, and POSIX rename() silently replaces the\n * empty directory this call just created. Publishing then targets the other\n * owner's directory; link() fails EEXIST, so this returns false and removes\n * only its own temporary file, never the directory (it is the other owner's\n * lock). See publishShortLockOwner for the rename fallback.\n *\n * After publication, a strict claim scan is followed by canonical inode and\n * owner verification. A displaced successful holder remains in a claim, so\n * no successor may enter until it is restored or released. If displacement\n * occurs after this scan/check, the next acquirer sees that claim instead.\n * Fail closed on scan errors. Older binaries do not honor this barrier and\n * retain their rename-window race; ordinary mixed-version mkdir contention\n * still works. See docs/short-lock-protocol.md.\n */\nexport const tryAcquireShortLock = (lock: string, ownerText: string): boolean => {\n try {\n fs.mkdirSync(lock, { mode: 0o700 });\n } catch (error) {\n if (errorCode(error) === \"EEXIST\") return false;\n throw error;\n }\n const created = lockInode(lock);\n const temporary = path.join(lock, `owner.${process.pid}.${randomUUID()}.tmp`);\n try {\n fs.writeFileSync(temporary, ownerText, { encoding: \"utf8\", mode: 0o600 });\n if (publishShortLockOwner(temporary, path.join(lock, \"owner\"))) {\n try {\n const claims = listClaims(lock, true);\n const canonical = lockInode(lock);\n if (claims.length === 0 && created !== undefined && canonical !== undefined\n && sameInode(created, canonical) && readOwnerText(lock) === ownerText) return true;\n } catch {\n // Cannot establish exclusion: withdraw, never enter the critical section.\n }\n releaseShortLock(lock, parseShortLockOwner(ownerText).token, 0);\n return false;\n }\n } catch (error) {\n // ENOENT: a reaper claimed the directory mid-publish. Whatever it puts\n // back has no owner and ages out; retry as contention.\n if (errorCode(error) === \"ENOENT\") return false;\n try {\n fs.rmSync(temporary, { force: true });\n // Only an empty directory is removed: never another owner's lock.\n fs.rmdirSync(lock);\n } catch {\n // The lock ages out.\n }\n throw error;\n }\n // EEXIST: another owner's live lock sits at `lock`. Contention.\n try {\n fs.rmSync(temporary, { force: true });\n } catch {\n // A stray temp leaves with that owner's directory.\n }\n return false;\n};\n\n/**\n * Removes the lock directory `lock` only when `verify(claimed)` accepts the\n * directory this process claimed by renaming it. Returns true when it removed\n * the lock, false when the claim failed or held another owner's lock.\n *\n * Stale-lock recovery must be an exclusive claim. Stat-then-delete is\n * TOCTOU: two reapers (or a reaper and a fresh writer that recreated the\n * lock in between) can both pass their checks, and the slower rm then\n * deletes a lock the faster one already replaced. rename() is the claim \u2014\n * only one process can move the directory, and removal targets the claimed\n * path, never the live lock path. A claim that turns out to hold a live\n * lock is renamed back before any destructive step; a live lock is never\n * deleted, even if the rename-back races a fresh writer. A live owner that\n * releases while its lock sits at the claim path takes it from there\n * (releaseShortLock), so the rename-back then finds nothing to restore.\n *\n * `expected` is the lock directory's inode when the caller judged it (stat it\n * before reading the owner); without it the lock is stat'd just before the\n * rename. When the claimed directory is a different inode, the lock was\n * reaped and re-acquired in between: the claim holds someone else's live\n * lock, so it is renamed back at once, without reading its owner or calling\n * `verify`, and never deleted. If that rename-back fails it is left for its\n * owner's release or the claim sweep.\n *\n * The claim itself is an acquisition barrier even on an inode mismatch.\n * A successor can populate the canonical directory but must withdraw before\n * entering its critical section while this claim exists. Restoration may\n * still fail; the barrier then persists until owner release or safe stale\n * cleanup. No compare-and-rename primitive or recursively reaped guard is\n * needed. Inode reuse is not detected here; `verify` also compares the owner.\n */\nexport const reapLockByRenameClaim = (\n lock: string,\n verify: (claimed: string) => boolean,\n expected: LockInode | undefined = lockInode(lock),\n): boolean => {\n if (expected === undefined) return false;\n const claim = claimPath(lock);\n try {\n fs.renameSync(lock, claim);\n } catch {\n return false;\n }\n const claimed = lockInode(claim);\n if (claimed === undefined || !sameInode(claimed, expected)) {\n try {\n fs.renameSync(claim, lock);\n } catch {\n // Left as a claim: its owner's release takes it, or the sweep does.\n }\n return false;\n }\n if (!verify(claim)) {\n try {\n fs.renameSync(claim, lock);\n } catch {\n // `lock` was recreated after the claim, or the owner released from the\n // claim path. Re-verify before any destructive step so a claimed live\n // lock is only ever left for its owner's release or the stale sweep,\n // never deleted.\n if (verify(claim)) fs.rmSync(claim, { recursive: true, force: true });\n }\n return false;\n }\n fs.rmSync(claim, { recursive: true, force: true });\n return true;\n};\n\nconst lastClaimSweep = new Map<string, number>();\n\n/**\n * Removes claim directories beside `lock` older than `staleMs`: reapers or\n * releasers that died mid-claim, or rename-backs that lost a race. Claims\n * are acquisition barriers: age alone must not discard a displaced live\n * holder. Require the ordinary owner-staleness verdict too. Returns the count.\n *\n * A claim's age comes from the `t<ms>` stamp in its name, which is the\n * claimant's clock, not this process's: a claimant whose clock runs ahead\n * makes its claim look younger, one that runs behind makes it look older.\n * Claims without a stamp (older versions) fall back to the directory's mtime,\n * which is when its contents last changed, not when it was claimed.\n */\nexport const sweepStaleLockClaims = (lock: string, staleMs: number, now = Date.now()): number => {\n let removed = 0;\n for (const claim of listClaims(lock)) {\n const stamp = /-t(\\d{1,15})-[^-]/.exec(path.basename(claim).slice(path.basename(lock).length + CLAIM_INFIX.length));\n let since = stamp ? Number(stamp[1]) : Number.NaN;\n if (!Number.isSafeInteger(since)) {\n try {\n since = fs.lstatSync(claim).mtimeMs;\n } catch {\n continue;\n }\n }\n if (now - since <= staleMs) continue;\n let owner: string | undefined;\n try {\n owner = fs.readFileSync(path.join(claim, \"owner\"), \"utf8\");\n } catch (error) {\n if (errorCode(error) !== \"ENOENT\") continue;\n }\n if (!shortLockReapable(owner, modifiedAt(claim), { staleMs, probes: { now: () => now } })) continue;\n try {\n fs.rmSync(claim, { recursive: true, force: true });\n removed += 1;\n } catch {\n // Another sweeper or the owner's release got there first.\n }\n }\n return removed;\n};\n\n/**\n * One stale-lock recovery step for a contended short lock: sweeps old claim\n * directories (at most once a second per lock and process), judges the lock\n * with shortLockReapable, and removes it through a rename claim that\n * re-verifies the same owner text and verdict. True when it removed the lock\n * and acquisition should retry at once. Never throws.\n */\nexport const reapStaleShortLock = (lock: string, options: ShortLockJudgeOptions): boolean => {\n try {\n const now = Date.now();\n if (now - (lastClaimSweep.get(lock) ?? 0) >= CLAIM_SWEEP_INTERVAL_MS) {\n lastClaimSweep.set(lock, now);\n if (lastClaimSweep.size > 256) lastClaimSweep.delete(lastClaimSweep.keys().next().value!);\n sweepStaleLockClaims(lock, options.staleMs, now);\n }\n // Stat before reading: the rename claim must take this same directory.\n const judged = lockInode(lock);\n if (judged === undefined) return false;\n const owner = readOwnerText(lock);\n const lockModifiedAt = modifiedAt(lock);\n if (lockModifiedAt === undefined) return false;\n if (!shortLockReapable(owner, lockModifiedAt, options)) return false;\n // Re-read: a rotated owner is judged afresh on the next attempt.\n if (readOwnerText(lock) !== owner) return false;\n return reapLockByRenameClaim(lock, (claimed) =>\n readOwnerText(claimed) === owner && shortLockReapable(owner, modifiedAt(claimed), options), judged);\n } catch {\n return false;\n }\n};\n\n/** Moves `source` to a private claim and deletes it when it holds `token`. */\nconst takeOwnLock = (lock: string, source: string, token: string): boolean => {\n if (ownerToken(source) !== token) return false;\n const trash = claimPath(lock);\n try {\n fs.renameSync(source, trash);\n } catch {\n return false;\n }\n if (ownerToken(trash) === token) {\n fs.rmSync(trash, { recursive: true, force: true });\n return true;\n }\n // Another owner's directory replaced ours between the read and the rename.\n try {\n fs.renameSync(trash, source);\n } catch {\n // Left as a claim: its owner's release takes it, or the sweep does.\n }\n return false;\n};\n\n/**\n * Releases a short lock acquired with `token`. The lock may be sitting at a\n * reaper's claim path (`<lock>.reap-*`) while the reaper verifies it; the\n * release then takes it from there, so the reaper's rename-back finds nothing\n * and cannot restore a released lock. A rename-back may also land between\n * two checks, so the release retries for a bounded few milliseconds.\n * Returns false when the lock was not found (reaped, or replaced by an\n * owner with another token, which is never touched).\n */\nexport const releaseShortLock = (\n lock: string,\n token: string,\n retryMs = SHORT_LOCK_RELEASE_RETRY_MS,\n): boolean => {\n // With a blocking sleep the bound is counted in 1 ms sleeps, not wall-clock\n // reads, so a frozen or faked clock cannot turn it into a spin. Without one,\n // counting attempts would collapse the window to microseconds, so the clock\n // bounds it and a hard attempt cap still stops a frozen or rewound clock.\n const deadline = Date.now() + retryMs;\n for (let attempt = 0; ; attempt++) {\n try {\n if (takeOwnLock(lock, lock, token)) return true;\n for (const claim of listClaims(lock)) {\n if (takeOwnLock(lock, claim, token)) return true;\n }\n } catch {\n // Raced with a reaper or sweeper; look again.\n }\n if (blockingSleep !== undefined) {\n if (attempt >= retryMs) return false;\n blockingSleep(1);\n } else if (attempt >= RELEASE_SPIN_ATTEMPT_CAP || Date.now() >= deadline) {\n return false;\n }\n }\n};\n\n/**\n * Runs `refresh(now)` on an unref'd interval until the returned stop function\n * is called. Refresh failures are swallowed: a missed beat only ages the\n * record toward the TTL.\n */\nexport const startOwnerHeartbeat = (\n refresh: (heartbeatAt: number) => void,\n intervalMs = OWNER_HEARTBEAT_INTERVAL_MS,\n): (() => void) => {\n const timer = setInterval(() => {\n try {\n refresh(Date.now());\n } catch {\n // The next beat retries; a stale heartbeat is the failure signal.\n }\n }, intervalMs);\n timer.unref?.();\n return () => clearInterval(timer);\n};\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,kBAAkB;AAC3B,OAAO,QAAQ;AACf,OAAO,QAAQ;AACf,OAAO,UAAU;AAuBjB,IAAM,yBAAyB,oBAAI,IAAI,CAAC,SAAS,UAAU,UAAU,OAAO,CAAC;AAE7E,IAAM,YAAY,CAAC,UACjB,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU,QACrD,OAAQ,MAA6B,IAAI,IACzC;AAMN,IAAM,iBAAqD,MAAM;AAC/D,MAAI;AACF,UAAM,SAAS,IAAI,WAAW,IAAI,kBAAkB,CAAC,CAAC;AACtD,WAAO,CAAC,OAAqB;AAC3B,cAAQ,KAAK,QAAQ,GAAG,GAAG,EAAE;AAAA,IAC/B;AAAA,EACF,QAAQ;AACN,WAAO;AAAA,EACT;AACF,GAAG;AAIH,IAAM,YAAY,CAAC,OAAqB,gBAAgB,EAAE;AAEnD,IAAM,eAAe,CAC1B,QACA,QACA,YACS;AACT,QAAM,WAAW,KAAK,IAAI,GAAG,SAAS,iBAAiB,CAAC;AACxD,QAAM,QAAQ,SAAS,sBAAsB;AAC7C,WAAS,UAAU,GAAG,WAAW,UAAU,WAAW;AACpD,QAAI;AACF,SAAG,WAAW,QAAQ,MAAM;AAC5B;AAAA,IACF,SAAS,OAAO;AACd,YAAM,OAAO,U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,IAAM,mBAAmB,CAC9B,MACA,OACA,UAAU,gCACE;AAKZ,QAAM,WAAW,KAAK,IAAI,IAAI;AAC9B,WAAS,UAAU,KAAK,WAAW;AACjC,QAAI;AACF,UAAI,YAAY,MAAM,MAAM,KAAK,EAAG,QAAO;AAC3C,iBAAW,SAAS,WAAW,IAAI,GAAG;AACpC,YAAI,YAAY,MAAM,OAAO,KAAK,EAAG,QAAO;AAAA,MAC9C;AAAA,IACF,QAAQ;AAAA,IAER;AACA,QAAI,kBAAkB,QAAW;AAC/B,UAAI,WAAW,QAAS,QAAO;AAC/B,oBAAc,CAAC;AAAA,IACjB,WAAW,WAAW,4BAA4B,KAAK,IAAI,KAAK,UAAU;AACxE,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAOO,IAAM,sBAAsB,CACjC,SACA,aAAa,gCACI;AACjB,QAAM,QAAQ,YAAY,MAAM;AAC9B,QAAI;AACF,cAAQ,KAAK,IAAI,CAAC;AAAA,IACpB,QAAQ;AAAA,IAER;AAAA,EACF,GAAG,UAAU;AACb,QAAM,QAAQ;AACd,SAAO,MAAM,cAAc,KAAK;AAClC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
readFabricExecutionTraceV1
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-B2FIGOPI.js";
|
|
4
4
|
|
|
5
5
|
// src/compaction/branch-details.ts
|
|
6
6
|
var FABRIC_BRANCH_SUMMARY_KIND = "pi-fabric.branch-summary";
|
|
@@ -218,4 +218,4 @@ export {
|
|
|
218
218
|
readFabricBranchSummaryDetails,
|
|
219
219
|
readFabricProjectionTrace
|
|
220
220
|
};
|
|
221
|
-
//# sourceMappingURL=chunk-
|
|
221
|
+
//# sourceMappingURL=chunk-3QH6JAE3.js.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {
|
|
2
|
+
truncateString
|
|
3
|
+
} from "./chunk-2CD7HLVP.js";
|
|
4
|
+
import {
|
|
5
|
+
applyActiveArgRepairs,
|
|
6
|
+
getActiveRepairCompiler,
|
|
7
|
+
normalizeActiveArguments
|
|
8
|
+
} from "./chunk-2QJ4MNS6.js";
|
|
9
|
+
|
|
10
|
+
// src/core/action-arguments.ts
|
|
11
|
+
import { Value } from "typebox/value";
|
|
12
|
+
var MAX_VALIDATION_MESSAGE_CHARS = 2e3;
|
|
13
|
+
var unexpectedKeys = (schema, value) => {
|
|
14
|
+
if (schema.type !== "object") return [];
|
|
15
|
+
if (schema.additionalProperties !== false) return [];
|
|
16
|
+
if (schema.patternProperties !== void 0) return [];
|
|
17
|
+
const properties = schema.properties;
|
|
18
|
+
if (!properties) return [];
|
|
19
|
+
return Object.keys(value).filter((key) => !Object.hasOwn(properties, key));
|
|
20
|
+
};
|
|
21
|
+
var validationMessage = (schema, value) => {
|
|
22
|
+
try {
|
|
23
|
+
if (Value.Check(schema, value)) return void 0;
|
|
24
|
+
const messages = [...Value.Errors(schema, value)].slice(0, 5).map((error) => {
|
|
25
|
+
const location = error;
|
|
26
|
+
const at = location.instancePath ?? location.path;
|
|
27
|
+
return typeof at === "string" && at !== "" && at !== "/" ? `${at}: ${error.message}` : error.message;
|
|
28
|
+
});
|
|
29
|
+
for (const key of unexpectedKeys(schema, value).slice(0, 5)) {
|
|
30
|
+
messages.push(`/${key}: must not have additional properties`);
|
|
31
|
+
}
|
|
32
|
+
return truncateString(
|
|
33
|
+
messages.join("; ") || "Schema validation failed",
|
|
34
|
+
MAX_VALIDATION_MESSAGE_CHARS
|
|
35
|
+
);
|
|
36
|
+
} catch {
|
|
37
|
+
return "Schema validator failed";
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var declaredPropertyNames = (schema) => {
|
|
41
|
+
const properties = schema.properties;
|
|
42
|
+
return properties ? Object.keys(properties) : [];
|
|
43
|
+
};
|
|
44
|
+
var repairCatalogInput = (ref, schema, args) => {
|
|
45
|
+
const extras = unexpectedKeys(schema, args).sort();
|
|
46
|
+
const observedUnexpected = extras.length > 0 ? extras.join("\0") : void 0;
|
|
47
|
+
if (extras.length > 0) {
|
|
48
|
+
getActiveRepairCompiler()?.observeInvalidArgs(
|
|
49
|
+
ref,
|
|
50
|
+
args,
|
|
51
|
+
declaredPropertyNames(schema),
|
|
52
|
+
extras.join(","),
|
|
53
|
+
{ countError: false, extraKeys: extras }
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
return { args: applyActiveArgRepairs(ref, args, schema), observedUnexpected };
|
|
57
|
+
};
|
|
58
|
+
var validateCatalogArgs = (ref, schema, args, observedUnexpected) => {
|
|
59
|
+
const compiler = getActiveRepairCompiler();
|
|
60
|
+
const normalize = (input) => {
|
|
61
|
+
const result = normalizeActiveArguments(ref, schema, input);
|
|
62
|
+
return { args: result.args, ...result.witness ? { normalization: result.witness } : {} };
|
|
63
|
+
};
|
|
64
|
+
const first = normalize(applyActiveArgRepairs(ref, args, schema));
|
|
65
|
+
const invalid = validationMessage(schema, first.args);
|
|
66
|
+
if (!invalid) return first;
|
|
67
|
+
const extras = unexpectedKeys(schema, first.args).sort();
|
|
68
|
+
if (observedUnexpected === void 0 || extras.join("\0") !== observedUnexpected) {
|
|
69
|
+
compiler?.observeInvalidArgs(
|
|
70
|
+
ref,
|
|
71
|
+
first.args,
|
|
72
|
+
declaredPropertyNames(schema),
|
|
73
|
+
invalid,
|
|
74
|
+
{ countError: false, extraKeys: extras }
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
const second = normalize(applyActiveArgRepairs(ref, first.args, schema));
|
|
78
|
+
const stillInvalid = validationMessage(schema, second.args);
|
|
79
|
+
if (stillInvalid) compiler?.recordInvocationError();
|
|
80
|
+
return stillInvalid ? { args: second.args, invalid: stillInvalid } : second;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export {
|
|
84
|
+
validationMessage,
|
|
85
|
+
repairCatalogInput,
|
|
86
|
+
validateCatalogArgs
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=chunk-4U47NCP2.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/core/action-arguments.ts"],
|
|
4
|
+
"sourcesContent": ["import { Value } from \"typebox/value\";\nimport { normalizeActiveArguments } from \"../entropy/active.js\";\nimport type { NormalFormWitness } from \"../entropy/normal-form.js\";\nimport { applyActiveArgRepairs, getActiveRepairCompiler } from \"../repairs/active.js\";\nimport { truncateString } from \"./action-result.js\";\n\nconst MAX_VALIDATION_MESSAGE_CHARS = 2_000;\n\n// TypeBox reports additionalProperties failures against the object root\n// without naming the offending keys; name them so a rejected near-miss call\n// is actionable (e.g. a before/after guess on memory.expand surfaces as\n// \"/before: must not have additional properties\").\nconst unexpectedKeys = (\n schema: Record<string, unknown>,\n value: Record<string, unknown>,\n): string[] => {\n if ((schema as { type?: unknown }).type !== \"object\") return [];\n if ((schema as { additionalProperties?: unknown }).additionalProperties !== false) return [];\n if ((schema as { patternProperties?: unknown }).patternProperties !== undefined) return [];\n const properties = (schema as { properties?: Record<string, unknown> }).properties;\n if (!properties) return [];\n return Object.keys(value).filter((key) => !Object.hasOwn(properties, key));\n};\n\nexport const validationMessage = (\n schema: Record<string, unknown>,\n value: Record<string, unknown>,\n): string | undefined => {\n try {\n if (Value.Check(schema, value)) return undefined;\n const messages = [...Value.Errors(schema, value)]\n .slice(0, 5)\n .map((error) => {\n // Prefix nested failures with their property path.\n const location = error as { instancePath?: unknown; path?: unknown };\n const at = location.instancePath ?? location.path;\n return typeof at === \"string\" && at !== \"\" && at !== \"/\"\n ? `${at}: ${error.message}`\n : error.message;\n });\n for (const key of unexpectedKeys(schema, value).slice(0, 5)) {\n messages.push(`/${key}: must not have additional properties`);\n }\n return truncateString(\n messages.join(\"; \") || \"Schema validation failed\",\n MAX_VALIDATION_MESSAGE_CHARS,\n );\n } catch {\n return \"Schema validator failed\";\n }\n};\n\nconst declaredPropertyNames = (schema: Record<string, unknown>): string[] => {\n const properties = (schema as { properties?: Record<string, unknown> }).properties;\n return properties ? Object.keys(properties) : [];\n};\n\nexport const repairCatalogInput = (\n ref: string,\n schema: Record<string, unknown>,\n args: Record<string, unknown>,\n): { args: Record<string, unknown>; observedUnexpected: string | undefined } => {\n const extras = unexpectedKeys(schema, args).sort();\n const observedUnexpected = extras.length > 0 ? extras.join(\"\\0\") : undefined;\n if (extras.length > 0) {\n getActiveRepairCompiler()?.observeInvalidArgs(\n ref, args, declaredPropertyNames(schema), extras.join(\",\"),\n { countError: false, extraKeys: extras },\n );\n }\n return { args: applyActiveArgRepairs(ref, args, schema), observedUnexpected };\n};\n\nexport const validateCatalogArgs = (\n ref: string,\n schema: Record<string, unknown>,\n args: Record<string, unknown>,\n observedUnexpected: string | undefined,\n): { args: Record<string, unknown>; invalid?: string; normalization?: NormalFormWitness } => {\n const compiler = getActiveRepairCompiler();\n const normalize = (input: Record<string, unknown>) => {\n const result = normalizeActiveArguments(ref, schema, input);\n return { args: result.args, ...(result.witness ? { normalization: result.witness } : {}) };\n };\n // Provider-owned preparation has already run. Generic conventions may\n // recover leftover invalid representations, never override an adapter's\n // interpretation or bypass its preparation errors.\n const first = normalize(applyActiveArgRepairs(ref, args, schema));\n const invalid = validationMessage(schema, first.args);\n if (!invalid) return first;\n const extras = unexpectedKeys(schema, first.args).sort();\n if (observedUnexpected === undefined || extras.join(\"\\0\") !== observedUnexpected) {\n compiler?.observeInvalidArgs(\n ref, first.args, declaredPropertyNames(schema), invalid,\n { countError: false, extraKeys: extras },\n );\n }\n const second = normalize(applyActiveArgRepairs(ref, first.args, schema));\n const stillInvalid = validationMessage(schema, second.args);\n if (stillInvalid) compiler?.recordInvocationError();\n return stillInvalid ? { args: second.args, invalid: stillInvalid } : second;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;AAAA,SAAS,aAAa;AAMtB,IAAM,+BAA+B;AAMrC,IAAM,iBAAiB,CACrB,QACA,UACa;AACb,MAAK,OAA8B,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import {
|
|
7
|
-
transpileFabricCodeWithSourceMap
|
|
8
|
-
} from "./chunk-3IJEQBFS.js";
|
|
5
|
+
} from "./chunk-6HM4TX7L.js";
|
|
9
6
|
import {
|
|
10
7
|
HumanWaitDeadlinePause
|
|
11
8
|
} from "./chunk-UPMWLOKL.js";
|
|
12
9
|
import {
|
|
10
|
+
transpileFabricCodeWithSourceMap
|
|
11
|
+
} from "./chunk-3IJEQBFS.js";
|
|
12
|
+
import {
|
|
13
|
+
fabricControlAbort,
|
|
13
14
|
piBashExitMetadata
|
|
14
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-UIVMSMSQ.js";
|
|
15
16
|
import {
|
|
16
17
|
resolveScriptRuntime,
|
|
17
18
|
resolveScriptRuntimeSync
|
|
@@ -22,7 +23,7 @@ import {
|
|
|
22
23
|
import {
|
|
23
24
|
runAbortable,
|
|
24
25
|
settleWithin
|
|
25
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-7CIQQOOD.js";
|
|
26
27
|
|
|
27
28
|
// src/runtime/node-process-runtime.ts
|
|
28
29
|
import { spawn } from "node:child_process";
|
|
@@ -237,7 +238,7 @@ var NodeProcessRuntime = class {
|
|
|
237
238
|
if (deadline) clearTimeout(deadline);
|
|
238
239
|
if (abortHandler) options.signal?.removeEventListener("abort", abortHandler);
|
|
239
240
|
if (!hostAbortController.signal.aborted && hostTasks.size > 0) {
|
|
240
|
-
hostAbortController.abort(
|
|
241
|
+
hostAbortController.abort(fabricControlAbort(result.error ?? "Process execution stopped"));
|
|
241
242
|
}
|
|
242
243
|
child.removeAllListeners();
|
|
243
244
|
if (child.connected) child.disconnect();
|
|
@@ -305,7 +306,7 @@ var NodeProcessRuntime = class {
|
|
|
305
306
|
finishing = true;
|
|
306
307
|
if (deadline) clearTimeout(deadline);
|
|
307
308
|
if (hostTasks.size > 0 && !hostAbortController.signal.aborted) {
|
|
308
|
-
hostAbortController.abort(
|
|
309
|
+
hostAbortController.abort(fabricControlAbort(message.result.error ?? "Process execution stopped"));
|
|
309
310
|
}
|
|
310
311
|
void (async () => {
|
|
311
312
|
const completed = await settleWithin(hostTasks, HOST_TASK_SETTLE_GRACE_MS);
|
|
@@ -405,4 +406,4 @@ export {
|
|
|
405
406
|
NodeProcessRuntime,
|
|
406
407
|
BunProcessRuntime
|
|
407
408
|
};
|
|
408
|
-
//# sourceMappingURL=chunk-
|
|
409
|
+
//# sourceMappingURL=chunk-5VZEAAHD.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/runtime/node-process-runtime.ts", "../../src/runtime/node-process-child-source.ts"],
|
|
4
|
+
"sourcesContent": ["import { spawn, type ChildProcess } from \"node:child_process\";\nimport { runAbortable, settleWithin } from \"../async-settlement.js\";\nimport { piBashExitMetadata } from \"../core/pi-bash-error.js\";\nimport { isPiShellRef } from \"../core/pi-tools.js\";\nimport { HumanWaitDeadlinePause } from \"./deadline-pause.js\";\nimport { guestSetupSource } from \"./quickjs-runtime.js\";\nimport type { FabricHostCall, FabricSandboxOptions, FabricSandboxResult } from \"./kernel.js\";\nimport { NODE_PROCESS_CHILD_SOURCE } from \"./node-process-child-source.js\";\nimport { createGuestStackMap, remapGuestErrorText } from \"./guest-stack-map.js\";\nimport { transpileFabricCodeWithSourceMap } from \"./type-checker.js\";\nimport {\n resolveScriptRuntime,\n resolveScriptRuntimeSync,\n} from \"../agents/transports/process-utils.js\";\nimport { fabricControlAbort } from \"../core/control-abort.js\";\n\ninterface ChildCallMessage {\n type: \"call\";\n id: number;\n ref: string;\n args: Record<string, unknown>;\n}\n\ninterface ChildResultMessage {\n type: \"result\";\n result: FabricSandboxResult;\n}\n\ntype ChildMessage = ChildCallMessage | ChildResultMessage | { type: \"output\"; text?: string; image?: unknown };\n\nconst HOST_TASK_SETTLE_GRACE_MS = 250;\n\nconst send = (child: ChildProcess, message: any): void => {\n if (!child.connected) return;\n child.send(message, () => undefined);\n};\n\nexport class NodeProcessRuntime {\n readonly #interpreter: \"node\" | \"bun\";\n\n constructor(interpreter: \"node\" | \"bun\" = \"node\") {\n this.#interpreter = interpreter;\n }\n\n async execute(\n code: string,\n hostCall: FabricHostCall,\n options: FabricSandboxOptions,\n ): Promise<FabricSandboxResult> {\n if (options.signal?.aborted) {\n return {\n value: undefined,\n logs: [],\n terminationReason: \"aborted\",\n error: \"Execution cancelled\",\n };\n }\n if (!Number.isSafeInteger(options.memoryLimitBytes) || options.memoryLimitBytes < 1) {\n return {\n value: undefined,\n logs: [],\n terminationReason: \"runtime_error\",\n error: \"Process memory limit must be a positive safe integer\",\n };\n }\n if (!Number.isFinite(options.timeoutMs) || options.timeoutMs < 1) {\n return {\n value: undefined,\n logs: [],\n terminationReason: \"runtime_error\",\n error: \"Process timeout must be positive\",\n };\n }\n\n // Bun evaluates --eval input as ESM and ignores V8 heap flags, so the\n // Bun child gets the guest source bare; Node needs the module + heap flags.\n // Bun resolution stays async: Pi may legitimately run under Node while bun\n // is only available on PATH, and the sync variant does no PATH lookup.\n const runtimeOptions = this.#interpreter === \"bun\" ? { requireBun: true } : { requireNode: true };\n const interpreterPath = this.#interpreter === \"bun\"\n ? await resolveScriptRuntime(runtimeOptions)\n : resolveScriptRuntimeSync(runtimeOptions);\n const child = spawn(\n interpreterPath,\n this.#interpreter === \"bun\"\n ? [\"--eval\", NODE_PROCESS_CHILD_SOURCE]\n : [\n // Guest import() through importModuleDynamically needs the vm\n // modules flag; Bun's vm ignores the option (see __fabricImport).\n \"--experimental-vm-modules\",\n `--max-old-space-size=${Math.max(16, Math.floor(options.memoryLimitBytes / (1024 * 1024)))}`,\n \"--input-type=module\",\n \"--eval\",\n NODE_PROCESS_CHILD_SOURCE,\n ],\n { stdio: [\"ignore\", \"ignore\", \"ignore\", \"ipc\"] },\n );\n // Bun resolution is async, so the signal may have aborted while resolving.\n if (options.signal?.aborted) {\n return {\n value: undefined,\n logs: [],\n terminationReason: \"aborted\",\n error: \"Execution cancelled\",\n };\n }\n const hostAbortController = new AbortController();\n const startedAt = Date.now();\n let effectiveTimeoutMs = options.timeoutMs;\n let deadlineAt = startedAt + effectiveTimeoutMs;\n let deadline: NodeJS.Timeout | undefined;\n let abortHandler: (() => void) | undefined;\n let settled = false;\n let finishing = false;\n const hostTasks = new Set<Promise<void>>();\n const partialLogs: string[] = [];\n const partialImages: unknown[] = [];\n let partialChars = 0;\n\n const guestBundle = options.transpiledCode === undefined\n ? transpileFabricCodeWithSourceMap(code)\n : { code: options.transpiledCode, sourceMap: options.transpiledSourceMap };\n const guestStackMap = createGuestStackMap(guestBundle.sourceMap);\n const guestLineCount = guestBundle.code.split(\"\\n\").length;\n\n return new Promise<FabricSandboxResult>((resolve) => {\n const finish = (result: FabricSandboxResult): void => {\n if (settled) return;\n settled = true;\n if (deadline) clearTimeout(deadline);\n if (abortHandler) options.signal?.removeEventListener(\"abort\", abortHandler);\n if (!hostAbortController.signal.aborted && hostTasks.size > 0) {\n hostAbortController.abort(fabricControlAbort(result.error ?? \"Process execution stopped\"));\n }\n child.removeAllListeners();\n if (child.connected) child.disconnect();\n if (child.exitCode === null && child.signalCode === null) child.kill(\"SIGKILL\");\n resolve(result.terminationReason === \"completed\" ? result : { ...result, logs: result.logs.length ? result.logs : partialLogs, emitted: result.emitted?.length ? result.emitted : partialImages });\n };\n const scheduleDeadline = (): void => {\n clearTimeout(deadline);\n if (settled || finishing) return;\n options.onDeadline?.(Number.isFinite(deadlineAt) ? deadlineAt : undefined);\n if (!Number.isFinite(deadlineAt)) return;\n deadline = setTimeout(() => {\n const error = `Execution timed out after ${effectiveTimeoutMs}ms`;\n finish({ value: undefined, logs: [], terminationReason: \"timed_out\", error });\n }, Math.min(2_147_483_647, Math.max(0, deadlineAt - Date.now())));\n deadline.unref?.();\n };\n const extendDeadline = (ref: string, args: Record<string, unknown>): void => {\n const requested = options.minimumTimeoutMsForHostCall?.(ref, args);\n if (typeof requested !== \"number\" || !Number.isFinite(requested)) return;\n if (humanWait.paused) {\n humanWait.raise(requested);\n return;\n }\n const nextDeadlineAt = Date.now() + Math.max(1, Math.floor(requested));\n if (nextDeadlineAt <= deadlineAt) return;\n deadlineAt = nextDeadlineAt;\n effectiveTimeoutMs = deadlineAt - startedAt;\n scheduleDeadline();\n };\n\n const humanWait = new HumanWaitDeadlinePause({\n remainingMs: () => deadlineAt - Date.now(),\n suspend: () => {\n clearTimeout(deadline);\n deadlineAt = Infinity;\n options.onDeadline?.(undefined);\n },\n resume: (remainingMs) => {\n deadlineAt = Date.now() + remainingMs;\n scheduleDeadline();\n },\n });\n\n abortHandler = () => {\n finish({\n value: undefined,\n logs: [],\n terminationReason: \"aborted\",\n error: \"Execution cancelled\",\n });\n };\n options.signal?.addEventListener(\"abort\", abortHandler, { once: true });\n\n child.on(\"message\", (raw: unknown) => {\n if (settled || finishing || typeof raw !== \"object\" || raw === null) return;\n const message = raw as ChildMessage;\n if (message.type === \"output\") {\n const chars = typeof message.text === \"string\" ? message.text.length : JSON.stringify(message.image ?? null).length;\n partialChars += chars;\n if (partialChars <= 16_777_216) {\n if (typeof message.text === \"string\") partialLogs.push(message.text);\n else if (message.image !== undefined) partialImages.push(message.image);\n }\n return;\n }\n if (message.type === \"result\") {\n finishing = true;\n if (deadline) clearTimeout(deadline);\n if (hostTasks.size > 0 && !hostAbortController.signal.aborted) {\n hostAbortController.abort(fabricControlAbort(message.result.error ?? \"Process execution stopped\"));\n }\n void (async () => {\n const completed = await settleWithin(hostTasks, HOST_TASK_SETTLE_GRACE_MS);\n if (!completed && !hostAbortController.signal.aborted) {\n hostAbortController.abort(\n new Error(\"Fabric guest execution ended before its host calls settled\"),\n );\n await settleWithin(hostTasks, HOST_TASK_SETTLE_GRACE_MS);\n }\n finish(\n message.result.error === undefined\n ? message.result\n : {\n ...message.result,\n error: remapGuestErrorText(message.result.error, guestStackMap, guestLineCount),\n },\n );\n })();\n return;\n }\n if (message.type !== \"call\") return;\n extendDeadline(message.ref, message.args);\n if (message.ref === \"fabric.$timer\") {\n const ms = Math.max(0, Number(message.args?.ms ?? 0));\n let timer: NodeJS.Timeout | undefined;\n const timerTask = new Promise<void>((resolveTask) => {\n timer = setTimeout(() => {\n if (!settled && !finishing) {\n send(child, { type: \"response\", id: message.id, ok: true, value: undefined });\n }\n resolveTask();\n }, ms);\n timer!.unref?.();\n });\n hostTasks.add(timerTask);\n void timerTask.finally(() => {\n hostTasks.delete(timerTask);\n if (timer) clearTimeout(timer);\n });\n return;\n }\n const waitsForHuman = options.isHumanWaitHostCall?.(message.ref, message.args) === true;\n if (waitsForHuman) humanWait.enter();\n const task = runAbortable(hostAbortController.signal, () =>\n hostCall(message.ref, message.args, hostAbortController.signal, (wait) => humanWait.run(wait)),\n ).finally(() => {\n if (waitsForHuman) humanWait.leave();\n }).then(\n (value) => send(child, { type: \"response\", id: message.id, ok: true, value }),\n (error) =>\n send(child, {\n type: \"response\",\n id: message.id,\n ok: false,\n error: error instanceof Error ? error.message : String(error),\n bashExit: isPiShellRef(message.ref) ? piBashExitMetadata(error) : undefined,\n }),\n );\n hostTasks.add(task);\n void task.finally(() => hostTasks.delete(task));\n });\n child.once(\"error\", (error) => {\n finish({\n value: undefined,\n logs: [],\n terminationReason: \"runtime_error\",\n error: `Process executor failed: ${error.message}`,\n });\n });\n child.once(\"exit\", (exitCode, signal) => {\n if (settled) return;\n const detail = signal ? `signal ${signal}` : `exit code ${exitCode ?? \"unknown\"}`;\n finish({\n value: undefined,\n logs: [],\n terminationReason: \"runtime_error\",\n error: `Process executor exited before returning a result (${detail}); it may have exceeded its memory limit`,\n });\n });\n\n scheduleDeadline();\n send(child, {\n type: \"execute\",\n setup: guestSetupSource(options.piToolCanonicalFields, options.nativeStoreEnabled, options.codemodeProfile, options.nativeToolsEnabled, options.providerGlobals),\n code: guestBundle.code,\n strings: options.strings ?? {},\n tokenBudget: options.tokenBudget,\n maxLogChars: options.maxLogChars ?? 100_000,\n });\n });\n }\n}\n\nexport class BunProcessRuntime extends NodeProcessRuntime {\n constructor() {\n super(\"bun\");\n }\n}\n", "export const NODE_PROCESS_CHILD_SOURCE = String.raw`\nimport vm from \"node:vm\";\n\nconst pending = new Map();\nlet nextCallId = 0;\n\nconst send = (message) => {\n if (process.connected) process.send?.(message);\n};\n\nconst formatValue = (value) => {\n if (typeof value === \"string\") return value;\n if (value instanceof Error) return value.stack ?? value.message;\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n};\n\nconst jsonCompatible = (value) => {\n if (value === undefined) return undefined;\n const serialized = JSON.stringify(value);\n return serialized === undefined ? undefined : JSON.parse(serialized);\n};\n\nconst run = async (message) => {\n const logs = [];\n let logChars = 0;\n let logsTruncated = false;\n const hostCall = (ref, args) => {\n const id = nextCallId++;\n return new Promise((resolve, reject) => {\n pending.set(id, { resolve, reject });\n send({\n type: \"call\",\n id,\n ref: String(ref),\n args:\n typeof args === \"object\" && args !== null && !Array.isArray(args)\n ? args\n : {},\n });\n });\n };\n const emitLog = line => { logs.push(line); send({ type: \"output\", text: line }); };\n const print = (...values) => {\n if (logsTruncated) return;\n const line = values.map(formatValue).join(\" \");\n const remaining = message.maxLogChars - logChars;\n if (line.length > remaining) {\n if (remaining > 0) emitLog(line.slice(0, remaining));\n emitLog(\"[Pi Fabric log output truncated]\");\n logsTruncated = true;\n return;\n }\n emitLog(line);\n logChars += line.length;\n };\n\n // Bun module namespace for the guest. The child resolves the specifier in\n // its own module context; under the node runtime it fails and the binding\n // stays undefined. Namespace objects come from this realm, so instanceof\n // against guest-realm classes fails (same caveat as other sandbox bridges).\n const __bun = await import(\"bun\").catch(() => undefined);\n const sandbox = {\n __fabricHostCall: hostCall,\n __fabricEmitImage: image => send({ type: \"output\", image }),\n __fabricTokenBudget: message.tokenBudget ?? Number.POSITIVE_INFINITY,\n // Native-module bridge for guests whose vm lacks the dynamic-import\n // callback. Bun >= 1.4 honors importModuleDynamically on runInContext\n // (natural import() works there), so this is mostly a fallback and an\n // explicit escape hatch. Cross-realm caveat: namespaces come from this\n // realm, so instanceof against guest-realm classes fails.\n __fabricImport: (specifier) => import(specifier),\n // Resolved above; undefined under the node runtime.\n __bun,\n print,\n \u03C0: jsonCompatible(message.strings),\n };\n const context = vm.createContext(sandbox, {\n name: \"pi-fabric-node-process\",\n codeGeneration: { strings: true, wasm: false },\n });\n\n try {\n vm.runInContext(message.setup, context, { filename: \"pi-fabric-setup.js\" });\n const promise = vm.runInContext(message.code + \"\\nglobalThis.__fabricRun(__piFabricMain)\", context, {\n filename: \"pi-fabric-guest.js\",\n // Node requires --experimental-vm-modules (set at spawn). Bun >= 1.4\n // honors this option on runInContext (unlike on createContext), so\n // natural guest import() works there; __fabricImport is a fallback.\n importModuleDynamically: (specifier) => import(specifier),\n });\n const value = jsonCompatible(await promise);\n send({ type: \"result\", result: { value, logs, emitted: jsonCompatible(context.__fabricEmitted), terminationReason: \"completed\" } });\n } catch (error) {\n send({\n type: \"result\",\n result: {\n logs,\n emitted: jsonCompatible(context.__fabricEmitted),\n terminationReason: \"runtime_error\",\n error: error?.stack ?? error?.message ?? String(error),\n },\n });\n }\n};\n\nprocess.on(\"message\", (message) => {\n if (typeof message !== \"object\" || message === null) return;\n if (message.type === \"execute\") {\n void run(message);\n return;\n }\n if (message.type !== \"response\") return;\n const operation = pending.get(message.id);\n if (!operation) return;\n pending.delete(message.id);\n if (message.ok) operation.resolve(message.value);\n else {\n const error = new Error(message.error ?? \"Host call failed\");\n if (message.bashExit) error.__fabricBashExit = message.bashExit;\n operation.reject(error);\n }\n});\n`;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAgC;;;ACAlC,IAAM,4BAA4B,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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AM,YAAY;AAAA,QAClB,SAAS,QAAQ,WAAW,CAAC;AAAA,QAC7B,aAAa,QAAQ;AAAA,QACrB,aAAa,QAAQ,eAAe;AAAA,MACtC,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;AAEO,IAAM,oBAAN,cAAgC,mBAAmB;AAAA,EACxD,cAAc;AACZ,UAAM,KAAK;AAAA,EACb;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
transpileFabricCodeWithSourceMap
|
|
3
|
-
} from "./chunk-3IJEQBFS.js";
|
|
4
1
|
import {
|
|
5
2
|
HumanWaitDeadlinePause
|
|
6
3
|
} from "./chunk-UPMWLOKL.js";
|
|
4
|
+
import {
|
|
5
|
+
transpileFabricCodeWithSourceMap
|
|
6
|
+
} from "./chunk-3IJEQBFS.js";
|
|
7
7
|
import {
|
|
8
8
|
PI_ARGUMENT_NORMALIZATION_SOURCE
|
|
9
9
|
} from "./chunk-6KO2LEOO.js";
|
|
10
10
|
import {
|
|
11
|
+
fabricControlAbort,
|
|
11
12
|
piBashExitMetadata
|
|
12
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-UIVMSMSQ.js";
|
|
13
14
|
import {
|
|
14
15
|
providerGlobalNames
|
|
15
16
|
} from "./chunk-35EEGOH3.js";
|
|
@@ -19,7 +20,7 @@ import {
|
|
|
19
20
|
import {
|
|
20
21
|
runAbortable,
|
|
21
22
|
settleWithin
|
|
22
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-7CIQQOOD.js";
|
|
23
24
|
|
|
24
25
|
// src/runtime/quickjs-runtime.ts
|
|
25
26
|
import releaseSyncVariant from "@jitl/quickjs-singlefile-mjs-release-sync";
|
|
@@ -673,6 +674,7 @@ globalThis.agents = Object.freeze({
|
|
|
673
674
|
run: (args) => __call("agents.run", args),
|
|
674
675
|
handoff: __handoff,
|
|
675
676
|
spawn: (args) => __call("agents.spawn", args),
|
|
677
|
+
observe: (args) => __call("agents.observe", args),
|
|
676
678
|
wait: (args) => __call("agents.wait", args),
|
|
677
679
|
join: (args) => __call("agents.join", args),
|
|
678
680
|
status: (args) => __call("agents.status", args),
|
|
@@ -1122,7 +1124,7 @@ var QuickJsRuntime = class {
|
|
|
1122
1124
|
const hostAbortController = new AbortController();
|
|
1123
1125
|
const abortHostCalls = (reason) => {
|
|
1124
1126
|
if (!hostAbortController.signal.aborted) {
|
|
1125
|
-
hostAbortController.abort(
|
|
1127
|
+
hostAbortController.abort(fabricControlAbort(reason));
|
|
1126
1128
|
}
|
|
1127
1129
|
};
|
|
1128
1130
|
const rejectExecutionGate = (message) => {
|
|
@@ -1562,7 +1564,7 @@ Promise.race([globalThis.__fabricRun(__piFabricMain), globalThis.__fabricExecuti
|
|
|
1562
1564
|
closing = true;
|
|
1563
1565
|
if (timedOut || cancelled || pendingHostPromises.size > 0) {
|
|
1564
1566
|
const cleanupMessage = cancelled ? "Execution cancelled" : timedOut ? timeoutMessage() : "Fabric guest execution ended before its host calls settled";
|
|
1565
|
-
if (!hostAbortController.signal.aborted) hostAbortController.abort(
|
|
1567
|
+
if (!hostAbortController.signal.aborted) hostAbortController.abort(fabricControlAbort(cleanupMessage));
|
|
1566
1568
|
rejectExecutionGate(cleanupMessage);
|
|
1567
1569
|
const errorHandle = context.newError(cleanupMessage);
|
|
1568
1570
|
for (const promise of pendingHostPromises) promise.reject(errorHandle);
|
|
@@ -1604,4 +1606,4 @@ export {
|
|
|
1604
1606
|
GUEST_SETUP,
|
|
1605
1607
|
QuickJsRuntime
|
|
1606
1608
|
};
|
|
1607
|
-
//# sourceMappingURL=chunk-
|
|
1609
|
+
//# sourceMappingURL=chunk-6HM4TX7L.js.map
|