pi-better-server 0.4.0 → 0.6.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 +8 -1
- 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 +87 -0
- package/scripts/event-publication/writer.mjs +6 -0
- package/scripts/measure-full-runtime/frontend.ts +24 -0
- package/scripts/measure-full-runtime/hosted-extension.ts +28 -0
- package/scripts/measure-full-runtime/probe.mjs +29 -0
- 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 +146 -0
- package/scripts/measure-shared-reads/probe.mjs +26 -2
- package/scripts/measure-shared-reads.mjs +44 -9
- package/scripts/private-runtime/package-lock.json +66 -4
- package/scripts/private-runtime/package.json +10 -2
- package/scripts/source-provenance.mjs +31 -0
- package/scripts/test-on-pi.sh +3 -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 +27 -0
- package/src/runtime/background-tools.ts +389 -0
- package/src/runtime/background.ts +410 -48
- 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 +71 -33
- package/src/runtime/domain/background/process-identity.mjs +20 -2
- package/src/runtime/domain/background/process.mjs +3 -3
- package/src/runtime/domain/background/registry.mjs +89 -4
- package/src/runtime/domain/background/types.mjs +1 -0
- package/src/runtime/domain/background-service/adapter-contract.domain.mjs +83 -0
- package/src/runtime/domain/background-service/adapter-contract.ts +70 -0
- package/src/runtime/domain/background-service/batch.domain.mjs +91 -0
- package/src/runtime/domain/background-service/batch.ts +111 -0
- package/src/runtime/domain/background-service/conditions.domain.mjs +94 -0
- package/src/runtime/domain/background-service/conditions.ts +99 -0
- package/src/runtime/domain/background-service/delivery-observer.domain.mjs +37 -0
- package/src/runtime/domain/background-service/delivery-observer.ts +42 -0
- package/src/runtime/domain/background-service/failures.domain.mjs +209 -0
- package/src/runtime/domain/background-service/failures.ts +212 -0
- package/src/runtime/domain/background-service/goal-provider.domain.mjs +193 -0
- package/src/runtime/domain/background-service/goal-provider.ts +209 -0
- package/src/runtime/domain/background-service/index.domain.mjs +54 -0
- package/src/runtime/domain/background-service/index.ts +55 -0
- package/src/runtime/domain/background-service/logs.domain.mjs +129 -0
- package/src/runtime/domain/background-service/logs.ts +134 -0
- package/src/runtime/domain/background-service/maintenance.domain.mjs +95 -0
- package/src/runtime/domain/background-service/maintenance.ts +98 -0
- package/src/runtime/domain/background-service/managed-authority.domain.mjs +32 -0
- package/src/runtime/domain/background-service/managed-authority.ts +30 -0
- package/src/runtime/domain/background-service/managed-client.domain.mjs +79 -0
- package/src/runtime/domain/background-service/managed-client.ts +73 -0
- package/src/runtime/domain/background-service/managed-frontend.domain.mjs +225 -0
- package/src/runtime/domain/background-service/managed-frontend.ts +176 -0
- package/src/runtime/domain/background-service/navigator-provider.domain.mjs +492 -0
- package/src/runtime/domain/background-service/navigator-provider.ts +485 -0
- 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 +4080 -0
- package/src/runtime/domain/background-service/observed-waits.ts +4513 -0
- package/src/runtime/domain/background-service/output.domain.mjs +867 -0
- package/src/runtime/domain/background-service/output.ts +952 -0
- package/src/runtime/domain/background-service/process-identity.domain.mjs +129 -0
- package/src/runtime/domain/background-service/process-identity.ts +134 -0
- package/src/runtime/domain/background-service/process.domain.mjs +512 -0
- package/src/runtime/domain/background-service/process.ts +532 -0
- package/src/runtime/domain/background-service/prompt.domain.mjs +58 -0
- package/src/runtime/domain/background-service/prompt.ts +72 -0
- package/src/runtime/domain/background-service/registry.domain.mjs +460 -0
- package/src/runtime/domain/background-service/registry.ts +450 -0
- package/src/runtime/domain/background-service/remote-task-preset.domain.mjs +67 -0
- package/src/runtime/domain/background-service/remote-task-preset.ts +127 -0
- package/src/runtime/domain/background-service/runtime.domain.mjs +1511 -0
- package/src/runtime/domain/background-service/runtime.ts +1636 -0
- package/src/runtime/domain/background-service/sandbox.domain.mjs +735 -0
- package/src/runtime/domain/background-service/sandbox.ts +913 -0
- package/src/runtime/domain/background-service/shared-callback-batcher.domain.mjs +777 -0
- package/src/runtime/domain/background-service/shared-callback-batcher.ts +956 -0
- package/src/runtime/domain/background-service/shared-execution-policy.domain.mjs +50 -0
- package/src/runtime/domain/background-service/shared-execution-policy.ts +61 -0
- package/src/runtime/domain/background-service/shared-failure-observations.domain.mjs +1078 -0
- package/src/runtime/domain/background-service/shared-failure-observations.ts +1166 -0
- package/src/runtime/domain/background-service/shared-harness-settings.domain.mjs +126 -0
- package/src/runtime/domain/background-service/shared-harness-settings.ts +116 -0
- package/src/runtime/domain/background-service/shared-log-utils.domain.mjs +1223 -0
- package/src/runtime/domain/background-service/shared-log-utils.ts +1492 -0
- package/src/runtime/domain/background-service/shared-navigator-panels.domain.mjs +289 -0
- package/src/runtime/domain/background-service/shared-navigator-panels.ts +272 -0
- package/src/runtime/domain/background-service/shared-navigator.domain.mjs +1930 -0
- package/src/runtime/domain/background-service/shared-navigator.ts +1962 -0
- 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 +189 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/index.domain.mjs +51 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/index.ts +122 -0
- 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 +163 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.ts +174 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-parent-callbacks.domain.mjs +66 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-parent-callbacks.ts +68 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.domain.mjs +87 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.ts +90 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.domain.mjs +97 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.ts +139 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/errors.domain.mjs +12 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/errors.ts +79 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.domain.mjs +342 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.ts +513 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.domain.mjs +283 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.ts +458 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/recovery.domain.mjs +52 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/recovery.ts +55 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.domain.mjs +114 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.ts +140 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.domain.mjs +280 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.ts +442 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.domain.mjs +420 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.ts +441 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/sqlite.domain.mjs +194 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/sqlite.ts +239 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +275 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +585 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.domain.mjs +120 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.ts +142 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/task-cancellation.domain.mjs +188 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/task-cancellation.ts +224 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.domain.mjs +25 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.ts +707 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/upgrade.domain.mjs +22 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/upgrade.ts +22 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/validate.domain.mjs +234 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/validate.ts +241 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/waits.domain.mjs +851 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/waits.ts +1424 -0
- package/src/runtime/domain/background-service/shared-permission-blocker.domain.mjs +40 -0
- package/src/runtime/domain/background-service/shared-permission-blocker.ts +48 -0
- package/src/runtime/domain/background-service/shared-render-scheduler.domain.mjs +41 -0
- package/src/runtime/domain/background-service/shared-render-scheduler.ts +47 -0
- package/src/runtime/domain/background-service/shared-sandbox-core.domain.mjs +1531 -0
- package/src/runtime/domain/background-service/shared-sandbox-core.ts +1757 -0
- package/src/runtime/domain/background-service/shared-sandbox-diagnostics.domain.mjs +591 -0
- package/src/runtime/domain/background-service/shared-sandbox-diagnostics.ts +491 -0
- package/src/runtime/domain/background-service/shared-ssh-core/index.domain.mjs +698 -0
- package/src/runtime/domain/background-service/shared-ssh-core/index.ts +979 -0
- package/src/runtime/domain/background-service/shared-stall-detector.domain.mjs +37 -0
- package/src/runtime/domain/background-service/shared-stall-detector.ts +69 -0
- package/src/runtime/domain/background-service/shared-work-client.mjs +303 -0
- package/src/runtime/domain/background-service/stall-attention.domain.mjs +29 -0
- package/src/runtime/domain/background-service/stall-attention.ts +31 -0
- package/src/runtime/domain/background-service/stall.domain.mjs +57 -0
- package/src/runtime/domain/background-service/stall.ts +57 -0
- package/src/runtime/domain/background-service/supervisor/README.md +111 -0
- package/src/runtime/domain/background-service/supervisor/emit-runner.mjs +90 -0
- package/src/runtime/domain/background-service/supervisor/generated/conditions.mjs +96 -0
- package/src/runtime/domain/background-service/supervisor/generated/identity.mjs +95 -0
- package/src/runtime/domain/background-service/supervisor/generated/process-identity.mjs +131 -0
- package/src/runtime/domain/background-service/supervisor/generated/process.mjs +514 -0
- package/src/runtime/domain/background-service/supervisor/generated/runner.mjs +872 -0
- package/src/runtime/domain/background-service/supervisor/generated/store.mjs +609 -0
- package/src/runtime/domain/background-service/supervisor/generated/types.mjs +50 -0
- package/src/runtime/domain/background-service/supervisor/identity.domain.mjs +93 -0
- package/src/runtime/domain/background-service/supervisor/identity.ts +99 -0
- package/src/runtime/domain/background-service/supervisor/index.domain.mjs +22 -0
- package/src/runtime/domain/background-service/supervisor/index.ts +37 -0
- package/src/runtime/domain/background-service/supervisor/invocation.domain.mjs +30 -0
- package/src/runtime/domain/background-service/supervisor/invocation.ts +44 -0
- package/src/runtime/domain/background-service/supervisor/runner.domain.mjs +870 -0
- package/src/runtime/domain/background-service/supervisor/runner.ts +982 -0
- package/src/runtime/domain/background-service/supervisor/store.domain.mjs +605 -0
- package/src/runtime/domain/background-service/supervisor/store.ts +651 -0
- package/src/runtime/domain/background-service/supervisor/supervisor.domain.mjs +721 -0
- package/src/runtime/domain/background-service/supervisor/supervisor.ts +804 -0
- package/src/runtime/domain/background-service/supervisor/types.domain.mjs +48 -0
- package/src/runtime/domain/background-service/supervisor/types.ts +394 -0
- package/src/runtime/domain/background-service/task-diagnostics.domain.mjs +60 -0
- package/src/runtime/domain/background-service/task-diagnostics.ts +71 -0
- package/src/runtime/domain/background-service/tools.domain.mjs +1050 -0
- package/src/runtime/domain/background-service/tools.ts +1142 -0
- package/src/runtime/domain/background-service/types.domain.mjs +5 -0
- package/src/runtime/domain/background-service/types.ts +236 -0
- package/src/runtime/domain/background-service/work-observation.domain.mjs +176 -0
- package/src/runtime/domain/background-service/work-observation.ts +144 -0
- 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-parent-callbacks.mjs +65 -0
- package/src/runtime/domain/coordinator/src/background-requests.mjs +86 -0
- 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/result-supervision.mjs +12 -0
- package/src/runtime/domain/coordinator/src/rows.mjs +2 -0
- package/src/runtime/domain/coordinator/src/schema.mjs +73 -21
- package/src/runtime/domain/coordinator/src/store.mjs +32 -3
- package/src/runtime/domain/coordinator/src/subagent-launch.mjs +119 -0
- package/src/runtime/domain/coordinator/src/types.mjs +1 -1
- package/src/runtime/domain/coordinator/src/upgrade.mjs +22 -0
- 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/parse.d.mts +4 -1
- package/src/runtime/domain/parse.mjs +50 -5
- package/src/runtime/domain/sandbox-policy/README.md +633 -0
- package/src/runtime/domain/sandbox-policy/background-admission.domain.mjs +83 -0
- package/src/runtime/domain/sandbox-policy/background-admission.ts +75 -0
- package/src/runtime/domain/sandbox-policy/commands.domain.mjs +245 -0
- package/src/runtime/domain/sandbox-policy/commands.ts +336 -0
- package/src/runtime/domain/sandbox-policy/deny-rules.domain.mjs +440 -0
- package/src/runtime/domain/sandbox-policy/deny-rules.ts +620 -0
- package/src/runtime/domain/sandbox-policy/diagnostics-command.domain.mjs +30 -0
- package/src/runtime/domain/sandbox-policy/diagnostics-command.ts +27 -0
- package/src/runtime/domain/sandbox-policy/events.domain.mjs +49 -0
- package/src/runtime/domain/sandbox-policy/events.ts +85 -0
- package/src/runtime/domain/sandbox-policy/files.domain.mjs +153 -0
- package/src/runtime/domain/sandbox-policy/files.ts +224 -0
- package/src/runtime/domain/sandbox-policy/index.domain.mjs +289 -0
- package/src/runtime/domain/sandbox-policy/index.ts +386 -0
- package/src/runtime/domain/sandbox-policy/package.json +66 -0
- package/src/runtime/domain/sandbox-policy/permission-settings.domain.mjs +36 -0
- package/src/runtime/domain/sandbox-policy/permission-settings.ts +46 -0
- package/src/runtime/domain/sandbox-policy/permissions-page.domain.mjs +309 -0
- package/src/runtime/domain/sandbox-policy/permissions-page.ts +295 -0
- package/src/runtime/domain/sandbox-policy/permissions.domain.mjs +98 -0
- package/src/runtime/domain/sandbox-policy/permissions.ts +125 -0
- package/src/runtime/domain/sandbox-policy/policy.domain.mjs +80 -0
- package/src/runtime/domain/sandbox-policy/policy.ts +102 -0
- package/src/runtime/domain/sandbox-policy/preferences.domain.mjs +55 -0
- package/src/runtime/domain/sandbox-policy/preferences.ts +82 -0
- package/src/runtime/domain/sandbox-policy/rules-page.domain.mjs +138 -0
- package/src/runtime/domain/sandbox-policy/rules-page.ts +176 -0
- package/src/runtime/domain/sandbox-policy/session-permissions.domain.mjs +22 -0
- package/src/runtime/domain/sandbox-policy/session-permissions.ts +24 -0
- package/src/runtime/domain/sandbox-policy/shared-harness-settings.domain.mjs +126 -0
- package/src/runtime/domain/sandbox-policy/shared-harness-settings.ts +116 -0
- package/src/runtime/domain/sandbox-policy/shared-permission-blocker.domain.mjs +40 -0
- package/src/runtime/domain/sandbox-policy/shared-permission-blocker.ts +48 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-core.domain.mjs +1531 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-core.ts +1757 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-diagnostics.domain.mjs +591 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-diagnostics.ts +491 -0
- package/src/runtime/domain/sandbox-policy/shared-task-application.domain.mjs +185 -0
- package/src/runtime/domain/sandbox-policy/shared-task-application.ts +185 -0
- package/src/runtime/domain/sandbox-policy/shared-task-apply-patch.domain.mjs +416 -0
- package/src/runtime/domain/sandbox-policy/shared-task-apply-patch.ts +409 -0
- package/src/runtime/domain/sandbox-policy/shared-task-exec.domain.mjs +325 -0
- package/src/runtime/domain/sandbox-policy/shared-task-exec.ts +335 -0
- package/src/runtime/domain/sandbox-policy/shared-task-files.domain.mjs +346 -0
- package/src/runtime/domain/sandbox-policy/shared-task-files.ts +342 -0
- 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 +220 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-list.ts +209 -0
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.domain.mjs +227 -0
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.ts +224 -0
- package/src/runtime/domain/sandbox-policy/shared-task-tools.domain.mjs +92 -0
- package/src/runtime/domain/sandbox-policy/shared-task-tools.ts +123 -0
- package/src/runtime/domain/sandbox-policy/shell.domain.mjs +93 -0
- package/src/runtime/domain/sandbox-policy/shell.ts +129 -0
- package/src/runtime/domain/sandbox-policy/state.domain.mjs +307 -0
- package/src/runtime/domain/sandbox-policy/state.ts +408 -0
- package/src/runtime/domain/sandbox-policy/status.domain.mjs +64 -0
- package/src/runtime/domain/sandbox-policy/status.ts +76 -0
- package/src/runtime/domain/sandbox-policy/subagent-admission.domain.mjs +69 -0
- package/src/runtime/domain/sandbox-policy/subagent-admission.ts +60 -0
- package/src/runtime/domain/subagents/CONTEXT.md +202 -0
- package/src/runtime/domain/subagents/PRODUCT.md +49 -0
- package/src/runtime/domain/subagents/README.md +201 -0
- package/src/runtime/domain/subagents/agent-catalog.mjs +64 -0
- package/src/runtime/domain/subagents/agent-commands.domain.mjs +822 -0
- package/src/runtime/domain/subagents/agent-commands.ts +905 -0
- package/src/runtime/domain/subagents/agent-inspection.domain.mjs +398 -0
- package/src/runtime/domain/subagents/agent-inspection.ts +574 -0
- package/src/runtime/domain/subagents/agent-operations.domain.mjs +40 -0
- package/src/runtime/domain/subagents/agent-operations.ts +61 -0
- package/src/runtime/domain/subagents/agent-session-settings.domain.mjs +112 -0
- package/src/runtime/domain/subagents/agent-session-settings.ts +118 -0
- package/src/runtime/domain/subagents/agents-catalog-tool.domain.mjs +84 -0
- package/src/runtime/domain/subagents/agents-catalog-tool.ts +118 -0
- package/src/runtime/domain/subagents/assignment-outcomes.domain.mjs +276 -0
- package/src/runtime/domain/subagents/assignment-outcomes.ts +212 -0
- package/src/runtime/domain/subagents/assignment-projection.mjs +261 -0
- package/src/runtime/domain/subagents/assignment-report.domain.mjs +174 -0
- package/src/runtime/domain/subagents/assignment-report.ts +156 -0
- package/src/runtime/domain/subagents/batch.mjs +275 -0
- package/src/runtime/domain/subagents/callback-fields.domain.mjs +72 -0
- package/src/runtime/domain/subagents/callback-fields.ts +95 -0
- package/src/runtime/domain/subagents/capacity.mjs +108 -0
- package/src/runtime/domain/subagents/catalog-editor.domain.mjs +98 -0
- package/src/runtime/domain/subagents/catalog-editor.ts +125 -0
- package/src/runtime/domain/subagents/catalog-host-admission.domain.mjs +104 -0
- package/src/runtime/domain/subagents/catalog-host-admission.ts +85 -0
- package/src/runtime/domain/subagents/catalog-identity.domain.mjs +222 -0
- package/src/runtime/domain/subagents/catalog-identity.ts +258 -0
- package/src/runtime/domain/subagents/catalog-overlay.domain.mjs +9 -0
- package/src/runtime/domain/subagents/catalog-overlay.ts +10 -0
- package/src/runtime/domain/subagents/catalog-preferences.domain.mjs +164 -0
- package/src/runtime/domain/subagents/catalog-preferences.ts +139 -0
- package/src/runtime/domain/subagents/catalog-resolver.domain.mjs +366 -0
- package/src/runtime/domain/subagents/catalog-resolver.ts +540 -0
- package/src/runtime/domain/subagents/catalog-runtime.domain.mjs +570 -0
- package/src/runtime/domain/subagents/catalog-runtime.ts +680 -0
- package/src/runtime/domain/subagents/catalog-schema.domain.mjs +1331 -0
- package/src/runtime/domain/subagents/catalog-schema.ts +1563 -0
- package/src/runtime/domain/subagents/catalog-skill-edits.domain.mjs +95 -0
- package/src/runtime/domain/subagents/catalog-skill-edits.ts +116 -0
- package/src/runtime/domain/subagents/catalog-store.domain.mjs +808 -0
- package/src/runtime/domain/subagents/catalog-store.ts +1006 -0
- package/src/runtime/domain/subagents/catalog-ui.domain.mjs +651 -0
- package/src/runtime/domain/subagents/catalog-ui.ts +611 -0
- 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-codemode.domain.mjs +16 -0
- package/src/runtime/domain/subagents/child-codemode.ts +17 -0
- package/src/runtime/domain/subagents/child-dependencies.mjs +193 -0
- package/src/runtime/domain/subagents/child-incidents.domain.mjs +170 -0
- package/src/runtime/domain/subagents/child-incidents.ts +169 -0
- package/src/runtime/domain/subagents/child-operations.domain.mjs +986 -0
- package/src/runtime/domain/subagents/child-operations.ts +1191 -0
- package/src/runtime/domain/subagents/child-ownership.domain.mjs +205 -0
- package/src/runtime/domain/subagents/child-ownership.ts +160 -0
- package/src/runtime/domain/subagents/child-preflight.mjs +38 -0
- 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/child-runtime.mjs +67 -0
- package/src/runtime/domain/subagents/child-steer.domain.mjs +109 -0
- package/src/runtime/domain/subagents/child-steer.ts +102 -0
- package/src/runtime/domain/subagents/cleanup.domain.mjs +818 -0
- package/src/runtime/domain/subagents/cleanup.ts +1017 -0
- package/src/runtime/domain/subagents/codex-import.domain.mjs +575 -0
- package/src/runtime/domain/subagents/codex-import.ts +717 -0
- package/src/runtime/domain/subagents/completion.domain.mjs +6 -0
- package/src/runtime/domain/subagents/completion.mjs +152 -0
- package/src/runtime/domain/subagents/completion.ts +11 -0
- package/src/runtime/domain/subagents/config.domain.mjs +248 -0
- package/src/runtime/domain/subagents/config.json +15 -0
- package/src/runtime/domain/subagents/config.ts +328 -0
- package/src/runtime/domain/subagents/continuation-authority.domain.mjs +38 -0
- package/src/runtime/domain/subagents/continuation-authority.ts +31 -0
- 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 +942 -0
- package/src/runtime/domain/subagents/continuation.ts +1051 -0
- package/src/runtime/domain/subagents/delegation.domain.mjs +19 -0
- package/src/runtime/domain/subagents/delegation.ts +24 -0
- package/src/runtime/domain/subagents/effective-settings.domain.mjs +130 -0
- package/src/runtime/domain/subagents/effective-settings.ts +184 -0
- package/src/runtime/domain/subagents/extensions.domain.mjs +6 -0
- package/src/runtime/domain/subagents/extensions.mjs +164 -0
- package/src/runtime/domain/subagents/extensions.ts +19 -0
- package/src/runtime/domain/subagents/failures.domain.mjs +362 -0
- package/src/runtime/domain/subagents/failures.ts +319 -0
- package/src/runtime/domain/subagents/finalization.domain.mjs +168 -0
- package/src/runtime/domain/subagents/finalization.ts +218 -0
- package/src/runtime/domain/subagents/git-remotes.domain.mjs +351 -0
- package/src/runtime/domain/subagents/git-remotes.ts +413 -0
- package/src/runtime/domain/subagents/git-workspace.domain.mjs +337 -0
- package/src/runtime/domain/subagents/git-workspace.ts +430 -0
- package/src/runtime/domain/subagents/goal-provider.domain.mjs +125 -0
- package/src/runtime/domain/subagents/goal-provider.ts +132 -0
- package/src/runtime/domain/subagents/health-observation.domain.mjs +617 -0
- package/src/runtime/domain/subagents/health-observation.ts +818 -0
- package/src/runtime/domain/subagents/health-surface.mjs +284 -0
- package/src/runtime/domain/subagents/health.domain.mjs +261 -0
- package/src/runtime/domain/subagents/health.ts +343 -0
- package/src/runtime/domain/subagents/historical-attention.domain.mjs +37 -0
- package/src/runtime/domain/subagents/historical-attention.ts +35 -0
- package/src/runtime/domain/subagents/incident-model.domain.mjs +322 -0
- package/src/runtime/domain/subagents/incident-model.ts +358 -0
- package/src/runtime/domain/subagents/index.domain.mjs +4731 -0
- package/src/runtime/domain/subagents/index.ts +4781 -0
- package/src/runtime/domain/subagents/launch-abort.domain.mjs +13 -0
- package/src/runtime/domain/subagents/launch-abort.ts +21 -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/lifecycle.domain.mjs +265 -0
- package/src/runtime/domain/subagents/lifecycle.ts +360 -0
- package/src/runtime/domain/subagents/list.domain.mjs +2 -0
- package/src/runtime/domain/subagents/list.mjs +152 -0
- package/src/runtime/domain/subagents/list.ts +19 -0
- package/src/runtime/domain/subagents/log-cursor.domain.mjs +217 -0
- package/src/runtime/domain/subagents/log-cursor.ts +268 -0
- package/src/runtime/domain/subagents/managed-background-capability.domain.mjs +10 -0
- package/src/runtime/domain/subagents/managed-background-capability.ts +9 -0
- package/src/runtime/domain/subagents/managed-failure-worker.mjs +36 -0
- package/src/runtime/domain/subagents/managed-launch-bootstrap.mjs +48 -0
- package/src/runtime/domain/subagents/managed-launch-client.domain.mjs +75 -0
- package/src/runtime/domain/subagents/managed-launch-client.ts +59 -0
- package/src/runtime/domain/subagents/managed-launch-host.domain.mjs +627 -0
- package/src/runtime/domain/subagents/managed-launch-host.ts +504 -0
- package/src/runtime/domain/subagents/managed-launch-journal.mjs +17 -0
- package/src/runtime/domain/subagents/managed-launch-ownership.domain.mjs +29 -0
- package/src/runtime/domain/subagents/managed-launch-ownership.ts +22 -0
- package/src/runtime/domain/subagents/managed-launch-port.domain.mjs +2 -0
- package/src/runtime/domain/subagents/managed-launch-port.ts +25 -0
- package/src/runtime/domain/subagents/managed-launch-recovery.domain.mjs +29 -0
- package/src/runtime/domain/subagents/managed-launch-recovery.ts +45 -0
- package/src/runtime/domain/subagents/managed-worker-bridge.domain.mjs +63 -0
- package/src/runtime/domain/subagents/managed-worker-bridge.ts +48 -0
- package/src/runtime/domain/subagents/managed-worker.mjs +13 -0
- package/src/runtime/domain/subagents/model-resolution-core.domain.mjs +822 -0
- package/src/runtime/domain/subagents/model-resolution-core.ts +1074 -0
- package/src/runtime/domain/subagents/model-resolution.domain.mjs +22 -0
- package/src/runtime/domain/subagents/model-resolution.ts +32 -0
- package/src/runtime/domain/subagents/navigator.domain.mjs +6 -0
- package/src/runtime/domain/subagents/navigator.mjs +1233 -0
- package/src/runtime/domain/subagents/navigator.ts +39 -0
- package/src/runtime/domain/subagents/operation-bridge-types.domain.mjs +1012 -0
- package/src/runtime/domain/subagents/operation-bridge-types.ts +1156 -0
- package/src/runtime/domain/subagents/outage-observations.domain.mjs +84 -0
- package/src/runtime/domain/subagents/outage-observations.ts +73 -0
- package/src/runtime/domain/subagents/output-payload.domain.mjs +767 -0
- package/src/runtime/domain/subagents/output-payload.ts +987 -0
- 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 +86 -0
- package/src/runtime/domain/subagents/park-checkpoint.domain.mjs +55 -0
- package/src/runtime/domain/subagents/park-checkpoint.ts +61 -0
- package/src/runtime/domain/subagents/parse.domain.mjs +1218 -0
- package/src/runtime/domain/subagents/parse.ts +1451 -0
- package/src/runtime/domain/subagents/permission-policy.domain.mjs +232 -0
- package/src/runtime/domain/subagents/permission-policy.ts +291 -0
- package/src/runtime/domain/subagents/process-identity.mjs +33 -0
- package/src/runtime/domain/subagents/registry.domain.mjs +1584 -0
- package/src/runtime/domain/subagents/registry.ts +1904 -0
- package/src/runtime/domain/subagents/role-assignment.domain.mjs +104 -0
- package/src/runtime/domain/subagents/role-assignment.ts +141 -0
- package/src/runtime/domain/subagents/roles/role.architect.md +13 -0
- package/src/runtime/domain/subagents/roles/role.developer.md +16 -0
- package/src/runtime/domain/subagents/roles/role.explorer.md +13 -0
- package/src/runtime/domain/subagents/roles/role.product-manager.md +13 -0
- package/src/runtime/domain/subagents/roles/role.researcher.md +13 -0
- package/src/runtime/domain/subagents/roles/role.reviewer.md +13 -0
- package/src/runtime/domain/subagents/roles/role.writer.md +12 -0
- package/src/runtime/domain/subagents/sandbox.domain.mjs +64 -0
- package/src/runtime/domain/subagents/sandbox.ts +92 -0
- package/src/runtime/domain/subagents/session-selection.domain.mjs +32 -0
- package/src/runtime/domain/subagents/session-selection.ts +35 -0
- package/src/runtime/domain/subagents/session-store.domain.mjs +489 -0
- package/src/runtime/domain/subagents/session-store.ts +468 -0
- package/src/runtime/domain/subagents/settings-page.domain.mjs +313 -0
- package/src/runtime/domain/subagents/settings-page.ts +363 -0
- package/src/runtime/domain/subagents/shared-callback-batcher.domain.mjs +777 -0
- package/src/runtime/domain/subagents/shared-callback-batcher.ts +956 -0
- package/src/runtime/domain/subagents/shared-catalog.domain.mjs +70 -0
- package/src/runtime/domain/subagents/shared-catalog.ts +61 -0
- package/src/runtime/domain/subagents/shared-execution-policy.domain.mjs +50 -0
- package/src/runtime/domain/subagents/shared-execution-policy.ts +61 -0
- package/src/runtime/domain/subagents/shared-failure-observations.domain.mjs +1078 -0
- package/src/runtime/domain/subagents/shared-failure-observations.ts +1166 -0
- package/src/runtime/domain/subagents/shared-harness-settings.domain.mjs +126 -0
- package/src/runtime/domain/subagents/shared-harness-settings.ts +116 -0
- package/src/runtime/domain/subagents/shared-log-utils.domain.mjs +1223 -0
- package/src/runtime/domain/subagents/shared-log-utils.ts +1492 -0
- package/src/runtime/domain/subagents/shared-navigator-panels.domain.mjs +289 -0
- package/src/runtime/domain/subagents/shared-navigator-panels.ts +272 -0
- package/src/runtime/domain/subagents/shared-navigator.domain.mjs +1930 -0
- package/src/runtime/domain/subagents/shared-navigator.ts +1962 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-inbox.mjs +144 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-observation.mjs +189 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/index.domain.mjs +51 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/index.ts +122 -0
- 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 +163 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.ts +174 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-parent-callbacks.domain.mjs +66 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-parent-callbacks.ts +68 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.domain.mjs +87 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.ts +90 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.domain.mjs +97 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.ts +139 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/errors.domain.mjs +12 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/errors.ts +79 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.domain.mjs +342 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.ts +513 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.domain.mjs +283 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.ts +458 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/recovery.domain.mjs +52 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/recovery.ts +55 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.domain.mjs +114 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.ts +140 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.domain.mjs +280 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.ts +442 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.domain.mjs +420 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.ts +441 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/sqlite.domain.mjs +194 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/sqlite.ts +239 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +275 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +585 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.domain.mjs +120 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.ts +142 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-cancellation.domain.mjs +188 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-cancellation.ts +224 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.domain.mjs +25 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.ts +707 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/upgrade.domain.mjs +22 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/upgrade.ts +22 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/validate.domain.mjs +234 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/validate.ts +241 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/waits.domain.mjs +851 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/waits.ts +1424 -0
- package/src/runtime/domain/subagents/shared-permission-blocker.domain.mjs +40 -0
- package/src/runtime/domain/subagents/shared-permission-blocker.ts +48 -0
- package/src/runtime/domain/subagents/shared-render-scheduler.domain.mjs +41 -0
- package/src/runtime/domain/subagents/shared-render-scheduler.ts +47 -0
- package/src/runtime/domain/subagents/shared-sandbox-core.domain.mjs +1531 -0
- package/src/runtime/domain/subagents/shared-sandbox-core.ts +1757 -0
- package/src/runtime/domain/subagents/shared-sandbox-diagnostics.domain.mjs +591 -0
- package/src/runtime/domain/subagents/shared-sandbox-diagnostics.ts +491 -0
- package/src/runtime/domain/subagents/shared-stall-detector.domain.mjs +37 -0
- package/src/runtime/domain/subagents/shared-stall-detector.ts +69 -0
- package/src/runtime/domain/subagents/shared-task-application.domain.mjs +185 -0
- package/src/runtime/domain/subagents/shared-task-application.ts +185 -0
- package/src/runtime/domain/subagents/shared-task-apply-patch.domain.mjs +416 -0
- package/src/runtime/domain/subagents/shared-task-apply-patch.ts +409 -0
- package/src/runtime/domain/subagents/shared-task-exec.domain.mjs +325 -0
- package/src/runtime/domain/subagents/shared-task-exec.ts +335 -0
- package/src/runtime/domain/subagents/shared-task-files.domain.mjs +346 -0
- package/src/runtime/domain/subagents/shared-task-files.ts +342 -0
- 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 +220 -0
- package/src/runtime/domain/subagents/shared-task-process-list.ts +209 -0
- package/src/runtime/domain/subagents/shared-task-sandbox.domain.mjs +227 -0
- package/src/runtime/domain/subagents/shared-task-sandbox.ts +224 -0
- package/src/runtime/domain/subagents/shared-task-tools.domain.mjs +92 -0
- package/src/runtime/domain/subagents/shared-task-tools.ts +123 -0
- package/src/runtime/domain/subagents/shared-work-client.mjs +303 -0
- package/src/runtime/domain/subagents/shared-worktree-context.domain.mjs +142 -0
- package/src/runtime/domain/subagents/shared-worktree-context.ts +158 -0
- package/src/runtime/domain/subagents/skill-picker.domain.mjs +316 -0
- package/src/runtime/domain/subagents/skill-picker.ts +353 -0
- package/src/runtime/domain/subagents/skills.domain.mjs +138 -0
- package/src/runtime/domain/subagents/skills.ts +183 -0
- package/src/runtime/domain/subagents/spawn.domain.mjs +72 -0
- package/src/runtime/domain/subagents/spawn.ts +80 -0
- package/src/runtime/domain/subagents/stop.domain.mjs +184 -0
- package/src/runtime/domain/subagents/stop.ts +217 -0
- package/src/runtime/domain/subagents/subagent-tools.domain.mjs +101 -0
- package/src/runtime/domain/subagents/subagent-tools.ts +137 -0
- package/src/runtime/domain/subagents/task-guard.domain.mjs +163 -0
- package/src/runtime/domain/subagents/task-guard.ts +144 -0
- package/src/runtime/domain/subagents/task-policy.domain.mjs +201 -0
- package/src/runtime/domain/subagents/task-policy.ts +236 -0
- package/src/runtime/domain/subagents/task-runtime.mjs +53 -0
- package/src/runtime/domain/subagents/task-tool-owner.domain.mjs +18 -0
- package/src/runtime/domain/subagents/task-tool-owner.ts +21 -0
- package/src/runtime/domain/subagents/thinking.domain.mjs +22 -0
- package/src/runtime/domain/subagents/thinking.ts +28 -0
- package/src/runtime/domain/subagents/tier-policy.domain.mjs +75 -0
- package/src/runtime/domain/subagents/tier-policy.ts +126 -0
- package/src/runtime/domain/subagents/timing-notifications.domain.mjs +51 -0
- package/src/runtime/domain/subagents/timing-notifications.ts +37 -0
- package/src/runtime/domain/subagents/timing.domain.mjs +487 -0
- package/src/runtime/domain/subagents/timing.ts +634 -0
- package/src/runtime/domain/subagents/tools.domain.mjs +558 -0
- package/src/runtime/domain/subagents/tools.ts +629 -0
- package/src/runtime/domain/subagents/widget.domain.mjs +6 -0
- package/src/runtime/domain/subagents/widget.mjs +246 -0
- package/src/runtime/domain/subagents/widget.ts +30 -0
- package/src/runtime/domain/subagents/work-observation.domain.mjs +316 -0
- package/src/runtime/domain/subagents/work-observation.ts +248 -0
- package/src/runtime/domain/subagents/worker-catalog.domain.mjs +120 -0
- package/src/runtime/domain/subagents/worker-catalog.ts +162 -0
- package/src/runtime/domain/subagents/worker-operations-host.domain.mjs +1009 -0
- package/src/runtime/domain/subagents/worker-operations-host.ts +1238 -0
- package/src/runtime/domain/subagents/worker-waits.domain.mjs +2336 -0
- package/src/runtime/domain/subagents/worker-waits.ts +2878 -0
- package/src/runtime/domain/subagents/workspace-scope.domain.mjs +52 -0
- package/src/runtime/domain/subagents/workspace-scope.ts +50 -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 +27 -3
- package/src/runtime/query-executor.ts +178 -34
- package/src/runtime/query-worker.mjs +119 -22
- package/src/runtime/read-model.ts +939 -113
- package/src/runtime/read-watchdog-probe.ts +4 -0
- package/src/runtime/result-supervision.ts +188 -16
- package/src/runtime/source-watch.ts +175 -0
- package/src/runtime/subagent-launch.ts +73 -0
- 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 +185 -22
- package/src/session-activity.ts +26 -4
- package/src/version.ts +1 -1
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-subagents/widget.mjs. Do not edit directly.
|
|
2
|
+
/**
|
|
3
|
+
* Pure helpers for the live subagent status widget.
|
|
4
|
+
*
|
|
5
|
+
* Kept free of TUI / registry I/O so unit tests can pin the flicker-related
|
|
6
|
+
* contracts (dirty-check, fixed-width geometry, undefined clear) without a
|
|
7
|
+
* live pi session.
|
|
8
|
+
*
|
|
9
|
+
* Host note: pi's setWidget(string[]) path disposes + rebuilds the component
|
|
10
|
+
* tree on every call. Callers must skip identical frames and keep line geometry
|
|
11
|
+
* stable so neighboring ▶ job-* rows do not jump.
|
|
12
|
+
*/
|
|
13
|
+
import { formatWidgetHealthSuffix } from "./health-surface.mjs";
|
|
14
|
+
export const SPINNER = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
15
|
+
/** Default ticker cadence (ms). */
|
|
16
|
+
export const TICK_MS = 1000;
|
|
17
|
+
/**
|
|
18
|
+
* How often to re-parse a run log for spend/tool on the UI hot path.
|
|
19
|
+
* Elapsed still updates every tick; spend may lag by this much (AC3).
|
|
20
|
+
*/
|
|
21
|
+
export const SPEND_REFRESH_MS = 5000;
|
|
22
|
+
/**
|
|
23
|
+
* Floor on how often any one run's log may be re-read on the UI hot path.
|
|
24
|
+
*
|
|
25
|
+
* The size/mtime freshness rules below correctly re-read a log that changed —
|
|
26
|
+
* but a live child writes continuously, so "changed" is true on every frame and
|
|
27
|
+
* the rules alone degenerate into re-reading each log as fast as the timer
|
|
28
|
+
* fires. This floor bounds that: within the floor a cached parse is reused even
|
|
29
|
+
* though the log grew. It only ever delays new numbers by the floor, and only
|
|
30
|
+
* for a run that is actively writing.
|
|
31
|
+
*/
|
|
32
|
+
export const HOT_PATH_REFRESH_FLOOR_MS = 1000;
|
|
33
|
+
/**
|
|
34
|
+
* Whether a cached parse is inside the hot-path refresh floor and must be
|
|
35
|
+
* reused. Requires an explicit `now` and a `refreshedAt` stamp, so callers that
|
|
36
|
+
* pass neither keep the pure size/mtime semantics.
|
|
37
|
+
*
|
|
38
|
+
* @param {{ refreshedAt?: number }|null|undefined} cached
|
|
39
|
+
* @param {number} [now]
|
|
40
|
+
* @param {number} [floorMs]
|
|
41
|
+
*/
|
|
42
|
+
export function withinRefreshFloor(cached, now, floorMs = HOT_PATH_REFRESH_FLOOR_MS) {
|
|
43
|
+
if (!cached || typeof now !== "number" || typeof cached.refreshedAt !== "number")
|
|
44
|
+
return false;
|
|
45
|
+
if (!(floorMs > 0))
|
|
46
|
+
return false;
|
|
47
|
+
// A stamp from the future (clock step) must not pin the cache forever.
|
|
48
|
+
const age = now - cached.refreshedAt;
|
|
49
|
+
return age >= 0 && age < floorMs;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Value that clears the widget. pi only clears on `undefined`; `[]` leaves an
|
|
53
|
+
* empty residual widget node.
|
|
54
|
+
*/
|
|
55
|
+
export const WIDGET_CLEAR = undefined;
|
|
56
|
+
/** Fixed field widths so line geometry does not jump as values grow. */
|
|
57
|
+
export const ELAPSED_WIDTH = 8; // "999h 59m", "99m 59s", "9999s"
|
|
58
|
+
export const TOKENS_WIDTH = 6; // "999.9k", "99.9M"
|
|
59
|
+
export const COST_WIDTH = 7; // "$999.99", "$0.0000"
|
|
60
|
+
/** "45s" · "2m 03s" · "1h 04m" — variable width (list/finalize paths). */
|
|
61
|
+
export function fmtElapsed(ms) {
|
|
62
|
+
const s = Math.max(0, Math.round(ms / 1000));
|
|
63
|
+
if (s < 60)
|
|
64
|
+
return `${s}s`;
|
|
65
|
+
const m = Math.floor(s / 60);
|
|
66
|
+
const rs = s % 60;
|
|
67
|
+
if (m < 60)
|
|
68
|
+
return `${m}m ${String(rs).padStart(2, "0")}s`;
|
|
69
|
+
const h = Math.floor(m / 60);
|
|
70
|
+
const rm = m % 60;
|
|
71
|
+
return `${h}h ${String(rm).padStart(2, "0")}m`;
|
|
72
|
+
}
|
|
73
|
+
/** Fixed-width elapsed for the live widget (right-pad to ELAPSED_WIDTH). */
|
|
74
|
+
export function fmtElapsedFixed(ms) {
|
|
75
|
+
return fmtElapsed(ms).padEnd(ELAPSED_WIDTH, " ");
|
|
76
|
+
}
|
|
77
|
+
/** "412" · "1.2k" · "27.9k" · "1.4M". */
|
|
78
|
+
export function fmtTokens(n) {
|
|
79
|
+
if (n < 1000)
|
|
80
|
+
return String(n);
|
|
81
|
+
if (n < 1_000_000)
|
|
82
|
+
return `${(n / 1000).toFixed(1)}k`;
|
|
83
|
+
return `${(n / 1_000_000).toFixed(1)}M`;
|
|
84
|
+
}
|
|
85
|
+
export function fmtTokensFixed(n) {
|
|
86
|
+
return fmtTokens(n).padStart(TOKENS_WIDTH, " ");
|
|
87
|
+
}
|
|
88
|
+
/** Compact USD cost, e.g. "$0.0057" or "$1.23". */
|
|
89
|
+
export function fmtCost(usd) {
|
|
90
|
+
if (usd <= 0)
|
|
91
|
+
return "$0";
|
|
92
|
+
return usd < 1 ? `$${usd.toFixed(4)}` : `$${usd.toFixed(2)}`;
|
|
93
|
+
}
|
|
94
|
+
/** Compact model label for the widget: drop the provider prefix. */
|
|
95
|
+
export function shortModel(model) {
|
|
96
|
+
return model ? (model.split("/").pop() ?? model) : "?";
|
|
97
|
+
}
|
|
98
|
+
export function fmtCostFixed(usd) {
|
|
99
|
+
return fmtCost(usd).padStart(COST_WIDTH, " ");
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* One-line spend summary, or "" when nothing has been spent yet.
|
|
103
|
+
* Variable-width form used by list/finalize (not the live widget).
|
|
104
|
+
*/
|
|
105
|
+
export function fmtSpend(u) {
|
|
106
|
+
if (!u || (u.total <= 0 && u.costUSD <= 0))
|
|
107
|
+
return "";
|
|
108
|
+
return `${fmtTokens(u.total)} tok (↑${fmtTokens(u.input)} ↓${fmtTokens(u.output)}) · ${fmtCost(u.costUSD)}`;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Fixed-width spend for the live widget. Empty string when no spend yet —
|
|
112
|
+
* callers should still reserve geometry via a stable suffix policy if needed;
|
|
113
|
+
* once spend appears, widths stay constant as digits grow within the caps.
|
|
114
|
+
*/
|
|
115
|
+
export function fmtSpendFixed(u) {
|
|
116
|
+
if (!u || (u.total <= 0 && u.costUSD <= 0))
|
|
117
|
+
return "";
|
|
118
|
+
return (`${fmtTokensFixed(u.total)} tok` +
|
|
119
|
+
` (↑${fmtTokensFixed(u.input)} ↓${fmtTokensFixed(u.output)})` +
|
|
120
|
+
` · ${fmtCostFixed(u.costUSD)}`);
|
|
121
|
+
}
|
|
122
|
+
/** Deep equality for widget line arrays. */
|
|
123
|
+
export function linesEqual(a, b) {
|
|
124
|
+
if (a === b)
|
|
125
|
+
return true;
|
|
126
|
+
if (!a || !b)
|
|
127
|
+
return false;
|
|
128
|
+
if (a.length !== b.length)
|
|
129
|
+
return false;
|
|
130
|
+
for (let i = 0; i < a.length; i++) {
|
|
131
|
+
if (a[i] !== b[i])
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Decide what setWidget should receive for this frame.
|
|
138
|
+
*
|
|
139
|
+
* @param {string[]|undefined|null} prevLines - last lines sent to setWidget
|
|
140
|
+
* @param {string[]|null} nextLines - newly built lines, or null when idle
|
|
141
|
+
* @returns {{ op: 'skip' } | { op: 'set', lines: string[] } | { op: 'clear' }}
|
|
142
|
+
*/
|
|
143
|
+
export function nextWidgetAction(prevLines, nextLines) {
|
|
144
|
+
if (nextLines === null || nextLines === undefined) {
|
|
145
|
+
// Already cleared / never painted — nothing to do.
|
|
146
|
+
if (prevLines === undefined || prevLines === null)
|
|
147
|
+
return { op: "skip" };
|
|
148
|
+
// Had visible content (or a mistaken [] residual) → clear with undefined.
|
|
149
|
+
return { op: "clear" };
|
|
150
|
+
}
|
|
151
|
+
if (linesEqual(prevLines, nextLines))
|
|
152
|
+
return { op: "skip" };
|
|
153
|
+
return { op: "set", lines: nextLines };
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Build the widget lines for currently-running subagents.
|
|
157
|
+
*
|
|
158
|
+
* Healthy/quiet health is silent (issue #67). Degraded observations may append
|
|
159
|
+
* a short suffix via `healthById` without making the widget interactive.
|
|
160
|
+
*
|
|
161
|
+
* @param {object} p
|
|
162
|
+
* @param {Array<{ id: string, name?: string|null, model?: string|null, startedAt: number }>} p.running
|
|
163
|
+
* @param {number} p.frame - spinner frame index
|
|
164
|
+
* @param {number} p.now - Date.now()
|
|
165
|
+
* @param {Record<string, { usage?: object, tool?: string|null }>} [p.spendById]
|
|
166
|
+
* @param {Record<string, object>|undefined} [p.healthById] - optional #66 observations
|
|
167
|
+
* @param {string|null} [p.affordanceHint] - left-arrow affordance shown on the title line
|
|
168
|
+
* @param {string|null} [p.selectedId] - selected run id while the main-window list is focused
|
|
169
|
+
* @returns {string[]}
|
|
170
|
+
*/
|
|
171
|
+
export function buildWidgetLines(p) {
|
|
172
|
+
const running = p.running ?? [];
|
|
173
|
+
const frame = p.frame ?? 0;
|
|
174
|
+
const now = p.now ?? Date.now();
|
|
175
|
+
const spendById = p.spendById ?? {};
|
|
176
|
+
const healthById = p.healthById ?? {};
|
|
177
|
+
const selectedId = p.selectedId ?? null;
|
|
178
|
+
const spin = SPINNER[((frame % SPINNER.length) + SPINNER.length) % SPINNER.length];
|
|
179
|
+
const hint = p.affordanceHint ? ` ${p.affordanceHint}` : "";
|
|
180
|
+
const lines = [`Subagents · ${running.length} running${hint}`];
|
|
181
|
+
for (const m of running) {
|
|
182
|
+
const el = fmtElapsedFixed(now - m.startedAt);
|
|
183
|
+
const snap = spendById[m.id] ?? {};
|
|
184
|
+
const spend = fmtSpendFixed(snap.usage);
|
|
185
|
+
const tool = snap.tool ? ` · ${snap.tool}` : "";
|
|
186
|
+
const health = formatWidgetHealthSuffix(healthById[m.id]);
|
|
187
|
+
const nm = m.name ?? m.id;
|
|
188
|
+
const prefix = selectedId === m.id ? "› " : " ";
|
|
189
|
+
// Preserve list-show-model (#14): "name · shortModel" before fixed elapsed.
|
|
190
|
+
// Two spaces before elapsed keep a stable gap; elapsed itself is fixed-width.
|
|
191
|
+
lines.push(`${prefix}${spin} ${nm} · ${shortModel(m.model)} ${el}${tool}${spend ? ` ${spend}` : ""}${health}`);
|
|
192
|
+
}
|
|
193
|
+
return lines;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Whether a cached spend snapshot is still fresh enough for the UI tick.
|
|
197
|
+
*
|
|
198
|
+
* @param {{ refreshedAt: number, logSize?: number }|null|undefined} cached
|
|
199
|
+
* @param {number} now
|
|
200
|
+
* @param {number} [logSize]
|
|
201
|
+
* @param {number} [ttlMs]
|
|
202
|
+
*/
|
|
203
|
+
export function isSpendCacheFresh(cached, now, logSize, ttlMs = SPEND_REFRESH_MS) {
|
|
204
|
+
if (!cached)
|
|
205
|
+
return false;
|
|
206
|
+
if (typeof logSize === "number" && cached.logSize !== logSize)
|
|
207
|
+
return false;
|
|
208
|
+
return now - cached.refreshedAt < ttlMs;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Whether a cached health-log parse is still valid for the widget tick.
|
|
212
|
+
* Invalidates on log size or mtime change so growth/rewrite re-extracts, while
|
|
213
|
+
* unchanged logs skip synchronous full-log reparses across repeated renders.
|
|
214
|
+
*
|
|
215
|
+
* @param {{ logSize?: number, mtimeMs?: number }|null|undefined} cached
|
|
216
|
+
* @param {number} logSize
|
|
217
|
+
* @param {number} [mtimeMs]
|
|
218
|
+
*/
|
|
219
|
+
export function isHealthLogCacheFresh(cached, logSize, mtimeMs) {
|
|
220
|
+
if (!cached)
|
|
221
|
+
return false;
|
|
222
|
+
if (cached.logSize !== logSize)
|
|
223
|
+
return false;
|
|
224
|
+
if (typeof mtimeMs === "number" && cached.mtimeMs !== mtimeMs)
|
|
225
|
+
return false;
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Resolve child-event facts via the size/mtime cache, under the hot-path
|
|
230
|
+
* refresh floor. Calls `extract` only on miss, so a frame never re-reads a log
|
|
231
|
+
* that has not changed, and never re-reads one that changed more often than
|
|
232
|
+
* `identity.now`/`floorMs` allow.
|
|
233
|
+
*
|
|
234
|
+
* @param {{ facts: unknown, rawLog: unknown, logSize?: number, mtimeMs?: number, refreshedAt?: number }|null|undefined} cached
|
|
235
|
+
* @param {{ logSize: number, mtimeMs?: number, now?: number, floorMs?: number }} identity
|
|
236
|
+
* @param {() => { facts: unknown, rawLog: unknown }} extract
|
|
237
|
+
* @returns {{ facts: unknown, rawLog: unknown, hit: boolean }}
|
|
238
|
+
*/
|
|
239
|
+
export function resolveHealthLogExtraction(cached, identity, extract) {
|
|
240
|
+
if (withinRefreshFloor(cached, identity.now, identity.floorMs)
|
|
241
|
+
|| isHealthLogCacheFresh(cached, identity.logSize, identity.mtimeMs)) {
|
|
242
|
+
return { facts: cached.facts, rawLog: cached.rawLog, hit: true };
|
|
243
|
+
}
|
|
244
|
+
const { facts, rawLog } = extract();
|
|
245
|
+
return { facts, rawLog, hit: false };
|
|
246
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript re-export of widget.mjs pure helpers.
|
|
3
|
+
* Logic lives in widget.mjs for ESM unit-test compatibility (mirrors completion.ts).
|
|
4
|
+
*/
|
|
5
|
+
export {
|
|
6
|
+
SPINNER,
|
|
7
|
+
TICK_MS,
|
|
8
|
+
SPEND_REFRESH_MS,
|
|
9
|
+
WIDGET_CLEAR,
|
|
10
|
+
ELAPSED_WIDTH,
|
|
11
|
+
TOKENS_WIDTH,
|
|
12
|
+
COST_WIDTH,
|
|
13
|
+
fmtElapsed,
|
|
14
|
+
fmtElapsedFixed,
|
|
15
|
+
fmtTokens,
|
|
16
|
+
fmtTokensFixed,
|
|
17
|
+
fmtCost,
|
|
18
|
+
fmtCostFixed,
|
|
19
|
+
shortModel,
|
|
20
|
+
fmtSpend,
|
|
21
|
+
fmtSpendFixed,
|
|
22
|
+
linesEqual,
|
|
23
|
+
nextWidgetAction,
|
|
24
|
+
buildWidgetLines,
|
|
25
|
+
isSpendCacheFresh,
|
|
26
|
+
isHealthLogCacheFresh,
|
|
27
|
+
resolveHealthLogExtraction,
|
|
28
|
+
HOT_PATH_REFRESH_FLOOR_MS,
|
|
29
|
+
withinRefreshFloor,
|
|
30
|
+
} from "./widget.mjs";
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-subagents/work-observation.ts. Do not edit directly.
|
|
2
|
+
import { mkdirSync, readFileSync, realpathSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { connectWorkClient } from "./shared-work-client.mjs";
|
|
6
|
+
export const TERMINAL_NAVIGATOR_RETENTION_MS = 30_000;
|
|
7
|
+
let client;
|
|
8
|
+
let snapshot;
|
|
9
|
+
let context;
|
|
10
|
+
let connecting;
|
|
11
|
+
let collecting;
|
|
12
|
+
let collectingClient;
|
|
13
|
+
let dirty = false;
|
|
14
|
+
let retry;
|
|
15
|
+
let backoff = 100;
|
|
16
|
+
let failure = "Shared runtime observation is connecting.";
|
|
17
|
+
let generation = 0;
|
|
18
|
+
let connectionAbort = new AbortController();
|
|
19
|
+
const details = new Map();
|
|
20
|
+
const pendingDetails = new Set();
|
|
21
|
+
let refresh = () => { };
|
|
22
|
+
const observationListeners = new Set();
|
|
23
|
+
export function onWorkObservation(notify) {
|
|
24
|
+
observationListeners.add(notify);
|
|
25
|
+
return () => { observationListeners.delete(notify); };
|
|
26
|
+
}
|
|
27
|
+
export function workObservation() { return snapshot; }
|
|
28
|
+
export function hasWorkObservationContext() { return context !== undefined; }
|
|
29
|
+
export function workObservationStarted() { return Boolean(connecting || client || retry || snapshot); }
|
|
30
|
+
export function workObservationFailure() { return snapshot?.reason ?? failure; }
|
|
31
|
+
function degraded(error) {
|
|
32
|
+
failure = String(error);
|
|
33
|
+
snapshot = { ...snapshot, status: "degraded", reason: failure, rows: snapshot?.rows ?? [] };
|
|
34
|
+
refresh();
|
|
35
|
+
}
|
|
36
|
+
function reconnectLater(current) {
|
|
37
|
+
if (retry || !context || current !== generation)
|
|
38
|
+
return;
|
|
39
|
+
retry = setTimeout(() => {
|
|
40
|
+
retry = undefined;
|
|
41
|
+
void ensureObservation().catch(error => { if (current === generation) {
|
|
42
|
+
degraded(error);
|
|
43
|
+
reconnectLater(current);
|
|
44
|
+
} });
|
|
45
|
+
}, backoff);
|
|
46
|
+
retry.unref?.();
|
|
47
|
+
backoff = Math.min(2000, backoff * 2);
|
|
48
|
+
}
|
|
49
|
+
// Every page is bounded; a conversation anchor fences collection across filtered queries.
|
|
50
|
+
async function collect(candidate, current) {
|
|
51
|
+
dirty = true;
|
|
52
|
+
if (collecting && collectingClient === candidate)
|
|
53
|
+
return collecting;
|
|
54
|
+
collectingClient = candidate;
|
|
55
|
+
const scope = { ...context.origin, active: true, limit: 200 };
|
|
56
|
+
collecting = (async () => {
|
|
57
|
+
do {
|
|
58
|
+
dirty = false;
|
|
59
|
+
let completed = false;
|
|
60
|
+
for (let attempt = 0; attempt < 2 && !completed; attempt++) {
|
|
61
|
+
try {
|
|
62
|
+
const anchorScope = { ...context.origin, limit: 1 };
|
|
63
|
+
const anchor = await candidate.get(anchorScope);
|
|
64
|
+
const first = await candidate.get(scope);
|
|
65
|
+
if (current !== generation || candidate !== client)
|
|
66
|
+
return;
|
|
67
|
+
if (first.status === "rebuilding") {
|
|
68
|
+
snapshot = { ...first, rows: snapshot?.rows ?? [] };
|
|
69
|
+
refresh();
|
|
70
|
+
// A newer publication may already be owed while this page
|
|
71
|
+
// was in flight. Drain that demand, but never poll for it.
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
const rows = [...first.rows];
|
|
75
|
+
let cursor = first.nextCursor;
|
|
76
|
+
while (cursor) {
|
|
77
|
+
const page = await candidate.get({ ...scope, cursor });
|
|
78
|
+
if (page.scopeRevision !== first.scopeRevision || page.instanceId !== first.instanceId)
|
|
79
|
+
throw new Error("resync_required: active pages changed");
|
|
80
|
+
rows.push(...page.rows);
|
|
81
|
+
cursor = page.nextCursor;
|
|
82
|
+
}
|
|
83
|
+
// Cover the disconnect interval, not merely the last 30 s of
|
|
84
|
+
// worker time. The navigator starts its own visibility clock.
|
|
85
|
+
const endedAfter = Math.min(Date.now() - TERMINAL_NAVIGATOR_RETENTION_MS, snapshot?.observedAtLocal ?? Date.now());
|
|
86
|
+
const history = await candidate.get({ ...context.origin, active: false, endedAfter, limit: 200 });
|
|
87
|
+
if (history.instanceId !== first.instanceId)
|
|
88
|
+
throw new Error("resync_required: history changed");
|
|
89
|
+
if (current !== generation || candidate !== client)
|
|
90
|
+
return;
|
|
91
|
+
const owed = [];
|
|
92
|
+
let owedCursor;
|
|
93
|
+
do {
|
|
94
|
+
const page = await candidate.get({ ...context.origin, pendingRecipient: true, limit: 200, ...(owedCursor ? { cursor: owedCursor } : {}) });
|
|
95
|
+
if (page.instanceId !== first.instanceId)
|
|
96
|
+
throw new Error("resync_required: recipient page changed");
|
|
97
|
+
owed.push(...page.rows);
|
|
98
|
+
owedCursor = page.nextCursor;
|
|
99
|
+
} while (owedCursor);
|
|
100
|
+
if (current !== generation || candidate !== client)
|
|
101
|
+
return;
|
|
102
|
+
const historyRows = [...history.rows];
|
|
103
|
+
let historyCursor = history.nextCursor;
|
|
104
|
+
while (historyCursor) {
|
|
105
|
+
const page = await candidate.get({ ...context.origin, active: false, endedAfter, limit: 200, cursor: historyCursor });
|
|
106
|
+
if (page.scopeRevision !== history.scopeRevision || page.instanceId !== first.instanceId)
|
|
107
|
+
throw new Error("resync_required: history pages changed");
|
|
108
|
+
historyRows.push(...page.rows);
|
|
109
|
+
historyCursor = page.nextCursor;
|
|
110
|
+
}
|
|
111
|
+
if (current !== generation || candidate !== client)
|
|
112
|
+
return;
|
|
113
|
+
const confirmed = await candidate.get(anchorScope);
|
|
114
|
+
if (current !== generation || candidate !== client)
|
|
115
|
+
return;
|
|
116
|
+
if (confirmed.instanceId !== anchor.instanceId || confirmed.scopeRevision !== anchor.scopeRevision)
|
|
117
|
+
throw new Error("resync_required: conversation changed during collection");
|
|
118
|
+
const allRows = [...new Map([...rows, ...historyRows, ...owed].map(row => [row.meta.id, row])).values()];
|
|
119
|
+
snapshot = { ...first, seq: anchor.seq, observedRevisionVector: anchor.observedRevisionVector, rows: allRows, nextCursor: undefined,
|
|
120
|
+
observedAtLocal: Date.now(),
|
|
121
|
+
totalMatching: first.totalMatching + history.totalMatching, activity: { active: rows.length } };
|
|
122
|
+
completed = true;
|
|
123
|
+
refresh();
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
if (current !== generation || candidate !== client)
|
|
127
|
+
return;
|
|
128
|
+
if (attempt === 1 || candidate.closed) {
|
|
129
|
+
degraded(error);
|
|
130
|
+
if (candidate.closed)
|
|
131
|
+
return;
|
|
132
|
+
// A notification received during these page reads is
|
|
133
|
+
// still owed a coherent collection. Drain only that
|
|
134
|
+
// demand through the outer loop; do not start a poller.
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
} while (dirty && current === generation && candidate === client && !candidate.closed);
|
|
140
|
+
})().finally(() => { if (current === generation && collectingClient === candidate)
|
|
141
|
+
collecting = undefined; });
|
|
142
|
+
return collecting;
|
|
143
|
+
}
|
|
144
|
+
async function connectObservation(current) {
|
|
145
|
+
const saved = context;
|
|
146
|
+
const signal = connectionAbort.signal;
|
|
147
|
+
mkdirSync(saved.agentDir, { recursive: true, mode: 0o700 });
|
|
148
|
+
saved.agentDir = realpathSync(saved.agentDir);
|
|
149
|
+
let registration;
|
|
150
|
+
try {
|
|
151
|
+
registration = JSON.parse(readFileSync(join(saved.agentDir, "server-registration-v1.json"), "utf8"));
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
if (error.code !== "ENOENT")
|
|
155
|
+
throw error;
|
|
156
|
+
const path = "./runtime-client/src/runtime/client.mjs";
|
|
157
|
+
const { ensureRuntime } = await import(path);
|
|
158
|
+
await ensureRuntime({ agentDir: saved.agentDir, signal });
|
|
159
|
+
registration = JSON.parse(readFileSync(join(saved.agentDir, "server-registration-v1.json"), "utf8"));
|
|
160
|
+
}
|
|
161
|
+
if (current !== generation)
|
|
162
|
+
return;
|
|
163
|
+
if (registration.version !== 1 || registration.agentDir !== saved.agentDir)
|
|
164
|
+
throw new Error("Invalid canonical runtime registration");
|
|
165
|
+
client?.close();
|
|
166
|
+
const candidate = await connectWorkClient(join(registration.serverDir, "pi-server.sock"), saved.agentDir, [], {
|
|
167
|
+
signal,
|
|
168
|
+
recover: async ({ timeoutMs, signal }) => {
|
|
169
|
+
const path = "./runtime-client/src/runtime/client.mjs";
|
|
170
|
+
const { ensureRuntime } = await import(path);
|
|
171
|
+
await ensureRuntime({ agentDir: saved.agentDir, serverDir: registration.serverDir, timeoutMs, signal });
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
if (current !== generation) {
|
|
175
|
+
candidate.close();
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
client = candidate;
|
|
179
|
+
candidate.onChange(() => {
|
|
180
|
+
if (current !== generation || candidate !== client)
|
|
181
|
+
return;
|
|
182
|
+
if (candidate.closed) {
|
|
183
|
+
details.clear();
|
|
184
|
+
pendingDetails.clear();
|
|
185
|
+
degraded(candidate.snapshot?.reason ?? "runtime-unavailable: disconnected; resync required");
|
|
186
|
+
reconnectLater(current);
|
|
187
|
+
}
|
|
188
|
+
else
|
|
189
|
+
void collect(candidate, current).catch(error => { if (current === generation)
|
|
190
|
+
degraded(error); });
|
|
191
|
+
});
|
|
192
|
+
await candidate.subscribe({ ...saved.origin, limit: 200 });
|
|
193
|
+
if (candidate.snapshot?.status === "rebuilding")
|
|
194
|
+
await new Promise((resolve, reject) => {
|
|
195
|
+
const timer = setTimeout(() => { stop(); reject(new Error("Runtime scope is still rebuilding; retry the observation.")); }, 5000);
|
|
196
|
+
const stop = candidate.onChange(value => {
|
|
197
|
+
if (value.status !== "rebuilding") {
|
|
198
|
+
stop();
|
|
199
|
+
clearTimeout(timer);
|
|
200
|
+
resolve();
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
await collect(candidate, current);
|
|
205
|
+
if (candidate.closed)
|
|
206
|
+
throw new Error("runtime-unavailable: disconnected; resync required");
|
|
207
|
+
if (current === generation) {
|
|
208
|
+
backoff = 100;
|
|
209
|
+
if (retry)
|
|
210
|
+
clearTimeout(retry);
|
|
211
|
+
retry = undefined;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
export function configureWorkObservation(agentDir, origin, changed) {
|
|
215
|
+
stopWorkObservation();
|
|
216
|
+
context = { agentDir, origin };
|
|
217
|
+
refresh = () => {
|
|
218
|
+
changed();
|
|
219
|
+
for (const notify of observationListeners)
|
|
220
|
+
notify();
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
export async function activateWorkObservation() {
|
|
224
|
+
if (!context)
|
|
225
|
+
return;
|
|
226
|
+
const current = generation;
|
|
227
|
+
try {
|
|
228
|
+
await ensureObservation();
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
if (current === generation) {
|
|
232
|
+
degraded(error);
|
|
233
|
+
reconnectLater(current);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
export async function startWorkObservation(agentDir, origin, changed) {
|
|
238
|
+
configureWorkObservation(agentDir, origin, changed);
|
|
239
|
+
await activateWorkObservation();
|
|
240
|
+
}
|
|
241
|
+
async function ensureObservation() {
|
|
242
|
+
if (connecting)
|
|
243
|
+
return connecting;
|
|
244
|
+
if (client && !client.closed)
|
|
245
|
+
return;
|
|
246
|
+
context ??= { agentDir: process.env.PI_CODING_AGENT_DIR ?? join(homedir(), ".pi", "agent"), origin: { cwd: process.cwd() } };
|
|
247
|
+
const current = generation;
|
|
248
|
+
connecting = connectObservation(current).finally(() => { if (current === generation)
|
|
249
|
+
connecting = undefined; });
|
|
250
|
+
return connecting;
|
|
251
|
+
}
|
|
252
|
+
async function query(scope) {
|
|
253
|
+
const current = generation;
|
|
254
|
+
for (let attempt = 0;; attempt++) {
|
|
255
|
+
try {
|
|
256
|
+
await ensureObservation();
|
|
257
|
+
if (current !== generation)
|
|
258
|
+
throw new Error("runtime-unavailable: observation closed");
|
|
259
|
+
return await client.get(scope);
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
if (current !== generation || (client && !client.closed) || attempt === 1)
|
|
263
|
+
throw error;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
export async function observedAssignment(id) {
|
|
268
|
+
const observation = await query({ id, limit: 1 });
|
|
269
|
+
const row = observation.rows[0];
|
|
270
|
+
if (!row)
|
|
271
|
+
throw new Error(observation.status === "ready" ? `No shared observation for ${id}` : observation.reason);
|
|
272
|
+
return { assignment: row.assignment, snapshot: observation };
|
|
273
|
+
}
|
|
274
|
+
export async function observedList(scope) { return query(scope); }
|
|
275
|
+
export function stopWorkObservation() {
|
|
276
|
+
generation++;
|
|
277
|
+
context = undefined;
|
|
278
|
+
connectionAbort.abort();
|
|
279
|
+
connectionAbort = new AbortController();
|
|
280
|
+
if (retry)
|
|
281
|
+
clearTimeout(retry);
|
|
282
|
+
retry = undefined;
|
|
283
|
+
client?.close();
|
|
284
|
+
client = undefined;
|
|
285
|
+
snapshot = undefined;
|
|
286
|
+
connecting = undefined;
|
|
287
|
+
collecting = undefined;
|
|
288
|
+
collectingClient = undefined;
|
|
289
|
+
dirty = false;
|
|
290
|
+
details.clear();
|
|
291
|
+
pendingDetails.clear();
|
|
292
|
+
backoff = 100;
|
|
293
|
+
}
|
|
294
|
+
export function requestWorkDetail(id) {
|
|
295
|
+
const cached = details.get(id);
|
|
296
|
+
if ((cached?.seq === snapshot?.seq && cached?.instanceId === snapshot?.instanceId) || pendingDetails.has(id) || !client)
|
|
297
|
+
return cached?.row;
|
|
298
|
+
pendingDetails.add(id);
|
|
299
|
+
const current = generation;
|
|
300
|
+
void query({ id, detail: true, limit: 1 }).then(value => {
|
|
301
|
+
if (current !== generation)
|
|
302
|
+
return;
|
|
303
|
+
details.set(id, { seq: value.seq, instanceId: value.instanceId, row: value.rows[0] });
|
|
304
|
+
if (details.size > 16)
|
|
305
|
+
details.delete(details.keys().next().value);
|
|
306
|
+
refresh();
|
|
307
|
+
}).catch(error => {
|
|
308
|
+
if (current !== generation)
|
|
309
|
+
return;
|
|
310
|
+
failure = String(error);
|
|
311
|
+
details.set(id, { seq: snapshot?.seq, instanceId: snapshot?.instanceId, row: { ...cached?.row, observationError: failure } });
|
|
312
|
+
refresh();
|
|
313
|
+
}).finally(() => { if (current === generation)
|
|
314
|
+
pendingDetails.delete(id); });
|
|
315
|
+
return cached?.row;
|
|
316
|
+
}
|