minimal-agent 0.13.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 +60 -4
- 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 +197 -206
- package/plugins/workflow-runner/src/index.ts +248 -249
- 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 +400 -489
- package/plugins/workflow-runner/src/runner.ts +488 -560
- 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 +151 -307
- package/plugins/workflow-runner/src/taskIdentity.ts +207 -355
- 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 -211
- package/plugins/workflow-runner/src/types.ts +154 -623
- 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 +474 -802
- package/plugins/workflow-runner/src/workflowState.ts +575 -970
- 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/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 +27 -6
- package/src/cli/print.ts +48 -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 +419 -74
- package/src/config/configService.ts +703 -145
- 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 +34 -5
- package/src/infra/verification.ts +39 -4
- 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 +139 -7
- package/src/plugins/pluginRunner.ts +173 -9
- package/src/plugins/slashFallback.js +113 -0
- package/src/plugins/slashFallback.ts +137 -0
- package/src/prompts/policyRegistry.js +12 -32
- package/src/prompts/policyRegistry.ts +15 -32
- 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 +90 -46
- package/src/tools/advisor/advisor.ts +100 -47
- 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 +22 -15
- package/src/tools/bash/bash.ts +23 -17
- 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/presentresult/presentresult.js +6 -15
- package/src/tools/presentresult/presentresult.ts +6 -15
- package/src/tools/read/read.js +62 -9
- package/src/tools/read/read.ts +63 -9
- package/src/tools/shared/fileUtils.js +1 -2
- package/src/tools/shared/fileUtils.ts +1 -2
- 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 -34
- package/src/tools/webbrowser/browserControl.ts +210 -56
- 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 +679 -144
- package/src/tools/webbrowser/webbrowser.ts +975 -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 +440 -38
- 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/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 -639
- package/plugins/workflow-runner/src/expressions.ts +0 -640
- 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 -126
- package/plugins/workflow-runner/src/recovery.ts +0 -156
- 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 -42
- package/plugins/workflow-runner/src/stepExecutors/assert.ts +0 -52
- 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 -227
- package/plugins/workflow-runner/src/stepExecutors/tool.ts +0 -274
- package/plugins/workflow-runner/src/stepExecutors/verify.js +0 -61
- package/plugins/workflow-runner/src/stepExecutors/verify.ts +0 -72
- 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 -167
- 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/e2eNewLayout.test.ts +0 -314
- package/plugins/workflow-runner/test/engineRobustness.test.ts +0 -234
- package/plugins/workflow-runner/test/expressions.test.ts +0 -439
- 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 -106
- 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 -221
- package/plugins/workflow-runner/test/recovery.test.ts +0 -265
- package/plugins/workflow-runner/test/research.load.test.ts +0 -328
- package/plugins/workflow-runner/test/runner.test.ts +0 -911
- package/plugins/workflow-runner/test/runnerPreflight.test.ts +0 -436
- package/plugins/workflow-runner/test/skillTurnDone.test.ts +0 -71
- package/plugins/workflow-runner/test/stateLifecycle.test.ts +0 -198
- package/plugins/workflow-runner/test/stepPipeline.test.ts +0 -114
- package/plugins/workflow-runner/test/taskArbitration.test.ts +0 -354
- package/plugins/workflow-runner/test/taskLifecycle.test.ts +0 -324
- 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 -201
- package/workflows/research.yaml +0 -873
- 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
- /package/workflows/{research.md → research/DESIGN.md} +0 -0
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { isAbsolute, resolve } from 'node:path';
|
|
2
|
-
import { interpolate } from './expressions.js';
|
|
3
|
-
import { effectiveWorkflowCwd } from './toolRuntime.js';
|
|
4
|
-
export function resolveWorkflowMultimodalOptions(step, vars, ctx, onMissing) {
|
|
5
|
-
const imageDetail = step.image_detail;
|
|
6
|
-
const imageMaxLongSidePixel = step.image_max_long_side_pixel;
|
|
7
|
-
const imageInputs = (step.images ?? []).map((item) => {
|
|
8
|
-
if (typeof item === 'string') {
|
|
9
|
-
return {
|
|
10
|
-
source: resolveWorkflowImageSource(interpolate(item, vars, { onMissing }), ctx),
|
|
11
|
-
detail: imageDetail,
|
|
12
|
-
maxLongSidePixel: imageMaxLongSidePixel,
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
return {
|
|
16
|
-
source: resolveWorkflowImageSource(interpolate(item.source, vars, { onMissing }), ctx),
|
|
17
|
-
detail: item.detail ?? imageDetail,
|
|
18
|
-
maxLongSidePixel: item.max_long_side_pixel ?? imageMaxLongSidePixel,
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
return {
|
|
22
|
-
imageInputs: imageInputs.length > 0 ? imageInputs : undefined,
|
|
23
|
-
parseInlineImages: step.parse_inline_images,
|
|
24
|
-
imageDetail,
|
|
25
|
-
imageMaxLongSidePixel,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
function resolveWorkflowImageSource(source, ctx) {
|
|
29
|
-
const clean = source.trim();
|
|
30
|
-
if (/^https?:\/\//i.test(clean) ||
|
|
31
|
-
/^data:image\//i.test(clean) ||
|
|
32
|
-
clean.startsWith('file://') ||
|
|
33
|
-
clean.startsWith('~/') ||
|
|
34
|
-
isAbsolute(clean)) {
|
|
35
|
-
return clean;
|
|
36
|
-
}
|
|
37
|
-
return resolve(effectiveWorkflowCwd(ctx), clean);
|
|
38
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { isAbsolute, resolve } from 'node:path';
|
|
2
|
-
|
|
3
|
-
import type { ImageDetail, ImageInputSpec } from '../../../src/plugin-sdk.js';
|
|
4
|
-
import { interpolate } from './expressions.js';
|
|
5
|
-
import { effectiveWorkflowCwd } from './toolRuntime.js';
|
|
6
|
-
import type { RunContext, StepDef, VarStack } from './types.js';
|
|
7
|
-
|
|
8
|
-
export interface WorkflowMultimodalOptions {
|
|
9
|
-
imageInputs?: ImageInputSpec[];
|
|
10
|
-
parseInlineImages?: boolean;
|
|
11
|
-
imageDetail?: ImageDetail;
|
|
12
|
-
imageMaxLongSidePixel?: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function resolveWorkflowMultimodalOptions(
|
|
16
|
-
step: StepDef,
|
|
17
|
-
vars: VarStack,
|
|
18
|
-
ctx: RunContext,
|
|
19
|
-
onMissing?: (expr: string) => void,
|
|
20
|
-
): WorkflowMultimodalOptions {
|
|
21
|
-
const imageDetail = step.image_detail;
|
|
22
|
-
const imageMaxLongSidePixel = step.image_max_long_side_pixel;
|
|
23
|
-
const imageInputs = (step.images ?? []).map((item) => {
|
|
24
|
-
if (typeof item === 'string') {
|
|
25
|
-
return {
|
|
26
|
-
source: resolveWorkflowImageSource(
|
|
27
|
-
interpolate(item, vars, { onMissing }),
|
|
28
|
-
ctx,
|
|
29
|
-
),
|
|
30
|
-
detail: imageDetail,
|
|
31
|
-
maxLongSidePixel: imageMaxLongSidePixel,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
source: resolveWorkflowImageSource(
|
|
36
|
-
interpolate(item.source, vars, { onMissing }),
|
|
37
|
-
ctx,
|
|
38
|
-
),
|
|
39
|
-
detail: item.detail ?? imageDetail,
|
|
40
|
-
maxLongSidePixel: item.max_long_side_pixel ?? imageMaxLongSidePixel,
|
|
41
|
-
};
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
imageInputs: imageInputs.length > 0 ? imageInputs : undefined,
|
|
46
|
-
parseInlineImages: step.parse_inline_images,
|
|
47
|
-
imageDetail,
|
|
48
|
-
imageMaxLongSidePixel,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function resolveWorkflowImageSource(source: string, ctx: RunContext): string {
|
|
53
|
-
const clean = source.trim();
|
|
54
|
-
if (
|
|
55
|
-
/^https?:\/\//i.test(clean) ||
|
|
56
|
-
/^data:image\//i.test(clean) ||
|
|
57
|
-
clean.startsWith('file://') ||
|
|
58
|
-
clean.startsWith('~/') ||
|
|
59
|
-
isAbsolute(clean)
|
|
60
|
-
) {
|
|
61
|
-
return clean;
|
|
62
|
-
}
|
|
63
|
-
return resolve(effectiveWorkflowCwd(ctx), clean);
|
|
64
|
-
}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ============================================================
|
|
3
|
-
* plugins/workflow-runner/src/recovery.ts —— 节点失败的自适应恢复
|
|
4
|
-
* ------------------------------------------------------------
|
|
5
|
-
* 「确定性工作流 × 随机应变 agent」的结合点(onError:'recover')。
|
|
6
|
-
*
|
|
7
|
-
* 传统 DAG 的脆点:某节点抛错 → 整条 halt(或 onError:'continue' 盲跳,下游
|
|
8
|
-
* capture 拿 undefined 静默级联错)。当节点声明 onError:'recover' 时,runner
|
|
9
|
-
* 不立刻 halt,而是调本模块起一个**有界恢复 agent**(委托 runQuery/TAOR),
|
|
10
|
-
* 喂给它「工作流总目标 + 失败节点的意图 + 错误信息 + 当前已知变量 + 下游 capture 契约」,
|
|
11
|
-
* 让它**随机应变去达成该节点本来要的结果**(换路径 / 换命令 / 先读后写…)。
|
|
12
|
-
*
|
|
13
|
-
* v0.9 重构:不再使用独立 miniReAct 子循环,而是委托主 TAOR 引擎(runQuery)
|
|
14
|
-
* 在共享 ctx.history 上执行。恢复过程也写入共享上下文——后续对话能看到"某步失败后
|
|
15
|
-
* 如何被自动修复",增强可解释性。
|
|
16
|
-
*
|
|
17
|
-
* —— 共享大脑 ——
|
|
18
|
-
* 恢复 agent 与正常 agent/llm/skill 步本质同构:都通过 runQuery(TAOR) 执行。
|
|
19
|
-
* 本模块只构造「救火」角色提示词,跑完后交给 interpretMiniReActResult 判定
|
|
20
|
-
* 「真救回 / 放弃」。返回 AgentOutcome:
|
|
21
|
-
* - { ok:true, value } —— runner 用同一个 step.capture 绑定后继续 happy path
|
|
22
|
-
* - { ok:false, reason } —— runner 带原因 honest halt
|
|
23
|
-
* ============================================================
|
|
24
|
-
*/
|
|
25
|
-
import { describeCaptureContract, effectiveGoalAnchor, interpretMiniReActResult, runStepQuery, truncate, } from './agentCommon.js';
|
|
26
|
-
import { interpolate, interpolateDeep } from './expressions.js';
|
|
27
|
-
// RECOVER_OPENING 作为用户消息的一部分(系统提示词已在 history[0] 中)
|
|
28
|
-
const RECOVER_OPENING = `你是一名资深的自动化工程师 / SRE,被一个确定性工作流临时调来「救火」。
|
|
29
|
-
工作流里一个原本写死的步骤刚刚执行失败了,现在交给你随机应变——先看错误信息诊断根因,再想办法真正达成这个步骤**本来要的结果**(关注它要的结果,别拘泥它原先怎么写)。`;
|
|
30
|
-
/** 描述失败节点「本来要干什么」,喂给恢复 agent 作为意图说明。 */
|
|
31
|
-
function describeStepIntent(step, vars) {
|
|
32
|
-
if (step.tool) {
|
|
33
|
-
const args = interpolateDeep(step.args ?? {}, vars);
|
|
34
|
-
return `调用工具 ${step.tool},参数:${JSON.stringify(args)}`;
|
|
35
|
-
}
|
|
36
|
-
if (step.agent) {
|
|
37
|
-
return `自主完成这个开放任务:${interpolate(step.agent, vars)}`;
|
|
38
|
-
}
|
|
39
|
-
if (step.llm) {
|
|
40
|
-
return `用 LLM 生成内容,提示词:${interpolate(step.llm, vars)}`;
|
|
41
|
-
}
|
|
42
|
-
if (step.skill) {
|
|
43
|
-
const input = step.input ? interpolate(step.input, vars) : '(无显式输入)';
|
|
44
|
-
return `执行 skill「${interpolate(step.skill, vars)}」,输入:${input}`;
|
|
45
|
-
}
|
|
46
|
-
if (step.type === 'assert') {
|
|
47
|
-
return `让这个断言成立:${step.condition}`;
|
|
48
|
-
}
|
|
49
|
-
return `完成步骤 ${step.id}`;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* 尝试自适应恢复一个失败的动作 step。
|
|
53
|
-
* - 救回 → { ok:true, value }(value.raw 已 normalize,可被原 step.capture 绑定)
|
|
54
|
-
* - 放弃 / 不可信 / 子循环抛错(含用户中断)→ { ok:false, reason }
|
|
55
|
-
*/
|
|
56
|
-
export async function* runRecovery(step, vars, ctx, errorMsg) {
|
|
57
|
-
const intent = describeStepIntent(step, vars);
|
|
58
|
-
const knownVars = truncate(JSON.stringify(vars.snapshot()), 1500);
|
|
59
|
-
const goalLine = ctx.goal ? `工作流总目标:${ctx.goal}\n\n` : '';
|
|
60
|
-
const captureLine = describeCaptureContract(step);
|
|
61
|
-
const hintLine = step.recover_hint
|
|
62
|
-
? `\n\n作者给恢复的提示:${interpolate(step.recover_hint, vars)}`
|
|
63
|
-
: '';
|
|
64
|
-
// 构造恢复 prompt(作为 user message push 进共享 history)
|
|
65
|
-
const recoverPrompt = `${RECOVER_OPENING}\n\n` +
|
|
66
|
-
`${goalLine}` +
|
|
67
|
-
`失败的步骤(id=${step.id})本来要做的事:\n${intent}\n\n` +
|
|
68
|
-
`它失败时的错误:\n${truncate(errorMsg, 800)}\n\n` +
|
|
69
|
-
`当前已知的变量(JSON):\n${knownVars}` +
|
|
70
|
-
`${captureLine}${hintLine}\n\n` +
|
|
71
|
-
`请随机应变,把这一步要的结果做出来;做不成就按约定输出放弃标记。`;
|
|
72
|
-
// output_schema 约束嵌入 prompt
|
|
73
|
-
const schemaHint = step.output_schema
|
|
74
|
-
? `\n\n【结构化输出约束】请严格按照以下 JSON Schema 输出结果:\n${JSON.stringify(step.output_schema, null, 2)}`
|
|
75
|
-
: '';
|
|
76
|
-
// 通用目标锚定(同 agent/llm/skill 步):恢复 agent 也要看到用户原始目标
|
|
77
|
-
// 与补充要求,不能只有 def.description 的"工作流总目标"(E10)。
|
|
78
|
-
const anchor = effectiveGoalAnchor(ctx);
|
|
79
|
-
const fullPrompt = anchor
|
|
80
|
-
? `${anchor}\n\n${recoverPrompt}${schemaHint}`
|
|
81
|
-
: recoverPrompt + schemaHint;
|
|
82
|
-
try {
|
|
83
|
-
// 委托 TAOR 引擎执行(共享消费层 runStepQuery)——事件透传给 UI(显示恢复进度)。
|
|
84
|
-
// 注意剥掉 step 的 allowed_tools 白名单:【allowed_tools 本身不是安全边界,是弱模型聚焦优化】
|
|
85
|
-
// (原步限定一小撮工具给能力弱的模型,避免它瞎试跑遍所有工具)。
|
|
86
|
-
// 恢复 agent 的职责正是「随机应变换路径」,需要它能调用原步没考虑过的替代工具,
|
|
87
|
-
// 所以这里解除聚焦限制。真正的安全边界在**另外两层**,此处没有动:
|
|
88
|
-
// 1. `StepDef.uses: [browser|computer]` —— 宿主能力切片(buildWorkflowToolContext 仍生效),
|
|
89
|
-
// 原步没声明 computer 的话,恢复 agent 也调不通 ComputerUse。
|
|
90
|
-
// 2. `ctx.tools` —— 插件层按 runtime + 宿主白名单裁剪后的有效工具集合,
|
|
91
|
-
// 无论 allowed_tools 写什么都不能超出它。
|
|
92
|
-
// 保持 v0.9 行为(放开 allowed_tools),但明确安全层次不发生变化。
|
|
93
|
-
const { rawText, sawLlmError, sawMaxTurns, llmErrorDetail } = yield* runStepQuery(fullPrompt, { ...step, allowed_tools: undefined }, ctx, { maxTurns: step.maxTurns ?? 25 });
|
|
94
|
-
// 恢复是兜底路径:无论 provider 失败还是模型空答,都按「没救回」返回
|
|
95
|
-
// ok:false(不抛重试——retry 在进入 recover 前已用尽);只是归因更诚实。
|
|
96
|
-
if (!rawText.trim() && sawLlmError) {
|
|
97
|
-
return {
|
|
98
|
-
ok: false,
|
|
99
|
-
reason: `LLM 调用失败且无产出${llmErrorDetail ? `—— ${truncate(llmErrorDetail, 300)}` : ''}`,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
// 恢复 agent 也撞 maxTurns 截断 → 截断产出不可信,诚实「未救回」
|
|
103
|
-
if (sawMaxTurns) {
|
|
104
|
-
return {
|
|
105
|
-
ok: false,
|
|
106
|
-
reason: `恢复 agent 达到最大轮数 ${step.maxTurns ?? 25} 被截断,产出不可信(未救回)`,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
const stepResult = {
|
|
110
|
-
raw: { text: rawText, result: rawText },
|
|
111
|
-
preview: rawText.length > 200 ? `${rawText.slice(0, 200)}...` : rawText,
|
|
112
|
-
};
|
|
113
|
-
const outcome = interpretMiniReActResult(stepResult, !!step.output_schema);
|
|
114
|
-
if (!outcome.ok)
|
|
115
|
-
return outcome;
|
|
116
|
-
// 救回:preview 加 recovered: 前缀(runner 的 step_end output 用),raw 原样。
|
|
117
|
-
return {
|
|
118
|
-
ok: true,
|
|
119
|
-
value: { raw: outcome.value.raw, preview: `recovered: ${outcome.value.preview}` },
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
catch (e) {
|
|
123
|
-
// runStepQuery 抛错(编程性异常 / 中断竞态)→ 恢复失败。
|
|
124
|
-
return { ok: false, reason: e.message ?? String(e) };
|
|
125
|
-
}
|
|
126
|
-
}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ============================================================
|
|
3
|
-
* plugins/workflow-runner/src/recovery.ts —— 节点失败的自适应恢复
|
|
4
|
-
* ------------------------------------------------------------
|
|
5
|
-
* 「确定性工作流 × 随机应变 agent」的结合点(onError:'recover')。
|
|
6
|
-
*
|
|
7
|
-
* 传统 DAG 的脆点:某节点抛错 → 整条 halt(或 onError:'continue' 盲跳,下游
|
|
8
|
-
* capture 拿 undefined 静默级联错)。当节点声明 onError:'recover' 时,runner
|
|
9
|
-
* 不立刻 halt,而是调本模块起一个**有界恢复 agent**(委托 runQuery/TAOR),
|
|
10
|
-
* 喂给它「工作流总目标 + 失败节点的意图 + 错误信息 + 当前已知变量 + 下游 capture 契约」,
|
|
11
|
-
* 让它**随机应变去达成该节点本来要的结果**(换路径 / 换命令 / 先读后写…)。
|
|
12
|
-
*
|
|
13
|
-
* v0.9 重构:不再使用独立 miniReAct 子循环,而是委托主 TAOR 引擎(runQuery)
|
|
14
|
-
* 在共享 ctx.history 上执行。恢复过程也写入共享上下文——后续对话能看到"某步失败后
|
|
15
|
-
* 如何被自动修复",增强可解释性。
|
|
16
|
-
*
|
|
17
|
-
* —— 共享大脑 ——
|
|
18
|
-
* 恢复 agent 与正常 agent/llm/skill 步本质同构:都通过 runQuery(TAOR) 执行。
|
|
19
|
-
* 本模块只构造「救火」角色提示词,跑完后交给 interpretMiniReActResult 判定
|
|
20
|
-
* 「真救回 / 放弃」。返回 AgentOutcome:
|
|
21
|
-
* - { ok:true, value } —— runner 用同一个 step.capture 绑定后继续 happy path
|
|
22
|
-
* - { ok:false, reason } —— runner 带原因 honest halt
|
|
23
|
-
* ============================================================
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
import type { LoopEvent } from '../../../src/plugin-sdk.js';
|
|
27
|
-
import {
|
|
28
|
-
type AgentOutcome,
|
|
29
|
-
describeCaptureContract,
|
|
30
|
-
effectiveGoalAnchor,
|
|
31
|
-
interpretMiniReActResult,
|
|
32
|
-
runStepQuery,
|
|
33
|
-
truncate,
|
|
34
|
-
} from './agentCommon.js';
|
|
35
|
-
import { interpolate, interpolateDeep } from './expressions.js';
|
|
36
|
-
import type { RunContext, StepDef, VarStack } from './types.js';
|
|
37
|
-
|
|
38
|
-
// RECOVER_OPENING 作为用户消息的一部分(系统提示词已在 history[0] 中)
|
|
39
|
-
const RECOVER_OPENING = `你是一名资深的自动化工程师 / SRE,被一个确定性工作流临时调来「救火」。
|
|
40
|
-
工作流里一个原本写死的步骤刚刚执行失败了,现在交给你随机应变——先看错误信息诊断根因,再想办法真正达成这个步骤**本来要的结果**(关注它要的结果,别拘泥它原先怎么写)。`;
|
|
41
|
-
|
|
42
|
-
/** 描述失败节点「本来要干什么」,喂给恢复 agent 作为意图说明。 */
|
|
43
|
-
function describeStepIntent(step: StepDef, vars: VarStack): string {
|
|
44
|
-
if (step.tool) {
|
|
45
|
-
const args = interpolateDeep(step.args ?? {}, vars);
|
|
46
|
-
return `调用工具 ${step.tool},参数:${JSON.stringify(args)}`;
|
|
47
|
-
}
|
|
48
|
-
if (step.agent) {
|
|
49
|
-
return `自主完成这个开放任务:${interpolate(step.agent, vars)}`;
|
|
50
|
-
}
|
|
51
|
-
if (step.llm) {
|
|
52
|
-
return `用 LLM 生成内容,提示词:${interpolate(step.llm, vars)}`;
|
|
53
|
-
}
|
|
54
|
-
if (step.skill) {
|
|
55
|
-
const input = step.input ? interpolate(step.input, vars) : '(无显式输入)';
|
|
56
|
-
return `执行 skill「${interpolate(step.skill, vars)}」,输入:${input}`;
|
|
57
|
-
}
|
|
58
|
-
if (step.type === 'assert') {
|
|
59
|
-
return `让这个断言成立:${step.condition}`;
|
|
60
|
-
}
|
|
61
|
-
return `完成步骤 ${step.id}`;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* 尝试自适应恢复一个失败的动作 step。
|
|
66
|
-
* - 救回 → { ok:true, value }(value.raw 已 normalize,可被原 step.capture 绑定)
|
|
67
|
-
* - 放弃 / 不可信 / 子循环抛错(含用户中断)→ { ok:false, reason }
|
|
68
|
-
*/
|
|
69
|
-
export async function* runRecovery(
|
|
70
|
-
step: StepDef,
|
|
71
|
-
vars: VarStack,
|
|
72
|
-
ctx: RunContext,
|
|
73
|
-
errorMsg: string,
|
|
74
|
-
): AsyncGenerator<LoopEvent, AgentOutcome, void> {
|
|
75
|
-
const intent = describeStepIntent(step, vars);
|
|
76
|
-
const knownVars = truncate(JSON.stringify(vars.snapshot()), 1500);
|
|
77
|
-
const goalLine = ctx.goal ? `工作流总目标:${ctx.goal}\n\n` : '';
|
|
78
|
-
const captureLine = describeCaptureContract(step);
|
|
79
|
-
const hintLine = step.recover_hint
|
|
80
|
-
? `\n\n作者给恢复的提示:${interpolate(step.recover_hint, vars)}`
|
|
81
|
-
: '';
|
|
82
|
-
|
|
83
|
-
// 构造恢复 prompt(作为 user message push 进共享 history)
|
|
84
|
-
const recoverPrompt =
|
|
85
|
-
`${RECOVER_OPENING}\n\n` +
|
|
86
|
-
`${goalLine}` +
|
|
87
|
-
`失败的步骤(id=${step.id})本来要做的事:\n${intent}\n\n` +
|
|
88
|
-
`它失败时的错误:\n${truncate(errorMsg, 800)}\n\n` +
|
|
89
|
-
`当前已知的变量(JSON):\n${knownVars}` +
|
|
90
|
-
`${captureLine}${hintLine}\n\n` +
|
|
91
|
-
`请随机应变,把这一步要的结果做出来;做不成就按约定输出放弃标记。`;
|
|
92
|
-
|
|
93
|
-
// output_schema 约束嵌入 prompt
|
|
94
|
-
const schemaHint = step.output_schema
|
|
95
|
-
? `\n\n【结构化输出约束】请严格按照以下 JSON Schema 输出结果:\n${JSON.stringify(step.output_schema, null, 2)}`
|
|
96
|
-
: '';
|
|
97
|
-
|
|
98
|
-
// 通用目标锚定(同 agent/llm/skill 步):恢复 agent 也要看到用户原始目标
|
|
99
|
-
// 与补充要求,不能只有 def.description 的"工作流总目标"(E10)。
|
|
100
|
-
const anchor = effectiveGoalAnchor(ctx);
|
|
101
|
-
const fullPrompt = anchor
|
|
102
|
-
? `${anchor}\n\n${recoverPrompt}${schemaHint}`
|
|
103
|
-
: recoverPrompt + schemaHint;
|
|
104
|
-
|
|
105
|
-
try {
|
|
106
|
-
// 委托 TAOR 引擎执行(共享消费层 runStepQuery)——事件透传给 UI(显示恢复进度)。
|
|
107
|
-
// 注意剥掉 step 的 allowed_tools 白名单:【allowed_tools 本身不是安全边界,是弱模型聚焦优化】
|
|
108
|
-
// (原步限定一小撮工具给能力弱的模型,避免它瞎试跑遍所有工具)。
|
|
109
|
-
// 恢复 agent 的职责正是「随机应变换路径」,需要它能调用原步没考虑过的替代工具,
|
|
110
|
-
// 所以这里解除聚焦限制。真正的安全边界在**另外两层**,此处没有动:
|
|
111
|
-
// 1. `StepDef.uses: [browser|computer]` —— 宿主能力切片(buildWorkflowToolContext 仍生效),
|
|
112
|
-
// 原步没声明 computer 的话,恢复 agent 也调不通 ComputerUse。
|
|
113
|
-
// 2. `ctx.tools` —— 插件层按 runtime + 宿主白名单裁剪后的有效工具集合,
|
|
114
|
-
// 无论 allowed_tools 写什么都不能超出它。
|
|
115
|
-
// 保持 v0.9 行为(放开 allowed_tools),但明确安全层次不发生变化。
|
|
116
|
-
const { rawText, sawLlmError, sawMaxTurns, llmErrorDetail } =
|
|
117
|
-
yield* runStepQuery(
|
|
118
|
-
fullPrompt,
|
|
119
|
-
{ ...step, allowed_tools: undefined },
|
|
120
|
-
ctx,
|
|
121
|
-
{ maxTurns: step.maxTurns ?? 25 },
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
// 恢复是兜底路径:无论 provider 失败还是模型空答,都按「没救回」返回
|
|
125
|
-
// ok:false(不抛重试——retry 在进入 recover 前已用尽);只是归因更诚实。
|
|
126
|
-
if (!rawText.trim() && sawLlmError) {
|
|
127
|
-
return {
|
|
128
|
-
ok: false,
|
|
129
|
-
reason: `LLM 调用失败且无产出${llmErrorDetail ? `—— ${truncate(llmErrorDetail, 300)}` : ''}`,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
// 恢复 agent 也撞 maxTurns 截断 → 截断产出不可信,诚实「未救回」
|
|
133
|
-
if (sawMaxTurns) {
|
|
134
|
-
return {
|
|
135
|
-
ok: false,
|
|
136
|
-
reason: `恢复 agent 达到最大轮数 ${step.maxTurns ?? 25} 被截断,产出不可信(未救回)`,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const stepResult: import('./types.js').StepResult = {
|
|
141
|
-
raw: { text: rawText, result: rawText },
|
|
142
|
-
preview: rawText.length > 200 ? `${rawText.slice(0, 200)}...` : rawText,
|
|
143
|
-
};
|
|
144
|
-
const outcome = interpretMiniReActResult(stepResult, !!step.output_schema);
|
|
145
|
-
if (!outcome.ok) return outcome;
|
|
146
|
-
|
|
147
|
-
// 救回:preview 加 recovered: 前缀(runner 的 step_end output 用),raw 原样。
|
|
148
|
-
return {
|
|
149
|
-
ok: true,
|
|
150
|
-
value: { raw: outcome.value.raw, preview: `recovered: ${outcome.value.preview}` },
|
|
151
|
-
};
|
|
152
|
-
} catch (e) {
|
|
153
|
-
// runStepQuery 抛错(编程性异常 / 中断竞态)→ 恢复失败。
|
|
154
|
-
return { ok: false, reason: (e as Error).message ?? String(e) };
|
|
155
|
-
}
|
|
156
|
-
}
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ============================================================
|
|
3
|
-
* plugins/workflow-runner/src/stepExecutors/agent.ts —— agent 步骤执行器
|
|
4
|
-
* ------------------------------------------------------------
|
|
5
|
-
* v0.9 重构:不再使用独立 miniReAct 子循环,而是委托主 TAOR 引擎
|
|
6
|
-
* (runQuery / src/loop.ts)执行。这样做的好处:
|
|
7
|
-
*
|
|
8
|
-
* 1. 上下文自然积累:每步的完整对话(user→assistant→tool→...)
|
|
9
|
-
* 都写入共享 history,后续步骤和用户对话都能看到
|
|
10
|
-
* 2. 工具/skills/插件信息来自系统提示词(history[0]),无需重复组装
|
|
11
|
-
* 3. 压缩自动生效:history 增长时 autoCompact / reactiveCompact 自动触发
|
|
12
|
-
* 4. Token 消耗透明:TUI status 行实时显示真实 token 数
|
|
13
|
-
* 5. 中断后上下文完整:已完成的步骤全在 history 里,可继续/调整
|
|
14
|
-
*
|
|
15
|
-
* 与 llm 步的区别:
|
|
16
|
-
* - agent 有 maxTurns 上限(默认 25),允许多轮工具调用
|
|
17
|
-
* - agent 的产出经过验证闸门(interpretMiniReActResult)
|
|
18
|
-
* - llm 只跑单轮 chat(maxTurns=1)
|
|
19
|
-
* ============================================================
|
|
20
|
-
*/
|
|
21
|
-
import { describeCaptureContract, describeLlmFailure, describeMaxTurnsCutoff, effectiveGoalAnchor, interpretMiniReActResult, runStepQuery, } from '../agentCommon.js';
|
|
22
|
-
import { evalExpr, interpolate } from '../expressions.js';
|
|
23
|
-
import { resolveWorkflowMultimodalOptions } from '../multimodal.js';
|
|
24
|
-
/**
|
|
25
|
-
* 执行一个 agent 步骤:构造 step prompt → 委托 runQuery(TAOR) → 提取结果。
|
|
26
|
-
*
|
|
27
|
-
* runQuery 会:
|
|
28
|
-
* 1. 把 prompt 作为 user message push 进 ctx.history
|
|
29
|
-
* 2. 跑 TAOR 循环(调 LLM → 执行工具 → 喂回 → 直到模型不调工具)
|
|
30
|
-
* 3. 把所有 assistant / tool 消息 push 进 ctx.history
|
|
31
|
-
* 4. yield UI 事件(text_delta / tool_start / tool_end / ...)
|
|
32
|
-
*/
|
|
33
|
-
export async function* execAgentStep(step, vars, ctx) {
|
|
34
|
-
// 默认 25(与 skill 步 skill.ts 对齐)。agent 步本就是「开放多工具任务」执行器,
|
|
35
|
-
// 弱模型常一轮只调一个工具(Read/Grep/Glob 各占一轮),旧默认 12 对探索类步骤
|
|
36
|
-
// (如 plan.yaml stage1_research)太紧——12 轮还没收集完就撞顶截断、误判失败。
|
|
37
|
-
// 这是安全阀不是性能阀;要更紧的步显式写小值即可。
|
|
38
|
-
const maxTurns = step.maxTurns ?? 25;
|
|
39
|
-
// 未定义变量插值可见化(裸 ${goal} 这类拼写/命名空间错的病根,静默空串会坑死下游)
|
|
40
|
-
const missing = [];
|
|
41
|
-
const iopts = { onMissing: (e) => missing.push(e) };
|
|
42
|
-
// 构造用户提示:包含步骤指令 + 变量 + capture 约束 + 内部标记防护
|
|
43
|
-
const userPrompt = `${interpolate(step.agent ?? '', vars, iopts)}${describeCaptureContract(step)}${step.input ? `\n\n上下文变量:${interpolate(step.input, vars, iopts)}` : ''}\n\n⚠️ 输出规范:直接输出你的工作成果即可,不要在输出中包含任何类似「放弃」、「GIVEUP」、「__AGENT__」或「[wf-internal」的内部标记文本。`;
|
|
44
|
-
// 如果有 output_schema,把 schema 约束嵌入 prompt(runQuery 不原生支持 responseFormat)
|
|
45
|
-
const schemaHint = step.output_schema
|
|
46
|
-
? `\n\n【结构化输出约束】请严格按照以下 JSON Schema 输出结果(不要包裹在 markdown 代码块中):\n${JSON.stringify(step.output_schema, null, 2)}`
|
|
47
|
-
: '';
|
|
48
|
-
const fullPrompt = userPrompt + schemaHint;
|
|
49
|
-
// 通用目标锚定(原始目标 + 累积的用户补充要求),前置注入 prompt。
|
|
50
|
-
// 确保每步 LLM 都能看到用户原始目标与运行中的补充要求,
|
|
51
|
-
// 避免长上下文 / fresh_context 导致目标被稀释或遗忘。
|
|
52
|
-
const anchor = effectiveGoalAnchor(ctx);
|
|
53
|
-
const effectivePrompt = anchor ? `${anchor}\n\n${fullPrompt}` : fullPrompt;
|
|
54
|
-
const multimodal = resolveWorkflowMultimodalOptions(step, vars, ctx, (e) => missing.push(e));
|
|
55
|
-
if (missing.length > 0) {
|
|
56
|
-
yield {
|
|
57
|
-
type: 'warning',
|
|
58
|
-
message: `step "${step.id}": 模板变量未定义,已按空串插值:${[...new Set(missing)].map((m) => `\${${m}}`).join('、')}(裸名请用 inputs.<name> 或先 capture/set)`,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
// 委托 TAOR 引擎执行(共享消费层 runStepQuery:携带 sessionState 以启用上下文压缩,
|
|
62
|
-
// 并统一侦测终结错误——runQuery 遇 LLM 失败是 yield error 后 return 不 throw)。
|
|
63
|
-
const { rawText, sawToolCall, toolNames, toolOkCount, toolFailCount, aborted, sawLlmError, sawMaxTurns, llmErrorDetail, } = yield* runStepQuery(effectivePrompt, step, ctx, {
|
|
64
|
-
maxTurns,
|
|
65
|
-
...multimodal,
|
|
66
|
-
});
|
|
67
|
-
const stepResult = {
|
|
68
|
-
raw: { text: rawText, result: rawText },
|
|
69
|
-
preview: rawText.length > 200 ? `${rawText.slice(0, 200)}...` : rawText,
|
|
70
|
-
};
|
|
71
|
-
// 用户中断导致的空产出:不过验证闸门(否则会误抛「放弃: 没有产出任何结果」),
|
|
72
|
-
// 直接返回当前(可能为空的)结果,由 runner 据 signal.aborted 收口(不当作可重试失败)。
|
|
73
|
-
if (aborted)
|
|
74
|
-
return stepResult;
|
|
75
|
-
// P0-1(同 llm.ts / skill.ts):LLM 失败(超时/网络错)且本步无任何产出 →
|
|
76
|
-
// 抛「可重试失败」交给 runner 的 in-run retry。必须在验证闸门之前——
|
|
77
|
-
// 否则 provider 故障会被闸门误归因为「agent 步骤放弃: 没有产出任何结果」,
|
|
78
|
-
// 混淆「provider 失败(该重试)」与「模型真放弃/空答(诚实 halt)」。
|
|
79
|
-
if (!rawText.trim() && sawLlmError) {
|
|
80
|
-
// 抛错文案附带 provider 真实报错(经 runner 落 progress.md,刷屏后仍可排障)
|
|
81
|
-
throw new Error(describeLlmFailure(step.id, llmErrorDetail));
|
|
82
|
-
}
|
|
83
|
-
// 撞 maxTurns 截断:截断时刻的文本是半截工作叙述,不是可信交付——
|
|
84
|
-
// 即使非空也不能过闸门(曾被静默当成功:半成品 PPTX 被整条链当真交付)。
|
|
85
|
-
// 抛可重试失败 → in-run retry 在共享 history 上续作(模型看到已有进度接着干)。
|
|
86
|
-
if (sawMaxTurns) {
|
|
87
|
-
throw new Error(describeMaxTurnsCutoff(step.id, maxTurns));
|
|
88
|
-
}
|
|
89
|
-
// done_when 验收兜底(K3/A2):弱模型常「宣告要干活」却不调工具就 end_turn
|
|
90
|
-
//(announce-not-do,2026-06-12 plan 工作流实跑事故的执行步烂尾根因之一)。
|
|
91
|
-
// yaml 作者声明确定性完成条件(如 fileExists('./doc/x.pptx')),不满足时
|
|
92
|
-
// 引擎自动 nudge 同一 agent 在共享 history 上继续干(看得到自己刚才的半截工作),
|
|
93
|
-
// 把「对抗模型不可靠」从每个 yaml 的 prompt 工程收回引擎单点。
|
|
94
|
-
if (step.done_when) {
|
|
95
|
-
const NUDGES = 2; // 提醒上限:超过说明模型真干不动,交给 onError/max_retries
|
|
96
|
-
let result = resultIfTextLooksDeliverable(step, rawText);
|
|
97
|
-
let lastOutcome = {
|
|
98
|
-
rawText,
|
|
99
|
-
sawToolCall,
|
|
100
|
-
toolNames,
|
|
101
|
-
toolOkCount,
|
|
102
|
-
toolFailCount,
|
|
103
|
-
};
|
|
104
|
-
for (let n = 0;; n++) {
|
|
105
|
-
if (evalDoneWhen(step, vars)) {
|
|
106
|
-
return result ?? doneWhenSatisfiedResult(step);
|
|
107
|
-
}
|
|
108
|
-
if (n >= NUDGES) {
|
|
109
|
-
throw new Error(`agent 步骤 "${step.id}" 完成条件未满足(done_when: ${step.done_when}),已提醒 ${NUDGES} 次仍未达成。${describeAttemptForDoneWhen(lastOutcome)}`);
|
|
110
|
-
}
|
|
111
|
-
yield {
|
|
112
|
-
type: 'warning',
|
|
113
|
-
message: `⏩ step "${step.id}" 完成条件未满足(${step.done_when}),提醒 agent 继续执行(第 ${n + 1}/${NUDGES} 次)。${describeAttemptForDoneWhen(lastOutcome)}`,
|
|
114
|
-
};
|
|
115
|
-
const nudge = yield* runStepQuery(`检查发现这一步还没有真正完成:完成条件 \`${step.done_when}\` 仍不成立。不要解释、不要宣告计划——继续实际执行(调用工具落盘/操作),直到完成条件成立,然后给出简短完成报告。`, step, ctx, { maxTurns });
|
|
116
|
-
if (nudge.aborted)
|
|
117
|
-
return result ?? stepResult;
|
|
118
|
-
if (!nudge.rawText.trim() && nudge.sawLlmError) {
|
|
119
|
-
throw new Error(describeLlmFailure(step.id, nudge.llmErrorDetail));
|
|
120
|
-
}
|
|
121
|
-
if (nudge.sawMaxTurns) {
|
|
122
|
-
throw new Error(describeMaxTurnsCutoff(step.id, maxTurns));
|
|
123
|
-
}
|
|
124
|
-
lastOutcome = nudge;
|
|
125
|
-
if (nudge.rawText.trim()) {
|
|
126
|
-
result = resultIfTextLooksDeliverable(step, nudge.rawText) ?? result;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
// 验证闸门:判断结果是"真交付"还是"放弃"。注意:带 done_when 的步骤已在上方
|
|
131
|
-
// 由确定性条件验收,避免"文件已落盘但最终空文本"或"还没落盘但空文本"绕过 nudge。
|
|
132
|
-
const outcome = interpretMiniReActResult(stepResult, !!step.output_schema);
|
|
133
|
-
if (!outcome.ok)
|
|
134
|
-
throw new Error(`agent 步骤放弃: ${outcome.reason}`);
|
|
135
|
-
return outcome.value;
|
|
136
|
-
}
|
|
137
|
-
function evalDoneWhen(step, vars) {
|
|
138
|
-
try {
|
|
139
|
-
return Boolean(evalExpr(step.done_when ?? '', vars));
|
|
140
|
-
}
|
|
141
|
-
catch (e) {
|
|
142
|
-
// 表达式坏了是 yaml 作者错误:响亮失败(同 max_iterations 解析失败哲学),
|
|
143
|
-
// 不能静默当 false 把好结果 nudge 死、也不能静默当 true 放走烂尾。
|
|
144
|
-
throw new Error(`step "${step.id}" 的 done_when 表达式求值失败: ${e.message}`);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
function doneWhenSatisfiedResult(step) {
|
|
148
|
-
const text = `完成条件已满足:${step.done_when}`;
|
|
149
|
-
return { raw: { text, result: text, content: text }, preview: text };
|
|
150
|
-
}
|
|
151
|
-
function resultIfTextLooksDeliverable(step, text) {
|
|
152
|
-
if (!text.trim())
|
|
153
|
-
return null;
|
|
154
|
-
const outcome = interpretMiniReActResult({
|
|
155
|
-
raw: { text, result: text },
|
|
156
|
-
preview: text.length > 200 ? `${text.slice(0, 200)}...` : text,
|
|
157
|
-
}, !!step.output_schema);
|
|
158
|
-
return outcome.ok ? outcome.value : null;
|
|
159
|
-
}
|
|
160
|
-
function describeAttemptForDoneWhen(outcome) {
|
|
161
|
-
const textState = outcome.rawText.trim()
|
|
162
|
-
? '本轮有文本报告'
|
|
163
|
-
: '本轮没有文本报告';
|
|
164
|
-
if (!outcome.sawToolCall) {
|
|
165
|
-
return `${textState},且没有观察到工具调用;请不要只宣告计划,必须调用工具完成产物。`;
|
|
166
|
-
}
|
|
167
|
-
const names = outcome.toolNames.length ? outcome.toolNames.join('、') : '未知工具';
|
|
168
|
-
const wrote = outcome.toolNames.some((name) => ['Write', 'Edit', 'MultiEdit', 'Bash'].includes(name));
|
|
169
|
-
const writeHint = wrote
|
|
170
|
-
? '已观察到写入类工具调用,但完成条件仍未满足,请检查路径或实际写入结果'
|
|
171
|
-
: '未观察到写入类工具调用,请立即调用 Write/Edit/Bash 落盘产物';
|
|
172
|
-
return `${textState};本轮工具调用:${names}(成功 ${outcome.toolOkCount},失败 ${outcome.toolFailCount})。${writeHint}。`;
|
|
173
|
-
}
|