@sema-agent/core 7.68.7 → 7.69.1
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 +2139 -0
- package/dist/agents/agent-definition.d.ts +32 -3
- package/dist/agents/agent-definition.js +39 -1
- package/dist/agents/agent-transcript-tool.js +16 -5
- package/dist/agents/cascade.js +9 -6
- package/dist/agents/cc-uds-peer-channel.js +2 -1
- package/dist/agents/cumulative-stats.d.ts +3 -1
- package/dist/agents/cumulative-stats.js +4 -1
- package/dist/agents/delegation-review-faces.d.ts +35 -0
- package/dist/agents/delegation-review-faces.js +26 -0
- package/dist/agents/inherited-tool-pool.d.ts +4 -2
- package/dist/agents/list-agents-tool.d.ts +8 -19
- package/dist/agents/list-agents-tool.js +19 -34
- package/dist/agents/peer-directory.js +3 -2
- package/dist/agents/peer-session-drain.js +3 -3
- package/dist/agents/repair-loop.js +17 -21
- package/dist/agents/retain-ledger.d.ts +122 -58
- package/dist/agents/retain-ledger.js +48 -21
- package/dist/agents/root-session-lane.d.ts +17 -0
- package/dist/agents/root-session-lane.js +9 -0
- package/dist/agents/send-message-tool.js +44 -31
- package/dist/agents/subagent-steps.d.ts +0 -11
- package/dist/agents/subagent-steps.js +1 -14
- package/dist/agents/subagent-transcript-placement.d.ts +4 -3
- package/dist/agents/subagent.d.ts +19 -8
- package/dist/agents/subagent.js +252 -208
- package/dist/agents/tool-filter.d.ts +31 -1
- package/dist/agents/tool-filter.js +28 -4
- package/dist/agents/verifier-independence.js +3 -2
- package/dist/agents/verify.d.ts +6 -2
- package/dist/agents/verify.js +17 -7
- package/dist/agents/yield-adoption.d.ts +17 -0
- package/dist/agents/yield-adoption.js +22 -2
- package/dist/brain/anthropic.js +42 -14
- package/dist/brain/claude-model-id.d.ts +36 -0
- package/dist/brain/claude-model-id.js +44 -0
- package/dist/brain/failover.js +14 -3
- package/dist/brain/fast-mode.d.ts +272 -0
- package/dist/brain/fast-mode.js +130 -0
- package/dist/brain/media-degrade.d.ts +5 -0
- package/dist/brain/media-degrade.js +1 -0
- package/dist/brain/model-capability.d.ts +122 -18
- package/dist/brain/model-capability.js +84 -7
- package/dist/brain/model-lane.d.ts +40 -16
- package/dist/brain/model-lane.js +97 -39
- package/dist/brain/model-presets.d.ts +4 -1
- package/dist/brain/model-presets.js +10 -1
- package/dist/brain/open-responses.js +37 -14
- package/dist/brain/openai.js +27 -15
- package/dist/brain/provider-dialect.d.ts +9 -0
- package/dist/brain/provider-dialect.js +4 -0
- package/dist/brain/provider-message.d.ts +2 -2
- package/dist/brain/provider-message.js +8 -8
- package/dist/brain/reasoning-request.d.ts +26 -0
- package/dist/brain/reasoning-request.js +14 -4
- package/dist/brain/reasoning-stamp.d.ts +3 -2
- package/dist/brain/reasoning.d.ts +8 -4
- package/dist/brain/reasoning.js +4 -3
- package/dist/brain/reference-model-traits.d.ts +59 -0
- package/dist/brain/reference-model-traits.js +46 -0
- package/dist/brain/request-params.js +1 -0
- package/dist/brain/route-adjudicator.d.ts +107 -106
- package/dist/brain/route-adjudicator.js +217 -51
- package/dist/brain/route-conformance.d.ts +6 -4
- package/dist/brain/routing.d.ts +2 -1
- package/dist/brain/routing.js +21 -5
- package/dist/brain/status-sink.d.ts +52 -10
- package/dist/brain/stream-engine.d.ts +68 -11
- package/dist/brain/stream-engine.js +512 -93
- package/dist/brain/stream-shared.d.ts +34 -8
- package/dist/brain/stream-shared.js +20 -7
- package/dist/brain/usage-reading.d.ts +15 -0
- package/dist/brain/usage-reading.js +18 -5
- package/dist/core/a2a.js +28 -21
- package/dist/core/advisor-verdict.d.ts +5 -4
- package/dist/core/advisor-verdict.js +2 -2
- package/dist/core/agent-config-dir.d.ts +39 -3
- package/dist/core/agent-config-dir.js +67 -11
- package/dist/core/agent-definition.d.ts +4 -1
- package/dist/core/agent-state.d.ts +25 -2
- package/dist/core/agent-state.js +50 -3
- package/dist/core/allow-entry.d.ts +11 -11
- package/dist/core/allow-entry.js +39 -32
- package/dist/core/ask-headline.d.ts +28 -16
- package/dist/core/ask-headline.js +18 -8
- package/dist/core/ask-origin.d.ts +108 -33
- package/dist/core/ask-origin.js +40 -11
- package/dist/core/ask-question.d.ts +9 -1
- package/dist/core/ask-question.js +3 -0
- package/dist/core/ask-unresolvable-notice.d.ts +10 -2
- package/dist/core/ask-unresolvable-notice.js +5 -2
- package/dist/core/attachment-source.d.ts +1 -1
- package/dist/core/attachment-source.js +2 -0
- package/dist/core/auto-compaction.d.ts +48 -66
- package/dist/core/auto-compaction.js +48 -106
- package/dist/core/auto-mode-directive.d.ts +30 -60
- package/dist/core/auto-mode-directive.js +36 -38
- package/dist/core/auto-mode.d.ts +40 -9
- package/dist/core/auto-mode.js +20 -5
- package/dist/core/background-agent-store.d.ts +87 -1
- package/dist/core/background-agent-store.js +72 -1
- package/dist/core/background-shell.d.ts +3 -0
- package/dist/core/background-shell.js +1 -0
- package/dist/core/cache-break-detector.d.ts +23 -11
- package/dist/core/cache-break-detector.js +12 -6
- package/dist/core/caller-text.d.ts +27 -8
- package/dist/core/caller-text.js +47 -1
- package/dist/core/checkpoint-features.d.ts +18 -10
- package/dist/core/checkpoint-features.js +1 -1
- package/dist/core/checkpoint-identity.d.ts +53 -0
- package/dist/core/checkpoint-identity.js +29 -0
- package/dist/core/checkpoint-queries.d.ts +4 -3
- package/dist/core/checkpoint-queries.js +5 -3
- package/dist/core/checkpoint-rekey.d.ts +70 -0
- package/dist/core/checkpoint-rekey.js +107 -0
- package/dist/core/checkpoint-requirements.d.ts +83 -10
- package/dist/core/checkpoint-requirements.js +53 -13
- package/dist/core/checkpoint-row-verdict.d.ts +5 -3
- package/dist/core/checkpoint-row-verdict.js +40 -4
- package/dist/core/checkpoint-store.d.ts +84 -7
- package/dist/core/checkpoint-store.js +38 -7
- package/dist/core/child-clamp-seats.d.ts +30 -3
- package/dist/core/child-clamp-seats.js +26 -1
- package/dist/core/classifier-category.d.ts +25 -0
- package/dist/core/classifier-category.js +93 -0
- package/dist/core/classifier-unavailable-arm.d.ts +62 -8
- package/dist/core/classifier-unavailable-arm.js +19 -2
- package/dist/core/command-sandbox-dispatch.d.ts +14 -2
- package/dist/core/command-sandbox.d.ts +209 -28
- package/dist/core/command-sandbox.js +195 -20
- package/dist/core/compaction-retired-members.d.ts +12 -0
- package/dist/core/compaction-retired-members.js +22 -0
- package/dist/core/config-refusal-codes.d.ts +41 -1
- package/dist/core/config-refusal-codes.js +18 -0
- package/dist/core/context-edit.d.ts +34 -18
- package/dist/core/context-edit.js +30 -1
- package/dist/core/context-settings.js +5 -4
- package/dist/core/cron.d.ts +68 -0
- package/dist/core/cron.js +259 -0
- package/dist/core/cross-boundary-taint.d.ts +15 -1
- package/dist/core/cross-boundary-taint.js +6 -0
- package/dist/core/delegation-frames.d.ts +36 -6
- package/dist/core/delegation-frames.js +3 -0
- package/dist/core/delegation-name.d.ts +10 -4
- package/dist/core/delegation-name.js +53 -23
- package/dist/core/engine-attestation.d.ts +26 -2
- package/dist/core/engine-attestation.js +4 -0
- package/dist/core/engine-capabilities.d.ts +53 -3
- package/dist/core/engine-capabilities.js +1 -1
- package/dist/core/engine-notice.d.ts +213 -95
- package/dist/core/engine-notice.js +29 -1
- package/dist/core/engine-version.d.ts +1 -0
- package/dist/core/engine-version.js +1 -0
- package/dist/core/extension-call-id.d.ts +4 -0
- package/dist/core/extension-call-id.js +8 -0
- package/dist/core/fast-tier-door.d.ts +36 -0
- package/dist/core/fast-tier-door.js +65 -0
- package/dist/core/file-history-store.d.ts +343 -67
- package/dist/core/file-history-store.js +320 -93
- package/dist/core/frame-settlement.d.ts +4 -0
- package/dist/core/frame-settlement.js +5 -0
- package/dist/core/gate-fold.js +13 -4
- package/dist/core/gate-lanes.js +27 -20
- package/dist/core/gate-outcome.d.ts +116 -13
- package/dist/core/gate-outcome.js +100 -4
- package/dist/core/git-read-only.d.ts +10 -0
- package/dist/core/git-read-only.js +1 -0
- package/dist/core/git-worktree-env.d.ts +29 -10
- package/dist/core/git-worktree-env.js +38 -18
- package/dist/core/governance-codes.d.ts +240 -8
- package/dist/core/governance-codes.js +204 -6
- package/dist/core/hooks.d.ts +27 -16
- package/dist/core/hooks.js +84 -82
- package/dist/core/host-floor.d.ts +2 -8
- package/dist/core/host-floor.js +6 -42
- package/dist/core/identity-rekey.d.ts +275 -0
- package/dist/core/identity-rekey.js +198 -0
- package/dist/core/image-admission.d.ts +7 -4
- package/dist/core/image-admission.js +24 -11
- package/dist/core/isolation-scope.d.ts +12 -0
- package/dist/core/isolation-scope.js +4 -0
- package/dist/core/leg-identity.d.ts +32 -2
- package/dist/core/leg-identity.js +16 -2
- package/dist/core/locked-config.d.ts +26 -6
- package/dist/core/locked-config.js +38 -17
- package/dist/core/loopback-host.d.ts +18 -0
- package/dist/core/loopback-host.js +40 -0
- package/dist/core/lsp.d.ts +3 -0
- package/dist/core/lsp.js +3 -2
- package/dist/core/mcp-connection-pool.d.ts +57 -33
- package/dist/core/mcp-connection-pool.js +47 -23
- package/dist/core/mcp-failure.d.ts +41 -19
- package/dist/core/mcp-failure.js +14 -8
- package/dist/core/mcp-host-read.js +5 -4
- package/dist/core/mcp-host-seat.js +3 -2
- package/dist/core/mcp-name-judge.js +2 -1
- package/dist/core/mcp-server-link.js +2 -1
- package/dist/core/mcp-server-spec.js +2 -2
- package/dist/core/mcp-server-unavailable-notice.d.ts +26 -16
- package/dist/core/mcp-server-unavailable-notice.js +25 -4
- package/dist/core/mcp.d.ts +15 -9
- package/dist/core/mcp.js +46 -34
- package/dist/core/memory-engine/consolidation-driver.js +8 -8
- package/dist/core/memory-engine/consolidation-write-gate.js +3 -2
- package/dist/core/memory-engine/engine.d.ts +48 -12
- package/dist/core/memory-engine/engine.js +117 -55
- package/dist/core/memory-engine/file-backend.d.ts +2 -1
- package/dist/core/memory-engine/index-copies.d.ts +47 -0
- package/dist/core/memory-engine/index-copies.js +88 -0
- package/dist/core/memory-engine/layout.d.ts +26 -8
- package/dist/core/memory-engine/layout.js +40 -4
- package/dist/core/memory-engine/origin-clearance.d.ts +9 -7
- package/dist/core/memory-engine/origin-clearance.js +2 -4
- package/dist/core/memory-engine/types.d.ts +16 -3
- package/dist/core/memory.d.ts +5 -0
- package/dist/core/memory.js +3 -0
- package/dist/core/mode-policy.d.ts +7 -1
- package/dist/core/mode-policy.js +9 -0
- package/dist/core/model-fallbacks.d.ts +13 -7
- package/dist/core/model-fallbacks.js +5 -3
- package/dist/core/model-receipt.d.ts +15 -0
- package/dist/core/model-receipt.js +54 -1
- package/dist/core/model-seat.d.ts +17 -15
- package/dist/core/mods/agent-stations.js +5 -4
- package/dist/core/mods/extension-call.d.ts +0 -4
- package/dist/core/mods/extension-call.js +0 -8
- package/dist/core/mods/host.d.ts +18 -0
- package/dist/core/mods/host.js +7 -0
- package/dist/core/mods/kernel/events.d.ts +12 -0
- package/dist/core/mods/kernel/events.js +18 -9
- package/dist/core/mods/kernel/registration.d.ts +13 -0
- package/dist/core/mods/kernel/registration.js +34 -1
- package/dist/core/mods/message-display.js +1 -1
- package/dist/core/mods/package.js +3 -3
- package/dist/core/mods/prompt-submit.js +2 -2
- package/dist/core/mods/session-append.js +3 -3
- package/dist/core/mods/session-compact.js +7 -7
- package/dist/core/mods/session-receive.js +3 -3
- package/dist/core/mods/session-send.js +3 -3
- package/dist/core/mods/stations.d.ts +10 -5
- package/dist/core/mods/stations.js +15 -13
- package/dist/core/mods/tool-call.js +12 -12
- package/dist/core/mounted-mcp.d.ts +10 -1
- package/dist/core/mounted-mcp.js +4 -0
- package/dist/core/output-style.d.ts +14 -8
- package/dist/core/output-style.js +6 -6
- package/dist/core/own-property-receipt.js +3 -5
- package/dist/core/owner-identity.d.ts +68 -0
- package/dist/core/owner-identity.js +39 -0
- package/dist/core/parent-spec-seat.d.ts +5 -1
- package/dist/core/parent-spec-seat.js +2 -0
- package/dist/core/park-resumability.js +2 -2
- package/dist/core/park-selfcheck.js +15 -4
- package/dist/core/path-guard-rows.d.ts +8 -3
- package/dist/core/path-guard-rows.js +18 -5
- package/dist/core/peer-seat.d.ts +40 -11
- package/dist/core/peer-seat.js +38 -9
- package/dist/core/permission-rule-model.d.ts +5 -0
- package/dist/core/permission-rule-model.js +27 -6
- package/dist/core/permission-rules.d.ts +42 -5
- package/dist/core/permission-rules.js +74 -10
- package/dist/core/persisted-rule-arms.d.ts +8 -6
- package/dist/core/persisted-rule-arms.js +13 -20
- package/dist/core/physical-path.d.ts +12 -8
- package/dist/core/physical-path.js +24 -14
- package/dist/core/present-plan-tool.js +2 -1
- package/dist/core/pricing.d.ts +65 -8
- package/dist/core/pricing.js +51 -0
- package/dist/core/process-identity.d.ts +11 -3
- package/dist/core/process-identity.js +26 -16
- package/dist/core/prompt-section-seat.js +6 -5
- package/dist/core/protocol-http-auth.d.ts +87 -10
- package/dist/core/protocol-http-auth.js +155 -23
- package/dist/core/reminder-mint.d.ts +4 -0
- package/dist/core/reminder-mint.js +1 -0
- package/dist/core/remote-env.d.ts +46 -1
- package/dist/core/remote-env.js +2 -0
- package/dist/core/resume-at-refusal.d.ts +47 -0
- package/dist/core/resume-at-refusal.js +9 -0
- package/dist/core/resume-startup-cause.d.ts +8 -3
- package/dist/core/resume-startup-cause.js +3 -1
- package/dist/core/retired-keys.d.ts +4 -0
- package/dist/core/retired-keys.js +4 -0
- package/dist/core/roles.d.ts +11 -5
- package/dist/core/roles.js +14 -3
- package/dist/core/rule-store-fault.d.ts +8 -1
- package/dist/core/rule-store-fault.js +5 -0
- package/dist/core/runner/advisor-instructions.d.ts +12 -12
- package/dist/core/runner/advisor-instructions.js +7 -24
- package/dist/core/runner/announce-once-ledger.d.ts +23 -8
- package/dist/core/runner/announce-once-ledger.js +69 -18
- package/dist/core/runner/assemble-result.d.ts +14 -0
- package/dist/core/runner/assemble-result.js +3 -2
- package/dist/core/runner/auto-strip-notice.js +1 -1
- package/dist/core/runner/branch-window.js +5 -3
- package/dist/core/runner/call-hook-stations.d.ts +3 -0
- package/dist/core/runner/call-hook-stations.js +4 -3
- package/dist/core/runner/caller-roster.js +2 -1
- package/dist/core/runner/capability-withheld-seat.js +47 -5
- package/dist/core/runner/classifier-ladder.d.ts +48 -8
- package/dist/core/runner/classifier-ladder.js +88 -38
- package/dist/core/runner/cleared-results-record.d.ts +33 -0
- package/dist/core/runner/cleared-results-record.js +56 -0
- package/dist/core/runner/clock-and-limits.d.ts +13 -2
- package/dist/core/runner/clock-and-limits.js +11 -8
- package/dist/core/runner/command-sandbox-frame.d.ts +56 -0
- package/dist/core/runner/command-sandbox-frame.js +107 -0
- package/dist/core/runner/compact-session.d.ts +3 -1
- package/dist/core/runner/compact-session.js +29 -18
- package/dist/core/runner/compaction-call-options.d.ts +2 -2
- package/dist/core/runner/compaction-knobs.d.ts +1 -1
- package/dist/core/runner/compaction-restate.d.ts +4 -4
- package/dist/core/runner/compaction-restate.js +3 -1
- package/dist/core/runner/construction-doors.js +9 -0
- package/dist/core/runner/continuation-gate.d.ts +39 -0
- package/dist/core/runner/continuation-gate.js +43 -0
- package/dist/core/runner/continues-from.d.ts +57 -0
- package/dist/core/runner/continues-from.js +76 -0
- package/dist/core/runner/contracts.d.ts +216 -86
- package/dist/core/runner/conversation-segment.d.ts +19 -12
- package/dist/core/runner/conversation-segment.js +27 -7
- package/dist/core/runner/credential-refusal-seat.js +31 -12
- package/dist/core/runner/cross-boundary-lane.d.ts +2 -2
- package/dist/core/runner/cross-boundary-lane.js +26 -13
- package/dist/core/runner/delegation-owner.d.ts +99 -9
- package/dist/core/runner/delegation-owner.js +107 -4
- package/dist/core/runner/denial-limit-arms.js +13 -12
- package/dist/core/runner/derived-route-fallback.d.ts +12 -26
- package/dist/core/runner/derived-route-fallback.js +4 -10
- package/dist/core/runner/earlier-grammar-notice.d.ts +6 -0
- package/dist/core/runner/earlier-grammar-notice.js +9 -0
- package/dist/core/runner/env-capability-census.js +2 -1
- package/dist/core/runner/execution-record.d.ts +4 -2
- package/dist/core/runner/execution-record.js +1 -1
- package/dist/core/runner/fast-mode-seat.d.ts +89 -0
- package/dist/core/runner/fast-mode-seat.js +215 -0
- package/dist/core/runner/file-history-restore.d.ts +52 -14
- package/dist/core/runner/file-history-restore.js +50 -8
- package/dist/core/runner/forward-sink.js +2 -2
- package/dist/core/runner/gate-exit.d.ts +43 -4
- package/dist/core/runner/gate-exit.js +59 -12
- package/dist/core/runner/git-leg-delivery.js +6 -3
- package/dist/core/runner/git-status-frame.d.ts +35 -27
- package/dist/core/runner/git-status-frame.js +56 -37
- package/dist/core/runner/halt-attribution.js +2 -2
- package/dist/core/runner/hook-progress-lane.d.ts +26 -0
- package/dist/core/runner/hook-progress-lane.js +72 -0
- package/dist/core/runner/initial-run-state.js +2 -2
- package/dist/core/runner/language-frame.d.ts +10 -8
- package/dist/core/runner/language-frame.js +7 -11
- package/dist/core/runner/left-as-is-seat.d.ts +20 -0
- package/dist/core/runner/left-as-is-seat.js +11 -0
- package/dist/core/runner/leg-caller-places.d.ts +39 -0
- package/dist/core/runner/leg-caller-places.js +23 -0
- package/dist/core/runner/leg-frame.d.ts +8 -2
- package/dist/core/runner/leg-receipt.d.ts +65 -0
- package/dist/core/runner/leg-receipt.js +53 -0
- package/dist/core/runner/listing-fold.d.ts +4 -3
- package/dist/core/runner/listing-fold.js +5 -5
- package/dist/core/runner/listing-replay.d.ts +41 -0
- package/dist/core/runner/listing-replay.js +75 -0
- package/dist/core/runner/main-call-account.d.ts +2 -1
- package/dist/core/runner/main-call-account.js +18 -5
- package/dist/core/runner/mcp-redial.d.ts +4 -2
- package/dist/core/runner/mcp-redial.js +3 -0
- package/dist/core/runner/media-removed-seat.d.ts +10 -6
- package/dist/core/runner/media-removed-seat.js +6 -3
- package/dist/core/runner/memory-consolidation-driver.js +3 -2
- package/dist/core/runner/messages-omitted-seat.d.ts +2 -1
- package/dist/core/runner/messages-omitted-seat.js +15 -5
- package/dist/core/runner/model-fallback-seat.d.ts +12 -9
- package/dist/core/runner/model-fallback-seat.js +24 -20
- package/dist/core/runner/nested-memory-lane.d.ts +16 -8
- package/dist/core/runner/nested-memory-lane.js +64 -53
- package/dist/core/runner/permission-rule-lanes.d.ts +4 -3
- package/dist/core/runner/permission-rule-lanes.js +2 -0
- package/dist/core/runner/person-path-rows.d.ts +25 -7
- package/dist/core/runner/person-path-rows.js +17 -3
- package/dist/core/runner/placement-fence.js +2 -2
- package/dist/core/runner/policy-throw.d.ts +3 -3
- package/dist/core/runner/policy-throw.js +7 -5
- package/dist/core/runner/prefix-ledger.d.ts +120 -0
- package/dist/core/runner/prefix-ledger.js +176 -0
- package/dist/core/runner/prepare-acquire-reconcile.d.ts +7 -1
- package/dist/core/runner/prepare-acquire-reconcile.js +9 -5
- package/dist/core/runner/prepare-advisor.d.ts +5 -0
- package/dist/core/runner/prepare-advisor.js +4 -3
- package/dist/core/runner/prepare-artifact.d.ts +10 -2
- package/dist/core/runner/prepare-artifact.js +19 -8
- package/dist/core/runner/prepare-ask-lane.d.ts +7 -0
- package/dist/core/runner/prepare-ask-lane.js +4 -3
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +11 -5
- package/dist/core/runner/prepare-caps-and-workflow.js +32 -23
- package/dist/core/runner/prepare-config-doors.d.ts +19 -8
- package/dist/core/runner/prepare-config-doors.js +42 -28
- package/dist/core/runner/prepare-context-lane.d.ts +28 -10
- package/dist/core/runner/prepare-context-lane.js +92 -40
- package/dist/core/runner/prepare-defer-classify.d.ts +12 -0
- package/dist/core/runner/prepare-defer-classify.js +5 -2
- package/dist/core/runner/prepare-delegation-surface.d.ts +10 -8
- package/dist/core/runner/prepare-delegation-surface.js +6 -7
- package/dist/core/runner/prepare-execution-env.d.ts +46 -4
- package/dist/core/runner/prepare-execution-env.js +47 -18
- package/dist/core/runner/prepare-file-history.d.ts +4 -1
- package/dist/core/runner/prepare-file-history.js +8 -9
- package/dist/core/runner/prepare-gate-stations.d.ts +18 -11
- package/dist/core/runner/prepare-gate-stations.js +24 -42
- package/dist/core/runner/prepare-hands-readface.d.ts +28 -11
- package/dist/core/runner/prepare-hands-readface.js +64 -54
- package/dist/core/runner/prepare-inherited-gate.d.ts +14 -2
- package/dist/core/runner/prepare-inherited-gate.js +12 -9
- package/dist/core/runner/prepare-leg-adoption.d.ts +36 -0
- package/dist/core/runner/prepare-leg-adoption.js +24 -0
- package/dist/core/runner/prepare-listings.d.ts +3 -0
- package/dist/core/runner/prepare-listings.js +2 -2
- package/dist/core/runner/prepare-lsp.d.ts +0 -3
- package/dist/core/runner/prepare-lsp.js +1 -2
- package/dist/core/runner/prepare-memory-engine-session.js +1 -1
- package/dist/core/runner/prepare-memory.d.ts +10 -2
- package/dist/core/runner/prepare-memory.js +53 -7
- package/dist/core/runner/prepare-offload-wrappers.d.ts +5 -5
- package/dist/core/runner/prepare-offload-wrappers.js +5 -5
- package/dist/core/runner/prepare-park-ask.d.ts +9 -2
- package/dist/core/runner/prepare-park-ask.js +5 -3
- package/dist/core/runner/prepare-policy-chain.d.ts +23 -5
- package/dist/core/runner/prepare-policy-chain.js +44 -27
- package/dist/core/runner/prepare-prompt-assembly.d.ts +23 -6
- package/dist/core/runner/prepare-prompt-assembly.js +15 -6
- package/dist/core/runner/prepare-prompt-inputs.d.ts +6 -10
- package/dist/core/runner/prepare-prompt-inputs.js +7 -8
- package/dist/core/runner/prepare-protocol-tools.d.ts +9 -4
- package/dist/core/runner/prepare-protocol-tools.js +11 -11
- package/dist/core/runner/prepare-run-refs.d.ts +7 -0
- package/dist/core/runner/prepare-run-refs.js +6 -2
- package/dist/core/runner/prepare-safety-scan.js +7 -0
- package/dist/core/runner/prepare-suspend-saga.d.ts +8 -1
- package/dist/core/runner/prepare-suspend-saga.js +6 -2
- package/dist/core/runner/prepare-task.d.ts +1 -30
- package/dist/core/runner/prepare-task.js +156 -186
- package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +5 -11
- package/dist/core/runner/prepare-tool-disclosure-mount.js +7 -8
- package/dist/core/runner/prepare-turn-wiring.d.ts +26 -28
- package/dist/core/runner/prepare-turn-wiring.js +13 -20
- package/dist/core/runner/prepare-wiring-manifest.d.ts +12 -3
- package/dist/core/runner/prepare-wiring-manifest.js +22 -17
- package/dist/core/runner/prompt-block.js +2 -2
- package/dist/core/runner/prompt-suggestions.d.ts +5 -8
- package/dist/core/runner/prompt-suggestions.js +5 -2
- package/dist/core/runner/read-block-judge.d.ts +47 -0
- package/dist/core/runner/read-block-judge.js +33 -0
- package/dist/core/runner/reply-pricing.d.ts +8 -4
- package/dist/core/runner/reply-pricing.js +6 -5
- package/dist/core/runner/resume-admission.js +2 -0
- package/dist/core/runner/resume-apply.js +4 -4
- package/dist/core/runner/resume-checkpoint-screen.d.ts +23 -2
- package/dist/core/runner/resume-checkpoint-screen.js +34 -27
- package/dist/core/runner/resume-preflight.js +3 -3
- package/dist/core/runner/rewind-files.js +21 -14
- package/dist/core/runner/role-resolution-table.d.ts +24 -16
- package/dist/core/runner/role-resolution-table.js +11 -11
- package/dist/core/runner/role-seat-defaulted.js +2 -2
- package/dist/core/runner/rule-store-unreadable-notice.d.ts +7 -2
- package/dist/core/runner/rule-store-unreadable-notice.js +22 -7
- package/dist/core/runner/run-attachment-seats.js +8 -15
- package/dist/core/runner/run-brain-sinks.js +1 -0
- package/dist/core/runner/run-compaction-machinery.d.ts +1 -11
- package/dist/core/runner/run-compaction-machinery.js +3 -40
- package/dist/core/runner/run-harness-handlers.d.ts +2 -2
- package/dist/core/runner/run-harness-handlers.js +22 -22
- package/dist/core/runner/run-identity-wiring.js +15 -10
- package/dist/core/runner/run-leg.js +44 -13
- package/dist/core/runner/run-notification-lane.d.ts +4 -1
- package/dist/core/runner/run-notification-lane.js +21 -8
- package/dist/core/runner/run-recovery-lanes.d.ts +0 -4
- package/dist/core/runner/run-recovery-lanes.js +35 -19
- package/dist/core/runner/run-settle-and-teardown.d.ts +6 -3
- package/dist/core/runner/run-settle-and-teardown.js +42 -52
- package/dist/core/runner/run-stop-and-final-verify.d.ts +4 -1
- package/dist/core/runner/run-stop-and-final-verify.js +12 -49
- package/dist/core/runner/run-telemetry-and-budget-seats.js +29 -11
- package/dist/core/runner/run-terminal-adoption.d.ts +11 -30
- package/dist/core/runner/run-terminal-adoption.js +10 -90
- package/dist/core/runner/run-tool-mount-facts.js +1 -5
- package/dist/core/runner/run-turn-boundary.js +69 -37
- package/dist/core/runner/runtask.d.ts +16 -7
- package/dist/core/runner/runtask.js +55 -34
- package/dist/core/runner/sandbox-network-seat.d.ts +52 -0
- package/dist/core/runner/sandbox-network-seat.js +40 -0
- package/dist/core/runner/seat-model-doors.d.ts +16 -0
- package/dist/core/runner/seat-model-doors.js +13 -0
- package/dist/core/runner/session-file-state-replay.d.ts +20 -0
- package/dist/core/runner/session-file-state-replay.js +17 -5
- package/dist/core/runner/session-hash-salt.d.ts +18 -0
- package/dist/core/runner/session-hash-salt.js +36 -0
- package/dist/core/runner/session-read-file-states.d.ts +37 -0
- package/dist/core/runner/session-read-file-states.js +19 -0
- package/dist/core/runner/session-rule-policy.d.ts +2 -1
- package/dist/core/runner/session-rule-policy.js +3 -2
- package/dist/core/runner/session-verb-doors.js +2 -1
- package/dist/core/runner/session-write-ledger.d.ts +5 -1
- package/dist/core/runner/session-write-ledger.js +19 -5
- package/dist/core/runner/shared-read-classifier.d.ts +48 -0
- package/dist/core/runner/shared-read-classifier.js +33 -0
- package/dist/core/runner/shell-env-withheld.d.ts +13 -7
- package/dist/core/runner/shell-env-withheld.js +28 -3
- package/dist/core/runner/side-call-account.d.ts +39 -3
- package/dist/core/runner/side-call-account.js +53 -9
- package/dist/core/runner/skill-mention.d.ts +12 -0
- package/dist/core/runner/skill-mention.js +50 -0
- package/dist/core/runner/skipped-rules-notice.d.ts +43 -0
- package/dist/core/runner/skipped-rules-notice.js +49 -0
- package/dist/core/runner/steering-preview.js +1 -1
- package/dist/core/runner/stop-tail-notice.d.ts +40 -0
- package/dist/core/runner/stop-tail-notice.js +35 -0
- package/dist/core/runner/stream-halt-verbs.js +1 -1
- package/dist/core/runner/stream-mode-verb.d.ts +11 -4
- package/dist/core/runner/stream-mode-verb.js +19 -7
- package/dist/core/runner/stream-settle-backstop.js +4 -1
- package/dist/core/runner/stream-steer-verb.js +4 -3
- package/dist/core/runner/synthetic-tools.d.ts +11 -11
- package/dist/core/runner/synthetic-tools.js +19 -22
- package/dist/core/runner/task-start-doors.d.ts +86 -0
- package/dist/core/runner/task-start-doors.js +108 -0
- package/dist/core/runner/teardown-bounded.d.ts +5 -5
- package/dist/core/runner/teardown-bounded.js +6 -6
- package/dist/core/runner/terminal-account.d.ts +3 -2
- package/dist/core/runner/terminal-account.js +5 -3
- package/dist/core/runner/tool-disclosure.js +8 -9
- package/dist/core/runner/tool-end-body.d.ts +2 -0
- package/dist/core/runner/tool-end-body.js +1 -0
- package/dist/core/runner/tool-face-overlay.js +1 -0
- package/dist/core/runner/tool-occurrence.d.ts +22 -24
- package/dist/core/runner/tool-occurrence.js +9 -15
- package/dist/core/runner/tool-progress-lane.js +1 -1
- package/dist/core/runner/tool-result-media-seat.d.ts +7 -4
- package/dist/core/runner/tool-result-media-seat.js +16 -4
- package/dist/core/runner/tool-table-view.d.ts +12 -10
- package/dist/core/runner/tool-table-view.js +23 -21
- package/dist/core/runner/tool-turn-repair-seat.d.ts +22 -2
- package/dist/core/runner/tool-turn-repair-seat.js +23 -5
- package/dist/core/runner/turn-attachments.d.ts +74 -148
- package/dist/core/runner/turn-attachments.js +153 -223
- package/dist/core/runner/usage-accounting.d.ts +15 -0
- package/dist/core/runner/usage-accounting.js +12 -4
- package/dist/core/runner/verdict-refusal.d.ts +45 -0
- package/dist/core/runner/verdict-refusal.js +39 -0
- package/dist/core/runner/write-protection-station.d.ts +10 -2
- package/dist/core/runner/write-protection-station.js +7 -7
- package/dist/core/runner-deps.d.ts +40 -32
- package/dist/core/runtime-caps.d.ts +5 -3
- package/dist/core/scheduler.d.ts +13 -3
- package/dist/core/scheduler.js +0 -12
- package/dist/core/secret-env.d.ts +61 -20
- package/dist/core/secret-env.js +83 -15
- package/dist/core/sensitive-path-policy.js +4 -0
- package/dist/core/session-checkout.d.ts +18 -1
- package/dist/core/session-checkout.js +33 -17
- package/dist/core/session-log-transfer.js +2 -2
- package/dist/core/session-policy-store.d.ts +220 -31
- package/dist/core/session-policy-store.js +333 -47
- package/dist/core/session-reconcile.d.ts +12 -0
- package/dist/core/session-reconcile.js +1 -1
- package/dist/core/session-store.d.ts +5 -3
- package/dist/core/session-store.js +11 -11
- package/dist/core/session.d.ts +31 -22
- package/dist/core/session.js +3 -2
- package/dist/core/shared-memory/normalize.js +2 -1
- package/dist/core/shell-run-candidates.d.ts +1 -1
- package/dist/core/shell-run-candidates.js +11 -3
- package/dist/core/side-query.d.ts +4 -0
- package/dist/core/side-query.js +7 -4
- package/dist/core/spec-contract.d.ts +4 -2
- package/dist/core/store-contracts/background-agent-store-contract.js +149 -0
- package/dist/core/store-contracts/checkpoint-store-contract.js +55 -0
- package/dist/core/store-contracts/contract-kit-version.d.ts +4 -4
- package/dist/core/store-contracts/file-history-store-contract.d.ts +1 -1
- package/dist/core/store-contracts/file-history-store-contract.js +282 -22
- package/dist/core/store-contracts/session-policy-store-contract.js +202 -0
- package/dist/core/store-contracts/session-store-contract.js +48 -14
- package/dist/core/store-contracts/tool-result-store-contract.d.ts +1 -1
- package/dist/core/store-contracts/tool-result-store-contract.js +128 -0
- package/dist/core/store-contracts/workflow-journal-store-contract.js +90 -1
- package/dist/core/swappable-deps.d.ts +16 -0
- package/dist/core/swappable-deps.js +61 -1
- package/dist/core/synthetic-read-verdict.d.ts +23 -0
- package/dist/core/synthetic-read-verdict.js +43 -18
- package/dist/core/task-event.d.ts +155 -60
- package/dist/core/task-intake.d.ts +23 -5
- package/dist/core/task-intake.js +33 -3
- package/dist/core/task-limits.d.ts +3 -1
- package/dist/core/task-notification.d.ts +171 -59
- package/dist/core/task-notification.js +162 -104
- package/dist/core/task-registry-agent.d.ts +12 -0
- package/dist/core/task-registry-agent.js +23 -9
- package/dist/core/task-registry-shared.d.ts +4 -2
- package/dist/core/task-registry-shared.js +1 -1
- package/dist/core/task-registry-workflow.js +8 -5
- package/dist/core/task-registry.d.ts +16 -1
- package/dist/core/task-registry.js +35 -23
- package/dist/core/task-result.d.ts +166 -10
- package/dist/core/task-spec-members.d.ts +8 -2
- package/dist/core/task-spec-members.js +11 -7
- package/dist/core/task-spec.d.ts +68 -32
- package/dist/core/task-start-judge.d.ts +41 -0
- package/dist/core/task-start-judge.js +26 -0
- package/dist/core/task-stream.d.ts +12 -1
- package/dist/core/terminal-cause.d.ts +23 -9
- package/dist/core/tool-catalog-entries.js +6 -5
- package/dist/core/tool-face-lists.d.ts +3 -2
- package/dist/core/tool-face-lists.js +6 -0
- package/dist/core/tool-face-reader.d.ts +3 -2
- package/dist/core/tool-face-reader.js +2 -2
- package/dist/core/tool-face.d.ts +27 -3
- package/dist/core/tool-face.js +2 -2
- package/dist/core/tool-model-gate.js +14 -13
- package/dist/core/tool-mount-facts.d.ts +16 -3
- package/dist/core/tool-mount-facts.js +10 -0
- package/dist/core/tool-mount-plan.d.ts +79 -10
- package/dist/core/tool-mount-plan.js +79 -24
- package/dist/core/tool-mount-static.d.ts +52 -6
- package/dist/core/tool-mount-static.js +82 -28
- package/dist/core/tool-name-aliases.js +1 -1
- package/dist/core/tool-policy.d.ts +55 -26
- package/dist/core/tool-policy.js +50 -36
- package/dist/core/tool-registry.d.ts +12 -2
- package/dist/core/tool-registry.js +9 -2
- package/dist/core/tool-result-budget.d.ts +2 -2
- package/dist/core/tool-result-bytes.d.ts +28 -9
- package/dist/core/tool-result-bytes.js +7 -5
- package/dist/core/tool-result-store.d.ts +310 -38
- package/dist/core/tool-result-store.js +325 -30
- package/dist/core/tool-roster.d.ts +41 -15
- package/dist/core/tool-roster.js +50 -12
- package/dist/core/tool-search-setting.js +2 -2
- package/dist/core/tool-spec-members.js +1 -1
- package/dist/core/tool-spec.d.ts +37 -10
- package/dist/core/tools.js +1 -0
- package/dist/core/trace.d.ts +42 -19
- package/dist/core/types.d.ts +5 -5
- package/dist/core/types.js +2 -2
- package/dist/core/unc-spelling.d.ts +145 -3
- package/dist/core/unc-spelling.js +161 -0
- package/dist/core/untrusted-egress.d.ts +82 -10
- package/dist/core/untrusted-egress.js +102 -9
- package/dist/core/untrusted-text.d.ts +28 -0
- package/dist/core/untrusted-text.js +67 -3
- package/dist/core/user-attachment.d.ts +18 -3
- package/dist/core/user-attachment.js +37 -31
- package/dist/core/user-row-origin.d.ts +22 -0
- package/dist/core/user-row-origin.js +15 -0
- package/dist/core/version.d.ts +1 -1
- package/dist/core/version.js +2 -12
- package/dist/core/wiring-manifest.d.ts +151 -30
- package/dist/core/wiring-manifest.js +69 -17
- package/dist/core/workflow-journal-store.d.ts +186 -16
- package/dist/core/workflow-journal-store.js +156 -1
- package/dist/core/workflow-run-store-contract.js +104 -1
- package/dist/core/workflow-run-store.d.ts +44 -4
- package/dist/core/workflow-run-store.js +9 -2
- package/dist/core/workspace-snapshot.d.ts +4 -1
- package/dist/core/workspace-snapshot.js +1 -1
- package/dist/core/write-protect.d.ts +4 -0
- package/dist/core/write-protect.js +17 -15
- package/dist/engine/compaction/compaction.d.ts +51 -101
- package/dist/engine/compaction/compaction.js +142 -224
- package/dist/engine/compaction/utils.d.ts +2 -11
- package/dist/engine/compaction/utils.js +4 -13
- package/dist/engine/execution-env/node-execution-env.d.ts +14 -6
- package/dist/engine/execution-env/node-execution-env.js +66 -20
- package/dist/engine/harness/agent-harness.d.ts +36 -12
- package/dist/engine/harness/agent-harness.js +84 -23
- package/dist/engine/harness/types.d.ts +36 -9
- package/dist/engine/harness/types.js +14 -1
- package/dist/engine/llm/tool-turns.d.ts +19 -2
- package/dist/engine/llm/tool-turns.js +29 -2
- package/dist/engine/llm/types.d.ts +103 -22
- package/dist/engine/llm/types.js +1 -1
- package/dist/engine/loop/agent-loop.d.ts +32 -10
- package/dist/engine/loop/agent-loop.js +144 -33
- package/dist/engine/loop/types.d.ts +21 -7
- package/dist/engine/lsp/node-lsp-manager.d.ts +6 -4
- package/dist/engine/lsp/node-lsp-manager.js +22 -21
- package/dist/engine/session/import-validate.js +2 -0
- package/dist/engine/session/repo-utils.d.ts +13 -7
- package/dist/engine/session/repo-utils.js +9 -4
- package/dist/index.d.ts +55 -31
- package/dist/index.js +44 -24
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/internal/harness.d.ts +2 -2
- package/dist/internal/harness.js +1 -1
- package/dist/internal/llm.d.ts +2 -2
- package/dist/internal/llm.js +1 -1
- package/dist/orchestration/goal.js +1 -1
- package/dist/orchestration/governance-baseline-validity.d.ts +20 -5
- package/dist/orchestration/governance-baseline-validity.js +87 -16
- package/dist/orchestration/run-spec.js +7 -2
- package/dist/orchestration/run-workflow-tool.d.ts +15 -12
- package/dist/orchestration/run-workflow-tool.js +759 -331
- package/dist/orchestration/workflow-governance.d.ts +1 -1
- package/dist/orchestration/workflow-observe.d.ts +22 -2
- package/dist/orchestration/workflow-observe.js +20 -9
- package/dist/orchestration/workflow-park-adoption.d.ts +438 -0
- package/dist/orchestration/workflow-park-adoption.js +767 -0
- package/dist/orchestration/workflow-size-guideline.d.ts +6 -8
- package/dist/orchestration/workflow-size-guideline.js +12 -14
- package/dist/orchestration/workflow-types.d.ts +117 -17
- package/dist/orchestration/workflow-types.js +40 -8
- package/dist/orchestration/workflow.d.ts +71 -26
- package/dist/orchestration/workflow.js +503 -201
- package/dist/prompt-assembly/artifact.js +4 -3
- package/dist/prompt-assembly/assemble.d.ts +2 -0
- package/dist/prompt-assembly/assemble.js +4 -1
- package/dist/prompt-assembly/bands.d.ts +3 -0
- package/dist/prompt-assembly/bands.js +6 -0
- package/dist/prompt-assembly/catalog/constitution.d.ts +1 -1
- package/dist/prompt-assembly/catalog/constitution.js +74 -9
- package/dist/prompt-assembly/catalog/core-behavior.d.ts +5 -4
- package/dist/prompt-assembly/catalog/core-behavior.js +52 -9
- package/dist/prompt-assembly/catalog/engine.d.ts +110 -5
- package/dist/prompt-assembly/catalog/engine.js +13 -0
- package/dist/prompt-assembly/catalog/events.d.ts +860 -0
- package/dist/prompt-assembly/catalog/events.js +62 -0
- package/dist/prompt-assembly/catalog/index.js +2 -1
- package/dist/prompt-assembly/catalog/locales/index.d.ts +2 -2
- package/dist/prompt-assembly/catalog/locales/index.js +4 -2
- package/dist/prompt-assembly/catalog/locales/zh-Hans/constitution.js +53 -1
- package/dist/prompt-assembly/catalog/locales/zh-Hans/core-behavior.js +51 -9
- package/dist/prompt-assembly/catalog/locales/zh-Hans/engine.js +12 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/events.d.ts +7 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/events.js +57 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/mechanism.d.ts +8 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/mechanism.js +57 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/modes.js +8 -2
- package/dist/prompt-assembly/catalog/locales/zh-Hans/role.js +37 -9
- package/dist/prompt-assembly/catalog/mechanism.d.ts +435 -0
- package/dist/prompt-assembly/catalog/mechanism.js +63 -0
- package/dist/prompt-assembly/catalog/memory.d.ts +3 -3
- package/dist/prompt-assembly/catalog/memory.js +12 -3
- package/dist/prompt-assembly/catalog/modes.d.ts +2 -2
- package/dist/prompt-assembly/catalog/modes.js +7 -1
- package/dist/prompt-assembly/catalog/role.d.ts +1 -1
- package/dist/prompt-assembly/catalog/role.js +43 -14
- package/dist/prompt-assembly/catalog/schema.d.ts +43 -20
- package/dist/prompt-assembly/catalog/schema.js +18 -6
- package/dist/prompt-assembly/catalog/sections.d.ts +1 -1
- package/dist/prompt-assembly/catalog/sections.js +28 -12
- package/dist/prompt-assembly/composer.d.ts +3 -0
- package/dist/prompt-assembly/composer.js +11 -5
- package/dist/prompt-assembly/engine-text.d.ts +14 -4
- package/dist/prompt-assembly/engine-text.js +18 -9
- package/dist/prompt-assembly/event-registry.d.ts +38 -31
- package/dist/prompt-assembly/event-registry.js +186 -25
- package/dist/prompt-assembly/explain.d.ts +24 -0
- package/dist/prompt-assembly/explain.js +11 -0
- package/dist/prompt-assembly/locale-review.js +3 -2
- package/dist/prompt-assembly/overlay.d.ts +25 -7
- package/dist/prompt-assembly/overlay.js +68 -14
- package/dist/prompt-assembly/select.d.ts +4 -3
- package/dist/prompt-assembly/select.js +11 -2
- package/dist/prompt-assembly/sugar.d.ts +3 -2
- package/dist/prompt-assembly/sugar.js +2 -2
- package/dist/prompt-assembly/tool-catalog.js +3 -2
- package/dist/prompt-assembly/turn-snapshot.d.ts +15 -27
- package/dist/prompt-assembly/turn-snapshot.js +7 -18
- package/dist/prompt-assembly/types.d.ts +6 -4
- package/dist/prompts/default.d.ts +15 -45
- package/dist/prompts/default.js +7 -21
- package/dist/shell/lex.d.ts +51 -10
- package/dist/shell/lex.js +223 -31
- package/dist/stores/file/adoption/adopt.d.ts +13 -3
- package/dist/stores/file/adoption/adopt.js +90 -95
- package/dist/stores/file/adoption/marker.d.ts +2 -1
- package/dist/stores/file/background-agent-store.d.ts +61 -0
- package/dist/stores/file/background-agent-store.js +64 -15
- package/dist/stores/file/checkpoint-store.d.ts +30 -2
- package/dist/stores/file/checkpoint-store.js +72 -23
- package/dist/stores/file/file-history-store.d.ts +13 -7
- package/dist/stores/file/file-history-store.js +170 -46
- package/dist/stores/file/fs-atomic.d.ts +57 -2
- package/dist/stores/file/fs-atomic.js +116 -48
- package/dist/stores/file/index.d.ts +2 -0
- package/dist/stores/file/index.js +2 -0
- package/dist/stores/file/ledger-damage.d.ts +87 -0
- package/dist/stores/file/ledger-damage.js +103 -0
- package/dist/stores/file/session-policy-store.d.ts +36 -4
- package/dist/stores/file/session-policy-store.js +177 -6
- package/dist/stores/file/shared-ledger.d.ts +123 -11
- package/dist/stores/file/shared-ledger.js +113 -18
- package/dist/stores/file/tool-result-store.d.ts +30 -1
- package/dist/stores/file/tool-result-store.js +60 -6
- package/dist/stores/file/workflow-journal-store.d.ts +73 -26
- package/dist/stores/file/workflow-journal-store.js +195 -32
- package/dist/stores/file/workflow-run-store.d.ts +47 -2
- package/dist/stores/file/workflow-run-store.js +17 -14
- package/dist/tools/artifact/artifact-tool.d.ts +9 -6
- package/dist/tools/artifact/artifact-tool.js +76 -40
- package/dist/tools/fs/bash-program-position.js +2 -6
- package/dist/tools/fs/bash-readonly-classifier.d.ts +18 -3
- package/dist/tools/fs/bash-readonly-classifier.js +12 -6
- package/dist/tools/fs/containment-face.d.ts +12 -3
- package/dist/tools/fs/containment-face.js +16 -7
- package/dist/tools/fs/env-error-detail.d.ts +11 -0
- package/dist/tools/fs/env-error-detail.js +13 -2
- package/dist/tools/fs/file-read-check.d.ts +26 -1
- package/dist/tools/fs/file-read-check.js +20 -2
- package/dist/tools/fs/fs-bash.js +30 -21
- package/dist/tools/fs/fs-pdf.d.ts +1 -1
- package/dist/tools/fs/fs-pdf.js +2 -2
- package/dist/tools/fs/fs-read.d.ts +3 -0
- package/dist/tools/fs/fs-read.js +6 -6
- package/dist/tools/fs/fs-search-tools.d.ts +2 -2
- package/dist/tools/fs/fs-search-tools.js +4 -4
- package/dist/tools/fs/fs-shared.d.ts +26 -9
- package/dist/tools/fs/fs-shared.js +12 -6
- package/dist/tools/fs/fs-write.d.ts +6 -4
- package/dist/tools/fs/fs-write.js +24 -18
- package/dist/tools/fs/index.js +5 -3
- package/dist/tools/fs/pattern-kill-guard.js +2 -1
- package/dist/tools/fs/pdf.d.ts +8 -0
- package/dist/tools/fs/pdf.js +22 -4
- package/dist/tools/fs/program-read-model.d.ts +4 -0
- package/dist/tools/fs/program-read-model.rows.js +3 -3
- package/dist/tools/fs/read-deny-home.d.ts +13 -2
- package/dist/tools/fs/read-deny-home.js +26 -22
- package/dist/tools/fs/read-deny.js +15 -6
- package/dist/tools/fs/read-floor.d.ts +11 -9
- package/dist/tools/fs/read-floor.js +7 -10
- package/dist/tools/fs/removal-targets.d.ts +33 -17
- package/dist/tools/fs/removal-targets.js +176 -59
- package/dist/tools/fs/repo-map.d.ts +1 -1
- package/dist/tools/fs/repo-map.js +2 -2
- package/dist/tools/fs/safety.d.ts +34 -108
- package/dist/tools/fs/safety.js +49 -124
- package/dist/tools/fs/shell-read-bindings.d.ts +8 -2
- package/dist/tools/fs/shell-read-bindings.js +25 -6
- package/dist/tools/fs/shell-read-check.d.ts +7 -2
- package/dist/tools/fs/shell-read-check.js +28 -6
- package/dist/tools/fs/shell-read-environment.d.ts +10 -2
- package/dist/tools/fs/shell-read-environment.js +20 -11
- package/dist/tools/fs/shell-read-establish.js +73 -43
- package/dist/tools/fs/shell-read-judge.d.ts +51 -21
- package/dist/tools/fs/shell-read-judge.js +22 -8
- package/dist/tools/fs/shell-read-object-path.d.ts +5 -1
- package/dist/tools/fs/shell-read-object-path.js +17 -4
- package/dist/tools/fs/shell-read-plan.d.ts +3 -3
- package/dist/tools/fs/shell-read-plan.js +23 -19
- package/dist/tools/fs/shell-read-sourced.js +10 -3
- package/dist/tools/fs/shell-read-start.d.ts +4 -2
- package/dist/tools/fs/shell-read-start.js +3 -3
- package/dist/tools/fs/shell-read-workdir.d.ts +14 -6
- package/dist/tools/fs/shell-read-workdir.js +35 -17
- package/dist/tools/fs/shell-reentry-text.d.ts +8 -0
- package/dist/tools/fs/shell-reentry-text.js +56 -0
- package/dist/tools/monitor.js +7 -5
- package/dist/tools/scheduler-tools.d.ts +44 -16
- package/dist/tools/scheduler-tools.js +87 -114
- package/dist/tools/task-list.d.ts +12 -4
- package/dist/tools/task-list.js +10 -7
- package/dist/tools/web.d.ts +2 -8
- package/dist/tools/web.js +5 -5
- package/dist/tools/worktree.js +23 -19
- package/package.json +7 -3
- package/test/export-surface.snapshot.json +390 -14
- package/wire-changes/{core-stores-sql@7.68.7.json → core-stores-sql@7.69.0.json} +5 -5
- package/wire-changes/core-stores-sql@7.69.1.json +39 -0
- package/wire-changes/core@7.69.0.json +9561 -0
- package/wire-changes/core@7.69.1.json +2561 -0
- package/wire-changes/mods-kernel@7.69.0.json +80 -0
- package/wire-changes/{mods-kernel@7.68.7.json → mods-kernel@7.69.1.json} +5 -5
- package/wire-changes/primitives@7.69.0.json +79 -0
- package/wire-changes/{primitives@7.68.7.json → primitives@7.69.1.json} +5 -5
- package/wire-changes/{wiki-gate@7.68.7.json → wiki-gate@7.69.0.json} +5 -5
- package/wire-changes/wiki-gate@7.69.1.json +39 -0
- package/dist/core/runner/prompt-hash-salt.d.ts +0 -1
- package/dist/core/runner/prompt-hash-salt.js +0 -2
- package/wire-changes/core@7.68.7.json +0 -140
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { presetRoleBaseOf, resolveModelDisplayLabel } from "../core/roles.js";
|
|
2
2
|
import { describeRejectedValue } from "../core/tool-search-setting.js";
|
|
3
|
+
import { takeSeat } from "../core/swappable-deps.js";
|
|
3
4
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
5
|
import { createHash, randomUUID } from "node:crypto";
|
|
5
6
|
import { availableParallelism } from "node:os";
|
|
6
7
|
import { mintCompletionId } from "../core/completion-id.js";
|
|
8
|
+
import { stampWorkflowMember } from "../core/leg-identity.js";
|
|
9
|
+
import { thrownFailureOf } from "../core/runner/terminal-account.js";
|
|
7
10
|
import { deliverEngineNotice } from "../core/engine-notice.js";
|
|
11
|
+
import { judgeCheckpointRow } from "../core/checkpoint-row-verdict.js";
|
|
8
12
|
import { applyParentSpecSeat } from "../core/parent-spec-seat.js";
|
|
9
13
|
import { TERMINAL_CAUSE_IS_REPLAYABLE, isTerminalCauseKind } from "../core/terminal-cause.js";
|
|
10
14
|
import { terminalProjection } from "../core/runner/terminal-projection.js";
|
|
@@ -14,27 +18,39 @@ import { GENERAL_PURPOSE_SUBAGENT_TYPE, markerFragment } from "../agents/subagen
|
|
|
14
18
|
import { runnerRoleMap } from "../agents/child-model-seat.js";
|
|
15
19
|
import { namesRoleBase } from "../prompt-assembly/role-base.js";
|
|
16
20
|
import { createSafeNotifier } from "../core/safe-notify.js";
|
|
17
|
-
import { callKeyOrdinal, clampRunIdText, oversizeJournalResult, journalOversizeTombstone, readWorkflowJournalEntry, JOURNAL_OVERSIZE_ERROR_CODE, MAX_JOURNAL_RESULT_BYTES, WorkflowJournalIncompatibleError, } from "../core/workflow-journal-store.js";
|
|
18
|
-
import { isWorkflowRunActive, closeWorkflowChannel, markWorkflowActive, publishWorkflowEvent, registerWorkflowParkDelivery } from "./workflow-observe.js";
|
|
21
|
+
import { assertJournalStoreGivesClaimsBack, callKeyOrdinal, clampRunIdText, journalKeepsLaunches, oversizeJournalResult, journalOversizeTombstone, readWorkflowJournalEntry, JOURNAL_OVERSIZE_ERROR_CODE, MAX_JOURNAL_RESULT_BYTES, WorkflowJournalIncompatibleError, } from "../core/workflow-journal-store.js";
|
|
22
|
+
import { isWorkflowRunActive, closeWorkflowChannel, markWorkflowActive, publishWorkflowEvent, readWorkflowParkedDecisions, registerWorkflowParkDelivery } from "./workflow-observe.js";
|
|
19
23
|
import { isDurablePause, resumeNeverStarted } from "../agents/suspend-guard.js";
|
|
20
24
|
import { RUNNING_AGENT_OBSERVE_EVERY_BEATS } from "../config/defaults.js";
|
|
21
25
|
import { boundInputHashOf } from "../core/canonical-json.js";
|
|
22
26
|
import { boundedRedactedSummary, egressThrownText } from "../core/untrusted-egress.js";
|
|
23
27
|
import { delimitUntrusted } from "../core/untrusted-text.js";
|
|
24
|
-
import {
|
|
28
|
+
import { reviewSubjectOf } from "../agents/delegation-review-faces.js";
|
|
29
|
+
import { OUTPUT_TOOL_NAME, TOOL_CATALOG_ENTRIES } from "../core/tool-catalog-entries.js";
|
|
30
|
+
import { readDelegationReview } from "../core/classifier-unavailable-arm.js";
|
|
25
31
|
import { judgeHostToolCeiling, refuseUnusableDefinition } from "../core/runner/sub-agent-deny-lists.js";
|
|
26
32
|
import { definitionSelectorLayer, withDefinitionServers } from "../agents/inherited-tool-pool.js";
|
|
27
33
|
import { snapshotToolNameList } from "../core/tool-name-list.js";
|
|
34
|
+
import { snapshotDefinitionLists } from "../agents/agent-definition.js";
|
|
35
|
+
import { holdKeeperDeclarations } from "../agents/retain-ledger.js";
|
|
28
36
|
import { snapshotAndValidateMcpEntries } from "../core/locked-config.js";
|
|
29
37
|
import { compileOutputSchema } from "../core/runner/strict-output-schema.js";
|
|
30
38
|
import { callerPlacementSeats } from "../core/runner/child-tree.js";
|
|
31
|
-
import {
|
|
39
|
+
import { judgedOwnerSeat } from "../core/runner/delegation-owner.js";
|
|
40
|
+
import { WorkflowBudgetExceededError, WorkflowNestingError, WorkflowAgentBlockedError, WorkflowAgentParkedError, WorkflowAgentSchemaError, WorkflowAgentStalledError, WorkflowMaxAgentsError, WORKFLOW_SPAWN_BLOCKED_ERROR_CODE, PARK_NOT_PENDING_STATUSES, runParkedOf, workflowParkHolderOf } from "./workflow-types.js";
|
|
41
|
+
import { claimLapseInstant, readWorkflowRunChain, runThatDrove, storeErrorClassOf, workflowRunSuccessors, workflowTreeOf, WORKFLOW_TREE_OVER_BOUND_REASON } from "./workflow-park-adoption.js";
|
|
32
42
|
import { WorkflowScriptError } from "./workflow-meta.js";
|
|
33
43
|
import { firstByteLaneKnobMs, STALL_FIRST_BYTE_MS, STALL_FIRST_TOKEN_MS } from "../brain/timeout.js";
|
|
34
44
|
import { asThrownError, isErrorLike, readMember, thrownIs, thrownName, thrownText } from "../core/thrown-value.js";
|
|
35
45
|
import { bindSettledRun } from "../core/workflow-settled-run.js";
|
|
36
46
|
import { persistTaskArtifact } from "../core/tool-result-store.js";
|
|
37
47
|
import { formatWorkflowRun, WORKFLOW_RECORD_WHOLE } from "../core/task-registry-shared.js";
|
|
48
|
+
const WORKFLOW_TOOL_NAME = (() => {
|
|
49
|
+
const entry = TOOL_CATALOG_ENTRIES.find((e) => e.id === "workflow");
|
|
50
|
+
if (entry === undefined)
|
|
51
|
+
throw new Error("workflow: the tool catalog has no `workflow` entry — a review notice cannot name the tool");
|
|
52
|
+
return entry.name;
|
|
53
|
+
})();
|
|
38
54
|
export * from "./workflow-types.js";
|
|
39
55
|
const MAX_TRANSCRIPT_CHARS = 4000;
|
|
40
56
|
const WORKFLOW_RESULT_MAX = 4000;
|
|
@@ -128,8 +144,7 @@ export function applyWorkflowAgentType(spec, agentType, registry) {
|
|
|
128
144
|
out.memory = def.memory;
|
|
129
145
|
if (out.memoryPersistenceCapable === undefined && def.memoryPersistenceCapable !== undefined)
|
|
130
146
|
out.memoryPersistenceCapable = def.memoryPersistenceCapable;
|
|
131
|
-
const
|
|
132
|
-
const ownServers = declared !== undefined ? snapshotAndValidateMcpEntries(declared, `AgentDefinition.mcp of ${JSON.stringify(def.name.slice(0, 80))}`) : undefined;
|
|
147
|
+
const ownServers = def.mcp;
|
|
133
148
|
if (ownServers !== undefined && ownServers.length > 0)
|
|
134
149
|
out.mcp = withDefinitionServers(out.mcp !== undefined ? snapshotAndValidateMcpEntries(out.mcp) : undefined, ownServers);
|
|
135
150
|
const lists = { allowTools: snapshotToolNameList(def.allowTools), denyTools: snapshotToolNameList(def.denyTools) };
|
|
@@ -139,7 +154,7 @@ export function applyWorkflowAgentType(spec, agentType, registry) {
|
|
|
139
154
|
return { spec: out, definitionToolLists: { agentType: def.name, layer: definitionSelectorLayer({ ...lists, ...(ownServers !== undefined ? { mcp: ownServers } : {}) }) } };
|
|
140
155
|
}
|
|
141
156
|
export function workflowAgentRegistry(opts) {
|
|
142
|
-
const deployment = opts.agents ?? [];
|
|
157
|
+
const deployment = (opts.agents ?? []).map(snapshotDefinitionLists);
|
|
143
158
|
const names = new Set(deployment.map((d) => d.name));
|
|
144
159
|
const builtins = opts.builtinAgents === false ? [] : builtinAgentDefinitions().filter((d) => !names.has(d.name));
|
|
145
160
|
return [...deployment, ...builtins];
|
|
@@ -198,12 +213,15 @@ export function assertSupportedAgentIsolation(isolation) {
|
|
|
198
213
|
throw e;
|
|
199
214
|
}
|
|
200
215
|
}
|
|
216
|
+
const CALL_INPUTS_THAT_MOVE = "the script, its args, or a setting folded into every call: the deployment's settings for workflows, the account the run is for, or — for a model handed to the session as an object rather than a catalog name — the object the session holds now (another object of the same id moves it); for a run whose launch record keeps no host model or tool face, also the session's own model, thinking level or tool lists";
|
|
201
217
|
function rethrowIfMaxAgents(e) {
|
|
202
218
|
if (thrownIs(e, WorkflowMaxAgentsError))
|
|
203
219
|
throw e;
|
|
204
220
|
return null;
|
|
205
221
|
}
|
|
206
|
-
function foldFanOutSettled(settled, lane, errorsOut, emitRunLog) {
|
|
222
|
+
function foldFanOutSettled(settled, lane, errorsOut, emitRunLog, runFinal) {
|
|
223
|
+
if (runFinal !== undefined && settled.some((s) => !s.ok))
|
|
224
|
+
throw runFinal;
|
|
207
225
|
let dropped = 0;
|
|
208
226
|
const droppedSlots = [];
|
|
209
227
|
const results = settled.map((s) => {
|
|
@@ -284,6 +302,10 @@ class WorkflowParkRefusal extends Error {
|
|
|
284
302
|
this.name = "WorkflowParkRefusal";
|
|
285
303
|
}
|
|
286
304
|
}
|
|
305
|
+
function runStoreUnreadableRefusal(fromRunId, cause) {
|
|
306
|
+
const what = cause === undefined ? `no answer within ${WORKFLOW_STORE_WAIT_BOUND_MS}ms, or records that name each other in a loop` : storeErrorClassOf(cause.err);
|
|
307
|
+
return new WorkflowParkRefusal("workflow.park_truth_unreadable", `startWorkflow: resume from "${fromRunId}" was REFUSED — the prior run's record, or that of a run it was resumed from, could not be read from the run store (${what}), so its parks cannot be proven.`, { reason: "store_threw" });
|
|
308
|
+
}
|
|
287
309
|
const workflowDepthStore = new AsyncLocalStorage();
|
|
288
310
|
function currentWorkflowDepth() {
|
|
289
311
|
return workflowDepthStore.getStore()?.depth ?? 0;
|
|
@@ -522,6 +544,25 @@ export const workflowResumeClaimFallback = {
|
|
|
522
544
|
table.delete(key);
|
|
523
545
|
},
|
|
524
546
|
};
|
|
547
|
+
export function takeWorkflowResumeClaim(store, input) {
|
|
548
|
+
if (store.resumeClaim === undefined)
|
|
549
|
+
return Promise.resolve({ ...workflowResumeClaimFallback.acquire(store, input), fallback: true });
|
|
550
|
+
return Promise.resolve(store.resumeClaim(input)).then((v) => ({
|
|
551
|
+
granted: Boolean(v.granted),
|
|
552
|
+
...(v.holder !== undefined ? { holder: v.holder } : {}),
|
|
553
|
+
...(claimLapseInstant(v.expiresAt) !== undefined ? { expiresAt: v.expiresAt } : {}),
|
|
554
|
+
fallback: false,
|
|
555
|
+
}));
|
|
556
|
+
}
|
|
557
|
+
export async function releaseWorkflowResumeClaim(store, input, fallback) {
|
|
558
|
+
if (fallback)
|
|
559
|
+
return workflowResumeClaimFallback.release(store, input);
|
|
560
|
+
try {
|
|
561
|
+
await store.releaseResumeClaim?.(input);
|
|
562
|
+
}
|
|
563
|
+
catch {
|
|
564
|
+
}
|
|
565
|
+
}
|
|
525
566
|
function parkLaneArmed(opts) {
|
|
526
567
|
return opts.store !== undefined && opts.checkpointStore !== undefined;
|
|
527
568
|
}
|
|
@@ -537,6 +578,9 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
537
578
|
if (opts.resumeFromRunId !== undefined && opts.journalStore === undefined) {
|
|
538
579
|
throw new Error("runWorkflow: resumeFromRunId requires a journalStore to load the prior run's journal");
|
|
539
580
|
}
|
|
581
|
+
assertJournalStoreGivesClaimsBack(opts.journalStore, "RunWorkflowOptions.journalStore");
|
|
582
|
+
const defaultSeat = takeSeat(opts.defaultGetApiKeyAndHeaders, () => runner.agentCatalog.models);
|
|
583
|
+
const authInheritOf = (spec) => { const seat = defaultSeat ?? opts.defaultGetApiKeyAndHeaders; return spec.getApiKeyAndHeaders === undefined && seat !== undefined ? { getApiKeyAndHeaders: seat } : {}; };
|
|
540
584
|
if (opts.checkpointStore !== undefined && !parkLaneArmed(opts)) {
|
|
541
585
|
throw new WorkflowParkRefusal("workflow.park_requires_run_store", "runWorkflow: checkpointStore (the store this run's children park in) requires a WorkflowRunStore — a workflow child's park is recorded on its wa* row and proven against the checkpoint store at the next resume, and without a run store there is no durable row for a host to route the parked approval by", {});
|
|
542
586
|
}
|
|
@@ -546,9 +590,13 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
546
590
|
if (opts.parkedResume !== undefined && opts.resumeFromRunId === undefined) {
|
|
547
591
|
throw new Error("runWorkflow: parkedResume drives a PARKED ordinal of a prior run and requires resumeFromRunId");
|
|
548
592
|
}
|
|
593
|
+
if (opts.launch !== undefined && !journalKeepsLaunches(opts.journalStore)) {
|
|
594
|
+
throw new Error("runWorkflow: launch is the record a continuation of this run reads back, and requires a journalStore that keeps launch records (recordLaunch and loadLaunch)");
|
|
595
|
+
}
|
|
549
596
|
const now = opts.now ?? (() => Date.now());
|
|
550
597
|
const scope = opts.scope ?? "default";
|
|
551
|
-
const parkedResume = opts.parkedResume, claimHolder = opts.holder;
|
|
598
|
+
const parkedResume = opts.parkedResume === undefined ? undefined : readWorkflowParkedDecisions(opts.parkedResume, "runWorkflow: parkedResume"), claimHolder = opts.holder;
|
|
599
|
+
let launchUnkept = false;
|
|
552
600
|
const runId = opts.runId ?? randomUUID();
|
|
553
601
|
if (opts.runId !== undefined && isWorkflowRunActive(opts.runId)) {
|
|
554
602
|
throw new Error(`startWorkflow: runId "${opts.runId}" is already an active workflow run in this process`);
|
|
@@ -558,6 +606,8 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
558
606
|
}
|
|
559
607
|
const concurrency = normalizeConcurrency(opts.concurrency);
|
|
560
608
|
const agentRegistry = workflowAgentRegistry(opts);
|
|
609
|
+
const holdKeeper = holdKeeperDeclarations(runner);
|
|
610
|
+
const launchingTool = internals?.launchingTool;
|
|
561
611
|
const modelCatalog = runner.agentCatalog?.models;
|
|
562
612
|
const store = opts.store;
|
|
563
613
|
const maxAgents = normalizeWorkflowHardCap("maxAgents", opts.maxAgents);
|
|
@@ -580,6 +630,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
580
630
|
signalSources.push(timeoutController.signal);
|
|
581
631
|
const workflowSignal = signalSources.length === 1 ? signalSources[0] : AbortSignal.any(signalSources);
|
|
582
632
|
let timeoutTimer;
|
|
633
|
+
let keeperHold;
|
|
583
634
|
let storeRev = 0;
|
|
584
635
|
const notifier = createSafeNotifier(opts.onNotifyError !== undefined ? { onError: opts.onNotifyError } : undefined);
|
|
585
636
|
const emit = (e) => {
|
|
@@ -619,7 +670,6 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
619
670
|
...(opts.description !== undefined ? { description: opts.description } : {}),
|
|
620
671
|
...(opts.sourceTaskId !== undefined ? { sourceTaskId: opts.sourceTaskId } : {}),
|
|
621
672
|
...(opts.originatingSessionId !== undefined ? { originatingSessionId: opts.originatingSessionId } : {}),
|
|
622
|
-
...(opts.effectiveArgs !== undefined ? { effectiveArgs: opts.effectiveArgs } : {}),
|
|
623
673
|
status: "running",
|
|
624
674
|
phases: (opts.phases ?? []).map((ph) => ({
|
|
625
675
|
title: ph.title,
|
|
@@ -745,7 +795,6 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
745
795
|
...(opts.onForwardEvent ? { onForwardEvent: opts.onForwardEvent } : {}),
|
|
746
796
|
...(opts.inheritedGate !== undefined ? { inheritedGate: opts.inheritedGate } : {}),
|
|
747
797
|
...(agentCeiling !== undefined ? { toolCeiling: agentCeiling } : {}),
|
|
748
|
-
...(internals?.mcpPool !== undefined ? { mcpPool: internals.mcpPool } : {}),
|
|
749
798
|
...((opts.rootSessionId ?? opts.originatingSessionId) !== undefined ? { rootSessionId: opts.rootSessionId ?? opts.originatingSessionId } : {}),
|
|
750
799
|
...(opts.rootSessionId !== undefined && opts.rootSessionIncarnation !== undefined ? { rootSessionIncarnation: opts.rootSessionIncarnation } : {}),
|
|
751
800
|
...(opts.rootSessionId !== undefined && opts.rootSessionScope !== undefined ? { rootSessionScope: opts.rootSessionScope } : {}),
|
|
@@ -777,7 +826,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
777
826
|
if (!bceSink)
|
|
778
827
|
return;
|
|
779
828
|
const id = waIdOf(callKey);
|
|
780
|
-
bceLive.set(id, { callKey, label, ...(agentType !== undefined ? { agentType } : {}), ...(sessionId !== undefined ? { sessionId } : {}), ...(model !== undefined ? { model } : {}), generation: 1 });
|
|
829
|
+
bceLive.set(id, { callKey, label, ...(agentType !== undefined ? { agentType } : {}), ...(sessionId !== undefined ? { sessionId } : {}), ...(sessionId !== undefined && judgedOwnerSeat({}, opts) === undefined ? { verified: true } : {}), ...(model !== undefined ? { model } : {}), generation: 1 });
|
|
781
830
|
bceEmit({
|
|
782
831
|
kind: "spawn",
|
|
783
832
|
taskId: id,
|
|
@@ -792,6 +841,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
792
841
|
name: label,
|
|
793
842
|
...(opts.parentTaskId !== undefined ? { parentTaskId: opts.parentTaskId } : {}),
|
|
794
843
|
workflowRunId: runId,
|
|
844
|
+
...askedAgainBit(callKey),
|
|
795
845
|
...(opts.originatingSessionId !== undefined ? { parentSessionId: opts.originatingSessionId } : {}),
|
|
796
846
|
...((opts.rootSessionId ?? opts.originatingSessionId) !== undefined ? { rootSessionId: opts.rootSessionId ?? opts.originatingSessionId } : {}),
|
|
797
847
|
startedAt: Date.now(),
|
|
@@ -800,8 +850,23 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
800
850
|
};
|
|
801
851
|
const bceBindSession = (callKey, sessionId) => {
|
|
802
852
|
const row = bceLive.get(waIdOf(callKey));
|
|
853
|
+
if (row === undefined)
|
|
854
|
+
return;
|
|
855
|
+
row.sessionId = sessionId;
|
|
856
|
+
delete row.verified;
|
|
857
|
+
};
|
|
858
|
+
const verifyAgentSession = (rec, sessionId) => {
|
|
859
|
+
if (finalized)
|
|
860
|
+
return false;
|
|
861
|
+
rec.sessionId = sessionId;
|
|
862
|
+
const row = bceLive.get(waIdOf(rec.callKey));
|
|
803
863
|
if (row !== undefined)
|
|
804
|
-
row.sessionId = sessionId;
|
|
864
|
+
(row.sessionId = sessionId), (row.verified = true);
|
|
865
|
+
return true;
|
|
866
|
+
};
|
|
867
|
+
const foldAgentSession = (rec, result) => {
|
|
868
|
+
if (result.sessionId)
|
|
869
|
+
verifyAgentSession(rec, result.sessionId);
|
|
805
870
|
};
|
|
806
871
|
const bceGeneration = (callKey, generation) => {
|
|
807
872
|
const row = bceLive.get(waIdOf(callKey));
|
|
@@ -824,6 +889,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
824
889
|
owner: runId,
|
|
825
890
|
...bceParentToolCall,
|
|
826
891
|
workflowRunId: runId,
|
|
892
|
+
...askedAgainBit(callKey),
|
|
827
893
|
...(scope !== undefined ? { scope } : {}),
|
|
828
894
|
...(row.agentType !== undefined ? { agentType: row.agentType } : { agentType: "workflow-agent" }),
|
|
829
895
|
...(row.model !== undefined ? { model: row.model } : {}),
|
|
@@ -836,14 +902,13 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
836
902
|
usage: e.usage,
|
|
837
903
|
});
|
|
838
904
|
};
|
|
839
|
-
const bceTerminal = (callKey, status, summary,
|
|
905
|
+
const bceTerminal = (callKey, status, summary, stats) => {
|
|
840
906
|
if (!bceSink)
|
|
841
907
|
return;
|
|
842
908
|
const id = waIdOf(callKey);
|
|
843
909
|
const row = bceLive.get(id);
|
|
844
910
|
if (row === undefined || !bceLive.delete(id))
|
|
845
911
|
return;
|
|
846
|
-
const coord = sessionId ?? row.sessionId;
|
|
847
912
|
bceEmit({
|
|
848
913
|
kind: "terminal",
|
|
849
914
|
taskId: id,
|
|
@@ -851,8 +916,9 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
851
916
|
owner: runId,
|
|
852
917
|
...bceParentToolCall,
|
|
853
918
|
workflowRunId: runId,
|
|
919
|
+
...askedAgainBit(callKey),
|
|
854
920
|
...(scope !== undefined ? { scope } : {}),
|
|
855
|
-
...(
|
|
921
|
+
...(row.sessionId === undefined ? {} : row.verified === true ? { sessionId: row.sessionId, transcriptId: row.sessionId } : { sessionWithdrawn: true }),
|
|
856
922
|
status,
|
|
857
923
|
seq: row.generation,
|
|
858
924
|
summary: boundedRedactedSummary(summary, 300),
|
|
@@ -898,11 +964,95 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
898
964
|
let resumeClaim;
|
|
899
965
|
const replayByOrdinal = [];
|
|
900
966
|
let divergence;
|
|
967
|
+
let resumeRefusal;
|
|
968
|
+
const refusalTerminal = (thrown) => (workflowSignal?.aborted !== true ? resumeRefusal : thrown === resumeRefusal ? (workflowSignal.reason ?? new Error("workflow aborted")) : thrown);
|
|
901
969
|
let parkedLeg;
|
|
970
|
+
const reachedParkOrdinals = new Set();
|
|
971
|
+
const stepAskedAgainAfter = (callKey) => {
|
|
972
|
+
const prior = replayByOrdinal[callKeyOrdinal(callKey)];
|
|
973
|
+
const t = prior?.callKey === callKey ? prior.result?.terminal : undefined;
|
|
974
|
+
if (t?.kind !== "failed" || t.code !== "workflow.park_not_pending")
|
|
975
|
+
return undefined;
|
|
976
|
+
const status = t.detail?.kind === "coded" ? t.detail.detail.status : undefined;
|
|
977
|
+
return PARK_NOT_PENDING_STATUSES.find((s) => s === status);
|
|
978
|
+
};
|
|
979
|
+
const askedAgainBit = (callKey) => {
|
|
980
|
+
const status = stepAskedAgainAfter(callKey);
|
|
981
|
+
return status === "expired" || status === "absent" ? { workflowStepAskedAgain: true } : {};
|
|
982
|
+
};
|
|
983
|
+
const memberAt = (callKey, label) => ({ runId, label, ...(askedAgainBit(callKey).workflowStepAskedAgain === true ? { askedAgain: true } : {}) });
|
|
984
|
+
const memberSeat = (callKey, label) => ({ workflowMember: memberAt(callKey, label) });
|
|
985
|
+
const memberStamp = (e, callKey, label) => stampWorkflowMember(e, memberAt(callKey, label));
|
|
986
|
+
const storeWithin = (p) => finalizeWithin(timers, p.then((value) => ({ ok: true, value }), () => ({ ok: false })), { ok: false }, true);
|
|
987
|
+
let admissionSuccessors;
|
|
988
|
+
const successorsAtAdmission = (fromRunId) => (admissionSuccessors ??= store === undefined ? Promise.resolve("unreadable") : workflowRunSuccessors(store, fromRunId, scope, storeWithin));
|
|
989
|
+
const endOf = (r) => ({ runId: r.id, status: r.status, ...(r.errorCode !== undefined ? { errorCode: r.errorCode } : {}) });
|
|
990
|
+
const continuationThatTook = async (key, fromRunId) => {
|
|
991
|
+
const successors = await successorsAtAdmission(fromRunId);
|
|
992
|
+
if (typeof successors === "string")
|
|
993
|
+
return undefined;
|
|
994
|
+
const took = runThatDrove(successors.filter((r) => r.id !== runId), key.callKey);
|
|
995
|
+
return took === undefined ? undefined : endOf(took);
|
|
996
|
+
};
|
|
997
|
+
const continuedBeforeOf = async (fromRunId) => {
|
|
998
|
+
const successors = await successorsAtAdmission(fromRunId);
|
|
999
|
+
if (typeof successors === "string")
|
|
1000
|
+
return undefined;
|
|
1001
|
+
const earlier = successors.filter((r) => r.id !== runId && r.resume?.fromRunId === fromRunId).sort((a, b) => b.startedAt - a.startedAt)[0];
|
|
1002
|
+
return earlier === undefined ? undefined : endOf(earlier);
|
|
1003
|
+
};
|
|
1004
|
+
const PASS_ATTEMPTS = 3;
|
|
1005
|
+
const passParksFrom = async (from, keys) => {
|
|
1006
|
+
let open = keys;
|
|
1007
|
+
for (let attempt = 0; attempt < PASS_ATTEMPTS && open.length > 0 && store !== undefined; attempt++) {
|
|
1008
|
+
const chain = await readWorkflowRunChain(store, from, scope, storeWithin);
|
|
1009
|
+
if (typeof chain === "string")
|
|
1010
|
+
return;
|
|
1011
|
+
const records = [chain.root, ...chain.successors.filter((r) => r.id !== runId)];
|
|
1012
|
+
const entryOf = (key) => chain.root.parks?.find((p) => p.token === key.token && p.parkedBy === from);
|
|
1013
|
+
const stand = (key) => {
|
|
1014
|
+
key.parkedBy = runId;
|
|
1015
|
+
const settled = entryOf(key)?.settledDecisions;
|
|
1016
|
+
if (settled !== undefined)
|
|
1017
|
+
key.settledDecisions = settled;
|
|
1018
|
+
};
|
|
1019
|
+
for (const key of open)
|
|
1020
|
+
if (entryOf(key)?.passedTo === runId)
|
|
1021
|
+
stand(key);
|
|
1022
|
+
open = open.filter((key) => {
|
|
1023
|
+
const entry = entryOf(key);
|
|
1024
|
+
if (entry === undefined || entry.passedTo !== undefined)
|
|
1025
|
+
return false;
|
|
1026
|
+
const holder = workflowParkHolderOf(key.token, records);
|
|
1027
|
+
return holder.kind === "held" && holder.runId === from;
|
|
1028
|
+
});
|
|
1029
|
+
if (open.length === 0)
|
|
1030
|
+
return;
|
|
1031
|
+
const next = structuredClone(chain.root);
|
|
1032
|
+
for (const p of next.parks ?? [])
|
|
1033
|
+
if (p.parkedBy === from && open.some((key) => key.token === p.token))
|
|
1034
|
+
p.passedTo = runId;
|
|
1035
|
+
const won = await storeWithin(Promise.resolve().then(() => store.update(from, scope, next, { rev: chain.root.rev ?? 0 }, { cause: "park_pass" })));
|
|
1036
|
+
if (won.ok && won.value) {
|
|
1037
|
+
for (const key of open)
|
|
1038
|
+
stand(key);
|
|
1039
|
+
return;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
};
|
|
1043
|
+
const standOnUnreachedParks = async () => {
|
|
1044
|
+
const reached = new Set([...run.agents.map((a) => callKeyOrdinal(a.callKey)), ...reachedParkOrdinals]);
|
|
1045
|
+
const candidates = (run.parks ?? []).filter((k) => k.parkedBy !== undefined && k.parkedBy !== runId && Number.isSafeInteger(k.generation) && !reached.has(callKeyOrdinal(k.callKey)));
|
|
1046
|
+
const byNamedRun = new Map();
|
|
1047
|
+
for (const key of candidates)
|
|
1048
|
+
byNamedRun.set(key.parkedBy, [...(byNamedRun.get(key.parkedBy) ?? []), key]);
|
|
1049
|
+
for (const [from, keys] of byNamedRun)
|
|
1050
|
+
await passParksFrom(from, keys);
|
|
1051
|
+
};
|
|
902
1052
|
const parkedError = () => {
|
|
903
1053
|
const p = parkedLeg;
|
|
904
1054
|
const gate = p.paused.terminal.gate;
|
|
905
|
-
return new WorkflowAgentParkedError(p.label, gate.kind, p.paused.terminal.checkpointId, gate.kind === "resource_limit" ? gate.reason : undefined);
|
|
1055
|
+
return new WorkflowAgentParkedError(p.label, gate.kind, p.paused.terminal.checkpointId, gate.kind === "resource_limit" ? gate.reason : undefined, stepAskedAgainAfter(p.callKey) !== undefined);
|
|
906
1056
|
};
|
|
907
1057
|
const parkWaits = new Map();
|
|
908
1058
|
const takenParkTokens = new Set();
|
|
@@ -1005,12 +1155,21 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1005
1155
|
const parkedResumeFor = (token) => parkedResume?.find((d) => d.token === token);
|
|
1006
1156
|
const parkedCallChangedError = (ordinal) => Object.assign(new Error(`workflow resume: ordinal ${ordinal} is PARKED on a checkpoint, but the call at that ordinal changed (its call key differs from the journaled one) ` +
|
|
1007
1157
|
(divergence === undefined
|
|
1008
|
-
?
|
|
1158
|
+
? `while no earlier call diverged from the record — the difference is in this call's own inputs (${CALL_INPUTS_THAT_MOVE}). `
|
|
1009
1159
|
: `after replay stopped at agent #${divergence.ordinal} (${divergence.reason}) — the calls from there on ran live, so this call may have been built from a live result rather than the recorded one. `) +
|
|
1010
1160
|
"A fresh spawn there would run beside the pinned child. Resume with the calls up to it unchanged, or decide the checkpoint " +
|
|
1011
1161
|
"through the deployment's approval channel and start a fresh run."), { code: "workflow.parked_call_changed" });
|
|
1012
1162
|
let inFlightLegs = 0;
|
|
1013
1163
|
let legsIdleResolve;
|
|
1164
|
+
let retired = false;
|
|
1165
|
+
const retire = () => {
|
|
1166
|
+
if (retired)
|
|
1167
|
+
return;
|
|
1168
|
+
retired = true;
|
|
1169
|
+
keeperHold?.release();
|
|
1170
|
+
if (timeoutTimer)
|
|
1171
|
+
clearTimeout(timeoutTimer);
|
|
1172
|
+
};
|
|
1014
1173
|
const legStart = () => {
|
|
1015
1174
|
inFlightLegs += 1;
|
|
1016
1175
|
};
|
|
@@ -1021,6 +1180,8 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1021
1180
|
const r = legsIdleResolve;
|
|
1022
1181
|
legsIdleResolve = undefined;
|
|
1023
1182
|
r?.();
|
|
1183
|
+
if (finalized)
|
|
1184
|
+
retire();
|
|
1024
1185
|
}
|
|
1025
1186
|
};
|
|
1026
1187
|
const awaitLegsIdle = async (signal) => {
|
|
@@ -1080,29 +1241,63 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1080
1241
|
result: "",
|
|
1081
1242
|
stats: { turns: 0, tokens: 0, costMicroUsd: 0, usageMissing: true },
|
|
1082
1243
|
terminal: { kind: "paused", gate: cp.gate, token: cp.token, ...(cp.checkpointId !== undefined ? { checkpointId: cp.checkpointId } : {}) },
|
|
1244
|
+
continuesFrom: { none: "run_open" },
|
|
1083
1245
|
});
|
|
1246
|
+
const unresumableRowResult = (drive, callKey, err) => {
|
|
1247
|
+
const row = drive.row;
|
|
1248
|
+
if (row === undefined || row.kind === "ok")
|
|
1249
|
+
return undefined;
|
|
1250
|
+
const reason = readMember(readMember(err, "detail"), "reason");
|
|
1251
|
+
if (codeOf(err) !== row.code || reason !== row.reason)
|
|
1252
|
+
return undefined;
|
|
1253
|
+
return {
|
|
1254
|
+
taskId: callKey,
|
|
1255
|
+
sessionId: drive.paused.sessionId,
|
|
1256
|
+
terminal: { kind: "failed", code: row.code, message: `${row.reason !== undefined ? `(${row.reason}) ` : ""}${row.sentence} The call did not run.` },
|
|
1257
|
+
result: "", resultEntryIds: [],
|
|
1258
|
+
intake: { committed: false },
|
|
1259
|
+
continuesFrom: { none: "nothing_taken_in" },
|
|
1260
|
+
stats: { turns: 0, tokens: 0, costMicroUsd: 0, usageMissing: true },
|
|
1261
|
+
};
|
|
1262
|
+
};
|
|
1084
1263
|
const driveInternals = (base, drive) => ({ ...base, ...(drive.inheritedGate !== undefined ? { inheritedGate: drive.inheritedGate } : {}), ...(claimHolder !== undefined ? { holder: claimHolder } : {}) });
|
|
1085
1264
|
const driveRefusalText = (err, drive) => {
|
|
1086
1265
|
const text = withoutToken(errText(err), drive.token);
|
|
1087
1266
|
return claimHolder === undefined || claimHolder === "" ? text : text.split(claimHolder).join("<holder>");
|
|
1088
1267
|
};
|
|
1089
|
-
const
|
|
1268
|
+
const noteDecision = (drive, callKey, result, code) => {
|
|
1269
|
+
if (drive.decisionId === undefined || run.resume === undefined || finalized)
|
|
1270
|
+
return;
|
|
1271
|
+
const decisions = (run.resume.decisions ??= []);
|
|
1272
|
+
if (decisions.some((d) => d.decisionId === drive.decisionId && d.callKey === callKey))
|
|
1273
|
+
return;
|
|
1274
|
+
decisions.push({ ordinal: callKeyOrdinal(callKey), callKey, decisionId: drive.decisionId, result, ...(code !== undefined && code !== "" ? { code } : {}) });
|
|
1275
|
+
};
|
|
1276
|
+
const codeOf = (err) => {
|
|
1277
|
+
const c = readMember(err, "code");
|
|
1278
|
+
return typeof c === "string" ? c : undefined;
|
|
1279
|
+
};
|
|
1280
|
+
function disposeParkedOrdinal(truth, ordinal, callKey, entry = parkedResumeFor(truth.key.token)) {
|
|
1281
|
+
reachedParkOrdinals.add(ordinal);
|
|
1090
1282
|
if (truth.key.callKey !== callKey)
|
|
1091
1283
|
throw parkedCallChangedError(ordinal);
|
|
1092
1284
|
if (truth.kind === "not_pending") {
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1285
|
+
const status = truth.status === "absent" ? "absent" : truth.status === "expired" ? "expired" : "resolved";
|
|
1286
|
+
const taken = truth.takenBy;
|
|
1287
|
+
const why = status === "expired" ? "expired"
|
|
1288
|
+
: status === "absent" ? "was removed"
|
|
1289
|
+
: taken !== undefined ? `was decided, and its approval was taken by another continuation of this run — run "${taken.runId}", which ended ${taken.status}${taken.errorCode !== undefined ? ` (${taken.errorCode})` : ""}`
|
|
1290
|
+
: "was decided outside this run";
|
|
1096
1291
|
const result = {
|
|
1097
1292
|
taskId: callKey,
|
|
1098
1293
|
sessionId: truth.key.sessionId,
|
|
1099
1294
|
terminal: {
|
|
1100
1295
|
kind: "failed",
|
|
1101
|
-
code: "workflow.park_not_pending",
|
|
1102
|
-
message: `the checkpoint this call was parked on is ${truth.status}${truth.checkpointId !== undefined ? ` (checkpoint ${truth.checkpointId})` : ""} — decided, expired or reaped outside this workflow; settled as failed on the resume's acknowledgement. The call did not run.`,
|
|
1296
|
+
...thrownFailureOf({ code: "workflow.park_not_pending", detail: { status, ordinal, ...(truth.checkpointId !== undefined ? { checkpointId: truth.checkpointId } : {}) } }, `the checkpoint this call was parked on is no longer waiting for a decision: it ${why}${truth.checkpointId !== undefined ? ` (checkpoint ${truth.checkpointId})` : ""}. The call did not run here; it is recorded as failed and the script continues.`),
|
|
1103
1297
|
},
|
|
1104
1298
|
result: "", resultEntryIds: [],
|
|
1105
1299
|
intake: { committed: false },
|
|
1300
|
+
continuesFrom: { none: "nothing_taken_in" },
|
|
1106
1301
|
stats: { turns: 0, tokens: 0, costMicroUsd: 0, usageMissing: true },
|
|
1107
1302
|
};
|
|
1108
1303
|
return { kind: "settle", result };
|
|
@@ -1111,12 +1306,13 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1111
1306
|
if (truth.material === undefined)
|
|
1112
1307
|
emitRunLog(`resume: ordinal ${ordinal} re-parks from its checkpoint row alone — the origin run's journal entry for the park was not readable or did not match the recorded park (empty result, zero stats).`);
|
|
1113
1308
|
const gate = truth.cp.gate;
|
|
1114
|
-
const outcome = entry
|
|
1309
|
+
const outcome = entry !== undefined ? entry.outcome : gate.kind === "resource_limit" && gate.reason === "preempt" ? { gate: "resource_limit", decision: "continue" } : undefined;
|
|
1115
1310
|
if (outcome !== undefined) {
|
|
1116
|
-
|
|
1311
|
+
const accounted = entry?.decisionId !== undefined && parkedResume?.includes(entry) === true ? { decisionId: entry.decisionId } : {};
|
|
1312
|
+
return { kind: "drive", drive: { token: truth.key.token, outcome, ...(entry?.inheritedGate !== undefined ? { inheritedGate: entry.inheritedGate } : {}), sessionId: paused.sessionId || undefined, paused, row: judgeCheckpointRow(truth.cp), ...accounted } };
|
|
1117
1313
|
}
|
|
1118
1314
|
return { kind: "repark", paused };
|
|
1119
|
-
}
|
|
1315
|
+
}
|
|
1120
1316
|
const deliverParkDecisions = async (decisions) => {
|
|
1121
1317
|
const ending = () => ({ kind: "suspending", ended: done.then(() => undefined, () => undefined) });
|
|
1122
1318
|
if (parkedLeg !== undefined || finalized)
|
|
@@ -1153,11 +1349,6 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1153
1349
|
results[at] = "not_parked_here";
|
|
1154
1350
|
continue;
|
|
1155
1351
|
}
|
|
1156
|
-
if (disposition.kind === "repark") {
|
|
1157
|
-
seatParkWait(w);
|
|
1158
|
-
results[at] = "kept_parked";
|
|
1159
|
-
continue;
|
|
1160
|
-
}
|
|
1161
1352
|
takenParkTokens.add(w.key.token);
|
|
1162
1353
|
if (disposition.kind === "settle") {
|
|
1163
1354
|
w.answer({ kind: "settle", result: disposition.result });
|
|
@@ -1196,7 +1387,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1196
1387
|
};
|
|
1197
1388
|
let journalTail = Promise.resolve();
|
|
1198
1389
|
const JOURNAL_DRAIN_MAX_MS = 5_000;
|
|
1199
|
-
const
|
|
1390
|
+
const awaitedAppends = new Map();
|
|
1200
1391
|
const lastAppendByCall = new Map();
|
|
1201
1392
|
const trackJournalWrite = (append, callKey) => {
|
|
1202
1393
|
const start = () => {
|
|
@@ -1211,19 +1402,19 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1211
1402
|
const write = prior === undefined ? start() : prior.then(start, start);
|
|
1212
1403
|
lastAppendByCall.set(callKey, write.catch(() => undefined));
|
|
1213
1404
|
if (finalized)
|
|
1214
|
-
return
|
|
1405
|
+
return Promise.resolve();
|
|
1215
1406
|
const written = new Promise((resolve, reject) => {
|
|
1216
1407
|
const handle = timers.setTimeout(() => {
|
|
1217
|
-
|
|
1408
|
+
awaitedAppends.delete(handle);
|
|
1218
1409
|
const fault = new WorkflowJournalAppendTimeoutError(runId, callKeyOrdinal(callKey), journalAppendTimeoutMs);
|
|
1219
1410
|
emitRunLog(`resume-journal: ${fault.message}`);
|
|
1220
1411
|
reject(fault);
|
|
1221
1412
|
}, journalAppendTimeoutMs);
|
|
1222
1413
|
handle?.ref?.();
|
|
1223
|
-
|
|
1414
|
+
awaitedAppends.set(handle, resolve);
|
|
1224
1415
|
const settled = () => {
|
|
1225
1416
|
timers.clearTimeout(handle);
|
|
1226
|
-
|
|
1417
|
+
awaitedAppends.delete(handle);
|
|
1227
1418
|
};
|
|
1228
1419
|
Promise.resolve(write).then(() => {
|
|
1229
1420
|
settled();
|
|
@@ -1236,7 +1427,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1236
1427
|
journalTail = journalTail.then(() => written).catch(() => undefined);
|
|
1237
1428
|
return written;
|
|
1238
1429
|
};
|
|
1239
|
-
const durableApprovalInherit = (s) => s.durableApproval === undefined && opts.defaultDurableApproval !== undefined ? { durableApproval: { ...opts.defaultDurableApproval } } : {};
|
|
1430
|
+
const durableApprovalInherit = (s) => s.durableApproval === undefined && opts.defaultDurableApproval !== undefined && !launchUnkept ? { durableApproval: { ...opts.defaultDurableApproval } } : {};
|
|
1240
1431
|
const journalDurableResult = (result) => {
|
|
1241
1432
|
const t = result.terminal;
|
|
1242
1433
|
if (t === undefined || t.kind !== "failed" || typeof t.message !== "string" || t.message === "")
|
|
@@ -1303,8 +1494,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1303
1494
|
rec.status = "parked";
|
|
1304
1495
|
rec.parkedCheckpointToken = paused.terminal.token;
|
|
1305
1496
|
rec.taskStatus = terminalProjection(paused.terminal).status;
|
|
1306
|
-
|
|
1307
|
-
rec.sessionId = paused.sessionId;
|
|
1497
|
+
foldAgentSession(rec, paused);
|
|
1308
1498
|
setLegRunId(rec, paused);
|
|
1309
1499
|
rec.endedAt = now();
|
|
1310
1500
|
rec.stats = { tokens: s.tokens ?? 0, turns: s.turns ?? 0, costMicroUsd: s.costMicroUsd };
|
|
@@ -1317,7 +1507,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1317
1507
|
const parks = run.parks ?? (run.parks = []);
|
|
1318
1508
|
const at = parks.findIndex((e) => e.callKey === rec.callKey);
|
|
1319
1509
|
const held = at === -1 ? undefined : parks[at];
|
|
1320
|
-
const holder = { parkedBy: runId, generation: held?.generation ?? 0 };
|
|
1510
|
+
const holder = { parkedBy: runId, generation: held?.generation ?? 0, ...(held?.token === paused.terminal.token && held.settledDecisions !== undefined ? { settledDecisions: held.settledDecisions } : {}) };
|
|
1321
1511
|
const key = held !== undefined && held.token === paused.terminal.token && held.originUnconfirmed !== true
|
|
1322
1512
|
? { callKey: rec.callKey, sessionId: paused.sessionId, token: paused.terminal.token, originRunId: held.originRunId, ...holder }
|
|
1323
1513
|
: { callKey: rec.callKey, sessionId: paused.sessionId, token: paused.terminal.token, originRunId: runId, originUnconfirmed: true, ...holder };
|
|
@@ -1371,6 +1561,8 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1371
1561
|
agentPhaseOf.set(rec, phaseInstance);
|
|
1372
1562
|
emit({ type: "agent_start", runId, label, phase, ...(groupId !== undefined ? { groupId } : {}), callKey, prompt, ...(model !== undefined ? { model } : {}), ...(d.kind === "repark" ? { replayed: true } : {}), ts: at });
|
|
1373
1563
|
bceSpawn(callKey, label, agentOpts.agentType, d.kind === "repark", (d.kind === "repark" ? d.paused.sessionId : d.result.sessionId) || undefined, model);
|
|
1564
|
+
if (d.kind === "repark")
|
|
1565
|
+
foldAgentSession(rec, d.paused);
|
|
1374
1566
|
return rec;
|
|
1375
1567
|
};
|
|
1376
1568
|
const settleParkedCall = async (rec, result, activityTail, agentOpts) => {
|
|
@@ -1434,6 +1626,11 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1434
1626
|
let groupDepth = 0;
|
|
1435
1627
|
const MAX_GROUP_DEPTH = 32;
|
|
1436
1628
|
let finalized = false;
|
|
1629
|
+
const latchFinalized = () => {
|
|
1630
|
+
finalized = true;
|
|
1631
|
+
if (inFlightLegs === 0)
|
|
1632
|
+
retire();
|
|
1633
|
+
};
|
|
1437
1634
|
const closeOpenMarker = (status) => {
|
|
1438
1635
|
if (!openMarkerPhase)
|
|
1439
1636
|
return;
|
|
@@ -1598,6 +1795,8 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1598
1795
|
if (finalized) {
|
|
1599
1796
|
throw new Error(`workflow run already finalized — ${lane} cannot be called after the script returned`);
|
|
1600
1797
|
}
|
|
1798
|
+
if (resumeRefusal !== undefined)
|
|
1799
|
+
throw resumeRefusal;
|
|
1601
1800
|
const effectiveSignal = spec.signal ?? agentOpts.signal ?? workflowSignal;
|
|
1602
1801
|
if (effectiveSignal?.aborted)
|
|
1603
1802
|
throw new Error("workflow aborted");
|
|
@@ -1663,7 +1862,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1663
1862
|
}
|
|
1664
1863
|
const review = opts.autoModeReview;
|
|
1665
1864
|
if (review === undefined)
|
|
1666
|
-
return runSpec;
|
|
1865
|
+
return { spec: runSpec };
|
|
1667
1866
|
const schema = runSpec.outputSchema;
|
|
1668
1867
|
let schemaText;
|
|
1669
1868
|
let specToLaunch = runSpec;
|
|
@@ -1733,10 +1932,11 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1733
1932
|
throw new Error("workflow aborted");
|
|
1734
1933
|
if (finalized)
|
|
1735
1934
|
throw new Error(`workflow run already finalized — ${lane} cannot spawn after the run ended`);
|
|
1736
|
-
|
|
1737
|
-
|
|
1935
|
+
const reading = readDelegationReview({ verdict, toolName: WORKFLOW_TOOL_NAME, toolCallId: opts.parentToolCallId ?? `${runId}:${callKey}`, site: "spawn", subject: reviewSubjectOf(label), seat: review.unavailable, aborted: false });
|
|
1936
|
+
if (reading.kind === "block") {
|
|
1937
|
+
throw new WorkflowAgentBlockedError(label, reading.category ?? "", boundedRedactedSummary(reading.reason, MAX_REVIEW_REASON_CHARS));
|
|
1738
1938
|
}
|
|
1739
|
-
return specToLaunch;
|
|
1939
|
+
return { spec: specToLaunch, ...(reading.unreviewed !== undefined ? { unreviewed: reading.unreviewed } : {}) };
|
|
1740
1940
|
};
|
|
1741
1941
|
const createUsageBeat = (rec) => {
|
|
1742
1942
|
let beatTokens = 0;
|
|
@@ -1774,8 +1974,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1774
1974
|
accumulateStats(result, true);
|
|
1775
1975
|
rec.status = result.terminal.kind === "completed" ? "completed" : "failed";
|
|
1776
1976
|
rec.taskStatus = terminalProjection(result.terminal).status;
|
|
1777
|
-
|
|
1778
|
-
rec.sessionId = result.sessionId;
|
|
1977
|
+
foldAgentSession(rec, result);
|
|
1779
1978
|
setLegRunId(rec, result);
|
|
1780
1979
|
rec.endedAt = now();
|
|
1781
1980
|
rec.stats = { tokens: s.tokens ?? 0, turns: s.turns ?? 0, costMicroUsd: s.costMicroUsd };
|
|
@@ -1787,7 +1986,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1787
1986
|
foldLegApprovalReport(rec, result);
|
|
1788
1987
|
emit({ type: "agent_end", runId, label: rec.label, phase: rec.phase, ...(rec.groupId !== undefined ? { groupId: rec.groupId } : {}), status: rec.status, output, ...(rec.errorCode !== undefined ? { errorCode: rec.errorCode } : {}), ...(result.stats.toolCalls !== undefined ? { toolCalls: result.stats.toolCalls } : {}), ...(result.model !== undefined ? { modelResolved: result.model } : {}), ts: rec.endedAt });
|
|
1789
1988
|
void persist("update");
|
|
1790
|
-
bceTerminal(rec.callKey, rec.status === "completed" ? "completed" : "failed", output,
|
|
1989
|
+
bceTerminal(rec.callKey, rec.status === "completed" ? "completed" : "failed", output, rec.stats);
|
|
1791
1990
|
await journalAppend(rec.callKey, result, rec.label);
|
|
1792
1991
|
if (agentOpts.schema && result.terminal.kind === "completed" && result.structuredOutput === undefined) {
|
|
1793
1992
|
throw new WorkflowAgentSchemaError(rec.label, result);
|
|
@@ -1798,7 +1997,14 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1798
1997
|
let drive;
|
|
1799
1998
|
const truth = opts.resumeFromRunId !== undefined ? parkedByOrdinal[ordinal] : undefined;
|
|
1800
1999
|
if (truth !== undefined) {
|
|
1801
|
-
|
|
2000
|
+
let d;
|
|
2001
|
+
try {
|
|
2002
|
+
d = disposeParkedOrdinal(truth, ordinal, callKey);
|
|
2003
|
+
}
|
|
2004
|
+
catch (refusal) {
|
|
2005
|
+
resumeRefusal ??= refusal;
|
|
2006
|
+
throw refusal;
|
|
2007
|
+
}
|
|
1802
2008
|
if (d.kind !== "drive")
|
|
1803
2009
|
return { kind: "dispose", d };
|
|
1804
2010
|
drive = d.drive;
|
|
@@ -1818,7 +2024,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1818
2024
|
? "a new call past the journaled prefix — the prior run ended before this point (the intended extend-the-script resume shape)"
|
|
1819
2025
|
: "no journal entry at this ordinal (never recorded, e.g. an oversize result under a pre-tombstone engine, or dropped)"
|
|
1820
2026
|
: cached.callKey !== callKey
|
|
1821
|
-
?
|
|
2027
|
+
? `the call changed — its call key changed from the journaled call's while no earlier call diverged from the record, so the difference is in this call's own inputs (${CALL_INPUTS_THAT_MOVE})`
|
|
1822
2028
|
: cached.result?.terminal?.kind === "failed" && cached.result.terminal.code === JOURNAL_OVERSIZE_ERROR_CODE
|
|
1823
2029
|
? "the prior result exceeded the journal size cap and was never cached"
|
|
1824
2030
|
: `the journaled result was ${cached.result?.terminal?.kind ?? "(no terminal record)"}, not completed`);
|
|
@@ -1859,7 +2065,8 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1859
2065
|
emit({ type: "agent_start", runId, label, phase, ...(groupId !== undefined ? { groupId } : {}), callKey, prompt, ...(replayModel !== undefined ? { model: replayModel } : {}), replayed: true, ts: at });
|
|
1860
2066
|
emit({ type: "agent_end", runId, label, phase, ...(groupId !== undefined ? { groupId } : {}), status: replayRec.status, output: cachedOutput, ...(rs.toolCalls !== undefined ? { toolCalls: rs.toolCalls } : {}), replayed: true, ts: at });
|
|
1861
2067
|
bceSpawn(callKey, label, agentOpts.agentType, true, r.sessionId || undefined, replayModel);
|
|
1862
|
-
|
|
2068
|
+
foldAgentSession(replayRec, r);
|
|
2069
|
+
bceTerminal(callKey, replayRec.status === "completed" ? "completed" : "failed", cachedOutput, replayRec.stats);
|
|
1863
2070
|
accumulateStats(r, false);
|
|
1864
2071
|
void persist("update");
|
|
1865
2072
|
await journalAppend(callKey, r);
|
|
@@ -1924,9 +2131,9 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1924
2131
|
const drive = nextDrive;
|
|
1925
2132
|
legStart();
|
|
1926
2133
|
const release = await sem.acquire();
|
|
1927
|
-
adviseIsolationIfConcurrent(agentOpts);
|
|
1928
2134
|
let result;
|
|
1929
2135
|
try {
|
|
2136
|
+
adviseIsolationIfConcurrent(agentOpts);
|
|
1930
2137
|
if (effectiveSignal?.aborted)
|
|
1931
2138
|
throw new Error("workflow aborted");
|
|
1932
2139
|
if (finalized)
|
|
@@ -1945,20 +2152,23 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1945
2152
|
const typedSpec0 = typed.spec;
|
|
1946
2153
|
const typedSpec = withWorkflowChildSeats(typedSpec0, inheritedModelSnap, inheritedThinkingSnap, runnerRoleMap(runner));
|
|
1947
2154
|
const seatedSpec = applyParentSpecSeat(withWorkflowChildPersona(typedSpec, agentOpts.schema ?? typedSpec.outputSchema), opts.parentSpecSeat);
|
|
1948
|
-
const authInherit = seatedSpec
|
|
2155
|
+
const authInherit = authInheritOf(seatedSpec);
|
|
1949
2156
|
assertChildParkSeat(seatedSpec);
|
|
1950
2157
|
const parkInherit = durableApprovalInherit(seatedSpec);
|
|
1951
2158
|
const preReviewSpec = agentOpts.schema
|
|
1952
2159
|
? { ...seatedSpec, ...authInherit, ...parkInherit, signal: effectiveSignal, outputSchema: agentOpts.schema }
|
|
1953
2160
|
: { ...seatedSpec, ...authInherit, ...parkInherit, signal: effectiveSignal };
|
|
1954
2161
|
judgeHostCeiling(preReviewSpec);
|
|
1955
|
-
const
|
|
2162
|
+
const reviewed = await reviewSpawnBeforeLaunch("ctx.agent", label, callKey, preReviewSpec, effectiveSignal, agentOpts.agentType, drive !== undefined);
|
|
2163
|
+
const runSpec = reviewed.spec;
|
|
2164
|
+
if (reviewed.unreviewed !== undefined)
|
|
2165
|
+
rec.unreviewed = { spawn: reviewed.unreviewed };
|
|
1956
2166
|
const enrichedForward = opts.onForwardEvent !== undefined
|
|
1957
2167
|
? (e) => {
|
|
1958
|
-
opts.onForwardEvent(e.type === "task_progress" || e.type === "task_started" ?
|
|
2168
|
+
opts.onForwardEvent(e.type === "task_progress" || e.type === "task_started" ? memberStamp(e, callKey, label) : e);
|
|
1959
2169
|
}
|
|
1960
2170
|
: undefined;
|
|
1961
|
-
const baseInternals = { ...(agentOpts.isolation ? { isolation: agentOpts.isolation } : {}), ...(opts.parentCwd !== undefined ? { parentCwd: opts.parentCwd } : {}), ...callerPlacementSeats(opts.parentCwd, opts.callerRoot), ...spawnAttribution, ...definitionSeats(typed), ...(await captureFloorSeatsNow()), ...(enrichedForward !== undefined ? { onForwardEvent: enrichedForward } : {}), delegationTaskType: "workflow", agentName: label, onWorkspaceResolved: createWorkspaceObserver(rec) };
|
|
2171
|
+
const baseInternals = { ...(agentOpts.isolation ? { isolation: agentOpts.isolation } : {}), ...(opts.parentCwd !== undefined ? { parentCwd: opts.parentCwd } : {}), ...callerPlacementSeats(opts.parentCwd, opts.callerRoot), ...spawnAttribution, ...definitionSeats(typed), ...(await captureFloorSeatsNow()), ...(enrichedForward !== undefined ? { onForwardEvent: enrichedForward } : {}), delegationTaskType: "workflow", agentName: label, ...memberSeat(callKey, label), onWorkspaceResolved: createWorkspaceObserver(rec) };
|
|
1962
2172
|
let attempts = 0;
|
|
1963
2173
|
let throttleRetried = false;
|
|
1964
2174
|
let lastAttemptReason;
|
|
@@ -1987,20 +2197,28 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1987
2197
|
}
|
|
1988
2198
|
};
|
|
1989
2199
|
const onCallerAbort = () => attemptCtl.abort(new Error("workflow aborted"));
|
|
1990
|
-
effectiveSignal?.
|
|
2200
|
+
if (effectiveSignal?.aborted === true)
|
|
2201
|
+
onCallerAbort();
|
|
2202
|
+
else
|
|
2203
|
+
effectiveSignal?.addEventListener("abort", onCallerAbort, { once: true });
|
|
1991
2204
|
armWatchdog();
|
|
1992
2205
|
const attemptSessionId = drive !== undefined ? drive.sessionId : attempts === 1 ? bornChildSessionId : resolveChildSessionIdAtSpawn(runSpec);
|
|
1993
2206
|
const attemptYield = legYieldSeats();
|
|
1994
2207
|
const attemptSpec = { ...runSpec, ...(attemptSessionId !== undefined ? { sessionId: attemptSessionId } : {}), signal: attemptCtl.signal, ...attemptYield?.spec };
|
|
1995
2208
|
if (attemptSessionId !== undefined && !finalized) {
|
|
1996
|
-
rec.sessionId = attemptSessionId;
|
|
1997
2209
|
bceBindSession(callKey, attemptSessionId);
|
|
2210
|
+
if (drive !== undefined || judgedOwnerSeat(attemptSpec, opts) === undefined)
|
|
2211
|
+
verifyAgentSession(rec, attemptSessionId);
|
|
2212
|
+
else
|
|
2213
|
+
delete rec.sessionId;
|
|
1998
2214
|
void persist("update");
|
|
1999
2215
|
}
|
|
2000
2216
|
const attemptInternals = {
|
|
2001
2217
|
...baseInternals,
|
|
2002
2218
|
...attemptYield?.internals,
|
|
2219
|
+
onSessionVerified: ((attempt) => (id) => void (attempts === attempt && verifyAgentSession(rec, id) && persist("update")))(attempts),
|
|
2003
2220
|
...(inheritedModelRef !== undefined ? { inheritedModelRef } : {}),
|
|
2221
|
+
...(drive === undefined && !runSpec.sessionId && attemptSessionId !== undefined ? { sessionIdMintedBySpawner: true } : {}),
|
|
2004
2222
|
...(bceSink !== undefined
|
|
2005
2223
|
? {
|
|
2006
2224
|
onForwardEvent: (e) => {
|
|
@@ -2154,7 +2372,11 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2154
2372
|
catch (err) {
|
|
2155
2373
|
if (drive !== undefined && !finalized && !thrownIs(err, WorkflowAgentParkedError)) {
|
|
2156
2374
|
emitRunLog(`[park] the parked leg "${label}" could not be driven — the resume was refused before this run consumed the checkpoint (${driveRefusalText(err, drive)}); the park stands on this run's record.`);
|
|
2375
|
+
noteDecision(drive, rec.callKey, "refused", codeOf(err));
|
|
2157
2376
|
release();
|
|
2377
|
+
const unresumable = unresumableRowResult(drive, rec.callKey, err);
|
|
2378
|
+
if (unresumable !== undefined)
|
|
2379
|
+
return await settleParkedCall(rec, unresumable, activityTail, agentOpts);
|
|
2158
2380
|
const answer = await parkAgentLeg(rec, drive.paused, activityTail, false);
|
|
2159
2381
|
if (answer.kind === "settle")
|
|
2160
2382
|
return await settleParkedCall(rec, answer.result, activityTail, agentOpts);
|
|
@@ -2170,8 +2392,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2170
2392
|
if (salvaged !== undefined) {
|
|
2171
2393
|
const salvagedFace = terminalProjection(salvaged.terminal);
|
|
2172
2394
|
rec.taskStatus = salvagedFace.status;
|
|
2173
|
-
|
|
2174
|
-
rec.sessionId = salvaged.sessionId;
|
|
2395
|
+
foldAgentSession(rec, salvaged);
|
|
2175
2396
|
setLegRunId(rec, salvaged);
|
|
2176
2397
|
if (salvagedFace.errorCode !== undefined)
|
|
2177
2398
|
rec.errorCode = salvagedFace.errorCode;
|
|
@@ -2202,6 +2423,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2202
2423
|
taskId: callKey,
|
|
2203
2424
|
sessionId: "",
|
|
2204
2425
|
result: boundedRedactedSummary(thrownText(err), 500), resultEntryIds: [],
|
|
2426
|
+
continuesFrom: thrownIs(err, WorkflowAgentBlockedError) || thrownIs(err, WorkflowBudgetExceededError) ? { none: "nothing_taken_in" } : { none: "unsettled" },
|
|
2205
2427
|
terminal: {
|
|
2206
2428
|
kind: "failed",
|
|
2207
2429
|
...(thrownIs(err, WorkflowAgentBlockedError) ? { code: WORKFLOW_SPAWN_BLOCKED_ERROR_CODE } : thrownIs(err, WorkflowBudgetExceededError) ? { code: err.code } : {}),
|
|
@@ -2211,7 +2433,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2211
2433
|
}, label).catch(() => undefined);
|
|
2212
2434
|
if (!((thrownIs(err, WorkflowBudgetExceededError) || thrownIs(err, WorkflowAgentParkedError)) && rec.startedAt === undefined))
|
|
2213
2435
|
await journaled;
|
|
2214
|
-
bceTerminal(callKey, "failed", rec.output ?? (thrownText(err)), rec.
|
|
2436
|
+
bceTerminal(callKey, "failed", rec.output ?? (thrownText(err)), rec.stats);
|
|
2215
2437
|
}
|
|
2216
2438
|
throw err;
|
|
2217
2439
|
}
|
|
@@ -2224,6 +2446,8 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2224
2446
|
const unstartedDrive = drive !== undefined && resumeNeverStarted(result) ? drive : undefined;
|
|
2225
2447
|
if (unstartedDrive !== undefined)
|
|
2226
2448
|
emitRunLog(`[park] the parked leg "${label}" was driven but the approved action never started (${result.terminal.kind === "failed" ? result.terminal.code : ""}); the park stands.`);
|
|
2449
|
+
if (drive !== undefined)
|
|
2450
|
+
noteDecision(drive, rec.callKey, unstartedDrive !== undefined ? "refused" : "driven", unstartedDrive !== undefined && result.terminal.kind === "failed" ? result.terminal.code : undefined);
|
|
2227
2451
|
const parkOn = isPausedResult(result) ? { paused: result, live: true } : unstartedDrive !== undefined ? { paused: unstartedDrive.paused, live: false } : undefined;
|
|
2228
2452
|
if (parkOn !== undefined) {
|
|
2229
2453
|
const answer = await parkAgentLeg(rec, parkOn.paused, activityTail, parkOn.live);
|
|
@@ -2271,7 +2495,6 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2271
2495
|
const launch = async (drive) => {
|
|
2272
2496
|
legStart();
|
|
2273
2497
|
const release = await sem.acquire();
|
|
2274
|
-
adviseIsolationIfConcurrent(agentOpts);
|
|
2275
2498
|
let released = false;
|
|
2276
2499
|
const releaseOnce = () => {
|
|
2277
2500
|
if (!released) {
|
|
@@ -2292,134 +2515,153 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2292
2515
|
legEnd();
|
|
2293
2516
|
releaseOnce();
|
|
2294
2517
|
};
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
throw new Error(finalized ? "workflow run already finalized — ctx.agentStream cannot spawn after the run ended" : "workflow aborted");
|
|
2299
|
-
}
|
|
2300
|
-
if (parkedLeg !== undefined && drive === undefined) {
|
|
2301
|
-
const parked = parkedError();
|
|
2302
|
-
rec.errorMessage = boundedRedactedSummary(parked.message, MAX_TRANSCRIPT_CHARS);
|
|
2303
|
-
recordFailed();
|
|
2304
|
-
releaseLeg();
|
|
2305
|
-
throw parked;
|
|
2306
|
-
}
|
|
2307
|
-
if (budgetTotal !== null && spent() >= budgetTotal) {
|
|
2308
|
-
if (drive !== undefined) {
|
|
2309
|
-
emitRunLog(`[park] the parked leg "${label}" could not be driven — the run's token ceiling was reached before its turn; the park stands.`);
|
|
2518
|
+
try {
|
|
2519
|
+
if (effectiveSignal?.aborted || finalized) {
|
|
2520
|
+
recordFailed();
|
|
2310
2521
|
releaseLeg();
|
|
2311
|
-
|
|
2522
|
+
throw new Error(finalized ? "workflow run already finalized — ctx.agentStream cannot spawn after the run ended" : "workflow aborted");
|
|
2312
2523
|
}
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
releaseLeg();
|
|
2318
|
-
void journalAppend(callKey, {
|
|
2319
|
-
taskId: callKey,
|
|
2320
|
-
sessionId: "",
|
|
2321
|
-
terminal: { kind: "failed", code: refusal.code, message: boundedRedactedSummary(refusal.message, 500) },
|
|
2322
|
-
result: boundedRedactedSummary(refusal.message, 500), resultEntryIds: [],
|
|
2323
|
-
stats: { turns: 0, tokens: 0, costMicroUsd: 0, usageMissing: true },
|
|
2324
|
-
}).catch(() => undefined);
|
|
2325
|
-
throw refusal;
|
|
2326
|
-
}
|
|
2327
|
-
rec.startedAt = now();
|
|
2328
|
-
const childSessionId = drive !== undefined ? drive.sessionId : resolveChildSessionIdAtSpawn(spec);
|
|
2329
|
-
bceSpawn(callKey, label, agentOpts.agentType, false, childSessionId, model);
|
|
2330
|
-
let stream;
|
|
2331
|
-
try {
|
|
2332
|
-
if (inheritedModelError !== undefined)
|
|
2333
|
-
throw inheritedModelError;
|
|
2334
|
-
const typed = applyWorkflowAgentType(spec, agentOpts.agentType, agentRegistry);
|
|
2335
|
-
const typedSpec0 = typed.spec;
|
|
2336
|
-
const typedSpec = withWorkflowChildSeats(typedSpec0, inheritedModelSnap, inheritedThinkingSnap, runnerRoleMap(runner));
|
|
2337
|
-
const seatedSpec = applyParentSpecSeat(withWorkflowChildPersona(typedSpec, agentOpts.schema ?? typedSpec.outputSchema), opts.parentSpecSeat);
|
|
2338
|
-
const authInherit = seatedSpec.getApiKeyAndHeaders === undefined && opts.defaultGetApiKeyAndHeaders !== undefined ? { getApiKeyAndHeaders: opts.defaultGetApiKeyAndHeaders } : {};
|
|
2339
|
-
assertChildParkSeat(seatedSpec);
|
|
2340
|
-
const parkInherit = durableApprovalInherit(seatedSpec);
|
|
2341
|
-
const baseRunSpec = agentOpts.schema
|
|
2342
|
-
? { ...seatedSpec, ...authInherit, ...parkInherit, signal: effectiveSignal, outputSchema: agentOpts.schema }
|
|
2343
|
-
: { ...seatedSpec, ...authInherit, ...parkInherit, signal: effectiveSignal };
|
|
2344
|
-
const preReviewSpec = childSessionId !== undefined ? { ...baseRunSpec, sessionId: childSessionId } : baseRunSpec;
|
|
2345
|
-
judgeHostCeiling(preReviewSpec);
|
|
2346
|
-
const runSpec = await reviewSpawnBeforeLaunch("ctx.agentStream", label, callKey, preReviewSpec, effectiveSignal, agentOpts.agentType, drive !== undefined);
|
|
2347
|
-
const enrichedForwardS = opts.onForwardEvent !== undefined
|
|
2348
|
-
? (e) => {
|
|
2349
|
-
opts.onForwardEvent(e.type === "task_progress" || e.type === "task_started" ? { ...e, workflowRunId: runId, workflowAgentLabel: label } : e);
|
|
2350
|
-
}
|
|
2351
|
-
: undefined;
|
|
2352
|
-
const streamYield = legYieldSeats();
|
|
2353
|
-
const runInternals = {
|
|
2354
|
-
...streamYield?.internals,
|
|
2355
|
-
...(inheritedModelRef !== undefined ? { inheritedModelRef } : {}),
|
|
2356
|
-
...(agentOpts.isolation ? { isolation: agentOpts.isolation } : {}),
|
|
2357
|
-
...(opts.parentCwd !== undefined ? { parentCwd: opts.parentCwd } : {}),
|
|
2358
|
-
...callerPlacementSeats(opts.parentCwd, opts.callerRoot),
|
|
2359
|
-
...spawnAttribution,
|
|
2360
|
-
...definitionSeats(typed),
|
|
2361
|
-
...(await captureFloorSeatsNow()),
|
|
2362
|
-
...(enrichedForwardS !== undefined ? { onForwardEvent: enrichedForwardS } : {}),
|
|
2363
|
-
delegationTaskType: "workflow",
|
|
2364
|
-
agentName: label,
|
|
2365
|
-
onActivity,
|
|
2366
|
-
onWorkspaceResolved: createWorkspaceObserver(rec),
|
|
2367
|
-
...(bceSink !== undefined
|
|
2368
|
-
? {
|
|
2369
|
-
onForwardEvent: (e) => {
|
|
2370
|
-
if (e.type === "task_progress")
|
|
2371
|
-
bceTick(callKey, e, childSessionId);
|
|
2372
|
-
try {
|
|
2373
|
-
enrichedForwardS?.(e);
|
|
2374
|
-
}
|
|
2375
|
-
catch {
|
|
2376
|
-
}
|
|
2377
|
-
},
|
|
2378
|
-
}
|
|
2379
|
-
: {}),
|
|
2380
|
-
};
|
|
2381
|
-
const legSpec = { ...runSpec, ...streamYield?.spec };
|
|
2382
|
-
stream = drive === undefined
|
|
2383
|
-
? workflowDepthStore.run({ depth: depth + 1 }, () => runner.runTaskStream(legSpec, undefined, runInternals))
|
|
2384
|
-
: await workflowDepthStore.run({ depth: depth + 1 }, () => {
|
|
2385
|
-
const d = drive;
|
|
2386
|
-
const { objective: _o, sessionId: _s, ...resumeConfig } = legSpec;
|
|
2387
|
-
return runner.resumeStream(d.token, d.outcome, resumeConfig, driveInternals(runInternals, d));
|
|
2388
|
-
});
|
|
2389
|
-
}
|
|
2390
|
-
catch (err) {
|
|
2391
|
-
if (drive !== undefined && !finalized) {
|
|
2392
|
-
emitRunLog(`[park] the parked leg "${label}" could not be driven — the resume was refused before this run consumed the checkpoint (${driveRefusalText(err, drive)}); the park stands on this run's record.`);
|
|
2524
|
+
if (parkedLeg !== undefined && drive === undefined) {
|
|
2525
|
+
const parked = parkedError();
|
|
2526
|
+
rec.errorMessage = boundedRedactedSummary(parked.message, MAX_TRANSCRIPT_CHARS);
|
|
2527
|
+
recordFailed();
|
|
2393
2528
|
releaseLeg();
|
|
2394
|
-
|
|
2529
|
+
throw parked;
|
|
2395
2530
|
}
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2531
|
+
if (budgetTotal !== null && spent() >= budgetTotal) {
|
|
2532
|
+
if (drive !== undefined) {
|
|
2533
|
+
emitRunLog(`[park] the parked leg "${label}" could not be driven — the run's token ceiling was reached before its turn; the park stands.`);
|
|
2534
|
+
releaseLeg();
|
|
2535
|
+
return await legAfterPark(drive.paused, [], false);
|
|
2536
|
+
}
|
|
2537
|
+
const refusal = new WorkflowBudgetExceededError(spent(), budgetTotal);
|
|
2538
|
+
rec.errorCode = refusal.code;
|
|
2402
2539
|
rec.errorMessage = boundedRedactedSummary(refusal.message, MAX_TRANSCRIPT_CHARS);
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
if (refusal !== undefined) {
|
|
2407
|
-
await journalAppend(callKey, {
|
|
2540
|
+
recordFailed();
|
|
2541
|
+
releaseLeg();
|
|
2542
|
+
void journalAppend(callKey, {
|
|
2408
2543
|
taskId: callKey,
|
|
2409
2544
|
sessionId: "",
|
|
2410
|
-
terminal: { kind: "failed", code:
|
|
2545
|
+
terminal: { kind: "failed", code: refusal.code, message: boundedRedactedSummary(refusal.message, 500) },
|
|
2411
2546
|
result: boundedRedactedSummary(refusal.message, 500), resultEntryIds: [],
|
|
2547
|
+
continuesFrom: { none: "nothing_taken_in" },
|
|
2412
2548
|
stats: { turns: 0, tokens: 0, costMicroUsd: 0, usageMissing: true },
|
|
2413
2549
|
}).catch(() => undefined);
|
|
2550
|
+
throw refusal;
|
|
2414
2551
|
}
|
|
2415
|
-
|
|
2416
|
-
|
|
2552
|
+
rec.startedAt = now();
|
|
2553
|
+
const childSessionId = drive !== undefined ? drive.sessionId : resolveChildSessionIdAtSpawn(spec);
|
|
2554
|
+
bceSpawn(callKey, label, agentOpts.agentType, false, childSessionId, model);
|
|
2555
|
+
let stream;
|
|
2556
|
+
try {
|
|
2557
|
+
adviseIsolationIfConcurrent(agentOpts);
|
|
2558
|
+
if (inheritedModelError !== undefined)
|
|
2559
|
+
throw inheritedModelError;
|
|
2560
|
+
const typed = applyWorkflowAgentType(spec, agentOpts.agentType, agentRegistry);
|
|
2561
|
+
const typedSpec0 = typed.spec;
|
|
2562
|
+
const typedSpec = withWorkflowChildSeats(typedSpec0, inheritedModelSnap, inheritedThinkingSnap, runnerRoleMap(runner));
|
|
2563
|
+
const seatedSpec = applyParentSpecSeat(withWorkflowChildPersona(typedSpec, agentOpts.schema ?? typedSpec.outputSchema), opts.parentSpecSeat);
|
|
2564
|
+
const authInherit = authInheritOf(seatedSpec);
|
|
2565
|
+
assertChildParkSeat(seatedSpec);
|
|
2566
|
+
const parkInherit = durableApprovalInherit(seatedSpec);
|
|
2567
|
+
const baseRunSpec = agentOpts.schema
|
|
2568
|
+
? { ...seatedSpec, ...authInherit, ...parkInherit, signal: effectiveSignal, outputSchema: agentOpts.schema }
|
|
2569
|
+
: { ...seatedSpec, ...authInherit, ...parkInherit, signal: effectiveSignal };
|
|
2570
|
+
const preReviewSpec = childSessionId !== undefined ? { ...baseRunSpec, sessionId: childSessionId } : baseRunSpec;
|
|
2571
|
+
judgeHostCeiling(preReviewSpec);
|
|
2572
|
+
const reviewed = await reviewSpawnBeforeLaunch("ctx.agentStream", label, callKey, preReviewSpec, effectiveSignal, agentOpts.agentType, drive !== undefined);
|
|
2573
|
+
const runSpec = reviewed.spec;
|
|
2574
|
+
if (reviewed.unreviewed !== undefined)
|
|
2575
|
+
rec.unreviewed = { spawn: reviewed.unreviewed };
|
|
2576
|
+
const enrichedForwardS = opts.onForwardEvent !== undefined
|
|
2577
|
+
? (e) => {
|
|
2578
|
+
opts.onForwardEvent(e.type === "task_progress" || e.type === "task_started" ? memberStamp(e, callKey, label) : e);
|
|
2579
|
+
}
|
|
2580
|
+
: undefined;
|
|
2581
|
+
const streamYield = legYieldSeats();
|
|
2582
|
+
const runInternals = {
|
|
2583
|
+
...streamYield?.internals,
|
|
2584
|
+
onSessionVerified: (id) => void (verifyAgentSession(rec, id) && persist("update")),
|
|
2585
|
+
...(inheritedModelRef !== undefined ? { inheritedModelRef } : {}),
|
|
2586
|
+
...(drive === undefined && !spec.sessionId && childSessionId !== undefined ? { sessionIdMintedBySpawner: true } : {}),
|
|
2587
|
+
...(agentOpts.isolation ? { isolation: agentOpts.isolation } : {}),
|
|
2588
|
+
...(opts.parentCwd !== undefined ? { parentCwd: opts.parentCwd } : {}),
|
|
2589
|
+
...callerPlacementSeats(opts.parentCwd, opts.callerRoot),
|
|
2590
|
+
...spawnAttribution,
|
|
2591
|
+
...definitionSeats(typed),
|
|
2592
|
+
...(await captureFloorSeatsNow()),
|
|
2593
|
+
...(enrichedForwardS !== undefined ? { onForwardEvent: enrichedForwardS } : {}),
|
|
2594
|
+
delegationTaskType: "workflow",
|
|
2595
|
+
agentName: label,
|
|
2596
|
+
...memberSeat(callKey, label),
|
|
2597
|
+
onActivity,
|
|
2598
|
+
onWorkspaceResolved: createWorkspaceObserver(rec),
|
|
2599
|
+
...(bceSink !== undefined
|
|
2600
|
+
? {
|
|
2601
|
+
onForwardEvent: (e) => {
|
|
2602
|
+
if (e.type === "task_progress")
|
|
2603
|
+
bceTick(callKey, e, childSessionId);
|
|
2604
|
+
try {
|
|
2605
|
+
enrichedForwardS?.(e);
|
|
2606
|
+
}
|
|
2607
|
+
catch {
|
|
2608
|
+
}
|
|
2609
|
+
},
|
|
2610
|
+
}
|
|
2611
|
+
: {}),
|
|
2612
|
+
};
|
|
2613
|
+
const legSpec = { ...runSpec, ...streamYield?.spec };
|
|
2614
|
+
stream = drive === undefined
|
|
2615
|
+
? workflowDepthStore.run({ depth: depth + 1 }, () => runner.runTaskStream(legSpec, undefined, runInternals))
|
|
2616
|
+
: await workflowDepthStore.run({ depth: depth + 1 }, () => {
|
|
2617
|
+
const d = drive;
|
|
2618
|
+
const { objective: _o, sessionId: _s, ...resumeConfig } = legSpec;
|
|
2619
|
+
return runner.resumeStream(d.token, d.outcome, resumeConfig, driveInternals(runInternals, d));
|
|
2620
|
+
});
|
|
2621
|
+
}
|
|
2622
|
+
catch (err) {
|
|
2623
|
+
if (drive !== undefined && !finalized) {
|
|
2624
|
+
emitRunLog(`[park] the parked leg "${label}" could not be driven — the resume was refused before this run consumed the checkpoint (${driveRefusalText(err, drive)}); the park stands on this run's record.`);
|
|
2625
|
+
noteDecision(drive, rec.callKey, "refused", codeOf(err));
|
|
2626
|
+
releaseLeg();
|
|
2627
|
+
const unresumable = unresumableRowResult(drive, rec.callKey, err);
|
|
2628
|
+
if (unresumable !== undefined)
|
|
2629
|
+
return { kind: "settled", result: await settleParkedCall(rec, unresumable, [], agentOpts) };
|
|
2630
|
+
return await legAfterPark(drive.paused, [], false);
|
|
2631
|
+
}
|
|
2632
|
+
const spawnMessage = thrownMessageOf(err);
|
|
2633
|
+
if (!finalized && rec.errorMessage === undefined && spawnMessage !== undefined)
|
|
2634
|
+
rec.errorMessage = boundedRedactedSummary(spawnMessage, MAX_TRANSCRIPT_CHARS);
|
|
2635
|
+
const refusal = !finalized && thrownIs(err, WorkflowAgentBlockedError) ? err : undefined;
|
|
2636
|
+
if (refusal !== undefined) {
|
|
2637
|
+
rec.errorCode = WORKFLOW_SPAWN_BLOCKED_ERROR_CODE;
|
|
2638
|
+
rec.errorMessage = boundedRedactedSummary(refusal.message, MAX_TRANSCRIPT_CHARS);
|
|
2639
|
+
}
|
|
2640
|
+
recordFailed();
|
|
2641
|
+
releaseLeg();
|
|
2642
|
+
if (refusal !== undefined) {
|
|
2643
|
+
await journalAppend(callKey, {
|
|
2644
|
+
taskId: callKey,
|
|
2645
|
+
sessionId: "",
|
|
2646
|
+
terminal: { kind: "failed", code: WORKFLOW_SPAWN_BLOCKED_ERROR_CODE, message: boundedRedactedSummary(refusal.message, 500) },
|
|
2647
|
+
result: boundedRedactedSummary(refusal.message, 500), resultEntryIds: [],
|
|
2648
|
+
continuesFrom: { none: "nothing_taken_in" },
|
|
2649
|
+
stats: { turns: 0, tokens: 0, costMicroUsd: 0, usageMissing: true },
|
|
2650
|
+
}).catch(() => undefined);
|
|
2651
|
+
}
|
|
2652
|
+
bceTerminal(callKey, "failed", thrownText(err), undefined);
|
|
2653
|
+
throw err;
|
|
2654
|
+
}
|
|
2655
|
+
if ((drive !== undefined || judgedOwnerSeat(spec, opts) === undefined) && childSessionId !== undefined && !finalized) {
|
|
2656
|
+
verifyAgentSession(rec, childSessionId);
|
|
2657
|
+
void persist("update");
|
|
2658
|
+
}
|
|
2659
|
+
return { kind: "stream", stream, releaseLeg, recordFailed, drive };
|
|
2417
2660
|
}
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2661
|
+
catch (err) {
|
|
2662
|
+
releaseLeg();
|
|
2663
|
+
throw err;
|
|
2421
2664
|
}
|
|
2422
|
-
return { kind: "stream", stream, releaseLeg, recordFailed, drive };
|
|
2423
2665
|
};
|
|
2424
2666
|
const firstLeg = disposition !== undefined ? await legAfterPark(disposition.paused, [], false) : await launch(arm.kind === "live" ? arm.drive : undefined);
|
|
2425
2667
|
if (firstLeg.kind === "settled")
|
|
@@ -2458,16 +2700,21 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2458
2700
|
if (!finalized && partialSpend !== undefined && (partialSpend.tokens > 0 || partialSpend.turns > 0 || (partialSpend.costMicroUsd ?? 0) > 0)) {
|
|
2459
2701
|
accumulateStats({ stats: partialSpend }, true);
|
|
2460
2702
|
}
|
|
2461
|
-
|
|
2462
|
-
|
|
2703
|
+
try {
|
|
2704
|
+
recordFailed();
|
|
2705
|
+
}
|
|
2706
|
+
finally {
|
|
2707
|
+
releaseLeg();
|
|
2708
|
+
}
|
|
2463
2709
|
await journalAppend(callKey, {
|
|
2464
2710
|
taskId: callKey,
|
|
2465
2711
|
sessionId: "",
|
|
2466
2712
|
terminal: { kind: "failed", message: boundedRedactedSummary(thrownText(err), 500) },
|
|
2467
2713
|
result: boundedRedactedSummary(thrownText(err), 500), resultEntryIds: [],
|
|
2714
|
+
continuesFrom: { none: "unsettled" },
|
|
2468
2715
|
stats: { turns: partialSpend?.turns ?? 0, tokens: partialSpend?.tokens ?? 0, costMicroUsd: partialSpend?.costMicroUsd ?? 0 },
|
|
2469
2716
|
}).catch(() => undefined);
|
|
2470
|
-
bceTerminal(callKey, "failed", thrownText(err),
|
|
2717
|
+
bceTerminal(callKey, "failed", thrownText(err), rec.stats);
|
|
2471
2718
|
throw err;
|
|
2472
2719
|
}
|
|
2473
2720
|
rollbackUsageBeat();
|
|
@@ -2478,6 +2725,8 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2478
2725
|
const unstartedDrive = drive !== undefined && resumeNeverStarted(result) ? drive : undefined;
|
|
2479
2726
|
if (unstartedDrive !== undefined)
|
|
2480
2727
|
emitRunLog(`[park] the parked leg "${label}" was driven but the approved action never started (${result.terminal.kind === "failed" ? result.terminal.code : ""}); the park stands.`);
|
|
2728
|
+
if (drive !== undefined)
|
|
2729
|
+
noteDecision(drive, rec.callKey, unstartedDrive !== undefined ? "refused" : "driven", unstartedDrive !== undefined && result.terminal.kind === "failed" ? result.terminal.code : undefined);
|
|
2481
2730
|
const parkOn = isPausedResult(result) ? { paused: result, live: true } : unstartedDrive !== undefined ? { paused: unstartedDrive.paused, live: false } : undefined;
|
|
2482
2731
|
if (parkOn !== undefined) {
|
|
2483
2732
|
const next = await legAfterPark(parkOn.paused, activityTail, parkOn.live);
|
|
@@ -2500,7 +2749,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2500
2749
|
const settled = await Promise.all(list.map((t, i) => Promise.resolve()
|
|
2501
2750
|
.then(t)
|
|
2502
2751
|
.then((v) => ({ ok: true, v }), (e) => ({ ok: false, e, i }))));
|
|
2503
|
-
return foldFanOutSettled(settled, "parallel", errorsOut, emitRunLog);
|
|
2752
|
+
return foldFanOutSettled(settled, "parallel", errorsOut, emitRunLog, resumeRefusal);
|
|
2504
2753
|
},
|
|
2505
2754
|
async pipeline(items, ...stagesAndOpts) {
|
|
2506
2755
|
const itemList = snapshotFanOutList("pipeline", "the item list", items);
|
|
@@ -2520,7 +2769,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2520
2769
|
const settled = await Promise.all(itemList.map((item, index) => stages
|
|
2521
2770
|
.reduce((acc, stage) => acc.then((prev) => stage(prev, item, index)), Promise.resolve(item))
|
|
2522
2771
|
.then((v) => ({ ok: true, v }), (e) => ({ ok: false, e, i: index }))));
|
|
2523
|
-
return foldFanOutSettled(settled, "pipeline", errorsOut, emitRunLog);
|
|
2772
|
+
return foldFanOutSettled(settled, "pipeline", errorsOut, emitRunLog, resumeRefusal);
|
|
2524
2773
|
},
|
|
2525
2774
|
async phase(title, body) {
|
|
2526
2775
|
if (finalized)
|
|
@@ -2638,23 +2887,62 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2638
2887
|
};
|
|
2639
2888
|
workflowSignal?.addEventListener("abort", suspendOnParks, { once: true });
|
|
2640
2889
|
registerWorkflowParkDelivery(runId, deliverParkDecisions);
|
|
2890
|
+
const stampHostFold = () => {
|
|
2891
|
+
try {
|
|
2892
|
+
const digest = opts.hostFoldDigest?.();
|
|
2893
|
+
if (typeof digest === "string" && digest !== "")
|
|
2894
|
+
run.hostFoldDigest = digest;
|
|
2895
|
+
}
|
|
2896
|
+
catch {
|
|
2897
|
+
}
|
|
2898
|
+
};
|
|
2899
|
+
const settleUnreachedDecisions = () => {
|
|
2900
|
+
if (run.resume === undefined)
|
|
2901
|
+
return;
|
|
2902
|
+
for (const entry of parkedResume ?? []) {
|
|
2903
|
+
if (entry.decisionId === undefined)
|
|
2904
|
+
continue;
|
|
2905
|
+
const key = run.parks?.find((p) => p.token === entry.token);
|
|
2906
|
+
if (key === undefined || run.resume.decisions?.some((d) => d.decisionId === entry.decisionId && d.callKey === key.callKey) === true)
|
|
2907
|
+
continue;
|
|
2908
|
+
(run.resume.decisions ??= []).push({ ordinal: callKeyOrdinal(key.callKey), callKey: key.callKey, decisionId: entry.decisionId, result: "not_reached", ...(run.errorCode !== undefined ? { code: run.errorCode } : {}) });
|
|
2909
|
+
}
|
|
2910
|
+
};
|
|
2641
2911
|
const done = (async () => {
|
|
2642
2912
|
try {
|
|
2913
|
+
keeperHold = holdKeeper({ agents: agentRegistry, tools: [launchingTool] });
|
|
2643
2914
|
const runBody = async () => {
|
|
2915
|
+
const launch = opts.launch;
|
|
2916
|
+
if (launch !== undefined && journalKeepsLaunches(journalStore)) {
|
|
2917
|
+
const kept = await finalizeWithin(timers, new Promise((resolve) => resolve(journalStore.recordLaunch(runId, scope, launch))).then(() => "kept", () => "threw"), "timeout");
|
|
2918
|
+
if (kept !== "kept") {
|
|
2919
|
+
launchUnkept = true;
|
|
2920
|
+
emitRunLog(`launch: this run's launch record was not kept (${kept === "timeout" ? `the journal store did not answer within ${WORKFLOW_STORE_WAIT_BOUND_MS}ms` : "the journal store refused it"}) — nothing could continue a card this run parked on, so its agents do not park on approvals.`);
|
|
2921
|
+
}
|
|
2922
|
+
}
|
|
2644
2923
|
if (opts.resumeFromRunId !== undefined && journalStore) {
|
|
2645
2924
|
const usingFallback = journalStore.resumeClaim === undefined;
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2925
|
+
let walkThrew;
|
|
2926
|
+
const walkWithin = (p) => storeWithin(p.catch((err) => ((walkThrew ??= { err }), Promise.reject(err))));
|
|
2927
|
+
const tree = store === undefined ? { root: opts.resumeFromRunId } : await workflowTreeOf(store, opts.resumeFromRunId, scope, walkWithin);
|
|
2928
|
+
if (tree === "unreadable")
|
|
2929
|
+
throw runStoreUnreadableRefusal(clampRunIdText(opts.resumeFromRunId), walkThrew);
|
|
2930
|
+
if (tree === "over_bound")
|
|
2931
|
+
throw new Error(`startWorkflow: resume from "${clampRunIdText(opts.resumeFromRunId)}" was REFUSED — ${WORKFLOW_TREE_OVER_BOUND_REASON}.`);
|
|
2932
|
+
if (finalized)
|
|
2933
|
+
throw new Error("workflow run already finalized — its resume admission takes no claim after the run ended");
|
|
2934
|
+
const verdict = takeWorkflowResumeClaim(journalStore, { sourceRunId: tree.root, newRunId: runId, scope });
|
|
2935
|
+
resumeClaim = { sourceRunId: tree.root, verdict, fallback: usingFallback };
|
|
2650
2936
|
const decision = await verdict;
|
|
2651
2937
|
if (!decision.granted) {
|
|
2652
2938
|
const holder = decision.holder !== undefined ? clampRunIdText(decision.holder) : "";
|
|
2939
|
+
const lapse = claimLapseInstant(decision.expiresAt);
|
|
2653
2940
|
throw new Error(`startWorkflow: resume from "${clampRunIdText(opts.resumeFromRunId)}" was REFUSED — ` +
|
|
2654
2941
|
`another run already holds the resume claim on it${holder ? ` (holder: ${holder})` : " (holder unknown to the store)"}. ` +
|
|
2655
2942
|
"Two concurrent resumes of one source run fork its execution: both replay the same prefix and then " +
|
|
2656
2943
|
"re-run the whole suffix live, duplicating every side effect. Wait for the holder to reach a terminal " +
|
|
2657
|
-
"state (or stop it) and resume again."
|
|
2944
|
+
"state (or stop it) and resume again. If the holder's process stopped without giving the claim back, " +
|
|
2945
|
+
`the claim lapses ${lapse !== undefined ? `at ${lapse} at the latest` : "when the journal store's expiry frees it"}, and the same resume goes through then.`);
|
|
2658
2946
|
}
|
|
2659
2947
|
const entries = judgedJournal(opts.resumeFromRunId, await journalStore.load(opts.resumeFromRunId, scope));
|
|
2660
2948
|
for (const e of entries) {
|
|
@@ -2674,10 +2962,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2674
2962
|
prior = await opts.store.get(opts.resumeFromRunId);
|
|
2675
2963
|
}
|
|
2676
2964
|
catch (err) {
|
|
2677
|
-
|
|
2678
|
-
const errCode = errName !== undefined ? readMember(err, "code") : undefined;
|
|
2679
|
-
const errClass = errName !== undefined ? `${errName}${typeof errCode === "string" ? `/${errCode}` : ""}` : typeof err;
|
|
2680
|
-
throw new WorkflowParkRefusal("workflow.park_truth_unreadable", `startWorkflow: resume from "${fromRunId}" was REFUSED — the prior run's record could not be read from the run store (${errClass}), so its parks cannot be proven.`, { reason: "store_threw" });
|
|
2965
|
+
throw runStoreUnreadableRefusal(fromRunId, { err });
|
|
2681
2966
|
}
|
|
2682
2967
|
if (prior !== null && prior.scope !== scope)
|
|
2683
2968
|
prior = null;
|
|
@@ -2711,7 +2996,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2711
2996
|
if (e === null || typeof e !== "object" || holder === undefined || typeof e.callKey !== "string" || typeof e.sessionId !== "string" || typeof e.token !== "string" || typeof e.originRunId !== "string" || !/^\d+:/.test(e.callKey)) {
|
|
2712
2997
|
throw parkBindingBroken(-1, "a recorded park entry is malformed or its call key has no ordinal");
|
|
2713
2998
|
}
|
|
2714
|
-
offerCandidate(callKeyOrdinal(e.callKey), { callKey: e.callKey, sessionId: e.sessionId, token: e.token, originRunId: e.originRunId, ...(e.originUnconfirmed === true ? { originUnconfirmed: true } : {}), ...holder });
|
|
2999
|
+
offerCandidate(callKeyOrdinal(e.callKey), { callKey: e.callKey, sessionId: e.sessionId, token: e.token, originRunId: e.originRunId, ...(e.originUnconfirmed === true ? { originUnconfirmed: true } : {}), ...holder, ...(Array.isArray(e.settledDecisions) ? { settledDecisions: e.settledDecisions } : {}) });
|
|
2715
3000
|
}
|
|
2716
3001
|
for (const [ord, e] of replayByOrdinal.entries()) {
|
|
2717
3002
|
if (e?.parked === undefined)
|
|
@@ -2745,8 +3030,13 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2745
3030
|
for (const key of inherited) {
|
|
2746
3031
|
const ord = callKeyOrdinal(key.callKey);
|
|
2747
3032
|
let truth = await readParkTruth(parkSeat, key, ord);
|
|
2748
|
-
if (truth.kind === "not_pending"
|
|
3033
|
+
if (truth.kind === "not_pending")
|
|
2749
3034
|
truth = await readParkTruth(parkSeat, key, ord);
|
|
3035
|
+
if (truth.kind === "not_pending" && truth.status === "resolved") {
|
|
3036
|
+
const takenBy = await continuationThatTook(key, fromRunId);
|
|
3037
|
+
if (takenBy !== undefined)
|
|
3038
|
+
truth = { ...truth, takenBy };
|
|
3039
|
+
}
|
|
2750
3040
|
if (truth.kind === "pending") {
|
|
2751
3041
|
const material = await parkMaterialOf(key, ord);
|
|
2752
3042
|
if (material !== undefined)
|
|
@@ -2762,10 +3052,12 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2762
3052
|
run.parks = inherited;
|
|
2763
3053
|
delete run.resumeAdmissionIncomplete;
|
|
2764
3054
|
}
|
|
3055
|
+
const continuedBefore = await continuedBeforeOf(opts.resumeFromRunId);
|
|
2765
3056
|
run.resume = {
|
|
2766
3057
|
fromRunId: clampRunIdText(opts.resumeFromRunId),
|
|
2767
3058
|
journalEntries: entries.length,
|
|
2768
3059
|
replayed: 0,
|
|
3060
|
+
...(continuedBefore !== undefined ? { continuedBefore } : {}),
|
|
2769
3061
|
};
|
|
2770
3062
|
if (entries.length === 0) {
|
|
2771
3063
|
emitRunLog("resume: the prior run's journal yielded NO entries under this run's scope — nothing will replay; the entire script runs live. " +
|
|
@@ -2808,6 +3100,8 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2808
3100
|
await awaitLegsIdle(workflowSignal);
|
|
2809
3101
|
throw parkedError();
|
|
2810
3102
|
}
|
|
3103
|
+
if (resumeRefusal !== undefined)
|
|
3104
|
+
throw refusalTerminal(resumeRefusal);
|
|
2811
3105
|
if (maxResultChars !== undefined) {
|
|
2812
3106
|
let size = 0;
|
|
2813
3107
|
try {
|
|
@@ -2819,7 +3113,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2819
3113
|
if (size > maxResultChars)
|
|
2820
3114
|
throw new WorkflowResultTooLargeError(size, maxResultChars);
|
|
2821
3115
|
}
|
|
2822
|
-
|
|
3116
|
+
latchFinalized();
|
|
2823
3117
|
const unsettledAtTerminal = settleActiveUsageBeats();
|
|
2824
3118
|
stampBudgetOvershoot(unsettledAtTerminal);
|
|
2825
3119
|
closeOpenMarker("completed");
|
|
@@ -2835,6 +3129,8 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2835
3129
|
const completedRunFailures = countAgentFailures();
|
|
2836
3130
|
if (completedRunFailures > 0)
|
|
2837
3131
|
run.agentFailures = completedRunFailures;
|
|
3132
|
+
stampHostFold();
|
|
3133
|
+
settleUnreachedDecisions();
|
|
2838
3134
|
await settleRecordArtifact();
|
|
2839
3135
|
emit({ type: "run_end", runId, status: "completed", ...(completedRunFailures > 0 ? { agentFailures: completedRunFailures } : {}), ts: run.endedAt });
|
|
2840
3136
|
await persist("update");
|
|
@@ -2844,7 +3140,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2844
3140
|
await awaitParksSettled();
|
|
2845
3141
|
if (parkedLeg !== undefined)
|
|
2846
3142
|
await awaitLegsIdle(workflowSignal);
|
|
2847
|
-
|
|
3143
|
+
latchFinalized();
|
|
2848
3144
|
const unsettledOnFailure = settleActiveUsageBeats();
|
|
2849
3145
|
stampBudgetOvershoot(unsettledOnFailure);
|
|
2850
3146
|
stampTimeoutInterruption();
|
|
@@ -2852,8 +3148,12 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2852
3148
|
run.status = "failed";
|
|
2853
3149
|
mintCompletionId(run);
|
|
2854
3150
|
run.endedAt = now();
|
|
3151
|
+
if (parkedLeg === undefined && resumeRefusal !== undefined)
|
|
3152
|
+
err = refusalTerminal(err);
|
|
2855
3153
|
if (parkedLeg !== undefined && !thrownIs(err, WorkflowAgentParkedError))
|
|
2856
3154
|
err = parkedError();
|
|
3155
|
+
if (parkedLeg !== undefined)
|
|
3156
|
+
await standOnUnreachedParks();
|
|
2857
3157
|
run.error = egressThrownText("same-principal", err);
|
|
2858
3158
|
closeAbandonedAgents(run.endedAt);
|
|
2859
3159
|
{
|
|
@@ -2869,6 +3169,8 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2869
3169
|
const failedRunFailures = countAgentFailures();
|
|
2870
3170
|
if (failedRunFailures > 0)
|
|
2871
3171
|
run.agentFailures = failedRunFailures;
|
|
3172
|
+
stampHostFold();
|
|
3173
|
+
settleUnreachedDecisions();
|
|
2872
3174
|
await settleRecordArtifact();
|
|
2873
3175
|
emit({ type: "run_end", runId, status: "failed", ...(failedRunFailures > 0 ? { agentFailures: failedRunFailures } : {}), ts: run.endedAt });
|
|
2874
3176
|
await persist("update");
|
|
@@ -2882,7 +3184,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2882
3184
|
throw err;
|
|
2883
3185
|
}
|
|
2884
3186
|
finally {
|
|
2885
|
-
|
|
3187
|
+
latchFinalized();
|
|
2886
3188
|
yieldIntent?.removeEventListener("abort", onYieldIntent);
|
|
2887
3189
|
yieldLegs.clear();
|
|
2888
3190
|
await new Promise((resolve) => {
|
|
@@ -2895,9 +3197,11 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2895
3197
|
resolve();
|
|
2896
3198
|
});
|
|
2897
3199
|
});
|
|
2898
|
-
for (const pending of
|
|
3200
|
+
for (const [pending, answer] of awaitedAppends) {
|
|
2899
3201
|
timers.clearTimeout(pending);
|
|
2900
|
-
|
|
3202
|
+
answer();
|
|
3203
|
+
}
|
|
3204
|
+
awaitedAppends.clear();
|
|
2901
3205
|
if (resumeClaim !== undefined) {
|
|
2902
3206
|
const granted = await finalizeWithin(timers, resumeClaim.verdict.then((v) => v.granted, () => false), false);
|
|
2903
3207
|
if (granted) {
|
|
@@ -2915,10 +3219,8 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2915
3219
|
}
|
|
2916
3220
|
}
|
|
2917
3221
|
}
|
|
2918
|
-
if (timeoutTimer)
|
|
2919
|
-
clearTimeout(timeoutTimer);
|
|
2920
3222
|
for (const row of [...bceLive.values()]) {
|
|
2921
|
-
bceTerminal(row.callKey, "failed", "abandoned by run finalize", undefined
|
|
3223
|
+
bceTerminal(row.callKey, "failed", "abandoned by run finalize", undefined);
|
|
2922
3224
|
}
|
|
2923
3225
|
workflowSignal?.removeEventListener("abort", suspendOnParks);
|
|
2924
3226
|
closeWorkflowChannel(runId);
|