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,558 @@
|
|
|
1
|
+
import { createReadStream } from 'node:fs';
|
|
2
|
+
import { open, readFile, stat, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { extname } from 'node:path';
|
|
4
|
+
import { createInterface } from 'node:readline';
|
|
5
|
+
import { execFile } from 'node:child_process';
|
|
6
|
+
import { mkdir } from 'node:fs/promises';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { promisify } from 'node:util';
|
|
9
|
+
import { randomUUID } from 'node:crypto';
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
|
|
12
|
+
import type { Tool, ToolCallContext, ToolResult } from '../../types.js';
|
|
13
|
+
import { toToolParameters } from '../../utils/zodToJson.js';
|
|
14
|
+
import {
|
|
15
|
+
DEFAULT_MAX_RESULT_SIZE_CHARS,
|
|
16
|
+
MAX_FILE_SIZE_BYTES,
|
|
17
|
+
MAX_LINES_TO_READ,
|
|
18
|
+
} from '../types.js';
|
|
19
|
+
import { fileActivityMetadata } from '../shared/fileActivity.js';
|
|
20
|
+
import {
|
|
21
|
+
hashFileBytes,
|
|
22
|
+
recordRead,
|
|
23
|
+
type FileReadState,
|
|
24
|
+
} from '../shared/fileState.js';
|
|
25
|
+
import {
|
|
26
|
+
hasBinaryExtension,
|
|
27
|
+
isBlockedDevicePath,
|
|
28
|
+
readTextFile,
|
|
29
|
+
resolveToolPath,
|
|
30
|
+
} from '../shared/fileUtils.js';
|
|
31
|
+
import { filePathField } from '../shared/schemas.js';
|
|
32
|
+
import {
|
|
33
|
+
pruneRuntimeOutputs,
|
|
34
|
+
sessionRuntimeDir,
|
|
35
|
+
type RuntimeIdentity,
|
|
36
|
+
} from '../../session/runtimeStore.js';
|
|
37
|
+
|
|
38
|
+
const inputSchema = z.object({
|
|
39
|
+
file_path: filePathField('读取'),
|
|
40
|
+
offset: z
|
|
41
|
+
.number()
|
|
42
|
+
.int()
|
|
43
|
+
.positive()
|
|
44
|
+
.optional()
|
|
45
|
+
.describe(
|
|
46
|
+
'文本文件为 1-indexed 起始行;Jupyter Notebook 为 1-indexed 起始 cell',
|
|
47
|
+
),
|
|
48
|
+
limit: z
|
|
49
|
+
.number()
|
|
50
|
+
.int()
|
|
51
|
+
.positive()
|
|
52
|
+
.optional()
|
|
53
|
+
.describe(`最多读取的文本行或 Notebook cells;默认 ${MAX_LINES_TO_READ}`),
|
|
54
|
+
pages: z
|
|
55
|
+
.string()
|
|
56
|
+
.regex(/^\d+(?:-\d+)?(?:,\d+(?:-\d+)?)*$/)
|
|
57
|
+
.optional()
|
|
58
|
+
.describe('PDF 页码,例如 "1-5,8";每次最多 20 页'),
|
|
59
|
+
pdf_mode: z
|
|
60
|
+
.enum(['auto', 'text', 'visual', 'both'])
|
|
61
|
+
.default('auto')
|
|
62
|
+
.optional(),
|
|
63
|
+
});
|
|
64
|
+
type ReadInput = z.infer<typeof inputSchema>;
|
|
65
|
+
|
|
66
|
+
const IMAGE_EXTENSIONS = new Set([
|
|
67
|
+
'.png',
|
|
68
|
+
'.jpg',
|
|
69
|
+
'.jpeg',
|
|
70
|
+
'.gif',
|
|
71
|
+
'.webp',
|
|
72
|
+
'.bmp',
|
|
73
|
+
]);
|
|
74
|
+
const MAX_IMAGE_BYTES = 25 * 1024 * 1024;
|
|
75
|
+
const MAX_NOTEBOOK_BYTES = 32 * 1024 * 1024;
|
|
76
|
+
const SMALL_TEXT_BYTES = 16 * 1024 * 1024;
|
|
77
|
+
|
|
78
|
+
const description = `Reads local text files, images, and Jupyter notebooks.
|
|
79
|
+
|
|
80
|
+
Usage:
|
|
81
|
+
- Relative paths resolve against the current working directory.
|
|
82
|
+
- Text results use 1-based line numbers. Use offset/limit for targeted ranges.
|
|
83
|
+
- PNG, JPEG, WebP, GIF, and BMP files are attached for visual inspection.
|
|
84
|
+
- For .ipynb files, offset/limit select cells; results include cell id, type, source, and bounded outputs.
|
|
85
|
+
- PDF supports page-selected text extraction and optional visual page rendering; office files use the matching project Skill.
|
|
86
|
+
- This tool reads files, not directories; use Glob for directory discovery.`;
|
|
87
|
+
|
|
88
|
+
function notebookSource(value: unknown): string {
|
|
89
|
+
if (Array.isArray(value))
|
|
90
|
+
return value
|
|
91
|
+
.filter((item): item is string => typeof item === 'string')
|
|
92
|
+
.join('');
|
|
93
|
+
return typeof value === 'string' ? value : '';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function renderNotebook(
|
|
97
|
+
raw: string,
|
|
98
|
+
offset: number,
|
|
99
|
+
limit: number,
|
|
100
|
+
): {
|
|
101
|
+
content: string;
|
|
102
|
+
total: number;
|
|
103
|
+
partial: boolean;
|
|
104
|
+
} {
|
|
105
|
+
const parsed = JSON.parse(raw) as {
|
|
106
|
+
cells?: unknown[];
|
|
107
|
+
metadata?: Record<string, unknown>;
|
|
108
|
+
};
|
|
109
|
+
if (!Array.isArray(parsed.cells)) throw new Error('Notebook 缺少 cells 数组');
|
|
110
|
+
const start = offset - 1;
|
|
111
|
+
const cells = parsed.cells.slice(start, start + limit);
|
|
112
|
+
const parts = cells.map((value, index) => {
|
|
113
|
+
const cell =
|
|
114
|
+
value && typeof value === 'object'
|
|
115
|
+
? (value as Record<string, unknown>)
|
|
116
|
+
: {};
|
|
117
|
+
const outputs = Array.isArray(cell.outputs) ? cell.outputs : [];
|
|
118
|
+
const renderedOutputs = outputs
|
|
119
|
+
.slice(0, 8)
|
|
120
|
+
.map((output) => {
|
|
121
|
+
if (!output || typeof output !== 'object') return String(output ?? '');
|
|
122
|
+
const item = output as Record<string, unknown>;
|
|
123
|
+
const text =
|
|
124
|
+
item.text ??
|
|
125
|
+
(item.data && typeof item.data === 'object'
|
|
126
|
+
? (item.data as Record<string, unknown>)['text/plain']
|
|
127
|
+
: undefined);
|
|
128
|
+
return notebookSource(text).slice(0, 2_000);
|
|
129
|
+
})
|
|
130
|
+
.filter(Boolean)
|
|
131
|
+
.join('\n');
|
|
132
|
+
return [
|
|
133
|
+
`## Cell ${start + index + 1} [selector=cell-${start + index + 1}${typeof cell.id === 'string' ? `; id=${cell.id}` : ''}; type=${String(cell.cell_type ?? 'unknown')}]`,
|
|
134
|
+
notebookSource(cell.source),
|
|
135
|
+
...(renderedOutputs ? [`\nOutput:\n${renderedOutputs}`] : []),
|
|
136
|
+
].join('\n');
|
|
137
|
+
});
|
|
138
|
+
const end = start + cells.length;
|
|
139
|
+
if (end < parsed.cells.length)
|
|
140
|
+
parts.push(
|
|
141
|
+
`... (${parsed.cells.length - end} cells remain; continue with offset=${end + 1})`,
|
|
142
|
+
);
|
|
143
|
+
return {
|
|
144
|
+
content: parts.join('\n\n'),
|
|
145
|
+
total: parsed.cells.length,
|
|
146
|
+
partial: start > 0 || end < parsed.cells.length,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function readStreamedText(
|
|
151
|
+
filePath: string,
|
|
152
|
+
offset: number,
|
|
153
|
+
limit: number,
|
|
154
|
+
): Promise<{ numbered: string; totalKnown: number; hasMore: boolean }> {
|
|
155
|
+
const handle = await open(filePath, 'r');
|
|
156
|
+
const prefix = Buffer.alloc(3);
|
|
157
|
+
const { bytesRead } = await handle.read(prefix, 0, 3, 0);
|
|
158
|
+
await handle.close();
|
|
159
|
+
const utf16 = bytesRead >= 2 && prefix[0] === 0xff && prefix[1] === 0xfe;
|
|
160
|
+
const stream = createReadStream(filePath, {
|
|
161
|
+
encoding: utf16 ? 'utf16le' : 'utf8',
|
|
162
|
+
start: utf16
|
|
163
|
+
? 2
|
|
164
|
+
: bytesRead >= 3 &&
|
|
165
|
+
prefix[0] === 0xef &&
|
|
166
|
+
prefix[1] === 0xbb &&
|
|
167
|
+
prefix[2] === 0xbf
|
|
168
|
+
? 3
|
|
169
|
+
: 0,
|
|
170
|
+
});
|
|
171
|
+
const rl = createInterface({ input: stream, crlfDelay: Infinity });
|
|
172
|
+
const lines: string[] = [];
|
|
173
|
+
let line = 0;
|
|
174
|
+
let hasMore = false;
|
|
175
|
+
for await (const value of rl) {
|
|
176
|
+
line += 1;
|
|
177
|
+
if (line >= offset && lines.length < limit) lines.push(`${line}\t${value}`);
|
|
178
|
+
else if (line >= offset + limit) {
|
|
179
|
+
hasMore = true;
|
|
180
|
+
rl.close();
|
|
181
|
+
stream.destroy();
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return { numbered: lines.join('\n'), totalKnown: line, hasMore };
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async function call(
|
|
189
|
+
input: ReadInput,
|
|
190
|
+
state?: FileReadState,
|
|
191
|
+
cwd?: string,
|
|
192
|
+
runtimeIdentity?: RuntimeIdentity,
|
|
193
|
+
): Promise<ToolResult> {
|
|
194
|
+
const offset = input.offset ?? 1;
|
|
195
|
+
const limit = input.limit ?? MAX_LINES_TO_READ;
|
|
196
|
+
const resolved = resolveToolPath(input.file_path, cwd);
|
|
197
|
+
if (!resolved.ok) return resolved;
|
|
198
|
+
const filePath = resolved.resolvedPath;
|
|
199
|
+
if (isBlockedDevicePath(filePath))
|
|
200
|
+
return { ok: false, error: `不允许读取设备文件:${filePath}` };
|
|
201
|
+
|
|
202
|
+
const info = await stat(filePath).catch((error: Error) => ({ error }));
|
|
203
|
+
if ('error' in info)
|
|
204
|
+
return {
|
|
205
|
+
ok: false,
|
|
206
|
+
error: `文件不存在或无法读取:${filePath}(${info.error.message})`,
|
|
207
|
+
};
|
|
208
|
+
if (!info.isFile())
|
|
209
|
+
return { ok: false, error: `${filePath} 不是文件;目录请用 Glob。` };
|
|
210
|
+
const ext = extname(filePath).toLowerCase();
|
|
211
|
+
|
|
212
|
+
if (ext === '.pdf') {
|
|
213
|
+
try {
|
|
214
|
+
const bytes = await readFile(filePath);
|
|
215
|
+
if (bytes.subarray(0, 5).toString() !== '%PDF-') {
|
|
216
|
+
return {
|
|
217
|
+
ok: false,
|
|
218
|
+
error: '文件扩展名是 PDF,但缺少有效 %PDF- 文件头',
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
const pdfjs = await import('pdfjs-dist/legacy/build/pdf.mjs');
|
|
222
|
+
const document = await pdfjs.getDocument({
|
|
223
|
+
data: new Uint8Array(bytes),
|
|
224
|
+
useSystemFonts: true,
|
|
225
|
+
}).promise;
|
|
226
|
+
try {
|
|
227
|
+
const requested = parsePdfPages(input.pages, document.numPages);
|
|
228
|
+
if (requested.length > 20)
|
|
229
|
+
return { ok: false, error: '一次最多读取 20 个 PDF 页面' };
|
|
230
|
+
const chunks: string[] = [];
|
|
231
|
+
for (const pageNumber of requested) {
|
|
232
|
+
const page = await document.getPage(pageNumber);
|
|
233
|
+
const text = await page.getTextContent();
|
|
234
|
+
chunks.push(
|
|
235
|
+
`## Page ${pageNumber}\n${text.items
|
|
236
|
+
.map((item) =>
|
|
237
|
+
'str' in item && typeof item.str === 'string' ? item.str : '',
|
|
238
|
+
)
|
|
239
|
+
.filter(Boolean)
|
|
240
|
+
.join(' ')}`,
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
const mode = input.pdf_mode ?? 'auto';
|
|
244
|
+
const sparse =
|
|
245
|
+
chunks.join('').replace(/\s/g, '').length < requested.length * 80;
|
|
246
|
+
const wantVisual =
|
|
247
|
+
mode === 'visual' || mode === 'both' || (mode === 'auto' && sparse);
|
|
248
|
+
const images = wantVisual
|
|
249
|
+
? await renderPdfPages(
|
|
250
|
+
document,
|
|
251
|
+
filePath,
|
|
252
|
+
requested.slice(0, 10),
|
|
253
|
+
runtimeIdentity,
|
|
254
|
+
)
|
|
255
|
+
: [];
|
|
256
|
+
recordRead(filePath, { contentHash: hashFileBytes(bytes) }, state);
|
|
257
|
+
const rawText =
|
|
258
|
+
mode === 'visual' ? '[visual-only mode]' : chunks.join('\n\n');
|
|
259
|
+
const text =
|
|
260
|
+
rawText.length > DEFAULT_MAX_RESULT_SIZE_CHARS
|
|
261
|
+
? `${rawText.slice(0, DEFAULT_MAX_RESULT_SIZE_CHARS)}\n... (PDF 文本输出已截断;请缩小 pages 范围继续读取)`
|
|
262
|
+
: rawText;
|
|
263
|
+
return {
|
|
264
|
+
ok: true,
|
|
265
|
+
content: `PDF ${document.numPages} pages; selected ${requested.join(', ')}.\n\n${text}${wantVisual && !images.length ? '\n\n视觉渲染不可用(Canvas 与 pdftoppm 均不可用);文本提取结果仍可用。' : ''}`,
|
|
266
|
+
metadata: await fileActivityMetadata(
|
|
267
|
+
filePath,
|
|
268
|
+
'read',
|
|
269
|
+
'not_run',
|
|
270
|
+
'source',
|
|
271
|
+
cwd,
|
|
272
|
+
),
|
|
273
|
+
...(images.length
|
|
274
|
+
? {
|
|
275
|
+
visionImages: images.map((source) => ({ source })),
|
|
276
|
+
visionNote:
|
|
277
|
+
'这是所选 PDF 页面的视觉渲染,请检查版式、图表和扫描内容。',
|
|
278
|
+
}
|
|
279
|
+
: {}),
|
|
280
|
+
};
|
|
281
|
+
} finally {
|
|
282
|
+
await document.destroy().catch(() => undefined);
|
|
283
|
+
}
|
|
284
|
+
} catch (error) {
|
|
285
|
+
const message = (error as Error).message;
|
|
286
|
+
return {
|
|
287
|
+
ok: false,
|
|
288
|
+
error: `PDF 解析失败${/password/i.test(message) ? '(文件可能已加密)' : ''}:${message}`,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (IMAGE_EXTENSIONS.has(ext)) {
|
|
294
|
+
if (info.size > MAX_IMAGE_BYTES)
|
|
295
|
+
return { ok: false, error: `图片超过 ${MAX_IMAGE_BYTES} 字节上限` };
|
|
296
|
+
const bytes = await readFile(filePath);
|
|
297
|
+
recordRead(filePath, { contentHash: hashFileBytes(bytes) }, state);
|
|
298
|
+
return {
|
|
299
|
+
ok: true,
|
|
300
|
+
content: `已读取图片:${filePath}(${info.size} 字节)。图像已附加供视觉模型检查;非视觉模型只能确认文件元数据,不能解读像素内容。`,
|
|
301
|
+
metadata: await fileActivityMetadata(
|
|
302
|
+
filePath,
|
|
303
|
+
'read',
|
|
304
|
+
'not_run',
|
|
305
|
+
'source',
|
|
306
|
+
cwd,
|
|
307
|
+
),
|
|
308
|
+
visionImages: [{ source: filePath }],
|
|
309
|
+
visionNote: '这是 Read 工具读取的本地图片,请直接检查图像内容。',
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (ext === '.ipynb') {
|
|
314
|
+
if (info.size > MAX_NOTEBOOK_BYTES)
|
|
315
|
+
return {
|
|
316
|
+
ok: false,
|
|
317
|
+
error: `Notebook 超过 ${MAX_NOTEBOOK_BYTES} 字节上限`,
|
|
318
|
+
};
|
|
319
|
+
try {
|
|
320
|
+
const snapshot = await readTextFile(filePath);
|
|
321
|
+
const rendered = renderNotebook(
|
|
322
|
+
snapshot.content,
|
|
323
|
+
offset,
|
|
324
|
+
Math.min(limit, 200),
|
|
325
|
+
);
|
|
326
|
+
let content = rendered.content;
|
|
327
|
+
let truncated = false;
|
|
328
|
+
if (content.length > DEFAULT_MAX_RESULT_SIZE_CHARS) {
|
|
329
|
+
content = `${content.slice(0, DEFAULT_MAX_RESULT_SIZE_CHARS)}\n\n... (Notebook 输出已截断)`;
|
|
330
|
+
truncated = true;
|
|
331
|
+
}
|
|
332
|
+
recordRead(
|
|
333
|
+
filePath,
|
|
334
|
+
{
|
|
335
|
+
offset,
|
|
336
|
+
limit,
|
|
337
|
+
partial: rendered.partial,
|
|
338
|
+
truncated,
|
|
339
|
+
...(!rendered.partial && !truncated
|
|
340
|
+
? { contentHash: hashFileBytes(snapshot.bytes) }
|
|
341
|
+
: {}),
|
|
342
|
+
},
|
|
343
|
+
state,
|
|
344
|
+
);
|
|
345
|
+
return {
|
|
346
|
+
ok: true,
|
|
347
|
+
content,
|
|
348
|
+
metadata: await fileActivityMetadata(
|
|
349
|
+
filePath,
|
|
350
|
+
'read',
|
|
351
|
+
'not_run',
|
|
352
|
+
'source',
|
|
353
|
+
cwd,
|
|
354
|
+
),
|
|
355
|
+
};
|
|
356
|
+
} catch (error) {
|
|
357
|
+
return {
|
|
358
|
+
ok: false,
|
|
359
|
+
error: `Notebook 解析失败:${(error as Error).message}`,
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (hasBinaryExtension(filePath)) {
|
|
365
|
+
return {
|
|
366
|
+
ok: false,
|
|
367
|
+
error: `不支持直接读取 ${ext || '该二进制格式'};PDF/Office 文件请使用对应 Skill。`,
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
if (info.size > MAX_FILE_SIZE_BYTES) {
|
|
371
|
+
return {
|
|
372
|
+
ok: false,
|
|
373
|
+
error: `文件超过 ${MAX_FILE_SIZE_BYTES} 字节硬上限。请用 Grep 定位,或用 Bash 做流式处理。`,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
try {
|
|
378
|
+
let content: string;
|
|
379
|
+
let totalLines: number;
|
|
380
|
+
let hasMore: boolean;
|
|
381
|
+
let completeBytes: Buffer | undefined;
|
|
382
|
+
if (info.size <= SMALL_TEXT_BYTES) {
|
|
383
|
+
const snapshot = await readTextFile(filePath);
|
|
384
|
+
completeBytes = snapshot.bytes;
|
|
385
|
+
const all =
|
|
386
|
+
snapshot.content.length === 0 ? [] : snapshot.content.split('\n');
|
|
387
|
+
const start = offset - 1;
|
|
388
|
+
const selected = all.slice(start, start + limit);
|
|
389
|
+
content = selected
|
|
390
|
+
.map((line, index) => `${start + index + 1}\t${line}`)
|
|
391
|
+
.join('\n');
|
|
392
|
+
totalLines = all.length;
|
|
393
|
+
hasMore = start + selected.length < all.length;
|
|
394
|
+
} else {
|
|
395
|
+
const streamed = await readStreamedText(filePath, offset, limit);
|
|
396
|
+
content = streamed.numbered;
|
|
397
|
+
totalLines = streamed.totalKnown;
|
|
398
|
+
hasMore = streamed.hasMore;
|
|
399
|
+
}
|
|
400
|
+
if (!content) content = '<file is empty>';
|
|
401
|
+
let truncated = false;
|
|
402
|
+
if (content.length > DEFAULT_MAX_RESULT_SIZE_CHARS) {
|
|
403
|
+
content = `${content.slice(0, DEFAULT_MAX_RESULT_SIZE_CHARS)}\n\n⚠️ 重要:Read 输出已截断;截断范围外仍有内容。需要整文件覆盖时必须分段完整读取,精确修改可继续使用 Edit。`;
|
|
404
|
+
truncated = true;
|
|
405
|
+
}
|
|
406
|
+
const partial = offset !== 1 || hasMore;
|
|
407
|
+
if (hasMore)
|
|
408
|
+
content += `\n\n... (还有更多内容;继续使用 offset=${offset + limit})`;
|
|
409
|
+
const reads = recordRead(
|
|
410
|
+
filePath,
|
|
411
|
+
{
|
|
412
|
+
offset,
|
|
413
|
+
limit,
|
|
414
|
+
partial,
|
|
415
|
+
truncated,
|
|
416
|
+
...(!partial && !truncated && completeBytes
|
|
417
|
+
? { contentHash: hashFileBytes(completeBytes) }
|
|
418
|
+
: {}),
|
|
419
|
+
},
|
|
420
|
+
state,
|
|
421
|
+
);
|
|
422
|
+
if (info.size > 100 * 1024 && offset === 1) {
|
|
423
|
+
content = `⚠️ 大文件:结果受行数和输出字符上限约束,请按需分段读取。\n\n${content}`;
|
|
424
|
+
}
|
|
425
|
+
if (reads >= 2)
|
|
426
|
+
content = `⚠️ 重复读取空转:该区间未变化,前一次 Read 结果仍然有效。\n\n${content}`;
|
|
427
|
+
return {
|
|
428
|
+
ok: true,
|
|
429
|
+
content,
|
|
430
|
+
metadata: await fileActivityMetadata(
|
|
431
|
+
filePath,
|
|
432
|
+
'read',
|
|
433
|
+
'not_run',
|
|
434
|
+
'source',
|
|
435
|
+
cwd,
|
|
436
|
+
),
|
|
437
|
+
};
|
|
438
|
+
} catch (error) {
|
|
439
|
+
return { ok: false, error: `读取失败:${(error as Error).message}` };
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
async function renderPdfPages(
|
|
444
|
+
document: Awaited<
|
|
445
|
+
ReturnType<
|
|
446
|
+
(typeof import('pdfjs-dist/legacy/build/pdf.mjs'))['getDocument']
|
|
447
|
+
>
|
|
448
|
+
>['promise'] extends Promise<infer T>
|
|
449
|
+
? T
|
|
450
|
+
: never,
|
|
451
|
+
filePath: string,
|
|
452
|
+
pages: number[],
|
|
453
|
+
identity?: RuntimeIdentity,
|
|
454
|
+
): Promise<string[]> {
|
|
455
|
+
const outputDir = join(sessionRuntimeDir(identity ?? {}), 'outputs');
|
|
456
|
+
const outputPrefix = `pdf_${randomUUID()}`;
|
|
457
|
+
await mkdir(outputDir, { recursive: true, mode: 0o700 });
|
|
458
|
+
const images: string[] = [];
|
|
459
|
+
const dynamicImport = new Function(
|
|
460
|
+
'specifier',
|
|
461
|
+
'return import(specifier)',
|
|
462
|
+
) as (specifier: string) => Promise<{
|
|
463
|
+
createCanvas?: (
|
|
464
|
+
width: number,
|
|
465
|
+
height: number,
|
|
466
|
+
) => {
|
|
467
|
+
getContext(type: '2d'): unknown;
|
|
468
|
+
toBuffer(type: 'image/png'): Buffer;
|
|
469
|
+
};
|
|
470
|
+
}>;
|
|
471
|
+
let createCanvas: Awaited<ReturnType<typeof dynamicImport>>['createCanvas'];
|
|
472
|
+
try {
|
|
473
|
+
({ createCanvas } = await dynamicImport('@napi-rs/canvas'));
|
|
474
|
+
} catch {
|
|
475
|
+
/* optional adapter */
|
|
476
|
+
}
|
|
477
|
+
if (createCanvas) {
|
|
478
|
+
try {
|
|
479
|
+
for (const pageNumber of pages) {
|
|
480
|
+
const page = await document.getPage(pageNumber);
|
|
481
|
+
const viewport = page.getViewport({ scale: 2 });
|
|
482
|
+
const canvas = createCanvas(
|
|
483
|
+
Math.ceil(viewport.width),
|
|
484
|
+
Math.ceil(viewport.height),
|
|
485
|
+
);
|
|
486
|
+
await page.render({
|
|
487
|
+
canvasContext: canvas.getContext('2d') as never,
|
|
488
|
+
viewport,
|
|
489
|
+
}).promise;
|
|
490
|
+
const target = join(
|
|
491
|
+
outputDir,
|
|
492
|
+
`${outputPrefix}-page-${pageNumber}.png`,
|
|
493
|
+
);
|
|
494
|
+
await writeFile(target, canvas.toBuffer('image/png'), { mode: 0o600 });
|
|
495
|
+
images.push(target);
|
|
496
|
+
}
|
|
497
|
+
void pruneRuntimeOutputs();
|
|
498
|
+
return images;
|
|
499
|
+
} catch {
|
|
500
|
+
images.length = 0;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
for (const pageNumber of pages) {
|
|
504
|
+
const prefix = join(outputDir, `${outputPrefix}-page-${pageNumber}`);
|
|
505
|
+
try {
|
|
506
|
+
await promisify(execFile)(
|
|
507
|
+
'pdftoppm',
|
|
508
|
+
[
|
|
509
|
+
'-f',
|
|
510
|
+
String(pageNumber),
|
|
511
|
+
'-l',
|
|
512
|
+
String(pageNumber),
|
|
513
|
+
'-singlefile',
|
|
514
|
+
'-png',
|
|
515
|
+
'-r',
|
|
516
|
+
'144',
|
|
517
|
+
filePath,
|
|
518
|
+
prefix,
|
|
519
|
+
],
|
|
520
|
+
{ maxBuffer: 1024 * 1024 },
|
|
521
|
+
);
|
|
522
|
+
images.push(`${prefix}.png`);
|
|
523
|
+
} catch {
|
|
524
|
+
break;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
void pruneRuntimeOutputs();
|
|
528
|
+
return images;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
function parsePdfPages(spec: string | undefined, total: number): number[] {
|
|
532
|
+
if (!spec)
|
|
533
|
+
return Array.from({ length: Math.min(total, 20) }, (_, index) => index + 1);
|
|
534
|
+
const pages = new Set<number>();
|
|
535
|
+
for (const part of spec.split(',')) {
|
|
536
|
+
const [first, last] = part.split('-').map(Number);
|
|
537
|
+
for (let page = first!; page <= (last ?? first!); page += 1) {
|
|
538
|
+
if (page < 1 || page > total)
|
|
539
|
+
throw new Error(`PDF 页码超出范围:${page}(共 ${total} 页)`);
|
|
540
|
+
pages.add(page);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
return [...pages].sort((left, right) => left - right);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
export const readTool: Tool<ReadInput> = {
|
|
547
|
+
name: 'Read',
|
|
548
|
+
description,
|
|
549
|
+
inputSchema,
|
|
550
|
+
parameters: toToolParameters(inputSchema),
|
|
551
|
+
isReadOnly: true,
|
|
552
|
+
isConcurrencySafe: true,
|
|
553
|
+
maxResultSizeChars: DEFAULT_MAX_RESULT_SIZE_CHARS,
|
|
554
|
+
interruptBehavior: () => 'cancel',
|
|
555
|
+
call: (input) => call(input),
|
|
556
|
+
callWithContext: (input, _signal, context: ToolCallContext) =>
|
|
557
|
+
call(input, context.sessionState?.fileReads, context.cwd, context),
|
|
558
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { createTwoFilesPatch, diffLines } from 'diff';
|
|
3
|
+
const MAX_BYTES = 5 * 1024 * 1024;
|
|
4
|
+
const MAX_LINES = 200_000;
|
|
5
|
+
const MAX_DIFF_CHARS = 16_000;
|
|
6
|
+
function hash(value) {
|
|
7
|
+
return createHash('sha256').update(value).digest('hex');
|
|
8
|
+
}
|
|
9
|
+
export function buildPatchSummary(before, after, label) {
|
|
10
|
+
const beforeHash = hash(before);
|
|
11
|
+
const afterHash = hash(after);
|
|
12
|
+
const totalBytes = Buffer.byteLength(before) + Buffer.byteLength(after);
|
|
13
|
+
const totalLines = (before.match(/\n/g)?.length ?? 0) + (after.match(/\n/g)?.length ?? 0) + 2;
|
|
14
|
+
if (totalBytes > MAX_BYTES || totalLines > MAX_LINES) {
|
|
15
|
+
return {
|
|
16
|
+
beforeHash,
|
|
17
|
+
afterHash,
|
|
18
|
+
additions: 0,
|
|
19
|
+
deletions: 0,
|
|
20
|
+
truncated: true,
|
|
21
|
+
omittedReason: 'too_large',
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const changes = diffLines(before, after);
|
|
25
|
+
const additions = changes
|
|
26
|
+
.filter((change) => change.added)
|
|
27
|
+
.reduce((sum, change) => sum + (change.count ?? 0), 0);
|
|
28
|
+
const deletions = changes
|
|
29
|
+
.filter((change) => change.removed)
|
|
30
|
+
.reduce((sum, change) => sum + (change.count ?? 0), 0);
|
|
31
|
+
let unifiedDiff = createTwoFilesPatch(`a/${label}`, `b/${label}`, before, after, undefined, undefined, { context: 3 });
|
|
32
|
+
const truncated = unifiedDiff.length > MAX_DIFF_CHARS;
|
|
33
|
+
if (truncated) {
|
|
34
|
+
unifiedDiff = `${unifiedDiff.slice(0, MAX_DIFF_CHARS)}\n... (diff preview truncated)`;
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
unifiedDiff,
|
|
38
|
+
beforeHash,
|
|
39
|
+
afterHash,
|
|
40
|
+
additions,
|
|
41
|
+
deletions,
|
|
42
|
+
truncated,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { createTwoFilesPatch, diffLines } from 'diff';
|
|
3
|
+
|
|
4
|
+
import type { FilePatchSummary } from '../../types.js';
|
|
5
|
+
|
|
6
|
+
const MAX_BYTES = 5 * 1024 * 1024;
|
|
7
|
+
const MAX_LINES = 200_000;
|
|
8
|
+
const MAX_DIFF_CHARS = 16_000;
|
|
9
|
+
|
|
10
|
+
function hash(value: string): string {
|
|
11
|
+
return createHash('sha256').update(value).digest('hex');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function buildPatchSummary(
|
|
15
|
+
before: string,
|
|
16
|
+
after: string,
|
|
17
|
+
label: string,
|
|
18
|
+
): FilePatchSummary {
|
|
19
|
+
const beforeHash = hash(before);
|
|
20
|
+
const afterHash = hash(after);
|
|
21
|
+
const totalBytes = Buffer.byteLength(before) + Buffer.byteLength(after);
|
|
22
|
+
const totalLines =
|
|
23
|
+
(before.match(/\n/g)?.length ?? 0) + (after.match(/\n/g)?.length ?? 0) + 2;
|
|
24
|
+
if (totalBytes > MAX_BYTES || totalLines > MAX_LINES) {
|
|
25
|
+
return {
|
|
26
|
+
beforeHash,
|
|
27
|
+
afterHash,
|
|
28
|
+
additions: 0,
|
|
29
|
+
deletions: 0,
|
|
30
|
+
truncated: true,
|
|
31
|
+
omittedReason: 'too_large',
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const changes = diffLines(before, after);
|
|
36
|
+
const additions = changes
|
|
37
|
+
.filter((change) => change.added)
|
|
38
|
+
.reduce((sum, change) => sum + (change.count ?? 0), 0);
|
|
39
|
+
const deletions = changes
|
|
40
|
+
.filter((change) => change.removed)
|
|
41
|
+
.reduce((sum, change) => sum + (change.count ?? 0), 0);
|
|
42
|
+
let unifiedDiff = createTwoFilesPatch(
|
|
43
|
+
`a/${label}`,
|
|
44
|
+
`b/${label}`,
|
|
45
|
+
before,
|
|
46
|
+
after,
|
|
47
|
+
undefined,
|
|
48
|
+
undefined,
|
|
49
|
+
{ context: 3 },
|
|
50
|
+
);
|
|
51
|
+
const truncated = unifiedDiff.length > MAX_DIFF_CHARS;
|
|
52
|
+
if (truncated) {
|
|
53
|
+
unifiedDiff = `${unifiedDiff.slice(0, MAX_DIFF_CHARS)}\n... (diff preview truncated)`;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
unifiedDiff,
|
|
57
|
+
beforeHash,
|
|
58
|
+
afterHash,
|
|
59
|
+
additions,
|
|
60
|
+
deletions,
|
|
61
|
+
truncated,
|
|
62
|
+
};
|
|
63
|
+
}
|