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,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 配置里每一个「数字输入」的边界与取值语义——**唯一真值**。
|
|
3
|
+
*
|
|
4
|
+
* 为什么要有这个文件(真实事故):同一个数字此前在**三层各写一份**互不相同的边界——
|
|
5
|
+
* 前端 input 的 `min/max/step`、写入时 `applyConfigPatch` 的 clamp、读回时
|
|
6
|
+
* `parseAdvisor/parseSubagents` 的 `boundedNumber`。三份一旦不一致,用户在设置页输入
|
|
7
|
+
* 一个「前端允许、后端不允许」的值,回车/失焦后会**静默变回原值**:前端没报错(它认为
|
|
8
|
+
* 合法),后端也没报错(它认为自己只是在纠偏),中间没有任何提示。顾问「输入预算」被
|
|
9
|
+
* 死钉在 128000 就是这么来的——用户的顾问模型是 90 万上下文窗口,却怎么改都跳回 12.8 万。
|
|
10
|
+
*
|
|
11
|
+
* 因此:**边界只准在这里声明**,minimal-agent 的读/写两层与 minimal-desktop 的设置页
|
|
12
|
+
* 全部 import 这里。前端 clamp 后再提交,后端再 clamp 一次兜底——两次 clamp 结果必然
|
|
13
|
+
* 相同,用户看到的值就是存下来的值。
|
|
14
|
+
*
|
|
15
|
+
* 单位约定:这里的边界一律用**存储单位**(毫秒 / 比例 / 绝对个数)。UI 若按秒/分钟/
|
|
16
|
+
* 百分比展示,自己换算(见 minimal-desktop `NumberInput`),不在这里再开一份显示单位的
|
|
17
|
+
* 边界,否则又回到多份真值。
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** 一个数字字段的取值边界。`step` 只影响 UI 的上下箭头步进,不参与合法性判断。 */
|
|
21
|
+
export interface NumericLimit {
|
|
22
|
+
min: number;
|
|
23
|
+
max: number;
|
|
24
|
+
step: number;
|
|
25
|
+
/** 'integer' = 只能是整数总量(token / 毫秒 / 轮数 / 个数);'ratio' = 比例,保留 4 位小数(= 百分比 2 位)。 */
|
|
26
|
+
kind: 'integer' | 'ratio';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const CONFIG_LIMITS = {
|
|
30
|
+
/** 顾问单次咨询喂进去的输入 token 上限。上界给到 200 万是为了容纳百万级上下文模型;
|
|
31
|
+
* 真正生效值还会再被「所选顾问模型的 contextWindow」二次收窄(见 advisor.ts)。 */
|
|
32
|
+
advisorInputTokenBudget: { min: 1_000, max: 2_000_000, step: 1_000, kind: 'integer' },
|
|
33
|
+
/** 顾问单次咨询的最长等待(毫秒)。重思考模型 + 大上下文可以跑很久,上界给到 10 分钟。 */
|
|
34
|
+
advisorTimeoutMs: { min: 5_000, max: 600_000, step: 5_000, kind: 'integer' },
|
|
35
|
+
|
|
36
|
+
/** 单个回合内最多派生几个子任务。 */
|
|
37
|
+
subagentMaxCallsPerTurn: { min: 1, max: 50, step: 1, kind: 'integer' },
|
|
38
|
+
/** 子任务并发上限。 */
|
|
39
|
+
subagentMaxConcurrent: { min: 1, max: 20, step: 1, kind: 'integer' },
|
|
40
|
+
/** 单个子任务的总时长兜底(毫秒),上界 2 小时。 */
|
|
41
|
+
subagentTimeoutMs: { min: 60_000, max: 7_200_000, step: 60_000, kind: 'integer' },
|
|
42
|
+
/** explore(只读调研)子任务的轮数上限。 */
|
|
43
|
+
subagentExploreMaxTurns: { min: 5, max: 500, step: 5, kind: 'integer' },
|
|
44
|
+
/** general(读写执行)子任务的轮数上限。 */
|
|
45
|
+
subagentGeneralMaxTurns: { min: 10, max: 1_000, step: 10, kind: 'integer' },
|
|
46
|
+
|
|
47
|
+
/** 电脑操作每帧画面的像素预算。 */
|
|
48
|
+
computerUseMaxImagePixels: { min: 100_000, max: 10_000_000, step: 100_000, kind: 'integer' },
|
|
49
|
+
|
|
50
|
+
/** 自动压缩触发阈值,占 contextWindow 的比例(0,1]。UI 按百分比展示,保留 2 位小数。 */
|
|
51
|
+
compactRatio: { min: 0.01, max: 1, step: 0.01, kind: 'ratio' },
|
|
52
|
+
|
|
53
|
+
/** 模型条目的上下文窗口。 */
|
|
54
|
+
modelContextWindow: { min: 1_000, max: 20_000_000, step: 1_000, kind: 'integer' },
|
|
55
|
+
/** 模型条目的单次输出上限(可留空 = 用公式推荐值,故 UI 允许空串,这里只约束填了值的情况)。 */
|
|
56
|
+
modelMaxTokens: { min: 256, max: 1_000_000, step: 256, kind: 'integer' },
|
|
57
|
+
} as const satisfies Record<string, NumericLimit>;
|
|
58
|
+
|
|
59
|
+
export type ConfigLimitKey = keyof typeof CONFIG_LIMITS;
|
|
60
|
+
|
|
61
|
+
/** 比例类字段保留的小数位(4 位比例 = 2 位百分比)。 */
|
|
62
|
+
const RATIO_DECIMALS = 4;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 把任意输入规整成该字段合法的存储值:非法/空 → fallback;整数类四舍五入;
|
|
66
|
+
* 比例类保留 4 位小数(否则 `0.85` 会被步进累加成 `0.8500000000000001` 存进 config.json)。
|
|
67
|
+
* 最后按 min/max 收口。
|
|
68
|
+
*/
|
|
69
|
+
export function normalizeLimited(value: unknown, limit: NumericLimit, fallback: number): number {
|
|
70
|
+
const raw = typeof value === 'number' && Number.isFinite(value) ? value : fallback;
|
|
71
|
+
const rounded = limit.kind === 'integer'
|
|
72
|
+
? Math.round(raw)
|
|
73
|
+
: Number(raw.toFixed(RATIO_DECIMALS));
|
|
74
|
+
return Math.min(limit.max, Math.max(limit.min, rounded));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** 判断一个值是否已经落在合法范围内(UI 用来决定要不要提示「已自动调整」)。 */
|
|
78
|
+
export function withinLimit(value: number, limit: NumericLimit): boolean {
|
|
79
|
+
return Number.isFinite(value) && value >= limit.min && value <= limit.max;
|
|
80
|
+
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================
|
|
3
|
+
* config.ts —— 全局配置加载(从 .env 读取)
|
|
4
|
+
* ------------------------------------------------------------
|
|
5
|
+
* 只从环境变量读取,集中管理所有配置。
|
|
6
|
+
*
|
|
7
|
+
* 必需的环境变量:
|
|
8
|
+
* MINIMAL_AGENT_BASE_URL - API 完整端点地址,如 https://api.minimax.chat/v1/chat/completions
|
|
9
|
+
* MINIMAL_AGENT_API_KEY - API key
|
|
10
|
+
* MINIMAL_AGENT_MODEL - 模型名,如 MiniMax-M2.7
|
|
11
|
+
*
|
|
12
|
+
* 可选的环境变量:
|
|
13
|
+
* MINIMAL_AGENT_PROVIDER - 友好名称,默认 "env"
|
|
14
|
+
* MINIMAL_AGENT_CONTEXT_WINDOW - 上下文窗口,默认 128000
|
|
15
|
+
* MINIMAL_AGENT_MAX_TOKENS - 单次输出 token 上限,默认 16384(弱 provider 默认偏小会截断长输出)
|
|
16
|
+
* ============================================================
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { configService } from './config/configService.js';
|
|
20
|
+
import type { Provider } from './types.js';
|
|
21
|
+
|
|
22
|
+
const DEFAULT_CONTEXT_WINDOW = 128_000;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 单次输出 token 上限的默认值。
|
|
26
|
+
*
|
|
27
|
+
* 16384:实测火山豆包接受、足够一次性写完整篇 PLAN.md(实测 ~6.5k token),又远低于
|
|
28
|
+
* 豆包 131072 的宽容上限。不发 max_tokens 的话豆包默认仅 4096,长输出会被硬截断。
|
|
29
|
+
* 个别 provider 若拒绝该值,client 会自动去掉 max_tokens 重发降级。
|
|
30
|
+
*/
|
|
31
|
+
const DEFAULT_MAX_TOKENS = 16_384;
|
|
32
|
+
|
|
33
|
+
/** 解析正整数环境变量(NaN/≤0 → undefined,由调用方决定默认值)。 */
|
|
34
|
+
function parsePositiveInt(raw: string | undefined): number | undefined {
|
|
35
|
+
if (!raw) return undefined;
|
|
36
|
+
const n = parseInt(raw, 10);
|
|
37
|
+
return !Number.isNaN(n) && n > 0 ? n : undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 解析压缩阈值比例(0~1 小数)。
|
|
42
|
+
* 非法值(NaN、0、负数、>1)返回 undefined,由调用方决定是否用默认值 0.85。
|
|
43
|
+
*/
|
|
44
|
+
function parseCompactRatio(raw: string | undefined): number | undefined {
|
|
45
|
+
if (!raw) return undefined;
|
|
46
|
+
const n = parseFloat(raw);
|
|
47
|
+
if (Number.isNaN(n) || n <= 0 || n > 1) return undefined;
|
|
48
|
+
return n;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 加载 Provider 配置(从环境变量)。
|
|
53
|
+
* 缺少必需变量时抛出明确错误。
|
|
54
|
+
*/
|
|
55
|
+
export async function loadProvider(): Promise<Provider> {
|
|
56
|
+
const baseURL = process.env.MINIMAL_AGENT_BASE_URL;
|
|
57
|
+
const apiKey = process.env.MINIMAL_AGENT_API_KEY;
|
|
58
|
+
const model = process.env.MINIMAL_AGENT_MODEL;
|
|
59
|
+
|
|
60
|
+
if (!baseURL || !apiKey || !model) {
|
|
61
|
+
const missing = [];
|
|
62
|
+
if (!baseURL) missing.push('MINIMAL_AGENT_BASE_URL');
|
|
63
|
+
if (!apiKey) missing.push('MINIMAL_AGENT_API_KEY');
|
|
64
|
+
if (!model) missing.push('MINIMAL_AGENT_MODEL');
|
|
65
|
+
|
|
66
|
+
throw new Error(
|
|
67
|
+
`缺少必需的环境变量:${missing.join(', ')}\n\n` +
|
|
68
|
+
`请在 .env 中配置:\n` +
|
|
69
|
+
` MINIMAL_AGENT_BASE_URL=https://api.example.com/v1\n` +
|
|
70
|
+
` MINIMAL_AGENT_API_KEY=your-api-key\n` +
|
|
71
|
+
` MINIMAL_AGENT_MODEL=your-model\n\n` +
|
|
72
|
+
`参考 .env.example`,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const contextWindowRaw = process.env.MINIMAL_AGENT_CONTEXT_WINDOW;
|
|
77
|
+
let contextWindow = DEFAULT_CONTEXT_WINDOW;
|
|
78
|
+
if (contextWindowRaw) {
|
|
79
|
+
const n = parseInt(contextWindowRaw, 10);
|
|
80
|
+
if (!Number.isNaN(n) && n > 0) {
|
|
81
|
+
contextWindow = n;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const compactRatio = parseCompactRatio(process.env.MINIMAL_AGENT_COMPACT_RATIO);
|
|
86
|
+
|
|
87
|
+
const maxTokens =
|
|
88
|
+
parsePositiveInt(process.env.MINIMAL_AGENT_MAX_TOKENS) ?? DEFAULT_MAX_TOKENS;
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
name: process.env.MINIMAL_AGENT_PROVIDER ?? 'env',
|
|
92
|
+
baseURL,
|
|
93
|
+
apiKey,
|
|
94
|
+
model,
|
|
95
|
+
contextWindow,
|
|
96
|
+
maxTokens,
|
|
97
|
+
...(compactRatio !== undefined ? { compactRatio } : {}),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Shared CLI/Desktop configuration: JSON first, environment only as bootstrap or env mode. */
|
|
102
|
+
export async function loadProviderLayered(): Promise<Provider | null> {
|
|
103
|
+
return configService.provider();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** @deprecated Compatibility hook. Trusted tools now read ConfigService directly. */
|
|
107
|
+
export async function applyToolKeysToEnv(): Promise<void> {
|
|
108
|
+
await configService.reload();
|
|
109
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { homedir } from 'node:os';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
/** 测试和嵌入宿主可覆盖 home 根,生产默认使用系统主目录。 */
|
|
5
|
+
export function agentHomeBase(): string {
|
|
6
|
+
return process.env.MINIMAL_AGENT_HOME || homedir();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function agentStateDir(): string {
|
|
10
|
+
return join(agentHomeBase(), '.minimal-agent');
|
|
11
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================
|
|
3
|
+
* src/context/archive.ts —— /new 自动归档历史对话
|
|
4
|
+
* ------------------------------------------------------------
|
|
5
|
+
* 做的事:
|
|
6
|
+
* `/new` 清空上下文前,先把当前对话历史落盘到 archive 目录,
|
|
7
|
+
* 供后续 `/list-archive`、`/restore <id>` 查看 / 找回。
|
|
8
|
+
*
|
|
9
|
+
* 文件路径:
|
|
10
|
+
* <MINIMAL_AGENT_HOME ?? ~>/.minimal-agent/archive/<cwd-hash>/<ISO-timestamp>.json
|
|
11
|
+
* - cwd-hash:当前工作目录 sha1 前 12 位(避免不同项目 archive 串台)
|
|
12
|
+
* - timestamp:new Date().toISOString().replace(/:/g, '-')(Windows 不允许冒号)
|
|
13
|
+
*
|
|
14
|
+
* 存储格式:
|
|
15
|
+
* { updatedAt: number; messages: Message[] }
|
|
16
|
+
*
|
|
17
|
+
* 抉择:
|
|
18
|
+
* - 仅含 system 消息(空对话)跳过写入,返回空字符串
|
|
19
|
+
* - 失败由调用方 try/catch 吞掉,本模块不做 stderr(保持纯函数语义)
|
|
20
|
+
* - 损坏文件在 listArchives 中静默 skip
|
|
21
|
+
* - 通过 MINIMAL_AGENT_HOME 环境变量让测试切到临时目录,避免污染真实 ~/.minimal-agent
|
|
22
|
+
* ============================================================
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { createHash } from 'node:crypto';
|
|
26
|
+
import { mkdir, readFile, readdir, stat, writeFile } from 'node:fs/promises';
|
|
27
|
+
import { homedir } from 'node:os';
|
|
28
|
+
import { join } from 'node:path';
|
|
29
|
+
|
|
30
|
+
import { getWorkingDir } from '../bootstrap/workingDir.js';
|
|
31
|
+
import { contentToPlainText } from '../multimodal.js';
|
|
32
|
+
import type { Message } from '../types.js';
|
|
33
|
+
|
|
34
|
+
/** 一条归档摘要,列表展示用 */
|
|
35
|
+
export interface ArchiveEntry {
|
|
36
|
+
/** archive id(ISO timestamp 字符串,冒号已替换为 - 以兼容 Windows) */
|
|
37
|
+
id: string;
|
|
38
|
+
/** 文件 mtime(unix millis),用于排序 */
|
|
39
|
+
updatedAt: number;
|
|
40
|
+
/** messages 数量(含 system) */
|
|
41
|
+
msgCount: number;
|
|
42
|
+
/** 首条 user message 前 80 字符(换行 / 多空白合并为单空格) */
|
|
43
|
+
firstUserPreview: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** 解析 archive 根目录,支持 MINIMAL_AGENT_HOME 测试覆盖 */
|
|
47
|
+
function agentHome(): string {
|
|
48
|
+
return process.env.MINIMAL_AGENT_HOME ?? homedir();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function archiveDir(cwd: string): string {
|
|
52
|
+
const hash = createHash('sha1').update(cwd).digest('hex').slice(0, 12);
|
|
53
|
+
return join(agentHome(), '.minimal-agent', 'archive', hash);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 归档当前 messages 到 archive 目录。
|
|
58
|
+
*
|
|
59
|
+
* @returns archive id(成功)或空字符串(无内容跳过)
|
|
60
|
+
*
|
|
61
|
+
* 行为:
|
|
62
|
+
* - messages 为空 / 仅含 system role → 跳过,返回 ''
|
|
63
|
+
* - 写入失败抛错(调用方负责吞)
|
|
64
|
+
*/
|
|
65
|
+
export async function archiveCurrent(messages: Message[]): Promise<string> {
|
|
66
|
+
const nonSystem = messages.filter((m) => m.role !== 'system');
|
|
67
|
+
if (nonSystem.length === 0) return '';
|
|
68
|
+
|
|
69
|
+
const dir = archiveDir(getWorkingDir());
|
|
70
|
+
await mkdir(dir, { recursive: true });
|
|
71
|
+
|
|
72
|
+
const id = new Date().toISOString().replace(/:/g, '-');
|
|
73
|
+
const path = join(dir, `${id}.json`);
|
|
74
|
+
// 写入完整 messages(含 system)—— restoreArchive 期待原样还原以做 roundtrip
|
|
75
|
+
// 跳过判定单独用 nonSystem(空对话不归档)—— 这是有意分层的:
|
|
76
|
+
// skip 判定 = "有没有用户/助手消息可归档"
|
|
77
|
+
// write 内容 = "保留完整上下文供 /restore 还原"
|
|
78
|
+
await writeFile(
|
|
79
|
+
path,
|
|
80
|
+
JSON.stringify({ updatedAt: Date.now(), messages }),
|
|
81
|
+
'utf8',
|
|
82
|
+
);
|
|
83
|
+
return id;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 列出当前 cwd 下所有归档,最新优先(按文件 mtime 倒序)。
|
|
88
|
+
*
|
|
89
|
+
* 损坏 / 无法解析的文件会被静默跳过——不影响其它条目展示。
|
|
90
|
+
* 目录不存在视作空列表。
|
|
91
|
+
*/
|
|
92
|
+
export async function listArchives(): Promise<ArchiveEntry[]> {
|
|
93
|
+
const dir = archiveDir(getWorkingDir());
|
|
94
|
+
let names: string[];
|
|
95
|
+
try {
|
|
96
|
+
names = await readdir(dir);
|
|
97
|
+
} catch {
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const entries: ArchiveEntry[] = [];
|
|
102
|
+
for (const name of names) {
|
|
103
|
+
if (!name.endsWith('.json')) continue;
|
|
104
|
+
const id = name.slice(0, -'.json'.length);
|
|
105
|
+
const fpath = join(dir, name);
|
|
106
|
+
try {
|
|
107
|
+
const st = await stat(fpath);
|
|
108
|
+
const raw = await readFile(fpath, 'utf8');
|
|
109
|
+
const data = JSON.parse(raw) as { messages: Message[] };
|
|
110
|
+
if (!Array.isArray(data.messages)) continue;
|
|
111
|
+
const firstUser = data.messages.find((m) => m.role === 'user');
|
|
112
|
+
const preview =
|
|
113
|
+
firstUser
|
|
114
|
+
? contentToPlainText(firstUser.content).replace(/\s+/g, ' ').slice(0, 80)
|
|
115
|
+
: '';
|
|
116
|
+
entries.push({
|
|
117
|
+
id,
|
|
118
|
+
updatedAt: st.mtimeMs,
|
|
119
|
+
msgCount: data.messages.length,
|
|
120
|
+
firstUserPreview: preview,
|
|
121
|
+
});
|
|
122
|
+
} catch {
|
|
123
|
+
// 损坏文件静默 skip
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return entries.sort((a, b) => b.updatedAt - a.updatedAt);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 按 id 恢复归档。
|
|
131
|
+
*
|
|
132
|
+
* @returns messages 数组(成功);找不到 / 损坏 / messages 非数组 → null
|
|
133
|
+
*/
|
|
134
|
+
export async function restoreArchive(id: string): Promise<Message[] | null> {
|
|
135
|
+
const dir = archiveDir(getWorkingDir());
|
|
136
|
+
const path = join(dir, `${id}.json`);
|
|
137
|
+
try {
|
|
138
|
+
const raw = await readFile(path, 'utf8');
|
|
139
|
+
const data = JSON.parse(raw) as { messages: Message[] };
|
|
140
|
+
return Array.isArray(data.messages) ? data.messages : null;
|
|
141
|
+
} catch {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { getCompactThreshold } from './compact.js';
|
|
2
|
+
import { countMessagesTokens, countTextTokens, estimateToolsTokens } from './tokenCounter.js';
|
|
3
|
+
import { budgetClassForToolName } from '../tools/capabilities.js';
|
|
4
|
+
export function buildContextBudgetPlan(input) {
|
|
5
|
+
const inputLimit = getCompactThreshold(input.provider);
|
|
6
|
+
const historyTokens = countMessagesTokens(input.history);
|
|
7
|
+
const toolTokens = estimateToolsTokens(input.tools);
|
|
8
|
+
const transientTokens = countTextTokens(input.transientContext ?? '');
|
|
9
|
+
const multimodalTokens = input.multimodalTokens ?? 0;
|
|
10
|
+
const totalInputTokens = historyTokens + toolTokens + transientTokens + multimodalTokens;
|
|
11
|
+
return {
|
|
12
|
+
contextWindow: input.provider.contextWindow,
|
|
13
|
+
inputLimit,
|
|
14
|
+
reservedOutput: Math.max(0, input.provider.contextWindow - inputLimit),
|
|
15
|
+
historyTokens,
|
|
16
|
+
toolTokens,
|
|
17
|
+
transientTokens,
|
|
18
|
+
multimodalTokens,
|
|
19
|
+
totalInputTokens,
|
|
20
|
+
overBudget: totalInputTokens > inputLimit,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const AUXILIARY_REMOVAL_ORDER = ['Advisor', 'Agent'];
|
|
24
|
+
/**
|
|
25
|
+
* Last-resort schema reduction. Normal requests keep the full catalog; this is
|
|
26
|
+
* used only after history compaction still cannot fit the provider window.
|
|
27
|
+
*/
|
|
28
|
+
export function fitToolsForEmergency(input) {
|
|
29
|
+
let tools = [...input.tools];
|
|
30
|
+
let plan = buildContextBudgetPlan({ ...input, tools });
|
|
31
|
+
if (!plan.overBudget)
|
|
32
|
+
return { tools, removedNames: [], plan };
|
|
33
|
+
const required = input.requiredNames ?? new Set();
|
|
34
|
+
const auxiliaryRank = new Map(AUXILIARY_REMOVAL_ORDER.map((name, index) => [name, index]));
|
|
35
|
+
const candidates = tools
|
|
36
|
+
.filter((tool) => !required.has(tool.name) && budgetClassForToolName(tool.name) === 'auxiliary')
|
|
37
|
+
.sort((a, b) => {
|
|
38
|
+
const rankA = auxiliaryRank.get(a.name);
|
|
39
|
+
const rankB = auxiliaryRank.get(b.name);
|
|
40
|
+
if (rankA !== undefined || rankB !== undefined) {
|
|
41
|
+
return (rankA ?? Number.MAX_SAFE_INTEGER) - (rankB ?? Number.MAX_SAFE_INTEGER);
|
|
42
|
+
}
|
|
43
|
+
return estimateToolsTokens([b]) - estimateToolsTokens([a]);
|
|
44
|
+
});
|
|
45
|
+
const removedNames = [];
|
|
46
|
+
for (const candidate of candidates) {
|
|
47
|
+
if (!plan.overBudget || tools.length <= 1)
|
|
48
|
+
break;
|
|
49
|
+
tools = tools.filter((tool) => tool.name !== candidate.name);
|
|
50
|
+
removedNames.push(candidate.name);
|
|
51
|
+
plan = buildContextBudgetPlan({ ...input, tools });
|
|
52
|
+
}
|
|
53
|
+
return { tools, removedNames, plan };
|
|
54
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Message, Provider, Tool } from '../types.js';
|
|
2
|
+
import { getCompactThreshold } from './compact.js';
|
|
3
|
+
import { countMessagesTokens, countTextTokens, estimateToolsTokens } from './tokenCounter.js';
|
|
4
|
+
import { budgetClassForToolName } from '../tools/capabilities.js';
|
|
5
|
+
|
|
6
|
+
export interface ContextBudgetPlan {
|
|
7
|
+
contextWindow: number;
|
|
8
|
+
inputLimit: number;
|
|
9
|
+
reservedOutput: number;
|
|
10
|
+
historyTokens: number;
|
|
11
|
+
toolTokens: number;
|
|
12
|
+
transientTokens: number;
|
|
13
|
+
multimodalTokens: number;
|
|
14
|
+
totalInputTokens: number;
|
|
15
|
+
overBudget: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function buildContextBudgetPlan(input: {
|
|
19
|
+
provider: Provider;
|
|
20
|
+
history: readonly Message[];
|
|
21
|
+
tools: readonly Tool[];
|
|
22
|
+
transientContext?: string;
|
|
23
|
+
multimodalTokens?: number;
|
|
24
|
+
}): ContextBudgetPlan {
|
|
25
|
+
const inputLimit = getCompactThreshold(input.provider);
|
|
26
|
+
const historyTokens = countMessagesTokens(input.history as Message[]);
|
|
27
|
+
const toolTokens = estimateToolsTokens(input.tools as Tool[]);
|
|
28
|
+
const transientTokens = countTextTokens(input.transientContext ?? '');
|
|
29
|
+
const multimodalTokens = input.multimodalTokens ?? 0;
|
|
30
|
+
const totalInputTokens = historyTokens + toolTokens + transientTokens + multimodalTokens;
|
|
31
|
+
return {
|
|
32
|
+
contextWindow: input.provider.contextWindow,
|
|
33
|
+
inputLimit,
|
|
34
|
+
reservedOutput: Math.max(0, input.provider.contextWindow - inputLimit),
|
|
35
|
+
historyTokens,
|
|
36
|
+
toolTokens,
|
|
37
|
+
transientTokens,
|
|
38
|
+
multimodalTokens,
|
|
39
|
+
totalInputTokens,
|
|
40
|
+
overBudget: totalInputTokens > inputLimit,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface EmergencyToolFit {
|
|
45
|
+
tools: Tool[];
|
|
46
|
+
removedNames: string[];
|
|
47
|
+
plan: ContextBudgetPlan;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const AUXILIARY_REMOVAL_ORDER = ['Advisor', 'Agent'];
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Last-resort schema reduction. Normal requests keep the full catalog; this is
|
|
54
|
+
* used only after history compaction still cannot fit the provider window.
|
|
55
|
+
*/
|
|
56
|
+
export function fitToolsForEmergency(input: {
|
|
57
|
+
provider: Provider;
|
|
58
|
+
history: readonly Message[];
|
|
59
|
+
tools: readonly Tool[];
|
|
60
|
+
transientContext?: string;
|
|
61
|
+
multimodalTokens?: number;
|
|
62
|
+
requiredNames?: ReadonlySet<string>;
|
|
63
|
+
}): EmergencyToolFit {
|
|
64
|
+
let tools = [...input.tools];
|
|
65
|
+
let plan = buildContextBudgetPlan({ ...input, tools });
|
|
66
|
+
if (!plan.overBudget) return { tools, removedNames: [], plan };
|
|
67
|
+
|
|
68
|
+
const required = input.requiredNames ?? new Set<string>();
|
|
69
|
+
const auxiliaryRank = new Map(AUXILIARY_REMOVAL_ORDER.map((name, index) => [name, index]));
|
|
70
|
+
const candidates = tools
|
|
71
|
+
.filter((tool) => !required.has(tool.name) && budgetClassForToolName(tool.name) === 'auxiliary')
|
|
72
|
+
.sort((a, b) => {
|
|
73
|
+
const rankA = auxiliaryRank.get(a.name);
|
|
74
|
+
const rankB = auxiliaryRank.get(b.name);
|
|
75
|
+
if (rankA !== undefined || rankB !== undefined) {
|
|
76
|
+
return (rankA ?? Number.MAX_SAFE_INTEGER) - (rankB ?? Number.MAX_SAFE_INTEGER);
|
|
77
|
+
}
|
|
78
|
+
return estimateToolsTokens([b]) - estimateToolsTokens([a]);
|
|
79
|
+
});
|
|
80
|
+
const removedNames: string[] = [];
|
|
81
|
+
for (const candidate of candidates) {
|
|
82
|
+
if (!plan.overBudget || tools.length <= 1) break;
|
|
83
|
+
tools = tools.filter((tool) => tool.name !== candidate.name);
|
|
84
|
+
removedNames.push(candidate.name);
|
|
85
|
+
plan = buildContextBudgetPlan({ ...input, tools });
|
|
86
|
+
}
|
|
87
|
+
return { tools, removedNames, plan };
|
|
88
|
+
}
|