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
|
@@ -32,6 +32,7 @@ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
|
32
32
|
import {
|
|
33
33
|
OPERATIONS_ATTEMPT_ID_ENV,
|
|
34
34
|
OPERATIONS_CHILD_ID_ENV,
|
|
35
|
+
OPERATIONS_DEADLINE_AT_ENV,
|
|
35
36
|
OPERATIONS_CONVERSATION_ID_ENV,
|
|
36
37
|
OPERATIONS_ENABLED_ENV,
|
|
37
38
|
OPERATIONS_ENDPOINT_ENV,
|
|
@@ -39,6 +40,7 @@ import {
|
|
|
39
40
|
OPERATIONS_TOKEN_ENV,
|
|
40
41
|
OPERATIONS_WRITER_LEASE_ID_ENV,
|
|
41
42
|
WAIT_OPERATIONS_TOOL,
|
|
43
|
+
assertWaitToolDependencies,
|
|
42
44
|
createToolDescriptor,
|
|
43
45
|
extractResultTaskIds,
|
|
44
46
|
normalizeWaitForOperationsResult,
|
|
@@ -55,17 +57,20 @@ import {
|
|
|
55
57
|
type OperationBridgeLogger,
|
|
56
58
|
type OperationRunHandlers,
|
|
57
59
|
type OperationRunInfo,
|
|
60
|
+
type OperationRequestContext,
|
|
61
|
+
type OperationRunRegistration,
|
|
58
62
|
} from "./worker-operations-host.ts";
|
|
59
63
|
import { captureParkCheckpoint, verifyParkCheckpoint, type ParkCheckpoint } from "./park-checkpoint.ts";
|
|
60
64
|
import { findSavedConversation, readConversationLease } from "./continuation.ts";
|
|
61
65
|
import { commitAssignmentTerminal, readOutcome, coordinatorPath, type AssignmentBinding } from "./assignment-outcomes.ts";
|
|
62
66
|
import { openStore } from "./shared-operation-coordinator/index.ts";
|
|
63
|
-
import { recordAssignmentReport } from "./assignment-report.ts";
|
|
67
|
+
import { recordAssignmentReport, recordAssignmentReportRejection } from "./assignment-report.ts";
|
|
64
68
|
import { currentSandboxPermissions } from "./permission-policy.ts";
|
|
65
69
|
import {
|
|
66
70
|
effectiveStatus,
|
|
67
71
|
isPendingPark,
|
|
68
72
|
listParkRecordCandidates,
|
|
73
|
+
scanParkRecords,
|
|
69
74
|
listMetas,
|
|
70
75
|
listPendingParkedRuns,
|
|
71
76
|
readMeta,
|
|
@@ -328,6 +333,7 @@ export interface WorkerAcknowledgeView {
|
|
|
328
333
|
export interface WorkerWaitReadyEvent {
|
|
329
334
|
readonly waitId: string;
|
|
330
335
|
readonly generation: number;
|
|
336
|
+
readonly parkedAttemptId?: string;
|
|
331
337
|
readonly owner: { kind: string; sessionId: string; workspace: string; branchId?: string | null; goalId?: string | null };
|
|
332
338
|
readonly parentOrigin?: { cwd: string; sessionId?: string };
|
|
333
339
|
readonly taskIds: readonly string[];
|
|
@@ -651,22 +657,22 @@ export function planWorkerBridgeTools(input: {
|
|
|
651
657
|
}
|
|
652
658
|
tools.push(name);
|
|
653
659
|
}
|
|
660
|
+
if (tools.includes(WAIT_OPERATIONS_TOOL)
|
|
661
|
+
&& (!tools.includes("acknowledge_operation_result") || !tools.some(name => name === "bg_task_status" || name === "bg_task_log"))
|
|
662
|
+
&& !(input.explicitTools && allow.has(WAIT_OPERATIONS_TOOL))) {
|
|
663
|
+
tools.splice(tools.indexOf(WAIT_OPERATIONS_TOOL), 1);
|
|
664
|
+
withheld.push({ name: WAIT_OPERATIONS_TOOL, reason: "the authorized tools cannot read and acknowledge terminal evidence" });
|
|
665
|
+
}
|
|
654
666
|
const has = (name: OperationBridgeToolName): boolean => tools.includes(name);
|
|
667
|
+
const capabilities = {
|
|
668
|
+
background: { spawn: has("bg_task_spawn"), watch: has("bg_task_watch"), status: has("bg_task_status"), log: has("bg_task_log") },
|
|
669
|
+
wait: has(WAIT_OPERATIONS_TOOL), acknowledge: has("acknowledge_operation_result"), parking: has(WAIT_OPERATIONS_TOOL),
|
|
670
|
+
};
|
|
671
|
+
assertWaitToolDependencies(capabilities, tools);
|
|
655
672
|
return {
|
|
656
673
|
tools,
|
|
657
674
|
withheld,
|
|
658
|
-
capabilities
|
|
659
|
-
background: {
|
|
660
|
-
spawn: has("bg_task_spawn"),
|
|
661
|
-
watch: has("bg_task_watch"),
|
|
662
|
-
status: has("bg_task_status"),
|
|
663
|
-
log: has("bg_task_log"),
|
|
664
|
-
},
|
|
665
|
-
wait: has(WAIT_OPERATIONS_TOOL),
|
|
666
|
-
acknowledge: has("acknowledge_operation_result"),
|
|
667
|
-
// The bridge derives `wait_for_operations` from `wait && parking`.
|
|
668
|
-
parking: has(WAIT_OPERATIONS_TOOL),
|
|
669
|
-
},
|
|
675
|
+
capabilities,
|
|
670
676
|
};
|
|
671
677
|
}
|
|
672
678
|
|
|
@@ -860,6 +866,8 @@ export interface WorkerOperationsHost {
|
|
|
860
866
|
|
|
861
867
|
function scopeOf(registration: {
|
|
862
868
|
runId: string;
|
|
869
|
+
attemptId?: string;
|
|
870
|
+
assignment?: AssignmentBinding;
|
|
863
871
|
conversationId: string;
|
|
864
872
|
workspace: string;
|
|
865
873
|
authorityReference: string;
|
|
@@ -869,6 +877,7 @@ function scopeOf(registration: {
|
|
|
869
877
|
return {
|
|
870
878
|
runId: registration.runId,
|
|
871
879
|
conversationId: registration.conversationId,
|
|
880
|
+
...(registration.assignment && registration.attemptId ? { assignmentAttemptId: registration.attemptId } : {}),
|
|
872
881
|
workspace: registration.workspace,
|
|
873
882
|
authorityReference: registration.authorityReference,
|
|
874
883
|
branchId: registration.branchId ?? null,
|
|
@@ -937,6 +946,7 @@ export function createWorkerOperationsHost(options: WorkerOperationsHostOptions)
|
|
|
937
946
|
};
|
|
938
947
|
|
|
939
948
|
const register = async (registration: WorkerOperationRegistration): Promise<WorkerOperationHandle> => {
|
|
949
|
+
assertWaitToolDependencies(registration.capabilities, registration.tools);
|
|
940
950
|
const supervised = registration.tools.some((name) => name !== "report_assignment_result");
|
|
941
951
|
if (supervised && !capability.available) {
|
|
942
952
|
const ready = await start();
|
|
@@ -966,6 +976,7 @@ export function createWorkerOperationsHost(options: WorkerOperationsHostOptions)
|
|
|
966
976
|
tools: [...registration.tools],
|
|
967
977
|
capabilities: registration.capabilities as unknown as JsonRecord,
|
|
968
978
|
assignmentOutcomesVersion: 1,
|
|
979
|
+
assignmentTaskOwnership: registration.assignment !== undefined,
|
|
969
980
|
owner,
|
|
970
981
|
...(registration.writerLeaseId ? { writerLeaseId: registration.writerLeaseId } : {}),
|
|
971
982
|
}) : { assignmentOutcomesVersion: 1 };
|
|
@@ -988,8 +999,9 @@ export function createWorkerOperationsHost(options: WorkerOperationsHostOptions)
|
|
|
988
999
|
}
|
|
989
1000
|
};
|
|
990
1001
|
const handlers: OperationRunHandlers = {};
|
|
1002
|
+
let onToolRejected: OperationRunRegistration["onToolRejected"];
|
|
991
1003
|
if (registration.capabilities.reportAssignment && registration.assignment) {
|
|
992
|
-
|
|
1004
|
+
const assertReportAuthority = (context: OperationRequestContext): RunMeta => {
|
|
993
1005
|
const live = host.getRun(registration.runId);
|
|
994
1006
|
const meta = readMeta(registration.runId);
|
|
995
1007
|
if (!live || live.revoked || live.tokenGeneration !== context.tokenGeneration || context.signal.aborted
|
|
@@ -1013,7 +1025,20 @@ export function createWorkerOperationsHost(options: WorkerOperationsHostOptions)
|
|
|
1013
1025
|
} finally { store.close(); }
|
|
1014
1026
|
}
|
|
1015
1027
|
return meta;
|
|
1016
|
-
}
|
|
1028
|
+
};
|
|
1029
|
+
handlers.report_assignment_result = async (params, context) => {
|
|
1030
|
+
let permissions: ReturnType<typeof currentSandboxPermissions>;
|
|
1031
|
+
try { permissions = currentSandboxPermissions(options.pi as never); }
|
|
1032
|
+
catch (error) {
|
|
1033
|
+
recordAssignmentReportRejection(reasonOf(error), () => assertReportAuthority(context));
|
|
1034
|
+
throw error;
|
|
1035
|
+
}
|
|
1036
|
+
return recordAssignmentReport(registration.runId, params,
|
|
1037
|
+
() => assertReportAuthority(context), permissions) as unknown as JsonRecord;
|
|
1038
|
+
};
|
|
1039
|
+
onToolRejected = (error, context) => {
|
|
1040
|
+
if (context.tool === "report_assignment_result") recordAssignmentReportRejection(error.message, () => assertReportAuthority(context));
|
|
1041
|
+
};
|
|
1017
1042
|
}
|
|
1018
1043
|
const execute = (tool: string, params: JsonRecord): Promise<JsonRecord> => rpc.call("execute-tool", {
|
|
1019
1044
|
runId: registration.runId,
|
|
@@ -1082,7 +1107,7 @@ export function createWorkerOperationsHost(options: WorkerOperationsHostOptions)
|
|
|
1082
1107
|
note: typeof params.note === "string" ? params.note : "",
|
|
1083
1108
|
owner,
|
|
1084
1109
|
}) as unknown as WorkerAcknowledgeView;
|
|
1085
|
-
const parked = parkedWaitByGeneration(waitId, generation);
|
|
1110
|
+
const parked = await parkedWaitByGeneration(waitId, generation);
|
|
1086
1111
|
if (parked) updateParkRecord(parked.runId, { phase: "consumed" });
|
|
1087
1112
|
return view;
|
|
1088
1113
|
};
|
|
@@ -1192,6 +1217,7 @@ export function createWorkerOperationsHost(options: WorkerOperationsHostOptions)
|
|
|
1192
1217
|
tools: normalizeToolDescriptors(registration.schemas, registration.capabilities),
|
|
1193
1218
|
ownership: (taskId) => ownsTask(taskId),
|
|
1194
1219
|
handlers,
|
|
1220
|
+
onToolRejected,
|
|
1195
1221
|
});
|
|
1196
1222
|
durable?.save(registration, handle.token);
|
|
1197
1223
|
return {
|
|
@@ -1247,7 +1273,7 @@ export function createWorkerOperationsHost(options: WorkerOperationsHostOptions)
|
|
|
1247
1273
|
export function childEnvironment(
|
|
1248
1274
|
token: string,
|
|
1249
1275
|
endpoint: string,
|
|
1250
|
-
registration: { runId: string; conversationId: string; attemptId: string },
|
|
1276
|
+
registration: { runId: string; conversationId: string; attemptId: string; policy?: { deadlineAt: number | null } },
|
|
1251
1277
|
): Record<string, string> {
|
|
1252
1278
|
return {
|
|
1253
1279
|
[OPERATIONS_ENABLED_ENV]: "1",
|
|
@@ -1257,6 +1283,7 @@ export function childEnvironment(
|
|
|
1257
1283
|
[OPERATIONS_CONVERSATION_ID_ENV]: registration.conversationId,
|
|
1258
1284
|
[OPERATIONS_ATTEMPT_ID_ENV]: registration.attemptId,
|
|
1259
1285
|
[OPERATIONS_CHILD_ID_ENV]: `${registration.runId}:${randomUUID()}`,
|
|
1286
|
+
...(registration.policy ? { [OPERATIONS_DEADLINE_AT_ENV]: String(registration.policy.deadlineAt ?? 0) } : {}),
|
|
1260
1287
|
};
|
|
1261
1288
|
}
|
|
1262
1289
|
|
|
@@ -1538,6 +1565,7 @@ export function ownerBindingFromContext(ctx: ExtensionContext): WaitOwnerBinding
|
|
|
1538
1565
|
export interface ResumeAdmissionRequest {
|
|
1539
1566
|
version: 1;
|
|
1540
1567
|
owner: { sessionId: string; workspace: string; branchId?: string | null; goalId?: string | null };
|
|
1568
|
+
pending?(): void;
|
|
1541
1569
|
reply(gate: { allowed: boolean; reason?: string; revision: number; isCurrent?: () => boolean }): void;
|
|
1542
1570
|
}
|
|
1543
1571
|
|
|
@@ -1552,7 +1580,7 @@ export type ResumeAdmission =
|
|
|
1552
1580
|
export async function requestResumeAdmission(
|
|
1553
1581
|
pi: unknown,
|
|
1554
1582
|
owner: WaitOwnerBinding,
|
|
1555
|
-
options: { timeoutMs?: number } = {},
|
|
1583
|
+
options: { timeoutMs?: number; pendingTimeoutMs?: number } = {},
|
|
1556
1584
|
): Promise<ResumeAdmission> {
|
|
1557
1585
|
const bus = serviceBusOf(pi);
|
|
1558
1586
|
if (!bus) {
|
|
@@ -1567,8 +1595,9 @@ export async function requestResumeAdmission(
|
|
|
1567
1595
|
clearTimeout(timer);
|
|
1568
1596
|
resolve(value);
|
|
1569
1597
|
};
|
|
1570
|
-
|
|
1598
|
+
let timer = setTimeout(() => finish(null), timeoutMs);
|
|
1571
1599
|
timer.unref?.();
|
|
1600
|
+
let pending = false;
|
|
1572
1601
|
const request: ResumeAdmissionRequest = {
|
|
1573
1602
|
version: 1,
|
|
1574
1603
|
owner: {
|
|
@@ -1577,6 +1606,14 @@ export async function requestResumeAdmission(
|
|
|
1577
1606
|
branchId: owner.branchId,
|
|
1578
1607
|
goalId: owner.goalId,
|
|
1579
1608
|
},
|
|
1609
|
+
pending: () => {
|
|
1610
|
+
if (pending || settled || options.pendingTimeoutMs === undefined) return;
|
|
1611
|
+
pending = true;
|
|
1612
|
+
clearTimeout(timer);
|
|
1613
|
+
const budget = Math.max(timeoutMs, Math.min(60_000, options.pendingTimeoutMs));
|
|
1614
|
+
timer = setTimeout(() => finish({ allowed: false, reason: `Workflow admission did not answer within ${budget} ms`, revision: 0 }), budget);
|
|
1615
|
+
timer.unref?.();
|
|
1616
|
+
},
|
|
1580
1617
|
reply: (gate) => {
|
|
1581
1618
|
if (!gate || typeof gate.allowed !== "boolean") {
|
|
1582
1619
|
finish({ allowed: false, reason: "Goal returned a malformed resume admission", revision: -1 });
|
|
@@ -1643,14 +1680,15 @@ export function parkedWaits(): ParkedWait[] {
|
|
|
1643
1680
|
}
|
|
1644
1681
|
|
|
1645
1682
|
export function parkedWaitForRun(runId: string): ParkedWait | null {
|
|
1646
|
-
|
|
1683
|
+
const meta = readMeta(runId);
|
|
1684
|
+
const record = meta && readParkRecord(runId);
|
|
1685
|
+
return meta && record && isPendingPark(record) ? parkedEntry(meta, record) : null;
|
|
1647
1686
|
}
|
|
1648
1687
|
|
|
1649
1688
|
/** A parked attempt's record for one wait generation, in any phase. */
|
|
1650
|
-
export function parkedWaitByGeneration(waitId: string, generation: number): ParkedWait | null {
|
|
1651
|
-
for (const meta of
|
|
1652
|
-
|
|
1653
|
-
if (!record || record.waitId !== waitId || record.generation !== generation) continue;
|
|
1689
|
+
export async function parkedWaitByGeneration(waitId: string, generation: number): Promise<ParkedWait | null> {
|
|
1690
|
+
for await (const { meta, record } of scanParkRecords()) {
|
|
1691
|
+
if (record.waitId !== waitId || record.generation !== generation) continue;
|
|
1654
1692
|
return parkedEntry(meta, record);
|
|
1655
1693
|
}
|
|
1656
1694
|
return null;
|
|
@@ -2130,20 +2168,29 @@ export function createResumeOrchestration(options: ResumeOrchestrationOptions):
|
|
|
2130
2168
|
};
|
|
2131
2169
|
|
|
2132
2170
|
const resume = (park: ParkedWait) => options.dispatch
|
|
2133
|
-
? options.dispatch(park, () => resumeInScope(park))
|
|
2171
|
+
? options.dispatch(park, () => resumeInScope(park)).catch(error => hold(park, reasonOf(error)))
|
|
2134
2172
|
: resumeInScope(park);
|
|
2135
2173
|
|
|
2136
2174
|
const adapter: WorkerContinuationAdapter = {
|
|
2137
2175
|
version: 1,
|
|
2138
2176
|
id: `subagents-continuation:${randomUUID()}`,
|
|
2139
2177
|
async onWaitReady(event) {
|
|
2140
|
-
|
|
2178
|
+
let park: ParkedWait | null;
|
|
2179
|
+
if (event.parkedAttemptId !== undefined) {
|
|
2180
|
+
const meta = readMeta(event.parkedAttemptId);
|
|
2181
|
+
const record = meta && readParkRecord(meta.id);
|
|
2182
|
+
if (!meta || meta.sessionId !== event.owner.sessionId || !record
|
|
2183
|
+
|| record.waitId !== event.waitId || record.generation !== event.generation) return "deferred";
|
|
2184
|
+
park = parkedEntry(meta, record);
|
|
2185
|
+
} else {
|
|
2186
|
+
park = await parkedWaitByGeneration(event.waitId, event.generation);
|
|
2187
|
+
}
|
|
2141
2188
|
if (!park) return "delivered";
|
|
2142
2189
|
const outcome = await resume(park);
|
|
2143
2190
|
return outcome === "skipped" ? "deferred" : "delivered";
|
|
2144
2191
|
},
|
|
2145
2192
|
async onWaitCancelled(event) {
|
|
2146
|
-
const park = parkedWaitByGeneration(event.waitId, event.generation);
|
|
2193
|
+
const park = await parkedWaitByGeneration(event.waitId, event.generation);
|
|
2147
2194
|
if (!park || park.record.phase === "cancelled") return;
|
|
2148
2195
|
const cancellation = await stopPublishedAttempt(park, event.reason, options.stopAttempt, options.now);
|
|
2149
2196
|
updateParkRecord(park.runId, {
|
|
@@ -2365,6 +2412,7 @@ export function isTerminalAttempt(meta: RunMeta): boolean {
|
|
|
2365
2412
|
export interface ResumedAttemptExitInput {
|
|
2366
2413
|
/** The attempt id published by the resume claim (NOT the parked attempt). */
|
|
2367
2414
|
attemptId: string;
|
|
2415
|
+
priorPark?: { runId: string; waitId: string; generation: number };
|
|
2368
2416
|
service: WorkerOperationService | undefined;
|
|
2369
2417
|
/** Recorded status for the reason text. */
|
|
2370
2418
|
status?: string;
|
|
@@ -2413,7 +2461,20 @@ export function conversationWriterLeaseLive(
|
|
|
2413
2461
|
* remain unchanged, even if writer exit cannot yet be proved.
|
|
2414
2462
|
*/
|
|
2415
2463
|
export async function settleResumedAttemptExit(input: ResumedAttemptExitInput): Promise<ResumedAttemptExitResult> {
|
|
2416
|
-
|
|
2464
|
+
if (input.priorPark) {
|
|
2465
|
+
const { runId, waitId, generation } = input.priorPark;
|
|
2466
|
+
const meta = readMeta(runId);
|
|
2467
|
+
const record = meta && readParkRecord(runId);
|
|
2468
|
+
if (!meta || !record || record.waitId !== waitId || record.generation !== generation || record.resumedBy !== input.attemptId) {
|
|
2469
|
+
return { outcome: "ignored" };
|
|
2470
|
+
}
|
|
2471
|
+
return settleResumedAttemptExitForParks(input, [parkedEntry(meta, record)]);
|
|
2472
|
+
}
|
|
2473
|
+
const candidates: ParkedWait[] = [];
|
|
2474
|
+
for await (const { meta, record } of scanParkRecords()) {
|
|
2475
|
+
if (record.resumedBy === input.attemptId) candidates.push(parkedEntry(meta, record));
|
|
2476
|
+
}
|
|
2477
|
+
return settleResumedAttemptExitForParks(input, candidates);
|
|
2417
2478
|
}
|
|
2418
2479
|
|
|
2419
2480
|
async function settleResumedAttemptExitForParks(input: ResumedAttemptExitInput, candidates: readonly ParkedWait[]): Promise<ResumedAttemptExitResult> {
|
|
@@ -2658,12 +2719,10 @@ export async function reconcileParkedWaits(
|
|
|
2658
2719
|
// Consumed waits cannot resume, but a missed exit observer may have left
|
|
2659
2720
|
// their published writer claim behind. Reconcile that exact claim once.
|
|
2660
2721
|
const candidates: ParkedWait[] = [];
|
|
2661
|
-
for (const meta of
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
const record = readParkRecord(meta.id);
|
|
2666
|
-
if (record) candidates.push(parkedEntry(meta, record));
|
|
2722
|
+
for await (const { meta, record } of scanParkRecords()) {
|
|
2723
|
+
if (!isPendingPark(record) && !(record.phase === "consumed" && record.resumedBy
|
|
2724
|
+
&& record.resumeClaimId && record.resumeExitReconciledClaimId !== record.resumeClaimId)) continue;
|
|
2725
|
+
candidates.push(parkedEntry(meta, record));
|
|
2667
2726
|
}
|
|
2668
2727
|
// Release earlier writers before admitting later waits in the conversation.
|
|
2669
2728
|
candidates.sort((a, b) => a.record.parkedAt - b.record.parkedAt);
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-subagents/workspace-files.ts. Do not edit directly.
|
|
2
|
+
// A private content store lets retained checkouts share identical Git objects and files.
|
|
3
|
+
// Source files are never hardlinked into storage. Restoring a file makes an independent copy.
|
|
4
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
5
|
+
import { chmodSync, closeSync, constants, copyFileSync, existsSync, lstatSync, mkdirSync, openSync, readSync, readdirSync, readlinkSync, renameSync, rmSync, symlinkSync, } from "node:fs";
|
|
6
|
+
import { dirname, join } from "node:path";
|
|
7
|
+
function fileHash(path) {
|
|
8
|
+
const fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
9
|
+
try {
|
|
10
|
+
const hash = createHash("sha256");
|
|
11
|
+
const buffer = Buffer.allocUnsafe(128 * 1024);
|
|
12
|
+
let bytes;
|
|
13
|
+
while ((bytes = readSync(fd, buffer, 0, buffer.length, null)) > 0)
|
|
14
|
+
hash.update(buffer.subarray(0, bytes));
|
|
15
|
+
return hash.digest("hex");
|
|
16
|
+
}
|
|
17
|
+
finally {
|
|
18
|
+
closeSync(fd);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function blobPath(store, hash) {
|
|
22
|
+
if (!/^[a-f0-9]{64}$/.test(hash))
|
|
23
|
+
throw new Error("Invalid saved file identity");
|
|
24
|
+
return join(store, hash.slice(0, 2), hash.slice(2));
|
|
25
|
+
}
|
|
26
|
+
function saveFile(path, store, hash) {
|
|
27
|
+
const dest = blobPath(store, hash);
|
|
28
|
+
if (existsSync(dest))
|
|
29
|
+
return;
|
|
30
|
+
mkdirSync(dirname(dest), { recursive: true, mode: 0o700 });
|
|
31
|
+
const temp = dest + "-" + randomUUID();
|
|
32
|
+
try {
|
|
33
|
+
copyFileSync(path, temp, constants.COPYFILE_FICLONE);
|
|
34
|
+
chmodSync(temp, 0o600);
|
|
35
|
+
if (fileHash(temp) !== hash)
|
|
36
|
+
throw new Error("File changed while saving " + path);
|
|
37
|
+
renameSync(temp, dest);
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
rmSync(temp, { force: true });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Directories precede children. Symbolic links are captured as links, never traversed.
|
|
44
|
+
export function snapshotTree(root, store, omit = new Set()) {
|
|
45
|
+
if (!lstatSync(root).isDirectory())
|
|
46
|
+
throw new Error("Expected a directory at " + root);
|
|
47
|
+
const entries = [];
|
|
48
|
+
function walk(parent) {
|
|
49
|
+
for (const child of readdirSync(join(root, parent)).sort()) {
|
|
50
|
+
const name = join(parent, child);
|
|
51
|
+
if (omit.has(name))
|
|
52
|
+
continue;
|
|
53
|
+
const path = join(root, name), stat = lstatSync(path), mode = stat.mode & 0o7777;
|
|
54
|
+
if (stat.isDirectory()) {
|
|
55
|
+
entries.push({ name, mode, type: "directory" });
|
|
56
|
+
walk(name);
|
|
57
|
+
}
|
|
58
|
+
else if (stat.isSymbolicLink()) {
|
|
59
|
+
entries.push({ name, mode, type: "symlink", target: readlinkSync(path) });
|
|
60
|
+
}
|
|
61
|
+
else if (stat.isFile()) {
|
|
62
|
+
const blob = fileHash(path);
|
|
63
|
+
if (store)
|
|
64
|
+
saveFile(path, store, blob);
|
|
65
|
+
entries.push({ name, mode, type: "file", blob });
|
|
66
|
+
}
|
|
67
|
+
else
|
|
68
|
+
throw new Error("Cannot save special file " + path + ". The original is retained.");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
walk("");
|
|
72
|
+
return entries;
|
|
73
|
+
}
|
|
74
|
+
export function restoreTree(root, store, entries) {
|
|
75
|
+
mkdirSync(root, { recursive: true, mode: 0o700 });
|
|
76
|
+
const directories = new Set(["."]);
|
|
77
|
+
for (const entry of entries) {
|
|
78
|
+
const parts = entry.name.split("/");
|
|
79
|
+
if (parts.some((p) => !p || p === "." || p === "..") || !directories.has(dirname(entry.name))) {
|
|
80
|
+
throw new Error("Invalid path in workspace manifest");
|
|
81
|
+
}
|
|
82
|
+
const dest = join(root, entry.name);
|
|
83
|
+
if (entry.type === "directory") {
|
|
84
|
+
mkdirSync(dest);
|
|
85
|
+
directories.add(entry.name);
|
|
86
|
+
}
|
|
87
|
+
else if (entry.type === "symlink")
|
|
88
|
+
symlinkSync(entry.target, dest);
|
|
89
|
+
else {
|
|
90
|
+
copyFileSync(blobPath(store, entry.blob), dest, constants.COPYFILE_EXCL | constants.COPYFILE_FICLONE);
|
|
91
|
+
chmodSync(dest, entry.mode);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
for (const entry of entries.slice().reverse()) {
|
|
95
|
+
if (entry.type === "directory")
|
|
96
|
+
chmodSync(join(root, entry.name), entry.mode);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
export function verifyTree(root, entries, omit) {
|
|
100
|
+
if (JSON.stringify(snapshotTree(root, undefined, omit)) !== JSON.stringify(entries)) {
|
|
101
|
+
throw new Error("Workspace contents changed or could not be recovered at " + root);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// A private content store lets retained checkouts share identical Git objects and files.
|
|
2
|
+
// Source files are never hardlinked into storage. Restoring a file makes an independent copy.
|
|
3
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
4
|
+
import {
|
|
5
|
+
chmodSync,
|
|
6
|
+
closeSync,
|
|
7
|
+
constants,
|
|
8
|
+
copyFileSync,
|
|
9
|
+
existsSync,
|
|
10
|
+
lstatSync,
|
|
11
|
+
mkdirSync,
|
|
12
|
+
openSync,
|
|
13
|
+
readSync,
|
|
14
|
+
readdirSync,
|
|
15
|
+
readlinkSync,
|
|
16
|
+
renameSync,
|
|
17
|
+
rmSync,
|
|
18
|
+
symlinkSync,
|
|
19
|
+
} from "node:fs";
|
|
20
|
+
import { dirname, join } from "node:path";
|
|
21
|
+
|
|
22
|
+
export type SavedEntry =
|
|
23
|
+
| { name: string; mode: number; type: "directory" }
|
|
24
|
+
| { name: string; mode: number; type: "file"; blob: string }
|
|
25
|
+
| { name: string; mode: number; type: "symlink"; target: string };
|
|
26
|
+
|
|
27
|
+
function fileHash(path: string): string {
|
|
28
|
+
const fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
29
|
+
try {
|
|
30
|
+
const hash = createHash("sha256");
|
|
31
|
+
const buffer = Buffer.allocUnsafe(128 * 1024);
|
|
32
|
+
let bytes: number;
|
|
33
|
+
while ((bytes = readSync(fd, buffer, 0, buffer.length, null)) > 0) hash.update(buffer.subarray(0, bytes));
|
|
34
|
+
return hash.digest("hex");
|
|
35
|
+
} finally {
|
|
36
|
+
closeSync(fd);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function blobPath(store: string, hash: string): string {
|
|
41
|
+
if (!/^[a-f0-9]{64}$/.test(hash)) throw new Error("Invalid saved file identity");
|
|
42
|
+
return join(store, hash.slice(0, 2), hash.slice(2));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function saveFile(path: string, store: string, hash: string): void {
|
|
46
|
+
const dest = blobPath(store, hash);
|
|
47
|
+
if (existsSync(dest)) return;
|
|
48
|
+
mkdirSync(dirname(dest), { recursive: true, mode: 0o700 });
|
|
49
|
+
const temp = dest + "-" + randomUUID();
|
|
50
|
+
try {
|
|
51
|
+
copyFileSync(path, temp, constants.COPYFILE_FICLONE);
|
|
52
|
+
chmodSync(temp, 0o600);
|
|
53
|
+
if (fileHash(temp) !== hash) throw new Error("File changed while saving " + path);
|
|
54
|
+
renameSync(temp, dest);
|
|
55
|
+
} finally {
|
|
56
|
+
rmSync(temp, { force: true });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Directories precede children. Symbolic links are captured as links, never traversed.
|
|
61
|
+
export function snapshotTree(root: string, store?: string, omit: ReadonlySet<string> = new Set()): SavedEntry[] {
|
|
62
|
+
if (!lstatSync(root).isDirectory()) throw new Error("Expected a directory at " + root);
|
|
63
|
+
const entries: SavedEntry[] = [];
|
|
64
|
+
function walk(parent: string): void {
|
|
65
|
+
for (const child of readdirSync(join(root, parent)).sort()) {
|
|
66
|
+
const name = join(parent, child);
|
|
67
|
+
if (omit.has(name)) continue;
|
|
68
|
+
const path = join(root, name),
|
|
69
|
+
stat = lstatSync(path),
|
|
70
|
+
mode = stat.mode & 0o7777;
|
|
71
|
+
if (stat.isDirectory()) {
|
|
72
|
+
entries.push({ name, mode, type: "directory" });
|
|
73
|
+
walk(name);
|
|
74
|
+
} else if (stat.isSymbolicLink()) {
|
|
75
|
+
entries.push({ name, mode, type: "symlink", target: readlinkSync(path) });
|
|
76
|
+
} else if (stat.isFile()) {
|
|
77
|
+
const blob = fileHash(path);
|
|
78
|
+
if (store) saveFile(path, store, blob);
|
|
79
|
+
entries.push({ name, mode, type: "file", blob });
|
|
80
|
+
} else throw new Error("Cannot save special file " + path + ". The original is retained.");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
walk("");
|
|
84
|
+
return entries;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function restoreTree(root: string, store: string, entries: SavedEntry[]): void {
|
|
88
|
+
mkdirSync(root, { recursive: true, mode: 0o700 });
|
|
89
|
+
const directories = new Set(["."]);
|
|
90
|
+
for (const entry of entries) {
|
|
91
|
+
const parts = entry.name.split("/");
|
|
92
|
+
if (parts.some((p) => !p || p === "." || p === "..") || !directories.has(dirname(entry.name))) {
|
|
93
|
+
throw new Error("Invalid path in workspace manifest");
|
|
94
|
+
}
|
|
95
|
+
const dest = join(root, entry.name);
|
|
96
|
+
if (entry.type === "directory") {
|
|
97
|
+
mkdirSync(dest);
|
|
98
|
+
directories.add(entry.name);
|
|
99
|
+
} else if (entry.type === "symlink") symlinkSync(entry.target, dest);
|
|
100
|
+
else {
|
|
101
|
+
copyFileSync(blobPath(store, entry.blob), dest, constants.COPYFILE_EXCL | constants.COPYFILE_FICLONE);
|
|
102
|
+
chmodSync(dest, entry.mode);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
for (const entry of entries.slice().reverse()) {
|
|
106
|
+
if (entry.type === "directory") chmodSync(join(root, entry.name), entry.mode);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function verifyTree(root: string, entries: SavedEntry[], omit?: ReadonlySet<string>): void {
|
|
111
|
+
if (JSON.stringify(snapshotTree(root, undefined, omit)) !== JSON.stringify(entries)) {
|
|
112
|
+
throw new Error("Workspace contents changed or could not be recovered at " + root);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workspace (folder) scope for cross-session discovery.
|
|
3
|
+
*
|
|
4
|
+
* `subagent_list` defaults to the caller's current folder and its descendants,
|
|
5
|
+
* not to the foreground session that spawned a run. A folder is identified by
|
|
6
|
+
* its canonical path: two foreground sessions in the same folder share one
|
|
7
|
+
* list scope, and a run in a sibling folder that merely shares a name prefix
|
|
8
|
+
* (`/repo-other` vs `/repo`) is a different workspace.
|
|
9
|
+
*
|
|
10
|
+
* Paths are compared with `node:path.relative`, never with string prefixes, so
|
|
11
|
+
* `..`, separators, and sibling names cannot be mistaken for descendants. An
|
|
12
|
+
* existing directory is resolved through `realpath` first (a symlinked
|
|
13
|
+
* workspace and its target are the same folder); a path that no longer exists
|
|
14
|
+
* falls back to `path.resolve` so a deleted run workspace still compares
|
|
15
|
+
* predictably.
|
|
16
|
+
*
|
|
17
|
+
* This helper is shared with the parent name resolver, so it owns no list-only
|
|
18
|
+
* state and performs no I/O beyond `realpath`.
|
|
19
|
+
*/
|
|
20
|
+
/** Canonical absolute form of one workspace path (realpath when it exists). */
|
|
21
|
+
export declare function normalizeWorkspacePath(path: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* True when `candidateCwd` is `scopeCwd` itself or lies beneath it.
|
|
24
|
+
*
|
|
25
|
+
* A missing or empty candidate is never inside a workspace: metadata that does
|
|
26
|
+
* not name a workspace cannot be placed in the caller's folder.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isWithinWorkspace(candidateCwd: string, scopeCwd: string): boolean;
|
|
29
|
+
/** Folder where the parent requested the work. The execution cwd stays on the run for delivery and authorization. */
|
|
30
|
+
export declare function discoveryWorkspace(meta: {
|
|
31
|
+
cwd: string;
|
|
32
|
+
recipe?: {
|
|
33
|
+
workspace?: {
|
|
34
|
+
source: string;
|
|
35
|
+
subdir: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
}): string;
|
|
@@ -50,3 +50,8 @@ export function isWithinWorkspace(candidateCwd, scopeCwd) {
|
|
|
50
50
|
return true;
|
|
51
51
|
return rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel);
|
|
52
52
|
}
|
|
53
|
+
/** Folder where the parent requested the work. The execution cwd stays on the run for delivery and authorization. */
|
|
54
|
+
export function discoveryWorkspace(meta) {
|
|
55
|
+
const workspace = meta.recipe?.workspace;
|
|
56
|
+
return workspace ? resolve(workspace.source, workspace.subdir) : meta.cwd;
|
|
57
|
+
}
|
|
@@ -48,3 +48,9 @@ export function isWithinWorkspace(candidateCwd: string, scopeCwd: string): boole
|
|
|
48
48
|
if (rel === "") return true;
|
|
49
49
|
return rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel);
|
|
50
50
|
}
|
|
51
|
+
|
|
52
|
+
/** Folder where the parent requested the work. The execution cwd stays on the run for delivery and authorization. */
|
|
53
|
+
export function discoveryWorkspace(meta: { cwd: string; recipe?: { workspace?: { source: string; subdir: string } } }): string {
|
|
54
|
+
const workspace = meta.recipe?.workspace;
|
|
55
|
+
return workspace ? resolve(workspace.source, workspace.subdir) : meta.cwd;
|
|
56
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-subagents/worktree-feedback.ts. Do not edit directly.
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { evaluateDeleteAccess, evaluateWriteAccess } from "./shared-sandbox-core.domain.mjs";
|
|
4
|
+
// Require all three observations: an actual failed Git call, Git naming the index
|
|
5
|
+
// and OS denial, and the captured policy refusing that specific filesystem operation.
|
|
6
|
+
export function deniedGitOperation(event, gitDir, policy) {
|
|
7
|
+
if (!event.isError)
|
|
8
|
+
return;
|
|
9
|
+
let operation;
|
|
10
|
+
if (event.toolName === "run_application" &&
|
|
11
|
+
typeof event.input.executable === "string" &&
|
|
12
|
+
/^(?:\/usr\/bin\/|\/bin\/)?git$/.test(event.input.executable) &&
|
|
13
|
+
Array.isArray(event.input.args)) {
|
|
14
|
+
operation = event.input.args[0];
|
|
15
|
+
}
|
|
16
|
+
else if (event.toolName === "bash" && typeof event.input.command === "string") {
|
|
17
|
+
// A compound shell command can print diagnostics from a different program.
|
|
18
|
+
const command = event.input.command.trim();
|
|
19
|
+
if (!/[;&|<>$`\n]/.test(command))
|
|
20
|
+
operation = /^(?:\/usr\/bin\/|\/bin\/)?git\s+([a-z-]+)(?:\s|$)/.exec(command)?.[1];
|
|
21
|
+
}
|
|
22
|
+
if (!operation ||
|
|
23
|
+
!/^(?:add|commit|checkout|switch|reset|merge|rebase|restore|stash|cherry-pick|update-index|rm|mv|apply)$/.test(operation))
|
|
24
|
+
return;
|
|
25
|
+
const index = join(gitDir, "index"), lock = index + ".lock";
|
|
26
|
+
for (const block of event.content) {
|
|
27
|
+
if (block.type !== "text" || !block.text)
|
|
28
|
+
continue;
|
|
29
|
+
for (const line of block.text.split("\n")) {
|
|
30
|
+
if (!/^(?:fatal|error): /i.test(line) ||
|
|
31
|
+
!/(?:permission denied|operation not permitted|read-only file system)\s*$/i.test(line))
|
|
32
|
+
continue;
|
|
33
|
+
if (line.includes("'" + lock + "'") && !evaluateWriteAccess(lock, policy).allowed)
|
|
34
|
+
return operation;
|
|
35
|
+
if ((line.includes("'" + lock + "'") || line.includes("'" + index + "'")) &&
|
|
36
|
+
/renam|unlink|remov/i.test(line) &&
|
|
37
|
+
!evaluateDeleteAccess(lock, policy).allowed)
|
|
38
|
+
return operation;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export function worktreePolicyNotice(gitDir, policy) {
|
|
43
|
+
const lock = join(gitDir, "index.lock");
|
|
44
|
+
if (!evaluateWriteAccess(lock, policy).allowed)
|
|
45
|
+
return "The current sandbox profile denies writes to the shared Git index.";
|
|
46
|
+
if (!evaluateDeleteAccess(lock, policy).allowed)
|
|
47
|
+
return "The current sandbox profile restricts renaming or removing the shared Git index lock.";
|
|
48
|
+
}
|
|
49
|
+
export function worktreeDenialText(operation, cwd) {
|
|
50
|
+
return ("The sandbox denied git " +
|
|
51
|
+
operation +
|
|
52
|
+
" access to linked worktree metadata. Review the changes in " +
|
|
53
|
+
cwd +
|
|
54
|
+
" or continue this conversation with recover_in_clone:true.");
|
|
55
|
+
}
|