harnery 0.35.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commander.d.ts +30 -5
- package/dist/commander.d.ts.map +1 -1
- package/dist/commander.js +124 -96
- package/dist/commands/agents.d.ts +23 -3
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +379 -198
- package/dist/commands/backup.d.ts.map +1 -1
- package/dist/commands/backup.js +10 -10
- package/dist/commands/browse-session.d.ts.map +1 -1
- package/dist/commands/browse-session.js +12 -0
- package/dist/commands/browse.d.ts +1 -1
- package/dist/commands/browse.d.ts.map +1 -1
- package/dist/commands/browse.js +5 -4
- package/dist/commands/conversations.d.ts +10 -0
- package/dist/commands/conversations.d.ts.map +1 -0
- package/dist/commands/conversations.js +201 -0
- package/dist/commands/deinit.d.ts.map +1 -1
- package/dist/commands/deinit.js +5 -0
- package/dist/commands/docs.d.ts.map +1 -1
- package/dist/commands/docs.js +13 -2
- package/dist/commands/doctor.d.ts +5 -0
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +51 -7
- package/dist/commands/fetch.js +6 -5
- package/dist/commands/files.d.ts +22 -0
- package/dist/commands/files.d.ts.map +1 -0
- package/dist/commands/files.js +113 -0
- package/dist/commands/governor.js +14 -12
- package/dist/commands/inbox.d.ts +5 -0
- package/dist/commands/inbox.d.ts.map +1 -0
- package/dist/commands/inbox.js +57 -0
- package/dist/commands/init.d.ts +4 -5
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +63 -13
- package/dist/commands/ledger-v3.d.ts.map +1 -1
- package/dist/commands/ledger-v3.js +347 -1
- package/dist/commands/logs.d.ts +4 -0
- package/dist/commands/logs.d.ts.map +1 -0
- package/dist/commands/logs.js +169 -0
- package/dist/commands/messages.d.ts +5 -0
- package/dist/commands/messages.d.ts.map +1 -0
- package/dist/commands/messages.js +45 -0
- package/dist/commands/outline.d.ts +1 -1
- package/dist/commands/outline.d.ts.map +1 -1
- package/dist/commands/outline.js +2 -2
- package/dist/commands/read.d.ts +1 -1
- package/dist/commands/read.d.ts.map +1 -1
- package/dist/commands/read.js +2 -2
- package/dist/commands/semantic.d.ts.map +1 -1
- package/dist/commands/semantic.js +54 -2
- package/dist/commands/storage.d.ts +4 -0
- package/dist/commands/storage.d.ts.map +1 -0
- package/dist/commands/storage.js +238 -0
- package/dist/commands/tunnel.d.ts +5 -1
- package/dist/commands/tunnel.d.ts.map +1 -1
- package/dist/commands/tunnel.js +44 -31
- package/dist/commands/web.d.ts +3 -0
- package/dist/commands/web.d.ts.map +1 -1
- package/dist/commands/web.js +67 -7
- package/dist/commands/work.js +3 -3
- package/dist/commands/workflow.js +13 -13
- package/dist/core/adapters/profiles.d.ts +1 -1
- package/dist/core/agents/cli.js +209 -39
- package/dist/core/agents/live-authority-v3.d.ts +47 -1
- package/dist/core/agents/live-authority-v3.d.ts.map +1 -1
- package/dist/core/agents/live-authority-v3.js +244 -10
- package/dist/core/agents/live-lifecycle-v3.js +6 -1
- package/dist/core/agents/live-observation-v3.d.ts.map +1 -1
- package/dist/core/agents/live-observation-v3.js +6 -1
- package/dist/core/agents/render/prompt-context.d.ts +9 -3
- package/dist/core/agents/render/prompt-context.d.ts.map +1 -1
- package/dist/core/agents/render/prompt-context.js +24 -7
- package/dist/core/agents/rules/stop-hook.d.ts +2 -0
- package/dist/core/agents/rules/stop-hook.d.ts.map +1 -1
- package/dist/core/agents/rules/stop-hook.js +94 -13
- package/dist/core/agents/rules/verdict.d.ts +1 -0
- package/dist/core/agents/rules/verdict.d.ts.map +1 -1
- package/dist/core/agents/session-events.d.ts.map +1 -1
- package/dist/core/agents/session-events.js +4 -0
- package/dist/core/agents/session-finalization-state-v3.js +1 -1
- package/dist/core/agents/session-finalizer-v3.js +5 -1
- package/dist/core/agents/state/activity-log.d.ts +3 -0
- package/dist/core/agents/state/activity-log.d.ts.map +1 -1
- package/dist/core/agents/state/activity-log.js +6 -3
- package/dist/core/agents/state/heartbeat-writer.d.ts +6 -0
- package/dist/core/agents/state/heartbeat-writer.d.ts.map +1 -1
- package/dist/core/agents/state/heartbeat-writer.js +18 -0
- package/dist/core/agents/state/live-coordination-view.d.ts +5 -7
- package/dist/core/agents/state/live-coordination-view.d.ts.map +1 -1
- package/dist/core/agents/state/live-coordination-view.js +15 -90
- package/dist/core/agents/state/live-coordination-writer.d.ts +12 -0
- package/dist/core/agents/state/live-coordination-writer.d.ts.map +1 -0
- package/dist/core/agents/state/live-coordination-writer.js +92 -0
- package/dist/core/artifacts/index.d.ts +21 -0
- package/dist/core/artifacts/index.d.ts.map +1 -1
- package/dist/core/artifacts/index.js +46 -1
- package/dist/core/config.d.ts +62 -4
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +98 -4
- package/dist/core/conversations/archive.d.ts +49 -0
- package/dist/core/conversations/archive.d.ts.map +1 -0
- package/dist/core/conversations/archive.js +136 -0
- package/dist/core/conversations/catalog.d.ts +10 -0
- package/dist/core/conversations/catalog.d.ts.map +1 -0
- package/dist/core/conversations/catalog.js +72 -0
- package/dist/core/conversations/context-pack.d.ts +6 -0
- package/dist/core/conversations/context-pack.d.ts.map +1 -0
- package/dist/core/conversations/context-pack.js +60 -0
- package/dist/core/conversations/contract.d.ts +155 -0
- package/dist/core/conversations/contract.d.ts.map +1 -0
- package/dist/core/conversations/contract.js +1 -0
- package/dist/core/conversations/evaluation.d.ts +16 -0
- package/dist/core/conversations/evaluation.d.ts.map +1 -0
- package/dist/core/conversations/evaluation.js +9 -0
- package/dist/core/conversations/index.d.ts +10 -0
- package/dist/core/conversations/index.d.ts.map +1 -0
- package/dist/core/conversations/index.js +9 -0
- package/dist/core/conversations/lifecycle.d.ts +28 -0
- package/dist/core/conversations/lifecycle.d.ts.map +1 -0
- package/dist/core/conversations/lifecycle.js +29 -0
- package/dist/core/conversations/normalize.d.ts +14 -0
- package/dist/core/conversations/normalize.d.ts.map +1 -0
- package/dist/core/conversations/normalize.js +82 -0
- package/dist/core/conversations/query.d.ts +8 -0
- package/dist/core/conversations/query.d.ts.map +1 -0
- package/dist/core/conversations/query.js +280 -0
- package/dist/core/conversations/search-index.d.ts +9 -0
- package/dist/core/conversations/search-index.d.ts.map +1 -0
- package/dist/core/conversations/search-index.js +29 -0
- package/dist/core/events/legacy-storage/canary.d.ts +18 -0
- package/dist/core/events/legacy-storage/canary.d.ts.map +1 -0
- package/dist/core/events/legacy-storage/canary.js +150 -0
- package/dist/core/events/legacy-storage/fence.d.ts +15 -0
- package/dist/core/events/legacy-storage/fence.d.ts.map +1 -0
- package/dist/core/events/legacy-storage/fence.js +115 -0
- package/dist/core/events/legacy-storage/index.d.ts +6 -0
- package/dist/core/events/legacy-storage/index.d.ts.map +1 -0
- package/dist/core/events/legacy-storage/index.js +5 -0
- package/dist/core/events/legacy-storage/inventory.d.ts +10 -0
- package/dist/core/events/legacy-storage/inventory.d.ts.map +1 -0
- package/dist/core/events/legacy-storage/inventory.js +40 -0
- package/dist/core/events/legacy-storage/manifest.d.ts +23 -0
- package/dist/core/events/legacy-storage/manifest.d.ts.map +1 -0
- package/dist/core/events/legacy-storage/manifest.js +108 -0
- package/dist/core/events/legacy-storage/reader.d.ts +15 -0
- package/dist/core/events/legacy-storage/reader.d.ts.map +1 -0
- package/dist/core/events/legacy-storage/reader.js +154 -0
- package/dist/core/events/v3/authority-outbox.d.ts +7 -2
- package/dist/core/events/v3/authority-outbox.d.ts.map +1 -1
- package/dist/core/events/v3/authority-outbox.js +16 -3
- package/dist/core/events/v3/base-contract.d.ts +81 -41
- package/dist/core/events/v3/base-contract.d.ts.map +1 -1
- package/dist/core/events/v3/base-contract.js +17 -7
- package/dist/core/events/v3/bootstrap.d.ts +39 -0
- package/dist/core/events/v3/bootstrap.d.ts.map +1 -1
- package/dist/core/events/v3/bootstrap.js +167 -3
- package/dist/core/events/v3/capabilities.js +3 -3
- package/dist/core/events/v3/control-witness.d.ts +44 -0
- package/dist/core/events/v3/control-witness.d.ts.map +1 -0
- package/dist/core/events/v3/control-witness.js +233 -0
- package/dist/core/events/v3/control-writer.d.ts +4 -0
- package/dist/core/events/v3/control-writer.d.ts.map +1 -0
- package/dist/core/events/v3/control-writer.js +16 -0
- package/dist/core/events/v3/control.d.ts +8 -2
- package/dist/core/events/v3/control.d.ts.map +1 -1
- package/dist/core/events/v3/control.js +46 -18
- package/dist/core/events/v3/coordination-transaction-recovery.d.ts +42 -0
- package/dist/core/events/v3/coordination-transaction-recovery.d.ts.map +1 -0
- package/dist/core/events/v3/coordination-transaction-recovery.js +342 -0
- package/dist/core/events/v3/coordination-view.d.ts.map +1 -1
- package/dist/core/events/v3/coordination-view.js +16 -1
- package/dist/core/events/v3/generated.d.ts +1 -1
- package/dist/core/events/v3/generated.js +1 -1
- package/dist/core/events/v3/index.d.ts +4 -2
- package/dist/core/events/v3/index.d.ts.map +1 -1
- package/dist/core/events/v3/index.js +3 -1
- package/dist/core/events/v3/live-route-observer.d.ts +31 -0
- package/dist/core/events/v3/live-route-observer.d.ts.map +1 -0
- package/dist/core/events/v3/live-route-observer.js +58 -0
- package/dist/core/events/v3/live-routing.d.ts +13 -21
- package/dist/core/events/v3/live-routing.d.ts.map +1 -1
- package/dist/core/events/v3/live-routing.js +45 -41
- package/dist/core/events/v3/producers/coordination-recorder.d.ts +11 -1
- package/dist/core/events/v3/producers/coordination-recorder.d.ts.map +1 -1
- package/dist/core/events/v3/producers/coordination-recorder.js +76 -10
- package/dist/core/events/v3/producers/diagnostic-summaries.d.ts +129 -0
- package/dist/core/events/v3/producers/diagnostic-summaries.d.ts.map +1 -0
- package/dist/core/events/v3/producers/diagnostic-summaries.js +499 -0
- package/dist/core/events/v3/producers/hook-base.js +1 -1
- package/dist/core/events/v3/producers/intake.d.ts +7 -0
- package/dist/core/events/v3/producers/intake.d.ts.map +1 -1
- package/dist/core/events/v3/producers/intake.js +25 -2
- package/dist/core/events/v3/producers/producer-state-observer.d.ts +8 -0
- package/dist/core/events/v3/producers/producer-state-observer.d.ts.map +1 -0
- package/dist/core/events/v3/producers/producer-state-observer.js +45 -0
- package/dist/core/events/v3/producers/recorder.d.ts +55 -1
- package/dist/core/events/v3/producers/recorder.d.ts.map +1 -1
- package/dist/core/events/v3/producers/recorder.js +353 -24
- package/dist/core/events/v3/reader.d.ts +51 -0
- package/dist/core/events/v3/reader.d.ts.map +1 -1
- package/dist/core/events/v3/reader.js +181 -1
- package/dist/core/events/v3/rotation-config.d.ts +9 -0
- package/dist/core/events/v3/rotation-config.d.ts.map +1 -0
- package/dist/core/events/v3/rotation-config.js +91 -0
- package/dist/core/events/v3/runtime-build.d.ts +11 -0
- package/dist/core/events/v3/runtime-build.d.ts.map +1 -0
- package/dist/core/events/v3/runtime-build.js +39 -0
- package/dist/core/events/v3/runtime-identity.d.ts +5 -0
- package/dist/core/events/v3/runtime-identity.d.ts.map +1 -0
- package/dist/core/events/v3/runtime-identity.js +18 -0
- package/dist/core/events/v3/runtime-telemetry-capabilities.d.ts +6 -5
- package/dist/core/events/v3/runtime-telemetry-capabilities.d.ts.map +1 -1
- package/dist/core/events/v3/runtime-telemetry-capabilities.js +1 -1
- package/dist/core/events/v3/support-storage/classify.d.ts +46 -0
- package/dist/core/events/v3/support-storage/classify.d.ts.map +1 -0
- package/dist/core/events/v3/support-storage/classify.js +149 -0
- package/dist/core/events/v3/support-storage/eligibility.d.ts +29 -0
- package/dist/core/events/v3/support-storage/eligibility.d.ts.map +1 -0
- package/dist/core/events/v3/support-storage/eligibility.js +35 -0
- package/dist/core/events/v3/support-storage/index.d.ts +10 -0
- package/dist/core/events/v3/support-storage/index.d.ts.map +1 -0
- package/dist/core/events/v3/support-storage/index.js +9 -0
- package/dist/core/events/v3/support-storage/inventory.d.ts +30 -0
- package/dist/core/events/v3/support-storage/inventory.d.ts.map +1 -0
- package/dist/core/events/v3/support-storage/inventory.js +94 -0
- package/dist/core/events/v3/support-storage/logical-authority.d.ts +14 -0
- package/dist/core/events/v3/support-storage/logical-authority.d.ts.map +1 -0
- package/dist/core/events/v3/support-storage/logical-authority.js +104 -0
- package/dist/core/events/v3/support-storage/maintenance.d.ts +98 -0
- package/dist/core/events/v3/support-storage/maintenance.d.ts.map +1 -0
- package/dist/core/events/v3/support-storage/maintenance.js +352 -0
- package/dist/core/events/v3/support-storage/pack-contract.d.ts +59 -0
- package/dist/core/events/v3/support-storage/pack-contract.d.ts.map +1 -0
- package/dist/core/events/v3/support-storage/pack-contract.js +249 -0
- package/dist/core/events/v3/support-storage/pack-reader.d.ts +34 -0
- package/dist/core/events/v3/support-storage/pack-reader.d.ts.map +1 -0
- package/dist/core/events/v3/support-storage/pack-reader.js +258 -0
- package/dist/core/events/v3/support-storage/pack-writer.d.ts +30 -0
- package/dist/core/events/v3/support-storage/pack-writer.d.ts.map +1 -0
- package/dist/core/events/v3/support-storage/pack-writer.js +268 -0
- package/dist/core/events/v3/support-storage/recovery.d.ts +15 -0
- package/dist/core/events/v3/support-storage/recovery.d.ts.map +1 -0
- package/dist/core/events/v3/support-storage/recovery.js +22 -0
- package/dist/core/events/v3/turn-telemetry.d.ts +14 -8
- package/dist/core/events/v3/turn-telemetry.d.ts.map +1 -1
- package/dist/core/events/v3/turn-telemetry.js +32 -2
- package/dist/core/events/v3/writer.d.ts +13 -1
- package/dist/core/events/v3/writer.d.ts.map +1 -1
- package/dist/core/events/v3/writer.js +126 -12
- package/dist/core/governor/plan-read.d.ts.map +1 -1
- package/dist/core/governor/plan-read.js +5 -21
- package/dist/core/governor/planning.js +6 -8
- package/dist/core/governor/service-read.d.ts +12 -0
- package/dist/core/governor/service-read.d.ts.map +1 -1
- package/dist/core/governor/service-read.js +266 -2
- package/dist/core/governor/service.d.ts +1 -0
- package/dist/core/governor/service.d.ts.map +1 -1
- package/dist/core/governor/service.js +53 -18
- package/dist/core/guard/evidence-v3.d.ts.map +1 -1
- package/dist/core/guard/evidence-v3.js +2 -0
- package/dist/core/hooks/adapter/events.d.ts.map +1 -1
- package/dist/core/hooks/adapter/events.js +1 -0
- package/dist/core/hooks/adapter/output.d.ts +4 -2
- package/dist/core/hooks/adapter/output.d.ts.map +1 -1
- package/dist/core/hooks/adapter/output.js +13 -5
- package/dist/core/hooks/adapter/runtime-telemetry.d.ts +27 -4
- package/dist/core/hooks/adapter/runtime-telemetry.d.ts.map +1 -1
- package/dist/core/hooks/adapter/runtime-telemetry.js +307 -6
- package/dist/core/hooks/cli.js +212 -30
- package/dist/core/hooks/effects/image-capture.d.ts +1 -1
- package/dist/core/hooks/effects/image-capture.d.ts.map +1 -1
- package/dist/core/hooks/effects/image-capture.js +4 -2
- package/dist/core/hooks/remediation-cap.d.ts +8 -3
- package/dist/core/hooks/remediation-cap.d.ts.map +1 -1
- package/dist/core/hooks/remediation-cap.js +3 -11
- package/dist/core/hooks/resolve/coord-root.d.ts +22 -9
- package/dist/core/hooks/resolve/coord-root.d.ts.map +1 -1
- package/dist/core/hooks/resolve/coord-root.js +92 -11
- package/dist/core/hooks/resolve/owner.d.ts.map +1 -1
- package/dist/core/hooks/resolve/owner.js +5 -0
- package/dist/core/hooks/resolve/transcript.d.ts +8 -0
- package/dist/core/hooks/resolve/transcript.d.ts.map +1 -1
- package/dist/core/hooks/resolve/transcript.js +11 -0
- package/dist/core/inbox/contract.d.ts +64 -0
- package/dist/core/inbox/contract.d.ts.map +1 -0
- package/dist/core/inbox/contract.js +13 -0
- package/dist/core/inbox/index.d.ts +5 -0
- package/dist/core/inbox/index.d.ts.map +1 -0
- package/dist/core/inbox/index.js +4 -0
- package/dist/core/inbox/lifecycle.d.ts +22 -0
- package/dist/core/inbox/lifecycle.d.ts.map +1 -0
- package/dist/core/inbox/lifecycle.js +41 -0
- package/dist/core/inbox/service.d.ts +36 -0
- package/dist/core/inbox/service.d.ts.map +1 -0
- package/dist/core/inbox/service.js +210 -0
- package/dist/core/inbox/watcher.d.ts +7 -0
- package/dist/core/inbox/watcher.d.ts.map +1 -0
- package/dist/core/inbox/watcher.js +26 -0
- package/dist/core/presence/codec-digest.d.ts.map +1 -1
- package/dist/core/presence/codec-digest.js +14 -3
- package/dist/core/presence/relay-client.d.ts +1 -0
- package/dist/core/presence/relay-client.d.ts.map +1 -1
- package/dist/core/presence/relay-client.js +52 -8
- package/dist/core/semantic/adapters.d.ts +11 -8
- package/dist/core/semantic/adapters.d.ts.map +1 -1
- package/dist/core/semantic/adapters.js +169 -31
- package/dist/core/semantic/contract.d.ts +532 -48
- package/dist/core/semantic/contract.d.ts.map +1 -1
- package/dist/core/semantic/contract.js +104 -3
- package/dist/core/semantic/index.d.ts +7 -3
- package/dist/core/semantic/index.d.ts.map +1 -1
- package/dist/core/semantic/index.js +7 -3
- package/dist/core/semantic/once.d.ts +6 -1
- package/dist/core/semantic/once.d.ts.map +1 -1
- package/dist/core/semantic/once.js +80 -9
- package/dist/core/semantic/prompt.d.ts.map +1 -1
- package/dist/core/semantic/prompt.js +14 -1
- package/dist/core/semantic/review.d.ts +144 -0
- package/dist/core/semantic/review.d.ts.map +1 -0
- package/dist/core/semantic/review.js +544 -0
- package/dist/core/semantic/routes.d.ts +10 -0
- package/dist/core/semantic/routes.d.ts.map +1 -0
- package/dist/core/semantic/routes.js +21 -0
- package/dist/core/semantic/scheduler.d.ts +14 -3
- package/dist/core/semantic/scheduler.d.ts.map +1 -1
- package/dist/core/semantic/scheduler.js +30 -6
- package/dist/core/semantic/service-status.d.ts +20 -0
- package/dist/core/semantic/service-status.d.ts.map +1 -1
- package/dist/core/semantic/service-status.js +60 -4
- package/dist/core/semantic/service.d.ts +1 -0
- package/dist/core/semantic/service.d.ts.map +1 -1
- package/dist/core/semantic/service.js +104 -15
- package/dist/core/semantic/soak.d.ts +75 -0
- package/dist/core/semantic/soak.d.ts.map +1 -0
- package/dist/core/semantic/soak.js +476 -0
- package/dist/core/semantic/storage.d.ts +11 -1
- package/dist/core/semantic/storage.d.ts.map +1 -1
- package/dist/core/semantic/storage.js +4 -3
- package/dist/core/semantic/usage.d.ts +43 -0
- package/dist/core/semantic/usage.d.ts.map +1 -0
- package/dist/core/semantic/usage.js +193 -0
- package/dist/core/semantic/validate.d.ts +3 -1
- package/dist/core/semantic/validate.d.ts.map +1 -1
- package/dist/core/semantic/validate.js +34 -1
- package/dist/core/storage/buffer.d.ts +28 -0
- package/dist/core/storage/buffer.d.ts.map +1 -0
- package/dist/core/storage/buffer.js +101 -0
- package/dist/core/storage/builtins.d.ts +3 -0
- package/dist/core/storage/builtins.d.ts.map +1 -0
- package/dist/core/storage/builtins.js +683 -0
- package/dist/core/storage/catalog.d.ts +19 -0
- package/dist/core/storage/catalog.d.ts.map +1 -0
- package/dist/core/storage/catalog.js +365 -0
- package/dist/core/storage/config.d.ts +16 -0
- package/dist/core/storage/config.d.ts.map +1 -0
- package/dist/core/storage/config.js +311 -0
- package/dist/core/storage/contract.d.ts +275 -0
- package/dist/core/storage/contract.d.ts.map +1 -0
- package/dist/core/storage/contract.js +3 -0
- package/dist/core/storage/durable-history.d.ts +36 -0
- package/dist/core/storage/durable-history.d.ts.map +1 -0
- package/dist/core/storage/durable-history.js +606 -0
- package/dist/core/storage/health.d.ts +4 -0
- package/dist/core/storage/health.d.ts.map +1 -0
- package/dist/core/storage/health.js +65 -0
- package/dist/core/storage/index.d.ts +16 -0
- package/dist/core/storage/index.d.ts.map +1 -0
- package/dist/core/storage/index.js +15 -0
- package/dist/core/storage/inventory.d.ts +25 -0
- package/dist/core/storage/inventory.d.ts.map +1 -0
- package/dist/core/storage/inventory.js +666 -0
- package/dist/core/storage/jsonl.d.ts +52 -0
- package/dist/core/storage/jsonl.d.ts.map +1 -0
- package/dist/core/storage/jsonl.js +156 -0
- package/dist/core/storage/log-retention.d.ts +52 -0
- package/dist/core/storage/log-retention.d.ts.map +1 -0
- package/dist/core/storage/log-retention.js +419 -0
- package/dist/core/storage/logger.d.ts +82 -0
- package/dist/core/storage/logger.d.ts.map +1 -0
- package/dist/core/storage/logger.js +411 -0
- package/dist/core/storage/maintenance-providers.d.ts +26 -0
- package/dist/core/storage/maintenance-providers.d.ts.map +1 -0
- package/dist/core/storage/maintenance-providers.js +141 -0
- package/dist/core/storage/maintenance.d.ts +125 -0
- package/dist/core/storage/maintenance.d.ts.map +1 -0
- package/dist/core/storage/maintenance.js +609 -0
- package/dist/core/storage/metrics.d.ts +60 -0
- package/dist/core/storage/metrics.d.ts.map +1 -0
- package/dist/core/storage/metrics.js +134 -0
- package/dist/core/storage/policy.d.ts +7 -0
- package/dist/core/storage/policy.d.ts.map +1 -0
- package/dist/core/storage/policy.js +110 -0
- package/dist/core/storage/process-log.d.ts +38 -0
- package/dist/core/storage/process-log.d.ts.map +1 -0
- package/dist/core/storage/process-log.js +165 -0
- package/dist/core/storage/query.d.ts +34 -0
- package/dist/core/storage/query.d.ts.map +1 -0
- package/dist/core/storage/query.js +295 -0
- package/dist/core/storage/receipts.d.ts +23 -0
- package/dist/core/storage/receipts.d.ts.map +1 -0
- package/dist/core/storage/receipts.js +117 -0
- package/dist/core/storage/segments.d.ts +84 -0
- package/dist/core/storage/segments.d.ts.map +1 -0
- package/dist/core/storage/segments.js +542 -0
- package/dist/core/storage/sink-graph.d.ts +65 -0
- package/dist/core/storage/sink-graph.d.ts.map +1 -0
- package/dist/core/storage/sink-graph.js +213 -0
- package/dist/core/storage/storm-control.d.ts +23 -0
- package/dist/core/storage/storm-control.d.ts.map +1 -0
- package/dist/core/storage/storm-control.js +59 -0
- package/dist/core/work/state.d.ts.map +1 -1
- package/dist/core/work/state.js +10 -14
- package/dist/core/workflow/live-session-v3.d.ts.map +1 -1
- package/dist/core/workflow/live-session-v3.js +2 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/lazy-commands.d.ts +26 -0
- package/dist/lazy-commands.d.ts.map +1 -0
- package/dist/lazy-commands.js +210 -0
- package/dist/lib/docs-lint.d.ts +2 -0
- package/dist/lib/docs-lint.d.ts.map +1 -1
- package/dist/lib/docs-lint.js +45 -80
- package/dist/lib/docs-metadata-audit.d.ts +3 -0
- package/dist/lib/docs-metadata-audit.d.ts.map +1 -1
- package/dist/lib/docs-metadata-audit.js +13 -23
- package/dist/lib/docs-metadata-sync.d.ts +1 -0
- package/dist/lib/docs-metadata-sync.d.ts.map +1 -1
- package/dist/lib/docs-metadata-sync.js +28 -10
- package/dist/lib/docs-repository-view.d.ts +22 -0
- package/dist/lib/docs-repository-view.d.ts.map +1 -0
- package/dist/lib/docs-repository-view.js +185 -0
- package/dist/lib/http/client.d.ts +11 -5
- package/dist/lib/http/client.d.ts.map +1 -1
- package/dist/lib/http/client.js +22 -4
- package/dist/lib/http/index.d.ts +1 -1
- package/dist/lib/http/index.d.ts.map +1 -1
- package/dist/lib/http/index.js +1 -1
- package/dist/lib/indexer-exclusions.d.ts +27 -0
- package/dist/lib/indexer-exclusions.d.ts.map +1 -0
- package/dist/lib/indexer-exclusions.js +176 -0
- package/dist/lib/instructions/templates.d.ts.map +1 -1
- package/dist/lib/instructions/templates.js +5 -0
- package/dist/lib/local-file-url.d.ts +9 -0
- package/dist/lib/local-file-url.d.ts.map +1 -0
- package/dist/lib/local-file-url.js +20 -0
- package/dist/lib/web-performance.d.ts +118 -0
- package/dist/lib/web-performance.d.ts.map +1 -0
- package/dist/lib/web-performance.js +192 -0
- package/package.json +29 -2
- package/schemas/config.schema.json +58 -0
- package/schemas/event-v3.schema.json +324 -112
- package/src/commander.ts +462 -95
- package/src/commands/agents.ts +517 -190
- package/src/commands/backup.ts +18 -14
- package/src/commands/browse-session.ts +12 -0
- package/src/commands/browse.ts +6 -7
- package/src/commands/conversations.ts +279 -0
- package/src/commands/deinit.ts +6 -0
- package/src/commands/docs.ts +25 -6
- package/src/commands/doctor.ts +75 -9
- package/src/commands/fetch.ts +7 -6
- package/src/commands/files.ts +143 -0
- package/src/commands/governor.ts +13 -12
- package/src/commands/inbox.ts +61 -0
- package/src/commands/init.ts +78 -16
- package/src/commands/ledger-v3.ts +421 -1
- package/src/commands/logs.ts +224 -0
- package/src/commands/messages.ts +61 -0
- package/src/commands/outline.ts +6 -2
- package/src/commands/read.ts +6 -2
- package/src/commands/semantic.ts +66 -1
- package/src/commands/storage.ts +310 -0
- package/src/commands/tunnel.ts +66 -52
- package/src/commands/web.ts +77 -7
- package/src/commands/work.ts +3 -3
- package/src/commands/workflow.ts +13 -13
- package/src/core/agents/cli.ts +259 -53
- package/src/core/agents/live-authority-v3.ts +341 -10
- package/src/core/agents/live-lifecycle-v3.ts +6 -1
- package/src/core/agents/live-observation-v3.ts +6 -1
- package/src/core/agents/render/prompt-context.ts +27 -6
- package/src/core/agents/rules/stop-hook.ts +107 -16
- package/src/core/agents/rules/verdict.ts +1 -0
- package/src/core/agents/session-events.ts +4 -0
- package/src/core/agents/session-finalization-state-v3.ts +1 -1
- package/src/core/agents/session-finalizer-v3.ts +4 -1
- package/src/core/agents/state/activity-log.ts +7 -2
- package/src/core/agents/state/heartbeat-writer.ts +27 -0
- package/src/core/agents/state/live-coordination-view.ts +16 -105
- package/src/core/agents/state/live-coordination-writer.ts +141 -0
- package/src/core/artifacts/index.ts +64 -1
- package/src/core/config.ts +126 -5
- package/src/core/conversations/archive.ts +237 -0
- package/src/core/conversations/catalog.ts +79 -0
- package/src/core/conversations/context-pack.ts +72 -0
- package/src/core/conversations/contract.ts +178 -0
- package/src/core/conversations/evaluation.ts +30 -0
- package/src/core/conversations/index.ts +9 -0
- package/src/core/conversations/lifecycle.ts +63 -0
- package/src/core/conversations/normalize.ts +105 -0
- package/src/core/conversations/query.ts +318 -0
- package/src/core/conversations/search-index.ts +48 -0
- package/src/core/events/legacy-storage/canary.ts +177 -0
- package/src/core/events/legacy-storage/fence.ts +129 -0
- package/src/core/events/legacy-storage/index.ts +5 -0
- package/src/core/events/legacy-storage/inventory.ts +51 -0
- package/src/core/events/legacy-storage/manifest.ts +136 -0
- package/src/core/events/legacy-storage/reader.ts +178 -0
- package/src/core/events/v3/authority-outbox.ts +22 -1
- package/src/core/events/v3/base-contract.ts +17 -7
- package/src/core/events/v3/bootstrap.ts +195 -2
- package/src/core/events/v3/capabilities.ts +3 -3
- package/src/core/events/v3/control-witness.ts +339 -0
- package/src/core/events/v3/control-writer.ts +16 -0
- package/src/core/events/v3/control.ts +54 -18
- package/src/core/events/v3/coordination-transaction-recovery.ts +477 -0
- package/src/core/events/v3/coordination-view.ts +17 -1
- package/src/core/events/v3/generated.ts +1 -1
- package/src/core/events/v3/index.ts +5 -2
- package/src/core/events/v3/live-route-observer.ts +80 -0
- package/src/core/events/v3/live-routing.ts +64 -46
- package/src/core/events/v3/producers/coordination-recorder.ts +95 -10
- package/src/core/events/v3/producers/diagnostic-summaries.ts +593 -0
- package/src/core/events/v3/producers/hook-base.ts +1 -1
- package/src/core/events/v3/producers/intake.ts +30 -2
- package/src/core/events/v3/producers/producer-state-observer.ts +52 -0
- package/src/core/events/v3/producers/recorder.ts +571 -33
- package/src/core/events/v3/reader.ts +243 -2
- package/src/core/events/v3/rotation-config.ts +98 -0
- package/src/core/events/v3/runtime-build.ts +41 -0
- package/src/core/events/v3/runtime-identity.ts +16 -0
- package/src/core/events/v3/runtime-telemetry-capabilities.ts +14 -8
- package/src/core/events/v3/support-storage/classify.ts +209 -0
- package/src/core/events/v3/support-storage/eligibility.ts +58 -0
- package/src/core/events/v3/support-storage/index.ts +9 -0
- package/src/core/events/v3/support-storage/inventory.ts +135 -0
- package/src/core/events/v3/support-storage/logical-authority.ts +117 -0
- package/src/core/events/v3/support-storage/maintenance.ts +501 -0
- package/src/core/events/v3/support-storage/pack-contract.ts +337 -0
- package/src/core/events/v3/support-storage/pack-reader.ts +346 -0
- package/src/core/events/v3/support-storage/pack-writer.ts +352 -0
- package/src/core/events/v3/support-storage/recovery.ts +43 -0
- package/src/core/events/v3/turn-telemetry.ts +58 -7
- package/src/core/events/v3/writer.ts +168 -16
- package/src/core/governor/plan-read.ts +5 -18
- package/src/core/governor/planning.ts +5 -8
- package/src/core/governor/service-read.ts +320 -2
- package/src/core/governor/service.ts +49 -22
- package/src/core/guard/evidence-v3.ts +1 -0
- package/src/core/hooks/adapter/events.ts +1 -0
- package/src/core/hooks/adapter/output.ts +12 -5
- package/src/core/hooks/adapter/runtime-telemetry.ts +408 -13
- package/src/core/hooks/cli.ts +226 -32
- package/src/core/hooks/effects/image-capture.ts +4 -1
- package/src/core/hooks/remediation-cap.ts +12 -6
- package/src/core/hooks/resolve/coord-root.ts +91 -11
- package/src/core/hooks/resolve/owner.ts +4 -0
- package/src/core/hooks/resolve/transcript.ts +18 -0
- package/src/core/inbox/contract.ts +81 -0
- package/src/core/inbox/index.ts +4 -0
- package/src/core/inbox/lifecycle.ts +104 -0
- package/src/core/inbox/service.ts +305 -0
- package/src/core/inbox/watcher.ts +36 -0
- package/src/core/presence/codec-digest.ts +15 -9
- package/src/core/presence/relay-client.ts +55 -7
- package/src/core/semantic/adapters.ts +200 -41
- package/src/core/semantic/contract.ts +135 -3
- package/src/core/semantic/index.ts +76 -2
- package/src/core/semantic/once.ts +93 -7
- package/src/core/semantic/prompt.ts +13 -1
- package/src/core/semantic/review.ts +803 -0
- package/src/core/semantic/routes.ts +30 -0
- package/src/core/semantic/scheduler.ts +49 -5
- package/src/core/semantic/service-status.ts +99 -5
- package/src/core/semantic/service.ts +116 -15
- package/src/core/semantic/soak.ts +638 -0
- package/src/core/semantic/storage.ts +20 -6
- package/src/core/semantic/usage.ts +272 -0
- package/src/core/semantic/validate.ts +31 -0
- package/src/core/storage/buffer.ts +124 -0
- package/src/core/storage/builtins.ts +916 -0
- package/src/core/storage/catalog.ts +467 -0
- package/src/core/storage/config.ts +423 -0
- package/src/core/storage/contract.ts +342 -0
- package/src/core/storage/durable-history.ts +738 -0
- package/src/core/storage/health.ts +76 -0
- package/src/core/storage/index.ts +15 -0
- package/src/core/storage/inventory.ts +859 -0
- package/src/core/storage/jsonl.ts +213 -0
- package/src/core/storage/log-retention.ts +555 -0
- package/src/core/storage/logger.ts +546 -0
- package/src/core/storage/maintenance-providers.ts +200 -0
- package/src/core/storage/maintenance.ts +929 -0
- package/src/core/storage/metrics.ts +199 -0
- package/src/core/storage/policy.ts +141 -0
- package/src/core/storage/process-log.ts +203 -0
- package/src/core/storage/query.ts +360 -0
- package/src/core/storage/receipts.ts +162 -0
- package/src/core/storage/segments.ts +721 -0
- package/src/core/storage/sink-graph.ts +343 -0
- package/src/core/storage/storm-control.ts +91 -0
- package/src/core/work/state.ts +12 -21
- package/src/core/workflow/live-session-v3.ts +2 -4
- package/src/index.ts +2 -0
- package/src/lazy-commands.ts +294 -0
- package/src/lib/docs-lint.ts +58 -77
- package/src/lib/docs-metadata-audit.ts +26 -21
- package/src/lib/docs-metadata-sync.ts +32 -9
- package/src/lib/docs-repository-view.ts +220 -0
- package/src/lib/http/client.ts +44 -8
- package/src/lib/http/index.ts +6 -1
- package/src/lib/indexer-exclusions.ts +173 -0
- package/src/lib/instructions/templates.ts +5 -0
- package/src/lib/local-file-url.ts +31 -0
- package/src/lib/web-performance.ts +335 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { normalizeConversationRecord } from "./normalize.js";
|
|
2
|
+
export async function queryConversationCatalog(catalog, request) {
|
|
3
|
+
validateRequest(request);
|
|
4
|
+
const started = performance.now();
|
|
5
|
+
const deadline = started + request.budgets.max_wall_ms;
|
|
6
|
+
const controller = new AbortController();
|
|
7
|
+
const records = [];
|
|
8
|
+
const snapshots = [];
|
|
9
|
+
let decodedBytes = 0;
|
|
10
|
+
let sourceRecords = 0;
|
|
11
|
+
let sourceTruncation;
|
|
12
|
+
const providers = request.provider_id ? [catalog.require(request.provider_id)] : catalog.list();
|
|
13
|
+
try {
|
|
14
|
+
providerLoop: for (const provider of providers) {
|
|
15
|
+
if (!provider.capabilities.can_list || !provider.capabilities.can_stream_source)
|
|
16
|
+
continue;
|
|
17
|
+
if (deadlineExpired(deadline)) {
|
|
18
|
+
sourceTruncation = "wall_budget";
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
let summaries;
|
|
22
|
+
try {
|
|
23
|
+
summaries = await beforeDeadline(provider.list(request.project_scope_id, { signal: controller.signal }), deadline, controller);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (!isWallBudgetError(error))
|
|
27
|
+
throw error;
|
|
28
|
+
sourceTruncation = "wall_budget";
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
for (const summary of summaries) {
|
|
32
|
+
if (deadlineExpired(deadline)) {
|
|
33
|
+
controller.abort();
|
|
34
|
+
sourceTruncation = "wall_budget";
|
|
35
|
+
break providerLoop;
|
|
36
|
+
}
|
|
37
|
+
if (summary.project_scope_id !== request.project_scope_id)
|
|
38
|
+
continue;
|
|
39
|
+
if (request.conversation_id && summary.conversation_id !== request.conversation_id)
|
|
40
|
+
continue;
|
|
41
|
+
let snapshot;
|
|
42
|
+
try {
|
|
43
|
+
snapshot = await beforeDeadline(provider.snapshot(request.project_scope_id, summary.conversation_id, {
|
|
44
|
+
signal: controller.signal,
|
|
45
|
+
}), deadline, controller);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (!isWallBudgetError(error))
|
|
49
|
+
throw error;
|
|
50
|
+
sourceTruncation = "wall_budget";
|
|
51
|
+
break providerLoop;
|
|
52
|
+
}
|
|
53
|
+
snapshots.push(snapshot);
|
|
54
|
+
let sequence = 0;
|
|
55
|
+
const iterator = provider
|
|
56
|
+
.stream(request.project_scope_id, summary.conversation_id, {
|
|
57
|
+
signal: controller.signal,
|
|
58
|
+
})[Symbol.asyncIterator]();
|
|
59
|
+
let iteratorCompleted = false;
|
|
60
|
+
try {
|
|
61
|
+
while (true) {
|
|
62
|
+
if (sourceRecords >= request.budgets.max_source_records) {
|
|
63
|
+
sourceTruncation = "record_budget";
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
let next;
|
|
67
|
+
try {
|
|
68
|
+
next = await beforeDeadline(iterator.next(), deadline, controller);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
if (!isWallBudgetError(error))
|
|
72
|
+
throw error;
|
|
73
|
+
sourceTruncation = "wall_budget";
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
if (next.done) {
|
|
77
|
+
iteratorCompleted = true;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
sourceRecords += 1;
|
|
81
|
+
sequence += 1;
|
|
82
|
+
const native = next.value;
|
|
83
|
+
const rawBytes = typeof native.content === "string" ? Buffer.byteLength(native.content) : 0;
|
|
84
|
+
if (decodedBytes + rawBytes > request.budgets.max_decoded_bytes) {
|
|
85
|
+
sourceTruncation = "byte_budget";
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
if (deadlineExpired(deadline)) {
|
|
89
|
+
controller.abort();
|
|
90
|
+
sourceTruncation = "wall_budget";
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
const normalized = normalizeConversationRecord({
|
|
94
|
+
capabilities: provider.capabilities,
|
|
95
|
+
snapshot,
|
|
96
|
+
native,
|
|
97
|
+
captured_at: snapshot.observed_at,
|
|
98
|
+
sequence,
|
|
99
|
+
});
|
|
100
|
+
decodedBytes += rawBytes;
|
|
101
|
+
if (deadlineExpired(deadline)) {
|
|
102
|
+
controller.abort();
|
|
103
|
+
sourceTruncation = "wall_budget";
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
if (normalized.record)
|
|
107
|
+
records.push(normalized.record);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
if (!iteratorCompleted)
|
|
112
|
+
requestIteratorReturn(iterator);
|
|
113
|
+
}
|
|
114
|
+
if (sourceTruncation)
|
|
115
|
+
break providerLoop;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
if (sourceTruncation)
|
|
121
|
+
controller.abort();
|
|
122
|
+
}
|
|
123
|
+
const result = queryConversationRecords(records, snapshots, request, { started_at: started });
|
|
124
|
+
if (!sourceTruncation || result.truncated)
|
|
125
|
+
return result;
|
|
126
|
+
return { ...result, truncated: true, truncation_reason: sourceTruncation };
|
|
127
|
+
}
|
|
128
|
+
class ConversationWallBudgetError extends Error {
|
|
129
|
+
}
|
|
130
|
+
async function beforeDeadline(operation, deadline, controller) {
|
|
131
|
+
const remaining = deadline - performance.now();
|
|
132
|
+
if (remaining <= 0) {
|
|
133
|
+
controller.abort();
|
|
134
|
+
throw new ConversationWallBudgetError();
|
|
135
|
+
}
|
|
136
|
+
let timer;
|
|
137
|
+
try {
|
|
138
|
+
const timeout = new Promise((_resolve, reject) => {
|
|
139
|
+
timer = setTimeout(() => {
|
|
140
|
+
controller.abort();
|
|
141
|
+
reject(new ConversationWallBudgetError());
|
|
142
|
+
}, remaining);
|
|
143
|
+
});
|
|
144
|
+
const result = await Promise.race([operation, timeout]);
|
|
145
|
+
if (deadlineExpired(deadline)) {
|
|
146
|
+
controller.abort();
|
|
147
|
+
throw new ConversationWallBudgetError();
|
|
148
|
+
}
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
finally {
|
|
152
|
+
if (timer !== undefined)
|
|
153
|
+
clearTimeout(timer);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function deadlineExpired(deadline) {
|
|
157
|
+
return performance.now() >= deadline;
|
|
158
|
+
}
|
|
159
|
+
function isWallBudgetError(error) {
|
|
160
|
+
return error instanceof ConversationWallBudgetError;
|
|
161
|
+
}
|
|
162
|
+
function requestIteratorReturn(iterator) {
|
|
163
|
+
try {
|
|
164
|
+
const returned = iterator.return?.();
|
|
165
|
+
if (returned)
|
|
166
|
+
void Promise.resolve(returned).catch(() => undefined);
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
// A provider cleanup failure cannot widen the query budget or replace its reason code.
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
export function queryConversationRecords(inputRecords, snapshots, request, internal = {}) {
|
|
173
|
+
validateRequest(request);
|
|
174
|
+
const started = internal.started_at ?? performance.now();
|
|
175
|
+
const records = [...inputRecords].sort((left, right) => left.project_scope_id.localeCompare(right.project_scope_id) ||
|
|
176
|
+
left.provider_id.localeCompare(right.provider_id) ||
|
|
177
|
+
left.conversation_id.localeCompare(right.conversation_id) ||
|
|
178
|
+
left.sequence - right.sequence ||
|
|
179
|
+
left.record_id.localeCompare(right.record_id));
|
|
180
|
+
const regex = request.regex
|
|
181
|
+
? compileRegex(request.regex, request.budgets.max_regex_chars)
|
|
182
|
+
: undefined;
|
|
183
|
+
const hits = [];
|
|
184
|
+
let scannedRecords = 0;
|
|
185
|
+
let decodedBytes = 0;
|
|
186
|
+
let truncation;
|
|
187
|
+
for (let index = 0; index < records.length; index += 1) {
|
|
188
|
+
const record = records[index];
|
|
189
|
+
if (!structuredMatch(record, request))
|
|
190
|
+
continue;
|
|
191
|
+
if (scannedRecords >= request.budgets.max_source_records) {
|
|
192
|
+
truncation = "record_budget";
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
if (decodedBytes + record.content_bytes > request.budgets.max_decoded_bytes) {
|
|
196
|
+
truncation = "byte_budget";
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
if (performance.now() - started > request.budgets.max_wall_ms) {
|
|
200
|
+
truncation = "wall_budget";
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
scannedRecords += 1;
|
|
204
|
+
decodedBytes += record.content_bytes;
|
|
205
|
+
if (request.text && !record.content.includes(request.text))
|
|
206
|
+
continue;
|
|
207
|
+
if (regex && !regex.test(record.content))
|
|
208
|
+
continue;
|
|
209
|
+
if (hits.length >= Math.min(request.limit, request.budgets.max_matches)) {
|
|
210
|
+
truncation = "match_budget";
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
hits.push({
|
|
214
|
+
record,
|
|
215
|
+
citation: citation(record),
|
|
216
|
+
neighbors: neighbors(records, index, request.context_before ?? 0, request.context_after ?? 0),
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
schema: "harnery.conversation-query/v1",
|
|
221
|
+
request,
|
|
222
|
+
hits,
|
|
223
|
+
scanned_records: scannedRecords,
|
|
224
|
+
decoded_bytes: decodedBytes,
|
|
225
|
+
truncated: truncation !== undefined,
|
|
226
|
+
...(truncation ? { truncation_reason: truncation } : {}),
|
|
227
|
+
snapshots: [...snapshots].sort((left, right) => left.snapshot_id.localeCompare(right.snapshot_id)),
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
export function citation(record) {
|
|
231
|
+
return {
|
|
232
|
+
record_id: record.record_id,
|
|
233
|
+
provider_id: record.provider_id,
|
|
234
|
+
conversation_id: record.conversation_id,
|
|
235
|
+
role: record.role,
|
|
236
|
+
occurred_at: record.occurred_at,
|
|
237
|
+
native_conversation_id: record.source.native_conversation_id,
|
|
238
|
+
...(record.source.native_record_id ? { native_record_id: record.source.native_record_id } : {}),
|
|
239
|
+
content_digest: record.content_digest,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
function structuredMatch(record, request) {
|
|
243
|
+
return (record.project_scope_id === request.project_scope_id &&
|
|
244
|
+
(!request.provider_id || record.provider_id === request.provider_id) &&
|
|
245
|
+
(!request.role || record.role === request.role) &&
|
|
246
|
+
(!request.session_id || record.session_id === request.session_id) &&
|
|
247
|
+
(!request.conversation_id || record.conversation_id === request.conversation_id) &&
|
|
248
|
+
(!request.record_id || record.record_id === request.record_id) &&
|
|
249
|
+
(!request.since || record.occurred_at >= new Date(request.since).toISOString()) &&
|
|
250
|
+
(!request.until || record.occurred_at <= new Date(request.until).toISOString()));
|
|
251
|
+
}
|
|
252
|
+
function neighbors(records, index, before, after) {
|
|
253
|
+
const target = records[index];
|
|
254
|
+
return records
|
|
255
|
+
.slice(Math.max(0, index - before), index + after + 1)
|
|
256
|
+
.filter((record) => record.record_id !== target.record_id &&
|
|
257
|
+
record.project_scope_id === target.project_scope_id &&
|
|
258
|
+
record.provider_id === target.provider_id &&
|
|
259
|
+
record.conversation_id === target.conversation_id);
|
|
260
|
+
}
|
|
261
|
+
function compileRegex(pattern, maxChars) {
|
|
262
|
+
if (pattern.length === 0 || pattern.length > maxChars)
|
|
263
|
+
throw new Error("conversation regex limit");
|
|
264
|
+
if (/\([^)]*[+*][^)]*\)[+*{]/.test(pattern))
|
|
265
|
+
throw new Error("unsafe nested conversation regex");
|
|
266
|
+
return new RegExp(pattern, "iu");
|
|
267
|
+
}
|
|
268
|
+
function validateRequest(request) {
|
|
269
|
+
if (!request.project_scope_id)
|
|
270
|
+
throw new Error("conversation query requires project_scope_id");
|
|
271
|
+
for (const [field, value] of Object.entries({ limit: request.limit, ...request.budgets })) {
|
|
272
|
+
if (!Number.isSafeInteger(value) || value <= 0)
|
|
273
|
+
throw new Error(`invalid conversation ${field}`);
|
|
274
|
+
}
|
|
275
|
+
if (request.role && request.role !== "user" && request.role !== "assistant") {
|
|
276
|
+
throw new Error("excluded conversation role");
|
|
277
|
+
}
|
|
278
|
+
if (request.text && request.regex)
|
|
279
|
+
throw new Error("conversation query accepts text or regex, not both");
|
|
280
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HarneryConversationRecordV1 } from "./contract.js";
|
|
2
|
+
export interface HarneryConversationSearchIndexV1 {
|
|
3
|
+
schema: "harnery.conversation-search-index/v1";
|
|
4
|
+
source_digest: `sha256:${string}`;
|
|
5
|
+
terms: Readonly<Record<string, readonly string[]>>;
|
|
6
|
+
}
|
|
7
|
+
export declare function buildConversationSearchIndex(records: readonly HarneryConversationRecordV1[]): HarneryConversationSearchIndexV1;
|
|
8
|
+
export declare function verifyIndexedRecords(index: HarneryConversationSearchIndexV1, records: readonly HarneryConversationRecordV1[], term: string): HarneryConversationRecordV1[];
|
|
9
|
+
//# sourceMappingURL=search-index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-index.d.ts","sourceRoot":"","sources":["../../../src/core/conversations/search-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAGjE,MAAM,WAAW,gCAAgC;IAC/C,MAAM,EAAE,sCAAsC,CAAC;IAC/C,aAAa,EAAE,UAAU,MAAM,EAAE,CAAC;IAClC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;CACpD;AAED,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,SAAS,2BAA2B,EAAE,GAC9C,gCAAgC,CAqBlC;AAED,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,gCAAgC,EACvC,OAAO,EAAE,SAAS,2BAA2B,EAAE,EAC/C,IAAI,EAAE,MAAM,GACX,2BAA2B,EAAE,CAS/B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { digest } from "./normalize.js";
|
|
2
|
+
export function buildConversationSearchIndex(records) {
|
|
3
|
+
const terms = new Map();
|
|
4
|
+
const ordered = [...records].sort((left, right) => left.record_id.localeCompare(right.record_id));
|
|
5
|
+
for (const record of ordered) {
|
|
6
|
+
for (const term of record.content.toLocaleLowerCase().match(/[\p{L}\p{N}_-]{2,}/gu) ?? []) {
|
|
7
|
+
const ids = terms.get(term) ?? new Set();
|
|
8
|
+
ids.add(record.record_id);
|
|
9
|
+
terms.set(term, ids);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
schema: "harnery.conversation-search-index/v1",
|
|
14
|
+
source_digest: digest(ordered.map((record) => `${record.record_id}:${record.content_digest}`).join("\n")),
|
|
15
|
+
terms: Object.fromEntries([...terms]
|
|
16
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
17
|
+
.map(([term, ids]) => [term, [...ids].sort()])),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function verifyIndexedRecords(index, records, term) {
|
|
21
|
+
const byId = new Map(records.map((record) => [record.record_id, record]));
|
|
22
|
+
return (index.terms[term.toLocaleLowerCase()] ?? []).map((id) => {
|
|
23
|
+
const record = byId.get(id);
|
|
24
|
+
if (!record?.content.toLocaleLowerCase().includes(term.toLocaleLowerCase())) {
|
|
25
|
+
throw new Error(`stale conversation index hit: ${id}`);
|
|
26
|
+
}
|
|
27
|
+
return record;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type LegacyV1SegmentManifest } from "./manifest.js";
|
|
2
|
+
export interface LegacyV1CanaryResult {
|
|
3
|
+
manifest: LegacyV1SegmentManifest;
|
|
4
|
+
manifest_path: string;
|
|
5
|
+
payload_path: string;
|
|
6
|
+
source_unchanged: true;
|
|
7
|
+
replacement_enabled: false;
|
|
8
|
+
}
|
|
9
|
+
/** Shadow-compress one fenced legacy segment, then prove byte and row parity. */
|
|
10
|
+
export declare function writeLegacyV1Canary(input: {
|
|
11
|
+
coord_root: string;
|
|
12
|
+
source_filename: string;
|
|
13
|
+
output_directory: string;
|
|
14
|
+
minimum_harnery_version: string;
|
|
15
|
+
created_at: string;
|
|
16
|
+
}): Promise<LegacyV1CanaryResult>;
|
|
17
|
+
export declare function activateLegacyV1CanaryReplacement(): never;
|
|
18
|
+
//# sourceMappingURL=canary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canary.d.ts","sourceRoot":"","sources":["../../../../src/core/events/legacy-storage/canary.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,uBAAuB,EAAmC,MAAM,eAAe,CAAC;AAG9F,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,uBAAuB,CAAC;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,IAAI,CAAC;IACvB,mBAAmB,EAAE,KAAK,CAAC;CAC5B;AAED,iFAAiF;AACjF,wBAAsB,mBAAmB,CAAC,KAAK,EAAE;IAC/C,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,uBAAuB,EAAE,MAAM,CAAC;IAChC,UAAU,EAAE,MAAM,CAAC;CACpB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAyFhC;AAED,wBAAgB,iCAAiC,IAAI,KAAK,CAEzD"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { constants, createReadStream, createWriteStream } from "node:fs";
|
|
3
|
+
import { chmod, lstat, mkdir, open, rename, rm } from "node:fs/promises";
|
|
4
|
+
import { basename, join, resolve } from "node:path";
|
|
5
|
+
import { pipeline } from "node:stream/promises";
|
|
6
|
+
import { createGzip } from "node:zlib";
|
|
7
|
+
import { canonicalJsonV3 } from "../v3/canonical.js";
|
|
8
|
+
import { verifyLegacyV1HardFence } from "./fence.js";
|
|
9
|
+
import { validateLegacyV1SegmentManifest } from "./manifest.js";
|
|
10
|
+
import { streamLegacyV1Rows } from "./reader.js";
|
|
11
|
+
/** Shadow-compress one fenced legacy segment, then prove byte and row parity. */
|
|
12
|
+
export async function writeLegacyV1Canary(input) {
|
|
13
|
+
await verifyLegacyV1HardFence(input.coord_root);
|
|
14
|
+
if (!/^events.+\.ndjson$/.test(input.source_filename) ||
|
|
15
|
+
input.source_filename.includes("/") ||
|
|
16
|
+
input.source_filename.includes("\\")) {
|
|
17
|
+
throw new Error("legacy_v1_canary_source_name_invalid");
|
|
18
|
+
}
|
|
19
|
+
const harnery = resolve(input.coord_root, ".harnery");
|
|
20
|
+
const source = join(harnery, input.source_filename);
|
|
21
|
+
const sourceStat = await lstat(source);
|
|
22
|
+
if (!sourceStat.isFile() || sourceStat.isSymbolicLink()) {
|
|
23
|
+
throw new Error("legacy_v1_canary_source_not_regular");
|
|
24
|
+
}
|
|
25
|
+
const sourceDigest = await hashFile(source);
|
|
26
|
+
const sourceFacts = await inspectRows(source);
|
|
27
|
+
const segmentId = `v1s_${createHash("sha256")
|
|
28
|
+
.update(`${input.source_filename}\0${sourceStat.size}\0${sourceDigest}`)
|
|
29
|
+
.digest("hex")
|
|
30
|
+
.slice(0, 32)}`;
|
|
31
|
+
const outputDirectory = resolve(input.output_directory);
|
|
32
|
+
await mkdir(outputDirectory, { recursive: true, mode: 0o700 });
|
|
33
|
+
await chmod(outputDirectory, 0o700);
|
|
34
|
+
const payloadPath = join(outputDirectory, `${segmentId}.ndjson.gz`);
|
|
35
|
+
const manifestPath = join(outputDirectory, `${segmentId}.manifest.json`);
|
|
36
|
+
const partialPayload = `${payloadPath}.partial`;
|
|
37
|
+
const partialManifest = `${manifestPath}.partial`;
|
|
38
|
+
await rejectExisting([payloadPath, manifestPath, partialPayload, partialManifest]);
|
|
39
|
+
try {
|
|
40
|
+
await pipeline(createReadStream(source), createGzip({ level: 9 }), createWriteStream(partialPayload, { flags: "wx", mode: 0o600 }));
|
|
41
|
+
await rename(partialPayload, payloadPath);
|
|
42
|
+
const payloadStat = await lstat(payloadPath);
|
|
43
|
+
const manifest = validateLegacyV1SegmentManifest({
|
|
44
|
+
format: "harnery-legacy-v1-segment",
|
|
45
|
+
format_version: 1,
|
|
46
|
+
segment_id: segmentId,
|
|
47
|
+
source: {
|
|
48
|
+
filename: input.source_filename,
|
|
49
|
+
bytes: sourceStat.size,
|
|
50
|
+
digest: sourceDigest,
|
|
51
|
+
row_count: sourceFacts.rows,
|
|
52
|
+
minimum_recorded_at: sourceFacts.minimum,
|
|
53
|
+
maximum_recorded_at: sourceFacts.maximum,
|
|
54
|
+
},
|
|
55
|
+
payload: {
|
|
56
|
+
algorithm: "gzip",
|
|
57
|
+
path: basename(payloadPath),
|
|
58
|
+
bytes: payloadStat.size,
|
|
59
|
+
digest: await hashFile(payloadPath),
|
|
60
|
+
},
|
|
61
|
+
minimum_harnery_version: input.minimum_harnery_version,
|
|
62
|
+
created_at: input.created_at,
|
|
63
|
+
});
|
|
64
|
+
const handle = await open(partialManifest, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL, 0o600);
|
|
65
|
+
try {
|
|
66
|
+
await handle.writeFile(`${canonicalJsonV3(manifest)}\n`, "utf8");
|
|
67
|
+
await handle.sync();
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
await handle.close();
|
|
71
|
+
}
|
|
72
|
+
await rename(partialManifest, manifestPath);
|
|
73
|
+
await proveRowParity(source, manifestPath);
|
|
74
|
+
const after = await lstat(source);
|
|
75
|
+
if (after.size !== sourceStat.size || (await hashFile(source)) !== sourceDigest) {
|
|
76
|
+
throw new Error("legacy_v1_canary_source_changed");
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
manifest,
|
|
80
|
+
manifest_path: manifestPath,
|
|
81
|
+
payload_path: payloadPath,
|
|
82
|
+
source_unchanged: true,
|
|
83
|
+
replacement_enabled: false,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
await rm(partialPayload, { force: true });
|
|
88
|
+
await rm(partialManifest, { force: true });
|
|
89
|
+
await rm(payloadPath, { force: true });
|
|
90
|
+
await rm(manifestPath, { force: true });
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export function activateLegacyV1CanaryReplacement() {
|
|
95
|
+
throw new Error("legacy_v1_replacement_activation_disabled");
|
|
96
|
+
}
|
|
97
|
+
async function inspectRows(path) {
|
|
98
|
+
let rows = 0;
|
|
99
|
+
const timestamps = [];
|
|
100
|
+
for await (const row of streamLegacyV1Rows(path)) {
|
|
101
|
+
rows += 1;
|
|
102
|
+
const value = JSON.parse(row.bytes.toString("utf8"));
|
|
103
|
+
const candidate = typeof value.at === "string"
|
|
104
|
+
? value.at
|
|
105
|
+
: typeof value.timestamp === "string"
|
|
106
|
+
? value.timestamp
|
|
107
|
+
: value.time &&
|
|
108
|
+
typeof value.time === "object" &&
|
|
109
|
+
typeof value.time.observed_at === "string"
|
|
110
|
+
? value.time.observed_at
|
|
111
|
+
: undefined;
|
|
112
|
+
if (candidate && Number.isFinite(Date.parse(candidate)))
|
|
113
|
+
timestamps.push(new Date(candidate).toISOString());
|
|
114
|
+
}
|
|
115
|
+
timestamps.sort();
|
|
116
|
+
return { rows, minimum: timestamps[0] ?? null, maximum: timestamps.at(-1) ?? null };
|
|
117
|
+
}
|
|
118
|
+
async function proveRowParity(loose, manifest) {
|
|
119
|
+
const left = streamLegacyV1Rows(loose)[Symbol.asyncIterator]();
|
|
120
|
+
const right = streamLegacyV1Rows(manifest)[Symbol.asyncIterator]();
|
|
121
|
+
while (true) {
|
|
122
|
+
const [looseRow, packedRow] = await Promise.all([left.next(), right.next()]);
|
|
123
|
+
if (looseRow.done || packedRow.done) {
|
|
124
|
+
if (looseRow.done !== packedRow.done)
|
|
125
|
+
throw new Error("legacy_v1_canary_row_count_mismatch");
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
if (!looseRow.value.bytes.equals(packedRow.value.bytes)) {
|
|
129
|
+
throw new Error(`legacy_v1_canary_row_mismatch:${looseRow.value.row_number}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async function hashFile(path) {
|
|
134
|
+
const hash = createHash("sha256");
|
|
135
|
+
for await (const current of createReadStream(path))
|
|
136
|
+
hash.update(current);
|
|
137
|
+
return `sha256:${hash.digest("hex")}`;
|
|
138
|
+
}
|
|
139
|
+
async function rejectExisting(paths) {
|
|
140
|
+
for (const path of paths) {
|
|
141
|
+
try {
|
|
142
|
+
await lstat(path);
|
|
143
|
+
throw new Error("legacy_v1_canary_output_exists");
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
if (error.code !== "ENOENT")
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface LegacyV1HardFence {
|
|
2
|
+
manifest_version: 1;
|
|
3
|
+
kind: "v1_hard_path_fence";
|
|
4
|
+
terminal_archive: string;
|
|
5
|
+
terminal_digest: `sha256:${string}`;
|
|
6
|
+
}
|
|
7
|
+
export interface VerifiedLegacyV1HardFence {
|
|
8
|
+
fence_directory: string;
|
|
9
|
+
marker_path: string;
|
|
10
|
+
terminal_archive_path: string;
|
|
11
|
+
marker: LegacyV1HardFence;
|
|
12
|
+
}
|
|
13
|
+
/** Verify the exact read-only V1 path fence and its terminal sealed segment. */
|
|
14
|
+
export declare function verifyLegacyV1HardFence(coordRoot: string): Promise<VerifiedLegacyV1HardFence>;
|
|
15
|
+
//# sourceMappingURL=fence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fence.d.ts","sourceRoot":"","sources":["../../../../src/core/events/legacy-storage/fence.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,iBAAiB;IAChC,gBAAgB,EAAE,CAAC,CAAC;IACpB,IAAI,EAAE,oBAAoB,CAAC;IAC3B,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,UAAU,MAAM,EAAE,CAAC;CACrC;AAED,MAAM,WAAW,yBAAyB;IACxC,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,MAAM,EAAE,iBAAiB,CAAC;CAC3B;AAKD,gFAAgF;AAChF,wBAAsB,uBAAuB,CAC3C,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,yBAAyB,CAAC,CA0DpC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { constants, createReadStream } from "node:fs";
|
|
3
|
+
import { lstat, open, readdir, realpath } from "node:fs/promises";
|
|
4
|
+
import { basename, join, relative, resolve } from "node:path";
|
|
5
|
+
import { canonicalJsonV3 } from "../v3/canonical.js";
|
|
6
|
+
const MARKER = "V1-SEALED.json";
|
|
7
|
+
const LEGACY_ACTIVE_NAME = ["events", "ndjson"].join(".");
|
|
8
|
+
/** Verify the exact read-only V1 path fence and its terminal sealed segment. */
|
|
9
|
+
export async function verifyLegacyV1HardFence(coordRoot) {
|
|
10
|
+
const root = resolve(coordRoot);
|
|
11
|
+
const harnery = join(root, ".harnery");
|
|
12
|
+
const harneryStat = await lstat(harnery);
|
|
13
|
+
if (!harneryStat.isDirectory() || harneryStat.isSymbolicLink()) {
|
|
14
|
+
throw new Error("legacy_v1_harnery_root_invalid");
|
|
15
|
+
}
|
|
16
|
+
const harneryReal = await realpath(harnery);
|
|
17
|
+
const fence = join(harnery, LEGACY_ACTIVE_NAME);
|
|
18
|
+
let fenceStat;
|
|
19
|
+
try {
|
|
20
|
+
fenceStat = await lstat(fence);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
if (error.code === "ENOENT") {
|
|
24
|
+
throw new Error("legacy_v1_hard_fence_missing");
|
|
25
|
+
}
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
if (!fenceStat.isDirectory() || fenceStat.isSymbolicLink()) {
|
|
29
|
+
throw new Error("legacy_v1_active_file_present_or_fence_invalid");
|
|
30
|
+
}
|
|
31
|
+
if ((fenceStat.mode & 0o222) !== 0)
|
|
32
|
+
throw new Error("legacy_v1_hard_fence_is_writable");
|
|
33
|
+
const fenceReal = await realpath(fence);
|
|
34
|
+
if (relative(harneryReal, fenceReal).startsWith(".."))
|
|
35
|
+
throw new Error("legacy_v1_hard_fence_escape");
|
|
36
|
+
const names = (await readdir(fence)).sort();
|
|
37
|
+
if (names.length !== 1 || names[0] !== MARKER)
|
|
38
|
+
throw new Error("legacy_v1_hard_fence_not_exact");
|
|
39
|
+
const markerPath = join(fence, MARKER);
|
|
40
|
+
const markerStat = await lstat(markerPath);
|
|
41
|
+
if (!markerStat.isFile() || markerStat.isSymbolicLink()) {
|
|
42
|
+
throw new Error("legacy_v1_hard_fence_marker_invalid");
|
|
43
|
+
}
|
|
44
|
+
if ((markerStat.mode & 0o222) !== 0)
|
|
45
|
+
throw new Error("legacy_v1_hard_fence_marker_writable");
|
|
46
|
+
if (markerStat.size > 64 * 1024)
|
|
47
|
+
throw new Error("legacy_v1_hard_fence_marker_too_large");
|
|
48
|
+
const markerText = await readFileNoFollow(markerPath);
|
|
49
|
+
const marker = validateFenceMarker(JSON.parse(markerText));
|
|
50
|
+
if (markerText.trim() !== canonicalJsonV3(marker)) {
|
|
51
|
+
throw new Error("legacy_v1_hard_fence_marker_noncanonical");
|
|
52
|
+
}
|
|
53
|
+
const terminalName = marker.terminal_archive.replace(/^\.harnery\//, "");
|
|
54
|
+
if (!/^events-[0-9]{4}-[0-9]{2}-[0-9]{2}(?:\.[1-9][0-9]*)?\.ndjson$/.test(terminalName)) {
|
|
55
|
+
throw new Error("legacy_v1_terminal_archive_name_invalid");
|
|
56
|
+
}
|
|
57
|
+
const terminalPath = join(harnery, terminalName);
|
|
58
|
+
const terminalStat = await lstat(terminalPath);
|
|
59
|
+
if (!terminalStat.isFile() || terminalStat.isSymbolicLink()) {
|
|
60
|
+
throw new Error("legacy_v1_terminal_archive_invalid");
|
|
61
|
+
}
|
|
62
|
+
if ((await hashFile(terminalPath)) !== marker.terminal_digest) {
|
|
63
|
+
throw new Error("legacy_v1_terminal_archive_digest_mismatch");
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
fence_directory: fence,
|
|
67
|
+
marker_path: markerPath,
|
|
68
|
+
terminal_archive_path: terminalPath,
|
|
69
|
+
marker,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function validateFenceMarker(value) {
|
|
73
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
74
|
+
throw new Error("legacy_v1_hard_fence_marker_invalid");
|
|
75
|
+
}
|
|
76
|
+
const marker = value;
|
|
77
|
+
if (Object.keys(marker).sort().join("\0") !==
|
|
78
|
+
["kind", "manifest_version", "terminal_archive", "terminal_digest"].sort().join("\0") ||
|
|
79
|
+
marker.manifest_version !== 1 ||
|
|
80
|
+
marker.kind !== "v1_hard_path_fence" ||
|
|
81
|
+
typeof marker.terminal_archive !== "string" ||
|
|
82
|
+
typeof marker.terminal_digest !== "string" ||
|
|
83
|
+
!/^sha256:[0-9a-f]{64}$/.test(marker.terminal_digest)) {
|
|
84
|
+
throw new Error("legacy_v1_hard_fence_marker_invalid");
|
|
85
|
+
}
|
|
86
|
+
return marker;
|
|
87
|
+
}
|
|
88
|
+
async function readFileNoFollow(path) {
|
|
89
|
+
const handle = await open(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
90
|
+
try {
|
|
91
|
+
const stat = await handle.stat();
|
|
92
|
+
if (!stat.isFile())
|
|
93
|
+
throw new Error("legacy_v1_hard_fence_marker_invalid");
|
|
94
|
+
return handle.readFile("utf8");
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
await handle.close();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async function hashFile(path) {
|
|
101
|
+
const hash = createHash("sha256");
|
|
102
|
+
const handle = await open(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
103
|
+
try {
|
|
104
|
+
const stat = await handle.stat();
|
|
105
|
+
if (!stat.isFile())
|
|
106
|
+
throw new Error(`legacy_v1_segment_not_regular:${basename(path)}`);
|
|
107
|
+
const stream = createReadStream(path, { fd: handle.fd, autoClose: false });
|
|
108
|
+
for await (const current of stream)
|
|
109
|
+
hash.update(current);
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
await handle.close();
|
|
113
|
+
}
|
|
114
|
+
return `sha256:${hash.digest("hex")}`;
|
|
115
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/events/legacy-storage/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface LegacyV1SegmentInventoryEntry {
|
|
2
|
+
filename: string;
|
|
3
|
+
path: string;
|
|
4
|
+
bytes: number;
|
|
5
|
+
digest: `sha256:${string}`;
|
|
6
|
+
compressed: boolean;
|
|
7
|
+
}
|
|
8
|
+
/** Enumerate all root events*.ndjson* frozen-history candidates, including manual variants. */
|
|
9
|
+
export declare function inventoryLegacyV1Segments(coordRoot: string): Promise<LegacyV1SegmentInventoryEntry[]>;
|
|
10
|
+
//# sourceMappingURL=inventory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inventory.d.ts","sourceRoot":"","sources":["../../../../src/core/events/legacy-storage/inventory.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,UAAU,MAAM,EAAE,CAAC;IAC3B,UAAU,EAAE,OAAO,CAAC;CACrB;AAID,+FAA+F;AAC/F,wBAAsB,yBAAyB,CAC7C,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,6BAA6B,EAAE,CAAC,CA0B1C"}
|