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,10 +1,11 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { listMetas, onMetaChanged } from "./registry.js";
|
|
3
|
-
import { getObservedWaitHost
|
|
3
|
+
import { getObservedWaitHost } from "./observed-wait-client.js";
|
|
4
|
+
import type { DurableTaskProjection } from "./observed-waits.js";
|
|
4
5
|
import type { BackgroundTaskMeta } from "./types.js";
|
|
5
6
|
import { isTerminalStatus } from "./types.js";
|
|
6
7
|
import { backgroundTaskProgressAt, observeBackgroundTaskStall } from "./stall.js";
|
|
7
|
-
import {
|
|
8
|
+
import { backgroundGoalObservation, onBackgroundObservation } from "./work-observation.js";
|
|
8
9
|
|
|
9
10
|
const GOAL_READY_EVENT = "pi-better-goal:ready";
|
|
10
11
|
const GOAL_REGISTER_PROVIDER_EVENT = "pi-better-goal:register-provider";
|
|
@@ -27,6 +28,7 @@ export interface GoalBackgroundProviderSnapshot {
|
|
|
27
28
|
providerId: string;
|
|
28
29
|
label?: string;
|
|
29
30
|
items: GoalBackgroundWorkItem[];
|
|
31
|
+
nextDeadline?: number | null;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
export function collectBackgroundTaskGoalActivity(
|
|
@@ -35,17 +37,17 @@ export function collectBackgroundTaskGoalActivity(
|
|
|
35
37
|
now = Date.now(),
|
|
36
38
|
durable: readonly DurableTaskProjection[] = [],
|
|
37
39
|
): GoalBackgroundProviderSnapshot {
|
|
40
|
+
const items = [
|
|
41
|
+
...metas.filter((meta) => isVisibleGoalActivity(meta, ctx, now)).map(backgroundTaskToGoalItem),
|
|
42
|
+
...durable.filter((task) => isVisibleDurableGoalActivity(task, ctx, now)).map(durableTaskToGoalItem),
|
|
43
|
+
];
|
|
44
|
+
const deadlines = items.filter(item => item.terminal && typeof item.endedAt === "number")
|
|
45
|
+
.map(item => item.endedAt! + TERMINAL_GOAL_ACTIVITY_RETENTION_MS).filter(deadline => deadline > now);
|
|
38
46
|
return {
|
|
39
47
|
providerId: "background-tasks",
|
|
40
48
|
label: "Background Tasks",
|
|
41
|
-
items
|
|
42
|
-
|
|
43
|
-
.filter((meta) => isVisibleGoalActivity(meta, ctx, now))
|
|
44
|
-
.map(backgroundTaskToGoalItem),
|
|
45
|
-
...durable
|
|
46
|
-
.filter((task) => isVisibleDurableGoalActivity(task, ctx, now))
|
|
47
|
-
.map(durableTaskToGoalItem),
|
|
48
|
-
],
|
|
49
|
+
items,
|
|
50
|
+
nextDeadline: deadlines.length ? Math.min(...deadlines) : null,
|
|
49
51
|
};
|
|
50
52
|
}
|
|
51
53
|
|
|
@@ -55,19 +57,30 @@ export function registerBackgroundTasksGoalProvider(pi: ExtensionAPI): void {
|
|
|
55
57
|
id: "background-tasks",
|
|
56
58
|
label: "Background Tasks",
|
|
57
59
|
scope: "session",
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
activityVersion: 1,
|
|
61
|
+
getActivity: async (ctx: ExtensionContext, options?: { cachedOnly?: boolean }) => {
|
|
62
|
+
const snapshot = await backgroundGoalObservation(pi, ctx, options?.cachedOnly);
|
|
63
|
+
if (!snapshot && options?.cachedOnly) return { providerId: "background-tasks", coverage: "unverified", items: [], nextDeadline: null };
|
|
60
64
|
if (snapshot.status !== "ready") throw new Error(snapshot.reason ?? "Background activity is unverified");
|
|
61
65
|
const durable = snapshot.rows.filter((row: any) => row.meta.durable).map((row: any) => row.meta);
|
|
62
66
|
const legacy = snapshot.rows.filter((row: any) => !row.meta.durable).map((row: any) => row.meta);
|
|
63
|
-
|
|
67
|
+
const activity = collectBackgroundTaskGoalActivity(legacy, ctx, Date.now(), durable);
|
|
68
|
+
const deadlines = [activity.nextDeadline, snapshot.nextDeadline].filter((value): value is number => typeof value === "number" && value > Date.now());
|
|
69
|
+
return { ...activity, nextDeadline: deadlines.length ? Math.min(...deadlines) : null };
|
|
64
70
|
},
|
|
65
71
|
// A durable operation change must refresh Goal activity even though it
|
|
66
72
|
// never writes a mutable legacy registry meta.
|
|
67
|
-
onActivityChanged: (notify: () => void) => {
|
|
73
|
+
onActivityChanged: (notify: () => void, ctx?: ExtensionContext) => {
|
|
68
74
|
const offRuntime = onBackgroundObservation(pi, notify);
|
|
69
|
-
const offMeta = onMetaChanged(
|
|
70
|
-
|
|
75
|
+
const offMeta = onMetaChanged(meta => {
|
|
76
|
+
if (ctx && meta && !belongsToGoalActivitySession(meta, ctx)) return;
|
|
77
|
+
notify();
|
|
78
|
+
});
|
|
79
|
+
const offDurable = getObservedWaitHost(pi)?.onDurableTaskChange(change => {
|
|
80
|
+
if (ctx && (change.workspace !== ctx.cwd || change.sessionId !== ctx.sessionManager.getSessionId())) return;
|
|
81
|
+
if (ctx && change.branchId && !ctx.sessionManager.getBranch().some(entry => entry.id === change.branchId)) return;
|
|
82
|
+
notify();
|
|
83
|
+
});
|
|
71
84
|
return () => {
|
|
72
85
|
offRuntime();
|
|
73
86
|
offMeta();
|
|
@@ -100,6 +113,7 @@ function belongsToGoalActivitySession(meta: BackgroundTaskMeta, ctx: ExtensionCo
|
|
|
100
113
|
const origin = meta.callbackOrigin;
|
|
101
114
|
if (origin) {
|
|
102
115
|
if (origin.cwd !== active.cwd) return false;
|
|
116
|
+
if (origin.branchId && !ctx.sessionManager.getBranch().some(entry => entry.id === origin.branchId)) return false;
|
|
103
117
|
if (origin.sessionId || active.sessionId) return origin.sessionId === active.sessionId;
|
|
104
118
|
return true;
|
|
105
119
|
}
|
|
@@ -126,6 +140,7 @@ function isVisibleDurableGoalActivity(
|
|
|
126
140
|
if (ctx) {
|
|
127
141
|
const active = getGoalActivityOrigin(ctx);
|
|
128
142
|
if (task.owner.workspace !== active.cwd) return false;
|
|
143
|
+
if (task.owner.branchId && !ctx.sessionManager.getBranch().some(entry => entry.id === task.owner.branchId)) return false;
|
|
129
144
|
if (active.sessionId || task.owner.sessionId) {
|
|
130
145
|
if (task.owner.sessionId !== active.sessionId) return false;
|
|
131
146
|
}
|
|
@@ -1,20 +1,34 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-background-tasks/src/index.ts. Do not edit directly.
|
|
2
|
+
import { shouldRestoreWorkObservation } from "./shared-work-client.mjs";
|
|
2
3
|
import { initializeNavigatorPanels } from "./shared-navigator-panels.domain.mjs";
|
|
3
4
|
import { registerBackgroundTasksGoalProvider } from "./goal-provider.domain.mjs";
|
|
4
5
|
import { createBackgroundTasksNavigator } from "./navigator-provider.domain.mjs";
|
|
5
|
-
import { createBackgroundTaskRuntime } from "./runtime.domain.mjs";
|
|
6
6
|
import { createManagedBackgroundFrontend } from "./managed-frontend.domain.mjs";
|
|
7
7
|
import { observeForegroundSandboxPolicy } from "./sandbox.domain.mjs";
|
|
8
8
|
import { registerTools } from "./tools.domain.mjs";
|
|
9
9
|
import { deliverBackgroundTasksPrompt } from "./prompt.domain.mjs";
|
|
10
10
|
import { closeBackgroundObservation } from "./work-observation.domain.mjs";
|
|
11
|
+
import { readBackgroundReviewInterval, saveBackgroundReviewInterval } from "./review-settings.domain.mjs";
|
|
11
12
|
export default function backgroundTasksExtension(pi) {
|
|
12
13
|
// The frontend owns native UI/delivery only. Mechanical tools run in the
|
|
13
|
-
// fixed server service
|
|
14
|
-
const runtime = createBackgroundTaskRuntime();
|
|
14
|
+
// fixed server service. Register their native definitions before the first turn.
|
|
15
15
|
const { host: observedWaits, proxy, ui } = createManagedBackgroundFrontend(pi);
|
|
16
|
-
const navigator = createBackgroundTasksNavigator(
|
|
16
|
+
const navigator = createBackgroundTasksNavigator(undefined, ui);
|
|
17
17
|
initializeNavigatorPanels(pi);
|
|
18
|
+
const intervalLabel = (minutes) => `${minutes} minute${minutes === 1 ? "" : "s"}`;
|
|
19
|
+
const reviewSetting = {
|
|
20
|
+
id: "background-review-interval",
|
|
21
|
+
label: "Background wait review interval",
|
|
22
|
+
values: [1, 5, 10, 15, 30, 60].map(intervalLabel),
|
|
23
|
+
get: () => intervalLabel(readBackgroundReviewInterval()),
|
|
24
|
+
change(value) {
|
|
25
|
+
saveBackgroundReviewInterval(Number.parseInt(value, 10));
|
|
26
|
+
void observedWaits.reconcileNow().catch(() => undefined);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
const registerReviewSetting = () => pi.events.emit("harness-settings:register", reviewSetting);
|
|
30
|
+
let stopReviewSettings = pi.events.on("harness-settings:request", registerReviewSetting);
|
|
31
|
+
registerReviewSetting();
|
|
18
32
|
// Sections on a host that renders them; text only where it renders none.
|
|
19
33
|
// Returning a prompt on modern pi would set forceSystemPrompt, and the request
|
|
20
34
|
// would then carry a snapshot, so sections published after it never arrive.
|
|
@@ -26,7 +40,8 @@ export default function backgroundTasksExtension(pi) {
|
|
|
26
40
|
observeForegroundSandboxPolicy(pi);
|
|
27
41
|
// Registered before registerTools(pi), so this runs before running tasks are resumed.
|
|
28
42
|
pi.on("session_start", async (_event, ctx) => {
|
|
29
|
-
|
|
43
|
+
stopReviewSettings ??= pi.events.on("harness-settings:request", registerReviewSetting);
|
|
44
|
+
registerReviewSetting();
|
|
30
45
|
registerBackgroundTasksGoalProvider(pi);
|
|
31
46
|
navigator.ensureBackgroundTasksNavigator(ctx);
|
|
32
47
|
});
|
|
@@ -36,17 +51,18 @@ export default function backgroundTasksExtension(pi) {
|
|
|
36
51
|
navigator.clearBackgroundTasksNavigatorSession();
|
|
37
52
|
});
|
|
38
53
|
pi.on("session_shutdown", async (_event, ctx) => {
|
|
54
|
+
stopReviewSettings?.();
|
|
55
|
+
stopReviewSettings = undefined;
|
|
39
56
|
closeBackgroundObservation(pi);
|
|
40
57
|
// /reload, session replacement, and quit load a fresh instance; stop this one's timers (#324).
|
|
41
58
|
observedWaits.close();
|
|
42
|
-
runtime.suspendScheduledWork();
|
|
43
59
|
navigator.clearBackgroundTasksNavigatorSession();
|
|
44
60
|
});
|
|
45
|
-
registerTools(proxy,
|
|
61
|
+
registerTools(proxy, undefined, navigator.refreshBackgroundTasksNavigator, { resumeLocal: false });
|
|
46
62
|
// Registered after registerTools so the callback batcher has its session
|
|
47
63
|
// context before a reconciled delivery can enqueue a parent notification.
|
|
48
|
-
pi.on("session_start",
|
|
49
|
-
observedWaits.start(ctx);
|
|
64
|
+
pi.on("session_start", (event, ctx) => {
|
|
65
|
+
observedWaits.start(ctx, shouldRestoreWorkObservation(event, ctx.sessionManager));
|
|
50
66
|
});
|
|
51
67
|
// A fork or branch navigation does not restart the session, but it changes
|
|
52
68
|
// which continuation may receive a queued callback. Update the host snapshot
|
|
@@ -1,21 +1,35 @@
|
|
|
1
|
+
import { shouldRestoreWorkObservation } from "./shared-work-client.mjs";
|
|
1
2
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
3
|
import { initializeNavigatorPanels } from "./shared-navigator-panels.ts";
|
|
3
4
|
import { registerBackgroundTasksGoalProvider } from "./goal-provider.js";
|
|
4
5
|
import { createBackgroundTasksNavigator } from "./navigator-provider.js";
|
|
5
|
-
import { createBackgroundTaskRuntime } from "./runtime.js";
|
|
6
6
|
import { createManagedBackgroundFrontend } from "./managed-frontend.js";
|
|
7
7
|
import { observeForegroundSandboxPolicy } from "./sandbox.js";
|
|
8
8
|
import { registerTools } from "./tools.js";
|
|
9
9
|
import { deliverBackgroundTasksPrompt } from "./prompt.js";
|
|
10
10
|
import { closeBackgroundObservation } from "./work-observation.js";
|
|
11
|
+
import { readBackgroundReviewInterval, saveBackgroundReviewInterval } from "./review-settings.js";
|
|
11
12
|
|
|
12
13
|
export default function backgroundTasksExtension(pi: ExtensionAPI): void {
|
|
13
14
|
// The frontend owns native UI/delivery only. Mechanical tools run in the
|
|
14
|
-
// fixed server service
|
|
15
|
-
const runtime = createBackgroundTaskRuntime();
|
|
15
|
+
// fixed server service. Register their native definitions before the first turn.
|
|
16
16
|
const {host: observedWaits, proxy, ui} = createManagedBackgroundFrontend(pi);
|
|
17
|
-
const navigator = createBackgroundTasksNavigator(
|
|
17
|
+
const navigator = createBackgroundTasksNavigator(undefined, ui);
|
|
18
18
|
initializeNavigatorPanels(pi);
|
|
19
|
+
const intervalLabel = (minutes: number) => `${minutes} minute${minutes === 1 ? "" : "s"}`;
|
|
20
|
+
const reviewSetting = {
|
|
21
|
+
id: "background-review-interval",
|
|
22
|
+
label: "Background wait review interval",
|
|
23
|
+
values: [1, 5, 10, 15, 30, 60].map(intervalLabel),
|
|
24
|
+
get: () => intervalLabel(readBackgroundReviewInterval()),
|
|
25
|
+
change(value: string) {
|
|
26
|
+
saveBackgroundReviewInterval(Number.parseInt(value, 10));
|
|
27
|
+
void observedWaits.reconcileNow().catch(() => undefined);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
const registerReviewSetting = () => pi.events.emit("harness-settings:register", reviewSetting);
|
|
31
|
+
let stopReviewSettings: (() => void) | undefined = pi.events.on("harness-settings:request", registerReviewSetting);
|
|
32
|
+
registerReviewSetting();
|
|
19
33
|
// Sections on a host that renders them; text only where it renders none.
|
|
20
34
|
// Returning a prompt on modern pi would set forceSystemPrompt, and the request
|
|
21
35
|
// would then carry a snapshot, so sections published after it never arrive.
|
|
@@ -27,7 +41,8 @@ export default function backgroundTasksExtension(pi: ExtensionAPI): void {
|
|
|
27
41
|
observeForegroundSandboxPolicy(pi);
|
|
28
42
|
// Registered before registerTools(pi), so this runs before running tasks are resumed.
|
|
29
43
|
pi.on("session_start", async (_event, ctx) => {
|
|
30
|
-
|
|
44
|
+
stopReviewSettings ??= pi.events.on("harness-settings:request", registerReviewSetting);
|
|
45
|
+
registerReviewSetting();
|
|
31
46
|
registerBackgroundTasksGoalProvider(pi);
|
|
32
47
|
navigator.ensureBackgroundTasksNavigator(ctx);
|
|
33
48
|
});
|
|
@@ -37,17 +52,18 @@ export default function backgroundTasksExtension(pi: ExtensionAPI): void {
|
|
|
37
52
|
navigator.clearBackgroundTasksNavigatorSession();
|
|
38
53
|
});
|
|
39
54
|
pi.on("session_shutdown", async (_event, ctx) => {
|
|
55
|
+
stopReviewSettings?.();
|
|
56
|
+
stopReviewSettings = undefined;
|
|
40
57
|
closeBackgroundObservation(pi);
|
|
41
58
|
// /reload, session replacement, and quit load a fresh instance; stop this one's timers (#324).
|
|
42
59
|
observedWaits.close();
|
|
43
|
-
runtime.suspendScheduledWork();
|
|
44
60
|
navigator.clearBackgroundTasksNavigatorSession();
|
|
45
61
|
});
|
|
46
|
-
registerTools(proxy,
|
|
62
|
+
registerTools(proxy, undefined, navigator.refreshBackgroundTasksNavigator, {resumeLocal:false});
|
|
47
63
|
// Registered after registerTools so the callback batcher has its session
|
|
48
64
|
// context before a reconciled delivery can enqueue a parent notification.
|
|
49
|
-
pi.on("session_start",
|
|
50
|
-
observedWaits.start(ctx);
|
|
65
|
+
pi.on("session_start", (event, ctx) => {
|
|
66
|
+
observedWaits.start(ctx, shouldRestoreWorkObservation(event, ctx.sessionManager));
|
|
51
67
|
});
|
|
52
68
|
// A fork or branch navigation does not restart the session, but it changes
|
|
53
69
|
// which continuation may receive a queued callback. Update the host snapshot
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { createHash, timingSafeEqual } from 'node:crypto';
|
|
3
3
|
import { lstatSync, readFileSync, realpathSync } from 'node:fs';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
|
-
import { readProcessStartTokenFresh } from "./process-identity.domain.mjs";
|
|
5
|
+
import { readAdmissionStartToken, readProcessStartTokenFresh } from "./process-identity.domain.mjs";
|
|
6
6
|
const ordered = (value) => value === null || typeof value !== 'object' ? value : Array.isArray(value) ? value.map(ordered) : Object.fromEntries(Object.keys(value).sort().map(key => [key, ordered(value[key])]));
|
|
7
7
|
export const backgroundDigest = (value) => createHash('sha256').update(JSON.stringify(ordered(value))).digest('hex');
|
|
8
8
|
export function readBackgroundAuthority(root, instance, authority, requireLive = true) {
|
|
@@ -14,14 +14,17 @@ export function readBackgroundAuthority(root, instance, authority, requireLive =
|
|
|
14
14
|
|| !stat.isFile() || stat.isSymbolicLink() || stat.uid !== dir.uid || (stat.mode & 0o077) || stat.size > 1024 * 1024)
|
|
15
15
|
throw new Error('background-authority-refused');
|
|
16
16
|
const record = JSON.parse(readFileSync(path, 'utf8')), digest = createHash('sha256').update(authority.secret).digest('hex');
|
|
17
|
-
if (record.version !== 1 || record.instanceId !== instance || record.id !== authority.id || typeof record.secretHash !== 'string'
|
|
17
|
+
if ((record.version !== 1 && record.version !== 2) || record.instanceId !== instance || record.id !== authority.id || typeof record.secretHash !== 'string'
|
|
18
18
|
|| record.secretHash.length !== digest.length || !timingSafeEqual(Buffer.from(record.secretHash), Buffer.from(digest))
|
|
19
19
|
|| typeof record.key !== 'string' || !record.key || typeof record.tool !== 'string' || !record.owner?.sessionId
|
|
20
20
|
|| record.owner.workspace !== realpathSync(record.owner.workspace) || !Number.isSafeInteger(record.pid) || !record.start
|
|
21
21
|
|| !Array.isArray(record.branchIds) || record.branchIds.some((id) => typeof id !== 'string'))
|
|
22
22
|
throw new Error('background-authority-refused');
|
|
23
23
|
if (requireLive) {
|
|
24
|
-
|
|
24
|
+
const start = record.version === 2 ? readAdmissionStartToken(record.pid) : readProcessStartTokenFresh(record.pid);
|
|
25
|
+
if (!start)
|
|
26
|
+
throw new Error('background-authority-refused: cannot verify host start time');
|
|
27
|
+
if (start !== record.start)
|
|
25
28
|
throw new Error('background-authority-refused: host identity changed');
|
|
26
29
|
process.kill(record.pid, 0);
|
|
27
30
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash, timingSafeEqual } from 'node:crypto';
|
|
2
2
|
import { lstatSync, readFileSync, realpathSync } from 'node:fs';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
-
import { readProcessStartTokenFresh } from './process-identity.js';
|
|
4
|
+
import { readAdmissionStartToken, readProcessStartTokenFresh } from './process-identity.js';
|
|
5
5
|
const ordered = (value: any): any => value === null || typeof value !== 'object' ? value : Array.isArray(value) ? value.map(ordered) : Object.fromEntries(Object.keys(value).sort().map(key => [key, ordered(value[key])]));
|
|
6
6
|
export const backgroundDigest = (value: unknown) => createHash('sha256').update(JSON.stringify(ordered(value))).digest('hex');
|
|
7
7
|
export function readBackgroundAuthority(root: string, instance: string, authority: any, requireLive = true): any {
|
|
@@ -13,14 +13,16 @@ export function readBackgroundAuthority(root: string, instance: string, authorit
|
|
|
13
13
|
|| !stat.isFile() || stat.isSymbolicLink() || stat.uid !== dir.uid || (stat.mode & 0o077) || stat.size > 1024 * 1024)
|
|
14
14
|
throw new Error('background-authority-refused');
|
|
15
15
|
const record = JSON.parse(readFileSync(path, 'utf8')), digest = createHash('sha256').update(authority.secret).digest('hex');
|
|
16
|
-
if (record.version !== 1 || record.instanceId !== instance || record.id !== authority.id || typeof record.secretHash !== 'string'
|
|
16
|
+
if ((record.version !== 1 && record.version !== 2) || record.instanceId !== instance || record.id !== authority.id || typeof record.secretHash !== 'string'
|
|
17
17
|
|| record.secretHash.length !== digest.length || !timingSafeEqual(Buffer.from(record.secretHash), Buffer.from(digest))
|
|
18
18
|
|| typeof record.key !== 'string' || !record.key || typeof record.tool !== 'string' || !record.owner?.sessionId
|
|
19
19
|
|| record.owner.workspace !== realpathSync(record.owner.workspace) || !Number.isSafeInteger(record.pid) || !record.start
|
|
20
20
|
|| !Array.isArray(record.branchIds) || record.branchIds.some((id: unknown) => typeof id !== 'string'))
|
|
21
21
|
throw new Error('background-authority-refused');
|
|
22
22
|
if (requireLive) {
|
|
23
|
-
|
|
23
|
+
const start = record.version === 2 ? readAdmissionStartToken(record.pid) : readProcessStartTokenFresh(record.pid);
|
|
24
|
+
if (!start) throw new Error('background-authority-refused: cannot verify host start time');
|
|
25
|
+
if (start !== record.start)
|
|
24
26
|
throw new Error('background-authority-refused: host identity changed');
|
|
25
27
|
process.kill(record.pid, 0);
|
|
26
28
|
}
|
|
@@ -4,25 +4,37 @@ import { lstatSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, w
|
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { getAgentDir } from '@earendil-works/pi-coding-agent';
|
|
6
6
|
import { backgroundDigest } from "./managed-authority.domain.mjs";
|
|
7
|
-
import { readProcessStartTokenFresh } from "./process-identity.domain.mjs";
|
|
7
|
+
import { readAdmissionStartToken, readProcessStartTokenFresh } from "./process-identity.domain.mjs";
|
|
8
8
|
import { currentForegroundSandboxPolicy, FOREGROUND_SANDBOX_POLICY_CHANNEL } from "./sandbox.domain.mjs";
|
|
9
|
-
import { backgroundObservation } from "./work-observation.domain.mjs";
|
|
9
|
+
import { backgroundListNeedsHistory, backgroundObservation } from "./work-observation.domain.mjs";
|
|
10
10
|
/** Native host proof carries scope and captured policy, never a transcript or module path. */
|
|
11
11
|
export async function requestBackgroundTool(pi, ctx, key, tool, params, parameters, signal) {
|
|
12
12
|
if (signal?.aborted)
|
|
13
13
|
throw new Error('Background request cancelled before admission');
|
|
14
|
-
|
|
14
|
+
const input = params && typeof params === 'object' ? params : {};
|
|
15
|
+
const list = tool === 'bg_task_list' || (tool === 'bg_task' && input.action === 'list');
|
|
16
|
+
if (list && backgroundListNeedsHistory(input)) {
|
|
17
|
+
// The root history index is shared. Wait on its read plane before acquiring
|
|
18
|
+
// a grant or entering the serialized tool queue, even for an all-session list.
|
|
19
|
+
const snapshot = await backgroundObservation(pi, ctx, true, false, { limit: 1 }, { timeoutMs: 60000, signal });
|
|
20
|
+
if (snapshot.status !== 'ready')
|
|
21
|
+
throw new Error(snapshot.reason ?? `Background history is ${snapshot.status}`);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
await backgroundObservation(pi, ctx);
|
|
25
|
+
}
|
|
26
|
+
signal?.throwIfAborted();
|
|
15
27
|
const root = realpathSync(getAgentDir()), registration = JSON.parse(readFileSync(join(root, 'server-registration-v1.json'), 'utf8'));
|
|
16
28
|
if (registration.version !== 1 || registration.agentDir !== root)
|
|
17
29
|
throw new Error('Invalid runtime registration');
|
|
18
30
|
const module = new URL('./shared-work-client.mjs', import.meta.url).href;
|
|
19
|
-
const {
|
|
31
|
+
const { connectWorkClient } = await import(module);
|
|
20
32
|
const directory = join(root, 'background-tool-admission');
|
|
21
33
|
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
22
34
|
const stat = lstatSync(directory);
|
|
23
35
|
if (!stat.isDirectory() || stat.isSymbolicLink() || stat.uid !== process.getuid?.() || (stat.mode & 0o077))
|
|
24
36
|
throw new Error('Unsafe Background admission directory');
|
|
25
|
-
const client =
|
|
37
|
+
const client = await connectWorkClient(join(registration.serverDir, 'pi-server.sock'), root, ['runtime-background-execution-v1'], { signal });
|
|
26
38
|
const id = randomUUID(), secret = randomBytes(32).toString('hex'), path = join(directory, `${id}.json`);
|
|
27
39
|
let off;
|
|
28
40
|
const abort = () => client.close();
|
|
@@ -34,9 +46,11 @@ export async function requestBackgroundTool(pi, ctx, key, tool, params, paramete
|
|
|
34
46
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
35
47
|
if (!sessionId)
|
|
36
48
|
throw new Error('Background tools require a native session identity');
|
|
37
|
-
const
|
|
49
|
+
const version = hello.capabilities?.includes("runtime-background-admission-v2") ? 2 : 1;
|
|
50
|
+
const start = version === 2 ? readAdmissionStartToken(process.pid) : readProcessStartTokenFresh(process.pid);
|
|
51
|
+
const record = { version, id, secretHash: createHash('sha256').update(secret).digest('hex'), instanceId: hello.instanceId,
|
|
38
52
|
owner: { kind: 'parent-session', sessionId, workspace: realpathSync(ctx.cwd) }, branchIds, projectTrusted: ctx.isProjectTrusted(),
|
|
39
|
-
pid: process.pid, start
|
|
53
|
+
pid: process.pid, start, key, tool, params, parametersDigest: parameters === undefined ? undefined : backgroundDigest(parameters), policy };
|
|
40
54
|
const staged = `${path}.tmp`;
|
|
41
55
|
writeFileSync(staged, JSON.stringify(record), { flag: 'wx', mode: 0o600 });
|
|
42
56
|
renameSync(staged, path);
|
|
@@ -3,25 +3,36 @@ import { lstatSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, w
|
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { getAgentDir, type ExtensionAPI, type ExtensionContext } from '@earendil-works/pi-coding-agent';
|
|
5
5
|
import { backgroundDigest } from './managed-authority.js';
|
|
6
|
-
import { readProcessStartTokenFresh } from './process-identity.js';
|
|
6
|
+
import { readAdmissionStartToken, readProcessStartTokenFresh } from './process-identity.js';
|
|
7
7
|
import { currentForegroundSandboxPolicy, FOREGROUND_SANDBOX_POLICY_CHANNEL } from './sandbox.js';
|
|
8
|
-
import { backgroundObservation } from './work-observation.js';
|
|
8
|
+
import { backgroundListNeedsHistory, backgroundObservation } from './work-observation.js';
|
|
9
9
|
/** Native host proof carries scope and captured policy, never a transcript or module path. */
|
|
10
10
|
export async function requestBackgroundTool(pi: ExtensionAPI, ctx: ExtensionContext, key: string, tool: string, params: unknown, parameters?: unknown, signal?: AbortSignal): Promise<any> {
|
|
11
11
|
if (signal?.aborted)
|
|
12
12
|
throw new Error('Background request cancelled before admission');
|
|
13
|
-
|
|
13
|
+
const input = params && typeof params === 'object' ? params as Record<string, unknown> : {};
|
|
14
|
+
const list = tool === 'bg_task_list' || (tool === 'bg_task' && input.action === 'list');
|
|
15
|
+
if (list && backgroundListNeedsHistory(input)) {
|
|
16
|
+
// The root history index is shared. Wait on its read plane before acquiring
|
|
17
|
+
// a grant or entering the serialized tool queue, even for an all-session list.
|
|
18
|
+
const snapshot = await backgroundObservation(pi, ctx, true, false, { limit: 1 }, { timeoutMs: 60000, signal });
|
|
19
|
+
if (snapshot.status !== 'ready')
|
|
20
|
+
throw new Error(snapshot.reason ?? `Background history is ${snapshot.status}`);
|
|
21
|
+
} else {
|
|
22
|
+
await backgroundObservation(pi, ctx);
|
|
23
|
+
}
|
|
24
|
+
signal?.throwIfAborted();
|
|
14
25
|
const root = realpathSync(getAgentDir()), registration = JSON.parse(readFileSync(join(root, 'server-registration-v1.json'), 'utf8'));
|
|
15
26
|
if (registration.version !== 1 || registration.agentDir !== root)
|
|
16
27
|
throw new Error('Invalid runtime registration');
|
|
17
28
|
const module = new URL('./shared-work-client.mjs', import.meta.url).href;
|
|
18
|
-
const {
|
|
29
|
+
const { connectWorkClient } = await import(module);
|
|
19
30
|
const directory = join(root, 'background-tool-admission');
|
|
20
31
|
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
21
32
|
const stat = lstatSync(directory);
|
|
22
33
|
if (!stat.isDirectory() || stat.isSymbolicLink() || stat.uid !== process.getuid?.() || (stat.mode & 0o077))
|
|
23
34
|
throw new Error('Unsafe Background admission directory');
|
|
24
|
-
const client =
|
|
35
|
+
const client = await connectWorkClient(join(registration.serverDir, 'pi-server.sock'), root, ['runtime-background-execution-v1'], { signal });
|
|
25
36
|
const id = randomUUID(), secret = randomBytes(32).toString('hex'), path = join(directory, `${id}.json`);
|
|
26
37
|
let off: unknown;
|
|
27
38
|
const abort = () => client.close();
|
|
@@ -33,9 +44,11 @@ export async function requestBackgroundTool(pi: ExtensionAPI, ctx: ExtensionCont
|
|
|
33
44
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
34
45
|
if (!sessionId)
|
|
35
46
|
throw new Error('Background tools require a native session identity');
|
|
36
|
-
const
|
|
47
|
+
const version = hello.capabilities?.includes("runtime-background-admission-v2") ? 2 : 1;
|
|
48
|
+
const start = version === 2 ? readAdmissionStartToken(process.pid) : readProcessStartTokenFresh(process.pid);
|
|
49
|
+
const record = { version, id, secretHash: createHash('sha256').update(secret).digest('hex'), instanceId: hello.instanceId,
|
|
37
50
|
owner: { kind: 'parent-session', sessionId, workspace: realpathSync(ctx.cwd) }, branchIds, projectTrusted: ctx.isProjectTrusted(),
|
|
38
|
-
pid: process.pid, start
|
|
51
|
+
pid: process.pid, start, key, tool, params, parametersDigest: parameters === undefined ? undefined : backgroundDigest(parameters), policy };
|
|
39
52
|
const staged = `${path}.tmp`;
|
|
40
53
|
writeFileSync(staged, JSON.stringify(record), { flag: 'wx', mode: 0o600 });
|
|
41
54
|
renameSync(staged, path);
|