harnery 0.36.0 → 0.38.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 +9 -0
- package/dist/commander.d.ts.map +1 -1
- package/dist/commander.js +10 -1
- package/dist/commands/admission.d.ts +21 -0
- package/dist/commands/admission.d.ts.map +1 -0
- package/dist/commands/admission.js +565 -0
- package/dist/commands/agents.d.ts +7 -0
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +148 -47
- package/dist/commands/artifacts.d.ts.map +1 -1
- package/dist/commands/artifacts.js +73 -2
- package/dist/commands/browse-ai.d.ts +2 -2
- package/dist/commands/browse-ai.d.ts.map +1 -1
- package/dist/commands/browse-ai.js +6 -4
- package/dist/commands/browse.d.ts.map +1 -1
- package/dist/commands/browse.js +360 -21
- package/dist/commands/diagnostics.d.ts +4 -0
- package/dist/commands/diagnostics.d.ts.map +1 -0
- package/dist/commands/diagnostics.js +229 -0
- package/dist/commands/fetch.js +1 -0
- package/dist/commands/files.d.ts +12 -0
- package/dist/commands/files.d.ts.map +1 -1
- package/dist/commands/files.js +54 -1
- package/dist/commands/governor.d.ts.map +1 -1
- package/dist/commands/governor.js +4 -0
- package/dist/commands/ledger-v3.d.ts.map +1 -1
- package/dist/commands/ledger-v3.js +71 -2
- package/dist/commands/qa-record.d.ts +144 -0
- package/dist/commands/qa-record.d.ts.map +1 -0
- package/dist/commands/qa-record.js +0 -0
- package/dist/commands/qa-run.d.ts +8 -0
- package/dist/commands/qa-run.d.ts.map +1 -0
- package/dist/commands/qa-run.js +396 -0
- package/dist/commands/qa-status.d.ts +71 -0
- package/dist/commands/qa-status.d.ts.map +1 -0
- package/dist/commands/qa-status.js +490 -0
- package/dist/commands/qa-verify.d.ts +40 -0
- package/dist/commands/qa-verify.d.ts.map +1 -0
- package/dist/commands/qa-verify.js +180 -0
- package/dist/commands/resources.d.ts +4 -0
- package/dist/commands/resources.d.ts.map +1 -0
- package/dist/commands/resources.js +29 -0
- package/dist/commands/review-pack.d.ts +4 -0
- package/dist/commands/review-pack.d.ts.map +1 -0
- package/dist/commands/review-pack.js +1001 -0
- package/dist/commands/supervisor.d.ts +4 -0
- package/dist/commands/supervisor.d.ts.map +1 -0
- package/dist/commands/supervisor.js +101 -0
- package/dist/commands/web.d.ts.map +1 -1
- package/dist/commands/web.js +17 -0
- package/dist/commands/workflow.d.ts.map +1 -1
- package/dist/commands/workflow.js +4 -0
- package/dist/core/agents/cli.js +7 -3
- package/dist/core/agents/health.d.ts +17 -0
- package/dist/core/agents/health.d.ts.map +1 -0
- package/dist/core/agents/health.js +109 -0
- package/dist/core/agents/mailbox.d.ts +92 -0
- package/dist/core/agents/mailbox.d.ts.map +1 -0
- package/dist/core/agents/mailbox.js +325 -0
- package/dist/core/agents/qa-signal.d.ts +111 -0
- package/dist/core/agents/qa-signal.d.ts.map +1 -0
- package/dist/core/agents/qa-signal.js +231 -0
- package/dist/core/agents/reconcile-coordination-v3.d.ts +44 -0
- package/dist/core/agents/reconcile-coordination-v3.d.ts.map +1 -0
- package/dist/core/agents/reconcile-coordination-v3.js +58 -0
- package/dist/core/agents/render/prompt-context.d.ts +5 -0
- package/dist/core/agents/render/prompt-context.d.ts.map +1 -1
- package/dist/core/agents/render/prompt-context.js +34 -13
- package/dist/core/agents/render/session-context.d.ts +8 -0
- package/dist/core/agents/render/session-context.d.ts.map +1 -1
- package/dist/core/agents/render/session-context.js +34 -3
- package/dist/core/agents/rules/commit-conflict.d.ts.map +1 -1
- package/dist/core/agents/rules/commit-conflict.js +50 -1
- package/dist/core/agents/rules/stop-hook.d.ts.map +1 -1
- package/dist/core/agents/rules/stop-hook.js +6 -10
- package/dist/core/agents/session-finalizer-v3.js +4 -1
- package/dist/core/agents/session-name-display.d.ts +20 -5
- package/dist/core/agents/session-name-display.d.ts.map +1 -1
- package/dist/core/agents/session-name-display.js +67 -7
- package/dist/core/agents/state/heartbeat-reader.d.ts +7 -0
- package/dist/core/agents/state/heartbeat-reader.d.ts.map +1 -1
- package/dist/core/agents/state/heartbeat-writer.d.ts +11 -0
- package/dist/core/agents/state/heartbeat-writer.d.ts.map +1 -1
- package/dist/core/agents/state/heartbeat-writer.js +17 -0
- package/dist/core/agents/state/live-coordination-view.d.ts.map +1 -1
- package/dist/core/agents/state/live-coordination-view.js +1 -0
- package/dist/core/agents/state/live-coordination-writer.js +5 -0
- package/dist/core/artifacts/constants.d.ts +1 -1
- package/dist/core/artifacts/constants.js +1 -1
- package/dist/core/artifacts/index.d.ts +82 -6
- package/dist/core/artifacts/index.d.ts.map +1 -1
- package/dist/core/artifacts/index.js +410 -15
- package/dist/core/config.d.ts +20 -0
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +59 -0
- package/dist/core/diagnostics/advice.d.ts +9 -0
- package/dist/core/diagnostics/advice.d.ts.map +1 -0
- package/dist/core/diagnostics/advice.js +112 -0
- package/dist/core/diagnostics/bundle.d.ts +51 -0
- package/dist/core/diagnostics/bundle.d.ts.map +1 -0
- package/dist/core/diagnostics/bundle.js +968 -0
- package/dist/core/diagnostics/comparison.d.ts +5 -0
- package/dist/core/diagnostics/comparison.d.ts.map +1 -0
- package/dist/core/diagnostics/comparison.js +444 -0
- package/dist/core/diagnostics/contract.d.ts +245 -0
- package/dist/core/diagnostics/contract.d.ts.map +1 -0
- package/dist/core/diagnostics/contract.js +18 -0
- package/dist/core/diagnostics/identity.d.ts +3 -0
- package/dist/core/diagnostics/identity.d.ts.map +1 -0
- package/dist/core/diagnostics/identity.js +10 -0
- package/dist/core/diagnostics/index.d.ts +8 -0
- package/dist/core/diagnostics/index.d.ts.map +1 -0
- package/dist/core/diagnostics/index.js +7 -0
- package/dist/core/diagnostics/replay.d.ts +8 -0
- package/dist/core/diagnostics/replay.d.ts.map +1 -0
- package/dist/core/diagnostics/replay.js +213 -0
- package/dist/core/diagnostics/sanitize.d.ts +9 -0
- package/dist/core/diagnostics/sanitize.d.ts.map +1 -0
- package/dist/core/diagnostics/sanitize.js +84 -0
- package/dist/core/events/legacy-storage/compression.d.ts +13 -0
- package/dist/core/events/legacy-storage/compression.d.ts.map +1 -0
- package/dist/core/events/legacy-storage/compression.js +107 -0
- package/dist/core/events/legacy-storage/index.d.ts +1 -0
- package/dist/core/events/legacy-storage/index.d.ts.map +1 -1
- package/dist/core/events/legacy-storage/index.js +1 -0
- package/dist/core/events/v3/archive-retention.d.ts +33 -0
- package/dist/core/events/v3/archive-retention.d.ts.map +1 -0
- package/dist/core/events/v3/archive-retention.js +195 -0
- package/dist/core/events/v3/bootstrap.d.ts.map +1 -1
- package/dist/core/events/v3/bootstrap.js +10 -0
- package/dist/core/events/v3/capabilities.d.ts +1 -1
- package/dist/core/events/v3/capabilities.d.ts.map +1 -1
- package/dist/core/events/v3/capabilities.js +1 -0
- package/dist/core/events/v3/coordination-view.d.ts +3 -0
- package/dist/core/events/v3/coordination-view.d.ts.map +1 -1
- package/dist/core/events/v3/coordination-view.js +69 -8
- package/dist/core/events/v3/index.d.ts +1 -0
- package/dist/core/events/v3/index.d.ts.map +1 -1
- package/dist/core/events/v3/index.js +1 -0
- package/dist/core/events/v3/live-routing.d.ts.map +1 -1
- package/dist/core/events/v3/live-routing.js +1 -0
- package/dist/core/events/v3/producers/hook-base.d.ts +1 -1
- package/dist/core/events/v3/producers/hook-base.d.ts.map +1 -1
- package/dist/core/events/v3/producers/hook-base.js +13 -2
- package/dist/core/events/v3/producers/intake.d.ts.map +1 -1
- package/dist/core/events/v3/producers/intake.js +10 -2
- package/dist/core/events/v3/producers/recorder.d.ts +39 -0
- package/dist/core/events/v3/producers/recorder.d.ts.map +1 -1
- package/dist/core/events/v3/producers/recorder.js +350 -17
- package/dist/core/hooks/adapter/output.d.ts +8 -0
- package/dist/core/hooks/adapter/output.d.ts.map +1 -1
- package/dist/core/hooks/adapter/output.js +11 -1
- package/dist/core/hooks/cli.js +303 -219
- package/dist/core/hooks/health.d.ts +59 -0
- package/dist/core/hooks/health.d.ts.map +1 -0
- package/dist/core/hooks/health.js +84 -0
- package/dist/core/hooks/resolve/transcript.d.ts.map +1 -1
- package/dist/core/hooks/resolve/transcript.js +10 -3
- package/dist/core/hooks/session-name-presence.d.ts.map +1 -1
- package/dist/core/hooks/session-name-presence.js +4 -1
- package/dist/core/qa-artifacts.d.ts +20 -0
- package/dist/core/qa-artifacts.d.ts.map +1 -0
- package/dist/core/qa-artifacts.js +110 -0
- package/dist/core/resources/contract.d.ts +96 -0
- package/dist/core/resources/contract.d.ts.map +1 -0
- package/dist/core/resources/contract.js +2 -0
- package/dist/core/resources/index.d.ts +6 -0
- package/dist/core/resources/index.d.ts.map +1 -0
- package/dist/core/resources/index.js +5 -0
- package/dist/core/resources/sampler.d.ts +34 -0
- package/dist/core/resources/sampler.d.ts.map +1 -0
- package/dist/core/resources/sampler.js +458 -0
- package/dist/core/resources/service-status.d.ts +3 -0
- package/dist/core/resources/service-status.d.ts.map +1 -0
- package/dist/core/resources/service-status.js +48 -0
- package/dist/core/resources/service.d.ts +26 -0
- package/dist/core/resources/service.d.ts.map +1 -0
- package/dist/core/resources/service.js +292 -0
- package/dist/core/resources/storage.d.ts +13 -0
- package/dist/core/resources/storage.d.ts.map +1 -0
- package/dist/core/resources/storage.js +30 -0
- package/dist/core/storage/atomic-json.d.ts +3 -0
- package/dist/core/storage/atomic-json.d.ts.map +1 -0
- package/dist/core/storage/atomic-json.js +15 -0
- package/dist/core/storage/builtins.d.ts.map +1 -1
- package/dist/core/storage/builtins.js +45 -6
- package/dist/core/storage/logger.d.ts +2 -0
- package/dist/core/storage/logger.d.ts.map +1 -1
- package/dist/core/storage/logger.js +2 -0
- package/dist/core/storage/query.d.ts +14 -0
- package/dist/core/storage/query.d.ts.map +1 -1
- package/dist/core/storage/query.js +51 -0
- package/dist/core/supervisor/activity.d.ts +4 -0
- package/dist/core/supervisor/activity.d.ts.map +1 -0
- package/dist/core/supervisor/activity.js +141 -0
- package/dist/core/supervisor/contract.d.ts +268 -0
- package/dist/core/supervisor/contract.d.ts.map +1 -0
- package/dist/core/supervisor/contract.js +35 -0
- package/dist/core/supervisor/explanations.d.ts +4 -0
- package/dist/core/supervisor/explanations.d.ts.map +1 -0
- package/dist/core/supervisor/explanations.js +71 -0
- package/dist/core/supervisor/findings.d.ts +20 -0
- package/dist/core/supervisor/findings.d.ts.map +1 -0
- package/dist/core/supervisor/findings.js +399 -0
- package/dist/core/supervisor/history.d.ts +9 -0
- package/dist/core/supervisor/history.d.ts.map +1 -0
- package/dist/core/supervisor/history.js +46 -0
- package/dist/core/supervisor/hook-health-alerts.d.ts +14 -0
- package/dist/core/supervisor/hook-health-alerts.d.ts.map +1 -0
- package/dist/core/supervisor/hook-health-alerts.js +70 -0
- package/dist/core/supervisor/hook-health-storage.d.ts +5 -0
- package/dist/core/supervisor/hook-health-storage.d.ts.map +1 -0
- package/dist/core/supervisor/hook-health-storage.js +24 -0
- package/dist/core/supervisor/hook-health.d.ts +72 -0
- package/dist/core/supervisor/hook-health.d.ts.map +1 -0
- package/dist/core/supervisor/hook-health.js +203 -0
- package/dist/core/supervisor/hooks.d.ts +10 -0
- package/dist/core/supervisor/hooks.d.ts.map +1 -0
- package/dist/core/supervisor/hooks.js +28 -0
- package/dist/core/supervisor/index.d.ts +15 -0
- package/dist/core/supervisor/index.d.ts.map +1 -0
- package/dist/core/supervisor/index.js +14 -0
- package/dist/core/supervisor/log-feed.d.ts +9 -0
- package/dist/core/supervisor/log-feed.d.ts.map +1 -0
- package/dist/core/supervisor/log-feed.js +103 -0
- package/dist/core/supervisor/service.d.ts +29 -0
- package/dist/core/supervisor/service.d.ts.map +1 -0
- package/dist/core/supervisor/service.js +450 -0
- package/dist/core/supervisor/services.d.ts +11 -0
- package/dist/core/supervisor/services.d.ts.map +1 -0
- package/dist/core/supervisor/services.js +155 -0
- package/dist/core/supervisor/status.d.ts +3 -0
- package/dist/core/supervisor/status.d.ts.map +1 -0
- package/dist/core/supervisor/status.js +48 -0
- package/dist/core/supervisor/storage.d.ts +30 -0
- package/dist/core/supervisor/storage.d.ts.map +1 -0
- package/dist/core/supervisor/storage.js +73 -0
- package/dist/core/supervisor/timeline.d.ts +3 -0
- package/dist/core/supervisor/timeline.d.ts.map +1 -0
- package/dist/core/supervisor/timeline.js +87 -0
- package/dist/core/workflow/admission.d.ts +23 -0
- package/dist/core/workflow/admission.d.ts.map +1 -0
- package/dist/core/workflow/admission.js +136 -0
- package/dist/core/workflow/engine.d.ts.map +1 -1
- package/dist/core/workflow/engine.js +77 -2
- package/dist/core/workflow/index.d.ts +3 -2
- package/dist/core/workflow/index.d.ts.map +1 -1
- package/dist/core/workflow/index.js +2 -1
- package/dist/core/workflow/proof.d.ts +2 -1
- package/dist/core/workflow/proof.d.ts.map +1 -1
- package/dist/core/workflow/proof.js +39 -1
- package/dist/core/workflow/run-state.d.ts +3 -2
- package/dist/core/workflow/run-state.d.ts.map +1 -1
- package/dist/core/workflow/run-state.js +8 -1
- package/dist/core/workflow/types.d.ts +33 -1
- package/dist/core/workflow/types.d.ts.map +1 -1
- package/dist/core/workflow/types.js +2 -1
- package/dist/lib/admission.d.ts +71 -0
- package/dist/lib/admission.d.ts.map +1 -0
- package/dist/lib/admission.js +264 -0
- package/dist/lib/agent-browser/client.d.ts +1 -1
- package/dist/lib/agent-browser/client.d.ts.map +1 -1
- package/dist/lib/agent-browser/client.js +1 -5
- package/dist/lib/browser/capture-fidelity.d.ts +39 -0
- package/dist/lib/browser/capture-fidelity.d.ts.map +1 -0
- package/dist/lib/browser/capture-fidelity.js +84 -0
- package/dist/lib/browser/client.d.ts +46 -1
- package/dist/lib/browser/client.d.ts.map +1 -1
- package/dist/lib/browser/client.js +168 -9
- package/dist/lib/browser/critique.d.ts +38 -1
- package/dist/lib/browser/critique.d.ts.map +1 -1
- package/dist/lib/browser/critique.js +34 -6
- package/dist/lib/browser/index.d.ts +5 -1
- package/dist/lib/browser/index.d.ts.map +1 -1
- package/dist/lib/browser/index.js +4 -0
- package/dist/lib/browser/page-review-judge.d.ts +64 -0
- package/dist/lib/browser/page-review-judge.d.ts.map +1 -0
- package/dist/lib/browser/page-review-judge.js +270 -0
- package/dist/lib/browser/page-review-pack.d.ts +613 -0
- package/dist/lib/browser/page-review-pack.d.ts.map +1 -0
- package/dist/lib/browser/page-review-pack.js +1751 -0
- package/dist/lib/browser/qa-run-contracts.d.ts +377 -0
- package/dist/lib/browser/qa-run-contracts.d.ts.map +1 -0
- package/dist/lib/browser/qa-run-contracts.js +361 -0
- package/dist/lib/browser/qa-run.d.ts +141 -0
- package/dist/lib/browser/qa-run.d.ts.map +1 -0
- package/dist/lib/browser/qa-run.js +1283 -0
- package/dist/lib/browser/request-diagnostics.d.ts +13 -0
- package/dist/lib/browser/request-diagnostics.d.ts.map +1 -0
- package/dist/lib/browser/request-diagnostics.js +18 -0
- package/dist/lib/browser/tiling.d.ts +19 -0
- package/dist/lib/browser/tiling.d.ts.map +1 -1
- package/dist/lib/browser/tiling.js +28 -0
- package/dist/lib/cookies/client.d.ts +9 -0
- package/dist/lib/cookies/client.d.ts.map +1 -1
- package/dist/lib/cookies/client.js +197 -44
- package/dist/lib/cookies/extra.d.ts +18 -0
- package/dist/lib/cookies/extra.d.ts.map +1 -0
- package/dist/lib/cookies/extra.js +14 -0
- package/dist/lib/cookies/index.d.ts +2 -1
- package/dist/lib/cookies/index.d.ts.map +1 -1
- package/dist/lib/cookies/index.js +2 -1
- package/dist/lib/coord-root-id.d.ts +9 -0
- package/dist/lib/coord-root-id.d.ts.map +1 -0
- package/dist/lib/coord-root-id.js +17 -0
- package/dist/lib/durable-job.d.ts +124 -0
- package/dist/lib/durable-job.d.ts.map +1 -0
- package/dist/lib/durable-job.js +296 -0
- package/dist/lib/http/client.d.ts +7 -1
- package/dist/lib/http/client.d.ts.map +1 -1
- package/dist/lib/http/client.js +2 -0
- package/dist/lib/instructions/apply.d.ts +3 -1
- package/dist/lib/instructions/apply.d.ts.map +1 -1
- package/dist/lib/instructions/apply.js +74 -3
- package/dist/lib/instructions/templates.d.ts.map +1 -1
- package/dist/lib/instructions/templates.js +11 -2
- package/package.json +19 -2
- package/src/commander.ts +75 -1
- package/src/commands/admission.ts +699 -0
- package/src/commands/agents.ts +189 -50
- package/src/commands/artifacts.ts +132 -18
- package/src/commands/browse-ai.ts +10 -5
- package/src/commands/browse.ts +496 -20
- package/src/commands/diagnostics.ts +271 -0
- package/src/commands/fetch.ts +1 -0
- package/src/commands/files.ts +102 -2
- package/src/commands/governor.ts +8 -0
- package/src/commands/ledger-v3.ts +82 -0
- package/src/commands/qa-record.ts +682 -0
- package/src/commands/qa-run.ts +503 -0
- package/src/commands/qa-status.ts +608 -0
- package/src/commands/qa-verify.ts +238 -0
- package/src/commands/resources.ts +38 -0
- package/src/commands/review-pack.ts +1281 -0
- package/src/commands/supervisor.ts +141 -0
- package/src/commands/web.ts +19 -0
- package/src/commands/workflow.ts +8 -0
- package/src/core/agents/cli.ts +7 -3
- package/src/core/agents/health.ts +142 -0
- package/src/core/agents/mailbox.ts +373 -0
- package/src/core/agents/qa-signal.ts +261 -0
- package/src/core/agents/reconcile-coordination-v3.ts +77 -0
- package/src/core/agents/render/prompt-context.ts +42 -12
- package/src/core/agents/render/session-context.ts +37 -3
- package/src/core/agents/rules/commit-conflict.ts +58 -1
- package/src/core/agents/rules/stop-hook.ts +6 -12
- package/src/core/agents/session-finalizer-v3.ts +4 -1
- package/src/core/agents/session-name-display.ts +78 -7
- package/src/core/agents/state/heartbeat-reader.ts +7 -0
- package/src/core/agents/state/heartbeat-writer.ts +23 -0
- package/src/core/agents/state/live-coordination-view.ts +1 -0
- package/src/core/agents/state/live-coordination-writer.ts +5 -0
- package/src/core/artifacts/constants.ts +1 -1
- package/src/core/artifacts/index.ts +565 -30
- package/src/core/config.ts +134 -2
- package/src/core/diagnostics/advice.ts +147 -0
- package/src/core/diagnostics/bundle.ts +1250 -0
- package/src/core/diagnostics/comparison.ts +565 -0
- package/src/core/diagnostics/contract.ts +311 -0
- package/src/core/diagnostics/identity.ts +11 -0
- package/src/core/diagnostics/index.ts +7 -0
- package/src/core/diagnostics/replay.ts +314 -0
- package/src/core/diagnostics/sanitize.ts +97 -0
- package/src/core/events/legacy-storage/compression.ts +130 -0
- package/src/core/events/legacy-storage/index.ts +1 -0
- package/src/core/events/v3/archive-retention.ts +251 -0
- package/src/core/events/v3/bootstrap.ts +10 -0
- package/src/core/events/v3/capabilities.ts +2 -0
- package/src/core/events/v3/coordination-view.ts +100 -11
- package/src/core/events/v3/index.ts +9 -0
- package/src/core/events/v3/live-routing.ts +1 -0
- package/src/core/events/v3/producers/hook-base.ts +14 -2
- package/src/core/events/v3/producers/intake.ts +10 -2
- package/src/core/events/v3/producers/recorder.ts +420 -17
- package/src/core/hooks/adapter/output.ts +12 -1
- package/src/core/hooks/cli.ts +332 -247
- package/src/core/hooks/health.ts +146 -0
- package/src/core/hooks/resolve/transcript.ts +10 -3
- package/src/core/hooks/session-name-presence.ts +6 -1
- package/src/core/qa-artifacts.ts +126 -0
- package/src/core/resources/contract.ts +105 -0
- package/src/core/resources/index.ts +5 -0
- package/src/core/resources/sampler.ts +590 -0
- package/src/core/resources/service-status.ts +62 -0
- package/src/core/resources/service.ts +337 -0
- package/src/core/resources/storage.ts +44 -0
- package/src/core/storage/atomic-json.ts +15 -0
- package/src/core/storage/builtins.ts +62 -6
- package/src/core/storage/logger.ts +2 -0
- package/src/core/storage/query.ts +58 -0
- package/src/core/supervisor/activity.ts +193 -0
- package/src/core/supervisor/contract.ts +312 -0
- package/src/core/supervisor/explanations.ts +104 -0
- package/src/core/supervisor/findings.ts +788 -0
- package/src/core/supervisor/history.ts +61 -0
- package/src/core/supervisor/hook-health-alerts.ts +108 -0
- package/src/core/supervisor/hook-health-storage.ts +25 -0
- package/src/core/supervisor/hook-health.ts +301 -0
- package/src/core/supervisor/hooks.ts +35 -0
- package/src/core/supervisor/index.ts +14 -0
- package/src/core/supervisor/log-feed.ts +131 -0
- package/src/core/supervisor/service.ts +511 -0
- package/src/core/supervisor/services.ts +203 -0
- package/src/core/supervisor/status.ts +59 -0
- package/src/core/supervisor/storage.ts +126 -0
- package/src/core/supervisor/timeline.ts +133 -0
- package/src/core/workflow/admission.ts +215 -0
- package/src/core/workflow/engine.ts +93 -1
- package/src/core/workflow/index.ts +10 -0
- package/src/core/workflow/proof.ts +54 -1
- package/src/core/workflow/run-state.ts +13 -1
- package/src/core/workflow/types.ts +39 -1
- package/src/lib/admission.ts +347 -0
- package/src/lib/agent-browser/client.ts +2 -10
- package/src/lib/browser/capture-fidelity.ts +98 -0
- package/src/lib/browser/client.ts +212 -10
- package/src/lib/browser/critique.ts +62 -7
- package/src/lib/browser/index.ts +65 -0
- package/src/lib/browser/page-review-judge.ts +360 -0
- package/src/lib/browser/page-review-pack.ts +2384 -0
- package/src/lib/browser/qa-run-contracts.ts +743 -0
- package/src/lib/browser/qa-run.ts +1462 -0
- package/src/lib/browser/request-diagnostics.ts +27 -0
- package/src/lib/browser/tiling.ts +32 -0
- package/src/lib/cookies/client.ts +228 -42
- package/src/lib/cookies/extra.ts +28 -0
- package/src/lib/cookies/index.ts +2 -0
- package/src/lib/coord-root-id.ts +23 -0
- package/src/lib/durable-job.ts +407 -0
- package/src/lib/http/client.ts +13 -1
- package/src/lib/instructions/apply.ts +81 -2
- package/src/lib/instructions/templates.ts +11 -2
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import {
|
|
4
|
+
closeSync,
|
|
5
|
+
existsSync,
|
|
6
|
+
mkdirSync,
|
|
7
|
+
openSync,
|
|
8
|
+
readdirSync,
|
|
9
|
+
readFileSync,
|
|
10
|
+
rmSync,
|
|
11
|
+
unlinkSync,
|
|
12
|
+
writeFileSync,
|
|
13
|
+
} from "node:fs";
|
|
14
|
+
import { hostname } from "node:os";
|
|
15
|
+
import { resolve } from "node:path";
|
|
16
|
+
import { performance } from "node:perf_hooks";
|
|
17
|
+
import { collectCoordinationHealthSnapshot } from "../agents/health.ts";
|
|
18
|
+
import { checkPidToken, processStartToken } from "../agents/state/proc-start.ts";
|
|
19
|
+
import type { ResourceSamplerState } from "../resources/contract.ts";
|
|
20
|
+
import { sampleResources } from "../resources/sampler.ts";
|
|
21
|
+
import { requestResourceServiceStop } from "../resources/service.ts";
|
|
22
|
+
import { readResourceServiceStatus } from "../resources/service-status.ts";
|
|
23
|
+
import { resourcePaths } from "../resources/storage.ts";
|
|
24
|
+
import { writePrivateJsonAtomic } from "../storage/atomic-json.ts";
|
|
25
|
+
import { closeProcessLoggers, legacyLogFields, processLogger } from "../storage/logger.ts";
|
|
26
|
+
import { collectSupervisorActivitySnapshot } from "./activity.ts";
|
|
27
|
+
import {
|
|
28
|
+
SUPERVISOR_SNAPSHOT_SCHEMA_VERSION,
|
|
29
|
+
SUPERVISOR_STATUS_SCHEMA_VERSION,
|
|
30
|
+
type SupervisorServiceStatusRecord,
|
|
31
|
+
type SupervisorSnapshot,
|
|
32
|
+
type SupervisorStatus,
|
|
33
|
+
} from "./contract.ts";
|
|
34
|
+
import { explainSupervisorFinding } from "./explanations.ts";
|
|
35
|
+
import { updateSupervisorFindings } from "./findings.ts";
|
|
36
|
+
import { updateSupervisorHistory } from "./history.ts";
|
|
37
|
+
import { projectHookHealth } from "./hook-health.ts";
|
|
38
|
+
import { writeSupervisorHookHealth } from "./hook-health-storage.ts";
|
|
39
|
+
import { collectHookHealth } from "./hooks.ts";
|
|
40
|
+
import { SupervisorLogCollector } from "./log-feed.ts";
|
|
41
|
+
import { collectServiceHealth } from "./services.ts";
|
|
42
|
+
import { readSupervisorStatus } from "./status.ts";
|
|
43
|
+
import { readSupervisorFindings, readSupervisorHistory, supervisorPaths } from "./storage.ts";
|
|
44
|
+
import { buildSupervisorTimeline } from "./timeline.ts";
|
|
45
|
+
|
|
46
|
+
export const SUPERVISOR_DEFAULT_INTERVAL_MS = 2_000;
|
|
47
|
+
export const SUPERVISOR_DEFAULT_IDLE_EXIT_MS = 2 * 60_000;
|
|
48
|
+
const SUPERVISOR_MIN_INTERVAL_MS = 500;
|
|
49
|
+
const SUPERVISOR_MAX_INTERVAL_MS = 60_000;
|
|
50
|
+
const SUPERVISOR_MIN_IDLE_EXIT_MS = 5_000;
|
|
51
|
+
const SUPERVISOR_MAX_IDLE_EXIT_MS = 24 * 60 * 60_000;
|
|
52
|
+
|
|
53
|
+
interface SupervisorLease {
|
|
54
|
+
pid: number;
|
|
55
|
+
start_token?: string;
|
|
56
|
+
host: string;
|
|
57
|
+
nonce: string;
|
|
58
|
+
created_at: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface RunSupervisorInput {
|
|
62
|
+
coordRoot: string;
|
|
63
|
+
intervalMs?: number;
|
|
64
|
+
idleExitMs?: number;
|
|
65
|
+
keepAlive?: boolean;
|
|
66
|
+
maxCycles?: number;
|
|
67
|
+
now?: () => Date;
|
|
68
|
+
wait?: (milliseconds: number) => Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type EnsureSupervisorResult =
|
|
72
|
+
| { state: "running" | "started"; status: SupervisorStatus }
|
|
73
|
+
| { state: "unavailable"; status: SupervisorStatus; error: string };
|
|
74
|
+
|
|
75
|
+
export async function spawnSupervisor(
|
|
76
|
+
coordRootRaw: string,
|
|
77
|
+
options: { intervalMs?: number; idleExitMs?: number; keepAlive?: boolean } = {},
|
|
78
|
+
): Promise<SupervisorStatus> {
|
|
79
|
+
const coordRoot = resolve(coordRootRaw);
|
|
80
|
+
const current = readSupervisorStatus(coordRoot);
|
|
81
|
+
if (current.running) {
|
|
82
|
+
throw new Error(`local supervisor is already running under pid ${current.record?.pid}`);
|
|
83
|
+
}
|
|
84
|
+
await stopLegacyResourceObserver(coordRoot);
|
|
85
|
+
const intervalMs = normalizeInterval(options.intervalMs);
|
|
86
|
+
const idleExitMs = normalizeIdleExit(options.idleExitMs);
|
|
87
|
+
const paths = supervisorPaths(coordRoot);
|
|
88
|
+
mkdirSync(paths.root, { recursive: true, mode: 0o700 });
|
|
89
|
+
rmSync(paths.stop, { force: true });
|
|
90
|
+
const harnBin = new URL("../../../bin/harn", import.meta.url).pathname;
|
|
91
|
+
if (!existsSync(harnBin)) throw new Error(`cannot find harn executable at ${harnBin}`);
|
|
92
|
+
let spawnError: Error | undefined;
|
|
93
|
+
const child = spawn(
|
|
94
|
+
harnBin,
|
|
95
|
+
[
|
|
96
|
+
"supervisor",
|
|
97
|
+
"daemon",
|
|
98
|
+
"--root",
|
|
99
|
+
coordRoot,
|
|
100
|
+
"--interval-ms",
|
|
101
|
+
String(intervalMs),
|
|
102
|
+
"--idle-exit-ms",
|
|
103
|
+
String(idleExitMs),
|
|
104
|
+
...(options.keepAlive ? ["--keep-alive"] : []),
|
|
105
|
+
],
|
|
106
|
+
{
|
|
107
|
+
cwd: coordRoot,
|
|
108
|
+
detached: true,
|
|
109
|
+
stdio: ["ignore", "ignore", "ignore"],
|
|
110
|
+
env: {
|
|
111
|
+
...process.env,
|
|
112
|
+
HARNERY_COORD_ROOT_OVERRIDE: coordRoot,
|
|
113
|
+
HARNERY_OUTPUT_SESSION_TEE: "0",
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
);
|
|
117
|
+
child.once("error", (error) => {
|
|
118
|
+
spawnError = error;
|
|
119
|
+
});
|
|
120
|
+
child.unref();
|
|
121
|
+
const deadline = Date.now() + 5_000;
|
|
122
|
+
while (Date.now() < deadline) {
|
|
123
|
+
await delay(50);
|
|
124
|
+
if (spawnError) throw spawnError;
|
|
125
|
+
const status = readSupervisorStatus(coordRoot);
|
|
126
|
+
if (status.running && status.record?.pid === child.pid) return status;
|
|
127
|
+
if (child.exitCode !== null) break;
|
|
128
|
+
}
|
|
129
|
+
throw new Error(`local supervisor failed to start; inspect ${paths.service}`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export async function ensureSupervisorRunning(coordRoot: string): Promise<EnsureSupervisorResult> {
|
|
133
|
+
const status = readSupervisorStatus(coordRoot);
|
|
134
|
+
if (status.running) return { state: "running", status };
|
|
135
|
+
try {
|
|
136
|
+
const started = await spawnSupervisor(coordRoot);
|
|
137
|
+
return { state: "started", status: started };
|
|
138
|
+
} catch (error) {
|
|
139
|
+
return {
|
|
140
|
+
state: "unavailable",
|
|
141
|
+
status: readSupervisorStatus(coordRoot),
|
|
142
|
+
error: error instanceof Error ? error.message : String(error),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function requestSupervisorStop(coordRootRaw: string): SupervisorStatus {
|
|
148
|
+
const coordRoot = resolve(coordRootRaw);
|
|
149
|
+
const paths = supervisorPaths(coordRoot);
|
|
150
|
+
const status = readSupervisorStatus(coordRoot);
|
|
151
|
+
mkdirSync(paths.root, { recursive: true, mode: 0o700 });
|
|
152
|
+
writePrivateJsonAtomic(paths.stop, {
|
|
153
|
+
requested_at: new Date().toISOString(),
|
|
154
|
+
requested_by_pid: process.pid,
|
|
155
|
+
});
|
|
156
|
+
if (status.running && status.record?.host === hostname()) {
|
|
157
|
+
try {
|
|
158
|
+
process.kill(status.record.pid, "SIGTERM");
|
|
159
|
+
} catch {
|
|
160
|
+
// The durable stop file handles a racing exit.
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return readSupervisorStatus(coordRoot);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export async function runSupervisor(
|
|
167
|
+
input: RunSupervisorInput,
|
|
168
|
+
): Promise<SupervisorServiceStatusRecord> {
|
|
169
|
+
const coordRoot = resolve(input.coordRoot);
|
|
170
|
+
const paths = supervisorPaths(coordRoot);
|
|
171
|
+
const intervalMs = normalizeInterval(input.intervalMs);
|
|
172
|
+
const idleExitMs = normalizeIdleExit(input.idleExitMs);
|
|
173
|
+
const keepAlive = input.keepAlive ?? false;
|
|
174
|
+
const now = input.now ?? (() => new Date());
|
|
175
|
+
const wait = input.wait ?? delay;
|
|
176
|
+
const lease = acquireLease(coordRoot, now());
|
|
177
|
+
rmSync(paths.stop, { force: true });
|
|
178
|
+
const startedAt = now().toISOString();
|
|
179
|
+
const startToken = processStartToken(process.pid);
|
|
180
|
+
const status: SupervisorServiceStatusRecord = {
|
|
181
|
+
schema_version: SUPERVISOR_STATUS_SCHEMA_VERSION,
|
|
182
|
+
pid: process.pid,
|
|
183
|
+
...(startToken ? { start_token: startToken } : {}),
|
|
184
|
+
host: hostname(),
|
|
185
|
+
nonce: lease.nonce,
|
|
186
|
+
state: "starting",
|
|
187
|
+
started_at: startedAt,
|
|
188
|
+
heartbeat_at: startedAt,
|
|
189
|
+
interval_ms: intervalMs,
|
|
190
|
+
keep_alive: keepAlive,
|
|
191
|
+
idle_exit_ms: idleExitMs,
|
|
192
|
+
cycle_count: 0,
|
|
193
|
+
};
|
|
194
|
+
let stopping = false;
|
|
195
|
+
let previousResource: ResourceSamplerState | undefined;
|
|
196
|
+
let history = readSupervisorHistory(coordRoot);
|
|
197
|
+
let findings = readSupervisorFindings(coordRoot);
|
|
198
|
+
let coordination = collectCoordinationHealthSnapshot(coordRoot, now());
|
|
199
|
+
const logs = new SupervisorLogCollector(coordRoot);
|
|
200
|
+
const writeStatus = () => {
|
|
201
|
+
status.heartbeat_at = now().toISOString();
|
|
202
|
+
writePrivateJsonAtomic(paths.service, status);
|
|
203
|
+
};
|
|
204
|
+
const requestStop = () => {
|
|
205
|
+
stopping = true;
|
|
206
|
+
status.state = "stopping";
|
|
207
|
+
writeStatus();
|
|
208
|
+
};
|
|
209
|
+
process.on("SIGINT", requestStop);
|
|
210
|
+
process.on("SIGTERM", requestStop);
|
|
211
|
+
status.state = "running";
|
|
212
|
+
writeStatus();
|
|
213
|
+
log(coordRoot, "supervisor.started", {
|
|
214
|
+
pid: process.pid,
|
|
215
|
+
interval_ms: intervalMs,
|
|
216
|
+
idle_exit_ms: idleExitMs,
|
|
217
|
+
keep_alive: keepAlive,
|
|
218
|
+
});
|
|
219
|
+
try {
|
|
220
|
+
while (!stopping && !existsSync(paths.stop)) {
|
|
221
|
+
const cycleStarted = performance.now();
|
|
222
|
+
try {
|
|
223
|
+
const cycleNow = now();
|
|
224
|
+
const serviceHealth = collectServiceHealth(coordRoot, status);
|
|
225
|
+
const resource = sampleResources(coordRoot, previousResource, {
|
|
226
|
+
services: [
|
|
227
|
+
{ pid: process.pid, id: "supervisor" },
|
|
228
|
+
...serviceHealth.consumers.map((consumer) => ({
|
|
229
|
+
pid: consumer.pid,
|
|
230
|
+
id: consumer.id,
|
|
231
|
+
})),
|
|
232
|
+
],
|
|
233
|
+
});
|
|
234
|
+
previousResource = resource.state;
|
|
235
|
+
writePrivateJsonAtomic(resourcePaths(coordRoot).snapshot, resource.snapshot);
|
|
236
|
+
const logFeed = await logs.collect(cycleNow);
|
|
237
|
+
writePrivateJsonAtomic(paths.log_feed, logFeed);
|
|
238
|
+
const hookHealth = projectHookHealth(logFeed, cycleNow);
|
|
239
|
+
writeSupervisorHookHealth(coordRoot, hookHealth);
|
|
240
|
+
const activity = collectSupervisorActivitySnapshot(coordRoot, cycleNow);
|
|
241
|
+
writePrivateJsonAtomic(paths.activity, activity);
|
|
242
|
+
const hooks = collectHookHealth(resource.snapshot);
|
|
243
|
+
const historyResult = updateSupervisorHistory(history, resource.snapshot);
|
|
244
|
+
history = historyResult.history;
|
|
245
|
+
if (historyResult.changed) writePrivateJsonAtomic(paths.history, history);
|
|
246
|
+
if (historyResult.changed)
|
|
247
|
+
coordination = collectCoordinationHealthSnapshot(coordRoot, cycleNow);
|
|
248
|
+
writePrivateJsonAtomic(paths.coordination_health, coordination);
|
|
249
|
+
const priorActiveFindingIds = new Set(findings?.active.map((finding) => finding.id) ?? []);
|
|
250
|
+
const priorTransitionKeys = new Set(
|
|
251
|
+
findings?.transitions.map((finding) => `${finding.id}:${finding.state}`) ?? [],
|
|
252
|
+
);
|
|
253
|
+
findings = updateSupervisorFindings({
|
|
254
|
+
previous: findings,
|
|
255
|
+
resource: resource.snapshot,
|
|
256
|
+
services: serviceHealth.services,
|
|
257
|
+
hooks,
|
|
258
|
+
history,
|
|
259
|
+
logFeed,
|
|
260
|
+
hookHealth,
|
|
261
|
+
coordination,
|
|
262
|
+
activity,
|
|
263
|
+
now: cycleNow,
|
|
264
|
+
});
|
|
265
|
+
writePrivateJsonAtomic(paths.findings, findings);
|
|
266
|
+
mkdirSync(paths.timelines, { recursive: true, mode: 0o700 });
|
|
267
|
+
mkdirSync(paths.explanations, { recursive: true, mode: 0o700 });
|
|
268
|
+
const projectionUpdates = [
|
|
269
|
+
...findings.active.filter((finding) => !priorActiveFindingIds.has(finding.id)),
|
|
270
|
+
...findings.transitions.filter(
|
|
271
|
+
(finding) => !priorTransitionKeys.has(`${finding.id}:${finding.state}`),
|
|
272
|
+
),
|
|
273
|
+
];
|
|
274
|
+
for (const finding of projectionUpdates) {
|
|
275
|
+
const relatedSources = coordination.recent_events.filter((source) => {
|
|
276
|
+
const delta = Math.abs(
|
|
277
|
+
Date.parse(source.observed_at) - Date.parse(finding.observed_at),
|
|
278
|
+
);
|
|
279
|
+
return Number.isFinite(delta) && delta <= 5 * 60_000;
|
|
280
|
+
});
|
|
281
|
+
writePrivateJsonAtomic(
|
|
282
|
+
resolve(paths.timelines, `${finding.id}.json`),
|
|
283
|
+
buildSupervisorTimeline(finding, relatedSources),
|
|
284
|
+
);
|
|
285
|
+
writePrivateJsonAtomic(
|
|
286
|
+
resolve(paths.explanations, `${finding.id}.json`),
|
|
287
|
+
explainSupervisorFinding(finding),
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
const retainedFindingIds = new Set([
|
|
291
|
+
...findings.active.map((finding) => finding.id),
|
|
292
|
+
...findings.transitions.map((finding) => finding.id),
|
|
293
|
+
]);
|
|
294
|
+
pruneProjectionDirectory(paths.timelines, retainedFindingIds);
|
|
295
|
+
pruneProjectionDirectory(paths.explanations, retainedFindingIds);
|
|
296
|
+
const attributedAgentCount = resource.snapshot.groups.filter(
|
|
297
|
+
(group) => group.kind === "agent",
|
|
298
|
+
).length;
|
|
299
|
+
const idle = serviceHealth.consumers.length === 0 && attributedAgentCount === 0;
|
|
300
|
+
if (!keepAlive && idle) status.idle_since ??= now().toISOString();
|
|
301
|
+
else status.idle_since = undefined;
|
|
302
|
+
const snapshot: SupervisorSnapshot = {
|
|
303
|
+
schema_version: SUPERVISOR_SNAPSHOT_SCHEMA_VERSION,
|
|
304
|
+
sampled_at: resource.snapshot.sampled_at,
|
|
305
|
+
sequence: status.cycle_count + 1,
|
|
306
|
+
collector_duration_ms: round1(performance.now() - cycleStarted),
|
|
307
|
+
resource_sample_duration_ms: resource.snapshot.sample_duration_ms,
|
|
308
|
+
services: serviceHealth.services,
|
|
309
|
+
hooks,
|
|
310
|
+
active_finding_count: findings.active.length,
|
|
311
|
+
history_point_count: history.points.length,
|
|
312
|
+
log_record_count: logFeed.total_records,
|
|
313
|
+
live_consumer_count: serviceHealth.consumers.length,
|
|
314
|
+
attributed_agent_count: attributedAgentCount,
|
|
315
|
+
};
|
|
316
|
+
writePrivateJsonAtomic(paths.snapshot, snapshot);
|
|
317
|
+
status.cycle_count += 1;
|
|
318
|
+
status.last_cycle_at = snapshot.sampled_at;
|
|
319
|
+
status.last_cycle_duration_ms = snapshot.collector_duration_ms;
|
|
320
|
+
status.last_error_code = undefined;
|
|
321
|
+
log(coordRoot, "supervisor.sample", {
|
|
322
|
+
cycle_count: status.cycle_count,
|
|
323
|
+
duration_ms: snapshot.collector_duration_ms,
|
|
324
|
+
resource_cpu_ms: resource.snapshot.collector_cpu_ms,
|
|
325
|
+
visible_processes: resource.snapshot.visible_process_count,
|
|
326
|
+
services: serviceHealth.services.length,
|
|
327
|
+
hooks: hooks.length,
|
|
328
|
+
findings: findings.active.length,
|
|
329
|
+
log_records: logFeed.total_records,
|
|
330
|
+
hook_health_records: hookHealth.source_record_count,
|
|
331
|
+
});
|
|
332
|
+
if (
|
|
333
|
+
!keepAlive &&
|
|
334
|
+
status.idle_since &&
|
|
335
|
+
now().getTime() - Date.parse(status.idle_since) >= idleExitMs
|
|
336
|
+
) {
|
|
337
|
+
log(coordRoot, "supervisor.idle_exit", { idle_exit_ms: idleExitMs });
|
|
338
|
+
break;
|
|
339
|
+
}
|
|
340
|
+
} catch (error) {
|
|
341
|
+
status.last_error_code = supervisorErrorCode(error);
|
|
342
|
+
status.state = "error";
|
|
343
|
+
log(coordRoot, "supervisor.sample_error", { reason_code: status.last_error_code }, error);
|
|
344
|
+
}
|
|
345
|
+
if (status.state === "error") status.state = "running";
|
|
346
|
+
writeStatus();
|
|
347
|
+
if (input.maxCycles !== undefined && status.cycle_count >= input.maxCycles) break;
|
|
348
|
+
const remaining = Math.max(0, intervalMs - (performance.now() - cycleStarted));
|
|
349
|
+
if (!stopping && !existsSync(paths.stop)) await wait(remaining);
|
|
350
|
+
}
|
|
351
|
+
} finally {
|
|
352
|
+
process.off("SIGINT", requestStop);
|
|
353
|
+
process.off("SIGTERM", requestStop);
|
|
354
|
+
status.state = "stopped";
|
|
355
|
+
status.stopped_at = now().toISOString();
|
|
356
|
+
status.idle_since = undefined;
|
|
357
|
+
writeStatus();
|
|
358
|
+
log(coordRoot, "supervisor.stopped", { cycle_count: status.cycle_count });
|
|
359
|
+
try {
|
|
360
|
+
await closeProcessLoggers();
|
|
361
|
+
} finally {
|
|
362
|
+
releaseLease(paths.lease, lease.nonce);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return status;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function acquireLease(coordRoot: string, now: Date): SupervisorLease {
|
|
369
|
+
const paths = supervisorPaths(coordRoot);
|
|
370
|
+
mkdirSync(paths.root, { recursive: true, mode: 0o700 });
|
|
371
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
372
|
+
const startToken = processStartToken(process.pid);
|
|
373
|
+
const lease: SupervisorLease = {
|
|
374
|
+
pid: process.pid,
|
|
375
|
+
...(startToken ? { start_token: startToken } : {}),
|
|
376
|
+
host: hostname(),
|
|
377
|
+
nonce: randomUUID(),
|
|
378
|
+
created_at: now.toISOString(),
|
|
379
|
+
};
|
|
380
|
+
try {
|
|
381
|
+
const fd = openSync(paths.lease, "wx", 0o600);
|
|
382
|
+
try {
|
|
383
|
+
writeFileSync(fd, `${JSON.stringify(lease)}\n`, "utf8");
|
|
384
|
+
} finally {
|
|
385
|
+
closeSync(fd);
|
|
386
|
+
}
|
|
387
|
+
return lease;
|
|
388
|
+
} catch (error) {
|
|
389
|
+
if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
|
|
390
|
+
const existing = readLease(paths.lease);
|
|
391
|
+
if (existing && leaseIsLive(existing)) {
|
|
392
|
+
throw new Error(`local supervisor lease is held by pid ${existing.pid}`);
|
|
393
|
+
}
|
|
394
|
+
try {
|
|
395
|
+
unlinkSync(paths.lease);
|
|
396
|
+
} catch {
|
|
397
|
+
// A concurrent starter may have replaced or removed the stale lease.
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
throw new Error("local supervisor could not acquire its singleton lease");
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function pruneProjectionDirectory(
|
|
405
|
+
directory: string,
|
|
406
|
+
retainedFindingIds: ReadonlySet<string>,
|
|
407
|
+
): void {
|
|
408
|
+
for (const file of readdirSync(directory)) {
|
|
409
|
+
if (!file.endsWith(".json")) continue;
|
|
410
|
+
const findingId = file.slice(0, -5);
|
|
411
|
+
if (!retainedFindingIds.has(findingId)) rmSync(resolve(directory, file), { force: true });
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function releaseLease(path: string, nonce: string): void {
|
|
416
|
+
const current = readLease(path);
|
|
417
|
+
if (current?.nonce !== nonce) return;
|
|
418
|
+
try {
|
|
419
|
+
unlinkSync(path);
|
|
420
|
+
} catch {
|
|
421
|
+
// A missing lease is already released.
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function readLease(path: string): SupervisorLease | undefined {
|
|
426
|
+
try {
|
|
427
|
+
const value = JSON.parse(readFileSync(path, "utf8")) as SupervisorLease;
|
|
428
|
+
return value && Number.isSafeInteger(value.pid) && typeof value.nonce === "string"
|
|
429
|
+
? value
|
|
430
|
+
: undefined;
|
|
431
|
+
} catch {
|
|
432
|
+
return undefined;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function leaseIsLive(lease: SupervisorLease): boolean {
|
|
437
|
+
if (lease.host !== hostname()) return true;
|
|
438
|
+
try {
|
|
439
|
+
process.kill(lease.pid, 0);
|
|
440
|
+
} catch (error) {
|
|
441
|
+
if ((error as NodeJS.ErrnoException).code !== "EPERM") return false;
|
|
442
|
+
}
|
|
443
|
+
return checkPidToken(lease.pid, lease.start_token) !== "mismatch";
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
async function stopLegacyResourceObserver(coordRoot: string): Promise<void> {
|
|
447
|
+
const legacy = readResourceServiceStatus(coordRoot);
|
|
448
|
+
if (!legacy.running) return;
|
|
449
|
+
requestResourceServiceStop(coordRoot);
|
|
450
|
+
const deadline = Date.now() + 2_000;
|
|
451
|
+
while (readResourceServiceStatus(coordRoot).running && Date.now() < deadline) await delay(50);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function log(
|
|
455
|
+
coordRoot: string,
|
|
456
|
+
event: string,
|
|
457
|
+
fields: Record<string, unknown>,
|
|
458
|
+
error?: unknown,
|
|
459
|
+
): void {
|
|
460
|
+
try {
|
|
461
|
+
const logger = processLogger(coordRoot, "supervisor");
|
|
462
|
+
if (error) logger.error(event, legacyLogFields(fields), error);
|
|
463
|
+
else logger.info(event, legacyLogFields(fields));
|
|
464
|
+
} catch {
|
|
465
|
+
// Observability must never break the supervisor loop.
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
function supervisorErrorCode(error: unknown): string {
|
|
470
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
471
|
+
if (/procfs|\/proc\//i.test(message)) return "procfs_read_failed";
|
|
472
|
+
if (/permission|EACCES|EPERM/i.test(message)) return "permission_denied";
|
|
473
|
+
if (/log/i.test(message)) return "log_collection_failed";
|
|
474
|
+
return "collection_failed";
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
function normalizeInterval(value: number | undefined): number {
|
|
478
|
+
const interval = value ?? SUPERVISOR_DEFAULT_INTERVAL_MS;
|
|
479
|
+
if (
|
|
480
|
+
!Number.isFinite(interval) ||
|
|
481
|
+
interval < SUPERVISOR_MIN_INTERVAL_MS ||
|
|
482
|
+
interval > SUPERVISOR_MAX_INTERVAL_MS
|
|
483
|
+
) {
|
|
484
|
+
throw new Error(
|
|
485
|
+
`supervisor interval must be ${SUPERVISOR_MIN_INTERVAL_MS}-${SUPERVISOR_MAX_INTERVAL_MS} ms`,
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
return Math.round(interval);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
function normalizeIdleExit(value: number | undefined): number {
|
|
492
|
+
const idle = value ?? SUPERVISOR_DEFAULT_IDLE_EXIT_MS;
|
|
493
|
+
if (
|
|
494
|
+
!Number.isFinite(idle) ||
|
|
495
|
+
idle < SUPERVISOR_MIN_IDLE_EXIT_MS ||
|
|
496
|
+
idle > SUPERVISOR_MAX_IDLE_EXIT_MS
|
|
497
|
+
) {
|
|
498
|
+
throw new Error(
|
|
499
|
+
`supervisor idle exit must be ${SUPERVISOR_MIN_IDLE_EXIT_MS}-${SUPERVISOR_MAX_IDLE_EXIT_MS} ms`,
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
return Math.round(idle);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
function delay(milliseconds: number): Promise<void> {
|
|
506
|
+
return new Promise((resolveDelay) => setTimeout(resolveDelay, milliseconds));
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function round1(value: number): number {
|
|
510
|
+
return Math.round(value * 10) / 10;
|
|
511
|
+
}
|