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,6 +1,16 @@
|
|
|
1
1
|
// Generated from packages/operation-coordinator/assignment-observation.mjs. Do not edit directly.
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
|
-
import {
|
|
3
|
+
import { AssignmentInbox } from "./assignment-inbox.mjs";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
|
|
6
|
+
// Only first-party source SQL passes this facade; quoted values stay untouched.
|
|
7
|
+
const sourceTables = new Set(["schema_meta", "sqlite_master", "sqlite_schema", "assignment_change_source", "assignment_changes",
|
|
8
|
+
"waits", "wait_dependencies", "resume_claims", "operations", "coordinator_state", "assignment_outcomes",
|
|
9
|
+
"subagent_launch_intents", "background_input_versions", "background_parent_callbacks", "assignments", "assignment_bindings", "assignment_attempts"]);
|
|
10
|
+
function sourceSQL(sql) {
|
|
11
|
+
if (/^PRAGMA\s+data_version\s*$/i.test(sql)) return "PRAGMA coordinator_source.data_version";
|
|
12
|
+
return sql.replace(/'(?:''|[^'])*'|\b[A-Za-z_][A-Za-z_0-9]*\b/g, token => sourceTables.has(token) ? `coordinator_source.${token}` : token);
|
|
13
|
+
}
|
|
4
14
|
|
|
5
15
|
/** Read-only, bounded projection input. Never creates/migrates a database. */
|
|
6
16
|
export function readAssignmentWaits(path, owner, connection) {
|
|
@@ -44,42 +54,63 @@ export function readAssignmentWaits(path, owner, connection) {
|
|
|
44
54
|
}
|
|
45
55
|
|
|
46
56
|
/** A root read model owns this connection; ordinary observers remain one-shot. */
|
|
47
|
-
export function createAssignmentReader(path) {
|
|
57
|
+
export function createAssignmentReader(path, inboxPath = ":memory:", derivedConnection, options = {}) {
|
|
58
|
+
const inbox = new AssignmentInbox(inboxPath, derivedConnection);
|
|
48
59
|
let db;
|
|
49
60
|
let identity;
|
|
50
61
|
let snapshot = false;
|
|
62
|
+
const composed = options.composed === true;
|
|
63
|
+
const owner = derivedConnection;
|
|
64
|
+
const dropSource = () => {
|
|
65
|
+
if (composed) { if (db) owner.exec("DETACH DATABASE coordinator_source"); }
|
|
66
|
+
else db?.close();
|
|
67
|
+
db = undefined; statements.clear();
|
|
68
|
+
};
|
|
51
69
|
const statements = new Map();
|
|
52
|
-
|
|
70
|
+
const reader = {
|
|
53
71
|
revision() {
|
|
54
72
|
const { statSync } = createRequire(import.meta.url)("node:fs");
|
|
55
73
|
const stat = statSync(path, { bigint: true });
|
|
56
74
|
const next = `${stat.dev}:${stat.ino}`;
|
|
57
75
|
if (identity !== next) {
|
|
58
76
|
if (snapshot) throw new Error("Coordinator identity changed during observation");
|
|
59
|
-
|
|
60
|
-
db = undefined;
|
|
61
|
-
statements.clear();
|
|
77
|
+
dropSource();
|
|
62
78
|
identity = next;
|
|
63
79
|
}
|
|
64
80
|
const { DatabaseSync } = createRequire(import.meta.url)("node:sqlite");
|
|
65
|
-
|
|
81
|
+
if (!db) {
|
|
82
|
+
if (composed) {
|
|
83
|
+
const uri = pathToFileURL(path); uri.searchParams.set("mode", "ro");
|
|
84
|
+
owner.prepare("ATTACH DATABASE ? AS coordinator_source").run(uri.href);
|
|
85
|
+
db = { prepare: sql => owner.prepare(sourceSQL(sql)), get observationActive() { return snapshot; }, beginSnapshot: () => reader.beginSnapshot() };
|
|
86
|
+
} else db = new DatabaseSync(path, { readOnly: true });
|
|
87
|
+
}
|
|
66
88
|
return `${identity}:${db.prepare("PRAGMA data_version").get().data_version}`;
|
|
67
89
|
},
|
|
68
90
|
connection(refresh = true) { if (refresh) this.revision(); return db; },
|
|
91
|
+
changes() { this.revision(); return inbox.receive(db, identity); },
|
|
92
|
+
acknowledgeChanges(batch, complete) { inbox.acknowledge(batch, complete); },
|
|
93
|
+
get changeMetrics() { return inbox.metrics; },
|
|
94
|
+
get snapshotActive() { return snapshot; },
|
|
69
95
|
|
|
70
96
|
beginSnapshot() {
|
|
71
97
|
this.revision();
|
|
72
98
|
if (snapshot) throw new Error("Coordinator snapshot already open");
|
|
73
|
-
db
|
|
99
|
+
const transaction = composed ? owner : db;
|
|
100
|
+
transaction.exec("BEGIN");
|
|
74
101
|
snapshot = true;
|
|
75
102
|
const release = () => {
|
|
76
103
|
if (!snapshot) return;
|
|
77
|
-
try {
|
|
104
|
+
try { transaction.exec("ROLLBACK"); } finally { snapshot = false; }
|
|
78
105
|
};
|
|
79
106
|
try {
|
|
80
107
|
// Pin the WAL read view before recording its revision; other writers keep advancing.
|
|
81
108
|
db.prepare("SELECT count(*) FROM sqlite_schema").get();
|
|
82
|
-
return { revision: this.revision(), release
|
|
109
|
+
return { revision: this.revision(), release, commit: () => {
|
|
110
|
+
if (!snapshot) return;
|
|
111
|
+
transaction.exec("COMMIT");
|
|
112
|
+
snapshot = false;
|
|
113
|
+
} };
|
|
83
114
|
} catch (error) { release(); throw error; }
|
|
84
115
|
},
|
|
85
116
|
|
|
@@ -94,30 +125,6 @@ export function createAssignmentReader(path) {
|
|
|
94
125
|
return { verified: false, waits: [], reason: "Coordinator state is unverified; compatible supervision is unavailable." };
|
|
95
126
|
}
|
|
96
127
|
},
|
|
97
|
-
conversationRevisions() {
|
|
98
|
-
try {
|
|
99
|
-
this.revision();
|
|
100
|
-
if (!["1", "2", "3", "4"].includes(db.prepare("SELECT value FROM schema_meta WHERE key = 'schema_version'").get()?.value)) return undefined;
|
|
101
|
-
const hashes = new Map();
|
|
102
|
-
const add = (sessionId, workspace, value) => {
|
|
103
|
-
const key = JSON.stringify([sessionId, workspace]);
|
|
104
|
-
if (!hashes.has(key)) hashes.set(key, createHash("sha256"));
|
|
105
|
-
hashes.get(key).update(JSON.stringify(value));
|
|
106
|
-
};
|
|
107
|
-
// One source pass per changed database revision, instead of one
|
|
108
|
-
// projection/query/log parse for every historical attempt.
|
|
109
|
-
for (const row of db.prepare(`SELECT w.*, (SELECT json_group_array(attempt_id)
|
|
110
|
-
FROM resume_claims c WHERE c.wait_id = w.wait_id AND c.generation = w.generation) AS claimed_attempts
|
|
111
|
-
FROM waits w WHERE owner_kind = 'worker-conversation' ORDER BY wait_id, generation`).all()) {
|
|
112
|
-
add(row.owner_session_id, row.owner_workspace, row);
|
|
113
|
-
}
|
|
114
|
-
for (const row of db.prepare("SELECT record_json FROM assignment_outcomes ORDER BY assignment_id").all()) {
|
|
115
|
-
const record = JSON.parse(row.record_json);
|
|
116
|
-
add(record.owner.sessionId, record.owner.workspace, record);
|
|
117
|
-
}
|
|
118
|
-
return new Map([...hashes].map(([key, hash]) => [key, hash.digest("hex")]));
|
|
119
|
-
} catch { return undefined; }
|
|
120
|
-
},
|
|
121
128
|
upgradeObligations() {
|
|
122
129
|
try { this.revision(); } catch (error) {
|
|
123
130
|
if (error.code === "ENOENT") return [];
|
|
@@ -144,7 +151,8 @@ export function createAssignmentReader(path) {
|
|
|
144
151
|
return [...obligations, ...reasons];
|
|
145
152
|
},
|
|
146
153
|
|
|
147
|
-
close() { if (snapshot) { db.exec("ROLLBACK"); snapshot = false; }
|
|
154
|
+
close() { if (snapshot) { (composed ? owner : db).exec("ROLLBACK"); snapshot = false; } dropSource(); identity = undefined; inbox.close(); },
|
|
148
155
|
|
|
149
156
|
};
|
|
157
|
+
return reader;
|
|
150
158
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
1
2
|
import { execFileSync } from "node:child_process";
|
|
2
3
|
/**
|
|
3
4
|
* Process start-token reads.
|
|
@@ -20,11 +21,12 @@ const TOKEN_MEMO_TTL_MS = 1_000;
|
|
|
20
21
|
/** Bound on memo entries; the panel is small, but a long session is not. */
|
|
21
22
|
const TOKEN_MEMO_MAX_ENTRIES = 512;
|
|
22
23
|
const tokenMemo = new Map();
|
|
23
|
-
function readTokenUncached(pid) {
|
|
24
|
+
function readTokenUncached(pid, admission = false) {
|
|
24
25
|
if (!Number.isInteger(pid) || pid <= 0 || process.platform === "win32")
|
|
25
26
|
return undefined;
|
|
26
27
|
try {
|
|
27
|
-
const output = execFileSync("ps", ["-o", "lstart=", "-p", String(pid)], {
|
|
28
|
+
const output = execFileSync(admission ? "/bin/ps" : "ps", ["-o", "lstart=", "-p", String(pid)], {
|
|
29
|
+
env: admission ? { LC_ALL: "C", TZ: "UTC0", PATH: "/usr/bin:/bin" } : process.env,
|
|
28
30
|
encoding: "utf8",
|
|
29
31
|
stdio: ["ignore", "pipe", "ignore"],
|
|
30
32
|
timeout: 2_000,
|
|
@@ -35,6 +37,22 @@ function readTokenUncached(pid) {
|
|
|
35
37
|
return undefined;
|
|
36
38
|
}
|
|
37
39
|
}
|
|
40
|
+
// Admission crosses process environments; stored task tokens retain their original format.
|
|
41
|
+
export function readAdmissionStartToken(pid) {
|
|
42
|
+
if (process.platform !== "linux")
|
|
43
|
+
return readTokenUncached(pid, true);
|
|
44
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
45
|
+
return undefined;
|
|
46
|
+
try {
|
|
47
|
+
const stat = readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
48
|
+
// Fields after the parenthesized command start at field 3. Start time is field 22.
|
|
49
|
+
const start = stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19];
|
|
50
|
+
return start && /^\d+$/.test(start) ? start : undefined;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
38
56
|
function remember(pid, token, now) {
|
|
39
57
|
if (tokenMemo.size >= TOKEN_MEMO_MAX_ENTRIES) {
|
|
40
58
|
// Drop expired entries first; only evict live ones if that was not enough.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
-
import { appendFileSync, closeSync, existsSync, mkdirSync, openSync, writeSync } from "node:fs";
|
|
3
|
-
import {
|
|
2
|
+
import { accessSync, appendFileSync, closeSync, constants, existsSync, mkdirSync, openSync, readFileSync, writeSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { dirname, join, win32 } from "node:path";
|
|
4
5
|
/** Known Git for Windows locations; `bash -lc` needs a real bash, not the WSL shim. */
|
|
5
6
|
const WINDOWS_BASH_CANDIDATES = [
|
|
6
7
|
"C:\\Program Files\\Git\\bin\\bash.exe",
|
|
@@ -13,7 +14,8 @@ const WINDOWS_BASH_CANDIDATES = [
|
|
|
13
14
|
* POSIX keeps `/bin/bash`. Windows has no `/bin/bash`, and the `bash.exe` found
|
|
14
15
|
* on PATH is usually the WSL launcher in System32 or the WindowsApps alias,
|
|
15
16
|
* either of which would run the command inside WSL instead of Windows. Prefer
|
|
16
|
-
* an explicit override, then Git for Windows,
|
|
17
|
+
* an explicit override, then Pi's shellPath, Git for Windows, and a non-WSL
|
|
18
|
+
* `bash.exe` on PATH.
|
|
17
19
|
*
|
|
18
20
|
* Resolved lazily at spawn time, not module load: env-injection extensions
|
|
19
21
|
* (e.g. pi-env) may apply settings.json `env` values after this module is
|
|
@@ -21,27 +23,62 @@ const WINDOWS_BASH_CANDIDATES = [
|
|
|
21
23
|
*
|
|
22
24
|
* Exposed for tests and reuse.
|
|
23
25
|
*/
|
|
24
|
-
export function resolveDefaultShell() {
|
|
26
|
+
export function resolveDefaultShell(shellPath) {
|
|
25
27
|
const fromEnv = process.env.PI_BETTER_BACKGROUND_TASKS_SHELL;
|
|
26
28
|
if (fromEnv)
|
|
27
29
|
return fromEnv;
|
|
28
30
|
if (process.platform !== "win32")
|
|
29
31
|
return "/bin/bash";
|
|
30
|
-
|
|
32
|
+
const configured = shellPath ?? readWindowsShellSetting();
|
|
33
|
+
const tried = [];
|
|
34
|
+
if (configured?.trim()) {
|
|
35
|
+
const candidate = /^~[\\/]/.test(configured) ? win32.join(homedir(), configured.slice(2)) : configured;
|
|
36
|
+
tried.push(candidate);
|
|
37
|
+
try {
|
|
38
|
+
accessSync(candidate, constants.F_OK);
|
|
39
|
+
return candidate;
|
|
40
|
+
}
|
|
41
|
+
catch { /* An unavailable setting leaves standard Windows discovery enabled. */ }
|
|
42
|
+
}
|
|
43
|
+
const gitCandidates = [process.env.ProgramFiles, process.env["ProgramFiles(x86)"]]
|
|
44
|
+
.filter((directory) => Boolean(directory))
|
|
45
|
+
.map(directory => win32.join(directory, "Git", "bin", "bash.exe"));
|
|
46
|
+
for (const candidate of new Set([...gitCandidates, ...WINDOWS_BASH_CANDIDATES])) {
|
|
47
|
+
tried.push(candidate);
|
|
31
48
|
if (existsSync(candidate))
|
|
32
49
|
return candidate;
|
|
33
50
|
}
|
|
34
|
-
for (const dir of (process.env.PATH ?? "").split(";")) {
|
|
51
|
+
for (const dir of (process.env.PATH ?? process.env.Path ?? "").split(";")) {
|
|
35
52
|
const trimmed = dir.trim();
|
|
36
53
|
if (!trimmed || /(^|[\\/])(system32|windowsapps)([\\/]|$)/i.test(trimmed))
|
|
37
54
|
continue;
|
|
38
|
-
const candidate = join(trimmed, "bash.exe");
|
|
55
|
+
const candidate = win32.join(trimmed, "bash.exe");
|
|
56
|
+
tried.push(candidate);
|
|
39
57
|
if (existsSync(candidate))
|
|
40
58
|
return candidate;
|
|
41
59
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
throw new Error("No Bash executable found for Windows Background tasks. Set Pi's shellPath in settings.json or "
|
|
61
|
+
+ "PI_BETTER_BACKGROUND_TASKS_SHELL to a working bash.exe. Searched:\n " + [...new Set(tried)].join("\n "));
|
|
62
|
+
}
|
|
63
|
+
function readWindowsShellSetting() {
|
|
64
|
+
const agentDir = process.env.PI_CODING_AGENT_DIR ?? join(homedir(), ".pi", "agent");
|
|
65
|
+
try {
|
|
66
|
+
const settings = JSON.parse(readFileSync(join(agentDir, "settings.json"), "utf8"));
|
|
67
|
+
return typeof settings?.shellPath === "string" ? settings.shellPath : undefined;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** Capture effective session settings before dispatching a Windows launch. */
|
|
74
|
+
export function resolveWindowsLaunchShell(pi) {
|
|
75
|
+
if (process.platform !== "win32")
|
|
76
|
+
return undefined;
|
|
77
|
+
const override = process.env.PI_BETTER_BACKGROUND_TASKS_SHELL;
|
|
78
|
+
if (override)
|
|
79
|
+
return override;
|
|
80
|
+
const settings = pi.getSettings?.();
|
|
81
|
+
return resolveDefaultShell(typeof settings?.shellPath === "string" ? settings.shellPath : undefined);
|
|
45
82
|
}
|
|
46
83
|
/** How long a timed-out process group has to exit on SIGTERM before SIGKILL. */
|
|
47
84
|
const TERMINATION_GRACE_MS = 2_000;
|
|
@@ -59,8 +96,8 @@ export function validateCommandSpec(spec) {
|
|
|
59
96
|
/** Convert a Windows path to the `/c/...` form MSYS bash resolves in redirections. Exposed for tests and reuse. */
|
|
60
97
|
export function toMsysPath(path) {
|
|
61
98
|
const forward = path.replace(/\\/g, "/");
|
|
62
|
-
const drive = /^([A-Za-z]):(\/.+)$/.exec(forward);
|
|
63
|
-
return drive ? `/${drive
|
|
99
|
+
const [, drive, rest] = /^([A-Za-z]):(\/.+)$/.exec(forward) ?? [];
|
|
100
|
+
return drive && rest ? `/${drive.toLowerCase()}${rest}` : forward;
|
|
64
101
|
}
|
|
65
102
|
/** Single-quote a value for safe literal use in a bash script line. Exposed for tests and reuse. */
|
|
66
103
|
export function bashSingleQuote(value) {
|
|
@@ -144,7 +181,7 @@ export function parseStepGateFailure(logText, id) {
|
|
|
144
181
|
if (!line.startsWith(marker) || !line.endsWith(" ---"))
|
|
145
182
|
continue;
|
|
146
183
|
const match = /^--- step gate \[[^\]]+\]: first failing step exit=(-?\d+); shell exit=(-?\d+): (.*) ---$/.exec(line);
|
|
147
|
-
if (!match)
|
|
184
|
+
if (!match || match[3] === undefined)
|
|
148
185
|
continue;
|
|
149
186
|
const stepExitCode = Number(match[1]);
|
|
150
187
|
const shellExitCode = Number(match[2]);
|
|
@@ -494,7 +531,8 @@ export function commandExecution(spec) {
|
|
|
494
531
|
const [command, ...args] = spec.argv;
|
|
495
532
|
return { execPath: command, execArgs: args };
|
|
496
533
|
}
|
|
497
|
-
|
|
534
|
+
const resolved = process.platform === "win32" ? spec.resolvedWindowsShell : undefined;
|
|
535
|
+
return { execPath: resolved ?? resolveDefaultShell(), execArgs: [spec.loginShell === false ? "-c" : "-lc", spec.command] };
|
|
498
536
|
}
|
|
499
537
|
function spawnArgs(spec, detached, stdio) {
|
|
500
538
|
const env = { ...process.env, ...spec.env };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { mkdirSync, readFileSync, readdirSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { isTerminalStatus } from "./types.mjs";
|
|
@@ -64,7 +64,7 @@ export function writeMeta(meta) {
|
|
|
64
64
|
indexMeta(meta);
|
|
65
65
|
for (const listener of metaChangedListeners) {
|
|
66
66
|
try {
|
|
67
|
-
listener();
|
|
67
|
+
listener(meta);
|
|
68
68
|
}
|
|
69
69
|
catch { /* best effort */ }
|
|
70
70
|
}
|
|
@@ -162,9 +162,10 @@ export function removeMeta(meta) {
|
|
|
162
162
|
metaCache.delete(meta.id);
|
|
163
163
|
removeIndexEntry(originIndexDir(originOf(meta)), meta.id);
|
|
164
164
|
removeIndexEntry(originActiveIndexDir(originOf(meta)), meta.id);
|
|
165
|
+
removeIndexEntry(recentPath(originOf(meta)), meta.id);
|
|
165
166
|
for (const listener of metaChangedListeners) {
|
|
166
167
|
try {
|
|
167
|
-
listener();
|
|
168
|
+
listener(meta);
|
|
168
169
|
}
|
|
169
170
|
catch { /* best effort */ }
|
|
170
171
|
}
|
|
@@ -232,6 +233,7 @@ export function listActiveMetasForOrigin(origin) {
|
|
|
232
233
|
export function observeMetasForOrigin(origin, activeOnly = true) {
|
|
233
234
|
const directory = activeOnly ? originActiveIndexDir(origin) : originIndexDir(origin);
|
|
234
235
|
let ids;
|
|
236
|
+
registryIo.indexDirectoryReads++;
|
|
235
237
|
try {
|
|
236
238
|
ids = readdirSync(directory).filter(id => id !== ".initialized");
|
|
237
239
|
}
|
|
@@ -248,6 +250,50 @@ export function observeMetasForOrigin(origin, activeOnly = true) {
|
|
|
248
250
|
}).filter((meta) => !!meta && !!meta.callbackOrigin && belongsToOrigin(meta, origin)
|
|
249
251
|
&& (!activeOnly || meta.status === "running")).sort((a, b) => b.startedAt - a.startedAt);
|
|
250
252
|
}
|
|
253
|
+
const RECENT_LIMIT = 256;
|
|
254
|
+
const RECENT_MS = 30000;
|
|
255
|
+
function recentPath(origin) {
|
|
256
|
+
return join(baseDir(), "by-origin-recent", originKey(origin));
|
|
257
|
+
}
|
|
258
|
+
function recentEntries(origin) {
|
|
259
|
+
const directory = recentPath(origin);
|
|
260
|
+
try {
|
|
261
|
+
registryIo.indexDirectoryReads++;
|
|
262
|
+
const entries = readdirSync(directory).filter(id => !id.startsWith(".")).flatMap(id => {
|
|
263
|
+
try {
|
|
264
|
+
registryIo.indexRevisionChecks++;
|
|
265
|
+
return [{ id, observedAt: statSync(join(directory, id)).mtimeMs }];
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
if (error.code === "ENOENT")
|
|
269
|
+
return [];
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
}).sort((a, b) => b.observedAt - a.observedAt || b.id.localeCompare(a.id));
|
|
273
|
+
return entries.filter(entry => Date.now() - entry.observedAt < RECENT_MS).slice(0, RECENT_LIMIT);
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
if (error.code === "ENOENT")
|
|
277
|
+
return [];
|
|
278
|
+
throw error;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
export function recentMetaDeadline(origin) {
|
|
282
|
+
return recentEntries(origin).map(entry => entry.observedAt + RECENT_MS);
|
|
283
|
+
}
|
|
284
|
+
/** Exact cooperative source identity; no metadata or historical enumeration. */
|
|
285
|
+
export function observationRevisionForOrigin(origin) {
|
|
286
|
+
return [originActiveIndexDir(origin), recentPath(origin)].map(indexDirectorySignature).join(";");
|
|
287
|
+
}
|
|
288
|
+
/** Bounded cooperative writes, including results written before the first reader. */
|
|
289
|
+
export function observeRecentMetasForOrigin(origin) {
|
|
290
|
+
return recentEntries(origin).map(entry => {
|
|
291
|
+
const record = inspectMeta(entry.id);
|
|
292
|
+
if (record.found && !record.meta)
|
|
293
|
+
throw new Error(`Unverified background task ${entry.id}: ${record.error}`);
|
|
294
|
+
return record.meta;
|
|
295
|
+
}).filter((meta) => !!meta && belongsToOrigin(meta, origin) && meta.dismissedAt === undefined);
|
|
296
|
+
}
|
|
251
297
|
function readMetaForSweep(id) {
|
|
252
298
|
const cached = metaCache.get(id);
|
|
253
299
|
if (cached && isTerminalStatus(cached.status))
|
|
@@ -296,6 +342,18 @@ function indexMeta(meta) {
|
|
|
296
342
|
writeIndexEntry(activeDirectory, meta.id);
|
|
297
343
|
else
|
|
298
344
|
removeIndexEntry(activeDirectory, meta.id);
|
|
345
|
+
const origin = originOf(meta), recentDirectory = recentPath(origin);
|
|
346
|
+
mkdirSync(recentDirectory, { recursive: true });
|
|
347
|
+
// Independent pointers preserve concurrent writers; prune only this bounded
|
|
348
|
+
// recent-write accelerator, never the authoritative metadata or history.
|
|
349
|
+
const candidates = readdirSync(recentDirectory).filter(id => !id.startsWith("."));
|
|
350
|
+
const retained = new Set(recentEntries(origin).filter(entry => entry.id !== meta.id).slice(0, RECENT_LIMIT - 1).map(entry => entry.id));
|
|
351
|
+
for (const id of candidates)
|
|
352
|
+
if (id !== meta.id && !retained.has(id))
|
|
353
|
+
removeIndexEntry(recentDirectory, id);
|
|
354
|
+
const temporary = join(recentDirectory, `.${meta.id}.${process.pid}.next`);
|
|
355
|
+
writeFileSync(temporary, "");
|
|
356
|
+
renameSync(temporary, join(recentDirectory, meta.id));
|
|
299
357
|
}
|
|
300
358
|
catch {
|
|
301
359
|
// Indexes are accelerators; meta.json remains authoritative.
|
|
@@ -325,13 +325,13 @@ function readText(path) {
|
|
|
325
325
|
catch (error) {
|
|
326
326
|
if (error.code === "ENOENT")
|
|
327
327
|
return { missing: true };
|
|
328
|
-
return { missing:
|
|
328
|
+
return { missing: false, error: error instanceof Error ? error.message : String(error) };
|
|
329
329
|
}
|
|
330
330
|
}
|
|
331
331
|
function readJsonRecord(path, problem) {
|
|
332
332
|
const read = readText(path);
|
|
333
|
-
if (read.
|
|
334
|
-
return { missing:
|
|
333
|
+
if (read.value === undefined)
|
|
334
|
+
return { missing: read.missing, error: read.error };
|
|
335
335
|
let parsed;
|
|
336
336
|
try {
|
|
337
337
|
parsed = JSON.parse(read.value);
|
|
@@ -463,13 +463,19 @@ class Supervisor {
|
|
|
463
463
|
}
|
|
464
464
|
applyReconciliation(launch, options) {
|
|
465
465
|
return withStateFence(this.directory, launch.taskId, () => {
|
|
466
|
-
const result = readTerminalRecord(this.directory, launch.taskId)
|
|
466
|
+
const { value: result, error: resultError } = readTerminalRecord(this.directory, launch.taskId);
|
|
467
|
+
if (resultError)
|
|
468
|
+
throw new Error(`Unreadable supervisor result record for ${launch.taskId}: ${resultError}`);
|
|
467
469
|
if (result)
|
|
468
470
|
return { status: result.status, terminal: true, result };
|
|
469
|
-
const existingLost = readLostRecord(this.directory, launch.taskId)
|
|
471
|
+
const { value: existingLost, error: lostError } = readLostRecord(this.directory, launch.taskId);
|
|
472
|
+
if (lostError)
|
|
473
|
+
throw new Error(`Unreadable supervisor loss record for ${launch.taskId}: ${lostError}`);
|
|
470
474
|
if (existingLost)
|
|
471
475
|
return { status: "lost", terminal: true, lost: existingLost };
|
|
472
|
-
const claim = readClaimRecord(this.directory, launch.taskId)
|
|
476
|
+
const { value: claim, error: claimError } = readClaimRecord(this.directory, launch.taskId);
|
|
477
|
+
if (claimError)
|
|
478
|
+
throw new Error(`Unreadable supervisor claim record for ${launch.taskId}: ${claimError}`);
|
|
473
479
|
if (claim) {
|
|
474
480
|
if (identityAlive(claim.pid, claim.pidStartTime, claim.claimedAt, this.readToken)) {
|
|
475
481
|
return { status: "running", terminal: false };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-background-tasks/src/adapter-contract.ts. Do not edit directly.
|
|
2
|
-
import { getObservedWaitHost } from "./observed-
|
|
2
|
+
import { getObservedWaitHost } from "./observed-wait-client.domain.mjs";
|
|
3
3
|
import { inspectMeta } from "./registry.domain.mjs";
|
|
4
4
|
/** Optional-peer contract, mirrored by pi-better-sandbox/background-admission.ts. */
|
|
5
5
|
export const BACKGROUND_ADAPTER_REQUEST = "pi-better-background-tasks:adapter-request";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { getObservedWaitHost } from "./observed-
|
|
2
|
+
import { getObservedWaitHost } from "./observed-wait-client.js";
|
|
3
3
|
import { inspectMeta } from "./registry.js";
|
|
4
4
|
|
|
5
5
|
/** Optional-peer contract, mirrored by pi-better-sandbox/background-admission.ts. */
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-background-tasks/src/goal-provider.ts. Do not edit directly.
|
|
2
2
|
import { listMetas, onMetaChanged } from "./registry.domain.mjs";
|
|
3
|
-
import { getObservedWaitHost } from "./observed-
|
|
3
|
+
import { getObservedWaitHost } from "./observed-wait-client.domain.mjs";
|
|
4
4
|
import { isTerminalStatus } from "./types.domain.mjs";
|
|
5
5
|
import { backgroundTaskProgressAt, observeBackgroundTaskStall } from "./stall.domain.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { backgroundGoalObservation, onBackgroundObservation } from "./work-observation.domain.mjs";
|
|
7
7
|
const GOAL_READY_EVENT = "pi-better-goal:ready";
|
|
8
8
|
const GOAL_REGISTER_PROVIDER_EVENT = "pi-better-goal:register-provider";
|
|
9
9
|
const readySubscriptions = new WeakSet();
|
|
10
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);
|
|
11
17
|
return {
|
|
12
18
|
providerId: "background-tasks",
|
|
13
19
|
label: "Background Tasks",
|
|
14
|
-
items
|
|
15
|
-
|
|
16
|
-
.filter((meta) => isVisibleGoalActivity(meta, ctx, now))
|
|
17
|
-
.map(backgroundTaskToGoalItem),
|
|
18
|
-
...durable
|
|
19
|
-
.filter((task) => isVisibleDurableGoalActivity(task, ctx, now))
|
|
20
|
-
.map(durableTaskToGoalItem),
|
|
21
|
-
],
|
|
20
|
+
items,
|
|
21
|
+
nextDeadline: deadlines.length ? Math.min(...deadlines) : null,
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
export function registerBackgroundTasksGoalProvider(pi) {
|
|
@@ -27,20 +27,35 @@ export function registerBackgroundTasksGoalProvider(pi) {
|
|
|
27
27
|
id: "background-tasks",
|
|
28
28
|
label: "Background Tasks",
|
|
29
29
|
scope: "session",
|
|
30
|
-
|
|
31
|
-
|
|
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 };
|
|
32
35
|
if (snapshot.status !== "ready")
|
|
33
36
|
throw new Error(snapshot.reason ?? "Background activity is unverified");
|
|
34
37
|
const durable = snapshot.rows.filter((row) => row.meta.durable).map((row) => row.meta);
|
|
35
38
|
const legacy = snapshot.rows.filter((row) => !row.meta.durable).map((row) => row.meta);
|
|
36
|
-
|
|
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 };
|
|
37
42
|
},
|
|
38
43
|
// A durable operation change must refresh Goal activity even though it
|
|
39
44
|
// never writes a mutable legacy registry meta.
|
|
40
|
-
onActivityChanged: (notify) => {
|
|
45
|
+
onActivityChanged: (notify, ctx) => {
|
|
41
46
|
const offRuntime = onBackgroundObservation(pi, notify);
|
|
42
|
-
const offMeta = onMetaChanged(
|
|
43
|
-
|
|
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
|
+
});
|
|
44
59
|
return () => {
|
|
45
60
|
offRuntime();
|
|
46
61
|
offMeta();
|
|
@@ -75,6 +90,8 @@ function belongsToGoalActivitySession(meta, ctx) {
|
|
|
75
90
|
if (origin) {
|
|
76
91
|
if (origin.cwd !== active.cwd)
|
|
77
92
|
return false;
|
|
93
|
+
if (origin.branchId && !ctx.sessionManager.getBranch().some(entry => entry.id === origin.branchId))
|
|
94
|
+
return false;
|
|
78
95
|
if (origin.sessionId || active.sessionId)
|
|
79
96
|
return origin.sessionId === active.sessionId;
|
|
80
97
|
return true;
|
|
@@ -100,6 +117,8 @@ function isVisibleDurableGoalActivity(task, ctx, now) {
|
|
|
100
117
|
const active = getGoalActivityOrigin(ctx);
|
|
101
118
|
if (task.owner.workspace !== active.cwd)
|
|
102
119
|
return false;
|
|
120
|
+
if (task.owner.branchId && !ctx.sessionManager.getBranch().some(entry => entry.id === task.owner.branchId))
|
|
121
|
+
return false;
|
|
103
122
|
if (active.sessionId || task.owner.sessionId) {
|
|
104
123
|
if (task.owner.sessionId !== active.sessionId)
|
|
105
124
|
return false;
|