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,450 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { closeSync, existsSync, mkdirSync, openSync, readdirSync, readFileSync, rmSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
4
|
+
import { hostname } from "node:os";
|
|
5
|
+
import { resolve } from "node:path";
|
|
6
|
+
import { performance } from "node:perf_hooks";
|
|
7
|
+
import { collectCoordinationHealthSnapshot } from "../agents/health.js";
|
|
8
|
+
import { checkPidToken, processStartToken } from "../agents/state/proc-start.js";
|
|
9
|
+
import { sampleResources } from "../resources/sampler.js";
|
|
10
|
+
import { requestResourceServiceStop } from "../resources/service.js";
|
|
11
|
+
import { readResourceServiceStatus } from "../resources/service-status.js";
|
|
12
|
+
import { resourcePaths } from "../resources/storage.js";
|
|
13
|
+
import { writePrivateJsonAtomic } from "../storage/atomic-json.js";
|
|
14
|
+
import { closeProcessLoggers, legacyLogFields, processLogger } from "../storage/logger.js";
|
|
15
|
+
import { collectSupervisorActivitySnapshot } from "./activity.js";
|
|
16
|
+
import { SUPERVISOR_SNAPSHOT_SCHEMA_VERSION, SUPERVISOR_STATUS_SCHEMA_VERSION, } from "./contract.js";
|
|
17
|
+
import { explainSupervisorFinding } from "./explanations.js";
|
|
18
|
+
import { updateSupervisorFindings } from "./findings.js";
|
|
19
|
+
import { updateSupervisorHistory } from "./history.js";
|
|
20
|
+
import { projectHookHealth } from "./hook-health.js";
|
|
21
|
+
import { writeSupervisorHookHealth } from "./hook-health-storage.js";
|
|
22
|
+
import { collectHookHealth } from "./hooks.js";
|
|
23
|
+
import { SupervisorLogCollector } from "./log-feed.js";
|
|
24
|
+
import { collectServiceHealth } from "./services.js";
|
|
25
|
+
import { readSupervisorStatus } from "./status.js";
|
|
26
|
+
import { readSupervisorFindings, readSupervisorHistory, supervisorPaths } from "./storage.js";
|
|
27
|
+
import { buildSupervisorTimeline } from "./timeline.js";
|
|
28
|
+
export const SUPERVISOR_DEFAULT_INTERVAL_MS = 2_000;
|
|
29
|
+
export const SUPERVISOR_DEFAULT_IDLE_EXIT_MS = 2 * 60_000;
|
|
30
|
+
const SUPERVISOR_MIN_INTERVAL_MS = 500;
|
|
31
|
+
const SUPERVISOR_MAX_INTERVAL_MS = 60_000;
|
|
32
|
+
const SUPERVISOR_MIN_IDLE_EXIT_MS = 5_000;
|
|
33
|
+
const SUPERVISOR_MAX_IDLE_EXIT_MS = 24 * 60 * 60_000;
|
|
34
|
+
export async function spawnSupervisor(coordRootRaw, options = {}) {
|
|
35
|
+
const coordRoot = resolve(coordRootRaw);
|
|
36
|
+
const current = readSupervisorStatus(coordRoot);
|
|
37
|
+
if (current.running) {
|
|
38
|
+
throw new Error(`local supervisor is already running under pid ${current.record?.pid}`);
|
|
39
|
+
}
|
|
40
|
+
await stopLegacyResourceObserver(coordRoot);
|
|
41
|
+
const intervalMs = normalizeInterval(options.intervalMs);
|
|
42
|
+
const idleExitMs = normalizeIdleExit(options.idleExitMs);
|
|
43
|
+
const paths = supervisorPaths(coordRoot);
|
|
44
|
+
mkdirSync(paths.root, { recursive: true, mode: 0o700 });
|
|
45
|
+
rmSync(paths.stop, { force: true });
|
|
46
|
+
const harnBin = new URL("../../../bin/harn", import.meta.url).pathname;
|
|
47
|
+
if (!existsSync(harnBin))
|
|
48
|
+
throw new Error(`cannot find harn executable at ${harnBin}`);
|
|
49
|
+
let spawnError;
|
|
50
|
+
const child = spawn(harnBin, [
|
|
51
|
+
"supervisor",
|
|
52
|
+
"daemon",
|
|
53
|
+
"--root",
|
|
54
|
+
coordRoot,
|
|
55
|
+
"--interval-ms",
|
|
56
|
+
String(intervalMs),
|
|
57
|
+
"--idle-exit-ms",
|
|
58
|
+
String(idleExitMs),
|
|
59
|
+
...(options.keepAlive ? ["--keep-alive"] : []),
|
|
60
|
+
], {
|
|
61
|
+
cwd: coordRoot,
|
|
62
|
+
detached: true,
|
|
63
|
+
stdio: ["ignore", "ignore", "ignore"],
|
|
64
|
+
env: {
|
|
65
|
+
...process.env,
|
|
66
|
+
HARNERY_COORD_ROOT_OVERRIDE: coordRoot,
|
|
67
|
+
HARNERY_OUTPUT_SESSION_TEE: "0",
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
child.once("error", (error) => {
|
|
71
|
+
spawnError = error;
|
|
72
|
+
});
|
|
73
|
+
child.unref();
|
|
74
|
+
const deadline = Date.now() + 5_000;
|
|
75
|
+
while (Date.now() < deadline) {
|
|
76
|
+
await delay(50);
|
|
77
|
+
if (spawnError)
|
|
78
|
+
throw spawnError;
|
|
79
|
+
const status = readSupervisorStatus(coordRoot);
|
|
80
|
+
if (status.running && status.record?.pid === child.pid)
|
|
81
|
+
return status;
|
|
82
|
+
if (child.exitCode !== null)
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
throw new Error(`local supervisor failed to start; inspect ${paths.service}`);
|
|
86
|
+
}
|
|
87
|
+
export async function ensureSupervisorRunning(coordRoot) {
|
|
88
|
+
const status = readSupervisorStatus(coordRoot);
|
|
89
|
+
if (status.running)
|
|
90
|
+
return { state: "running", status };
|
|
91
|
+
try {
|
|
92
|
+
const started = await spawnSupervisor(coordRoot);
|
|
93
|
+
return { state: "started", status: started };
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
return {
|
|
97
|
+
state: "unavailable",
|
|
98
|
+
status: readSupervisorStatus(coordRoot),
|
|
99
|
+
error: error instanceof Error ? error.message : String(error),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
export function requestSupervisorStop(coordRootRaw) {
|
|
104
|
+
const coordRoot = resolve(coordRootRaw);
|
|
105
|
+
const paths = supervisorPaths(coordRoot);
|
|
106
|
+
const status = readSupervisorStatus(coordRoot);
|
|
107
|
+
mkdirSync(paths.root, { recursive: true, mode: 0o700 });
|
|
108
|
+
writePrivateJsonAtomic(paths.stop, {
|
|
109
|
+
requested_at: new Date().toISOString(),
|
|
110
|
+
requested_by_pid: process.pid,
|
|
111
|
+
});
|
|
112
|
+
if (status.running && status.record?.host === hostname()) {
|
|
113
|
+
try {
|
|
114
|
+
process.kill(status.record.pid, "SIGTERM");
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// The durable stop file handles a racing exit.
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return readSupervisorStatus(coordRoot);
|
|
121
|
+
}
|
|
122
|
+
export async function runSupervisor(input) {
|
|
123
|
+
const coordRoot = resolve(input.coordRoot);
|
|
124
|
+
const paths = supervisorPaths(coordRoot);
|
|
125
|
+
const intervalMs = normalizeInterval(input.intervalMs);
|
|
126
|
+
const idleExitMs = normalizeIdleExit(input.idleExitMs);
|
|
127
|
+
const keepAlive = input.keepAlive ?? false;
|
|
128
|
+
const now = input.now ?? (() => new Date());
|
|
129
|
+
const wait = input.wait ?? delay;
|
|
130
|
+
const lease = acquireLease(coordRoot, now());
|
|
131
|
+
rmSync(paths.stop, { force: true });
|
|
132
|
+
const startedAt = now().toISOString();
|
|
133
|
+
const startToken = processStartToken(process.pid);
|
|
134
|
+
const status = {
|
|
135
|
+
schema_version: SUPERVISOR_STATUS_SCHEMA_VERSION,
|
|
136
|
+
pid: process.pid,
|
|
137
|
+
...(startToken ? { start_token: startToken } : {}),
|
|
138
|
+
host: hostname(),
|
|
139
|
+
nonce: lease.nonce,
|
|
140
|
+
state: "starting",
|
|
141
|
+
started_at: startedAt,
|
|
142
|
+
heartbeat_at: startedAt,
|
|
143
|
+
interval_ms: intervalMs,
|
|
144
|
+
keep_alive: keepAlive,
|
|
145
|
+
idle_exit_ms: idleExitMs,
|
|
146
|
+
cycle_count: 0,
|
|
147
|
+
};
|
|
148
|
+
let stopping = false;
|
|
149
|
+
let previousResource;
|
|
150
|
+
let history = readSupervisorHistory(coordRoot);
|
|
151
|
+
let findings = readSupervisorFindings(coordRoot);
|
|
152
|
+
let coordination = collectCoordinationHealthSnapshot(coordRoot, now());
|
|
153
|
+
const logs = new SupervisorLogCollector(coordRoot);
|
|
154
|
+
const writeStatus = () => {
|
|
155
|
+
status.heartbeat_at = now().toISOString();
|
|
156
|
+
writePrivateJsonAtomic(paths.service, status);
|
|
157
|
+
};
|
|
158
|
+
const requestStop = () => {
|
|
159
|
+
stopping = true;
|
|
160
|
+
status.state = "stopping";
|
|
161
|
+
writeStatus();
|
|
162
|
+
};
|
|
163
|
+
process.on("SIGINT", requestStop);
|
|
164
|
+
process.on("SIGTERM", requestStop);
|
|
165
|
+
status.state = "running";
|
|
166
|
+
writeStatus();
|
|
167
|
+
log(coordRoot, "supervisor.started", {
|
|
168
|
+
pid: process.pid,
|
|
169
|
+
interval_ms: intervalMs,
|
|
170
|
+
idle_exit_ms: idleExitMs,
|
|
171
|
+
keep_alive: keepAlive,
|
|
172
|
+
});
|
|
173
|
+
try {
|
|
174
|
+
while (!stopping && !existsSync(paths.stop)) {
|
|
175
|
+
const cycleStarted = performance.now();
|
|
176
|
+
try {
|
|
177
|
+
const cycleNow = now();
|
|
178
|
+
const serviceHealth = collectServiceHealth(coordRoot, status);
|
|
179
|
+
const resource = sampleResources(coordRoot, previousResource, {
|
|
180
|
+
services: [
|
|
181
|
+
{ pid: process.pid, id: "supervisor" },
|
|
182
|
+
...serviceHealth.consumers.map((consumer) => ({
|
|
183
|
+
pid: consumer.pid,
|
|
184
|
+
id: consumer.id,
|
|
185
|
+
})),
|
|
186
|
+
],
|
|
187
|
+
});
|
|
188
|
+
previousResource = resource.state;
|
|
189
|
+
writePrivateJsonAtomic(resourcePaths(coordRoot).snapshot, resource.snapshot);
|
|
190
|
+
const logFeed = await logs.collect(cycleNow);
|
|
191
|
+
writePrivateJsonAtomic(paths.log_feed, logFeed);
|
|
192
|
+
const hookHealth = projectHookHealth(logFeed, cycleNow);
|
|
193
|
+
writeSupervisorHookHealth(coordRoot, hookHealth);
|
|
194
|
+
const activity = collectSupervisorActivitySnapshot(coordRoot, cycleNow);
|
|
195
|
+
writePrivateJsonAtomic(paths.activity, activity);
|
|
196
|
+
const hooks = collectHookHealth(resource.snapshot);
|
|
197
|
+
const historyResult = updateSupervisorHistory(history, resource.snapshot);
|
|
198
|
+
history = historyResult.history;
|
|
199
|
+
if (historyResult.changed)
|
|
200
|
+
writePrivateJsonAtomic(paths.history, history);
|
|
201
|
+
if (historyResult.changed)
|
|
202
|
+
coordination = collectCoordinationHealthSnapshot(coordRoot, cycleNow);
|
|
203
|
+
writePrivateJsonAtomic(paths.coordination_health, coordination);
|
|
204
|
+
const priorActiveFindingIds = new Set(findings?.active.map((finding) => finding.id) ?? []);
|
|
205
|
+
const priorTransitionKeys = new Set(findings?.transitions.map((finding) => `${finding.id}:${finding.state}`) ?? []);
|
|
206
|
+
findings = updateSupervisorFindings({
|
|
207
|
+
previous: findings,
|
|
208
|
+
resource: resource.snapshot,
|
|
209
|
+
services: serviceHealth.services,
|
|
210
|
+
hooks,
|
|
211
|
+
history,
|
|
212
|
+
logFeed,
|
|
213
|
+
hookHealth,
|
|
214
|
+
coordination,
|
|
215
|
+
activity,
|
|
216
|
+
now: cycleNow,
|
|
217
|
+
});
|
|
218
|
+
writePrivateJsonAtomic(paths.findings, findings);
|
|
219
|
+
mkdirSync(paths.timelines, { recursive: true, mode: 0o700 });
|
|
220
|
+
mkdirSync(paths.explanations, { recursive: true, mode: 0o700 });
|
|
221
|
+
const projectionUpdates = [
|
|
222
|
+
...findings.active.filter((finding) => !priorActiveFindingIds.has(finding.id)),
|
|
223
|
+
...findings.transitions.filter((finding) => !priorTransitionKeys.has(`${finding.id}:${finding.state}`)),
|
|
224
|
+
];
|
|
225
|
+
for (const finding of projectionUpdates) {
|
|
226
|
+
const relatedSources = coordination.recent_events.filter((source) => {
|
|
227
|
+
const delta = Math.abs(Date.parse(source.observed_at) - Date.parse(finding.observed_at));
|
|
228
|
+
return Number.isFinite(delta) && delta <= 5 * 60_000;
|
|
229
|
+
});
|
|
230
|
+
writePrivateJsonAtomic(resolve(paths.timelines, `${finding.id}.json`), buildSupervisorTimeline(finding, relatedSources));
|
|
231
|
+
writePrivateJsonAtomic(resolve(paths.explanations, `${finding.id}.json`), explainSupervisorFinding(finding));
|
|
232
|
+
}
|
|
233
|
+
const retainedFindingIds = new Set([
|
|
234
|
+
...findings.active.map((finding) => finding.id),
|
|
235
|
+
...findings.transitions.map((finding) => finding.id),
|
|
236
|
+
]);
|
|
237
|
+
pruneProjectionDirectory(paths.timelines, retainedFindingIds);
|
|
238
|
+
pruneProjectionDirectory(paths.explanations, retainedFindingIds);
|
|
239
|
+
const attributedAgentCount = resource.snapshot.groups.filter((group) => group.kind === "agent").length;
|
|
240
|
+
const idle = serviceHealth.consumers.length === 0 && attributedAgentCount === 0;
|
|
241
|
+
if (!keepAlive && idle)
|
|
242
|
+
status.idle_since ??= now().toISOString();
|
|
243
|
+
else
|
|
244
|
+
status.idle_since = undefined;
|
|
245
|
+
const snapshot = {
|
|
246
|
+
schema_version: SUPERVISOR_SNAPSHOT_SCHEMA_VERSION,
|
|
247
|
+
sampled_at: resource.snapshot.sampled_at,
|
|
248
|
+
sequence: status.cycle_count + 1,
|
|
249
|
+
collector_duration_ms: round1(performance.now() - cycleStarted),
|
|
250
|
+
resource_sample_duration_ms: resource.snapshot.sample_duration_ms,
|
|
251
|
+
services: serviceHealth.services,
|
|
252
|
+
hooks,
|
|
253
|
+
active_finding_count: findings.active.length,
|
|
254
|
+
history_point_count: history.points.length,
|
|
255
|
+
log_record_count: logFeed.total_records,
|
|
256
|
+
live_consumer_count: serviceHealth.consumers.length,
|
|
257
|
+
attributed_agent_count: attributedAgentCount,
|
|
258
|
+
};
|
|
259
|
+
writePrivateJsonAtomic(paths.snapshot, snapshot);
|
|
260
|
+
status.cycle_count += 1;
|
|
261
|
+
status.last_cycle_at = snapshot.sampled_at;
|
|
262
|
+
status.last_cycle_duration_ms = snapshot.collector_duration_ms;
|
|
263
|
+
status.last_error_code = undefined;
|
|
264
|
+
log(coordRoot, "supervisor.sample", {
|
|
265
|
+
cycle_count: status.cycle_count,
|
|
266
|
+
duration_ms: snapshot.collector_duration_ms,
|
|
267
|
+
resource_cpu_ms: resource.snapshot.collector_cpu_ms,
|
|
268
|
+
visible_processes: resource.snapshot.visible_process_count,
|
|
269
|
+
services: serviceHealth.services.length,
|
|
270
|
+
hooks: hooks.length,
|
|
271
|
+
findings: findings.active.length,
|
|
272
|
+
log_records: logFeed.total_records,
|
|
273
|
+
hook_health_records: hookHealth.source_record_count,
|
|
274
|
+
});
|
|
275
|
+
if (!keepAlive &&
|
|
276
|
+
status.idle_since &&
|
|
277
|
+
now().getTime() - Date.parse(status.idle_since) >= idleExitMs) {
|
|
278
|
+
log(coordRoot, "supervisor.idle_exit", { idle_exit_ms: idleExitMs });
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
status.last_error_code = supervisorErrorCode(error);
|
|
284
|
+
status.state = "error";
|
|
285
|
+
log(coordRoot, "supervisor.sample_error", { reason_code: status.last_error_code }, error);
|
|
286
|
+
}
|
|
287
|
+
if (status.state === "error")
|
|
288
|
+
status.state = "running";
|
|
289
|
+
writeStatus();
|
|
290
|
+
if (input.maxCycles !== undefined && status.cycle_count >= input.maxCycles)
|
|
291
|
+
break;
|
|
292
|
+
const remaining = Math.max(0, intervalMs - (performance.now() - cycleStarted));
|
|
293
|
+
if (!stopping && !existsSync(paths.stop))
|
|
294
|
+
await wait(remaining);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
finally {
|
|
298
|
+
process.off("SIGINT", requestStop);
|
|
299
|
+
process.off("SIGTERM", requestStop);
|
|
300
|
+
status.state = "stopped";
|
|
301
|
+
status.stopped_at = now().toISOString();
|
|
302
|
+
status.idle_since = undefined;
|
|
303
|
+
writeStatus();
|
|
304
|
+
log(coordRoot, "supervisor.stopped", { cycle_count: status.cycle_count });
|
|
305
|
+
try {
|
|
306
|
+
await closeProcessLoggers();
|
|
307
|
+
}
|
|
308
|
+
finally {
|
|
309
|
+
releaseLease(paths.lease, lease.nonce);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return status;
|
|
313
|
+
}
|
|
314
|
+
function acquireLease(coordRoot, now) {
|
|
315
|
+
const paths = supervisorPaths(coordRoot);
|
|
316
|
+
mkdirSync(paths.root, { recursive: true, mode: 0o700 });
|
|
317
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
318
|
+
const startToken = processStartToken(process.pid);
|
|
319
|
+
const lease = {
|
|
320
|
+
pid: process.pid,
|
|
321
|
+
...(startToken ? { start_token: startToken } : {}),
|
|
322
|
+
host: hostname(),
|
|
323
|
+
nonce: randomUUID(),
|
|
324
|
+
created_at: now.toISOString(),
|
|
325
|
+
};
|
|
326
|
+
try {
|
|
327
|
+
const fd = openSync(paths.lease, "wx", 0o600);
|
|
328
|
+
try {
|
|
329
|
+
writeFileSync(fd, `${JSON.stringify(lease)}\n`, "utf8");
|
|
330
|
+
}
|
|
331
|
+
finally {
|
|
332
|
+
closeSync(fd);
|
|
333
|
+
}
|
|
334
|
+
return lease;
|
|
335
|
+
}
|
|
336
|
+
catch (error) {
|
|
337
|
+
if (error.code !== "EEXIST")
|
|
338
|
+
throw error;
|
|
339
|
+
const existing = readLease(paths.lease);
|
|
340
|
+
if (existing && leaseIsLive(existing)) {
|
|
341
|
+
throw new Error(`local supervisor lease is held by pid ${existing.pid}`);
|
|
342
|
+
}
|
|
343
|
+
try {
|
|
344
|
+
unlinkSync(paths.lease);
|
|
345
|
+
}
|
|
346
|
+
catch {
|
|
347
|
+
// A concurrent starter may have replaced or removed the stale lease.
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
throw new Error("local supervisor could not acquire its singleton lease");
|
|
352
|
+
}
|
|
353
|
+
function pruneProjectionDirectory(directory, retainedFindingIds) {
|
|
354
|
+
for (const file of readdirSync(directory)) {
|
|
355
|
+
if (!file.endsWith(".json"))
|
|
356
|
+
continue;
|
|
357
|
+
const findingId = file.slice(0, -5);
|
|
358
|
+
if (!retainedFindingIds.has(findingId))
|
|
359
|
+
rmSync(resolve(directory, file), { force: true });
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
function releaseLease(path, nonce) {
|
|
363
|
+
const current = readLease(path);
|
|
364
|
+
if (current?.nonce !== nonce)
|
|
365
|
+
return;
|
|
366
|
+
try {
|
|
367
|
+
unlinkSync(path);
|
|
368
|
+
}
|
|
369
|
+
catch {
|
|
370
|
+
// A missing lease is already released.
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
function readLease(path) {
|
|
374
|
+
try {
|
|
375
|
+
const value = JSON.parse(readFileSync(path, "utf8"));
|
|
376
|
+
return value && Number.isSafeInteger(value.pid) && typeof value.nonce === "string"
|
|
377
|
+
? value
|
|
378
|
+
: undefined;
|
|
379
|
+
}
|
|
380
|
+
catch {
|
|
381
|
+
return undefined;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
function leaseIsLive(lease) {
|
|
385
|
+
if (lease.host !== hostname())
|
|
386
|
+
return true;
|
|
387
|
+
try {
|
|
388
|
+
process.kill(lease.pid, 0);
|
|
389
|
+
}
|
|
390
|
+
catch (error) {
|
|
391
|
+
if (error.code !== "EPERM")
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
return checkPidToken(lease.pid, lease.start_token) !== "mismatch";
|
|
395
|
+
}
|
|
396
|
+
async function stopLegacyResourceObserver(coordRoot) {
|
|
397
|
+
const legacy = readResourceServiceStatus(coordRoot);
|
|
398
|
+
if (!legacy.running)
|
|
399
|
+
return;
|
|
400
|
+
requestResourceServiceStop(coordRoot);
|
|
401
|
+
const deadline = Date.now() + 2_000;
|
|
402
|
+
while (readResourceServiceStatus(coordRoot).running && Date.now() < deadline)
|
|
403
|
+
await delay(50);
|
|
404
|
+
}
|
|
405
|
+
function log(coordRoot, event, fields, error) {
|
|
406
|
+
try {
|
|
407
|
+
const logger = processLogger(coordRoot, "supervisor");
|
|
408
|
+
if (error)
|
|
409
|
+
logger.error(event, legacyLogFields(fields), error);
|
|
410
|
+
else
|
|
411
|
+
logger.info(event, legacyLogFields(fields));
|
|
412
|
+
}
|
|
413
|
+
catch {
|
|
414
|
+
// Observability must never break the supervisor loop.
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
function supervisorErrorCode(error) {
|
|
418
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
419
|
+
if (/procfs|\/proc\//i.test(message))
|
|
420
|
+
return "procfs_read_failed";
|
|
421
|
+
if (/permission|EACCES|EPERM/i.test(message))
|
|
422
|
+
return "permission_denied";
|
|
423
|
+
if (/log/i.test(message))
|
|
424
|
+
return "log_collection_failed";
|
|
425
|
+
return "collection_failed";
|
|
426
|
+
}
|
|
427
|
+
function normalizeInterval(value) {
|
|
428
|
+
const interval = value ?? SUPERVISOR_DEFAULT_INTERVAL_MS;
|
|
429
|
+
if (!Number.isFinite(interval) ||
|
|
430
|
+
interval < SUPERVISOR_MIN_INTERVAL_MS ||
|
|
431
|
+
interval > SUPERVISOR_MAX_INTERVAL_MS) {
|
|
432
|
+
throw new Error(`supervisor interval must be ${SUPERVISOR_MIN_INTERVAL_MS}-${SUPERVISOR_MAX_INTERVAL_MS} ms`);
|
|
433
|
+
}
|
|
434
|
+
return Math.round(interval);
|
|
435
|
+
}
|
|
436
|
+
function normalizeIdleExit(value) {
|
|
437
|
+
const idle = value ?? SUPERVISOR_DEFAULT_IDLE_EXIT_MS;
|
|
438
|
+
if (!Number.isFinite(idle) ||
|
|
439
|
+
idle < SUPERVISOR_MIN_IDLE_EXIT_MS ||
|
|
440
|
+
idle > SUPERVISOR_MAX_IDLE_EXIT_MS) {
|
|
441
|
+
throw new Error(`supervisor idle exit must be ${SUPERVISOR_MIN_IDLE_EXIT_MS}-${SUPERVISOR_MAX_IDLE_EXIT_MS} ms`);
|
|
442
|
+
}
|
|
443
|
+
return Math.round(idle);
|
|
444
|
+
}
|
|
445
|
+
function delay(milliseconds) {
|
|
446
|
+
return new Promise((resolveDelay) => setTimeout(resolveDelay, milliseconds));
|
|
447
|
+
}
|
|
448
|
+
function round1(value) {
|
|
449
|
+
return Math.round(value * 10) / 10;
|
|
450
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ObservedServiceHealth, type SupervisorConsumerRecord, type SupervisorServiceStatusRecord } from "./contract.js";
|
|
2
|
+
export declare function registerSupervisorConsumer(coordRoot: string, input: {
|
|
3
|
+
id: string;
|
|
4
|
+
pid?: number;
|
|
5
|
+
}): SupervisorConsumerRecord;
|
|
6
|
+
export declare function unregisterSupervisorConsumer(coordRoot: string, id: string): void;
|
|
7
|
+
export declare function collectServiceHealth(coordRoot: string, supervisor: SupervisorServiceStatusRecord): {
|
|
8
|
+
services: ObservedServiceHealth[];
|
|
9
|
+
consumers: SupervisorConsumerRecord[];
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=services.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../../../src/core/supervisor/services.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,qBAAqB,EAE1B,KAAK,wBAAwB,EAC7B,KAAK,6BAA6B,EACnC,MAAM,eAAe,CAAC;AAGvB,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAClC,wBAAwB,CAY1B;AAED,wBAAgB,4BAA4B,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAEhF;AAED,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,6BAA6B,GACxC;IAAE,QAAQ,EAAE,qBAAqB,EAAE,CAAC;IAAC,SAAS,EAAE,wBAAwB,EAAE,CAAA;CAAE,CAuC9E"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, rmSync, statSync } from "node:fs";
|
|
2
|
+
import { hostname } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { checkPidToken, processStartToken } from "../agents/state/proc-start.js";
|
|
5
|
+
import { writePrivateJsonAtomic } from "../storage/atomic-json.js";
|
|
6
|
+
import { SUPERVISOR_CONSUMER_SCHEMA_VERSION, } from "./contract.js";
|
|
7
|
+
import { readSupervisorConsumer, supervisorConsumerPath, supervisorPaths } from "./storage.js";
|
|
8
|
+
export function registerSupervisorConsumer(coordRoot, input) {
|
|
9
|
+
const pid = input.pid ?? process.pid;
|
|
10
|
+
const startToken = processStartToken(pid);
|
|
11
|
+
const record = {
|
|
12
|
+
schema_version: SUPERVISOR_CONSUMER_SCHEMA_VERSION,
|
|
13
|
+
id: input.id,
|
|
14
|
+
pid,
|
|
15
|
+
...(startToken ? { start_token: startToken } : {}),
|
|
16
|
+
registered_at: new Date().toISOString(),
|
|
17
|
+
};
|
|
18
|
+
writePrivateJsonAtomic(supervisorConsumerPath(coordRoot, input.id), record);
|
|
19
|
+
return record;
|
|
20
|
+
}
|
|
21
|
+
export function unregisterSupervisorConsumer(coordRoot, id) {
|
|
22
|
+
rmSync(supervisorConsumerPath(coordRoot, id), { force: true });
|
|
23
|
+
}
|
|
24
|
+
export function collectServiceHealth(coordRoot, supervisor) {
|
|
25
|
+
const consumers = readLiveConsumers(coordRoot);
|
|
26
|
+
const semantic = readDetachedService(join(coordRoot, ".harnery", "semantic", "v2", "service.json"), "semantic-reader");
|
|
27
|
+
const governor = readDetachedService(join(coordRoot, ".harnery", "governor-service", "service.json"), "governor");
|
|
28
|
+
const relay = readPresenceRelay(join(coordRoot, ".harnery", "presence", "relay-daemon.json"));
|
|
29
|
+
const dashboard = consumers.find((consumer) => consumer.id === "dashboard");
|
|
30
|
+
const services = [
|
|
31
|
+
{
|
|
32
|
+
id: "supervisor",
|
|
33
|
+
state: supervisor.state === "running"
|
|
34
|
+
? "running"
|
|
35
|
+
: supervisor.state === "error"
|
|
36
|
+
? "stale"
|
|
37
|
+
: "stopped",
|
|
38
|
+
pid: supervisor.pid,
|
|
39
|
+
started_at: supervisor.started_at,
|
|
40
|
+
heartbeat_at: supervisor.heartbeat_at,
|
|
41
|
+
...(supervisor.state === "error" ? { reason: "supervisor-reported-error" } : {}),
|
|
42
|
+
},
|
|
43
|
+
semantic,
|
|
44
|
+
governor,
|
|
45
|
+
relay,
|
|
46
|
+
dashboard
|
|
47
|
+
? {
|
|
48
|
+
id: "dashboard",
|
|
49
|
+
state: "running",
|
|
50
|
+
pid: dashboard.pid,
|
|
51
|
+
started_at: dashboard.registered_at,
|
|
52
|
+
}
|
|
53
|
+
: { id: "dashboard", state: "stopped" },
|
|
54
|
+
];
|
|
55
|
+
return { services, consumers };
|
|
56
|
+
}
|
|
57
|
+
function readLiveConsumers(coordRoot) {
|
|
58
|
+
const directory = supervisorPaths(coordRoot).consumers;
|
|
59
|
+
if (!existsSync(directory))
|
|
60
|
+
return [];
|
|
61
|
+
const live = [];
|
|
62
|
+
for (const entry of readdirSync(directory)) {
|
|
63
|
+
if (!entry.endsWith(".json"))
|
|
64
|
+
continue;
|
|
65
|
+
const path = `${directory}/${entry}`;
|
|
66
|
+
const record = readSupervisorConsumer(path);
|
|
67
|
+
if (!record || !consumerAlive(record)) {
|
|
68
|
+
rmSync(path, { force: true });
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
live.push(record);
|
|
72
|
+
}
|
|
73
|
+
return live.sort((left, right) => left.id.localeCompare(right.id));
|
|
74
|
+
}
|
|
75
|
+
function consumerAlive(record) {
|
|
76
|
+
if (record.schema_version !== SUPERVISOR_CONSUMER_SCHEMA_VERSION ||
|
|
77
|
+
!Number.isSafeInteger(record.pid) ||
|
|
78
|
+
record.pid < 1 ||
|
|
79
|
+
typeof record.id !== "string") {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
process.kill(record.pid, 0);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
if (error.code !== "EPERM")
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
return checkPidToken(record.pid, record.start_token) !== "mismatch";
|
|
90
|
+
}
|
|
91
|
+
function readDetachedService(path, id) {
|
|
92
|
+
const record = readBoundedJson(path);
|
|
93
|
+
if (!record || !Number.isSafeInteger(record.pid) || record.pid < 1) {
|
|
94
|
+
return { id, state: "stopped" };
|
|
95
|
+
}
|
|
96
|
+
if (record.state === "stopping" || record.state === "stopped") {
|
|
97
|
+
return projection(id, "stopped", record);
|
|
98
|
+
}
|
|
99
|
+
if (record.host && record.host !== hostname()) {
|
|
100
|
+
const age = record.heartbeat_at
|
|
101
|
+
? Date.now() - Date.parse(record.heartbeat_at)
|
|
102
|
+
: Number.POSITIVE_INFINITY;
|
|
103
|
+
const state = Number.isFinite(age) && age < 120_000 ? "running" : "stale";
|
|
104
|
+
return projection(id, state, record, state === "stale" ? "remote-heartbeat-expired" : undefined);
|
|
105
|
+
}
|
|
106
|
+
const state = pidAlive(record.pid) ? "running" : "stale";
|
|
107
|
+
return projection(id, state, record, state === "stale" ? "recorded-running-process-missing" : undefined);
|
|
108
|
+
}
|
|
109
|
+
function readPresenceRelay(path) {
|
|
110
|
+
const record = readBoundedJson(path);
|
|
111
|
+
if (!record || !Number.isSafeInteger(record.pid) || record.pid < 1) {
|
|
112
|
+
return { id: "presence-relay", state: "stopped" };
|
|
113
|
+
}
|
|
114
|
+
const running = pidAlive(record.pid);
|
|
115
|
+
return {
|
|
116
|
+
id: "presence-relay",
|
|
117
|
+
state: running ? "running" : "stale",
|
|
118
|
+
pid: record.pid,
|
|
119
|
+
...(record.started_at ? { started_at: record.started_at } : {}),
|
|
120
|
+
...(!running ? { reason: "recorded-running-process-missing" } : {}),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function projection(id, state, record, reason) {
|
|
124
|
+
return {
|
|
125
|
+
id,
|
|
126
|
+
state,
|
|
127
|
+
pid: record.pid,
|
|
128
|
+
...(record.started_at ? { started_at: record.started_at } : {}),
|
|
129
|
+
...(record.heartbeat_at ? { heartbeat_at: record.heartbeat_at } : {}),
|
|
130
|
+
...(reason ? { reason } : {}),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function readBoundedJson(path) {
|
|
134
|
+
if (!existsSync(path))
|
|
135
|
+
return undefined;
|
|
136
|
+
try {
|
|
137
|
+
const size = statSync(path).size;
|
|
138
|
+
if (size < 2 || size > 512 * 1_024)
|
|
139
|
+
return undefined;
|
|
140
|
+
const value = JSON.parse(readFileSync(path, "utf8"));
|
|
141
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function pidAlive(pid) {
|
|
148
|
+
try {
|
|
149
|
+
process.kill(pid, 0);
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
return error.code === "EPERM";
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../../src/core/supervisor/status.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,eAAe,CAAC;AAKvB,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,SAAa,GAAG,gBAAgB,CAyB5F"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { hostname } from "node:os";
|
|
2
|
+
import { checkPidToken } from "../agents/state/proc-start.js";
|
|
3
|
+
import { SUPERVISOR_STATUS_SCHEMA_VERSION, } from "./contract.js";
|
|
4
|
+
import { readSupervisorServiceRecord, supervisorPaths } from "./storage.js";
|
|
5
|
+
const STALE_HEARTBEAT_MS = 15_000;
|
|
6
|
+
export function readSupervisorStatus(coordRoot, nowMs = Date.now()) {
|
|
7
|
+
const paths = supervisorPaths(coordRoot);
|
|
8
|
+
const record = readSupervisorServiceRecord(coordRoot);
|
|
9
|
+
if (!validRecord(record)) {
|
|
10
|
+
return {
|
|
11
|
+
running: false,
|
|
12
|
+
stale: false,
|
|
13
|
+
status_path: paths.service,
|
|
14
|
+
snapshot_path: paths.snapshot,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const heartbeatAt = Date.parse(record.heartbeat_at);
|
|
18
|
+
const stale = !Number.isFinite(heartbeatAt) || nowMs - heartbeatAt > STALE_HEARTBEAT_MS;
|
|
19
|
+
const running = record.host === hostname() &&
|
|
20
|
+
!stale &&
|
|
21
|
+
(record.state === "starting" || record.state === "running" || record.state === "stopping") &&
|
|
22
|
+
pidStillMatches(record.pid, record.start_token);
|
|
23
|
+
return {
|
|
24
|
+
running,
|
|
25
|
+
stale,
|
|
26
|
+
record,
|
|
27
|
+
status_path: paths.service,
|
|
28
|
+
snapshot_path: paths.snapshot,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function validRecord(value) {
|
|
32
|
+
return (value?.schema_version === SUPERVISOR_STATUS_SCHEMA_VERSION &&
|
|
33
|
+
Number.isSafeInteger(value.pid) &&
|
|
34
|
+
value.pid > 0 &&
|
|
35
|
+
typeof value.host === "string" &&
|
|
36
|
+
typeof value.heartbeat_at === "string" &&
|
|
37
|
+
typeof value.keep_alive === "boolean");
|
|
38
|
+
}
|
|
39
|
+
function pidStillMatches(pid, startToken) {
|
|
40
|
+
try {
|
|
41
|
+
process.kill(pid, 0);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (error.code !== "EPERM")
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return checkPidToken(pid, startToken) !== "mismatch";
|
|
48
|
+
}
|