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
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Filesystem catalog: project, personal, and bundled sources.
|
|
4
4
|
*
|
|
5
|
-
* Discovery is deterministic
|
|
6
|
-
*
|
|
5
|
+
* Discovery is deterministic. Direct callers read disk on every call; the server
|
|
6
|
+
* can supply bounded source reuse after admission. Callers launching a batch retain the snapshot
|
|
7
7
|
* and reuse that object for every job.
|
|
8
8
|
*
|
|
9
9
|
* Project files are read only when `projectTrusted` is true. Pass Pi's
|
|
@@ -69,12 +69,12 @@ export function listScopedAgents(input, scope) {
|
|
|
69
69
|
throw new Error("Unsafe project config directory");
|
|
70
70
|
const directory = scope === "project" ? projectCatalogPaths(input.cwd, config).agents : userCatalogPaths(input.userRoot).agents;
|
|
71
71
|
const occurrences = new Map();
|
|
72
|
-
collectDirectory(directory, scope, "agent", occurrences, diagnostics);
|
|
72
|
+
collectDirectory(directory, scope, "agent", occurrences, diagnostics, input.sources);
|
|
73
73
|
const agents = [...occurrences.values()].flat().flatMap(item => item.parse.definition?.kind === "agent"
|
|
74
74
|
? [{ path: item.path, definition: item.parse.definition }] : []);
|
|
75
75
|
return { agents, diagnostics };
|
|
76
76
|
}
|
|
77
|
-
/**
|
|
77
|
+
/** Discover authorized sources. Identical bytes produce the same content digest. */
|
|
78
78
|
export function loadCatalog(input) {
|
|
79
79
|
const loadedAt = new Date().toISOString();
|
|
80
80
|
const diagnostics = [];
|
|
@@ -91,8 +91,8 @@ export function loadCatalog(input) {
|
|
|
91
91
|
groups.set(scope, new Map());
|
|
92
92
|
if (input.projectTrusted) {
|
|
93
93
|
const project = projectCatalogPaths(input.cwd, configDirName);
|
|
94
|
-
collectDirectory(project.roles, "project", "role", groups.get("project"), diagnostics);
|
|
95
|
-
collectDirectory(project.agents, "project", "agent", groups.get("project"), diagnostics);
|
|
94
|
+
collectDirectory(project.roles, "project", "role", groups.get("project"), diagnostics, input.sources);
|
|
95
|
+
collectDirectory(project.agents, "project", "agent", groups.get("project"), diagnostics, input.sources);
|
|
96
96
|
}
|
|
97
97
|
else {
|
|
98
98
|
const project = projectCatalogPaths(input.cwd, configDirName);
|
|
@@ -101,8 +101,8 @@ export function loadCatalog(input) {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
const user = userCatalogPaths(input.userRoot);
|
|
104
|
-
collectDirectory(user.roles, "user", "role", groups.get("user"), diagnostics);
|
|
105
|
-
collectDirectory(user.agents, "user", "agent", groups.get("user"), diagnostics);
|
|
104
|
+
collectDirectory(user.roles, "user", "role", groups.get("user"), diagnostics, input.sources);
|
|
105
|
+
collectDirectory(user.agents, "user", "agent", groups.get("user"), diagnostics, input.sources);
|
|
106
106
|
const bundledRoles = input.bundledRoot ?? bundledRolesRoot();
|
|
107
107
|
if (!existsSync(bundledRoles)) {
|
|
108
108
|
diagnostics.push(diagnostic(DiagnosticCodes.bundledMissing, `Bundled role directory ${bundledRoles} is missing.`, {
|
|
@@ -114,23 +114,21 @@ export function loadCatalog(input) {
|
|
|
114
114
|
}));
|
|
115
115
|
}
|
|
116
116
|
else {
|
|
117
|
-
collectDirectory(bundledRoles, "bundled", "role", groups.get("bundled"), diagnostics);
|
|
117
|
+
collectDirectory(bundledRoles, "bundled", "role", groups.get("bundled"), diagnostics, input.sources);
|
|
118
118
|
}
|
|
119
119
|
if (input.bundledAgentsRoot) {
|
|
120
|
-
collectDirectory(input.bundledAgentsRoot, "bundled", "agent", groups.get("bundled"), diagnostics);
|
|
120
|
+
collectDirectory(input.bundledAgentsRoot, "bundled", "agent", groups.get("bundled"), diagnostics, input.sources);
|
|
121
121
|
}
|
|
122
122
|
const { entries, blocked } = selectIdentities(groups, diagnostics);
|
|
123
123
|
const savedSettings = {};
|
|
124
124
|
const preferenceSources = {};
|
|
125
|
-
const preferenceDigests = [];
|
|
126
125
|
const scopes = [
|
|
127
126
|
{ scope: "user", root: user.root },
|
|
128
127
|
...(input.projectTrusted ? [{ scope: "project", root: projectCatalogPaths(input.cwd, configDirName).root }] : []),
|
|
129
128
|
];
|
|
130
129
|
for (const { scope, root } of scopes) {
|
|
131
130
|
try {
|
|
132
|
-
const preferences = readCatalogPreferences(root);
|
|
133
|
-
preferenceDigests.push(preferences.digest);
|
|
131
|
+
const preferences = input.sources?.preferences?.(root) ?? readCatalogPreferences(root);
|
|
134
132
|
for (const entry of entries) {
|
|
135
133
|
if (scope === "user" && entry.scope === "project")
|
|
136
134
|
continue;
|
|
@@ -141,8 +139,8 @@ export function loadCatalog(input) {
|
|
|
141
139
|
if (own.bundled) {
|
|
142
140
|
const fallbacks = entry.scope === "bundled" ? [entry] : entry.unused.filter(source => source.scope === "bundled");
|
|
143
141
|
const fallback = fallbacks.length === 1 ? fallbacks[0] : undefined;
|
|
144
|
-
const raw = fallback ? readFileSync(fallback.path, "utf8") : undefined;
|
|
145
|
-
const parsed = raw === undefined ? undefined : parseDefinition(raw, fallback.path);
|
|
142
|
+
const raw = fallback ? (input.sources?.read(fallback.path) ?? readFileSync(fallback.path, "utf8")) : undefined;
|
|
143
|
+
const parsed = raw === undefined ? undefined : (input.sources?.parse(raw, fallback.path) ?? parseDefinition(raw, fallback.path));
|
|
146
144
|
if (!fallback || !parsed?.ok || parsed.definition?.id !== entry.id || parsed.diagnostics.some(item => item.blocking)
|
|
147
145
|
|| contentDigest(raw) !== fallback.contentDigest) {
|
|
148
146
|
const failure = diagnostic("catalog-preferences", `Cannot inherit bundled runtime defaults for ${entry.id}: a single valid bundled definition is required.`, {
|
|
@@ -182,8 +180,8 @@ export function loadCatalog(input) {
|
|
|
182
180
|
}
|
|
183
181
|
}
|
|
184
182
|
}
|
|
185
|
-
const snapshot = finishSnapshot(entries, blocked, diagnostics, loadedAt);
|
|
186
|
-
const digest = contentDigest(JSON.stringify([snapshot.digest,
|
|
183
|
+
const snapshot = finishSnapshot(entries, blocked, diagnostics, loadedAt, input.sources);
|
|
184
|
+
const digest = contentDigest(JSON.stringify([snapshot.digest, savedSettings, preferenceSources]));
|
|
187
185
|
return deepFreeze({ ...snapshot, digest, revision: digest, savedSettings, preferenceSources });
|
|
188
186
|
}
|
|
189
187
|
export function refreshCatalog(input) {
|
|
@@ -372,7 +370,7 @@ export function saveDefinition(input) {
|
|
|
372
370
|
export function isSafeConfigDirName(name) {
|
|
373
371
|
return /^\.[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(name) || /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(name);
|
|
374
372
|
}
|
|
375
|
-
function collectDirectory(directory, scope, directoryKind, into, diagnostics) {
|
|
373
|
+
function collectDirectory(directory, scope, directoryKind, into, diagnostics, sources) {
|
|
376
374
|
let stats;
|
|
377
375
|
try {
|
|
378
376
|
stats = lstatSync(directory);
|
|
@@ -449,7 +447,7 @@ function collectDirectory(directory, scope, directoryKind, into, diagnostics) {
|
|
|
449
447
|
continue;
|
|
450
448
|
let raw;
|
|
451
449
|
try {
|
|
452
|
-
raw = readFileSync(path, "utf8");
|
|
450
|
+
raw = sources?.read(path) ?? readFileSync(path, "utf8");
|
|
453
451
|
}
|
|
454
452
|
catch (error) {
|
|
455
453
|
diagnostics.push(diagnostic(DiagnosticCodes.ioError, `Could not read ${path}: ${error.message}`, {
|
|
@@ -462,7 +460,7 @@ function collectDirectory(directory, scope, directoryKind, into, diagnostics) {
|
|
|
462
460
|
}
|
|
463
461
|
let parse;
|
|
464
462
|
try {
|
|
465
|
-
parse = parseDefinition(raw, path);
|
|
463
|
+
parse = sources?.parse(raw, path) ?? parseDefinition(raw, path);
|
|
466
464
|
}
|
|
467
465
|
catch (error) {
|
|
468
466
|
const detail = error instanceof Error ? error.message : String(error);
|
|
@@ -586,11 +584,11 @@ function unusedSource(occurrence, reason) {
|
|
|
586
584
|
reason,
|
|
587
585
|
};
|
|
588
586
|
}
|
|
589
|
-
function finishSnapshot(entries, blocked, diagnostics, loadedAt) {
|
|
587
|
+
function finishSnapshot(entries, blocked, diagnostics, loadedAt, sources) {
|
|
590
588
|
const roleEntries = [];
|
|
591
589
|
const agentEntries = [];
|
|
592
590
|
for (const entry of entries) {
|
|
593
|
-
const frozen = deepFreeze(cloneEntry(entry));
|
|
591
|
+
const frozen = sources?.entry?.(entry) ?? deepFreeze(cloneEntry(entry));
|
|
594
592
|
if (frozen.kind === "role")
|
|
595
593
|
roleEntries.push([frozen.id, frozen]);
|
|
596
594
|
else
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Filesystem catalog: project, personal, and bundled sources.
|
|
3
3
|
*
|
|
4
|
-
* Discovery is deterministic
|
|
5
|
-
*
|
|
4
|
+
* Discovery is deterministic. Direct callers read disk on every call; the server
|
|
5
|
+
* can supply bounded source reuse after admission. Callers launching a batch retain the snapshot
|
|
6
6
|
* and reuse that object for every job.
|
|
7
7
|
*
|
|
8
8
|
* Project files are read only when `projectTrusted` is true. Pass Pi's
|
|
@@ -51,6 +51,13 @@ export const DEFAULT_PROJECT_CONFIG_DIR_NAME = ".pi";
|
|
|
51
51
|
export const SOURCE_PRECEDENCE = ["project", "user", "bundled"] as const;
|
|
52
52
|
|
|
53
53
|
export interface LoadCatalogInput {
|
|
54
|
+
/** Server-owned, bounded source reuse. Admission and discovery still run first. */
|
|
55
|
+
sources?: {
|
|
56
|
+
read(path: string): string;
|
|
57
|
+
parse(raw: string, path: string): ParseResult;
|
|
58
|
+
entry?(entry: CatalogEntry): CatalogEntry;
|
|
59
|
+
preferences?(root: string): ReturnType<typeof readCatalogPreferences>;
|
|
60
|
+
};
|
|
54
61
|
cwd: string;
|
|
55
62
|
/** Host trust decision. Untrusted projects do not contribute definitions. */
|
|
56
63
|
projectTrusted: boolean;
|
|
@@ -195,13 +202,13 @@ export function listScopedAgents(input: LoadCatalogInput, scope: "user" | "proje
|
|
|
195
202
|
if (!isSafeConfigDirName(config)) throw new Error("Unsafe project config directory");
|
|
196
203
|
const directory = scope === "project" ? projectCatalogPaths(input.cwd, config).agents : userCatalogPaths(input.userRoot).agents;
|
|
197
204
|
const occurrences = new Map<string, Occurrence[]>();
|
|
198
|
-
collectDirectory(directory, scope, "agent", occurrences, diagnostics);
|
|
205
|
+
collectDirectory(directory, scope, "agent", occurrences, diagnostics, input.sources);
|
|
199
206
|
const agents = [...occurrences.values()].flat().flatMap(item => item.parse.definition?.kind === "agent"
|
|
200
207
|
? [{ path: item.path, definition: item.parse.definition }] : []);
|
|
201
208
|
return { agents, diagnostics };
|
|
202
209
|
}
|
|
203
210
|
|
|
204
|
-
/**
|
|
211
|
+
/** Discover authorized sources. Identical bytes produce the same content digest. */
|
|
205
212
|
export function loadCatalog(input: LoadCatalogInput): CatalogSnapshot {
|
|
206
213
|
const loadedAt = new Date().toISOString();
|
|
207
214
|
const diagnostics: Diagnostic[] = [];
|
|
@@ -219,8 +226,8 @@ export function loadCatalog(input: LoadCatalogInput): CatalogSnapshot {
|
|
|
219
226
|
|
|
220
227
|
if (input.projectTrusted) {
|
|
221
228
|
const project = projectCatalogPaths(input.cwd, configDirName);
|
|
222
|
-
collectDirectory(project.roles, "project", "role", groups.get("project")!, diagnostics);
|
|
223
|
-
collectDirectory(project.agents, "project", "agent", groups.get("project")!, diagnostics);
|
|
229
|
+
collectDirectory(project.roles, "project", "role", groups.get("project")!, diagnostics, input.sources);
|
|
230
|
+
collectDirectory(project.agents, "project", "agent", groups.get("project")!, diagnostics, input.sources);
|
|
224
231
|
} else {
|
|
225
232
|
const project = projectCatalogPaths(input.cwd, configDirName);
|
|
226
233
|
if (pathExists(project.roles) || pathExists(project.agents) || pathExists(project.root)) {
|
|
@@ -233,8 +240,8 @@ export function loadCatalog(input: LoadCatalogInput): CatalogSnapshot {
|
|
|
233
240
|
}
|
|
234
241
|
|
|
235
242
|
const user = userCatalogPaths(input.userRoot);
|
|
236
|
-
collectDirectory(user.roles, "user", "role", groups.get("user")!, diagnostics);
|
|
237
|
-
collectDirectory(user.agents, "user", "agent", groups.get("user")!, diagnostics);
|
|
243
|
+
collectDirectory(user.roles, "user", "role", groups.get("user")!, diagnostics, input.sources);
|
|
244
|
+
collectDirectory(user.agents, "user", "agent", groups.get("user")!, diagnostics, input.sources);
|
|
238
245
|
|
|
239
246
|
const bundledRoles = input.bundledRoot ?? bundledRolesRoot();
|
|
240
247
|
if (!existsSync(bundledRoles)) {
|
|
@@ -246,24 +253,22 @@ export function loadCatalog(input: LoadCatalogInput): CatalogSnapshot {
|
|
|
246
253
|
severity: "warning",
|
|
247
254
|
}));
|
|
248
255
|
} else {
|
|
249
|
-
collectDirectory(bundledRoles, "bundled", "role", groups.get("bundled")!, diagnostics);
|
|
256
|
+
collectDirectory(bundledRoles, "bundled", "role", groups.get("bundled")!, diagnostics, input.sources);
|
|
250
257
|
}
|
|
251
258
|
if (input.bundledAgentsRoot) {
|
|
252
|
-
collectDirectory(input.bundledAgentsRoot, "bundled", "agent", groups.get("bundled")!, diagnostics);
|
|
259
|
+
collectDirectory(input.bundledAgentsRoot, "bundled", "agent", groups.get("bundled")!, diagnostics, input.sources);
|
|
253
260
|
}
|
|
254
261
|
|
|
255
262
|
const { entries, blocked } = selectIdentities(groups, diagnostics);
|
|
256
263
|
const savedSettings: Record<string, { model?: string | null; effort?: ThinkingLevel | null }> = {};
|
|
257
264
|
const preferenceSources: Record<string, Partial<Record<"model" | "effort", { scope: "user" | "project"; path: string; bundled?: boolean }>>> = {};
|
|
258
|
-
const preferenceDigests: string[] = [];
|
|
259
265
|
const scopes = [
|
|
260
266
|
{ scope: "user" as const, root: user.root },
|
|
261
267
|
...(input.projectTrusted ? [{ scope: "project" as const, root: projectCatalogPaths(input.cwd, configDirName).root }] : []),
|
|
262
268
|
];
|
|
263
269
|
for (const { scope, root } of scopes) {
|
|
264
270
|
try {
|
|
265
|
-
const preferences = readCatalogPreferences(root);
|
|
266
|
-
preferenceDigests.push(preferences.digest);
|
|
271
|
+
const preferences = input.sources?.preferences?.(root) ?? readCatalogPreferences(root);
|
|
267
272
|
for (const entry of entries) {
|
|
268
273
|
if (scope === "user" && entry.scope === "project") continue;
|
|
269
274
|
const own = preferences.settings[entry.id];
|
|
@@ -272,8 +277,8 @@ export function loadCatalog(input: LoadCatalogInput): CatalogSnapshot {
|
|
|
272
277
|
if (own.bundled) {
|
|
273
278
|
const fallbacks = entry.scope === "bundled" ? [entry] : entry.unused.filter(source => source.scope === "bundled");
|
|
274
279
|
const fallback = fallbacks.length === 1 ? fallbacks[0] : undefined;
|
|
275
|
-
const raw = fallback ? readFileSync(fallback.path, "utf8") : undefined;
|
|
276
|
-
const parsed = raw === undefined ? undefined : parseDefinition(raw, fallback!.path);
|
|
280
|
+
const raw = fallback ? (input.sources?.read(fallback.path) ?? readFileSync(fallback.path, "utf8")) : undefined;
|
|
281
|
+
const parsed = raw === undefined ? undefined : (input.sources?.parse(raw, fallback!.path) ?? parseDefinition(raw, fallback!.path));
|
|
277
282
|
if (!fallback || !parsed?.ok || parsed.definition?.id !== entry.id || parsed.diagnostics.some(item => item.blocking)
|
|
278
283
|
|| contentDigest(raw!) !== fallback.contentDigest) {
|
|
279
284
|
const failure = diagnostic("catalog-preferences", `Cannot inherit bundled runtime defaults for ${entry.id}: a single valid bundled definition is required.`, {
|
|
@@ -309,8 +314,8 @@ export function loadCatalog(input: LoadCatalogInput): CatalogSnapshot {
|
|
|
309
314
|
}
|
|
310
315
|
}
|
|
311
316
|
}
|
|
312
|
-
const snapshot = finishSnapshot(entries, blocked, diagnostics, loadedAt);
|
|
313
|
-
const digest = contentDigest(JSON.stringify([snapshot.digest,
|
|
317
|
+
const snapshot = finishSnapshot(entries, blocked, diagnostics, loadedAt, input.sources);
|
|
318
|
+
const digest = contentDigest(JSON.stringify([snapshot.digest, savedSettings, preferenceSources]));
|
|
314
319
|
return deepFreeze({ ...snapshot, digest, revision: digest, savedSettings, preferenceSources });
|
|
315
320
|
}
|
|
316
321
|
|
|
@@ -526,6 +531,7 @@ function collectDirectory(
|
|
|
526
531
|
directoryKind: CatalogKind,
|
|
527
532
|
into: Map<string, Occurrence[]>,
|
|
528
533
|
diagnostics: Diagnostic[],
|
|
534
|
+
sources?: LoadCatalogInput["sources"],
|
|
529
535
|
): void {
|
|
530
536
|
let stats;
|
|
531
537
|
try {
|
|
@@ -602,7 +608,7 @@ function collectDirectory(
|
|
|
602
608
|
if (!fileStats.isFile()) continue;
|
|
603
609
|
let raw: string;
|
|
604
610
|
try {
|
|
605
|
-
raw = readFileSync(path, "utf8");
|
|
611
|
+
raw = sources?.read(path) ?? readFileSync(path, "utf8");
|
|
606
612
|
} catch (error) {
|
|
607
613
|
diagnostics.push(diagnostic(DiagnosticCodes.ioError, `Could not read ${path}: ${(error as Error).message}`, {
|
|
608
614
|
scope,
|
|
@@ -614,7 +620,7 @@ function collectDirectory(
|
|
|
614
620
|
}
|
|
615
621
|
let parse: ParseResult;
|
|
616
622
|
try {
|
|
617
|
-
parse = parseDefinition(raw, path);
|
|
623
|
+
parse = sources?.parse(raw, path) ?? parseDefinition(raw, path);
|
|
618
624
|
} catch (error) {
|
|
619
625
|
const detail = error instanceof Error ? error.message : String(error);
|
|
620
626
|
diagnostics.push(diagnostic(
|
|
@@ -765,11 +771,12 @@ function finishSnapshot(
|
|
|
765
771
|
blocked: CatalogEntry[],
|
|
766
772
|
diagnostics: Diagnostic[],
|
|
767
773
|
loadedAt: string,
|
|
774
|
+
sources?: LoadCatalogInput["sources"],
|
|
768
775
|
): CatalogSnapshot {
|
|
769
776
|
const roleEntries: Array<readonly [string, CatalogEntry]> = [];
|
|
770
777
|
const agentEntries: Array<readonly [string, CatalogEntry]> = [];
|
|
771
778
|
for (const entry of entries) {
|
|
772
|
-
const frozen = deepFreeze(cloneEntry(entry));
|
|
779
|
+
const frozen = sources?.entry?.(entry) ?? deepFreeze(cloneEntry(entry));
|
|
773
780
|
if (frozen.kind === "role") roleEntries.push([frozen.id, frozen]);
|
|
774
781
|
else agentEntries.push([frozen.id, frozen]);
|
|
775
782
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-subagents/child-apply-patch.ts. Do not edit directly.
|
|
2
|
+
import { withFileMutationQueue } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import { createApplyPatchToolDefinition } from "./shared-task-apply-patch.domain.mjs";
|
|
4
|
+
import { createTaskFileOperations } from "./shared-task-files.domain.mjs";
|
|
5
|
+
/** Ordinary worker implementation. Confined workers install their own guarded definition. */
|
|
6
|
+
export default function childApplyPatch(pi) {
|
|
7
|
+
const files = createTaskFileOperations({ requireLaunchPlan: () => ({ confined: false }) });
|
|
8
|
+
const tool = createApplyPatchToolDefinition(process.cwd(), {
|
|
9
|
+
readFile: files.read.readFile, writeFile: files.write.writeFile, mkdir: files.write.mkdir,
|
|
10
|
+
remove: files.remove.remove, checkWrite: files.check.write, checkRemove: files.check.remove,
|
|
11
|
+
}, withFileMutationQueue);
|
|
12
|
+
pi.registerTool(tool);
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { withFileMutationQueue, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { createApplyPatchToolDefinition } from "./shared-task-apply-patch.ts";
|
|
3
|
+
import { createTaskFileOperations } from "./shared-task-files.ts";
|
|
4
|
+
|
|
5
|
+
/** Ordinary worker implementation. Confined workers install their own guarded definition. */
|
|
6
|
+
export default function childApplyPatch(pi: ExtensionAPI): void {
|
|
7
|
+
const files = createTaskFileOperations({ requireLaunchPlan: () => ({ confined: false }) });
|
|
8
|
+
const tool = createApplyPatchToolDefinition(process.cwd(), {
|
|
9
|
+
readFile: files.read.readFile, writeFile: files.write.writeFile, mkdir: files.write.mkdir,
|
|
10
|
+
remove: files.remove.remove, checkWrite: files.check.write, checkRemove: files.check.remove,
|
|
11
|
+
}, withFileMutationQueue);
|
|
12
|
+
pi.registerTool(tool as Parameters<ExtensionAPI["registerTool"]>[0]);
|
|
13
|
+
}
|
|
@@ -71,34 +71,39 @@ export function configSnapshot(directories) {
|
|
|
71
71
|
export async function resolveChildClosure({ resolution, model, virtual = false, config = {}, resolvePath, load = loadContract, configPaths = [] }) {
|
|
72
72
|
const result = { ...resolution, specs: [], reasons: { ...resolution.reasons }, paths: {}, declarations: [],
|
|
73
73
|
providers: [], modelGroups: [], fingerprints: configPaths.map(path => ({ path, hash: fingerprint(path) })) };
|
|
74
|
+
function requiredPath(spec, from) {
|
|
75
|
+
const path = resolvePath(spec, from);
|
|
76
|
+
if (path)
|
|
77
|
+
return path;
|
|
78
|
+
const reason = (resolution.reasons[spec] ?? []).join(', ');
|
|
79
|
+
throw new Error(`Child dependency ${spec}${from ? ` required by ${from}` : ''} is not installed.${reason ? ` Selected for ${reason}.` : ''}`);
|
|
80
|
+
}
|
|
74
81
|
if (resolution.mode !== 'isolated') {
|
|
75
82
|
if (virtual)
|
|
76
83
|
throw new Error(`Virtual model ${model} requires isolated mode with a declared supplier; ${resolution.mode} mode is unsupported.`);
|
|
77
|
-
return { ...result, specs: resolution.specs, paths: Object.fromEntries(resolution.specs.map(spec =>
|
|
78
|
-
const path = resolvePath(spec);
|
|
79
|
-
if (!path)
|
|
80
|
-
throw new Error(`Child dependency ${spec} is not installed.`);
|
|
81
|
-
return [spec, path];
|
|
82
|
-
})) };
|
|
84
|
+
return { ...result, specs: resolution.specs, paths: Object.fromEntries(resolution.specs.map(spec => [spec, requiredPath(spec)])) };
|
|
83
85
|
}
|
|
84
86
|
const providerMap = { ...BUILTIN_PROVIDER_EXTENSIONS, ...(config.providerExtensions ?? {}) };
|
|
85
|
-
const active = [], done = new Set();
|
|
87
|
+
const active = [], done = new Set(), entrypoints = new Set();
|
|
86
88
|
let ownsVirtual = false;
|
|
87
89
|
const visit = async (spec, from) => {
|
|
88
|
-
const path =
|
|
89
|
-
if (!path)
|
|
90
|
-
throw new Error(`Child dependency ${spec}${from ? ` required by ${from}` : ''} is not installed.`);
|
|
90
|
+
const path = requiredPath(spec, from);
|
|
91
91
|
const root = packageRoot(path);
|
|
92
92
|
const identity = root ?? realpathSync(path);
|
|
93
93
|
if (active.includes(identity))
|
|
94
94
|
throw new Error(`Child dependency cycle: ${[...active, identity].join(' -> ')}`);
|
|
95
|
-
|
|
95
|
+
// Different tool entrypoints can share a package and its dependency manifest.
|
|
96
|
+
const entrypoint = realpathSync(path);
|
|
97
|
+
if (entrypoints.has(entrypoint))
|
|
96
98
|
return;
|
|
97
|
-
|
|
99
|
+
entrypoints.add(entrypoint);
|
|
98
100
|
// Two packages may declare the same relative spec against different roots.
|
|
99
101
|
const key = result.paths[spec] && result.paths[spec] !== path ? path : spec;
|
|
100
102
|
result.specs.push(key);
|
|
101
103
|
result.paths[key] = path;
|
|
104
|
+
if (done.has(identity))
|
|
105
|
+
return;
|
|
106
|
+
active.push(identity);
|
|
102
107
|
if (root) {
|
|
103
108
|
const manifestPath = join(root, 'package.json');
|
|
104
109
|
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
@@ -151,7 +156,7 @@ export async function resolveChildLaunch(options, trustedPaths = []) {
|
|
|
151
156
|
return { resolution, fullResolution };
|
|
152
157
|
}
|
|
153
158
|
/** Validate actual child registration, never the parent's catalog. Groups require one physical candidate. */
|
|
154
|
-
export async function checkChildPreflight(plan, { registry, tools, model }, load = loadContract) {
|
|
159
|
+
export async function checkChildPreflight(plan, { registry, tools, registeredTools = [], model }, load = loadContract) {
|
|
155
160
|
if (plan.configSnapshot && JSON.stringify(configSnapshot(plan.configSnapshot.map(item => item.dir))) !== JSON.stringify(plan.configSnapshot))
|
|
156
161
|
throw new Error('Child configuration drift: agent or project JSON configuration changed. Launch again.');
|
|
157
162
|
for (const item of plan.fingerprints)
|
|
@@ -175,7 +180,14 @@ export async function checkChildPreflight(plan, { registry, tools, model }, load
|
|
|
175
180
|
if (!available.some(m => m.provider === group.provider && m.api !== 'pi-virtual' &&
|
|
176
181
|
(group.ids.includes(m.id) || (group.prefix && m.id.startsWith(group.prefix)))))
|
|
177
182
|
throw new Error(`Child has no available candidate for ${group.provider}: ${group.ids.join(', ')}${group.prefix ? ` (prefix ${group.prefix})` : ''}. Check extension, models and credentials.`);
|
|
178
|
-
|
|
179
|
-
|
|
183
|
+
const inactive = [];
|
|
184
|
+
for (const tool of plan.tools) {
|
|
185
|
+
if (tools.includes(tool))
|
|
186
|
+
continue;
|
|
187
|
+
if (!plan.optionalTrustedTools?.includes(tool) || !registeredTools.includes(tool)) {
|
|
180
188
|
throw new Error(`Child requested tool ${tool} is unavailable.`);
|
|
189
|
+
}
|
|
190
|
+
inactive.push(tool);
|
|
191
|
+
}
|
|
192
|
+
return inactive;
|
|
181
193
|
}
|
|
@@ -20,7 +20,8 @@ import { readFileSync, realpathSync } from "node:fs";
|
|
|
20
20
|
import { connect } from "node:net";
|
|
21
21
|
import * as piSdk from "@earendil-works/pi-coding-agent";
|
|
22
22
|
import { captureParkCheckpoint } from "./park-checkpoint.domain.mjs";
|
|
23
|
-
import {
|
|
23
|
+
import { supportsPromptSections } from "./shared-execution-policy.domain.mjs";
|
|
24
|
+
import { ACKNOWLEDGE_OPERATION_TOOL, OPERATION_BRIDGE_ENV_KEYS, OPERATION_BRIDGE_TOOL_NAMES, OPERATION_BRIDGE_VERSION, OPERATIONS_ATTEMPT_ID_ENV, OPERATIONS_CHILD_ID_ENV, OPERATIONS_CONVERSATION_ID_ENV, OPERATIONS_DEADLINE_AT_ENV, OPERATIONS_ENABLED_ENV, OPERATIONS_ENDPOINT_ENV, OPERATIONS_RUN_ID_ENV, OPERATIONS_TOKEN_ENV, OPERATIONS_WRITER_LEASE_ID_ENV, WAIT_OPERATIONS_TOOL, assertWaitToolDependencies, OperationBridgeError, OperationToolError, cloneJson, deepFreeze, descriptorFingerprint, findBridgeEnvironmentKey, isLaunchTool, normalizeWaitForOperationsResult, requiresParkCheckpoint, parseBridgeEndpoint, validateJsonSchemaSupport, validateJsonSchema, redactSecret, } from "./operation-bridge-types.domain.mjs";
|
|
24
25
|
const ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,255}$/;
|
|
25
26
|
/** Namespace access keeps an older SDK without a VERSION export from failing at import time. */
|
|
26
27
|
const PI_CODING_AGENT_VERSION = piSdk.VERSION;
|
|
@@ -66,6 +67,10 @@ export function readChildOperationBridgeConfig(env = process.env) {
|
|
|
66
67
|
const token = env[OPERATIONS_TOKEN_ENV];
|
|
67
68
|
const runId = env[OPERATIONS_RUN_ID_ENV];
|
|
68
69
|
const conversationId = env[OPERATIONS_CONVERSATION_ID_ENV];
|
|
70
|
+
const deadline = env[OPERATIONS_DEADLINE_AT_ENV];
|
|
71
|
+
if (deadline !== undefined && (!/^\d+$/.test(deadline) || !Number.isSafeInteger(Number(deadline)))) {
|
|
72
|
+
return { status: "invalid", reason: "operation bridge assignment deadline is invalid" };
|
|
73
|
+
}
|
|
69
74
|
try {
|
|
70
75
|
parseBridgeEndpoint(endpoint);
|
|
71
76
|
}
|
|
@@ -85,6 +90,7 @@ export function readChildOperationBridgeConfig(env = process.env) {
|
|
|
85
90
|
token,
|
|
86
91
|
runId,
|
|
87
92
|
conversationId,
|
|
93
|
+
...(deadline !== undefined ? { deadlineAt: Number(deadline) || null } : {}),
|
|
88
94
|
...(env[OPERATIONS_ATTEMPT_ID_ENV] ? { attemptId: env[OPERATIONS_ATTEMPT_ID_ENV] } : {}),
|
|
89
95
|
...(env[OPERATIONS_WRITER_LEASE_ID_ENV] ? { writerLeaseId: env[OPERATIONS_WRITER_LEASE_ID_ENV] } : {}),
|
|
90
96
|
...(env[OPERATIONS_CHILD_ID_ENV] ? { childId: env[OPERATIONS_CHILD_ID_ENV] } : {}),
|
|
@@ -402,6 +408,7 @@ export function verifyDescriptor(value, config) {
|
|
|
402
408
|
}));
|
|
403
409
|
}
|
|
404
410
|
const capabilities = validateCapabilities(record.capabilities);
|
|
411
|
+
assertWaitToolDependencies(capabilities, [...seen]);
|
|
405
412
|
if (seen.has(WAIT_OPERATIONS_TOOL) && !(capabilities.wait && capabilities.parking)) {
|
|
406
413
|
throw new OperationBridgeError("invalid-request", "parent exposed wait_for_operations without a parking capability");
|
|
407
414
|
}
|
|
@@ -621,7 +628,17 @@ export function installChildOperationBridge(pi, options = {}) {
|
|
|
621
628
|
let installed = false;
|
|
622
629
|
let starting;
|
|
623
630
|
let completingPark = false;
|
|
631
|
+
let completion = { correctionUsed: false, reported: false };
|
|
632
|
+
let reportError;
|
|
633
|
+
let bridgeConfig;
|
|
624
634
|
const env = options.env ?? process.env;
|
|
635
|
+
const completionEntryType = "pi-subagent-completion";
|
|
636
|
+
const canCorrectCompletion = (signal) => state.status === "ready"
|
|
637
|
+
&& !completion.correctionUsed && !completion.reported && !signal?.aborted
|
|
638
|
+
&& (bridgeConfig?.deadlineAt == null || Date.now() < bridgeConfig.deadlineAt);
|
|
639
|
+
function saveCompletion() {
|
|
640
|
+
pi.appendEntry(completionEntryType, { attemptId: bridgeConfig?.attemptId ?? bridgeConfig?.runId, ...completion });
|
|
641
|
+
}
|
|
625
642
|
const handle = {
|
|
626
643
|
getState: () => ({ ...state, ...(state.descriptor ? { descriptor: state.descriptor } : {}) }),
|
|
627
644
|
};
|
|
@@ -655,7 +672,7 @@ export function installChildOperationBridge(pi, options = {}) {
|
|
|
655
672
|
if (activeToolExecutions === 0)
|
|
656
673
|
restoreBridgeEnvironment();
|
|
657
674
|
});
|
|
658
|
-
pi.on("session_start", async (_event,
|
|
675
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
659
676
|
if (installed || starting)
|
|
660
677
|
return starting;
|
|
661
678
|
starting = (async () => {
|
|
@@ -669,6 +686,7 @@ export function installChildOperationBridge(pi, options = {}) {
|
|
|
669
686
|
return;
|
|
670
687
|
}
|
|
671
688
|
state.status = "connecting";
|
|
689
|
+
bridgeConfig = read.config;
|
|
672
690
|
options.onDiagnostic?.({ event: "connecting" });
|
|
673
691
|
const active = (options.clientFactory ?? ((config) => createOperationBridgeClient(config, {
|
|
674
692
|
requestTimeoutMs: options.requestTimeoutMs,
|
|
@@ -686,6 +704,19 @@ export function installChildOperationBridge(pi, options = {}) {
|
|
|
686
704
|
}
|
|
687
705
|
client = active;
|
|
688
706
|
state.descriptor = descriptor;
|
|
707
|
+
if (descriptor.capabilities.reportAssignment) {
|
|
708
|
+
const entries = ctx.sessionManager.getEntries();
|
|
709
|
+
for (let index = entries.length - 1; index >= 0; index--) {
|
|
710
|
+
const entry = entries[index];
|
|
711
|
+
if (entry.type !== "custom" || entry.customType !== completionEntryType)
|
|
712
|
+
continue;
|
|
713
|
+
const data = entry.data;
|
|
714
|
+
if (data?.attemptId !== (read.config.attemptId ?? read.config.runId))
|
|
715
|
+
continue;
|
|
716
|
+
completion = { correctionUsed: data.correctionUsed === true, reported: data.reported === true };
|
|
717
|
+
break;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
689
720
|
try {
|
|
690
721
|
registerTools(descriptor, state.parkingSupported === true);
|
|
691
722
|
}
|
|
@@ -703,6 +734,33 @@ export function installChildOperationBridge(pi, options = {}) {
|
|
|
703
734
|
})().finally(() => { starting = undefined; });
|
|
704
735
|
return starting;
|
|
705
736
|
});
|
|
737
|
+
pi.on("before_agent_start", (event, ctx) => {
|
|
738
|
+
if (!state.descriptor?.capabilities.reportAssignment)
|
|
739
|
+
return;
|
|
740
|
+
const instruction = `Assignment completion: call report_assignment_result before returning. Evidence sources must resolve inside this assigned workspace: ${JSON.stringify(ctx.cwd)}. A sibling output directory is outside that boundary; use an existing workspace file or place the reportable artifact inside the workspace. Use offset and max_bytes for evidence larger than 65536 bytes. Continue remaining local work within the existing deadline, or report a concrete blocker; do not infer a tool-call budget from the number of calls you have made.`;
|
|
741
|
+
if (!supportsPromptSections(event.systemPromptOptions))
|
|
742
|
+
return { systemPrompt: `${event.systemPrompt}\n\n${instruction}` };
|
|
743
|
+
const prompt = event.systemPromptOptions;
|
|
744
|
+
(prompt.sections ??= {}).assignment_completion = instruction;
|
|
745
|
+
});
|
|
746
|
+
pi.on("agent_end", (event, ctx) => {
|
|
747
|
+
if (!state.descriptor?.capabilities.reportAssignment || !canCorrectCompletion(ctx.signal))
|
|
748
|
+
return;
|
|
749
|
+
let last;
|
|
750
|
+
for (let index = event.messages.length - 1; index >= 0; index--) {
|
|
751
|
+
const message = event.messages[index];
|
|
752
|
+
if (message.role !== "assistant")
|
|
753
|
+
continue;
|
|
754
|
+
last = message;
|
|
755
|
+
break;
|
|
756
|
+
}
|
|
757
|
+
if (last?.stopReason !== "stop")
|
|
758
|
+
return;
|
|
759
|
+
completion.correctionUsed = true;
|
|
760
|
+
saveCompletion();
|
|
761
|
+
pi.sendMessage({ customType: "assignment-completion-correction", display: false,
|
|
762
|
+
content: `The assignment has no accepted report. ${reportError ? `The latest report was refused: ${reportError}. ` : ""}This is the one completion correction for this execution attempt, within its original authority and deadline. Finish available remaining work, inspect and acknowledge any outstanding operation evidence, then call report_assignment_result with workspace evidence. If progress is blocked or work remains, report incomplete with remaining_work and the concrete blocker. Do not claim completion from process exit or final prose.` }, { deliverAs: "followUp", triggerTurn: true });
|
|
763
|
+
});
|
|
706
764
|
pi.on("message_end", (event) => {
|
|
707
765
|
const message = event.message;
|
|
708
766
|
if (message.role !== "assistant" || !Array.isArray(message.content))
|
|
@@ -777,6 +835,8 @@ export function installChildOperationBridge(pi, options = {}) {
|
|
|
777
835
|
return await invokeTool(tool, toolCallId, params, signal);
|
|
778
836
|
}
|
|
779
837
|
catch (error) {
|
|
838
|
+
if (tool.name === "report_assignment_result")
|
|
839
|
+
reportError = redactSecret(error instanceof Error ? error.message : String(error)).slice(0, 2048);
|
|
780
840
|
return toolErrorResult(error);
|
|
781
841
|
}
|
|
782
842
|
},
|
|
@@ -790,6 +850,13 @@ export function installChildOperationBridge(pi, options = {}) {
|
|
|
790
850
|
throw new OperationToolError("tool parameters must be an object");
|
|
791
851
|
}
|
|
792
852
|
const params = rawParams;
|
|
853
|
+
if (tool.name === "report_assignment_result" && params.status === "incomplete" && !params.blocker
|
|
854
|
+
&& Array.isArray(params.remaining_work) && params.remaining_work.length > 0
|
|
855
|
+
&& validateJsonSchema(tool.parameters, params).ok && canCorrectCompletion(signal)) {
|
|
856
|
+
completion.correctionUsed = true;
|
|
857
|
+
saveCompletion();
|
|
858
|
+
throw new OperationToolError("The incomplete report has not been accepted. Use the one completion correction to continue the listed remaining local work within the original authority and deadline, then report the result. If blocked or still incomplete, report that explicitly; no further automatic correction will be requested.");
|
|
859
|
+
}
|
|
793
860
|
if (isLaunchTool(tool.name, params)) {
|
|
794
861
|
const bridgeEnvironmentField = findBridgeEnvironmentKey(params);
|
|
795
862
|
if (bridgeEnvironmentField) {
|
|
@@ -797,6 +864,17 @@ export function installChildOperationBridge(pi, options = {}) {
|
|
|
797
864
|
}
|
|
798
865
|
}
|
|
799
866
|
const raw = await client.request(tool.name, params, { signal });
|
|
867
|
+
if (tool.name === "report_assignment_result" && raw && typeof raw === "object"
|
|
868
|
+
&& ["complete", "incomplete"].includes(String(raw.status))) {
|
|
869
|
+
completion.reported = true;
|
|
870
|
+
reportError = undefined;
|
|
871
|
+
saveCompletion();
|
|
872
|
+
}
|
|
873
|
+
if (tool.name === ACKNOWLEDGE_OPERATION_TOOL && params.disposition === "assignment-complete"
|
|
874
|
+
&& raw && typeof raw === "object" && raw.phase === "consumed") {
|
|
875
|
+
completion.reported = true;
|
|
876
|
+
saveCompletion();
|
|
877
|
+
}
|
|
800
878
|
if (tool.name === WAIT_OPERATIONS_TOOL) {
|
|
801
879
|
return waitToolResult(toolCallId, raw);
|
|
802
880
|
}
|