harnery 0.32.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/README.md +2 -0
- package/dist/commander.d.ts.map +1 -1
- package/dist/commander.js +7 -1
- 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 +1408 -565
- 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 +2 -2
- package/dist/commands/claude-desktop.d.ts.map +1 -1
- package/dist/commands/claude-desktop.js +2 -2
- 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.d.ts +4 -2
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +55 -7
- 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 +10 -2
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +233 -51
- package/dist/commands/instructions.d.ts +4 -0
- package/dist/commands/instructions.d.ts.map +1 -0
- package/dist/commands/instructions.js +100 -0
- 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 +15 -6
- 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 +27 -25
- package/dist/core/agents/cli.js +212 -235
- 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 -70
- 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 +5 -5
- package/dist/core/agents/index.d.ts.map +1 -1
- package/dist/core/agents/index.js +5 -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 +10 -4
- package/dist/core/agents/render/prompt-context.d.ts.map +1 -1
- package/dist/core/agents/render/prompt-context.js +61 -55
- 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 +15 -33
- 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 +29 -46
- package/dist/core/agents/state/heartbeat-writer.d.ts.map +1 -1
- package/dist/core/agents/state/heartbeat-writer.js +59 -199
- 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 +45 -0
- package/dist/core/agents/state/session-state.d.ts.map +1 -0
- package/dist/core/agents/state/session-state.js +90 -0
- 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 +13 -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 +64 -24
- 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 +345 -400
- package/dist/core/hooks/codex-authorization.d.ts +30 -0
- package/dist/core/hooks/codex-authorization.d.ts.map +1 -0
- package/dist/core/hooks/codex-authorization.js +199 -0
- 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 +8 -3
- package/dist/core/presence/blob.d.ts.map +1 -1
- package/dist/core/presence/blob.js +54 -41
- 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/index.js +15 -1
- 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/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 +33 -0
- package/dist/lib/instructions/bundle.d.ts.map +1 -0
- package/dist/lib/instructions/bundle.js +149 -0
- 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 +27 -6
- 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 +7 -1
- package/src/commands/adapter.ts +2 -2
- package/src/commands/agents.ts +1737 -570
- 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 +7 -5
- 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 +73 -8
- package/src/commands/events.ts +256 -0
- package/src/commands/governor.ts +18 -4
- package/src/commands/init.ts +264 -57
- package/src/commands/instructions.ts +129 -0
- package/src/commands/journal.ts +4 -13
- package/src/commands/ledger-v3.ts +111 -0
- package/src/commands/presence.ts +18 -11
- 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 +39 -28
- package/src/core/agents/cli.ts +242 -263
- package/src/core/agents/codex-archive-v3.ts +138 -0
- package/src/core/agents/coord-client.ts +75 -177
- package/src/core/agents/finalization.ts +120 -38
- package/src/core/agents/index.ts +5 -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 +89 -55
- package/src/core/agents/render/session-context.ts +23 -32
- 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 +98 -242
- package/src/core/agents/state/live-coordination-view.ts +290 -0
- package/src/core/agents/state/session-state.ts +143 -0
- 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 +15 -6
- package/src/core/hooks/adapter/output.ts +7 -2
- package/src/core/hooks/adapter/parse.ts +81 -36
- package/src/core/hooks/adapter/wiring.ts +119 -13
- package/src/core/hooks/cli.ts +398 -422
- package/src/core/hooks/codex-authorization.ts +253 -0
- 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 +63 -38
- package/src/core/presence/codec-digest.ts +215 -0
- package/src/core/presence/index.ts +18 -1
- 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/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 +199 -0
- 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 -65
- package/dist/core/agents/state/heartbeat-projector.d.ts.map +0 -1
- package/dist/core/agents/state/heartbeat-projector.js +0 -527
- 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 -312
- 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 -582
- 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 -538
- package/src/core/hooks/events/ulid.ts +0 -51
- package/src/lib/docs-frontmatter-migrate.ts +0 -427
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import type { EventV3, RuntimeAttestationV3 } from "./contract.ts";
|
|
2
|
+
import {
|
|
3
|
+
EVENT_V3_SAFETY_REDUCER_BUILD,
|
|
4
|
+
type GenerationSafetyStateV3,
|
|
5
|
+
reduceSafetyProjectionV3,
|
|
6
|
+
type SafetyProjectionDiagnosticV3,
|
|
7
|
+
type SafetyProjectionV3,
|
|
8
|
+
type WaitProjectionV3,
|
|
9
|
+
} from "./projection.ts";
|
|
10
|
+
import { type ReadLedgerV3Result, readLedgerV3 } from "./reader.ts";
|
|
11
|
+
|
|
12
|
+
export const EVENT_V3_COORDINATION_VIEW_VERSION = 1 as const;
|
|
13
|
+
|
|
14
|
+
export interface CoordinationGenerationViewV3 {
|
|
15
|
+
contract_major: 2;
|
|
16
|
+
instance_id: string;
|
|
17
|
+
session_id: string;
|
|
18
|
+
generation_id: string;
|
|
19
|
+
root_id: string;
|
|
20
|
+
run_id?: string;
|
|
21
|
+
workflow_id?: string;
|
|
22
|
+
workflow_agent_id?: string;
|
|
23
|
+
identity_id?: string;
|
|
24
|
+
runtime_attestation: RuntimeAttestationV3;
|
|
25
|
+
parent_generation_id?: string;
|
|
26
|
+
delegation_id?: string;
|
|
27
|
+
delegation_role?: string;
|
|
28
|
+
phase: "live" | "terminal";
|
|
29
|
+
activity: "working" | "needs_input" | "idle" | "terminal";
|
|
30
|
+
task_state?: string;
|
|
31
|
+
task_state_updated_at?: string;
|
|
32
|
+
lifecycle_state?: string;
|
|
33
|
+
lifecycle_state_updated_at?: string;
|
|
34
|
+
presence_state?: string;
|
|
35
|
+
presence_state_updated_at?: string;
|
|
36
|
+
started_at: string;
|
|
37
|
+
last_observed_at: string;
|
|
38
|
+
last_event_id: string;
|
|
39
|
+
source_position: { segment_ordinal: number; byte_offset: number };
|
|
40
|
+
waits: WaitProjectionV3[];
|
|
41
|
+
files_touched: string[];
|
|
42
|
+
progress_count: number;
|
|
43
|
+
last_context_event_id?: string;
|
|
44
|
+
provisional_termination?: GenerationSafetyStateV3["provisional_termination"];
|
|
45
|
+
terminal?: GenerationSafetyStateV3["terminal"];
|
|
46
|
+
evidence_complete: boolean;
|
|
47
|
+
authority_eligible: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface CoordinationViewV3 {
|
|
51
|
+
projection_version: typeof EVENT_V3_COORDINATION_VIEW_VERSION;
|
|
52
|
+
contract_major: 2;
|
|
53
|
+
reducer_build_id: typeof EVENT_V3_SAFETY_REDUCER_BUILD;
|
|
54
|
+
source_complete: boolean;
|
|
55
|
+
authority_safe: boolean;
|
|
56
|
+
diagnostics: SafetyProjectionDiagnosticV3[];
|
|
57
|
+
instances: Record<string, CoordinationGenerationViewV3>;
|
|
58
|
+
terminal_generations: Record<string, CoordinationGenerationViewV3>;
|
|
59
|
+
delegations: SafetyProjectionV3["delegations"];
|
|
60
|
+
decisions: SafetyProjectionV3["decisions"];
|
|
61
|
+
health: SafetyProjectionV3["health"];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export class CoordinationViewV3Error extends Error {
|
|
65
|
+
constructor(public readonly diagnostics: SafetyProjectionDiagnosticV3[]) {
|
|
66
|
+
super("event_v3_coordination_view:authority_unsafe");
|
|
67
|
+
this.name = "CoordinationViewV3Error";
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Read the complete V3 catalog and derive the disposable coordination view. */
|
|
72
|
+
export function readCoordinationViewV3(coordRoot: string): CoordinationViewV3 {
|
|
73
|
+
return projectCoordinationViewV3(readLedgerV3(coordRoot));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Build the one privacy-safe lifecycle view shared by heartbeat, status,
|
|
78
|
+
* finalization, web, and Codec adapters. This function performs no writes.
|
|
79
|
+
*/
|
|
80
|
+
export function projectCoordinationViewV3(read: ReadLedgerV3Result): CoordinationViewV3 {
|
|
81
|
+
const safety = reduceSafetyProjectionV3(read);
|
|
82
|
+
const starts = new Map<string, Extract<EventV3, { event_type: "session.started" }>>();
|
|
83
|
+
const eventGeneration = new Map<string, string>();
|
|
84
|
+
for (const { event } of read.events) {
|
|
85
|
+
const generationId = "generation_id" in event.scope ? event.scope.generation_id : undefined;
|
|
86
|
+
if (generationId !== undefined) {
|
|
87
|
+
eventGeneration.set(event.event_id, generationId);
|
|
88
|
+
}
|
|
89
|
+
if (event.event_type === "session.started" && generationId !== undefined) {
|
|
90
|
+
starts.set(generationId, event as Extract<EventV3, { event_type: "session.started" }>);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const instances: Record<string, CoordinationGenerationViewV3> = {};
|
|
95
|
+
const terminalGenerations: Record<string, CoordinationGenerationViewV3> = {};
|
|
96
|
+
const states = Object.values(safety.generations).sort((left, right) =>
|
|
97
|
+
left.generation_id.localeCompare(right.generation_id),
|
|
98
|
+
);
|
|
99
|
+
for (const state of states) {
|
|
100
|
+
const started = starts.get(state.generation_id);
|
|
101
|
+
if (!started) continue;
|
|
102
|
+
const diagnostics = safety.diagnostics.filter(
|
|
103
|
+
(diagnostic) =>
|
|
104
|
+
diagnostic.generation_id === state.generation_id ||
|
|
105
|
+
diagnostic.subject_instance_id === state.instance_id ||
|
|
106
|
+
(diagnostic.event_id !== undefined &&
|
|
107
|
+
eventGeneration.get(diagnostic.event_id) === state.generation_id) ||
|
|
108
|
+
diagnostic.code === "ledger_incomplete",
|
|
109
|
+
);
|
|
110
|
+
const delegation = Object.values(safety.delegations).find(
|
|
111
|
+
(candidate) => candidate.child_generation_id === state.generation_id,
|
|
112
|
+
);
|
|
113
|
+
const filesTouched = Object.values(safety.claims)
|
|
114
|
+
.filter(
|
|
115
|
+
(claim) =>
|
|
116
|
+
claim.subject_instance_id === state.instance_id &&
|
|
117
|
+
claim.access === "write" &&
|
|
118
|
+
claim.target_kind === "workspace_path" &&
|
|
119
|
+
claim.target_display !== undefined,
|
|
120
|
+
)
|
|
121
|
+
.map((claim) => claim.target_display!)
|
|
122
|
+
.filter((path, index, all) => all.indexOf(path) === index)
|
|
123
|
+
.sort();
|
|
124
|
+
const view: CoordinationGenerationViewV3 = {
|
|
125
|
+
contract_major: 2,
|
|
126
|
+
instance_id: state.instance_id,
|
|
127
|
+
session_id: state.session_id,
|
|
128
|
+
generation_id: state.generation_id,
|
|
129
|
+
root_id: started.scope.root_id,
|
|
130
|
+
run_id: started.scope.run_id,
|
|
131
|
+
workflow_id: started.scope.workflow_id,
|
|
132
|
+
workflow_agent_id: started.scope.workflow_agent_id,
|
|
133
|
+
identity_id: safety.identities[state.instance_id],
|
|
134
|
+
runtime_attestation: started.payload.runtime_attestation,
|
|
135
|
+
parent_generation_id: (started.links as { parent_generation_id?: string })
|
|
136
|
+
.parent_generation_id,
|
|
137
|
+
delegation_id: delegation?.delegation_id,
|
|
138
|
+
delegation_role: delegation?.role,
|
|
139
|
+
phase: state.phase,
|
|
140
|
+
activity: state.activity,
|
|
141
|
+
task_state: state.task_state,
|
|
142
|
+
task_state_updated_at: state.task_state_updated_at,
|
|
143
|
+
lifecycle_state: state.lifecycle_state,
|
|
144
|
+
lifecycle_state_updated_at: state.lifecycle_state_updated_at,
|
|
145
|
+
presence_state: state.presence_state,
|
|
146
|
+
presence_state_updated_at: state.presence_state_updated_at,
|
|
147
|
+
started_at: state.started_at,
|
|
148
|
+
last_observed_at: state.last_observed_at,
|
|
149
|
+
last_event_id: state.last_event_id,
|
|
150
|
+
source_position: {
|
|
151
|
+
segment_ordinal: state.last_segment_ordinal,
|
|
152
|
+
byte_offset: state.last_byte_offset,
|
|
153
|
+
},
|
|
154
|
+
waits: Object.values(state.waits).sort((left, right) =>
|
|
155
|
+
left.started_event_id.localeCompare(right.started_event_id),
|
|
156
|
+
),
|
|
157
|
+
files_touched: state.phase === "live" ? filesTouched : [],
|
|
158
|
+
progress_count: state.progress_event_ids.length,
|
|
159
|
+
last_context_event_id: state.last_context_event_id,
|
|
160
|
+
provisional_termination: state.provisional_termination,
|
|
161
|
+
terminal: state.terminal,
|
|
162
|
+
evidence_complete: safety.evidence_complete && diagnostics.length === 0,
|
|
163
|
+
authority_eligible: safety.authority_safe && state.phase === "live",
|
|
164
|
+
};
|
|
165
|
+
if (state.phase === "terminal") {
|
|
166
|
+
terminalGenerations[state.generation_id] = view;
|
|
167
|
+
} else if (safety.current_generation_by_instance[state.instance_id] === state.generation_id) {
|
|
168
|
+
instances[state.instance_id] = view;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return {
|
|
173
|
+
projection_version: EVENT_V3_COORDINATION_VIEW_VERSION,
|
|
174
|
+
contract_major: 2,
|
|
175
|
+
reducer_build_id: EVENT_V3_SAFETY_REDUCER_BUILD,
|
|
176
|
+
source_complete: read.complete,
|
|
177
|
+
authority_safe: safety.authority_safe,
|
|
178
|
+
diagnostics: safety.diagnostics,
|
|
179
|
+
instances,
|
|
180
|
+
terminal_generations: terminalGenerations,
|
|
181
|
+
delegations: safety.delegations,
|
|
182
|
+
decisions: safety.decisions,
|
|
183
|
+
health: safety.health,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Refuse authority decisions while still allowing callers to render diagnostics. */
|
|
188
|
+
export function requireAuthoritySafeCoordinationViewV3(
|
|
189
|
+
view: CoordinationViewV3,
|
|
190
|
+
): CoordinationViewV3 {
|
|
191
|
+
if (!view.authority_safe) throw new CoordinationViewV3Error(view.diagnostics);
|
|
192
|
+
return view;
|
|
193
|
+
}
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import type { LatencyMetricV3 } from "./latency.ts";
|
|
2
|
+
import type { ReadLedgerV3Result } from "./reader.ts";
|
|
3
|
+
|
|
4
|
+
export const EVENT_V3_ECONOMICS_PROJECTION_VERSION = "event-v3-economics-v1" as const;
|
|
5
|
+
|
|
6
|
+
export interface TokenTotalsV3 {
|
|
7
|
+
input_tokens: number;
|
|
8
|
+
output_tokens: number;
|
|
9
|
+
cache_read_tokens: number;
|
|
10
|
+
cache_write_tokens: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type TokenTotalsMetricV3 =
|
|
14
|
+
| { state: "observed"; value: TokenTotalsV3 }
|
|
15
|
+
| { state: "unknown"; known: TokenTotalsV3; reasons: string[] };
|
|
16
|
+
|
|
17
|
+
export type CostMetricV3 =
|
|
18
|
+
| { state: "observed"; usd: number; pricing_key: string }
|
|
19
|
+
| { state: "unknown"; known_usd: number; reasons: string[] };
|
|
20
|
+
|
|
21
|
+
export interface ModelPricingV3 {
|
|
22
|
+
input_usd_per_million: number;
|
|
23
|
+
output_usd_per_million: number;
|
|
24
|
+
cache_read_usd_per_million?: number;
|
|
25
|
+
cache_write_usd_per_million?: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface EconomicsProjectionOptionsV3 {
|
|
29
|
+
pricing?: Record<string, ModelPricingV3>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface TurnEconomicsV3 {
|
|
33
|
+
generation_id: string;
|
|
34
|
+
turn_id: string;
|
|
35
|
+
terminal_event_id: string;
|
|
36
|
+
model_key: string | null;
|
|
37
|
+
usage_method: string | null;
|
|
38
|
+
tokens: TokenTotalsMetricV3;
|
|
39
|
+
inference_ms: LatencyMetricV3;
|
|
40
|
+
harness_ms: LatencyMetricV3;
|
|
41
|
+
slowest_hook: string | null;
|
|
42
|
+
slowest_hook_ms: number | null;
|
|
43
|
+
cost: CostMetricV3;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface GenerationEconomicsV3 {
|
|
47
|
+
generation_id: string;
|
|
48
|
+
turn_count: number;
|
|
49
|
+
tokens: TokenTotalsMetricV3;
|
|
50
|
+
inference_ms: LatencyMetricV3;
|
|
51
|
+
harness_ms: LatencyMetricV3;
|
|
52
|
+
cost: CostMetricV3;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface EconomicsProjectionV3 {
|
|
56
|
+
projection_version: typeof EVENT_V3_ECONOMICS_PROJECTION_VERSION;
|
|
57
|
+
turns: TurnEconomicsV3[];
|
|
58
|
+
generations: GenerationEconomicsV3[];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type DelegationRollupDiagnosticCodeV3 = "delegation_cycle" | "generation_economics_missing";
|
|
62
|
+
|
|
63
|
+
export interface DelegationRollupV3 {
|
|
64
|
+
root_generation_id: string;
|
|
65
|
+
generation_ids: string[];
|
|
66
|
+
tokens: TokenTotalsMetricV3;
|
|
67
|
+
inference_ms: LatencyMetricV3;
|
|
68
|
+
harness_ms: LatencyMetricV3;
|
|
69
|
+
cost: CostMetricV3;
|
|
70
|
+
diagnostics: Array<{
|
|
71
|
+
code: DelegationRollupDiagnosticCodeV3;
|
|
72
|
+
generation_id: string;
|
|
73
|
+
}>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface EventShape {
|
|
77
|
+
event_id: string;
|
|
78
|
+
event_type: string;
|
|
79
|
+
scope: { generation_id?: string; turn_id?: string };
|
|
80
|
+
payload: Record<string, unknown>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function projectEconomicsV3(
|
|
84
|
+
read: ReadLedgerV3Result,
|
|
85
|
+
options: EconomicsProjectionOptionsV3 = {},
|
|
86
|
+
): EconomicsProjectionV3 {
|
|
87
|
+
if (!read.complete) throw new Error("economics projection requires a complete V3 ledger read");
|
|
88
|
+
const models = new Map<string, string | null>();
|
|
89
|
+
const turns: TurnEconomicsV3[] = [];
|
|
90
|
+
for (const positioned of read.events) {
|
|
91
|
+
const event = positioned.event as unknown as EventShape;
|
|
92
|
+
const generationId = event.scope.generation_id;
|
|
93
|
+
if (
|
|
94
|
+
generationId &&
|
|
95
|
+
(event.event_type === "session.started" || event.event_type === "session.attestation_changed")
|
|
96
|
+
) {
|
|
97
|
+
models.set(generationId, modelKey(event.payload.runtime_attestation));
|
|
98
|
+
}
|
|
99
|
+
if (event.event_type !== "turn.completed") continue;
|
|
100
|
+
const tokens = tokensFromObservation(event.payload.usage);
|
|
101
|
+
const model = generationId ? (models.get(generationId) ?? null) : null;
|
|
102
|
+
const slowestHook = slowestHookFromObservation(event.payload.harness);
|
|
103
|
+
turns.push({
|
|
104
|
+
generation_id: generationId ?? "",
|
|
105
|
+
turn_id: event.scope.turn_id ?? "",
|
|
106
|
+
terminal_event_id: event.event_id,
|
|
107
|
+
model_key: model,
|
|
108
|
+
usage_method: usageMethod(event.payload.usage),
|
|
109
|
+
tokens,
|
|
110
|
+
inference_ms: timingFromObservation(
|
|
111
|
+
event.payload.inference,
|
|
112
|
+
"api_time_ms",
|
|
113
|
+
"inference_unknown",
|
|
114
|
+
),
|
|
115
|
+
harness_ms: timingFromObservation(event.payload.harness, "hook_time_ms", "harness_unknown"),
|
|
116
|
+
slowest_hook: slowestHook.name,
|
|
117
|
+
slowest_hook_ms: slowestHook.duration_ms,
|
|
118
|
+
cost: costForTurn(tokens, model, options.pricing),
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
const grouped = new Map<string, TurnEconomicsV3[]>();
|
|
122
|
+
for (const turn of turns) {
|
|
123
|
+
const generationTurns = grouped.get(turn.generation_id) ?? [];
|
|
124
|
+
generationTurns.push(turn);
|
|
125
|
+
grouped.set(turn.generation_id, generationTurns);
|
|
126
|
+
}
|
|
127
|
+
const generations = [...grouped.entries()].map(([generationId, generationTurns]) => ({
|
|
128
|
+
generation_id: generationId,
|
|
129
|
+
turn_count: generationTurns.length,
|
|
130
|
+
tokens: sumTokenMetrics(generationTurns.map(({ tokens }) => tokens)),
|
|
131
|
+
inference_ms: sumTimingMetrics(generationTurns.map(({ inference_ms }) => inference_ms)),
|
|
132
|
+
harness_ms: sumTimingMetrics(generationTurns.map(({ harness_ms }) => harness_ms)),
|
|
133
|
+
cost: sumCostMetrics(generationTurns.map(({ cost }) => cost)),
|
|
134
|
+
}));
|
|
135
|
+
generations.sort((left, right) => left.generation_id.localeCompare(right.generation_id));
|
|
136
|
+
return { projection_version: EVENT_V3_ECONOMICS_PROJECTION_VERSION, turns, generations };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function projectDelegationRollupV3(
|
|
140
|
+
read: ReadLedgerV3Result,
|
|
141
|
+
economics: EconomicsProjectionV3,
|
|
142
|
+
rootGenerationId: string,
|
|
143
|
+
): DelegationRollupV3 {
|
|
144
|
+
if (!read.complete) throw new Error("delegation rollup requires a complete V3 ledger read");
|
|
145
|
+
const children = new Map<string, Set<string>>();
|
|
146
|
+
for (const positioned of read.events) {
|
|
147
|
+
const event = positioned.event as unknown as EventShape;
|
|
148
|
+
if (event.event_type !== "agent.completed") continue;
|
|
149
|
+
const parent = event.scope.generation_id;
|
|
150
|
+
const child = string(event.payload.child_generation_id);
|
|
151
|
+
if (!parent || !child) continue;
|
|
152
|
+
const set = children.get(parent) ?? new Set<string>();
|
|
153
|
+
set.add(child);
|
|
154
|
+
children.set(parent, set);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const generationIds: string[] = [];
|
|
158
|
+
const diagnostics: DelegationRollupV3["diagnostics"] = [];
|
|
159
|
+
const visited = new Set<string>();
|
|
160
|
+
const active = new Set<string>();
|
|
161
|
+
const visit = (generationId: string): void => {
|
|
162
|
+
if (active.has(generationId)) {
|
|
163
|
+
diagnostics.push({ code: "delegation_cycle", generation_id: generationId });
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (visited.has(generationId)) return;
|
|
167
|
+
visited.add(generationId);
|
|
168
|
+
active.add(generationId);
|
|
169
|
+
generationIds.push(generationId);
|
|
170
|
+
for (const child of [...(children.get(generationId) ?? [])].sort()) visit(child);
|
|
171
|
+
active.delete(generationId);
|
|
172
|
+
};
|
|
173
|
+
visit(rootGenerationId);
|
|
174
|
+
|
|
175
|
+
const byGeneration = new Map(
|
|
176
|
+
economics.generations.map((generation) => [generation.generation_id, generation]),
|
|
177
|
+
);
|
|
178
|
+
const included = generationIds.flatMap((generationId) => {
|
|
179
|
+
const generation = byGeneration.get(generationId);
|
|
180
|
+
if (generation) return [generation];
|
|
181
|
+
diagnostics.push({ code: "generation_economics_missing", generation_id: generationId });
|
|
182
|
+
return [];
|
|
183
|
+
});
|
|
184
|
+
const missing = diagnostics
|
|
185
|
+
.filter(({ code }) => code === "generation_economics_missing")
|
|
186
|
+
.map(({ generation_id }) => `generation_economics_missing:${generation_id}`);
|
|
187
|
+
return {
|
|
188
|
+
root_generation_id: rootGenerationId,
|
|
189
|
+
generation_ids: generationIds,
|
|
190
|
+
tokens: sumTokenMetrics([
|
|
191
|
+
...included.map(({ tokens }) => tokens),
|
|
192
|
+
...missing.map((reason) => ({
|
|
193
|
+
state: "unknown" as const,
|
|
194
|
+
known: zeroTokens(),
|
|
195
|
+
reasons: [reason],
|
|
196
|
+
})),
|
|
197
|
+
]),
|
|
198
|
+
inference_ms: sumTimingMetrics([
|
|
199
|
+
...included.map(({ inference_ms }) => inference_ms),
|
|
200
|
+
...missing.map((reason) => ({ state: "unknown" as const, known_ms: 0, reasons: [reason] })),
|
|
201
|
+
]),
|
|
202
|
+
harness_ms: sumTimingMetrics([
|
|
203
|
+
...included.map(({ harness_ms }) => harness_ms),
|
|
204
|
+
...missing.map((reason) => ({ state: "unknown" as const, known_ms: 0, reasons: [reason] })),
|
|
205
|
+
]),
|
|
206
|
+
cost: sumCostMetrics([
|
|
207
|
+
...included.map(({ cost }) => cost),
|
|
208
|
+
...missing.map((reason) => ({ state: "unknown" as const, known_usd: 0, reasons: [reason] })),
|
|
209
|
+
]),
|
|
210
|
+
diagnostics,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function modelKey(runtimeAttestation: unknown): string | null {
|
|
215
|
+
const model = record(record(runtimeAttestation).model);
|
|
216
|
+
if (model.state !== "observed") return null;
|
|
217
|
+
const value = record(model.value);
|
|
218
|
+
const provider = string(value.provider);
|
|
219
|
+
const id = string(value.id);
|
|
220
|
+
return provider && id ? `${provider}/${id}` : null;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function tokensFromObservation(value: unknown): TokenTotalsMetricV3 {
|
|
224
|
+
const observation = record(value);
|
|
225
|
+
if (observation.state !== "observed") {
|
|
226
|
+
return { state: "unknown", known: zeroTokens(), reasons: [observationReason(value)] };
|
|
227
|
+
}
|
|
228
|
+
const usage = record(observation.value);
|
|
229
|
+
if (!nonnegative(usage.input_tokens) || !nonnegative(usage.output_tokens)) {
|
|
230
|
+
return { state: "unknown", known: zeroTokens(), reasons: ["usage_invalid"] };
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
state: "observed",
|
|
234
|
+
value: {
|
|
235
|
+
input_tokens: usage.input_tokens as number,
|
|
236
|
+
output_tokens: usage.output_tokens as number,
|
|
237
|
+
cache_read_tokens: nonnegative(usage.cache_read_tokens)
|
|
238
|
+
? (usage.cache_read_tokens as number)
|
|
239
|
+
: 0,
|
|
240
|
+
cache_write_tokens: nonnegative(usage.cache_write_tokens)
|
|
241
|
+
? (usage.cache_write_tokens as number)
|
|
242
|
+
: 0,
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function usageMethod(value: unknown): string | null {
|
|
248
|
+
const observation = record(value);
|
|
249
|
+
return observation.state === "observed" ? string(record(observation.value).method) || null : null;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function timingFromObservation(value: unknown, field: string, fallback: string): LatencyMetricV3 {
|
|
253
|
+
const observation = record(value);
|
|
254
|
+
const fieldValue = record(observation.value)[field];
|
|
255
|
+
return observation.state === "observed" && nonnegative(fieldValue)
|
|
256
|
+
? { state: "observed", value_ms: fieldValue as number }
|
|
257
|
+
: { state: "unknown", known_ms: 0, reasons: [observationReason(value) || fallback] };
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function slowestHookFromObservation(value: unknown): {
|
|
261
|
+
name: string | null;
|
|
262
|
+
duration_ms: number | null;
|
|
263
|
+
} {
|
|
264
|
+
const observation = record(value);
|
|
265
|
+
if (observation.state !== "observed") return { name: null, duration_ms: null };
|
|
266
|
+
const harness = record(observation.value);
|
|
267
|
+
const name = string(harness.slowest_hook);
|
|
268
|
+
const duration = harness.slowest_hook_ms;
|
|
269
|
+
return name && nonnegative(duration) && Number.isSafeInteger(duration)
|
|
270
|
+
? { name, duration_ms: duration as number }
|
|
271
|
+
: { name: null, duration_ms: null };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function costForTurn(
|
|
275
|
+
tokens: TokenTotalsMetricV3,
|
|
276
|
+
model: string | null,
|
|
277
|
+
pricing: Record<string, ModelPricingV3> | undefined,
|
|
278
|
+
): CostMetricV3 {
|
|
279
|
+
const reasons: string[] = tokens.state === "unknown" ? ["usage_unknown"] : [];
|
|
280
|
+
const tokenValue = tokens.state === "observed" ? tokens.value : tokens.known;
|
|
281
|
+
if (!model)
|
|
282
|
+
return { state: "unknown", known_usd: 0, reasons: [...reasons, "model_unknown"].sort() };
|
|
283
|
+
const rates = pricing?.[model];
|
|
284
|
+
if (!rates) {
|
|
285
|
+
return {
|
|
286
|
+
state: "unknown",
|
|
287
|
+
known_usd: 0,
|
|
288
|
+
reasons: [...reasons, `pricing_unavailable:${model}`].sort(),
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
if (tokenValue.cache_read_tokens > 0 && rates.cache_read_usd_per_million === undefined) {
|
|
292
|
+
reasons.push("cache_read_pricing_unavailable");
|
|
293
|
+
}
|
|
294
|
+
if (tokenValue.cache_write_tokens > 0 && rates.cache_write_usd_per_million === undefined) {
|
|
295
|
+
reasons.push("cache_write_pricing_unavailable");
|
|
296
|
+
}
|
|
297
|
+
const usd =
|
|
298
|
+
(tokenValue.input_tokens * rates.input_usd_per_million +
|
|
299
|
+
tokenValue.output_tokens * rates.output_usd_per_million +
|
|
300
|
+
tokenValue.cache_read_tokens * (rates.cache_read_usd_per_million ?? 0) +
|
|
301
|
+
tokenValue.cache_write_tokens * (rates.cache_write_usd_per_million ?? 0)) /
|
|
302
|
+
1_000_000;
|
|
303
|
+
return reasons.length > 0
|
|
304
|
+
? { state: "unknown", known_usd: roundUsd(usd), reasons }
|
|
305
|
+
: { state: "observed", usd: roundUsd(usd), pricing_key: model };
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function sumTokenMetrics(metrics: TokenTotalsMetricV3[]): TokenTotalsMetricV3 {
|
|
309
|
+
const total = zeroTokens();
|
|
310
|
+
const reasons: string[] = [];
|
|
311
|
+
for (const metric of metrics) {
|
|
312
|
+
addTokens(total, metric.state === "observed" ? metric.value : metric.known);
|
|
313
|
+
if (metric.state === "unknown") reasons.push(...metric.reasons);
|
|
314
|
+
}
|
|
315
|
+
return reasons.length === 0
|
|
316
|
+
? { state: "observed", value: total }
|
|
317
|
+
: { state: "unknown", known: total, reasons: unique(reasons) };
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function sumTimingMetrics(metrics: LatencyMetricV3[]): LatencyMetricV3 {
|
|
321
|
+
let known = 0;
|
|
322
|
+
const reasons: string[] = [];
|
|
323
|
+
for (const metric of metrics) {
|
|
324
|
+
known += metric.state === "observed" ? metric.value_ms : metric.known_ms;
|
|
325
|
+
if (metric.state === "unknown") reasons.push(...metric.reasons);
|
|
326
|
+
}
|
|
327
|
+
return reasons.length === 0
|
|
328
|
+
? { state: "observed", value_ms: known }
|
|
329
|
+
: { state: "unknown", known_ms: known, reasons: unique(reasons) };
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function sumCostMetrics(metrics: CostMetricV3[]): CostMetricV3 {
|
|
333
|
+
let known = 0;
|
|
334
|
+
const reasons: string[] = [];
|
|
335
|
+
const keys = new Set<string>();
|
|
336
|
+
for (const metric of metrics) {
|
|
337
|
+
known += metric.state === "observed" ? metric.usd : metric.known_usd;
|
|
338
|
+
if (metric.state === "observed") keys.add(metric.pricing_key);
|
|
339
|
+
else reasons.push(...metric.reasons);
|
|
340
|
+
}
|
|
341
|
+
return reasons.length === 0
|
|
342
|
+
? { state: "observed", usd: roundUsd(known), pricing_key: [...keys].sort().join("+") }
|
|
343
|
+
: { state: "unknown", known_usd: roundUsd(known), reasons: unique(reasons) };
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function zeroTokens(): TokenTotalsV3 {
|
|
347
|
+
return { input_tokens: 0, output_tokens: 0, cache_read_tokens: 0, cache_write_tokens: 0 };
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function addTokens(target: TokenTotalsV3, value: TokenTotalsV3): void {
|
|
351
|
+
target.input_tokens += value.input_tokens;
|
|
352
|
+
target.output_tokens += value.output_tokens;
|
|
353
|
+
target.cache_read_tokens += value.cache_read_tokens;
|
|
354
|
+
target.cache_write_tokens += value.cache_write_tokens;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function nonnegative(value: unknown): boolean {
|
|
358
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function observationReason(value: unknown): string {
|
|
362
|
+
const observation = record(value);
|
|
363
|
+
const state = string(observation.state) || "unknown";
|
|
364
|
+
const reason = string(observation.reason);
|
|
365
|
+
return reason ? `${state}:${reason}` : state;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function roundUsd(value: number): number {
|
|
369
|
+
return Math.round(value * 1_000_000_000_000) / 1_000_000_000_000;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function unique(values: string[]): string[] {
|
|
373
|
+
return [...new Set(values)].sort();
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function record(value: unknown): Record<string, unknown> {
|
|
377
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
378
|
+
? (value as Record<string, unknown>)
|
|
379
|
+
: {};
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function string(value: unknown): string {
|
|
383
|
+
return typeof value === "string" ? value : "";
|
|
384
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CoordinationViewV3,
|
|
3
|
+
projectCoordinationViewV3,
|
|
4
|
+
readCoordinationViewV3,
|
|
5
|
+
} from "./coordination-view.ts";
|
|
6
|
+
import type { ReadLedgerV3Result } from "./reader.ts";
|
|
7
|
+
|
|
8
|
+
export const EVENT_V3_FINALIZATION_VIEW_VERSION = 1 as const;
|
|
9
|
+
|
|
10
|
+
export type FinalizationScopeV3ErrorCode = "authority_unsafe" | "instance_not_live";
|
|
11
|
+
|
|
12
|
+
export class FinalizationScopeV3Error extends Error {
|
|
13
|
+
constructor(public readonly code: FinalizationScopeV3ErrorCode) {
|
|
14
|
+
super(`event_v3_finalization_scope:${code}`);
|
|
15
|
+
this.name = "FinalizationScopeV3Error";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface FinalizationScopeV3 {
|
|
20
|
+
projection_version: typeof EVENT_V3_FINALIZATION_VIEW_VERSION;
|
|
21
|
+
contract_major: 2;
|
|
22
|
+
instance_id: string;
|
|
23
|
+
session_id: string;
|
|
24
|
+
generation_id: string;
|
|
25
|
+
lifecycle_state?: string;
|
|
26
|
+
files_touched: string[];
|
|
27
|
+
source_event_id: string;
|
|
28
|
+
source_position: { segment_ordinal: number; byte_offset: number };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Read and validate the current V3 finalization boundary for one live instance. */
|
|
32
|
+
export function readFinalizationScopeV3(
|
|
33
|
+
coordRoot: string,
|
|
34
|
+
instanceId: string,
|
|
35
|
+
): FinalizationScopeV3 {
|
|
36
|
+
return finalizationScopeFromCoordinationViewV3(readCoordinationViewV3(coordRoot), instanceId);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Pure adapter used by replay tests and safety consumers. */
|
|
40
|
+
export function projectFinalizationScopeV3(
|
|
41
|
+
read: ReadLedgerV3Result,
|
|
42
|
+
instanceId: string,
|
|
43
|
+
): FinalizationScopeV3 {
|
|
44
|
+
return finalizationScopeFromCoordinationViewV3(projectCoordinationViewV3(read), instanceId);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function finalizationScopeFromCoordinationViewV3(
|
|
48
|
+
view: CoordinationViewV3,
|
|
49
|
+
instanceId: string,
|
|
50
|
+
): FinalizationScopeV3 {
|
|
51
|
+
if (!view.authority_safe) throw new FinalizationScopeV3Error("authority_unsafe");
|
|
52
|
+
const instance = view.instances[instanceId];
|
|
53
|
+
if (!instance?.authority_eligible) {
|
|
54
|
+
throw new FinalizationScopeV3Error("instance_not_live");
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
projection_version: EVENT_V3_FINALIZATION_VIEW_VERSION,
|
|
58
|
+
contract_major: 2,
|
|
59
|
+
instance_id: instance.instance_id,
|
|
60
|
+
session_id: instance.session_id,
|
|
61
|
+
generation_id: instance.generation_id,
|
|
62
|
+
lifecycle_state: instance.lifecycle_state,
|
|
63
|
+
files_touched: [...instance.files_touched],
|
|
64
|
+
source_event_id: instance.last_event_id,
|
|
65
|
+
source_position: { ...instance.source_position },
|
|
66
|
+
};
|
|
67
|
+
}
|