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,7 +1,8 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-subagents/task-guard.ts. Do not edit directly.
|
|
2
2
|
/** Installed as the final inline extension by the trusted native launcher. */
|
|
3
3
|
import { SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
4
|
-
import {
|
|
4
|
+
import { deniedGitOperation, worktreeDenialText } from "./worktree-feedback.domain.mjs";
|
|
5
|
+
import { canonicalizePath, compileWritePolicy, describeSandboxSupport } from "./shared-sandbox-core.domain.mjs";
|
|
5
6
|
import { GUARDED_TASK_TOOLS, installTaskTools, TASK_BUILTINS } from "./shared-task-sandbox.domain.mjs";
|
|
6
7
|
import { parseTaskPolicy, RUN_APPLICATION, selectTaskTools } from "./task-policy.domain.mjs";
|
|
7
8
|
import { SANDBOX_POLICY_CHANNEL, SANDBOX_POLICY_REQUEST_CHANNEL } from "./permission-policy.domain.mjs";
|
|
@@ -62,6 +63,18 @@ export default function taskGuard(pi, input, fatal, ownedTools = false) {
|
|
|
62
63
|
policy: Object.freeze({ writableRoot: policy.root, home: policy.home, permissions: policy.permissions, denyWrite: policy.denyWrite,
|
|
63
64
|
runtimeCompatibility: true, runtimeWrite: Object.freeze([policy.scratch]) }),
|
|
64
65
|
});
|
|
66
|
+
if (policy.worktreeGitDir) {
|
|
67
|
+
const gitDir = policy.worktreeGitDir;
|
|
68
|
+
const compiled = compileWritePolicy(plan.policy);
|
|
69
|
+
pi.on("tool_result", event => {
|
|
70
|
+
const operation = deniedGitOperation(event, gitDir, compiled);
|
|
71
|
+
if (operation)
|
|
72
|
+
return {
|
|
73
|
+
content: [...event.content, { type: "text", text: worktreeDenialText(operation, policy.root) }],
|
|
74
|
+
details: { ...(event.details && typeof event.details === "object" ? event.details : {}), deniedWorktreeGitOperation: operation },
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
}
|
|
65
78
|
const controller = Object.freeze({ requireLaunchPlan: () => plan });
|
|
66
79
|
let shellPath;
|
|
67
80
|
let currentCwd = process.cwd();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** Installed as the final inline extension by the trusted native launcher. */
|
|
2
2
|
import { SettingsManager, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
|
-
import {
|
|
3
|
+
import { deniedGitOperation, worktreeDenialText } from "./worktree-feedback.ts";
|
|
4
|
+
import { canonicalizePath, compileWritePolicy, describeSandboxSupport } from "./shared-sandbox-core.ts";
|
|
4
5
|
import { GUARDED_TASK_TOOLS, installTaskTools, TASK_BUILTINS } from "./shared-task-sandbox.ts";
|
|
5
6
|
import { parseTaskPolicy, RUN_APPLICATION, selectTaskTools, type TaskPolicy } from "./task-policy.ts";
|
|
6
7
|
import { SANDBOX_POLICY_CHANNEL, SANDBOX_POLICY_REQUEST_CHANNEL } from "./permission-policy.ts";
|
|
@@ -51,6 +52,17 @@ export default function taskGuard(pi: ExtensionAPI, input: unknown, fatal: (erro
|
|
|
51
52
|
policy: Object.freeze({ writableRoot: policy.root, home: policy.home, permissions: policy.permissions, denyWrite: policy.denyWrite,
|
|
52
53
|
runtimeCompatibility: true, runtimeWrite: Object.freeze([policy.scratch]) }),
|
|
53
54
|
});
|
|
55
|
+
if (policy.worktreeGitDir) {
|
|
56
|
+
const gitDir = policy.worktreeGitDir;
|
|
57
|
+
const compiled = compileWritePolicy(plan.policy);
|
|
58
|
+
pi.on("tool_result", event => {
|
|
59
|
+
const operation = deniedGitOperation(event, gitDir, compiled);
|
|
60
|
+
if (operation) return {
|
|
61
|
+
content: [...event.content, {type: "text", text: worktreeDenialText(operation, policy.root)}],
|
|
62
|
+
details: { ...(event.details && typeof event.details === "object" ? event.details : {}), deniedWorktreeGitOperation: operation },
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}
|
|
54
66
|
const controller = Object.freeze({ requireLaunchPlan: () => plan });
|
|
55
67
|
let shellPath: string | undefined;
|
|
56
68
|
let currentCwd = process.cwd();
|
|
@@ -125,6 +125,7 @@ export function parseTaskPolicy(value) {
|
|
|
125
125
|
throw new Error("Invalid task sandbox extension tools.");
|
|
126
126
|
return Object.freeze({
|
|
127
127
|
version: 1, root: absolute("root"), home: absolute("home"), agentDir: absolute("agentDir"), profilePath: absolute("profilePath"), scratch: absolute("scratch"),
|
|
128
|
+
...(v.worktreeGitDir !== undefined ? { worktreeGitDir: absolute("worktreeGitDir") } : {}),
|
|
128
129
|
permissions: Object.freeze({
|
|
129
130
|
projectFiles: p.projectFiles, outsideProject: p.outsideProject, storedCredentials: p.storedCredentials,
|
|
130
131
|
commands: p.commands, network: p.network,
|
|
@@ -172,7 +173,7 @@ export function prepareTaskRuntime(options) {
|
|
|
172
173
|
const scratch = createTaskScratch();
|
|
173
174
|
const policy = parseTaskPolicy({
|
|
174
175
|
version: 1, root, home, agentDir, profilePath: join(controlDir, "task.sb"), scratch: scratch.path,
|
|
175
|
-
permissions,
|
|
176
|
+
permissions, worktreeGitDir: options.worktreeGitDir,
|
|
176
177
|
denyWrite: [...new Set([
|
|
177
178
|
...(options.capturedDenyWrite ?? []),
|
|
178
179
|
controlDir, scratch.anchor, agentDir, ...runtimeDirectories, ...(options.runtimeRoots ?? []), join(root, ".pi"),
|
|
@@ -184,7 +185,7 @@ export function prepareTaskRuntime(options) {
|
|
|
184
185
|
tools: options.tools,
|
|
185
186
|
applyPatch: options.applyPatch === true,
|
|
186
187
|
operationBridge: options.tools.some(name => OPERATION_BRIDGE_TOOL_NAMES.includes(name)) &&
|
|
187
|
-
(options.extensionPaths ?? []).some(path => canonicalizePath(path) === canonicalizePath(fileURLToPath(new URL("./child-operations.ts", import.meta.url)))),
|
|
188
|
+
(options.extensionPaths ?? []).some(path => canonicalizePath(path) === canonicalizePath(options.operationBridgePath ?? fileURLToPath(new URL("./child-operations.ts", import.meta.url)))),
|
|
188
189
|
extensionTools: (options.extensionTools ?? []).map((tool) => ({ ...tool, root: canonicalizePath(tool.root) })),
|
|
189
190
|
});
|
|
190
191
|
compileWritePolicy({ writableRoot: root, home, permissions: policy.permissions, denyWrite: policy.denyWrite, runtimeCompatibility: true });
|
|
@@ -69,6 +69,8 @@ export type TaskPermissions = Readonly<SandboxPermissions> & CommandSettings;
|
|
|
69
69
|
export type TaskPolicy = Readonly<{
|
|
70
70
|
version: 1;
|
|
71
71
|
root: string;
|
|
72
|
+
/** Actual linked checkout metadata recorded by the launcher. */
|
|
73
|
+
worktreeGitDir?: string;
|
|
72
74
|
home: string;
|
|
73
75
|
agentDir: string;
|
|
74
76
|
profilePath: string;
|
|
@@ -154,6 +156,7 @@ export function parseTaskPolicy(value: unknown): TaskPolicy { if (!value || t
|
|
|
154
156
|
})) throw new Error("Invalid task sandbox extension tools.");
|
|
155
157
|
return Object.freeze({
|
|
156
158
|
version: 1, root: absolute("root"), home: absolute("home"), agentDir: absolute("agentDir"), profilePath: absolute("profilePath"), scratch: absolute("scratch"),
|
|
159
|
+
...(v.worktreeGitDir !== undefined ? { worktreeGitDir: absolute("worktreeGitDir") } : {}),
|
|
157
160
|
permissions: Object.freeze({
|
|
158
161
|
projectFiles: p.projectFiles, outsideProject: p.outsideProject, storedCredentials: p.storedCredentials,
|
|
159
162
|
commands: p.commands, network: p.network,
|
|
@@ -175,6 +178,9 @@ export function prepareTaskRuntime(options: {
|
|
|
175
178
|
root: string; controlDir: string; tools: readonly string[]; piBin?: string;
|
|
176
179
|
permissions?: SandboxPermissions & Partial<CommandSettings>; extensionPaths?: readonly string[]; runtimeRoots?: readonly string[];
|
|
177
180
|
capturedDenyWrite?: readonly string[];
|
|
181
|
+
worktreeGitDir?: string;
|
|
182
|
+
/** Trusted launcher-selected bridge from the pinned worker release. */
|
|
183
|
+
operationBridgePath?: string;
|
|
178
184
|
applyPatch?: boolean; extensionTools?: readonly TaskExtensionTool[];
|
|
179
185
|
}): { file: string; fileArgs: string[]; policy: TaskPolicy; policyPath: string } {
|
|
180
186
|
if (typeof PiCodingAgent.getAgentDir !== "function" || typeof PiCodingAgent.getPackageDir !== "function") {
|
|
@@ -204,7 +210,7 @@ export function prepareTaskRuntime(options: {
|
|
|
204
210
|
const scratch = createTaskScratch();
|
|
205
211
|
const policy = parseTaskPolicy({
|
|
206
212
|
version: 1, root, home, agentDir, profilePath: join(controlDir, "task.sb"), scratch: scratch.path,
|
|
207
|
-
permissions,
|
|
213
|
+
permissions, worktreeGitDir: options.worktreeGitDir,
|
|
208
214
|
denyWrite: [...new Set([
|
|
209
215
|
...(options.capturedDenyWrite ?? []),
|
|
210
216
|
controlDir, scratch.anchor, agentDir, ...runtimeDirectories, ...(options.runtimeRoots ?? []), join(root, ".pi"),
|
|
@@ -216,7 +222,7 @@ export function prepareTaskRuntime(options: {
|
|
|
216
222
|
tools: options.tools,
|
|
217
223
|
applyPatch: options.applyPatch === true,
|
|
218
224
|
operationBridge: options.tools.some(name => (OPERATION_BRIDGE_TOOL_NAMES as readonly string[]).includes(name)) &&
|
|
219
|
-
(options.extensionPaths ?? []).some(path => canonicalizePath(path) === canonicalizePath(fileURLToPath(new URL("./child-operations.ts", import.meta.url)))),
|
|
225
|
+
(options.extensionPaths ?? []).some(path => canonicalizePath(path) === canonicalizePath(options.operationBridgePath ?? fileURLToPath(new URL("./child-operations.ts", import.meta.url)))),
|
|
220
226
|
extensionTools: (options.extensionTools ?? []).map((tool) => ({ ...tool, root: canonicalizePath(tool.root) })),
|
|
221
227
|
});
|
|
222
228
|
compileWritePolicy({ writableRoot: root, home, permissions: policy.permissions, denyWrite: policy.denyWrite, runtimeCompatibility: true });
|
|
@@ -235,7 +235,7 @@ function isProgressResult(name, command, afterFailure, novel) {
|
|
|
235
235
|
/** Cheap pre-filter: only these rows can change progress state. */
|
|
236
236
|
export function isProgressRelevantLine(line) {
|
|
237
237
|
const head = line.slice(0, 160);
|
|
238
|
-
return head.includes('"tool_execution_start"') || head.includes('"message_end"');
|
|
238
|
+
return head.includes('"tool_execution_start"') || head.includes('"tool_execution_end"') || head.includes('"message_end"');
|
|
239
239
|
}
|
|
240
240
|
/** Fold one parsed child event into the progress state. */
|
|
241
241
|
export function foldProgress(state, event) {
|
|
@@ -276,6 +276,15 @@ export function foldProgress(state, event) {
|
|
|
276
276
|
});
|
|
277
277
|
return;
|
|
278
278
|
}
|
|
279
|
+
if (type === "tool_execution_end" && typeof event.parentToolCallId === "string") {
|
|
280
|
+
// Nested calls do not get a transcript toolResult. The outer call still
|
|
281
|
+
// owns progress accounting through its timestamped result message.
|
|
282
|
+
const id = event.toolCallId;
|
|
283
|
+
if (typeof id === "string" && state.open.delete(id) && state.open.size === 0) {
|
|
284
|
+
state.inFlightSince = undefined;
|
|
285
|
+
}
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
279
288
|
if (type !== "message_end")
|
|
280
289
|
return;
|
|
281
290
|
const message = event.message;
|
|
@@ -350,7 +350,7 @@ function isProgressResult(name: string, command: string | undefined, afterFailur
|
|
|
350
350
|
/** Cheap pre-filter: only these rows can change progress state. */
|
|
351
351
|
export function isProgressRelevantLine(line: string): boolean {
|
|
352
352
|
const head = line.slice(0, 160);
|
|
353
|
-
return head.includes('"tool_execution_start"') || head.includes('"message_end"');
|
|
353
|
+
return head.includes('"tool_execution_start"') || head.includes('"tool_execution_end"') || head.includes('"message_end"');
|
|
354
354
|
}
|
|
355
355
|
|
|
356
356
|
/** Fold one parsed child event into the progress state. */
|
|
@@ -390,6 +390,15 @@ export function foldProgress(state: ProgressState, event: Record<string, unknown
|
|
|
390
390
|
});
|
|
391
391
|
return;
|
|
392
392
|
}
|
|
393
|
+
if (type === "tool_execution_end" && typeof event.parentToolCallId === "string") {
|
|
394
|
+
// Nested calls do not get a transcript toolResult. The outer call still
|
|
395
|
+
// owns progress accounting through its timestamped result message.
|
|
396
|
+
const id = event.toolCallId;
|
|
397
|
+
if (typeof id === "string" && state.open.delete(id) && state.open.size === 0) {
|
|
398
|
+
state.inFlightSince = undefined;
|
|
399
|
+
}
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
393
402
|
if (type !== "message_end") return;
|
|
394
403
|
const message = event.message as Record<string, unknown> | undefined;
|
|
395
404
|
const at = typeof message?.timestamp === "number" && Number.isFinite(message.timestamp) ? message.timestamp : undefined;
|
|
@@ -17,10 +17,9 @@
|
|
|
17
17
|
import { createHash } from "node:crypto";
|
|
18
18
|
import { assignmentFor, projectAssignment, createAssignmentProjector, withAssignmentObservations } from "./assignment-projection.mjs";
|
|
19
19
|
import { readMeta, listRunRecords, effectiveStatus, isFinalResultStatus } from "./registry.domain.mjs";
|
|
20
|
-
import { buildSubagentResultPayload } from "./finalization.domain.mjs";
|
|
21
20
|
import { stopRun } from "./stop.domain.mjs";
|
|
22
21
|
import { SUBAGENT_LIST_DEFAULT_LIMIT, SUBAGENT_LIST_MAX_LIMIT, SUBAGENT_LIST_STATUSES, collectSubagentList, formatSubagentListRow, listFolderScopeKey, normalizeSubagentListOptions, } from "./list.domain.mjs";
|
|
23
|
-
import { assembleOrphanedResult, assembleRunningResult, assembleSubagentListPayload, assembleSubagentOutput, assembleUnreadableMetadata, listIncidentCount, formatIncidentLabel, listRevisions, requestScopeKey, resolveActiveOrigin, resolveRunAccess, unknownRunError, } from "./output-payload.domain.mjs";
|
|
22
|
+
import { assembleOrphanedResult, assembleRunningResult, assembleSubagentListPayload, assembleSubagentOutput, assembleUnreadableMetadata, listIncidentCount, formatIncidentLabel, listRevisions, requestScopeKey, resolveActiveOrigin, resolveRunAccess, assembleSubagentResult, unknownRunError, } from "./output-payload.domain.mjs";
|
|
24
23
|
import { budgetFor, readOutputControls } from "./shared-log-utils.domain.mjs";
|
|
25
24
|
import { readRunFailures } from "./failures.domain.mjs";
|
|
26
25
|
import { actionablePermissionBlockers } from "./shared-failure-observations.domain.mjs";
|
|
@@ -465,7 +464,8 @@ export function subagentResultTool(Type, baseSession = {}) {
|
|
|
465
464
|
if (access.kind === "denied")
|
|
466
465
|
return subagentResultText(access.payload);
|
|
467
466
|
const meta = access.meta;
|
|
468
|
-
|
|
467
|
+
// A saved result remains readable after its row leaves the live observation.
|
|
468
|
+
const observed = access.retained ? undefined : await session.observeAssignment?.(meta.id);
|
|
469
469
|
const outcome = meta.assignment ? baseSession.inspectOutcome?.(meta, params, ctx) : undefined;
|
|
470
470
|
// Exact inspection has already checked recipient and read authority.
|
|
471
471
|
// Its immutable terminal record supersedes an older shared projection
|
|
@@ -497,11 +497,7 @@ export function subagentResultTool(Type, baseSession = {}) {
|
|
|
497
497
|
}
|
|
498
498
|
return resultText(assembleRunningResult(p.id, meta, p, scopeKey, healthLine));
|
|
499
499
|
}
|
|
500
|
-
|
|
501
|
-
if (body === null) {
|
|
502
|
-
return resultText(assembleRunningResult(p.id, meta, p, scopeKey, healthLine));
|
|
503
|
-
}
|
|
504
|
-
return resultText(body);
|
|
500
|
+
return resultText(assembleSubagentResult(p.id, meta, p, healthLine, scopeKey));
|
|
505
501
|
});
|
|
506
502
|
},
|
|
507
503
|
};
|
|
@@ -18,7 +18,6 @@ import { createHash } from "node:crypto";
|
|
|
18
18
|
import { assignmentFor, projectAssignment, createAssignmentProjector, withAssignmentObservations } from "./assignment-projection.mjs";
|
|
19
19
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
20
20
|
import { readMeta, listRunRecords, effectiveStatus, isFinalResultStatus, type RunCallbackOrigin, type RunMeta, type RunStatus } from "./registry.ts";
|
|
21
|
-
import { buildSubagentResultPayload } from "./finalization.ts";
|
|
22
21
|
import { stopRun } from "./stop.ts";
|
|
23
22
|
import {
|
|
24
23
|
SUBAGENT_LIST_DEFAULT_LIMIT,
|
|
@@ -41,6 +40,7 @@ import {
|
|
|
41
40
|
requestScopeKey,
|
|
42
41
|
resolveActiveOrigin,
|
|
43
42
|
resolveRunAccess,
|
|
43
|
+
assembleSubagentResult,
|
|
44
44
|
unknownRunError,
|
|
45
45
|
type SubagentToolSession,
|
|
46
46
|
} from "./output-payload.ts";
|
|
@@ -531,7 +531,8 @@ export function subagentResultTool(Type: TypeModule, baseSession: SubagentToolSe
|
|
|
531
531
|
}
|
|
532
532
|
if (access.kind === "denied") return subagentResultText(access.payload);
|
|
533
533
|
const meta = access.meta;
|
|
534
|
-
|
|
534
|
+
// A saved result remains readable after its row leaves the live observation.
|
|
535
|
+
const observed = access.retained ? undefined : await session.observeAssignment?.(meta.id);
|
|
535
536
|
const outcome = meta.assignment ? baseSession.inspectOutcome?.(meta, params as Record<string, unknown>, ctx) : undefined;
|
|
536
537
|
// Exact inspection has already checked recipient and read authority.
|
|
537
538
|
// Its immutable terminal record supersedes an older shared projection
|
|
@@ -563,11 +564,7 @@ export function subagentResultTool(Type: TypeModule, baseSession: SubagentToolSe
|
|
|
563
564
|
}
|
|
564
565
|
return resultText(assembleRunningResult(p.id, meta, p, scopeKey, healthLine));
|
|
565
566
|
}
|
|
566
|
-
|
|
567
|
-
if (body === null) {
|
|
568
|
-
return resultText(assembleRunningResult(p.id, meta, p, scopeKey, healthLine));
|
|
569
|
-
}
|
|
570
|
-
return resultText(body);
|
|
567
|
+
return resultText(assembleSubagentResult(p.id, meta, p, healthLine, scopeKey));
|
|
571
568
|
});
|
|
572
569
|
},
|
|
573
570
|
} as ToolDefinition;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { mkdirSync, readFileSync, realpathSync } from "node:fs";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
|
-
import {
|
|
5
|
+
import { connectWorkClient } from "./shared-work-client.mjs";
|
|
6
6
|
export const TERMINAL_NAVIGATOR_RETENTION_MS = 30_000;
|
|
7
7
|
let client;
|
|
8
8
|
let snapshot;
|
|
@@ -10,15 +10,25 @@ let context;
|
|
|
10
10
|
let connecting;
|
|
11
11
|
let collecting;
|
|
12
12
|
let collectingClient;
|
|
13
|
+
let collectionRetry;
|
|
14
|
+
let collectionFailures = 0;
|
|
13
15
|
let dirty = false;
|
|
14
16
|
let retry;
|
|
15
17
|
let backoff = 100;
|
|
16
18
|
let failure = "Shared runtime observation is connecting.";
|
|
17
19
|
let generation = 0;
|
|
20
|
+
let connectionAbort = new AbortController();
|
|
18
21
|
const details = new Map();
|
|
19
22
|
const pendingDetails = new Set();
|
|
20
23
|
let refresh = () => { };
|
|
24
|
+
const observationListeners = new Set();
|
|
25
|
+
export function onWorkObservation(notify) {
|
|
26
|
+
observationListeners.add(notify);
|
|
27
|
+
return () => { observationListeners.delete(notify); };
|
|
28
|
+
}
|
|
21
29
|
export function workObservation() { return snapshot; }
|
|
30
|
+
export function hasWorkObservationContext() { return context !== undefined; }
|
|
31
|
+
export function workObservationStarted() { return Boolean(connecting || client || retry || snapshot); }
|
|
22
32
|
export function workObservationFailure() { return snapshot?.reason ?? failure; }
|
|
23
33
|
function degraded(error) {
|
|
24
34
|
failure = String(error);
|
|
@@ -38,8 +48,11 @@ function reconnectLater(current) {
|
|
|
38
48
|
retry.unref?.();
|
|
39
49
|
backoff = Math.min(2000, backoff * 2);
|
|
40
50
|
}
|
|
41
|
-
// Every page is bounded;
|
|
51
|
+
// Every page is bounded; a conversation anchor fences collection across filtered queries.
|
|
42
52
|
async function collect(candidate, current) {
|
|
53
|
+
if (collectionRetry)
|
|
54
|
+
clearTimeout(collectionRetry);
|
|
55
|
+
collectionRetry = undefined;
|
|
43
56
|
dirty = true;
|
|
44
57
|
if (collecting && collectingClient === candidate)
|
|
45
58
|
return collecting;
|
|
@@ -51,25 +64,32 @@ async function collect(candidate, current) {
|
|
|
51
64
|
let completed = false;
|
|
52
65
|
for (let attempt = 0; attempt < 2 && !completed; attempt++) {
|
|
53
66
|
try {
|
|
67
|
+
const anchorScope = { ...context.origin, limit: 1 };
|
|
68
|
+
const anchor = await candidate.get(anchorScope);
|
|
54
69
|
const first = await candidate.get(scope);
|
|
55
70
|
if (current !== generation || candidate !== client)
|
|
56
71
|
return;
|
|
57
72
|
if (first.status === "rebuilding") {
|
|
58
73
|
snapshot = { ...first, rows: snapshot?.rows ?? [] };
|
|
59
74
|
refresh();
|
|
60
|
-
|
|
75
|
+
// A newer publication may already be owed while this page
|
|
76
|
+
// was in flight. Drain that demand, but never poll for it.
|
|
77
|
+
break;
|
|
61
78
|
}
|
|
62
79
|
const rows = [...first.rows];
|
|
63
80
|
let cursor = first.nextCursor;
|
|
64
81
|
while (cursor) {
|
|
65
82
|
const page = await candidate.get({ ...scope, cursor });
|
|
66
|
-
if (page.
|
|
83
|
+
if (page.scopeRevision !== first.scopeRevision || page.instanceId !== first.instanceId)
|
|
67
84
|
throw new Error("resync_required: active pages changed");
|
|
68
85
|
rows.push(...page.rows);
|
|
69
86
|
cursor = page.nextCursor;
|
|
70
87
|
}
|
|
71
|
-
|
|
72
|
-
|
|
88
|
+
// Cover the disconnect interval, not merely the last 30 s of
|
|
89
|
+
// worker time. The navigator starts its own visibility clock.
|
|
90
|
+
const endedAfter = Math.min(Date.now() - TERMINAL_NAVIGATOR_RETENTION_MS, snapshot?.observedAtLocal ?? Date.now());
|
|
91
|
+
const history = await candidate.get({ ...context.origin, active: false, endedAfter, limit: 200 });
|
|
92
|
+
if (history.instanceId !== first.instanceId)
|
|
73
93
|
throw new Error("resync_required: history changed");
|
|
74
94
|
if (current !== generation || candidate !== client)
|
|
75
95
|
return;
|
|
@@ -77,16 +97,34 @@ async function collect(candidate, current) {
|
|
|
77
97
|
let owedCursor;
|
|
78
98
|
do {
|
|
79
99
|
const page = await candidate.get({ ...context.origin, pendingRecipient: true, limit: 200, ...(owedCursor ? { cursor: owedCursor } : {}) });
|
|
80
|
-
if (page.
|
|
100
|
+
if (page.instanceId !== first.instanceId)
|
|
81
101
|
throw new Error("resync_required: recipient page changed");
|
|
82
102
|
owed.push(...page.rows);
|
|
83
103
|
owedCursor = page.nextCursor;
|
|
84
104
|
} while (owedCursor);
|
|
85
105
|
if (current !== generation || candidate !== client)
|
|
86
106
|
return;
|
|
87
|
-
const
|
|
88
|
-
|
|
107
|
+
const historyRows = [...history.rows];
|
|
108
|
+
let historyCursor = history.nextCursor;
|
|
109
|
+
while (historyCursor) {
|
|
110
|
+
const page = await candidate.get({ ...context.origin, active: false, endedAfter, limit: 200, cursor: historyCursor });
|
|
111
|
+
if (page.scopeRevision !== history.scopeRevision || page.instanceId !== first.instanceId)
|
|
112
|
+
throw new Error("resync_required: history pages changed");
|
|
113
|
+
historyRows.push(...page.rows);
|
|
114
|
+
historyCursor = page.nextCursor;
|
|
115
|
+
}
|
|
116
|
+
if (current !== generation || candidate !== client)
|
|
117
|
+
return;
|
|
118
|
+
const confirmed = await candidate.get(anchorScope);
|
|
119
|
+
if (current !== generation || candidate !== client)
|
|
120
|
+
return;
|
|
121
|
+
if (confirmed.instanceId !== anchor.instanceId || confirmed.scopeRevision !== anchor.scopeRevision)
|
|
122
|
+
throw new Error("resync_required: conversation changed during collection");
|
|
123
|
+
const allRows = [...new Map([...rows, ...historyRows, ...owed].map(row => [row.meta.id, row])).values()];
|
|
124
|
+
snapshot = { ...first, seq: anchor.seq, observedRevisionVector: anchor.observedRevisionVector, rows: allRows, nextCursor: undefined,
|
|
125
|
+
observedAtLocal: Date.now(),
|
|
89
126
|
totalMatching: first.totalMatching + history.totalMatching, activity: { active: rows.length } };
|
|
127
|
+
collectionFailures = 0;
|
|
90
128
|
completed = true;
|
|
91
129
|
refresh();
|
|
92
130
|
}
|
|
@@ -95,8 +133,21 @@ async function collect(candidate, current) {
|
|
|
95
133
|
return;
|
|
96
134
|
if (attempt === 1 || candidate.closed) {
|
|
97
135
|
degraded(error);
|
|
98
|
-
if (candidate.closed)
|
|
136
|
+
if (current !== generation || candidate !== client || candidate.closed)
|
|
99
137
|
return;
|
|
138
|
+
// Retry the outstanding notification after transient transport or
|
|
139
|
+
// consistency failures, even when the terminal source sends no more events.
|
|
140
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
141
|
+
if (!dirty && /^(?:runtime-(?:timeout|overloaded|unhealthy)|resync_required):/.test(message) && collectionFailures < 3) {
|
|
142
|
+
const wait = 100 * 2 ** collectionFailures++;
|
|
143
|
+
collectionRetry = setTimeout(() => {
|
|
144
|
+
collectionRetry = undefined;
|
|
145
|
+
if (current === generation && candidate === client && !candidate.closed)
|
|
146
|
+
void collect(candidate, current).catch(error => { if (current === generation && candidate === client)
|
|
147
|
+
degraded(error); });
|
|
148
|
+
}, wait);
|
|
149
|
+
collectionRetry.unref?.();
|
|
150
|
+
}
|
|
100
151
|
// A notification received during these page reads is
|
|
101
152
|
// still owed a coherent collection. Drain only that
|
|
102
153
|
// demand through the outer loop; do not start a poller.
|
|
@@ -111,6 +162,7 @@ async function collect(candidate, current) {
|
|
|
111
162
|
}
|
|
112
163
|
async function connectObservation(current) {
|
|
113
164
|
const saved = context;
|
|
165
|
+
const signal = connectionAbort.signal;
|
|
114
166
|
mkdirSync(saved.agentDir, { recursive: true, mode: 0o700 });
|
|
115
167
|
saved.agentDir = realpathSync(saved.agentDir);
|
|
116
168
|
let registration;
|
|
@@ -122,7 +174,7 @@ async function connectObservation(current) {
|
|
|
122
174
|
throw error;
|
|
123
175
|
const path = "./runtime-client/src/runtime/client.mjs";
|
|
124
176
|
const { ensureRuntime } = await import(path);
|
|
125
|
-
await ensureRuntime({ agentDir: saved.agentDir });
|
|
177
|
+
await ensureRuntime({ agentDir: saved.agentDir, signal });
|
|
126
178
|
registration = JSON.parse(readFileSync(join(saved.agentDir, "server-registration-v1.json"), "utf8"));
|
|
127
179
|
}
|
|
128
180
|
if (current !== generation)
|
|
@@ -130,11 +182,23 @@ async function connectObservation(current) {
|
|
|
130
182
|
if (registration.version !== 1 || registration.agentDir !== saved.agentDir)
|
|
131
183
|
throw new Error("Invalid canonical runtime registration");
|
|
132
184
|
client?.close();
|
|
133
|
-
const candidate =
|
|
185
|
+
const candidate = await connectWorkClient(join(registration.serverDir, "pi-server.sock"), saved.agentDir, [], {
|
|
186
|
+
signal,
|
|
187
|
+
recover: async ({ timeoutMs, signal }) => {
|
|
188
|
+
const path = "./runtime-client/src/runtime/client.mjs";
|
|
189
|
+
const { ensureRuntime } = await import(path);
|
|
190
|
+
await ensureRuntime({ agentDir: saved.agentDir, serverDir: registration.serverDir, timeoutMs, signal });
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
if (current !== generation) {
|
|
194
|
+
candidate.close();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
134
197
|
client = candidate;
|
|
135
198
|
candidate.onChange(() => {
|
|
136
199
|
if (current !== generation || candidate !== client)
|
|
137
200
|
return;
|
|
201
|
+
collectionFailures = 0;
|
|
138
202
|
if (candidate.closed) {
|
|
139
203
|
details.clear();
|
|
140
204
|
pendingDetails.clear();
|
|
@@ -145,7 +209,7 @@ async function connectObservation(current) {
|
|
|
145
209
|
void collect(candidate, current).catch(error => { if (current === generation)
|
|
146
210
|
degraded(error); });
|
|
147
211
|
});
|
|
148
|
-
await candidate.subscribe({ ...saved.origin,
|
|
212
|
+
await candidate.subscribe({ ...saved.origin, limit: 200 });
|
|
149
213
|
if (candidate.snapshot?.status === "rebuilding")
|
|
150
214
|
await new Promise((resolve, reject) => {
|
|
151
215
|
const timer = setTimeout(() => { stop(); reject(new Error("Runtime scope is still rebuilding; retry the observation.")); }, 5000);
|
|
@@ -167,11 +231,19 @@ async function connectObservation(current) {
|
|
|
167
231
|
retry = undefined;
|
|
168
232
|
}
|
|
169
233
|
}
|
|
170
|
-
export
|
|
234
|
+
export function configureWorkObservation(agentDir, origin, changed) {
|
|
171
235
|
stopWorkObservation();
|
|
172
|
-
const current = generation;
|
|
173
236
|
context = { agentDir, origin };
|
|
174
|
-
refresh =
|
|
237
|
+
refresh = () => {
|
|
238
|
+
changed();
|
|
239
|
+
for (const notify of observationListeners)
|
|
240
|
+
notify();
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
export async function activateWorkObservation() {
|
|
244
|
+
if (!context)
|
|
245
|
+
return;
|
|
246
|
+
const current = generation;
|
|
175
247
|
try {
|
|
176
248
|
await ensureObservation();
|
|
177
249
|
}
|
|
@@ -182,6 +254,10 @@ export async function startWorkObservation(agentDir, origin, changed) {
|
|
|
182
254
|
}
|
|
183
255
|
}
|
|
184
256
|
}
|
|
257
|
+
export async function startWorkObservation(agentDir, origin, changed) {
|
|
258
|
+
configureWorkObservation(agentDir, origin, changed);
|
|
259
|
+
await activateWorkObservation();
|
|
260
|
+
}
|
|
185
261
|
async function ensureObservation() {
|
|
186
262
|
if (connecting)
|
|
187
263
|
return connecting;
|
|
@@ -194,13 +270,16 @@ async function ensureObservation() {
|
|
|
194
270
|
return connecting;
|
|
195
271
|
}
|
|
196
272
|
async function query(scope) {
|
|
273
|
+
const current = generation;
|
|
197
274
|
for (let attempt = 0;; attempt++) {
|
|
198
275
|
try {
|
|
199
276
|
await ensureObservation();
|
|
277
|
+
if (current !== generation)
|
|
278
|
+
throw new Error("runtime-unavailable: observation closed");
|
|
200
279
|
return await client.get(scope);
|
|
201
280
|
}
|
|
202
281
|
catch (error) {
|
|
203
|
-
if ((client && !client.closed) || attempt === 1)
|
|
282
|
+
if (current !== generation || (client && !client.closed) || attempt === 1)
|
|
204
283
|
throw error;
|
|
205
284
|
}
|
|
206
285
|
}
|
|
@@ -216,6 +295,12 @@ export async function observedList(scope) { return query(scope); }
|
|
|
216
295
|
export function stopWorkObservation() {
|
|
217
296
|
generation++;
|
|
218
297
|
context = undefined;
|
|
298
|
+
if (collectionRetry)
|
|
299
|
+
clearTimeout(collectionRetry);
|
|
300
|
+
collectionRetry = undefined;
|
|
301
|
+
collectionFailures = 0;
|
|
302
|
+
connectionAbort.abort();
|
|
303
|
+
connectionAbort = new AbortController();
|
|
219
304
|
if (retry)
|
|
220
305
|
clearTimeout(retry);
|
|
221
306
|
retry = undefined;
|