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,646 @@
|
|
|
1
|
+
export const DOCS_METADATA_SCHEMA_V2 = "harnery-doc/v2";
|
|
2
|
+
|
|
3
|
+
export const DOCS_METADATA_TYPES = [
|
|
4
|
+
"plan",
|
|
5
|
+
"issue",
|
|
6
|
+
"handoff",
|
|
7
|
+
"runbook",
|
|
8
|
+
"topic",
|
|
9
|
+
"audit",
|
|
10
|
+
"book",
|
|
11
|
+
"entity",
|
|
12
|
+
"concept",
|
|
13
|
+
"query",
|
|
14
|
+
"page",
|
|
15
|
+
"inquiry",
|
|
16
|
+
"quote-sheet",
|
|
17
|
+
"weekly-post",
|
|
18
|
+
"synced-page",
|
|
19
|
+
] as const;
|
|
20
|
+
|
|
21
|
+
export type DocsMetadataType = (typeof DOCS_METADATA_TYPES)[number];
|
|
22
|
+
|
|
23
|
+
export type DocsMetadataProfile =
|
|
24
|
+
| "lifecycle"
|
|
25
|
+
| "runbook"
|
|
26
|
+
| "wiki"
|
|
27
|
+
| "synced"
|
|
28
|
+
| "quote-sheet"
|
|
29
|
+
| "weekly-post"
|
|
30
|
+
| "inquiry"
|
|
31
|
+
| "general";
|
|
32
|
+
|
|
33
|
+
export interface DocsMetadataValidationIssue {
|
|
34
|
+
severity: "error" | "warning";
|
|
35
|
+
code: string;
|
|
36
|
+
field: string;
|
|
37
|
+
message: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface DocsMetadataValidationResult {
|
|
41
|
+
valid: boolean;
|
|
42
|
+
profile: DocsMetadataProfile | null;
|
|
43
|
+
issues: DocsMetadataValidationIssue[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const RFC3339_UTC_SECONDS = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/;
|
|
47
|
+
const SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
48
|
+
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
49
|
+
|
|
50
|
+
const PLAN_STATUSES = new Set(["proposed", "in-progress", "shipped", "abandoned"]);
|
|
51
|
+
const ISSUE_STATUSES = new Set(["open", "resolved", "wontfix"]);
|
|
52
|
+
const HANDOFF_STATUSES = new Set(["open", "resolved", "abandoned"]);
|
|
53
|
+
const ISSUE_SEVERITIES = new Set(["low", "medium", "high", "critical"]);
|
|
54
|
+
const LIFECYCLE_TYPES = new Set<DocsMetadataType>(["plan", "issue", "handoff"]);
|
|
55
|
+
const WIKI_TYPES = new Set<DocsMetadataType>(["book", "entity", "concept", "query", "page"]);
|
|
56
|
+
const SUPPORTED_TYPES = new Set<DocsMetadataType>(DOCS_METADATA_TYPES);
|
|
57
|
+
|
|
58
|
+
const BASE_FIELDS = new Set([
|
|
59
|
+
"schema",
|
|
60
|
+
"type",
|
|
61
|
+
"created_at",
|
|
62
|
+
"updated_at",
|
|
63
|
+
"owner",
|
|
64
|
+
"summary",
|
|
65
|
+
"tags",
|
|
66
|
+
"relations",
|
|
67
|
+
"access",
|
|
68
|
+
]);
|
|
69
|
+
|
|
70
|
+
const PROFILE_FIELDS: Record<DocsMetadataProfile, ReadonlySet<string>> = {
|
|
71
|
+
lifecycle: new Set([
|
|
72
|
+
...BASE_FIELDS,
|
|
73
|
+
"status",
|
|
74
|
+
"status_changed_at",
|
|
75
|
+
"status_note",
|
|
76
|
+
"severity",
|
|
77
|
+
"resolved_at",
|
|
78
|
+
"affected",
|
|
79
|
+
"resolution",
|
|
80
|
+
]),
|
|
81
|
+
runbook: new Set([...BASE_FIELDS, "title", "audience", "source", "reviewed_at", "review_due_at"]),
|
|
82
|
+
wiki: new Set([
|
|
83
|
+
...BASE_FIELDS,
|
|
84
|
+
"title",
|
|
85
|
+
"category",
|
|
86
|
+
"aliases",
|
|
87
|
+
"source_count",
|
|
88
|
+
"provenance",
|
|
89
|
+
"primary_entity",
|
|
90
|
+
"source_pages",
|
|
91
|
+
"source_tokens",
|
|
92
|
+
"top_entities",
|
|
93
|
+
]),
|
|
94
|
+
synced: new Set([
|
|
95
|
+
...BASE_FIELDS,
|
|
96
|
+
"title",
|
|
97
|
+
"handle",
|
|
98
|
+
"published",
|
|
99
|
+
"source",
|
|
100
|
+
"source_updated_at",
|
|
101
|
+
"source_id",
|
|
102
|
+
"source_template",
|
|
103
|
+
]),
|
|
104
|
+
"quote-sheet": new Set([
|
|
105
|
+
...BASE_FIELDS,
|
|
106
|
+
"title",
|
|
107
|
+
"status",
|
|
108
|
+
"product",
|
|
109
|
+
"variant",
|
|
110
|
+
"sku",
|
|
111
|
+
"manufacturer",
|
|
112
|
+
"customer",
|
|
113
|
+
"bid_id",
|
|
114
|
+
"drive_file_id",
|
|
115
|
+
"drive_title",
|
|
116
|
+
"quote_date",
|
|
117
|
+
"revision",
|
|
118
|
+
"batch_size",
|
|
119
|
+
"order_size",
|
|
120
|
+
"price",
|
|
121
|
+
"source_pdf",
|
|
122
|
+
"claims",
|
|
123
|
+
]),
|
|
124
|
+
"weekly-post": new Set([...BASE_FIELDS, "title", "status", "week", "coverage"]),
|
|
125
|
+
inquiry: new Set([
|
|
126
|
+
...BASE_FIELDS,
|
|
127
|
+
"title",
|
|
128
|
+
"status",
|
|
129
|
+
"status_changed_at",
|
|
130
|
+
"resolved_at",
|
|
131
|
+
"severity",
|
|
132
|
+
"affected",
|
|
133
|
+
]),
|
|
134
|
+
general: BASE_FIELDS,
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const LIFECYCLE_FIELDS: Record<"plan" | "issue" | "handoff", ReadonlySet<string>> = {
|
|
138
|
+
plan: new Set([...BASE_FIELDS, "status", "status_changed_at", "status_note"]),
|
|
139
|
+
issue: new Set([
|
|
140
|
+
...BASE_FIELDS,
|
|
141
|
+
"status",
|
|
142
|
+
"status_changed_at",
|
|
143
|
+
"status_note",
|
|
144
|
+
"severity",
|
|
145
|
+
"resolved_at",
|
|
146
|
+
"affected",
|
|
147
|
+
]),
|
|
148
|
+
handoff: new Set([...BASE_FIELDS, "status", "status_changed_at", "status_note", "resolution"]),
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
152
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function add(
|
|
156
|
+
issues: DocsMetadataValidationIssue[],
|
|
157
|
+
severity: DocsMetadataValidationIssue["severity"],
|
|
158
|
+
code: string,
|
|
159
|
+
field: string,
|
|
160
|
+
message: string,
|
|
161
|
+
): void {
|
|
162
|
+
issues.push({ severity, code, field, message });
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function docsMetadataProfileForType(type: DocsMetadataType): DocsMetadataProfile {
|
|
166
|
+
if (LIFECYCLE_TYPES.has(type)) return "lifecycle";
|
|
167
|
+
if (type === "runbook") return "runbook";
|
|
168
|
+
if (WIKI_TYPES.has(type)) return "wiki";
|
|
169
|
+
if (type === "synced-page") return "synced";
|
|
170
|
+
if (type === "quote-sheet") return "quote-sheet";
|
|
171
|
+
if (type === "weekly-post") return "weekly-post";
|
|
172
|
+
if (type === "inquiry") return "inquiry";
|
|
173
|
+
return "general";
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function isDocsMetadataType(value: unknown): value is DocsMetadataType {
|
|
177
|
+
return typeof value === "string" && SUPPORTED_TYPES.has(value as DocsMetadataType);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function requireString(
|
|
181
|
+
data: Record<string, unknown>,
|
|
182
|
+
field: string,
|
|
183
|
+
issues: DocsMetadataValidationIssue[],
|
|
184
|
+
): string | null {
|
|
185
|
+
const value = data[field];
|
|
186
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
187
|
+
add(issues, "error", "required_string", field, `${field} must be a non-empty string`);
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
return value;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function validateTimestamp(
|
|
194
|
+
data: Record<string, unknown>,
|
|
195
|
+
field: string,
|
|
196
|
+
issues: DocsMetadataValidationIssue[],
|
|
197
|
+
required = true,
|
|
198
|
+
): number | null {
|
|
199
|
+
const value = data[field];
|
|
200
|
+
if (value === undefined && !required) return null;
|
|
201
|
+
if (typeof value !== "string" || !RFC3339_UTC_SECONDS.test(value)) {
|
|
202
|
+
add(
|
|
203
|
+
issues,
|
|
204
|
+
"error",
|
|
205
|
+
"invalid_timestamp",
|
|
206
|
+
field,
|
|
207
|
+
`${field} must use RFC 3339 UTC seconds, for example 2026-08-19T19:47:53Z`,
|
|
208
|
+
);
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
const parsed = Date.parse(value);
|
|
212
|
+
if (Number.isNaN(parsed) || new Date(parsed).toISOString().replace(".000Z", "Z") !== value) {
|
|
213
|
+
add(issues, "error", "invalid_timestamp", field, `${field} is not a real timestamp`);
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
return parsed;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function validateOwner(
|
|
220
|
+
data: Record<string, unknown>,
|
|
221
|
+
issues: DocsMetadataValidationIssue[],
|
|
222
|
+
required = false,
|
|
223
|
+
): void {
|
|
224
|
+
if (data.owner === undefined && !required) return;
|
|
225
|
+
const owner = requireString(data, "owner", issues);
|
|
226
|
+
if (owner && !SLUG.test(owner)) {
|
|
227
|
+
add(issues, "error", "invalid_owner", "owner", "owner must be a lowercase kebab-case id");
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function validateSummary(
|
|
232
|
+
data: Record<string, unknown>,
|
|
233
|
+
issues: DocsMetadataValidationIssue[],
|
|
234
|
+
required = false,
|
|
235
|
+
): void {
|
|
236
|
+
if (data.summary === undefined && !required) return;
|
|
237
|
+
requireString(data, "summary", issues);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function validateOptionalString(
|
|
241
|
+
data: Record<string, unknown>,
|
|
242
|
+
field: string,
|
|
243
|
+
issues: DocsMetadataValidationIssue[],
|
|
244
|
+
): void {
|
|
245
|
+
if (data[field] !== undefined) requireString(data, field, issues);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function validateStringList(
|
|
249
|
+
value: unknown,
|
|
250
|
+
field: string,
|
|
251
|
+
issues: DocsMetadataValidationIssue[],
|
|
252
|
+
itemPattern?: RegExp,
|
|
253
|
+
): string[] | null {
|
|
254
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string" || !item.trim())) {
|
|
255
|
+
add(issues, "error", "invalid_list", field, `${field} must be a YAML list of strings`);
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
const items = value as string[];
|
|
259
|
+
if (new Set(items).size !== items.length) {
|
|
260
|
+
add(issues, "error", "duplicate_list_item", field, `${field} contains duplicate values`);
|
|
261
|
+
}
|
|
262
|
+
if (itemPattern) {
|
|
263
|
+
for (const item of items) {
|
|
264
|
+
if (!itemPattern.test(item)) {
|
|
265
|
+
add(
|
|
266
|
+
issues,
|
|
267
|
+
"error",
|
|
268
|
+
"invalid_list_item",
|
|
269
|
+
field,
|
|
270
|
+
`${field} contains invalid value '${item}'`,
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return items;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function validateRelations(
|
|
279
|
+
data: Record<string, unknown>,
|
|
280
|
+
issues: DocsMetadataValidationIssue[],
|
|
281
|
+
): void {
|
|
282
|
+
if (data.relations === undefined) return;
|
|
283
|
+
if (!isRecord(data.relations)) {
|
|
284
|
+
add(issues, "error", "invalid_relations", "relations", "relations must be a YAML mapping");
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const allowed = new Set(["depends_on", "supersedes", "superseded_by", "continues", "related"]);
|
|
288
|
+
for (const [key, value] of Object.entries(data.relations)) {
|
|
289
|
+
if (!allowed.has(key)) {
|
|
290
|
+
add(issues, "error", "unknown_relation", `relations.${key}`, `unknown relation '${key}'`);
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
validateStringList(value, `relations.${key}`, issues);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function validateAccess(
|
|
298
|
+
data: Record<string, unknown>,
|
|
299
|
+
issues: DocsMetadataValidationIssue[],
|
|
300
|
+
): void {
|
|
301
|
+
if (data.access === undefined) return;
|
|
302
|
+
if (!isRecord(data.access)) {
|
|
303
|
+
add(issues, "error", "invalid_access", "access", "access must be a YAML mapping");
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
const allowed = new Set(["roles", "viewers"]);
|
|
307
|
+
for (const key of Object.keys(data.access)) {
|
|
308
|
+
if (!allowed.has(key)) {
|
|
309
|
+
add(
|
|
310
|
+
issues,
|
|
311
|
+
"error",
|
|
312
|
+
"unknown_access_field",
|
|
313
|
+
`access.${key}`,
|
|
314
|
+
`unknown access field '${key}'`,
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (data.access.roles !== undefined) {
|
|
319
|
+
validateStringList(data.access.roles, "access.roles", issues, SLUG);
|
|
320
|
+
}
|
|
321
|
+
if (data.access.viewers !== undefined) {
|
|
322
|
+
validateStringList(data.access.viewers, "access.viewers", issues, EMAIL);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function validateLifecycle(
|
|
327
|
+
data: Record<string, unknown>,
|
|
328
|
+
type: "plan" | "issue" | "handoff",
|
|
329
|
+
createdAt: number | null,
|
|
330
|
+
updatedAt: number | null,
|
|
331
|
+
issues: DocsMetadataValidationIssue[],
|
|
332
|
+
): void {
|
|
333
|
+
const status = requireString(data, "status", issues);
|
|
334
|
+
const allowed =
|
|
335
|
+
type === "plan" ? PLAN_STATUSES : type === "issue" ? ISSUE_STATUSES : HANDOFF_STATUSES;
|
|
336
|
+
if (status && !allowed.has(status)) {
|
|
337
|
+
add(issues, "error", "invalid_status", "status", `status '${status}' is invalid for ${type}`);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const changedAt = validateTimestamp(data, "status_changed_at", issues);
|
|
341
|
+
if (createdAt !== null && changedAt !== null && changedAt < createdAt) {
|
|
342
|
+
add(
|
|
343
|
+
issues,
|
|
344
|
+
"error",
|
|
345
|
+
"timestamp_order",
|
|
346
|
+
"status_changed_at",
|
|
347
|
+
"status_changed_at cannot precede created_at",
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
if (updatedAt !== null && changedAt !== null && changedAt > updatedAt) {
|
|
351
|
+
add(
|
|
352
|
+
issues,
|
|
353
|
+
"error",
|
|
354
|
+
"timestamp_order",
|
|
355
|
+
"status_changed_at",
|
|
356
|
+
"status_changed_at cannot be later than updated_at",
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
validateOptionalString(data, "status_note", issues);
|
|
361
|
+
|
|
362
|
+
if (type === "issue") {
|
|
363
|
+
const severity = requireString(data, "severity", issues);
|
|
364
|
+
if (severity && !ISSUE_SEVERITIES.has(severity)) {
|
|
365
|
+
add(
|
|
366
|
+
issues,
|
|
367
|
+
"error",
|
|
368
|
+
"invalid_severity",
|
|
369
|
+
"severity",
|
|
370
|
+
`severity '${severity}' must be low, medium, high, or critical`,
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
if (data.affected !== undefined) validateStringList(data.affected, "affected", issues);
|
|
374
|
+
const resolvedAt = validateTimestamp(data, "resolved_at", issues, status === "resolved");
|
|
375
|
+
if (status !== "resolved" && resolvedAt !== null) {
|
|
376
|
+
add(
|
|
377
|
+
issues,
|
|
378
|
+
"error",
|
|
379
|
+
"unexpected_resolved_at",
|
|
380
|
+
"resolved_at",
|
|
381
|
+
"resolved_at is only valid when status is resolved",
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
if (createdAt !== null && resolvedAt !== null && resolvedAt < createdAt) {
|
|
385
|
+
add(
|
|
386
|
+
issues,
|
|
387
|
+
"error",
|
|
388
|
+
"timestamp_order",
|
|
389
|
+
"resolved_at",
|
|
390
|
+
"resolved_at cannot precede created_at",
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
if (updatedAt !== null && resolvedAt !== null && resolvedAt > updatedAt) {
|
|
394
|
+
add(
|
|
395
|
+
issues,
|
|
396
|
+
"error",
|
|
397
|
+
"timestamp_order",
|
|
398
|
+
"resolved_at",
|
|
399
|
+
"resolved_at cannot be later than updated_at",
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
if (type === "handoff") {
|
|
405
|
+
const terminal = status === "resolved" || status === "abandoned";
|
|
406
|
+
if (terminal && !isRecord(data.resolution)) {
|
|
407
|
+
add(
|
|
408
|
+
issues,
|
|
409
|
+
"error",
|
|
410
|
+
"missing_resolution",
|
|
411
|
+
"resolution",
|
|
412
|
+
"terminal handoffs require a resolution mapping",
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
if (!terminal && data.resolution !== undefined) {
|
|
416
|
+
add(
|
|
417
|
+
issues,
|
|
418
|
+
"error",
|
|
419
|
+
"unexpected_resolution",
|
|
420
|
+
"resolution",
|
|
421
|
+
"open handoffs cannot carry resolution metadata",
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
if (isRecord(data.resolution)) {
|
|
425
|
+
if (typeof data.resolution.outcome !== "string" || !data.resolution.outcome.trim()) {
|
|
426
|
+
add(
|
|
427
|
+
issues,
|
|
428
|
+
"error",
|
|
429
|
+
"invalid_resolution",
|
|
430
|
+
"resolution.outcome",
|
|
431
|
+
"resolution.outcome must be a non-empty string",
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
if (data.resolution.commits !== undefined) {
|
|
435
|
+
validateStringList(data.resolution.commits, "resolution.commits", issues);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function validateRunbook(
|
|
442
|
+
data: Record<string, unknown>,
|
|
443
|
+
updatedAt: number | null,
|
|
444
|
+
issues: DocsMetadataValidationIssue[],
|
|
445
|
+
): void {
|
|
446
|
+
validateOptionalString(data, "title", issues);
|
|
447
|
+
validateOptionalString(data, "audience", issues);
|
|
448
|
+
validateOptionalString(data, "source", issues);
|
|
449
|
+
const reviewedAt = validateTimestamp(data, "reviewed_at", issues);
|
|
450
|
+
const reviewDueAt = validateTimestamp(data, "review_due_at", issues);
|
|
451
|
+
if (reviewedAt !== null && reviewDueAt !== null && reviewDueAt <= reviewedAt) {
|
|
452
|
+
add(
|
|
453
|
+
issues,
|
|
454
|
+
"error",
|
|
455
|
+
"timestamp_order",
|
|
456
|
+
"review_due_at",
|
|
457
|
+
"review_due_at must be later than reviewed_at",
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
if (updatedAt !== null && reviewedAt !== null && reviewedAt > updatedAt) {
|
|
461
|
+
add(
|
|
462
|
+
issues,
|
|
463
|
+
"error",
|
|
464
|
+
"timestamp_order",
|
|
465
|
+
"reviewed_at",
|
|
466
|
+
"reviewed_at cannot be later than updated_at",
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function validateWiki(data: Record<string, unknown>, issues: DocsMetadataValidationIssue[]): void {
|
|
472
|
+
requireString(data, "title", issues);
|
|
473
|
+
requireString(data, "category", issues);
|
|
474
|
+
if (data.aliases !== undefined) validateStringList(data.aliases, "aliases", issues);
|
|
475
|
+
if (
|
|
476
|
+
typeof data.source_count !== "number" ||
|
|
477
|
+
!Number.isInteger(data.source_count) ||
|
|
478
|
+
data.source_count < 0
|
|
479
|
+
) {
|
|
480
|
+
add(
|
|
481
|
+
issues,
|
|
482
|
+
"error",
|
|
483
|
+
"invalid_source_count",
|
|
484
|
+
"source_count",
|
|
485
|
+
"source_count must be a non-negative integer",
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
if (!isRecord(data.provenance)) {
|
|
489
|
+
add(issues, "error", "invalid_provenance", "provenance", "provenance must be a mapping");
|
|
490
|
+
} else {
|
|
491
|
+
validateStringList(data.provenance.sources, "provenance.sources", issues);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function validateSynced(
|
|
496
|
+
data: Record<string, unknown>,
|
|
497
|
+
issues: DocsMetadataValidationIssue[],
|
|
498
|
+
): void {
|
|
499
|
+
requireString(data, "title", issues);
|
|
500
|
+
requireString(data, "handle", issues);
|
|
501
|
+
requireString(data, "source", issues);
|
|
502
|
+
validateTimestamp(data, "source_updated_at", issues);
|
|
503
|
+
if (typeof data.published !== "boolean") {
|
|
504
|
+
add(issues, "error", "invalid_boolean", "published", "published must be a boolean");
|
|
505
|
+
}
|
|
506
|
+
validateOptionalString(data, "source_id", issues);
|
|
507
|
+
validateOptionalString(data, "source_template", issues);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
function validateQuoteSheet(
|
|
511
|
+
data: Record<string, unknown>,
|
|
512
|
+
issues: DocsMetadataValidationIssue[],
|
|
513
|
+
): void {
|
|
514
|
+
for (const field of ["title", "status", "product", "manufacturer", "quote_date", "source_pdf"]) {
|
|
515
|
+
requireString(data, field, issues);
|
|
516
|
+
}
|
|
517
|
+
if (
|
|
518
|
+
typeof data.status === "string" &&
|
|
519
|
+
!new Set(["not-final", "unsigned", "signed", "final"]).has(data.status)
|
|
520
|
+
) {
|
|
521
|
+
add(
|
|
522
|
+
issues,
|
|
523
|
+
"error",
|
|
524
|
+
"invalid_status",
|
|
525
|
+
"status",
|
|
526
|
+
"quote-sheet status must be not-final, unsigned, signed, or final",
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
function validateWeeklyPost(
|
|
532
|
+
data: Record<string, unknown>,
|
|
533
|
+
issues: DocsMetadataValidationIssue[],
|
|
534
|
+
): void {
|
|
535
|
+
for (const field of ["title", "status", "week", "coverage"]) requireString(data, field, issues);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
function validateInquiry(
|
|
539
|
+
data: Record<string, unknown>,
|
|
540
|
+
createdAt: number | null,
|
|
541
|
+
updatedAt: number | null,
|
|
542
|
+
issues: DocsMetadataValidationIssue[],
|
|
543
|
+
): void {
|
|
544
|
+
requireString(data, "title", issues);
|
|
545
|
+
const status = requireString(data, "status", issues);
|
|
546
|
+
if (status && !new Set(["open", "resolved", "abandoned"]).has(status)) {
|
|
547
|
+
add(issues, "error", "invalid_status", "status", `inquiry status '${status}' is invalid`);
|
|
548
|
+
}
|
|
549
|
+
const changedAt = validateTimestamp(data, "status_changed_at", issues);
|
|
550
|
+
if (createdAt !== null && changedAt !== null && changedAt < createdAt) {
|
|
551
|
+
add(
|
|
552
|
+
issues,
|
|
553
|
+
"error",
|
|
554
|
+
"timestamp_order",
|
|
555
|
+
"status_changed_at",
|
|
556
|
+
"status_changed_at cannot precede created_at",
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
if (updatedAt !== null && changedAt !== null && changedAt > updatedAt) {
|
|
560
|
+
add(
|
|
561
|
+
issues,
|
|
562
|
+
"error",
|
|
563
|
+
"timestamp_order",
|
|
564
|
+
"status_changed_at",
|
|
565
|
+
"status_changed_at cannot be later than updated_at",
|
|
566
|
+
);
|
|
567
|
+
}
|
|
568
|
+
const resolvedAt = validateTimestamp(data, "resolved_at", issues, status === "resolved");
|
|
569
|
+
if (status !== "resolved" && resolvedAt !== null) {
|
|
570
|
+
add(
|
|
571
|
+
issues,
|
|
572
|
+
"error",
|
|
573
|
+
"unexpected_resolved_at",
|
|
574
|
+
"resolved_at",
|
|
575
|
+
"resolved_at is only valid when status is resolved",
|
|
576
|
+
);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/** Validate one parsed YAML frontmatter mapping against the harnery-doc/v2 contract. */
|
|
581
|
+
export function validateDocsMetadataV2(
|
|
582
|
+
data: Record<string, unknown>,
|
|
583
|
+
): DocsMetadataValidationResult {
|
|
584
|
+
const issues: DocsMetadataValidationIssue[] = [];
|
|
585
|
+
if (data.schema !== DOCS_METADATA_SCHEMA_V2) {
|
|
586
|
+
add(issues, "error", "invalid_schema", "schema", `schema must be '${DOCS_METADATA_SCHEMA_V2}'`);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
const rawType = requireString(data, "type", issues);
|
|
590
|
+
const type = rawType && isDocsMetadataType(rawType) ? rawType : null;
|
|
591
|
+
if (rawType && !type) {
|
|
592
|
+
add(issues, "error", "invalid_type", "type", `unsupported document type '${rawType}'`);
|
|
593
|
+
}
|
|
594
|
+
const profile = type ? docsMetadataProfileForType(type) : null;
|
|
595
|
+
|
|
596
|
+
const createdAt = validateTimestamp(data, "created_at", issues);
|
|
597
|
+
const updatedAt = validateTimestamp(data, "updated_at", issues);
|
|
598
|
+
if (createdAt !== null && updatedAt !== null && updatedAt < createdAt) {
|
|
599
|
+
add(issues, "error", "timestamp_order", "updated_at", "updated_at cannot precede created_at");
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
if (data.tags !== undefined) validateStringList(data.tags, "tags", issues, SLUG);
|
|
603
|
+
const lifecycleType = type !== null && LIFECYCLE_TYPES.has(type);
|
|
604
|
+
validateOwner(data, issues, lifecycleType || type === "runbook" || type === "inquiry");
|
|
605
|
+
validateSummary(data, issues, type !== null);
|
|
606
|
+
validateRelations(data, issues);
|
|
607
|
+
validateAccess(data, issues);
|
|
608
|
+
|
|
609
|
+
if (profile) {
|
|
610
|
+
const allowed =
|
|
611
|
+
type && LIFECYCLE_TYPES.has(type)
|
|
612
|
+
? LIFECYCLE_FIELDS[type as "plan" | "issue" | "handoff"]
|
|
613
|
+
: PROFILE_FIELDS[profile];
|
|
614
|
+
for (const key of Object.keys(data)) {
|
|
615
|
+
if (!allowed.has(key) && !key.startsWith("x_")) {
|
|
616
|
+
add(issues, "error", "unknown_field", key, `unknown ${profile} metadata field '${key}'`);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
if (type && LIFECYCLE_TYPES.has(type)) {
|
|
622
|
+
validateLifecycle(data, type as "plan" | "issue" | "handoff", createdAt, updatedAt, issues);
|
|
623
|
+
} else if (type === "runbook") {
|
|
624
|
+
validateRunbook(data, updatedAt, issues);
|
|
625
|
+
} else if (type && WIKI_TYPES.has(type)) {
|
|
626
|
+
validateWiki(data, issues);
|
|
627
|
+
} else if (type === "synced-page") {
|
|
628
|
+
validateSynced(data, issues);
|
|
629
|
+
} else if (type === "quote-sheet") {
|
|
630
|
+
validateQuoteSheet(data, issues);
|
|
631
|
+
} else if (type === "weekly-post") {
|
|
632
|
+
validateWeeklyPost(data, issues);
|
|
633
|
+
} else if (type === "inquiry") {
|
|
634
|
+
validateInquiry(data, createdAt, updatedAt, issues);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
return {
|
|
638
|
+
valid: issues.every((issue) => issue.severity !== "error"),
|
|
639
|
+
profile,
|
|
640
|
+
issues,
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
export function isDocsMetadataV2(data: Record<string, unknown>): boolean {
|
|
645
|
+
return data.schema === DOCS_METADATA_SCHEMA_V2;
|
|
646
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, isAbsolute, relative, resolve } from "node:path";
|
|
3
|
+
import { dump as dumpYaml, JSON_SCHEMA } from "js-yaml";
|
|
4
|
+
import type { DocsMetadataType } from "./docs-metadata-v2.ts";
|
|
5
|
+
import { validateDocsMetadataV2 } from "./docs-metadata-v2.ts";
|
|
6
|
+
|
|
7
|
+
export interface DocsNewOpts {
|
|
8
|
+
type: "plan" | "issue" | "handoff" | "runbook" | "topic";
|
|
9
|
+
path: string;
|
|
10
|
+
summary: string;
|
|
11
|
+
owner: string;
|
|
12
|
+
status?: string;
|
|
13
|
+
severity?: string;
|
|
14
|
+
now?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function createDocsFile(repoRoot: string, opts: DocsNewOpts): string {
|
|
18
|
+
const file = resolve(repoRoot, opts.path);
|
|
19
|
+
const relativePath = relative(resolve(repoRoot), file);
|
|
20
|
+
if (!relativePath || relativePath.startsWith("..") || isAbsolute(relativePath)) {
|
|
21
|
+
throw new Error("document path must stay inside the repository");
|
|
22
|
+
}
|
|
23
|
+
if (!file.endsWith(".md")) throw new Error("document path must end in .md");
|
|
24
|
+
if (existsSync(file)) throw new Error(`document already exists: ${opts.path}`);
|
|
25
|
+
const now = opts.now ?? new Date().toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
26
|
+
const type: DocsMetadataType = opts.type;
|
|
27
|
+
const data: Record<string, unknown> = {
|
|
28
|
+
schema: "harnery-doc/v2",
|
|
29
|
+
type,
|
|
30
|
+
created_at: now,
|
|
31
|
+
updated_at: now,
|
|
32
|
+
owner: opts.owner,
|
|
33
|
+
summary: opts.summary,
|
|
34
|
+
};
|
|
35
|
+
if (type === "plan" || type === "issue" || type === "handoff") {
|
|
36
|
+
data.status = opts.status ?? (type === "plan" ? "proposed" : "open");
|
|
37
|
+
data.status_changed_at = now;
|
|
38
|
+
}
|
|
39
|
+
if (type === "issue") data.severity = opts.severity ?? "medium";
|
|
40
|
+
if (type === "runbook") {
|
|
41
|
+
data.reviewed_at = now;
|
|
42
|
+
const due = new Date(now);
|
|
43
|
+
due.setUTCDate(due.getUTCDate() + 180);
|
|
44
|
+
data.review_due_at = due.toISOString().replace(".000Z", "Z");
|
|
45
|
+
}
|
|
46
|
+
const validation = validateDocsMetadataV2(data);
|
|
47
|
+
if (!validation.valid) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
validation.issues.map((issue) => `${issue.field}: ${issue.message}`).join("; "),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
const yaml = dumpYaml(data, { schema: JSON_SCHEMA, noRefs: true, lineWidth: -1 }).trimEnd();
|
|
53
|
+
const title = opts.path
|
|
54
|
+
.split("/")
|
|
55
|
+
.at(-1)!
|
|
56
|
+
.replace(/\.md$/, "")
|
|
57
|
+
.replace(/^\d{4}-\d{2}-\d{2}_/, "")
|
|
58
|
+
.replace(/[-_]/g, " ")
|
|
59
|
+
.replace(/\b\w/g, (letter) => letter.toUpperCase());
|
|
60
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
61
|
+
writeFileSync(file, `---\n${yaml}\n---\n\n# ${title}\n\n${opts.summary}\n`, "utf8");
|
|
62
|
+
return file;
|
|
63
|
+
}
|