@sema-agent/core 7.72.0 → 7.74.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +565 -0
- package/dist/agents/inherited-tool-pool.d.ts +26 -1
- package/dist/agents/inherited-tool-pool.js +46 -2
- package/dist/agents/list-agents-tool.js +1 -1
- package/dist/agents/parked-resume-drive.d.ts +10 -0
- package/dist/agents/parked-resume-drive.js +9 -0
- package/dist/agents/retain-ledger.d.ts +3 -0
- package/dist/agents/retain-ledger.js +3 -3
- package/dist/agents/send-message-tool.js +5 -4
- package/dist/agents/send-user-message-tool.d.ts +12 -0
- package/dist/agents/send-user-message-tool.js +67 -0
- package/dist/agents/subagent-steps.d.ts +9 -0
- package/dist/agents/subagent-steps.js +38 -0
- package/dist/agents/subagent.d.ts +2 -0
- package/dist/agents/subagent.js +43 -12
- package/dist/agents/verify.js +23 -8
- package/dist/agents/yield-adoption.js +3 -1
- package/dist/brain/anthropic.d.ts +42 -1
- package/dist/brain/anthropic.js +68 -13
- package/dist/brain/failover.d.ts +5 -0
- package/dist/brain/failover.js +51 -22
- package/dist/brain/model-lane.d.ts +12 -3
- package/dist/brain/model-lane.js +5 -5
- package/dist/brain/open-responses.js +7 -8
- package/dist/brain/openai.js +31 -24
- package/dist/brain/route-adjudicator.d.ts +33 -4
- package/dist/brain/route-adjudicator.js +49 -12
- package/dist/brain/stream-engine.js +166 -156
- package/dist/brain/stream-shared.d.ts +4 -3
- package/dist/brain/stream-shared.js +2 -2
- package/dist/core/actions-digest.d.ts +43 -0
- package/dist/core/actions-digest.js +22 -0
- package/dist/core/allow-entry.js +4 -4
- package/dist/core/ask-class.d.ts +2 -2
- package/dist/core/ask-headline.d.ts +1 -1
- package/dist/core/ask-origin.d.ts +44 -4
- package/dist/core/ask-origin.js +29 -10
- package/dist/core/auto-mode.d.ts +7 -9
- package/dist/core/auto-mode.js +114 -8
- package/dist/core/background-agent-store.d.ts +1 -0
- package/dist/core/background-agent-store.js +49 -8
- package/dist/core/checkpoint-features.d.ts +3 -2
- package/dist/core/checkpoint-features.js +1 -1
- package/dist/core/checkpoint-rekey.d.ts +1 -1
- package/dist/core/checkpoint-rekey.js +6 -1
- package/dist/core/checkpoint-requirements.d.ts +23 -3
- package/dist/core/checkpoint-requirements.js +5 -1
- package/dist/core/checkpoint-row-verdict.d.ts +1 -1
- package/dist/core/checkpoint-row-verdict.js +9 -3
- package/dist/core/checkpoint-store.d.ts +26 -2
- package/dist/core/checkpoint-store.js +9 -2
- package/dist/core/child-clamp-seats.d.ts +15 -0
- package/dist/core/child-clamp-seats.js +15 -0
- package/dist/core/config-refusal-codes.d.ts +1 -1
- package/dist/core/config-refusal-codes.js +1 -0
- package/dist/core/cron.js +9 -1
- package/dist/core/delegation-frames.d.ts +1 -0
- package/dist/core/delegation-frames.js +1 -1
- package/dist/core/deployment-shape.d.ts +7 -0
- package/dist/core/deployment-shape.js +19 -0
- package/dist/core/engine-capabilities.d.ts +13 -1
- package/dist/core/engine-capabilities.js +1 -1
- package/dist/core/engine-notice.d.ts +41 -28
- package/dist/core/engine-version.js +1 -1
- package/dist/core/entries-not-applied.d.ts +19 -7
- package/dist/core/entries-not-applied.js +33 -1
- package/dist/core/gate-fold.js +5 -4
- package/dist/core/gate-lanes.js +8 -12
- package/dist/core/gate-outcome.d.ts +8 -2
- package/dist/core/gate-outcome.js +10 -3
- package/dist/core/governance-codes.d.ts +14 -2
- package/dist/core/governance-codes.js +22 -6
- package/dist/core/hook-condition.d.ts +37 -0
- package/dist/core/hook-condition.js +567 -0
- package/dist/core/hooks.d.ts +5 -0
- package/dist/core/hooks.js +1 -0
- package/dist/core/host-instance.d.ts +23 -0
- package/dist/core/host-instance.js +69 -0
- package/dist/core/instruction-preview.d.ts +63 -0
- package/dist/core/instruction-preview.js +406 -0
- package/dist/core/leg-budget.d.ts +26 -0
- package/dist/core/leg-budget.js +9 -0
- package/dist/core/leg-identity.d.ts +51 -1
- package/dist/core/leg-identity.js +45 -2
- package/dist/core/manager-launch-check.d.ts +48 -0
- package/dist/core/manager-launch-check.js +64 -0
- package/dist/core/mcp-call-meta.d.ts +2 -2
- package/dist/core/mcp-injection-drop.d.ts +20 -10
- package/dist/core/mcp-injection-drop.js +9 -3
- package/dist/core/mcp-server-spec.d.ts +2 -1
- package/dist/core/member-outcome.d.ts +3 -2
- package/dist/core/member-outcome.js +1 -1
- package/dist/core/memory-engine/deletion-record.d.ts +46 -0
- package/dist/core/memory-engine/deletion-record.js +96 -0
- package/dist/core/memory-engine/engine.js +24 -16
- package/dist/core/memory-engine/file-backend.js +7 -5
- package/dist/core/memory-engine/projection-ledger.d.ts +1 -1
- package/dist/core/memory-engine/projection-ledger.js +1 -1
- package/dist/core/memory-engine/scope-contract.d.ts +18 -13
- package/dist/core/memory-engine/scope-contract.js +18 -18
- package/dist/core/memory-engine/sync-client.js +26 -6
- package/dist/core/memory-engine/sync.d.ts +20 -2
- package/dist/core/memory-engine/sync.js +18 -17
- package/dist/core/mode-policy.d.ts +25 -6
- package/dist/core/mode-policy.js +33 -8
- package/dist/core/model-seat.d.ts +8 -5
- package/dist/core/model-shell.d.ts +129 -0
- package/dist/core/model-shell.js +249 -0
- package/dist/core/mods/kernel/digest.d.ts +4 -0
- package/dist/core/mods/kernel/digest.js +5 -0
- package/dist/core/mods/kernel/dispatch.d.ts +3 -0
- package/dist/core/mods/kernel/dispatch.js +15 -6
- package/dist/core/mods/kernel/events.d.ts +21 -5
- package/dist/core/mods/kernel/events.js +19 -10
- package/dist/core/mods/kernel/hash-mirror.d.ts +1 -0
- package/dist/core/mods/kernel/hash-mirror.js +55 -0
- package/dist/core/mods/kernel/index.d.ts +1 -0
- package/dist/core/mods/kernel/index.js +1 -0
- package/dist/core/mods/kernel/package-reader.d.ts +48 -0
- package/dist/core/mods/kernel/package-reader.js +149 -0
- package/dist/core/mods/kernel/site-rules.d.ts +4 -0
- package/dist/core/mods/kernel/site-rules.js +13 -0
- package/dist/core/mods/package.d.ts +7 -3
- package/dist/core/mods/package.js +47 -80
- package/dist/core/own-property-receipt.js +11 -4
- package/dist/core/parent-spec-seat.d.ts +13 -11
- package/dist/core/parent-spec-seat.js +13 -9
- package/dist/core/peer-seat.js +3 -3
- package/dist/core/peer-task-store.d.ts +365 -0
- package/dist/core/peer-task-store.js +682 -0
- package/dist/core/permission-rule-consent.js +6 -11
- package/dist/core/permission-rule-model.d.ts +27 -0
- package/dist/core/permission-rule-model.js +33 -5
- package/dist/core/permission-rule-org.js +13 -3
- package/dist/core/permission-rule-provider.d.ts +35 -33
- package/dist/core/permission-rule-provider.js +38 -295
- package/dist/core/permission-rule-store.d.ts +181 -8
- package/dist/core/permission-rule-store.js +420 -17
- package/dist/core/permission-rule-sync.js +15 -1
- package/dist/core/permission-rules.js +4 -1
- package/dist/core/project-seat.d.ts +55 -0
- package/dist/core/project-seat.js +96 -0
- package/dist/core/protocol-http-auth.d.ts +3 -2
- package/dist/core/protocol-http-auth.js +26 -18
- package/dist/core/remote-env.d.ts +4 -4
- package/dist/core/retain-seat.d.ts +42 -0
- package/dist/core/retain-seat.js +76 -0
- package/dist/core/retired-keys.js +1 -0
- package/dist/core/rewind-refusal-codes.d.ts +8 -0
- package/dist/core/rewind-refusal-codes.js +12 -0
- package/dist/core/roles.d.ts +2 -2
- package/dist/core/roles.js +15 -1
- package/dist/core/rule-offer-read.d.ts +1 -1
- package/dist/core/rule-offer-read.js +32 -4
- package/dist/core/rule-store-fault.d.ts +9 -7
- package/dist/core/rule-store-fault.js +8 -3
- package/dist/core/run-ledger-seat.d.ts +66 -0
- package/dist/core/run-ledger-seat.js +70 -0
- package/dist/core/run-ledger.d.ts +332 -0
- package/dist/core/run-ledger.js +550 -0
- package/dist/core/runner/checkpoint-scope.d.ts +14 -3
- package/dist/core/runner/checkpoint-scope.js +16 -6
- package/dist/core/runner/compact-session.js +1 -1
- package/dist/core/runner/construction-doors.js +8 -0
- package/dist/core/runner/contracts.d.ts +21 -5
- package/dist/core/runner/cross-boundary-lane.d.ts +8 -1
- package/dist/core/runner/cross-boundary-lane.js +4 -0
- package/dist/core/runner/delegation-owner.d.ts +30 -0
- package/dist/core/runner/delegation-owner.js +20 -4
- package/dist/core/runner/finish-reason-seat.js +4 -2
- package/dist/core/runner/gate-exit.d.ts +7 -0
- package/dist/core/runner/gate-exit.js +2 -1
- package/dist/core/runner/leg-frame.js +3 -0
- package/dist/core/runner/model-lane-seat.d.ts +3 -0
- package/dist/core/runner/model-lane-seat.js +4 -0
- package/dist/core/runner/nested-memory-lane.d.ts +22 -5
- package/dist/core/runner/nested-memory-lane.js +91 -30
- package/dist/core/runner/person-path-rows.d.ts +27 -16
- package/dist/core/runner/person-path-rows.js +93 -15
- package/dist/core/runner/prepare-caps-and-workflow.js +98 -88
- package/dist/core/runner/prepare-config-doors.d.ts +1 -0
- package/dist/core/runner/prepare-config-doors.js +13 -7
- package/dist/core/runner/prepare-context-lane.js +1 -0
- package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
- package/dist/core/runner/prepare-delegation-surface.js +6 -0
- package/dist/core/runner/prepare-execution-env.d.ts +3 -3
- package/dist/core/runner/prepare-gate-stations.d.ts +6 -0
- package/dist/core/runner/prepare-gate-stations.js +3 -1
- package/dist/core/runner/prepare-hands-readface.d.ts +5 -2
- package/dist/core/runner/prepare-hands-readface.js +15 -3
- package/dist/core/runner/prepare-inherited-gate.d.ts +6 -3
- package/dist/core/runner/prepare-inherited-gate.js +13 -5
- package/dist/core/runner/prepare-offload-wrappers.js +1 -1
- package/dist/core/runner/prepare-run-refs.d.ts +1 -1
- package/dist/core/runner/prepare-run-refs.js +3 -2
- package/dist/core/runner/prepare-suspend-saga.d.ts +6 -2
- package/dist/core/runner/prepare-suspend-saga.js +4 -2
- package/dist/core/runner/prepare-task.js +42 -30
- package/dist/core/runner/prepare-turn-wiring.d.ts +4 -3
- package/dist/core/runner/prepare-turn-wiring.js +2 -1
- package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -1
- package/dist/core/runner/prepare-wiring-manifest.js +8 -6
- package/dist/core/runner/resume-apply.js +11 -5
- package/dist/core/runner/resume-policy-outcome.js +5 -2
- package/dist/core/runner/resume-review-outcome.d.ts +3 -0
- package/dist/core/runner/resume-review-outcome.js +24 -1
- package/dist/core/runner/role-seat-defaulted.d.ts +3 -3
- package/dist/core/runner/role-seat-defaulted.js +1 -1
- package/dist/core/runner/rule-store-unreadable-notice.d.ts +1 -1
- package/dist/core/runner/rule-store-unreadable-notice.js +3 -3
- package/dist/core/runner/run-harness-handlers.js +4 -1
- package/dist/core/runner/run-identity-wiring.js +3 -2
- package/dist/core/runner/run-leg.js +5 -2
- package/dist/core/runner/run-notification-lane.js +20 -1
- package/dist/core/runner/run-settle-and-teardown.js +21 -12
- package/dist/core/runner/run-stop-and-final-verify.js +6 -0
- package/dist/core/runner/run-telemetry-and-budget-seats.js +1 -1
- package/dist/core/runner/runtask.d.ts +6 -2
- package/dist/core/runner/runtask.js +21 -9
- package/dist/core/runner/shell-env-withheld.d.ts +6 -4
- package/dist/core/runner/shell-env-withheld.js +25 -3
- package/dist/core/runner/stop-tail-notice.d.ts +10 -2
- package/dist/core/runner/stop-tail-notice.js +9 -2
- package/dist/core/runner/stream-settle-backstop.d.ts +1 -0
- package/dist/core/runner/stream-settle-backstop.js +1 -0
- package/dist/core/runner/sub-agent-deny-lists.js +9 -5
- package/dist/core/runner/task-start-doors.js +6 -3
- package/dist/core/runner/terminal-account.d.ts +6 -1
- package/dist/core/runner/terminal-account.js +16 -1
- package/dist/core/runner/tool-end-body.d.ts +1 -1
- package/dist/core/runner/tool-not-executed.d.ts +27 -8
- package/dist/core/runner/tool-not-executed.js +22 -11
- package/dist/core/runner/unreadable-person-rows.d.ts +2 -1
- package/dist/core/runner/write-protection-station.d.ts +1 -1
- package/dist/core/runner/write-protection-station.js +1 -1
- package/dist/core/runner-deps.d.ts +17 -10
- package/dist/core/secret-env.d.ts +61 -37
- package/dist/core/secret-env.js +49 -49
- package/dist/core/session-checkout.d.ts +3 -0
- package/dist/core/session-checkout.js +1 -0
- package/dist/core/session-store.d.ts +12 -6
- package/dist/core/session-store.js +26 -6
- package/dist/core/session.d.ts +31 -8
- package/dist/core/shell-read-silence.d.ts +40 -2
- package/dist/core/shell-read-silence.js +23 -4
- package/dist/core/store-contracts/checkpoint-store-contract.js +10 -0
- package/dist/core/store-contracts/peer-task-store-contract.d.ts +21 -0
- package/dist/core/store-contracts/peer-task-store-contract.js +516 -0
- package/dist/core/store-contracts/session-store-contract.d.ts +15 -2
- package/dist/core/store-contracts/session-store-contract.js +87 -3
- package/dist/core/store-contracts/workflow-journal-store-contract.d.ts +19 -1
- package/dist/core/store-contracts/workflow-journal-store-contract.js +89 -1
- package/dist/core/task-event.d.ts +14 -7
- package/dist/core/task-notification.d.ts +96 -10
- package/dist/core/task-notification.js +135 -6
- package/dist/core/task-registry-agent.d.ts +1 -0
- package/dist/core/task-registry-agent.js +1 -1
- package/dist/core/task-registry-shared.d.ts +12 -1
- package/dist/core/task-registry-shared.js +3 -1
- package/dist/core/task-registry-workflow.d.ts +1 -1
- package/dist/core/task-registry-workflow.js +9 -1
- package/dist/core/task-registry.d.ts +40 -2
- package/dist/core/task-registry.js +80 -15
- package/dist/core/task-result.d.ts +18 -3
- package/dist/core/task-spec-members.d.ts +3 -1
- package/dist/core/task-spec-members.js +19 -3
- package/dist/core/task-spec.d.ts +48 -22
- package/dist/core/tool-catalog-entries.js +2 -0
- package/dist/core/tool-gate-phase.d.ts +6 -3
- package/dist/core/tool-gate-phase.js +1 -0
- package/dist/core/tool-mount-facts.d.ts +8 -4
- package/dist/core/tool-mount-facts.js +7 -2
- package/dist/core/tool-mount-plan.d.ts +3 -1
- package/dist/core/tool-mount-plan.js +10 -3
- package/dist/core/tool-mount-static.d.ts +1 -1
- package/dist/core/tool-mount-static.js +4 -2
- package/dist/core/tool-result-store.d.ts +56 -3
- package/dist/core/tool-result-store.js +219 -25
- package/dist/core/tool-spec.d.ts +9 -2
- package/dist/core/trace.d.ts +3 -3
- package/dist/core/user-attachment.d.ts +5 -1
- package/dist/core/user-attachment.js +14 -7
- package/dist/core/wiring-manifest.d.ts +26 -20
- package/dist/core/wiring-manifest.js +7 -3
- package/dist/core/workflow-journal-store.d.ts +53 -10
- package/dist/core/workflow-journal-store.js +27 -4
- package/dist/core/workflow-run-store-contract.js +16 -0
- package/dist/core/workflow-run-store.d.ts +9 -7
- package/dist/core/workflow-run-store.js +4 -1
- package/dist/engine/execution-env/node-execution-env.d.ts +75 -1
- package/dist/engine/execution-env/node-execution-env.js +227 -13
- package/dist/engine/harness/types.d.ts +49 -1
- package/dist/engine/harness/types.js +10 -0
- package/dist/engine/llm/types.d.ts +13 -7
- package/dist/engine/llm/validation.d.ts +8 -1
- package/dist/engine/llm/validation.js +31 -2
- package/dist/engine/lsp/node-lsp-manager.js +2 -1
- package/dist/engine/session/import-validate.js +6 -1
- package/dist/engine/session/session.d.ts +15 -2
- package/dist/engine/session/session.js +34 -4
- package/dist/host-env.d.ts +10 -0
- package/dist/host-env.js +1 -0
- package/dist/index.d.ts +28 -9
- package/dist/index.js +22 -6
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/orchestration/goal.js +1 -1
- package/dist/orchestration/run-workflow-tool.js +40 -32
- package/dist/orchestration/workflow-park-adoption.d.ts +51 -12
- package/dist/orchestration/workflow-park-adoption.js +47 -12
- package/dist/orchestration/workflow-primitives.js +10 -1
- package/dist/orchestration/workflow-script-runner.d.ts +2 -2
- package/dist/orchestration/workflow-stop.d.ts +128 -0
- package/dist/orchestration/workflow-stop.js +156 -0
- package/dist/orchestration/workflow.d.ts +31 -7
- package/dist/orchestration/workflow.js +119 -57
- package/dist/prompts/manager-recipe.d.ts +18 -0
- package/dist/prompts/manager-recipe.js +24 -0
- package/dist/shell/lex.d.ts +2 -2
- package/dist/shell/lex.js +1 -1
- package/dist/stores/file/permission-rule-store.d.ts +3 -1
- package/dist/stores/file/permission-rule-store.js +0 -1
- package/dist/stores/file/workflow-journal-store.d.ts +16 -3
- package/dist/stores/file/workflow-journal-store.js +93 -5
- package/dist/stores/file/workflow-run-store.d.ts +1 -1
- package/dist/tools/fs/bash-model-shell.d.ts +23 -0
- package/dist/tools/fs/bash-model-shell.js +25 -0
- package/dist/tools/fs/bash-readonly-classifier.d.ts +6 -0
- package/dist/tools/fs/bash-readonly-classifier.js +3 -0
- package/dist/tools/fs/file-write-check.js +9 -3
- package/dist/tools/fs/fs-bash.js +13 -11
- package/dist/tools/fs/index.d.ts +8 -7
- package/dist/tools/fs/index.js +4 -4
- package/dist/tools/fs/read-deny-home.d.ts +1 -1
- package/dist/tools/fs/read-deny-home.js +5 -5
- package/dist/tools/fs/read-deny.d.ts +33 -8
- package/dist/tools/fs/read-deny.js +114 -25
- package/dist/tools/fs/safety.d.ts +4 -1
- package/dist/tools/fs/safety.js +4 -2
- package/dist/tools/fs/shell-read-argv.js +1 -0
- package/dist/tools/fs/shell-read-check.d.ts +9 -2
- package/dist/tools/fs/shell-read-check.js +134 -22
- package/dist/tools/fs/shell-read-establish.d.ts +9 -0
- package/dist/tools/fs/shell-read-establish.js +21 -11
- package/dist/tools/fs/shell-read-judge.d.ts +13 -1
- package/dist/tools/fs/shell-read-judge.js +26 -7
- package/dist/tools/fs/shell-read-plan.d.ts +7 -3
- package/dist/tools/fs/shell-read-plan.js +8 -5
- package/dist/tools/fs/shell-read-word.d.ts +8 -0
- package/dist/tools/fs/shell-read-word.js +13 -4
- package/dist/tools/fs/shell-read-write-targets.js +17 -9
- package/dist/tools/monitor.js +12 -8
- package/dist/tools/scheduler-tools.d.ts +1 -0
- package/dist/tools/scheduler-tools.js +5 -2
- package/package.json +3 -2
- package/test/export-surface.snapshot.json +192 -3
- package/wire-changes/answers/core-stores-sql@7.73.0.json +28 -0
- package/wire-changes/answers/core-stores-sql@7.74.0.json +7 -0
- package/wire-changes/answers/core@7.73.0.json +216 -0
- package/wire-changes/answers/core@7.74.0.json +68 -0
- package/wire-changes/answers/mods-kernel@7.73.0.json +7 -0
- package/wire-changes/answers/mods-kernel@7.74.0.json +21 -0
- package/wire-changes/answers/primitives@7.73.0.json +12 -0
- package/wire-changes/answers/primitives@7.74.0.json +7 -0
- package/wire-changes/answers/wiki-gate@7.73.0.json +7 -0
- package/wire-changes/answers/wiki-gate@7.74.0.json +8 -0
- package/wire-changes/core-stores-sql@7.73.0.json +326 -0
- package/wire-changes/core-stores-sql@7.74.0.json +143 -0
- package/wire-changes/core@7.73.0.json +6480 -0
- package/wire-changes/core@7.74.0.json +2210 -0
- package/wire-changes/mods-kernel@7.73.0.json +147 -0
- package/wire-changes/mods-kernel@7.74.0.json +421 -0
- package/wire-changes/primitives@7.73.0.json +227 -0
- package/wire-changes/primitives@7.74.0.json +174 -0
- package/wire-changes/wiki-gate@7.73.0.json +145 -0
- package/wire-changes/wiki-gate@7.74.0.json +145 -0
|
@@ -10,9 +10,10 @@ import { foreignLine } from "../core/protocol-http-auth.js";
|
|
|
10
10
|
import { withDelegationProvenance } from "../core/tool-policy.js";
|
|
11
11
|
import { LAUNCH_RECEIPT_OWN_WORDS_CLAUSE, launchReceiptNoQuoteClause } from "../agents/launch-receipt-contract.js";
|
|
12
12
|
import { createHash, randomUUID } from "node:crypto";
|
|
13
|
-
import { startWorkflow, WORKFLOW_STORE_WAIT_BOUND_MS,
|
|
13
|
+
import { startWorkflow, WORKFLOW_STORE_WAIT_BOUND_MS, takeWorkflowResumeClaims, releaseWorkflowResumeClaims } from "./workflow.js";
|
|
14
|
+
import { workflowStopOf } from "./workflow-stop.js";
|
|
14
15
|
import { assertJournalStoreGivesClaimsBack, journalKeepsLaunches } from "../core/workflow-journal-store.js";
|
|
15
|
-
import { boundedStoreRead, createWorkflowParkAdopter, otherWaitingLine, readWorkflowRunTree, readWorkflowRunTreeWithin, registerWorkflowParkAdopter, workflowLineForkReason, workflowLineTailOf, workflowTreeOverBoundSentence } from "./workflow-park-adoption.js";
|
|
16
|
+
import { boundedStoreRead, createWorkflowParkAdopter, otherWaitingLine, readWorkflowRunTree, readWorkflowRunTreeWithin, registerWorkflowParkAdopter, sameClaimKeys, workflowClaimKeysOf, workflowLineForkReason, workflowLineTailOf, workflowTreeOverBoundSentence } from "./workflow-park-adoption.js";
|
|
16
17
|
import { settledRunOf } from "../core/workflow-settled-run.js";
|
|
17
18
|
import { WORKFLOW_AGENT_PARKED_ERROR_CODE, WORKFLOW_STEP_ASKED_AGAIN, firstFailedAgentCodeOf, parkedAgentsOf, workflowMembersOf, workflowParkHolderOf } from "./workflow-types.js";
|
|
18
19
|
import { memberLedgerClause, memberRefusalsText } from "../core/member-outcome.js";
|
|
@@ -140,7 +141,7 @@ function workflowUsageBlock(run) {
|
|
|
140
141
|
...(run.endedAt !== undefined ? { duration_ms: run.endedAt - run.startedAt } : {}),
|
|
141
142
|
};
|
|
142
143
|
}
|
|
143
|
-
function workflowDiagnostics(runId, journalRef, resumeMiss, record, held) {
|
|
144
|
+
function workflowDiagnostics(runId, journalRef, resumeMiss, record, held, stoppedBy) {
|
|
144
145
|
const journalTeach = journalRef === undefined
|
|
145
146
|
? ""
|
|
146
147
|
: journalRef.includes("://")
|
|
@@ -152,10 +153,13 @@ function workflowDiagnostics(runId, journalRef, resumeMiss, record, held) {
|
|
|
152
153
|
return ((record ?? "") +
|
|
153
154
|
journalTeach +
|
|
154
155
|
resumeMissTeach +
|
|
155
|
-
(
|
|
156
|
-
? ` ${
|
|
157
|
-
:
|
|
156
|
+
(stoppedBy !== undefined
|
|
157
|
+
? ` ${workflowStoppedSentence(stoppedBy)}.`
|
|
158
|
+
: held !== undefined
|
|
159
|
+
? ` ${heldStepSentence(held)}.`
|
|
160
|
+
: ` To continue after editing the script: re-invoke with resumeFromRunId: "${runId}" (completed agents replay from the journal; only new/changed calls run).`)).trimStart();
|
|
158
161
|
}
|
|
162
|
+
const workflowStoppedSentence = (stoppedBy) => `The workflow was stopped (by ${JSON.stringify(boundedRedactedSummary(stoppedBy, 64))}): no run of it starts another step, so resuming it (resumeFromRunId) is refused — to run the work again, start the workflow again`;
|
|
159
163
|
const heldStepSentence = (held) => held.holder !== undefined
|
|
160
164
|
? `The parked step still belongs to run "${held.holder}": with a person's decision on its card, that run continues from the step; ` +
|
|
161
165
|
`if the card is no longer waiting (expired, removed, or decided elsewhere), a resume of "${held.holder}" records the step as failed and its script continues`
|
|
@@ -188,8 +192,8 @@ const SCRIPT_ERROR_CODES = new Set([
|
|
|
188
192
|
"workflow.result_too_large",
|
|
189
193
|
"workflow.budget_exceeded",
|
|
190
194
|
]);
|
|
191
|
-
function failureSummary(err, runId, run, held) {
|
|
192
|
-
return withUnusedDecisions(failureSummaryOf(err, runId, run, held), run);
|
|
195
|
+
function failureSummary(err, runId, run, held, stoppedBy) {
|
|
196
|
+
return withUnusedDecisions(failureSummaryOf(err, runId, run, held, stoppedBy), run);
|
|
193
197
|
}
|
|
194
198
|
const RESUME_REFUSAL_CODES = new Set(["workflow.parked_call_changed", "workflow.park_truth_unreadable", "workflow.park_binding_broken", "workflow.park_requires_run_store"]);
|
|
195
199
|
function withUnusedDecisions(summary, run) {
|
|
@@ -221,7 +225,7 @@ function continuedBeforeSentence(run) {
|
|
|
221
225
|
const ended = `${before.status}${before.errorCode !== undefined ? ` (${before.errorCode})` : ""}`;
|
|
222
226
|
return ` — run "${boundedRedactedSummary(run.resume.fromRunId, 80)}" had already been continued as run "${boundedRedactedSummary(before.runId, 80)}", which ended ${ended}; this run continued from that earlier point, so the steps after it that had not completed there ran again here`;
|
|
223
227
|
}
|
|
224
|
-
function failureSummaryOf(err, runId, run, held) {
|
|
228
|
+
function failureSummaryOf(err, runId, run, held, stoppedBy) {
|
|
225
229
|
const codeWord = readMember(err, "code");
|
|
226
230
|
const thrownCode = typeof codeWord === "string" && codeWord !== WORKFLOW_AGENT_PARKED_ERROR_CODE ? codeWord : undefined;
|
|
227
231
|
const code = run !== undefined ? run.errorCode : thrownCode;
|
|
@@ -244,11 +248,13 @@ function failureSummaryOf(err, runId, run, held) {
|
|
|
244
248
|
(runId ? `; the diagnostics below name its record (the parked agent's row reads status "parked")` : "") +
|
|
245
249
|
`; do not re-issue the same call — once a person decides the approval, the decision continues this run from the parked call; you do not resume it, and if it cannot be continued you are told then`);
|
|
246
250
|
}
|
|
247
|
-
const guide =
|
|
248
|
-
? `;
|
|
249
|
-
:
|
|
250
|
-
? `; which agents failed is in the diagnostics below
|
|
251
|
-
:
|
|
251
|
+
const guide = stoppedBy !== undefined
|
|
252
|
+
? `; ${workflowStoppedSentence(stoppedBy)}`
|
|
253
|
+
: held !== undefined
|
|
254
|
+
? `; which agents failed is in the diagnostics below. ${heldStepSentence(held)}`
|
|
255
|
+
: runId
|
|
256
|
+
? `; which agents failed is in the diagnostics below; after fixing, re-invoke with resumeFromRunId: "${runId}" (completed agents replay from the journal)`
|
|
257
|
+
: "";
|
|
252
258
|
const scriptWords = code && SCRIPT_ERROR_CODES.has(code) ? readMember(err, "message") : undefined;
|
|
253
259
|
if (code && typeof scriptWords === "string") {
|
|
254
260
|
const msg = egressText("same-principal", scriptWords);
|
|
@@ -332,11 +338,11 @@ function claimWithin(p, late) {
|
|
|
332
338
|
});
|
|
333
339
|
});
|
|
334
340
|
}
|
|
335
|
-
async function takeToolResumeClaim(journal, args, what, runId, reportStoreFault) {
|
|
341
|
+
async function takeToolResumeClaim(journal, args, what, runId, reportStoreFault, carriesDecision = false) {
|
|
336
342
|
const who = what === "record" ? "record of a person's answer" : what;
|
|
337
343
|
let verdict;
|
|
338
344
|
try {
|
|
339
|
-
verdict = await claimWithin(
|
|
345
|
+
verdict = await claimWithin(takeWorkflowResumeClaims(journal, args.keys, args.newRunId, args.scope, carriesDecision), (late) => void (late.granted ? releaseWorkflowResumeClaims(journal, args.keys, args.newRunId, args.scope, late.fallback) : undefined));
|
|
340
346
|
}
|
|
341
347
|
catch (err) {
|
|
342
348
|
reportStoreFault?.(`the ${who}'s resume claim on workflow run ${JSON.stringify(runId)} could not be taken`, err);
|
|
@@ -936,14 +942,14 @@ async function mountRunWorkflowTool(d) {
|
|
|
936
942
|
return `an approval card of workflow run "${inlineUntrusted(target, 64)}"'s workflow could not be read — not started; resume again once the checkpoint store answers`;
|
|
937
943
|
if (line.kind === "waiting")
|
|
938
944
|
return notContinuedRefusalOf(namedResume, "waiting_elsewhere", { waiting: line.lines, decisionIds: heldDecisionIds });
|
|
939
|
-
return {
|
|
945
|
+
return { keys: workflowClaimKeysOf(tree).keys, target };
|
|
940
946
|
};
|
|
941
947
|
const firstLine = await modelLineRefusal();
|
|
942
948
|
if (typeof firstLine === "string")
|
|
943
949
|
return structuredError(firstLine);
|
|
944
950
|
if (firstLine !== undefined)
|
|
945
951
|
resumeFromRunId = firstLine.target;
|
|
946
|
-
const
|
|
952
|
+
const claimKeys = continuation !== undefined ? continuation.claimKeys : firstLine?.keys;
|
|
947
953
|
let sourceLaunch = continuation?.launch;
|
|
948
954
|
if (continuation === undefined && resumeFromRunId !== undefined && journalKeepsLaunches(d.journalStore)) {
|
|
949
955
|
const scope = runScope;
|
|
@@ -982,17 +988,17 @@ async function mountRunWorkflowTool(d) {
|
|
|
982
988
|
let continuationDecisions = continuation?.decisions;
|
|
983
989
|
const releaseContinuationClaim = () => {
|
|
984
990
|
if (continuationClaim !== undefined && d.journalStore !== undefined)
|
|
985
|
-
void
|
|
991
|
+
void releaseWorkflowResumeClaims(d.journalStore, continuationClaim.args.keys, continuationClaim.args.newRunId, continuationClaim.args.scope, continuationClaim.fallback);
|
|
986
992
|
};
|
|
987
|
-
if (resumeFromRunId !== undefined &&
|
|
993
|
+
if (resumeFromRunId !== undefined && claimKeys !== undefined && d.journalStore !== undefined && launchRunId !== undefined) {
|
|
988
994
|
const journal = d.journalStore;
|
|
989
|
-
const args = {
|
|
990
|
-
const taken = await takeToolResumeClaim(journal, args, continuation !== undefined ? "continuation" : "resume", resumeFromRunId, reportStoreFault);
|
|
995
|
+
const args = { keys: claimKeys, newRunId: launchRunId, scope: resumeScope };
|
|
996
|
+
const taken = await takeToolResumeClaim(journal, args, continuation !== undefined ? "continuation" : "resume", resumeFromRunId, reportStoreFault, continuation !== undefined || heldDecisionIds.length > 0);
|
|
991
997
|
if ("refused" in taken)
|
|
992
998
|
return structuredError(taken.refused);
|
|
993
999
|
if ("held" in taken) {
|
|
994
1000
|
if (continuation === undefined)
|
|
995
|
-
return structuredError(notContinuedRefusalOf(namedResume ?? resumeFromRunId, "continuing_elsewhere", { ...taken.held, decisionIds: heldDecisionIds }));
|
|
1001
|
+
return structuredError(notContinuedRefusalOf(namedResume ?? resumeFromRunId, taken.held.stoppedBy !== undefined ? "workflow_stopped" : "continuing_elsewhere", { ...taken.held, decisionIds: heldDecisionIds }));
|
|
996
1002
|
continuation.onClaimHeld(taken.held);
|
|
997
1003
|
return structuredError("another run already holds this run's resume claim — not started");
|
|
998
1004
|
}
|
|
@@ -1005,7 +1011,7 @@ async function mountRunWorkflowTool(d) {
|
|
|
1005
1011
|
catch {
|
|
1006
1012
|
again = `the records of workflow run "${inlineUntrusted(resumeFromRunId, 64)}"'s workflow could not be read — not started`;
|
|
1007
1013
|
}
|
|
1008
|
-
if (again !== undefined && typeof again !== "string" && (again.
|
|
1014
|
+
if (again !== undefined && typeof again !== "string" && (!sameClaimKeys(again.keys, claimKeys) || again.target !== resumeFromRunId)) {
|
|
1009
1015
|
again = `the records of workflow run "${inlineUntrusted(namedResume ?? "", 64)}"'s workflow changed while this call took its resume claim (a run of it was continued, removed or created again meanwhile) — not started; call again to continue from what they say now`;
|
|
1010
1016
|
}
|
|
1011
1017
|
if (typeof again === "string") {
|
|
@@ -1114,7 +1120,7 @@ async function mountRunWorkflowTool(d) {
|
|
|
1114
1120
|
workflowDepth: d.workflowDepth,
|
|
1115
1121
|
launchingTool: tool,
|
|
1116
1122
|
...((ctx.toolSelector?.layers ?? d.parentToolCeiling) !== undefined ? { toolCeiling: (ctx.toolSelector?.layers ?? d.parentToolCeiling) } : {}),
|
|
1117
|
-
...(continuationClaim !== undefined ? { resumeClaimKey: continuationClaim.args.
|
|
1123
|
+
...(continuationClaim !== undefined && continuationClaim.args.keys[0] !== undefined ? { resumeClaimKey: continuationClaim.args.keys[0] } : {}),
|
|
1118
1124
|
...(namedResume !== undefined && resumeFromRunId !== namedResume ? { resumeAsked: namedResume } : {}),
|
|
1119
1125
|
});
|
|
1120
1126
|
}
|
|
@@ -1135,6 +1141,7 @@ async function mountRunWorkflowTool(d) {
|
|
|
1135
1141
|
description: meta.name ?? meta.description,
|
|
1136
1142
|
toolUseId: ctx.toolCallId,
|
|
1137
1143
|
...(taskOwner !== undefined ? { owner: taskOwner } : {}),
|
|
1144
|
+
...(sourceTaskId !== undefined && sourceTaskId !== (ctx.sessionId ?? d.originatingSessionId) ? { parentTaskId: sourceTaskId } : {}),
|
|
1138
1145
|
scope: runScope,
|
|
1139
1146
|
...(d.originatingSessionId !== undefined ? { originatingSessionId: d.originatingSessionId } : {}),
|
|
1140
1147
|
...occupantStamp(rootOccupantSeat(ctx.rootSessionId ?? d.rootSessionId ?? d.originatingSessionId, ctx, d)),
|
|
@@ -1201,7 +1208,7 @@ async function mountRunWorkflowTool(d) {
|
|
|
1201
1208
|
summary: completionSummary(meta.name, res.run) + continuedBeforeSentence(res.run),
|
|
1202
1209
|
result: boundedRedactedSummary(res.result, 4000),
|
|
1203
1210
|
usage: workflowUsageBlock(res.run),
|
|
1204
|
-
diagnostics: workflowDiagnostics(runId, journalLocatorOf(runId, res.run.scope), res.run.resume?.journalEntries === 0, recordOf(res.run)),
|
|
1211
|
+
diagnostics: workflowDiagnostics(runId, journalLocatorOf(runId, res.run.scope), res.run.resume?.journalEntries === 0, recordOf(res.run), undefined, workflowStopOf(handle)),
|
|
1205
1212
|
completionId: res.run.completionId,
|
|
1206
1213
|
members: workflowMembersOf(res.run),
|
|
1207
1214
|
}), async (err) => {
|
|
@@ -1213,11 +1220,12 @@ async function mountRunWorkflowTool(d) {
|
|
|
1213
1220
|
const failedRun = settledRunOf(handle.done);
|
|
1214
1221
|
const record = failedRun !== undefined ? recordOf(failedRun) : workflowRecordPickupOf(undefined).line;
|
|
1215
1222
|
const held = await heldStepOf(failedRun, d.store);
|
|
1216
|
-
const
|
|
1223
|
+
const stoppedBy = workflowStopOf(handle);
|
|
1224
|
+
const summary = failureSummary(err, runId, failedRun, held, stoppedBy) + continuedBeforeSentence(failedRun);
|
|
1217
1225
|
const settleId = failedRun?.completionId;
|
|
1218
1226
|
parts = {
|
|
1219
1227
|
summary,
|
|
1220
|
-
diagnostics: workflowDiagnostics(runId, undefined, undefined, record, held),
|
|
1228
|
+
diagnostics: workflowDiagnostics(runId, undefined, undefined, record, held, stoppedBy),
|
|
1221
1229
|
...(settleId !== undefined ? { completionId: settleId } : {}),
|
|
1222
1230
|
...(failedRun !== undefined ? { members: workflowMembersOf(failedRun) } : {}),
|
|
1223
1231
|
...((code) => (code !== undefined ? { errorCode: code } : {}))(failedRun === undefined ? undefined : workflowNotifiedCodeOf(failedRun)),
|
|
@@ -1278,12 +1286,12 @@ async function mountRunWorkflowTool(d) {
|
|
|
1278
1286
|
return { refused: launchRefusalText(details?.content) };
|
|
1279
1287
|
return { runId: details.details.workflowRunId };
|
|
1280
1288
|
},
|
|
1281
|
-
underClaim: async (
|
|
1289
|
+
underClaim: async (claimKeys, scope, body) => {
|
|
1282
1290
|
const journal = d.journalStore;
|
|
1283
1291
|
if (journal === undefined)
|
|
1284
1292
|
return { refused: "no journal store holds this workflow's resume claim" };
|
|
1285
|
-
const args = {
|
|
1286
|
-
const taken = await takeToolResumeClaim(journal, args, "record",
|
|
1293
|
+
const args = { keys: claimKeys, newRunId: answerRecordClaimHolder(), scope };
|
|
1294
|
+
const taken = await takeToolResumeClaim(journal, args, "record", claimKeys[0] ?? "", reportStoreFault);
|
|
1287
1295
|
if ("refused" in taken)
|
|
1288
1296
|
return { refused: taken.refused };
|
|
1289
1297
|
if ("held" in taken)
|
|
@@ -1292,7 +1300,7 @@ async function mountRunWorkflowTool(d) {
|
|
|
1292
1300
|
return { value: await body() };
|
|
1293
1301
|
}
|
|
1294
1302
|
finally {
|
|
1295
|
-
void
|
|
1303
|
+
void releaseWorkflowResumeClaims(journal, args.keys, args.newRunId, args.scope, taken.granted.fallback);
|
|
1296
1304
|
}
|
|
1297
1305
|
},
|
|
1298
1306
|
waitBoundMs: WORKFLOW_STORE_WAIT_BOUND_MS,
|
|
@@ -15,7 +15,7 @@ export interface WorkflowParkDecision {
|
|
|
15
15
|
readonly inheritedGate?: InheritedGate;
|
|
16
16
|
}
|
|
17
17
|
/** Why a decision did not continue its run — the closed set `workflow.parked_decision_unused` carries as `detail.reason`. */
|
|
18
|
-
export declare const WORKFLOW_PARK_UNUSED_REASONS: readonly ["workflow_not_mounted", "entry_unreadable", "record_unreadable", "not_holder", "not_pending", "decision_spent", "launch_unrecorded", "launch_unreadable", "host_changed", "denied", "ask_unanswerable", "call_changed", "launch_refused", "continuing_elsewhere", "card_unresumable", "waiting_elsewhere", "run_not_ended"];
|
|
18
|
+
export declare const WORKFLOW_PARK_UNUSED_REASONS: readonly ["workflow_not_mounted", "entry_unreadable", "record_unreadable", "not_holder", "not_pending", "decision_spent", "launch_unrecorded", "launch_unreadable", "host_changed", "denied", "ask_unanswerable", "call_changed", "launch_refused", "continuing_elsewhere", "card_unresumable", "waiting_elsewhere", "run_not_ended", "workflow_stopped"];
|
|
19
19
|
export type WorkflowParkUnusedReason = (typeof WORKFLOW_PARK_UNUSED_REASONS)[number];
|
|
20
20
|
/** What is left to do with a decision a reason answers (#5208): `deliverable` — the same decision stays usable, and a later hand-over of
|
|
21
21
|
* it is judged again; `decide_again` — only a person's new decision for the card continues the run (this one is spent, or — kept —
|
|
@@ -110,6 +110,9 @@ export declare const WORKFLOW_PARK_UNUSED_REASON_CLASS: {
|
|
|
110
110
|
readonly run_not_ended: {
|
|
111
111
|
readonly kept: "deliverable";
|
|
112
112
|
};
|
|
113
|
+
readonly workflow_stopped: {
|
|
114
|
+
readonly kept: "withdraw";
|
|
115
|
+
};
|
|
113
116
|
};
|
|
114
117
|
/** The class of an answer `reason` gave, as {@link WORKFLOW_PARK_UNUSED_REASON_CLASS} reads it — a lookup and nothing else: the row's
|
|
115
118
|
* `spent` class when `spent` is `true`, its `kept` class when it is `false`. Undefined — no guess, never the other arm — for a word
|
|
@@ -218,6 +221,9 @@ export type WorkflowParkAdoption = {
|
|
|
218
221
|
/** `continuing_elsewhere`: the store answered a remaining time for the claim that does not read — no instant is named, and
|
|
219
222
|
* the sentence says so. Absent otherwise. */
|
|
220
223
|
readonly claimLapseUnreadable?: true;
|
|
224
|
+
/** `workflow_stopped`: who stopped the workflow, as the journal store reports its stop (`ResumeClaimAnswer.stopped.by`). Not on
|
|
225
|
+
* the notice; the sentence reads it. */
|
|
226
|
+
readonly stoppedBy?: string;
|
|
221
227
|
/** `waiting_elsewhere`: the lines of the workflow that wait and hold this run off — each line's head run and what it waits
|
|
222
228
|
* on ({@link WorkflowWaitingLine}). The notice's detail carries their runs as `holder` (the run, or every run when more
|
|
223
229
|
* than one line waits, as for a fork); a host finds each card by the holder law. */
|
|
@@ -260,10 +266,11 @@ export type WorkflowParkAdoption = {
|
|
|
260
266
|
readonly why?: string;
|
|
261
267
|
};
|
|
262
268
|
/** What a refused resume claim tells of its hold: the run it is held for and when the store's expiry frees it, each when the
|
|
263
|
-
* store said — the members `continuing_elsewhere` carries
|
|
269
|
+
* store said — the members `continuing_elsewhere` carries; or, for a workflow that was stopped, who stopped it (`stoppedBy`, the
|
|
270
|
+
* member `workflow_stopped` carries: a stop holds the claim for good, for no run). */
|
|
264
271
|
export type WorkflowClaimHeld = Pick<Extract<WorkflowParkAdoption, {
|
|
265
272
|
kind: "unused";
|
|
266
|
-
}>, "claimExpiresAt" | "claimLapseUnreadable" | "heldForAnswer"> & {
|
|
273
|
+
}>, "claimExpiresAt" | "claimLapseUnreadable" | "heldForAnswer" | "stoppedBy"> & {
|
|
267
274
|
readonly holder?: string;
|
|
268
275
|
};
|
|
269
276
|
/** What the remaining time a refused resume claim's answer carries tells ({@link claimRemainingOf}): `unsaid` — the store
|
|
@@ -290,10 +297,14 @@ export declare function claimRemainingOf(answer: {
|
|
|
290
297
|
export declare function answerRecordClaimHolder(): string;
|
|
291
298
|
export declare function isAnswerRecordClaimHolder(holder: string | undefined): boolean;
|
|
292
299
|
/** The hold a refused claim's verdict tells ({@link WorkflowClaimHeld}), its remaining time as {@link claimRemainingOf} read it; a
|
|
293
|
-
* holder that records a person's answer is no run, and is told as that ({@link isAnswerRecordClaimHolder}: `heldForAnswer`)
|
|
300
|
+
* holder that records a person's answer is no run, and is told as that ({@link isAnswerRecordClaimHolder}: `heldForAnswer`); a
|
|
301
|
+
* stop the store reports (`stopped`) is told as that alone — it is no run's hold and never lapses. */
|
|
294
302
|
export declare function claimHeldOf(verdict: {
|
|
295
303
|
readonly holder?: string;
|
|
296
304
|
readonly lapse?: WorkflowClaimLapse;
|
|
305
|
+
readonly stopped?: {
|
|
306
|
+
readonly by: string;
|
|
307
|
+
};
|
|
297
308
|
}): WorkflowClaimHeld;
|
|
298
309
|
/** The words a refusal says, in brackets, of a claim whose store answered a remaining time that does not read. */
|
|
299
310
|
export declare const CLAIM_REMAINING_UNREADABLE_NOTE = "the journal store answered a remaining time for the claim that does not read, so no time is named";
|
|
@@ -348,8 +359,8 @@ export interface WorkflowContinuation {
|
|
|
348
359
|
readonly decisionId: string;
|
|
349
360
|
readonly inheritedGate?: InheritedGate;
|
|
350
361
|
}>;
|
|
351
|
-
/** The
|
|
352
|
-
readonly
|
|
362
|
+
/** The keys the workflow's resume claim is taken under ({@link workflowClaimKeysOf} of `fromRunId`'s tree): its root first. */
|
|
363
|
+
readonly claimKeys: readonly string[];
|
|
353
364
|
}
|
|
354
365
|
/** The seats the Workflow tool's closure hands its adopter. Every seat that reads the call's context reads the one the leg
|
|
355
366
|
* hands (`WorkflowParkAdoptionLeg.ctxOf`): the context a model's own call of this leg is run with, so the continuation's
|
|
@@ -383,10 +394,11 @@ export interface WorkflowParkAdopterSeats {
|
|
|
383
394
|
} | {
|
|
384
395
|
readonly superseded: true;
|
|
385
396
|
}>;
|
|
386
|
-
/** Hold the workflow's resume claim —
|
|
387
|
-
* started under it — while `body` runs, and give it back once `body` has settled: `value`, what `body` answered; `claimHeld`,
|
|
388
|
-
* the claim another run holds (as the store told it); `refused`, a store that threw or did not answer in time (`body`
|
|
389
|
-
|
|
397
|
+
/** Hold the workflow's resume claim — under `claimKeys` ({@link workflowClaimKeysOf}) in `scope`, taken as the launch takes it, no
|
|
398
|
+
* run started under it — while `body` runs, and give it back once `body` has settled: `value`, what `body` answered; `claimHeld`,
|
|
399
|
+
* the claim another run holds or a stop (as the store told it); `refused`, a store that threw or did not answer in time (`body`
|
|
400
|
+
* not run). */
|
|
401
|
+
readonly underClaim: <T>(claimKeys: readonly string[], scope: string, body: () => Promise<T>) => Promise<{
|
|
390
402
|
readonly value: T;
|
|
391
403
|
} | {
|
|
392
404
|
readonly claimHeld: WorkflowClaimHeld;
|
|
@@ -481,6 +493,9 @@ declare const WORKFLOW_RUN_TREE: unique symbol;
|
|
|
481
493
|
export interface WorkflowRunTree {
|
|
482
494
|
readonly root: WorkflowRun;
|
|
483
495
|
readonly records: readonly WorkflowRun[];
|
|
496
|
+
/** The id the root names as its source when the reader found a record under it that is another creation (the source was removed and
|
|
497
|
+
* the id used again): that id now names another workflow's run. */
|
|
498
|
+
readonly sourceRecreated?: string;
|
|
484
499
|
readonly [WORKFLOW_RUN_TREE]: true;
|
|
485
500
|
}
|
|
486
501
|
/**
|
|
@@ -492,6 +507,30 @@ export interface WorkflowRunTree {
|
|
|
492
507
|
* judging whether a card is still waited on, reads the whole tree: {@link readWorkflowRunTree}.
|
|
493
508
|
*/
|
|
494
509
|
export declare function workflowRunTreeOfOne(run: WorkflowRun): WorkflowRunTree;
|
|
510
|
+
/**
|
|
511
|
+
* The names a workflow's tree answers to on the journal store's claim table (#5156): the keys its resume claim is taken under and a stop
|
|
512
|
+
* writes its tombstone on — the tree's root first, then the tree id the root records when it is another id (a root whose own edge up
|
|
513
|
+
* does not hold: its source was removed). A root that names no source is its own tree id (one key). A root that names a source it does
|
|
514
|
+
* not reach and records no tree id (an older engine's record, its line broken) has no tree id: `fragment`, and the root alone is its
|
|
515
|
+
* key — a stop of it stops that part of the workflow only. So is a tree id that the reader found used again by another workflow's run
|
|
516
|
+
* (`sourceRecreated`): that id is the other workflow's key now. Every reader that takes, re-takes or stops the claim reads it here.
|
|
517
|
+
*/
|
|
518
|
+
export declare function workflowClaimKeysOf(tree: WorkflowRunTree): {
|
|
519
|
+
readonly keys: readonly string[];
|
|
520
|
+
readonly fragment: boolean;
|
|
521
|
+
};
|
|
522
|
+
/** The one judgment of whether a park a run's record names binds a checkpoint row — read by a resume's admission before it acts on the
|
|
523
|
+
* row and by a stop before it withdraws the card: why it does not (the record names no token or no session for it; the store answered a
|
|
524
|
+
* row under another token; the row belongs to another session), or `undefined` when it binds. Without `row`, the key alone is judged. */
|
|
525
|
+
export declare function parkBindingFault(key: {
|
|
526
|
+
readonly token: string;
|
|
527
|
+
readonly sessionId: string;
|
|
528
|
+
}, row?: {
|
|
529
|
+
readonly token: string;
|
|
530
|
+
readonly sessionId: string;
|
|
531
|
+
}): string | undefined;
|
|
532
|
+
/** Whether two key lists ({@link workflowClaimKeysOf}) name the same keys in the same order. */
|
|
533
|
+
export declare function sameClaimKeys(a: readonly string[], b: readonly string[]): boolean;
|
|
495
534
|
/** The record of `id` in `tree`, if it is one of its runs. */
|
|
496
535
|
export declare function workflowRunInTree(tree: WorkflowRunTree, id: string): WorkflowRun | undefined;
|
|
497
536
|
/** The runs of `tree` below `id` (its successors, theirs, …), in the order the tree holds them. */
|
|
@@ -638,9 +677,9 @@ export declare function workflowParkUnusedSentence(o: Extract<WorkflowParkAdopti
|
|
|
638
677
|
}>): string;
|
|
639
678
|
/** The refusal of a model's `Workflow({ resumeFromRunId })` call for a run that is not continued: the reason's own sentence (the
|
|
640
679
|
* engine's continuation tells the person the same one), with the decision half only when the call carried decisions. */
|
|
641
|
-
export declare function notContinuedRefusalOf(runId: string, reason: "launch_unreadable" | "waiting_elsewhere" | "continuing_elsewhere", more?: Pick<Extract<WorkflowParkAdoption, {
|
|
680
|
+
export declare function notContinuedRefusalOf(runId: string, reason: "launch_unreadable" | "waiting_elsewhere" | "continuing_elsewhere" | "workflow_stopped", more?: Pick<Extract<WorkflowParkAdoption, {
|
|
642
681
|
kind: "unused";
|
|
643
|
-
}>, "code" | "holder" | "waiting" | "claimExpiresAt" | "claimLapseUnreadable" | "heldForAnswer"> & {
|
|
682
|
+
}>, "code" | "holder" | "waiting" | "claimExpiresAt" | "claimLapseUnreadable" | "heldForAnswer" | "stoppedBy"> & {
|
|
644
683
|
readonly decisionIds?: readonly string[];
|
|
645
684
|
}): string;
|
|
646
685
|
/** Why a run of a tree past {@link WORKFLOW_TREE_RUNS_MAX} is not continued, and the way out — one wording for the model's own
|
|
@@ -26,6 +26,7 @@ export const WORKFLOW_PARK_UNUSED_REASONS = Object.freeze([
|
|
|
26
26
|
"card_unresumable",
|
|
27
27
|
"waiting_elsewhere",
|
|
28
28
|
"run_not_ended",
|
|
29
|
+
"workflow_stopped",
|
|
29
30
|
]);
|
|
30
31
|
function frozenRows(table) {
|
|
31
32
|
for (const row of Object.values(table))
|
|
@@ -50,6 +51,7 @@ export const WORKFLOW_PARK_UNUSED_REASON_CLASS = frozenRows({
|
|
|
50
51
|
card_unresumable: { kept: "deliverable", spent: "start_over", spentWhen: "terminal" },
|
|
51
52
|
waiting_elsewhere: { kept: "deliverable" },
|
|
52
53
|
run_not_ended: { kept: "deliverable" },
|
|
54
|
+
workflow_stopped: { kept: "withdraw" },
|
|
53
55
|
});
|
|
54
56
|
export function workflowParkUnusedClassOf(reason, spent) {
|
|
55
57
|
if (typeof spent !== "boolean" || typeof reason !== "string" || !Object.hasOwn(WORKFLOW_PARK_UNUSED_REASON_CLASS, reason))
|
|
@@ -58,7 +60,7 @@ export function workflowParkUnusedClassOf(reason, spent) {
|
|
|
58
60
|
return spent ? row.spent : row.kept;
|
|
59
61
|
}
|
|
60
62
|
const SETTLING = new Set(WORKFLOW_PARK_UNUSED_REASONS.filter((r) => WORKFLOW_PARK_UNUSED_REASON_CLASS[r].spent !== undefined));
|
|
61
|
-
const UNMARKED_REASONS = new Set(["workflow_not_mounted", "entry_unreadable", "record_unreadable", "run_not_ended", "not_pending", "not_holder"]);
|
|
63
|
+
const UNMARKED_REASONS = new Set(["workflow_not_mounted", "entry_unreadable", "record_unreadable", "run_not_ended", "not_pending", "not_holder", "workflow_stopped"]);
|
|
62
64
|
function settlesDecision(o) {
|
|
63
65
|
if (!Object.hasOwn(WORKFLOW_PARK_UNUSED_REASON_CLASS, o.reason))
|
|
64
66
|
return false;
|
|
@@ -171,6 +173,8 @@ export function isAnswerRecordClaimHolder(holder) {
|
|
|
171
173
|
return holder !== undefined && holder.startsWith(ANSWER_RECORD_CLAIM_HOLDER_PREFIX);
|
|
172
174
|
}
|
|
173
175
|
export function claimHeldOf(verdict) {
|
|
176
|
+
if (verdict.stopped !== undefined)
|
|
177
|
+
return { stoppedBy: verdict.stopped.by };
|
|
174
178
|
const lapse = verdict.lapse;
|
|
175
179
|
return {
|
|
176
180
|
...(isAnswerRecordClaimHolder(verdict.holder) ? { heldForAnswer: true } : verdict.holder !== undefined ? { holder: verdict.holder } : {}),
|
|
@@ -250,10 +254,31 @@ export function isContinuationOf(a, b) {
|
|
|
250
254
|
return typeof named !== "string" || workflowRunCreationIdOf(a) === named;
|
|
251
255
|
}
|
|
252
256
|
const WORKFLOW_RUN_TREE = Symbol("WorkflowRunTree");
|
|
253
|
-
const mintTree = (root, records) => ({ root, records, [WORKFLOW_RUN_TREE]: true });
|
|
257
|
+
const mintTree = (root, records, sourceRecreated) => ({ root, records, ...(sourceRecreated !== undefined ? { sourceRecreated } : {}), [WORKFLOW_RUN_TREE]: true });
|
|
254
258
|
export function workflowRunTreeOfOne(run) {
|
|
255
259
|
return mintTree(run, [run]);
|
|
256
260
|
}
|
|
261
|
+
export function workflowClaimKeysOf(tree) {
|
|
262
|
+
const root = tree.root;
|
|
263
|
+
const recorded = root.treeId;
|
|
264
|
+
const named = typeof recorded === "string" ? recorded : resumedFromOf(root) === undefined ? root.id : undefined;
|
|
265
|
+
const treeId = named !== undefined && named === tree.sourceRecreated ? undefined : named;
|
|
266
|
+
return { keys: treeId === undefined || treeId === root.id ? [root.id] : [root.id, treeId], fragment: treeId === undefined };
|
|
267
|
+
}
|
|
268
|
+
export function parkBindingFault(key, row) {
|
|
269
|
+
if (key.token === "" || key.sessionId === "")
|
|
270
|
+
return "the record names no token or no session for it";
|
|
271
|
+
if (row === undefined)
|
|
272
|
+
return undefined;
|
|
273
|
+
if (row.token !== key.token)
|
|
274
|
+
return "the checkpoint store answered a row under another token";
|
|
275
|
+
if (row.sessionId !== key.sessionId)
|
|
276
|
+
return "the checkpoint belongs to another session than the parked row";
|
|
277
|
+
return undefined;
|
|
278
|
+
}
|
|
279
|
+
export function sameClaimKeys(a, b) {
|
|
280
|
+
return a.length === b.length && a.every((k, i) => k === b[i]);
|
|
281
|
+
}
|
|
257
282
|
export function workflowRunInTree(tree, id) {
|
|
258
283
|
return tree.records.find((r) => r.id === id);
|
|
259
284
|
}
|
|
@@ -314,6 +339,7 @@ export async function readWorkflowRunTreeWithin(store, runId, scope, within, sel
|
|
|
314
339
|
let at = await read(runId);
|
|
315
340
|
if (at === "unreadable" || at === null)
|
|
316
341
|
return "unreadable";
|
|
342
|
+
let sourceRecreated;
|
|
317
343
|
for (;;) {
|
|
318
344
|
line.push(at);
|
|
319
345
|
const up = resumedFromOf(at);
|
|
@@ -324,8 +350,11 @@ export async function readWorkflowRunTreeWithin(store, runId, scope, within, sel
|
|
|
324
350
|
const source = await read(up);
|
|
325
351
|
if (source === "unreadable")
|
|
326
352
|
return "unreadable";
|
|
327
|
-
if (source === null || !isContinuationOf(source, at))
|
|
353
|
+
if (source === null || !isContinuationOf(source, at)) {
|
|
354
|
+
if (source !== null)
|
|
355
|
+
sourceRecreated = up;
|
|
328
356
|
break;
|
|
357
|
+
}
|
|
329
358
|
if (line.length >= WORKFLOW_TREE_RUNS_MAX)
|
|
330
359
|
return "over_bound";
|
|
331
360
|
at = source;
|
|
@@ -373,7 +402,7 @@ export async function readWorkflowRunTreeWithin(store, runId, scope, within, sel
|
|
|
373
402
|
if (down === undefined || workflowRunCreationIdOf(down) !== workflowRunCreationIdOf(r))
|
|
374
403
|
return "unreadable";
|
|
375
404
|
}
|
|
376
|
-
return mintTree(root, records);
|
|
405
|
+
return mintTree(root, records, sourceRecreated);
|
|
377
406
|
}
|
|
378
407
|
export async function otherWaitingLine(tree, parkStore, fromRunId, within) {
|
|
379
408
|
const records = tree.records;
|
|
@@ -731,9 +760,11 @@ export function createWorkflowParkAdopter(seats) {
|
|
|
731
760
|
const line = await otherWaitingLine(over, parkStore, x.id, within);
|
|
732
761
|
return line.kind === "unreadable" ? unusedCarried("record_unreadable") : line.kind === "waiting" ? unusedCarried("waiting_elsewhere", { waiting: line.lines }) : line.root;
|
|
733
762
|
};
|
|
734
|
-
const
|
|
735
|
-
if (typeof
|
|
736
|
-
return told(
|
|
763
|
+
const line0 = await lineOf(tree);
|
|
764
|
+
if (typeof line0 !== "string")
|
|
765
|
+
return told(line0);
|
|
766
|
+
const claimKeys = workflowClaimKeysOf(tree).keys;
|
|
767
|
+
const sameTree = (over) => sameClaimKeys(workflowClaimKeysOf(over).keys, claimKeys);
|
|
737
768
|
if (x.errorCode !== WORKFLOW_AGENT_PARKED_ERROR_CODE)
|
|
738
769
|
return unusedCarried("record_unreadable");
|
|
739
770
|
let launch;
|
|
@@ -801,14 +832,14 @@ export function createWorkflowParkAdopter(seats) {
|
|
|
801
832
|
const line = await lineOf(judgedTree);
|
|
802
833
|
if (typeof line !== "string")
|
|
803
834
|
superseded = line;
|
|
804
|
-
else if (
|
|
835
|
+
else if (!sameTree(judgedTree))
|
|
805
836
|
superseded = unusedCarried("record_unreadable");
|
|
806
837
|
return superseded === undefined ? carried.map(({ entry }) => decisionOf(entry)) : false;
|
|
807
838
|
};
|
|
808
839
|
const deniedUnderClaim = async (layer) => {
|
|
809
840
|
if ((await rejudge()) === false || carried.length === 0)
|
|
810
841
|
return undefined;
|
|
811
|
-
if (judgedTree
|
|
842
|
+
if (!sameTree(judgedTree)) {
|
|
812
843
|
superseded = unusedCarried("record_unreadable");
|
|
813
844
|
return undefined;
|
|
814
845
|
}
|
|
@@ -844,7 +875,9 @@ export function createWorkflowParkAdopter(seats) {
|
|
|
844
875
|
}
|
|
845
876
|
if (judged.kind === "denied" && judged.explicit) {
|
|
846
877
|
const layer = judged.layer;
|
|
847
|
-
const under = await seats.underClaim(
|
|
878
|
+
const under = await seats.underClaim(claimKeys, scope, () => deniedUnderClaim(layer));
|
|
879
|
+
if ("claimHeld" in under && under.claimHeld.stoppedBy !== undefined)
|
|
880
|
+
return unusedCarried("workflow_stopped", { stoppedBy: under.claimHeld.stoppedBy });
|
|
848
881
|
if ("claimHeld" in under)
|
|
849
882
|
return unusedCarried("continuing_elsewhere", { ...under.claimHeld, answerUnrecorded: true });
|
|
850
883
|
if ("refused" in under)
|
|
@@ -860,7 +893,7 @@ export function createWorkflowParkAdopter(seats) {
|
|
|
860
893
|
}
|
|
861
894
|
let started;
|
|
862
895
|
try {
|
|
863
|
-
started = await seats.launch({ fromRunId: runId, launch, decisions: carried.map(({ entry }) => decisionOf(entry)),
|
|
896
|
+
started = await seats.launch({ fromRunId: runId, launch, decisions: carried.map(({ entry }) => decisionOf(entry)), claimKeys }, ctx, confirm);
|
|
864
897
|
}
|
|
865
898
|
catch (e) {
|
|
866
899
|
started = { refused: `the continuation's launch threw ${storeErrorClassOf(e)}` };
|
|
@@ -869,7 +902,7 @@ export function createWorkflowParkAdopter(seats) {
|
|
|
869
902
|
if ("refused" in started)
|
|
870
903
|
return told(unusedCarried("launch_refused", { why: neutral(started.refused, WHY_ECHO_MAX) }));
|
|
871
904
|
if ("claimHeld" in started)
|
|
872
|
-
return told(unusedCarried("continuing_elsewhere", started.claimHeld));
|
|
905
|
+
return told(started.claimHeld.stoppedBy !== undefined ? unusedCarried("workflow_stopped", { stoppedBy: started.claimHeld.stoppedBy }) : unusedCarried("continuing_elsewhere", started.claimHeld));
|
|
873
906
|
if ("superseded" in started)
|
|
874
907
|
return supersededAnswer();
|
|
875
908
|
const stepDenied = carried.some((c) => isObject(c.entry.outcome) && c.entry.outcome.decision === "deny");
|
|
@@ -952,6 +985,8 @@ export function workflowParkUnusedSentence(o) {
|
|
|
952
985
|
const echo = (s) => `"${neutral(s)}"`;
|
|
953
986
|
const waiting = "The approval card is still waiting";
|
|
954
987
|
switch (o.reason) {
|
|
988
|
+
case "workflow_stopped":
|
|
989
|
+
return `the workflow was stopped${o.stoppedBy !== undefined ? ` (by ${echo(o.stoppedBy)})` : ""}: it does not run another step, so this decision continues nothing and nothing was started. Nothing is left to do for this decision; to run the work again, start the workflow again`;
|
|
955
990
|
case "workflow_not_mounted":
|
|
956
991
|
return `this run of the session cannot start workflows. ${waiting}, and the decision is kept for a later run of the session that can`;
|
|
957
992
|
case "entry_unreadable":
|
|
@@ -94,7 +94,16 @@ export function buildWorkflowPrimitives(ctx, governance, onAgentSpawn, parentChe
|
|
|
94
94
|
};
|
|
95
95
|
return {
|
|
96
96
|
agent,
|
|
97
|
-
parallel: (thunks) =>
|
|
97
|
+
parallel: async (thunks, opts) => {
|
|
98
|
+
if (opts === null || typeof opts !== "object") {
|
|
99
|
+
return ctx.parallel(thunks, undefined);
|
|
100
|
+
}
|
|
101
|
+
const errors = opts.errors;
|
|
102
|
+
if (errors !== undefined && !Array.isArray(errors)) {
|
|
103
|
+
throw new TypeError("parallel: opts.errors must be an array");
|
|
104
|
+
}
|
|
105
|
+
return ctx.parallel(thunks, errors !== undefined ? { errors } : undefined);
|
|
106
|
+
},
|
|
98
107
|
pipeline: (items, ...stages) => ctx.pipeline(items, ...stages),
|
|
99
108
|
phase: (title, body) => ctx.phase(title, body),
|
|
100
109
|
log: (message) => ctx.log(message),
|
|
@@ -90,8 +90,8 @@ export interface WorkflowPrimitives {
|
|
|
90
90
|
/** Spawn one governed sub-agent. `spec` is an UNTRUSTED `WorkflowAgentSpec` (whitelist-constructed by the
|
|
91
91
|
* engine, design/98 §2.5); `opts` carries `label`/`phase`/`schema`. Resolves to the task result. */
|
|
92
92
|
agent(spec: unknown, opts?: unknown): Promise<unknown>;
|
|
93
|
-
/** Run thunks concurrently (BARRIER); a thrown thunk resolves to `null`. */
|
|
94
|
-
parallel(thunks: unknown[]): Promise<unknown[]>;
|
|
93
|
+
/** Run thunks concurrently (BARRIER); a thrown thunk resolves to `null`. `opts.errors`, an array, collects one entry per failed slot. */
|
|
94
|
+
parallel(thunks: unknown[], opts?: unknown): Promise<unknown[]>;
|
|
95
95
|
/** Run each item through all stages independently (no barrier between stages). */
|
|
96
96
|
pipeline(items: unknown[], ...stages: unknown[]): Promise<unknown[]>;
|
|
97
97
|
/** Group work under a named phase (observability). */
|