@caupulican/pi-adaptative 0.81.39 → 0.81.41
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/CHANGELOG.md +77 -0
- package/README.md +2 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts +2 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js +3 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.ts +4 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts +9 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +290 -107
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +357 -122
- package/dist/bundled-resources/skills/tool-call-repair/references/repair-catalogue.md +2 -2
- package/dist/cli/args.d.ts +4 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +31 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-directory-layout.d.ts +15 -0
- package/dist/core/agent-directory-layout.d.ts.map +1 -0
- package/dist/core/agent-directory-layout.js +72 -0
- package/dist/core/agent-directory-layout.js.map +1 -0
- package/dist/core/agent-paths.d.ts +25 -2
- package/dist/core/agent-paths.d.ts.map +1 -1
- package/dist/core/agent-paths.js +79 -4
- package/dist/core/agent-paths.js.map +1 -1
- package/dist/core/agent-session-contracts.d.ts +293 -0
- package/dist/core/agent-session-contracts.d.ts.map +1 -0
- package/dist/core/agent-session-contracts.js +26 -0
- package/dist/core/agent-session-contracts.js.map +1 -0
- package/dist/core/agent-session-runtime.d.ts +52 -8
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +400 -79
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +1 -0
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +1 -0
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +74 -518
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +370 -1432
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +3 -1
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/autonomy/approval-gate.d.ts +3 -2
- package/dist/core/autonomy/approval-gate.d.ts.map +1 -1
- package/dist/core/autonomy/approval-gate.js +6 -28
- package/dist/core/autonomy/approval-gate.js.map +1 -1
- package/dist/core/autonomy/bounded-completion.d.ts +1 -1
- package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
- package/dist/core/autonomy/bounded-completion.js +1 -1
- package/dist/core/autonomy/bounded-completion.js.map +1 -1
- package/dist/core/autonomy/contracts.d.ts +20 -12
- package/dist/core/autonomy/contracts.d.ts.map +1 -1
- package/dist/core/autonomy/contracts.js.map +1 -1
- package/dist/core/autonomy/foreground-envelope.d.ts +8 -2
- package/dist/core/autonomy/foreground-envelope.d.ts.map +1 -1
- package/dist/core/autonomy/foreground-envelope.js +8 -25
- package/dist/core/autonomy/foreground-envelope.js.map +1 -1
- package/dist/core/autonomy/gates.d.ts.map +1 -1
- package/dist/core/autonomy/gates.js +8 -10
- package/dist/core/autonomy/gates.js.map +1 -1
- package/dist/core/autonomy/lane-private-paths.d.ts +2 -0
- package/dist/core/autonomy/lane-private-paths.d.ts.map +1 -0
- package/dist/core/autonomy/lane-private-paths.js +16 -0
- package/dist/core/autonomy/lane-private-paths.js.map +1 -0
- package/dist/core/autonomy/lane-tool-surface.d.ts +10 -0
- package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.js +48 -9
- package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
- package/dist/core/autonomy/lane-tracker.d.ts +14 -0
- package/dist/core/autonomy/lane-tracker.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tracker.js +38 -0
- package/dist/core/autonomy/lane-tracker.js.map +1 -1
- package/dist/core/autonomy/risk-assessment.d.ts +1 -2
- package/dist/core/autonomy/risk-assessment.d.ts.map +1 -1
- package/dist/core/autonomy/risk-assessment.js +1 -123
- package/dist/core/autonomy/risk-assessment.js.map +1 -1
- package/dist/core/autonomy/session-lane-record.d.ts +4 -4
- package/dist/core/autonomy/session-lane-record.d.ts.map +1 -1
- package/dist/core/autonomy/session-lane-record.js +16 -29
- package/dist/core/autonomy/session-lane-record.js.map +1 -1
- package/dist/core/autonomy/telemetry-events.d.ts +1 -1
- package/dist/core/autonomy/telemetry-events.d.ts.map +1 -1
- package/dist/core/autonomy/telemetry-events.js +1 -1
- package/dist/core/autonomy/telemetry-events.js.map +1 -1
- package/dist/core/autonomy-telemetry.d.ts +7 -7
- package/dist/core/autonomy-telemetry.d.ts.map +1 -1
- package/dist/core/autonomy-telemetry.js +9 -9
- package/dist/core/autonomy-telemetry.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +56 -236
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +141 -1273
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/bedrock-sso-login.d.ts +16 -0
- package/dist/core/bedrock-sso-login.d.ts.map +1 -0
- package/dist/core/bedrock-sso-login.js +98 -0
- package/dist/core/bedrock-sso-login.js.map +1 -0
- package/dist/core/capability-contract.d.ts +4 -0
- package/dist/core/capability-contract.d.ts.map +1 -0
- package/dist/core/capability-contract.js +28 -0
- package/dist/core/capability-contract.js.map +1 -0
- package/dist/core/compaction-controller.d.ts +90 -0
- package/dist/core/compaction-controller.d.ts.map +1 -0
- package/dist/core/compaction-controller.js +452 -0
- package/dist/core/compaction-controller.js.map +1 -0
- package/dist/core/compaction-support.d.ts +13 -17
- package/dist/core/compaction-support.d.ts.map +1 -1
- package/dist/core/compaction-support.js +3 -3
- package/dist/core/compaction-support.js.map +1 -1
- package/dist/core/context/context-artifacts.d.ts +6 -2
- package/dist/core/context/context-artifacts.d.ts.map +1 -1
- package/dist/core/context/context-artifacts.js +34 -2
- package/dist/core/context/context-artifacts.js.map +1 -1
- package/dist/core/context/context-store-retention.d.ts +8 -2
- package/dist/core/context/context-store-retention.d.ts.map +1 -1
- package/dist/core/context/context-store-retention.js +158 -35
- package/dist/core/context/context-store-retention.js.map +1 -1
- package/dist/core/context/okf-memory.d.ts.map +1 -1
- package/dist/core/context/okf-memory.js +9 -11
- package/dist/core/context/okf-memory.js.map +1 -1
- package/dist/core/context/sqlite-runtime-index.d.ts.map +1 -1
- package/dist/core/context/sqlite-runtime-index.js +6 -8
- package/dist/core/context/sqlite-runtime-index.js.map +1 -1
- package/dist/core/context-gc.d.ts +3 -0
- package/dist/core/context-gc.d.ts.map +1 -1
- package/dist/core/context-gc.js +10 -5
- package/dist/core/context-gc.js.map +1 -1
- package/dist/core/context-pipeline.d.ts +1 -1
- package/dist/core/context-pipeline.d.ts.map +1 -1
- package/dist/core/context-pipeline.js +16 -37
- package/dist/core/context-pipeline.js.map +1 -1
- package/dist/core/cost/cost-summary.d.ts.map +1 -1
- package/dist/core/cost/cost-summary.js +5 -3
- package/dist/core/cost/cost-summary.js.map +1 -1
- package/dist/core/cost/daily-usage.d.ts.map +1 -1
- package/dist/core/cost/daily-usage.js +4 -5
- package/dist/core/cost/daily-usage.js.map +1 -1
- package/dist/core/default-tool-surface.d.ts.map +1 -1
- package/dist/core/default-tool-surface.js +2 -0
- package/dist/core/default-tool-surface.js.map +1 -1
- package/dist/core/delegation/managed-lane-controller.d.ts +34 -0
- package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -0
- package/dist/core/delegation/managed-lane-controller.js +217 -0
- package/dist/core/delegation/managed-lane-controller.js.map +1 -0
- package/dist/core/delegation/session-worker-claim.d.ts +44 -0
- package/dist/core/delegation/session-worker-claim.d.ts.map +1 -0
- package/dist/core/delegation/session-worker-claim.js +98 -0
- package/dist/core/delegation/session-worker-claim.js.map +1 -0
- package/dist/core/delegation/worker-actions.d.ts +7 -5
- package/dist/core/delegation/worker-actions.d.ts.map +1 -1
- package/dist/core/delegation/worker-actions.js +20 -4
- package/dist/core/delegation/worker-actions.js.map +1 -1
- package/dist/core/delegation/{worker-result.d.ts → worker-claim.d.ts} +13 -13
- package/dist/core/delegation/worker-claim.d.ts.map +1 -0
- package/dist/core/delegation/{worker-result.js → worker-claim.js} +61 -51
- package/dist/core/delegation/worker-claim.js.map +1 -0
- package/dist/core/delegation/worker-delegation-controller.d.ts +110 -0
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -0
- package/dist/core/delegation/worker-delegation-controller.js +861 -0
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -0
- package/dist/core/delegation/worker-delegation-request.d.ts +11 -0
- package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -0
- package/dist/core/delegation/worker-delegation-request.js +2 -0
- package/dist/core/delegation/worker-delegation-request.js.map +1 -0
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts +40 -0
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -0
- package/dist/core/delegation/worker-dispatch-scheduler.js +93 -0
- package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -0
- package/dist/core/delegation/worker-execution-policy.d.ts +62 -0
- package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -0
- package/dist/core/delegation/worker-execution-policy.js +160 -0
- package/dist/core/delegation/worker-execution-policy.js.map +1 -0
- package/dist/core/delegation/worker-lane-projection.d.ts +14 -0
- package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -0
- package/dist/core/delegation/worker-lane-projection.js +100 -0
- package/dist/core/delegation/worker-lane-projection.js.map +1 -0
- package/dist/core/delegation/worker-lifecycle.d.ts +97 -0
- package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -0
- package/dist/core/delegation/worker-lifecycle.js +339 -0
- package/dist/core/delegation/worker-lifecycle.js.map +1 -0
- package/dist/core/delegation/worker-notification-coordinator.d.ts +36 -0
- package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -0
- package/dist/core/delegation/worker-notification-coordinator.js +90 -0
- package/dist/core/delegation/worker-notification-coordinator.js.map +1 -0
- package/dist/core/delegation/worker-profile-resolver.d.ts +55 -0
- package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -0
- package/dist/core/delegation/worker-profile-resolver.js +113 -0
- package/dist/core/delegation/worker-profile-resolver.js.map +1 -0
- package/dist/core/delegation/worker-runner.d.ts +25 -14
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +122 -53
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/delegation/worker-task-label.d.ts +3 -0
- package/dist/core/delegation/worker-task-label.d.ts.map +1 -0
- package/dist/core/delegation/worker-task-label.js +11 -0
- package/dist/core/delegation/worker-task-label.js.map +1 -0
- package/dist/core/doctor.d.ts +8 -0
- package/dist/core/doctor.d.ts.map +1 -1
- package/dist/core/doctor.js +32 -1
- package/dist/core/doctor.js.map +1 -1
- package/dist/core/extension-import-authority.d.ts +6 -0
- package/dist/core/extension-import-authority.d.ts.map +1 -0
- package/dist/core/extension-import-authority.js +10 -0
- package/dist/core/extension-import-authority.js.map +1 -0
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts +5 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +52 -18
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +3 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +20 -5
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/stale-context.d.ts +2 -0
- package/dist/core/extensions/stale-context.d.ts.map +1 -0
- package/dist/core/extensions/stale-context.js +2 -0
- package/dist/core/extensions/stale-context.js.map +1 -0
- package/dist/core/extensions/storage.d.ts +8 -0
- package/dist/core/extensions/storage.d.ts.map +1 -0
- package/dist/core/extensions/storage.js +28 -0
- package/dist/core/extensions/storage.js.map +1 -0
- package/dist/core/extensions/types.d.ts +78 -21
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/failure-corpus.d.ts +1 -15
- package/dist/core/failure-corpus.d.ts.map +1 -1
- package/dist/core/failure-corpus.js +9 -37
- package/dist/core/failure-corpus.js.map +1 -1
- package/dist/core/foreground-recovery-controller.d.ts +53 -0
- package/dist/core/foreground-recovery-controller.d.ts.map +1 -0
- package/dist/core/foreground-recovery-controller.js +111 -0
- package/dist/core/foreground-recovery-controller.js.map +1 -0
- package/dist/core/gateways/channel-provider.d.ts +3 -0
- package/dist/core/gateways/channel-provider.d.ts.map +1 -1
- package/dist/core/gateways/channel-provider.js +31 -6
- package/dist/core/gateways/channel-provider.js.map +1 -1
- package/dist/core/goal-loop-controller.d.ts +14 -9
- package/dist/core/goal-loop-controller.d.ts.map +1 -1
- package/dist/core/goal-loop-controller.js +47 -75
- package/dist/core/goal-loop-controller.js.map +1 -1
- package/dist/core/goals/compact-goal-context.d.ts +11 -0
- package/dist/core/goals/compact-goal-context.d.ts.map +1 -0
- package/dist/core/goals/compact-goal-context.js +59 -0
- package/dist/core/goals/compact-goal-context.js.map +1 -0
- package/dist/core/goals/goal-acceptance.d.ts +11 -0
- package/dist/core/goals/goal-acceptance.d.ts.map +1 -0
- package/dist/core/goals/goal-acceptance.js +27 -0
- package/dist/core/goals/goal-acceptance.js.map +1 -0
- package/dist/core/goals/goal-auto-continue-controller.d.ts +28 -0
- package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -0
- package/dist/core/goals/goal-auto-continue-controller.js +90 -0
- package/dist/core/goals/goal-auto-continue-controller.js.map +1 -0
- package/dist/core/goals/goal-continuation-controller.d.ts +2 -2
- package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-controller.js +52 -11
- package/dist/core/goals/goal-continuation-controller.js.map +1 -1
- package/dist/core/goals/goal-continuation-defaults.d.ts +4 -29
- package/dist/core/goals/goal-continuation-defaults.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-defaults.js +4 -32
- package/dist/core/goals/goal-continuation-defaults.js.map +1 -1
- package/dist/core/goals/goal-continuation-prompt.d.ts +8 -18
- package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-prompt.js +9 -179
- package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
- package/dist/core/goals/goal-lifecycle.d.ts +43 -0
- package/dist/core/goals/goal-lifecycle.d.ts.map +1 -0
- package/dist/core/goals/goal-lifecycle.js +102 -0
- package/dist/core/goals/goal-lifecycle.js.map +1 -0
- package/dist/core/goals/goal-record.d.ts +17 -0
- package/dist/core/goals/goal-record.d.ts.map +1 -0
- package/dist/core/goals/goal-record.js +31 -0
- package/dist/core/goals/goal-record.js.map +1 -0
- package/dist/core/goals/goal-runtime-snapshot.d.ts +11 -9
- package/dist/core/goals/goal-runtime-snapshot.d.ts.map +1 -1
- package/dist/core/goals/goal-runtime-snapshot.js +10 -8
- package/dist/core/goals/goal-runtime-snapshot.js.map +1 -1
- package/dist/core/goals/goal-session-controller.d.ts +42 -0
- package/dist/core/goals/goal-session-controller.d.ts.map +1 -0
- package/dist/core/goals/goal-session-controller.js +128 -0
- package/dist/core/goals/goal-session-controller.js.map +1 -0
- package/dist/core/goals/goal-state.d.ts +46 -25
- package/dist/core/goals/goal-state.d.ts.map +1 -1
- package/dist/core/goals/goal-state.js +91 -24
- package/dist/core/goals/goal-state.js.map +1 -1
- package/dist/core/goals/goal-tool-core.d.ts +9 -10
- package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
- package/dist/core/goals/goal-tool-core.js +60 -75
- package/dist/core/goals/goal-tool-core.js.map +1 -1
- package/dist/core/goals/session-goal-state.d.ts +20 -12
- package/dist/core/goals/session-goal-state.d.ts.map +1 -1
- package/dist/core/goals/session-goal-state.js +133 -33
- package/dist/core/goals/session-goal-state.js.map +1 -1
- package/dist/core/human-input-controller.d.ts +47 -0
- package/dist/core/human-input-controller.d.ts.map +1 -0
- package/dist/core/human-input-controller.js +181 -0
- package/dist/core/human-input-controller.js.map +1 -0
- package/dist/core/human-input.d.ts +100 -0
- package/dist/core/human-input.d.ts.map +1 -0
- package/dist/core/human-input.js +362 -0
- package/dist/core/human-input.js.map +1 -0
- package/dist/core/index.d.ts +9 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +9 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/{telemetry.d.ts → install-telemetry.d.ts} +1 -1
- package/dist/core/install-telemetry.d.ts.map +1 -0
- package/dist/core/{telemetry.js → install-telemetry.js} +1 -1
- package/dist/core/install-telemetry.js.map +1 -0
- package/dist/core/keybindings.d.ts +17 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +24 -6
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/learning/learning-audit.d.ts +2 -4
- package/dist/core/learning/learning-audit.d.ts.map +1 -1
- package/dist/core/learning/learning-audit.js +9 -29
- package/dist/core/learning/learning-audit.js.map +1 -1
- package/dist/core/learning/learning-gate.d.ts.map +1 -1
- package/dist/core/learning/learning-gate.js +1 -6
- package/dist/core/learning/learning-gate.js.map +1 -1
- package/dist/core/learning/session-learning-decision.d.ts +2 -4
- package/dist/core/learning/session-learning-decision.d.ts.map +1 -1
- package/dist/core/learning/session-learning-decision.js +9 -29
- package/dist/core/learning/session-learning-decision.js.map +1 -1
- package/dist/core/local-runtime-controller.d.ts +1 -1
- package/dist/core/local-runtime-controller.d.ts.map +1 -1
- package/dist/core/local-runtime-controller.js.map +1 -1
- package/dist/core/memory-controller.d.ts.map +1 -1
- package/dist/core/memory-controller.js +4 -4
- package/dist/core/memory-controller.js.map +1 -1
- package/dist/core/model-capability.d.ts +0 -19
- package/dist/core/model-capability.d.ts.map +1 -1
- package/dist/core/model-capability.js +1 -19
- package/dist/core/model-capability.js.map +1 -1
- package/dist/core/model-registry.d.ts +6 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +13 -5
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +17 -2
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +38 -25
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-router/intent-classifier.d.ts +1 -4
- package/dist/core/model-router/intent-classifier.d.ts.map +1 -1
- package/dist/core/model-router/intent-classifier.js +1 -156
- package/dist/core/model-router/intent-classifier.js.map +1 -1
- package/dist/core/model-router-controller.d.ts +1 -1
- package/dist/core/model-router-controller.d.ts.map +1 -1
- package/dist/core/model-router-controller.js +2 -2
- package/dist/core/model-router-controller.js.map +1 -1
- package/dist/core/model-selection-controller.d.ts +5 -5
- package/dist/core/model-selection-controller.d.ts.map +1 -1
- package/dist/core/model-selection-controller.js.map +1 -1
- package/dist/core/model-tool-protocol.d.ts +23 -0
- package/dist/core/model-tool-protocol.d.ts.map +1 -0
- package/dist/core/model-tool-protocol.js +43 -0
- package/dist/core/model-tool-protocol.js.map +1 -0
- package/dist/core/models/adaptation-store.d.ts +4 -6
- package/dist/core/models/adaptation-store.d.ts.map +1 -1
- package/dist/core/models/adaptation-store.js +95 -83
- package/dist/core/models/adaptation-store.js.map +1 -1
- package/dist/core/models/fitness-store.d.ts +2 -12
- package/dist/core/models/fitness-store.d.ts.map +1 -1
- package/dist/core/models/fitness-store.js +84 -57
- package/dist/core/models/fitness-store.js.map +1 -1
- package/dist/core/models/host-state-store.d.ts +34 -0
- package/dist/core/models/host-state-store.d.ts.map +1 -0
- package/dist/core/models/host-state-store.js +86 -0
- package/dist/core/models/host-state-store.js.map +1 -0
- package/dist/core/orchestration/agent-resume.d.ts +24 -0
- package/dist/core/orchestration/agent-resume.d.ts.map +1 -0
- package/dist/core/orchestration/agent-resume.js +90 -0
- package/dist/core/orchestration/agent-resume.js.map +1 -0
- package/dist/core/orchestration/capability-gateway.d.ts +61 -0
- package/dist/core/orchestration/capability-gateway.d.ts.map +1 -0
- package/dist/core/orchestration/capability-gateway.js +152 -0
- package/dist/core/orchestration/capability-gateway.js.map +1 -0
- package/dist/core/orchestration/contracts.d.ts +343 -0
- package/dist/core/orchestration/contracts.d.ts.map +1 -0
- package/dist/core/orchestration/contracts.js +135 -0
- package/dist/core/orchestration/contracts.js.map +1 -0
- package/dist/core/orchestration/delegation-ledger.d.ts +56 -0
- package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -0
- package/dist/core/orchestration/delegation-ledger.js +200 -0
- package/dist/core/orchestration/delegation-ledger.js.map +1 -0
- package/dist/core/orchestration/event-store.d.ts +83 -0
- package/dist/core/orchestration/event-store.d.ts.map +1 -0
- package/dist/core/orchestration/event-store.js +560 -0
- package/dist/core/orchestration/event-store.js.map +1 -0
- package/dist/core/orchestration/lane-tool-manifests.d.ts +9 -0
- package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -0
- package/dist/core/orchestration/lane-tool-manifests.js +37 -0
- package/dist/core/orchestration/lane-tool-manifests.js.map +1 -0
- package/dist/core/orchestration/model-binding.d.ts +15 -0
- package/dist/core/orchestration/model-binding.d.ts.map +1 -0
- package/dist/core/orchestration/model-binding.js +29 -0
- package/dist/core/orchestration/model-binding.js.map +1 -0
- package/dist/core/orchestration/policy-compiler.d.ts +49 -0
- package/dist/core/orchestration/policy-compiler.d.ts.map +1 -0
- package/dist/core/orchestration/policy-compiler.js +191 -0
- package/dist/core/orchestration/policy-compiler.js.map +1 -0
- package/dist/core/orchestration/policy-gate.d.ts +18 -0
- package/dist/core/orchestration/policy-gate.d.ts.map +1 -0
- package/dist/core/orchestration/policy-gate.js +24 -0
- package/dist/core/orchestration/policy-gate.js.map +1 -0
- package/dist/core/orchestration/profile-registry.d.ts +51 -0
- package/dist/core/orchestration/profile-registry.d.ts.map +1 -0
- package/dist/core/orchestration/profile-registry.js +393 -0
- package/dist/core/orchestration/profile-registry.js.map +1 -0
- package/dist/core/orchestration/profile-store.d.ts +31 -0
- package/dist/core/orchestration/profile-store.d.ts.map +1 -0
- package/dist/core/orchestration/profile-store.js +136 -0
- package/dist/core/orchestration/profile-store.js.map +1 -0
- package/dist/core/orchestration/risk-budget.d.ts +9 -0
- package/dist/core/orchestration/risk-budget.d.ts.map +1 -0
- package/dist/core/orchestration/risk-budget.js +48 -0
- package/dist/core/orchestration/risk-budget.js.map +1 -0
- package/dist/core/orchestration/task-runtime.d.ts +168 -0
- package/dist/core/orchestration/task-runtime.d.ts.map +1 -0
- package/dist/core/orchestration/task-runtime.js +1600 -0
- package/dist/core/orchestration/task-runtime.js.map +1 -0
- package/dist/core/orchestration/work-state-projection.d.ts +32 -0
- package/dist/core/orchestration/work-state-projection.d.ts.map +1 -0
- package/dist/core/orchestration/work-state-projection.js +116 -0
- package/dist/core/orchestration/work-state-projection.js.map +1 -0
- package/dist/core/orchestration/worker-execution-contract.d.ts +21 -0
- package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -0
- package/dist/core/orchestration/worker-execution-contract.js +179 -0
- package/dist/core/orchestration/worker-execution-contract.js.map +1 -0
- package/dist/core/orchestration/worker-result-adapter.d.ts +21 -0
- package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -0
- package/dist/core/orchestration/worker-result-adapter.js +109 -0
- package/dist/core/orchestration/worker-result-adapter.js.map +1 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +20 -3
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/process-identity.d.ts +11 -0
- package/dist/core/process-identity.d.ts.map +1 -0
- package/dist/core/process-identity.js +26 -0
- package/dist/core/process-identity.js.map +1 -0
- package/dist/core/process-matrix/codes.d.ts +14 -3
- package/dist/core/process-matrix/codes.d.ts.map +1 -1
- package/dist/core/process-matrix/codes.js.map +1 -1
- package/dist/core/process-matrix/resume-launcher.d.ts +26 -0
- package/dist/core/process-matrix/resume-launcher.d.ts.map +1 -0
- package/dist/core/process-matrix/resume-launcher.js +62 -0
- package/dist/core/process-matrix/resume-launcher.js.map +1 -0
- package/dist/core/process-matrix/runtime.d.ts +37 -22
- package/dist/core/process-matrix/runtime.d.ts.map +1 -1
- package/dist/core/process-matrix/runtime.js +399 -76
- package/dist/core/process-matrix/runtime.js.map +1 -1
- package/dist/core/process-matrix/store.d.ts +5 -2
- package/dist/core/process-matrix/store.d.ts.map +1 -1
- package/dist/core/process-matrix/store.js +123 -14
- package/dist/core/process-matrix/store.js.map +1 -1
- package/dist/core/process-matrix/supervisor.d.ts +10 -7
- package/dist/core/process-matrix/supervisor.d.ts.map +1 -1
- package/dist/core/process-matrix/supervisor.js +45 -14
- package/dist/core/process-matrix/supervisor.js.map +1 -1
- package/dist/core/profile-filter-controller.d.ts +8 -1
- package/dist/core/profile-filter-controller.d.ts.map +1 -1
- package/dist/core/profile-filter-controller.js +23 -5
- package/dist/core/profile-filter-controller.js.map +1 -1
- package/dist/core/profile-registry.d.ts.map +1 -1
- package/dist/core/profile-registry.js +6 -8
- package/dist/core/profile-registry.js.map +1 -1
- package/dist/core/prompt-templates.d.ts +1 -0
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +18 -29
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/reflection-controller.d.ts +5 -5
- package/dist/core/reflection-controller.d.ts.map +1 -1
- package/dist/core/reflection-controller.js +5 -2
- package/dist/core/reflection-controller.js.map +1 -1
- package/dist/core/reload-blockers.d.ts.map +1 -1
- package/dist/core/reload-blockers.js +6 -8
- package/dist/core/reload-blockers.js.map +1 -1
- package/dist/core/request-auth.d.ts +7 -0
- package/dist/core/request-auth.d.ts.map +1 -0
- package/dist/core/request-auth.js +8 -0
- package/dist/core/request-auth.js.map +1 -0
- package/dist/core/research/evidence-bundle.d.ts.map +1 -1
- package/dist/core/research/evidence-bundle.js +1 -6
- package/dist/core/research/evidence-bundle.js.map +1 -1
- package/dist/core/research/lane-model-resolver.d.ts +33 -0
- package/dist/core/research/lane-model-resolver.d.ts.map +1 -0
- package/dist/core/research/lane-model-resolver.js +65 -0
- package/dist/core/research/lane-model-resolver.js.map +1 -0
- package/dist/core/research/model-fitness-controller.d.ts +38 -0
- package/dist/core/research/model-fitness-controller.d.ts.map +1 -0
- package/dist/core/research/model-fitness-controller.js +106 -0
- package/dist/core/research/model-fitness-controller.js.map +1 -0
- package/dist/core/research/model-fitness.d.ts +1 -1
- package/dist/core/research/model-fitness.d.ts.map +1 -1
- package/dist/core/research/model-fitness.js +4 -4
- package/dist/core/research/model-fitness.js.map +1 -1
- package/dist/core/research/research-gate.d.ts.map +1 -1
- package/dist/core/research/research-gate.js +7 -7
- package/dist/core/research/research-gate.js.map +1 -1
- package/dist/core/research/research-lane-controller.d.ts +62 -0
- package/dist/core/research/research-lane-controller.d.ts.map +1 -0
- package/dist/core/research/research-lane-controller.js +292 -0
- package/dist/core/research/research-lane-controller.js.map +1 -0
- package/dist/core/research/session-evidence-bundle.d.ts +2 -4
- package/dist/core/research/session-evidence-bundle.d.ts.map +1 -1
- package/dist/core/research/session-evidence-bundle.js +10 -46
- package/dist/core/research/session-evidence-bundle.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +23 -8
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/risk-classifier.d.ts +6 -0
- package/dist/core/risk-classifier.d.ts.map +1 -0
- package/dist/core/risk-classifier.js +233 -0
- package/dist/core/risk-classifier.js.map +1 -0
- package/dist/core/runtime-builder.d.ts +41 -23
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +365 -253
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/sdk.d.ts +6 -3
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +68 -25
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/secrets/credential-exposure-guard.d.ts +9 -0
- package/dist/core/secrets/credential-exposure-guard.d.ts.map +1 -0
- package/dist/core/secrets/credential-exposure-guard.js +241 -0
- package/dist/core/secrets/credential-exposure-guard.js.map +1 -0
- package/dist/core/secrets/secret-dotenv.d.ts +27 -0
- package/dist/core/secrets/secret-dotenv.d.ts.map +1 -0
- package/dist/core/secrets/secret-dotenv.js +183 -0
- package/dist/core/secrets/secret-dotenv.js.map +1 -0
- package/dist/core/secrets/secret-vault-format.d.ts +112 -0
- package/dist/core/secrets/secret-vault-format.d.ts.map +1 -0
- package/dist/core/secrets/secret-vault-format.js +397 -0
- package/dist/core/secrets/secret-vault-format.js.map +1 -0
- package/dist/core/secrets/secret-vault.d.ts +72 -0
- package/dist/core/secrets/secret-vault.d.ts.map +1 -0
- package/dist/core/secrets/secret-vault.js +671 -0
- package/dist/core/secrets/secret-vault.js.map +1 -0
- package/dist/core/session-analytics.d.ts +4 -23
- package/dist/core/session-analytics.d.ts.map +1 -1
- package/dist/core/session-analytics.js +67 -70
- package/dist/core/session-analytics.js.map +1 -1
- package/dist/core/session-image-store.d.ts +33 -0
- package/dist/core/session-image-store.d.ts.map +1 -0
- package/dist/core/session-image-store.js +283 -0
- package/dist/core/session-image-store.js.map +1 -0
- package/dist/core/session-role.d.ts +11 -4
- package/dist/core/session-role.d.ts.map +1 -1
- package/dist/core/session-role.js +24 -5
- package/dist/core/session-role.js.map +1 -1
- package/dist/core/session-snapshot.d.ts +34 -0
- package/dist/core/session-snapshot.d.ts.map +1 -0
- package/dist/core/session-snapshot.js +68 -0
- package/dist/core/session-snapshot.js.map +1 -0
- package/dist/core/session-supervision-runtime.d.ts +31 -0
- package/dist/core/session-supervision-runtime.d.ts.map +1 -0
- package/dist/core/session-supervision-runtime.js +97 -0
- package/dist/core/session-supervision-runtime.js.map +1 -0
- package/dist/core/session-tree-navigator.d.ts +4 -6
- package/dist/core/session-tree-navigator.d.ts.map +1 -1
- package/dist/core/session-tree-navigator.js +4 -1
- package/dist/core/session-tree-navigator.js.map +1 -1
- package/dist/core/settings-manager.d.ts +10 -5
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +81 -29
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +2 -2
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/tasks/session-task-state.d.ts +2 -4
- package/dist/core/tasks/session-task-state.d.ts.map +1 -1
- package/dist/core/tasks/session-task-state.js +10 -28
- package/dist/core/tasks/session-task-state.js.map +1 -1
- package/dist/core/tasks/task-projection.d.ts +20 -0
- package/dist/core/tasks/task-projection.d.ts.map +1 -0
- package/dist/core/tasks/task-projection.js +47 -0
- package/dist/core/tasks/task-projection.js.map +1 -0
- package/dist/core/tasks/task-state.d.ts +4 -0
- package/dist/core/tasks/task-state.d.ts.map +1 -1
- package/dist/core/tasks/task-state.js +28 -11
- package/dist/core/tasks/task-state.js.map +1 -1
- package/dist/core/tool-capability-policy.d.ts +13 -0
- package/dist/core/tool-capability-policy.d.ts.map +1 -0
- package/dist/core/tool-capability-policy.js +86 -0
- package/dist/core/tool-capability-policy.js.map +1 -0
- package/dist/core/tool-gate-controller.d.ts.map +1 -1
- package/dist/core/tool-gate-controller.js +8 -2
- package/dist/core/tool-gate-controller.js.map +1 -1
- package/dist/core/tool-protocol-controller.d.ts +89 -0
- package/dist/core/tool-protocol-controller.d.ts.map +1 -0
- package/dist/core/tool-protocol-controller.js +512 -0
- package/dist/core/tool-protocol-controller.js.map +1 -0
- package/dist/core/tool-recovery-log-records.d.ts +2 -3
- package/dist/core/tool-recovery-log-records.d.ts.map +1 -1
- package/dist/core/tool-recovery-log-records.js +9 -35
- package/dist/core/tool-recovery-log-records.js.map +1 -1
- package/dist/core/tool-recovery-stats.d.ts +21 -1
- package/dist/core/tool-recovery-stats.d.ts.map +1 -1
- package/dist/core/tool-recovery-stats.js.map +1 -1
- package/dist/core/tool-selection/tool-performance-store.d.ts +3 -7
- package/dist/core/tool-selection/tool-performance-store.d.ts.map +1 -1
- package/dist/core/tool-selection/tool-performance-store.js +97 -138
- package/dist/core/tool-selection/tool-performance-store.js.map +1 -1
- package/dist/core/tools/ask-question.d.ts +124 -0
- package/dist/core/tools/ask-question.d.ts.map +1 -0
- package/dist/core/tools/ask-question.js +693 -0
- package/dist/core/tools/ask-question.js.map +1 -0
- package/dist/core/tools/bash.d.ts +5 -0
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +59 -5
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/delegate-status.d.ts +31 -3
- package/dist/core/tools/delegate-status.d.ts.map +1 -1
- package/dist/core/tools/delegate-status.js +148 -29
- package/dist/core/tools/delegate-status.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +15 -13
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +106 -23
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/extensionify.d.ts.map +1 -1
- package/dist/core/tools/extensionify.js +1 -0
- package/dist/core/tools/extensionify.js.map +1 -1
- package/dist/core/tools/git-filter.d.ts +1 -8
- package/dist/core/tools/git-filter.d.ts.map +1 -1
- package/dist/core/tools/git-filter.js +2 -63
- package/dist/core/tools/git-filter.js.map +1 -1
- package/dist/core/tools/goal.d.ts +10 -8
- package/dist/core/tools/goal.d.ts.map +1 -1
- package/dist/core/tools/goal.js +106 -28
- package/dist/core/tools/goal.js.map +1 -1
- package/dist/core/tools/index.d.ts +1 -0
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +1 -0
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/model-fitness.d.ts.map +1 -1
- package/dist/core/tools/model-fitness.js +2 -2
- package/dist/core/tools/model-fitness.js.map +1 -1
- package/dist/core/tools/orchestration-panel.d.ts +40 -0
- package/dist/core/tools/orchestration-panel.d.ts.map +1 -0
- package/dist/core/tools/orchestration-panel.js +124 -0
- package/dist/core/tools/orchestration-panel.js.map +1 -0
- package/dist/core/tools/output-accumulator.d.ts +11 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +36 -3
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/core/tools/python.d.ts +2 -0
- package/dist/core/tools/python.d.ts.map +1 -1
- package/dist/core/tools/python.js +3 -1
- package/dist/core/tools/python.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +1 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/run-process.d.ts +26 -0
- package/dist/core/tools/run-process.d.ts.map +1 -0
- package/dist/core/tools/run-process.js +138 -0
- package/dist/core/tools/run-process.js.map +1 -0
- package/dist/core/tools/search-command-guard.d.ts +14 -0
- package/dist/core/tools/search-command-guard.d.ts.map +1 -0
- package/dist/core/tools/search-command-guard.js +333 -0
- package/dist/core/tools/search-command-guard.js.map +1 -0
- package/dist/core/tools/secret-store.d.ts +38 -0
- package/dist/core/tools/secret-store.d.ts.map +1 -0
- package/dist/core/tools/secret-store.js +412 -0
- package/dist/core/tools/secret-store.js.map +1 -0
- package/dist/core/tools/shell-command-parser.d.ts +16 -0
- package/dist/core/tools/shell-command-parser.d.ts.map +1 -0
- package/dist/core/tools/shell-command-parser.js +113 -0
- package/dist/core/tools/shell-command-parser.js.map +1 -0
- package/dist/core/tools/task-steps.d.ts +2 -0
- package/dist/core/tools/task-steps.d.ts.map +1 -1
- package/dist/core/tools/task-steps.js +99 -0
- package/dist/core/tools/task-steps.js.map +1 -1
- package/dist/core/tools/tmux-dispatch.d.ts +3 -5
- package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
- package/dist/core/tools/tmux-dispatch.js +4 -4
- package/dist/core/tools/tmux-dispatch.js.map +1 -1
- package/dist/core/tools/windows-shell-engine.d.ts.map +1 -1
- package/dist/core/tools/windows-shell-engine.js +4 -6
- package/dist/core/tools/windows-shell-engine.js.map +1 -1
- package/dist/core/util/atomic-file.d.ts +6 -2
- package/dist/core/util/atomic-file.d.ts.map +1 -1
- package/dist/core/util/atomic-file.js +4 -4
- package/dist/core/util/atomic-file.js.map +1 -1
- package/dist/core/util/bounded-jsonl.d.ts +10 -0
- package/dist/core/util/bounded-jsonl.d.ts.map +1 -0
- package/dist/core/util/bounded-jsonl.js +75 -0
- package/dist/core/util/bounded-jsonl.js.map +1 -0
- package/dist/core/util/value-guards.d.ts +5 -0
- package/dist/core/util/value-guards.d.ts.map +1 -0
- package/dist/core/util/value-guards.js +12 -0
- package/dist/core/util/value-guards.js.map +1 -0
- package/dist/core/worktree-sync/store.d.ts +3 -3
- package/dist/core/worktree-sync/store.d.ts.map +1 -1
- package/dist/core/worktree-sync/store.js +10 -5
- package/dist/core/worktree-sync/store.js.map +1 -1
- package/dist/index.d.ts +15 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +149 -51
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts +4 -6
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +186 -28
- package/dist/migrations.js.map +1 -1
- package/dist/modes/interactive/auth-dialogs-controller.d.ts +4 -0
- package/dist/modes/interactive/auth-dialogs-controller.d.ts.map +1 -1
- package/dist/modes/interactive/auth-dialogs-controller.js +60 -1
- package/dist/modes/interactive/auth-dialogs-controller.js.map +1 -1
- package/dist/modes/interactive/clipboard-input.d.ts +7 -1
- package/dist/modes/interactive/clipboard-input.d.ts.map +1 -1
- package/dist/modes/interactive/clipboard-input.js +44 -6
- package/dist/modes/interactive/clipboard-input.js.map +1 -1
- package/dist/modes/interactive/components/activity-lane.d.ts +55 -0
- package/dist/modes/interactive/components/activity-lane.d.ts.map +1 -0
- package/dist/modes/interactive/components/activity-lane.js +304 -0
- package/dist/modes/interactive/components/activity-lane.js.map +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +19 -10
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/expandable-text.d.ts +12 -0
- package/dist/modes/interactive/components/expandable-text.d.ts.map +1 -0
- package/dist/modes/interactive/components/expandable-text.js +17 -0
- package/dist/modes/interactive/components/expandable-text.js.map +1 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +15 -1
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js +30 -21
- package/dist/modes/interactive/components/extension-editor.js.map +1 -1
- package/dist/modes/interactive/components/extension-input.d.ts +1 -0
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-input.js +6 -1
- package/dist/modes/interactive/components/extension-input.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +2 -2
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +23 -14
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +6 -6
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +19 -11
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +53 -20
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tool-group.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-group.js +3 -0
- package/dist/modes/interactive/components/tool-group.js.map +1 -1
- package/dist/modes/interactive/components/usage-action-selector.d.ts +16 -0
- package/dist/modes/interactive/components/usage-action-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/usage-action-selector.js +46 -0
- package/dist/modes/interactive/components/usage-action-selector.js.map +1 -0
- package/dist/modes/interactive/config-backup.d.ts.map +1 -1
- package/dist/modes/interactive/config-backup.js +5 -4
- package/dist/modes/interactive/config-backup.js.map +1 -1
- package/dist/modes/interactive/extension-ui-host.d.ts +14 -0
- package/dist/modes/interactive/extension-ui-host.d.ts.map +1 -1
- package/dist/modes/interactive/extension-ui-host.js +77 -15
- package/dist/modes/interactive/extension-ui-host.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts +15 -0
- package/dist/modes/interactive/external-editor.d.ts.map +1 -1
- package/dist/modes/interactive/external-editor.js +27 -19
- package/dist/modes/interactive/external-editor.js.map +1 -1
- package/dist/modes/interactive/history-reload-math.d.ts +6 -2
- package/dist/modes/interactive/history-reload-math.d.ts.map +1 -1
- package/dist/modes/interactive/history-reload-math.js +10 -5
- package/dist/modes/interactive/history-reload-math.js.map +1 -1
- package/dist/modes/interactive/interactive-event-controller.d.ts +74 -0
- package/dist/modes/interactive/interactive-event-controller.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-event-controller.js +328 -0
- package/dist/modes/interactive/interactive-event-controller.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +22 -24
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +245 -595
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/key-handlers.d.ts.map +1 -1
- package/dist/modes/interactive/key-handlers.js +1 -1
- package/dist/modes/interactive/key-handlers.js.map +1 -1
- package/dist/modes/interactive/loaded-resources-view.d.ts +20 -0
- package/dist/modes/interactive/loaded-resources-view.d.ts.map +1 -0
- package/dist/modes/interactive/loaded-resources-view.js +147 -0
- package/dist/modes/interactive/loaded-resources-view.js.map +1 -0
- package/dist/modes/interactive/profile-menu-controller.d.ts.map +1 -1
- package/dist/modes/interactive/profile-menu-controller.js +7 -7
- package/dist/modes/interactive/profile-menu-controller.js.map +1 -1
- package/dist/modes/interactive/report-commands.d.ts.map +1 -1
- package/dist/modes/interactive/report-commands.js +21 -0
- package/dist/modes/interactive/report-commands.js.map +1 -1
- package/dist/modes/interactive/resource-display.d.ts.map +1 -1
- package/dist/modes/interactive/resource-display.js +8 -2
- package/dist/modes/interactive/resource-display.js.map +1 -1
- package/dist/modes/interactive/resource-shell-commands.d.ts +1 -5
- package/dist/modes/interactive/resource-shell-commands.d.ts.map +1 -1
- package/dist/modes/interactive/resource-shell-commands.js +0 -5
- package/dist/modes/interactive/resource-shell-commands.js.map +1 -1
- package/dist/modes/interactive/session-flow-commands.d.ts +27 -8
- package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-flow-commands.js +150 -64
- package/dist/modes/interactive/session-flow-commands.js.map +1 -1
- package/dist/modes/interactive/session-io-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-io-commands.js +16 -6
- package/dist/modes/interactive/session-io-commands.js.map +1 -1
- package/dist/modes/interactive/session-replacement-errors.d.ts +7 -0
- package/dist/modes/interactive/session-replacement-errors.d.ts.map +1 -0
- package/dist/modes/interactive/session-replacement-errors.js +15 -0
- package/dist/modes/interactive/session-replacement-errors.js.map +1 -0
- package/dist/modes/interactive/startup-checks.d.ts.map +1 -1
- package/dist/modes/interactive/startup-checks.js +1 -1
- package/dist/modes/interactive/startup-checks.js.map +1 -1
- package/dist/modes/interactive/usage-commands.d.ts +34 -0
- package/dist/modes/interactive/usage-commands.d.ts.map +1 -0
- package/dist/modes/interactive/usage-commands.js +225 -0
- package/dist/modes/interactive/usage-commands.js.map +1 -0
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +82 -23
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +15 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js +138 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +2 -13
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/clipboard-native.d.ts +1 -0
- package/dist/utils/clipboard-native.d.ts.map +1 -1
- package/dist/utils/clipboard-native.js.map +1 -1
- package/dist/utils/clipboard.d.ts +1 -0
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +52 -1
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/platform.d.ts +3 -0
- package/dist/utils/platform.d.ts.map +1 -0
- package/dist/utils/platform.js +8 -0
- package/dist/utils/platform.js.map +1 -0
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +5 -3
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +3 -1
- package/dist/utils/version-check.js.map +1 -1
- package/dist/utils/work-directory.d.ts +11 -0
- package/dist/utils/work-directory.d.ts.map +1 -1
- package/dist/utils/work-directory.js +30 -9
- package/dist/utils/work-directory.js.map +1 -1
- package/docs/UI_POLISH_ORCHESTRATION.md +38 -0
- package/docs/UI_QUALITY_ORCHESTRATION.md +28 -0
- package/docs/docs.json +4 -0
- package/docs/extensions.md +62 -2
- package/docs/harness-architecture.md +156 -0
- package/docs/keybindings.md +11 -1
- package/docs/process-matrix.md +59 -26
- package/docs/providers.md +9 -1
- package/docs/rpc.md +45 -2
- package/docs/sessions.md +15 -0
- package/docs/settings.md +125 -11
- package/docs/task-steps.md +8 -0
- package/docs/telemetry.md +19 -0
- package/docs/tmux-agent-manager.md +10 -3
- package/docs/ui-reference/README.md +9 -0
- package/docs/ui-reference/orchestration-after.txt +14 -0
- package/docs/ui-reference/orchestration-before.txt +13 -0
- package/docs/ui-reference/orchestration-reference.txt +16 -0
- package/docs/usage.md +22 -2
- package/docs/work-directory.md +19 -8
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/question.ts +34 -245
- package/examples/extensions/questionnaire.ts +41 -407
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +13 -13
- package/package.json +4 -4
- package/dist/core/delegation/session-worker-result.d.ts +0 -46
- package/dist/core/delegation/session-worker-result.d.ts.map +0 -1
- package/dist/core/delegation/session-worker-result.js +0 -113
- package/dist/core/delegation/session-worker-result.js.map +0 -1
- package/dist/core/delegation/worker-result.d.ts.map +0 -1
- package/dist/core/delegation/worker-result.js.map +0 -1
- package/dist/core/telemetry.d.ts.map +0 -1
- package/dist/core/telemetry.js.map +0 -1
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { DelegationOrchestrationLedger, } from "../orchestration/delegation-ledger.js";
|
|
2
|
+
import { verifierWorkerExecutionContract } from "../orchestration/worker-execution-contract.js";
|
|
3
|
+
import { ACTIVE_WORKER_ATTEMPT_STATUSES, isManagedWorkerAttempt, projectManagedWorkerLaneRecords, projectWorkerLaneRecord, selectedManagedWorkerAttempt, selectedWorkerAttempt, } from "./worker-lane-projection.js";
|
|
4
|
+
/**
|
|
5
|
+
* Sole owner of in-process worker lifecycle state. LaneRecord is a compatibility/UI projection;
|
|
6
|
+
* all transitions are committed through DurableTaskRuntime before the projection is returned.
|
|
7
|
+
*/
|
|
8
|
+
export class WorkerLifecycle {
|
|
9
|
+
ledger;
|
|
10
|
+
nextLaneNumber;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.ledger = new DelegationOrchestrationLedger(options);
|
|
13
|
+
const snapshot = this.ledger.runtime.getSnapshot();
|
|
14
|
+
const highest = Object.keys(snapshot.tasks).reduce((current, taskId) => {
|
|
15
|
+
const suffix = /^worker-(\d+)$/.exec(taskId)?.[1];
|
|
16
|
+
return suffix ? Math.max(current, Number(suffix)) : current;
|
|
17
|
+
}, 0);
|
|
18
|
+
this.nextLaneNumber = highest + 1;
|
|
19
|
+
}
|
|
20
|
+
prepare(input, laneId) {
|
|
21
|
+
let selectedLaneId = laneId;
|
|
22
|
+
if (!selectedLaneId) {
|
|
23
|
+
const snapshot = this.ledger.runtime.getSnapshot();
|
|
24
|
+
while (snapshot.tasks[`worker-${this.nextLaneNumber}`])
|
|
25
|
+
this.nextLaneNumber += 1;
|
|
26
|
+
selectedLaneId = `worker-${this.nextLaneNumber++}`;
|
|
27
|
+
}
|
|
28
|
+
const attempt = this.ledger.prepare({ ...input, laneId: selectedLaneId });
|
|
29
|
+
const record = this.getRecord(selectedLaneId);
|
|
30
|
+
if (!record)
|
|
31
|
+
throw new Error(`Durable worker '${selectedLaneId}' was not projected after enqueue.`);
|
|
32
|
+
return { record, attempt };
|
|
33
|
+
}
|
|
34
|
+
prepareManaged(input) {
|
|
35
|
+
const before = selectedManagedWorkerAttempt(this.ledger.runtime.getSnapshot(), input.laneId);
|
|
36
|
+
if (before?.dispatch.dispatchSequence === input.dispatchSequence) {
|
|
37
|
+
if (before.dispatch.provider !== "legacy" &&
|
|
38
|
+
(before.dispatch.instructions !== input.instructions ||
|
|
39
|
+
before.dispatch.profileId !== input.profileId ||
|
|
40
|
+
before.dispatch.provider !== input.provider ||
|
|
41
|
+
before.dispatch.worktreeLaneKey !== input.worktreeLaneKey ||
|
|
42
|
+
before.dispatch.authorizationId !== input.authorizationId)) {
|
|
43
|
+
throw new Error(`Managed worker '${input.laneId}' turn ${input.dispatchSequence} was re-reported with conflicting dispatch data.`);
|
|
44
|
+
}
|
|
45
|
+
if (before.status === "queued") {
|
|
46
|
+
const handle = this.startPreparedManagedAttempt(before, input.leaseTtlMs, input.compileGrant);
|
|
47
|
+
const record = this.getManagedRecord(input.laneId);
|
|
48
|
+
if (!record)
|
|
49
|
+
throw new Error(`Managed worker '${input.laneId}' was not projected.`);
|
|
50
|
+
return {
|
|
51
|
+
record,
|
|
52
|
+
attempt: this.ledger.runtime.getSnapshot().attempts[before.attemptId],
|
|
53
|
+
handle,
|
|
54
|
+
created: true,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const record = this.getManagedRecord(input.laneId);
|
|
58
|
+
if (!record)
|
|
59
|
+
throw new Error(`Managed worker '${input.laneId}' was not projected.`);
|
|
60
|
+
if (!before.lease)
|
|
61
|
+
throw new Error(`Managed worker '${input.laneId}' has no durable lease.`);
|
|
62
|
+
return {
|
|
63
|
+
record,
|
|
64
|
+
attempt: before,
|
|
65
|
+
handle: this.startedHandle(before),
|
|
66
|
+
created: false,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (before && ACTIVE_WORKER_ATTEMPT_STATUSES.has(before.status)) {
|
|
70
|
+
throw new Error(`Managed worker '${input.laneId}' cannot dispatch turn ${input.dispatchSequence} while turn ${before.dispatch.dispatchSequence ?? 1} is active.`);
|
|
71
|
+
}
|
|
72
|
+
const attempt = this.ledger.prepareManaged(input);
|
|
73
|
+
const handle = this.startPreparedManagedAttempt(attempt, input.leaseTtlMs, input.compileGrant);
|
|
74
|
+
const record = this.getManagedRecord(input.laneId);
|
|
75
|
+
if (!record)
|
|
76
|
+
throw new Error(`Managed worker '${input.laneId}' was not projected after dispatch.`);
|
|
77
|
+
return { record, attempt: this.ledger.runtime.getSnapshot().attempts[attempt.attemptId], handle, created: true };
|
|
78
|
+
}
|
|
79
|
+
synchronizeGoalState(goal) {
|
|
80
|
+
const before = new Map(this.getRecords().map((record) => [record.laneId, record.status]));
|
|
81
|
+
this.ledger.synchronizeGoalState(goal);
|
|
82
|
+
return this.getRecords().filter((record) => {
|
|
83
|
+
const previous = before.get(record.laneId);
|
|
84
|
+
return ((previous === "queued" || previous === "running") &&
|
|
85
|
+
record.status !== "queued" &&
|
|
86
|
+
record.status !== "running");
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
start(laneId, leaseTtlMs) {
|
|
90
|
+
const attempt = this.requireActiveAttempt(laneId);
|
|
91
|
+
return this.ledger.start(attempt.attemptId, leaseTtlMs);
|
|
92
|
+
}
|
|
93
|
+
bindGrant(attemptId, grant) {
|
|
94
|
+
this.ledger.runtime.bindAttemptGrant(attemptId, grant);
|
|
95
|
+
}
|
|
96
|
+
finish(result, options = {}) {
|
|
97
|
+
this.ledger.runtime.finishAttempt(result);
|
|
98
|
+
const record = this.getRecord(result.taskId);
|
|
99
|
+
if (!record)
|
|
100
|
+
throw new Error(`Durable worker '${result.taskId}' was not projected after completion.`);
|
|
101
|
+
if (options.notify !== false)
|
|
102
|
+
this.enqueueTerminalNotification(record);
|
|
103
|
+
return record;
|
|
104
|
+
}
|
|
105
|
+
reconcileVerification(args) {
|
|
106
|
+
this.ledger.runtime.finishVerification({
|
|
107
|
+
taskId: args.subjectTaskId,
|
|
108
|
+
verifierTaskId: args.verifierTaskId,
|
|
109
|
+
verifierAttemptId: args.verifierAttemptId,
|
|
110
|
+
verdict: args.verdict,
|
|
111
|
+
reasonCode: args.reasonCode,
|
|
112
|
+
});
|
|
113
|
+
const subject = this.getRecord(args.subjectTaskId);
|
|
114
|
+
if (!subject)
|
|
115
|
+
throw new Error(`Verified worker '${args.subjectTaskId}' was not projected.`);
|
|
116
|
+
this.enqueueTerminalNotification(subject);
|
|
117
|
+
return subject;
|
|
118
|
+
}
|
|
119
|
+
cancel(laneId, reasonCode) {
|
|
120
|
+
const attempt = this.getActiveAttempt(laneId);
|
|
121
|
+
if (!attempt)
|
|
122
|
+
return this.getRecord(laneId);
|
|
123
|
+
this.ledger.cancel(attempt.attemptId, reasonCode);
|
|
124
|
+
const record = this.getRecord(laneId);
|
|
125
|
+
if (record)
|
|
126
|
+
this.enqueueTerminalNotification(record);
|
|
127
|
+
return record;
|
|
128
|
+
}
|
|
129
|
+
recoverQueued() {
|
|
130
|
+
return this.ledger.recoverQueuedDispatches().flatMap((attempt) => {
|
|
131
|
+
if (isManagedWorkerAttempt(attempt))
|
|
132
|
+
return [];
|
|
133
|
+
const record = this.getRecord(attempt.taskId);
|
|
134
|
+
const task = this.ledger.runtime.getSnapshot().tasks[attempt.taskId]?.task;
|
|
135
|
+
return record
|
|
136
|
+
? [
|
|
137
|
+
{
|
|
138
|
+
record,
|
|
139
|
+
attempt,
|
|
140
|
+
...(task?.verificationOfTaskId ? { verificationOfTaskId: task.verificationOfTaskId } : {}),
|
|
141
|
+
},
|
|
142
|
+
]
|
|
143
|
+
: [];
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/** Close crash windows between implementation completion, verifier dispatch, and reconciliation. */
|
|
147
|
+
getPendingVerificationRecoveries() {
|
|
148
|
+
const snapshot = this.ledger.runtime.getSnapshot();
|
|
149
|
+
return Object.values(snapshot.tasks).flatMap((subject) => {
|
|
150
|
+
if (subject.verification)
|
|
151
|
+
return [];
|
|
152
|
+
const implementationAttempt = selectedWorkerAttempt(snapshot, subject.task.taskId);
|
|
153
|
+
if (implementationAttempt?.result?.nextAction !== "independent_verification_required")
|
|
154
|
+
return [];
|
|
155
|
+
const verifier = Object.values(snapshot.tasks)
|
|
156
|
+
.filter((candidate) => candidate.task.verificationOfTaskId === subject.task.taskId)
|
|
157
|
+
.sort((left, right) => left.task.createdAt.localeCompare(right.task.createdAt))
|
|
158
|
+
.at(-1);
|
|
159
|
+
if (!verifier) {
|
|
160
|
+
const verifierExecutionContract = implementationAttempt.dispatch.executionContract
|
|
161
|
+
? verifierWorkerExecutionContract(implementationAttempt.dispatch.executionContract)
|
|
162
|
+
: undefined;
|
|
163
|
+
return [
|
|
164
|
+
{
|
|
165
|
+
action: "dispatch",
|
|
166
|
+
subjectTaskId: subject.task.taskId,
|
|
167
|
+
implementationProfileId: implementationAttempt.dispatch.profileId,
|
|
168
|
+
summary: implementationAttempt.result.summary,
|
|
169
|
+
artifactUris: implementationAttempt.result.artifacts.map((artifact) => artifact.uri),
|
|
170
|
+
...(verifierExecutionContract ? { verifierExecutionContract } : {}),
|
|
171
|
+
},
|
|
172
|
+
];
|
|
173
|
+
}
|
|
174
|
+
const verifierAttempt = selectedWorkerAttempt(snapshot, verifier.task.taskId);
|
|
175
|
+
if (!verifierAttempt || ACTIVE_WORKER_ATTEMPT_STATUSES.has(verifierAttempt.status))
|
|
176
|
+
return [];
|
|
177
|
+
const review = verifierAttempt.result?.evidence.find((evidence) => evidence.kind === "review" && evidence.metadata?.subjectTaskId === subject.task.taskId);
|
|
178
|
+
const verdictValue = review?.metadata?.verdict;
|
|
179
|
+
const verdict = review?.trusted && (verdictValue === "accepted" || verdictValue === "rejected")
|
|
180
|
+
? verdictValue
|
|
181
|
+
: "inconclusive";
|
|
182
|
+
const reasonCodesValue = review?.metadata?.reasonCodes;
|
|
183
|
+
const reasonCodes = Array.isArray(reasonCodesValue)
|
|
184
|
+
? reasonCodesValue.filter((reasonCode) => typeof reasonCode === "string")
|
|
185
|
+
: [];
|
|
186
|
+
return [
|
|
187
|
+
{
|
|
188
|
+
action: "reconcile",
|
|
189
|
+
subjectTaskId: subject.task.taskId,
|
|
190
|
+
verifierTaskId: verifier.task.taskId,
|
|
191
|
+
verifierAttemptId: verifierAttempt.attemptId,
|
|
192
|
+
verdict,
|
|
193
|
+
reasonCode: verdict === "accepted"
|
|
194
|
+
? "independent_verification_accepted"
|
|
195
|
+
: verdict === "rejected"
|
|
196
|
+
? `independent_verification_rejected:${reasonCodes.join(",") || "unspecified"}`
|
|
197
|
+
: `independent_verification_inconclusive:${verifierAttempt.reasonCode ?? verifierAttempt.result?.reasonCode ?? "interrupted"}`,
|
|
198
|
+
},
|
|
199
|
+
];
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
getTask(taskId) {
|
|
203
|
+
return this.ledger.runtime.getSnapshot().tasks[taskId];
|
|
204
|
+
}
|
|
205
|
+
getTaskRuntimeSnapshot() {
|
|
206
|
+
return this.ledger.runtime.getSnapshot();
|
|
207
|
+
}
|
|
208
|
+
getRecords() {
|
|
209
|
+
const snapshot = this.ledger.runtime.getSnapshot();
|
|
210
|
+
return Object.keys(snapshot.tasks).flatMap((taskId) => {
|
|
211
|
+
const attempt = selectedWorkerAttempt(snapshot, taskId);
|
|
212
|
+
if (!attempt || isManagedWorkerAttempt(attempt))
|
|
213
|
+
return [];
|
|
214
|
+
const record = projectWorkerLaneRecord(snapshot, taskId);
|
|
215
|
+
return record ? [record] : [];
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
getManagedRecords() {
|
|
219
|
+
return projectManagedWorkerLaneRecords(this.ledger.runtime.getSnapshot());
|
|
220
|
+
}
|
|
221
|
+
getAllRecords() {
|
|
222
|
+
return [...this.getRecords(), ...this.getManagedRecords()];
|
|
223
|
+
}
|
|
224
|
+
getRecord(laneId) {
|
|
225
|
+
return projectWorkerLaneRecord(this.ledger.runtime.getSnapshot(), laneId);
|
|
226
|
+
}
|
|
227
|
+
getManagedRecord(laneId) {
|
|
228
|
+
return this.getManagedRecords().find((record) => record.laneId === laneId);
|
|
229
|
+
}
|
|
230
|
+
getManagedAttempt(laneId) {
|
|
231
|
+
return selectedManagedWorkerAttempt(this.ledger.runtime.getSnapshot(), laneId);
|
|
232
|
+
}
|
|
233
|
+
getManagedHandle(laneId) {
|
|
234
|
+
const attempt = this.getManagedAttempt(laneId);
|
|
235
|
+
return attempt?.lease ? this.startedHandle(attempt) : undefined;
|
|
236
|
+
}
|
|
237
|
+
getActiveAttempt(laneId) {
|
|
238
|
+
return selectedWorkerAttempt(this.ledger.runtime.getSnapshot(), laneId);
|
|
239
|
+
}
|
|
240
|
+
getRunningCount(profileId) {
|
|
241
|
+
const snapshot = this.ledger.runtime.getSnapshot();
|
|
242
|
+
return Object.keys(snapshot.tasks).filter((taskId) => {
|
|
243
|
+
const attempt = selectedWorkerAttempt(snapshot, taskId);
|
|
244
|
+
return (attempt?.status === "running" &&
|
|
245
|
+
!isManagedWorkerAttempt(attempt) &&
|
|
246
|
+
(!profileId || attempt.dispatch.profileId === profileId));
|
|
247
|
+
}).length;
|
|
248
|
+
}
|
|
249
|
+
getPendingTerminalNotifications() {
|
|
250
|
+
this.ensureTerminalNotifications();
|
|
251
|
+
const snapshot = this.ledger.runtime.getSnapshot();
|
|
252
|
+
return Object.values(snapshot.notifications).flatMap((notification) => {
|
|
253
|
+
if (notification.status !== "pending" || !notification.attemptId)
|
|
254
|
+
return [];
|
|
255
|
+
const attempt = snapshot.attempts[notification.attemptId];
|
|
256
|
+
if (!attempt)
|
|
257
|
+
return [];
|
|
258
|
+
const record = projectWorkerLaneRecord(snapshot, attempt.taskId);
|
|
259
|
+
if (!record || record.status === "queued" || record.status === "running")
|
|
260
|
+
return [];
|
|
261
|
+
return [{ notificationId: notification.notificationId, record }];
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
getTerminalNotification(laneId) {
|
|
265
|
+
const record = this.getRecord(laneId) ?? this.getManagedRecord(laneId);
|
|
266
|
+
if (!record || record.status === "queued" || record.status === "running")
|
|
267
|
+
return undefined;
|
|
268
|
+
this.enqueueTerminalNotification(record);
|
|
269
|
+
const attempt = this.getActiveAttempt(laneId) ?? this.getManagedAttempt(laneId);
|
|
270
|
+
if (!attempt)
|
|
271
|
+
return undefined;
|
|
272
|
+
const notificationId = `worker-terminal:${attempt.attemptId}`;
|
|
273
|
+
const notification = this.ledger.runtime.getSnapshot().notifications[notificationId];
|
|
274
|
+
return notification ? { notificationId, status: notification.status, record } : undefined;
|
|
275
|
+
}
|
|
276
|
+
markNotificationsDelivered(notificationIds) {
|
|
277
|
+
for (const notificationId of notificationIds)
|
|
278
|
+
this.ledger.runtime.markNotificationDelivered(notificationId);
|
|
279
|
+
}
|
|
280
|
+
ensureTerminalNotifications() {
|
|
281
|
+
const snapshot = this.ledger.runtime.getSnapshot();
|
|
282
|
+
for (const taskId of Object.keys(snapshot.tasks)) {
|
|
283
|
+
const record = projectWorkerLaneRecord(snapshot, taskId);
|
|
284
|
+
if (record && record.status !== "queued" && record.status !== "running") {
|
|
285
|
+
this.enqueueTerminalNotification(record);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
enqueueTerminalNotification(record) {
|
|
290
|
+
const attempt = this.getActiveAttempt(record.laneId) ?? this.getManagedAttempt(record.laneId);
|
|
291
|
+
if (!attempt || ACTIVE_WORKER_ATTEMPT_STATUSES.has(attempt.status))
|
|
292
|
+
return;
|
|
293
|
+
const snapshot = this.ledger.runtime.getSnapshot();
|
|
294
|
+
const task = snapshot.tasks[attempt.taskId];
|
|
295
|
+
if (!task)
|
|
296
|
+
return;
|
|
297
|
+
if (attempt.result?.nextAction === "independent_verification_required" && !task.verification)
|
|
298
|
+
return;
|
|
299
|
+
this.ledger.runtime.enqueueNotification({
|
|
300
|
+
notificationId: `worker-terminal:${attempt.attemptId}`,
|
|
301
|
+
objectiveId: task.task.objectiveId,
|
|
302
|
+
attemptId: attempt.attemptId,
|
|
303
|
+
message: `Worker ${record.laneId} reached ${record.status}.`,
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
requireActiveAttempt(laneId) {
|
|
307
|
+
const attempt = this.getActiveAttempt(laneId);
|
|
308
|
+
if (!attempt || !ACTIVE_WORKER_ATTEMPT_STATUSES.has(attempt.status)) {
|
|
309
|
+
throw new Error(`Durable worker '${laneId}' has no active attempt.`);
|
|
310
|
+
}
|
|
311
|
+
return attempt;
|
|
312
|
+
}
|
|
313
|
+
startedHandle(attempt) {
|
|
314
|
+
const task = this.ledger.runtime.getSnapshot().tasks[attempt.taskId];
|
|
315
|
+
if (!task || !attempt.lease)
|
|
316
|
+
throw new Error(`Attempt '${attempt.attemptId}' has no started handle.`);
|
|
317
|
+
return {
|
|
318
|
+
objectiveId: task.task.objectiveId,
|
|
319
|
+
taskId: task.task.taskId,
|
|
320
|
+
attemptId: attempt.attemptId,
|
|
321
|
+
leaseId: attempt.lease.leaseId,
|
|
322
|
+
fencingToken: attempt.lease.fencingToken,
|
|
323
|
+
expiresAt: attempt.lease.expiresAt,
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
startPreparedManagedAttempt(attempt, leaseTtlMs, compileGrant) {
|
|
327
|
+
const task = this.ledger.runtime.getSnapshot().tasks[attempt.taskId];
|
|
328
|
+
if (!task)
|
|
329
|
+
throw new Error(`Managed attempt '${attempt.attemptId}' has no durable task.`);
|
|
330
|
+
const grant = compileGrant({
|
|
331
|
+
objectiveId: task.task.objectiveId,
|
|
332
|
+
taskId: task.task.taskId,
|
|
333
|
+
attemptId: attempt.attemptId,
|
|
334
|
+
});
|
|
335
|
+
this.bindGrant(attempt.attemptId, grant);
|
|
336
|
+
return this.ledger.start(attempt.attemptId, leaseTtlMs, `managed:${attempt.dispatch.logicalLaneId ?? attempt.taskId}`);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
//# sourceMappingURL=worker-lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-lifecycle.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-lifecycle.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,6BAA6B,GAI7B,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,+BAA+B,EAAE,MAAM,+CAA+C,CAAC;AAChG,OAAO,EACN,8BAA8B,EAC9B,sBAAsB,EACtB,+BAA+B,EAC/B,uBAAuB,EACvB,4BAA4B,EAC5B,qBAAqB,GACrB,MAAM,6BAA6B,CAAC;AAoBrC;;;GAGG;AACH,MAAM,OAAO,eAAe;IAClB,MAAM,CAAgC;IACvC,cAAc,CAAS;IAE/B,YAAY,OAAgD,EAAE;QAC7D,IAAI,CAAC,MAAM,GAAG,IAAI,6BAA6B,CAAC,OAAO,CAAC,CAAC;QACzD,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;QACnD,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,C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K,CAAC,YAAY;YACxC,SAAS,EAAE,OAAO,CAAC,KAAK,CAAC,SAAS;SAClC,CAAC;IAAA,CACF;IAEO,2BAA2B,CAClC,OAA4B,EAC5B,UAAkB,EAClB,YAAoG,EACzE;QAC3B,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACrE,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,OAAO,CAAC,SAAS,wBAAwB,CAAC,CAAC;QAC1F,MAAM,KAAK,GAAG,YAAY,CAAC;YAC1B,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW;YAClC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM;YACxB,SAAS,EAAE,OAAO,CAAC,SAAS;SAC5B,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QACzC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CACvB,OAAO,CAAC,SAAS,EACjB,UAAU,EACV,WAAW,OAAO,CAAC,QAAQ,CAAC,aAAa,IAAI,OAAO,CAAC,MAAM,EAAE,CAC7D,CAAC;IAAA,CACF;CACD","sourcesContent":["import type { LaneRecord } from \"../autonomy/lane-tracker.ts\";\nimport type { GoalState } from \"../goals/goal-state.ts\";\nimport type { ExecutionGrant, WorkerExecutionContract, WorkerResultContract } from \"../orchestration/contracts.ts\";\nimport {\n\tDelegationOrchestrationLedger,\n\ttype PrepareDelegationInput,\n\ttype PrepareManagedDelegationInput,\n\ttype StartedDelegationAttempt,\n} from \"../orchestration/delegation-ledger.ts\";\nimport type { AttemptRuntimeState, TaskRuntimeProjection } from \"../orchestration/task-runtime.ts\";\nimport { verifierWorkerExecutionContract } from \"../orchestration/worker-execution-contract.ts\";\nimport {\n\tACTIVE_WORKER_ATTEMPT_STATUSES,\n\tisManagedWorkerAttempt,\n\tprojectManagedWorkerLaneRecords,\n\tprojectWorkerLaneRecord,\n\tselectedManagedWorkerAttempt,\n\tselectedWorkerAttempt,\n} from \"./worker-lane-projection.ts\";\n\nexport type PendingVerificationRecovery =\n\t| {\n\t\t\taction: \"dispatch\";\n\t\t\tsubjectTaskId: string;\n\t\t\timplementationProfileId: string;\n\t\t\tsummary: string;\n\t\t\tartifactUris: readonly string[];\n\t\t\tverifierExecutionContract?: WorkerExecutionContract;\n\t }\n\t| {\n\t\t\taction: \"reconcile\";\n\t\t\tsubjectTaskId: string;\n\t\t\tverifierTaskId: string;\n\t\t\tverifierAttemptId: string;\n\t\t\tverdict: \"accepted\" | \"rejected\" | \"inconclusive\";\n\t\t\treasonCode: string;\n\t };\n\n/**\n * Sole owner of in-process worker lifecycle state. LaneRecord is a compatibility/UI projection;\n * all transitions are committed through DurableTaskRuntime before the projection is returned.\n */\nexport class WorkerLifecycle {\n\treadonly ledger: DelegationOrchestrationLedger;\n\tprivate nextLaneNumber: number;\n\n\tconstructor(options: { agentDir: string; sessionId: string }) {\n\t\tthis.ledger = new DelegationOrchestrationLedger(options);\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\tconst highest = Object.keys(snapshot.tasks).reduce((current, taskId) => {\n\t\t\tconst suffix = /^worker-(\\d+)$/.exec(taskId)?.[1];\n\t\t\treturn suffix ? Math.max(current, Number(suffix)) : current;\n\t\t}, 0);\n\t\tthis.nextLaneNumber = highest + 1;\n\t}\n\n\tprepare(\n\t\tinput: Omit<PrepareDelegationInput, \"laneId\">,\n\t\tlaneId?: string,\n\t): {\n\t\trecord: LaneRecord;\n\t\tattempt: AttemptRuntimeState;\n\t} {\n\t\tlet selectedLaneId = laneId;\n\t\tif (!selectedLaneId) {\n\t\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\t\twhile (snapshot.tasks[`worker-${this.nextLaneNumber}`]) this.nextLaneNumber += 1;\n\t\t\tselectedLaneId = `worker-${this.nextLaneNumber++}`;\n\t\t}\n\t\tconst attempt = this.ledger.prepare({ ...input, laneId: selectedLaneId });\n\t\tconst record = this.getRecord(selectedLaneId);\n\t\tif (!record) throw new Error(`Durable worker '${selectedLaneId}' was not projected after enqueue.`);\n\t\treturn { record, attempt };\n\t}\n\n\tprepareManaged(\n\t\tinput: PrepareManagedDelegationInput & {\n\t\t\tleaseTtlMs: number;\n\t\t\tcompileGrant(target: { objectiveId: string; taskId: string; attemptId: string }): ExecutionGrant;\n\t\t},\n\t): {\n\t\trecord: LaneRecord;\n\t\tattempt: AttemptRuntimeState;\n\t\thandle: StartedDelegationAttempt;\n\t\tcreated: boolean;\n\t} {\n\t\tconst before = selectedManagedWorkerAttempt(this.ledger.runtime.getSnapshot(), input.laneId);\n\t\tif (before?.dispatch.dispatchSequence === input.dispatchSequence) {\n\t\t\tif (\n\t\t\t\tbefore.dispatch.provider !== \"legacy\" &&\n\t\t\t\t(before.dispatch.instructions !== input.instructions ||\n\t\t\t\t\tbefore.dispatch.profileId !== input.profileId ||\n\t\t\t\t\tbefore.dispatch.provider !== input.provider ||\n\t\t\t\t\tbefore.dispatch.worktreeLaneKey !== input.worktreeLaneKey ||\n\t\t\t\t\tbefore.dispatch.authorizationId !== input.authorizationId)\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Managed worker '${input.laneId}' turn ${input.dispatchSequence} was re-reported with conflicting dispatch data.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (before.status === \"queued\") {\n\t\t\t\tconst handle = this.startPreparedManagedAttempt(before, input.leaseTtlMs, input.compileGrant);\n\t\t\t\tconst record = this.getManagedRecord(input.laneId);\n\t\t\t\tif (!record) throw new Error(`Managed worker '${input.laneId}' was not projected.`);\n\t\t\t\treturn {\n\t\t\t\t\trecord,\n\t\t\t\t\tattempt: this.ledger.runtime.getSnapshot().attempts[before.attemptId]!,\n\t\t\t\t\thandle,\n\t\t\t\t\tcreated: true,\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst record = this.getManagedRecord(input.laneId);\n\t\t\tif (!record) throw new Error(`Managed worker '${input.laneId}' was not projected.`);\n\t\t\tif (!before.lease) throw new Error(`Managed worker '${input.laneId}' has no durable lease.`);\n\t\t\treturn {\n\t\t\t\trecord,\n\t\t\t\tattempt: before,\n\t\t\t\thandle: this.startedHandle(before),\n\t\t\t\tcreated: false,\n\t\t\t};\n\t\t}\n\t\tif (before && ACTIVE_WORKER_ATTEMPT_STATUSES.has(before.status)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Managed worker '${input.laneId}' cannot dispatch turn ${input.dispatchSequence} while turn ${before.dispatch.dispatchSequence ?? 1} is active.`,\n\t\t\t);\n\t\t}\n\t\tconst attempt = this.ledger.prepareManaged(input);\n\t\tconst handle = this.startPreparedManagedAttempt(attempt, input.leaseTtlMs, input.compileGrant);\n\t\tconst record = this.getManagedRecord(input.laneId);\n\t\tif (!record) throw new Error(`Managed worker '${input.laneId}' was not projected after dispatch.`);\n\t\treturn { record, attempt: this.ledger.runtime.getSnapshot().attempts[attempt.attemptId]!, handle, created: true };\n\t}\n\n\tsynchronizeGoalState(goal: GoalState): LaneRecord[] {\n\t\tconst before = new Map(this.getRecords().map((record) => [record.laneId, record.status]));\n\t\tthis.ledger.synchronizeGoalState(goal);\n\t\treturn this.getRecords().filter((record) => {\n\t\t\tconst previous = before.get(record.laneId);\n\t\t\treturn (\n\t\t\t\t(previous === \"queued\" || previous === \"running\") &&\n\t\t\t\trecord.status !== \"queued\" &&\n\t\t\t\trecord.status !== \"running\"\n\t\t\t);\n\t\t});\n\t}\n\n\tstart(laneId: string, leaseTtlMs: number): StartedDelegationAttempt {\n\t\tconst attempt = this.requireActiveAttempt(laneId);\n\t\treturn this.ledger.start(attempt.attemptId, leaseTtlMs);\n\t}\n\n\tbindGrant(attemptId: string, grant: ExecutionGrant): void {\n\t\tthis.ledger.runtime.bindAttemptGrant(attemptId, grant);\n\t}\n\n\tfinish(result: WorkerResultContract, options: { notify?: boolean } = {}): LaneRecord {\n\t\tthis.ledger.runtime.finishAttempt(result);\n\t\tconst record = this.getRecord(result.taskId);\n\t\tif (!record) throw new Error(`Durable worker '${result.taskId}' was not projected after completion.`);\n\t\tif (options.notify !== false) this.enqueueTerminalNotification(record);\n\t\treturn record;\n\t}\n\n\treconcileVerification(args: {\n\t\tsubjectTaskId: string;\n\t\tverifierTaskId: string;\n\t\tverifierAttemptId: string;\n\t\tverdict: \"accepted\" | \"rejected\" | \"inconclusive\";\n\t\treasonCode: string;\n\t}): LaneRecord {\n\t\tthis.ledger.runtime.finishVerification({\n\t\t\ttaskId: args.subjectTaskId,\n\t\t\tverifierTaskId: args.verifierTaskId,\n\t\t\tverifierAttemptId: args.verifierAttemptId,\n\t\t\tverdict: args.verdict,\n\t\t\treasonCode: args.reasonCode,\n\t\t});\n\t\tconst subject = this.getRecord(args.subjectTaskId);\n\t\tif (!subject) throw new Error(`Verified worker '${args.subjectTaskId}' was not projected.`);\n\t\tthis.enqueueTerminalNotification(subject);\n\t\treturn subject;\n\t}\n\n\tcancel(laneId: string, reasonCode: string): LaneRecord | undefined {\n\t\tconst attempt = this.getActiveAttempt(laneId);\n\t\tif (!attempt) return this.getRecord(laneId);\n\t\tthis.ledger.cancel(attempt.attemptId, reasonCode);\n\t\tconst record = this.getRecord(laneId);\n\t\tif (record) this.enqueueTerminalNotification(record);\n\t\treturn record;\n\t}\n\n\trecoverQueued(): Array<{\n\t\trecord: LaneRecord;\n\t\tattempt: AttemptRuntimeState;\n\t\tverificationOfTaskId?: string;\n\t}> {\n\t\treturn this.ledger.recoverQueuedDispatches().flatMap((attempt) => {\n\t\t\tif (isManagedWorkerAttempt(attempt)) return [];\n\t\t\tconst record = this.getRecord(attempt.taskId);\n\t\t\tconst task = this.ledger.runtime.getSnapshot().tasks[attempt.taskId]?.task;\n\t\t\treturn record\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\trecord,\n\t\t\t\t\t\t\tattempt,\n\t\t\t\t\t\t\t...(task?.verificationOfTaskId ? { verificationOfTaskId: task.verificationOfTaskId } : {}),\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: [];\n\t\t});\n\t}\n\n\t/** Close crash windows between implementation completion, verifier dispatch, and reconciliation. */\n\tgetPendingVerificationRecoveries(): PendingVerificationRecovery[] {\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\treturn Object.values(snapshot.tasks).flatMap<PendingVerificationRecovery>((subject) => {\n\t\t\tif (subject.verification) return [];\n\t\t\tconst implementationAttempt = selectedWorkerAttempt(snapshot, subject.task.taskId);\n\t\t\tif (implementationAttempt?.result?.nextAction !== \"independent_verification_required\") return [];\n\t\t\tconst verifier = Object.values(snapshot.tasks)\n\t\t\t\t.filter((candidate) => candidate.task.verificationOfTaskId === subject.task.taskId)\n\t\t\t\t.sort((left, right) => left.task.createdAt.localeCompare(right.task.createdAt))\n\t\t\t\t.at(-1);\n\t\t\tif (!verifier) {\n\t\t\t\tconst verifierExecutionContract = implementationAttempt.dispatch.executionContract\n\t\t\t\t\t? verifierWorkerExecutionContract(implementationAttempt.dispatch.executionContract)\n\t\t\t\t\t: undefined;\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\taction: \"dispatch\" as const,\n\t\t\t\t\t\tsubjectTaskId: subject.task.taskId,\n\t\t\t\t\t\timplementationProfileId: implementationAttempt.dispatch.profileId,\n\t\t\t\t\t\tsummary: implementationAttempt.result.summary,\n\t\t\t\t\t\tartifactUris: implementationAttempt.result.artifacts.map((artifact) => artifact.uri),\n\t\t\t\t\t\t...(verifierExecutionContract ? { verifierExecutionContract } : {}),\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\t\t\tconst verifierAttempt = selectedWorkerAttempt(snapshot, verifier.task.taskId);\n\t\t\tif (!verifierAttempt || ACTIVE_WORKER_ATTEMPT_STATUSES.has(verifierAttempt.status)) return [];\n\t\t\tconst review = verifierAttempt.result?.evidence.find(\n\t\t\t\t(evidence) => evidence.kind === \"review\" && evidence.metadata?.subjectTaskId === subject.task.taskId,\n\t\t\t);\n\t\t\tconst verdictValue = review?.metadata?.verdict;\n\t\t\tconst verdict =\n\t\t\t\treview?.trusted && (verdictValue === \"accepted\" || verdictValue === \"rejected\")\n\t\t\t\t\t? verdictValue\n\t\t\t\t\t: \"inconclusive\";\n\t\t\tconst reasonCodesValue = review?.metadata?.reasonCodes;\n\t\t\tconst reasonCodes = Array.isArray(reasonCodesValue)\n\t\t\t\t? reasonCodesValue.filter((reasonCode): reasonCode is string => typeof reasonCode === \"string\")\n\t\t\t\t: [];\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\taction: \"reconcile\" as const,\n\t\t\t\t\tsubjectTaskId: subject.task.taskId,\n\t\t\t\t\tverifierTaskId: verifier.task.taskId,\n\t\t\t\t\tverifierAttemptId: verifierAttempt.attemptId,\n\t\t\t\t\tverdict,\n\t\t\t\t\treasonCode:\n\t\t\t\t\t\tverdict === \"accepted\"\n\t\t\t\t\t\t\t? \"independent_verification_accepted\"\n\t\t\t\t\t\t\t: verdict === \"rejected\"\n\t\t\t\t\t\t\t\t? `independent_verification_rejected:${reasonCodes.join(\",\") || \"unspecified\"}`\n\t\t\t\t\t\t\t\t: `independent_verification_inconclusive:${verifierAttempt.reasonCode ?? verifierAttempt.result?.reasonCode ?? \"interrupted\"}`,\n\t\t\t\t},\n\t\t\t];\n\t\t});\n\t}\n\n\tgetTask(taskId: string): TaskRuntimeProjection[\"tasks\"][string] | undefined {\n\t\treturn this.ledger.runtime.getSnapshot().tasks[taskId];\n\t}\n\n\tgetTaskRuntimeSnapshot(): TaskRuntimeProjection {\n\t\treturn this.ledger.runtime.getSnapshot();\n\t}\n\n\tgetRecords(): LaneRecord[] {\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\treturn Object.keys(snapshot.tasks).flatMap((taskId) => {\n\t\t\tconst attempt = selectedWorkerAttempt(snapshot, taskId);\n\t\t\tif (!attempt || isManagedWorkerAttempt(attempt)) return [];\n\t\t\tconst record = projectWorkerLaneRecord(snapshot, taskId);\n\t\t\treturn record ? [record] : [];\n\t\t});\n\t}\n\n\tgetManagedRecords(): LaneRecord[] {\n\t\treturn projectManagedWorkerLaneRecords(this.ledger.runtime.getSnapshot());\n\t}\n\n\tgetAllRecords(): LaneRecord[] {\n\t\treturn [...this.getRecords(), ...this.getManagedRecords()];\n\t}\n\n\tgetRecord(laneId: string): LaneRecord | undefined {\n\t\treturn projectWorkerLaneRecord(this.ledger.runtime.getSnapshot(), laneId);\n\t}\n\n\tgetManagedRecord(laneId: string): LaneRecord | undefined {\n\t\treturn this.getManagedRecords().find((record) => record.laneId === laneId);\n\t}\n\n\tgetManagedAttempt(laneId: string): AttemptRuntimeState | undefined {\n\t\treturn selectedManagedWorkerAttempt(this.ledger.runtime.getSnapshot(), laneId);\n\t}\n\n\tgetManagedHandle(laneId: string): StartedDelegationAttempt | undefined {\n\t\tconst attempt = this.getManagedAttempt(laneId);\n\t\treturn attempt?.lease ? this.startedHandle(attempt) : undefined;\n\t}\n\n\tgetActiveAttempt(laneId: string): AttemptRuntimeState | undefined {\n\t\treturn selectedWorkerAttempt(this.ledger.runtime.getSnapshot(), laneId);\n\t}\n\n\tgetRunningCount(profileId?: string): number {\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\treturn Object.keys(snapshot.tasks).filter((taskId) => {\n\t\t\tconst attempt = selectedWorkerAttempt(snapshot, taskId);\n\t\t\treturn (\n\t\t\t\tattempt?.status === \"running\" &&\n\t\t\t\t!isManagedWorkerAttempt(attempt) &&\n\t\t\t\t(!profileId || attempt.dispatch.profileId === profileId)\n\t\t\t);\n\t\t}).length;\n\t}\n\n\tgetPendingTerminalNotifications(): Array<{ notificationId: string; record: LaneRecord }> {\n\t\tthis.ensureTerminalNotifications();\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\treturn Object.values(snapshot.notifications).flatMap((notification) => {\n\t\t\tif (notification.status !== \"pending\" || !notification.attemptId) return [];\n\t\t\tconst attempt = snapshot.attempts[notification.attemptId];\n\t\t\tif (!attempt) return [];\n\t\t\tconst record = projectWorkerLaneRecord(snapshot, attempt.taskId);\n\t\t\tif (!record || record.status === \"queued\" || record.status === \"running\") return [];\n\t\t\treturn [{ notificationId: notification.notificationId, record }];\n\t\t});\n\t}\n\n\tgetTerminalNotification(\n\t\tlaneId: string,\n\t): { notificationId: string; status: \"pending\" | \"delivered\"; record: LaneRecord } | undefined {\n\t\tconst record = this.getRecord(laneId) ?? this.getManagedRecord(laneId);\n\t\tif (!record || record.status === \"queued\" || record.status === \"running\") return undefined;\n\t\tthis.enqueueTerminalNotification(record);\n\t\tconst attempt = this.getActiveAttempt(laneId) ?? this.getManagedAttempt(laneId);\n\t\tif (!attempt) return undefined;\n\t\tconst notificationId = `worker-terminal:${attempt.attemptId}`;\n\t\tconst notification = this.ledger.runtime.getSnapshot().notifications[notificationId];\n\t\treturn notification ? { notificationId, status: notification.status, record } : undefined;\n\t}\n\n\tmarkNotificationsDelivered(notificationIds: readonly string[]): void {\n\t\tfor (const notificationId of notificationIds) this.ledger.runtime.markNotificationDelivered(notificationId);\n\t}\n\n\tprivate ensureTerminalNotifications(): void {\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\tfor (const taskId of Object.keys(snapshot.tasks)) {\n\t\t\tconst record = projectWorkerLaneRecord(snapshot, taskId);\n\t\t\tif (record && record.status !== \"queued\" && record.status !== \"running\") {\n\t\t\t\tthis.enqueueTerminalNotification(record);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate enqueueTerminalNotification(record: LaneRecord): void {\n\t\tconst attempt = this.getActiveAttempt(record.laneId) ?? this.getManagedAttempt(record.laneId);\n\t\tif (!attempt || ACTIVE_WORKER_ATTEMPT_STATUSES.has(attempt.status)) return;\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\tconst task = snapshot.tasks[attempt.taskId];\n\t\tif (!task) return;\n\t\tif (attempt.result?.nextAction === \"independent_verification_required\" && !task.verification) return;\n\t\tthis.ledger.runtime.enqueueNotification({\n\t\t\tnotificationId: `worker-terminal:${attempt.attemptId}`,\n\t\t\tobjectiveId: task.task.objectiveId,\n\t\t\tattemptId: attempt.attemptId,\n\t\t\tmessage: `Worker ${record.laneId} reached ${record.status}.`,\n\t\t});\n\t}\n\n\tprivate requireActiveAttempt(laneId: string): AttemptRuntimeState {\n\t\tconst attempt = this.getActiveAttempt(laneId);\n\t\tif (!attempt || !ACTIVE_WORKER_ATTEMPT_STATUSES.has(attempt.status)) {\n\t\t\tthrow new Error(`Durable worker '${laneId}' has no active attempt.`);\n\t\t}\n\t\treturn attempt;\n\t}\n\n\tprivate startedHandle(attempt: AttemptRuntimeState): StartedDelegationAttempt {\n\t\tconst task = this.ledger.runtime.getSnapshot().tasks[attempt.taskId];\n\t\tif (!task || !attempt.lease) throw new Error(`Attempt '${attempt.attemptId}' has no started handle.`);\n\t\treturn {\n\t\t\tobjectiveId: task.task.objectiveId,\n\t\t\ttaskId: task.task.taskId,\n\t\t\tattemptId: attempt.attemptId,\n\t\t\tleaseId: attempt.lease.leaseId,\n\t\t\tfencingToken: attempt.lease.fencingToken,\n\t\t\texpiresAt: attempt.lease.expiresAt,\n\t\t};\n\t}\n\n\tprivate startPreparedManagedAttempt(\n\t\tattempt: AttemptRuntimeState,\n\t\tleaseTtlMs: number,\n\t\tcompileGrant: (target: { objectiveId: string; taskId: string; attemptId: string }) => ExecutionGrant,\n\t): StartedDelegationAttempt {\n\t\tconst task = this.ledger.runtime.getSnapshot().tasks[attempt.taskId];\n\t\tif (!task) throw new Error(`Managed attempt '${attempt.attemptId}' has no durable task.`);\n\t\tconst grant = compileGrant({\n\t\t\tobjectiveId: task.task.objectiveId,\n\t\t\ttaskId: task.task.taskId,\n\t\t\tattemptId: attempt.attemptId,\n\t\t});\n\t\tthis.bindGrant(attempt.attemptId, grant);\n\t\treturn this.ledger.start(\n\t\t\tattempt.attemptId,\n\t\t\tleaseTtlMs,\n\t\t\t`managed:${attempt.dispatch.logicalLaneId ?? attempt.taskId}`,\n\t\t);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { LaneRecord, LaneTerminalStatus } from "../autonomy/lane-tracker.ts";
|
|
2
|
+
export interface WorkerTerminalHandoffRecord {
|
|
3
|
+
laneId: string;
|
|
4
|
+
status: LaneTerminalStatus;
|
|
5
|
+
reasonCode?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface WorkerNotificationStatus {
|
|
8
|
+
active: number;
|
|
9
|
+
queued: number;
|
|
10
|
+
running: number;
|
|
11
|
+
completedSinceFlush: number;
|
|
12
|
+
failedSinceFlush: number;
|
|
13
|
+
terminalSinceFlush: readonly WorkerTerminalHandoffRecord[];
|
|
14
|
+
}
|
|
15
|
+
export interface WorkerNotificationCoordinatorOptions {
|
|
16
|
+
getWorkerRecords(): readonly LaneRecord[];
|
|
17
|
+
emitStatus(status: WorkerNotificationStatus): void;
|
|
18
|
+
notify(records: readonly WorkerTerminalHandoffRecord[]): Promise<void>;
|
|
19
|
+
warn(message: string): void;
|
|
20
|
+
markDurableDelivered(notificationIds: readonly string[]): void;
|
|
21
|
+
}
|
|
22
|
+
/** Event-driven, bounded terminal outbox. Durable worker events can be replayed into it on resume. */
|
|
23
|
+
export declare class WorkerNotificationCoordinator {
|
|
24
|
+
private readonly options;
|
|
25
|
+
private readonly pending;
|
|
26
|
+
private scheduled;
|
|
27
|
+
private disposed;
|
|
28
|
+
private deliveryTail;
|
|
29
|
+
constructor(options: WorkerNotificationCoordinatorOptions);
|
|
30
|
+
recordTerminal(record: LaneRecord, durableNotificationId?: string): void;
|
|
31
|
+
statusChanged(): void;
|
|
32
|
+
dispose(): void;
|
|
33
|
+
private schedule;
|
|
34
|
+
private flush;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=worker-notification-coordinator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-notification-coordinator.d.ts","s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I,IAAI,CAId;IAED,OAAO,CAAC,QAAQ;IAMhB,OAAO,CAAC,KAAK;CA+Cb","sourcesContent":["import type { LaneRecord, LaneTerminalStatus } from \"../autonomy/lane-tracker.ts\";\n\nconst HANDOFF_TIMEOUT_MS = 30_000;\n\nexport interface WorkerTerminalHandoffRecord {\n\tlaneId: string;\n\tstatus: LaneTerminalStatus;\n\treasonCode?: string;\n}\n\nexport interface WorkerNotificationStatus {\n\tactive: number;\n\tqueued: number;\n\trunning: number;\n\tcompletedSinceFlush: number;\n\tfailedSinceFlush: number;\n\tterminalSinceFlush: readonly WorkerTerminalHandoffRecord[];\n}\n\ninterface PendingWorkerNotification {\n\tkey: string;\n\trecord: WorkerTerminalHandoffRecord;\n\tdurableNotificationId?: string;\n}\n\nexport interface WorkerNotificationCoordinatorOptions {\n\tgetWorkerRecords(): readonly LaneRecord[];\n\temitStatus(status: WorkerNotificationStatus): void;\n\tnotify(records: readonly WorkerTerminalHandoffRecord[]): Promise<void>;\n\twarn(message: string): void;\n\tmarkDurableDelivered(notificationIds: readonly string[]): void;\n}\n\n/** Event-driven, bounded terminal outbox. Durable worker events can be replayed into it on resume. */\nexport class WorkerNotificationCoordinator {\n\tprivate readonly options: WorkerNotificationCoordinatorOptions;\n\tprivate readonly pending = new Map<string, PendingWorkerNotification>();\n\tprivate scheduled = false;\n\tprivate disposed = false;\n\tprivate deliveryTail = Promise.resolve();\n\n\tconstructor(options: WorkerNotificationCoordinatorOptions) {\n\t\tthis.options = options;\n\t}\n\n\trecordTerminal(record: LaneRecord, durableNotificationId?: string): void {\n\t\tif (record.status === \"queued\" || record.status === \"running\") return;\n\t\tconst key = durableNotificationId ?? `transient:${record.laneId}:${record.completedAt ?? record.status}`;\n\t\tthis.pending.set(key, {\n\t\t\tkey,\n\t\t\trecord: {\n\t\t\t\tlaneId: record.laneId,\n\t\t\t\tstatus: record.status,\n\t\t\t\t...(record.reasonCode ? { reasonCode: record.reasonCode } : {}),\n\t\t\t},\n\t\t\t...(durableNotificationId ? { durableNotificationId } : {}),\n\t\t});\n\t\tthis.schedule();\n\t}\n\n\tstatusChanged(): void {\n\t\tthis.schedule();\n\t}\n\n\tdispose(): void {\n\t\tthis.disposed = true;\n\t\tthis.scheduled = false;\n\t\tthis.pending.clear();\n\t}\n\n\tprivate schedule(): void {\n\t\tif (this.disposed || this.scheduled) return;\n\t\tthis.scheduled = true;\n\t\tqueueMicrotask(() => this.flush());\n\t}\n\n\tprivate flush(): void {\n\t\tthis.scheduled = false;\n\t\tif (this.disposed) return;\n\t\tconst batch = [...this.pending.values()];\n\t\tthis.pending.clear();\n\t\tconst workerRecords = this.options.getWorkerRecords();\n\t\tconst queued = workerRecords.filter((record) => record.status === \"queued\").length;\n\t\tconst running = workerRecords.filter((record) => record.status === \"running\").length;\n\t\tconst terminalSinceFlush = batch.map((notification) => notification.record);\n\t\tthis.options.emitStatus({\n\t\t\tactive: queued + running,\n\t\t\tqueued,\n\t\t\trunning,\n\t\t\tcompletedSinceFlush: terminalSinceFlush.filter((record) => record.status === \"succeeded\").length,\n\t\t\tfailedSinceFlush: terminalSinceFlush.filter((record) => record.status !== \"succeeded\").length,\n\t\t\tterminalSinceFlush,\n\t\t});\n\t\tif (batch.length === 0) return;\n\t\tconst delivery = this.deliveryTail.then(async () => {\n\t\t\tif (this.disposed) return;\n\t\t\tlet timeout: ReturnType<typeof setTimeout> | undefined;\n\t\t\ttry {\n\t\t\t\tawait Promise.race([\n\t\t\t\t\tthis.options.notify(terminalSinceFlush),\n\t\t\t\t\tnew Promise<never>((_resolve, reject) => {\n\t\t\t\t\t\ttimeout = setTimeout(\n\t\t\t\t\t\t\t() => reject(new Error(`worker terminal handoff timed out after ${HANDOFF_TIMEOUT_MS}ms`)),\n\t\t\t\t\t\t\tHANDOFF_TIMEOUT_MS,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (typeof timeout === \"object\" && timeout && \"unref\" in timeout) timeout.unref();\n\t\t\t\t\t}),\n\t\t\t\t]);\n\t\t\t\tconst durableIds = batch.flatMap((notification) =>\n\t\t\t\t\tnotification.durableNotificationId ? [notification.durableNotificationId] : [],\n\t\t\t\t);\n\t\t\t\tif (durableIds.length > 0) this.options.markDurableDelivered(durableIds);\n\t\t\t} finally {\n\t\t\t\tif (timeout) clearTimeout(timeout);\n\t\t\t}\n\t\t});\n\t\tthis.deliveryTail = delivery.catch((error: unknown) => {\n\t\t\tfor (const notification of batch) this.pending.set(notification.key, notification);\n\t\t\tthis.options.warn(\n\t\t\t\t`Background worker handoff failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t});\n\t}\n}\n"]}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const HANDOFF_TIMEOUT_MS = 30_000;
|
|
2
|
+
/** Event-driven, bounded terminal outbox. Durable worker events can be replayed into it on resume. */
|
|
3
|
+
export class WorkerNotificationCoordinator {
|
|
4
|
+
options;
|
|
5
|
+
pending = new Map();
|
|
6
|
+
scheduled = false;
|
|
7
|
+
disposed = false;
|
|
8
|
+
deliveryTail = Promise.resolve();
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
recordTerminal(record, durableNotificationId) {
|
|
13
|
+
if (record.status === "queued" || record.status === "running")
|
|
14
|
+
return;
|
|
15
|
+
const key = durableNotificationId ?? `transient:${record.laneId}:${record.completedAt ?? record.status}`;
|
|
16
|
+
this.pending.set(key, {
|
|
17
|
+
key,
|
|
18
|
+
record: {
|
|
19
|
+
laneId: record.laneId,
|
|
20
|
+
status: record.status,
|
|
21
|
+
...(record.reasonCode ? { reasonCode: record.reasonCode } : {}),
|
|
22
|
+
},
|
|
23
|
+
...(durableNotificationId ? { durableNotificationId } : {}),
|
|
24
|
+
});
|
|
25
|
+
this.schedule();
|
|
26
|
+
}
|
|
27
|
+
statusChanged() {
|
|
28
|
+
this.schedule();
|
|
29
|
+
}
|
|
30
|
+
dispose() {
|
|
31
|
+
this.disposed = true;
|
|
32
|
+
this.scheduled = false;
|
|
33
|
+
this.pending.clear();
|
|
34
|
+
}
|
|
35
|
+
schedule() {
|
|
36
|
+
if (this.disposed || this.scheduled)
|
|
37
|
+
return;
|
|
38
|
+
this.scheduled = true;
|
|
39
|
+
queueMicrotask(() => this.flush());
|
|
40
|
+
}
|
|
41
|
+
flush() {
|
|
42
|
+
this.scheduled = false;
|
|
43
|
+
if (this.disposed)
|
|
44
|
+
return;
|
|
45
|
+
const batch = [...this.pending.values()];
|
|
46
|
+
this.pending.clear();
|
|
47
|
+
const workerRecords = this.options.getWorkerRecords();
|
|
48
|
+
const queued = workerRecords.filter((record) => record.status === "queued").length;
|
|
49
|
+
const running = workerRecords.filter((record) => record.status === "running").length;
|
|
50
|
+
const terminalSinceFlush = batch.map((notification) => notification.record);
|
|
51
|
+
this.options.emitStatus({
|
|
52
|
+
active: queued + running,
|
|
53
|
+
queued,
|
|
54
|
+
running,
|
|
55
|
+
completedSinceFlush: terminalSinceFlush.filter((record) => record.status === "succeeded").length,
|
|
56
|
+
failedSinceFlush: terminalSinceFlush.filter((record) => record.status !== "succeeded").length,
|
|
57
|
+
terminalSinceFlush,
|
|
58
|
+
});
|
|
59
|
+
if (batch.length === 0)
|
|
60
|
+
return;
|
|
61
|
+
const delivery = this.deliveryTail.then(async () => {
|
|
62
|
+
if (this.disposed)
|
|
63
|
+
return;
|
|
64
|
+
let timeout;
|
|
65
|
+
try {
|
|
66
|
+
await Promise.race([
|
|
67
|
+
this.options.notify(terminalSinceFlush),
|
|
68
|
+
new Promise((_resolve, reject) => {
|
|
69
|
+
timeout = setTimeout(() => reject(new Error(`worker terminal handoff timed out after ${HANDOFF_TIMEOUT_MS}ms`)), HANDOFF_TIMEOUT_MS);
|
|
70
|
+
if (typeof timeout === "object" && timeout && "unref" in timeout)
|
|
71
|
+
timeout.unref();
|
|
72
|
+
}),
|
|
73
|
+
]);
|
|
74
|
+
const durableIds = batch.flatMap((notification) => notification.durableNotificationId ? [notification.durableNotificationId] : []);
|
|
75
|
+
if (durableIds.length > 0)
|
|
76
|
+
this.options.markDurableDelivered(durableIds);
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
if (timeout)
|
|
80
|
+
clearTimeout(timeout);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
this.deliveryTail = delivery.catch((error) => {
|
|
84
|
+
for (const notification of batch)
|
|
85
|
+
this.pending.set(notification.key, notification);
|
|
86
|
+
this.options.warn(`Background worker handoff failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=worker-notification-coordinator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-notification-coordinator.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-notification-coordinator.ts"],"names":[],"mappings":"AAEA,MAAM,kBAAkB,GAAG,MAAM,CAAC;AA+BlC,sGAAsG;AACtG,MAAM,OAAO,6BAA6B;IACxB,OAAO,CAAuC;IAC9C,OAAO,GAAG,IAAI,GAAG,EAAqC,CAAC;IAChE,SAAS,GAAG,KAAK,CAAC;IAClB,QAAQ,GAAG,KAAK,CAAC;IACjB,YAAY,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAEzC,YAAY,OAA6C,EAAE;QAC1D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAAA,CACvB;IAED,cAAc,CAAC,MAAkB,EAAE,qBAA8B,EAAQ;QACxE,IAAI,MAAM,CAAC,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS;YAAE,OAAO;QACtE,MAAM,GAAG,GAAG,qBAAqB,IAAI,aAAa,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QACzG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE;YACrB,GAAG;YACH,MAAM,EAAE;gBACP,MAAM,EAAE,MAAM,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BAAE,OAAO,CAAC,KAAK,EAAE,CAAC;oBAAA,CAClF,CAAC;iBACF,CAAC,CAAC;gBACH,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,EAAE,CACjD,YAAY,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,EAAE,CAC9E,CAAC;gBACF,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC;oBAAE,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;YAC1E,CAAC;oBAAS,CAAC;gBACV,IAAI,OAAO;oBAAE,YAAY,CAAC,OAAO,CAAC,CAAC;YACpC,CAAC;QAAA,CACD,CAAC,CAAC;QACH,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE,CAAC;YACtD,KAAK,MAAM,YAAY,IAAI,KAAK;gBAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;YACnF,IAAI,CAAC,OAAO,CAAC,IAAI,CAChB,qCAAqC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAC7F,CAAC;QAAA,CACF,CAAC,CAAC;IAAA,CACH;CACD","sourcesContent":["import type { LaneRecord, LaneTerminalStatus } from \"../autonomy/lane-tracker.ts\";\n\nconst HANDOFF_TIMEOUT_MS = 30_000;\n\nexport interface WorkerTerminalHandoffRecord {\n\tlaneId: string;\n\tstatus: LaneTerminalStatus;\n\treasonCode?: string;\n}\n\nexport interface WorkerNotificationStatus {\n\tactive: number;\n\tqueued: number;\n\trunning: number;\n\tcompletedSinceFlush: number;\n\tfailedSinceFlush: number;\n\tterminalSinceFlush: readonly WorkerTerminalHandoffRecord[];\n}\n\ninterface PendingWorkerNotification {\n\tkey: string;\n\trecord: WorkerTerminalHandoffRecord;\n\tdurableNotificationId?: string;\n}\n\nexport interface WorkerNotificationCoordinatorOptions {\n\tgetWorkerRecords(): readonly LaneRecord[];\n\temitStatus(status: WorkerNotificationStatus): void;\n\tnotify(records: readonly WorkerTerminalHandoffRecord[]): Promise<void>;\n\twarn(message: string): void;\n\tmarkDurableDelivered(notificationIds: readonly string[]): void;\n}\n\n/** Event-driven, bounded terminal outbox. Durable worker events can be replayed into it on resume. */\nexport class WorkerNotificationCoordinator {\n\tprivate readonly options: WorkerNotificationCoordinatorOptions;\n\tprivate readonly pending = new Map<string, PendingWorkerNotification>();\n\tprivate scheduled = false;\n\tprivate disposed = false;\n\tprivate deliveryTail = Promise.resolve();\n\n\tconstructor(options: WorkerNotificationCoordinatorOptions) {\n\t\tthis.options = options;\n\t}\n\n\trecordTerminal(record: LaneRecord, durableNotificationId?: string): void {\n\t\tif (record.status === \"queued\" || record.status === \"running\") return;\n\t\tconst key = durableNotificationId ?? `transient:${record.laneId}:${record.completedAt ?? record.status}`;\n\t\tthis.pending.set(key, {\n\t\t\tkey,\n\t\t\trecord: {\n\t\t\t\tlaneId: record.laneId,\n\t\t\t\tstatus: record.status,\n\t\t\t\t...(record.reasonCode ? { reasonCode: record.reasonCode } : {}),\n\t\t\t},\n\t\t\t...(durableNotificationId ? { durableNotificationId } : {}),\n\t\t});\n\t\tthis.schedule();\n\t}\n\n\tstatusChanged(): void {\n\t\tthis.schedule();\n\t}\n\n\tdispose(): void {\n\t\tthis.disposed = true;\n\t\tthis.scheduled = false;\n\t\tthis.pending.clear();\n\t}\n\n\tprivate schedule(): void {\n\t\tif (this.disposed || this.scheduled) return;\n\t\tthis.scheduled = true;\n\t\tqueueMicrotask(() => this.flush());\n\t}\n\n\tprivate flush(): void {\n\t\tthis.scheduled = false;\n\t\tif (this.disposed) return;\n\t\tconst batch = [...this.pending.values()];\n\t\tthis.pending.clear();\n\t\tconst workerRecords = this.options.getWorkerRecords();\n\t\tconst queued = workerRecords.filter((record) => record.status === \"queued\").length;\n\t\tconst running = workerRecords.filter((record) => record.status === \"running\").length;\n\t\tconst terminalSinceFlush = batch.map((notification) => notification.record);\n\t\tthis.options.emitStatus({\n\t\t\tactive: queued + running,\n\t\t\tqueued,\n\t\t\trunning,\n\t\t\tcompletedSinceFlush: terminalSinceFlush.filter((record) => record.status === \"succeeded\").length,\n\t\t\tfailedSinceFlush: terminalSinceFlush.filter((record) => record.status !== \"succeeded\").length,\n\t\t\tterminalSinceFlush,\n\t\t});\n\t\tif (batch.length === 0) return;\n\t\tconst delivery = this.deliveryTail.then(async () => {\n\t\t\tif (this.disposed) return;\n\t\t\tlet timeout: ReturnType<typeof setTimeout> | undefined;\n\t\t\ttry {\n\t\t\t\tawait Promise.race([\n\t\t\t\t\tthis.options.notify(terminalSinceFlush),\n\t\t\t\t\tnew Promise<never>((_resolve, reject) => {\n\t\t\t\t\t\ttimeout = setTimeout(\n\t\t\t\t\t\t\t() => reject(new Error(`worker terminal handoff timed out after ${HANDOFF_TIMEOUT_MS}ms`)),\n\t\t\t\t\t\t\tHANDOFF_TIMEOUT_MS,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (typeof timeout === \"object\" && timeout && \"unref\" in timeout) timeout.unref();\n\t\t\t\t\t}),\n\t\t\t\t]);\n\t\t\t\tconst durableIds = batch.flatMap((notification) =>\n\t\t\t\t\tnotification.durableNotificationId ? [notification.durableNotificationId] : [],\n\t\t\t\t);\n\t\t\t\tif (durableIds.length > 0) this.options.markDurableDelivered(durableIds);\n\t\t\t} finally {\n\t\t\t\tif (timeout) clearTimeout(timeout);\n\t\t\t}\n\t\t});\n\t\tthis.deliveryTail = delivery.catch((error: unknown) => {\n\t\t\tfor (const notification of batch) this.pending.set(notification.key, notification);\n\t\t\tthis.options.warn(\n\t\t\t\t`Background worker handoff failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t});\n\t}\n}\n"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Api, Model } from "@caupulican/pi-ai";
|
|
2
|
+
import type { ModelRegistry } from "../model-registry.ts";
|
|
3
|
+
import type { OrchestrationModelBinding, OrchestrationProfile, WorkerProfileExecutionContract } from "../orchestration/contracts.ts";
|
|
4
|
+
import type { SettingsManager } from "../settings-manager.ts";
|
|
5
|
+
import type { WorkerDelegationRequest } from "./worker-delegation-request.ts";
|
|
6
|
+
export interface ResolvedWorkerProfile {
|
|
7
|
+
model: Model<Api>;
|
|
8
|
+
modelBinding: OrchestrationModelBinding;
|
|
9
|
+
profile: OrchestrationProfile;
|
|
10
|
+
soul?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface WorkerProfileResolverOptions {
|
|
13
|
+
agentDir: string;
|
|
14
|
+
cwd: string;
|
|
15
|
+
getSettingsManager(): SettingsManager;
|
|
16
|
+
getModelRegistry(): ModelRegistry;
|
|
17
|
+
isModelExhausted(model: Model<Api>): boolean;
|
|
18
|
+
getActiveOrchestrationProfile(): OrchestrationProfile | undefined;
|
|
19
|
+
onDiagnostic(message: string): void;
|
|
20
|
+
}
|
|
21
|
+
export declare class WorkerProfileResolver {
|
|
22
|
+
private readonly options;
|
|
23
|
+
private readonly warnedDiagnostics;
|
|
24
|
+
constructor(options: WorkerProfileResolverOptions);
|
|
25
|
+
catalog(): Array<{
|
|
26
|
+
profileId: string;
|
|
27
|
+
role: string;
|
|
28
|
+
description: string;
|
|
29
|
+
}>;
|
|
30
|
+
resolve(request: WorkerDelegationRequest, defaultProfileId: string | undefined): {
|
|
31
|
+
ok: true;
|
|
32
|
+
resolved: ResolvedWorkerProfile;
|
|
33
|
+
} | {
|
|
34
|
+
ok: false;
|
|
35
|
+
reason: string;
|
|
36
|
+
};
|
|
37
|
+
resolveVerifier(workerProfile: OrchestrationProfile): {
|
|
38
|
+
ok: true;
|
|
39
|
+
resolved: ResolvedWorkerProfile;
|
|
40
|
+
} | {
|
|
41
|
+
ok: false;
|
|
42
|
+
reason: string;
|
|
43
|
+
};
|
|
44
|
+
resolveContract(contract: WorkerProfileExecutionContract): {
|
|
45
|
+
ok: true;
|
|
46
|
+
resolved: ResolvedWorkerProfile;
|
|
47
|
+
} | {
|
|
48
|
+
ok: false;
|
|
49
|
+
reason: string;
|
|
50
|
+
};
|
|
51
|
+
private resolveProfileId;
|
|
52
|
+
private isProfileAuthorized;
|
|
53
|
+
private loadProfiles;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=worker-profile-resolver.d.ts.map
|