pi-better-server 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -3
- package/scripts/copy-pi-test-providers.mjs +10 -0
- package/scripts/event-publication/README.md +26 -0
- package/scripts/event-publication/commit.mjs +21 -0
- package/scripts/event-publication/measure.mjs +37 -5
- package/scripts/event-publication/writer.mjs +3 -8
- package/scripts/measure-full-runtime/frontend.ts +10 -2
- package/scripts/measure-full-runtime/probe.mjs +4 -2
- package/scripts/measure-full-runtime/recovery-trace-loader.mjs +51 -0
- package/scripts/measure-full-runtime/recovery-trace.mjs +16 -0
- package/scripts/measure-full-runtime.mjs +2 -0
- package/scripts/measure-shared-reads.mjs +2 -1
- package/scripts/private-runtime/package-lock.json +18 -0
- package/scripts/private-runtime/package.json +4 -1
- package/scripts/source-provenance.mjs +2 -2
- package/scripts/test-on-pi.sh +2 -9
- package/src/handshake.ts +1 -1
- package/src/hosted-session.ts +32 -4
- package/src/maintenance.ts +35 -7
- package/src/registry.ts +28 -4
- package/src/runtime/attempt-invalidation.ts +54 -0
- package/src/runtime/background-history.ts +151 -45
- package/src/runtime/background-policy.ts +9 -4
- package/src/runtime/background-tools.ts +181 -27
- package/src/runtime/background.ts +365 -70
- package/src/runtime/cancellation.ts +28 -7
- package/src/runtime/catalog-sources.ts +199 -0
- package/src/runtime/catalog.ts +53 -21
- package/src/runtime/client.ts +22 -2
- package/src/runtime/domain/assignment-inbox.mjs +119 -0
- package/src/runtime/domain/assignment-observation.d.mts +1 -1
- package/src/runtime/domain/assignment-observation.mjs +43 -35
- package/src/runtime/domain/background/process-identity.mjs +20 -2
- package/src/runtime/domain/background/process.mjs +52 -14
- package/src/runtime/domain/background/registry.mjs +61 -3
- package/src/runtime/domain/background/supervisor/store.mjs +3 -3
- package/src/runtime/domain/background/supervisor/supervisor.mjs +9 -3
- package/src/runtime/domain/background/types.mjs +1 -0
- package/src/runtime/domain/background-service/adapter-contract.domain.mjs +1 -1
- package/src/runtime/domain/background-service/adapter-contract.ts +1 -1
- package/src/runtime/domain/background-service/goal-provider.domain.mjs +35 -16
- package/src/runtime/domain/background-service/goal-provider.ts +31 -16
- package/src/runtime/domain/background-service/index.domain.mjs +25 -9
- package/src/runtime/domain/background-service/index.ts +25 -9
- package/src/runtime/domain/background-service/managed-authority.domain.mjs +6 -3
- package/src/runtime/domain/background-service/managed-authority.ts +5 -3
- package/src/runtime/domain/background-service/managed-client.domain.mjs +21 -7
- package/src/runtime/domain/background-service/managed-client.ts +20 -7
- package/src/runtime/domain/background-service/managed-frontend.domain.mjs +159 -19
- package/src/runtime/domain/background-service/managed-frontend.ts +135 -19
- package/src/runtime/domain/background-service/navigator-provider.domain.mjs +21 -5
- package/src/runtime/domain/background-service/navigator-provider.ts +19 -5
- package/src/runtime/domain/background-service/observed-wait-client.domain.mjs +6 -0
- package/src/runtime/domain/background-service/observed-wait-client.ts +10 -0
- package/src/runtime/domain/background-service/observed-waits.domain.mjs +372 -57
- package/src/runtime/domain/background-service/observed-waits.ts +321 -53
- package/src/runtime/domain/background-service/process-identity.domain.mjs +20 -2
- package/src/runtime/domain/background-service/process-identity.ts +18 -2
- package/src/runtime/domain/background-service/process.domain.mjs +52 -14
- package/src/runtime/domain/background-service/process.ts +48 -14
- package/src/runtime/domain/background-service/registry.domain.mjs +61 -3
- package/src/runtime/domain/background-service/registry.ts +53 -5
- package/src/runtime/domain/background-service/review-settings.domain.mjs +16 -0
- package/src/runtime/domain/background-service/review-settings.ts +18 -0
- package/src/runtime/domain/background-service/runtime.domain.mjs +40 -86
- package/src/runtime/domain/background-service/runtime.ts +27 -82
- package/src/runtime/domain/background-service/sandbox.domain.mjs +14 -15
- package/src/runtime/domain/background-service/sandbox.ts +14 -11
- package/src/runtime/domain/background-service/shared-callback-batcher.domain.mjs +8 -1
- package/src/runtime/domain/background-service/shared-callback-batcher.ts +11 -2
- package/src/runtime/domain/background-service/shared-navigator-panels.domain.mjs +24 -2
- package/src/runtime/domain/background-service/shared-navigator-panels.ts +26 -4
- package/src/runtime/domain/background-service/shared-navigator.domain.mjs +273 -41
- package/src/runtime/domain/background-service/shared-navigator.ts +244 -40
- package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-inbox.mjs +144 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-observation.mjs +53 -41
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.ts +73 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.ts +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.domain.mjs +11 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.ts +14 -3
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.domain.mjs +4 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.ts +5 -3
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.domain.mjs +44 -4
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.ts +50 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.domain.mjs +7 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.ts +9 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.domain.mjs +12 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.ts +12 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.domain.mjs +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.ts +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.domain.mjs +42 -21
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.ts +40 -24
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +26 -4
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +40 -8
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.domain.mjs +23 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.ts +24 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.domain.mjs +1 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.ts +5 -1
- package/src/runtime/domain/background-service/shared-sandbox-core.ts +1 -1
- package/src/runtime/domain/background-service/shared-work-client.mjs +174 -7
- package/src/runtime/domain/background-service/stall.domain.mjs +5 -3
- package/src/runtime/domain/background-service/stall.ts +7 -4
- package/src/runtime/domain/background-service/supervised-progress.domain.mjs +42 -0
- package/src/runtime/domain/background-service/supervised-progress.ts +43 -0
- package/src/runtime/domain/background-service/supervisor/README.md +1 -4
- package/src/runtime/domain/background-service/supervisor/emit-runner.mjs +1 -0
- package/src/runtime/domain/background-service/supervisor/generated/process-identity.mjs +20 -2
- package/src/runtime/domain/background-service/supervisor/generated/process.mjs +52 -14
- package/src/runtime/domain/background-service/supervisor/generated/runner.mjs +47 -4
- package/src/runtime/domain/background-service/supervisor/generated/store.mjs +3 -3
- package/src/runtime/domain/background-service/supervisor/generated/watch-fingerprint.mjs +69 -0
- package/src/runtime/domain/background-service/supervisor/runner.domain.mjs +47 -4
- package/src/runtime/domain/background-service/supervisor/runner.ts +38 -3
- package/src/runtime/domain/background-service/supervisor/store.domain.mjs +3 -3
- package/src/runtime/domain/background-service/supervisor/store.ts +3 -3
- package/src/runtime/domain/background-service/supervisor/supervisor.domain.mjs +9 -3
- package/src/runtime/domain/background-service/supervisor/supervisor.ts +6 -3
- package/src/runtime/domain/background-service/task-diagnostics.domain.mjs +1 -1
- package/src/runtime/domain/background-service/task-diagnostics.ts +1 -1
- package/src/runtime/domain/background-service/tools.domain.mjs +53 -40
- package/src/runtime/domain/background-service/tools.ts +67 -54
- package/src/runtime/domain/background-service/types.domain.mjs +1 -0
- package/src/runtime/domain/background-service/types.ts +7 -3
- package/src/runtime/domain/background-service/watch-fingerprint.domain.mjs +67 -0
- package/src/runtime/domain/background-service/watch-fingerprint.ts +70 -0
- package/src/runtime/domain/background-service/work-observation.domain.mjs +46 -20
- package/src/runtime/domain/background-service/work-observation.ts +46 -19
- package/src/runtime/domain/catalog/catalog-store.d.mts +9 -1
- package/src/runtime/domain/catalog/catalog-store.mjs +20 -22
- package/src/runtime/domain/coordinator/src/assignment-changes.mjs +75 -0
- package/src/runtime/domain/coordinator/src/assignment-outcomes.mjs +2 -0
- package/src/runtime/domain/coordinator/src/background-requests.mjs +11 -2
- package/src/runtime/domain/coordinator/src/discovery.mjs +4 -2
- package/src/runtime/domain/coordinator/src/operations.mjs +44 -4
- package/src/runtime/domain/coordinator/src/outbox.mjs +7 -0
- package/src/runtime/domain/coordinator/src/result-supervision.mjs +12 -0
- package/src/runtime/domain/coordinator/src/rows.mjs +2 -0
- package/src/runtime/domain/coordinator/src/schema.mjs +42 -21
- package/src/runtime/domain/coordinator/src/store.mjs +26 -4
- package/src/runtime/domain/coordinator/src/subagent-launch.mjs +23 -1
- package/src/runtime/domain/coordinator/src/types.mjs +1 -1
- package/src/runtime/domain/health-observation.d.mts +3 -1
- package/src/runtime/domain/health-observation.mjs +189 -190
- package/src/runtime/domain/log-cursor.d.mts +2 -0
- package/src/runtime/domain/log-cursor.mjs +85 -16
- package/src/runtime/domain/log-paths.mjs +8 -1
- package/src/runtime/domain/parse.d.mts +4 -1
- package/src/runtime/domain/parse.mjs +58 -9
- package/src/runtime/domain/sandbox-policy/README.md +63 -65
- package/src/runtime/domain/sandbox-policy/commands.domain.mjs +11 -8
- package/src/runtime/domain/sandbox-policy/commands.ts +12 -7
- package/src/runtime/domain/sandbox-policy/index.domain.mjs +53 -9
- package/src/runtime/domain/sandbox-policy/index.ts +52 -9
- package/src/runtime/domain/sandbox-policy/package.json +1 -1
- package/src/runtime/domain/sandbox-policy/permission-settings.domain.mjs +5 -2
- package/src/runtime/domain/sandbox-policy/permission-settings.ts +9 -2
- package/src/runtime/domain/sandbox-policy/permissions-page.domain.mjs +56 -137
- package/src/runtime/domain/sandbox-policy/permissions-page.ts +52 -130
- package/src/runtime/domain/sandbox-policy/permissions.domain.mjs +1 -6
- package/src/runtime/domain/sandbox-policy/permissions.ts +1 -6
- package/src/runtime/domain/sandbox-policy/shared-sandbox-core.ts +1 -1
- package/src/runtime/domain/sandbox-policy/shared-task-exec.domain.mjs +14 -1
- package/src/runtime/domain/sandbox-policy/shared-task-exec.ts +12 -1
- package/src/runtime/domain/sandbox-policy/shared-task-process-identity.domain.mjs +140 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-identity.ts +126 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-list.domain.mjs +3 -2
- package/src/runtime/domain/sandbox-policy/shared-task-process-list.ts +8 -2
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.domain.mjs +4 -3
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.ts +5 -3
- package/src/runtime/domain/sandbox-policy/shared-task-tools.domain.mjs +8 -5
- package/src/runtime/domain/sandbox-policy/shared-task-tools.ts +8 -5
- package/src/runtime/domain/session-store.mjs +7 -0
- package/src/runtime/domain/subagents/README.md +13 -11
- package/src/runtime/domain/subagents/assignment-outcomes.domain.mjs +10 -7
- package/src/runtime/domain/subagents/assignment-outcomes.ts +9 -6
- package/src/runtime/domain/subagents/assignment-report.domain.mjs +109 -24
- package/src/runtime/domain/subagents/assignment-report.ts +103 -19
- package/src/runtime/domain/subagents/batch.mjs +13 -5
- package/src/runtime/domain/subagents/catalog-host-admission.domain.mjs +21 -3
- package/src/runtime/domain/subagents/catalog-host-admission.ts +19 -3
- package/src/runtime/domain/subagents/catalog-preferences.ts +1 -1
- package/src/runtime/domain/subagents/catalog-resolver.domain.mjs +35 -1
- package/src/runtime/domain/subagents/catalog-resolver.ts +35 -1
- package/src/runtime/domain/subagents/catalog-store.domain.mjs +20 -22
- package/src/runtime/domain/subagents/catalog-store.ts +27 -20
- package/src/runtime/domain/subagents/child-apply-patch.domain.mjs +13 -0
- package/src/runtime/domain/subagents/child-apply-patch.ts +13 -0
- package/src/runtime/domain/subagents/child-dependencies.mjs +27 -15
- package/src/runtime/domain/subagents/child-operations.domain.mjs +80 -2
- package/src/runtime/domain/subagents/child-operations.ts +80 -1
- package/src/runtime/domain/subagents/child-preflight.mjs +9 -2
- package/src/runtime/domain/subagents/child-process-list.domain.mjs +7 -0
- package/src/runtime/domain/subagents/child-process-list.ts +8 -0
- package/src/runtime/domain/subagents/cleanup.domain.mjs +11 -2
- package/src/runtime/domain/subagents/cleanup.ts +10 -2
- package/src/runtime/domain/subagents/config.domain.mjs +54 -2
- package/src/runtime/domain/subagents/config.ts +53 -3
- package/src/runtime/domain/subagents/continuation-authority.domain.mjs +5 -1
- package/src/runtime/domain/subagents/continuation-authority.ts +3 -1
- package/src/runtime/domain/subagents/continuation-runtime.domain.mjs +89 -0
- package/src/runtime/domain/subagents/continuation-runtime.ts +88 -0
- package/src/runtime/domain/subagents/continuation.domain.mjs +4 -2
- package/src/runtime/domain/subagents/continuation.ts +4 -2
- package/src/runtime/domain/subagents/extensions.mjs +11 -13
- package/src/runtime/domain/subagents/failures.domain.mjs +11 -2
- package/src/runtime/domain/subagents/failures.ts +10 -2
- package/src/runtime/domain/subagents/finalization.domain.mjs +16 -1
- package/src/runtime/domain/subagents/finalization.ts +21 -1
- package/src/runtime/domain/subagents/goal-provider.domain.mjs +44 -2
- package/src/runtime/domain/subagents/goal-provider.ts +44 -2
- package/src/runtime/domain/subagents/health-observation.domain.mjs +189 -190
- package/src/runtime/domain/subagents/health-observation.ts +43 -48
- package/src/runtime/domain/subagents/index.domain.mjs +457 -182
- package/src/runtime/domain/subagents/index.ts +417 -155
- package/src/runtime/domain/subagents/isolated-workspace.domain.mjs +515 -0
- package/src/runtime/domain/subagents/isolated-workspace.ts +557 -0
- package/src/runtime/domain/subagents/launch-context.domain.mjs +24 -0
- package/src/runtime/domain/subagents/launch-context.ts +23 -0
- package/src/runtime/domain/subagents/launch-digest.mjs +6 -0
- package/src/runtime/domain/subagents/list.mjs +2 -2
- package/src/runtime/domain/subagents/log-cursor.domain.mjs +85 -16
- package/src/runtime/domain/subagents/log-cursor.ts +91 -15
- package/src/runtime/domain/subagents/managed-launch-bootstrap.mjs +2 -2
- package/src/runtime/domain/subagents/managed-launch-client.domain.mjs +27 -7
- package/src/runtime/domain/subagents/managed-launch-client.ts +28 -8
- package/src/runtime/domain/subagents/managed-launch-host.domain.mjs +222 -14
- package/src/runtime/domain/subagents/managed-launch-host.ts +168 -15
- package/src/runtime/domain/subagents/managed-launch-journal.mjs +1 -5
- package/src/runtime/domain/subagents/managed-launch-port.ts +4 -0
- package/src/runtime/domain/subagents/operation-bridge-types.domain.mjs +27 -2
- package/src/runtime/domain/subagents/operation-bridge-types.ts +27 -2
- package/src/runtime/domain/subagents/output-payload.domain.mjs +24 -9
- package/src/runtime/domain/subagents/output-payload.ts +26 -12
- package/src/runtime/domain/subagents/owned-exit.domain.mjs +12 -0
- package/src/runtime/domain/subagents/owned-exit.ts +12 -0
- package/src/runtime/domain/subagents/package.json +4 -2
- package/src/runtime/domain/subagents/parse.domain.mjs +58 -9
- package/src/runtime/domain/subagents/parse.ts +57 -10
- package/src/runtime/domain/subagents/permission-policy.domain.mjs +32 -8
- package/src/runtime/domain/subagents/permission-policy.ts +41 -8
- package/src/runtime/domain/subagents/process-identity.mjs +33 -0
- package/src/runtime/domain/subagents/registry.domain.mjs +71 -51
- package/src/runtime/domain/subagents/registry.ts +77 -38
- package/src/runtime/domain/subagents/retained-result.domain.mjs +56 -0
- package/src/runtime/domain/subagents/retained-result.ts +65 -0
- package/src/runtime/domain/subagents/session-selection.domain.mjs +3 -1
- package/src/runtime/domain/subagents/session-selection.ts +2 -1
- package/src/runtime/domain/subagents/session-store.domain.mjs +7 -0
- package/src/runtime/domain/subagents/session-store.ts +9 -0
- package/src/runtime/domain/subagents/settings-page.domain.mjs +151 -107
- package/src/runtime/domain/subagents/settings-page.ts +147 -108
- package/src/runtime/domain/subagents/shared-callback-batcher.domain.mjs +8 -1
- package/src/runtime/domain/subagents/shared-callback-batcher.ts +11 -2
- package/src/runtime/domain/subagents/shared-catalog.domain.mjs +28 -29
- package/src/runtime/domain/subagents/shared-catalog.ts +29 -21
- package/src/runtime/domain/subagents/shared-navigator-panels.domain.mjs +24 -2
- package/src/runtime/domain/subagents/shared-navigator-panels.ts +26 -4
- package/src/runtime/domain/subagents/shared-navigator.domain.mjs +273 -41
- package/src/runtime/domain/subagents/shared-navigator.ts +244 -40
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-inbox.mjs +144 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-observation.mjs +53 -41
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.ts +73 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.ts +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.domain.mjs +11 -2
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.ts +14 -3
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.domain.mjs +4 -2
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.ts +5 -3
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.domain.mjs +44 -4
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.ts +50 -2
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.domain.mjs +7 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.ts +9 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.domain.mjs +12 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.ts +12 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.domain.mjs +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.ts +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.domain.mjs +42 -21
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.ts +40 -24
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +26 -4
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +40 -8
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.domain.mjs +23 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.ts +24 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.domain.mjs +1 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.ts +5 -1
- package/src/runtime/domain/subagents/shared-sandbox-core.ts +1 -1
- package/src/runtime/domain/subagents/shared-task-exec.domain.mjs +14 -1
- package/src/runtime/domain/subagents/shared-task-exec.ts +12 -1
- package/src/runtime/domain/subagents/shared-task-process-identity.domain.mjs +140 -0
- package/src/runtime/domain/subagents/shared-task-process-identity.ts +126 -0
- package/src/runtime/domain/subagents/shared-task-process-list.domain.mjs +3 -2
- package/src/runtime/domain/subagents/shared-task-process-list.ts +8 -2
- package/src/runtime/domain/subagents/shared-task-sandbox.domain.mjs +4 -3
- package/src/runtime/domain/subagents/shared-task-sandbox.ts +5 -3
- package/src/runtime/domain/subagents/shared-task-tools.domain.mjs +8 -5
- package/src/runtime/domain/subagents/shared-task-tools.ts +8 -5
- package/src/runtime/domain/subagents/shared-work-client.mjs +174 -7
- package/src/runtime/domain/subagents/subagent-tools.domain.mjs +22 -38
- package/src/runtime/domain/subagents/subagent-tools.ts +28 -34
- package/src/runtime/domain/subagents/task-guard.domain.mjs +14 -1
- package/src/runtime/domain/subagents/task-guard.ts +13 -1
- package/src/runtime/domain/subagents/task-policy.domain.mjs +3 -2
- package/src/runtime/domain/subagents/task-policy.ts +8 -2
- package/src/runtime/domain/subagents/timing.domain.mjs +10 -1
- package/src/runtime/domain/subagents/timing.ts +10 -1
- package/src/runtime/domain/subagents/tools.domain.mjs +4 -8
- package/src/runtime/domain/subagents/tools.ts +4 -7
- package/src/runtime/domain/subagents/work-observation.domain.mjs +102 -17
- package/src/runtime/domain/subagents/work-observation.ts +91 -17
- package/src/runtime/domain/subagents/worker-operations-host.domain.mjs +9 -4
- package/src/runtime/domain/subagents/worker-operations-host.ts +12 -4
- package/src/runtime/domain/subagents/worker-waits.domain.mjs +89 -35
- package/src/runtime/domain/subagents/worker-waits.ts +93 -34
- package/src/runtime/domain/subagents/workspace-files.domain.mjs +103 -0
- package/src/runtime/domain/subagents/workspace-files.ts +114 -0
- package/src/runtime/domain/subagents/workspace-scope.domain.d.mts +38 -0
- package/src/runtime/domain/subagents/workspace-scope.domain.mjs +5 -0
- package/src/runtime/domain/subagents/workspace-scope.ts +6 -0
- package/src/runtime/domain/subagents/worktree-feedback.domain.mjs +55 -0
- package/src/runtime/domain/subagents/worktree-feedback.ts +77 -0
- package/src/runtime/health-config.ts +27 -11
- package/src/runtime/log-checkpoints.ts +117 -0
- package/src/runtime/mutation-store.ts +5 -4
- package/src/runtime/queries.ts +25 -2
- package/src/runtime/query-executor.ts +149 -28
- package/src/runtime/query-worker.mjs +106 -21
- package/src/runtime/read-model.ts +849 -121
- package/src/runtime/read-watchdog-probe.ts +4 -0
- package/src/runtime/result-supervision.ts +188 -16
- package/src/runtime/root.ts +5 -2
- package/src/runtime/source-watch.ts +175 -0
- package/src/runtime/subagent-launch.ts +11 -4
- package/src/runtime/work-budget.ts +130 -0
- package/src/runtime/work-client.d.mts +8 -0
- package/src/runtime/work-client.mjs +150 -7
- package/src/server.ts +104 -23
- package/src/session-activity.ts +26 -4
- package/src/version.ts +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-background-tasks/src/runtime.ts. Do not edit directly.
|
|
2
|
-
import {
|
|
2
|
+
import { WATCH_FINGERPRINT_VERSION, watchOutcomeFingerprint } from "./watch-fingerprint.domain.mjs";
|
|
3
3
|
import { readFileSync, statSync } from "node:fs";
|
|
4
4
|
import { appendLine, appendTaskOutput, appendWatchResult, retainLogTail, resolveMaxLogBytes } from "./logs.domain.mjs";
|
|
5
5
|
import { evaluateCondition, validateCondition } from "./conditions.domain.mjs";
|
|
6
|
-
import { parseStepGateFailure, processExists, runCommandOnce, spawnCommand, STEP_GATE_COMMAND_ENV, stepGateScript, stopProcessGroup } from "./process.domain.mjs";
|
|
6
|
+
import { commandExecution, parseStepGateFailure, processExists, resolveWindowsLaunchShell, runCommandOnce, spawnCommand, STEP_GATE_COMMAND_ENV, stepGateScript, stopProcessGroup } from "./process.domain.mjs";
|
|
7
7
|
import { currentProcessStartToken, readProcessStartToken } from "./process-identity.domain.mjs";
|
|
8
8
|
import { DEFAULT_TMUX_BOOTSTRAP_TIMEOUT_MS, expandSshRemoteTaskPreset } from "./remote-task-preset.domain.mjs";
|
|
9
9
|
import { ensureTaskDir, logPathFor, nextTaskId, readMeta, sandboxProfilePathFor, writeMeta } from "./registry.domain.mjs";
|
|
@@ -14,16 +14,16 @@ import { markFailureAttentionDelivered } from "./shared-failure-observations.dom
|
|
|
14
14
|
import { getCallbackBatcher } from "./shared-callback-batcher.domain.mjs";
|
|
15
15
|
import { formatCallbackFacts } from "./output.domain.mjs";
|
|
16
16
|
import { observeTaskStallAttention } from "./stall-attention.domain.mjs";
|
|
17
|
-
import { isTerminalStatus } from "./types.domain.mjs";
|
|
17
|
+
import { FIRST_WATCH_CHECK_WAIT_MS, isTerminalStatus } from "./types.domain.mjs";
|
|
18
18
|
export const DEFAULT_WATCH_TIMEOUT_SECONDS = 15 * 60;
|
|
19
19
|
/** Consecutive blind checks (exit 0, stderr, no condition matched) before a watch is flagged (#359). */
|
|
20
20
|
export const DEFAULT_BLIND_CHECKS = 3;
|
|
21
21
|
/** How long bg_task_watch waits for the first check before returning (#359). */
|
|
22
|
-
export
|
|
22
|
+
export { FIRST_WATCH_CHECK_WAIT_MS } from "./types.domain.mjs";
|
|
23
23
|
/** How to fix a false alarm: some tools write progress or warnings to stderr on success. */
|
|
24
24
|
export const BLIND_CHECK_HINT = "If the stderr is expected (progress or warnings), redirect it (2>/dev/null) or set blind_checks:0.";
|
|
25
25
|
/** Each cached extension factory owns its scheduling and suspension state. */
|
|
26
|
-
export function createBackgroundTaskRuntime(attention = createFailureAttention(), deliverCompletion, admission) {
|
|
26
|
+
export function createBackgroundTaskRuntime(attention = createFailureAttention(), deliverCompletion, admission, sourceWork = (_kind, _id, work) => work()) {
|
|
27
27
|
const { resumeFailureAttention, scheduleFailureAttention, stopFailureAttention, suspendFailureAttention } = attention;
|
|
28
28
|
const watcherTimers = new Map();
|
|
29
29
|
const remoteSessionTimers = new Map();
|
|
@@ -224,6 +224,7 @@ export function createBackgroundTaskRuntime(attention = createFailureAttention()
|
|
|
224
224
|
// launch cwd is passed so a relative alias resolves where the task will run.
|
|
225
225
|
assertBackgroundExecutionAllowed(params, sandboxPlan, { remote: Boolean(params.ssh), cwd });
|
|
226
226
|
const commandLimits = backgroundExecutionLimits(sandboxPlan);
|
|
227
|
+
const resolvedWindowsShell = params.ssh ? undefined : resolveWindowsLaunchShell(pi);
|
|
227
228
|
const id = nextTaskId();
|
|
228
229
|
admission?.prepared?.(id);
|
|
229
230
|
const logPath = logPathFor(id);
|
|
@@ -239,7 +240,7 @@ export function createBackgroundTaskRuntime(attention = createFailureAttention()
|
|
|
239
240
|
remote: params.remote,
|
|
240
241
|
}, dependencies.remoteRunner)
|
|
241
242
|
: undefined;
|
|
242
|
-
const operatorSpec = remoteTask?.commandSpec ?? { ...params, cwd, shell: params.shell ?? true };
|
|
243
|
+
const operatorSpec = remoteTask?.commandSpec ?? { ...params, cwd, shell: params.shell ?? true, resolvedWindowsShell };
|
|
243
244
|
const commandSpec = withStepGate(operatorSpec, id, stepGated);
|
|
244
245
|
const sandboxNotices = [];
|
|
245
246
|
const launchSpec = remoteTask
|
|
@@ -432,7 +433,8 @@ export function createBackgroundTaskRuntime(attention = createFailureAttention()
|
|
|
432
433
|
clearRemoteSessionTimer(id);
|
|
433
434
|
if (scheduledWorkSuspended)
|
|
434
435
|
return;
|
|
435
|
-
const
|
|
436
|
+
const dueAt = Date.now() + delayMs;
|
|
437
|
+
const timer = setTimeout(() => void sourceWork("remote-poll", id, () => scheduledWorkSuspended ? undefined : pollRemoteSession(pi, id, getActiveSession), dueAt), delayMs);
|
|
436
438
|
timer.unref();
|
|
437
439
|
remoteSessionTimers.set(id, timer);
|
|
438
440
|
}
|
|
@@ -535,6 +537,7 @@ export function createBackgroundTaskRuntime(attention = createFailureAttention()
|
|
|
535
537
|
const sandboxPlan = resolveForegroundSandboxPlan(pi, !!params.ssh, params, "bg_task_watch");
|
|
536
538
|
assertBackgroundExecutionAllowed(params, sandboxPlan, { remote: Boolean(params.ssh), cwd });
|
|
537
539
|
const commandLimits = backgroundExecutionLimits(sandboxPlan);
|
|
540
|
+
const resolvedWindowsShell = params.ssh || params.shell === false ? undefined : resolveWindowsLaunchShell(pi);
|
|
538
541
|
const id = nextTaskId();
|
|
539
542
|
admission?.prepared?.(id);
|
|
540
543
|
const now = Date.now();
|
|
@@ -549,11 +552,12 @@ export function createBackgroundTaskRuntime(attention = createFailureAttention()
|
|
|
549
552
|
remote: params.remote,
|
|
550
553
|
}, dependencies.remoteRunner)
|
|
551
554
|
: undefined;
|
|
552
|
-
const commandSpec = remoteTask?.commandSpec ?? { ...params, cwd, shell: params.shell ?? true };
|
|
555
|
+
const commandSpec = remoteTask?.commandSpec ?? { ...params, cwd, shell: params.shell ?? true, resolvedWindowsShell };
|
|
553
556
|
const sandboxNotices = [];
|
|
554
557
|
const launchSpec = remoteTask
|
|
555
558
|
? commandSpec
|
|
556
559
|
: confineCommandSpec(commandSpec, sandboxPlan, sandboxProfilePathFor(id), {}, (line) => sandboxNotices.push(line), "bg_task_watch");
|
|
560
|
+
const invocation = resolvedWindowsShell ? commandExecution(launchSpec) : undefined;
|
|
557
561
|
const meta = withCommandPolicy({
|
|
558
562
|
id,
|
|
559
563
|
name: params.name,
|
|
@@ -571,7 +575,7 @@ export function createBackgroundTaskRuntime(attention = createFailureAttention()
|
|
|
571
575
|
shell: commandSpec.shell,
|
|
572
576
|
cwd,
|
|
573
577
|
env: params.env,
|
|
574
|
-
launchArgv: launchArgvOf(commandSpec, launchSpec),
|
|
578
|
+
launchArgv: invocation ? [invocation.execPath, ...invocation.execArgs] : launchArgvOf(commandSpec, launchSpec),
|
|
575
579
|
sandbox: sandboxProvenance(sandboxPlan, !!remoteTask),
|
|
576
580
|
maxLogBytes: resolveMaxLogBytes(params.max_log_bytes),
|
|
577
581
|
spawnPid: process.pid,
|
|
@@ -637,6 +641,10 @@ export function createBackgroundTaskRuntime(attention = createFailureAttention()
|
|
|
637
641
|
scheduleLogRetention(pi, meta.id, getActiveSession);
|
|
638
642
|
const remoteTask = resolvePersistedRemoteTask(meta, dependencies.remoteRunner);
|
|
639
643
|
if (meta.kind === "command_watch") {
|
|
644
|
+
// Shared display refreshes can revisit an already supervised watch. They
|
|
645
|
+
// must not replace its captured interval with a new immediate poll.
|
|
646
|
+
if (watcherTimers.has(meta.id) || activePolls.has(meta.id))
|
|
647
|
+
return meta;
|
|
640
648
|
scheduleWatch(pi, meta.id, 0, getActiveSession, remoteTask
|
|
641
649
|
? (timeoutMs) => remoteTask.runOnce(undefined, timeoutMs)
|
|
642
650
|
: dependencies.watchPollRunner);
|
|
@@ -714,7 +722,9 @@ export function createBackgroundTaskRuntime(attention = createFailureAttention()
|
|
|
714
722
|
const arm = () => {
|
|
715
723
|
if (scheduledWorkSuspended)
|
|
716
724
|
return;
|
|
717
|
-
const
|
|
725
|
+
const dueAt = Date.now() + delayMs;
|
|
726
|
+
const timer = setTimeout(() => sourceWork("handoff", id, () => { if (!scheduledWorkSuspended)
|
|
727
|
+
check(); }, dueAt), delayMs);
|
|
718
728
|
timer.unref();
|
|
719
729
|
handoffTimers.set(id, timer);
|
|
720
730
|
};
|
|
@@ -847,7 +857,8 @@ export function createBackgroundTaskRuntime(attention = createFailureAttention()
|
|
|
847
857
|
clearWatchTimer(id);
|
|
848
858
|
if (scheduledWorkSuspended)
|
|
849
859
|
return;
|
|
850
|
-
const
|
|
860
|
+
const dueAt = Date.now() + delayMs;
|
|
861
|
+
const timer = setTimeout(() => void sourceWork("watch", id, () => scheduledWorkSuspended ? undefined : pollWatch(pi, id, getActiveSession, runOnce), dueAt), delayMs);
|
|
851
862
|
timer.unref();
|
|
852
863
|
watcherTimers.set(id, timer);
|
|
853
864
|
}
|
|
@@ -1135,7 +1146,8 @@ export function createBackgroundTaskRuntime(attention = createFailureAttention()
|
|
|
1135
1146
|
if (scheduledWorkSuspended)
|
|
1136
1147
|
return;
|
|
1137
1148
|
const delay = Math.max(0, deadlineAt - Date.now());
|
|
1138
|
-
const
|
|
1149
|
+
const dueAt = deadlineAt;
|
|
1150
|
+
const timer = setTimeout(() => void sourceWork("process-deadline", id, () => scheduledWorkSuspended ? undefined : timeoutProcess(pi, id, getActiveSession), dueAt), delay);
|
|
1139
1151
|
timer.unref();
|
|
1140
1152
|
processTimeoutTimers.set(id, timer);
|
|
1141
1153
|
}
|
|
@@ -1329,16 +1341,23 @@ export function createBackgroundTaskRuntime(attention = createFailureAttention()
|
|
|
1329
1341
|
stopLogRetention(id);
|
|
1330
1342
|
if (scheduledWorkSuspended)
|
|
1331
1343
|
return;
|
|
1344
|
+
let dueAt = Date.now() + LOG_RETENTION_CHECK_MS;
|
|
1332
1345
|
const timer = setInterval(() => {
|
|
1333
|
-
const
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1346
|
+
const due = dueAt;
|
|
1347
|
+
dueAt = Date.now() + LOG_RETENTION_CHECK_MS;
|
|
1348
|
+
return sourceWork("log-retention", id, () => {
|
|
1349
|
+
if (scheduledWorkSuspended)
|
|
1350
|
+
return;
|
|
1351
|
+
const meta = readMeta(id);
|
|
1352
|
+
if (!meta || meta.status !== "running") {
|
|
1353
|
+
stopLogRetention(id);
|
|
1354
|
+
return;
|
|
1355
|
+
}
|
|
1356
|
+
if (meta.kind === "process")
|
|
1357
|
+
enforceLogRetention(meta);
|
|
1358
|
+
if (observeTaskStallAttention(meta))
|
|
1359
|
+
scheduleFailureAttention(pi, id, getActiveSession);
|
|
1360
|
+
}, due);
|
|
1342
1361
|
}, LOG_RETENTION_CHECK_MS);
|
|
1343
1362
|
timer.unref();
|
|
1344
1363
|
logRetentionTimers.set(id, timer);
|
|
@@ -1403,71 +1422,6 @@ export function createBackgroundTaskRuntime(attention = createFailureAttention()
|
|
|
1403
1422
|
return result.stdout.slice(0, 4000);
|
|
1404
1423
|
}
|
|
1405
1424
|
}
|
|
1406
|
-
/** Version tag of the watch outcome fingerprint. A value from another version is adopted, never compared. */
|
|
1407
|
-
const WATCH_FINGERPRINT_VERSION = "v1";
|
|
1408
|
-
/** OSC and CSI control sequences are display markup, not content. */
|
|
1409
|
-
const TERMINAL_ESCAPE = /\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)|\u001b\[[0-?]*[ -/]*[@-~]/g;
|
|
1410
|
-
/**
|
|
1411
|
-
* Text as the terminal would settle it. Redraw frames and control sequences are
|
|
1412
|
-
* display churn: repainting the same visible line is not a new observation.
|
|
1413
|
-
*/
|
|
1414
|
-
function settledTerminalText(text) {
|
|
1415
|
-
return text
|
|
1416
|
-
.replace(TERMINAL_ESCAPE, "")
|
|
1417
|
-
.split("\n")
|
|
1418
|
-
.map((line) => {
|
|
1419
|
-
// A CR immediately before LF ends the line; any other CR overwrites it in place.
|
|
1420
|
-
const body = line.endsWith("\r") ? line.slice(0, -1) : line;
|
|
1421
|
-
return (body.split("\r").at(-1) ?? "").replace(/[ \t]+$/, "");
|
|
1422
|
-
})
|
|
1423
|
-
.join("\n")
|
|
1424
|
-
.replace(/\n+$/, "");
|
|
1425
|
-
}
|
|
1426
|
-
/** Objects compare by content regardless of key order, so reordered keys are not progress. */
|
|
1427
|
-
function canonicalJsonText(value) {
|
|
1428
|
-
if (Array.isArray(value))
|
|
1429
|
-
return `[${value.map(canonicalJsonText).join(",")}]`;
|
|
1430
|
-
if (value && typeof value === "object") {
|
|
1431
|
-
const record = value;
|
|
1432
|
-
const entries = Object.keys(record).sort()
|
|
1433
|
-
.map((key) => `${JSON.stringify(key)}:${canonicalJsonText(record[key])}`);
|
|
1434
|
-
return `{${entries.join(",")}}`;
|
|
1435
|
-
}
|
|
1436
|
-
return JSON.stringify(value) ?? "null";
|
|
1437
|
-
}
|
|
1438
|
-
/** stdout compares as JSON content when it parses, and as settled text otherwise. */
|
|
1439
|
-
function canonicalWatchStdout(stdout) {
|
|
1440
|
-
const settled = settledTerminalText(stdout);
|
|
1441
|
-
try {
|
|
1442
|
-
return `json:${canonicalJsonText(JSON.parse(settled))}`;
|
|
1443
|
-
}
|
|
1444
|
-
catch {
|
|
1445
|
-
return `text:${settled}`;
|
|
1446
|
-
}
|
|
1447
|
-
}
|
|
1448
|
-
/**
|
|
1449
|
-
* What a poll observed, independent of when it ran. Exit status, signal, error,
|
|
1450
|
-
* stdout content, and stderr content are included; poll metadata (start time,
|
|
1451
|
-
* end time, duration, check count) is deliberately not, so it can never hide a
|
|
1452
|
-
* watch that reports the same outcome forever. Watch stdout may carry its own
|
|
1453
|
-
* timestamps: projecting meaningful fields is the caller's job, not this
|
|
1454
|
-
* fingerprint's guess.
|
|
1455
|
-
*/
|
|
1456
|
-
function watchOutcomeFingerprint(result) {
|
|
1457
|
-
// A runner may report why the check itself could not run; that is part of the
|
|
1458
|
-
// observed outcome, not poll metadata.
|
|
1459
|
-
const reported = result.error;
|
|
1460
|
-
const error = typeof reported === "string" ? settledTerminalText(reported) : null;
|
|
1461
|
-
const payload = JSON.stringify([
|
|
1462
|
-
result.exitCode,
|
|
1463
|
-
result.signal ?? null,
|
|
1464
|
-
result.timedOut === true,
|
|
1465
|
-
error,
|
|
1466
|
-
canonicalWatchStdout(result.stdout),
|
|
1467
|
-
settledTerminalText(result.stderr),
|
|
1468
|
-
]);
|
|
1469
|
-
return `${WATCH_FINGERPRINT_VERSION}:${createHash("sha256").update(payload).digest("hex")}`;
|
|
1470
|
-
}
|
|
1471
1425
|
/**
|
|
1472
1426
|
* A watch's state clock advances only when its observed outcome changes. The
|
|
1473
1427
|
* poll itself is activity (`lastCheckedAt`), not progress, so a stationary
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WATCH_FINGERPRINT_VERSION, watchOutcomeFingerprint } from "./watch-fingerprint.js";
|
|
2
2
|
import { readFileSync, statSync } from "node:fs";
|
|
3
3
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
import { appendLine, appendTaskOutput, appendWatchResult, retainLogTail, resolveMaxLogBytes } from "./logs.js";
|
|
5
5
|
import { evaluateCondition, validateCondition } from "./conditions.js";
|
|
6
|
-
import { parseStepGateFailure, processExists, runCommandOnce, spawnCommand, STEP_GATE_COMMAND_ENV, stepGateScript, stopProcessGroup } from "./process.js";
|
|
6
|
+
import { commandExecution, parseStepGateFailure, processExists, resolveWindowsLaunchShell, runCommandOnce, spawnCommand, STEP_GATE_COMMAND_ENV, stepGateScript, stopProcessGroup } from "./process.js";
|
|
7
7
|
import { currentProcessStartToken, readProcessStartToken } from "./process-identity.js";
|
|
8
8
|
import { DEFAULT_TMUX_BOOTSTRAP_TIMEOUT_MS, expandSshRemoteTaskPreset } from "./remote-task-preset.js";
|
|
9
9
|
import type { RemoteRunner, ResolvedSshRemoteTask } from "./remote-task-preset.js";
|
|
@@ -27,7 +27,7 @@ import type {
|
|
|
27
27
|
TerminalResult,
|
|
28
28
|
} from "./types.js";
|
|
29
29
|
import { observeTaskStallAttention } from "./stall-attention.js";
|
|
30
|
-
import { isTerminalStatus } from "./types.js";
|
|
30
|
+
import { FIRST_WATCH_CHECK_WAIT_MS, isTerminalStatus } from "./types.js";
|
|
31
31
|
|
|
32
32
|
export type ActiveSessionProvider = () => BackgroundTaskCallbackOrigin | undefined;
|
|
33
33
|
|
|
@@ -98,7 +98,7 @@ export const DEFAULT_WATCH_TIMEOUT_SECONDS = 15 * 60;
|
|
|
98
98
|
/** Consecutive blind checks (exit 0, stderr, no condition matched) before a watch is flagged (#359). */
|
|
99
99
|
export const DEFAULT_BLIND_CHECKS = 3;
|
|
100
100
|
/** How long bg_task_watch waits for the first check before returning (#359). */
|
|
101
|
-
export
|
|
101
|
+
export { FIRST_WATCH_CHECK_WAIT_MS } from "./types.js";
|
|
102
102
|
/** How to fix a false alarm: some tools write progress or warnings to stderr on success. */
|
|
103
103
|
export const BLIND_CHECK_HINT = "If the stderr is expected (progress or warnings), redirect it (2>/dev/null) or set blind_checks:0.";
|
|
104
104
|
/**
|
|
@@ -110,7 +110,8 @@ export type FirstCheckWaitEnd = "timeout" | "aborted" | "suspended";
|
|
|
110
110
|
export type FirstCheckOutcome = FirstWatchCheck | { pending: FirstCheckWaitEnd; waitedMs: number } | undefined;
|
|
111
111
|
|
|
112
112
|
/** Each cached extension factory owns its scheduling and suspension state. */
|
|
113
|
-
export function createBackgroundTaskRuntime(attention = createFailureAttention(), deliverCompletion?: (origin: BackgroundTaskCallbackOrigin | undefined, event: Parameters<ReturnType<typeof getCallbackBatcher>["enqueue"]>[0]) => void, admission?: { assert(): void; prepared?(id: string): void }
|
|
113
|
+
export function createBackgroundTaskRuntime(attention = createFailureAttention(), deliverCompletion?: (origin: BackgroundTaskCallbackOrigin | undefined, event: Parameters<ReturnType<typeof getCallbackBatcher>["enqueue"]>[0]) => void, admission?: { assert(): void; prepared?(id: string): void },
|
|
114
|
+
sourceWork: (kind: string, id: string, work: () => unknown, dueAt?: number) => unknown = (_kind, _id, work) => work()) {
|
|
114
115
|
const { resumeFailureAttention, scheduleFailureAttention, stopFailureAttention, suspendFailureAttention } = attention;
|
|
115
116
|
const watcherTimers = new Map<string, ReturnType<typeof setTimeout>>();
|
|
116
117
|
const remoteSessionTimers = new Map<string, ReturnType<typeof setTimeout>>();
|
|
@@ -314,6 +315,7 @@ function spawnTask(
|
|
|
314
315
|
// launch cwd is passed so a relative alias resolves where the task will run.
|
|
315
316
|
assertBackgroundExecutionAllowed(params, sandboxPlan, { remote: Boolean(params.ssh), cwd });
|
|
316
317
|
const commandLimits = backgroundExecutionLimits(sandboxPlan);
|
|
318
|
+
const resolvedWindowsShell = params.ssh ? undefined : resolveWindowsLaunchShell(pi);
|
|
317
319
|
const id = nextTaskId();
|
|
318
320
|
admission?.prepared?.(id);
|
|
319
321
|
const logPath = logPathFor(id);
|
|
@@ -329,7 +331,7 @@ function spawnTask(
|
|
|
329
331
|
remote: params.remote,
|
|
330
332
|
}, dependencies.remoteRunner)
|
|
331
333
|
: undefined;
|
|
332
|
-
const operatorSpec: CommandSpec = remoteTask?.commandSpec ?? { ...params, cwd, shell: params.shell ?? true };
|
|
334
|
+
const operatorSpec: CommandSpec = remoteTask?.commandSpec ?? { ...params, cwd, shell: params.shell ?? true, resolvedWindowsShell };
|
|
333
335
|
const commandSpec = withStepGate(operatorSpec, id, stepGated);
|
|
334
336
|
const sandboxNotices: string[] = [];
|
|
335
337
|
const launchSpec = remoteTask
|
|
@@ -517,7 +519,8 @@ function scheduleRemoteSessionPoll(
|
|
|
517
519
|
): void {
|
|
518
520
|
clearRemoteSessionTimer(id);
|
|
519
521
|
if (scheduledWorkSuspended) return;
|
|
520
|
-
const
|
|
522
|
+
const dueAt = Date.now() + delayMs;
|
|
523
|
+
const timer = setTimeout(() => void sourceWork("remote-poll", id, () => scheduledWorkSuspended ? undefined : pollRemoteSession(pi, id, getActiveSession), dueAt), delayMs);
|
|
521
524
|
timer.unref();
|
|
522
525
|
remoteSessionTimers.set(id, timer);
|
|
523
526
|
}
|
|
@@ -627,6 +630,7 @@ function startWatchTask(
|
|
|
627
630
|
const sandboxPlan = resolveForegroundSandboxPlan(pi, !!params.ssh, params, "bg_task_watch");
|
|
628
631
|
assertBackgroundExecutionAllowed(params, sandboxPlan, { remote: Boolean(params.ssh), cwd });
|
|
629
632
|
const commandLimits = backgroundExecutionLimits(sandboxPlan);
|
|
633
|
+
const resolvedWindowsShell = params.ssh || params.shell === false ? undefined : resolveWindowsLaunchShell(pi);
|
|
630
634
|
const id = nextTaskId();
|
|
631
635
|
admission?.prepared?.(id);
|
|
632
636
|
const now = Date.now();
|
|
@@ -641,11 +645,12 @@ function startWatchTask(
|
|
|
641
645
|
remote: params.remote,
|
|
642
646
|
}, dependencies.remoteRunner)
|
|
643
647
|
: undefined;
|
|
644
|
-
const commandSpec: CommandSpec = remoteTask?.commandSpec ?? { ...params, cwd, shell: params.shell ?? true };
|
|
648
|
+
const commandSpec: CommandSpec = remoteTask?.commandSpec ?? { ...params, cwd, shell: params.shell ?? true, resolvedWindowsShell };
|
|
645
649
|
const sandboxNotices: string[] = [];
|
|
646
650
|
const launchSpec = remoteTask
|
|
647
651
|
? commandSpec
|
|
648
652
|
: confineCommandSpec(commandSpec, sandboxPlan, sandboxProfilePathFor(id), {}, (line) => sandboxNotices.push(line), "bg_task_watch");
|
|
653
|
+
const invocation = resolvedWindowsShell ? commandExecution(launchSpec) : undefined;
|
|
649
654
|
const meta = withCommandPolicy({
|
|
650
655
|
id,
|
|
651
656
|
name: params.name,
|
|
@@ -663,7 +668,7 @@ function startWatchTask(
|
|
|
663
668
|
shell: commandSpec.shell,
|
|
664
669
|
cwd,
|
|
665
670
|
env: params.env,
|
|
666
|
-
launchArgv: launchArgvOf(commandSpec, launchSpec),
|
|
671
|
+
launchArgv: invocation ? [invocation.execPath, ...invocation.execArgs] : launchArgvOf(commandSpec, launchSpec),
|
|
667
672
|
sandbox: sandboxProvenance(sandboxPlan, !!remoteTask),
|
|
668
673
|
maxLogBytes: resolveMaxLogBytes(params.max_log_bytes),
|
|
669
674
|
spawnPid: process.pid,
|
|
@@ -735,6 +740,9 @@ function resumeRunningTask(
|
|
|
735
740
|
scheduleLogRetention(pi, meta.id, getActiveSession);
|
|
736
741
|
const remoteTask = resolvePersistedRemoteTask(meta, dependencies.remoteRunner);
|
|
737
742
|
if (meta.kind === "command_watch") {
|
|
743
|
+
// Shared display refreshes can revisit an already supervised watch. They
|
|
744
|
+
// must not replace its captured interval with a new immediate poll.
|
|
745
|
+
if (watcherTimers.has(meta.id) || activePolls.has(meta.id)) return meta;
|
|
738
746
|
scheduleWatch(pi, meta.id, 0, getActiveSession, remoteTask
|
|
739
747
|
? (timeoutMs) => remoteTask.runOnce(undefined, timeoutMs)
|
|
740
748
|
: dependencies.watchPollRunner);
|
|
@@ -814,7 +822,8 @@ function scheduleHandoff(
|
|
|
814
822
|
};
|
|
815
823
|
const arm = () => {
|
|
816
824
|
if (scheduledWorkSuspended) return;
|
|
817
|
-
const
|
|
825
|
+
const dueAt = Date.now() + delayMs;
|
|
826
|
+
const timer = setTimeout(() => sourceWork("handoff", id, () => { if (!scheduledWorkSuspended) check(); }, dueAt), delayMs);
|
|
818
827
|
timer.unref();
|
|
819
828
|
handoffTimers.set(id, timer);
|
|
820
829
|
};
|
|
@@ -957,7 +966,8 @@ function scheduleWatch(
|
|
|
957
966
|
): void {
|
|
958
967
|
clearWatchTimer(id);
|
|
959
968
|
if (scheduledWorkSuspended) return;
|
|
960
|
-
const
|
|
969
|
+
const dueAt = Date.now() + delayMs;
|
|
970
|
+
const timer = setTimeout(() => void sourceWork("watch", id, () => scheduledWorkSuspended ? undefined : pollWatch(pi, id, getActiveSession, runOnce), dueAt), delayMs);
|
|
961
971
|
timer.unref();
|
|
962
972
|
watcherTimers.set(id, timer);
|
|
963
973
|
}
|
|
@@ -1260,7 +1270,8 @@ function scheduleProcessTimeout(
|
|
|
1260
1270
|
clearProcessTimeout(id);
|
|
1261
1271
|
if (scheduledWorkSuspended) return;
|
|
1262
1272
|
const delay = Math.max(0, deadlineAt - Date.now());
|
|
1263
|
-
const
|
|
1273
|
+
const dueAt = deadlineAt;
|
|
1274
|
+
const timer = setTimeout(() => void sourceWork("process-deadline", id, () => scheduledWorkSuspended ? undefined : timeoutProcess(pi, id, getActiveSession), dueAt), delay);
|
|
1264
1275
|
timer.unref();
|
|
1265
1276
|
processTimeoutTimers.set(id, timer);
|
|
1266
1277
|
}
|
|
@@ -1459,7 +1470,9 @@ function launchArgvOf(commandSpec: CommandSpec, launchSpec: CommandSpec): string
|
|
|
1459
1470
|
function scheduleLogRetention(pi: ExtensionAPI, id: string, getActiveSession?: ActiveSessionProvider): void {
|
|
1460
1471
|
stopLogRetention(id);
|
|
1461
1472
|
if (scheduledWorkSuspended) return;
|
|
1462
|
-
|
|
1473
|
+
let dueAt = Date.now() + LOG_RETENTION_CHECK_MS;
|
|
1474
|
+
const timer = setInterval(() => { const due = dueAt; dueAt = Date.now() + LOG_RETENTION_CHECK_MS; return sourceWork("log-retention", id, () => {
|
|
1475
|
+
if (scheduledWorkSuspended) return;
|
|
1463
1476
|
const meta = readMeta(id);
|
|
1464
1477
|
if (!meta || meta.status !== "running") {
|
|
1465
1478
|
stopLogRetention(id);
|
|
@@ -1467,7 +1480,7 @@ function scheduleLogRetention(pi: ExtensionAPI, id: string, getActiveSession?: A
|
|
|
1467
1480
|
}
|
|
1468
1481
|
if (meta.kind === "process") enforceLogRetention(meta);
|
|
1469
1482
|
if (observeTaskStallAttention(meta)) scheduleFailureAttention(pi, id, getActiveSession);
|
|
1470
|
-
}, LOG_RETENTION_CHECK_MS);
|
|
1483
|
+
}, due); }, LOG_RETENTION_CHECK_MS);
|
|
1471
1484
|
timer.unref();
|
|
1472
1485
|
logRetentionTimers.set(id, timer);
|
|
1473
1486
|
}
|
|
@@ -1530,74 +1543,6 @@ function extractLastState(result: { stdout: string }): unknown {
|
|
|
1530
1543
|
}
|
|
1531
1544
|
}
|
|
1532
1545
|
|
|
1533
|
-
/** Version tag of the watch outcome fingerprint. A value from another version is adopted, never compared. */
|
|
1534
|
-
const WATCH_FINGERPRINT_VERSION = "v1";
|
|
1535
|
-
/** OSC and CSI control sequences are display markup, not content. */
|
|
1536
|
-
const TERMINAL_ESCAPE = /\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)|\u001b\[[0-?]*[ -/]*[@-~]/g;
|
|
1537
|
-
|
|
1538
|
-
/**
|
|
1539
|
-
* Text as the terminal would settle it. Redraw frames and control sequences are
|
|
1540
|
-
* display churn: repainting the same visible line is not a new observation.
|
|
1541
|
-
*/
|
|
1542
|
-
function settledTerminalText(text: string): string {
|
|
1543
|
-
return text
|
|
1544
|
-
.replace(TERMINAL_ESCAPE, "")
|
|
1545
|
-
.split("\n")
|
|
1546
|
-
.map((line) => {
|
|
1547
|
-
// A CR immediately before LF ends the line; any other CR overwrites it in place.
|
|
1548
|
-
const body = line.endsWith("\r") ? line.slice(0, -1) : line;
|
|
1549
|
-
return (body.split("\r").at(-1) ?? "").replace(/[ \t]+$/, "");
|
|
1550
|
-
})
|
|
1551
|
-
.join("\n")
|
|
1552
|
-
.replace(/\n+$/, "");
|
|
1553
|
-
}
|
|
1554
|
-
|
|
1555
|
-
/** Objects compare by content regardless of key order, so reordered keys are not progress. */
|
|
1556
|
-
function canonicalJsonText(value: unknown): string {
|
|
1557
|
-
if (Array.isArray(value)) return `[${value.map(canonicalJsonText).join(",")}]`;
|
|
1558
|
-
if (value && typeof value === "object") {
|
|
1559
|
-
const record = value as Record<string, unknown>;
|
|
1560
|
-
const entries = Object.keys(record).sort()
|
|
1561
|
-
.map((key) => `${JSON.stringify(key)}:${canonicalJsonText(record[key])}`);
|
|
1562
|
-
return `{${entries.join(",")}}`;
|
|
1563
|
-
}
|
|
1564
|
-
return JSON.stringify(value) ?? "null";
|
|
1565
|
-
}
|
|
1566
|
-
|
|
1567
|
-
/** stdout compares as JSON content when it parses, and as settled text otherwise. */
|
|
1568
|
-
function canonicalWatchStdout(stdout: string): string {
|
|
1569
|
-
const settled = settledTerminalText(stdout);
|
|
1570
|
-
try {
|
|
1571
|
-
return `json:${canonicalJsonText(JSON.parse(settled))}`;
|
|
1572
|
-
} catch {
|
|
1573
|
-
return `text:${settled}`;
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
|
|
1577
|
-
/**
|
|
1578
|
-
* What a poll observed, independent of when it ran. Exit status, signal, error,
|
|
1579
|
-
* stdout content, and stderr content are included; poll metadata (start time,
|
|
1580
|
-
* end time, duration, check count) is deliberately not, so it can never hide a
|
|
1581
|
-
* watch that reports the same outcome forever. Watch stdout may carry its own
|
|
1582
|
-
* timestamps: projecting meaningful fields is the caller's job, not this
|
|
1583
|
-
* fingerprint's guess.
|
|
1584
|
-
*/
|
|
1585
|
-
function watchOutcomeFingerprint(result: CommandResult): string {
|
|
1586
|
-
// A runner may report why the check itself could not run; that is part of the
|
|
1587
|
-
// observed outcome, not poll metadata.
|
|
1588
|
-
const reported = (result as CommandResult & { error?: unknown }).error;
|
|
1589
|
-
const error = typeof reported === "string" ? settledTerminalText(reported) : null;
|
|
1590
|
-
const payload = JSON.stringify([
|
|
1591
|
-
result.exitCode,
|
|
1592
|
-
result.signal ?? null,
|
|
1593
|
-
result.timedOut === true,
|
|
1594
|
-
error,
|
|
1595
|
-
canonicalWatchStdout(result.stdout),
|
|
1596
|
-
settledTerminalText(result.stderr),
|
|
1597
|
-
]);
|
|
1598
|
-
return `${WATCH_FINGERPRINT_VERSION}:${createHash("sha256").update(payload).digest("hex")}`;
|
|
1599
|
-
}
|
|
1600
|
-
|
|
1601
1546
|
/**
|
|
1602
1547
|
* A watch's state clock advances only when its observed outcome changes. The
|
|
1603
1548
|
* poll itself is activity (`lastCheckedAt`), not progress, so a stationary
|
|
@@ -242,6 +242,7 @@ function readPermissions(value) {
|
|
|
242
242
|
projectFiles: p.projectFiles,
|
|
243
243
|
outsideProject: p.outsideProject,
|
|
244
244
|
storedCredentials: p.storedCredentials,
|
|
245
|
+
...(p.processAccess === undefined ? {} : { processAccess: p.processAccess }),
|
|
245
246
|
...(p.shell === undefined ? {} : { shell: p.shell }),
|
|
246
247
|
...(p.commandTimeoutSeconds === undefined ? {} : { commandTimeoutSeconds: p.commandTimeoutSeconds }),
|
|
247
248
|
});
|
|
@@ -264,22 +265,20 @@ export function observeForegroundSandboxPolicy(pi) {
|
|
|
264
265
|
try {
|
|
265
266
|
const published = data && typeof data === "object" ? data : undefined;
|
|
266
267
|
const hasBackground = published && Object.hasOwn(published, "background");
|
|
267
|
-
const
|
|
268
|
-
|
|
268
|
+
const main = readPolicy(data);
|
|
269
|
+
const policy = hasBackground ? readPolicy(published.background, "Background tasks") : main;
|
|
270
|
+
if (hasBackground && (!main || !policy))
|
|
269
271
|
throw new Error("Invalid Background tasks sandbox policy; update permissions in /sandbox.");
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
mirror.mainConfined =
|
|
276
|
-
mirror.processAccess =
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
mirror.policy = policy;
|
|
281
|
-
mirror.error = undefined;
|
|
282
|
-
}
|
|
272
|
+
if (!policy || !main)
|
|
273
|
+
return;
|
|
274
|
+
const isOff = (scope) => scope.state === "disabled" || scope.state === "inactive";
|
|
275
|
+
const allowsRead = (scope) => scope.permissions !== undefined &&
|
|
276
|
+
(isOff(scope) || scope.permissions.processAccess === "read");
|
|
277
|
+
mirror.mainConfined = !isOff(main);
|
|
278
|
+
mirror.processAccess = allowsRead(main) && allowsRead(policy) ? "read" : "off";
|
|
279
|
+
Object.assign(policy, { policySource: hasBackground ? "background" : "main-legacy" });
|
|
280
|
+
mirror.policy = policy;
|
|
281
|
+
mirror.error = undefined;
|
|
283
282
|
}
|
|
284
283
|
catch (error) {
|
|
285
284
|
mirror.error = error;
|
|
@@ -214,7 +214,7 @@ export interface ForegroundSandboxPolicy {
|
|
|
214
214
|
readonly denyWrite: readonly string[];
|
|
215
215
|
/** Human-readable evidence for why `state` is what it is. */
|
|
216
216
|
readonly reason: string;
|
|
217
|
-
readonly permissions?: Readonly<SandboxPermissions & { enabled: boolean }>;
|
|
217
|
+
readonly permissions?: Readonly<SandboxPermissions & { enabled: boolean; processAccess?: "off" | "read" }>;
|
|
218
218
|
readonly policySource?: "background" | "main-legacy";
|
|
219
219
|
}
|
|
220
220
|
|
|
@@ -320,6 +320,7 @@ function readPermissions(value: unknown): ForegroundSandboxPolicy["permissions"]
|
|
|
320
320
|
projectFiles: p.projectFiles as SandboxPermissions["projectFiles"],
|
|
321
321
|
outsideProject: p.outsideProject as SandboxPermissions["outsideProject"],
|
|
322
322
|
storedCredentials: p.storedCredentials as SandboxPermissions["storedCredentials"],
|
|
323
|
+
...(p.processAccess === undefined ? {} : { processAccess: p.processAccess as "off" | "read" }),
|
|
323
324
|
...(p.shell === undefined ? {} : { shell: p.shell as boolean }),
|
|
324
325
|
...(p.commandTimeoutSeconds === undefined ? {} : { commandTimeoutSeconds: p.commandTimeoutSeconds as number | null }),
|
|
325
326
|
});
|
|
@@ -343,16 +344,18 @@ export function observeForegroundSandboxPolicy(pi: unknown): void {
|
|
|
343
344
|
try {
|
|
344
345
|
const published = data && typeof data === "object" ? data as Record<string, unknown> : undefined;
|
|
345
346
|
const hasBackground = published && Object.hasOwn(published, "background");
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
mirror.
|
|
354
|
-
|
|
355
|
-
|
|
347
|
+
const main = readPolicy(data);
|
|
348
|
+
const policy = hasBackground ? readPolicy(published.background, "Background tasks") : main;
|
|
349
|
+
if (hasBackground && (!main || !policy)) throw new Error("Invalid Background tasks sandbox policy; update permissions in /sandbox.");
|
|
350
|
+
if (!policy || !main) return;
|
|
351
|
+
const isOff = (scope: ForegroundSandboxPolicy) => scope.state === "disabled" || scope.state === "inactive";
|
|
352
|
+
const allowsRead = (scope: ForegroundSandboxPolicy) => scope.permissions !== undefined &&
|
|
353
|
+
(isOff(scope) || scope.permissions.processAccess === "read");
|
|
354
|
+
mirror.mainConfined = !isOff(main);
|
|
355
|
+
mirror.processAccess = allowsRead(main) && allowsRead(policy) ? "read" : "off";
|
|
356
|
+
Object.assign(policy, { policySource: hasBackground ? "background" : "main-legacy" });
|
|
357
|
+
mirror.policy = policy;
|
|
358
|
+
mirror.error = undefined;
|
|
356
359
|
} catch (error) {
|
|
357
360
|
mirror.error = error as Error;
|
|
358
361
|
mirror.processAccess = "off";
|
|
@@ -400,6 +400,7 @@ export function createCallbackBatcher(host, options = {}) {
|
|
|
400
400
|
const pending = new Map();
|
|
401
401
|
const inFlight = new Set();
|
|
402
402
|
const urgentInFlight = new Set();
|
|
403
|
+
const urgentSettlements = new Set();
|
|
403
404
|
const handedOff = new Map();
|
|
404
405
|
const activeTools = new Set();
|
|
405
406
|
let sequence = 0;
|
|
@@ -583,7 +584,9 @@ export function createCallbackBatcher(host, options = {}) {
|
|
|
583
584
|
const handoff = host.sendMessage({ customType: event.customType, content: formatUrgentCallback(event, { maxBytes }), display: true,
|
|
584
585
|
...(event.receiptId ? { details: { urgentEventId: event.receiptId } } : {}) }, { deliverAs: "followUp", triggerTurn: true });
|
|
585
586
|
if (isPromiseLike(handoff)) {
|
|
586
|
-
|
|
587
|
+
const settlement = Promise.resolve(handoff).then(() => acknowledge(), () => false).finally(() => { urgentInFlight.delete(key); urgentSettlements.delete(settlement); });
|
|
588
|
+
urgentSettlements.add(settlement);
|
|
589
|
+
return settlement;
|
|
587
590
|
}
|
|
588
591
|
const acknowledged = acknowledge();
|
|
589
592
|
urgentInFlight.delete(key);
|
|
@@ -634,6 +637,10 @@ export function createCallbackBatcher(host, options = {}) {
|
|
|
634
637
|
return pending.size > 0 ? api.flush() : true;
|
|
635
638
|
},
|
|
636
639
|
deliverUrgent,
|
|
640
|
+
async settled() {
|
|
641
|
+
await flushPromise;
|
|
642
|
+
await Promise.all([...urgentSettlements]);
|
|
643
|
+
},
|
|
637
644
|
cancel() {
|
|
638
645
|
cancelTimer();
|
|
639
646
|
pending.clear();
|
|
@@ -210,6 +210,8 @@ export interface CallbackBatcher {
|
|
|
210
210
|
toolEnded(toolCallId: string): Promise<boolean>;
|
|
211
211
|
deliverUrgent(event: UrgentCallbackEvent): boolean | Promise<boolean>;
|
|
212
212
|
cancel(): void;
|
|
213
|
+
/** Await already-started handoffs after the owner has cancelled scheduling. */
|
|
214
|
+
settled(): Promise<void>;
|
|
213
215
|
pendingCount(): number;
|
|
214
216
|
}
|
|
215
217
|
|
|
@@ -568,6 +570,7 @@ export function createCallbackBatcher(
|
|
|
568
570
|
const pending = new Map<string, PendingEvent>();
|
|
569
571
|
const inFlight = new Set<string>();
|
|
570
572
|
const urgentInFlight = new Set<string>();
|
|
573
|
+
const urgentSettlements = new Set<Promise<boolean>>();
|
|
571
574
|
const handedOff = new Map<string, number>();
|
|
572
575
|
const activeTools = new Set<string>();
|
|
573
576
|
let sequence = 0;
|
|
@@ -750,10 +753,12 @@ export function createCallbackBatcher(
|
|
|
750
753
|
{ deliverAs: "followUp", triggerTurn: true },
|
|
751
754
|
);
|
|
752
755
|
if (isPromiseLike(handoff)) {
|
|
753
|
-
|
|
756
|
+
const settlement = Promise.resolve(handoff).then(
|
|
754
757
|
() => acknowledge(),
|
|
755
758
|
() => false,
|
|
756
|
-
).finally(() => urgentInFlight.delete(key));
|
|
759
|
+
).finally(() => { urgentInFlight.delete(key); urgentSettlements.delete(settlement); });
|
|
760
|
+
urgentSettlements.add(settlement);
|
|
761
|
+
return settlement;
|
|
757
762
|
}
|
|
758
763
|
const acknowledged = acknowledge();
|
|
759
764
|
urgentInFlight.delete(key);
|
|
@@ -800,6 +805,10 @@ export function createCallbackBatcher(
|
|
|
800
805
|
return pending.size > 0 ? api.flush() : true;
|
|
801
806
|
},
|
|
802
807
|
deliverUrgent,
|
|
808
|
+
async settled() {
|
|
809
|
+
await flushPromise;
|
|
810
|
+
await Promise.all([...urgentSettlements]);
|
|
811
|
+
},
|
|
803
812
|
cancel() {
|
|
804
813
|
cancelTimer();
|
|
805
814
|
pending.clear();
|