harnery 0.33.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commander.d.ts.map +1 -1
- package/dist/commander.js +4 -0
- package/dist/commands/adapter.js +2 -2
- package/dist/commands/agents.d.ts +144 -1
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +1220 -588
- package/dist/commands/artifacts.d.ts.map +1 -1
- package/dist/commands/artifacts.js +7 -6
- package/dist/commands/backup.d.ts +1 -1
- package/dist/commands/backup.d.ts.map +1 -1
- package/dist/commands/backup.js +29 -16
- package/dist/commands/browse.d.ts.map +1 -1
- package/dist/commands/browse.js +234 -12
- package/dist/commands/checkpoint.d.ts.map +1 -1
- package/dist/commands/checkpoint.js +3 -2
- package/dist/commands/claude-desktop.d.ts +1 -1
- package/dist/commands/claude-desktop.d.ts.map +1 -1
- package/dist/commands/claude-desktop.js +3 -74
- package/dist/commands/context.js +1 -6
- package/dist/commands/decision.d.ts.map +1 -1
- package/dist/commands/decision.js +22 -38
- package/dist/commands/docs.d.ts.map +1 -1
- package/dist/commands/docs.js +91 -28
- package/dist/commands/doctor.js +10 -1
- package/dist/commands/events.d.ts +5 -0
- package/dist/commands/events.d.ts.map +1 -0
- package/dist/commands/events.js +189 -0
- package/dist/commands/governor.d.ts.map +1 -1
- package/dist/commands/governor.js +13 -4
- package/dist/commands/init.d.ts +9 -2
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +223 -51
- package/dist/commands/journal.d.ts.map +1 -1
- package/dist/commands/journal.js +4 -13
- package/dist/commands/ledger-v3.d.ts +5 -0
- package/dist/commands/ledger-v3.d.ts.map +1 -0
- package/dist/commands/ledger-v3.js +91 -0
- package/dist/commands/presence.d.ts.map +1 -1
- package/dist/commands/presence.js +11 -5
- package/dist/commands/sync.d.ts +1 -1
- package/dist/commands/sync.js +1 -1
- package/dist/commands/web.d.ts +6 -0
- package/dist/commands/web.d.ts.map +1 -1
- package/dist/commands/web.js +67 -7
- package/dist/commands/work.d.ts.map +1 -1
- package/dist/commands/work.js +22 -5
- package/dist/core/adapter.d.ts +5 -0
- package/dist/core/adapter.d.ts.map +1 -0
- package/dist/core/adapter.js +1 -0
- package/dist/core/adapters/attest.d.ts +5 -2
- package/dist/core/adapters/attest.d.ts.map +1 -1
- package/dist/core/adapters/attest.js +8 -3
- package/dist/core/adapters/profiles.d.ts +6 -6
- package/dist/core/adapters/profiles.d.ts.map +1 -1
- package/dist/core/adapters/profiles.js +4 -4
- package/dist/core/agents/canonical-emit.d.ts +17 -15
- package/dist/core/agents/canonical-emit.d.ts.map +1 -1
- package/dist/core/agents/canonical-emit.js +22 -22
- package/dist/core/agents/cli.js +207 -234
- package/dist/core/agents/codex-archive-v3.d.ts +14 -0
- package/dist/core/agents/codex-archive-v3.d.ts.map +1 -0
- package/dist/core/agents/codex-archive-v3.js +110 -0
- package/dist/core/agents/coord-client.d.ts +19 -81
- package/dist/core/agents/coord-client.d.ts.map +1 -1
- package/dist/core/agents/coord-client.js +65 -155
- package/dist/core/agents/finalization.d.ts +4 -1
- package/dist/core/agents/finalization.d.ts.map +1 -1
- package/dist/core/agents/finalization.js +89 -32
- package/dist/core/agents/index.d.ts +4 -5
- package/dist/core/agents/index.d.ts.map +1 -1
- package/dist/core/agents/index.js +4 -5
- package/dist/core/agents/live-authority-v3.d.ts +59 -0
- package/dist/core/agents/live-authority-v3.d.ts.map +1 -0
- package/dist/core/agents/live-authority-v3.js +233 -0
- package/dist/core/agents/live-lifecycle-v3.d.ts +20 -0
- package/dist/core/agents/live-lifecycle-v3.d.ts.map +1 -0
- package/dist/core/agents/live-lifecycle-v3.js +91 -0
- package/dist/core/agents/live-observation-v3.d.ts +25 -0
- package/dist/core/agents/live-observation-v3.d.ts.map +1 -0
- package/dist/core/agents/live-observation-v3.js +157 -0
- package/dist/core/agents/render/prompt-context.d.ts +4 -4
- package/dist/core/agents/render/prompt-context.d.ts.map +1 -1
- package/dist/core/agents/render/prompt-context.js +23 -58
- package/dist/core/agents/render/session-context.d.ts +1 -1
- package/dist/core/agents/render/session-context.d.ts.map +1 -1
- package/dist/core/agents/render/session-context.js +8 -32
- package/dist/core/agents/rules/claim-conflict.d.ts +3 -3
- package/dist/core/agents/rules/claim-conflict.d.ts.map +1 -1
- package/dist/core/agents/rules/claim-conflict.js +79 -127
- package/dist/core/agents/rules/commit-conflict.d.ts.map +1 -1
- package/dist/core/agents/rules/commit-conflict.js +3 -18
- package/dist/core/agents/rules/stop-hook.d.ts +9 -50
- package/dist/core/agents/rules/stop-hook.d.ts.map +1 -1
- package/dist/core/agents/rules/stop-hook.js +193 -236
- package/dist/core/agents/session-events.d.ts +5 -7
- package/dist/core/agents/session-events.d.ts.map +1 -1
- package/dist/core/agents/session-events.js +127 -95
- package/dist/core/agents/session-finalization-state-v3.d.ts +30 -0
- package/dist/core/agents/session-finalization-state-v3.d.ts.map +1 -0
- package/dist/core/agents/session-finalization-state-v3.js +40 -0
- package/dist/core/agents/session-finalizer-v3.d.ts +107 -0
- package/dist/core/agents/session-finalizer-v3.d.ts.map +1 -0
- package/dist/core/agents/session-finalizer-v3.js +734 -0
- package/dist/core/agents/session-name-display.d.ts +40 -0
- package/dist/core/agents/session-name-display.d.ts.map +1 -0
- package/dist/core/agents/session-name-display.js +119 -0
- package/dist/core/agents/state/activity-log.d.ts +3 -3
- package/dist/core/agents/state/activity-log.d.ts.map +1 -1
- package/dist/core/agents/state/activity-log.js +7 -16
- package/dist/core/agents/state/heartbeat-writer.d.ts +23 -55
- package/dist/core/agents/state/heartbeat-writer.d.ts.map +1 -1
- package/dist/core/agents/state/heartbeat-writer.js +56 -228
- package/dist/core/agents/state/live-coordination-view.d.ts +31 -0
- package/dist/core/agents/state/live-coordination-view.d.ts.map +1 -0
- package/dist/core/agents/state/live-coordination-view.js +209 -0
- package/dist/core/agents/state/session-state.d.ts +4 -3
- package/dist/core/agents/state/session-state.d.ts.map +1 -1
- package/dist/core/agents/state/session-state.js +18 -9
- package/dist/core/agents/state/stale-sweep.d.ts +1 -1
- package/dist/core/agents/state/stale-sweep.d.ts.map +1 -1
- package/dist/core/agents/state/stale-sweep.js +26 -15
- package/dist/core/artifacts/index.d.ts.map +1 -1
- package/dist/core/artifacts/index.js +5 -7
- package/dist/core/config.d.ts +33 -2
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +98 -2
- package/dist/core/context/index.d.ts +1 -4
- package/dist/core/context/index.d.ts.map +1 -1
- package/dist/core/context/index.js +9 -9
- package/dist/core/events/span-parent.d.ts +15 -0
- package/dist/core/events/span-parent.d.ts.map +1 -0
- package/dist/core/events/span-parent.js +34 -0
- package/dist/core/events/v3/advance.d.ts +14 -0
- package/dist/core/events/v3/advance.d.ts.map +1 -0
- package/dist/core/events/v3/advance.js +134 -0
- package/dist/core/events/v3/authority-outbox.d.ts +78 -0
- package/dist/core/events/v3/authority-outbox.d.ts.map +1 -0
- package/dist/core/events/v3/authority-outbox.js +399 -0
- package/dist/core/events/v3/base-builder.d.ts +20 -0
- package/dist/core/events/v3/base-builder.d.ts.map +1 -0
- package/dist/core/events/v3/base-builder.js +29 -0
- package/dist/core/events/v3/base-contract.d.ts +7576 -0
- package/dist/core/events/v3/base-contract.d.ts.map +1 -0
- package/dist/core/events/v3/base-contract.js +647 -0
- package/dist/core/events/v3/bootstrap.d.ts +34 -0
- package/dist/core/events/v3/bootstrap.d.ts.map +1 -0
- package/dist/core/events/v3/bootstrap.js +175 -0
- package/dist/core/events/v3/builder.d.ts +20 -0
- package/dist/core/events/v3/builder.d.ts.map +1 -0
- package/dist/core/events/v3/builder.js +28 -0
- package/dist/core/events/v3/canonical.d.ts +31 -0
- package/dist/core/events/v3/canonical.d.ts.map +1 -0
- package/dist/core/events/v3/canonical.js +100 -0
- package/dist/core/events/v3/capabilities.d.ts +31 -0
- package/dist/core/events/v3/capabilities.d.ts.map +1 -0
- package/dist/core/events/v3/capabilities.js +107 -0
- package/dist/core/events/v3/capability-drift.d.ts +22 -0
- package/dist/core/events/v3/capability-drift.d.ts.map +1 -0
- package/dist/core/events/v3/capability-drift.js +134 -0
- package/dist/core/events/v3/catalog.d.ts +38 -0
- package/dist/core/events/v3/catalog.d.ts.map +1 -0
- package/dist/core/events/v3/catalog.js +135 -0
- package/dist/core/events/v3/clock-order.d.ts +34 -0
- package/dist/core/events/v3/clock-order.d.ts.map +1 -0
- package/dist/core/events/v3/clock-order.js +35 -0
- package/dist/core/events/v3/contract.d.ts +171 -0
- package/dist/core/events/v3/contract.d.ts.map +1 -0
- package/dist/core/events/v3/contract.js +180 -0
- package/dist/core/events/v3/control.d.ts +111 -0
- package/dist/core/events/v3/control.d.ts.map +1 -0
- package/dist/core/events/v3/control.js +419 -0
- package/dist/core/events/v3/coordination-view.d.ts +69 -0
- package/dist/core/events/v3/coordination-view.d.ts.map +1 -0
- package/dist/core/events/v3/coordination-view.js +119 -0
- package/dist/core/events/v3/economics.d.ts +77 -0
- package/dist/core/events/v3/economics.d.ts.map +1 -0
- package/dist/core/events/v3/economics.js +274 -0
- package/dist/core/events/v3/finalization-view.d.ts +26 -0
- package/dist/core/events/v3/finalization-view.d.ts.map +1 -0
- package/dist/core/events/v3/finalization-view.js +37 -0
- package/dist/core/events/v3/fingerprint-keys.d.ts +25 -0
- package/dist/core/events/v3/fingerprint-keys.d.ts.map +1 -0
- package/dist/core/events/v3/fingerprint-keys.js +217 -0
- package/dist/core/events/v3/generated.d.ts +4 -0
- package/dist/core/events/v3/generated.d.ts.map +1 -0
- package/dist/core/events/v3/generated.js +47 -0
- package/dist/core/events/v3/ids.d.ts +9 -0
- package/dist/core/events/v3/ids.d.ts.map +1 -0
- package/dist/core/events/v3/ids.js +25 -0
- package/dist/core/events/v3/index.d.ts +35 -0
- package/dist/core/events/v3/index.d.ts.map +1 -0
- package/dist/core/events/v3/index.js +33 -0
- package/dist/core/events/v3/latency.d.ts +63 -0
- package/dist/core/events/v3/latency.d.ts.map +1 -0
- package/dist/core/events/v3/latency.js +412 -0
- package/dist/core/events/v3/live-feed.d.ts +45 -0
- package/dist/core/events/v3/live-feed.d.ts.map +1 -0
- package/dist/core/events/v3/live-feed.js +246 -0
- package/dist/core/events/v3/live-observation.d.ts +35 -0
- package/dist/core/events/v3/live-observation.d.ts.map +1 -0
- package/dist/core/events/v3/live-observation.js +1 -0
- package/dist/core/events/v3/live-routing.d.ts +57 -0
- package/dist/core/events/v3/live-routing.d.ts.map +1 -0
- package/dist/core/events/v3/live-routing.js +107 -0
- package/dist/core/events/v3/producers/command-recorder.d.ts +67 -0
- package/dist/core/events/v3/producers/command-recorder.d.ts.map +1 -0
- package/dist/core/events/v3/producers/command-recorder.js +477 -0
- package/dist/core/events/v3/producers/command.d.ts +50 -0
- package/dist/core/events/v3/producers/command.d.ts.map +1 -0
- package/dist/core/events/v3/producers/command.js +135 -0
- package/dist/core/events/v3/producers/coordination-recorder.d.ts +53 -0
- package/dist/core/events/v3/producers/coordination-recorder.d.ts.map +1 -0
- package/dist/core/events/v3/producers/coordination-recorder.js +376 -0
- package/dist/core/events/v3/producers/coordination.d.ts +90 -0
- package/dist/core/events/v3/producers/coordination.d.ts.map +1 -0
- package/dist/core/events/v3/producers/coordination.js +229 -0
- package/dist/core/events/v3/producers/hook-base.d.ts +54 -0
- package/dist/core/events/v3/producers/hook-base.d.ts.map +1 -0
- package/dist/core/events/v3/producers/hook-base.js +424 -0
- package/dist/core/events/v3/producers/hook.d.ts +29 -0
- package/dist/core/events/v3/producers/hook.d.ts.map +1 -0
- package/dist/core/events/v3/producers/hook.js +71 -0
- package/dist/core/events/v3/producers/intake.d.ts +65 -0
- package/dist/core/events/v3/producers/intake.d.ts.map +1 -0
- package/dist/core/events/v3/producers/intake.js +244 -0
- package/dist/core/events/v3/producers/recorder.d.ts +240 -0
- package/dist/core/events/v3/producers/recorder.d.ts.map +1 -0
- package/dist/core/events/v3/producers/recorder.js +2176 -0
- package/dist/core/events/v3/projection.d.ts +101 -0
- package/dist/core/events/v3/projection.d.ts.map +1 -0
- package/dist/core/events/v3/projection.js +479 -0
- package/dist/core/events/v3/reader.d.ts +75 -0
- package/dist/core/events/v3/reader.d.ts.map +1 -0
- package/dist/core/events/v3/reader.js +778 -0
- package/dist/core/events/v3/recovery-record.d.ts +47 -0
- package/dist/core/events/v3/recovery-record.d.ts.map +1 -0
- package/dist/core/events/v3/recovery-record.js +167 -0
- package/dist/core/events/v3/recovery.d.ts +22 -0
- package/dist/core/events/v3/recovery.d.ts.map +1 -0
- package/dist/core/events/v3/recovery.js +227 -0
- package/dist/core/events/v3/span-state.d.ts +52 -0
- package/dist/core/events/v3/span-state.d.ts.map +1 -0
- package/dist/core/events/v3/span-state.js +142 -0
- package/dist/core/events/v3/targets.d.ts +23 -0
- package/dist/core/events/v3/targets.d.ts.map +1 -0
- package/dist/core/events/v3/targets.js +134 -0
- package/dist/core/events/v3/turn-telemetry.d.ts +41 -0
- package/dist/core/events/v3/turn-telemetry.d.ts.map +1 -0
- package/dist/core/events/v3/turn-telemetry.js +168 -0
- package/dist/core/events/v3/validate.d.ts +9 -0
- package/dist/core/events/v3/validate.d.ts.map +1 -0
- package/dist/core/events/v3/validate.js +281 -0
- package/dist/core/events/v3/writer.d.ts +56 -0
- package/dist/core/events/v3/writer.d.ts.map +1 -0
- package/dist/core/events/v3/writer.js +335 -0
- package/dist/core/governor/index.d.ts +1 -1
- package/dist/core/governor/index.d.ts.map +1 -1
- package/dist/core/governor/index.js +1 -1
- package/dist/core/governor/plan-api.d.ts +2 -1
- package/dist/core/governor/plan-api.d.ts.map +1 -1
- package/dist/core/governor/plan-api.js +6 -3
- package/dist/core/governor/read.d.ts +1 -1
- package/dist/core/governor/read.d.ts.map +1 -1
- package/dist/core/governor/read.js +1 -1
- package/dist/core/governor/state.d.ts +9 -0
- package/dist/core/governor/state.d.ts.map +1 -1
- package/dist/core/governor/state.js +40 -3
- package/dist/core/guard/config.d.ts +5 -0
- package/dist/core/guard/config.d.ts.map +1 -0
- package/dist/core/guard/config.js +157 -0
- package/dist/core/guard/coordinator.d.ts +14 -0
- package/dist/core/guard/coordinator.d.ts.map +1 -0
- package/dist/core/guard/coordinator.js +173 -0
- package/dist/core/guard/evaluator.d.ts +4 -0
- package/dist/core/guard/evaluator.d.ts.map +1 -0
- package/dist/core/guard/evaluator.js +242 -0
- package/dist/core/guard/evidence-v3.d.ts +15 -0
- package/dist/core/guard/evidence-v3.d.ts.map +1 -0
- package/dist/core/guard/evidence-v3.js +171 -0
- package/dist/core/guard/index.d.ts +10 -0
- package/dist/core/guard/index.d.ts.map +1 -0
- package/dist/core/guard/index.js +6 -0
- package/dist/core/guard/live-source-v3.d.ts +40 -0
- package/dist/core/guard/live-source-v3.d.ts.map +1 -0
- package/dist/core/guard/live-source-v3.js +128 -0
- package/dist/core/guard/storage.d.ts +27 -0
- package/dist/core/guard/storage.d.ts.map +1 -0
- package/dist/core/guard/storage.js +140 -0
- package/dist/core/guard/types.d.ts +119 -0
- package/dist/core/guard/types.d.ts.map +1 -0
- package/dist/core/guard/types.js +1 -0
- package/dist/core/hooks/adapter/detect.d.ts +18 -1
- package/dist/core/hooks/adapter/detect.d.ts.map +1 -1
- package/dist/core/hooks/adapter/detect.js +29 -0
- package/dist/core/hooks/adapter/events.d.ts +7 -4
- package/dist/core/hooks/adapter/events.d.ts.map +1 -1
- package/dist/core/hooks/adapter/events.js +12 -4
- package/dist/core/hooks/adapter/output.d.ts +2 -2
- package/dist/core/hooks/adapter/output.d.ts.map +1 -1
- package/dist/core/hooks/adapter/parse.d.ts +7 -4
- package/dist/core/hooks/adapter/parse.d.ts.map +1 -1
- package/dist/core/hooks/adapter/parse.js +63 -25
- package/dist/core/hooks/adapter/wiring.d.ts +30 -4
- package/dist/core/hooks/adapter/wiring.d.ts.map +1 -1
- package/dist/core/hooks/adapter/wiring.js +89 -11
- package/dist/core/hooks/cli.d.ts +1 -1
- package/dist/core/hooks/cli.js +305 -444
- package/dist/core/hooks/effects/image-capture.d.ts +20 -34
- package/dist/core/hooks/effects/image-capture.d.ts.map +1 -1
- package/dist/core/hooks/effects/image-capture.js +212 -221
- package/dist/core/hooks/effects/index.d.ts +1 -9
- package/dist/core/hooks/effects/index.d.ts.map +1 -1
- package/dist/core/hooks/effects/index.js +1 -24
- package/dist/core/hooks/events/input-hash.d.ts +7 -0
- package/dist/core/hooks/events/input-hash.d.ts.map +1 -0
- package/dist/core/hooks/events/input-hash.js +43 -0
- package/dist/core/hooks/index.d.ts +4 -3
- package/dist/core/hooks/index.d.ts.map +1 -1
- package/dist/core/hooks/index.js +2 -3
- package/dist/core/hooks/resolve/coord-root.d.ts +1 -1
- package/dist/core/hooks/resolve/coord-root.js +1 -1
- package/dist/core/hooks/resolve/owner.d.ts +16 -15
- package/dist/core/hooks/resolve/owner.d.ts.map +1 -1
- package/dist/core/hooks/resolve/owner.js +51 -42
- package/dist/core/hooks/resolve/transcript.d.ts +33 -3
- package/dist/core/hooks/resolve/transcript.d.ts.map +1 -1
- package/dist/core/hooks/resolve/transcript.js +155 -14
- package/dist/core/hooks/session-name-presence.d.ts +9 -10
- package/dist/core/hooks/session-name-presence.d.ts.map +1 -1
- package/dist/core/hooks/session-name-presence.js +15 -15
- package/dist/core/hooks/unsafe-cross-shell.d.ts +1 -1
- package/dist/core/hooks/unsafe-cross-shell.d.ts.map +1 -1
- package/dist/core/journal/index.d.ts +2 -2
- package/dist/core/journal/index.d.ts.map +1 -1
- package/dist/core/journal/index.js +9 -22
- package/dist/core/presence/blob.d.ts +4 -3
- package/dist/core/presence/blob.d.ts.map +1 -1
- package/dist/core/presence/blob.js +45 -44
- package/dist/core/presence/codec-digest.d.ts +29 -0
- package/dist/core/presence/codec-digest.d.ts.map +1 -0
- package/dist/core/presence/codec-digest.js +170 -0
- package/dist/core/presence/relay-client.d.ts +1 -1
- package/dist/core/presence/relay-client.d.ts.map +1 -1
- package/dist/core/presence/relay-client.js +5 -5
- package/dist/core/work/index.d.ts +1 -1
- package/dist/core/work/index.d.ts.map +1 -1
- package/dist/core/work/index.js +1 -1
- package/dist/core/work/read.d.ts +1 -1
- package/dist/core/work/read.d.ts.map +1 -1
- package/dist/core/work/read.js +1 -1
- package/dist/core/work/runner.d.ts.map +1 -1
- package/dist/core/work/runner.js +6 -0
- package/dist/core/work/state.d.ts +9 -0
- package/dist/core/work/state.d.ts.map +1 -1
- package/dist/core/work/state.js +17 -3
- package/dist/core/workflow/engine.js +24 -25
- package/dist/core/workflow/live-session-v3.d.ts +19 -0
- package/dist/core/workflow/live-session-v3.d.ts.map +1 -0
- package/dist/core/workflow/live-session-v3.js +86 -0
- package/dist/core/workflow/scope-id.d.ts +3 -0
- package/dist/core/workflow/scope-id.d.ts.map +1 -0
- package/dist/core/workflow/scope-id.js +5 -0
- package/dist/core/workflow/workspaces/leases.d.ts +4 -0
- package/dist/core/workflow/workspaces/leases.d.ts.map +1 -1
- package/dist/core/workflow/workspaces/leases.js +53 -19
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/browser/client.d.ts +41 -0
- package/dist/lib/browser/client.d.ts.map +1 -1
- package/dist/lib/browser/client.js +203 -0
- package/dist/lib/browser/critique.d.ts +28 -2
- package/dist/lib/browser/critique.d.ts.map +1 -1
- package/dist/lib/browser/critique.js +74 -18
- package/dist/lib/browser/geometry.d.ts +1 -1
- package/dist/lib/browser/geometry.d.ts.map +1 -1
- package/dist/lib/browser/geometry.js +130 -6
- package/dist/lib/browser/index.d.ts +3 -0
- package/dist/lib/browser/index.d.ts.map +1 -1
- package/dist/lib/browser/index.js +3 -0
- package/dist/lib/browser/qa-plan.d.ts +174 -0
- package/dist/lib/browser/qa-plan.d.ts.map +1 -0
- package/dist/lib/browser/qa-plan.js +321 -0
- package/dist/lib/browser/qa-reuse.d.ts +99 -0
- package/dist/lib/browser/qa-reuse.d.ts.map +1 -0
- package/dist/lib/browser/qa-reuse.js +222 -0
- package/dist/lib/browser/qa-snapshot.d.ts +64 -0
- package/dist/lib/browser/qa-snapshot.d.ts.map +1 -0
- package/dist/lib/browser/qa-snapshot.js +171 -0
- package/dist/lib/browser/runts.d.ts.map +1 -1
- package/dist/lib/browser/runts.js +22 -1
- package/dist/lib/browser/tiling.d.ts +71 -0
- package/dist/lib/browser/tiling.d.ts.map +1 -0
- package/dist/lib/browser/tiling.js +118 -0
- package/dist/lib/claude-desktop.d.ts +0 -47
- package/dist/lib/claude-desktop.d.ts.map +1 -1
- package/dist/lib/claude-desktop.js +1 -169
- package/dist/lib/context/index.d.ts +0 -3
- package/dist/lib/context/index.d.ts.map +1 -1
- package/dist/lib/context/index.js +20 -42
- package/dist/lib/council/index.d.ts +2 -2
- package/dist/lib/council/index.d.ts.map +1 -1
- package/dist/lib/council/index.js +9 -20
- package/dist/lib/docs-frontmatter.d.ts +1 -6
- package/dist/lib/docs-frontmatter.d.ts.map +1 -1
- package/dist/lib/docs-frontmatter.js +12 -78
- package/dist/lib/docs-index.d.ts +9 -0
- package/dist/lib/docs-index.d.ts.map +1 -1
- package/dist/lib/docs-index.js +32 -3
- package/dist/lib/docs-lint.d.ts.map +1 -1
- package/dist/lib/docs-lint.js +14 -30
- package/dist/lib/docs-metadata-audit.d.ts +19 -0
- package/dist/lib/docs-metadata-audit.d.ts.map +1 -0
- package/dist/lib/docs-metadata-audit.js +132 -0
- package/dist/lib/docs-metadata-managed.d.ts +23 -0
- package/dist/lib/docs-metadata-managed.d.ts.map +1 -0
- package/dist/lib/docs-metadata-managed.js +78 -0
- package/dist/lib/docs-metadata-sync.d.ts +20 -0
- package/dist/lib/docs-metadata-sync.d.ts.map +1 -0
- package/dist/lib/docs-metadata-sync.js +222 -0
- package/dist/lib/docs-metadata-v2-schema.d.ts +273 -0
- package/dist/lib/docs-metadata-v2-schema.d.ts.map +1 -0
- package/dist/lib/docs-metadata-v2-schema.js +134 -0
- package/dist/lib/docs-metadata-v2.d.ts +21 -0
- package/dist/lib/docs-metadata-v2.d.ts.map +1 -0
- package/dist/lib/docs-metadata-v2.js +424 -0
- package/dist/lib/docs-new.d.ts +11 -0
- package/dist/lib/docs-new.d.ts.map +1 -0
- package/dist/lib/docs-new.js +52 -0
- package/dist/lib/docs-sweep.d.ts.map +1 -1
- package/dist/lib/docs-sweep.js +45 -29
- package/dist/lib/headless/index.d.ts +98 -0
- package/dist/lib/headless/index.d.ts.map +1 -0
- package/dist/lib/headless/index.js +211 -0
- package/dist/lib/identities/assume.d.ts +4 -4
- package/dist/lib/identities/assume.d.ts.map +1 -1
- package/dist/lib/identities/assume.js +52 -68
- package/dist/lib/instructions/apply.d.ts +5 -4
- package/dist/lib/instructions/apply.d.ts.map +1 -1
- package/dist/lib/instructions/apply.js +32 -20
- package/dist/lib/instructions/bundle.d.ts +1 -1
- package/dist/lib/instructions/bundle.d.ts.map +1 -1
- package/dist/lib/instructions/bundle.js +1 -1
- package/dist/lib/instructions/splice.d.ts +0 -1
- package/dist/lib/instructions/splice.d.ts.map +1 -1
- package/dist/lib/instructions/splice.js +22 -6
- package/dist/lib/instructions/templates.d.ts +7 -5
- package/dist/lib/instructions/templates.d.ts.map +1 -1
- package/dist/lib/instructions/templates.js +79 -9
- package/package.json +26 -5
- package/schemas/config.schema.json +120 -2
- package/schemas/docs-metadata-v2.schema.json +441 -0
- package/schemas/event-v3.schema.json +24472 -0
- package/src/commander.ts +4 -0
- package/src/commands/adapter.ts +2 -2
- package/src/commands/agents.ts +1512 -592
- package/src/commands/artifacts.ts +7 -6
- package/src/commands/backup.ts +29 -21
- package/src/commands/browse.ts +349 -8
- package/src/commands/checkpoint.ts +4 -3
- package/src/commands/claude-desktop.ts +2 -101
- package/src/commands/context.ts +1 -6
- package/src/commands/decision.ts +27 -44
- package/src/commands/docs.ts +100 -33
- package/src/commands/doctor.ts +14 -1
- package/src/commands/events.ts +256 -0
- package/src/commands/governor.ts +18 -4
- package/src/commands/init.ts +253 -57
- package/src/commands/instructions.ts +1 -1
- package/src/commands/journal.ts +4 -13
- package/src/commands/ledger-v3.ts +111 -0
- package/src/commands/presence.ts +11 -10
- package/src/commands/sync.ts +1 -1
- package/src/commands/web.ts +67 -8
- package/src/commands/work.ts +28 -5
- package/src/core/adapter.ts +5 -0
- package/src/core/adapters/attest.ts +8 -3
- package/src/core/adapters/profiles.ts +4 -6
- package/src/core/agents/canonical-emit.ts +34 -25
- package/src/core/agents/cli.ts +236 -262
- package/src/core/agents/codex-archive-v3.ts +138 -0
- package/src/core/agents/coord-client.ts +75 -188
- package/src/core/agents/finalization.ts +120 -38
- package/src/core/agents/index.ts +4 -5
- package/src/core/agents/live-authority-v3.ts +375 -0
- package/src/core/agents/live-lifecycle-v3.ts +140 -0
- package/src/core/agents/live-observation-v3.ts +216 -0
- package/src/core/agents/render/prompt-context.ts +29 -60
- package/src/core/agents/render/session-context.ts +10 -31
- package/src/core/agents/rules/claim-conflict.ts +85 -126
- package/src/core/agents/rules/commit-conflict.ts +3 -14
- package/src/core/agents/rules/stop-hook.ts +239 -293
- package/src/core/agents/session-events.ts +137 -104
- package/src/core/agents/session-finalization-state-v3.ts +90 -0
- package/src/core/agents/session-finalizer-v3.ts +953 -0
- package/src/core/agents/session-name-display.ts +149 -0
- package/src/core/agents/state/activity-log.ts +6 -14
- package/src/core/agents/state/heartbeat-writer.ts +82 -277
- package/src/core/agents/state/live-coordination-view.ts +290 -0
- package/src/core/agents/state/session-state.ts +24 -12
- package/src/core/agents/state/stale-sweep.ts +40 -17
- package/src/core/artifacts/index.ts +4 -5
- package/src/core/config.ts +148 -3
- package/src/core/context/index.ts +9 -17
- package/src/core/events/span-parent.ts +46 -0
- package/src/core/events/v3/advance.ts +168 -0
- package/src/core/events/v3/authority-outbox.ts +548 -0
- package/src/core/events/v3/base-builder.ts +60 -0
- package/src/core/events/v3/base-contract.ts +882 -0
- package/src/core/events/v3/bootstrap.ts +226 -0
- package/src/core/events/v3/builder.ts +59 -0
- package/src/core/events/v3/canonical.ts +153 -0
- package/src/core/events/v3/capabilities.ts +171 -0
- package/src/core/events/v3/capability-drift.ts +177 -0
- package/src/core/events/v3/catalog.ts +202 -0
- package/src/core/events/v3/clock-order.ts +41 -0
- package/src/core/events/v3/contract.ts +365 -0
- package/src/core/events/v3/control.ts +576 -0
- package/src/core/events/v3/coordination-view.ts +193 -0
- package/src/core/events/v3/economics.ts +384 -0
- package/src/core/events/v3/finalization-view.ts +67 -0
- package/src/core/events/v3/fingerprint-keys.ts +260 -0
- package/src/core/events/v3/generated.ts +48 -0
- package/src/core/events/v3/ids.ts +33 -0
- package/src/core/events/v3/index.ts +322 -0
- package/src/core/events/v3/latency.ts +551 -0
- package/src/core/events/v3/live-feed.ts +319 -0
- package/src/core/events/v3/live-observation.ts +39 -0
- package/src/core/events/v3/live-routing.ts +135 -0
- package/src/core/events/v3/producers/command-recorder.ts +631 -0
- package/src/core/events/v3/producers/command.ts +201 -0
- package/src/core/events/v3/producers/coordination-recorder.ts +538 -0
- package/src/core/events/v3/producers/coordination.ts +355 -0
- package/src/core/events/v3/producers/hook-base.ts +578 -0
- package/src/core/events/v3/producers/hook.ts +119 -0
- package/src/core/events/v3/producers/intake.ts +319 -0
- package/src/core/events/v3/producers/recorder.ts +2805 -0
- package/src/core/events/v3/projection.ts +653 -0
- package/src/core/events/v3/reader.ts +1127 -0
- package/src/core/events/v3/recovery-record.ts +244 -0
- package/src/core/events/v3/recovery.ts +271 -0
- package/src/core/events/v3/span-state.ts +187 -0
- package/src/core/events/v3/targets.ts +182 -0
- package/src/core/events/v3/turn-telemetry.ts +259 -0
- package/src/core/events/v3/validate.ts +361 -0
- package/src/core/events/v3/writer.ts +419 -0
- package/src/core/governor/index.ts +3 -0
- package/src/core/governor/plan-api.ts +10 -2
- package/src/core/governor/read.ts +3 -0
- package/src/core/governor/state.ts +52 -5
- package/src/core/guard/config.ts +206 -0
- package/src/core/guard/coordinator.ts +227 -0
- package/src/core/guard/evaluator.ts +343 -0
- package/src/core/guard/evidence-v3.ts +227 -0
- package/src/core/guard/index.ts +35 -0
- package/src/core/guard/live-source-v3.ts +204 -0
- package/src/core/guard/storage.ts +188 -0
- package/src/core/guard/types.ts +152 -0
- package/src/core/hooks/adapter/detect.ts +28 -1
- package/src/core/hooks/adapter/events.ts +14 -6
- package/src/core/hooks/adapter/output.ts +7 -2
- package/src/core/hooks/adapter/parse.ts +80 -38
- package/src/core/hooks/adapter/wiring.ts +119 -13
- package/src/core/hooks/cli.ts +351 -466
- package/src/core/hooks/effects/image-capture.ts +228 -238
- package/src/core/hooks/effects/index.ts +1 -36
- package/src/core/hooks/events/input-hash.ts +47 -0
- package/src/core/hooks/index.ts +4 -11
- package/src/core/hooks/resolve/coord-root.ts +1 -1
- package/src/core/hooks/resolve/owner.ts +52 -45
- package/src/core/hooks/resolve/transcript.ts +165 -14
- package/src/core/hooks/session-name-presence.ts +14 -15
- package/src/core/hooks/unsafe-cross-shell.ts +1 -1
- package/src/core/journal/index.ts +15 -22
- package/src/core/presence/blob.ts +48 -41
- package/src/core/presence/codec-digest.ts +215 -0
- package/src/core/presence/relay-client.ts +5 -5
- package/src/core/work/index.ts +3 -0
- package/src/core/work/read.ts +3 -0
- package/src/core/work/runner.ts +6 -0
- package/src/core/work/state.ts +27 -3
- package/src/core/workflow/engine.ts +24 -24
- package/src/core/workflow/live-session-v3.ts +126 -0
- package/src/core/workflow/scope-id.ts +6 -0
- package/src/core/workflow/workspaces/leases.ts +56 -19
- package/src/index.ts +1 -1
- package/src/lib/browser/client.ts +230 -0
- package/src/lib/browser/critique.ts +104 -27
- package/src/lib/browser/geometry.ts +143 -14
- package/src/lib/browser/index.ts +34 -0
- package/src/lib/browser/qa-plan.ts +501 -0
- package/src/lib/browser/qa-reuse.ts +306 -0
- package/src/lib/browser/qa-snapshot.ts +223 -0
- package/src/lib/browser/runts.ts +27 -2
- package/src/lib/browser/tiling.ts +164 -0
- package/src/lib/claude-desktop.ts +1 -232
- package/src/lib/context/index.ts +22 -46
- package/src/lib/council/index.ts +9 -21
- package/src/lib/docs-frontmatter.ts +8 -79
- package/src/lib/docs-index.ts +33 -3
- package/src/lib/docs-lint.ts +15 -29
- package/src/lib/docs-metadata-audit.ts +166 -0
- package/src/lib/docs-metadata-managed.ts +83 -0
- package/src/lib/docs-metadata-sync.ts +262 -0
- package/src/lib/docs-metadata-v2-schema.ts +138 -0
- package/src/lib/docs-metadata-v2.ts +646 -0
- package/src/lib/docs-new.ts +63 -0
- package/src/lib/docs-sweep.ts +42 -28
- package/src/lib/headless/index.ts +287 -0
- package/src/lib/identities/assume.ts +67 -86
- package/src/lib/instructions/apply.ts +33 -20
- package/src/lib/instructions/bundle.ts +2 -2
- package/src/lib/instructions/splice.ts +21 -7
- package/src/lib/instructions/templates.ts +85 -13
- package/dist/core/agents/cli-emit.d.ts +0 -27
- package/dist/core/agents/cli-emit.d.ts.map +0 -1
- package/dist/core/agents/cli-emit.js +0 -57
- package/dist/core/agents/codex-replay.d.ts +0 -29
- package/dist/core/agents/codex-replay.d.ts.map +0 -1
- package/dist/core/agents/codex-replay.js +0 -138
- package/dist/core/agents/events/consume.d.ts +0 -82
- package/dist/core/agents/events/consume.d.ts.map +0 -1
- package/dist/core/agents/events/consume.js +0 -195
- package/dist/core/agents/events/emit.d.ts +0 -42
- package/dist/core/agents/events/emit.d.ts.map +0 -1
- package/dist/core/agents/events/emit.js +0 -75
- package/dist/core/agents/events/ulid.d.ts +0 -11
- package/dist/core/agents/events/ulid.d.ts.map +0 -1
- package/dist/core/agents/events/ulid.js +0 -47
- package/dist/core/agents/state/heartbeat-projector.d.ts +0 -76
- package/dist/core/agents/state/heartbeat-projector.d.ts.map +0 -1
- package/dist/core/agents/state/heartbeat-projector.js +0 -581
- package/dist/core/hooks/events/emit.d.ts +0 -31
- package/dist/core/hooks/events/emit.d.ts.map +0 -1
- package/dist/core/hooks/events/emit.js +0 -93
- package/dist/core/hooks/events/rotate.d.ts +0 -43
- package/dist/core/hooks/events/rotate.d.ts.map +0 -1
- package/dist/core/hooks/events/rotate.js +0 -142
- package/dist/core/hooks/events/schema.d.ts +0 -341
- package/dist/core/hooks/events/schema.d.ts.map +0 -1
- package/dist/core/hooks/events/schema.js +0 -12
- package/dist/core/hooks/events/ulid.d.ts +0 -10
- package/dist/core/hooks/events/ulid.d.ts.map +0 -1
- package/dist/core/hooks/events/ulid.js +0 -47
- package/dist/lib/docs-frontmatter-migrate.d.ts +0 -33
- package/dist/lib/docs-frontmatter-migrate.d.ts.map +0 -1
- package/dist/lib/docs-frontmatter-migrate.js +0 -364
- package/src/core/agents/cli-emit.ts +0 -64
- package/src/core/agents/codex-replay.ts +0 -163
- package/src/core/agents/events/consume.ts +0 -254
- package/src/core/agents/events/emit.ts +0 -115
- package/src/core/agents/events/ulid.ts +0 -51
- package/src/core/agents/state/heartbeat-projector.ts +0 -645
- package/src/core/hooks/events/emit.ts +0 -125
- package/src/core/hooks/events/rotate.ts +0 -151
- package/src/core/hooks/events/schema.ts +0 -582
- package/src/core/hooks/events/ulid.ts +0 -51
- package/src/lib/docs-frontmatter-migrate.ts +0 -427
|
@@ -0,0 +1,631 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import {
|
|
3
|
+
chmodSync,
|
|
4
|
+
closeSync,
|
|
5
|
+
existsSync,
|
|
6
|
+
fsyncSync,
|
|
7
|
+
mkdirSync,
|
|
8
|
+
openSync,
|
|
9
|
+
readdirSync,
|
|
10
|
+
readFileSync,
|
|
11
|
+
renameSync,
|
|
12
|
+
statSync,
|
|
13
|
+
unlinkSync,
|
|
14
|
+
writeFileSync,
|
|
15
|
+
} from "node:fs";
|
|
16
|
+
import { hostname } from "node:os";
|
|
17
|
+
import { join, resolve } from "node:path";
|
|
18
|
+
import type { Adapter } from "../../../adapter.ts";
|
|
19
|
+
import { fsyncParentDirectory } from "../../../workflow/durable-record.ts";
|
|
20
|
+
import { acquireNoClobberLease } from "../../../workflow/workspaces/leases.ts";
|
|
21
|
+
import { selectCommandParentSpan } from "../../span-parent.ts";
|
|
22
|
+
import { buildEventV3 } from "../builder.ts";
|
|
23
|
+
import { normalizeNativeIdV3 } from "../canonical.ts";
|
|
24
|
+
import { markObservedClockRegressionV3 } from "../clock-order.ts";
|
|
25
|
+
import type { EventV3 } from "../contract.ts";
|
|
26
|
+
import { type EventV3WriteMode, readEventV3ControlState } from "../control.ts";
|
|
27
|
+
import { fingerprintContextV3 } from "../fingerprint-keys.ts";
|
|
28
|
+
import { clockIdV3, spanIdV3 } from "../ids.ts";
|
|
29
|
+
import { tryWriteLiveDisplayV3 } from "../live-feed.ts";
|
|
30
|
+
import { closeSpanStateV3, openSpanStateV3 } from "../span-state.ts";
|
|
31
|
+
import { assertEventV3, validateEventV3 } from "../validate.ts";
|
|
32
|
+
import {
|
|
33
|
+
EVENT_V3_LEDGER_RELATIVE_ROOT,
|
|
34
|
+
type WriteEventV3Options,
|
|
35
|
+
type WriteEventV3Result,
|
|
36
|
+
writeEventV3,
|
|
37
|
+
} from "../writer.ts";
|
|
38
|
+
import {
|
|
39
|
+
type CommandObservationV3,
|
|
40
|
+
type CommandSignalV3,
|
|
41
|
+
normalizeCommandEventV3,
|
|
42
|
+
} from "./command.ts";
|
|
43
|
+
import { readHookProducerStateByInstanceV3 } from "./recorder.ts";
|
|
44
|
+
|
|
45
|
+
const COMMAND_STATE_FORMAT = "harnery-v3-command-producer" as const;
|
|
46
|
+
const COMMAND_STATE_VERSION = 1 as const;
|
|
47
|
+
const MAX_OBSERVATIONS = 512;
|
|
48
|
+
|
|
49
|
+
interface RecordedCommandObservationV3 {
|
|
50
|
+
source_id: `hid_${string}`;
|
|
51
|
+
event_id: `evt_${string}`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface PendingCommandEventV3 {
|
|
55
|
+
source_id: `hid_${string}`;
|
|
56
|
+
event: EventV3;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface CommandRecorderStateV3 {
|
|
60
|
+
format: typeof COMMAND_STATE_FORMAT;
|
|
61
|
+
format_version: typeof COMMAND_STATE_VERSION;
|
|
62
|
+
adapter: Adapter;
|
|
63
|
+
instance_id: `inst_${string}`;
|
|
64
|
+
session_id: `sid_${string}`;
|
|
65
|
+
generation_id: `gen_${string}`;
|
|
66
|
+
turn_id: `tid_${string}`;
|
|
67
|
+
attestation_id: `att_${string}`;
|
|
68
|
+
privacy_epoch_id: `pep_${string}`;
|
|
69
|
+
boot_id: `boot_${string}`;
|
|
70
|
+
clock_id: `clk_${string}`;
|
|
71
|
+
span_id: `span_${string}`;
|
|
72
|
+
parent_span_id?: `span_${string}`;
|
|
73
|
+
opened_at: string;
|
|
74
|
+
opened_monotonic_ns?: string;
|
|
75
|
+
open_event_id?: `evt_${string}`;
|
|
76
|
+
next_sequence: number;
|
|
77
|
+
last_event_id: `evt_${string}`;
|
|
78
|
+
last_observed_at?: string;
|
|
79
|
+
terminal: boolean;
|
|
80
|
+
observations: RecordedCommandObservationV3[];
|
|
81
|
+
pending?: PendingCommandEventV3;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface RecordCommandSignalV3Input {
|
|
85
|
+
coordRoot: string;
|
|
86
|
+
mode: EventV3WriteMode;
|
|
87
|
+
signal: CommandSignalV3;
|
|
88
|
+
observation: CommandObservationV3;
|
|
89
|
+
adapter: Adapter;
|
|
90
|
+
instance_id: `inst_${string}`;
|
|
91
|
+
producer_id: `prd_${string}`;
|
|
92
|
+
build_id: `build_${string}`;
|
|
93
|
+
platform: "linux" | "windows" | "macos" | "unknown";
|
|
94
|
+
bridge?: "codex-wsl";
|
|
95
|
+
monotonic_ns?: string;
|
|
96
|
+
observed_at?: string;
|
|
97
|
+
writerOptions?: WriteEventV3Options;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export type RecordCommandSignalV3Result =
|
|
101
|
+
| { state: "gate_closed"; reason: string }
|
|
102
|
+
| { state: "generation_unavailable"; reason: string }
|
|
103
|
+
| { state: "command_span_unstarted" }
|
|
104
|
+
| { state: "missing_observation_id" }
|
|
105
|
+
| { state: "already_recorded"; event_id: string }
|
|
106
|
+
| { state: "recorded"; event: EventV3; durability: WriteEventV3Result; recovered: boolean };
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Join a CLI/session-tee command to an already-started hook generation and
|
|
110
|
+
* record it through its own crash-recoverable producer sequence. This is
|
|
111
|
+
* inert until the exact candidate or active control gate is open.
|
|
112
|
+
*/
|
|
113
|
+
export function recordCommandSignalV3(
|
|
114
|
+
input: RecordCommandSignalV3Input,
|
|
115
|
+
): RecordCommandSignalV3Result {
|
|
116
|
+
const control = readEventV3ControlState(input.coordRoot);
|
|
117
|
+
if (control.state !== input.mode) {
|
|
118
|
+
return { state: "gate_closed", reason: control.state };
|
|
119
|
+
}
|
|
120
|
+
const hook = readHookProducerStateByInstanceV3(input.coordRoot, input.instance_id);
|
|
121
|
+
if (!hook || hook.adapter !== input.adapter) {
|
|
122
|
+
return { state: "generation_unavailable", reason: "hook_generation_not_joinable" };
|
|
123
|
+
}
|
|
124
|
+
if (!hook.current_turn_id) {
|
|
125
|
+
return { state: "generation_unavailable", reason: "turn_not_started" };
|
|
126
|
+
}
|
|
127
|
+
const rootId = control.genesis.event.scope.root_id as `root_${string}`;
|
|
128
|
+
const epochId = control.genesis.profile.privacy_key_epoch;
|
|
129
|
+
const rootContext = fingerprintContextV3(input.coordRoot, rootId, undefined, epochId);
|
|
130
|
+
const commandSource = normalizeNativeIdV3(
|
|
131
|
+
rootContext,
|
|
132
|
+
"session-tee.command",
|
|
133
|
+
`${input.adapter}\0${hook.session_id}\0${input.observation.native_command_id}`,
|
|
134
|
+
);
|
|
135
|
+
const sourceId = observationSourceId(input, rootContext);
|
|
136
|
+
if (!sourceId) return { state: "missing_observation_id" };
|
|
137
|
+
const path = commandStatePath(input.coordRoot, commandSource);
|
|
138
|
+
const lease = acquireCommandLease(input.coordRoot, path);
|
|
139
|
+
try {
|
|
140
|
+
let state = existsSync(path) ? readCommandState(path) : undefined;
|
|
141
|
+
if (state && !matchesHookState(state, hook, input, epochId)) {
|
|
142
|
+
throw new Error("V3 command producer state does not match the joined hook generation");
|
|
143
|
+
}
|
|
144
|
+
let recovered = false;
|
|
145
|
+
if (state?.pending) {
|
|
146
|
+
const pending = state.pending;
|
|
147
|
+
const durability = writeEventV3(input.coordRoot, pending.event);
|
|
148
|
+
applyCommandEvent(state, pending.source_id, pending.event);
|
|
149
|
+
state.pending = undefined;
|
|
150
|
+
publishCommandState(path, state);
|
|
151
|
+
if (pending.source_id === sourceId) {
|
|
152
|
+
maybeWriteCommandLiveDisplay(input.coordRoot, pending.event, input.observation);
|
|
153
|
+
return { state: "recorded", event: pending.event, durability, recovered: true };
|
|
154
|
+
}
|
|
155
|
+
recovered = true;
|
|
156
|
+
}
|
|
157
|
+
if (state) {
|
|
158
|
+
const already = state.observations.find((observation) => observation.source_id === sourceId);
|
|
159
|
+
if (already) return { state: "already_recorded", event_id: already.event_id };
|
|
160
|
+
}
|
|
161
|
+
if (input.signal === "command.started") {
|
|
162
|
+
if (state) {
|
|
163
|
+
return {
|
|
164
|
+
state: "already_recorded",
|
|
165
|
+
event_id: state.observations[0]?.event_id ?? state.last_event_id,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
state = newCommandState(input, hook, epochId);
|
|
169
|
+
} else if (!state) {
|
|
170
|
+
return { state: "command_span_unstarted" };
|
|
171
|
+
}
|
|
172
|
+
if (state.terminal) return { state: "command_span_unstarted" };
|
|
173
|
+
|
|
174
|
+
const fingerprintContext = fingerprintContextV3(
|
|
175
|
+
input.coordRoot,
|
|
176
|
+
rootId,
|
|
177
|
+
state.generation_id,
|
|
178
|
+
state.privacy_epoch_id,
|
|
179
|
+
);
|
|
180
|
+
const event = normalizeCommandEventV3(input.signal, input.observation, {
|
|
181
|
+
root_id: rootId,
|
|
182
|
+
instance_id: state.instance_id,
|
|
183
|
+
session_id: state.session_id,
|
|
184
|
+
generation_id: state.generation_id,
|
|
185
|
+
turn_id: state.turn_id,
|
|
186
|
+
attestation_id: state.attestation_id,
|
|
187
|
+
producer_id: input.producer_id,
|
|
188
|
+
boot_id: state.boot_id,
|
|
189
|
+
sequence: state.next_sequence,
|
|
190
|
+
build_id: input.build_id,
|
|
191
|
+
platform: input.platform,
|
|
192
|
+
bridge: input.bridge,
|
|
193
|
+
span_id: state.span_id,
|
|
194
|
+
parent_span_id: state.parent_span_id,
|
|
195
|
+
caused_by: [
|
|
196
|
+
state.last_event_id,
|
|
197
|
+
...(input.signal === "command.completed" && state.open_event_id
|
|
198
|
+
? [state.open_event_id]
|
|
199
|
+
: []),
|
|
200
|
+
].filter((value, index, values) => values.indexOf(value) === index),
|
|
201
|
+
observed_at: input.observed_at,
|
|
202
|
+
monotonic_ns: input.monotonic_ns,
|
|
203
|
+
clock_id: state.clock_id,
|
|
204
|
+
terminal_span:
|
|
205
|
+
input.signal === "command.completed"
|
|
206
|
+
? closeSpanStateV3(
|
|
207
|
+
{
|
|
208
|
+
span_id: state.span_id,
|
|
209
|
+
...(state.parent_span_id ? { parent_span_id: state.parent_span_id } : {}),
|
|
210
|
+
opened_at: state.opened_at,
|
|
211
|
+
boot_id: state.boot_id,
|
|
212
|
+
...(state.opened_monotonic_ns
|
|
213
|
+
? { opened_monotonic_ns: state.opened_monotonic_ns }
|
|
214
|
+
: {}),
|
|
215
|
+
...(state.open_event_id ? { open_event_id: state.open_event_id } : {}),
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
boot_id: state.boot_id,
|
|
219
|
+
clock: {
|
|
220
|
+
observed_at: input.observed_at ?? new Date().toISOString(),
|
|
221
|
+
...(input.monotonic_ns ? { monotonic_ns: input.monotonic_ns } : {}),
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
)
|
|
225
|
+
: undefined,
|
|
226
|
+
fingerprintContext,
|
|
227
|
+
attribution_method: "session_env",
|
|
228
|
+
});
|
|
229
|
+
if (!event) return { state: "command_span_unstarted" };
|
|
230
|
+
|
|
231
|
+
markObservedClockRegressionV3(event, state.last_observed_at);
|
|
232
|
+
state.pending = { source_id: sourceId, event };
|
|
233
|
+
publishCommandState(path, state);
|
|
234
|
+
const durability = writeEventV3(input.coordRoot, event, input.writerOptions);
|
|
235
|
+
applyCommandEvent(state, sourceId, event);
|
|
236
|
+
state.pending = undefined;
|
|
237
|
+
publishCommandState(path, state);
|
|
238
|
+
maybeWriteCommandLiveDisplay(input.coordRoot, event, input.observation);
|
|
239
|
+
return { state: "recorded", event, durability, recovered };
|
|
240
|
+
} finally {
|
|
241
|
+
lease.release();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export interface CloseAbandonedCommandSpansV3Input {
|
|
246
|
+
coordRoot: string;
|
|
247
|
+
mode: EventV3WriteMode;
|
|
248
|
+
generation_id: `gen_${string}`;
|
|
249
|
+
build_id: `build_${string}`;
|
|
250
|
+
platform: "linux" | "windows" | "macos" | "unknown";
|
|
251
|
+
observed_at: string;
|
|
252
|
+
writerOptions?: WriteEventV3Options;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export interface CloseAbandonedCommandSpansV3Result {
|
|
256
|
+
closed: number;
|
|
257
|
+
skipped: number;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Session-end command closer (ADR 0078): every non-terminal command span of
|
|
262
|
+
* the ending generation gets a derived `command.completed` with an unknown
|
|
263
|
+
* outcome, so a `process.exit` or SIGKILL that outran the CLI's finalize can
|
|
264
|
+
* no longer leave the generation with an unpaired command forever. Command
|
|
265
|
+
* spans never block turns; this exists for corpus honesty and invariant 11.
|
|
266
|
+
*/
|
|
267
|
+
export function closeAbandonedCommandSpansV3(
|
|
268
|
+
input: CloseAbandonedCommandSpansV3Input,
|
|
269
|
+
): CloseAbandonedCommandSpansV3Result {
|
|
270
|
+
const result: CloseAbandonedCommandSpansV3Result = { closed: 0, skipped: 0 };
|
|
271
|
+
const control = readEventV3ControlState(input.coordRoot);
|
|
272
|
+
if (control.state !== input.mode) return result;
|
|
273
|
+
const rootId = control.genesis.event.scope.root_id as `root_${string}`;
|
|
274
|
+
const directory = join(
|
|
275
|
+
resolve(input.coordRoot),
|
|
276
|
+
EVENT_V3_LEDGER_RELATIVE_ROOT,
|
|
277
|
+
"private-producers/session-tee",
|
|
278
|
+
);
|
|
279
|
+
if (!existsSync(directory)) return result;
|
|
280
|
+
for (const name of readdirSync(directory).filter((entry) =>
|
|
281
|
+
/^hid_[a-f0-9]{64}\.json$/.test(entry),
|
|
282
|
+
)) {
|
|
283
|
+
const path = join(directory, name);
|
|
284
|
+
let preview: CommandRecorderStateV3;
|
|
285
|
+
try {
|
|
286
|
+
preview = readCommandState(path);
|
|
287
|
+
} catch {
|
|
288
|
+
result.skipped += 1;
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
if (preview.generation_id !== input.generation_id || preview.terminal) continue;
|
|
292
|
+
let lease: ReturnType<typeof acquireCommandLease>;
|
|
293
|
+
try {
|
|
294
|
+
lease = acquireCommandLease(input.coordRoot, path);
|
|
295
|
+
} catch {
|
|
296
|
+
result.skipped += 1;
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
try {
|
|
300
|
+
const state = readCommandState(path);
|
|
301
|
+
if (state.generation_id !== input.generation_id) continue;
|
|
302
|
+
if (state.pending) {
|
|
303
|
+
const pending = state.pending;
|
|
304
|
+
writeEventV3(input.coordRoot, pending.event, input.writerOptions);
|
|
305
|
+
applyCommandEvent(state, pending.source_id, pending.event);
|
|
306
|
+
state.pending = undefined;
|
|
307
|
+
publishCommandState(path, state);
|
|
308
|
+
}
|
|
309
|
+
if (state.terminal) continue;
|
|
310
|
+
const context = fingerprintContextV3(
|
|
311
|
+
input.coordRoot,
|
|
312
|
+
rootId,
|
|
313
|
+
state.generation_id,
|
|
314
|
+
state.privacy_epoch_id,
|
|
315
|
+
);
|
|
316
|
+
const sourceId = normalizeNativeIdV3(
|
|
317
|
+
context,
|
|
318
|
+
"session-tee.observation",
|
|
319
|
+
`recovery:${state.span_id}`,
|
|
320
|
+
);
|
|
321
|
+
const event = buildEventV3("command.completed", {
|
|
322
|
+
producer: {
|
|
323
|
+
producer_id: "prd_agent-finalizer",
|
|
324
|
+
boot_id: `boot_${randomUUID()}`,
|
|
325
|
+
sequence: 1,
|
|
326
|
+
component: "session-tee",
|
|
327
|
+
build_id: input.build_id,
|
|
328
|
+
platform: input.platform,
|
|
329
|
+
},
|
|
330
|
+
scope: {
|
|
331
|
+
root_id: rootId,
|
|
332
|
+
instance_id: state.instance_id,
|
|
333
|
+
session_id: state.session_id,
|
|
334
|
+
generation_id: state.generation_id,
|
|
335
|
+
turn_id: state.turn_id,
|
|
336
|
+
},
|
|
337
|
+
attestation_id: state.attestation_id,
|
|
338
|
+
links: {
|
|
339
|
+
caused_by: [
|
|
340
|
+
state.last_event_id,
|
|
341
|
+
...(state.open_event_id ? [state.open_event_id] : []),
|
|
342
|
+
].filter((value, index, values) => values.indexOf(value) === index),
|
|
343
|
+
span_id: state.span_id,
|
|
344
|
+
...(state.parent_span_id ? { parent_span_id: state.parent_span_id } : {}),
|
|
345
|
+
},
|
|
346
|
+
provenance: {
|
|
347
|
+
source_event: "session-tee.recovery",
|
|
348
|
+
attestation: "derived",
|
|
349
|
+
confidence: "medium",
|
|
350
|
+
attribution: {
|
|
351
|
+
method: "session_env",
|
|
352
|
+
state: "verified",
|
|
353
|
+
subject_instance_id: state.instance_id,
|
|
354
|
+
},
|
|
355
|
+
},
|
|
356
|
+
observed_at: input.observed_at,
|
|
357
|
+
clock_id: state.clock_id,
|
|
358
|
+
payload: {
|
|
359
|
+
outcome: "unknown",
|
|
360
|
+
duration_ms: { state: "unknown", reason: "command_completion_not_observed" },
|
|
361
|
+
span: closeSpanStateV3(
|
|
362
|
+
{
|
|
363
|
+
span_id: state.span_id,
|
|
364
|
+
...(state.parent_span_id ? { parent_span_id: state.parent_span_id } : {}),
|
|
365
|
+
opened_at: state.opened_at,
|
|
366
|
+
boot_id: state.boot_id,
|
|
367
|
+
...(state.opened_monotonic_ns
|
|
368
|
+
? { opened_monotonic_ns: state.opened_monotonic_ns }
|
|
369
|
+
: {}),
|
|
370
|
+
...(state.open_event_id ? { open_event_id: state.open_event_id } : {}),
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
boot_id: state.boot_id,
|
|
374
|
+
clock: { observed_at: input.observed_at },
|
|
375
|
+
recovery_reason: "command_completion_not_observed",
|
|
376
|
+
},
|
|
377
|
+
),
|
|
378
|
+
recovery: { reason: "command_completion_not_observed" },
|
|
379
|
+
},
|
|
380
|
+
}) as EventV3;
|
|
381
|
+
markObservedClockRegressionV3(event, state.last_observed_at);
|
|
382
|
+
assertEventV3(event);
|
|
383
|
+
state.pending = { source_id: sourceId, event };
|
|
384
|
+
publishCommandState(path, state);
|
|
385
|
+
writeEventV3(input.coordRoot, event, input.writerOptions);
|
|
386
|
+
applyCommandEvent(state, sourceId, event);
|
|
387
|
+
state.pending = undefined;
|
|
388
|
+
publishCommandState(path, state);
|
|
389
|
+
result.closed += 1;
|
|
390
|
+
} finally {
|
|
391
|
+
lease.release();
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return result;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function newCommandState(
|
|
398
|
+
input: RecordCommandSignalV3Input,
|
|
399
|
+
hook: NonNullable<ReturnType<typeof readHookProducerStateByInstanceV3>>,
|
|
400
|
+
epochId: `pep_${string}`,
|
|
401
|
+
): CommandRecorderStateV3 {
|
|
402
|
+
const parentSpanId = selectCommandParentSpan(hook.spans, hook.current_turn_id!);
|
|
403
|
+
const bootId = `boot_${randomUUID()}` as const;
|
|
404
|
+
const opened = openSpanStateV3({
|
|
405
|
+
span_id: spanIdV3(),
|
|
406
|
+
...(parentSpanId ? { parent_span_id: parentSpanId } : {}),
|
|
407
|
+
boot_id: bootId,
|
|
408
|
+
clock: {
|
|
409
|
+
observed_at: input.observed_at ?? new Date().toISOString(),
|
|
410
|
+
...(input.monotonic_ns ? { monotonic_ns: input.monotonic_ns } : {}),
|
|
411
|
+
},
|
|
412
|
+
});
|
|
413
|
+
return {
|
|
414
|
+
format: COMMAND_STATE_FORMAT,
|
|
415
|
+
format_version: COMMAND_STATE_VERSION,
|
|
416
|
+
adapter: input.adapter,
|
|
417
|
+
instance_id: input.instance_id,
|
|
418
|
+
session_id: hook.session_id,
|
|
419
|
+
generation_id: hook.generation_id,
|
|
420
|
+
turn_id: hook.current_turn_id!,
|
|
421
|
+
attestation_id: hook.attestation_id,
|
|
422
|
+
privacy_epoch_id: epochId,
|
|
423
|
+
boot_id: bootId,
|
|
424
|
+
clock_id: clockIdV3(),
|
|
425
|
+
span_id: opened.span_id,
|
|
426
|
+
...(parentSpanId ? { parent_span_id: parentSpanId } : {}),
|
|
427
|
+
opened_at: opened.opened_at,
|
|
428
|
+
...(opened.opened_monotonic_ns ? { opened_monotonic_ns: opened.opened_monotonic_ns } : {}),
|
|
429
|
+
next_sequence: 1,
|
|
430
|
+
last_event_id: hook.last_event_id!,
|
|
431
|
+
terminal: false,
|
|
432
|
+
observations: [],
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function matchesHookState(
|
|
437
|
+
state: CommandRecorderStateV3,
|
|
438
|
+
hook: NonNullable<ReturnType<typeof readHookProducerStateByInstanceV3>>,
|
|
439
|
+
input: RecordCommandSignalV3Input,
|
|
440
|
+
epochId: string,
|
|
441
|
+
): boolean {
|
|
442
|
+
return (
|
|
443
|
+
state.adapter === input.adapter &&
|
|
444
|
+
state.instance_id === input.instance_id &&
|
|
445
|
+
state.session_id === hook.session_id &&
|
|
446
|
+
state.generation_id === hook.generation_id &&
|
|
447
|
+
state.turn_id === hook.current_turn_id &&
|
|
448
|
+
state.attestation_id === hook.attestation_id &&
|
|
449
|
+
state.privacy_epoch_id === epochId
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function observationSourceId(
|
|
454
|
+
input: RecordCommandSignalV3Input,
|
|
455
|
+
context: ReturnType<typeof fingerprintContextV3>,
|
|
456
|
+
): `hid_${string}` | undefined {
|
|
457
|
+
const nativeObservation =
|
|
458
|
+
input.signal === "command.output_observed"
|
|
459
|
+
? input.observation.native_observation_id
|
|
460
|
+
: `${input.signal}:${input.observation.native_command_id}`;
|
|
461
|
+
return nativeObservation
|
|
462
|
+
? normalizeNativeIdV3(context, "session-tee.observation", nativeObservation)
|
|
463
|
+
: undefined;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function applyCommandEvent(
|
|
467
|
+
state: CommandRecorderStateV3,
|
|
468
|
+
sourceId: `hid_${string}`,
|
|
469
|
+
event: EventV3,
|
|
470
|
+
): void {
|
|
471
|
+
// Only events on the state's own producer chain advance its sequence; the
|
|
472
|
+
// finalizer's derived closer uses a fresh boot at sequence 1.
|
|
473
|
+
if (event.producer.boot_id === state.boot_id) state.next_sequence += 1;
|
|
474
|
+
state.last_event_id = event.event_id as `evt_${string}`;
|
|
475
|
+
state.last_observed_at = event.time.observed_at;
|
|
476
|
+
state.observations.push({ source_id: sourceId, event_id: event.event_id as `evt_${string}` });
|
|
477
|
+
if (state.observations.length > MAX_OBSERVATIONS) state.observations.shift();
|
|
478
|
+
if (event.event_type === "command.started") {
|
|
479
|
+
state.open_event_id = event.event_id as `evt_${string}`;
|
|
480
|
+
}
|
|
481
|
+
if (event.event_type === "command.completed") state.terminal = true;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
function commandStatePath(coordRoot: string, commandSource: `hid_${string}`): string {
|
|
485
|
+
return join(
|
|
486
|
+
resolve(coordRoot),
|
|
487
|
+
EVENT_V3_LEDGER_RELATIVE_ROOT,
|
|
488
|
+
"private-producers/session-tee",
|
|
489
|
+
`${commandSource}.json`,
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
function acquireCommandLease(coordRoot: string, statePath: string) {
|
|
494
|
+
const directory = join(statePath, "..");
|
|
495
|
+
const producerRoot = join(resolve(coordRoot), EVENT_V3_LEDGER_RELATIVE_ROOT, "private-producers");
|
|
496
|
+
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
497
|
+
chmodSync(producerRoot, 0o700);
|
|
498
|
+
chmodSync(directory, 0o700);
|
|
499
|
+
return acquireNoClobberLease({
|
|
500
|
+
path: `${statePath}.lease`,
|
|
501
|
+
scope: "event-v3-command-producer",
|
|
502
|
+
authoritySha256: createHash("sha256")
|
|
503
|
+
.update(resolve(coordRoot))
|
|
504
|
+
.update("\0")
|
|
505
|
+
.update(statePath)
|
|
506
|
+
.digest("hex"),
|
|
507
|
+
staleAfterMs: 5_000,
|
|
508
|
+
validateStaleOwner: (owner) => owner.host === hostname() && !pidIsAlive(owner.pid),
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function publishCommandState(path: string, state: CommandRecorderStateV3): void {
|
|
513
|
+
const temporary = `${path}.tmp-${process.pid}-${randomUUID()}`;
|
|
514
|
+
let fd: number | undefined;
|
|
515
|
+
try {
|
|
516
|
+
fd = openSync(temporary, "wx", 0o600);
|
|
517
|
+
writeFileSync(fd, `${JSON.stringify(state)}\n`, "utf8");
|
|
518
|
+
fsyncSync(fd);
|
|
519
|
+
closeSync(fd);
|
|
520
|
+
fd = undefined;
|
|
521
|
+
renameSync(temporary, path);
|
|
522
|
+
chmodSync(path, 0o600);
|
|
523
|
+
fsyncParentDirectory(path);
|
|
524
|
+
} finally {
|
|
525
|
+
if (fd !== undefined) closeSync(fd);
|
|
526
|
+
if (existsSync(temporary)) unlinkSync(temporary);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function readCommandState(path: string): CommandRecorderStateV3 {
|
|
531
|
+
if ((statSync(path).mode & 0o077) !== 0) throw new Error("V3 command state is not owner-only");
|
|
532
|
+
let parsed: unknown;
|
|
533
|
+
try {
|
|
534
|
+
parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
535
|
+
} catch {
|
|
536
|
+
throw new Error("V3 command state is unreadable");
|
|
537
|
+
}
|
|
538
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
539
|
+
throw new Error("V3 command state is invalid");
|
|
540
|
+
}
|
|
541
|
+
const state = parsed as CommandRecorderStateV3;
|
|
542
|
+
const allowed = new Set([
|
|
543
|
+
"adapter",
|
|
544
|
+
"attestation_id",
|
|
545
|
+
"boot_id",
|
|
546
|
+
"clock_id",
|
|
547
|
+
"format",
|
|
548
|
+
"format_version",
|
|
549
|
+
"generation_id",
|
|
550
|
+
"instance_id",
|
|
551
|
+
"last_event_id",
|
|
552
|
+
"last_observed_at",
|
|
553
|
+
"next_sequence",
|
|
554
|
+
"observations",
|
|
555
|
+
"opened_at",
|
|
556
|
+
"opened_monotonic_ns",
|
|
557
|
+
"open_event_id",
|
|
558
|
+
"parent_span_id",
|
|
559
|
+
"pending",
|
|
560
|
+
"privacy_epoch_id",
|
|
561
|
+
"session_id",
|
|
562
|
+
"span_id",
|
|
563
|
+
"terminal",
|
|
564
|
+
"turn_id",
|
|
565
|
+
]);
|
|
566
|
+
if (
|
|
567
|
+
Object.keys(state).some((key) => !allowed.has(key)) ||
|
|
568
|
+
state.format !== COMMAND_STATE_FORMAT ||
|
|
569
|
+
state.format_version !== COMMAND_STATE_VERSION ||
|
|
570
|
+
!["claude-code", "codex", "cursor"].includes(state.adapter) ||
|
|
571
|
+
!/^inst_[a-zA-Z0-9._-]{1,128}$/.test(state.instance_id) ||
|
|
572
|
+
!/^sid_[a-f0-9]{64}$/.test(state.session_id) ||
|
|
573
|
+
!/^gen_[0-9a-f-]{36}$/.test(state.generation_id) ||
|
|
574
|
+
!/^tid_[a-f0-9]{64}$/.test(state.turn_id) ||
|
|
575
|
+
!/^att_[0-9a-f-]{36}$/.test(state.attestation_id) ||
|
|
576
|
+
!/^pep_[a-zA-Z0-9._-]+$/.test(state.privacy_epoch_id) ||
|
|
577
|
+
!/^boot_[a-zA-Z0-9._-]+$/.test(state.boot_id) ||
|
|
578
|
+
!/^clk_[0-9a-f-]{36}$/.test(state.clock_id) ||
|
|
579
|
+
!/^span_[0-9a-f-]{36}$/.test(state.span_id) ||
|
|
580
|
+
!Number.isFinite(Date.parse(state.opened_at)) ||
|
|
581
|
+
(state.opened_monotonic_ns !== undefined && !/^\d+$/.test(state.opened_monotonic_ns)) ||
|
|
582
|
+
(state.open_event_id !== undefined && !/^evt_[0-9a-f-]{36}$/.test(state.open_event_id)) ||
|
|
583
|
+
(state.parent_span_id !== undefined && !/^span_[0-9a-f-]{36}$/.test(state.parent_span_id)) ||
|
|
584
|
+
!/^evt_[0-9a-f-]{36}$/.test(state.last_event_id) ||
|
|
585
|
+
(state.last_observed_at !== undefined &&
|
|
586
|
+
!Number.isFinite(Date.parse(state.last_observed_at))) ||
|
|
587
|
+
!Number.isSafeInteger(state.next_sequence) ||
|
|
588
|
+
state.next_sequence < 1 ||
|
|
589
|
+
typeof state.terminal !== "boolean" ||
|
|
590
|
+
!Array.isArray(state.observations) ||
|
|
591
|
+
state.observations.length > MAX_OBSERVATIONS ||
|
|
592
|
+
state.observations.some(
|
|
593
|
+
(observation) =>
|
|
594
|
+
!/^hid_[a-f0-9]{64}$/.test(observation.source_id) ||
|
|
595
|
+
!/^evt_[0-9a-f-]{36}$/.test(observation.event_id),
|
|
596
|
+
) ||
|
|
597
|
+
(state.pending !== undefined &&
|
|
598
|
+
(!/^hid_[a-f0-9]{64}$/.test(state.pending.source_id) ||
|
|
599
|
+
!validateEventV3(state.pending.event).ok))
|
|
600
|
+
) {
|
|
601
|
+
throw new Error("V3 command state is invalid");
|
|
602
|
+
}
|
|
603
|
+
return state;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
function pidIsAlive(pid: number): boolean {
|
|
607
|
+
if (!Number.isSafeInteger(pid) || pid < 1) return false;
|
|
608
|
+
try {
|
|
609
|
+
process.kill(pid, 0);
|
|
610
|
+
return true;
|
|
611
|
+
} catch (error) {
|
|
612
|
+
return (error as NodeJS.ErrnoException).code !== "ESRCH";
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
function maybeWriteCommandLiveDisplay(
|
|
617
|
+
coordRoot: string,
|
|
618
|
+
event: EventV3,
|
|
619
|
+
observation: CommandObservationV3,
|
|
620
|
+
): void {
|
|
621
|
+
if (event.event_type !== "command.started") return;
|
|
622
|
+
if (!("generation_id" in event.scope)) return;
|
|
623
|
+
const intent = observation.intent;
|
|
624
|
+
if (typeof intent !== "string" || intent.length === 0) return;
|
|
625
|
+
tryWriteLiveDisplayV3(coordRoot, {
|
|
626
|
+
generation_id: event.scope.generation_id,
|
|
627
|
+
event_id: event.event_id,
|
|
628
|
+
executable: event.payload.executable,
|
|
629
|
+
intent_display: intent,
|
|
630
|
+
});
|
|
631
|
+
}
|