minimal-agent 0.10.0 → 0.12.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 +11 -3
- package/package.json +52 -5
- package/plugins/computer_use/.claude-plugin/plugin.json +6 -0
- package/plugins/computer_use/README.md +94 -0
- package/plugins/computer_use/app/_template.md +142 -0
- package/plugins/computer_use/app/chrome.md +165 -0
- package/plugins/computer_use/app/finder.md +76 -0
- package/plugins/computer_use/app/macos-system-settings.md +81 -0
- package/plugins/computer_use/app/microsoft-excel.md +80 -0
- package/plugins/computer_use/app/microsoft-powerpoint.md +80 -0
- package/plugins/computer_use/app/microsoft-word.md +79 -0
- package/plugins/computer_use/app/wechat.md +413 -0
- package/plugins/computer_use/app/weread.md +319 -0
- package/plugins/computer_use/commands/computeruse.md +25 -0
- package/plugins/computer_use/commands/cu.md +9 -0
- package/plugins/computer_use/plugin.js +26 -0
- package/plugins/computer_use/plugin.ts +30 -0
- package/plugins/computer_use/src/capture.js +90 -0
- package/plugins/computer_use/src/capture.ts +104 -0
- package/plugins/computer_use/src/commands.js +91 -0
- package/plugins/computer_use/src/commands.ts +103 -0
- package/plugins/computer_use/src/daemon.js +134 -0
- package/plugins/computer_use/src/daemon.ts +161 -0
- package/plugins/computer_use/src/manuals.js +135 -0
- package/plugins/computer_use/src/manuals.ts +159 -0
- package/plugins/computer_use/src/verify.js +168 -0
- package/plugins/computer_use/src/verify.ts +219 -0
- package/plugins/computer_use/test/commands.test.ts +73 -0
- package/plugins/cron-runner/plugin.ts +38 -0
- package/plugins/cron-runner/src/commands.ts +373 -0
- package/plugins/cron-runner/src/cronTime.ts +155 -0
- package/plugins/cron-runner/src/lock.ts +79 -0
- package/plugins/cron-runner/src/runs.ts +99 -0
- package/plugins/cron-runner/src/scheduleEngine.ts +76 -0
- package/plugins/cron-runner/src/scheduler.ts +376 -0
- package/plugins/cron-runner/src/schema.ts +139 -0
- package/plugins/cron-runner/src/service.ts +193 -0
- package/plugins/cron-runner/src/store.ts +333 -0
- package/plugins/cron-runner/src/types.ts +141 -0
- package/plugins/cron-runner/test/cronTime.test.ts +41 -0
- package/plugins/cron-runner/test/plugin-integration.test.ts +47 -0
- package/plugins/cron-runner/test/scheduleEngine.test.ts +41 -0
- package/plugins/cron-runner/test/service.test.ts +76 -0
- package/plugins/cron-runner/test/store-and-scheduler.test.ts +501 -0
- package/plugins/workflow-runner/plugin.js +56 -2
- package/plugins/workflow-runner/plugin.ts +113 -0
- package/plugins/workflow-runner/src/agentCommon.js +43 -4
- package/plugins/workflow-runner/src/agentCommon.ts +435 -0
- package/plugins/workflow-runner/src/controlFlow/branch.js +40 -0
- package/plugins/workflow-runner/src/controlFlow/branch.ts +46 -0
- package/plugins/workflow-runner/src/controlFlow/loop.js +211 -0
- package/plugins/workflow-runner/src/controlFlow/loop.ts +248 -0
- package/plugins/workflow-runner/src/controlFlow/pause.js +129 -0
- package/plugins/workflow-runner/src/controlFlow/pause.ts +141 -0
- package/plugins/workflow-runner/src/controlFlow/signal.js +21 -0
- package/plugins/workflow-runner/src/controlFlow/signal.ts +29 -0
- package/plugins/workflow-runner/src/controlFlow/types.js +18 -0
- package/plugins/workflow-runner/src/controlFlow/types.ts +63 -0
- package/plugins/workflow-runner/src/dslManifest.ts +127 -0
- package/plugins/workflow-runner/src/expressions.ts +622 -0
- package/plugins/workflow-runner/src/index.js +13 -4
- package/plugins/workflow-runner/src/index.ts +338 -0
- package/plugins/workflow-runner/src/jsonPayload.ts +84 -0
- package/plugins/workflow-runner/src/loader.js +23 -0
- package/plugins/workflow-runner/src/loader.ts +721 -0
- package/plugins/workflow-runner/src/multimodal.js +2 -1
- package/plugins/workflow-runner/src/multimodal.ts +64 -0
- package/plugins/workflow-runner/src/recovery.ts +149 -0
- package/plugins/workflow-runner/src/runner.js +75 -659
- package/plugins/workflow-runner/src/runner.ts +604 -0
- package/plugins/workflow-runner/src/stepExecutors/agent.ts +234 -0
- package/plugins/workflow-runner/src/stepExecutors/assert.ts +50 -0
- package/plugins/workflow-runner/src/stepExecutors/echo.js +31 -0
- package/plugins/workflow-runner/src/stepExecutors/echo.ts +38 -0
- package/plugins/workflow-runner/src/stepExecutors/llm.ts +133 -0
- package/plugins/workflow-runner/src/stepExecutors/set.js +49 -0
- package/plugins/workflow-runner/src/stepExecutors/set.ts +56 -0
- package/plugins/workflow-runner/src/stepExecutors/skill.js +5 -6
- package/plugins/workflow-runner/src/stepExecutors/skill.ts +140 -0
- package/plugins/workflow-runner/src/stepExecutors/tool.js +80 -8
- package/plugins/workflow-runner/src/stepExecutors/tool.ts +256 -0
- package/plugins/workflow-runner/src/stepExecutors/verify.ts +68 -0
- package/plugins/workflow-runner/src/stepPipeline.js +277 -0
- package/plugins/workflow-runner/src/stepPipeline.ts +366 -0
- package/plugins/workflow-runner/src/taskIdentity.ts +405 -0
- package/plugins/workflow-runner/src/toolRuntime.js +48 -0
- package/plugins/workflow-runner/src/toolRuntime.ts +64 -0
- package/plugins/workflow-runner/src/types.js +37 -1
- package/plugins/workflow-runner/src/types.ts +602 -0
- package/plugins/workflow-runner/src/workflowState.ts +733 -0
- package/plugins/workflow-runner/test/agent.test.ts +587 -0
- package/plugins/workflow-runner/test/agentLlmError.test.ts +373 -0
- package/plugins/workflow-runner/test/bashBlacklist.sweep.test.ts +65 -0
- package/plugins/workflow-runner/test/captureMisbind.test.ts +99 -0
- package/plugins/workflow-runner/test/cli.e2e.test.ts +147 -0
- package/plugins/workflow-runner/test/context-files.test.ts +320 -0
- package/plugins/workflow-runner/test/e2e.test.ts +370 -0
- package/plugins/workflow-runner/test/engineRobustness.test.ts +226 -0
- package/plugins/workflow-runner/test/expressions.test.ts +397 -0
- package/plugins/workflow-runner/test/foundation.test.ts +126 -0
- package/plugins/workflow-runner/test/graceful.test.ts +139 -0
- package/plugins/workflow-runner/test/greedyInputs.load.test.ts +47 -0
- package/plugins/workflow-runner/test/hostCapability.test.ts +108 -0
- package/plugins/workflow-runner/test/illustrate.load.test.ts +183 -0
- package/plugins/workflow-runner/test/jsonPayload.test.ts +83 -0
- package/plugins/workflow-runner/test/loader.test.ts +617 -0
- package/plugins/workflow-runner/test/maxTurnsRetryDelay.test.ts +33 -0
- package/plugins/workflow-runner/test/multimodal.test.ts +342 -0
- package/plugins/workflow-runner/test/output-schema.test.ts +213 -0
- package/plugins/workflow-runner/test/parseWorkflowArgs.test.ts +87 -0
- package/plugins/workflow-runner/test/pluginRunner.isolation.test.ts +269 -0
- package/plugins/workflow-runner/test/ppt.load.test.ts +1220 -0
- package/plugins/workflow-runner/test/ralphLoop.e2e.test.ts +220 -0
- package/plugins/workflow-runner/test/recovery.test.ts +265 -0
- package/plugins/workflow-runner/test/runner.test.ts +911 -0
- package/plugins/workflow-runner/test/runnerPreflight.test.ts +379 -0
- package/plugins/workflow-runner/test/skillTurnDone.test.ts +71 -0
- package/plugins/workflow-runner/test/stateLifecycle.test.ts +150 -0
- package/plugins/workflow-runner/test/stepPipeline.test.ts +114 -0
- package/plugins/workflow-runner/test/taskArbitration.test.ts +338 -0
- package/plugins/workflow-runner/test/taskIdentity.test.ts +237 -0
- package/plugins/workflow-runner/test/taskLifecycle.test.ts +270 -0
- package/plugins/workflow-runner/test/toolArtifactOverwrite.test.ts +221 -0
- package/plugins/workflow-runner/test/toolCapabilityBoundary.test.ts +29 -0
- package/plugins/workflow-runner/test/toolRuntimeIntegration.test.ts +168 -0
- package/plugins/workflow-runner/test/webppt.load.test.ts +250 -0
- package/plugins/workflow-runner/test/word.load.test.ts +208 -0
- package/plugins/workflow-runner/test/workflows.smoke.test.ts +76 -0
- package/plugins/workflow-runner/test/yamlGuardConditions.test.ts +207 -0
- package/skills/browser-automation/SKILL.md +9 -19
- package/skills/web-crawler/SKILL.md +9 -11
- package/src/askBridge.ts +249 -0
- package/src/bootstrap/cwdArg.js +10 -3
- package/src/bootstrap/cwdArg.ts +31 -0
- package/src/bootstrap/workingDir.ts +48 -0
- package/src/cli/args.js +70 -7
- package/src/cli/args.ts +146 -0
- package/src/cli/computerUse.js +185 -0
- package/src/cli/computerUse.ts +221 -0
- package/src/cli/configMenu.js +274 -202
- package/src/cli/configMenu.tsx +521 -0
- package/src/cli/memoryAccess.js +45 -0
- package/src/cli/memoryAccess.ts +53 -0
- package/src/cli/print.js +119 -5
- package/src/cli/print.ts +597 -0
- package/src/cli/quickModelSetup.js +60 -0
- package/src/cli/quickModelSetup.tsx +96 -0
- package/src/cli/streamJson.js +80 -4
- package/src/cli/streamJson.ts +433 -0
- package/src/cli/wizards/advisorWizard.js +1 -0
- package/src/cli/wizards/advisorWizard.tsx +195 -0
- package/src/cli/wizards/agentRuntimeWizard.js +84 -0
- package/src/cli/wizards/agentRuntimeWizard.tsx +134 -0
- package/src/cli/wizards/browserWizard.js +55 -0
- package/src/cli/wizards/browserWizard.tsx +77 -0
- package/src/cli/wizards/contextAdvisorWizard.js +84 -0
- package/src/cli/wizards/contextAdvisorWizard.tsx +124 -0
- package/src/cli/wizards/fieldForm.js +7 -4
- package/src/cli/wizards/fieldForm.tsx +250 -0
- package/src/cli/wizards/imageWizard.js +4 -5
- package/src/cli/wizards/imageWizard.tsx +96 -0
- package/src/cli/wizards/openRouterWizard.tsx +48 -0
- package/src/cli/wizards/providerPresets.js +1 -8
- package/src/cli/wizards/providerPresets.ts +106 -0
- package/src/cli/wizards/providerWizard.js +152 -205
- package/src/cli/wizards/providerWizard.tsx +266 -0
- package/src/cli/wizards/searchWizard.tsx +47 -0
- package/src/cli/wizards/ttsWizard.js +4 -3
- package/src/cli/wizards/ttsWizard.tsx +61 -0
- package/src/config/configDefaults.js +25 -0
- package/src/config/configDefaults.ts +33 -0
- package/src/config/configDiagnostics.js +117 -0
- package/src/config/configDiagnostics.ts +166 -0
- package/src/config/configFile.js +52 -32
- package/src/config/configFile.ts +633 -0
- package/src/config/configManagement.js +126 -0
- package/src/config/configManagement.ts +159 -0
- package/src/config/configService.js +66 -11
- package/src/config/configService.ts +554 -0
- package/src/config/numericLimits.js +61 -0
- package/src/config/numericLimits.ts +80 -0
- package/src/config.ts +109 -0
- package/src/context/agentHome.ts +11 -0
- package/src/context/archive.ts +144 -0
- package/src/context/budgetPlan.js +54 -0
- package/src/context/budgetPlan.ts +88 -0
- package/src/context/compact.js +179 -106
- package/src/context/compact.ts +584 -0
- package/src/context/contextBundle.js +119 -0
- package/src/context/contextBundle.ts +176 -0
- package/src/context/contextLock.ts +84 -0
- package/src/context/microCompactLite.ts +218 -0
- package/src/context/persistContext.ts +177 -0
- package/src/context/reactiveCompact.js +19 -4
- package/src/context/reactiveCompact.ts +240 -0
- package/src/context/recentDirs.ts +42 -0
- package/src/context/sessionPath.ts +206 -0
- package/src/context/sessionRegistry.js +8 -2
- package/src/context/sessionRegistry.ts +414 -0
- package/src/context/snipCompact.ts +163 -0
- package/src/context/tokenCounter.ts +106 -0
- package/src/context/workspaceIndex.js +2 -2
- package/src/context/workspaceIndex.ts +751 -0
- package/src/entry.compiled.tsx +20 -0
- package/src/harness/claimValidation.js +9 -0
- package/src/harness/claimValidation.ts +22 -0
- package/src/harness/evidenceLedger.js +92 -0
- package/src/harness/evidenceLedger.ts +96 -0
- package/src/harness/stallGuard.js +60 -0
- package/src/harness/stallGuard.ts +81 -0
- package/src/humanIntervention.js +129 -0
- package/src/humanIntervention.ts +216 -0
- package/src/infra/verification.ts +295 -0
- package/src/irreversible/rules.js +216 -0
- package/src/irreversible/rules.ts +261 -0
- package/src/llm/client.js +40 -3
- package/src/llm/client.ts +621 -0
- package/src/llm/promptCache.js +27 -0
- package/src/llm/promptCache.ts +41 -0
- package/src/llm/providers/anthropicFormat.js +41 -5
- package/src/llm/providers/anthropicFormat.ts +290 -0
- package/src/llm/providers/openaiFormat.js +186 -8
- package/src/llm/providers/openaiFormat.ts +428 -0
- package/src/loop.js +614 -63
- package/src/loop.ts +1454 -0
- package/src/main.js +67 -10
- package/src/main.tsx +344 -0
- package/src/memory/codec.js +204 -0
- package/src/memory/codec.ts +249 -0
- package/src/memory/constants.js +34 -0
- package/src/memory/constants.ts +50 -0
- package/src/memory/episodicMemory.js +684 -0
- package/src/memory/episodicMemory.ts +815 -0
- package/src/memory/fileStore.js +148 -0
- package/src/memory/fileStore.ts +184 -0
- package/src/memory/memoryService.js +570 -0
- package/src/memory/memoryService.ts +859 -0
- package/src/memory/migration.js +128 -0
- package/src/memory/migration.ts +160 -0
- package/src/memory/repository.js +789 -0
- package/src/memory/repository.ts +893 -0
- package/src/memory/retrieval.js +108 -0
- package/src/memory/retrieval.ts +145 -0
- package/src/memory/searchIndex.js +107 -0
- package/src/memory/searchIndex.ts +153 -0
- package/src/memory/topicView.js +82 -0
- package/src/memory/topicView.ts +95 -0
- package/src/memory/turnJournal.js +95 -0
- package/src/memory/turnJournal.ts +120 -0
- package/src/memory/types.js +2 -0
- package/src/memory/types.ts +186 -0
- package/src/messageQueue.ts +123 -0
- package/src/multimodal.js +128 -46
- package/src/multimodal.ts +349 -0
- package/src/plugin-sdk.js +21 -1
- package/src/plugin-sdk.ts +134 -0
- package/src/plugins/builtinPluginIds.js +47 -0
- package/src/plugins/builtinPluginIds.ts +51 -0
- package/src/plugins/builtinRegistry.ts +43 -0
- package/src/plugins/commandRouter.js +40 -26
- package/src/plugins/commandRouter.ts +261 -0
- package/src/plugins/hookEngine.ts +341 -0
- package/src/plugins/pluginApi.ts +133 -0
- package/src/plugins/pluginLifecycle.ts +34 -0
- package/src/plugins/pluginLoader.ts +147 -0
- package/src/plugins/pluginManifest.js +127 -0
- package/src/plugins/pluginManifest.ts +152 -0
- package/src/plugins/pluginRunner.js +47 -2
- package/src/plugins/pluginRunner.ts +207 -0
- package/src/plugins/transcript.ts +208 -0
- package/src/prompts/lint.js +169 -0
- package/src/prompts/lint.ts +220 -0
- package/src/prompts/pluginList.js +32 -16
- package/src/prompts/pluginList.ts +86 -0
- package/src/prompts/policyRegistry.js +318 -0
- package/src/prompts/policyRegistry.ts +358 -0
- package/src/prompts/projectInstructions.js +24 -0
- package/src/prompts/projectInstructions.ts +81 -0
- package/src/prompts/promptAssembly.js +311 -202
- package/src/prompts/promptAssembly.ts +510 -0
- package/src/prompts/skillList.js +106 -45
- package/src/prompts/skillList.ts +198 -0
- package/src/prompts/system.js +31 -6
- package/src/prompts/system.ts +81 -0
- package/src/runtime/agentRuntimeContext.js +53 -0
- package/src/runtime/agentRuntimeContext.ts +112 -0
- package/src/session/runAgentTurn.js +71 -12
- package/src/session/runAgentTurn.ts +181 -0
- package/src/session/runTurn.js +29 -0
- package/src/session/runTurn.ts +160 -0
- package/src/session/runtimeStore.js +149 -0
- package/src/session/runtimeStore.ts +197 -0
- package/src/session/sessionState.js +79 -3
- package/src/session/sessionState.ts +134 -0
- package/src/toolGate.ts +50 -0
- package/src/tools/advisor/advisor.js +76 -15
- package/src/tools/advisor/advisor.ts +512 -0
- package/src/tools/agent/agent.js +245 -29
- package/src/tools/agent/agent.ts +837 -0
- package/src/tools/agent/agentTaskService.js +60 -0
- package/src/tools/agent/agentTaskService.ts +113 -0
- package/src/tools/agent/agentTypes.js +20 -8
- package/src/tools/agent/agentTypes.ts +94 -0
- package/src/tools/agent/coordinator.ts +111 -0
- package/src/tools/agent/worktree.ts +296 -0
- package/src/tools/ask/ask.js +17 -0
- package/src/tools/ask/ask.ts +122 -0
- package/src/tools/bash/attachImage.js +223 -0
- package/src/tools/bash/attachImage.ts +281 -0
- package/src/tools/bash/bash.js +132 -14
- package/src/tools/bash/bash.ts +642 -0
- package/src/tools/bash/semantics.ts +103 -0
- package/src/tools/bash/warnings.js +17 -11
- package/src/tools/bash/warnings.ts +117 -0
- package/src/tools/capabilities.js +42 -0
- package/src/tools/capabilities.ts +69 -0
- package/src/tools/computeruse/accessibilityPermission.js +261 -0
- package/src/tools/computeruse/accessibilityPermission.ts +294 -0
- package/src/tools/computeruse/axSearch.js +96 -0
- package/src/tools/computeruse/axSearch.ts +120 -0
- package/src/tools/computeruse/axSnap.js +272 -0
- package/src/tools/computeruse/axSnap.ts +349 -0
- package/src/tools/computeruse/capabilityLabels.js +95 -0
- package/src/tools/computeruse/capabilityLabels.ts +115 -0
- package/src/tools/computeruse/computerUseService.js +2235 -0
- package/src/tools/computeruse/computerUseService.ts +2686 -0
- package/src/tools/computeruse/computeruse.js +2742 -0
- package/src/tools/computeruse/computeruse.ts +3265 -0
- package/src/tools/computeruse/diagnosticTrace.js +154 -0
- package/src/tools/computeruse/diagnosticTrace.ts +195 -0
- package/src/tools/computeruse/diagnostics.js +369 -0
- package/src/tools/computeruse/diagnostics.ts +453 -0
- package/src/tools/computeruse/grants.js +53 -0
- package/src/tools/computeruse/grants.ts +70 -0
- package/src/tools/computeruse/humanBoundary.js +159 -0
- package/src/tools/computeruse/humanBoundary.ts +199 -0
- package/src/tools/computeruse/intervention.js +77 -0
- package/src/tools/computeruse/intervention.ts +110 -0
- package/src/tools/computeruse/manualSchema.js +709 -0
- package/src/tools/computeruse/manualSchema.ts +916 -0
- package/src/tools/computeruse/observationImages.js +705 -0
- package/src/tools/computeruse/observationImages.ts +889 -0
- package/src/tools/computeruse/protocol.js +60 -0
- package/src/tools/computeruse/protocol.ts +515 -0
- package/src/tools/computeruse/telemetryLog.js +57 -0
- package/src/tools/computeruse/telemetryLog.ts +67 -0
- package/src/tools/computeruse/vision/appGuide.js +325 -0
- package/src/tools/computeruse/vision/appGuide.ts +482 -0
- package/src/tools/computeruse/vision/focus.js +291 -0
- package/src/tools/computeruse/vision/focus.ts +382 -0
- package/src/tools/computeruse/vision/frames.js +248 -0
- package/src/tools/computeruse/vision/frames.ts +329 -0
- package/src/tools/computeruse/vision/geometry.js +131 -0
- package/src/tools/computeruse/vision/geometry.ts +163 -0
- package/src/tools/computeruse/vision/imaging.js +201 -0
- package/src/tools/computeruse/vision/imaging.ts +281 -0
- package/src/tools/computeruse/vision/png.js +274 -0
- package/src/tools/computeruse/vision/png.ts +317 -0
- package/src/tools/computeruse/vision/raster.js +320 -0
- package/src/tools/computeruse/vision/raster.ts +408 -0
- package/src/tools/computeruse/vision/settle.js +131 -0
- package/src/tools/computeruse/vision/settle.ts +220 -0
- package/src/tools/computeruse/vision/telemetry.js +196 -0
- package/src/tools/computeruse/vision/telemetry.ts +241 -0
- package/src/tools/computeruse/visionOcr.js +115 -0
- package/src/tools/computeruse/visionOcr.ts +128 -0
- package/src/tools/computeruse/waitFor.js +237 -0
- package/src/tools/computeruse/waitFor.ts +291 -0
- package/src/tools/download/download.js +10 -6
- package/src/tools/download/download.ts +187 -0
- package/src/tools/edit/edit.js +30 -18
- package/src/tools/edit/edit.ts +349 -0
- package/src/tools/edit/multi-edit.js +25 -14
- package/src/tools/edit/multi-edit.ts +223 -0
- package/src/tools/effectiveToolSet.js +73 -0
- package/src/tools/effectiveToolSet.ts +91 -0
- package/src/tools/genimage/genimage.ts +257 -0
- package/src/tools/genspeech/genspeech.ts +83 -0
- package/src/tools/glob/glob.js +176 -29
- package/src/tools/glob/glob.ts +283 -0
- package/src/tools/grep/grep.js +61 -19
- package/src/tools/grep/grep.ts +239 -0
- package/src/tools/grep/rgPath.ts +206 -0
- package/src/tools/index.js +99 -5
- package/src/tools/index.ts +293 -0
- package/src/tools/lsp/config.js +113 -0
- package/src/tools/lsp/config.ts +113 -0
- package/src/tools/lsp/lsp.js +256 -0
- package/src/tools/lsp/lsp.ts +274 -0
- package/src/tools/lsp/service.js +303 -0
- package/src/tools/lsp/service.ts +296 -0
- package/src/tools/memory/memory.js +520 -0
- package/src/tools/memory/memory.ts +625 -0
- package/src/tools/memory/policy.js +53 -0
- package/src/tools/memory/policy.ts +72 -0
- package/src/tools/notebook/notebookEdit.js +114 -0
- package/src/tools/notebook/notebookEdit.ts +126 -0
- package/src/tools/powershell/powershell.js +210 -0
- package/src/tools/powershell/powershell.ts +239 -0
- package/src/tools/presentresult/presentresult.js +145 -0
- package/src/tools/presentresult/presentresult.ts +156 -0
- package/src/tools/read/read.js +371 -163
- package/src/tools/read/read.ts +558 -0
- package/src/tools/shared/diffSummary.js +44 -0
- package/src/tools/shared/diffSummary.ts +63 -0
- package/src/tools/shared/fileActivity.js +51 -0
- package/src/tools/shared/fileActivity.ts +66 -0
- package/src/tools/shared/fileMutationBus.js +13 -0
- package/src/tools/shared/fileMutationBus.ts +14 -0
- package/src/tools/shared/fileState.js +73 -65
- package/src/tools/shared/fileState.ts +145 -0
- package/src/tools/shared/fileUtils.js +81 -4
- package/src/tools/shared/fileUtils.ts +504 -0
- package/src/tools/shared/killTree.ts +50 -0
- package/src/tools/shared/permanentDeleteGuard.js +26 -0
- package/src/tools/shared/permanentDeleteGuard.ts +34 -0
- package/src/tools/shared/schemas.ts +20 -0
- package/src/tools/shared/toolOutputStore.js +97 -0
- package/src/tools/shared/toolOutputStore.ts +110 -0
- package/src/tools/skill/skill.js +86 -0
- package/src/tools/skill/skill.ts +94 -0
- package/src/tools/snip/snip.js +67 -0
- package/src/tools/snip/snip.ts +80 -0
- package/src/tools/tasks/backgroundTaskService.js +275 -0
- package/src/tools/tasks/backgroundTaskService.ts +369 -0
- package/src/tools/tasks/processEvidence.js +24 -0
- package/src/tools/tasks/processEvidence.ts +34 -0
- package/src/tools/tasks/taskManagement.js +163 -0
- package/src/tools/tasks/taskManagement.ts +180 -0
- package/src/tools/tasks/taskOutput.js +113 -0
- package/src/tools/tasks/taskOutput.ts +145 -0
- package/src/tools/tasks/taskStop.js +74 -0
- package/src/tools/tasks/taskStop.ts +99 -0
- package/src/tools/tasks/taskStore.js +46 -0
- package/src/tools/tasks/taskStore.ts +77 -0
- package/src/tools/terminal/terminalCapture.js +167 -0
- package/src/tools/terminal/terminalCapture.ts +179 -0
- package/src/tools/trash/trash.js +233 -0
- package/src/tools/trash/trash.ts +283 -0
- package/src/tools/types.js +1 -1
- package/src/tools/types.ts +24 -0
- package/src/tools/webbrowser/agentBrowserPath.ts +286 -0
- package/src/tools/webbrowser/browser.js +214 -11
- package/src/tools/webbrowser/browser.ts +293 -0
- package/src/tools/webbrowser/browserControl.js +153 -48
- package/src/tools/webbrowser/browserControl.ts +262 -0
- package/src/tools/webbrowser/browserDaemon.js +147 -39
- package/src/tools/webbrowser/browserDaemon.ts +270 -0
- package/src/tools/webbrowser/browserOutcome.js +273 -0
- package/src/tools/webbrowser/browserOutcome.ts +306 -0
- package/src/tools/webbrowser/browserRunRegistry.js +150 -0
- package/src/tools/webbrowser/browserRunRegistry.ts +179 -0
- package/src/tools/webbrowser/browserService.js +20 -6
- package/src/tools/webbrowser/browserService.ts +56 -0
- package/src/tools/webbrowser/browserStream.js +30 -1
- package/src/tools/webbrowser/browserStream.ts +216 -0
- package/src/tools/webbrowser/browserTabs.js +143 -0
- package/src/tools/webbrowser/browserTabs.ts +210 -0
- package/src/tools/webbrowser/webbrowser.js +831 -150
- package/src/tools/webbrowser/webbrowser.ts +1537 -0
- package/src/tools/webfetch/preapproved.ts +274 -0
- package/src/tools/webfetch/webfetch.js +24 -23
- package/src/tools/webfetch/webfetch.ts +383 -0
- package/src/tools/websearch/websearch.js +12 -11
- package/src/tools/websearch/websearch.ts +292 -0
- package/src/tools/worktree/sessionWorktree.js +128 -0
- package/src/tools/worktree/sessionWorktree.ts +158 -0
- package/src/tools/write/write.js +27 -44
- package/src/tools/write/write.ts +136 -0
- package/src/types.ts +960 -0
- package/src/ui/App.js +216 -12
- package/src/ui/App.tsx +879 -0
- package/src/ui/AskQuestion.tsx +300 -0
- package/src/ui/InputBox.js +77 -1
- package/src/ui/InputBox.tsx +567 -0
- package/src/ui/LiveArea.tsx +344 -0
- package/src/ui/MessageList.js +27 -6
- package/src/ui/MessageList.tsx +559 -0
- package/src/ui/ModelPicker.tsx +107 -0
- package/src/ui/QueuedMessagesBanner.tsx +51 -0
- package/src/ui/Root.js +6 -8
- package/src/ui/Root.tsx +100 -0
- package/src/ui/SessionPicker.tsx +169 -0
- package/src/ui/StatusLine.js +22 -1
- package/src/ui/StatusLine.tsx +145 -0
- package/src/ui/WorkspacePicker.tsx +84 -0
- package/src/ui/advisorCommand.js +54 -0
- package/src/ui/advisorCommand.ts +63 -0
- package/src/ui/computerCommand.js +19 -0
- package/src/ui/computerCommand.ts +35 -0
- package/src/ui/figures.ts +45 -0
- package/src/ui/hooks/askSlot.ts +112 -0
- package/src/ui/hooks/useChat.js +271 -7
- package/src/ui/hooks/useChat.ts +1578 -0
- package/src/ui/hooks/useInputHistory.ts +235 -0
- package/src/ui/hooks/usePasteHandler.ts +220 -0
- package/src/ui/hooks/useTerminalSize.ts +41 -0
- package/src/ui/hooks/useTextBuffer.ts +108 -0
- package/src/ui/hooks/useTokenUsage.ts +44 -0
- package/src/ui/liveViewport.ts +189 -0
- package/src/ui/markdown.ts +230 -0
- package/src/ui/textBuffer.ts +239 -0
- package/src/ui/theme.ts +35 -0
- package/src/utils/clipboardImage.js +358 -0
- package/src/utils/clipboardImage.ts +420 -0
- package/src/utils/debugLog.ts +50 -0
- package/src/utils/greenRoot.ts +35 -0
- package/src/utils/packageRoot.ts +40 -0
- package/src/utils/pathContains.js +28 -0
- package/src/utils/pathContains.ts +31 -0
- package/src/utils/resourcePaths.ts +71 -0
- package/src/utils/stripThink.ts +49 -0
- package/src/utils/zodToJson.ts +73 -0
- package/src/web/browserBridge.js +365 -66
- package/src/web/browserBridge.ts +672 -0
- package/src/web/protocol.ts +1804 -0
- package/vendor/computer-use/arm64-darwin/cu-helperd +0 -0
- package/workflows/ppt.yaml +13 -2
- package/workflows/wechat-reading-shots.yaml +315 -0
- package/workflows/word.yaml +11 -1
- package/skills/docx/scripts/office/helpers/__pycache__/__init__.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/helpers/__pycache__/merge_runs.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/helpers/__pycache__/simplify_redlines.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/__init__.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/base.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/docx.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/pptx.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/redlining.cpython-314.pyc +0 -0
- package/skills/image-stats/scripts/__pycache__/image_stats.cpython-314.pyc +0 -0
- package/skills/image-stats/scripts/__pycache__/image_stats_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/assemble_material.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/assemble_material_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/chart_sanity_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/check_language_policy.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/check_ui_artifact.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/check_ui_artifact_pptx_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/deck_pages_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/deck_pages_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/deck_visual_style_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/deck_visual_style_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_budget_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_budget_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_repair_hints.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_repair_hints_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_style_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_style_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/draft_coverage_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/extract_source_assets.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/extract_source_assets_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/generated_image_review_collect.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/generated_image_review_collect_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/image_plan_lint.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/image_plan_lint_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/image_prompt_rewrite.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/image_prompt_rewrite_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/layout_balance.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/layout_balance_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/normalize_design_json.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/normalize_design_json_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/plan_source_layout.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/plan_source_layout_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/resolve_source_hint.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/resolve_source_hint_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/resolve_source_input.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/resolve_source_input_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/scaffold_ui_artifact.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/source_usage_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/source_usage_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/text_readability_pixel.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/visual_quality_gate.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/visual_quality_gate_test.cpython-314.pyc +0 -0
- /package/skills/ai-image/scripts/{generate_test.mjs → generate.selftest.mjs} +0 -0
- /package/skills/ai-image/scripts/{generate_from_plan_test.mjs → generate_from_plan.selftest.mjs} +0 -0
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================
|
|
3
|
+
* plugins/workflow-runner/test/agentLlmError.test.ts
|
|
4
|
+
* ------------------------------------------------------------
|
|
5
|
+
* agent 步的 llm_error 归因契约(P0-A 回归锚):
|
|
6
|
+
*
|
|
7
|
+
* runQuery 遇 LLM 超时/网络错是 yield error(code:'llm_error') 后 return(不 throw)。
|
|
8
|
+
* 曾经 agent.ts 只侦测 'aborted',provider 失败被验证闸门误归因为
|
|
9
|
+
* 「agent 步骤放弃: 没有产出任何结果」——与 llm/skill 步的诚实归因
|
|
10
|
+
* 「LLM 调用失败且无产出(触发重试)」不一致(现场日志可见同一运行两种文案)。
|
|
11
|
+
*
|
|
12
|
+
* 本文件锁定三条语义:
|
|
13
|
+
* 1. LLM 失败且无产出 → 抛「可重试失败」→ runner in-run retry → 重试成功则 done
|
|
14
|
+
* 2. 重试耗尽 → halt 文案是「LLM 调用失败且无产出」,不是「步骤放弃」
|
|
15
|
+
* 3. 用户中断(signal.aborted)→ 不触发任何重试(红线:aborted 不重试)
|
|
16
|
+
*
|
|
17
|
+
* 约定:DI 注入 ctx.chat(不 mock.module client/loop/plugin-sdk),走真实 runQuery。
|
|
18
|
+
* ============================================================
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { afterEach, beforeEach, describe, expect, it, mock } from 'bun:test';
|
|
22
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
23
|
+
import { tmpdir } from 'node:os';
|
|
24
|
+
import { join } from 'node:path';
|
|
25
|
+
|
|
26
|
+
import { _resetWorkingDir } from '../../../src/bootstrap/workingDir.js';
|
|
27
|
+
import type { LoopEvent, Provider } from '../../../src/types.js';
|
|
28
|
+
import { runWorkflow } from '../src/runner.js';
|
|
29
|
+
import type { RunContext, WorkflowDef, WorkflowEvent } from '../src/types.js';
|
|
30
|
+
|
|
31
|
+
type WfOrLoop = WorkflowEvent | LoopEvent;
|
|
32
|
+
|
|
33
|
+
const fakeProvider: Provider = {
|
|
34
|
+
name: 'test',
|
|
35
|
+
baseURL: '',
|
|
36
|
+
apiKey: '',
|
|
37
|
+
model: 'm',
|
|
38
|
+
contextWindow: 128000,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
async function collect(
|
|
42
|
+
gen: AsyncGenerator<WfOrLoop, void, void>,
|
|
43
|
+
): Promise<WfOrLoop[]> {
|
|
44
|
+
const out: WfOrLoop[] = [];
|
|
45
|
+
for await (const ev of gen) out.push(ev);
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
describe('workflows/agent llm_error 归因(P0-A)', () => {
|
|
50
|
+
let tmp: string;
|
|
51
|
+
let ctx: RunContext;
|
|
52
|
+
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
tmp = mkdtempSync(join(tmpdir(), 'wf-agent-llmerr-'));
|
|
55
|
+
process.env.MINIMAL_AGENT_CWD = tmp;
|
|
56
|
+
_resetWorkingDir();
|
|
57
|
+
mock.module('../../../src/bootstrap/workingDir.js', () => ({
|
|
58
|
+
getWorkingDir: () => tmp,
|
|
59
|
+
initWorkingDir: () => tmp,
|
|
60
|
+
_resetWorkingDir: () => {},
|
|
61
|
+
}));
|
|
62
|
+
ctx = { provider: fakeProvider, history: [], cwd: tmp, tools: [] };
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
afterEach(() => {
|
|
66
|
+
delete process.env.MINIMAL_AGENT_CWD;
|
|
67
|
+
_resetWorkingDir();
|
|
68
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('LLM 第一次失败(超时类)→ in-run retry 重跑 → 第二次成功 → workflow done', async () => {
|
|
72
|
+
let call = 0;
|
|
73
|
+
ctx.chat = async function* () {
|
|
74
|
+
call++;
|
|
75
|
+
if (call === 1) throw new Error('socket timeout');
|
|
76
|
+
yield { type: 'text_delta', delta: 'real-result' };
|
|
77
|
+
yield { type: 'done', stopReason: 'stop' };
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const def: WorkflowDef = {
|
|
81
|
+
name: 'agent-llmerr-retry',
|
|
82
|
+
description: 'provider 抖动被 retry 救回',
|
|
83
|
+
steps: [
|
|
84
|
+
{ id: 'a1', agent: '做点事', capture: { content: 'out' }, max_retries: 1 },
|
|
85
|
+
{ id: 'check', type: 'assert', condition: 'out == "real-result"' },
|
|
86
|
+
],
|
|
87
|
+
};
|
|
88
|
+
const events = await collect(runWorkflow(def, {}, ctx));
|
|
89
|
+
|
|
90
|
+
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
91
|
+
// runQuery 的 error(llm_error) 事件会透传给 UI(红字照常显示),
|
|
92
|
+
// 但不应出现 workflow halt(重试已救回)
|
|
93
|
+
expect(
|
|
94
|
+
events.some(
|
|
95
|
+
(e) => e.type === 'error' && e.error.includes('Workflow halted'),
|
|
96
|
+
),
|
|
97
|
+
).toBe(false);
|
|
98
|
+
// 重试 warning 必须出现,且文案是诚实归因(LLM 失败),不是「步骤放弃」
|
|
99
|
+
const retryWarn = events.find(
|
|
100
|
+
(e): e is { type: 'warning'; message: string } =>
|
|
101
|
+
e.type === 'warning' && e.message.includes('重试 1/1'),
|
|
102
|
+
);
|
|
103
|
+
expect(retryWarn).toBeDefined();
|
|
104
|
+
expect(retryWarn!.message).toContain('LLM 调用失败且无产出');
|
|
105
|
+
expect(retryWarn!.message).not.toContain('步骤放弃');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('LLM 持续失败 → 重试耗尽 → halt 文案为「LLM 调用失败且无产出」而非「步骤放弃」', async () => {
|
|
109
|
+
ctx.chat = async function* () {
|
|
110
|
+
throw new Error('connection refused');
|
|
111
|
+
// biome-ignore lint/correctness/noUnreachable: 让 TS 认出 generator 形状
|
|
112
|
+
yield { type: 'done', stopReason: 'stop' };
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const def: WorkflowDef = {
|
|
116
|
+
name: 'agent-llmerr-exhaust',
|
|
117
|
+
description: 'provider 持续故障',
|
|
118
|
+
steps: [{ id: 'a1', agent: '做点事', max_retries: 1 }],
|
|
119
|
+
};
|
|
120
|
+
const events = await collect(runWorkflow(def, {}, ctx));
|
|
121
|
+
|
|
122
|
+
expect(events.some((e) => e.type === 'workflow_done')).toBe(false);
|
|
123
|
+
// 看 halt 事件(runQuery 透传的 error(llm_error) 是另一回事)
|
|
124
|
+
const halt = events.find(
|
|
125
|
+
(e): e is { type: 'error'; error: string } =>
|
|
126
|
+
e.type === 'error' && e.error.includes('Workflow halted'),
|
|
127
|
+
);
|
|
128
|
+
expect(halt).toBeDefined();
|
|
129
|
+
expect(halt!.error).toContain('LLM 调用失败且无产出');
|
|
130
|
+
expect(halt!.error).not.toContain('步骤放弃');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('halt 文案附带 provider 真实报错细节(落 progress.md 的持久证据)', async () => {
|
|
134
|
+
ctx.chat = async function* () {
|
|
135
|
+
throw new Error('ECONNRESET api.minimax.chat 端口 443');
|
|
136
|
+
// biome-ignore lint/correctness/noUnreachable: stub
|
|
137
|
+
yield { type: 'done', stopReason: 'stop' };
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const def: WorkflowDef = {
|
|
141
|
+
name: 'agent-llmerr-detail',
|
|
142
|
+
description: '证据持久化',
|
|
143
|
+
steps: [{ id: 'a1', agent: '做点事', max_retries: 0 }],
|
|
144
|
+
};
|
|
145
|
+
const events = await collect(runWorkflow(def, {}, ctx));
|
|
146
|
+
|
|
147
|
+
const halt = events.find(
|
|
148
|
+
(e): e is { type: 'error'; error: string } =>
|
|
149
|
+
e.type === 'error' && e.error.includes('Workflow halted'),
|
|
150
|
+
);
|
|
151
|
+
expect(halt).toBeDefined();
|
|
152
|
+
// 不再只有「无产出」四个字——provider 报错原文可排障
|
|
153
|
+
expect(halt!.error).toContain('ECONNRESET');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('self_heal.retry_delay_ms 退避生效(重试前等待,线性)', async () => {
|
|
157
|
+
let call = 0;
|
|
158
|
+
ctx.chat = async function* () {
|
|
159
|
+
call++;
|
|
160
|
+
if (call === 1) throw new Error('transient');
|
|
161
|
+
yield { type: 'text_delta', delta: 'ok' };
|
|
162
|
+
yield { type: 'done', stopReason: 'stop' };
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const def: WorkflowDef = {
|
|
166
|
+
name: 'agent-retry-delay',
|
|
167
|
+
description: '退避重试',
|
|
168
|
+
self_heal: { retry_delay_ms: 120 },
|
|
169
|
+
steps: [{ id: 'a1', agent: '做点事', max_retries: 1 }],
|
|
170
|
+
};
|
|
171
|
+
const t0 = Date.now();
|
|
172
|
+
const events = await collect(runWorkflow(def, {}, ctx));
|
|
173
|
+
const elapsed = Date.now() - t0;
|
|
174
|
+
|
|
175
|
+
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
176
|
+
expect(elapsed).toBeGreaterThanOrEqual(110); // 第 1 次重试应等 ~120ms
|
|
177
|
+
// warning 文案可见化退避
|
|
178
|
+
expect(
|
|
179
|
+
events.some((e) => e.type === 'warning' && e.message.includes('120ms 后')),
|
|
180
|
+
).toBe(true);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('agent 撞 maxTurns 截断 → 抛可重试失败 → 重试在共享 history 上续作成功(伪成功根除锚)', async () => {
|
|
184
|
+
// 真事故:execute_plan 撞 25 轮被截断,半截产出被验证闸门当成功放行 →
|
|
185
|
+
// 半成品 PPTX 被整条链当真交付。现在:截断 = 可重试失败,重试 = 续作。
|
|
186
|
+
let chatCalls = 0;
|
|
187
|
+
ctx.executeTool = async () => ({ ok: true, content: 'tool-ok' });
|
|
188
|
+
ctx.chat = async function* () {
|
|
189
|
+
chatCalls++;
|
|
190
|
+
if (chatCalls <= 2) {
|
|
191
|
+
// 前两次一直调工具 → 耗尽 maxTurns=2 被截断
|
|
192
|
+
yield {
|
|
193
|
+
type: 'tool_call_delta',
|
|
194
|
+
index: 0,
|
|
195
|
+
id: `t${chatCalls}`,
|
|
196
|
+
name: 'Glob',
|
|
197
|
+
argumentsDelta: '{"pattern":"*"}',
|
|
198
|
+
};
|
|
199
|
+
yield { type: 'done', stopReason: 'tool_calls' };
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
// 重试(续作):模型看到已有进度,直接给出最终交付
|
|
203
|
+
yield { type: 'text_delta', delta: 'final-deliverable' };
|
|
204
|
+
yield { type: 'done', stopReason: 'stop' };
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const def: WorkflowDef = {
|
|
208
|
+
name: 'agent-maxturns-cutoff',
|
|
209
|
+
description: '截断诚实化',
|
|
210
|
+
steps: [
|
|
211
|
+
{ id: 'a1', agent: '干活', maxTurns: 2, max_retries: 1, capture: { content: 'out' } },
|
|
212
|
+
{ id: 'chk', type: 'assert', condition: 'out == "final-deliverable"' },
|
|
213
|
+
],
|
|
214
|
+
};
|
|
215
|
+
const events = await collect(runWorkflow(def, {}, ctx));
|
|
216
|
+
|
|
217
|
+
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
218
|
+
// 截断被诚实归因 + 触发了重试
|
|
219
|
+
const retryWarn = events.find(
|
|
220
|
+
(e): e is { type: 'warning'; message: string } =>
|
|
221
|
+
e.type === 'warning' &&
|
|
222
|
+
e.message.includes('轮数预算用尽') &&
|
|
223
|
+
e.message.includes('续跑 1/1'),
|
|
224
|
+
);
|
|
225
|
+
expect(retryWarn).toBeDefined();
|
|
226
|
+
expect(retryWarn!.message).not.toContain('提前结束');
|
|
227
|
+
expect(retryWarn!.message).not.toContain('截断时产出不可信');
|
|
228
|
+
expect(retryWarn!.message).not.toContain('__WF_MAX_TURNS_CUTOFF__');
|
|
229
|
+
const retryProgress = events.find(
|
|
230
|
+
(e): e is Extract<typeof e, { type: 'plugin_progress' }> & { message: string } =>
|
|
231
|
+
e.type === 'plugin_progress' &&
|
|
232
|
+
typeof e.message === 'string' &&
|
|
233
|
+
e.message.includes('阶段轮数预算用尽'),
|
|
234
|
+
);
|
|
235
|
+
expect(retryProgress).toBeDefined();
|
|
236
|
+
expect(retryProgress!.message).toContain('正在续跑 1/1');
|
|
237
|
+
expect(retryProgress!.message).not.toContain('截断时产出不可信');
|
|
238
|
+
expect(chatCalls).toBe(3);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it('self_heal.max_turns_retry_delay_ms 只影响 maxTurns 截断重试', async () => {
|
|
242
|
+
let chatCalls = 0;
|
|
243
|
+
ctx.executeTool = async () => ({ ok: true, content: 'tool-ok' });
|
|
244
|
+
ctx.chat = async function* () {
|
|
245
|
+
chatCalls++;
|
|
246
|
+
if (chatCalls <= 2) {
|
|
247
|
+
yield {
|
|
248
|
+
type: 'tool_call_delta',
|
|
249
|
+
index: 0,
|
|
250
|
+
id: `mt-${chatCalls}`,
|
|
251
|
+
name: 'Glob',
|
|
252
|
+
argumentsDelta: '{"pattern":"*"}',
|
|
253
|
+
};
|
|
254
|
+
yield { type: 'done', stopReason: 'tool_calls' };
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
yield { type: 'text_delta', delta: 'done-after-delay' };
|
|
258
|
+
yield { type: 'done', stopReason: 'stop' };
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
const def: WorkflowDef = {
|
|
262
|
+
name: 'agent-maxturns-delay',
|
|
263
|
+
description: '截断错峰续跑',
|
|
264
|
+
self_heal: { retry_delay_ms: 0, max_turns_retry_delay_ms: 80 },
|
|
265
|
+
steps: [{ id: 'a1', agent: '干活', maxTurns: 2, max_retries: 1 }],
|
|
266
|
+
};
|
|
267
|
+
const t0 = Date.now();
|
|
268
|
+
const events = await collect(runWorkflow(def, {}, ctx));
|
|
269
|
+
const elapsed = Date.now() - t0;
|
|
270
|
+
|
|
271
|
+
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
272
|
+
expect(elapsed).toBeGreaterThanOrEqual(70);
|
|
273
|
+
expect(
|
|
274
|
+
events.some(
|
|
275
|
+
(e) =>
|
|
276
|
+
e.type === 'warning' &&
|
|
277
|
+
e.message.includes('轮数预算用尽') &&
|
|
278
|
+
e.message.includes('80ms 后'),
|
|
279
|
+
),
|
|
280
|
+
).toBe(true);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('agent 撞 maxTurns 且重试耗尽 → halt 文案带「被截断」而非伪成功', async () => {
|
|
284
|
+
ctx.executeTool = async () => ({ ok: true, content: 'tool-ok' });
|
|
285
|
+
ctx.chat = async function* () {
|
|
286
|
+
yield {
|
|
287
|
+
type: 'tool_call_delta',
|
|
288
|
+
index: 0,
|
|
289
|
+
id: 'loop-forever',
|
|
290
|
+
name: 'Glob',
|
|
291
|
+
argumentsDelta: '{"pattern":"*"}',
|
|
292
|
+
};
|
|
293
|
+
yield { type: 'done', stopReason: 'tool_calls' };
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
const def: WorkflowDef = {
|
|
297
|
+
name: 'agent-maxturns-exhaust',
|
|
298
|
+
description: 'd',
|
|
299
|
+
steps: [{ id: 'a1', agent: '干活', maxTurns: 2, max_retries: 0 }],
|
|
300
|
+
};
|
|
301
|
+
const events = await collect(runWorkflow(def, {}, ctx));
|
|
302
|
+
|
|
303
|
+
expect(events.some((e) => e.type === 'workflow_done')).toBe(false);
|
|
304
|
+
const halt = events.find(
|
|
305
|
+
(e): e is { type: 'error'; error: string } =>
|
|
306
|
+
e.type === 'error' && e.error.includes('Workflow halted'),
|
|
307
|
+
);
|
|
308
|
+
expect(halt).toBeDefined();
|
|
309
|
+
expect(halt!.error).toContain('被截断');
|
|
310
|
+
expect(halt!.error).toContain('重试额度已用尽');
|
|
311
|
+
expect(halt!.error).not.toContain('截断时产出不可信');
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it('provider finish_reason=length → workflow step 视为截断失败,不把半截文本当交付', async () => {
|
|
315
|
+
ctx.chat = async function* () {
|
|
316
|
+
yield { type: 'text_delta', delta: 'partial deliverable' };
|
|
317
|
+
yield { type: 'done', stopReason: 'length' };
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
const def: WorkflowDef = {
|
|
321
|
+
name: 'agent-provider-length',
|
|
322
|
+
description: 'provider max_tokens 截断',
|
|
323
|
+
steps: [
|
|
324
|
+
{ id: 'a1', agent: '干活', max_retries: 0, capture: { content: 'out' } },
|
|
325
|
+
{ id: 'should_not_run', type: 'assert', condition: 'false' },
|
|
326
|
+
],
|
|
327
|
+
};
|
|
328
|
+
const events = await collect(runWorkflow(def, {}, ctx));
|
|
329
|
+
|
|
330
|
+
expect(events.some((e) => e.type === 'workflow_done')).toBe(false);
|
|
331
|
+
const halt = events.find(
|
|
332
|
+
(e): e is { type: 'error'; error: string } =>
|
|
333
|
+
e.type === 'error' && e.error.includes('Workflow halted'),
|
|
334
|
+
);
|
|
335
|
+
expect(halt).toBeDefined();
|
|
336
|
+
expect(halt!.error).toContain('被截断');
|
|
337
|
+
const startedIds = events
|
|
338
|
+
.filter(
|
|
339
|
+
(e): e is Extract<WorkflowEvent, { type: 'workflow_step_start' }> =>
|
|
340
|
+
e.type === 'workflow_step_start',
|
|
341
|
+
)
|
|
342
|
+
.map((e) => e.id);
|
|
343
|
+
expect(startedIds).not.toContain('should_not_run');
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it('用户中断(signal.aborted)→ 不触发任何重试(aborted 不重试红线)', async () => {
|
|
347
|
+
const ac = new AbortController();
|
|
348
|
+
ctx.signal = ac.signal;
|
|
349
|
+
ctx.chat = async function* () {
|
|
350
|
+
// 模拟用户在 LLM 流式期间按 ESC:中断信号生效 + 流抛 AbortError
|
|
351
|
+
ac.abort();
|
|
352
|
+
const e = new Error('aborted');
|
|
353
|
+
e.name = 'AbortError';
|
|
354
|
+
throw e;
|
|
355
|
+
// biome-ignore lint/correctness/noUnreachable: 让 TS 认出 generator 形状
|
|
356
|
+
yield { type: 'done', stopReason: 'stop' };
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
const def: WorkflowDef = {
|
|
360
|
+
name: 'agent-aborted',
|
|
361
|
+
description: '中断不重试',
|
|
362
|
+
steps: [{ id: 'a1', agent: '做点事', max_retries: 2 }],
|
|
363
|
+
};
|
|
364
|
+
const events = await collect(runWorkflow(def, {}, ctx));
|
|
365
|
+
|
|
366
|
+
expect(events.some((e) => e.type === 'interrupted')).toBe(true);
|
|
367
|
+
expect(events.some((e) => e.type === 'workflow_done')).toBe(false);
|
|
368
|
+
// 关键:没有任何重试 warning(runner 的 !signal.aborted 守卫生效)
|
|
369
|
+
expect(
|
|
370
|
+
events.some((e) => e.type === 'warning' && e.message.includes('重试')),
|
|
371
|
+
).toBe(false);
|
|
372
|
+
});
|
|
373
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* test/bashBlacklist.sweep.test.ts
|
|
3
|
+
* ------------------------------------------------------------
|
|
4
|
+
* 全库不变量:workflows/*.yaml 所有 tool:Bash 步的 command 文本
|
|
5
|
+
* 不得命中 Bash 工具安全黑名单(checkForbidden)。
|
|
6
|
+
*
|
|
7
|
+
* 事故背书(2026-07-02):ppt.yaml stage_export 的 bash 注释「硬门 halt」
|
|
8
|
+
* 被旧版整段裸词扫描误杀——整步执行前被拒 → onError:halt → 确定性死端
|
|
9
|
+
* (resume 原样命令原样再拒),且要真机跑完前 21 阶段才暴露。
|
|
10
|
+
* 本测试把「yaml 命令 × Bash 黑名单」这条集成缝隙压进 CI:
|
|
11
|
+
* 任何 yaml 未来加注释/文案再撞任何黑名单模式,就地红灯。
|
|
12
|
+
*
|
|
13
|
+
* 说明:扫描的是 yaml 原文(含 ${} 插值占位)——作者手写的地雷都在原文里;
|
|
14
|
+
* 运行时插值进来的值属运行数据,不在本测试职责内。
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { describe, expect, it } from 'bun:test';
|
|
18
|
+
import { readdir } from 'node:fs/promises';
|
|
19
|
+
import { join } from 'node:path';
|
|
20
|
+
|
|
21
|
+
import { checkForbidden } from '../../../src/tools/bash/bash.js';
|
|
22
|
+
import { parseWorkflowFile } from '../src/loader.js';
|
|
23
|
+
import type { StepDef } from '../src/types.js';
|
|
24
|
+
|
|
25
|
+
const workflowsDir = join(
|
|
26
|
+
import.meta.dir.replace(/[/\\]test$/, ''), // plugins/workflow-runner
|
|
27
|
+
'..', // plugins
|
|
28
|
+
'..', // 仓库根
|
|
29
|
+
'workflows',
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
/** 递归收集所有嵌套步(loop.do / branch.then / branch.else)。 */
|
|
33
|
+
function collectSteps(steps: StepDef[] | undefined): StepDef[] {
|
|
34
|
+
if (!steps) return [];
|
|
35
|
+
const out: StepDef[] = [];
|
|
36
|
+
for (const s of steps) {
|
|
37
|
+
out.push(s);
|
|
38
|
+
out.push(...collectSteps(s.do), ...collectSteps(s.then), ...collectSteps(s.else));
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
describe('workflows/*.yaml × Bash 安全黑名单 sweep', () => {
|
|
44
|
+
it('所有 tool:Bash 步的 command 不命中黑名单', async () => {
|
|
45
|
+
const files = (await readdir(workflowsDir)).filter((f) => /\.ya?ml$/.test(f));
|
|
46
|
+
expect(files.length).toBeGreaterThan(0);
|
|
47
|
+
|
|
48
|
+
let scanned = 0;
|
|
49
|
+
const hits: string[] = [];
|
|
50
|
+
for (const file of files) {
|
|
51
|
+
const def = await parseWorkflowFile(join(workflowsDir, file));
|
|
52
|
+
for (const step of collectSteps(def.steps)) {
|
|
53
|
+
if (step.tool?.toLowerCase() !== 'bash') continue;
|
|
54
|
+
const command = (step.args as Record<string, unknown> | undefined)?.command;
|
|
55
|
+
if (typeof command !== 'string') continue;
|
|
56
|
+
scanned++;
|
|
57
|
+
const reason = checkForbidden(command);
|
|
58
|
+
if (reason) hits.push(`${file}::${step.id} → ${reason}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
expect(scanned).toBeGreaterThan(0); // 空扫描 = 收集逻辑坏了,别假绿
|
|
63
|
+
expect(hits).toEqual([]);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================
|
|
3
|
+
* capture 绑空了必须响亮说出来
|
|
4
|
+
* ------------------------------------------------------------
|
|
5
|
+
* `capture` 的写法是 `{ 结果字段: 变量名 }`。写反成 `{ 变量名: 结果字段 }`
|
|
6
|
+
* 语法完全合法、加载期查不出来,运行时只是安静地绑一个 undefined。
|
|
7
|
+
*
|
|
8
|
+
* 真实代价(wechat-reading-shots 实测):`text: pager` 写反成 `pager: text` 后,
|
|
9
|
+
* 下游 assert 判假,用户看到的是 onFail 里那句业务文案「三种翻页方式都不奏效」
|
|
10
|
+
* —— 与真实原因(capture 写反)毫无关系,排查方向被彻底带偏,白跑一整轮。
|
|
11
|
+
* 同一个坑 `adaptive-research.yaml` 也踩过一次(文件里留着注释
|
|
12
|
+
* 「曾绑 content 导致 notes 恒 undefined」)。两次 → 够格进引擎。
|
|
13
|
+
* ============================================================
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, expect, mock, test } from 'bun:test';
|
|
17
|
+
import { mkdtempSync } from 'node:fs';
|
|
18
|
+
import { tmpdir } from 'node:os';
|
|
19
|
+
import { join } from 'node:path';
|
|
20
|
+
import { runWorkflow } from '../src/runner.js';
|
|
21
|
+
import type { Provider } from '../../../src/types.js';
|
|
22
|
+
import type { RunContext, WorkflowDef } from '../src/types.js';
|
|
23
|
+
|
|
24
|
+
mock.module('../../../src/llm/client.js', () => ({
|
|
25
|
+
chat: async function* () {
|
|
26
|
+
yield { type: 'text_delta', delta: 'right' };
|
|
27
|
+
yield { type: 'done', stopReason: 'stop' };
|
|
28
|
+
},
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
const provider: Provider = {
|
|
32
|
+
name: 'test',
|
|
33
|
+
baseURL: '',
|
|
34
|
+
apiKey: '',
|
|
35
|
+
model: 'm',
|
|
36
|
+
contextWindow: 128000,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* ⚠️ **工作流名必须每次运行唯一。**
|
|
41
|
+
*
|
|
42
|
+
* 工作流状态目录锚的是 `getWorkingDir()`(进程级),**不是** `RunContext.cwd` ——
|
|
43
|
+
* 见 `runner.ts` 里 `new WorkflowState(getWorkingDir(), def.name)`。
|
|
44
|
+
* 所以给 ctx 传一个 mkdtemp 目录**隔离不了状态**:同名工作流第二次跑会命中
|
|
45
|
+
* 「同名任务此前已完成」而**整条短路**,`workflow_done` 照发、步骤一个不跑 ——
|
|
46
|
+
* 于是断言全部空过,测试在两种实现下都绿,什么都证明不了。
|
|
47
|
+
*
|
|
48
|
+
* 实测踩到:本文件的两条 capture 断言曾在「注入旧行为」时依然全绿,
|
|
49
|
+
* 查下去才发现根本没执行到被测代码。用唯一名根治。
|
|
50
|
+
*/
|
|
51
|
+
function uniqueName(base: string): string {
|
|
52
|
+
return `${base}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function collectWarnings(def: WorkflowDef): Promise<string[]> {
|
|
56
|
+
const ctx = {
|
|
57
|
+
provider,
|
|
58
|
+
history: [{ role: 'system', content: 'sys' }],
|
|
59
|
+
// ⚠️ 每个 case 一个全新目录:工作流状态(.minimal-agent-workflow/<name>/)会让
|
|
60
|
+
// 同名同 goal 的第二次运行走 resume 跳过已完成步 —— 那样 capture 根本不执行,
|
|
61
|
+
// 测试第二次跑就"莫名其妙"变红。共用 cwd 的测试不是测试,是掷骰子。
|
|
62
|
+
cwd: mkdtempSync(join(tmpdir(), 'wf-capture-')),
|
|
63
|
+
} as unknown as RunContext;
|
|
64
|
+
const warnings: string[] = [];
|
|
65
|
+
for await (const event of runWorkflow(def, {}, ctx)) {
|
|
66
|
+
if ((event as { type?: string }).type === 'warning') {
|
|
67
|
+
warnings.push((event as { message: string }).message);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return warnings;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
describe('bindCapture 取不到字段时报 warning', () => {
|
|
74
|
+
test('写反的 capture({变量名: 结果字段})被抓住,并报出实际可绑字段', async () => {
|
|
75
|
+
const warnings = await collectWarnings({
|
|
76
|
+
name: uniqueName('misbind'),
|
|
77
|
+
steps: [
|
|
78
|
+
// ⚠️ 写反:想把 raw.text 绑给变量 pager,却写成了 pager: text
|
|
79
|
+
{ id: 'probe', llm: '按哪个键翻页', capture: { pager: 'text' } },
|
|
80
|
+
],
|
|
81
|
+
} as never);
|
|
82
|
+
|
|
83
|
+
const hit = warnings.find((w) => w.includes('capture 取不到字段'));
|
|
84
|
+
expect(hit).toBeDefined();
|
|
85
|
+
// 四条信息缺一不可:取不到哪个字段、哪个变量被绑空、是哪一步、实际有什么可绑
|
|
86
|
+
expect(hit).toContain('`pager`');
|
|
87
|
+
expect(hit).toContain('`text`');
|
|
88
|
+
expect(hit).toContain('probe');
|
|
89
|
+
expect(hit).toContain('写反');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('写对的 capture 不产生 warning —— 不能变成噪声', async () => {
|
|
93
|
+
const warnings = await collectWarnings({
|
|
94
|
+
name: uniqueName('ok'),
|
|
95
|
+
steps: [{ id: 'probe', llm: '按哪个键翻页', capture: { text: 'pager' } }],
|
|
96
|
+
} as never);
|
|
97
|
+
expect(warnings.filter((w) => w.includes('capture 取不到字段'))).toHaveLength(0);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================
|
|
3
|
+
* plugins/workflow-runner/test/cli.e2e.test.ts
|
|
4
|
+
* ------------------------------------------------------------
|
|
5
|
+
* 最外层 CLI 端到端:拉子进程跑 `bun src/main.tsx -p "/workflow ..."`,
|
|
6
|
+
* 验证 stdout / stderr / 退出码 / 文件副作用 全链路。
|
|
7
|
+
*
|
|
8
|
+
* 覆盖 3 个用例:
|
|
9
|
+
* 1. golden path:/workflow cli-e2e --input topic=world → exit 0 + 文件落盘
|
|
10
|
+
* 2. /workflows 列出 cli-e2e
|
|
11
|
+
* 3. 缺必填 input → exit 1 + 错误信息含 "topic"
|
|
12
|
+
*
|
|
13
|
+
* fake provider env:workflow 是 tool-only,永不调 API;fake env 仅满足
|
|
14
|
+
* main.tsx 的 provider 配置校验。
|
|
15
|
+
* ============================================================
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { afterEach, beforeEach, describe, expect, it } from 'bun:test';
|
|
19
|
+
import {
|
|
20
|
+
copyFileSync,
|
|
21
|
+
existsSync,
|
|
22
|
+
mkdirSync,
|
|
23
|
+
mkdtempSync,
|
|
24
|
+
readFileSync,
|
|
25
|
+
rmSync,
|
|
26
|
+
} from 'node:fs';
|
|
27
|
+
import { tmpdir } from 'node:os';
|
|
28
|
+
import { join, resolve } from 'node:path';
|
|
29
|
+
|
|
30
|
+
const REPO_ROOT = resolve(import.meta.dir, '..', '..', '..');
|
|
31
|
+
const FIXTURE = join(import.meta.dir, 'fixtures', 'cli-e2e.yaml');
|
|
32
|
+
const FIXTURE_ASK = join(import.meta.dir, 'fixtures', 'cli-ask-e2e.yaml');
|
|
33
|
+
const FIXTURE_GREEDY = join(import.meta.dir, 'fixtures', 'greedy-e2e.yaml');
|
|
34
|
+
|
|
35
|
+
const SPAWN_TIMEOUT = 60_000;
|
|
36
|
+
|
|
37
|
+
interface SpawnResult {
|
|
38
|
+
exitCode: number;
|
|
39
|
+
stdout: string;
|
|
40
|
+
stderr: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function spawnMain(promptArg: string, cwd: string): Promise<SpawnResult> {
|
|
44
|
+
const proc = Bun.spawn(
|
|
45
|
+
['bun', 'src/main.tsx', '-d', cwd, '-p', promptArg],
|
|
46
|
+
{
|
|
47
|
+
cwd: REPO_ROOT,
|
|
48
|
+
env: {
|
|
49
|
+
...process.env,
|
|
50
|
+
MINIMAL_AGENT_BASE_URL: 'http://fake.invalid',
|
|
51
|
+
MINIMAL_AGENT_API_KEY: 'fake-key',
|
|
52
|
+
MINIMAL_AGENT_MODEL: 'fake-model',
|
|
53
|
+
MINIMAL_AGENT_CONTEXT_WINDOW: '128000',
|
|
54
|
+
},
|
|
55
|
+
stdout: 'pipe',
|
|
56
|
+
stderr: 'pipe',
|
|
57
|
+
},
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const [stdout, stderr, exitCode] = await Promise.all([
|
|
61
|
+
new Response(proc.stdout).text(),
|
|
62
|
+
new Response(proc.stderr).text(),
|
|
63
|
+
proc.exited,
|
|
64
|
+
]);
|
|
65
|
+
|
|
66
|
+
return { exitCode, stdout, stderr };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
describe('CLI 端到端 /workflow(拉子进程跑 main.tsx)', () => {
|
|
70
|
+
let tmp: string;
|
|
71
|
+
|
|
72
|
+
beforeEach(() => {
|
|
73
|
+
tmp = mkdtempSync(join(tmpdir(), 'cli-e2e-'));
|
|
74
|
+
mkdirSync(join(tmp, 'workflows'), { recursive: true });
|
|
75
|
+
copyFileSync(FIXTURE, join(tmp, 'workflows', 'cli-e2e.yaml'));
|
|
76
|
+
copyFileSync(FIXTURE_ASK, join(tmp, 'workflows', 'cli-ask-e2e.yaml'));
|
|
77
|
+
copyFileSync(FIXTURE_GREEDY, join(tmp, 'workflows', 'greedy-e2e.yaml'));
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
afterEach(() => {
|
|
81
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it(
|
|
85
|
+
'golden path:跑完 + 文件落盘 + exit 0',
|
|
86
|
+
async () => {
|
|
87
|
+
const r = await spawnMain(
|
|
88
|
+
'/workflow cli-e2e --input topic=world',
|
|
89
|
+
tmp,
|
|
90
|
+
);
|
|
91
|
+
expect(r.exitCode).toBe(0);
|
|
92
|
+
const filePath = join(tmp, 'out', 'world', 'note.txt');
|
|
93
|
+
expect(existsSync(filePath)).toBe(true);
|
|
94
|
+
expect(readFileSync(filePath, 'utf8')).toBe('topic=world ok');
|
|
95
|
+
},
|
|
96
|
+
SPAWN_TIMEOUT,
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
it(
|
|
100
|
+
'/workflows 列出 cli-e2e',
|
|
101
|
+
async () => {
|
|
102
|
+
const r = await spawnMain('/workflows', tmp);
|
|
103
|
+
expect(r.exitCode).toBe(0);
|
|
104
|
+
expect(r.stdout).toContain('cli-e2e');
|
|
105
|
+
},
|
|
106
|
+
SPAWN_TIMEOUT,
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
it(
|
|
110
|
+
'缺必填 input → exit 1 + 错误信息含 "topic"',
|
|
111
|
+
async () => {
|
|
112
|
+
const r = await spawnMain('/workflow cli-e2e', tmp);
|
|
113
|
+
expect(r.exitCode).toBe(1);
|
|
114
|
+
expect(r.stderr).toContain('topic');
|
|
115
|
+
},
|
|
116
|
+
SPAWN_TIMEOUT,
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
// -p 非交互下「含 AskUserQuestion 的工作流」也能跑通:askBridge 自动选推荐项、不挂起。
|
|
120
|
+
// 这是 ppt 工作流 stage0「样式推荐」在 -p / 宿主 spawn 下自动兜底那条路径的最小复现。
|
|
121
|
+
it(
|
|
122
|
+
'含 AskUserQuestion 的工作流在 -p 下自动选推荐项、不挂起、跑完 exit 0',
|
|
123
|
+
async () => {
|
|
124
|
+
const r = await spawnMain('/workflow cli-ask-e2e', tmp);
|
|
125
|
+
expect(r.exitCode).toBe(0);
|
|
126
|
+
// askBridge 非交互兜底:自动选每题首项(推荐项),stderr 注记
|
|
127
|
+
expect(r.stderr).toContain('自动选推荐项');
|
|
128
|
+
// echo 文本经 text 事件 + 末尾 turn_done 正常回到 -p stdout
|
|
129
|
+
expect(r.stdout).toContain('ASK-E2E-DONE');
|
|
130
|
+
},
|
|
131
|
+
SPAWN_TIMEOUT,
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
// 贪婪首参:命令行里 workflow 名之后的整句(含空格分隔段)被 join 进首个 input,
|
|
135
|
+
// 不逐位拆映射、不撞后面的 number/enum 输入。这是 ppt「打一句话自然语言就能跑」
|
|
136
|
+
// 的根因修复——曾因严格 posN↔inputs[N] 把整句拆碎、pos2 撞 number 报「必须是数字」。
|
|
137
|
+
it(
|
|
138
|
+
'greedy 首参把整句位置参数 join 进首个 input(不拆碎、不撞类型)',
|
|
139
|
+
async () => {
|
|
140
|
+
const r = await spawnMain('/workflow greedy-e2e 收集 资料 浅色', tmp);
|
|
141
|
+
expect(r.exitCode).toBe(0);
|
|
142
|
+
// 三段位置参数被空格 join 还原成整句进 brief,echo 原样回显
|
|
143
|
+
expect(r.stdout).toContain('GREEDY-BRIEF=[收集 资料 浅色]');
|
|
144
|
+
},
|
|
145
|
+
SPAWN_TIMEOUT,
|
|
146
|
+
);
|
|
147
|
+
});
|