minimal-agent 0.12.0 → 0.14.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/README.md +6 -5
- package/package.json +62 -5
- package/plugins/computer_use/.claude-plugin/plugin.json +1 -1
- package/plugins/cron-runner/src/commands.js +4 -4
- package/plugins/cron-runner/src/commands.ts +4 -4
- package/plugins/workflow-runner/.claude-plugin/plugin.json +2 -2
- package/plugins/workflow-runner/commands/workflow.md +57 -90
- package/plugins/workflow-runner/commands/workflows.md +4 -4
- package/plugins/workflow-runner/plugin.js +24 -13
- package/plugins/workflow-runner/plugin.ts +28 -13
- package/plugins/workflow-runner/src/discovery.js +160 -0
- package/plugins/workflow-runner/src/discovery.ts +194 -0
- package/plugins/workflow-runner/src/goalAnchor.js +53 -0
- package/plugins/workflow-runner/src/goalAnchor.ts +59 -0
- package/plugins/workflow-runner/src/index.js +204 -185
- package/plugins/workflow-runner/src/index.ts +249 -224
- package/plugins/workflow-runner/src/inputCoercion.js +40 -0
- package/plugins/workflow-runner/src/inputCoercion.ts +43 -0
- package/plugins/workflow-runner/src/journal.js +224 -0
- package/plugins/workflow-runner/src/journal.ts +274 -0
- package/plugins/workflow-runner/src/jsonSchema.js +132 -0
- package/plugins/workflow-runner/src/jsonSchema.ts +162 -0
- package/plugins/workflow-runner/src/moduleResolution.js +64 -0
- package/plugins/workflow-runner/src/moduleResolution.ts +71 -0
- package/plugins/workflow-runner/src/resourceInputs.js +220 -0
- package/plugins/workflow-runner/src/resourceInputs.ts +300 -0
- package/plugins/workflow-runner/src/runner.js +404 -467
- package/plugins/workflow-runner/src/runner.ts +491 -535
- package/plugins/workflow-runner/src/runtime/config.js +46 -0
- package/plugins/workflow-runner/src/runtime/config.ts +69 -0
- package/plugins/workflow-runner/src/runtime/context.js +1304 -0
- package/plugins/workflow-runner/src/runtime/context.ts +1786 -0
- package/plugins/workflow-runner/src/runtime/exec.js +34 -0
- package/plugins/workflow-runner/src/runtime/exec.ts +53 -0
- package/plugins/workflow-runner/src/runtime/flow.js +8 -0
- package/plugins/workflow-runner/src/runtime/flow.ts +12 -0
- package/plugins/workflow-runner/src/runtime/fs.js +27 -0
- package/plugins/workflow-runner/src/runtime/fs.ts +41 -0
- package/plugins/workflow-runner/src/runtime/model.js +6 -0
- package/plugins/workflow-runner/src/runtime/model.ts +8 -0
- package/plugins/workflow-runner/src/runtime/output.js +7 -0
- package/plugins/workflow-runner/src/runtime/output.ts +21 -0
- package/plugins/workflow-runner/src/runtime/scheduler.js +141 -0
- package/plugins/workflow-runner/src/runtime/scheduler.ts +166 -0
- package/plugins/workflow-runner/src/runtime/state.js +16 -0
- package/plugins/workflow-runner/src/runtime/state.ts +19 -0
- package/plugins/workflow-runner/src/runtime/tools.js +3 -0
- package/plugins/workflow-runner/src/runtime/tools.ts +6 -0
- package/plugins/workflow-runner/src/sandbox.js +141 -0
- package/plugins/workflow-runner/src/sandbox.ts +182 -0
- package/plugins/workflow-runner/src/scriptGuard.d.mts +38 -0
- package/plugins/workflow-runner/src/scriptGuard.mjs +449 -0
- package/plugins/workflow-runner/src/taskIdentity.js +172 -152
- package/plugins/workflow-runner/src/taskIdentity.ts +233 -200
- package/plugins/workflow-runner/src/toolRuntime.js +29 -8
- package/plugins/workflow-runner/src/toolRuntime.ts +36 -11
- package/plugins/workflow-runner/src/types.js +7 -105
- package/plugins/workflow-runner/src/types.ts +155 -520
- package/plugins/workflow-runner/src/util.js +47 -0
- package/plugins/workflow-runner/src/util.ts +51 -0
- package/plugins/workflow-runner/src/workflowContext.js +20 -0
- package/plugins/workflow-runner/src/workflowContext.ts +58 -0
- package/plugins/workflow-runner/src/workflowDependencies.js +36 -0
- package/plugins/workflow-runner/src/workflowDependencies.ts +59 -0
- package/plugins/workflow-runner/src/workflowFingerprint.js +118 -0
- package/plugins/workflow-runner/src/workflowFingerprint.ts +122 -0
- package/plugins/workflow-runner/src/workflowState.js +542 -469
- package/plugins/workflow-runner/src/workflowState.ts +639 -589
- package/plugins/workflow-runner/test/api.test.ts +223 -0
- package/plugins/workflow-runner/test/apiCapabilities.test.ts +614 -0
- package/plugins/workflow-runner/test/apiConcurrencyGate.test.ts +104 -0
- package/plugins/workflow-runner/test/apiEcho.test.ts +210 -0
- package/plugins/workflow-runner/test/apiReadText.test.ts +178 -0
- package/plugins/workflow-runner/test/apiResourceLedger.test.ts +184 -0
- package/plugins/workflow-runner/test/childWorkflow.test.ts +304 -0
- package/plugins/workflow-runner/test/discovery.test.ts +234 -0
- package/plugins/workflow-runner/test/goalAnchor.test.ts +106 -0
- package/plugins/workflow-runner/test/goalController.test.ts +317 -0
- package/plugins/workflow-runner/test/journalLanes.test.ts +198 -0
- package/plugins/workflow-runner/test/listResources.test.ts +106 -0
- package/plugins/workflow-runner/test/resourceInputs.test.ts +294 -0
- package/plugins/workflow-runner/test/sandbox.test.ts +126 -0
- package/plugins/workflow-runner/test/scheduler.test.ts +70 -0
- package/plugins/workflow-runner/test/scriptGuard.test.ts +276 -0
- package/plugins/workflow-runner/test/skillDocSync.test.ts +78 -0
- package/plugins/workflow-runner/test/taskIdentity.test.ts +288 -179
- package/plugins/workflow-runner/test/workflowFingerprint.test.ts +106 -0
- package/plugins/workflow-runner/test/workflowState.test.ts +429 -0
- package/skills/pptx/examples/assets/cover-bg.svg +23 -0
- package/skills/pptx/examples/assets/icon-spark.svg +5 -0
- package/skills/skill-creator/scripts/run_eval.py +3 -2
- package/skills/ui-design/SKILL.md +5 -2
- package/skills/ui-design/references/layout-composition.md +1 -1
- package/skills/workflow-creator/SKILL.md +344 -0
- package/skills/workflow-creator/assets/template/workflow.mjs +48 -0
- package/skills/workflow-creator/references/api.md +216 -0
- package/skills/workflow-creator/references/migration.md +103 -0
- package/skills/workflow-creator/references/patterns.md +779 -0
- package/skills/workflow-creator/scripts/list-resources.mjs +205 -0
- package/skills/workflow-creator/scripts/scaffold.mjs +148 -0
- package/skills/workflow-creator/scripts/validate.mjs +275 -0
- package/skills/workflow-creator/scripts/workflow-creator.test.mjs +82 -0
- package/src/advisor/advisorCoordinator.js +503 -0
- package/src/advisor/advisorCoordinator.ts +657 -0
- package/src/cli/configMenu.tsx +0 -1
- package/src/cli/print.js +44 -6
- package/src/cli/print.ts +73 -4
- package/src/cli/streamJson.js +5 -6
- package/src/cli/streamJson.ts +8 -4
- package/src/cli/wizards/advisorWizard.js +4 -2
- package/src/cli/wizards/advisorWizard.tsx +8 -2
- package/src/cli/wizards/contextAdvisorWizard.js +5 -4
- package/src/cli/wizards/contextAdvisorWizard.tsx +7 -6
- package/src/collaboration/taskFlow.js +115 -0
- package/src/collaboration/taskFlow.ts +169 -0
- package/src/config/configDefaults.js +41 -1
- package/src/config/configDefaults.ts +43 -1
- package/src/config/configDiagnostics.ts +2 -2
- package/src/config/configFile.js +40 -9
- package/src/config/configFile.ts +60 -11
- package/src/config/configService.js +443 -74
- package/src/config/configService.ts +723 -142
- package/src/config/numericLimits.js +22 -0
- package/src/config/numericLimits.ts +24 -0
- package/src/config.js +1 -0
- package/src/config.ts +3 -2
- package/src/context/budgetPlan.js +1 -1
- package/src/context/budgetPlan.ts +1 -1
- package/src/context/compact.js +7 -2
- package/src/context/compact.ts +9 -2
- package/src/context/microCompactLite.js +212 -13
- package/src/context/microCompactLite.ts +261 -12
- package/src/context/sessionRegistry.js +8 -1
- package/src/context/sessionRegistry.ts +18 -5
- package/src/context/toolResultArchive.js +72 -0
- package/src/context/toolResultArchive.ts +95 -0
- package/src/goal/errors.js +8 -0
- package/src/goal/errors.ts +18 -0
- package/src/goal/goalRuntime.js +344 -0
- package/src/goal/goalRuntime.ts +466 -0
- package/src/goal/goalStore.js +200 -0
- package/src/goal/goalStore.ts +219 -0
- package/src/goal/index.js +4 -0
- package/src/goal/index.ts +4 -0
- package/src/goal/statusMapping.js +71 -0
- package/src/goal/statusMapping.ts +95 -0
- package/src/goal/types.js +7 -0
- package/src/goal/types.ts +179 -0
- package/src/goal/workflowController.js +306 -0
- package/src/goal/workflowController.ts +360 -0
- package/src/harness/evidenceLedger.js +2 -0
- package/src/harness/evidenceLedger.ts +1 -0
- package/src/harness/stallGuard.js +9 -3
- package/src/harness/stallGuard.ts +7 -3
- package/src/images/imageResolver.js +161 -0
- package/src/images/imageResolver.ts +189 -0
- package/src/infra/verification.js +56 -20
- package/src/infra/verification.ts +87 -20
- package/src/llm/client.js +79 -21
- package/src/llm/client.ts +182 -35
- package/src/llm/gatewayClient.js +201 -0
- package/src/llm/gatewayClient.ts +299 -0
- package/src/llm/messageProvenance.js +46 -0
- package/src/llm/messageProvenance.ts +58 -0
- package/src/llm/modelProvider.js +1 -0
- package/src/llm/modelProvider.ts +22 -0
- package/src/llm/providers/anthropicFormat.js +108 -1
- package/src/llm/providers/anthropicFormat.ts +115 -4
- package/src/llm/providers/openaiFormat.js +9 -0
- package/src/llm/providers/openaiFormat.ts +12 -3
- package/src/loop.js +319 -54
- package/src/loop.ts +373 -57
- package/src/main.js +4 -1
- package/src/main.tsx +4 -1
- package/src/managedExecution/index.js +2 -0
- package/src/managedExecution/index.ts +2 -0
- package/src/managedExecution/registry.js +15 -0
- package/src/managedExecution/registry.ts +20 -0
- package/src/managedExecution/types.js +1 -0
- package/src/managedExecution/types.ts +86 -0
- package/src/modelRef.js +9 -0
- package/src/modelRef.ts +31 -0
- package/src/multimodal.js +14 -28
- package/src/multimodal.ts +17 -33
- package/src/net/lanDiscovery.js +65 -0
- package/src/net/lanDiscovery.ts +82 -0
- package/src/plugin-sdk.js +28 -3
- package/src/plugin-sdk.ts +39 -6
- package/src/plugins/pluginApi.ts +16 -1
- package/src/plugins/pluginLoader.js +4 -0
- package/src/plugins/pluginLoader.ts +6 -0
- package/src/plugins/pluginRunner.js +152 -9
- package/src/plugins/pluginRunner.ts +186 -8
- package/src/plugins/slashFallback.js +113 -0
- package/src/plugins/slashFallback.ts +137 -0
- package/src/prompts/policyRegistry.js +15 -8
- package/src/prompts/policyRegistry.ts +18 -8
- package/src/prompts/promptAssembly.js +103 -12
- package/src/prompts/promptAssembly.ts +114 -12
- package/src/prompts/skillList.js +21 -3
- package/src/prompts/skillList.ts +27 -2
- package/src/prompts/stableSystemPrompt.js +18 -0
- package/src/prompts/stableSystemPrompt.ts +33 -0
- package/src/runtime/agentRuntimeContext.js +8 -2
- package/src/runtime/agentRuntimeContext.ts +17 -4
- package/src/session/runAgentTurn.js +78 -12
- package/src/session/runAgentTurn.ts +105 -23
- package/src/session/runTurn.js +10 -9
- package/src/session/runTurn.ts +17 -8
- package/src/session/sessionState.ts +2 -0
- package/src/team/auth.js +186 -0
- package/src/team/auth.ts +298 -0
- package/src/team/cli.js +105 -0
- package/src/team/cli.ts +122 -0
- package/src/team/onlineToolContract.js +64 -0
- package/src/team/onlineToolContract.ts +109 -0
- package/src/team/toolPolicy.js +36 -0
- package/src/team/toolPolicy.ts +75 -0
- package/src/tools/advisor/advisor.js +148 -37
- package/src/tools/advisor/advisor.ts +161 -38
- package/src/tools/advisor/advisorDecision.js +71 -0
- package/src/tools/advisor/advisorDecision.ts +85 -0
- package/src/tools/agent/agent.js +18 -5
- package/src/tools/agent/agent.ts +21 -7
- package/src/tools/agent/agentControl.js +246 -0
- package/src/tools/agent/agentControl.ts +284 -0
- package/src/tools/agent/agentTaskService.js +40 -1
- package/src/tools/agent/agentTaskService.ts +44 -1
- package/src/tools/agent/agentTypes.js +14 -2
- package/src/tools/agent/agentTypes.ts +15 -2
- package/src/tools/applypatch/applyPatch.js +362 -0
- package/src/tools/applypatch/applyPatch.ts +428 -0
- package/src/tools/bash/bash.js +70 -18
- package/src/tools/bash/bash.ts +75 -20
- package/src/tools/capabilities.js +10 -5
- package/src/tools/capabilities.ts +10 -5
- package/src/tools/computeruse/computerIntent.js +32 -0
- package/src/tools/computeruse/computerIntent.ts +46 -0
- package/src/tools/computeruse/telemetryLog.js +12 -0
- package/src/tools/computeruse/telemetryLog.ts +16 -0
- package/src/tools/computeruse/vision/telemetry.js +1 -0
- package/src/tools/computeruse/vision/telemetry.ts +1 -0
- package/src/tools/effectiveToolSet.js +4 -0
- package/src/tools/effectiveToolSet.ts +4 -0
- package/src/tools/index.js +21 -2
- package/src/tools/index.ts +33 -2
- package/src/tools/powershell/powershell.js +18 -1
- package/src/tools/powershell/powershell.ts +18 -2
- package/src/tools/presentresult/presentresult.js +6 -15
- package/src/tools/presentresult/presentresult.ts +6 -15
- package/src/tools/read/read.js +69 -11
- package/src/tools/read/read.ts +70 -11
- package/src/tools/shared/fileUtils.js +1 -2
- package/src/tools/shared/fileUtils.ts +1 -2
- package/src/tools/shared/permanentDeleteGuard.js +34 -3
- package/src/tools/shared/permanentDeleteGuard.ts +43 -6
- package/src/tools/shared/toolOutputStore.js +23 -1
- package/src/tools/shared/toolOutputStore.ts +22 -1
- package/src/tools/skill/skill.js +9 -3
- package/src/tools/skill/skill.ts +8 -4
- package/src/tools/toolPromptGuides.js +117 -0
- package/src/tools/toolPromptGuides.ts +137 -0
- package/src/tools/webbrowser/agentBrowserPath.js +19 -9
- package/src/tools/webbrowser/agentBrowserPath.ts +70 -28
- package/src/tools/webbrowser/browser.js +27 -11
- package/src/tools/webbrowser/browser.ts +68 -24
- package/src/tools/webbrowser/browserAutomation.js +329 -0
- package/src/tools/webbrowser/browserAutomation.ts +467 -0
- package/src/tools/webbrowser/browserAxState.js +97 -0
- package/src/tools/webbrowser/browserAxState.ts +142 -0
- package/src/tools/webbrowser/browserBatch.js +1578 -0
- package/src/tools/webbrowser/browserBatch.ts +2382 -0
- package/src/tools/webbrowser/browserCdp.js +208 -0
- package/src/tools/webbrowser/browserCdp.ts +255 -0
- package/src/tools/webbrowser/browserConditions.js +24 -0
- package/src/tools/webbrowser/browserConditions.ts +45 -0
- package/src/tools/webbrowser/browserContent.js +281 -0
- package/src/tools/webbrowser/browserContent.ts +438 -0
- package/src/tools/webbrowser/browserControl.js +131 -30
- package/src/tools/webbrowser/browserControl.ts +210 -50
- package/src/tools/webbrowser/browserDaemon.js +22 -14
- package/src/tools/webbrowser/browserDaemon.ts +54 -21
- package/src/tools/webbrowser/browserFrames.js +47 -0
- package/src/tools/webbrowser/browserFrames.ts +54 -0
- package/src/tools/webbrowser/browserInteractionResolver.js +17 -0
- package/src/tools/webbrowser/browserInteractionResolver.ts +40 -0
- package/src/tools/webbrowser/browserLocator.js +140 -0
- package/src/tools/webbrowser/browserLocator.ts +194 -0
- package/src/tools/webbrowser/browserOutcome.js +10 -17
- package/src/tools/webbrowser/browserOutcome.ts +48 -31
- package/src/tools/webbrowser/browserRecovery.js +58 -0
- package/src/tools/webbrowser/browserRecovery.ts +83 -0
- package/src/tools/webbrowser/browserRunRegistry.js +35 -3
- package/src/tools/webbrowser/browserRunRegistry.ts +91 -15
- package/src/tools/webbrowser/browserService.js +28 -2
- package/src/tools/webbrowser/browserService.ts +49 -9
- package/src/tools/webbrowser/browserStream.js +132 -33
- package/src/tools/webbrowser/browserStream.ts +224 -50
- package/src/tools/webbrowser/browserTabs.js +48 -15
- package/src/tools/webbrowser/browserTabs.ts +178 -96
- package/src/tools/webbrowser/webbrowser.js +683 -144
- package/src/tools/webbrowser/webbrowser.ts +979 -236
- package/src/tools/webfetch/preapproved.js +0 -2
- package/src/tools/webfetch/preapproved.ts +0 -2
- package/src/tools/websearch/websearch.js +129 -8
- package/src/tools/websearch/websearch.ts +138 -6
- package/src/types.ts +450 -42
- package/src/ui/App.js +377 -58
- package/src/ui/App.tsx +576 -111
- package/src/ui/LiveArea.js +14 -8
- package/src/ui/LiveArea.tsx +14 -10
- package/src/ui/MessageList.js +63 -20
- package/src/ui/MessageList.tsx +101 -16
- package/src/ui/ModelPicker.js +7 -4
- package/src/ui/ModelPicker.tsx +55 -8
- package/src/ui/hooks/useChat.js +152 -163
- package/src/ui/hooks/useChat.ts +396 -334
- package/src/ui/loginCommand.js +56 -0
- package/src/ui/loginCommand.ts +63 -0
- package/src/ui/toolProgress.js +41 -0
- package/src/ui/toolProgress.ts +44 -0
- package/src/web/browserBridge.js +20 -2
- package/src/web/browserBridge.ts +20 -2
- package/src/web/protocol.ts +1897 -194
- package/workflows/adaptive-research/workflow.mjs +86 -0
- package/workflows/e2e-capabilities/workflow.mjs +102 -0
- package/workflows/e2e-llm/workflow.mjs +52 -0
- package/workflows/e2e-smoke/workflow.mjs +59 -0
- package/workflows/e2e-vision-schema/README.md +48 -0
- package/workflows/e2e-vision-schema/workflow.mjs +149 -0
- package/workflows/e2e-write-greet/workflow.mjs +37 -0
- package/workflows/file-census/README.md +14 -0
- package/workflows/file-census/scripts/.gitkeep +2 -0
- package/workflows/file-census/workflow.mjs +110 -0
- package/workflows/goal/README.md +166 -0
- package/workflows/goal/prompts/audit.md +57 -0
- package/workflows/goal/prompts/contract.md +56 -0
- package/workflows/goal/prompts/iterate.md +37 -0
- package/workflows/goal/workflow.mjs +501 -0
- package/workflows/illustrate/README.md +90 -0
- package/workflows/illustrate/assets/engines.json +20 -0
- package/workflows/illustrate/assets/extract-baidu.js +21 -0
- package/workflows/illustrate/assets/extract-bing.js +33 -0
- package/workflows/illustrate/assets/extract-google.js +31 -0
- package/workflows/illustrate/workflow.mjs +301 -0
- package/workflows/plan/workflow.mjs +389 -0
- package/workflows/question-crops/README.md +35 -0
- package/workflows/question-crops/prompts/inventory.md +23 -0
- package/workflows/question-crops/scripts/image-ops.mjs +305 -0
- package/workflows/question-crops/scripts/image-ops.test.mjs +95 -0
- package/workflows/question-crops/workflow.mjs +172 -0
- package/workflows/ralph-loop/workflow.mjs +162 -0
- package/workflows/research/DESIGN.md +449 -0
- package/workflows/research/README.md +74 -0
- package/workflows/research/prompts/s0-goal.md +43 -0
- package/workflows/research/prompts/s1-early-exit.md +22 -0
- package/workflows/research/prompts/s1-map.md +58 -0
- package/workflows/research/prompts/s2-options.md +53 -0
- package/workflows/research/prompts/s3-deep-dive.md +56 -0
- package/workflows/research/prompts/s4-verify.md +74 -0
- package/workflows/research/prompts/s5-synthesis.md +81 -0
- package/workflows/research/prompts/s5b-fill-gaps.md +32 -0
- package/workflows/research/prompts/s6-package.md +32 -0
- package/workflows/research/scripts/build-report.mjs +98 -0
- package/workflows/research/workflow.mjs +288 -0
- package/workflows/wechat-reading-shots/prompts/collect-params.md +16 -0
- package/workflows/wechat-reading-shots/prompts/evaluate.md +20 -0
- package/workflows/wechat-reading-shots/prompts/open-book.md +28 -0
- package/workflows/wechat-reading-shots/prompts/read-page.md +13 -0
- package/workflows/wechat-reading-shots/prompts/turn-batch.md +24 -0
- package/workflows/wechat-reading-shots/test/control-flow.test.ts +329 -0
- package/workflows/wechat-reading-shots/workflow.mjs +266 -0
- package/workflows/wrong-question-docx/README.md +55 -0
- package/workflows/wrong-question-docx/prompts/figure-qa.md +8 -0
- package/workflows/wrong-question-docx/prompts/transcribe.md +25 -0
- package/workflows/wrong-question-docx/scripts/workbook.mjs +857 -0
- package/workflows/wrong-question-docx/test/control-flow.test.ts +165 -0
- package/workflows/wrong-question-docx/test/workbook.test.mjs +303 -0
- package/workflows/wrong-question-docx/workflow.mjs +485 -0
- package/plugins/workflow-runner/src/agentCommon.js +0 -354
- package/plugins/workflow-runner/src/agentCommon.ts +0 -435
- package/plugins/workflow-runner/src/controlFlow/branch.js +0 -40
- package/plugins/workflow-runner/src/controlFlow/branch.ts +0 -46
- package/plugins/workflow-runner/src/controlFlow/loop.js +0 -211
- package/plugins/workflow-runner/src/controlFlow/loop.ts +0 -248
- package/plugins/workflow-runner/src/controlFlow/pause.js +0 -129
- package/plugins/workflow-runner/src/controlFlow/pause.ts +0 -141
- package/plugins/workflow-runner/src/controlFlow/signal.js +0 -21
- package/plugins/workflow-runner/src/controlFlow/signal.ts +0 -29
- package/plugins/workflow-runner/src/controlFlow/types.js +0 -18
- package/plugins/workflow-runner/src/controlFlow/types.ts +0 -63
- package/plugins/workflow-runner/src/dslManifest.js +0 -72
- package/plugins/workflow-runner/src/dslManifest.ts +0 -127
- package/plugins/workflow-runner/src/expressions.js +0 -618
- package/plugins/workflow-runner/src/expressions.ts +0 -622
- package/plugins/workflow-runner/src/loader.js +0 -573
- package/plugins/workflow-runner/src/loader.ts +0 -721
- package/plugins/workflow-runner/src/multimodal.js +0 -38
- package/plugins/workflow-runner/src/multimodal.ts +0 -64
- package/plugins/workflow-runner/src/recovery.js +0 -119
- package/plugins/workflow-runner/src/recovery.ts +0 -149
- package/plugins/workflow-runner/src/stepExecutors/agent.js +0 -173
- package/plugins/workflow-runner/src/stepExecutors/agent.ts +0 -234
- package/plugins/workflow-runner/src/stepExecutors/assert.js +0 -41
- package/plugins/workflow-runner/src/stepExecutors/assert.ts +0 -50
- package/plugins/workflow-runner/src/stepExecutors/echo.js +0 -31
- package/plugins/workflow-runner/src/stepExecutors/echo.ts +0 -38
- package/plugins/workflow-runner/src/stepExecutors/llm.js +0 -99
- package/plugins/workflow-runner/src/stepExecutors/llm.ts +0 -133
- package/plugins/workflow-runner/src/stepExecutors/set.js +0 -49
- package/plugins/workflow-runner/src/stepExecutors/set.ts +0 -56
- package/plugins/workflow-runner/src/stepExecutors/skill.js +0 -111
- package/plugins/workflow-runner/src/stepExecutors/skill.ts +0 -140
- package/plugins/workflow-runner/src/stepExecutors/tool.js +0 -208
- package/plugins/workflow-runner/src/stepExecutors/tool.ts +0 -256
- package/plugins/workflow-runner/src/stepExecutors/verify.js +0 -58
- package/plugins/workflow-runner/src/stepExecutors/verify.ts +0 -68
- package/plugins/workflow-runner/src/stepPipeline.js +0 -277
- package/plugins/workflow-runner/src/stepPipeline.ts +0 -366
- package/plugins/workflow-runner/test/agent.test.ts +0 -587
- package/plugins/workflow-runner/test/agentLlmError.test.ts +0 -373
- package/plugins/workflow-runner/test/bashBlacklist.sweep.test.ts +0 -65
- package/plugins/workflow-runner/test/captureMisbind.test.ts +0 -99
- package/plugins/workflow-runner/test/cli.e2e.test.ts +0 -147
- package/plugins/workflow-runner/test/context-files.test.ts +0 -320
- package/plugins/workflow-runner/test/e2e.test.ts +0 -370
- package/plugins/workflow-runner/test/engineRobustness.test.ts +0 -226
- package/plugins/workflow-runner/test/expressions.test.ts +0 -397
- package/plugins/workflow-runner/test/foundation.test.ts +0 -126
- package/plugins/workflow-runner/test/graceful.test.ts +0 -139
- package/plugins/workflow-runner/test/greedyInputs.load.test.ts +0 -47
- package/plugins/workflow-runner/test/hostCapability.test.ts +0 -108
- package/plugins/workflow-runner/test/illustrate.load.test.ts +0 -183
- package/plugins/workflow-runner/test/jsonPayload.test.ts +0 -83
- package/plugins/workflow-runner/test/loader.test.ts +0 -617
- package/plugins/workflow-runner/test/maxTurnsRetryDelay.test.ts +0 -33
- package/plugins/workflow-runner/test/multimodal.test.ts +0 -342
- package/plugins/workflow-runner/test/output-schema.test.ts +0 -213
- package/plugins/workflow-runner/test/parseWorkflowArgs.test.ts +0 -87
- package/plugins/workflow-runner/test/pluginRunner.isolation.test.ts +0 -269
- package/plugins/workflow-runner/test/ppt.load.test.ts +0 -1220
- package/plugins/workflow-runner/test/ralphLoop.e2e.test.ts +0 -220
- package/plugins/workflow-runner/test/recovery.test.ts +0 -265
- package/plugins/workflow-runner/test/runner.test.ts +0 -911
- package/plugins/workflow-runner/test/runnerPreflight.test.ts +0 -379
- package/plugins/workflow-runner/test/skillTurnDone.test.ts +0 -71
- package/plugins/workflow-runner/test/stateLifecycle.test.ts +0 -150
- package/plugins/workflow-runner/test/stepPipeline.test.ts +0 -114
- package/plugins/workflow-runner/test/taskArbitration.test.ts +0 -338
- package/plugins/workflow-runner/test/taskLifecycle.test.ts +0 -270
- package/plugins/workflow-runner/test/toolArtifactOverwrite.test.ts +0 -221
- package/plugins/workflow-runner/test/toolCapabilityBoundary.test.ts +0 -29
- package/plugins/workflow-runner/test/toolRuntimeIntegration.test.ts +0 -168
- package/plugins/workflow-runner/test/webppt.load.test.ts +0 -250
- package/plugins/workflow-runner/test/word.load.test.ts +0 -208
- package/plugins/workflow-runner/test/workflows.smoke.test.ts +0 -76
- package/plugins/workflow-runner/test/yamlGuardConditions.test.ts +0 -207
- package/src/advisorState.js +0 -22
- package/src/cli/configWizard.js +0 -293
- package/src/tools/toolProgressBridge.js +0 -48
- package/workflows/adaptive-research.yaml +0 -50
- package/workflows/book-review-short.yaml +0 -125
- package/workflows/e2e-write-greet.yaml +0 -31
- package/workflows/illustrate.yaml +0 -227
- package/workflows/plan.yaml +0 -470
- package/workflows/ppt.yaml +0 -1670
- package/workflows/ralph-loop.yaml +0 -199
- package/workflows/schema.json +0 -176
- package/workflows/webppt.yaml +0 -496
- package/workflows/wechat-reading-shots.yaml +0 -315
- package/workflows/word.yaml +0 -720
- package/workflows/youtube-shorts.yaml +0 -202
|
@@ -1,911 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ============================================================
|
|
3
|
-
* test/workflows/runner.test.ts
|
|
4
|
-
* ------------------------------------------------------------
|
|
5
|
-
* runner P0 行为:
|
|
6
|
-
* - tool / llm / assert step 成功路径
|
|
7
|
-
* - capture 绑变量到 VarStack
|
|
8
|
-
* - when=false → workflow_step_skipped
|
|
9
|
-
* - onError=halt(默认)→ workflow halt + error
|
|
10
|
-
* - onError=continue → 继续下一步
|
|
11
|
-
* - 工作流完成 yield workflow_done
|
|
12
|
-
*
|
|
13
|
-
* 策略:
|
|
14
|
-
* - tool 步骤用真实 Write 工具(写到 tmpdir,避免 mock executeTool)
|
|
15
|
-
* - llm 步骤 mock.module('../../../src/llm/client.js')
|
|
16
|
-
* - assert / when 走纯表达式引擎,无需 mock
|
|
17
|
-
* ============================================================
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import { afterEach, beforeEach, describe, expect, it, mock } from 'bun:test';
|
|
21
|
-
import {
|
|
22
|
-
existsSync,
|
|
23
|
-
mkdirSync,
|
|
24
|
-
mkdtempSync,
|
|
25
|
-
readFileSync,
|
|
26
|
-
rmSync,
|
|
27
|
-
writeFileSync,
|
|
28
|
-
} from 'node:fs';
|
|
29
|
-
import { tmpdir } from 'node:os';
|
|
30
|
-
import { join } from 'node:path';
|
|
31
|
-
|
|
32
|
-
import { _resetWorkingDir } from '../../../src/bootstrap/workingDir.js';
|
|
33
|
-
import { ALL_TOOLS } from '../../../src/tools/index.js';
|
|
34
|
-
import { runWorkflow } from '../src/runner.js';
|
|
35
|
-
import type {
|
|
36
|
-
LoopEvent,
|
|
37
|
-
Provider,
|
|
38
|
-
} from '../../../src/types.js';
|
|
39
|
-
import type {
|
|
40
|
-
RunContext,
|
|
41
|
-
WorkflowDef,
|
|
42
|
-
WorkflowEvent,
|
|
43
|
-
} from '../src/types.js';
|
|
44
|
-
|
|
45
|
-
type WfOrLoop = WorkflowEvent | LoopEvent;
|
|
46
|
-
|
|
47
|
-
const fakeProvider: Provider = {
|
|
48
|
-
name: 'test',
|
|
49
|
-
baseURL: '',
|
|
50
|
-
apiKey: '',
|
|
51
|
-
model: 'm',
|
|
52
|
-
contextWindow: 128000,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
async function collect(
|
|
56
|
-
gen: AsyncGenerator<WfOrLoop, void, void>,
|
|
57
|
-
): Promise<WfOrLoop[]> {
|
|
58
|
-
const out: WfOrLoop[] = [];
|
|
59
|
-
for await (const ev of gen) out.push(ev);
|
|
60
|
-
return out;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
describe('workflows/runner', () => {
|
|
64
|
-
let tmp: string;
|
|
65
|
-
let ctx: RunContext;
|
|
66
|
-
|
|
67
|
-
beforeEach(() => {
|
|
68
|
-
tmp = mkdtempSync(join(tmpdir(), 'wf-runner-'));
|
|
69
|
-
process.env.MINIMAL_AGENT_CWD = tmp;
|
|
70
|
-
_resetWorkingDir();
|
|
71
|
-
// 抵抗 pluginRunner.test.ts 等遗留的 workingDir.ts mock 全局污染
|
|
72
|
-
mock.module('../../../src/bootstrap/workingDir.js', () => ({
|
|
73
|
-
getWorkingDir: () => tmp,
|
|
74
|
-
initWorkingDir: () => tmp,
|
|
75
|
-
_resetWorkingDir: () => {},
|
|
76
|
-
}));
|
|
77
|
-
ctx = { provider: fakeProvider, history: [], cwd: tmp, tools: ALL_TOOLS };
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
afterEach(() => {
|
|
81
|
-
delete process.env.MINIMAL_AGENT_CWD;
|
|
82
|
-
_resetWorkingDir();
|
|
83
|
-
rmSync(tmp, { recursive: true, force: true });
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('线性 assert step 全通过 → workflow_done', async () => {
|
|
87
|
-
const def: WorkflowDef = {
|
|
88
|
-
name: 'pure-assert',
|
|
89
|
-
description: 'd',
|
|
90
|
-
steps: [
|
|
91
|
-
{ id: 's1', type: 'assert', condition: '1 == 1' },
|
|
92
|
-
{ id: 's2', type: 'assert', condition: '"a" != "b"' },
|
|
93
|
-
],
|
|
94
|
-
};
|
|
95
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
96
|
-
const types = events.map((e) => e.type);
|
|
97
|
-
expect(types[0]).toBe('workflow_start');
|
|
98
|
-
expect(types.filter((t) => t === 'workflow_step_end').length).toBe(2);
|
|
99
|
-
// v0.9 后 workflow 完成时可能在 workflow_done 前插入 assistant_message 等事件,
|
|
100
|
-
// 不再保证 workflow_done 严格是末位事件,改用 contains 检查存在性。
|
|
101
|
-
expect(types).toContain('workflow_done');
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('assert 失败 → halt + error 事件', async () => {
|
|
105
|
-
const def: WorkflowDef = {
|
|
106
|
-
name: 'assert-fail',
|
|
107
|
-
description: 'd',
|
|
108
|
-
steps: [
|
|
109
|
-
{ id: 's1', type: 'assert', condition: '1 == 2', onFail: 'nope' },
|
|
110
|
-
{ id: 's2', type: 'assert', condition: 'true' }, // 不应执行
|
|
111
|
-
],
|
|
112
|
-
};
|
|
113
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
114
|
-
expect(events.some((e) => e.type === 'error')).toBe(true);
|
|
115
|
-
// s2 不应有 step_start
|
|
116
|
-
const startedIds = events
|
|
117
|
-
.filter((e): e is Extract<WorkflowEvent, { type: 'workflow_step_start' }> => e.type === 'workflow_step_start')
|
|
118
|
-
.map((e) => e.id);
|
|
119
|
-
expect(startedIds).toEqual(['s1']);
|
|
120
|
-
// 没 workflow_done
|
|
121
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(false);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('onError=continue → 失败后继续下一步', async () => {
|
|
125
|
-
const def: WorkflowDef = {
|
|
126
|
-
name: 'continue',
|
|
127
|
-
description: 'd',
|
|
128
|
-
steps: [
|
|
129
|
-
{ id: 's1', type: 'assert', condition: 'false', onError: 'continue' },
|
|
130
|
-
{ id: 's2', type: 'assert', condition: 'true' },
|
|
131
|
-
],
|
|
132
|
-
};
|
|
133
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
134
|
-
const ends = events.filter(
|
|
135
|
-
(e): e is Extract<WorkflowEvent, { type: 'workflow_step_end' }> => e.type === 'workflow_step_end',
|
|
136
|
-
);
|
|
137
|
-
expect(ends.length).toBe(2);
|
|
138
|
-
expect(ends[0].ok).toBe(false);
|
|
139
|
-
expect(ends[1].ok).toBe(true);
|
|
140
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('when=false → workflow_step_skipped 而不是 step_start', async () => {
|
|
144
|
-
const def: WorkflowDef = {
|
|
145
|
-
name: 'skip',
|
|
146
|
-
description: 'd',
|
|
147
|
-
inputs: [{ name: 'flag', type: 'string' }],
|
|
148
|
-
steps: [
|
|
149
|
-
{
|
|
150
|
-
id: 's1',
|
|
151
|
-
type: 'assert',
|
|
152
|
-
condition: 'true',
|
|
153
|
-
when: 'inputs.flag == "yes"',
|
|
154
|
-
},
|
|
155
|
-
{ id: 's2', type: 'assert', condition: 'true' },
|
|
156
|
-
],
|
|
157
|
-
};
|
|
158
|
-
const events = await collect(runWorkflow(def, { flag: 'no' }, ctx));
|
|
159
|
-
const skipped = events.find((e) => e.type === 'workflow_step_skipped');
|
|
160
|
-
expect(skipped).toBeDefined();
|
|
161
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('tool step 写文件 + ${var} 插值(用真实 Write 工具)', async () => {
|
|
165
|
-
const def: WorkflowDef = {
|
|
166
|
-
name: 'wr',
|
|
167
|
-
description: 'd',
|
|
168
|
-
inputs: [{ name: 'book', type: 'string' }],
|
|
169
|
-
steps: [
|
|
170
|
-
{
|
|
171
|
-
id: 'w',
|
|
172
|
-
tool: 'Write',
|
|
173
|
-
args: {
|
|
174
|
-
file_path: 'videos/${inputs.book}/x.txt',
|
|
175
|
-
content: 'hello ${inputs.book}',
|
|
176
|
-
},
|
|
177
|
-
},
|
|
178
|
-
],
|
|
179
|
-
};
|
|
180
|
-
const events = await collect(runWorkflow(def, { book: '原则' }, ctx));
|
|
181
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
182
|
-
|
|
183
|
-
const filePath = join(tmp, 'videos', '原则', 'x.txt');
|
|
184
|
-
expect(existsSync(filePath)).toBe(true);
|
|
185
|
-
expect(readFileSync(filePath, 'utf8')).toBe('hello 原则');
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('声明 artifacts 但最终缺失时不能标记 workflow_done', async () => {
|
|
189
|
-
const def: WorkflowDef = {
|
|
190
|
-
name: 'missing-artifact',
|
|
191
|
-
description: 'd',
|
|
192
|
-
artifacts: ['expected.txt'],
|
|
193
|
-
steps: [{ id: 'noop', type: 'assert', condition: 'true' }],
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
197
|
-
|
|
198
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(false);
|
|
199
|
-
expect(
|
|
200
|
-
events.some(
|
|
201
|
-
(e) =>
|
|
202
|
-
e.type === 'error' &&
|
|
203
|
-
e.error.includes('工作流声明的产物缺失') &&
|
|
204
|
-
e.error.includes('expected.txt'),
|
|
205
|
-
),
|
|
206
|
-
).toBe(true);
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it('capture 把 tool 结果绑到变量,下一步 assert 能用', async () => {
|
|
210
|
-
const def: WorkflowDef = {
|
|
211
|
-
name: 'cap',
|
|
212
|
-
description: 'd',
|
|
213
|
-
steps: [
|
|
214
|
-
{
|
|
215
|
-
id: 'w',
|
|
216
|
-
tool: 'Write',
|
|
217
|
-
args: { file_path: 'a.txt', content: 'data' },
|
|
218
|
-
capture: { content: 'last_write_content' },
|
|
219
|
-
},
|
|
220
|
-
{
|
|
221
|
-
id: 'check',
|
|
222
|
-
type: 'assert',
|
|
223
|
-
condition: 'length(last_write_content) > 0',
|
|
224
|
-
},
|
|
225
|
-
],
|
|
226
|
-
};
|
|
227
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
228
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it('未知 tool → halt + error', async () => {
|
|
232
|
-
const def: WorkflowDef = {
|
|
233
|
-
name: 'badtool',
|
|
234
|
-
description: 'd',
|
|
235
|
-
steps: [{ id: 'x', tool: 'NoSuchTool9999' }],
|
|
236
|
-
};
|
|
237
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
238
|
-
expect(events.some((e) => e.type === 'error')).toBe(true);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it('llm step 拿 chat 累积文本 + capture text', async () => {
|
|
242
|
-
mock.module('../../../src/llm/client.js', () => ({
|
|
243
|
-
chat: async function* () {
|
|
244
|
-
yield { type: 'text_delta', delta: 'Hello ' };
|
|
245
|
-
yield { type: 'text_delta', delta: 'world' };
|
|
246
|
-
yield { type: 'done', stopReason: 'stop' };
|
|
247
|
-
},
|
|
248
|
-
}));
|
|
249
|
-
|
|
250
|
-
const def: WorkflowDef = {
|
|
251
|
-
name: 'llm-cap',
|
|
252
|
-
description: 'd',
|
|
253
|
-
steps: [
|
|
254
|
-
{
|
|
255
|
-
id: 'g',
|
|
256
|
-
llm: 'irrelevant',
|
|
257
|
-
capture: { text: 'msg' },
|
|
258
|
-
},
|
|
259
|
-
{
|
|
260
|
-
id: 'check',
|
|
261
|
-
type: 'assert',
|
|
262
|
-
condition: 'msg == "Hello world"',
|
|
263
|
-
},
|
|
264
|
-
],
|
|
265
|
-
};
|
|
266
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
267
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
it('workflow_step_start 的 index 与 total 与 steps 长度一致', async () => {
|
|
271
|
-
const def: WorkflowDef = {
|
|
272
|
-
name: 'count',
|
|
273
|
-
description: 'd',
|
|
274
|
-
steps: [
|
|
275
|
-
{ id: 'a', type: 'assert', condition: 'true' },
|
|
276
|
-
{ id: 'b', type: 'assert', condition: 'true' },
|
|
277
|
-
{ id: 'c', type: 'assert', condition: 'true' },
|
|
278
|
-
],
|
|
279
|
-
};
|
|
280
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
281
|
-
const starts = events.filter(
|
|
282
|
-
(e): e is Extract<WorkflowEvent, { type: 'workflow_step_start' }> => e.type === 'workflow_step_start',
|
|
283
|
-
);
|
|
284
|
-
expect(starts.length).toBe(3);
|
|
285
|
-
expect(starts.map((s) => s.index)).toEqual([0, 1, 2]);
|
|
286
|
-
expect(starts.every((s) => s.total === 3)).toBe(true);
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
it('signal.aborted → 立即 interrupted', async () => {
|
|
290
|
-
const ctrl = new AbortController();
|
|
291
|
-
ctrl.abort();
|
|
292
|
-
const def: WorkflowDef = {
|
|
293
|
-
name: 'abort',
|
|
294
|
-
description: 'd',
|
|
295
|
-
steps: [{ id: 'a', type: 'assert', condition: 'true' }],
|
|
296
|
-
};
|
|
297
|
-
const events = await collect(
|
|
298
|
-
runWorkflow(def, {}, { provider: fakeProvider, history: [], signal: ctrl.signal, cwd: tmp, tools: [] }),
|
|
299
|
-
);
|
|
300
|
-
expect(events.some((e) => e.type === 'interrupted')).toBe(true);
|
|
301
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(false);
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
it('P1 branch step:condition=true → 走 then 分支,输出 branch=true', async () => {
|
|
305
|
-
const def: WorkflowDef = {
|
|
306
|
-
name: 'branch-true',
|
|
307
|
-
description: 'd',
|
|
308
|
-
inputs: [{ name: 'x', type: 'number' }],
|
|
309
|
-
steps: [
|
|
310
|
-
{
|
|
311
|
-
id: 'br',
|
|
312
|
-
type: 'branch',
|
|
313
|
-
condition: 'inputs.x > 0',
|
|
314
|
-
then: [
|
|
315
|
-
{
|
|
316
|
-
id: 'then_w',
|
|
317
|
-
tool: 'Write',
|
|
318
|
-
args: { file_path: 'pos.txt', content: 'positive' },
|
|
319
|
-
},
|
|
320
|
-
],
|
|
321
|
-
else: [
|
|
322
|
-
{
|
|
323
|
-
id: 'else_w',
|
|
324
|
-
tool: 'Write',
|
|
325
|
-
args: { file_path: 'neg.txt', content: 'negative' },
|
|
326
|
-
},
|
|
327
|
-
],
|
|
328
|
-
},
|
|
329
|
-
],
|
|
330
|
-
};
|
|
331
|
-
const events = await collect(runWorkflow(def, { x: 5 }, ctx));
|
|
332
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
333
|
-
expect(existsSync(join(tmp, 'pos.txt'))).toBe(true);
|
|
334
|
-
expect(existsSync(join(tmp, 'neg.txt'))).toBe(false);
|
|
335
|
-
const ends = events.filter(
|
|
336
|
-
(e): e is Extract<WorkflowEvent, { type: 'workflow_step_end' }> => e.type === 'workflow_step_end',
|
|
337
|
-
);
|
|
338
|
-
// 至少 then_w (1) + br (1) = 2 个 step_end,且都 ok
|
|
339
|
-
expect(ends.length).toBe(2);
|
|
340
|
-
expect(ends.every((e) => e.ok)).toBe(true);
|
|
341
|
-
const brEnd = ends.find((e) => e.id === 'br');
|
|
342
|
-
expect(brEnd?.output).toBe('branch=true');
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
it('P1 branch step:condition=false → 走 else 分支', async () => {
|
|
346
|
-
const def: WorkflowDef = {
|
|
347
|
-
name: 'branch-false',
|
|
348
|
-
description: 'd',
|
|
349
|
-
inputs: [{ name: 'x', type: 'number' }],
|
|
350
|
-
steps: [
|
|
351
|
-
{
|
|
352
|
-
id: 'br',
|
|
353
|
-
type: 'branch',
|
|
354
|
-
condition: 'inputs.x > 0',
|
|
355
|
-
then: [{ id: 'then_a', type: 'assert', condition: 'true' }],
|
|
356
|
-
else: [
|
|
357
|
-
{
|
|
358
|
-
id: 'else_w',
|
|
359
|
-
tool: 'Write',
|
|
360
|
-
args: { file_path: 'neg.txt', content: 'negative' },
|
|
361
|
-
},
|
|
362
|
-
],
|
|
363
|
-
},
|
|
364
|
-
],
|
|
365
|
-
};
|
|
366
|
-
const events = await collect(runWorkflow(def, { x: -3 }, ctx));
|
|
367
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
368
|
-
expect(existsSync(join(tmp, 'neg.txt'))).toBe(true);
|
|
369
|
-
const brEnd = events.find(
|
|
370
|
-
(e): e is Extract<WorkflowEvent, { type: 'workflow_step_end' }> =>
|
|
371
|
-
e.type === 'workflow_step_end' && e.id === 'br',
|
|
372
|
-
);
|
|
373
|
-
expect(brEnd?.output).toBe('branch=false');
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
it('P1 branch step:缺 then/else 也合法(cond 求值后空跳过)', async () => {
|
|
377
|
-
const def: WorkflowDef = {
|
|
378
|
-
name: 'branch-empty',
|
|
379
|
-
description: 'd',
|
|
380
|
-
steps: [
|
|
381
|
-
{ id: 'br', type: 'branch', condition: '1 == 1' },
|
|
382
|
-
{ id: 's2', type: 'assert', condition: 'true' },
|
|
383
|
-
],
|
|
384
|
-
};
|
|
385
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
386
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
387
|
-
const ids = events
|
|
388
|
-
.filter((e): e is Extract<WorkflowEvent, { type: 'workflow_step_end' }> => e.type === 'workflow_step_end')
|
|
389
|
-
.map((e) => e.id);
|
|
390
|
-
expect(ids).toEqual(['br', 's2']);
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
it('set 步类型保留:单一 ${expr} 保布尔/数字/数组,多片段仍字符串(E2)', async () => {
|
|
394
|
-
const def: WorkflowDef = {
|
|
395
|
-
name: 'typed-set',
|
|
396
|
-
description: 'd',
|
|
397
|
-
steps: [
|
|
398
|
-
{
|
|
399
|
-
id: 'init',
|
|
400
|
-
type: 'set',
|
|
401
|
-
set: { qualified: true, count: 7, label: 'x' },
|
|
402
|
-
},
|
|
403
|
-
{
|
|
404
|
-
id: 'copy',
|
|
405
|
-
type: 'set',
|
|
406
|
-
set: {
|
|
407
|
-
// 单一表达式 → 类型保留
|
|
408
|
-
final_qualified: '${qualified}',
|
|
409
|
-
next_count: '${count + 1}',
|
|
410
|
-
arr: "${split('a,b', ',')}",
|
|
411
|
-
// 多片段模板 → 仍是字符串(向后兼容)
|
|
412
|
-
summary: '${label}-${count}',
|
|
413
|
-
},
|
|
414
|
-
},
|
|
415
|
-
// 布尔直接 == true 可过(不再需要 == 'true' 防御)——这是 E2 的验收标准
|
|
416
|
-
{ id: 'check_bool', type: 'assert', condition: 'final_qualified == true' },
|
|
417
|
-
{ id: 'check_num', type: 'assert', condition: 'next_count == 8' },
|
|
418
|
-
{ id: 'check_arr', type: 'assert', condition: 'length(arr) == 2' },
|
|
419
|
-
{ id: 'check_str', type: 'assert', condition: "summary == 'x-7'" },
|
|
420
|
-
],
|
|
421
|
-
};
|
|
422
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
423
|
-
expect(events.some((e) => e.type === 'error')).toBe(false);
|
|
424
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
it('set 步确定性提取:extract + join 从输出抽 <learning> 标签(E1 落地)', async () => {
|
|
428
|
-
const def: WorkflowDef = {
|
|
429
|
-
name: 'extract-learning',
|
|
430
|
-
description: 'd',
|
|
431
|
-
steps: [
|
|
432
|
-
{
|
|
433
|
-
id: 'fake_output',
|
|
434
|
-
type: 'set',
|
|
435
|
-
set: {
|
|
436
|
-
output:
|
|
437
|
-
'做完了 <learning>坑一</learning> 其它 <learning>坑二</learning>',
|
|
438
|
-
},
|
|
439
|
-
},
|
|
440
|
-
{
|
|
441
|
-
id: 'extract',
|
|
442
|
-
type: 'set',
|
|
443
|
-
set: {
|
|
444
|
-
learning: "${join(extract(output, '<learning>(.*?)</learning>'), '; ')}",
|
|
445
|
-
},
|
|
446
|
-
},
|
|
447
|
-
{ id: 'check', type: 'assert', condition: "learning == '坑一; 坑二'" },
|
|
448
|
-
// 无标签时 extract → [] → join → ''(ralph-loop 的 when 守卫依赖这个语义)
|
|
449
|
-
{
|
|
450
|
-
id: 'extract_none',
|
|
451
|
-
type: 'set',
|
|
452
|
-
set: { none: "${join(extract('无标签文本', '<learning>(.*?)</learning>'), '; ')}" },
|
|
453
|
-
},
|
|
454
|
-
{ id: 'check_none', type: 'assert', condition: "none == ''" },
|
|
455
|
-
],
|
|
456
|
-
};
|
|
457
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
458
|
-
expect(events.some((e) => e.type === 'error')).toBe(false);
|
|
459
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
460
|
-
});
|
|
461
|
-
|
|
462
|
-
it('P1 loop step:over=数组字面量,子步骤用 ${as} 和 ${as}_idx', async () => {
|
|
463
|
-
const def: WorkflowDef = {
|
|
464
|
-
name: 'loop-lit',
|
|
465
|
-
description: 'd',
|
|
466
|
-
steps: [
|
|
467
|
-
{
|
|
468
|
-
id: 'lp',
|
|
469
|
-
type: 'loop',
|
|
470
|
-
over: '["a", "b", "c"]',
|
|
471
|
-
as: 'item',
|
|
472
|
-
do: [
|
|
473
|
-
{
|
|
474
|
-
id: 'w',
|
|
475
|
-
tool: 'Write',
|
|
476
|
-
args: {
|
|
477
|
-
file_path: 'items/${item_idx}-${item}.txt',
|
|
478
|
-
content: 'idx=${item_idx} val=${item}',
|
|
479
|
-
},
|
|
480
|
-
},
|
|
481
|
-
],
|
|
482
|
-
},
|
|
483
|
-
],
|
|
484
|
-
};
|
|
485
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
486
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
487
|
-
for (let i = 0; i < 3; i++) {
|
|
488
|
-
const val = ['a', 'b', 'c'][i];
|
|
489
|
-
const filePath = join(tmp, 'items', `${i}-${val}.txt`);
|
|
490
|
-
expect(existsSync(filePath)).toBe(true);
|
|
491
|
-
expect(readFileSync(filePath, 'utf8')).toBe(`idx=${i} val=${val}`);
|
|
492
|
-
}
|
|
493
|
-
const lpEnd = events.find(
|
|
494
|
-
(e): e is Extract<WorkflowEvent, { type: 'workflow_step_end' }> =>
|
|
495
|
-
e.type === 'workflow_step_end' && e.id === 'lp',
|
|
496
|
-
);
|
|
497
|
-
expect(lpEnd?.output).toBe('loop 3 次');
|
|
498
|
-
});
|
|
499
|
-
|
|
500
|
-
it('P1 loop step:迭代变量在循环外不再可见(push/pop 帧)', async () => {
|
|
501
|
-
const def: WorkflowDef = {
|
|
502
|
-
name: 'loop-scope',
|
|
503
|
-
description: 'd',
|
|
504
|
-
steps: [
|
|
505
|
-
{
|
|
506
|
-
id: 'lp',
|
|
507
|
-
type: 'loop',
|
|
508
|
-
over: '[1, 2]',
|
|
509
|
-
as: 'i',
|
|
510
|
-
do: [{ id: 'noop', type: 'assert', condition: 'i > 0' }],
|
|
511
|
-
},
|
|
512
|
-
// 循环外的 ${i} 已 pop —— 这里把它当字符串拿不到,length()=0
|
|
513
|
-
{ id: 'check', type: 'assert', condition: 'length(i) == 0' },
|
|
514
|
-
],
|
|
515
|
-
};
|
|
516
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
517
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
518
|
-
});
|
|
519
|
-
|
|
520
|
-
it('P1 loop step:over 求值不是数组 → halt + error', async () => {
|
|
521
|
-
const def: WorkflowDef = {
|
|
522
|
-
name: 'loop-bad-over',
|
|
523
|
-
description: 'd',
|
|
524
|
-
steps: [
|
|
525
|
-
{
|
|
526
|
-
id: 'lp',
|
|
527
|
-
type: 'loop',
|
|
528
|
-
over: '"not an array"',
|
|
529
|
-
as: 'i',
|
|
530
|
-
do: [{ id: 'inner', type: 'assert', condition: 'true' }],
|
|
531
|
-
},
|
|
532
|
-
],
|
|
533
|
-
};
|
|
534
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
535
|
-
expect(events.some((e) => e.type === 'error')).toBe(true);
|
|
536
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(false);
|
|
537
|
-
});
|
|
538
|
-
|
|
539
|
-
it('pause 真 HITL:非交互宿主 askBridge 自动选推荐项(继续)→ 放行', async () => {
|
|
540
|
-
// 不注入 executeTool:走真 AskUserQuestion → askBridge 无 UI handler → 自动选首项「继续执行 (推荐)」
|
|
541
|
-
const def: WorkflowDef = {
|
|
542
|
-
name: 'pause-approve',
|
|
543
|
-
description: 'd',
|
|
544
|
-
steps: [
|
|
545
|
-
{ id: 'p1', type: 'pause', prompt: '等用户确认' },
|
|
546
|
-
{ id: 's2', type: 'assert', condition: 'true' },
|
|
547
|
-
],
|
|
548
|
-
};
|
|
549
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
550
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
551
|
-
const end = events.find(
|
|
552
|
-
(e): e is Extract<WorkflowEvent, { type: 'workflow_step_end' }> =>
|
|
553
|
-
e.type === 'workflow_step_end' && e.id === 'p1',
|
|
554
|
-
);
|
|
555
|
-
expect(end?.ok).toBe(true);
|
|
556
|
-
expect(end?.output).toContain('审批通过');
|
|
557
|
-
});
|
|
558
|
-
|
|
559
|
-
it('pause 真 HITL:用户选「停止」→ halt 且现场保留(可 resume)', async () => {
|
|
560
|
-
// DI executeTool:模拟用户在 AskUserQuestion 界面选了「停止(保留现场)」
|
|
561
|
-
ctx.executeTool = async (name: string) => {
|
|
562
|
-
expect(name).toBe('AskUserQuestion');
|
|
563
|
-
return { ok: true, content: '用户已回答 AskUserQuestion:\nA1: 停止(保留现场)' };
|
|
564
|
-
};
|
|
565
|
-
const def: WorkflowDef = {
|
|
566
|
-
name: 'pause-stop',
|
|
567
|
-
description: 'd',
|
|
568
|
-
steps: [
|
|
569
|
-
{ id: 'gate', type: 'pause', prompt: '等审批' },
|
|
570
|
-
{ id: 'after', type: 'assert', condition: 'true' }, // 不应执行
|
|
571
|
-
],
|
|
572
|
-
};
|
|
573
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
574
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(false);
|
|
575
|
-
const halt = events.find(
|
|
576
|
-
(e): e is { type: 'error'; error: string } =>
|
|
577
|
-
e.type === 'error' && e.error.includes('Workflow halted'),
|
|
578
|
-
);
|
|
579
|
-
expect(halt).toBeDefined();
|
|
580
|
-
expect(halt!.error).toContain('选择停止');
|
|
581
|
-
const startedIds = events
|
|
582
|
-
.filter(
|
|
583
|
-
(e): e is Extract<WorkflowEvent, { type: 'workflow_step_start' }> =>
|
|
584
|
-
e.type === 'workflow_step_start',
|
|
585
|
-
)
|
|
586
|
-
.map((e) => e.id);
|
|
587
|
-
expect(startedIds).not.toContain('after');
|
|
588
|
-
});
|
|
589
|
-
|
|
590
|
-
it('pause 真 HITL:提示语含「停止」字样 + 用户选「继续」→ 必须放行(事故回归锚)', async () => {
|
|
591
|
-
// 真事故:plan.yaml 的 pause 提示语写着『选「停止」会保留现场…』,
|
|
592
|
-
// 回执的 Q 行带问题原文——曾因看整个 content 把用户选的「继续」误判成停止。
|
|
593
|
-
ctx.executeTool = async (_name: string, rawArgsJson: string) => {
|
|
594
|
-
const args = JSON.parse(rawArgsJson) as {
|
|
595
|
-
questions: { question: string }[];
|
|
596
|
-
};
|
|
597
|
-
// 模拟 ask.ts 的真实回执格式:Q 行含问题原文(内含「停止」)+ A 行是用户的选择
|
|
598
|
-
return {
|
|
599
|
-
ok: true,
|
|
600
|
-
content: `用户已回答 AskUserQuestion:\n\nQ1 [审批闸门] ${args.questions[0].question}\nA1: 继续执行 (推荐)`,
|
|
601
|
-
};
|
|
602
|
-
};
|
|
603
|
-
const def: WorkflowDef = {
|
|
604
|
-
name: 'pause-q-contains-stop',
|
|
605
|
-
description: 'd',
|
|
606
|
-
steps: [
|
|
607
|
-
{
|
|
608
|
-
id: 'gate',
|
|
609
|
-
type: 'pause',
|
|
610
|
-
prompt: '计划已生成。选「停止」会保留现场,稍后可从断点续跑。',
|
|
611
|
-
},
|
|
612
|
-
{ id: 'after', type: 'assert', condition: 'true' },
|
|
613
|
-
],
|
|
614
|
-
};
|
|
615
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
616
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
617
|
-
const end = events.find(
|
|
618
|
-
(e): e is Extract<WorkflowEvent, { type: 'workflow_step_end' }> =>
|
|
619
|
-
e.type === 'workflow_step_end' && e.id === 'gate',
|
|
620
|
-
);
|
|
621
|
-
expect(end?.ok).toBe(true);
|
|
622
|
-
});
|
|
623
|
-
|
|
624
|
-
it('pause 真 HITL:自由输入(其他逃生项)→ 不放行,原话进 halt 文案', async () => {
|
|
625
|
-
ctx.executeTool = async () => ({
|
|
626
|
-
ok: true,
|
|
627
|
-
content: '用户已回答 AskUserQuestion:\n\nQ1 [审批闸门] 是否继续?\nA1: 先把第3步的方案换成方案B',
|
|
628
|
-
});
|
|
629
|
-
const def: WorkflowDef = {
|
|
630
|
-
name: 'pause-freetext',
|
|
631
|
-
description: 'd',
|
|
632
|
-
steps: [{ id: 'gate', type: 'pause', prompt: '是否继续?' }],
|
|
633
|
-
};
|
|
634
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
635
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(false);
|
|
636
|
-
const halt = events.find(
|
|
637
|
-
(e): e is { type: 'error'; error: string } =>
|
|
638
|
-
e.type === 'error' && e.error.includes('Workflow halted'),
|
|
639
|
-
);
|
|
640
|
-
expect(halt).toBeDefined();
|
|
641
|
-
expect(halt!.error).toContain('先把第3步的方案换成方案B');
|
|
642
|
-
});
|
|
643
|
-
|
|
644
|
-
it('pause 真 HITL:free_text=approve 时自由输入作为补充要求放行并 capture', async () => {
|
|
645
|
-
ctx.executeTool = async () => ({
|
|
646
|
-
ok: true,
|
|
647
|
-
content:
|
|
648
|
-
'用户已回答 AskUserQuestion:\n\nQ1 [审批闸门] 是否继续?\nA1: 确认使用 pptx skill,不要从头摸索 ppt 操作',
|
|
649
|
-
});
|
|
650
|
-
const def: WorkflowDef = {
|
|
651
|
-
name: 'pause-freetext-approve',
|
|
652
|
-
description: 'd',
|
|
653
|
-
steps: [
|
|
654
|
-
{
|
|
655
|
-
id: 'gate',
|
|
656
|
-
type: 'pause',
|
|
657
|
-
prompt: '是否继续?',
|
|
658
|
-
free_text: 'approve',
|
|
659
|
-
capture: { text: 'approval_notes' },
|
|
660
|
-
},
|
|
661
|
-
{ id: 'after', type: 'assert', condition: "includes(approval_notes, 'pptx skill')" },
|
|
662
|
-
],
|
|
663
|
-
};
|
|
664
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
665
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
666
|
-
const end = events.find(
|
|
667
|
-
(e): e is Extract<WorkflowEvent, { type: 'workflow_step_end' }> =>
|
|
668
|
-
e.type === 'workflow_step_end' && e.id === 'gate',
|
|
669
|
-
);
|
|
670
|
-
expect(end?.ok).toBe(true);
|
|
671
|
-
expect(end?.output).toContain('补充要求');
|
|
672
|
-
expect(end?.output).toContain('pptx skill');
|
|
673
|
-
});
|
|
674
|
-
|
|
675
|
-
// R1 减法重构:专用 approval_loop 步类型已删除(0 个 yaml 使用即孤儿)。
|
|
676
|
-
// 同一审批语义由通用组合表达(loop + pause(free_text:approve) + branch + llm 修订),
|
|
677
|
-
// 与 plan.yaml v4 的 stage4 审批环同范式——本测试锁定该组合的行为等价性。
|
|
678
|
-
it('plan 审批闭环(通用组合):自由输入先改 PLAN.md,再次明确继续后才执行', async () => {
|
|
679
|
-
let askCount = 0;
|
|
680
|
-
ctx.executeTool = async (name: string, rawArgsJson: string, signal?: AbortSignal) => {
|
|
681
|
-
if (name === 'AskUserQuestion') {
|
|
682
|
-
askCount += 1;
|
|
683
|
-
return {
|
|
684
|
-
ok: true,
|
|
685
|
-
content:
|
|
686
|
-
askCount === 1
|
|
687
|
-
? '用户已回答 AskUserQuestion:\n\nQ1 [审批闸门] 是否继续?\nA1: 图形都用 svg,不要位图'
|
|
688
|
-
: '用户已回答 AskUserQuestion:\n\nQ1 [审批闸门] 是否继续?\nA1: 继续执行 (推荐)',
|
|
689
|
-
};
|
|
690
|
-
}
|
|
691
|
-
return (await import('../../../src/tools/index.js')).executeTool(name, rawArgsJson, signal);
|
|
692
|
-
};
|
|
693
|
-
ctx.chat = async function* () {
|
|
694
|
-
yield { type: 'text_delta', delta: '最终计划:所有图形都用 svg\n## 产出物清单\n- [ ] executed.txt' };
|
|
695
|
-
yield { type: 'done', stopReason: 'stop' };
|
|
696
|
-
};
|
|
697
|
-
|
|
698
|
-
const def: WorkflowDef = {
|
|
699
|
-
name: 'plan-approval-loop',
|
|
700
|
-
description: 'd',
|
|
701
|
-
artifacts: ['PLAN.md', 'executed.txt'],
|
|
702
|
-
steps: [
|
|
703
|
-
{ id: 'init', type: 'set', set: { final_plan_text: '初版计划:图形随意', plan_approved: false, approval_notes: '' } },
|
|
704
|
-
{
|
|
705
|
-
id: 'write_plan',
|
|
706
|
-
tool: 'Write',
|
|
707
|
-
args: { file_path: 'PLAN.md', content: '${final_plan_text}' },
|
|
708
|
-
artifacts: ['PLAN.md'],
|
|
709
|
-
},
|
|
710
|
-
{
|
|
711
|
-
id: 'approval',
|
|
712
|
-
type: 'loop',
|
|
713
|
-
max_iterations: 3,
|
|
714
|
-
do: [
|
|
715
|
-
{
|
|
716
|
-
id: 'gate',
|
|
717
|
-
type: 'pause',
|
|
718
|
-
prompt: '是否继续执行 PLAN.md?',
|
|
719
|
-
free_text: 'approve',
|
|
720
|
-
capture: { text: 'approval_notes' },
|
|
721
|
-
},
|
|
722
|
-
{
|
|
723
|
-
id: 'route',
|
|
724
|
-
type: 'branch',
|
|
725
|
-
condition: "approval_notes == ''",
|
|
726
|
-
then: [
|
|
727
|
-
{ id: 'mark_approved', type: 'set', set: { plan_approved: 'true' } },
|
|
728
|
-
{ id: 'approved_break', type: 'break' },
|
|
729
|
-
],
|
|
730
|
-
else: [
|
|
731
|
-
{
|
|
732
|
-
id: 'revise',
|
|
733
|
-
llm: '把用户反馈合入计划:${approval_notes}\n当前计划:${final_plan_text}',
|
|
734
|
-
capture: { text: 'final_plan_text' },
|
|
735
|
-
},
|
|
736
|
-
{
|
|
737
|
-
id: 'revise_write',
|
|
738
|
-
tool: 'Write',
|
|
739
|
-
args: { file_path: 'PLAN.md', content: '${final_plan_text}' },
|
|
740
|
-
artifacts: ['PLAN.md'],
|
|
741
|
-
},
|
|
742
|
-
{ id: 'clear_notes', type: 'set', set: { approval_notes: '' } },
|
|
743
|
-
],
|
|
744
|
-
},
|
|
745
|
-
],
|
|
746
|
-
},
|
|
747
|
-
{
|
|
748
|
-
id: 'ensure_approved',
|
|
749
|
-
type: 'assert',
|
|
750
|
-
condition: "plan_approved == true || plan_approved == 'true'",
|
|
751
|
-
},
|
|
752
|
-
{
|
|
753
|
-
id: 'execute',
|
|
754
|
-
tool: 'Write',
|
|
755
|
-
args: { file_path: 'executed.txt', content: 'executed after approval' },
|
|
756
|
-
artifacts: ['executed.txt'],
|
|
757
|
-
},
|
|
758
|
-
],
|
|
759
|
-
};
|
|
760
|
-
|
|
761
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
762
|
-
|
|
763
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
764
|
-
expect(askCount).toBe(2);
|
|
765
|
-
expect(readFileSync(join(tmp, 'PLAN.md'), 'utf8')).toContain('svg');
|
|
766
|
-
expect(readFileSync(join(tmp, 'executed.txt'), 'utf8')).toBe('executed after approval');
|
|
767
|
-
|
|
768
|
-
const ended = events
|
|
769
|
-
.filter(
|
|
770
|
-
(e): e is Extract<WorkflowEvent, { type: 'workflow_step_end' }> =>
|
|
771
|
-
e.type === 'workflow_step_end',
|
|
772
|
-
)
|
|
773
|
-
.map((e) => e.id);
|
|
774
|
-
expect(ended.indexOf('revise_write')).toBeLessThan(ended.indexOf('execute'));
|
|
775
|
-
});
|
|
776
|
-
|
|
777
|
-
it('pause 真 HITL:用户取消提问(ESC)→ 不放行(审批门上取消 = 不批准)', async () => {
|
|
778
|
-
ctx.executeTool = async () => ({ ok: false, error: '提问被取消 / 中断:esc' });
|
|
779
|
-
const def: WorkflowDef = {
|
|
780
|
-
name: 'pause-cancel',
|
|
781
|
-
description: 'd',
|
|
782
|
-
steps: [{ id: 'gate', type: 'pause', prompt: '等审批' }],
|
|
783
|
-
};
|
|
784
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
785
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(false);
|
|
786
|
-
expect(
|
|
787
|
-
events.some(
|
|
788
|
-
(e) => e.type === 'error' && e.error.includes('选择停止'),
|
|
789
|
-
),
|
|
790
|
-
).toBe(true);
|
|
791
|
-
});
|
|
792
|
-
|
|
793
|
-
it('P1 TUI 可见:每个 step 镜像 plugin_progress,tool 步骤发 tool_start/tool_end', async () => {
|
|
794
|
-
const def: WorkflowDef = {
|
|
795
|
-
name: 'visible',
|
|
796
|
-
description: 'd',
|
|
797
|
-
steps: [
|
|
798
|
-
{ id: 'w', tool: 'Write', args: { file_path: 'out.txt', content: 'hi' } },
|
|
799
|
-
{ id: 'a', type: 'assert', condition: 'true' },
|
|
800
|
-
],
|
|
801
|
-
};
|
|
802
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
803
|
-
const types = events.map((e) => e.type);
|
|
804
|
-
|
|
805
|
-
// 通用进度事件:开工(0/2) + 2 个 step 级 + 完成(2/2) = 4 条 plugin_progress
|
|
806
|
-
const pp = events.filter(
|
|
807
|
-
(e): e is Extract<LoopEvent, { type: 'plugin_progress' }> =>
|
|
808
|
-
e.type === 'plugin_progress',
|
|
809
|
-
);
|
|
810
|
-
expect(pp.length).toBe(4);
|
|
811
|
-
expect(pp.every((e) => e.pluginId === 'workflow-runner')).toBe(true);
|
|
812
|
-
expect(pp.some((e) => e.message?.includes('step w (tool)'))).toBe(true);
|
|
813
|
-
|
|
814
|
-
// tool 步骤像普通 ReAct 工具调用一样可见
|
|
815
|
-
expect(types.filter((t) => t === 'tool_start').length).toBe(1);
|
|
816
|
-
expect(types.filter((t) => t === 'tool_end').length).toBe(1);
|
|
817
|
-
const ts = events.find(
|
|
818
|
-
(e): e is Extract<LoopEvent, { type: 'tool_start' }> =>
|
|
819
|
-
e.type === 'tool_start',
|
|
820
|
-
);
|
|
821
|
-
expect(ts?.toolName).toBe('Write');
|
|
822
|
-
|
|
823
|
-
// 私有 workflow_* 仍在(-p / 既有 e2e 测试依赖),但末位可能因 v0.9 重构后
|
|
824
|
-
// runWorkflow 补发 assistant_message 而非严格以 workflow_done 收尾。
|
|
825
|
-
expect(types[0]).toBe('workflow_start');
|
|
826
|
-
expect(types).toContain('workflow_done');
|
|
827
|
-
expect(existsSync(join(tmp, 'out.txt'))).toBe(true);
|
|
828
|
-
});
|
|
829
|
-
|
|
830
|
-
it('P1 skill step:加载 cwd/skills/<name>/SKILL.md,跑 runQuery 累计 text', async () => {
|
|
831
|
-
// 在 tmp 准备一个最小 SKILL.md
|
|
832
|
-
const skillDir = join(tmp, 'skills', 'echo-bot');
|
|
833
|
-
mkdirSync(skillDir, { recursive: true });
|
|
834
|
-
writeFileSync(
|
|
835
|
-
join(skillDir, 'SKILL.md'),
|
|
836
|
-
'---\nname: echo-bot\ndescription: echo\n---\n\n按用户指示原样输出',
|
|
837
|
-
'utf8',
|
|
838
|
-
);
|
|
839
|
-
|
|
840
|
-
// skill executor 经真实 runQuery(TAOR) 执行;用 ctx.chat DI 注入 stub chat,
|
|
841
|
-
// 让真实 runQuery 真把 assistant 消息推进 ctx.history(skill.ts 据此提取结果)。
|
|
842
|
-
// 不再 mock.module(loop.js)——那是空壳 runQuery 不推 history(提取空、必失败),
|
|
843
|
-
// 且会全局泄漏污染其它测试文件(recovery 等的 runRecovery 也走 runQuery)。
|
|
844
|
-
ctx.chat = async function* () {
|
|
845
|
-
yield { type: 'text_delta', delta: 'echoed-' };
|
|
846
|
-
yield { type: 'text_delta', delta: 'OK' };
|
|
847
|
-
yield { type: 'done', stopReason: 'stop' };
|
|
848
|
-
};
|
|
849
|
-
|
|
850
|
-
const def: WorkflowDef = {
|
|
851
|
-
name: 'skill-test',
|
|
852
|
-
description: 'd',
|
|
853
|
-
steps: [
|
|
854
|
-
{
|
|
855
|
-
id: 'sk',
|
|
856
|
-
skill: 'echo-bot',
|
|
857
|
-
input: 'say hi',
|
|
858
|
-
capture: { text: 'msg' },
|
|
859
|
-
},
|
|
860
|
-
{ id: 'check', type: 'assert', condition: 'msg == "echoed-OK"' },
|
|
861
|
-
],
|
|
862
|
-
};
|
|
863
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
864
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
865
|
-
});
|
|
866
|
-
|
|
867
|
-
it('P1 skill step:未找到 skill → halt + error', async () => {
|
|
868
|
-
const def: WorkflowDef = {
|
|
869
|
-
name: 'skill-missing',
|
|
870
|
-
description: 'd',
|
|
871
|
-
steps: [{ id: 'sk', skill: 'definitely-not-exists' }],
|
|
872
|
-
};
|
|
873
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
874
|
-
expect(events.some((e) => e.type === 'error')).toBe(true);
|
|
875
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(false);
|
|
876
|
-
});
|
|
877
|
-
|
|
878
|
-
it('onError:continue 降级 → capture 绑明确占位文本(非空串)+ warning 可见化', async () => {
|
|
879
|
-
// chat 永远 throw → llm 步空产出抛异常 → max_retries=0 直接落 onError:continue。
|
|
880
|
-
// 此前降级完全静默且 capture 留空:下游 prompt 内插 ${req} 得空段,模型困惑。
|
|
881
|
-
ctx.chat = async function* () {
|
|
882
|
-
throw new Error('provider down');
|
|
883
|
-
// biome-ignore lint/correctness/noUnreachable: stub
|
|
884
|
-
yield { type: 'done', stopReason: 'stop' };
|
|
885
|
-
};
|
|
886
|
-
|
|
887
|
-
const def: WorkflowDef = {
|
|
888
|
-
name: 'continue-placeholder',
|
|
889
|
-
description: 'd',
|
|
890
|
-
steps: [
|
|
891
|
-
{
|
|
892
|
-
id: 'g',
|
|
893
|
-
llm: 'do it',
|
|
894
|
-
capture: { text: 'req' },
|
|
895
|
-
max_retries: 0,
|
|
896
|
-
onError: 'continue',
|
|
897
|
-
},
|
|
898
|
-
// 占位文本生效:req 非空且含机器可识别前缀
|
|
899
|
-
{ id: 'check', type: 'assert', condition: 'includes(req, "上游步骤 g 失败")' },
|
|
900
|
-
],
|
|
901
|
-
};
|
|
902
|
-
const events = await collect(runWorkflow(def, {}, ctx));
|
|
903
|
-
|
|
904
|
-
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
905
|
-
expect(
|
|
906
|
-
events.some(
|
|
907
|
-
(e) => e.type === 'warning' && e.message.includes('降级'),
|
|
908
|
-
),
|
|
909
|
-
).toBe(true);
|
|
910
|
-
});
|
|
911
|
-
});
|