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
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** Select a saved, installed worker closure without changing the server owner. */
|
|
2
|
+
import { readFileSync, realpathSync, statSync } from "node:fs";
|
|
3
|
+
import { basename, dirname, join, normalize, sep } from "node:path";
|
|
4
|
+
|
|
5
|
+
const DOMAIN = join("src", "runtime", "domain", "subagents");
|
|
6
|
+
type Recipe = { runtimeRoot?: string; baseExtensionArgs?: readonly string[]; extensionArgs?: readonly string[] };
|
|
7
|
+
type Command = { file: string; fileArgs: string[] };
|
|
8
|
+
|
|
9
|
+
export function managedRuntimeRoot(domain: string): string | undefined {
|
|
10
|
+
if (!domain.endsWith(`${sep}${DOMAIN}`)) return undefined;
|
|
11
|
+
const root = domain.slice(0, -(DOMAIN.length + 1));
|
|
12
|
+
return basename(dirname(root)) === "releases" && /^[a-f0-9]{64}$/.test(basename(root)) ? root : undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ContinuationRuntime {
|
|
16
|
+
root: string;
|
|
17
|
+
mapPath(path: string): string;
|
|
18
|
+
mapArgs(args: readonly string[]): string[];
|
|
19
|
+
command(command: Command): Command;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Only sibling, published releases are eligible. User extensions retain their
|
|
24
|
+
* original identity check. Permission policy is still generated by the current
|
|
25
|
+
* server; a saved runtime does not grandfather its previous permission grants.
|
|
26
|
+
* Published releases are retained by the installer (it removes staging only).
|
|
27
|
+
* Any future release GC must treat LaunchRecipe.runtimeRoot as a reference.
|
|
28
|
+
*/
|
|
29
|
+
export function selectContinuationRuntime(options: { currentDir: string; recipe?: Recipe }): ContinuationRuntime | undefined {
|
|
30
|
+
const current = managedRuntimeRoot(options.currentDir);
|
|
31
|
+
if (!current || !options.recipe) return undefined;
|
|
32
|
+
const recipe = options.recipe;
|
|
33
|
+
// Upgrade recipes written before runtimeRoot existed using the mandatory
|
|
34
|
+
// harness control, never a user-selected/custom extension path.
|
|
35
|
+
const args = recipe.baseExtensionArgs ?? recipe.extensionArgs ?? [];
|
|
36
|
+
const steer = args.find((value, index) => args[index - 1] === "--extension" && value.endsWith(`${sep}${DOMAIN}${sep}child-steer.ts`));
|
|
37
|
+
const saved = recipe.runtimeRoot ?? (steer ? managedRuntimeRoot(dirname(steer)) : undefined);
|
|
38
|
+
if (!saved || saved === current) return undefined;
|
|
39
|
+
const unavailable = (detail: string): never => {
|
|
40
|
+
throw new Error(`Cannot resume: saved runtime ${basename(saved)} unavailable (${detail}). Restore that release or explicitly launch a replacement conversation; no worker was started.`);
|
|
41
|
+
};
|
|
42
|
+
if (normalize(saved) !== saved || dirname(saved) !== dirname(current) || !/^[a-f0-9]{64}$/.test(basename(saved))) {
|
|
43
|
+
return unavailable("not a sibling managed release");
|
|
44
|
+
}
|
|
45
|
+
function manifest(root: string) {
|
|
46
|
+
let value;
|
|
47
|
+
try {
|
|
48
|
+
if (realpathSync(root) !== root) return unavailable("release path is not canonical");
|
|
49
|
+
value = JSON.parse(readFileSync(join(root, "runtime.json"), "utf8"));
|
|
50
|
+
} catch { return unavailable("missing or unreadable release manifest"); }
|
|
51
|
+
if (value.format !== 1 || value.root !== root || value.build?.contentId !== basename(root)
|
|
52
|
+
|| value.node !== join(root, "node/bin/node") || value.installRoot !== dirname(dirname(root))) {
|
|
53
|
+
return unavailable("invalid release manifest");
|
|
54
|
+
}
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
const before = manifest(saved), now = manifest(current);
|
|
58
|
+
// These releases share the existing v1 worker admission/policy/bridge wire
|
|
59
|
+
// formats. Refuse SDK, Node, platform or protocol transitions rather than
|
|
60
|
+
// assuming that a new server can host any historic worker.
|
|
61
|
+
if (before.build.protocolVersion !== 1 || now.build.protocolVersion !== 1
|
|
62
|
+
|| ["piSdkVersion", "nodeVersion", "platform"].some(key => !before.build[key] || before.build[key] !== now.build[key])) {
|
|
63
|
+
throw new Error(`Cannot resume: saved runtime ${basename(saved)} is incompatible with the current worker protocol, SDK or platform. Explicit replacement is required; no worker was started.`);
|
|
64
|
+
}
|
|
65
|
+
function required(path: string, directory = false): string {
|
|
66
|
+
try {
|
|
67
|
+
const stat = statSync(path);
|
|
68
|
+
if (realpathSync(path) !== path || !(stat.isFile() || directory && stat.isDirectory())) return unavailable("worker file is missing or redirected");
|
|
69
|
+
} catch { return unavailable("worker file is missing or unreadable"); }
|
|
70
|
+
return path;
|
|
71
|
+
}
|
|
72
|
+
const node = required(before.node);
|
|
73
|
+
const mapPath = (path: string): string => path.startsWith(`${current}${sep}`)
|
|
74
|
+
? required(join(saved, path.slice(current.length + 1)), true) : path;
|
|
75
|
+
return {
|
|
76
|
+
root: saved,
|
|
77
|
+
mapPath,
|
|
78
|
+
mapArgs: values => values.map((value, index) => values[index - 1] === "--extension" ? mapPath(value) : value),
|
|
79
|
+
command: command => {
|
|
80
|
+
// Only executable slots are rewritten. A prompt or arbitrary CLI
|
|
81
|
+
// value that happens to contain a runtime path must stay untouched.
|
|
82
|
+
const fileArgs = [...command.fileArgs];
|
|
83
|
+
fileArgs[0] = mapPath(fileArgs[0]!);
|
|
84
|
+
if (basename(fileArgs[0]!) === "task-runtime.mjs") fileArgs[1] = mapPath(fileArgs[1]!);
|
|
85
|
+
return { file: node, fileArgs };
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-subagents/continuation.ts. Do not edit directly.
|
|
2
|
+
import { hasWorkspaceCheckpoint } from "./isolated-workspace.domain.mjs";
|
|
2
3
|
/**
|
|
3
4
|
* Subagent continuation.
|
|
4
5
|
*
|
|
@@ -452,7 +453,8 @@ export function planContinuation(options) {
|
|
|
452
453
|
catch {
|
|
453
454
|
workspaceIsDir = false;
|
|
454
455
|
}
|
|
455
|
-
|
|
456
|
+
const recoverable = !workspaceIsDir && recipe.workspace && hasWorkspaceCheckpoint(recipe.workspace);
|
|
457
|
+
if (!workspaceIsDir && !recoverable)
|
|
456
458
|
throw refusal(id, `its workspace ${recipe.cwd} is missing.`);
|
|
457
459
|
if (recipe.sandboxDir !== undefined) {
|
|
458
460
|
let sandboxIsDir = false;
|
|
@@ -462,7 +464,7 @@ export function planContinuation(options) {
|
|
|
462
464
|
catch {
|
|
463
465
|
sandboxIsDir = false;
|
|
464
466
|
}
|
|
465
|
-
if (!sandboxIsDir)
|
|
467
|
+
if (!sandboxIsDir && !recoverable)
|
|
466
468
|
throw refusal(id, `its sandbox workspace ${recipe.sandboxDir} is missing.`);
|
|
467
469
|
}
|
|
468
470
|
const lookup = findSavedConversation({
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { hasWorkspaceCheckpoint } from "./isolated-workspace.ts";
|
|
1
2
|
/**
|
|
2
3
|
* Subagent continuation.
|
|
3
4
|
*
|
|
@@ -536,11 +537,12 @@ export function planContinuation(options: {
|
|
|
536
537
|
|
|
537
538
|
let workspaceIsDir = false;
|
|
538
539
|
try { workspaceIsDir = statSync(recipe.cwd).isDirectory(); } catch { workspaceIsDir = false; }
|
|
539
|
-
|
|
540
|
+
const recoverable = !workspaceIsDir && recipe.workspace && hasWorkspaceCheckpoint(recipe.workspace);
|
|
541
|
+
if (!workspaceIsDir && !recoverable) throw refusal(id, `its workspace ${recipe.cwd} is missing.`);
|
|
540
542
|
if (recipe.sandboxDir !== undefined) {
|
|
541
543
|
let sandboxIsDir = false;
|
|
542
544
|
try { sandboxIsDir = statSync(recipe.sandboxDir).isDirectory(); } catch { sandboxIsDir = false; }
|
|
543
|
-
if (!sandboxIsDir) throw refusal(id, `its sandbox workspace ${recipe.sandboxDir} is missing.`);
|
|
545
|
+
if (!sandboxIsDir && !recoverable) throw refusal(id, `its sandbox workspace ${recipe.sandboxDir} is missing.`);
|
|
544
546
|
}
|
|
545
547
|
|
|
546
548
|
const lookup: ConversationLookup = findSavedConversation({
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
* A builtin needs no extension, so it never counts as unmapped.
|
|
35
35
|
*/
|
|
36
36
|
// codemode is supplied by the harness child adapter, not a discovered package.
|
|
37
|
-
export const BUILTIN_TOOLS = ["read", "bash", "edit", "write", "codemode"];
|
|
37
|
+
export const BUILTIN_TOOLS = ["read", "bash", "edit", "write", "grep", "find", "ls", "codemode"];
|
|
38
38
|
/** Marker spec meaning "this extension's own package" (for allow_nested). */
|
|
39
39
|
export const SELF_SPEC = "self";
|
|
40
40
|
/**
|
|
@@ -87,11 +87,11 @@ export function toolList(tools) {
|
|
|
87
87
|
* @returns {{mode: "isolated"|"clean"|"inherit", specs: string[], unmapped: string[], reasons: Record<string,string[]>}}
|
|
88
88
|
* mode — "isolated" passes --no-extensions + explicit -e (the default);
|
|
89
89
|
* "clean" passes --no-extensions with no -e;
|
|
90
|
-
* "inherit"
|
|
90
|
+
* "inherit" keeps discovery and adds explicitly selected mappings.
|
|
91
91
|
* specs — extension specs to load, deduped, in a stable order.
|
|
92
92
|
* unmapped — requested tools that are neither builtin nor mapped to an
|
|
93
|
-
* extension.
|
|
94
|
-
*
|
|
93
|
+
* extension. Admission rejects a known missing required provider.
|
|
94
|
+
* Preflight verifies registrations supplied by loaded extensions.
|
|
95
95
|
* reasons — spec -> what pulled it in, for the spawn diagnostic.
|
|
96
96
|
*/
|
|
97
97
|
export function resolveExtensions(a = {}) {
|
|
@@ -107,13 +107,11 @@ export function resolveExtensions(a = {}) {
|
|
|
107
107
|
};
|
|
108
108
|
// allow_nested is honored in every mode: it is an explicit caller request,
|
|
109
109
|
// and without our own package loaded the child has no subagent tools at all.
|
|
110
|
-
|
|
110
|
+
const inherit = cfg.inheritExtensions === true;
|
|
111
|
+
if (a.allowNested && !inherit)
|
|
111
112
|
add(SELF_SPEC, "allow_nested");
|
|
112
|
-
if (cfg.inheritExtensions === true) {
|
|
113
|
-
return { mode: "inherit", specs: [], unmapped: [], reasons: {} };
|
|
114
|
-
}
|
|
115
113
|
if (a.clean === true) {
|
|
116
|
-
return { mode: "clean", specs, unmapped: [], reasons };
|
|
114
|
+
return { mode: inherit ? "inherit" : "clean", specs, unmapped: [], reasons };
|
|
117
115
|
}
|
|
118
116
|
const toolMap = cfg.toolExtensions ?? {};
|
|
119
117
|
const unmapped = [];
|
|
@@ -122,13 +120,15 @@ export function resolveExtensions(a = {}) {
|
|
|
122
120
|
continue;
|
|
123
121
|
const mapped = toSpecList(toolMap[tool]);
|
|
124
122
|
if (mapped.length === 0) {
|
|
125
|
-
if (!unmapped.includes(tool))
|
|
123
|
+
if (!inherit && !unmapped.includes(tool))
|
|
126
124
|
unmapped.push(tool);
|
|
127
125
|
continue;
|
|
128
126
|
}
|
|
129
127
|
for (const spec of mapped)
|
|
130
128
|
add(spec, `tool:${tool}`);
|
|
131
129
|
}
|
|
130
|
+
if (inherit)
|
|
131
|
+
return { mode: "inherit", specs, unmapped, reasons };
|
|
132
132
|
// Model auth is not tool-shaped: xai/grok needs pi-xai-oauth loaded or the
|
|
133
133
|
// child cannot authenticate at all, whatever tools it was granted. A user
|
|
134
134
|
// entry for a provider wins over the built-in one, including an empty list
|
|
@@ -150,9 +150,7 @@ export function resolveExtensions(a = {}) {
|
|
|
150
150
|
* @returns {{args: string[], missing: string[]}}
|
|
151
151
|
*/
|
|
152
152
|
export function extensionArgs(resolution, resolvePath) {
|
|
153
|
-
|
|
154
|
-
return { args: [], missing: [] };
|
|
155
|
-
const args = ["--no-extensions"];
|
|
153
|
+
const args = resolution.mode === "inherit" ? [] : ["--no-extensions"];
|
|
156
154
|
const missing = [];
|
|
157
155
|
for (const spec of resolution.specs) {
|
|
158
156
|
const path = resolvePath(spec);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-subagents/failures.ts. Do not edit directly.
|
|
2
|
-
import {
|
|
2
|
+
import { resultDir } from "./session-store.domain.mjs";
|
|
3
|
+
import { existsSync, closeSync, fstatSync, openSync, readSync } from "node:fs";
|
|
3
4
|
import { join } from "node:path";
|
|
4
5
|
import { logPathFor, runDir, taskRuntimeTrust } from "./registry.domain.mjs";
|
|
5
6
|
import { activeFailures, actionableFailures, disposeIncidents, failureIdentity, findIncident, formatFailureSummary, formatTerminalFailureFacts, markFailureAttentionDelivered, observeFailures, pendingFailureAttention, readFailureState } from "./shared-failure-observations.domain.mjs";
|
|
@@ -16,7 +17,10 @@ const workerDiagnostics = new SandboxDiagnostics({ context: "worker",
|
|
|
16
17
|
});
|
|
17
18
|
export { formatFailureSummary, pendingFailureAttention, markFailureAttentionDelivered, toolOperation };
|
|
18
19
|
export const failurePath = (id) => join(runDir(id), "failures.jsonl");
|
|
19
|
-
export
|
|
20
|
+
export function readRunFailures(id) {
|
|
21
|
+
const retained = !existsSync(runDir(id)) && resultDir(id);
|
|
22
|
+
return readFailureState(retained ? join(retained, "failures.jsonl") : failurePath(id));
|
|
23
|
+
}
|
|
20
24
|
const scans = new Map();
|
|
21
25
|
/** When each run's trust first could not be read, for the bounded wait (#325). */
|
|
22
26
|
const trustUnknownSince = new Map();
|
|
@@ -176,6 +180,11 @@ function exactRuleLeftovers(path, prior) {
|
|
|
176
180
|
/** Scan complete source records, independent of the finite progress/transcript tail. */
|
|
177
181
|
export function collectRunFailures(id, cwd, terminal = false, assertCurrent = () => { }) {
|
|
178
182
|
assertCurrent();
|
|
183
|
+
if (!existsSync(runDir(id))) {
|
|
184
|
+
const retained = resultDir(id);
|
|
185
|
+
if (retained && existsSync(join(retained, "result.json")))
|
|
186
|
+
return readRunFailures(id);
|
|
187
|
+
}
|
|
179
188
|
const path = failurePath(id);
|
|
180
189
|
let fd;
|
|
181
190
|
try {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resultDir } from "./session-store.ts";
|
|
2
|
+
import { existsSync, closeSync, fstatSync, openSync, readSync } from "node:fs";
|
|
2
3
|
import { join } from "node:path";
|
|
3
4
|
import { logPathFor, runDir, taskRuntimeTrust } from "./registry.ts";
|
|
4
5
|
import { activeFailures, actionableFailures, disposeIncidents, failureIdentity, findIncident, formatFailureSummary, formatTerminalFailureFacts, markFailureAttentionDelivered,
|
|
@@ -18,7 +19,10 @@ const workerDiagnostics = new SandboxDiagnostics({ context: "worker",
|
|
|
18
19
|
|
|
19
20
|
export { formatFailureSummary, pendingFailureAttention, markFailureAttentionDelivered, toolOperation };
|
|
20
21
|
export const failurePath = (id: string) => join(runDir(id), "failures.jsonl");
|
|
21
|
-
export
|
|
22
|
+
export function readRunFailures(id: string): FailureState {
|
|
23
|
+
const retained = !existsSync(runDir(id)) && resultDir(id);
|
|
24
|
+
return readFailureState(retained ? join(retained, "failures.jsonl") : failurePath(id));
|
|
25
|
+
}
|
|
22
26
|
interface Scan {
|
|
23
27
|
offset: number; head: string; identity: string; model: IncidentModel; retry?: number;
|
|
24
28
|
/**
|
|
@@ -162,6 +166,10 @@ function exactRuleLeftovers(path: string, prior: FailureState): Set<string> {
|
|
|
162
166
|
/** Scan complete source records, independent of the finite progress/transcript tail. */
|
|
163
167
|
export function collectRunFailures(id: string, cwd: string, terminal = false, assertCurrent: () => void = () => {}): FailureState {
|
|
164
168
|
assertCurrent();
|
|
169
|
+
if (!existsSync(runDir(id))) {
|
|
170
|
+
const retained = resultDir(id);
|
|
171
|
+
if (retained && existsSync(join(retained, "result.json"))) return readRunFailures(id);
|
|
172
|
+
}
|
|
165
173
|
const path = failurePath(id);
|
|
166
174
|
let fd: number;
|
|
167
175
|
try { fd = openSync(logPathFor(id), "r"); }
|
|
@@ -15,6 +15,18 @@ import { parseRunForLifecycle } from "./parse.domain.mjs";
|
|
|
15
15
|
import { canExitFinalize, effectiveStatus, isFinalResultStatus, readMeta, updateParkRecord, writeMeta, } from "./registry.domain.mjs";
|
|
16
16
|
import { fmtElapsed, fmtSpend } from "./widget.domain.mjs";
|
|
17
17
|
import { evaluateParkDisposition } from "./worker-waits.domain.mjs";
|
|
18
|
+
import { reconcileRun } from "./health.domain.mjs";
|
|
19
|
+
/** The current management owner calls this only for an interrupted, unobserved writer. */
|
|
20
|
+
export function reconcileInterruptedRun(meta, probe, now, hooks = {}) {
|
|
21
|
+
const reconciliation = reconcileRun(meta, probe, now);
|
|
22
|
+
if ((meta.status === "running" || meta.status === "orphaned") && meta.supervisionInterruptedAt !== undefined && reconciliation.status === "lost") {
|
|
23
|
+
const run = parseRunForLifecycle(meta.id);
|
|
24
|
+
if (run.sawEnd && run.unmatchedToolCalls.length === 0) {
|
|
25
|
+
return { reconciliation, finalization: finalizeRun(meta.id, null, { ...hooks, recoveredWriterExit: true }) };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return { reconciliation };
|
|
29
|
+
}
|
|
18
30
|
/**
|
|
19
31
|
* Finalize a run once its child exits. Idempotent: a run already marked
|
|
20
32
|
* terminal is left alone. Persists lifecycle classification + failureReason
|
|
@@ -59,7 +71,10 @@ export function finalizeRun(id, code, hooks = {}) {
|
|
|
59
71
|
// and the recorded wait is held for its owner.
|
|
60
72
|
const park = evaluateParkDisposition({
|
|
61
73
|
runId: id,
|
|
62
|
-
|
|
74
|
+
// Preserve a verified staged checkpoint for post-restart park recovery.
|
|
75
|
+
// The coordinator still requires writer-exit and lease-release proof.
|
|
76
|
+
cleanExit: (code === 0 || (code === null && hooks.recoveredWriterExit === true))
|
|
77
|
+
&& completed && !outcome.incomplete && !outcome.diagnostics.modelError,
|
|
63
78
|
});
|
|
64
79
|
const parked = park.parked && park.record !== undefined;
|
|
65
80
|
if (parked && park.record) {
|
|
@@ -26,8 +26,11 @@ import {
|
|
|
26
26
|
} from "./registry.ts";
|
|
27
27
|
import { fmtElapsed, fmtSpend } from "./widget.ts";
|
|
28
28
|
import { evaluateParkDisposition, type ParkDisposition } from "./worker-waits.ts";
|
|
29
|
+
import { reconcileRun, type ProcessProbe, type ReconcileResult } from "./health.ts";
|
|
29
30
|
|
|
30
31
|
export interface FinalizeHooks {
|
|
32
|
+
/** Recovery proved the original writer gone; the exit observer was lost. */
|
|
33
|
+
recoveredWriterExit?: boolean;
|
|
31
34
|
renderWidget?: () => void;
|
|
32
35
|
notify?: (message: string, level: "info" | "warning") => void;
|
|
33
36
|
sendMessage?: (
|
|
@@ -45,6 +48,20 @@ export interface FinalizeResult {
|
|
|
45
48
|
park?: ParkDisposition;
|
|
46
49
|
}
|
|
47
50
|
|
|
51
|
+
/** The current management owner calls this only for an interrupted, unobserved writer. */
|
|
52
|
+
export function reconcileInterruptedRun(meta: RunMeta, probe: ProcessProbe, now: number, hooks: FinalizeHooks = {}): {
|
|
53
|
+
reconciliation: ReconcileResult; finalization?: FinalizeResult;
|
|
54
|
+
} {
|
|
55
|
+
const reconciliation = reconcileRun(meta, probe, now);
|
|
56
|
+
if ((meta.status === "running" || meta.status === "orphaned") && meta.supervisionInterruptedAt !== undefined && reconciliation.status === "lost") {
|
|
57
|
+
const run = parseRunForLifecycle(meta.id);
|
|
58
|
+
if (run.sawEnd && run.unmatchedToolCalls.length === 0) {
|
|
59
|
+
return { reconciliation, finalization: finalizeRun(meta.id, null, { ...hooks, recoveredWriterExit: true }) };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return { reconciliation };
|
|
63
|
+
}
|
|
64
|
+
|
|
48
65
|
/**
|
|
49
66
|
* Finalize a run once its child exits. Idempotent: a run already marked
|
|
50
67
|
* terminal is left alone. Persists lifecycle classification + failureReason
|
|
@@ -92,7 +109,10 @@ export function finalizeRun(
|
|
|
92
109
|
// and the recorded wait is held for its owner.
|
|
93
110
|
const park = evaluateParkDisposition({
|
|
94
111
|
runId: id,
|
|
95
|
-
|
|
112
|
+
// Preserve a verified staged checkpoint for post-restart park recovery.
|
|
113
|
+
// The coordinator still requires writer-exit and lease-release proof.
|
|
114
|
+
cleanExit: (code === 0 || (code === null && hooks.recoveredWriterExit === true))
|
|
115
|
+
&& completed && !outcome.incomplete && !outcome.diagnostics.modelError,
|
|
96
116
|
});
|
|
97
117
|
const parked = park.parked && park.record !== undefined;
|
|
98
118
|
if (parked && park.record) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-subagents/goal-provider.ts. Do not edit directly.
|
|
2
|
+
import { activateWorkObservation, hasWorkObservationContext, workObservation, onWorkObservation } from "./work-observation.domain.mjs";
|
|
2
3
|
import { belongsToOrigin, effectiveStatus, isPendingPark, listMetasForParent, onMetaChanged, readParkRecord, } from "./registry.domain.mjs";
|
|
3
4
|
const GOAL_READY_EVENT = "pi-better-goal:ready";
|
|
4
5
|
const GOAL_REGISTER_PROVIDER_EVENT = "pi-better-goal:register-provider";
|
|
@@ -30,13 +31,40 @@ function parkActivity(meta) {
|
|
|
30
31
|
...(record.resumedBy ? { resumedBy: record.resumedBy } : {}),
|
|
31
32
|
};
|
|
32
33
|
}
|
|
34
|
+
function observedActivity(observed, ctx) {
|
|
35
|
+
if (observed?.status !== "ready")
|
|
36
|
+
throw new Error(observed?.reason ?? "Subagent activity is unverified");
|
|
37
|
+
return {
|
|
38
|
+
providerId: "subagents", label: "Subagents", nextDeadline: observed.nextDeadline ?? null,
|
|
39
|
+
items: observed.rows.filter((row) => !ctx || (belongsToOrigin(row.meta, { cwd: ctx.cwd, sessionId: ctx.sessionManager.getSessionId() }) &&
|
|
40
|
+
(!row.meta.callbackOrigin?.branchId || ctx.sessionManager.getBranch().some(entry => entry.id === row.meta.callbackOrigin.branchId)))).map((row) => {
|
|
41
|
+
const status = row.assignment.state;
|
|
42
|
+
const active = status === "running" || status === "waiting";
|
|
43
|
+
return { id: row.meta.id, label: row.meta.name, status, active, terminal: !active,
|
|
44
|
+
attention: !active && status !== "completed", unhealthy: row.meta.status === "orphaned",
|
|
45
|
+
startedAt: row.meta.startedAt, endedAt: row.meta.endedAt,
|
|
46
|
+
details: { assignment: row.assignment, sourceRevision: row.sourceRevision } };
|
|
47
|
+
}),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
33
50
|
export function registerSubagentsGoalProvider(pi) {
|
|
34
51
|
const emitProvider = () => {
|
|
35
52
|
pi.events?.emit(GOAL_REGISTER_PROVIDER_EVENT, {
|
|
36
53
|
id: "subagents",
|
|
37
54
|
label: "Subagents",
|
|
38
55
|
scope: "session",
|
|
39
|
-
|
|
56
|
+
activityVersion: 1,
|
|
57
|
+
getActivity: (ctx, options) => {
|
|
58
|
+
const observed = workObservation();
|
|
59
|
+
if (!observed && options?.cachedOnly) {
|
|
60
|
+
return { providerId: "subagents", coverage: "unverified", items: [], nextDeadline: null };
|
|
61
|
+
}
|
|
62
|
+
if (!observed && hasWorkObservationContext()) {
|
|
63
|
+
return activateWorkObservation().then(() => observedActivity(workObservation(), ctx));
|
|
64
|
+
}
|
|
65
|
+
if (observed) {
|
|
66
|
+
return observedActivity(observed, ctx);
|
|
67
|
+
}
|
|
40
68
|
let sessionId;
|
|
41
69
|
try {
|
|
42
70
|
sessionId = ctx?.sessionManager?.getSessionId();
|
|
@@ -47,9 +75,11 @@ export function registerSubagentsGoalProvider(pi) {
|
|
|
47
75
|
const origin = ctx ? { cwd: ctx.cwd, sessionId } : undefined;
|
|
48
76
|
return {
|
|
49
77
|
providerId: "subagents",
|
|
78
|
+
nextDeadline: null,
|
|
50
79
|
label: "Subagents",
|
|
51
80
|
items: listMetasForParent(process.pid)
|
|
52
81
|
.filter((meta) => !origin || belongsToOrigin(meta, origin))
|
|
82
|
+
.filter((meta) => !ctx || !meta.callbackOrigin?.branchId || ctx.sessionManager.getBranch().some(entry => entry.id === meta.callbackOrigin?.branchId))
|
|
53
83
|
.map((meta) => {
|
|
54
84
|
const status = effectiveStatus(meta);
|
|
55
85
|
const active = status === "running" || status === "orphaned";
|
|
@@ -72,7 +102,19 @@ export function registerSubagentsGoalProvider(pi) {
|
|
|
72
102
|
}),
|
|
73
103
|
};
|
|
74
104
|
},
|
|
75
|
-
onActivityChanged:
|
|
105
|
+
onActivityChanged: (notify, ctx) => {
|
|
106
|
+
const offObservation = onWorkObservation(notify);
|
|
107
|
+
const offMeta = onMetaChanged((meta) => {
|
|
108
|
+
if (ctx && meta) {
|
|
109
|
+
if (!belongsToOrigin(meta, { cwd: ctx.cwd, sessionId: ctx.sessionManager.getSessionId() }))
|
|
110
|
+
return;
|
|
111
|
+
if (meta.callbackOrigin?.branchId && !ctx.sessionManager.getBranch().some(entry => entry.id === meta.callbackOrigin?.branchId))
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
notify();
|
|
115
|
+
});
|
|
116
|
+
return () => { offObservation(); offMeta(); };
|
|
117
|
+
},
|
|
76
118
|
});
|
|
77
119
|
};
|
|
78
120
|
if (!goalReadySubscriptions.has(pi)) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { activateWorkObservation, hasWorkObservationContext, workObservation, onWorkObservation } from "./work-observation.ts";
|
|
2
3
|
import {
|
|
3
4
|
belongsToOrigin,
|
|
4
5
|
effectiveStatus,
|
|
@@ -38,13 +39,42 @@ function parkActivity(meta: Parameters<typeof effectiveStatus>[0]): Record<strin
|
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
function observedActivity(observed: any, ctx?: ExtensionContext) {
|
|
43
|
+
if (observed?.status !== "ready") throw new Error(observed?.reason ?? "Subagent activity is unverified");
|
|
44
|
+
return {
|
|
45
|
+
providerId: "subagents", label: "Subagents", nextDeadline: observed.nextDeadline ?? null,
|
|
46
|
+
items: observed.rows.filter((row: any) => !ctx || (
|
|
47
|
+
belongsToOrigin(row.meta, { cwd: ctx.cwd, sessionId: ctx.sessionManager.getSessionId() }) &&
|
|
48
|
+
(!row.meta.callbackOrigin?.branchId || ctx.sessionManager.getBranch().some(entry => entry.id === row.meta.callbackOrigin.branchId))
|
|
49
|
+
)).map((row: any) => {
|
|
50
|
+
const status = row.assignment.state;
|
|
51
|
+
const active = status === "running" || status === "waiting";
|
|
52
|
+
return { id: row.meta.id, label: row.meta.name, status, active, terminal: !active,
|
|
53
|
+
attention: !active && status !== "completed", unhealthy: row.meta.status === "orphaned",
|
|
54
|
+
startedAt: row.meta.startedAt, endedAt: row.meta.endedAt,
|
|
55
|
+
details: { assignment: row.assignment, sourceRevision: row.sourceRevision } };
|
|
56
|
+
}),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
41
60
|
export function registerSubagentsGoalProvider(pi: ExtensionAPI): void {
|
|
42
61
|
const emitProvider = (): void => {
|
|
43
62
|
pi.events?.emit(GOAL_REGISTER_PROVIDER_EVENT, {
|
|
44
63
|
id: "subagents",
|
|
45
64
|
label: "Subagents",
|
|
46
65
|
scope: "session",
|
|
47
|
-
|
|
66
|
+
activityVersion: 1,
|
|
67
|
+
getActivity: (ctx?: ExtensionContext, options?: { cachedOnly?: boolean }) => {
|
|
68
|
+
const observed = workObservation();
|
|
69
|
+
if (!observed && options?.cachedOnly) {
|
|
70
|
+
return { providerId: "subagents", coverage: "unverified", items: [], nextDeadline: null };
|
|
71
|
+
}
|
|
72
|
+
if (!observed && hasWorkObservationContext()) {
|
|
73
|
+
return activateWorkObservation().then(() => observedActivity(workObservation(), ctx));
|
|
74
|
+
}
|
|
75
|
+
if (observed) {
|
|
76
|
+
return observedActivity(observed, ctx);
|
|
77
|
+
}
|
|
48
78
|
let sessionId: string | undefined;
|
|
49
79
|
try {
|
|
50
80
|
sessionId = ctx?.sessionManager?.getSessionId();
|
|
@@ -54,9 +84,11 @@ export function registerSubagentsGoalProvider(pi: ExtensionAPI): void {
|
|
|
54
84
|
const origin = ctx ? { cwd: ctx.cwd, sessionId } : undefined;
|
|
55
85
|
return {
|
|
56
86
|
providerId: "subagents",
|
|
87
|
+
nextDeadline: null,
|
|
57
88
|
label: "Subagents",
|
|
58
89
|
items: listMetasForParent(process.pid)
|
|
59
90
|
.filter((meta) => !origin || belongsToOrigin(meta, origin))
|
|
91
|
+
.filter((meta) => !ctx || !meta.callbackOrigin?.branchId || ctx.sessionManager.getBranch().some(entry => entry.id === meta.callbackOrigin?.branchId))
|
|
60
92
|
.map((meta) => {
|
|
61
93
|
const status = effectiveStatus(meta);
|
|
62
94
|
const active = status === "running" || status === "orphaned";
|
|
@@ -79,7 +111,17 @@ export function registerSubagentsGoalProvider(pi: ExtensionAPI): void {
|
|
|
79
111
|
}),
|
|
80
112
|
};
|
|
81
113
|
},
|
|
82
|
-
onActivityChanged:
|
|
114
|
+
onActivityChanged: (notify: () => void, ctx?: ExtensionContext) => {
|
|
115
|
+
const offObservation = onWorkObservation(notify);
|
|
116
|
+
const offMeta = onMetaChanged((meta) => {
|
|
117
|
+
if (ctx && meta) {
|
|
118
|
+
if (!belongsToOrigin(meta, { cwd: ctx.cwd, sessionId: ctx.sessionManager.getSessionId() })) return;
|
|
119
|
+
if (meta.callbackOrigin?.branchId && !ctx.sessionManager.getBranch().some(entry => entry.id === meta.callbackOrigin?.branchId)) return;
|
|
120
|
+
}
|
|
121
|
+
notify();
|
|
122
|
+
});
|
|
123
|
+
return () => { offObservation(); offMeta(); };
|
|
124
|
+
},
|
|
83
125
|
});
|
|
84
126
|
};
|
|
85
127
|
if (!goalReadySubscriptions.has(pi)) {
|