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,19 +1,41 @@
|
|
|
1
1
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { truncateToWidth as piTruncateToWidth, visibleWidth as piVisibleWidth } from "@earendil-works/pi-tui";
|
|
3
|
+
import { readHarnessSetting, updateHarnessSetting } from "./shared-harness-settings.ts";
|
|
3
4
|
import type { Component } from "@earendil-works/pi-tui";
|
|
4
5
|
import { createRenderScheduler, type RenderScheduler } from "./shared-render-scheduler.ts";
|
|
5
|
-
import { setNavigatorPanel } from "./shared-navigator-panels.ts";
|
|
6
|
+
import { setNavigatorPanel, type NavigatorPanelLayout } from "./shared-navigator-panels.ts";
|
|
6
7
|
|
|
7
8
|
export default function navigatorExtension(): void {
|
|
8
9
|
// Internal shared package. Pi may scan its symlink in the extension directory
|
|
9
10
|
// for sibling relative imports; loading it directly should be harmless.
|
|
10
11
|
}
|
|
11
12
|
|
|
13
|
+
export type NavigatorView = "tree" | "flatten";
|
|
14
|
+
export function getNavigatorView(): NavigatorView { return state().view ?? "flatten"; }
|
|
15
|
+
export function loadNavigatorView(): void {
|
|
16
|
+
const value = readHarnessSetting("navigatorView");
|
|
17
|
+
state().view = value === "tree" ? "tree" : "flatten";
|
|
18
|
+
}
|
|
19
|
+
export function setNavigatorView(value: string): void {
|
|
20
|
+
if (value !== "tree" && value !== "flatten") throw new Error("View must be tree or flatten.");
|
|
21
|
+
updateHarnessSetting("navigatorView", () => value);
|
|
22
|
+
state().view = value;
|
|
23
|
+
refreshBackgroundWorkNavigator();
|
|
24
|
+
}
|
|
25
|
+
|
|
12
26
|
export type BackgroundWorkStatusTone = "running" | "success" | "failed" | "warning" | "muted";
|
|
13
27
|
|
|
14
28
|
export type BackgroundWorkRow = {
|
|
15
29
|
providerId: string;
|
|
16
30
|
id: string;
|
|
31
|
+
/** Stable worker conversation identity, independent of execution attempts. */
|
|
32
|
+
agentId?: string;
|
|
33
|
+
parentAgentId?: string;
|
|
34
|
+
readOnly?: boolean;
|
|
35
|
+
treeDepth?: number;
|
|
36
|
+
lastChild?: boolean;
|
|
37
|
+
|
|
38
|
+
ownerGroupLabel?: string;
|
|
17
39
|
name?: string;
|
|
18
40
|
model?: string;
|
|
19
41
|
effort?: string;
|
|
@@ -70,9 +92,65 @@ export type BackgroundWorkProvider = {
|
|
|
70
92
|
close(id: string): BackgroundWorkCloseOutcome;
|
|
71
93
|
/** Return true when this detail handled the key. The navigator refreshes the sheet. */
|
|
72
94
|
handleDetailInput?(id: string, data: string): boolean;
|
|
95
|
+
/** An explicit navigator interaction may attach a deferred work subscription. */
|
|
96
|
+
onOpen?(): void;
|
|
73
97
|
onVisibleChanged?(notify: () => void): () => void;
|
|
74
98
|
};
|
|
75
99
|
|
|
100
|
+
/** UI time is independent of worker time; repeated refreshes never renew it. */
|
|
101
|
+
export function createTerminalRowRetention(retentionMs = 30_000) {
|
|
102
|
+
const held = new Map<string, { row: BackgroundWorkRow; until: number }>();
|
|
103
|
+
const dismissed = new Set<string>();
|
|
104
|
+
return {
|
|
105
|
+
clear() { held.clear(); dismissed.clear(); },
|
|
106
|
+
dismiss(id: string) { held.delete(id); dismissed.add(id); },
|
|
107
|
+
merge(rows: BackgroundWorkRow[], now: number): BackgroundWorkRow[] {
|
|
108
|
+
const result: BackgroundWorkRow[] = [];
|
|
109
|
+
const present = new Set(rows.map(row => row.id));
|
|
110
|
+
for (const id of dismissed) if (!present.has(id)) dismissed.delete(id);
|
|
111
|
+
for (const row of rows) {
|
|
112
|
+
if (dismissed.has(row.id)) continue;
|
|
113
|
+
const terminal = ["completed", "succeeded", "failed", "cancelled", "killed", "lost", "timed_out"].includes(row.status);
|
|
114
|
+
if (!terminal) { held.delete(row.id); result.push(row); continue; }
|
|
115
|
+
let entry = held.get(row.id);
|
|
116
|
+
if (!entry) { entry = {row, until: now + retentionMs}; held.set(row.id, entry); }
|
|
117
|
+
entry.row = {...row, expiresAt: entry.until};
|
|
118
|
+
if (now < entry.until) result.push(entry.row);
|
|
119
|
+
}
|
|
120
|
+
for (const [id, entry] of held) {
|
|
121
|
+
if (present.has(id)) continue;
|
|
122
|
+
if (now < entry.until) result.push(entry.row);
|
|
123
|
+
else held.delete(id);
|
|
124
|
+
}
|
|
125
|
+
return result;
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** A frontend-only diagnostic, never an execution record or authority to retry. */
|
|
131
|
+
export async function observeNavigatorLaunch<T>(ctx: ExtensionContext, providerId: string, key: string, name: string, launch: () => Promise<T>): Promise<T> {
|
|
132
|
+
const scope = JSON.stringify([ctx.cwd, ctx.sessionManager?.getSessionId?.()]);
|
|
133
|
+
const report = (error: unknown) => {
|
|
134
|
+
const s = state();
|
|
135
|
+
if (!isNavigatorUiAvailable(s.uiCtx) || s.observationScope !== scope) return;
|
|
136
|
+
const id = `launch-error-${key}`;
|
|
137
|
+
const primary = error instanceof Error ? error.message : String(error);
|
|
138
|
+
const failures = s.launchFailures ??= new Map();
|
|
139
|
+
const identity = rowKey(providerId, id);
|
|
140
|
+
failures.set(identity, {providerId, id, name, status: "failed", statusTone: "failed", kind: "launch-error", elapsed: "", primary,
|
|
141
|
+
secondary: "Launch failed or was not confirmed; inspect before retrying.", sortStartedAt: Date.now()});
|
|
142
|
+
// Diagnostics are session-local and bounded, including expired tombstones.
|
|
143
|
+
if (failures.size > 128) failures.delete(failures.keys().next().value!);
|
|
144
|
+
refreshBackgroundWorkNavigator();
|
|
145
|
+
};
|
|
146
|
+
try {
|
|
147
|
+
const result = await launch();
|
|
148
|
+
const response = result as {isError?: boolean; content?: {type: string; text?: string}[]};
|
|
149
|
+
if (response?.isError) report(response.content?.filter(item => item.type === "text").map(item => item.text).join("\n") || "Launch request failed");
|
|
150
|
+
return result;
|
|
151
|
+
} catch (error) { report(error); throw error; }
|
|
152
|
+
}
|
|
153
|
+
|
|
76
154
|
type HostDeps = {
|
|
77
155
|
createDefaultEditor: (tui: unknown, theme: unknown, keybindings: unknown) => unknown;
|
|
78
156
|
isOpenTrigger: (data: string) => boolean;
|
|
@@ -83,6 +161,10 @@ type HostDeps = {
|
|
|
83
161
|
|
|
84
162
|
type NavigatorState = {
|
|
85
163
|
providers: Map<string, BackgroundWorkProvider>;
|
|
164
|
+
view?: NavigatorView;
|
|
165
|
+
terminalRows?: Map<string, ReturnType<typeof createTerminalRowRetention>>;
|
|
166
|
+
launchFailures?: Map<string, BackgroundWorkRow>;
|
|
167
|
+
observationScope?: string;
|
|
86
168
|
registrationTokens?: Map<string, symbol>;
|
|
87
169
|
unsubscribers: Map<string, () => void>;
|
|
88
170
|
uiCtx?: ExtensionContext;
|
|
@@ -202,6 +284,10 @@ export function applyCloseConfirmFooter(ui: { setStatus(key: string, value: stri
|
|
|
202
284
|
export function ensureBackgroundWorkNavigator(ctx: ExtensionContext, deps: HostDeps, owner?: symbol): void {
|
|
203
285
|
if (!isNavigatorUiAvailable(ctx)) return;
|
|
204
286
|
const s = state();
|
|
287
|
+
if (s.view === undefined) { try { loadNavigatorView(); } catch { s.view = "flatten"; } }
|
|
288
|
+
const scope = JSON.stringify([ctx.cwd, ctx.sessionManager?.getSessionId?.()]);
|
|
289
|
+
if (s.observationScope !== scope) { s.terminalRows?.clear(); s.launchFailures?.clear(); }
|
|
290
|
+
s.observationScope = scope;
|
|
205
291
|
s.uiCtx = ctx;
|
|
206
292
|
s.uiOwner = owner;
|
|
207
293
|
s.deps = {
|
|
@@ -239,6 +325,9 @@ export function disposeBackgroundWorkNavigator(ctx?: ExtensionContext, owner?: s
|
|
|
239
325
|
stopMainListWidget();
|
|
240
326
|
const activeCtx = ctx ?? s.uiCtx;
|
|
241
327
|
s.uiCtx = undefined;
|
|
328
|
+
s.terminalRows?.clear();
|
|
329
|
+
s.launchFailures?.clear();
|
|
330
|
+
s.observationScope = undefined;
|
|
242
331
|
s.uiOwner = undefined;
|
|
243
332
|
if (activeCtx && isNavigatorUiAvailable(activeCtx)) {
|
|
244
333
|
try { setNavigatorPanel(activeCtx, MAIN_LIST_WIDGET_KEY, undefined); } catch { /* ignore */ }
|
|
@@ -328,7 +417,7 @@ function refreshMainListWidget(): void {
|
|
|
328
417
|
}
|
|
329
418
|
if (!s.mainListWidgetInstalled) {
|
|
330
419
|
try {
|
|
331
|
-
setNavigatorPanel(ctx, MAIN_LIST_WIDGET_KEY, (tui: { requestRender?(): void }, theme: unknown) => createMainListWidget(tui, theme, deps), { placement: "aboveEditor" });
|
|
420
|
+
setNavigatorPanel(ctx, MAIN_LIST_WIDGET_KEY, (tui: { requestRender?(): void }, theme: unknown, layout) => createMainListWidget(tui, theme, deps, layout), { placement: "aboveEditor" });
|
|
332
421
|
s.mainListWidgetInstalled = true;
|
|
333
422
|
} catch { /* ignore */ }
|
|
334
423
|
}
|
|
@@ -371,7 +460,7 @@ const BACK_TARGET = "back-to-main";
|
|
|
371
460
|
|
|
372
461
|
function highlightPointerTarget(theme: unknown, line: string, width: number): string {
|
|
373
462
|
const colors = theme as { bg?(color: string, value: string): string } | undefined;
|
|
374
|
-
return colors?.bg?.("selectedBg", line + " ".repeat(Math.max(0, width -
|
|
463
|
+
return colors?.bg?.("selectedBg", line + " ".repeat(Math.max(0, width - piVisibleWidth(line))))
|
|
375
464
|
?? themeFgFromTheme(theme)("accent", line);
|
|
376
465
|
}
|
|
377
466
|
|
|
@@ -406,7 +495,7 @@ function createPointerNavigation(targetAt: (event: WidgetMouseEvent) => string |
|
|
|
406
495
|
};
|
|
407
496
|
}
|
|
408
497
|
|
|
409
|
-
function createMainListWidget(tui: { requestRender?(): void }, theme: unknown, deps: HostDeps): MainListWidget {
|
|
498
|
+
function createMainListWidget(tui: { requestRender?(): void }, theme: unknown, deps: HostDeps, panelLayout: NavigatorPanelLayout = { availableRows: () => Infinity }): MainListWidget {
|
|
410
499
|
const requestRender = () => tui.requestRender?.();
|
|
411
500
|
state().mainListRequestRender = requestRender;
|
|
412
501
|
// navigatorId per rendered line, so a pointer row resolves by structure, never by row text.
|
|
@@ -439,8 +528,23 @@ function createMainListWidget(tui: { requestRender?(): void }, theme: unknown, d
|
|
|
439
528
|
if (hint) { layout.lines.push(deps.truncate(` ${hint}`, renderWidth(width))); layout.owners.push(undefined); }
|
|
440
529
|
lineWidth = renderWidth(width);
|
|
441
530
|
// The leading gap line belongs to the widget too, so its slot stays ownerless.
|
|
531
|
+
let rawLines = ["", ...layout.lines];
|
|
442
532
|
lineOwners = [undefined, ...layout.owners];
|
|
443
|
-
const
|
|
533
|
+
const budget = Math.max(0, Math.floor(panelLayout.availableRows()));
|
|
534
|
+
if (rawLines.length > budget) {
|
|
535
|
+
const selected = state().mainListFocused ? lineOwners.indexOf(state().mainListSelectedId) : -1;
|
|
536
|
+
const count = Math.max(0, budget - 1);
|
|
537
|
+
const start = selected >= 0 ? Math.max(0, Math.min(selected - Math.floor(count / 2), rawLines.length - count)) : 2;
|
|
538
|
+
rawLines = rawLines.slice(start, start + count);
|
|
539
|
+
lineOwners = lineOwners.slice(start, start + count);
|
|
540
|
+
const visible = new Set(lineOwners.filter(Boolean));
|
|
541
|
+
if (budget > 0) {
|
|
542
|
+
const hidden = rows.length - visible.size;
|
|
543
|
+
rawLines.push(deps.truncate(hidden ? ` +${hidden} tasks` : ` ${rows.length} tasks`, renderWidth(width)));
|
|
544
|
+
lineOwners.push(undefined);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
const lines = rawLines.map((line, index) =>
|
|
444
548
|
pointer.hovered && lineOwners[index] === pointer.hovered ? highlightPointerTarget(theme, line, lineWidth) : line);
|
|
445
549
|
state().lastMainListLines = lines;
|
|
446
550
|
return lines;
|
|
@@ -483,10 +587,14 @@ function listRows(now = Date.now()): InternalRow[] {
|
|
|
483
587
|
for (const provider of providers()) {
|
|
484
588
|
let providerRows: BackgroundWorkRow[] = [];
|
|
485
589
|
try { providerRows = provider.listRows(now) ?? []; } catch { providerRows = []; }
|
|
590
|
+
providerRows = [...providerRows, ...[...(state().launchFailures?.values() ?? [])].filter(row => row.providerId === provider.id)];
|
|
591
|
+
const retention = state().terminalRows ??= new Map();
|
|
592
|
+
if (!retention.has(provider.id)) retention.set(provider.id, createTerminalRowRetention());
|
|
593
|
+
if (isNavigatorUiAvailable(state().uiCtx)) providerRows = retention.get(provider.id)!.merge(providerRows, now);
|
|
486
594
|
const orderedProviderRows = [...providerRows].sort((a, b) => b.sortStartedAt - a.sortStartedAt || rowDisplayName(a).localeCompare(rowDisplayName(b)));
|
|
487
595
|
let showSection = orderedProviderRows.length > 0 || provider.parentRow !== undefined;
|
|
488
596
|
try { showSection = provider.showSection?.(orderedProviderRows, now) ?? showSection; } catch { showSection = false; }
|
|
489
|
-
if (!showSection) continue;
|
|
597
|
+
if (!showSection && !(getNavigatorView() === "tree" && provider.parentRow)) continue;
|
|
490
598
|
let parentRow: BackgroundWorkRow | null = null;
|
|
491
599
|
try { parentRow = provider.parentRow?.(now) ?? null; } catch { parentRow = null; }
|
|
492
600
|
if (parentRow) {
|
|
@@ -501,7 +609,48 @@ function listRows(now = Date.now()): InternalRow[] {
|
|
|
501
609
|
rows.push({ ...row, navigatorId: rowKey(provider.id, row.id), providerLabel: provider.label });
|
|
502
610
|
}
|
|
503
611
|
}
|
|
504
|
-
|
|
612
|
+
const conversations = mergeAgentAttempts(rows);
|
|
613
|
+
return getNavigatorView() === "tree" ? treeRows(conversations) : conversations;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/** A resumed execution is still the same agent in either layout. */
|
|
617
|
+
export function mergeAgentAttempts<T extends BackgroundWorkRow>(rows: T[]): T[] {
|
|
618
|
+
const latest = new Map<string, T>();
|
|
619
|
+
for (const row of rows) {
|
|
620
|
+
if (row.providerId !== "subagents" || !row.agentId) continue;
|
|
621
|
+
const previous = latest.get(row.agentId);
|
|
622
|
+
if (!previous || row.sortStartedAt > previous.sortStartedAt
|
|
623
|
+
|| (row.sortStartedAt === previous.sortStartedAt && row.id > previous.id)) latest.set(row.agentId, row);
|
|
624
|
+
}
|
|
625
|
+
return rows.filter(row => row.providerId !== "subagents" || !row.agentId || latest.get(row.agentId) === row);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/** Two levels only: agents are peers, tasks attach by captured conversation. */
|
|
629
|
+
export function treeRows<T extends BackgroundWorkRow>(rows: T[]): T[] {
|
|
630
|
+
const agents = new Map<string, T>();
|
|
631
|
+
for (const row of rows.filter(row => row.providerId === "subagents")) {
|
|
632
|
+
const key = row.agentId ?? row.id;
|
|
633
|
+
const prior = agents.get(key);
|
|
634
|
+
if (!prior || row.sortStartedAt > prior.sortStartedAt) agents.set(key, row);
|
|
635
|
+
}
|
|
636
|
+
const tasks = rows.filter(row => row.providerId !== "subagents");
|
|
637
|
+
const ordered = [...agents.entries()].sort(([a], [b]) => a === "main" ? -1 : b === "main" ? 1 : 0);
|
|
638
|
+
const result: T[] = [], attached = new Set<T>();
|
|
639
|
+
for (const [key, agent] of ordered) {
|
|
640
|
+
const children = tasks.filter(row => (row.parentAgentId ?? "main") === key);
|
|
641
|
+
result.push({...agent, treeDepth: 0});
|
|
642
|
+
children.forEach((row, i) => { result.push({...row, treeDepth: 1, lastChild: i === children.length - 1}); attached.add(row); });
|
|
643
|
+
}
|
|
644
|
+
// Never hide live work when its owner's observation has not arrived yet.
|
|
645
|
+
const missing = new Map<string, T[]>();
|
|
646
|
+
for (const row of tasks) if (!attached.has(row)) {
|
|
647
|
+
const key = row.parentAgentId ?? "main";
|
|
648
|
+
missing.set(key, [...(missing.get(key) ?? []), row]);
|
|
649
|
+
}
|
|
650
|
+
for (const [key, children] of missing) children.forEach((row, i) => result.push({...row,
|
|
651
|
+
treeDepth: 1, lastChild: i === children.length - 1,
|
|
652
|
+
ownerGroupLabel: i === 0 ? (key === "main" ? "Main" : `Agent ${key} · not running`) : undefined}));
|
|
653
|
+
return result;
|
|
505
654
|
}
|
|
506
655
|
|
|
507
656
|
function rowDisplayName(row: Pick<BackgroundWorkRow, "name" | "id">): string {
|
|
@@ -582,6 +731,15 @@ function buildMainListLayout(
|
|
|
582
731
|
lines.push(line);
|
|
583
732
|
owners.push(owner);
|
|
584
733
|
};
|
|
734
|
+
if (getNavigatorView() === "tree") {
|
|
735
|
+
push(providerGroupLabel("work", fg));
|
|
736
|
+
for (const row of rows) {
|
|
737
|
+
if (row.ownerGroupLabel) push(` ${dim(row.ownerGroupLabel, fg)}`);
|
|
738
|
+
push(formatMainListRow(row, options.focused === true && row.navigatorId === options.selectedId, fg, width), row.navigatorId);
|
|
739
|
+
}
|
|
740
|
+
push(""); push(shortcutsLine(options.focused === true, fg));
|
|
741
|
+
return {lines: lines.map(line => safeTruncate(line, width, truncate)), owners};
|
|
742
|
+
}
|
|
585
743
|
const grouped = new Map<string, InternalRow[]>();
|
|
586
744
|
for (const row of rows) {
|
|
587
745
|
const existing = grouped.get(row.providerLabel) ?? [];
|
|
@@ -606,8 +764,9 @@ function buildMainListLayout(
|
|
|
606
764
|
}
|
|
607
765
|
|
|
608
766
|
function shortcutsLine(focused: boolean, fg: (color: string, value: string) => string): string {
|
|
767
|
+
const selected = state().mainListRows?.find(row => row.navigatorId === state().mainListSelectedId);
|
|
609
768
|
const keys = focused
|
|
610
|
-
?
|
|
769
|
+
? `↑↓ switch · Enter detail${selected?.readOnly || selected?.parentRow ? "" : " · x stop"} · Esc unfocus`
|
|
611
770
|
: "← work navigator";
|
|
612
771
|
return dim(keys, fg);
|
|
613
772
|
}
|
|
@@ -618,22 +777,22 @@ function providerGroupLabel(label: string, fg: (color: string, value: string) =>
|
|
|
618
777
|
}
|
|
619
778
|
|
|
620
779
|
function formatMainListRow(row: InternalRow, selected: boolean, fg: (color: string, value: string) => string, width: number): string {
|
|
621
|
-
const prefix = selected ? fg("accent", "› ") : " ";
|
|
780
|
+
const prefix = (selected ? fg("accent", "› ") : " ") + (row.treeDepth === 1 ? dim(` ${row.lastChild ? "└─" : "├─"} `, fg) : "");
|
|
622
781
|
const name = row.name || row.id;
|
|
623
782
|
const indicator = statusIndicator(row);
|
|
624
783
|
const status = fg(indicator.color, indicator.glyph);
|
|
625
784
|
const elapsed = singleLine(row.elapsed || "-");
|
|
626
785
|
const available = Math.max(24, width || MAIN_LIST_FALLBACK_WIDTH);
|
|
627
|
-
const elapsedWidth = Math.min(Math.max(
|
|
786
|
+
const elapsedWidth = Math.min(Math.max(piVisibleWidth(elapsed), 4), 12);
|
|
628
787
|
const statusWidth = 2;
|
|
629
|
-
const leftPrefixWidth =
|
|
788
|
+
const leftPrefixWidth = piVisibleWidth(prefix) + statusWidth + 1;
|
|
630
789
|
const maxNameWidth = Math.max(8, Math.floor(available * 0.36));
|
|
631
790
|
const nameWidth = Math.max(8, Math.min(44, maxNameWidth, available - leftPrefixWidth - elapsedWidth - 10));
|
|
632
791
|
const rightWidth = Math.max(8, available - leftPrefixWidth - nameWidth - 1);
|
|
633
792
|
const summaryWidth = Math.max(1, rightWidth - elapsedWidth - 1);
|
|
634
793
|
const left = `${prefix}${fit(status, statusWidth)} ${fit(name, nameWidth)}`;
|
|
635
794
|
const right = `${dim(fitRight(rowSummary(row), summaryWidth), fg)} ${fitRight(elapsed, elapsedWidth)}`;
|
|
636
|
-
const gap = Math.max(1, available -
|
|
795
|
+
const gap = Math.max(1, available - piVisibleWidth(left) - piVisibleWidth(right));
|
|
637
796
|
return `${left}${" ".repeat(gap)}${right}`;
|
|
638
797
|
}
|
|
639
798
|
|
|
@@ -648,17 +807,21 @@ function statusGlyph(row: InternalRow): string {
|
|
|
648
807
|
function statusIndicator(row: InternalRow, now = Date.now()): { glyph: string; color: string } {
|
|
649
808
|
void now;
|
|
650
809
|
if (row.statusTone !== "running") return { glyph: statusGlyph(row), color: toneColor(row.statusTone, row.status) };
|
|
651
|
-
|
|
810
|
+
const glyph = row.treeDepth === 1 && row.providerId === "background-tasks" ? ">_" : RUNNING_DOT_GLYPH;
|
|
811
|
+
return { glyph, color: "accent" };
|
|
652
812
|
}
|
|
653
813
|
|
|
654
814
|
function mainListSignature(rows: InternalRow[], options: { selectedId?: string; focused?: boolean; closeHint?: string | null } = {}): string {
|
|
655
815
|
return JSON.stringify({
|
|
816
|
+
view: getNavigatorView(),
|
|
656
817
|
focused: options.focused === true,
|
|
657
818
|
closeHint: options.closeHint ?? null,
|
|
658
819
|
selectedId: options.focused === true ? options.selectedId ?? null : null,
|
|
659
820
|
rows: rows.map((row) => ({
|
|
660
821
|
navigatorId: row.navigatorId,
|
|
661
822
|
providerLabel: row.providerLabel,
|
|
823
|
+
parentAgentId: row.parentAgentId,
|
|
824
|
+
agentId: row.agentId,
|
|
662
825
|
parentRow: row.parentRow === true,
|
|
663
826
|
providerId: row.providerId,
|
|
664
827
|
id: row.id,
|
|
@@ -684,6 +847,9 @@ function stableFacts(facts: string[] | undefined): string[] {
|
|
|
684
847
|
}
|
|
685
848
|
|
|
686
849
|
function rowSummary(row: InternalRow): string {
|
|
850
|
+
if (getNavigatorView() === "tree" && row.providerId === "background-tasks") {
|
|
851
|
+
return [singleLine(row.status).replaceAll("_", " "), ...(row.facts ?? []).map(singleLine)].join(" · ");
|
|
852
|
+
}
|
|
687
853
|
if (row.providerId === "subagents") {
|
|
688
854
|
const attention = row.facts?.map(singleLine).filter(Boolean);
|
|
689
855
|
if (attention?.length) return `${singleLine(row.status)} · ${attention.join(" · ")}`;
|
|
@@ -713,15 +879,15 @@ function rowSummary(row: InternalRow): string {
|
|
|
713
879
|
|
|
714
880
|
function fit(value: string, width: number): string {
|
|
715
881
|
const str = singleLine(value);
|
|
716
|
-
const visible =
|
|
717
|
-
if (visible
|
|
882
|
+
const visible = piVisibleWidth(str);
|
|
883
|
+
if (visible > width) return piTruncateToWidth(str, width);
|
|
718
884
|
return str + " ".repeat(width - visible);
|
|
719
885
|
}
|
|
720
886
|
|
|
721
887
|
function fitRight(value: string, width: number): string {
|
|
722
888
|
const str = singleLine(value);
|
|
723
|
-
const visible =
|
|
724
|
-
if (visible
|
|
889
|
+
const visible = piVisibleWidth(str);
|
|
890
|
+
if (visible > width) return piTruncateToWidth(str, width);
|
|
725
891
|
return " ".repeat(width - visible) + str;
|
|
726
892
|
}
|
|
727
893
|
|
|
@@ -736,20 +902,33 @@ function prepareDetail(navigatorId: string, options?: {logTailLines?: number}):
|
|
|
736
902
|
|
|
737
903
|
function detailFor(navigatorId: string, now = Date.now(), options?: { logTailLines?: number }): BackgroundWorkDetail | null {
|
|
738
904
|
const { providerId, id } = splitRowKey(navigatorId);
|
|
905
|
+
const failed = state().launchFailures?.get(navigatorId);
|
|
906
|
+
if (failed) return {providerId, id, title: failed.name ?? "Launch failed", status: "failed", statusTone: "failed", metadata: [], evidence: {label: "Launch error", text: failed.primary}};
|
|
739
907
|
const provider = state().providers.get(providerId);
|
|
740
908
|
if (!provider) return null;
|
|
741
909
|
try { return provider.detail(id, now, options); } catch { return null; }
|
|
742
910
|
}
|
|
743
911
|
|
|
744
912
|
function closeFor(row: InternalRow): BackgroundWorkCloseOutcome {
|
|
745
|
-
if (row.parentRow) return { action: "not-closable", providerId: row.providerId, id: row.id };
|
|
913
|
+
if (row.parentRow || row.readOnly) return { action: "not-closable", providerId: row.providerId, id: row.id };
|
|
746
914
|
const provider = state().providers.get(row.providerId);
|
|
915
|
+
if (state().launchFailures?.delete(row.navigatorId)) {
|
|
916
|
+
state().terminalRows?.get(row.providerId)?.dismiss(row.id);
|
|
917
|
+
return {action: "dismissed", providerId: row.providerId, id: row.id};
|
|
918
|
+
}
|
|
747
919
|
if (!provider) return { action: "missing", providerId: row.providerId, id: row.id };
|
|
748
|
-
try {
|
|
920
|
+
try {
|
|
921
|
+
const outcome = provider.close(row.id);
|
|
922
|
+
if (["dismissed", "stopped-and-dismissed"].includes(outcome.action)
|
|
923
|
+
|| outcome.action === "requested" && ["completed", "succeeded", "failed", "cancelled", "killed", "lost", "timed_out"].includes(row.status)) {
|
|
924
|
+
state().terminalRows?.get(row.providerId)?.dismiss(row.id);
|
|
925
|
+
}
|
|
926
|
+
return outcome;
|
|
927
|
+
} catch { return { action: "missing", providerId: row.providerId, id: row.id }; }
|
|
749
928
|
}
|
|
750
929
|
|
|
751
930
|
function closeHintFor(row: InternalRow | undefined): string | null {
|
|
752
|
-
if (!row || row.parentRow) return null;
|
|
931
|
+
if (!row || row.parentRow || row.readOnly) return null;
|
|
753
932
|
const provider = state().providers.get(row.providerId);
|
|
754
933
|
if (!provider) return null;
|
|
755
934
|
try { return `${provider.armCloseLabel(row)} ${row.name || row.id}`; } catch { return null; }
|
|
@@ -775,28 +954,43 @@ function installNavigatorEditor(ui: any, deps: HostDeps): unknown {
|
|
|
775
954
|
|
|
776
955
|
function wrapEditor(inner: any, deps: HostDeps): unknown {
|
|
777
956
|
if (inner && typeof inner.render === "function") state().editorComponent = inner as Component;
|
|
957
|
+
const methods = new Map<PropertyKey, { original: Function; exposed: Function }>();
|
|
958
|
+
const replacements = new Map<PropertyKey, Function>();
|
|
778
959
|
const proxy: any = new Proxy(inner, {
|
|
779
960
|
get(target, prop) {
|
|
961
|
+
const value = Reflect.get(target, prop);
|
|
962
|
+
if (typeof value !== "function" || replacements.get(prop) === value) return value;
|
|
963
|
+
const cached = methods.get(prop);
|
|
964
|
+
if (cached && cached.original === value) return cached.exposed;
|
|
965
|
+
// Capture the method before another editor decorator replaces it.
|
|
966
|
+
// A decorator can retain this wrapper and call it as its delegate.
|
|
967
|
+
let exposed = value.bind(target);
|
|
780
968
|
if (prop === "handleInput") {
|
|
781
|
-
|
|
969
|
+
exposed = (data: string) => {
|
|
782
970
|
if (target.getText?.() === "" && handleMainListInput(data, deps)) {
|
|
783
971
|
return;
|
|
784
972
|
}
|
|
785
|
-
|
|
973
|
+
value.call(target, data);
|
|
786
974
|
};
|
|
787
975
|
}
|
|
788
|
-
if (prop === "render"
|
|
789
|
-
|
|
976
|
+
if (prop === "render") {
|
|
977
|
+
exposed = (...args: unknown[]) => {
|
|
790
978
|
const s = state();
|
|
791
979
|
if (s.editorFocusTarget === proxy) s.editorRenders = (s.editorRenders ?? 0) + 1;
|
|
792
|
-
return
|
|
980
|
+
return value.apply(target, args);
|
|
793
981
|
};
|
|
794
982
|
}
|
|
795
|
-
|
|
796
|
-
return
|
|
983
|
+
methods.set(prop, { original: value, exposed });
|
|
984
|
+
return exposed;
|
|
797
985
|
},
|
|
798
986
|
set(target, prop, value) {
|
|
799
|
-
|
|
987
|
+
const cached = methods.get(prop);
|
|
988
|
+
const restoring = cached !== undefined && value === cached.exposed;
|
|
989
|
+
if (!Reflect.set(target, prop, restoring ? cached.original : value)) return false;
|
|
990
|
+
// Preserve replacement identity so the installing decorator can undo it.
|
|
991
|
+
if (!restoring && typeof value === "function") replacements.set(prop, value);
|
|
992
|
+
else replacements.delete(prop);
|
|
993
|
+
return true;
|
|
800
994
|
},
|
|
801
995
|
});
|
|
802
996
|
// Pi mounts and focuses whatever the factory returns; an extension that
|
|
@@ -807,6 +1001,9 @@ function wrapEditor(inner: any, deps: HostDeps): unknown {
|
|
|
807
1001
|
|
|
808
1002
|
function handleMainListInput(data: string, deps: HostDeps): boolean {
|
|
809
1003
|
const s = state();
|
|
1004
|
+
if (!s.mainListFocused && deps.isOpenTrigger(data)) {
|
|
1005
|
+
for (const provider of s.providers.values()) provider.onOpen?.();
|
|
1006
|
+
}
|
|
810
1007
|
const rows = listRows();
|
|
811
1008
|
if (rows.length === 0) {
|
|
812
1009
|
// Every row is gone, but an overlay that lost focus may still be mounted: Esc still closes it.
|
|
@@ -876,7 +1073,7 @@ function dismissOverlay(): void {
|
|
|
876
1073
|
|
|
877
1074
|
function handleMainListCloseKey(): void {
|
|
878
1075
|
const row = selectedMainListRow();
|
|
879
|
-
if (!row || row.parentRow) return;
|
|
1076
|
+
if (!row || row.parentRow || row.readOnly) return;
|
|
880
1077
|
const s = state();
|
|
881
1078
|
const now = Date.now();
|
|
882
1079
|
const arm = s.mainListCloseArm;
|
|
@@ -917,6 +1114,7 @@ function openNavigator(): void {
|
|
|
917
1114
|
const ctx = s.uiCtx;
|
|
918
1115
|
const deps = s.deps;
|
|
919
1116
|
if (!ctx || !deps || !isNavigatorUiAvailable(ctx)) return;
|
|
1117
|
+
for (const provider of s.providers.values()) provider.onOpen?.();
|
|
920
1118
|
const rows = listRows();
|
|
921
1119
|
if (rows.length === 0) return;
|
|
922
1120
|
const selectedId = selectedMainListRow()?.navigatorId ?? rows[0]!.navigatorId;
|
|
@@ -991,6 +1189,8 @@ function createOverlayComponent(
|
|
|
991
1189
|
onClosed: () => void,
|
|
992
1190
|
initialDetailId: string,
|
|
993
1191
|
) {
|
|
1192
|
+
let editorRendersSeen = state().editorRenders ?? 0;
|
|
1193
|
+
let sawLiveEditor = liveEditorMounted(tui) === true;
|
|
994
1194
|
// The overlay only ever shows one row's detail; the rail below it is the list.
|
|
995
1195
|
const overlayState: OverlayState = { rows: initialRows, selected: 0 };
|
|
996
1196
|
let logTailRows: number = DEFAULT_LOG_TAIL_ROWS;
|
|
@@ -1113,7 +1313,7 @@ function createOverlayComponent(
|
|
|
1113
1313
|
|
|
1114
1314
|
function handleCloseKey(): void {
|
|
1115
1315
|
const row = selectedRow();
|
|
1116
|
-
if (!row || row.parentRow) return;
|
|
1316
|
+
if (!row || row.parentRow || row.readOnly) return;
|
|
1117
1317
|
const now = Date.now();
|
|
1118
1318
|
if (closeArm?.id === row.navigatorId && now >= closeArm.armedAt && now < closeArm.armedAt + CLOSE_ARM_MS) {
|
|
1119
1319
|
clearCloseArm();
|
|
@@ -1148,19 +1348,23 @@ function createOverlayComponent(
|
|
|
1148
1348
|
requestRender();
|
|
1149
1349
|
}
|
|
1150
1350
|
|
|
1151
|
-
let editorRendersSeen: number | undefined;
|
|
1152
1351
|
/**
|
|
1153
|
-
*
|
|
1154
|
-
*
|
|
1155
|
-
*
|
|
1156
|
-
* rendered since the previous overlay frame (Pi renders the editor before it composites overlays).
|
|
1352
|
+
* Close when a replacement editor takes over while the sheet is open (#332).
|
|
1353
|
+
* A wrapper inside another extension's editor still counts as live if it rendered since
|
|
1354
|
+
* the last overlay frame. Pi renders the editor before it composites overlays.
|
|
1157
1355
|
*/
|
|
1158
1356
|
function closeIfEditorReplaced(): void {
|
|
1159
|
-
const rendersBefore = editorRendersSeen;
|
|
1160
1357
|
const renders = state().editorRenders ?? 0;
|
|
1358
|
+
const rendered = renders !== editorRendersSeen;
|
|
1161
1359
|
editorRendersSeen = renders;
|
|
1162
|
-
state().editorRenderedLastFrame =
|
|
1163
|
-
if (closed
|
|
1360
|
+
state().editorRenderedLastFrame = rendered;
|
|
1361
|
+
if (closed) return;
|
|
1362
|
+
const mounted = liveEditorMounted(tui);
|
|
1363
|
+
if (rendered || mounted === true) {
|
|
1364
|
+
sawLiveEditor = true;
|
|
1365
|
+
return;
|
|
1366
|
+
}
|
|
1367
|
+
if (mounted !== false || !sawLiveEditor) return;
|
|
1164
1368
|
// Not from inside pi-tui's render pass: hiding an overlay there would change the stack it is drawing.
|
|
1165
1369
|
queueMicrotask(() => {
|
|
1166
1370
|
if (closed) return;
|
|
@@ -1687,9 +1891,9 @@ function fill(glyph: string, label: string, width: number): string {
|
|
|
1687
1891
|
}
|
|
1688
1892
|
|
|
1689
1893
|
function safeTruncate(line: string, width: number, truncate: (s: string, width: number) => string): string {
|
|
1690
|
-
if (
|
|
1894
|
+
if (piVisibleWidth(line) <= width) return line;
|
|
1691
1895
|
const cut = truncate(line, width);
|
|
1692
|
-
return
|
|
1896
|
+
return piVisibleWidth(cut) > width ? piTruncateToWidth(cut, width) : cut;
|
|
1693
1897
|
}
|
|
1694
1898
|
|
|
1695
1899
|
const ANSI_RE = new RegExp("[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))", "g");
|