@xzzpig/pi-subagents 0.21.0 → 0.24.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 +356 -0
- package/README.md +2 -2
- package/agents/evidence-auditor.md +1 -0
- package/agents/oracle.md +1 -0
- package/agents/reviewer.md +1 -0
- package/bundle/agent-management.js +16 -0
- package/bundle/agents.js +41 -0
- package/bundle/background-work.js +16 -0
- package/bundle/capability-ceiling.js +22 -0
- package/bundle/child-tool-plan.js +11 -0
- package/bundle/chunk-355ECEP2.js +1321 -0
- package/bundle/chunk-35GII5EF.js +637 -0
- package/bundle/chunk-3G4JXNZ4.js +4130 -0
- package/bundle/chunk-3U633XDZ.js +749 -0
- package/bundle/chunk-4QFZZV3O.js +57 -0
- package/bundle/chunk-62OCY2S4.js +14 -0
- package/bundle/chunk-7J4ZXMY7.js +18 -0
- package/bundle/chunk-7K3Z6DM7.js +276 -0
- package/bundle/chunk-BGIYHF2W.js +138 -0
- package/bundle/chunk-CTPAE36Y.js +94 -0
- package/bundle/chunk-D4EHT5SJ.js +14 -0
- package/bundle/chunk-ED55MIC2.js +1681 -0
- package/bundle/chunk-F3NSN7UH.js +7331 -0
- package/bundle/chunk-FJWI64H7.js +490 -0
- package/bundle/chunk-H36HBZB2.js +753 -0
- package/bundle/chunk-ICNYIALB.js +7347 -0
- package/bundle/chunk-KD2IMFN4.js +1310 -0
- package/bundle/chunk-LCDJWBVM.js +57 -0
- package/bundle/chunk-LPVUHUZ7.js +5503 -0
- package/bundle/chunk-MYCL5QEJ.js +1372 -0
- package/bundle/chunk-NCWCVJLT.js +1768 -0
- package/bundle/chunk-NIXWDZZV.js +9 -0
- package/bundle/chunk-NTRJDXBC.js +4175 -0
- package/bundle/chunk-OFGSZBHP.js +16924 -0
- package/bundle/chunk-OTLRAB22.js +143 -0
- package/bundle/chunk-QXASAHIA.js +173 -0
- package/bundle/chunk-RB4GELQA.js +458 -0
- package/bundle/chunk-RK2HDPLK.js +1234 -0
- package/bundle/chunk-SW2VMNIU.js +526 -0
- package/bundle/chunk-T65XRVVM.js +940 -0
- package/bundle/chunk-U4ODUYAG.js +235 -0
- package/bundle/chunk-UFNSLL5D.js +9796 -0
- package/bundle/chunk-UKG4V45O.js +228 -0
- package/bundle/chunk-UQDHXMUG.js +264 -0
- package/bundle/chunk-V2KFIGFH.js +8774 -0
- package/bundle/chunk-VO3G7HI3.js +85 -0
- package/bundle/chunk-WPW4V6HM.js +227 -0
- package/bundle/chunk-WW76JRIX.js +175 -0
- package/bundle/chunk-XA3DY6UG.js +161 -0
- package/bundle/chunk-YFCK7H2S.js +129 -0
- package/bundle/chunk-YYREO77V.js +137 -0
- package/bundle/chunk-Z6TFJ6BR.js +400 -0
- package/bundle/control-channel.js +11 -0
- package/bundle/delegation.js +14 -0
- package/bundle/external-job-provider.js +20 -0
- package/bundle/external-runs.js +21 -0
- package/bundle/index.js +30 -0
- package/bundle/inspectors.js +8 -0
- package/bundle/intercom-bridge.js +11 -0
- package/bundle/preflight.js +468 -0
- package/bundle/project-panes.js +28 -0
- package/bundle/required-child-extensions.js +6 -0
- package/bundle/shared-types.js +8 -0
- package/bundle/supervisor-routing.js +12 -0
- package/bundle/workflow-resources.js +7 -0
- package/docs/agents.md +42 -10
- package/docs/configuration.md +59 -14
- package/docs/extension-api.md +61 -9
- package/docs/fork-supervisor-routing.md +77 -0
- package/docs/missions.md +2 -0
- package/docs/observability.md +20 -5
- package/docs/standalone-background.md +8 -6
- package/docs/tool-reference.md +18 -5
- package/docs/workflows.md +25 -7
- package/index.d.ts +3 -0
- package/index.js +14 -0
- package/node_modules/@xzzpig/pi-components/package.json +1 -2
- package/package.json +107 -86
- package/skills/council-mode/SKILL.md +1 -4
- package/skills/pi-subagents/SKILL.md +130 -106
- package/skills/pi-subagents/references/orchestration.md +124 -0
- package/skills/pi-subagents/references/prompting-and-roles.md +96 -291
- package/src/agents/advertised-agent-prompt.d.ts +13 -0
- package/src/agents/advertised-agent-prompt.js +68 -0
- package/src/agents/agent-eject.d.ts +39 -0
- package/src/agents/agent-eject.js +263 -0
- package/src/agents/agent-management.d.ts +33 -0
- package/src/agents/agent-management.js +1541 -0
- package/src/agents/agent-memory.d.ts +48 -0
- package/src/agents/agent-memory.js +350 -0
- package/src/agents/agent-refinements.d.ts +99 -0
- package/src/agents/agent-refinements.js +568 -0
- package/src/agents/agent-scope.d.ts +3 -0
- package/src/agents/agent-scope.js +8 -0
- package/src/agents/agent-selection.d.ts +2 -0
- package/src/agents/agent-selection.js +22 -0
- package/src/agents/agent-serializer.d.ts +7 -0
- package/src/agents/agent-serializer.js +213 -0
- package/src/agents/agents.d.ts +352 -0
- package/src/agents/agents.js +2817 -0
- package/src/agents/builtin-names.d.ts +1 -0
- package/src/agents/builtin-names.js +16 -0
- package/src/agents/chain-serializer.d.ts +6 -0
- package/src/agents/chain-serializer.js +318 -0
- package/src/agents/frontmatter.d.ts +19 -0
- package/src/agents/frontmatter.js +166 -0
- package/src/agents/global-npm-root.d.ts +6 -0
- package/src/agents/global-npm-root.js +57 -0
- package/src/agents/identity.d.ts +7 -0
- package/src/agents/identity.js +29 -0
- package/src/agents/proactive-skills.d.ts +35 -0
- package/src/agents/proactive-skills.js +155 -0
- package/src/agents/runtime-agent-events.d.ts +26 -0
- package/src/agents/runtime-agent-events.js +52 -0
- package/src/agents/runtime-agent-registry.d.ts +66 -0
- package/src/agents/runtime-agent-registry.js +415 -0
- package/src/agents/runtime-discovery.d.ts +13 -0
- package/src/agents/runtime-discovery.js +27 -0
- package/src/agents/skills.d.ts +34 -0
- package/src/agents/skills.js +718 -0
- package/src/api/agent-management.d.ts +2 -0
- package/src/api/agent-management.js +2 -0
- package/src/api/agents.d.ts +6 -0
- package/src/api/agents.js +3 -0
- package/src/api/background-work.d.ts +41 -0
- package/src/api/background-work.js +171 -0
- package/src/api/capability-ceiling.d.ts +1 -0
- package/src/api/capability-ceiling.js +1 -0
- package/src/api/child-tool-plan.d.ts +1 -0
- package/src/api/child-tool-plan.js +1 -0
- package/src/api/control-channel.d.ts +1 -0
- package/src/api/control-channel.js +1 -0
- package/src/api/delegation.d.ts +132 -0
- package/src/api/delegation.js +8 -0
- package/src/api/external-job-provider.d.ts +57 -0
- package/src/api/external-job-provider.js +139 -0
- package/src/api/external-runs.d.ts +47 -0
- package/src/api/external-runs.js +245 -0
- package/src/api/inspectors.d.ts +20 -0
- package/src/api/inspectors.js +11 -0
- package/src/api/intercom-bridge.d.ts +1 -0
- package/src/api/intercom-bridge.js +1 -0
- package/src/api/preflight.d.ts +183 -0
- package/src/api/preflight.js +455 -0
- package/src/api/project-panes.d.ts +7 -0
- package/src/api/project-panes.js +7 -0
- package/src/api/required-child-extensions.d.ts +1 -0
- package/src/api/required-child-extensions.js +1 -0
- package/src/api/shared-types.d.ts +1 -0
- package/src/api/shared-types.js +1 -0
- package/src/api/supervisor-routing.d.ts +110 -0
- package/src/api/supervisor-routing.js +95 -0
- package/src/api/workflow-resources.d.ts +2 -0
- package/src/api/workflow-resources.js +1 -0
- package/src/extension/active-runs-prompt.d.ts +7 -0
- package/src/extension/active-runs-prompt.js +29 -0
- package/src/extension/config.d.ts +7 -0
- package/src/extension/config.js +290 -0
- package/src/extension/context-injection.d.ts +52 -0
- package/src/extension/context-injection.js +102 -0
- package/src/extension/control-notices.d.ts +18 -0
- package/src/extension/control-notices.js +29 -0
- package/src/extension/declaration-pinning.d.ts +18 -0
- package/src/extension/declaration-pinning.js +167 -0
- package/src/extension/doctor.d.ts +34 -0
- package/src/extension/doctor.js +236 -0
- package/src/extension/fanout-child.d.ts +6 -0
- package/src/extension/fanout-child.js +278 -0
- package/src/extension/herdr-pi-bridge.d.ts +16 -0
- package/src/extension/herdr-pi-bridge.js +261 -0
- package/src/extension/index.d.ts +18 -0
- package/src/extension/index.js +1288 -0
- package/src/extension/public-execution.d.ts +71 -0
- package/src/extension/public-execution.js +214 -0
- package/src/extension/reply-workflow-script.d.ts +11 -0
- package/src/extension/reply-workflow-script.js +71 -0
- package/src/extension/rpc.d.ts +84 -0
- package/src/extension/rpc.js +729 -0
- package/src/extension/schemas.d.ts +276 -0
- package/src/extension/schemas.js +311 -0
- package/src/extension/steering-notices.d.ts +14 -0
- package/src/extension/steering-notices.js +22 -0
- package/src/extension/subagent-guide.d.ts +4 -0
- package/src/extension/subagent-guide.js +114 -0
- package/src/extension/subagent-options.d.ts +7 -0
- package/src/extension/subagent-options.js +64 -0
- package/src/extension/tool-activation.d.ts +7 -0
- package/src/extension/tool-activation.js +185 -0
- package/src/extension/tool-description.d.ts +19 -0
- package/src/extension/tool-description.js +169 -0
- package/src/extension/tool-result.d.ts +9 -0
- package/src/extension/tool-result.js +16 -0
- package/src/extension/upgrade-notice.d.ts +6 -0
- package/src/extension/upgrade-notice.js +42 -0
- package/src/inspectors/actions.d.ts +24 -0
- package/src/inspectors/actions.js +182 -0
- package/src/inspectors/ghostty/actions.d.ts +11 -0
- package/src/inspectors/ghostty/actions.js +62 -0
- package/src/inspectors/ghostty/plugin.d.ts +7 -0
- package/src/inspectors/ghostty/plugin.js +23 -0
- package/src/inspectors/herdr/actions.d.ts +25 -0
- package/src/inspectors/herdr/actions.js +133 -0
- package/src/inspectors/herdr/client.d.ts +41 -0
- package/src/inspectors/herdr/client.js +129 -0
- package/src/inspectors/herdr/focus.d.ts +24 -0
- package/src/inspectors/herdr/focus.js +49 -0
- package/src/inspectors/herdr/plugin.d.ts +6 -0
- package/src/inspectors/herdr/plugin.js +14 -0
- package/src/inspectors/herdr/project-panes.d.ts +136 -0
- package/src/inspectors/herdr/project-panes.js +610 -0
- package/src/inspectors/inspector-runner.d.ts +23 -0
- package/src/inspectors/inspector-runner.js +161 -0
- package/src/inspectors/plugins.d.ts +8 -0
- package/src/inspectors/plugins.js +82 -0
- package/src/inspectors/session-roots-codec.d.ts +15 -0
- package/src/inspectors/session-roots-codec.js +32 -0
- package/src/inspectors/shell-command.d.ts +1 -0
- package/src/inspectors/shell-command.js +16 -0
- package/src/inspectors/tmux/actions.d.ts +25 -0
- package/src/inspectors/tmux/actions.js +181 -0
- package/src/inspectors/tmux/client.d.ts +27 -0
- package/src/inspectors/tmux/client.js +64 -0
- package/src/inspectors/tmux/plugin.d.ts +7 -0
- package/src/inspectors/tmux/plugin.js +14 -0
- package/src/inspectors/types.d.ts +48 -0
- package/src/inspectors/types.js +1 -0
- package/src/integrations/herdr-status.d.ts +47 -0
- package/src/integrations/herdr-status.js +350 -0
- package/src/integrations/pi-web-session-liveness.d.ts +19 -0
- package/src/integrations/pi-web-session-liveness.js +53 -0
- package/src/integrations/program-status.d.ts +30 -0
- package/src/integrations/program-status.js +188 -0
- package/src/intercom/fork-supervisor-routing.d.ts +90 -0
- package/src/intercom/fork-supervisor-routing.js +392 -0
- package/src/intercom/intercom-bridge.d.ts +58 -0
- package/src/intercom/intercom-bridge.js +193 -0
- package/src/intercom/native-supervisor-channel.d.ts +97 -0
- package/src/intercom/native-supervisor-channel.js +1184 -0
- package/src/intercom/result-intercom.d.ts +35 -0
- package/src/intercom/result-intercom.js +376 -0
- package/src/intercom/supervisor-ui.d.ts +29 -0
- package/src/intercom/supervisor-ui.js +49 -0
- package/src/missions/actions.d.ts +54 -0
- package/src/missions/actions.js +400 -0
- package/src/missions/goal-driver.d.ts +16 -0
- package/src/missions/goal-driver.js +171 -0
- package/src/missions/lifecycle.d.ts +50 -0
- package/src/missions/lifecycle.js +388 -0
- package/src/missions/store.d.ts +21 -0
- package/src/missions/store.js +605 -0
- package/src/missions/types.d.ts +169 -0
- package/src/missions/types.js +9 -0
- package/src/missions/workflow-state.d.ts +14 -0
- package/src/missions/workflow-state.js +273 -0
- package/src/policy/authority.d.ts +9 -0
- package/src/policy/authority.js +41 -0
- package/src/profiles/profiles.d.ts +134 -0
- package/src/profiles/profiles.js +526 -0
- package/src/runs/background/active-async-capacity.d.ts +115 -0
- package/src/runs/background/active-async-capacity.js +517 -0
- package/src/runs/background/active-run-index.d.ts +12 -0
- package/src/runs/background/active-run-index.js +157 -0
- package/src/runs/background/async-execution.d.ts +304 -0
- package/src/runs/background/async-execution.js +2206 -0
- package/src/runs/background/async-job-tracker.d.ts +37 -0
- package/src/runs/background/async-job-tracker.js +921 -0
- package/src/runs/background/async-resume.d.ts +60 -0
- package/src/runs/background/async-resume.js +707 -0
- package/src/runs/background/async-retention.d.ts +45 -0
- package/src/runs/background/async-retention.js +932 -0
- package/src/runs/background/async-status-snapshot.d.ts +9 -0
- package/src/runs/background/async-status-snapshot.js +26 -0
- package/src/runs/background/async-status.d.ts +177 -0
- package/src/runs/background/async-status.js +710 -0
- package/src/runs/background/auto-drain.d.ts +16 -0
- package/src/runs/background/auto-drain.js +71 -0
- package/src/runs/background/await-async-run.d.ts +26 -0
- package/src/runs/background/await-async-run.js +83 -0
- package/src/runs/background/binary-bootstrap.d.ts +8 -0
- package/src/runs/background/binary-bootstrap.js +69 -0
- package/src/runs/background/boot-id.d.ts +12 -0
- package/src/runs/background/boot-id.js +47 -0
- package/src/runs/background/calendar-schedule.d.ts +26 -0
- package/src/runs/background/calendar-schedule.js +93 -0
- package/src/runs/background/chain-append.d.ts +34 -0
- package/src/runs/background/chain-append.js +299 -0
- package/src/runs/background/chain-root-attachment.d.ts +51 -0
- package/src/runs/background/chain-root-attachment.js +186 -0
- package/src/runs/background/completion-batcher.d.ts +51 -0
- package/src/runs/background/completion-batcher.js +119 -0
- package/src/runs/background/completion-dedupe.d.ts +13 -0
- package/src/runs/background/completion-dedupe.js +48 -0
- package/src/runs/background/completion-replay.d.ts +47 -0
- package/src/runs/background/completion-replay.js +266 -0
- package/src/runs/background/control-channel.d.ts +170 -0
- package/src/runs/background/control-channel.js +610 -0
- package/src/runs/background/fleet-view.d.ts +63 -0
- package/src/runs/background/fleet-view.js +666 -0
- package/src/runs/background/index-segment.d.ts +16 -0
- package/src/runs/background/index-segment.js +58 -0
- package/src/runs/background/inspect-rpc.d.ts +64 -0
- package/src/runs/background/inspect-rpc.js +422 -0
- package/src/runs/background/interrupted-elsewhere.d.ts +22 -0
- package/src/runs/background/interrupted-elsewhere.js +68 -0
- package/src/runs/background/notify.d.ts +214 -0
- package/src/runs/background/notify.js +1001 -0
- package/src/runs/background/owned-process-tree.d.ts +10 -0
- package/src/runs/background/owned-process-tree.js +116 -0
- package/src/runs/background/parallel-groups.d.ts +3 -0
- package/src/runs/background/parallel-groups.js +46 -0
- package/src/runs/background/pid-namespace.d.ts +2 -0
- package/src/runs/background/pid-namespace.js +19 -0
- package/src/runs/background/process-terminal-candidate.d.ts +17 -0
- package/src/runs/background/process-terminal-candidate.js +96 -0
- package/src/runs/background/process-terminal.d.ts +21 -0
- package/src/runs/background/process-terminal.js +227 -0
- package/src/runs/background/result-delivery-ownership.d.ts +14 -0
- package/src/runs/background/result-delivery-ownership.js +38 -0
- package/src/runs/background/result-files.d.ts +63 -0
- package/src/runs/background/result-files.js +629 -0
- package/src/runs/background/result-watcher.d.ts +92 -0
- package/src/runs/background/result-watcher.js +819 -0
- package/src/runs/background/resume-guidance.d.ts +4 -0
- package/src/runs/background/resume-guidance.js +57 -0
- package/src/runs/background/retained-children.d.ts +24 -0
- package/src/runs/background/retained-children.js +128 -0
- package/src/runs/background/retained-nested-route-tracker.d.ts +12 -0
- package/src/runs/background/retained-nested-route-tracker.js +90 -0
- package/src/runs/background/run-child-session.d.ts +123 -0
- package/src/runs/background/run-child-session.js +670 -0
- package/src/runs/background/run-id-query.d.ts +3 -0
- package/src/runs/background/run-id-query.js +6 -0
- package/src/runs/background/run-id-resolver.d.ts +22 -0
- package/src/runs/background/run-id-resolver.js +172 -0
- package/src/runs/background/run-status.d.ts +25 -0
- package/src/runs/background/run-status.js +850 -0
- package/src/runs/background/runner-aliases.d.ts +17 -0
- package/src/runs/background/runner-aliases.js +191 -0
- package/src/runs/background/runner-child-launch.d.ts +24 -0
- package/src/runs/background/runner-child-launch.js +72 -0
- package/src/runs/background/runner-child-sessions.d.ts +6 -0
- package/src/runs/background/runner-child-sessions.js +34 -0
- package/src/runs/background/runner-http-dispatcher.d.ts +45 -0
- package/src/runs/background/runner-http-dispatcher.js +115 -0
- package/src/runs/background/runner-startup-failure.d.ts +13 -0
- package/src/runs/background/runner-startup-failure.js +46 -0
- package/src/runs/background/scheduled-runs.d.ts +127 -0
- package/src/runs/background/scheduled-runs.js +1265 -0
- package/src/runs/background/stale-run-reconciler.d.ts +62 -0
- package/src/runs/background/stale-run-reconciler.js +509 -0
- package/src/runs/background/steering.d.ts +51 -0
- package/src/runs/background/steering.js +246 -0
- package/src/runs/background/subagent-runner-bootstrap.d.ts +13 -0
- package/src/runs/background/subagent-runner-bootstrap.js +283 -0
- package/src/runs/background/subagent-runner.d.ts +210 -0
- package/src/runs/background/subagent-runner.js +4963 -0
- package/src/runs/background/subagent-wait.d.ts +124 -0
- package/src/runs/background/subagent-wait.js +756 -0
- package/src/runs/background/terminal-run-index.d.ts +10 -0
- package/src/runs/background/terminal-run-index.js +209 -0
- package/src/runs/background/top-level-async.d.ts +7 -0
- package/src/runs/background/top-level-async.js +5 -0
- package/src/runs/background/wait-completions.d.ts +28 -0
- package/src/runs/background/wait-completions.js +264 -0
- package/src/runs/background/wait-config.d.ts +8 -0
- package/src/runs/background/wait-config.js +46 -0
- package/src/runs/background/wait-subscriptions.d.ts +26 -0
- package/src/runs/background/wait-subscriptions.js +339 -0
- package/src/runs/background/wait-tool.d.ts +6 -0
- package/src/runs/background/wait-tool.js +48 -0
- package/src/runs/background/workflow-terminal-proof.d.ts +47 -0
- package/src/runs/background/workflow-terminal-proof.js +116 -0
- package/src/runs/foreground/async-dismiss-action.d.ts +6 -0
- package/src/runs/foreground/async-dismiss-action.js +82 -0
- package/src/runs/foreground/async-steering-action.d.ts +31 -0
- package/src/runs/foreground/async-steering-action.js +294 -0
- package/src/runs/foreground/async-stop-action.d.ts +13 -0
- package/src/runs/foreground/async-stop-action.js +213 -0
- package/src/runs/foreground/command-action.d.ts +12 -0
- package/src/runs/foreground/command-action.js +38 -0
- package/src/runs/foreground/execution.d.ts +10 -0
- package/src/runs/foreground/execution.js +2322 -0
- package/src/runs/foreground/foreground-control.d.ts +24 -0
- package/src/runs/foreground/foreground-control.js +138 -0
- package/src/runs/foreground/foreground-history.d.ts +25 -0
- package/src/runs/foreground/foreground-history.js +267 -0
- package/src/runs/foreground/prompt-audit.d.ts +32 -0
- package/src/runs/foreground/prompt-audit.js +138 -0
- package/src/runs/foreground/subagent-executor.d.ts +316 -0
- package/src/runs/foreground/subagent-executor.js +7986 -0
- package/src/runs/foreground/workflow-detach-reconcile.d.ts +15 -0
- package/src/runs/foreground/workflow-detach-reconcile.js +283 -0
- package/src/runs/foreground/workflow-foreground-steering.d.ts +43 -0
- package/src/runs/foreground/workflow-foreground-steering.js +148 -0
- package/src/runs/shared/abort-recovery.d.ts +26 -0
- package/src/runs/shared/abort-recovery.js +108 -0
- package/src/runs/shared/acceptance.d.ts +144 -0
- package/src/runs/shared/acceptance.js +1616 -0
- package/src/runs/shared/agent-contract.d.ts +5 -0
- package/src/runs/shared/agent-contract.js +35 -0
- package/src/runs/shared/async-status-projection.d.ts +100 -0
- package/src/runs/shared/async-status-projection.js +566 -0
- package/src/runs/shared/background-process-options.d.ts +4 -0
- package/src/runs/shared/background-process-options.js +6 -0
- package/src/runs/shared/capability-ceiling.d.ts +58 -0
- package/src/runs/shared/capability-ceiling.js +179 -0
- package/src/runs/shared/chain-outputs.d.ts +18 -0
- package/src/runs/shared/chain-outputs.js +104 -0
- package/src/runs/shared/child-commands.d.ts +29 -0
- package/src/runs/shared/child-commands.js +254 -0
- package/src/runs/shared/child-hooks.d.ts +31 -0
- package/src/runs/shared/child-hooks.js +173 -0
- package/src/runs/shared/child-identity.d.ts +23 -0
- package/src/runs/shared/child-identity.js +40 -0
- package/src/runs/shared/child-launch-plan.d.ts +70 -0
- package/src/runs/shared/child-launch-plan.js +88 -0
- package/src/runs/shared/child-launch.d.ts +128 -0
- package/src/runs/shared/child-launch.js +262 -0
- package/src/runs/shared/child-lifecycle.d.ts +13 -0
- package/src/runs/shared/child-lifecycle.js +22 -0
- package/src/runs/shared/child-runtime-config.d.ts +111 -0
- package/src/runs/shared/child-runtime-config.js +44 -0
- package/src/runs/shared/child-session.d.ts +178 -0
- package/src/runs/shared/child-session.js +726 -0
- package/src/runs/shared/child-tool-plan.d.ts +101 -0
- package/src/runs/shared/child-tool-plan.js +430 -0
- package/src/runs/shared/claude-code-adapter.d.ts +80 -0
- package/src/runs/shared/claude-code-adapter.js +255 -0
- package/src/runs/shared/codex-exec-adapter.d.ts +25 -0
- package/src/runs/shared/codex-exec-adapter.js +127 -0
- package/src/runs/shared/context-mode.d.ts +12 -0
- package/src/runs/shared/context-mode.js +38 -0
- package/src/runs/shared/cursor-agent-adapter.d.ts +26 -0
- package/src/runs/shared/cursor-agent-adapter.js +99 -0
- package/src/runs/shared/dynamic-fanout.d.ts +49 -0
- package/src/runs/shared/dynamic-fanout.js +273 -0
- package/src/runs/shared/effective-system-prompt.d.ts +17 -0
- package/src/runs/shared/effective-system-prompt.js +23 -0
- package/src/runs/shared/extension-bindings.d.ts +25 -0
- package/src/runs/shared/extension-bindings.js +96 -0
- package/src/runs/shared/external-cli-contract.d.ts +29 -0
- package/src/runs/shared/external-cli-contract.js +145 -0
- package/src/runs/shared/external-cli-preflight.d.ts +41 -0
- package/src/runs/shared/external-cli-preflight.js +159 -0
- package/src/runs/shared/external-cli-runner.d.ts +65 -0
- package/src/runs/shared/external-cli-runner.js +425 -0
- package/src/runs/shared/external-job-bridge.d.ts +24 -0
- package/src/runs/shared/external-job-bridge.js +486 -0
- package/src/runs/shared/external-job-runner.d.ts +44 -0
- package/src/runs/shared/external-job-runner.js +352 -0
- package/src/runs/shared/fast-mode-extension.d.ts +3 -0
- package/src/runs/shared/fast-mode-extension.js +8 -0
- package/src/runs/shared/fork-placed-env.d.ts +4 -0
- package/src/runs/shared/fork-placed-env.js +13 -0
- package/src/runs/shared/git-environment.d.ts +2 -0
- package/src/runs/shared/git-environment.js +27 -0
- package/src/runs/shared/herdr-connection.d.ts +79 -0
- package/src/runs/shared/herdr-connection.js +269 -0
- package/src/runs/shared/herdr-external-adapters.d.ts +148 -0
- package/src/runs/shared/herdr-external-adapters.js +404 -0
- package/src/runs/shared/herdr-machine.d.ts +59 -0
- package/src/runs/shared/herdr-machine.js +294 -0
- package/src/runs/shared/herdr-pane-host.d.ts +88 -0
- package/src/runs/shared/herdr-pane-host.js +155 -0
- package/src/runs/shared/herdr-pi-protocol.d.ts +21 -0
- package/src/runs/shared/herdr-pi-protocol.js +57 -0
- package/src/runs/shared/herdr-placed-run.d.ts +144 -0
- package/src/runs/shared/herdr-placed-run.js +380 -0
- package/src/runs/shared/host-step-status.d.ts +33 -0
- package/src/runs/shared/host-step-status.js +244 -0
- package/src/runs/shared/lane-metadata.d.ts +23 -0
- package/src/runs/shared/lane-metadata.js +126 -0
- package/src/runs/shared/launch-cwd.d.ts +1 -0
- package/src/runs/shared/launch-cwd.js +16 -0
- package/src/runs/shared/local-machine-access.d.ts +5 -0
- package/src/runs/shared/local-machine-access.js +28 -0
- package/src/runs/shared/long-running-guard.d.ts +34 -0
- package/src/runs/shared/long-running-guard.js +256 -0
- package/src/runs/shared/mcp-config-sources.d.ts +33 -0
- package/src/runs/shared/mcp-config-sources.js +418 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +86 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.js +477 -0
- package/src/runs/shared/mcp-direct-tool-grant.d.ts +42 -0
- package/src/runs/shared/mcp-direct-tool-grant.js +159 -0
- package/src/runs/shared/model-resolution-diagnostic.d.ts +44 -0
- package/src/runs/shared/model-resolution-diagnostic.js +116 -0
- package/src/runs/shared/model-resolution.d.ts +109 -0
- package/src/runs/shared/model-resolution.js +411 -0
- package/src/runs/shared/model-scope.d.ts +68 -0
- package/src/runs/shared/model-scope.js +171 -0
- package/src/runs/shared/mutation-evidence.d.ts +18 -0
- package/src/runs/shared/mutation-evidence.js +198 -0
- package/src/runs/shared/nested-events.d.ts +135 -0
- package/src/runs/shared/nested-events.js +1090 -0
- package/src/runs/shared/nested-path.d.ts +8 -0
- package/src/runs/shared/nested-path.js +34 -0
- package/src/runs/shared/nested-render.d.ts +20 -0
- package/src/runs/shared/nested-render.js +115 -0
- package/src/runs/shared/orca-progress-tabs.d.ts +31 -0
- package/src/runs/shared/orca-progress-tabs.js +503 -0
- package/src/runs/shared/parallel-handoff.d.ts +78 -0
- package/src/runs/shared/parallel-handoff.js +783 -0
- package/src/runs/shared/parallel-utils.d.ts +177 -0
- package/src/runs/shared/parallel-utils.js +125 -0
- package/src/runs/shared/partial-output.d.ts +24 -0
- package/src/runs/shared/partial-output.js +35 -0
- package/src/runs/shared/permissions.d.ts +12 -0
- package/src/runs/shared/permissions.js +92 -0
- package/src/runs/shared/pi-spawn.d.ts +31 -0
- package/src/runs/shared/pi-spawn.js +211 -0
- package/src/runs/shared/placed-run-owner.d.ts +49 -0
- package/src/runs/shared/placed-run-owner.js +93 -0
- package/src/runs/shared/placement-host.d.ts +99 -0
- package/src/runs/shared/placement-host.js +157 -0
- package/src/runs/shared/process-signal.d.ts +15 -0
- package/src/runs/shared/process-signal.js +21 -0
- package/src/runs/shared/profile-extensions.d.ts +21 -0
- package/src/runs/shared/profile-extensions.js +122 -0
- package/src/runs/shared/profile-launch-env.d.ts +26 -0
- package/src/runs/shared/profile-launch-env.js +90 -0
- package/src/runs/shared/readonly-drain-observation.d.ts +25 -0
- package/src/runs/shared/readonly-drain-observation.js +50 -0
- package/src/runs/shared/rex-machine.d.ts +25 -0
- package/src/runs/shared/rex-machine.js +83 -0
- package/src/runs/shared/rex-pane-host.d.ts +62 -0
- package/src/runs/shared/rex-pane-host.js +327 -0
- package/src/runs/shared/run-fanout-budget.d.ts +14 -0
- package/src/runs/shared/run-fanout-budget.js +258 -0
- package/src/runs/shared/run-ownership.d.ts +3 -0
- package/src/runs/shared/run-ownership.js +8 -0
- package/src/runs/shared/runner-launcher.d.ts +11 -0
- package/src/runs/shared/runner-launcher.js +24 -0
- package/src/runs/shared/runtime-acknowledged-extensions.d.ts +7 -0
- package/src/runs/shared/runtime-acknowledged-extensions.js +44 -0
- package/src/runs/shared/sandbox-profile-guard.d.ts +23 -0
- package/src/runs/shared/sandbox-profile-guard.js +106 -0
- package/src/runs/shared/sandbox-startup-diagnostics.d.ts +21 -0
- package/src/runs/shared/sandbox-startup-diagnostics.js +51 -0
- package/src/runs/shared/session-lease.d.ts +69 -0
- package/src/runs/shared/session-lease.js +250 -0
- package/src/runs/shared/single-output.d.ts +90 -0
- package/src/runs/shared/single-output.js +349 -0
- package/src/runs/shared/spawn-budget.d.ts +20 -0
- package/src/runs/shared/spawn-budget.js +93 -0
- package/src/runs/shared/structured-output.d.ts +66 -0
- package/src/runs/shared/structured-output.js +483 -0
- package/src/runs/shared/subagent-control.d.ts +50 -0
- package/src/runs/shared/subagent-control.js +247 -0
- package/src/runs/shared/subagent-prompt-runtime.d.ts +90 -0
- package/src/runs/shared/subagent-prompt-runtime.js +776 -0
- package/src/runs/shared/tool-availability.d.ts +16 -0
- package/src/runs/shared/tool-availability.js +29 -0
- package/src/runs/shared/tool-budget.d.ts +21 -0
- package/src/runs/shared/tool-budget.js +78 -0
- package/src/runs/shared/tool-timeout.d.ts +31 -0
- package/src/runs/shared/tool-timeout.js +73 -0
- package/src/runs/shared/usage-budget.d.ts +7 -0
- package/src/runs/shared/usage-budget.js +74 -0
- package/src/runs/shared/usage-reconciliation.d.ts +8 -0
- package/src/runs/shared/usage-reconciliation.js +71 -0
- package/src/runs/shared/workflow-async-child-guidance.d.ts +3 -0
- package/src/runs/shared/workflow-async-child-guidance.js +17 -0
- package/src/runs/shared/workflow-graph.d.ts +31 -0
- package/src/runs/shared/workflow-graph.js +221 -0
- package/src/runs/shared/worktree-cleanup-apply.d.ts +36 -0
- package/src/runs/shared/worktree-cleanup-apply.js +178 -0
- package/src/runs/shared/worktree-cleanup-plan.d.ts +84 -0
- package/src/runs/shared/worktree-cleanup-plan.js +803 -0
- package/src/runs/shared/worktree-lock.d.ts +5 -0
- package/src/runs/shared/worktree-lock.js +40 -0
- package/src/runs/shared/worktree-setup-command.d.ts +38 -0
- package/src/runs/shared/worktree-setup-command.js +200 -0
- package/src/runs/shared/worktree.d.ts +181 -0
- package/src/runs/shared/worktree.js +1346 -0
- package/src/shared/accessible-dir.d.ts +11 -0
- package/src/shared/accessible-dir.js +39 -0
- package/src/shared/agent-stream-options.d.ts +5 -0
- package/src/shared/agent-stream-options.js +3 -0
- package/src/shared/artifacts.d.ts +22 -0
- package/src/shared/artifacts.js +272 -0
- package/src/shared/atomic-json.d.ts +19 -0
- package/src/shared/atomic-json.js +61 -0
- package/src/shared/capacity-resilient-json.d.ts +26 -0
- package/src/shared/capacity-resilient-json.js +86 -0
- package/src/shared/child-cache-retention.d.ts +29 -0
- package/src/shared/child-cache-retention.js +40 -0
- package/src/shared/child-session-name.d.ts +8 -0
- package/src/shared/child-session-name.js +40 -0
- package/src/shared/child-transcript.d.ts +37 -0
- package/src/shared/child-transcript.js +225 -0
- package/src/shared/completion-owner.d.ts +7 -0
- package/src/shared/completion-owner.js +13 -0
- package/src/shared/disabled-features.d.ts +93 -0
- package/src/shared/disabled-features.js +120 -0
- package/src/shared/display-text.d.ts +5 -0
- package/src/shared/display-text.js +154 -0
- package/src/shared/edit-distance.d.ts +4 -0
- package/src/shared/edit-distance.js +32 -0
- package/src/shared/extension-context.d.ts +21 -0
- package/src/shared/extension-context.js +39 -0
- package/src/shared/file-coalescer.d.ts +11 -0
- package/src/shared/file-coalescer.js +34 -0
- package/src/shared/file-lease.d.ts +10 -0
- package/src/shared/file-lease.js +106 -0
- package/src/shared/file-system-retry.d.ts +31 -0
- package/src/shared/file-system-retry.js +84 -0
- package/src/shared/fork-context.d.ts +64 -0
- package/src/shared/fork-context.js +185 -0
- package/src/shared/fork-session-cwd.d.ts +2 -0
- package/src/shared/fork-session-cwd.js +23 -0
- package/src/shared/formatters.d.ts +35 -0
- package/src/shared/formatters.js +137 -0
- package/src/shared/jsonl-writer.d.ts +20 -0
- package/src/shared/jsonl-writer.js +67 -0
- package/src/shared/launch-contract.d.ts +65 -0
- package/src/shared/launch-contract.js +145 -0
- package/src/shared/model-info.d.ts +55 -0
- package/src/shared/model-info.js +103 -0
- package/src/shared/model-response-aliases.d.ts +1 -0
- package/src/shared/model-response-aliases.js +15 -0
- package/src/shared/node-executable.d.ts +1 -0
- package/src/shared/node-executable.js +20 -0
- package/src/shared/opencode-session-headers.d.ts +12 -0
- package/src/shared/opencode-session-headers.js +26 -0
- package/src/shared/package-version.d.ts +2 -0
- package/src/shared/package-version.js +14 -0
- package/src/shared/parent-wake.d.ts +26 -0
- package/src/shared/parent-wake.js +68 -0
- package/src/shared/permission-profile.d.ts +26 -0
- package/src/shared/permission-profile.js +49 -0
- package/src/shared/prompt-resources.d.ts +5 -0
- package/src/shared/prompt-resources.js +10 -0
- package/src/shared/provider-diagnostics.d.ts +9 -0
- package/src/shared/provider-diagnostics.js +75 -0
- package/src/shared/pruned-fork.d.ts +34 -0
- package/src/shared/pruned-fork.js +434 -0
- package/src/shared/required-child-extensions.d.ts +34 -0
- package/src/shared/required-child-extensions.js +105 -0
- package/src/shared/runtime-module-path.d.ts +10 -0
- package/src/shared/runtime-module-path.js +16 -0
- package/src/shared/sandbox-profile.d.ts +12 -0
- package/src/shared/sandbox-profile.js +35 -0
- package/src/shared/session-file-trust.d.ts +1 -0
- package/src/shared/session-file-trust.js +20 -0
- package/src/shared/session-identity.d.ts +8 -0
- package/src/shared/session-identity.js +32 -0
- package/src/shared/session-succession.d.ts +4 -0
- package/src/shared/session-succession.js +24 -0
- package/src/shared/session-tokens.d.ts +2 -0
- package/src/shared/session-tokens.js +58 -0
- package/src/shared/settings-file-lease.d.ts +4 -0
- package/src/shared/settings-file-lease.js +38 -0
- package/src/shared/settings.d.ts +146 -0
- package/src/shared/settings.js +247 -0
- package/src/shared/shortcuts.d.ts +1 -0
- package/src/shared/shortcuts.js +17 -0
- package/src/shared/status-format.d.ts +9 -0
- package/src/shared/status-format.js +60 -0
- package/src/shared/thinking-ceiling.d.ts +13 -0
- package/src/shared/thinking-ceiling.js +37 -0
- package/src/shared/types.d.ts +2840 -0
- package/src/shared/types.js +276 -0
- package/src/shared/utf8.d.ts +5 -0
- package/src/shared/utf8.js +12 -0
- package/src/shared/utils.d.ts +83 -0
- package/src/shared/utils.js +612 -0
- package/src/shared/watch-strategy.d.ts +2 -0
- package/src/shared/watch-strategy.js +5 -0
- package/src/shared/workflow-child-permit.d.ts +58 -0
- package/src/shared/workflow-child-permit.js +159 -0
- package/src/slash/delegation-adapters.d.ts +154 -0
- package/src/slash/delegation-adapters.js +316 -0
- package/src/slash/delegation-json.d.ts +10 -0
- package/src/slash/delegation-json.js +117 -0
- package/src/slash/delegation-request.d.ts +12 -0
- package/src/slash/delegation-request.js +174 -0
- package/src/slash/prompt-template-bridge.d.ts +29 -0
- package/src/slash/prompt-template-bridge.js +399 -0
- package/src/slash/prompt-workflows.d.ts +21 -0
- package/src/slash/prompt-workflows.js +274 -0
- package/src/slash/selector.d.ts +47 -0
- package/src/slash/selector.js +117 -0
- package/src/slash/slash-bridge.d.ts +30 -0
- package/src/slash/slash-bridge.js +132 -0
- package/src/slash/slash-commands.d.ts +10 -0
- package/src/slash/slash-commands.js +1059 -0
- package/src/slash/slash-live-state.d.ts +21 -0
- package/src/slash/slash-live-state.js +263 -0
- package/src/slash/subagent-cost.d.ts +29 -0
- package/src/slash/subagent-cost.js +310 -0
- package/src/slash/subagents-admin.d.ts +3 -0
- package/src/slash/subagents-admin.js +481 -0
- package/src/tui/fleet-layout.d.ts +20 -0
- package/src/tui/fleet-layout.js +17 -0
- package/src/tui/fleet-native-transcript.d.ts +53 -0
- package/src/tui/fleet-native-transcript.js +339 -0
- package/src/tui/fleet-status.d.ts +92 -0
- package/src/tui/fleet-status.js +1132 -0
- package/src/tui/fleet-transcript.d.ts +64 -0
- package/src/tui/fleet-transcript.js +544 -0
- package/src/tui/fleet-viewport.d.ts +12 -0
- package/src/tui/fleet-viewport.js +35 -0
- package/src/tui/fleet.d.ts +196 -0
- package/src/tui/fleet.js +1588 -0
- package/src/tui/mouse-events.d.ts +21 -0
- package/src/tui/mouse-events.js +26 -0
- package/src/tui/render-helpers.d.ts +23 -0
- package/src/tui/render-helpers.js +100 -0
- package/src/tui/render.d.ts +66 -0
- package/src/tui/render.js +3707 -0
- package/src/tui/running-tone.d.ts +10 -0
- package/src/tui/running-tone.js +22 -0
- package/src/tui/subagent-messages.d.ts +22 -0
- package/src/tui/subagent-messages.js +270 -0
- package/src/ui-silent-marker.d.ts +20 -0
- package/src/ui-silent-marker.js +25 -0
- package/src/watchdog/change-signature.d.ts +7 -0
- package/src/watchdog/change-signature.js +243 -0
- package/src/watchdog/child-status.d.ts +53 -0
- package/src/watchdog/child-status.js +187 -0
- package/src/watchdog/diff-tool.d.ts +25 -0
- package/src/watchdog/diff-tool.js +104 -0
- package/src/watchdog/emission-guard.d.ts +36 -0
- package/src/watchdog/emission-guard.js +97 -0
- package/src/watchdog/guidance.d.ts +3 -0
- package/src/watchdog/guidance.js +19 -0
- package/src/watchdog/lsp-diagnostics.d.ts +17 -0
- package/src/watchdog/lsp-diagnostics.js +489 -0
- package/src/watchdog/model-selection.d.ts +24 -0
- package/src/watchdog/model-selection.js +167 -0
- package/src/watchdog/permission-arbiter.d.ts +20 -0
- package/src/watchdog/permission-arbiter.js +135 -0
- package/src/watchdog/register-child.d.ts +13 -0
- package/src/watchdog/register-child.js +128 -0
- package/src/watchdog/register-main.d.ts +11 -0
- package/src/watchdog/register-main.js +400 -0
- package/src/watchdog/render.d.ts +3 -0
- package/src/watchdog/render.js +33 -0
- package/src/watchdog/review.d.ts +36 -0
- package/src/watchdog/review.js +319 -0
- package/src/watchdog/rules.d.ts +21 -0
- package/src/watchdog/rules.js +58 -0
- package/src/watchdog/runtime.d.ts +195 -0
- package/src/watchdog/runtime.js +864 -0
- package/src/watchdog/scope.d.ts +14 -0
- package/src/watchdog/scope.js +44 -0
- package/src/watchdog/settings.d.ts +29 -0
- package/src/watchdog/settings.js +480 -0
- package/src/watchdog/tool-actions.d.ts +17 -0
- package/src/watchdog/tool-actions.js +150 -0
- package/src/watchdog/turn-delta.d.ts +15 -0
- package/src/watchdog/turn-delta.js +188 -0
- package/src/watchdog/types.d.ts +141 -0
- package/src/watchdog/types.js +27 -0
- package/src/watchdog/warning-format.d.ts +7 -0
- package/src/watchdog/warning-format.js +59 -0
- package/src/workflows/chat-progress.d.ts +37 -0
- package/src/workflows/chat-progress.js +129 -0
- package/src/workflows/host-command.d.ts +30 -0
- package/src/workflows/host-command.js +227 -0
- package/src/workflows/scripted-workflow.d.ts +204 -0
- package/src/workflows/scripted-workflow.js +1673 -0
- package/src/workflows/structured-workflow-scripts.d.ts +10 -0
- package/src/workflows/structured-workflow-scripts.js +179 -0
- package/src/workflows/workflow-auto-resume.d.ts +32 -0
- package/src/workflows/workflow-auto-resume.js +102 -0
- package/src/workflows/workflow-checklist.d.ts +127 -0
- package/src/workflows/workflow-checklist.js +314 -0
- package/src/workflows/workflow-child-summary.d.ts +24 -0
- package/src/workflows/workflow-child-summary.js +195 -0
- package/src/workflows/workflow-launch-record.d.ts +27 -0
- package/src/workflows/workflow-launch-record.js +48 -0
- package/src/workflows/workflow-preflight.d.ts +58 -0
- package/src/workflows/workflow-preflight.js +288 -0
- package/src/workflows/workflow-receipt.d.ts +34 -0
- package/src/workflows/workflow-receipt.js +454 -0
- package/src/workflows/workflow-resources.d.ts +55 -0
- package/src/workflows/workflow-resources.js +271 -0
- package/src/workflows/workflow-resume-claim.d.ts +82 -0
- package/src/workflows/workflow-resume-claim.js +210 -0
- package/src/workflows/workflow-resume.d.ts +56 -0
- package/src/workflows/workflow-resume.js +106 -0
- package/src/workflows/workflow-reuse.d.ts +61 -0
- package/src/workflows/workflow-reuse.js +186 -0
- package/src/workflows/workflow-revival.d.ts +33 -0
- package/src/workflows/workflow-revival.js +111 -0
- package/src/workflows/workflow-settlement.d.ts +84 -0
- package/src/workflows/workflow-settlement.js +203 -0
- package/src/workflows/workflow-stop-cause.d.ts +6 -0
- package/src/workflows/workflow-stop-cause.js +8 -0
- package/workflow-script-worker.cjs +1342 -0
- package/index.ts +0 -18
- package/node_modules/@xzzpig/pi-components/src/transcript.ts +0 -1878
- package/skills/pi-subagents/references/constraints-and-recipes.md +0 -74
- package/skills/pi-subagents/references/execution-controls.md +0 -561
- package/skills/pi-subagents/references/management-authoring-rpc.md +0 -165
- package/skills/pi-subagents/references/multi-lane-orchestration.md +0 -61
- package/skills/pi-subagents/references/review-and-validation.md +0 -73
- package/src/agents/advertised-agent-prompt.ts +0 -82
- package/src/agents/agent-eject.ts +0 -339
- package/src/agents/agent-management.ts +0 -1442
- package/src/agents/agent-memory.ts +0 -341
- package/src/agents/agent-refinements.ts +0 -624
- package/src/agents/agent-scope.ts +0 -10
- package/src/agents/agent-selection.ts +0 -25
- package/src/agents/agent-serializer.ts +0 -195
- package/src/agents/agents.ts +0 -3169
- package/src/agents/builtin-names.ts +0 -16
- package/src/agents/chain-serializer.ts +0 -285
- package/src/agents/frontmatter.ts +0 -153
- package/src/agents/global-npm-root.ts +0 -58
- package/src/agents/identity.ts +0 -30
- package/src/agents/proactive-skills.ts +0 -197
- package/src/agents/runtime-agent-events.ts +0 -70
- package/src/agents/runtime-agent-registry.ts +0 -457
- package/src/agents/runtime-discovery.ts +0 -39
- package/src/agents/skills.ts +0 -787
- package/src/api/agent-management.ts +0 -9
- package/src/api/agents.ts +0 -19
- package/src/api/background-work.ts +0 -206
- package/src/api/capability-ceiling.ts +0 -16
- package/src/api/child-tool-plan.ts +0 -5
- package/src/api/control-channel.ts +0 -4
- package/src/api/delegation.ts +0 -131
- package/src/api/external-job-provider.ts +0 -195
- package/src/api/external-runs.ts +0 -282
- package/src/api/inspectors.ts +0 -27
- package/src/api/intercom-bridge.ts +0 -3
- package/src/api/preflight.ts +0 -641
- package/src/api/project-panes.ts +0 -32
- package/src/api/required-child-extensions.ts +0 -6
- package/src/api/shared-types.ts +0 -29
- package/src/api/workflow-resources.ts +0 -6
- package/src/extension/config.ts +0 -262
- package/src/extension/context-injection.ts +0 -123
- package/src/extension/control-notices.ts +0 -53
- package/src/extension/declaration-pinning.ts +0 -164
- package/src/extension/doctor.ts +0 -284
- package/src/extension/fanout-child.ts +0 -282
- package/src/extension/herdr-pi-bridge.ts +0 -166
- package/src/extension/index.ts +0 -1185
- package/src/extension/public-execution.ts +0 -262
- package/src/extension/reply-workflow-script.ts +0 -67
- package/src/extension/rpc.ts +0 -881
- package/src/extension/schemas.ts +0 -337
- package/src/extension/steering-notices.ts +0 -35
- package/src/extension/subagent-guide.ts +0 -127
- package/src/extension/subagent-options.ts +0 -47
- package/src/extension/tool-activation.ts +0 -147
- package/src/extension/tool-description.ts +0 -193
- package/src/extension/tool-result.ts +0 -19
- package/src/extension/upgrade-notice.ts +0 -40
- package/src/inspectors/actions.ts +0 -174
- package/src/inspectors/ghostty/actions.ts +0 -74
- package/src/inspectors/ghostty/plugin.ts +0 -29
- package/src/inspectors/herdr/actions.ts +0 -155
- package/src/inspectors/herdr/client.ts +0 -130
- package/src/inspectors/herdr/focus.ts +0 -55
- package/src/inspectors/herdr/plugin.ts +0 -20
- package/src/inspectors/herdr/project-panes.ts +0 -733
- package/src/inspectors/inspector-runner.ts +0 -153
- package/src/inspectors/plugins.ts +0 -76
- package/src/inspectors/session-roots-codec.ts +0 -31
- package/src/inspectors/shell-command.ts +0 -16
- package/src/inspectors/tmux/actions.ts +0 -204
- package/src/inspectors/tmux/client.ts +0 -85
- package/src/inspectors/tmux/plugin.ts +0 -21
- package/src/inspectors/types.ts +0 -51
- package/src/integrations/herdr-status.ts +0 -385
- package/src/integrations/pi-web-session-liveness.ts +0 -73
- package/src/integrations/program-status.ts +0 -215
- package/src/intercom/intercom-bridge.ts +0 -235
- package/src/intercom/native-supervisor-channel.ts +0 -1000
- package/src/intercom/result-intercom.ts +0 -433
- package/src/intercom/supervisor-ui.ts +0 -72
- package/src/missions/actions.ts +0 -433
- package/src/missions/goal-driver.ts +0 -177
- package/src/missions/lifecycle.ts +0 -367
- package/src/missions/store.ts +0 -613
- package/src/missions/types.ts +0 -190
- package/src/missions/workflow-state.ts +0 -281
- package/src/policy/authority.ts +0 -50
- package/src/profiles/profiles.ts +0 -674
- package/src/runs/background/active-async-capacity.ts +0 -548
- package/src/runs/background/active-run-index.ts +0 -155
- package/src/runs/background/async-execution.ts +0 -2479
- package/src/runs/background/async-job-tracker.ts +0 -869
- package/src/runs/background/async-resume.ts +0 -686
- package/src/runs/background/async-retention.ts +0 -953
- package/src/runs/background/async-status-snapshot.ts +0 -46
- package/src/runs/background/async-status.ts +0 -787
- package/src/runs/background/auto-drain.ts +0 -92
- package/src/runs/background/await-async-run.ts +0 -83
- package/src/runs/background/binary-bootstrap.ts +0 -67
- package/src/runs/background/calendar-schedule.ts +0 -90
- package/src/runs/background/chain-append.ts +0 -321
- package/src/runs/background/chain-root-attachment.ts +0 -263
- package/src/runs/background/completion-batcher.ts +0 -168
- package/src/runs/background/completion-dedupe.ts +0 -58
- package/src/runs/background/completion-replay.ts +0 -287
- package/src/runs/background/control-channel.ts +0 -659
- package/src/runs/background/fleet-view.ts +0 -692
- package/src/runs/background/index-segment.ts +0 -59
- package/src/runs/background/inspect-rpc.ts +0 -443
- package/src/runs/background/notify.ts +0 -1083
- package/src/runs/background/owned-process-tree.ts +0 -131
- package/src/runs/background/parallel-groups.ts +0 -45
- package/src/runs/background/pid-namespace.ts +0 -18
- package/src/runs/background/process-terminal-candidate.ts +0 -98
- package/src/runs/background/process-terminal.ts +0 -231
- package/src/runs/background/result-delivery-ownership.ts +0 -45
- package/src/runs/background/result-files.ts +0 -634
- package/src/runs/background/result-watcher.ts +0 -842
- package/src/runs/background/resume-guidance.ts +0 -56
- package/src/runs/background/retained-children.ts +0 -136
- package/src/runs/background/retained-nested-route-tracker.ts +0 -96
- package/src/runs/background/run-child-session.ts +0 -725
- package/src/runs/background/run-id-query.ts +0 -7
- package/src/runs/background/run-id-resolver.ts +0 -183
- package/src/runs/background/run-status.ts +0 -803
- package/src/runs/background/runner-aliases.ts +0 -183
- package/src/runs/background/runner-child-launch.ts +0 -96
- package/src/runs/background/runner-child-sessions.ts +0 -32
- package/src/runs/background/runner-http-dispatcher.ts +0 -122
- package/src/runs/background/runner-startup-failure.ts +0 -56
- package/src/runs/background/scheduled-runs.ts +0 -1222
- package/src/runs/background/stale-run-reconciler.ts +0 -463
- package/src/runs/background/steering.ts +0 -260
- package/src/runs/background/subagent-runner-bootstrap.ts +0 -279
- package/src/runs/background/subagent-runner.ts +0 -5251
- package/src/runs/background/subagent-wait.ts +0 -895
- package/src/runs/background/terminal-run-index.ts +0 -183
- package/src/runs/background/top-level-async.ts +0 -14
- package/src/runs/background/wait-completions.ts +0 -262
- package/src/runs/background/wait-config.ts +0 -50
- package/src/runs/background/wait-subscriptions.ts +0 -354
- package/src/runs/background/wait-tool.ts +0 -57
- package/src/runs/background/workflow-terminal-proof.ts +0 -85
- package/src/runs/foreground/async-dismiss-action.ts +0 -86
- package/src/runs/foreground/async-steering-action.ts +0 -276
- package/src/runs/foreground/async-stop-action.ts +0 -216
- package/src/runs/foreground/command-action.ts +0 -41
- package/src/runs/foreground/execution.ts +0 -2315
- package/src/runs/foreground/foreground-control.ts +0 -157
- package/src/runs/foreground/foreground-history.ts +0 -164
- package/src/runs/foreground/prompt-audit.ts +0 -172
- package/src/runs/foreground/subagent-executor.ts +0 -8227
- package/src/runs/foreground/workflow-detach-reconcile.ts +0 -304
- package/src/runs/foreground/workflow-foreground-steering.ts +0 -169
- package/src/runs/shared/abort-recovery.ts +0 -119
- package/src/runs/shared/acceptance.ts +0 -1664
- package/src/runs/shared/agent-contract.ts +0 -38
- package/src/runs/shared/async-status-projection.ts +0 -664
- package/src/runs/shared/background-process-options.ts +0 -9
- package/src/runs/shared/capability-ceiling.ts +0 -214
- package/src/runs/shared/chain-outputs.ts +0 -116
- package/src/runs/shared/child-commands.ts +0 -229
- package/src/runs/shared/child-hooks.ts +0 -175
- package/src/runs/shared/child-identity.ts +0 -62
- package/src/runs/shared/child-launch-plan.ts +0 -163
- package/src/runs/shared/child-launch.ts +0 -389
- package/src/runs/shared/child-lifecycle.ts +0 -28
- package/src/runs/shared/child-runtime-config.ts +0 -136
- package/src/runs/shared/child-session.ts +0 -699
- package/src/runs/shared/child-tool-plan.ts +0 -599
- package/src/runs/shared/claude-code-adapter.ts +0 -288
- package/src/runs/shared/codex-exec-adapter.ts +0 -129
- package/src/runs/shared/context-mode.ts +0 -44
- package/src/runs/shared/cursor-agent-adapter.ts +0 -114
- package/src/runs/shared/dynamic-fanout.ts +0 -297
- package/src/runs/shared/effective-system-prompt.ts +0 -33
- package/src/runs/shared/extension-bindings.ts +0 -103
- package/src/runs/shared/external-cli-contract.ts +0 -177
- package/src/runs/shared/external-cli-preflight.ts +0 -190
- package/src/runs/shared/external-cli-runner.ts +0 -437
- package/src/runs/shared/external-job-bridge.ts +0 -514
- package/src/runs/shared/external-job-runner.ts +0 -389
- package/src/runs/shared/fast-mode-extension.ts +0 -10
- package/src/runs/shared/fork-command-result.ts +0 -10
- package/src/runs/shared/git-environment.ts +0 -29
- package/src/runs/shared/herdr-connection.ts +0 -134
- package/src/runs/shared/herdr-external-adapters.ts +0 -169
- package/src/runs/shared/herdr-machine.ts +0 -279
- package/src/runs/shared/herdr-pi-protocol.ts +0 -59
- package/src/runs/shared/herdr-placed-run.ts +0 -264
- package/src/runs/shared/host-step-status.ts +0 -231
- package/src/runs/shared/lane-metadata.ts +0 -126
- package/src/runs/shared/launch-cwd.ts +0 -16
- package/src/runs/shared/long-running-guard.ts +0 -221
- package/src/runs/shared/mcp-config-sources.ts +0 -426
- package/src/runs/shared/mcp-direct-tool-allowlist.ts +0 -579
- package/src/runs/shared/mcp-direct-tool-grant.ts +0 -210
- package/src/runs/shared/model-resolution-diagnostic.ts +0 -101
- package/src/runs/shared/model-resolution.ts +0 -503
- package/src/runs/shared/model-scope.ts +0 -224
- package/src/runs/shared/mutation-evidence.ts +0 -199
- package/src/runs/shared/nested-events.ts +0 -1125
- package/src/runs/shared/nested-path.ts +0 -38
- package/src/runs/shared/nested-render.ts +0 -127
- package/src/runs/shared/orca-progress-tabs.ts +0 -511
- package/src/runs/shared/parallel-handoff.ts +0 -789
- package/src/runs/shared/parallel-utils.ts +0 -292
- package/src/runs/shared/partial-output.ts +0 -48
- package/src/runs/shared/permissions.ts +0 -86
- package/src/runs/shared/pi-spawn.ts +0 -205
- package/src/runs/shared/process-signal.ts +0 -35
- package/src/runs/shared/profile-extensions.ts +0 -134
- package/src/runs/shared/profile-launch-env.ts +0 -121
- package/src/runs/shared/readonly-drain-observation.ts +0 -42
- package/src/runs/shared/run-fanout-budget.ts +0 -267
- package/src/runs/shared/run-history.ts +0 -288
- package/src/runs/shared/runner-launcher.ts +0 -25
- package/src/runs/shared/runtime-acknowledged-extensions.ts +0 -44
- package/src/runs/shared/sandbox-profile-guard.ts +0 -119
- package/src/runs/shared/sandbox-startup-diagnostics.ts +0 -54
- package/src/runs/shared/session-lease.ts +0 -293
- package/src/runs/shared/single-output.ts +0 -366
- package/src/runs/shared/spawn-budget.ts +0 -128
- package/src/runs/shared/structured-output.ts +0 -463
- package/src/runs/shared/subagent-control.ts +0 -295
- package/src/runs/shared/subagent-prompt-runtime.ts +0 -598
- package/src/runs/shared/tool-availability.ts +0 -37
- package/src/runs/shared/tool-budget.ts +0 -87
- package/src/runs/shared/tool-timeout.ts +0 -93
- package/src/runs/shared/usage-budget.ts +0 -65
- package/src/runs/shared/usage-reconciliation.ts +0 -73
- package/src/runs/shared/workflow-async-child-guidance.ts +0 -18
- package/src/runs/shared/workflow-graph.ts +0 -225
- package/src/runs/shared/worktree-cleanup-apply.ts +0 -160
- package/src/runs/shared/worktree-cleanup-plan.ts +0 -891
- package/src/runs/shared/worktree-lock.ts +0 -29
- package/src/runs/shared/worktree-setup-command.ts +0 -213
- package/src/runs/shared/worktree.ts +0 -1554
- package/src/shared/accessible-dir.ts +0 -47
- package/src/shared/agent-stream-options.ts +0 -5
- package/src/shared/artifacts.ts +0 -281
- package/src/shared/atomic-json.ts +0 -85
- package/src/shared/capacity-resilient-json.ts +0 -102
- package/src/shared/child-cache-retention.ts +0 -43
- package/src/shared/child-session-name.ts +0 -48
- package/src/shared/child-transcript.ts +0 -264
- package/src/shared/completion-owner.ts +0 -14
- package/src/shared/disabled-features.ts +0 -123
- package/src/shared/display-text.ts +0 -150
- package/src/shared/edit-distance.ts +0 -33
- package/src/shared/extension-context.ts +0 -37
- package/src/shared/file-coalescer.ts +0 -49
- package/src/shared/file-lease.ts +0 -74
- package/src/shared/file-system-retry.ts +0 -95
- package/src/shared/fork-context.ts +0 -243
- package/src/shared/fork-session-cwd.ts +0 -27
- package/src/shared/formatters.ts +0 -142
- package/src/shared/jsonl-writer.ts +0 -92
- package/src/shared/launch-contract.ts +0 -206
- package/src/shared/model-info.ts +0 -132
- package/src/shared/model-response-aliases.ts +0 -13
- package/src/shared/node-executable.ts +0 -21
- package/src/shared/opencode-session-headers.ts +0 -30
- package/src/shared/package-version.ts +0 -17
- package/src/shared/parent-wake.ts +0 -79
- package/src/shared/permission-profile.ts +0 -56
- package/src/shared/prompt-resources.ts +0 -11
- package/src/shared/pruned-fork.ts +0 -469
- package/src/shared/required-child-extensions.ts +0 -115
- package/src/shared/runtime-module-path.ts +0 -19
- package/src/shared/sandbox-profile.ts +0 -37
- package/src/shared/session-file-trust.ts +0 -19
- package/src/shared/session-identity.ts +0 -10
- package/src/shared/session-tokens.ts +0 -55
- package/src/shared/settings-file-lease.ts +0 -36
- package/src/shared/settings.ts +0 -412
- package/src/shared/shortcuts.ts +0 -13
- package/src/shared/status-format.ts +0 -55
- package/src/shared/thinking-ceiling.ts +0 -46
- package/src/shared/types.ts +0 -3105
- package/src/shared/utf8.ts +0 -11
- package/src/shared/utils.ts +0 -610
- package/src/shared/watch-strategy.ts +0 -12
- package/src/shared/workflow-child-permit.ts +0 -212
- package/src/slash/delegation-adapters.ts +0 -452
- package/src/slash/delegation-json.ts +0 -108
- package/src/slash/delegation-request.ts +0 -176
- package/src/slash/prompt-template-bridge.ts +0 -434
- package/src/slash/prompt-workflows.ts +0 -298
- package/src/slash/selector.ts +0 -147
- package/src/slash/slash-bridge.ts +0 -192
- package/src/slash/slash-commands.ts +0 -1096
- package/src/slash/slash-live-state.ts +0 -310
- package/src/slash/subagent-cost.ts +0 -317
- package/src/slash/subagents-admin.ts +0 -489
- package/src/tui/fleet-native-transcript.ts +0 -424
- package/src/tui/fleet-status.ts +0 -1139
- package/src/tui/fleet-transcript.ts +0 -591
- package/src/tui/fleet.ts +0 -1618
- package/src/tui/mouse-events.ts +0 -42
- package/src/tui/render-helpers.ts +0 -111
- package/src/tui/render.ts +0 -3824
- package/src/tui/running-tone.ts +0 -28
- package/src/tui/subagent-messages.ts +0 -305
- package/src/ui-silent-marker.ts +0 -32
- package/src/watchdog/change-signature.ts +0 -260
- package/src/watchdog/child-status.ts +0 -225
- package/src/watchdog/diff-tool.ts +0 -112
- package/src/watchdog/emission-guard.ts +0 -125
- package/src/watchdog/guidance.ts +0 -20
- package/src/watchdog/lsp-diagnostics.ts +0 -538
- package/src/watchdog/model-selection.ts +0 -187
- package/src/watchdog/permission-arbiter.ts +0 -154
- package/src/watchdog/register-child.ts +0 -136
- package/src/watchdog/register-main.ts +0 -425
- package/src/watchdog/render.ts +0 -31
- package/src/watchdog/review.ts +0 -362
- package/src/watchdog/rules.ts +0 -70
- package/src/watchdog/runtime.ts +0 -927
- package/src/watchdog/scope.ts +0 -51
- package/src/watchdog/settings.ts +0 -520
- package/src/watchdog/tool-actions.ts +0 -156
- package/src/watchdog/turn-delta.ts +0 -190
- package/src/watchdog/types.ts +0 -186
- package/src/watchdog/warning-format.ts +0 -72
- package/src/workflows/chat-progress.ts +0 -152
- package/src/workflows/host-command.ts +0 -235
- package/src/workflows/scripted-workflow.ts +0 -2733
- package/src/workflows/structured-workflow-scripts.ts +0 -177
- package/src/workflows/workflow-checklist.ts +0 -442
- package/src/workflows/workflow-child-summary.ts +0 -172
- package/src/workflows/workflow-preflight.ts +0 -297
- package/src/workflows/workflow-receipt.ts +0 -390
- package/src/workflows/workflow-resources.ts +0 -275
- package/src/workflows/workflow-reuse.ts +0 -120
- package/src/workflows/workflow-revival.ts +0 -123
- package/src/workflows/workflow-settlement.ts +0 -252
|
@@ -0,0 +1,1673 @@
|
|
|
1
|
+
import { accessSync, constants, readFileSync, realpathSync, statSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { dirname, resolve as resolvePath } from "node:path";
|
|
4
|
+
import { Worker } from "node:worker_threads";
|
|
5
|
+
import { DEFAULT_GLOBAL_CONCURRENCY_LIMIT, Semaphore } from "../runs/shared/parallel-utils.js";
|
|
6
|
+
import { HOST_STEP_MAX_COUNT } from "../runs/shared/host-step-status.js";
|
|
7
|
+
import { describeGateAcceptanceConflict, parseGateInput } from "../runs/shared/acceptance.js";
|
|
8
|
+
import { normalizeWorkflowHostCommandParams } from "./host-command.js";
|
|
9
|
+
const KEY_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
10
|
+
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.";
|
|
11
|
+
function validGitRef(ref) {
|
|
12
|
+
if (typeof ref !== "string" || !ref || ref === "@" || Buffer.byteLength(ref, "utf-8") > 1024 || ref.startsWith("/") || ref.endsWith("/") || ref.includes("//") || ref.includes("..") || ref.includes("@{"))
|
|
13
|
+
return false;
|
|
14
|
+
if (/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/iu.test(ref))
|
|
15
|
+
return false;
|
|
16
|
+
if (/[[\]\\~^:?*\u0000-\u0020\u007f]/u.test(ref) || ref.endsWith(".") || ref.endsWith(".lock"))
|
|
17
|
+
return false;
|
|
18
|
+
return ref.split("/").every((component) => component.length > 0 && component !== "." && component !== ".." && !component.startsWith(".") && !component.endsWith(".") && !component.endsWith(".lock"));
|
|
19
|
+
}
|
|
20
|
+
const requireFromPackage = createRequire(import.meta.url);
|
|
21
|
+
const WORKFLOW_ASSEMBLY_FLUSH_TIMEOUT_MS = 5_000;
|
|
22
|
+
const WORKFLOW_WORKER_URL = new URL("../../workflow-script-worker.cjs", import.meta.url);
|
|
23
|
+
let nodeWorkerSource;
|
|
24
|
+
function isWorkflowScriptFailureKind(value) {
|
|
25
|
+
return value === "validation" || value === "script" || value === "child" || value === "return-serialization" || value === "timeout" || value === "detached-child" || value === "runtime";
|
|
26
|
+
}
|
|
27
|
+
function taggedWorkflowError(message, kind) {
|
|
28
|
+
return Object.assign(new Error(message), { workflowErrorKind: kind });
|
|
29
|
+
}
|
|
30
|
+
export class WorkflowScriptError extends Error {
|
|
31
|
+
partial;
|
|
32
|
+
errorKind;
|
|
33
|
+
constructor(message, partial, errorKind, options) {
|
|
34
|
+
super(message, options);
|
|
35
|
+
this.name = "WorkflowScriptError";
|
|
36
|
+
this.partial = partial;
|
|
37
|
+
this.errorKind = errorKind;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function combinedAbortSignal(signals) {
|
|
41
|
+
const controller = new AbortController();
|
|
42
|
+
const abort = (signal) => {
|
|
43
|
+
if (controller.signal.aborted)
|
|
44
|
+
return;
|
|
45
|
+
controller.abort(signal.reason);
|
|
46
|
+
};
|
|
47
|
+
for (const signal of signals) {
|
|
48
|
+
if (signal.aborted) {
|
|
49
|
+
abort(signal);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
signal.addEventListener("abort", () => abort(signal), { once: true });
|
|
53
|
+
}
|
|
54
|
+
return controller.signal;
|
|
55
|
+
}
|
|
56
|
+
function isRecord(value) {
|
|
57
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
58
|
+
}
|
|
59
|
+
function isAcceptanceMetadataRecovery(result) {
|
|
60
|
+
return !result.ok
|
|
61
|
+
&& result.recovery?.status === "available-for-review"
|
|
62
|
+
&& result.recovery.reason === "acceptance-metadata-rejected";
|
|
63
|
+
}
|
|
64
|
+
const RECOVERY_REVIEW_MUTATION_VERB_PATTERN = /\b(?:add(?:ing)?|append(?:ing)?|apply(?:ing)?|cherry[ -]pick(?:ing)?|change|changing|clean(?:ing)?|commit(?:ting)?|cop(?:y|ying)|create|creating|delete|deleting|edit(?:ing)?|fix(?:ing)?|implement(?:ing)?|insert(?:ing)?|make|making|merge|merging|mov(?:e|ing)|modify(?:ing)?|mutate|mutating|open(?:ing)?|patch(?:ing)?|prepend(?:ing)?|push(?:ing)?|rebase|rebasing|refactor(?:ing)?|remove|removing|rename|renaming|replace|replacing|revert(?:ing)?|revise|revising|rewrite|rewriting|sav(?:e|ing)|stag(?:e|ing)|stash(?:ing)?|tag(?:ging)?|touch(?:ing)?|update|updating|write|writing)\b/i;
|
|
65
|
+
const RECOVERY_REVIEW_READ_ONLY_PATTERN = /\b(?:read[- ]only|review only|only return findings|return findings only|suggest fixes only|without\s+(?:editing|modifying|changing|writing|touching)|do not\s+(?:edit|modify|change|write|touch)|don't\s+(?:edit|modify|change|write|touch)|must not\s+(?:edit|modify|change|write|touch))\b/i;
|
|
66
|
+
const RECOVERY_REVIEW_NO_MUTATION_CLAUSE_PATTERN = /\b(?:do not|don't|must not)\s+(?:edit|modify|change|write|touch)(?:\s+files?)?(?:\s*,\s*(?:commit|push|comment|merge|launch(?:\s+subagents?)?)(?=\s*(?:,|\bor\b|[.;!?\n)]|$)))*(?:\s*,?\s*or\s+(?:commit|push|comment|merge|launch(?:\s+subagents?)?)(?=\s*(?:[.;!?\n)]|$)))?/gi;
|
|
67
|
+
const RECOVERY_REVIEW_DELIVERABLE_PATTERN = /\b(?:compose|create|draft|prepare|produce|write)\s+(?:(?:a|an|the|your)\s+)?(?:findings?|review|report|summary|analysis|recommendations?)(?:\s+(?:to|at|in)\s+\S+)?/gi;
|
|
68
|
+
const RECOVERY_REVIEW_CONTEXT_OBJECT_PATTERN = /\breview\s+(?:(?:the|this|that|saved)\s+)?(?:patch|diff|changes?|implementation|report)\b/gi;
|
|
69
|
+
const RECOVERY_REVIEW_MUTATION_NOUN_CONTEXT_PATTERN = /\b(?:later\s+real\s+)?update\s+imperatives?\b/gi;
|
|
70
|
+
const RECOVERY_REVIEW_PRIOR_FIX_CONTEXT_PATTERN = /\bthe\s+prior\s+fix\s+keeps\b/gi;
|
|
71
|
+
const RECOVERY_REVIEW_DETECTION_CONTEXT_PATTERN = /\b(?:mutation\s+detection\s+now\s+includes\s+move\/rename\/copy\s+file\s+mutation\s+imperatives|delegation\s+detection\s+now\s+blocks\s+get\/let\/have\/tell\/ask\s+follow-up\s+forms)(?=[,.;!?\n]|\b(?:and|but|then|however|nevertheless|nonetheless|yet)\b|$)/gi;
|
|
72
|
+
const RECOVERY_REVIEW_PATTERN_CHANGE_CONTEXT_PATTERN = /\bRECOVERY_REVIEW_MUTATION_VERB_PATTERN\s+now\s+includes\s+append,\s+prepend,\s+and\s+sav(?:e|ing)\b(?=\s*(?:[,.;!?\n)]|$))/gi;
|
|
73
|
+
const RECOVERY_REVIEW_GIT_PATTERN_CHANGE_CONTEXT_PATTERN = /\bfixed\s+mutating\s+git\s+follow-up\s+bypasses\b|\b(?:added|adding)\s+[a-z][a-z-]*(?:\/[a-z][a-z-]*)*(?:(?:\s*,\s*(?:and\s+)?|\s+and\s+)[a-z][a-z-]*(?:\/[a-z][a-z-]*)*)*\s+to\s+the\s+(?:mutation\s+imperative|mutating\s+git\s+command)\s+pattern\b|\band\s+[a-z][a-z-]*(?:\/[a-z][a-z-]*)*(?:(?:\s*,\s*(?:and\s+)?|\s+and\s+)[a-z][a-z-]*(?:\/[a-z][a-z-]*)*)*\s+to\s+the\s+mutating\s+git\s+command\s+pattern\b/gi;
|
|
74
|
+
const RECOVERY_REVIEW_VALIDATION_EVIDENCE_PATTERN = /\bvalidation(?:\s+after\s+fix)?\s*:/gi;
|
|
75
|
+
const RECOVERY_REVIEW_CONTRACT_PROHIBITION_PATTERN = /\b(?:do not|don't|must not)\s+(?:mutate\s+durable\s+state|launch\s+(?:mutating|destructive|mutating\/destructive)\s+work)(?:\s+or\s+(?:mutate\s+durable\s+state|launch\s+(?:mutating|destructive|mutating\/destructive)\s+work))*/gi;
|
|
76
|
+
const RECOVERY_REVIEW_ONLY_REVIEW_CONTRACT_PATTERN = /\bmay\s+only\s+launch\s+explicit\s+read-only\s+review\s+children\s+with\s+acceptance:false\b/gi;
|
|
77
|
+
const RECOVERY_REVIEW_BLOCKED_CONTEXT_FRAGMENT_PATTERN = /\bstate\.set, runs\.host, runs\.steer, ordinary\/mutating children, and destructive command wording are blocked(?=[,.;!?\n)\]}]|$)/gi;
|
|
78
|
+
const RECOVERY_REVIEW_REGRESSION_EVIDENCE_PATTERN = /\b(?:existing regressions cover plain rm and git clean\/reset\/restore|prior regressions covering rm\/git clean as evidence only)(?=[,.;!?\n)\]}]|$)/gi;
|
|
79
|
+
const RECOVERY_REVIEW_BLOCKED_QUOTED_EXAMPLE_PATTERN = /(?:`[^`\n]+`|'[^'\n]+'|"[^"\n]+")(?:(?:\s*,\s*(?:and\s+)?|\s+and\s+)(?:`[^`\n]+`|'[^'\n]+'|"[^"\n]+"))*\s+(?:is|are|remains?)\s+(?:blocked|(?:an?\s+)?blocked\s+examples?)(?=[,.;!?\n)\]}]|$)/gi;
|
|
80
|
+
const RECOVERY_REVIEW_CONTEXT_QUOTED_EXAMPLE_PATTERN = /\b(?:examples?|phrasing|forms|variants):\s*(?:`[^`\n]+`|'[^'\n]+'|"[^"\n]+")(?:(?:\s*,\s*(?:and\s+)?|\s+and\s+)(?:`[^`\n]+`|'[^'\n]+'|"[^"\n]+"))*/gi;
|
|
81
|
+
const RECOVERY_REVIEW_LISTED_BLOCKED_EXAMPLE_PATTERN = /(?:^|[.;!?\n]\s*)blocked\s+examples:\s*(?:\r?\n[ \t]*(?:[-*]|\d+[.)])\s+[^\r\n]+)+/gim;
|
|
82
|
+
const RECOVERY_REVIEW_BLOCKS_QUOTED_EXAMPLE_PATTERN = /\b(?:this\s+)?blocks?\s+examples?\s+like\s+(?:`[^`\n]+`|'[^'\n]+'|"[^"\n]+")(?:(?:\s*,\s*(?:and\s+)?|\s+and\s+)(?:`[^`\n]+`|'[^'\n]+'|"[^"\n]+"))*/gi;
|
|
83
|
+
const RECOVERY_REVIEW_EXAMPLES_LIKE_BLOCKED_PATTERN = /\bexamples?\s+like\s+(?:`[^`\n]+`|'[^'\n]+'|"[^"\n]+")(?:(?:\s*,\s*(?:and\s+)?|\s+and\s+)(?:`[^`\n]+`|'[^'\n]+'|"[^"\n]+"))*\s+(?:is|are|remains?)\s+blocked\b/gi;
|
|
84
|
+
const RECOVERY_REVIEW_QUOTED_VISIBLE_BLOCKED_PATTERN = /(?:\b(?:(?:the\s+)?examples?|commands?\s+hidden\s+in)\s+|(?:^|[\s([{]))(?:`[^`\n]+`|'[^'\n]+'|"[^"\n]+")(?:(?:\s*,\s*(?:and\s+|or\s+)?|\s+(?:and|or)\s+)(?:`[^`\n]+`|'[^'\n]+'|"[^"\n]+"))*\s+(?:(?:is|are|remains?)\s+)?visible\s+and\s+blocked\b/gi;
|
|
85
|
+
const RECOVERY_REVIEW_PROMPTS_LIKE_BLOCKED_PATTERN = /\bdescribed\s+prompts?\s+like\s+Run\s+git\s+rebase\s+main,\s+git\s+rebase\s+main,\s+Run\s+git\s+cherry-pick\s+abc123,\s+cherry-pick\s+abc123,\s+and\s+Stage\s+the\s+changed\s+files\s+as\s+blocked\b/gi;
|
|
86
|
+
const RECOVERY_REVIEW_GIT_MUTATIONS_BROADER_CONTEXT_PATTERN = /\bpositive\s+git\s+mutations\s+are\s+broader:\s*git\s+branch\s+-D\s+old,\s+git\s+tag\s+-d\s+v1\.0,\s+git\s+stash,\s+git\s+revert\s+abc123,\s+and\s+natural\s+cherry\s+pick\s+abc123\s+now\s+trips?\s+the\s+recovery\s+barrier\b/gi;
|
|
87
|
+
const RECOVERY_REVIEW_GIT_COVERAGE_CONTEXT_PATTERN = /\bbroadened\s+positive\s+git\s+mutation\s+coverage\s+for\s+natural\s+`cherry\s+pick`,\s+`revert`,\s+`stash`,\s+`tag`,\s+plus\s+git\s+`branch\|revert\|stash\|tag`/gi;
|
|
88
|
+
const RECOVERY_REVIEW_REGRESSION_QUOTED_EXAMPLE_PATTERN = /\b(?:added\s+)?exact\s+regressions?\s+for\s+(?:`[^`\n]+`|'[^'\n]+'|"[^"\n]+")(?:(?:\s*,\s*(?:and\s+)?|\s+and\s+)(?:`[^`\n]+`|'[^'\n]+'|"[^"\n]+"))*/gi;
|
|
89
|
+
const RECOVERY_REVIEW_REGRESSION_ANAPHORIC_EXAMPLE_PATTERN = /\b(?:added\s+)?exact\s+regressions?\s+for\s+(?:do|run|execute|perform|apply)\s+(?:it|that|this|(?:the\s+)?(?:(?:previous(?:ly)?|prior|above|quoted|blocked)\s+){0,4}(?:command|example|operation|action|phrase|instruction|request))(?:[\s,]+(?:now|still|again|really|actually|immediately)){0,3}[\s,]+anyway(?:(?:\s*,\s*(?:and\s+)?|\s+and\s+)(?:do|run|execute|perform|apply)\s+(?:it|that|this|(?:the\s+)?(?:(?:previous(?:ly)?|prior|above|quoted|blocked)\s+){0,4}(?:command|example|operation|action|phrase|instruction|request))(?:[\s,]+(?:now|still|again|really|actually|immediately)){0,3}[\s,]+anyway)*/gi;
|
|
90
|
+
const RECOVERY_REVIEW_REGRESSION_FOLLOWED_BY_ANAPHORIC_PATTERN = /\badded\s+(?:exact\s+)?regressions?\s+for\s+quoted\s+rm\s+remaining\s+blocked\s+followed\s+by\s+execute\s+the\s+previous\s+command\b(?=\s*(?:[,.;!?\n)]|\bwhile\b|$))/gi;
|
|
91
|
+
const RECOVERY_REVIEW_REGRESSION_FOLLOWED_BY_NAMED_RM_PATTERN = /\b(?:added\s+)?(?:exact\s+)?regressions?\s+for\s+quoted\s+rm\s+remaining\s+blocked\s+followed\s+by\s+(?:do|run|execute|perform|apply)\s+(?:it|that|this|(?:the\s+)?(?:(?:previous(?:ly)?|prior|above|quoted|blocked)\s+){0,4}(?:command|example|operation|action|phrase|instruction|request))(?:[\s,]+(?:now|still|again|really|actually|immediately)){0,3}(?:[\s,]+anyway)?(?=\s*(?:[,.;!?\n)]|\bwhile\b|$))/gi;
|
|
92
|
+
const RECOVERY_REVIEW_BLOCKED_LIVE_VARIANT_CONTEXT_PATTERN = /\b(?:while\s+)?keeping\s+live-command\s+variants\s+such\s+as\s+followed\s+by\s+execute\s+the\s+previous\s+command\s+then\s+update\s+tests\s+blocked\b(?=\s*(?:[,.;!?\n)]|$))/gi;
|
|
93
|
+
const RECOVERY_REVIEW_ANAPHORIC_REFERENCES_CONTEXT_PATTERN = /\bdirect\s+anaphoric\s+references\s+now\s+include\s+numeric\s+and\s+word\s+ordinals\s+through\s+tenth\s+plus\s+one,\s+so\s+(?: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,]+(?:right|now|still|again|really|actually|immediately)){0,4}[\s,]+anyway(?:(?:\s*,\s*(?:and\s+)?|\s+and\s+)(?: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,]+(?:right|now|still|again|really|actually|immediately)){0,4}[\s,]+anyway)*\s+(?:is|are|remains?)\s+blocked\b(?:\s+after\s+quoted\s+destructive\s+examples\s+are\s+scrubbed)?/gi;
|
|
94
|
+
const RECOVERY_REVIEW_NO_ANAPHORIC_MUTATION_CLAUSE_PATTERN = /\b(?:do not|don't|must not)\s+(?: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))(?:(?!\b(?:and|but|then|however|nevertheless|nonetheless|yet)\b)[^,.;!?\n—–-]){0,80}/gi;
|
|
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
|
+
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
|
+
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
|
+
const RECOVERY_REVIEW_DESTRUCTIVE_COMMAND_PATTERN = /(?:^|[\s;,.`'"([{])(?:\S*\/)?(?:rm|rmdir|unlink|truncate|mv|cp|chmod|chown)\b|\bgit\b(?:\s+(?:-[A-Za-z](?:\s+(?:"[^"\n]*"|'[^'\n]*'|\S+))?|--(?:git-dir|work-tree|namespace|exec-path|config-env)(?:=(?:"[^"\n]*"|'[^'\n]*'|\S+)|\s+(?:"[^"\n]*"|'[^'\n]*'|\S+))|--[A-Za-z0-9-]+(?:=(?:"[^"\n]*"|'[^'\n]*'|\S+))?))*\s+(?:add|branch|cherry-pick|clean|commit|merge|rebase|reset|restore|revert|stash|tag|checkout|switch)\b/i;
|
|
99
|
+
const RECOVERY_REVIEW_DASH_LIVE_ACTION_PATTERN = /(?:[—–]|--|\s-\s|:|\s\/\s)\s*(?:then\s+)?(?:(?: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|(?:launch|start|spawn|run)\b[^,.;!?\n]*(?:workers?|reviewers?|agents?|subagents?|children|child|runs?)\b|(?:\S*\/)?(?:rm|rmdir|unlink|truncate|mv|cp|chmod|chown)\b|git\b[^,.;!?\n]*\b(?:add|branch|cherry-pick|clean|commit|merge|rebase|reset|restore|revert|stash|tag|checkout|switch)\b)/i;
|
|
100
|
+
function isExplicitReadOnlyRecoveryReview(params) {
|
|
101
|
+
const agent = typeof params.agent === "string" ? params.agent.trim() : "";
|
|
102
|
+
const task = typeof params.task === "string" ? params.task.trim() : "";
|
|
103
|
+
const taskDestructiveCommandText = task
|
|
104
|
+
.replace(RECOVERY_REVIEW_BLOCKED_CONTEXT_FRAGMENT_PATTERN, " ")
|
|
105
|
+
.replace(RECOVERY_REVIEW_REGRESSION_EVIDENCE_PATTERN, " ")
|
|
106
|
+
.replace(RECOVERY_REVIEW_BLOCKED_QUOTED_EXAMPLE_PATTERN, " ")
|
|
107
|
+
.replace(RECOVERY_REVIEW_CONTEXT_QUOTED_EXAMPLE_PATTERN, " ")
|
|
108
|
+
.replace(RECOVERY_REVIEW_LISTED_BLOCKED_EXAMPLE_PATTERN, " ")
|
|
109
|
+
.replace(RECOVERY_REVIEW_BLOCKS_QUOTED_EXAMPLE_PATTERN, " ")
|
|
110
|
+
.replace(RECOVERY_REVIEW_EXAMPLES_LIKE_BLOCKED_PATTERN, " ")
|
|
111
|
+
.replace(RECOVERY_REVIEW_QUOTED_VISIBLE_BLOCKED_PATTERN, " ")
|
|
112
|
+
.replace(RECOVERY_REVIEW_PROMPTS_LIKE_BLOCKED_PATTERN, " ")
|
|
113
|
+
.replace(RECOVERY_REVIEW_GIT_MUTATIONS_BROADER_CONTEXT_PATTERN, " ")
|
|
114
|
+
.replace(RECOVERY_REVIEW_GIT_COVERAGE_CONTEXT_PATTERN, " ")
|
|
115
|
+
.replace(RECOVERY_REVIEW_REGRESSION_FOLLOWED_BY_NAMED_RM_PATTERN, " ");
|
|
116
|
+
const taskDashLiveActionText = task
|
|
117
|
+
.replace(RECOVERY_REVIEW_DELIVERABLE_PATTERN, " ")
|
|
118
|
+
.replace(RECOVERY_REVIEW_CONTEXT_OBJECT_PATTERN, " ")
|
|
119
|
+
.replace(RECOVERY_REVIEW_MUTATION_NOUN_CONTEXT_PATTERN, " ")
|
|
120
|
+
.replace(RECOVERY_REVIEW_PRIOR_FIX_CONTEXT_PATTERN, " ")
|
|
121
|
+
.replace(RECOVERY_REVIEW_DETECTION_CONTEXT_PATTERN, " ")
|
|
122
|
+
.replace(RECOVERY_REVIEW_PATTERN_CHANGE_CONTEXT_PATTERN, " ")
|
|
123
|
+
.replace(RECOVERY_REVIEW_GIT_PATTERN_CHANGE_CONTEXT_PATTERN, " ")
|
|
124
|
+
.replace(RECOVERY_REVIEW_VALIDATION_EVIDENCE_PATTERN, " ")
|
|
125
|
+
.replace(RECOVERY_REVIEW_CONTRACT_PROHIBITION_PATTERN, " ")
|
|
126
|
+
.replace(RECOVERY_REVIEW_ONLY_REVIEW_CONTRACT_PATTERN, " ")
|
|
127
|
+
.replace(RECOVERY_REVIEW_BLOCKED_QUOTED_EXAMPLE_PATTERN, " ")
|
|
128
|
+
.replace(RECOVERY_REVIEW_CONTEXT_QUOTED_EXAMPLE_PATTERN, " ")
|
|
129
|
+
.replace(RECOVERY_REVIEW_LISTED_BLOCKED_EXAMPLE_PATTERN, " ")
|
|
130
|
+
.replace(RECOVERY_REVIEW_BLOCKS_QUOTED_EXAMPLE_PATTERN, " ")
|
|
131
|
+
.replace(RECOVERY_REVIEW_EXAMPLES_LIKE_BLOCKED_PATTERN, " ")
|
|
132
|
+
.replace(RECOVERY_REVIEW_QUOTED_VISIBLE_BLOCKED_PATTERN, " ")
|
|
133
|
+
.replace(RECOVERY_REVIEW_PROMPTS_LIKE_BLOCKED_PATTERN, " ")
|
|
134
|
+
.replace(RECOVERY_REVIEW_GIT_MUTATIONS_BROADER_CONTEXT_PATTERN, " ")
|
|
135
|
+
.replace(RECOVERY_REVIEW_GIT_COVERAGE_CONTEXT_PATTERN, " ")
|
|
136
|
+
.replace(RECOVERY_REVIEW_REGRESSION_QUOTED_EXAMPLE_PATTERN, " ")
|
|
137
|
+
.replace(RECOVERY_REVIEW_REGRESSION_ANAPHORIC_EXAMPLE_PATTERN, " ")
|
|
138
|
+
.replace(RECOVERY_REVIEW_REGRESSION_FOLLOWED_BY_ANAPHORIC_PATTERN, " ")
|
|
139
|
+
.replace(RECOVERY_REVIEW_BLOCKED_LIVE_VARIANT_CONTEXT_PATTERN, " ")
|
|
140
|
+
.replace(RECOVERY_REVIEW_ANAPHORIC_REFERENCES_CONTEXT_PATTERN, " ");
|
|
141
|
+
const taskMutationText = task
|
|
142
|
+
.replace(RECOVERY_REVIEW_DELIVERABLE_PATTERN, " ")
|
|
143
|
+
.replace(RECOVERY_REVIEW_CONTEXT_OBJECT_PATTERN, " ")
|
|
144
|
+
.replace(RECOVERY_REVIEW_MUTATION_NOUN_CONTEXT_PATTERN, " ")
|
|
145
|
+
.replace(RECOVERY_REVIEW_PRIOR_FIX_CONTEXT_PATTERN, " ")
|
|
146
|
+
.replace(RECOVERY_REVIEW_DETECTION_CONTEXT_PATTERN, " ")
|
|
147
|
+
.replace(RECOVERY_REVIEW_PATTERN_CHANGE_CONTEXT_PATTERN, " ")
|
|
148
|
+
.replace(RECOVERY_REVIEW_GIT_PATTERN_CHANGE_CONTEXT_PATTERN, " ")
|
|
149
|
+
.replace(RECOVERY_REVIEW_VALIDATION_EVIDENCE_PATTERN, " ")
|
|
150
|
+
.replace(RECOVERY_REVIEW_CONTRACT_PROHIBITION_PATTERN, " ")
|
|
151
|
+
.replace(RECOVERY_REVIEW_ONLY_REVIEW_CONTRACT_PATTERN, " ")
|
|
152
|
+
.replace(RECOVERY_REVIEW_BLOCKED_CONTEXT_FRAGMENT_PATTERN, " ")
|
|
153
|
+
.replace(RECOVERY_REVIEW_REGRESSION_EVIDENCE_PATTERN, " ")
|
|
154
|
+
.replace(RECOVERY_REVIEW_BLOCKED_QUOTED_EXAMPLE_PATTERN, " ")
|
|
155
|
+
.replace(RECOVERY_REVIEW_CONTEXT_QUOTED_EXAMPLE_PATTERN, " ")
|
|
156
|
+
.replace(RECOVERY_REVIEW_LISTED_BLOCKED_EXAMPLE_PATTERN, " ")
|
|
157
|
+
.replace(RECOVERY_REVIEW_BLOCKS_QUOTED_EXAMPLE_PATTERN, " ")
|
|
158
|
+
.replace(RECOVERY_REVIEW_EXAMPLES_LIKE_BLOCKED_PATTERN, " ")
|
|
159
|
+
.replace(RECOVERY_REVIEW_QUOTED_VISIBLE_BLOCKED_PATTERN, " ")
|
|
160
|
+
.replace(RECOVERY_REVIEW_PROMPTS_LIKE_BLOCKED_PATTERN, " ")
|
|
161
|
+
.replace(RECOVERY_REVIEW_GIT_MUTATIONS_BROADER_CONTEXT_PATTERN, " ")
|
|
162
|
+
.replace(RECOVERY_REVIEW_GIT_COVERAGE_CONTEXT_PATTERN, " ")
|
|
163
|
+
.replace(RECOVERY_REVIEW_REGRESSION_QUOTED_EXAMPLE_PATTERN, " ")
|
|
164
|
+
.replace(RECOVERY_REVIEW_REGRESSION_ANAPHORIC_EXAMPLE_PATTERN, " ")
|
|
165
|
+
.replace(RECOVERY_REVIEW_REGRESSION_FOLLOWED_BY_ANAPHORIC_PATTERN, " ")
|
|
166
|
+
.replace(RECOVERY_REVIEW_BLOCKED_LIVE_VARIANT_CONTEXT_PATTERN, " ")
|
|
167
|
+
.replace(RECOVERY_REVIEW_ANAPHORIC_REFERENCES_CONTEXT_PATTERN, " ")
|
|
168
|
+
.replace(RECOVERY_REVIEW_NO_ANAPHORIC_MUTATION_CLAUSE_PATTERN, " ")
|
|
169
|
+
.replace(RECOVERY_REVIEW_NO_DELEGATION_CLAUSE_PATTERN, " ")
|
|
170
|
+
.replace(RECOVERY_REVIEW_NO_MUTATION_CLAUSE_PATTERN, " ")
|
|
171
|
+
.replace(new RegExp(RECOVERY_REVIEW_READ_ONLY_PATTERN.source, "gi"), " ");
|
|
172
|
+
return params.acceptance === false
|
|
173
|
+
&& agent !== ""
|
|
174
|
+
&& /\b(?:advisor|oracle|review|reviewer)\b/i.test(agent)
|
|
175
|
+
&& RECOVERY_REVIEW_READ_ONLY_PATTERN.test(task)
|
|
176
|
+
&& !RECOVERY_REVIEW_DESTRUCTIVE_COMMAND_PATTERN.test(taskDestructiveCommandText)
|
|
177
|
+
&& !RECOVERY_REVIEW_MUTATION_VERB_PATTERN.test(taskMutationText)
|
|
178
|
+
&& !RECOVERY_REVIEW_DELEGATION_PATTERN.test(taskMutationText)
|
|
179
|
+
&& !RECOVERY_REVIEW_ANAPHORIC_MUTATION_PATTERN.test(taskMutationText)
|
|
180
|
+
&& !RECOVERY_REVIEW_DESTRUCTIVE_COMMAND_PATTERN.test(taskMutationText)
|
|
181
|
+
&& !RECOVERY_REVIEW_DASH_LIVE_ACTION_PATTERN.test(taskDashLiveActionText);
|
|
182
|
+
}
|
|
183
|
+
function recoveryBarrierMessage(sourceKey, target) {
|
|
184
|
+
return `Run '${target}' cannot launch after run '${sourceKey}' returned rejected acceptance recovery; only explicit read-only review children with acceptance:false may follow.`;
|
|
185
|
+
}
|
|
186
|
+
function isPlainJsonObject(value) {
|
|
187
|
+
if (!isRecord(value))
|
|
188
|
+
return false;
|
|
189
|
+
const prototype = Object.getPrototypeOf(value);
|
|
190
|
+
return prototype === null || prototype === Object.prototype;
|
|
191
|
+
}
|
|
192
|
+
function parseWorkflowResumeReference(value) {
|
|
193
|
+
if (!isRecord(value))
|
|
194
|
+
return undefined;
|
|
195
|
+
const fields = Object.keys(value);
|
|
196
|
+
if (fields.some((field) => field !== "workflowRunId" && field !== "key" && field !== "latest"))
|
|
197
|
+
throw new Error("keyed resume contains unsupported fields.");
|
|
198
|
+
if (typeof value.workflowRunId !== "string" || !value.workflowRunId.trim())
|
|
199
|
+
throw new Error("keyed resume workflowRunId must be non-empty.");
|
|
200
|
+
const key = validateKey(value.key, "keyed resume");
|
|
201
|
+
if (value.latest !== true)
|
|
202
|
+
throw new Error("keyed resume requires latest: true.");
|
|
203
|
+
return { workflowRunId: value.workflowRunId.trim(), key, latest: true };
|
|
204
|
+
}
|
|
205
|
+
function omitUndefinedWorkflowValues(value, seen = new Set()) {
|
|
206
|
+
if (value === null || typeof value !== "object")
|
|
207
|
+
return value;
|
|
208
|
+
if (seen.has(value))
|
|
209
|
+
return value;
|
|
210
|
+
seen.add(value);
|
|
211
|
+
const normalized = Array.isArray(value)
|
|
212
|
+
? value.map((entry) => entry === undefined ? null : omitUndefinedWorkflowValues(entry, seen))
|
|
213
|
+
: isPlainJsonObject(value)
|
|
214
|
+
? Object.fromEntries(Object.entries(value).flatMap(([key, entry]) => entry === undefined ? [] : [[key, omitUndefinedWorkflowValues(entry, seen)]]))
|
|
215
|
+
: value;
|
|
216
|
+
seen.delete(value);
|
|
217
|
+
return normalized;
|
|
218
|
+
}
|
|
219
|
+
function omitNonJsonWorkflowResultMetadata(value) {
|
|
220
|
+
const normalized = omitUndefinedWorkflowValues(value);
|
|
221
|
+
if (!isPlainJsonObject(normalized) || !Object.hasOwn(normalized, "results"))
|
|
222
|
+
return normalized;
|
|
223
|
+
try {
|
|
224
|
+
assertWorkflowJsonValue(normalized.results, "runs.run result.results");
|
|
225
|
+
return normalized;
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
const { results: _results, ...safeResult } = normalized;
|
|
229
|
+
return safeResult;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
export function assertWorkflowJsonValue(value, path = "value", seen = new Set()) {
|
|
233
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
234
|
+
return;
|
|
235
|
+
if (typeof value === "number") {
|
|
236
|
+
if (!Number.isFinite(value))
|
|
237
|
+
throw new Error(`${path} must contain only finite JSON numbers.`);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (typeof value !== "object")
|
|
241
|
+
throw new Error(`${path} must be a JSON value; received ${typeof value}.`);
|
|
242
|
+
if (seen.has(value))
|
|
243
|
+
throw new Error(`${path} must not contain cycles.`);
|
|
244
|
+
seen.add(value);
|
|
245
|
+
if (Array.isArray(value)) {
|
|
246
|
+
for (let index = 0; index < value.length; index++) {
|
|
247
|
+
if (!Object.hasOwn(value, index))
|
|
248
|
+
throw new Error(`${path} must not contain sparse array entries.`);
|
|
249
|
+
assertWorkflowJsonValue(value[index], `${path}[${index}]`, seen);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
const prototype = Object.getPrototypeOf(value);
|
|
254
|
+
if (prototype !== null && prototype !== Object.prototype)
|
|
255
|
+
throw new Error(`${path} must contain only plain JSON objects.`);
|
|
256
|
+
if (Object.getOwnPropertySymbols(value).length > 0)
|
|
257
|
+
throw new Error(`${path} must not contain symbol keys.`);
|
|
258
|
+
for (const [key, entry] of Object.entries(value))
|
|
259
|
+
assertWorkflowJsonValue(entry, `${path}.${key}`, seen);
|
|
260
|
+
}
|
|
261
|
+
seen.delete(value);
|
|
262
|
+
}
|
|
263
|
+
export function formatWorkflowJsonPreview(value, maxLength) {
|
|
264
|
+
try {
|
|
265
|
+
assertWorkflowJsonValue(value);
|
|
266
|
+
const serialized = JSON.stringify(value);
|
|
267
|
+
if (typeof serialized !== "string")
|
|
268
|
+
return undefined;
|
|
269
|
+
// Serialized JSON never ends in "…", so the suffix always means the preview was cut.
|
|
270
|
+
return serialized.length > maxLength ? `${serialized.slice(0, maxLength)}…` : serialized;
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
return undefined;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function workflowReturnRecoveryHint(children) {
|
|
277
|
+
if (children.length === 0)
|
|
278
|
+
return " Return only plain JSON data. For a child result, select fields such as { runId: child.runId, ok: child.ok, outputReference: child.outputReference }.";
|
|
279
|
+
const references = children.slice(0, 10).map((child) => {
|
|
280
|
+
const fields = [child.runId ? `runId=${child.runId.slice(0, 500)}` : undefined, child.outputReference ? `outputReference=${child.outputReference.slice(0, 500)}` : undefined, child.artifactPaths[0] ? `artifact=${child.artifactPaths[0].slice(0, 500)}` : undefined].filter((field) => field !== undefined);
|
|
281
|
+
return `'${child.key}'${fields.length > 0 ? ` (${fields.join(", ")})` : ""}`;
|
|
282
|
+
});
|
|
283
|
+
return ` ${children.some((child) => child.state === "running") ? "Child calls returned before return serialization failed; launch receipts do not prove completion." : "Child work completed before return serialization failed."} Recover outputs from: ${references.join(", ")}${children.length > references.length ? `, and ${children.length - references.length} more` : ""}. Return a plain projection such as { runId: child.runId, ok: child.ok, outputReference: child.outputReference }.`;
|
|
284
|
+
}
|
|
285
|
+
/** Display-only preview for the exact simple `return runs.run(key, {...})` form. */
|
|
286
|
+
export function previewSimpleWorkflowRun(script) {
|
|
287
|
+
const body = script?.match(/^\s*return\s+(?:await\s+)?runs\.run\s*\(\s*(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`[^`$\\]*`)\s*,\s*\{([\s\S]*)\}\s*\)\s*;?\s*$/)?.[1];
|
|
288
|
+
if (body === undefined)
|
|
289
|
+
return undefined;
|
|
290
|
+
const readProperty = (name) => {
|
|
291
|
+
const match = body.match(new RegExp(`(?:^|,)\\s*(?:${name}|["']${name}["'])\\s*:\\s*("(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*'|\u0060[^\u0060$\\\\]*\u0060)`));
|
|
292
|
+
if (!match?.[1])
|
|
293
|
+
return undefined;
|
|
294
|
+
const literal = match[1];
|
|
295
|
+
if (literal.startsWith('"')) {
|
|
296
|
+
try {
|
|
297
|
+
return JSON.parse(literal);
|
|
298
|
+
}
|
|
299
|
+
catch {
|
|
300
|
+
return undefined;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (literal.slice(1, -1).includes("\\"))
|
|
304
|
+
return undefined;
|
|
305
|
+
return literal.slice(1, -1);
|
|
306
|
+
};
|
|
307
|
+
const agent = readProperty("agent");
|
|
308
|
+
const task = readProperty("task");
|
|
309
|
+
return { ...(agent !== undefined ? { agent } : {}), ...(task !== undefined ? { task } : {}) };
|
|
310
|
+
}
|
|
311
|
+
function stableJson(value) {
|
|
312
|
+
if (Array.isArray(value))
|
|
313
|
+
return `[${value.map(stableJson).join(",")}]`;
|
|
314
|
+
if (isRecord(value))
|
|
315
|
+
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stableJson(value[key])}`).join(",")}}`;
|
|
316
|
+
return JSON.stringify(value) ?? "undefined";
|
|
317
|
+
}
|
|
318
|
+
function canonicalRunParams(params) {
|
|
319
|
+
if (params.gate === undefined || params.acceptance !== false)
|
|
320
|
+
return params;
|
|
321
|
+
const { acceptance: _acceptance, ...withoutAcceptance } = params;
|
|
322
|
+
return withoutAcceptance;
|
|
323
|
+
}
|
|
324
|
+
/** Canonical launch-params identity; matches the worker's stableRunJson(canonicalRunParams(params)). */
|
|
325
|
+
export function workflowRunParamsFingerprint(params) {
|
|
326
|
+
return stableJson(canonicalRunParams(params));
|
|
327
|
+
}
|
|
328
|
+
function validateKey(value, owner = "runs.run") {
|
|
329
|
+
if (typeof value !== "string" || !KEY_PATTERN.test(value)) {
|
|
330
|
+
throw new Error(`${owner} key must be 1-128 characters using letters, numbers, '.', '_' or '-', and start with a letter or number.`);
|
|
331
|
+
}
|
|
332
|
+
return value;
|
|
333
|
+
}
|
|
334
|
+
const AST_LOCATION_KEYS = new Set(["type", "start", "end", "loc", "range"]);
|
|
335
|
+
function astNode(value) {
|
|
336
|
+
return Boolean(value) && typeof value === "object" && typeof value.type === "string";
|
|
337
|
+
}
|
|
338
|
+
function literalString(node) {
|
|
339
|
+
if (!astNode(node))
|
|
340
|
+
return undefined;
|
|
341
|
+
if (node.type === "Literal" && typeof node.value === "string")
|
|
342
|
+
return node.value;
|
|
343
|
+
if (node.type === "TemplateLiteral" && Array.isArray(node.expressions) && node.expressions.length === 0 && Array.isArray(node.quasis)) {
|
|
344
|
+
const first = node.quasis[0];
|
|
345
|
+
if (typeof first?.value?.cooked === "string")
|
|
346
|
+
return first.value.cooked;
|
|
347
|
+
}
|
|
348
|
+
return undefined;
|
|
349
|
+
}
|
|
350
|
+
function directRunsCall(node, method) {
|
|
351
|
+
if (!astNode(node) || node.type !== "CallExpression" || !astNode(node.callee) || node.callee.type !== "MemberExpression")
|
|
352
|
+
return false;
|
|
353
|
+
const property = node.callee.computed === true ? literalString(node.callee.property) : astNode(node.callee.property) && node.callee.property.type === "Identifier" ? node.callee.property.name : undefined;
|
|
354
|
+
return property === method && astNode(node.callee.object) && node.callee.object.type === "Identifier" && node.callee.object.name === "runs";
|
|
355
|
+
}
|
|
356
|
+
function validateStaticHostCall(call) {
|
|
357
|
+
const args = Array.isArray(call.arguments) ? call.arguments : [];
|
|
358
|
+
const keyNode = astNode(args[0]) ? args[0] : undefined;
|
|
359
|
+
const params = astNode(args[1]) ? args[1] : undefined;
|
|
360
|
+
const errors = [];
|
|
361
|
+
const key = literalString(keyNode);
|
|
362
|
+
if (keyNode && key !== undefined && !KEY_PATTERN.test(key))
|
|
363
|
+
errors.push({ message: "runs.host key must be 1-128 characters using letters, numbers, '.', '_' or '-', and start with a letter or number.", ...nodeLocation(keyNode) });
|
|
364
|
+
if (!params || params.type !== "ObjectExpression" || !Array.isArray(params.properties) || params.properties.some((property) => !astNode(property) || property.type !== "Property"))
|
|
365
|
+
return errors;
|
|
366
|
+
const allowed = new Set(["kind", "command", "timeoutMs", "output", "role", "provider"]);
|
|
367
|
+
for (const property of params.properties) {
|
|
368
|
+
if (!astNode(property))
|
|
369
|
+
continue;
|
|
370
|
+
const name = staticPropertyKey(property);
|
|
371
|
+
if (name !== undefined && !allowed.has(name))
|
|
372
|
+
errors.push({ message: name === "cwd" ? "runs.host params contain unsupported field 'cwd'. The host step does not accept per-step cwd; commands and relative output paths use the workflow cwd. Set cwd on the outer subagent request, or put a trusted directory change in command (for example, 'cd /path/to/worktree && npm test')." : `runs.host params contain unsupported field '${name}'.`, ...nodeLocation(property) });
|
|
373
|
+
}
|
|
374
|
+
const kindNode = directObjectPropertyValue(params, "kind");
|
|
375
|
+
const commandNode = directObjectPropertyValue(params, "command");
|
|
376
|
+
const timeoutNode = directObjectPropertyValue(params, "timeoutMs");
|
|
377
|
+
const kind = literalString(kindNode);
|
|
378
|
+
const command = literalString(commandNode);
|
|
379
|
+
const timeout = astNode(timeoutNode) && timeoutNode.type === "Literal" ? timeoutNode.value : undefined;
|
|
380
|
+
if (!kindNode)
|
|
381
|
+
errors.push({ message: "runs.host params require kind: 'command'.", ...nodeLocation(params) });
|
|
382
|
+
else if (kind !== undefined && kind !== "command")
|
|
383
|
+
errors.push({ message: "runs.host params kind must be 'command'.", ...nodeLocation(kindNode) });
|
|
384
|
+
if (!commandNode)
|
|
385
|
+
errors.push({ message: "runs.host params require command.", ...nodeLocation(params) });
|
|
386
|
+
else if (command !== undefined && !command.trim())
|
|
387
|
+
errors.push({ message: "runs.host params command must be non-empty.", ...nodeLocation(commandNode) });
|
|
388
|
+
if (!timeoutNode)
|
|
389
|
+
errors.push({ message: "runs.host params require timeoutMs.", ...nodeLocation(params) });
|
|
390
|
+
else if (typeof timeout === "number" && (!Number.isInteger(timeout) || timeout < 1))
|
|
391
|
+
errors.push({ message: "runs.host params timeoutMs must be a positive integer.", ...nodeLocation(timeoutNode) });
|
|
392
|
+
const outputNode = directObjectPropertyValue(params, "output");
|
|
393
|
+
const output = literalString(outputNode);
|
|
394
|
+
if (outputNode && output !== undefined && (!output.trim() || /^[/\\]|(?:^|[/\\])\.\.(?:[/\\]|$)/.test(output)))
|
|
395
|
+
errors.push({ message: "runs.host params output must be a non-empty relative path without traversal.", ...nodeLocation(outputNode) });
|
|
396
|
+
const roleNode = directObjectPropertyValue(params, "role");
|
|
397
|
+
const role = literalString(roleNode);
|
|
398
|
+
if (roleNode && role !== undefined && role !== "ci" && role !== "gate")
|
|
399
|
+
errors.push({ message: "runs.host params role must be 'ci' or 'gate'.", ...nodeLocation(roleNode) });
|
|
400
|
+
return errors;
|
|
401
|
+
}
|
|
402
|
+
function nodeLocation(node) {
|
|
403
|
+
return node.loc ? { line: Math.max(1, node.loc.start.line - 1), column: node.loc.start.column + 1 } : {};
|
|
404
|
+
}
|
|
405
|
+
function walkAst(node, visit, includeNestedFunctions = true) {
|
|
406
|
+
if (Array.isArray(node)) {
|
|
407
|
+
for (const item of node)
|
|
408
|
+
walkAst(item, visit, includeNestedFunctions);
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
if (!astNode(node))
|
|
412
|
+
return;
|
|
413
|
+
visit(node);
|
|
414
|
+
if (!includeNestedFunctions && (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression"))
|
|
415
|
+
return;
|
|
416
|
+
for (const [key, child] of Object.entries(node)) {
|
|
417
|
+
if (!AST_LOCATION_KEYS.has(key))
|
|
418
|
+
walkAst(child, visit, includeNestedFunctions);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
function bindingPatternContainsName(node, name) {
|
|
422
|
+
if (!astNode(node))
|
|
423
|
+
return false;
|
|
424
|
+
if (node.type === "Identifier")
|
|
425
|
+
return node.name === name;
|
|
426
|
+
if (node.type === "RestElement")
|
|
427
|
+
return bindingPatternContainsName(node.argument, name);
|
|
428
|
+
if (node.type === "AssignmentPattern")
|
|
429
|
+
return bindingPatternContainsName(node.left, name);
|
|
430
|
+
if (node.type === "ArrayPattern" && Array.isArray(node.elements))
|
|
431
|
+
return node.elements.some((element) => bindingPatternContainsName(element, name));
|
|
432
|
+
if (node.type === "ObjectPattern" && Array.isArray(node.properties))
|
|
433
|
+
return node.properties.some((property) => {
|
|
434
|
+
if (!astNode(property))
|
|
435
|
+
return false;
|
|
436
|
+
return property.type === "RestElement"
|
|
437
|
+
? bindingPatternContainsName(property.argument, name)
|
|
438
|
+
: property.type === "Property" && bindingPatternContainsName(property.value, name);
|
|
439
|
+
});
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
function definitelyReassignsBinding(node, name) {
|
|
443
|
+
let assignment = node;
|
|
444
|
+
while (astNode(assignment) && assignment.type === "AssignmentExpression" && assignment.operator !== "&&=" && assignment.operator !== "||=" && assignment.operator !== "??=") {
|
|
445
|
+
if (bindingPatternContainsName(assignment.left, name))
|
|
446
|
+
return true;
|
|
447
|
+
assignment = assignment.right;
|
|
448
|
+
}
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
function lexicalDeclarationContainsName(node, name) {
|
|
452
|
+
if (!astNode(node))
|
|
453
|
+
return false;
|
|
454
|
+
if (node.type === "VariableDeclaration" && node.kind !== "var" && Array.isArray(node.declarations)) {
|
|
455
|
+
return node.declarations.some((declaration) => astNode(declaration) && bindingPatternContainsName(declaration.id, name));
|
|
456
|
+
}
|
|
457
|
+
return (node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") && bindingPatternContainsName(node.id, name);
|
|
458
|
+
}
|
|
459
|
+
function scopeShadowsIdentifier(node, name) {
|
|
460
|
+
if (node.type === "BlockStatement" && Array.isArray(node.body))
|
|
461
|
+
return node.body.some((statement) => lexicalDeclarationContainsName(statement, name));
|
|
462
|
+
if (node.type === "CatchClause")
|
|
463
|
+
return bindingPatternContainsName(node.param, name);
|
|
464
|
+
if (node.type === "ForStatement")
|
|
465
|
+
return lexicalDeclarationContainsName(node.init, name);
|
|
466
|
+
if (node.type === "ForInStatement" || node.type === "ForOfStatement")
|
|
467
|
+
return lexicalDeclarationContainsName(node.left, name);
|
|
468
|
+
if (node.type === "SwitchStatement" && Array.isArray(node.cases)) {
|
|
469
|
+
return node.cases.some((entry) => astNode(entry) && Array.isArray(entry.consequent) && entry.consequent.some((statement) => lexicalDeclarationContainsName(statement, name)));
|
|
470
|
+
}
|
|
471
|
+
return false;
|
|
472
|
+
}
|
|
473
|
+
function walkAstWithoutShadowedIdentifier(node, name, visit) {
|
|
474
|
+
if (Array.isArray(node)) {
|
|
475
|
+
for (const item of node)
|
|
476
|
+
walkAstWithoutShadowedIdentifier(item, name, visit);
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
if (!astNode(node) || scopeShadowsIdentifier(node, name))
|
|
480
|
+
return;
|
|
481
|
+
visit(node);
|
|
482
|
+
if (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression")
|
|
483
|
+
return;
|
|
484
|
+
for (const [key, child] of Object.entries(node)) {
|
|
485
|
+
if (!AST_LOCATION_KEYS.has(key))
|
|
486
|
+
walkAstWithoutShadowedIdentifier(child, name, visit);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
function definitelyNonJson(node, normalizeUndefined = false) {
|
|
490
|
+
if (node.type === "Literal") {
|
|
491
|
+
if (typeof node.bigint === "string")
|
|
492
|
+
return "BigInt values are not JSON-representable";
|
|
493
|
+
if (node.regex !== undefined)
|
|
494
|
+
return "regular expressions are not JSON-representable";
|
|
495
|
+
return undefined;
|
|
496
|
+
}
|
|
497
|
+
if (node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression")
|
|
498
|
+
return "functions are not JSON-representable";
|
|
499
|
+
if (node.type === "Identifier" && node.name === "undefined")
|
|
500
|
+
return normalizeUndefined ? undefined : "undefined is not JSON-representable";
|
|
501
|
+
if (node.type === "UnaryExpression" && node.operator === "void")
|
|
502
|
+
return normalizeUndefined ? undefined : "undefined is not JSON-representable";
|
|
503
|
+
if (node.type === "ArrayExpression" && Array.isArray(node.elements)) {
|
|
504
|
+
if (node.elements.some((entry) => entry === null))
|
|
505
|
+
return "sparse arrays are not JSON-representable";
|
|
506
|
+
for (const entry of node.elements)
|
|
507
|
+
if (astNode(entry)) {
|
|
508
|
+
const error = definitelyNonJson(entry, normalizeUndefined);
|
|
509
|
+
if (error)
|
|
510
|
+
return error;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
if (node.type === "ObjectExpression" && Array.isArray(node.properties)) {
|
|
514
|
+
const values = new Map();
|
|
515
|
+
for (const property of node.properties) {
|
|
516
|
+
if (!astNode(property) || property.type !== "Property" || !astNode(property.value) || property.kind !== "init")
|
|
517
|
+
return undefined;
|
|
518
|
+
const key = staticPropertyKey(property);
|
|
519
|
+
if (key === undefined)
|
|
520
|
+
return undefined;
|
|
521
|
+
values.set(key, property.value);
|
|
522
|
+
}
|
|
523
|
+
for (const value of values.values()) {
|
|
524
|
+
const error = definitelyNonJson(value, normalizeUndefined);
|
|
525
|
+
if (error)
|
|
526
|
+
return error;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return undefined;
|
|
530
|
+
}
|
|
531
|
+
function staticPropertyKey(property) {
|
|
532
|
+
return property.computed === true
|
|
533
|
+
? literalString(property.key)
|
|
534
|
+
: literalString(property.key) ?? (astNode(property.key) && property.key.type === "Identifier" ? property.key.name : undefined);
|
|
535
|
+
}
|
|
536
|
+
function directObjectPropertyValue(node, name) {
|
|
537
|
+
if (node.type !== "ObjectExpression" || !Array.isArray(node.properties))
|
|
538
|
+
return undefined;
|
|
539
|
+
let value;
|
|
540
|
+
for (const property of node.properties) {
|
|
541
|
+
if (!astNode(property) || property.type !== "Property" || !astNode(property.value))
|
|
542
|
+
continue;
|
|
543
|
+
if (staticPropertyKey(property) === name)
|
|
544
|
+
value = property.value;
|
|
545
|
+
}
|
|
546
|
+
return value;
|
|
547
|
+
}
|
|
548
|
+
function validateStaticBaseRef(params, owner) {
|
|
549
|
+
if (params.type !== "ObjectExpression" || !Array.isArray(params.properties))
|
|
550
|
+
return [];
|
|
551
|
+
// Inspect the final definition only. A later spread or unknown key may overwrite it.
|
|
552
|
+
for (let index = params.properties.length - 1; index >= 0; index--) {
|
|
553
|
+
const property = params.properties[index];
|
|
554
|
+
if (!astNode(property) || property.type !== "Property")
|
|
555
|
+
return [];
|
|
556
|
+
const key = staticPropertyKey(property);
|
|
557
|
+
if (key === undefined)
|
|
558
|
+
return [];
|
|
559
|
+
if (key !== "baseRef")
|
|
560
|
+
continue;
|
|
561
|
+
if (property.kind !== "init" || !astNode(property.value))
|
|
562
|
+
return [];
|
|
563
|
+
const valueNode = property.value;
|
|
564
|
+
const value = literalString(valueNode);
|
|
565
|
+
if ((value !== undefined || valueNode.type === "Literal") && !validGitRef(value)) {
|
|
566
|
+
return [{ message: `${owner} ${BASE_REF_VALIDATION_ERROR}`, ...nodeLocation(valueNode) }];
|
|
567
|
+
}
|
|
568
|
+
return [];
|
|
569
|
+
}
|
|
570
|
+
return [];
|
|
571
|
+
}
|
|
572
|
+
// Children with their own cwd, agentScope, or resume resolve agents elsewhere, and a
|
|
573
|
+
// spread or computed key can replace `agent`; leave those to launch-time resolution.
|
|
574
|
+
function staticChildAgentNode(params) {
|
|
575
|
+
if (!astNode(params) || params.type !== "ObjectExpression" || !Array.isArray(params.properties))
|
|
576
|
+
return undefined;
|
|
577
|
+
let agent;
|
|
578
|
+
for (const property of params.properties) {
|
|
579
|
+
if (!astNode(property) || property.type !== "Property")
|
|
580
|
+
return undefined;
|
|
581
|
+
const key = staticPropertyKey(property);
|
|
582
|
+
if (key === undefined || key === "cwd" || key === "agentScope" || key === "resume")
|
|
583
|
+
return undefined;
|
|
584
|
+
if (key === "agent")
|
|
585
|
+
agent = property.kind === "init" && astNode(property.value) ? property.value : undefined;
|
|
586
|
+
}
|
|
587
|
+
return literalString(agent) === undefined ? undefined : agent;
|
|
588
|
+
}
|
|
589
|
+
function validateStaticChildAgents(call, agentNameError) {
|
|
590
|
+
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
|
+
const children = directRunsCall(call, "run")
|
|
596
|
+
? [{ owner: "runs.run", params: args[1] }]
|
|
597
|
+
: directRunsCall(call, "all")
|
|
598
|
+
? elements(args[0]).map((params) => ({ owner: "runs.all item", params }))
|
|
599
|
+
: directRunsCall(call, "lanes")
|
|
600
|
+
? elements(args[0]).flatMap((lane) => staticLane(lane) ? elements(directObjectPropertyValue(lane, "stages")).map((params) => ({ owner: "runs.lanes stage", params })) : [])
|
|
601
|
+
: [];
|
|
602
|
+
const errors = [];
|
|
603
|
+
for (const child of children) {
|
|
604
|
+
const agentNode = staticChildAgentNode(child.params);
|
|
605
|
+
const agentName = literalString(agentNode);
|
|
606
|
+
const error = agentName === undefined ? undefined : agentNameError(agentName);
|
|
607
|
+
if (agentNode && error)
|
|
608
|
+
errors.push({ kind: "agent", message: `${child.owner}: ${error}`, ...nodeLocation(agentNode) });
|
|
609
|
+
}
|
|
610
|
+
return errors;
|
|
611
|
+
}
|
|
612
|
+
function directRunsAllKeys(call) {
|
|
613
|
+
const args = Array.isArray(call.arguments) ? call.arguments : [];
|
|
614
|
+
const items = astNode(args[0]) && args[0].type === "ArrayExpression" && Array.isArray(args[0].elements) ? args[0].elements : [];
|
|
615
|
+
return items.flatMap((item) => {
|
|
616
|
+
if (!astNode(item))
|
|
617
|
+
return [];
|
|
618
|
+
const keyNode = directObjectPropertyValue(item, "key");
|
|
619
|
+
const key = literalString(keyNode);
|
|
620
|
+
return keyNode && key !== undefined ? [{ key, node: keyNode }] : [];
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
function containsWorkflowLaunch(node) {
|
|
624
|
+
let found = false;
|
|
625
|
+
walkAst(node, (candidate) => {
|
|
626
|
+
if (directRunsCall(candidate, "run") || directRunsCall(candidate, "all") || directRunsCall(candidate, "lanes"))
|
|
627
|
+
found = true;
|
|
628
|
+
});
|
|
629
|
+
return found;
|
|
630
|
+
}
|
|
631
|
+
function containsRunsIdentifier(node) {
|
|
632
|
+
let found = false;
|
|
633
|
+
walkAst(node, (candidate) => {
|
|
634
|
+
if (candidate.type === "Identifier" && candidate.name === "runs")
|
|
635
|
+
found = true;
|
|
636
|
+
});
|
|
637
|
+
return found;
|
|
638
|
+
}
|
|
639
|
+
function invalidatesRunsBinding(workflowBody) {
|
|
640
|
+
let invalidated = false;
|
|
641
|
+
walkAst(workflowBody, (node) => {
|
|
642
|
+
if ((node.type === "VariableDeclarator" || node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ClassDeclaration" || node.type === "ClassExpression")
|
|
643
|
+
&& containsRunsIdentifier(node.id))
|
|
644
|
+
invalidated = true;
|
|
645
|
+
if ((node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") && Array.isArray(node.params)
|
|
646
|
+
&& node.params.some(containsRunsIdentifier))
|
|
647
|
+
invalidated = true;
|
|
648
|
+
if (node.type === "CatchClause" && containsRunsIdentifier(node.param))
|
|
649
|
+
invalidated = true;
|
|
650
|
+
if ((node.type === "AssignmentExpression" || node.type === "UpdateExpression") && containsRunsIdentifier(node.left ?? node.argument))
|
|
651
|
+
invalidated = true;
|
|
652
|
+
});
|
|
653
|
+
return invalidated;
|
|
654
|
+
}
|
|
655
|
+
function containsAbruptControl(node) {
|
|
656
|
+
let found = false;
|
|
657
|
+
walkAst(node, (candidate) => {
|
|
658
|
+
if (candidate !== node && (candidate.type === "ReturnStatement" || candidate.type === "ThrowStatement" || candidate.type === "BreakStatement" || candidate.type === "ContinueStatement"))
|
|
659
|
+
found = true;
|
|
660
|
+
}, false);
|
|
661
|
+
return found;
|
|
662
|
+
}
|
|
663
|
+
function directLaunchCall(expression) {
|
|
664
|
+
if (!astNode(expression))
|
|
665
|
+
return undefined;
|
|
666
|
+
const candidate = expression.type === "AwaitExpression" && astNode(expression.argument) ? expression.argument : expression;
|
|
667
|
+
return directRunsCall(candidate, "run") || directRunsCall(candidate, "all") ? candidate : undefined;
|
|
668
|
+
}
|
|
669
|
+
function staticWorkflowLaunchPlan(workflowBody) {
|
|
670
|
+
if (workflowBody.type !== "BlockStatement" || !Array.isArray(workflowBody.body) || invalidatesRunsBinding(workflowBody)) {
|
|
671
|
+
return { keys: [], dynamic: containsWorkflowLaunch(workflowBody) };
|
|
672
|
+
}
|
|
673
|
+
const keys = new Set();
|
|
674
|
+
let dynamic = false;
|
|
675
|
+
let remainderUncertain = false;
|
|
676
|
+
const addCall = (call) => {
|
|
677
|
+
const args = Array.isArray(call.arguments) ? call.arguments : [];
|
|
678
|
+
let nestedLaunch = false;
|
|
679
|
+
for (const argument of args)
|
|
680
|
+
walkAst(argument, (node) => {
|
|
681
|
+
if (node !== call && (directRunsCall(node, "run") || directRunsCall(node, "all") || directRunsCall(node, "lanes")))
|
|
682
|
+
nestedLaunch = true;
|
|
683
|
+
});
|
|
684
|
+
if (nestedLaunch) {
|
|
685
|
+
dynamic = true;
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
if (directRunsCall(call, "run")) {
|
|
689
|
+
const key = literalString(args[0]);
|
|
690
|
+
if (key === undefined)
|
|
691
|
+
dynamic = true;
|
|
692
|
+
else
|
|
693
|
+
keys.add(key);
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
const array = astNode(args[0]) && args[0].type === "ArrayExpression" && Array.isArray(args[0].elements) ? args[0] : undefined;
|
|
697
|
+
if (!array) {
|
|
698
|
+
dynamic = true;
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
const batchKeys = [];
|
|
702
|
+
for (const item of array.elements) {
|
|
703
|
+
if (!astNode(item) || item.type !== "ObjectExpression" || !Array.isArray(item.properties)
|
|
704
|
+
|| item.properties.some((property) => !astNode(property) || property.type !== "Property" || staticPropertyKey(property) === undefined)) {
|
|
705
|
+
dynamic = true;
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
const key = literalString(directObjectPropertyValue(item, "key"));
|
|
709
|
+
if (key === undefined) {
|
|
710
|
+
dynamic = true;
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
batchKeys.push(key);
|
|
714
|
+
}
|
|
715
|
+
for (const key of batchKeys)
|
|
716
|
+
keys.add(key);
|
|
717
|
+
};
|
|
718
|
+
for (const statement of workflowBody.body) {
|
|
719
|
+
if (!astNode(statement))
|
|
720
|
+
continue;
|
|
721
|
+
if (remainderUncertain) {
|
|
722
|
+
if (containsWorkflowLaunch(statement))
|
|
723
|
+
dynamic = true;
|
|
724
|
+
continue;
|
|
725
|
+
}
|
|
726
|
+
const expressions = [];
|
|
727
|
+
if (statement.type === "VariableDeclaration" && Array.isArray(statement.declarations)) {
|
|
728
|
+
for (const declaration of statement.declarations)
|
|
729
|
+
if (astNode(declaration))
|
|
730
|
+
expressions.push(declaration.init);
|
|
731
|
+
}
|
|
732
|
+
else if (statement.type === "ExpressionStatement")
|
|
733
|
+
expressions.push(statement.expression);
|
|
734
|
+
else if (statement.type === "ReturnStatement" || statement.type === "ThrowStatement")
|
|
735
|
+
expressions.push(statement.argument);
|
|
736
|
+
let handledLaunch = false;
|
|
737
|
+
for (const expression of expressions) {
|
|
738
|
+
const call = directLaunchCall(expression);
|
|
739
|
+
if (call) {
|
|
740
|
+
addCall(call);
|
|
741
|
+
handledLaunch = true;
|
|
742
|
+
}
|
|
743
|
+
else if (containsWorkflowLaunch(expression))
|
|
744
|
+
dynamic = true;
|
|
745
|
+
}
|
|
746
|
+
if (!handledLaunch && expressions.length === 0 && containsWorkflowLaunch(statement))
|
|
747
|
+
dynamic = true;
|
|
748
|
+
if (statement.type === "ReturnStatement" || statement.type === "ThrowStatement")
|
|
749
|
+
remainderUncertain = true;
|
|
750
|
+
else if (containsAbruptControl(statement))
|
|
751
|
+
remainderUncertain = true;
|
|
752
|
+
}
|
|
753
|
+
return { keys: [...keys], dynamic };
|
|
754
|
+
}
|
|
755
|
+
/** Parse a workflowScript and apply only rules that are decidable from its local syntax. */
|
|
756
|
+
export function validateWorkflowScript(script, options = {}) {
|
|
757
|
+
const errors = [];
|
|
758
|
+
if (!script.trim())
|
|
759
|
+
return { ok: false, errors: [{ message: "workflowScript must not be empty." }] };
|
|
760
|
+
let root;
|
|
761
|
+
try {
|
|
762
|
+
const parser = requireFromPackage(resolveWorkflowParserEntry());
|
|
763
|
+
root = parser.parse(`(async () => {\n${script}\n})()`, { ecmaVersion: "latest", sourceType: "script", locations: true });
|
|
764
|
+
}
|
|
765
|
+
catch (error) {
|
|
766
|
+
const location = error && typeof error === "object" && "loc" in error && error.loc && typeof error.loc === "object"
|
|
767
|
+
? error.loc
|
|
768
|
+
: undefined;
|
|
769
|
+
const message = (error instanceof Error ? error.message : String(error)).replace(/\s+\(\d+:\d+\)$/, "");
|
|
770
|
+
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
|
+
}
|
|
772
|
+
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)
|
|
773
|
+
? root.body[0].expression.callee
|
|
774
|
+
: undefined;
|
|
775
|
+
const workflowBody = wrapper && astNode(wrapper.body) ? wrapper.body : root;
|
|
776
|
+
// A rebound `runs` may not be the workflow API, so its calls prove nothing about child launches.
|
|
777
|
+
const runsRebound = invalidatesRunsBinding(workflowBody);
|
|
778
|
+
const agentNameError = options.agentNameError && !runsRebound ? options.agentNameError : undefined;
|
|
779
|
+
walkAst(workflowBody, (node) => {
|
|
780
|
+
if (node !== wrapper && node.async === true && (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression")) {
|
|
781
|
+
errors.push({ message: "workflowScript does not support nested async functions. Use top-level await, plain helper functions that return runs.run(...), or explicit Promise chains.", ...nodeLocation(node) });
|
|
782
|
+
}
|
|
783
|
+
if (node.type === "ImportExpression")
|
|
784
|
+
errors.push({ message: "workflowScript cannot load modules with import().", ...nodeLocation(node) });
|
|
785
|
+
if (directRunsCall(node, "run")) {
|
|
786
|
+
const args = Array.isArray(node.arguments) ? node.arguments : [];
|
|
787
|
+
const keyNode = astNode(args[0]) ? args[0] : undefined;
|
|
788
|
+
const key = literalString(keyNode);
|
|
789
|
+
if (keyNode && key !== undefined && !KEY_PATTERN.test(key))
|
|
790
|
+
errors.push({ message: "runs.run key must be 1-128 characters using letters, numbers, '.', '_' or '-', and start with a letter or number.", ...nodeLocation(keyNode) });
|
|
791
|
+
if (keyNode?.type === "ObjectExpression" && !runsRebound)
|
|
792
|
+
errors.push({ message: `runs.run expects (key, params); got an object as the first argument. Use runs.run("plan", { agent, task }) or runs.all([{ key, agent, task }]).`, ...nodeLocation(keyNode) });
|
|
793
|
+
if (astNode(args[1])) {
|
|
794
|
+
errors.push(...validateStaticBaseRef(args[1], "runs.run"));
|
|
795
|
+
const message = definitelyNonJson(args[1]);
|
|
796
|
+
if (message)
|
|
797
|
+
errors.push({ message: `runs.run params are invalid: ${message}.`, ...nodeLocation(args[1]) });
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
if (directRunsCall(node, "all")) {
|
|
801
|
+
for (const entry of directRunsAllKeys(node))
|
|
802
|
+
if (!KEY_PATTERN.test(entry.key))
|
|
803
|
+
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) });
|
|
804
|
+
const args = Array.isArray(node.arguments) ? node.arguments : [];
|
|
805
|
+
if (astNode(args[0]) && args[0].type === "ArrayExpression" && Array.isArray(args[0].elements)) {
|
|
806
|
+
for (const item of args[0].elements)
|
|
807
|
+
if (astNode(item)) {
|
|
808
|
+
errors.push(...validateStaticBaseRef(item, "runs.all item"));
|
|
809
|
+
const message = definitelyNonJson(item);
|
|
810
|
+
if (message)
|
|
811
|
+
errors.push({ message: `runs.all item params are invalid: ${message}.`, ...nodeLocation(item) });
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
if (directRunsCall(node, "host"))
|
|
816
|
+
errors.push(...validateStaticHostCall(node));
|
|
817
|
+
if (agentNameError)
|
|
818
|
+
errors.push(...validateStaticChildAgents(node, agentNameError));
|
|
819
|
+
const boundaryValue = node.type === "CallExpression" && astNode(node.callee) && node.callee.type === "Identifier" && node.callee.name === "emit" && Array.isArray(node.arguments) && astNode(node.arguments[0])
|
|
820
|
+
? node.arguments[0]
|
|
821
|
+
: node.type === "CallExpression" && astNode(node.callee) && node.callee.type === "MemberExpression" && astNode(node.callee.object) && node.callee.object.type === "Identifier" && node.callee.object.name === "state" && astNode(node.callee.property) && node.callee.property.type === "Identifier" && node.callee.property.name === "set" && Array.isArray(node.arguments) && astNode(node.arguments[1])
|
|
822
|
+
? node.arguments[1]
|
|
823
|
+
: undefined;
|
|
824
|
+
if (boundaryValue) {
|
|
825
|
+
// emit normalizes undefined like return; state.set values must already be JSON.
|
|
826
|
+
const message = definitelyNonJson(boundaryValue, Array.isArray(node.arguments) && boundaryValue === node.arguments[0]);
|
|
827
|
+
if (message)
|
|
828
|
+
errors.push({ message: `workflowScript boundary value is invalid: ${message}.`, ...nodeLocation(boundaryValue) });
|
|
829
|
+
}
|
|
830
|
+
});
|
|
831
|
+
walkAst(workflowBody, (node) => {
|
|
832
|
+
if (node.type !== "ReturnStatement" || !astNode(node.argument))
|
|
833
|
+
return;
|
|
834
|
+
const message = definitelyNonJson(node.argument, true);
|
|
835
|
+
if (message)
|
|
836
|
+
errors.push({ message: `workflowScript boundary value is invalid: ${message}.`, ...nodeLocation(node.argument) });
|
|
837
|
+
}, false);
|
|
838
|
+
if (workflowBody.type === "BlockStatement" && Array.isArray(workflowBody.body)) {
|
|
839
|
+
for (let statementIndex = 0; statementIndex < workflowBody.body.length; statementIndex++) {
|
|
840
|
+
const statement = workflowBody.body[statementIndex];
|
|
841
|
+
if (!astNode(statement) || statement.type !== "VariableDeclaration" || !Array.isArray(statement.declarations))
|
|
842
|
+
continue;
|
|
843
|
+
for (const declaration of statement.declarations) {
|
|
844
|
+
if (!astNode(declaration) || !astNode(declaration.id) || declaration.id.type !== "Identifier" || !astNode(declaration.init) || declaration.init.type !== "AwaitExpression" || !astNode(declaration.init.argument) || !directRunsCall(declaration.init.argument, "all"))
|
|
845
|
+
continue;
|
|
846
|
+
const name = declaration.id.name;
|
|
847
|
+
const laterStatements = workflowBody.body.slice(statementIndex + 1);
|
|
848
|
+
const keys = new Set(directRunsAllKeys(declaration.init.argument).map((entry) => entry.key));
|
|
849
|
+
if (keys.size === 0)
|
|
850
|
+
continue;
|
|
851
|
+
const args = Array.isArray(declaration.init.argument.arguments) ? declaration.init.argument.arguments : [];
|
|
852
|
+
const itemCount = astNode(args[0]) && args[0].type === "ArrayExpression" && Array.isArray(args[0].elements) ? args[0].elements.length : 0;
|
|
853
|
+
const arrayResultShape = Array.from({ length: itemCount });
|
|
854
|
+
for (const later of laterStatements) {
|
|
855
|
+
walkAstWithoutShadowedIdentifier(later, name, (node) => {
|
|
856
|
+
if (node.type !== "MemberExpression" || !astNode(node.object) || node.object.type !== "Identifier" || node.object.name !== name)
|
|
857
|
+
return;
|
|
858
|
+
const property = node.computed === true ? literalString(node.property) : astNode(node.property) && node.property.type === "Identifier" ? node.property.name : undefined;
|
|
859
|
+
if (property && keys.has(property) && !(property in arrayResultShape))
|
|
860
|
+
errors.push({ message: `runs.all returns an ordered array; '${name}.${property}' is keyed access. Use an index, destructuring, or map(...).`, ...nodeLocation(node) });
|
|
861
|
+
});
|
|
862
|
+
if (statement.kind !== "const" && astNode(later) && later.type === "ExpressionStatement" && definitelyReassignsBinding(later.expression, name))
|
|
863
|
+
break;
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
const warnings = [];
|
|
869
|
+
if (options.maxSubagentSpawnsPerRun !== undefined) {
|
|
870
|
+
const plan = staticWorkflowLaunchPlan(workflowBody);
|
|
871
|
+
if (plan.keys.length > options.maxSubagentSpawnsPerRun) {
|
|
872
|
+
errors.push({
|
|
873
|
+
kind: "spawn-budget",
|
|
874
|
+
message: `workflowScript statically requires child launches ${plan.keys.map((key) => `'${key}'`).join(", ")}; minimum required: ${plan.keys.length}; configured: ${options.maxSubagentSpawnsPerRun}.`,
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
if (plan.dynamic) {
|
|
878
|
+
warnings.push({
|
|
879
|
+
kind: "dynamic-spawn-count",
|
|
880
|
+
message: `workflowScript contains dynamic child launches; static validation proved ${plan.keys.length} launch(es), so runtime fan-out enforcement remains authoritative for the configured budget of ${options.maxSubagentSpawnsPerRun}.`,
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
const unique = errors.filter((error, index) => errors.findIndex((candidate) => candidate.message === error.message && candidate.line === error.line && candidate.column === error.column) === index);
|
|
885
|
+
return { ok: unique.length === 0, errors: unique, ...(warnings.length > 0 ? { warnings } : {}) };
|
|
886
|
+
}
|
|
887
|
+
function workflowStringMetadata(params) {
|
|
888
|
+
return {
|
|
889
|
+
...(typeof params.phase === "string" && params.phase.trim() ? { phase: params.phase.trim() } : {}),
|
|
890
|
+
...(typeof params.label === "string" && params.label.trim() ? { label: params.label.trim() } : {}),
|
|
891
|
+
// Requested agent name, so a child is identifiable while it runs. Launch
|
|
892
|
+
// resolution overwrites this with the canonical name on the terminal entry.
|
|
893
|
+
...(typeof params.agent === "string" && params.agent.trim() ? { agent: params.agent.trim() } : {}),
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
function resolveWorkflowParserEntry() {
|
|
897
|
+
try {
|
|
898
|
+
return requireFromPackage.resolve("acorn");
|
|
899
|
+
}
|
|
900
|
+
catch (primaryError) {
|
|
901
|
+
// Some runtimes (e.g. Bun-compiled single-file binaries) fail bare
|
|
902
|
+
// package-specifier resolution through createRequire while subpath
|
|
903
|
+
// resolution still works. Resolve the manifest and derive the
|
|
904
|
+
// CommonJS entry from its "main" field instead.
|
|
905
|
+
try {
|
|
906
|
+
const manifestPath = requireFromPackage.resolve("acorn/package.json");
|
|
907
|
+
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
908
|
+
const entry = typeof manifest.main === "string" && manifest.main ? manifest.main : "./dist/acorn.js";
|
|
909
|
+
return resolvePath(dirname(manifestPath), entry);
|
|
910
|
+
}
|
|
911
|
+
catch {
|
|
912
|
+
throw primaryError;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
const AUTO_RESUME_PARAM_KEYS = ["acceptance", "agentContract", "baseRef", "index", "intercomBridge", "label", "lane", "maxRuntimeMs", "output", "outputMode", "outputSchema", "phase", "skill", "skills", "task", "timeoutMs", "toolBudget", "worktree"];
|
|
917
|
+
function isZeroUsage(usage) {
|
|
918
|
+
if (!isRecord(usage))
|
|
919
|
+
return false;
|
|
920
|
+
const cost = usage.cost;
|
|
921
|
+
return (usage.input ?? 0) === 0
|
|
922
|
+
&& (usage.output ?? 0) === 0
|
|
923
|
+
&& (usage.cacheRead ?? 0) === 0
|
|
924
|
+
&& (usage.cacheWrite ?? 0) === 0
|
|
925
|
+
&& (!isRecord(cost) || (cost.total ?? 0) === 0);
|
|
926
|
+
}
|
|
927
|
+
function setupAbortResumeParams(params, result, signal) {
|
|
928
|
+
if (signal.aborted || result.state === "running" || result.ok || result.stopped || result.interrupted || !result.runId)
|
|
929
|
+
return undefined;
|
|
930
|
+
const childResult = Array.isArray(result.results) && result.results.length === 1 && isRecord(result.results[0]) ? result.results[0] : undefined;
|
|
931
|
+
const error = typeof childResult?.error === "string" ? childResult.error : result.error;
|
|
932
|
+
if (error !== "This operation was aborted" || !isZeroUsage(childResult?.usage))
|
|
933
|
+
return undefined;
|
|
934
|
+
const messages = Array.isArray(childResult?.messages) ? childResult.messages : [];
|
|
935
|
+
const message = messages.findLast((entry) => isRecord(entry) && entry.role === "assistant");
|
|
936
|
+
if (message !== undefined) {
|
|
937
|
+
if (!isRecord(message))
|
|
938
|
+
return undefined;
|
|
939
|
+
if (message.stopReason !== "error" || message.errorMessage !== error)
|
|
940
|
+
return undefined;
|
|
941
|
+
if (!Array.isArray(message.content) || message.content.length > 0 || !isZeroUsage(message.usage))
|
|
942
|
+
return undefined;
|
|
943
|
+
if (Object.hasOwn(message, "diagnostics") || Object.hasOwn(message, "responseId"))
|
|
944
|
+
return undefined;
|
|
945
|
+
}
|
|
946
|
+
const task = typeof params.task === "string" && params.task.trim() ? params.task.trim() : "Continue after the setup abort.";
|
|
947
|
+
const resumeParams = { resume: result.runId, task };
|
|
948
|
+
for (const key of AUTO_RESUME_PARAM_KEYS) {
|
|
949
|
+
if (Object.hasOwn(params, key))
|
|
950
|
+
resumeParams[key] = params[key];
|
|
951
|
+
}
|
|
952
|
+
resumeParams.resume = result.runId;
|
|
953
|
+
resumeParams.task = task;
|
|
954
|
+
return resumeParams;
|
|
955
|
+
}
|
|
956
|
+
export async function runWorkflowScript(options) {
|
|
957
|
+
const emptyPartial = () => ({ emits: [], console: [], trace: [], children: [] });
|
|
958
|
+
if (!options.script.trim())
|
|
959
|
+
throw new WorkflowScriptError("workflowScript must not be empty.", emptyPartial(), "validation");
|
|
960
|
+
if (options.timeoutMs !== undefined && (!Number.isInteger(options.timeoutMs) || options.timeoutMs < 1))
|
|
961
|
+
throw new WorkflowScriptError("workflow script timeout must be a positive integer.", emptyPartial(), "runtime");
|
|
962
|
+
if (options.globalConcurrencyLimit !== undefined && (!Number.isSafeInteger(options.globalConcurrencyLimit) || options.globalConcurrencyLimit < 1)) {
|
|
963
|
+
throw new WorkflowScriptError("workflow script global concurrency limit must be a positive integer.", emptyPartial(), "runtime");
|
|
964
|
+
}
|
|
965
|
+
const launchSemaphore = new Semaphore(options.globalConcurrencyLimit ?? DEFAULT_GLOBAL_CONCURRENCY_LIMIT);
|
|
966
|
+
if (options.processCwd !== undefined) {
|
|
967
|
+
let staleCwd = false;
|
|
968
|
+
try {
|
|
969
|
+
realpathSync(process.cwd());
|
|
970
|
+
}
|
|
971
|
+
catch (error) {
|
|
972
|
+
const code = typeof error === "object" && error !== null && "code" in error ? error.code : undefined;
|
|
973
|
+
if (code !== "ENOENT")
|
|
974
|
+
throw new WorkflowScriptError("Workflow current cwd could not be validated.", emptyPartial(), "runtime", { cause: error });
|
|
975
|
+
staleCwd = true;
|
|
976
|
+
}
|
|
977
|
+
try {
|
|
978
|
+
if (staleCwd)
|
|
979
|
+
process.chdir(options.processCwd);
|
|
980
|
+
else {
|
|
981
|
+
const target = realpathSync(options.processCwd);
|
|
982
|
+
if (!statSync(target).isDirectory()) {
|
|
983
|
+
const error = new Error(`ENOTDIR: not a directory, access '${target}'`);
|
|
984
|
+
error.code = "ENOTDIR";
|
|
985
|
+
throw error;
|
|
986
|
+
}
|
|
987
|
+
accessSync(target, constants.X_OK);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
catch (error) {
|
|
991
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
992
|
+
throw new WorkflowScriptError(`Workflow process cwd is unavailable: ${options.processCwd}: ${detail}`, emptyPartial(), "runtime", { cause: error });
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
let acornPath;
|
|
996
|
+
try {
|
|
997
|
+
acornPath = resolveWorkflowParserEntry();
|
|
998
|
+
}
|
|
999
|
+
catch (error) {
|
|
1000
|
+
throw new WorkflowScriptError("Workflow parser dependency 'acorn' is unavailable from pi-subagents. Reinstall pi-subagents dependencies before launching workflowScript.", emptyPartial(), "runtime", { cause: error });
|
|
1001
|
+
}
|
|
1002
|
+
let worker;
|
|
1003
|
+
try {
|
|
1004
|
+
const bun = typeof process.versions.bun === "string";
|
|
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 } });
|
|
1011
|
+
}
|
|
1012
|
+
catch (error) {
|
|
1013
|
+
throw new WorkflowScriptError(`Workflow worker could not start: ${error instanceof Error ? error.message : String(error)}`, emptyPartial(), "runtime", { cause: error });
|
|
1014
|
+
}
|
|
1015
|
+
const emits = [];
|
|
1016
|
+
const consoleEntries = [];
|
|
1017
|
+
const trace = [];
|
|
1018
|
+
const children = new Map();
|
|
1019
|
+
const childOrder = [];
|
|
1020
|
+
const launches = new Map();
|
|
1021
|
+
const steers = new Map();
|
|
1022
|
+
const hostCalls = new Map();
|
|
1023
|
+
const stoppedLaunches = new Set();
|
|
1024
|
+
const childStopControllers = new Map();
|
|
1025
|
+
const batchAdmissions = new Map();
|
|
1026
|
+
const observedRunCalls = new Set();
|
|
1027
|
+
const observedSteerCalls = new Set();
|
|
1028
|
+
const observedHostCalls = new Set();
|
|
1029
|
+
const childController = new AbortController();
|
|
1030
|
+
let acceptanceRecoveryBarrier;
|
|
1031
|
+
let settled = false;
|
|
1032
|
+
let finishing = false;
|
|
1033
|
+
let assemblyAbortRequested = false;
|
|
1034
|
+
let assemblyFlushTimer;
|
|
1035
|
+
let abortError;
|
|
1036
|
+
const partial = () => ({ emits, console: consoleEntries, trace, children: childOrder.flatMap((key) => {
|
|
1037
|
+
const child = children.get(key);
|
|
1038
|
+
return child ? [child] : [];
|
|
1039
|
+
}) });
|
|
1040
|
+
// Hosts use onTrace to persist a progress journal, and it is invoked from inside
|
|
1041
|
+
// the run-promise handlers below. A throw here would reject the child promise the
|
|
1042
|
+
// script is awaiting, so a single failed status write could mark a completed child
|
|
1043
|
+
// failed and abort its siblings through Promise.all. Telemetry must not decide
|
|
1044
|
+
// workflow outcomes, so a failing callback is reported and the run continues.
|
|
1045
|
+
const traceChanged = () => {
|
|
1046
|
+
try {
|
|
1047
|
+
options.onTrace?.([...trace]);
|
|
1048
|
+
}
|
|
1049
|
+
catch (error) {
|
|
1050
|
+
console.error("Workflow onTrace callback failed:", error);
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
1053
|
+
const lanePlanChanged = (lanes) => {
|
|
1054
|
+
try {
|
|
1055
|
+
options.onLanePlan?.(lanes);
|
|
1056
|
+
}
|
|
1057
|
+
catch (error) {
|
|
1058
|
+
console.error("Workflow onLanePlan callback failed:", error);
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
const hostStepChanged = (hostStep) => {
|
|
1062
|
+
try {
|
|
1063
|
+
options.onHostStep?.(hostStep);
|
|
1064
|
+
}
|
|
1065
|
+
catch (error) {
|
|
1066
|
+
console.error("Workflow onHostStep callback failed:", error);
|
|
1067
|
+
}
|
|
1068
|
+
};
|
|
1069
|
+
const stoppedChildResult = (key, message) => ({ key, ok: false, stopped: true, output: message, error: message, artifactPaths: [] });
|
|
1070
|
+
const responseBoundaryFailure = (key, error) => {
|
|
1071
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
1072
|
+
return { key, ok: false, output: text, error: text, artifactPaths: [] };
|
|
1073
|
+
};
|
|
1074
|
+
const assertRecoveryBarrierAllowsRun = (key, params) => {
|
|
1075
|
+
if (!acceptanceRecoveryBarrier || isExplicitReadOnlyRecoveryReview(params))
|
|
1076
|
+
return;
|
|
1077
|
+
throw new Error(recoveryBarrierMessage(acceptanceRecoveryBarrier.key, key));
|
|
1078
|
+
};
|
|
1079
|
+
const recordAcceptanceRecoveryBarrier = (key, result) => {
|
|
1080
|
+
if (isAcceptanceMetadataRecovery(result))
|
|
1081
|
+
acceptanceRecoveryBarrier = { key };
|
|
1082
|
+
};
|
|
1083
|
+
const stopChild = (key, message = `Workflow child '${key}' stopped.`) => {
|
|
1084
|
+
if (!launches.has(key) || children.has(key))
|
|
1085
|
+
return false;
|
|
1086
|
+
stoppedLaunches.add(key);
|
|
1087
|
+
children.set(key, stoppedChildResult(key, message));
|
|
1088
|
+
childStopControllers.get(key)?.abort(new Error(message));
|
|
1089
|
+
const started = trace.findLast((entry) => entry.operation === "run" && entry.key === key && entry.state === "started");
|
|
1090
|
+
trace.push({
|
|
1091
|
+
operation: "run",
|
|
1092
|
+
key,
|
|
1093
|
+
state: "stopped",
|
|
1094
|
+
...(started?.agent ? { agent: started.agent } : {}),
|
|
1095
|
+
...(started?.phase ? { phase: started.phase } : {}),
|
|
1096
|
+
...(started?.label ? { label: started.label } : {}),
|
|
1097
|
+
...(started?.generatedLaneKey ? { generatedLaneKey: started.generatedLaneKey } : {}),
|
|
1098
|
+
error: message,
|
|
1099
|
+
});
|
|
1100
|
+
traceChanged();
|
|
1101
|
+
return true;
|
|
1102
|
+
};
|
|
1103
|
+
const notifyChildSettled = (key, result) => {
|
|
1104
|
+
if (result.state === "running" || !options.onChildSettled || !options.workflowRunId)
|
|
1105
|
+
return;
|
|
1106
|
+
const outcome = result.ok
|
|
1107
|
+
? "completed"
|
|
1108
|
+
: result.stopped
|
|
1109
|
+
? "stopped"
|
|
1110
|
+
: result.detached
|
|
1111
|
+
? "paused"
|
|
1112
|
+
: "failed";
|
|
1113
|
+
const outputReference = result.outputReference ?? result.outputArtifactPath;
|
|
1114
|
+
try {
|
|
1115
|
+
options.onChildSettled({
|
|
1116
|
+
workflowRunId: options.workflowRunId,
|
|
1117
|
+
childKey: key,
|
|
1118
|
+
...(result.runId ? { childRunId: result.runId } : {}),
|
|
1119
|
+
outcome,
|
|
1120
|
+
...(outputReference ? { outputReference } : {}),
|
|
1121
|
+
...(!result.ok && result.error ? { error: result.error } : {}),
|
|
1122
|
+
workflowRunning: !settled && !finishing,
|
|
1123
|
+
result,
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1126
|
+
catch (error) {
|
|
1127
|
+
console.error("Workflow onChildSettled callback failed:", error);
|
|
1128
|
+
}
|
|
1129
|
+
};
|
|
1130
|
+
options.registerStopChild?.(stopChild);
|
|
1131
|
+
return await new Promise((resolve, reject) => {
|
|
1132
|
+
const finish = (outcome) => {
|
|
1133
|
+
if (settled || finishing)
|
|
1134
|
+
return;
|
|
1135
|
+
finishing = true;
|
|
1136
|
+
if (assemblyFlushTimer !== undefined) {
|
|
1137
|
+
clearTimeout(assemblyFlushTimer);
|
|
1138
|
+
assemblyFlushTimer = undefined;
|
|
1139
|
+
}
|
|
1140
|
+
childController.abort("error" in outcome ? outcome.error : new Error("Workflow script completed."));
|
|
1141
|
+
void Promise.allSettled([...steers.values(), ...hostCalls.values()].map(({ promise }) => promise)).then(() => {
|
|
1142
|
+
if (settled)
|
|
1143
|
+
return;
|
|
1144
|
+
settled = true;
|
|
1145
|
+
options.registerStopChild?.(undefined);
|
|
1146
|
+
if (timer)
|
|
1147
|
+
clearTimeout(timer);
|
|
1148
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
1149
|
+
void worker.terminate();
|
|
1150
|
+
const unobservedKeys = "value" in outcome ? [...launches].filter(([, launch]) => !launch.observed).map(([key]) => key) : [];
|
|
1151
|
+
const completionError = unobservedKeys.length > 0
|
|
1152
|
+
? new Error(`workflowScript completed with unawaited runs.run launch(es): ${unobservedKeys.map((key) => `'${key}'`).join(", ")}. For ordinary parallel fanout use await runs.all([{key, agent, task}, ...]); do not read .output from unawaited launches.`)
|
|
1153
|
+
: "value" in outcome
|
|
1154
|
+
? (() => {
|
|
1155
|
+
const unobservedSteers = [...steers.values()].filter((steer) => !steer.observed).map((steer) => steer.key);
|
|
1156
|
+
if (unobservedSteers.length > 0)
|
|
1157
|
+
return new Error(`workflowScript completed with unawaited runs.steer call(s): ${unobservedSteers.map((key) => `'${key}'`).join(", ")}. Await or return each call.`);
|
|
1158
|
+
const unobservedHosts = [...hostCalls.values()].filter((host) => !host.observed).map((host) => host.key);
|
|
1159
|
+
return unobservedHosts.length > 0 ? new Error(`workflowScript completed with unawaited runs.host call(s): ${unobservedHosts.map((key) => `'${key}'`).join(", ")}. Await or return each call.`) : undefined;
|
|
1160
|
+
})()
|
|
1161
|
+
: undefined;
|
|
1162
|
+
// Stops and reloads end through the abort paths untagged: they are not failures.
|
|
1163
|
+
if ("error" in outcome)
|
|
1164
|
+
reject(new WorkflowScriptError(outcome.error.message, partial(), isWorkflowScriptFailureKind(outcome.error.workflowErrorKind) ? outcome.error.workflowErrorKind : undefined));
|
|
1165
|
+
else if (completionError)
|
|
1166
|
+
reject(new WorkflowScriptError(completionError.message, partial(), "validation"));
|
|
1167
|
+
else
|
|
1168
|
+
resolve({ value: outcome.value, ...partial() });
|
|
1169
|
+
});
|
|
1170
|
+
};
|
|
1171
|
+
const onAbort = () => {
|
|
1172
|
+
const signalReason = options.signal?.reason;
|
|
1173
|
+
const error = signalReason instanceof Error
|
|
1174
|
+
? signalReason
|
|
1175
|
+
: typeof signalReason === "string"
|
|
1176
|
+
? new Error(signalReason)
|
|
1177
|
+
: new Error("Workflow script aborted.");
|
|
1178
|
+
if (finishing)
|
|
1179
|
+
return;
|
|
1180
|
+
abortError = error;
|
|
1181
|
+
const allChildrenSettled = launches.size > 0
|
|
1182
|
+
&& [...launches.keys()].every((key) => children.has(key));
|
|
1183
|
+
let mayFlushAssembly = false;
|
|
1184
|
+
try {
|
|
1185
|
+
mayFlushAssembly = options.continueAfterAbortWhenChildrenSettled?.(error) === true;
|
|
1186
|
+
}
|
|
1187
|
+
catch (callbackError) {
|
|
1188
|
+
const callbackMessage = callbackError instanceof Error ? callbackError.message : String(callbackError);
|
|
1189
|
+
return finish({ error: taggedWorkflowError(`Workflow assembly flush eligibility failed: ${callbackMessage}`, "runtime") });
|
|
1190
|
+
}
|
|
1191
|
+
if (mayFlushAssembly && allChildrenSettled) {
|
|
1192
|
+
// A reloaded async workflow may already be past its last child launch.
|
|
1193
|
+
// Keep the worker alive for pure result assembly, but abort the child
|
|
1194
|
+
// signal so any later launch or side effect cannot use stale context.
|
|
1195
|
+
assemblyAbortRequested = true;
|
|
1196
|
+
childController.abort(error);
|
|
1197
|
+
assemblyFlushTimer = setTimeout(() => finish({ error }), WORKFLOW_ASSEMBLY_FLUSH_TIMEOUT_MS);
|
|
1198
|
+
return;
|
|
1199
|
+
}
|
|
1200
|
+
for (const key of launches.keys()) {
|
|
1201
|
+
if (children.has(key))
|
|
1202
|
+
continue;
|
|
1203
|
+
stoppedLaunches.add(key);
|
|
1204
|
+
const started = trace.findLast((entry) => entry.operation === "run" && entry.key === key && entry.state === "started");
|
|
1205
|
+
trace.push({
|
|
1206
|
+
operation: "run",
|
|
1207
|
+
key,
|
|
1208
|
+
state: "stopped",
|
|
1209
|
+
...(started?.agent ? { agent: started.agent } : {}),
|
|
1210
|
+
...(started?.phase ? { phase: started.phase } : {}),
|
|
1211
|
+
...(started?.label ? { label: started.label } : {}),
|
|
1212
|
+
...(started?.generatedLaneKey ? { generatedLaneKey: started.generatedLaneKey } : {}),
|
|
1213
|
+
error: error.message,
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1216
|
+
traceChanged();
|
|
1217
|
+
finish({ error });
|
|
1218
|
+
};
|
|
1219
|
+
const timer = options.timeoutMs === undefined
|
|
1220
|
+
? undefined
|
|
1221
|
+
: setTimeout(() => {
|
|
1222
|
+
finish({ error: taggedWorkflowError(`Workflow script timed out after ${options.timeoutMs}ms.`, "timeout") });
|
|
1223
|
+
}, options.timeoutMs);
|
|
1224
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
1225
|
+
if (options.signal?.aborted)
|
|
1226
|
+
return onAbort();
|
|
1227
|
+
worker.on("error", (error) => finish({ error: taggedWorkflowError(`Workflow worker failed: ${error instanceof Error ? error.message : String(error)}`, "runtime") }));
|
|
1228
|
+
worker.on("exit", (code) => {
|
|
1229
|
+
if (!settled && code !== 0)
|
|
1230
|
+
finish({ error: taggedWorkflowError(`Workflow worker exited with code ${code}.`, "runtime") });
|
|
1231
|
+
});
|
|
1232
|
+
worker.on("message", (message) => {
|
|
1233
|
+
if (settled)
|
|
1234
|
+
return;
|
|
1235
|
+
if (message.type === "lanePlan" && Array.isArray(message.lanes)) {
|
|
1236
|
+
lanePlanChanged(message.lanes);
|
|
1237
|
+
return;
|
|
1238
|
+
}
|
|
1239
|
+
if (message.type === "emit") {
|
|
1240
|
+
try {
|
|
1241
|
+
assertWorkflowJsonValue(message.value, "emit");
|
|
1242
|
+
}
|
|
1243
|
+
catch (error) {
|
|
1244
|
+
finish({ error: taggedWorkflowError(`Workflow emit could not be persisted: ${error instanceof Error ? error.message : String(error)}`, "runtime") });
|
|
1245
|
+
return;
|
|
1246
|
+
}
|
|
1247
|
+
emits.push(message.value);
|
|
1248
|
+
try {
|
|
1249
|
+
options.onEmit?.([...emits]);
|
|
1250
|
+
}
|
|
1251
|
+
catch (error) {
|
|
1252
|
+
emits.pop();
|
|
1253
|
+
finish({ error: taggedWorkflowError(`Workflow emit could not be persisted: ${error instanceof Error ? error.message : String(error)}`, "runtime") });
|
|
1254
|
+
}
|
|
1255
|
+
return;
|
|
1256
|
+
}
|
|
1257
|
+
if (message.type === "console") {
|
|
1258
|
+
const level = message.level;
|
|
1259
|
+
if ((level === "log" || level === "info" || level === "warn" || level === "error") && typeof message.text === "string")
|
|
1260
|
+
consoleEntries.push({ level, text: message.text });
|
|
1261
|
+
return;
|
|
1262
|
+
}
|
|
1263
|
+
if (message.type === "complete") {
|
|
1264
|
+
try {
|
|
1265
|
+
assertWorkflowJsonValue(message.value, "return");
|
|
1266
|
+
}
|
|
1267
|
+
catch (error) {
|
|
1268
|
+
return finish({ error: taggedWorkflowError(`Workflow return could not be persisted: ${error instanceof Error ? error.message : String(error)}`, "return-serialization") });
|
|
1269
|
+
}
|
|
1270
|
+
return finish({ value: message.value });
|
|
1271
|
+
}
|
|
1272
|
+
if (message.type === "error") {
|
|
1273
|
+
const rawError = typeof message.error === "string" ? message.error : "Workflow script failed.";
|
|
1274
|
+
const text = message.errorPhase === "return-serialization" ? `${rawError}${workflowReturnRecoveryHint(partial().children)}` : rawError;
|
|
1275
|
+
return finish({ error: isWorkflowScriptFailureKind(message.errorKind) ? taggedWorkflowError(text, message.errorKind) : new Error(text) });
|
|
1276
|
+
}
|
|
1277
|
+
if (message.type === "callObserved" && typeof message.callId === "number") {
|
|
1278
|
+
const key = typeof message.key === "string" ? message.key : undefined;
|
|
1279
|
+
if (message.operation === "run") {
|
|
1280
|
+
const launch = key ? launches.get(key) : undefined;
|
|
1281
|
+
if (launch)
|
|
1282
|
+
launch.observed = true;
|
|
1283
|
+
else
|
|
1284
|
+
observedRunCalls.add(message.callId);
|
|
1285
|
+
}
|
|
1286
|
+
else if (message.operation === "steer") {
|
|
1287
|
+
const steer = steers.get(message.callId);
|
|
1288
|
+
if (steer)
|
|
1289
|
+
steer.observed = true;
|
|
1290
|
+
else
|
|
1291
|
+
observedSteerCalls.add(message.callId);
|
|
1292
|
+
}
|
|
1293
|
+
else if (message.operation === "host") {
|
|
1294
|
+
const host = hostCalls.get(message.callId);
|
|
1295
|
+
if (host)
|
|
1296
|
+
host.observed = true;
|
|
1297
|
+
else
|
|
1298
|
+
observedHostCalls.add(message.callId);
|
|
1299
|
+
}
|
|
1300
|
+
return;
|
|
1301
|
+
}
|
|
1302
|
+
if (message.type !== "call" || typeof message.callId !== "number" || typeof message.method !== "string" || !isRecord(message.args))
|
|
1303
|
+
return;
|
|
1304
|
+
if (assemblyAbortRequested)
|
|
1305
|
+
return finish({ error: abortError ?? new Error("Workflow context was replaced or reloaded.") });
|
|
1306
|
+
const respond = (promise, responsePath, onBoundaryError) => {
|
|
1307
|
+
void promise.then((value) => {
|
|
1308
|
+
if (settled)
|
|
1309
|
+
return;
|
|
1310
|
+
const normalized = responsePath ? omitNonJsonWorkflowResultMetadata(value) : omitUndefinedWorkflowValues(value);
|
|
1311
|
+
if (!responsePath) {
|
|
1312
|
+
worker.postMessage({ type: "response", callId: message.callId, ok: true, value: normalized });
|
|
1313
|
+
return;
|
|
1314
|
+
}
|
|
1315
|
+
try {
|
|
1316
|
+
assertWorkflowJsonValue(normalized, responsePath);
|
|
1317
|
+
worker.postMessage({ type: "response", callId: message.callId, ok: true, value: normalized });
|
|
1318
|
+
}
|
|
1319
|
+
catch (error) {
|
|
1320
|
+
onBoundaryError?.(error);
|
|
1321
|
+
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
|
+
}
|
|
1323
|
+
}, (error) => {
|
|
1324
|
+
if (!settled) {
|
|
1325
|
+
const errorKind = error instanceof Error ? error.workflowErrorKind : undefined;
|
|
1326
|
+
worker.postMessage({ type: "response", callId: message.callId, ok: false, error: error instanceof Error ? error.message : String(error), ...(isWorkflowScriptFailureKind(errorKind) ? { errorKind } : {}) });
|
|
1327
|
+
}
|
|
1328
|
+
});
|
|
1329
|
+
};
|
|
1330
|
+
if (message.method === "state.get" || message.method === "state.set") {
|
|
1331
|
+
if (!options.state)
|
|
1332
|
+
return respond(Promise.reject(new Error("Workflow state is unavailable without a mission.")));
|
|
1333
|
+
let key;
|
|
1334
|
+
try {
|
|
1335
|
+
key = validateKey(message.args.key, "state");
|
|
1336
|
+
}
|
|
1337
|
+
catch (error) {
|
|
1338
|
+
return respond(Promise.reject(error));
|
|
1339
|
+
}
|
|
1340
|
+
if (message.method === "state.get")
|
|
1341
|
+
return respond(Promise.resolve().then(() => options.state.get(key)));
|
|
1342
|
+
if (acceptanceRecoveryBarrier)
|
|
1343
|
+
return respond(Promise.reject(new Error(recoveryBarrierMessage(acceptanceRecoveryBarrier.key, `state.set('${key}')`))));
|
|
1344
|
+
const value = message.args.value;
|
|
1345
|
+
try {
|
|
1346
|
+
assertWorkflowJsonValue(value, `state.set('${key}') value`);
|
|
1347
|
+
}
|
|
1348
|
+
catch (error) {
|
|
1349
|
+
return respond(Promise.reject(error));
|
|
1350
|
+
}
|
|
1351
|
+
return respond(Promise.resolve().then(() => options.state.set(key, value)));
|
|
1352
|
+
}
|
|
1353
|
+
if (message.method === "status") {
|
|
1354
|
+
const keyOrRunId = message.args.keyOrRunId;
|
|
1355
|
+
if (typeof keyOrRunId !== "string" || !keyOrRunId.trim())
|
|
1356
|
+
return respond(Promise.reject(new Error("runs.status(keyOrRunId) requires a non-empty string.")));
|
|
1357
|
+
const known = children.get(keyOrRunId);
|
|
1358
|
+
const target = known?.runId ?? keyOrRunId;
|
|
1359
|
+
trace.push({ operation: "status", key: keyOrRunId, state: "started", ...(known?.runId ? { runId: known.runId } : {}) });
|
|
1360
|
+
traceChanged();
|
|
1361
|
+
if (settled || finishing)
|
|
1362
|
+
return;
|
|
1363
|
+
respond(options.status(target, childController.signal).then((result) => {
|
|
1364
|
+
if (settled || finishing)
|
|
1365
|
+
return result;
|
|
1366
|
+
trace.push({ operation: "status", key: keyOrRunId, state: result.ok ? "completed" : "failed", ...(result.runId ? { runId: result.runId } : {}), ...(!result.ok ? { error: result.output } : {}) });
|
|
1367
|
+
traceChanged();
|
|
1368
|
+
if (!result.ok)
|
|
1369
|
+
throw new Error(`Status '${keyOrRunId}' failed: ${result.output}`);
|
|
1370
|
+
return result;
|
|
1371
|
+
}));
|
|
1372
|
+
return;
|
|
1373
|
+
}
|
|
1374
|
+
if (message.method === "steer") {
|
|
1375
|
+
let key;
|
|
1376
|
+
try {
|
|
1377
|
+
key = validateKey(message.args.key, "runs.steer");
|
|
1378
|
+
}
|
|
1379
|
+
catch (error) {
|
|
1380
|
+
return respond(Promise.reject(error));
|
|
1381
|
+
}
|
|
1382
|
+
const steerMessage = message.args.message;
|
|
1383
|
+
if (typeof steerMessage !== "string" || !steerMessage.trim())
|
|
1384
|
+
return respond(Promise.reject(new Error(`runs.steer('${key}') requires a non-empty message.`)));
|
|
1385
|
+
const steerOptions = isRecord(message.args.options) ? message.args.options : {};
|
|
1386
|
+
if (acceptanceRecoveryBarrier)
|
|
1387
|
+
return respond(Promise.reject(new Error(recoveryBarrierMessage(acceptanceRecoveryBarrier.key, `runs.steer('${key}')`))));
|
|
1388
|
+
const startedAt = Date.now();
|
|
1389
|
+
trace.push({ operation: "steer", key, state: "started" });
|
|
1390
|
+
traceChanged();
|
|
1391
|
+
const promise = Promise.resolve().then(() => {
|
|
1392
|
+
if (!launches.has(key))
|
|
1393
|
+
throw new Error(`runs.steer('${key}') requires a prior runs.run/runs.all launch with that key.`);
|
|
1394
|
+
if (!options.steer)
|
|
1395
|
+
throw new Error("Workflow steering is unavailable in this host.");
|
|
1396
|
+
return options.steer(key, steerMessage.trim(), steerOptions, childController.signal);
|
|
1397
|
+
}).then((receipt) => {
|
|
1398
|
+
trace.push({ operation: "steer", key, state: receipt.state, durationMs: Date.now() - startedAt, ...(receipt.error ? { error: receipt.error } : {}) });
|
|
1399
|
+
traceChanged();
|
|
1400
|
+
return receipt;
|
|
1401
|
+
}, (error) => {
|
|
1402
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
1403
|
+
trace.push({ operation: "steer", key, state: "failed", durationMs: Date.now() - startedAt, error: text });
|
|
1404
|
+
traceChanged();
|
|
1405
|
+
throw error;
|
|
1406
|
+
});
|
|
1407
|
+
steers.set(message.callId, { key, promise, observed: observedSteerCalls.delete(message.callId) });
|
|
1408
|
+
respond(promise);
|
|
1409
|
+
return;
|
|
1410
|
+
}
|
|
1411
|
+
if (message.method === "host") {
|
|
1412
|
+
let key;
|
|
1413
|
+
let params;
|
|
1414
|
+
try {
|
|
1415
|
+
key = validateKey(message.args.key, "runs.host");
|
|
1416
|
+
params = normalizeWorkflowHostCommandParams(message.args.params, `runs.host('${key}') params`);
|
|
1417
|
+
}
|
|
1418
|
+
catch (error) {
|
|
1419
|
+
return respond(Promise.reject(error));
|
|
1420
|
+
}
|
|
1421
|
+
if (acceptanceRecoveryBarrier)
|
|
1422
|
+
return respond(Promise.reject(new Error(recoveryBarrierMessage(acceptanceRecoveryBarrier.key, `runs.host('${key}')`))));
|
|
1423
|
+
if (!options.host)
|
|
1424
|
+
return respond(Promise.reject(new Error("runs.host is unavailable in this host context.")));
|
|
1425
|
+
if (hostCalls.size >= HOST_STEP_MAX_COUNT)
|
|
1426
|
+
return respond(Promise.reject(new Error(`workflowScript supports at most ${HOST_STEP_MAX_COUNT} runs.host calls.`)));
|
|
1427
|
+
const startedAt = Date.now();
|
|
1428
|
+
const startedStep = {
|
|
1429
|
+
version: 1,
|
|
1430
|
+
kind: "host-step",
|
|
1431
|
+
monitorKind: "command",
|
|
1432
|
+
id: key,
|
|
1433
|
+
label: key,
|
|
1434
|
+
...(params.role ? { role: params.role } : {}),
|
|
1435
|
+
...(params.provider ? { provider: params.provider } : {}),
|
|
1436
|
+
state: "running",
|
|
1437
|
+
updatedAt: startedAt,
|
|
1438
|
+
deadlineAt: startedAt + params.timeoutMs,
|
|
1439
|
+
};
|
|
1440
|
+
hostStepChanged(startedStep);
|
|
1441
|
+
trace.push({ operation: "host", key, state: "started" });
|
|
1442
|
+
traceChanged();
|
|
1443
|
+
const promise = Promise.resolve().then(() => options.host(key, params, childController.signal)).then((result) => {
|
|
1444
|
+
const state = result.state === "stopped" ? "cancelled" : result.ok ? "done" : "error";
|
|
1445
|
+
const detail = [result.error, result.stderr.trim() || result.stdout.trim()].filter(Boolean).join(" ").replace(/\s+/g, " ").trim().slice(0, 200);
|
|
1446
|
+
hostStepChanged({ ...startedStep, state, ...(state === "done" ? { verdict: "pass" } : {}), ...(!result.ok ? { reasonCode: result.state === "timed-out" ? "timed_out" : result.state === "stopped" ? "aborted" : "command_failed" } : {}), ...(detail ? { detail } : {}), reportPath: params.output ?? result.outputPath.split(/[\\/]/).at(-1), exitCode: result.exitCode, updatedAt: Date.now() });
|
|
1447
|
+
trace.push({ operation: "host", key, state: result.ok ? "completed" : result.state === "stopped" ? "stopped" : "failed", durationMs: result.durationMs, ...(!result.ok ? { error: result.error ?? "Host command failed." } : {}) });
|
|
1448
|
+
traceChanged();
|
|
1449
|
+
if (!result.ok)
|
|
1450
|
+
throw new Error(`Host command '${key}' failed: ${detail || result.error || `exit code ${result.exitCode ?? "unknown"}`}`);
|
|
1451
|
+
return result;
|
|
1452
|
+
}, (error) => {
|
|
1453
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
1454
|
+
hostStepChanged({ ...startedStep, state: "error", reasonCode: "execution_failed", detail: text.replace(/\s+/g, " ").slice(0, 200), updatedAt: Date.now() });
|
|
1455
|
+
trace.push({ operation: "host", key, state: "failed", durationMs: Date.now() - startedAt, error: text });
|
|
1456
|
+
traceChanged();
|
|
1457
|
+
throw error;
|
|
1458
|
+
});
|
|
1459
|
+
hostCalls.set(message.callId, { key, promise, observed: observedHostCalls.delete(message.callId) });
|
|
1460
|
+
respond(promise, `runs.host('${key}') result`);
|
|
1461
|
+
return;
|
|
1462
|
+
}
|
|
1463
|
+
if (message.method !== "run")
|
|
1464
|
+
return respond(Promise.reject(new Error(`Unknown runs API method '${message.method}'.`)));
|
|
1465
|
+
let key;
|
|
1466
|
+
try {
|
|
1467
|
+
key = validateKey(message.args.key);
|
|
1468
|
+
}
|
|
1469
|
+
catch (error) {
|
|
1470
|
+
return respond(Promise.reject(error));
|
|
1471
|
+
}
|
|
1472
|
+
const params = message.args.params;
|
|
1473
|
+
if (!isRecord(params))
|
|
1474
|
+
return respond(Promise.reject(new Error(`runs.run('${key}', params) requires a params object.`)));
|
|
1475
|
+
const generatedLaneKey = typeof message.args.generatedLaneKey === "string" && KEY_PATTERN.test(message.args.generatedLaneKey) && key.startsWith(`${message.args.generatedLaneKey}.`)
|
|
1476
|
+
? message.args.generatedLaneKey
|
|
1477
|
+
: undefined;
|
|
1478
|
+
const collectFailure = message.args.collectFailure === true;
|
|
1479
|
+
const callObserved = observedRunCalls.delete(message.callId);
|
|
1480
|
+
const deliver = (promise) => collectFailure
|
|
1481
|
+
? promise
|
|
1482
|
+
: promise.then((result) => {
|
|
1483
|
+
const recoverableAcceptanceMetadata = result.recovery?.status === "available-for-review"
|
|
1484
|
+
&& result.recovery.reason === "acceptance-metadata-rejected";
|
|
1485
|
+
if (!result.ok && result.state !== "running" && !result.stopped && !recoverableAcceptanceMetadata) {
|
|
1486
|
+
throw taggedWorkflowError(`Run '${key}' ${result.detached ? "detached" : "failed"}: ${result.error ?? result.output}`, result.detached ? "detached-child" : "child");
|
|
1487
|
+
}
|
|
1488
|
+
return result;
|
|
1489
|
+
});
|
|
1490
|
+
const fingerprint = workflowRunParamsFingerprint(params);
|
|
1491
|
+
const existing = launches.get(key);
|
|
1492
|
+
if (existing) {
|
|
1493
|
+
if (existing.fingerprint !== fingerprint)
|
|
1494
|
+
return respond(Promise.reject(new Error(`Duplicate workflow key '${key}' used with incompatible launch params.`)));
|
|
1495
|
+
if (callObserved)
|
|
1496
|
+
existing.observed = true;
|
|
1497
|
+
trace.push({ operation: "run", key, state: "reused", ...workflowStringMetadata(params), ...(existing.generatedLaneKey ? { generatedLaneKey: existing.generatedLaneKey } : {}) });
|
|
1498
|
+
traceChanged();
|
|
1499
|
+
return respond(deliver(existing.promise), `runs.run('${key}') result`, (error) => children.set(key, responseBoundaryFailure(key, error)));
|
|
1500
|
+
}
|
|
1501
|
+
const permitError = options.oneUsePermit?.claim(key);
|
|
1502
|
+
if (permitError)
|
|
1503
|
+
return respond(Promise.reject(new Error(permitError)));
|
|
1504
|
+
if (options.oneUsePermit && message.args.batch !== undefined)
|
|
1505
|
+
return respond(Promise.reject(new Error("Workflow child permit does not support runs.all.")));
|
|
1506
|
+
if (options.oneUsePermit && params.resume !== undefined)
|
|
1507
|
+
return respond(Promise.reject(new Error("Workflow child permit does not support retained resume.")));
|
|
1508
|
+
if (params.action !== undefined)
|
|
1509
|
+
return respond(Promise.reject(new Error(`runs.run('${key}') accepts execution params only; management action is not allowed.`)));
|
|
1510
|
+
if (params.workflowScript !== undefined)
|
|
1511
|
+
return respond(Promise.reject(new Error(`runs.run('${key}') cannot start a nested workflow script.`)));
|
|
1512
|
+
if (params.tasks !== undefined || params.chain !== undefined || params.parallel !== undefined || params.concurrency !== undefined || params.chainDir !== undefined) {
|
|
1513
|
+
return respond(Promise.reject(new Error(`runs.run('${key}') accepts one child via { agent, task }; use runs.all(...) and JavaScript control flow for orchestration.`)));
|
|
1514
|
+
}
|
|
1515
|
+
if (params.worktree !== undefined && typeof params.worktree !== "boolean") {
|
|
1516
|
+
return respond(Promise.reject(new Error(`runs.run('${key}') worktree must be true or false.`)));
|
|
1517
|
+
}
|
|
1518
|
+
if (params.baseRef !== undefined && (typeof params.baseRef !== "string" || !validGitRef(params.baseRef))) {
|
|
1519
|
+
return respond(Promise.reject(new Error(`runs.run('${key}') ${BASE_REF_VALIDATION_ERROR}`)));
|
|
1520
|
+
}
|
|
1521
|
+
if (params.gate !== undefined) {
|
|
1522
|
+
const parsedGate = parseGateInput(params.gate);
|
|
1523
|
+
if (!parsedGate.ok)
|
|
1524
|
+
return respond(Promise.reject(new Error(`runs.run('${key}') ${parsedGate.error}`)));
|
|
1525
|
+
}
|
|
1526
|
+
if (params.gate !== undefined && params.acceptance !== undefined && params.acceptance !== false) {
|
|
1527
|
+
return respond(Promise.reject(new Error(`runs.run('${key}') gate cannot be combined with acceptance; use one gate command or acceptance.verify.` + describeGateAcceptanceConflict(params.gate, params.acceptance))));
|
|
1528
|
+
}
|
|
1529
|
+
if (params.gate !== undefined && params.resume !== undefined) {
|
|
1530
|
+
return respond(Promise.reject(new Error(`runs.run('${key}') gate is not supported with retained resume.`)));
|
|
1531
|
+
}
|
|
1532
|
+
let resumeReference;
|
|
1533
|
+
try {
|
|
1534
|
+
if (params.resume !== undefined && typeof params.resume !== "string")
|
|
1535
|
+
resumeReference = parseWorkflowResumeReference(params.resume);
|
|
1536
|
+
}
|
|
1537
|
+
catch (error) {
|
|
1538
|
+
return respond(Promise.reject(new Error(`runs.run('${key}') ${error instanceof Error ? error.message : String(error)}`)));
|
|
1539
|
+
}
|
|
1540
|
+
if (typeof params.resume === "string" && !params.resume.trim())
|
|
1541
|
+
return respond(Promise.reject(new Error(`runs.run('${key}') resume must be a non-empty retained run id.`)));
|
|
1542
|
+
if (params.resume !== undefined && params.agent !== undefined) {
|
|
1543
|
+
return respond(Promise.reject(new Error(`runs.run('${key}') resume and agent are mutually exclusive.`)));
|
|
1544
|
+
}
|
|
1545
|
+
if (params.resume !== undefined && (typeof params.task !== "string" || !params.task.trim())) {
|
|
1546
|
+
return respond(Promise.reject(new Error(`runs.run('${key}') resume requires a non-empty task follow-up.`)));
|
|
1547
|
+
}
|
|
1548
|
+
const startedAt = Date.now();
|
|
1549
|
+
const batch = isRecord(message.args.batch) && typeof message.args.batch.id === "string" && Array.isArray(message.args.batch.calls)
|
|
1550
|
+
? { id: message.args.batch.id, calls: message.args.batch.calls.filter((call) => isRecord(call) && typeof call.key === "string" && isRecord(call.params)) }
|
|
1551
|
+
: undefined;
|
|
1552
|
+
let admission = batch ? batchAdmissions.get(batch.id) : undefined;
|
|
1553
|
+
if (!admission) {
|
|
1554
|
+
const seenKeys = new Set();
|
|
1555
|
+
const calls = (batch?.calls ?? [{ key, params }]).filter((call) => {
|
|
1556
|
+
if (seenKeys.has(call.key) || launches.has(call.key))
|
|
1557
|
+
return false;
|
|
1558
|
+
seenKeys.add(call.key);
|
|
1559
|
+
return true;
|
|
1560
|
+
});
|
|
1561
|
+
admission = Promise.resolve().then(() => {
|
|
1562
|
+
if (settled || finishing)
|
|
1563
|
+
return;
|
|
1564
|
+
for (const call of calls)
|
|
1565
|
+
assertRecoveryBarrierAllowsRun(call.key, call.params);
|
|
1566
|
+
return options.admit?.(calls, childController.signal);
|
|
1567
|
+
});
|
|
1568
|
+
if (batch)
|
|
1569
|
+
batchAdmissions.set(batch.id, admission);
|
|
1570
|
+
}
|
|
1571
|
+
let resolvedResumeLineage;
|
|
1572
|
+
const promise = admission.then(async () => {
|
|
1573
|
+
if (settled || finishing || stoppedLaunches.has(key)) {
|
|
1574
|
+
const reason = childController.signal.reason;
|
|
1575
|
+
const text = children.get(key)?.error ?? (reason instanceof Error ? reason.message : typeof reason === "string" ? reason : "Workflow script aborted.");
|
|
1576
|
+
return stoppedChildResult(key, text);
|
|
1577
|
+
}
|
|
1578
|
+
const childStopController = new AbortController();
|
|
1579
|
+
childStopControllers.set(key, childStopController);
|
|
1580
|
+
const childSignal = combinedAbortSignal([childController.signal, childStopController.signal]);
|
|
1581
|
+
const resumeInput = resumeReference ?? (typeof params.resume === "string" && options.resolveResume ? params.resume : undefined);
|
|
1582
|
+
const resolvedResumeValue = resumeInput
|
|
1583
|
+
? await Promise.resolve().then(() => {
|
|
1584
|
+
if (!options.resolveResume)
|
|
1585
|
+
throw new Error("Keyed workflow receipt resume is unavailable in this host.");
|
|
1586
|
+
return options.resolveResume(resumeInput, childSignal, typeof params.index === "number" ? params.index : undefined);
|
|
1587
|
+
})
|
|
1588
|
+
: undefined;
|
|
1589
|
+
const resolvedResume = typeof resolvedResumeValue === "string"
|
|
1590
|
+
? resolvedResumeValue
|
|
1591
|
+
: isRecord(resolvedResumeValue) && typeof resolvedResumeValue.runId === "string"
|
|
1592
|
+
? resolvedResumeValue.runId
|
|
1593
|
+
: undefined;
|
|
1594
|
+
if (resumeReference && (typeof resolvedResume !== "string" || !resolvedResume.trim()))
|
|
1595
|
+
throw new Error("Keyed workflow receipt resume resolved without a retained run id.");
|
|
1596
|
+
const resolvedResumeId = resolvedResume?.trim();
|
|
1597
|
+
if (isRecord(resolvedResumeValue)) {
|
|
1598
|
+
const lineage = Array.isArray(resolvedResumeValue.runIds)
|
|
1599
|
+
? resolvedResumeValue.runIds.filter((runId) => typeof runId === "string" && Boolean(runId.trim())).map((runId) => runId.trim())
|
|
1600
|
+
: [];
|
|
1601
|
+
resolvedResumeLineage = [...new Set(lineage.length ? lineage : [resolvedResumeId])];
|
|
1602
|
+
if (resolvedResumeLineage.at(-1) !== resolvedResumeId)
|
|
1603
|
+
resolvedResumeLineage.push(resolvedResumeId);
|
|
1604
|
+
if (typeof resumeInput === "string") {
|
|
1605
|
+
const predecessor = [...children.values()].find((child) => child.runId === resolvedResumeId);
|
|
1606
|
+
if (predecessor?.continuation && predecessor.continuation.runIds.at(-1) === resolvedResumeId)
|
|
1607
|
+
resolvedResumeLineage = predecessor.continuation.runIds;
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
const launchParams = resolvedResumeId ? { ...params, resume: resolvedResumeId } : params;
|
|
1611
|
+
await launchSemaphore.acquire();
|
|
1612
|
+
try {
|
|
1613
|
+
if (settled || finishing || stoppedLaunches.has(key) || childSignal.aborted) {
|
|
1614
|
+
const reason = childSignal.reason;
|
|
1615
|
+
const text = children.get(key)?.error ?? (reason instanceof Error ? reason.message : typeof reason === "string" ? reason : "Workflow script aborted.");
|
|
1616
|
+
return stoppedChildResult(key, text);
|
|
1617
|
+
}
|
|
1618
|
+
const result = await options.launch(key, launchParams, childSignal, { admitted: true, batch: batch !== undefined });
|
|
1619
|
+
const autoResumeParams = setupAbortResumeParams(params, result, childSignal);
|
|
1620
|
+
if (!autoResumeParams)
|
|
1621
|
+
return result;
|
|
1622
|
+
resolvedResumeLineage = [...new Set([...(resolvedResumeLineage ?? []), result.runId])];
|
|
1623
|
+
trace.push({ operation: "run", key, state: "started", ...workflowStringMetadata(autoResumeParams), ...(generatedLaneKey ? { generatedLaneKey } : {}), phase: "auto-resume", runId: result.runId });
|
|
1624
|
+
traceChanged();
|
|
1625
|
+
return options.launch(key, autoResumeParams, childSignal, { admitted: true, batch: batch !== undefined });
|
|
1626
|
+
}
|
|
1627
|
+
finally {
|
|
1628
|
+
launchSemaphore.release();
|
|
1629
|
+
}
|
|
1630
|
+
}, (error) => {
|
|
1631
|
+
if (!childController.signal.aborted)
|
|
1632
|
+
throw error;
|
|
1633
|
+
const reason = childController.signal.reason;
|
|
1634
|
+
return stoppedChildResult(key, reason instanceof Error ? reason.message : typeof reason === "string" ? reason : "Workflow script aborted.");
|
|
1635
|
+
}).then((result) => {
|
|
1636
|
+
let normalized = !result.ok && result.state !== "running" && !result.error ? { ...result, error: result.output } : result;
|
|
1637
|
+
if (resolvedResumeLineage?.length && normalized.runId) {
|
|
1638
|
+
normalized = { ...normalized, continuation: { runIds: [...new Set([...resolvedResumeLineage, normalized.runId])] } };
|
|
1639
|
+
}
|
|
1640
|
+
childStopControllers.delete(key);
|
|
1641
|
+
if (stoppedLaunches.has(key))
|
|
1642
|
+
return children.get(key) ?? normalized;
|
|
1643
|
+
children.set(key, normalized);
|
|
1644
|
+
recordAcceptanceRecoveryBarrier(key, normalized);
|
|
1645
|
+
const state = normalized.state === "running" ? "started" : normalized.ok ? "completed" : normalized.stopped ? "stopped" : normalized.detached ? "detached" : "failed";
|
|
1646
|
+
const settledEntry = { operation: "run", key, state, durationMs: Date.now() - startedAt, ...workflowStringMetadata(params), ...(generatedLaneKey ? { generatedLaneKey } : {}), ...(normalized.agent ? { agent: normalized.agent } : {}), ...(normalized.runId ? { runId: normalized.runId } : {}), ...(!normalized.ok && normalized.state !== "running" ? { error: normalized.error ?? normalized.output } : {}) };
|
|
1647
|
+
if (normalized.reused)
|
|
1648
|
+
settledEntry.reused = true;
|
|
1649
|
+
trace.push(settledEntry);
|
|
1650
|
+
traceChanged();
|
|
1651
|
+
notifyChildSettled(key, normalized);
|
|
1652
|
+
return normalized;
|
|
1653
|
+
}, (error) => {
|
|
1654
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
1655
|
+
const failure = { key, ok: false, output: text, error: text, artifactPaths: [] };
|
|
1656
|
+
childStopControllers.delete(key);
|
|
1657
|
+
if (stoppedLaunches.has(key))
|
|
1658
|
+
return children.get(key) ?? { ...failure, stopped: true };
|
|
1659
|
+
children.set(key, failure);
|
|
1660
|
+
trace.push({ operation: "run", key, state: "failed", durationMs: Date.now() - startedAt, ...workflowStringMetadata(params), ...(generatedLaneKey ? { generatedLaneKey } : {}), error: text });
|
|
1661
|
+
traceChanged();
|
|
1662
|
+
notifyChildSettled(key, failure);
|
|
1663
|
+
return failure;
|
|
1664
|
+
});
|
|
1665
|
+
launches.set(key, { fingerprint, promise, observed: callObserved, ...(generatedLaneKey ? { generatedLaneKey } : {}) });
|
|
1666
|
+
childOrder.push(key);
|
|
1667
|
+
trace.push({ operation: "run", key, state: "started", ...workflowStringMetadata(params), ...(generatedLaneKey ? { generatedLaneKey } : {}) });
|
|
1668
|
+
traceChanged();
|
|
1669
|
+
respond(deliver(promise), `runs.run('${key}') result`, (error) => children.set(key, responseBoundaryFailure(key, error)));
|
|
1670
|
+
});
|
|
1671
|
+
worker.postMessage({ type: "start", script: options.script, ...(options.args ? { args: options.args } : {}), stateEnabled: options.state !== undefined });
|
|
1672
|
+
});
|
|
1673
|
+
}
|