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,212 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import {
|
|
4
|
+
actionableFailures, activeFailures, failureAttentionHandled, failureIdentity, formatFailureSummary, markFailureAttentionDelivered,
|
|
5
|
+
observeFailures, pendingAttentionNote, pendingAttentionRows, pendingFailureAttention, readCommandIntent, readFailureState,
|
|
6
|
+
type FailureEvent, type FailureState,
|
|
7
|
+
} from "./shared-failure-observations.js";
|
|
8
|
+
import { getCallbackBatcher } from "./shared-callback-batcher.js";
|
|
9
|
+
import { listMetasForOrigin, originOf, readMeta, taskDir } from "./registry.js";
|
|
10
|
+
import type { ActiveSessionProvider } from "./runtime.js";
|
|
11
|
+
import type { BackgroundTaskMeta } from "./types.js";
|
|
12
|
+
|
|
13
|
+
export const failurePath = (id: string): string => join(taskDir(id), "failures.jsonl");
|
|
14
|
+
export const failureSummary = (id: string): string => formatFailureSummary(readFailureState(failurePath(id)));
|
|
15
|
+
/**
|
|
16
|
+
* The failure summary plus whether anything needs action. A navigator row leads with failure text
|
|
17
|
+
* only when something does; the quiet history line never displaces the command (#332).
|
|
18
|
+
*/
|
|
19
|
+
export function failureView(id: string): { text: string; actionable: boolean } {
|
|
20
|
+
const state = readFailureState(failurePath(id));
|
|
21
|
+
return { text: formatFailureSummary(state), actionable: actionableFailures(state).length > 0 };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function recordFailure(meta: BackgroundTaskMeta, operation: string, summary: string, eventKey: unknown,
|
|
25
|
+
options: { category?: string; expected?: boolean; incomplete?: boolean; evidence?: string; at?: number } = {}): void {
|
|
26
|
+
observeFailures(failurePath(meta.id), [{
|
|
27
|
+
id: failureIdentity(meta.id, operation, eventKey), operation,
|
|
28
|
+
kind: options.incomplete ? "incomplete" : "failure", summary,
|
|
29
|
+
category: options.category, expected: options.expected, evidence: options.evidence,
|
|
30
|
+
at: options.at,
|
|
31
|
+
}]);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function recoverFailure(meta: BackgroundTaskMeta, operation: string, eventKey: unknown, at = Date.now()): void {
|
|
35
|
+
const path = failurePath(meta.id);
|
|
36
|
+
const active = readFailureState(path).observations[failureIdentity(operation)];
|
|
37
|
+
if (!active || active.status === "resolved") return;
|
|
38
|
+
observeFailures(path, [{
|
|
39
|
+
id: failureIdentity(meta.id, operation, "recovered", eventKey), operation,
|
|
40
|
+
kind: "recovered", incidents: [active.id], at,
|
|
41
|
+
}]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Validate `operation_id` / `expected_exit_codes` before anything is launched (#325), with the same
|
|
46
|
+
* validator the subagent task runtime's bash uses. Background commands are launched by the parent
|
|
47
|
+
* agent itself, so the declaration is trusted; a malformed one refuses the launch.
|
|
48
|
+
*/
|
|
49
|
+
export function readTaskIntent(params: { operation_id?: unknown; expected_exit_codes?: unknown }): Pick<BackgroundTaskMeta, "operationId" | "expectedExitCodes"> {
|
|
50
|
+
const { intent, error } = readCommandIntent({ operationId: params.operation_id, expectedExitCodes: params.expected_exit_codes },
|
|
51
|
+
{ operationId: "operation_id", expectedExitCodes: "expected_exit_codes" });
|
|
52
|
+
if (error) throw new Error(`Invalid command intent: ${error}. The task was not started.`);
|
|
53
|
+
return { ...(intent.operationId ? { operationId: intent.operationId } : {}), ...(intent.expectedExitCodes ? { expectedExitCodes: intent.expectedExitCodes } : {}) };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A structured exit code the caller declared intentional before launch. Signals and timeouts never are. */
|
|
57
|
+
export function isDeclaredExpectedExit(meta: BackgroundTaskMeta, exitCode: number | null | undefined): exitCode is number {
|
|
58
|
+
return typeof exitCode === "number" && exitCode !== 0 && (meta.expectedExitCodes ?? []).includes(exitCode);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Record a non-zero command exit, classified as expected only when its code was declared before launch. */
|
|
62
|
+
export function recordExitFailure(meta: BackgroundTaskMeta, operation: string, summary: string, exitCode: number | null | undefined, eventKey: unknown,
|
|
63
|
+
options: { at?: number; expected?: boolean } = {}): void {
|
|
64
|
+
const declared = isDeclaredExpectedExit(meta, exitCode);
|
|
65
|
+
recordFailure(meta, operation, declared ? `${summary} (declared expected)` : summary, eventKey,
|
|
66
|
+
{ category: "exit", expected: declared || options.expected === true, at: options.at });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function declaredOperation(meta: BackgroundTaskMeta): string | undefined {
|
|
70
|
+
return meta.operationId ? failureIdentity("bg-operation", meta.kind, meta.operationId, meta.cwd, meta.ssh?.target ?? null) : undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Recovery crosses tasks only within one owner (#325): the same non-empty session id, or, for
|
|
75
|
+
* sessionless tasks, the same spawning process (#312's sessionless ownership rule). The origin
|
|
76
|
+
* index alone treats two sessionless sessions in one cwd as one origin.
|
|
77
|
+
*/
|
|
78
|
+
function sameRecoveryOwner(a: BackgroundTaskMeta, b: BackgroundTaskMeta): boolean {
|
|
79
|
+
const sa = a.callbackOrigin?.sessionId, sb = b.callbackOrigin?.sessionId;
|
|
80
|
+
if (sa || sb) return Boolean(sa) && sa === sb;
|
|
81
|
+
return a.spawnPid === b.spawnPid && a.spawnPidStartTime === b.spawnPidStartTime;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* A task that succeeded with a declared `operationId` recovers the unresolved failures of earlier
|
|
86
|
+
* tasks of the same owner (session, or spawning process when sessionless) that declared the same operation (same kind, cwd, and SSH target) and
|
|
87
|
+
* failed before this task started: a modified retry as a new task. Observation gaps and expected
|
|
88
|
+
* failures are left alone; nothing is matched on command text.
|
|
89
|
+
*/
|
|
90
|
+
export function recoverDeclaredOperation(meta: BackgroundTaskMeta, at = Date.now()): void {
|
|
91
|
+
const operation = declaredOperation(meta);
|
|
92
|
+
if (!operation) return;
|
|
93
|
+
let earlier: BackgroundTaskMeta[];
|
|
94
|
+
try { earlier = listMetasForOrigin(originOf(meta)); } catch { return; }
|
|
95
|
+
for (const task of earlier) {
|
|
96
|
+
if (task.id === meta.id || task.startedAt >= meta.startedAt || declaredOperation(task) !== operation || !sameRecoveryOwner(task, meta)) continue;
|
|
97
|
+
const path = failurePath(task.id);
|
|
98
|
+
const events: FailureEvent[] = activeFailures(readFailureState(path))
|
|
99
|
+
.filter((x) => x.status === "unresolved" && x.category !== "observation-incomplete" && x.lastObservedAt <= meta.startedAt)
|
|
100
|
+
.map((x) => ({ id: failureIdentity(task.id, x.id, "recovered-by", meta.id), operation: x.operation, kind: "recovered", incidents: [x.id], at,
|
|
101
|
+
evidence: `task ${meta.id} (operation ${meta.operationId}) succeeded` }));
|
|
102
|
+
if (events.length) observeFailures(path, events);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function createFailureAttention(deliverUrgent?: (origin: BackgroundTaskMeta["callbackOrigin"], event: Parameters<ReturnType<typeof getCallbackBatcher>["deliverUrgent"]>[0]) => boolean | Promise<boolean>) {
|
|
107
|
+
const attentionTimers = new Map<string, ReturnType<typeof setTimeout>>();
|
|
108
|
+
let attentionSuspended = false;
|
|
109
|
+
/** Session shutdown: stop this instance's attention timers; the next session_start reschedules (#324). */
|
|
110
|
+
function suspendFailureAttention(): void {
|
|
111
|
+
attentionSuspended = true;
|
|
112
|
+
for (const timer of attentionTimers.values()) clearTimeout(timer);
|
|
113
|
+
attentionTimers.clear();
|
|
114
|
+
}
|
|
115
|
+
function resumeFailureAttention(): void {
|
|
116
|
+
attentionSuspended = false;
|
|
117
|
+
}
|
|
118
|
+
function stopFailureAttention(id: string): void {
|
|
119
|
+
const timer = attentionTimers.get(id);
|
|
120
|
+
if (timer) clearTimeout(timer);
|
|
121
|
+
attentionTimers.delete(id);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Model-facing fields of a running task's failure attention. The notification
|
|
126
|
+
* identity is per incident set; the inspect target is the real task id.
|
|
127
|
+
* Only the pending incidents are rows; earlier deliveries are counted, never repeated (#315).
|
|
128
|
+
*/
|
|
129
|
+
function failureAttentionFields(meta: BackgroundTaskMeta, state: FailureState, pending: { key: string; incidents: string[] }) {
|
|
130
|
+
const rows = pendingAttentionRows(state, pending.incidents);
|
|
131
|
+
const note = pendingAttentionNote(state, pending.incidents);
|
|
132
|
+
const due = pending.incidents.length;
|
|
133
|
+
return {
|
|
134
|
+
source: "background-task" as const,
|
|
135
|
+
id: `failure:${meta.id}:${pending.key}`,
|
|
136
|
+
inspectId: meta.id,
|
|
137
|
+
label: meta.name ?? meta.id,
|
|
138
|
+
status: "failure",
|
|
139
|
+
customType: "background-task-failure",
|
|
140
|
+
content: `Background task ${meta.id} is still running with ${due} failure observation${due === 1 ? "" : "s"} that need attention.${note ? ` ${note}` : ""}`,
|
|
141
|
+
detailTool: "bg_task_status" as const,
|
|
142
|
+
failureRows: rows,
|
|
143
|
+
incidentCount: rows.length || undefined,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Running incidents get one grace wake. Terminal incidents ride the completion callback. */
|
|
148
|
+
function scheduleFailureAttention(pi: ExtensionAPI, id: string, getActiveSession?: ActiveSessionProvider): void {
|
|
149
|
+
stopFailureAttention(id);
|
|
150
|
+
if (attentionSuspended) return;
|
|
151
|
+
const meta = readMeta(id);
|
|
152
|
+
if (!meta) {
|
|
153
|
+
const timer = setTimeout(() => scheduleFailureAttention(pi, id, getActiveSession), 1_000);
|
|
154
|
+
timer.unref();
|
|
155
|
+
attentionTimers.set(id, timer);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (meta.status !== "running" || meta.callback === false || meta.stopRequestedAt) return;
|
|
159
|
+
const state = readFailureState(failurePath(id));
|
|
160
|
+
const pending = pendingFailureAttention(state, Date.now());
|
|
161
|
+
if (pending) {
|
|
162
|
+
const deliver = (event: Parameters<ReturnType<typeof getCallbackBatcher>["deliverUrgent"]>[0]) => deliverUrgent ? deliverUrgent(meta.callbackOrigin,event) : getCallbackBatcher(pi).deliverUrgent(event);
|
|
163
|
+
const delivery = deliver({
|
|
164
|
+
receiptId: `background-failure:${meta.id}:${pending.key}`,
|
|
165
|
+
...failureAttentionFields(meta, state, pending),
|
|
166
|
+
isDelivered: () => {
|
|
167
|
+
const current = readMeta(id);
|
|
168
|
+
if (!current) throw new Error("Task metadata is unavailable; defer failure notification");
|
|
169
|
+
const now = readFailureState(failurePath(id));
|
|
170
|
+
return current.status !== "running" || failureAttentionHandled(now, pending.incidents);
|
|
171
|
+
},
|
|
172
|
+
getSuppressionReason: () => {
|
|
173
|
+
if (attentionSuspended) throw new Error("Failure attention instance is suspended; defer notification");
|
|
174
|
+
const current = readMeta(id);
|
|
175
|
+
if (!current) throw new Error("Task metadata is unavailable; defer failure notification");
|
|
176
|
+
if (current.status !== "running" || current.callback === false || current.stopRequestedAt) return "task is no longer running";
|
|
177
|
+
const origin = current.callbackOrigin;
|
|
178
|
+
const active = getActiveSession?.();
|
|
179
|
+
if (origin && (!active || origin.cwd !== active.cwd || (origin.sessionId && origin.sessionId !== active.sessionId))) return "callback origin is not active";
|
|
180
|
+
if (!origin && active && active.cwd !== current.cwd) return "callback cwd is not active";
|
|
181
|
+
return undefined;
|
|
182
|
+
},
|
|
183
|
+
onDelivered: (at) => { markFailureAttentionDelivered(failurePath(id), pending, at); },
|
|
184
|
+
});
|
|
185
|
+
void Promise.resolve(delivery).then((sent) => {
|
|
186
|
+
if (!sent && !attentionSuspended && (!readMeta(id) || readMeta(id)?.status === "running")) {
|
|
187
|
+
const timer = setTimeout(() => scheduleFailureAttention(pi, id, getActiveSession), 1_000);
|
|
188
|
+
timer.unref();
|
|
189
|
+
attentionTimers.set(id, timer);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const due = Object.values(state.observations)
|
|
195
|
+
.filter((x) => x.status === "unresolved" && state.delivered[x.id] === undefined)
|
|
196
|
+
.map((x) => x.firstObservedAt + 60_000 - Date.now());
|
|
197
|
+
if (due.length) {
|
|
198
|
+
const timer = setTimeout(() => scheduleFailureAttention(pi, id, getActiveSession), Math.max(1, Math.min(...due)));
|
|
199
|
+
timer.unref();
|
|
200
|
+
attentionTimers.set(id, timer);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return { suspendFailureAttention, resumeFailureAttention, stopFailureAttention, scheduleFailureAttention, failureAttentionFields };
|
|
205
|
+
}
|
|
206
|
+
/** Shared by the compatibility exports here and the legacy background runtime. */
|
|
207
|
+
export const defaultAttention = createFailureAttention();
|
|
208
|
+
export const { suspendFailureAttention, resumeFailureAttention, stopFailureAttention, scheduleFailureAttention, failureAttentionFields } = defaultAttention;
|
|
209
|
+
|
|
210
|
+
export function terminalFailureAttention(id: string) {
|
|
211
|
+
return pendingFailureAttention(readFailureState(failurePath(id)), Date.now(), { terminal: true });
|
|
212
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-background-tasks/src/goal-provider.ts. Do not edit directly.
|
|
2
|
+
import { listMetas, onMetaChanged } from "./registry.domain.mjs";
|
|
3
|
+
import { getObservedWaitHost } from "./observed-wait-client.domain.mjs";
|
|
4
|
+
import { isTerminalStatus } from "./types.domain.mjs";
|
|
5
|
+
import { backgroundTaskProgressAt, observeBackgroundTaskStall } from "./stall.domain.mjs";
|
|
6
|
+
import { backgroundGoalObservation, onBackgroundObservation } from "./work-observation.domain.mjs";
|
|
7
|
+
const GOAL_READY_EVENT = "pi-better-goal:ready";
|
|
8
|
+
const GOAL_REGISTER_PROVIDER_EVENT = "pi-better-goal:register-provider";
|
|
9
|
+
const readySubscriptions = new WeakSet();
|
|
10
|
+
export function collectBackgroundTaskGoalActivity(metas = listMetas(), ctx, now = Date.now(), durable = []) {
|
|
11
|
+
const items = [
|
|
12
|
+
...metas.filter((meta) => isVisibleGoalActivity(meta, ctx, now)).map(backgroundTaskToGoalItem),
|
|
13
|
+
...durable.filter((task) => isVisibleDurableGoalActivity(task, ctx, now)).map(durableTaskToGoalItem),
|
|
14
|
+
];
|
|
15
|
+
const deadlines = items.filter(item => item.terminal && typeof item.endedAt === "number")
|
|
16
|
+
.map(item => item.endedAt + TERMINAL_GOAL_ACTIVITY_RETENTION_MS).filter(deadline => deadline > now);
|
|
17
|
+
return {
|
|
18
|
+
providerId: "background-tasks",
|
|
19
|
+
label: "Background Tasks",
|
|
20
|
+
items,
|
|
21
|
+
nextDeadline: deadlines.length ? Math.min(...deadlines) : null,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function registerBackgroundTasksGoalProvider(pi) {
|
|
25
|
+
const emitProvider = () => {
|
|
26
|
+
pi.events?.emit(GOAL_REGISTER_PROVIDER_EVENT, {
|
|
27
|
+
id: "background-tasks",
|
|
28
|
+
label: "Background Tasks",
|
|
29
|
+
scope: "session",
|
|
30
|
+
activityVersion: 1,
|
|
31
|
+
getActivity: async (ctx, options) => {
|
|
32
|
+
const snapshot = await backgroundGoalObservation(pi, ctx, options?.cachedOnly);
|
|
33
|
+
if (!snapshot && options?.cachedOnly)
|
|
34
|
+
return { providerId: "background-tasks", coverage: "unverified", items: [], nextDeadline: null };
|
|
35
|
+
if (snapshot.status !== "ready")
|
|
36
|
+
throw new Error(snapshot.reason ?? "Background activity is unverified");
|
|
37
|
+
const durable = snapshot.rows.filter((row) => row.meta.durable).map((row) => row.meta);
|
|
38
|
+
const legacy = snapshot.rows.filter((row) => !row.meta.durable).map((row) => row.meta);
|
|
39
|
+
const activity = collectBackgroundTaskGoalActivity(legacy, ctx, Date.now(), durable);
|
|
40
|
+
const deadlines = [activity.nextDeadline, snapshot.nextDeadline].filter((value) => typeof value === "number" && value > Date.now());
|
|
41
|
+
return { ...activity, nextDeadline: deadlines.length ? Math.min(...deadlines) : null };
|
|
42
|
+
},
|
|
43
|
+
// A durable operation change must refresh Goal activity even though it
|
|
44
|
+
// never writes a mutable legacy registry meta.
|
|
45
|
+
onActivityChanged: (notify, ctx) => {
|
|
46
|
+
const offRuntime = onBackgroundObservation(pi, notify);
|
|
47
|
+
const offMeta = onMetaChanged(meta => {
|
|
48
|
+
if (ctx && meta && !belongsToGoalActivitySession(meta, ctx))
|
|
49
|
+
return;
|
|
50
|
+
notify();
|
|
51
|
+
});
|
|
52
|
+
const offDurable = getObservedWaitHost(pi)?.onDurableTaskChange(change => {
|
|
53
|
+
if (ctx && (change.workspace !== ctx.cwd || change.sessionId !== ctx.sessionManager.getSessionId()))
|
|
54
|
+
return;
|
|
55
|
+
if (ctx && change.branchId && !ctx.sessionManager.getBranch().some(entry => entry.id === change.branchId))
|
|
56
|
+
return;
|
|
57
|
+
notify();
|
|
58
|
+
});
|
|
59
|
+
return () => {
|
|
60
|
+
offRuntime();
|
|
61
|
+
offMeta();
|
|
62
|
+
offDurable?.();
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
if (!readySubscriptions.has(pi)) {
|
|
68
|
+
pi.events?.on?.(GOAL_READY_EVENT, emitProvider);
|
|
69
|
+
readySubscriptions.add(pi);
|
|
70
|
+
}
|
|
71
|
+
emitProvider();
|
|
72
|
+
}
|
|
73
|
+
const TERMINAL_GOAL_ACTIVITY_RETENTION_MS = 30_000;
|
|
74
|
+
function isVisibleGoalActivity(meta, ctx, now) {
|
|
75
|
+
if (meta.dismissedAt !== undefined)
|
|
76
|
+
return false;
|
|
77
|
+
if (ctx && !belongsToGoalActivitySession(meta, ctx))
|
|
78
|
+
return false;
|
|
79
|
+
if (meta.status === "running")
|
|
80
|
+
return true;
|
|
81
|
+
if (!ctx)
|
|
82
|
+
return true;
|
|
83
|
+
if (typeof meta.endedAt !== "number")
|
|
84
|
+
return true;
|
|
85
|
+
return now - meta.endedAt < TERMINAL_GOAL_ACTIVITY_RETENTION_MS;
|
|
86
|
+
}
|
|
87
|
+
function belongsToGoalActivitySession(meta, ctx) {
|
|
88
|
+
const active = getGoalActivityOrigin(ctx);
|
|
89
|
+
const origin = meta.callbackOrigin;
|
|
90
|
+
if (origin) {
|
|
91
|
+
if (origin.cwd !== active.cwd)
|
|
92
|
+
return false;
|
|
93
|
+
if (origin.branchId && !ctx.sessionManager.getBranch().some(entry => entry.id === origin.branchId))
|
|
94
|
+
return false;
|
|
95
|
+
if (origin.sessionId || active.sessionId)
|
|
96
|
+
return origin.sessionId === active.sessionId;
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
if (active.sessionId)
|
|
100
|
+
return false;
|
|
101
|
+
return meta.cwd === active.cwd;
|
|
102
|
+
}
|
|
103
|
+
function getGoalActivityOrigin(ctx) {
|
|
104
|
+
let sessionId;
|
|
105
|
+
try {
|
|
106
|
+
sessionId = ctx.sessionManager?.getSessionId();
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
sessionId = undefined;
|
|
110
|
+
}
|
|
111
|
+
return { cwd: ctx.cwd, sessionId };
|
|
112
|
+
}
|
|
113
|
+
function isVisibleDurableGoalActivity(task, ctx, now) {
|
|
114
|
+
if (task.dismissedAt !== undefined)
|
|
115
|
+
return false;
|
|
116
|
+
if (ctx) {
|
|
117
|
+
const active = getGoalActivityOrigin(ctx);
|
|
118
|
+
if (task.owner.workspace !== active.cwd)
|
|
119
|
+
return false;
|
|
120
|
+
if (task.owner.branchId && !ctx.sessionManager.getBranch().some(entry => entry.id === task.owner.branchId))
|
|
121
|
+
return false;
|
|
122
|
+
if (active.sessionId || task.owner.sessionId) {
|
|
123
|
+
if (task.owner.sessionId !== active.sessionId)
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (!task.terminal)
|
|
128
|
+
return true;
|
|
129
|
+
if (!ctx)
|
|
130
|
+
return true;
|
|
131
|
+
if (task.endedAt === undefined)
|
|
132
|
+
return true;
|
|
133
|
+
return now - task.endedAt < TERMINAL_GOAL_ACTIVITY_RETENTION_MS;
|
|
134
|
+
}
|
|
135
|
+
function durableTaskToGoalItem(task) {
|
|
136
|
+
const item = {
|
|
137
|
+
id: task.id,
|
|
138
|
+
status: task.status,
|
|
139
|
+
active: task.active,
|
|
140
|
+
terminal: task.terminal,
|
|
141
|
+
attention: task.attention,
|
|
142
|
+
startedAt: task.startedAt,
|
|
143
|
+
details: {
|
|
144
|
+
durable: true,
|
|
145
|
+
operationId: task.operationId,
|
|
146
|
+
kind: task.kind,
|
|
147
|
+
cwd: task.cwd,
|
|
148
|
+
command: task.command,
|
|
149
|
+
argv: task.argv,
|
|
150
|
+
logPath: task.logPaths.stdout,
|
|
151
|
+
lastProgressAt: task.endedAt ?? task.startedAt,
|
|
152
|
+
waits: task.waits.map((wait) => `${wait.waitId}:${wait.phase}`),
|
|
153
|
+
...(task.reason ? { reason: task.reason } : {}),
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
if (task.name !== undefined)
|
|
157
|
+
item.label = task.name;
|
|
158
|
+
if (task.endedAt !== undefined)
|
|
159
|
+
item.endedAt = task.endedAt;
|
|
160
|
+
return item;
|
|
161
|
+
}
|
|
162
|
+
function backgroundTaskToGoalItem(meta) {
|
|
163
|
+
const active = meta.status === "running";
|
|
164
|
+
const terminal = isTerminalStatus(meta.status);
|
|
165
|
+
const stall = observeBackgroundTaskStall(meta);
|
|
166
|
+
const unhealthy = active && stall.state === "stalled";
|
|
167
|
+
const attention = (terminal && meta.status !== "succeeded") || unhealthy;
|
|
168
|
+
const item = {
|
|
169
|
+
id: meta.id,
|
|
170
|
+
status: meta.status,
|
|
171
|
+
active,
|
|
172
|
+
unhealthy,
|
|
173
|
+
terminal,
|
|
174
|
+
attention,
|
|
175
|
+
startedAt: meta.startedAt,
|
|
176
|
+
details: {
|
|
177
|
+
kind: meta.kind,
|
|
178
|
+
callback: meta.callback !== false,
|
|
179
|
+
cwd: meta.cwd,
|
|
180
|
+
command: meta.command,
|
|
181
|
+
argv: meta.argv,
|
|
182
|
+
logPath: meta.logPath,
|
|
183
|
+
spawnPid: meta.spawnPid,
|
|
184
|
+
lastProgressAt: backgroundTaskProgressAt(meta),
|
|
185
|
+
stall: stall.state,
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
if (meta.name !== undefined)
|
|
189
|
+
item.label = meta.name;
|
|
190
|
+
if (meta.endedAt !== undefined)
|
|
191
|
+
item.endedAt = meta.endedAt;
|
|
192
|
+
return item;
|
|
193
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { listMetas, onMetaChanged } from "./registry.js";
|
|
3
|
+
import { getObservedWaitHost } from "./observed-wait-client.js";
|
|
4
|
+
import type { DurableTaskProjection } from "./observed-waits.js";
|
|
5
|
+
import type { BackgroundTaskMeta } from "./types.js";
|
|
6
|
+
import { isTerminalStatus } from "./types.js";
|
|
7
|
+
import { backgroundTaskProgressAt, observeBackgroundTaskStall } from "./stall.js";
|
|
8
|
+
import { backgroundGoalObservation, onBackgroundObservation } from "./work-observation.js";
|
|
9
|
+
|
|
10
|
+
const GOAL_READY_EVENT = "pi-better-goal:ready";
|
|
11
|
+
const GOAL_REGISTER_PROVIDER_EVENT = "pi-better-goal:register-provider";
|
|
12
|
+
const readySubscriptions = new WeakSet<ExtensionAPI>();
|
|
13
|
+
|
|
14
|
+
export interface GoalBackgroundWorkItem {
|
|
15
|
+
id: string;
|
|
16
|
+
label?: string;
|
|
17
|
+
status: string;
|
|
18
|
+
active: boolean;
|
|
19
|
+
unhealthy?: boolean;
|
|
20
|
+
terminal?: boolean;
|
|
21
|
+
attention?: boolean;
|
|
22
|
+
startedAt?: number;
|
|
23
|
+
endedAt?: number;
|
|
24
|
+
details?: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface GoalBackgroundProviderSnapshot {
|
|
28
|
+
providerId: string;
|
|
29
|
+
label?: string;
|
|
30
|
+
items: GoalBackgroundWorkItem[];
|
|
31
|
+
nextDeadline?: number | null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function collectBackgroundTaskGoalActivity(
|
|
35
|
+
metas: BackgroundTaskMeta[] = listMetas(),
|
|
36
|
+
ctx?: ExtensionContext,
|
|
37
|
+
now = Date.now(),
|
|
38
|
+
durable: readonly DurableTaskProjection[] = [],
|
|
39
|
+
): GoalBackgroundProviderSnapshot {
|
|
40
|
+
const items = [
|
|
41
|
+
...metas.filter((meta) => isVisibleGoalActivity(meta, ctx, now)).map(backgroundTaskToGoalItem),
|
|
42
|
+
...durable.filter((task) => isVisibleDurableGoalActivity(task, ctx, now)).map(durableTaskToGoalItem),
|
|
43
|
+
];
|
|
44
|
+
const deadlines = items.filter(item => item.terminal && typeof item.endedAt === "number")
|
|
45
|
+
.map(item => item.endedAt! + TERMINAL_GOAL_ACTIVITY_RETENTION_MS).filter(deadline => deadline > now);
|
|
46
|
+
return {
|
|
47
|
+
providerId: "background-tasks",
|
|
48
|
+
label: "Background Tasks",
|
|
49
|
+
items,
|
|
50
|
+
nextDeadline: deadlines.length ? Math.min(...deadlines) : null,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function registerBackgroundTasksGoalProvider(pi: ExtensionAPI): void {
|
|
55
|
+
const emitProvider = (): void => {
|
|
56
|
+
pi.events?.emit(GOAL_REGISTER_PROVIDER_EVENT, {
|
|
57
|
+
id: "background-tasks",
|
|
58
|
+
label: "Background Tasks",
|
|
59
|
+
scope: "session",
|
|
60
|
+
activityVersion: 1,
|
|
61
|
+
getActivity: async (ctx: ExtensionContext, options?: { cachedOnly?: boolean }) => {
|
|
62
|
+
const snapshot = await backgroundGoalObservation(pi, ctx, options?.cachedOnly);
|
|
63
|
+
if (!snapshot && options?.cachedOnly) return { providerId: "background-tasks", coverage: "unverified", items: [], nextDeadline: null };
|
|
64
|
+
if (snapshot.status !== "ready") throw new Error(snapshot.reason ?? "Background activity is unverified");
|
|
65
|
+
const durable = snapshot.rows.filter((row: any) => row.meta.durable).map((row: any) => row.meta);
|
|
66
|
+
const legacy = snapshot.rows.filter((row: any) => !row.meta.durable).map((row: any) => row.meta);
|
|
67
|
+
const activity = collectBackgroundTaskGoalActivity(legacy, ctx, Date.now(), durable);
|
|
68
|
+
const deadlines = [activity.nextDeadline, snapshot.nextDeadline].filter((value): value is number => typeof value === "number" && value > Date.now());
|
|
69
|
+
return { ...activity, nextDeadline: deadlines.length ? Math.min(...deadlines) : null };
|
|
70
|
+
},
|
|
71
|
+
// A durable operation change must refresh Goal activity even though it
|
|
72
|
+
// never writes a mutable legacy registry meta.
|
|
73
|
+
onActivityChanged: (notify: () => void, ctx?: ExtensionContext) => {
|
|
74
|
+
const offRuntime = onBackgroundObservation(pi, notify);
|
|
75
|
+
const offMeta = onMetaChanged(meta => {
|
|
76
|
+
if (ctx && meta && !belongsToGoalActivitySession(meta, ctx)) return;
|
|
77
|
+
notify();
|
|
78
|
+
});
|
|
79
|
+
const offDurable = getObservedWaitHost(pi)?.onDurableTaskChange(change => {
|
|
80
|
+
if (ctx && (change.workspace !== ctx.cwd || change.sessionId !== ctx.sessionManager.getSessionId())) return;
|
|
81
|
+
if (ctx && change.branchId && !ctx.sessionManager.getBranch().some(entry => entry.id === change.branchId)) return;
|
|
82
|
+
notify();
|
|
83
|
+
});
|
|
84
|
+
return () => {
|
|
85
|
+
offRuntime();
|
|
86
|
+
offMeta();
|
|
87
|
+
offDurable?.();
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
if (!readySubscriptions.has(pi)) {
|
|
94
|
+
pi.events?.on?.(GOAL_READY_EVENT, emitProvider);
|
|
95
|
+
readySubscriptions.add(pi);
|
|
96
|
+
}
|
|
97
|
+
emitProvider();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const TERMINAL_GOAL_ACTIVITY_RETENTION_MS = 30_000;
|
|
101
|
+
|
|
102
|
+
function isVisibleGoalActivity(meta: BackgroundTaskMeta, ctx: ExtensionContext | undefined, now: number): boolean {
|
|
103
|
+
if (meta.dismissedAt !== undefined) return false;
|
|
104
|
+
if (ctx && !belongsToGoalActivitySession(meta, ctx)) return false;
|
|
105
|
+
if (meta.status === "running") return true;
|
|
106
|
+
if (!ctx) return true;
|
|
107
|
+
if (typeof meta.endedAt !== "number") return true;
|
|
108
|
+
return now - meta.endedAt < TERMINAL_GOAL_ACTIVITY_RETENTION_MS;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function belongsToGoalActivitySession(meta: BackgroundTaskMeta, ctx: ExtensionContext): boolean {
|
|
112
|
+
const active = getGoalActivityOrigin(ctx);
|
|
113
|
+
const origin = meta.callbackOrigin;
|
|
114
|
+
if (origin) {
|
|
115
|
+
if (origin.cwd !== active.cwd) return false;
|
|
116
|
+
if (origin.branchId && !ctx.sessionManager.getBranch().some(entry => entry.id === origin.branchId)) return false;
|
|
117
|
+
if (origin.sessionId || active.sessionId) return origin.sessionId === active.sessionId;
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
if (active.sessionId) return false;
|
|
121
|
+
return meta.cwd === active.cwd;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function getGoalActivityOrigin(ctx: ExtensionContext) {
|
|
125
|
+
let sessionId: string | undefined;
|
|
126
|
+
try {
|
|
127
|
+
sessionId = ctx.sessionManager?.getSessionId();
|
|
128
|
+
} catch {
|
|
129
|
+
sessionId = undefined;
|
|
130
|
+
}
|
|
131
|
+
return { cwd: ctx.cwd, sessionId };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function isVisibleDurableGoalActivity(
|
|
135
|
+
task: DurableTaskProjection,
|
|
136
|
+
ctx: ExtensionContext | undefined,
|
|
137
|
+
now: number,
|
|
138
|
+
): boolean {
|
|
139
|
+
if (task.dismissedAt !== undefined) return false;
|
|
140
|
+
if (ctx) {
|
|
141
|
+
const active = getGoalActivityOrigin(ctx);
|
|
142
|
+
if (task.owner.workspace !== active.cwd) return false;
|
|
143
|
+
if (task.owner.branchId && !ctx.sessionManager.getBranch().some(entry => entry.id === task.owner.branchId)) return false;
|
|
144
|
+
if (active.sessionId || task.owner.sessionId) {
|
|
145
|
+
if (task.owner.sessionId !== active.sessionId) return false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (!task.terminal) return true;
|
|
149
|
+
if (!ctx) return true;
|
|
150
|
+
if (task.endedAt === undefined) return true;
|
|
151
|
+
return now - task.endedAt < TERMINAL_GOAL_ACTIVITY_RETENTION_MS;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function durableTaskToGoalItem(task: DurableTaskProjection): GoalBackgroundWorkItem {
|
|
155
|
+
const item: GoalBackgroundWorkItem = {
|
|
156
|
+
id: task.id,
|
|
157
|
+
status: task.status,
|
|
158
|
+
active: task.active,
|
|
159
|
+
terminal: task.terminal,
|
|
160
|
+
attention: task.attention,
|
|
161
|
+
startedAt: task.startedAt,
|
|
162
|
+
details: {
|
|
163
|
+
durable: true,
|
|
164
|
+
operationId: task.operationId,
|
|
165
|
+
kind: task.kind,
|
|
166
|
+
cwd: task.cwd,
|
|
167
|
+
command: task.command,
|
|
168
|
+
argv: task.argv,
|
|
169
|
+
logPath: task.logPaths.stdout,
|
|
170
|
+
lastProgressAt: task.endedAt ?? task.startedAt,
|
|
171
|
+
waits: task.waits.map((wait) => `${wait.waitId}:${wait.phase}`),
|
|
172
|
+
...(task.reason ? { reason: task.reason } : {}),
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
if (task.name !== undefined) item.label = task.name;
|
|
176
|
+
if (task.endedAt !== undefined) item.endedAt = task.endedAt;
|
|
177
|
+
return item;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function backgroundTaskToGoalItem(meta: BackgroundTaskMeta): GoalBackgroundWorkItem {
|
|
181
|
+
const active = meta.status === "running";
|
|
182
|
+
const terminal = isTerminalStatus(meta.status);
|
|
183
|
+
const stall = observeBackgroundTaskStall(meta);
|
|
184
|
+
const unhealthy = active && stall.state === "stalled";
|
|
185
|
+
const attention = (terminal && meta.status !== "succeeded") || unhealthy;
|
|
186
|
+
const item: GoalBackgroundWorkItem = {
|
|
187
|
+
id: meta.id,
|
|
188
|
+
status: meta.status,
|
|
189
|
+
active,
|
|
190
|
+
unhealthy,
|
|
191
|
+
terminal,
|
|
192
|
+
attention,
|
|
193
|
+
startedAt: meta.startedAt,
|
|
194
|
+
details: {
|
|
195
|
+
kind: meta.kind,
|
|
196
|
+
callback: meta.callback !== false,
|
|
197
|
+
cwd: meta.cwd,
|
|
198
|
+
command: meta.command,
|
|
199
|
+
argv: meta.argv,
|
|
200
|
+
logPath: meta.logPath,
|
|
201
|
+
spawnPid: meta.spawnPid,
|
|
202
|
+
lastProgressAt: backgroundTaskProgressAt(meta),
|
|
203
|
+
stall: stall.state,
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
if (meta.name !== undefined) item.label = meta.name;
|
|
207
|
+
if (meta.endedAt !== undefined) item.endedAt = meta.endedAt;
|
|
208
|
+
return item;
|
|
209
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-background-tasks/src/index.ts. Do not edit directly.
|
|
2
|
+
import { shouldRestoreWorkObservation } from "./shared-work-client.mjs";
|
|
3
|
+
import { initializeNavigatorPanels } from "./shared-navigator-panels.domain.mjs";
|
|
4
|
+
import { registerBackgroundTasksGoalProvider } from "./goal-provider.domain.mjs";
|
|
5
|
+
import { createBackgroundTasksNavigator } from "./navigator-provider.domain.mjs";
|
|
6
|
+
import { createManagedBackgroundFrontend } from "./managed-frontend.domain.mjs";
|
|
7
|
+
import { observeForegroundSandboxPolicy } from "./sandbox.domain.mjs";
|
|
8
|
+
import { registerTools } from "./tools.domain.mjs";
|
|
9
|
+
import { deliverBackgroundTasksPrompt } from "./prompt.domain.mjs";
|
|
10
|
+
import { closeBackgroundObservation } from "./work-observation.domain.mjs";
|
|
11
|
+
export default function backgroundTasksExtension(pi) {
|
|
12
|
+
// The frontend owns native UI/delivery only. Mechanical tools run in the
|
|
13
|
+
// fixed server service. Register their native definitions before the first turn.
|
|
14
|
+
const { host: observedWaits, proxy, ui } = createManagedBackgroundFrontend(pi);
|
|
15
|
+
const navigator = createBackgroundTasksNavigator(undefined, ui);
|
|
16
|
+
initializeNavigatorPanels(pi);
|
|
17
|
+
// Sections on a host that renders them; text only where it renders none.
|
|
18
|
+
// Returning a prompt on modern pi would set forceSystemPrompt, and the request
|
|
19
|
+
// would then carry a snapshot, so sections published after it never arrive.
|
|
20
|
+
pi.on("before_agent_start", (event) => deliverBackgroundTasksPrompt(event));
|
|
21
|
+
registerBackgroundTasksGoalProvider(pi);
|
|
22
|
+
navigator.ensureBackgroundTasksNavigatorProvider(pi);
|
|
23
|
+
// Subscribed at load so a sandbox extension that publishes later is heard, and
|
|
24
|
+
// asked for a snapshot in case one published before this extension existed.
|
|
25
|
+
observeForegroundSandboxPolicy(pi);
|
|
26
|
+
// Registered before registerTools(pi), so this runs before running tasks are resumed.
|
|
27
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
28
|
+
registerBackgroundTasksGoalProvider(pi);
|
|
29
|
+
navigator.ensureBackgroundTasksNavigator(ctx);
|
|
30
|
+
});
|
|
31
|
+
pi.on("session_before_switch", async () => {
|
|
32
|
+
closeBackgroundObservation(pi);
|
|
33
|
+
observedWaits.close();
|
|
34
|
+
navigator.clearBackgroundTasksNavigatorSession();
|
|
35
|
+
});
|
|
36
|
+
pi.on("session_shutdown", async (_event, ctx) => {
|
|
37
|
+
closeBackgroundObservation(pi);
|
|
38
|
+
// /reload, session replacement, and quit load a fresh instance; stop this one's timers (#324).
|
|
39
|
+
observedWaits.close();
|
|
40
|
+
navigator.clearBackgroundTasksNavigatorSession();
|
|
41
|
+
});
|
|
42
|
+
registerTools(proxy, undefined, navigator.refreshBackgroundTasksNavigator, { resumeLocal: false });
|
|
43
|
+
// Registered after registerTools so the callback batcher has its session
|
|
44
|
+
// context before a reconciled delivery can enqueue a parent notification.
|
|
45
|
+
pi.on("session_start", (event, ctx) => {
|
|
46
|
+
observedWaits.start(ctx, shouldRestoreWorkObservation(event, ctx.sessionManager));
|
|
47
|
+
});
|
|
48
|
+
// A fork or branch navigation does not restart the session, but it changes
|
|
49
|
+
// which continuation may receive a queued callback. Update the host snapshot
|
|
50
|
+
// on the same event the callback batcher uses.
|
|
51
|
+
pi.on("session_tree", async (_event, ctx) => {
|
|
52
|
+
observedWaits.noteParentContext(ctx);
|
|
53
|
+
});
|
|
54
|
+
}
|