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,111 @@
|
|
|
1
|
+
# Detached local supervisor
|
|
2
|
+
|
|
3
|
+
Slice 2 of [ADR 0020](../../../../docs/adr/0020-observed-waits-retain-an-owner.md) and the
|
|
4
|
+
[observed-waits design](../../../../docs/plans/observed-waits-design.md): local process and command-watch
|
|
5
|
+
supervision that survives the process that launched it. Nothing in this directory is wired into the
|
|
6
|
+
Background Tasks tools yet; the parent owns that integration.
|
|
7
|
+
|
|
8
|
+
## Contract
|
|
9
|
+
|
|
10
|
+
| Function | Meaning |
|
|
11
|
+
| --- | --- |
|
|
12
|
+
| `createLocalSupervisor({ directory })` | Caller-side adapter. The directory is configurable and may be any writable path. |
|
|
13
|
+
| `.start(options)` | Validate, persist the launch record, spawn the runner in its own process group, and report the durable claim. |
|
|
14
|
+
| `.inspect(taskId, options?)` | Reconcile from records. Never launches, never retries. |
|
|
15
|
+
| `.stop(taskId, options?)` | Write a durable stop request, wait for runner evidence, then escalate to a verified process group. |
|
|
16
|
+
|
|
17
|
+
`options.token` is the execution identity: the task id is derived from it (`bgs_<sha256 prefix>`), so a
|
|
18
|
+
second `start` with the same token reports the existing execution and a different request under the
|
|
19
|
+
same token is refused. A runner claims the token with an exclusive file create before executing, so
|
|
20
|
+
even two racing runners cannot execute the same command twice.
|
|
21
|
+
|
|
22
|
+
Statuses: `starting`, `running`, `succeeded`, `failed`, `timed_out`, `cancelled`, `lost`. `starting`
|
|
23
|
+
and `running` are observations; the others come from a durable terminal record. `lost` means no
|
|
24
|
+
terminal evidence exists and none can now appear — it is never reinterpreted as success.
|
|
25
|
+
|
|
26
|
+
## Durable records (`<directory>/tasks/<taskId>/`)
|
|
27
|
+
|
|
28
|
+
| File | Writer | Purpose |
|
|
29
|
+
| --- | --- | --- |
|
|
30
|
+
| `launch.json` | caller, once | immutable argv/cwd/limits/conditions; never contains environment values |
|
|
31
|
+
| `claim.json` | runner, exclusive | proves the token was claimed before execution |
|
|
32
|
+
| `command.json` | runner | identity of the live command or watch check |
|
|
33
|
+
| `stop.json` | caller | durable stop request, readable from any process |
|
|
34
|
+
| `result.json` | runner (or stop escalation) | terminal status, exit code, bounded evidence, log paths |
|
|
35
|
+
| `lost.json` | any inspector | no terminal evidence exists |
|
|
36
|
+
| `stdout.log`, `stderr.log` | runner | per-stream output, capped per stream |
|
|
37
|
+
| `events.log` | runner | lifecycle lines (claim, checks, stop, terminal) plus inherited runner stderr |
|
|
38
|
+
|
|
39
|
+
Terminal records are written exclusively: the first terminal record wins, so a late writer cannot turn
|
|
40
|
+
evidence into a different outcome.
|
|
41
|
+
|
|
42
|
+
## Boundaries
|
|
43
|
+
|
|
44
|
+
- **Admission is the caller's.** Pass an argv that was already admitted and, if applicable, already
|
|
45
|
+
confined by the sandbox wrapper. The supervisor executes it verbatim and adds no permission.
|
|
46
|
+
- **Environment values are not persisted.** `env` is merged into the runner's own environment only;
|
|
47
|
+
records say `"environment": "inherited"`.
|
|
48
|
+
- **No relaunch of ambiguous execution.** A launch without a claim is reported (`starting`, then
|
|
49
|
+
`lost`), never retried. A runner that disappears without a terminal record is `lost`.
|
|
50
|
+
- **Identity gates every signal.** The caller signals a process only when the recorded start token
|
|
51
|
+
verifies against the live pid. `created but no token` means `unknown`, and an unknown identity is
|
|
52
|
+
refused rather than signalled. The runner signals the direct child through the `ChildProcess`
|
|
53
|
+
handle it still owns, and rechecks the recorded token before the delayed escalation.
|
|
54
|
+
- **A group signal requires a live, owned leader.** The pgid is only addressable evidence that *a*
|
|
55
|
+
group exists; after the leader exits, a recycled id is indistinguishable from the original. The
|
|
56
|
+
runner therefore signals the group only while the leader it spawned is still alive on its
|
|
57
|
+
retained handle and its recorded start token agrees — the leader is then a live member, which is
|
|
58
|
+
what proves the group. Once it exits, the runner sends no further group signal: the direct child
|
|
59
|
+
was already killed through the handle, the cleanup is reported `groupCleanup: "unproven"`, and
|
|
60
|
+
surviving members are left to their owner. The same rule governs the caller's external cleanup:
|
|
61
|
+
every group signal re-verifies the leader, and a dead leader refuses the escalation.
|
|
62
|
+
- **`empty` is never claimed when cleanup is unproven.** `groupCleanup: "empty"` means a group
|
|
63
|
+
signal was sent while the leader was owned *and* the group was then observed empty. If identity
|
|
64
|
+
was lost first, the terminal says `unproven` even if the group later disappears on its own.
|
|
65
|
+
- **Stopping a task with a surviving command never rewrites the verdict.** If a recorded command
|
|
66
|
+
survives its runner — a `lost` task, or a terminal whose `groupCleanup` is `unproven` — an explicit
|
|
67
|
+
`stop` kills it only with a verified identity, writes `cleanup.json`, and leaves the recorded
|
|
68
|
+
verdict intact. Unknown identity is refused with an explicit reason. When the recorded leader is
|
|
69
|
+
already gone but its group still has members, those members cannot be proven and the stop refuses
|
|
70
|
+
them; cleanup of such a group stays an operator action.
|
|
71
|
+
- **Local only.** No SSH or remote adapter, no coordinator database, no dependency waits, no model
|
|
72
|
+
continuation. Stopping a task is a caller action and does not imply assignment success.
|
|
73
|
+
- **Watch conditions are the production ones.** `successWhen`/`failureWhen` are validated with
|
|
74
|
+
`validateCondition` and evaluated with `evaluateCondition`; failure wins over success, and a
|
|
75
|
+
condition evaluation error (`json_path_*`) keeps the watch running, as in `pollWatch`.
|
|
76
|
+
|
|
77
|
+
## Shipped runner artifact
|
|
78
|
+
|
|
79
|
+
The executable is the emitted JavaScript closure under `generated/`, never the
|
|
80
|
+
TypeScript source: Node refuses type stripping under `node_modules`
|
|
81
|
+
(`ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING`). `runner.ts` is the source; run
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
node src/supervisor/emit-runner.mjs
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
to regenerate `generated/*.mjs` after changing the runner or its runtime
|
|
88
|
+
dependencies. The closure covers `runner`, `store`, `types`, `identity`,
|
|
89
|
+
`conditions`, `process` and `process-identity`, imports only `node:` builtins,
|
|
90
|
+
and is checked in so the package works without a build step.
|
|
91
|
+
`supervisor.codegen.test.ts` regenerates it and fails on drift.
|
|
92
|
+
|
|
93
|
+
**Packaging (parent-owned):** the package `files` list carries
|
|
94
|
+
`src/supervisor/**/*.mjs` so the closure ships; `npm pack --dry-run` includes
|
|
95
|
+
`src/supervisor/generated/*.mjs`. The installed-path test copies this tree into a
|
|
96
|
+
temp `node_modules` and runs it there.
|
|
97
|
+
|
|
98
|
+
The runner is spawned detached with `stdio` pointed at `events.log`, so a crash
|
|
99
|
+
before the claim is still diagnosable. Output capture mirrors `runCommandOnce`
|
|
100
|
+
(per-command timeout, SIGTERM then SIGKILL to the process group after 2s,
|
|
101
|
+
UTF-8-safe truncation), except that the child handle is retained so a stop can
|
|
102
|
+
end an in-flight check, and group cleanup is driven to a proven empty state
|
|
103
|
+
before the terminal record is published.
|
|
104
|
+
|
|
105
|
+
Tests: `supervisor.test.ts` drives real subprocesses for parent-exit survival, duplicate-token
|
|
106
|
+
single execution, stop, timeout, watch cadence/conditions, environment secrecy, lost evidence,
|
|
107
|
+
installed-path execution, emitted-closure drift, atomic record publication, TERM-resistant
|
|
108
|
+
descendant cleanup, delayed-late-claim fencing, orphan cleanup with verified/unknown identity,
|
|
109
|
+
a live fence holder that pauses past the old stale window, proven-dead and unreadable fence owners,
|
|
110
|
+
a suspended runner that must report cleanup unproven instead of signalling a pgid it can no
|
|
111
|
+
longer prove, plus the proof that a recorded command with an unverifiable identity is left alone.
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-background-tasks/src/supervisor/emit-runner.mjs. Do not edit directly.
|
|
2
|
+
#!/usr/bin/env node
|
|
3
|
+
/**
|
|
4
|
+
* Emit the supervisor runner's JavaScript dependency closure.
|
|
5
|
+
*
|
|
6
|
+
* Node refuses to strip types for a `.ts` file under `node_modules`
|
|
7
|
+
* (`ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING`), so the executable that ships
|
|
8
|
+
* cannot be the TypeScript source. This script transpiles the runner and every
|
|
9
|
+
* module it imports at runtime into flat `.mjs` files under `generated/`, with
|
|
10
|
+
* relative specifiers rewritten to the emitted names and type-only imports
|
|
11
|
+
* erased.
|
|
12
|
+
*
|
|
13
|
+
* The closure is checked in so the package works without a build step, and
|
|
14
|
+
* `supervisor.codegen.test.ts` regenerates it and fails on drift. Run it after
|
|
15
|
+
* changing the runner or its runtime dependencies:
|
|
16
|
+
*
|
|
17
|
+
* ```
|
|
18
|
+
* node src/supervisor/emit-runner.mjs # writes generated/
|
|
19
|
+
* node src/supervisor/emit-runner.mjs <outDir> # writes elsewhere (drift test)
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Bare imports are limited to `node:` builtins on purpose: the closure must run
|
|
23
|
+
* from a bare install without relying on the caller's module graph.
|
|
24
|
+
*/
|
|
25
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
26
|
+
import { createRequire } from "node:module";
|
|
27
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
28
|
+
import { fileURLToPath } from "node:url";
|
|
29
|
+
const require = createRequire(import.meta.url);
|
|
30
|
+
const ts = require("typescript");
|
|
31
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
32
|
+
const outputDir = process.argv[2] ? resolve(process.argv[2]) : join(here, "generated");
|
|
33
|
+
/** Runtime entry first; everything else is reachable from it. */
|
|
34
|
+
const CLOSURE = [
|
|
35
|
+
{ source: join(here, "runner.ts"), out: "runner.mjs" },
|
|
36
|
+
{ source: join(here, "store.ts"), out: "store.mjs" },
|
|
37
|
+
{ source: join(here, "types.ts"), out: "types.mjs" },
|
|
38
|
+
{ source: join(here, "identity.ts"), out: "identity.mjs" },
|
|
39
|
+
{ source: join(here, "..", "conditions.ts"), out: "conditions.mjs" },
|
|
40
|
+
{ source: join(here, "..", "process.ts"), out: "process.mjs" },
|
|
41
|
+
{ source: join(here, "..", "process-identity.ts"), out: "process-identity.mjs" },
|
|
42
|
+
];
|
|
43
|
+
const bySource = new Map(CLOSURE.map((entry) => [resolve(entry.source), entry.out]));
|
|
44
|
+
const COMPILER_OPTIONS = {
|
|
45
|
+
target: ts.ScriptTarget.ES2022,
|
|
46
|
+
module: ts.ModuleKind.ESNext,
|
|
47
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
48
|
+
isolatedModules: true,
|
|
49
|
+
removeComments: false,
|
|
50
|
+
newLine: ts.NewLineKind.LineFeed,
|
|
51
|
+
};
|
|
52
|
+
const BANNER = "// Generated by src/supervisor/emit-runner.mjs from the TypeScript source.\n"
|
|
53
|
+
+ "// Do not edit: change the source and re-run the emitter (a drift test enforces this).\n";
|
|
54
|
+
function rewriteSpecifiers(code, sourcePath) {
|
|
55
|
+
const sourceDir = dirname(sourcePath);
|
|
56
|
+
const replace = (match, prefix, specifier, suffix) => {
|
|
57
|
+
const target = bySource.get(resolve(sourceDir, specifier));
|
|
58
|
+
if (!target) {
|
|
59
|
+
throw new Error(`${relative(here, sourcePath)} imports ${JSON.stringify(specifier)}, which is not part of the emitted runner closure. `
|
|
60
|
+
+ "Add it to CLOSURE in emit-runner.mjs or remove the runtime import.");
|
|
61
|
+
}
|
|
62
|
+
return `${prefix}./${target}${suffix}`;
|
|
63
|
+
};
|
|
64
|
+
const rewritten = code.replace(/(from\s*")((?:\.\.?\/)[^"]*\.ts)(")/g, replace);
|
|
65
|
+
const dynamicRewritten = rewritten.replace(/(import\s*\(\s*")((?:\.\.?\/)[^"]*\.ts)(")/g, replace);
|
|
66
|
+
const leftover = dynamicRewritten.match(/(?:from\s*"|import\s*\(\s*")((?:\.\.?\/)[^"]*\.ts)"/);
|
|
67
|
+
if (leftover) {
|
|
68
|
+
throw new Error(`${relative(here, sourcePath)} still references ${leftover[1]} after emission.`);
|
|
69
|
+
}
|
|
70
|
+
return dynamicRewritten;
|
|
71
|
+
}
|
|
72
|
+
mkdirSync(outputDir, { recursive: true });
|
|
73
|
+
const emitted = [];
|
|
74
|
+
for (const entry of CLOSURE) {
|
|
75
|
+
const source = readFileSync(entry.source, "utf8");
|
|
76
|
+
const result = ts.transpileModule(source, {
|
|
77
|
+
fileName: entry.source,
|
|
78
|
+
compilerOptions: COMPILER_OPTIONS,
|
|
79
|
+
reportDiagnostics: true,
|
|
80
|
+
});
|
|
81
|
+
const errors = (result.diagnostics ?? []).filter((diagnostic) => diagnostic.category === ts.DiagnosticCategory.Error);
|
|
82
|
+
if (errors.length > 0) {
|
|
83
|
+
const messages = errors.map((diagnostic) => ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
|
|
84
|
+
throw new Error(`Could not emit ${entry.out}: ${messages.join("; ")}`);
|
|
85
|
+
}
|
|
86
|
+
const code = rewriteSpecifiers(result.outputText, entry.source);
|
|
87
|
+
writeFileSync(join(outputDir, entry.out), `${BANNER}\n${code}`);
|
|
88
|
+
emitted.push(entry.out);
|
|
89
|
+
}
|
|
90
|
+
process.stdout.write(`emitted ${emitted.length} module(s) to ${outputDir}: ${emitted.join(", ")}\n`);
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-background-tasks/src/supervisor/generated/conditions.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
|
+
export function validateCondition(condition) {
|
|
5
|
+
if ((condition.type === "json_path_equals" || condition.type === "json_path_exists") && !parseJsonPath(condition.path)) {
|
|
6
|
+
return `unsupported JSON path: ${condition.path}. Use a root-prefixed path such as $.status or $.terminalFailure.`;
|
|
7
|
+
}
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
export function evaluateCondition(condition, result) {
|
|
11
|
+
switch (condition.type) {
|
|
12
|
+
case "exit_code":
|
|
13
|
+
return { matched: result.exitCode === condition.equals, value: result.exitCode };
|
|
14
|
+
case "stdout_contains":
|
|
15
|
+
return { matched: result.stdout.includes(condition.value) };
|
|
16
|
+
case "stderr_contains":
|
|
17
|
+
return { matched: result.stderr.includes(condition.value) };
|
|
18
|
+
case "json_path_equals": {
|
|
19
|
+
const resolved = resolveJsonPath(result.stdout, condition.path);
|
|
20
|
+
if (!resolved.ok)
|
|
21
|
+
return { matched: false, error: resolved.error };
|
|
22
|
+
return { matched: deepEqual(resolved.value, condition.value), value: resolved.value };
|
|
23
|
+
}
|
|
24
|
+
case "json_path_exists": {
|
|
25
|
+
const resolved = resolveJsonPath(result.stdout, condition.path);
|
|
26
|
+
return resolved.ok ? { matched: true, value: resolved.value } : { matched: false, error: resolved.error };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function resolveJsonPath(jsonText, path) {
|
|
31
|
+
let current;
|
|
32
|
+
try {
|
|
33
|
+
current = JSON.parse(jsonText);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
return { ok: false, error: `stdout is not valid JSON: ${error instanceof Error ? error.message : String(error)}` };
|
|
37
|
+
}
|
|
38
|
+
const tokens = parseJsonPath(path);
|
|
39
|
+
if (!tokens)
|
|
40
|
+
return { ok: false, error: `unsupported JSON path: ${path}` };
|
|
41
|
+
for (const token of tokens) {
|
|
42
|
+
if (typeof token === "number") {
|
|
43
|
+
if (!Array.isArray(current) || token < 0 || token >= current.length) {
|
|
44
|
+
return { ok: false, error: `JSON path not found: ${path}` };
|
|
45
|
+
}
|
|
46
|
+
current = current[token];
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (current === null || typeof current !== "object" || !(token in current)) {
|
|
50
|
+
return { ok: false, error: `JSON path not found: ${path}` };
|
|
51
|
+
}
|
|
52
|
+
current = current[token];
|
|
53
|
+
}
|
|
54
|
+
return { ok: true, value: current };
|
|
55
|
+
}
|
|
56
|
+
function parseJsonPath(path) {
|
|
57
|
+
if (!path.startsWith("$"))
|
|
58
|
+
return undefined;
|
|
59
|
+
const tokens = [];
|
|
60
|
+
let i = 1;
|
|
61
|
+
while (i < path.length) {
|
|
62
|
+
if (path[i] === ".") {
|
|
63
|
+
i += 1;
|
|
64
|
+
const start = i;
|
|
65
|
+
while (i < path.length && /[A-Za-z0-9_$-]/.test(path[i]))
|
|
66
|
+
i += 1;
|
|
67
|
+
if (i === start)
|
|
68
|
+
return undefined;
|
|
69
|
+
tokens.push(path.slice(start, i));
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (path[i] === "[") {
|
|
73
|
+
const end = path.indexOf("]", i);
|
|
74
|
+
if (end === -1)
|
|
75
|
+
return undefined;
|
|
76
|
+
const raw = path.slice(i + 1, end).trim();
|
|
77
|
+
const quoted = raw.match(/^['\"](.+)['\"]$/);
|
|
78
|
+
if (quoted) {
|
|
79
|
+
tokens.push(quoted[1]);
|
|
80
|
+
}
|
|
81
|
+
else if (/^\d+$/.test(raw)) {
|
|
82
|
+
tokens.push(Number(raw));
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
i = end + 1;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
return tokens;
|
|
93
|
+
}
|
|
94
|
+
function deepEqual(a, b) {
|
|
95
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
96
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-background-tasks/src/supervisor/generated/identity.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
|
+
* Process identity rules for the local supervisor.
|
|
6
|
+
*
|
|
7
|
+
* Signalling a numeric pid is only safe when the process behind it is provably
|
|
8
|
+
* the one this task recorded. A live pid is *not* proof: pids are recycled, and
|
|
9
|
+
* "still alive" would let a stop kill an unrelated process. Two kinds of proof
|
|
10
|
+
* exist here:
|
|
11
|
+
*
|
|
12
|
+
* - **Verified identity**: the recorded start token matches what the OS reports
|
|
13
|
+
* for that pid right now. Required before the caller signals anything.
|
|
14
|
+
* - **Owned handle**: the runner still holds the `ChildProcess` object it
|
|
15
|
+
* spawned and the child has not exited. The runner may signal that child
|
|
16
|
+
* directly without a token, because the handle *is* the identity.
|
|
17
|
+
*
|
|
18
|
+
* When no start token is available (for example a platform or sandbox where
|
|
19
|
+
* `ps` cannot run), identity is `unknown`. Callers must refuse to signal, not
|
|
20
|
+
* guess.
|
|
21
|
+
*/
|
|
22
|
+
import { processExists } from "./process.mjs";
|
|
23
|
+
import { readProcessStartToken } from "./process-identity.mjs";
|
|
24
|
+
export function readStartToken(pid) {
|
|
25
|
+
return readProcessStartToken(pid);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Decide whether `pid` is provably the recorded process.
|
|
29
|
+
*
|
|
30
|
+
* - `dead` / `absent`: nothing to signal.
|
|
31
|
+
* - `mismatched`: the pid now belongs to a different process; never signal.
|
|
32
|
+
* - `unknown`: alive but unprovable (no recorded or readable start token).
|
|
33
|
+
* - `verified`: safe for the caller to signal.
|
|
34
|
+
*/
|
|
35
|
+
export function verifyProcessIdentity(pid, recordedStartToken, reader = readStartToken) {
|
|
36
|
+
if (pid === undefined || !Number.isInteger(pid) || pid <= 0)
|
|
37
|
+
return "absent";
|
|
38
|
+
if (!processExists(pid))
|
|
39
|
+
return "dead";
|
|
40
|
+
if (!recordedStartToken)
|
|
41
|
+
return "unknown";
|
|
42
|
+
const current = reader(pid);
|
|
43
|
+
if (!current)
|
|
44
|
+
return "unknown";
|
|
45
|
+
return current === recordedStartToken ? "verified" : "mismatched";
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Liveness with the same reader the caller uses for signalling.
|
|
49
|
+
*
|
|
50
|
+
* `processIdentityAlive` in production code always reads the OS token directly.
|
|
51
|
+
* A supervisor instance may be given a different reader (a portability or test
|
|
52
|
+
* seam), and it must not decide "alive" with one identity source and "verified"
|
|
53
|
+
* with another: on a platform where the OS token is readable, a fixture token
|
|
54
|
+
* would otherwise make `inspect` call a live command dead and skip cleanup.
|
|
55
|
+
*
|
|
56
|
+
* With the default reader this is exactly `processIdentityAlive`.
|
|
57
|
+
*/
|
|
58
|
+
export function identityAlive(pid, recordedStartToken, recordedAt, reader = readStartToken) {
|
|
59
|
+
if (pid === undefined || !Number.isInteger(pid) || pid <= 0)
|
|
60
|
+
return false;
|
|
61
|
+
if (!processExists(pid))
|
|
62
|
+
return false;
|
|
63
|
+
const current = reader(pid);
|
|
64
|
+
if (recordedStartToken !== undefined && current !== undefined)
|
|
65
|
+
return recordedStartToken === current;
|
|
66
|
+
if (recordedStartToken === undefined && current !== undefined && recordedAt !== undefined) {
|
|
67
|
+
const startedAt = Date.parse(current);
|
|
68
|
+
if (Number.isFinite(startedAt) && startedAt > recordedAt + 2_000)
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
/** True when the caller may send signals for this verdict. */
|
|
74
|
+
export function identityAllowsSignals(verdict) {
|
|
75
|
+
return verdict === "verified";
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Whether the process group still has any member.
|
|
79
|
+
*
|
|
80
|
+
* POSIX keeps a group id reserved while the group is non-empty, which is what
|
|
81
|
+
* makes a group-directed SIGKILL after the leader exited addressable at all.
|
|
82
|
+
* Windows has no process groups in libuv; there the tree is removed with
|
|
83
|
+
* `taskkill /T /F` and this reports false.
|
|
84
|
+
*/
|
|
85
|
+
export function processGroupAlive(pgid) {
|
|
86
|
+
if (pgid === undefined || pgid <= 0 || process.platform === "win32")
|
|
87
|
+
return false;
|
|
88
|
+
try {
|
|
89
|
+
process.kill(-pgid, 0);
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
return error.code !== "ESRCH";
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-background-tasks/src/supervisor/generated/process-identity.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
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { execFileSync } from "node:child_process";
|
|
6
|
+
/**
|
|
7
|
+
* Process start-token reads.
|
|
8
|
+
*
|
|
9
|
+
* `ps` is a process spawn. Reading it on a rendering path — once per task, per
|
|
10
|
+
* frame, for every terminal task kept in the panel — is a measurable CPU drain
|
|
11
|
+
* on its own, and it competes with the very commands the panel is showing.
|
|
12
|
+
*
|
|
13
|
+
* Two rules keep that bounded:
|
|
14
|
+
*
|
|
15
|
+
* 1. A pid's start token is immutable for the life of that pid, so a short-lived
|
|
16
|
+
* memo is safe. Entries expire so a recycled pid is re-read rather than
|
|
17
|
+
* mistaking the previous owner's token for the current one, and failures are
|
|
18
|
+
* memoized too, so a pid that cannot be read is not retried on every frame.
|
|
19
|
+
* 2. Callers that decide to *signal* a pid can ask for a fresh read. Liveness
|
|
20
|
+
* display may use the memo; authorization may not.
|
|
21
|
+
*/
|
|
22
|
+
/** How long one pid→token answer is trusted. Short enough to bound pid reuse. */
|
|
23
|
+
const TOKEN_MEMO_TTL_MS = 1_000;
|
|
24
|
+
/** Bound on memo entries; the panel is small, but a long session is not. */
|
|
25
|
+
const TOKEN_MEMO_MAX_ENTRIES = 512;
|
|
26
|
+
const tokenMemo = new Map();
|
|
27
|
+
function readTokenUncached(pid, admission = false) {
|
|
28
|
+
if (!Number.isInteger(pid) || pid <= 0 || process.platform === "win32")
|
|
29
|
+
return undefined;
|
|
30
|
+
try {
|
|
31
|
+
const output = execFileSync(admission ? "/bin/ps" : "ps", ["-o", "lstart=", "-p", String(pid)], {
|
|
32
|
+
env: admission ? { LC_ALL: "C", TZ: "UTC0", PATH: "/usr/bin:/bin" } : process.env,
|
|
33
|
+
encoding: "utf8",
|
|
34
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
35
|
+
timeout: 2_000,
|
|
36
|
+
}).trim();
|
|
37
|
+
return output || undefined;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Admission crosses process environments; stored task tokens retain their original format.
|
|
44
|
+
export function readAdmissionStartToken(pid) {
|
|
45
|
+
if (process.platform !== "linux")
|
|
46
|
+
return readTokenUncached(pid, true);
|
|
47
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
48
|
+
return undefined;
|
|
49
|
+
try {
|
|
50
|
+
const stat = readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
51
|
+
// Fields after the parenthesized command start at field 3. Start time is field 22.
|
|
52
|
+
const start = stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19];
|
|
53
|
+
return start && /^\d+$/.test(start) ? start : undefined;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function remember(pid, token, now) {
|
|
60
|
+
if (tokenMemo.size >= TOKEN_MEMO_MAX_ENTRIES) {
|
|
61
|
+
// Drop expired entries first; only evict live ones if that was not enough.
|
|
62
|
+
for (const [candidate, entry] of tokenMemo) {
|
|
63
|
+
if (now - entry.readAt >= TOKEN_MEMO_TTL_MS)
|
|
64
|
+
tokenMemo.delete(candidate);
|
|
65
|
+
}
|
|
66
|
+
if (tokenMemo.size >= TOKEN_MEMO_MAX_ENTRIES) {
|
|
67
|
+
const oldest = tokenMemo.keys().next();
|
|
68
|
+
if (!oldest.done)
|
|
69
|
+
tokenMemo.delete(oldest.value);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
tokenMemo.set(pid, { token, readAt: now });
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Start token for `pid`, memoized for {@link TOKEN_MEMO_TTL_MS}.
|
|
76
|
+
*
|
|
77
|
+
* Suitable for liveness and display. A caller that is about to send a signal
|
|
78
|
+
* must use {@link readProcessStartTokenFresh} instead.
|
|
79
|
+
*/
|
|
80
|
+
export function readProcessStartToken(pid) {
|
|
81
|
+
if (!Number.isInteger(pid) || pid <= 0 || process.platform === "win32")
|
|
82
|
+
return undefined;
|
|
83
|
+
const now = Date.now();
|
|
84
|
+
const entry = tokenMemo.get(pid);
|
|
85
|
+
if (entry && now - entry.readAt < TOKEN_MEMO_TTL_MS)
|
|
86
|
+
return entry.token;
|
|
87
|
+
const token = readTokenUncached(pid);
|
|
88
|
+
remember(pid, token, now);
|
|
89
|
+
return token;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Start token for `pid`, always read from the OS.
|
|
93
|
+
*
|
|
94
|
+
* Used where the answer authorizes a signal, so a recycled pid cannot inherit
|
|
95
|
+
* a memoized identity.
|
|
96
|
+
*/
|
|
97
|
+
export function readProcessStartTokenFresh(pid) {
|
|
98
|
+
if (!Number.isInteger(pid) || pid <= 0 || process.platform === "win32")
|
|
99
|
+
return undefined;
|
|
100
|
+
const token = readTokenUncached(pid);
|
|
101
|
+
remember(pid, token, Date.now());
|
|
102
|
+
return token;
|
|
103
|
+
}
|
|
104
|
+
/** Drop every memoized identity. Tests and reloads start from a clean slate. */
|
|
105
|
+
export function clearProcessIdentityMemo() {
|
|
106
|
+
tokenMemo.clear();
|
|
107
|
+
}
|
|
108
|
+
const selfStartToken = readTokenUncached(process.pid);
|
|
109
|
+
export function currentProcessStartToken() {
|
|
110
|
+
return selfStartToken;
|
|
111
|
+
}
|
|
112
|
+
export function processIdentityAlive(pid, recordedStartToken, recordedAt) {
|
|
113
|
+
if (!pid || pid <= 0)
|
|
114
|
+
return false;
|
|
115
|
+
try {
|
|
116
|
+
process.kill(pid, 0);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
if (error.code !== "EPERM")
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
const current = readProcessStartToken(pid);
|
|
123
|
+
if (recordedStartToken && current)
|
|
124
|
+
return recordedStartToken === current;
|
|
125
|
+
if (!recordedStartToken && current && recordedAt !== undefined) {
|
|
126
|
+
const currentStartedAt = Date.parse(current);
|
|
127
|
+
if (Number.isFinite(currentStartedAt) && currentStartedAt > recordedAt + 2_000)
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
}
|