@sema-agent/core 7.69.0 → 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 +583 -0
- package/dist/agents/repair-loop.js +6 -14
- package/dist/agents/subagent.js +2 -1
- package/dist/agents/verify.d.ts +1 -1
- package/dist/agents/verify.js +7 -1
- package/dist/brain/reasoning-request.d.ts +7 -0
- package/dist/brain/reasoning-request.js +6 -0
- package/dist/core/agent-config-dir.d.ts +39 -3
- package/dist/core/agent-config-dir.js +67 -11
- package/dist/core/allow-entry.d.ts +5 -5
- package/dist/core/allow-entry.js +12 -6
- package/dist/core/ask-headline.d.ts +2 -2
- package/dist/core/ask-origin.d.ts +31 -31
- package/dist/core/ask-origin.js +20 -13
- package/dist/core/attachment-source.d.ts +1 -1
- package/dist/core/attachment-source.js +1 -0
- package/dist/core/auto-compaction.d.ts +44 -62
- package/dist/core/auto-compaction.js +44 -103
- package/dist/core/cache-break-detector.d.ts +23 -11
- package/dist/core/cache-break-detector.js +11 -5
- package/dist/core/checkpoint-features.d.ts +1 -1
- package/dist/core/checkpoint-features.js +1 -1
- package/dist/core/checkpoint-requirements.d.ts +19 -1
- package/dist/core/checkpoint-requirements.js +6 -0
- package/dist/core/checkpoint-row-verdict.js +3 -0
- package/dist/core/checkpoint-store.d.ts +13 -2
- package/dist/core/child-clamp-seats.d.ts +30 -3
- package/dist/core/child-clamp-seats.js +24 -0
- 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 +1 -1
- package/dist/core/config-refusal-codes.js +2 -0
- package/dist/core/context-edit.d.ts +32 -17
- package/dist/core/context-edit.js +28 -0
- package/dist/core/cron.d.ts +68 -0
- package/dist/core/cron.js +259 -0
- package/dist/core/engine-attestation.d.ts +16 -0
- package/dist/core/engine-attestation.js +2 -0
- package/dist/core/engine-capabilities.d.ts +14 -1
- package/dist/core/engine-capabilities.js +1 -1
- package/dist/core/engine-notice.d.ts +18 -7
- package/dist/core/engine-version.js +1 -1
- package/dist/core/gate-outcome.d.ts +29 -2
- package/dist/core/gate-outcome.js +6 -0
- 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.js +9 -8
- package/dist/core/governance-codes.d.ts +9 -2
- package/dist/core/governance-codes.js +9 -0
- package/dist/core/locked-config.js +7 -3
- package/dist/core/lsp.d.ts +3 -0
- package/dist/core/lsp.js +3 -2
- package/dist/core/memory-engine/engine.d.ts +48 -12
- package/dist/core/memory-engine/engine.js +108 -46
- 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 +20 -3
- package/dist/core/memory-engine/layout.js +39 -3
- 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/mode-policy.d.ts +7 -1
- package/dist/core/mode-policy.js +9 -0
- package/dist/core/mods/session-compact.js +3 -3
- package/dist/core/mods/stations.d.ts +2 -0
- package/dist/core/mods/stations.js +2 -1
- 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 +3 -0
- package/dist/core/peer-seat.js +3 -0
- package/dist/core/permission-rule-model.js +3 -2
- package/dist/core/process-identity.d.ts +11 -3
- package/dist/core/process-identity.js +26 -16
- package/dist/core/runner/assemble-result.d.ts +5 -0
- package/dist/core/runner/assemble-result.js +1 -1
- 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/compact-session.js +14 -9
- package/dist/core/runner/compaction-knobs.d.ts +1 -1
- package/dist/core/runner/continuation-gate.js +2 -1
- package/dist/core/runner/continues-from.d.ts +1 -1
- package/dist/core/runner/continues-from.js +1 -1
- package/dist/core/runner/contracts.d.ts +83 -31
- package/dist/core/runner/conversation-segment.d.ts +19 -12
- package/dist/core/runner/conversation-segment.js +27 -7
- package/dist/core/runner/derived-route-fallback.d.ts +2 -12
- package/dist/core/runner/derived-route-fallback.js +0 -6
- package/dist/core/runner/gate-exit.d.ts +2 -1
- package/dist/core/runner/gate-exit.js +4 -2
- package/dist/core/runner/git-status-frame.d.ts +2 -2
- package/dist/core/runner/git-status-frame.js +2 -1
- package/dist/core/runner/initial-run-state.js +1 -1
- 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 +29 -2
- package/dist/core/runner/leg-receipt.js +37 -6
- 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/messages-omitted-seat.d.ts +2 -1
- package/dist/core/runner/messages-omitted-seat.js +15 -5
- package/dist/core/runner/person-path-rows.d.ts +25 -7
- package/dist/core/runner/person-path-rows.js +16 -2
- package/dist/core/runner/prefix-ledger.d.ts +120 -0
- package/dist/core/runner/prefix-ledger.js +176 -0
- package/dist/core/runner/prepare-advisor.d.ts +2 -0
- package/dist/core/runner/prepare-advisor.js +2 -1
- package/dist/core/runner/prepare-artifact.d.ts +3 -0
- package/dist/core/runner/prepare-artifact.js +2 -2
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +2 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +4 -3
- package/dist/core/runner/prepare-config-doors.d.ts +9 -8
- package/dist/core/runner/prepare-config-doors.js +15 -12
- package/dist/core/runner/prepare-context-lane.d.ts +25 -6
- package/dist/core/runner/prepare-context-lane.js +82 -27
- package/dist/core/runner/prepare-gate-stations.d.ts +1 -2
- package/dist/core/runner/prepare-gate-stations.js +2 -4
- package/dist/core/runner/prepare-hands-readface.d.ts +18 -5
- package/dist/core/runner/prepare-hands-readface.js +41 -22
- package/dist/core/runner/prepare-inherited-gate.d.ts +5 -0
- package/dist/core/runner/prepare-inherited-gate.js +2 -0
- package/dist/core/runner/prepare-memory.d.ts +10 -2
- package/dist/core/runner/prepare-memory.js +51 -5
- package/dist/core/runner/prepare-policy-chain.d.ts +3 -0
- package/dist/core/runner/prepare-policy-chain.js +13 -2
- package/dist/core/runner/prepare-prompt-assembly.d.ts +12 -4
- package/dist/core/runner/prepare-prompt-assembly.js +10 -4
- package/dist/core/runner/prepare-prompt-inputs.d.ts +3 -7
- package/dist/core/runner/prepare-prompt-inputs.js +6 -7
- package/dist/core/runner/prepare-safety-scan.js +7 -0
- package/dist/core/runner/prepare-suspend-saga.d.ts +4 -0
- package/dist/core/runner/prepare-suspend-saga.js +3 -2
- package/dist/core/runner/prepare-task.js +59 -53
- 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 +16 -25
- package/dist/core/runner/prepare-turn-wiring.js +8 -18
- package/dist/core/runner/prepare-wiring-manifest.d.ts +1 -0
- package/dist/core/runner/prepare-wiring-manifest.js +3 -2
- package/dist/core/runner/prompt-suggestions.d.ts +3 -1
- package/dist/core/runner/prompt-suggestions.js +1 -1
- 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/role-resolution-table.d.ts +15 -10
- package/dist/core/runner/role-resolution-table.js +4 -5
- package/dist/core/runner/rule-store-unreadable-notice.d.ts +7 -4
- package/dist/core/runner/rule-store-unreadable-notice.js +4 -3
- package/dist/core/runner/run-compaction-machinery.d.ts +0 -10
- package/dist/core/runner/run-compaction-machinery.js +3 -39
- package/dist/core/runner/run-harness-handlers.js +4 -17
- package/dist/core/runner/run-identity-wiring.js +4 -1
- package/dist/core/runner/run-leg.js +11 -1
- package/dist/core/runner/run-recovery-lanes.d.ts +0 -4
- package/dist/core/runner/run-recovery-lanes.js +34 -18
- package/dist/core/runner/run-settle-and-teardown.d.ts +1 -3
- package/dist/core/runner/run-settle-and-teardown.js +14 -22
- package/dist/core/runner/run-telemetry-and-budget-seats.js +0 -1
- package/dist/core/runner/run-terminal-adoption.d.ts +11 -30
- package/dist/core/runner/run-terminal-adoption.js +5 -88
- package/dist/core/runner/run-tool-mount-facts.js +1 -5
- package/dist/core/runner/run-turn-boundary.js +56 -26
- package/dist/core/runner/runtask.js +7 -7
- 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/shell-env-withheld.d.ts +8 -5
- package/dist/core/runner/shell-env-withheld.js +3 -3
- package/dist/core/runner/side-call-account.d.ts +9 -1
- package/dist/core/runner/side-call-account.js +15 -4
- package/dist/core/runner/skill-mention.d.ts +12 -0
- package/dist/core/runner/skill-mention.js +50 -0
- package/dist/core/runner/stream-settle-backstop.js +1 -0
- package/dist/core/runner/synthetic-tools.js +2 -2
- package/dist/core/runner/tool-table-view.d.ts +5 -9
- package/dist/core/runner/tool-table-view.js +23 -21
- package/dist/core/runner/write-protection-station.d.ts +5 -2
- package/dist/core/runner/write-protection-station.js +1 -1
- package/dist/core/runner-deps.d.ts +25 -27
- package/dist/core/scheduler.d.ts +13 -3
- package/dist/core/scheduler.js +0 -12
- package/dist/core/secret-env.d.ts +47 -11
- package/dist/core/secret-env.js +65 -4
- package/dist/core/sensitive-path-policy.js +4 -0
- package/dist/core/session-checkout.js +10 -9
- package/dist/core/shell-read-silence.d.ts +2 -1
- package/dist/core/shell-run-candidates.d.ts +1 -1
- package/dist/core/shell-run-candidates.js +11 -3
- package/dist/core/task-event.d.ts +32 -10
- package/dist/core/task-intake.d.ts +5 -3
- package/dist/core/task-intake.js +6 -2
- package/dist/core/task-result.d.ts +39 -0
- package/dist/core/task-spec-members.d.ts +3 -0
- package/dist/core/task-spec-members.js +2 -2
- package/dist/core/task-spec.d.ts +37 -20
- package/dist/core/tool-policy.d.ts +30 -18
- package/dist/core/tool-policy.js +44 -32
- package/dist/core/tool-roster.d.ts +21 -7
- package/dist/core/tool-roster.js +34 -6
- package/dist/core/tool-spec-members.js +1 -1
- package/dist/core/tool-spec.d.ts +27 -0
- package/dist/core/tools.js +1 -0
- package/dist/core/trace.d.ts +42 -19
- package/dist/core/unc-spelling.d.ts +31 -0
- package/dist/core/unc-spelling.js +51 -0
- package/dist/core/wiring-manifest.d.ts +30 -3
- package/dist/core/wiring-manifest.js +10 -0
- package/dist/core/workflow-run-store-contract.js +22 -0
- package/dist/core/workflow-run-store.d.ts +17 -13
- package/dist/core/workflow-run-store.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 +48 -98
- package/dist/engine/compaction/compaction.js +136 -216
- 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.js +17 -6
- package/dist/engine/harness/agent-harness.d.ts +19 -5
- package/dist/engine/harness/agent-harness.js +18 -7
- package/dist/engine/harness/types.d.ts +5 -7
- package/dist/engine/loop/agent-loop.d.ts +14 -1
- package/dist/engine/loop/agent-loop.js +31 -11
- package/dist/engine/loop/types.d.ts +8 -2
- package/dist/index.d.ts +9 -6
- package/dist/index.js +8 -6
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/internal/harness.d.ts +1 -1
- package/dist/internal/harness.js +1 -1
- package/dist/orchestration/run-spec.js +7 -2
- package/dist/orchestration/run-workflow-tool.js +5 -3
- package/dist/orchestration/workflow-park-adoption.d.ts +66 -8
- package/dist/orchestration/workflow-park-adoption.js +195 -45
- package/dist/orchestration/workflow-types.d.ts +20 -0
- package/dist/orchestration/workflow-types.js +1 -0
- package/dist/orchestration/workflow.d.ts +3 -2
- package/dist/orchestration/workflow.js +10 -4
- package/dist/prompt-assembly/catalog/core-behavior.js +6 -0
- package/dist/prompt-assembly/catalog/events.d.ts +8 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/core-behavior.js +6 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/mechanism.js +1 -0
- package/dist/prompt-assembly/catalog/mechanism.d.ts +8 -0
- package/dist/prompt-assembly/catalog/mechanism.js +1 -0
- package/dist/prompt-assembly/catalog/schema.d.ts +1 -1
- package/dist/prompt-assembly/catalog/schema.js +1 -0
- package/dist/prompt-assembly/catalog/sections.js +8 -0
- package/dist/prompt-assembly/event-registry.js +1 -0
- package/dist/prompt-assembly/select.js +1 -0
- package/dist/prompt-assembly/turn-snapshot.d.ts +14 -27
- package/dist/prompt-assembly/turn-snapshot.js +6 -18
- package/dist/prompt-assembly/types.d.ts +3 -0
- package/dist/prompts/default.d.ts +9 -0
- package/dist/prompts/default.js +4 -0
- package/dist/shell/lex.d.ts +75 -11
- package/dist/shell/lex.js +340 -76
- 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 +19 -9
- package/dist/tools/fs/containment-face.d.ts +12 -3
- package/dist/tools/fs/containment-face.js +16 -7
- 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 +4 -4
- package/dist/tools/fs/fs-read.d.ts +3 -0
- package/dist/tools/fs/fs-read.js +2 -2
- 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/index.js +5 -3
- package/dist/tools/fs/pdf.js +12 -4
- 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/removal-targets.d.ts +33 -17
- package/dist/tools/fs/removal-targets.js +160 -61
- 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 +28 -5
- package/dist/tools/fs/safety.js +72 -8
- 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 +3 -0
- package/dist/tools/fs/shell-read-check.js +22 -4
- package/dist/tools/fs/shell-read-establish.js +73 -43
- package/dist/tools/fs/shell-read-judge.d.ts +32 -14
- package/dist/tools/fs/shell-read-judge.js +13 -5
- 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 +8 -2
- package/dist/tools/fs/shell-read-plan.js +36 -22
- package/dist/tools/fs/shell-read-sourced.js +12 -4
- 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/scheduler-tools.d.ts +7 -17
- package/dist/tools/scheduler-tools.js +9 -85
- package/dist/tools/worktree.js +5 -4
- package/package.json +3 -2
- package/test/export-surface.snapshot.json +47 -1
- package/wire-changes/core-stores-sql@7.68.6.json +39 -0
- package/wire-changes/core-stores-sql@7.69.1.json +39 -0
- package/wire-changes/core@7.68.6.json +125 -0
- package/wire-changes/core@7.69.1.json +2561 -0
- package/wire-changes/mods-kernel@7.68.6.json +39 -0
- package/wire-changes/mods-kernel@7.69.1.json +39 -0
- package/wire-changes/primitives@7.68.6.json +39 -0
- package/wire-changes/primitives@7.69.1.json +39 -0
- package/wire-changes/wiki-gate@7.68.6.json +39 -0
- 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
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
* for the `Workflow` call that continues it (an ordinary ask is answered by a person's decision — an allow or a deny of the
|
|
13
13
|
* parked step alike; any other class is put to a person, and nobody to ask is a refusal); then one continuation starts, its
|
|
14
14
|
* resume claim taken before the run exists (a claim another run holds starts nothing). What did not start is answered with a
|
|
15
|
-
* reason from one closed set.
|
|
15
|
+
* reason from one closed set. A reason that settles a decision for good ({@link WORKFLOW_PARK_SETTLING_REASONS}) is also recorded,
|
|
16
|
+
* once, on the record of the run that holds the decision's park, and a decision so recorded, handed over again, is answered with
|
|
17
|
+
* nothing ({@link workflowParkDecisionOf} reads the record). One continuation per run per leg; nothing here throws.
|
|
16
18
|
*/
|
|
17
19
|
import type { CheckpointStore, CheckpointToken, ResumeOutcome } from "../core/checkpoint-store.js";
|
|
18
20
|
import type { WorkflowRunStore } from "../core/workflow-run-store.js";
|
|
@@ -33,6 +35,52 @@ export interface WorkflowParkDecision {
|
|
|
33
35
|
/** Why a decision did not continue its run — the closed set `workflow.parked_decision_unused` carries as `detail.reason`. */
|
|
34
36
|
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", "launch_refused", "continuing_elsewhere", "card_unresumable", "waiting_elsewhere", "run_not_ended"];
|
|
35
37
|
export type WorkflowParkUnusedReason = (typeof WORKFLOW_PARK_UNUSED_REASONS)[number];
|
|
38
|
+
/**
|
|
39
|
+
* The reasons that settle a decision for good — no later hand-over of it continues the run; a person decides the card again (a new
|
|
40
|
+
* decision) or starts the workflow again, as each reason's sentence says: the decision was used once and its drive refused
|
|
41
|
+
* (`decision_spent`); the card is one no engine release resumes (`card_unresumable` with `terminal` — only then: a card another
|
|
42
|
+
* release reads stays deliverable to a worker of that release); the run's launch record does not read back (`launch_unreadable`);
|
|
43
|
+
* a person, asked whether to run the Workflow call that continues it, answered no (`denied` with `explicit` — only then: a deny rule
|
|
44
|
+
* of any layer, the deployment's policy or its approval seat, a hook, a classifier, the session's mode, a wait that ran out or was
|
|
45
|
+
* cancelled, an approver or a policy that failed leave it deliverable). Every other reason leaves
|
|
46
|
+
* the decision deliverable — `host_changed` among them: once what the run's agents run under is back to what it ran under, the
|
|
47
|
+
* same decision continues the run (and a worker still on those settings can use it meanwhile). The `reason` of a `spent`
|
|
48
|
+
* {@link workflowParkDecisionOf} reading.
|
|
49
|
+
*/
|
|
50
|
+
export declare const WORKFLOW_PARK_SETTLING_REASONS: readonly ["decision_spent", "card_unresumable", "launch_unreadable", "denied"];
|
|
51
|
+
export type WorkflowParkSettlingReason = (typeof WORKFLOW_PARK_SETTLING_REASONS)[number];
|
|
52
|
+
/** What came of one host decision for one park, as the run records of the park's chain say ({@link workflowParkDecisionOf}):
|
|
53
|
+
* - `open` — no record says anything of it: a hand-over may continue the run (the card's own state and the holder law aside);
|
|
54
|
+
* - `carried` — a continuation (`runId`) carried it and ended before its script reached the parked step (`not_reached`): it is not
|
|
55
|
+
* spent, and handed over again on its own it only reaches the same wait — hand it over with a decision for what stopped that run;
|
|
56
|
+
* - `driven` — a continuation (`runId`) drove the parked step with it: the card was consumed;
|
|
57
|
+
* - `spent` — no later hand-over of it continues the run (`reason`, a word of {@link WORKFLOW_PARK_SETTLING_REASONS}, and its
|
|
58
|
+
* `code`): the drive of a continuation (`runId`) refused it, or the engine's continuation judged it on the record of the run that
|
|
59
|
+
* held the park (`runId`) and said so. */
|
|
60
|
+
export type WorkflowParkDecisionState = {
|
|
61
|
+
readonly kind: "open";
|
|
62
|
+
} | {
|
|
63
|
+
readonly kind: "carried";
|
|
64
|
+
readonly runId: string;
|
|
65
|
+
} | {
|
|
66
|
+
readonly kind: "driven";
|
|
67
|
+
readonly runId: string;
|
|
68
|
+
} | {
|
|
69
|
+
readonly kind: "spent";
|
|
70
|
+
readonly runId: string;
|
|
71
|
+
readonly reason: WorkflowParkSettlingReason;
|
|
72
|
+
readonly code?: string;
|
|
73
|
+
};
|
|
74
|
+
type RecordsOfPark = ReadonlyArray<Pick<WorkflowRun, "id" | "parks" | "resume"> | null | undefined>;
|
|
75
|
+
/**
|
|
76
|
+
* What came of the host decision `decisionId` for the park on `token`, read off the run records given — hand it the park's chain, the
|
|
77
|
+
* records the holder law reads ({@link workflowParkHolderOf}: the run that parked it and its successors): a run that comes to hold a
|
|
78
|
+
* park carries its holder's marks onto its own entry, but a mark another leg wrote on an earlier holder while the park was moving on
|
|
79
|
+
* lives on that earlier record alone, and the holder's record by itself reads such a decision `open`. The one reading a host's "hand it
|
|
80
|
+
* over again?" judge and the engine's continuation share. Pure over the records; whether the card is still pending is the checkpoint
|
|
81
|
+
* store's word, and which run to hand it to the holder law's, never this. A `driven` row wins, then a `spent` one, then `carried`.
|
|
82
|
+
*/
|
|
83
|
+
export declare function workflowParkDecisionOf(token: string, decisionId: string, records: RecordsOfPark): WorkflowParkDecisionState;
|
|
36
84
|
/** What came of the decisions naming one run. */
|
|
37
85
|
export type WorkflowParkAdoption = {
|
|
38
86
|
readonly kind: "started";
|
|
@@ -66,6 +114,9 @@ export type WorkflowParkAdoption = {
|
|
|
66
114
|
readonly rowReason?: string;
|
|
67
115
|
readonly rowSentence?: string;
|
|
68
116
|
readonly terminal?: true;
|
|
117
|
+
/** `denied`: the refusal is a person's own answer to the call's question (it settles the decision; every other refusal leaves
|
|
118
|
+
* it deliverable). Not on the notice; the sentence reads it. */
|
|
119
|
+
readonly explicit?: true;
|
|
69
120
|
/** `not_pending`: the run that continued the run from this card (its record holds a `driven` row for the card's call). */
|
|
70
121
|
readonly continuedAs?: string;
|
|
71
122
|
/** `host_changed`: which half moved — `identity`: the settings every agent of the run is folded under (the deployment's
|
|
@@ -115,7 +166,8 @@ export type HostFoldInput = (typeof HOST_FOLD_INPUTS)[number];
|
|
|
115
166
|
/** The stamp of a fold whose inputs digest to `digests`. */
|
|
116
167
|
export declare function hostFoldStampOf(digests: Readonly<Record<HostFoldInput, string>>): string;
|
|
117
168
|
/** This leg's gate for the `Workflow` call that continues a run: judged with every layer of the leg's gate, the ask resolved
|
|
118
|
-
* by the answer given here (a person's decision answers only an ask whose class is `ordinary`), never parked.
|
|
169
|
+
* by the answer given here (a person's decision answers only an ask whose class is `ordinary`), never parked. A refusal says
|
|
170
|
+
* whether it is a person's own "no" to the call's question (`explicit`) — the one refusal that settles the decision. */
|
|
119
171
|
export interface WorkflowContinuationGate {
|
|
120
172
|
judge(call: {
|
|
121
173
|
readonly toolCallId: string;
|
|
@@ -126,6 +178,7 @@ export interface WorkflowContinuationGate {
|
|
|
126
178
|
} | {
|
|
127
179
|
readonly kind: "denied";
|
|
128
180
|
readonly layer: string;
|
|
181
|
+
readonly explicit: boolean;
|
|
129
182
|
} | {
|
|
130
183
|
readonly kind: "ask_unanswerable";
|
|
131
184
|
}>;
|
|
@@ -163,9 +216,10 @@ export interface WorkflowParkAdopterSeats {
|
|
|
163
216
|
readonly chainToHand: (ctx: ToolExecuteContext) => InheritedGate["parentConstraints"] | undefined;
|
|
164
217
|
/** Start the continuation (the tool's own launch, its third argument): the new run's id, the launch's refusal, or — the run's
|
|
165
218
|
* resume claim taken before the run exists and refused — its hold, as the store told it (no run was started). Once the claim is
|
|
166
|
-
* granted and before the run exists, the launch asks `confirm` (the adopter's card judgment read again, under the claim):
|
|
219
|
+
* granted and before the run exists, the launch asks `confirm` (the adopter's card judgment read again, under the claim): the
|
|
220
|
+
* decisions the continuation carries — `continuation.decisions` less any another leg recorded as settled meanwhile — or
|
|
167
221
|
* `false` ⇒ it releases the claim and starts nothing (`superseded`). */
|
|
168
|
-
readonly launch: (continuation: WorkflowContinuation, ctx: ToolExecuteContext, confirm: () => Promise<
|
|
222
|
+
readonly launch: (continuation: WorkflowContinuation, ctx: ToolExecuteContext, confirm: () => Promise<WorkflowContinuation["decisions"] | false>) => Promise<{
|
|
169
223
|
readonly runId: string;
|
|
170
224
|
} | {
|
|
171
225
|
readonly refused: string;
|
|
@@ -265,7 +319,7 @@ export declare function readWorkflowRunChain(store: Pick<WorkflowRunStore, "get"
|
|
|
265
319
|
* run it resumed, or the run it names has no record in `scope` any more (reaped: the walk stops below it) — and the line, `runId`
|
|
266
320
|
* and every run above it. `runId` without a record is its own root and line (nothing to walk). `"unreadable"` when a read fails or
|
|
267
321
|
* the walk meets a run twice; `"over_bound"` when the line is more runs than {@link WORKFLOW_TREE_RUNS_MAX}. The one walk the
|
|
268
|
-
* resume claim's key
|
|
322
|
+
* resume claim's key, the one-waiting-line judge ({@link otherWaitingLine}) and the continuation's read of its run under the claim read.
|
|
269
323
|
*/
|
|
270
324
|
export declare function workflowTreeOf(store: Pick<WorkflowRunStore, "get">, runId: string, scope: string, within: BoundedStoreRead): Promise<{
|
|
271
325
|
root: string;
|
|
@@ -311,7 +365,9 @@ export type WorkflowLineVerdict = {
|
|
|
311
365
|
* {@link WORKFLOW_TREE_RUNS_MAX} (`over_bound`). Only this tree's records and its own cards are read: never the host's pending
|
|
312
366
|
* listing.
|
|
313
367
|
*/
|
|
314
|
-
export declare function otherWaitingLine(store: Pick<WorkflowRunStore, "get" | "listByScope">, parkStore: CheckpointStore | undefined, fromRunId: string, scope: string, within: BoundedStoreRead
|
|
368
|
+
export declare function otherWaitingLine(store: Pick<WorkflowRunStore, "get" | "listByScope">, parkStore: CheckpointStore | undefined, fromRunId: string, scope: string, within: BoundedStoreRead,
|
|
369
|
+
/** `fromRunId`'s tree as {@link workflowTreeOf} read it just now, when the caller did (the walk is not made twice). */
|
|
370
|
+
walked?: Awaited<ReturnType<typeof workflowTreeOf>>): Promise<WorkflowLineVerdict>;
|
|
315
371
|
/** The run among `records` whose record accounts a `driven` decision for `callKey` — the run that took a decided card's
|
|
316
372
|
* approval. One reading for the adopter's `continuedAs` and for the sentence a resume settles that step with. */
|
|
317
373
|
export declare function runThatDrove(records: readonly WorkflowRun[], callKey: string): WorkflowRun | undefined;
|
|
@@ -353,8 +409,9 @@ export declare function resumedCallRefusalOf(o: WorkflowParkAdoption): string |
|
|
|
353
409
|
/**
|
|
354
410
|
* A leg's workflow-park contributor to its adoption step: the decisions it carries are continued by the mounted Workflow tool's
|
|
355
411
|
* adopter (or, with no tool mounted, answered `workflow_not_mounted`); every decision that did not continue its run is told to
|
|
356
|
-
* the person once per run (`workflow.parked_decision_unused`, through `deliver`)
|
|
357
|
-
*
|
|
412
|
+
* the person once per run (`workflow.parked_decision_unused`, through `deliver`) — except one the engine already recorded as settled
|
|
413
|
+
* for good, which is answered with nothing — and the returned text — the first request's `workflow_continuation` frame — tells the
|
|
414
|
+
* model what came of each. Undefined when the leg carries no decision.
|
|
358
415
|
*/
|
|
359
416
|
export declare function workflowParksContributor(input: {
|
|
360
417
|
readonly decisions: ReadonlyArray<unknown> | undefined;
|
|
@@ -378,3 +435,4 @@ export declare function workflowParksContributor(input: {
|
|
|
378
435
|
* Workflow tool's name, which the model is told not to call for a continuation the engine started. A decision whose approval
|
|
379
436
|
* the model was already told once to ask for (`askedBefore`) is left out: it is told to the person alone. */
|
|
380
437
|
export declare function workflowContinuationFrameBody(all: readonly WorkflowParkAdoption[], toolName: string, say: EngineText): string | undefined;
|
|
438
|
+
export {};
|
|
@@ -5,7 +5,7 @@ import { readMember, thrownName, thrownText } from "../core/thrown-value.js";
|
|
|
5
5
|
import { inlineUntrusted } from "../core/untrusted-text.js";
|
|
6
6
|
import { egressText } from "../core/untrusted-egress.js";
|
|
7
7
|
import { foreignLine } from "../core/protocol-http-auth.js";
|
|
8
|
-
import { WORKFLOW_AGENT_PARKED_ERROR_CODE, workflowParkHolderOf } from "./workflow-types.js";
|
|
8
|
+
import { WORKFLOW_AGENT_PARKED_ERROR_CODE, WORKFLOW_PARK_SETTLED_DECISIONS_MAX, workflowParkHolderOf } from "./workflow-types.js";
|
|
9
9
|
export const WORKFLOW_PARK_UNUSED_REASONS = Object.freeze([
|
|
10
10
|
"workflow_not_mounted",
|
|
11
11
|
"entry_unreadable",
|
|
@@ -24,6 +24,56 @@ export const WORKFLOW_PARK_UNUSED_REASONS = Object.freeze([
|
|
|
24
24
|
"waiting_elsewhere",
|
|
25
25
|
"run_not_ended",
|
|
26
26
|
]);
|
|
27
|
+
export const WORKFLOW_PARK_SETTLING_REASONS = Object.freeze(["decision_spent", "card_unresumable", "launch_unreadable", "denied"]);
|
|
28
|
+
const SETTLING = new Set(WORKFLOW_PARK_SETTLING_REASONS);
|
|
29
|
+
function settlesDecision(o) {
|
|
30
|
+
return SETTLING.has(o.reason) && (o.reason !== "card_unresumable" || o.terminal === true) && (o.reason !== "denied" || o.explicit === true);
|
|
31
|
+
}
|
|
32
|
+
function parkEntriesOn(token, records) {
|
|
33
|
+
const out = [];
|
|
34
|
+
for (const r of records) {
|
|
35
|
+
if (r === null || r === undefined || !Array.isArray(r.parks))
|
|
36
|
+
continue;
|
|
37
|
+
for (const entry of r.parks)
|
|
38
|
+
if (isObject(entry) && entry.token === token)
|
|
39
|
+
out.push({ runId: r.id, entry });
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
function settledMarkOf(token, decisionId, records) {
|
|
44
|
+
for (const { runId, entry } of parkEntriesOn(token, records)) {
|
|
45
|
+
if (!Array.isArray(entry.settledDecisions))
|
|
46
|
+
continue;
|
|
47
|
+
for (const m of entry.settledDecisions) {
|
|
48
|
+
if (!isObject(m) || m.decisionId !== decisionId || typeof m.reason !== "string" || !SETTLING.has(m.reason))
|
|
49
|
+
continue;
|
|
50
|
+
return { kind: "spent", runId, reason: m.reason, ...(typeof m.code === "string" ? { code: m.code } : {}) };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
export function workflowParkDecisionOf(token, decisionId, records) {
|
|
56
|
+
const callKeys = new Set(parkEntriesOn(token, records).map(({ entry }) => entry.callKey).filter((k) => typeof k === "string"));
|
|
57
|
+
let driven;
|
|
58
|
+
let refused;
|
|
59
|
+
let carried;
|
|
60
|
+
for (const r of records) {
|
|
61
|
+
const rows = r?.resume?.decisions;
|
|
62
|
+
if (r === null || r === undefined || !Array.isArray(rows))
|
|
63
|
+
continue;
|
|
64
|
+
for (const d of rows) {
|
|
65
|
+
if (!isObject(d) || d.decisionId !== decisionId || typeof d.callKey !== "string" || !callKeys.has(d.callKey))
|
|
66
|
+
continue;
|
|
67
|
+
if (d.result === "driven")
|
|
68
|
+
driven ??= { kind: "driven", runId: r.id };
|
|
69
|
+
else if (d.result === "refused")
|
|
70
|
+
refused ??= { kind: "spent", runId: r.id, reason: "decision_spent", ...(typeof d.code === "string" ? { code: d.code } : {}) };
|
|
71
|
+
else if (d.result === "not_reached")
|
|
72
|
+
carried ??= { kind: "carried", runId: r.id };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return driven ?? settledMarkOf(token, decisionId, records) ?? refused ?? carried ?? { kind: "open" };
|
|
76
|
+
}
|
|
27
77
|
export function claimHeldOf(verdict) {
|
|
28
78
|
return { ...(verdict.holder !== undefined ? { holder: verdict.holder } : {}), ...(verdict.expiresAt !== undefined ? { claimExpiresAt: verdict.expiresAt } : {}) };
|
|
29
79
|
}
|
|
@@ -131,7 +181,12 @@ export async function readWorkflowRunChain(store, rootId, scope, within) {
|
|
|
131
181
|
return typeof successors === "string" ? successors : { root, successors };
|
|
132
182
|
}
|
|
133
183
|
export async function workflowTreeOf(store, runId, scope, within) {
|
|
184
|
+
const walked = await workflowLineOf(store, runId, scope, within);
|
|
185
|
+
return typeof walked === "string" ? walked : { root: walked.root, line: walked.line, recorded: walked.recorded };
|
|
186
|
+
}
|
|
187
|
+
async function workflowLineOf(store, runId, scope, within) {
|
|
134
188
|
const line = [];
|
|
189
|
+
const records = [];
|
|
135
190
|
const seen = new Set();
|
|
136
191
|
let id = runId;
|
|
137
192
|
for (;;) {
|
|
@@ -139,21 +194,22 @@ export async function workflowTreeOf(store, runId, scope, within) {
|
|
|
139
194
|
if (r === "unreadable")
|
|
140
195
|
return "unreadable";
|
|
141
196
|
if (r === null)
|
|
142
|
-
return line.length === 0 ? { root: runId, line: [runId], recorded: false } : { root: line[line.length - 1], line, recorded: true };
|
|
197
|
+
return line.length === 0 ? { root: runId, line: [runId], recorded: false, records } : { root: line[line.length - 1], line, recorded: true, records };
|
|
143
198
|
if (line.length >= WORKFLOW_TREE_RUNS_MAX)
|
|
144
199
|
return "over_bound";
|
|
145
200
|
line.push(id);
|
|
201
|
+
records.push(r);
|
|
146
202
|
seen.add(id);
|
|
147
203
|
const up = r.resume?.fromRunId;
|
|
148
204
|
if (up === undefined)
|
|
149
|
-
return { root: id, line, recorded: true };
|
|
205
|
+
return { root: id, line, recorded: true, records };
|
|
150
206
|
if (seen.has(up))
|
|
151
207
|
return "unreadable";
|
|
152
208
|
id = up;
|
|
153
209
|
}
|
|
154
210
|
}
|
|
155
|
-
export async function otherWaitingLine(store, parkStore, fromRunId, scope, within) {
|
|
156
|
-
const tree = await workflowTreeOf(store, fromRunId, scope, within);
|
|
211
|
+
export async function otherWaitingLine(store, parkStore, fromRunId, scope, within, walked) {
|
|
212
|
+
const tree = walked ?? (await workflowTreeOf(store, fromRunId, scope, within));
|
|
157
213
|
if (typeof tree === "string")
|
|
158
214
|
return { kind: tree };
|
|
159
215
|
if (!tree.recorded)
|
|
@@ -232,10 +288,50 @@ function readDecisions(raw) {
|
|
|
232
288
|
}
|
|
233
289
|
return { usable, unreadable };
|
|
234
290
|
}
|
|
291
|
+
const SETTLE_ATTEMPTS = 3;
|
|
235
292
|
export function createWorkflowParkAdopter(seats) {
|
|
236
293
|
const within = boundedStoreRead(seats.waitBoundMs);
|
|
237
294
|
const readRun = async (id, scope) => (seats.store === undefined ? "unreadable" : readWorkflowRunIn(seats.store, id, scope, within));
|
|
238
295
|
const successorsOf = async (x, scope) => (seats.store === undefined ? "unreadable" : workflowRunSuccessors(seats.store, x.id, scope, within));
|
|
296
|
+
const settleOn = async (held, scope, all) => {
|
|
297
|
+
const others = new Set();
|
|
298
|
+
const store = seats.store;
|
|
299
|
+
if (store === undefined)
|
|
300
|
+
return others;
|
|
301
|
+
const runId = held.id;
|
|
302
|
+
const marks = all.filter((m, i) => all.findIndex((o) => o.token === m.token && o.decisionId === m.decisionId) === i);
|
|
303
|
+
let mineMayHaveLanded = false;
|
|
304
|
+
for (let attempt = 0; attempt < SETTLE_ATTEMPTS; attempt++) {
|
|
305
|
+
const now = attempt === 0 ? held : await readRun(runId, scope);
|
|
306
|
+
if (now === "unreadable" || now === null || now.status === "running")
|
|
307
|
+
return others;
|
|
308
|
+
const next = structuredClone(now);
|
|
309
|
+
let added = false;
|
|
310
|
+
for (const m of marks) {
|
|
311
|
+
const entry = next.parks?.find((p) => isObject(p) && p.token === m.token && p.parkedBy === runId);
|
|
312
|
+
if (entry === undefined)
|
|
313
|
+
continue;
|
|
314
|
+
const kept = Array.isArray(entry.settledDecisions) ? entry.settledDecisions.filter((s) => isObject(s)) : [];
|
|
315
|
+
if (settledMarkOf(m.token, m.decisionId, [{ id: runId, parks: [{ ...entry, settledDecisions: kept }] }]) !== undefined) {
|
|
316
|
+
if (!mineMayHaveLanded)
|
|
317
|
+
others.add(m.decisionId);
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
if (kept.length >= WORKFLOW_PARK_SETTLED_DECISIONS_MAX)
|
|
321
|
+
continue;
|
|
322
|
+
entry.settledDecisions = [...kept, { decisionId: m.decisionId, reason: m.reason, ...(m.code !== undefined ? { code: m.code } : {}) }];
|
|
323
|
+
added = true;
|
|
324
|
+
}
|
|
325
|
+
if (!added)
|
|
326
|
+
return others;
|
|
327
|
+
const won = await within(Promise.resolve().then(() => store.update(runId, scope, next, { rev: now.rev ?? 0 }, { cause: "park_decision_settled" })));
|
|
328
|
+
if (won.ok && won.value)
|
|
329
|
+
return others;
|
|
330
|
+
if (!won.ok)
|
|
331
|
+
mineMayHaveLanded = true;
|
|
332
|
+
}
|
|
333
|
+
return others;
|
|
334
|
+
};
|
|
239
335
|
const cardOf = async (parkStore, token) => {
|
|
240
336
|
if (parkStore === undefined)
|
|
241
337
|
return { kind: "unread" };
|
|
@@ -244,7 +340,7 @@ export function createWorkflowParkAdopter(seats) {
|
|
|
244
340
|
return { kind: "unread" };
|
|
245
341
|
return read.value === null || read.value.status !== "pending" ? { kind: "gone" } : { kind: "pending", row: read.value };
|
|
246
342
|
};
|
|
247
|
-
const judgeCards = async (x, records, parkStore, entries, unused) => {
|
|
343
|
+
const judgeCards = async (x, records, parkStore, entries, unused, settle, quiet) => {
|
|
248
344
|
const carried = [];
|
|
249
345
|
let first;
|
|
250
346
|
let unresumable;
|
|
@@ -269,20 +365,26 @@ export function createWorkflowParkAdopter(seats) {
|
|
|
269
365
|
if (row.kind !== "ok") {
|
|
270
366
|
unresumable ??= unused("card_unresumable", { code: row.code, ...(row.reason !== undefined ? { rowReason: row.reason } : {}), rowSentence: row.sentence, ...(row.terminal === true ? { terminal: true } : {}) });
|
|
271
367
|
first ??= unresumable;
|
|
368
|
+
if (row.terminal === true)
|
|
369
|
+
settle(entry, "card_unresumable", row.code);
|
|
272
370
|
continue;
|
|
273
371
|
}
|
|
274
|
-
const
|
|
275
|
-
if (
|
|
276
|
-
|
|
372
|
+
const was = workflowParkDecisionOf(entry.token, entry.decisionId, records);
|
|
373
|
+
if (was.kind === "spent") {
|
|
374
|
+
if (was.reason !== "decision_spent" || quiet.has(entry.decisionId))
|
|
375
|
+
quiet.add(entry.decisionId);
|
|
376
|
+
else {
|
|
377
|
+
first ??= unused("decision_spent", was.code !== undefined ? { code: was.code } : {});
|
|
378
|
+
settle(entry, "decision_spent", was.code);
|
|
379
|
+
}
|
|
277
380
|
continue;
|
|
278
381
|
}
|
|
279
382
|
carried.push({ entry, state: card.row.state });
|
|
280
383
|
}
|
|
281
384
|
return { carried, ...(first !== undefined ? { first } : {}), ...(unresumable !== undefined ? { unresumable } : {}) };
|
|
282
385
|
};
|
|
283
|
-
const adoptOne = async (runId, entries, leg, approvedCall) => {
|
|
284
|
-
const
|
|
285
|
-
const unused = (reason, more = {}) => ({ kind: "unused", runId, decisionIds, reason, ...more });
|
|
386
|
+
const adoptOne = async (runId, entries, leg, quiet, approvedCall) => {
|
|
387
|
+
const unused = (reason, more = {}) => ({ kind: "unused", runId, decisionIds: entries.map((e) => e.decisionId), reason, ...more });
|
|
286
388
|
const toolCallId = leg.mintCallId();
|
|
287
389
|
const ctx = leg.ctxOf(toolCallId);
|
|
288
390
|
const scope = seats.scopeOf(ctx);
|
|
@@ -302,24 +404,62 @@ export function createWorkflowParkAdopter(seats) {
|
|
|
302
404
|
};
|
|
303
405
|
if (x === "unreadable" || x === null || x.resumeAdmissionIncomplete === true)
|
|
304
406
|
return cardsFirst("record_unreadable");
|
|
407
|
+
if (approvedCall === undefined)
|
|
408
|
+
for (const e of entries)
|
|
409
|
+
if (settledMarkOf(e.token, e.decisionId, [x]) !== undefined)
|
|
410
|
+
quiet.add(e.decisionId);
|
|
411
|
+
if (entries.every((e) => quiet.has(e.decisionId)))
|
|
412
|
+
return "settled_before";
|
|
305
413
|
if (x.status === "running")
|
|
306
414
|
return cardsFirst("run_not_ended");
|
|
307
415
|
const successors = await successorsOf(x, scope);
|
|
308
416
|
if (typeof successors === "string")
|
|
309
417
|
return cardsFirst("record_unreadable");
|
|
310
|
-
const
|
|
418
|
+
const records = [x, ...successors];
|
|
419
|
+
const settling = [];
|
|
420
|
+
const settle = (entry, reason, code) => {
|
|
421
|
+
if (approvedCall === undefined && !quiet.has(entry.decisionId))
|
|
422
|
+
settling.push({ token: entry.token, decisionId: entry.decisionId, reason, ...(code !== undefined ? { code } : {}) });
|
|
423
|
+
};
|
|
424
|
+
const told = async (o) => {
|
|
425
|
+
if (o.kind !== "unused" || !settlesDecision(o))
|
|
426
|
+
return o;
|
|
427
|
+
const marks = settling.filter((m) => m.reason === o.reason && m.code === o.code && o.decisionIds.includes(m.decisionId));
|
|
428
|
+
if (marks.length > 0)
|
|
429
|
+
for (const id of await settleOn(x, scope, marks))
|
|
430
|
+
quiet.add(id);
|
|
431
|
+
return o;
|
|
432
|
+
};
|
|
433
|
+
const judged = await judgeCards(x, records, parkStore, entries, unused, settle, quiet);
|
|
311
434
|
if (judged.unresumable !== undefined)
|
|
312
|
-
return judged.unresumable;
|
|
313
|
-
|
|
435
|
+
return told(judged.unresumable);
|
|
436
|
+
if (judged.carried.length === 0)
|
|
437
|
+
return told(judged.first ?? unused("record_unreadable"));
|
|
438
|
+
const walked = seats.store === undefined ? "unreadable" : await workflowLineOf(seats.store, x.id, scope, within);
|
|
439
|
+
const unrecordedOn = (w, of) => typeof w === "string"
|
|
440
|
+
? of
|
|
441
|
+
: of.filter((c) => {
|
|
442
|
+
const recorded = settledMarkOf(c.entry.token, c.entry.decisionId, w.records) !== undefined;
|
|
443
|
+
if (recorded)
|
|
444
|
+
quiet.add(c.entry.decisionId);
|
|
445
|
+
return !recorded;
|
|
446
|
+
});
|
|
447
|
+
let carried = unrecordedOn(walked, judged.carried);
|
|
314
448
|
if (carried.length === 0)
|
|
315
|
-
return judged.first
|
|
316
|
-
const
|
|
317
|
-
const unusedCarried = (reason, more = {}) => ({ kind: "unused", runId, decisionIds:
|
|
318
|
-
const
|
|
319
|
-
const
|
|
449
|
+
return judged.first !== undefined ? told(judged.first) : "settled_before";
|
|
450
|
+
const carriedIdsOf = () => carried.map((c) => c.entry.decisionId);
|
|
451
|
+
const unusedCarried = (reason, more = {}) => ({ kind: "unused", runId, decisionIds: carriedIdsOf(), reason, ...more });
|
|
452
|
+
const settledCarried = (reason, more = {}) => {
|
|
453
|
+
for (const { entry } of carried)
|
|
454
|
+
settle(entry, reason, more.code);
|
|
455
|
+
return told(unusedCarried(reason, more));
|
|
456
|
+
};
|
|
457
|
+
const lineOf = async (walked) => {
|
|
458
|
+
const line = seats.store === undefined ? { kind: "unreadable" } : await otherWaitingLine(seats.store, parkStore, x.id, scope, within, walked);
|
|
320
459
|
return line.kind === "unreadable" || line.kind === "over_bound" ? unusedCarried("record_unreadable") : line.kind === "waiting" ? unusedCarried("waiting_elsewhere", { waiting: line.lines }) : line.root;
|
|
321
460
|
};
|
|
322
|
-
const
|
|
461
|
+
const treeOf = (w) => (typeof w === "string" ? w : { root: w.root, line: w.line, recorded: w.recorded });
|
|
462
|
+
const claimKey = await lineOf(treeOf(walked));
|
|
323
463
|
if (typeof claimKey !== "string")
|
|
324
464
|
return claimKey;
|
|
325
465
|
if (x.errorCode !== WORKFLOW_AGENT_PARKED_ERROR_CODE)
|
|
@@ -333,7 +473,7 @@ export function createWorkflowParkAdopter(seats) {
|
|
|
333
473
|
return unusedCarried("record_unreadable");
|
|
334
474
|
}
|
|
335
475
|
if (launchRead.kind === "defect")
|
|
336
|
-
return
|
|
476
|
+
return settledCarried("launch_unreadable", { code: launchRead.member });
|
|
337
477
|
if (launchRead.kind === "record")
|
|
338
478
|
launch = launchRead.record;
|
|
339
479
|
}
|
|
@@ -360,7 +500,7 @@ export function createWorkflowParkAdopter(seats) {
|
|
|
360
500
|
return "carried";
|
|
361
501
|
}
|
|
362
502
|
if (launch === undefined)
|
|
363
|
-
return seats.instructOnce(
|
|
503
|
+
return seats.instructOnce(carriedIdsOf()) ? unusedCarried("launch_unrecorded") : unusedCarried("launch_unrecorded", { askedBefore: true });
|
|
364
504
|
const name = launch.callArgs.name;
|
|
365
505
|
const input = { script: launch.script, ...(launch.effectiveArgs !== undefined ? { args: launch.effectiveArgs } : {}), ...(typeof name === "string" ? { name } : {}), resumeFromRunId: runId };
|
|
366
506
|
const byPerson = carried.every((c) => isObject(c.entry.outcome) && isObject(c.entry.outcome.hostDecision) && c.entry.outcome.hostDecision.decidedBy === "person");
|
|
@@ -373,21 +513,27 @@ export function createWorkflowParkAdopter(seats) {
|
|
|
373
513
|
judged = { kind: "ask_unanswerable" };
|
|
374
514
|
}
|
|
375
515
|
if (judged.kind === "denied")
|
|
376
|
-
return
|
|
516
|
+
return settledCarried("denied", { code: judged.layer, ...(judged.explicit ? { explicit: true } : {}) });
|
|
377
517
|
if (judged.kind === "ask_unanswerable")
|
|
378
|
-
return seats.instructOnce(
|
|
518
|
+
return seats.instructOnce(carriedIdsOf()) ? unusedCarried("ask_unanswerable") : unusedCarried("ask_unanswerable", { askedBefore: true });
|
|
379
519
|
}
|
|
380
520
|
let superseded;
|
|
381
521
|
const confirm = async () => {
|
|
522
|
+
const lineNow = seats.store === undefined ? "unreadable" : await workflowLineOf(seats.store, x.id, scope, within);
|
|
523
|
+
carried = unrecordedOn(lineNow, carried);
|
|
524
|
+
if (carried.length === 0) {
|
|
525
|
+
superseded = "settled_before";
|
|
526
|
+
return false;
|
|
527
|
+
}
|
|
382
528
|
const now = await successorsOf(x, scope);
|
|
383
|
-
const again = typeof now === "string" ? undefined : await judgeCards(x, [x, ...now], parkStore, carried.map((c) => c.entry), unusedCarried);
|
|
529
|
+
const again = typeof now === "string" ? undefined : await judgeCards(x, [x, ...now], parkStore, carried.map((c) => c.entry), unusedCarried, settle, quiet);
|
|
384
530
|
superseded = again === undefined ? unusedCarried("record_unreadable") : (again.unresumable ?? (again.carried.length < carried.length ? (again.first ?? unusedCarried("record_unreadable")) : undefined));
|
|
385
531
|
if (superseded !== undefined)
|
|
386
532
|
return false;
|
|
387
|
-
const line = await lineOf();
|
|
533
|
+
const line = await lineOf(treeOf(lineNow));
|
|
388
534
|
if (typeof line !== "string")
|
|
389
535
|
superseded = line;
|
|
390
|
-
return superseded === undefined;
|
|
536
|
+
return superseded === undefined ? carried.map(({ entry }) => decisionOf(entry)) : false;
|
|
391
537
|
};
|
|
392
538
|
let started;
|
|
393
539
|
try {
|
|
@@ -402,9 +548,9 @@ export function createWorkflowParkAdopter(seats) {
|
|
|
402
548
|
if ("claimHeld" in started)
|
|
403
549
|
return unusedCarried("continuing_elsewhere", started.claimHeld);
|
|
404
550
|
if ("superseded" in started)
|
|
405
|
-
return superseded ?? unusedCarried("record_unreadable");
|
|
551
|
+
return superseded === "settled_before" ? superseded : told(superseded ?? unusedCarried("record_unreadable"));
|
|
406
552
|
const stepDenied = carried.some((c) => isObject(c.entry.outcome) && c.entry.outcome.decision === "deny");
|
|
407
|
-
return { kind: "started", runId, decisionIds:
|
|
553
|
+
return { kind: "started", runId, decisionIds: carriedIdsOf(), continuedAs: started.runId, ...(stepDenied ? { stepDenied: true } : {}) };
|
|
408
554
|
};
|
|
409
555
|
return async (leg) => {
|
|
410
556
|
const { usable, unreadable } = readDecisions(seats.decisions);
|
|
@@ -423,8 +569,8 @@ export function createWorkflowParkAdopter(seats) {
|
|
|
423
569
|
if (resumed !== undefined) {
|
|
424
570
|
if (resumed.approved) {
|
|
425
571
|
try {
|
|
426
|
-
const adopted = await adoptOne(runId, entries, leg, resumed.toolCallId);
|
|
427
|
-
const refusal = adopted === "carried" ? undefined : resumedCallRefusalOf(adopted);
|
|
572
|
+
const adopted = await adoptOne(runId, entries, leg, new Set(), resumed.toolCallId);
|
|
573
|
+
const refusal = adopted === "carried" || adopted === "settled_before" ? undefined : resumedCallRefusalOf(adopted);
|
|
428
574
|
if (refusal !== undefined)
|
|
429
575
|
seats.holdForCall(runId, resumed.toolCallId, { refusal });
|
|
430
576
|
}
|
|
@@ -434,9 +580,15 @@ export function createWorkflowParkAdopter(seats) {
|
|
|
434
580
|
continue;
|
|
435
581
|
}
|
|
436
582
|
try {
|
|
437
|
-
const
|
|
438
|
-
|
|
583
|
+
const quiet = new Set();
|
|
584
|
+
const adopted = await adoptOne(runId, entries, leg, quiet);
|
|
585
|
+
if (adopted === "carried" || adopted === "settled_before")
|
|
586
|
+
continue;
|
|
587
|
+
const kept = adopted.kind === "unused" ? adopted.decisionIds.filter((id) => !quiet.has(id)) : [];
|
|
588
|
+
if (adopted.kind !== "unused" || kept.length === adopted.decisionIds.length)
|
|
439
589
|
out.push(adopted);
|
|
590
|
+
else if (kept.length > 0)
|
|
591
|
+
out.push({ ...adopted, decisionIds: kept });
|
|
440
592
|
}
|
|
441
593
|
catch {
|
|
442
594
|
out.push({ kind: "unused", runId, decisionIds: entries.map((e) => e.decisionId), reason: "record_unreadable" });
|
|
@@ -527,16 +679,14 @@ export function workflowParkUnusedSentence(o) {
|
|
|
527
679
|
return `the record of what the workflow was started with does not read back in the shape it was written in${o.code !== undefined ? ` (${neutral(o.code)})` : ""}, so the run cannot be continued here. Start the workflow again, and report the defect to the deployment`;
|
|
528
680
|
case "host_changed":
|
|
529
681
|
return o.changed === "parent_chain"
|
|
530
|
-
? `the permission rules the workflow's agents were stopped under have changed since. ${waiting}
|
|
682
|
+
? `the permission rules the workflow's agents were stopped under have changed since. ${waiting} and the decision is kept: once those rules are back to what they were, the same decision continues the run when it is handed over again — or start the workflow again`
|
|
531
683
|
: o.inputs !== undefined
|
|
532
|
-
? `what the workflow's agents run under has changed since the workflow stopped: ${o.inputs.map((k) => HOST_FOLD_INPUT_WORDS[k]).join("; ")}. ${waiting}
|
|
533
|
-
: `what the workflow's agents run under (the deployment's settings for workflow agents, this session's permission limits, the workflow's model, or the account it runs for) has changed since the workflow stopped. ${waiting}
|
|
684
|
+
? `what the workflow's agents run under has changed since the workflow stopped: ${o.inputs.map((k) => HOST_FOLD_INPUT_WORDS[k]).join("; ")}. ${waiting} and the decision is kept: once ${o.inputs.length === 1 ? "it is back to what it was" : "they are back to what they were"}, the same decision continues the run when it is handed over again — or start the workflow again`
|
|
685
|
+
: `what the workflow's agents run under (the deployment's settings for workflow agents, this session's permission limits, the workflow's model, or the account it runs for) has changed since the workflow stopped. ${waiting} and the decision is kept: once it is back to what it was, the same decision continues the run when it is handed over again — or start the workflow again`;
|
|
534
686
|
case "denied":
|
|
535
|
-
return
|
|
536
|
-
?
|
|
537
|
-
: o.code === "mode"
|
|
538
|
-
? "switch the session out of that permission mode and decide again"
|
|
539
|
-
: "the refusal comes from settings this session cannot change (the deployment's or the organization's) — decide again once they allow the Workflow tool, or start the workflow again where they do"}`;
|
|
687
|
+
return o.explicit === true
|
|
688
|
+
? `a person answered no when asked to continue the workflow. ${waiting}; decide the card again (a new decision) to continue the run, or start the workflow again`
|
|
689
|
+
: `this session's permission settings now refuse to run the workflow${o.code !== undefined ? ` (${neutral(o.code)})` : ""}. ${waiting} and the decision is kept: once ${o.code === "persisted_rule" ? "that deny rule for the Workflow tool is removed" : o.code === "mode" ? "the session is out of that permission mode" : "the Workflow tool is allowed again"}, the same decision continues the run when it is handed over again — or start the workflow again`;
|
|
540
690
|
case "ask_unanswerable":
|
|
541
691
|
return o.askedBefore === true
|
|
542
692
|
? `continuing the workflow needs a person's approval that nobody can give in this session right now, and the session's model was already asked once to request it as a new card without the run going on, so it is not asked again. ${waiting} and the decision is kept; decide the card again where a person can approve`
|
|
@@ -545,7 +695,7 @@ export function workflowParkUnusedSentence(o) {
|
|
|
545
695
|
return `the workflow could not be started${o.why !== undefined ? `: ${neutral(o.why, WHY_ECHO_MAX)}` : ""}. ${waiting}, and the decision can still be used when it is handed over again; if the cause does not clear, start the workflow again`;
|
|
546
696
|
}
|
|
547
697
|
}
|
|
548
|
-
const
|
|
698
|
+
const settledForGood = (o) => o.reason === "not_pending" || settlesDecision(o);
|
|
549
699
|
export function notContinuedRefusalOf(runId, reason, more = {}) {
|
|
550
700
|
const { decisionIds = [], ...rest } = more;
|
|
551
701
|
return `workflow run "${neutral(runId)}" is not continued: ${workflowParkUnusedSentence({ kind: "unused", runId, decisionIds, reason, ...rest })}.`;
|
|
@@ -582,7 +732,7 @@ export function workflowParksContributor(input) {
|
|
|
582
732
|
input.deliver({
|
|
583
733
|
code: "workflow.parked_decision_unused",
|
|
584
734
|
message: `the approval decision for workflow run "${neutral(o.runId)}" was not used to continue it: ${workflowParkUnusedSentence(o)}.`,
|
|
585
|
-
detail: { runId: o.runId, decisionIds: [...o.decisionIds], reason: o.reason, ...holderDetailOf(o), ...(o.code !== undefined ? { code: o.code } : {}), ...(o.changed !== undefined ? { changed: o.changed } : {}), ...(o.why !== undefined ? { why: o.why } : {}), ...(o.askedBefore === true ? { askedBefore: true } : {}), ...(o.rowReason !== undefined ? { rowReason: o.rowReason } : {}), ...(o.terminal === true ? { terminal: true } : {}), ...(o.continuedAs !== undefined ? { continuedAs: o.continuedAs } : {}) },
|
|
735
|
+
detail: { runId: o.runId, decisionIds: [...o.decisionIds], reason: o.reason, ...holderDetailOf(o), ...(o.code !== undefined ? { code: o.code } : {}), ...(o.changed !== undefined ? { changed: o.changed } : {}), ...(o.inputs !== undefined ? { inputs: [...o.inputs] } : {}), ...(o.why !== undefined ? { why: o.why } : {}), ...(o.askedBefore === true ? { askedBefore: true } : {}), ...(o.rowReason !== undefined ? { rowReason: o.rowReason } : {}), ...(o.terminal === true ? { terminal: true } : {}), ...(o.continuedAs !== undefined ? { continuedAs: o.continuedAs } : {}) },
|
|
586
736
|
});
|
|
587
737
|
}
|
|
588
738
|
catch {
|
|
@@ -608,7 +758,7 @@ export function workflowContinuationFrameBody(all, toolName, say) {
|
|
|
608
758
|
? say("core/event.workflow-continuation.ask", { run: id(o.runId), sentence: workflowParkUnusedSentence(o), tool })
|
|
609
759
|
: o.reason === "launch_unrecorded"
|
|
610
760
|
? say("core/event.workflow-continuation.model-continues", { run: id(o.runId), sentence: workflowParkUnusedSentence(o), tool })
|
|
611
|
-
: say(
|
|
761
|
+
: say(settledForGood(o) ? "core/event.workflow-continuation.settled" : "core/event.workflow-continuation.not-applied", { run: id(o.runId), sentence: workflowParkUnusedSentence(o) }));
|
|
612
762
|
if (outcomes.length > shown.length)
|
|
613
763
|
lines.push(say("core/event.workflow-continuation.more", { count: String(outcomes.length - shown.length) }));
|
|
614
764
|
return lines.join("\n");
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { TaskResult, TaskStatus, ToolActivity } from "../core/types.js";
|
|
2
|
+
/** How many settled decisions one park entry keeps ({@link WorkflowRun.parks}`[].settledDecisions`); past it a further decision is
|
|
3
|
+
* not recorded (it is judged and told again each time it is handed over again), and none recorded is ever dropped. */
|
|
4
|
+
export declare const WORKFLOW_PARK_SETTLED_DECISIONS_MAX = 16;
|
|
2
5
|
/** A workflow run's lifecycle words (closed; the stored run's `status` is read against it). */
|
|
3
6
|
export declare const WORKFLOW_RUN_STATUSES: readonly ["running", "completed", "failed"];
|
|
4
7
|
export type WorkflowRunStatus = (typeof WORKFLOW_RUN_STATUSES)[number];
|
|
@@ -505,6 +508,18 @@ export interface WorkflowRun {
|
|
|
505
508
|
* it: every decision for the park continues this run again. Writing it rewrites a FINISHED record, so a store applies an
|
|
506
509
|
* update of a finished row like any other, and answers from `get` every member it keeps. Absent on an entry no
|
|
507
510
|
* continuation has stood on from this record, and on every entry written before the member existed.
|
|
511
|
+
*
|
|
512
|
+
* `settledDecisions` lists the host's decisions for this park that the engine's continuation judged it will never use to
|
|
513
|
+
* continue the run, and told the person so once: each one's `decisionId`, the `reason` it was told with (a word of
|
|
514
|
+
* `WORKFLOW_PARK_SETTLING_REASONS`; a reader counts no other word) and that reason's `code`. Written on the entry of the run
|
|
515
|
+
* that held the park when it was judged — a finished run — by a compare-and-set of that record on its `rev` (`update` with
|
|
516
|
+
* `cause: "park_decision_settled"`), at most {@link WORKFLOW_PARK_SETTLED_DECISIONS_MAX} per entry (past it a decision is not
|
|
517
|
+
* recorded). It rides with the park: a run that comes to hold the park (it re-parks the same card, or the park passes to it)
|
|
518
|
+
* carries its holder's list onto its own entry as it reads it then — a mark another leg writes on the earlier holder after that is on
|
|
519
|
+
* that record alone, so a reader reads the park's chain. A mark lives as long as its record: when the latest holder's record is gone
|
|
520
|
+
* and an earlier holder's is not, that one holds the park again without what was recorded after it.
|
|
521
|
+
* `workflowParkDecisionOf` reads it; a decision it names, handed over again, is told nothing and never carried. A store that does
|
|
522
|
+
* not keep it costs only that: every hand-over is judged and told again, as before the member.
|
|
508
523
|
*/
|
|
509
524
|
parks?: Array<{
|
|
510
525
|
callKey: string;
|
|
@@ -515,6 +530,11 @@ export interface WorkflowRun {
|
|
|
515
530
|
parkedBy?: string;
|
|
516
531
|
generation?: number;
|
|
517
532
|
passedTo?: string;
|
|
533
|
+
settledDecisions?: Array<{
|
|
534
|
+
decisionId: string;
|
|
535
|
+
reason: string;
|
|
536
|
+
code?: string;
|
|
537
|
+
}>;
|
|
518
538
|
}>;
|
|
519
539
|
/**
|
|
520
540
|
* Set (`true`) on a resume run's record from its creation and REMOVED the moment its admission completes — so a record
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export const WORKFLOW_PARK_SETTLED_DECISIONS_MAX = 16;
|
|
1
2
|
export const WORKFLOW_RUN_STATUSES = Object.freeze(["running", "completed", "failed"]);
|
|
2
3
|
export const WORKFLOW_ITEM_STATUSES = Object.freeze(["running", "completed", "failed", "parked"]);
|
|
3
4
|
export const PARK_TRUTH_UNREADABLE_REASONS = Object.freeze(["store_threw", "record_missing", "record_not_terminal", "parks_unreadable", "admission_incomplete", "checkpoint_store_threw", "capability_not_armed"]);
|
|
@@ -347,8 +347,9 @@ export interface RunWorkflowOptions {
|
|
|
347
347
|
* throw is swallowed and NEVER breaks the workflow (the run/script is the source of truth; the store is an
|
|
348
348
|
* observation layer). The owner writes its record while it runs (rev CAS); after it has finished, a later
|
|
349
349
|
* continuation of its chain writes it once more for each park that continuation comes to stand on without
|
|
350
|
-
* reaching it (the entry's `passedTo`, rev CAS)
|
|
351
|
-
* `
|
|
350
|
+
* reaching it (the entry's `passedTo`, rev CAS), and the engine's continuation of it writes it to record a decision it will never
|
|
351
|
+
* use (a park entry's `settledDecisions`, rev CAS) — so the owner is not the record's only writer. The owner's own writes carry no
|
|
352
|
+
* `update` cause; those writes carry `cause: "park_pass"` / `"park_decision_settled"` (see {@link WorkflowRunStore.update}). */
|
|
352
353
|
store?: WorkflowRunStore;
|
|
353
354
|
/** Where the run's full record (its result and every agent's row) is written at its terminal, for `ReadToolResult` to
|
|
354
355
|
* read back: the engine writes it before `run_end` and records the outcome on {@link WorkflowRun.recordArtifact}
|