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,578 @@
|
|
|
1
|
+
import type { Adapter } from "../../../adapter.ts";
|
|
2
|
+
import type { ParsedPayload } from "../../../hooks/adapter/parse.ts";
|
|
3
|
+
import { buildEventV3Base } from "../base-builder.ts";
|
|
4
|
+
import type { EventV3Base, RuntimeAttestationV3Base } from "../base-contract.ts";
|
|
5
|
+
import { type FingerprintContextV3, fingerprintV3, normalizeNativeIdV3 } from "../canonical.ts";
|
|
6
|
+
import { adapterSignalSupportV3, adapterTurnWaitCountSupportV3 } from "../capabilities.ts";
|
|
7
|
+
import { eventIdV3 } from "../ids.ts";
|
|
8
|
+
import { exactToolInputFingerprintV3, extractTargetsV3 } from "../targets.ts";
|
|
9
|
+
|
|
10
|
+
export type HookSignalV3Base =
|
|
11
|
+
| "session-start"
|
|
12
|
+
| "session-end"
|
|
13
|
+
| "user-prompt-submit"
|
|
14
|
+
| "stop"
|
|
15
|
+
| "stop-failure"
|
|
16
|
+
| "pre-tool-use"
|
|
17
|
+
| "post-tool-use"
|
|
18
|
+
| "post-tool-use-failure"
|
|
19
|
+
| "permission-request"
|
|
20
|
+
| "sub-agent-start"
|
|
21
|
+
| "sub-agent-stop"
|
|
22
|
+
| "pre-compact"
|
|
23
|
+
| "post-compact";
|
|
24
|
+
|
|
25
|
+
export interface HookProducerContextV3Base {
|
|
26
|
+
coordRoot: string;
|
|
27
|
+
adapter: Adapter;
|
|
28
|
+
adapterVersion?: string;
|
|
29
|
+
harnessVersion?: string;
|
|
30
|
+
root_id: `root_${string}`;
|
|
31
|
+
run_id?: `run_${string}`;
|
|
32
|
+
workflow_id?: `wf_${string}`;
|
|
33
|
+
workflow_agent_id?: string;
|
|
34
|
+
instance_id: `inst_${string}`;
|
|
35
|
+
generation_id: `gen_${string}`;
|
|
36
|
+
attestation_id: `att_${string}`;
|
|
37
|
+
producer_id: `prd_${string}`;
|
|
38
|
+
boot_id: `boot_${string}`;
|
|
39
|
+
sequence: number;
|
|
40
|
+
build_id: `build_${string}`;
|
|
41
|
+
platform: "linux" | "windows" | "macos" | "unknown";
|
|
42
|
+
bridge?: "codex-wsl";
|
|
43
|
+
capability_profile: `cap_${string}`;
|
|
44
|
+
fingerprintContext: FingerprintContextV3;
|
|
45
|
+
turn_native_id?: string;
|
|
46
|
+
turn_id?: `tid_${string}`;
|
|
47
|
+
span_id?: `span_${string}`;
|
|
48
|
+
caused_by?: `evt_${string}`[];
|
|
49
|
+
event_id?: `evt_${string}`;
|
|
50
|
+
observed_at?: string;
|
|
51
|
+
recorded_at?: string;
|
|
52
|
+
monotonic_ns?: string;
|
|
53
|
+
clock_id?: `clk_${string}`;
|
|
54
|
+
duration_ms?: number;
|
|
55
|
+
tool_call_count?: number;
|
|
56
|
+
tool_call_count_support?: "native" | "derived" | "conditional" | "unsupported";
|
|
57
|
+
tool_call_count_missing_reason?: string;
|
|
58
|
+
response_bytes?: number;
|
|
59
|
+
delegation_id?: `del_${string}`;
|
|
60
|
+
child_generation_id?: `gen_${string}`;
|
|
61
|
+
agent_role?: string;
|
|
62
|
+
stop_remediation?: boolean;
|
|
63
|
+
turn_ritual?: TurnRitualEvidenceV3;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface TurnRitualEvidenceV3 {
|
|
67
|
+
status_box_present: boolean;
|
|
68
|
+
status_box_present_strict: boolean;
|
|
69
|
+
session_name_required: boolean;
|
|
70
|
+
session_name_present: boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
type TurnRitualObservationV3 = NonNullable<
|
|
74
|
+
Extract<EventV3Base, { event_type: "turn.completed" }>["payload"]["ritual"]
|
|
75
|
+
>;
|
|
76
|
+
|
|
77
|
+
/** Normalize one already-parsed hook payload directly into V3Base without retaining its raw fields. */
|
|
78
|
+
export function normalizeHookEventV3Base(
|
|
79
|
+
signal: HookSignalV3Base,
|
|
80
|
+
payload: ParsedPayload,
|
|
81
|
+
context: HookProducerContextV3Base,
|
|
82
|
+
): EventV3Base | null {
|
|
83
|
+
const eventId = context.event_id ?? eventIdV3();
|
|
84
|
+
const sessionNative =
|
|
85
|
+
payload.session_id ?? payload.conversation_id ?? payload.agent_id ?? context.instance_id;
|
|
86
|
+
const sessionId = asSessionId(
|
|
87
|
+
normalizeNativeIdV3(context.fingerprintContext, `${context.adapter}.session`, sessionNative),
|
|
88
|
+
);
|
|
89
|
+
const turnNative =
|
|
90
|
+
payload.turn_id ?? context.turn_native_id ?? `${sessionNative}:${context.sequence}`;
|
|
91
|
+
// A native payload turn id normally outranks the producer-state stamp: a
|
|
92
|
+
// lost or late user-prompt-submit hook must not mis-attribute this event to
|
|
93
|
+
// a stale turn (ADR 0078 turn attribution). Turn terminals are different:
|
|
94
|
+
// Cursor can mint a new generation_id for Stop, so the producer's open turn
|
|
95
|
+
// is the authoritative correlation target when one exists.
|
|
96
|
+
const terminalTurnId =
|
|
97
|
+
signal === "stop" || signal === "stop-failure" ? context.turn_id : undefined;
|
|
98
|
+
const turnId = terminalTurnId
|
|
99
|
+
? terminalTurnId
|
|
100
|
+
: payload.turn_id
|
|
101
|
+
? asTurnId(
|
|
102
|
+
normalizeNativeIdV3(
|
|
103
|
+
context.fingerprintContext,
|
|
104
|
+
`${context.adapter}.turn`,
|
|
105
|
+
payload.turn_id,
|
|
106
|
+
),
|
|
107
|
+
)
|
|
108
|
+
: (context.turn_id ??
|
|
109
|
+
asTurnId(
|
|
110
|
+
normalizeNativeIdV3(context.fingerprintContext, `${context.adapter}.turn`, turnNative),
|
|
111
|
+
));
|
|
112
|
+
const generationScope = {
|
|
113
|
+
root_id: context.root_id,
|
|
114
|
+
instance_id: context.instance_id,
|
|
115
|
+
session_id: sessionId,
|
|
116
|
+
generation_id: context.generation_id,
|
|
117
|
+
...(context.run_id ? { run_id: context.run_id } : {}),
|
|
118
|
+
...(context.workflow_id ? { workflow_id: context.workflow_id } : {}),
|
|
119
|
+
...(context.workflow_agent_id ? { workflow_agent_id: context.workflow_agent_id } : {}),
|
|
120
|
+
};
|
|
121
|
+
const turnScope = { ...generationScope, turn_id: turnId };
|
|
122
|
+
const producer = {
|
|
123
|
+
producer_id: context.producer_id,
|
|
124
|
+
boot_id: context.boot_id,
|
|
125
|
+
sequence: context.sequence,
|
|
126
|
+
component: "agent-hook" as const,
|
|
127
|
+
build_id: context.build_id,
|
|
128
|
+
platform: context.platform,
|
|
129
|
+
...(context.bridge ? { bridge: context.bridge } : {}),
|
|
130
|
+
};
|
|
131
|
+
const provenance = {
|
|
132
|
+
source_event: `${context.adapter}.${signal}`,
|
|
133
|
+
attestation: "native" as const,
|
|
134
|
+
confidence: "exact" as const,
|
|
135
|
+
...(payload.tool_use_id
|
|
136
|
+
? {
|
|
137
|
+
source_record_id: asSourceId(
|
|
138
|
+
normalizeNativeIdV3(
|
|
139
|
+
context.fingerprintContext,
|
|
140
|
+
`${context.adapter}.source-record`,
|
|
141
|
+
payload.tool_use_id,
|
|
142
|
+
),
|
|
143
|
+
),
|
|
144
|
+
}
|
|
145
|
+
: {}),
|
|
146
|
+
attribution: {
|
|
147
|
+
method: "native_payload" as const,
|
|
148
|
+
state: "verified" as const,
|
|
149
|
+
subject_instance_id: context.instance_id,
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
const common = {
|
|
153
|
+
event_id: eventId,
|
|
154
|
+
producer,
|
|
155
|
+
attestation_id: context.attestation_id,
|
|
156
|
+
provenance,
|
|
157
|
+
observed_at: context.observed_at,
|
|
158
|
+
recorded_at: context.recorded_at,
|
|
159
|
+
monotonic_ns: context.monotonic_ns,
|
|
160
|
+
clock_id: context.clock_id,
|
|
161
|
+
};
|
|
162
|
+
const causedBy = context.caused_by ?? [];
|
|
163
|
+
|
|
164
|
+
switch (signal) {
|
|
165
|
+
case "session-start": {
|
|
166
|
+
const runtimeAttestation: RuntimeAttestationV3Base = {
|
|
167
|
+
attestation_id: context.attestation_id,
|
|
168
|
+
generation_id: context.generation_id,
|
|
169
|
+
adapter: observedIdentity(context.adapter, context.adapterVersion),
|
|
170
|
+
harness: observedIdentity(context.adapter, context.harnessVersion),
|
|
171
|
+
model: payload.model
|
|
172
|
+
? {
|
|
173
|
+
state: "observed",
|
|
174
|
+
value: { provider: providerFor(context.adapter), id: safeModelId(payload.model) },
|
|
175
|
+
attestation: "native",
|
|
176
|
+
confidence: "exact",
|
|
177
|
+
}
|
|
178
|
+
: { state: "expected_but_missing", capability: "model_identity", reason: "not_reported" },
|
|
179
|
+
capability_profile: context.capability_profile,
|
|
180
|
+
declared_by_event_id: eventId,
|
|
181
|
+
};
|
|
182
|
+
return buildEventV3Base("session.started", {
|
|
183
|
+
...common,
|
|
184
|
+
scope: generationScope,
|
|
185
|
+
links: { caused_by: causedBy },
|
|
186
|
+
payload: {
|
|
187
|
+
runtime_attestation: runtimeAttestation,
|
|
188
|
+
resume:
|
|
189
|
+
payload.source === "resume"
|
|
190
|
+
? { state: "unknown", reason: "prior_generation_not_bound" }
|
|
191
|
+
: { state: "not_applicable" },
|
|
192
|
+
},
|
|
193
|
+
}) as EventV3Base;
|
|
194
|
+
}
|
|
195
|
+
case "session-end":
|
|
196
|
+
return buildEventV3Base("session.ended", {
|
|
197
|
+
...common,
|
|
198
|
+
scope: generationScope,
|
|
199
|
+
links: { caused_by: causedBy },
|
|
200
|
+
payload: {
|
|
201
|
+
outcome:
|
|
202
|
+
payload.clean_exit === true
|
|
203
|
+
? "succeeded"
|
|
204
|
+
: payload.clean_exit === false
|
|
205
|
+
? "failed"
|
|
206
|
+
: "unknown",
|
|
207
|
+
authority: "native",
|
|
208
|
+
reason:
|
|
209
|
+
payload.clean_exit === true
|
|
210
|
+
? "native_clean_exit"
|
|
211
|
+
: payload.clean_exit === false
|
|
212
|
+
? "native_unclean_exit"
|
|
213
|
+
: "native_exit_outcome_unknown",
|
|
214
|
+
completeness: { state: "unknown", reason: "terminal_signal_coverage_unmeasured" },
|
|
215
|
+
},
|
|
216
|
+
}) as EventV3Base;
|
|
217
|
+
case "user-prompt-submit": {
|
|
218
|
+
const prompt = payload.prompt ?? "";
|
|
219
|
+
return buildEventV3Base("turn.started", {
|
|
220
|
+
...common,
|
|
221
|
+
scope: turnScope,
|
|
222
|
+
links: { caused_by: causedBy },
|
|
223
|
+
payload: {
|
|
224
|
+
input: {
|
|
225
|
+
storage: "omitted",
|
|
226
|
+
media_type: "text/plain",
|
|
227
|
+
bytes: Buffer.byteLength(prompt, "utf8"),
|
|
228
|
+
fingerprint: fingerprintV3(context.fingerprintContext, "user-prompt", prompt),
|
|
229
|
+
},
|
|
230
|
+
intent_kind: "unknown",
|
|
231
|
+
...(context.stop_remediation ? { stop_remediation: true } : {}),
|
|
232
|
+
},
|
|
233
|
+
}) as EventV3Base;
|
|
234
|
+
}
|
|
235
|
+
case "stop":
|
|
236
|
+
case "stop-failure":
|
|
237
|
+
return buildEventV3Base("turn.completed", {
|
|
238
|
+
...common,
|
|
239
|
+
scope: turnScope,
|
|
240
|
+
links: { caused_by: causedBy },
|
|
241
|
+
payload: {
|
|
242
|
+
outcome: signal === "stop" ? "succeeded" : "failed",
|
|
243
|
+
duration_ms: measuredOrMissing(
|
|
244
|
+
context.duration_ms,
|
|
245
|
+
"turn_duration",
|
|
246
|
+
"turn_timing_not_supplied",
|
|
247
|
+
),
|
|
248
|
+
tool_call_count:
|
|
249
|
+
context.tool_call_count_support === "unsupported"
|
|
250
|
+
? { state: "unsupported", capability: "turn_tool_call_count" }
|
|
251
|
+
: measuredOrMissing(
|
|
252
|
+
context.tool_call_count,
|
|
253
|
+
"turn_tool_call_count",
|
|
254
|
+
context.tool_call_count_missing_reason ?? "turn_aggregate_not_supplied",
|
|
255
|
+
),
|
|
256
|
+
wait_count:
|
|
257
|
+
adapterTurnWaitCountSupportV3(context.adapter) === "unsupported"
|
|
258
|
+
? { state: "unsupported", capability: "turn_wait_count" }
|
|
259
|
+
: measuredOrMissing(undefined, "turn_wait_count", "turn_wait_aggregate_not_supplied"),
|
|
260
|
+
response:
|
|
261
|
+
context.response_bytes === undefined
|
|
262
|
+
? { state: "unsupported", capability: "turn_response_descriptor" }
|
|
263
|
+
: {
|
|
264
|
+
state: "observed",
|
|
265
|
+
value: {
|
|
266
|
+
storage: "omitted",
|
|
267
|
+
media_type: "text/plain",
|
|
268
|
+
bytes: context.response_bytes,
|
|
269
|
+
},
|
|
270
|
+
attestation: "derived",
|
|
271
|
+
confidence: "exact",
|
|
272
|
+
},
|
|
273
|
+
...(context.turn_ritual
|
|
274
|
+
? { ritual: turnRitualObservation(context.adapter, context.turn_ritual) }
|
|
275
|
+
: {}),
|
|
276
|
+
},
|
|
277
|
+
}) as EventV3Base;
|
|
278
|
+
case "pre-tool-use": {
|
|
279
|
+
if (!payload.tool_name || !context.span_id) return null;
|
|
280
|
+
const toolInput = payload.tool_input ?? null;
|
|
281
|
+
return buildEventV3Base("tool.requested", {
|
|
282
|
+
...common,
|
|
283
|
+
scope: turnScope,
|
|
284
|
+
links: { caused_by: causedBy, span_id: context.span_id },
|
|
285
|
+
payload: {
|
|
286
|
+
tool: { namespace: context.adapter, name: safeToolName(payload.tool_name) },
|
|
287
|
+
input: {
|
|
288
|
+
storage: "omitted",
|
|
289
|
+
media_type: "application/json",
|
|
290
|
+
bytes: byteLengthOfUnknown(toolInput),
|
|
291
|
+
},
|
|
292
|
+
exact_input: exactToolInputFingerprintV3(
|
|
293
|
+
context.fingerprintContext,
|
|
294
|
+
context.adapter,
|
|
295
|
+
payload.tool_name,
|
|
296
|
+
toolInput,
|
|
297
|
+
),
|
|
298
|
+
targets: extractTargetsV3({
|
|
299
|
+
coordRoot: context.coordRoot,
|
|
300
|
+
toolNamespace: context.adapter,
|
|
301
|
+
toolName: payload.tool_name,
|
|
302
|
+
toolInput,
|
|
303
|
+
fingerprintContext: context.fingerprintContext,
|
|
304
|
+
}),
|
|
305
|
+
},
|
|
306
|
+
}) as EventV3Base;
|
|
307
|
+
}
|
|
308
|
+
case "post-tool-use":
|
|
309
|
+
case "post-tool-use-failure": {
|
|
310
|
+
if (!payload.tool_name || !context.span_id) return null;
|
|
311
|
+
return buildEventV3Base("tool.completed", {
|
|
312
|
+
...common,
|
|
313
|
+
scope: turnScope,
|
|
314
|
+
links: { caused_by: causedBy, span_id: context.span_id },
|
|
315
|
+
payload: {
|
|
316
|
+
tool: { namespace: context.adapter, name: safeToolName(payload.tool_name) },
|
|
317
|
+
outcome: signal === "post-tool-use" ? "succeeded" : "failed",
|
|
318
|
+
duration_ms: measuredOrMissing(
|
|
319
|
+
context.duration_ms,
|
|
320
|
+
"tool_duration",
|
|
321
|
+
"span_timing_not_supplied",
|
|
322
|
+
),
|
|
323
|
+
result: {
|
|
324
|
+
storage: "omitted",
|
|
325
|
+
media_type:
|
|
326
|
+
typeof payload.tool_response === "string" ? "text/plain" : "application/json",
|
|
327
|
+
bytes: byteLengthOfUnknown(payload.tool_response ?? null),
|
|
328
|
+
},
|
|
329
|
+
...(signal === "post-tool-use-failure"
|
|
330
|
+
? { error: { class: "adapter_tool_failure" } }
|
|
331
|
+
: {}),
|
|
332
|
+
},
|
|
333
|
+
}) as EventV3Base;
|
|
334
|
+
}
|
|
335
|
+
case "permission-request": {
|
|
336
|
+
const waitNative = payload.tool_use_id ?? `${sessionNative}:${context.sequence}`;
|
|
337
|
+
const waitId = normalizeNativeIdV3(
|
|
338
|
+
context.fingerprintContext,
|
|
339
|
+
`${context.adapter}.wait`,
|
|
340
|
+
waitNative,
|
|
341
|
+
);
|
|
342
|
+
return buildEventV3Base("wait.started", {
|
|
343
|
+
...common,
|
|
344
|
+
scope: turnScope,
|
|
345
|
+
links: { caused_by: causedBy },
|
|
346
|
+
payload: { wait_id: waitId, kind: "permission" },
|
|
347
|
+
}) as EventV3Base;
|
|
348
|
+
}
|
|
349
|
+
case "sub-agent-start": {
|
|
350
|
+
if (!context.delegation_id || !context.child_generation_id) return null;
|
|
351
|
+
return buildEventV3Base("agent.started", {
|
|
352
|
+
...common,
|
|
353
|
+
scope: generationScope,
|
|
354
|
+
links: {
|
|
355
|
+
caused_by: causedBy,
|
|
356
|
+
delegation_id: context.delegation_id,
|
|
357
|
+
parent_generation_id: context.generation_id,
|
|
358
|
+
},
|
|
359
|
+
payload: {
|
|
360
|
+
delegation_id: context.delegation_id,
|
|
361
|
+
child_generation_id: context.child_generation_id,
|
|
362
|
+
role: safeToken(context.agent_role ?? "agent", "agent"),
|
|
363
|
+
},
|
|
364
|
+
}) as EventV3Base;
|
|
365
|
+
}
|
|
366
|
+
case "sub-agent-stop": {
|
|
367
|
+
if (!context.delegation_id || !context.child_generation_id) return null;
|
|
368
|
+
return buildEventV3Base("agent.completed", {
|
|
369
|
+
...common,
|
|
370
|
+
scope: generationScope,
|
|
371
|
+
links: {
|
|
372
|
+
caused_by: causedBy,
|
|
373
|
+
delegation_id: context.delegation_id,
|
|
374
|
+
parent_generation_id: context.generation_id,
|
|
375
|
+
},
|
|
376
|
+
payload: {
|
|
377
|
+
delegation_id: context.delegation_id,
|
|
378
|
+
child_generation_id: context.child_generation_id,
|
|
379
|
+
outcome:
|
|
380
|
+
payload.exit_status === "ok"
|
|
381
|
+
? "succeeded"
|
|
382
|
+
: payload.exit_status === "interrupted"
|
|
383
|
+
? "interrupted"
|
|
384
|
+
: payload.exit_status
|
|
385
|
+
? "failed"
|
|
386
|
+
: "unknown",
|
|
387
|
+
},
|
|
388
|
+
}) as EventV3Base;
|
|
389
|
+
}
|
|
390
|
+
case "pre-compact":
|
|
391
|
+
return buildEventV3Base("context.compaction_started", {
|
|
392
|
+
...common,
|
|
393
|
+
scope: generationScope,
|
|
394
|
+
links: { caused_by: causedBy },
|
|
395
|
+
payload: {
|
|
396
|
+
before: contextMeasurement(
|
|
397
|
+
inputContextMeasurement(payload, "before"),
|
|
398
|
+
context,
|
|
399
|
+
"pre_compaction",
|
|
400
|
+
),
|
|
401
|
+
method: `${context.adapter.replaceAll("-", "_")}_hook`,
|
|
402
|
+
},
|
|
403
|
+
}) as EventV3Base;
|
|
404
|
+
case "post-compact":
|
|
405
|
+
return buildEventV3Base("context.compaction_completed", {
|
|
406
|
+
...common,
|
|
407
|
+
scope: generationScope,
|
|
408
|
+
links: { caused_by: causedBy },
|
|
409
|
+
payload: {
|
|
410
|
+
outcome: "succeeded",
|
|
411
|
+
before: contextMeasurement(
|
|
412
|
+
inputContextMeasurement(payload, "before"),
|
|
413
|
+
context,
|
|
414
|
+
"pre_compaction",
|
|
415
|
+
),
|
|
416
|
+
after: contextMeasurement(
|
|
417
|
+
inputContextMeasurement(payload, "after"),
|
|
418
|
+
context,
|
|
419
|
+
"post_compaction",
|
|
420
|
+
),
|
|
421
|
+
},
|
|
422
|
+
}) as EventV3Base;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function turnRitualObservation(
|
|
427
|
+
adapter: Adapter,
|
|
428
|
+
evidence: TurnRitualEvidenceV3,
|
|
429
|
+
): TurnRitualObservationV3 {
|
|
430
|
+
if (adapter === "cursor") {
|
|
431
|
+
const unsupported = { state: "unsupported" as const, capability: "assistant_reply_text" };
|
|
432
|
+
return {
|
|
433
|
+
status_box_present: unsupported,
|
|
434
|
+
status_box_present_strict: unsupported,
|
|
435
|
+
session_name: unsupported,
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
const observed = <T>(value: T) => ({
|
|
439
|
+
state: "observed" as const,
|
|
440
|
+
value,
|
|
441
|
+
attestation: "derived" as const,
|
|
442
|
+
confidence: "exact" as const,
|
|
443
|
+
});
|
|
444
|
+
return {
|
|
445
|
+
status_box_present: observed(evidence.status_box_present),
|
|
446
|
+
status_box_present_strict: observed(evidence.status_box_present_strict),
|
|
447
|
+
session_name: observed({
|
|
448
|
+
required: evidence.session_name_required,
|
|
449
|
+
present: evidence.session_name_present,
|
|
450
|
+
}),
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function inputContextMeasurement(payload: ParsedPayload, phase: "before" | "after") {
|
|
455
|
+
const metadata = plainRecord(payload.raw.compact_metadata);
|
|
456
|
+
const usedKeys =
|
|
457
|
+
phase === "before"
|
|
458
|
+
? ["pre_tokens", "pre_compact_tokens", "used_tokens"]
|
|
459
|
+
: ["post_tokens", "post_compact_tokens", "used_tokens"];
|
|
460
|
+
const limitKeys = [
|
|
461
|
+
"context_window_size",
|
|
462
|
+
"context_window_tokens",
|
|
463
|
+
"window_tokens",
|
|
464
|
+
"limit_tokens",
|
|
465
|
+
];
|
|
466
|
+
return {
|
|
467
|
+
used: firstNumber(payload.raw, metadata, usedKeys),
|
|
468
|
+
limit: firstNumber(payload.raw, metadata, limitKeys),
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
function contextMeasurement(
|
|
473
|
+
measurement: { used?: number; limit?: number },
|
|
474
|
+
context: HookProducerContextV3Base,
|
|
475
|
+
capability: "pre_compaction" | "post_compaction",
|
|
476
|
+
) {
|
|
477
|
+
if (adapterSignalSupportV3(context.adapter, capability) === "unsupported") {
|
|
478
|
+
return { state: "unsupported", capability } as const;
|
|
479
|
+
}
|
|
480
|
+
if (measurement.used === undefined || measurement.limit === undefined || measurement.limit < 1) {
|
|
481
|
+
return {
|
|
482
|
+
state: "expected_but_missing",
|
|
483
|
+
capability,
|
|
484
|
+
reason: "context_measurement_incomplete",
|
|
485
|
+
} as const;
|
|
486
|
+
}
|
|
487
|
+
return {
|
|
488
|
+
state: "observed",
|
|
489
|
+
value: {
|
|
490
|
+
used_tokens: Math.floor(measurement.used),
|
|
491
|
+
limit_tokens: Math.floor(measurement.limit),
|
|
492
|
+
remaining_tokens: Math.max(0, Math.floor(measurement.limit - measurement.used)),
|
|
493
|
+
measured_at: context.observed_at ?? context.recorded_at ?? new Date().toISOString(),
|
|
494
|
+
method: `${context.adapter.replaceAll("-", "_")}_hook`,
|
|
495
|
+
},
|
|
496
|
+
attestation: "native",
|
|
497
|
+
confidence: "exact",
|
|
498
|
+
} as const;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function firstNumber(
|
|
502
|
+
primary: Record<string, unknown>,
|
|
503
|
+
secondary: Record<string, unknown> | undefined,
|
|
504
|
+
keys: string[],
|
|
505
|
+
): number | undefined {
|
|
506
|
+
for (const key of keys) {
|
|
507
|
+
for (const source of [primary, secondary]) {
|
|
508
|
+
const value = source?.[key];
|
|
509
|
+
if (typeof value === "number" && Number.isFinite(value) && value >= 0) return value;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
return undefined;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
function plainRecord(value: unknown): Record<string, unknown> | undefined {
|
|
516
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;
|
|
517
|
+
const prototype = Object.getPrototypeOf(value);
|
|
518
|
+
return prototype === Object.prototype || prototype === null
|
|
519
|
+
? (value as Record<string, unknown>)
|
|
520
|
+
: undefined;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function observedIdentity(id: string, version: string | undefined) {
|
|
524
|
+
return {
|
|
525
|
+
state: "observed" as const,
|
|
526
|
+
value: { id, ...(version ? { version } : {}) },
|
|
527
|
+
attestation: "native" as const,
|
|
528
|
+
confidence: "exact" as const,
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
function providerFor(adapter: Adapter): string {
|
|
533
|
+
if (adapter === "claude-code") return "anthropic";
|
|
534
|
+
if (adapter === "codex") return "openai";
|
|
535
|
+
return "cursor";
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
function safeModelId(value: string): string {
|
|
539
|
+
return safeToken(value, "unknown-model");
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
function safeToolName(value: string): string {
|
|
543
|
+
return safeToken(value, "unknown-tool");
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
function safeToken(value: string, fallback: string): string {
|
|
547
|
+
const normalized = value
|
|
548
|
+
.normalize("NFC")
|
|
549
|
+
.replace(/[^a-zA-Z0-9._:/+-]/g, "_")
|
|
550
|
+
.slice(0, 128);
|
|
551
|
+
return /^[a-zA-Z0-9]/.test(normalized) ? normalized : fallback;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
function byteLengthOfUnknown(value: unknown): number {
|
|
555
|
+
try {
|
|
556
|
+
return Buffer.byteLength(JSON.stringify(value) ?? "null", "utf8");
|
|
557
|
+
} catch {
|
|
558
|
+
return 0;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function measuredOrMissing(value: number | undefined, capability: string, reason: string) {
|
|
563
|
+
return value === undefined
|
|
564
|
+
? ({ state: "expected_but_missing", capability, reason } as const)
|
|
565
|
+
: ({ state: "observed", value, attestation: "derived", confidence: "exact" } as const);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
function asSessionId(value: `hid_${string}`): `sid_${string}` {
|
|
569
|
+
return `sid_${value.slice(4)}`;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
function asTurnId(value: `hid_${string}`): `tid_${string}` {
|
|
573
|
+
return `tid_${value.slice(4)}`;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
function asSourceId(value: `hid_${string}`): `hid_${string}` {
|
|
577
|
+
return value;
|
|
578
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { ParsedPayload } from "../../../hooks/adapter/parse.ts";
|
|
2
|
+
import type { EventV3Base } from "../base-contract.ts";
|
|
3
|
+
import type { EventOfTypeV3, EventTypeV3, SpanSummaryV3 } from "../contract.ts";
|
|
4
|
+
import { EVENT_V3_CONTRACT_MAJOR, EVENT_V3_CONTRACT_NAME } from "../contract.ts";
|
|
5
|
+
import { EVENT_V3_SCHEMA_DIGEST } from "../generated.ts";
|
|
6
|
+
import {
|
|
7
|
+
emptyHarnessTimingV3,
|
|
8
|
+
extractTurnTelemetryV3,
|
|
9
|
+
type HarnessTimingAccumulatorV3,
|
|
10
|
+
harnessObservationV3,
|
|
11
|
+
type TurnTelemetryV3,
|
|
12
|
+
} from "../turn-telemetry.ts";
|
|
13
|
+
import { assertEventV3 } from "../validate.ts";
|
|
14
|
+
import {
|
|
15
|
+
type HookProducerContextV3Base,
|
|
16
|
+
type HookSignalV3Base,
|
|
17
|
+
normalizeHookEventV3Base,
|
|
18
|
+
} from "./hook-base.ts";
|
|
19
|
+
|
|
20
|
+
export interface HookProducerContextV3 extends HookProducerContextV3Base {
|
|
21
|
+
/** Required for terminal events; captured when the corresponding span opens. */
|
|
22
|
+
terminal_span?: SpanSummaryV3;
|
|
23
|
+
/** Required by V3 delegation starts so the child span is anchored in its parent tree. */
|
|
24
|
+
parent_span_id?: `span_${string}`;
|
|
25
|
+
/** Optional recorder aggregate. An empty aggregate remains explicit missing evidence. */
|
|
26
|
+
harness_timing?: HarnessTimingAccumulatorV3;
|
|
27
|
+
/** Test/replay override for already-extracted telemetry. */
|
|
28
|
+
turn_telemetry?: TurnTelemetryV3;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type HookSignalV3 = HookSignalV3Base;
|
|
32
|
+
|
|
33
|
+
const TERMINAL_EVENT_TYPES = new Set([
|
|
34
|
+
"session.ended",
|
|
35
|
+
"turn.completed",
|
|
36
|
+
"tool.completed",
|
|
37
|
+
"agent.completed",
|
|
38
|
+
"wait.ended",
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
export type HookEventV3 = EventOfTypeV3<EventTypeV3>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Normalize one hook payload to the V3 contract.
|
|
45
|
+
*
|
|
46
|
+
* The V3 base normalizer owns privacy and scope. This adapter adds contract
|
|
47
|
+
* identity, self-contained terminal spans, and economics. Returning null for an incomplete terminal prevents a producer
|
|
48
|
+
* from writing a structurally valid-looking event without its load-bearing
|
|
49
|
+
* self-contained span.
|
|
50
|
+
*/
|
|
51
|
+
export function normalizeHookEventV3(
|
|
52
|
+
signal: HookSignalV3Base,
|
|
53
|
+
payload: ParsedPayload,
|
|
54
|
+
context: HookProducerContextV3,
|
|
55
|
+
): HookEventV3 | null {
|
|
56
|
+
const base = normalizeHookEventV3Base(signal, payload, context);
|
|
57
|
+
if (!base) return null;
|
|
58
|
+
return upgradeHookEventV3(base, payload, context);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Upgrade recorder-synthesized hook events, including resolving wait terminals. */
|
|
62
|
+
export function upgradeHookEventV3(
|
|
63
|
+
base: EventV3Base,
|
|
64
|
+
source: ParsedPayload,
|
|
65
|
+
context: HookProducerContextV3,
|
|
66
|
+
): HookEventV3 | null {
|
|
67
|
+
if (TERMINAL_EVENT_TYPES.has(base.event_type) && !context.terminal_span) return null;
|
|
68
|
+
if (base.event_type === "agent.started" && (!context.span_id || !context.parent_span_id)) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const event = {
|
|
73
|
+
...base,
|
|
74
|
+
contract: {
|
|
75
|
+
name: EVENT_V3_CONTRACT_NAME,
|
|
76
|
+
major: EVENT_V3_CONTRACT_MAJOR,
|
|
77
|
+
schema_digest: EVENT_V3_SCHEMA_DIGEST,
|
|
78
|
+
},
|
|
79
|
+
event_type: base.event_type,
|
|
80
|
+
links: {
|
|
81
|
+
...(base.links as Record<string, unknown>),
|
|
82
|
+
...(context.span_id ? { span_id: context.span_id } : {}),
|
|
83
|
+
...(context.parent_span_id ? { parent_span_id: context.parent_span_id } : {}),
|
|
84
|
+
},
|
|
85
|
+
payload: terminalPayload(base.event_type, base.payload, source, context),
|
|
86
|
+
};
|
|
87
|
+
assertEventV3(event);
|
|
88
|
+
return event as HookEventV3;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function terminalPayload(
|
|
92
|
+
eventType: string,
|
|
93
|
+
basePayload: object,
|
|
94
|
+
source: ParsedPayload,
|
|
95
|
+
context: HookProducerContextV3,
|
|
96
|
+
): object {
|
|
97
|
+
if (!TERMINAL_EVENT_TYPES.has(eventType)) return basePayload;
|
|
98
|
+
const span = context.terminal_span as SpanSummaryV3;
|
|
99
|
+
if (eventType === "tool.completed") {
|
|
100
|
+
return { ...basePayload, duration_ms: span.duration_ms, span };
|
|
101
|
+
}
|
|
102
|
+
if (eventType !== "turn.completed") return { ...basePayload, span };
|
|
103
|
+
|
|
104
|
+
const telemetry =
|
|
105
|
+
context.turn_telemetry ??
|
|
106
|
+
extractTurnTelemetryV3(
|
|
107
|
+
context.adapter,
|
|
108
|
+
source.raw,
|
|
109
|
+
context.observed_at ?? context.recorded_at ?? new Date().toISOString(),
|
|
110
|
+
);
|
|
111
|
+
return {
|
|
112
|
+
...basePayload,
|
|
113
|
+
duration_ms: span.duration_ms,
|
|
114
|
+
span,
|
|
115
|
+
usage: telemetry.usage,
|
|
116
|
+
inference: telemetry.inference,
|
|
117
|
+
harness: harnessObservationV3(context.harness_timing ?? emptyHarnessTimingV3()),
|
|
118
|
+
};
|
|
119
|
+
}
|