pi-better-server 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -3
- package/scripts/copy-pi-test-providers.mjs +10 -0
- package/scripts/event-publication/README.md +26 -0
- package/scripts/event-publication/commit.mjs +21 -0
- package/scripts/event-publication/measure.mjs +37 -5
- package/scripts/event-publication/writer.mjs +3 -8
- package/scripts/measure-full-runtime/frontend.ts +10 -2
- package/scripts/measure-full-runtime/probe.mjs +4 -2
- package/scripts/measure-full-runtime/recovery-trace-loader.mjs +51 -0
- package/scripts/measure-full-runtime/recovery-trace.mjs +16 -0
- package/scripts/measure-full-runtime.mjs +2 -0
- package/scripts/measure-shared-reads.mjs +2 -1
- package/scripts/private-runtime/package-lock.json +18 -0
- package/scripts/private-runtime/package.json +4 -1
- package/scripts/source-provenance.mjs +2 -2
- package/scripts/test-on-pi.sh +2 -9
- package/src/handshake.ts +1 -1
- package/src/hosted-session.ts +32 -4
- package/src/maintenance.ts +35 -7
- package/src/registry.ts +28 -4
- package/src/runtime/attempt-invalidation.ts +54 -0
- package/src/runtime/background-history.ts +151 -45
- package/src/runtime/background-policy.ts +9 -4
- package/src/runtime/background-tools.ts +181 -27
- package/src/runtime/background.ts +365 -70
- package/src/runtime/cancellation.ts +28 -7
- package/src/runtime/catalog-sources.ts +199 -0
- package/src/runtime/catalog.ts +53 -21
- package/src/runtime/client.ts +22 -2
- package/src/runtime/domain/assignment-inbox.mjs +119 -0
- package/src/runtime/domain/assignment-observation.d.mts +1 -1
- package/src/runtime/domain/assignment-observation.mjs +43 -35
- package/src/runtime/domain/background/process-identity.mjs +20 -2
- package/src/runtime/domain/background/process.mjs +52 -14
- package/src/runtime/domain/background/registry.mjs +61 -3
- package/src/runtime/domain/background/supervisor/store.mjs +3 -3
- package/src/runtime/domain/background/supervisor/supervisor.mjs +9 -3
- package/src/runtime/domain/background/types.mjs +1 -0
- package/src/runtime/domain/background-service/adapter-contract.domain.mjs +1 -1
- package/src/runtime/domain/background-service/adapter-contract.ts +1 -1
- package/src/runtime/domain/background-service/goal-provider.domain.mjs +35 -16
- package/src/runtime/domain/background-service/goal-provider.ts +31 -16
- package/src/runtime/domain/background-service/index.domain.mjs +25 -9
- package/src/runtime/domain/background-service/index.ts +25 -9
- package/src/runtime/domain/background-service/managed-authority.domain.mjs +6 -3
- package/src/runtime/domain/background-service/managed-authority.ts +5 -3
- package/src/runtime/domain/background-service/managed-client.domain.mjs +21 -7
- package/src/runtime/domain/background-service/managed-client.ts +20 -7
- package/src/runtime/domain/background-service/managed-frontend.domain.mjs +159 -19
- package/src/runtime/domain/background-service/managed-frontend.ts +135 -19
- package/src/runtime/domain/background-service/navigator-provider.domain.mjs +21 -5
- package/src/runtime/domain/background-service/navigator-provider.ts +19 -5
- package/src/runtime/domain/background-service/observed-wait-client.domain.mjs +6 -0
- package/src/runtime/domain/background-service/observed-wait-client.ts +10 -0
- package/src/runtime/domain/background-service/observed-waits.domain.mjs +372 -57
- package/src/runtime/domain/background-service/observed-waits.ts +321 -53
- package/src/runtime/domain/background-service/process-identity.domain.mjs +20 -2
- package/src/runtime/domain/background-service/process-identity.ts +18 -2
- package/src/runtime/domain/background-service/process.domain.mjs +52 -14
- package/src/runtime/domain/background-service/process.ts +48 -14
- package/src/runtime/domain/background-service/registry.domain.mjs +61 -3
- package/src/runtime/domain/background-service/registry.ts +53 -5
- package/src/runtime/domain/background-service/review-settings.domain.mjs +16 -0
- package/src/runtime/domain/background-service/review-settings.ts +18 -0
- package/src/runtime/domain/background-service/runtime.domain.mjs +40 -86
- package/src/runtime/domain/background-service/runtime.ts +27 -82
- package/src/runtime/domain/background-service/sandbox.domain.mjs +14 -15
- package/src/runtime/domain/background-service/sandbox.ts +14 -11
- package/src/runtime/domain/background-service/shared-callback-batcher.domain.mjs +8 -1
- package/src/runtime/domain/background-service/shared-callback-batcher.ts +11 -2
- package/src/runtime/domain/background-service/shared-navigator-panels.domain.mjs +24 -2
- package/src/runtime/domain/background-service/shared-navigator-panels.ts +26 -4
- package/src/runtime/domain/background-service/shared-navigator.domain.mjs +273 -41
- package/src/runtime/domain/background-service/shared-navigator.ts +244 -40
- package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-inbox.mjs +144 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-observation.mjs +53 -41
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.ts +73 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.ts +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.domain.mjs +11 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.ts +14 -3
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.domain.mjs +4 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.ts +5 -3
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.domain.mjs +44 -4
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.ts +50 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.domain.mjs +7 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.ts +9 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.domain.mjs +12 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.ts +12 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.domain.mjs +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.ts +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.domain.mjs +42 -21
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.ts +40 -24
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +26 -4
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +40 -8
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.domain.mjs +23 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.ts +24 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.domain.mjs +1 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.ts +5 -1
- package/src/runtime/domain/background-service/shared-sandbox-core.ts +1 -1
- package/src/runtime/domain/background-service/shared-work-client.mjs +174 -7
- package/src/runtime/domain/background-service/stall.domain.mjs +5 -3
- package/src/runtime/domain/background-service/stall.ts +7 -4
- package/src/runtime/domain/background-service/supervised-progress.domain.mjs +42 -0
- package/src/runtime/domain/background-service/supervised-progress.ts +43 -0
- package/src/runtime/domain/background-service/supervisor/README.md +1 -4
- package/src/runtime/domain/background-service/supervisor/emit-runner.mjs +1 -0
- package/src/runtime/domain/background-service/supervisor/generated/process-identity.mjs +20 -2
- package/src/runtime/domain/background-service/supervisor/generated/process.mjs +52 -14
- package/src/runtime/domain/background-service/supervisor/generated/runner.mjs +47 -4
- package/src/runtime/domain/background-service/supervisor/generated/store.mjs +3 -3
- package/src/runtime/domain/background-service/supervisor/generated/watch-fingerprint.mjs +69 -0
- package/src/runtime/domain/background-service/supervisor/runner.domain.mjs +47 -4
- package/src/runtime/domain/background-service/supervisor/runner.ts +38 -3
- package/src/runtime/domain/background-service/supervisor/store.domain.mjs +3 -3
- package/src/runtime/domain/background-service/supervisor/store.ts +3 -3
- package/src/runtime/domain/background-service/supervisor/supervisor.domain.mjs +9 -3
- package/src/runtime/domain/background-service/supervisor/supervisor.ts +6 -3
- package/src/runtime/domain/background-service/task-diagnostics.domain.mjs +1 -1
- package/src/runtime/domain/background-service/task-diagnostics.ts +1 -1
- package/src/runtime/domain/background-service/tools.domain.mjs +53 -40
- package/src/runtime/domain/background-service/tools.ts +67 -54
- package/src/runtime/domain/background-service/types.domain.mjs +1 -0
- package/src/runtime/domain/background-service/types.ts +7 -3
- package/src/runtime/domain/background-service/watch-fingerprint.domain.mjs +67 -0
- package/src/runtime/domain/background-service/watch-fingerprint.ts +70 -0
- package/src/runtime/domain/background-service/work-observation.domain.mjs +46 -20
- package/src/runtime/domain/background-service/work-observation.ts +46 -19
- package/src/runtime/domain/catalog/catalog-store.d.mts +9 -1
- package/src/runtime/domain/catalog/catalog-store.mjs +20 -22
- package/src/runtime/domain/coordinator/src/assignment-changes.mjs +75 -0
- package/src/runtime/domain/coordinator/src/assignment-outcomes.mjs +2 -0
- package/src/runtime/domain/coordinator/src/background-requests.mjs +11 -2
- package/src/runtime/domain/coordinator/src/discovery.mjs +4 -2
- package/src/runtime/domain/coordinator/src/operations.mjs +44 -4
- package/src/runtime/domain/coordinator/src/outbox.mjs +7 -0
- package/src/runtime/domain/coordinator/src/result-supervision.mjs +12 -0
- package/src/runtime/domain/coordinator/src/rows.mjs +2 -0
- package/src/runtime/domain/coordinator/src/schema.mjs +42 -21
- package/src/runtime/domain/coordinator/src/store.mjs +26 -4
- package/src/runtime/domain/coordinator/src/subagent-launch.mjs +23 -1
- package/src/runtime/domain/coordinator/src/types.mjs +1 -1
- package/src/runtime/domain/health-observation.d.mts +3 -1
- package/src/runtime/domain/health-observation.mjs +189 -190
- package/src/runtime/domain/log-cursor.d.mts +2 -0
- package/src/runtime/domain/log-cursor.mjs +85 -16
- package/src/runtime/domain/log-paths.mjs +8 -1
- package/src/runtime/domain/parse.d.mts +4 -1
- package/src/runtime/domain/parse.mjs +58 -9
- package/src/runtime/domain/sandbox-policy/README.md +63 -65
- package/src/runtime/domain/sandbox-policy/commands.domain.mjs +11 -8
- package/src/runtime/domain/sandbox-policy/commands.ts +12 -7
- package/src/runtime/domain/sandbox-policy/index.domain.mjs +53 -9
- package/src/runtime/domain/sandbox-policy/index.ts +52 -9
- package/src/runtime/domain/sandbox-policy/package.json +1 -1
- package/src/runtime/domain/sandbox-policy/permission-settings.domain.mjs +5 -2
- package/src/runtime/domain/sandbox-policy/permission-settings.ts +9 -2
- package/src/runtime/domain/sandbox-policy/permissions-page.domain.mjs +56 -137
- package/src/runtime/domain/sandbox-policy/permissions-page.ts +52 -130
- package/src/runtime/domain/sandbox-policy/permissions.domain.mjs +1 -6
- package/src/runtime/domain/sandbox-policy/permissions.ts +1 -6
- package/src/runtime/domain/sandbox-policy/shared-sandbox-core.ts +1 -1
- package/src/runtime/domain/sandbox-policy/shared-task-exec.domain.mjs +14 -1
- package/src/runtime/domain/sandbox-policy/shared-task-exec.ts +12 -1
- package/src/runtime/domain/sandbox-policy/shared-task-process-identity.domain.mjs +140 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-identity.ts +126 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-list.domain.mjs +3 -2
- package/src/runtime/domain/sandbox-policy/shared-task-process-list.ts +8 -2
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.domain.mjs +4 -3
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.ts +5 -3
- package/src/runtime/domain/sandbox-policy/shared-task-tools.domain.mjs +8 -5
- package/src/runtime/domain/sandbox-policy/shared-task-tools.ts +8 -5
- package/src/runtime/domain/session-store.mjs +7 -0
- package/src/runtime/domain/subagents/README.md +13 -11
- package/src/runtime/domain/subagents/assignment-outcomes.domain.mjs +10 -7
- package/src/runtime/domain/subagents/assignment-outcomes.ts +9 -6
- package/src/runtime/domain/subagents/assignment-report.domain.mjs +109 -24
- package/src/runtime/domain/subagents/assignment-report.ts +103 -19
- package/src/runtime/domain/subagents/batch.mjs +13 -5
- package/src/runtime/domain/subagents/catalog-host-admission.domain.mjs +21 -3
- package/src/runtime/domain/subagents/catalog-host-admission.ts +19 -3
- package/src/runtime/domain/subagents/catalog-preferences.ts +1 -1
- package/src/runtime/domain/subagents/catalog-resolver.domain.mjs +35 -1
- package/src/runtime/domain/subagents/catalog-resolver.ts +35 -1
- package/src/runtime/domain/subagents/catalog-store.domain.mjs +20 -22
- package/src/runtime/domain/subagents/catalog-store.ts +27 -20
- package/src/runtime/domain/subagents/child-apply-patch.domain.mjs +13 -0
- package/src/runtime/domain/subagents/child-apply-patch.ts +13 -0
- package/src/runtime/domain/subagents/child-dependencies.mjs +27 -15
- package/src/runtime/domain/subagents/child-operations.domain.mjs +80 -2
- package/src/runtime/domain/subagents/child-operations.ts +80 -1
- package/src/runtime/domain/subagents/child-preflight.mjs +9 -2
- package/src/runtime/domain/subagents/child-process-list.domain.mjs +7 -0
- package/src/runtime/domain/subagents/child-process-list.ts +8 -0
- package/src/runtime/domain/subagents/cleanup.domain.mjs +11 -2
- package/src/runtime/domain/subagents/cleanup.ts +10 -2
- package/src/runtime/domain/subagents/config.domain.mjs +54 -2
- package/src/runtime/domain/subagents/config.ts +53 -3
- package/src/runtime/domain/subagents/continuation-authority.domain.mjs +5 -1
- package/src/runtime/domain/subagents/continuation-authority.ts +3 -1
- package/src/runtime/domain/subagents/continuation-runtime.domain.mjs +89 -0
- package/src/runtime/domain/subagents/continuation-runtime.ts +88 -0
- package/src/runtime/domain/subagents/continuation.domain.mjs +4 -2
- package/src/runtime/domain/subagents/continuation.ts +4 -2
- package/src/runtime/domain/subagents/extensions.mjs +11 -13
- package/src/runtime/domain/subagents/failures.domain.mjs +11 -2
- package/src/runtime/domain/subagents/failures.ts +10 -2
- package/src/runtime/domain/subagents/finalization.domain.mjs +16 -1
- package/src/runtime/domain/subagents/finalization.ts +21 -1
- package/src/runtime/domain/subagents/goal-provider.domain.mjs +44 -2
- package/src/runtime/domain/subagents/goal-provider.ts +44 -2
- package/src/runtime/domain/subagents/health-observation.domain.mjs +189 -190
- package/src/runtime/domain/subagents/health-observation.ts +43 -48
- package/src/runtime/domain/subagents/index.domain.mjs +457 -182
- package/src/runtime/domain/subagents/index.ts +417 -155
- package/src/runtime/domain/subagents/isolated-workspace.domain.mjs +515 -0
- package/src/runtime/domain/subagents/isolated-workspace.ts +557 -0
- package/src/runtime/domain/subagents/launch-context.domain.mjs +24 -0
- package/src/runtime/domain/subagents/launch-context.ts +23 -0
- package/src/runtime/domain/subagents/launch-digest.mjs +6 -0
- package/src/runtime/domain/subagents/list.mjs +2 -2
- package/src/runtime/domain/subagents/log-cursor.domain.mjs +85 -16
- package/src/runtime/domain/subagents/log-cursor.ts +91 -15
- package/src/runtime/domain/subagents/managed-launch-bootstrap.mjs +2 -2
- package/src/runtime/domain/subagents/managed-launch-client.domain.mjs +27 -7
- package/src/runtime/domain/subagents/managed-launch-client.ts +28 -8
- package/src/runtime/domain/subagents/managed-launch-host.domain.mjs +222 -14
- package/src/runtime/domain/subagents/managed-launch-host.ts +168 -15
- package/src/runtime/domain/subagents/managed-launch-journal.mjs +1 -5
- package/src/runtime/domain/subagents/managed-launch-port.ts +4 -0
- package/src/runtime/domain/subagents/operation-bridge-types.domain.mjs +27 -2
- package/src/runtime/domain/subagents/operation-bridge-types.ts +27 -2
- package/src/runtime/domain/subagents/output-payload.domain.mjs +24 -9
- package/src/runtime/domain/subagents/output-payload.ts +26 -12
- package/src/runtime/domain/subagents/owned-exit.domain.mjs +12 -0
- package/src/runtime/domain/subagents/owned-exit.ts +12 -0
- package/src/runtime/domain/subagents/package.json +4 -2
- package/src/runtime/domain/subagents/parse.domain.mjs +58 -9
- package/src/runtime/domain/subagents/parse.ts +57 -10
- package/src/runtime/domain/subagents/permission-policy.domain.mjs +32 -8
- package/src/runtime/domain/subagents/permission-policy.ts +41 -8
- package/src/runtime/domain/subagents/process-identity.mjs +33 -0
- package/src/runtime/domain/subagents/registry.domain.mjs +71 -51
- package/src/runtime/domain/subagents/registry.ts +77 -38
- package/src/runtime/domain/subagents/retained-result.domain.mjs +56 -0
- package/src/runtime/domain/subagents/retained-result.ts +65 -0
- package/src/runtime/domain/subagents/session-selection.domain.mjs +3 -1
- package/src/runtime/domain/subagents/session-selection.ts +2 -1
- package/src/runtime/domain/subagents/session-store.domain.mjs +7 -0
- package/src/runtime/domain/subagents/session-store.ts +9 -0
- package/src/runtime/domain/subagents/settings-page.domain.mjs +151 -107
- package/src/runtime/domain/subagents/settings-page.ts +147 -108
- package/src/runtime/domain/subagents/shared-callback-batcher.domain.mjs +8 -1
- package/src/runtime/domain/subagents/shared-callback-batcher.ts +11 -2
- package/src/runtime/domain/subagents/shared-catalog.domain.mjs +28 -29
- package/src/runtime/domain/subagents/shared-catalog.ts +29 -21
- package/src/runtime/domain/subagents/shared-navigator-panels.domain.mjs +24 -2
- package/src/runtime/domain/subagents/shared-navigator-panels.ts +26 -4
- package/src/runtime/domain/subagents/shared-navigator.domain.mjs +273 -41
- package/src/runtime/domain/subagents/shared-navigator.ts +244 -40
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-inbox.mjs +144 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-observation.mjs +53 -41
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.ts +73 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.ts +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.domain.mjs +11 -2
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.ts +14 -3
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.domain.mjs +4 -2
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.ts +5 -3
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.domain.mjs +44 -4
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.ts +50 -2
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.domain.mjs +7 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.ts +9 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.domain.mjs +12 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.ts +12 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.domain.mjs +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.ts +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.domain.mjs +42 -21
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.ts +40 -24
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +26 -4
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +40 -8
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.domain.mjs +23 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.ts +24 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.domain.mjs +1 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.ts +5 -1
- package/src/runtime/domain/subagents/shared-sandbox-core.ts +1 -1
- package/src/runtime/domain/subagents/shared-task-exec.domain.mjs +14 -1
- package/src/runtime/domain/subagents/shared-task-exec.ts +12 -1
- package/src/runtime/domain/subagents/shared-task-process-identity.domain.mjs +140 -0
- package/src/runtime/domain/subagents/shared-task-process-identity.ts +126 -0
- package/src/runtime/domain/subagents/shared-task-process-list.domain.mjs +3 -2
- package/src/runtime/domain/subagents/shared-task-process-list.ts +8 -2
- package/src/runtime/domain/subagents/shared-task-sandbox.domain.mjs +4 -3
- package/src/runtime/domain/subagents/shared-task-sandbox.ts +5 -3
- package/src/runtime/domain/subagents/shared-task-tools.domain.mjs +8 -5
- package/src/runtime/domain/subagents/shared-task-tools.ts +8 -5
- package/src/runtime/domain/subagents/shared-work-client.mjs +174 -7
- package/src/runtime/domain/subagents/subagent-tools.domain.mjs +22 -38
- package/src/runtime/domain/subagents/subagent-tools.ts +28 -34
- package/src/runtime/domain/subagents/task-guard.domain.mjs +14 -1
- package/src/runtime/domain/subagents/task-guard.ts +13 -1
- package/src/runtime/domain/subagents/task-policy.domain.mjs +3 -2
- package/src/runtime/domain/subagents/task-policy.ts +8 -2
- package/src/runtime/domain/subagents/timing.domain.mjs +10 -1
- package/src/runtime/domain/subagents/timing.ts +10 -1
- package/src/runtime/domain/subagents/tools.domain.mjs +4 -8
- package/src/runtime/domain/subagents/tools.ts +4 -7
- package/src/runtime/domain/subagents/work-observation.domain.mjs +102 -17
- package/src/runtime/domain/subagents/work-observation.ts +91 -17
- package/src/runtime/domain/subagents/worker-operations-host.domain.mjs +9 -4
- package/src/runtime/domain/subagents/worker-operations-host.ts +12 -4
- package/src/runtime/domain/subagents/worker-waits.domain.mjs +89 -35
- package/src/runtime/domain/subagents/worker-waits.ts +93 -34
- package/src/runtime/domain/subagents/workspace-files.domain.mjs +103 -0
- package/src/runtime/domain/subagents/workspace-files.ts +114 -0
- package/src/runtime/domain/subagents/workspace-scope.domain.d.mts +38 -0
- package/src/runtime/domain/subagents/workspace-scope.domain.mjs +5 -0
- package/src/runtime/domain/subagents/workspace-scope.ts +6 -0
- package/src/runtime/domain/subagents/worktree-feedback.domain.mjs +55 -0
- package/src/runtime/domain/subagents/worktree-feedback.ts +77 -0
- package/src/runtime/health-config.ts +27 -11
- package/src/runtime/log-checkpoints.ts +117 -0
- package/src/runtime/mutation-store.ts +5 -4
- package/src/runtime/queries.ts +25 -2
- package/src/runtime/query-executor.ts +149 -28
- package/src/runtime/query-worker.mjs +106 -21
- package/src/runtime/read-model.ts +849 -121
- package/src/runtime/read-watchdog-probe.ts +4 -0
- package/src/runtime/result-supervision.ts +188 -16
- package/src/runtime/root.ts +5 -2
- package/src/runtime/source-watch.ts +175 -0
- package/src/runtime/subagent-launch.ts +11 -4
- package/src/runtime/work-budget.ts +130 -0
- package/src/runtime/work-client.d.mts +8 -0
- package/src/runtime/work-client.mjs +150 -7
- package/src/server.ts +104 -23
- package/src/session-activity.ts +26 -4
- package/src/version.ts +1 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-subagents/index.ts. Do not edit directly.
|
|
2
|
+
import { shouldRestoreWorkObservation } from "./shared-work-client.mjs";
|
|
2
3
|
import { appendTimingWake, removeTimingReceipt, receiptTimingWake, timingWakeReceipt } from "./timing-notifications.domain.mjs";
|
|
4
|
+
import { captureLaunchContext } from "./launch-context.domain.mjs";
|
|
3
5
|
/**
|
|
4
6
|
* pi-better-subagents — Claude Code-style async subagents for pi.
|
|
5
7
|
*
|
|
@@ -16,7 +18,7 @@ import { createAssignmentProjector } from "./assignment-projection.mjs";
|
|
|
16
18
|
import { historicalWaits, attentionRevision, attentionDismissed, dismissAttention } from "./historical-attention.domain.mjs";
|
|
17
19
|
import { registerAssignmentAttempt, commitAssignmentTerminal, readOutcome, receiptOutcome, outcomeTranscriptReceipt, inspectOutcome, createOutcomeHost, closeOutcomeHost, claimOutcome } from "./assignment-outcomes.domain.mjs";
|
|
18
20
|
import { currentSandboxPermissions } from "./permission-policy.domain.mjs";
|
|
19
|
-
import { createToolDescriptor } from "./operation-bridge-types.domain.mjs";
|
|
21
|
+
import { assertWaitToolDependencies, createToolDescriptor } from "./operation-bridge-types.domain.mjs";
|
|
20
22
|
import { requestResumeAdmission } from "./worker-waits.domain.mjs";
|
|
21
23
|
import { execSync } from "node:child_process";
|
|
22
24
|
import { writeFileSync, mkdirSync, renameSync, statSync } from "node:fs";
|
|
@@ -24,41 +26,40 @@ import * as PiCodingAgent from "@earendil-works/pi-coding-agent";
|
|
|
24
26
|
import * as PiTui from "@earendil-works/pi-tui";
|
|
25
27
|
import { CustomEditor } from "@earendil-works/pi-coding-agent";
|
|
26
28
|
import { initializeNavigatorPanels } from "./shared-navigator-panels.domain.mjs";
|
|
27
|
-
import { workObservation, workObservationFailure,
|
|
29
|
+
import { workObservation, workObservationStarted, workObservationFailure, configureWorkObservation, activateWorkObservation, stopWorkObservation, observedAssignment, observedList, requestWorkDetail, TERMINAL_NAVIGATOR_RETENTION_MS } from "./work-observation.domain.mjs";
|
|
28
30
|
import { withAssignmentObservations } from "./assignment-projection.mjs";
|
|
29
31
|
import { formatNavigatorHealthFacts } from "./health-surface.mjs";
|
|
30
32
|
import { matchesKey, Key, truncateToWidth } from "@earendil-works/pi-tui";
|
|
31
33
|
import { Type } from "typebox";
|
|
32
|
-
import { disposeBackgroundWorkNavigator, ensureBackgroundWorkNavigator, isNavigatorUiAvailable, refreshBackgroundWorkNavigator, registerBackgroundWorkProvider, renderRegisteredWorkDetail, } from "./shared-navigator.domain.mjs";
|
|
34
|
+
import { disposeBackgroundWorkNavigator, ensureBackgroundWorkNavigator, isNavigatorUiAvailable, refreshBackgroundWorkNavigator, registerBackgroundWorkProvider, observeNavigatorLaunch, renderRegisteredWorkDetail, } from "./shared-navigator.domain.mjs";
|
|
33
35
|
import { spawnDetached } from "./spawn.domain.mjs";
|
|
34
|
-
import { abortUncommittedLaunch } from "./launch-abort.domain.mjs";
|
|
35
36
|
import { parseRun, parseRunForLifecycle, resetParseRunCursor } from "./parse.domain.mjs";
|
|
36
|
-
import { finalizeRun as finalizeRunCore } from "./finalization.domain.mjs";
|
|
37
|
+
import { finalizeRun as finalizeRunCore, reconcileInterruptedRun } from "./finalization.domain.mjs";
|
|
38
|
+
import { completeOwnedExit } from "./owned-exit.domain.mjs";
|
|
37
39
|
import { selectSessionByName } from "./session-selection.domain.mjs";
|
|
38
40
|
import { isWithinWorkspace } from "./workspace-scope.domain.mjs";
|
|
39
|
-
import {
|
|
41
|
+
import { BUILTIN_TOOLS } from "./extensions.domain.mjs";
|
|
42
|
+
import { ORDINARY_TOOL_PROVIDERS, activeChildProviders, ordinaryChildConfig, addEditablePatch, loadConfig, writeDelegationMode, writeSubagentSettings, isConcurrencyCap, normalizeConcurrencyCap, normalizeTools, resolveExtensionPath, configPath, selfDir, SAFE_DEFAULT_TOOLS, SAFE_CLEAN_TOOLS } from "./config.domain.mjs";
|
|
40
43
|
import { createSubagentSettingsPage } from "./settings-page.domain.mjs";
|
|
41
44
|
import { deliverSubagentPrompt, effectiveSubagentSettings, subagentSettingsTool } from "./effective-settings.domain.mjs";
|
|
42
45
|
import { STEER_FILE_ENV, readSteerReceipt } from "./child-steer.domain.mjs";
|
|
43
46
|
import { continuationTimingParams, decideTiming, describeTiming, DEFAULT_TIMING_MINUTES, emptyProgress, foldProgress, formatTimingLimits, isTimingMinutes, isProgressRelevantLine, resolveRunTiming, steerText, stuckAlertText, TIMING_ENV, timingParameterSchemas, toolWaitAlertText, validatedTimingMinutes, } from "./timing.domain.mjs";
|
|
44
47
|
import { readAppendedLines } from "./log-cursor.domain.mjs";
|
|
45
48
|
import { DELEGATION_MODES, DELEGATION_MODE_REQUEST, isDelegationMode, normalizeDelegationMode } from "./delegation.domain.mjs";
|
|
46
|
-
import { resolveChildClosure, resolveChildLaunch, configSnapshot } from "./child-dependencies.mjs";
|
|
47
|
-
import { PREFLIGHT_ENV } from "./child-preflight.mjs";
|
|
48
49
|
import { resolveExtensions, extensionArgs } from "./extensions.domain.mjs";
|
|
49
|
-
import { prepareTaskRuntime, applyDirectApplicationLoadout, RUN_APPLICATION, SDK_BUILTIN_TOOLS } from "./task-policy.domain.mjs";
|
|
50
|
-
import {
|
|
50
|
+
import { prepareTaskRuntime, applyDirectApplicationLoadout, DEFAULT_TASK_PERMISSIONS, RUN_APPLICATION, SDK_BUILTIN_TOOLS } from "./task-policy.domain.mjs";
|
|
51
|
+
import { worktreePolicyNotice } from "./worktree-feedback.domain.mjs";
|
|
52
|
+
import { canonicalizePath, compileWritePolicy, takeRecoverySnapshot } from "./shared-sandbox-core.domain.mjs";
|
|
51
53
|
import { TASK_BUILTINS } from "./shared-task-sandbox.domain.mjs";
|
|
52
|
-
import {
|
|
53
|
-
import { announceExecutionAdapter, observeSandboxPermissions, resolveCommandSettings, resolveSubagentPermissions, } from "./permission-policy.domain.mjs";
|
|
54
|
-
import { resolveSubagentWorkspace } from "./git-workspace.domain.mjs";
|
|
54
|
+
import { describeTaskTools, planTaskTools, selectEffectiveTaskTools } from "./subagent-tools.domain.mjs";
|
|
55
|
+
import { announceExecutionAdapter, describeSubagentProcessPolicy, effectiveWorkerProcessAccess, observeSandboxPermissions, resolveCommandSettings, resolveSubagentPermissions, } from "./permission-policy.domain.mjs";
|
|
55
56
|
import { dirname, isAbsolute, join } from "node:path";
|
|
56
57
|
import { baseDir, taskWorkspaceDir, sessionsDir, runDir, recordTaskRuntimeProvenance, recordLaunchAttempt, clearLaunchAttempt, logPathFor, promptPathFor, nextRunId, writeMeta, readMeta, listMetas, listActiveMetasForParent, listMetasForOrigin, listMetasForParent, onMetaChanged, effectiveStatus, ownedByThisParent as ownedByFrontend, navigatorVisibleRuns, dismissRun, } from "./registry.domain.mjs";
|
|
57
58
|
import { captureProcessIdentity, extractChildEventFactsFromLog, loadHealthThresholdsFromConfig, isAbandonedByParent, needsMonitoring, observeRunHealth, realProcessProbe, reconcileRun, resetChildEventLogCursor, } from "./health.domain.mjs";
|
|
58
|
-
import { assignBatchJobNames, batchLaunchOutputSchema, batchLaunchResult, mergeJobOptions, nextBatchId, planBatchLaunches, validateBatchPlan, } from "./batch.mjs";
|
|
59
|
+
import { assignBatchJobNames, batchLaunchOutputSchema, batchLaunchResult, mergeJobOptions, nextBatchId, normalizeSessionSelector, planBatchLaunches, validateBatchPlan, } from "./batch.mjs";
|
|
59
60
|
import { formatCapacityRejectMessage, getSharedCapacityGate, } from "./capacity.mjs";
|
|
60
61
|
import { buildHealthCallbackDelivery } from "./completion.domain.mjs";
|
|
61
|
-
import { cancelCallbackBatch, getCallbackBatcher, setCallbackBatchContext } from "./shared-callback-batcher.domain.mjs";
|
|
62
|
+
import { cancelCallbackBatch, getCallbackBatcher, packCallbackBatch, setCallbackBatchContext } from "./shared-callback-batcher.domain.mjs";
|
|
62
63
|
let managementPort;
|
|
63
64
|
const ownedByThisParent = (meta) => managementPort ? managementPort.owns(meta) : ownedByFrontend(meta);
|
|
64
65
|
const supervisedMetas = () => managementPort ? managementPort.supervised() : listMetasForParent(process.pid);
|
|
@@ -70,6 +71,7 @@ import { stopRun } from "./stop.domain.mjs";
|
|
|
70
71
|
import { WIDGET_CLEAR, fmtElapsed, fmtSpend, fmtTokens, shortModel, isSpendCacheFresh, resolveHealthLogExtraction, withinRefreshFloor, } from "./widget.domain.mjs";
|
|
71
72
|
import { executeNavigatorClose, pendingNavigatorPark, buildNavigatorDetail, } from "./navigator.domain.mjs";
|
|
72
73
|
import { enforceRegistrySizeCapOnce, runDailyCleanupOnce } from "./cleanup.domain.mjs";
|
|
74
|
+
import { managedRuntimeRoot, selectContinuationRuntime } from "./continuation-runtime.domain.mjs";
|
|
73
75
|
import { ContinuationError, acquireConversationLease, assertContinuationExtensions, buildLaunchRecipe, planContinuation, } from "./continuation.domain.mjs";
|
|
74
76
|
import { createHash } from "node:crypto";
|
|
75
77
|
import { assertThinkingLevel, parseModelThinking } from "./thinking.domain.mjs";
|
|
@@ -166,7 +168,7 @@ function callbackOriginFromContext(ctx) {
|
|
|
166
168
|
catch {
|
|
167
169
|
sessionId = undefined;
|
|
168
170
|
}
|
|
169
|
-
return { cwd: ctx.cwd, sessionId };
|
|
171
|
+
return { cwd: ctx.cwd, sessionId, branchId: ctx.sessionManager?.getLeafId?.() ?? null };
|
|
170
172
|
}
|
|
171
173
|
/** Origin with a readable session id, or undefined when identity is unavailable. */
|
|
172
174
|
function verifiedOriginFromContext(ctx) {
|
|
@@ -483,10 +485,57 @@ async function tryEnqueueAssignmentOutcome(pi, meta) {
|
|
|
483
485
|
return;
|
|
484
486
|
}
|
|
485
487
|
const deliveryHost = outcomeHost;
|
|
486
|
-
|
|
488
|
+
// The Goal scheduler can take up to 20 seconds. Keep the short probe only
|
|
489
|
+
// for a standalone parent, with no bound Goal or acknowledged check.
|
|
490
|
+
const workflowBudgetMs = 25_000;
|
|
491
|
+
const gate = await requestResumeAdmission(pi, active, {
|
|
492
|
+
timeoutMs: active.goalId || outcome.recipient.goalId ? workflowBudgetMs : 50,
|
|
493
|
+
pendingTimeoutMs: workflowBudgetMs,
|
|
494
|
+
});
|
|
487
495
|
outcomeAdmission.set(outcome.eventId, () => gate.allowed ? gate.isCurrent?.() !== false : !active.goalId && !outcome.recipient.goalId && gate.revision === -1);
|
|
488
496
|
if (!gate.allowed && (active.goalId || outcome.recipient.goalId || gate.revision !== -1)) {
|
|
489
|
-
|
|
497
|
+
// Admission controls model execution, not delivery of an already
|
|
498
|
+
// committed result. Paused Goals still owe their human a notification.
|
|
499
|
+
if (sessionTornDown || outcomeHost !== deliveryHost || uiCtx !== ctx || callbackSuppressionReason(meta)
|
|
500
|
+
|| (outcome.recipient.branchId && !ctx.sessionManager.getBranch().some(entry => entry.id === outcome.recipient.branchId))) {
|
|
501
|
+
deferOutcome(meta, "Recorded parent delivery scope changed; automatic reconciliation will retry.");
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
// Native Pi queues messages during a turn even with triggerTurn:false.
|
|
505
|
+
// Wait for idle so replay cannot enqueue the same unreceipted message.
|
|
506
|
+
if (!ctx.isIdle()) {
|
|
507
|
+
deferOutcome(meta, "Waiting for an idle parent to append the outcome without starting a turn.");
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
if (!claimOutcome(meta, deliveryHost)) {
|
|
511
|
+
deferOutcome(meta, "Outcome dispatch is owned by another host; automatic reconciliation will retry.");
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
const details = { completionEventIds: [outcome.eventId] };
|
|
515
|
+
const packed = packCallbackBatch([{
|
|
516
|
+
source: "subagent", id: outcome.eventId, inspectId: meta.id, receiptId: outcome.eventId,
|
|
517
|
+
label: meta.name ?? meta.id, status: outcome.outcome, outcome: outcome.reason,
|
|
518
|
+
detailTool: "subagent_result", callback: true,
|
|
519
|
+
}]);
|
|
520
|
+
try {
|
|
521
|
+
await pi.sendMessage({ customType: "background-completion-batch", display: true,
|
|
522
|
+
content: `${packed.text}\nAutomatic continuation: ${gate.reason}`, details }, { triggerTurn: false });
|
|
523
|
+
}
|
|
524
|
+
catch (error) {
|
|
525
|
+
// A failed persistence must not look like a durable transcript receipt.
|
|
526
|
+
details.completionEventIds.length = 0;
|
|
527
|
+
throw error;
|
|
528
|
+
}
|
|
529
|
+
const entry = outcomeTranscriptReceipt(ctx.sessionManager.getBranch(), outcome.eventId);
|
|
530
|
+
if (!entry)
|
|
531
|
+
throw new Error("Awaiting durable recipient transcript receipt.");
|
|
532
|
+
receiptOutcome(meta, entry);
|
|
533
|
+
markCompletionCallbackSent(meta.id, Date.now());
|
|
534
|
+
deferOutcome(meta);
|
|
535
|
+
try {
|
|
536
|
+
ctx.ui?.notify(`${meta.name ?? meta.id}: ${outcome.outcome}. Automatic continuation: ${gate.reason}. Inspect subagent_result.`, outcome.outcome === "failed" ? "warning" : "info");
|
|
537
|
+
}
|
|
538
|
+
catch { /* transcript remains visible */ }
|
|
490
539
|
return;
|
|
491
540
|
}
|
|
492
541
|
// Admission may yield across a session switch or Goal/workflow change.
|
|
@@ -639,19 +688,13 @@ function deliverFailureAttention(pi, meta, now) {
|
|
|
639
688
|
function markHealthCallbackSuppressed(meta, status, reason, now) {
|
|
640
689
|
if (isConversationIdentityReason(reason))
|
|
641
690
|
return;
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
if (meta.lostCallbackSuppressedAt !== undefined)
|
|
650
|
-
return;
|
|
651
|
-
meta.lostCallbackSuppressedAt = now;
|
|
652
|
-
meta.lostCallbackSuppressedReason = reason;
|
|
653
|
-
}
|
|
654
|
-
writeMeta(meta);
|
|
691
|
+
writeMeta(meta, { patch: current => {
|
|
692
|
+
if (isHealthCallbackHandled(current, status))
|
|
693
|
+
return;
|
|
694
|
+
return status === "orphaned"
|
|
695
|
+
? { orphanedCallbackSuppressedAt: now, orphanedCallbackSuppressedReason: reason }
|
|
696
|
+
: { lostCallbackSuppressedAt: now, lostCallbackSuppressedReason: reason };
|
|
697
|
+
} });
|
|
655
698
|
}
|
|
656
699
|
function isHealthCallbackHandled(meta, status) {
|
|
657
700
|
return status === "orphaned"
|
|
@@ -793,8 +836,10 @@ function stopTicker() {
|
|
|
793
836
|
/** How often supervision is reconciled. Independent of TUI render scheduling. */
|
|
794
837
|
const HEALTH_TICK_MS = 15_000;
|
|
795
838
|
let healthTicker;
|
|
839
|
+
let managedHealthClose;
|
|
796
840
|
/** ExtensionAPI retained so health transitions can deliver coordinator follow-ups (#65). */
|
|
797
841
|
let healthPi;
|
|
842
|
+
let recoverWorkerWaitsAfterExit;
|
|
798
843
|
/**
|
|
799
844
|
* Deliver a durable, deduped coordinator follow-up for orphaned/lost (#65).
|
|
800
845
|
*
|
|
@@ -837,11 +882,11 @@ function deliverHealthCallback(pi, meta, status, now) {
|
|
|
837
882
|
return;
|
|
838
883
|
}
|
|
839
884
|
// The marker acknowledges quiet delivery, never a model turn.
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
885
|
+
writeMeta(meta, { patch: current => {
|
|
886
|
+
if (current.status !== status || isHealthCallbackHandled(current, status) || callbackSuppressionReason(current))
|
|
887
|
+
return;
|
|
888
|
+
return status === "orphaned" ? { orphanedCallbackSentAt: now } : { lostCallbackSentAt: now };
|
|
889
|
+
} });
|
|
845
890
|
return;
|
|
846
891
|
}
|
|
847
892
|
void getCallbackBatcher(pi).deliverUrgent({
|
|
@@ -867,11 +912,11 @@ function deliverHealthCallback(pi, meta, status, now) {
|
|
|
867
912
|
if (attention.incidents.some((incident) => pendingFailureAttention(collectRunFailures(meta.id, meta.cwd), at, { terminal: true })?.incidents.includes(incident)))
|
|
868
913
|
return;
|
|
869
914
|
}
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
915
|
+
writeMeta(current, { patch: current => {
|
|
916
|
+
if (isHealthCallbackHandled(current, status))
|
|
917
|
+
return;
|
|
918
|
+
return status === "orphaned" ? { orphanedCallbackSentAt: at } : { lostCallbackSentAt: at };
|
|
919
|
+
} });
|
|
875
920
|
},
|
|
876
921
|
onSuppressed: (reason, at) => {
|
|
877
922
|
const current = readMeta(meta.id);
|
|
@@ -1214,7 +1259,7 @@ function enforceTiming(pi, meta, now) {
|
|
|
1214
1259
|
return false;
|
|
1215
1260
|
}
|
|
1216
1261
|
/** One reconciliation + durable health-callback recovery pass. */
|
|
1217
|
-
function reconcileHealth() {
|
|
1262
|
+
function reconcileHealth(ids) {
|
|
1218
1263
|
if (!managementPort)
|
|
1219
1264
|
return;
|
|
1220
1265
|
try {
|
|
@@ -1226,7 +1271,8 @@ function reconcileHealth() {
|
|
|
1226
1271
|
}
|
|
1227
1272
|
const ctx = uiCtx;
|
|
1228
1273
|
const pi = healthPi;
|
|
1229
|
-
|
|
1274
|
+
const selected = ids ? ids.map(id => readMeta(id)).filter((meta) => Boolean(meta)) : supervisedMetas();
|
|
1275
|
+
for (const summary of selected) {
|
|
1230
1276
|
if (!ownedByThisParent(summary))
|
|
1231
1277
|
continue;
|
|
1232
1278
|
// running/orphaned: process reconcile. lost: durable callback recovery only.
|
|
@@ -1248,10 +1294,25 @@ function reconcileHealth() {
|
|
|
1248
1294
|
// Interrupted work whose child already exited is finalized from its own
|
|
1249
1295
|
// coherent log before any other verdict (and before timing can mislabel
|
|
1250
1296
|
// an already-finished run as stopped) (#625).
|
|
1297
|
+
let interruptedReconciliation;
|
|
1251
1298
|
if (meta.status === "running" || meta.status === "orphaned") {
|
|
1252
1299
|
try {
|
|
1253
|
-
if (
|
|
1254
|
-
|
|
1300
|
+
if (pi && !directlySupervisedRunIds.has(meta.id) && meta.supervisionInterruptedAt !== undefined) {
|
|
1301
|
+
const observed = reconcileInterruptedRun(meta, realProcessProbe, now, {
|
|
1302
|
+
renderWidget,
|
|
1303
|
+
notify: (message, level) => { try {
|
|
1304
|
+
ctx?.ui.notify(message, level);
|
|
1305
|
+
}
|
|
1306
|
+
catch { /* unavailable UI */ } },
|
|
1307
|
+
sendMessage: () => enqueueCompletionCallback(pi, meta.id),
|
|
1308
|
+
});
|
|
1309
|
+
if (observed.finalization?.applied) {
|
|
1310
|
+
void recoverWorkerWaitsAfterExit?.().catch(() => undefined);
|
|
1311
|
+
syncHealthTicker();
|
|
1312
|
+
continue;
|
|
1313
|
+
}
|
|
1314
|
+
interruptedReconciliation = observed.reconciliation;
|
|
1315
|
+
}
|
|
1255
1316
|
}
|
|
1256
1317
|
catch { /* best-effort; the ordinary reconciliation below still runs */ }
|
|
1257
1318
|
}
|
|
@@ -1261,7 +1322,7 @@ function reconcileHealth() {
|
|
|
1261
1322
|
}
|
|
1262
1323
|
catch { /* timing is best-effort per tick; supervision below still runs */ }
|
|
1263
1324
|
if (meta.status === "running" || meta.status === "orphaned") {
|
|
1264
|
-
const result = reconcileRun(meta, realProcessProbe, now);
|
|
1325
|
+
const result = interruptedReconciliation ?? reconcileRun(meta, realProcessProbe, now);
|
|
1265
1326
|
if (result.changed) {
|
|
1266
1327
|
Object.assign(meta, result.patch, { status: result.status });
|
|
1267
1328
|
writeMeta(meta);
|
|
@@ -1307,7 +1368,7 @@ function reconcileHealth() {
|
|
|
1307
1368
|
// is the human's own interrupted work, not another session's live run, and
|
|
1308
1369
|
// `finalizeInterruptedRunFromLog` still requires all process evidence to be
|
|
1309
1370
|
// absent, so a live writer is never touched.
|
|
1310
|
-
for (const summary of listMetas({ includeArchived: false })) {
|
|
1371
|
+
for (const summary of ids ? selected : listMetas({ includeArchived: false })) {
|
|
1311
1372
|
if (summary.status !== "running" && summary.status !== "orphaned")
|
|
1312
1373
|
continue;
|
|
1313
1374
|
if (ownedByThisParent(summary) || !ownsInterruptedSupervision(summary))
|
|
@@ -1321,7 +1382,7 @@ function reconcileHealth() {
|
|
|
1321
1382
|
catch { /* the next tick retries */ }
|
|
1322
1383
|
}
|
|
1323
1384
|
// Completed runs can still have failed completion handoffs to retry.
|
|
1324
|
-
for (const summary of
|
|
1385
|
+
for (const summary of selected) {
|
|
1325
1386
|
if (!pi || !ownedByThisParent(summary) || summary.status === "running" || summary.status === "orphaned" || summary.status === "lost")
|
|
1326
1387
|
continue;
|
|
1327
1388
|
const meta = readMeta(summary.id);
|
|
@@ -1423,6 +1484,10 @@ function syncHealthTicker() {
|
|
|
1423
1484
|
stopHealthTicker();
|
|
1424
1485
|
return;
|
|
1425
1486
|
}
|
|
1487
|
+
if (managementPort.observeHealth) {
|
|
1488
|
+
ensureHealthTicker();
|
|
1489
|
+
return;
|
|
1490
|
+
}
|
|
1426
1491
|
if (needsMonitoring(supervisedMetas()) || needsInterruptedSupervision())
|
|
1427
1492
|
ensureHealthTicker();
|
|
1428
1493
|
else
|
|
@@ -1432,6 +1497,10 @@ function syncHealthTicker() {
|
|
|
1432
1497
|
function ensureHealthTicker() {
|
|
1433
1498
|
if (!managementPort)
|
|
1434
1499
|
return;
|
|
1500
|
+
if (managementPort.observeHealth) {
|
|
1501
|
+
managedHealthClose ??= managementPort.observeHealth(ids => reconcileHealth(ids));
|
|
1502
|
+
return;
|
|
1503
|
+
}
|
|
1435
1504
|
// Not gated on `sessionTornDown`: a spawn always means the current session is
|
|
1436
1505
|
// doing new work. Only `syncHealthTicker` — the path a late child finalizer
|
|
1437
1506
|
// takes — stays closed in a replaced instance.
|
|
@@ -1441,6 +1510,8 @@ function ensureHealthTicker() {
|
|
|
1441
1510
|
healthTicker.unref?.(); // never keep the process alive on our account
|
|
1442
1511
|
}
|
|
1443
1512
|
function stopHealthTicker() {
|
|
1513
|
+
managedHealthClose?.();
|
|
1514
|
+
managedHealthClose = undefined;
|
|
1444
1515
|
if (healthTicker) {
|
|
1445
1516
|
clearInterval(healthTicker);
|
|
1446
1517
|
healthTicker = undefined;
|
|
@@ -1448,7 +1519,7 @@ function stopHealthTicker() {
|
|
|
1448
1519
|
}
|
|
1449
1520
|
/** Test/diagnostic seam: whether the periodic reconciliation loop is active. */
|
|
1450
1521
|
export function isHealthTickerActive() {
|
|
1451
|
-
return healthTicker !== undefined;
|
|
1522
|
+
return healthTicker !== undefined || managedHealthClose !== undefined;
|
|
1452
1523
|
}
|
|
1453
1524
|
/**
|
|
1454
1525
|
* Spawn-time identity probe. Production uses the OS-backed probe; extension-
|
|
@@ -1509,7 +1580,7 @@ const pendingNavigatorDismissals = new Set();
|
|
|
1509
1580
|
function navigatorRunningCount() {
|
|
1510
1581
|
const snapshot = workObservation();
|
|
1511
1582
|
return (snapshot?.rows.filter((row) => !pendingNavigatorDismissals.has(row.meta.id) && !row.meta.dismissedAt && ["running", "waiting"].includes(row.assignment.state)).length ?? 0) +
|
|
1512
|
-
(
|
|
1583
|
+
(workObservationStarted() && snapshot?.status !== "ready" ? 1 : 0);
|
|
1513
1584
|
}
|
|
1514
1585
|
/**
|
|
1515
1586
|
* The visible run set. The durable origin index limits reads to this session;
|
|
@@ -1616,22 +1687,20 @@ function subagentWorkRows(now) {
|
|
|
1616
1687
|
if (!undismissed.has(id))
|
|
1617
1688
|
pendingNavigatorDismissals.delete(id);
|
|
1618
1689
|
}
|
|
1619
|
-
const rows = sourceRows.filter((row) => !pendingNavigatorDismissals.has(row.meta.id) && !row.meta.dismissedAt
|
|
1620
|
-
(["running", "waiting"].includes(row.assignment.state) || typeof (row.meta.endedAt ?? row.meta.lostAt) !== "number" ||
|
|
1621
|
-
now - (row.meta.endedAt ?? row.meta.lostAt) < TERMINAL_NAVIGATOR_RETENTION_MS)).map((row) => {
|
|
1690
|
+
const rows = sourceRows.filter((row) => !pendingNavigatorDismissals.has(row.meta.id) && !row.meta.dismissedAt).map((row) => {
|
|
1622
1691
|
const meta = row.meta;
|
|
1623
1692
|
const health = row.health ? observeRunHealth({ ...row.health, status: row.assignment.processStatus === "exited" ? meta.status : row.assignment.processStatus, now, startedAt: meta.startedAt }) : undefined;
|
|
1624
1693
|
const terminal = !["running", "waiting"].includes(row.assignment.state);
|
|
1625
|
-
return { providerId: "subagents", id: meta.id, name: meta.name || meta.id,
|
|
1694
|
+
return { providerId: "subagents", id: meta.id, agentId: meta.sessionId ?? meta.id, name: meta.name || meta.id,
|
|
1626
1695
|
model: shortModel(meta.model), effort: meta.effort, status: row.assignment.state,
|
|
1627
1696
|
tool: row.display?.tool, tokens: row.display?.spend,
|
|
1628
1697
|
statusTone: statusTone(row.assignment.state), kind: "subagent", elapsed: fmtElapsed((meta.endedAt ?? now) - meta.startedAt),
|
|
1629
1698
|
primary: [shortModel(meta.model), meta.effort, row.display?.tool, row.display?.spend].filter(Boolean).join(" ") || "subagent run", facts: formatNavigatorHealthFacts(health), sortStartedAt: meta.startedAt,
|
|
1630
1699
|
expiresAt: terminal && typeof meta.endedAt === "number" ? meta.endedAt + TERMINAL_NAVIGATOR_RETENTION_MS : undefined };
|
|
1631
1700
|
});
|
|
1632
|
-
if (
|
|
1633
|
-
rows.unshift({ providerId: "subagents", id: "runtime-observation", name: "
|
|
1634
|
-
status: snapshot?.status ?? "degraded", statusTone: "warning", kind: "observation", elapsed: "", primary:
|
|
1701
|
+
if (workObservationStarted() && snapshot?.status !== "ready")
|
|
1702
|
+
rows.unshift({ providerId: "subagents", id: "runtime-observation", name: "Status sync",
|
|
1703
|
+
status: snapshot?.status ?? "degraded", statusTone: "warning", kind: "observation", readOnly: true, elapsed: "", primary: "Task status unconfirmed · enter for details", sortStartedAt: now });
|
|
1635
1704
|
return rows;
|
|
1636
1705
|
}
|
|
1637
1706
|
const DELEGATION_BLURB = {
|
|
@@ -1714,6 +1783,14 @@ function mainAgentWorkDetail(now) {
|
|
|
1714
1783
|
function subagentWorkDetail(id, now, options) {
|
|
1715
1784
|
if (id === "main")
|
|
1716
1785
|
return mainAgentWorkDetail(now);
|
|
1786
|
+
if (id === "runtime-observation")
|
|
1787
|
+
return {
|
|
1788
|
+
providerId: "subagents", id, title: "Subagent status sync", status: workObservation()?.status ?? "rebuilding", statusTone: "warning",
|
|
1789
|
+
subtitle: "Shared status service · task status unconfirmed",
|
|
1790
|
+
metadata: [{ label: "scope", value: "Subagent status reads; not an individual task" }],
|
|
1791
|
+
evidence: { label: "Full diagnostic", text: workObservationFailure() },
|
|
1792
|
+
footerActions: [],
|
|
1793
|
+
};
|
|
1717
1794
|
const row = requestWorkDetail(id);
|
|
1718
1795
|
if (!row?.detail)
|
|
1719
1796
|
return { providerId: "subagents", id, title: id, status: row?.observationError ? "degraded" : "rebuilding", statusTone: "warning", metadata: [], evidence: { label: "observation", text: row?.observationError ?? workObservationFailure() } };
|
|
@@ -1814,8 +1891,10 @@ function ensureSubagentProvider() {
|
|
|
1814
1891
|
id: "subagents",
|
|
1815
1892
|
label: "Subagents",
|
|
1816
1893
|
priority: 10,
|
|
1894
|
+
onOpen: () => { void activateWorkObservation(); },
|
|
1817
1895
|
visibleCount: () => navigatorRunningCount(),
|
|
1818
|
-
|
|
1896
|
+
// The last worker becoming terminal must not hide its retained result.
|
|
1897
|
+
showSection: (rows) => rows.length > 0,
|
|
1819
1898
|
parentRow: (now) => mainAgentWorkRow(now),
|
|
1820
1899
|
listRows: (now) => subagentWorkRows(now),
|
|
1821
1900
|
detail: (id, now, options) => subagentWorkDetail(id, now, options),
|
|
@@ -1833,6 +1912,8 @@ function ensureSubagentProvider() {
|
|
|
1833
1912
|
},
|
|
1834
1913
|
armCloseLabel: (row) => pendingNavigatorPark(workObservation()?.rows.find((observed) => observed.meta.id === row.id)?.meta) ? "x again to cancel resume" : row.status === "running" || row.status === "orphaned" ? "x again to stop" : "x again to dismiss",
|
|
1835
1914
|
close: (id) => {
|
|
1915
|
+
if (id === "runtime-observation")
|
|
1916
|
+
return { action: "not-closable", providerId: "subagents", id };
|
|
1836
1917
|
const outcome = navigatorCloseRun(id);
|
|
1837
1918
|
return { ...outcome, providerId: "subagents" };
|
|
1838
1919
|
},
|
|
@@ -1957,13 +2038,14 @@ function resolvePiBinary() {
|
|
|
1957
2038
|
* first-party finalizer (finalization.ts) so tests can exercise the durable
|
|
1958
2039
|
* path without importing the pi package.
|
|
1959
2040
|
*/
|
|
1960
|
-
function finalizeRun(pi, ctx, id, code) {
|
|
2041
|
+
function finalizeRun(pi, ctx, id, code, recoveredWriterExit = false) {
|
|
1961
2042
|
progressCache.delete(id);
|
|
1962
2043
|
directlySupervisedRunIds.delete(id);
|
|
1963
2044
|
// Host-facing wrapper around first-party finalizer (finalization.ts).
|
|
1964
2045
|
// Coherent child-exit evidence may supersede provisional orphaned/lost
|
|
1965
2046
|
// reconciliation; finalization.ts enforces canExitFinalize + lifecycle authority.
|
|
1966
|
-
finalizeRunCore(id, code, {
|
|
2047
|
+
const result = finalizeRunCore(id, code, {
|
|
2048
|
+
recoveredWriterExit,
|
|
1967
2049
|
renderWidget,
|
|
1968
2050
|
notify: (message, level) => {
|
|
1969
2051
|
try {
|
|
@@ -1973,6 +2055,11 @@ function finalizeRun(pi, ctx, id, code) {
|
|
|
1973
2055
|
},
|
|
1974
2056
|
sendMessage: () => enqueueCompletionCallback(pi, id),
|
|
1975
2057
|
});
|
|
2058
|
+
if (recoveredWriterExit && result.applied) {
|
|
2059
|
+
// The old exit callback is gone. Finish its durable wait handoff after
|
|
2060
|
+
// recovery, including the independent writer and lease proof checks.
|
|
2061
|
+
void recoverWorkerWaitsAfterExit?.().catch(() => undefined);
|
|
2062
|
+
}
|
|
1976
2063
|
syncHealthTicker();
|
|
1977
2064
|
}
|
|
1978
2065
|
/**
|
|
@@ -2009,7 +2096,7 @@ function finalizeInterruptedRunFromLog(pi, meta, now) {
|
|
|
2009
2096
|
return false;
|
|
2010
2097
|
// Exit code is unknown after the observer is gone; the lifecycle authority
|
|
2011
2098
|
// classifies from the coherent stream instead of inventing one.
|
|
2012
|
-
finalizeRun(pi, uiCtx, meta.id, null);
|
|
2099
|
+
finalizeRun(pi, uiCtx, meta.id, null, true);
|
|
2013
2100
|
return true;
|
|
2014
2101
|
}
|
|
2015
2102
|
/**
|
|
@@ -2088,7 +2175,8 @@ function revalidateContinuationUnderLease(plan, origin) {
|
|
|
2088
2175
|
id: plan.prior.id,
|
|
2089
2176
|
prior: current,
|
|
2090
2177
|
origin,
|
|
2091
|
-
|
|
2178
|
+
// Archived attempts are completed and cannot be competing writers.
|
|
2179
|
+
others: listMetas({ includeArchived: false }),
|
|
2092
2180
|
});
|
|
2093
2181
|
if (fresh.conversation.sessionId !== plan.conversation.sessionId || fresh.conversation.path !== plan.conversation.path) {
|
|
2094
2182
|
throw new ContinuationError(`Cannot continue ${plan.prior.id}: the saved conversation it would reopen changed while this launch was being prepared ` +
|
|
@@ -2225,15 +2313,17 @@ function latestConversationAttempt(sessionId, metas) {
|
|
|
2225
2313
|
* missing session is the only error added here. Nothing is ever recreated.
|
|
2226
2314
|
*/
|
|
2227
2315
|
function requestedSessionId(job, cwd) {
|
|
2228
|
-
|
|
2316
|
+
const sessionId = normalizeSessionSelector(job.session_id);
|
|
2317
|
+
const sessionName = normalizeSessionSelector(job.session_name);
|
|
2318
|
+
if (sessionId !== undefined && sessionName !== undefined) {
|
|
2229
2319
|
throw new Error("Pass either session_id or session_name, not both.");
|
|
2230
2320
|
}
|
|
2231
|
-
if (
|
|
2232
|
-
if (typeof
|
|
2321
|
+
if (sessionName !== undefined) {
|
|
2322
|
+
if (typeof sessionName !== "string")
|
|
2233
2323
|
throw new Error("session_name must be a non-empty name.");
|
|
2234
|
-
return selectSessionByName(listMetas(),
|
|
2324
|
+
return selectSessionByName(listMetas(), sessionName, (workspace) => isWithinWorkspace(workspace, cwd));
|
|
2235
2325
|
}
|
|
2236
|
-
return
|
|
2326
|
+
return sessionId;
|
|
2237
2327
|
}
|
|
2238
2328
|
function continuationPlanFor(sessionId, origin) {
|
|
2239
2329
|
const others = listMetas();
|
|
@@ -2300,6 +2390,12 @@ export default function (pi, managed) {
|
|
|
2300
2390
|
let catalogModelRegistry;
|
|
2301
2391
|
let delegationOverride;
|
|
2302
2392
|
let capOverride;
|
|
2393
|
+
let workspaceOverride;
|
|
2394
|
+
const activeWorkspace = () => workspaceOverride ?? (loadConfig().gitWorkspace === "worktree" ? "worktree" : "clone");
|
|
2395
|
+
const changeWorkspace = (mode) => {
|
|
2396
|
+
workspaceOverride = mode;
|
|
2397
|
+
pi.appendEntry("pi-better-subagents-workspace", { version: 1, mode });
|
|
2398
|
+
};
|
|
2303
2399
|
let timingOverride = {};
|
|
2304
2400
|
let skillsOverride;
|
|
2305
2401
|
const savedSkills = () => {
|
|
@@ -2419,7 +2515,9 @@ export default function (pi, managed) {
|
|
|
2419
2515
|
capOverride = undefined;
|
|
2420
2516
|
delegationOverride = undefined;
|
|
2421
2517
|
timingOverride = {};
|
|
2518
|
+
workspaceOverride = undefined;
|
|
2422
2519
|
skillsOverride = undefined;
|
|
2520
|
+
pi.appendEntry("pi-better-subagents-workspace", { version: 1, mode: null });
|
|
2423
2521
|
pi.appendEntry("pi-better-subagents-cap", { version: 1, maxConcurrent: null });
|
|
2424
2522
|
pi.appendEntry("pi-better-subagents-delegation", { version: 1, mode: null });
|
|
2425
2523
|
pi.appendEntry("pi-better-subagents-timing", { version: 1, maxMinutes: null, toolWaitMinutes: null, stuckMinutes: null });
|
|
@@ -2523,6 +2621,7 @@ export default function (pi, managed) {
|
|
|
2523
2621
|
savedTiming.stuckMinutes = cfg.stuckMinutes;
|
|
2524
2622
|
}
|
|
2525
2623
|
writeSubagentSettings({
|
|
2624
|
+
...(workspaceOverride ? { gitWorkspace: workspaceOverride } : {}),
|
|
2526
2625
|
delegationMode: activeDelegationMode(),
|
|
2527
2626
|
maxConcurrent: activeConcurrencyCap(),
|
|
2528
2627
|
...savedTiming,
|
|
@@ -2566,6 +2665,7 @@ export default function (pi, managed) {
|
|
|
2566
2665
|
delegationOverride = undefined;
|
|
2567
2666
|
capOverride = undefined;
|
|
2568
2667
|
timingOverride = {};
|
|
2668
|
+
workspaceOverride = undefined;
|
|
2569
2669
|
skillsOverride = undefined;
|
|
2570
2670
|
const branch = ctx.sessionManager?.getBranch?.();
|
|
2571
2671
|
if (!Array.isArray(branch))
|
|
@@ -2608,6 +2708,12 @@ export default function (pi, managed) {
|
|
|
2608
2708
|
}
|
|
2609
2709
|
continue;
|
|
2610
2710
|
}
|
|
2711
|
+
if (entry.type === "custom" && entry.customType === "pi-better-subagents-workspace") {
|
|
2712
|
+
const data = entry.data;
|
|
2713
|
+
if (data?.version === 1 && (data.mode === "worktree" || data.mode === "clone" || data.mode === null)) {
|
|
2714
|
+
workspaceOverride = data.mode ?? undefined;
|
|
2715
|
+
}
|
|
2716
|
+
}
|
|
2611
2717
|
if (entry.type === "custom" && entry.customType === "pi-better-subagents-timing") {
|
|
2612
2718
|
const data = entry.data;
|
|
2613
2719
|
if (data?.version !== 1)
|
|
@@ -2640,6 +2746,7 @@ export default function (pi, managed) {
|
|
|
2640
2746
|
// Capture for the health ticker (module-level); needed for orphaned/lost
|
|
2641
2747
|
// coordinator follow-ups that fire outside a tool-call stack (#65).
|
|
2642
2748
|
healthPi = pi;
|
|
2749
|
+
recoverWorkerWaitsAfterExit = reconcileWorkerWaits;
|
|
2643
2750
|
ensureSubagentProvider();
|
|
2644
2751
|
registerSubagentsGoalProvider(pi);
|
|
2645
2752
|
observeSandboxPermissions(pi);
|
|
@@ -2649,13 +2756,16 @@ export default function (pi, managed) {
|
|
|
2649
2756
|
const registerSpawnTool = (definition) => {
|
|
2650
2757
|
registeredSpawnSchemas.set(definition.name, definition.parameters);
|
|
2651
2758
|
pi.registerTool(managed ? { ...definition, async execute(key, params, signal, onUpdate, ctx) {
|
|
2759
|
+
ctx = captureLaunchContext(ctx);
|
|
2652
2760
|
restoreDelegationMode(ctx);
|
|
2653
2761
|
await workerOperations.start();
|
|
2654
2762
|
return definition.execute(key, params, signal, onUpdate, ctx);
|
|
2655
|
-
} } : { ...definition, async execute(key, params,
|
|
2763
|
+
} } : { ...definition, async execute(key, params, signal, _onUpdate, ctx) {
|
|
2764
|
+
ctx = captureLaunchContext(ctx);
|
|
2656
2765
|
catalogHostFrom(ctx);
|
|
2657
2766
|
const { submitManagedLaunch } = await import("./managed-launch-client.domain.mjs");
|
|
2658
|
-
|
|
2767
|
+
void activateWorkObservation();
|
|
2768
|
+
return await observeNavigatorLaunch(ctx, "subagents", key, "Subagent launch", () => submitManagedLaunch(pi, ctx, key, definition.name, params, signal));
|
|
2659
2769
|
} });
|
|
2660
2770
|
};
|
|
2661
2771
|
announceExecutionAdapter(pi, {
|
|
@@ -2751,6 +2861,10 @@ export default function (pi, managed) {
|
|
|
2751
2861
|
* this call, and a manual continuation passes neither.
|
|
2752
2862
|
*/
|
|
2753
2863
|
internal) {
|
|
2864
|
+
const { resolveChildClosure, resolveChildLaunch, configSnapshot } = await import("./child-dependencies.mjs");
|
|
2865
|
+
const { resolveSubagentWorkspace, inspectGitWorkspace } = await import("./git-workspace.domain.mjs");
|
|
2866
|
+
const { workspaceChoice, createIsolatedWorkspace, restoreWorkspace, discardWorkspace, markWorkspaceWriter } = await import("./isolated-workspace.domain.mjs");
|
|
2867
|
+
const { PREFLIGHT_ENV } = await import("./child-preflight.mjs");
|
|
2754
2868
|
assertThinkingLevel(p.thinking);
|
|
2755
2869
|
// Skill exposure is a caller choice, not a launch: validate its shape
|
|
2756
2870
|
// before any attempt directory or capacity effect exists. A continuation
|
|
@@ -2770,11 +2884,12 @@ export default function (pi, managed) {
|
|
|
2770
2884
|
// frozen confinement intent. Historical metadata can never widen authority,
|
|
2771
2885
|
// and a profile that would change confinement refuses instead of silently
|
|
2772
2886
|
// moving a live conversation into a different sandbox.
|
|
2773
|
-
const permissionPlan = resolveSubagentPermissions(pi, resume
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2887
|
+
const permissionPlan = resolveSubagentPermissions(pi, p.sandbox, resume && { runId: resume.prior.id, sandbox: resume.recipe.sandbox });
|
|
2888
|
+
const processPolicy = describeSubagentProcessPolicy(permissionPlan, process.platform);
|
|
2889
|
+
const processAccess = effectiveWorkerProcessAccess(permissionPlan);
|
|
2890
|
+
const taskPermissions = permissionPlan.inactiveProfile
|
|
2891
|
+
? { ...DEFAULT_TASK_PERMISSIONS, processAccess }
|
|
2892
|
+
: permissionPlan.permissions;
|
|
2778
2893
|
const cfg = loadConfig();
|
|
2779
2894
|
// Harness-owned timing (soft deadline, ceiling, tool-wait and stuck windows); validated before any side effect.
|
|
2780
2895
|
resolveRunTiming({ params: launchTimingParams(p), settings: timingSettingsFor(cfg), env: process.env, startedAt: 0 });
|
|
@@ -2842,7 +2957,36 @@ export default function (pi, managed) {
|
|
|
2842
2957
|
// The disposable clone this launch owns (removed if the spawn fails); a caller's sandbox_dir is not ours.
|
|
2843
2958
|
// A continuation never prepares another clone: the recipe's workspace already
|
|
2844
2959
|
// holds the prior attempt's uncommitted work.
|
|
2845
|
-
|
|
2960
|
+
if (p.isolation === false && p.git_clone_workspace)
|
|
2961
|
+
throw new Error("Choose either live checkout or git_clone_workspace.");
|
|
2962
|
+
if (p.recover_in_clone && (!resume || resume.recipe.workspace?.mode !== "worktree" || internal?.resumeWait)) {
|
|
2963
|
+
throw new Error("Clone handoff requires an explicit continuation of a linked worktree.");
|
|
2964
|
+
}
|
|
2965
|
+
if (resume && p.isolation !== undefined && Boolean(resume.recipe.workspace || resume.recipe.gitCloneWorkspace) !== p.isolation) {
|
|
2966
|
+
throw new ContinuationError("Changing isolation would replace the saved workspace.");
|
|
2967
|
+
}
|
|
2968
|
+
const handoffAuthority = p.recover_in_clone ? resume?.recipe.workspaceAuthority : undefined;
|
|
2969
|
+
if (p.recover_in_clone && resume) {
|
|
2970
|
+
const previous = handoffAuthority?.sandbox;
|
|
2971
|
+
const permissions = taskPermissions ?? DEFAULT_TASK_PERMISSIONS;
|
|
2972
|
+
assertAssignmentPermissionScope(handoffAuthority, {
|
|
2973
|
+
mandatoryPermissions: permissionPlan.enforced,
|
|
2974
|
+
sandbox: sandboxEnabled ? {
|
|
2975
|
+
root: resume.recipe.sandboxDir,
|
|
2976
|
+
denyWrite: previous?.denyWrite ?? [],
|
|
2977
|
+
permissions: {
|
|
2978
|
+
...DEFAULT_TASK_PERMISSIONS, ...permissions, ...resolveCommandSettings(permissions),
|
|
2979
|
+
processAccess: permissions.processAccess ?? "off",
|
|
2980
|
+
},
|
|
2981
|
+
} : null,
|
|
2982
|
+
});
|
|
2983
|
+
}
|
|
2984
|
+
const selected = normalizeTools(p.tools ?? cfg.defaultTools ?? (p.clean ? SAFE_CLEAN_TOOLS : SAFE_DEFAULT_TOOLS));
|
|
2985
|
+
let isolated = resume?.recipe.workspace;
|
|
2986
|
+
if (!resume && !p.sandbox_dir && p.isolation !== false) {
|
|
2987
|
+
isolated = workspaceChoice(p.cwd ?? ctx.cwd, id, p.git_clone_workspace ? "clone" : activeWorkspace(), p.git_clone_workspace ? "write" : selected, p.git_clone_workspace ? "" : p.exclude_tools ?? "");
|
|
2988
|
+
}
|
|
2989
|
+
const ownedCloneWorkspace = !resume && !p.sandbox_dir && (isolated || p.git_clone_workspace) ? taskWorkspaceDir(id) : undefined;
|
|
2846
2990
|
// A launch attempt only becomes a run when `writeMeta` commits. Until
|
|
2847
2991
|
// then everything it creates (prompt, control/, provenance, its own
|
|
2848
2992
|
// session dir, clone workspace, task scratch) belongs to the attempt and
|
|
@@ -2852,6 +2996,7 @@ export default function (pi, managed) {
|
|
|
2852
2996
|
let spawned;
|
|
2853
2997
|
let launchScratch;
|
|
2854
2998
|
let committed = false;
|
|
2999
|
+
let createdWorkspace = false;
|
|
2855
3000
|
try {
|
|
2856
3001
|
if (!resume)
|
|
2857
3002
|
mkdirSync(childSessionDir, { recursive: true });
|
|
@@ -2861,17 +3006,33 @@ export default function (pi, managed) {
|
|
|
2861
3006
|
// concurrent purge can tell this live attempt from dead launch debris
|
|
2862
3007
|
// (#623 R1). The outer catch drops the whole directory on failure.
|
|
2863
3008
|
recordLaunchAttempt(id);
|
|
3009
|
+
// Cleanup, restoration and the actual writer share the conversation lease.
|
|
3010
|
+
if (resume || managed)
|
|
3011
|
+
lease = acquireConversationLease({ sessionId, attemptId: id });
|
|
3012
|
+
if (resume) {
|
|
3013
|
+
revalidateContinuationUnderLease(resume, callbackOrigin);
|
|
3014
|
+
if (isolated)
|
|
3015
|
+
isolated = restoreWorkspace(isolated, p.recover_in_clone, resume.prior.id);
|
|
3016
|
+
}
|
|
3017
|
+
if (!resume && isolated) {
|
|
3018
|
+
const root = taskWorkspaceDir(id);
|
|
3019
|
+
mkdirSync(dirname(root), { recursive: true });
|
|
3020
|
+
mkdirSync(root, { mode: 0o700 });
|
|
3021
|
+
createdWorkspace = true;
|
|
3022
|
+
}
|
|
3023
|
+
const isolatedCwd = isolated && !resume && !p.git_clone_workspace ? createIsolatedWorkspace(isolated, true) : undefined;
|
|
2864
3024
|
const workspace = resume
|
|
2865
3025
|
? { cwd: resume.recipe.cwd, requestedSandboxDir: resume.recipe.sandboxDir }
|
|
2866
|
-
:
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
3026
|
+
: isolatedCwd ? { cwd: isolatedCwd, requestedSandboxDir: sandboxEnabled ? isolatedCwd : undefined }
|
|
3027
|
+
: resolveSubagentWorkspace({
|
|
3028
|
+
ctxCwd: ctx.cwd, cwd: p.cwd, sandboxDir: p.sandbox_dir ?? ownedCloneWorkspace,
|
|
3029
|
+
gitCloneWorkspace: p.git_clone_workspace, runId: id, runDirPath: runDir(id), sandboxEnabled,
|
|
3030
|
+
});
|
|
3031
|
+
// Legacy explicit clones launch at the repository root, even when the source is a subdirectory.
|
|
3032
|
+
if (!resume && isolated && p.git_clone_workspace)
|
|
3033
|
+
isolated = { ...isolated, subdir: "" };
|
|
3034
|
+
let workspaceNote = isolated ? `Git workspace: ${isolated.mode} at ${workspace.cwd}. Base ${isolated.base}.`
|
|
3035
|
+
+ (isolated.mode === "worktree" && sandboxEnabled ? " Git metadata is shared outside this checkout. If the sandbox denies a Git operation, report the operation and current changes. The parent can review them here or continue this session with recover_in_clone:true." : "") : "";
|
|
2875
3036
|
const cwd = workspace.cwd;
|
|
2876
3037
|
const requestedSandboxDir = workspace.requestedSandboxDir;
|
|
2877
3038
|
// Skill exposure is decided once per attempt. A continuation replays the
|
|
@@ -2897,7 +3058,8 @@ export default function (pi, managed) {
|
|
|
2897
3058
|
});
|
|
2898
3059
|
if (requestedSandboxDir)
|
|
2899
3060
|
mkdirSync(requestedSandboxDir, { recursive: true });
|
|
2900
|
-
|
|
3061
|
+
const workerPrompt = workspaceNote ? workspaceNote + "\n\n" + p.prompt : p.prompt;
|
|
3062
|
+
writeFileSync(promptPathFor(id), workerPrompt);
|
|
2901
3063
|
// A continuation keeps the recipe's launch intent; only current
|
|
2902
3064
|
// permission-driven adjustments are re-derived from it.
|
|
2903
3065
|
const requestedTools = resume ? callerLaunchTools(resume.recipe.tools) : p.tools;
|
|
@@ -2905,7 +3067,7 @@ export default function (pi, managed) {
|
|
|
2905
3067
|
const clean = resume ? resume.recipe.clean : p.clean === true;
|
|
2906
3068
|
const allowNested = resume ? resume.recipe.allowNested : p.allow_nested === true;
|
|
2907
3069
|
const approve = resume ? resume.recipe.approve : p.approve === true;
|
|
2908
|
-
const gitCloneWorkspace = resume ? resume.recipe.gitCloneWorkspace : p.git_clone_workspace === true;
|
|
3070
|
+
const gitCloneWorkspace = isolated ? isolated.mode === "clone" : resume ? resume.recipe.gitCloneWorkspace : p.git_clone_workspace === true;
|
|
2909
3071
|
const callbackEnabled = resume ? p.callback ?? resume.recipe.callback : p.callback !== false;
|
|
2910
3072
|
const launchName = resume ? resume.recipe.name : p.name;
|
|
2911
3073
|
// The frozen launch snapshot is the same shape a fresh spawn freezes.
|
|
@@ -2918,8 +3080,7 @@ export default function (pi, managed) {
|
|
|
2918
3080
|
allow = [...allow.split(","), ...SUBAGENT_TOOLS.filter((t) => !have.has(t))]
|
|
2919
3081
|
.filter(Boolean).join(",");
|
|
2920
3082
|
}
|
|
2921
|
-
//
|
|
2922
|
-
// the guarded apply_patch adapter, and trusted tools admitted by name and package.
|
|
3083
|
+
// Exclusions apply to the worker selection before provider admission (ADR 0027).
|
|
2923
3084
|
const requestedExcludes = new Set(requestedExcludeTools.split(",").map((t) => t.trim()).filter(Boolean));
|
|
2924
3085
|
// Supervised worker operations. This only decides which names the
|
|
2925
3086
|
// child's loadout carries: clean children, explicit tool lists,
|
|
@@ -2961,20 +3122,19 @@ export default function (pi, managed) {
|
|
|
2961
3122
|
bridgePlan.capabilities = { ...bridgePlan.capabilities, reportAssignment: true };
|
|
2962
3123
|
productionBridgeSchemas.schemas.set("report_assignment_result", createToolDescriptor("report_assignment_result"));
|
|
2963
3124
|
}
|
|
3125
|
+
assertWaitToolDependencies(bridgePlan.capabilities, bridgePlan.tools);
|
|
2964
3126
|
const bridgeEnabled = bridgePlan.tools.length > 0;
|
|
2965
3127
|
if (bridgeEnabled) {
|
|
2966
3128
|
allow = [...new Set([...allow.split(",").filter(Boolean), ...bridgePlan.tools])].join(",");
|
|
2967
3129
|
}
|
|
2968
|
-
if (
|
|
3130
|
+
if (!clean) {
|
|
2969
3131
|
const names = allow.split(",").filter(Boolean);
|
|
2970
|
-
//
|
|
2971
|
-
if (
|
|
2972
|
-
names
|
|
2973
|
-
if (requestedTools === undefined)
|
|
2974
|
-
names.push(...permissionPlan.tools.trusted.map((entry) => entry.name));
|
|
3132
|
+
// Derive the editable loadout before applying the resource policy.
|
|
3133
|
+
if (!resume)
|
|
3134
|
+
addEditablePatch(names, requestedExcludes);
|
|
2975
3135
|
allow = [...new Set(names)].join(",");
|
|
2976
3136
|
}
|
|
2977
|
-
if (sandboxEnabled && requestedTools === undefined &&
|
|
3137
|
+
if (sandboxEnabled && requestedTools === undefined && processAccess === "read") {
|
|
2978
3138
|
allow = [...new Set([...allow.split(","), "process_list"])].join(",");
|
|
2979
3139
|
}
|
|
2980
3140
|
// Shell Off confines the child to directly launched applications: a requested bash
|
|
@@ -2994,12 +3154,20 @@ export default function (pi, managed) {
|
|
|
2994
3154
|
// Candidates for the task-tool plan: exclusions and bridge-supplied
|
|
2995
3155
|
// names never reach extension admission.
|
|
2996
3156
|
const plannedTools = allow.split(",").filter((name) => name && !requestedExcludes.has(name) && !bridgeToolNames.has(name));
|
|
3157
|
+
const continuationRuntime = selectContinuationRuntime({ currentDir: selfDir(), recipe: resume?.recipe });
|
|
3158
|
+
const workerPath = (path) => continuationRuntime?.mapPath(path) ?? path;
|
|
3159
|
+
const workerArgs = (args) => continuationRuntime?.mapArgs(args) ?? args;
|
|
3160
|
+
const workerResolvePath = (spec) => {
|
|
3161
|
+
const path = resolveExtensionPath(spec);
|
|
3162
|
+
return path ? workerPath(path) : path;
|
|
3163
|
+
};
|
|
3164
|
+
const normalProviders = ordinaryChildConfig(cfg, managed?.activeProviders?.() ?? activeChildProviders(pi));
|
|
2997
3165
|
const taskTools = sandboxEnabled ? planTaskTools({
|
|
2998
3166
|
requested: plannedTools,
|
|
2999
3167
|
settings: permissionPlan.tools, network: permissionPlan.permissions?.network ?? true,
|
|
3000
|
-
processAccess
|
|
3168
|
+
processAccess,
|
|
3001
3169
|
builtins: [...TASK_BUILTINS, "codemode"], registered: pi.getAllTools?.() ?? [],
|
|
3002
|
-
toolExtensions:
|
|
3170
|
+
toolExtensions: normalProviders.toolExtensions, resolvePath: workerResolvePath,
|
|
3003
3171
|
}) : undefined;
|
|
3004
3172
|
// One effective selection feeds the task policy, child preflight, worker
|
|
3005
3173
|
// bridge and frozen recipe, so a refused tool cannot leak into any of them
|
|
@@ -3019,9 +3187,9 @@ export default function (pi, managed) {
|
|
|
3019
3187
|
.map((tool) => `${tool.name} (${withheldBridgeReasons.get(tool.name) ?? tool.reason})`).join(", ");
|
|
3020
3188
|
throw resume
|
|
3021
3189
|
? new ContinuationError(`Cannot continue ${resume.prior.id}: its frozen launch requires tool(s) this parent can no longer provide: ${detail}. ` +
|
|
3022
|
-
`Launch a new run instead of continuing this conversation
|
|
3190
|
+
`Launch a new run instead of continuing this conversation. ${processPolicy}`)
|
|
3023
3191
|
: new Error(`Requested tool(s) are not available in the task sandbox: ${detail}. ` +
|
|
3024
|
-
`
|
|
3192
|
+
`Check the child tool provider and the Subagents resource permissions; nothing was launched.`);
|
|
3025
3193
|
}
|
|
3026
3194
|
if (toolSelection) {
|
|
3027
3195
|
if (plannedTools.length > 0 && toolSelection.tools.length === 0) {
|
|
@@ -3029,53 +3197,66 @@ export default function (pi, managed) {
|
|
|
3029
3197
|
}
|
|
3030
3198
|
allow = toolSelection.tools.join(",");
|
|
3031
3199
|
}
|
|
3200
|
+
// Older recipes were frozen before isolated workers gained Harness providers
|
|
3201
|
+
// and inherited workers began loading mappings explicitly.
|
|
3202
|
+
const legacyToolLoading = resume !== undefined && !resume.recipe.toolLoadingVersion;
|
|
3203
|
+
let extensionConfig = cfg;
|
|
3204
|
+
if (!sandboxEnabled && !legacyToolLoading)
|
|
3205
|
+
extensionConfig = normalProviders;
|
|
3206
|
+
if (legacyToolLoading && cfg.inheritExtensions)
|
|
3207
|
+
extensionConfig = { ...cfg, toolExtensions: {} };
|
|
3032
3208
|
const dependencyOptions = {
|
|
3033
3209
|
model, virtual: (() => {
|
|
3034
3210
|
const slash = model?.indexOf("/") ?? -1;
|
|
3035
3211
|
return slash > 0 && ctx.modelRegistry?.find?.(model.slice(0, slash), model.slice(slash + 1))?.api === "pi-virtual";
|
|
3036
|
-
})(), config:
|
|
3037
|
-
configPaths: [configPath(), join(selfDir(), "config.json")],
|
|
3212
|
+
})(), config: extensionConfig, resolvePath: workerResolvePath,
|
|
3213
|
+
configPaths: [configPath(), workerPath(join(selfDir(), "config.json"))],
|
|
3038
3214
|
};
|
|
3039
3215
|
// Bridge tools are supplied by the worker bridge extension, not by a
|
|
3040
3216
|
// configured toolExtensions mapping: keep them out of extension
|
|
3041
3217
|
// resolution so `unmapped` stays an accurate operator warning and the
|
|
3042
3218
|
// frozen launch recipe never depends on bridge availability.
|
|
3043
|
-
const extensionAllowlist = () => (
|
|
3044
|
-
|
|
3045
|
-
: allow);
|
|
3219
|
+
const extensionAllowlist = () => allow.split(",")
|
|
3220
|
+
.filter(name => !requestedExcludes.has(name) && !bridgeToolNames.has(name)).join(",");
|
|
3046
3221
|
const { resolution, fullResolution } = await resolveChildLaunch({ ...dependencyOptions, resolution: resolveExtensions({
|
|
3047
3222
|
// Only SDK builtins reach `--tools` and extension resolution: process_list and run_application
|
|
3048
3223
|
// are task builtins that the mandatory guard installs and activates itself.
|
|
3049
3224
|
tools: sandboxEnabled ? allow.split(",").filter((name) => SDK_BUILTIN_TOOLS.includes(name)).join(",") : extensionAllowlist(),
|
|
3050
|
-
model, clean, allowNested: sandboxEnabled ? false : allowNested, config:
|
|
3225
|
+
model, clean, allowNested: sandboxEnabled ? false : allowNested, config: extensionConfig,
|
|
3051
3226
|
}) }, taskTools?.trusted.map(tool => tool.loadPath) ?? []);
|
|
3052
|
-
|
|
3227
|
+
if (!sandboxEnabled && resolution.mode === "isolated" &&
|
|
3228
|
+
fullResolution.specs.every((spec) => Object.values(ORDINARY_TOOL_PROVIDERS).includes(spec))) {
|
|
3229
|
+
const missingTools = resolution.unmapped.filter((name) => requiredToolNames.has(name));
|
|
3230
|
+
if (missingTools.length)
|
|
3231
|
+
throw new Error(`No provider for required child tools: ${missingTools.join(", ")}. Configure toolExtensions or change the requested tools.`);
|
|
3232
|
+
}
|
|
3233
|
+
const { args: resolvedExtArgs, missing } = extensionArgs(resolution, (spec) => resolution.paths[spec] ?? workerResolvePath(spec));
|
|
3053
3234
|
const trustedExtArgs = fullResolution.specs.map(spec => fullResolution.paths[spec])
|
|
3054
3235
|
.filter(path => !resolvedExtArgs.includes(path)).flatMap(path => ["--extension", path]);
|
|
3055
3236
|
// Harness child controls ride along in every mode, including clean and unsandboxed runs.
|
|
3056
3237
|
// They deliver deadline steers and keep external monitoring with the coordinator.
|
|
3057
3238
|
const codemodeArgs = !sandboxEnabled && allow.split(",").includes("codemode") && !requestedExcludes.has("codemode")
|
|
3058
3239
|
? ["--extension", join(selfDir(), "child-codemode.ts")] : [];
|
|
3059
|
-
const extArgs = [...resolvedExtArgs, ...trustedExtArgs, ...codemodeArgs,
|
|
3240
|
+
const extArgs = workerArgs([...resolvedExtArgs, ...trustedExtArgs, ...codemodeArgs,
|
|
3060
3241
|
"--extension", childSteerExtensionPath(), "--extension", join(selfDir(), "child-ownership.ts")]
|
|
3061
|
-
.map((value, index, all) => sandboxEnabled && all[index - 1] === "--extension" ? canonicalizePath(value) : value);
|
|
3062
|
-
const baseExtensionArgs = [...resolvedExtArgs, ...codemodeArgs,
|
|
3242
|
+
.map((value, index, all) => sandboxEnabled && all[index - 1] === "--extension" ? canonicalizePath(value) : value));
|
|
3243
|
+
const baseExtensionArgs = workerArgs([...resolvedExtArgs, ...codemodeArgs,
|
|
3063
3244
|
"--extension", childSteerExtensionPath(), "--extension", join(selfDir(), "child-ownership.ts")]
|
|
3064
|
-
.map((value, index, all) => sandboxEnabled && all[index - 1] === "--extension" ? canonicalizePath(value) : value);
|
|
3245
|
+
.map((value, index, all) => sandboxEnabled && all[index - 1] === "--extension" ? canonicalizePath(value) : value));
|
|
3065
3246
|
if (resume?.recipe.extensionArgs) {
|
|
3066
3247
|
// A model escalation may change provider auth, but an unchanged tool
|
|
3067
3248
|
// must not silently switch implementations with current configuration.
|
|
3068
3249
|
const reference = model === resume.recipe.model ? resolution : await resolveChildClosure({
|
|
3069
3250
|
...dependencyOptions, model: resume.recipe.model, virtual: false, resolution: resolveExtensions({
|
|
3070
3251
|
tools: sandboxEnabled ? allow.split(",").filter((name) => SDK_BUILTIN_TOOLS.includes(name)).join(",") : extensionAllowlist(),
|
|
3071
|
-
model: resume.recipe.model, clean, allowNested: sandboxEnabled ? false : allowNested, config:
|
|
3252
|
+
model: resume.recipe.model, clean, allowNested: sandboxEnabled ? false : allowNested, config: extensionConfig,
|
|
3072
3253
|
})
|
|
3073
3254
|
});
|
|
3074
|
-
const referenceArgs = [...extensionArgs(reference, (spec) => reference.paths[spec] ??
|
|
3255
|
+
const referenceArgs = [...extensionArgs(reference, (spec) => reference.paths[spec] ?? workerResolvePath(spec)).args, ...codemodeArgs,
|
|
3075
3256
|
...(!resume.recipe.baseExtensionArgs ? trustedExtArgs : []),
|
|
3076
3257
|
"--extension", childSteerExtensionPath(), "--extension", join(selfDir(), "child-ownership.ts")]
|
|
3077
3258
|
.map((value, index, all) => sandboxEnabled && all[index - 1] === "--extension" ? canonicalizePath(value) : value);
|
|
3078
|
-
assertContinuationExtensions(resume.prior.id, resume.recipe, referenceArgs, taskTools?.trusted ?? []);
|
|
3259
|
+
assertContinuationExtensions(resume.prior.id, resume.recipe, workerArgs(referenceArgs), (taskTools?.trusted ?? []).map(tool => ({ ...tool, loadPath: workerPath(tool.loadPath) })));
|
|
3079
3260
|
}
|
|
3080
3261
|
if (sandboxEnabled && resolution.mode === "inherit") {
|
|
3081
3262
|
throw new Error("Task confinement requires explicit extensions; inheritExtensions is unsupported while sandboxing is enabled.");
|
|
@@ -3104,7 +3285,7 @@ export default function (pi, managed) {
|
|
|
3104
3285
|
// supervision capability, not a tool implementation, so it must not
|
|
3105
3286
|
// invalidate a conversation's saved recipe when it appears later.
|
|
3106
3287
|
const commandExtArgs = bridgeEnabled
|
|
3107
|
-
? [...extArgs, "--extension", childBridgeExtensionPath(selfDir())]
|
|
3288
|
+
? [...extArgs, "--extension", workerPath(childBridgeExtensionPath(selfDir()))]
|
|
3108
3289
|
: extArgs;
|
|
3109
3290
|
const args = [
|
|
3110
3291
|
"-p", "--mode", "json",
|
|
@@ -3116,28 +3297,45 @@ export default function (pi, managed) {
|
|
|
3116
3297
|
...(allow && !sandboxEnabled ? ["--tools", allow] : []),
|
|
3117
3298
|
...(excludes.size ? ["--exclude-tools", [...excludes].join(",")] : []),
|
|
3118
3299
|
...(sandboxEnabled ? ["--no-builtin-tools", "--no-approve"] : approve ? ["--approve"] : []),
|
|
3119
|
-
|
|
3300
|
+
workerPrompt,
|
|
3120
3301
|
];
|
|
3121
3302
|
const selectedTools = allow.split(",").filter((name) => name && !excludes.has(name));
|
|
3303
|
+
const inheritedTrusted = resume ? new Set(resume.recipe.optionalTrustedTools ?? []) : undefined;
|
|
3304
|
+
const optionalTrustedTools = taskTools?.trusted.filter(({ name }) => selectedTools.includes(name)
|
|
3305
|
+
&& (inheritedTrusted ? inheritedTrusted.has(name) : requestedTools === undefined)).map(({ name }) => name) ?? [];
|
|
3122
3306
|
const dropped = toolSelection?.dropped ?? [];
|
|
3123
3307
|
const taskRuntime = sandboxEnabled && requestedSandboxDir ? prepareTaskRuntime({
|
|
3308
|
+
worktreeGitDir: isolated?.mode === "worktree" ? inspectGitWorkspace(cwd).gitDir : undefined,
|
|
3124
3309
|
root: requestedSandboxDir, controlDir: join(runDir(id), "control"),
|
|
3125
3310
|
tools: selectedTools,
|
|
3126
|
-
permissions:
|
|
3311
|
+
permissions: taskPermissions && { ...taskPermissions, ...commandSettings },
|
|
3127
3312
|
applyPatch: taskTools?.applyPatch === true,
|
|
3128
|
-
extensionTools: taskTools?.trusted.map(({ loadPath: _loadPath, ...tool }) => tool) ?? [],
|
|
3313
|
+
extensionTools: taskTools?.trusted.map(({ loadPath: _loadPath, ...tool }) => ({ ...tool, root: workerPath(tool.root) })) ?? [],
|
|
3129
3314
|
// The sandboxed child's policy enables the guarded operation bridge
|
|
3130
3315
|
// only when the fixed bridge adapter path is among its extension
|
|
3131
3316
|
// paths; the task guard then admits those tools by exact source.
|
|
3132
3317
|
extensionPaths: [
|
|
3133
3318
|
...extArgs.flatMap((arg, index) => arg === "--extension" && extArgs[index + 1] ? [extArgs[index + 1]] : []),
|
|
3134
|
-
...(bridgeEnabled ? [childBridgeExtensionPath(selfDir())] : []),
|
|
3319
|
+
...(bridgeEnabled ? [workerPath(childBridgeExtensionPath(selfDir()))] : []),
|
|
3135
3320
|
],
|
|
3321
|
+
operationBridgePath: workerPath(childBridgeExtensionPath(selfDir())),
|
|
3136
3322
|
runtimeRoots: [baseDir()],
|
|
3137
3323
|
capturedDenyWrite: internal?.resumeWait
|
|
3138
3324
|
? resume?.prior.operations?.policy.sandbox?.denyWrite
|
|
3139
|
-
:
|
|
3325
|
+
: handoffAuthority?.sandbox?.denyWrite,
|
|
3140
3326
|
}) : undefined;
|
|
3327
|
+
if (taskRuntime?.policy.worktreeGitDir) {
|
|
3328
|
+
const policy = taskRuntime.policy;
|
|
3329
|
+
const notice = worktreePolicyNotice(policy.worktreeGitDir, compileWritePolicy({
|
|
3330
|
+
writableRoot: policy.root, home: policy.home, permissions: policy.permissions,
|
|
3331
|
+
denyWrite: policy.denyWrite, runtimeCompatibility: true, runtimeWrite: [policy.scratch],
|
|
3332
|
+
}));
|
|
3333
|
+
if (notice) {
|
|
3334
|
+
workspaceNote += " " + notice;
|
|
3335
|
+
args[args.length - 1] = workspaceNote + "\n\n" + p.prompt;
|
|
3336
|
+
writeFileSync(promptPathFor(id), args[args.length - 1]);
|
|
3337
|
+
}
|
|
3338
|
+
}
|
|
3141
3339
|
launchScratch = taskRuntime?.policy.scratch;
|
|
3142
3340
|
if (sandboxEnabled && !taskRuntime)
|
|
3143
3341
|
throw new Error("Task sandbox has no workspace; refusing an unconfined child.");
|
|
@@ -3159,9 +3357,10 @@ export default function (pi, managed) {
|
|
|
3159
3357
|
catch { /* ignore */ }
|
|
3160
3358
|
});
|
|
3161
3359
|
}
|
|
3162
|
-
const
|
|
3360
|
+
const currentCommand = taskRuntime ? { file: taskRuntime.file, fileArgs: [...taskRuntime.fileArgs, ...args] }
|
|
3163
3361
|
: managed ? managed.workerCommand(args)
|
|
3164
3362
|
: { file: process.execPath, fileArgs: [join(selfDir(), "child-runtime.mjs"), resolvePiBinary(), ...args] };
|
|
3363
|
+
const cmd = continuationRuntime?.command(currentCommand) ?? currentCommand;
|
|
3165
3364
|
const sandboxDir = taskRuntime ? requestedSandboxDir : undefined;
|
|
3166
3365
|
// Reservations prevent competing admissions, but do not grandfather
|
|
3167
3366
|
// unstarted work after a cap reduction. No await separates this live
|
|
@@ -3170,22 +3369,12 @@ export default function (pi, managed) {
|
|
|
3170
3369
|
if (countRunning() >= maxConcurrent) {
|
|
3171
3370
|
throw new Error(`Max concurrent subagents (${maxConcurrent}) reached. Stop or let some finish first.`);
|
|
3172
3371
|
}
|
|
3173
|
-
//
|
|
3174
|
-
// and finalization. A live duplicate continuation is refused instead of
|
|
3175
|
-
// letting two processes rewrite one session file. A fresh launch has a
|
|
3176
|
-
// brand-new native session id, so it cannot contend with anyone and
|
|
3177
|
-
// needs no lease; every continuation does.
|
|
3178
|
-
if (resume || managed) {
|
|
3179
|
-
lease = acquireConversationLease({ sessionId, attemptId: id });
|
|
3180
|
-
}
|
|
3181
|
-
// The lease is the first moment no other process can retire this
|
|
3182
|
-
// conversation: re-prove the history identity the cached plan was
|
|
3183
|
-
// built from, so `--session` can never reopen a file another sweep
|
|
3184
|
-
// removed as an empty replacement.
|
|
3372
|
+
// Recheck the saved conversation after asynchronous launch preparation.
|
|
3185
3373
|
if (resume)
|
|
3186
3374
|
revalidateContinuationUnderLease(resume, callbackOrigin);
|
|
3187
3375
|
const preflightPath = join(runDir(id), "child-preflight.json");
|
|
3188
3376
|
writeFileSync(preflightPath, JSON.stringify({ ...fullResolution, model, tools: selectedTools,
|
|
3377
|
+
optionalTrustedTools,
|
|
3189
3378
|
configSnapshot: configSnapshot([dirname(configPath()), join(cwd, ".pi")]),
|
|
3190
3379
|
}));
|
|
3191
3380
|
// Register the worker's bridge run before the child can start, so the
|
|
@@ -3259,23 +3448,29 @@ export default function (pi, managed) {
|
|
|
3259
3448
|
throw new PreSpawnResumeError("This legacy park has no verified assignment outcome recipient; refusing continuation on an unsupported binding.");
|
|
3260
3449
|
if (!assignment && bridgeEnabled)
|
|
3261
3450
|
throw new Error("Durable assignment outcomes require a recorded parent session and transcript capability.");
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3451
|
+
const workspaceAuthority = {
|
|
3452
|
+
mandatoryPermissions: permissionPlan.enforced,
|
|
3453
|
+
sandbox: taskRuntime ? {
|
|
3265
3454
|
root: taskRuntime.policy.root,
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
} : null
|
|
3269
|
-
|
|
3455
|
+
permissions: taskRuntime.policy.permissions,
|
|
3456
|
+
denyWrite: [...taskRuntime.policy.denyWrite],
|
|
3457
|
+
} : null,
|
|
3458
|
+
};
|
|
3459
|
+
if (internal?.resumeWait) {
|
|
3460
|
+
assertAssignmentPermissionScope(resume?.prior.operations?.policy, workspaceAuthority, Boolean(managed));
|
|
3270
3461
|
}
|
|
3271
3462
|
// Freeze the ordinary recipe before the durable external-launch intent.
|
|
3272
3463
|
const recipe = buildLaunchRecipe({
|
|
3464
|
+
...(!legacyToolLoading ? { toolLoadingVersion: 1 } : {}),
|
|
3465
|
+
...(isolated ? { workspace: isolated, workspaceAuthority } : {}),
|
|
3273
3466
|
attemptId: id, sessionId, sessionDir: childSessionDir, cwd, model, effort: thinking,
|
|
3274
3467
|
tools: callerLaunchTools(allow), excludeTools: requestedExcludes.size ? [...requestedExcludes].join(",") : undefined,
|
|
3468
|
+
...(optionalTrustedTools.length ? { optionalTrustedTools } : {}),
|
|
3275
3469
|
skills: skills.mode === "inherit" ? undefined : [...skills.paths], clean, allowNested, approve,
|
|
3276
3470
|
sandbox: sandboxEnabled, sandboxDir: requestedSandboxDir, gitCloneWorkspace, callback: callbackEnabled, name: launchName,
|
|
3277
3471
|
agent: resume ? resume.recipe.agent : p.agent, role: resume ? resume.recipe.role : p.role,
|
|
3278
3472
|
alias: resume ? resume.recipe.alias : p.alias, catalog: launchCatalog, extensionArgs: extArgs, baseExtensionArgs,
|
|
3473
|
+
runtimeRoot: continuationRuntime?.root ?? managedRuntimeRoot(selfDir()),
|
|
3279
3474
|
trustedExtensions: resume?.recipe.trustedExtensions ?? taskTools?.trusted.map(({ name, package: owner, loadPath }) => ({ name, package: owner, loadPath })),
|
|
3280
3475
|
});
|
|
3281
3476
|
const startedAt = Date.now();
|
|
@@ -3331,6 +3526,8 @@ export default function (pi, managed) {
|
|
|
3331
3526
|
timing: resolveRunTiming({ params: launchTimingParams(p), settings: timingSettingsFor(cfg), env: process.env, startedAt }),
|
|
3332
3527
|
};
|
|
3333
3528
|
const dispatchGuard = await internal?.beforeSpawn?.({ runId: id, permissionPlan });
|
|
3529
|
+
if (isolated)
|
|
3530
|
+
markWorkspaceWriter(isolated, id);
|
|
3334
3531
|
const managedEnv = managed?.beforeSpawn({ id, sessionId, lease: lease.token, leasePath: lease.path,
|
|
3335
3532
|
preflightPath, policyPath: taskRuntime?.policyPath, permissions: permissionPlan, recipe, recoveryMeta: meta });
|
|
3336
3533
|
spawned = releaseChild(dispatchGuard, () => spawnDetached({ file: cmd.file, fileArgs: cmd.fileArgs, cwd, logPath: logPathFor(id),
|
|
@@ -3360,33 +3557,30 @@ export default function (pi, managed) {
|
|
|
3360
3557
|
// Register exit supervision before any fallible post-spawn publication.
|
|
3361
3558
|
// A failed metadata write must not strand a running child without a close
|
|
3362
3559
|
// handler; the lease stays held until that child has actually exited.
|
|
3363
|
-
|
|
3364
|
-
try {
|
|
3365
|
-
finalizeRun(pi, ctx, id, code);
|
|
3366
|
-
}
|
|
3367
|
-
finally {
|
|
3368
|
-
lease?.release();
|
|
3369
|
-
}
|
|
3560
|
+
const exitCompletion = completeOwnedExit(spawned.exit, code => finalizeRun(pi, ctx, id, code), () => { lease?.release(); }, async () => {
|
|
3370
3561
|
if (workerBridge)
|
|
3371
3562
|
workerOperations.release(id, "attempt-exited");
|
|
3372
3563
|
// Reconcile this attempt's earlier published writer before its
|
|
3373
3564
|
// next park can admit another continuation of the conversation.
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3565
|
+
if (internal?.resumeWait && resume)
|
|
3566
|
+
await settleResumedAttemptExit({
|
|
3567
|
+
attemptId: id,
|
|
3568
|
+
priorPark: { runId: resume.prior.id, ...internal.resumeWait },
|
|
3569
|
+
service: workerOperations.service,
|
|
3570
|
+
status: readMeta(id)?.status ?? "exited",
|
|
3571
|
+
// The exit handler releases the conversation writer lease just
|
|
3572
|
+
// above, before this call.
|
|
3573
|
+
writerLeaseReleased: true,
|
|
3574
|
+
notify: (message) => {
|
|
3575
|
+
try {
|
|
3576
|
+
uiCtx?.ui?.notify?.(message, "warning");
|
|
3577
|
+
}
|
|
3578
|
+
catch { /* ignore UI failures */ }
|
|
3579
|
+
},
|
|
3580
|
+
});
|
|
3388
3581
|
await settleParkedExit(id);
|
|
3389
3582
|
});
|
|
3583
|
+
managed?.observeExit?.(id, exitCompletion);
|
|
3390
3584
|
writeMeta(meta);
|
|
3391
3585
|
committed = true;
|
|
3392
3586
|
// `meta.json` is now the record of this run; the claim has served its
|
|
@@ -3406,7 +3600,7 @@ export default function (pi, managed) {
|
|
|
3406
3600
|
: resolution.specs.length
|
|
3407
3601
|
? `Runtime: isolated · extensions ${resolution.specs.join(", ")}\n`
|
|
3408
3602
|
: `Runtime: isolated · built-in tools only\n`;
|
|
3409
|
-
const warn = (dropped.length ? `Task sandbox: ${dropped.map((tool) => `${tool.name} disabled (${withheldBridgeReasons.get(tool.name) ?? tool.reason})`).join("; ")}.\n` : "") +
|
|
3603
|
+
const warn = (workspaceNote ? workspaceNote + "\n" : "") + (dropped.length ? `Task sandbox: ${dropped.map((tool) => `${tool.name} disabled (${withheldBridgeReasons.get(tool.name) ?? tool.reason})`).join("; ")}.\n` : "") +
|
|
3410
3604
|
(!sandboxEnabled && resolution.unmapped.length
|
|
3411
3605
|
? `NOTE: no extension mapped for ${resolution.unmapped.join(", ")} — ` +
|
|
3412
3606
|
`${resolution.unmapped.length > 1 ? "these tools" : "this tool"} will NOT exist in the child. ` +
|
|
@@ -3415,7 +3609,9 @@ export default function (pi, managed) {
|
|
|
3415
3609
|
const modelNote = catalogDefaultNote(resume ? undefined : p.catalog, model, thinking);
|
|
3416
3610
|
// The resolved skill exposure rides with the runtime summary, which every
|
|
3417
3611
|
// launch and continuation message already prints.
|
|
3418
|
-
|
|
3612
|
+
const inventoryNote = taskRuntime?.policy.permissions?.processAccess === "read" &&
|
|
3613
|
+
!taskRuntime.policy.tools.includes("process_list") ? " process_list is not in this launch's tool loadout." : "";
|
|
3614
|
+
return { id, meta, spawned, runtime: `${runtime}${processPolicy}${inventoryNote}\n${describeSkillExposure(skills)}\n${meta.timing ? `${formatTimingLimits(meta.timing, startedAt)}\n` : ""}`, warn, sandboxDir, modelNote };
|
|
3419
3615
|
}
|
|
3420
3616
|
catch (error) {
|
|
3421
3617
|
// A launch that never committed metadata is not a run: drop
|
|
@@ -3427,10 +3623,13 @@ export default function (pi, managed) {
|
|
|
3427
3623
|
// must not keep running unsupervised; its log goes with the
|
|
3428
3624
|
// attempt, because a record without metadata can never be read.
|
|
3429
3625
|
if (!committed) {
|
|
3626
|
+
const { abortUncommittedLaunch } = await import("./launch-abort.domain.mjs");
|
|
3430
3627
|
await abortUncommittedLaunch(id, {
|
|
3431
3628
|
child: spawned, lease,
|
|
3432
|
-
artifacts: { sessionDir: childSessionDir, workspaceDir: ownedCloneWorkspace, scratch: launchScratch },
|
|
3629
|
+
artifacts: { sessionDir: childSessionDir, workspaceDir: isolated ? undefined : ownedCloneWorkspace, scratch: launchScratch },
|
|
3433
3630
|
});
|
|
3631
|
+
if (createdWorkspace && isolated)
|
|
3632
|
+
discardWorkspace(isolated);
|
|
3434
3633
|
}
|
|
3435
3634
|
throw error;
|
|
3436
3635
|
}
|
|
@@ -3502,7 +3701,7 @@ export default function (pi, managed) {
|
|
|
3502
3701
|
id: prior.id,
|
|
3503
3702
|
prior,
|
|
3504
3703
|
origin: { cwd: input.park.record.ownerWorkspace ?? prior.callbackOrigin?.cwd ?? prior.cwd, sessionId: input.park.record.ownerSessionId ?? prior.callbackOrigin?.sessionId },
|
|
3505
|
-
others: listMetas(),
|
|
3704
|
+
others: listMetas({ includeArchived: false }),
|
|
3506
3705
|
});
|
|
3507
3706
|
}
|
|
3508
3707
|
catch (error) {
|
|
@@ -3547,7 +3746,7 @@ export default function (pi, managed) {
|
|
|
3547
3746
|
claim: input.claim,
|
|
3548
3747
|
owner,
|
|
3549
3748
|
admissionRevision: input.admissionRevision,
|
|
3550
|
-
permissionsUnchanged: () => samePermissionPlan(permissionPlan, resolveSubagentPermissions(pi, target.recipe.sandbox)),
|
|
3749
|
+
permissionsUnchanged: () => samePermissionPlan(permissionPlan, resolveSubagentPermissions(pi, undefined, { runId: target.prior.id, sandbox: target.recipe.sandbox })),
|
|
3551
3750
|
capacityAvailable: () => resumeCapacity().recheck(),
|
|
3552
3751
|
}),
|
|
3553
3752
|
onSpawned: () => { spawned = true; },
|
|
@@ -3581,7 +3780,10 @@ export default function (pi, managed) {
|
|
|
3581
3780
|
};
|
|
3582
3781
|
return JSON.stringify(sort(value));
|
|
3583
3782
|
};
|
|
3584
|
-
|
|
3783
|
+
// Describe provenance to the caller, but fence on authority, not its display label.
|
|
3784
|
+
const { activationSource: _leftSource, ...leftAuthority } = left;
|
|
3785
|
+
const { activationSource: _rightSource, ...rightAuthority } = right;
|
|
3786
|
+
return canonical(leftAuthority) === canonical(rightAuthority);
|
|
3585
3787
|
}
|
|
3586
3788
|
/** Preserve the original assignment deadline across parking; never extend it. */
|
|
3587
3789
|
function continuationTiming(prior) {
|
|
@@ -3643,11 +3845,7 @@ export default function (pi, managed) {
|
|
|
3643
3845
|
}
|
|
3644
3846
|
catch { /* a host that refuses the adapter leaves parking unavailable */ }
|
|
3645
3847
|
try {
|
|
3646
|
-
const reconciliation =
|
|
3647
|
-
resume: (park) => orchestration.resume(park),
|
|
3648
|
-
notifyWhen: (meta) => Boolean(activeCallbackOrigin && belongsToOrigin(meta, activeCallbackOrigin)),
|
|
3649
|
-
notify: notifyOwnedWait,
|
|
3650
|
-
});
|
|
3848
|
+
const reconciliation = reconcileWorkerWaits();
|
|
3651
3849
|
if (managed) {
|
|
3652
3850
|
void reconciliation.catch(() => undefined);
|
|
3653
3851
|
return;
|
|
@@ -3660,6 +3858,17 @@ export default function (pi, managed) {
|
|
|
3660
3858
|
}
|
|
3661
3859
|
catch { /* reconciliation retries on the next session start */ }
|
|
3662
3860
|
}
|
|
3861
|
+
async function reconcileWorkerWaits() {
|
|
3862
|
+
const service = workerOperations.service;
|
|
3863
|
+
if (!service)
|
|
3864
|
+
return;
|
|
3865
|
+
const orchestration = ensureResumeOrchestration();
|
|
3866
|
+
await reconcileParkedWaits(service, {
|
|
3867
|
+
resume: (park) => orchestration.resume(park),
|
|
3868
|
+
notifyWhen: (meta) => Boolean(activeCallbackOrigin && belongsToOrigin(meta, activeCallbackOrigin)),
|
|
3869
|
+
notify: notifyOwnedWait,
|
|
3870
|
+
});
|
|
3871
|
+
}
|
|
3663
3872
|
// ---- subagent_spawn -------------------------------------------------
|
|
3664
3873
|
//
|
|
3665
3874
|
// One tool launches both fresh work and a continuation of saved work. A
|
|
@@ -3686,7 +3895,7 @@ export default function (pi, managed) {
|
|
|
3686
3895
|
...CATALOG_GUIDELINES,
|
|
3687
3896
|
"Subagent sandboxing defaults to off. Human settings in /sandbox control file, credential-file, command, and network permissions; sandbox:false cannot override an enabled human profile. Set sandbox:true to request kernel confinement, including without published settings. Set callback:false to finish quietly — then read the result on demand via subagent_result.",
|
|
3688
3897
|
"Every launch automatically joins one shared harness-owned watcher, including batch launches; it stops when the last active run ends. Do not start a separate heartbeat or background watcher for subagents. A tool call still open for tool_wait_minutes (default 5) or no progress for stuck_minutes (default 10) sends one factual alert; these alerts never stop, cancel, or restart the run. Hard timeouts default to 60 minutes; max_minutes overrides that default (0 disables). Soft deadlines remain opt-in for work with a real wall-clock bound: deadline_minutes steers the child to wrap up and later stops it after grace_minutes, while max_minutes stops it without grace. Do not set elapsed-time limits merely because a task may take a while; use them only when the work needs a real wall-clock bound.",
|
|
3689
|
-
"
|
|
3898
|
+
"Git writers receive separate checkouts by default. /subagents settings selects Clone or Worktree. isolation:false selects the live checkout. A sandboxed Worktree can return its files or explicitly continue in a verified Clone with recover_in_clone:true.",
|
|
3690
3899
|
"Saved conversations persist automatically. To continue a completed or stopped worker in its own history, call subagent_spawn with session_id (the native session id reported for the saved conversation) and the new feedback as prompt. Omit session_id for a brand-new conversation.",
|
|
3691
3900
|
"On a continuation, pass prompt, session_id, and only optional model, thinking, callback, or timing overrides. Launch-only options (name, agent, role, alias, tools, exclude_tools, skills, clean, sandbox, sandbox_dir, cwd, git_clone_workspace, approve, allow_nested) keep the saved recipe; repeat them only with the same value, otherwise the launch is refused.",
|
|
3692
3901
|
"Do not restate the original task or role when continuing: they already live in the saved conversation. A running or orphaned latest attempt blocks continuation until it stops, and missing saved history is refused rather than recreated.",
|
|
@@ -3709,6 +3918,8 @@ export default function (pi, managed) {
|
|
|
3709
3918
|
sandbox_dir: Type.Optional(Type.String({ description: "Confine writes to (and run the child in) this directory instead of the working dir. Created if missing." })),
|
|
3710
3919
|
callback: Type.Optional(Type.Boolean({ description: "Default TRUE: on completion, trigger a turn that calls subagent_result and presents the result. Set false to finish quietly — the result is then read on demand via subagent_result." })),
|
|
3711
3920
|
cwd: Type.Optional(Type.String({ description: "Working directory (default: current)." })),
|
|
3921
|
+
isolation: Type.Optional(Type.Boolean({ description: "Use false to work in the live checkout. By default each Git writer gets its own workspace." })),
|
|
3922
|
+
recover_in_clone: Type.Optional(Type.Boolean({ description: "Continue a stopped or completed linked-worktree conversation in a verified clone with the same history and permissions." })),
|
|
3712
3923
|
git_clone_workspace: Type.Optional(Type.Boolean({ description: "Prepare a disposable Git clone workspace for sandboxed Git-mutating subagents. The clone has a real .git/ directory inside the sandbox writable root and is self-contained after setup." })),
|
|
3713
3924
|
approve: Type.Optional(Type.Boolean({ description: "Trust project-local files in the child (default: false; headless runs cannot prompt for trust)." })),
|
|
3714
3925
|
allow_nested: Type.Optional(Type.Boolean({ description: "Allow the child to spawn its own subagents (default: false). Loads this extension in the child and allowlists its tools." })),
|
|
@@ -3748,6 +3959,8 @@ export default function (pi, managed) {
|
|
|
3748
3959
|
model: p.model,
|
|
3749
3960
|
thinking: p.thinking,
|
|
3750
3961
|
callback: p.callback,
|
|
3962
|
+
isolation: p.isolation,
|
|
3963
|
+
recover_in_clone: p.recover_in_clone,
|
|
3751
3964
|
deadline_minutes: p.deadline_minutes,
|
|
3752
3965
|
grace_minutes: p.grace_minutes,
|
|
3753
3966
|
max_minutes: p.max_minutes,
|
|
@@ -3872,6 +4085,7 @@ export default function (pi, managed) {
|
|
|
3872
4085
|
callback: Type.Optional(Type.Boolean({ description: "Default TRUE: post result back on completion." })),
|
|
3873
4086
|
clean: Type.Optional(Type.Boolean({ description: "Hermetic builtins-only child; no extensions load." })),
|
|
3874
4087
|
cwd: Type.Optional(Type.String({ description: "Working directory (default: current)." })),
|
|
4088
|
+
isolation: Type.Optional(Type.Boolean({ description: "Use false to work in the live checkout. By default each Git writer gets its own workspace." })),
|
|
3875
4089
|
git_clone_workspace: Type.Optional(Type.Boolean({ description: "Prepare a disposable Git clone workspace for each job (same semantics as subagent_spawn)." })),
|
|
3876
4090
|
approve: Type.Optional(Type.Boolean({ description: "Trust project-local files in children." })),
|
|
3877
4091
|
allow_nested: Type.Optional(Type.Boolean({ description: "Allow children to spawn their own subagents." })),
|
|
@@ -3895,6 +4109,8 @@ export default function (pi, managed) {
|
|
|
3895
4109
|
callback: Type.Optional(Type.Boolean()),
|
|
3896
4110
|
clean: Type.Optional(Type.Boolean()),
|
|
3897
4111
|
cwd: Type.Optional(Type.String()),
|
|
4112
|
+
isolation: Type.Optional(Type.Boolean({ description: "Use false to work in the live checkout. By default each Git writer gets its own workspace." })),
|
|
4113
|
+
recover_in_clone: Type.Optional(Type.Boolean({ description: "Continue this job in a verified Clone." })),
|
|
3898
4114
|
git_clone_workspace: Type.Optional(Type.Boolean()),
|
|
3899
4115
|
approve: Type.Optional(Type.Boolean()),
|
|
3900
4116
|
allow_nested: Type.Optional(Type.Boolean()),
|
|
@@ -3929,8 +4145,10 @@ export default function (pi, managed) {
|
|
|
3929
4145
|
throw new Error(blankSelector);
|
|
3930
4146
|
let catalogSnapshot;
|
|
3931
4147
|
let catalogHost;
|
|
3932
|
-
const needsCatalog = p.jobs.some((job) =>
|
|
3933
|
-
|
|
4148
|
+
const needsCatalog = p.jobs.some((job) => {
|
|
4149
|
+
const merged = mergeJobOptions(p.shared, job);
|
|
4150
|
+
return merged.session_id === undefined && merged.session_name === undefined && hasCatalogSelector(merged);
|
|
4151
|
+
});
|
|
3934
4152
|
if (needsCatalog) {
|
|
3935
4153
|
catalogHost = catalogHostFrom(ctx);
|
|
3936
4154
|
noteCatalogHost(catalogHost);
|
|
@@ -3987,7 +4205,7 @@ export default function (pi, managed) {
|
|
|
3987
4205
|
const job = p.jobs[i];
|
|
3988
4206
|
let name = names[i];
|
|
3989
4207
|
const merged = mergeJobOptions(p.shared, job);
|
|
3990
|
-
const isContinuation =
|
|
4208
|
+
const isContinuation = merged.session_id !== undefined || merged.session_name !== undefined;
|
|
3991
4209
|
// A continuation keeps its own frozen model and effort. shared.model
|
|
3992
4210
|
// is a default for NEW conversations, so only a per-job value is an
|
|
3993
4211
|
// explicit escalation of the saved recipe.
|
|
@@ -4003,7 +4221,7 @@ export default function (pi, managed) {
|
|
|
4003
4221
|
}
|
|
4004
4222
|
}
|
|
4005
4223
|
try {
|
|
4006
|
-
const sessionId = requestedSessionId(
|
|
4224
|
+
const sessionId = requestedSessionId(merged, ctx.cwd);
|
|
4007
4225
|
// A saved conversation is never re-resolved against the catalog.
|
|
4008
4226
|
if (sessionId === undefined && catalogSnapshot && catalogHost && hasCatalogSelector(merged)) {
|
|
4009
4227
|
const explicitName = typeof job.name === "string" && job.name.trim() !== "" ? job.name : undefined;
|
|
@@ -4182,6 +4400,7 @@ export default function (pi, managed) {
|
|
|
4182
4400
|
const timing = timingState();
|
|
4183
4401
|
return {
|
|
4184
4402
|
mode: settings.delegationMode, maxConcurrent: settings.maxConcurrent,
|
|
4403
|
+
gitWorkspace: activeWorkspace(),
|
|
4185
4404
|
maxMinutes: timing.maxMinutes,
|
|
4186
4405
|
modeSource: settings.sources.delegationMode,
|
|
4187
4406
|
capSource: settings.sources.maxConcurrent,
|
|
@@ -4197,7 +4416,7 @@ export default function (pi, managed) {
|
|
|
4197
4416
|
skillsError: skills.error,
|
|
4198
4417
|
};
|
|
4199
4418
|
},
|
|
4200
|
-
changeMode, changeCap, changeTiming, changeSkills, save: saveSettings, reset: resetSettings,
|
|
4419
|
+
changeMode, changeWorkspace, changeCap, changeTiming, changeSkills, save: saveSettings, reset: resetSettings,
|
|
4201
4420
|
discoverSkills: () => discoveredSkillsFromContext(ctx),
|
|
4202
4421
|
// Close this page first; the catalog opens after ui.custom resolves.
|
|
4203
4422
|
openAgents: () => done("agents"),
|
|
@@ -4211,7 +4430,7 @@ export default function (pi, managed) {
|
|
|
4211
4430
|
: skills.mode === "none" ? "no skills" : `${skills.paths.length} selected skills`;
|
|
4212
4431
|
const timing = timingState();
|
|
4213
4432
|
ctx.ui.notify(`Delegation mode: ${activeDelegationMode()}. Concurrent subagents: ${activeConcurrencyCap()}. ` +
|
|
4214
|
-
`
|
|
4433
|
+
`Run timeout: ${timing.maxMinutes ? timing.maxMinutes + " minutes" : "No limit"}. Tool-wait alert: ${timing.toolWaitMinutes} min. ` +
|
|
4215
4434
|
`No-progress alert: ${timing.stuckMinutes} min. Skills: ${skillChoice}. ` +
|
|
4216
4435
|
`Use /subagents mode <mode>, cap <number>, tool-wait <minutes>, stuck <minutes>, or settings; /subagents save persists them.`, "info");
|
|
4217
4436
|
}
|
|
@@ -4222,6 +4441,30 @@ export default function (pi, managed) {
|
|
|
4222
4441
|
pi.events?.emit("harness-settings:register", contribution);
|
|
4223
4442
|
pi.events?.emit("harness-settings:register", agentsContribution);
|
|
4224
4443
|
};
|
|
4444
|
+
const unsubscribeToolLoading = pi.events?.on?.("pi-better-subagents:default-tool-loading", (request) => {
|
|
4445
|
+
const query = request;
|
|
4446
|
+
if (typeof query?.reply !== "function")
|
|
4447
|
+
return;
|
|
4448
|
+
const config = ordinaryChildConfig(loadConfig(), activeChildProviders(pi));
|
|
4449
|
+
const names = normalizeTools(config.defaultTools ?? SAFE_DEFAULT_TOOLS).split(",").filter(Boolean);
|
|
4450
|
+
addEditablePatch(names, new Set());
|
|
4451
|
+
const rows = [...new Set(names)].map(name => {
|
|
4452
|
+
if (name === "codemode") {
|
|
4453
|
+
const supported = "createCodemodeExtension" in PiCodingAgent && typeof PiCodingAgent.createCodemodeExtension === "function";
|
|
4454
|
+
return { name, provider: supported ? "Harness" : "SDK unavailable" };
|
|
4455
|
+
}
|
|
4456
|
+
if (BUILTIN_TOOLS.includes(name))
|
|
4457
|
+
return { name, provider: "Pi" };
|
|
4458
|
+
const spec = config.toolExtensions?.[name];
|
|
4459
|
+
const sources = typeof spec === "string" ? [spec] : spec ?? [];
|
|
4460
|
+
const providers = sources.map(source => {
|
|
4461
|
+
const label = source === ORDINARY_TOOL_PROVIDERS[name] ? "Harness" : source;
|
|
4462
|
+
return resolveExtensionPath(source) ? label : `${label} (missing)`;
|
|
4463
|
+
});
|
|
4464
|
+
return { name, provider: providers.join(", ") || (config.inheritExtensions ? "Session extensions" : "No provider mapped") };
|
|
4465
|
+
});
|
|
4466
|
+
query.reply(rows);
|
|
4467
|
+
});
|
|
4225
4468
|
const unsubscribeSettingsRequest = pi.events?.on?.("harness-settings:request", registerSettings);
|
|
4226
4469
|
const unsubscribeOutcomeWorkflow = pi.events?.on?.("pi-better-workflow:changed", () => recoverAssignmentOutcomes(pi));
|
|
4227
4470
|
registerSettings();
|
|
@@ -4279,7 +4522,7 @@ export default function (pi, managed) {
|
|
|
4279
4522
|
: skills.mode === "none" ? "no skills" : `${skills.paths.length} selected skills`;
|
|
4280
4523
|
const timing = timingState();
|
|
4281
4524
|
if (ctx.hasUI && !(await ctx.ui.confirm("Save subagent defaults?", `Future sessions will start in ${activeDelegationMode()} with a cap of ${activeConcurrencyCap()}, ` +
|
|
4282
|
-
`timeout ${timing.maxMinutes
|
|
4525
|
+
`run timeout ${timing.maxMinutes ? timing.maxMinutes + " minutes" : "No limit"}, tool-wait alert ${timing.toolWaitMinutes} min, ` +
|
|
4283
4526
|
`no-progress alert ${timing.stuckMinutes} min, and ${skillChoice}.`))) {
|
|
4284
4527
|
ctx.ui.notify("Subagent defaults unchanged.", "info");
|
|
4285
4528
|
return;
|
|
@@ -4387,7 +4630,15 @@ export default function (pi, managed) {
|
|
|
4387
4630
|
// Capture a UI-bearing context and, if runs from a prior session are still
|
|
4388
4631
|
// alive, resume the ticking widget. Deferred out of the factory per pi's
|
|
4389
4632
|
// "no background resources at load" rule.
|
|
4390
|
-
|
|
4633
|
+
let restoreObservation;
|
|
4634
|
+
let offFirstAssignment;
|
|
4635
|
+
const cancelDeferredObservation = () => {
|
|
4636
|
+
if (restoreObservation)
|
|
4637
|
+
clearImmediate(restoreObservation);
|
|
4638
|
+
offFirstAssignment?.();
|
|
4639
|
+
offFirstAssignment = undefined;
|
|
4640
|
+
};
|
|
4641
|
+
pi.on("session_start", async (event, ctx) => {
|
|
4391
4642
|
// A session begins in this process again (reload, restart, or a session
|
|
4392
4643
|
// switch), so the previous session's teardown no longer applies: the
|
|
4393
4644
|
// replacing session owns this instance's supervision loops (#625).
|
|
@@ -4412,11 +4663,31 @@ export default function (pi, managed) {
|
|
|
4412
4663
|
activeCallbackOrigin = callbackOriginFromContext(ctx);
|
|
4413
4664
|
pendingRecipientRecovery.clear();
|
|
4414
4665
|
observedRecipientRows.clear();
|
|
4415
|
-
|
|
4416
|
-
|
|
4666
|
+
cancelDeferredObservation();
|
|
4667
|
+
if (!managed && activeCallbackOrigin) {
|
|
4668
|
+
configureWorkObservation(PiCodingAgent.getAgentDir(), activeCallbackOrigin, () => {
|
|
4417
4669
|
refreshBackgroundWorkNavigator(ctx);
|
|
4418
4670
|
observeRecipientNotifications(pi);
|
|
4419
4671
|
});
|
|
4672
|
+
if (!event?.reason) {
|
|
4673
|
+
// Older hosts use completion of their untyped start callback as the readiness signal.
|
|
4674
|
+
await activateWorkObservation();
|
|
4675
|
+
}
|
|
4676
|
+
else if (shouldRestoreWorkObservation(event, ctx.sessionManager)) {
|
|
4677
|
+
restoreObservation = setImmediate(() => { void activateWorkObservation(); });
|
|
4678
|
+
}
|
|
4679
|
+
else {
|
|
4680
|
+
// Another extension can assign work to this recipient before it calls a tool.
|
|
4681
|
+
const origin = activeCallbackOrigin;
|
|
4682
|
+
offFirstAssignment = onMetaChanged(meta => {
|
|
4683
|
+
if (!meta || !belongsToOrigin(meta, origin))
|
|
4684
|
+
return;
|
|
4685
|
+
offFirstAssignment?.();
|
|
4686
|
+
offFirstAssignment = undefined;
|
|
4687
|
+
void activateWorkObservation();
|
|
4688
|
+
});
|
|
4689
|
+
}
|
|
4690
|
+
}
|
|
4420
4691
|
if (!managed) {
|
|
4421
4692
|
recoverCompletionCallbacks(pi);
|
|
4422
4693
|
observeRecipientNotifications(pi);
|
|
@@ -4471,6 +4742,7 @@ export default function (pi, managed) {
|
|
|
4471
4742
|
await startWorkerOperations();
|
|
4472
4743
|
});
|
|
4473
4744
|
pi.on("session_before_switch", () => {
|
|
4745
|
+
cancelDeferredObservation();
|
|
4474
4746
|
closeCatalogHost();
|
|
4475
4747
|
agentSessionSettings.clear();
|
|
4476
4748
|
catalogModelRegistry = undefined;
|
|
@@ -4485,6 +4757,7 @@ export default function (pi, managed) {
|
|
|
4485
4757
|
// Tear down the timer and clear the widget when the session ends.
|
|
4486
4758
|
pi.on("session_shutdown", async (event, ctx) => {
|
|
4487
4759
|
closeCatalogHost();
|
|
4760
|
+
cancelDeferredObservation();
|
|
4488
4761
|
stopWorkObservation();
|
|
4489
4762
|
pendingNavigatorDismissals.clear();
|
|
4490
4763
|
if (outcomeTicker)
|
|
@@ -4494,6 +4767,8 @@ export default function (pi, managed) {
|
|
|
4494
4767
|
closeOutcomeHost(outcomeHost);
|
|
4495
4768
|
if (typeof unsubscribeOutcomeWorkflow === "function")
|
|
4496
4769
|
unsubscribeOutcomeWorkflow();
|
|
4770
|
+
if (typeof unsubscribeToolLoading === "function")
|
|
4771
|
+
unsubscribeToolLoading();
|
|
4497
4772
|
if (typeof unsubscribeSettingsRequest === "function")
|
|
4498
4773
|
unsubscribeSettingsRequest();
|
|
4499
4774
|
// #625: subagent children are detached process groups that outlive this
|