pi-better-server 0.5.0 → 0.7.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 +7 -3
- 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 +37 -5
- package/scripts/event-publication/writer.mjs +3 -8
- package/scripts/measure-full-runtime/frontend.ts +10 -2
- package/scripts/measure-full-runtime/probe.mjs +4 -2
- 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 +2 -0
- package/scripts/measure-shared-reads.mjs +2 -1
- package/scripts/private-runtime/package-lock.json +18 -0
- package/scripts/private-runtime/package.json +4 -1
- package/scripts/source-provenance.mjs +2 -2
- package/scripts/test-on-pi.sh +2 -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 +9 -4
- package/src/runtime/background-tools.ts +181 -27
- package/src/runtime/background.ts +365 -70
- 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 +43 -35
- package/src/runtime/domain/background/process-identity.mjs +20 -2
- package/src/runtime/domain/background/process.mjs +52 -14
- package/src/runtime/domain/background/registry.mjs +61 -3
- package/src/runtime/domain/background/supervisor/store.mjs +3 -3
- package/src/runtime/domain/background/supervisor/supervisor.mjs +9 -3
- package/src/runtime/domain/background/types.mjs +1 -0
- package/src/runtime/domain/background-service/adapter-contract.domain.mjs +1 -1
- package/src/runtime/domain/background-service/adapter-contract.ts +1 -1
- package/src/runtime/domain/background-service/goal-provider.domain.mjs +35 -16
- package/src/runtime/domain/background-service/goal-provider.ts +31 -16
- package/src/runtime/domain/background-service/index.domain.mjs +25 -9
- package/src/runtime/domain/background-service/index.ts +25 -9
- package/src/runtime/domain/background-service/managed-authority.domain.mjs +6 -3
- package/src/runtime/domain/background-service/managed-authority.ts +5 -3
- package/src/runtime/domain/background-service/managed-client.domain.mjs +21 -7
- package/src/runtime/domain/background-service/managed-client.ts +20 -7
- package/src/runtime/domain/background-service/managed-frontend.domain.mjs +159 -19
- package/src/runtime/domain/background-service/managed-frontend.ts +135 -19
- package/src/runtime/domain/background-service/navigator-provider.domain.mjs +21 -5
- package/src/runtime/domain/background-service/navigator-provider.ts +19 -5
- 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 +372 -57
- package/src/runtime/domain/background-service/observed-waits.ts +321 -53
- package/src/runtime/domain/background-service/process-identity.domain.mjs +20 -2
- package/src/runtime/domain/background-service/process-identity.ts +18 -2
- package/src/runtime/domain/background-service/process.domain.mjs +52 -14
- package/src/runtime/domain/background-service/process.ts +48 -14
- package/src/runtime/domain/background-service/registry.domain.mjs +61 -3
- package/src/runtime/domain/background-service/registry.ts +53 -5
- package/src/runtime/domain/background-service/review-settings.domain.mjs +16 -0
- package/src/runtime/domain/background-service/review-settings.ts +18 -0
- package/src/runtime/domain/background-service/runtime.domain.mjs +40 -86
- package/src/runtime/domain/background-service/runtime.ts +27 -82
- package/src/runtime/domain/background-service/sandbox.domain.mjs +14 -15
- package/src/runtime/domain/background-service/sandbox.ts +14 -11
- package/src/runtime/domain/background-service/shared-callback-batcher.domain.mjs +8 -1
- package/src/runtime/domain/background-service/shared-callback-batcher.ts +11 -2
- package/src/runtime/domain/background-service/shared-navigator-panels.domain.mjs +24 -2
- package/src/runtime/domain/background-service/shared-navigator-panels.ts +26 -4
- package/src/runtime/domain/background-service/shared-navigator.domain.mjs +273 -41
- package/src/runtime/domain/background-service/shared-navigator.ts +244 -40
- 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 +53 -41
- 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 +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.ts +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.domain.mjs +11 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.ts +14 -3
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.domain.mjs +4 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.ts +5 -3
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.domain.mjs +44 -4
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.ts +50 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.domain.mjs +7 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.ts +9 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.domain.mjs +12 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.ts +12 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.domain.mjs +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.ts +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.domain.mjs +42 -21
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.ts +40 -24
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +26 -4
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +40 -8
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.domain.mjs +23 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.ts +24 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.domain.mjs +1 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.ts +5 -1
- package/src/runtime/domain/background-service/shared-sandbox-core.ts +1 -1
- package/src/runtime/domain/background-service/shared-work-client.mjs +174 -7
- package/src/runtime/domain/background-service/stall.domain.mjs +5 -3
- package/src/runtime/domain/background-service/stall.ts +7 -4
- package/src/runtime/domain/background-service/supervised-progress.domain.mjs +42 -0
- package/src/runtime/domain/background-service/supervised-progress.ts +43 -0
- package/src/runtime/domain/background-service/supervisor/README.md +1 -4
- package/src/runtime/domain/background-service/supervisor/emit-runner.mjs +1 -0
- package/src/runtime/domain/background-service/supervisor/generated/process-identity.mjs +20 -2
- package/src/runtime/domain/background-service/supervisor/generated/process.mjs +52 -14
- package/src/runtime/domain/background-service/supervisor/generated/runner.mjs +47 -4
- package/src/runtime/domain/background-service/supervisor/generated/store.mjs +3 -3
- package/src/runtime/domain/background-service/supervisor/generated/watch-fingerprint.mjs +69 -0
- package/src/runtime/domain/background-service/supervisor/runner.domain.mjs +47 -4
- package/src/runtime/domain/background-service/supervisor/runner.ts +38 -3
- package/src/runtime/domain/background-service/supervisor/store.domain.mjs +3 -3
- package/src/runtime/domain/background-service/supervisor/store.ts +3 -3
- package/src/runtime/domain/background-service/supervisor/supervisor.domain.mjs +9 -3
- package/src/runtime/domain/background-service/supervisor/supervisor.ts +6 -3
- package/src/runtime/domain/background-service/task-diagnostics.domain.mjs +1 -1
- package/src/runtime/domain/background-service/task-diagnostics.ts +1 -1
- package/src/runtime/domain/background-service/tools.domain.mjs +53 -40
- package/src/runtime/domain/background-service/tools.ts +67 -54
- package/src/runtime/domain/background-service/types.domain.mjs +1 -0
- package/src/runtime/domain/background-service/types.ts +7 -3
- package/src/runtime/domain/background-service/watch-fingerprint.domain.mjs +67 -0
- package/src/runtime/domain/background-service/watch-fingerprint.ts +70 -0
- package/src/runtime/domain/background-service/work-observation.domain.mjs +46 -20
- package/src/runtime/domain/background-service/work-observation.ts +46 -19
- 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-requests.mjs +11 -2
- 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/outbox.mjs +7 -0
- 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 +42 -21
- package/src/runtime/domain/coordinator/src/store.mjs +26 -4
- package/src/runtime/domain/coordinator/src/subagent-launch.mjs +23 -1
- package/src/runtime/domain/coordinator/src/types.mjs +1 -1
- 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/log-paths.mjs +8 -1
- package/src/runtime/domain/parse.d.mts +4 -1
- package/src/runtime/domain/parse.mjs +58 -9
- package/src/runtime/domain/sandbox-policy/README.md +63 -65
- package/src/runtime/domain/sandbox-policy/commands.domain.mjs +11 -8
- package/src/runtime/domain/sandbox-policy/commands.ts +12 -7
- package/src/runtime/domain/sandbox-policy/index.domain.mjs +53 -9
- package/src/runtime/domain/sandbox-policy/index.ts +52 -9
- package/src/runtime/domain/sandbox-policy/package.json +1 -1
- package/src/runtime/domain/sandbox-policy/permission-settings.domain.mjs +5 -2
- package/src/runtime/domain/sandbox-policy/permission-settings.ts +9 -2
- package/src/runtime/domain/sandbox-policy/permissions-page.domain.mjs +56 -137
- package/src/runtime/domain/sandbox-policy/permissions-page.ts +52 -130
- package/src/runtime/domain/sandbox-policy/permissions.domain.mjs +1 -6
- package/src/runtime/domain/sandbox-policy/permissions.ts +1 -6
- package/src/runtime/domain/sandbox-policy/shared-sandbox-core.ts +1 -1
- package/src/runtime/domain/sandbox-policy/shared-task-exec.domain.mjs +14 -1
- package/src/runtime/domain/sandbox-policy/shared-task-exec.ts +12 -1
- 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 +3 -2
- package/src/runtime/domain/sandbox-policy/shared-task-process-list.ts +8 -2
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.domain.mjs +4 -3
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.ts +5 -3
- package/src/runtime/domain/sandbox-policy/shared-task-tools.domain.mjs +8 -5
- package/src/runtime/domain/sandbox-policy/shared-task-tools.ts +8 -5
- package/src/runtime/domain/session-store.mjs +7 -0
- package/src/runtime/domain/subagents/README.md +13 -11
- package/src/runtime/domain/subagents/assignment-outcomes.domain.mjs +10 -7
- package/src/runtime/domain/subagents/assignment-outcomes.ts +9 -6
- package/src/runtime/domain/subagents/assignment-report.domain.mjs +109 -24
- package/src/runtime/domain/subagents/assignment-report.ts +103 -19
- package/src/runtime/domain/subagents/batch.mjs +13 -5
- package/src/runtime/domain/subagents/catalog-host-admission.domain.mjs +21 -3
- package/src/runtime/domain/subagents/catalog-host-admission.ts +19 -3
- package/src/runtime/domain/subagents/catalog-preferences.ts +1 -1
- package/src/runtime/domain/subagents/catalog-resolver.domain.mjs +35 -1
- package/src/runtime/domain/subagents/catalog-resolver.ts +35 -1
- package/src/runtime/domain/subagents/catalog-store.domain.mjs +20 -22
- package/src/runtime/domain/subagents/catalog-store.ts +27 -20
- 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-dependencies.mjs +27 -15
- package/src/runtime/domain/subagents/child-operations.domain.mjs +80 -2
- package/src/runtime/domain/subagents/child-operations.ts +80 -1
- package/src/runtime/domain/subagents/child-preflight.mjs +9 -2
- 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/cleanup.domain.mjs +11 -2
- package/src/runtime/domain/subagents/cleanup.ts +10 -2
- package/src/runtime/domain/subagents/config.domain.mjs +54 -2
- package/src/runtime/domain/subagents/config.ts +53 -3
- package/src/runtime/domain/subagents/continuation-authority.domain.mjs +5 -1
- package/src/runtime/domain/subagents/continuation-authority.ts +3 -1
- 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 +4 -2
- package/src/runtime/domain/subagents/continuation.ts +4 -2
- package/src/runtime/domain/subagents/extensions.mjs +11 -13
- package/src/runtime/domain/subagents/failures.domain.mjs +11 -2
- package/src/runtime/domain/subagents/failures.ts +10 -2
- package/src/runtime/domain/subagents/finalization.domain.mjs +16 -1
- package/src/runtime/domain/subagents/finalization.ts +21 -1
- package/src/runtime/domain/subagents/goal-provider.domain.mjs +44 -2
- package/src/runtime/domain/subagents/goal-provider.ts +44 -2
- package/src/runtime/domain/subagents/health-observation.domain.mjs +189 -190
- package/src/runtime/domain/subagents/health-observation.ts +43 -48
- package/src/runtime/domain/subagents/index.domain.mjs +457 -182
- package/src/runtime/domain/subagents/index.ts +417 -155
- package/src/runtime/domain/subagents/isolated-workspace.domain.mjs +515 -0
- package/src/runtime/domain/subagents/isolated-workspace.ts +557 -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/list.mjs +2 -2
- package/src/runtime/domain/subagents/log-cursor.domain.mjs +85 -16
- package/src/runtime/domain/subagents/log-cursor.ts +91 -15
- package/src/runtime/domain/subagents/managed-launch-bootstrap.mjs +2 -2
- package/src/runtime/domain/subagents/managed-launch-client.domain.mjs +27 -7
- package/src/runtime/domain/subagents/managed-launch-client.ts +28 -8
- package/src/runtime/domain/subagents/managed-launch-host.domain.mjs +222 -14
- package/src/runtime/domain/subagents/managed-launch-host.ts +168 -15
- package/src/runtime/domain/subagents/managed-launch-journal.mjs +1 -5
- package/src/runtime/domain/subagents/managed-launch-port.ts +4 -0
- package/src/runtime/domain/subagents/operation-bridge-types.domain.mjs +27 -2
- package/src/runtime/domain/subagents/operation-bridge-types.ts +27 -2
- package/src/runtime/domain/subagents/output-payload.domain.mjs +24 -9
- package/src/runtime/domain/subagents/output-payload.ts +26 -12
- 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 +4 -2
- package/src/runtime/domain/subagents/parse.domain.mjs +58 -9
- package/src/runtime/domain/subagents/parse.ts +57 -10
- package/src/runtime/domain/subagents/permission-policy.domain.mjs +32 -8
- package/src/runtime/domain/subagents/permission-policy.ts +41 -8
- package/src/runtime/domain/subagents/process-identity.mjs +33 -0
- package/src/runtime/domain/subagents/registry.domain.mjs +71 -51
- package/src/runtime/domain/subagents/registry.ts +77 -38
- package/src/runtime/domain/subagents/retained-result.domain.mjs +56 -0
- package/src/runtime/domain/subagents/retained-result.ts +65 -0
- package/src/runtime/domain/subagents/session-selection.domain.mjs +3 -1
- package/src/runtime/domain/subagents/session-selection.ts +2 -1
- package/src/runtime/domain/subagents/session-store.domain.mjs +7 -0
- package/src/runtime/domain/subagents/session-store.ts +9 -0
- package/src/runtime/domain/subagents/settings-page.domain.mjs +151 -107
- package/src/runtime/domain/subagents/settings-page.ts +147 -108
- package/src/runtime/domain/subagents/shared-callback-batcher.domain.mjs +8 -1
- package/src/runtime/domain/subagents/shared-callback-batcher.ts +11 -2
- package/src/runtime/domain/subagents/shared-catalog.domain.mjs +28 -29
- package/src/runtime/domain/subagents/shared-catalog.ts +29 -21
- package/src/runtime/domain/subagents/shared-navigator-panels.domain.mjs +24 -2
- package/src/runtime/domain/subagents/shared-navigator-panels.ts +26 -4
- package/src/runtime/domain/subagents/shared-navigator.domain.mjs +273 -41
- package/src/runtime/domain/subagents/shared-navigator.ts +244 -40
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-inbox.mjs +144 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-observation.mjs +53 -41
- 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 +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.ts +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.domain.mjs +11 -2
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.ts +14 -3
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.domain.mjs +4 -2
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.ts +5 -3
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.domain.mjs +44 -4
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.ts +50 -2
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.domain.mjs +7 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.ts +9 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.domain.mjs +12 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.ts +12 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.domain.mjs +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.ts +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.domain.mjs +42 -21
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.ts +40 -24
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +26 -4
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +40 -8
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.domain.mjs +23 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.ts +24 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.domain.mjs +1 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.ts +5 -1
- package/src/runtime/domain/subagents/shared-sandbox-core.ts +1 -1
- package/src/runtime/domain/subagents/shared-task-exec.domain.mjs +14 -1
- package/src/runtime/domain/subagents/shared-task-exec.ts +12 -1
- 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 +3 -2
- package/src/runtime/domain/subagents/shared-task-process-list.ts +8 -2
- package/src/runtime/domain/subagents/shared-task-sandbox.domain.mjs +4 -3
- package/src/runtime/domain/subagents/shared-task-sandbox.ts +5 -3
- package/src/runtime/domain/subagents/shared-task-tools.domain.mjs +8 -5
- package/src/runtime/domain/subagents/shared-task-tools.ts +8 -5
- package/src/runtime/domain/subagents/shared-work-client.mjs +174 -7
- package/src/runtime/domain/subagents/subagent-tools.domain.mjs +22 -38
- package/src/runtime/domain/subagents/subagent-tools.ts +28 -34
- package/src/runtime/domain/subagents/task-guard.domain.mjs +14 -1
- package/src/runtime/domain/subagents/task-guard.ts +13 -1
- package/src/runtime/domain/subagents/task-policy.domain.mjs +3 -2
- package/src/runtime/domain/subagents/task-policy.ts +8 -2
- package/src/runtime/domain/subagents/timing.domain.mjs +10 -1
- package/src/runtime/domain/subagents/timing.ts +10 -1
- package/src/runtime/domain/subagents/tools.domain.mjs +4 -8
- package/src/runtime/domain/subagents/tools.ts +4 -7
- package/src/runtime/domain/subagents/work-observation.domain.mjs +102 -17
- package/src/runtime/domain/subagents/work-observation.ts +91 -17
- package/src/runtime/domain/subagents/worker-operations-host.domain.mjs +9 -4
- package/src/runtime/domain/subagents/worker-operations-host.ts +12 -4
- package/src/runtime/domain/subagents/worker-waits.domain.mjs +89 -35
- package/src/runtime/domain/subagents/worker-waits.ts +93 -34
- package/src/runtime/domain/subagents/workspace-files.domain.mjs +103 -0
- package/src/runtime/domain/subagents/workspace-files.ts +114 -0
- package/src/runtime/domain/subagents/workspace-scope.domain.d.mts +38 -0
- package/src/runtime/domain/subagents/workspace-scope.domain.mjs +5 -0
- package/src/runtime/domain/subagents/workspace-scope.ts +6 -0
- package/src/runtime/domain/subagents/worktree-feedback.domain.mjs +55 -0
- package/src/runtime/domain/subagents/worktree-feedback.ts +77 -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 +25 -2
- package/src/runtime/query-executor.ts +149 -28
- package/src/runtime/query-worker.mjs +106 -21
- package/src/runtime/read-model.ts +849 -121
- package/src/runtime/read-watchdog-probe.ts +4 -0
- package/src/runtime/result-supervision.ts +188 -16
- package/src/runtime/root.ts +5 -2
- package/src/runtime/source-watch.ts +175 -0
- package/src/runtime/subagent-launch.ts +11 -4
- 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 +104 -23
- package/src/session-activity.ts +26 -4
- package/src/version.ts +1 -1
|
@@ -14,13 +14,14 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { StoreError } from "./errors.domain.mjs";
|
|
16
16
|
import { mapOperation, ownerFromRow, readOperation, requireOperation } from "./rows.domain.mjs";
|
|
17
|
-
import { columnText, getRows, isUniqueViolation, run, } from "./sqlite.domain.mjs";
|
|
18
|
-
import { describeOwnerDiff, normalizeOwner, optionalText, requireBoolean, requireEnum, requireEvidenceKind, requireId, requireObserver, requireOptionalCounter, requireText, sameOwner, } from "./validate.domain.mjs";
|
|
17
|
+
import { columnJson, columnText, getRow, getRows, isUniqueViolation, run, } from "./sqlite.domain.mjs";
|
|
18
|
+
import { describeOwnerDiff, normalizeOwner, optionalText, requireBoolean, requireCounter, requireEnum, requireEvidenceKind, requireId, requireObserver, requireOptionalCounter, requireText, sameOwner, } from "./validate.domain.mjs";
|
|
19
19
|
import { mapOutbox } from "./rows.domain.mjs";
|
|
20
20
|
import { settleWaitsForOperation } from "./waits.domain.mjs";
|
|
21
21
|
import { bumpChangeRevision } from "./discovery.domain.mjs";
|
|
22
22
|
const HEALTH_VALUES = ["active", "unmonitored", "lost"];
|
|
23
23
|
const OUTCOME_VALUES = ["succeeded", "failed", "cancelled", "lost"];
|
|
24
|
+
const ASSIGNMENT_CLEANUP_PAGE_MAX = 256;
|
|
24
25
|
function normalizeSupervision(value) {
|
|
25
26
|
if (value === undefined || value === null)
|
|
26
27
|
return null;
|
|
@@ -70,6 +71,9 @@ export function registerOperation(ctx, input) {
|
|
|
70
71
|
const taskId = requireId("taskId", input.taskId);
|
|
71
72
|
const launchToken = requireId("launchToken", input.launchToken);
|
|
72
73
|
const owner = normalizeOwner("owner", input.owner);
|
|
74
|
+
const assignmentAttemptId = input.assignmentAttemptId === undefined
|
|
75
|
+
? undefined
|
|
76
|
+
: requireId("assignmentAttemptId", input.assignmentAttemptId);
|
|
73
77
|
const observer = requireObserver("observer", input.observer);
|
|
74
78
|
const supervision = normalizeSupervision(input.supervision);
|
|
75
79
|
const authorityRef = optionalText("authorityRef", input.authorityRef, 512);
|
|
@@ -90,6 +94,8 @@ export function registerOperation(ctx, input) {
|
|
|
90
94
|
differences.push("taskId");
|
|
91
95
|
if (existing.launchToken !== launchToken)
|
|
92
96
|
differences.push("launchToken");
|
|
97
|
+
if (existing.assignmentAttemptId !== assignmentAttemptId)
|
|
98
|
+
differences.push("assignmentAttemptId");
|
|
93
99
|
if (!sameOwner(existing.owner, owner)) {
|
|
94
100
|
differences.push(`owner (${describeOwnerDiff(existing.owner, owner)})`);
|
|
95
101
|
}
|
|
@@ -107,14 +113,28 @@ export function registerOperation(ctx, input) {
|
|
|
107
113
|
return { operation: existing, created: false };
|
|
108
114
|
}
|
|
109
115
|
assertTaskAvailable();
|
|
116
|
+
if (assignmentAttemptId !== undefined) {
|
|
117
|
+
const binding = getRow(ctx, `SELECT b.owner_json, o.assignment_id AS terminal_assignment_id
|
|
118
|
+
FROM assignment_attempts a
|
|
119
|
+
JOIN assignment_bindings b ON b.assignment_id = a.assignment_id
|
|
120
|
+
LEFT JOIN assignment_outcomes o ON o.assignment_id = a.assignment_id
|
|
121
|
+
WHERE a.attempt_id = ?`, assignmentAttemptId);
|
|
122
|
+
const capturedOwner = binding && columnJson(binding, "owner_json");
|
|
123
|
+
if (!binding || !capturedOwner || !sameOwner(capturedOwner, owner)) {
|
|
124
|
+
throw new StoreError("foreign-owner", "Operation owner must match the captured owner of a registered assignment attempt.");
|
|
125
|
+
}
|
|
126
|
+
if (binding.terminal_assignment_id !== null) {
|
|
127
|
+
throw new StoreError("validation", "A terminal assignment cannot register a new operation.");
|
|
128
|
+
}
|
|
129
|
+
}
|
|
110
130
|
const at = ctx.now();
|
|
111
131
|
try {
|
|
112
132
|
run(ctx, `INSERT INTO operations (
|
|
113
133
|
operation_id, task_id, launch_token,
|
|
114
|
-
owner_kind, owner_session_id, owner_workspace, owner_branch_id, owner_goal_id,
|
|
134
|
+
owner_kind, owner_session_id, owner_workspace, owner_branch_id, owner_goal_id, assignment_attempt_id,
|
|
115
135
|
observer_kind, observer_version, supervision_json, supervision_host_id, authority_ref, intent_ref,
|
|
116
136
|
phase, health, health_reason, terminal_revision, created_at, updated_at
|
|
117
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'running', 'active', NULL, 0, ?, ?)`, operationId, taskId, launchToken, owner.kind, owner.sessionId, owner.workspace, owner.branchId ?? null, owner.goalId ?? null, observer.kind, observer.version, supervision ? JSON.stringify(supervision) : null, supervision?.hostId ?? null, authorityRef, intentRef, at, at);
|
|
137
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'running', 'active', NULL, 0, ?, ?)`, operationId, taskId, launchToken, owner.kind, owner.sessionId, owner.workspace, owner.branchId ?? null, owner.goalId ?? null, assignmentAttemptId ?? null, observer.kind, observer.version, supervision ? JSON.stringify(supervision) : null, supervision?.hostId ?? null, authorityRef, intentRef, at, at);
|
|
118
138
|
}
|
|
119
139
|
catch (error) {
|
|
120
140
|
// Another process may have registered the same launch (or the same task)
|
|
@@ -293,6 +313,26 @@ export function listOperations(ctx, filter = {}) {
|
|
|
293
313
|
return getRows(ctx, `SELECT *, EXISTS(SELECT 1 FROM coordinator_state s WHERE s.key = 'result-supervision-v1:' || operations.operation_id) AS result_managed FROM operations ${where} ORDER BY created_at, operation_id`, ...params)
|
|
294
314
|
.map(row => ({ ...mapOperation(row), resultManaged: Number(row.result_managed) === 1 }));
|
|
295
315
|
}
|
|
316
|
+
export function listAssignmentCleanupOperations(ctx, limit, afterOperationId) {
|
|
317
|
+
const requested = requireCounter("limit", limit);
|
|
318
|
+
if (requested === 0)
|
|
319
|
+
throw new StoreError("validation", "Invalid limit: must be at least 1");
|
|
320
|
+
const cursor = afterOperationId === undefined ? "" : requireId("afterOperationId", afterOperationId);
|
|
321
|
+
// Seek the partial index in cursor order rather than sorting all running operations.
|
|
322
|
+
return getRows(ctx, `SELECT op.*, EXISTS(SELECT 1 FROM coordinator_state s
|
|
323
|
+
WHERE s.key = 'result-supervision-v1:' || op.operation_id) AS result_managed
|
|
324
|
+
FROM operations op INDEXED BY operations_assignment_cleanup
|
|
325
|
+
JOIN assignment_attempts a ON a.attempt_id = op.assignment_attempt_id
|
|
326
|
+
JOIN assignment_outcomes o ON o.assignment_id = a.assignment_id
|
|
327
|
+
WHERE op.assignment_attempt_id IS NOT NULL AND op.operation_id > ?
|
|
328
|
+
AND (op.terminal_revision = 0 OR op.terminal_outcome = 'lost'
|
|
329
|
+
OR EXISTS (SELECT 1 FROM operation_evidence e WHERE e.operation_id = op.operation_id
|
|
330
|
+
AND e.terminal_revision = op.terminal_revision AND e.kind = 'terminal-record'
|
|
331
|
+
AND e.summary LIKE '%groupCleanup=unproven%'))
|
|
332
|
+
AND NOT EXISTS (SELECT 1 FROM coordinator_state s WHERE s.key = 'assignment-cleanup-verified:' || op.operation_id)
|
|
333
|
+
ORDER BY op.operation_id LIMIT ?`, cursor, Math.min(requested, ASSIGNMENT_CLEANUP_PAGE_MAX))
|
|
334
|
+
.map(row => ({ ...mapOperation(row), resultManaged: Number(row.result_managed) === 1 }));
|
|
335
|
+
}
|
|
296
336
|
/** Running operations assigned to one supervising host, using the phase/host index. */
|
|
297
337
|
export function listRunningSupervisedBy(ctx, hostId) {
|
|
298
338
|
return getRows(ctx, "SELECT *, EXISTS(SELECT 1 FROM coordinator_state s WHERE s.key = 'result-supervision-v1:' || operations.operation_id) AS result_managed FROM operations WHERE phase = 'running' AND supervision_host_id = ? ORDER BY created_at, operation_id", requireId("hostId", hostId)).map(row => ({ ...mapOperation(row), resultManaged: Number(row.result_managed) === 1 }));
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
import { StoreError } from "./errors.ts";
|
|
15
15
|
import { mapOperation, ownerFromRow, readOperation, requireOperation } from "./rows.ts";
|
|
16
16
|
import {
|
|
17
|
+
columnJson,
|
|
17
18
|
columnText,
|
|
19
|
+
getRow,
|
|
18
20
|
getRows,
|
|
19
21
|
isUniqueViolation,
|
|
20
22
|
run,
|
|
@@ -25,6 +27,7 @@ import type {
|
|
|
25
27
|
ObserverHealth,
|
|
26
28
|
OperationFilter,
|
|
27
29
|
OperationRecord,
|
|
30
|
+
OwnerIdentity,
|
|
28
31
|
ReleaseSupervisionInput,
|
|
29
32
|
RecordSupervisionInput,
|
|
30
33
|
RecordTerminalOutcomeInput,
|
|
@@ -40,6 +43,7 @@ import {
|
|
|
40
43
|
normalizeOwner,
|
|
41
44
|
optionalText,
|
|
42
45
|
requireBoolean,
|
|
46
|
+
requireCounter,
|
|
43
47
|
requireEnum,
|
|
44
48
|
requireEvidenceKind,
|
|
45
49
|
requireId,
|
|
@@ -54,6 +58,7 @@ import { bumpChangeRevision } from "./discovery.ts";
|
|
|
54
58
|
|
|
55
59
|
const HEALTH_VALUES: readonly ObserverHealth[] = ["active", "unmonitored", "lost"];
|
|
56
60
|
const OUTCOME_VALUES: readonly TerminalOutcome[] = ["succeeded", "failed", "cancelled", "lost"];
|
|
61
|
+
const ASSIGNMENT_CLEANUP_PAGE_MAX = 256;
|
|
57
62
|
|
|
58
63
|
function normalizeSupervision(value: unknown): SupervisionIdentity | null {
|
|
59
64
|
if (value === undefined || value === null) return null;
|
|
@@ -108,6 +113,9 @@ export function registerOperation(
|
|
|
108
113
|
const taskId = requireId("taskId", input.taskId);
|
|
109
114
|
const launchToken = requireId("launchToken", input.launchToken);
|
|
110
115
|
const owner = normalizeOwner("owner", input.owner);
|
|
116
|
+
const assignmentAttemptId = input.assignmentAttemptId === undefined
|
|
117
|
+
? undefined
|
|
118
|
+
: requireId("assignmentAttemptId", input.assignmentAttemptId);
|
|
111
119
|
const observer = requireObserver("observer", input.observer);
|
|
112
120
|
const supervision = normalizeSupervision(input.supervision);
|
|
113
121
|
const authorityRef = optionalText("authorityRef", input.authorityRef, 512);
|
|
@@ -133,6 +141,7 @@ export function registerOperation(
|
|
|
133
141
|
const differences: string[] = [];
|
|
134
142
|
if (existing.taskId !== taskId) differences.push("taskId");
|
|
135
143
|
if (existing.launchToken !== launchToken) differences.push("launchToken");
|
|
144
|
+
if (existing.assignmentAttemptId !== assignmentAttemptId) differences.push("assignmentAttemptId");
|
|
136
145
|
if (!sameOwner(existing.owner, owner)) {
|
|
137
146
|
differences.push(`owner (${describeOwnerDiff(existing.owner, owner)})`);
|
|
138
147
|
}
|
|
@@ -154,6 +163,20 @@ export function registerOperation(
|
|
|
154
163
|
return { operation: existing, created: false };
|
|
155
164
|
}
|
|
156
165
|
assertTaskAvailable();
|
|
166
|
+
if (assignmentAttemptId !== undefined) {
|
|
167
|
+
const binding = getRow(ctx, `SELECT b.owner_json, o.assignment_id AS terminal_assignment_id
|
|
168
|
+
FROM assignment_attempts a
|
|
169
|
+
JOIN assignment_bindings b ON b.assignment_id = a.assignment_id
|
|
170
|
+
LEFT JOIN assignment_outcomes o ON o.assignment_id = a.assignment_id
|
|
171
|
+
WHERE a.attempt_id = ?`, assignmentAttemptId);
|
|
172
|
+
const capturedOwner = binding && columnJson<OwnerIdentity>(binding, "owner_json");
|
|
173
|
+
if (!binding || !capturedOwner || !sameOwner(capturedOwner, owner)) {
|
|
174
|
+
throw new StoreError("foreign-owner", "Operation owner must match the captured owner of a registered assignment attempt.");
|
|
175
|
+
}
|
|
176
|
+
if (binding.terminal_assignment_id !== null) {
|
|
177
|
+
throw new StoreError("validation", "A terminal assignment cannot register a new operation.");
|
|
178
|
+
}
|
|
179
|
+
}
|
|
157
180
|
|
|
158
181
|
const at = ctx.now();
|
|
159
182
|
try {
|
|
@@ -161,10 +184,10 @@ export function registerOperation(
|
|
|
161
184
|
ctx,
|
|
162
185
|
`INSERT INTO operations (
|
|
163
186
|
operation_id, task_id, launch_token,
|
|
164
|
-
owner_kind, owner_session_id, owner_workspace, owner_branch_id, owner_goal_id,
|
|
187
|
+
owner_kind, owner_session_id, owner_workspace, owner_branch_id, owner_goal_id, assignment_attempt_id,
|
|
165
188
|
observer_kind, observer_version, supervision_json, supervision_host_id, authority_ref, intent_ref,
|
|
166
189
|
phase, health, health_reason, terminal_revision, created_at, updated_at
|
|
167
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'running', 'active', NULL, 0, ?, ?)`,
|
|
190
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'running', 'active', NULL, 0, ?, ?)`,
|
|
168
191
|
operationId,
|
|
169
192
|
taskId,
|
|
170
193
|
launchToken,
|
|
@@ -173,6 +196,7 @@ export function registerOperation(
|
|
|
173
196
|
owner.workspace,
|
|
174
197
|
owner.branchId ?? null,
|
|
175
198
|
owner.goalId ?? null,
|
|
199
|
+
assignmentAttemptId ?? null,
|
|
176
200
|
observer.kind,
|
|
177
201
|
observer.version,
|
|
178
202
|
supervision ? JSON.stringify(supervision) : null,
|
|
@@ -439,6 +463,30 @@ export function listOperations(
|
|
|
439
463
|
.map(row => ({ ...mapOperation(row), resultManaged: Number(row.result_managed) === 1 }));
|
|
440
464
|
}
|
|
441
465
|
|
|
466
|
+
export function listAssignmentCleanupOperations(
|
|
467
|
+
ctx: StoreContext,
|
|
468
|
+
limit: number,
|
|
469
|
+
afterOperationId?: string,
|
|
470
|
+
): OperationRecord[] {
|
|
471
|
+
const requested = requireCounter("limit", limit);
|
|
472
|
+
if (requested === 0) throw new StoreError("validation", "Invalid limit: must be at least 1");
|
|
473
|
+
const cursor = afterOperationId === undefined ? "" : requireId("afterOperationId", afterOperationId);
|
|
474
|
+
// Seek the partial index in cursor order rather than sorting all running operations.
|
|
475
|
+
return getRows(ctx, `SELECT op.*, EXISTS(SELECT 1 FROM coordinator_state s
|
|
476
|
+
WHERE s.key = 'result-supervision-v1:' || op.operation_id) AS result_managed
|
|
477
|
+
FROM operations op INDEXED BY operations_assignment_cleanup
|
|
478
|
+
JOIN assignment_attempts a ON a.attempt_id = op.assignment_attempt_id
|
|
479
|
+
JOIN assignment_outcomes o ON o.assignment_id = a.assignment_id
|
|
480
|
+
WHERE op.assignment_attempt_id IS NOT NULL AND op.operation_id > ?
|
|
481
|
+
AND (op.terminal_revision = 0 OR op.terminal_outcome = 'lost'
|
|
482
|
+
OR EXISTS (SELECT 1 FROM operation_evidence e WHERE e.operation_id = op.operation_id
|
|
483
|
+
AND e.terminal_revision = op.terminal_revision AND e.kind = 'terminal-record'
|
|
484
|
+
AND e.summary LIKE '%groupCleanup=unproven%'))
|
|
485
|
+
AND NOT EXISTS (SELECT 1 FROM coordinator_state s WHERE s.key = 'assignment-cleanup-verified:' || op.operation_id)
|
|
486
|
+
ORDER BY op.operation_id LIMIT ?`, cursor, Math.min(requested, ASSIGNMENT_CLEANUP_PAGE_MAX))
|
|
487
|
+
.map(row => ({ ...mapOperation(row), resultManaged: Number(row.result_managed) === 1 }));
|
|
488
|
+
}
|
|
489
|
+
|
|
442
490
|
/** Running operations assigned to one supervising host, using the phase/host index. */
|
|
443
491
|
export function listRunningSupervisedBy(
|
|
444
492
|
ctx: StoreContext,
|
|
@@ -156,6 +156,13 @@ export function listOutbox(ctx, filter = {}) {
|
|
|
156
156
|
const where = clauses.length > 0 ? `WHERE ${clauses.join(" AND ")}` : "";
|
|
157
157
|
return getRows(ctx, `SELECT * FROM outbox_events ${where} ORDER BY created_at, event_id`, ...params).map((row) => mapOutbox(ctx, row));
|
|
158
158
|
}
|
|
159
|
+
/** Check a wait handoff without loading the retained evidence for its generations. */
|
|
160
|
+
export function hasDeliveredWaitDependency(ctx, operationId, terminalRevision, recipient) {
|
|
161
|
+
const owner = ownerClause("recipient", recipient);
|
|
162
|
+
return getRows(ctx, `SELECT 1 FROM outbox_events
|
|
163
|
+
WHERE operation_id = ? AND terminal_revision = ? AND event_type = 'dependency-ready'
|
|
164
|
+
AND delivered_at IS NOT NULL AND ${owner.sql} LIMIT 1`, requireId("operationId", operationId), requireCounter("terminalRevision", terminalRevision), ...owner.params).length > 0;
|
|
165
|
+
}
|
|
159
166
|
/** Find recipients with deliverable dependencies without loading each event's evidence. */
|
|
160
167
|
export function listDispatchableOutboxRecipients(ctx) {
|
|
161
168
|
return getRows(ctx, `SELECT recipient_kind, recipient_session_id, recipient_workspace, recipient_branch_id, recipient_goal_id,
|
|
@@ -281,6 +281,15 @@ export function listOutbox(ctx: StoreContext, filter: OutboxFilter = {}): Outbox
|
|
|
281
281
|
).map((row) => mapOutbox(ctx, row));
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
+
/** Check a wait handoff without loading the retained evidence for its generations. */
|
|
285
|
+
export function hasDeliveredWaitDependency(ctx: StoreContext, operationId: string, terminalRevision: number, recipient: OwnerIdentity): boolean {
|
|
286
|
+
const owner = ownerClause("recipient", recipient);
|
|
287
|
+
return getRows(ctx, `SELECT 1 FROM outbox_events
|
|
288
|
+
WHERE operation_id = ? AND terminal_revision = ? AND event_type = 'dependency-ready'
|
|
289
|
+
AND delivered_at IS NOT NULL AND ${owner.sql} LIMIT 1`,
|
|
290
|
+
requireId("operationId", operationId), requireCounter("terminalRevision", terminalRevision), ...owner.params).length > 0;
|
|
291
|
+
}
|
|
292
|
+
|
|
284
293
|
/** Find recipients with deliverable dependencies without loading each event's evidence. */
|
|
285
294
|
export function listDispatchableOutboxRecipients(ctx: StoreContext): Array<{ recipient: OwnerIdentity; count: number }> {
|
|
286
295
|
return getRows(
|
package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.domain.mjs
CHANGED
|
@@ -5,6 +5,18 @@ import { getRow, run } from "./sqlite.domain.mjs";
|
|
|
5
5
|
import { getOperation, recordSupervision, recordTerminalOutcome } from "./operations.domain.mjs";
|
|
6
6
|
import { requireId, requirePath } from "./validate.domain.mjs";
|
|
7
7
|
const PREFIX = "result-supervision-v1:";
|
|
8
|
+
/** A bounded observation page. A gap requires restoring active authority, not history. */
|
|
9
|
+
export function resultSupervisionChanges(ctx, after) {
|
|
10
|
+
const generation = String(ctx.db.prepare("SELECT generation FROM assignment_change_source WHERE singleton=1").get().generation);
|
|
11
|
+
const bounds = ctx.db.prepare("SELECT min(seq) AS first, max(seq) AS last FROM assignment_changes").get();
|
|
12
|
+
const last = Number(bounds.last ?? 0);
|
|
13
|
+
const reset = !after || after.generation !== generation || after.seq > last
|
|
14
|
+
|| (bounds.first !== null && after.seq < Number(bounds.first) - 1);
|
|
15
|
+
const rows = reset ? [] : ctx.db.prepare("SELECT seq, entity, entity_id FROM assignment_changes WHERE seq>? ORDER BY seq LIMIT 128").all(after.seq);
|
|
16
|
+
const seq = reset ? last : Number(rows.at(-1)?.seq ?? after.seq);
|
|
17
|
+
return { generation, seq, reset, more: seq < last,
|
|
18
|
+
operationIds: [...new Set(rows.filter(row => row.entity === "background:operation").map(row => String(row.entity_id)))] };
|
|
19
|
+
}
|
|
8
20
|
export function resultSupervisions(ctx, activeOnly = false) {
|
|
9
21
|
const rows = activeOnly
|
|
10
22
|
? ctx.db.prepare("SELECT s.value FROM operations o JOIN coordinator_state s ON s.key = ? || o.operation_id WHERE o.phase = 'running'").all(PREFIX)
|
|
@@ -7,6 +7,18 @@ import type { RecordTerminalOutcomeInput } from "./types.ts";
|
|
|
7
7
|
import type { OwnerIdentity } from "./types.ts";
|
|
8
8
|
|
|
9
9
|
const PREFIX = "result-supervision-v1:";
|
|
10
|
+
/** A bounded observation page. A gap requires restoring active authority, not history. */
|
|
11
|
+
export function resultSupervisionChanges(ctx: StoreContext, after?: { generation: string; seq: number }) {
|
|
12
|
+
const generation = String(ctx.db.prepare("SELECT generation FROM assignment_change_source WHERE singleton=1").get()!.generation);
|
|
13
|
+
const bounds = ctx.db.prepare("SELECT min(seq) AS first, max(seq) AS last FROM assignment_changes").get()!;
|
|
14
|
+
const last = Number(bounds.last ?? 0);
|
|
15
|
+
const reset = !after || after.generation !== generation || after.seq > last
|
|
16
|
+
|| (bounds.first !== null && after.seq < Number(bounds.first) - 1);
|
|
17
|
+
const rows = reset ? [] : ctx.db.prepare("SELECT seq, entity, entity_id FROM assignment_changes WHERE seq>? ORDER BY seq LIMIT 128").all(after!.seq);
|
|
18
|
+
const seq = reset ? last : Number(rows.at(-1)?.seq ?? after!.seq);
|
|
19
|
+
return { generation, seq, reset, more: seq < last,
|
|
20
|
+
operationIds: [...new Set(rows.filter(row => row.entity === "background:operation").map(row => String(row.entity_id)))] };
|
|
21
|
+
}
|
|
10
22
|
export interface ResultSupervision {
|
|
11
23
|
operationId: string;
|
|
12
24
|
directory: string;
|
|
@@ -28,11 +28,13 @@ export function getOperationRowByTask(ctx, taskId) {
|
|
|
28
28
|
return getRow(ctx, "SELECT * FROM operations WHERE task_id = ?", taskId);
|
|
29
29
|
}
|
|
30
30
|
export function mapOperation(row) {
|
|
31
|
+
const assignmentAttemptId = columnNullableText(row, "assignment_attempt_id");
|
|
31
32
|
return {
|
|
32
33
|
operationId: columnText(row, "operation_id"),
|
|
33
34
|
taskId: columnText(row, "task_id"),
|
|
34
35
|
launchToken: columnText(row, "launch_token"),
|
|
35
36
|
owner: ownerFromRow(row),
|
|
37
|
+
...(assignmentAttemptId === null ? {} : { assignmentAttemptId }),
|
|
36
38
|
observer: {
|
|
37
39
|
kind: columnText(row, "observer_kind"),
|
|
38
40
|
version: columnText(row, "observer_version"),
|
|
@@ -74,11 +74,13 @@ export function getOperationRowByTask(
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
export function mapOperation(row: Record<string, unknown>): OperationRecord {
|
|
77
|
+
const assignmentAttemptId = columnNullableText(row, "assignment_attempt_id");
|
|
77
78
|
return {
|
|
78
79
|
operationId: columnText(row, "operation_id"),
|
|
79
80
|
taskId: columnText(row, "task_id"),
|
|
80
81
|
launchToken: columnText(row, "launch_token"),
|
|
81
82
|
owner: ownerFromRow(row),
|
|
83
|
+
...(assignmentAttemptId === null ? {} : { assignmentAttemptId }),
|
|
82
84
|
observer: {
|
|
83
85
|
kind: columnText(row, "observer_kind"),
|
|
84
86
|
version: columnText(row, "observer_version"),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-subagents/shared-operation-coordinator/src/schema.ts. Do not edit directly.
|
|
2
2
|
// Generated from packages/operation-coordinator/src/schema.ts. Do not edit directly.
|
|
3
3
|
/**
|
|
4
|
-
* Schema
|
|
4
|
+
* Schema v5 for the durable operation coordinator.
|
|
5
5
|
*
|
|
6
6
|
* The store refuses to open a database whose recorded version it does not
|
|
7
7
|
* understand, and leaves the file untouched. An unreadable or newer database
|
|
@@ -55,6 +55,14 @@ const BACKGROUND_CALLBACK_DDL = [
|
|
|
55
55
|
SELECT 1,'',COALESCE(MAX(operation_id),''),CASE WHEN MAX(operation_id) IS NULL THEN 1 ELSE 0 END
|
|
56
56
|
FROM operations WHERE owner_kind='parent-session' AND observer_kind='local-supervisor'`,
|
|
57
57
|
];
|
|
58
|
+
const ASSIGNMENT_ATTEMPTS_DDL = `CREATE TABLE IF NOT EXISTS assignment_attempts (
|
|
59
|
+
attempt_id TEXT PRIMARY KEY,
|
|
60
|
+
assignment_id TEXT NOT NULL REFERENCES assignment_bindings (assignment_id)
|
|
61
|
+
)`;
|
|
62
|
+
const ASSIGNMENT_ATTEMPT_COLUMN = `assignment_attempt_id TEXT REFERENCES assignment_attempts (attempt_id)`;
|
|
63
|
+
const ASSIGNMENT_CLEANUP_INDEX = `CREATE INDEX IF NOT EXISTS operations_assignment_cleanup
|
|
64
|
+
ON operations (operation_id, assignment_attempt_id)
|
|
65
|
+
WHERE assignment_attempt_id IS NOT NULL`;
|
|
58
66
|
const DDL = [
|
|
59
67
|
`CREATE TABLE task_cancellation_authorities (
|
|
60
68
|
credential_hash TEXT PRIMARY KEY,
|
|
@@ -91,6 +99,7 @@ const DDL = [
|
|
|
91
99
|
owner_workspace TEXT NOT NULL,
|
|
92
100
|
owner_branch_id TEXT,
|
|
93
101
|
owner_goal_id TEXT,
|
|
102
|
+
${ASSIGNMENT_ATTEMPT_COLUMN},
|
|
94
103
|
observer_kind TEXT NOT NULL,
|
|
95
104
|
observer_version TEXT NOT NULL,
|
|
96
105
|
supervision_json TEXT,
|
|
@@ -113,6 +122,7 @@ const DDL = [
|
|
|
113
122
|
`CREATE INDEX operations_owner ON operations (owner_kind, owner_session_id)`,
|
|
114
123
|
`CREATE INDEX operations_phase ON operations (phase)`,
|
|
115
124
|
`CREATE INDEX operations_running_supervisor ON operations (phase, supervision_host_id)`,
|
|
125
|
+
ASSIGNMENT_CLEANUP_INDEX,
|
|
116
126
|
// Discovery leadership is separate from per-operation supervision. The token
|
|
117
127
|
// fences stale acquisition and release; the host id is checked with process
|
|
118
128
|
// identity before a replacement.
|
|
@@ -266,10 +276,7 @@ const DDL = [
|
|
|
266
276
|
owner_json TEXT NOT NULL,
|
|
267
277
|
recipient_json TEXT NOT NULL
|
|
268
278
|
)`,
|
|
269
|
-
|
|
270
|
-
attempt_id TEXT PRIMARY KEY,
|
|
271
|
-
assignment_id TEXT NOT NULL REFERENCES assignment_bindings (assignment_id)
|
|
272
|
-
)`,
|
|
279
|
+
ASSIGNMENT_ATTEMPTS_DDL,
|
|
273
280
|
`CREATE TABLE assignment_outcome_waits (
|
|
274
281
|
assignment_id TEXT NOT NULL REFERENCES assignment_outcomes (assignment_id),
|
|
275
282
|
wait_id TEXT NOT NULL,
|
|
@@ -313,17 +320,16 @@ export function ensureSchema(ctx) {
|
|
|
313
320
|
throw new StoreError("schema-version", `The database was written by schema version ${recorded}; this build understands version ${SCHEMA_VERSION}. Upgrade the harness instead of downgrading the records.`);
|
|
314
321
|
}
|
|
315
322
|
if (recorded < SCHEMA_VERSION) {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
if (recorded === 1 || recorded === 2) {
|
|
323
|
+
ctx.transaction(() => {
|
|
324
|
+
// Another opener may have finished the upgrade before we acquired the write lock.
|
|
325
|
+
const current = readSchemaVersion(ctx);
|
|
326
|
+
if (current === SCHEMA_VERSION)
|
|
327
|
+
return;
|
|
328
|
+
if (current !== recorded) {
|
|
329
|
+
throw new StoreError("schema-version", "The coordinator schema changed during opening. Reopen the store to verify it.");
|
|
330
|
+
}
|
|
325
331
|
ensureAdditiveSchema(ctx);
|
|
326
|
-
|
|
332
|
+
if (recorded <= 2) {
|
|
327
333
|
if (recorded === 1)
|
|
328
334
|
ctx.db.exec("ALTER TABLE outbox_events ADD COLUMN event_type TEXT NOT NULL DEFAULT 'dependency-ready'");
|
|
329
335
|
for (const statement of DDL.filter((sql) => sql.startsWith("CREATE TABLE assignment_")))
|
|
@@ -332,14 +338,29 @@ export function ensureSchema(ctx) {
|
|
|
332
338
|
ctx.db.exec("UPDATE waits SET dispatch_disarmed = 1 WHERE EXISTS (SELECT 1 FROM assignment_outcome_waits aw WHERE aw.wait_id = waits.wait_id AND aw.generation = waits.generation)");
|
|
333
339
|
ctx.db.exec("DROP INDEX waits_one_pending_per_owner");
|
|
334
340
|
ctx.db.exec(DDL.find((sql) => sql.startsWith("CREATE UNIQUE INDEX waits_one_pending_per_owner")));
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
341
|
+
}
|
|
342
|
+
else if (recorded === 3) {
|
|
343
|
+
ctx.db.exec(DDL.find((sql) => sql.startsWith("CREATE TABLE assignment_repairs")));
|
|
344
|
+
}
|
|
345
|
+
ensureAssignmentCleanupSchema(ctx);
|
|
346
|
+
run(ctx, "UPDATE schema_meta SET value = ? WHERE key = ?", String(SCHEMA_VERSION), SCHEMA_VERSION_KEY);
|
|
347
|
+
});
|
|
348
|
+
return;
|
|
340
349
|
}
|
|
341
350
|
ensureAdditiveSchema(ctx);
|
|
342
|
-
ctx
|
|
351
|
+
ensureAssignmentCleanupSchema(ctx);
|
|
352
|
+
}
|
|
353
|
+
function ensureAssignmentCleanupSchema(ctx) {
|
|
354
|
+
const hasColumn = () => getRows(ctx, "PRAGMA table_info(operations)").some(row => row.name === "assignment_attempt_id");
|
|
355
|
+
if (hasColumn() && getRow(ctx, "SELECT 1 FROM sqlite_master WHERE name = 'operations_assignment_cleanup'"))
|
|
356
|
+
return;
|
|
357
|
+
ctx.transaction(() => {
|
|
358
|
+
ctx.db.exec(ASSIGNMENT_ATTEMPTS_DDL);
|
|
359
|
+
// Legacy writers leave the nullable provenance unset.
|
|
360
|
+
if (!hasColumn())
|
|
361
|
+
ctx.db.exec(`ALTER TABLE operations ADD COLUMN ${ASSIGNMENT_ATTEMPT_COLUMN}`);
|
|
362
|
+
ctx.db.exec(ASSIGNMENT_CLEANUP_INDEX);
|
|
363
|
+
});
|
|
343
364
|
}
|
|
344
365
|
/**
|
|
345
366
|
* Schema version 1 is extended additively: older readers ignore the new column,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Generated from packages/operation-coordinator/src/schema.ts. Do not edit directly.
|
|
2
2
|
/**
|
|
3
|
-
* Schema
|
|
3
|
+
* Schema v5 for the durable operation coordinator.
|
|
4
4
|
*
|
|
5
5
|
* The store refuses to open a database whose recorded version it does not
|
|
6
6
|
* understand, and leaves the file untouched. An unreadable or newer database
|
|
@@ -57,6 +57,15 @@ const BACKGROUND_CALLBACK_DDL = [
|
|
|
57
57
|
FROM operations WHERE owner_kind='parent-session' AND observer_kind='local-supervisor'`,
|
|
58
58
|
];
|
|
59
59
|
|
|
60
|
+
const ASSIGNMENT_ATTEMPTS_DDL = `CREATE TABLE IF NOT EXISTS assignment_attempts (
|
|
61
|
+
attempt_id TEXT PRIMARY KEY,
|
|
62
|
+
assignment_id TEXT NOT NULL REFERENCES assignment_bindings (assignment_id)
|
|
63
|
+
)`;
|
|
64
|
+
const ASSIGNMENT_ATTEMPT_COLUMN = `assignment_attempt_id TEXT REFERENCES assignment_attempts (attempt_id)`;
|
|
65
|
+
const ASSIGNMENT_CLEANUP_INDEX = `CREATE INDEX IF NOT EXISTS operations_assignment_cleanup
|
|
66
|
+
ON operations (operation_id, assignment_attempt_id)
|
|
67
|
+
WHERE assignment_attempt_id IS NOT NULL`;
|
|
68
|
+
|
|
60
69
|
const DDL: readonly string[] = [
|
|
61
70
|
`CREATE TABLE task_cancellation_authorities (
|
|
62
71
|
credential_hash TEXT PRIMARY KEY,
|
|
@@ -93,6 +102,7 @@ const DDL: readonly string[] = [
|
|
|
93
102
|
owner_workspace TEXT NOT NULL,
|
|
94
103
|
owner_branch_id TEXT,
|
|
95
104
|
owner_goal_id TEXT,
|
|
105
|
+
${ASSIGNMENT_ATTEMPT_COLUMN},
|
|
96
106
|
observer_kind TEXT NOT NULL,
|
|
97
107
|
observer_version TEXT NOT NULL,
|
|
98
108
|
supervision_json TEXT,
|
|
@@ -115,6 +125,7 @@ const DDL: readonly string[] = [
|
|
|
115
125
|
`CREATE INDEX operations_owner ON operations (owner_kind, owner_session_id)`,
|
|
116
126
|
`CREATE INDEX operations_phase ON operations (phase)`,
|
|
117
127
|
`CREATE INDEX operations_running_supervisor ON operations (phase, supervision_host_id)`,
|
|
128
|
+
ASSIGNMENT_CLEANUP_INDEX,
|
|
118
129
|
// Discovery leadership is separate from per-operation supervision. The token
|
|
119
130
|
// fences stale acquisition and release; the host id is checked with process
|
|
120
131
|
// identity before a replacement.
|
|
@@ -268,10 +279,7 @@ const DDL: readonly string[] = [
|
|
|
268
279
|
owner_json TEXT NOT NULL,
|
|
269
280
|
recipient_json TEXT NOT NULL
|
|
270
281
|
)`,
|
|
271
|
-
|
|
272
|
-
attempt_id TEXT PRIMARY KEY,
|
|
273
|
-
assignment_id TEXT NOT NULL REFERENCES assignment_bindings (assignment_id)
|
|
274
|
-
)`,
|
|
282
|
+
ASSIGNMENT_ATTEMPTS_DDL,
|
|
275
283
|
`CREATE TABLE assignment_outcome_waits (
|
|
276
284
|
assignment_id TEXT NOT NULL REFERENCES assignment_outcomes (assignment_id),
|
|
277
285
|
wait_id TEXT NOT NULL,
|
|
@@ -333,34 +341,42 @@ export function ensureSchema(ctx: StoreContext): void {
|
|
|
333
341
|
);
|
|
334
342
|
}
|
|
335
343
|
if (recorded < SCHEMA_VERSION) {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
344
|
-
if (recorded === 1 || recorded === 2) {
|
|
344
|
+
ctx.transaction(() => {
|
|
345
|
+
// Another opener may have finished the upgrade before we acquired the write lock.
|
|
346
|
+
const current = readSchemaVersion(ctx);
|
|
347
|
+
if (current === SCHEMA_VERSION) return;
|
|
348
|
+
if (current !== recorded) {
|
|
349
|
+
throw new StoreError("schema-version", "The coordinator schema changed during opening. Reopen the store to verify it.");
|
|
350
|
+
}
|
|
345
351
|
ensureAdditiveSchema(ctx);
|
|
346
|
-
|
|
352
|
+
if (recorded <= 2) {
|
|
347
353
|
if (recorded === 1) ctx.db.exec("ALTER TABLE outbox_events ADD COLUMN event_type TEXT NOT NULL DEFAULT 'dependency-ready'");
|
|
348
354
|
for (const statement of DDL.filter((sql) => sql.startsWith("CREATE TABLE assignment_"))) ctx.db.exec(statement.replace("CREATE TABLE", "CREATE TABLE IF NOT EXISTS"));
|
|
349
355
|
ctx.db.exec("ALTER TABLE waits ADD COLUMN dispatch_disarmed INTEGER NOT NULL DEFAULT 0");
|
|
350
356
|
ctx.db.exec("UPDATE waits SET dispatch_disarmed = 1 WHERE EXISTS (SELECT 1 FROM assignment_outcome_waits aw WHERE aw.wait_id = waits.wait_id AND aw.generation = waits.generation)");
|
|
351
357
|
ctx.db.exec("DROP INDEX waits_one_pending_per_owner");
|
|
352
358
|
ctx.db.exec(DDL.find((sql) => sql.startsWith("CREATE UNIQUE INDEX waits_one_pending_per_owner"))!);
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
);
|
|
359
|
+
} else if (recorded === 3) {
|
|
360
|
+
ctx.db.exec(DDL.find((sql) => sql.startsWith("CREATE TABLE assignment_repairs"))!);
|
|
361
|
+
}
|
|
362
|
+
ensureAssignmentCleanupSchema(ctx);
|
|
363
|
+
run(ctx, "UPDATE schema_meta SET value = ? WHERE key = ?", String(SCHEMA_VERSION), SCHEMA_VERSION_KEY);
|
|
364
|
+
});
|
|
365
|
+
return;
|
|
361
366
|
}
|
|
362
367
|
ensureAdditiveSchema(ctx);
|
|
363
|
-
ctx
|
|
368
|
+
ensureAssignmentCleanupSchema(ctx);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function ensureAssignmentCleanupSchema(ctx: StoreContext): void {
|
|
372
|
+
const hasColumn = () => getRows(ctx, "PRAGMA table_info(operations)").some(row => row.name === "assignment_attempt_id");
|
|
373
|
+
if (hasColumn() && getRow(ctx, "SELECT 1 FROM sqlite_master WHERE name = 'operations_assignment_cleanup'")) return;
|
|
374
|
+
ctx.transaction(() => {
|
|
375
|
+
ctx.db.exec(ASSIGNMENT_ATTEMPTS_DDL);
|
|
376
|
+
// Legacy writers leave the nullable provenance unset.
|
|
377
|
+
if (!hasColumn()) ctx.db.exec(`ALTER TABLE operations ADD COLUMN ${ASSIGNMENT_ATTEMPT_COLUMN}`);
|
|
378
|
+
ctx.db.exec(ASSIGNMENT_CLEANUP_INDEX);
|
|
379
|
+
});
|
|
364
380
|
}
|
|
365
381
|
|
|
366
382
|
/**
|
|
@@ -13,17 +13,18 @@ import { setParentCallbackPending, listPendingParentCallbacks, listRecentBackgro
|
|
|
13
13
|
import { BackgroundRequests } from "./background-requests.domain.mjs";
|
|
14
14
|
import { StoreError } from "./errors.domain.mjs";
|
|
15
15
|
import { SubagentLaunchJournal } from "./subagent-launch.domain.mjs";
|
|
16
|
-
import { resultSupervision, resultSupervisions, resultScopeManaged, handoffResultScope, handoffResultSupervision, handoffResultSupervisions, recoverResultSupervision, publishSupervisedResult } from "./result-supervision.domain.mjs";
|
|
16
|
+
import { resultSupervisionChanges, resultSupervision, resultSupervisions, resultScopeManaged, handoffResultScope, handoffResultSupervision, handoffResultSupervisions, recoverResultSupervision, publishSupervisedResult } from "./result-supervision.domain.mjs";
|
|
17
17
|
import { acceptTaskCancellation, getTaskCancellation, recordTaskStopRequested, admitTaskCancellation, authorizedTaskCancellation, finishTaskCancellation, cancellationRuntimeEpoch, acceptAuthorizedTaskCancellation, taskCancellationManaged, pendingTaskCancellations, finishTaskCancellationIntent, unknownTaskCancellation } from "./task-cancellation.domain.mjs";
|
|
18
18
|
import { repairFailedResume } from "./recovery.domain.mjs";
|
|
19
19
|
import { recordAssignmentOutcome, getAssignmentOutcome, inspectAssignmentOutcome, consumeAssignmentOutcome, registerAssignment, receiptAssignmentOutcome } from "./assignment-outcomes.domain.mjs";
|
|
20
20
|
import { describeOwnerDiff, normalizeOwner, requireCounter, requireId, requirePath, } from "./validate.domain.mjs";
|
|
21
21
|
import { ensureSchema } from "./schema.domain.mjs";
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
22
|
+
import { ensureAssignmentChanges } from "./assignment-changes.domain.mjs";
|
|
23
|
+
import { createContext, openDatabase, run } from "./sqlite.domain.mjs";
|
|
24
|
+
import { getOperation as readOperationRecord, listAssignmentCleanupOperations as readAssignmentCleanupOperations, listOperations as readOperationRecords, listRunningSupervisedBy as readRunningSupervisedBy, releaseSupervision as writeSupervisionRelease, recordSupervision as writeSupervision, recordTerminalOutcome as writeTerminalOutcome, registerOperation as writeOperation, } from "./operations.domain.mjs";
|
|
24
25
|
import { getChangeRevision as readChangeRevision, readDiscoveryClaim as readClaim, readDiscoveryState, releaseDiscoveryClaim as deleteDiscoveryClaim, tryClaimDiscovery as writeDiscoveryClaim, } from "./discovery.domain.mjs";
|
|
25
26
|
import { acknowledgeResult as writeAcknowledgement, cancelWait as writeCancellation, claimResume as writeClaim, findPendingWaitForOwner, getWait as readWait, listDependencies as readDependencies, listEvidencePins as readPins, listEvidenceReads as readReads, listResumeClaims as readClaims, listUnreconciledClaims, listWaits as readWaits, publishResumeAttempt as writeAttemptPublication, recordEvidencePin as writePin, recordEvidenceRead as writeRead, registerWait as writeWait, releaseEvidencePins as writePinRelease, holdFailedResume as writeHoldFailedResume, releaseResumeClaim as writeClaimRelease, transitionWaitPhase as writePhase, } from "./waits.domain.mjs";
|
|
26
|
-
import { claimOutbox as writeOutboxClaim, listDispatchableOutboxRecipients as readDispatchableOutboxRecipients, listOutbox as readOutbox, markOutboxDelivered as writeOutboxDelivery, releaseOutbox as writeOutboxRelease, } from "./outbox.domain.mjs";
|
|
27
|
+
import { claimOutbox as writeOutboxClaim, hasDeliveredWaitDependency as readDeliveredWaitDependency, listDispatchableOutboxRecipients as readDispatchableOutboxRecipients, listOutbox as readOutbox, markOutboxDelivered as writeOutboxDelivery, releaseOutbox as writeOutboxRelease, } from "./outbox.domain.mjs";
|
|
27
28
|
import { readOperationEvidence } from "./rows.domain.mjs";
|
|
28
29
|
import { SCHEMA_VERSION, } from "./types.domain.mjs";
|
|
29
30
|
export function openStore(options) {
|
|
@@ -32,6 +33,7 @@ export function openStore(options) {
|
|
|
32
33
|
const ctx = createContext(db, options.now ? { now: options.now } : {});
|
|
33
34
|
try {
|
|
34
35
|
ensureSchema(ctx);
|
|
36
|
+
ensureAssignmentChanges(ctx);
|
|
35
37
|
}
|
|
36
38
|
catch (error) {
|
|
37
39
|
try {
|
|
@@ -53,6 +55,8 @@ export function openStore(options) {
|
|
|
53
55
|
resultScopeManaged(scope) { alive(); return resultScopeManaged(ctx, scope); },
|
|
54
56
|
handoffResultScope(input) { alive(); return handoffResultScope(ctx, input); },
|
|
55
57
|
resultSupervision(id) { alive(); return resultSupervision(ctx, id); },
|
|
58
|
+
hasSubagentManagement() { alive(); return Boolean(ctx.db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='subagent_management'").get()); },
|
|
59
|
+
resultSupervisionChanges(after) { alive(); return resultSupervisionChanges(ctx, after); },
|
|
56
60
|
resultSupervisions(activeOnly) { alive(); return resultSupervisions(ctx, activeOnly); },
|
|
57
61
|
handoffResultSupervision(input) { alive(); return handoffResultSupervision(ctx, input); },
|
|
58
62
|
handoffResultSupervisions(input) { alive(); return handoffResultSupervisions(ctx, input); },
|
|
@@ -111,6 +115,20 @@ export function openStore(options) {
|
|
|
111
115
|
alive();
|
|
112
116
|
return readOperationRecords(ctx, filter);
|
|
113
117
|
},
|
|
118
|
+
listAssignmentCleanupOperations(limit, afterOperationId) {
|
|
119
|
+
alive();
|
|
120
|
+
return readAssignmentCleanupOperations(ctx, limit, afterOperationId);
|
|
121
|
+
},
|
|
122
|
+
verifyAssignmentCleanup(operationId, launchToken, terminalRevision) {
|
|
123
|
+
alive();
|
|
124
|
+
if (!Number.isSafeInteger(terminalRevision) || terminalRevision < 1)
|
|
125
|
+
return false;
|
|
126
|
+
return run(ctx, `INSERT OR IGNORE INTO coordinator_state (key, value)
|
|
127
|
+
SELECT 'assignment-cleanup-verified:' || op.operation_id, op.launch_token
|
|
128
|
+
FROM operations op JOIN assignment_attempts a ON a.attempt_id = op.assignment_attempt_id
|
|
129
|
+
JOIN assignment_outcomes o ON o.assignment_id = a.assignment_id
|
|
130
|
+
WHERE op.operation_id = ? AND op.launch_token = ? AND op.terminal_revision = ?`, operationId, launchToken, terminalRevision) > 0;
|
|
131
|
+
},
|
|
114
132
|
listRunningSupervisedBy(hostId) {
|
|
115
133
|
alive();
|
|
116
134
|
return readRunningSupervisedBy(ctx, hostId);
|
|
@@ -232,6 +250,10 @@ export function openStore(options) {
|
|
|
232
250
|
alive();
|
|
233
251
|
return readOutbox(ctx, filter);
|
|
234
252
|
},
|
|
253
|
+
hasDeliveredWaitDependency(operationId, terminalRevision, recipient) {
|
|
254
|
+
alive();
|
|
255
|
+
return readDeliveredWaitDependency(ctx, operationId, terminalRevision, recipient);
|
|
256
|
+
},
|
|
235
257
|
listDispatchableOutboxRecipients() {
|
|
236
258
|
alive();
|
|
237
259
|
return readDispatchableOutboxRecipients(ctx);
|