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
package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.domain.mjs
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-subagents/shared-operation-coordinator/src/subagent-launch.ts. Do not edit directly.
|
|
2
|
+
// Generated from packages/operation-coordinator/src/subagent-launch.ts. Do not edit directly.
|
|
3
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
4
|
+
/** Fixed launch journal on the coordinator's existing connection and transaction. */
|
|
5
|
+
export class SubagentLaunchJournal {
|
|
6
|
+
context;
|
|
7
|
+
alive;
|
|
8
|
+
constructor(context, alive) {
|
|
9
|
+
this.context = context;
|
|
10
|
+
this.alive = alive;
|
|
11
|
+
this.transaction(() => this.db.exec(`CREATE TABLE IF NOT EXISTS subagent_launch_intents (
|
|
12
|
+
owner TEXT NOT NULL, request_key TEXT NOT NULL, digest TEXT NOT NULL,
|
|
13
|
+
epoch INTEGER NOT NULL, state TEXT NOT NULL, attempts TEXT NOT NULL, result TEXT,
|
|
14
|
+
PRIMARY KEY(owner, request_key));
|
|
15
|
+
CREATE TABLE IF NOT EXISTS subagent_management (singleton INTEGER PRIMARY KEY CHECK(singleton=1), instance TEXT NOT NULL, epoch INTEGER NOT NULL);`));
|
|
16
|
+
}
|
|
17
|
+
get db() { this.alive(); return this.context.db; }
|
|
18
|
+
transaction(run) { this.alive(); return this.context.transaction(run); }
|
|
19
|
+
epoch(instance) {
|
|
20
|
+
return this.transaction(() => {
|
|
21
|
+
const previous = this.db.prepare("SELECT * FROM subagent_management WHERE singleton=1").get();
|
|
22
|
+
if (previous?.instance === instance)
|
|
23
|
+
return Number(previous.epoch);
|
|
24
|
+
const epoch = (Number(previous?.epoch ?? 0)) + 1;
|
|
25
|
+
this.db.prepare("INSERT OR REPLACE INTO subagent_management VALUES (1, ?, ?)").run(instance, epoch);
|
|
26
|
+
return epoch;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
current(epoch) {
|
|
30
|
+
if (this.db.prepare("SELECT epoch FROM subagent_management WHERE singleton=1").get()?.epoch !== epoch)
|
|
31
|
+
throw new Error("stale-runtime-epoch");
|
|
32
|
+
}
|
|
33
|
+
read(owner, key) { return this.db.prepare("SELECT * FROM subagent_launch_intents WHERE owner=? AND request_key=?").get(owner, key); }
|
|
34
|
+
attempt(id) {
|
|
35
|
+
const row = this.db.prepare("SELECT j.value AS attempt FROM subagent_launch_intents, json_each(subagent_launch_intents.attempts) j WHERE json_extract(j.value, '$.id')=? LIMIT 1").get(id);
|
|
36
|
+
return row ? JSON.parse(String(row.attempt)) : undefined;
|
|
37
|
+
}
|
|
38
|
+
unresolvedAttempts() {
|
|
39
|
+
return this.db.prepare("SELECT j.value AS attempt FROM subagent_launch_intents, json_each(subagent_launch_intents.attempts) j WHERE subagent_launch_intents.state='accepted'").all().map(row => JSON.parse(String(row.attempt)));
|
|
40
|
+
}
|
|
41
|
+
pendingIntents() {
|
|
42
|
+
return this.db.prepare("SELECT * FROM subagent_launch_intents WHERE state='accepted'").all();
|
|
43
|
+
}
|
|
44
|
+
progressKey(owner, key) { return `launch-progress:${createHash('sha256').update(JSON.stringify([owner, key])).digest('hex')}`; }
|
|
45
|
+
progress(owner, key) {
|
|
46
|
+
const row = this.db.prepare('SELECT value FROM coordinator_state WHERE key=?').get(this.progressKey(owner, key));
|
|
47
|
+
return row ? JSON.parse(String(row.value)) : undefined;
|
|
48
|
+
}
|
|
49
|
+
noteProgress(owner, key) {
|
|
50
|
+
const previous = this.progress(owner, key), now = Date.now();
|
|
51
|
+
this.db.prepare('INSERT OR REPLACE INTO coordinator_state (key,value) VALUES (?,?)').run(this.progressKey(owner, key), JSON.stringify({ acceptedAt: previous?.acceptedAt ?? now, lastProgressAt: now }));
|
|
52
|
+
}
|
|
53
|
+
lifecycleReasons(owner, key) {
|
|
54
|
+
const exact = owner !== undefined && key !== undefined ? this.read(owner, key) : undefined;
|
|
55
|
+
const intents = owner !== undefined ? exact?.state === 'accepted' ? [exact] : [] : this.pendingIntents();
|
|
56
|
+
return intents.map(intent => ({ kind: 'task', id: this.progressKey(intent.owner, intent.request_key),
|
|
57
|
+
owner: intent.owner, management: { epoch: intent.epoch }, acceptedAt: this.progress(intent.owner, intent.request_key)?.acceptedAt ?? null,
|
|
58
|
+
lastProgressAt: this.progress(intent.owner, intent.request_key)?.lastProgressAt ?? null, executionDeadline: null, nextDeadline: null,
|
|
59
|
+
attempts: JSON.parse(intent.attempts).map(attempt => ({ id: attempt.id, sessionId: attempt.sessionId,
|
|
60
|
+
state: attempt.state, writer: { pid: attempt.writerPid ?? attempt.pid, start: attempt.writerStartTime ?? attempt.pidStartTime } })),
|
|
61
|
+
recovery: 'drain-accepted-launch-until-journal-return-or-authoritative-handoff' }));
|
|
62
|
+
}
|
|
63
|
+
finishRecovery(owner, key, epoch, result) {
|
|
64
|
+
this.transaction(() => {
|
|
65
|
+
this.current(epoch);
|
|
66
|
+
this.db.prepare("UPDATE subagent_launch_intents SET state='returned', result=? WHERE owner=? AND request_key=? AND state='accepted' AND epoch<?")
|
|
67
|
+
.run(JSON.stringify(result), owner, key, epoch);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
accept(owner, key, digest, epoch) {
|
|
71
|
+
return this.transaction(() => {
|
|
72
|
+
this.current(epoch);
|
|
73
|
+
const prior = this.read(owner, key);
|
|
74
|
+
if (prior) {
|
|
75
|
+
if (prior.digest !== digest)
|
|
76
|
+
throw new Error("request-conflict: launch key has different content");
|
|
77
|
+
return { prior: true, ...prior };
|
|
78
|
+
}
|
|
79
|
+
this.db.prepare("INSERT INTO subagent_launch_intents VALUES (?, ?, ?, ?, 'accepted', '[]', NULL)").run(owner, key, digest, epoch);
|
|
80
|
+
this.noteProgress(owner, key);
|
|
81
|
+
return this.read(owner, key);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
prepare(owner, key, epoch, input) {
|
|
85
|
+
return this.transaction(() => {
|
|
86
|
+
this.current(epoch);
|
|
87
|
+
const row = this.read(owner, key);
|
|
88
|
+
if (!row || row.epoch !== epoch || row.state !== "accepted")
|
|
89
|
+
throw new Error("Launch intent is not admitted");
|
|
90
|
+
const attempts = JSON.parse(row.attempts);
|
|
91
|
+
if (attempts.some(attempt => attempt.id === input.id))
|
|
92
|
+
throw new Error("Attempt already dispatched; reconcile exact identity");
|
|
93
|
+
const attempt = { ...input, token: randomBytes(32).toString("hex"), state: "prepared" };
|
|
94
|
+
attempts.push(attempt);
|
|
95
|
+
this.db.prepare("UPDATE subagent_launch_intents SET attempts=? WHERE owner=? AND request_key=?").run(JSON.stringify(attempts), owner, key);
|
|
96
|
+
this.noteProgress(owner, key);
|
|
97
|
+
return attempt;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
spawned(owner, key, epoch, id, pid, pidStartTime) {
|
|
101
|
+
this.transaction(() => {
|
|
102
|
+
this.current(epoch);
|
|
103
|
+
const attempts = JSON.parse(this.read(owner, key).attempts);
|
|
104
|
+
const attempt = attempts.find(value => value.id === id);
|
|
105
|
+
if (!attempt || attempt.state !== "prepared")
|
|
106
|
+
throw new Error("Launch publication is ambiguous");
|
|
107
|
+
if (attempt.writerPid && attempt.writerPid !== pid)
|
|
108
|
+
throw new Error("Launch writer does not match spawned process");
|
|
109
|
+
Object.assign(attempt, { state: "spawned", pid, pidStartTime });
|
|
110
|
+
this.db.prepare("UPDATE subagent_launch_intents SET attempts=? WHERE owner=? AND request_key=?").run(JSON.stringify(attempts), owner, key);
|
|
111
|
+
this.noteProgress(owner, key);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
finish(owner, key, epoch, result) {
|
|
115
|
+
this.transaction(() => {
|
|
116
|
+
this.current(epoch);
|
|
117
|
+
this.db.prepare("UPDATE subagent_launch_intents SET state='returned', result=? WHERE owner=? AND request_key=? AND epoch=?").run(JSON.stringify(result), owner, key, epoch);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Generated from packages/operation-coordinator/src/subagent-launch.ts. Do not edit directly.
|
|
2
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
3
|
+
import type { StoreContext } from "./sqlite.ts";
|
|
4
|
+
|
|
5
|
+
export interface LaunchAttempt {
|
|
6
|
+
id: string;
|
|
7
|
+
sessionId: string;
|
|
8
|
+
lease: string;
|
|
9
|
+
leasePath: string;
|
|
10
|
+
preflightPath: string;
|
|
11
|
+
preflightDigest: string;
|
|
12
|
+
policyPath?: string;
|
|
13
|
+
policyDigest?: string;
|
|
14
|
+
capacityOwner: { pid: number; start: string };
|
|
15
|
+
launchAuthority?: unknown;
|
|
16
|
+
recipe: unknown;
|
|
17
|
+
permissions: unknown;
|
|
18
|
+
token: string;
|
|
19
|
+
state: "prepared" | "spawned";
|
|
20
|
+
pid?: number;
|
|
21
|
+
writerPid?: number;
|
|
22
|
+
writerStartTime?: string;
|
|
23
|
+
pidStartTime?: string;
|
|
24
|
+
recoveryMeta?: unknown;
|
|
25
|
+
bootstrapped?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface LaunchIntent {
|
|
28
|
+
owner: string; request_key: string; digest: string; epoch: number;
|
|
29
|
+
state: "accepted" | "returned"; attempts: string; result: string | null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Fixed launch journal on the coordinator's existing connection and transaction. */
|
|
33
|
+
export class SubagentLaunchJournal {
|
|
34
|
+
private context: StoreContext;
|
|
35
|
+
private alive: () => void;
|
|
36
|
+
constructor(context: StoreContext, alive: () => void) {
|
|
37
|
+
this.context = context;
|
|
38
|
+
this.alive = alive;
|
|
39
|
+
this.transaction(() => this.db.exec(`CREATE TABLE IF NOT EXISTS subagent_launch_intents (
|
|
40
|
+
owner TEXT NOT NULL, request_key TEXT NOT NULL, digest TEXT NOT NULL,
|
|
41
|
+
epoch INTEGER NOT NULL, state TEXT NOT NULL, attempts TEXT NOT NULL, result TEXT,
|
|
42
|
+
PRIMARY KEY(owner, request_key));
|
|
43
|
+
CREATE TABLE IF NOT EXISTS subagent_management (singleton INTEGER PRIMARY KEY CHECK(singleton=1), instance TEXT NOT NULL, epoch INTEGER NOT NULL);`));
|
|
44
|
+
}
|
|
45
|
+
private get db() { this.alive(); return this.context.db; }
|
|
46
|
+
private transaction<T>(run: () => T): T { this.alive(); return this.context.transaction(run); }
|
|
47
|
+
epoch(instance: string) {
|
|
48
|
+
return this.transaction(() => {
|
|
49
|
+
const previous = this.db.prepare("SELECT * FROM subagent_management WHERE singleton=1").get();
|
|
50
|
+
if (previous?.instance === instance) return Number(previous.epoch);
|
|
51
|
+
const epoch = (Number(previous?.epoch ?? 0)) + 1;
|
|
52
|
+
this.db.prepare("INSERT OR REPLACE INTO subagent_management VALUES (1, ?, ?)").run(instance, epoch);
|
|
53
|
+
return epoch;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
current(epoch: number) {
|
|
57
|
+
if (this.db.prepare("SELECT epoch FROM subagent_management WHERE singleton=1").get()?.epoch !== epoch) throw new Error("stale-runtime-epoch");
|
|
58
|
+
}
|
|
59
|
+
read(owner: string, key: string): LaunchIntent | undefined { return this.db.prepare("SELECT * FROM subagent_launch_intents WHERE owner=? AND request_key=?").get(owner, key) as unknown as LaunchIntent | undefined; }
|
|
60
|
+
attempt(id: string): LaunchAttempt | undefined {
|
|
61
|
+
const row = this.db.prepare("SELECT j.value AS attempt FROM subagent_launch_intents, json_each(subagent_launch_intents.attempts) j WHERE json_extract(j.value, '$.id')=? LIMIT 1").get(id);
|
|
62
|
+
return row ? JSON.parse(String(row.attempt)) : undefined;
|
|
63
|
+
}
|
|
64
|
+
unresolvedAttempts() {
|
|
65
|
+
return this.db.prepare("SELECT j.value AS attempt FROM subagent_launch_intents, json_each(subagent_launch_intents.attempts) j WHERE subagent_launch_intents.state='accepted'").all().map(row => JSON.parse(String(row.attempt)));
|
|
66
|
+
}
|
|
67
|
+
pendingIntents(): LaunchIntent[] {
|
|
68
|
+
return this.db.prepare("SELECT * FROM subagent_launch_intents WHERE state='accepted'").all() as unknown as LaunchIntent[];
|
|
69
|
+
}
|
|
70
|
+
private progressKey(owner: string, key: string) { return `launch-progress:${createHash('sha256').update(JSON.stringify([owner, key])).digest('hex')}`; }
|
|
71
|
+
private progress(owner: string, key: string) {
|
|
72
|
+
const row = this.db.prepare('SELECT value FROM coordinator_state WHERE key=?').get(this.progressKey(owner, key));
|
|
73
|
+
return row ? JSON.parse(String(row.value)) as { acceptedAt: number; lastProgressAt: number } : undefined;
|
|
74
|
+
}
|
|
75
|
+
private noteProgress(owner: string, key: string) {
|
|
76
|
+
const previous = this.progress(owner, key), now = Date.now();
|
|
77
|
+
this.db.prepare('INSERT OR REPLACE INTO coordinator_state (key,value) VALUES (?,?)').run(this.progressKey(owner, key),
|
|
78
|
+
JSON.stringify({ acceptedAt: previous?.acceptedAt ?? now, lastProgressAt: now }));
|
|
79
|
+
}
|
|
80
|
+
lifecycleReasons(owner?: string, key?: string) {
|
|
81
|
+
const exact = owner !== undefined && key !== undefined ? this.read(owner, key) : undefined;
|
|
82
|
+
const intents = owner !== undefined ? exact?.state === 'accepted' ? [exact] : [] : this.pendingIntents();
|
|
83
|
+
return intents.map(intent => ({ kind: 'task', id: this.progressKey(intent.owner, intent.request_key),
|
|
84
|
+
owner: intent.owner, management: { epoch: intent.epoch }, acceptedAt: this.progress(intent.owner, intent.request_key)?.acceptedAt ?? null,
|
|
85
|
+
lastProgressAt: this.progress(intent.owner, intent.request_key)?.lastProgressAt ?? null, executionDeadline: null, nextDeadline: null,
|
|
86
|
+
attempts: (JSON.parse(intent.attempts) as LaunchAttempt[]).map(attempt => ({ id: attempt.id, sessionId: attempt.sessionId,
|
|
87
|
+
state: attempt.state, writer: { pid: attempt.writerPid ?? attempt.pid, start: attempt.writerStartTime ?? attempt.pidStartTime } })),
|
|
88
|
+
recovery: 'drain-accepted-launch-until-journal-return-or-authoritative-handoff' }));
|
|
89
|
+
}
|
|
90
|
+
finishRecovery(owner: string, key: string, epoch: number, result: unknown) {
|
|
91
|
+
this.transaction(() => {
|
|
92
|
+
this.current(epoch);
|
|
93
|
+
this.db.prepare("UPDATE subagent_launch_intents SET state='returned', result=? WHERE owner=? AND request_key=? AND state='accepted' AND epoch<?")
|
|
94
|
+
.run(JSON.stringify(result), owner, key, epoch);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
accept(owner: string, key: string, digest: string, epoch: number) {
|
|
98
|
+
return this.transaction(() => {
|
|
99
|
+
this.current(epoch);
|
|
100
|
+
const prior = this.read(owner, key);
|
|
101
|
+
if (prior) {
|
|
102
|
+
if (prior.digest !== digest) throw new Error("request-conflict: launch key has different content");
|
|
103
|
+
return { prior: true, ...prior };
|
|
104
|
+
}
|
|
105
|
+
this.db.prepare("INSERT INTO subagent_launch_intents VALUES (?, ?, ?, ?, 'accepted', '[]', NULL)").run(owner, key, digest, epoch);
|
|
106
|
+
this.noteProgress(owner, key);
|
|
107
|
+
return this.read(owner, key);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
prepare(owner: string, key: string, epoch: number, input: Omit<LaunchAttempt, "token" | "state">) {
|
|
111
|
+
return this.transaction(() => {
|
|
112
|
+
this.current(epoch);
|
|
113
|
+
const row = this.read(owner, key);
|
|
114
|
+
if (!row || row.epoch !== epoch || row.state !== "accepted") throw new Error("Launch intent is not admitted");
|
|
115
|
+
const attempts: LaunchAttempt[] = JSON.parse(row.attempts);
|
|
116
|
+
if (attempts.some(attempt => attempt.id === input.id)) throw new Error("Attempt already dispatched; reconcile exact identity");
|
|
117
|
+
const attempt: LaunchAttempt = { ...input, token: randomBytes(32).toString("hex"), state: "prepared" };
|
|
118
|
+
attempts.push(attempt);
|
|
119
|
+
this.db.prepare("UPDATE subagent_launch_intents SET attempts=? WHERE owner=? AND request_key=?").run(JSON.stringify(attempts), owner, key);
|
|
120
|
+
this.noteProgress(owner, key);
|
|
121
|
+
return attempt;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
spawned(owner: string, key: string, epoch: number, id: string, pid: number, pidStartTime?: string) {
|
|
125
|
+
this.transaction(() => {
|
|
126
|
+
this.current(epoch);
|
|
127
|
+
const attempts = JSON.parse(this.read(owner, key)!.attempts) as LaunchAttempt[];
|
|
128
|
+
const attempt = attempts.find(value => value.id === id);
|
|
129
|
+
if (!attempt || attempt.state !== "prepared") throw new Error("Launch publication is ambiguous");
|
|
130
|
+
if (attempt.writerPid && attempt.writerPid !== pid) throw new Error("Launch writer does not match spawned process");
|
|
131
|
+
Object.assign(attempt, { state: "spawned", pid, pidStartTime });
|
|
132
|
+
this.db.prepare("UPDATE subagent_launch_intents SET attempts=? WHERE owner=? AND request_key=?").run(JSON.stringify(attempts), owner, key);
|
|
133
|
+
this.noteProgress(owner, key);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
finish(owner: string, key: string, epoch: number, result: unknown) {
|
|
137
|
+
this.transaction(() => {
|
|
138
|
+
this.current(epoch);
|
|
139
|
+
this.db.prepare("UPDATE subagent_launch_intents SET state='returned', result=? WHERE owner=? AND request_key=? AND epoch=?").run(JSON.stringify(result), owner, key, epoch);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-cancellation.domain.mjs
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-subagents/shared-operation-coordinator/src/task-cancellation.ts. Do not edit directly.
|
|
2
|
+
// Generated from packages/operation-coordinator/src/task-cancellation.ts. Do not edit directly.
|
|
3
|
+
/**
|
|
4
|
+
* Durable intent for the fixed cancel_task operation. Admission and process
|
|
5
|
+
* identity checks remain the host's responsibility. An accepted intent is not
|
|
6
|
+
* evidence that a process stopped; recovery must use its original launch token.
|
|
7
|
+
*/
|
|
8
|
+
import { StoreError } from "./errors.domain.mjs";
|
|
9
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
10
|
+
import { getOperation, recordTerminalOutcome } from "./operations.domain.mjs";
|
|
11
|
+
import { columnText, getRow, run } from "./sqlite.domain.mjs";
|
|
12
|
+
import { normalizeOwner, requireCounter, requireId, requireText, sameOwner } from "./validate.domain.mjs";
|
|
13
|
+
export function cancellationRuntimeEpoch(ctx, instanceId) {
|
|
14
|
+
return ctx.transaction(() => {
|
|
15
|
+
const row = getRow(ctx, "SELECT value FROM coordinator_state WHERE key = 'cancellation-runtime'");
|
|
16
|
+
const current = row ? JSON.parse(columnText(row, "value")) : { epoch: 0 };
|
|
17
|
+
if (!instanceId || current.instanceId === instanceId)
|
|
18
|
+
return current.epoch;
|
|
19
|
+
const epoch = current.epoch + 1;
|
|
20
|
+
run(ctx, "INSERT INTO coordinator_state (key, value) VALUES ('cancellation-runtime', ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value", JSON.stringify({ instanceId, epoch }));
|
|
21
|
+
return epoch;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function cancelEpoch(ctx, operationId) {
|
|
25
|
+
const row = getRow(ctx, "SELECT value FROM coordinator_state WHERE key = ?", `cancel:${operationId}`);
|
|
26
|
+
return row ? Number(columnText(row, "value")) : 0;
|
|
27
|
+
}
|
|
28
|
+
function revision(operation, epoch) {
|
|
29
|
+
const op = operation;
|
|
30
|
+
return createHash("sha256").update(JSON.stringify([op && {
|
|
31
|
+
operationId: op.operationId, owner: op.owner, launchToken: op.launchToken,
|
|
32
|
+
terminalRevision: op.terminalRevision, phase: op.phase, authorityRef: op.authorityRef,
|
|
33
|
+
hostId: op.supervision?.hostId,
|
|
34
|
+
}, epoch])).digest("hex");
|
|
35
|
+
}
|
|
36
|
+
export function taskCancellationManaged(ctx, operationId) {
|
|
37
|
+
return !!getRow(ctx, "SELECT credential_hash FROM task_cancellation_authorities WHERE json_extract(request_json, '$.request.operationId') = ? LIMIT 1", requireId("operationId", operationId));
|
|
38
|
+
}
|
|
39
|
+
export function pendingTaskCancellations(ctx) {
|
|
40
|
+
return ctx.db.prepare("SELECT a.* FROM task_cancellation_authorities a JOIN task_cancellation_requests r ON json_extract(a.request_json, '$.request.operationId') = r.operation_id AND json_extract(a.request_json, '$.request.idempotencyKey') = r.request_key WHERE r.result_json IS NULL").all()
|
|
41
|
+
.map(row => ({ credentialHash: columnText(row, "credential_hash"), ...JSON.parse(columnText(row, "request_json")), directory: columnText(row, "directory") }));
|
|
42
|
+
}
|
|
43
|
+
export function acceptAuthorizedTaskCancellation(ctx, input) {
|
|
44
|
+
return ctx.transaction(() => {
|
|
45
|
+
const admission = authorizedTaskCancellation(ctx, input.credential);
|
|
46
|
+
const previous = getTaskCancellation(ctx, admission.request);
|
|
47
|
+
if (previous)
|
|
48
|
+
return acceptTaskCancellation(ctx, admission.request);
|
|
49
|
+
if (input.runtimeEpoch !== cancellationRuntimeEpoch(ctx) || input.runtimeEpoch !== admission.runtimeEpoch)
|
|
50
|
+
throw new StoreError("supervision-conflict", "not_accepted: stale-runtime-epoch; query journal before new admission");
|
|
51
|
+
const operation = getOperation(ctx, admission.request.operationId);
|
|
52
|
+
const epoch = cancelEpoch(ctx, admission.request.operationId);
|
|
53
|
+
if (epoch !== admission.cancelEpoch || revision(operation, epoch) !== admission.revision)
|
|
54
|
+
throw new StoreError("operation-conflict", "not_accepted: stale-revision or cancellation epoch");
|
|
55
|
+
const intent = acceptTaskCancellation(ctx, admission.request);
|
|
56
|
+
run(ctx, "INSERT INTO coordinator_state (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value", `cancel:${intent.operationId}`, String(epoch + 1));
|
|
57
|
+
return intent;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
export function cancellationCredential() {
|
|
61
|
+
const credential = randomBytes(32).toString("hex");
|
|
62
|
+
return { credential, hash: credentialHash(credential) };
|
|
63
|
+
}
|
|
64
|
+
function credentialHash(credential) {
|
|
65
|
+
return createHash("sha256").update(requireText("credential", credential, 128)).digest("hex");
|
|
66
|
+
}
|
|
67
|
+
/** Called only by the existing admitted domain host, never by a socket command. */
|
|
68
|
+
export function admitTaskCancellation(ctx, input) {
|
|
69
|
+
const normalized = request(input.request);
|
|
70
|
+
const hash = requireId("credentialHash", input.credentialHash);
|
|
71
|
+
const directory = requireText("directory", input.directory, 4096);
|
|
72
|
+
ctx.transaction(() => {
|
|
73
|
+
const operation = getOperation(ctx, normalized.operationId);
|
|
74
|
+
if (!operation || !sameOwner(operation.owner, normalized.owner))
|
|
75
|
+
throw new StoreError("foreign-owner", "Cancellation admission requires the recorded owner.");
|
|
76
|
+
const previous = getTaskCancellation(ctx, normalized);
|
|
77
|
+
if (operation.launchToken !== normalized.expectedLaunchToken || (!previous && operation.supervision?.hostId !== normalized.expectedHostId)) {
|
|
78
|
+
throw new StoreError("supervision-conflict", "Cancellation admission requires the current exact launch and host.");
|
|
79
|
+
}
|
|
80
|
+
if (previous && JSON.stringify(request(previous)) !== JSON.stringify(normalized))
|
|
81
|
+
throw new StoreError("request-conflict", "Cancellation key is bound to different request content.");
|
|
82
|
+
const original = previous ? request(previous) : normalized;
|
|
83
|
+
const epoch = cancelEpoch(ctx, normalized.operationId);
|
|
84
|
+
run(ctx, "INSERT INTO task_cancellation_authorities (credential_hash, request_json, directory) VALUES (?, ?, ?)", hash, JSON.stringify({ request: original, runtimeEpoch: cancellationRuntimeEpoch(ctx), cancelEpoch: epoch, revision: revision(operation, epoch) }), directory);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/** A credential binds an already-admitted exact request, not a claimed session ID. */
|
|
88
|
+
export function authorizedTaskCancellation(ctx, credential) {
|
|
89
|
+
const row = getRow(ctx, "SELECT * FROM task_cancellation_authorities WHERE credential_hash = ?", credentialHash(credential));
|
|
90
|
+
if (!row)
|
|
91
|
+
throw new StoreError("foreign-owner", "permission-unavailable: cancellation authority is not registered.");
|
|
92
|
+
return { credentialHash: credentialHash(credential), ...JSON.parse(columnText(row, "request_json")), directory: columnText(row, "directory") };
|
|
93
|
+
}
|
|
94
|
+
export function finishTaskCancellation(ctx, input) {
|
|
95
|
+
const admission = authorizedTaskCancellation(ctx, input.credential);
|
|
96
|
+
return finishTaskCancellationIntent(ctx, { request: admission.request, status: input.status, terminal: input.terminal });
|
|
97
|
+
}
|
|
98
|
+
export function finishTaskCancellationIntent(ctx, input) {
|
|
99
|
+
return ctx.transaction(() => {
|
|
100
|
+
const intent = recordTaskStopRequested(ctx, input.request);
|
|
101
|
+
if (intent.result)
|
|
102
|
+
return intent;
|
|
103
|
+
if (input.publication) {
|
|
104
|
+
if (input.publication.operationId !== intent.operationId || !sameOwner(input.publication.owner, intent.owner))
|
|
105
|
+
throw new StoreError("foreign-owner", "Terminal publication does not match the cancellation intent.");
|
|
106
|
+
recordTerminalOutcome(ctx, input.publication);
|
|
107
|
+
}
|
|
108
|
+
const result = { status: requireText("status", input.status, 64), terminal: input.terminal === true };
|
|
109
|
+
run(ctx, "UPDATE task_cancellation_requests SET result_json = ? WHERE owner_key = ? AND request_key = ?", JSON.stringify(result), ownerKey(intent.owner), intent.idempotencyKey);
|
|
110
|
+
return { ...intent, result };
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
export function unknownTaskCancellation(ctx, input) {
|
|
114
|
+
return ctx.transaction(() => {
|
|
115
|
+
const intent = getTaskCancellation(ctx, input);
|
|
116
|
+
if (!intent)
|
|
117
|
+
throw new StoreError("request-conflict", "Cannot record an unknown outcome without an accepted intent.");
|
|
118
|
+
if (intent.result)
|
|
119
|
+
return intent;
|
|
120
|
+
const result = { status: "outcome_unknown", terminal: false };
|
|
121
|
+
run(ctx, "UPDATE task_cancellation_requests SET result_json = ? WHERE owner_key = ? AND request_key = ?", JSON.stringify(result), ownerKey(intent.owner), intent.idempotencyKey);
|
|
122
|
+
return { ...intent, result };
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
function ownerKey(owner) {
|
|
126
|
+
return JSON.stringify([owner.kind, owner.sessionId, owner.workspace, owner.branchId, owner.goalId]);
|
|
127
|
+
}
|
|
128
|
+
function request(input) {
|
|
129
|
+
return {
|
|
130
|
+
owner: normalizeOwner("owner", input.owner),
|
|
131
|
+
idempotencyKey: requireText("idempotencyKey", input.idempotencyKey, 512),
|
|
132
|
+
operationId: requireId("operationId", input.operationId),
|
|
133
|
+
expectedLaunchToken: requireId("launchToken", input.expectedLaunchToken),
|
|
134
|
+
expectedTerminalRevision: requireCounter("terminalRevision", input.expectedTerminalRevision),
|
|
135
|
+
expectedHostId: requireId("hostId", input.expectedHostId),
|
|
136
|
+
reason: requireText("reason", input.reason, 1024),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
export function getTaskCancellation(ctx, input) {
|
|
140
|
+
const owner = normalizeOwner("owner", input.owner);
|
|
141
|
+
const key = requireText("idempotencyKey", input.idempotencyKey, 512);
|
|
142
|
+
const row = getRow(ctx, "SELECT intent_json, state, result_json FROM task_cancellation_requests WHERE owner_key = ? AND request_key = ?", ownerKey(owner), key);
|
|
143
|
+
if (!row)
|
|
144
|
+
return null;
|
|
145
|
+
return { ...JSON.parse(columnText(row, "intent_json")), state: columnText(row, "state"), ...(row.result_json ? { result: JSON.parse(columnText(row, "result_json")) } : {}) };
|
|
146
|
+
}
|
|
147
|
+
export function acceptTaskCancellation(ctx, input) {
|
|
148
|
+
const normalized = request(input);
|
|
149
|
+
return ctx.transaction(() => {
|
|
150
|
+
// Journal lookup precedes current object checks: a retry after terminal
|
|
151
|
+
// publication must recover the original receipt, not become a new stop.
|
|
152
|
+
const previous = getTaskCancellation(ctx, normalized);
|
|
153
|
+
if (previous) {
|
|
154
|
+
const { operation: _operation, taskId: _taskId, state: _state, acceptedAt: _at, result: _result, ...original } = previous;
|
|
155
|
+
if (JSON.stringify(original) !== JSON.stringify(normalized)) {
|
|
156
|
+
throw new StoreError("request-conflict", "Cancellation key is already bound to different request content.");
|
|
157
|
+
}
|
|
158
|
+
return previous;
|
|
159
|
+
}
|
|
160
|
+
const operation = getOperation(ctx, normalized.operationId);
|
|
161
|
+
if (!operation)
|
|
162
|
+
throw new StoreError("unknown-operation", "Cancellation operation does not exist.");
|
|
163
|
+
if (!sameOwner(operation.owner, normalized.owner))
|
|
164
|
+
throw new StoreError("foreign-owner", "Cancellation requires the recorded execution owner.");
|
|
165
|
+
if (operation.launchToken !== normalized.expectedLaunchToken || operation.terminalRevision !== normalized.expectedTerminalRevision) {
|
|
166
|
+
throw new StoreError("operation-conflict", "Cancellation launch token or terminal revision changed.");
|
|
167
|
+
}
|
|
168
|
+
if (operation.supervision?.hostId !== normalized.expectedHostId) {
|
|
169
|
+
throw new StoreError("supervision-conflict", "Cancellation supervision host changed.");
|
|
170
|
+
}
|
|
171
|
+
const intent = {
|
|
172
|
+
...normalized, operation: "cancel_task", taskId: operation.taskId, state: "accepted", acceptedAt: ctx.now(),
|
|
173
|
+
};
|
|
174
|
+
run(ctx, "INSERT INTO task_cancellation_requests (owner_key, request_key, operation_id, intent_json, state) VALUES (?, ?, ?, ?, 'accepted')", ownerKey(normalized.owner), normalized.idempotencyKey, operation.operationId, JSON.stringify(intent));
|
|
175
|
+
return intent;
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
/** Record durable stop-file publication, never process exit or a terminal verdict. */
|
|
179
|
+
export function recordTaskStopRequested(ctx, input) {
|
|
180
|
+
return ctx.transaction(() => {
|
|
181
|
+
const normalized = request(input);
|
|
182
|
+
if (!getTaskCancellation(ctx, normalized))
|
|
183
|
+
throw new StoreError("request-conflict", "Cancellation intent must commit before the stop action.");
|
|
184
|
+
const intent = acceptTaskCancellation(ctx, normalized);
|
|
185
|
+
run(ctx, "UPDATE task_cancellation_requests SET state = 'stop-requested' WHERE owner_key = ? AND request_key = ?", ownerKey(normalized.owner), normalized.idempotencyKey);
|
|
186
|
+
return { ...intent, state: "stop-requested" };
|
|
187
|
+
});
|
|
188
|
+
}
|