@caupulican/pi-adaptative 0.86.3 → 0.86.6
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 +44 -0
- package/dist/core/agent-paths.d.ts +13 -0
- package/dist/core/agent-paths.d.ts.map +1 -1
- package/dist/core/agent-paths.js +23 -0
- package/dist/core/agent-paths.js.map +1 -1
- package/dist/core/autonomy/bounded-completion.d.ts +7 -0
- package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
- package/dist/core/autonomy/bounded-completion.js +12 -4
- package/dist/core/autonomy/bounded-completion.js.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.d.ts +2 -0
- package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.js +6 -3
- package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
- package/dist/core/autonomy/subagent-prompt.js +1 -1
- package/dist/core/autonomy/subagent-prompt.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +25 -2
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +67 -0
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/delegation/replay-safe-mailbox-bounds.d.ts +4 -0
- package/dist/core/delegation/replay-safe-mailbox-bounds.d.ts.map +1 -0
- package/dist/core/delegation/replay-safe-mailbox-bounds.js +20 -0
- package/dist/core/delegation/replay-safe-mailbox-bounds.js.map +1 -0
- package/dist/core/delegation/sanitized-context-fork.d.ts +25 -0
- package/dist/core/delegation/sanitized-context-fork.d.ts.map +1 -0
- package/dist/core/delegation/sanitized-context-fork.js +299 -0
- package/dist/core/delegation/sanitized-context-fork.js.map +1 -0
- package/dist/core/delegation/session-root-mailbox.d.ts +75 -0
- package/dist/core/delegation/session-root-mailbox.d.ts.map +1 -0
- package/dist/core/delegation/session-root-mailbox.js +627 -0
- package/dist/core/delegation/session-root-mailbox.js.map +1 -0
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts +102 -9
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.js +1307 -125
- package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-agent-control.d.ts +183 -8
- package/dist/core/delegation/worker-agent-control.d.ts.map +1 -1
- package/dist/core/delegation/worker-agent-control.js +778 -48
- package/dist/core/delegation/worker-agent-control.js.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.d.ts +9 -0
- package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.js +479 -214
- package/dist/core/delegation/worker-attempt-executor.js.map +1 -1
- package/dist/core/delegation/worker-authority-resolver.d.ts +9 -0
- package/dist/core/delegation/worker-authority-resolver.d.ts.map +1 -1
- package/dist/core/delegation/worker-authority-resolver.js +21 -2
- package/dist/core/delegation/worker-authority-resolver.js.map +1 -1
- package/dist/core/delegation/worker-context-fork-store.d.ts +71 -0
- package/dist/core/delegation/worker-context-fork-store.d.ts.map +1 -0
- package/dist/core/delegation/worker-context-fork-store.js +437 -0
- package/dist/core/delegation/worker-context-fork-store.js.map +1 -0
- package/dist/core/delegation/worker-context-inheritance-policy.d.ts +18 -0
- package/dist/core/delegation/worker-context-inheritance-policy.d.ts.map +1 -0
- package/dist/core/delegation/worker-context-inheritance-policy.js +28 -0
- package/dist/core/delegation/worker-context-inheritance-policy.js.map +1 -0
- package/dist/core/delegation/worker-conversation-revision.d.ts +31 -0
- package/dist/core/delegation/worker-conversation-revision.d.ts.map +1 -0
- package/dist/core/delegation/worker-conversation-revision.js +203 -0
- package/dist/core/delegation/worker-conversation-revision.js.map +1 -0
- package/dist/core/delegation/worker-conversation-store.d.ts +130 -18
- package/dist/core/delegation/worker-conversation-store.d.ts.map +1 -1
- package/dist/core/delegation/worker-conversation-store.js +1263 -79
- package/dist/core/delegation/worker-conversation-store.js.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.d.ts +30 -2
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.js +675 -111
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
- package/dist/core/delegation/worker-delegation-request.d.ts +2 -0
- package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-request.js.map +1 -1
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts +20 -1
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -1
- package/dist/core/delegation/worker-dispatch-scheduler.js +210 -37
- package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -1
- package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -1
- package/dist/core/delegation/worker-execution-policy.js +14 -2
- package/dist/core/delegation/worker-execution-policy.js.map +1 -1
- package/dist/core/delegation/worker-fleet-limits.d.ts +38 -0
- package/dist/core/delegation/worker-fleet-limits.d.ts.map +1 -0
- package/dist/core/delegation/worker-fleet-limits.js +113 -0
- package/dist/core/delegation/worker-fleet-limits.js.map +1 -0
- package/dist/core/delegation/worker-lane-projection.d.ts +1 -0
- package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -1
- package/dist/core/delegation/worker-lane-projection.js +6 -2
- package/dist/core/delegation/worker-lane-projection.js.map +1 -1
- package/dist/core/delegation/worker-lifecycle.d.ts +20 -3
- package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
- package/dist/core/delegation/worker-lifecycle.js +42 -18
- package/dist/core/delegation/worker-lifecycle.js.map +1 -1
- package/dist/core/delegation/worker-notification-coordinator.d.ts +4 -0
- package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-notification-coordinator.js +45 -4
- package/dist/core/delegation/worker-notification-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-provider-turn-protocol.d.ts +50 -0
- package/dist/core/delegation/worker-provider-turn-protocol.d.ts.map +1 -0
- package/dist/core/delegation/worker-provider-turn-protocol.js +185 -0
- package/dist/core/delegation/worker-provider-turn-protocol.js.map +1 -0
- package/dist/core/delegation/worker-recovery-coordinator.d.ts +45 -4
- package/dist/core/delegation/worker-recovery-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-recovery-coordinator.js +223 -17
- package/dist/core/delegation/worker-recovery-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-retry-policy.d.ts +36 -0
- package/dist/core/delegation/worker-retry-policy.d.ts.map +1 -0
- package/dist/core/delegation/worker-retry-policy.js +41 -0
- package/dist/core/delegation/worker-retry-policy.js.map +1 -0
- package/dist/core/delegation/worker-runner.d.ts +3 -1
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +4 -2
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/delegation/worker-task-view.d.ts +43 -0
- package/dist/core/delegation/worker-task-view.d.ts.map +1 -0
- package/dist/core/delegation/worker-task-view.js +194 -0
- package/dist/core/delegation/worker-task-view.js.map +1 -0
- package/dist/core/delegation/worker-terminal-handoff-coordinator.d.ts +55 -0
- package/dist/core/delegation/worker-terminal-handoff-coordinator.d.ts.map +1 -0
- package/dist/core/delegation/worker-terminal-handoff-coordinator.js +179 -0
- package/dist/core/delegation/worker-terminal-handoff-coordinator.js.map +1 -0
- package/dist/core/delegation/worker-tree-budget-coordinator.d.ts +2 -2
- package/dist/core/delegation/worker-tree-budget-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-tree-budget-coordinator.js +12 -46
- package/dist/core/delegation/worker-tree-budget-coordinator.js.map +1 -1
- package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-controller.js +15 -0
- package/dist/core/goals/goal-continuation-controller.js.map +1 -1
- package/dist/core/goals/goal-state.d.ts +6 -0
- package/dist/core/goals/goal-state.d.ts.map +1 -1
- package/dist/core/goals/goal-state.js +1 -0
- package/dist/core/goals/goal-state.js.map +1 -1
- package/dist/core/goals/goal-tool-core.d.ts +1 -0
- package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
- package/dist/core/goals/goal-tool-core.js +25 -3
- package/dist/core/goals/goal-tool-core.js.map +1 -1
- package/dist/core/keybindings.d.ts +10 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +2 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/orchestration/attempt-ordering.d.ts +9 -0
- package/dist/core/orchestration/attempt-ordering.d.ts.map +1 -0
- package/dist/core/orchestration/attempt-ordering.js +29 -0
- package/dist/core/orchestration/attempt-ordering.js.map +1 -0
- package/dist/core/orchestration/capability-gateway.d.ts +19 -0
- package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
- package/dist/core/orchestration/capability-gateway.js +19 -2
- package/dist/core/orchestration/capability-gateway.js.map +1 -1
- package/dist/core/orchestration/contracts.d.ts +43 -3
- package/dist/core/orchestration/contracts.d.ts.map +1 -1
- package/dist/core/orchestration/contracts.js +24 -0
- package/dist/core/orchestration/contracts.js.map +1 -1
- package/dist/core/orchestration/delegation-ledger.d.ts +8 -3
- package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -1
- package/dist/core/orchestration/delegation-ledger.js +148 -55
- package/dist/core/orchestration/delegation-ledger.js.map +1 -1
- package/dist/core/orchestration/event-store.d.ts +6 -3
- package/dist/core/orchestration/event-store.d.ts.map +1 -1
- package/dist/core/orchestration/event-store.js +228 -30
- package/dist/core/orchestration/event-store.js.map +1 -1
- package/dist/core/orchestration/task-runtime-codecs.d.ts +31 -0
- package/dist/core/orchestration/task-runtime-codecs.d.ts.map +1 -0
- package/dist/core/orchestration/task-runtime-codecs.js +1471 -0
- package/dist/core/orchestration/task-runtime-codecs.js.map +1 -0
- package/dist/core/orchestration/task-runtime-projection.d.ts +30 -0
- package/dist/core/orchestration/task-runtime-projection.d.ts.map +1 -0
- package/dist/core/orchestration/task-runtime-projection.js +340 -0
- package/dist/core/orchestration/task-runtime-projection.js.map +1 -0
- package/dist/core/orchestration/task-runtime-reducer.d.ts +38 -0
- package/dist/core/orchestration/task-runtime-reducer.d.ts.map +1 -0
- package/dist/core/orchestration/task-runtime-reducer.js +1270 -0
- package/dist/core/orchestration/task-runtime-reducer.js.map +1 -0
- package/dist/core/orchestration/task-runtime-state.d.ts +142 -0
- package/dist/core/orchestration/task-runtime-state.d.ts.map +1 -0
- package/dist/core/orchestration/task-runtime-state.js +14 -0
- package/dist/core/orchestration/task-runtime-state.js.map +1 -0
- package/dist/core/orchestration/task-runtime.d.ts +44 -98
- package/dist/core/orchestration/task-runtime.d.ts.map +1 -1
- package/dist/core/orchestration/task-runtime.js +357 -1113
- package/dist/core/orchestration/task-runtime.js.map +1 -1
- package/dist/core/orchestration/worker-context-fork-reference.d.ts +20 -0
- package/dist/core/orchestration/worker-context-fork-reference.d.ts.map +1 -0
- package/dist/core/orchestration/worker-context-fork-reference.js +53 -0
- package/dist/core/orchestration/worker-context-fork-reference.js.map +1 -0
- package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -1
- package/dist/core/orchestration/worker-execution-contract.js +4 -2
- package/dist/core/orchestration/worker-execution-contract.js.map +1 -1
- package/dist/core/research/research-runner.d.ts +2 -0
- package/dist/core/research/research-runner.d.ts.map +1 -1
- package/dist/core/research/research-runner.js +1 -0
- package/dist/core/research/research-runner.js.map +1 -1
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +8 -0
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/secrets/credential-project.d.ts.map +1 -1
- package/dist/core/secrets/credential-project.js +24 -2
- package/dist/core/secrets/credential-project.js.map +1 -1
- package/dist/core/security/secret-text.d.ts +3 -0
- package/dist/core/security/secret-text.d.ts.map +1 -1
- package/dist/core/security/secret-text.js +15 -0
- package/dist/core/security/secret-text.js.map +1 -1
- package/dist/core/settings-manager.d.ts +3 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +160 -8
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +33 -15
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +763 -115
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/goal.d.ts +1 -0
- package/dist/core/tools/goal.d.ts.map +1 -1
- package/dist/core/tools/goal.js +9 -1
- package/dist/core/tools/goal.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +1 -0
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/activity-lane.d.ts +5 -0
- package/dist/modes/interactive/components/activity-lane.d.ts.map +1 -1
- package/dist/modes/interactive/components/activity-lane.js +133 -49
- package/dist/modes/interactive/components/activity-lane.js.map +1 -1
- package/dist/modes/interactive/components/agents-overlay.d.ts +40 -0
- package/dist/modes/interactive/components/agents-overlay.d.ts.map +1 -0
- package/dist/modes/interactive/components/agents-overlay.js +153 -0
- package/dist/modes/interactive/components/agents-overlay.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +18 -13
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-event-controller.d.ts +1 -1
- package/dist/modes/interactive/interactive-event-controller.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-event-controller.js +6 -3
- package/dist/modes/interactive/interactive-event-controller.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +5 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +51 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/key-handlers.d.ts +1 -0
- package/dist/modes/interactive/key-handlers.d.ts.map +1 -1
- package/dist/modes/interactive/key-handlers.js +1 -0
- package/dist/modes/interactive/key-handlers.js.map +1 -1
- package/docs/harness-architecture.md +61 -17
- package/docs/settings.md +17 -9
- package/docs/worker-profiles.md +6 -2
- 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/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 +12 -12
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-execution-policy.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-execution-policy.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAW7F,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAU,CAAC;AAChE,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,CAAU,CAAC;AAcpD,SAAS,mBAAmB,CAAC,aAAgC,EAAE,YAA+B;IAC7F,MAAM,aAAa,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CACxD,YAAY,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAChC,IAAI,iBAAiB,CAAC,OAAO,EAAE,QAAQ,CAAC;YAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAC3D,IAAI,iBAAiB,CAAC,QAAQ,EAAE,OAAO,CAAC;YAAE,OAAO,CAAC,QA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AE,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;QACtD,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACzC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAC5E;QACD,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACjE,eAAe,EAAE,IAAI,CAAC,MAAM;QAC5B,eAAe,EAAE,IAAI,CAAC,MAAM;QAC5B,aAAa,EAAE,oBAAoB;KACnC,CAAC,CAAC;IACH,IAAI,QAAQ,CAAC,OAAO,KAAK,OAAO;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,CAAC,WAAW,EAAE,CAAC;IAC1F,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;AAC5C,CAAC","sourcesContent":["import path from \"node:path\";\nimport { isPathWithinScope } from \"../autonomy/path-scope.ts\";\nimport { mapToolNamesForPlatform, STABLE_SHELL_TOOL_NAME } from \"../default-tool-surface.ts\";\nimport type {\n\tExecutionGrant,\n\tHarnessCapability,\n\tOrchestrationProfile,\n\tResourcePointer,\n\tRiskBudget,\n\tToolCapabilityManifest,\n\tWorkerExecutionAuthorityContract,\n\tWorkerRole,\n} from \"../orchestration/contracts.ts\";\nimport { buildLaneToolManifests } from \"../orchestration/lane-tool-manifests.ts\";\nimport { ExecutionPolicyCompiler } from \"../orchestration/policy-compiler.ts\";\nimport { intersectRiskBudgets } from \"../orchestration/risk-budget.ts\";\nimport type { ResolvedWorkerDelegationSettings } from \"../settings-manager.ts\";\nimport { getToolCapabilityPolicy } from \"../tool-capability-policy.ts\";\n\nconst READ_TOOL_NAMES = [\"read\", \"grep\", \"find\", \"ls\"] as const;\nconst WRITE_TOOL_NAMES = [\"write\", \"edit\"] as const;\n\nexport interface WorkerExecutionPlan {\n\ttoolManifests: readonly ToolCapabilityManifest[];\n\trequiredCapabilities: readonly HarnessCapability[];\n\treadPaths: readonly string[];\n\twritePaths: readonly string[];\n\tdeniedPaths: readonly string[];\n\treadMemory: boolean;\n\twriteEnabled: boolean;\n\tprocessEnabled: boolean;\n\tbudget: RiskBudget;\n}\n\nfunction intersectPathScopes(admittedPaths: readonly string[], currentPaths: readonly string[]): string[] {\n\tconst intersections = admittedPaths.flatMap((admitted) =>\n\t\tcurrentPaths.flatMap((current) => {\n\t\t\tif (isPathWithinScope(current, admitted)) return [current];\n\t\t\tif (isPathWithinScope(admitted, current)) return [admitted];\n\t\t\treturn [];\n\t\t}),\n\t);\n\treturn [...new Set(intersections.map((entry) => path.resolve(entry)))];\n}\n\nexport function workerExecutionAuthorityFromPlan(plan: WorkerExecutionPlan): WorkerExecutionAuthorityContract {\n\treturn {\n\t\tcapabilities: [...plan.requiredCapabilities],\n\t\ttoolNames: plan.toolManifests.map((manifest) => manifest.toolName),\n\t\treadPaths: [...plan.readPaths],\n\t\twritePaths: [...plan.writePaths],\n\t\tdeniedPaths: [...plan.deniedPaths],\n\t\tbudget: { ...plan.budget },\n\t};\n}\n\n/** Apply live revocations to admitted authority without allowing later settings to widen it. */\nexport function narrowWorkerExecutionPlan(\n\tadmitted: WorkerExecutionAuthorityContract,\n\tcurrent: WorkerExecutionPlan,\n): WorkerExecutionPlan {\n\tconst admittedTools = new Set(mapToolNamesForPlatform(admitted.toolNames));\n\tconst admittedCapabilities = new Set(admitted.capabilities);\n\tconst toolManifests = current.toolManifests.filter(\n\t\t(manifest) =>\n\t\t\tadmittedTools.has(manifest.toolName) &&\n\t\t\tmanifest.capabilities.every((capability) => admittedCapabilities.has(capability)),\n\t);\n\tconst requiredCapabilities = [...new Set(toolManifests.flatMap((manifest) => manifest.capabilities))];\n\tconst grantedTools = new Set(toolManifests.map((manifest) => manifest.toolName));\n\tconst readEnabled = requiredCapabilities.some(\n\t\t(capability) => capability === \"filesystem.read\" || capability === \"worktree.read\",\n\t);\n\tconst writeEnabled = grantedTools.has(\"write\") || grantedTools.has(\"edit\");\n\treturn {\n\t\ttoolManifests,\n\t\trequiredCapabilities,\n\t\treadPaths: readEnabled ? intersectPathScopes(admitted.readPaths, current.readPaths) : [],\n\t\twritePaths: writeEnabled ? intersectPathScopes(admitted.writePaths, current.writePaths) : [],\n\t\tdeniedPaths: [...new Set([...admitted.deniedPaths, ...current.deniedPaths].map((entry) => path.resolve(entry)))],\n\t\treadMemory: grantedTools.has(\"memory\"),\n\t\twriteEnabled,\n\t\tprocessEnabled: grantedTools.has(\"run_process\") || grantedTools.has(STABLE_SHELL_TOOL_NAME),\n\t\tbudget: intersectRiskBudgets(admitted.budget, current.budget),\n\t};\n}\n\nexport function buildWorkerExecutionPlan(args: {\n\tprofile: OrchestrationProfile;\n\tsettings: ResolvedWorkerDelegationSettings;\n\tcwd: string;\n\tdeniedPaths: readonly string[];\n\tforegroundMaxCostUsd?: number;\n\tmemoryEnabled: boolean;\n\trequestedReadPaths?: readonly string[];\n\trequestedWritePaths?: readonly string[];\n}): WorkerExecutionPlan {\n\tconst profileToolNames = new Set(mapToolNamesForPlatform(args.profile.toolNames));\n\tconst grantsRead =\n\t\targs.profile.capabilityCeiling.includes(\"filesystem.read\") ||\n\t\targs.profile.capabilityCeiling.includes(\"worktree.read\");\n\tconst writeEligible =\n\t\targs.settings.writeEnabled &&\n\t\targs.settings.writePaths.length > 0 &&\n\t\t(args.profile.capabilityCeiling.includes(\"filesystem.write\") ||\n\t\t\targs.profile.capabilityCeiling.includes(\"worktree.mutate\"));\n\tconst memoryEligible =\n\t\targs.memoryEnabled && profileToolNames.has(\"memory\") && args.profile.capabilityCeiling.includes(\"memory.query\");\n\tconst processEligible =\n\t\targs.profile.capabilityCeiling.includes(\"process.exec\") ||\n\t\targs.profile.capabilityCeiling.includes(\"tests.execute\");\n\tconst enabledProcessToolNames = processEligible\n\t\t? [\n\t\t\t\t...(args.profile.executionPolicy && profileToolNames.has(\"run_process\") ? ([\"run_process\"] as const) : []),\n\t\t\t\t...(profileToolNames.has(STABLE_SHELL_TOOL_NAME) ? [STABLE_SHELL_TOOL_NAME] : []),\n\t\t\t]\n\t\t: [];\n\tconst enabledToolNames = [\n\t\t...(grantsRead ? READ_TOOL_NAMES : []),\n\t\t...(writeEligible ? WRITE_TOOL_NAMES : []),\n\t\t...(memoryEligible ? ([\"memory\"] as const) : []),\n\t\t...enabledProcessToolNames,\n\t\t...(profileToolNames.has(\"delegate\") && args.profile.capabilityCeiling.includes(\"workflow.delegate\")\n\t\t\t? ([\"delegate\"] as const)\n\t\t\t: []),\n\t];\n\tconst toolManifests = buildLaneToolManifests(args.profile, enabledToolNames);\n\tconst grantedTools = new Set(toolManifests.map((manifest) => manifest.toolName));\n\tconst readEnabled = toolManifests.some((manifest) =>\n\t\tmanifest.capabilities.some((capability) => capability === \"filesystem.read\" || capability === \"worktree.read\"),\n\t);\n\tconst writeEnabled = grantedTools.has(\"write\") || grantedTools.has(\"edit\");\n\tconst readMemory = grantedTools.has(\"memory\");\n\tconst processEnabled = grantedTools.has(\"run_process\") || grantedTools.has(STABLE_SHELL_TOOL_NAME);\n\tconst budget = intersectRiskBudgets(\n\t\targs.profile.budget,\n\t\t...(args.settings.maxUsd > 0 ? [{ maxCostUsd: args.settings.maxUsd }] : []),\n\t\t...(args.foregroundMaxCostUsd !== undefined ? [{ maxCostUsd: args.foregroundMaxCostUsd }] : []),\n\t\t...(args.settings.maxWallClockMs > 0 ? [{ maxWallClockMs: args.settings.maxWallClockMs }] : []),\n\t);\n\treturn {\n\t\ttoolManifests,\n\t\trequiredCapabilities: [...new Set(toolManifests.flatMap((manifest) => manifest.capabilities))],\n\t\treadPaths: readEnabled\n\t\t\t? (args.requestedReadPaths ?? [args.cwd]).map((entry) =>\n\t\t\t\t\tpath.isAbsolute(entry) ? path.resolve(entry) : path.resolve(args.cwd, entry),\n\t\t\t\t)\n\t\t\t: [],\n\t\twritePaths: writeEnabled\n\t\t\t? intersectPathScopes(\n\t\t\t\t\targs.settings.writePaths.map((entry) =>\n\t\t\t\t\t\tpath.isAbsolute(entry) ? path.resolve(entry) : path.resolve(args.cwd, entry),\n\t\t\t\t\t),\n\t\t\t\t\t(args.requestedWritePaths ?? args.settings.writePaths).map((entry) =>\n\t\t\t\t\t\tpath.isAbsolute(entry) ? path.resolve(entry) : path.resolve(args.cwd, entry),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t: [],\n\t\tdeniedPaths: args.deniedPaths.map((entry) => path.resolve(entry)),\n\t\treadMemory,\n\t\twriteEnabled,\n\t\tprocessEnabled,\n\t\tbudget,\n\t};\n}\n\nexport function compileWorkerExecutionGrant(args: {\n\ttarget: { objectiveId: string; taskId: string; attemptId: string };\n\tprofile: OrchestrationProfile;\n\tplan: WorkerExecutionPlan;\n\tresources: readonly ResourcePointer[];\n}): { ok: true; grant: ExecutionGrant } | { ok: false; reasonCodes: readonly string[] } {\n\tconst compiled = new ExecutionPolicyCompiler().compile({\n\t\tobjectiveId: args.target.objectiveId,\n\t\ttaskId: args.target.taskId,\n\t\tattemptId: args.target.attemptId,\n\t\tsubjectId: `in-process:${args.target.attemptId}`,\n\t\trole: args.profile.role,\n\t\trequiredCapabilities: args.plan.requiredCapabilities,\n\t\trequestedCapabilities: args.plan.requiredCapabilities,\n\t\tauthorityCapabilities: args.profile.capabilityCeiling,\n\t\trequestedTools: args.plan.toolManifests.map((manifest) => manifest.toolName),\n\t\ttoolManifests: args.plan.toolManifests,\n\t\tresources: args.resources,\n\t\treadPaths: args.plan.readPaths,\n\t\twritePaths: args.plan.writePaths,\n\t\tdeniedPaths: args.plan.deniedPaths,\n\t\trequestedBudget: args.plan.budget,\n\t\tauthorityBudget: args.plan.budget,\n\t\tpolicyVersion: \"worker-profile-v1\",\n\t});\n\tif (compiled.outcome !== \"allow\") return { ok: false, reasonCodes: compiled.reasonCodes };\n\treturn { ok: true, grant: compiled.grant };\n}\n\n/** Compile the host's durable authority record before an externally managed process is launched. */\nexport function compileManagedProcessExecutionGrant(args: {\n\ttarget: { objectiveId: string; taskId: string; attemptId: string };\n\tlaneId: string;\n\tauthorizationId: string;\n\trole: WorkerRole;\n\tallowedTools: readonly string[];\n\twritePaths: readonly string[];\n\tcwd: string;\n\tdeniedPaths: readonly string[];\n\tbudget: RiskBudget;\n}): { ok: true; grant: ExecutionGrant } | { ok: false; reasonCodes: readonly string[] } {\n\tconst manifests: ToolCapabilityManifest[] = [];\n\tconst unknownTools: string[] = [];\n\tfor (const toolName of [...new Set(args.allowedTools)]) {\n\t\tconst policy = getToolCapabilityPolicy(toolName);\n\t\tconst capability = policy?.capabilityCandidates[0];\n\t\tif (!policy || !capability) {\n\t\t\tunknownTools.push(toolName);\n\t\t\tcontinue;\n\t\t}\n\t\tmanifests.push({\n\t\t\ttoolName,\n\t\t\tmoduleSpecifier: `managed-process:${toolName}`,\n\t\t\tcapabilities: [capability],\n\t\t\troles: [args.role],\n\t\t\tenforcements: [policy.enforcement],\n\t\t});\n\t}\n\tif (unknownTools.length > 0) return { ok: false, reasonCodes: unknownTools.map((name) => `unknown_tool:${name}`) };\n\tconst capabilities = [...new Set(manifests.flatMap((manifest) => manifest.capabilities))];\n\tconst readEnabled = capabilities.some(\n\t\t(capability) => capability === \"filesystem.read\" || capability === \"worktree.read\",\n\t);\n\tconst compiled = new ExecutionPolicyCompiler().compile({\n\t\t...args.target,\n\t\tsubjectId: `managed:${args.laneId}:${args.authorizationId}`,\n\t\trole: args.role,\n\t\trequiredCapabilities: capabilities,\n\t\trequestedCapabilities: capabilities,\n\t\tauthorityCapabilities: capabilities,\n\t\trequestedTools: manifests.map((manifest) => manifest.toolName),\n\t\ttoolManifests: manifests,\n\t\treadPaths: readEnabled ? [path.resolve(args.cwd)] : [],\n\t\twritePaths: args.writePaths.map((entry) =>\n\t\t\tpath.isAbsolute(entry) ? path.resolve(entry) : path.resolve(args.cwd, entry),\n\t\t),\n\t\tdeniedPaths: args.deniedPaths.map((entry) => path.resolve(entry)),\n\t\trequestedBudget: args.budget,\n\t\tauthorityBudget: args.budget,\n\t\tpolicyVersion: \"managed-process-v1\",\n\t});\n\tif (compiled.outcome !== \"allow\") return { ok: false, reasonCodes: compiled.reasonCodes };\n\treturn { ok: true, grant: compiled.grant };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"worker-execution-policy.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-execution-policy.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAW7F,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAU,CAAC;AAChE,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,CAAU,CAAC;AAcpD,SAAS,mBAAmB,CAAC,aAAgC,EAAE,YAA+B;IAC7F,MAAM,aAAa,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CACxD,YAAY,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAChC,IAAI,iBAAiB,CAAC,O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AAoB;KACnC,CAAC,CAAC;IACH,IAAI,QAAQ,CAAC,OAAO,KAAK,OAAO;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,CAAC,WAAW,EAAE,CAAC;IAC1F,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;AAC5C,CAAC","sourcesContent":["import path from \"node:path\";\nimport { isPathWithinScope } from \"../autonomy/path-scope.ts\";\nimport { mapToolNamesForPlatform, STABLE_SHELL_TOOL_NAME } from \"../default-tool-surface.ts\";\nimport type {\n\tExecutionGrant,\n\tHarnessCapability,\n\tOrchestrationProfile,\n\tResourcePointer,\n\tRiskBudget,\n\tToolCapabilityManifest,\n\tWorkerExecutionAuthorityContract,\n\tWorkerRole,\n} from \"../orchestration/contracts.ts\";\nimport { buildLaneToolManifests } from \"../orchestration/lane-tool-manifests.ts\";\nimport { ExecutionPolicyCompiler } from \"../orchestration/policy-compiler.ts\";\nimport { intersectRiskBudgets } from \"../orchestration/risk-budget.ts\";\nimport type { ResolvedWorkerDelegationSettings } from \"../settings-manager.ts\";\nimport { getToolCapabilityPolicy } from \"../tool-capability-policy.ts\";\n\nconst READ_TOOL_NAMES = [\"read\", \"grep\", \"find\", \"ls\"] as const;\nconst WRITE_TOOL_NAMES = [\"write\", \"edit\"] as const;\n\nexport interface WorkerExecutionPlan {\n\ttoolManifests: readonly ToolCapabilityManifest[];\n\trequiredCapabilities: readonly HarnessCapability[];\n\treadPaths: readonly string[];\n\twritePaths: readonly string[];\n\tdeniedPaths: readonly string[];\n\treadMemory: boolean;\n\twriteEnabled: boolean;\n\tprocessEnabled: boolean;\n\tbudget: RiskBudget;\n}\n\nfunction intersectPathScopes(admittedPaths: readonly string[], currentPaths: readonly string[]): string[] {\n\tconst intersections = admittedPaths.flatMap((admitted) =>\n\t\tcurrentPaths.flatMap((current) => {\n\t\t\tif (isPathWithinScope(current, admitted)) return [current];\n\t\t\tif (isPathWithinScope(admitted, current)) return [admitted];\n\t\t\treturn [];\n\t\t}),\n\t);\n\treturn [...new Set(intersections.map((entry) => path.resolve(entry)))];\n}\n\nexport function workerExecutionAuthorityFromPlan(plan: WorkerExecutionPlan): WorkerExecutionAuthorityContract {\n\treturn {\n\t\tcapabilities: [...plan.requiredCapabilities],\n\t\ttoolNames: plan.toolManifests.map((manifest) => manifest.toolName),\n\t\treadPaths: [...plan.readPaths],\n\t\twritePaths: [...plan.writePaths],\n\t\tdeniedPaths: [...plan.deniedPaths],\n\t\tbudget: { ...plan.budget },\n\t};\n}\n\n/** Apply live revocations to admitted authority without allowing later settings to widen it. */\nexport function narrowWorkerExecutionPlan(\n\tadmitted: WorkerExecutionAuthorityContract,\n\tcurrent: WorkerExecutionPlan,\n): WorkerExecutionPlan {\n\tconst admittedTools = new Set(mapToolNamesForPlatform(admitted.toolNames));\n\tconst admittedCapabilities = new Set(admitted.capabilities);\n\tconst toolManifests = current.toolManifests.filter(\n\t\t(manifest) =>\n\t\t\tadmittedTools.has(manifest.toolName) &&\n\t\t\tmanifest.capabilities.every((capability) => admittedCapabilities.has(capability)),\n\t);\n\tconst requiredCapabilities = [...new Set(toolManifests.flatMap((manifest) => manifest.capabilities))];\n\tconst grantedTools = new Set(toolManifests.map((manifest) => manifest.toolName));\n\tconst readEnabled = requiredCapabilities.some(\n\t\t(capability) => capability === \"filesystem.read\" || capability === \"worktree.read\",\n\t);\n\tconst writeEnabled = grantedTools.has(\"write\") || grantedTools.has(\"edit\");\n\treturn {\n\t\ttoolManifests,\n\t\trequiredCapabilities,\n\t\treadPaths: readEnabled ? intersectPathScopes(admitted.readPaths, current.readPaths) : [],\n\t\twritePaths: writeEnabled ? intersectPathScopes(admitted.writePaths, current.writePaths) : [],\n\t\tdeniedPaths: [...new Set([...admitted.deniedPaths, ...current.deniedPaths].map((entry) => path.resolve(entry)))],\n\t\treadMemory: grantedTools.has(\"memory\"),\n\t\twriteEnabled,\n\t\tprocessEnabled: grantedTools.has(\"run_process\") || grantedTools.has(STABLE_SHELL_TOOL_NAME),\n\t\tbudget: intersectRiskBudgets(admitted.budget, current.budget),\n\t};\n}\n\nexport function buildWorkerExecutionPlan(args: {\n\tprofile: OrchestrationProfile;\n\tsettings: ResolvedWorkerDelegationSettings;\n\tcwd: string;\n\tdeniedPaths: readonly string[];\n\tforegroundMaxCostUsd?: number;\n\tmemoryEnabled: boolean;\n\trequestedReadPaths?: readonly string[];\n\trequestedWritePaths?: readonly string[];\n}): WorkerExecutionPlan {\n\tconst profileToolNames = new Set(mapToolNamesForPlatform(args.profile.toolNames));\n\tconst grantsRead =\n\t\targs.profile.capabilityCeiling.includes(\"filesystem.read\") ||\n\t\targs.profile.capabilityCeiling.includes(\"worktree.read\");\n\tconst writeEligible =\n\t\targs.settings.writeEnabled &&\n\t\targs.settings.writePaths.length > 0 &&\n\t\t(args.profile.capabilityCeiling.includes(\"filesystem.write\") ||\n\t\t\targs.profile.capabilityCeiling.includes(\"worktree.mutate\"));\n\tconst memoryEligible = args.memoryEnabled;\n\tconst processEligible =\n\t\targs.profile.capabilityCeiling.includes(\"process.exec\") ||\n\t\targs.profile.capabilityCeiling.includes(\"tests.execute\");\n\tconst enabledProcessToolNames = processEligible\n\t\t? [\n\t\t\t\t...(args.profile.executionPolicy && profileToolNames.has(\"run_process\") ? ([\"run_process\"] as const) : []),\n\t\t\t\t...(profileToolNames.has(STABLE_SHELL_TOOL_NAME) ? [STABLE_SHELL_TOOL_NAME] : []),\n\t\t\t]\n\t\t: [];\n\tconst enabledToolNames = [\n\t\t...(grantsRead ? READ_TOOL_NAMES : []),\n\t\t...(writeEligible ? WRITE_TOOL_NAMES : []),\n\t\t...(memoryEligible ? ([\"memory\"] as const) : []),\n\t\t...enabledProcessToolNames,\n\t\t...(profileToolNames.has(\"delegate\") && args.profile.capabilityCeiling.includes(\"workflow.delegate\")\n\t\t\t? ([\"delegate\"] as const)\n\t\t\t: []),\n\t];\n\tconst toolManifests = buildLaneToolManifests(args.profile, enabledToolNames);\n\tif (memoryEligible && !toolManifests.some((manifest) => manifest.toolName === \"memory\")) {\n\t\ttoolManifests.push({\n\t\t\ttoolName: \"memory\",\n\t\t\tmoduleSpecifier: \"../tools/memory.ts\",\n\t\t\tcapabilities: [\"memory.query\"],\n\t\t\troles: [args.profile.role],\n\t\t\tenforcements: [\"memory-broker\"],\n\t\t});\n\t}\n\tconst grantedTools = new Set(toolManifests.map((manifest) => manifest.toolName));\n\tconst readEnabled = toolManifests.some((manifest) =>\n\t\tmanifest.capabilities.some((capability) => capability === \"filesystem.read\" || capability === \"worktree.read\"),\n\t);\n\tconst writeEnabled = grantedTools.has(\"write\") || grantedTools.has(\"edit\");\n\tconst readMemory = grantedTools.has(\"memory\");\n\tconst processEnabled = grantedTools.has(\"run_process\") || grantedTools.has(STABLE_SHELL_TOOL_NAME);\n\tconst budget = intersectRiskBudgets(\n\t\targs.profile.budget,\n\t\t...(args.settings.maxUsd > 0 ? [{ maxCostUsd: args.settings.maxUsd }] : []),\n\t\t...(args.foregroundMaxCostUsd !== undefined ? [{ maxCostUsd: args.foregroundMaxCostUsd }] : []),\n\t\t...(args.settings.maxWallClockMs > 0 ? [{ maxWallClockMs: args.settings.maxWallClockMs }] : []),\n\t);\n\treturn {\n\t\ttoolManifests,\n\t\trequiredCapabilities: [...new Set(toolManifests.flatMap((manifest) => manifest.capabilities))],\n\t\treadPaths: readEnabled\n\t\t\t? (args.requestedReadPaths ?? [args.cwd]).map((entry) =>\n\t\t\t\t\tpath.isAbsolute(entry) ? path.resolve(entry) : path.resolve(args.cwd, entry),\n\t\t\t\t)\n\t\t\t: [],\n\t\twritePaths: writeEnabled\n\t\t\t? intersectPathScopes(\n\t\t\t\t\targs.settings.writePaths.map((entry) =>\n\t\t\t\t\t\tpath.isAbsolute(entry) ? path.resolve(entry) : path.resolve(args.cwd, entry),\n\t\t\t\t\t),\n\t\t\t\t\t(args.requestedWritePaths ?? args.settings.writePaths).map((entry) =>\n\t\t\t\t\t\tpath.isAbsolute(entry) ? path.resolve(entry) : path.resolve(args.cwd, entry),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t: [],\n\t\tdeniedPaths: args.deniedPaths.map((entry) => path.resolve(entry)),\n\t\treadMemory,\n\t\twriteEnabled,\n\t\tprocessEnabled,\n\t\tbudget,\n\t};\n}\n\nexport function compileWorkerExecutionGrant(args: {\n\ttarget: { objectiveId: string; taskId: string; attemptId: string };\n\tprofile: OrchestrationProfile;\n\tplan: WorkerExecutionPlan;\n\tresources: readonly ResourcePointer[];\n}): { ok: true; grant: ExecutionGrant } | { ok: false; reasonCodes: readonly string[] } {\n\tconst authorityCapabilities =\n\t\targs.plan.readMemory && !args.profile.capabilityCeiling.includes(\"memory.query\")\n\t\t\t? [...args.profile.capabilityCeiling, \"memory.query\" as const]\n\t\t\t: args.profile.capabilityCeiling;\n\tconst compiled = new ExecutionPolicyCompiler().compile({\n\t\tobjectiveId: args.target.objectiveId,\n\t\ttaskId: args.target.taskId,\n\t\tattemptId: args.target.attemptId,\n\t\tsubjectId: `in-process:${args.target.attemptId}`,\n\t\trole: args.profile.role,\n\t\trequiredCapabilities: args.plan.requiredCapabilities,\n\t\trequestedCapabilities: args.plan.requiredCapabilities,\n\t\tauthorityCapabilities,\n\t\trequestedTools: args.plan.toolManifests.map((manifest) => manifest.toolName),\n\t\ttoolManifests: args.plan.toolManifests,\n\t\tresources: args.resources,\n\t\treadPaths: args.plan.readPaths,\n\t\twritePaths: args.plan.writePaths,\n\t\tdeniedPaths: args.plan.deniedPaths,\n\t\trequestedBudget: args.plan.budget,\n\t\tauthorityBudget: args.plan.budget,\n\t\tpolicyVersion: \"worker-profile-v1\",\n\t});\n\tif (compiled.outcome !== \"allow\") return { ok: false, reasonCodes: compiled.reasonCodes };\n\treturn { ok: true, grant: compiled.grant };\n}\n\n/** Compile the host's durable authority record before an externally managed process is launched. */\nexport function compileManagedProcessExecutionGrant(args: {\n\ttarget: { objectiveId: string; taskId: string; attemptId: string };\n\tlaneId: string;\n\tauthorizationId: string;\n\trole: WorkerRole;\n\tallowedTools: readonly string[];\n\twritePaths: readonly string[];\n\tcwd: string;\n\tdeniedPaths: readonly string[];\n\tbudget: RiskBudget;\n}): { ok: true; grant: ExecutionGrant } | { ok: false; reasonCodes: readonly string[] } {\n\tconst manifests: ToolCapabilityManifest[] = [];\n\tconst unknownTools: string[] = [];\n\tfor (const toolName of [...new Set(args.allowedTools)]) {\n\t\tconst policy = getToolCapabilityPolicy(toolName);\n\t\tconst capability = policy?.capabilityCandidates[0];\n\t\tif (!policy || !capability) {\n\t\t\tunknownTools.push(toolName);\n\t\t\tcontinue;\n\t\t}\n\t\tmanifests.push({\n\t\t\ttoolName,\n\t\t\tmoduleSpecifier: `managed-process:${toolName}`,\n\t\t\tcapabilities: [capability],\n\t\t\troles: [args.role],\n\t\t\tenforcements: [policy.enforcement],\n\t\t});\n\t}\n\tif (unknownTools.length > 0) return { ok: false, reasonCodes: unknownTools.map((name) => `unknown_tool:${name}`) };\n\tconst capabilities = [...new Set(manifests.flatMap((manifest) => manifest.capabilities))];\n\tconst readEnabled = capabilities.some(\n\t\t(capability) => capability === \"filesystem.read\" || capability === \"worktree.read\",\n\t);\n\tconst compiled = new ExecutionPolicyCompiler().compile({\n\t\t...args.target,\n\t\tsubjectId: `managed:${args.laneId}:${args.authorizationId}`,\n\t\trole: args.role,\n\t\trequiredCapabilities: capabilities,\n\t\trequestedCapabilities: capabilities,\n\t\tauthorityCapabilities: capabilities,\n\t\trequestedTools: manifests.map((manifest) => manifest.toolName),\n\t\ttoolManifests: manifests,\n\t\treadPaths: readEnabled ? [path.resolve(args.cwd)] : [],\n\t\twritePaths: args.writePaths.map((entry) =>\n\t\t\tpath.isAbsolute(entry) ? path.resolve(entry) : path.resolve(args.cwd, entry),\n\t\t),\n\t\tdeniedPaths: args.deniedPaths.map((entry) => path.resolve(entry)),\n\t\trequestedBudget: args.budget,\n\t\tauthorityBudget: args.budget,\n\t\tpolicyVersion: \"managed-process-v1\",\n\t});\n\tif (compiled.outcome !== \"allow\") return { ok: false, reasonCodes: compiled.reasonCodes };\n\treturn { ok: true, grant: compiled.grant };\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type AgentBindingContract } from "../orchestration/contracts.ts";
|
|
2
|
+
import type { TaskRuntimeProjection } from "../orchestration/task-runtime.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Process-independent safety ceilings for one durable session fleet. These limits bound persisted
|
|
5
|
+
* identity growth and scheduler fan-out; model/provider budgets remain separately authoritative.
|
|
6
|
+
*/
|
|
7
|
+
export interface WorkerFleetLimits {
|
|
8
|
+
maxDepth: number;
|
|
9
|
+
maxAgentsPerSession: number;
|
|
10
|
+
maxChildrenPerAgent: number;
|
|
11
|
+
maxQueuedDispatches: number;
|
|
12
|
+
}
|
|
13
|
+
export declare const DEFAULT_WORKER_FLEET_LIMITS: Readonly<WorkerFleetLimits>;
|
|
14
|
+
export type NewWorkerAdmission = {
|
|
15
|
+
ok: true;
|
|
16
|
+
depth: number;
|
|
17
|
+
} | {
|
|
18
|
+
ok: false;
|
|
19
|
+
reasonCode: "worker_agent_parent_unknown" | "worker_agent_parent_retired" | "worker_agent_depth_limit_reached" | "worker_agent_child_limit_reached" | "worker_agent_session_limit_reached";
|
|
20
|
+
};
|
|
21
|
+
export type WorkerIdentityHeadroomAdmission = {
|
|
22
|
+
ok: true;
|
|
23
|
+
} | {
|
|
24
|
+
ok: false;
|
|
25
|
+
reasonCode: "worker_agent_session_limit_reached";
|
|
26
|
+
};
|
|
27
|
+
/** Subjects whose admitted verifier identity has not yet been materialized. */
|
|
28
|
+
export declare function pendingVerifierSubjectTaskIds(snapshot: Pick<TaskRuntimeProjection, "agents" | "tasks" | "attempts">): Set<string>;
|
|
29
|
+
/**
|
|
30
|
+
* A persistent-agent turn consumes no implementation identity, but its retained immutable contract
|
|
31
|
+
* can still require a fresh verifier. Protect both that verifier and every earlier reservation.
|
|
32
|
+
*/
|
|
33
|
+
export declare function evaluateReusableWorkerTaskAdmission(snapshot: Pick<TaskRuntimeProjection, "agents" | "tasks" | "attempts">, agentId: string, limits?: Readonly<WorkerFleetLimits>): WorkerIdentityHeadroomAdmission;
|
|
34
|
+
/** Evaluate a new durable identity before a task, conversation, or scheduler entry is created. */
|
|
35
|
+
export declare function evaluateNewWorkerAdmission(agents: Readonly<Record<string, AgentBindingContract>>, parentAgentId?: string, limits?: Readonly<WorkerFleetLimits>, requiredAgentSlots?: number): NewWorkerAdmission;
|
|
36
|
+
/** Keep one queue slot reserved for an already-admitted mandatory verifier. */
|
|
37
|
+
export declare function workerQueueHasCapacity(queuedCount: number, priority: boolean, limits?: Readonly<WorkerFleetLimits>): boolean;
|
|
38
|
+
//# sourceMappingURL=worker-fleet-limits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-fleet-limits.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-fleet-limits.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,oBAAoB,EAAoC,MAAM,+BAA+B,CAAC;AAC5G,OAAO,KAAK,EAAuB,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAEnG;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,mBAAmB,EAAE,MAAM,CAAC;CAC5B;AAED,eAAO,MAAM,2BAA2B,EAAE,QAAQ,CAAC,iBAAiB,CAKlE,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAC3B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC3B;IACA,EAAE,EAAE,KAAK,CAAC;IACV,UAAU,EACP,6BAA6B,GAC7B,6BAA6B,GAC7B,kCAAkC,GAClC,kCAAkC,GAClC,oCAAoC,CAAC;CACvC,CAAC;AAEL,MAAM,MAAM,+BAA+B,GACxC;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GACZ;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,UAAU,EAAE,oCAAoC,CAAA;CAAE,CAAC;AAEnE,+EAA+E;AAC/E,wBAAgB,6BAA6B,CAC5C,QAAQ,EAAE,IAAI,CAAC,qBAAqB,EAAE,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAC,GACpE,GAAG,CAAC,MAAM,CAAC,CA0Cb;AAgBD;;;GAGG;AACH,wBAAgB,mCAAmC,CAClD,QAAQ,EAAE,IAAI,CAAC,qBAAqB,EAAE,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAC,EACtE,OAAO,EAAE,MAAM,EACf,MAAM,GAAE,QAAQ,CAAC,iBAAiB,CAA+B,GAC/D,+BAA+B,CAKjC;AAED,kGAAkG;AAClG,wBAAgB,0BAA0B,CACzC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC,EACtD,aAAa,CAAC,EAAE,MAAM,EACtB,MAAM,GAAE,QAAQ,CAAC,iBAAiB,CAA+B,EACjE,kBAAkB,SAAI,GACpB,kBAAkB,CAoBpB;AAED,+EAA+E;AAC/E,wBAAgB,sBAAsB,CACrC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,OAAO,EACjB,MAAM,GAAE,QAAQ,CAAC,iBAAiB,CAA+B,GAC/D,OAAO,CAIT"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { latestAgentAttemptByDurableOrder } from "../orchestration/attempt-ordering.js";
|
|
2
|
+
import { MAX_ORCHESTRATION_AGENT_BINDINGS } from "../orchestration/contracts.js";
|
|
3
|
+
export const DEFAULT_WORKER_FLEET_LIMITS = Object.freeze({
|
|
4
|
+
maxDepth: 8,
|
|
5
|
+
maxAgentsPerSession: MAX_ORCHESTRATION_AGENT_BINDINGS,
|
|
6
|
+
maxChildrenPerAgent: 64,
|
|
7
|
+
maxQueuedDispatches: 256,
|
|
8
|
+
});
|
|
9
|
+
/** Subjects whose admitted verifier identity has not yet been materialized. */
|
|
10
|
+
export function pendingVerifierSubjectTaskIds(snapshot) {
|
|
11
|
+
const agents = snapshot.agents ?? {};
|
|
12
|
+
const tasks = snapshot.tasks ?? {};
|
|
13
|
+
const attempts = snapshot.attempts ?? {};
|
|
14
|
+
const pending = new Set();
|
|
15
|
+
for (const taskId in tasks) {
|
|
16
|
+
if (!Object.hasOwn(tasks, taskId))
|
|
17
|
+
continue;
|
|
18
|
+
const subject = tasks[taskId];
|
|
19
|
+
if (!subject || subject.verification)
|
|
20
|
+
continue;
|
|
21
|
+
let attempt;
|
|
22
|
+
for (let index = subject.attemptIds.length - 1; index >= 0; index -= 1) {
|
|
23
|
+
attempt = attempts[subject.attemptIds[index]];
|
|
24
|
+
if (attempt)
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
if (!attempt?.dispatch.executionContract?.verifier)
|
|
28
|
+
continue;
|
|
29
|
+
if (attempt.status === "queued" ||
|
|
30
|
+
attempt.status === "leased" ||
|
|
31
|
+
attempt.status === "running" ||
|
|
32
|
+
attempt.status === "suspended" ||
|
|
33
|
+
attempt.result?.nextAction === "independent_verification_required") {
|
|
34
|
+
pending.add(subject.task.taskId);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (pending.size === 0)
|
|
38
|
+
return pending;
|
|
39
|
+
for (const taskId in tasks) {
|
|
40
|
+
if (!Object.hasOwn(tasks, taskId))
|
|
41
|
+
continue;
|
|
42
|
+
const verifierTask = tasks[taskId];
|
|
43
|
+
const verificationOfTaskId = verifierTask?.task.verificationOfTaskId;
|
|
44
|
+
if (!verifierTask || !verificationOfTaskId || !pending.has(verificationOfTaskId))
|
|
45
|
+
continue;
|
|
46
|
+
let verifierAttempt;
|
|
47
|
+
for (let index = verifierTask.attemptIds.length - 1; index >= 0; index -= 1) {
|
|
48
|
+
verifierAttempt = attempts[verifierTask.attemptIds[index]];
|
|
49
|
+
if (verifierAttempt)
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
const verifierAgentId = verifierAttempt?.agentId ?? verifierAttempt?.dispatch.logicalLaneId ?? verifierTask.task.taskId;
|
|
53
|
+
if (agents[verifierAgentId])
|
|
54
|
+
pending.delete(verificationOfTaskId);
|
|
55
|
+
if (pending.size === 0)
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
return pending;
|
|
59
|
+
}
|
|
60
|
+
/** Reserve durable identity slots without applying parent depth or direct-child limits. */
|
|
61
|
+
function evaluateWorkerIdentityHeadroom(agents, requiredAgentSlots, limits = DEFAULT_WORKER_FLEET_LIMITS) {
|
|
62
|
+
if (!Number.isSafeInteger(requiredAgentSlots) || requiredAgentSlots < 0) {
|
|
63
|
+
throw new TypeError("requiredAgentSlots must be a non-negative safe integer.");
|
|
64
|
+
}
|
|
65
|
+
return requiredAgentSlots > limits.maxAgentsPerSession - Object.keys(agents).length
|
|
66
|
+
? { ok: false, reasonCode: "worker_agent_session_limit_reached" }
|
|
67
|
+
: { ok: true };
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A persistent-agent turn consumes no implementation identity, but its retained immutable contract
|
|
71
|
+
* can still require a fresh verifier. Protect both that verifier and every earlier reservation.
|
|
72
|
+
*/
|
|
73
|
+
export function evaluateReusableWorkerTaskAdmission(snapshot, agentId, limits = DEFAULT_WORKER_FLEET_LIMITS) {
|
|
74
|
+
const latestAttempt = latestAgentAttemptByDurableOrder(snapshot, agentId);
|
|
75
|
+
const requiredAgentSlots = pendingVerifierSubjectTaskIds(snapshot).size + (latestAttempt?.dispatch.executionContract?.verifier ? 1 : 0);
|
|
76
|
+
return evaluateWorkerIdentityHeadroom(snapshot.agents, requiredAgentSlots, limits);
|
|
77
|
+
}
|
|
78
|
+
/** Evaluate a new durable identity before a task, conversation, or scheduler entry is created. */
|
|
79
|
+
export function evaluateNewWorkerAdmission(agents, parentAgentId, limits = DEFAULT_WORKER_FLEET_LIMITS, requiredAgentSlots = 1) {
|
|
80
|
+
if (!Number.isSafeInteger(requiredAgentSlots) || requiredAgentSlots < 1) {
|
|
81
|
+
throw new TypeError("requiredAgentSlots must be a positive safe integer.");
|
|
82
|
+
}
|
|
83
|
+
const headroom = evaluateWorkerIdentityHeadroom(agents, requiredAgentSlots, limits);
|
|
84
|
+
if (!headroom.ok)
|
|
85
|
+
return headroom;
|
|
86
|
+
if (!parentAgentId)
|
|
87
|
+
return { ok: true, depth: 0 };
|
|
88
|
+
const parent = agents[parentAgentId];
|
|
89
|
+
if (!parent)
|
|
90
|
+
return { ok: false, reasonCode: "worker_agent_parent_unknown" };
|
|
91
|
+
if (parent.status === "retired")
|
|
92
|
+
return { ok: false, reasonCode: "worker_agent_parent_retired" };
|
|
93
|
+
const depth = parent.depth + 1;
|
|
94
|
+
if (depth > limits.maxDepth)
|
|
95
|
+
return { ok: false, reasonCode: "worker_agent_depth_limit_reached" };
|
|
96
|
+
let directChildren = 0;
|
|
97
|
+
for (const agent of Object.values(agents)) {
|
|
98
|
+
if (agent.parentAgentId === parent.agentId)
|
|
99
|
+
directChildren += 1;
|
|
100
|
+
}
|
|
101
|
+
if (directChildren >= limits.maxChildrenPerAgent) {
|
|
102
|
+
return { ok: false, reasonCode: "worker_agent_child_limit_reached" };
|
|
103
|
+
}
|
|
104
|
+
return { ok: true, depth };
|
|
105
|
+
}
|
|
106
|
+
/** Keep one queue slot reserved for an already-admitted mandatory verifier. */
|
|
107
|
+
export function workerQueueHasCapacity(queuedCount, priority, limits = DEFAULT_WORKER_FLEET_LIMITS) {
|
|
108
|
+
if (!Number.isSafeInteger(queuedCount) || queuedCount < 0)
|
|
109
|
+
return false;
|
|
110
|
+
const ceiling = priority ? limits.maxQueuedDispatches : limits.maxQueuedDispatches - 1;
|
|
111
|
+
return queuedCount < ceiling;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=worker-fleet-limits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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C5B,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,sBAAsB,CACrC,WAAmB,EACnB,QAAiB,EACjB,MAAM,GAAgC,2BAA2B;IAEjE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,WAAW,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IACxE,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,MAAM,CAAC,mBAAmB,GAAG,CAAC,CAAC;IACvF,OAAO,WAAW,GAAG,OAAO,CAAC;AAC9B,CAAC","sourcesContent":["import { latestAgentAttemptByDurableOrder } from \"../orchestration/attempt-ordering.ts\";\nimport { type AgentBindingContract, MAX_ORCHESTRATION_AGENT_BINDINGS } from \"../orchestration/contracts.ts\";\nimport type { AttemptRuntimeState, TaskRuntimeProjection } from \"../orchestration/task-runtime.ts\";\n\n/**\n * Process-independent safety ceilings for one durable session fleet. These limits bound persisted\n * identity growth and scheduler fan-out; model/provider budgets remain separately authoritative.\n */\nexport interface WorkerFleetLimits {\n\tmaxDepth: number;\n\tmaxAgentsPerSession: number;\n\tmaxChildrenPerAgent: number;\n\tmaxQueuedDispatches: number;\n}\n\nexport const DEFAULT_WORKER_FLEET_LIMITS: Readonly<WorkerFleetLimits> = Object.freeze({\n\tmaxDepth: 8,\n\tmaxAgentsPerSession: MAX_ORCHESTRATION_AGENT_BINDINGS,\n\tmaxChildrenPerAgent: 64,\n\tmaxQueuedDispatches: 256,\n});\n\nexport type NewWorkerAdmission =\n\t| { ok: true; depth: number }\n\t| {\n\t\t\tok: false;\n\t\t\treasonCode:\n\t\t\t\t| \"worker_agent_parent_unknown\"\n\t\t\t\t| \"worker_agent_parent_retired\"\n\t\t\t\t| \"worker_agent_depth_limit_reached\"\n\t\t\t\t| \"worker_agent_child_limit_reached\"\n\t\t\t\t| \"worker_agent_session_limit_reached\";\n\t };\n\nexport type WorkerIdentityHeadroomAdmission =\n\t| { ok: true }\n\t| { ok: false; reasonCode: \"worker_agent_session_limit_reached\" };\n\n/** Subjects whose admitted verifier identity has not yet been materialized. */\nexport function pendingVerifierSubjectTaskIds(\n\tsnapshot: Pick<TaskRuntimeProjection, \"agents\" | \"tasks\" | \"attempts\">,\n): Set<string> {\n\tconst agents = snapshot.agents ?? {};\n\tconst tasks = snapshot.tasks ?? {};\n\tconst attempts = snapshot.attempts ?? {};\n\tconst pending = new Set<string>();\n\tfor (const taskId in tasks) {\n\t\tif (!Object.hasOwn(tasks, taskId)) continue;\n\t\tconst subject = tasks[taskId];\n\t\tif (!subject || subject.verification) continue;\n\t\tlet attempt: AttemptRuntimeState | undefined;\n\t\tfor (let index = subject.attemptIds.length - 1; index >= 0; index -= 1) {\n\t\t\tattempt = attempts[subject.attemptIds[index]!];\n\t\t\tif (attempt) break;\n\t\t}\n\t\tif (!attempt?.dispatch.executionContract?.verifier) continue;\n\t\tif (\n\t\t\tattempt.status === \"queued\" ||\n\t\t\tattempt.status === \"leased\" ||\n\t\t\tattempt.status === \"running\" ||\n\t\t\tattempt.status === \"suspended\" ||\n\t\t\tattempt.result?.nextAction === \"independent_verification_required\"\n\t\t) {\n\t\t\tpending.add(subject.task.taskId);\n\t\t}\n\t}\n\tif (pending.size === 0) return pending;\n\tfor (const taskId in tasks) {\n\t\tif (!Object.hasOwn(tasks, taskId)) continue;\n\t\tconst verifierTask = tasks[taskId];\n\t\tconst verificationOfTaskId = verifierTask?.task.verificationOfTaskId;\n\t\tif (!verifierTask || !verificationOfTaskId || !pending.has(verificationOfTaskId)) continue;\n\t\tlet verifierAttempt: AttemptRuntimeState | undefined;\n\t\tfor (let index = verifierTask.attemptIds.length - 1; index >= 0; index -= 1) {\n\t\t\tverifierAttempt = attempts[verifierTask.attemptIds[index]!];\n\t\t\tif (verifierAttempt) break;\n\t\t}\n\t\tconst verifierAgentId =\n\t\t\tverifierAttempt?.agentId ?? verifierAttempt?.dispatch.logicalLaneId ?? verifierTask.task.taskId;\n\t\tif (agents[verifierAgentId]) pending.delete(verificationOfTaskId);\n\t\tif (pending.size === 0) break;\n\t}\n\treturn pending;\n}\n\n/** Reserve durable identity slots without applying parent depth or direct-child limits. */\nfunction evaluateWorkerIdentityHeadroom(\n\tagents: Readonly<Record<string, AgentBindingContract>>,\n\trequiredAgentSlots: number,\n\tlimits: Readonly<WorkerFleetLimits> = DEFAULT_WORKER_FLEET_LIMITS,\n): WorkerIdentityHeadroomAdmission {\n\tif (!Number.isSafeInteger(requiredAgentSlots) || requiredAgentSlots < 0) {\n\t\tthrow new TypeError(\"requiredAgentSlots must be a non-negative safe integer.\");\n\t}\n\treturn requiredAgentSlots > limits.maxAgentsPerSession - Object.keys(agents).length\n\t\t? { ok: false, reasonCode: \"worker_agent_session_limit_reached\" }\n\t\t: { ok: true };\n}\n\n/**\n * A persistent-agent turn consumes no implementation identity, but its retained immutable contract\n * can still require a fresh verifier. Protect both that verifier and every earlier reservation.\n */\nexport function evaluateReusableWorkerTaskAdmission(\n\tsnapshot: Pick<TaskRuntimeProjection, \"agents\" | \"tasks\" | \"attempts\">,\n\tagentId: string,\n\tlimits: Readonly<WorkerFleetLimits> = DEFAULT_WORKER_FLEET_LIMITS,\n): WorkerIdentityHeadroomAdmission {\n\tconst latestAttempt = latestAgentAttemptByDurableOrder(snapshot, agentId);\n\tconst requiredAgentSlots =\n\t\tpendingVerifierSubjectTaskIds(snapshot).size + (latestAttempt?.dispatch.executionContract?.verifier ? 1 : 0);\n\treturn evaluateWorkerIdentityHeadroom(snapshot.agents, requiredAgentSlots, limits);\n}\n\n/** Evaluate a new durable identity before a task, conversation, or scheduler entry is created. */\nexport function evaluateNewWorkerAdmission(\n\tagents: Readonly<Record<string, AgentBindingContract>>,\n\tparentAgentId?: string,\n\tlimits: Readonly<WorkerFleetLimits> = DEFAULT_WORKER_FLEET_LIMITS,\n\trequiredAgentSlots = 1,\n): NewWorkerAdmission {\n\tif (!Number.isSafeInteger(requiredAgentSlots) || requiredAgentSlots < 1) {\n\t\tthrow new TypeError(\"requiredAgentSlots must be a positive safe integer.\");\n\t}\n\tconst headroom = evaluateWorkerIdentityHeadroom(agents, requiredAgentSlots, limits);\n\tif (!headroom.ok) return headroom;\n\tif (!parentAgentId) return { ok: true, depth: 0 };\n\tconst parent = agents[parentAgentId];\n\tif (!parent) return { ok: false, reasonCode: \"worker_agent_parent_unknown\" };\n\tif (parent.status === \"retired\") return { ok: false, reasonCode: \"worker_agent_parent_retired\" };\n\tconst depth = parent.depth + 1;\n\tif (depth > limits.maxDepth) return { ok: false, reasonCode: \"worker_agent_depth_limit_reached\" };\n\tlet directChildren = 0;\n\tfor (const agent of Object.values(agents)) {\n\t\tif (agent.parentAgentId === parent.agentId) directChildren += 1;\n\t}\n\tif (directChildren >= limits.maxChildrenPerAgent) {\n\t\treturn { ok: false, reasonCode: \"worker_agent_child_limit_reached\" };\n\t}\n\treturn { ok: true, depth };\n}\n\n/** Keep one queue slot reserved for an already-admitted mandatory verifier. */\nexport function workerQueueHasCapacity(\n\tqueuedCount: number,\n\tpriority: boolean,\n\tlimits: Readonly<WorkerFleetLimits> = DEFAULT_WORKER_FLEET_LIMITS,\n): boolean {\n\tif (!Number.isSafeInteger(queuedCount) || queuedCount < 0) return false;\n\tconst ceiling = priority ? limits.maxQueuedDispatches : limits.maxQueuedDispatches - 1;\n\treturn queuedCount < ceiling;\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { LaneRecord } from "../autonomy/lane-tracker.ts";
|
|
2
2
|
import type { AttemptRuntimeState, TaskRuntimeProjection } from "../orchestration/task-runtime.ts";
|
|
3
3
|
export declare const ACTIVE_WORKER_ATTEMPT_STATUSES: ReadonlySet<string>;
|
|
4
|
+
export declare const NONTERMINAL_WORKER_ATTEMPT_STATUSES: ReadonlySet<string>;
|
|
4
5
|
export declare function isManagedWorkerAttempt(attempt: AttemptRuntimeState): boolean;
|
|
5
6
|
export declare function selectedWorkerAttempt(snapshot: TaskRuntimeProjection, taskId: string): AttemptRuntimeState | undefined;
|
|
6
7
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-lane-projection.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-lane-projection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAsB,MAAM,6BAA6B,CAAC;AAClF,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAGnG,eAAO,MAAM,8BAA8B,EAAE,WAAW,CAAC,MAAM,CAA4C,CAAC;
|
|
1
|
+
{"version":3,"file":"worker-lane-projection.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-lane-projection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAsB,MAAM,6BAA6B,CAAC;AAClF,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAGnG,eAAO,MAAM,8BAA8B,EAAE,WAAW,CAAC,MAAM,CAA4C,CAAC;AAC5G,eAAO,MAAM,mCAAmC,EAAE,WAAW,CAAC,MAAM,CAGlE,CAAC;AAEH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAE5E;AAWD,wBAAgB,qBAAqB,CACpC,QAAQ,EAAE,qBAAqB,EAC/B,MAAM,EAAE,MAAM,GACZ,mBAAmB,GAAG,SAAS,CAQjC;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,qBAAqB,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CA2C/G;AAED,oEAAoE;AACpE,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,qBAAqB,GAAG,UAAU,EAAE,CAkB7F;AAED,wBAAgB,4BAA4B,CAC3C,QAAQ,EAAE,qBAAqB,EAC/B,aAAa,EAAE,MAAM,GACnB,mBAAmB,GAAG,SAAS,CAQjC"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { deriveWorkerTaskLabel } from "./worker-task-label.js";
|
|
2
2
|
export const ACTIVE_WORKER_ATTEMPT_STATUSES = new Set(["queued", "leased", "running"]);
|
|
3
|
+
export const NONTERMINAL_WORKER_ATTEMPT_STATUSES = new Set([
|
|
4
|
+
...ACTIVE_WORKER_ATTEMPT_STATUSES,
|
|
5
|
+
"suspended",
|
|
6
|
+
]);
|
|
3
7
|
export function isManagedWorkerAttempt(attempt) {
|
|
4
8
|
return attempt.dispatch.executionKind === "managed-process";
|
|
5
9
|
}
|
|
@@ -20,7 +24,7 @@ export function selectedWorkerAttempt(snapshot, taskId) {
|
|
|
20
24
|
if (!task)
|
|
21
25
|
return undefined;
|
|
22
26
|
const attempts = task.attemptIds.map((attemptId) => snapshot.attempts[attemptId]).filter(Boolean);
|
|
23
|
-
return ([...attempts].reverse().find((attempt) => attempt &&
|
|
27
|
+
return ([...attempts].reverse().find((attempt) => attempt && NONTERMINAL_WORKER_ATTEMPT_STATUSES.has(attempt.status)) ??
|
|
24
28
|
attempts.at(-1));
|
|
25
29
|
}
|
|
26
30
|
/**
|
|
@@ -43,7 +47,7 @@ export function projectWorkerLaneRecord(snapshot, taskId) {
|
|
|
43
47
|
: "failed"
|
|
44
48
|
: attempt.status === "queued"
|
|
45
49
|
? "queued"
|
|
46
|
-
: attempt.status === "leased" || attempt.status === "running"
|
|
50
|
+
: attempt.status === "leased" || attempt.status === "running" || attempt.status === "suspended"
|
|
47
51
|
? "running"
|
|
48
52
|
: terminalStatus(attempt);
|
|
49
53
|
const reasonCode = task.verification?.reasonCode ?? attempt.result?.reasonCode ?? attempt.reasonCode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-lane-projection.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-lane-projection.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,MAAM,CAAC,MAAM,8BAA8B,GAAwB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G,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,4BAA4B,CAC3C,QAA+B,EAC/B,aAAqB;IAErB,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;SACrC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,sBAAsB,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,aAAa,KAAK,aAAa,CAAC;SACxG,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACrB,MAAM,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,gBAAgB,IAAI,CAAC,CAAC,CAAC;QAChG,OAAO,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAClF,CAAC,CAAC;SACD,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AACV,CAAC","sourcesContent":["import type { LaneRecord, LaneTerminalStatus } from \"../autonomy/lane-tracker.ts\";\nimport type { AttemptRuntimeState, TaskRuntimeProjection } from \"../orchestration/task-runtime.ts\";\nimport { deriveWorkerTaskLabel } from \"./worker-task-label.ts\";\n\nexport const ACTIVE_WORKER_ATTEMPT_STATUSES: ReadonlySet<string> = new Set([\"queued\", \"leased\", \"running\"]);\n\nexport function isManagedWorkerAttempt(attempt: AttemptRuntimeState): boolean {\n\treturn attempt.dispatch.executionKind === \"managed-process\";\n}\n\nfunction terminalStatus(attempt: AttemptRuntimeState): LaneTerminalStatus {\n\tif (attempt.status === \"completed\") return \"succeeded\";\n\tif (attempt.status === \"cancelled\") return \"canceled\";\n\tconst reasonCode = attempt.result?.reasonCode ?? attempt.reasonCode ?? \"\";\n\tif (reasonCode.includes(\"budget\")) return \"budget_exhausted\";\n\tif (reasonCode.includes(\"timeout\")) return \"timeout\";\n\treturn \"failed\";\n}\n\nexport function selectedWorkerAttempt(\n\tsnapshot: TaskRuntimeProjection,\n\ttaskId: string,\n): AttemptRuntimeState | undefined {\n\tconst task = snapshot.tasks[taskId];\n\tif (!task) return undefined;\n\tconst attempts = task.attemptIds.map((attemptId) => snapshot.attempts[attemptId]).filter(Boolean);\n\treturn (\n\t\t[...attempts].reverse().find((attempt) => attempt && ACTIVE_WORKER_ATTEMPT_STATUSES.has(attempt.status)) ??\n\t\tattempts.at(-1)\n\t);\n}\n\n/**\n * One-way compatibility projection from durable orchestration state. A LaneRecord is never read\n * back to decide lifecycle, retry, verification, or notification transitions.\n */\nexport function projectWorkerLaneRecord(snapshot: TaskRuntimeProjection, taskId: string): LaneRecord | undefined {\n\tconst task = snapshot.tasks[taskId];\n\tconst attempt = selectedWorkerAttempt(snapshot, taskId);\n\tif (!task || !attempt) return undefined;\n\tconst managed = isManagedWorkerAttempt(attempt);\n\tconst objective = snapshot.objectives[task.task.objectiveId];\n\tconst awaitingVerification =\n\t\tattempt.result?.nextAction === \"independent_verification_required\" && task.verification === undefined;\n\tconst status = awaitingVerification\n\t\t? \"running\"\n\t\t: task.verification\n\t\t\t? task.verification.verdict === \"accepted\"\n\t\t\t\t? \"succeeded\"\n\t\t\t\t: \"failed\"\n\t\t\t: attempt.status === \"queued\"\n\t\t\t\t? \"queued\"\n\t\t\t\t: attempt.status === \"leased\" || attempt.status === \"running\"\n\t\t\t\t\t? \"running\"\n\t\t\t\t\t: terminalStatus(attempt);\n\tconst reasonCode = task.verification?.reasonCode ?? attempt.result?.reasonCode ?? attempt.reasonCode;\n\tconst genericTitle = `Delegated ${task.task.role} work`;\n\tconst label = deriveWorkerTaskLabel(\n\t\ttask.task.title === genericTitle ? task.task.description : task.task.title,\n\t\tgenericTitle,\n\t);\n\tconst goalId = objective?.objective.objectiveId.startsWith(\"goal:\")\n\t\t? objective.objective.objectiveId.slice(\"goal:\".length)\n\t\t: undefined;\n\treturn {\n\t\tlaneId: managed ? (attempt.dispatch.logicalLaneId ?? taskId) : taskId,\n\t\ttype: managed ? \"tmux-worker\" : \"worker\",\n\t\tstatus,\n\t\tlabel,\n\t\tprofileId: attempt.dispatch.profileId,\n\t\t...(reasonCode ? { reasonCode } : {}),\n\t\t...(attempt.status !== \"queued\" ? { startedAt: attempt.createdAt } : {}),\n\t\t...(status === \"queued\" || status === \"running\"\n\t\t\t? {}\n\t\t\t: { completedAt: task.verification?.completedAt ?? attempt.updatedAt }),\n\t\t...(attempt.result?.usage.costUsd !== undefined ? { costUsd: attempt.result.usage.costUsd } : {}),\n\t\t...(goalId ? { goalId } : {}),\n\t\t...(attempt.dispatch.worktreeLaneKey ? { worktreeLaneKey: attempt.dispatch.worktreeLaneKey } : {}),\n\t};\n}\n\n/** Latest durable turn for each externally managed logical lane. */\nexport function projectManagedWorkerLaneRecords(snapshot: TaskRuntimeProjection): LaneRecord[] {\n\tconst latest = new Map<string, { sequence: number; createdAt: string; record: LaneRecord }>();\n\tfor (const taskId of Object.keys(snapshot.tasks)) {\n\t\tconst attempt = selectedWorkerAttempt(snapshot, taskId);\n\t\tif (!attempt || !isManagedWorkerAttempt(attempt)) continue;\n\t\tconst record = projectWorkerLaneRecord(snapshot, taskId);\n\t\tif (!record) continue;\n\t\tconst sequence = attempt.dispatch.dispatchSequence ?? 1;\n\t\tconst current = latest.get(record.laneId);\n\t\tif (\n\t\t\t!current ||\n\t\t\tsequence > current.sequence ||\n\t\t\t(sequence === current.sequence && attempt.createdAt.localeCompare(current.createdAt) > 0)\n\t\t) {\n\t\t\tlatest.set(record.laneId, { sequence, createdAt: attempt.createdAt, record });\n\t\t}\n\t}\n\treturn [...latest.values()].map((entry) => entry.record);\n}\n\nexport function selectedManagedWorkerAttempt(\n\tsnapshot: TaskRuntimeProjection,\n\tlogicalLaneId: string,\n): AttemptRuntimeState | undefined {\n\treturn Object.values(snapshot.attempts)\n\t\t.filter((attempt) => isManagedWorkerAttempt(attempt) && attempt.dispatch.logicalLaneId === logicalLaneId)\n\t\t.sort((left, right) => {\n\t\t\tconst sequence = (left.dispatch.dispatchSequence ?? 1) - (right.dispatch.dispatchSequence ?? 1);\n\t\t\treturn sequence !== 0 ? sequence : left.createdAt.localeCompare(right.createdAt);\n\t\t})\n\t\t.at(-1);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"worker-lane-projection.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-lane-projection.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,MAAM,CAAC,MAAM,8BAA8B,GAAwB,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;AAC5G,MAAM,CAAC,MAAM,mCAAmC,GAAwB,IAAI,GAAG,CAAC;IAC/E,GAAG,8BAA8B;IACjC,WAAW;CACX,CAAC,CAAC;AAEH,MAAM,UAAU,sBAAsB,CAAC,OAA4B;IAClE,OAAO,OAAO,CAAC,QAAQ,CAAC,aAAa,KAAK,iBAAiB,CAAC;AAC7D,CAAC;AAED,SAAS,cAAc,CAAC,OAA4B;IACnD,IAAI,OAAO,CAAC,MAAM,KAAK,WAAW;QAAE,OAAO,WAAW,CAAC;IACvD,IAAI,OAAO,CAAC,MAAM,KAAK,WAAW;QAAE,OAAO,UAAU,CAAC;IACtD,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,EAAE,UAAU,IAAI,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC;IAC1E,IAAI,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,kBAAkB,CAAC;IAC7D,IAAI,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC;QAAE,OAAO,SAAS,CAAC;IACrD,OAAO,QAAQ,CAAC;AACjB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AAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAClF,CAAC,CAAC;SACD,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AACV,CAAC","sourcesContent":["import type { LaneRecord, LaneTerminalStatus } from \"../autonomy/lane-tracker.ts\";\nimport type { AttemptRuntimeState, TaskRuntimeProjection } from \"../orchestration/task-runtime.ts\";\nimport { deriveWorkerTaskLabel } from \"./worker-task-label.ts\";\n\nexport const ACTIVE_WORKER_ATTEMPT_STATUSES: ReadonlySet<string> = new Set([\"queued\", \"leased\", \"running\"]);\nexport const NONTERMINAL_WORKER_ATTEMPT_STATUSES: ReadonlySet<string> = new Set([\n\t...ACTIVE_WORKER_ATTEMPT_STATUSES,\n\t\"suspended\",\n]);\n\nexport function isManagedWorkerAttempt(attempt: AttemptRuntimeState): boolean {\n\treturn attempt.dispatch.executionKind === \"managed-process\";\n}\n\nfunction terminalStatus(attempt: AttemptRuntimeState): LaneTerminalStatus {\n\tif (attempt.status === \"completed\") return \"succeeded\";\n\tif (attempt.status === \"cancelled\") return \"canceled\";\n\tconst reasonCode = attempt.result?.reasonCode ?? attempt.reasonCode ?? \"\";\n\tif (reasonCode.includes(\"budget\")) return \"budget_exhausted\";\n\tif (reasonCode.includes(\"timeout\")) return \"timeout\";\n\treturn \"failed\";\n}\n\nexport function selectedWorkerAttempt(\n\tsnapshot: TaskRuntimeProjection,\n\ttaskId: string,\n): AttemptRuntimeState | undefined {\n\tconst task = snapshot.tasks[taskId];\n\tif (!task) return undefined;\n\tconst attempts = task.attemptIds.map((attemptId) => snapshot.attempts[attemptId]).filter(Boolean);\n\treturn (\n\t\t[...attempts].reverse().find((attempt) => attempt && NONTERMINAL_WORKER_ATTEMPT_STATUSES.has(attempt.status)) ??\n\t\tattempts.at(-1)\n\t);\n}\n\n/**\n * One-way compatibility projection from durable orchestration state. A LaneRecord is never read\n * back to decide lifecycle, retry, verification, or notification transitions.\n */\nexport function projectWorkerLaneRecord(snapshot: TaskRuntimeProjection, taskId: string): LaneRecord | undefined {\n\tconst task = snapshot.tasks[taskId];\n\tconst attempt = selectedWorkerAttempt(snapshot, taskId);\n\tif (!task || !attempt) return undefined;\n\tconst managed = isManagedWorkerAttempt(attempt);\n\tconst objective = snapshot.objectives[task.task.objectiveId];\n\tconst awaitingVerification =\n\t\tattempt.result?.nextAction === \"independent_verification_required\" && task.verification === undefined;\n\tconst status = awaitingVerification\n\t\t? \"running\"\n\t\t: task.verification\n\t\t\t? task.verification.verdict === \"accepted\"\n\t\t\t\t? \"succeeded\"\n\t\t\t\t: \"failed\"\n\t\t\t: attempt.status === \"queued\"\n\t\t\t\t? \"queued\"\n\t\t\t\t: attempt.status === \"leased\" || attempt.status === \"running\" || attempt.status === \"suspended\"\n\t\t\t\t\t? \"running\"\n\t\t\t\t\t: terminalStatus(attempt);\n\tconst reasonCode = task.verification?.reasonCode ?? attempt.result?.reasonCode ?? attempt.reasonCode;\n\tconst genericTitle = `Delegated ${task.task.role} work`;\n\tconst label = deriveWorkerTaskLabel(\n\t\ttask.task.title === genericTitle ? task.task.description : task.task.title,\n\t\tgenericTitle,\n\t);\n\tconst goalId = objective?.objective.objectiveId.startsWith(\"goal:\")\n\t\t? objective.objective.objectiveId.slice(\"goal:\".length)\n\t\t: undefined;\n\treturn {\n\t\tlaneId: managed ? (attempt.dispatch.logicalLaneId ?? taskId) : taskId,\n\t\ttype: managed ? \"tmux-worker\" : \"worker\",\n\t\tstatus,\n\t\tlabel,\n\t\tprofileId: attempt.dispatch.profileId,\n\t\t...(reasonCode ? { reasonCode } : {}),\n\t\t...(attempt.status !== \"queued\" ? { startedAt: attempt.createdAt } : {}),\n\t\t...(status === \"queued\" || status === \"running\"\n\t\t\t? {}\n\t\t\t: { completedAt: task.verification?.completedAt ?? attempt.updatedAt }),\n\t\t...(attempt.result?.usage.costUsd !== undefined ? { costUsd: attempt.result.usage.costUsd } : {}),\n\t\t...(goalId ? { goalId } : {}),\n\t\t...(attempt.dispatch.worktreeLaneKey ? { worktreeLaneKey: attempt.dispatch.worktreeLaneKey } : {}),\n\t};\n}\n\n/** Latest durable turn for each externally managed logical lane. */\nexport function projectManagedWorkerLaneRecords(snapshot: TaskRuntimeProjection): LaneRecord[] {\n\tconst latest = new Map<string, { sequence: number; createdAt: string; record: LaneRecord }>();\n\tfor (const taskId of Object.keys(snapshot.tasks)) {\n\t\tconst attempt = selectedWorkerAttempt(snapshot, taskId);\n\t\tif (!attempt || !isManagedWorkerAttempt(attempt)) continue;\n\t\tconst record = projectWorkerLaneRecord(snapshot, taskId);\n\t\tif (!record) continue;\n\t\tconst sequence = attempt.dispatch.dispatchSequence ?? 1;\n\t\tconst current = latest.get(record.laneId);\n\t\tif (\n\t\t\t!current ||\n\t\t\tsequence > current.sequence ||\n\t\t\t(sequence === current.sequence && attempt.createdAt.localeCompare(current.createdAt) > 0)\n\t\t) {\n\t\t\tlatest.set(record.laneId, { sequence, createdAt: attempt.createdAt, record });\n\t\t}\n\t}\n\treturn [...latest.values()].map((entry) => entry.record);\n}\n\nexport function selectedManagedWorkerAttempt(\n\tsnapshot: TaskRuntimeProjection,\n\tlogicalLaneId: string,\n): AttemptRuntimeState | undefined {\n\treturn Object.values(snapshot.attempts)\n\t\t.filter((attempt) => isManagedWorkerAttempt(attempt) && attempt.dispatch.logicalLaneId === logicalLaneId)\n\t\t.sort((left, right) => {\n\t\t\tconst sequence = (left.dispatch.dispatchSequence ?? 1) - (right.dispatch.dispatchSequence ?? 1);\n\t\t\treturn sequence !== 0 ? sequence : left.createdAt.localeCompare(right.createdAt);\n\t\t})\n\t\t.at(-1);\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { LaneRecord } from "../autonomy/lane-tracker.ts";
|
|
2
2
|
import type { GoalState } from "../goals/goal-state.ts";
|
|
3
|
-
import type { AgentBindingContract, AgentResumeContext, AttemptUsageSnapshot, ExecutionGrant, WorkerExecutionContract, WorkerResultContract, WorkerRole } from "../orchestration/contracts.ts";
|
|
3
|
+
import type { AgentBindingContract, AgentResumeContext, AttemptRetryState, AttemptUsageSnapshot, ExecutionGrant, WorkerExecutionContract, WorkerResultContract, WorkerRole } from "../orchestration/contracts.ts";
|
|
4
4
|
import { DelegationOrchestrationLedger, type PrepareDelegationInput, type PrepareManagedDelegationInput, type StartedDelegationAttempt } from "../orchestration/delegation-ledger.ts";
|
|
5
|
-
import type { AttemptRuntimeState, TaskRuntimeProjection } from "../orchestration/task-runtime.ts";
|
|
5
|
+
import type { AttemptDispatchReadiness, AttemptRuntimeState, TaskRuntimeProjection } from "../orchestration/task-runtime.ts";
|
|
6
6
|
export type PendingVerificationRecovery = {
|
|
7
7
|
action: "dispatch";
|
|
8
8
|
subjectTaskId: string;
|
|
@@ -30,15 +30,20 @@ export declare class WorkerLifecycle {
|
|
|
30
30
|
agentDir: string;
|
|
31
31
|
sessionId: string;
|
|
32
32
|
isProcessAlive?: (pid: number) => boolean;
|
|
33
|
+
now?: () => number;
|
|
33
34
|
});
|
|
34
35
|
prepare(input: Omit<PrepareDelegationInput, "laneId">, laneId?: string): {
|
|
35
36
|
record: LaneRecord;
|
|
36
37
|
attempt: AttemptRuntimeState;
|
|
37
38
|
};
|
|
39
|
+
/** Return the next generated lane id without reserving it or changing lifecycle state. */
|
|
40
|
+
getNextAvailableLaneIdCandidate(): string;
|
|
38
41
|
/** Queue the next distinct task/attempt for an idle logical agent. */
|
|
39
42
|
prepareAgentTurn(input: {
|
|
40
43
|
agentId: string;
|
|
41
44
|
instructions: string;
|
|
45
|
+
controlMessageId?: string;
|
|
46
|
+
dependsOnTaskIds?: readonly string[];
|
|
42
47
|
}): {
|
|
43
48
|
record: LaneRecord;
|
|
44
49
|
attempt: AttemptRuntimeState;
|
|
@@ -49,6 +54,8 @@ export declare class WorkerLifecycle {
|
|
|
49
54
|
role: WorkerRole;
|
|
50
55
|
resumeContext: AgentResumeContext;
|
|
51
56
|
}): AgentBindingContract;
|
|
57
|
+
/** Retire one idle logical worker while retaining its durable binding and transcript identity. */
|
|
58
|
+
retireAgent(agentId: string): AgentBindingContract;
|
|
52
59
|
prepareManaged(input: PrepareManagedDelegationInput & {
|
|
53
60
|
leaseTtlMs: number;
|
|
54
61
|
compileGrant(target: {
|
|
@@ -86,9 +93,17 @@ export declare class WorkerLifecycle {
|
|
|
86
93
|
leaseId: string;
|
|
87
94
|
fencingToken: number;
|
|
88
95
|
reasonCode: string;
|
|
96
|
+
retry?: AttemptRetryState;
|
|
89
97
|
}): void;
|
|
90
98
|
resumeAgent(laneId: string, agentId: string, leaseTtlMs: number, ownerId?: string): StartedDelegationAttempt;
|
|
91
|
-
suspendAgent(laneId: string, agentId: string, ownerId: string, reasonCode?: string): void;
|
|
99
|
+
suspendAgent(laneId: string, agentId: string, ownerId: string, reasonCode?: string, retry?: AttemptRetryState): void;
|
|
100
|
+
scheduleAgentRetry(args: {
|
|
101
|
+
laneId: string;
|
|
102
|
+
agentId: string;
|
|
103
|
+
ownerId: string;
|
|
104
|
+
reasonCode: string;
|
|
105
|
+
retry: AttemptRetryState;
|
|
106
|
+
}): AttemptRuntimeState;
|
|
92
107
|
bindGrant(attemptId: string, grant: ExecutionGrant): void;
|
|
93
108
|
finish(result: WorkerResultContract, options?: {
|
|
94
109
|
notify?: boolean;
|
|
@@ -112,6 +127,8 @@ export declare class WorkerLifecycle {
|
|
|
112
127
|
getAgent(agentId: string): AgentBindingContract | undefined;
|
|
113
128
|
getLatestAgentAttempt(agentId: string): AttemptRuntimeState | undefined;
|
|
114
129
|
getTaskRuntimeSnapshot(): TaskRuntimeProjection;
|
|
130
|
+
/** Read-only dispatch gate for an already persisted queued worker attempt. */
|
|
131
|
+
getAttemptDispatchReadiness(attemptId: string): AttemptDispatchReadiness;
|
|
115
132
|
getRecords(): LaneRecord[];
|
|
116
133
|
getManagedRecords(): LaneRecord[];
|
|
117
134
|
getAllRecords(): LaneRecord[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-lifecycle.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"worker-lifecycle.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAGxD,OAAO,KAAK,EACX,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,uBAAuB,EACvB,oBAAoB,EACpB,UAAU,EACV,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACN,6BAA6B,EAC7B,KAAK,sBAAsB,EAC3B,KAAK,6BAA6B,EAClC,KAAK,wBAAwB,EAC7B,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EACX,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACrB,MAAM,kCAAkC,CAAC;AAa1C,MAAM,MAAM,2BAA2B,GACpC;IACA,MAAM,EAAE,UAAU,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,uBAAuB,EAAE,MAAM,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,yBAAyB,CAAC,EAAE,uBAAuB,CAAC;CACnD,GACD;IACA,MAAM,EAAE,WAAW,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,UAAU,GAAG,UAAU,GAAG,cAAc,CAAC;IACl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