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,453 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================
|
|
3
|
+
* diagnostics.ts —— 给宿主/插件的 Computer Use 只读门面
|
|
4
|
+
* ------------------------------------------------------------
|
|
5
|
+
* 桌面操作的**执行**在 `computeruse.ts`(可信内核工具),**知识与命令面**在
|
|
6
|
+
* `plugins/computer_use/`。插件需要的只有三类事:看一眼状态、读诊断、把一次
|
|
7
|
+
* 观测沉淀成说明书草稿。本模块就是这三类事的全部出口。
|
|
8
|
+
*
|
|
9
|
+
* ★ 为什么不直接把 `computerUseService` 交给插件(此前就是这么做的):
|
|
10
|
+
* 那个对象的 `request()` 能派发 `click` / `type` / `file_drop`。一个「只做
|
|
11
|
+
* 诊断与知识管理」的插件不该拿得到操作鼠标键盘的能力,而 `plugin-sdk.ts`
|
|
12
|
+
* 当时的注释恰恰宣称「只开放这几件事」——注释与代码不一致时改代码。
|
|
13
|
+
*
|
|
14
|
+
* ★ 为什么写盘(`writeManualDraft`)也在这里而不是插件里:它需要用户确认 +
|
|
15
|
+
* 原子写。若留给插件,插件就得直接 import `askBridge` 与文件 API ——
|
|
16
|
+
* 刚收窄的 SDK 会立刻从别的路径重新变宽。**有副作用的那一步由内核持有**,
|
|
17
|
+
* 插件只负责编排与呈现。
|
|
18
|
+
* ============================================================
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { randomUUID } from 'node:crypto';
|
|
22
|
+
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
23
|
+
import { existsSync } from 'node:fs';
|
|
24
|
+
import { dirname, join } from 'node:path';
|
|
25
|
+
|
|
26
|
+
import { getWorkingDir } from '../../bootstrap/workingDir.js';
|
|
27
|
+
import { hasAskHandler, requestUserChoice } from '../../askBridge.js';
|
|
28
|
+
import { anonymousOwnerId, computerUseService, ComputerUseService, computerUseStateDir, findComputerUseHelper } from './computerUseService.js';
|
|
29
|
+
import type { ComputerState, ComputerUseResponse, ComputerUseRunContext } from './protocol.js';
|
|
30
|
+
import { WORKSPACE_MANUAL_DIR, loadAllAppManuals, matchGuide, type AppGuide } from './vision/appGuide.js';
|
|
31
|
+
import { appendFieldNotes, markFlowVerified } from './manualSchema.js';
|
|
32
|
+
import { deriveFocusSnapshot } from './vision/focus.js';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 诊断用的运行身份:**只有 observe 能力**。
|
|
36
|
+
*
|
|
37
|
+
* 不是靠调用方自觉传对参数——这条命令面在结构上就派发不出写类动作,因为它
|
|
38
|
+
* 手里的 run 从来没拿到过 interact/type/submit。
|
|
39
|
+
*/
|
|
40
|
+
function diagnosticRun(): ComputerUseRunContext {
|
|
41
|
+
return {
|
|
42
|
+
ownerId: anonymousOwnerId(),
|
|
43
|
+
conversationKey: 'diagnostics',
|
|
44
|
+
runId: randomUUID(),
|
|
45
|
+
surface: 'cli',
|
|
46
|
+
allowedApps: [],
|
|
47
|
+
grantId: randomUUID(),
|
|
48
|
+
capabilities: ['observe'],
|
|
49
|
+
// 观测档下没有任何不可逆动作可做,也就不该存在一条「问人要授权」的路径。
|
|
50
|
+
supervised: false,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface ManualDraft {
|
|
55
|
+
/** 建议的文件名(不含 .md) */
|
|
56
|
+
name: string;
|
|
57
|
+
markdown: string;
|
|
58
|
+
/** 采集过程中值得说出来的事(权限不足、已有同名说明书…) */
|
|
59
|
+
warnings: string[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type WriteDraftResult =
|
|
63
|
+
| { ok: true; path: string }
|
|
64
|
+
| { ok: false; error: string };
|
|
65
|
+
|
|
66
|
+
export const computerUseDiagnostics = {
|
|
67
|
+
platformSupported(): boolean {
|
|
68
|
+
return ComputerUseService.platformSupported();
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
helperPath(): string | null {
|
|
72
|
+
return findComputerUseHelper();
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
stateDir(): string {
|
|
76
|
+
return computerUseStateDir();
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
/** 说明书落盘目录(工作区,可写)。 */
|
|
80
|
+
manualDir(): string {
|
|
81
|
+
return join(getWorkingDir(), WORKSPACE_MANUAL_DIR);
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
status(signal?: AbortSignal): Promise<ComputerUseResponse> {
|
|
85
|
+
return computerUseService.request(diagnosticRun(), { action: 'status' }, signal);
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
permissions(signal?: AbortSignal): Promise<ComputerUseResponse> {
|
|
89
|
+
return computerUseService.request(diagnosticRun(), { action: 'permissions' }, signal);
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
observe(signal?: AbortSignal): Promise<ComputerUseResponse> {
|
|
93
|
+
return computerUseService.request(diagnosticRun(), { action: 'observe' }, signal, { internalObserve: true });
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
captureDraft(name: string | undefined, signal?: AbortSignal): Promise<ManualDraft | string> {
|
|
97
|
+
return captureDraft(name, signal);
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
writeManualDraft(draft: ManualDraft, signal?: AbortSignal): Promise<WriteDraftResult> {
|
|
101
|
+
return writeManualDraft(draft, signal);
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
/** 取一份说明书的**原始 markdown**(验收回写要做行级编辑,不能只拿解析结果)。 */
|
|
105
|
+
readManualSource(name: string): Promise<ManualSource | string> {
|
|
106
|
+
return readManualSource(name);
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
/** 把验收结果写回工作区那份说明书。 */
|
|
110
|
+
saveVerification(input: SaveVerificationInput, signal?: AbortSignal): Promise<WriteDraftResult> {
|
|
111
|
+
return saveVerification(input, signal);
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export interface ManualSource {
|
|
116
|
+
name: string;
|
|
117
|
+
/** 原始文件路径(可能在只读的包内目录)。 */
|
|
118
|
+
path: string;
|
|
119
|
+
markdown: string;
|
|
120
|
+
guide: AppGuide;
|
|
121
|
+
/** 这份说明书是不是已经在工作区(可写)。 */
|
|
122
|
+
inWorkspace: boolean;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface SaveVerificationInput {
|
|
126
|
+
source: ManualSource;
|
|
127
|
+
/** 全部步骤通过、可以翻 `verified: true` 的 flow。 */
|
|
128
|
+
verifiedFlows: string[];
|
|
129
|
+
/** 追加到 `## 实测记录` 的行。 */
|
|
130
|
+
notes: string[];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 读一份说明书的原文。
|
|
135
|
+
*
|
|
136
|
+
* 为什么要原文而不是 `AppGuide`:验收要把 `verified: false` 翻成 true,而
|
|
137
|
+
* 「parse → 改 → 重新序列化」会抹掉 frontmatter 里的全部注释。那些注释是
|
|
138
|
+
* 说明书里最难重建的部分,所以回写走行级编辑(`markFlowVerified`),
|
|
139
|
+
* 前提是手里有原始字节。
|
|
140
|
+
*/
|
|
141
|
+
async function readManualSource(name: string): Promise<ManualSource | string> {
|
|
142
|
+
const { guides, rejected } = await loadAllAppManuals();
|
|
143
|
+
const guide = guides.find((item) => item.name === name)
|
|
144
|
+
?? rejected.find((item) => item.guide.name === name)?.guide;
|
|
145
|
+
if (!guide) return `没有名为「${name}」的说明书。用 /computeruse apps 看清单。`;
|
|
146
|
+
|
|
147
|
+
const markdown = await readFile(guide.path, 'utf8').catch(() => null);
|
|
148
|
+
if (markdown === null) return `读不到 ${guide.path}。`;
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
name,
|
|
152
|
+
path: guide.path,
|
|
153
|
+
markdown,
|
|
154
|
+
guide,
|
|
155
|
+
inWorkspace: guide.path.startsWith(computerUseDiagnostics.manualDir()),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* 写回验收结果。
|
|
161
|
+
*
|
|
162
|
+
* ★ **一律写工作区那份**,哪怕原文在包内目录。包内目录在 npm / 绿色版安装后
|
|
163
|
+
* 通常只读,而且那是我们随包发布的知识,不该被某台机器的一次验收改掉。
|
|
164
|
+
* 工作区那份优先级更高(见 appGuide.ts::appManualProviders),所以复制过去
|
|
165
|
+
* 再改,效果就是「这台机器上的实测结论覆盖随包默认」。
|
|
166
|
+
*/
|
|
167
|
+
async function saveVerification(
|
|
168
|
+
input: SaveVerificationInput,
|
|
169
|
+
signal?: AbortSignal,
|
|
170
|
+
): Promise<WriteDraftResult> {
|
|
171
|
+
const dir = computerUseDiagnostics.manualDir();
|
|
172
|
+
const target = join(dir, `${input.source.name}.md`);
|
|
173
|
+
|
|
174
|
+
let markdown = input.source.markdown;
|
|
175
|
+
const flipped: string[] = [];
|
|
176
|
+
const unflipped: string[] = [];
|
|
177
|
+
for (const flowId of input.verifiedFlows) {
|
|
178
|
+
const next = markFlowVerified(markdown, flowId);
|
|
179
|
+
if (next) {
|
|
180
|
+
markdown = next;
|
|
181
|
+
flipped.push(flowId);
|
|
182
|
+
} else {
|
|
183
|
+
unflipped.push(flowId);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
markdown = appendFieldNotes(markdown, input.notes);
|
|
187
|
+
|
|
188
|
+
if (!hasAskHandler()) {
|
|
189
|
+
return { ok: false, error: '当前宿主没有可用的确认界面,未写盘。' };
|
|
190
|
+
}
|
|
191
|
+
let approved = false;
|
|
192
|
+
try {
|
|
193
|
+
const answers = await requestUserChoice([{
|
|
194
|
+
header: '写入实测结论',
|
|
195
|
+
question: `把这次验收的结论写到 ${target}?\n`
|
|
196
|
+
+ (input.source.inWorkspace ? '' : `(原文在 ${input.source.path},会复制到工作区再改,不动包内文件。)\n`)
|
|
197
|
+
+ `翻为已验证的流程:${flipped.join('、') || '(无)'}\n`
|
|
198
|
+
+ (unflipped.length > 0 ? `⚠️ 这些找不到可翻的 verified 行,只会记进实测记录:${unflipped.join('、')}\n` : '')
|
|
199
|
+
+ `新增实测记录 ${input.notes.length} 行。`,
|
|
200
|
+
options: [
|
|
201
|
+
{ label: '取消 (推荐)', description: '不写盘。结论已打印,你可以自己整理。' },
|
|
202
|
+
{ label: '写入', description: `更新 ${target}` },
|
|
203
|
+
],
|
|
204
|
+
}], signal);
|
|
205
|
+
approved = answers[0]?.selected.some((label) => label.startsWith('写入')) === true;
|
|
206
|
+
} catch {
|
|
207
|
+
return { ok: false, error: '确认过程被中断,未写盘。' };
|
|
208
|
+
}
|
|
209
|
+
if (!approved) return { ok: false, error: '你取消了写入。' };
|
|
210
|
+
|
|
211
|
+
try {
|
|
212
|
+
await mkdir(dir, { recursive: true });
|
|
213
|
+
const temp = join(dir, `.${input.source.name}.${process.pid}.${randomUUID()}.tmp`);
|
|
214
|
+
await writeFile(temp, markdown, { mode: 0o600 });
|
|
215
|
+
await rename(temp, target);
|
|
216
|
+
return { ok: true, path: target };
|
|
217
|
+
} catch (error) {
|
|
218
|
+
return {
|
|
219
|
+
ok: false,
|
|
220
|
+
error: `写入失败:${error instanceof Error ? error.message : String(error)}`,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// ============================================================
|
|
226
|
+
// 草稿采集
|
|
227
|
+
// ============================================================
|
|
228
|
+
|
|
229
|
+
/** AX 树里值得写进说明书的控件候选上限。再多就不是「关键控件」了。 */
|
|
230
|
+
const MAX_CONTROL_CANDIDATES = 15;
|
|
231
|
+
const MAX_WINDOW_LINES = 10;
|
|
232
|
+
|
|
233
|
+
interface AxCandidate {
|
|
234
|
+
role: string;
|
|
235
|
+
names: string[];
|
|
236
|
+
focused: boolean;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* 从一次观测生成说明书草稿。
|
|
241
|
+
*
|
|
242
|
+
* ★ **草稿里不出现任何 rect。** 窗口位置与控件 bounds 是「这一秒屏幕长什么样」,
|
|
243
|
+
* 不是「这个应用怎么用」——窗口能拉伸、能全屏、能换显示器。把一次观测的坐标
|
|
244
|
+
* 写成 schema 里的稳定事实,等于制造一批看着像已验证、实际下一次就失准的数据。
|
|
245
|
+
* 稳定的是 **AX role + name 锚点**,所以草稿只出这个。
|
|
246
|
+
*
|
|
247
|
+
* ★ `layout` 与 `flows` 留空:它们要靠实机与使用逐步沉淀,编不出来。
|
|
248
|
+
*/
|
|
249
|
+
async function captureDraft(
|
|
250
|
+
requestedName: string | undefined,
|
|
251
|
+
signal?: AbortSignal,
|
|
252
|
+
): Promise<ManualDraft | string> {
|
|
253
|
+
if (!ComputerUseService.platformSupported()) {
|
|
254
|
+
return `当前平台是 ${process.platform},Computer Use 只支持 macOS,无法采集。`;
|
|
255
|
+
}
|
|
256
|
+
const response = await computerUseService.request(
|
|
257
|
+
diagnosticRun(), { action: 'observe' }, signal, { internalObserve: true },
|
|
258
|
+
);
|
|
259
|
+
if (!response.ok || !response.state) {
|
|
260
|
+
return `采集失败:${response.error?.code ?? 'failed'}: ${response.error?.message ?? '未知错误'}`;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const state = response.state;
|
|
264
|
+
const app = state.activeApp;
|
|
265
|
+
if (!app?.id && !app?.name) {
|
|
266
|
+
return '拿不到前台应用身份,无法采集。先把目标应用切到前台再试。';
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const warnings: string[] = [];
|
|
270
|
+
const name = sanitizeName(requestedName ?? app?.id?.split('.').pop() ?? app?.name ?? 'unknown');
|
|
271
|
+
|
|
272
|
+
const { guides } = await loadAllAppManuals();
|
|
273
|
+
const existing = matchGuide(guides, { id: app?.id, name: app?.name });
|
|
274
|
+
if (existing) {
|
|
275
|
+
warnings.push(
|
|
276
|
+
`已有说明书「${existing.guide.name}」认领这个应用(${existing.guide.path})——`
|
|
277
|
+
+ '草稿仅供对照,不要直接盖掉已沉淀的内容。',
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
if (state.accessibility?.truncated === true) {
|
|
281
|
+
warnings.push(
|
|
282
|
+
'无障碍树不完整(权限不足或元素过多),控件候选会很少甚至为空。'
|
|
283
|
+
+ '自绘界面(Electron / Qt / 跨端客户端)本来就是这样——那不是采集失败。',
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const candidates = collectAxCandidates(state);
|
|
288
|
+
const focus = deriveFocusSnapshot(state);
|
|
289
|
+
|
|
290
|
+
return { name, markdown: renderDraft({ name, state, candidates, focus }), warnings };
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function sanitizeName(raw: string): string {
|
|
294
|
+
const cleaned = raw.trim().toLowerCase().replace(/[^a-z0-9._-]+/g, '-').replace(/^-+|-+$/g, '');
|
|
295
|
+
return cleaned || 'unknown';
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function collectAxCandidates(state: ComputerState): AxCandidate[] {
|
|
299
|
+
const byRole = new Map<string, AxCandidate>();
|
|
300
|
+
const walk = (node: { role?: string; name?: string; focused?: boolean; children?: unknown[] } | undefined): void => {
|
|
301
|
+
if (!node) return;
|
|
302
|
+
const role = node.role?.trim();
|
|
303
|
+
if (role) {
|
|
304
|
+
const entry = byRole.get(role) ?? { role, names: [], focused: false };
|
|
305
|
+
const label = node.name?.trim();
|
|
306
|
+
if (label && !entry.names.includes(label) && entry.names.length < 5) entry.names.push(label);
|
|
307
|
+
if (node.focused === true) entry.focused = true;
|
|
308
|
+
byRole.set(role, entry);
|
|
309
|
+
}
|
|
310
|
+
for (const child of (node.children ?? []) as typeof node[]) walk(child);
|
|
311
|
+
};
|
|
312
|
+
walk(state.accessibility?.root as never);
|
|
313
|
+
return [...byRole.values()].slice(0, MAX_CONTROL_CANDIDATES);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function renderDraft(input: {
|
|
317
|
+
name: string;
|
|
318
|
+
state: ComputerState;
|
|
319
|
+
candidates: AxCandidate[];
|
|
320
|
+
focus: ReturnType<typeof deriveFocusSnapshot>;
|
|
321
|
+
}): string {
|
|
322
|
+
const app = input.state.activeApp;
|
|
323
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
324
|
+
const quoted = (value: string): string => JSON.stringify(value);
|
|
325
|
+
|
|
326
|
+
const controls = input.candidates.length > 0
|
|
327
|
+
? input.candidates.map((candidate) => [
|
|
328
|
+
` - id: ${sanitizeName(candidate.role)}`,
|
|
329
|
+
` ax: { role: ${candidate.role}${candidate.names.length > 0 ? `, name: [${candidate.names.map(quoted).join(', ')}]` : ''} }`,
|
|
330
|
+
` desc: 采集自实机 AX 树${candidate.focused ? '(采集时持有焦点)' : ''}`,
|
|
331
|
+
' verified: false',
|
|
332
|
+
].join('\n')).join('\n')
|
|
333
|
+
: '';
|
|
334
|
+
|
|
335
|
+
const windows = input.state.windows.slice(0, MAX_WINDOW_LINES)
|
|
336
|
+
.map((window) => `- ${window.title ?? '(无标题)'}`);
|
|
337
|
+
|
|
338
|
+
return [
|
|
339
|
+
'---',
|
|
340
|
+
'schemaVersion: 2',
|
|
341
|
+
'guideVersion: 1',
|
|
342
|
+
'status: draft',
|
|
343
|
+
`platforms: [${process.platform === 'darwin' ? 'macOS' : process.platform}]`,
|
|
344
|
+
'match:',
|
|
345
|
+
` bundleId: [${app?.id ? quoted(app.id) : ''}]`,
|
|
346
|
+
` processName: [${app?.name ? quoted(app.name) : ''}]`,
|
|
347
|
+
` displayName: [${app?.name ? quoted(app.name) : ''}]`,
|
|
348
|
+
'',
|
|
349
|
+
'# 不可逆动作:**必须人工补全**。采集看不出「哪个动作收不回来」——',
|
|
350
|
+
'# 那是产品语义,不是屏幕上的像素。留空等于这个应用没有任何不可逆防护。',
|
|
351
|
+
'irreversible: []',
|
|
352
|
+
'',
|
|
353
|
+
'# 界面分区留空:一次观测的窗口位置不是稳定的应用知识(窗口能拉伸、能全屏)。',
|
|
354
|
+
'layout: []',
|
|
355
|
+
'',
|
|
356
|
+
controls ? 'controls:' : 'controls: []',
|
|
357
|
+
...(controls ? [controls] : []),
|
|
358
|
+
'',
|
|
359
|
+
'# 典型流程留空:靠实机与使用逐步沉淀,采集编不出来。',
|
|
360
|
+
'flows: {}',
|
|
361
|
+
'',
|
|
362
|
+
'verification:',
|
|
363
|
+
` environment: ${process.platform} · 采集于 ${today}(应用版本未知)`,
|
|
364
|
+
` verifiedAt: ${today}`,
|
|
365
|
+
' verifiedItems: [identity]',
|
|
366
|
+
' unverifiedItems: [layout, controls, flows]',
|
|
367
|
+
'---',
|
|
368
|
+
'',
|
|
369
|
+
`# ${input.name} App Guide(自动采集草稿)`,
|
|
370
|
+
'',
|
|
371
|
+
'> 本文由 `/computeruse capture` 从**一次真实观测**生成。身份是实测的;',
|
|
372
|
+
'> 控件候选来自当时的 AX 树,**未经验证**;分区与流程需要人来写。',
|
|
373
|
+
'',
|
|
374
|
+
'## 观测候选',
|
|
375
|
+
'',
|
|
376
|
+
`- 前台应用:${app?.name ?? '未知'}(${app?.id ?? '无标识'})`,
|
|
377
|
+
`- 无障碍树:${input.state.accessibility ? (input.state.accessibility.truncated ? '不完整' : '可用') : '无'}`,
|
|
378
|
+
`- 焦点:${input.focus ? `${input.focus.role ?? '未知控件'}(L${input.focus.level})` : '不可用'}`,
|
|
379
|
+
'',
|
|
380
|
+
'### 当时的窗口',
|
|
381
|
+
'',
|
|
382
|
+
...(windows.length > 0 ? windows : ['- (没有可见窗口)']),
|
|
383
|
+
'',
|
|
384
|
+
'## 实测记录',
|
|
385
|
+
'',
|
|
386
|
+
'> 说明书与实况不符时,把**观察到的事实**追加到这里,一条一行,带日期与版本。',
|
|
387
|
+
'> 只写观察到的,不写推测。',
|
|
388
|
+
'',
|
|
389
|
+
'- (暂无)',
|
|
390
|
+
'',
|
|
391
|
+
].join('\n');
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// ============================================================
|
|
395
|
+
// 受控写盘
|
|
396
|
+
// ============================================================
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* 把草稿写进工作区说明书目录。
|
|
400
|
+
*
|
|
401
|
+
* 三条边界:
|
|
402
|
+
* ① **必须有人确认** —— 无 ask handler 就不写。这是往用户项目里放文件。
|
|
403
|
+
* ② **不覆盖** —— 已存在就拒绝,让用户自己合并。自动合并两份说明书是赌博。
|
|
404
|
+
* ③ **原子写** —— 同目录 temp + rename,避免半截文件被当成合法说明书加载。
|
|
405
|
+
*/
|
|
406
|
+
async function writeManualDraft(
|
|
407
|
+
draft: ManualDraft,
|
|
408
|
+
signal?: AbortSignal,
|
|
409
|
+
): Promise<WriteDraftResult> {
|
|
410
|
+
const dir = computerUseDiagnostics.manualDir();
|
|
411
|
+
const target = join(dir, `${draft.name}.md`);
|
|
412
|
+
|
|
413
|
+
if (existsSync(target)) {
|
|
414
|
+
return {
|
|
415
|
+
ok: false,
|
|
416
|
+
error: `${target} 已存在。不自动覆盖——请自己对照合并,或换一个名字重跑。`,
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
if (!hasAskHandler()) {
|
|
420
|
+
return { ok: false, error: '当前宿主没有可用的确认界面,未写盘。草稿见上方输出。' };
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
let approved = false;
|
|
424
|
+
try {
|
|
425
|
+
const answers = await requestUserChoice([{
|
|
426
|
+
header: '写入说明书',
|
|
427
|
+
question: `把采集到的草稿写到 ${target}?\n`
|
|
428
|
+
+ '它是**未验证**的起点,不是成品;写入后请自己核对并补全不可逆动作清单。',
|
|
429
|
+
options: [
|
|
430
|
+
{ label: '取消 (推荐)', description: '不写盘。草稿已经打印出来,你可以自己保存。' },
|
|
431
|
+
{ label: '写入', description: `在 ${dir} 下新建 ${draft.name}.md` },
|
|
432
|
+
],
|
|
433
|
+
}], signal);
|
|
434
|
+
approved = answers[0]?.selected.some((label) => label.startsWith('写入')) === true;
|
|
435
|
+
} catch {
|
|
436
|
+
return { ok: false, error: '确认过程被中断,未写盘。' };
|
|
437
|
+
}
|
|
438
|
+
if (!approved) return { ok: false, error: '你取消了写入。' };
|
|
439
|
+
|
|
440
|
+
try {
|
|
441
|
+
await mkdir(dir, { recursive: true });
|
|
442
|
+
const temp = join(dirname(target), `.${draft.name}.${process.pid}.${randomUUID()}.tmp`);
|
|
443
|
+
await writeFile(temp, draft.markdown, { mode: 0o600 });
|
|
444
|
+
await rename(temp, target);
|
|
445
|
+
return { ok: true, path: target };
|
|
446
|
+
} catch (error) {
|
|
447
|
+
// 只读目录、磁盘满都会走到这里。报出来,不抛异常——采集本身是成功的。
|
|
448
|
+
return {
|
|
449
|
+
ok: false,
|
|
450
|
+
error: `写入失败:${error instanceof Error ? error.message : String(error)}`,
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
const FILE_TRANSFER = /(上传|导入|拖入|发送文件|attach|upload|import|drop\s+file)/i;
|
|
3
|
+
const CLIPBOARD_READ = /(读取|查看|获取|粘贴).{0,8}(剪贴板|clipboard)/i;
|
|
4
|
+
const CLIPBOARD_WRITE = /(复制|写入).{0,8}(剪贴板|clipboard)|复制.{0,12}(文本|内容)/i;
|
|
5
|
+
/**
|
|
6
|
+
* 从用户输入推断本回合**可能**需要的能力。
|
|
7
|
+
*
|
|
8
|
+
* ⚠️ 这是启发式,不是授权判定。它的输入是自然语言,而自然语言是可被诱导的
|
|
9
|
+
* ——「帮我删掉草稿」这种日常说法就会命中「删除」。因此:
|
|
10
|
+
*
|
|
11
|
+
* - 它**不再**产出 `submit`。最终提交必须由模型显式自报 `intent:'submit'`
|
|
12
|
+
* 并经人工确认(见 protocol.ts::requiredCapability 与 computeruse.ts 的
|
|
13
|
+
* 不可逆准入),一句话不能换来不可撤销的权力。
|
|
14
|
+
* - 它产出的 file-drop / clipboard 仍受更硬的边界约束:拖入文件要过
|
|
15
|
+
* `allowedFileRoots` 的 realpath 校验,与这里猜得准不准无关。
|
|
16
|
+
*/
|
|
17
|
+
export function inferComputerUseCapabilities(text) {
|
|
18
|
+
const capabilities = new Set(['observe', 'interact', 'type']);
|
|
19
|
+
if (FILE_TRANSFER.test(text))
|
|
20
|
+
capabilities.add('file-drop');
|
|
21
|
+
if (CLIPBOARD_READ.test(text))
|
|
22
|
+
capabilities.add('clipboard-read');
|
|
23
|
+
if (CLIPBOARD_WRITE.test(text))
|
|
24
|
+
capabilities.add('clipboard-write');
|
|
25
|
+
return [...capabilities];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 本回合的输入是否**看起来**要做不可撤销的事。
|
|
29
|
+
*
|
|
30
|
+
* 只用于提示宿主「这一回合可能需要准备好确认通道」,**不直接授予 submit**。
|
|
31
|
+
* 与 `inferComputerUseCapabilities` 分开,是为了让「猜测」和「授权」在类型
|
|
32
|
+
* 上就无法混用。
|
|
33
|
+
*/
|
|
34
|
+
const FINAL_SUBMIT = /(发送|发布|提交|确认购买|永久删除|接受合同|send|publish|submit|purchase|delete|accept)/i;
|
|
35
|
+
export function looksLikeIrreversibleRequest(text) {
|
|
36
|
+
return FINAL_SUBMIT.test(text);
|
|
37
|
+
}
|
|
38
|
+
export function createComputerUseRunContext(input) {
|
|
39
|
+
return {
|
|
40
|
+
ownerId: input.ownerId,
|
|
41
|
+
conversationKey: input.conversationKey,
|
|
42
|
+
runId: input.runId,
|
|
43
|
+
surface: input.surface,
|
|
44
|
+
allowedApps: input.allowedApps ?? [],
|
|
45
|
+
grantId: randomUUID(),
|
|
46
|
+
capabilities: inferComputerUseCapabilities(input.text),
|
|
47
|
+
// 原话只进确认弹窗的说明文字,不参与授权判定(见 ComputerUseRunContext.userInput)。
|
|
48
|
+
userInput: input.text,
|
|
49
|
+
...(input.allowedFileRoots ? { allowedFileRoots: input.allowedFileRoots } : {}),
|
|
50
|
+
...(input.supervised !== undefined ? { supervised: input.supervised } : {}),
|
|
51
|
+
...(input.diagnosticTraceDir ? { diagnosticTraceDir: input.diagnosticTraceDir } : {}),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import type {
|
|
3
|
+
ComputerUseCapability,
|
|
4
|
+
ComputerUseRunContext,
|
|
5
|
+
ComputerUseSurface,
|
|
6
|
+
} from './protocol.js';
|
|
7
|
+
|
|
8
|
+
const FILE_TRANSFER = /(上传|导入|拖入|发送文件|attach|upload|import|drop\s+file)/i;
|
|
9
|
+
const CLIPBOARD_READ = /(读取|查看|获取|粘贴).{0,8}(剪贴板|clipboard)/i;
|
|
10
|
+
const CLIPBOARD_WRITE = /(复制|写入).{0,8}(剪贴板|clipboard)|复制.{0,12}(文本|内容)/i;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 从用户输入推断本回合**可能**需要的能力。
|
|
14
|
+
*
|
|
15
|
+
* ⚠️ 这是启发式,不是授权判定。它的输入是自然语言,而自然语言是可被诱导的
|
|
16
|
+
* ——「帮我删掉草稿」这种日常说法就会命中「删除」。因此:
|
|
17
|
+
*
|
|
18
|
+
* - 它**不再**产出 `submit`。最终提交必须由模型显式自报 `intent:'submit'`
|
|
19
|
+
* 并经人工确认(见 protocol.ts::requiredCapability 与 computeruse.ts 的
|
|
20
|
+
* 不可逆准入),一句话不能换来不可撤销的权力。
|
|
21
|
+
* - 它产出的 file-drop / clipboard 仍受更硬的边界约束:拖入文件要过
|
|
22
|
+
* `allowedFileRoots` 的 realpath 校验,与这里猜得准不准无关。
|
|
23
|
+
*/
|
|
24
|
+
export function inferComputerUseCapabilities(text: string): ComputerUseCapability[] {
|
|
25
|
+
const capabilities = new Set<ComputerUseCapability>(['observe', 'interact', 'type']);
|
|
26
|
+
if (FILE_TRANSFER.test(text)) capabilities.add('file-drop');
|
|
27
|
+
if (CLIPBOARD_READ.test(text)) capabilities.add('clipboard-read');
|
|
28
|
+
if (CLIPBOARD_WRITE.test(text)) capabilities.add('clipboard-write');
|
|
29
|
+
return [...capabilities];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 本回合的输入是否**看起来**要做不可撤销的事。
|
|
34
|
+
*
|
|
35
|
+
* 只用于提示宿主「这一回合可能需要准备好确认通道」,**不直接授予 submit**。
|
|
36
|
+
* 与 `inferComputerUseCapabilities` 分开,是为了让「猜测」和「授权」在类型
|
|
37
|
+
* 上就无法混用。
|
|
38
|
+
*/
|
|
39
|
+
const FINAL_SUBMIT = /(发送|发布|提交|确认购买|永久删除|接受合同|send|publish|submit|purchase|delete|accept)/i;
|
|
40
|
+
|
|
41
|
+
export function looksLikeIrreversibleRequest(text: string): boolean {
|
|
42
|
+
return FINAL_SUBMIT.test(text);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function createComputerUseRunContext(input: {
|
|
46
|
+
ownerId: string;
|
|
47
|
+
conversationKey: string;
|
|
48
|
+
runId: string;
|
|
49
|
+
surface: ComputerUseSurface;
|
|
50
|
+
text: string;
|
|
51
|
+
allowedFileRoots?: string[];
|
|
52
|
+
allowedApps?: string[];
|
|
53
|
+
supervised?: boolean;
|
|
54
|
+
diagnosticTraceDir?: string;
|
|
55
|
+
}): ComputerUseRunContext {
|
|
56
|
+
return {
|
|
57
|
+
ownerId: input.ownerId,
|
|
58
|
+
conversationKey: input.conversationKey,
|
|
59
|
+
runId: input.runId,
|
|
60
|
+
surface: input.surface,
|
|
61
|
+
allowedApps: input.allowedApps ?? [],
|
|
62
|
+
grantId: randomUUID(),
|
|
63
|
+
capabilities: inferComputerUseCapabilities(input.text),
|
|
64
|
+
// 原话只进确认弹窗的说明文字,不参与授权判定(见 ComputerUseRunContext.userInput)。
|
|
65
|
+
userInput: input.text,
|
|
66
|
+
...(input.allowedFileRoots ? { allowedFileRoots: input.allowedFileRoots } : {}),
|
|
67
|
+
...(input.supervised !== undefined ? { supervised: input.supervised } : {}),
|
|
68
|
+
...(input.diagnosticTraceDir ? { diagnosticTraceDir: input.diagnosticTraceDir } : {}),
|
|
69
|
+
};
|
|
70
|
+
}
|