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,276 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-subagents/assignment-outcomes.ts. Do not edit directly.
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { isDeepStrictEqual } from "node:util";
|
|
5
|
+
import { join, relative, isAbsolute, dirname, resolve } from "node:path";
|
|
6
|
+
import { openSync, closeSync, fstatSync, readSync, realpathSync, constants } from "node:fs";
|
|
7
|
+
import { openStore, ownerDiff } from "./shared-operation-coordinator/index.domain.mjs";
|
|
8
|
+
import { processStartToken, readMeta } from "./registry.domain.mjs";
|
|
9
|
+
import { credentialFilePaths } from "./shared-sandbox-core.domain.mjs";
|
|
10
|
+
import { readAssignmentReport } from "./assignment-report.domain.mjs";
|
|
11
|
+
export const ASSIGNMENT_OUTCOMES_VERSION = 1;
|
|
12
|
+
const closedHosts = globalThis.__assignmentOutcomeClosedHosts ??= new Set();
|
|
13
|
+
export function createOutcomeHost() {
|
|
14
|
+
return `assignment:${process.pid}:${encodeURIComponent(processStartToken(process.pid) ?? "unknown")}:${randomUUID()}`;
|
|
15
|
+
}
|
|
16
|
+
export function closeOutcomeHost(hostId) {
|
|
17
|
+
closedHosts.add(hostId);
|
|
18
|
+
}
|
|
19
|
+
export function claimOutcome(meta, hostId) {
|
|
20
|
+
const outcome = readOutcome(meta);
|
|
21
|
+
if (!outcome)
|
|
22
|
+
return false;
|
|
23
|
+
return withStore((store) => {
|
|
24
|
+
const event = store.listOutbox().find((e) => e.eventId === outcome.eventId);
|
|
25
|
+
if (!event || ["delivered", "acknowledged"].includes(event.state))
|
|
26
|
+
return false;
|
|
27
|
+
if (event.dispatchClaim) {
|
|
28
|
+
if (event.dispatchClaim.claimedBy === hostId)
|
|
29
|
+
return true;
|
|
30
|
+
const [prefix, pidText, token] = event.dispatchClaim.claimedBy.split(":");
|
|
31
|
+
let dead = closedHosts.has(event.dispatchClaim.claimedBy);
|
|
32
|
+
if (prefix === "assignment" && !dead) {
|
|
33
|
+
try {
|
|
34
|
+
process.kill(Number(pidText), 0);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
dead = error.code === "ESRCH";
|
|
38
|
+
}
|
|
39
|
+
const current = processStartToken(Number(pidText));
|
|
40
|
+
if (current && token !== "unknown" && encodeURIComponent(current) !== token)
|
|
41
|
+
dead = true;
|
|
42
|
+
}
|
|
43
|
+
if (!dead)
|
|
44
|
+
return false;
|
|
45
|
+
store.releaseOutbox({ eventId: event.eventId, claimToken: event.dispatchClaim.token, reason: "prior outcome delivery host exited" });
|
|
46
|
+
}
|
|
47
|
+
return store.claimOutbox({ type: "assignment-outcome", eventId: outcome.eventId, recipient: outcome.recipient, claimToken: `outcome_${randomUUID()}`, claimedBy: hostId, limit: 1 }).length === 1;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
export function coordinatorPath() {
|
|
51
|
+
return join(process.env.PI_CODING_AGENT_DIR ?? join(homedir(), ".pi", "agent"), "operation-coordinator.sqlite");
|
|
52
|
+
}
|
|
53
|
+
function withStore(body) {
|
|
54
|
+
const path = coordinatorPath();
|
|
55
|
+
const borrowed = runtimeStores.get(canonicalRoot(dirname(path)));
|
|
56
|
+
if (borrowed)
|
|
57
|
+
return body(borrowed.store);
|
|
58
|
+
const store = openStore({ path });
|
|
59
|
+
try {
|
|
60
|
+
return body(store);
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
store.close();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const runtimeStores = new Map();
|
|
67
|
+
function canonicalRoot(root) {
|
|
68
|
+
try {
|
|
69
|
+
return realpathSync(root);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return resolve(root);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** Fixed runtime adapter borrows its mutation connection; it retains ownership. */
|
|
76
|
+
export function bindRuntimeOutcomeStore(root, store) {
|
|
77
|
+
const key = canonicalRoot(root);
|
|
78
|
+
let entry = runtimeStores.get(key);
|
|
79
|
+
if (entry && entry.store !== store)
|
|
80
|
+
throw new Error("Assignment runtime store already bound");
|
|
81
|
+
if (!entry) {
|
|
82
|
+
entry = { store, leases: 0 };
|
|
83
|
+
runtimeStores.set(key, entry);
|
|
84
|
+
}
|
|
85
|
+
entry.leases++;
|
|
86
|
+
let released = false;
|
|
87
|
+
return () => {
|
|
88
|
+
if (released)
|
|
89
|
+
return;
|
|
90
|
+
released = true;
|
|
91
|
+
if (--entry.leases === 0)
|
|
92
|
+
runtimeStores.delete(key);
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
export function registerAssignmentAttempt(binding, attemptId) {
|
|
96
|
+
if (binding.version !== ASSIGNMENT_OUTCOMES_VERSION)
|
|
97
|
+
throw new Error("Unsupported assignment outcome capability.");
|
|
98
|
+
withStore((store) => store.registerAssignment({ ...binding, attemptId }));
|
|
99
|
+
}
|
|
100
|
+
/** Called before any completion handoff, including callback:false and inactive parents. */
|
|
101
|
+
export function commitAssignmentTerminal(meta, recoveryFailure = false) {
|
|
102
|
+
const binding = meta.assignment;
|
|
103
|
+
if (!binding)
|
|
104
|
+
return null;
|
|
105
|
+
return withStore((store) => {
|
|
106
|
+
const existing = store.getAssignmentOutcome(binding.assignmentId);
|
|
107
|
+
if (existing)
|
|
108
|
+
return existing;
|
|
109
|
+
if (!["failed", "completed", "killed", "lost"].includes(meta.status) || (meta.status === "completed" && meta.park))
|
|
110
|
+
return null;
|
|
111
|
+
const waits = store.listWaits({ owner: binding.owner }).filter((w) => w.origin?.assignmentRef === binding.assignmentId);
|
|
112
|
+
// A published automatic attempt's exit belongs to bounded recovery first.
|
|
113
|
+
if (!recoveryFailure && meta.status !== "killed" && meta.operations?.resumeLaunchToken && waits.some((w) => !w.acknowledgement && ["resuming", "ready"].includes(w.phase)))
|
|
114
|
+
return null;
|
|
115
|
+
// A coherent attempt exit does not establish interpretation or completion.
|
|
116
|
+
if (meta.status === "completed" && waits.some((w) => !w.acknowledgement))
|
|
117
|
+
return null;
|
|
118
|
+
let report = null;
|
|
119
|
+
let invalidReport = "";
|
|
120
|
+
try {
|
|
121
|
+
report = readAssignmentReport(meta);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
if (meta.status === "completed")
|
|
125
|
+
invalidReport = "Assignment completion is unverified: retained report evidence is unavailable or changed.";
|
|
126
|
+
}
|
|
127
|
+
const complete = meta.status === "completed" && (report ? report.status === "complete"
|
|
128
|
+
: !invalidReport && waits.some((w) => w.acknowledgement?.disposition === "assignment-complete"));
|
|
129
|
+
const reportReason = report?.status === "incomplete" ? `Assignment incomplete: ${report.reason}`
|
|
130
|
+
+ (report.blocker ? ` Blocked (${report.blocker.kind}): ${report.blocker.reason}.` : "")
|
|
131
|
+
+ (report.remainingWork ? ` Remaining work: ${report.remainingWork.join("; ")}.` : "") : report?.reason;
|
|
132
|
+
try {
|
|
133
|
+
return store.recordAssignmentOutcome({ ...binding, revision: 1,
|
|
134
|
+
outcome: complete ? "succeeded" : meta.status === "killed" ? "cancelled" : "failed",
|
|
135
|
+
reason: (meta.failureReason || invalidReport || (meta.status === "completed" && report ? reportReason : complete ? "Assigned work and required interpretation are complete."
|
|
136
|
+
: meta.status === "completed" && meta.assignmentReportRejection ? `Assignment report rejected: ${meta.assignmentReportRejection.reason}`
|
|
137
|
+
: meta.status === "completed" ? "Assignment completion is unverified: the attempt exited without an evidence-backed completion decision. Inspect retained output and continue unfinished work or report a concrete blocker."
|
|
138
|
+
: `Assignment ended ${meta.status}; retained attempt evidence is available.`)).slice(0, 8192),
|
|
139
|
+
processUncertain: meta.status === "lost" || typeof meta.exitCode !== "number"
|
|
140
|
+
|| waits.some((w) => w.dependencies.some((d) => d.terminalRevision === 0)
|
|
141
|
+
|| store.listResumeClaims({ waitId: w.waitId, generation: w.generation, state: "published" }).length > 0),
|
|
142
|
+
evidence: [{ kind: "log", ref: meta.logPath, summary: `Attempt ${meta.id}: ${meta.status}` },
|
|
143
|
+
...(report ? [{ kind: "artifact", ref: meta.assignmentReport.path, summary: report.reason },
|
|
144
|
+
...report.evidence.map((e) => ({ kind: "artifact", ref: e.path, summary: e.explanation }))] : [])],
|
|
145
|
+
waits: waits.map((w) => ({ waitId: w.waitId, generation: w.generation, cancelEpoch: w.cancelEpoch })), });
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
// A competing finalizer may commit after our initial read. The store
|
|
149
|
+
// still refuses rewrites; return only the same captured binding's winner.
|
|
150
|
+
// Borrowed runtime stores use a different coordinator module's StoreError constructor.
|
|
151
|
+
if (error instanceof Error && error.name === "StoreError" && "code" in error
|
|
152
|
+
&& error.code === "validation" && error.message === "A terminal assignment cannot be rewritten or reopened.") {
|
|
153
|
+
const winner = store.getAssignmentOutcome(binding.assignmentId);
|
|
154
|
+
const current = readMeta(meta.id);
|
|
155
|
+
if (winner && winner.assignmentId === binding.assignmentId && winner.revision === 1 && ownerDiff(winner.owner, binding.owner) === "none"
|
|
156
|
+
&& ownerDiff(winner.recipient, binding.recipient) === "none"
|
|
157
|
+
&& current?.assignment?.assignmentId === binding.assignmentId
|
|
158
|
+
&& ownerDiff(current.assignment.owner, binding.owner) === "none" && ownerDiff(current.assignment.recipient, binding.recipient) === "none"
|
|
159
|
+
&& current.sessionId === meta.sessionId && current.cwd === meta.cwd && current.pid === meta.pid && current.pidStartTime === meta.pidStartTime
|
|
160
|
+
&& isDeepStrictEqual(current.management, meta.management)
|
|
161
|
+
&& current.operations?.resumeLaunchToken === meta.operations?.resumeLaunchToken
|
|
162
|
+
&& winner.evidence.some(evidence => evidence.kind === "log" && evidence.ref === meta.logPath))
|
|
163
|
+
return winner;
|
|
164
|
+
}
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
export function readOutcome(meta) {
|
|
170
|
+
return meta.assignment ? withStore((store) => store.getAssignmentOutcome(meta.assignment.assignmentId)) : null;
|
|
171
|
+
}
|
|
172
|
+
export function assignmentRetainsEvidence(meta) {
|
|
173
|
+
if (!meta.assignment)
|
|
174
|
+
return false;
|
|
175
|
+
return withStore((store) => {
|
|
176
|
+
const outcome = store.getAssignmentOutcome(meta.assignment.assignmentId);
|
|
177
|
+
if (!outcome)
|
|
178
|
+
return false;
|
|
179
|
+
if (!outcome.disposition)
|
|
180
|
+
return true;
|
|
181
|
+
const waits = store.listWaits({ owner: outcome.owner }).filter((w) => w.origin?.assignmentRef === outcome.assignmentId);
|
|
182
|
+
return waits.some((w) => store.listResumeClaims({ waitId: w.waitId, generation: w.generation, state: "published" }).length > 0);
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
export function receiptOutcome(meta, entryId) {
|
|
186
|
+
const record = readOutcome(meta);
|
|
187
|
+
if (record)
|
|
188
|
+
withStore((store) => store.receiptAssignmentOutcome({ assignmentId: record.assignmentId, recipient: record.recipient, revision: record.revision, entryId }));
|
|
189
|
+
}
|
|
190
|
+
export function outcomeTranscriptReceipt(entries, eventId) {
|
|
191
|
+
for (const raw of entries) {
|
|
192
|
+
const entry = raw;
|
|
193
|
+
const message = entry.type === "custom_message" ? entry
|
|
194
|
+
: entry.type === "message" && entry.message?.role === "custom" ? entry.message : null;
|
|
195
|
+
if (message?.customType !== "background-completion-batch")
|
|
196
|
+
continue;
|
|
197
|
+
const ids = message.details?.completionEventIds;
|
|
198
|
+
if (Array.isArray(ids) && ids.includes(eventId))
|
|
199
|
+
return entry.id ?? eventId;
|
|
200
|
+
}
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
function under(path, root) {
|
|
204
|
+
const rel = relative(root, path);
|
|
205
|
+
return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
|
|
206
|
+
}
|
|
207
|
+
export function inspectOutcome(meta, input) {
|
|
208
|
+
if (input.disposition && !Number.isInteger(input.revision))
|
|
209
|
+
throw new Error("Outcome disposition requires the exact outcome_revision.");
|
|
210
|
+
if (!meta.assignment)
|
|
211
|
+
throw new Error("This run has no durable assignment outcome capability.");
|
|
212
|
+
return withStore((store) => {
|
|
213
|
+
const outcome = store.getAssignmentOutcome(meta.assignment.assignmentId);
|
|
214
|
+
if (!outcome || outcome.recipient.sessionId !== input.recipient.sessionId || outcome.recipient.workspace !== input.recipient.workspace
|
|
215
|
+
|| (outcome.recipient.branchId && outcome.recipient.branchId !== input.recipient.branchId && !input.branchIds?.includes(outcome.recipient.branchId)))
|
|
216
|
+
throw new Error("Outcome belongs to a different parent session or branch.");
|
|
217
|
+
const policy = input.permissions?.permissions;
|
|
218
|
+
if (meta.operations?.policy.sandbox && !policy)
|
|
219
|
+
throw new Error("Current mandatory read authority is unavailable.");
|
|
220
|
+
const readable = (path) => {
|
|
221
|
+
const real = realpathSync(path);
|
|
222
|
+
if (credentialFilePaths(homedir()).some((p) => {
|
|
223
|
+
try {
|
|
224
|
+
return under(real, realpathSync(p));
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
return under(real, p);
|
|
228
|
+
}
|
|
229
|
+
}))
|
|
230
|
+
throw new Error("Credential evidence access is refused.");
|
|
231
|
+
const access = under(real, realpathSync(input.recipient.workspace)) ? policy?.projectFiles : policy?.outsideProject;
|
|
232
|
+
if (policy?.enabled && access !== "read" && access !== "read-write")
|
|
233
|
+
throw new Error("Current file read permission refuses this evidence.");
|
|
234
|
+
return real;
|
|
235
|
+
};
|
|
236
|
+
const waits = store.listWaits({ owner: outcome.owner }).filter((w) => w.origin?.assignmentRef === outcome.assignmentId);
|
|
237
|
+
let logs = [];
|
|
238
|
+
if (input.operationId) {
|
|
239
|
+
if (!waits.some((w) => w.dependencies.some((d) => d.operationId === input.operationId)))
|
|
240
|
+
throw new Error("Operation is not an assignment dependency.");
|
|
241
|
+
logs = store.listOperationEvidence(input.operationId).filter((e) => e.kind === "log").slice(0, 2).map((e) => {
|
|
242
|
+
if (!isAbsolute(e.ref))
|
|
243
|
+
throw new Error("Legacy dependency log has no verified absolute path; inspect its retained summary instead.");
|
|
244
|
+
const fd = openSync(readable(e.ref), constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
245
|
+
try {
|
|
246
|
+
const size = fstatSync(fd).size;
|
|
247
|
+
const bytes = Buffer.alloc(Math.min(size, 4096));
|
|
248
|
+
const count = readSync(fd, bytes, 0, bytes.length, Math.max(0, size - bytes.length));
|
|
249
|
+
return { ref: e.ref, text: bytes.subarray(0, count).toString("utf8") };
|
|
250
|
+
}
|
|
251
|
+
finally {
|
|
252
|
+
closeSync(fd);
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
// Check retained references before recording an inspection, never a worker read.
|
|
257
|
+
const unavailableEvidence = [];
|
|
258
|
+
for (const pin of [...outcome.evidence, ...store.listEvidencePins({ waitId: outcome.eventId, generation: 1 })]) {
|
|
259
|
+
if ((pin.kind === "log" || pin.kind === "artifact") && isAbsolute(pin.ref)) {
|
|
260
|
+
try {
|
|
261
|
+
readable(pin.ref);
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
if (error.code !== "ENOENT")
|
|
265
|
+
throw error;
|
|
266
|
+
unavailableEvidence.push(pin.ref);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const request = { assignmentId: outcome.assignmentId, recipient: outcome.recipient, revision: input.revision ?? outcome.revision };
|
|
271
|
+
const record = input.disposition
|
|
272
|
+
? store.consumeAssignmentOutcome({ ...request, disposition: input.disposition, note: input.note ?? "" })
|
|
273
|
+
: store.inspectAssignmentOutcome(request);
|
|
274
|
+
return { outcome: record, unavailableEvidence, dependencies: waits.slice(0, 20).map((w) => ({ waitId: w.waitId, generation: w.generation, phase: w.phase, acknowledgement: w.acknowledgement, dependencies: w.dependencies.slice(0, 20) })), logs };
|
|
275
|
+
});
|
|
276
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { isDeepStrictEqual } from "node:util";
|
|
4
|
+
import { join, relative, isAbsolute, dirname, resolve } from "node:path";
|
|
5
|
+
import { openSync, closeSync, fstatSync, readSync, realpathSync, constants } from "node:fs";
|
|
6
|
+
import { openStore, ownerDiff, type OwnerIdentity, type AssignmentOutcomeRecord } from "./shared-operation-coordinator/index.ts";
|
|
7
|
+
import type { RunMeta } from "./registry.ts";
|
|
8
|
+
import { processStartToken, readMeta } from "./registry.ts";
|
|
9
|
+
import type { PermissionSnapshot } from "./permission-policy.ts";
|
|
10
|
+
import { credentialFilePaths } from "./shared-sandbox-core.ts";
|
|
11
|
+
import { readAssignmentReport } from "./assignment-report.ts";
|
|
12
|
+
|
|
13
|
+
export const ASSIGNMENT_OUTCOMES_VERSION = 1;
|
|
14
|
+
const closedHosts = (globalThis as typeof globalThis & { __assignmentOutcomeClosedHosts?: Set<string> }).__assignmentOutcomeClosedHosts ??= new Set<string>();
|
|
15
|
+
export function createOutcomeHost(): string {
|
|
16
|
+
return `assignment:${process.pid}:${encodeURIComponent(processStartToken(process.pid) ?? "unknown")}:${randomUUID()}`;
|
|
17
|
+
}
|
|
18
|
+
export function closeOutcomeHost(hostId: string): void {
|
|
19
|
+
closedHosts.add(hostId);
|
|
20
|
+
}
|
|
21
|
+
export function claimOutcome(meta: RunMeta, hostId: string): boolean {
|
|
22
|
+
const outcome = readOutcome(meta);
|
|
23
|
+
if (!outcome) return false;
|
|
24
|
+
return withStore((store) => {
|
|
25
|
+
const event = store.listOutbox().find((e) => e.eventId === outcome.eventId);
|
|
26
|
+
if (!event || ["delivered", "acknowledged"].includes(event.state)) return false;
|
|
27
|
+
if (event.dispatchClaim) {
|
|
28
|
+
if (event.dispatchClaim.claimedBy === hostId) return true;
|
|
29
|
+
const [prefix, pidText, token] = event.dispatchClaim.claimedBy.split(":");
|
|
30
|
+
let dead = closedHosts.has(event.dispatchClaim.claimedBy);
|
|
31
|
+
if (prefix === "assignment" && !dead) {
|
|
32
|
+
try { process.kill(Number(pidText), 0); } catch (error) { dead = (error as NodeJS.ErrnoException).code === "ESRCH"; }
|
|
33
|
+
const current = processStartToken(Number(pidText));
|
|
34
|
+
if (current && token !== "unknown" && encodeURIComponent(current) !== token) dead = true;
|
|
35
|
+
}
|
|
36
|
+
if (!dead) return false;
|
|
37
|
+
store.releaseOutbox({ eventId: event.eventId, claimToken: event.dispatchClaim.token, reason: "prior outcome delivery host exited" });
|
|
38
|
+
}
|
|
39
|
+
return store.claimOutbox({ type: "assignment-outcome", eventId: outcome.eventId, recipient: outcome.recipient, claimToken: `outcome_${randomUUID()}`, claimedBy: hostId, limit: 1 }).length === 1;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
export interface AssignmentBinding { version: 1; assignmentId: string; owner: OwnerIdentity; recipient: OwnerIdentity }
|
|
43
|
+
export function coordinatorPath(): string {
|
|
44
|
+
return join(process.env.PI_CODING_AGENT_DIR ?? join(homedir(), ".pi", "agent"), "operation-coordinator.sqlite");
|
|
45
|
+
}
|
|
46
|
+
function withStore<T>(body: (store: ReturnType<typeof openStore>) => T): T {
|
|
47
|
+
const path = coordinatorPath();
|
|
48
|
+
const borrowed = runtimeStores.get(canonicalRoot(dirname(path)));
|
|
49
|
+
if (borrowed) return body(borrowed.store);
|
|
50
|
+
const store = openStore({ path });
|
|
51
|
+
try { return body(store); } finally { store.close(); }
|
|
52
|
+
}
|
|
53
|
+
const runtimeStores = new Map<string, { store: ReturnType<typeof openStore>; leases: number }>();
|
|
54
|
+
function canonicalRoot(root: string): string {
|
|
55
|
+
try { return realpathSync(root); } catch { return resolve(root); }
|
|
56
|
+
}
|
|
57
|
+
/** Fixed runtime adapter borrows its mutation connection; it retains ownership. */
|
|
58
|
+
export function bindRuntimeOutcomeStore(root: string, store: ReturnType<typeof openStore>): () => void {
|
|
59
|
+
const key = canonicalRoot(root);
|
|
60
|
+
let entry = runtimeStores.get(key);
|
|
61
|
+
if (entry && entry.store !== store) throw new Error("Assignment runtime store already bound");
|
|
62
|
+
if (!entry) { entry = { store, leases: 0 }; runtimeStores.set(key, entry); }
|
|
63
|
+
entry.leases++;
|
|
64
|
+
let released = false;
|
|
65
|
+
return () => {
|
|
66
|
+
if (released) return;
|
|
67
|
+
released = true;
|
|
68
|
+
if (--entry.leases === 0) runtimeStores.delete(key);
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export function registerAssignmentAttempt(binding: AssignmentBinding, attemptId: string): void {
|
|
72
|
+
if (binding.version !== ASSIGNMENT_OUTCOMES_VERSION) throw new Error("Unsupported assignment outcome capability.");
|
|
73
|
+
withStore((store) => store.registerAssignment({ ...binding, attemptId }));
|
|
74
|
+
}
|
|
75
|
+
/** Called before any completion handoff, including callback:false and inactive parents. */
|
|
76
|
+
export function commitAssignmentTerminal(meta: RunMeta, recoveryFailure = false): AssignmentOutcomeRecord | null {
|
|
77
|
+
const binding = meta.assignment;
|
|
78
|
+
if (!binding) return null;
|
|
79
|
+
return withStore((store) => {
|
|
80
|
+
const existing = store.getAssignmentOutcome(binding.assignmentId);
|
|
81
|
+
if (existing) return existing;
|
|
82
|
+
if (!["failed", "completed", "killed", "lost"].includes(meta.status) || (meta.status === "completed" && meta.park)) return null;
|
|
83
|
+
const waits = store.listWaits({ owner: binding.owner }).filter((w) => w.origin?.assignmentRef === binding.assignmentId);
|
|
84
|
+
// A published automatic attempt's exit belongs to bounded recovery first.
|
|
85
|
+
if (!recoveryFailure && meta.status !== "killed" && meta.operations?.resumeLaunchToken && waits.some((w) => !w.acknowledgement && ["resuming", "ready"].includes(w.phase))) return null;
|
|
86
|
+
// A coherent attempt exit does not establish interpretation or completion.
|
|
87
|
+
if (meta.status === "completed" && waits.some((w) => !w.acknowledgement)) return null;
|
|
88
|
+
let report = null;
|
|
89
|
+
let invalidReport = "";
|
|
90
|
+
try { report = readAssignmentReport(meta); }
|
|
91
|
+
catch { if (meta.status === "completed") invalidReport = "Assignment completion is unverified: retained report evidence is unavailable or changed."; }
|
|
92
|
+
const complete = meta.status === "completed" && (report ? report.status === "complete"
|
|
93
|
+
: !invalidReport && waits.some((w) => w.acknowledgement?.disposition === "assignment-complete"));
|
|
94
|
+
const reportReason = report?.status === "incomplete" ? `Assignment incomplete: ${report.reason}`
|
|
95
|
+
+ (report.blocker ? ` Blocked (${report.blocker.kind}): ${report.blocker.reason}.` : "")
|
|
96
|
+
+ (report.remainingWork ? ` Remaining work: ${report.remainingWork.join("; ")}.` : "") : report?.reason;
|
|
97
|
+
try { return store.recordAssignmentOutcome({ ...binding, revision: 1,
|
|
98
|
+
outcome: complete ? "succeeded" : meta.status === "killed" ? "cancelled" : "failed",
|
|
99
|
+
reason: (meta.failureReason || invalidReport || (meta.status === "completed" && report ? reportReason : complete ? "Assigned work and required interpretation are complete."
|
|
100
|
+
: meta.status === "completed" && meta.assignmentReportRejection ? `Assignment report rejected: ${meta.assignmentReportRejection.reason}`
|
|
101
|
+
: meta.status === "completed" ? "Assignment completion is unverified: the attempt exited without an evidence-backed completion decision. Inspect retained output and continue unfinished work or report a concrete blocker."
|
|
102
|
+
: `Assignment ended ${meta.status}; retained attempt evidence is available.`)).slice(0, 8192),
|
|
103
|
+
processUncertain: meta.status === "lost" || typeof meta.exitCode !== "number"
|
|
104
|
+
|| waits.some((w) => w.dependencies.some((d) => d.terminalRevision === 0)
|
|
105
|
+
|| store.listResumeClaims({ waitId: w.waitId, generation: w.generation, state: "published" }).length > 0),
|
|
106
|
+
evidence: [{ kind: "log", ref: meta.logPath, summary: `Attempt ${meta.id}: ${meta.status}` },
|
|
107
|
+
...(report ? [{ kind: "artifact" as const, ref: meta.assignmentReport!.path, summary: report.reason },
|
|
108
|
+
...report.evidence.map((e) => ({ kind: "artifact" as const, ref: e.path, summary: e.explanation }))] : [])],
|
|
109
|
+
waits: waits.map((w) => ({ waitId: w.waitId, generation: w.generation, cancelEpoch: w.cancelEpoch })),
|
|
110
|
+
}); } catch (error) {
|
|
111
|
+
// A competing finalizer may commit after our initial read. The store
|
|
112
|
+
// still refuses rewrites; return only the same captured binding's winner.
|
|
113
|
+
// Borrowed runtime stores use a different coordinator module's StoreError constructor.
|
|
114
|
+
if (error instanceof Error && error.name === "StoreError" && "code" in error
|
|
115
|
+
&& error.code === "validation" && error.message === "A terminal assignment cannot be rewritten or reopened.") {
|
|
116
|
+
const winner = store.getAssignmentOutcome(binding.assignmentId);
|
|
117
|
+
const current = readMeta(meta.id);
|
|
118
|
+
if (winner && winner.assignmentId === binding.assignmentId && winner.revision === 1 && ownerDiff(winner.owner, binding.owner) === "none"
|
|
119
|
+
&& ownerDiff(winner.recipient, binding.recipient) === "none"
|
|
120
|
+
&& current?.assignment?.assignmentId === binding.assignmentId
|
|
121
|
+
&& ownerDiff(current.assignment.owner, binding.owner) === "none" && ownerDiff(current.assignment.recipient, binding.recipient) === "none"
|
|
122
|
+
&& current.sessionId === meta.sessionId && current.cwd === meta.cwd && current.pid === meta.pid && current.pidStartTime === meta.pidStartTime
|
|
123
|
+
&& isDeepStrictEqual(current.management, meta.management)
|
|
124
|
+
&& current.operations?.resumeLaunchToken === meta.operations?.resumeLaunchToken
|
|
125
|
+
&& winner.evidence.some(evidence => evidence.kind === "log" && evidence.ref === meta.logPath)) return winner;
|
|
126
|
+
}
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
export function readOutcome(meta: RunMeta): AssignmentOutcomeRecord | null {
|
|
132
|
+
return meta.assignment ? withStore((store) => store.getAssignmentOutcome(meta.assignment!.assignmentId)) : null;
|
|
133
|
+
}
|
|
134
|
+
export function assignmentRetainsEvidence(meta: RunMeta): boolean {
|
|
135
|
+
if (!meta.assignment) return false;
|
|
136
|
+
return withStore((store) => {
|
|
137
|
+
const outcome = store.getAssignmentOutcome(meta.assignment!.assignmentId);
|
|
138
|
+
if (!outcome) return false;
|
|
139
|
+
if (!outcome.disposition) return true;
|
|
140
|
+
const waits = store.listWaits({ owner: outcome.owner }).filter((w) => w.origin?.assignmentRef === outcome.assignmentId);
|
|
141
|
+
return waits.some((w) => store.listResumeClaims({ waitId: w.waitId, generation: w.generation, state: "published" }).length > 0);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
export function receiptOutcome(meta: RunMeta, entryId: string): void {
|
|
145
|
+
const record = readOutcome(meta);
|
|
146
|
+
if (record) withStore((store) => store.receiptAssignmentOutcome({ assignmentId: record.assignmentId, recipient: record.recipient, revision: record.revision, entryId }));
|
|
147
|
+
}
|
|
148
|
+
export function outcomeTranscriptReceipt(entries: readonly unknown[], eventId: string): string | null {
|
|
149
|
+
for (const raw of entries) {
|
|
150
|
+
const entry = raw as { id?: string; type?: string; customType?: string; details?: { completionEventIds?: unknown }; message?: { role?: string; customType?: string; details?: { completionEventIds?: unknown } } };
|
|
151
|
+
const message = entry.type === "custom_message" ? entry
|
|
152
|
+
: entry.type === "message" && entry.message?.role === "custom" ? entry.message : null;
|
|
153
|
+
if (message?.customType !== "background-completion-batch") continue;
|
|
154
|
+
const ids = message.details?.completionEventIds;
|
|
155
|
+
if (Array.isArray(ids) && ids.includes(eventId)) return entry.id ?? eventId;
|
|
156
|
+
}
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
function under(path: string, root: string): boolean {
|
|
160
|
+
const rel = relative(root, path);
|
|
161
|
+
return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
|
|
162
|
+
}
|
|
163
|
+
export function inspectOutcome(meta: RunMeta, input: { recipient: OwnerIdentity; branchIds?: readonly string[]; permissions?: PermissionSnapshot; operationId?: string; revision?: number; disposition?: "consumed" | "dismissed"; note?: string }) {
|
|
164
|
+
if (input.disposition && !Number.isInteger(input.revision)) throw new Error("Outcome disposition requires the exact outcome_revision.");
|
|
165
|
+
if (!meta.assignment) throw new Error("This run has no durable assignment outcome capability.");
|
|
166
|
+
return withStore((store) => {
|
|
167
|
+
const outcome = store.getAssignmentOutcome(meta.assignment!.assignmentId);
|
|
168
|
+
if (!outcome || outcome.recipient.sessionId !== input.recipient.sessionId || outcome.recipient.workspace !== input.recipient.workspace
|
|
169
|
+
|| (outcome.recipient.branchId && outcome.recipient.branchId !== input.recipient.branchId && !input.branchIds?.includes(outcome.recipient.branchId))) throw new Error("Outcome belongs to a different parent session or branch.");
|
|
170
|
+
const policy = input.permissions?.permissions;
|
|
171
|
+
if (meta.operations?.policy.sandbox && !policy) throw new Error("Current mandatory read authority is unavailable.");
|
|
172
|
+
const readable = (path: string): string => {
|
|
173
|
+
const real = realpathSync(path);
|
|
174
|
+
if (credentialFilePaths(homedir()).some((p) => {
|
|
175
|
+
try { return under(real, realpathSync(p)); } catch { return under(real, p); }
|
|
176
|
+
})) throw new Error("Credential evidence access is refused.");
|
|
177
|
+
const access = under(real, realpathSync(input.recipient.workspace)) ? policy?.projectFiles : policy?.outsideProject;
|
|
178
|
+
if (policy?.enabled && access !== "read" && access !== "read-write") throw new Error("Current file read permission refuses this evidence.");
|
|
179
|
+
return real;
|
|
180
|
+
};
|
|
181
|
+
const waits = store.listWaits({ owner: outcome.owner }).filter((w) => w.origin?.assignmentRef === outcome.assignmentId);
|
|
182
|
+
let logs: Array<{ ref: string; text: string }> = [];
|
|
183
|
+
if (input.operationId) {
|
|
184
|
+
if (!waits.some((w) => w.dependencies.some((d) => d.operationId === input.operationId))) throw new Error("Operation is not an assignment dependency.");
|
|
185
|
+
logs = store.listOperationEvidence(input.operationId).filter((e) => e.kind === "log").slice(0, 2).map((e) => {
|
|
186
|
+
if (!isAbsolute(e.ref)) throw new Error("Legacy dependency log has no verified absolute path; inspect its retained summary instead.");
|
|
187
|
+
const fd = openSync(readable(e.ref), constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
188
|
+
try {
|
|
189
|
+
const size = fstatSync(fd).size;
|
|
190
|
+
const bytes = Buffer.alloc(Math.min(size, 4096));
|
|
191
|
+
const count = readSync(fd, bytes, 0, bytes.length, Math.max(0, size - bytes.length));
|
|
192
|
+
return { ref: e.ref, text: bytes.subarray(0, count).toString("utf8") };
|
|
193
|
+
} finally { closeSync(fd); }
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
// Check retained references before recording an inspection, never a worker read.
|
|
197
|
+
const unavailableEvidence: string[] = [];
|
|
198
|
+
for (const pin of [...outcome.evidence, ...store.listEvidencePins({ waitId: outcome.eventId, generation: 1 })]) {
|
|
199
|
+
if ((pin.kind === "log" || pin.kind === "artifact") && isAbsolute(pin.ref)) {
|
|
200
|
+
try { readable(pin.ref); } catch (error) {
|
|
201
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
202
|
+
unavailableEvidence.push(pin.ref);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
const request = { assignmentId: outcome.assignmentId, recipient: outcome.recipient, revision: input.revision ?? outcome.revision };
|
|
207
|
+
const record = input.disposition
|
|
208
|
+
? store.consumeAssignmentOutcome({ ...request, disposition: input.disposition, note: input.note ?? "" })
|
|
209
|
+
: store.inspectAssignmentOutcome(request);
|
|
210
|
+
return { outcome: record, unavailableEvidence, dependencies: waits.slice(0, 20).map((w) => ({ waitId: w.waitId, generation: w.generation, phase: w.phase, acknowledgement: w.acknowledgement, dependencies: w.dependencies.slice(0, 20) })), logs };
|
|
211
|
+
});
|
|
212
|
+
}
|