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
|
@@ -8,6 +8,7 @@ import { unlink } from "node:fs/promises";
|
|
|
8
8
|
import { homedir } from "node:os";
|
|
9
9
|
import { maybeBuildSandboxCommand } from "./shared-sandbox-core.domain.mjs";
|
|
10
10
|
export const PROCESS_LIST_TOOL = "process_list";
|
|
11
|
+
export const PROCESS_ACCESS_OFF = "Sandbox: Process access is Off. Enable Read in /sandbox.";
|
|
11
12
|
const EXECUTABLE = "/usr/bin/pgrep";
|
|
12
13
|
const MAX_STDOUT = 1024 * 1024;
|
|
13
14
|
const MAX_STDERR = 2048;
|
|
@@ -147,11 +148,11 @@ function run(file, argv, cwd, home, signal) {
|
|
|
147
148
|
});
|
|
148
149
|
});
|
|
149
150
|
}
|
|
150
|
-
export function createProcessListToolDefinition(cwd, controller, access) {
|
|
151
|
+
export function createProcessListToolDefinition(cwd, controller, access, accessDenied = () => PROCESS_ACCESS_OFF) {
|
|
151
152
|
let identity;
|
|
152
153
|
const checkAccess = () => {
|
|
153
154
|
if (access() !== "read")
|
|
154
|
-
throw new Error(
|
|
155
|
+
throw new Error(accessDenied());
|
|
155
156
|
};
|
|
156
157
|
const checkExecutable = () => {
|
|
157
158
|
const current = executableIdentity();
|
|
@@ -9,6 +9,7 @@ import { maybeBuildSandboxCommand, type SandboxWritePolicy } from "./shared-sand
|
|
|
9
9
|
import type { TaskFileController } from "./shared-task-files.ts";
|
|
10
10
|
|
|
11
11
|
export const PROCESS_LIST_TOOL = "process_list";
|
|
12
|
+
export const PROCESS_ACCESS_OFF = "Sandbox: Process access is Off. Enable Read in /sandbox.";
|
|
12
13
|
|
|
13
14
|
const EXECUTABLE = "/usr/bin/pgrep";
|
|
14
15
|
const MAX_STDOUT = 1024 * 1024;
|
|
@@ -139,10 +140,15 @@ function run(file: string, argv: string[], cwd: string, home: string, signal?: A
|
|
|
139
140
|
});
|
|
140
141
|
}
|
|
141
142
|
|
|
142
|
-
export function createProcessListToolDefinition(
|
|
143
|
+
export function createProcessListToolDefinition(
|
|
144
|
+
cwd: string,
|
|
145
|
+
controller: TaskFileController,
|
|
146
|
+
access: () => "off" | "read",
|
|
147
|
+
accessDenied: () => string = () => PROCESS_ACCESS_OFF,
|
|
148
|
+
) {
|
|
143
149
|
let identity: string | undefined;
|
|
144
150
|
const checkAccess = () => {
|
|
145
|
-
if (access() !== "read") throw new Error(
|
|
151
|
+
if (access() !== "read") throw new Error(accessDenied());
|
|
146
152
|
};
|
|
147
153
|
const checkExecutable = () => {
|
|
148
154
|
const current = executableIdentity();
|
|
@@ -9,7 +9,7 @@ import { basename, dirname, isAbsolute, join, parse, resolve, sep } from "node:p
|
|
|
9
9
|
import { canonicalizePath, compileWritePolicy, isRemovableUnderWrite } from "./shared-sandbox-core.domain.mjs";
|
|
10
10
|
import { createTaskFileOperations } from "./shared-task-files.domain.mjs";
|
|
11
11
|
import { APPLY_PATCH_TOOL, createApplyPatchToolDefinition } from "./shared-task-apply-patch.domain.mjs";
|
|
12
|
-
import { createProcessListToolDefinition, PROCESS_LIST_TOOL } from "./shared-task-process-list.domain.mjs";
|
|
12
|
+
import { createProcessListToolDefinition, PROCESS_ACCESS_OFF, PROCESS_LIST_TOOL } from "./shared-task-process-list.domain.mjs";
|
|
13
13
|
import { createRunApplicationToolDefinition, RUN_APPLICATION_TOOL } from "./shared-task-application.domain.mjs";
|
|
14
14
|
import { createTaskExecutor, directShellInterpreter, SHELL_SCRIPTS_OFF, shellInterpreterOff } from "./shared-task-exec.domain.mjs";
|
|
15
15
|
export const TASK_BUILTINS = Object.freeze(["read", "write", "edit", "bash", PROCESS_LIST_TOOL, RUN_APPLICATION_TOOL]);
|
|
@@ -141,7 +141,7 @@ export function installTaskTools(pi, options) {
|
|
|
141
141
|
pi.registerTool(own(createEditToolDefinition(cwd, { operations: files.edit })));
|
|
142
142
|
pi.registerTool(own(options.bashDefinition ? options.bashDefinition(cwd, bash) : createBashToolDefinition(cwd, { operations: bash })));
|
|
143
143
|
pi.registerTool(own(createRunApplicationToolDefinition(cwd, commandExec)));
|
|
144
|
-
pi.registerTool(own(createProcessListToolDefinition(cwd, controller, options.processAccess ?? (() => "off"))));
|
|
144
|
+
pi.registerTool(own(createProcessListToolDefinition(cwd, controller, options.processAccess ?? (() => "off"), processAccessDenied)));
|
|
145
145
|
if (options.applyPatch) {
|
|
146
146
|
const patchFiles = createTaskFileOperations(controller, options.diagnostics, "apply_patch");
|
|
147
147
|
pi.registerTool(own(createApplyPatchToolDefinition(cwd, {
|
|
@@ -150,6 +150,7 @@ export function installTaskTools(pi, options) {
|
|
|
150
150
|
}, PiCodingAgent.withFileMutationQueue)));
|
|
151
151
|
}
|
|
152
152
|
};
|
|
153
|
+
const processAccessDenied = options.processAccessDenied ?? (() => PROCESS_ACCESS_OFF);
|
|
153
154
|
register(options.cwd);
|
|
154
155
|
pi.on("user_bash", () => ({ operations: bash }));
|
|
155
156
|
pi.on("tool_call", (event, ctx) => {
|
|
@@ -192,7 +193,7 @@ export function installTaskTools(pi, options) {
|
|
|
192
193
|
}
|
|
193
194
|
}
|
|
194
195
|
if (event.toolName === PROCESS_LIST_TOOL && options.processAccess?.() !== "read") {
|
|
195
|
-
return blocked(
|
|
196
|
+
return blocked(processAccessDenied(), "process-inspection");
|
|
196
197
|
}
|
|
197
198
|
return;
|
|
198
199
|
}
|
|
@@ -10,7 +10,7 @@ import { basename, dirname, isAbsolute, join, parse, resolve, sep } from "node:p
|
|
|
10
10
|
import { canonicalizePath, compileWritePolicy, isRemovableUnderWrite, type SandboxPermissions } from "./shared-sandbox-core.ts";
|
|
11
11
|
import { createTaskFileOperations, type TaskFileController } from "./shared-task-files.ts";
|
|
12
12
|
import { APPLY_PATCH_TOOL, createApplyPatchToolDefinition } from "./shared-task-apply-patch.ts";
|
|
13
|
-
import { createProcessListToolDefinition, PROCESS_LIST_TOOL } from "./shared-task-process-list.ts";
|
|
13
|
+
import { createProcessListToolDefinition, PROCESS_ACCESS_OFF, PROCESS_LIST_TOOL } from "./shared-task-process-list.ts";
|
|
14
14
|
import { createRunApplicationToolDefinition, RUN_APPLICATION_TOOL } from "./shared-task-application.ts";
|
|
15
15
|
import { createTaskExecutor, directShellInterpreter, SHELL_SCRIPTS_OFF, shellInterpreterOff } from "./shared-task-exec.ts";
|
|
16
16
|
import type { SandboxDiagnostics, DiagnosticResource } from "./shared-sandbox-diagnostics.ts";
|
|
@@ -124,6 +124,7 @@ export function installTaskTools(pi: ExtensionAPI, options: {
|
|
|
124
124
|
applyPatch?: boolean;
|
|
125
125
|
/** Human-controlled access to the fixed read-only inventory adapter. */
|
|
126
126
|
processAccess?: () => "off" | "read";
|
|
127
|
+
processAccessDenied?: () => string;
|
|
127
128
|
/** Build the admitted bash definition from the confined operations (default: the SDK bash tool). */
|
|
128
129
|
bashDefinition?: (cwd: string, operations: BashOperations) => ReturnType<typeof createBashToolDefinition>;
|
|
129
130
|
diagnostics?: Pick<SandboxDiagnostics, "observe">;
|
|
@@ -150,7 +151,7 @@ export function installTaskTools(pi: ExtensionAPI, options: {
|
|
|
150
151
|
pi.registerTool(own(createEditToolDefinition(cwd, { operations: files.edit })));
|
|
151
152
|
pi.registerTool(own(options.bashDefinition ? options.bashDefinition(cwd, bash) : createBashToolDefinition(cwd, { operations: bash })));
|
|
152
153
|
pi.registerTool(own(createRunApplicationToolDefinition(cwd, commandExec)) as any);
|
|
153
|
-
pi.registerTool(own(createProcessListToolDefinition(cwd, controller, options.processAccess ?? (() => "off"))) as any);
|
|
154
|
+
pi.registerTool(own(createProcessListToolDefinition(cwd, controller, options.processAccess ?? (() => "off"), processAccessDenied)) as any);
|
|
154
155
|
if (options.applyPatch) {
|
|
155
156
|
const patchFiles = createTaskFileOperations(controller, options.diagnostics, "apply_patch");
|
|
156
157
|
pi.registerTool(own(createApplyPatchToolDefinition(cwd, {
|
|
@@ -159,6 +160,7 @@ export function installTaskTools(pi: ExtensionAPI, options: {
|
|
|
159
160
|
}, PiCodingAgent.withFileMutationQueue)) as any);
|
|
160
161
|
}
|
|
161
162
|
};
|
|
163
|
+
const processAccessDenied = options.processAccessDenied ?? (() => PROCESS_ACCESS_OFF);
|
|
162
164
|
register(options.cwd);
|
|
163
165
|
pi.on("user_bash", () => ({ operations: bash }));
|
|
164
166
|
pi.on("tool_call", (event, ctx) => {
|
|
@@ -195,7 +197,7 @@ export function installTaskTools(pi: ExtensionAPI, options: {
|
|
|
195
197
|
}
|
|
196
198
|
}
|
|
197
199
|
if (event.toolName === PROCESS_LIST_TOOL && options.processAccess?.() !== "read") {
|
|
198
|
-
return blocked(
|
|
200
|
+
return blocked(processAccessDenied(), "process-inspection");
|
|
199
201
|
}
|
|
200
202
|
return;
|
|
201
203
|
}
|
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
* - Guarded tools are harness adapters that go through the task's guarded file
|
|
7
7
|
* operations, so the file rules govern them. Today: apply_patch.
|
|
8
8
|
* - Trusted tools are extension tools admitted by name AND owning package.
|
|
9
|
-
* They run in the child Pi process, outside the file rules
|
|
10
|
-
* one in /sandbox. Network tools are refused while Network is Off.
|
|
9
|
+
* They run in the child Pi process, outside the file rules. The launch record pins their source. Network tools are refused while Network is Off.
|
|
11
10
|
*/
|
|
12
11
|
import { existsSync } from "node:fs";
|
|
13
12
|
import { dirname, join } from "node:path";
|
|
@@ -64,6 +63,12 @@ export function toolPackage(tool) {
|
|
|
64
63
|
const pkg = info.source && info.source !== "builtin" ? info.source : base;
|
|
65
64
|
return { name: tool.name, package: pkg, root: base };
|
|
66
65
|
}
|
|
66
|
+
export function supportsChildProvider(name, pkg, root) {
|
|
67
|
+
if (RESERVED_TOOL_NAMES.includes(name))
|
|
68
|
+
return false;
|
|
69
|
+
const harnessOwners = [pkg, root].map(id => id.replace(/\/+$/, "")).filter(id => HARNESS_PACKAGES.test(id));
|
|
70
|
+
return !harnessOwners.length || (SSH_TOOL_NAMES.includes(name) && harnessOwners.every(id => SSH_PACKAGE.test(id)));
|
|
71
|
+
}
|
|
67
72
|
/** Candidate trusted tools, excluding core builtins, guarded names and non-SSH harness tools. */
|
|
68
73
|
export function discoverTrustedTools(tools) {
|
|
69
74
|
const found = [];
|
|
@@ -73,9 +78,7 @@ export function discoverTrustedTools(tools) {
|
|
|
73
78
|
const owner = toolPackage(tool);
|
|
74
79
|
if (!owner)
|
|
75
80
|
continue;
|
|
76
|
-
|
|
77
|
-
.filter((id) => HARNESS_PACKAGES.test(id));
|
|
78
|
-
if (harnessOwners.length && !(SSH_TOOL_NAMES.includes(tool.name) && harnessOwners.every((id) => SSH_PACKAGE.test(id))))
|
|
81
|
+
if (!supportsChildProvider(tool.name, owner.package, owner.root))
|
|
79
82
|
continue;
|
|
80
83
|
if (!found.some((t) => t.name === owner.name && t.package === owner.package)) {
|
|
81
84
|
found.push(tool.sourceInfo?.source === "builtin" ? { ...owner, source: "builtin" } : owner);
|
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
* - Guarded tools are harness adapters that go through the task's guarded file
|
|
6
6
|
* operations, so the file rules govern them. Today: apply_patch.
|
|
7
7
|
* - Trusted tools are extension tools admitted by name AND owning package.
|
|
8
|
-
* They run in the child Pi process, outside the file rules
|
|
9
|
-
* one in /sandbox. Network tools are refused while Network is Off.
|
|
8
|
+
* They run in the child Pi process, outside the file rules. The launch record pins their source. Network tools are refused while Network is Off.
|
|
10
9
|
*/
|
|
11
10
|
import { existsSync } from "node:fs";
|
|
12
11
|
import { dirname, join } from "node:path";
|
|
@@ -97,6 +96,12 @@ export function toolPackage(tool: ToolSource): DiscoveredTool | undefined {
|
|
|
97
96
|
return { name: tool.name, package: pkg, root: base };
|
|
98
97
|
}
|
|
99
98
|
|
|
99
|
+
export function supportsChildProvider(name: string, pkg: string, root: string): boolean {
|
|
100
|
+
if (RESERVED_TOOL_NAMES.includes(name)) return false;
|
|
101
|
+
const harnessOwners = [pkg, root].map(id => id.replace(/\/+$/, "")).filter(id => HARNESS_PACKAGES.test(id));
|
|
102
|
+
return !harnessOwners.length || (SSH_TOOL_NAMES.includes(name) && harnessOwners.every(id => SSH_PACKAGE.test(id)));
|
|
103
|
+
}
|
|
104
|
+
|
|
100
105
|
/** Candidate trusted tools, excluding core builtins, guarded names and non-SSH harness tools. */
|
|
101
106
|
export function discoverTrustedTools(tools: readonly ToolSource[]): DiscoveredTool[] {
|
|
102
107
|
const found: DiscoveredTool[] = [];
|
|
@@ -104,9 +109,7 @@ export function discoverTrustedTools(tools: readonly ToolSource[]): DiscoveredTo
|
|
|
104
109
|
if (RESERVED_TOOL_NAMES.includes(tool.name)) continue;
|
|
105
110
|
const owner = toolPackage(tool);
|
|
106
111
|
if (!owner) continue;
|
|
107
|
-
|
|
108
|
-
.filter((id) => HARNESS_PACKAGES.test(id));
|
|
109
|
-
if (harnessOwners.length && !(SSH_TOOL_NAMES.includes(tool.name) && harnessOwners.every((id) => SSH_PACKAGE.test(id)))) continue;
|
|
112
|
+
if (!supportsChildProvider(tool.name, owner.package, owner.root)) continue;
|
|
110
113
|
if (!found.some((t) => t.name === owner.name && t.package === owner.package)) {
|
|
111
114
|
found.push(tool.sourceInfo?.source === "builtin" ? { ...owner, source: "builtin" } : owner);
|
|
112
115
|
}
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-subagents/shared-work-client.mjs. Do not edit directly.
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
2
3
|
import { connect } from "node:net";
|
|
3
4
|
import { performance } from "node:perf_hooks";
|
|
5
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
6
|
+
/** A persisted session can own work even when its selected branch is empty. */
|
|
7
|
+
export function shouldRestoreWorkObservation(event, session) {
|
|
8
|
+
if (event?.piBetterObserveWork)
|
|
9
|
+
return true;
|
|
10
|
+
const reason = event?.reason;
|
|
11
|
+
if (reason === "new")
|
|
12
|
+
return false;
|
|
13
|
+
if (reason !== "startup" || typeof session?.getSessionFile !== "function")
|
|
14
|
+
return true;
|
|
15
|
+
const file = session.getSessionFile();
|
|
16
|
+
return file ? existsSync(file) : Boolean(session.getLeafId?.());
|
|
17
|
+
}
|
|
4
18
|
/** SDK-free observation stream. Cached snapshots are the only synchronous read API. */
|
|
5
19
|
export class WorkClient {
|
|
6
20
|
socket;
|
|
@@ -12,6 +26,11 @@ export class WorkClient {
|
|
|
12
26
|
scope;
|
|
13
27
|
buffer = "";
|
|
14
28
|
closed = false;
|
|
29
|
+
recoveryTimer;
|
|
30
|
+
recoveryActive = false;
|
|
31
|
+
recoveryAgain = false;
|
|
32
|
+
recoveryDelay = 100;
|
|
33
|
+
scopeGeneration = 0;
|
|
15
34
|
constructor(socketPath, agentDir, requiredCapabilities = []) {
|
|
16
35
|
this.socket = typeof socketPath === "string" ? connect(socketPath) : socketPath;
|
|
17
36
|
this.socket.setEncoding("utf8");
|
|
@@ -32,10 +51,10 @@ export class WorkClient {
|
|
|
32
51
|
}
|
|
33
52
|
if (message.event.type === "resync_required") {
|
|
34
53
|
this.degrade(message.event.reason);
|
|
35
|
-
|
|
54
|
+
this.scheduleRecovery();
|
|
36
55
|
}
|
|
37
56
|
else if (message.event.type === "runtime_snapshot")
|
|
38
|
-
this.accept(message.event.snapshot);
|
|
57
|
+
this.accept(message.event.snapshot, message.event.previousSeq);
|
|
39
58
|
}
|
|
40
59
|
else {
|
|
41
60
|
const request = this.pending.get(message.id);
|
|
@@ -54,7 +73,9 @@ export class WorkClient {
|
|
|
54
73
|
}
|
|
55
74
|
}
|
|
56
75
|
});
|
|
57
|
-
this.socket.on("error", error => this.fail(error)
|
|
76
|
+
this.socket.on("error", error => this.fail(["ECONNRESET", "EPIPE"].includes(error.code)
|
|
77
|
+
? Object.assign(new Error(`runtime-unavailable: disconnected (${error.code}); resync required`, { cause: error }), { code: error.code })
|
|
78
|
+
: error));
|
|
58
79
|
this.socket.on("close", () => this.fail(new Error("runtime-unavailable: disconnected; resync required")));
|
|
59
80
|
this.ready = this.request("hello", { protocolVersion: 1, runtimeRoot: agentDir, requiredCapabilities: ["runtime-state-v1", "runtime-subscriptions-v1", ...requiredCapabilities] })
|
|
60
81
|
.then(async (hello) => { if (typeof socketPath === "string" && hello.capabilities?.includes("runtime-client-retention-v1"))
|
|
@@ -80,31 +101,78 @@ export class WorkClient {
|
|
|
80
101
|
this.snapshot = { ...this.snapshot, status: "degraded", reason, rows: this.snapshot?.rows ?? [] };
|
|
81
102
|
this.notify();
|
|
82
103
|
}
|
|
83
|
-
accept(snapshot) {
|
|
104
|
+
accept(snapshot, previousSeq) {
|
|
84
105
|
if (this.snapshot?.instanceId === snapshot.instanceId && snapshot.seq < this.snapshot.seq)
|
|
85
106
|
return;
|
|
86
107
|
if (this.snapshot?.instanceId && this.snapshot.instanceId !== snapshot.instanceId) {
|
|
87
108
|
this.degrade("instance-changed: resync required");
|
|
88
109
|
snapshot = { ...snapshot, resyncRequired: true, resyncReason: "instance-changed" };
|
|
89
110
|
}
|
|
90
|
-
else if (this.snapshot?.seq !== undefined &&
|
|
111
|
+
else if (this.snapshot?.seq !== undefined && Number.isSafeInteger(previousSeq) && previousSeq > this.snapshot.seq) {
|
|
91
112
|
this.degrade("sequence-gap: replacing with a full authoritative snapshot");
|
|
92
113
|
snapshot = { ...snapshot, resyncRequired: true, resyncReason: "sequence-gap" };
|
|
93
114
|
}
|
|
94
|
-
//
|
|
115
|
+
// Global seq may skip unrelated changes; only a missing subscription
|
|
116
|
+
// predecessor indicates loss. The received snapshot is still complete.
|
|
95
117
|
this.snapshot = Object.freeze(snapshot);
|
|
96
118
|
this.notify();
|
|
97
119
|
}
|
|
120
|
+
scheduleRecovery(delay = 0) {
|
|
121
|
+
if (this.closed)
|
|
122
|
+
return;
|
|
123
|
+
if (this.recoveryActive) {
|
|
124
|
+
this.recoveryAgain = true;
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (this.recoveryTimer)
|
|
128
|
+
return;
|
|
129
|
+
this.recoveryTimer = setTimeout(() => {
|
|
130
|
+
this.recoveryTimer = undefined;
|
|
131
|
+
void this.recover();
|
|
132
|
+
}, delay);
|
|
133
|
+
this.recoveryTimer.unref?.();
|
|
134
|
+
}
|
|
135
|
+
async recover() {
|
|
136
|
+
const generation = this.scopeGeneration;
|
|
137
|
+
this.recoveryActive = true;
|
|
138
|
+
let retry = false;
|
|
139
|
+
try {
|
|
140
|
+
await this.resync();
|
|
141
|
+
this.recoveryDelay = 100;
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
if (!this.closed && generation === this.scopeGeneration) {
|
|
145
|
+
this.degrade(String(error));
|
|
146
|
+
retry = /runtime-(?:timeout|overloaded|unhealthy)/.test(String(error));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
finally {
|
|
150
|
+
this.recoveryActive = false;
|
|
151
|
+
const again = this.recoveryAgain;
|
|
152
|
+
this.recoveryAgain = false;
|
|
153
|
+
if (!this.closed && (again || retry && generation === this.scopeGeneration)) {
|
|
154
|
+
this.scheduleRecovery(again ? 0 : this.recoveryDelay);
|
|
155
|
+
this.recoveryDelay = Math.min(1000, this.recoveryDelay * 2);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
98
159
|
async subscribe(scope) {
|
|
99
160
|
await this.ready;
|
|
161
|
+
this.scopeGeneration++;
|
|
162
|
+
clearTimeout(this.recoveryTimer);
|
|
163
|
+
this.recoveryTimer = undefined;
|
|
164
|
+
this.recoveryAgain = false;
|
|
165
|
+
this.recoveryDelay = 100;
|
|
100
166
|
this.scope = scope;
|
|
101
167
|
const snapshot = await this.request("runtime_subscribe", { scope });
|
|
102
168
|
this.accept(snapshot);
|
|
103
169
|
return snapshot;
|
|
104
170
|
}
|
|
105
171
|
async resync() {
|
|
172
|
+
const generation = this.scopeGeneration;
|
|
106
173
|
const snapshot = await this.request("runtime_subscribe", { scope: this.scope, sinceSeq: this.snapshot?.seq, instanceId: this.snapshot?.instanceId });
|
|
107
|
-
this.
|
|
174
|
+
if (!this.closed && generation === this.scopeGeneration)
|
|
175
|
+
this.accept(snapshot);
|
|
108
176
|
return snapshot;
|
|
109
177
|
}
|
|
110
178
|
async get(scope) {
|
|
@@ -122,6 +190,9 @@ export class WorkClient {
|
|
|
122
190
|
if (this.closed)
|
|
123
191
|
return;
|
|
124
192
|
this.closed = true;
|
|
193
|
+
this.scopeGeneration++;
|
|
194
|
+
clearTimeout(this.recoveryTimer);
|
|
195
|
+
this.recoveryTimer = undefined;
|
|
125
196
|
for (const request of this.pending.values()) {
|
|
126
197
|
clearTimeout(request.timer);
|
|
127
198
|
request.reject(error);
|
|
@@ -134,3 +205,99 @@ export class WorkClient {
|
|
|
134
205
|
}
|
|
135
206
|
close() { this.fail(new Error("runtime-unavailable: client closed")); this.listeners.clear(); this.catalogListeners.clear(); }
|
|
136
207
|
}
|
|
208
|
+
// Shared across the standalone extension copies, but never across agent roots.
|
|
209
|
+
const recoveryKey = Symbol.for("pi-better-runtime.connection-recovery.v2");
|
|
210
|
+
const recoveries = globalThis[recoveryKey] ??= new Map();
|
|
211
|
+
const connectionDemands = globalThis[Symbol.for("pi-better-runtime.connection-demand.v2")] ??= new Map();
|
|
212
|
+
/** Establish a transport only. Never replay an application request after dispatch. */
|
|
213
|
+
export async function connectWorkClient(socketPath, agentDir, capabilities = [], options = {}) {
|
|
214
|
+
const timeoutMs = options.timeoutMs ?? 60000;
|
|
215
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0)
|
|
216
|
+
throw new Error("Invalid connection timeout");
|
|
217
|
+
const deadline = performance.now() + timeoutMs;
|
|
218
|
+
const started = performance.now();
|
|
219
|
+
let backoff = 100, recovered = false, lastError, recoveryError, ownedRecovery;
|
|
220
|
+
const remaining = () => Math.max(1, deadline - performance.now());
|
|
221
|
+
const key = JSON.stringify([agentDir, socketPath]);
|
|
222
|
+
connectionDemands.set(key, (connectionDemands.get(key) ?? 0) + 1);
|
|
223
|
+
try {
|
|
224
|
+
while (performance.now() < deadline) {
|
|
225
|
+
options.signal?.throwIfAborted();
|
|
226
|
+
const client = new WorkClient(socketPath, agentDir, capabilities);
|
|
227
|
+
const abort = () => client.close();
|
|
228
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
229
|
+
const timer = setTimeout(() => client.close(), remaining());
|
|
230
|
+
try {
|
|
231
|
+
await client.ready;
|
|
232
|
+
options.signal?.throwIfAborted();
|
|
233
|
+
return client;
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
client.close();
|
|
237
|
+
options.signal?.throwIfAborted();
|
|
238
|
+
lastError = error;
|
|
239
|
+
if (recoveryError)
|
|
240
|
+
throw recoveryError;
|
|
241
|
+
if (!["ENOENT", "ECONNREFUSED", "ECONNRESET", "EPIPE"].includes(error?.code)
|
|
242
|
+
&& !/runtime-unavailable: (?:disconnected|server closed)/.test(String(error)))
|
|
243
|
+
throw error;
|
|
244
|
+
}
|
|
245
|
+
finally {
|
|
246
|
+
clearTimeout(timer);
|
|
247
|
+
options.signal?.removeEventListener("abort", abort);
|
|
248
|
+
}
|
|
249
|
+
// Most replacement gaps need only a reconnect. Startup remains owner-safe.
|
|
250
|
+
if (!recovered && options.recover && performance.now() - started >= 250 && performance.now() < deadline) {
|
|
251
|
+
recovered = true;
|
|
252
|
+
let recovery = recoveries.get(key);
|
|
253
|
+
if (!recovery) {
|
|
254
|
+
const controller = new AbortController();
|
|
255
|
+
const budget = Math.ceil(remaining());
|
|
256
|
+
const timer = setTimeout(() => {
|
|
257
|
+
controller.abort(new Error("runtime-unavailable: reconnect deadline exceeded during recovery"));
|
|
258
|
+
}, budget);
|
|
259
|
+
const promise = waitForRecovery(Promise.resolve().then(() => options.recover({ timeoutMs: budget, signal: controller.signal })), controller.signal)
|
|
260
|
+
.finally(() => clearTimeout(timer));
|
|
261
|
+
recovery = { promise, controller, key };
|
|
262
|
+
recoveries.set(key, recovery);
|
|
263
|
+
void recovery.promise.finally(() => { if (recoveries.get(key) === recovery)
|
|
264
|
+
recoveries.delete(key); }).catch(() => { });
|
|
265
|
+
}
|
|
266
|
+
// A caller can cancel its wait without cancelling another caller's recovery.
|
|
267
|
+
// Keep trying the transport while the owner-safe installer waits.
|
|
268
|
+
// A replacement can accept compatible clients before the pinned
|
|
269
|
+
// installer finishes; waiting for it would stall all subscribers.
|
|
270
|
+
ownedRecovery = recovery;
|
|
271
|
+
void recovery.promise.catch(error => { recoveryError = error; });
|
|
272
|
+
}
|
|
273
|
+
if (performance.now() >= deadline)
|
|
274
|
+
break;
|
|
275
|
+
await delay(Math.min(backoff, remaining()), undefined, { signal: options.signal });
|
|
276
|
+
backoff = Math.min(1000, backoff * 2);
|
|
277
|
+
}
|
|
278
|
+
throw new Error("runtime-unavailable: reconnect deadline exceeded; task state is unknown, retry after recovery", { cause: lastError });
|
|
279
|
+
}
|
|
280
|
+
finally {
|
|
281
|
+
const remainingDemand = connectionDemands.get(key) - 1;
|
|
282
|
+
if (remainingDemand)
|
|
283
|
+
connectionDemands.set(key, remainingDemand);
|
|
284
|
+
else {
|
|
285
|
+
connectionDemands.delete(key);
|
|
286
|
+
const recovery = recoveries.get(key) ?? ownedRecovery;
|
|
287
|
+
if (recovery) {
|
|
288
|
+
recoveries.delete(key);
|
|
289
|
+
recovery.controller.abort();
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
function waitForRecovery(recovery, signal) {
|
|
295
|
+
return new Promise((resolve, reject) => {
|
|
296
|
+
const finish = (callback, value) => { signal.removeEventListener("abort", abort); callback(value); };
|
|
297
|
+
const abort = () => finish(reject, signal.reason);
|
|
298
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
299
|
+
recovery.then(value => finish(resolve, value), error => finish(reject, error));
|
|
300
|
+
if (signal.aborted)
|
|
301
|
+
abort();
|
|
302
|
+
});
|
|
303
|
+
}
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-subagents/subagent-tools.ts. Do not edit directly.
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* Guarded: apply_patch, a harness adapter on the guarded file operations.
|
|
6
|
-
* Trusted: a tool ticked in /sandbox, admitted by name AND owning package, whose
|
|
7
|
-
* package is loaded into the child. `toolExtensions` in config.json still picks
|
|
8
|
-
* the package to load (an override), but the loaded package must be the ticked one.
|
|
9
|
-
*/
|
|
2
|
+
/** Bind selected tools to their confined adapter or canonical provider before startup (ADR 0027). */
|
|
3
|
+
import { supportedChildEntrypoint } from "./config.domain.mjs";
|
|
10
4
|
import { canonicalizePath } from "./shared-sandbox-core.domain.mjs";
|
|
11
|
-
import { isNetworkTool, packageLabel,
|
|
5
|
+
import { isNetworkTool, packageLabel, discoverTrustedTools, RESERVED_TOOL_NAMES } from "./shared-task-tools.domain.mjs";
|
|
12
6
|
export const APPLY_PATCH = "apply_patch";
|
|
13
7
|
function specList(value) {
|
|
14
8
|
if (typeof value === "string")
|
|
@@ -17,6 +11,7 @@ function specList(value) {
|
|
|
17
11
|
}
|
|
18
12
|
export function planTaskTools(options) {
|
|
19
13
|
const plan = { applyPatch: false, trusted: [], refused: [] };
|
|
14
|
+
const registered = discoverTrustedTools(options.registered);
|
|
20
15
|
for (const name of options.requested) {
|
|
21
16
|
if (name === "process_list" && options.processAccess !== "read") {
|
|
22
17
|
plan.refused.push({ name, reason: "Process access is Off; enable Read in /sandbox" });
|
|
@@ -25,15 +20,11 @@ export function planTaskTools(options) {
|
|
|
25
20
|
if (options.builtins.includes(name))
|
|
26
21
|
continue;
|
|
27
22
|
if (name === APPLY_PATCH) {
|
|
28
|
-
|
|
29
|
-
plan.applyPatch = true;
|
|
30
|
-
else
|
|
31
|
-
plan.refused.push({ name, reason: "apply_patch is off in /sandbox (Subagents · Tools)" });
|
|
23
|
+
plan.applyPatch = true;
|
|
32
24
|
continue;
|
|
33
25
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
plan.refused.push({ name, reason: "not a guarded tool and not ticked as trusted in /sandbox (Subagents · Tools)" });
|
|
26
|
+
if (RESERVED_TOOL_NAMES.includes(name)) {
|
|
27
|
+
plan.refused.push({ name, reason: "no supported task adapter" });
|
|
37
28
|
continue;
|
|
38
29
|
}
|
|
39
30
|
const network = isNetworkTool(name);
|
|
@@ -41,39 +32,32 @@ export function planTaskTools(options) {
|
|
|
41
32
|
plan.refused.push({ name, reason: "needs Network access, which is Off for subagents" });
|
|
42
33
|
continue;
|
|
43
34
|
}
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
const
|
|
35
|
+
// The selected mapping identifies the implementation. Old saved entries can
|
|
36
|
+
// still identify its package when the worker has no configured mapping.
|
|
37
|
+
const mapped = specList(options.toolExtensions?.[name]);
|
|
38
|
+
const packages = mapped.length ? mapped : options.settings.trusted.filter(tool => tool.name === name).map(tool => tool.package);
|
|
47
39
|
let chosen;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const loadPath = options.resolvePath(entry.package);
|
|
54
|
-
if (loadPath) {
|
|
55
|
-
chosen = { package: entry.package, loadPath };
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
problem = `its package ${packageLabel(entry.package)} is not installed`;
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
const owner = options.registered.map(toolPackage).find((tool) => tool?.name === name && tool.package === entry.package);
|
|
62
|
-
const loadPath = owner?.root ?? (entry.package.startsWith("npm:") ? options.resolvePath(entry.package) : undefined);
|
|
63
|
-
if (loadPath) {
|
|
64
|
-
chosen = { package: entry.package, loadPath };
|
|
40
|
+
for (const pkg of packages) {
|
|
41
|
+
const owner = registered.find(tool => tool.name === name && tool.package === pkg);
|
|
42
|
+
const path = mapped.length ? options.resolvePath(pkg) : owner?.root ?? (pkg.startsWith("npm:") ? options.resolvePath(pkg) : undefined);
|
|
43
|
+
if (path) {
|
|
44
|
+
chosen = { package: pkg, loadPath: path };
|
|
65
45
|
break;
|
|
66
46
|
}
|
|
67
|
-
problem = `its package ${packageLabel(entry.package)} can't be found (not installed or not loaded in this Pi)`;
|
|
68
47
|
}
|
|
69
48
|
if (!chosen) {
|
|
70
|
-
|
|
49
|
+
const reason = packages.length ? `provider ${packages.map(packageLabel).join(", ")} is unavailable` : "no provider selected for this worker";
|
|
50
|
+
plan.refused.push({ name, reason });
|
|
71
51
|
continue;
|
|
72
52
|
}
|
|
73
53
|
// A directory is admitted as a package root; a file admits only itself.
|
|
74
54
|
let root;
|
|
75
55
|
try {
|
|
76
56
|
root = canonicalizePath(chosen.loadPath);
|
|
57
|
+
if (!supportedChildEntrypoint(name, chosen.package, root)) {
|
|
58
|
+
plan.refused.push({ name, reason: "provider requires a supported task adapter" });
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
77
61
|
}
|
|
78
62
|
catch {
|
|
79
63
|
plan.refused.push({ name, reason: `its package path ${chosen.loadPath} can't be resolved` });
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Guarded: apply_patch, a harness adapter on the guarded file operations.
|
|
5
|
-
* Trusted: a tool ticked in /sandbox, admitted by name AND owning package, whose
|
|
6
|
-
* package is loaded into the child. `toolExtensions` in config.json still picks
|
|
7
|
-
* the package to load (an override), but the loaded package must be the ticked one.
|
|
8
|
-
*/
|
|
1
|
+
/** Bind selected tools to their confined adapter or canonical provider before startup (ADR 0027). */
|
|
2
|
+
import { supportedChildEntrypoint } from "./config.ts";
|
|
9
3
|
import { canonicalizePath } from "./shared-sandbox-core.ts";
|
|
10
|
-
import { isNetworkTool, packageLabel,
|
|
4
|
+
import { isNetworkTool, packageLabel, discoverTrustedTools, RESERVED_TOOL_NAMES, type SubagentToolSettings, type ToolSource } from "./shared-task-tools.ts";
|
|
11
5
|
import type { TaskExtensionTool } from "./task-policy.ts";
|
|
12
6
|
|
|
13
7
|
export const APPLY_PATCH = "apply_patch";
|
|
@@ -32,12 +26,13 @@ export function planTaskTools(options: {
|
|
|
32
26
|
network: boolean;
|
|
33
27
|
processAccess?: "off" | "read";
|
|
34
28
|
builtins: readonly string[];
|
|
35
|
-
/** Tools registered in the parent Pi (`pi.getAllTools()`), used to
|
|
29
|
+
/** Tools registered in the parent Pi (`pi.getAllTools()`), used to resolve a legacy provider identity. */
|
|
36
30
|
registered: readonly ToolSource[];
|
|
37
31
|
toolExtensions?: Record<string, string | string[]> | null;
|
|
38
32
|
resolvePath: (spec: string) => string | undefined;
|
|
39
33
|
}): TaskToolPlan {
|
|
40
34
|
const plan: TaskToolPlan = { applyPatch: false, trusted: [], refused: [] };
|
|
35
|
+
const registered = discoverTrustedTools(options.registered);
|
|
41
36
|
for (const name of options.requested) {
|
|
42
37
|
if (name === "process_list" && options.processAccess !== "read") {
|
|
43
38
|
plan.refused.push({ name, reason: "Process access is Off; enable Read in /sandbox" });
|
|
@@ -45,13 +40,11 @@ export function planTaskTools(options: {
|
|
|
45
40
|
}
|
|
46
41
|
if (options.builtins.includes(name)) continue;
|
|
47
42
|
if (name === APPLY_PATCH) {
|
|
48
|
-
|
|
49
|
-
else plan.refused.push({ name, reason: "apply_patch is off in /sandbox (Subagents · Tools)" });
|
|
43
|
+
plan.applyPatch = true;
|
|
50
44
|
continue;
|
|
51
45
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
plan.refused.push({ name, reason: "not a guarded tool and not ticked as trusted in /sandbox (Subagents · Tools)" });
|
|
46
|
+
if (RESERVED_TOOL_NAMES.includes(name)) {
|
|
47
|
+
plan.refused.push({ name, reason: "no supported task adapter" });
|
|
55
48
|
continue;
|
|
56
49
|
}
|
|
57
50
|
const network = isNetworkTool(name);
|
|
@@ -59,32 +52,33 @@ export function planTaskTools(options: {
|
|
|
59
52
|
plan.refused.push({ name, reason: "needs Network access, which is Off for subagents" });
|
|
60
53
|
continue;
|
|
61
54
|
}
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
const
|
|
55
|
+
// The selected mapping identifies the implementation. Old saved entries can
|
|
56
|
+
// still identify its package when the worker has no configured mapping.
|
|
57
|
+
const mapped = specList(options.toolExtensions?.[name]);
|
|
58
|
+
const packages = mapped.length ? mapped : options.settings.trusted.filter(tool => tool.name === name).map(tool => tool.package);
|
|
65
59
|
let chosen: { package: string; loadPath: string } | undefined;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const loadPath = options.resolvePath(entry.package);
|
|
71
|
-
if (loadPath) { chosen = { package: entry.package, loadPath }; break; }
|
|
72
|
-
problem = `its package ${packageLabel(entry.package)} is not installed`;
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
const owner = options.registered.map(toolPackage).find((tool) => tool?.name === name && tool.package === entry.package);
|
|
76
|
-
const loadPath = owner?.root ?? (entry.package.startsWith("npm:") ? options.resolvePath(entry.package) : undefined);
|
|
77
|
-
if (loadPath) { chosen = { package: entry.package, loadPath }; break; }
|
|
78
|
-
problem = `its package ${packageLabel(entry.package)} can't be found (not installed or not loaded in this Pi)`;
|
|
60
|
+
for (const pkg of packages) {
|
|
61
|
+
const owner = registered.find(tool => tool.name === name && tool.package === pkg);
|
|
62
|
+
const path = mapped.length ? options.resolvePath(pkg) : owner?.root ?? (pkg.startsWith("npm:") ? options.resolvePath(pkg) : undefined);
|
|
63
|
+
if (path) { chosen = { package: pkg, loadPath: path }; break; }
|
|
79
64
|
}
|
|
80
65
|
if (!chosen) {
|
|
81
|
-
|
|
66
|
+
const reason = packages.length ? `provider ${packages.map(packageLabel).join(", ")} is unavailable` : "no provider selected for this worker";
|
|
67
|
+
plan.refused.push({ name, reason });
|
|
82
68
|
continue;
|
|
83
69
|
}
|
|
84
70
|
// A directory is admitted as a package root; a file admits only itself.
|
|
85
71
|
let root: string;
|
|
86
|
-
try {
|
|
87
|
-
|
|
72
|
+
try {
|
|
73
|
+
root = canonicalizePath(chosen.loadPath);
|
|
74
|
+
if (!supportedChildEntrypoint(name, chosen.package, root)) {
|
|
75
|
+
plan.refused.push({ name, reason: "provider requires a supported task adapter" });
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
} catch {
|
|
79
|
+
plan.refused.push({ name, reason: `its package path ${chosen.loadPath} can't be resolved` });
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
88
82
|
plan.trusted.push({ name, package: chosen.package, root, network, loadPath: chosen.loadPath });
|
|
89
83
|
}
|
|
90
84
|
return plan;
|