@causyne/agent 1.20.122 → 1.20.127
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/bin/causyne.js +38 -15
- package/docs/SECURITY_REVIEW.md +42 -6
- package/package.json +7 -7
- package/src/acp/agentCatalog.js +74 -50
- package/src/acp/agentCatalog.ts +82 -49
- package/src/acp/client.js +309 -86
- package/src/acp/client.ts +291 -84
- package/src/acp/protocol.js +147 -3
- package/src/acp/protocol.ts +181 -4
- package/src/acp/server.js +418 -45
- package/src/acp/server.ts +404 -47
- package/src/agent/abortableDelay.js +2 -2
- package/src/agent/abortableDelay.ts +2 -2
- package/src/agent/errorClassifier.js +51 -7
- package/src/agent/errorClassifier.ts +52 -6
- package/src/agent/providerFailure.js +1 -1
- package/src/agent/providerFailure.ts +7 -1
- package/src/agent/toolArgValidator.js +38 -4
- package/src/agent/toolArgValidator.ts +39 -4
- package/src/agent/toolTurnIntegrity.js +28 -7
- package/src/agent/toolTurnIntegrity.ts +25 -6
- package/src/agent/workspaceBoundary.js +30 -4
- package/src/agent/workspaceBoundary.ts +32 -4
- package/src/agentLoop.js +673 -236
- package/src/agentLoop.ts +705 -233
- package/src/approvalPolicy.js +61 -10
- package/src/approvalPolicy.ts +69 -11
- package/src/auditLog.js +641 -48
- package/src/auditLog.ts +661 -0
- package/src/autoUpdate.js +32 -5
- package/src/autoUpdate.ts +27 -5
- package/src/backgroundTasks.js +328 -0
- package/src/backgroundTasks.ts +339 -0
- package/src/benchmarks/codingEval.js +558 -0
- package/src/benchmarks/codingEval.ts +628 -0
- package/src/benchmarks/planCache.js +115 -134
- package/src/benchmarks/planCache.ts +163 -0
- package/src/browser/browserRuntime.js +52 -0
- package/src/browser/browserRuntime.ts +55 -0
- package/src/browser/causyneBrowser.js +914 -13
- package/src/browser/causyneBrowser.ts +1075 -35
- package/src/browser/searchProviders.js +94 -6
- package/src/browser/searchProviders.ts +89 -6
- package/src/browser/urlPolicy.js +22 -2
- package/src/browser/urlPolicy.ts +19 -2
- package/src/browser/workspacePathSafety.js +6 -4
- package/src/browser/workspacePathSafety.ts +7 -4
- package/src/capabilities.js +18 -17
- package/src/capabilities.ts +38 -0
- package/src/checkpoints.js +1241 -1127
- package/src/checkpoints.ts +1377 -0
- package/src/cliMode.js +718 -754
- package/src/cliMode.ts +792 -0
- package/src/codebase/repoMap.js +656 -0
- package/src/codebase/repoMap.ts +664 -0
- package/src/commands.js +3806 -2513
- package/src/commands.ts +4162 -0
- package/src/compiledSkills.js +8052 -8054
- package/src/compiledSkills.ts +8078 -0
- package/src/config.js +118 -1
- package/src/config.ts +124 -1
- package/src/configVault.js +29 -2
- package/src/configVault.ts +26 -2
- package/src/contextManager.js +473 -557
- package/src/contextManager.ts +599 -0
- package/src/continuum/adapters/antigravity.js +8 -3
- package/src/continuum/adapters/antigravity.ts +8 -3
- package/src/continuum/sanitizer.js +23 -1
- package/src/continuum/sanitizer.ts +23 -1
- package/src/continuum/ui/continuumPicker.js +0 -2
- package/src/continuum/ui/continuumPicker.ts +0 -2
- package/src/continuum/ui/continuumPickerView.js +0 -2
- package/src/continuum/ui/continuumPickerView.ts +4 -20
- package/src/core/contextCompactor.js +142 -14
- package/src/core/contextCompactor.ts +150 -15
- package/src/core/goalLoop.js +257 -0
- package/src/core/goalLoop.ts +310 -0
- package/src/creative/liveBridge.js +3 -2
- package/src/creative/liveBridge.ts +4 -2
- package/src/creative/studioScripts.js +1 -1
- package/src/creative/studioScripts.ts +1 -1
- package/src/decideTools.js +7 -2
- package/src/decideTools.ts +7 -2
- package/src/decisionPolicy.js +10 -2
- package/src/decisionPolicy.ts +10 -2
- package/src/designPalettes.js +72 -84
- package/src/designPalettes.ts +111 -0
- package/src/devMode.js +2 -2
- package/src/devMode.ts +6 -0
- package/src/diffReview.js +370 -0
- package/src/diffReview.ts +407 -0
- package/src/dynamicCatalogue.js +311 -11
- package/src/dynamicCatalogue.ts +331 -11
- package/src/embodimentSession.js +143 -154
- package/src/embodimentSession.ts +173 -0
- package/src/engines/installer.js +60 -29
- package/src/engines/installer.ts +73 -22
- package/src/enterprisePolicy.js +660 -0
- package/src/enterprisePolicy.ts +728 -0
- package/src/entrypoint.js +646 -268
- package/src/entrypoint.ts +740 -0
- package/src/game/causyneCoreBridge.js +686 -0
- package/src/game/causyneCoreBridge.ts +702 -0
- package/src/game/gameLauncher.js +287 -0
- package/src/game/gameLauncher.ts +352 -0
- package/src/game/gameProvisioner.js +425 -0
- package/src/game/gameProvisioner.ts +488 -0
- package/src/gitSnapshot.js +417 -312
- package/src/gitSnapshot.ts +500 -0
- package/src/headlessCli.js +343 -25
- package/src/headlessCli.ts +343 -20
- package/src/hooks.js +247 -26
- package/src/hooks.ts +236 -26
- package/src/ignoreRules.js +297 -0
- package/src/ignoreRules.ts +308 -0
- package/src/implementationPlan.js +7 -6
- package/src/implementationPlan.ts +8 -6
- package/src/infra/atomicWriter.js +127 -18
- package/src/infra/atomicWriter.ts +141 -20
- package/src/launchIntent.js +85 -4
- package/src/launchIntent.ts +88 -4
- package/src/licensing/entitlements.js +553 -237
- package/src/licensing/entitlements.ts +590 -0
- package/src/licensing/policy.js +17 -1
- package/src/licensing/policy.ts +31 -0
- package/src/lsp/lspCatalog.js +398 -0
- package/src/lsp/lspCatalog.ts +452 -0
- package/src/lsp/lspClient.js +770 -0
- package/src/lsp/lspClient.ts +862 -0
- package/src/lsp/lspProtocol.js +121 -0
- package/src/lsp/lspProtocol.ts +140 -0
- package/src/mcp/mcpClient.js +69 -8
- package/src/mcp/mcpClient.ts +66 -9
- package/src/mcp/mcpRegistry.js +255 -15
- package/src/mcp/mcpRegistry.ts +241 -14
- package/src/mcp/mcpSecurity.js +6 -7
- package/src/mcp/mcpSecurity.ts +7 -6
- package/src/memory/contextBudget.js +2 -0
- package/src/memory/contextBudget.ts +1 -0
- package/src/memory/episodicStore.js +2 -5
- package/src/memory/episodicStore.ts +2 -5
- package/src/memory.js +80 -32
- package/src/memory.ts +111 -0
- package/src/memoryManager.js +151 -143
- package/src/memoryManager.ts +182 -0
- package/src/modelCatalogue.js +172 -195
- package/src/modelCatalogue.ts +201 -0
- package/src/modelIds.js +8 -27
- package/src/modelIds.ts +33 -0
- package/src/modelVariants.js +645 -0
- package/src/modelVariants.ts +717 -0
- package/src/observer/evidence.js +5 -1
- package/src/observer/evidence.ts +5 -1
- package/src/osKeychain.js +17 -9
- package/src/osKeychain.ts +14 -9
- package/src/outputRecovery.js +3 -2
- package/src/outputRecovery.ts +4 -2
- package/src/outputStore.js +210 -156
- package/src/outputStore.ts +321 -0
- package/src/permissionPresets.js +327 -0
- package/src/permissionPresets.ts +361 -0
- package/src/planCache.js +3 -6
- package/src/planCache.ts +3 -6
- package/src/plugins/pluginManager.js +689 -461
- package/src/plugins/pluginManager.ts +807 -0
- package/src/plugins/pluginRunner.js +82 -37
- package/src/plugins/pluginRunner.ts +98 -0
- package/src/plugins/pluginSkills.js +47 -9
- package/src/plugins/pluginSkills.ts +46 -8
- package/src/pluginsFactory/discovery.js +0 -1
- package/src/pluginsFactory/discovery.ts +0 -1
- package/src/pluginsFactory/templates.js +17 -4
- package/src/pluginsFactory/templates.ts +17 -4
- package/src/prWorkflow.js +337 -0
- package/src/prWorkflow.ts +376 -0
- package/src/procSignal.js +1 -2
- package/src/procSignal.ts +1 -3
- package/src/projectInstructions.js +319 -0
- package/src/projectInstructions.ts +361 -0
- package/src/providers/acp.js +234 -49
- package/src/providers/acp.ts +240 -50
- package/src/providers/anthropic.js +152 -47
- package/src/providers/anthropic.ts +152 -45
- package/src/providers/antigravity.js +620 -356
- package/src/providers/antigravity.ts +621 -357
- package/src/providers/base.js +9 -2
- package/src/providers/base.ts +10 -2
- package/src/providers/byokHttp.js +134 -18
- package/src/providers/byokHttp.ts +181 -19
- package/src/providers/byokStream.js +183 -44
- package/src/providers/byokStream.ts +179 -62
- package/src/providers/dashscope-byok.js +50 -8
- package/src/providers/dashscope-byok.ts +59 -13
- package/src/providers/deepseek.js +12 -3
- package/src/providers/deepseek.ts +12 -3
- package/src/providers/factory.js +41 -0
- package/src/providers/factory.ts +42 -0
- package/src/providers/gemini.js +74 -22
- package/src/providers/gemini.ts +78 -26
- package/src/providers/moonshot.js +60 -8
- package/src/providers/moonshot.ts +64 -14
- package/src/providers/muse.js +6 -0
- package/src/providers/muse.ts +8 -0
- package/src/providers/ollama.js +299 -21
- package/src/providers/ollama.ts +331 -29
- package/src/providers/openai-compatible.js +81 -12
- package/src/providers/openai-compatible.ts +89 -18
- package/src/providers/openai.js +87 -6
- package/src/providers/openai.ts +74 -6
- package/src/providers/openrouter.js +248 -66
- package/src/providers/openrouter.ts +243 -70
- package/src/providers/qwen-byok.js +50 -8
- package/src/providers/qwen-byok.ts +59 -13
- package/src/providers/wireNormalizer.js +66 -0
- package/src/providers/wireNormalizer.ts +64 -0
- package/src/providers/xai.js +31 -8
- package/src/providers/xai.ts +38 -14
- package/src/provisioning/capabilityConsent.js +29 -11
- package/src/provisioning/capabilityConsent.ts +42 -0
- package/src/provisioning/capabilityProvisioner.js +309 -197
- package/src/provisioning/capabilityProvisioner.ts +413 -0
- package/src/provisioning/capabilityTools.js +31 -17
- package/src/provisioning/capabilityTools.ts +43 -0
- package/src/provisioning/npmInstall.js +33 -5
- package/src/provisioning/npmInstall.ts +33 -5
- package/src/reporting.js +330 -326
- package/src/reporting.ts +484 -0
- package/src/sandbox.js +71 -0
- package/src/sandbox.ts +81 -0
- package/src/scheduler/scheduler.js +372 -0
- package/src/scheduler/scheduler.ts +433 -0
- package/src/sessionJournal.js +24 -3
- package/src/sessionJournal.ts +18 -3
- package/src/sessionSearchIndex.js +267 -0
- package/src/sessionSearchIndex.ts +311 -0
- package/src/sessionStore.js +1 -2
- package/src/sessionStore.ts +2 -0
- package/src/skillsManager.js +2 -3
- package/src/skillsManager.ts +2 -3
- package/src/slopDetector.js +202 -265
- package/src/slopDetector.ts +279 -0
- package/src/smartToolsUse.js +10 -4
- package/src/smartToolsUse.ts +10 -4
- package/src/stallGuard.js +10 -3
- package/src/stallGuard.ts +9 -3
- package/src/taskBuffer.js +91 -40
- package/src/taskBuffer.ts +94 -0
- package/src/tokenTracker.js +78 -11
- package/src/tokenTracker.ts +69 -11
- package/src/toolPacks.js +11 -0
- package/src/toolPacks.ts +11 -0
- package/src/tools/applyPatch.js +610 -0
- package/src/tools/applyPatch.ts +661 -0
- package/src/tools/archive.js +135 -21
- package/src/tools/archive.ts +136 -21
- package/src/tools/astryxOracle.js +77 -72
- package/src/tools/astryxOracle.ts +95 -0
- package/src/tools/axSnapshot.js +127 -147
- package/src/tools/axSnapshot.ts +174 -0
- package/src/tools/backgroundTask.js +86 -0
- package/src/tools/backgroundTask.ts +121 -0
- package/src/tools/blenderAutomator.js +434 -390
- package/src/tools/blenderAutomator.ts +623 -0
- package/src/tools/checkSystemSpecs.js +54 -61
- package/src/tools/checkSystemSpecs.ts +73 -0
- package/src/tools/clipboard.js +42 -31
- package/src/tools/clipboard.ts +61 -0
- package/src/tools/codeSearchAst.js +359 -91
- package/src/tools/codeSearchAst.ts +399 -0
- package/src/tools/codeSearcher.js +179 -37
- package/src/tools/codeSearcher.ts +188 -33
- package/src/tools/codeTools.js +208 -245
- package/src/tools/codeTools.ts +271 -0
- package/src/tools/codebaseSearch.js +5 -0
- package/src/tools/codebaseSearch.ts +5 -0
- package/src/tools/desktopAct.js +185 -197
- package/src/tools/desktopAct.ts +257 -0
- package/src/tools/dynamicLoader.js +4 -40
- package/src/tools/dynamicLoader.ts +13 -0
- package/src/tools/executeProceduralMedia.js +117 -86
- package/src/tools/executeProceduralMedia.ts +135 -0
- package/src/tools/fileTracker.js +74 -0
- package/src/tools/fileTracker.ts +94 -0
- package/src/tools/fsDelete.js +57 -47
- package/src/tools/fsDelete.ts +80 -0
- package/src/tools/fsEdit.js +192 -74
- package/src/tools/fsEdit.ts +201 -72
- package/src/tools/fsMove.js +79 -52
- package/src/tools/fsMove.ts +108 -0
- package/src/tools/fsRead.js +54 -15
- package/src/tools/fsRead.ts +55 -15
- package/src/tools/fsSearch.js +5 -0
- package/src/tools/fsSearch.ts +5 -0
- package/src/tools/fsWrite.js +14 -6
- package/src/tools/fsWrite.ts +14 -6
- package/src/tools/gameAiBehaviorTree.js +74 -91
- package/src/tools/gameAiBehaviorTree.ts +219 -0
- package/src/tools/gameAnimationRig.js +128 -147
- package/src/tools/gameAnimationRig.ts +215 -0
- package/src/tools/gameAssetFetcher.js +403 -441
- package/src/tools/gameAssetFetcher.ts +477 -0
- package/src/tools/gameAssetHarvester.js +171 -200
- package/src/tools/gameAssetHarvester.ts +261 -0
- package/src/tools/gameAudioSynth.js +223 -259
- package/src/tools/gameAudioSynth.ts +255 -0
- package/src/tools/gameBuilder.js +100 -91
- package/src/tools/gameBuilder.ts +913 -0
- package/src/tools/gameCanvasAudit.js +138 -96
- package/src/tools/gameCanvasAudit.ts +157 -0
- package/src/tools/gameCinematicSequencer.js +93 -111
- package/src/tools/gameCinematicSequencer.ts +165 -0
- package/src/tools/gameDataForge.js +115 -118
- package/src/tools/gameDataForge.ts +151 -0
- package/src/tools/gameDialogueTreeGen.js +125 -156
- package/src/tools/gameDialogueTreeGen.ts +159 -0
- package/src/tools/gameEconomyBalancer.js +150 -153
- package/src/tools/gameEconomyBalancer.ts +186 -0
- package/src/tools/gameEntitySpawner.js +91 -108
- package/src/tools/gameEntitySpawner.ts +209 -0
- package/src/tools/gameLoreForge.js +125 -147
- package/src/tools/gameLoreForge.ts +162 -0
- package/src/tools/gameQuestArcBuilder.js +105 -144
- package/src/tools/gameQuestArcBuilder.ts +147 -0
- package/src/tools/gameSceneBuilder.js +143 -149
- package/src/tools/gameSceneBuilder.ts +196 -0
- package/src/tools/gameShaderForge.js +83 -101
- package/src/tools/gameShaderForge.ts +181 -0
- package/src/tools/gameTilemapGenerator.js +99 -129
- package/src/tools/gameTilemapGenerator.ts +158 -0
- package/src/tools/gameUiHudBuilder.js +109 -129
- package/src/tools/gameUiHudBuilder.ts +300 -0
- package/src/tools/gameVfxEmitterGen.js +86 -89
- package/src/tools/gameVfxEmitterGen.ts +133 -0
- package/src/tools/gameWebRuntimeInspector.js +153 -86
- package/src/tools/gameWebRuntimeInspector.ts +167 -0
- package/src/tools/generateMediaViaApi.js +57 -15
- package/src/tools/generateMediaViaApi.ts +56 -15
- package/src/tools/gitExec.js +133 -86
- package/src/tools/gitExec.ts +146 -0
- package/src/tools/gitWorktree.js +115 -0
- package/src/tools/gitWorktree.ts +150 -0
- package/src/tools/godotAutomator.js +417 -394
- package/src/tools/godotAutomator.ts +530 -0
- package/src/tools/lspCodeIntel.js +217 -0
- package/src/tools/lspCodeIntel.ts +260 -0
- package/src/tools/manageLocalAiDependencies.js +242 -206
- package/src/tools/manageLocalAiDependencies.ts +288 -0
- package/src/tools/multiEdit.js +16 -76
- package/src/tools/multiEdit.ts +20 -77
- package/src/tools/nativeEngine.js +2 -2
- package/src/tools/nativeEngine.ts +2 -2
- package/src/tools/openSourceToolProvisioner.js +2 -2
- package/src/tools/openSourceToolProvisioner.ts +2 -2
- package/src/tools/osSandbox.js +152 -15
- package/src/tools/osSandbox.ts +148 -15
- package/src/tools/palmierAutomator.js +147 -95
- package/src/tools/palmierAutomator.ts +171 -0
- package/src/tools/payloadSanitizer.js +0 -1
- package/src/tools/payloadSanitizer.ts +0 -1
- package/src/tools/pdfReader.js +197 -104
- package/src/tools/pdfReader.ts +216 -0
- package/src/tools/persistentShell.js +267 -144
- package/src/tools/persistentShell.ts +314 -0
- package/src/tools/pluginManager.js +84 -72
- package/src/tools/pluginManager.ts +109 -0
- package/src/tools/presentDeliverable.js +103 -0
- package/src/tools/presentDeliverable.ts +127 -0
- package/src/tools/printer.js +278 -296
- package/src/tools/printer.ts +326 -0
- package/src/tools/procTerm.js +96 -83
- package/src/tools/procTerm.ts +127 -0
- package/src/tools/processList.js +45 -48
- package/src/tools/processList.ts +73 -0
- package/src/tools/ptcRuntime.js +444 -0
- package/src/tools/ptcRuntime.ts +490 -0
- package/src/tools/ptyTerminal.js +1096 -0
- package/src/tools/ptyTerminal.ts +1231 -0
- package/src/tools/registry.js +308 -287
- package/src/tools/registry.ts +495 -0
- package/src/tools/repoMap.js +46 -0
- package/src/tools/repoMap.ts +66 -0
- package/src/tools/subagentOrchestrator.js +404 -348
- package/src/tools/subagentOrchestrator.ts +457 -0
- package/src/tools/sysRun.js +83 -26
- package/src/tools/sysRun.ts +80 -26
- package/src/tools/toolForge.js +84 -67
- package/src/tools/toolForge.ts +102 -0
- package/src/tools/toolOutputStore.js +26 -4
- package/src/tools/toolOutputStore.ts +22 -4
- package/src/tools/toolPathSafety.js +262 -0
- package/src/tools/toolPathSafety.ts +308 -0
- package/src/tools/toolScanner.js +28 -0
- package/src/tools/toolScanner.ts +29 -0
- package/src/tools/toolSelfRepair.js +21 -6
- package/src/tools/toolSelfRepair.ts +26 -6
- package/src/tools/walkerSafety.ts +1 -0
- package/src/tools/webFetch.js +163 -13
- package/src/tools/webFetch.ts +150 -13
- package/src/tools/webSearch.js +123 -36
- package/src/tools/webSearch.ts +124 -33
- package/src/toolsList.js +5 -0
- package/src/toolsList.ts +5 -0
- package/src/tui/ask.js +159 -168
- package/src/tui/ask.ts +259 -0
- package/src/tui/banner.js +5 -1
- package/src/tui/banner.ts +6 -1
- package/src/tui/block.js +0 -1
- package/src/tui/block.ts +0 -1
- package/src/tui/chatRenderer.js +1194 -1443
- package/src/tui/chatRenderer.ts +1335 -0
- package/src/tui/clipboardImage.js +36 -12
- package/src/tui/clipboardImage.ts +39 -13
- package/src/tui/clipboardSync.js +34 -9
- package/src/tui/clipboardSync.ts +38 -9
- package/src/tui/codeProgress.js +0 -1
- package/src/tui/codeProgress.ts +0 -1
- package/src/tui/completion.js +396 -371
- package/src/tui/completion.ts +575 -0
- package/src/tui/composerControls.js +212 -34
- package/src/tui/composerControls.ts +235 -34
- package/src/tui/consoleGuard.js +27 -7
- package/src/tui/consoleGuard.ts +29 -7
- package/src/tui/dialogs.js +867 -733
- package/src/tui/dialogs.ts +971 -0
- package/src/tui/diff.js +205 -195
- package/src/tui/diff.ts +336 -0
- package/src/tui/history.js +143 -108
- package/src/tui/history.ts +167 -0
- package/src/tui/home.js +166 -161
- package/src/tui/home.ts +252 -0
- package/src/tui/invocation.js +59 -67
- package/src/tui/invocation.ts +116 -0
- package/src/tui/keys.js +437 -420
- package/src/tui/keys.ts +597 -0
- package/src/tui/lineEditor.js +477 -432
- package/src/tui/lineEditor.ts +542 -0
- package/src/tui/messageActionPlacement.js +0 -1
- package/src/tui/messageActionPlacement.ts +0 -1
- package/src/tui/messageInteraction.js +0 -2
- package/src/tui/messageInteraction.ts +0 -2
- package/src/tui/modelPicker.js +22 -15
- package/src/tui/modelPicker.ts +25 -18
- package/src/tui/observerPicker.js +0 -2
- package/src/tui/observerPicker.ts +0 -2
- package/src/tui/overlay.js +2 -6
- package/src/tui/overlay.ts +2 -6
- package/src/tui/prompt.js +1818 -2151
- package/src/tui/prompt.ts +1872 -0
- package/src/tui/runningLight.js +0 -1
- package/src/tui/runningLight.ts +0 -1
- package/src/tui/selectList.js +369 -349
- package/src/tui/selectList.ts +433 -0
- package/src/tui/sessionPicker.js +0 -1
- package/src/tui/sessionPicker.ts +0 -1
- package/src/tui/sessionPickerView.js +0 -2
- package/src/tui/sessionPickerView.ts +4 -21
- package/src/tui/sessionSidebar.js +3 -1
- package/src/tui/sessionSidebar.ts +4 -1
- package/src/tui/setup.js +39 -14
- package/src/tui/setup.ts +45 -14
- package/src/tui/skillAuthoring.js +0 -2
- package/src/tui/skillAuthoring.ts +0 -3
- package/src/tui/stageSurface.js +829 -909
- package/src/tui/stageSurface.ts +1003 -0
- package/src/tui/statusLine.js +7 -4
- package/src/tui/statusLine.ts +9 -3
- package/src/tui/terminalInputFramer.js +82 -69
- package/src/tui/terminalInputFramer.ts +116 -0
- package/src/tui/text.js +25 -10
- package/src/tui/text.ts +24 -10
- package/src/tui/textLayout.js +0 -1
- package/src/tui/textLayout.ts +0 -1
- package/src/tui/theme.js +245 -250
- package/src/tui/theme.ts +441 -0
- package/src/tui/thinkingBox.js +0 -1
- package/src/tui/thinkingBox.ts +0 -1
- package/src/tui/transcript.js +239 -216
- package/src/tui/transcript.ts +324 -0
- package/src/tui/turnRail.js +53 -54
- package/src/tui/turnRail.ts +51 -49
- package/src/tui/usageCard.js +0 -2
- package/src/tui/usageCard.ts +0 -2
- package/src/tui/workspaceSwitch.js +4 -2
- package/src/tui/workspaceSwitch.ts +5 -2
- package/src/types/contracts.ts +4 -1
- package/src/utils/browserOpen.js +107 -0
- package/src/utils/browserOpen.ts +129 -0
- package/src/utils/cli_ui.js +0 -0
- package/src/utils/cli_ui.ts +158 -0
- package/src/utils/winSpawn.js +248 -0
- package/src/utils/winSpawn.ts +275 -0
- package/src/verification/boundedExplorer.js +138 -107
- package/src/verification/boundedExplorer.ts +154 -0
- package/src/verification/byokSmokeProbe.js +193 -0
- package/src/verification/byokSmokeProbe.ts +234 -0
- package/src/verification/cliProbe.js +144 -110
- package/src/verification/cliProbe.ts +170 -0
- package/src/verification/featureMap.js +105 -75
- package/src/verification/featureMap.ts +124 -0
- package/src/verification/interactivePty.js +195 -100
- package/src/verification/interactivePty.ts +333 -0
- package/src/verification/propertyProbe.js +109 -101
- package/src/verification/propertyProbe.ts +159 -0
- package/src/verification/ptyProbe.js +168 -73
- package/src/verification/ptyProbe.ts +254 -0
- package/src/verification/skillCatalog.js +25 -25
- package/src/verification/skillCatalog.ts +66 -0
- package/src/verification/statechart.js +140 -127
- package/src/verification/statechart.ts +196 -0
- package/src/verification/uiRuntime.js +80 -49
- package/src/verification/uiRuntime.ts +88 -0
- package/src/version.js +37 -32
- package/src/version.ts +45 -0
- package/src/web/client/browserPanel.js +702 -0
- package/src/web/client/browserPanel.ts +663 -0
- package/src/web/client/chatStream.js +309 -0
- package/src/web/client/chatStream.ts +289 -0
- package/src/web/client/cliPanel.js +165 -0
- package/src/web/client/cliPanel.ts +171 -0
- package/src/web/client/composer.js +204 -0
- package/src/web/client/composer.ts +209 -0
- package/src/web/client/diffPanel.js +176 -0
- package/src/web/client/diffPanel.ts +203 -0
- package/src/web/client/dom.js +220 -0
- package/src/web/client/dom.ts +221 -0
- package/src/web/client/filesAndCanvas.js +231 -0
- package/src/web/client/filesAndCanvas.ts +238 -0
- package/src/web/client/gameLauncherUi.js +78 -0
- package/src/web/client/gameLauncherUi.ts +78 -0
- package/src/web/client/main.js +301 -0
- package/src/web/client/main.ts +368 -0
- package/src/web/client/markdown.js +364 -0
- package/src/web/client/markdown.ts +373 -0
- package/src/web/client/modelPicker.js +455 -0
- package/src/web/client/modelPicker.ts +451 -0
- package/src/web/client/permissionPresetsUi.js +307 -0
- package/src/web/client/permissionPresetsUi.ts +333 -0
- package/src/web/client/sessions.js +353 -0
- package/src/web/client/sessions.ts +372 -0
- package/src/web/client/settingsModal.js +191 -0
- package/src/web/client/settingsModal.ts +176 -0
- package/src/web/client/state.js +250 -0
- package/src/web/client/state.ts +233 -0
- package/src/web/client/streamSmoother.js +127 -0
- package/src/web/client/streamSmoother.ts +119 -0
- package/src/web/client/studioLayout.js +54 -0
- package/src/web/client/studioLayout.ts +60 -0
- package/src/web/client/studioShell.js +327 -0
- package/src/web/client/studioShell.ts +340 -0
- package/src/web/client/studioStart.js +77 -0
- package/src/web/client/studioStart.ts +89 -0
- package/src/web/client/terminalPanel.js +357 -0
- package/src/web/client/terminalPanel.ts +345 -0
- package/src/web/client/turnView.js +934 -0
- package/src/web/client/turnView.ts +981 -0
- package/src/web/client/types.js +1 -0
- package/src/web/client/types.ts +319 -0
- package/src/web/client/validators.js +106 -0
- package/src/web/client/validators.ts +96 -0
- package/src/web/guiLauncher.js +89 -0
- package/src/web/guiLauncher.ts +119 -0
- package/src/web/server/activeRuns.js +152 -0
- package/src/web/server/activeRuns.ts +171 -0
- package/src/web/server/routesBrowser.js +355 -0
- package/src/web/server/routesBrowser.ts +386 -0
- package/src/web/server/routesChat.js +304 -0
- package/src/web/server/routesChat.ts +347 -0
- package/src/web/server/routesCore.js +472 -0
- package/src/web/server/routesCore.ts +522 -0
- package/src/web/server/routesTerminal.js +162 -0
- package/src/web/server/routesTerminal.ts +182 -0
- package/src/web/server/routesWorkspace.js +510 -0
- package/src/web/server/routesWorkspace.ts +546 -0
- package/src/web/server/security.js +98 -0
- package/src/web/server/security.ts +108 -0
- package/src/web/server/sessionTranscript.js +586 -0
- package/src/web/server/sessionTranscript.ts +566 -0
- package/src/web/server/staticAssets.js +80 -0
- package/src/web/server/staticAssets.ts +91 -0
- package/src/web/server/types.js +1 -0
- package/src/web/server/types.ts +135 -0
- package/src/web/server/workspaceFiles.js +368 -0
- package/src/web/server/workspaceFiles.ts +363 -0
- package/src/web/skybridgeBrowserBridge.js +256 -0
- package/src/web/skybridgeBrowserBridge.ts +285 -0
- package/src/web/skybridgeBrowserMcp.js +730 -0
- package/src/web/skybridgeBrowserMcp.ts +813 -0
- package/src/web/skybridgeServer.js +249 -0
- package/src/web/skybridgeServer.ts +305 -0
- package/src/web/skybridgeUi.js +38 -0
- package/src/web/skybridgeUi.ts +47 -0
- package/src/web/styles/agent.css +380 -0
- package/src/web/styles/composer.css +193 -0
- package/src/web/styles/overlays.css +436 -0
- package/src/web/styles/shell.css +387 -0
- package/src/web/styles/studio.css +723 -0
- package/src/web/styles/thread.css +221 -0
- package/src/web/styles/tokens.css +94 -0
- package/src/web/ui/brandMark.js +73 -0
- package/src/web/ui/brandMark.ts +82 -0
- package/src/web/ui/modalsTemplate.js +139 -0
- package/src/web/ui/modalsTemplate.ts +139 -0
- package/src/web/ui/sidebarTemplate.js +63 -0
- package/src/web/ui/sidebarTemplate.ts +64 -0
- package/src/web/ui/studioTemplate.js +258 -0
- package/src/web/ui/studioTemplate.ts +258 -0
- package/src/web/ui/workspaceTemplate.js +72 -0
- package/src/web/ui/workspaceTemplate.ts +73 -0
- package/src/worktreeManager.js +526 -0
- package/src/worktreeManager.ts +567 -0
- package/src/zeroCostFailover.js +168 -0
- package/src/zeroCostFailover.ts +198 -0
- package/src/zeroCostRouting.js +391 -0
- package/src/zeroCostRouting.ts +437 -0
- package/src/agentLoop.d.ts +0 -65
- package/src/auditLog.d.ts +0 -3
- package/src/checkpoints.d.ts +0 -4
- package/src/compiledSkills.d.ts +0 -5
- package/src/contextManager.d.ts +0 -14
- package/src/designPalettes.d.ts +0 -2
- package/src/devMode.d.ts +0 -1
- package/src/embodimentSession.d.ts +0 -2
- package/src/licensing/entitlements.d.ts +0 -14
- package/src/memory.d.ts +0 -13
- package/src/memoryManager.d.ts +0 -1
- package/src/modelCatalogue.d.ts +0 -6
- package/src/modelIds.d.ts +0 -2
- package/src/outputStore.d.ts +0 -4
- package/src/plugins/pluginManager.d.ts +0 -7
- package/src/providers/antigravity.d.ts +0 -19
- package/src/provisioning/capabilityProvisioner.d.ts +0 -12
- package/src/slopDetector.d.ts +0 -3
- package/src/taskBuffer.d.ts +0 -1
- package/src/tools/desktopAct.d.ts +0 -10
- package/src/tools/registry.d.ts +0 -5
- package/src/tui/chatRenderer.d.ts +0 -27
- package/src/tui/diff.d.ts +0 -3
- package/src/utils/cli_ui.d.ts +0 -19
- package/src/utils/paths.d.ts +0 -3
- package/src/verification/skillCatalog.d.ts +0 -1
- package/src/version.d.ts +0 -1
package/src/acp/server.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import crypto from 'node:crypto';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
4
5
|
import { AgentLoop } from '../agentLoop.js';
|
|
5
6
|
import type { AgentLoopEvent } from '../agentLoop.js';
|
|
6
7
|
import { createApprovalScope } from '../approvalGrants.js';
|
|
7
8
|
import type { ApprovalScope } from '../approvalGrants.js';
|
|
9
|
+
import { loadConfig } from '../config.js';
|
|
10
|
+
import { DEFAULT_MODEL_BY_PROVIDER, MODEL_CATALOGUE, PEER_MODEL_CATALOGUE } from '../modelCatalogue.js';
|
|
11
|
+
import { resolveModelVariants } from '../modelVariants.js';
|
|
12
|
+
import { McpClient } from '../mcp/mcpClient.js';
|
|
13
|
+
import type { McpServerDefinition } from '../mcp/mcpClient.js';
|
|
14
|
+
import { registerSessionMcpServers, unregisterSessionMcpServers } from '../mcp/mcpRegistry.js';
|
|
8
15
|
import { createSession, getSession, saveSessionMessages, forkSession } from '../sessionJournal.js';
|
|
9
16
|
import { isBlockedWorkspaceRoot } from '../sandboxPolicy.js';
|
|
10
17
|
import { safeDisplay } from '../tui/text.js';
|
|
@@ -39,11 +46,17 @@ import type {
|
|
|
39
46
|
PromptRequest,
|
|
40
47
|
PromptResponse,
|
|
41
48
|
RequestPermissionResponse,
|
|
49
|
+
SessionConfigOption,
|
|
42
50
|
SessionInfo,
|
|
51
|
+
SessionModelState,
|
|
43
52
|
SessionModeState,
|
|
44
53
|
SessionNotification,
|
|
45
54
|
SessionUpdate,
|
|
55
|
+
SetSessionConfigOptionRequest,
|
|
56
|
+
SetSessionConfigOptionResponse,
|
|
46
57
|
SetSessionModeRequest,
|
|
58
|
+
SetSessionModelRequest,
|
|
59
|
+
SetSessionModelResponse,
|
|
47
60
|
StopReason,
|
|
48
61
|
ToolCall,
|
|
49
62
|
ToolCallStatus,
|
|
@@ -89,15 +102,55 @@ interface AcpSession {
|
|
|
89
102
|
title: string;
|
|
90
103
|
cwd: string;
|
|
91
104
|
modeId: string;
|
|
105
|
+
model?: string | undefined;
|
|
106
|
+
variant?: string | undefined;
|
|
107
|
+
mcpServers?: McpServerDefinition[] | undefined;
|
|
92
108
|
loop: AgentLoop | null;
|
|
93
109
|
busy: boolean;
|
|
94
110
|
cancelled: boolean;
|
|
95
111
|
updatedAt: number;
|
|
96
112
|
queue: Promise<unknown>;
|
|
113
|
+
generation: number;
|
|
114
|
+
pendingPrompts: number;
|
|
97
115
|
/** Session-local standing approvals. Forked/resumed sessions never inherit. */
|
|
98
116
|
approvalScope: ApprovalScope;
|
|
99
117
|
}
|
|
100
118
|
|
|
119
|
+
const FORBIDDEN_ENV_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
120
|
+
const MAX_SESSION_MCP_SERVERS = 16;
|
|
121
|
+
|
|
122
|
+
function providerModelsForCatalogue(provider: string): string[] {
|
|
123
|
+
const norm = provider.trim().toLowerCase();
|
|
124
|
+
if (!norm) return [];
|
|
125
|
+
const peerKey = norm.startsWith('acp/') ? norm.slice(4) : norm;
|
|
126
|
+
if (Object.hasOwn(PEER_MODEL_CATALOGUE, peerKey)) {
|
|
127
|
+
return [...(PEER_MODEL_CATALOGUE[peerKey] ?? [])];
|
|
128
|
+
}
|
|
129
|
+
const providerLabelMatch: Record<string, string[]> = {
|
|
130
|
+
deepseek: ['DeepSeek'],
|
|
131
|
+
qwen: ['Qwen'],
|
|
132
|
+
dashscope: ['Qwen'],
|
|
133
|
+
'dashscope-byok': ['Qwen'],
|
|
134
|
+
anthropic: ['Anthropic'],
|
|
135
|
+
openai: ['OpenAI'],
|
|
136
|
+
gemini: ['Gemini'],
|
|
137
|
+
'gemini-free': ['Gemini (Free Tier)'],
|
|
138
|
+
moonshot: ['Moonshot'],
|
|
139
|
+
xai: ['xAI'],
|
|
140
|
+
groq: ['Groq (Free Tier)'],
|
|
141
|
+
cerebras: ['Cerebras (Free Tier)'],
|
|
142
|
+
openrouter: ['OpenRouter (Free Tier)'],
|
|
143
|
+
mistral: ['Mistral (Free Tier)']
|
|
144
|
+
};
|
|
145
|
+
const labels = providerLabelMatch[norm] ?? [];
|
|
146
|
+
const models: string[] = [];
|
|
147
|
+
for (const label of labels) {
|
|
148
|
+
const entries = MODEL_CATALOGUE[label];
|
|
149
|
+
if (Array.isArray(entries)) models.push(...entries);
|
|
150
|
+
}
|
|
151
|
+
return models;
|
|
152
|
+
}
|
|
153
|
+
|
|
101
154
|
const MODE_TO_AUTONOMY: Record<string, 'A' | 'B' | 'C'> = {
|
|
102
155
|
autonomous: 'C',
|
|
103
156
|
standard: 'B',
|
|
@@ -117,16 +170,21 @@ const MAX_PROMPT_CHARS = 200_000;
|
|
|
117
170
|
const MAX_RAW_CHARS = 4000;
|
|
118
171
|
const MAX_JSONRPC_BUFFER_BYTES = 8 * 1024 * 1024;
|
|
119
172
|
const MAX_SESSIONS = 128;
|
|
173
|
+
const MAX_PENDING_PROMPTS_PER_SESSION = 32;
|
|
174
|
+
const MAX_PENDING_PROMPTS = 128;
|
|
120
175
|
|
|
121
176
|
function textFromPrompt(prompt: ContentBlock[]): string | null {
|
|
122
177
|
const parts: string[] = [];
|
|
178
|
+
let length = 0;
|
|
123
179
|
for (const block of prompt) {
|
|
124
180
|
if (!block || typeof block !== 'object' || block.type !== 'text' || typeof block.text !== 'string') {
|
|
125
181
|
return null;
|
|
126
182
|
}
|
|
183
|
+
length += block.text.length + (parts.length ? 1 : 0);
|
|
184
|
+
if (length > MAX_PROMPT_CHARS) return null;
|
|
127
185
|
parts.push(block.text);
|
|
128
186
|
}
|
|
129
|
-
return parts.join('\n')
|
|
187
|
+
return parts.join('\n');
|
|
130
188
|
}
|
|
131
189
|
|
|
132
190
|
function textFromContent(content: unknown): string {
|
|
@@ -179,9 +237,15 @@ export class AcpServer {
|
|
|
179
237
|
private readonly agentVersion: string;
|
|
180
238
|
private readonly permissionTimeoutMs: number;
|
|
181
239
|
private readonly sessions = new Map<string, AcpSession>();
|
|
240
|
+
private readonly assistantStreams = new WeakMap<AcpSession, { key: string; text: string }>();
|
|
241
|
+
private readonly reasoningStreams = new WeakMap<AcpSession, string>();
|
|
242
|
+
private readonly failedTurns = new WeakSet<AcpSession>();
|
|
182
243
|
private readonly pending = new Map<string | number, PendingClientRequest>();
|
|
183
244
|
private nextClientRequestId = 1;
|
|
245
|
+
private pendingPrompts = 0;
|
|
184
246
|
private buffer = '';
|
|
247
|
+
private discardOversizedFrame = false;
|
|
248
|
+
private decoder = new StringDecoder('utf8');
|
|
185
249
|
private closed = false;
|
|
186
250
|
private workspaceRoot: string | null = null;
|
|
187
251
|
private dataListener: ((chunk: Buffer | string) => void) | null = null;
|
|
@@ -201,19 +265,26 @@ export class AcpServer {
|
|
|
201
265
|
}
|
|
202
266
|
|
|
203
267
|
start(): void {
|
|
204
|
-
if (!this.input || this.dataListener) return;
|
|
268
|
+
if (this.closed || !this.input || this.dataListener) return;
|
|
205
269
|
this.dataListener = (chunk: Buffer | string) => {
|
|
206
|
-
|
|
207
|
-
if (this.
|
|
270
|
+
let text = typeof chunk === 'string' ? chunk : this.decoder.write(chunk);
|
|
271
|
+
if (this.discardOversizedFrame) {
|
|
272
|
+
const newline = text.indexOf('\n');
|
|
273
|
+
if (newline < 0) return;
|
|
274
|
+
text = text.slice(newline + 1);
|
|
275
|
+
this.discardOversizedFrame = false;
|
|
276
|
+
}
|
|
277
|
+
this.buffer += text;
|
|
278
|
+
void this.drainBuffer();
|
|
279
|
+
if (Buffer.byteLength(this.buffer, 'utf8') > MAX_JSONRPC_BUFFER_BYTES) {
|
|
208
280
|
this.buffer = '';
|
|
281
|
+
this.discardOversizedFrame = true;
|
|
209
282
|
this.write({
|
|
210
283
|
jsonrpc: '2.0',
|
|
211
284
|
id: null,
|
|
212
285
|
error: { code: ACP_ERROR_CODES.INVALID_REQUEST, message: 'Request frame exceeds maximum size' }
|
|
213
286
|
});
|
|
214
|
-
return;
|
|
215
287
|
}
|
|
216
|
-
void this.drainBuffer();
|
|
217
288
|
};
|
|
218
289
|
this.endListener = () => { void this.stop(); };
|
|
219
290
|
this.errorListener = () => { void this.stop(); };
|
|
@@ -229,8 +300,10 @@ export class AcpServer {
|
|
|
229
300
|
if (this.input && this.endListener) this.input.off('end', this.endListener);
|
|
230
301
|
if (this.input && this.errorListener) this.input.off('error', this.errorListener);
|
|
231
302
|
this.buffer = '';
|
|
303
|
+
const closingIds = [...this.sessions.keys()];
|
|
232
304
|
for (const session of this.sessions.values()) {
|
|
233
305
|
session.cancelled = true;
|
|
306
|
+
session.generation++;
|
|
234
307
|
try {
|
|
235
308
|
session.loop?.abort();
|
|
236
309
|
} catch {
|
|
@@ -238,6 +311,7 @@ export class AcpServer {
|
|
|
238
311
|
}
|
|
239
312
|
}
|
|
240
313
|
this.sessions.clear();
|
|
314
|
+
await Promise.allSettled(closingIds.map((id) => unregisterSessionMcpServers(id)));
|
|
241
315
|
for (const [id, pending] of this.pending) {
|
|
242
316
|
clearTimeout(pending.timer);
|
|
243
317
|
pending.reject(new Error('server stopped'));
|
|
@@ -249,9 +323,9 @@ export class AcpServer {
|
|
|
249
323
|
const lines: string[] = [];
|
|
250
324
|
let index = this.buffer.indexOf('\n');
|
|
251
325
|
while (index >= 0) {
|
|
252
|
-
const line = this.buffer.slice(0, index)
|
|
326
|
+
const line = this.buffer.slice(0, index);
|
|
253
327
|
this.buffer = this.buffer.slice(index + 1);
|
|
254
|
-
if (line) lines.push(line);
|
|
328
|
+
if (line.trim() || Buffer.byteLength(line, 'utf8') > MAX_JSONRPC_BUFFER_BYTES) lines.push(line);
|
|
255
329
|
index = this.buffer.indexOf('\n');
|
|
256
330
|
}
|
|
257
331
|
for (const line of lines) {
|
|
@@ -260,8 +334,9 @@ export class AcpServer {
|
|
|
260
334
|
}
|
|
261
335
|
|
|
262
336
|
async handleLine(line: string): Promise<void> {
|
|
337
|
+
if (this.closed) return;
|
|
263
338
|
const cleaned = line.replace(/^\uFEFF/, '').replace(/\r$/, '');
|
|
264
|
-
if (
|
|
339
|
+
if (Buffer.byteLength(line, 'utf8') > MAX_JSONRPC_BUFFER_BYTES) {
|
|
265
340
|
this.write({
|
|
266
341
|
jsonrpc: '2.0',
|
|
267
342
|
id: null,
|
|
@@ -299,10 +374,11 @@ export class AcpServer {
|
|
|
299
374
|
if (!this.isPlainParams(notification.params)) return;
|
|
300
375
|
if (notification.method === ACP_METHODS.CANCEL) {
|
|
301
376
|
const params = notification.params as CancelNotification | undefined;
|
|
302
|
-
const sid = params && typeof params.sessionId === 'string' ? params.sessionId
|
|
377
|
+
const sid = params && typeof params.sessionId === 'string' ? params.sessionId : '';
|
|
303
378
|
const session = sid ? this.sessions.get(sid) : undefined;
|
|
304
379
|
if (session) {
|
|
305
380
|
session.cancelled = true;
|
|
381
|
+
session.generation++;
|
|
306
382
|
this.rejectPendingForSession(session.id, 'session cancelled');
|
|
307
383
|
try {
|
|
308
384
|
session.loop?.abort();
|
|
@@ -331,6 +407,12 @@ export class AcpServer {
|
|
|
331
407
|
case ACP_METHODS.SET_MODE:
|
|
332
408
|
this.writeResult(request.id, this.setMode(request.params as SetSessionModeRequest | undefined));
|
|
333
409
|
return;
|
|
410
|
+
case ACP_METHODS.SET_MODEL:
|
|
411
|
+
this.writeResult(request.id, this.setModel(request.params as SetSessionModelRequest | undefined));
|
|
412
|
+
return;
|
|
413
|
+
case ACP_METHODS.SET_CONFIG_OPTION:
|
|
414
|
+
this.writeResult(request.id, this.setConfigOption(request.params as SetSessionConfigOptionRequest | undefined));
|
|
415
|
+
return;
|
|
334
416
|
case ACP_METHODS.LIST:
|
|
335
417
|
this.writeResult(request.id, this.listSessions(request.params as ListSessionsRequest | undefined));
|
|
336
418
|
return;
|
|
@@ -380,20 +462,94 @@ export class AcpServer {
|
|
|
380
462
|
return error;
|
|
381
463
|
}
|
|
382
464
|
|
|
465
|
+
private parseSessionMcpServers(raw: unknown, cwd: string): McpServerDefinition[] {
|
|
466
|
+
if (raw === undefined) return [];
|
|
467
|
+
if (!Array.isArray(raw)) {
|
|
468
|
+
throw this.paramsError('mcpServers must be an array');
|
|
469
|
+
}
|
|
470
|
+
if (raw.length > MAX_SESSION_MCP_SERVERS) {
|
|
471
|
+
throw this.paramsError(`Maximum ${MAX_SESSION_MCP_SERVERS} MCP servers per session exceeded`);
|
|
472
|
+
}
|
|
473
|
+
const definitions: McpServerDefinition[] = [];
|
|
474
|
+
for (const entry of raw) {
|
|
475
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
|
|
476
|
+
throw this.paramsError('Each MCP server entry must be an object');
|
|
477
|
+
}
|
|
478
|
+
const item = entry as Record<string, unknown>;
|
|
479
|
+
const rawType = typeof item.type === 'string' ? item.type.trim().toLowerCase() : '';
|
|
480
|
+
if (rawType === 'http' || rawType === 'sse' || typeof item.url === 'string') {
|
|
481
|
+
throw this.paramsError('HTTP/SSE MCP servers are not supported by this agent');
|
|
482
|
+
}
|
|
483
|
+
if (typeof item.name !== 'string' || !item.name.trim()) {
|
|
484
|
+
throw this.paramsError('Stdio MCP server requires a non-empty name');
|
|
485
|
+
}
|
|
486
|
+
if (typeof item.command !== 'string' || !item.command.trim()) {
|
|
487
|
+
throw this.paramsError('Stdio MCP server requires a non-empty command');
|
|
488
|
+
}
|
|
489
|
+
if (!Array.isArray(item.args) || !item.args.every((arg) => typeof arg === 'string')) {
|
|
490
|
+
throw this.paramsError('Stdio MCP server requires an args string array');
|
|
491
|
+
}
|
|
492
|
+
let env: Record<string, string> | undefined;
|
|
493
|
+
if (item.env !== undefined) {
|
|
494
|
+
const mapped = Object.create(null) as Record<string, string>;
|
|
495
|
+
if (Array.isArray(item.env)) {
|
|
496
|
+
for (const pair of item.env) {
|
|
497
|
+
if (!pair || typeof pair !== 'object' || Array.isArray(pair)) {
|
|
498
|
+
throw this.paramsError('Stdio MCP server env entries must be { name, value } objects');
|
|
499
|
+
}
|
|
500
|
+
const rec = pair as Record<string, unknown>;
|
|
501
|
+
if (typeof rec.name !== 'string' || !rec.name || typeof rec.value !== 'string') {
|
|
502
|
+
throw this.paramsError('Stdio MCP server env entries require string name and value');
|
|
503
|
+
}
|
|
504
|
+
if (!FORBIDDEN_ENV_KEYS.has(rec.name)) mapped[rec.name] = rec.value;
|
|
505
|
+
}
|
|
506
|
+
} else if (typeof item.env === 'object' && item.env !== null) {
|
|
507
|
+
for (const [k, v] of Object.entries(item.env as Record<string, unknown>)) {
|
|
508
|
+
if (typeof v !== 'string') {
|
|
509
|
+
throw this.paramsError('Stdio MCP server env values must be strings');
|
|
510
|
+
}
|
|
511
|
+
if (!FORBIDDEN_ENV_KEYS.has(k)) mapped[k] = v;
|
|
512
|
+
}
|
|
513
|
+
} else {
|
|
514
|
+
throw this.paramsError('Stdio MCP server env must be an array or object');
|
|
515
|
+
}
|
|
516
|
+
if (Object.keys(mapped).length > 0) env = { ...mapped };
|
|
517
|
+
}
|
|
518
|
+
const def: McpServerDefinition = {
|
|
519
|
+
name: item.name.trim(),
|
|
520
|
+
command: item.command.trim(),
|
|
521
|
+
args: [...item.args],
|
|
522
|
+
...(env ? { env } : {}),
|
|
523
|
+
cwd
|
|
524
|
+
};
|
|
525
|
+
const problem = McpClient.validateDefinition(def);
|
|
526
|
+
if (problem) {
|
|
527
|
+
throw this.paramsError(`Invalid MCP server "${def.name}": ${problem}`);
|
|
528
|
+
}
|
|
529
|
+
definitions.push(def);
|
|
530
|
+
}
|
|
531
|
+
return definitions;
|
|
532
|
+
}
|
|
533
|
+
|
|
383
534
|
private newSession(params: NewSessionRequest | undefined): NewSessionResponse {
|
|
384
535
|
if (!params || typeof params.cwd !== 'string' || !params.cwd.trim()) {
|
|
385
536
|
throw this.paramsError('session/new requires cwd');
|
|
386
537
|
}
|
|
387
|
-
if (Array.isArray(params.
|
|
388
|
-
throw this.paramsError('MCP servers are not supported by this agent');
|
|
389
|
-
}
|
|
390
|
-
if (Array.isArray(params.additionalDirectories) && params.additionalDirectories.length > 0) {
|
|
538
|
+
if (params.additionalDirectories !== undefined && (!Array.isArray(params.additionalDirectories) || params.additionalDirectories.length > 0)) {
|
|
391
539
|
throw this.paramsError('additionalDirectories is not supported by this agent');
|
|
392
540
|
}
|
|
393
541
|
const cwd = this.resolveWorkspace(params.cwd);
|
|
542
|
+
const mcpServers = this.parseSessionMcpServers(params.mcpServers, cwd);
|
|
394
543
|
this.bindWorkspace(cwd);
|
|
544
|
+
if (this.sessions.size >= MAX_SESSIONS) {
|
|
545
|
+
throw this.paramsError(`Maximum concurrent sessions (${MAX_SESSIONS}) exceeded`);
|
|
546
|
+
}
|
|
395
547
|
const record = createSession(cwd, 'Untitled', false);
|
|
396
548
|
const session = this.addSession(record.id, cwd, record.title, MODES.currentModeId);
|
|
549
|
+
if (mcpServers.length > 0) {
|
|
550
|
+
session.mcpServers = mcpServers;
|
|
551
|
+
registerSessionMcpServers(session.id, mcpServers);
|
|
552
|
+
}
|
|
397
553
|
return this.sessionResponse(session);
|
|
398
554
|
}
|
|
399
555
|
|
|
@@ -436,6 +592,8 @@ export class AcpServer {
|
|
|
436
592
|
cancelled: false,
|
|
437
593
|
updatedAt: Date.now(),
|
|
438
594
|
queue: Promise.resolve(),
|
|
595
|
+
generation: 0,
|
|
596
|
+
pendingPrompts: 0,
|
|
439
597
|
approvalScope: createApprovalScope()
|
|
440
598
|
};
|
|
441
599
|
this.sessions.set(id, session);
|
|
@@ -449,10 +607,97 @@ export class AcpServer {
|
|
|
449
607
|
};
|
|
450
608
|
}
|
|
451
609
|
|
|
610
|
+
private buildSessionCatalog(session: AcpSession): { models?: SessionModelState; configOptions?: SessionConfigOption[] } {
|
|
611
|
+
let config: Record<string, unknown> = {};
|
|
612
|
+
try {
|
|
613
|
+
config = loadConfig() as Record<string, unknown>;
|
|
614
|
+
} catch {
|
|
615
|
+
config = {};
|
|
616
|
+
}
|
|
617
|
+
const provider = typeof config.provider === 'string' && config.provider.trim()
|
|
618
|
+
? config.provider.trim()
|
|
619
|
+
: 'deepseek';
|
|
620
|
+
const configuredModel = typeof config.model === 'string' && config.model.trim()
|
|
621
|
+
? config.model.trim()
|
|
622
|
+
: (DEFAULT_MODEL_BY_PROVIDER[provider.toLowerCase()] || '');
|
|
623
|
+
const activeModel = session.model || configuredModel;
|
|
624
|
+
const seen = new Set<string>();
|
|
625
|
+
const modelIds: string[] = [];
|
|
626
|
+
const addModel = (id: string) => {
|
|
627
|
+
const clean = id.trim();
|
|
628
|
+
if (!clean || seen.has(clean)) return;
|
|
629
|
+
seen.add(clean);
|
|
630
|
+
modelIds.push(clean);
|
|
631
|
+
};
|
|
632
|
+
if (activeModel) addModel(activeModel);
|
|
633
|
+
if (configuredModel) addModel(configuredModel);
|
|
634
|
+
for (const candidate of providerModelsForCatalogue(provider)) {
|
|
635
|
+
addModel(candidate);
|
|
636
|
+
if (modelIds.length >= 64) break;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
const configOptions: SessionConfigOption[] = [];
|
|
640
|
+
const primaryModelId = activeModel || modelIds[0];
|
|
641
|
+
if (modelIds.length > 0 && primaryModelId) {
|
|
642
|
+
configOptions.push({
|
|
643
|
+
id: 'model',
|
|
644
|
+
name: 'Model',
|
|
645
|
+
category: 'model',
|
|
646
|
+
type: 'select',
|
|
647
|
+
currentValue: primaryModelId,
|
|
648
|
+
options: modelIds.map((id) => ({ value: id, name: id }))
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
const currentVariant = session.variant
|
|
653
|
+
|| (typeof config.reasoningEffort === 'string' && config.reasoningEffort.trim() ? config.reasoningEffort.trim() : undefined);
|
|
654
|
+
if (activeModel) {
|
|
655
|
+
try {
|
|
656
|
+
const variantSpec = resolveModelVariants({
|
|
657
|
+
provider,
|
|
658
|
+
model: activeModel,
|
|
659
|
+
currentVariant: currentVariant ?? null
|
|
660
|
+
});
|
|
661
|
+
if (variantSpec.supported && variantSpec.options.length > 0) {
|
|
662
|
+
const resolvedVariant = currentVariant || variantSpec.defaultVariant || variantSpec.options[0]?.id;
|
|
663
|
+
configOptions.push({
|
|
664
|
+
id: 'thought_level',
|
|
665
|
+
name: 'Reasoning effort',
|
|
666
|
+
category: 'thought_level',
|
|
667
|
+
type: 'select',
|
|
668
|
+
...(resolvedVariant ? { currentValue: resolvedVariant } : {}),
|
|
669
|
+
options: variantSpec.options.map((opt) => ({
|
|
670
|
+
value: opt.id,
|
|
671
|
+
name: opt.label,
|
|
672
|
+
description: opt.description
|
|
673
|
+
}))
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
} catch {
|
|
677
|
+
// Variant discovery is best-effort; never fail session creation.
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
const models: SessionModelState | undefined = modelIds.length > 0 && primaryModelId
|
|
682
|
+
? {
|
|
683
|
+
currentModelId: primaryModelId,
|
|
684
|
+
availableModels: modelIds.map((id) => ({ modelId: id, name: id }))
|
|
685
|
+
}
|
|
686
|
+
: undefined;
|
|
687
|
+
|
|
688
|
+
return {
|
|
689
|
+
...(models ? { models } : {}),
|
|
690
|
+
...(configOptions.length > 0 ? { configOptions } : {})
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
|
|
452
694
|
private sessionResponse(session: AcpSession): NewSessionResponse {
|
|
695
|
+
const catalog = this.buildSessionCatalog(session);
|
|
453
696
|
return {
|
|
454
697
|
sessionId: session.id,
|
|
455
|
-
modes: this.modesFor(session)
|
|
698
|
+
modes: this.modesFor(session),
|
|
699
|
+
...(catalog.models ? { models: catalog.models } : {}),
|
|
700
|
+
...(catalog.configOptions ? { configOptions: catalog.configOptions } : {})
|
|
456
701
|
};
|
|
457
702
|
}
|
|
458
703
|
|
|
@@ -476,42 +721,76 @@ export class AcpServer {
|
|
|
476
721
|
if (text === null || !text.trim()) {
|
|
477
722
|
return { stopReason: 'refusal' };
|
|
478
723
|
}
|
|
479
|
-
session.
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
724
|
+
if (session.pendingPrompts >= MAX_PENDING_PROMPTS_PER_SESSION || this.pendingPrompts >= MAX_PENDING_PROMPTS) {
|
|
725
|
+
throw this.paramsError('Session prompt queue is full');
|
|
726
|
+
}
|
|
727
|
+
session.pendingPrompts++;
|
|
728
|
+
this.pendingPrompts++;
|
|
729
|
+
const generation = session.generation;
|
|
730
|
+
const execute = (): Promise<StopReason> => generation === session.generation ? this.runTurn(session, text) : Promise.resolve('cancelled');
|
|
731
|
+
session.queue = session.queue.then(execute, execute);
|
|
732
|
+
try {
|
|
733
|
+
const stopReason = await session.queue as StopReason;
|
|
734
|
+
return { stopReason };
|
|
735
|
+
} finally {
|
|
736
|
+
session.pendingPrompts--;
|
|
737
|
+
this.pendingPrompts--;
|
|
738
|
+
}
|
|
485
739
|
}
|
|
486
740
|
|
|
487
741
|
private async runTurn(session: AcpSession, text: string): Promise<StopReason> {
|
|
488
|
-
if (this.closed ||
|
|
742
|
+
if (this.closed || this.sessions.get(session.id) !== session) {
|
|
489
743
|
return 'cancelled';
|
|
490
744
|
}
|
|
491
745
|
session.updatedAt = Date.now();
|
|
492
746
|
session.cancelled = false;
|
|
747
|
+
this.assistantStreams.delete(session);
|
|
748
|
+
this.reasoningStreams.delete(session);
|
|
749
|
+
this.failedTurns.delete(session);
|
|
493
750
|
session.busy = true;
|
|
494
751
|
const taskId = `acp-${crypto.randomUUID()}`;
|
|
752
|
+
let acceptingEvents = true;
|
|
495
753
|
const sink = {
|
|
496
754
|
readyState: 1,
|
|
497
|
-
send: (payload: string) => this.onLoopPayload(session, payload)
|
|
755
|
+
send: (payload: string) => { if (acceptingEvents && !session.cancelled && this.sessions.get(session.id) === session) this.onLoopPayload(session, payload); }
|
|
498
756
|
};
|
|
757
|
+
const peerMcpServers = Array.isArray(session.mcpServers) && session.mcpServers.length > 0
|
|
758
|
+
? session.mcpServers
|
|
759
|
+
.filter((def): def is McpServerDefinition & { command: string } => typeof def.command === 'string' && def.command.length > 0)
|
|
760
|
+
.map((def) => ({
|
|
761
|
+
name: def.name,
|
|
762
|
+
command: def.command,
|
|
763
|
+
args: Array.isArray(def.args) ? [...def.args] : [],
|
|
764
|
+
env: Object.entries(def.env ?? {}).map(([name, value]) => ({ name, value }))
|
|
765
|
+
}))
|
|
766
|
+
: [];
|
|
499
767
|
const loopOptions = {
|
|
500
768
|
workspaceRoot: session.cwd,
|
|
501
769
|
memorySessionId: session.memorySessionId,
|
|
502
|
-
approvalScope: session.approvalScope
|
|
770
|
+
approvalScope: session.approvalScope,
|
|
771
|
+
...(session.model ? { model: session.model } : {}),
|
|
772
|
+
...(session.variant ? { variant: session.variant } : {}),
|
|
773
|
+
...(peerMcpServers.length > 0 ? { peerMcpServers } : {})
|
|
503
774
|
};
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
775
|
+
let loop: AgentLoop;
|
|
776
|
+
try {
|
|
777
|
+
loop = this.loopFactory
|
|
778
|
+
? this.loopFactory({
|
|
779
|
+
sessionId: session.id,
|
|
780
|
+
memorySessionId: session.memorySessionId,
|
|
781
|
+
taskId,
|
|
782
|
+
userPrompt: text,
|
|
783
|
+
cwd: session.cwd,
|
|
784
|
+
sink,
|
|
785
|
+
approvalScope: session.approvalScope
|
|
786
|
+
})
|
|
787
|
+
: new AgentLoop(sink, taskId, text, loopOptions);
|
|
788
|
+
} catch {
|
|
789
|
+
acceptingEvents = false;
|
|
790
|
+
session.busy = false;
|
|
791
|
+
session.loop = null;
|
|
792
|
+
return 'refusal';
|
|
793
|
+
}
|
|
515
794
|
const autonomy = MODE_TO_AUTONOMY[session.modeId];
|
|
516
795
|
if (autonomy) {
|
|
517
796
|
try {
|
|
@@ -525,12 +804,15 @@ export class AcpServer {
|
|
|
525
804
|
let stopReason: StopReason = 'end_turn';
|
|
526
805
|
try {
|
|
527
806
|
await loop.run();
|
|
807
|
+
if (this.failedTurns.has(session)) stopReason = 'refusal';
|
|
528
808
|
} catch {
|
|
529
809
|
stopReason = 'refusal';
|
|
530
810
|
} finally {
|
|
811
|
+
acceptingEvents = false;
|
|
531
812
|
session.loop = null;
|
|
532
813
|
session.busy = false;
|
|
533
|
-
if (this.sessions.
|
|
814
|
+
if (this.sessions.get(session.id) === session) {
|
|
815
|
+
this.rejectPendingForSession(session.id, 'turn ended');
|
|
534
816
|
const record = getSession(session.memorySessionId);
|
|
535
817
|
if (record) session.title = safeDisplay(record.title).replace(/\s+/g, ' ').trim() || session.title;
|
|
536
818
|
}
|
|
@@ -540,6 +822,7 @@ export class AcpServer {
|
|
|
540
822
|
}
|
|
541
823
|
|
|
542
824
|
private requestDecision(session: AcpSession, loop: AgentLoop, request: unknown): Promise<{ optionId: string; label: string } | null> {
|
|
825
|
+
if (this.closed || session.cancelled || session.loop !== loop || this.sessions.get(session.id) !== session) return Promise.resolve(null);
|
|
543
826
|
if (request === null || typeof request !== 'object' || Array.isArray(request)) return Promise.resolve(null);
|
|
544
827
|
const record = request as Record<string, unknown>;
|
|
545
828
|
const options = Array.isArray(record.options) ? record.options : [];
|
|
@@ -551,6 +834,7 @@ export class AcpServer {
|
|
|
551
834
|
const id = typeof item.id === 'string' ? item.id : '';
|
|
552
835
|
const label = typeof item.label === 'string' ? item.label : id;
|
|
553
836
|
if (!id) continue;
|
|
837
|
+
if (labels.has(id)) return Promise.resolve(null);
|
|
554
838
|
labels.set(id, label);
|
|
555
839
|
permissionOptions.push({ optionId: id, name: label, kind: 'allow_once' });
|
|
556
840
|
}
|
|
@@ -566,7 +850,7 @@ export class AcpServer {
|
|
|
566
850
|
toolCall,
|
|
567
851
|
options: permissionOptions
|
|
568
852
|
}).then((response) => {
|
|
569
|
-
if (session.cancelled ||
|
|
853
|
+
if (this.closed || session.cancelled || session.loop !== loop || this.sessions.get(session.id) !== session) return null;
|
|
570
854
|
const outcome = response && typeof response.outcome === 'object' && response.outcome !== null
|
|
571
855
|
? response.outcome
|
|
572
856
|
: null;
|
|
@@ -585,18 +869,31 @@ export class AcpServer {
|
|
|
585
869
|
} catch {
|
|
586
870
|
return;
|
|
587
871
|
}
|
|
872
|
+
if (!event || typeof event !== 'object' || Array.isArray(event) || typeof event.type !== 'string') return;
|
|
588
873
|
this.onLoopEvent(session, event);
|
|
589
874
|
}
|
|
590
875
|
|
|
591
876
|
private onLoopEvent(session: AcpSession, event: AgentLoopEvent): void {
|
|
592
877
|
switch (event.type) {
|
|
593
878
|
case 'agent_message': {
|
|
594
|
-
|
|
879
|
+
const text = String(event.content ?? '');
|
|
880
|
+
const key = typeof event.streamId === 'number' || typeof event.streamId === 'string' ? String(event.streamId) : '';
|
|
881
|
+
const previous = this.assistantStreams.get(session);
|
|
882
|
+
const tracked = Boolean(key) || event.streaming === true || previous?.key === '';
|
|
883
|
+
const sameStream = tracked && previous?.key === key;
|
|
884
|
+
const delta = sameStream && text.startsWith(previous.text) ? text.slice(previous.text.length) : text;
|
|
885
|
+
if (tracked) this.assistantStreams.set(session, { key, text });
|
|
886
|
+
if (event.streaming !== true && !key) this.assistantStreams.delete(session);
|
|
887
|
+
if (delta) this.notify(session.id, { sessionUpdate: 'agent_message_chunk', content: { type: 'text', text: delta } });
|
|
595
888
|
return;
|
|
596
889
|
}
|
|
597
890
|
case 'agent_reasoning': {
|
|
598
891
|
const text = String(event.content ?? '');
|
|
599
|
-
|
|
892
|
+
const previous = this.reasoningStreams.get(session) || '';
|
|
893
|
+
const delta = text.startsWith(previous) ? text.slice(previous.length) : text;
|
|
894
|
+
if (event.streaming === true) this.reasoningStreams.set(session, text);
|
|
895
|
+
else this.reasoningStreams.delete(session);
|
|
896
|
+
if (delta) this.notify(session.id, { sessionUpdate: 'agent_thought_chunk', content: { type: 'text', text: delta } });
|
|
600
897
|
return;
|
|
601
898
|
}
|
|
602
899
|
case 'status':
|
|
@@ -608,6 +905,7 @@ export class AcpServer {
|
|
|
608
905
|
case 'warning':
|
|
609
906
|
case 'budget_warning':
|
|
610
907
|
case 'error': {
|
|
908
|
+
if (event.type === 'error') this.failedTurns.add(session);
|
|
611
909
|
const text = String(event.message ?? 'Task error');
|
|
612
910
|
this.notify(session.id, { sessionUpdate: 'agent_message_chunk', content: { type: 'text', text } });
|
|
613
911
|
return;
|
|
@@ -671,6 +969,8 @@ export class AcpServer {
|
|
|
671
969
|
return;
|
|
672
970
|
}
|
|
673
971
|
case 'approval_request': {
|
|
972
|
+
const requestingLoop = session.loop;
|
|
973
|
+
if (!requestingLoop) return;
|
|
674
974
|
const toolCallId = String(event.toolCallId ?? '');
|
|
675
975
|
if (!toolCallId) return;
|
|
676
976
|
const args = event.args !== null && typeof event.args === 'object' && !Array.isArray(event.args)
|
|
@@ -694,8 +994,8 @@ export class AcpServer {
|
|
|
694
994
|
toolCall,
|
|
695
995
|
options
|
|
696
996
|
}).then((response) => {
|
|
697
|
-
if (session.cancelled ||
|
|
698
|
-
|
|
997
|
+
if (session.cancelled || session.loop !== requestingLoop || this.sessions.get(session.id) !== session) {
|
|
998
|
+
requestingLoop.handleApprovalResponse(toolCallId, false);
|
|
699
999
|
return;
|
|
700
1000
|
}
|
|
701
1001
|
const outcome = response && typeof response.outcome === 'object' && response.outcome !== null
|
|
@@ -707,9 +1007,9 @@ export class AcpServer {
|
|
|
707
1007
|
const canonicalTool = tool.replace(/\./g, '_');
|
|
708
1008
|
if (selected === 'allow_always') session.approvalScope.grantAlways(canonicalTool);
|
|
709
1009
|
const approved = selected === 'allow_once' || selected === 'allow_always';
|
|
710
|
-
|
|
1010
|
+
requestingLoop.handleApprovalResponse(toolCallId, approved);
|
|
711
1011
|
}).catch(() => {
|
|
712
|
-
|
|
1012
|
+
requestingLoop.handleApprovalResponse(toolCallId, false);
|
|
713
1013
|
});
|
|
714
1014
|
return;
|
|
715
1015
|
}
|
|
@@ -747,6 +1047,45 @@ export class AcpServer {
|
|
|
747
1047
|
return {};
|
|
748
1048
|
}
|
|
749
1049
|
|
|
1050
|
+
private setModel(params: SetSessionModelRequest | undefined): SetSessionModelResponse {
|
|
1051
|
+
if (!params || typeof params.modelId !== 'string' || !params.modelId.trim()) {
|
|
1052
|
+
throw this.paramsError('session/set_model requires a non-empty modelId');
|
|
1053
|
+
}
|
|
1054
|
+
const session = this.requireSession(params.sessionId);
|
|
1055
|
+
const modelId = params.modelId.trim();
|
|
1056
|
+
if (modelId.length > 200) throw this.paramsError('modelId is too long');
|
|
1057
|
+
session.model = modelId === 'default' ? undefined : modelId;
|
|
1058
|
+
session.updatedAt = Date.now();
|
|
1059
|
+
const { configOptions } = this.buildSessionCatalog(session);
|
|
1060
|
+
if (configOptions) {
|
|
1061
|
+
this.notify(session.id, { sessionUpdate: 'config_option_update', configOptions });
|
|
1062
|
+
}
|
|
1063
|
+
return configOptions ? { configOptions } : {};
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
private setConfigOption(params: SetSessionConfigOptionRequest | undefined): SetSessionConfigOptionResponse {
|
|
1067
|
+
if (!params || typeof params.configId !== 'string' || typeof params.value !== 'string') {
|
|
1068
|
+
throw this.paramsError('session/set_config_option requires configId and value');
|
|
1069
|
+
}
|
|
1070
|
+
const session = this.requireSession(params.sessionId);
|
|
1071
|
+
const configId = params.configId.trim().toLowerCase();
|
|
1072
|
+
const value = params.value.trim();
|
|
1073
|
+
if (!value || value.length > 200) throw this.paramsError('Invalid config option value');
|
|
1074
|
+
if (configId === 'model') {
|
|
1075
|
+
session.model = value === 'default' ? undefined : value;
|
|
1076
|
+
} else if (configId === 'thought_level' || configId === 'reasoning_effort' || configId === 'thinking' || configId === 'effort') {
|
|
1077
|
+
session.variant = value === 'default' || value === 'auto' ? undefined : value;
|
|
1078
|
+
} else {
|
|
1079
|
+
throw this.paramsError(`Unknown config option: ${params.configId}`);
|
|
1080
|
+
}
|
|
1081
|
+
session.updatedAt = Date.now();
|
|
1082
|
+
const { configOptions } = this.buildSessionCatalog(session);
|
|
1083
|
+
if (configOptions) {
|
|
1084
|
+
this.notify(session.id, { sessionUpdate: 'config_option_update', configOptions });
|
|
1085
|
+
}
|
|
1086
|
+
return configOptions ? { configOptions } : {};
|
|
1087
|
+
}
|
|
1088
|
+
|
|
750
1089
|
private canonicalizePath(targetPath: string): string {
|
|
751
1090
|
const resolved = path.resolve(targetPath);
|
|
752
1091
|
try {
|
|
@@ -775,6 +1114,7 @@ export class AcpServer {
|
|
|
775
1114
|
private closeSession(params: CloseSessionRequest | undefined): Record<string, never> {
|
|
776
1115
|
const session = this.requireSession(params?.sessionId);
|
|
777
1116
|
session.cancelled = true;
|
|
1117
|
+
session.generation++;
|
|
778
1118
|
this.rejectPendingForSession(session.id, 'session closed');
|
|
779
1119
|
try {
|
|
780
1120
|
session.loop?.abort();
|
|
@@ -782,6 +1122,7 @@ export class AcpServer {
|
|
|
782
1122
|
// Closing never blocks on cancellation.
|
|
783
1123
|
}
|
|
784
1124
|
this.sessions.delete(session.id);
|
|
1125
|
+
void unregisterSessionMcpServers(session.id);
|
|
785
1126
|
return {};
|
|
786
1127
|
}
|
|
787
1128
|
|
|
@@ -790,12 +1131,20 @@ export class AcpServer {
|
|
|
790
1131
|
if (!params || typeof params.sessionId !== 'string' || !params.sessionId) {
|
|
791
1132
|
throw this.paramsError('session/load requires sessionId');
|
|
792
1133
|
}
|
|
793
|
-
if (Array.isArray(params.mcpServers) && params.mcpServers.length > 0) {
|
|
794
|
-
throw this.paramsError('MCP servers are not supported by this agent');
|
|
795
|
-
}
|
|
796
1134
|
const live = this.sessions.get(params.sessionId);
|
|
797
1135
|
if (live) {
|
|
1136
|
+
if (params.cwd !== undefined && this.resolveWorkspace(params.cwd) !== live.cwd) {
|
|
1137
|
+
throw this.paramsError('session workspace does not match cwd');
|
|
1138
|
+
}
|
|
1139
|
+
if (live.busy || live.pendingPrompts > 0) {
|
|
1140
|
+
throw this.paramsError('session is busy; cancel it before loading');
|
|
1141
|
+
}
|
|
1142
|
+
const mcpServers = this.parseSessionMcpServers(params.mcpServers, live.cwd);
|
|
798
1143
|
this.bindWorkspace(live.cwd);
|
|
1144
|
+
if (mcpServers.length > 0) {
|
|
1145
|
+
live.mcpServers = mcpServers;
|
|
1146
|
+
registerSessionMcpServers(live.id, mcpServers);
|
|
1147
|
+
}
|
|
799
1148
|
this.replayTranscript(live, getSession(live.memorySessionId)?.messages ?? []);
|
|
800
1149
|
return { modes: this.modesFor(live) };
|
|
801
1150
|
}
|
|
@@ -806,8 +1155,13 @@ export class AcpServer {
|
|
|
806
1155
|
if (record.workspace && this.canonicalizePath(record.workspace) !== cwd) {
|
|
807
1156
|
throw this.paramsError('session workspace does not match cwd');
|
|
808
1157
|
}
|
|
1158
|
+
const mcpServers = this.parseSessionMcpServers(params.mcpServers, cwd);
|
|
809
1159
|
this.bindWorkspace(cwd);
|
|
810
1160
|
const session = this.addSession(record.id, cwd, record.title, MODES.currentModeId);
|
|
1161
|
+
if (mcpServers.length > 0) {
|
|
1162
|
+
session.mcpServers = mcpServers;
|
|
1163
|
+
registerSessionMcpServers(session.id, mcpServers);
|
|
1164
|
+
}
|
|
811
1165
|
this.replayTranscript(session, record.messages);
|
|
812
1166
|
return { modes: this.modesFor(session) };
|
|
813
1167
|
}
|
|
@@ -824,7 +1178,7 @@ export class AcpServer {
|
|
|
824
1178
|
const source = this.sessions.get(params.sessionId);
|
|
825
1179
|
const sourceRecord = getSession(params.sessionId);
|
|
826
1180
|
if (!source && !sourceRecord) throw this.notFound(`Unknown session: ${params.sessionId}`);
|
|
827
|
-
if (source
|
|
1181
|
+
if (source && (source.busy || source.pendingPrompts > 0)) throw this.paramsError('session is busy; cancel it before forking');
|
|
828
1182
|
const requested = params.cwd ?? source?.cwd ?? sourceRecord?.workspace;
|
|
829
1183
|
const cwd = this.resolveWorkspace(requested);
|
|
830
1184
|
if (source && source.cwd !== cwd) throw this.paramsError('fork must stay in the source workspace');
|
|
@@ -833,6 +1187,9 @@ export class AcpServer {
|
|
|
833
1187
|
}
|
|
834
1188
|
this.bindWorkspace(cwd);
|
|
835
1189
|
const title = `Fork of ${source?.title || sourceRecord?.title || 'Untitled'}`;
|
|
1190
|
+
if (this.sessions.size >= MAX_SESSIONS) {
|
|
1191
|
+
throw this.paramsError(`Maximum concurrent sessions (${MAX_SESSIONS}) exceeded`);
|
|
1192
|
+
}
|
|
836
1193
|
const forked = forkSession(params.sessionId, { title, makeActive: false, workspace: cwd });
|
|
837
1194
|
if (!forked) throw this.paramsError('Failed to fork session journal');
|
|
838
1195
|
const session = this.addSession(forked.id, cwd, title, source?.modeId ?? MODES.currentModeId);
|