pi-better-server 0.4.0 → 0.6.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/package.json +8 -1
- package/scripts/copy-pi-test-providers.mjs +10 -0
- package/scripts/event-publication/README.md +26 -0
- package/scripts/event-publication/commit.mjs +21 -0
- package/scripts/event-publication/measure.mjs +87 -0
- package/scripts/event-publication/writer.mjs +6 -0
- package/scripts/measure-full-runtime/frontend.ts +24 -0
- package/scripts/measure-full-runtime/hosted-extension.ts +28 -0
- package/scripts/measure-full-runtime/probe.mjs +29 -0
- package/scripts/measure-full-runtime/recovery-trace-loader.mjs +51 -0
- package/scripts/measure-full-runtime/recovery-trace.mjs +16 -0
- package/scripts/measure-full-runtime.mjs +146 -0
- package/scripts/measure-shared-reads/probe.mjs +26 -2
- package/scripts/measure-shared-reads.mjs +44 -9
- package/scripts/private-runtime/package-lock.json +66 -4
- package/scripts/private-runtime/package.json +10 -2
- package/scripts/source-provenance.mjs +31 -0
- package/scripts/test-on-pi.sh +3 -9
- package/src/handshake.ts +1 -1
- package/src/hosted-session.ts +32 -4
- package/src/maintenance.ts +35 -7
- package/src/registry.ts +28 -4
- package/src/runtime/attempt-invalidation.ts +54 -0
- package/src/runtime/background-history.ts +151 -45
- package/src/runtime/background-policy.ts +27 -0
- package/src/runtime/background-tools.ts +389 -0
- package/src/runtime/background.ts +410 -48
- package/src/runtime/cancellation.ts +28 -7
- package/src/runtime/catalog-sources.ts +199 -0
- package/src/runtime/catalog.ts +53 -21
- package/src/runtime/client.ts +22 -2
- package/src/runtime/domain/assignment-inbox.mjs +119 -0
- package/src/runtime/domain/assignment-observation.d.mts +1 -1
- package/src/runtime/domain/assignment-observation.mjs +71 -33
- package/src/runtime/domain/background/process-identity.mjs +20 -2
- package/src/runtime/domain/background/process.mjs +3 -3
- package/src/runtime/domain/background/registry.mjs +89 -4
- package/src/runtime/domain/background/types.mjs +1 -0
- package/src/runtime/domain/background-service/adapter-contract.domain.mjs +83 -0
- package/src/runtime/domain/background-service/adapter-contract.ts +70 -0
- package/src/runtime/domain/background-service/batch.domain.mjs +91 -0
- package/src/runtime/domain/background-service/batch.ts +111 -0
- package/src/runtime/domain/background-service/conditions.domain.mjs +94 -0
- package/src/runtime/domain/background-service/conditions.ts +99 -0
- package/src/runtime/domain/background-service/delivery-observer.domain.mjs +37 -0
- package/src/runtime/domain/background-service/delivery-observer.ts +42 -0
- package/src/runtime/domain/background-service/failures.domain.mjs +209 -0
- package/src/runtime/domain/background-service/failures.ts +212 -0
- package/src/runtime/domain/background-service/goal-provider.domain.mjs +193 -0
- package/src/runtime/domain/background-service/goal-provider.ts +209 -0
- package/src/runtime/domain/background-service/index.domain.mjs +54 -0
- package/src/runtime/domain/background-service/index.ts +55 -0
- package/src/runtime/domain/background-service/logs.domain.mjs +129 -0
- package/src/runtime/domain/background-service/logs.ts +134 -0
- package/src/runtime/domain/background-service/maintenance.domain.mjs +95 -0
- package/src/runtime/domain/background-service/maintenance.ts +98 -0
- package/src/runtime/domain/background-service/managed-authority.domain.mjs +32 -0
- package/src/runtime/domain/background-service/managed-authority.ts +30 -0
- package/src/runtime/domain/background-service/managed-client.domain.mjs +79 -0
- package/src/runtime/domain/background-service/managed-client.ts +73 -0
- package/src/runtime/domain/background-service/managed-frontend.domain.mjs +225 -0
- package/src/runtime/domain/background-service/managed-frontend.ts +176 -0
- package/src/runtime/domain/background-service/navigator-provider.domain.mjs +492 -0
- package/src/runtime/domain/background-service/navigator-provider.ts +485 -0
- package/src/runtime/domain/background-service/observed-wait-client.domain.mjs +6 -0
- package/src/runtime/domain/background-service/observed-wait-client.ts +10 -0
- package/src/runtime/domain/background-service/observed-waits.domain.mjs +4080 -0
- package/src/runtime/domain/background-service/observed-waits.ts +4513 -0
- package/src/runtime/domain/background-service/output.domain.mjs +867 -0
- package/src/runtime/domain/background-service/output.ts +952 -0
- package/src/runtime/domain/background-service/process-identity.domain.mjs +129 -0
- package/src/runtime/domain/background-service/process-identity.ts +134 -0
- package/src/runtime/domain/background-service/process.domain.mjs +512 -0
- package/src/runtime/domain/background-service/process.ts +532 -0
- package/src/runtime/domain/background-service/prompt.domain.mjs +58 -0
- package/src/runtime/domain/background-service/prompt.ts +72 -0
- package/src/runtime/domain/background-service/registry.domain.mjs +460 -0
- package/src/runtime/domain/background-service/registry.ts +450 -0
- package/src/runtime/domain/background-service/remote-task-preset.domain.mjs +67 -0
- package/src/runtime/domain/background-service/remote-task-preset.ts +127 -0
- package/src/runtime/domain/background-service/runtime.domain.mjs +1511 -0
- package/src/runtime/domain/background-service/runtime.ts +1636 -0
- package/src/runtime/domain/background-service/sandbox.domain.mjs +735 -0
- package/src/runtime/domain/background-service/sandbox.ts +913 -0
- package/src/runtime/domain/background-service/shared-callback-batcher.domain.mjs +777 -0
- package/src/runtime/domain/background-service/shared-callback-batcher.ts +956 -0
- package/src/runtime/domain/background-service/shared-execution-policy.domain.mjs +50 -0
- package/src/runtime/domain/background-service/shared-execution-policy.ts +61 -0
- package/src/runtime/domain/background-service/shared-failure-observations.domain.mjs +1078 -0
- package/src/runtime/domain/background-service/shared-failure-observations.ts +1166 -0
- package/src/runtime/domain/background-service/shared-harness-settings.domain.mjs +126 -0
- package/src/runtime/domain/background-service/shared-harness-settings.ts +116 -0
- package/src/runtime/domain/background-service/shared-log-utils.domain.mjs +1223 -0
- package/src/runtime/domain/background-service/shared-log-utils.ts +1492 -0
- package/src/runtime/domain/background-service/shared-navigator-panels.domain.mjs +289 -0
- package/src/runtime/domain/background-service/shared-navigator-panels.ts +272 -0
- package/src/runtime/domain/background-service/shared-navigator.domain.mjs +1930 -0
- package/src/runtime/domain/background-service/shared-navigator.ts +1962 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-inbox.mjs +144 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-observation.mjs +189 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/index.domain.mjs +51 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/index.ts +122 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.ts +73 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +163 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.ts +174 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-parent-callbacks.domain.mjs +66 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-parent-callbacks.ts +68 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.domain.mjs +87 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.ts +90 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.domain.mjs +97 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.ts +139 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/errors.domain.mjs +12 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/errors.ts +79 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.domain.mjs +342 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.ts +513 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.domain.mjs +283 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.ts +458 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/recovery.domain.mjs +52 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/recovery.ts +55 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.domain.mjs +114 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.ts +140 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.domain.mjs +280 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.ts +442 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.domain.mjs +420 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.ts +441 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/sqlite.domain.mjs +194 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/sqlite.ts +239 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +275 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +585 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.domain.mjs +120 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.ts +142 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/task-cancellation.domain.mjs +188 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/task-cancellation.ts +224 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.domain.mjs +25 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.ts +707 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/upgrade.domain.mjs +22 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/upgrade.ts +22 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/validate.domain.mjs +234 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/validate.ts +241 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/waits.domain.mjs +851 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/waits.ts +1424 -0
- package/src/runtime/domain/background-service/shared-permission-blocker.domain.mjs +40 -0
- package/src/runtime/domain/background-service/shared-permission-blocker.ts +48 -0
- package/src/runtime/domain/background-service/shared-render-scheduler.domain.mjs +41 -0
- package/src/runtime/domain/background-service/shared-render-scheduler.ts +47 -0
- package/src/runtime/domain/background-service/shared-sandbox-core.domain.mjs +1531 -0
- package/src/runtime/domain/background-service/shared-sandbox-core.ts +1757 -0
- package/src/runtime/domain/background-service/shared-sandbox-diagnostics.domain.mjs +591 -0
- package/src/runtime/domain/background-service/shared-sandbox-diagnostics.ts +491 -0
- package/src/runtime/domain/background-service/shared-ssh-core/index.domain.mjs +698 -0
- package/src/runtime/domain/background-service/shared-ssh-core/index.ts +979 -0
- package/src/runtime/domain/background-service/shared-stall-detector.domain.mjs +37 -0
- package/src/runtime/domain/background-service/shared-stall-detector.ts +69 -0
- package/src/runtime/domain/background-service/shared-work-client.mjs +303 -0
- package/src/runtime/domain/background-service/stall-attention.domain.mjs +29 -0
- package/src/runtime/domain/background-service/stall-attention.ts +31 -0
- package/src/runtime/domain/background-service/stall.domain.mjs +57 -0
- package/src/runtime/domain/background-service/stall.ts +57 -0
- package/src/runtime/domain/background-service/supervisor/README.md +111 -0
- package/src/runtime/domain/background-service/supervisor/emit-runner.mjs +90 -0
- package/src/runtime/domain/background-service/supervisor/generated/conditions.mjs +96 -0
- package/src/runtime/domain/background-service/supervisor/generated/identity.mjs +95 -0
- package/src/runtime/domain/background-service/supervisor/generated/process-identity.mjs +131 -0
- package/src/runtime/domain/background-service/supervisor/generated/process.mjs +514 -0
- package/src/runtime/domain/background-service/supervisor/generated/runner.mjs +872 -0
- package/src/runtime/domain/background-service/supervisor/generated/store.mjs +609 -0
- package/src/runtime/domain/background-service/supervisor/generated/types.mjs +50 -0
- package/src/runtime/domain/background-service/supervisor/identity.domain.mjs +93 -0
- package/src/runtime/domain/background-service/supervisor/identity.ts +99 -0
- package/src/runtime/domain/background-service/supervisor/index.domain.mjs +22 -0
- package/src/runtime/domain/background-service/supervisor/index.ts +37 -0
- package/src/runtime/domain/background-service/supervisor/invocation.domain.mjs +30 -0
- package/src/runtime/domain/background-service/supervisor/invocation.ts +44 -0
- package/src/runtime/domain/background-service/supervisor/runner.domain.mjs +870 -0
- package/src/runtime/domain/background-service/supervisor/runner.ts +982 -0
- package/src/runtime/domain/background-service/supervisor/store.domain.mjs +605 -0
- package/src/runtime/domain/background-service/supervisor/store.ts +651 -0
- package/src/runtime/domain/background-service/supervisor/supervisor.domain.mjs +721 -0
- package/src/runtime/domain/background-service/supervisor/supervisor.ts +804 -0
- package/src/runtime/domain/background-service/supervisor/types.domain.mjs +48 -0
- package/src/runtime/domain/background-service/supervisor/types.ts +394 -0
- package/src/runtime/domain/background-service/task-diagnostics.domain.mjs +60 -0
- package/src/runtime/domain/background-service/task-diagnostics.ts +71 -0
- package/src/runtime/domain/background-service/tools.domain.mjs +1050 -0
- package/src/runtime/domain/background-service/tools.ts +1142 -0
- package/src/runtime/domain/background-service/types.domain.mjs +5 -0
- package/src/runtime/domain/background-service/types.ts +236 -0
- package/src/runtime/domain/background-service/work-observation.domain.mjs +176 -0
- package/src/runtime/domain/background-service/work-observation.ts +144 -0
- package/src/runtime/domain/catalog/catalog-store.d.mts +9 -1
- package/src/runtime/domain/catalog/catalog-store.mjs +20 -22
- package/src/runtime/domain/coordinator/src/assignment-changes.mjs +75 -0
- package/src/runtime/domain/coordinator/src/assignment-outcomes.mjs +2 -0
- package/src/runtime/domain/coordinator/src/background-parent-callbacks.mjs +65 -0
- package/src/runtime/domain/coordinator/src/background-requests.mjs +86 -0
- package/src/runtime/domain/coordinator/src/discovery.mjs +4 -2
- package/src/runtime/domain/coordinator/src/operations.mjs +44 -4
- package/src/runtime/domain/coordinator/src/result-supervision.mjs +12 -0
- package/src/runtime/domain/coordinator/src/rows.mjs +2 -0
- package/src/runtime/domain/coordinator/src/schema.mjs +73 -21
- package/src/runtime/domain/coordinator/src/store.mjs +32 -3
- package/src/runtime/domain/coordinator/src/subagent-launch.mjs +119 -0
- package/src/runtime/domain/coordinator/src/types.mjs +1 -1
- package/src/runtime/domain/coordinator/src/upgrade.mjs +22 -0
- package/src/runtime/domain/health-observation.d.mts +3 -1
- package/src/runtime/domain/health-observation.mjs +189 -190
- package/src/runtime/domain/log-cursor.d.mts +2 -0
- package/src/runtime/domain/log-cursor.mjs +85 -16
- package/src/runtime/domain/parse.d.mts +4 -1
- package/src/runtime/domain/parse.mjs +50 -5
- package/src/runtime/domain/sandbox-policy/README.md +633 -0
- package/src/runtime/domain/sandbox-policy/background-admission.domain.mjs +83 -0
- package/src/runtime/domain/sandbox-policy/background-admission.ts +75 -0
- package/src/runtime/domain/sandbox-policy/commands.domain.mjs +245 -0
- package/src/runtime/domain/sandbox-policy/commands.ts +336 -0
- package/src/runtime/domain/sandbox-policy/deny-rules.domain.mjs +440 -0
- package/src/runtime/domain/sandbox-policy/deny-rules.ts +620 -0
- package/src/runtime/domain/sandbox-policy/diagnostics-command.domain.mjs +30 -0
- package/src/runtime/domain/sandbox-policy/diagnostics-command.ts +27 -0
- package/src/runtime/domain/sandbox-policy/events.domain.mjs +49 -0
- package/src/runtime/domain/sandbox-policy/events.ts +85 -0
- package/src/runtime/domain/sandbox-policy/files.domain.mjs +153 -0
- package/src/runtime/domain/sandbox-policy/files.ts +224 -0
- package/src/runtime/domain/sandbox-policy/index.domain.mjs +289 -0
- package/src/runtime/domain/sandbox-policy/index.ts +386 -0
- package/src/runtime/domain/sandbox-policy/package.json +66 -0
- package/src/runtime/domain/sandbox-policy/permission-settings.domain.mjs +36 -0
- package/src/runtime/domain/sandbox-policy/permission-settings.ts +46 -0
- package/src/runtime/domain/sandbox-policy/permissions-page.domain.mjs +309 -0
- package/src/runtime/domain/sandbox-policy/permissions-page.ts +295 -0
- package/src/runtime/domain/sandbox-policy/permissions.domain.mjs +98 -0
- package/src/runtime/domain/sandbox-policy/permissions.ts +125 -0
- package/src/runtime/domain/sandbox-policy/policy.domain.mjs +80 -0
- package/src/runtime/domain/sandbox-policy/policy.ts +102 -0
- package/src/runtime/domain/sandbox-policy/preferences.domain.mjs +55 -0
- package/src/runtime/domain/sandbox-policy/preferences.ts +82 -0
- package/src/runtime/domain/sandbox-policy/rules-page.domain.mjs +138 -0
- package/src/runtime/domain/sandbox-policy/rules-page.ts +176 -0
- package/src/runtime/domain/sandbox-policy/session-permissions.domain.mjs +22 -0
- package/src/runtime/domain/sandbox-policy/session-permissions.ts +24 -0
- package/src/runtime/domain/sandbox-policy/shared-harness-settings.domain.mjs +126 -0
- package/src/runtime/domain/sandbox-policy/shared-harness-settings.ts +116 -0
- package/src/runtime/domain/sandbox-policy/shared-permission-blocker.domain.mjs +40 -0
- package/src/runtime/domain/sandbox-policy/shared-permission-blocker.ts +48 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-core.domain.mjs +1531 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-core.ts +1757 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-diagnostics.domain.mjs +591 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-diagnostics.ts +491 -0
- package/src/runtime/domain/sandbox-policy/shared-task-application.domain.mjs +185 -0
- package/src/runtime/domain/sandbox-policy/shared-task-application.ts +185 -0
- package/src/runtime/domain/sandbox-policy/shared-task-apply-patch.domain.mjs +416 -0
- package/src/runtime/domain/sandbox-policy/shared-task-apply-patch.ts +409 -0
- package/src/runtime/domain/sandbox-policy/shared-task-exec.domain.mjs +325 -0
- package/src/runtime/domain/sandbox-policy/shared-task-exec.ts +335 -0
- package/src/runtime/domain/sandbox-policy/shared-task-files.domain.mjs +346 -0
- package/src/runtime/domain/sandbox-policy/shared-task-files.ts +342 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-identity.domain.mjs +140 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-identity.ts +126 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-list.domain.mjs +220 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-list.ts +209 -0
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.domain.mjs +227 -0
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.ts +224 -0
- package/src/runtime/domain/sandbox-policy/shared-task-tools.domain.mjs +92 -0
- package/src/runtime/domain/sandbox-policy/shared-task-tools.ts +123 -0
- package/src/runtime/domain/sandbox-policy/shell.domain.mjs +93 -0
- package/src/runtime/domain/sandbox-policy/shell.ts +129 -0
- package/src/runtime/domain/sandbox-policy/state.domain.mjs +307 -0
- package/src/runtime/domain/sandbox-policy/state.ts +408 -0
- package/src/runtime/domain/sandbox-policy/status.domain.mjs +64 -0
- package/src/runtime/domain/sandbox-policy/status.ts +76 -0
- package/src/runtime/domain/sandbox-policy/subagent-admission.domain.mjs +69 -0
- package/src/runtime/domain/sandbox-policy/subagent-admission.ts +60 -0
- package/src/runtime/domain/subagents/CONTEXT.md +202 -0
- package/src/runtime/domain/subagents/PRODUCT.md +49 -0
- package/src/runtime/domain/subagents/README.md +201 -0
- package/src/runtime/domain/subagents/agent-catalog.mjs +64 -0
- package/src/runtime/domain/subagents/agent-commands.domain.mjs +822 -0
- package/src/runtime/domain/subagents/agent-commands.ts +905 -0
- package/src/runtime/domain/subagents/agent-inspection.domain.mjs +398 -0
- package/src/runtime/domain/subagents/agent-inspection.ts +574 -0
- package/src/runtime/domain/subagents/agent-operations.domain.mjs +40 -0
- package/src/runtime/domain/subagents/agent-operations.ts +61 -0
- package/src/runtime/domain/subagents/agent-session-settings.domain.mjs +112 -0
- package/src/runtime/domain/subagents/agent-session-settings.ts +118 -0
- package/src/runtime/domain/subagents/agents-catalog-tool.domain.mjs +84 -0
- package/src/runtime/domain/subagents/agents-catalog-tool.ts +118 -0
- package/src/runtime/domain/subagents/assignment-outcomes.domain.mjs +276 -0
- package/src/runtime/domain/subagents/assignment-outcomes.ts +212 -0
- package/src/runtime/domain/subagents/assignment-projection.mjs +261 -0
- package/src/runtime/domain/subagents/assignment-report.domain.mjs +174 -0
- package/src/runtime/domain/subagents/assignment-report.ts +156 -0
- package/src/runtime/domain/subagents/batch.mjs +275 -0
- package/src/runtime/domain/subagents/callback-fields.domain.mjs +72 -0
- package/src/runtime/domain/subagents/callback-fields.ts +95 -0
- package/src/runtime/domain/subagents/capacity.mjs +108 -0
- package/src/runtime/domain/subagents/catalog-editor.domain.mjs +98 -0
- package/src/runtime/domain/subagents/catalog-editor.ts +125 -0
- package/src/runtime/domain/subagents/catalog-host-admission.domain.mjs +104 -0
- package/src/runtime/domain/subagents/catalog-host-admission.ts +85 -0
- package/src/runtime/domain/subagents/catalog-identity.domain.mjs +222 -0
- package/src/runtime/domain/subagents/catalog-identity.ts +258 -0
- package/src/runtime/domain/subagents/catalog-overlay.domain.mjs +9 -0
- package/src/runtime/domain/subagents/catalog-overlay.ts +10 -0
- package/src/runtime/domain/subagents/catalog-preferences.domain.mjs +164 -0
- package/src/runtime/domain/subagents/catalog-preferences.ts +139 -0
- package/src/runtime/domain/subagents/catalog-resolver.domain.mjs +366 -0
- package/src/runtime/domain/subagents/catalog-resolver.ts +540 -0
- package/src/runtime/domain/subagents/catalog-runtime.domain.mjs +570 -0
- package/src/runtime/domain/subagents/catalog-runtime.ts +680 -0
- package/src/runtime/domain/subagents/catalog-schema.domain.mjs +1331 -0
- package/src/runtime/domain/subagents/catalog-schema.ts +1563 -0
- package/src/runtime/domain/subagents/catalog-skill-edits.domain.mjs +95 -0
- package/src/runtime/domain/subagents/catalog-skill-edits.ts +116 -0
- package/src/runtime/domain/subagents/catalog-store.domain.mjs +808 -0
- package/src/runtime/domain/subagents/catalog-store.ts +1006 -0
- package/src/runtime/domain/subagents/catalog-ui.domain.mjs +651 -0
- package/src/runtime/domain/subagents/catalog-ui.ts +611 -0
- package/src/runtime/domain/subagents/child-apply-patch.domain.mjs +13 -0
- package/src/runtime/domain/subagents/child-apply-patch.ts +13 -0
- package/src/runtime/domain/subagents/child-codemode.domain.mjs +16 -0
- package/src/runtime/domain/subagents/child-codemode.ts +17 -0
- package/src/runtime/domain/subagents/child-dependencies.mjs +193 -0
- package/src/runtime/domain/subagents/child-incidents.domain.mjs +170 -0
- package/src/runtime/domain/subagents/child-incidents.ts +169 -0
- package/src/runtime/domain/subagents/child-operations.domain.mjs +986 -0
- package/src/runtime/domain/subagents/child-operations.ts +1191 -0
- package/src/runtime/domain/subagents/child-ownership.domain.mjs +205 -0
- package/src/runtime/domain/subagents/child-ownership.ts +160 -0
- package/src/runtime/domain/subagents/child-preflight.mjs +38 -0
- package/src/runtime/domain/subagents/child-process-list.domain.mjs +7 -0
- package/src/runtime/domain/subagents/child-process-list.ts +8 -0
- package/src/runtime/domain/subagents/child-runtime.mjs +67 -0
- package/src/runtime/domain/subagents/child-steer.domain.mjs +109 -0
- package/src/runtime/domain/subagents/child-steer.ts +102 -0
- package/src/runtime/domain/subagents/cleanup.domain.mjs +818 -0
- package/src/runtime/domain/subagents/cleanup.ts +1017 -0
- package/src/runtime/domain/subagents/codex-import.domain.mjs +575 -0
- package/src/runtime/domain/subagents/codex-import.ts +717 -0
- package/src/runtime/domain/subagents/completion.domain.mjs +6 -0
- package/src/runtime/domain/subagents/completion.mjs +152 -0
- package/src/runtime/domain/subagents/completion.ts +11 -0
- package/src/runtime/domain/subagents/config.domain.mjs +248 -0
- package/src/runtime/domain/subagents/config.json +15 -0
- package/src/runtime/domain/subagents/config.ts +328 -0
- package/src/runtime/domain/subagents/continuation-authority.domain.mjs +38 -0
- package/src/runtime/domain/subagents/continuation-authority.ts +31 -0
- package/src/runtime/domain/subagents/continuation-runtime.domain.mjs +89 -0
- package/src/runtime/domain/subagents/continuation-runtime.ts +88 -0
- package/src/runtime/domain/subagents/continuation.domain.mjs +942 -0
- package/src/runtime/domain/subagents/continuation.ts +1051 -0
- package/src/runtime/domain/subagents/delegation.domain.mjs +19 -0
- package/src/runtime/domain/subagents/delegation.ts +24 -0
- package/src/runtime/domain/subagents/effective-settings.domain.mjs +130 -0
- package/src/runtime/domain/subagents/effective-settings.ts +184 -0
- package/src/runtime/domain/subagents/extensions.domain.mjs +6 -0
- package/src/runtime/domain/subagents/extensions.mjs +164 -0
- package/src/runtime/domain/subagents/extensions.ts +19 -0
- package/src/runtime/domain/subagents/failures.domain.mjs +362 -0
- package/src/runtime/domain/subagents/failures.ts +319 -0
- package/src/runtime/domain/subagents/finalization.domain.mjs +168 -0
- package/src/runtime/domain/subagents/finalization.ts +218 -0
- package/src/runtime/domain/subagents/git-remotes.domain.mjs +351 -0
- package/src/runtime/domain/subagents/git-remotes.ts +413 -0
- package/src/runtime/domain/subagents/git-workspace.domain.mjs +337 -0
- package/src/runtime/domain/subagents/git-workspace.ts +430 -0
- package/src/runtime/domain/subagents/goal-provider.domain.mjs +125 -0
- package/src/runtime/domain/subagents/goal-provider.ts +132 -0
- package/src/runtime/domain/subagents/health-observation.domain.mjs +617 -0
- package/src/runtime/domain/subagents/health-observation.ts +818 -0
- package/src/runtime/domain/subagents/health-surface.mjs +284 -0
- package/src/runtime/domain/subagents/health.domain.mjs +261 -0
- package/src/runtime/domain/subagents/health.ts +343 -0
- package/src/runtime/domain/subagents/historical-attention.domain.mjs +37 -0
- package/src/runtime/domain/subagents/historical-attention.ts +35 -0
- package/src/runtime/domain/subagents/incident-model.domain.mjs +322 -0
- package/src/runtime/domain/subagents/incident-model.ts +358 -0
- package/src/runtime/domain/subagents/index.domain.mjs +4731 -0
- package/src/runtime/domain/subagents/index.ts +4781 -0
- package/src/runtime/domain/subagents/launch-abort.domain.mjs +13 -0
- package/src/runtime/domain/subagents/launch-abort.ts +21 -0
- package/src/runtime/domain/subagents/launch-context.domain.mjs +24 -0
- package/src/runtime/domain/subagents/launch-context.ts +23 -0
- package/src/runtime/domain/subagents/launch-digest.mjs +6 -0
- package/src/runtime/domain/subagents/lifecycle.domain.mjs +265 -0
- package/src/runtime/domain/subagents/lifecycle.ts +360 -0
- package/src/runtime/domain/subagents/list.domain.mjs +2 -0
- package/src/runtime/domain/subagents/list.mjs +152 -0
- package/src/runtime/domain/subagents/list.ts +19 -0
- package/src/runtime/domain/subagents/log-cursor.domain.mjs +217 -0
- package/src/runtime/domain/subagents/log-cursor.ts +268 -0
- package/src/runtime/domain/subagents/managed-background-capability.domain.mjs +10 -0
- package/src/runtime/domain/subagents/managed-background-capability.ts +9 -0
- package/src/runtime/domain/subagents/managed-failure-worker.mjs +36 -0
- package/src/runtime/domain/subagents/managed-launch-bootstrap.mjs +48 -0
- package/src/runtime/domain/subagents/managed-launch-client.domain.mjs +75 -0
- package/src/runtime/domain/subagents/managed-launch-client.ts +59 -0
- package/src/runtime/domain/subagents/managed-launch-host.domain.mjs +627 -0
- package/src/runtime/domain/subagents/managed-launch-host.ts +504 -0
- package/src/runtime/domain/subagents/managed-launch-journal.mjs +17 -0
- package/src/runtime/domain/subagents/managed-launch-ownership.domain.mjs +29 -0
- package/src/runtime/domain/subagents/managed-launch-ownership.ts +22 -0
- package/src/runtime/domain/subagents/managed-launch-port.domain.mjs +2 -0
- package/src/runtime/domain/subagents/managed-launch-port.ts +25 -0
- package/src/runtime/domain/subagents/managed-launch-recovery.domain.mjs +29 -0
- package/src/runtime/domain/subagents/managed-launch-recovery.ts +45 -0
- package/src/runtime/domain/subagents/managed-worker-bridge.domain.mjs +63 -0
- package/src/runtime/domain/subagents/managed-worker-bridge.ts +48 -0
- package/src/runtime/domain/subagents/managed-worker.mjs +13 -0
- package/src/runtime/domain/subagents/model-resolution-core.domain.mjs +822 -0
- package/src/runtime/domain/subagents/model-resolution-core.ts +1074 -0
- package/src/runtime/domain/subagents/model-resolution.domain.mjs +22 -0
- package/src/runtime/domain/subagents/model-resolution.ts +32 -0
- package/src/runtime/domain/subagents/navigator.domain.mjs +6 -0
- package/src/runtime/domain/subagents/navigator.mjs +1233 -0
- package/src/runtime/domain/subagents/navigator.ts +39 -0
- package/src/runtime/domain/subagents/operation-bridge-types.domain.mjs +1012 -0
- package/src/runtime/domain/subagents/operation-bridge-types.ts +1156 -0
- package/src/runtime/domain/subagents/outage-observations.domain.mjs +84 -0
- package/src/runtime/domain/subagents/outage-observations.ts +73 -0
- package/src/runtime/domain/subagents/output-payload.domain.mjs +767 -0
- package/src/runtime/domain/subagents/output-payload.ts +987 -0
- package/src/runtime/domain/subagents/owned-exit.domain.mjs +12 -0
- package/src/runtime/domain/subagents/owned-exit.ts +12 -0
- package/src/runtime/domain/subagents/package.json +86 -0
- package/src/runtime/domain/subagents/park-checkpoint.domain.mjs +55 -0
- package/src/runtime/domain/subagents/park-checkpoint.ts +61 -0
- package/src/runtime/domain/subagents/parse.domain.mjs +1218 -0
- package/src/runtime/domain/subagents/parse.ts +1451 -0
- package/src/runtime/domain/subagents/permission-policy.domain.mjs +232 -0
- package/src/runtime/domain/subagents/permission-policy.ts +291 -0
- package/src/runtime/domain/subagents/process-identity.mjs +33 -0
- package/src/runtime/domain/subagents/registry.domain.mjs +1584 -0
- package/src/runtime/domain/subagents/registry.ts +1904 -0
- package/src/runtime/domain/subagents/role-assignment.domain.mjs +104 -0
- package/src/runtime/domain/subagents/role-assignment.ts +141 -0
- package/src/runtime/domain/subagents/roles/role.architect.md +13 -0
- package/src/runtime/domain/subagents/roles/role.developer.md +16 -0
- package/src/runtime/domain/subagents/roles/role.explorer.md +13 -0
- package/src/runtime/domain/subagents/roles/role.product-manager.md +13 -0
- package/src/runtime/domain/subagents/roles/role.researcher.md +13 -0
- package/src/runtime/domain/subagents/roles/role.reviewer.md +13 -0
- package/src/runtime/domain/subagents/roles/role.writer.md +12 -0
- package/src/runtime/domain/subagents/sandbox.domain.mjs +64 -0
- package/src/runtime/domain/subagents/sandbox.ts +92 -0
- package/src/runtime/domain/subagents/session-selection.domain.mjs +32 -0
- package/src/runtime/domain/subagents/session-selection.ts +35 -0
- package/src/runtime/domain/subagents/session-store.domain.mjs +489 -0
- package/src/runtime/domain/subagents/session-store.ts +468 -0
- package/src/runtime/domain/subagents/settings-page.domain.mjs +313 -0
- package/src/runtime/domain/subagents/settings-page.ts +363 -0
- package/src/runtime/domain/subagents/shared-callback-batcher.domain.mjs +777 -0
- package/src/runtime/domain/subagents/shared-callback-batcher.ts +956 -0
- package/src/runtime/domain/subagents/shared-catalog.domain.mjs +70 -0
- package/src/runtime/domain/subagents/shared-catalog.ts +61 -0
- package/src/runtime/domain/subagents/shared-execution-policy.domain.mjs +50 -0
- package/src/runtime/domain/subagents/shared-execution-policy.ts +61 -0
- package/src/runtime/domain/subagents/shared-failure-observations.domain.mjs +1078 -0
- package/src/runtime/domain/subagents/shared-failure-observations.ts +1166 -0
- package/src/runtime/domain/subagents/shared-harness-settings.domain.mjs +126 -0
- package/src/runtime/domain/subagents/shared-harness-settings.ts +116 -0
- package/src/runtime/domain/subagents/shared-log-utils.domain.mjs +1223 -0
- package/src/runtime/domain/subagents/shared-log-utils.ts +1492 -0
- package/src/runtime/domain/subagents/shared-navigator-panels.domain.mjs +289 -0
- package/src/runtime/domain/subagents/shared-navigator-panels.ts +272 -0
- package/src/runtime/domain/subagents/shared-navigator.domain.mjs +1930 -0
- package/src/runtime/domain/subagents/shared-navigator.ts +1962 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-inbox.mjs +144 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-observation.mjs +189 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/index.domain.mjs +51 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/index.ts +122 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.ts +73 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +163 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.ts +174 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-parent-callbacks.domain.mjs +66 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-parent-callbacks.ts +68 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.domain.mjs +87 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.ts +90 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.domain.mjs +97 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.ts +139 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/errors.domain.mjs +12 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/errors.ts +79 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.domain.mjs +342 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.ts +513 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.domain.mjs +283 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.ts +458 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/recovery.domain.mjs +52 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/recovery.ts +55 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.domain.mjs +114 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.ts +140 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.domain.mjs +280 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.ts +442 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.domain.mjs +420 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.ts +441 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/sqlite.domain.mjs +194 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/sqlite.ts +239 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +275 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +585 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.domain.mjs +120 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.ts +142 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-cancellation.domain.mjs +188 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-cancellation.ts +224 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.domain.mjs +25 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.ts +707 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/upgrade.domain.mjs +22 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/upgrade.ts +22 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/validate.domain.mjs +234 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/validate.ts +241 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/waits.domain.mjs +851 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/waits.ts +1424 -0
- package/src/runtime/domain/subagents/shared-permission-blocker.domain.mjs +40 -0
- package/src/runtime/domain/subagents/shared-permission-blocker.ts +48 -0
- package/src/runtime/domain/subagents/shared-render-scheduler.domain.mjs +41 -0
- package/src/runtime/domain/subagents/shared-render-scheduler.ts +47 -0
- package/src/runtime/domain/subagents/shared-sandbox-core.domain.mjs +1531 -0
- package/src/runtime/domain/subagents/shared-sandbox-core.ts +1757 -0
- package/src/runtime/domain/subagents/shared-sandbox-diagnostics.domain.mjs +591 -0
- package/src/runtime/domain/subagents/shared-sandbox-diagnostics.ts +491 -0
- package/src/runtime/domain/subagents/shared-stall-detector.domain.mjs +37 -0
- package/src/runtime/domain/subagents/shared-stall-detector.ts +69 -0
- package/src/runtime/domain/subagents/shared-task-application.domain.mjs +185 -0
- package/src/runtime/domain/subagents/shared-task-application.ts +185 -0
- package/src/runtime/domain/subagents/shared-task-apply-patch.domain.mjs +416 -0
- package/src/runtime/domain/subagents/shared-task-apply-patch.ts +409 -0
- package/src/runtime/domain/subagents/shared-task-exec.domain.mjs +325 -0
- package/src/runtime/domain/subagents/shared-task-exec.ts +335 -0
- package/src/runtime/domain/subagents/shared-task-files.domain.mjs +346 -0
- package/src/runtime/domain/subagents/shared-task-files.ts +342 -0
- package/src/runtime/domain/subagents/shared-task-process-identity.domain.mjs +140 -0
- package/src/runtime/domain/subagents/shared-task-process-identity.ts +126 -0
- package/src/runtime/domain/subagents/shared-task-process-list.domain.mjs +220 -0
- package/src/runtime/domain/subagents/shared-task-process-list.ts +209 -0
- package/src/runtime/domain/subagents/shared-task-sandbox.domain.mjs +227 -0
- package/src/runtime/domain/subagents/shared-task-sandbox.ts +224 -0
- package/src/runtime/domain/subagents/shared-task-tools.domain.mjs +92 -0
- package/src/runtime/domain/subagents/shared-task-tools.ts +123 -0
- package/src/runtime/domain/subagents/shared-work-client.mjs +303 -0
- package/src/runtime/domain/subagents/shared-worktree-context.domain.mjs +142 -0
- package/src/runtime/domain/subagents/shared-worktree-context.ts +158 -0
- package/src/runtime/domain/subagents/skill-picker.domain.mjs +316 -0
- package/src/runtime/domain/subagents/skill-picker.ts +353 -0
- package/src/runtime/domain/subagents/skills.domain.mjs +138 -0
- package/src/runtime/domain/subagents/skills.ts +183 -0
- package/src/runtime/domain/subagents/spawn.domain.mjs +72 -0
- package/src/runtime/domain/subagents/spawn.ts +80 -0
- package/src/runtime/domain/subagents/stop.domain.mjs +184 -0
- package/src/runtime/domain/subagents/stop.ts +217 -0
- package/src/runtime/domain/subagents/subagent-tools.domain.mjs +101 -0
- package/src/runtime/domain/subagents/subagent-tools.ts +137 -0
- package/src/runtime/domain/subagents/task-guard.domain.mjs +163 -0
- package/src/runtime/domain/subagents/task-guard.ts +144 -0
- package/src/runtime/domain/subagents/task-policy.domain.mjs +201 -0
- package/src/runtime/domain/subagents/task-policy.ts +236 -0
- package/src/runtime/domain/subagents/task-runtime.mjs +53 -0
- package/src/runtime/domain/subagents/task-tool-owner.domain.mjs +18 -0
- package/src/runtime/domain/subagents/task-tool-owner.ts +21 -0
- package/src/runtime/domain/subagents/thinking.domain.mjs +22 -0
- package/src/runtime/domain/subagents/thinking.ts +28 -0
- package/src/runtime/domain/subagents/tier-policy.domain.mjs +75 -0
- package/src/runtime/domain/subagents/tier-policy.ts +126 -0
- package/src/runtime/domain/subagents/timing-notifications.domain.mjs +51 -0
- package/src/runtime/domain/subagents/timing-notifications.ts +37 -0
- package/src/runtime/domain/subagents/timing.domain.mjs +487 -0
- package/src/runtime/domain/subagents/timing.ts +634 -0
- package/src/runtime/domain/subagents/tools.domain.mjs +558 -0
- package/src/runtime/domain/subagents/tools.ts +629 -0
- package/src/runtime/domain/subagents/widget.domain.mjs +6 -0
- package/src/runtime/domain/subagents/widget.mjs +246 -0
- package/src/runtime/domain/subagents/widget.ts +30 -0
- package/src/runtime/domain/subagents/work-observation.domain.mjs +316 -0
- package/src/runtime/domain/subagents/work-observation.ts +248 -0
- package/src/runtime/domain/subagents/worker-catalog.domain.mjs +120 -0
- package/src/runtime/domain/subagents/worker-catalog.ts +162 -0
- package/src/runtime/domain/subagents/worker-operations-host.domain.mjs +1009 -0
- package/src/runtime/domain/subagents/worker-operations-host.ts +1238 -0
- package/src/runtime/domain/subagents/worker-waits.domain.mjs +2336 -0
- package/src/runtime/domain/subagents/worker-waits.ts +2878 -0
- package/src/runtime/domain/subagents/workspace-scope.domain.mjs +52 -0
- package/src/runtime/domain/subagents/workspace-scope.ts +50 -0
- package/src/runtime/health-config.ts +27 -11
- package/src/runtime/log-checkpoints.ts +117 -0
- package/src/runtime/mutation-store.ts +5 -4
- package/src/runtime/queries.ts +27 -3
- package/src/runtime/query-executor.ts +178 -34
- package/src/runtime/query-worker.mjs +119 -22
- package/src/runtime/read-model.ts +939 -113
- package/src/runtime/read-watchdog-probe.ts +4 -0
- package/src/runtime/result-supervision.ts +188 -16
- package/src/runtime/source-watch.ts +175 -0
- package/src/runtime/subagent-launch.ts +73 -0
- package/src/runtime/work-budget.ts +130 -0
- package/src/runtime/work-client.d.mts +8 -0
- package/src/runtime/work-client.mjs +150 -7
- package/src/server.ts +185 -22
- package/src/session-activity.ts +26 -4
- package/src/version.ts +1 -1
|
@@ -0,0 +1,872 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-background-tasks/src/supervisor/generated/runner.mjs. Do not edit directly.
|
|
2
|
+
// Generated by src/supervisor/emit-runner.mjs from the TypeScript source.
|
|
3
|
+
// Do not edit: change the source and re-run the emitter (a drift test enforces this).
|
|
4
|
+
/**
|
|
5
|
+
* Detached local runner: one process or one command-watch loop, owned outside
|
|
6
|
+
* the caller's process group.
|
|
7
|
+
*
|
|
8
|
+
* This module is the source of the emitted executable. Node refuses to strip
|
|
9
|
+
* types for files under `node_modules`, so the shipped entrypoint is the
|
|
10
|
+
* JavaScript closure under `generated/` (see `emit-runner.mjs`); this file is
|
|
11
|
+
* what that closure is generated from and what tests and typechecking read.
|
|
12
|
+
*
|
|
13
|
+
* The runner:
|
|
14
|
+
*
|
|
15
|
+
* 1. re-reads and re-validates the immutable launch record,
|
|
16
|
+
* 2. durably claims the launch token under the cross-process state fence, so a
|
|
17
|
+
* claim and a `lost` attestation cannot interleave (a lost launch can never
|
|
18
|
+
* be executed late),
|
|
19
|
+
* 3. spawns the command in its own process group,
|
|
20
|
+
* 4. owns the per-command cap, the watch cadence and the whole-task deadline, and
|
|
21
|
+
* 5. publishes terminal evidence to `result.json` independently of the caller's
|
|
22
|
+
* lifetime.
|
|
23
|
+
*
|
|
24
|
+
* Signal authority is deliberately narrow:
|
|
25
|
+
* - the direct child is signalled through the retained `ChildProcess` handle
|
|
26
|
+
* while it has not exited (the handle is the identity), and only if a recorded
|
|
27
|
+
* start token that is still readable agrees;
|
|
28
|
+
* - the process group is signalled only inside a termination window, and the
|
|
29
|
+
* delayed escalation rechecks identity first;
|
|
30
|
+
* - a stop or timeout is not published until the group is proven empty (or the
|
|
31
|
+
* cleanup deadline discloses it as unproven).
|
|
32
|
+
*/
|
|
33
|
+
import { spawn } from "node:child_process";
|
|
34
|
+
import { closeSync, openSync, realpathSync } from "node:fs";
|
|
35
|
+
import { resolve } from "node:path";
|
|
36
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
37
|
+
import { fileURLToPath } from "node:url";
|
|
38
|
+
import { evaluateCondition, validateCondition } from "./conditions.mjs";
|
|
39
|
+
import { completeUtf8Length, stopProcessGroup, utf8PrefixLength } from "./process.mjs";
|
|
40
|
+
import { readProcessStartToken } from "./process-identity.mjs";
|
|
41
|
+
import { processGroupAlive } from "./identity.mjs";
|
|
42
|
+
import { appendEvent, appendStreamBytes, claimLaunch, ensureSupervisorTaskDir, readLaunchRecord, readStopRequest, writeCommandRecord, writeTerminalRecord, } from "./store.mjs";
|
|
43
|
+
import { DEFAULT_TERMINAL_TAIL_BYTES, DEFAULT_WATCH_INTERVAL_MS, SUPERVISOR_GROUP_CLEANUP_DEADLINE_MS, SUPERVISOR_POLL_MS, SUPERVISOR_RECORD_VERSION, SUPERVISOR_RUNNER_VERSION, SUPERVISOR_TERMINATION_GRACE_MS, } from "./types.mjs";
|
|
44
|
+
/** How long the runner waits for `close` after the child reported `exit`. */
|
|
45
|
+
const PIPE_CLOSE_GRACE_MS = 1_000;
|
|
46
|
+
function createCapture() {
|
|
47
|
+
return { chunks: [], stored: 0, discarded: 0, truncated: false };
|
|
48
|
+
}
|
|
49
|
+
/** Same bounded-capture rule as `runCommandOnce`: store a cap, count what was dropped. */
|
|
50
|
+
function captureChunk(target, chunk, maxBytes) {
|
|
51
|
+
if (target.truncated) {
|
|
52
|
+
target.discarded += chunk.length;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const room = maxBytes - target.stored;
|
|
56
|
+
if (chunk.length <= room) {
|
|
57
|
+
target.chunks.push(chunk);
|
|
58
|
+
target.stored += chunk.length;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const take = utf8PrefixLength(chunk, room);
|
|
62
|
+
if (take > 0) {
|
|
63
|
+
target.chunks.push(chunk.subarray(0, take));
|
|
64
|
+
target.stored += take;
|
|
65
|
+
}
|
|
66
|
+
target.discarded += chunk.length - take;
|
|
67
|
+
target.truncated = true;
|
|
68
|
+
}
|
|
69
|
+
function finishCapture(target) {
|
|
70
|
+
const stored = Buffer.concat(target.chunks, target.stored);
|
|
71
|
+
const keep = target.truncated ? completeUtf8Length(stored) : stored.length;
|
|
72
|
+
return {
|
|
73
|
+
text: stored.subarray(0, keep).toString("utf8"),
|
|
74
|
+
discardedBytes: target.discarded + (stored.length - keep),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function createStreamSink(path) {
|
|
78
|
+
return { path, bytes: 0, discardedBytes: 0, tail: [], tailBytes: 0 };
|
|
79
|
+
}
|
|
80
|
+
/** Last `maxBytes` bytes without starting mid-codepoint. */
|
|
81
|
+
function utf8Tail(buffer, maxBytes) {
|
|
82
|
+
if (buffer.length <= maxBytes)
|
|
83
|
+
return buffer;
|
|
84
|
+
let start = buffer.length - maxBytes;
|
|
85
|
+
while (start < buffer.length && (buffer[start] & 0xc0) === 0x80)
|
|
86
|
+
start += 1;
|
|
87
|
+
return buffer.subarray(start);
|
|
88
|
+
}
|
|
89
|
+
/** Last `maxBytes` bytes of a stream, as text. */
|
|
90
|
+
function sinkTailText(sink, maxBytes = DEFAULT_TERMINAL_TAIL_BYTES) {
|
|
91
|
+
return utf8Tail(Buffer.concat(sink.tail, sink.tailBytes), maxBytes).toString("utf8");
|
|
92
|
+
}
|
|
93
|
+
/** Last `maxBytes` bytes of captured text, so the durable record stays bounded. */
|
|
94
|
+
function tailText(text, maxBytes = DEFAULT_TERMINAL_TAIL_BYTES) {
|
|
95
|
+
const buffer = Buffer.from(text, "utf8");
|
|
96
|
+
return buffer.length <= maxBytes ? text : utf8Tail(buffer, maxBytes).toString("utf8");
|
|
97
|
+
}
|
|
98
|
+
/** Stream one chunk to its own log, capped per stream, keeping a bounded tail for evidence. */
|
|
99
|
+
function streamChunk(sink, chunk, maxBytes) {
|
|
100
|
+
if (chunk.length === 0)
|
|
101
|
+
return;
|
|
102
|
+
const room = maxBytes - sink.bytes;
|
|
103
|
+
const take = room <= 0 ? 0 : chunk.length <= room ? chunk.length : utf8PrefixLength(chunk, room);
|
|
104
|
+
if (take > 0) {
|
|
105
|
+
appendStreamBytes(sink.path, chunk.subarray(0, take));
|
|
106
|
+
sink.bytes += take;
|
|
107
|
+
}
|
|
108
|
+
sink.discardedBytes += chunk.length - take;
|
|
109
|
+
if (take === 0)
|
|
110
|
+
return;
|
|
111
|
+
sink.tail.push(chunk.subarray(0, take));
|
|
112
|
+
sink.tailBytes += take;
|
|
113
|
+
// Trim lazily so a chatty process does not recopy the tail on every chunk.
|
|
114
|
+
if (sink.tailBytes > DEFAULT_TERMINAL_TAIL_BYTES * 2) {
|
|
115
|
+
const keep = utf8Tail(Buffer.concat(sink.tail, sink.tailBytes), DEFAULT_TERMINAL_TAIL_BYTES);
|
|
116
|
+
sink.tail = [keep];
|
|
117
|
+
sink.tailBytes = keep.length;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function startToken(pid) {
|
|
121
|
+
return pid === undefined ? undefined : readProcessStartToken(pid);
|
|
122
|
+
}
|
|
123
|
+
function capReason(seconds) {
|
|
124
|
+
return `timeout: the Background tasks command time limit of ${seconds}s was reached`;
|
|
125
|
+
}
|
|
126
|
+
function oneLine(text) {
|
|
127
|
+
return text.replace(/\s+/g, " ").trim();
|
|
128
|
+
}
|
|
129
|
+
function openStreams(directory, taskId) {
|
|
130
|
+
const paths = ensureSupervisorTaskDir(directory, taskId);
|
|
131
|
+
// Create the evidence files up front: a consumer that sees a terminal record
|
|
132
|
+
// may read them, and a command that wrote nothing still has empty logs.
|
|
133
|
+
for (const path of [paths.stdout, paths.stderr, paths.events]) {
|
|
134
|
+
try {
|
|
135
|
+
closeSync(openSync(path, "a", 0o600));
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
// An unwritable log is reported through the terminal record, not a crash.
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
paths,
|
|
143
|
+
stdout: createStreamSink(paths.stdout),
|
|
144
|
+
stderr: createStreamSink(paths.stderr),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/** True when a stop was requested, by the durable request file or by a signal to this runner. */
|
|
148
|
+
function observeStop(ctx) {
|
|
149
|
+
if (ctx.stopRequested)
|
|
150
|
+
return true;
|
|
151
|
+
const request = readStopRequest(ctx.directory, ctx.taskId);
|
|
152
|
+
if (!request)
|
|
153
|
+
return false;
|
|
154
|
+
ctx.stopRequested = true;
|
|
155
|
+
appendEvent(ctx.paths.events, `stop request observed requested_at=${request.requestedAt}${request.reason ? ` reason=${oneLine(request.reason)}` : ""}`);
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Run one command under termination and cleanup control.
|
|
160
|
+
*
|
|
161
|
+
* The resolved outcome always carries the cleanup verdict, so a caller can only
|
|
162
|
+
* publish a stop/timeout after the process group was killed and proven empty
|
|
163
|
+
* (or the cleanup deadline disclosed it as unproven).
|
|
164
|
+
*/
|
|
165
|
+
function runChild(ctx, plan) {
|
|
166
|
+
return new Promise((resolveOutcome) => {
|
|
167
|
+
const stdoutCapture = createCapture();
|
|
168
|
+
const stderrCapture = createCapture();
|
|
169
|
+
const startedAt = Date.now();
|
|
170
|
+
let child;
|
|
171
|
+
try {
|
|
172
|
+
child = spawn(plan.argv[0], plan.argv.slice(1), {
|
|
173
|
+
cwd: plan.cwd,
|
|
174
|
+
env: process.env,
|
|
175
|
+
detached: true,
|
|
176
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
177
|
+
windowsHide: process.platform === "win32",
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
182
|
+
resolveOutcome({
|
|
183
|
+
startedAt,
|
|
184
|
+
endedAt: Date.now(),
|
|
185
|
+
exitCode: null,
|
|
186
|
+
exitSignal: null,
|
|
187
|
+
timedOut: false,
|
|
188
|
+
cancelled: false,
|
|
189
|
+
cleanup: "none",
|
|
190
|
+
spawnError: message,
|
|
191
|
+
stdout: "",
|
|
192
|
+
stderr: message,
|
|
193
|
+
stdoutDiscardedBytes: 0,
|
|
194
|
+
stderrDiscardedBytes: 0,
|
|
195
|
+
});
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const pid = child.pid;
|
|
199
|
+
const pgid = pid;
|
|
200
|
+
const ownedStartToken = startToken(pid);
|
|
201
|
+
if (pid !== undefined) {
|
|
202
|
+
plan.onSpawn?.({ pid, pgid, pidStartTime: ownedStartToken });
|
|
203
|
+
}
|
|
204
|
+
let termination;
|
|
205
|
+
let cleanup = "none";
|
|
206
|
+
let exited = false;
|
|
207
|
+
let captureClosed = false;
|
|
208
|
+
let exitCode = null;
|
|
209
|
+
let exitSignal = null;
|
|
210
|
+
let spawnError;
|
|
211
|
+
let settled = false;
|
|
212
|
+
const timers = [];
|
|
213
|
+
let groupPoll;
|
|
214
|
+
let stopPoll;
|
|
215
|
+
/** First time the group looked empty; two spaced observations are required. */
|
|
216
|
+
let firstEmptyAt;
|
|
217
|
+
/**
|
|
218
|
+
* Set once the runner can no longer prove the numeric pgid still names its
|
|
219
|
+
* group. A pgid is addressable evidence only while the group's leader is
|
|
220
|
+
* owned and verified; after that a recycled id is indistinguishable, so the
|
|
221
|
+
* cleanup is reported unproven and no further group signal is sent.
|
|
222
|
+
*/
|
|
223
|
+
let identityUnproven = false;
|
|
224
|
+
const arm = (ms, fn) => {
|
|
225
|
+
// Kept referenced: after the child exits, these timers are what keep the
|
|
226
|
+
// runner alive long enough to finish group cleanup and publish evidence.
|
|
227
|
+
const timer = setTimeout(fn, Math.max(1, ms));
|
|
228
|
+
timers.push(timer);
|
|
229
|
+
return timer;
|
|
230
|
+
};
|
|
231
|
+
const clearTimers = () => {
|
|
232
|
+
for (const timer of timers)
|
|
233
|
+
clearTimeout(timer);
|
|
234
|
+
if (groupPoll)
|
|
235
|
+
clearTimeout(groupPoll);
|
|
236
|
+
if (stopPoll)
|
|
237
|
+
clearInterval(stopPoll);
|
|
238
|
+
};
|
|
239
|
+
/** The handle is the identity: only a child that has not exited is ours to signal. */
|
|
240
|
+
const ownsDirect = () => child.exitCode === null && child.signalCode === null;
|
|
241
|
+
/** A recorded token must not disagree with the live process. */
|
|
242
|
+
const tokenAgrees = () => {
|
|
243
|
+
if (pid === undefined || ownedStartToken === undefined)
|
|
244
|
+
return true;
|
|
245
|
+
const current = readProcessStartToken(pid);
|
|
246
|
+
return current === undefined || current === ownedStartToken;
|
|
247
|
+
};
|
|
248
|
+
const signalDirect = (signal) => {
|
|
249
|
+
if (!ownsDirect() || !tokenAgrees())
|
|
250
|
+
return false;
|
|
251
|
+
try {
|
|
252
|
+
child.kill(signal);
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
/** Stop addressing the numeric pgid; the cleanup will be reported unproven. */
|
|
260
|
+
const markGroupUnproven = () => {
|
|
261
|
+
identityUnproven = true;
|
|
262
|
+
if (termination !== undefined && cleanup === "pending") {
|
|
263
|
+
cleanup = "unproven";
|
|
264
|
+
tryPublish();
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* A group signal is authorized only while the leader is still owned by the
|
|
269
|
+
* retained handle and its recorded start token agrees. The leader is then a
|
|
270
|
+
* live member of the group, so the pgid cannot have been recycled. Once it
|
|
271
|
+
* exits, no surviving member's identity can be proven from here, so the
|
|
272
|
+
* runner refuses the group signal instead of risking a foreign group.
|
|
273
|
+
*/
|
|
274
|
+
const signalGroup = (signal) => {
|
|
275
|
+
if (pid === undefined || !ownsDirect() || !tokenAgrees()) {
|
|
276
|
+
markGroupUnproven();
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
if (!processGroupAlive(pid))
|
|
280
|
+
return false;
|
|
281
|
+
try {
|
|
282
|
+
stopProcessGroup(pid, pid, signal);
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
const pollGroupUntilEmpty = () => {
|
|
290
|
+
if (settled || cleanup !== "pending")
|
|
291
|
+
return;
|
|
292
|
+
if (process.platform === "win32") {
|
|
293
|
+
// `taskkill /T /F` removes the tree; there is no group identity to poll.
|
|
294
|
+
cleanup = "taskkill";
|
|
295
|
+
tryPublish();
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const observedAt = Date.now();
|
|
299
|
+
const alive = pid !== undefined && processGroupAlive(pid);
|
|
300
|
+
if (!alive) {
|
|
301
|
+
// One empty observation can be a transient (the group is reserved while a
|
|
302
|
+
// member is alive, so a single miss is not proof). Require it to hold
|
|
303
|
+
// across a short window before reporting the group empty.
|
|
304
|
+
firstEmptyAt ??= observedAt;
|
|
305
|
+
if (observedAt - firstEmptyAt < 50) {
|
|
306
|
+
groupPoll = setTimeout(pollGroupUntilEmpty, 25);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
// Empty is only "cleanup proven" when identity was never lost; after the
|
|
310
|
+
// leader exited the emptiness was not established by a proven cleanup.
|
|
311
|
+
cleanup = identityUnproven ? "unproven" : "empty";
|
|
312
|
+
tryPublish();
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
firstEmptyAt = undefined;
|
|
316
|
+
if (!(ownsDirect() && tokenAgrees())) {
|
|
317
|
+
// The leader is gone and the group still has members. Do not signal a
|
|
318
|
+
// pgid we cannot prove, and do not claim the cleanup.
|
|
319
|
+
markGroupUnproven();
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (observedAt >= (termination?.startedAt ?? 0) + SUPERVISOR_GROUP_CLEANUP_DEADLINE_MS) {
|
|
323
|
+
cleanup = "unproven";
|
|
324
|
+
tryPublish();
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
groupPoll = setTimeout(pollGroupUntilEmpty, 25);
|
|
328
|
+
};
|
|
329
|
+
const requestTermination = (reason, kind) => {
|
|
330
|
+
if (termination !== undefined || settled)
|
|
331
|
+
return;
|
|
332
|
+
termination = { reason, kind, startedAt: Date.now() };
|
|
333
|
+
cleanup = "pending";
|
|
334
|
+
signalDirect("SIGTERM");
|
|
335
|
+
signalGroup("SIGTERM");
|
|
336
|
+
// Watch for an early, cooperative exit from the first millisecond; the
|
|
337
|
+
// group is only reported empty once it truly is.
|
|
338
|
+
pollGroupUntilEmpty();
|
|
339
|
+
// Keep the escalation independent of the child's own exit: a TERM-resistant
|
|
340
|
+
// descendant must still be killed after the direct child is gone.
|
|
341
|
+
arm(SUPERVISOR_TERMINATION_GRACE_MS, () => {
|
|
342
|
+
// Direct-child signals are authorized by the retained handle. The group
|
|
343
|
+
// signal is authorized only while that leader is still owned.
|
|
344
|
+
// Signal the verified group before killing its identity anchor. Killing
|
|
345
|
+
// the leader first lets the kernel reap it before group authorization.
|
|
346
|
+
signalGroup("SIGKILL");
|
|
347
|
+
signalDirect("SIGKILL");
|
|
348
|
+
});
|
|
349
|
+
// Hard bound: never leave the caller waiting on a process the kernel keeps
|
|
350
|
+
// alive; disclose cleanup as unproven instead.
|
|
351
|
+
arm(SUPERVISOR_GROUP_CLEANUP_DEADLINE_MS + PIPE_CLOSE_GRACE_MS, () => {
|
|
352
|
+
if (cleanup === "pending")
|
|
353
|
+
cleanup = "unproven";
|
|
354
|
+
if (!exited) {
|
|
355
|
+
exited = true;
|
|
356
|
+
captureClosed = true;
|
|
357
|
+
}
|
|
358
|
+
tryPublish();
|
|
359
|
+
});
|
|
360
|
+
if (process.platform === "win32")
|
|
361
|
+
cleanup = "taskkill";
|
|
362
|
+
};
|
|
363
|
+
const tryPublish = () => {
|
|
364
|
+
if (settled)
|
|
365
|
+
return;
|
|
366
|
+
if (!exited || !captureClosed)
|
|
367
|
+
return;
|
|
368
|
+
if (termination !== undefined && cleanup === "pending")
|
|
369
|
+
return;
|
|
370
|
+
settled = true;
|
|
371
|
+
clearTimers();
|
|
372
|
+
ctx.cancelActive = undefined;
|
|
373
|
+
const stdout = finishCapture(stdoutCapture);
|
|
374
|
+
const stderr = finishCapture(stderrCapture);
|
|
375
|
+
resolveOutcome({
|
|
376
|
+
startedAt,
|
|
377
|
+
endedAt: Date.now(),
|
|
378
|
+
exitCode,
|
|
379
|
+
exitSignal,
|
|
380
|
+
timedOut: termination?.reason === "timeout",
|
|
381
|
+
cancelled: termination?.reason === "stop",
|
|
382
|
+
cleanup: cleanup,
|
|
383
|
+
...(spawnError === undefined ? {} : { spawnError }),
|
|
384
|
+
stdout: stdout.text,
|
|
385
|
+
stderr: stderr.text,
|
|
386
|
+
stdoutDiscardedBytes: stdout.discardedBytes,
|
|
387
|
+
stderrDiscardedBytes: stderr.discardedBytes,
|
|
388
|
+
});
|
|
389
|
+
};
|
|
390
|
+
child.stdout?.on("data", (chunk) => {
|
|
391
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
392
|
+
if (plan.mode === "stream")
|
|
393
|
+
streamChunk(ctx.stdout, buffer, plan.maxBytes);
|
|
394
|
+
else
|
|
395
|
+
captureChunk(stdoutCapture, buffer, plan.maxBytes);
|
|
396
|
+
});
|
|
397
|
+
child.stderr?.on("data", (chunk) => {
|
|
398
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
399
|
+
if (plan.mode === "stream")
|
|
400
|
+
streamChunk(ctx.stderr, buffer, plan.maxBytes);
|
|
401
|
+
else
|
|
402
|
+
captureChunk(stderrCapture, buffer, plan.maxBytes);
|
|
403
|
+
});
|
|
404
|
+
child.on("error", (error) => {
|
|
405
|
+
spawnError = error.message;
|
|
406
|
+
if (plan.mode !== "stream") {
|
|
407
|
+
captureChunk(stderrCapture, Buffer.from(`\n--- spawn error: ${error.message} ---\n`), plan.maxBytes);
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
appendEvent(ctx.paths.events, `spawn error: ${oneLine(error.message)}`);
|
|
411
|
+
}
|
|
412
|
+
exited = true;
|
|
413
|
+
captureClosed = true;
|
|
414
|
+
tryPublish();
|
|
415
|
+
});
|
|
416
|
+
child.on("exit", (code, signal) => {
|
|
417
|
+
exited = true;
|
|
418
|
+
exitCode = code;
|
|
419
|
+
exitSignal = signal;
|
|
420
|
+
// `close` waits for the pipes; a surviving grandchild can hold them past the exit.
|
|
421
|
+
arm(PIPE_CLOSE_GRACE_MS, () => {
|
|
422
|
+
captureClosed = true;
|
|
423
|
+
tryPublish();
|
|
424
|
+
});
|
|
425
|
+
tryPublish();
|
|
426
|
+
});
|
|
427
|
+
child.on("close", (code, signal) => {
|
|
428
|
+
exited = true;
|
|
429
|
+
captureClosed = true;
|
|
430
|
+
exitCode ??= code;
|
|
431
|
+
exitSignal ??= signal;
|
|
432
|
+
tryPublish();
|
|
433
|
+
});
|
|
434
|
+
stopPoll = setInterval(() => {
|
|
435
|
+
if (!observeStop(ctx))
|
|
436
|
+
return;
|
|
437
|
+
requestTermination("stop", "task");
|
|
438
|
+
}, SUPERVISOR_POLL_MS);
|
|
439
|
+
ctx.cancelActive = () => requestTermination("stop", "task");
|
|
440
|
+
if (plan.killAt !== undefined) {
|
|
441
|
+
arm(plan.killAt - Date.now(), () => {
|
|
442
|
+
appendEvent(ctx.paths.events, plan.killKind === "cap" ? "command time limit reached" : "task deadline reached");
|
|
443
|
+
requestTermination("timeout", plan.killKind);
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
function finalize(ctx, terminal) {
|
|
449
|
+
if (ctx.finalized)
|
|
450
|
+
return;
|
|
451
|
+
ctx.finalized = true;
|
|
452
|
+
ctx.cancelActive = undefined;
|
|
453
|
+
const record = {
|
|
454
|
+
version: SUPERVISOR_RECORD_VERSION,
|
|
455
|
+
taskId: ctx.taskId,
|
|
456
|
+
token: ctx.launch.token,
|
|
457
|
+
kind: ctx.launch.kind,
|
|
458
|
+
status: terminal.status,
|
|
459
|
+
attestedBy: "runner",
|
|
460
|
+
reason: terminal.reason,
|
|
461
|
+
exitCode: terminal.exitCode,
|
|
462
|
+
signal: terminal.signal,
|
|
463
|
+
timedOut: terminal.timedOut,
|
|
464
|
+
startedAt: ctx.startedAt,
|
|
465
|
+
endedAt: Date.now(),
|
|
466
|
+
...(ctx.launch.kind === "watch" ? { checks: ctx.checks } : {}),
|
|
467
|
+
...(terminal.matchedCondition === undefined ? {} : { matchedCondition: terminal.matchedCondition }),
|
|
468
|
+
...(terminal.matchedValue === undefined ? {} : { matchedValue: terminal.matchedValue }),
|
|
469
|
+
...(terminal.lastCheck === undefined ? {} : { lastCheck: terminal.lastCheck }),
|
|
470
|
+
...(terminal.lastOutput === undefined ? {} : { lastOutput: terminal.lastOutput }),
|
|
471
|
+
...(terminal.groupCleanup === undefined ? {} : { groupCleanup: terminal.groupCleanup }),
|
|
472
|
+
stdoutBytes: ctx.stdout.bytes,
|
|
473
|
+
stderrBytes: ctx.stderr.bytes,
|
|
474
|
+
stdoutDiscardedBytes: ctx.stdout.discardedBytes,
|
|
475
|
+
stderrDiscardedBytes: ctx.stderr.discardedBytes,
|
|
476
|
+
logs: { stdout: ctx.paths.stdout, stderr: ctx.paths.stderr, events: ctx.paths.events },
|
|
477
|
+
runner: { pid: ctx.runnerPid, pidStartTime: ctx.runnerPidStartTime },
|
|
478
|
+
...(ctx.command === undefined
|
|
479
|
+
? {}
|
|
480
|
+
: { command: { pid: ctx.command.pid, pgid: ctx.command.pgid, pidStartTime: ctx.command.pidStartTime } }),
|
|
481
|
+
...(terminal.error === undefined ? {} : { error: terminal.error }),
|
|
482
|
+
};
|
|
483
|
+
// The event line goes first: a reader that sees a terminal record can rely on
|
|
484
|
+
// the lifecycle trace already being present.
|
|
485
|
+
appendEvent(ctx.paths.events, `terminal status=${record.status} attested_by=runner reason=${oneLine(record.reason)} exit=${record.exitCode ?? "null"} `
|
|
486
|
+
+ `signal=${record.signal ?? "null"} timed_out=${record.timedOut}`
|
|
487
|
+
+ `${record.groupCleanup === undefined ? "" : ` group_cleanup=${record.groupCleanup}`}`
|
|
488
|
+
+ `${ctx.launch.kind === "watch" ? ` checks=${ctx.checks}` : ""}`);
|
|
489
|
+
const written = writeTerminalRecord(ctx.directory, record);
|
|
490
|
+
if (!written) {
|
|
491
|
+
appendEvent(ctx.paths.events, "a terminal record already existed; it was not overwritten");
|
|
492
|
+
}
|
|
493
|
+
process.exit(0);
|
|
494
|
+
}
|
|
495
|
+
function cancelledTerminal(reason, cleanup, lastCheck) {
|
|
496
|
+
return {
|
|
497
|
+
status: "cancelled",
|
|
498
|
+
reason,
|
|
499
|
+
exitCode: lastCheck?.exitCode ?? null,
|
|
500
|
+
signal: lastCheck?.signal ?? null,
|
|
501
|
+
timedOut: false,
|
|
502
|
+
groupCleanup: cleanup,
|
|
503
|
+
...(lastCheck ? { lastCheck } : {}),
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
function asCommandResult(outcome) {
|
|
507
|
+
return {
|
|
508
|
+
exitCode: outcome.exitCode,
|
|
509
|
+
signal: outcome.exitSignal,
|
|
510
|
+
stdout: outcome.stdout,
|
|
511
|
+
stderr: outcome.stderr,
|
|
512
|
+
startedAt: outcome.startedAt,
|
|
513
|
+
endedAt: outcome.endedAt,
|
|
514
|
+
...(outcome.timedOut ? { timedOut: true } : {}),
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
function evidenceOf(outcome, matched) {
|
|
518
|
+
return {
|
|
519
|
+
startedAt: outcome.startedAt,
|
|
520
|
+
endedAt: outcome.endedAt,
|
|
521
|
+
durationMs: Math.max(0, outcome.endedAt - outcome.startedAt),
|
|
522
|
+
exitCode: outcome.exitCode,
|
|
523
|
+
signal: outcome.exitSignal === null ? null : String(outcome.exitSignal),
|
|
524
|
+
...(outcome.timedOut ? { timedOut: true } : {}),
|
|
525
|
+
stdout: tailText(outcome.stdout),
|
|
526
|
+
stderr: tailText(outcome.stderr),
|
|
527
|
+
...(outcome.stdoutDiscardedBytes > 0 ? { stdoutDiscardedBytes: outcome.stdoutDiscardedBytes } : {}),
|
|
528
|
+
...(outcome.stderrDiscardedBytes > 0 ? { stderrDiscardedBytes: outcome.stderrDiscardedBytes } : {}),
|
|
529
|
+
...(matched?.condition === undefined ? {} : { matchedCondition: matched.condition }),
|
|
530
|
+
...(matched?.value === undefined ? {} : { matchedValue: matched.value }),
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
function nextCheckDelay(intervalMs, deadlineAt) {
|
|
534
|
+
if (deadlineAt === undefined)
|
|
535
|
+
return intervalMs;
|
|
536
|
+
return Math.max(0, Math.min(intervalMs, deadlineAt - Date.now()));
|
|
537
|
+
}
|
|
538
|
+
/** Wait out the cadence, staying responsive to a stop request. True means stop. */
|
|
539
|
+
async function waitForNextCheck(ctx, delayMs) {
|
|
540
|
+
const until = Date.now() + delayMs;
|
|
541
|
+
while (!ctx.finalized) {
|
|
542
|
+
if (observeStop(ctx))
|
|
543
|
+
return true;
|
|
544
|
+
const remaining = until - Date.now();
|
|
545
|
+
if (remaining <= 0)
|
|
546
|
+
return false;
|
|
547
|
+
await delay(Math.min(SUPERVISOR_POLL_MS, remaining));
|
|
548
|
+
}
|
|
549
|
+
return true;
|
|
550
|
+
}
|
|
551
|
+
async function runWatch(ctx) {
|
|
552
|
+
const intervalMs = ctx.launch.intervalMs ?? DEFAULT_WATCH_INTERVAL_MS;
|
|
553
|
+
const deadlineAt = ctx.launch.taskTimeoutMs === undefined ? undefined : ctx.startedAt + ctx.launch.taskTimeoutMs;
|
|
554
|
+
while (!ctx.finalized) {
|
|
555
|
+
if (observeStop(ctx)) {
|
|
556
|
+
finalize(ctx, cancelledTerminal("stopped by request", "none"));
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
if (deadlineAt !== undefined && Date.now() >= deadlineAt) {
|
|
560
|
+
finalize(ctx, { status: "timed_out", reason: "timeout", exitCode: null, signal: null, timedOut: true, groupCleanup: "none" });
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
const remaining = deadlineAt === undefined ? undefined : Math.max(1, deadlineAt - Date.now());
|
|
564
|
+
const capMs = ctx.launch.commandTimeoutMs;
|
|
565
|
+
const pollTimeoutMs = capMs === undefined ? remaining : remaining === undefined ? capMs : Math.min(remaining, capMs);
|
|
566
|
+
const capBound = capMs !== undefined && (remaining === undefined || capMs < remaining);
|
|
567
|
+
const checkStartedAt = Date.now();
|
|
568
|
+
const outcome = await runChild(ctx, {
|
|
569
|
+
argv: ctx.launch.command.argv,
|
|
570
|
+
cwd: ctx.launch.command.cwd,
|
|
571
|
+
...(pollTimeoutMs === undefined ? {} : { killAt: checkStartedAt + pollTimeoutMs }),
|
|
572
|
+
killKind: capBound ? "cap" : "task",
|
|
573
|
+
mode: "buffer",
|
|
574
|
+
maxBytes: ctx.launch.maxLogBytes,
|
|
575
|
+
attempt: ctx.checks + 1,
|
|
576
|
+
onSpawn: (identity) => {
|
|
577
|
+
ctx.command = { ...identity, startedAt: checkStartedAt, attempt: ctx.checks + 1 };
|
|
578
|
+
try {
|
|
579
|
+
writeCommandRecord(ctx.directory, {
|
|
580
|
+
version: SUPERVISOR_RECORD_VERSION,
|
|
581
|
+
taskId: ctx.taskId,
|
|
582
|
+
token: ctx.launch.token,
|
|
583
|
+
runnerPid: ctx.runnerPid,
|
|
584
|
+
pid: identity.pid,
|
|
585
|
+
pgid: identity.pgid,
|
|
586
|
+
pidStartTime: identity.pidStartTime,
|
|
587
|
+
startedAt: checkStartedAt,
|
|
588
|
+
attempt: ctx.checks + 1,
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
catch {
|
|
592
|
+
// Recording the live identity is best effort; the check itself must still run.
|
|
593
|
+
}
|
|
594
|
+
},
|
|
595
|
+
});
|
|
596
|
+
if (ctx.finalized)
|
|
597
|
+
return;
|
|
598
|
+
ctx.checks += 1;
|
|
599
|
+
// Per-check output keeps the streams apart: stdout bytes in stdout.log, stderr in stderr.log.
|
|
600
|
+
streamChunk(ctx.stdout, Buffer.from(outcome.stdout), ctx.launch.maxLogBytes);
|
|
601
|
+
streamChunk(ctx.stderr, Buffer.from(outcome.stderr), ctx.launch.maxLogBytes);
|
|
602
|
+
appendEvent(ctx.paths.events, `check #${ctx.checks} exit=${outcome.exitCode ?? "null"} signal=${outcome.exitSignal ?? "null"} `
|
|
603
|
+
+ `duration_ms=${Math.max(0, outcome.endedAt - outcome.startedAt)} timed_out=${outcome.timedOut}`
|
|
604
|
+
+ `${outcome.cancelled ? " cancelled=true" : ""}`
|
|
605
|
+
+ `${capBound ? " cap_bound=true" : ""}`
|
|
606
|
+
+ `${outcome.cleanup === "none" ? "" : ` group_cleanup=${outcome.cleanup}`}`);
|
|
607
|
+
if (outcome.cancelled || observeStop(ctx)) {
|
|
608
|
+
finalize(ctx, cancelledTerminal("stopped by request", outcome.cleanup, evidenceOf(outcome)));
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
if (outcome.timedOut) {
|
|
612
|
+
const reason = capBound ? capReason(ctx.launch.commandTimeoutMs / 1000) : "timeout";
|
|
613
|
+
finalize(ctx, {
|
|
614
|
+
status: "timed_out",
|
|
615
|
+
reason,
|
|
616
|
+
exitCode: outcome.exitCode,
|
|
617
|
+
signal: outcome.exitSignal === null ? null : String(outcome.exitSignal),
|
|
618
|
+
timedOut: true,
|
|
619
|
+
groupCleanup: outcome.cleanup,
|
|
620
|
+
lastCheck: evidenceOf(outcome),
|
|
621
|
+
});
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
if (outcome.spawnError !== undefined) {
|
|
625
|
+
finalize(ctx, {
|
|
626
|
+
status: "failed",
|
|
627
|
+
reason: `the watch check could not run: ${outcome.spawnError}`,
|
|
628
|
+
exitCode: outcome.exitCode,
|
|
629
|
+
signal: null,
|
|
630
|
+
timedOut: false,
|
|
631
|
+
lastCheck: evidenceOf(outcome),
|
|
632
|
+
error: outcome.spawnError,
|
|
633
|
+
});
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
// Production ordering: validate both conditions, evaluate both, then let
|
|
637
|
+
// failure win before success. A JSON-path parse error keeps the watch
|
|
638
|
+
// running (the condition itself was valid at launch).
|
|
639
|
+
const conditionErrors = [];
|
|
640
|
+
for (const [name, condition] of [["success_when", ctx.launch.successWhen], ["failure_when", ctx.launch.failureWhen]]) {
|
|
641
|
+
const invalid = condition ? validateCondition(condition) : undefined;
|
|
642
|
+
if (invalid) {
|
|
643
|
+
finalize(ctx, {
|
|
644
|
+
status: "failed",
|
|
645
|
+
reason: `${name}: ${invalid}`,
|
|
646
|
+
exitCode: outcome.exitCode,
|
|
647
|
+
signal: outcome.exitSignal === null ? null : String(outcome.exitSignal),
|
|
648
|
+
timedOut: false,
|
|
649
|
+
lastCheck: evidenceOf(outcome),
|
|
650
|
+
});
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
const failure = ctx.launch.failureWhen ? evaluateCondition(ctx.launch.failureWhen, asCommandResult(outcome)) : undefined;
|
|
655
|
+
const success = ctx.launch.successWhen ? evaluateCondition(ctx.launch.successWhen, asCommandResult(outcome)) : undefined;
|
|
656
|
+
for (const [name, match] of [["failure_when", failure], ["success_when", success]]) {
|
|
657
|
+
if (match?.error)
|
|
658
|
+
conditionErrors.push(`${name}: ${match.error}`);
|
|
659
|
+
}
|
|
660
|
+
if (failure?.matched) {
|
|
661
|
+
finalize(ctx, {
|
|
662
|
+
status: "failed",
|
|
663
|
+
reason: "failure condition matched",
|
|
664
|
+
exitCode: outcome.exitCode,
|
|
665
|
+
signal: outcome.exitSignal === null ? null : String(outcome.exitSignal),
|
|
666
|
+
timedOut: false,
|
|
667
|
+
matchedCondition: ctx.launch.failureWhen,
|
|
668
|
+
matchedValue: failure.value,
|
|
669
|
+
lastCheck: evidenceOf(outcome, { condition: ctx.launch.failureWhen, value: failure.value }),
|
|
670
|
+
});
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
if (conditionErrors.length > 0) {
|
|
674
|
+
appendEvent(ctx.paths.events, `condition error (the watch keeps running): ${oneLine(conditionErrors.join("; "))}`);
|
|
675
|
+
}
|
|
676
|
+
else if (success?.matched) {
|
|
677
|
+
finalize(ctx, {
|
|
678
|
+
status: "succeeded",
|
|
679
|
+
reason: "success condition matched",
|
|
680
|
+
exitCode: outcome.exitCode,
|
|
681
|
+
signal: outcome.exitSignal === null ? null : String(outcome.exitSignal),
|
|
682
|
+
timedOut: false,
|
|
683
|
+
matchedCondition: ctx.launch.successWhen,
|
|
684
|
+
matchedValue: success.value,
|
|
685
|
+
lastCheck: evidenceOf(outcome, { condition: ctx.launch.successWhen, value: success.value }),
|
|
686
|
+
});
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
if (await waitForNextCheck(ctx, nextCheckDelay(intervalMs, deadlineAt))) {
|
|
690
|
+
finalize(ctx, cancelledTerminal("stopped by request", "none"));
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
async function runProcess(ctx) {
|
|
696
|
+
const { argv, cwd } = ctx.launch.command;
|
|
697
|
+
const deadlineAt = ctx.launch.taskTimeoutMs === undefined ? undefined : ctx.startedAt + ctx.launch.taskTimeoutMs;
|
|
698
|
+
const capAt = ctx.launch.commandTimeoutMs === undefined ? undefined : ctx.startedAt + ctx.launch.commandTimeoutMs;
|
|
699
|
+
const capBound = capAt !== undefined && (deadlineAt === undefined || capAt <= deadlineAt);
|
|
700
|
+
const killAt = capBound ? capAt : deadlineAt;
|
|
701
|
+
const outcome = await runChild(ctx, {
|
|
702
|
+
argv,
|
|
703
|
+
cwd,
|
|
704
|
+
...(killAt === undefined ? {} : { killAt }),
|
|
705
|
+
killKind: capBound ? "cap" : "task",
|
|
706
|
+
mode: "stream",
|
|
707
|
+
maxBytes: ctx.launch.maxLogBytes,
|
|
708
|
+
attempt: 1,
|
|
709
|
+
onSpawn: (identity) => {
|
|
710
|
+
ctx.command = { ...identity, startedAt: Date.now(), attempt: 1 };
|
|
711
|
+
try {
|
|
712
|
+
writeCommandRecord(ctx.directory, {
|
|
713
|
+
version: SUPERVISOR_RECORD_VERSION,
|
|
714
|
+
taskId: ctx.taskId,
|
|
715
|
+
token: ctx.launch.token,
|
|
716
|
+
runnerPid: ctx.runnerPid,
|
|
717
|
+
pid: identity.pid,
|
|
718
|
+
pgid: identity.pgid,
|
|
719
|
+
pidStartTime: identity.pidStartTime,
|
|
720
|
+
startedAt: ctx.command.startedAt,
|
|
721
|
+
attempt: 1,
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
catch {
|
|
725
|
+
// Identity is best effort; execution and terminal evidence are not.
|
|
726
|
+
}
|
|
727
|
+
},
|
|
728
|
+
});
|
|
729
|
+
if (ctx.finalized)
|
|
730
|
+
return;
|
|
731
|
+
appendEvent(ctx.paths.events, `spawn pid=${ctx.command?.pid ?? "unknown"} pgid=${ctx.command?.pgid ?? "unknown"} cwd=${cwd} argv=${JSON.stringify(argv)}`);
|
|
732
|
+
const lastOutput = { stdout: sinkTailText(ctx.stdout), stderr: sinkTailText(ctx.stderr) };
|
|
733
|
+
if (outcome.spawnError !== undefined) {
|
|
734
|
+
finalize(ctx, {
|
|
735
|
+
status: "failed",
|
|
736
|
+
reason: `could not start the command: ${outcome.spawnError}`,
|
|
737
|
+
exitCode: null,
|
|
738
|
+
signal: null,
|
|
739
|
+
timedOut: false,
|
|
740
|
+
lastOutput,
|
|
741
|
+
error: outcome.spawnError,
|
|
742
|
+
});
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
if (outcome.cancelled) {
|
|
746
|
+
finalize(ctx, {
|
|
747
|
+
status: "cancelled",
|
|
748
|
+
reason: "stopped by request",
|
|
749
|
+
exitCode: outcome.exitCode,
|
|
750
|
+
signal: outcome.exitSignal === null ? null : String(outcome.exitSignal),
|
|
751
|
+
timedOut: false,
|
|
752
|
+
groupCleanup: outcome.cleanup,
|
|
753
|
+
lastOutput,
|
|
754
|
+
});
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
if (outcome.timedOut) {
|
|
758
|
+
finalize(ctx, {
|
|
759
|
+
status: "timed_out",
|
|
760
|
+
reason: capBound ? capReason(ctx.launch.commandTimeoutMs / 1000) : "timeout",
|
|
761
|
+
exitCode: outcome.exitCode,
|
|
762
|
+
signal: outcome.exitSignal === null ? null : String(outcome.exitSignal),
|
|
763
|
+
timedOut: true,
|
|
764
|
+
groupCleanup: outcome.cleanup,
|
|
765
|
+
lastOutput,
|
|
766
|
+
});
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
769
|
+
const ok = outcome.exitCode === 0;
|
|
770
|
+
finalize(ctx, {
|
|
771
|
+
status: ok ? "succeeded" : "failed",
|
|
772
|
+
reason: ok
|
|
773
|
+
? "process exited with code 0"
|
|
774
|
+
: `process exited with code ${outcome.exitCode ?? "unknown"}${outcome.exitSignal ? ` (${outcome.exitSignal})` : ""}`,
|
|
775
|
+
exitCode: outcome.exitCode,
|
|
776
|
+
signal: outcome.exitSignal === null ? null : String(outcome.exitSignal),
|
|
777
|
+
timedOut: false,
|
|
778
|
+
groupCleanup: outcome.cleanup,
|
|
779
|
+
lastOutput,
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
function main() {
|
|
783
|
+
const [directory, taskId] = process.argv.slice(2);
|
|
784
|
+
if (!directory || !taskId) {
|
|
785
|
+
process.stderr.write("usage: runner.mjs <supervisor-directory> <taskId>\n");
|
|
786
|
+
return 2;
|
|
787
|
+
}
|
|
788
|
+
const launchRead = readLaunchRecord(directory, taskId);
|
|
789
|
+
if (!launchRead.value) {
|
|
790
|
+
process.stderr.write(`supervisor runner: ${launchRead.missing ? "no launch record" : launchRead.error} for ${taskId}\n`);
|
|
791
|
+
return 2;
|
|
792
|
+
}
|
|
793
|
+
const launch = launchRead.value;
|
|
794
|
+
const { paths, stdout, stderr } = openStreams(directory, taskId);
|
|
795
|
+
const runnerPidStartTime = startToken(process.pid);
|
|
796
|
+
const claim = claimLaunch(directory, taskId, {
|
|
797
|
+
version: SUPERVISOR_RECORD_VERSION,
|
|
798
|
+
taskId,
|
|
799
|
+
token: launch.token,
|
|
800
|
+
pid: process.pid,
|
|
801
|
+
pidStartTime: runnerPidStartTime,
|
|
802
|
+
claimedAt: Date.now(),
|
|
803
|
+
});
|
|
804
|
+
if (claim.status !== "claimed") {
|
|
805
|
+
// Neither a lost launch, an existing claim, nor a terminal record may ever
|
|
806
|
+
// execute again. This is the durable refusal, not a heuristic.
|
|
807
|
+
const detail = claim.status === "lost"
|
|
808
|
+
? "the launch is recorded lost; a late execution is refused"
|
|
809
|
+
: claim.status === "terminal"
|
|
810
|
+
? "a terminal record already exists"
|
|
811
|
+
: `the token is already claimed by pid ${claim.claim.pid}`;
|
|
812
|
+
appendEvent(paths.events, `runner ${process.pid} refused the launch: ${detail}; no command was executed`);
|
|
813
|
+
return 0;
|
|
814
|
+
}
|
|
815
|
+
const ctx = {
|
|
816
|
+
directory,
|
|
817
|
+
taskId,
|
|
818
|
+
launch,
|
|
819
|
+
paths,
|
|
820
|
+
runnerPid: process.pid,
|
|
821
|
+
runnerPidStartTime,
|
|
822
|
+
startedAt: Date.now(),
|
|
823
|
+
checks: 0,
|
|
824
|
+
stdout,
|
|
825
|
+
stderr,
|
|
826
|
+
stopRequested: false,
|
|
827
|
+
finalized: false,
|
|
828
|
+
};
|
|
829
|
+
appendEvent(paths.events, `claimed runner_pid=${process.pid} runner_version=${SUPERVISOR_RUNNER_VERSION} kind=${launch.kind} cwd=${launch.command.cwd}`);
|
|
830
|
+
const onSignal = (signal) => {
|
|
831
|
+
appendEvent(paths.events, `runner received ${signal}`);
|
|
832
|
+
ctx.stopRequested = true;
|
|
833
|
+
if (ctx.cancelActive)
|
|
834
|
+
ctx.cancelActive();
|
|
835
|
+
else
|
|
836
|
+
finalize(ctx, cancelledTerminal("stopped by request", "none"));
|
|
837
|
+
};
|
|
838
|
+
process.on("SIGTERM", () => onSignal("SIGTERM"));
|
|
839
|
+
process.on("SIGINT", () => onSignal("SIGINT"));
|
|
840
|
+
if (observeStop(ctx)) {
|
|
841
|
+
finalize(ctx, cancelledTerminal("stopped before the command started", "none"));
|
|
842
|
+
return 0;
|
|
843
|
+
}
|
|
844
|
+
const run = launch.kind === "watch" ? runWatch(ctx) : runProcess(ctx);
|
|
845
|
+
void run.catch((error) => {
|
|
846
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
847
|
+
appendEvent(paths.events, `runner error: ${oneLine(message)}`);
|
|
848
|
+
finalize(ctx, { status: "failed", reason: `supervisor runner error: ${message}`, exitCode: null, signal: null, timedOut: false, error: message });
|
|
849
|
+
});
|
|
850
|
+
// The command's own child handle and timers keep this process alive after main
|
|
851
|
+
// returns; finalize() writes the terminal record and exits.
|
|
852
|
+
return 0;
|
|
853
|
+
}
|
|
854
|
+
function invokedAsEntrypoint() {
|
|
855
|
+
const invoked = process.argv[1];
|
|
856
|
+
if (!invoked)
|
|
857
|
+
return false;
|
|
858
|
+
const resolveReal = (path) => {
|
|
859
|
+
try {
|
|
860
|
+
return realpathSync(path);
|
|
861
|
+
}
|
|
862
|
+
catch {
|
|
863
|
+
return resolve(path);
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
return resolveReal(invoked) === resolveReal(fileURLToPath(import.meta.url));
|
|
867
|
+
}
|
|
868
|
+
if (invokedAsEntrypoint()) {
|
|
869
|
+
// The runner's exit code reports runner health, not the command verdict: a
|
|
870
|
+
// recorded failure still exits 0 because the evidence was durably written.
|
|
871
|
+
process.exitCode = main();
|
|
872
|
+
}
|