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,4 @@
|
|
|
1
|
+
// Fixed labels only: the watchdog log must not include request or source data.
|
|
2
|
+
export const executionPhases = ["starting", "idle", "snapshot", "request", "publish"] as const;
|
|
3
|
+
export const inventoryPhases = ["idle", "background", "metadata", "coordinator", "log-stats", "projection", "verify", "commit"] as const;
|
|
4
|
+
export type InventoryPhase = typeof inventoryPhases[number];
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
2
|
+
import { existsSync, watch, type FSWatcher } from "node:fs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { acquireMutationStore } from "./mutation-store.ts";
|
|
5
|
+
import { ENTITY_BUDGET } from "./work-budget.ts";
|
|
5
6
|
// @ts-expect-error Generated canonical supervisor.
|
|
6
7
|
import { createLocalSupervisor } from "./domain/background/supervisor/supervisor.mjs";
|
|
8
|
+
// @ts-expect-error Generated canonical durable stop records.
|
|
9
|
+
import { readStopRequest } from "./domain/background/supervisor/store.mjs";
|
|
10
|
+
// @ts-expect-error Generated canonical process identity checks.
|
|
11
|
+
import { processGroupAlive } from "./domain/background/supervisor/identity.mjs";
|
|
7
12
|
// @ts-expect-error Generated canonical terminal evidence rules.
|
|
8
13
|
import { supervisorTerminalPublication } from "./domain/background/terminal-publication.mjs";
|
|
9
14
|
|
|
@@ -16,48 +21,215 @@ export function hasResultSupervision(root: string): boolean {
|
|
|
16
21
|
finally { db.close(); }
|
|
17
22
|
}
|
|
18
23
|
|
|
19
|
-
/**
|
|
24
|
+
/** Observes managed task results and stops exact tasks of terminal assignments. */
|
|
20
25
|
export class RuntimeResultSupervision {
|
|
21
26
|
private store: any;
|
|
27
|
+
private budget: ReturnType<typeof acquireMutationStore>["budget"];
|
|
22
28
|
private releaseStore: () => void;
|
|
23
|
-
private timer
|
|
29
|
+
private timer?: NodeJS.Timeout;
|
|
30
|
+
private watcher?: FSWatcher;
|
|
31
|
+
private taskWatchers = new Map<string, FSWatcher>();
|
|
32
|
+
private active = new Map<string, { grant: any; due: number; reason?: any; failure?: string; uncertainSince?: number }>();
|
|
33
|
+
private dirty = new Set<string>();
|
|
34
|
+
private position?: { generation: string; seq: number };
|
|
35
|
+
private scheduled = false;
|
|
36
|
+
private closed = false;
|
|
37
|
+
readonly metrics = { restores: 0, feedPages: 0, inspections: 0, publications: 0, deadlineLatenessMs: 0, passes: 0 };
|
|
24
38
|
readonly hostId: string;
|
|
25
39
|
readonly epoch: string;
|
|
26
|
-
|
|
27
|
-
|
|
40
|
+
private observationReason?: string;
|
|
41
|
+
private assignmentCleanup?: Promise<void>;
|
|
42
|
+
private assignmentCleanupCursor?: string;
|
|
43
|
+
private assignmentCleanupReason?: string;
|
|
44
|
+
get reason() { return this.assignmentCleanupReason ?? this.observationReason; }
|
|
45
|
+
private verificationMs: number;
|
|
46
|
+
constructor(root: string, epoch: string, verificationMs = 30_000) {
|
|
47
|
+
this.verificationMs = verificationMs;
|
|
28
48
|
this.epoch = epoch;
|
|
29
49
|
this.hostId = `server:${epoch}`;
|
|
30
50
|
const lease = acquireMutationStore(root);
|
|
31
51
|
this.store = lease.store;
|
|
52
|
+
this.budget = lease.budget;
|
|
32
53
|
this.releaseStore = lease.release;
|
|
54
|
+
this.watcher = watch(root, (_event, file) => {
|
|
55
|
+
if (!file || String(file).startsWith("operation-coordinator.sqlite")) this.schedule();
|
|
56
|
+
});
|
|
57
|
+
this.watcher.on("error", () => { this.watcher?.close(); this.watcher = undefined; });
|
|
33
58
|
this.reconcile();
|
|
34
|
-
this.timer = setInterval(() => this.reconcile(), 250);
|
|
35
|
-
this.timer.unref();
|
|
36
59
|
}
|
|
60
|
+
private schedule() {
|
|
61
|
+
if (this.closed || this.scheduled) return;
|
|
62
|
+
this.scheduled = true;
|
|
63
|
+
setImmediate(() => { this.scheduled = false; if (!this.closed) this.reconcile(); });
|
|
64
|
+
}
|
|
65
|
+
private retain(grant: any) {
|
|
66
|
+
const previous = this.active.get(grant.operationId);
|
|
67
|
+
if (previous && JSON.stringify(previous.grant) === JSON.stringify(grant)) return;
|
|
68
|
+
const now = Date.now();
|
|
69
|
+
this.active.set(grant.operationId, { grant, due: now, reason: { kind: "verification", id: grant.operationId,
|
|
70
|
+
operationId: grant.operationId, owner: grant.owner, lastProgressAt: now, nextDeadline: now + this.verificationMs,
|
|
71
|
+
recovery: "restore-captured-result-authority" } });
|
|
72
|
+
this.dirty.add(grant.operationId);
|
|
73
|
+
this.taskWatchers.get(grant.operationId)?.close();
|
|
74
|
+
this.taskWatchers.delete(grant.operationId);
|
|
75
|
+
try {
|
|
76
|
+
const watcher = watch(join(grant.directory, "tasks", this.store.getOperation(grant.operationId).taskId), () => {
|
|
77
|
+
if (this.active.has(grant.operationId)) { this.dirty.add(grant.operationId); this.schedule(); }
|
|
78
|
+
});
|
|
79
|
+
watcher.on("error", () => { watcher.close(); this.taskWatchers.delete(grant.operationId); });
|
|
80
|
+
this.taskWatchers.set(grant.operationId, watcher);
|
|
81
|
+
} catch { /* Missing task evidence is checked at its bounded deadline. */ }
|
|
82
|
+
}
|
|
83
|
+
private forget(id: string) {
|
|
84
|
+
this.active.delete(id); this.dirty.delete(id);
|
|
85
|
+
this.taskWatchers.get(id)?.close(); this.taskWatchers.delete(id);
|
|
86
|
+
}
|
|
87
|
+
livenessReasons() { return [...this.active.values()].flatMap(entry => entry.reason ? [entry.reason] : []); }
|
|
88
|
+
manages(operationId: string) { return this.active.has(operationId); }
|
|
37
89
|
reconcile() {
|
|
90
|
+
if (this.closed) return;
|
|
91
|
+
const release = this.budget.enter("control");
|
|
92
|
+
if (!release) {
|
|
93
|
+
if (this.timer) clearTimeout(this.timer);
|
|
94
|
+
this.timer = setTimeout(() => this.reconcile(), 1000); this.timer.unref(); return;
|
|
95
|
+
}
|
|
96
|
+
this.metrics.passes++;
|
|
38
97
|
try {
|
|
39
|
-
this.
|
|
40
|
-
|
|
98
|
+
this.observationReason = undefined;
|
|
99
|
+
try {
|
|
100
|
+
const page = this.store.resultSupervisionChanges(this.position);
|
|
101
|
+
this.metrics.feedPages++;
|
|
102
|
+
if (page.reset) {
|
|
103
|
+
this.metrics.restores++;
|
|
104
|
+
const grants = this.store.resultSupervisions(true);
|
|
105
|
+
const ids = new Set(grants.map((grant: any) => grant.operationId));
|
|
106
|
+
for (const id of this.active.keys()) if (!ids.has(id)) this.forget(id);
|
|
107
|
+
for (const grant of grants) this.retain(grant);
|
|
108
|
+
} else for (const id of page.operationIds) {
|
|
109
|
+
const grant = this.store.resultSupervision(id);
|
|
110
|
+
const operation = this.store.getOperation(id);
|
|
111
|
+
if (grant && operation?.phase === "running" && !operation.terminalRevision) { this.retain(grant); this.dirty.add(id); }
|
|
112
|
+
else this.forget(id);
|
|
113
|
+
}
|
|
114
|
+
// Restart always restores authority; this in-memory position never authorizes work.
|
|
115
|
+
this.position = { generation: page.generation, seq: page.seq };
|
|
116
|
+
if (page.more) this.schedule();
|
|
117
|
+
} catch (error) {
|
|
118
|
+
// Feed recovery must not suppress deadlines for already captured work.
|
|
119
|
+
this.observationReason = String(error);
|
|
120
|
+
}
|
|
121
|
+
const now = Date.now();
|
|
122
|
+
for (const [id, entry] of this.active) if (entry.due <= now) this.dirty.add(id);
|
|
123
|
+
for (const id of [...this.dirty].slice(0, ENTITY_BUDGET)) {
|
|
124
|
+
this.dirty.delete(id);
|
|
125
|
+
const entry = this.active.get(id)!;
|
|
126
|
+
let grant = entry.grant;
|
|
127
|
+
this.metrics.deadlineLatenessMs = Math.max(this.metrics.deadlineLatenessMs, Math.max(0, now - entry.due));
|
|
128
|
+
entry.due = now + 1000;
|
|
41
129
|
const operation = this.store.getOperation(grant.operationId);
|
|
42
|
-
if (!operation || operation.terminalRevision > 0) continue;
|
|
130
|
+
if (!operation || operation.terminalRevision > 0) { this.forget(id); continue; }
|
|
131
|
+
entry.reason = undefined;
|
|
132
|
+
const uncertain = (reason: string) => {
|
|
133
|
+
this.observationReason = reason;
|
|
134
|
+
entry.failure = reason;
|
|
135
|
+
entry.uncertainSince ??= now;
|
|
136
|
+
if (now < entry.uncertainSince + this.verificationMs) entry.reason = {
|
|
137
|
+
kind: "verification", id: operation.taskId, operationId: operation.operationId,
|
|
138
|
+
owner: operation.owner, lastProgressAt: entry.uncertainSince,
|
|
139
|
+
nextDeadline: entry.uncertainSince + this.verificationMs, recovery: reason,
|
|
140
|
+
};
|
|
141
|
+
else entry.due = Infinity;
|
|
142
|
+
if (entry.reason) entry.due = Math.min(entry.due, entry.uncertainSince + this.verificationMs);
|
|
143
|
+
};
|
|
144
|
+
try {
|
|
43
145
|
if (grant.capability?.adapter !== "background-results-v1" || !grant.capability.captured || !grant.capability.current) {
|
|
44
|
-
|
|
146
|
+
uncertain("permission-unavailable: captured Background adapter or permission source unavailable");
|
|
45
147
|
continue;
|
|
46
148
|
}
|
|
47
149
|
if (grant.epoch !== this.epoch) {
|
|
48
150
|
// Daemon startup has already proved the preceding root owner exited.
|
|
49
151
|
grant = { ...grant, hostId: this.hostId, epoch: this.epoch };
|
|
50
152
|
this.store.recoverResultSupervision(grant);
|
|
153
|
+
entry.grant = grant;
|
|
51
154
|
}
|
|
155
|
+
this.metrics.inspections++;
|
|
52
156
|
const inspection = createLocalSupervisor({ directory: grant.directory }).inspect(operation.taskId);
|
|
53
157
|
if (!inspection || inspection.token !== grant.launchToken) {
|
|
54
|
-
|
|
158
|
+
uncertain("reconciling: exact runner evidence unavailable; no replacement command is permitted");
|
|
55
159
|
continue;
|
|
56
160
|
}
|
|
57
|
-
if (inspection.terminal
|
|
58
|
-
|
|
161
|
+
if (!inspection.terminal && (inspection.fenceBusy || !inspection.claim?.pidStartTime)) {
|
|
162
|
+
uncertain("reconciling: runner start identity or state fence is unverified; no takeover is permitted");
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (inspection.terminal) {
|
|
166
|
+
this.store.publishSupervisedResult({ operationId: operation.operationId,
|
|
167
|
+
epoch: this.epoch, publication: supervisorTerminalPublication(operation, inspection) });
|
|
168
|
+
this.metrics.publications++; this.forget(id);
|
|
169
|
+
} else {
|
|
170
|
+
entry.failure = undefined;
|
|
171
|
+
entry.uncertainSince = undefined;
|
|
172
|
+
entry.reason = { kind: "runner", id: operation.taskId, operationId: operation.operationId,
|
|
173
|
+
launchToken: grant.launchToken, owner: operation.owner, directory: grant.directory,
|
|
174
|
+
lastProgressAt: inspection.command?.startedAt ?? inspection.claim?.claimedAt ?? inspection.launch.createdAt,
|
|
175
|
+
nextDeadline: entry.due, recovery: "observe-existing-runner" };
|
|
176
|
+
}
|
|
177
|
+
} catch (error) { uncertain(String(error)); }
|
|
59
178
|
}
|
|
60
|
-
|
|
179
|
+
this.observationReason ??= [...this.active.values()].find(entry => entry.failure)?.failure;
|
|
180
|
+
try { this.reconcileAssignmentCleanup(); }
|
|
181
|
+
catch (error) { this.assignmentCleanupReason = `Assignment cleanup: ${String(error)}`; }
|
|
182
|
+
} catch (error) { this.observationReason = String(error); }
|
|
183
|
+
finally {
|
|
184
|
+
release();
|
|
185
|
+
if (this.timer) clearTimeout(this.timer);
|
|
186
|
+
if (this.dirty.size) this.schedule();
|
|
187
|
+
// A cheap journal page repairs missed database hints; task inspections are
|
|
188
|
+
// charged only to exact dirty identities or their liveness deadline.
|
|
189
|
+
const next = [...this.active.values()].reduce((deadline, entry) => Math.min(deadline, entry.due), Date.now() + 1000);
|
|
190
|
+
this.timer = setTimeout(() => this.reconcile(), Math.max(1, next - Date.now()));
|
|
191
|
+
this.timer.unref();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
private reconcileAssignmentCleanup() {
|
|
195
|
+
if (this.assignmentCleanup) return;
|
|
196
|
+
const [operation] = this.store.listAssignmentCleanupOperations(1, this.assignmentCleanupCursor);
|
|
197
|
+
this.assignmentCleanupCursor = operation?.operationId;
|
|
198
|
+
if (!operation) {
|
|
199
|
+
if (!this.store.listAssignmentCleanupOperations(1).length) this.assignmentCleanupReason = undefined;
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const grant = this.store.resultSupervision(operation.operationId);
|
|
203
|
+
if (!grant || (operation.terminalRevision === 0 && grant.epoch !== this.epoch) || grant.launchToken !== operation.launchToken || grant.hostId !== operation.supervision?.hostId ||
|
|
204
|
+
grant.capability?.adapter !== "background-results-v1" || !grant.capability.captured || !grant.capability.current) {
|
|
205
|
+
this.assignmentCleanupReason = `Assignment cleanup for ${operation.taskId}: exact supervision authority unavailable`;
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const supervisor = createLocalSupervisor({ directory: grant.directory });
|
|
209
|
+
const inspection = supervisor.snapshot(operation.taskId);
|
|
210
|
+
const stop = readStopRequest(grant.directory, operation.taskId);
|
|
211
|
+
if (inspection?.token !== operation.launchToken || (stop && stop.token !== operation.launchToken)) {
|
|
212
|
+
this.assignmentCleanupReason = `Assignment cleanup for ${operation.taskId}: exact launch evidence unavailable`;
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
this.assignmentCleanupReason = `Assignment cleanup for ${operation.taskId}: waiting for supervisor evidence`;
|
|
216
|
+
if (inspection.terminal) {
|
|
217
|
+
if (inspection.status !== "lost" && inspection.result?.groupCleanup !== "unproven") return;
|
|
218
|
+
const pgid = inspection.command?.pgid ?? inspection.command?.pid;
|
|
219
|
+
if (inspection.cleanup?.groupEmpty === true || (pgid && !processGroupAlive(pgid))) {
|
|
220
|
+
this.store.verifyAssignmentCleanup(operation.operationId, operation.launchToken, operation.terminalRevision);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
this.assignmentCleanupReason = `Assignment cleanup for ${operation.taskId}: process group exit unverified`;
|
|
224
|
+
if (!pgid) return;
|
|
225
|
+
}
|
|
226
|
+
this.assignmentCleanup = supervisor.stop(operation.taskId, { token: operation.launchToken, reason: "owning assignment ended" })
|
|
227
|
+
.catch((error: unknown) => { this.assignmentCleanupReason = `Assignment cleanup for ${operation.taskId}: ${String(error)}`; })
|
|
228
|
+
.finally(() => { this.assignmentCleanup = undefined; });
|
|
229
|
+
}
|
|
230
|
+
close() {
|
|
231
|
+
this.closed = true; if (this.timer) clearTimeout(this.timer); this.watcher?.close();
|
|
232
|
+
for (const watcher of this.taskWatchers.values()) watcher.close();
|
|
233
|
+
this.taskWatchers.clear(); this.releaseStore();
|
|
61
234
|
}
|
|
62
|
-
close() { clearInterval(this.timer); this.releaseStore(); }
|
|
63
235
|
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import { realpathSync, statSync, watch } from "node:fs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { basename, dirname, relative, sep } from "node:path";
|
|
5
|
+
import { isMainThread, type MessagePort } from "node:worker_threads";
|
|
6
|
+
|
|
7
|
+
export interface SourceWatcher extends EventEmitter { ready: Promise<void>; close(): void }
|
|
8
|
+
export type SourceWatch = (path: string, listener: (event: string, name?: string) => void, shareParent?: boolean) => SourceWatcher;
|
|
9
|
+
export type WatchBackend = (path: string, changed: (name?: string) => void, failed: (error: Error) => void, shareParent?: boolean) => () => Promise<void>;
|
|
10
|
+
|
|
11
|
+
type ChangeListener = (name?: string) => void;
|
|
12
|
+
interface DarwinRunStream {
|
|
13
|
+
listeners: Map<string, Set<ChangeListener>>;
|
|
14
|
+
stop: () => Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
const runStreams = new Map<string, DarwinRunStream>();
|
|
17
|
+
|
|
18
|
+
// FSEvents is recursive. Share a stream across sibling run directories while
|
|
19
|
+
// keeping individual subscriptions, event routing and generation cleanup.
|
|
20
|
+
function watchDarwinRun(parent: string, root: string, changed: ChangeListener): () => Promise<void> {
|
|
21
|
+
const stat = statSync(parent, { bigint: true });
|
|
22
|
+
const key = JSON.stringify([parent, String(stat.dev), String(stat.ino)]);
|
|
23
|
+
let stream = runStreams.get(key);
|
|
24
|
+
if (!stream) {
|
|
25
|
+
const listeners = new Map<string, Set<ChangeListener>>();
|
|
26
|
+
const native = createRequire(import.meta.url)("fsevents");
|
|
27
|
+
const stop = native.watch(parent, (entry: string, flags: number) => {
|
|
28
|
+
if ((flags & 7) || entry === parent) {
|
|
29
|
+
for (const group of listeners.values()) for (const notify of group) notify();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
for (const notify of listeners.get(dirname(entry)) ?? []) notify(basename(entry));
|
|
33
|
+
// A directory itself was renamed or removed.
|
|
34
|
+
for (const notify of listeners.get(entry) ?? []) notify();
|
|
35
|
+
});
|
|
36
|
+
stream = { listeners, stop };
|
|
37
|
+
runStreams.set(key, stream);
|
|
38
|
+
}
|
|
39
|
+
const group = stream.listeners.get(root) ?? new Set<ChangeListener>();
|
|
40
|
+
const notify: ChangeListener = name => changed(name);
|
|
41
|
+
group.add(notify);
|
|
42
|
+
stream.listeners.set(root, group);
|
|
43
|
+
return async () => {
|
|
44
|
+
if (!group.delete(notify)) return;
|
|
45
|
+
if (!group.size) stream.listeners.delete(root);
|
|
46
|
+
if (!stream.listeners.size) {
|
|
47
|
+
runStreams.delete(key);
|
|
48
|
+
await stream.stop();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const nativeWatch: WatchBackend = (path, changed, failed, shareParent) => {
|
|
54
|
+
const root = realpathSync(path);
|
|
55
|
+
if (process.platform !== "darwin") {
|
|
56
|
+
const watcher = watch(root, (_event, name) => changed(name ?? undefined));
|
|
57
|
+
watcher.on("error", failed);
|
|
58
|
+
return () => new Promise(resolve => { watcher.once("close", resolve); watcher.close(); });
|
|
59
|
+
}
|
|
60
|
+
// Loaded only by the owner, never by an executor worker.
|
|
61
|
+
if (!isMainThread) throw new Error("Darwin native source watches require the host transport");
|
|
62
|
+
if (shareParent && dirname(root) === realpathSync(dirname(path))) return watchDarwinRun(dirname(root), root, changed);
|
|
63
|
+
const native = createRequire(import.meta.url)("fsevents");
|
|
64
|
+
return native.watch(root, (entry: string, flags: number) => {
|
|
65
|
+
const name = relative(root, entry);
|
|
66
|
+
if (name === ".." || name.includes(sep)) return;
|
|
67
|
+
changed(flags & 7 ? undefined : name || basename(root));
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const watchSource: SourceWatch = (path, listener, shareParent) => {
|
|
72
|
+
const watcher = new EventEmitter() as SourceWatcher;
|
|
73
|
+
let closed = false;
|
|
74
|
+
watcher.on("change", listener);
|
|
75
|
+
const stop = nativeWatch(path, name => { if (!closed) watcher.emit("change", "rename", name); }, error => { if (!closed) watcher.emit("error", error); }, shareParent);
|
|
76
|
+
watcher.ready = Promise.resolve();
|
|
77
|
+
watcher.close = () => { if (!closed) { closed = true; void stop().then(() => watcher.emit("close"), error => watcher.emit("error", error)); } };
|
|
78
|
+
return watcher;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
interface Subscription { live: boolean; busy: boolean; names: Set<string | undefined>; overflow: boolean; stop: () => Promise<void>; retiring?: Promise<void> }
|
|
82
|
+
/** One executor owns native lifetimes even when its worker cannot run cleanup. */
|
|
83
|
+
export class HostSourceWatches {
|
|
84
|
+
private entries = new Map<string, Subscription>();
|
|
85
|
+
private revoked = new Set<number>();
|
|
86
|
+
private stopFailures = 0;
|
|
87
|
+
private backend: WatchBackend;
|
|
88
|
+
private limit: number;
|
|
89
|
+
constructor(backend: WatchBackend = nativeWatch, limit = 16384) { this.backend = backend; this.limit = limit; }
|
|
90
|
+
metrics() { return { allocated: this.entries.size, retiring: [...this.entries.values()].filter(value => !value.live).length, stopFailures: this.stopFailures }; }
|
|
91
|
+
handle(generation: number, message: any, send: (value: any) => void) {
|
|
92
|
+
if (!String(message.type).startsWith("source-watch-")) return false;
|
|
93
|
+
const id = message.id, key = `${generation}:${id}`;
|
|
94
|
+
if (!Number.isSafeInteger(id) || id < 1) return true;
|
|
95
|
+
const entry = this.entries.get(key);
|
|
96
|
+
if (message.type === "source-watch-subscribe") {
|
|
97
|
+
if (this.revoked.has(generation)) return true;
|
|
98
|
+
try {
|
|
99
|
+
if (entry || this.entries.size >= this.limit) throw new Error("Source watch capacity exhausted (including retiring subscriptions)");
|
|
100
|
+
const value: Subscription = { live: true, busy: false, names: new Set(), overflow: false, stop: async () => {} };
|
|
101
|
+
this.entries.set(key, value);
|
|
102
|
+
const changed = (name?: string) => {
|
|
103
|
+
if (!value.live) return;
|
|
104
|
+
if (value.busy) {
|
|
105
|
+
if (value.names.size < 128) value.names.add(name); else value.overflow = true;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
value.busy = true;
|
|
109
|
+
send({ type: "source-watch-event", id, names: [name] });
|
|
110
|
+
};
|
|
111
|
+
try { value.stop = this.backend(message.path, changed, error => {
|
|
112
|
+
if (!value.live) return;
|
|
113
|
+
send({ type: "source-watch-error", id, error: String(error).slice(0, 512) });
|
|
114
|
+
void this.retire(key, value).catch(() => {});
|
|
115
|
+
}, message.shareParent === true); }
|
|
116
|
+
catch (error) { this.entries.delete(key); throw error; }
|
|
117
|
+
send({ type: "source-watch-subscribed", id });
|
|
118
|
+
} catch (error) { send({ type: "source-watch-subscribed", id, error: String(error).slice(0, 512) }); }
|
|
119
|
+
} else if (message.type === "source-watch-consumed" && entry?.live) {
|
|
120
|
+
entry.busy = false;
|
|
121
|
+
if (entry.names.size || entry.overflow) {
|
|
122
|
+
const names = [...entry.names];
|
|
123
|
+
if (entry.overflow) names.push(undefined);
|
|
124
|
+
entry.names.clear(); entry.overflow = false; entry.busy = true;
|
|
125
|
+
send({ type: "source-watch-event", id, names });
|
|
126
|
+
}
|
|
127
|
+
} else if (message.type === "source-watch-unsubscribe") {
|
|
128
|
+
void (entry ? this.retire(key, entry) : Promise.resolve()).then(() => send({ type: "source-watch-unsubscribed", id }),
|
|
129
|
+
error => send({ type: "source-watch-unsubscribed", id, error: String(error).slice(0, 512) }));
|
|
130
|
+
}
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
private retire(key: string, entry: Subscription) {
|
|
134
|
+
entry.live = false;
|
|
135
|
+
return entry.retiring ??= Promise.resolve().then(entry.stop).then(() => { this.entries.delete(key); }, error => { this.stopFailures++; throw error; });
|
|
136
|
+
}
|
|
137
|
+
revoke(generation: number) {
|
|
138
|
+
this.revoked.add(generation);
|
|
139
|
+
return Promise.all([...this.entries].filter(([key]) => key.startsWith(`${generation}:`)).map(([key, entry]) => this.retire(key, entry)));
|
|
140
|
+
}
|
|
141
|
+
close() { return Promise.all([...this.entries].map(([key, entry]) => this.retire(key, entry))); }
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function workerSourceWatch(port: MessagePort): SourceWatch {
|
|
145
|
+
let counter = 0;
|
|
146
|
+
const entries = new Map<number, { watcher: SourceWatcher; resolve(): void; reject(error: Error): void; closed: boolean }>();
|
|
147
|
+
port.on("message", message => {
|
|
148
|
+
const entry = entries.get(message.id);
|
|
149
|
+
if (!entry || !String(message.type).startsWith("source-watch-")) return;
|
|
150
|
+
if (message.type === "source-watch-subscribed") {
|
|
151
|
+
if (message.error) entry.reject(new Error(message.error)); else entry.resolve();
|
|
152
|
+
} else if (message.type === "source-watch-error") {
|
|
153
|
+
if (!entry.closed) entry.watcher.emit("error", new Error(message.error));
|
|
154
|
+
} else if (message.type === "source-watch-event") {
|
|
155
|
+
if (!entry.closed) for (const name of message.names) entry.watcher.emit("change", "rename", name);
|
|
156
|
+
port.postMessage({ type: "source-watch-consumed", id: message.id });
|
|
157
|
+
} else if (message.type === "source-watch-unsubscribed") {
|
|
158
|
+
entries.delete(message.id);
|
|
159
|
+
if (message.error) entry.watcher.emit("error", new Error(message.error)); else entry.watcher.emit("close");
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
return (path, listener, shareParent) => {
|
|
163
|
+
// Preserve synchronous missing-path semantics; the model owns ancestor selection.
|
|
164
|
+
realpathSync(path);
|
|
165
|
+
const id = ++counter, watcher = new EventEmitter() as SourceWatcher;
|
|
166
|
+
let resolve!: () => void, reject!: (error: Error) => void;
|
|
167
|
+
watcher.ready = new Promise<void>((yes, no) => { resolve = yes; reject = no; });
|
|
168
|
+
void watcher.ready.catch(() => {});
|
|
169
|
+
const entry = { watcher, resolve, reject, closed: false };
|
|
170
|
+
entries.set(id, entry); watcher.on("change", listener);
|
|
171
|
+
watcher.close = () => { if (!entry.closed) { entry.closed = true; port.postMessage({ type: "source-watch-unsubscribe", id }); } };
|
|
172
|
+
port.postMessage({ type: "source-watch-subscribe", id, path, shareParent });
|
|
173
|
+
return watcher;
|
|
174
|
+
};
|
|
175
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { effectiveBackgroundPolicy } from './background-policy.ts';
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { acquireMutationStore } from "./mutation-store.ts";
|
|
6
|
+
|
|
7
|
+
export function hasSubagentManagement(root: string): boolean {
|
|
8
|
+
const path = join(root, "operation-coordinator.sqlite");
|
|
9
|
+
if (!existsSync(path)) return false;
|
|
10
|
+
const { DatabaseSync } = createRequire(import.meta.url)("node:sqlite");
|
|
11
|
+
const db = new DatabaseSync(path, { readOnly: true });
|
|
12
|
+
try { return !!db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='subagent_management'").get(); }
|
|
13
|
+
finally { db.close(); }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Fixed bundled domain adapter. No client module paths reach this boundary. */
|
|
17
|
+
export async function createSubagentLaunch(root: string, instance: string, catalog: unknown, verificationMs = 30000) {
|
|
18
|
+
if (Number(process.versions.node.split(".")[0]) < 24) throw new Error("Managed subagents require Node 24 or newer");
|
|
19
|
+
const path = "./domain/subagents/managed-launch-host.domain.mjs";
|
|
20
|
+
const { ManagedSubagentHost } = await import(path);
|
|
21
|
+
const lease = acquireMutationStore(root);
|
|
22
|
+
let host: any;
|
|
23
|
+
try {
|
|
24
|
+
const servicePath = "./domain/background-service/observed-waits.domain.mjs";
|
|
25
|
+
const { createObservedWaitHost } = await import(servicePath);
|
|
26
|
+
const permissionPath = "./domain/sandbox-policy/permission-settings.domain.mjs";
|
|
27
|
+
const { readPermissionSettings } = await import(permissionPath);
|
|
28
|
+
const toolsPath = "./domain/background-service/tools.domain.mjs";
|
|
29
|
+
const runtimePath = "./domain/background-service/runtime.domain.mjs";
|
|
30
|
+
const { registerTools } = await import(toolsPath);
|
|
31
|
+
const { createBackgroundTaskRuntime } = await import(runtimePath);
|
|
32
|
+
const registryPath = './domain/background-service/registry.domain.mjs';
|
|
33
|
+
const { readMeta } = await import(registryPath);
|
|
34
|
+
const sandboxPath="./domain/background-service/sandbox.domain.mjs";
|
|
35
|
+
const sandbox=await import(sandboxPath);
|
|
36
|
+
host = new ManagedSubagentHost(root, instance, catalog, lease.store, (pi: any) => {
|
|
37
|
+
const service = createObservedWaitHost(pi, { sharedStore: lease.store, storePath: join(root, "operation-coordinator.sqlite"), serverOwnedResults: true, pollMs: 0,
|
|
38
|
+
enterControl: () => lease.budget.enter("control"), verificationMs,
|
|
39
|
+
prepareWorkerPolicy(run:any){
|
|
40
|
+
const resolve=()=>{
|
|
41
|
+
const attempt=lease.store.subagentLaunchJournal().attempt(run.runId);
|
|
42
|
+
if(!attempt?.launchAuthority)throw new Error('permission-unavailable: captured worker launch authority missing');
|
|
43
|
+
const saved=attempt.launchAuthority.permissions;
|
|
44
|
+
const captured=saved?.backgroundPolicy ?? (saved?.subagentPermissions?{state:saved.subagentPermissions.enabled?'enabled':'inactive',permissions:saved.subagentPermissions}:undefined);
|
|
45
|
+
return effectiveBackgroundPolicy(captured,readPermissionSettings({agentDir:()=>root}).background,run.workspace) ?? {state:'inactive'};
|
|
46
|
+
};
|
|
47
|
+
const workerPolicy=resolve();sandbox.clearForegroundSandboxPolicy(pi);
|
|
48
|
+
pi.events.emit('pi-better-sandbox:policy',{...workerPolicy,background:workerPolicy});
|
|
49
|
+
const expected=JSON.stringify(workerPolicy);
|
|
50
|
+
return ()=>{if(JSON.stringify(resolve())!==expected)throw new Error('permission-unavailable: Background policy changed before worker dispatch');};
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const runtime = createBackgroundTaskRuntime(undefined, undefined, undefined,
|
|
54
|
+
(kind: string, id: string, work: () => unknown, dueAt?: number) => {
|
|
55
|
+
const origin = readMeta(id)?.callbackOrigin;
|
|
56
|
+
return lease.budget.scheduleSource(`legacy-${kind}`, id, work, JSON.stringify([origin?.cwd ?? root, origin?.sessionId ?? null]), dueAt);
|
|
57
|
+
});
|
|
58
|
+
registerTools(pi, runtime, () => undefined);
|
|
59
|
+
const close = service.close.bind(service);
|
|
60
|
+
service.close = () => { try { close(); } finally { runtime.suspendScheduledWork(); } };
|
|
61
|
+
return service;
|
|
62
|
+
}, () => readPermissionSettings({ agentDir: () => root }), verificationMs, () => lease.budget.enter("control"));
|
|
63
|
+
await host.recover();
|
|
64
|
+
const close = host.close.bind(host);
|
|
65
|
+
host.close = async () => {
|
|
66
|
+
try { await close(); } finally { lease.release(); }
|
|
67
|
+
};
|
|
68
|
+
return host;
|
|
69
|
+
} catch (error) {
|
|
70
|
+
try { await host?.close(); } finally { lease.release(); }
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// Source hints coalesce by entity. Receipt/application remains owned by each
|
|
2
|
+
// domain; both domains take the same bounded foreground allowance before repair.
|
|
3
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
4
|
+
export const ENTITY_BUDGET = 32;
|
|
5
|
+
export type WorkLane = "control" | "query" | "repair";
|
|
6
|
+
const lanes: WorkLane[] = ["control", "query", "repair"];
|
|
7
|
+
const limits = [16, 8, 8];
|
|
8
|
+
const sourceKinds = ['legacy-watch', 'legacy-remote-poll', 'legacy-handoff', 'legacy-process-deadline', 'legacy-log-retention'];
|
|
9
|
+
const wakeIndex = 10 + sourceKinds.length * 5;
|
|
10
|
+
export function notifyWorkBudget(buffer: SharedArrayBuffer) {
|
|
11
|
+
const counters = new Int32Array(buffer);
|
|
12
|
+
if (counters.length > wakeIndex) { Atomics.add(counters, wakeIndex, 1); Atomics.notify(counters, wakeIndex); }
|
|
13
|
+
}
|
|
14
|
+
/** Root-wide outstanding source work. Reserved lanes cannot be consumed by a wedged reader. */
|
|
15
|
+
export function createWorkBudget(buffer = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * (wakeIndex + 7 + sourceKinds.length))) {
|
|
16
|
+
const counters = new Int32Array(buffer);
|
|
17
|
+
const legacyIndex = 9 + sourceKinds.length * 5;
|
|
18
|
+
const reservation = new AsyncLocalStorage<{ active: boolean }>();
|
|
19
|
+
const pending = new Map<string, Promise<unknown>>();
|
|
20
|
+
const ownerObservations = new Map<string, number>();
|
|
21
|
+
const queue: Array<() => boolean> = [];
|
|
22
|
+
let waiting = false, pumping = false;
|
|
23
|
+
const pump = () => {
|
|
24
|
+
if (pumping) return;
|
|
25
|
+
pumping = true;
|
|
26
|
+
const version = Atomics.load(counters, wakeIndex);
|
|
27
|
+
for (let i = 0; i < queue.length;) { if (queue[i]!()) queue.splice(i, 1); else i++; }
|
|
28
|
+
pumping = false;
|
|
29
|
+
if (queue.length && !waiting) {
|
|
30
|
+
const wait = (Atomics as typeof Atomics & { waitAsync(array: Int32Array, index: number, value: number): { async: boolean; value: string | Promise<string> } }).waitAsync(counters, wakeIndex, version);
|
|
31
|
+
if (wait.async) { waiting = true; void (wait.value as Promise<string>).then(() => { waiting = false; pump(); }); }
|
|
32
|
+
else queueMicrotask(pump);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const sourceWork = new Map<string, { started: number; completed: number; failed: number; elapsedMs: number; active: number }>();
|
|
36
|
+
return { buffer,
|
|
37
|
+
// Timers and accepted recovery use deferred dispatch. Synchronous callers
|
|
38
|
+
// retain their return/throw contract; nested source measurement never waits.
|
|
39
|
+
scheduleSource<T>(kind: string, id: string, work: () => T, owner = 'runtime', dueAt?: number): Promise<Awaited<T>> {
|
|
40
|
+
if (reservation.getStore()?.active) return Promise.resolve().then(() => this.source(kind, work)) as Promise<Awaited<T>>;
|
|
41
|
+
const key = JSON.stringify([owner, kind, id]);
|
|
42
|
+
const prior = pending.get(key);
|
|
43
|
+
if (prior) return prior as Promise<Awaited<T>>;
|
|
44
|
+
let resolve!: (value: Awaited<T>) => void, reject!: (error: unknown) => void;
|
|
45
|
+
const result = new Promise<Awaited<T>>((yes, no) => { resolve = yes; reject = no; });
|
|
46
|
+
pending.set(key, result);
|
|
47
|
+
queue.push(() => {
|
|
48
|
+
// Outstanding observations cannot consume the slots needed by deadlines.
|
|
49
|
+
const observation = !['legacy-process-deadline', 'legacy-handoff', 'cancellation'].includes(kind);
|
|
50
|
+
if (observation && owner !== 'runtime' && (ownerObservations.get(owner) ?? 0) >= 2) return false;
|
|
51
|
+
if (observation && counters.length > legacyIndex) {
|
|
52
|
+
for (;;) {
|
|
53
|
+
const active = Atomics.load(counters, legacyIndex);
|
|
54
|
+
if (active >= 8) return false;
|
|
55
|
+
if (Atomics.compareExchange(counters, legacyIndex, active, active + 1) === active) break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const release = this.enter('control');
|
|
59
|
+
if (!release) { if (observation && counters.length > legacyIndex) Atomics.sub(counters, legacyIndex, 1); return false; }
|
|
60
|
+
const scope = { active: true };
|
|
61
|
+
const sourceIndex = sourceKinds.indexOf(kind);
|
|
62
|
+
if (sourceIndex >= 0 && dueAt !== undefined) Atomics.add(counters, wakeIndex + 7 + sourceIndex, Math.max(0, Date.now() - dueAt));
|
|
63
|
+
if (observation) ownerObservations.set(owner, (ownerObservations.get(owner) ?? 0) + 1);
|
|
64
|
+
const finish = () => {
|
|
65
|
+
scope.active = false;
|
|
66
|
+
if (observation) { const left = ownerObservations.get(owner)! - 1; if (left) ownerObservations.set(owner, left); else ownerObservations.delete(owner); }
|
|
67
|
+
if (observation && counters.length > legacyIndex) Atomics.sub(counters, legacyIndex, 1); pending.delete(key); release();
|
|
68
|
+
};
|
|
69
|
+
try {
|
|
70
|
+
Promise.resolve(reservation.run(scope, () => this.source(kind, work))).then(value => { finish(); resolve(value); }, error => { finish(); reject(error); });
|
|
71
|
+
} catch (error) { finish(); reject(error); }
|
|
72
|
+
return true;
|
|
73
|
+
});
|
|
74
|
+
pump();
|
|
75
|
+
return result;
|
|
76
|
+
},
|
|
77
|
+
// Measure at the owner that performs the work, including asynchronous completion.
|
|
78
|
+
source<T>(kind: string, work: () => T): T {
|
|
79
|
+
const index = sourceKinds.indexOf(kind), base = 9 + index * 5;
|
|
80
|
+
const shared = index >= 0 && counters.length >= base + 5;
|
|
81
|
+
let metric = sourceWork.get(kind);
|
|
82
|
+
if (!metric) { metric = { started: 0, completed: 0, failed: 0, elapsedMs: 0, active: 0 }; sourceWork.set(kind, metric); }
|
|
83
|
+
metric.started++; metric.active++;
|
|
84
|
+
if (shared) { Atomics.add(counters, base, 1); Atomics.add(counters, base + 4, 1); }
|
|
85
|
+
const started = performance.now();
|
|
86
|
+
const finish = (failed: boolean) => {
|
|
87
|
+
const elapsed = performance.now() - started;
|
|
88
|
+
metric.active--; metric.completed++; metric.failed += Number(failed); metric.elapsedMs += elapsed;
|
|
89
|
+
if (shared) { Atomics.add(counters, base + 1, 1); Atomics.add(counters, base + 2, Number(failed)); Atomics.add(counters, base + 3, Math.round(elapsed)); Atomics.sub(counters, base + 4, 1); }
|
|
90
|
+
};
|
|
91
|
+
try {
|
|
92
|
+
const value = work();
|
|
93
|
+
if (value instanceof Promise) return value.then(result => { finish(false); return result; }, error => { finish(true); throw error; }) as T;
|
|
94
|
+
finish(false);
|
|
95
|
+
return value;
|
|
96
|
+
} catch (error) { finish(true); throw error; }
|
|
97
|
+
},
|
|
98
|
+
enter(lane: WorkLane) {
|
|
99
|
+
const index = lanes.indexOf(lane);
|
|
100
|
+
for (;;) {
|
|
101
|
+
const used = Atomics.load(counters, index);
|
|
102
|
+
if (used >= limits[index]!) { Atomics.add(counters, index + 6, 1); return undefined; }
|
|
103
|
+
if (Atomics.compareExchange(counters, index, used, used + 1) === used) break;
|
|
104
|
+
}
|
|
105
|
+
Atomics.add(counters, index + 3, 1);
|
|
106
|
+
const started = performance.now();
|
|
107
|
+
let released = false;
|
|
108
|
+
return () => { if (!released) {
|
|
109
|
+
released = true; Atomics.sub(counters, index, 1);
|
|
110
|
+
Atomics.add(counters, wakeIndex + 1 + index, 1);
|
|
111
|
+
Atomics.add(counters, wakeIndex + 4 + index, Math.round(performance.now() - started));
|
|
112
|
+
notifyWorkBudget(buffer);
|
|
113
|
+
} };
|
|
114
|
+
},
|
|
115
|
+
metrics() { return { queuedSources: queue.length, pendingSources: pending.size, sources: { ...Object.fromEntries([...sourceWork].map(([kind, metric]) => [kind, { ...metric, deadlineLatenessMs: 0 }])),
|
|
116
|
+
...Object.fromEntries(sourceKinds.flatMap((kind, i) => {
|
|
117
|
+
const base = 9 + i * 5;
|
|
118
|
+
return counters.length < base + 5 ? [] : [[kind, { started: Atomics.load(counters, base), completed: Atomics.load(counters, base + 1),
|
|
119
|
+
failed: Atomics.load(counters, base + 2), elapsedMs: Atomics.load(counters, base + 3), active: Atomics.load(counters, base + 4),
|
|
120
|
+
deadlineLatenessMs: Atomics.load(counters, wakeIndex + 7 + i) }]];
|
|
121
|
+
})) }, capacity: ENTITY_BUDGET, lanes: Object.fromEntries(lanes.map((lane, i) => [lane,
|
|
122
|
+
{ capacity: limits[i], active: Atomics.load(counters, i), admitted: Atomics.load(counters, i + 3), deferred: Atomics.load(counters, i + 6),
|
|
123
|
+
completed: Atomics.load(counters, wakeIndex + 1 + i), elapsedMs: Atomics.load(counters, wakeIndex + 4 + i) }])) }; },
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
export function workPage<T>(items: Iterable<T>, limit = ENTITY_BUDGET): T[] {
|
|
127
|
+
const page: T[] = [];
|
|
128
|
+
for (const item of items) { if (page.length === limit) break; page.push(item); }
|
|
129
|
+
return page;
|
|
130
|
+
}
|
|
@@ -12,3 +12,11 @@ export class WorkClient {
|
|
|
12
12
|
onCatalog(listener: (snapshot: any) => void): () => void;
|
|
13
13
|
close(): void;
|
|
14
14
|
}
|
|
15
|
+
|
|
16
|
+
export interface ConnectionOptions {
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
recover?: (options: { timeoutMs: number; signal: AbortSignal }) => Promise<unknown>;
|
|
20
|
+
}
|
|
21
|
+
/** Establishes a connection; never replays application requests. */
|
|
22
|
+
export function connectWorkClient(socketPath: string, agentDir: string, capabilities?: string[], options?: ConnectionOptions): Promise<WorkClient>;
|