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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
3
4
|
import { createRequire } from "node:module";
|
|
4
5
|
import { acquireMutationStore } from "./mutation-store.ts";
|
|
5
6
|
// @ts-expect-error Generated canonical supervisor; only stop is invoked here.
|
|
@@ -28,7 +29,10 @@ export function hasPendingCancellation(root: string): boolean {
|
|
|
28
29
|
export class RuntimeCancellation {
|
|
29
30
|
private store: any;
|
|
30
31
|
private releaseStore: () => void;
|
|
32
|
+
private budget: ReturnType<typeof acquireMutationStore>['budget'];
|
|
31
33
|
private pending = new Map<string, Promise<unknown>>();
|
|
34
|
+
private reasons = new Map<string, any>();
|
|
35
|
+
lifecycleReasons() { return [...this.reasons.values()].map(reason => ({ ...reason })); }
|
|
32
36
|
readonly epoch: number;
|
|
33
37
|
private fault?: (stage: CancellationStage) => void;
|
|
34
38
|
get busy() { return this.pending.size > 0; }
|
|
@@ -36,13 +40,14 @@ export class RuntimeCancellation {
|
|
|
36
40
|
this.fault = fault;
|
|
37
41
|
const lease = acquireMutationStore(root);
|
|
38
42
|
this.store = lease.store;
|
|
43
|
+
this.budget = lease.budget;
|
|
39
44
|
this.releaseStore = lease.release;
|
|
40
45
|
try {
|
|
41
46
|
this.epoch = this.store.cancellationRuntimeEpoch(instanceId);
|
|
42
47
|
for (const admission of this.store.pendingTaskCancellations()) void this.execute(admission);
|
|
43
48
|
} catch (error) { this.releaseStore(); throw error; }
|
|
44
49
|
}
|
|
45
|
-
async handle(command: Record<string, unknown
|
|
50
|
+
async handle(command: Record<string, unknown>, onAccepted?: (id: string) => void, releaseControl?: () => void) {
|
|
46
51
|
if (Object.keys(command).some(key => !["id", "type", "credential"].includes(key))) throw new Error("not_accepted: unsupported cancellation field");
|
|
47
52
|
if (command.type === "runtime_cancellation_status") return { runtimeEpoch: this.epoch };
|
|
48
53
|
if (typeof command.credential !== "string") throw new Error("not_accepted: permission-unavailable: cancellation credential required");
|
|
@@ -56,14 +61,22 @@ export class RuntimeCancellation {
|
|
|
56
61
|
try { this.store.acceptAuthorizedTaskCancellation({ credential: command.credential, runtimeEpoch: this.epoch }); }
|
|
57
62
|
catch (error) { throw new Error(`not_accepted: ${String(error)}`); }
|
|
58
63
|
this.fault?.("accepted");
|
|
59
|
-
|
|
64
|
+
onAccepted?.(`cancellation:${createHash('sha256').update(JSON.stringify([admission.request.owner, admission.request.idempotencyKey])).digest('hex')}`);
|
|
65
|
+
return this.execute(admission, releaseControl);
|
|
60
66
|
}
|
|
61
|
-
private execute(admission: any): Promise<any> {
|
|
67
|
+
private execute(admission: any, releaseControl?: () => void): Promise<any> {
|
|
62
68
|
const key = JSON.stringify([admission.request.owner, admission.request.idempotencyKey]);
|
|
63
69
|
const running = this.pending.get(key);
|
|
64
|
-
if (running) return running;
|
|
70
|
+
if (running) { releaseControl?.(); return running; }
|
|
65
71
|
const intent = this.store.getTaskCancellation(admission.request);
|
|
66
|
-
const
|
|
72
|
+
const progress = (phase: string) => this.reasons.set(key, { kind: 'task',
|
|
73
|
+
id: `cancellation:${createHash('sha256').update(key).digest('hex')}`, operationId: intent.operationId, taskId: intent.taskId,
|
|
74
|
+
owner: admission.request.owner, management: { epoch: this.epoch }, acceptedAt: intent.acceptedAt,
|
|
75
|
+
phase, lastProgressAt: Date.now(), executionDeadline: null, nextDeadline: null,
|
|
76
|
+
recovery: 'recover-exact-durable-stop-intent-without-repeating-ambiguous-process-action' });
|
|
77
|
+
progress(releaseControl ? 'accepted' : 'waiting-for-control-capacity');
|
|
78
|
+
const run = async () => {
|
|
79
|
+
progress('accepted');
|
|
67
80
|
try {
|
|
68
81
|
const supervisor = createLocalSupervisor({ directory: admission.directory });
|
|
69
82
|
const stop = readStopRequest(admission.directory, intent.taskId);
|
|
@@ -78,8 +91,10 @@ export class RuntimeCancellation {
|
|
|
78
91
|
const inspection = supervisor.snapshot(intent.taskId);
|
|
79
92
|
if (inspection?.token !== intent.expectedLaunchToken) throw new Error("Exact launch token mismatch; refusing action");
|
|
80
93
|
this.fault?.("before-stop-file");
|
|
94
|
+
progress('writing-stop-intent');
|
|
81
95
|
writeStopRequest(admission.directory, { version: 1, taskId: intent.taskId, token: intent.expectedLaunchToken, requestedAt: Date.now(), reason: intent.reason });
|
|
82
96
|
this.fault?.("after-stop-file");
|
|
97
|
+
progress('awaiting-exact-supervisor-stop');
|
|
83
98
|
result = await supervisor.stop(intent.taskId, { token: intent.expectedLaunchToken, reason: intent.reason });
|
|
84
99
|
this.fault?.("after-process-action");
|
|
85
100
|
}
|
|
@@ -90,8 +105,14 @@ export class RuntimeCancellation {
|
|
|
90
105
|
...(result.terminal ? { publication: supervisorTerminalPublication(operation, inspection) } : {}) });
|
|
91
106
|
} catch {
|
|
92
107
|
return { ...this.store.unknownTaskCancellation(admission.request), state: "outcome_unknown" };
|
|
93
|
-
}
|
|
94
|
-
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
// Recovery reserves here; socket execution transfers its existing lease.
|
|
111
|
+
// Both retain capacity until the physical operation has settled.
|
|
112
|
+
const dispatched = releaseControl
|
|
113
|
+
? Promise.resolve().then(run).finally(releaseControl)
|
|
114
|
+
: this.budget.scheduleSource('cancellation', key, () => Promise.resolve().then(run));
|
|
115
|
+
const execution = dispatched.finally(() => { this.pending.delete(key); this.reasons.delete(key); });
|
|
95
116
|
this.pending.set(key, execution);
|
|
96
117
|
return execution;
|
|
97
118
|
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { lstatSync, opendirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { bundledRolesRoot, contentDigest, loadCatalog, projectCatalogPaths, userCatalogPaths } from "./domain/catalog/catalog-store.mjs";
|
|
4
|
+
import { parseDefinition } from "./domain/catalog/catalog-schema.mjs";
|
|
5
|
+
import { readCatalogPreferences } from "./domain/catalog/catalog-preferences.mjs";
|
|
6
|
+
import type { CatalogEntry } from "./domain/catalog/catalog-store.mjs";
|
|
7
|
+
|
|
8
|
+
type Location = { cwd: string; userRoot: string; projectTrusted: boolean };
|
|
9
|
+
type Scope = { version: string; snapshot: ReturnType<typeof loadCatalog>; loc: Location; scan?: Generator<void, string>; checked?: string };
|
|
10
|
+
|
|
11
|
+
// Fixed-build, server-local derived values only. No grant or launch authority is cached.
|
|
12
|
+
export class CatalogSources {
|
|
13
|
+
readonly metrics = { reads: 0, parses: 0, scopes: 0, notifications: 0, stats: 0, repairSteps: 0, repairs: 0, entries: 0, preferenceReads: 0 };
|
|
14
|
+
private files = new Map<string, { version: string; raw: string }>();
|
|
15
|
+
private fileBytes = 0;
|
|
16
|
+
private parsed = new Map<string, ReturnType<typeof parseDefinition>>();
|
|
17
|
+
private scopes = new Map<string, Scope>();
|
|
18
|
+
private entries = new Map<string, CatalogEntry>();
|
|
19
|
+
private preferencesCache = new Map<string, { version: string; value: ReturnType<typeof readCatalogPreferences> }>();
|
|
20
|
+
private observing = false;
|
|
21
|
+
private active = new Set<string>();
|
|
22
|
+
private turn = 0;
|
|
23
|
+
|
|
24
|
+
beginObservation() { this.observing = true; this.active.clear(); }
|
|
25
|
+
endObservation() {
|
|
26
|
+
this.observing = false;
|
|
27
|
+
for (const [key, scope] of this.scopes) if (!this.active.has(key)) { scope.scan?.return(""); scope.scan = undefined; }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The budget counts iterator/stat steps across all scopes, not per observer. */
|
|
31
|
+
repair(budget = 128) {
|
|
32
|
+
const scopes = [...this.active].map(key => this.scopes.get(key)).filter((scope): scope is Scope => !!scope);
|
|
33
|
+
if (!scopes.length) return false;
|
|
34
|
+
const completed = new Set<Scope>();
|
|
35
|
+
let changed = false;
|
|
36
|
+
for (let step = 0; step < budget; step++) {
|
|
37
|
+
if (completed.size === scopes.length) break;
|
|
38
|
+
const scope = scopes[this.turn++ % scopes.length]!;
|
|
39
|
+
if (completed.has(scope)) { step--; continue; }
|
|
40
|
+
scope.scan ??= this.scan(scope.loc);
|
|
41
|
+
this.metrics.repairSteps++;
|
|
42
|
+
const next = scope.scan.next();
|
|
43
|
+
if (next.done) {
|
|
44
|
+
scope.checked = next.value;
|
|
45
|
+
scope.scan = undefined;
|
|
46
|
+
this.metrics.repairs++;
|
|
47
|
+
changed ||= scope.checked !== scope.version;
|
|
48
|
+
completed.add(scope);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return changed;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
watchPaths() {
|
|
55
|
+
return new Set([...this.active].flatMap(key => {
|
|
56
|
+
const loc = this.scopes.get(key)?.loc;
|
|
57
|
+
return loc ? this.paths(loc).directories : [];
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
hint(path: string) {
|
|
62
|
+
for (const key of this.active) {
|
|
63
|
+
const scope = this.scopes.get(key);
|
|
64
|
+
if (scope && this.paths(scope.loc).directories.some(directory => directory === path || directory === dirname(path))) {
|
|
65
|
+
scope.checked = "hint:" + path + ":" + this.version(path);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private paths(loc: Location) {
|
|
71
|
+
const user = userCatalogPaths(loc.userRoot), project = projectCatalogPaths(loc.cwd);
|
|
72
|
+
return { project, roots: [user.root, ...(loc.projectTrusted ? [project.root] : [])],
|
|
73
|
+
directories: [user.root, user.roles, user.agents, bundledRolesRoot(), ...(loc.projectTrusted ? [project.root, project.roles, project.agents] : [])] };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private *scan(loc: Location): Generator<void, string> {
|
|
77
|
+
const { roots, directories, project } = this.paths(loc);
|
|
78
|
+
const versions: unknown[] = [];
|
|
79
|
+
for (const root of roots) { versions.push([root, this.version(join(root, "settings.json"))]); yield; }
|
|
80
|
+
if (!loc.projectTrusted) { versions.push([project.root, this.version(project.root)]); yield; }
|
|
81
|
+
for (const directory of directories) {
|
|
82
|
+
versions.push([directory, this.version(directory)]); yield;
|
|
83
|
+
let handle: ReturnType<typeof opendirSync> | undefined;
|
|
84
|
+
const files: unknown[] = [];
|
|
85
|
+
try {
|
|
86
|
+
const stats = lstatSync(directory);
|
|
87
|
+
if (!stats.isDirectory() || stats.isSymbolicLink()) continue;
|
|
88
|
+
handle = opendirSync(directory);
|
|
89
|
+
for (;;) {
|
|
90
|
+
const entry = handle.readSync();
|
|
91
|
+
if (!entry) break;
|
|
92
|
+
if (!entry.name.startsWith(".") && entry.name.endsWith(".md")) files.push([entry.name, this.version(join(directory, entry.name))]);
|
|
93
|
+
yield;
|
|
94
|
+
}
|
|
95
|
+
} catch (error) { files.push(String(error)); }
|
|
96
|
+
finally { handle?.closeSync(); }
|
|
97
|
+
versions.push(files.sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b))));
|
|
98
|
+
}
|
|
99
|
+
return JSON.stringify(versions);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
entry = (entry: CatalogEntry) => {
|
|
103
|
+
const key = JSON.stringify(entry);
|
|
104
|
+
const previous = this.entries.get(key);
|
|
105
|
+
if (previous) return previous;
|
|
106
|
+
this.metrics.entries++;
|
|
107
|
+
if (Buffer.byteLength(key) <= 64 * 1024) this.put(this.entries, key, entry, 512);
|
|
108
|
+
return entry;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
preferences = (root: string) => {
|
|
112
|
+
const version = this.version(root) + this.version(join(root, "settings.json"));
|
|
113
|
+
const previous = this.preferencesCache.get(root);
|
|
114
|
+
if (previous?.version === version) return previous.value;
|
|
115
|
+
this.metrics.preferenceReads++;
|
|
116
|
+
const value = readCatalogPreferences(root);
|
|
117
|
+
this.put(this.preferencesCache, root, { version, value }, 128);
|
|
118
|
+
return value;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
private version(path: string): string {
|
|
122
|
+
this.metrics.stats++;
|
|
123
|
+
try {
|
|
124
|
+
const s = lstatSync(path, { bigint: true });
|
|
125
|
+
return [s.dev, s.ino, s.mode, s.size, s.mtimeNs, s.ctimeNs].join(":");
|
|
126
|
+
} catch (error) { return String(error); }
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
read = (path: string): string => {
|
|
130
|
+
const version = this.version(path);
|
|
131
|
+
const previous = this.files.get(path);
|
|
132
|
+
if (previous?.version === version) return previous.raw;
|
|
133
|
+
this.metrics.reads++;
|
|
134
|
+
const raw = readFileSync(path, "utf8");
|
|
135
|
+
this.fileBytes -= previous ? Buffer.byteLength(previous.raw) : 0;
|
|
136
|
+
this.files.delete(path);
|
|
137
|
+
// Large definitions remain readable but cannot consume the shared cache budget.
|
|
138
|
+
if (Buffer.byteLength(raw) > 1024 * 1024) return raw;
|
|
139
|
+
this.fileBytes += Buffer.byteLength(raw);
|
|
140
|
+
while (this.files.size && (this.fileBytes > 16 * 1024 * 1024 || this.files.size >= 2048)) {
|
|
141
|
+
const oldest = this.files.keys().next().value!;
|
|
142
|
+
this.fileBytes -= Buffer.byteLength(this.files.get(oldest)!.raw);
|
|
143
|
+
this.files.delete(oldest);
|
|
144
|
+
}
|
|
145
|
+
this.put(this.files, path, { version, raw }, 2048);
|
|
146
|
+
return raw;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
parse = (raw: string, path: string): ReturnType<typeof parseDefinition> => {
|
|
150
|
+
const key = JSON.stringify([path, contentDigest(raw)]);
|
|
151
|
+
const previous = this.parsed.get(key);
|
|
152
|
+
if (previous) return previous;
|
|
153
|
+
this.metrics.parses++;
|
|
154
|
+
const parsed = parseDefinition(raw, path);
|
|
155
|
+
if (Buffer.byteLength(raw) <= 64 * 1024) this.put(this.parsed, key, parsed, 512);
|
|
156
|
+
return parsed;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
load(loc: Location, fresh = false) {
|
|
160
|
+
const key = JSON.stringify([loc.cwd, loc.userRoot, loc.projectTrusted]);
|
|
161
|
+
const previous = this.scopes.get(key);
|
|
162
|
+
if (this.observing) this.active.add(key);
|
|
163
|
+
if (this.observing && !fresh && previous && (!previous.checked || previous.checked === previous.version)) return previous.snapshot;
|
|
164
|
+
let version = this.observing && previous?.checked;
|
|
165
|
+
if (!version) {
|
|
166
|
+
const scan = this.scan(loc);
|
|
167
|
+
let next = scan.next();
|
|
168
|
+
while (!next.done) next = scan.next();
|
|
169
|
+
version = next.value;
|
|
170
|
+
}
|
|
171
|
+
if (!fresh && previous?.version === version) return previous.snapshot;
|
|
172
|
+
this.metrics.scopes++;
|
|
173
|
+
// Writes always use fresh bytes, not a stat-derived content proof.
|
|
174
|
+
const sources = fresh ? {
|
|
175
|
+
read: (path: string) => { this.metrics.reads++; return readFileSync(path, "utf8"); },
|
|
176
|
+
parse: this.parse,
|
|
177
|
+
entry: this.entry,
|
|
178
|
+
preferences: (root: string) => { this.metrics.preferenceReads++; return readCatalogPreferences(root); },
|
|
179
|
+
} : this;
|
|
180
|
+
const snapshot = loadCatalog({ ...loc, sources });
|
|
181
|
+
if (!previous && this.scopes.size >= 64) this.scopes.values().next().value?.scan?.return("");
|
|
182
|
+
// Hot exact hints must not restart a long missed-event reconciliation pass.
|
|
183
|
+
this.put(this.scopes, key, { version, snapshot, loc, scan: previous?.scan }, 64);
|
|
184
|
+
return snapshot;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private put<K, V>(map: Map<K, V>, key: K, value: V, limit: number) {
|
|
188
|
+
map.delete(key); map.set(key, value);
|
|
189
|
+
if (map.size > limit) map.delete(map.keys().next().value!);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
get resources() { return { scopes: this.scopes.size, scans: [...this.scopes.values()].filter(scope => !!scope.scan).length, files: this.files.size, fileBytes: this.fileBytes }; }
|
|
193
|
+
|
|
194
|
+
clear() {
|
|
195
|
+
for (const scope of this.scopes.values()) scope.scan?.return("");
|
|
196
|
+
this.files.clear(); this.fileBytes = 0; this.parsed.clear(); this.scopes.clear();
|
|
197
|
+
this.entries.clear(); this.preferencesCache.clear(); this.active.clear();
|
|
198
|
+
}
|
|
199
|
+
}
|
package/src/runtime/catalog.ts
CHANGED
|
@@ -1,56 +1,88 @@
|
|
|
1
1
|
import { realpathSync } from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import { saveDefinition, resetRuntimeToBundled, resetUserDefinition, listScopedAgents } from "./domain/catalog/catalog-store.mjs";
|
|
3
3
|
import { withAgentSessionSettings, saveAgentSessionDefaults } from "./domain/catalog/agent-session-settings.mjs";
|
|
4
4
|
import { saveSkillExposure } from "./domain/catalog/catalog-skill-edits.mjs";
|
|
5
5
|
import { parseDefinition } from "./domain/catalog/catalog-schema.mjs";
|
|
6
6
|
import { CatalogAdmission } from "./catalog-admission.ts";
|
|
7
7
|
import { overlayDigest } from "./domain/catalog/catalog-overlay.mjs";
|
|
8
|
-
import { watch, type FSWatcher } from "node:fs";
|
|
9
|
-
import {
|
|
8
|
+
import { watch, lstatSync, type FSWatcher } from "node:fs";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { CatalogSources } from "./catalog-sources.ts";
|
|
10
11
|
|
|
11
12
|
/** One server-owned filesystem catalog; registrations belong to the live socket. */
|
|
12
13
|
export class SharedCatalog {
|
|
14
|
+
readonly sources = new CatalogSources();
|
|
13
15
|
private agentDir: string;
|
|
14
16
|
readonly admission: CatalogAdmission;
|
|
15
17
|
private observers = new Set<() => void>();
|
|
16
18
|
private timer?: ReturnType<typeof setInterval>;
|
|
17
19
|
private pending?: ReturnType<typeof setTimeout>;
|
|
18
|
-
private watchers = new Map<string, { watcher: FSWatcher;
|
|
20
|
+
private watchers = new Map<string, { watcher: FSWatcher; identity: string }>();
|
|
19
21
|
constructor(agentDir: string, instanceId: string) { this.agentDir = agentDir; this.admission = new CatalogAdmission(agentDir, instanceId); }
|
|
20
22
|
|
|
21
23
|
observe(read: () => any, emit: (snapshot: any) => void) {
|
|
22
24
|
if (this.observers.size >= 64) throw new Error("catalog-subscription-limit");
|
|
23
25
|
let revision: string | undefined, seq = 0;
|
|
24
|
-
const watched: string[] = [];
|
|
25
26
|
const initial = read();
|
|
26
|
-
const paths = new Set<string>([this.agentDir, ...[...initial.roles, ...initial.agents].map(([, entry]: any) => dirname(entry.path))]);
|
|
27
|
-
const notify = () => { this.pending ??= setTimeout(() => { this.pending = undefined; for (const reconcile of this.observers) reconcile(); }, 50); this.pending.unref(); };
|
|
28
|
-
for (const path of paths) {
|
|
29
|
-
const existing = this.watchers.get(path);
|
|
30
|
-
if (existing) { existing.references++; watched.push(path); continue; }
|
|
31
|
-
try {
|
|
32
|
-
const watcher = watch(path, { persistent: false }, notify); watcher.on("error", notify);
|
|
33
|
-
this.watchers.set(path, { watcher, references: 1 }); watched.push(path);
|
|
34
|
-
} catch { /* Bounded reconciliation also discovers newly created paths. */ }
|
|
35
|
-
}
|
|
36
27
|
const reconcile = () => {
|
|
37
28
|
let snapshot;
|
|
38
29
|
try { snapshot = read(); } catch { snapshot = { revision: "revoked", status: "revoked", roles: [], agents: [], diagnostics: [] }; }
|
|
39
30
|
if (snapshot.revision === revision) return;
|
|
40
31
|
revision = snapshot.revision;
|
|
32
|
+
this.sources.metrics.notifications++;
|
|
41
33
|
emit({ ...snapshot, seq: ++seq });
|
|
42
34
|
};
|
|
43
35
|
revision = initial.revision;
|
|
44
36
|
this.observers.add(reconcile);
|
|
45
|
-
this.
|
|
37
|
+
this.cycle();
|
|
38
|
+
this.timer ??= setInterval(() => this.cycle(), 1000);
|
|
46
39
|
this.timer.unref();
|
|
47
40
|
return { snapshot: { ...initial, seq }, close: () => {
|
|
48
|
-
this.observers.delete(reconcile);
|
|
49
|
-
|
|
50
|
-
|
|
41
|
+
if (!this.observers.delete(reconcile)) return;
|
|
42
|
+
if (!this.observers.size) {
|
|
43
|
+
clearInterval(this.timer); this.timer = undefined; clearTimeout(this.pending); this.pending = undefined;
|
|
44
|
+
for (const { watcher } of this.watchers.values()) watcher.close();
|
|
45
|
+
this.watchers.clear(); this.sources.clear();
|
|
46
|
+
} else this.cycle();
|
|
51
47
|
} };
|
|
52
48
|
}
|
|
53
49
|
|
|
50
|
+
private cycle() {
|
|
51
|
+
this.sources.beginObservation();
|
|
52
|
+
try {
|
|
53
|
+
// Verify every live grant before any project reconciliation work.
|
|
54
|
+
for (const reconcile of this.observers) reconcile();
|
|
55
|
+
if (this.sources.repair(128)) for (const reconcile of this.observers) reconcile();
|
|
56
|
+
const paths = this.sources.watchPaths();
|
|
57
|
+
for (const [path, entry] of this.watchers) {
|
|
58
|
+
let identity = "";
|
|
59
|
+
try { const stat = lstatSync(path); identity = `${stat.dev}:${stat.ino}`; } catch { /* Replaced/missing root. */ }
|
|
60
|
+
if (!paths.has(path) || identity !== entry.identity) { entry.watcher.close(); this.watchers.delete(path); }
|
|
61
|
+
}
|
|
62
|
+
for (const path of paths) {
|
|
63
|
+
if (this.watchers.has(path)) continue;
|
|
64
|
+
try {
|
|
65
|
+
const stat = lstatSync(path);
|
|
66
|
+
if (!stat.isDirectory() || stat.isSymbolicLink()) continue;
|
|
67
|
+
const watcher = watch(path, { persistent: false }, (_event, name) => {
|
|
68
|
+
this.sources.hint(name ? join(path, name.toString()) : path);
|
|
69
|
+
this.schedule();
|
|
70
|
+
});
|
|
71
|
+
watcher.on("error", () => { watcher.close(); this.watchers.delete(path); this.schedule(); });
|
|
72
|
+
this.watchers.set(path, { watcher, identity: `${stat.dev}:${stat.ino}` });
|
|
73
|
+
} catch { /* Repair discovers missing and rebuilt directories without a watcher. */ }
|
|
74
|
+
}
|
|
75
|
+
} finally { this.sources.endObservation(); }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private schedule() {
|
|
79
|
+
if (!this.observers.size || this.pending) return;
|
|
80
|
+
this.pending = setTimeout(() => { this.pending = undefined; this.cycle(); }, 50);
|
|
81
|
+
this.pending.unref();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
get observationResources() { return { observers: this.observers.size, watchers: this.watchers.size, timer: !!this.timer, pending: !!this.pending }; }
|
|
85
|
+
|
|
54
86
|
connection() {
|
|
55
87
|
let registration: { cwd: string; sessionId: string; projectAccess: boolean; authority?: unknown } | undefined;
|
|
56
88
|
const location = () => {
|
|
@@ -71,9 +103,9 @@ export class SharedCatalog {
|
|
|
71
103
|
const loc = location();
|
|
72
104
|
if (command.type === "runtime_get_catalog_scope") {
|
|
73
105
|
if (command.scope !== "user" && command.scope !== "project") throw new Error("Invalid catalog scope");
|
|
74
|
-
return listScopedAgents(loc, command.scope);
|
|
106
|
+
return listScopedAgents({ ...loc, sources: this.sources }, command.scope);
|
|
75
107
|
}
|
|
76
|
-
const snapshot =
|
|
108
|
+
const snapshot = this.sources.load(loc, command.type === "runtime_edit_catalog" || command.fresh === true);
|
|
77
109
|
if (command.type === "runtime_get_catalog") {
|
|
78
110
|
const overlay = validateOverlay(command.overlay);
|
|
79
111
|
if (registration?.authority && command.overlay !== undefined) {
|
package/src/runtime/client.ts
CHANGED
|
@@ -88,11 +88,12 @@ export async function ensureRuntime(options: RuntimeOptions): Promise<any> {
|
|
|
88
88
|
catch (error) {
|
|
89
89
|
if (!["ENOENT", "ECONNREFUSED"].includes((error as NodeJS.ErrnoException).code ?? "")) throw error;
|
|
90
90
|
}
|
|
91
|
-
const
|
|
92
|
-
if (
|
|
91
|
+
const recovered = await waitForRuntimeOwner(root.serverDir, query, timeoutMs, options.signal);
|
|
92
|
+
if (recovered !== undefined) return recovered;
|
|
93
93
|
let runtime;
|
|
94
94
|
try { runtime = await stageRuntime({ run: runLocal, artifact, installRoot: options.installRoot ?? join(root.agentDir, "managed-runtime"), signal: options.signal, onProgress: options.onProgress, offline: options.offline }); }
|
|
95
95
|
catch (error) { throw new Error(`runtime-unavailable: ${String(error)}. Connect to the network to cache the pinned runtime, or repair the reported corrupt cache; no fallback manager was started.`); }
|
|
96
|
+
options.signal?.throwIfAborted();
|
|
96
97
|
const fd = openSync(join(root.serverDir, "daemon.log"), "a", 0o600);
|
|
97
98
|
try {
|
|
98
99
|
const env = { ...process.env, PI_SERVER_DIR: root.serverDir, PI_CODING_AGENT_DIR: root.agentDir, PI_SERVER_AGENT: "pi" };
|
|
@@ -109,3 +110,22 @@ export async function ensureRuntime(options: RuntimeOptions): Promise<any> {
|
|
|
109
110
|
}
|
|
110
111
|
throw new Error(`runtime-unavailable: startup timed out; inspect ${join(root.serverDir, "daemon.log")}; owner was not replaced`);
|
|
111
112
|
}
|
|
113
|
+
|
|
114
|
+
/** Wait for the current owner to listen or release ownership; never replace it. */
|
|
115
|
+
export async function waitForRuntimeOwner(serverDir: string, query: () => Promise<any>, timeoutMs: number, signal?: AbortSignal): Promise<any | undefined> {
|
|
116
|
+
// A draining owner can outlive its listening socket. Wait for it rather than
|
|
117
|
+
// treating the handoff window as failure or starting a competing writer.
|
|
118
|
+
const ownerDeadline = Date.now() + timeoutMs;
|
|
119
|
+
let backoff = 100;
|
|
120
|
+
for (;;) {
|
|
121
|
+
const owner = inspectDaemonOwner(serverDir);
|
|
122
|
+
if (owner.status === "ambiguous") throw new Error(`runtime-unhealthy: existing ambiguous owner at ${serverDir}; no replacement was started`);
|
|
123
|
+
if (owner.status !== "live") return undefined;
|
|
124
|
+
signal?.throwIfAborted();
|
|
125
|
+
if (Date.now() >= ownerDeadline) throw new Error("runtime-unavailable: reconnect deadline exceeded waiting for existing live owner");
|
|
126
|
+
await delay(Math.min(backoff, ownerDeadline - Date.now()), undefined, { signal });
|
|
127
|
+
backoff = Math.min(1000, backoff * 2);
|
|
128
|
+
try { return await query(); }
|
|
129
|
+
catch (error) { if (!["ENOENT", "ECONNREFUSED"].includes((error as NodeJS.ErrnoException).code ?? "")) throw error; }
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// Generated from packages/operation-coordinator/assignment-inbox.mjs. Do not edit directly.
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
|
|
4
|
+
/** Rebuildable observation state, never an execution or delivery credential. */
|
|
5
|
+
export class AssignmentInbox {
|
|
6
|
+
constructor(path, connectionOrOptions, options = {}) {
|
|
7
|
+
const connection = typeof connectionOrOptions?.prepare === "function" ? connectionOrOptions : undefined;
|
|
8
|
+
if (!connection) options = connectionOrOptions ?? options;
|
|
9
|
+
this.entityPrefix = options.entityPrefix;
|
|
10
|
+
const { DatabaseSync } = createRequire(import.meta.url)("node:sqlite");
|
|
11
|
+
this.shared = Boolean(connection);
|
|
12
|
+
this.db = connection ?? new DatabaseSync(path);
|
|
13
|
+
this.alias = this.entityPrefix === "background:" ? "background_inbox" : "assignment_inbox";
|
|
14
|
+
this.prefix = connection ? `${this.alias}.` : "";
|
|
15
|
+
let attached = false;
|
|
16
|
+
try {
|
|
17
|
+
// Share the query owner's handle; only the attached derived file is durable.
|
|
18
|
+
if (connection) {
|
|
19
|
+
connection.prepare(`ATTACH DATABASE ? AS ${this.alias}`).run(path);
|
|
20
|
+
attached = true;
|
|
21
|
+
}
|
|
22
|
+
// A second observer may open while the first holds a derived write
|
|
23
|
+
// transaction. Existing schema/diagnostics require no write reservation.
|
|
24
|
+
const tables = this.db.prepare(`SELECT count(*) AS n FROM ${this.prefix}sqlite_master
|
|
25
|
+
WHERE type='table' AND name IN ('position','pending','applied_scopes','diagnostics')`).get().n;
|
|
26
|
+
if (tables === 4 && this.db.prepare(`SELECT 1 FROM ${this.prefix}diagnostics LIMIT 1`).get()) return;
|
|
27
|
+
this.db.exec(`CREATE TABLE IF NOT EXISTS ${this.prefix}position (
|
|
28
|
+
singleton INTEGER PRIMARY KEY CHECK(singleton=1), generation TEXT NOT NULL,
|
|
29
|
+
received INTEGER NOT NULL, applied INTEGER NOT NULL);
|
|
30
|
+
CREATE TABLE IF NOT EXISTS ${this.prefix}pending (
|
|
31
|
+
scope TEXT PRIMARY KEY, seq INTEGER NOT NULL, first_seq INTEGER NOT NULL, since INTEGER NOT NULL);
|
|
32
|
+
CREATE TABLE IF NOT EXISTS ${this.prefix}applied_scopes (scope TEXT PRIMARY KEY, seq INTEGER NOT NULL);
|
|
33
|
+
CREATE TABLE IF NOT EXISTS ${this.prefix}diagnostics (repairs INTEGER NOT NULL);`);
|
|
34
|
+
// Reopening an initialized inbox must not reserve every attached file
|
|
35
|
+
// merely to execute an INSERT whose SELECT would produce no rows.
|
|
36
|
+
if (!this.db.prepare(`SELECT 1 FROM ${this.prefix}diagnostics LIMIT 1`).get()) {
|
|
37
|
+
this.db.exec(`INSERT INTO ${this.prefix}diagnostics SELECT 0 WHERE NOT EXISTS (SELECT 1 FROM ${this.prefix}diagnostics)`);
|
|
38
|
+
}
|
|
39
|
+
} catch (error) {
|
|
40
|
+
// A failed constructor cannot transfer its alias to a caller.
|
|
41
|
+
// Never detach an earlier participant or close a borrowed owner.
|
|
42
|
+
try {
|
|
43
|
+
if (attached) this.db.exec(`DETACH DATABASE ${this.alias}`);
|
|
44
|
+
else if (!connection) this.db.close();
|
|
45
|
+
} catch (cleanup) { throw new AggregateError([error, cleanup], "Assignment inbox initialization and owned cleanup failed"); }
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
receive(source, identity) {
|
|
51
|
+
const version = source.prepare("SELECT value FROM schema_meta WHERE key='schema_version'").get()?.value;
|
|
52
|
+
if (!["1", "2", "3", "4"].includes(version)) throw new Error("Unsupported assignment source schema");
|
|
53
|
+
const token = source.prepare("SELECT generation FROM assignment_change_source WHERE singleton=1").get()?.generation;
|
|
54
|
+
if (!token) throw new Error("Assignment change journal unavailable");
|
|
55
|
+
const generation = `${identity}:${version}:${token}`;
|
|
56
|
+
const bounds = source.prepare("SELECT min(seq) AS first, max(seq) AS last FROM assignment_changes").get();
|
|
57
|
+
const last = Number(bounds.last ?? 0);
|
|
58
|
+
const position = this.db.prepare(`SELECT * FROM ${this.prefix}position WHERE singleton=1`).get();
|
|
59
|
+
const reset = !position || position.generation !== generation || position.received > last
|
|
60
|
+
|| (bounds.first !== null && position.received < Number(bounds.first) - 1);
|
|
61
|
+
const after = reset ? last : position.received;
|
|
62
|
+
const changes = reset ? [] : source.prepare("SELECT * FROM assignment_changes WHERE seq>? ORDER BY seq LIMIT 128").all(after);
|
|
63
|
+
this.more = !reset && Number(changes.at(-1)?.seq ?? after) < last;
|
|
64
|
+
if (!reset && !changes.length) return this.batch(generation);
|
|
65
|
+
this.db.exec(this.shared ? `SAVEPOINT ${this.alias}_receive` : "BEGIN IMMEDIATE");
|
|
66
|
+
try {
|
|
67
|
+
if (reset) {
|
|
68
|
+
this.db.exec(`DELETE FROM ${this.prefix}pending; DELETE FROM ${this.prefix}applied_scopes; UPDATE ${this.prefix}diagnostics SET repairs=repairs+1`);
|
|
69
|
+
this.db.prepare(`INSERT INTO ${this.prefix}pending VALUES('*', ?, 0, ?)`).run(last, Date.now());
|
|
70
|
+
this.db.prepare(`INSERT OR REPLACE INTO ${this.prefix}position VALUES(1, ?, ?, 0)`).run(generation, last);
|
|
71
|
+
}
|
|
72
|
+
const insert = this.db.prepare(`INSERT INTO ${this.prefix}pending VALUES(?, ?, ?, ?)
|
|
73
|
+
ON CONFLICT(scope) DO UPDATE SET seq=excluded.seq`);
|
|
74
|
+
for (const change of changes) {
|
|
75
|
+
const background = change.entity.startsWith('background:');
|
|
76
|
+
if (this.entityPrefix ? !change.entity.startsWith(this.entityPrefix) : background) continue;
|
|
77
|
+
insert.run(JSON.stringify([change.session_id, change.workspace, change.assignment_id]), change.seq, change.seq, Date.now());
|
|
78
|
+
}
|
|
79
|
+
// The obligations above and received position commit together.
|
|
80
|
+
if (changes.length) this.db.prepare(`UPDATE ${this.prefix}position SET received=? WHERE singleton=1`).run(changes.at(-1).seq);
|
|
81
|
+
this.db.exec(this.shared ? `RELEASE ${this.alias}_receive` : "COMMIT");
|
|
82
|
+
} catch (error) { this.db.exec(this.shared ? `ROLLBACK TO ${this.alias}_receive; RELEASE ${this.alias}_receive` : "ROLLBACK"); throw error; }
|
|
83
|
+
return this.batch(generation);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
batch(generation) {
|
|
87
|
+
const batch = new Map(this.db.prepare(`SELECT scope, seq FROM ${this.prefix}pending ORDER BY first_seq, scope LIMIT 128`).all().map(row => [row.scope, String(row.seq)]));
|
|
88
|
+
Object.defineProperty(batch, "generation", { value: generation });
|
|
89
|
+
return batch;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
acknowledge(batch, baselineComplete) {
|
|
93
|
+
const position = this.db.prepare(`SELECT * FROM ${this.prefix}position WHERE singleton=1`).get();
|
|
94
|
+
if (batch.generation && batch.generation !== position?.generation) return;
|
|
95
|
+
if (batch.size && ![...batch.keys()].some(scope => scope !== "*" || baselineComplete)) return;
|
|
96
|
+
if (!batch.size && (!position || position.applied === position.received)) return;
|
|
97
|
+
this.db.exec(this.shared ? `SAVEPOINT ${this.alias}_ack` : "BEGIN IMMEDIATE");
|
|
98
|
+
try {
|
|
99
|
+
const remove = this.db.prepare(`DELETE FROM ${this.prefix}pending WHERE scope=? AND seq=?`);
|
|
100
|
+
const applied = this.db.prepare(`INSERT INTO ${this.prefix}applied_scopes VALUES(?,?) ON CONFLICT(scope) DO UPDATE SET seq=max(seq,excluded.seq)`);
|
|
101
|
+
for (const [scope, seq] of batch) if (scope !== "*" || baselineComplete) {
|
|
102
|
+
if (remove.run(scope, Number(seq)).changes) applied.run(scope, Number(seq));
|
|
103
|
+
}
|
|
104
|
+
// A later entity completing cannot advance past any earlier obligation.
|
|
105
|
+
this.db.exec(`UPDATE ${this.prefix}position SET applied=max(0,min(received,
|
|
106
|
+
COALESCE((SELECT min(first_seq)-1 FROM ${this.prefix}pending), received))) WHERE singleton=1`);
|
|
107
|
+
this.db.exec(this.shared ? `RELEASE ${this.alias}_ack` : "COMMIT");
|
|
108
|
+
} catch (error) { this.db.exec(this.shared ? `ROLLBACK TO ${this.alias}_ack; RELEASE ${this.alias}_ack` : "ROLLBACK"); throw error; }
|
|
109
|
+
}
|
|
110
|
+
get metrics() {
|
|
111
|
+
const pending = this.db.prepare(`SELECT count(*) AS pending, min(since) AS oldestPendingAt FROM ${this.prefix}pending`).get();
|
|
112
|
+
return { ...this.db.prepare(`SELECT * FROM ${this.prefix}position`).get(),
|
|
113
|
+
more: Boolean(this.more),
|
|
114
|
+
affected: this.db.prepare(`SELECT scope, seq, first_seq, since FROM ${this.prefix}pending ORDER BY first_seq, scope LIMIT 128`).all(),
|
|
115
|
+
...pending, oldestPendingAgeMs: pending.oldestPendingAt === null ? 0 : Math.max(0, Date.now() - Number(pending.oldestPendingAt)),
|
|
116
|
+
...this.db.prepare(`SELECT repairs FROM ${this.prefix}diagnostics`).get() };
|
|
117
|
+
}
|
|
118
|
+
close() { if (this.shared) this.db.exec(`DETACH DATABASE ${this.alias}`); else this.db.close(); }
|
|
119
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export function createAssignmentReader(path: string): { revision(): string; beginSnapshot(): { revision: string; release(): void }; read(owner: any): any;
|
|
1
|
+
export function createAssignmentReader(path: string, inboxPath?: string, derivedConnection?: any, options?: { composed?: boolean }): { revision(): string; connection(refresh?: boolean): any; beginSnapshot(): { revision: string; release(): void; commit(): void }; readonly snapshotActive: boolean; read(owner: any): any; changes(): Map<string, string>; acknowledgeChanges(batch: Map<string, string>, complete: boolean): void; readonly changeMetrics: any; upgradeObligations(): any[]; close(): void };
|