harnery 0.33.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commander.d.ts.map +1 -1
- package/dist/commander.js +4 -0
- package/dist/commands/adapter.js +2 -2
- package/dist/commands/agents.d.ts +144 -1
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +1220 -588
- package/dist/commands/artifacts.d.ts.map +1 -1
- package/dist/commands/artifacts.js +7 -6
- package/dist/commands/backup.d.ts +1 -1
- package/dist/commands/backup.d.ts.map +1 -1
- package/dist/commands/backup.js +29 -16
- package/dist/commands/browse.d.ts.map +1 -1
- package/dist/commands/browse.js +234 -12
- package/dist/commands/checkpoint.d.ts.map +1 -1
- package/dist/commands/checkpoint.js +3 -2
- package/dist/commands/claude-desktop.d.ts +1 -1
- package/dist/commands/claude-desktop.d.ts.map +1 -1
- package/dist/commands/claude-desktop.js +3 -74
- package/dist/commands/context.js +1 -6
- package/dist/commands/decision.d.ts.map +1 -1
- package/dist/commands/decision.js +22 -38
- package/dist/commands/docs.d.ts.map +1 -1
- package/dist/commands/docs.js +91 -28
- package/dist/commands/doctor.js +10 -1
- package/dist/commands/events.d.ts +5 -0
- package/dist/commands/events.d.ts.map +1 -0
- package/dist/commands/events.js +189 -0
- package/dist/commands/governor.d.ts.map +1 -1
- package/dist/commands/governor.js +13 -4
- package/dist/commands/init.d.ts +9 -2
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +223 -51
- package/dist/commands/journal.d.ts.map +1 -1
- package/dist/commands/journal.js +4 -13
- package/dist/commands/ledger-v3.d.ts +5 -0
- package/dist/commands/ledger-v3.d.ts.map +1 -0
- package/dist/commands/ledger-v3.js +91 -0
- package/dist/commands/presence.d.ts.map +1 -1
- package/dist/commands/presence.js +11 -5
- package/dist/commands/sync.d.ts +1 -1
- package/dist/commands/sync.js +1 -1
- package/dist/commands/web.d.ts +6 -0
- package/dist/commands/web.d.ts.map +1 -1
- package/dist/commands/web.js +67 -7
- package/dist/commands/work.d.ts.map +1 -1
- package/dist/commands/work.js +22 -5
- package/dist/core/adapter.d.ts +5 -0
- package/dist/core/adapter.d.ts.map +1 -0
- package/dist/core/adapter.js +1 -0
- package/dist/core/adapters/attest.d.ts +5 -2
- package/dist/core/adapters/attest.d.ts.map +1 -1
- package/dist/core/adapters/attest.js +8 -3
- package/dist/core/adapters/profiles.d.ts +6 -6
- package/dist/core/adapters/profiles.d.ts.map +1 -1
- package/dist/core/adapters/profiles.js +4 -4
- package/dist/core/agents/canonical-emit.d.ts +17 -15
- package/dist/core/agents/canonical-emit.d.ts.map +1 -1
- package/dist/core/agents/canonical-emit.js +22 -22
- package/dist/core/agents/cli.js +207 -234
- package/dist/core/agents/codex-archive-v3.d.ts +14 -0
- package/dist/core/agents/codex-archive-v3.d.ts.map +1 -0
- package/dist/core/agents/codex-archive-v3.js +110 -0
- package/dist/core/agents/coord-client.d.ts +19 -81
- package/dist/core/agents/coord-client.d.ts.map +1 -1
- package/dist/core/agents/coord-client.js +65 -155
- package/dist/core/agents/finalization.d.ts +4 -1
- package/dist/core/agents/finalization.d.ts.map +1 -1
- package/dist/core/agents/finalization.js +89 -32
- package/dist/core/agents/index.d.ts +4 -5
- package/dist/core/agents/index.d.ts.map +1 -1
- package/dist/core/agents/index.js +4 -5
- package/dist/core/agents/live-authority-v3.d.ts +59 -0
- package/dist/core/agents/live-authority-v3.d.ts.map +1 -0
- package/dist/core/agents/live-authority-v3.js +233 -0
- package/dist/core/agents/live-lifecycle-v3.d.ts +20 -0
- package/dist/core/agents/live-lifecycle-v3.d.ts.map +1 -0
- package/dist/core/agents/live-lifecycle-v3.js +91 -0
- package/dist/core/agents/live-observation-v3.d.ts +25 -0
- package/dist/core/agents/live-observation-v3.d.ts.map +1 -0
- package/dist/core/agents/live-observation-v3.js +157 -0
- package/dist/core/agents/render/prompt-context.d.ts +4 -4
- package/dist/core/agents/render/prompt-context.d.ts.map +1 -1
- package/dist/core/agents/render/prompt-context.js +23 -58
- package/dist/core/agents/render/session-context.d.ts +1 -1
- package/dist/core/agents/render/session-context.d.ts.map +1 -1
- package/dist/core/agents/render/session-context.js +8 -32
- package/dist/core/agents/rules/claim-conflict.d.ts +3 -3
- package/dist/core/agents/rules/claim-conflict.d.ts.map +1 -1
- package/dist/core/agents/rules/claim-conflict.js +79 -127
- package/dist/core/agents/rules/commit-conflict.d.ts.map +1 -1
- package/dist/core/agents/rules/commit-conflict.js +3 -18
- package/dist/core/agents/rules/stop-hook.d.ts +9 -50
- package/dist/core/agents/rules/stop-hook.d.ts.map +1 -1
- package/dist/core/agents/rules/stop-hook.js +193 -236
- package/dist/core/agents/session-events.d.ts +5 -7
- package/dist/core/agents/session-events.d.ts.map +1 -1
- package/dist/core/agents/session-events.js +127 -95
- package/dist/core/agents/session-finalization-state-v3.d.ts +30 -0
- package/dist/core/agents/session-finalization-state-v3.d.ts.map +1 -0
- package/dist/core/agents/session-finalization-state-v3.js +40 -0
- package/dist/core/agents/session-finalizer-v3.d.ts +107 -0
- package/dist/core/agents/session-finalizer-v3.d.ts.map +1 -0
- package/dist/core/agents/session-finalizer-v3.js +734 -0
- package/dist/core/agents/session-name-display.d.ts +40 -0
- package/dist/core/agents/session-name-display.d.ts.map +1 -0
- package/dist/core/agents/session-name-display.js +119 -0
- package/dist/core/agents/state/activity-log.d.ts +3 -3
- package/dist/core/agents/state/activity-log.d.ts.map +1 -1
- package/dist/core/agents/state/activity-log.js +7 -16
- package/dist/core/agents/state/heartbeat-writer.d.ts +23 -55
- package/dist/core/agents/state/heartbeat-writer.d.ts.map +1 -1
- package/dist/core/agents/state/heartbeat-writer.js +56 -228
- package/dist/core/agents/state/live-coordination-view.d.ts +31 -0
- package/dist/core/agents/state/live-coordination-view.d.ts.map +1 -0
- package/dist/core/agents/state/live-coordination-view.js +209 -0
- package/dist/core/agents/state/session-state.d.ts +4 -3
- package/dist/core/agents/state/session-state.d.ts.map +1 -1
- package/dist/core/agents/state/session-state.js +18 -9
- package/dist/core/agents/state/stale-sweep.d.ts +1 -1
- package/dist/core/agents/state/stale-sweep.d.ts.map +1 -1
- package/dist/core/agents/state/stale-sweep.js +26 -15
- package/dist/core/artifacts/index.d.ts.map +1 -1
- package/dist/core/artifacts/index.js +5 -7
- package/dist/core/config.d.ts +33 -2
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +98 -2
- package/dist/core/context/index.d.ts +1 -4
- package/dist/core/context/index.d.ts.map +1 -1
- package/dist/core/context/index.js +9 -9
- package/dist/core/events/span-parent.d.ts +15 -0
- package/dist/core/events/span-parent.d.ts.map +1 -0
- package/dist/core/events/span-parent.js +34 -0
- package/dist/core/events/v3/advance.d.ts +14 -0
- package/dist/core/events/v3/advance.d.ts.map +1 -0
- package/dist/core/events/v3/advance.js +134 -0
- package/dist/core/events/v3/authority-outbox.d.ts +78 -0
- package/dist/core/events/v3/authority-outbox.d.ts.map +1 -0
- package/dist/core/events/v3/authority-outbox.js +399 -0
- package/dist/core/events/v3/base-builder.d.ts +20 -0
- package/dist/core/events/v3/base-builder.d.ts.map +1 -0
- package/dist/core/events/v3/base-builder.js +29 -0
- package/dist/core/events/v3/base-contract.d.ts +7576 -0
- package/dist/core/events/v3/base-contract.d.ts.map +1 -0
- package/dist/core/events/v3/base-contract.js +647 -0
- package/dist/core/events/v3/bootstrap.d.ts +34 -0
- package/dist/core/events/v3/bootstrap.d.ts.map +1 -0
- package/dist/core/events/v3/bootstrap.js +175 -0
- package/dist/core/events/v3/builder.d.ts +20 -0
- package/dist/core/events/v3/builder.d.ts.map +1 -0
- package/dist/core/events/v3/builder.js +28 -0
- package/dist/core/events/v3/canonical.d.ts +31 -0
- package/dist/core/events/v3/canonical.d.ts.map +1 -0
- package/dist/core/events/v3/canonical.js +100 -0
- package/dist/core/events/v3/capabilities.d.ts +31 -0
- package/dist/core/events/v3/capabilities.d.ts.map +1 -0
- package/dist/core/events/v3/capabilities.js +107 -0
- package/dist/core/events/v3/capability-drift.d.ts +22 -0
- package/dist/core/events/v3/capability-drift.d.ts.map +1 -0
- package/dist/core/events/v3/capability-drift.js +134 -0
- package/dist/core/events/v3/catalog.d.ts +38 -0
- package/dist/core/events/v3/catalog.d.ts.map +1 -0
- package/dist/core/events/v3/catalog.js +135 -0
- package/dist/core/events/v3/clock-order.d.ts +34 -0
- package/dist/core/events/v3/clock-order.d.ts.map +1 -0
- package/dist/core/events/v3/clock-order.js +35 -0
- package/dist/core/events/v3/contract.d.ts +171 -0
- package/dist/core/events/v3/contract.d.ts.map +1 -0
- package/dist/core/events/v3/contract.js +180 -0
- package/dist/core/events/v3/control.d.ts +111 -0
- package/dist/core/events/v3/control.d.ts.map +1 -0
- package/dist/core/events/v3/control.js +419 -0
- package/dist/core/events/v3/coordination-view.d.ts +69 -0
- package/dist/core/events/v3/coordination-view.d.ts.map +1 -0
- package/dist/core/events/v3/coordination-view.js +119 -0
- package/dist/core/events/v3/economics.d.ts +77 -0
- package/dist/core/events/v3/economics.d.ts.map +1 -0
- package/dist/core/events/v3/economics.js +274 -0
- package/dist/core/events/v3/finalization-view.d.ts +26 -0
- package/dist/core/events/v3/finalization-view.d.ts.map +1 -0
- package/dist/core/events/v3/finalization-view.js +37 -0
- package/dist/core/events/v3/fingerprint-keys.d.ts +25 -0
- package/dist/core/events/v3/fingerprint-keys.d.ts.map +1 -0
- package/dist/core/events/v3/fingerprint-keys.js +217 -0
- package/dist/core/events/v3/generated.d.ts +4 -0
- package/dist/core/events/v3/generated.d.ts.map +1 -0
- package/dist/core/events/v3/generated.js +47 -0
- package/dist/core/events/v3/ids.d.ts +9 -0
- package/dist/core/events/v3/ids.d.ts.map +1 -0
- package/dist/core/events/v3/ids.js +25 -0
- package/dist/core/events/v3/index.d.ts +35 -0
- package/dist/core/events/v3/index.d.ts.map +1 -0
- package/dist/core/events/v3/index.js +33 -0
- package/dist/core/events/v3/latency.d.ts +63 -0
- package/dist/core/events/v3/latency.d.ts.map +1 -0
- package/dist/core/events/v3/latency.js +412 -0
- package/dist/core/events/v3/live-feed.d.ts +45 -0
- package/dist/core/events/v3/live-feed.d.ts.map +1 -0
- package/dist/core/events/v3/live-feed.js +246 -0
- package/dist/core/events/v3/live-observation.d.ts +35 -0
- package/dist/core/events/v3/live-observation.d.ts.map +1 -0
- package/dist/core/events/v3/live-observation.js +1 -0
- package/dist/core/events/v3/live-routing.d.ts +57 -0
- package/dist/core/events/v3/live-routing.d.ts.map +1 -0
- package/dist/core/events/v3/live-routing.js +107 -0
- package/dist/core/events/v3/producers/command-recorder.d.ts +67 -0
- package/dist/core/events/v3/producers/command-recorder.d.ts.map +1 -0
- package/dist/core/events/v3/producers/command-recorder.js +477 -0
- package/dist/core/events/v3/producers/command.d.ts +50 -0
- package/dist/core/events/v3/producers/command.d.ts.map +1 -0
- package/dist/core/events/v3/producers/command.js +135 -0
- package/dist/core/events/v3/producers/coordination-recorder.d.ts +53 -0
- package/dist/core/events/v3/producers/coordination-recorder.d.ts.map +1 -0
- package/dist/core/events/v3/producers/coordination-recorder.js +376 -0
- package/dist/core/events/v3/producers/coordination.d.ts +90 -0
- package/dist/core/events/v3/producers/coordination.d.ts.map +1 -0
- package/dist/core/events/v3/producers/coordination.js +229 -0
- package/dist/core/events/v3/producers/hook-base.d.ts +54 -0
- package/dist/core/events/v3/producers/hook-base.d.ts.map +1 -0
- package/dist/core/events/v3/producers/hook-base.js +424 -0
- package/dist/core/events/v3/producers/hook.d.ts +29 -0
- package/dist/core/events/v3/producers/hook.d.ts.map +1 -0
- package/dist/core/events/v3/producers/hook.js +71 -0
- package/dist/core/events/v3/producers/intake.d.ts +65 -0
- package/dist/core/events/v3/producers/intake.d.ts.map +1 -0
- package/dist/core/events/v3/producers/intake.js +244 -0
- package/dist/core/events/v3/producers/recorder.d.ts +240 -0
- package/dist/core/events/v3/producers/recorder.d.ts.map +1 -0
- package/dist/core/events/v3/producers/recorder.js +2176 -0
- package/dist/core/events/v3/projection.d.ts +101 -0
- package/dist/core/events/v3/projection.d.ts.map +1 -0
- package/dist/core/events/v3/projection.js +479 -0
- package/dist/core/events/v3/reader.d.ts +75 -0
- package/dist/core/events/v3/reader.d.ts.map +1 -0
- package/dist/core/events/v3/reader.js +778 -0
- package/dist/core/events/v3/recovery-record.d.ts +47 -0
- package/dist/core/events/v3/recovery-record.d.ts.map +1 -0
- package/dist/core/events/v3/recovery-record.js +167 -0
- package/dist/core/events/v3/recovery.d.ts +22 -0
- package/dist/core/events/v3/recovery.d.ts.map +1 -0
- package/dist/core/events/v3/recovery.js +227 -0
- package/dist/core/events/v3/span-state.d.ts +52 -0
- package/dist/core/events/v3/span-state.d.ts.map +1 -0
- package/dist/core/events/v3/span-state.js +142 -0
- package/dist/core/events/v3/targets.d.ts +23 -0
- package/dist/core/events/v3/targets.d.ts.map +1 -0
- package/dist/core/events/v3/targets.js +134 -0
- package/dist/core/events/v3/turn-telemetry.d.ts +41 -0
- package/dist/core/events/v3/turn-telemetry.d.ts.map +1 -0
- package/dist/core/events/v3/turn-telemetry.js +168 -0
- package/dist/core/events/v3/validate.d.ts +9 -0
- package/dist/core/events/v3/validate.d.ts.map +1 -0
- package/dist/core/events/v3/validate.js +281 -0
- package/dist/core/events/v3/writer.d.ts +56 -0
- package/dist/core/events/v3/writer.d.ts.map +1 -0
- package/dist/core/events/v3/writer.js +335 -0
- package/dist/core/governor/index.d.ts +1 -1
- package/dist/core/governor/index.d.ts.map +1 -1
- package/dist/core/governor/index.js +1 -1
- package/dist/core/governor/plan-api.d.ts +2 -1
- package/dist/core/governor/plan-api.d.ts.map +1 -1
- package/dist/core/governor/plan-api.js +6 -3
- package/dist/core/governor/read.d.ts +1 -1
- package/dist/core/governor/read.d.ts.map +1 -1
- package/dist/core/governor/read.js +1 -1
- package/dist/core/governor/state.d.ts +9 -0
- package/dist/core/governor/state.d.ts.map +1 -1
- package/dist/core/governor/state.js +40 -3
- package/dist/core/guard/config.d.ts +5 -0
- package/dist/core/guard/config.d.ts.map +1 -0
- package/dist/core/guard/config.js +157 -0
- package/dist/core/guard/coordinator.d.ts +14 -0
- package/dist/core/guard/coordinator.d.ts.map +1 -0
- package/dist/core/guard/coordinator.js +173 -0
- package/dist/core/guard/evaluator.d.ts +4 -0
- package/dist/core/guard/evaluator.d.ts.map +1 -0
- package/dist/core/guard/evaluator.js +242 -0
- package/dist/core/guard/evidence-v3.d.ts +15 -0
- package/dist/core/guard/evidence-v3.d.ts.map +1 -0
- package/dist/core/guard/evidence-v3.js +171 -0
- package/dist/core/guard/index.d.ts +10 -0
- package/dist/core/guard/index.d.ts.map +1 -0
- package/dist/core/guard/index.js +6 -0
- package/dist/core/guard/live-source-v3.d.ts +40 -0
- package/dist/core/guard/live-source-v3.d.ts.map +1 -0
- package/dist/core/guard/live-source-v3.js +128 -0
- package/dist/core/guard/storage.d.ts +27 -0
- package/dist/core/guard/storage.d.ts.map +1 -0
- package/dist/core/guard/storage.js +140 -0
- package/dist/core/guard/types.d.ts +119 -0
- package/dist/core/guard/types.d.ts.map +1 -0
- package/dist/core/guard/types.js +1 -0
- package/dist/core/hooks/adapter/detect.d.ts +18 -1
- package/dist/core/hooks/adapter/detect.d.ts.map +1 -1
- package/dist/core/hooks/adapter/detect.js +29 -0
- package/dist/core/hooks/adapter/events.d.ts +7 -4
- package/dist/core/hooks/adapter/events.d.ts.map +1 -1
- package/dist/core/hooks/adapter/events.js +12 -4
- package/dist/core/hooks/adapter/output.d.ts +2 -2
- package/dist/core/hooks/adapter/output.d.ts.map +1 -1
- package/dist/core/hooks/adapter/parse.d.ts +7 -4
- package/dist/core/hooks/adapter/parse.d.ts.map +1 -1
- package/dist/core/hooks/adapter/parse.js +63 -25
- package/dist/core/hooks/adapter/wiring.d.ts +30 -4
- package/dist/core/hooks/adapter/wiring.d.ts.map +1 -1
- package/dist/core/hooks/adapter/wiring.js +89 -11
- package/dist/core/hooks/cli.d.ts +1 -1
- package/dist/core/hooks/cli.js +305 -444
- package/dist/core/hooks/effects/image-capture.d.ts +20 -34
- package/dist/core/hooks/effects/image-capture.d.ts.map +1 -1
- package/dist/core/hooks/effects/image-capture.js +212 -221
- package/dist/core/hooks/effects/index.d.ts +1 -9
- package/dist/core/hooks/effects/index.d.ts.map +1 -1
- package/dist/core/hooks/effects/index.js +1 -24
- package/dist/core/hooks/events/input-hash.d.ts +7 -0
- package/dist/core/hooks/events/input-hash.d.ts.map +1 -0
- package/dist/core/hooks/events/input-hash.js +43 -0
- package/dist/core/hooks/index.d.ts +4 -3
- package/dist/core/hooks/index.d.ts.map +1 -1
- package/dist/core/hooks/index.js +2 -3
- package/dist/core/hooks/resolve/coord-root.d.ts +1 -1
- package/dist/core/hooks/resolve/coord-root.js +1 -1
- package/dist/core/hooks/resolve/owner.d.ts +16 -15
- package/dist/core/hooks/resolve/owner.d.ts.map +1 -1
- package/dist/core/hooks/resolve/owner.js +51 -42
- package/dist/core/hooks/resolve/transcript.d.ts +33 -3
- package/dist/core/hooks/resolve/transcript.d.ts.map +1 -1
- package/dist/core/hooks/resolve/transcript.js +155 -14
- package/dist/core/hooks/session-name-presence.d.ts +9 -10
- package/dist/core/hooks/session-name-presence.d.ts.map +1 -1
- package/dist/core/hooks/session-name-presence.js +15 -15
- package/dist/core/hooks/unsafe-cross-shell.d.ts +1 -1
- package/dist/core/hooks/unsafe-cross-shell.d.ts.map +1 -1
- package/dist/core/journal/index.d.ts +2 -2
- package/dist/core/journal/index.d.ts.map +1 -1
- package/dist/core/journal/index.js +9 -22
- package/dist/core/presence/blob.d.ts +4 -3
- package/dist/core/presence/blob.d.ts.map +1 -1
- package/dist/core/presence/blob.js +45 -44
- package/dist/core/presence/codec-digest.d.ts +29 -0
- package/dist/core/presence/codec-digest.d.ts.map +1 -0
- package/dist/core/presence/codec-digest.js +170 -0
- package/dist/core/presence/relay-client.d.ts +1 -1
- package/dist/core/presence/relay-client.d.ts.map +1 -1
- package/dist/core/presence/relay-client.js +5 -5
- package/dist/core/work/index.d.ts +1 -1
- package/dist/core/work/index.d.ts.map +1 -1
- package/dist/core/work/index.js +1 -1
- package/dist/core/work/read.d.ts +1 -1
- package/dist/core/work/read.d.ts.map +1 -1
- package/dist/core/work/read.js +1 -1
- package/dist/core/work/runner.d.ts.map +1 -1
- package/dist/core/work/runner.js +6 -0
- package/dist/core/work/state.d.ts +9 -0
- package/dist/core/work/state.d.ts.map +1 -1
- package/dist/core/work/state.js +17 -3
- package/dist/core/workflow/engine.js +24 -25
- package/dist/core/workflow/live-session-v3.d.ts +19 -0
- package/dist/core/workflow/live-session-v3.d.ts.map +1 -0
- package/dist/core/workflow/live-session-v3.js +86 -0
- package/dist/core/workflow/scope-id.d.ts +3 -0
- package/dist/core/workflow/scope-id.d.ts.map +1 -0
- package/dist/core/workflow/scope-id.js +5 -0
- package/dist/core/workflow/workspaces/leases.d.ts +4 -0
- package/dist/core/workflow/workspaces/leases.d.ts.map +1 -1
- package/dist/core/workflow/workspaces/leases.js +53 -19
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/browser/client.d.ts +41 -0
- package/dist/lib/browser/client.d.ts.map +1 -1
- package/dist/lib/browser/client.js +203 -0
- package/dist/lib/browser/critique.d.ts +28 -2
- package/dist/lib/browser/critique.d.ts.map +1 -1
- package/dist/lib/browser/critique.js +74 -18
- package/dist/lib/browser/geometry.d.ts +1 -1
- package/dist/lib/browser/geometry.d.ts.map +1 -1
- package/dist/lib/browser/geometry.js +130 -6
- package/dist/lib/browser/index.d.ts +3 -0
- package/dist/lib/browser/index.d.ts.map +1 -1
- package/dist/lib/browser/index.js +3 -0
- package/dist/lib/browser/qa-plan.d.ts +174 -0
- package/dist/lib/browser/qa-plan.d.ts.map +1 -0
- package/dist/lib/browser/qa-plan.js +321 -0
- package/dist/lib/browser/qa-reuse.d.ts +99 -0
- package/dist/lib/browser/qa-reuse.d.ts.map +1 -0
- package/dist/lib/browser/qa-reuse.js +222 -0
- package/dist/lib/browser/qa-snapshot.d.ts +64 -0
- package/dist/lib/browser/qa-snapshot.d.ts.map +1 -0
- package/dist/lib/browser/qa-snapshot.js +171 -0
- package/dist/lib/browser/runts.d.ts.map +1 -1
- package/dist/lib/browser/runts.js +22 -1
- package/dist/lib/browser/tiling.d.ts +71 -0
- package/dist/lib/browser/tiling.d.ts.map +1 -0
- package/dist/lib/browser/tiling.js +118 -0
- package/dist/lib/claude-desktop.d.ts +0 -47
- package/dist/lib/claude-desktop.d.ts.map +1 -1
- package/dist/lib/claude-desktop.js +1 -169
- package/dist/lib/context/index.d.ts +0 -3
- package/dist/lib/context/index.d.ts.map +1 -1
- package/dist/lib/context/index.js +20 -42
- package/dist/lib/council/index.d.ts +2 -2
- package/dist/lib/council/index.d.ts.map +1 -1
- package/dist/lib/council/index.js +9 -20
- package/dist/lib/docs-frontmatter.d.ts +1 -6
- package/dist/lib/docs-frontmatter.d.ts.map +1 -1
- package/dist/lib/docs-frontmatter.js +12 -78
- package/dist/lib/docs-index.d.ts +9 -0
- package/dist/lib/docs-index.d.ts.map +1 -1
- package/dist/lib/docs-index.js +32 -3
- package/dist/lib/docs-lint.d.ts.map +1 -1
- package/dist/lib/docs-lint.js +14 -30
- package/dist/lib/docs-metadata-audit.d.ts +19 -0
- package/dist/lib/docs-metadata-audit.d.ts.map +1 -0
- package/dist/lib/docs-metadata-audit.js +132 -0
- package/dist/lib/docs-metadata-managed.d.ts +23 -0
- package/dist/lib/docs-metadata-managed.d.ts.map +1 -0
- package/dist/lib/docs-metadata-managed.js +78 -0
- package/dist/lib/docs-metadata-sync.d.ts +20 -0
- package/dist/lib/docs-metadata-sync.d.ts.map +1 -0
- package/dist/lib/docs-metadata-sync.js +222 -0
- package/dist/lib/docs-metadata-v2-schema.d.ts +273 -0
- package/dist/lib/docs-metadata-v2-schema.d.ts.map +1 -0
- package/dist/lib/docs-metadata-v2-schema.js +134 -0
- package/dist/lib/docs-metadata-v2.d.ts +21 -0
- package/dist/lib/docs-metadata-v2.d.ts.map +1 -0
- package/dist/lib/docs-metadata-v2.js +424 -0
- package/dist/lib/docs-new.d.ts +11 -0
- package/dist/lib/docs-new.d.ts.map +1 -0
- package/dist/lib/docs-new.js +52 -0
- package/dist/lib/docs-sweep.d.ts.map +1 -1
- package/dist/lib/docs-sweep.js +45 -29
- package/dist/lib/headless/index.d.ts +98 -0
- package/dist/lib/headless/index.d.ts.map +1 -0
- package/dist/lib/headless/index.js +211 -0
- package/dist/lib/identities/assume.d.ts +4 -4
- package/dist/lib/identities/assume.d.ts.map +1 -1
- package/dist/lib/identities/assume.js +52 -68
- package/dist/lib/instructions/apply.d.ts +5 -4
- package/dist/lib/instructions/apply.d.ts.map +1 -1
- package/dist/lib/instructions/apply.js +32 -20
- package/dist/lib/instructions/bundle.d.ts +1 -1
- package/dist/lib/instructions/bundle.d.ts.map +1 -1
- package/dist/lib/instructions/bundle.js +1 -1
- package/dist/lib/instructions/splice.d.ts +0 -1
- package/dist/lib/instructions/splice.d.ts.map +1 -1
- package/dist/lib/instructions/splice.js +22 -6
- package/dist/lib/instructions/templates.d.ts +7 -5
- package/dist/lib/instructions/templates.d.ts.map +1 -1
- package/dist/lib/instructions/templates.js +79 -9
- package/package.json +26 -5
- package/schemas/config.schema.json +120 -2
- package/schemas/docs-metadata-v2.schema.json +441 -0
- package/schemas/event-v3.schema.json +24472 -0
- package/src/commander.ts +4 -0
- package/src/commands/adapter.ts +2 -2
- package/src/commands/agents.ts +1512 -592
- package/src/commands/artifacts.ts +7 -6
- package/src/commands/backup.ts +29 -21
- package/src/commands/browse.ts +349 -8
- package/src/commands/checkpoint.ts +4 -3
- package/src/commands/claude-desktop.ts +2 -101
- package/src/commands/context.ts +1 -6
- package/src/commands/decision.ts +27 -44
- package/src/commands/docs.ts +100 -33
- package/src/commands/doctor.ts +14 -1
- package/src/commands/events.ts +256 -0
- package/src/commands/governor.ts +18 -4
- package/src/commands/init.ts +253 -57
- package/src/commands/instructions.ts +1 -1
- package/src/commands/journal.ts +4 -13
- package/src/commands/ledger-v3.ts +111 -0
- package/src/commands/presence.ts +11 -10
- package/src/commands/sync.ts +1 -1
- package/src/commands/web.ts +67 -8
- package/src/commands/work.ts +28 -5
- package/src/core/adapter.ts +5 -0
- package/src/core/adapters/attest.ts +8 -3
- package/src/core/adapters/profiles.ts +4 -6
- package/src/core/agents/canonical-emit.ts +34 -25
- package/src/core/agents/cli.ts +236 -262
- package/src/core/agents/codex-archive-v3.ts +138 -0
- package/src/core/agents/coord-client.ts +75 -188
- package/src/core/agents/finalization.ts +120 -38
- package/src/core/agents/index.ts +4 -5
- package/src/core/agents/live-authority-v3.ts +375 -0
- package/src/core/agents/live-lifecycle-v3.ts +140 -0
- package/src/core/agents/live-observation-v3.ts +216 -0
- package/src/core/agents/render/prompt-context.ts +29 -60
- package/src/core/agents/render/session-context.ts +10 -31
- package/src/core/agents/rules/claim-conflict.ts +85 -126
- package/src/core/agents/rules/commit-conflict.ts +3 -14
- package/src/core/agents/rules/stop-hook.ts +239 -293
- package/src/core/agents/session-events.ts +137 -104
- package/src/core/agents/session-finalization-state-v3.ts +90 -0
- package/src/core/agents/session-finalizer-v3.ts +953 -0
- package/src/core/agents/session-name-display.ts +149 -0
- package/src/core/agents/state/activity-log.ts +6 -14
- package/src/core/agents/state/heartbeat-writer.ts +82 -277
- package/src/core/agents/state/live-coordination-view.ts +290 -0
- package/src/core/agents/state/session-state.ts +24 -12
- package/src/core/agents/state/stale-sweep.ts +40 -17
- package/src/core/artifacts/index.ts +4 -5
- package/src/core/config.ts +148 -3
- package/src/core/context/index.ts +9 -17
- package/src/core/events/span-parent.ts +46 -0
- package/src/core/events/v3/advance.ts +168 -0
- package/src/core/events/v3/authority-outbox.ts +548 -0
- package/src/core/events/v3/base-builder.ts +60 -0
- package/src/core/events/v3/base-contract.ts +882 -0
- package/src/core/events/v3/bootstrap.ts +226 -0
- package/src/core/events/v3/builder.ts +59 -0
- package/src/core/events/v3/canonical.ts +153 -0
- package/src/core/events/v3/capabilities.ts +171 -0
- package/src/core/events/v3/capability-drift.ts +177 -0
- package/src/core/events/v3/catalog.ts +202 -0
- package/src/core/events/v3/clock-order.ts +41 -0
- package/src/core/events/v3/contract.ts +365 -0
- package/src/core/events/v3/control.ts +576 -0
- package/src/core/events/v3/coordination-view.ts +193 -0
- package/src/core/events/v3/economics.ts +384 -0
- package/src/core/events/v3/finalization-view.ts +67 -0
- package/src/core/events/v3/fingerprint-keys.ts +260 -0
- package/src/core/events/v3/generated.ts +48 -0
- package/src/core/events/v3/ids.ts +33 -0
- package/src/core/events/v3/index.ts +322 -0
- package/src/core/events/v3/latency.ts +551 -0
- package/src/core/events/v3/live-feed.ts +319 -0
- package/src/core/events/v3/live-observation.ts +39 -0
- package/src/core/events/v3/live-routing.ts +135 -0
- package/src/core/events/v3/producers/command-recorder.ts +631 -0
- package/src/core/events/v3/producers/command.ts +201 -0
- package/src/core/events/v3/producers/coordination-recorder.ts +538 -0
- package/src/core/events/v3/producers/coordination.ts +355 -0
- package/src/core/events/v3/producers/hook-base.ts +578 -0
- package/src/core/events/v3/producers/hook.ts +119 -0
- package/src/core/events/v3/producers/intake.ts +319 -0
- package/src/core/events/v3/producers/recorder.ts +2805 -0
- package/src/core/events/v3/projection.ts +653 -0
- package/src/core/events/v3/reader.ts +1127 -0
- package/src/core/events/v3/recovery-record.ts +244 -0
- package/src/core/events/v3/recovery.ts +271 -0
- package/src/core/events/v3/span-state.ts +187 -0
- package/src/core/events/v3/targets.ts +182 -0
- package/src/core/events/v3/turn-telemetry.ts +259 -0
- package/src/core/events/v3/validate.ts +361 -0
- package/src/core/events/v3/writer.ts +419 -0
- package/src/core/governor/index.ts +3 -0
- package/src/core/governor/plan-api.ts +10 -2
- package/src/core/governor/read.ts +3 -0
- package/src/core/governor/state.ts +52 -5
- package/src/core/guard/config.ts +206 -0
- package/src/core/guard/coordinator.ts +227 -0
- package/src/core/guard/evaluator.ts +343 -0
- package/src/core/guard/evidence-v3.ts +227 -0
- package/src/core/guard/index.ts +35 -0
- package/src/core/guard/live-source-v3.ts +204 -0
- package/src/core/guard/storage.ts +188 -0
- package/src/core/guard/types.ts +152 -0
- package/src/core/hooks/adapter/detect.ts +28 -1
- package/src/core/hooks/adapter/events.ts +14 -6
- package/src/core/hooks/adapter/output.ts +7 -2
- package/src/core/hooks/adapter/parse.ts +80 -38
- package/src/core/hooks/adapter/wiring.ts +119 -13
- package/src/core/hooks/cli.ts +351 -466
- package/src/core/hooks/effects/image-capture.ts +228 -238
- package/src/core/hooks/effects/index.ts +1 -36
- package/src/core/hooks/events/input-hash.ts +47 -0
- package/src/core/hooks/index.ts +4 -11
- package/src/core/hooks/resolve/coord-root.ts +1 -1
- package/src/core/hooks/resolve/owner.ts +52 -45
- package/src/core/hooks/resolve/transcript.ts +165 -14
- package/src/core/hooks/session-name-presence.ts +14 -15
- package/src/core/hooks/unsafe-cross-shell.ts +1 -1
- package/src/core/journal/index.ts +15 -22
- package/src/core/presence/blob.ts +48 -41
- package/src/core/presence/codec-digest.ts +215 -0
- package/src/core/presence/relay-client.ts +5 -5
- package/src/core/work/index.ts +3 -0
- package/src/core/work/read.ts +3 -0
- package/src/core/work/runner.ts +6 -0
- package/src/core/work/state.ts +27 -3
- package/src/core/workflow/engine.ts +24 -24
- package/src/core/workflow/live-session-v3.ts +126 -0
- package/src/core/workflow/scope-id.ts +6 -0
- package/src/core/workflow/workspaces/leases.ts +56 -19
- package/src/index.ts +1 -1
- package/src/lib/browser/client.ts +230 -0
- package/src/lib/browser/critique.ts +104 -27
- package/src/lib/browser/geometry.ts +143 -14
- package/src/lib/browser/index.ts +34 -0
- package/src/lib/browser/qa-plan.ts +501 -0
- package/src/lib/browser/qa-reuse.ts +306 -0
- package/src/lib/browser/qa-snapshot.ts +223 -0
- package/src/lib/browser/runts.ts +27 -2
- package/src/lib/browser/tiling.ts +164 -0
- package/src/lib/claude-desktop.ts +1 -232
- package/src/lib/context/index.ts +22 -46
- package/src/lib/council/index.ts +9 -21
- package/src/lib/docs-frontmatter.ts +8 -79
- package/src/lib/docs-index.ts +33 -3
- package/src/lib/docs-lint.ts +15 -29
- package/src/lib/docs-metadata-audit.ts +166 -0
- package/src/lib/docs-metadata-managed.ts +83 -0
- package/src/lib/docs-metadata-sync.ts +262 -0
- package/src/lib/docs-metadata-v2-schema.ts +138 -0
- package/src/lib/docs-metadata-v2.ts +646 -0
- package/src/lib/docs-new.ts +63 -0
- package/src/lib/docs-sweep.ts +42 -28
- package/src/lib/headless/index.ts +287 -0
- package/src/lib/identities/assume.ts +67 -86
- package/src/lib/instructions/apply.ts +33 -20
- package/src/lib/instructions/bundle.ts +2 -2
- package/src/lib/instructions/splice.ts +21 -7
- package/src/lib/instructions/templates.ts +85 -13
- package/dist/core/agents/cli-emit.d.ts +0 -27
- package/dist/core/agents/cli-emit.d.ts.map +0 -1
- package/dist/core/agents/cli-emit.js +0 -57
- package/dist/core/agents/codex-replay.d.ts +0 -29
- package/dist/core/agents/codex-replay.d.ts.map +0 -1
- package/dist/core/agents/codex-replay.js +0 -138
- package/dist/core/agents/events/consume.d.ts +0 -82
- package/dist/core/agents/events/consume.d.ts.map +0 -1
- package/dist/core/agents/events/consume.js +0 -195
- package/dist/core/agents/events/emit.d.ts +0 -42
- package/dist/core/agents/events/emit.d.ts.map +0 -1
- package/dist/core/agents/events/emit.js +0 -75
- package/dist/core/agents/events/ulid.d.ts +0 -11
- package/dist/core/agents/events/ulid.d.ts.map +0 -1
- package/dist/core/agents/events/ulid.js +0 -47
- package/dist/core/agents/state/heartbeat-projector.d.ts +0 -76
- package/dist/core/agents/state/heartbeat-projector.d.ts.map +0 -1
- package/dist/core/agents/state/heartbeat-projector.js +0 -581
- package/dist/core/hooks/events/emit.d.ts +0 -31
- package/dist/core/hooks/events/emit.d.ts.map +0 -1
- package/dist/core/hooks/events/emit.js +0 -93
- package/dist/core/hooks/events/rotate.d.ts +0 -43
- package/dist/core/hooks/events/rotate.d.ts.map +0 -1
- package/dist/core/hooks/events/rotate.js +0 -142
- package/dist/core/hooks/events/schema.d.ts +0 -341
- package/dist/core/hooks/events/schema.d.ts.map +0 -1
- package/dist/core/hooks/events/schema.js +0 -12
- package/dist/core/hooks/events/ulid.d.ts +0 -10
- package/dist/core/hooks/events/ulid.d.ts.map +0 -1
- package/dist/core/hooks/events/ulid.js +0 -47
- package/dist/lib/docs-frontmatter-migrate.d.ts +0 -33
- package/dist/lib/docs-frontmatter-migrate.d.ts.map +0 -1
- package/dist/lib/docs-frontmatter-migrate.js +0 -364
- package/src/core/agents/cli-emit.ts +0 -64
- package/src/core/agents/codex-replay.ts +0 -163
- package/src/core/agents/events/consume.ts +0 -254
- package/src/core/agents/events/emit.ts +0 -115
- package/src/core/agents/events/ulid.ts +0 -51
- package/src/core/agents/state/heartbeat-projector.ts +0 -645
- package/src/core/hooks/events/emit.ts +0 -125
- package/src/core/hooks/events/rotate.ts +0 -151
- package/src/core/hooks/events/schema.ts +0 -582
- package/src/core/hooks/events/ulid.ts +0 -51
- package/src/lib/docs-frontmatter-migrate.ts +0 -427
|
@@ -0,0 +1,778 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { closeSync, existsSync, lstatSync, openSync, readdirSync, readFileSync, readSync, statSync, } from "node:fs";
|
|
4
|
+
import { join, relative, resolve } from "node:path";
|
|
5
|
+
import { canonicalJsonV3, sha256V3 } from "./canonical.js";
|
|
6
|
+
import { readEventV3Catalog, readEventV3SegmentManifest, } from "./catalog.js";
|
|
7
|
+
import { EVENT_V3_SCHEMA_DIGEST } from "./generated.js";
|
|
8
|
+
import { eventV3RecoveryRecordsRoot, listEventV3RecoveryReceipts, } from "./recovery-record.js";
|
|
9
|
+
import { validateEventV3 } from "./validate.js";
|
|
10
|
+
/** Inspect one failed active authority without weakening the canonical read boundary. */
|
|
11
|
+
export function inspectInvalidActiveAuthorityV3(coordRoot, controlReason) {
|
|
12
|
+
const paths = eventV3Paths(coordRoot);
|
|
13
|
+
const ledger = readLedgerV3(coordRoot, { authority: "active" });
|
|
14
|
+
if (ledger.complete || ledger.diagnostics.length === 0) {
|
|
15
|
+
throw new Error("event_v3_recovery_requires_incomplete_ledger");
|
|
16
|
+
}
|
|
17
|
+
const diagnostic = [...ledger.diagnostics].sort((left, right) => left.segment_ordinal - right.segment_ordinal || left.byte_offset - right.byte_offset)[0];
|
|
18
|
+
const activeOrdinal = existsSync(paths.catalog)
|
|
19
|
+
? readEventV3Catalog(paths.catalog).active.ordinal
|
|
20
|
+
: 1;
|
|
21
|
+
if (diagnostic.segment_ordinal !== activeOrdinal) {
|
|
22
|
+
throw new Error("event_v3_recovery_first_failure_is_not_in_active_authority");
|
|
23
|
+
}
|
|
24
|
+
const active = readFileSync(paths.active);
|
|
25
|
+
if (diagnostic.byte_offset > active.length) {
|
|
26
|
+
throw new Error("event_v3_recovery_diagnostic_offset_exceeds_active_authority");
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
control_reason: controlReason,
|
|
30
|
+
authority_digest: digestEventV3AuthorityDirectoryV3(paths.root),
|
|
31
|
+
active_digest: sha256V3(active),
|
|
32
|
+
active_bytes: active.length,
|
|
33
|
+
validated_prefix_digest: sha256V3(active.subarray(0, diagnostic.byte_offset)),
|
|
34
|
+
validated_prefix_bytes: diagnostic.byte_offset,
|
|
35
|
+
diagnostic: {
|
|
36
|
+
code: diagnostic.code,
|
|
37
|
+
segment_ordinal: diagnostic.segment_ordinal,
|
|
38
|
+
byte_offset: diagnostic.byte_offset,
|
|
39
|
+
...(diagnostic.event_id ? { event_id: diagnostic.event_id } : {}),
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** Hash one preserved V3 authority by relative path, byte count, and file digest. */
|
|
44
|
+
export function digestEventV3AuthorityDirectoryV3(root) {
|
|
45
|
+
const base = resolve(root);
|
|
46
|
+
if (!lstatSync(base).isDirectory())
|
|
47
|
+
throw new Error("V3 authority root is not a directory");
|
|
48
|
+
const files = [];
|
|
49
|
+
const visit = (directory) => {
|
|
50
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
51
|
+
const path = join(directory, entry.name);
|
|
52
|
+
if (entry.isSymbolicLink())
|
|
53
|
+
throw new Error("V3 authority contains a symbolic link");
|
|
54
|
+
if (entry.isDirectory()) {
|
|
55
|
+
visit(path);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (!entry.isFile())
|
|
59
|
+
throw new Error("V3 authority contains a non-regular file");
|
|
60
|
+
const bytes = readFileSync(path);
|
|
61
|
+
files.push({
|
|
62
|
+
path: relative(base, path).replaceAll("\\", "/"),
|
|
63
|
+
bytes: bytes.length,
|
|
64
|
+
digest: sha256V3(bytes),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
visit(base);
|
|
69
|
+
files.sort((left, right) => left.path.localeCompare(right.path));
|
|
70
|
+
return `sha256:${createHash("sha256").update(canonicalJsonV3(files)).digest("hex")}`;
|
|
71
|
+
}
|
|
72
|
+
const MAX_CACHED_LEDGER_READS = 4;
|
|
73
|
+
const ledgerReadCacheV3 = new Map();
|
|
74
|
+
export const EVENT_V3_LEDGER_RELATIVE_ROOT = ".harnery/ledgers/v3";
|
|
75
|
+
export function eventV3Paths(coordRoot) {
|
|
76
|
+
const root = join(resolve(coordRoot), EVENT_V3_LEDGER_RELATIVE_ROOT);
|
|
77
|
+
return {
|
|
78
|
+
root,
|
|
79
|
+
active: join(root, "active.ndjson"),
|
|
80
|
+
catalog: join(root, "catalog.json"),
|
|
81
|
+
segments: join(root, "segments"),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** Stable file target for change notification only; reads still go through readLedgerV3. */
|
|
85
|
+
export function eventV3ActiveWatchPath(coordRoot) {
|
|
86
|
+
return eventV3Paths(coordRoot).active;
|
|
87
|
+
}
|
|
88
|
+
/** Read the complete V3 ledger through catalog-bound filesystem discovery. */
|
|
89
|
+
export function readLedgerV3(coordRoot, options = {}) {
|
|
90
|
+
const cacheKey = ledgerReadCacheKeyV3(coordRoot, options);
|
|
91
|
+
const storage = ledgerStorageVersionV3(coordRoot);
|
|
92
|
+
const cached = ledgerReadCacheV3.get(cacheKey);
|
|
93
|
+
if (cached?.storage.fingerprint === storage.fingerprint) {
|
|
94
|
+
ledgerReadCacheV3.delete(cacheKey);
|
|
95
|
+
ledgerReadCacheV3.set(cacheKey, cached);
|
|
96
|
+
return cached.result;
|
|
97
|
+
}
|
|
98
|
+
const resumed = cached ? resumeCachedLedgerReadV3(cached, storage, options) : undefined;
|
|
99
|
+
if (resumed) {
|
|
100
|
+
rememberLedgerReadV3(cacheKey, resumed);
|
|
101
|
+
return resumed.result;
|
|
102
|
+
}
|
|
103
|
+
const discovered = discoverLedgerFramesV3(coordRoot);
|
|
104
|
+
const validated = validateLedgerFramesV3(discovered.frames, options);
|
|
105
|
+
const recovery = discoverRecoveryReceiptsV3(coordRoot);
|
|
106
|
+
const diagnostics = [
|
|
107
|
+
...discovered.diagnostics,
|
|
108
|
+
...validated.result.diagnostics,
|
|
109
|
+
...recovery.diagnostics,
|
|
110
|
+
];
|
|
111
|
+
const result = {
|
|
112
|
+
...validated.result,
|
|
113
|
+
diagnostics,
|
|
114
|
+
complete: diagnostics.length === 0,
|
|
115
|
+
bytes: discovered.bytes,
|
|
116
|
+
failed_epochs: recovery.receipts,
|
|
117
|
+
};
|
|
118
|
+
rememberLedgerReadV3(cacheKey, {
|
|
119
|
+
storage,
|
|
120
|
+
active: discovered.active,
|
|
121
|
+
validation_state: isolateValidationStateV3(validated.state),
|
|
122
|
+
result,
|
|
123
|
+
});
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
function rememberLedgerReadV3(cacheKey, cached) {
|
|
127
|
+
ledgerReadCacheV3.delete(cacheKey);
|
|
128
|
+
ledgerReadCacheV3.set(cacheKey, cached);
|
|
129
|
+
while (ledgerReadCacheV3.size > MAX_CACHED_LEDGER_READS) {
|
|
130
|
+
const oldestKey = ledgerReadCacheV3.keys().next().value;
|
|
131
|
+
if (oldestKey === undefined)
|
|
132
|
+
break;
|
|
133
|
+
ledgerReadCacheV3.delete(oldestKey);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export function readLedgerV3Since(coordRoot, cursor, options = {}) {
|
|
137
|
+
const discovered = discoverLedgerFramesV3(coordRoot);
|
|
138
|
+
const read = readLedgerFramesV3Since(discovered.frames, cursor, options);
|
|
139
|
+
const recovery = discoverRecoveryReceiptsV3(coordRoot);
|
|
140
|
+
const diagnostics = [...discovered.diagnostics, ...read.diagnostics, ...recovery.diagnostics];
|
|
141
|
+
return {
|
|
142
|
+
...read,
|
|
143
|
+
events: diagnostics.length === 0 ? read.events : [],
|
|
144
|
+
diagnostics,
|
|
145
|
+
complete: diagnostics.length === 0,
|
|
146
|
+
bytes: discovered.bytes,
|
|
147
|
+
failed_epochs: recovery.receipts,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function discoverRecoveryReceiptsV3(coordRoot) {
|
|
151
|
+
try {
|
|
152
|
+
return { receipts: listEventV3RecoveryReceipts(coordRoot), diagnostics: [] };
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
return {
|
|
156
|
+
receipts: [],
|
|
157
|
+
diagnostics: [storageDiagnostic("recovery_record_invalid", 0)],
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Validate an already-discovered V3 event stream in exact physical order.
|
|
163
|
+
* Filesystem/catalog discovery feeds this boundary; every downstream reader
|
|
164
|
+
* and projection consumes its positioned, authority-checked result.
|
|
165
|
+
*/
|
|
166
|
+
export function readLedgerFramesV3(frames, options = {}) {
|
|
167
|
+
return validateLedgerFramesV3(frames, options).result;
|
|
168
|
+
}
|
|
169
|
+
function validateLedgerFramesV3(frames, options) {
|
|
170
|
+
const state = {
|
|
171
|
+
diagnostics: [],
|
|
172
|
+
events: [],
|
|
173
|
+
advances: [],
|
|
174
|
+
accepted: new Set(options.accepted_schema_digests ?? [EVENT_V3_SCHEMA_DIGEST]),
|
|
175
|
+
reader_build: options.reader_build ?? "build_harnery-v3",
|
|
176
|
+
seen_ids: new Map(),
|
|
177
|
+
producer_sequences: new Map(),
|
|
178
|
+
attestations: new Set(),
|
|
179
|
+
clocks: new Map(),
|
|
180
|
+
};
|
|
181
|
+
validateLedgerFramesIntoStateV3(frames, state);
|
|
182
|
+
return { result: finishLedgerValidationV3(state, options, ledgerFramesBytesV3(frames)), state };
|
|
183
|
+
}
|
|
184
|
+
function validateLedgerFramesIntoStateV3(frames, state) {
|
|
185
|
+
state.first_position ??= frames[0]?.position;
|
|
186
|
+
const { diagnostics, events, advances, accepted, reader_build: readerBuild, seen_ids: seenIds, producer_sequences: producerSequences, attestations, clocks, } = state;
|
|
187
|
+
for (const frame of frames) {
|
|
188
|
+
if (state.pending) {
|
|
189
|
+
const comparison = comparePosition(frame.position, state.pending.position);
|
|
190
|
+
if (comparison === 0) {
|
|
191
|
+
state.active_schema_digest = state.pending.next_schema_digest;
|
|
192
|
+
state.pending = undefined;
|
|
193
|
+
}
|
|
194
|
+
else if (comparison > 0) {
|
|
195
|
+
diagnostics.push(diagnostic("advance_boundary_missed", frame, state.pending.event_id));
|
|
196
|
+
state.pending = undefined;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
let parsed;
|
|
200
|
+
try {
|
|
201
|
+
parsed = JSON.parse(frame.raw);
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
diagnostics.push(diagnostic("malformed_json", frame));
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
const loose = parsed;
|
|
208
|
+
const looseContract = record(loose.contract);
|
|
209
|
+
if (looseContract.major !== 3) {
|
|
210
|
+
diagnostics.push(diagnostic("unsupported_major", frame));
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
const validation = validateEventV3(parsed);
|
|
214
|
+
if (!validation.ok || !validation.event) {
|
|
215
|
+
diagnostics.push(diagnostic("invalid_contract", frame));
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
const event = validation.event;
|
|
219
|
+
const shape = event;
|
|
220
|
+
if (canonicalJsonV3(event) !== frame.raw) {
|
|
221
|
+
diagnostics.push(diagnostic("noncanonical_frame", frame, shape.event_id));
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
const priorFrame = seenIds.get(shape.event_id);
|
|
225
|
+
if (priorFrame !== undefined) {
|
|
226
|
+
if (priorFrame !== frame.raw) {
|
|
227
|
+
diagnostics.push(diagnostic("conflicting_event_id", frame, shape.event_id));
|
|
228
|
+
}
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
seenIds.set(shape.event_id, frame.raw);
|
|
232
|
+
if (shape.event_type === "ledger.genesis") {
|
|
233
|
+
if (state.genesis_id !== undefined) {
|
|
234
|
+
diagnostics.push(diagnostic("multiple_genesis", frame, shape.event_id));
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
if (events.length !== 0)
|
|
238
|
+
diagnostics.push(diagnostic("genesis_not_first", frame, shape.event_id));
|
|
239
|
+
const payload = shape.payload;
|
|
240
|
+
state.genesis_id = string(payload.genesis_id);
|
|
241
|
+
state.active_schema_digest = string(payload.generated_schema_digest);
|
|
242
|
+
if (state.active_schema_digest !== shape.contract.schema_digest) {
|
|
243
|
+
diagnostics.push(diagnostic("genesis_digest_mismatch", frame, shape.event_id));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
else if (state.genesis_id === undefined) {
|
|
247
|
+
diagnostics.push(diagnostic("missing_genesis", frame, shape.event_id));
|
|
248
|
+
}
|
|
249
|
+
if (!accepted.has(shape.contract.schema_digest)) {
|
|
250
|
+
diagnostics.push(diagnostic("unsupported_schema_digest", frame, shape.event_id));
|
|
251
|
+
}
|
|
252
|
+
if (state.active_schema_digest !== undefined &&
|
|
253
|
+
shape.contract.schema_digest !== state.active_schema_digest) {
|
|
254
|
+
diagnostics.push(diagnostic("unexpected_schema_digest", frame, shape.event_id));
|
|
255
|
+
}
|
|
256
|
+
for (const parentId of shape.links.caused_by) {
|
|
257
|
+
if (!seenIds.has(parentId)) {
|
|
258
|
+
diagnostics.push(diagnostic("causal_parent_missing", frame, shape.event_id));
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
validateClock(shape, frame, clocks, diagnostics);
|
|
263
|
+
validateAttestation(shape, frame, attestations, diagnostics);
|
|
264
|
+
validateProducerSequence(shape, frame, producerSequences, diagnostics);
|
|
265
|
+
if (shape.event_type === "ledger.schema_advanced") {
|
|
266
|
+
const payload = shape.payload;
|
|
267
|
+
const nextDigest = string(payload.next_schema_digest);
|
|
268
|
+
const priorDigest = string(payload.prior_schema_digest);
|
|
269
|
+
const effectivePosition = {
|
|
270
|
+
segment_ordinal: number(payload.effective_segment_ordinal),
|
|
271
|
+
byte_offset: number(payload.effective_byte_offset),
|
|
272
|
+
};
|
|
273
|
+
if (priorDigest !== state.active_schema_digest) {
|
|
274
|
+
diagnostics.push(diagnostic("advance_prior_mismatch", frame, shape.event_id));
|
|
275
|
+
}
|
|
276
|
+
if (!accepted.has(nextDigest)) {
|
|
277
|
+
diagnostics.push(diagnostic("advance_digest_unsupported", frame, shape.event_id));
|
|
278
|
+
}
|
|
279
|
+
const compatibleBuilds = stringArray(payload.compatible_reader_builds);
|
|
280
|
+
if (!compatibleBuilds.includes(readerBuild)) {
|
|
281
|
+
diagnostics.push(diagnostic("advance_reader_incompatible", frame, shape.event_id));
|
|
282
|
+
}
|
|
283
|
+
if (comparePosition(effectivePosition, frame.position) <= 0 || state.pending) {
|
|
284
|
+
diagnostics.push(diagnostic("advance_boundary_invalid", frame, shape.event_id));
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
state.pending = {
|
|
288
|
+
event_id: shape.event_id,
|
|
289
|
+
next_schema_digest: nextDigest,
|
|
290
|
+
position: effectivePosition,
|
|
291
|
+
};
|
|
292
|
+
advances.push({
|
|
293
|
+
event_id: shape.event_id,
|
|
294
|
+
prior_schema_digest: priorDigest,
|
|
295
|
+
next_schema_digest: nextDigest,
|
|
296
|
+
effective_position: effectivePosition,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
events.push({ event, position: frame.position });
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function finishLedgerValidationV3(state, options, bytes) {
|
|
304
|
+
const diagnostics = [...state.diagnostics];
|
|
305
|
+
if (state.genesis_id === undefined &&
|
|
306
|
+
!diagnostics.some(({ code }) => code === "missing_genesis")) {
|
|
307
|
+
diagnostics.push({
|
|
308
|
+
code: "missing_genesis",
|
|
309
|
+
segment_ordinal: state.first_position?.segment_ordinal ?? 0,
|
|
310
|
+
byte_offset: state.first_position?.byte_offset ?? 0,
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
if (options.authority === "active" && state.genesis_id !== undefined) {
|
|
314
|
+
const activations = state.events.filter(({ event }) => event.event_type === "ledger.activated");
|
|
315
|
+
if (activations.length === 0) {
|
|
316
|
+
diagnostics.push({ code: "missing_activation", segment_ordinal: 0, byte_offset: 0 });
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
const activation = activations.at(-1);
|
|
320
|
+
const payload = activation.event.payload;
|
|
321
|
+
if (payload.genesis_id !== state.genesis_id) {
|
|
322
|
+
diagnostics.push(diagnostic("activation_genesis_mismatch", {
|
|
323
|
+
raw: "",
|
|
324
|
+
position: activation.position,
|
|
325
|
+
}, activation.event.event_id));
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
events: state.events,
|
|
331
|
+
diagnostics,
|
|
332
|
+
complete: diagnostics.length === 0,
|
|
333
|
+
genesis_id: state.genesis_id,
|
|
334
|
+
active_schema_digest: state.active_schema_digest,
|
|
335
|
+
advances: state.advances,
|
|
336
|
+
bytes,
|
|
337
|
+
failed_epochs: [],
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
function ledgerFramesBytesV3(frames) {
|
|
341
|
+
return frames.reduce((total, frame) => total + Buffer.byteLength(frame.raw, "utf8") + 1, 0);
|
|
342
|
+
}
|
|
343
|
+
export function readLedgerFramesV3Since(frames, cursor, options = {}) {
|
|
344
|
+
const read = readLedgerFramesV3(frames, options);
|
|
345
|
+
if (!read.genesis_id || !read.complete) {
|
|
346
|
+
return { ...read, events: [], cursor, reset_required: Boolean(cursor) };
|
|
347
|
+
}
|
|
348
|
+
if (cursor?.genesis_id !== undefined && cursor.genesis_id !== read.genesis_id) {
|
|
349
|
+
return withCursorDiagnostic(read, "cursor_genesis_mismatch", cursor);
|
|
350
|
+
}
|
|
351
|
+
let startIndex = 0;
|
|
352
|
+
if (cursor) {
|
|
353
|
+
const index = read.events.findIndex(({ event, position }) => event.event_id === cursor.event_id &&
|
|
354
|
+
position.segment_ordinal === cursor.segment_ordinal &&
|
|
355
|
+
position.byte_offset === cursor.byte_offset);
|
|
356
|
+
if (index < 0)
|
|
357
|
+
return withCursorDiagnostic(read, "cursor_position_missing", cursor);
|
|
358
|
+
startIndex = index + 1;
|
|
359
|
+
}
|
|
360
|
+
const last = read.events.at(-1);
|
|
361
|
+
return {
|
|
362
|
+
...read,
|
|
363
|
+
events: read.events.slice(startIndex),
|
|
364
|
+
cursor: last
|
|
365
|
+
? {
|
|
366
|
+
genesis_id: read.genesis_id,
|
|
367
|
+
segment_ordinal: last.position.segment_ordinal,
|
|
368
|
+
byte_offset: last.position.byte_offset,
|
|
369
|
+
event_id: last.event.event_id,
|
|
370
|
+
}
|
|
371
|
+
: cursor,
|
|
372
|
+
reset_required: false,
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
function validateAttestation(event, frame, attestations, diagnostics) {
|
|
376
|
+
if (event.event_type === "session.started") {
|
|
377
|
+
if (event.attestation_id)
|
|
378
|
+
attestations.add(event.attestation_id);
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
if (event.event_type === "session.attestation_changed") {
|
|
382
|
+
const prior = string(event.payload.prior_attestation_id);
|
|
383
|
+
if (!attestations.has(prior)) {
|
|
384
|
+
diagnostics.push(diagnostic("unresolved_attestation", frame, event.event_id));
|
|
385
|
+
}
|
|
386
|
+
if (event.attestation_id)
|
|
387
|
+
attestations.add(event.attestation_id);
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (event.attestation_id && !attestations.has(event.attestation_id)) {
|
|
391
|
+
diagnostics.push(diagnostic("unresolved_attestation", frame, event.event_id));
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
function validateClock(event, frame, clocks, diagnostics) {
|
|
395
|
+
const prior = clocks.get(event.time.clock_id);
|
|
396
|
+
const observedAtMs = Date.parse(event.time.observed_at);
|
|
397
|
+
if (prior && observedAtMs < prior.observed_at_ms && event.time.skew !== "regressed") {
|
|
398
|
+
diagnostics.push(diagnostic("wall_clock_regression_unmarked", frame, event.event_id));
|
|
399
|
+
}
|
|
400
|
+
const monotonicNs = event.time.monotonic_ns ? BigInt(event.time.monotonic_ns) : undefined;
|
|
401
|
+
if (prior?.monotonic_ns !== undefined &&
|
|
402
|
+
monotonicNs !== undefined &&
|
|
403
|
+
monotonicNs < prior.monotonic_ns) {
|
|
404
|
+
diagnostics.push(diagnostic("monotonic_clock_regression", frame, event.event_id));
|
|
405
|
+
}
|
|
406
|
+
clocks.set(event.time.clock_id, {
|
|
407
|
+
observed_at_ms: observedAtMs,
|
|
408
|
+
...(monotonicNs !== undefined ? { monotonic_ns: monotonicNs } : {}),
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
function validateProducerSequence(event, frame, sequences, diagnostics) {
|
|
412
|
+
const key = `${event.producer.producer_id}\0${event.producer.boot_id}`;
|
|
413
|
+
const prior = sequences.get(key);
|
|
414
|
+
if ((prior === undefined && event.producer.sequence !== 1) ||
|
|
415
|
+
(prior !== undefined && event.producer.sequence !== prior + 1)) {
|
|
416
|
+
diagnostics.push(diagnostic("producer_sequence_gap", frame, event.event_id));
|
|
417
|
+
}
|
|
418
|
+
sequences.set(key, event.producer.sequence);
|
|
419
|
+
}
|
|
420
|
+
function withCursorDiagnostic(read, code, cursor) {
|
|
421
|
+
return {
|
|
422
|
+
...read,
|
|
423
|
+
events: [],
|
|
424
|
+
diagnostics: [
|
|
425
|
+
...read.diagnostics,
|
|
426
|
+
{
|
|
427
|
+
code,
|
|
428
|
+
segment_ordinal: cursor.segment_ordinal,
|
|
429
|
+
byte_offset: cursor.byte_offset,
|
|
430
|
+
event_id: cursor.event_id,
|
|
431
|
+
},
|
|
432
|
+
],
|
|
433
|
+
complete: false,
|
|
434
|
+
reset_required: true,
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
function diagnostic(code, frame, eventId) {
|
|
438
|
+
return {
|
|
439
|
+
code,
|
|
440
|
+
segment_ordinal: frame.position.segment_ordinal,
|
|
441
|
+
byte_offset: frame.position.byte_offset,
|
|
442
|
+
...(eventId ? { event_id: eventId } : {}),
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
function comparePosition(left, right) {
|
|
446
|
+
return left.segment_ordinal - right.segment_ordinal || left.byte_offset - right.byte_offset;
|
|
447
|
+
}
|
|
448
|
+
function record(value) {
|
|
449
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
450
|
+
? value
|
|
451
|
+
: {};
|
|
452
|
+
}
|
|
453
|
+
function string(value) {
|
|
454
|
+
return typeof value === "string" ? value : "";
|
|
455
|
+
}
|
|
456
|
+
function number(value) {
|
|
457
|
+
return typeof value === "number" ? value : -1;
|
|
458
|
+
}
|
|
459
|
+
function stringArray(value) {
|
|
460
|
+
return Array.isArray(value)
|
|
461
|
+
? value.filter((item) => typeof item === "string")
|
|
462
|
+
: [];
|
|
463
|
+
}
|
|
464
|
+
function ledgerReadCacheKeyV3(coordRoot, options) {
|
|
465
|
+
const accepted = [...new Set(options.accepted_schema_digests ?? [EVENT_V3_SCHEMA_DIGEST])].sort();
|
|
466
|
+
return JSON.stringify([
|
|
467
|
+
resolve(coordRoot),
|
|
468
|
+
options.authority ?? "",
|
|
469
|
+
options.reader_build ?? "",
|
|
470
|
+
accepted,
|
|
471
|
+
]);
|
|
472
|
+
}
|
|
473
|
+
function resumeCachedLedgerReadV3(cached, storage, options) {
|
|
474
|
+
if (!cached.result.complete ||
|
|
475
|
+
!cached.active ||
|
|
476
|
+
!storage.active ||
|
|
477
|
+
cached.storage.stable_fingerprint !== storage.stable_fingerprint ||
|
|
478
|
+
cached.active.path !== storage.active.path ||
|
|
479
|
+
storage.active.size <= cached.active.bytes) {
|
|
480
|
+
return undefined;
|
|
481
|
+
}
|
|
482
|
+
const appended = readActiveRangeV3(storage.active.path, cached.active.bytes, storage.active.size, cached.active.segment_ordinal);
|
|
483
|
+
if (!appended)
|
|
484
|
+
return undefined;
|
|
485
|
+
const state = {
|
|
486
|
+
...cached.validation_state,
|
|
487
|
+
diagnostics: [],
|
|
488
|
+
events: [...cached.validation_state.events],
|
|
489
|
+
advances: [...cached.validation_state.advances],
|
|
490
|
+
};
|
|
491
|
+
validateLedgerFramesIntoStateV3(appended.frames, state);
|
|
492
|
+
const validated = finishLedgerValidationV3(state, options, cached.result.bytes + appended.bytes);
|
|
493
|
+
const diagnostics = [...appended.diagnostics, ...validated.diagnostics];
|
|
494
|
+
return {
|
|
495
|
+
storage,
|
|
496
|
+
active: {
|
|
497
|
+
...cached.active,
|
|
498
|
+
bytes: storage.active.size,
|
|
499
|
+
},
|
|
500
|
+
validation_state: isolateValidationStateV3(state),
|
|
501
|
+
result: {
|
|
502
|
+
...validated,
|
|
503
|
+
diagnostics,
|
|
504
|
+
complete: diagnostics.length === 0,
|
|
505
|
+
failed_epochs: cached.result.failed_epochs,
|
|
506
|
+
},
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
function isolateValidationStateV3(state) {
|
|
510
|
+
return {
|
|
511
|
+
...state,
|
|
512
|
+
diagnostics: [...state.diagnostics],
|
|
513
|
+
events: [...state.events],
|
|
514
|
+
advances: [...state.advances],
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
function readActiveRangeV3(path, start, end, segmentOrdinal) {
|
|
518
|
+
const length = end - start;
|
|
519
|
+
const bytes = Buffer.alloc(length);
|
|
520
|
+
let offset = 0;
|
|
521
|
+
let fd;
|
|
522
|
+
try {
|
|
523
|
+
fd = openSync(path, "r");
|
|
524
|
+
while (offset < length) {
|
|
525
|
+
const read = readSync(fd, bytes, offset, length - offset, start + offset);
|
|
526
|
+
if (read === 0)
|
|
527
|
+
return undefined;
|
|
528
|
+
offset += read;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
catch {
|
|
532
|
+
return undefined;
|
|
533
|
+
}
|
|
534
|
+
finally {
|
|
535
|
+
if (fd !== undefined)
|
|
536
|
+
closeSync(fd);
|
|
537
|
+
}
|
|
538
|
+
return framesFromBytes(bytes, segmentOrdinal, true, start);
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Cheap identity for every filesystem object that can change discovery.
|
|
542
|
+
* Capture it before reading: a concurrent append then changes the next call's
|
|
543
|
+
* fingerprint, so a read that raced the writer is never retained as current.
|
|
544
|
+
*/
|
|
545
|
+
function ledgerStorageVersionV3(coordRoot) {
|
|
546
|
+
const paths = eventV3Paths(coordRoot);
|
|
547
|
+
const catalog = pathStorageVersionV3(paths.catalog);
|
|
548
|
+
const active = pathStorageVersionV3(paths.active);
|
|
549
|
+
const parts = [`catalog:${catalog.fingerprint}`];
|
|
550
|
+
const stableParts = [`catalog:${catalog.fingerprint}`, `active:${active.stable_fingerprint}`];
|
|
551
|
+
let names;
|
|
552
|
+
try {
|
|
553
|
+
names = readdirSync(paths.segments)
|
|
554
|
+
.filter((name) => /^(\d{12})\.(ndjson|manifest\.json)$/.test(name))
|
|
555
|
+
.sort();
|
|
556
|
+
}
|
|
557
|
+
catch (error) {
|
|
558
|
+
const segmentError = `segments:${filesystemErrorCode(error)}`;
|
|
559
|
+
parts.push(segmentError);
|
|
560
|
+
stableParts.push(segmentError);
|
|
561
|
+
return {
|
|
562
|
+
fingerprint: [...parts, `active:${active.fingerprint}`].join("|"),
|
|
563
|
+
stable_fingerprint: stableParts.join("|"),
|
|
564
|
+
...(active.regular ? { active: { path: paths.active, size: active.size } } : {}),
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
for (const name of names) {
|
|
568
|
+
const part = `segment:${name}:${pathStorageVersionV3(join(paths.segments, name)).fingerprint}`;
|
|
569
|
+
parts.push(part);
|
|
570
|
+
stableParts.push(part);
|
|
571
|
+
}
|
|
572
|
+
const recoveryRoot = eventV3RecoveryRecordsRoot(coordRoot);
|
|
573
|
+
let recoveryNames = [];
|
|
574
|
+
try {
|
|
575
|
+
recoveryNames = readdirSync(recoveryRoot)
|
|
576
|
+
.filter((name) => name.endsWith(".committed.json"))
|
|
577
|
+
.sort();
|
|
578
|
+
}
|
|
579
|
+
catch (error) {
|
|
580
|
+
const code = filesystemErrorCode(error);
|
|
581
|
+
if (code !== "ENOENT") {
|
|
582
|
+
const part = `recoveries:${code}`;
|
|
583
|
+
parts.push(part);
|
|
584
|
+
stableParts.push(part);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
for (const name of recoveryNames) {
|
|
588
|
+
const part = `recovery:${name}:${pathStorageVersionV3(join(recoveryRoot, name)).fingerprint}`;
|
|
589
|
+
parts.push(part);
|
|
590
|
+
stableParts.push(part);
|
|
591
|
+
}
|
|
592
|
+
return {
|
|
593
|
+
fingerprint: [...parts, `active:${active.fingerprint}`].join("|"),
|
|
594
|
+
stable_fingerprint: stableParts.join("|"),
|
|
595
|
+
...(active.regular ? { active: { path: paths.active, size: active.size } } : {}),
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
function pathStorageVersionV3(path) {
|
|
599
|
+
try {
|
|
600
|
+
const stat = lstatSync(path, { bigint: true });
|
|
601
|
+
const stableFingerprint = [stat.mode, stat.dev, stat.ino, stat.birthtimeNs].join(":");
|
|
602
|
+
return {
|
|
603
|
+
fingerprint: [stableFingerprint, stat.size, stat.mtimeNs, stat.ctimeNs].join(":"),
|
|
604
|
+
stable_fingerprint: stableFingerprint,
|
|
605
|
+
regular: stat.isFile() && !stat.isSymbolicLink(),
|
|
606
|
+
size: Number(stat.size),
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
catch (error) {
|
|
610
|
+
const code = filesystemErrorCode(error);
|
|
611
|
+
return { fingerprint: code, stable_fingerprint: code, regular: false, size: 0 };
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
function filesystemErrorCode(error) {
|
|
615
|
+
return error && typeof error === "object" && "code" in error
|
|
616
|
+
? String(error.code)
|
|
617
|
+
: "unavailable";
|
|
618
|
+
}
|
|
619
|
+
function discoverLedgerFramesV3(coordRoot) {
|
|
620
|
+
const paths = eventV3Paths(coordRoot);
|
|
621
|
+
if (!existsSync(paths.catalog)) {
|
|
622
|
+
if (hasSealedV3Metadata(paths.segments)) {
|
|
623
|
+
return {
|
|
624
|
+
frames: [],
|
|
625
|
+
diagnostics: [storageDiagnostic("catalog_invalid", 0)],
|
|
626
|
+
bytes: 0,
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
if (!existsSync(paths.active))
|
|
630
|
+
return { frames: [], diagnostics: [], bytes: 0 };
|
|
631
|
+
const bytes = readFileSync(paths.active);
|
|
632
|
+
return {
|
|
633
|
+
...framesFromBytes(bytes, 1, true),
|
|
634
|
+
active: { bytes: bytes.length, path: paths.active, segment_ordinal: 1 },
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
let catalog;
|
|
638
|
+
try {
|
|
639
|
+
catalog = readEventV3Catalog(paths.catalog);
|
|
640
|
+
}
|
|
641
|
+
catch {
|
|
642
|
+
return {
|
|
643
|
+
frames: [],
|
|
644
|
+
diagnostics: [storageDiagnostic("catalog_invalid", 0)],
|
|
645
|
+
bytes: 0,
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
const discovered = { frames: [], diagnostics: [], bytes: 0 };
|
|
649
|
+
for (const entry of catalog.segments) {
|
|
650
|
+
discoverSealedSegment(paths.segments, entry, discovered);
|
|
651
|
+
}
|
|
652
|
+
discoverActiveSegment(paths.active, catalog, discovered);
|
|
653
|
+
return discovered;
|
|
654
|
+
}
|
|
655
|
+
function discoverSealedSegment(segmentsRoot, entry, discovered) {
|
|
656
|
+
const segmentPath = join(segmentsRoot, entry.segment_file);
|
|
657
|
+
const manifestPath = join(segmentsRoot, entry.manifest_file);
|
|
658
|
+
if (!regularFile(segmentPath) || !regularFile(manifestPath)) {
|
|
659
|
+
discovered.diagnostics.push(storageDiagnostic("missing_segment", entry.ordinal));
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
const segmentBytes = readFileSync(segmentPath);
|
|
663
|
+
const manifestBytes = readFileSync(manifestPath);
|
|
664
|
+
discovered.bytes += segmentBytes.length;
|
|
665
|
+
if (segmentBytes.length !== entry.bytes || sha256V3(segmentBytes) !== entry.segment_digest) {
|
|
666
|
+
discovered.diagnostics.push(storageDiagnostic("segment_digest_mismatch", entry.ordinal));
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
if (sha256V3(manifestBytes) !== entry.manifest_digest) {
|
|
670
|
+
discovered.diagnostics.push(storageDiagnostic("manifest_digest_mismatch", entry.ordinal));
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
let manifest;
|
|
674
|
+
try {
|
|
675
|
+
manifest = readEventV3SegmentManifest(manifestPath);
|
|
676
|
+
}
|
|
677
|
+
catch {
|
|
678
|
+
discovered.diagnostics.push(storageDiagnostic("manifest_segment_mismatch", entry.ordinal));
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
const segment = framesFromBytes(segmentBytes, entry.ordinal, false);
|
|
682
|
+
if (!manifestMatchesCatalog(manifest, entry) ||
|
|
683
|
+
!manifestMatchesFrames(manifest, segment.frames)) {
|
|
684
|
+
discovered.diagnostics.push(storageDiagnostic("manifest_segment_mismatch", entry.ordinal));
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
discovered.frames.push(...segment.frames);
|
|
688
|
+
discovered.diagnostics.push(...segment.diagnostics);
|
|
689
|
+
}
|
|
690
|
+
function discoverActiveSegment(activePath, catalog, discovered) {
|
|
691
|
+
if (!regularFile(activePath)) {
|
|
692
|
+
discovered.diagnostics.push(storageDiagnostic("active_replaced", catalog.active.ordinal));
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
const stat = statSync(activePath);
|
|
696
|
+
const bigintStat = statSync(activePath, { bigint: true });
|
|
697
|
+
if (String(stat.dev) !== catalog.active.device ||
|
|
698
|
+
String(stat.ino) !== catalog.active.inode ||
|
|
699
|
+
String(bigintStat.birthtimeNs) !== catalog.active.birthtime_ns) {
|
|
700
|
+
discovered.diagnostics.push(storageDiagnostic("active_replaced", catalog.active.ordinal));
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
const bytes = readFileSync(activePath);
|
|
704
|
+
const active = framesFromBytes(bytes, catalog.active.ordinal, true);
|
|
705
|
+
discovered.frames.push(...active.frames);
|
|
706
|
+
discovered.diagnostics.push(...active.diagnostics);
|
|
707
|
+
discovered.bytes += bytes.length;
|
|
708
|
+
discovered.active = {
|
|
709
|
+
bytes: bytes.length,
|
|
710
|
+
path: activePath,
|
|
711
|
+
segment_ordinal: catalog.active.ordinal,
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
function framesFromBytes(bytes, segmentOrdinal, allowPartialFinalFrame, initialByteOffset = 0) {
|
|
715
|
+
const raw = bytes.toString("utf8");
|
|
716
|
+
const frames = [];
|
|
717
|
+
const diagnostics = [];
|
|
718
|
+
const lines = raw.split("\n");
|
|
719
|
+
let byteOffset = initialByteOffset;
|
|
720
|
+
for (const [index, line] of lines.entries()) {
|
|
721
|
+
const final = index === lines.length - 1;
|
|
722
|
+
const lineBytes = Buffer.byteLength(line, "utf8");
|
|
723
|
+
if (line.length === 0) {
|
|
724
|
+
if (!final) {
|
|
725
|
+
diagnostics.push(storageDiagnostic("malformed_json", segmentOrdinal, byteOffset));
|
|
726
|
+
byteOffset += 1;
|
|
727
|
+
}
|
|
728
|
+
continue;
|
|
729
|
+
}
|
|
730
|
+
if (final && !raw.endsWith("\n")) {
|
|
731
|
+
diagnostics.push(storageDiagnostic(allowPartialFinalFrame ? "partial_final_frame" : "malformed_json", segmentOrdinal, byteOffset));
|
|
732
|
+
break;
|
|
733
|
+
}
|
|
734
|
+
frames.push({
|
|
735
|
+
raw: line,
|
|
736
|
+
position: { segment_ordinal: segmentOrdinal, byte_offset: byteOffset },
|
|
737
|
+
});
|
|
738
|
+
byteOffset += lineBytes + 1;
|
|
739
|
+
}
|
|
740
|
+
return { frames, diagnostics, bytes: bytes.length };
|
|
741
|
+
}
|
|
742
|
+
function manifestMatchesCatalog(manifest, entry) {
|
|
743
|
+
return (manifest.ordinal === entry.ordinal &&
|
|
744
|
+
manifest.segment_file === entry.segment_file &&
|
|
745
|
+
manifest.segment_digest === entry.segment_digest &&
|
|
746
|
+
manifest.bytes === entry.bytes &&
|
|
747
|
+
manifest.row_count === entry.row_count);
|
|
748
|
+
}
|
|
749
|
+
function manifestMatchesFrames(manifest, frames) {
|
|
750
|
+
if (frames.length !== manifest.row_count)
|
|
751
|
+
return false;
|
|
752
|
+
try {
|
|
753
|
+
const records = frames.map(({ raw }) => record(JSON.parse(raw)));
|
|
754
|
+
const schemaDigests = [
|
|
755
|
+
...new Set(records.map((event) => string(record(event.contract).schema_digest))),
|
|
756
|
+
].sort();
|
|
757
|
+
return (records[0]?.event_id === manifest.first_event_id &&
|
|
758
|
+
records.at(-1)?.event_id === manifest.last_event_id &&
|
|
759
|
+
schemaDigests.join("\0") === manifest.schema_digests.join("\0"));
|
|
760
|
+
}
|
|
761
|
+
catch {
|
|
762
|
+
return false;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
function hasSealedV3Metadata(segmentsPath) {
|
|
766
|
+
if (!existsSync(segmentsPath))
|
|
767
|
+
return false;
|
|
768
|
+
return readdirSync(segmentsPath).some((name) => /^(\d{12})\.(ndjson|manifest\.json)$/.test(name));
|
|
769
|
+
}
|
|
770
|
+
function regularFile(path) {
|
|
771
|
+
if (!existsSync(path))
|
|
772
|
+
return false;
|
|
773
|
+
const stat = lstatSync(path);
|
|
774
|
+
return stat.isFile() && !stat.isSymbolicLink();
|
|
775
|
+
}
|
|
776
|
+
function storageDiagnostic(code, segmentOrdinal, byteOffset = 0) {
|
|
777
|
+
return { code, segment_ordinal: segmentOrdinal, byte_offset: byteOffset };
|
|
778
|
+
}
|