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,55 @@
|
|
|
1
|
+
import { shouldRestoreWorkObservation } from "./shared-work-client.mjs";
|
|
2
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import { initializeNavigatorPanels } from "./shared-navigator-panels.ts";
|
|
4
|
+
import { registerBackgroundTasksGoalProvider } from "./goal-provider.js";
|
|
5
|
+
import { createBackgroundTasksNavigator } from "./navigator-provider.js";
|
|
6
|
+
import { createManagedBackgroundFrontend } from "./managed-frontend.js";
|
|
7
|
+
import { observeForegroundSandboxPolicy } from "./sandbox.js";
|
|
8
|
+
import { registerTools } from "./tools.js";
|
|
9
|
+
import { deliverBackgroundTasksPrompt } from "./prompt.js";
|
|
10
|
+
import { closeBackgroundObservation } from "./work-observation.js";
|
|
11
|
+
|
|
12
|
+
export default function backgroundTasksExtension(pi: ExtensionAPI): void {
|
|
13
|
+
// The frontend owns native UI/delivery only. Mechanical tools run in the
|
|
14
|
+
// fixed server service. Register their native definitions before the first turn.
|
|
15
|
+
const {host: observedWaits, proxy, ui} = createManagedBackgroundFrontend(pi);
|
|
16
|
+
const navigator = createBackgroundTasksNavigator(undefined, ui);
|
|
17
|
+
initializeNavigatorPanels(pi);
|
|
18
|
+
// Sections on a host that renders them; text only where it renders none.
|
|
19
|
+
// Returning a prompt on modern pi would set forceSystemPrompt, and the request
|
|
20
|
+
// would then carry a snapshot, so sections published after it never arrive.
|
|
21
|
+
pi.on("before_agent_start", (event) => deliverBackgroundTasksPrompt(event));
|
|
22
|
+
registerBackgroundTasksGoalProvider(pi);
|
|
23
|
+
navigator.ensureBackgroundTasksNavigatorProvider(pi);
|
|
24
|
+
// Subscribed at load so a sandbox extension that publishes later is heard, and
|
|
25
|
+
// asked for a snapshot in case one published before this extension existed.
|
|
26
|
+
observeForegroundSandboxPolicy(pi);
|
|
27
|
+
// Registered before registerTools(pi), so this runs before running tasks are resumed.
|
|
28
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
29
|
+
registerBackgroundTasksGoalProvider(pi);
|
|
30
|
+
navigator.ensureBackgroundTasksNavigator(ctx);
|
|
31
|
+
});
|
|
32
|
+
pi.on("session_before_switch", async () => {
|
|
33
|
+
closeBackgroundObservation(pi);
|
|
34
|
+
observedWaits.close();
|
|
35
|
+
navigator.clearBackgroundTasksNavigatorSession();
|
|
36
|
+
});
|
|
37
|
+
pi.on("session_shutdown", async (_event, ctx) => {
|
|
38
|
+
closeBackgroundObservation(pi);
|
|
39
|
+
// /reload, session replacement, and quit load a fresh instance; stop this one's timers (#324).
|
|
40
|
+
observedWaits.close();
|
|
41
|
+
navigator.clearBackgroundTasksNavigatorSession();
|
|
42
|
+
});
|
|
43
|
+
registerTools(proxy, undefined, navigator.refreshBackgroundTasksNavigator, {resumeLocal:false});
|
|
44
|
+
// Registered after registerTools so the callback batcher has its session
|
|
45
|
+
// context before a reconciled delivery can enqueue a parent notification.
|
|
46
|
+
pi.on("session_start", (event, ctx) => {
|
|
47
|
+
observedWaits.start(ctx, shouldRestoreWorkObservation(event, ctx.sessionManager));
|
|
48
|
+
});
|
|
49
|
+
// A fork or branch navigation does not restart the session, but it changes
|
|
50
|
+
// which continuation may receive a queued callback. Update the host snapshot
|
|
51
|
+
// on the same event the callback batcher uses.
|
|
52
|
+
pi.on("session_tree", async (_event, ctx) => {
|
|
53
|
+
observedWaits.noteParentContext(ctx);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-background-tasks/src/logs.ts. Do not edit directly.
|
|
2
|
+
import { appendFileSync, closeSync, openSync, readSync, statSync, truncateSync } from "node:fs";
|
|
3
|
+
import { dirname } from "node:path";
|
|
4
|
+
import { mkdirSync } from "node:fs";
|
|
5
|
+
import { pageRetainedFile, readBoundedTail, tailTerminalDisplay, terminalDisplayRows } from "./shared-log-utils.domain.mjs";
|
|
6
|
+
export const DEFAULT_MAX_LOG_BYTES = 4 * 1024 * 1024;
|
|
7
|
+
export const MAX_LOG_TAIL_READ_BYTES = 512 * 1024;
|
|
8
|
+
const RETAINED_LOG_FRACTION = 0.75;
|
|
9
|
+
export function appendWatchResult(logPath, result) {
|
|
10
|
+
mkdirSync(dirname(logPath), { recursive: true });
|
|
11
|
+
const capture = result.captureTruncated
|
|
12
|
+
? ` capture_discarded_stdout=${result.stdoutDiscardedBytes ?? 0} capture_discarded_stderr=${result.stderrDiscardedBytes ?? 0}`
|
|
13
|
+
: "";
|
|
14
|
+
const header = `\n--- check ${new Date(result.startedAt).toISOString()} exit=${result.exitCode ?? "null"} signal=${result.signal ?? "null"} duration_ms=${result.endedAt - result.startedAt}${capture} ---\n`;
|
|
15
|
+
appendFileSync(logPath, header);
|
|
16
|
+
if (result.stdout)
|
|
17
|
+
appendFileSync(logPath, result.stdout.endsWith("\n") ? result.stdout : `${result.stdout}\n`);
|
|
18
|
+
if (result.stderr)
|
|
19
|
+
appendFileSync(logPath, `[stderr]\n${result.stderr.endsWith("\n") ? result.stderr : `${result.stderr}\n`}`);
|
|
20
|
+
}
|
|
21
|
+
export function appendLine(logPath, line) {
|
|
22
|
+
mkdirSync(dirname(logPath), { recursive: true });
|
|
23
|
+
appendFileSync(logPath, `${line}\n`);
|
|
24
|
+
}
|
|
25
|
+
export function appendTaskOutput(logPath, output) {
|
|
26
|
+
if (!output)
|
|
27
|
+
return;
|
|
28
|
+
mkdirSync(dirname(logPath), { recursive: true });
|
|
29
|
+
appendFileSync(logPath, output);
|
|
30
|
+
}
|
|
31
|
+
export function readLog(logPath, tailLines) {
|
|
32
|
+
const requestedRows = tailLines && tailLines > 0 ? Math.floor(tailLines) : undefined;
|
|
33
|
+
const tail = readBoundedTail(logPath, MAX_LOG_TAIL_READ_BYTES);
|
|
34
|
+
if (tail.error) {
|
|
35
|
+
return { text: "", truncated: tail.truncated, totalBytes: tail.totalBytes, error: tail.error };
|
|
36
|
+
}
|
|
37
|
+
if (!tail.text)
|
|
38
|
+
return { text: "", truncated: false, totalBytes: tail.totalBytes };
|
|
39
|
+
if (!requestedRows)
|
|
40
|
+
return { text: tail.text, truncated: tail.truncated, totalBytes: tail.totalBytes };
|
|
41
|
+
const rows = terminalDisplayRows(tail.text);
|
|
42
|
+
const omittedRows = Math.max(0, rows.length - requestedRows);
|
|
43
|
+
return {
|
|
44
|
+
text: tailTerminalDisplay(tail.text, requestedRows),
|
|
45
|
+
truncated: tail.truncated || omittedRows > 0,
|
|
46
|
+
totalBytes: tail.totalBytes,
|
|
47
|
+
...(omittedRows > 0 ? { omittedRows } : {}),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export function captureGapsFor(meta) {
|
|
51
|
+
const gaps = [];
|
|
52
|
+
if (meta.stdoutDiscardedBytes) {
|
|
53
|
+
gaps.push({ bytes: meta.stdoutDiscardedBytes, detail: "stdout capture overflow" });
|
|
54
|
+
}
|
|
55
|
+
if (meta.stderrDiscardedBytes) {
|
|
56
|
+
gaps.push({ bytes: meta.stderrDiscardedBytes, detail: "stderr capture overflow" });
|
|
57
|
+
}
|
|
58
|
+
if (!gaps.length && meta.captureDiscardedBytes) {
|
|
59
|
+
gaps.push({ bytes: meta.captureDiscardedBytes, detail: `${meta.captureOverflowEvents ?? 1} capture overflow(s)` });
|
|
60
|
+
}
|
|
61
|
+
return gaps;
|
|
62
|
+
}
|
|
63
|
+
/** Page retained raw bytes with this task's generation and disclosed capture/retention loss. */
|
|
64
|
+
export function pageTaskLog(meta, request = {}) {
|
|
65
|
+
return pageRetainedFile(meta.logPath, {
|
|
66
|
+
...request,
|
|
67
|
+
resource: request.resource ?? meta.id,
|
|
68
|
+
generation: request.generation ?? meta.logGeneration ?? 0,
|
|
69
|
+
discardedBytes: request.discardedBytes ?? meta.logDiscardedBytes,
|
|
70
|
+
captureGaps: request.captureGaps ?? captureGapsFor(meta),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
export function resolveMaxLogBytes(value) {
|
|
74
|
+
if (value === undefined || !Number.isFinite(value) || value <= 0)
|
|
75
|
+
return DEFAULT_MAX_LOG_BYTES;
|
|
76
|
+
return Math.max(64 * 1024, Math.floor(value));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Compact in place so detached children keep writing to the same inode. A
|
|
80
|
+
* rename-based rotation would leave their inherited descriptor unbounded.
|
|
81
|
+
*/
|
|
82
|
+
export function retainLogTail(logPath, maxBytes) {
|
|
83
|
+
let size;
|
|
84
|
+
try {
|
|
85
|
+
size = statSync(logPath).size;
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
if (size <= maxBytes)
|
|
91
|
+
return undefined;
|
|
92
|
+
const start = Math.max(0, size - Math.floor(maxBytes * RETAINED_LOG_FRACTION));
|
|
93
|
+
let fd;
|
|
94
|
+
let retained;
|
|
95
|
+
try {
|
|
96
|
+
fd = openSync(logPath, "r");
|
|
97
|
+
retained = Buffer.allocUnsafe(size - start);
|
|
98
|
+
let offset = 0;
|
|
99
|
+
while (offset < retained.length) {
|
|
100
|
+
const read = readSync(fd, retained, offset, retained.length - offset, start + offset);
|
|
101
|
+
if (read <= 0)
|
|
102
|
+
break;
|
|
103
|
+
offset += read;
|
|
104
|
+
}
|
|
105
|
+
retained = retained.subarray(0, offset);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
if (fd !== undefined) {
|
|
112
|
+
try {
|
|
113
|
+
closeSync(fd);
|
|
114
|
+
}
|
|
115
|
+
catch { /* best effort */ }
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const discardedBytes = Math.max(0, size - retained.length);
|
|
119
|
+
try {
|
|
120
|
+
truncateSync(logPath, 0);
|
|
121
|
+
if (retained.length)
|
|
122
|
+
appendFileSync(logPath, retained);
|
|
123
|
+
appendFileSync(logPath, `--- log retention discarded ${discardedBytes} bytes; newest output retained ---\n`);
|
|
124
|
+
return { discardedBytes };
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { appendFileSync, closeSync, openSync, readSync, statSync, truncateSync } from "node:fs";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { mkdirSync } from "node:fs";
|
|
4
|
+
import { pageRetainedFile, readBoundedTail, tailTerminalDisplay, terminalDisplayRows } from "./shared-log-utils.js";
|
|
5
|
+
import type { FilePageRequest, PageResult } from "./shared-log-utils.js";
|
|
6
|
+
import type { BackgroundTaskMeta, CommandResult } from "./types.js";
|
|
7
|
+
|
|
8
|
+
export const DEFAULT_MAX_LOG_BYTES = 4 * 1024 * 1024;
|
|
9
|
+
export const MAX_LOG_TAIL_READ_BYTES = 512 * 1024;
|
|
10
|
+
const RETAINED_LOG_FRACTION = 0.75;
|
|
11
|
+
|
|
12
|
+
export function appendWatchResult(logPath: string, result: CommandResult): void {
|
|
13
|
+
mkdirSync(dirname(logPath), { recursive: true });
|
|
14
|
+
const capture = result.captureTruncated
|
|
15
|
+
? ` capture_discarded_stdout=${result.stdoutDiscardedBytes ?? 0} capture_discarded_stderr=${result.stderrDiscardedBytes ?? 0}`
|
|
16
|
+
: "";
|
|
17
|
+
const header = `\n--- check ${new Date(result.startedAt).toISOString()} exit=${result.exitCode ?? "null"} signal=${result.signal ?? "null"} duration_ms=${result.endedAt - result.startedAt}${capture} ---\n`;
|
|
18
|
+
appendFileSync(logPath, header);
|
|
19
|
+
if (result.stdout) appendFileSync(logPath, result.stdout.endsWith("\n") ? result.stdout : `${result.stdout}\n`);
|
|
20
|
+
if (result.stderr) appendFileSync(logPath, `[stderr]\n${result.stderr.endsWith("\n") ? result.stderr : `${result.stderr}\n`}`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function appendLine(logPath: string, line: string): void {
|
|
24
|
+
mkdirSync(dirname(logPath), { recursive: true });
|
|
25
|
+
appendFileSync(logPath, `${line}\n`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function appendTaskOutput(logPath: string, output: string): void {
|
|
29
|
+
if (!output) return;
|
|
30
|
+
mkdirSync(dirname(logPath), { recursive: true });
|
|
31
|
+
appendFileSync(logPath, output);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface LogRead {
|
|
35
|
+
text: string;
|
|
36
|
+
truncated: boolean;
|
|
37
|
+
totalBytes?: number;
|
|
38
|
+
error?: string;
|
|
39
|
+
/** Display rows before the returned tail within the bounded read window. */
|
|
40
|
+
omittedRows?: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function readLog(logPath: string, tailLines?: number): LogRead {
|
|
44
|
+
const requestedRows = tailLines && tailLines > 0 ? Math.floor(tailLines) : undefined;
|
|
45
|
+
const tail = readBoundedTail(logPath, MAX_LOG_TAIL_READ_BYTES);
|
|
46
|
+
if (tail.error) {
|
|
47
|
+
return { text: "", truncated: tail.truncated, totalBytes: tail.totalBytes, error: tail.error };
|
|
48
|
+
}
|
|
49
|
+
if (!tail.text) return { text: "", truncated: false, totalBytes: tail.totalBytes };
|
|
50
|
+
if (!requestedRows) return { text: tail.text, truncated: tail.truncated, totalBytes: tail.totalBytes };
|
|
51
|
+
const rows = terminalDisplayRows(tail.text);
|
|
52
|
+
const omittedRows = Math.max(0, rows.length - requestedRows);
|
|
53
|
+
return {
|
|
54
|
+
text: tailTerminalDisplay(tail.text, requestedRows),
|
|
55
|
+
truncated: tail.truncated || omittedRows > 0,
|
|
56
|
+
totalBytes: tail.totalBytes,
|
|
57
|
+
...(omittedRows > 0 ? { omittedRows } : {}),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function captureGapsFor(meta: BackgroundTaskMeta): Array<{ bytes: number; detail?: string }> {
|
|
62
|
+
const gaps: Array<{ bytes: number; detail?: string }> = [];
|
|
63
|
+
if (meta.stdoutDiscardedBytes) {
|
|
64
|
+
gaps.push({ bytes: meta.stdoutDiscardedBytes, detail: "stdout capture overflow" });
|
|
65
|
+
}
|
|
66
|
+
if (meta.stderrDiscardedBytes) {
|
|
67
|
+
gaps.push({ bytes: meta.stderrDiscardedBytes, detail: "stderr capture overflow" });
|
|
68
|
+
}
|
|
69
|
+
if (!gaps.length && meta.captureDiscardedBytes) {
|
|
70
|
+
gaps.push({ bytes: meta.captureDiscardedBytes, detail: `${meta.captureOverflowEvents ?? 1} capture overflow(s)` });
|
|
71
|
+
}
|
|
72
|
+
return gaps;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Page retained raw bytes with this task's generation and disclosed capture/retention loss. */
|
|
76
|
+
export function pageTaskLog(meta: BackgroundTaskMeta, request: FilePageRequest = {}): PageResult {
|
|
77
|
+
return pageRetainedFile(meta.logPath, {
|
|
78
|
+
...request,
|
|
79
|
+
resource: request.resource ?? meta.id,
|
|
80
|
+
generation: request.generation ?? meta.logGeneration ?? 0,
|
|
81
|
+
discardedBytes: request.discardedBytes ?? meta.logDiscardedBytes,
|
|
82
|
+
captureGaps: request.captureGaps ?? captureGapsFor(meta),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function resolveMaxLogBytes(value: number | undefined): number {
|
|
87
|
+
if (value === undefined || !Number.isFinite(value) || value <= 0) return DEFAULT_MAX_LOG_BYTES;
|
|
88
|
+
return Math.max(64 * 1024, Math.floor(value));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Compact in place so detached children keep writing to the same inode. A
|
|
93
|
+
* rename-based rotation would leave their inherited descriptor unbounded.
|
|
94
|
+
*/
|
|
95
|
+
export function retainLogTail(logPath: string, maxBytes: number): { discardedBytes: number } | undefined {
|
|
96
|
+
let size: number;
|
|
97
|
+
try {
|
|
98
|
+
size = statSync(logPath).size;
|
|
99
|
+
} catch {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
if (size <= maxBytes) return undefined;
|
|
103
|
+
|
|
104
|
+
const start = Math.max(0, size - Math.floor(maxBytes * RETAINED_LOG_FRACTION));
|
|
105
|
+
let fd: number | undefined;
|
|
106
|
+
let retained: Buffer;
|
|
107
|
+
try {
|
|
108
|
+
fd = openSync(logPath, "r");
|
|
109
|
+
retained = Buffer.allocUnsafe(size - start);
|
|
110
|
+
let offset = 0;
|
|
111
|
+
while (offset < retained.length) {
|
|
112
|
+
const read = readSync(fd, retained, offset, retained.length - offset, start + offset);
|
|
113
|
+
if (read <= 0) break;
|
|
114
|
+
offset += read;
|
|
115
|
+
}
|
|
116
|
+
retained = retained.subarray(0, offset);
|
|
117
|
+
} catch {
|
|
118
|
+
return undefined;
|
|
119
|
+
} finally {
|
|
120
|
+
if (fd !== undefined) {
|
|
121
|
+
try { closeSync(fd); } catch { /* best effort */ }
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const discardedBytes = Math.max(0, size - retained.length);
|
|
126
|
+
try {
|
|
127
|
+
truncateSync(logPath, 0);
|
|
128
|
+
if (retained.length) appendFileSync(logPath, retained);
|
|
129
|
+
appendFileSync(logPath, `--- log retention discarded ${discardedBytes} bytes; newest output retained ---\n`);
|
|
130
|
+
return { discardedBytes };
|
|
131
|
+
} catch {
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-background-tasks/src/maintenance.ts. Do not edit directly.
|
|
2
|
+
import { mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { recordFailure } from "./failures.domain.mjs";
|
|
5
|
+
import { baseDir, listMetas, removeMeta, writeMeta } from "./registry.domain.mjs";
|
|
6
|
+
import { processIdentityAlive as defaultProcessIdentityAlive } from "./process-identity.domain.mjs";
|
|
7
|
+
import { isTerminalStatus } from "./types.domain.mjs";
|
|
8
|
+
export const DEFAULT_TASK_RETENTION_MS = 7 * 24 * 60 * 60 * 1000;
|
|
9
|
+
const STALE_MAINTENANCE_LOCK_MS = 10 * 60 * 1000;
|
|
10
|
+
export function runTaskMaintenance(options = {}) {
|
|
11
|
+
const now = options.now ?? Date.now();
|
|
12
|
+
const date = new Date(now).toISOString().slice(0, 10);
|
|
13
|
+
const statePath = join(baseDir(), "maintenance-state.json");
|
|
14
|
+
const lockPath = join(baseDir(), "maintenance.lock");
|
|
15
|
+
if (!options.force && readState(statePath).lastDate === date)
|
|
16
|
+
return { ran: false, reconciled: 0, removed: 0 };
|
|
17
|
+
if (!options.force && !acquireMaintenanceLock(lockPath, now))
|
|
18
|
+
return { ran: false, reconciled: 0, removed: 0 };
|
|
19
|
+
let reconciled = 0;
|
|
20
|
+
let removed = 0;
|
|
21
|
+
try {
|
|
22
|
+
const identityAlive = options.processIdentityAlive ?? defaultProcessIdentityAlive;
|
|
23
|
+
const metas = options.metas ?? listMetas();
|
|
24
|
+
for (const meta of metas) {
|
|
25
|
+
if (meta.status !== "running" || belongsToOrigin(meta, options.activeOrigin))
|
|
26
|
+
continue;
|
|
27
|
+
if (identityAlive(meta.spawnPid, meta.spawnPidStartTime, meta.startedAt))
|
|
28
|
+
continue;
|
|
29
|
+
if (meta.remote?.session === "tmux")
|
|
30
|
+
continue;
|
|
31
|
+
if (meta.kind === "process" && identityAlive(meta.pid, meta.pidStartTime, meta.startedAt))
|
|
32
|
+
continue;
|
|
33
|
+
meta.status = "failed";
|
|
34
|
+
meta.endedAt = now;
|
|
35
|
+
meta.error = "task supervisor is no longer alive; execution result is unavailable";
|
|
36
|
+
meta.result = { reason: meta.error };
|
|
37
|
+
recordFailure(meta, "execution", meta.error, "supervisor-lost", { incomplete: true, at: now });
|
|
38
|
+
writeMeta(meta);
|
|
39
|
+
reconciled += 1;
|
|
40
|
+
}
|
|
41
|
+
const cutoff = now - (options.retentionMs ?? DEFAULT_TASK_RETENTION_MS);
|
|
42
|
+
for (const meta of metas) {
|
|
43
|
+
if (!isTerminalStatus(meta.status))
|
|
44
|
+
continue;
|
|
45
|
+
if ((meta.endedAt ?? meta.startedAt) >= cutoff)
|
|
46
|
+
continue;
|
|
47
|
+
if (removeMeta(meta))
|
|
48
|
+
removed += 1;
|
|
49
|
+
}
|
|
50
|
+
if (!options.force)
|
|
51
|
+
writeFileSync(statePath, JSON.stringify({ lastDate: date }));
|
|
52
|
+
return { ran: true, reconciled, removed };
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
if (!options.force)
|
|
56
|
+
rmSync(lockPath, { recursive: true, force: true });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function readState(path) {
|
|
60
|
+
try {
|
|
61
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return {};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function acquireMaintenanceLock(path, now) {
|
|
68
|
+
mkdirSync(baseDir(), { recursive: true });
|
|
69
|
+
try {
|
|
70
|
+
mkdirSync(path);
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
try {
|
|
75
|
+
if (now - statSync(path).mtimeMs <= STALE_MAINTENANCE_LOCK_MS)
|
|
76
|
+
return false;
|
|
77
|
+
rmSync(path, { recursive: true, force: true });
|
|
78
|
+
mkdirSync(path);
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function belongsToOrigin(meta, active) {
|
|
87
|
+
if (!active)
|
|
88
|
+
return false;
|
|
89
|
+
const origin = meta.callbackOrigin ?? { cwd: meta.cwd };
|
|
90
|
+
if (origin.cwd !== active.cwd)
|
|
91
|
+
return false;
|
|
92
|
+
if (origin.sessionId || active.sessionId)
|
|
93
|
+
return origin.sessionId === active.sessionId;
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { recordFailure } from "./failures.js";
|
|
4
|
+
import { baseDir, listMetas, removeMeta, writeMeta } from "./registry.js";
|
|
5
|
+
import { processIdentityAlive as defaultProcessIdentityAlive } from "./process-identity.js";
|
|
6
|
+
import type { BackgroundTaskCallbackOrigin, BackgroundTaskMeta } from "./types.js";
|
|
7
|
+
import { isTerminalStatus } from "./types.js";
|
|
8
|
+
|
|
9
|
+
export const DEFAULT_TASK_RETENTION_MS = 7 * 24 * 60 * 60 * 1000;
|
|
10
|
+
const STALE_MAINTENANCE_LOCK_MS = 10 * 60 * 1000;
|
|
11
|
+
|
|
12
|
+
interface MaintenanceState {
|
|
13
|
+
lastDate?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface TaskMaintenanceOptions {
|
|
17
|
+
now?: number;
|
|
18
|
+
activeOrigin?: BackgroundTaskCallbackOrigin;
|
|
19
|
+
retentionMs?: number;
|
|
20
|
+
processIdentityAlive?: (pid: number | undefined, token?: string, recordedAt?: number) => boolean;
|
|
21
|
+
metas?: BackgroundTaskMeta[];
|
|
22
|
+
force?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface TaskMaintenanceResult {
|
|
26
|
+
ran: boolean;
|
|
27
|
+
reconciled: number;
|
|
28
|
+
removed: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function runTaskMaintenance(options: TaskMaintenanceOptions = {}): TaskMaintenanceResult {
|
|
32
|
+
const now = options.now ?? Date.now();
|
|
33
|
+
const date = new Date(now).toISOString().slice(0, 10);
|
|
34
|
+
const statePath = join(baseDir(), "maintenance-state.json");
|
|
35
|
+
const lockPath = join(baseDir(), "maintenance.lock");
|
|
36
|
+
if (!options.force && readState(statePath).lastDate === date) return { ran: false, reconciled: 0, removed: 0 };
|
|
37
|
+
if (!options.force && !acquireMaintenanceLock(lockPath, now)) return { ran: false, reconciled: 0, removed: 0 };
|
|
38
|
+
|
|
39
|
+
let reconciled = 0;
|
|
40
|
+
let removed = 0;
|
|
41
|
+
try {
|
|
42
|
+
const identityAlive = options.processIdentityAlive ?? defaultProcessIdentityAlive;
|
|
43
|
+
const metas = options.metas ?? listMetas();
|
|
44
|
+
for (const meta of metas) {
|
|
45
|
+
if (meta.status !== "running" || belongsToOrigin(meta, options.activeOrigin)) continue;
|
|
46
|
+
if (identityAlive(meta.spawnPid, meta.spawnPidStartTime, meta.startedAt)) continue;
|
|
47
|
+
if (meta.remote?.session === "tmux") continue;
|
|
48
|
+
if (meta.kind === "process" && identityAlive(meta.pid, meta.pidStartTime, meta.startedAt)) continue;
|
|
49
|
+
meta.status = "failed";
|
|
50
|
+
meta.endedAt = now;
|
|
51
|
+
meta.error = "task supervisor is no longer alive; execution result is unavailable";
|
|
52
|
+
meta.result = { reason: meta.error };
|
|
53
|
+
recordFailure(meta, "execution", meta.error, "supervisor-lost", { incomplete: true, at: now });
|
|
54
|
+
writeMeta(meta);
|
|
55
|
+
reconciled += 1;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const cutoff = now - (options.retentionMs ?? DEFAULT_TASK_RETENTION_MS);
|
|
59
|
+
for (const meta of metas) {
|
|
60
|
+
if (!isTerminalStatus(meta.status)) continue;
|
|
61
|
+
if ((meta.endedAt ?? meta.startedAt) >= cutoff) continue;
|
|
62
|
+
if (removeMeta(meta)) removed += 1;
|
|
63
|
+
}
|
|
64
|
+
if (!options.force) writeFileSync(statePath, JSON.stringify({ lastDate: date } satisfies MaintenanceState));
|
|
65
|
+
return { ran: true, reconciled, removed };
|
|
66
|
+
} finally {
|
|
67
|
+
if (!options.force) rmSync(lockPath, { recursive: true, force: true });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function readState(path: string): MaintenanceState {
|
|
72
|
+
try { return JSON.parse(readFileSync(path, "utf8")) as MaintenanceState; } catch { return {}; }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function acquireMaintenanceLock(path: string, now: number): boolean {
|
|
76
|
+
mkdirSync(baseDir(), { recursive: true });
|
|
77
|
+
try {
|
|
78
|
+
mkdirSync(path);
|
|
79
|
+
return true;
|
|
80
|
+
} catch {
|
|
81
|
+
try {
|
|
82
|
+
if (now - statSync(path).mtimeMs <= STALE_MAINTENANCE_LOCK_MS) return false;
|
|
83
|
+
rmSync(path, { recursive: true, force: true });
|
|
84
|
+
mkdirSync(path);
|
|
85
|
+
return true;
|
|
86
|
+
} catch {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function belongsToOrigin(meta: BackgroundTaskMeta, active: BackgroundTaskCallbackOrigin | undefined): boolean {
|
|
93
|
+
if (!active) return false;
|
|
94
|
+
const origin = meta.callbackOrigin ?? { cwd: meta.cwd };
|
|
95
|
+
if (origin.cwd !== active.cwd) return false;
|
|
96
|
+
if (origin.sessionId || active.sessionId) return origin.sessionId === active.sessionId;
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-background-tasks/src/managed-authority.ts. Do not edit directly.
|
|
2
|
+
import { createHash, timingSafeEqual } from 'node:crypto';
|
|
3
|
+
import { lstatSync, readFileSync, realpathSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { readAdmissionStartToken, readProcessStartTokenFresh } from "./process-identity.domain.mjs";
|
|
6
|
+
const ordered = (value) => value === null || typeof value !== 'object' ? value : Array.isArray(value) ? value.map(ordered) : Object.fromEntries(Object.keys(value).sort().map(key => [key, ordered(value[key])]));
|
|
7
|
+
export const backgroundDigest = (value) => createHash('sha256').update(JSON.stringify(ordered(value))).digest('hex');
|
|
8
|
+
export function readBackgroundAuthority(root, instance, authority, requireLive = true) {
|
|
9
|
+
if (!authority || !/^[a-f0-9-]{36}$/.test(authority.id) || !/^[a-f0-9]{64}$/.test(authority.secret))
|
|
10
|
+
throw new Error('background-authority-refused');
|
|
11
|
+
const directory = join(root, 'background-tool-admission'), path = join(directory, `${authority.id}.json`);
|
|
12
|
+
const dir = lstatSync(directory), stat = lstatSync(path);
|
|
13
|
+
if (!dir.isDirectory() || dir.isSymbolicLink() || dir.uid !== process.getuid?.() || (dir.mode & 0o077)
|
|
14
|
+
|| !stat.isFile() || stat.isSymbolicLink() || stat.uid !== dir.uid || (stat.mode & 0o077) || stat.size > 1024 * 1024)
|
|
15
|
+
throw new Error('background-authority-refused');
|
|
16
|
+
const record = JSON.parse(readFileSync(path, 'utf8')), digest = createHash('sha256').update(authority.secret).digest('hex');
|
|
17
|
+
if ((record.version !== 1 && record.version !== 2) || record.instanceId !== instance || record.id !== authority.id || typeof record.secretHash !== 'string'
|
|
18
|
+
|| record.secretHash.length !== digest.length || !timingSafeEqual(Buffer.from(record.secretHash), Buffer.from(digest))
|
|
19
|
+
|| typeof record.key !== 'string' || !record.key || typeof record.tool !== 'string' || !record.owner?.sessionId
|
|
20
|
+
|| record.owner.workspace !== realpathSync(record.owner.workspace) || !Number.isSafeInteger(record.pid) || !record.start
|
|
21
|
+
|| !Array.isArray(record.branchIds) || record.branchIds.some((id) => typeof id !== 'string'))
|
|
22
|
+
throw new Error('background-authority-refused');
|
|
23
|
+
if (requireLive) {
|
|
24
|
+
const start = record.version === 2 ? readAdmissionStartToken(record.pid) : readProcessStartTokenFresh(record.pid);
|
|
25
|
+
if (!start)
|
|
26
|
+
throw new Error('background-authority-refused: cannot verify host start time');
|
|
27
|
+
if (start !== record.start)
|
|
28
|
+
throw new Error('background-authority-refused: host identity changed');
|
|
29
|
+
process.kill(record.pid, 0);
|
|
30
|
+
}
|
|
31
|
+
return record;
|
|
32
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createHash, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import { lstatSync, readFileSync, realpathSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { readAdmissionStartToken, readProcessStartTokenFresh } from './process-identity.js';
|
|
5
|
+
const ordered = (value: any): any => value === null || typeof value !== 'object' ? value : Array.isArray(value) ? value.map(ordered) : Object.fromEntries(Object.keys(value).sort().map(key => [key, ordered(value[key])]));
|
|
6
|
+
export const backgroundDigest = (value: unknown) => createHash('sha256').update(JSON.stringify(ordered(value))).digest('hex');
|
|
7
|
+
export function readBackgroundAuthority(root: string, instance: string, authority: any, requireLive = true): any {
|
|
8
|
+
if (!authority || !/^[a-f0-9-]{36}$/.test(authority.id) || !/^[a-f0-9]{64}$/.test(authority.secret))
|
|
9
|
+
throw new Error('background-authority-refused');
|
|
10
|
+
const directory = join(root, 'background-tool-admission'), path = join(directory, `${authority.id}.json`);
|
|
11
|
+
const dir = lstatSync(directory), stat = lstatSync(path);
|
|
12
|
+
if (!dir.isDirectory() || dir.isSymbolicLink() || dir.uid !== process.getuid?.() || (dir.mode & 0o077)
|
|
13
|
+
|| !stat.isFile() || stat.isSymbolicLink() || stat.uid !== dir.uid || (stat.mode & 0o077) || stat.size > 1024 * 1024)
|
|
14
|
+
throw new Error('background-authority-refused');
|
|
15
|
+
const record = JSON.parse(readFileSync(path, 'utf8')), digest = createHash('sha256').update(authority.secret).digest('hex');
|
|
16
|
+
if ((record.version !== 1 && record.version !== 2) || record.instanceId !== instance || record.id !== authority.id || typeof record.secretHash !== 'string'
|
|
17
|
+
|| record.secretHash.length !== digest.length || !timingSafeEqual(Buffer.from(record.secretHash), Buffer.from(digest))
|
|
18
|
+
|| typeof record.key !== 'string' || !record.key || typeof record.tool !== 'string' || !record.owner?.sessionId
|
|
19
|
+
|| record.owner.workspace !== realpathSync(record.owner.workspace) || !Number.isSafeInteger(record.pid) || !record.start
|
|
20
|
+
|| !Array.isArray(record.branchIds) || record.branchIds.some((id: unknown) => typeof id !== 'string'))
|
|
21
|
+
throw new Error('background-authority-refused');
|
|
22
|
+
if (requireLive) {
|
|
23
|
+
const start = record.version === 2 ? readAdmissionStartToken(record.pid) : readProcessStartTokenFresh(record.pid);
|
|
24
|
+
if (!start) throw new Error('background-authority-refused: cannot verify host start time');
|
|
25
|
+
if (start !== record.start)
|
|
26
|
+
throw new Error('background-authority-refused: host identity changed');
|
|
27
|
+
process.kill(record.pid, 0);
|
|
28
|
+
}
|
|
29
|
+
return record;
|
|
30
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-background-tasks/src/managed-client.ts. Do not edit directly.
|
|
2
|
+
import { createHash, randomBytes, randomUUID } from 'node:crypto';
|
|
3
|
+
import { lstatSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { getAgentDir } from '@earendil-works/pi-coding-agent';
|
|
6
|
+
import { backgroundDigest } from "./managed-authority.domain.mjs";
|
|
7
|
+
import { readAdmissionStartToken, readProcessStartTokenFresh } from "./process-identity.domain.mjs";
|
|
8
|
+
import { currentForegroundSandboxPolicy, FOREGROUND_SANDBOX_POLICY_CHANNEL } from "./sandbox.domain.mjs";
|
|
9
|
+
import { backgroundListNeedsHistory, backgroundObservation } from "./work-observation.domain.mjs";
|
|
10
|
+
/** Native host proof carries scope and captured policy, never a transcript or module path. */
|
|
11
|
+
export async function requestBackgroundTool(pi, ctx, key, tool, params, parameters, signal) {
|
|
12
|
+
if (signal?.aborted)
|
|
13
|
+
throw new Error('Background request cancelled before admission');
|
|
14
|
+
const input = params && typeof params === 'object' ? params : {};
|
|
15
|
+
const list = tool === 'bg_task_list' || (tool === 'bg_task' && input.action === 'list');
|
|
16
|
+
if (list && backgroundListNeedsHistory(input)) {
|
|
17
|
+
// The root history index is shared. Wait on its read plane before acquiring
|
|
18
|
+
// a grant or entering the serialized tool queue, even for an all-session list.
|
|
19
|
+
const snapshot = await backgroundObservation(pi, ctx, true, false, { limit: 1 }, { timeoutMs: 60000, signal });
|
|
20
|
+
if (snapshot.status !== 'ready')
|
|
21
|
+
throw new Error(snapshot.reason ?? `Background history is ${snapshot.status}`);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
await backgroundObservation(pi, ctx);
|
|
25
|
+
}
|
|
26
|
+
signal?.throwIfAborted();
|
|
27
|
+
const root = realpathSync(getAgentDir()), registration = JSON.parse(readFileSync(join(root, 'server-registration-v1.json'), 'utf8'));
|
|
28
|
+
if (registration.version !== 1 || registration.agentDir !== root)
|
|
29
|
+
throw new Error('Invalid runtime registration');
|
|
30
|
+
const module = new URL('./shared-work-client.mjs', import.meta.url).href;
|
|
31
|
+
const { connectWorkClient } = await import(module);
|
|
32
|
+
const directory = join(root, 'background-tool-admission');
|
|
33
|
+
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
34
|
+
const stat = lstatSync(directory);
|
|
35
|
+
if (!stat.isDirectory() || stat.isSymbolicLink() || stat.uid !== process.getuid?.() || (stat.mode & 0o077))
|
|
36
|
+
throw new Error('Unsafe Background admission directory');
|
|
37
|
+
const client = await connectWorkClient(join(registration.serverDir, 'pi-server.sock'), root, ['runtime-background-execution-v1'], { signal });
|
|
38
|
+
const id = randomUUID(), secret = randomBytes(32).toString('hex'), path = join(directory, `${id}.json`);
|
|
39
|
+
let off;
|
|
40
|
+
const abort = () => client.close();
|
|
41
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
42
|
+
try {
|
|
43
|
+
const hello = await client.ready;
|
|
44
|
+
const policy = currentForegroundSandboxPolicy(pi);
|
|
45
|
+
const branchIds = ctx.sessionManager.getBranch().map(entry => entry.id).filter((value) => typeof value === 'string');
|
|
46
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
47
|
+
if (!sessionId)
|
|
48
|
+
throw new Error('Background tools require a native session identity');
|
|
49
|
+
const version = hello.capabilities?.includes("runtime-background-admission-v2") ? 2 : 1;
|
|
50
|
+
const start = version === 2 ? readAdmissionStartToken(process.pid) : readProcessStartTokenFresh(process.pid);
|
|
51
|
+
const record = { version, id, secretHash: createHash('sha256').update(secret).digest('hex'), instanceId: hello.instanceId,
|
|
52
|
+
owner: { kind: 'parent-session', sessionId, workspace: realpathSync(ctx.cwd) }, branchIds, projectTrusted: ctx.isProjectTrusted(),
|
|
53
|
+
pid: process.pid, start, key, tool, params, parametersDigest: parameters === undefined ? undefined : backgroundDigest(parameters), policy };
|
|
54
|
+
const staged = `${path}.tmp`;
|
|
55
|
+
writeFileSync(staged, JSON.stringify(record), { flag: 'wx', mode: 0o600 });
|
|
56
|
+
renameSync(staged, path);
|
|
57
|
+
let checking = false;
|
|
58
|
+
off = pi.events.on(FOREGROUND_SANDBOX_POLICY_CHANNEL, () => {
|
|
59
|
+
if (checking)
|
|
60
|
+
return;
|
|
61
|
+
checking = true;
|
|
62
|
+
try {
|
|
63
|
+
if (backgroundDigest(currentForegroundSandboxPolicy(pi) ?? null) !== backgroundDigest(policy ?? null))
|
|
64
|
+
rmSync(path, { force: true });
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
checking = false;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return await client.request('runtime_background_tool', { authority: { id, secret } });
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
if (typeof off === 'function')
|
|
74
|
+
off();
|
|
75
|
+
signal?.removeEventListener('abort', abort);
|
|
76
|
+
client.close();
|
|
77
|
+
rmSync(path, { force: true });
|
|
78
|
+
}
|
|
79
|
+
}
|