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,419 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import {
|
|
3
|
+
chmodSync,
|
|
4
|
+
closeSync,
|
|
5
|
+
existsSync,
|
|
6
|
+
fsyncSync,
|
|
7
|
+
lstatSync,
|
|
8
|
+
mkdirSync,
|
|
9
|
+
openSync,
|
|
10
|
+
readdirSync,
|
|
11
|
+
readFileSync,
|
|
12
|
+
readSync,
|
|
13
|
+
renameSync,
|
|
14
|
+
statSync,
|
|
15
|
+
truncateSync,
|
|
16
|
+
unlinkSync,
|
|
17
|
+
writeFileSync,
|
|
18
|
+
writeSync,
|
|
19
|
+
} from "node:fs";
|
|
20
|
+
import { hostname } from "node:os";
|
|
21
|
+
import { join, resolve } from "node:path";
|
|
22
|
+
import { fsyncParentDirectory } from "../../workflow/durable-record.ts";
|
|
23
|
+
import { acquireNoClobberLease } from "../../workflow/workspaces/leases.ts";
|
|
24
|
+
import { canonicalJsonV3, sha256V3 } from "./canonical.ts";
|
|
25
|
+
import type { EventV3 } from "./contract.ts";
|
|
26
|
+
import { EVENT_V3_SCHEMA_DIGEST } from "./generated.ts";
|
|
27
|
+
import { assertEventV3 } from "./validate.ts";
|
|
28
|
+
|
|
29
|
+
const MAX_LINE_BYTES = 16 * 1024;
|
|
30
|
+
const DEFAULT_LEASE_MS = 5_000;
|
|
31
|
+
|
|
32
|
+
export const EVENT_V3_LEDGER_RELATIVE_ROOT = ".harnery/ledgers/v3" as const;
|
|
33
|
+
|
|
34
|
+
export type EventV3DurabilityState = "committed" | "ready";
|
|
35
|
+
|
|
36
|
+
export interface WriteEventV3Result {
|
|
37
|
+
state: EventV3DurabilityState;
|
|
38
|
+
event_id: string;
|
|
39
|
+
row_digest: `sha256:${string}`;
|
|
40
|
+
ready_path?: string;
|
|
41
|
+
diagnostic_code?: "wal_drain_failed";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface WriteEventV3Options {
|
|
45
|
+
leaseMs?: number;
|
|
46
|
+
/**
|
|
47
|
+
* Leave the durable row in the ready WAL instead of draining it into the
|
|
48
|
+
* active authority during this call. A later `drainReadyEventsV3` commits
|
|
49
|
+
* the batch under one append lease. Production writers default to false;
|
|
50
|
+
* the option exists for matched harness-cost experiments.
|
|
51
|
+
*/
|
|
52
|
+
deferDrain?: boolean;
|
|
53
|
+
now?: () => number;
|
|
54
|
+
onStep?: (step: EventV3WriteStep, eventId?: string) => void;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type EventV3WriteStep =
|
|
58
|
+
| "ready_temp_flushed"
|
|
59
|
+
| "ready_published"
|
|
60
|
+
| "active_tail_repaired"
|
|
61
|
+
| "active_row_appended"
|
|
62
|
+
| "active_row_flushed"
|
|
63
|
+
| "receipt_committed"
|
|
64
|
+
| "receipt_removed";
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Persist one already-normalized V3 event through the spool-first WAL.
|
|
68
|
+
*
|
|
69
|
+
* A successful ready rename is the durability boundary. Lease contention or
|
|
70
|
+
* append failure leaves that ready record recoverable and returns `ready`
|
|
71
|
+
* instead of changing the producing tool's result.
|
|
72
|
+
*/
|
|
73
|
+
export function writeEventV3(
|
|
74
|
+
coordRoot: string,
|
|
75
|
+
event: EventV3,
|
|
76
|
+
options: WriteEventV3Options = {},
|
|
77
|
+
): WriteEventV3Result {
|
|
78
|
+
assertEventV3(event);
|
|
79
|
+
if (event.contract.schema_digest !== EVENT_V3_SCHEMA_DIGEST) {
|
|
80
|
+
throw new Error("event schema digest is not accepted by this V3 writer");
|
|
81
|
+
}
|
|
82
|
+
const row = `${canonicalJsonV3(event)}\n`;
|
|
83
|
+
const bytes = Buffer.byteLength(row, "utf8");
|
|
84
|
+
if (bytes > MAX_LINE_BYTES) {
|
|
85
|
+
throw new Error(`event exceeds the V3 ${MAX_LINE_BYTES}-byte row limit`);
|
|
86
|
+
}
|
|
87
|
+
const paths = ensureEventV3Layout(coordRoot);
|
|
88
|
+
const rowDigest = sha256V3(row);
|
|
89
|
+
const readyName = `${String(event.producer.sequence).padStart(16, "0")}-${event.event_id}-${rowDigest.slice(7)}.ready`;
|
|
90
|
+
const readyPath = join(paths.spool, readyName);
|
|
91
|
+
writeReadyRecord(paths.spool, readyPath, row, event.event_id, options.onStep);
|
|
92
|
+
|
|
93
|
+
if (options.deferDrain) {
|
|
94
|
+
return {
|
|
95
|
+
state: "ready",
|
|
96
|
+
event_id: event.event_id,
|
|
97
|
+
row_digest: rowDigest,
|
|
98
|
+
ready_path: readyPath,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
drainReadyEventsV3(coordRoot, options);
|
|
104
|
+
} catch {
|
|
105
|
+
return {
|
|
106
|
+
state: "ready",
|
|
107
|
+
event_id: event.event_id,
|
|
108
|
+
row_digest: rowDigest,
|
|
109
|
+
ready_path: readyPath,
|
|
110
|
+
diagnostic_code: "wal_drain_failed",
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
return existsSync(readyPath)
|
|
114
|
+
? {
|
|
115
|
+
state: "ready",
|
|
116
|
+
event_id: event.event_id,
|
|
117
|
+
row_digest: rowDigest,
|
|
118
|
+
ready_path: readyPath,
|
|
119
|
+
}
|
|
120
|
+
: { state: "committed", event_id: event.event_id, row_digest: rowDigest };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Drain every durable ready record under the fenced append lease. */
|
|
124
|
+
export function drainReadyEventsV3(coordRoot: string, options: WriteEventV3Options = {}): number {
|
|
125
|
+
const paths = ensureEventV3Layout(coordRoot);
|
|
126
|
+
return withEventV3LedgerLease(coordRoot, options, () =>
|
|
127
|
+
drainReadyEventsUnderLeaseV3(paths, options),
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function withEventV3LedgerLease<T>(
|
|
132
|
+
coordRoot: string,
|
|
133
|
+
options: WriteEventV3Options,
|
|
134
|
+
operation: () => T,
|
|
135
|
+
): T {
|
|
136
|
+
const paths = ensureEventV3Layout(coordRoot);
|
|
137
|
+
const authority = createHash("sha256")
|
|
138
|
+
.update(resolve(coordRoot))
|
|
139
|
+
.update("\0")
|
|
140
|
+
.update(EVENT_V3_SCHEMA_DIGEST)
|
|
141
|
+
.digest("hex");
|
|
142
|
+
const lease = acquireNoClobberLease({
|
|
143
|
+
path: paths.lease,
|
|
144
|
+
scope: "event-v3-append",
|
|
145
|
+
authoritySha256: authority,
|
|
146
|
+
staleAfterMs: options.leaseMs ?? DEFAULT_LEASE_MS,
|
|
147
|
+
now: options.now,
|
|
148
|
+
validateStaleOwner: (owner) => owner.host === hostname() && !pidIsAlive(owner.pid),
|
|
149
|
+
});
|
|
150
|
+
try {
|
|
151
|
+
return operation();
|
|
152
|
+
} finally {
|
|
153
|
+
lease.release();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function drainReadyEventsUnderLeaseV3(
|
|
158
|
+
paths: ReturnType<typeof eventV3Paths>,
|
|
159
|
+
options: WriteEventV3Options = {},
|
|
160
|
+
): number {
|
|
161
|
+
if (repairUnterminatedActiveFrame(paths.active)) {
|
|
162
|
+
options.onStep?.("active_tail_repaired");
|
|
163
|
+
}
|
|
164
|
+
requeueCommittedReceipts(paths.spool);
|
|
165
|
+
const readyNames = readdirSync(paths.spool)
|
|
166
|
+
.filter((name) => name.endsWith(".ready"))
|
|
167
|
+
.sort();
|
|
168
|
+
if (readyNames.length === 0) return 0;
|
|
169
|
+
const readyRows = causallyOrderedReadyRows(
|
|
170
|
+
readyNames.map((readyName) => {
|
|
171
|
+
const readyPath = join(paths.spool, readyName);
|
|
172
|
+
const row = readAndValidateReadyRow(readyPath);
|
|
173
|
+
return {
|
|
174
|
+
readyName,
|
|
175
|
+
readyPath,
|
|
176
|
+
row,
|
|
177
|
+
event: JSON.parse(row) as EventV3,
|
|
178
|
+
};
|
|
179
|
+
}),
|
|
180
|
+
);
|
|
181
|
+
const activeFd = openSync(paths.active, "a", 0o600);
|
|
182
|
+
let committed = 0;
|
|
183
|
+
try {
|
|
184
|
+
for (const { readyName, readyPath, row } of readyRows) {
|
|
185
|
+
const eventId = eventIdFromReadyName(readyName);
|
|
186
|
+
writeSync(activeFd, row, undefined, "utf8");
|
|
187
|
+
options.onStep?.("active_row_appended", eventId);
|
|
188
|
+
fsyncSync(activeFd);
|
|
189
|
+
options.onStep?.("active_row_flushed", eventId);
|
|
190
|
+
const committedPath = `${readyPath.slice(0, -".ready".length)}.committed`;
|
|
191
|
+
renameSync(readyPath, committedPath);
|
|
192
|
+
fsyncParentDirectory(committedPath);
|
|
193
|
+
options.onStep?.("receipt_committed", eventId);
|
|
194
|
+
unlinkSync(committedPath);
|
|
195
|
+
fsyncParentDirectory(committedPath);
|
|
196
|
+
options.onStep?.("receipt_removed", eventId);
|
|
197
|
+
committed += 1;
|
|
198
|
+
}
|
|
199
|
+
} finally {
|
|
200
|
+
closeSync(activeFd);
|
|
201
|
+
}
|
|
202
|
+
return committed;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
interface ReadyEventRowV3 {
|
|
206
|
+
readyName: string;
|
|
207
|
+
readyPath: string;
|
|
208
|
+
row: string;
|
|
209
|
+
event: EventV3;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Keep the spool's deterministic filename order except where a ready event
|
|
214
|
+
* names another ready event as a cause. Those dependencies are committed
|
|
215
|
+
* first; a cycle stays in the WAL and never poisons the active authority.
|
|
216
|
+
*/
|
|
217
|
+
function causallyOrderedReadyRows(rows: ReadyEventRowV3[]): ReadyEventRowV3[] {
|
|
218
|
+
const pending = new Map(rows.map((row) => [row.event.event_id, row]));
|
|
219
|
+
const ordered: ReadyEventRowV3[] = [];
|
|
220
|
+
while (pending.size > 0) {
|
|
221
|
+
const next = rows.find(({ event }) => {
|
|
222
|
+
const causes = (event.links as { caused_by: string[] }).caused_by;
|
|
223
|
+
return pending.has(event.event_id) && causes.every((eventId) => !pending.has(eventId));
|
|
224
|
+
});
|
|
225
|
+
if (!next) throw new Error("ready V3 events contain a causal dependency cycle");
|
|
226
|
+
pending.delete(next.event.event_id);
|
|
227
|
+
ordered.push(next);
|
|
228
|
+
}
|
|
229
|
+
return ordered;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* A `.committed` receipt is created only after the active row is flushed. If
|
|
234
|
+
* the process dies before unlinking it, replaying the exact canonical row is
|
|
235
|
+
* safe: the validating reader deduplicates the event ID and detects conflicts.
|
|
236
|
+
*/
|
|
237
|
+
function requeueCommittedReceipts(spool: string): void {
|
|
238
|
+
const committedNames = readdirSync(spool)
|
|
239
|
+
.filter((name) => name.endsWith(".committed"))
|
|
240
|
+
.sort();
|
|
241
|
+
for (const committedName of committedNames) {
|
|
242
|
+
const committedPath = join(spool, committedName);
|
|
243
|
+
readAndValidateReadyRow(committedPath);
|
|
244
|
+
const readyPath = `${committedPath.slice(0, -".committed".length)}.ready`;
|
|
245
|
+
if (existsSync(readyPath)) {
|
|
246
|
+
if (readFileSync(readyPath, "utf8") !== readFileSync(committedPath, "utf8")) {
|
|
247
|
+
throw new Error("committed and ready receipts conflict");
|
|
248
|
+
}
|
|
249
|
+
unlinkSync(committedPath);
|
|
250
|
+
} else {
|
|
251
|
+
renameSync(committedPath, readyPath);
|
|
252
|
+
}
|
|
253
|
+
fsyncParentDirectory(readyPath);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export function eventV3Paths(coordRoot: string) {
|
|
258
|
+
const root = join(resolve(coordRoot), EVENT_V3_LEDGER_RELATIVE_ROOT);
|
|
259
|
+
return {
|
|
260
|
+
root,
|
|
261
|
+
active: join(root, "active.ndjson"),
|
|
262
|
+
catalog: join(root, "catalog.json"),
|
|
263
|
+
spool: join(root, "spool"),
|
|
264
|
+
diagnostics: join(root, "diagnostics"),
|
|
265
|
+
segments: join(root, "segments"),
|
|
266
|
+
authorityOutbox: join(root, "authority-outbox"),
|
|
267
|
+
lease: join(root, "append-lease"),
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export function ensureEventV3Layout(coordRoot: string) {
|
|
272
|
+
assertSupportedPath(coordRoot);
|
|
273
|
+
const paths = eventV3Paths(coordRoot);
|
|
274
|
+
for (const path of [
|
|
275
|
+
paths.root,
|
|
276
|
+
paths.spool,
|
|
277
|
+
paths.diagnostics,
|
|
278
|
+
paths.segments,
|
|
279
|
+
paths.authorityOutbox,
|
|
280
|
+
]) {
|
|
281
|
+
mkdirSync(path, { recursive: true, mode: 0o700 });
|
|
282
|
+
chmodSync(path, 0o700);
|
|
283
|
+
}
|
|
284
|
+
if (!existsSync(paths.active)) {
|
|
285
|
+
let fd: number | undefined;
|
|
286
|
+
try {
|
|
287
|
+
fd = openSync(paths.active, "wx", 0o600);
|
|
288
|
+
fsyncSync(fd);
|
|
289
|
+
fsyncParentDirectory(paths.active);
|
|
290
|
+
} catch (error) {
|
|
291
|
+
if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
|
|
292
|
+
} finally {
|
|
293
|
+
if (fd !== undefined) closeSync(fd);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
const active = lstatSync(paths.active);
|
|
297
|
+
if (!active.isFile() || active.isSymbolicLink() || (active.mode & 0o077) !== 0) {
|
|
298
|
+
throw new Error("active V3 ledger must be an owner-only regular file");
|
|
299
|
+
}
|
|
300
|
+
return paths;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function writeReadyRecord(
|
|
304
|
+
spool: string,
|
|
305
|
+
readyPath: string,
|
|
306
|
+
row: string,
|
|
307
|
+
eventId: string,
|
|
308
|
+
onStep?: WriteEventV3Options["onStep"],
|
|
309
|
+
): void {
|
|
310
|
+
const temporary = join(spool, `.tmp-${process.pid}-${randomUUID()}`);
|
|
311
|
+
let fd: number | undefined;
|
|
312
|
+
try {
|
|
313
|
+
fd = openSync(temporary, "wx", 0o600);
|
|
314
|
+
writeFileSync(fd, row, "utf8");
|
|
315
|
+
fsyncSync(fd);
|
|
316
|
+
onStep?.("ready_temp_flushed", eventId);
|
|
317
|
+
closeSync(fd);
|
|
318
|
+
fd = undefined;
|
|
319
|
+
renameSync(temporary, readyPath);
|
|
320
|
+
fsyncParentDirectory(readyPath);
|
|
321
|
+
onStep?.("ready_published", eventId);
|
|
322
|
+
} finally {
|
|
323
|
+
if (fd !== undefined) closeSync(fd);
|
|
324
|
+
if (existsSync(temporary)) unlinkSync(temporary);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function readAndValidateReadyRow(path: string): string {
|
|
329
|
+
const size = statSync(path).size;
|
|
330
|
+
if (size <= 1 || size > MAX_LINE_BYTES) throw new Error("ready event has invalid size");
|
|
331
|
+
const row = readFileSync(path, "utf8");
|
|
332
|
+
if (!row.endsWith("\n") || row.slice(0, -1).includes("\n")) {
|
|
333
|
+
throw new Error("ready event is not one complete frame");
|
|
334
|
+
}
|
|
335
|
+
let parsed: unknown;
|
|
336
|
+
try {
|
|
337
|
+
parsed = JSON.parse(row);
|
|
338
|
+
} catch {
|
|
339
|
+
throw new Error("ready event is not valid JSON");
|
|
340
|
+
}
|
|
341
|
+
assertEventV3(parsed);
|
|
342
|
+
if (`${canonicalJsonV3(parsed)}\n` !== row) {
|
|
343
|
+
throw new Error("ready event is not canonically serialized");
|
|
344
|
+
}
|
|
345
|
+
return row;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function repairUnterminatedActiveFrame(activePath: string): boolean {
|
|
349
|
+
const size = statSync(activePath).size;
|
|
350
|
+
if (size === 0) return false;
|
|
351
|
+
const tailBytes = Math.min(size, MAX_LINE_BYTES + 1);
|
|
352
|
+
const fd = openSync(activePath, "r");
|
|
353
|
+
const tail = Buffer.allocUnsafe(tailBytes);
|
|
354
|
+
try {
|
|
355
|
+
const bytesRead = readFileTail(fd, tail, size - tailBytes);
|
|
356
|
+
if (bytesRead > 0 && tail[bytesRead - 1] === 0x0a) return false;
|
|
357
|
+
const lastNewline = tail.lastIndexOf(0x0a, bytesRead - 1);
|
|
358
|
+
if (lastNewline < 0 && size > MAX_LINE_BYTES) {
|
|
359
|
+
throw new Error("active V3 tail exceeds the frame limit without a boundary");
|
|
360
|
+
}
|
|
361
|
+
const repairedSize = size - tailBytes + Math.max(0, lastNewline + 1);
|
|
362
|
+
truncateSync(activePath, repairedSize);
|
|
363
|
+
} finally {
|
|
364
|
+
closeSync(fd);
|
|
365
|
+
}
|
|
366
|
+
const repairFd = openSync(activePath, "r+");
|
|
367
|
+
try {
|
|
368
|
+
fsyncSync(repairFd);
|
|
369
|
+
} finally {
|
|
370
|
+
closeSync(repairFd);
|
|
371
|
+
}
|
|
372
|
+
fsyncParentDirectory(activePath);
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function eventIdFromReadyName(name: string): string | undefined {
|
|
377
|
+
const match = name.match(/^\d{16}-(evt_[0-9a-f-]{36})-/);
|
|
378
|
+
return match?.[1];
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function readFileTail(fd: number, buffer: Buffer, position: number): number {
|
|
382
|
+
let read = 0;
|
|
383
|
+
while (read < buffer.length) {
|
|
384
|
+
const count = requireReadSync(fd, buffer, read, buffer.length - read, position + read);
|
|
385
|
+
if (count === 0) break;
|
|
386
|
+
read += count;
|
|
387
|
+
}
|
|
388
|
+
return read;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
function requireReadSync(
|
|
392
|
+
fd: number,
|
|
393
|
+
buffer: Buffer,
|
|
394
|
+
offset: number,
|
|
395
|
+
length: number,
|
|
396
|
+
position: number,
|
|
397
|
+
): number {
|
|
398
|
+
// Kept in one helper so the storage state machine has a single positional-read seam.
|
|
399
|
+
return readSync(fd, buffer, offset, length, position);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function pidIsAlive(pid: number): boolean {
|
|
403
|
+
if (!Number.isSafeInteger(pid) || pid < 1) return false;
|
|
404
|
+
try {
|
|
405
|
+
process.kill(pid, 0);
|
|
406
|
+
return true;
|
|
407
|
+
} catch (error) {
|
|
408
|
+
return (error as NodeJS.ErrnoException).code !== "ESRCH";
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function assertSupportedPath(coordRoot: string): void {
|
|
413
|
+
if (
|
|
414
|
+
/^(\\\\|\/\/wsl(?:\.localhost)?\/)/i.test(coordRoot) ||
|
|
415
|
+
/^\/mnt\/[a-z](?:\/|$)/i.test(coordRoot)
|
|
416
|
+
) {
|
|
417
|
+
throw new Error("V3 writer refuses direct UNC or cross-boundary coordination roots");
|
|
418
|
+
}
|
|
419
|
+
}
|
|
@@ -80,12 +80,15 @@ export {
|
|
|
80
80
|
type GovernorAutomationPolicy,
|
|
81
81
|
type GovernorIntent,
|
|
82
82
|
type GovernorLimits,
|
|
83
|
+
type GovernorListResult,
|
|
84
|
+
type GovernorListWarning,
|
|
83
85
|
type GovernorMission,
|
|
84
86
|
type GovernorNextAction,
|
|
85
87
|
type GovernorProjection,
|
|
86
88
|
type GovernorRecord,
|
|
87
89
|
type GovernorState,
|
|
88
90
|
listGovernors,
|
|
91
|
+
listGovernorsWithWarnings,
|
|
89
92
|
newGovernorId,
|
|
90
93
|
readGovernor,
|
|
91
94
|
} from "./state.ts";
|
|
@@ -5,7 +5,12 @@ import {
|
|
|
5
5
|
reopenGovernorMissionPlan,
|
|
6
6
|
retryGovernorPlanProposal,
|
|
7
7
|
} from "./planning.ts";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
acquireGovernorLease,
|
|
10
|
+
type GovernorListWarning,
|
|
11
|
+
listGovernorsWithWarnings,
|
|
12
|
+
readGovernorIgnoringLease,
|
|
13
|
+
} from "./state.ts";
|
|
9
14
|
|
|
10
15
|
export function approveGovernorPlan(input: {
|
|
11
16
|
coordRoot: string;
|
|
@@ -60,8 +65,11 @@ export function rejectGovernorPlan(input: {
|
|
|
60
65
|
export function findCompletedMissionGoverning(
|
|
61
66
|
coordRoot: string,
|
|
62
67
|
workId: string,
|
|
68
|
+
onWarning?: (warning: GovernorListWarning) => void,
|
|
63
69
|
): string | undefined {
|
|
64
|
-
|
|
70
|
+
const result = listGovernorsWithWarnings(coordRoot);
|
|
71
|
+
for (const warning of result.warnings) onWarning?.(warning);
|
|
72
|
+
for (const record of result.records) {
|
|
65
73
|
if (record.projection.state !== "succeeded" || !record.intent.mission) continue;
|
|
66
74
|
if (record.projection.root_work_id === workId || record.projection.work_ids.includes(workId)) {
|
|
67
75
|
return record.intent.id;
|
|
@@ -49,11 +49,14 @@ export {
|
|
|
49
49
|
type GovernorAutomationPolicy,
|
|
50
50
|
type GovernorIntent,
|
|
51
51
|
type GovernorLimits,
|
|
52
|
+
type GovernorListResult,
|
|
53
|
+
type GovernorListWarning,
|
|
52
54
|
type GovernorMission,
|
|
53
55
|
type GovernorNextAction,
|
|
54
56
|
type GovernorProjection,
|
|
55
57
|
type GovernorRecord,
|
|
56
58
|
type GovernorState,
|
|
57
59
|
listGovernors,
|
|
60
|
+
listGovernorsWithWarnings,
|
|
58
61
|
readGovernor,
|
|
59
62
|
} from "./state.ts";
|
|
@@ -37,6 +37,13 @@ const MAX_ACCEPTANCE = 50;
|
|
|
37
37
|
const MAX_INTENT_BYTES = 256 * 1024;
|
|
38
38
|
const MAX_TEMPLATES = 20;
|
|
39
39
|
const TEMPLATE_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
40
|
+
const GOVERNOR_SPECIALIST_PROFILE_KEYS = [
|
|
41
|
+
"instructions",
|
|
42
|
+
"adapter",
|
|
43
|
+
"effort",
|
|
44
|
+
"maxAttempts",
|
|
45
|
+
] as const;
|
|
46
|
+
const GOVERNOR_SPECIALIST_PROFILE_KEY_SET = new Set<string>(GOVERNOR_SPECIALIST_PROFILE_KEYS);
|
|
40
47
|
const FOREIGN_LEASE_STALE_MS = 24 * 60 * 60 * 1_000;
|
|
41
48
|
/** Ceiling on CONSECUTIVE uncharged (upstream) replans (ADR 0046). Because an
|
|
42
49
|
* uncharged replan does not spend `max_replans`, an unending vendor outage would
|
|
@@ -159,6 +166,16 @@ export interface GovernorRecord {
|
|
|
159
166
|
plans: GovernorPlanRecord[];
|
|
160
167
|
}
|
|
161
168
|
|
|
169
|
+
export interface GovernorListWarning {
|
|
170
|
+
goal_id: string;
|
|
171
|
+
reason: string;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface GovernorListResult {
|
|
175
|
+
records: GovernorRecord[];
|
|
176
|
+
warnings: GovernorListWarning[];
|
|
177
|
+
}
|
|
178
|
+
|
|
162
179
|
export interface CreateGovernorInput {
|
|
163
180
|
coordRoot: string;
|
|
164
181
|
rootWorkId?: string;
|
|
@@ -175,6 +192,7 @@ export function createGovernor(input: CreateGovernorInput): GovernorRecord {
|
|
|
175
192
|
const coordRoot = resolve(input.coordRoot);
|
|
176
193
|
const id = input.id ?? newGovernorId();
|
|
177
194
|
assertGovernorId(id);
|
|
195
|
+
assertGovernorSpecialistProfileKeys(input.specialists);
|
|
178
196
|
const mission = input.mission ? normalizeMission(input.mission) : undefined;
|
|
179
197
|
if (mission && !input.replanning) {
|
|
180
198
|
throw new Error("governor mission requires a replanning policy");
|
|
@@ -231,16 +249,28 @@ export function readGovernorIgnoringLease(coordRoot: string, goalId: string): Go
|
|
|
231
249
|
}
|
|
232
250
|
|
|
233
251
|
export function listGovernors(coordRoot: string): GovernorRecord[] {
|
|
252
|
+
return listGovernorsWithWarnings(coordRoot).records;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export function listGovernorsWithWarnings(coordRoot: string): GovernorListResult {
|
|
234
256
|
const base = join(resolve(coordRoot), ".harnery", "governors");
|
|
235
|
-
if (!existsSync(base)) return [];
|
|
257
|
+
if (!existsSync(base)) return { records: [], warnings: [] };
|
|
236
258
|
const records: GovernorRecord[] = [];
|
|
259
|
+
const warnings: GovernorListWarning[] = [];
|
|
237
260
|
for (const name of readdirSync(base)) {
|
|
238
261
|
if (!GOAL_ID.test(name) || !existsSync(governorIntentPath(coordRoot, name))) continue;
|
|
239
|
-
|
|
262
|
+
try {
|
|
263
|
+
records.push(readGovernor(coordRoot, name));
|
|
264
|
+
} catch (error) {
|
|
265
|
+
warnings.push({
|
|
266
|
+
goal_id: name,
|
|
267
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
268
|
+
});
|
|
269
|
+
}
|
|
240
270
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
271
|
+
records.sort((left, right) => right.intent.created_at.localeCompare(left.intent.created_at));
|
|
272
|
+
warnings.sort((left, right) => left.goal_id.localeCompare(right.goal_id));
|
|
273
|
+
return { records, warnings };
|
|
244
274
|
}
|
|
245
275
|
|
|
246
276
|
export function collectGovernorWork(coordRoot: string, rootWorkId: string): WorkRecord[] {
|
|
@@ -882,6 +912,23 @@ function validateIntent(intent: GovernorIntent, goalId: string): void {
|
|
|
882
912
|
if (intent.replanning) validateReplanning(intent.replanning, specialists, intent.limits, goalId);
|
|
883
913
|
}
|
|
884
914
|
|
|
915
|
+
function assertGovernorSpecialistProfileKeys(
|
|
916
|
+
specialists: Readonly<Record<string, WorkflowSpecialistProfile>>,
|
|
917
|
+
): void {
|
|
918
|
+
if (!specialists || typeof specialists !== "object" || Array.isArray(specialists)) return;
|
|
919
|
+
for (const [id, profile] of Object.entries(specialists)) {
|
|
920
|
+
if (!profile || typeof profile !== "object" || Array.isArray(profile)) continue;
|
|
921
|
+
const unsupported = Object.keys(profile)
|
|
922
|
+
.filter((key) => !GOVERNOR_SPECIALIST_PROFILE_KEY_SET.has(key))
|
|
923
|
+
.sort();
|
|
924
|
+
if (unsupported.length === 0) continue;
|
|
925
|
+
throw new Error(
|
|
926
|
+
`governor specialist ${id} has unsupported key ${JSON.stringify(unsupported[0])}; ` +
|
|
927
|
+
`allowed keys: ${GOVERNOR_SPECIALIST_PROFILE_KEYS.join(", ")}`,
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
|
|
885
932
|
function normalizeMission(input: CreateGovernorMissionInput): GovernorMission {
|
|
886
933
|
if (!Array.isArray(input.acceptance)) {
|
|
887
934
|
throw new Error("governor mission acceptance must be an array");
|