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,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================
|
|
3
|
+
* stepPipeline —— 「提交一步」的单一实现 + 顺带修正的静默失效
|
|
4
|
+
* ------------------------------------------------------------
|
|
5
|
+
* 重构前这套动作(绑 capture → 写 progress → 落 vars → 记 checkpoint → 发 step_end)
|
|
6
|
+
* 被 `runSteps` 的各内联块各抄一份:recordCheckpoint ×7、appendProgress ×17、
|
|
7
|
+
* step_end ×19。抄多份的直接后果是漂移 —— 其中 `echo` / `set` 干脆**从不调
|
|
8
|
+
* `bindCapture`**:yaml 写了 `capture:` 既不报错也不生效,resume 也回放不出来。
|
|
9
|
+
*
|
|
10
|
+
* 搬进执行器体系后它们走统一流水线,capture 自然生效。这里钉住这个修正,
|
|
11
|
+
* 以及「不许再抄第二份流水线」这条结构约束。
|
|
12
|
+
* ============================================================
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, expect, mock, test } from 'bun:test';
|
|
16
|
+
import { mkdtempSync, readFileSync } from 'node:fs';
|
|
17
|
+
import { tmpdir } from 'node:os';
|
|
18
|
+
import { join } from 'node:path';
|
|
19
|
+
import { runWorkflow } from '../src/runner.js';
|
|
20
|
+
import type { Provider } from '../../../src/types.js';
|
|
21
|
+
import type { RunContext, WorkflowDef, WorkflowEvent } from '../src/types.js';
|
|
22
|
+
|
|
23
|
+
mock.module('../../../src/llm/client.js', () => ({
|
|
24
|
+
chat: async function* () {
|
|
25
|
+
yield { type: 'text_delta', delta: 'ok' };
|
|
26
|
+
yield { type: 'done', stopReason: 'stop' };
|
|
27
|
+
},
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
const provider: Provider = {
|
|
31
|
+
name: 't', baseURL: '', apiKey: '', model: 'm', contextWindow: 128000,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* ⚠️ **工作流名必须每次运行唯一。**
|
|
36
|
+
*
|
|
37
|
+
* 工作流状态目录锚的是 `getWorkingDir()`(进程级),**不是** `RunContext.cwd` ——
|
|
38
|
+
* 见 `runner.ts` 里 `new WorkflowState(getWorkingDir(), def.name)`。
|
|
39
|
+
* 所以给 ctx 传一个 mkdtemp 目录**隔离不了状态**:同名工作流第二次跑会命中
|
|
40
|
+
* 「同名任务此前已完成」而**整条短路**,`workflow_done` 照发、步骤一个不跑 ——
|
|
41
|
+
* 于是断言全部空过,测试在两种实现下都绿,什么都证明不了。
|
|
42
|
+
*
|
|
43
|
+
* 实测踩到:本文件的两条 capture 断言曾在「注入旧行为」时依然全绿,
|
|
44
|
+
* 查下去才发现根本没执行到被测代码。用唯一名根治。
|
|
45
|
+
*/
|
|
46
|
+
function uniqueName(base: string): string {
|
|
47
|
+
return `${base}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function run(def: WorkflowDef): Promise<WorkflowEvent[]> {
|
|
51
|
+
const ctx = {
|
|
52
|
+
provider,
|
|
53
|
+
history: [{ role: 'system', content: 'sys' }],
|
|
54
|
+
cwd: mkdtempSync(join(tmpdir(), 'wf-pipeline-')),
|
|
55
|
+
} as unknown as RunContext;
|
|
56
|
+
const out: WorkflowEvent[] = [];
|
|
57
|
+
for await (const e of runWorkflow(def, {}, ctx)) out.push(e as WorkflowEvent);
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
describe('★ 修正:echo / set 的 capture 从静默失效变为生效', () => {
|
|
62
|
+
test('echo 带 capture → 变量真的被绑上,下游 assert 能用', async () => {
|
|
63
|
+
const events = await run({
|
|
64
|
+
name: uniqueName('echo-capture'),
|
|
65
|
+
steps: [
|
|
66
|
+
{ id: 'say', type: 'echo', message: 'HELLO', capture: { text: 'said' } },
|
|
67
|
+
{ id: 'check', type: 'assert', condition: "said == 'HELLO'" },
|
|
68
|
+
],
|
|
69
|
+
} as never);
|
|
70
|
+
// 重构前:echo 从不调 bindCapture → said 为 undefined → assert 判假 → halted
|
|
71
|
+
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('set 带 capture → 别名变量也被绑上', async () => {
|
|
75
|
+
const events = await run({
|
|
76
|
+
name: uniqueName('set-capture'),
|
|
77
|
+
steps: [
|
|
78
|
+
{ id: 'init', type: 'set', set: { phase: 'PLAN' }, capture: { phase: 'alias' } },
|
|
79
|
+
{ id: 'check', type: 'assert', condition: "alias == 'PLAN'" },
|
|
80
|
+
],
|
|
81
|
+
} as never);
|
|
82
|
+
expect(events.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('★ 结构约束:流水线只许有一份实现', () => {
|
|
87
|
+
const runnerSrc = readFileSync(
|
|
88
|
+
join(import.meta.dir, '..', 'src', 'runner.ts'),
|
|
89
|
+
'utf8',
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
test('runner.ts 不再自己记 checkpoint / 发 step_end(都走 stepPipeline)', () => {
|
|
93
|
+
// 重构前:recordCheckpoint ×7、appendProgress ×17、step_end ×19
|
|
94
|
+
expect((runnerSrc.match(/state\.recordCheckpoint\(/g) ?? []).length).toBe(0);
|
|
95
|
+
expect((runnerSrc.match(/type: 'workflow_step_end'/g) ?? []).length).toBeLessThanOrEqual(2);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('runSteps 保持精简(控制流已搬进 controlFlow/)', () => {
|
|
99
|
+
const lines = runnerSrc.split('\n');
|
|
100
|
+
const s = lines.findIndex((l) => l.startsWith('async function* runSteps('));
|
|
101
|
+
const e = lines.findIndex((l, i) => i > s && l === '}');
|
|
102
|
+
expect(e - s + 1).toBeLessThanOrEqual(200); // 重构前 780
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('★ controlFlow/ 不反向 import runner —— 靠注入的 runBlock', () => {
|
|
106
|
+
for (const f of ['loop', 'branch', 'pause', 'signal', 'types']) {
|
|
107
|
+
const src = readFileSync(
|
|
108
|
+
join(import.meta.dir, '..', 'src', 'controlFlow', `${f}.ts`),
|
|
109
|
+
'utf8',
|
|
110
|
+
);
|
|
111
|
+
expect(src).not.toContain("from '../runner.js'");
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================
|
|
3
|
+
* plugins/workflow-runner/test/taskArbitration.test.ts
|
|
4
|
+
* ------------------------------------------------------------
|
|
5
|
+
* 任务身份语义仲裁层(hash 不等 + 旧任务未完成时的二审)契约:
|
|
6
|
+
*
|
|
7
|
+
* hash 仍是同任务的权威信号(相等 → resume/completed)。hash 不等且旧任务
|
|
8
|
+
* 未完成时不再一票否决 new-task,仲裁链逐级降级:
|
|
9
|
+
* a. 延续短语快路径(继续/接着/continue…)→ resume,不花 LLM
|
|
10
|
+
* b. LLM 单轮仲裁(JSON verdict)→ resume / new 决断
|
|
11
|
+
* c. unsure / LLM 不可用 → AskUserQuestion(非交互自动选推荐项=全新开始)
|
|
12
|
+
* d. 提问也失败 → 兜底 new-task(= 旧红线行为)
|
|
13
|
+
*
|
|
14
|
+
* 仲裁判定 resume 时:旧任务状态/产物保留、从断点续跑,goalAnchor 锚旧目标
|
|
15
|
+
* + 新输入作补充指令(不能让每步 LLM 把「继续」当成目标)。
|
|
16
|
+
*
|
|
17
|
+
* 约定:DI 注入(chat / executeTool stub),禁 mock.module(client/loop/plugin-sdk)。
|
|
18
|
+
* ============================================================
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { afterEach, beforeEach, describe, expect, it, mock } from 'bun:test';
|
|
22
|
+
import { existsSync, mkdtempSync, rmSync, writeFileSync } 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 {
|
|
29
|
+
buildTaskArbitrator,
|
|
30
|
+
isContinuationPhrase,
|
|
31
|
+
type TaskArbitrationContext,
|
|
32
|
+
} from '../src/taskIdentity.js';
|
|
33
|
+
import { WorkflowState } from '../src/workflowState.js';
|
|
34
|
+
import { runWorkflow } from '../src/runner.js';
|
|
35
|
+
import type { RunContext, StepDef, WorkflowDef, WorkflowEvent } from '../src/types.js';
|
|
36
|
+
|
|
37
|
+
type WfOrLoop = WorkflowEvent | LoopEvent;
|
|
38
|
+
|
|
39
|
+
const fakeProvider: Provider = {
|
|
40
|
+
name: 'test',
|
|
41
|
+
baseURL: '',
|
|
42
|
+
apiKey: '',
|
|
43
|
+
model: 'm',
|
|
44
|
+
contextWindow: 128000,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
async function collect(
|
|
48
|
+
gen: AsyncGenerator<WfOrLoop, void, void>,
|
|
49
|
+
): Promise<WfOrLoop[]> {
|
|
50
|
+
const out: WfOrLoop[] = [];
|
|
51
|
+
for await (const ev of gen) out.push(ev);
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const ACTX: TaskArbitrationContext = {
|
|
56
|
+
workflowName: 'plan',
|
|
57
|
+
prevGoal: '写一份产品架构说明 PPT',
|
|
58
|
+
newGoal: '继续',
|
|
59
|
+
completedStepIds: ['gathering', 'research'],
|
|
60
|
+
totalSteps: 5,
|
|
61
|
+
artifacts: ['PLAN.md'],
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// ---------------- 1. 单元:短语快路径 ----------------
|
|
65
|
+
|
|
66
|
+
describe('taskIdentity::isContinuationPhrase(延续短语快路径)', () => {
|
|
67
|
+
it('中英文延续短语命中', () => {
|
|
68
|
+
for (const g of ['继续', '继续吧', '接着做', '继续执行', 'continue', 'resume', 'go on', '继续!']) {
|
|
69
|
+
expect(isContinuationPhrase(g)).toBe(true);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('实质性新目标不命中', () => {
|
|
74
|
+
for (const g of ['写一份产品架构说明 PPT', '帮我重构 runner.ts', '继续深入研究量子计算的产业落地并写一份长篇报告']) {
|
|
75
|
+
expect(isContinuationPhrase(g)).toBe(false);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// ---------------- 2. 单元:复合仲裁器逐级降级 ----------------
|
|
81
|
+
|
|
82
|
+
describe('taskIdentity::buildTaskArbitrator(仲裁链逐级降级)', () => {
|
|
83
|
+
it('a. 延续短语 → resume,不调 LLM 也不提问', async () => {
|
|
84
|
+
let chatCalled = 0;
|
|
85
|
+
let askCalled = 0;
|
|
86
|
+
const notes: string[] = [];
|
|
87
|
+
const arb = buildTaskArbitrator({
|
|
88
|
+
provider: fakeProvider,
|
|
89
|
+
chat: async function* () {
|
|
90
|
+
chatCalled++;
|
|
91
|
+
yield { type: 'done', stopReason: 'stop' };
|
|
92
|
+
},
|
|
93
|
+
executeTool: async () => {
|
|
94
|
+
askCalled++;
|
|
95
|
+
return { ok: true, content: '' };
|
|
96
|
+
},
|
|
97
|
+
notes,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
expect(await arb(ACTX)).toBe('resume');
|
|
101
|
+
expect(chatCalled).toBe(0);
|
|
102
|
+
expect(askCalled).toBe(0);
|
|
103
|
+
expect(notes.some((n) => n.includes('延续短语'))).toBe(true);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('b. LLM 判 resume → resume(决断,不提问)', async () => {
|
|
107
|
+
let askCalled = 0;
|
|
108
|
+
const arb = buildTaskArbitrator({
|
|
109
|
+
provider: fakeProvider,
|
|
110
|
+
chat: async function* () {
|
|
111
|
+
yield { type: 'text_delta', delta: '{"verdict":"resume","reason":"是延续"}' };
|
|
112
|
+
yield { type: 'done', stopReason: 'stop' };
|
|
113
|
+
},
|
|
114
|
+
executeTool: async () => {
|
|
115
|
+
askCalled++;
|
|
116
|
+
return { ok: true, content: '' };
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
expect(await arb({ ...ACTX, newGoal: '把刚才那个 PPT 做完' })).toBe('resume');
|
|
121
|
+
expect(askCalled).toBe(0);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('b. LLM 判 new → new(决断)', async () => {
|
|
125
|
+
const arb = buildTaskArbitrator({
|
|
126
|
+
provider: fakeProvider,
|
|
127
|
+
chat: async function* () {
|
|
128
|
+
yield { type: 'text_delta', delta: '{"verdict":"new","reason":"无关新需求"}' };
|
|
129
|
+
yield { type: 'done', stopReason: 'stop' };
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
expect(await arb({ ...ACTX, newGoal: '帮我修一个登录 bug' })).toBe('new');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('c. LLM unsure → AskUserQuestion,按用户选择走(选"继续上次任务"→ resume)', async () => {
|
|
137
|
+
const arb = buildTaskArbitrator({
|
|
138
|
+
provider: fakeProvider,
|
|
139
|
+
chat: async function* () {
|
|
140
|
+
yield { type: 'text_delta', delta: '{"verdict":"unsure","reason":"说不准"}' };
|
|
141
|
+
yield { type: 'done', stopReason: 'stop' };
|
|
142
|
+
},
|
|
143
|
+
executeTool: async (name: string) => {
|
|
144
|
+
expect(name).toBe('AskUserQuestion');
|
|
145
|
+
return { ok: true, content: '用户已回答 AskUserQuestion:\nA1: 继续上次任务' };
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
expect(await arb({ ...ACTX, newGoal: '模糊输入' })).toBe('resume');
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('d. LLM 抛错 + 提问也失败 → 兜底 new(= 旧红线行为)', async () => {
|
|
153
|
+
const notes: string[] = [];
|
|
154
|
+
const arb = buildTaskArbitrator({
|
|
155
|
+
provider: fakeProvider,
|
|
156
|
+
chat: async function* () {
|
|
157
|
+
throw new Error('LLM down');
|
|
158
|
+
// biome-ignore lint/correctness/noUnreachable: stub
|
|
159
|
+
yield { type: 'done', stopReason: 'stop' };
|
|
160
|
+
},
|
|
161
|
+
executeTool: async () => ({ ok: false, error: '提问被取消' }),
|
|
162
|
+
notes,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
expect(await arb({ ...ACTX, newGoal: '模糊输入' })).toBe('new');
|
|
166
|
+
expect(notes.some((n) => n.includes('全新任务'))).toBe(true);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// ---------------- 3. 状态层:init 接仲裁结果 ----------------
|
|
171
|
+
|
|
172
|
+
const STEPS: StepDef[] = [
|
|
173
|
+
{ id: 's1', type: 'assert', condition: 'true' },
|
|
174
|
+
{ id: 's2', type: 'assert', condition: 'true' },
|
|
175
|
+
];
|
|
176
|
+
|
|
177
|
+
describe('workflowState::init × 仲裁(resume 保留现场 / new 清理重开)', () => {
|
|
178
|
+
let tmp: string;
|
|
179
|
+
|
|
180
|
+
beforeEach(() => {
|
|
181
|
+
tmp = mkdtempSync(join(tmpdir(), 'wf-arb-'));
|
|
182
|
+
});
|
|
183
|
+
afterEach(() => {
|
|
184
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('仲裁判 resume → 保留旧状态与产物、回放 checkpoint、带 prevGoal/supplementaryGoal', async () => {
|
|
188
|
+
// 旧任务:fresh + 完成一步 + 留产物(不 markDone = 未完成)
|
|
189
|
+
const s1 = new WorkflowState(tmp, 'plan');
|
|
190
|
+
await s1.init('plan', { goal: '写产品架构 PPT' }, STEPS, 1, ['PLAN.md']);
|
|
191
|
+
await s1.recordCheckpoint('s1', 'ok', { out: 'v1' }, {});
|
|
192
|
+
writeFileSync(join(tmp, 'PLAN.md'), '# 半成品');
|
|
193
|
+
|
|
194
|
+
// 新输入「继续」(hash 必然不等)+ 仲裁器判 resume
|
|
195
|
+
const s2 = new WorkflowState(tmp, 'plan');
|
|
196
|
+
const r = await s2.init('plan', { goal: '继续' }, STEPS, 1, ['PLAN.md'], async () => 'resume');
|
|
197
|
+
|
|
198
|
+
expect(r.mode).toBe('resume');
|
|
199
|
+
expect(r.completedStepIds).toEqual(['s1']);
|
|
200
|
+
expect(r.capturedVars?.s1).toEqual({ out: 'v1' });
|
|
201
|
+
expect(r.prevGoal).toBe('写产品架构 PPT');
|
|
202
|
+
expect(r.supplementaryGoal).toBe('继续');
|
|
203
|
+
// 现场未被清理
|
|
204
|
+
expect(existsSync(join(tmp, 'PLAN.md'))).toBe(true);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('仲裁判 new → 走 new-task 清理重开', async () => {
|
|
208
|
+
const s1 = new WorkflowState(tmp, 'plan');
|
|
209
|
+
await s1.init('plan', { goal: '写产品架构 PPT' }, STEPS, 1, ['PLAN.md']);
|
|
210
|
+
writeFileSync(join(tmp, 'PLAN.md'), '# 旧产物');
|
|
211
|
+
|
|
212
|
+
const s2 = new WorkflowState(tmp, 'plan');
|
|
213
|
+
const r = await s2.init('plan', { goal: '修登录 bug' }, STEPS, 1, ['PLAN.md'], async () => 'new');
|
|
214
|
+
|
|
215
|
+
expect(r.mode).toBe('new-task');
|
|
216
|
+
expect(existsSync(join(tmp, 'PLAN.md'))).toBe(false);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('仲裁器抛错 → 兜底 new-task(不让仲裁 halt 工作流)', async () => {
|
|
220
|
+
const s1 = new WorkflowState(tmp, 'plan');
|
|
221
|
+
await s1.init('plan', { goal: '写产品架构 PPT' }, STEPS, 1, []);
|
|
222
|
+
|
|
223
|
+
const s2 = new WorkflowState(tmp, 'plan');
|
|
224
|
+
const r = await s2.init('plan', { goal: '继续' }, STEPS, 1, [], async () => {
|
|
225
|
+
throw new Error('仲裁崩了');
|
|
226
|
+
});
|
|
227
|
+
expect(r.mode).toBe('new-task');
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it('旧任务已完成(status=done)→ 不仲裁,直接 new-task', async () => {
|
|
231
|
+
const s1 = new WorkflowState(tmp, 'plan');
|
|
232
|
+
await s1.init('plan', { goal: '写产品架构 PPT' }, STEPS, 1, []);
|
|
233
|
+
await s1.markDone(); // 活动目录 done(未归档的边角情形)
|
|
234
|
+
|
|
235
|
+
let arbCalled = 0;
|
|
236
|
+
const s2 = new WorkflowState(tmp, 'plan');
|
|
237
|
+
const r = await s2.init('plan', { goal: '继续' }, STEPS, 1, [], async () => {
|
|
238
|
+
arbCalled++;
|
|
239
|
+
return 'resume';
|
|
240
|
+
});
|
|
241
|
+
expect(r.mode).toBe('new-task');
|
|
242
|
+
expect(arbCalled).toBe(0);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it('不同名 workflow 状态按名隔离(E6)→ B 判 fresh、不仲裁、不碰 A 的现场', async () => {
|
|
246
|
+
// A(other-wf)未完成现场
|
|
247
|
+
const sA = new WorkflowState(tmp, 'other-wf');
|
|
248
|
+
await sA.init('other-wf', { goal: '别的事' }, STEPS, 1, []);
|
|
249
|
+
|
|
250
|
+
// 跑 B(plan):A 的状态对 B 不可见 → fresh(不会误判 resume/new-task,也不仲裁)
|
|
251
|
+
let arbCalled = 0;
|
|
252
|
+
const sB = new WorkflowState(tmp, 'plan');
|
|
253
|
+
const r = await sB.init('plan', { goal: '继续' }, STEPS, 1, [], async () => {
|
|
254
|
+
arbCalled++;
|
|
255
|
+
return 'resume';
|
|
256
|
+
});
|
|
257
|
+
expect(r.mode).toBe('fresh');
|
|
258
|
+
expect(arbCalled).toBe(0);
|
|
259
|
+
// A 的现场完好(曾经会被 B 的 new-task 清掉——E6 事故)
|
|
260
|
+
expect(existsSync(join(tmp, '.minimal-agent-workflow', 'other-wf', 'current.json'))).toBe(true);
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// ---------------- 4. 端到端:runWorkflow「继续」续跑 + goalAnchor 锚旧目标 ----------------
|
|
265
|
+
|
|
266
|
+
describe('runWorkflow × 仲裁延续(端到端)', () => {
|
|
267
|
+
let tmp: string;
|
|
268
|
+
let ctx: RunContext;
|
|
269
|
+
|
|
270
|
+
beforeEach(() => {
|
|
271
|
+
tmp = mkdtempSync(join(tmpdir(), 'wf-arb-e2e-'));
|
|
272
|
+
process.env.MINIMAL_AGENT_CWD = tmp;
|
|
273
|
+
_resetWorkingDir();
|
|
274
|
+
mock.module('../../../src/bootstrap/workingDir.js', () => ({
|
|
275
|
+
getWorkingDir: () => tmp,
|
|
276
|
+
initWorkingDir: () => tmp,
|
|
277
|
+
_resetWorkingDir: () => {},
|
|
278
|
+
}));
|
|
279
|
+
ctx = { provider: fakeProvider, history: [], cwd: tmp, tools: [] };
|
|
280
|
+
});
|
|
281
|
+
afterEach(() => {
|
|
282
|
+
delete process.env.MINIMAL_AGENT_CWD;
|
|
283
|
+
_resetWorkingDir();
|
|
284
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it('输入「继续」→ 短语快路径 resume;goalAnchor 锚旧目标而非「继续」', async () => {
|
|
288
|
+
const def: WorkflowDef = {
|
|
289
|
+
name: 'cont-wf',
|
|
290
|
+
description: 'd',
|
|
291
|
+
inputs: [{ name: 'goal', type: 'string', required: true }],
|
|
292
|
+
steps: [
|
|
293
|
+
// prompt 正文内插 ${inputs.goal}(模拟 plan.yaml 的业务上下文写法):
|
|
294
|
+
// 仲裁 resume 时必须渲染旧任务真实目标,不能是「继续」
|
|
295
|
+
{ id: 'g1', llm: '目标:${inputs.goal},做第一步', capture: { text: 'a' } },
|
|
296
|
+
{ id: 'g2', llm: '目标:${inputs.goal},做第二步', capture: { text: 'b' } },
|
|
297
|
+
],
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
// 第一次:真实目标,g1 成功后 g2 失败(中断现场)
|
|
301
|
+
let calls = 0;
|
|
302
|
+
ctx.chat = async function* () {
|
|
303
|
+
calls++;
|
|
304
|
+
if (calls === 2) throw new Error('boom'); // g2 失败 → halt,保留现场
|
|
305
|
+
yield { type: 'text_delta', delta: `out-${calls}` };
|
|
306
|
+
yield { type: 'done', stopReason: 'stop' };
|
|
307
|
+
};
|
|
308
|
+
const ev1 = await collect(runWorkflow(def, { goal: '写产品架构说明文档' }, ctx));
|
|
309
|
+
expect(ev1.some((e) => e.type === 'workflow_done')).toBe(false);
|
|
310
|
+
|
|
311
|
+
// 第二次:输入「继续」→ 仲裁快路径 resume(不该花 LLM 做仲裁)。
|
|
312
|
+
// 记录每次 chat 收到的 user prompt,验证 goalAnchor 锚的是旧目标。
|
|
313
|
+
const prompts: string[] = [];
|
|
314
|
+
ctx.history = [];
|
|
315
|
+
ctx.chat = async function* (args) {
|
|
316
|
+
const user = [...args.messages].reverse().find((m) => m.role === 'user');
|
|
317
|
+
prompts.push(typeof user?.content === 'string' ? user.content : '');
|
|
318
|
+
yield { type: 'text_delta', delta: 'resumed-out' };
|
|
319
|
+
yield { type: 'done', stopReason: 'stop' };
|
|
320
|
+
};
|
|
321
|
+
const ev2 = await collect(runWorkflow(def, { goal: '继续' }, ctx));
|
|
322
|
+
|
|
323
|
+
expect(ev2.some((e) => e.type === 'workflow_done')).toBe(true);
|
|
324
|
+
// 仲裁可见化:延续短语 warning
|
|
325
|
+
expect(
|
|
326
|
+
ev2.some((e) => e.type === 'warning' && e.message.includes('延续短语')),
|
|
327
|
+
).toBe(true);
|
|
328
|
+
// goalAnchor 锚旧目标 + 补充指令,而不是把「继续」当目标
|
|
329
|
+
expect(prompts.length).toBeGreaterThan(0);
|
|
330
|
+
for (const p of prompts) {
|
|
331
|
+
expect(p).toContain('写产品架构说明文档');
|
|
332
|
+
expect(p).not.toContain('用户原始目标:继续');
|
|
333
|
+
// prompt 正文的 ${inputs.goal} 内插也必须是旧目标(VarStack inputs 已替换)
|
|
334
|
+
expect(p).toContain('目标:写产品架构说明文档');
|
|
335
|
+
expect(p).not.toContain('目标:继续');
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
});
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================
|
|
3
|
+
* test/taskIdentity.test.ts —— 任务身份判定单元测试
|
|
4
|
+
* ------------------------------------------------------------
|
|
5
|
+
* 覆盖 taskIdentity.ts 的所有核心功能:
|
|
6
|
+
* - computeTaskId() hash 计算
|
|
7
|
+
* - 时间窗口判定(30分钟内视为同任务)
|
|
8
|
+
* - 任务身份匹配逻辑(hash_match / time_window / expired / different_workflow)
|
|
9
|
+
* - normalizeGoal() 归一化规则
|
|
10
|
+
* - extractGoal() 提取策略
|
|
11
|
+
*
|
|
12
|
+
* 设计原则:
|
|
13
|
+
* - 不依赖文件系统(computeTaskId 在无 workingDir 时返回 no_previous)
|
|
14
|
+
* - 需要文件系统时用 tmpdir + 手写 current.json
|
|
15
|
+
* - 纯函数逻辑用大量边界用例覆盖
|
|
16
|
+
* ============================================================
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { afterEach, beforeEach, describe, expect, it } from 'bun:test';
|
|
20
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
21
|
+
import { tmpdir } from 'node:os';
|
|
22
|
+
import { join } from 'node:path';
|
|
23
|
+
|
|
24
|
+
import { computeTaskId } from '../src/taskIdentity.js';
|
|
25
|
+
|
|
26
|
+
describe('taskIdentity::normalizeGoal (隐式测试 via computeTaskId)', () => {
|
|
27
|
+
it('相同内容产生相同 hash(确定性)', () => {
|
|
28
|
+
const r1 = computeTaskId('test-wf', { goal: 'hello world' });
|
|
29
|
+
const r2 = computeTaskId('test-wf', { goal: 'hello world' });
|
|
30
|
+
expect(r1.hash).toBe(r2.hash);
|
|
31
|
+
expect(r1.hash.length).toBe(16);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('不同内容产生不同 hash(碰撞敏感度)', () => {
|
|
35
|
+
const r1 = computeTaskId('test-wf', { goal: '目标A' });
|
|
36
|
+
const r2 = computeTaskId('test-wf', { goal: '目标B' });
|
|
37
|
+
expect(r1.hash).not.toBe(r2.hash);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('大小写不敏感(归一化转小写)', () => {
|
|
41
|
+
const r1 = computeTaskId('test-wf', { goal: 'Hello World' });
|
|
42
|
+
const r2 = computeTaskId('test-wf', { goal: 'hello world' });
|
|
43
|
+
expect(r1.hash).toBe(r2.hash);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('标点符号被去除', () => {
|
|
47
|
+
const r1 = computeTaskId('test-wf', { goal: 'Hello, World!' });
|
|
48
|
+
const r2 = computeTaskId('test-wf', { goal: 'hello world' });
|
|
49
|
+
expect(r1.hash).toBe(r2.hash);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('多余空格被压缩', () => {
|
|
53
|
+
const r1 = computeTaskId('test-wf', { goal: 'hello world' });
|
|
54
|
+
const r2 = computeTaskId('test-wf', { goal: 'hello world' });
|
|
55
|
+
expect(r1.hash).toBe(r2.hash);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('中文保留正常', () => {
|
|
59
|
+
const r = computeTaskId('test-wf', { goal: '实现用户认证模块' });
|
|
60
|
+
expect(r.hash.length).toBe(16);
|
|
61
|
+
// 中文不应被去除
|
|
62
|
+
expect(r.hash).toMatch(/^[0-9a-f]{16}$/);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('超长输入被截断到 200 字符', () => {
|
|
66
|
+
const longGoal = 'a'.repeat(300);
|
|
67
|
+
const r1 = computeTaskId('test-wf', { goal: longGoal });
|
|
68
|
+
const r2 = computeTaskId('test-wf', { goal: 'a'.repeat(200) });
|
|
69
|
+
expect(r1.hash).toBe(r2.hash);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('首尾空格被 trim', () => {
|
|
73
|
+
const r1 = computeTaskId('test-wf', { goal: ' hello world ' });
|
|
74
|
+
const r2 = computeTaskId('test-wf', { goal: 'hello world' });
|
|
75
|
+
expect(r1.hash).toBe(r2.hash);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('taskIdentity::extractGoal 策略', () => {
|
|
80
|
+
it('优先级1:直接使用 inputs.goal', () => {
|
|
81
|
+
const r1 = computeTaskId('wf', { goal: '我的目标', other: '忽略这个' });
|
|
82
|
+
const r2 = computeTaskId('wf', { goal: '我的目标', other: '不同的值' });
|
|
83
|
+
expect(r1.hash).toBe(r2.hash); // 只看 goal
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('优先级2:无 goal 时取第一个 length > 2 的 string 值', () => {
|
|
87
|
+
const r1 = computeTaskId('wf', { short: 'ab', description: '这是一个较长的描述' });
|
|
88
|
+
// 应该取 description(length > 2),而不是 short
|
|
89
|
+
const r2 = computeTaskId('wf', { description: '这是一个较长的描述' });
|
|
90
|
+
expect(r1.hash).toBe(r2.hash);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('优先级3:所有 string 都太短时 JSON 序列化整个 inputs', () => {
|
|
94
|
+
const r1 = computeTaskId('wf', { a: 'x', b: 'y' });
|
|
95
|
+
const r2 = computeTaskId('wf', { a: 'x', b: 'y' });
|
|
96
|
+
expect(r1.hash).toBe(r2.hash); // 确定性
|
|
97
|
+
expect(r1.hash.length).toBe(16);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('空 inputs 也能处理', () => {
|
|
101
|
+
const r = computeTaskId('wf', {});
|
|
102
|
+
expect(r.hash.length).toBe(16);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('非 string 值被跳过(number/boolean/null)', () => {
|
|
106
|
+
const r1 = computeTaskId('wf', { count: 42, flag: true });
|
|
107
|
+
const r2 = computeTaskId('wf', {});
|
|
108
|
+
// 没有可用的 string → 都走 JSON.stringify
|
|
109
|
+
// 但序列化结果不同,所以 hash 不同是正常的
|
|
110
|
+
expect(r1.hash.length).toBe(16);
|
|
111
|
+
expect(r2.hash.length).toBe(16);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe('taskIdentity::无 workingDir 基础行为', () => {
|
|
116
|
+
it('无 workingDir → isSameTask=false, reason=no_previous', () => {
|
|
117
|
+
const r = computeTaskId('test-wf', { goal: 'hello' });
|
|
118
|
+
expect(r.isSameTask).toBe(false);
|
|
119
|
+
expect(r.reason).toBe('no_previous');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('不同 workflow 名产生不同 hash', () => {
|
|
123
|
+
const r1 = computeTaskId('wf-a', { goal: 'same goal' });
|
|
124
|
+
const r2 = computeTaskId('wf-b', { goal: 'same goal' });
|
|
125
|
+
expect(r1.hash).not.toBe(r2.hash); // workflow 名参与 hash
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('taskIdentity::文件系统交互(时间窗口 + hash 匹配)', () => {
|
|
130
|
+
let tmp: string;
|
|
131
|
+
|
|
132
|
+
beforeEach(() => {
|
|
133
|
+
tmp = mkdtempSync(join(tmpdir(), 'task-id-'));
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
afterEach(() => {
|
|
137
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
function writeCurrentState(data: {
|
|
141
|
+
taskId?: string;
|
|
142
|
+
name?: string;
|
|
143
|
+
startedAt?: string;
|
|
144
|
+
status?: string;
|
|
145
|
+
}): void {
|
|
146
|
+
// E6 后状态目录按 workflow 名隔离:computeTaskId('test-wf', …) 读 test-wf/ 子目录
|
|
147
|
+
const stateDir = join(tmp, '.minimal-agent-workflow', 'test-wf');
|
|
148
|
+
mkdirSync(stateDir, { recursive: true });
|
|
149
|
+
writeFileSync(
|
|
150
|
+
join(stateDir, 'current.json'),
|
|
151
|
+
JSON.stringify(data, null, 2),
|
|
152
|
+
'utf8',
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
it('无 current.json → no_previous', () => {
|
|
157
|
+
const r = computeTaskId('test-wf', { goal: 'hello' }, tmp);
|
|
158
|
+
expect(r.isSameTask).toBe(false);
|
|
159
|
+
expect(r.reason).toBe('no_previous');
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('不同 workflow 名 → different_workflow', () => {
|
|
163
|
+
writeCurrentState({
|
|
164
|
+
name: 'other-wf',
|
|
165
|
+
taskId: 'abc123',
|
|
166
|
+
startedAt: new Date().toISOString(),
|
|
167
|
+
});
|
|
168
|
+
const r = computeTaskId('test-wf', { goal: 'hello' }, tmp);
|
|
169
|
+
expect(r.isSameTask).toBe(false);
|
|
170
|
+
expect(r.reason).toBe('different_workflow');
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('时间窗口内但 goal 不同 → 仍判不同任务(hash 权威,recency 不覆盖)', () => {
|
|
174
|
+
// 刚刚启动的任务,但这次换了完全不同的 goal
|
|
175
|
+
writeCurrentState({
|
|
176
|
+
name: 'test-wf',
|
|
177
|
+
taskId: 'old-hash',
|
|
178
|
+
startedAt: new Date().toISOString(),
|
|
179
|
+
});
|
|
180
|
+
const r = computeTaskId('test-wf', { goal: '完全不同的新目标' }, tmp);
|
|
181
|
+
// 30 分钟内换不同 goal 必须当成全新任务(需求 3.2「不相关新任务自动清理重开」),
|
|
182
|
+
// 而非旧版「时间窗口覆盖 hash」错误 resume 旧任务把旧变量混进新目标。
|
|
183
|
+
expect(r.isSameTask).toBe(false);
|
|
184
|
+
expect(r.reason).toBe('hash_diff');
|
|
185
|
+
expect(r.hash).not.toBe('old-hash');
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('时间窗口过期 + hash 匹配 → hash_match', () => {
|
|
189
|
+
// 31 分钟前启动的任务(超出 30 分钟窗口)
|
|
190
|
+
const pastDate = new Date(Date.now() - 31 * 60 * 1000);
|
|
191
|
+
const expectedHash = computeTaskId('test-wf', { goal: 'same goal' }).hash;
|
|
192
|
+
|
|
193
|
+
writeCurrentState({
|
|
194
|
+
name: 'test-wf',
|
|
195
|
+
taskId: expectedHash,
|
|
196
|
+
startedAt: pastDate.toISOString(),
|
|
197
|
+
});
|
|
198
|
+
const r = computeTaskId('test-wf', { goal: 'same goal' }, tmp);
|
|
199
|
+
expect(r.isSameTask).toBe(true);
|
|
200
|
+
expect(r.reason).toBe('hash_match');
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('hash 不匹配 → 不同任务(hash_diff,与时间无关)', () => {
|
|
204
|
+
const pastDate = new Date(Date.now() - 31 * 60 * 1000);
|
|
205
|
+
writeCurrentState({
|
|
206
|
+
name: 'test-wf',
|
|
207
|
+
taskId: 'some-old-hash',
|
|
208
|
+
startedAt: pastDate.toISOString(),
|
|
209
|
+
});
|
|
210
|
+
const r = computeTaskId('test-wf', { goal: 'completely new target' }, tmp);
|
|
211
|
+
expect(r.isSameTask).toBe(false);
|
|
212
|
+
expect(r.reason).toBe('hash_diff');
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('损坏的 current.json → 容错返回 no_previous', () => {
|
|
216
|
+
const stateDir = join(tmp, '.minimal-agent-workflow', 'test-wf');
|
|
217
|
+
mkdirSync(stateDir, { recursive: true });
|
|
218
|
+
writeFileSync(join(stateDir, 'current.json'), '{invalid json', 'utf8');
|
|
219
|
+
|
|
220
|
+
const r = computeTaskId('test-wf', { goal: 'hello' }, tmp);
|
|
221
|
+
expect(r.isSameTask).toBe(false);
|
|
222
|
+
expect(r.reason).toBe('no_previous');
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('current.json 缺少 startedAt 字段 → 降级为 hash 比较', () => {
|
|
226
|
+
const expectedHash = computeTaskId('test-wf', { goal: 'target' }).hash;
|
|
227
|
+
writeCurrentState({
|
|
228
|
+
name: 'test-wf',
|
|
229
|
+
taskId: expectedHash,
|
|
230
|
+
// 没有 startedAt
|
|
231
|
+
});
|
|
232
|
+
const r = computeTaskId('test-wf', { goal: 'target' }, tmp);
|
|
233
|
+
// 无 startedAt 时时间窗口检查不通过,走 hash 匹配
|
|
234
|
+
expect(r.isSameTask).toBe(true);
|
|
235
|
+
expect(r.reason).toBe('hash_match');
|
|
236
|
+
});
|
|
237
|
+
});
|