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,360 @@
|
|
|
1
|
+
import {
|
|
2
|
+
closeSync,
|
|
3
|
+
existsSync,
|
|
4
|
+
constants as fsConstants,
|
|
5
|
+
fstatSync,
|
|
6
|
+
lstatSync,
|
|
7
|
+
openSync,
|
|
8
|
+
readSync,
|
|
9
|
+
realpathSync,
|
|
10
|
+
} from "node:fs";
|
|
11
|
+
import { dirname, isAbsolute, join, relative } from "node:path";
|
|
12
|
+
import { Readable } from "node:stream";
|
|
13
|
+
import { createGunzip } from "node:zlib";
|
|
14
|
+
import type { HarneryLogLevel, HarneryRegisteredStorageFamily } from "./contract.ts";
|
|
15
|
+
import type { HarneryLogRecordV1 } from "./jsonl.ts";
|
|
16
|
+
import { parseLogRecord } from "./jsonl.ts";
|
|
17
|
+
import { familyLogDirectory, readSegmentManifest } from "./segments.ts";
|
|
18
|
+
|
|
19
|
+
export interface HarneryLogQuery {
|
|
20
|
+
family_ids?: readonly string[];
|
|
21
|
+
minimum_level?: HarneryLogLevel;
|
|
22
|
+
event?: string;
|
|
23
|
+
since?: string;
|
|
24
|
+
until?: string;
|
|
25
|
+
context?: Readonly<Record<string, string | number | boolean | null>>;
|
|
26
|
+
max_records: number;
|
|
27
|
+
max_bytes: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface HarneryLogQueryResult {
|
|
31
|
+
records: readonly HarneryLogRecordV1[];
|
|
32
|
+
records_examined: number;
|
|
33
|
+
bytes_examined: number;
|
|
34
|
+
truncated: boolean;
|
|
35
|
+
/** Per-family highest sequence intentionally expired by retention. */
|
|
36
|
+
expired_through: Readonly<Record<string, number>>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface HarneryLogFollowCursor {
|
|
40
|
+
family_id: string;
|
|
41
|
+
manifest_sequence: number;
|
|
42
|
+
active_offset: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const LEVELS: readonly HarneryLogLevel[] = ["trace", "debug", "info", "warn", "error", "fatal"];
|
|
46
|
+
const MAX_UNBOUNDED_RECORD_BYTES = 1024 * 1024;
|
|
47
|
+
const STREAM_CHUNK_BYTES = 64 * 1024;
|
|
48
|
+
|
|
49
|
+
export async function queryLogs(
|
|
50
|
+
families: readonly HarneryRegisteredStorageFamily[],
|
|
51
|
+
query: HarneryLogQuery,
|
|
52
|
+
): Promise<HarneryLogQueryResult> {
|
|
53
|
+
if (
|
|
54
|
+
!Number.isSafeInteger(query.max_records) ||
|
|
55
|
+
query.max_records <= 0 ||
|
|
56
|
+
!Number.isSafeInteger(query.max_bytes) ||
|
|
57
|
+
query.max_bytes <= 0
|
|
58
|
+
)
|
|
59
|
+
throw new Error("log query requires positive global budgets");
|
|
60
|
+
const records: HarneryLogRecordV1[] = [];
|
|
61
|
+
let bytes = 0;
|
|
62
|
+
let examined = 0;
|
|
63
|
+
let truncated = false;
|
|
64
|
+
const expiredThrough: Record<string, number> = {};
|
|
65
|
+
for (const family of families) {
|
|
66
|
+
if (query.family_ids && !query.family_ids.includes(family.id)) continue;
|
|
67
|
+
const directory = familyLogDirectory(family);
|
|
68
|
+
const manifest = readSegmentManifest(directory, family);
|
|
69
|
+
expiredThrough[family.id] = manifest.pruned_through_sequence ?? 0;
|
|
70
|
+
const sources = manifestSources(directory, manifest);
|
|
71
|
+
const maximumLineBytes =
|
|
72
|
+
family.policy.records.max_record_bytes.limit ?? MAX_UNBOUNDED_RECORD_BYTES;
|
|
73
|
+
for (const source of sources) {
|
|
74
|
+
for await (const line of linesFrom(source.path, source.gzip, maximumLineBytes)) {
|
|
75
|
+
const lineBytes = Buffer.byteLength(line) + 1;
|
|
76
|
+
if (bytes + lineBytes > query.max_bytes || examined >= query.max_records) {
|
|
77
|
+
truncated = true;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
bytes += lineBytes;
|
|
81
|
+
examined += 1;
|
|
82
|
+
if (!line.trim()) continue;
|
|
83
|
+
const record = parseLogRecord(line);
|
|
84
|
+
if (matches(record, query)) records.push(record);
|
|
85
|
+
}
|
|
86
|
+
if (truncated) break;
|
|
87
|
+
}
|
|
88
|
+
if (truncated) break;
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
records,
|
|
92
|
+
records_examined: examined,
|
|
93
|
+
bytes_examined: bytes,
|
|
94
|
+
truncated,
|
|
95
|
+
expired_through: expiredThrough,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function rotationFollowCursor(
|
|
100
|
+
family: HarneryRegisteredStorageFamily,
|
|
101
|
+
): HarneryLogFollowCursor {
|
|
102
|
+
const directory = familyLogDirectory(family);
|
|
103
|
+
const manifest = readSegmentManifest(directory, family);
|
|
104
|
+
const active = join(directory, "active.jsonl");
|
|
105
|
+
return {
|
|
106
|
+
family_id: family.id,
|
|
107
|
+
manifest_sequence: manifest.next_sequence - 1,
|
|
108
|
+
active_offset: existsSync(active) ? regularFileStat(active).size : 0,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export async function readLogFollow(
|
|
113
|
+
family: HarneryRegisteredStorageFamily,
|
|
114
|
+
cursor: HarneryLogFollowCursor,
|
|
115
|
+
maxBytes: number,
|
|
116
|
+
): Promise<{
|
|
117
|
+
records: readonly HarneryLogRecordV1[];
|
|
118
|
+
cursor: HarneryLogFollowCursor;
|
|
119
|
+
rotated: boolean;
|
|
120
|
+
history_expired: boolean;
|
|
121
|
+
}> {
|
|
122
|
+
if (cursor.family_id !== family.id) throw new Error("follow cursor family mismatch");
|
|
123
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) {
|
|
124
|
+
throw new Error("follow requires a positive byte budget");
|
|
125
|
+
}
|
|
126
|
+
const directory = familyLogDirectory(family);
|
|
127
|
+
const manifest = readSegmentManifest(directory, family);
|
|
128
|
+
const rotated = manifest.next_sequence - 1 > cursor.manifest_sequence;
|
|
129
|
+
const prunedThrough = manifest.pruned_through_sequence ?? 0;
|
|
130
|
+
const historyExpired = prunedThrough > 0 && cursor.manifest_sequence <= prunedThrough;
|
|
131
|
+
const active = join(directory, "active.jsonl");
|
|
132
|
+
if (!existsSync(active)) {
|
|
133
|
+
return {
|
|
134
|
+
records: [],
|
|
135
|
+
cursor: rotationFollowCursor(family),
|
|
136
|
+
rotated,
|
|
137
|
+
history_expired: historyExpired,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const opened = openRegularNoFollow(active);
|
|
141
|
+
const maximumLineBytes =
|
|
142
|
+
family.policy.records.max_record_bytes.limit ?? MAX_UNBOUNDED_RECORD_BYTES;
|
|
143
|
+
const records: HarneryLogRecordV1[] = [];
|
|
144
|
+
let offset: number;
|
|
145
|
+
let consumed = 0;
|
|
146
|
+
try {
|
|
147
|
+
const size = fstatSync(opened.fd).size;
|
|
148
|
+
offset = rotated || cursor.active_offset > size ? 0 : cursor.active_offset;
|
|
149
|
+
let position = offset;
|
|
150
|
+
let remainingBudget = Math.min(maxBytes, size - offset);
|
|
151
|
+
let pending: Buffer[] = [];
|
|
152
|
+
let pendingBytes = 0;
|
|
153
|
+
while (remainingBudget > 0) {
|
|
154
|
+
const chunk = Buffer.allocUnsafe(Math.min(STREAM_CHUNK_BYTES, remainingBudget));
|
|
155
|
+
const bytesRead = readSync(opened.fd, chunk, 0, chunk.byteLength, position);
|
|
156
|
+
if (bytesRead === 0) break;
|
|
157
|
+
const view = chunk.subarray(0, bytesRead);
|
|
158
|
+
let start = 0;
|
|
159
|
+
for (let index = 0; index < view.byteLength; index += 1) {
|
|
160
|
+
if (view[index] !== 10) continue;
|
|
161
|
+
const part = view.subarray(start, index);
|
|
162
|
+
assertLineBound(active, pendingBytes + part.byteLength + 1, maximumLineBytes);
|
|
163
|
+
if (part.byteLength > 0) pending.push(part);
|
|
164
|
+
const line = Buffer.concat(pending, pendingBytes + part.byteLength).toString("utf8");
|
|
165
|
+
if (line) records.push(parseLogRecord(line));
|
|
166
|
+
consumed = position + index + 1 - offset;
|
|
167
|
+
pending = [];
|
|
168
|
+
pendingBytes = 0;
|
|
169
|
+
start = index + 1;
|
|
170
|
+
}
|
|
171
|
+
const tail = view.subarray(start);
|
|
172
|
+
assertLineBound(active, pendingBytes + tail.byteLength, maximumLineBytes);
|
|
173
|
+
if (tail.byteLength > 0) {
|
|
174
|
+
pending.push(tail);
|
|
175
|
+
pendingBytes += tail.byteLength;
|
|
176
|
+
}
|
|
177
|
+
position += bytesRead;
|
|
178
|
+
remainingBudget -= bytesRead;
|
|
179
|
+
}
|
|
180
|
+
assertOpenFileIdentity(active, opened.fd, opened.parent);
|
|
181
|
+
} finally {
|
|
182
|
+
closeSync(opened.fd);
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
records,
|
|
186
|
+
cursor: {
|
|
187
|
+
family_id: family.id,
|
|
188
|
+
manifest_sequence: manifest.next_sequence - 1,
|
|
189
|
+
active_offset: offset + consumed,
|
|
190
|
+
},
|
|
191
|
+
rotated,
|
|
192
|
+
history_expired: historyExpired,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function manifestSources(
|
|
197
|
+
directory: string,
|
|
198
|
+
manifest: ReturnType<typeof readSegmentManifest>,
|
|
199
|
+
): Array<{ path: string; gzip: boolean }> {
|
|
200
|
+
const sealed = manifest.segments.map((segment) => ({
|
|
201
|
+
path: join(directory, segment.file),
|
|
202
|
+
gzip: true,
|
|
203
|
+
}));
|
|
204
|
+
const active = join(directory, "active.jsonl");
|
|
205
|
+
return existsSync(active) ? [...sealed, { path: active, gzip: false }] : sealed;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function* linesFrom(
|
|
209
|
+
path: string,
|
|
210
|
+
gzip: boolean,
|
|
211
|
+
maximumLineBytes: number,
|
|
212
|
+
): AsyncGenerator<string> {
|
|
213
|
+
const opened = openRegularNoFollow(path);
|
|
214
|
+
const input = Readable.from(descriptorChunks(opened.fd));
|
|
215
|
+
const stream = gzip
|
|
216
|
+
? input.pipe(
|
|
217
|
+
createGunzip({
|
|
218
|
+
chunkSize: Math.max(64, Math.min(STREAM_CHUNK_BYTES, maximumLineBytes + 1)),
|
|
219
|
+
}),
|
|
220
|
+
)
|
|
221
|
+
: input;
|
|
222
|
+
let pending: Buffer[] = [];
|
|
223
|
+
let pendingBytes = 0;
|
|
224
|
+
try {
|
|
225
|
+
for await (const value of stream) {
|
|
226
|
+
const chunk = Buffer.isBuffer(value) ? value : Buffer.from(value as Uint8Array);
|
|
227
|
+
let start = 0;
|
|
228
|
+
for (let index = 0; index < chunk.byteLength; index += 1) {
|
|
229
|
+
if (chunk[index] !== 10) continue;
|
|
230
|
+
const part = chunk.subarray(start, index);
|
|
231
|
+
assertLineBound(path, pendingBytes + part.byteLength + 1, maximumLineBytes);
|
|
232
|
+
if (part.byteLength > 0) pending.push(part);
|
|
233
|
+
yield Buffer.concat(pending, pendingBytes + part.byteLength).toString("utf8");
|
|
234
|
+
pending = [];
|
|
235
|
+
pendingBytes = 0;
|
|
236
|
+
start = index + 1;
|
|
237
|
+
}
|
|
238
|
+
const tail = chunk.subarray(start);
|
|
239
|
+
assertLineBound(path, pendingBytes + tail.byteLength, maximumLineBytes);
|
|
240
|
+
if (tail.byteLength > 0) {
|
|
241
|
+
pending.push(tail);
|
|
242
|
+
pendingBytes += tail.byteLength;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (pendingBytes > 0) throw new Error(`log query has a partial JSONL record: ${path}`);
|
|
246
|
+
} finally {
|
|
247
|
+
assertOpenFileIdentity(path, opened.fd, opened.parent);
|
|
248
|
+
stream.destroy();
|
|
249
|
+
input.destroy();
|
|
250
|
+
closeOwnedDescriptor(opened.fd);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function matches(record: HarneryLogRecordV1, query: HarneryLogQuery): boolean {
|
|
255
|
+
if (query.minimum_level && LEVELS.indexOf(record.level) < LEVELS.indexOf(query.minimum_level))
|
|
256
|
+
return false;
|
|
257
|
+
if (query.event && record.event !== query.event) return false;
|
|
258
|
+
if (query.since && record.emitted_at < query.since) return false;
|
|
259
|
+
if (query.until && record.emitted_at > query.until) return false;
|
|
260
|
+
return Object.entries(query.context ?? {}).every(([key, value]) => record.context[key] === value);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
interface DirectoryIdentity {
|
|
264
|
+
path: string;
|
|
265
|
+
real_path: string;
|
|
266
|
+
dev: number;
|
|
267
|
+
ino: number;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function captureDirectoryIdentity(path: string): DirectoryIdentity {
|
|
271
|
+
const stat = lstatSync(path);
|
|
272
|
+
if (stat.isSymbolicLink()) throw new Error(`log query rejects symlink: ${path}`);
|
|
273
|
+
if (!stat.isDirectory()) throw new Error(`log query path is not a directory: ${path}`);
|
|
274
|
+
return { path, real_path: realpathSync(path), dev: stat.dev, ino: stat.ino };
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function assertDirectoryIdentity(identity: DirectoryIdentity): void {
|
|
278
|
+
const current = lstatSync(identity.path);
|
|
279
|
+
if (
|
|
280
|
+
current.isSymbolicLink() ||
|
|
281
|
+
!current.isDirectory() ||
|
|
282
|
+
current.dev !== identity.dev ||
|
|
283
|
+
current.ino !== identity.ino ||
|
|
284
|
+
realpathSync(identity.path) !== identity.real_path
|
|
285
|
+
) {
|
|
286
|
+
throw new Error(`log query directory identity changed: ${identity.path}`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function openRegularNoFollow(path: string): { fd: number; parent: DirectoryIdentity } {
|
|
291
|
+
const parent = captureDirectoryIdentity(dirname(path));
|
|
292
|
+
rejectSymlink(path);
|
|
293
|
+
const fd = openSync(path, fsConstants.O_RDONLY | noFollowFlag());
|
|
294
|
+
try {
|
|
295
|
+
assertOpenFileIdentity(path, fd, parent);
|
|
296
|
+
return { fd, parent };
|
|
297
|
+
} catch (error) {
|
|
298
|
+
closeSync(fd);
|
|
299
|
+
throw error;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function assertOpenFileIdentity(path: string, fd: number, parent: DirectoryIdentity): void {
|
|
304
|
+
assertDirectoryIdentity(parent);
|
|
305
|
+
const opened = fstatSync(fd);
|
|
306
|
+
const current = lstatSync(path);
|
|
307
|
+
if (
|
|
308
|
+
!opened.isFile() ||
|
|
309
|
+
current.isSymbolicLink() ||
|
|
310
|
+
!current.isFile() ||
|
|
311
|
+
opened.dev !== current.dev ||
|
|
312
|
+
opened.ino !== current.ino
|
|
313
|
+
) {
|
|
314
|
+
throw new Error(`log query path identity changed: ${path}`);
|
|
315
|
+
}
|
|
316
|
+
const fromParent = relative(parent.real_path, realpathSync(path));
|
|
317
|
+
if (fromParent.startsWith("..") || isAbsolute(fromParent)) {
|
|
318
|
+
throw new Error(`log query path escapes parent boundary: ${path}`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function regularFileStat(path: string) {
|
|
323
|
+
const opened = openRegularNoFollow(path);
|
|
324
|
+
try {
|
|
325
|
+
return fstatSync(opened.fd);
|
|
326
|
+
} finally {
|
|
327
|
+
closeSync(opened.fd);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function rejectSymlink(path: string): void {
|
|
332
|
+
if (lstatSync(path).isSymbolicLink()) throw new Error(`log query rejects symlink: ${path}`);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function assertLineBound(path: string, bytes: number, maximum: number): void {
|
|
336
|
+
if (bytes > maximum) throw new Error(`log query record exceeds ${maximum} bytes: ${path}`);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function noFollowFlag(): number {
|
|
340
|
+
return fsConstants.O_NOFOLLOW ?? 0;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function closeOwnedDescriptor(fd: number): void {
|
|
344
|
+
try {
|
|
345
|
+
closeSync(fd);
|
|
346
|
+
} catch (error) {
|
|
347
|
+
if ((error as NodeJS.ErrnoException).code !== "EBADF") throw error;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
async function* descriptorChunks(fd: number): AsyncGenerator<Buffer> {
|
|
352
|
+
let position = 0;
|
|
353
|
+
while (true) {
|
|
354
|
+
const chunk = Buffer.allocUnsafe(STREAM_CHUNK_BYTES);
|
|
355
|
+
const bytesRead = readSync(fd, chunk, 0, chunk.byteLength, position);
|
|
356
|
+
if (bytesRead === 0) return;
|
|
357
|
+
position += bytesRead;
|
|
358
|
+
yield chunk.subarray(0, bytesRead);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import {
|
|
3
|
+
closeSync,
|
|
4
|
+
existsSync,
|
|
5
|
+
fsyncSync,
|
|
6
|
+
lstatSync,
|
|
7
|
+
mkdirSync,
|
|
8
|
+
openSync,
|
|
9
|
+
readdirSync,
|
|
10
|
+
readFileSync,
|
|
11
|
+
renameSync,
|
|
12
|
+
unlinkSync,
|
|
13
|
+
writeFileSync,
|
|
14
|
+
} from "node:fs";
|
|
15
|
+
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
16
|
+
import {
|
|
17
|
+
HARNERY_MAINTENANCE_RECEIPT_SCHEMA,
|
|
18
|
+
HarneryMaintenanceError,
|
|
19
|
+
type HarneryMaintenanceReceipt,
|
|
20
|
+
} from "./maintenance.ts";
|
|
21
|
+
|
|
22
|
+
export const HARNERY_RECEIPT_SEGMENT_MANIFEST_SCHEMA =
|
|
23
|
+
"harnery.storage-maintenance-receipt-segment/v1" as const;
|
|
24
|
+
|
|
25
|
+
export interface HarneryReceiptConsolidationPlan {
|
|
26
|
+
schema: typeof HARNERY_RECEIPT_SEGMENT_MANIFEST_SCHEMA;
|
|
27
|
+
segment_id: string;
|
|
28
|
+
created_at: string;
|
|
29
|
+
source_count: number;
|
|
30
|
+
source_bytes: number;
|
|
31
|
+
source_paths_sha256: string;
|
|
32
|
+
payload_sha256: string;
|
|
33
|
+
payload_bytes: number;
|
|
34
|
+
applied: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Losslessly packs immutable maintenance receipts. The default is a pure plan;
|
|
39
|
+
* source replacement requires both an exact consolidation id and `yes`.
|
|
40
|
+
*/
|
|
41
|
+
export function consolidateMutationReceipts(
|
|
42
|
+
coordRoot: string,
|
|
43
|
+
options: {
|
|
44
|
+
now?: Date;
|
|
45
|
+
threshold?: number;
|
|
46
|
+
yes?: boolean;
|
|
47
|
+
consolidation_id?: string;
|
|
48
|
+
} = {},
|
|
49
|
+
): HarneryReceiptConsolidationPlan | undefined {
|
|
50
|
+
const now = options.now ?? new Date();
|
|
51
|
+
if (!Number.isFinite(now.getTime()))
|
|
52
|
+
throw new HarneryMaintenanceError("invalid_time", "receipt consolidation");
|
|
53
|
+
const threshold = options.threshold ?? 1_000;
|
|
54
|
+
if (!Number.isSafeInteger(threshold) || threshold <= 1) {
|
|
55
|
+
throw new HarneryMaintenanceError("invalid_threshold", "receipt consolidation threshold");
|
|
56
|
+
}
|
|
57
|
+
const root = join(resolve(coordRoot), ".harnery", "maintenance", "receipts");
|
|
58
|
+
if (!existsSync(root)) return undefined;
|
|
59
|
+
const files = receiptFiles(root);
|
|
60
|
+
if (files.length < threshold) return undefined;
|
|
61
|
+
const rows = files.map((path) => readReceipt(path));
|
|
62
|
+
const payload = `${rows.map(({ receipt }) => JSON.stringify(receipt)).join("\n")}\n`;
|
|
63
|
+
const relativePaths = rows.map(({ path }) => relative(root, path).split(sep).join("/")).sort();
|
|
64
|
+
const segmentId =
|
|
65
|
+
options.consolidation_id ?? `receipts-${now.toISOString().slice(0, 10)}-${randomUUID()}`;
|
|
66
|
+
if (!/^[a-z0-9][a-z0-9._-]{0,127}$/.test(segmentId)) {
|
|
67
|
+
throw new HarneryMaintenanceError("invalid_id", "receipt consolidation id");
|
|
68
|
+
}
|
|
69
|
+
const plan: HarneryReceiptConsolidationPlan = {
|
|
70
|
+
schema: HARNERY_RECEIPT_SEGMENT_MANIFEST_SCHEMA,
|
|
71
|
+
segment_id: segmentId,
|
|
72
|
+
created_at: now.toISOString(),
|
|
73
|
+
source_count: rows.length,
|
|
74
|
+
source_bytes: rows.reduce((sum, row) => sum + row.bytes, 0),
|
|
75
|
+
source_paths_sha256: sha256(`${relativePaths.join("\n")}\n`),
|
|
76
|
+
payload_sha256: sha256(payload),
|
|
77
|
+
payload_bytes: Buffer.byteLength(payload),
|
|
78
|
+
applied: false,
|
|
79
|
+
};
|
|
80
|
+
if (!options.yes) return plan;
|
|
81
|
+
if (options.consolidation_id !== segmentId) {
|
|
82
|
+
throw new HarneryMaintenanceError(
|
|
83
|
+
"confirmation_required",
|
|
84
|
+
"receipt replacement requires an exact consolidation id and --yes",
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
const segments = join(root, "segments");
|
|
88
|
+
mkdirSync(segments, { recursive: true, mode: 0o700 });
|
|
89
|
+
const payloadPath = join(segments, `${segmentId}.jsonl`);
|
|
90
|
+
const manifestPath = join(segments, `${segmentId}.manifest.json`);
|
|
91
|
+
writeExclusiveDurable(payloadPath, payload);
|
|
92
|
+
const observed = readFileSync(payloadPath);
|
|
93
|
+
if (observed.byteLength !== plan.payload_bytes || sha256(observed) !== plan.payload_sha256) {
|
|
94
|
+
throw new HarneryMaintenanceError("receipt_segment_mismatch", segmentId);
|
|
95
|
+
}
|
|
96
|
+
const committed = { ...plan, applied: true };
|
|
97
|
+
writeExclusiveDurable(manifestPath, `${JSON.stringify(committed, null, 2)}\n`);
|
|
98
|
+
for (const row of rows) {
|
|
99
|
+
const current = readReceipt(row.path);
|
|
100
|
+
if (current.digest !== row.digest) {
|
|
101
|
+
throw new HarneryMaintenanceError("receipt_changed", relative(root, row.path));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
for (const row of rows) unlinkSync(row.path);
|
|
105
|
+
return committed;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function receiptFiles(root: string): string[] {
|
|
109
|
+
const result: string[] = [];
|
|
110
|
+
for (const transaction of readdirSync(root, { withFileTypes: true })) {
|
|
111
|
+
if (transaction.name === "segments") continue;
|
|
112
|
+
const transactionPath = join(root, transaction.name);
|
|
113
|
+
const transactionStat = lstatSync(transactionPath);
|
|
114
|
+
if (!transaction.isDirectory() || transactionStat.isSymbolicLink()) continue;
|
|
115
|
+
for (const file of readdirSync(transactionPath, { withFileTypes: true })) {
|
|
116
|
+
if (!file.name.endsWith(".json")) continue;
|
|
117
|
+
result.push(join(transactionPath, file.name));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return result.sort();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function readReceipt(path: string): {
|
|
124
|
+
path: string;
|
|
125
|
+
bytes: number;
|
|
126
|
+
digest: string;
|
|
127
|
+
receipt: HarneryMaintenanceReceipt;
|
|
128
|
+
} {
|
|
129
|
+
const stat = lstatSync(path);
|
|
130
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.size <= 0 || stat.size > 256 * 1_024) {
|
|
131
|
+
throw new HarneryMaintenanceError("unsafe_receipt", path);
|
|
132
|
+
}
|
|
133
|
+
const bytes = readFileSync(path);
|
|
134
|
+
const receipt = JSON.parse(bytes.toString("utf8")) as HarneryMaintenanceReceipt;
|
|
135
|
+
if (
|
|
136
|
+
receipt.schema !== HARNERY_MAINTENANCE_RECEIPT_SCHEMA ||
|
|
137
|
+
typeof receipt.transaction_id !== "string" ||
|
|
138
|
+
typeof receipt.action_id !== "string" ||
|
|
139
|
+
!/^[a-f0-9]{64}$/.test(receipt.action_sha256)
|
|
140
|
+
) {
|
|
141
|
+
throw new HarneryMaintenanceError("invalid_receipt", path);
|
|
142
|
+
}
|
|
143
|
+
return { path, bytes: bytes.byteLength, digest: sha256(bytes), receipt };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function writeExclusiveDurable(path: string, bytes: string): void {
|
|
147
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
148
|
+
const temporary = `${path}.tmp-${process.pid}-${randomUUID()}`;
|
|
149
|
+
const fd = openSync(temporary, "wx", 0o600);
|
|
150
|
+
try {
|
|
151
|
+
writeFileSync(fd, bytes, "utf8");
|
|
152
|
+
fsyncSync(fd);
|
|
153
|
+
} finally {
|
|
154
|
+
closeSync(fd);
|
|
155
|
+
}
|
|
156
|
+
if (existsSync(path)) throw new HarneryMaintenanceError("segment_exists", path);
|
|
157
|
+
renameSync(temporary, path);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function sha256(value: string | Uint8Array): string {
|
|
161
|
+
return createHash("sha256").update(value).digest("hex");
|
|
162
|
+
}
|