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,777 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-subagents/shared-callback-batcher.ts. Do not edit directly.
|
|
2
|
+
// Generated from packages/callback-batcher/index.ts. Do not edit directly.
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import { harnessSettingsPath, readHarnessSetting, updateHarnessSetting, } from "./shared-harness-settings.domain.mjs";
|
|
6
|
+
export const CALLBACK_SETTINGS_ENTRY = "pi-better-callback-settings";
|
|
7
|
+
const CALLBACK_PREFERENCES_FILE = "pi-better-callback-preferences.json";
|
|
8
|
+
function isDeliveryMode(mode) {
|
|
9
|
+
return mode === "hold" || mode === "steer";
|
|
10
|
+
}
|
|
11
|
+
function validCallbackPreferences(value) {
|
|
12
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
13
|
+
return false;
|
|
14
|
+
const data = value;
|
|
15
|
+
return Object.keys(data).length === 2 && Object.hasOwn(data, "version") && Object.hasOwn(data, "mode")
|
|
16
|
+
&& data.version === 1 && isDeliveryMode(data.mode);
|
|
17
|
+
}
|
|
18
|
+
function parseCallbackPreferences(value) {
|
|
19
|
+
if (!validCallbackPreferences(value))
|
|
20
|
+
throw new Error('Expected { version: 1, mode: "hold" | "steer" }');
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
function legacyCallbackPreferencesPath(seams) {
|
|
24
|
+
return join((seams.agentDir ?? getAgentDir)(), "extensions", CALLBACK_PREFERENCES_FILE);
|
|
25
|
+
}
|
|
26
|
+
/** Branch history is authoritative; abandoned branches and invalid entries are ignored. */
|
|
27
|
+
export function getCallbackSettings(ctx, seams = {}) {
|
|
28
|
+
const branch = ctx.sessionManager?.getBranch?.() ?? [];
|
|
29
|
+
for (let i = branch.length - 1; i >= 0; i--) {
|
|
30
|
+
const entry = branch[i];
|
|
31
|
+
if (entry?.type === "custom" && entry.customType === CALLBACK_SETTINGS_ENTRY && validCallbackPreferences(entry.data)) {
|
|
32
|
+
return { mode: entry.data.mode, source: "session" };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return getSessionDefault(ctx, seams);
|
|
36
|
+
}
|
|
37
|
+
function getSessionDefault(ctx, seams) {
|
|
38
|
+
const sessionId = ctx.sessionManager?.getSessionId?.();
|
|
39
|
+
const defaults = globalState().sessionDefaults ??= new WeakMap();
|
|
40
|
+
const initial = ctx.sessionManager ? defaults.get(ctx.sessionManager) : undefined;
|
|
41
|
+
if (initial && initial.sessionId === sessionId)
|
|
42
|
+
return { mode: initial.mode, source: "default" };
|
|
43
|
+
const snapshot = (mode) => {
|
|
44
|
+
if (ctx.sessionManager)
|
|
45
|
+
defaults.set(ctx.sessionManager, { sessionId, mode });
|
|
46
|
+
return { mode, source: "default" };
|
|
47
|
+
};
|
|
48
|
+
const path = harnessSettingsPath(seams);
|
|
49
|
+
try {
|
|
50
|
+
const data = readHarnessSetting("callbacks", seams, {
|
|
51
|
+
path: legacyCallbackPreferencesPath(seams),
|
|
52
|
+
parse: parseCallbackPreferences,
|
|
53
|
+
});
|
|
54
|
+
return snapshot(data === undefined ? "hold" : parseCallbackPreferences(data).mode);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
const prefix = error.code ? "Cannot read" : "Invalid";
|
|
58
|
+
throw new Error(`${prefix} callback default at ${path}: ${String(error)}`, { cause: error });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** Saves only the future-session default; never changes the active branch or batcher. */
|
|
62
|
+
export function saveCallbackDefault(mode, seams = {}) {
|
|
63
|
+
if (!isDeliveryMode(mode))
|
|
64
|
+
throw new Error("Invalid callback delivery mode. Nothing saved.");
|
|
65
|
+
const path = harnessSettingsPath(seams);
|
|
66
|
+
try {
|
|
67
|
+
updateHarnessSetting("callbacks", () => ({ version: 1, mode }), seams);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
throw new Error(`Cannot save callback default at ${path}: ${String(error)}`, { cause: error });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** Persist first so a failed append cannot become a transient delivery-mode change. */
|
|
74
|
+
export function changeCallbackSetting(host, ctx, mode) {
|
|
75
|
+
if (!isDeliveryMode(mode))
|
|
76
|
+
throw new Error("Invalid callback delivery mode. Nothing changed.");
|
|
77
|
+
const data = { version: 1, mode };
|
|
78
|
+
try {
|
|
79
|
+
host.appendEntry(CALLBACK_SETTINGS_ENTRY, data);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
// Pi advances its in-memory branch before disk persistence. Invalidate
|
|
83
|
+
// our payload so that failed entry cannot become a restored setting.
|
|
84
|
+
data.version = 0;
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
const batcher = bindCallbackBatcher(host, ctx);
|
|
88
|
+
batcher.setWhileBusy(mode);
|
|
89
|
+
batcher.setAvailability(() => ctx.isIdle());
|
|
90
|
+
}
|
|
91
|
+
const GLOBAL_STATE_KEY = Symbol.for("@1aboveio/pi-better-harness/callback-batcher");
|
|
92
|
+
const DEFAULT_WINDOW_MS = 100;
|
|
93
|
+
const DEFAULT_RETRY_MS = 1_000;
|
|
94
|
+
const MAX_LABEL_BYTES = 160;
|
|
95
|
+
const MAX_ID_BYTES = 200;
|
|
96
|
+
/**
|
|
97
|
+
* Status field bound. Long statuses keep whole `; `-separated notes and say
|
|
98
|
+
* how many were left out, instead of cutting mid-word (#323).
|
|
99
|
+
*/
|
|
100
|
+
const MAX_STATUS_BYTES = 160;
|
|
101
|
+
const MAX_FAILURE_BYTES = 400;
|
|
102
|
+
const MAX_DECISION_BYTES = 400;
|
|
103
|
+
const encoder = new TextEncoder();
|
|
104
|
+
const decoder = new TextDecoder("utf-8");
|
|
105
|
+
/** OUTPUT-POLICY default: UTF-8 bytes of one model-facing callback batch. */
|
|
106
|
+
export const CALLBACK_BATCH_BUDGET_BYTES = 2 * 1024;
|
|
107
|
+
/** Documented hard cap. Explicit larger pages clamp here. */
|
|
108
|
+
export const CALLBACK_BATCH_MAX_BYTES = 8 * 1024;
|
|
109
|
+
const RETRIEVAL_FOOTER = "Retrieve durable results/status with the listed tools using cursor/limit. Full results and logs are intentionally omitted.";
|
|
110
|
+
export const CALLBACK_BATCH_WINDOW_ENV = "PI_BETTER_CALLBACK_BATCH_MS";
|
|
111
|
+
export const DEFAULT_CALLBACK_BATCH_WINDOW_MS = DEFAULT_WINDOW_MS;
|
|
112
|
+
export function resolveCallbackBatchWindowMs(value = process.env[CALLBACK_BATCH_WINDOW_ENV]) {
|
|
113
|
+
if (value === undefined || value === null || value === "")
|
|
114
|
+
return DEFAULT_WINDOW_MS;
|
|
115
|
+
const parsed = Number(value);
|
|
116
|
+
if (!Number.isFinite(parsed))
|
|
117
|
+
return DEFAULT_WINDOW_MS;
|
|
118
|
+
return Math.max(0, Math.min(5_000, Math.floor(parsed)));
|
|
119
|
+
}
|
|
120
|
+
export function utf8ByteLength(text) {
|
|
121
|
+
return encoder.encode(text).byteLength;
|
|
122
|
+
}
|
|
123
|
+
export function callbackBatchBudget(requested) {
|
|
124
|
+
const parsed = typeof requested === "number" ? requested
|
|
125
|
+
: typeof requested === "string" && requested.trim() !== "" ? Number(requested)
|
|
126
|
+
: Number.NaN;
|
|
127
|
+
if (!Number.isFinite(parsed) || parsed <= 0)
|
|
128
|
+
return CALLBACK_BATCH_BUDGET_BYTES;
|
|
129
|
+
return Math.min(Math.max(1, Math.floor(parsed)), CALLBACK_BATCH_MAX_BYTES);
|
|
130
|
+
}
|
|
131
|
+
function completeUtf8End(bytes, to) {
|
|
132
|
+
if (to <= 0)
|
|
133
|
+
return 0;
|
|
134
|
+
if (to >= bytes.length)
|
|
135
|
+
return bytes.length;
|
|
136
|
+
let seqStart = to - 1;
|
|
137
|
+
while (seqStart > 0 && (bytes[seqStart] & 0xc0) === 0x80)
|
|
138
|
+
seqStart -= 1;
|
|
139
|
+
if ((bytes[seqStart] & 0xc0) === 0x80)
|
|
140
|
+
return to;
|
|
141
|
+
const lead = bytes[seqStart];
|
|
142
|
+
const needed = lead <= 0x7f ? 1
|
|
143
|
+
: (lead & 0xe0) === 0xc0 ? 2
|
|
144
|
+
: (lead & 0xf0) === 0xe0 ? 3
|
|
145
|
+
: (lead & 0xf8) === 0xf0 ? 4
|
|
146
|
+
: 1;
|
|
147
|
+
return seqStart + needed > to ? seqStart : to;
|
|
148
|
+
}
|
|
149
|
+
function clipUtf8Prefix(text, maxBytes) {
|
|
150
|
+
if (maxBytes <= 0)
|
|
151
|
+
return "";
|
|
152
|
+
const bytes = encoder.encode(text);
|
|
153
|
+
if (bytes.byteLength <= maxBytes)
|
|
154
|
+
return text;
|
|
155
|
+
return decoder.decode(bytes.subarray(0, completeUtf8End(bytes, Math.min(maxBytes, bytes.byteLength))));
|
|
156
|
+
}
|
|
157
|
+
function boundedField(value, maxBytes) {
|
|
158
|
+
const oneLine = String(value ?? "").replace(/\s+/g, " ").trim();
|
|
159
|
+
if (utf8ByteLength(oneLine) <= maxBytes)
|
|
160
|
+
return oneLine;
|
|
161
|
+
const ellipsis = "...";
|
|
162
|
+
return `${clipUtf8Prefix(oneLine, Math.max(0, maxBytes - utf8ByteLength(ellipsis)))}${ellipsis}`;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* The status field under MAX_STATUS_BYTES without losing meaning: the leading
|
|
166
|
+
* lifecycle note is always kept, later `; `-separated notes are kept whole
|
|
167
|
+
* while they fit, and anything left out is named with a count and the inspect
|
|
168
|
+
* tool rather than an ellipsis.
|
|
169
|
+
*/
|
|
170
|
+
function boundedStatus(value) {
|
|
171
|
+
const status = String(value ?? "").replace(/\s+/g, " ").trim();
|
|
172
|
+
if (utf8ByteLength(status) <= MAX_STATUS_BYTES)
|
|
173
|
+
return status;
|
|
174
|
+
const notes = status.split(/;\s+/).filter(Boolean);
|
|
175
|
+
const omission = (count) => ` (+${count} more status note${count === 1 ? "" : "s"}; see inspect)`;
|
|
176
|
+
const reserve = utf8ByteLength(omission(notes.length));
|
|
177
|
+
let kept = notes[0] ?? "";
|
|
178
|
+
if (utf8ByteLength(kept) + reserve > MAX_STATUS_BYTES) {
|
|
179
|
+
const suffix = " (clipped; see inspect)";
|
|
180
|
+
return `${clipUtf8Prefix(kept, MAX_STATUS_BYTES - utf8ByteLength(suffix))}${suffix}`;
|
|
181
|
+
}
|
|
182
|
+
let count = 1;
|
|
183
|
+
for (const note of notes.slice(1)) {
|
|
184
|
+
const next = `${kept}; ${note}`;
|
|
185
|
+
if (utf8ByteLength(next) + reserve > MAX_STATUS_BYTES)
|
|
186
|
+
break;
|
|
187
|
+
kept = next;
|
|
188
|
+
count += 1;
|
|
189
|
+
}
|
|
190
|
+
return count < notes.length ? `${kept}${omission(notes.length - count)}` : kept;
|
|
191
|
+
}
|
|
192
|
+
function inspectFor(event) {
|
|
193
|
+
const id = boundedField(event.inspectId ?? event.id, MAX_ID_BYTES);
|
|
194
|
+
return event.detailTool === "bg_task_status"
|
|
195
|
+
? `bg_task_status id=${id}`
|
|
196
|
+
: `subagent_result id=${JSON.stringify(id)}`;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Whole incident rows that fit `maxBytes`, one per line. A first row that does
|
|
200
|
+
* not fit is shown as a clipped prefix and is NOT counted as shown.
|
|
201
|
+
*/
|
|
202
|
+
function incidentLines(rows, total, maxBytes, indent) {
|
|
203
|
+
const lines = [];
|
|
204
|
+
let used = 0;
|
|
205
|
+
let shown = 0;
|
|
206
|
+
for (const row of rows) {
|
|
207
|
+
const line = `${indent}${String(row).replace(/\s+/g, " ").trim()}`;
|
|
208
|
+
const size = utf8ByteLength(line) + 1;
|
|
209
|
+
if (used + size <= maxBytes) {
|
|
210
|
+
lines.push(line);
|
|
211
|
+
used += size;
|
|
212
|
+
shown += 1;
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (lines.length === 0 && maxBytes - indent.length > 48) {
|
|
216
|
+
lines.push(`${indent}${boundedField(row, maxBytes - utf8ByteLength(indent) - 1)} (clipped)`);
|
|
217
|
+
}
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
return { lines, shown, total: Math.max(total, rows.length) };
|
|
221
|
+
}
|
|
222
|
+
function countsLine(incidents, inspect) {
|
|
223
|
+
if (incidents.total <= 0)
|
|
224
|
+
return undefined;
|
|
225
|
+
const omitted = Math.max(0, incidents.total - incidents.shown);
|
|
226
|
+
return ` incidents=${incidents.total} shown=${incidents.shown}` +
|
|
227
|
+
(omitted > 0 ? ` omittedIncidents=${omitted} retrieve: ${inspect} (incident pages via cursor)` : "");
|
|
228
|
+
}
|
|
229
|
+
function eventIncidents(event, failureBytes) {
|
|
230
|
+
if (event.failureRows && event.failureRows.length) {
|
|
231
|
+
return incidentLines(event.failureRows, event.incidentCount ?? event.failureRows.length, failureBytes, " failure: ");
|
|
232
|
+
}
|
|
233
|
+
if (event.failure) {
|
|
234
|
+
const total = event.incidentCount ?? 1;
|
|
235
|
+
const whole = incidentLines([event.failure], 1, failureBytes, " failure: ");
|
|
236
|
+
const legacyShown = whole.shown ? Math.max(0, total - (event.omittedIncidents ?? 0)) : 0;
|
|
237
|
+
return { lines: whole.lines, shown: legacyShown, total };
|
|
238
|
+
}
|
|
239
|
+
const total = event.incidentCount ?? 0;
|
|
240
|
+
return { lines: [], shown: 0, total };
|
|
241
|
+
}
|
|
242
|
+
function formatRow(event, detailBytes = MAX_FAILURE_BYTES + MAX_DECISION_BYTES) {
|
|
243
|
+
const source = boundedField(event.source, 40);
|
|
244
|
+
const id = boundedField(event.id, MAX_ID_BYTES);
|
|
245
|
+
const label = boundedField(event.label, MAX_LABEL_BYTES);
|
|
246
|
+
const status = boundedStatus(event.status);
|
|
247
|
+
const inspect = inspectFor(event);
|
|
248
|
+
const lines = [
|
|
249
|
+
`- source=${source} | id=${id} | label=${JSON.stringify(label)} | status=${status} | inspect: ${inspect}`,
|
|
250
|
+
];
|
|
251
|
+
if (event.outcome) {
|
|
252
|
+
const outcome = boundedField(event.outcome, 80);
|
|
253
|
+
if (outcome && outcome !== status)
|
|
254
|
+
lines.push(` outcome=${outcome}`);
|
|
255
|
+
}
|
|
256
|
+
const decisionBytes = Math.min(MAX_DECISION_BYTES, Math.floor(detailBytes / 2));
|
|
257
|
+
if (event.decision && decisionBytes > 24)
|
|
258
|
+
lines.push(` decision: ${boundedField(event.decision, decisionBytes)}`);
|
|
259
|
+
const incidents = eventIncidents(event, Math.max(0, Math.min(MAX_FAILURE_BYTES * 2, detailBytes - decisionBytes)));
|
|
260
|
+
lines.push(...incidents.lines);
|
|
261
|
+
const counts = countsLine(incidents, inspect);
|
|
262
|
+
if (counts)
|
|
263
|
+
lines.push(counts);
|
|
264
|
+
return lines.join("\n");
|
|
265
|
+
}
|
|
266
|
+
function renderBatch(represented, omitted, detailBytes) {
|
|
267
|
+
const count = represented.length;
|
|
268
|
+
const heading = `${count} background completion${count === 1 ? " is" : "s are"} ready:`;
|
|
269
|
+
const omittedLine = omitted > 0
|
|
270
|
+
? `${omitted} more completion${omitted === 1 ? "" : "s"} omitted from this batch (not receipted; still queued).`
|
|
271
|
+
: undefined;
|
|
272
|
+
return [heading, ...represented.map((event) => formatRow(event, detailBytes)), omittedLine, RETRIEVAL_FOOTER]
|
|
273
|
+
.filter((line) => Boolean(line))
|
|
274
|
+
.join("\n");
|
|
275
|
+
}
|
|
276
|
+
function clipRendered(text, maxBytes) {
|
|
277
|
+
if (utf8ByteLength(text) <= maxBytes)
|
|
278
|
+
return text;
|
|
279
|
+
const suffix = "\n[clipped to callback budget]";
|
|
280
|
+
const budget = maxBytes - utf8ByteLength(suffix);
|
|
281
|
+
if (budget < 24)
|
|
282
|
+
return clipUtf8Prefix(text, maxBytes);
|
|
283
|
+
return `${clipUtf8Prefix(text, budget)}${suffix}`;
|
|
284
|
+
}
|
|
285
|
+
function eventPriority(event) {
|
|
286
|
+
if (event.failure || event.failureRows?.length || (event.omittedIncidents ?? 0) > 0 || (event.incidentCount ?? 0) > 0)
|
|
287
|
+
return 0;
|
|
288
|
+
if (event.decision)
|
|
289
|
+
return 1;
|
|
290
|
+
const status = String(event.status ?? "").toLowerCase();
|
|
291
|
+
if (/(?:fail|orphan|lost|timed_out|timeout|unresolved|incomplete|observation incomplete)/.test(status))
|
|
292
|
+
return 0;
|
|
293
|
+
return 2;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Urgent health/failure callback under the total budget. Order: header,
|
|
297
|
+
* explanation, whole incident rows that fit, the incident count line (total,
|
|
298
|
+
* shown, omitted, retrieval), and the inspect line. The count and inspect
|
|
299
|
+
* lines are never dropped; unshown explanation bytes are counted.
|
|
300
|
+
*/
|
|
301
|
+
export function formatUrgentCallback(event, options = {}) {
|
|
302
|
+
const maxBytes = callbackBatchBudget(options.maxBytes);
|
|
303
|
+
const target = event.inspectId ?? event.id;
|
|
304
|
+
const id = boundedField(target, MAX_ID_BYTES);
|
|
305
|
+
const label = boundedField(event.label, MAX_LABEL_BYTES);
|
|
306
|
+
const status = boundedStatus(event.status);
|
|
307
|
+
const tool = event.detailTool
|
|
308
|
+
?? (event.source === "background-task" ? "bg_task_status" : "subagent_result");
|
|
309
|
+
const inspectTarget = tool === "bg_task_status" ? `bg_task_status id=${id}` : `subagent_result id=${JSON.stringify(id)}`;
|
|
310
|
+
const inspect = `Inspect: ${inspectTarget}`;
|
|
311
|
+
const header = `${boundedField(event.source, 40)} id=${id} label=${JSON.stringify(label)} status=${status}`;
|
|
312
|
+
const source = String(event.content ?? "").trim();
|
|
313
|
+
const rows = event.failureRows ?? [];
|
|
314
|
+
const total = rows.length ? Math.max(rows.length, event.incidentCount ?? 0) : event.incidentCount ?? 0;
|
|
315
|
+
const legacyOmitted = rows.length ? 0 : event.omittedIncidents ?? 0;
|
|
316
|
+
const counts = (shown) => {
|
|
317
|
+
if (total <= 0)
|
|
318
|
+
return undefined;
|
|
319
|
+
const omitted = rows.length ? total - shown : legacyOmitted;
|
|
320
|
+
const shownPart = rows.length ? ` shown=${shown}` : "";
|
|
321
|
+
return `incidents=${total}${shownPart}` +
|
|
322
|
+
(omitted > 0 ? ` omittedIncidents=${omitted} retrieve: ${inspectTarget} (incident pages via cursor)` : "");
|
|
323
|
+
};
|
|
324
|
+
const render = (body, note, shownRows) => [header, body, note, ...shownRows, counts(shownRows.length), inspect]
|
|
325
|
+
.filter((part) => Boolean(part && part.length > 0))
|
|
326
|
+
.join("\n");
|
|
327
|
+
const fixed = utf8ByteLength(render("", undefined, [])) + 16;
|
|
328
|
+
const room = Math.max(0, maxBytes - fixed);
|
|
329
|
+
// The explanation keeps at least half the room when incident rows compete.
|
|
330
|
+
const contentShare = rows.length ? Math.floor(room / 2) : room;
|
|
331
|
+
let body = source;
|
|
332
|
+
let note;
|
|
333
|
+
if (utf8ByteLength(source) > contentShare) {
|
|
334
|
+
const noteFor = (omitted) => `omittedBytes=${omitted} retrieve: ${inspectTarget}`;
|
|
335
|
+
const clipped = clipUtf8Prefix(source, Math.max(0, contentShare - utf8ByteLength(noteFor(utf8ByteLength(source))) - 1));
|
|
336
|
+
body = clipped;
|
|
337
|
+
note = noteFor(utf8ByteLength(source) - utf8ByteLength(clipped));
|
|
338
|
+
}
|
|
339
|
+
const shown = [];
|
|
340
|
+
for (const row of rows) {
|
|
341
|
+
const line = String(row).replace(/\s+/g, " ").trim();
|
|
342
|
+
if (utf8ByteLength(render(body, note, [...shown, line])) + 8 > maxBytes)
|
|
343
|
+
break;
|
|
344
|
+
shown.push(line);
|
|
345
|
+
}
|
|
346
|
+
const rendered = render(body, note, shown);
|
|
347
|
+
if (utf8ByteLength(rendered) <= maxBytes)
|
|
348
|
+
return rendered;
|
|
349
|
+
const minimal = render("", source ? `omittedBytes=${utf8ByteLength(source)} retrieve: ${inspectTarget}` : undefined, []);
|
|
350
|
+
return clipRendered(minimal, maxBytes);
|
|
351
|
+
}
|
|
352
|
+
export function packCallbackBatch(events, options = {}) {
|
|
353
|
+
const maxBytes = callbackBatchBudget(options.maxBytes);
|
|
354
|
+
if (events.length === 0) {
|
|
355
|
+
return { text: renderBatch([], 0), represented: [], omitted: 0 };
|
|
356
|
+
}
|
|
357
|
+
const ranked = events.map((event, index) => ({ event, index }))
|
|
358
|
+
.sort((a, b) => eventPriority(a.event) - eventPriority(b.event) || a.index - b.index);
|
|
359
|
+
const selected = new Set();
|
|
360
|
+
const renderSelected = () => {
|
|
361
|
+
const represented = events.filter((_, index) => selected.has(index));
|
|
362
|
+
return renderBatch(represented, events.length - selected.size);
|
|
363
|
+
};
|
|
364
|
+
for (const { index } of ranked) {
|
|
365
|
+
selected.add(index);
|
|
366
|
+
if (utf8ByteLength(renderSelected()) <= maxBytes)
|
|
367
|
+
continue;
|
|
368
|
+
selected.delete(index);
|
|
369
|
+
if (selected.size === 0) {
|
|
370
|
+
// One row alone exceeds the budget: shrink its detail, never its counts.
|
|
371
|
+
const event = events[index];
|
|
372
|
+
for (const detail of [MAX_FAILURE_BYTES, 200, 0]) {
|
|
373
|
+
const text = renderBatch([event], events.length - 1, detail);
|
|
374
|
+
if (utf8ByteLength(text) <= maxBytes) {
|
|
375
|
+
return { text, represented: [event], omitted: events.length - 1 };
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return {
|
|
379
|
+
text: clipRendered(renderBatch([event], events.length - 1, 0), maxBytes),
|
|
380
|
+
represented: [event],
|
|
381
|
+
omitted: events.length - 1,
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
const represented = events.filter((_, index) => selected.has(index));
|
|
386
|
+
return {
|
|
387
|
+
text: renderSelected(),
|
|
388
|
+
represented,
|
|
389
|
+
omitted: events.length - represented.length,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
export function formatCallbackBatch(events, options = {}) {
|
|
393
|
+
return packCallbackBatch(events, options).text;
|
|
394
|
+
}
|
|
395
|
+
export function createCallbackBatcher(host, options = {}) {
|
|
396
|
+
const windowMs = options.windowMs ?? resolveCallbackBatchWindowMs();
|
|
397
|
+
const retryMs = Math.max(0, options.retryMs ?? DEFAULT_RETRY_MS);
|
|
398
|
+
let whileBusy = options.whileBusy ?? "hold";
|
|
399
|
+
const maxBytes = callbackBatchBudget(options.maxBytes);
|
|
400
|
+
const pending = new Map();
|
|
401
|
+
const inFlight = new Set();
|
|
402
|
+
const urgentInFlight = new Set();
|
|
403
|
+
const urgentSettlements = new Set();
|
|
404
|
+
const handedOff = new Map();
|
|
405
|
+
const activeTools = new Set();
|
|
406
|
+
let sequence = 0;
|
|
407
|
+
let timer;
|
|
408
|
+
let flushPromise;
|
|
409
|
+
let isAvailable = options.isAvailable ?? (() => true);
|
|
410
|
+
let gated = options.isAvailable !== undefined;
|
|
411
|
+
let awaitingRun = false;
|
|
412
|
+
let cancelled = false;
|
|
413
|
+
let foregroundRunning = false;
|
|
414
|
+
const deliveryMode = () => {
|
|
415
|
+
if (cancelled)
|
|
416
|
+
return undefined;
|
|
417
|
+
try {
|
|
418
|
+
if (!isAvailable()) {
|
|
419
|
+
awaitingRun = false;
|
|
420
|
+
return whileBusy === "steer" && foregroundRunning && activeTools.size === 0 ? "steer" : undefined;
|
|
421
|
+
}
|
|
422
|
+
return !awaitingRun ? "followUp" : undefined;
|
|
423
|
+
}
|
|
424
|
+
catch {
|
|
425
|
+
return undefined;
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
const cancelTimer = () => {
|
|
429
|
+
if (timer)
|
|
430
|
+
clearTimeout(timer);
|
|
431
|
+
timer = undefined;
|
|
432
|
+
};
|
|
433
|
+
const schedule = (delayMs) => {
|
|
434
|
+
if (timer || pending.size === 0)
|
|
435
|
+
return;
|
|
436
|
+
// Some idle transitions (manual compaction) have no agent_settled event.
|
|
437
|
+
const delay = deliveryMode() ? delayMs : retryMs;
|
|
438
|
+
timer = setTimeout(() => {
|
|
439
|
+
timer = undefined;
|
|
440
|
+
void api.flush();
|
|
441
|
+
}, Math.max(1, delay));
|
|
442
|
+
timer.unref?.();
|
|
443
|
+
};
|
|
444
|
+
const enqueue = (event) => {
|
|
445
|
+
if (event.callback === false)
|
|
446
|
+
return false;
|
|
447
|
+
const key = completionKey(event);
|
|
448
|
+
if (pending.has(key) || inFlight.has(key))
|
|
449
|
+
return false;
|
|
450
|
+
pending.set(key, { event, sequence: sequence++ });
|
|
451
|
+
schedule(windowMs);
|
|
452
|
+
return true;
|
|
453
|
+
};
|
|
454
|
+
const performFlush = async () => {
|
|
455
|
+
cancelTimer();
|
|
456
|
+
const mode = deliveryMode();
|
|
457
|
+
if (!mode) {
|
|
458
|
+
schedule(retryMs);
|
|
459
|
+
return false;
|
|
460
|
+
}
|
|
461
|
+
const snapshot = [...pending.entries()]
|
|
462
|
+
.sort((a, b) => a[1].sequence - b[1].sequence);
|
|
463
|
+
pending.clear();
|
|
464
|
+
for (const [key] of snapshot)
|
|
465
|
+
inFlight.add(key);
|
|
466
|
+
const deliverable = [];
|
|
467
|
+
let deferred = false;
|
|
468
|
+
for (const item of snapshot) {
|
|
469
|
+
const [key, pendingEvent] = item;
|
|
470
|
+
const priorHandoff = handedOff.get(key);
|
|
471
|
+
if (priorHandoff !== undefined) {
|
|
472
|
+
if (!invokeDelivered(pendingEvent.event, priorHandoff)) {
|
|
473
|
+
deferred = true;
|
|
474
|
+
pending.set(key, pendingEvent);
|
|
475
|
+
}
|
|
476
|
+
inFlight.delete(key);
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
const disposition = eventDisposition(pendingEvent.event);
|
|
480
|
+
if (disposition.kind === "deferred") {
|
|
481
|
+
deferred = true;
|
|
482
|
+
pending.set(key, pendingEvent);
|
|
483
|
+
inFlight.delete(key);
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
if (disposition.kind === "delivered") {
|
|
487
|
+
inFlight.delete(key);
|
|
488
|
+
continue;
|
|
489
|
+
}
|
|
490
|
+
if (disposition.kind === "suppressed") {
|
|
491
|
+
invokeSuppressed(pendingEvent.event, disposition.reason, Date.now());
|
|
492
|
+
inFlight.delete(key);
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
deliverable.push(item);
|
|
496
|
+
}
|
|
497
|
+
if (deliverable.length === 0) {
|
|
498
|
+
if (pending.size > 0)
|
|
499
|
+
schedule(deferred ? retryMs : windowMs);
|
|
500
|
+
return !deferred;
|
|
501
|
+
}
|
|
502
|
+
const packed = packCallbackBatch(deliverable.map(([, item]) => item.event), { maxBytes });
|
|
503
|
+
const representedSet = new Set(packed.represented);
|
|
504
|
+
const representedItems = deliverable.filter(([, item]) => representedSet.has(item.event));
|
|
505
|
+
const overflowItems = deliverable.filter(([, item]) => !representedSet.has(item.event));
|
|
506
|
+
const receiptDetails = { completionEventIds: representedItems.map(([, item]) => item.event.receiptId).filter((id) => Boolean(id)) };
|
|
507
|
+
try {
|
|
508
|
+
// Pi may defer the requested run while settled handlers finish, leaving
|
|
509
|
+
// isIdle() true. Permit no second handoff until a run starts.
|
|
510
|
+
awaitingRun = mode === "followUp" && gated;
|
|
511
|
+
await host.sendMessage({
|
|
512
|
+
customType: "background-completion-batch",
|
|
513
|
+
content: packed.text,
|
|
514
|
+
display: true,
|
|
515
|
+
...(receiptDetails.completionEventIds.length ? { details: receiptDetails } : {}),
|
|
516
|
+
},
|
|
517
|
+
// Newer Pi requires triggerTurn for steering too; false only appends
|
|
518
|
+
// a custom message at the turn boundary without continuing the agent.
|
|
519
|
+
{ deliverAs: mode, triggerTurn: true });
|
|
520
|
+
}
|
|
521
|
+
catch {
|
|
522
|
+
receiptDetails.completionEventIds.length = 0;
|
|
523
|
+
awaitingRun = false;
|
|
524
|
+
for (const [key] of deliverable)
|
|
525
|
+
inFlight.delete(key);
|
|
526
|
+
const retryItems = [...deliverable, ...pending.entries()]
|
|
527
|
+
.sort((a, b) => a[1].sequence - b[1].sequence);
|
|
528
|
+
pending.clear();
|
|
529
|
+
for (const [key, item] of retryItems) {
|
|
530
|
+
if (!pending.has(key))
|
|
531
|
+
pending.set(key, item);
|
|
532
|
+
}
|
|
533
|
+
schedule(retryMs);
|
|
534
|
+
return false;
|
|
535
|
+
}
|
|
536
|
+
const deliveredAt = Date.now();
|
|
537
|
+
for (const [key, item] of representedItems) {
|
|
538
|
+
handedOff.set(key, deliveredAt);
|
|
539
|
+
if (!invokeDelivered(item.event, deliveredAt)) {
|
|
540
|
+
deferred = true;
|
|
541
|
+
pending.set(key, item);
|
|
542
|
+
}
|
|
543
|
+
inFlight.delete(key);
|
|
544
|
+
}
|
|
545
|
+
for (const [key, item] of overflowItems) {
|
|
546
|
+
pending.set(key, item);
|
|
547
|
+
inFlight.delete(key);
|
|
548
|
+
}
|
|
549
|
+
if (pending.size > 0)
|
|
550
|
+
schedule(deferred ? retryMs : windowMs);
|
|
551
|
+
return !deferred;
|
|
552
|
+
};
|
|
553
|
+
const flush = () => {
|
|
554
|
+
if (flushPromise)
|
|
555
|
+
return flushPromise;
|
|
556
|
+
flushPromise = performFlush().finally(() => {
|
|
557
|
+
flushPromise = undefined;
|
|
558
|
+
});
|
|
559
|
+
return flushPromise;
|
|
560
|
+
};
|
|
561
|
+
const deliverUrgent = (event) => {
|
|
562
|
+
const key = eventKey(event);
|
|
563
|
+
if (urgentInFlight.has(key))
|
|
564
|
+
return false;
|
|
565
|
+
const priorHandoff = handedOff.get(key);
|
|
566
|
+
if (priorHandoff !== undefined)
|
|
567
|
+
return invokeDelivered(event, priorHandoff);
|
|
568
|
+
const acknowledge = () => {
|
|
569
|
+
const at = Date.now();
|
|
570
|
+
handedOff.set(key, at);
|
|
571
|
+
return invokeDelivered(event, at);
|
|
572
|
+
};
|
|
573
|
+
const disposition = eventDisposition(event);
|
|
574
|
+
if (disposition.kind === "deferred")
|
|
575
|
+
return false;
|
|
576
|
+
if (disposition.kind === "delivered")
|
|
577
|
+
return true;
|
|
578
|
+
if (disposition.kind === "suppressed") {
|
|
579
|
+
invokeSuppressed(event, disposition.reason, Date.now());
|
|
580
|
+
return true;
|
|
581
|
+
}
|
|
582
|
+
urgentInFlight.add(key);
|
|
583
|
+
try {
|
|
584
|
+
const handoff = host.sendMessage({ customType: event.customType, content: formatUrgentCallback(event, { maxBytes }), display: true,
|
|
585
|
+
...(event.receiptId ? { details: { urgentEventId: event.receiptId } } : {}) }, { deliverAs: "followUp", triggerTurn: true });
|
|
586
|
+
if (isPromiseLike(handoff)) {
|
|
587
|
+
const settlement = Promise.resolve(handoff).then(() => acknowledge(), () => false).finally(() => { urgentInFlight.delete(key); urgentSettlements.delete(settlement); });
|
|
588
|
+
urgentSettlements.add(settlement);
|
|
589
|
+
return settlement;
|
|
590
|
+
}
|
|
591
|
+
const acknowledged = acknowledge();
|
|
592
|
+
urgentInFlight.delete(key);
|
|
593
|
+
return acknowledged;
|
|
594
|
+
}
|
|
595
|
+
catch {
|
|
596
|
+
urgentInFlight.delete(key);
|
|
597
|
+
return false;
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
const api = {
|
|
601
|
+
enqueue,
|
|
602
|
+
flush,
|
|
603
|
+
setHost(next) { host = next; },
|
|
604
|
+
setAvailability(check) {
|
|
605
|
+
gated = true;
|
|
606
|
+
isAvailable = check;
|
|
607
|
+
cancelled = false;
|
|
608
|
+
deliveryMode();
|
|
609
|
+
cancelTimer();
|
|
610
|
+
schedule(windowMs);
|
|
611
|
+
},
|
|
612
|
+
setWhileBusy(mode) {
|
|
613
|
+
if (!isDeliveryMode(mode))
|
|
614
|
+
throw new Error("Invalid callback delivery mode. Nothing changed.");
|
|
615
|
+
whileBusy = mode;
|
|
616
|
+
cancelTimer();
|
|
617
|
+
schedule(windowMs);
|
|
618
|
+
},
|
|
619
|
+
setForegroundRunning(running) {
|
|
620
|
+
foregroundRunning = running;
|
|
621
|
+
cancelTimer();
|
|
622
|
+
schedule(windowMs);
|
|
623
|
+
},
|
|
624
|
+
toolStarted(toolCallId) {
|
|
625
|
+
activeTools.add(toolCallId);
|
|
626
|
+
},
|
|
627
|
+
async toolEnded(toolCallId) {
|
|
628
|
+
const ended = activeTools.delete(toolCallId);
|
|
629
|
+
if (activeTools.size > 0 || whileBusy !== "steer" || cancelled)
|
|
630
|
+
return false;
|
|
631
|
+
if (!ended)
|
|
632
|
+
return flushPromise ?? false;
|
|
633
|
+
// A timer may still be completing a deferred flush. Recheck after it so
|
|
634
|
+
// the tool boundary cannot lose the pending batch to that older attempt.
|
|
635
|
+
if (flushPromise)
|
|
636
|
+
await flushPromise;
|
|
637
|
+
return pending.size > 0 ? api.flush() : true;
|
|
638
|
+
},
|
|
639
|
+
deliverUrgent,
|
|
640
|
+
async settled() {
|
|
641
|
+
await flushPromise;
|
|
642
|
+
await Promise.all([...urgentSettlements]);
|
|
643
|
+
},
|
|
644
|
+
cancel() {
|
|
645
|
+
cancelTimer();
|
|
646
|
+
pending.clear();
|
|
647
|
+
awaitingRun = false;
|
|
648
|
+
activeTools.clear();
|
|
649
|
+
foregroundRunning = false;
|
|
650
|
+
cancelled = true;
|
|
651
|
+
},
|
|
652
|
+
pendingCount() {
|
|
653
|
+
return pending.size;
|
|
654
|
+
},
|
|
655
|
+
};
|
|
656
|
+
return api;
|
|
657
|
+
}
|
|
658
|
+
export function getCallbackBatcher(host, options = {}) {
|
|
659
|
+
const state = globalState();
|
|
660
|
+
const key = host.events ?? host;
|
|
661
|
+
const existing = state.byHost.get(key);
|
|
662
|
+
if (existing) {
|
|
663
|
+
existing.setHost(host);
|
|
664
|
+
return existing;
|
|
665
|
+
}
|
|
666
|
+
const created = createCallbackBatcher(host, options);
|
|
667
|
+
state.byHost.set(key, created);
|
|
668
|
+
return created;
|
|
669
|
+
}
|
|
670
|
+
export function cancelCallbackBatch(host) {
|
|
671
|
+
const batcher = globalState().byHost.get(host.events ?? host);
|
|
672
|
+
batcher?.setAvailability(() => false);
|
|
673
|
+
batcher?.cancel();
|
|
674
|
+
}
|
|
675
|
+
/** Restore current branch/default mode without resetting foreground tools or receipts. */
|
|
676
|
+
export function setCallbackBatchContext(host, ctx, seams = {}) {
|
|
677
|
+
const batcher = bindCallbackBatcher(host, ctx);
|
|
678
|
+
let mode = "hold";
|
|
679
|
+
try {
|
|
680
|
+
const settings = getCallbackSettings(ctx, seams);
|
|
681
|
+
if (settings.source === "session") {
|
|
682
|
+
// Capture the initial default even when an override currently hides it,
|
|
683
|
+
// so navigating to an unconfigured branch cannot inherit a later save.
|
|
684
|
+
try {
|
|
685
|
+
getSessionDefault(ctx, seams);
|
|
686
|
+
}
|
|
687
|
+
catch {
|
|
688
|
+
if (ctx.sessionManager) {
|
|
689
|
+
const defaults = globalState().sessionDefaults ??= new WeakMap();
|
|
690
|
+
defaults.set(ctx.sessionManager, { sessionId: ctx.sessionManager.getSessionId?.(), mode: "hold" });
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
mode = settings.mode;
|
|
695
|
+
}
|
|
696
|
+
catch (error) {
|
|
697
|
+
try {
|
|
698
|
+
ctx.ui?.notify(`Callback delivery restored to hold: ${String(error)}`, "error");
|
|
699
|
+
}
|
|
700
|
+
catch { /* A failing UI must not retain the prior session's delivery mode. */ }
|
|
701
|
+
}
|
|
702
|
+
batcher.setWhileBusy(mode);
|
|
703
|
+
// Schedule rather than await delivery inside agent_settled: its handlers are
|
|
704
|
+
// still settling the previous run, and sendMessage may start a new one.
|
|
705
|
+
batcher.setAvailability(() => ctx.isIdle());
|
|
706
|
+
}
|
|
707
|
+
function bindCallbackBatcher(host, ctx) {
|
|
708
|
+
const state = globalState();
|
|
709
|
+
const bySession = state.bySession ??= new WeakMap();
|
|
710
|
+
const shared = ctx.sessionManager ? bySession.get(ctx.sessionManager) : undefined;
|
|
711
|
+
const batcher = shared ?? getCallbackBatcher(host);
|
|
712
|
+
if (ctx.sessionManager)
|
|
713
|
+
bySession.set(ctx.sessionManager, batcher);
|
|
714
|
+
state.byHost.set(host.events ?? host, batcher);
|
|
715
|
+
batcher.setHost(host);
|
|
716
|
+
return batcher;
|
|
717
|
+
}
|
|
718
|
+
function globalState() {
|
|
719
|
+
const root = globalThis;
|
|
720
|
+
root[GLOBAL_STATE_KEY] ??= { byHost: new WeakMap() };
|
|
721
|
+
return root[GLOBAL_STATE_KEY];
|
|
722
|
+
}
|
|
723
|
+
function eventKey(event) {
|
|
724
|
+
return `${event.source}\u0000${event.id}\u0000${event.status}`;
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Ordinary completion identity is the run/task id, not the status wording (#624).
|
|
728
|
+
*
|
|
729
|
+
* The status field is a snapshot taken when a notification is enqueued (failure
|
|
730
|
+
* notes, observation gaps, timing reason). Including it in the key meant a
|
|
731
|
+
* not-yet-delivered run whose status changed between enqueues entered the
|
|
732
|
+
* pending map twice; one flush then rendered both rows and the caller saw one
|
|
733
|
+
* completion twice. Urgent events keep the status in their key: those are
|
|
734
|
+
* distinct transitions (orphaned, lost, a timing wake, a failure key), not
|
|
735
|
+
* restatements of a single ordinary completion. The first queued snapshot is the
|
|
736
|
+
* one delivered; a later status wording for the same id is dropped rather than
|
|
737
|
+
* re-queued, and the durable result stays the authority for failure detail.
|
|
738
|
+
*/
|
|
739
|
+
function completionKey(event) {
|
|
740
|
+
return `${event.source}\u0000${event.id}`;
|
|
741
|
+
}
|
|
742
|
+
function eventDisposition(event) {
|
|
743
|
+
try {
|
|
744
|
+
if (event.isDelivered?.())
|
|
745
|
+
return { kind: "delivered" };
|
|
746
|
+
}
|
|
747
|
+
catch {
|
|
748
|
+
return { kind: "deferred" };
|
|
749
|
+
}
|
|
750
|
+
try {
|
|
751
|
+
const reason = event.getSuppressionReason?.();
|
|
752
|
+
return reason ? { kind: "suppressed", reason } : { kind: "deliver" };
|
|
753
|
+
}
|
|
754
|
+
catch {
|
|
755
|
+
return { kind: "deferred" };
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
function invokeDelivered(event, at) {
|
|
759
|
+
try {
|
|
760
|
+
event.onDelivered?.(at);
|
|
761
|
+
return true;
|
|
762
|
+
}
|
|
763
|
+
catch {
|
|
764
|
+
return false;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
function invokeSuppressed(event, reason, at) {
|
|
768
|
+
try {
|
|
769
|
+
event.onSuppressed?.(reason, at);
|
|
770
|
+
}
|
|
771
|
+
catch { /* best effort durable suppression */ }
|
|
772
|
+
}
|
|
773
|
+
function isPromiseLike(value) {
|
|
774
|
+
return (typeof value === "object" || typeof value === "function")
|
|
775
|
+
&& value !== null
|
|
776
|
+
&& typeof value.then === "function";
|
|
777
|
+
}
|