harnery 0.33.0 → 0.34.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/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 +1237 -590
- 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 +306 -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 +161 -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 +1530 -593
- 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 +352 -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 +171 -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,548 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import {
|
|
3
|
+
closeSync,
|
|
4
|
+
existsSync,
|
|
5
|
+
fsyncSync,
|
|
6
|
+
linkSync,
|
|
7
|
+
openSync,
|
|
8
|
+
readdirSync,
|
|
9
|
+
readFileSync,
|
|
10
|
+
unlinkSync,
|
|
11
|
+
writeFileSync,
|
|
12
|
+
} from "node:fs";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { fsyncParentDirectory } from "../../workflow/durable-record.ts";
|
|
15
|
+
import { canonicalJsonV3, sha256V3 } from "./canonical.ts";
|
|
16
|
+
import type { EventV3 } from "./contract.ts";
|
|
17
|
+
import { assertEventV3 } from "./validate.ts";
|
|
18
|
+
import { ensureEventV3Layout, eventV3Paths, writeEventV3 } from "./writer.ts";
|
|
19
|
+
|
|
20
|
+
const SHA256_PATTERN = /^sha256:[a-f0-9]{64}$/;
|
|
21
|
+
const INSTANCE_PATTERN = /^inst_[a-zA-Z0-9._-]{1,128}$/;
|
|
22
|
+
const TX_PATTERN = /^txn_[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
23
|
+
const SAFE_ID_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
24
|
+
const REASON_PATTERN = /^[a-z0-9][a-z0-9._-]{0,79}$/;
|
|
25
|
+
|
|
26
|
+
export type AuthorityMutationV3 =
|
|
27
|
+
| {
|
|
28
|
+
kind: "task.transition";
|
|
29
|
+
state: "set" | "cleared";
|
|
30
|
+
task_fingerprint?: `sha256:${string}`;
|
|
31
|
+
}
|
|
32
|
+
| {
|
|
33
|
+
kind: "lifecycle.transition";
|
|
34
|
+
state: "active" | "blocked" | "done";
|
|
35
|
+
reason_code?: string;
|
|
36
|
+
}
|
|
37
|
+
| {
|
|
38
|
+
kind: "claim.transition";
|
|
39
|
+
operation: "acquired" | "released";
|
|
40
|
+
target_fingerprint: `sha256:${string}`;
|
|
41
|
+
access: "read" | "write";
|
|
42
|
+
}
|
|
43
|
+
| {
|
|
44
|
+
kind: "identity.assume";
|
|
45
|
+
identity_id: string;
|
|
46
|
+
}
|
|
47
|
+
| {
|
|
48
|
+
kind: "decision.resolve";
|
|
49
|
+
decision_id: string;
|
|
50
|
+
outcome: "approved" | "denied" | "deferred";
|
|
51
|
+
}
|
|
52
|
+
| {
|
|
53
|
+
kind: "wait.start";
|
|
54
|
+
wait_id: string;
|
|
55
|
+
wait_kind:
|
|
56
|
+
| "permission"
|
|
57
|
+
| "approval"
|
|
58
|
+
| "decision"
|
|
59
|
+
| "operator_input"
|
|
60
|
+
| "dependency"
|
|
61
|
+
| "scheduled";
|
|
62
|
+
}
|
|
63
|
+
| {
|
|
64
|
+
kind: "wait.end";
|
|
65
|
+
wait_id: string;
|
|
66
|
+
outcome:
|
|
67
|
+
| "succeeded"
|
|
68
|
+
| "failed"
|
|
69
|
+
| "cancelled"
|
|
70
|
+
| "timed_out"
|
|
71
|
+
| "denied"
|
|
72
|
+
| "interrupted"
|
|
73
|
+
| "unknown";
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export interface PrepareAuthorityTransactionV3Input {
|
|
77
|
+
transaction_id?: `txn_${string}`;
|
|
78
|
+
expected_prior_state_digest: `sha256:${string}`;
|
|
79
|
+
desired_state_digest: `sha256:${string}`;
|
|
80
|
+
actor_instance_id: string;
|
|
81
|
+
subject_instance_id: string;
|
|
82
|
+
mutation: AuthorityMutationV3;
|
|
83
|
+
event: EventV3;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface AuthorityTransactionV3 {
|
|
87
|
+
format: "harnery-event-v3-authority-transaction";
|
|
88
|
+
format_version: 1;
|
|
89
|
+
transaction_id: `txn_${string}`;
|
|
90
|
+
expected_prior_state_digest: `sha256:${string}`;
|
|
91
|
+
desired_state_digest: `sha256:${string}`;
|
|
92
|
+
actor_instance_id: string;
|
|
93
|
+
subject_instance_id: string;
|
|
94
|
+
mutation: AuthorityMutationV3;
|
|
95
|
+
event_id: string;
|
|
96
|
+
event_row: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface AuthorityReceiptV3 {
|
|
100
|
+
format: "harnery-event-v3-authority-receipt";
|
|
101
|
+
format_version: 1;
|
|
102
|
+
transaction_id: `txn_${string}`;
|
|
103
|
+
transaction_digest: `sha256:${string}`;
|
|
104
|
+
desired_state_digest: `sha256:${string}`;
|
|
105
|
+
event_id: string;
|
|
106
|
+
event_row_digest: `sha256:${string}`;
|
|
107
|
+
committed_at: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface AuthorityReconcilerV3 {
|
|
111
|
+
readStateDigest: () => `sha256:${string}`;
|
|
112
|
+
apply: (mutation: AuthorityMutationV3, transactionId: string) => void;
|
|
113
|
+
now?: () => Date;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Durably publish the full transaction before any authority-bearing state mutation. */
|
|
117
|
+
export function prepareAuthorityTransactionV3(
|
|
118
|
+
coordRoot: string,
|
|
119
|
+
input: PrepareAuthorityTransactionV3Input,
|
|
120
|
+
): AuthorityTransactionV3 {
|
|
121
|
+
return publishAuthorityTransactionV3(coordRoot, buildAuthorityTransactionV3(input));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Build and validate an authority transaction without touching durable state. */
|
|
125
|
+
export function buildAuthorityTransactionV3(
|
|
126
|
+
input: PrepareAuthorityTransactionV3Input,
|
|
127
|
+
): AuthorityTransactionV3 {
|
|
128
|
+
assertEventV3(input.event);
|
|
129
|
+
const transaction: AuthorityTransactionV3 = {
|
|
130
|
+
format: "harnery-event-v3-authority-transaction",
|
|
131
|
+
format_version: 1,
|
|
132
|
+
transaction_id: input.transaction_id ?? `txn_${randomUUID()}`,
|
|
133
|
+
expected_prior_state_digest: input.expected_prior_state_digest,
|
|
134
|
+
desired_state_digest: input.desired_state_digest,
|
|
135
|
+
actor_instance_id: input.actor_instance_id,
|
|
136
|
+
subject_instance_id: input.subject_instance_id,
|
|
137
|
+
mutation: input.mutation,
|
|
138
|
+
event_id: input.event.event_id,
|
|
139
|
+
event_row: `${canonicalJsonV3(input.event)}\n`,
|
|
140
|
+
};
|
|
141
|
+
validateTransaction(transaction);
|
|
142
|
+
return transaction;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Publish an already-built transaction exactly, preserving its pre-minted event. */
|
|
146
|
+
export function publishAuthorityTransactionV3(
|
|
147
|
+
coordRoot: string,
|
|
148
|
+
transaction: AuthorityTransactionV3,
|
|
149
|
+
): AuthorityTransactionV3 {
|
|
150
|
+
validateTransaction(transaction);
|
|
151
|
+
const paths = ensureEventV3Layout(coordRoot);
|
|
152
|
+
const readyPath = authorityReadyPath(paths.authorityOutbox, transaction.transaction_id);
|
|
153
|
+
const serialized = `${canonicalJsonV3(transaction)}\n`;
|
|
154
|
+
if (existsSync(readyPath)) {
|
|
155
|
+
if (readFileSync(readyPath, "utf8") !== serialized) {
|
|
156
|
+
throw new Error("authority transaction ID conflicts with another ready transaction");
|
|
157
|
+
}
|
|
158
|
+
return transaction;
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
publishExclusive(readyPath, serialized);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
|
|
164
|
+
if (readFileSync(readyPath, "utf8") !== serialized) {
|
|
165
|
+
throw new Error("authority transaction ID conflicts with another ready transaction");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return transaction;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Apply or recognize the desired state, durably submit its event, then leave a hash-only receipt. */
|
|
172
|
+
export function reconcileAuthorityTransactionV3(
|
|
173
|
+
coordRoot: string,
|
|
174
|
+
transactionId: string,
|
|
175
|
+
reconciler: AuthorityReconcilerV3,
|
|
176
|
+
): AuthorityReceiptV3 {
|
|
177
|
+
assertTransactionId(transactionId);
|
|
178
|
+
const paths = ensureEventV3Layout(coordRoot);
|
|
179
|
+
const committedPath = authorityCommittedPath(paths.authorityOutbox, transactionId);
|
|
180
|
+
if (existsSync(committedPath)) return readAuthorityReceiptV3(committedPath);
|
|
181
|
+
const readyPath = authorityReadyPath(paths.authorityOutbox, transactionId);
|
|
182
|
+
const transaction = readAuthorityTransactionV3(readyPath);
|
|
183
|
+
const current = reconciler.readStateDigest();
|
|
184
|
+
if (current === transaction.expected_prior_state_digest) {
|
|
185
|
+
reconciler.apply(transaction.mutation, transaction.transaction_id);
|
|
186
|
+
} else if (current !== transaction.desired_state_digest) {
|
|
187
|
+
throw new Error("authority transaction prior state conflicts with current state");
|
|
188
|
+
}
|
|
189
|
+
if (reconciler.readStateDigest() !== transaction.desired_state_digest) {
|
|
190
|
+
throw new Error("authority transaction did not reach its declared desired state");
|
|
191
|
+
}
|
|
192
|
+
const event = JSON.parse(transaction.event_row) as unknown;
|
|
193
|
+
assertEventV3(event);
|
|
194
|
+
writeEventV3(coordRoot, event);
|
|
195
|
+
const receipt: AuthorityReceiptV3 = {
|
|
196
|
+
format: "harnery-event-v3-authority-receipt",
|
|
197
|
+
format_version: 1,
|
|
198
|
+
transaction_id: transaction.transaction_id,
|
|
199
|
+
transaction_digest: sha256V3(`${canonicalJsonV3(transaction)}\n`),
|
|
200
|
+
desired_state_digest: transaction.desired_state_digest,
|
|
201
|
+
event_id: transaction.event_id,
|
|
202
|
+
event_row_digest: sha256V3(transaction.event_row),
|
|
203
|
+
committed_at: (reconciler.now ?? (() => new Date()))().toISOString(),
|
|
204
|
+
};
|
|
205
|
+
try {
|
|
206
|
+
publishExclusive(committedPath, `${canonicalJsonV3(receipt)}\n`);
|
|
207
|
+
} catch (error) {
|
|
208
|
+
if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
|
|
209
|
+
return readAuthorityReceiptV3(committedPath);
|
|
210
|
+
}
|
|
211
|
+
unlinkSync(readyPath);
|
|
212
|
+
fsyncParentDirectory(readyPath);
|
|
213
|
+
return receipt;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function listPendingAuthorityTransactionsV3(coordRoot: string): AuthorityTransactionV3[] {
|
|
217
|
+
const outbox = eventV3Paths(coordRoot).authorityOutbox;
|
|
218
|
+
if (!existsSync(outbox)) return [];
|
|
219
|
+
return readdirSync(outbox)
|
|
220
|
+
.filter((name) => name.endsWith(".ready.json"))
|
|
221
|
+
.sort()
|
|
222
|
+
.map((name) => readAuthorityTransactionV3(join(outbox, name)));
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function readAuthorityTransactionV3(path: string): AuthorityTransactionV3 {
|
|
226
|
+
const serialized = readFileSync(path, "utf8");
|
|
227
|
+
let parsed: unknown;
|
|
228
|
+
try {
|
|
229
|
+
parsed = JSON.parse(serialized);
|
|
230
|
+
} catch {
|
|
231
|
+
throw new Error("authority transaction is malformed");
|
|
232
|
+
}
|
|
233
|
+
const transaction = validateTransaction(parsed);
|
|
234
|
+
if (`${canonicalJsonV3(transaction)}\n` !== serialized) {
|
|
235
|
+
throw new Error("authority transaction is not canonical");
|
|
236
|
+
}
|
|
237
|
+
return transaction;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export function readAuthorityReceiptV3(path: string): AuthorityReceiptV3 {
|
|
241
|
+
const serialized = readFileSync(path, "utf8");
|
|
242
|
+
let parsed: unknown;
|
|
243
|
+
try {
|
|
244
|
+
parsed = JSON.parse(serialized);
|
|
245
|
+
} catch {
|
|
246
|
+
throw new Error("authority receipt is malformed");
|
|
247
|
+
}
|
|
248
|
+
const receipt = validateReceipt(parsed);
|
|
249
|
+
if (`${canonicalJsonV3(receipt)}\n` !== serialized) {
|
|
250
|
+
throw new Error("authority receipt is not canonical");
|
|
251
|
+
}
|
|
252
|
+
return receipt;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function validateTransaction(value: unknown): AuthorityTransactionV3 {
|
|
256
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
257
|
+
throw new Error("authority transaction envelope is invalid");
|
|
258
|
+
}
|
|
259
|
+
const record = value as Record<string, unknown>;
|
|
260
|
+
if (
|
|
261
|
+
Object.keys(record).sort().join("\0") !==
|
|
262
|
+
"actor_instance_id\0desired_state_digest\0event_id\0event_row\0expected_prior_state_digest\0format\0format_version\0mutation\0subject_instance_id\0transaction_id"
|
|
263
|
+
) {
|
|
264
|
+
throw new Error("authority transaction has unsupported fields");
|
|
265
|
+
}
|
|
266
|
+
if (
|
|
267
|
+
record.format !== "harnery-event-v3-authority-transaction" ||
|
|
268
|
+
record.format_version !== 1 ||
|
|
269
|
+
typeof record.transaction_id !== "string" ||
|
|
270
|
+
typeof record.expected_prior_state_digest !== "string" ||
|
|
271
|
+
typeof record.desired_state_digest !== "string" ||
|
|
272
|
+
typeof record.actor_instance_id !== "string" ||
|
|
273
|
+
typeof record.subject_instance_id !== "string" ||
|
|
274
|
+
typeof record.event_id !== "string" ||
|
|
275
|
+
typeof record.event_row !== "string"
|
|
276
|
+
) {
|
|
277
|
+
throw new Error("authority transaction values are invalid");
|
|
278
|
+
}
|
|
279
|
+
assertTransactionId(record.transaction_id);
|
|
280
|
+
if (
|
|
281
|
+
!SHA256_PATTERN.test(record.expected_prior_state_digest) ||
|
|
282
|
+
!SHA256_PATTERN.test(record.desired_state_digest) ||
|
|
283
|
+
!INSTANCE_PATTERN.test(record.actor_instance_id) ||
|
|
284
|
+
!INSTANCE_PATTERN.test(record.subject_instance_id)
|
|
285
|
+
) {
|
|
286
|
+
throw new Error("authority transaction authority fields are invalid");
|
|
287
|
+
}
|
|
288
|
+
const mutation = validateMutation(record.mutation);
|
|
289
|
+
let event: unknown;
|
|
290
|
+
try {
|
|
291
|
+
event = JSON.parse(record.event_row);
|
|
292
|
+
} catch {
|
|
293
|
+
throw new Error("authority transaction event row is malformed");
|
|
294
|
+
}
|
|
295
|
+
assertEventV3(event);
|
|
296
|
+
if (record.event_id !== event.event_id || `${canonicalJsonV3(event)}\n` !== record.event_row) {
|
|
297
|
+
throw new Error("authority transaction event row is not canonical or mismatched");
|
|
298
|
+
}
|
|
299
|
+
const transaction = { ...(record as unknown as AuthorityTransactionV3), mutation };
|
|
300
|
+
validateTransactionBinding(transaction, event);
|
|
301
|
+
return transaction;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function validateMutation(value: unknown): AuthorityMutationV3 {
|
|
305
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
306
|
+
throw new Error("authority mutation is invalid");
|
|
307
|
+
}
|
|
308
|
+
const mutation = value as Record<string, unknown>;
|
|
309
|
+
if (mutation.kind === "task.transition") {
|
|
310
|
+
const allowed =
|
|
311
|
+
mutation.task_fingerprint === undefined ? "kind\0state" : "kind\0state\0task_fingerprint";
|
|
312
|
+
if (
|
|
313
|
+
Object.keys(mutation).sort().join("\0") !== allowed ||
|
|
314
|
+
!["set", "cleared"].includes(String(mutation.state)) ||
|
|
315
|
+
(mutation.state === "set" &&
|
|
316
|
+
(typeof mutation.task_fingerprint !== "string" ||
|
|
317
|
+
!SHA256_PATTERN.test(mutation.task_fingerprint))) ||
|
|
318
|
+
(mutation.state === "cleared" && mutation.task_fingerprint !== undefined)
|
|
319
|
+
) {
|
|
320
|
+
throw new Error("authority task mutation is invalid");
|
|
321
|
+
}
|
|
322
|
+
} else if (mutation.kind === "lifecycle.transition") {
|
|
323
|
+
const allowed = mutation.reason_code === undefined ? "kind\0state" : "kind\0reason_code\0state";
|
|
324
|
+
if (
|
|
325
|
+
Object.keys(mutation).sort().join("\0") !== allowed ||
|
|
326
|
+
!["active", "blocked", "done"].includes(String(mutation.state)) ||
|
|
327
|
+
(mutation.reason_code !== undefined &&
|
|
328
|
+
(typeof mutation.reason_code !== "string" || !REASON_PATTERN.test(mutation.reason_code)))
|
|
329
|
+
) {
|
|
330
|
+
throw new Error("authority lifecycle mutation is invalid");
|
|
331
|
+
}
|
|
332
|
+
} else if (mutation.kind === "claim.transition") {
|
|
333
|
+
if (
|
|
334
|
+
Object.keys(mutation).sort().join("\0") !== "access\0kind\0operation\0target_fingerprint" ||
|
|
335
|
+
!["read", "write"].includes(String(mutation.access)) ||
|
|
336
|
+
!["acquired", "released"].includes(String(mutation.operation)) ||
|
|
337
|
+
typeof mutation.target_fingerprint !== "string" ||
|
|
338
|
+
!SHA256_PATTERN.test(mutation.target_fingerprint)
|
|
339
|
+
) {
|
|
340
|
+
throw new Error("authority claim mutation is invalid");
|
|
341
|
+
}
|
|
342
|
+
} else if (mutation.kind === "identity.assume") {
|
|
343
|
+
if (
|
|
344
|
+
Object.keys(mutation).sort().join("\0") !== "identity_id\0kind" ||
|
|
345
|
+
typeof mutation.identity_id !== "string" ||
|
|
346
|
+
!SAFE_ID_PATTERN.test(mutation.identity_id)
|
|
347
|
+
) {
|
|
348
|
+
throw new Error("authority identity mutation is invalid");
|
|
349
|
+
}
|
|
350
|
+
} else if (mutation.kind === "decision.resolve") {
|
|
351
|
+
if (
|
|
352
|
+
Object.keys(mutation).sort().join("\0") !== "decision_id\0kind\0outcome" ||
|
|
353
|
+
typeof mutation.decision_id !== "string" ||
|
|
354
|
+
!SAFE_ID_PATTERN.test(mutation.decision_id) ||
|
|
355
|
+
!["approved", "denied", "deferred"].includes(String(mutation.outcome))
|
|
356
|
+
) {
|
|
357
|
+
throw new Error("authority decision mutation is invalid");
|
|
358
|
+
}
|
|
359
|
+
} else if (mutation.kind === "wait.start") {
|
|
360
|
+
if (
|
|
361
|
+
Object.keys(mutation).sort().join("\0") !== "kind\0wait_id\0wait_kind" ||
|
|
362
|
+
typeof mutation.wait_id !== "string" ||
|
|
363
|
+
!SAFE_ID_PATTERN.test(mutation.wait_id) ||
|
|
364
|
+
!["permission", "approval", "decision", "operator_input", "dependency", "scheduled"].includes(
|
|
365
|
+
String(mutation.wait_kind),
|
|
366
|
+
)
|
|
367
|
+
) {
|
|
368
|
+
throw new Error("authority wait-start mutation is invalid");
|
|
369
|
+
}
|
|
370
|
+
} else if (mutation.kind === "wait.end") {
|
|
371
|
+
if (
|
|
372
|
+
Object.keys(mutation).sort().join("\0") !== "kind\0outcome\0wait_id" ||
|
|
373
|
+
typeof mutation.wait_id !== "string" ||
|
|
374
|
+
!SAFE_ID_PATTERN.test(mutation.wait_id) ||
|
|
375
|
+
![
|
|
376
|
+
"succeeded",
|
|
377
|
+
"failed",
|
|
378
|
+
"cancelled",
|
|
379
|
+
"timed_out",
|
|
380
|
+
"denied",
|
|
381
|
+
"interrupted",
|
|
382
|
+
"unknown",
|
|
383
|
+
].includes(String(mutation.outcome))
|
|
384
|
+
) {
|
|
385
|
+
throw new Error("authority wait-end mutation is invalid");
|
|
386
|
+
}
|
|
387
|
+
} else {
|
|
388
|
+
throw new Error("authority mutation kind is unsupported");
|
|
389
|
+
}
|
|
390
|
+
return mutation as unknown as AuthorityMutationV3;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function validateTransactionBinding(transaction: AuthorityTransactionV3, event: EventV3): void {
|
|
394
|
+
if (
|
|
395
|
+
event.scope.instance_id !== transaction.actor_instance_id ||
|
|
396
|
+
event.provenance.attribution.state !== "verified" ||
|
|
397
|
+
event.provenance.attribution.observer_instance_id !== transaction.actor_instance_id ||
|
|
398
|
+
event.provenance.attribution.subject_instance_id !== transaction.subject_instance_id
|
|
399
|
+
) {
|
|
400
|
+
throw new Error("authority transaction attribution does not match its event");
|
|
401
|
+
}
|
|
402
|
+
const mutation = transaction.mutation;
|
|
403
|
+
if (mutation.kind === "task.transition") {
|
|
404
|
+
if (
|
|
405
|
+
event.event_type !== "coord.task_changed" ||
|
|
406
|
+
event.payload.actor_instance_id !== transaction.actor_instance_id ||
|
|
407
|
+
event.payload.subject_instance_id !== transaction.subject_instance_id ||
|
|
408
|
+
event.payload.authority.transaction_id !== transaction.transaction_id ||
|
|
409
|
+
event.payload.new_state !== mutation.state ||
|
|
410
|
+
event.payload.reason_fingerprint?.digest !== mutation.task_fingerprint
|
|
411
|
+
) {
|
|
412
|
+
throw new Error("authority task transaction does not match its event");
|
|
413
|
+
}
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
if (mutation.kind === "lifecycle.transition") {
|
|
417
|
+
if (
|
|
418
|
+
event.event_type !== "coord.lifecycle_changed" ||
|
|
419
|
+
event.payload.actor_instance_id !== transaction.actor_instance_id ||
|
|
420
|
+
event.payload.subject_instance_id !== transaction.subject_instance_id ||
|
|
421
|
+
event.payload.authority.transaction_id !== transaction.transaction_id ||
|
|
422
|
+
event.payload.new_state !== mutation.state ||
|
|
423
|
+
event.payload.reason !== (mutation.reason_code ?? "lifecycle_transition")
|
|
424
|
+
) {
|
|
425
|
+
throw new Error("authority lifecycle transaction does not match its event");
|
|
426
|
+
}
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
if (mutation.kind === "claim.transition") {
|
|
430
|
+
const operation = mutation.operation;
|
|
431
|
+
if (
|
|
432
|
+
event.event_type !== "coord.claim_changed" ||
|
|
433
|
+
event.payload.actor_instance_id !== transaction.actor_instance_id ||
|
|
434
|
+
event.payload.subject_instance_id !== transaction.subject_instance_id ||
|
|
435
|
+
event.payload.authority.transaction_id !== transaction.transaction_id ||
|
|
436
|
+
event.payload.operation !== operation ||
|
|
437
|
+
event.payload.target.fingerprint.digest !== mutation.target_fingerprint ||
|
|
438
|
+
event.payload.access !== mutation.access
|
|
439
|
+
) {
|
|
440
|
+
throw new Error("authority claim transaction does not match its event");
|
|
441
|
+
}
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
if (mutation.kind === "identity.assume") {
|
|
445
|
+
if (
|
|
446
|
+
event.event_type !== "coord.identity_attested" ||
|
|
447
|
+
event.payload.actor_instance_id !== transaction.actor_instance_id ||
|
|
448
|
+
event.payload.subject_instance_id !== transaction.subject_instance_id ||
|
|
449
|
+
event.payload.authority.transaction_id !== transaction.transaction_id ||
|
|
450
|
+
event.payload.identity_id !== mutation.identity_id
|
|
451
|
+
) {
|
|
452
|
+
throw new Error("authority identity transaction does not match its event");
|
|
453
|
+
}
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (mutation.kind === "decision.resolve") {
|
|
457
|
+
if (
|
|
458
|
+
event.event_type !== "decision.state_changed" ||
|
|
459
|
+
event.payload.authority.transaction_id !== transaction.transaction_id ||
|
|
460
|
+
event.payload.decision_id !== mutation.decision_id ||
|
|
461
|
+
event.payload.new_state !== mutation.outcome
|
|
462
|
+
) {
|
|
463
|
+
throw new Error("authority decision transaction does not match its event");
|
|
464
|
+
}
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
if (mutation.kind === "wait.start") {
|
|
468
|
+
if (
|
|
469
|
+
event.event_type !== "wait.started" ||
|
|
470
|
+
event.payload.authority_reference !== transaction.transaction_id ||
|
|
471
|
+
event.payload.wait_id !== mutation.wait_id ||
|
|
472
|
+
event.payload.kind !== mutation.wait_kind
|
|
473
|
+
) {
|
|
474
|
+
throw new Error("authority wait-start transaction does not match its event");
|
|
475
|
+
}
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
if (mutation.kind !== "wait.end") {
|
|
479
|
+
throw new Error("authority transaction mutation binding is unsupported");
|
|
480
|
+
}
|
|
481
|
+
if (
|
|
482
|
+
event.event_type !== "wait.ended" ||
|
|
483
|
+
event.payload.resolution_reference !== transaction.transaction_id ||
|
|
484
|
+
event.payload.wait_id !== mutation.wait_id ||
|
|
485
|
+
event.payload.outcome !== mutation.outcome
|
|
486
|
+
) {
|
|
487
|
+
throw new Error("authority wait-end transaction does not match its event");
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
function validateReceipt(value: unknown): AuthorityReceiptV3 {
|
|
492
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
493
|
+
throw new Error("authority receipt is invalid");
|
|
494
|
+
}
|
|
495
|
+
const receipt = value as Record<string, unknown>;
|
|
496
|
+
if (
|
|
497
|
+
Object.keys(receipt).sort().join("\0") !==
|
|
498
|
+
"committed_at\0desired_state_digest\0event_id\0event_row_digest\0format\0format_version\0transaction_digest\0transaction_id" ||
|
|
499
|
+
receipt.format !== "harnery-event-v3-authority-receipt" ||
|
|
500
|
+
receipt.format_version !== 1 ||
|
|
501
|
+
typeof receipt.transaction_id !== "string" ||
|
|
502
|
+
typeof receipt.transaction_digest !== "string" ||
|
|
503
|
+
typeof receipt.desired_state_digest !== "string" ||
|
|
504
|
+
typeof receipt.event_id !== "string" ||
|
|
505
|
+
typeof receipt.event_row_digest !== "string" ||
|
|
506
|
+
typeof receipt.committed_at !== "string" ||
|
|
507
|
+
!SHA256_PATTERN.test(receipt.transaction_digest) ||
|
|
508
|
+
!SHA256_PATTERN.test(receipt.desired_state_digest) ||
|
|
509
|
+
!SHA256_PATTERN.test(receipt.event_row_digest) ||
|
|
510
|
+
Number.isNaN(Date.parse(receipt.committed_at))
|
|
511
|
+
) {
|
|
512
|
+
throw new Error("authority receipt values are invalid");
|
|
513
|
+
}
|
|
514
|
+
assertTransactionId(receipt.transaction_id);
|
|
515
|
+
return receipt as unknown as AuthorityReceiptV3;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
function publishExclusive(path: string, serialized: string): void {
|
|
519
|
+
const temporary = `${path}.tmp-${process.pid}-${randomUUID()}`;
|
|
520
|
+
let fd: number | undefined;
|
|
521
|
+
try {
|
|
522
|
+
fd = openSync(temporary, "wx", 0o600);
|
|
523
|
+
writeFileSync(fd, serialized, "utf8");
|
|
524
|
+
fsyncSync(fd);
|
|
525
|
+
closeSync(fd);
|
|
526
|
+
fd = undefined;
|
|
527
|
+
linkSync(temporary, path);
|
|
528
|
+
fsyncParentDirectory(path);
|
|
529
|
+
unlinkSync(temporary);
|
|
530
|
+
} finally {
|
|
531
|
+
if (fd !== undefined) closeSync(fd);
|
|
532
|
+
if (existsSync(temporary)) unlinkSync(temporary);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
function authorityReadyPath(outbox: string, transactionId: string): string {
|
|
537
|
+
assertTransactionId(transactionId);
|
|
538
|
+
return join(outbox, `${transactionId}.ready.json`);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
function authorityCommittedPath(outbox: string, transactionId: string): string {
|
|
542
|
+
assertTransactionId(transactionId);
|
|
543
|
+
return join(outbox, `${transactionId}.committed.json`);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
function assertTransactionId(value: string): void {
|
|
547
|
+
if (!TX_PATTERN.test(value)) throw new Error("authority transaction ID is invalid");
|
|
548
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { EventOfTypeV3Base, EventPayloadV3Base, EventTypeV3Base } from "./base-contract.ts";
|
|
2
|
+
import { EVENT_V3_BASE_CONTRACT_MAJOR, EVENT_V3_BASE_CONTRACT_NAME } from "./base-contract.ts";
|
|
3
|
+
import { EVENT_V3_SCHEMA_DIGEST } from "./generated.ts";
|
|
4
|
+
import { clockIdV3, eventIdV3 } from "./ids.ts";
|
|
5
|
+
|
|
6
|
+
type EventWithoutDiscriminator<T extends EventTypeV3Base> = Omit<
|
|
7
|
+
EventOfTypeV3Base<T>,
|
|
8
|
+
"attestation_id" | "contract" | "event_id" | "event_type" | "payload" | "time"
|
|
9
|
+
>;
|
|
10
|
+
|
|
11
|
+
type RootEventTypeV3Base =
|
|
12
|
+
| "ledger.genesis"
|
|
13
|
+
| "ledger.activated"
|
|
14
|
+
| "ledger.schema_advanced"
|
|
15
|
+
| "ledger.comparability_advanced";
|
|
16
|
+
|
|
17
|
+
type AttestationInputV3Base<T extends EventTypeV3Base> = T extends RootEventTypeV3Base
|
|
18
|
+
? { attestation_id?: never }
|
|
19
|
+
: { attestation_id: `att_${string}` };
|
|
20
|
+
|
|
21
|
+
export type BuildEventV3BaseInput<T extends EventTypeV3Base> = EventWithoutDiscriminator<T> &
|
|
22
|
+
AttestationInputV3Base<T> & {
|
|
23
|
+
payload: EventPayloadV3Base<T>;
|
|
24
|
+
event_id?: `evt_${string}`;
|
|
25
|
+
observed_at?: string;
|
|
26
|
+
recorded_at?: string;
|
|
27
|
+
monotonic_ns?: string;
|
|
28
|
+
clock_id?: `clk_${string}`;
|
|
29
|
+
skew?: "normal" | "regressed" | "unknown";
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export function buildEventV3Base<T extends EventTypeV3Base>(
|
|
33
|
+
eventType: T,
|
|
34
|
+
input: BuildEventV3BaseInput<T>,
|
|
35
|
+
): EventOfTypeV3Base<T> {
|
|
36
|
+
const now = input.recorded_at ?? new Date().toISOString();
|
|
37
|
+
const event = {
|
|
38
|
+
contract: {
|
|
39
|
+
name: EVENT_V3_BASE_CONTRACT_NAME,
|
|
40
|
+
major: EVENT_V3_BASE_CONTRACT_MAJOR,
|
|
41
|
+
schema_digest: EVENT_V3_SCHEMA_DIGEST,
|
|
42
|
+
},
|
|
43
|
+
event_id: input.event_id ?? eventIdV3(),
|
|
44
|
+
event_type: eventType,
|
|
45
|
+
time: {
|
|
46
|
+
observed_at: input.observed_at ?? now,
|
|
47
|
+
recorded_at: now,
|
|
48
|
+
...(input.monotonic_ns ? { monotonic_ns: input.monotonic_ns } : {}),
|
|
49
|
+
clock_id: input.clock_id ?? clockIdV3(),
|
|
50
|
+
skew: input.skew ?? "unknown",
|
|
51
|
+
},
|
|
52
|
+
producer: input.producer,
|
|
53
|
+
scope: input.scope,
|
|
54
|
+
...(input.attestation_id ? { attestation_id: input.attestation_id } : {}),
|
|
55
|
+
links: input.links,
|
|
56
|
+
provenance: input.provenance,
|
|
57
|
+
payload: input.payload,
|
|
58
|
+
};
|
|
59
|
+
return event as unknown as EventOfTypeV3Base<T>;
|
|
60
|
+
}
|