@xzzpig/pi-subagents 0.24.1 → 0.25.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 +28 -0
- package/bundle/agent-management.js +4 -4
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/chunk-34TUUBRN.js +1107 -0
- package/bundle/{chunk-SW2VMNIU.js → chunk-5OD3OWTE.js} +2 -2
- package/bundle/{chunk-ZWXU5SPQ.js → chunk-5YEOWNSD.js} +371 -135
- package/bundle/{chunk-EUPJB4S7.js → chunk-5Z7JAORM.js} +196 -1219
- package/bundle/{chunk-LCDJWBVM.js → chunk-66JNFRFS.js} +1 -1
- package/bundle/{chunk-6BJUEES3.js → chunk-6MNRKUHY.js} +23 -12
- package/bundle/{chunk-ED55MIC2.js → chunk-CGFF4WA3.js} +42 -19
- package/bundle/{chunk-TMHVDPYW.js → chunk-DLVPMML3.js} +263 -154
- package/bundle/chunk-HXRB42AF.js +108 -0
- package/bundle/{chunk-355ECEP2.js → chunk-IH7LQVEE.js} +29 -14
- package/bundle/{chunk-SLNMBXLL.js → chunk-IJWITCC6.js} +411 -249
- package/bundle/{chunk-RU522D5W.js → chunk-IKFKH5EL.js} +369 -50
- package/bundle/{chunk-Z6TFJ6BR.js → chunk-INWSUNI6.js} +1 -1
- package/bundle/{chunk-JEA2ZKUA.js → chunk-IUDEI6FJ.js} +35 -200
- package/bundle/{chunk-WW76JRIX.js → chunk-JAXVBXGF.js} +1 -1
- package/bundle/{chunk-ICNYIALB.js → chunk-JH5H4CYJ.js} +784 -474
- package/bundle/{chunk-35GII5EF.js → chunk-JWFLPSTP.js} +41 -117
- package/bundle/{chunk-LMGQAJ3O.js → chunk-KCJFGKVK.js} +350 -123
- package/bundle/{chunk-RB4GELQA.js → chunk-LPJEKHOY.js} +1 -1
- package/bundle/chunk-LYKG4FKH.js +523 -0
- package/bundle/{chunk-X6LOM3Z4.js → chunk-LZ3HBDTR.js} +161 -78
- package/bundle/{chunk-FG6SQJAR.js → chunk-OGPOCGWX.js} +24 -6
- package/bundle/{chunk-Y6H2G6KX.js → chunk-OSVXFWPG.js} +67 -30
- package/bundle/{chunk-FJWI64H7.js → chunk-RMSABUN3.js} +27 -13
- package/bundle/{chunk-H36HBZB2.js → chunk-SJPABBZG.js} +2 -2
- package/bundle/{chunk-3U633XDZ.js → chunk-U3ZDUUTM.js} +11 -3
- package/bundle/{chunk-LVWU2HOO.js → chunk-ULGMXABL.js} +16 -7
- package/bundle/{chunk-WPW4V6HM.js → chunk-W7ZA6TYD.js} +2 -2
- package/bundle/{chunk-V2KFIGFH.js → chunk-XAC2XNAP.js} +503 -304
- package/bundle/{chunk-TGLFTQWJ.js → chunk-YWXILP5N.js} +5 -4
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +12 -10
- package/bundle/project-panes.js +3 -3
- package/bundle/workflow-resources.js +1 -1
- package/docs/agents.md +27 -6
- package/docs/configuration.md +20 -8
- package/docs/extension-api.md +18 -1
- package/docs/models.md +6 -2
- package/docs/observability.md +2 -0
- package/docs/tool-reference.md +7 -1
- package/docs/workflows.md +30 -2
- package/node_modules/@xzzpig/pi-components/CHANGELOG.md +12 -0
- package/node_modules/@xzzpig/pi-components/README.md +94 -0
- package/node_modules/@xzzpig/pi-components/dist/src/transcript-presenter.d.ts +186 -0
- package/node_modules/@xzzpig/pi-components/dist/src/transcript-presenter.js +693 -0
- package/node_modules/@xzzpig/pi-components/package.json +5 -1
- package/package.json +4 -4
- package/skills/pi-subagents/SKILL.md +15 -6
- package/skills/pi-subagents/references/prompting-and-roles.md +1 -0
- package/src/agents/agent-management.d.ts +1 -0
- package/src/agents/agent-management.js +46 -18
- package/src/agents/agent-memory.d.ts +1 -4
- package/src/agents/agent-memory.js +1 -4
- package/src/agents/agent-serializer.d.ts +2 -0
- package/src/agents/agent-serializer.js +1 -1
- package/src/agents/agents.d.ts +2 -3
- package/src/agents/agents.js +46 -20
- package/src/agents/frontmatter.js +1 -8
- package/src/agents/global-npm-root.d.ts +1 -0
- package/src/agents/global-npm-root.js +11 -3
- package/src/agents/skills.d.ts +0 -3
- package/src/agents/skills.js +0 -3
- package/src/api/preflight.d.ts +3 -1
- package/src/api/preflight.js +2 -0
- package/src/extension/config.d.ts +1 -0
- package/src/extension/config.js +13 -1
- package/src/extension/herdr-pi-bridge.js +10 -2
- package/src/extension/index.d.ts +0 -13
- package/src/extension/index.js +51 -37
- package/src/extension/public-execution.d.ts +1 -0
- package/src/extension/public-execution.js +4 -0
- package/src/extension/reply-workflow-script.js +24 -4
- package/src/extension/schemas.d.ts +12 -3
- package/src/extension/schemas.js +7 -3
- package/src/extension/session-switch.d.ts +25 -0
- package/src/extension/session-switch.js +138 -0
- package/src/extension/subagent-guide.d.ts +1 -1
- package/src/extension/subagent-guide.js +1 -1
- package/src/extension/subagent-launch-tool.d.ts +25 -0
- package/src/extension/subagent-launch-tool.js +48 -0
- package/src/extension/tool-activation.js +55 -15
- package/src/extension/tool-description.d.ts +1 -1
- package/src/extension/tool-description.js +14 -8
- package/src/inspectors/herdr/actions.d.ts +0 -1
- package/src/inspectors/herdr/actions.js +0 -1
- package/src/inspectors/session-roots-codec.d.ts +0 -1
- package/src/inspectors/session-roots-codec.js +0 -1
- package/src/inspectors/tmux/actions.d.ts +0 -1
- package/src/inspectors/tmux/actions.js +0 -1
- package/src/integrations/herdr-status.js +3 -8
- package/src/intercom/native-supervisor-channel.js +65 -9
- package/src/runs/background/async-execution.d.ts +7 -10
- package/src/runs/background/async-execution.js +66 -29
- package/src/runs/background/async-job-tracker.js +12 -0
- package/src/runs/background/async-resume.d.ts +2 -1
- package/src/runs/background/async-resume.js +114 -40
- package/src/runs/background/async-retention.d.ts +0 -2
- package/src/runs/background/async-retention.js +17 -6
- package/src/runs/background/async-status.d.ts +2 -0
- package/src/runs/background/async-status.js +4 -0
- package/src/runs/background/auto-drain.js +2 -1
- package/src/runs/background/boot-id.d.ts +1 -3
- package/src/runs/background/boot-id.js +1 -3
- package/src/runs/background/completion-batcher.d.ts +3 -4
- package/src/runs/background/completion-batcher.js +2 -3
- package/src/runs/background/control-channel.d.ts +0 -6
- package/src/runs/background/control-channel.js +0 -6
- package/src/runs/background/fleet-view.js +2 -3
- package/src/runs/background/notify.d.ts +0 -2
- package/src/runs/background/notify.js +0 -2
- package/src/runs/background/result-watcher.d.ts +1 -0
- package/src/runs/background/result-watcher.js +59 -29
- package/src/runs/background/resume-guidance.js +4 -2
- package/src/runs/background/retained-children.js +2 -1
- package/src/runs/background/run-child-session.d.ts +2 -3
- package/src/runs/background/run-child-session.js +5 -8
- package/src/runs/background/run-status.js +9 -7
- package/src/runs/background/runner-aliases.js +15 -0
- package/src/runs/background/scheduled-runs.d.ts +3 -1
- package/src/runs/background/scheduled-runs.js +13 -16
- package/src/runs/background/steering.d.ts +2 -11
- package/src/runs/background/steering.js +11 -6
- package/src/runs/background/subagent-runner.d.ts +2 -6
- package/src/runs/background/subagent-runner.js +88 -70
- package/src/runs/background/subagent-wait.js +12 -15
- package/src/runs/background/wait-config.d.ts +2 -0
- package/src/runs/background/wait-config.js +17 -3
- package/src/runs/background/wait-subscriptions.js +124 -12
- package/src/runs/background/wait-tool.js +4 -2
- package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
- package/src/runs/background/workflow-terminal-proof.js +0 -1
- package/src/runs/foreground/async-steering-action.js +24 -9
- package/src/runs/foreground/async-stop-action.d.ts +1 -1
- package/src/runs/foreground/async-stop-action.js +9 -1
- package/src/runs/foreground/execution.d.ts +0 -3
- package/src/runs/foreground/execution.js +56 -24
- package/src/runs/foreground/prompt-audit.js +1 -0
- package/src/runs/foreground/subagent-executor.d.ts +5 -10
- package/src/runs/foreground/subagent-executor.js +164 -49
- package/src/runs/shared/acceptance.js +69 -26
- package/src/runs/shared/async-status-projection.d.ts +2 -0
- package/src/runs/shared/async-status-projection.js +10 -0
- package/src/runs/shared/child-commands.js +15 -2
- package/src/runs/shared/child-hooks.d.ts +1 -7
- package/src/runs/shared/child-hooks.js +13 -5
- package/src/runs/shared/child-launch.js +6 -2
- package/src/runs/shared/child-runtime-config.d.ts +0 -1
- package/src/runs/shared/child-session.d.ts +6 -5
- package/src/runs/shared/child-session.js +85 -38
- package/src/runs/shared/child-tool-plan.d.ts +0 -1
- package/src/runs/shared/child-tool-plan.js +0 -1
- package/src/runs/shared/claude-code-adapter.js +11 -0
- package/src/runs/shared/external-cli-contract.d.ts +49 -0
- package/src/runs/shared/external-cli-contract.js +18 -13
- package/src/runs/shared/external-cli-runner.js +26 -6
- package/src/runs/shared/herdr-connection.js +2 -1
- package/src/runs/shared/herdr-pane-host.d.ts +2 -2
- package/src/runs/shared/herdr-pane-host.js +17 -1
- package/src/runs/shared/herdr-placed-run.js +51 -24
- package/src/runs/shared/lane-metadata.d.ts +0 -1
- package/src/runs/shared/lane-metadata.js +0 -1
- package/src/runs/shared/mcp-config-sources.d.ts +4 -1
- package/src/runs/shared/mcp-config-sources.js +1 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +0 -3
- package/src/runs/shared/mcp-direct-tool-allowlist.js +26 -17
- package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
- package/src/runs/shared/model-resolution-diagnostic.d.ts +0 -1
- package/src/runs/shared/model-resolution.d.ts +20 -5
- package/src/runs/shared/model-resolution.js +55 -50
- package/src/runs/shared/model-scope.d.ts +1 -5
- package/src/runs/shared/model-scope.js +1 -5
- package/src/runs/shared/mutation-evidence.d.ts +1 -1
- package/src/runs/shared/mutation-evidence.js +52 -7
- package/src/runs/shared/nested-events.d.ts +1 -0
- package/src/runs/shared/nested-events.js +1 -1
- package/src/runs/shared/parallel-utils.d.ts +0 -1
- package/src/runs/shared/permissions.js +5 -3
- package/src/runs/shared/placement-host.d.ts +5 -1
- package/src/runs/shared/rex-pane-host.d.ts +0 -1
- package/src/runs/shared/rex-pane-host.js +0 -2
- package/src/runs/shared/run-launch-folder.d.ts +12 -0
- package/src/runs/shared/run-launch-folder.js +21 -0
- package/src/runs/shared/runner-launcher.d.ts +12 -1
- package/src/runs/shared/runner-launcher.js +16 -0
- package/src/runs/shared/single-output.d.ts +3 -3
- package/src/runs/shared/single-output.js +5 -3
- package/src/runs/shared/structured-output.d.ts +8 -0
- package/src/runs/shared/structured-output.js +40 -5
- package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
- package/src/runs/shared/subagent-prompt-runtime.js +18 -4
- package/src/runs/shared/supervisor-wait-timer.d.ts +16 -0
- package/src/runs/shared/supervisor-wait-timer.js +61 -0
- package/src/runs/shared/tool-timeout.js +2 -1
- package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
- package/src/runs/shared/worktree-cleanup-plan.js +0 -1
- package/src/runs/shared/worktree.d.ts +3 -0
- package/src/runs/shared/worktree.js +20 -0
- package/src/shared/artifacts.d.ts +1 -0
- package/src/shared/artifacts.js +132 -22
- package/src/shared/capacity-resilient-json.d.ts +1 -1
- package/src/shared/child-cache-retention.d.ts +1 -2
- package/src/shared/child-cache-retention.js +1 -2
- package/src/shared/fleet-transcript-reader.d.ts +51 -0
- package/src/shared/fleet-transcript-reader.js +333 -0
- package/src/shared/formatters.d.ts +0 -18
- package/src/shared/formatters.js +0 -18
- package/src/shared/pruned-fork.js +2 -2
- package/src/shared/reported-progress.d.ts +1 -0
- package/src/shared/reported-progress.js +12 -0
- package/src/shared/session-succession.d.ts +16 -1
- package/src/shared/session-succession.js +41 -2
- package/src/shared/session-warnings.d.ts +7 -0
- package/src/shared/session-warnings.js +26 -0
- package/src/shared/settings.d.ts +0 -23
- package/src/shared/settings.js +3 -35
- package/src/shared/status-format.d.ts +1 -0
- package/src/shared/status-format.js +1 -1
- package/src/shared/types.d.ts +108 -59
- package/src/shared/types.js +0 -12
- package/src/shared/utils.d.ts +3 -15
- package/src/shared/utils.js +4 -22
- package/src/shared/wait-tool-name.d.ts +8 -0
- package/src/shared/wait-tool-name.js +13 -0
- package/src/slash/slash-commands.js +2 -1
- package/src/slash/subagent-cost.d.ts +3 -2
- package/src/slash/subagent-cost.js +22 -3
- package/src/slash/subagents-admin.js +0 -1
- package/src/tui/fleet-status.d.ts +0 -5
- package/src/tui/fleet-status.js +4 -24
- package/src/tui/fleet.js +6 -4
- package/src/tui/render.d.ts +0 -9
- package/src/tui/render.js +194 -68
- package/src/tui/subagent-messages.js +3 -2
- package/src/watchdog/model-selection.js +2 -2
- package/src/watchdog/permission-arbiter.js +1 -0
- package/src/watchdog/register-child.d.ts +2 -3
- package/src/watchdog/register-child.js +2 -3
- package/src/watchdog/review.d.ts +0 -5
- package/src/watchdog/review.js +4 -3
- package/src/watchdog/turn-delta.js +2 -1
- package/src/workflows/scripted-workflow.d.ts +2 -0
- package/src/workflows/scripted-workflow.js +344 -59
- package/src/workflows/structured-workflow-scripts.d.ts +4 -3
- package/src/workflows/structured-workflow-scripts.js +32 -11
- package/src/workflows/workflow-launch-record.d.ts +15 -6
- package/src/workflows/workflow-launch-record.js +30 -12
- package/src/workflows/workflow-receipt.js +36 -53
- package/src/workflows/workflow-resources.js +4 -4
- package/src/workflows/workflow-resume-claim.d.ts +2 -0
- package/src/workflows/workflow-resume-claim.js +3 -3
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +13 -8
- package/src/workflows/workflow-script-worker.d.ts +13 -0
- package/src/workflows/workflow-script-worker.js +81 -0
- package/workflow-script-process.cjs +36 -0
- package/workflow-script-worker.cjs +4 -1
- package/bundle/chunk-U4ODUYAG.js +0 -235
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { accessSync, constants, readFileSync, realpathSync, statSync } from "node:fs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { dirname, resolve as resolvePath } from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { createWorkflowScriptWorker } from "./workflow-script-worker.js";
|
|
5
5
|
import { DEFAULT_GLOBAL_CONCURRENCY_LIMIT, Semaphore } from "../runs/shared/parallel-utils.js";
|
|
6
6
|
import { HOST_STEP_MAX_COUNT } from "../runs/shared/host-step-status.js";
|
|
7
7
|
import { describeGateAcceptanceConflict, parseGateInput } from "../runs/shared/acceptance.js";
|
|
8
|
+
import { REQUIRE_LAUNCHER_SHAPE_ERROR } from "../runs/shared/runner-launcher.js";
|
|
8
9
|
import { normalizeWorkflowHostCommandParams } from "./host-command.js";
|
|
9
10
|
const KEY_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
10
11
|
const BASE_REF_VALIDATION_ERROR = "baseRef must be a valid Git ref: use HEAD or a supported named ref (for example, refs/heads/main). Full 40/64-character commit IDs and revision expressions are unsupported.";
|
|
@@ -19,8 +20,7 @@ function validGitRef(ref) {
|
|
|
19
20
|
}
|
|
20
21
|
const requireFromPackage = createRequire(import.meta.url);
|
|
21
22
|
const WORKFLOW_ASSEMBLY_FLUSH_TIMEOUT_MS = 5_000;
|
|
22
|
-
const
|
|
23
|
-
let nodeWorkerSource;
|
|
23
|
+
const WORKFLOW_DRAIN_CHILD_MESSAGE = "Workflow draining; child not started.";
|
|
24
24
|
function isWorkflowScriptFailureKind(value) {
|
|
25
25
|
return value === "validation" || value === "script" || value === "child" || value === "return-serialization" || value === "timeout" || value === "detached-child" || value === "runtime";
|
|
26
26
|
}
|
|
@@ -95,8 +95,182 @@ const RECOVERY_REVIEW_NO_ANAPHORIC_MUTATION_CLAUSE_PATTERN = /\b(?:do not|don't|
|
|
|
95
95
|
const RECOVERY_REVIEW_NO_DELEGATION_CLAUSE_PATTERN = /\b(?:do not|don't|must not)\s+(?:(?:launch|start|spawn|run)\b(?:(?!\b(?:and|but|then|however|nevertheless|nonetheless|yet)\b)[^,.;!?\n])*(?:workers?|reviewers?|agents?|subagents?|children|child|runs?)|(?:get|let|request|hand\s+off|assign|use|have|tell)\b(?:(?!\b(?:and|but|then|however|nevertheless|nonetheless|yet)\b)[^,.;!?\n])*(?:workers?|reviewers?|agents?|subagents?|children|child)|(?:get|let|have|tell|request)\b(?:(?!\b(?:and|but|then|however|nevertheless|nonetheless|yet)\b)[^,.;!?\n])*(?:review|implementation|fix(?:es)?|changes?|follow-up)\b(?:(?!\b(?:and|but|then|however|nevertheless|nonetheless|yet)\b)[^,.;!?\n])*\b(?:from|with|via|by)\b(?:(?!\b(?:and|but|then|however|nevertheless|nonetheless|yet)\b)[^,.;!?\n])*(?:workers?|reviewers?|agents?|subagents?|children|child)|ask\b(?:(?!\b(?:and|but|then|however|nevertheless|nonetheless|yet)\b)[^,.;!?\n])*(?:(?:workers?|reviewers?|agents?|subagents?|children|child)\b(?:(?!\b(?:and|but|then|however|nevertheless|nonetheless|yet)\b)[^,.;!?\n])*\b(?:continue|implement|review|fix|edit|write|modify|change|patch|update|delete|remove|create|follow-up)|(?:review|implementation|fix(?:es)?|changes?|follow-up)\b(?:(?!\b(?:and|but|then|however|nevertheless|nonetheless|yet)\b)[^,.;!?\n])*\b(?:from|via)\b(?:(?!\b(?:and|but|then|however|nevertheless|nonetheless|yet)\b)[^,.;!?\n])*(?:workers?|reviewers?|agents?|subagents?|children|child)))\b/gi;
|
|
96
96
|
const RECOVERY_REVIEW_DELEGATION_PATTERN = /\b(?:launch|start|spawn|run)\b[^,.;!?\n]*(?:workers?|reviewers?|agents?|subagents?|children|child|runs?)\b|\b(?:delegate|hand\s+off|assign)\s+(?:remediation|implementation(?:\s+follow-up)?|changes?|fix(?:es)?|follow-up)\s+to\s+(?:(?:a|an|the)\s+)?(?:workers?|reviewers?|agents?|subagents?|children|child)\b|\b(?:get|let|have|tell|request)\b[^,.;!?\n]*(?:workers?|reviewers?|agents?|subagents?|children|child)\b[^,.;!?\n]*\b(?:continue|implement|review|fix|edit|write|modify|change|patch|update|delete|remove|create|follow-up)\b|\b(?:get|let|have|tell|request)\b[^,.;!?\n]*(?:review|implementation|fix(?:es)?|changes?|follow-up)\b[^,.;!?\n]*\b(?:from|with|via|by)\b[^,.;!?\n]*(?:workers?|reviewers?|agents?|subagents?|children|child)\b|\bask\b[^,.;!?\n]*(?:(?:workers?|reviewers?|agents?|subagents?|children|child)\b[^,.;!?\n]*\b(?:continue|implement|review|fix|edit|write|modify|change|patch|update|delete|remove|create|follow-up)|(?:review|implementation|fix(?:es)?|changes?|follow-up)\b[^,.;!?\n]*\b(?:from|via)\b[^,.;!?\n]*(?:workers?|reviewers?|agents?|subagents?|children|child))\b|\buse\b[^,.;!?\n]*(?:workers?|reviewers?|agents?|subagents?|children|child|runs?)\s+(?:for|to)\s+(?:implementation|follow-up|remediation|fix|edit|write|modify|change|patch|update|delete|remove|create)\b/i;
|
|
97
97
|
const RECOVERY_REVIEW_ANAPHORIC_MUTATION_PATTERN = /\b(?:do|run|execute|perform|apply)\s+(?:it|that|this|(?:the\s+)?(?:(?:\d+(?:st|nd|rd|th)|first|second|third|fourth|fifth|sixth|seventh|eighth|ninth|tenth|last|next|previous(?:ly)?|prior|above|quoted|blocked)\s+){0,4}(?:command|example|operation|action|phrase|instruction|request|one))(?!(?:\s+(?:(?:now|still|also|already)\s+)*(?:is|are|remains?)\s+blocked\b))(?:(?:[\s,]+\w+){0,4}[\s,]+anyway|(?:(?!\b(?:and|but|then|however|nevertheless|nonetheless|yet)\b)[^,.;!?\n]){0,80})(?=\s*(?:[,.;!?\n)]|\b(?:and|but|then|however|nevertheless|nonetheless|yet)\b|$))/i;
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
// A path need not cross another command-start separator: the same command can match from
|
|
99
|
+
// the last such separator before its slash. Excluding those characters from the path prefix
|
|
100
|
+
// preserves detection while preventing overlapping starts from rescanning the same suffix.
|
|
101
|
+
const RECOVERY_REVIEW_MUTATING_PATH_COMMAND_PATTERN = /(?:^|[\s;,.`'"([{])(?:[^\s;,.`'"([{]*\/)?(?:rm|rmdir|unlink|truncate|mv|cp|chmod|chown)\b/i;
|
|
102
|
+
const RECOVERY_REVIEW_WORD_CHARACTER_PATTERN = /^\w$/;
|
|
103
|
+
// Each branch after a separator is checked at its own anchor, and what it needs from the rest of the
|
|
104
|
+
// line or path comes from tables built in one backward pass, so many separators never rescan a suffix.
|
|
105
|
+
const RECOVERY_REVIEW_DASH_SEPARATOR_AT_PATTERN = /(?:[—–]|--|\s-\s|:|\s\/\s)/iy;
|
|
106
|
+
const RECOVERY_REVIEW_DASH_SEPARATOR_EXISTS_PATTERN = /(?:[—–]|--|\s-\s|:|\s\/\s)/i;
|
|
107
|
+
const RECOVERY_REVIEW_DASH_ACTION_AT_PATTERN = /(?:add|append|apply|change|cherry[ -]pick|clean|commit|copy|create|delete|edit|fix|implement|insert|make|merge|move|modify|mutate|open|patch|prepend|push|rebase|refactor|remove|rename|replace|revert|revise|rewrite|save|stage|stash|tag|touch|update|write)\b/iy;
|
|
108
|
+
const RECOVERY_REVIEW_DASH_LAUNCH_AT_PATTERN = /(?:launch|start|spawn|run)\b/iy;
|
|
109
|
+
const RECOVERY_REVIEW_DASH_WORKER_AT_PATTERN = /(?:workers?|reviewers?|agents?|subagents?|children|child|runs?)\b/iy;
|
|
110
|
+
const RECOVERY_REVIEW_DASH_GIT_AT_PATTERN = /git\b/iy;
|
|
111
|
+
const RECOVERY_REVIEW_DASH_GIT_COMMAND_AT_PATTERN = /\b(?:add|branch|cherry-pick|clean|commit|merge|rebase|reset|restore|revert|stash|tag|checkout|switch)\b/iy;
|
|
112
|
+
const RECOVERY_REVIEW_DASH_FILE_COMMAND_AT_PATTERN = /(?:rm|rmdir|unlink|truncate|mv|cp|chmod|chown)\b/iy;
|
|
113
|
+
const RECOVERY_REVIEW_DASH_THEN_AT_PATTERN = /then/iy;
|
|
114
|
+
const RECOVERY_REVIEW_DASH_LINE_STOP_CHARACTERS = ",.;!?\n";
|
|
115
|
+
const RECOVERY_REVIEW_WHITESPACE_CHARACTER_PATTERN = /^\s$/;
|
|
116
|
+
// Sticky patterns: lastIndex anchors each check. No check yields, so the shared lastIndex cannot interleave.
|
|
117
|
+
function matchesDashBranchAt(pattern, text, index) {
|
|
118
|
+
pattern.lastIndex = index;
|
|
119
|
+
return pattern.test(text);
|
|
120
|
+
}
|
|
121
|
+
function dashBranchLengthAt(pattern, text, index) {
|
|
122
|
+
pattern.lastIndex = index;
|
|
123
|
+
const match = pattern.exec(text);
|
|
124
|
+
return match === null ? 0 : match[0].length;
|
|
125
|
+
}
|
|
126
|
+
function skipDashSeparatorWhitespace(text, index) {
|
|
127
|
+
while (index < text.length && RECOVERY_REVIEW_WHITESPACE_CHARACTER_PATTERN.test(text.charAt(index)))
|
|
128
|
+
index++;
|
|
129
|
+
return index;
|
|
130
|
+
}
|
|
131
|
+
// workerAhead[i] says whether the rest of the line still holds the worker word, gitCommandAhead[i]
|
|
132
|
+
// the same for a git command, and pathCommandAhead[i] whether the rest of the path holds a file
|
|
133
|
+
// command behind a slash.
|
|
134
|
+
function acceptsDashLiveActionAt(text, index, workerAhead, gitCommandAhead, pathCommandAhead) {
|
|
135
|
+
if (matchesDashBranchAt(RECOVERY_REVIEW_DASH_ACTION_AT_PATTERN, text, index))
|
|
136
|
+
return true;
|
|
137
|
+
const launchLength = dashBranchLengthAt(RECOVERY_REVIEW_DASH_LAUNCH_AT_PATTERN, text, index);
|
|
138
|
+
if (launchLength > 0 && workerAhead[index + launchLength] === 1)
|
|
139
|
+
return true;
|
|
140
|
+
if (matchesDashBranchAt(RECOVERY_REVIEW_DASH_FILE_COMMAND_AT_PATTERN, text, index) || pathCommandAhead[index] === 1)
|
|
141
|
+
return true;
|
|
142
|
+
return matchesDashBranchAt(RECOVERY_REVIEW_DASH_GIT_AT_PATTERN, text, index) && gitCommandAhead[index + 3] === 1;
|
|
143
|
+
}
|
|
144
|
+
function mentionsDashLiveAction(text) {
|
|
145
|
+
if (!RECOVERY_REVIEW_DASH_SEPARATOR_EXISTS_PATTERN.test(text))
|
|
146
|
+
return false;
|
|
147
|
+
const workerAhead = new Uint8Array(text.length + 1);
|
|
148
|
+
const gitCommandAhead = new Uint8Array(text.length + 1);
|
|
149
|
+
const pathCommandAhead = new Uint8Array(text.length + 1);
|
|
150
|
+
for (let index = text.length - 1; index >= 0; index--) {
|
|
151
|
+
const character = text.charAt(index);
|
|
152
|
+
const lineCharacter = !RECOVERY_REVIEW_DASH_LINE_STOP_CHARACTERS.includes(character);
|
|
153
|
+
const pathCharacter = !RECOVERY_REVIEW_WHITESPACE_CHARACTER_PATTERN.test(character);
|
|
154
|
+
workerAhead[index] = matchesDashBranchAt(RECOVERY_REVIEW_DASH_WORKER_AT_PATTERN, text, index) || (lineCharacter && workerAhead[index + 1] === 1) ? 1 : 0;
|
|
155
|
+
gitCommandAhead[index] = matchesDashBranchAt(RECOVERY_REVIEW_DASH_GIT_COMMAND_AT_PATTERN, text, index) || (lineCharacter && gitCommandAhead[index + 1] === 1) ? 1 : 0;
|
|
156
|
+
pathCommandAhead[index] = (character === "/" && matchesDashBranchAt(RECOVERY_REVIEW_DASH_FILE_COMMAND_AT_PATTERN, text, index + 1)) || (pathCharacter && pathCommandAhead[index + 1] === 1) ? 1 : 0;
|
|
157
|
+
}
|
|
158
|
+
for (let index = 0; index < text.length; index++) {
|
|
159
|
+
const separatorLength = dashBranchLengthAt(RECOVERY_REVIEW_DASH_SEPARATOR_AT_PATTERN, text, index);
|
|
160
|
+
if (separatorLength === 0)
|
|
161
|
+
continue;
|
|
162
|
+
// \s* and then\s+ only cross whitespace, and no branch starts with whitespace, so the end
|
|
163
|
+
// of that whitespace run is the only anchor a branch can match at.
|
|
164
|
+
const anchor = skipDashSeparatorWhitespace(text, index + separatorLength);
|
|
165
|
+
if (acceptsDashLiveActionAt(text, anchor, workerAhead, gitCommandAhead, pathCommandAhead))
|
|
166
|
+
return true;
|
|
167
|
+
if (!matchesDashBranchAt(RECOVERY_REVIEW_DASH_THEN_AT_PATTERN, text, anchor))
|
|
168
|
+
continue;
|
|
169
|
+
const afterThen = skipDashSeparatorWhitespace(text, anchor + 4);
|
|
170
|
+
if (afterThen > anchor + 4 && acceptsDashLiveActionAt(text, afterThen, workerAhead, gitCommandAhead, pathCommandAhead))
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
// This is the git branch of the dash-live check, not a shell parser. afterOption and
|
|
176
|
+
// afterSpace implement (\s+OPTION)*\s+; short/special options can also take \s+V,
|
|
177
|
+
// generic long options only =V. V keeps "[^"\n]*", '[^'\n]*' and \S+ alive together.
|
|
178
|
+
function createMutatingGitStates() {
|
|
179
|
+
const state = () => ({ edges: [], epsilon: [] });
|
|
180
|
+
const edge = (from, character, next) => {
|
|
181
|
+
from.edges.push({ character, next });
|
|
182
|
+
};
|
|
183
|
+
const literal = (from, word, end) => {
|
|
184
|
+
for (let index = 0; index < word.length; index++) {
|
|
185
|
+
const next = index === word.length - 1 ? end : state();
|
|
186
|
+
edge(from, new RegExp(word.charAt(index), "i"), next);
|
|
187
|
+
from = next;
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
const start = state();
|
|
191
|
+
const accept = state();
|
|
192
|
+
const afterOption = state();
|
|
193
|
+
const afterSpace = state();
|
|
194
|
+
literal(start, "git", afterOption);
|
|
195
|
+
edge(afterOption, /\s/, afterSpace);
|
|
196
|
+
edge(afterSpace, /\s/, afterSpace);
|
|
197
|
+
for (const command of ["add", "branch", "cherry-pick", "clean", "commit", "merge", "rebase", "reset", "restore", "revert", "stash", "tag", "checkout", "switch"]) {
|
|
198
|
+
literal(afterSpace, command, accept);
|
|
199
|
+
}
|
|
200
|
+
const value = state();
|
|
201
|
+
const beforeSeparatedValue = state();
|
|
202
|
+
const separatedValue = state();
|
|
203
|
+
edge(beforeSeparatedValue, /\s/, separatedValue);
|
|
204
|
+
edge(separatedValue, /\s/, separatedValue);
|
|
205
|
+
separatedValue.epsilon.push(value);
|
|
206
|
+
const shortDash = state();
|
|
207
|
+
const shortOption = state();
|
|
208
|
+
literal(afterSpace, "-", shortDash);
|
|
209
|
+
edge(shortDash, /[A-Za-z]/, shortOption);
|
|
210
|
+
shortOption.epsilon.push(afterOption, beforeSeparatedValue);
|
|
211
|
+
const longStart = state();
|
|
212
|
+
const longName = state();
|
|
213
|
+
literal(shortDash, "-", longStart);
|
|
214
|
+
edge(longStart, /[A-Za-z0-9-]/, longName);
|
|
215
|
+
edge(longName, /[A-Za-z0-9-]/, longName);
|
|
216
|
+
longName.epsilon.push(afterOption);
|
|
217
|
+
edge(longName, /=/, value);
|
|
218
|
+
for (const option of ["git-dir", "work-tree", "namespace", "exec-path", "config-env"]) {
|
|
219
|
+
const specialOption = state();
|
|
220
|
+
literal(longStart, option, specialOption);
|
|
221
|
+
edge(specialOption, /=/, value);
|
|
222
|
+
specialOption.epsilon.push(beforeSeparatedValue);
|
|
223
|
+
}
|
|
224
|
+
for (const [quote, body] of [[/"/, /[^"\n]/], [/'/, /[^'\n]/]]) {
|
|
225
|
+
const quotedValue = state();
|
|
226
|
+
edge(value, quote, quotedValue);
|
|
227
|
+
edge(quotedValue, body, quotedValue);
|
|
228
|
+
edge(quotedValue, quote, afterOption);
|
|
229
|
+
}
|
|
230
|
+
const plainValue = state();
|
|
231
|
+
edge(value, /\S/, plainValue);
|
|
232
|
+
edge(plainValue, /\S/, plainValue);
|
|
233
|
+
plainValue.epsilon.push(afterOption);
|
|
234
|
+
return { start, accept };
|
|
235
|
+
}
|
|
236
|
+
const MUTATING_GIT_STATES = createMutatingGitStates();
|
|
237
|
+
function mentionsMutatingGitCommand(text) {
|
|
238
|
+
let active = new Set();
|
|
239
|
+
let next = new Set();
|
|
240
|
+
const addState = (states, state) => {
|
|
241
|
+
if (states.has(state))
|
|
242
|
+
return;
|
|
243
|
+
states.add(state);
|
|
244
|
+
for (const reachable of state.epsilon)
|
|
245
|
+
addState(states, reachable);
|
|
246
|
+
};
|
|
247
|
+
// Inject starts even inside another candidate's value. Deduplicating states at each UTF-16
|
|
248
|
+
// position preserves every reading without backtracking or suffix rescans: O(n*m) time and
|
|
249
|
+
// O(m) space for this fixed graph of m states. /i (without /u) uses ASCII word boundaries.
|
|
250
|
+
for (let position = 0; position <= text.length; position++) {
|
|
251
|
+
const character = text.charAt(position);
|
|
252
|
+
const previousIsWord = RECOVERY_REVIEW_WORD_CHARACTER_PATTERN.test(text.charAt(position - 1));
|
|
253
|
+
const currentIsWord = RECOVERY_REVIEW_WORD_CHARACTER_PATTERN.test(character);
|
|
254
|
+
if (active.has(MUTATING_GIT_STATES.accept) && previousIsWord !== currentIsWord)
|
|
255
|
+
return true;
|
|
256
|
+
if (!previousIsWord)
|
|
257
|
+
addState(active, MUTATING_GIT_STATES.start);
|
|
258
|
+
if (position === text.length)
|
|
259
|
+
break;
|
|
260
|
+
next.clear();
|
|
261
|
+
for (const state of active) {
|
|
262
|
+
for (const edge of state.edges) {
|
|
263
|
+
if (edge.character.test(character))
|
|
264
|
+
addState(next, edge.next);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
[active, next] = [next, active];
|
|
268
|
+
}
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
function mentionsMutatingCommand(text) {
|
|
272
|
+
return RECOVERY_REVIEW_MUTATING_PATH_COMMAND_PATTERN.test(text) || mentionsMutatingGitCommand(text);
|
|
273
|
+
}
|
|
100
274
|
function isExplicitReadOnlyRecoveryReview(params) {
|
|
101
275
|
const agent = typeof params.agent === "string" ? params.agent.trim() : "";
|
|
102
276
|
const task = typeof params.task === "string" ? params.task.trim() : "";
|
|
@@ -173,12 +347,12 @@ function isExplicitReadOnlyRecoveryReview(params) {
|
|
|
173
347
|
&& agent !== ""
|
|
174
348
|
&& /\b(?:advisor|oracle|review|reviewer)\b/i.test(agent)
|
|
175
349
|
&& RECOVERY_REVIEW_READ_ONLY_PATTERN.test(task)
|
|
176
|
-
&& !
|
|
350
|
+
&& !mentionsMutatingCommand(taskDestructiveCommandText)
|
|
177
351
|
&& !RECOVERY_REVIEW_MUTATION_VERB_PATTERN.test(taskMutationText)
|
|
178
352
|
&& !RECOVERY_REVIEW_DELEGATION_PATTERN.test(taskMutationText)
|
|
179
353
|
&& !RECOVERY_REVIEW_ANAPHORIC_MUTATION_PATTERN.test(taskMutationText)
|
|
180
|
-
&& !
|
|
181
|
-
&& !
|
|
354
|
+
&& !mentionsMutatingCommand(taskMutationText)
|
|
355
|
+
&& !mentionsDashLiveAction(taskDashLiveActionText);
|
|
182
356
|
}
|
|
183
357
|
function recoveryBarrierMessage(sourceKey, target) {
|
|
184
358
|
return `Run '${target}' cannot launch after run '${sourceKey}' returned rejected acceptance recovery; only explicit read-only review children with acceptance:false may follow.`;
|
|
@@ -545,29 +719,63 @@ function directObjectPropertyValue(node, name) {
|
|
|
545
719
|
}
|
|
546
720
|
return value;
|
|
547
721
|
}
|
|
548
|
-
function
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
722
|
+
function arrayElements(node) {
|
|
723
|
+
return astNode(node) && node.type === "ArrayExpression" && Array.isArray(node.elements) ? node.elements : [];
|
|
724
|
+
}
|
|
725
|
+
/** The final definition of `name` in an object literal; undefined when a later spread or unknown key may overwrite it. */
|
|
726
|
+
function finalStaticProperty(node, name) {
|
|
727
|
+
if (node.type !== "ObjectExpression" || !Array.isArray(node.properties))
|
|
728
|
+
return undefined;
|
|
729
|
+
for (let index = node.properties.length - 1; index >= 0; index--) {
|
|
730
|
+
const property = node.properties[index];
|
|
554
731
|
if (!astNode(property) || property.type !== "Property")
|
|
555
|
-
return
|
|
732
|
+
return undefined;
|
|
556
733
|
const key = staticPropertyKey(property);
|
|
557
734
|
if (key === undefined)
|
|
558
|
-
return
|
|
559
|
-
if (key
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
}
|
|
735
|
+
return undefined;
|
|
736
|
+
if (key === name)
|
|
737
|
+
return property;
|
|
738
|
+
}
|
|
739
|
+
return undefined;
|
|
740
|
+
}
|
|
741
|
+
function validateStaticBaseRef(params, owner) {
|
|
742
|
+
const property = finalStaticProperty(params, "baseRef");
|
|
743
|
+
if (property?.kind !== "init" || !astNode(property.value))
|
|
568
744
|
return [];
|
|
745
|
+
const valueNode = property.value;
|
|
746
|
+
const value = literalString(valueNode);
|
|
747
|
+
return (value !== undefined || valueNode.type === "Literal") && !validGitRef(value)
|
|
748
|
+
? [{ message: `${owner} ${BASE_REF_VALIDATION_ERROR}`, ...nodeLocation(valueNode) }]
|
|
749
|
+
: [];
|
|
750
|
+
}
|
|
751
|
+
// Same text as validateLaneSpecs in workflow-script-worker.cjs; a test compares the two.
|
|
752
|
+
const LANE_RETAINED_RESUME_ERROR = "cannot resume a retained run id in runs.lanes; use runs.run(key, { resume: id }) outside lanes, or start the lane with an agent stage and use resume: \"previous\" later.";
|
|
753
|
+
// A spread or unknown computed key on the lane can replace `stages`.
|
|
754
|
+
function staticLane(lane) {
|
|
755
|
+
return astNode(lane) && lane.type === "ObjectExpression" && Array.isArray(lane.properties)
|
|
756
|
+
&& lane.properties.every((property) => astNode(property) && property.type === "Property" && staticPropertyKey(property) !== undefined);
|
|
757
|
+
}
|
|
758
|
+
/** The launch-time first-stage resume rule, for lanes written out as literals. */
|
|
759
|
+
function validateStaticLaneResumes(call) {
|
|
760
|
+
const args = Array.isArray(call.arguments) ? call.arguments : [];
|
|
761
|
+
const lanes = arrayElements(args[0]);
|
|
762
|
+
const errors = [];
|
|
763
|
+
for (let laneIndex = 0; laneIndex < lanes.length; laneIndex++) {
|
|
764
|
+
const lane = lanes[laneIndex];
|
|
765
|
+
// A spread shifts every later lane index the runtime reports.
|
|
766
|
+
if (astNode(lane) && lane.type === "SpreadElement")
|
|
767
|
+
break;
|
|
768
|
+
if (!staticLane(lane))
|
|
769
|
+
continue;
|
|
770
|
+
const first = arrayElements(directObjectPropertyValue(lane, "stages"))[0];
|
|
771
|
+
if (!astNode(first))
|
|
772
|
+
continue;
|
|
773
|
+
const property = finalStaticProperty(first, "resume");
|
|
774
|
+
const resume = property?.kind === "init" ? literalString(property.value) : undefined;
|
|
775
|
+
if (resume !== undefined && resume !== "previous")
|
|
776
|
+
errors.push({ message: `runs.lanes lane ${laneIndex} stage 0 ${LANE_RETAINED_RESUME_ERROR}`, ...nodeLocation(first) });
|
|
569
777
|
}
|
|
570
|
-
return
|
|
778
|
+
return errors;
|
|
571
779
|
}
|
|
572
780
|
// Children with their own cwd, agentScope, or resume resolve agents elsewhere, and a
|
|
573
781
|
// spread or computed key can replace `agent`; leave those to launch-time resolution.
|
|
@@ -588,16 +796,12 @@ function staticChildAgentNode(params) {
|
|
|
588
796
|
}
|
|
589
797
|
function validateStaticChildAgents(call, agentNameError) {
|
|
590
798
|
const args = Array.isArray(call.arguments) ? call.arguments : [];
|
|
591
|
-
const elements = (node) => astNode(node) && node.type === "ArrayExpression" && Array.isArray(node.elements) ? node.elements : [];
|
|
592
|
-
// A spread or unknown computed key on the lane can replace `stages`.
|
|
593
|
-
const staticLane = (lane) => astNode(lane) && lane.type === "ObjectExpression" && Array.isArray(lane.properties)
|
|
594
|
-
&& lane.properties.every((property) => astNode(property) && property.type === "Property" && staticPropertyKey(property) !== undefined);
|
|
595
799
|
const children = directRunsCall(call, "run")
|
|
596
800
|
? [{ owner: "runs.run", params: args[1] }]
|
|
597
801
|
: directRunsCall(call, "all")
|
|
598
|
-
?
|
|
802
|
+
? arrayElements(args[0]).map((params) => ({ owner: "runs.all item", params }))
|
|
599
803
|
: directRunsCall(call, "lanes")
|
|
600
|
-
?
|
|
804
|
+
? arrayElements(args[0]).flatMap((lane) => staticLane(lane) ? arrayElements(directObjectPropertyValue(lane, "stages")).map((params) => ({ owner: "runs.lanes stage", params })) : [])
|
|
601
805
|
: [];
|
|
602
806
|
const errors = [];
|
|
603
807
|
for (const child of children) {
|
|
@@ -611,8 +815,7 @@ function validateStaticChildAgents(call, agentNameError) {
|
|
|
611
815
|
}
|
|
612
816
|
function directRunsAllKeys(call) {
|
|
613
817
|
const args = Array.isArray(call.arguments) ? call.arguments : [];
|
|
614
|
-
|
|
615
|
-
return items.flatMap((item) => {
|
|
818
|
+
return arrayElements(args[0]).flatMap((item) => {
|
|
616
819
|
if (!astNode(item))
|
|
617
820
|
return [];
|
|
618
821
|
const keyNode = directObjectPropertyValue(item, "key");
|
|
@@ -620,6 +823,41 @@ function directRunsAllKeys(call) {
|
|
|
620
823
|
return keyNode && key !== undefined ? [{ key, node: keyNode }] : [];
|
|
621
824
|
});
|
|
622
825
|
}
|
|
826
|
+
/** runs.all items certain to reach the runtime without a key: plain literals in the array, or the one result of a map callback. */
|
|
827
|
+
function keylessRunsAllItems(call) {
|
|
828
|
+
const args = Array.isArray(call.arguments) ? call.arguments : [];
|
|
829
|
+
const items = args[0];
|
|
830
|
+
if (!astNode(items))
|
|
831
|
+
return [];
|
|
832
|
+
if (items.type === "ArrayExpression" && Array.isArray(items.elements)) {
|
|
833
|
+
return items.elements.flatMap((item, index) => keylessItemLiteral(item) ? [{ node: item, index }] : []);
|
|
834
|
+
}
|
|
835
|
+
const callee = items.type === "CallExpression" && astNode(items.callee) && items.callee.type === "MemberExpression" && items.callee.computed !== true ? items.callee : undefined;
|
|
836
|
+
if (!callee || !astNode(callee.property) || callee.property.type !== "Identifier" || callee.property.name !== "map")
|
|
837
|
+
return [];
|
|
838
|
+
const callback = Array.isArray(items.arguments) ? items.arguments[0] : undefined;
|
|
839
|
+
if (!astNode(callback) || (callback.type !== "ArrowFunctionExpression" && callback.type !== "FunctionExpression") || !astNode(callback.body))
|
|
840
|
+
return [];
|
|
841
|
+
let result = callback.body;
|
|
842
|
+
if (callback.body.type === "BlockStatement" && Array.isArray(callback.body.body)) {
|
|
843
|
+
// Only a callback whose single return is its last statement always returns that literal.
|
|
844
|
+
const returns = [];
|
|
845
|
+
walkAst(callback.body, (node) => { if (node.type === "ReturnStatement")
|
|
846
|
+
returns.push(node); }, false);
|
|
847
|
+
result = returns.length === 1 && returns[0] === callback.body.body.at(-1) ? returns[0].argument : undefined;
|
|
848
|
+
}
|
|
849
|
+
return keylessItemLiteral(result) ? [{ node: result }] : [];
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* An object literal whose own keys are all visible (no spread, getter, setter, or computed key) and has no `key`.
|
|
853
|
+
* A thenable item (`{ then: child.then }`) is awaited as a launched child, so only the runtime can check it.
|
|
854
|
+
*/
|
|
855
|
+
function keylessItemLiteral(node) {
|
|
856
|
+
return astNode(node) && node.type === "ObjectExpression" && Array.isArray(node.properties)
|
|
857
|
+
// `__proto__: base` sets the prototype, and the runtime's destructuring reads a `key` found there.
|
|
858
|
+
&& node.properties.every((property) => astNode(property) && property.type === "Property" && property.kind === "init" && property.computed !== true && staticPropertyKey(property) !== "__proto__")
|
|
859
|
+
&& !directObjectPropertyValue(node, "key") && !directObjectPropertyValue(node, "then");
|
|
860
|
+
}
|
|
623
861
|
function containsWorkflowLaunch(node) {
|
|
624
862
|
let found = false;
|
|
625
863
|
walkAst(node, (candidate) => {
|
|
@@ -766,7 +1004,13 @@ export function validateWorkflowScript(script, options = {}) {
|
|
|
766
1004
|
const location = error && typeof error === "object" && "loc" in error && error.loc && typeof error.loc === "object"
|
|
767
1005
|
? error.loc
|
|
768
1006
|
: undefined;
|
|
769
|
-
const
|
|
1007
|
+
const parserMessage = (error instanceof Error ? error.message : String(error)).replace(/\s+\(\d+:\d+\)$/, "");
|
|
1008
|
+
const source = script.trim();
|
|
1009
|
+
// A path passed where source is expected parses as a regex or a stray token. Keep the parser's
|
|
1010
|
+
// message too: a one-token script can also be a real syntax error.
|
|
1011
|
+
const message = /^\S+$/.test(source) && (/^(?:~|\.{1,2})?\//.test(source) || /\.(?:[cm]?[jt]s|json)$/.test(source))
|
|
1012
|
+
? `${parserMessage}. The script looks like a file path ('${source}'): options.script takes the script's source text; pass a script file as workflow: "${source}".`
|
|
1013
|
+
: parserMessage;
|
|
770
1014
|
return { ok: false, errors: [{ message, ...(typeof location?.line === "number" ? { line: Math.max(1, location.line - 1) } : {}), ...(typeof location?.column === "number" ? { column: location.column + 1 } : {}) }] };
|
|
771
1015
|
}
|
|
772
1016
|
const wrapper = astNode(root.body) ? undefined : Array.isArray(root.body) && astNode(root.body[0]) && astNode(root.body[0].expression) && astNode(root.body[0].expression.callee)
|
|
@@ -801,19 +1045,24 @@ export function validateWorkflowScript(script, options = {}) {
|
|
|
801
1045
|
for (const entry of directRunsAllKeys(node))
|
|
802
1046
|
if (!KEY_PATTERN.test(entry.key))
|
|
803
1047
|
errors.push({ message: "runs.all item key must be 1-128 characters using letters, numbers, '.', '_' or '-', and start with a letter or number.", ...nodeLocation(entry.node) });
|
|
1048
|
+
if (!runsRebound)
|
|
1049
|
+
for (const item of keylessRunsAllItems(node)) {
|
|
1050
|
+
const subject = item.index === undefined ? "runs.all items built by this map(...) callback have no key" : `runs.all item ${item.index} has no key`;
|
|
1051
|
+
errors.push({ message: `${subject}; every runs.all item needs a stable key, for example runs.all([{ key: "review", agent, task }]).`, ...nodeLocation(item.node) });
|
|
1052
|
+
}
|
|
804
1053
|
const args = Array.isArray(node.arguments) ? node.arguments : [];
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
}
|
|
813
|
-
}
|
|
1054
|
+
for (const item of arrayElements(args[0]))
|
|
1055
|
+
if (astNode(item)) {
|
|
1056
|
+
errors.push(...validateStaticBaseRef(item, "runs.all item"));
|
|
1057
|
+
const message = definitelyNonJson(item);
|
|
1058
|
+
if (message)
|
|
1059
|
+
errors.push({ message: `runs.all item params are invalid: ${message}.`, ...nodeLocation(item) });
|
|
1060
|
+
}
|
|
814
1061
|
}
|
|
815
1062
|
if (directRunsCall(node, "host"))
|
|
816
1063
|
errors.push(...validateStaticHostCall(node));
|
|
1064
|
+
if (directRunsCall(node, "lanes") && !runsRebound)
|
|
1065
|
+
errors.push(...validateStaticLaneResumes(node));
|
|
817
1066
|
if (agentNameError)
|
|
818
1067
|
errors.push(...validateStaticChildAgents(node, agentNameError));
|
|
819
1068
|
const boundaryValue = node.type === "CallExpression" && astNode(node.callee) && node.callee.type === "Identifier" && node.callee.name === "emit" && Array.isArray(node.arguments) && astNode(node.arguments[0])
|
|
@@ -849,7 +1098,7 @@ export function validateWorkflowScript(script, options = {}) {
|
|
|
849
1098
|
if (keys.size === 0)
|
|
850
1099
|
continue;
|
|
851
1100
|
const args = Array.isArray(declaration.init.argument.arguments) ? declaration.init.argument.arguments : [];
|
|
852
|
-
const itemCount =
|
|
1101
|
+
const itemCount = arrayElements(args[0]).length;
|
|
853
1102
|
const arrayResultShape = Array.from({ length: itemCount });
|
|
854
1103
|
for (const later of laterStatements) {
|
|
855
1104
|
walkAstWithoutShadowedIdentifier(later, name, (node) => {
|
|
@@ -1001,13 +1250,7 @@ export async function runWorkflowScript(options) {
|
|
|
1001
1250
|
}
|
|
1002
1251
|
let worker;
|
|
1003
1252
|
try {
|
|
1004
|
-
|
|
1005
|
-
// Bun needs a real file as its resolver base on warm transpiler-cache hits, and no eval key at all: with one,
|
|
1006
|
-
// its Worker finalizer passes the URL to URL.revokeObjectURL and throws. Node keeps eval source because its
|
|
1007
|
-
// eval worker does not re-resolve inherited --import preloads after a cwd change.
|
|
1008
|
-
worker = bun
|
|
1009
|
-
? new Worker(WORKFLOW_WORKER_URL, { workerData: { acornPath } })
|
|
1010
|
-
: new Worker(nodeWorkerSource ??= readFileSync(WORKFLOW_WORKER_URL, "utf8"), { eval: true, workerData: { acornPath } });
|
|
1253
|
+
worker = createWorkflowScriptWorker(acornPath);
|
|
1011
1254
|
}
|
|
1012
1255
|
catch (error) {
|
|
1013
1256
|
throw new WorkflowScriptError(`Workflow worker could not start: ${error instanceof Error ? error.message : String(error)}`, emptyPartial(), "runtime", { cause: error });
|
|
@@ -1030,6 +1273,10 @@ export async function runWorkflowScript(options) {
|
|
|
1030
1273
|
let acceptanceRecoveryBarrier;
|
|
1031
1274
|
let settled = false;
|
|
1032
1275
|
let finishing = false;
|
|
1276
|
+
let draining = false;
|
|
1277
|
+
let onDrained;
|
|
1278
|
+
// Keys past the concurrency semaphore: a drain lets these finish and stops the rest.
|
|
1279
|
+
const acquiredLaunches = new Set();
|
|
1033
1280
|
let assemblyAbortRequested = false;
|
|
1034
1281
|
let assemblyFlushTimer;
|
|
1035
1282
|
let abortError;
|
|
@@ -1080,6 +1327,13 @@ export async function runWorkflowScript(options) {
|
|
|
1080
1327
|
if (isAcceptanceMetadataRecovery(result))
|
|
1081
1328
|
acceptanceRecoveryBarrier = { key };
|
|
1082
1329
|
};
|
|
1330
|
+
const drainIfIdle = () => {
|
|
1331
|
+
if (!onDrained || [...launches.keys()].some((key) => !children.has(key)))
|
|
1332
|
+
return;
|
|
1333
|
+
const done = onDrained;
|
|
1334
|
+
onDrained = undefined;
|
|
1335
|
+
done();
|
|
1336
|
+
};
|
|
1083
1337
|
const stopChild = (key, message = `Workflow child '${key}' stopped.`) => {
|
|
1084
1338
|
if (!launches.has(key) || children.has(key))
|
|
1085
1339
|
return false;
|
|
@@ -1098,8 +1352,21 @@ export async function runWorkflowScript(options) {
|
|
|
1098
1352
|
error: message,
|
|
1099
1353
|
});
|
|
1100
1354
|
traceChanged();
|
|
1355
|
+
drainIfIdle();
|
|
1101
1356
|
return true;
|
|
1102
1357
|
};
|
|
1358
|
+
const drain = (done) => {
|
|
1359
|
+
if (!draining) {
|
|
1360
|
+
draining = true;
|
|
1361
|
+
onDrained = done;
|
|
1362
|
+
}
|
|
1363
|
+
for (const key of launches.keys())
|
|
1364
|
+
if (!acquiredLaunches.has(key))
|
|
1365
|
+
stopChild(key, WORKFLOW_DRAIN_CHILD_MESSAGE);
|
|
1366
|
+
const started = [...launches.keys()].filter((key) => !children.has(key)).length;
|
|
1367
|
+
drainIfIdle();
|
|
1368
|
+
return started;
|
|
1369
|
+
};
|
|
1103
1370
|
const notifyChildSettled = (key, result) => {
|
|
1104
1371
|
if (result.state === "running" || !options.onChildSettled || !options.workflowRunId)
|
|
1105
1372
|
return;
|
|
@@ -1128,6 +1395,7 @@ export async function runWorkflowScript(options) {
|
|
|
1128
1395
|
}
|
|
1129
1396
|
};
|
|
1130
1397
|
options.registerStopChild?.(stopChild);
|
|
1398
|
+
options.registerDrain?.(drain);
|
|
1131
1399
|
return await new Promise((resolve, reject) => {
|
|
1132
1400
|
const finish = (outcome) => {
|
|
1133
1401
|
if (settled || finishing)
|
|
@@ -1143,6 +1411,7 @@ export async function runWorkflowScript(options) {
|
|
|
1143
1411
|
return;
|
|
1144
1412
|
settled = true;
|
|
1145
1413
|
options.registerStopChild?.(undefined);
|
|
1414
|
+
options.registerDrain?.(undefined);
|
|
1146
1415
|
if (timer)
|
|
1147
1416
|
clearTimeout(timer);
|
|
1148
1417
|
options.signal?.removeEventListener("abort", onAbort);
|
|
@@ -1226,8 +1495,8 @@ export async function runWorkflowScript(options) {
|
|
|
1226
1495
|
return onAbort();
|
|
1227
1496
|
worker.on("error", (error) => finish({ error: taggedWorkflowError(`Workflow worker failed: ${error instanceof Error ? error.message : String(error)}`, "runtime") }));
|
|
1228
1497
|
worker.on("exit", (code) => {
|
|
1229
|
-
if (!settled &&
|
|
1230
|
-
finish({ error: taggedWorkflowError(`Workflow worker exited
|
|
1498
|
+
if (!settled && !finishing)
|
|
1499
|
+
finish({ error: taggedWorkflowError(`Workflow worker exited before returning a result (code ${code}).`, "runtime") });
|
|
1231
1500
|
});
|
|
1232
1501
|
worker.on("message", (message) => {
|
|
1233
1502
|
if (settled)
|
|
@@ -1305,7 +1574,8 @@ export async function runWorkflowScript(options) {
|
|
|
1305
1574
|
return finish({ error: abortError ?? new Error("Workflow context was replaced or reloaded.") });
|
|
1306
1575
|
const respond = (promise, responsePath, onBoundaryError) => {
|
|
1307
1576
|
void promise.then((value) => {
|
|
1308
|
-
|
|
1577
|
+
// While draining, the script gets no answers: a refusal it throws on would abort the started children.
|
|
1578
|
+
if (settled || draining)
|
|
1309
1579
|
return;
|
|
1310
1580
|
const normalized = responsePath ? omitNonJsonWorkflowResultMetadata(value) : omitUndefinedWorkflowValues(value);
|
|
1311
1581
|
if (!responsePath) {
|
|
@@ -1321,7 +1591,7 @@ export async function runWorkflowScript(options) {
|
|
|
1321
1591
|
worker.postMessage({ type: "response", callId: message.callId, ok: false, error: `${responsePath} must contain only JSON data before it can be returned from workflowScript. Return a plain projection such as { runId, ok, output }. ${error instanceof Error ? error.message : String(error)}` });
|
|
1322
1592
|
}
|
|
1323
1593
|
}, (error) => {
|
|
1324
|
-
if (!settled) {
|
|
1594
|
+
if (!settled && !draining) {
|
|
1325
1595
|
const errorKind = error instanceof Error ? error.workflowErrorKind : undefined;
|
|
1326
1596
|
worker.postMessage({ type: "response", callId: message.callId, ok: false, error: error instanceof Error ? error.message : String(error), ...(isWorkflowScriptFailureKind(errorKind) ? { errorKind } : {}) });
|
|
1327
1597
|
}
|
|
@@ -1420,6 +1690,8 @@ export async function runWorkflowScript(options) {
|
|
|
1420
1690
|
}
|
|
1421
1691
|
if (acceptanceRecoveryBarrier)
|
|
1422
1692
|
return respond(Promise.reject(new Error(recoveryBarrierMessage(acceptanceRecoveryBarrier.key, `runs.host('${key}')`))));
|
|
1693
|
+
if (draining)
|
|
1694
|
+
return respond(Promise.reject(new Error(`runs.host('${key}') refused: the workflow is draining.`)));
|
|
1423
1695
|
if (!options.host)
|
|
1424
1696
|
return respond(Promise.reject(new Error("runs.host is unavailable in this host context.")));
|
|
1425
1697
|
if (hostCalls.size >= HOST_STEP_MAX_COUNT)
|
|
@@ -1494,8 +1766,13 @@ export async function runWorkflowScript(options) {
|
|
|
1494
1766
|
return respond(Promise.reject(new Error(`Duplicate workflow key '${key}' used with incompatible launch params.`)));
|
|
1495
1767
|
if (callObserved)
|
|
1496
1768
|
existing.observed = true;
|
|
1497
|
-
|
|
1498
|
-
|
|
1769
|
+
// Matching params make every later reuse entry identical, and each trace change rewrites the
|
|
1770
|
+
// whole trace to status.json and events.jsonl, so a re-delivery loop would grow without bound.
|
|
1771
|
+
if (!existing.reuseTraced) {
|
|
1772
|
+
existing.reuseTraced = true;
|
|
1773
|
+
trace.push({ operation: "run", key, state: "reused", ...workflowStringMetadata(params), ...(existing.generatedLaneKey ? { generatedLaneKey: existing.generatedLaneKey } : {}) });
|
|
1774
|
+
traceChanged();
|
|
1775
|
+
}
|
|
1499
1776
|
return respond(deliver(existing.promise), `runs.run('${key}') result`, (error) => children.set(key, responseBoundaryFailure(key, error)));
|
|
1500
1777
|
}
|
|
1501
1778
|
const permitError = options.oneUsePermit?.claim(key);
|
|
@@ -1507,6 +1784,9 @@ export async function runWorkflowScript(options) {
|
|
|
1507
1784
|
return respond(Promise.reject(new Error("Workflow child permit does not support retained resume.")));
|
|
1508
1785
|
if (params.action !== undefined)
|
|
1509
1786
|
return respond(Promise.reject(new Error(`runs.run('${key}') accepts execution params only; management action is not allowed.`)));
|
|
1787
|
+
// Before admission, which resolves a resume target; the executor would only see this after that.
|
|
1788
|
+
if (params.requireLauncher !== undefined)
|
|
1789
|
+
return respond(Promise.reject(new Error(`runs.run('${key}'): ${REQUIRE_LAUNCHER_SHAPE_ERROR}`)));
|
|
1510
1790
|
if (params.workflowScript !== undefined)
|
|
1511
1791
|
return respond(Promise.reject(new Error(`runs.run('${key}') cannot start a nested workflow script.`)));
|
|
1512
1792
|
if (params.tasks !== undefined || params.chain !== undefined || params.parallel !== undefined || params.concurrency !== undefined || params.chainDir !== undefined) {
|
|
@@ -1559,7 +1839,7 @@ export async function runWorkflowScript(options) {
|
|
|
1559
1839
|
return true;
|
|
1560
1840
|
});
|
|
1561
1841
|
admission = Promise.resolve().then(() => {
|
|
1562
|
-
if (settled || finishing)
|
|
1842
|
+
if (settled || finishing || draining)
|
|
1563
1843
|
return;
|
|
1564
1844
|
for (const call of calls)
|
|
1565
1845
|
assertRecoveryBarrierAllowsRun(call.key, call.params);
|
|
@@ -1570,6 +1850,8 @@ export async function runWorkflowScript(options) {
|
|
|
1570
1850
|
}
|
|
1571
1851
|
let resolvedResumeLineage;
|
|
1572
1852
|
const promise = admission.then(async () => {
|
|
1853
|
+
if (draining)
|
|
1854
|
+
stopChild(key, WORKFLOW_DRAIN_CHILD_MESSAGE);
|
|
1573
1855
|
if (settled || finishing || stoppedLaunches.has(key)) {
|
|
1574
1856
|
const reason = childController.signal.reason;
|
|
1575
1857
|
const text = children.get(key)?.error ?? (reason instanceof Error ? reason.message : typeof reason === "string" ? reason : "Workflow script aborted.");
|
|
@@ -1615,6 +1897,7 @@ export async function runWorkflowScript(options) {
|
|
|
1615
1897
|
const text = children.get(key)?.error ?? (reason instanceof Error ? reason.message : typeof reason === "string" ? reason : "Workflow script aborted.");
|
|
1616
1898
|
return stoppedChildResult(key, text);
|
|
1617
1899
|
}
|
|
1900
|
+
acquiredLaunches.add(key);
|
|
1618
1901
|
const result = await options.launch(key, launchParams, childSignal, { admitted: true, batch: batch !== undefined });
|
|
1619
1902
|
const autoResumeParams = setupAbortResumeParams(params, result, childSignal);
|
|
1620
1903
|
if (!autoResumeParams)
|
|
@@ -1649,6 +1932,7 @@ export async function runWorkflowScript(options) {
|
|
|
1649
1932
|
trace.push(settledEntry);
|
|
1650
1933
|
traceChanged();
|
|
1651
1934
|
notifyChildSettled(key, normalized);
|
|
1935
|
+
drainIfIdle();
|
|
1652
1936
|
return normalized;
|
|
1653
1937
|
}, (error) => {
|
|
1654
1938
|
const text = error instanceof Error ? error.message : String(error);
|
|
@@ -1660,6 +1944,7 @@ export async function runWorkflowScript(options) {
|
|
|
1660
1944
|
trace.push({ operation: "run", key, state: "failed", durationMs: Date.now() - startedAt, ...workflowStringMetadata(params), ...(generatedLaneKey ? { generatedLaneKey } : {}), error: text });
|
|
1661
1945
|
traceChanged();
|
|
1662
1946
|
notifyChildSettled(key, failure);
|
|
1947
|
+
drainIfIdle();
|
|
1663
1948
|
return failure;
|
|
1664
1949
|
});
|
|
1665
1950
|
launches.set(key, { fingerprint, promise, observed: callObserved, ...(generatedLaneKey ? { generatedLaneKey } : {}) });
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* and never becomes code. Scripts run on the ordinary workflow runtime.
|
|
5
5
|
*/
|
|
6
6
|
export type StructuredWorkflowKind = "tasks" | "chain";
|
|
7
|
-
|
|
7
|
+
/** Recovery advice per rejected field, so a retry keeps the caller's intent instead of dropping the field. */
|
|
8
|
+
export declare function unsupportedChildFieldAdvice(fields: readonly string[], scripts: boolean): string;
|
|
8
9
|
export declare function isPlainRecord(value: unknown): value is Record<string, unknown>;
|
|
9
|
-
/** Validate exact data shapes and expand them into a package-owned workflow script. */
|
|
10
|
-
export declare function buildStructuredWorkflowScript(kind: StructuredWorkflowKind, steps: unknown, originalTask: string | undefined): string;
|
|
10
|
+
/** Validate exact data shapes and expand them into a package-owned workflow script. `scripts` is true only for the named `parallel` workflow; top-level tasks and chain exist only when workflow scripts are disabled. */
|
|
11
|
+
export declare function buildStructuredWorkflowScript(kind: StructuredWorkflowKind, steps: unknown, originalTask: string | undefined, scripts: boolean): string;
|