pi-better-server 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -1
- package/scripts/copy-pi-test-providers.mjs +10 -0
- package/scripts/event-publication/README.md +26 -0
- package/scripts/event-publication/commit.mjs +21 -0
- package/scripts/event-publication/measure.mjs +87 -0
- package/scripts/event-publication/writer.mjs +6 -0
- package/scripts/measure-full-runtime/frontend.ts +24 -0
- package/scripts/measure-full-runtime/hosted-extension.ts +28 -0
- package/scripts/measure-full-runtime/probe.mjs +29 -0
- package/scripts/measure-full-runtime/recovery-trace-loader.mjs +51 -0
- package/scripts/measure-full-runtime/recovery-trace.mjs +16 -0
- package/scripts/measure-full-runtime.mjs +146 -0
- package/scripts/measure-shared-reads/probe.mjs +26 -2
- package/scripts/measure-shared-reads.mjs +44 -9
- package/scripts/private-runtime/package-lock.json +66 -4
- package/scripts/private-runtime/package.json +10 -2
- package/scripts/source-provenance.mjs +31 -0
- package/scripts/test-on-pi.sh +3 -9
- package/src/handshake.ts +1 -1
- package/src/hosted-session.ts +32 -4
- package/src/maintenance.ts +35 -7
- package/src/registry.ts +28 -4
- package/src/runtime/attempt-invalidation.ts +54 -0
- package/src/runtime/background-history.ts +151 -45
- package/src/runtime/background-policy.ts +27 -0
- package/src/runtime/background-tools.ts +389 -0
- package/src/runtime/background.ts +410 -48
- package/src/runtime/cancellation.ts +28 -7
- package/src/runtime/catalog-sources.ts +199 -0
- package/src/runtime/catalog.ts +53 -21
- package/src/runtime/client.ts +22 -2
- package/src/runtime/domain/assignment-inbox.mjs +119 -0
- package/src/runtime/domain/assignment-observation.d.mts +1 -1
- package/src/runtime/domain/assignment-observation.mjs +71 -33
- package/src/runtime/domain/background/process-identity.mjs +20 -2
- package/src/runtime/domain/background/process.mjs +3 -3
- package/src/runtime/domain/background/registry.mjs +89 -4
- package/src/runtime/domain/background/types.mjs +1 -0
- package/src/runtime/domain/background-service/adapter-contract.domain.mjs +83 -0
- package/src/runtime/domain/background-service/adapter-contract.ts +70 -0
- package/src/runtime/domain/background-service/batch.domain.mjs +91 -0
- package/src/runtime/domain/background-service/batch.ts +111 -0
- package/src/runtime/domain/background-service/conditions.domain.mjs +94 -0
- package/src/runtime/domain/background-service/conditions.ts +99 -0
- package/src/runtime/domain/background-service/delivery-observer.domain.mjs +37 -0
- package/src/runtime/domain/background-service/delivery-observer.ts +42 -0
- package/src/runtime/domain/background-service/failures.domain.mjs +209 -0
- package/src/runtime/domain/background-service/failures.ts +212 -0
- package/src/runtime/domain/background-service/goal-provider.domain.mjs +193 -0
- package/src/runtime/domain/background-service/goal-provider.ts +209 -0
- package/src/runtime/domain/background-service/index.domain.mjs +54 -0
- package/src/runtime/domain/background-service/index.ts +55 -0
- package/src/runtime/domain/background-service/logs.domain.mjs +129 -0
- package/src/runtime/domain/background-service/logs.ts +134 -0
- package/src/runtime/domain/background-service/maintenance.domain.mjs +95 -0
- package/src/runtime/domain/background-service/maintenance.ts +98 -0
- package/src/runtime/domain/background-service/managed-authority.domain.mjs +32 -0
- package/src/runtime/domain/background-service/managed-authority.ts +30 -0
- package/src/runtime/domain/background-service/managed-client.domain.mjs +79 -0
- package/src/runtime/domain/background-service/managed-client.ts +73 -0
- package/src/runtime/domain/background-service/managed-frontend.domain.mjs +225 -0
- package/src/runtime/domain/background-service/managed-frontend.ts +176 -0
- package/src/runtime/domain/background-service/navigator-provider.domain.mjs +492 -0
- package/src/runtime/domain/background-service/navigator-provider.ts +485 -0
- package/src/runtime/domain/background-service/observed-wait-client.domain.mjs +6 -0
- package/src/runtime/domain/background-service/observed-wait-client.ts +10 -0
- package/src/runtime/domain/background-service/observed-waits.domain.mjs +4080 -0
- package/src/runtime/domain/background-service/observed-waits.ts +4513 -0
- package/src/runtime/domain/background-service/output.domain.mjs +867 -0
- package/src/runtime/domain/background-service/output.ts +952 -0
- package/src/runtime/domain/background-service/process-identity.domain.mjs +129 -0
- package/src/runtime/domain/background-service/process-identity.ts +134 -0
- package/src/runtime/domain/background-service/process.domain.mjs +512 -0
- package/src/runtime/domain/background-service/process.ts +532 -0
- package/src/runtime/domain/background-service/prompt.domain.mjs +58 -0
- package/src/runtime/domain/background-service/prompt.ts +72 -0
- package/src/runtime/domain/background-service/registry.domain.mjs +460 -0
- package/src/runtime/domain/background-service/registry.ts +450 -0
- package/src/runtime/domain/background-service/remote-task-preset.domain.mjs +67 -0
- package/src/runtime/domain/background-service/remote-task-preset.ts +127 -0
- package/src/runtime/domain/background-service/runtime.domain.mjs +1511 -0
- package/src/runtime/domain/background-service/runtime.ts +1636 -0
- package/src/runtime/domain/background-service/sandbox.domain.mjs +735 -0
- package/src/runtime/domain/background-service/sandbox.ts +913 -0
- package/src/runtime/domain/background-service/shared-callback-batcher.domain.mjs +777 -0
- package/src/runtime/domain/background-service/shared-callback-batcher.ts +956 -0
- package/src/runtime/domain/background-service/shared-execution-policy.domain.mjs +50 -0
- package/src/runtime/domain/background-service/shared-execution-policy.ts +61 -0
- package/src/runtime/domain/background-service/shared-failure-observations.domain.mjs +1078 -0
- package/src/runtime/domain/background-service/shared-failure-observations.ts +1166 -0
- package/src/runtime/domain/background-service/shared-harness-settings.domain.mjs +126 -0
- package/src/runtime/domain/background-service/shared-harness-settings.ts +116 -0
- package/src/runtime/domain/background-service/shared-log-utils.domain.mjs +1223 -0
- package/src/runtime/domain/background-service/shared-log-utils.ts +1492 -0
- package/src/runtime/domain/background-service/shared-navigator-panels.domain.mjs +289 -0
- package/src/runtime/domain/background-service/shared-navigator-panels.ts +272 -0
- package/src/runtime/domain/background-service/shared-navigator.domain.mjs +1930 -0
- package/src/runtime/domain/background-service/shared-navigator.ts +1962 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-inbox.mjs +144 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-observation.mjs +189 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/index.domain.mjs +51 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/index.ts +122 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.ts +73 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +163 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.ts +174 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-parent-callbacks.domain.mjs +66 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-parent-callbacks.ts +68 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.domain.mjs +87 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.ts +90 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.domain.mjs +97 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.ts +139 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/errors.domain.mjs +12 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/errors.ts +79 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.domain.mjs +342 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.ts +513 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.domain.mjs +283 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.ts +458 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/recovery.domain.mjs +52 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/recovery.ts +55 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.domain.mjs +114 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.ts +140 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.domain.mjs +280 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.ts +442 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.domain.mjs +420 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.ts +441 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/sqlite.domain.mjs +194 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/sqlite.ts +239 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +275 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +585 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.domain.mjs +120 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.ts +142 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/task-cancellation.domain.mjs +188 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/task-cancellation.ts +224 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.domain.mjs +25 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.ts +707 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/upgrade.domain.mjs +22 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/upgrade.ts +22 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/validate.domain.mjs +234 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/validate.ts +241 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/waits.domain.mjs +851 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/waits.ts +1424 -0
- package/src/runtime/domain/background-service/shared-permission-blocker.domain.mjs +40 -0
- package/src/runtime/domain/background-service/shared-permission-blocker.ts +48 -0
- package/src/runtime/domain/background-service/shared-render-scheduler.domain.mjs +41 -0
- package/src/runtime/domain/background-service/shared-render-scheduler.ts +47 -0
- package/src/runtime/domain/background-service/shared-sandbox-core.domain.mjs +1531 -0
- package/src/runtime/domain/background-service/shared-sandbox-core.ts +1757 -0
- package/src/runtime/domain/background-service/shared-sandbox-diagnostics.domain.mjs +591 -0
- package/src/runtime/domain/background-service/shared-sandbox-diagnostics.ts +491 -0
- package/src/runtime/domain/background-service/shared-ssh-core/index.domain.mjs +698 -0
- package/src/runtime/domain/background-service/shared-ssh-core/index.ts +979 -0
- package/src/runtime/domain/background-service/shared-stall-detector.domain.mjs +37 -0
- package/src/runtime/domain/background-service/shared-stall-detector.ts +69 -0
- package/src/runtime/domain/background-service/shared-work-client.mjs +303 -0
- package/src/runtime/domain/background-service/stall-attention.domain.mjs +29 -0
- package/src/runtime/domain/background-service/stall-attention.ts +31 -0
- package/src/runtime/domain/background-service/stall.domain.mjs +57 -0
- package/src/runtime/domain/background-service/stall.ts +57 -0
- package/src/runtime/domain/background-service/supervisor/README.md +111 -0
- package/src/runtime/domain/background-service/supervisor/emit-runner.mjs +90 -0
- package/src/runtime/domain/background-service/supervisor/generated/conditions.mjs +96 -0
- package/src/runtime/domain/background-service/supervisor/generated/identity.mjs +95 -0
- package/src/runtime/domain/background-service/supervisor/generated/process-identity.mjs +131 -0
- package/src/runtime/domain/background-service/supervisor/generated/process.mjs +514 -0
- package/src/runtime/domain/background-service/supervisor/generated/runner.mjs +872 -0
- package/src/runtime/domain/background-service/supervisor/generated/store.mjs +609 -0
- package/src/runtime/domain/background-service/supervisor/generated/types.mjs +50 -0
- package/src/runtime/domain/background-service/supervisor/identity.domain.mjs +93 -0
- package/src/runtime/domain/background-service/supervisor/identity.ts +99 -0
- package/src/runtime/domain/background-service/supervisor/index.domain.mjs +22 -0
- package/src/runtime/domain/background-service/supervisor/index.ts +37 -0
- package/src/runtime/domain/background-service/supervisor/invocation.domain.mjs +30 -0
- package/src/runtime/domain/background-service/supervisor/invocation.ts +44 -0
- package/src/runtime/domain/background-service/supervisor/runner.domain.mjs +870 -0
- package/src/runtime/domain/background-service/supervisor/runner.ts +982 -0
- package/src/runtime/domain/background-service/supervisor/store.domain.mjs +605 -0
- package/src/runtime/domain/background-service/supervisor/store.ts +651 -0
- package/src/runtime/domain/background-service/supervisor/supervisor.domain.mjs +721 -0
- package/src/runtime/domain/background-service/supervisor/supervisor.ts +804 -0
- package/src/runtime/domain/background-service/supervisor/types.domain.mjs +48 -0
- package/src/runtime/domain/background-service/supervisor/types.ts +394 -0
- package/src/runtime/domain/background-service/task-diagnostics.domain.mjs +60 -0
- package/src/runtime/domain/background-service/task-diagnostics.ts +71 -0
- package/src/runtime/domain/background-service/tools.domain.mjs +1050 -0
- package/src/runtime/domain/background-service/tools.ts +1142 -0
- package/src/runtime/domain/background-service/types.domain.mjs +5 -0
- package/src/runtime/domain/background-service/types.ts +236 -0
- package/src/runtime/domain/background-service/work-observation.domain.mjs +176 -0
- package/src/runtime/domain/background-service/work-observation.ts +144 -0
- package/src/runtime/domain/catalog/catalog-store.d.mts +9 -1
- package/src/runtime/domain/catalog/catalog-store.mjs +20 -22
- package/src/runtime/domain/coordinator/src/assignment-changes.mjs +75 -0
- package/src/runtime/domain/coordinator/src/assignment-outcomes.mjs +2 -0
- package/src/runtime/domain/coordinator/src/background-parent-callbacks.mjs +65 -0
- package/src/runtime/domain/coordinator/src/background-requests.mjs +86 -0
- package/src/runtime/domain/coordinator/src/discovery.mjs +4 -2
- package/src/runtime/domain/coordinator/src/operations.mjs +44 -4
- package/src/runtime/domain/coordinator/src/result-supervision.mjs +12 -0
- package/src/runtime/domain/coordinator/src/rows.mjs +2 -0
- package/src/runtime/domain/coordinator/src/schema.mjs +73 -21
- package/src/runtime/domain/coordinator/src/store.mjs +32 -3
- package/src/runtime/domain/coordinator/src/subagent-launch.mjs +119 -0
- package/src/runtime/domain/coordinator/src/types.mjs +1 -1
- package/src/runtime/domain/coordinator/src/upgrade.mjs +22 -0
- package/src/runtime/domain/health-observation.d.mts +3 -1
- package/src/runtime/domain/health-observation.mjs +189 -190
- package/src/runtime/domain/log-cursor.d.mts +2 -0
- package/src/runtime/domain/log-cursor.mjs +85 -16
- package/src/runtime/domain/parse.d.mts +4 -1
- package/src/runtime/domain/parse.mjs +50 -5
- package/src/runtime/domain/sandbox-policy/README.md +633 -0
- package/src/runtime/domain/sandbox-policy/background-admission.domain.mjs +83 -0
- package/src/runtime/domain/sandbox-policy/background-admission.ts +75 -0
- package/src/runtime/domain/sandbox-policy/commands.domain.mjs +245 -0
- package/src/runtime/domain/sandbox-policy/commands.ts +336 -0
- package/src/runtime/domain/sandbox-policy/deny-rules.domain.mjs +440 -0
- package/src/runtime/domain/sandbox-policy/deny-rules.ts +620 -0
- package/src/runtime/domain/sandbox-policy/diagnostics-command.domain.mjs +30 -0
- package/src/runtime/domain/sandbox-policy/diagnostics-command.ts +27 -0
- package/src/runtime/domain/sandbox-policy/events.domain.mjs +49 -0
- package/src/runtime/domain/sandbox-policy/events.ts +85 -0
- package/src/runtime/domain/sandbox-policy/files.domain.mjs +153 -0
- package/src/runtime/domain/sandbox-policy/files.ts +224 -0
- package/src/runtime/domain/sandbox-policy/index.domain.mjs +289 -0
- package/src/runtime/domain/sandbox-policy/index.ts +386 -0
- package/src/runtime/domain/sandbox-policy/package.json +66 -0
- package/src/runtime/domain/sandbox-policy/permission-settings.domain.mjs +36 -0
- package/src/runtime/domain/sandbox-policy/permission-settings.ts +46 -0
- package/src/runtime/domain/sandbox-policy/permissions-page.domain.mjs +309 -0
- package/src/runtime/domain/sandbox-policy/permissions-page.ts +295 -0
- package/src/runtime/domain/sandbox-policy/permissions.domain.mjs +98 -0
- package/src/runtime/domain/sandbox-policy/permissions.ts +125 -0
- package/src/runtime/domain/sandbox-policy/policy.domain.mjs +80 -0
- package/src/runtime/domain/sandbox-policy/policy.ts +102 -0
- package/src/runtime/domain/sandbox-policy/preferences.domain.mjs +55 -0
- package/src/runtime/domain/sandbox-policy/preferences.ts +82 -0
- package/src/runtime/domain/sandbox-policy/rules-page.domain.mjs +138 -0
- package/src/runtime/domain/sandbox-policy/rules-page.ts +176 -0
- package/src/runtime/domain/sandbox-policy/session-permissions.domain.mjs +22 -0
- package/src/runtime/domain/sandbox-policy/session-permissions.ts +24 -0
- package/src/runtime/domain/sandbox-policy/shared-harness-settings.domain.mjs +126 -0
- package/src/runtime/domain/sandbox-policy/shared-harness-settings.ts +116 -0
- package/src/runtime/domain/sandbox-policy/shared-permission-blocker.domain.mjs +40 -0
- package/src/runtime/domain/sandbox-policy/shared-permission-blocker.ts +48 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-core.domain.mjs +1531 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-core.ts +1757 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-diagnostics.domain.mjs +591 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-diagnostics.ts +491 -0
- package/src/runtime/domain/sandbox-policy/shared-task-application.domain.mjs +185 -0
- package/src/runtime/domain/sandbox-policy/shared-task-application.ts +185 -0
- package/src/runtime/domain/sandbox-policy/shared-task-apply-patch.domain.mjs +416 -0
- package/src/runtime/domain/sandbox-policy/shared-task-apply-patch.ts +409 -0
- package/src/runtime/domain/sandbox-policy/shared-task-exec.domain.mjs +325 -0
- package/src/runtime/domain/sandbox-policy/shared-task-exec.ts +335 -0
- package/src/runtime/domain/sandbox-policy/shared-task-files.domain.mjs +346 -0
- package/src/runtime/domain/sandbox-policy/shared-task-files.ts +342 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-identity.domain.mjs +140 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-identity.ts +126 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-list.domain.mjs +220 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-list.ts +209 -0
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.domain.mjs +227 -0
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.ts +224 -0
- package/src/runtime/domain/sandbox-policy/shared-task-tools.domain.mjs +92 -0
- package/src/runtime/domain/sandbox-policy/shared-task-tools.ts +123 -0
- package/src/runtime/domain/sandbox-policy/shell.domain.mjs +93 -0
- package/src/runtime/domain/sandbox-policy/shell.ts +129 -0
- package/src/runtime/domain/sandbox-policy/state.domain.mjs +307 -0
- package/src/runtime/domain/sandbox-policy/state.ts +408 -0
- package/src/runtime/domain/sandbox-policy/status.domain.mjs +64 -0
- package/src/runtime/domain/sandbox-policy/status.ts +76 -0
- package/src/runtime/domain/sandbox-policy/subagent-admission.domain.mjs +69 -0
- package/src/runtime/domain/sandbox-policy/subagent-admission.ts +60 -0
- package/src/runtime/domain/subagents/CONTEXT.md +202 -0
- package/src/runtime/domain/subagents/PRODUCT.md +49 -0
- package/src/runtime/domain/subagents/README.md +201 -0
- package/src/runtime/domain/subagents/agent-catalog.mjs +64 -0
- package/src/runtime/domain/subagents/agent-commands.domain.mjs +822 -0
- package/src/runtime/domain/subagents/agent-commands.ts +905 -0
- package/src/runtime/domain/subagents/agent-inspection.domain.mjs +398 -0
- package/src/runtime/domain/subagents/agent-inspection.ts +574 -0
- package/src/runtime/domain/subagents/agent-operations.domain.mjs +40 -0
- package/src/runtime/domain/subagents/agent-operations.ts +61 -0
- package/src/runtime/domain/subagents/agent-session-settings.domain.mjs +112 -0
- package/src/runtime/domain/subagents/agent-session-settings.ts +118 -0
- package/src/runtime/domain/subagents/agents-catalog-tool.domain.mjs +84 -0
- package/src/runtime/domain/subagents/agents-catalog-tool.ts +118 -0
- package/src/runtime/domain/subagents/assignment-outcomes.domain.mjs +276 -0
- package/src/runtime/domain/subagents/assignment-outcomes.ts +212 -0
- package/src/runtime/domain/subagents/assignment-projection.mjs +261 -0
- package/src/runtime/domain/subagents/assignment-report.domain.mjs +174 -0
- package/src/runtime/domain/subagents/assignment-report.ts +156 -0
- package/src/runtime/domain/subagents/batch.mjs +275 -0
- package/src/runtime/domain/subagents/callback-fields.domain.mjs +72 -0
- package/src/runtime/domain/subagents/callback-fields.ts +95 -0
- package/src/runtime/domain/subagents/capacity.mjs +108 -0
- package/src/runtime/domain/subagents/catalog-editor.domain.mjs +98 -0
- package/src/runtime/domain/subagents/catalog-editor.ts +125 -0
- package/src/runtime/domain/subagents/catalog-host-admission.domain.mjs +104 -0
- package/src/runtime/domain/subagents/catalog-host-admission.ts +85 -0
- package/src/runtime/domain/subagents/catalog-identity.domain.mjs +222 -0
- package/src/runtime/domain/subagents/catalog-identity.ts +258 -0
- package/src/runtime/domain/subagents/catalog-overlay.domain.mjs +9 -0
- package/src/runtime/domain/subagents/catalog-overlay.ts +10 -0
- package/src/runtime/domain/subagents/catalog-preferences.domain.mjs +164 -0
- package/src/runtime/domain/subagents/catalog-preferences.ts +139 -0
- package/src/runtime/domain/subagents/catalog-resolver.domain.mjs +366 -0
- package/src/runtime/domain/subagents/catalog-resolver.ts +540 -0
- package/src/runtime/domain/subagents/catalog-runtime.domain.mjs +570 -0
- package/src/runtime/domain/subagents/catalog-runtime.ts +680 -0
- package/src/runtime/domain/subagents/catalog-schema.domain.mjs +1331 -0
- package/src/runtime/domain/subagents/catalog-schema.ts +1563 -0
- package/src/runtime/domain/subagents/catalog-skill-edits.domain.mjs +95 -0
- package/src/runtime/domain/subagents/catalog-skill-edits.ts +116 -0
- package/src/runtime/domain/subagents/catalog-store.domain.mjs +808 -0
- package/src/runtime/domain/subagents/catalog-store.ts +1006 -0
- package/src/runtime/domain/subagents/catalog-ui.domain.mjs +651 -0
- package/src/runtime/domain/subagents/catalog-ui.ts +611 -0
- package/src/runtime/domain/subagents/child-apply-patch.domain.mjs +13 -0
- package/src/runtime/domain/subagents/child-apply-patch.ts +13 -0
- package/src/runtime/domain/subagents/child-codemode.domain.mjs +16 -0
- package/src/runtime/domain/subagents/child-codemode.ts +17 -0
- package/src/runtime/domain/subagents/child-dependencies.mjs +193 -0
- package/src/runtime/domain/subagents/child-incidents.domain.mjs +170 -0
- package/src/runtime/domain/subagents/child-incidents.ts +169 -0
- package/src/runtime/domain/subagents/child-operations.domain.mjs +986 -0
- package/src/runtime/domain/subagents/child-operations.ts +1191 -0
- package/src/runtime/domain/subagents/child-ownership.domain.mjs +205 -0
- package/src/runtime/domain/subagents/child-ownership.ts +160 -0
- package/src/runtime/domain/subagents/child-preflight.mjs +38 -0
- package/src/runtime/domain/subagents/child-process-list.domain.mjs +7 -0
- package/src/runtime/domain/subagents/child-process-list.ts +8 -0
- package/src/runtime/domain/subagents/child-runtime.mjs +67 -0
- package/src/runtime/domain/subagents/child-steer.domain.mjs +109 -0
- package/src/runtime/domain/subagents/child-steer.ts +102 -0
- package/src/runtime/domain/subagents/cleanup.domain.mjs +818 -0
- package/src/runtime/domain/subagents/cleanup.ts +1017 -0
- package/src/runtime/domain/subagents/codex-import.domain.mjs +575 -0
- package/src/runtime/domain/subagents/codex-import.ts +717 -0
- package/src/runtime/domain/subagents/completion.domain.mjs +6 -0
- package/src/runtime/domain/subagents/completion.mjs +152 -0
- package/src/runtime/domain/subagents/completion.ts +11 -0
- package/src/runtime/domain/subagents/config.domain.mjs +248 -0
- package/src/runtime/domain/subagents/config.json +15 -0
- package/src/runtime/domain/subagents/config.ts +328 -0
- package/src/runtime/domain/subagents/continuation-authority.domain.mjs +38 -0
- package/src/runtime/domain/subagents/continuation-authority.ts +31 -0
- package/src/runtime/domain/subagents/continuation-runtime.domain.mjs +89 -0
- package/src/runtime/domain/subagents/continuation-runtime.ts +88 -0
- package/src/runtime/domain/subagents/continuation.domain.mjs +942 -0
- package/src/runtime/domain/subagents/continuation.ts +1051 -0
- package/src/runtime/domain/subagents/delegation.domain.mjs +19 -0
- package/src/runtime/domain/subagents/delegation.ts +24 -0
- package/src/runtime/domain/subagents/effective-settings.domain.mjs +130 -0
- package/src/runtime/domain/subagents/effective-settings.ts +184 -0
- package/src/runtime/domain/subagents/extensions.domain.mjs +6 -0
- package/src/runtime/domain/subagents/extensions.mjs +164 -0
- package/src/runtime/domain/subagents/extensions.ts +19 -0
- package/src/runtime/domain/subagents/failures.domain.mjs +362 -0
- package/src/runtime/domain/subagents/failures.ts +319 -0
- package/src/runtime/domain/subagents/finalization.domain.mjs +168 -0
- package/src/runtime/domain/subagents/finalization.ts +218 -0
- package/src/runtime/domain/subagents/git-remotes.domain.mjs +351 -0
- package/src/runtime/domain/subagents/git-remotes.ts +413 -0
- package/src/runtime/domain/subagents/git-workspace.domain.mjs +337 -0
- package/src/runtime/domain/subagents/git-workspace.ts +430 -0
- package/src/runtime/domain/subagents/goal-provider.domain.mjs +125 -0
- package/src/runtime/domain/subagents/goal-provider.ts +132 -0
- package/src/runtime/domain/subagents/health-observation.domain.mjs +617 -0
- package/src/runtime/domain/subagents/health-observation.ts +818 -0
- package/src/runtime/domain/subagents/health-surface.mjs +284 -0
- package/src/runtime/domain/subagents/health.domain.mjs +261 -0
- package/src/runtime/domain/subagents/health.ts +343 -0
- package/src/runtime/domain/subagents/historical-attention.domain.mjs +37 -0
- package/src/runtime/domain/subagents/historical-attention.ts +35 -0
- package/src/runtime/domain/subagents/incident-model.domain.mjs +322 -0
- package/src/runtime/domain/subagents/incident-model.ts +358 -0
- package/src/runtime/domain/subagents/index.domain.mjs +4731 -0
- package/src/runtime/domain/subagents/index.ts +4781 -0
- package/src/runtime/domain/subagents/launch-abort.domain.mjs +13 -0
- package/src/runtime/domain/subagents/launch-abort.ts +21 -0
- package/src/runtime/domain/subagents/launch-context.domain.mjs +24 -0
- package/src/runtime/domain/subagents/launch-context.ts +23 -0
- package/src/runtime/domain/subagents/launch-digest.mjs +6 -0
- package/src/runtime/domain/subagents/lifecycle.domain.mjs +265 -0
- package/src/runtime/domain/subagents/lifecycle.ts +360 -0
- package/src/runtime/domain/subagents/list.domain.mjs +2 -0
- package/src/runtime/domain/subagents/list.mjs +152 -0
- package/src/runtime/domain/subagents/list.ts +19 -0
- package/src/runtime/domain/subagents/log-cursor.domain.mjs +217 -0
- package/src/runtime/domain/subagents/log-cursor.ts +268 -0
- package/src/runtime/domain/subagents/managed-background-capability.domain.mjs +10 -0
- package/src/runtime/domain/subagents/managed-background-capability.ts +9 -0
- package/src/runtime/domain/subagents/managed-failure-worker.mjs +36 -0
- package/src/runtime/domain/subagents/managed-launch-bootstrap.mjs +48 -0
- package/src/runtime/domain/subagents/managed-launch-client.domain.mjs +75 -0
- package/src/runtime/domain/subagents/managed-launch-client.ts +59 -0
- package/src/runtime/domain/subagents/managed-launch-host.domain.mjs +627 -0
- package/src/runtime/domain/subagents/managed-launch-host.ts +504 -0
- package/src/runtime/domain/subagents/managed-launch-journal.mjs +17 -0
- package/src/runtime/domain/subagents/managed-launch-ownership.domain.mjs +29 -0
- package/src/runtime/domain/subagents/managed-launch-ownership.ts +22 -0
- package/src/runtime/domain/subagents/managed-launch-port.domain.mjs +2 -0
- package/src/runtime/domain/subagents/managed-launch-port.ts +25 -0
- package/src/runtime/domain/subagents/managed-launch-recovery.domain.mjs +29 -0
- package/src/runtime/domain/subagents/managed-launch-recovery.ts +45 -0
- package/src/runtime/domain/subagents/managed-worker-bridge.domain.mjs +63 -0
- package/src/runtime/domain/subagents/managed-worker-bridge.ts +48 -0
- package/src/runtime/domain/subagents/managed-worker.mjs +13 -0
- package/src/runtime/domain/subagents/model-resolution-core.domain.mjs +822 -0
- package/src/runtime/domain/subagents/model-resolution-core.ts +1074 -0
- package/src/runtime/domain/subagents/model-resolution.domain.mjs +22 -0
- package/src/runtime/domain/subagents/model-resolution.ts +32 -0
- package/src/runtime/domain/subagents/navigator.domain.mjs +6 -0
- package/src/runtime/domain/subagents/navigator.mjs +1233 -0
- package/src/runtime/domain/subagents/navigator.ts +39 -0
- package/src/runtime/domain/subagents/operation-bridge-types.domain.mjs +1012 -0
- package/src/runtime/domain/subagents/operation-bridge-types.ts +1156 -0
- package/src/runtime/domain/subagents/outage-observations.domain.mjs +84 -0
- package/src/runtime/domain/subagents/outage-observations.ts +73 -0
- package/src/runtime/domain/subagents/output-payload.domain.mjs +767 -0
- package/src/runtime/domain/subagents/output-payload.ts +987 -0
- package/src/runtime/domain/subagents/owned-exit.domain.mjs +12 -0
- package/src/runtime/domain/subagents/owned-exit.ts +12 -0
- package/src/runtime/domain/subagents/package.json +86 -0
- package/src/runtime/domain/subagents/park-checkpoint.domain.mjs +55 -0
- package/src/runtime/domain/subagents/park-checkpoint.ts +61 -0
- package/src/runtime/domain/subagents/parse.domain.mjs +1218 -0
- package/src/runtime/domain/subagents/parse.ts +1451 -0
- package/src/runtime/domain/subagents/permission-policy.domain.mjs +232 -0
- package/src/runtime/domain/subagents/permission-policy.ts +291 -0
- package/src/runtime/domain/subagents/process-identity.mjs +33 -0
- package/src/runtime/domain/subagents/registry.domain.mjs +1584 -0
- package/src/runtime/domain/subagents/registry.ts +1904 -0
- package/src/runtime/domain/subagents/role-assignment.domain.mjs +104 -0
- package/src/runtime/domain/subagents/role-assignment.ts +141 -0
- package/src/runtime/domain/subagents/roles/role.architect.md +13 -0
- package/src/runtime/domain/subagents/roles/role.developer.md +16 -0
- package/src/runtime/domain/subagents/roles/role.explorer.md +13 -0
- package/src/runtime/domain/subagents/roles/role.product-manager.md +13 -0
- package/src/runtime/domain/subagents/roles/role.researcher.md +13 -0
- package/src/runtime/domain/subagents/roles/role.reviewer.md +13 -0
- package/src/runtime/domain/subagents/roles/role.writer.md +12 -0
- package/src/runtime/domain/subagents/sandbox.domain.mjs +64 -0
- package/src/runtime/domain/subagents/sandbox.ts +92 -0
- package/src/runtime/domain/subagents/session-selection.domain.mjs +32 -0
- package/src/runtime/domain/subagents/session-selection.ts +35 -0
- package/src/runtime/domain/subagents/session-store.domain.mjs +489 -0
- package/src/runtime/domain/subagents/session-store.ts +468 -0
- package/src/runtime/domain/subagents/settings-page.domain.mjs +313 -0
- package/src/runtime/domain/subagents/settings-page.ts +363 -0
- package/src/runtime/domain/subagents/shared-callback-batcher.domain.mjs +777 -0
- package/src/runtime/domain/subagents/shared-callback-batcher.ts +956 -0
- package/src/runtime/domain/subagents/shared-catalog.domain.mjs +70 -0
- package/src/runtime/domain/subagents/shared-catalog.ts +61 -0
- package/src/runtime/domain/subagents/shared-execution-policy.domain.mjs +50 -0
- package/src/runtime/domain/subagents/shared-execution-policy.ts +61 -0
- package/src/runtime/domain/subagents/shared-failure-observations.domain.mjs +1078 -0
- package/src/runtime/domain/subagents/shared-failure-observations.ts +1166 -0
- package/src/runtime/domain/subagents/shared-harness-settings.domain.mjs +126 -0
- package/src/runtime/domain/subagents/shared-harness-settings.ts +116 -0
- package/src/runtime/domain/subagents/shared-log-utils.domain.mjs +1223 -0
- package/src/runtime/domain/subagents/shared-log-utils.ts +1492 -0
- package/src/runtime/domain/subagents/shared-navigator-panels.domain.mjs +289 -0
- package/src/runtime/domain/subagents/shared-navigator-panels.ts +272 -0
- package/src/runtime/domain/subagents/shared-navigator.domain.mjs +1930 -0
- package/src/runtime/domain/subagents/shared-navigator.ts +1962 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-inbox.mjs +144 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-observation.mjs +189 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/index.domain.mjs +51 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/index.ts +122 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.ts +73 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +163 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.ts +174 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-parent-callbacks.domain.mjs +66 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-parent-callbacks.ts +68 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.domain.mjs +87 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.ts +90 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.domain.mjs +97 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.ts +139 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/errors.domain.mjs +12 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/errors.ts +79 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.domain.mjs +342 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.ts +513 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.domain.mjs +283 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.ts +458 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/recovery.domain.mjs +52 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/recovery.ts +55 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.domain.mjs +114 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.ts +140 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.domain.mjs +280 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.ts +442 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.domain.mjs +420 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.ts +441 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/sqlite.domain.mjs +194 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/sqlite.ts +239 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +275 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +585 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.domain.mjs +120 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.ts +142 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-cancellation.domain.mjs +188 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-cancellation.ts +224 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.domain.mjs +25 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.ts +707 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/upgrade.domain.mjs +22 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/upgrade.ts +22 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/validate.domain.mjs +234 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/validate.ts +241 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/waits.domain.mjs +851 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/waits.ts +1424 -0
- package/src/runtime/domain/subagents/shared-permission-blocker.domain.mjs +40 -0
- package/src/runtime/domain/subagents/shared-permission-blocker.ts +48 -0
- package/src/runtime/domain/subagents/shared-render-scheduler.domain.mjs +41 -0
- package/src/runtime/domain/subagents/shared-render-scheduler.ts +47 -0
- package/src/runtime/domain/subagents/shared-sandbox-core.domain.mjs +1531 -0
- package/src/runtime/domain/subagents/shared-sandbox-core.ts +1757 -0
- package/src/runtime/domain/subagents/shared-sandbox-diagnostics.domain.mjs +591 -0
- package/src/runtime/domain/subagents/shared-sandbox-diagnostics.ts +491 -0
- package/src/runtime/domain/subagents/shared-stall-detector.domain.mjs +37 -0
- package/src/runtime/domain/subagents/shared-stall-detector.ts +69 -0
- package/src/runtime/domain/subagents/shared-task-application.domain.mjs +185 -0
- package/src/runtime/domain/subagents/shared-task-application.ts +185 -0
- package/src/runtime/domain/subagents/shared-task-apply-patch.domain.mjs +416 -0
- package/src/runtime/domain/subagents/shared-task-apply-patch.ts +409 -0
- package/src/runtime/domain/subagents/shared-task-exec.domain.mjs +325 -0
- package/src/runtime/domain/subagents/shared-task-exec.ts +335 -0
- package/src/runtime/domain/subagents/shared-task-files.domain.mjs +346 -0
- package/src/runtime/domain/subagents/shared-task-files.ts +342 -0
- package/src/runtime/domain/subagents/shared-task-process-identity.domain.mjs +140 -0
- package/src/runtime/domain/subagents/shared-task-process-identity.ts +126 -0
- package/src/runtime/domain/subagents/shared-task-process-list.domain.mjs +220 -0
- package/src/runtime/domain/subagents/shared-task-process-list.ts +209 -0
- package/src/runtime/domain/subagents/shared-task-sandbox.domain.mjs +227 -0
- package/src/runtime/domain/subagents/shared-task-sandbox.ts +224 -0
- package/src/runtime/domain/subagents/shared-task-tools.domain.mjs +92 -0
- package/src/runtime/domain/subagents/shared-task-tools.ts +123 -0
- package/src/runtime/domain/subagents/shared-work-client.mjs +303 -0
- package/src/runtime/domain/subagents/shared-worktree-context.domain.mjs +142 -0
- package/src/runtime/domain/subagents/shared-worktree-context.ts +158 -0
- package/src/runtime/domain/subagents/skill-picker.domain.mjs +316 -0
- package/src/runtime/domain/subagents/skill-picker.ts +353 -0
- package/src/runtime/domain/subagents/skills.domain.mjs +138 -0
- package/src/runtime/domain/subagents/skills.ts +183 -0
- package/src/runtime/domain/subagents/spawn.domain.mjs +72 -0
- package/src/runtime/domain/subagents/spawn.ts +80 -0
- package/src/runtime/domain/subagents/stop.domain.mjs +184 -0
- package/src/runtime/domain/subagents/stop.ts +217 -0
- package/src/runtime/domain/subagents/subagent-tools.domain.mjs +101 -0
- package/src/runtime/domain/subagents/subagent-tools.ts +137 -0
- package/src/runtime/domain/subagents/task-guard.domain.mjs +163 -0
- package/src/runtime/domain/subagents/task-guard.ts +144 -0
- package/src/runtime/domain/subagents/task-policy.domain.mjs +201 -0
- package/src/runtime/domain/subagents/task-policy.ts +236 -0
- package/src/runtime/domain/subagents/task-runtime.mjs +53 -0
- package/src/runtime/domain/subagents/task-tool-owner.domain.mjs +18 -0
- package/src/runtime/domain/subagents/task-tool-owner.ts +21 -0
- package/src/runtime/domain/subagents/thinking.domain.mjs +22 -0
- package/src/runtime/domain/subagents/thinking.ts +28 -0
- package/src/runtime/domain/subagents/tier-policy.domain.mjs +75 -0
- package/src/runtime/domain/subagents/tier-policy.ts +126 -0
- package/src/runtime/domain/subagents/timing-notifications.domain.mjs +51 -0
- package/src/runtime/domain/subagents/timing-notifications.ts +37 -0
- package/src/runtime/domain/subagents/timing.domain.mjs +487 -0
- package/src/runtime/domain/subagents/timing.ts +634 -0
- package/src/runtime/domain/subagents/tools.domain.mjs +558 -0
- package/src/runtime/domain/subagents/tools.ts +629 -0
- package/src/runtime/domain/subagents/widget.domain.mjs +6 -0
- package/src/runtime/domain/subagents/widget.mjs +246 -0
- package/src/runtime/domain/subagents/widget.ts +30 -0
- package/src/runtime/domain/subagents/work-observation.domain.mjs +316 -0
- package/src/runtime/domain/subagents/work-observation.ts +248 -0
- package/src/runtime/domain/subagents/worker-catalog.domain.mjs +120 -0
- package/src/runtime/domain/subagents/worker-catalog.ts +162 -0
- package/src/runtime/domain/subagents/worker-operations-host.domain.mjs +1009 -0
- package/src/runtime/domain/subagents/worker-operations-host.ts +1238 -0
- package/src/runtime/domain/subagents/worker-waits.domain.mjs +2336 -0
- package/src/runtime/domain/subagents/worker-waits.ts +2878 -0
- package/src/runtime/domain/subagents/workspace-scope.domain.mjs +52 -0
- package/src/runtime/domain/subagents/workspace-scope.ts +50 -0
- package/src/runtime/health-config.ts +27 -11
- package/src/runtime/log-checkpoints.ts +117 -0
- package/src/runtime/mutation-store.ts +5 -4
- package/src/runtime/queries.ts +27 -3
- package/src/runtime/query-executor.ts +178 -34
- package/src/runtime/query-worker.mjs +119 -22
- package/src/runtime/read-model.ts +939 -113
- package/src/runtime/read-watchdog-probe.ts +4 -0
- package/src/runtime/result-supervision.ts +188 -16
- package/src/runtime/source-watch.ts +175 -0
- package/src/runtime/subagent-launch.ts +73 -0
- package/src/runtime/work-budget.ts +130 -0
- package/src/runtime/work-client.d.mts +8 -0
- package/src/runtime/work-client.mjs +150 -7
- package/src/server.ts +185 -22
- package/src/session-activity.ts +26 -4
- package/src/version.ts +1 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { performance } from 'node:perf_hooks';
|
|
2
|
+
import { setImmediate as yieldTurn } from 'node:timers/promises';
|
|
3
|
+
|
|
4
|
+
interface Attempt {
|
|
5
|
+
id: string; sessionId?: string; cwd: string; resumedFrom?: string;
|
|
6
|
+
operations?: { resumeLaunchToken?: string };
|
|
7
|
+
assignment?: { assignmentId?: string };
|
|
8
|
+
}
|
|
9
|
+
type Graph = Map<string, Set<string>>;
|
|
10
|
+
|
|
11
|
+
/** Index resume edges once; each invalidated component is visited at most once per scope. */
|
|
12
|
+
export async function affectedAttempts(related: Iterable<Attempt>, changed: Iterable<Attempt>): Promise<Set<string>> {
|
|
13
|
+
const graphs = new Map<string, Graph>();
|
|
14
|
+
const visited = new Map<string, Set<string>>();
|
|
15
|
+
const affected = new Set<string>();
|
|
16
|
+
let sliceStarted = performance.now(), operations = 0;
|
|
17
|
+
const checkpoint = async () => {
|
|
18
|
+
if (++operations % 256 === 0 || performance.now() - sliceStarted >= 8) {
|
|
19
|
+
await yieldTurn(); sliceStarted = performance.now();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const scope = (meta: Attempt, assignment: boolean) => JSON.stringify([
|
|
23
|
+
meta.sessionId, meta.cwd, assignment, assignment ? meta.assignment?.assignmentId : null,
|
|
24
|
+
]);
|
|
25
|
+
for (const meta of related) {
|
|
26
|
+
if (meta.operations?.resumeLaunchToken && meta.resumedFrom) {
|
|
27
|
+
for (const key of [scope(meta, false), scope(meta, true)]) {
|
|
28
|
+
let graph = graphs.get(key);
|
|
29
|
+
if (!graph) { graph = new Map(); graphs.set(key, graph); }
|
|
30
|
+
for (const [from, to] of [[meta.id, meta.resumedFrom], [meta.resumedFrom, meta.id]]) {
|
|
31
|
+
let neighbors = graph.get(from!);
|
|
32
|
+
if (!neighbors) { neighbors = new Set(); graph.set(from!, neighbors); }
|
|
33
|
+
neighbors.add(to!);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
await checkpoint();
|
|
38
|
+
}
|
|
39
|
+
for (const meta of changed) {
|
|
40
|
+
const key = scope(meta, Boolean(meta.assignment));
|
|
41
|
+
let seen = visited.get(key);
|
|
42
|
+
if (!seen) { seen = new Set(); visited.set(key, seen); }
|
|
43
|
+
const graph = graphs.get(key), pending = [meta.id];
|
|
44
|
+
while (pending.length) {
|
|
45
|
+
const id = pending.pop()!;
|
|
46
|
+
if (seen.has(id)) continue;
|
|
47
|
+
seen.add(id); affected.add(id);
|
|
48
|
+
for (const neighbor of graph?.get(id) ?? []) if (!seen.has(neighbor)) pending.push(neighbor);
|
|
49
|
+
await checkpoint();
|
|
50
|
+
}
|
|
51
|
+
await checkpoint();
|
|
52
|
+
}
|
|
53
|
+
return affected;
|
|
54
|
+
}
|
|
@@ -2,8 +2,9 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { readdir, stat } from "node:fs/promises";
|
|
3
3
|
import { watch, statSync, type FSWatcher } from "node:fs";
|
|
4
4
|
import { dirname, join } from "node:path";
|
|
5
|
-
import { setImmediate as yieldTurn } from "node:timers/promises";
|
|
5
|
+
import { setImmediate as yieldTurn, setTimeout as delay } from "node:timers/promises";
|
|
6
6
|
import type { WorkScope } from "./read-model.ts";
|
|
7
|
+
import { workPage } from "./work-budget.ts";
|
|
7
8
|
// @ts-expect-error Generated canonical cursor and scope functions.
|
|
8
9
|
import { rowCursorKey, pageRows, sessionScopeKey } from "./domain/shared-log-utils.mjs";
|
|
9
10
|
// @ts-expect-error Generated canonical passive registry inspection.
|
|
@@ -25,6 +26,7 @@ export class BackgroundHistory {
|
|
|
25
26
|
private directory: string;
|
|
26
27
|
private source: () => any;
|
|
27
28
|
private project: (operations: any[]) => any[];
|
|
29
|
+
private directoryFor: (operation: any) => string;
|
|
28
30
|
private changed: () => void;
|
|
29
31
|
private pending?: Promise<void>;
|
|
30
32
|
private completed = 0;
|
|
@@ -37,29 +39,45 @@ export class BackgroundHistory {
|
|
|
37
39
|
private timer?: ReturnType<typeof setInterval>;
|
|
38
40
|
private changes = 0;
|
|
39
41
|
private observedVersion = "";
|
|
42
|
+
private imported = false;
|
|
43
|
+
private dirty = new Set<string>();
|
|
44
|
+
private applying: string[] = [];
|
|
45
|
+
private dirtyLegacy = new Set<string>();
|
|
46
|
+
private applyingLegacy: string[] = [];
|
|
47
|
+
private legacyOwed = true;
|
|
40
48
|
status: "ready" | "rebuilding" | "degraded" = "rebuilding";
|
|
49
|
+
get queryStatus() {
|
|
50
|
+
// A delivered hint is an outstanding observation obligation even before
|
|
51
|
+
// its scheduled refresh starts; page-local checks cannot verify off-page rows.
|
|
52
|
+
return this.status === "ready" && (this.dirty.size || this.dirtyLegacy.size || this.legacyOwed || !this.imported)
|
|
53
|
+
? "rebuilding" : this.status;
|
|
54
|
+
}
|
|
41
55
|
reason?: string;
|
|
42
|
-
readonly metrics = { inventories: 0, metadataReads: 0, projections: 0 };
|
|
56
|
+
readonly metrics = { inventories: 0, metadataReads: 0, projections: 0, operationReads: 0, operationQueries: 0, dependencyQueries: 0, inputStats: 0, incrementalBatches: 0 };
|
|
43
57
|
|
|
44
|
-
constructor(db: any, directory: string, source: () => any, project: (operations: any[]) => any[], changed: () => void) {
|
|
58
|
+
constructor(db: any, directory: string, source: () => any, project: (operations: any[]) => any[], changed: () => void, directoryFor = (_operation: any) => directory) {
|
|
45
59
|
this.db = db; this.directory = directory; this.source = source; this.project = project; this.changed = changed;
|
|
60
|
+
this.directoryFor = directoryFor;
|
|
46
61
|
db.exec(`CREATE TABLE background_history (key TEXT PRIMARY KEY, id TEXT, workspace TEXT, session TEXT,
|
|
47
|
-
known INTEGER, unreadable INTEGER, state TEXT, started REAL, payload TEXT, signature TEXT, failure TEXT, spawn_pid INTEGER, active INTEGER, context TEXT);
|
|
48
|
-
CREATE INDEX background_history_scope ON background_history(workspace, session, state, started DESC, id DESC);
|
|
49
|
-
CREATE INDEX background_history_process ON background_history(workspace, session, spawn_pid, state, started DESC, id DESC);
|
|
50
|
-
CREATE INDEX background_history_state ON background_history(state, started DESC, id DESC);
|
|
51
|
-
CREATE INDEX background_history_order ON background_history(started DESC, id DESC);
|
|
62
|
+
known INTEGER, unreadable INTEGER, state TEXT, started REAL, payload TEXT, signature TEXT, failure TEXT, spawn_pid INTEGER, active INTEGER, context TEXT, dismissed INTEGER);
|
|
63
|
+
CREATE INDEX background_history_scope ON background_history(dismissed, workspace, session, state, started DESC, id DESC);
|
|
64
|
+
CREATE INDEX background_history_process ON background_history(dismissed, workspace, session, spawn_pid, state, started DESC, id DESC);
|
|
65
|
+
CREATE INDEX background_history_state ON background_history(dismissed, state, started DESC, id DESC);
|
|
66
|
+
CREATE INDEX background_history_order ON background_history(dismissed, started DESC, id DESC);
|
|
52
67
|
CREATE TABLE background_history_revisions (workspace TEXT, session TEXT, state TEXT, content INTEGER, failure INTEGER,
|
|
53
68
|
PRIMARY KEY (workspace, session, state));`);
|
|
54
69
|
}
|
|
55
70
|
|
|
56
71
|
private sourceVersion() {
|
|
57
72
|
const db = this.source();
|
|
58
|
-
const roots = [tasksDir()
|
|
73
|
+
const roots = [tasksDir()].map(path => {
|
|
74
|
+
this.metrics.inputStats++;
|
|
59
75
|
try { const s = statSync(path, { bigint: true }); return `${s.dev}:${s.ino}:${s.mtimeNs}:${s.ctimeNs}`; }
|
|
60
76
|
catch (error) { if ((error as NodeJS.ErrnoException).code === "ENOENT") return "missing"; throw error; }
|
|
61
77
|
});
|
|
62
|
-
|
|
78
|
+
const journal = db?.prepare("SELECT 1 FROM sqlite_master WHERE name='assignment_change_source'").get();
|
|
79
|
+
return JSON.stringify([db ? journal ? db.prepare("SELECT generation FROM assignment_change_source").get()?.generation
|
|
80
|
+
: db.prepare("PRAGMA data_version").get().data_version : "absent", roots]);
|
|
63
81
|
}
|
|
64
82
|
|
|
65
83
|
private observeSources() {
|
|
@@ -67,7 +85,16 @@ export class BackgroundHistory {
|
|
|
67
85
|
if (this.watchers.has(path)) continue;
|
|
68
86
|
try {
|
|
69
87
|
const watcher = watch(path, { recursive: true }, (_event, file) => {
|
|
70
|
-
if (
|
|
88
|
+
if (this.closed) return;
|
|
89
|
+
const legacy = file && /^tasks[/\\]([A-Za-z0-9_-]+)[/\\](?:meta\.json|failures\.jsonl(?:\.observed)?)$/.exec(String(file));
|
|
90
|
+
if (path !== this.directory && legacy) { this.dirtyLegacy.add(legacy[1]!); this.invalidateOperation(""); return; }
|
|
91
|
+
const match = file && /^tasks[/\\]([^/\\]+)[/\\](?:result|lost|launch|claim|command|stop|cleanup)\.json$|^observed[/\\]([^/\\]+)\.json$/.exec(String(file));
|
|
92
|
+
if (path === this.directory && match) {
|
|
93
|
+
const op = this.source()?.prepare("SELECT operation_id FROM operations WHERE task_id=?").get(match[1] ?? match[2]);
|
|
94
|
+
if (op) this.invalidateOperation(op.operation_id);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (!file || /(?:meta|result|lost|launch|claim)\.json$|failures\.jsonl(?:\.observed)?$|^observed[/\\].*\.json$/.test(String(file))) this.invalidateLegacy();
|
|
71
98
|
});
|
|
72
99
|
watcher.on("error", () => { this.watchers.delete(path); watcher.close(); this.status = "degraded"; this.reason = "Background history watcher failed; reconciling source signatures"; this.invalidate(); });
|
|
73
100
|
this.watchers.set(path, watcher);
|
|
@@ -76,29 +103,70 @@ export class BackgroundHistory {
|
|
|
76
103
|
}
|
|
77
104
|
|
|
78
105
|
invalidate() {
|
|
79
|
-
this.completed = 0; this.generation++;
|
|
106
|
+
this.completed = 0; this.generation++; this.legacyOwed = true;
|
|
107
|
+
this.imported = false;
|
|
80
108
|
if (!this.activated || this.closed || this.scheduled) return;
|
|
81
109
|
this.scheduled = true;
|
|
82
110
|
setImmediate(() => { this.scheduled = false; if (!this.closed && !this.pending) this.startRefresh(); });
|
|
83
111
|
}
|
|
84
112
|
|
|
113
|
+
invalidateOperation(id: string) {
|
|
114
|
+
if (!this.activated || this.closed) return;
|
|
115
|
+
this.dirty.add(id);
|
|
116
|
+
if (!this.scheduled) { this.scheduled = true; setImmediate(() => { this.scheduled = false; if (!this.closed && !this.pending) this.startRefresh(); }); }
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private operationInput(op: any) {
|
|
120
|
+
const waits = this.source().prepare(`SELECT w.* FROM waits w JOIN wait_dependencies d ON w.wait_id = d.wait_id AND w.generation = d.generation
|
|
121
|
+
WHERE d.operation_id = ? ORDER BY w.wait_id, w.generation`).all(op.operation_id);
|
|
122
|
+
this.metrics.dependencyQueries++;
|
|
123
|
+
const directory = this.directoryFor(op);
|
|
124
|
+
const context = currentIdentity(join(directory, "observed", `${op.task_id}.json`));
|
|
125
|
+
const files = ["launch", "claim", "command", "result", "lost", "stop", "cleanup"]
|
|
126
|
+
.map(name => currentIdentity(join(directory, "tasks", op.task_id, `${name}.json`)));
|
|
127
|
+
this.metrics.inputStats += 8;
|
|
128
|
+
const active = op.phase === "running" ? this.project([op])[0] : undefined;
|
|
129
|
+
return { context, active, signature: digest([op, waits, context, files, active]) };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
repairOperation(op: any, id: string) {
|
|
133
|
+
if (!this.activated || !this.imported || this.closed) return;
|
|
134
|
+
const previous = this.db.prepare("SELECT signature FROM background_history WHERE key=?").get(`d:${id}`);
|
|
135
|
+
if (op?.owner_kind !== "parent-session" || op.observer_kind !== "local-supervisor") {
|
|
136
|
+
if (previous) this.invalidateOperation(id);
|
|
137
|
+
} else if (!previous || previous.signature !== this.operationInput(op).signature) this.invalidateOperation(id);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private invalidateLegacy() {
|
|
141
|
+
this.legacyOwed = true; this.completed = 0;
|
|
142
|
+
this.invalidateOperation("");
|
|
143
|
+
}
|
|
144
|
+
|
|
85
145
|
reconcile() {
|
|
86
146
|
if (!this.activated || this.closed) return;
|
|
87
147
|
const version = this.sourceVersion();
|
|
88
|
-
if (version !== this.observedVersion) { this.observedVersion = version; this.
|
|
148
|
+
if (version !== this.observedVersion) { this.observedVersion = version; this.invalidateLegacy(); }
|
|
89
149
|
}
|
|
90
150
|
|
|
91
151
|
private startRefresh(version?: string) {
|
|
152
|
+
if (this.source()?.observationActive) return;
|
|
92
153
|
if (this.closed || this.pending) return;
|
|
93
154
|
const previous = this.status, changes = this.changes;
|
|
94
155
|
this.status = "rebuilding";
|
|
95
156
|
this.pending = Promise.resolve().then(() => this.refresh(version ?? this.sourceVersion())).catch(error => {
|
|
96
|
-
|
|
157
|
+
for (const id of this.applying) this.dirty.add(id);
|
|
158
|
+
for (const id of this.applyingLegacy) this.dirtyLegacy.add(id);
|
|
159
|
+
if (!this.closed) {
|
|
160
|
+
this.status = error === this.sourceChanged ? "rebuilding" : "degraded";
|
|
161
|
+
this.reason = error === this.sourceChanged ? undefined : String(error);
|
|
162
|
+
}
|
|
97
163
|
}).finally(() => {
|
|
164
|
+
this.applying = [];
|
|
165
|
+
this.applyingLegacy = [];
|
|
98
166
|
this.pending = undefined;
|
|
99
167
|
if (this.closed) return;
|
|
100
168
|
if (changes !== this.changes || previous !== this.status) this.changed();
|
|
101
|
-
if (this.status === "rebuilding") this.
|
|
169
|
+
if (this.status !== "degraded" && (this.status === "rebuilding" || this.dirty.size || this.dirtyLegacy.size)) this.invalidateOperation("");
|
|
102
170
|
});
|
|
103
171
|
}
|
|
104
172
|
|
|
@@ -106,7 +174,7 @@ export class BackgroundHistory {
|
|
|
106
174
|
this.observeSources();
|
|
107
175
|
if (!this.activated) {
|
|
108
176
|
this.activated = true;
|
|
109
|
-
this.timer = setInterval(() => this.startRefresh(), 30000); this.timer.unref();
|
|
177
|
+
this.timer = setInterval(() => { this.legacyOwed = true; this.startRefresh(); }, 30000); this.timer.unref();
|
|
110
178
|
}
|
|
111
179
|
const version = this.sourceVersion();
|
|
112
180
|
this.observedVersion = version;
|
|
@@ -115,10 +183,15 @@ export class BackgroundHistory {
|
|
|
115
183
|
this.startRefresh(version);
|
|
116
184
|
}
|
|
117
185
|
const resource = `list:${sessionScopeKey({ all: scope.backgroundAll, origin: { cwd: scope.cwd, sessionId: scope.sessionId }, processId: scope.processId })}:${[...(scope.statuses ?? [])].sort().join(",")}`;
|
|
118
|
-
const
|
|
119
|
-
if (!scope.backgroundAll)
|
|
120
|
-
|
|
121
|
-
|
|
186
|
+
const ownerClauses: string[] = [], ownerArgs: any[] = [];
|
|
187
|
+
if (!scope.backgroundAll) {
|
|
188
|
+
ownerClauses.push("workspace = ? AND session = ?");
|
|
189
|
+
ownerArgs.push(scope.cwd, scope.sessionId ?? "");
|
|
190
|
+
if (!scope.sessionId) { ownerClauses.push("spawn_pid = ?"); ownerArgs.push(scope.processId ?? -1); }
|
|
191
|
+
}
|
|
192
|
+
const ownerWhere = ownerClauses.join(" AND ");
|
|
193
|
+
const clauses = ["unreadable = 0", "dismissed = 0"], args = [...ownerArgs];
|
|
194
|
+
if (ownerWhere) clauses.push("known = 1", ownerWhere);
|
|
122
195
|
if (scope.statuses?.length) { clauses.push(`(state IN (${scope.statuses.map(() => "?").join(",")})${scope.statuses.includes("running") ? " OR active = 1" : ""})`); args.push(...scope.statuses); }
|
|
123
196
|
if (scope.active !== undefined) { clauses.push("active = ?"); args.push(scope.active ? 1 : 0); }
|
|
124
197
|
const where = clauses.join(" AND ");
|
|
@@ -130,8 +203,14 @@ export class BackgroundHistory {
|
|
|
130
203
|
const selected = this.db.prepare(`SELECT key, id, payload, context FROM background_history WHERE ${where}${after} ORDER BY started DESC, id DESC LIMIT ?`)
|
|
131
204
|
.all(...args, ...anchorArgs, (scope.limit ?? 10) + 1);
|
|
132
205
|
for (const row of selected) {
|
|
133
|
-
|
|
134
|
-
|
|
206
|
+
if (row.key.startsWith("d:")) this.metrics.operationQueries++;
|
|
207
|
+
const op = row.key.startsWith("d:") ? this.source()?.prepare("SELECT * FROM operations WHERE operation_id=?").get(row.key.slice(2)) : undefined;
|
|
208
|
+
const path = row.key.startsWith("d:") ? join(op ? this.directoryFor(op) : this.directory, "observed", `${row.id}.json`) : join(tasksDir(), row.id, "meta.json");
|
|
209
|
+
this.metrics.inputStats++;
|
|
210
|
+
if (row.context !== currentIdentity(path)) {
|
|
211
|
+
if (row.key.startsWith("d:")) this.invalidateOperation(row.key.slice(2)); else this.invalidateLegacy();
|
|
212
|
+
this.status = "rebuilding";
|
|
213
|
+
}
|
|
135
214
|
}
|
|
136
215
|
const records = selected.map((row: any) => JSON.parse(row.payload));
|
|
137
216
|
const page = pageRows(records, { resource, cursor: scope.cursor, limit: scope.limit ?? 10, maxBytes: Number.MAX_SAFE_INTEGER,
|
|
@@ -140,18 +219,36 @@ export class BackgroundHistory {
|
|
|
140
219
|
const revisions = this.db.prepare(`SELECT sum(content) AS content, sum(failure) AS failure FROM background_history_revisions
|
|
141
220
|
WHERE workspace = ? AND session = ? AND state IN (${revisionStates.map(() => "?").join(",")})`)
|
|
142
221
|
.get(scope.backgroundAll ? "" : scope.cwd, scope.backgroundAll ? "" : scope.sessionId || `process:${scope.processId ?? -1}`, ...revisionStates);
|
|
143
|
-
const
|
|
222
|
+
const diagnosticScope = ownerWhere ? ` AND (known = 0 OR (${ownerWhere}))` : "";
|
|
223
|
+
const diagnostics = this.db.prepare(`SELECT sum(unreadable) AS unreadable, sum(known = 0 AND unreadable = 0) AS unknown
|
|
224
|
+
FROM background_history WHERE dismissed = 0${diagnosticScope}`).get(...ownerArgs);
|
|
144
225
|
return { records: records.slice(0, scope.limit ?? 10).map((meta: any) => ({ id: meta.id, found: true, readable: true, meta })),
|
|
145
226
|
page: { total: Number(aggregate.n), before, nextCursor: page.nextCursor, resource,
|
|
146
227
|
contentRevision: digest([aggregate.n, revisions.content, diagnostics.unreadable, diagnostics.unknown]), failureRevision: digest(revisions.failure),
|
|
147
228
|
unreadable: Number(diagnostics.unreadable ?? 0), unknown: scope.backgroundAll ? 0 : Number(diagnostics.unknown ?? 0) } };
|
|
148
229
|
}
|
|
149
230
|
|
|
231
|
+
private readonly sourceChanged = new Error("Background history source replaced during refresh");
|
|
150
232
|
private async refresh(version: string) {
|
|
151
233
|
const generation = this.generation;
|
|
152
|
-
|
|
234
|
+
const ownerBusy = () => {
|
|
235
|
+
if (generation !== this.generation) throw this.sourceChanged;
|
|
236
|
+
return !this.closed && this.source()?.observationActive;
|
|
237
|
+
};
|
|
238
|
+
const baseline = !this.imported;
|
|
239
|
+
const legacy = this.legacyOwed || baseline;
|
|
240
|
+
this.legacyOwed = false;
|
|
241
|
+
if (baseline || legacy) this.metrics.inventories++;
|
|
242
|
+
else this.metrics.incrementalBatches++;
|
|
243
|
+
const dirty = workPage(this.dirty, 128).filter(Boolean);
|
|
244
|
+
this.applying = dirty;
|
|
245
|
+
const dirtyLegacy = workPage(this.dirtyLegacy, 128);
|
|
246
|
+
this.applyingLegacy = dirtyLegacy;
|
|
247
|
+
for (const id of dirtyLegacy) this.dirtyLegacy.delete(id);
|
|
248
|
+
for (const id of dirty) this.dirty.delete(id);
|
|
249
|
+
this.dirty.delete("");
|
|
153
250
|
const seen = new Set<string>();
|
|
154
|
-
const upsert = this.db.prepare(`INSERT OR REPLACE INTO background_history VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`);
|
|
251
|
+
const upsert = this.db.prepare(`INSERT OR REPLACE INTO background_history VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`);
|
|
155
252
|
const previous = this.db.prepare("SELECT * FROM background_history WHERE key = ?");
|
|
156
253
|
const bump = (row: any, content: boolean, failure: boolean) => {
|
|
157
254
|
const session = row.session || `process:${row.spawn_pid ?? -1}`;
|
|
@@ -174,7 +271,7 @@ export class BackgroundHistory {
|
|
|
174
271
|
const known = origin && typeof origin.cwd === "string";
|
|
175
272
|
upsert.run(key, meta?.id ?? key, origin?.cwd ?? "", origin?.sessionId ?? "", known ? 1 : 0, unreadable ? 1 : 0,
|
|
176
273
|
meta?.status ?? "", meta?.startedAt ?? 0, JSON.stringify(meta ?? null), signature, failure, meta?.spawnPid ?? null,
|
|
177
|
-
meta?.durable ? Number(meta.active) : Number(meta?.status === "running"), context);
|
|
274
|
+
meta?.durable ? Number(meta.active) : Number(meta?.status === "running"), context, Number(meta?.dismissedAt !== undefined));
|
|
178
275
|
this.changes++;
|
|
179
276
|
if (old) bump(old, true, old.failure !== failure);
|
|
180
277
|
bump(previous.get(key), true, old?.failure !== failure);
|
|
@@ -182,43 +279,46 @@ export class BackgroundHistory {
|
|
|
182
279
|
const source = this.source();
|
|
183
280
|
let last = "";
|
|
184
281
|
if (source) for (;;) {
|
|
282
|
+
while (ownerBusy()) await delay(10);
|
|
185
283
|
if (this.closed) return;
|
|
186
|
-
|
|
187
|
-
|
|
284
|
+
this.metrics.operationQueries += baseline ? 1 : dirty.length;
|
|
285
|
+
const operations = baseline ? source.prepare(`SELECT * FROM operations WHERE owner_kind = 'parent-session' AND observer_kind = 'local-supervisor'
|
|
286
|
+
AND operation_id > ? ORDER BY operation_id LIMIT 128`).all(last)
|
|
287
|
+
: dirty.map(id => source.prepare("SELECT * FROM operations WHERE operation_id=? AND owner_kind='parent-session' AND observer_kind='local-supervisor'").get(id)).filter(Boolean);
|
|
288
|
+
this.metrics.operationReads += operations.length;
|
|
188
289
|
if (!operations.length) break;
|
|
189
290
|
for (const op of operations) {
|
|
190
291
|
if (this.closed) return;
|
|
191
292
|
const key = `d:${op.operation_id}`;
|
|
192
|
-
const
|
|
193
|
-
WHERE d.operation_id = ? ORDER BY w.wait_id, w.generation`).all(op.operation_id);
|
|
194
|
-
const context = await identity(join(this.directory, "observed", `${op.task_id}.json`));
|
|
195
|
-
const signature = digest([op, waits, context,
|
|
196
|
-
await identity(join(this.directory, "tasks", op.task_id, "result.json")), await identity(join(this.directory, "tasks", op.task_id, "lost.json")),
|
|
197
|
-
// Active runner/wait facts come from the current shared projection.
|
|
198
|
-
op.phase === "running" ? this.project([op]) : null]);
|
|
293
|
+
const { context, active, signature } = this.operationInput(op);
|
|
199
294
|
let meta;
|
|
200
295
|
if (previous.get(key)?.signature !== signature) {
|
|
201
296
|
this.metrics.projections++;
|
|
202
|
-
meta = this.project([op])[0];
|
|
203
|
-
|
|
204
|
-
|
|
297
|
+
meta = active ?? this.project([op])[0];
|
|
298
|
+
// Retain the source signature even when dismissal hides the row:
|
|
299
|
+
// absence would make every exact repair demand another history build.
|
|
300
|
+
meta = { ...meta, callbackOrigin: { cwd: op.owner_workspace, sessionId: op.owner_session_id, branchId: op.owner_branch_id ?? null }, logPath: meta.logPaths?.stdout ?? "" };
|
|
205
301
|
}
|
|
206
|
-
if (meta) save(key, meta, signature, "",
|
|
302
|
+
if (meta) save(key, meta, signature, "", meta.unreadable === true, context);
|
|
207
303
|
else if (previous.get(key)?.signature === signature) seen.add(key);
|
|
208
304
|
}
|
|
209
305
|
last = operations.at(-1).operation_id;
|
|
210
306
|
await yieldTurn();
|
|
307
|
+
if (!baseline) break;
|
|
211
308
|
}
|
|
212
|
-
let ids: string[] =
|
|
213
|
-
try { ids = await readdir(tasksDir()); }
|
|
309
|
+
let ids: string[] = dirtyLegacy;
|
|
310
|
+
try { if (legacy) ids = await readdir(tasksDir()); }
|
|
214
311
|
catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error; }
|
|
215
312
|
let batch = 0;
|
|
216
313
|
for (const id of ids) {
|
|
217
314
|
if (this.closed) return;
|
|
218
315
|
if (!/^[A-Za-z0-9_-]+$/.test(id)) continue;
|
|
219
316
|
const key = `l:${id}`, path = join(tasksDir(), id);
|
|
317
|
+
this.metrics.inputStats += 3;
|
|
220
318
|
const signature = await identity(join(path, "meta.json"));
|
|
221
319
|
const failure = digest([await identity(join(path, "failures.jsonl")), await identity(join(path, "failures.jsonl.observed"))]);
|
|
320
|
+
while (ownerBusy()) await delay(10);
|
|
321
|
+
if (this.closed) return;
|
|
222
322
|
if (previous.get(key)?.signature === signature) { seen.add(key); updateFailure(key, failure); }
|
|
223
323
|
else {
|
|
224
324
|
this.metrics.metadataReads++;
|
|
@@ -227,13 +327,19 @@ export class BackgroundHistory {
|
|
|
227
327
|
}
|
|
228
328
|
if (++batch % 128 === 0) await yieldTurn();
|
|
229
329
|
}
|
|
330
|
+
while (ownerBusy()) await delay(10);
|
|
230
331
|
if (this.closed) return;
|
|
231
|
-
|
|
232
|
-
|
|
332
|
+
const removals = baseline ? this.db.prepare("SELECT key FROM background_history").all()
|
|
333
|
+
: [...(legacy ? this.db.prepare("SELECT key FROM background_history WHERE key LIKE 'l:%'").all() : []),
|
|
334
|
+
...dirty.map(id => ({ key: `d:${id}` })), ...dirtyLegacy.map(id => ({ key: `l:${id}` }))];
|
|
335
|
+
for (const row of removals) {
|
|
336
|
+
const affected = row.key.startsWith("d:") ? baseline || dirty.includes(row.key.slice(2)) : legacy || dirtyLegacy.includes(row.key.slice(2));
|
|
337
|
+
if (affected && !seen.has(row.key) && previous.get(row.key)) { this.changes++; bump(previous.get(row.key), true, true); this.db.prepare("DELETE FROM background_history WHERE key = ?").run(row.key); }
|
|
233
338
|
}
|
|
234
339
|
this.version = version;
|
|
235
|
-
this.
|
|
236
|
-
this.
|
|
340
|
+
this.imported = generation === this.generation;
|
|
341
|
+
this.completed = Date.now();
|
|
342
|
+
this.status = this.dirty.size || this.dirtyLegacy.size || !this.imported ? "rebuilding" : "ready";
|
|
237
343
|
this.reason = undefined;
|
|
238
344
|
}
|
|
239
345
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Intersect captured execution authority with the current mandatory Background profile. */
|
|
2
|
+
export function effectiveBackgroundPolicy(captured: any, fresh: any, workspace: string): any {
|
|
3
|
+
if (!captured && !fresh.enabled)
|
|
4
|
+
return undefined;
|
|
5
|
+
if (captured && ['failed', 'unavailable'].includes(captured.state))
|
|
6
|
+
return captured;
|
|
7
|
+
const old = captured?.permissions;
|
|
8
|
+
const finish = (profile: any) => ({ ...captured, state: profile.enabled ? 'enabled' : captured?.state ?? 'inactive',
|
|
9
|
+
writableRoot: captured?.writableRoot ?? workspace, denyWrite: captured?.denyWrite ?? [], permissions: profile,
|
|
10
|
+
reason: 'Captured Background authority intersected with current mandatory profile' });
|
|
11
|
+
if (!fresh.enabled) return finish(old?.enabled ? { ...old } : { ...fresh });
|
|
12
|
+
if (!old?.enabled) return finish({ ...fresh });
|
|
13
|
+
const access = ['off', 'read', 'write', 'read-write'];
|
|
14
|
+
const profile = { ...fresh };
|
|
15
|
+
for (const key of ['projectFiles', 'outsideProject', 'storedCredentials']) {
|
|
16
|
+
if (!access.includes(old[key]) || !access.includes(fresh[key]))
|
|
17
|
+
throw new Error('permission-unavailable: invalid Background profile');
|
|
18
|
+
profile[key] = access[access.indexOf(old[key]) & access.indexOf(fresh[key])];
|
|
19
|
+
}
|
|
20
|
+
for (const key of ['commands', 'network'])
|
|
21
|
+
profile[key] = Boolean(old[key] && fresh[key]);
|
|
22
|
+
profile.shell = old.shell !== false && fresh.shell !== false;
|
|
23
|
+
profile.processAccess = old.processAccess === 'read' && fresh.processAccess === 'read' ? 'read' : 'off';
|
|
24
|
+
const limits = [old.commandTimeoutSeconds, fresh.commandTimeoutSeconds].filter(n => typeof n === 'number' && n > 0);
|
|
25
|
+
profile.commandTimeoutSeconds = limits.length ? Math.min(...limits) : null;
|
|
26
|
+
return finish(profile);
|
|
27
|
+
}
|