@causyne/agent 1.20.124 → 1.20.128
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 +1 -1
- package/docs/THIRD_PARTY_NOTICES.md +36 -2
- package/package.json +6 -4
- package/src/acp/protocol.ts +19 -1
- package/src/acp/server.js +282 -8
- package/src/acp/server.ts +284 -8
- package/src/agent/abortableDelay.js +2 -2
- package/src/agent/abortableDelay.ts +2 -2
- package/src/agent/errorClassifier.js +9 -1
- package/src/agent/errorClassifier.ts +8 -1
- package/src/agentLoop.js +142 -53
- package/src/agentLoop.ts +151 -50
- package/src/approvalPolicy.js +34 -10
- package/src/approvalPolicy.ts +42 -11
- package/src/browser/causyneBrowser.js +61 -3
- package/src/browser/causyneBrowser.ts +65 -3
- package/src/browser/urlPolicy.js +14 -1
- package/src/browser/urlPolicy.ts +12 -1
- package/src/cliMode.js +21 -9
- package/src/cliMode.ts +20 -8
- package/src/commands.js +365 -45
- package/src/commands.ts +403 -45
- package/src/config.js +19 -4
- package/src/config.ts +18 -4
- package/src/core/contextCompactor.js +54 -7
- package/src/core/contextCompactor.ts +63 -7
- package/src/core/goalLoop.js +257 -0
- package/src/core/goalLoop.ts +310 -0
- package/src/entrypoint.js +135 -3
- package/src/entrypoint.ts +136 -3
- 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/headlessCli.js +19 -12
- package/src/headlessCli.ts +22 -8
- package/src/infra/atomicWriter.js +40 -4
- package/src/infra/atomicWriter.ts +36 -4
- package/src/launchIntent.js +73 -3
- package/src/launchIntent.ts +76 -3
- package/src/lsp/lspClient.js +83 -12
- package/src/lsp/lspClient.ts +75 -12
- package/src/mcp/mcpRegistry.js +75 -8
- package/src/mcp/mcpRegistry.ts +70 -7
- package/src/memory/contextBudget.js +2 -0
- package/src/memory/contextBudget.ts +1 -0
- package/src/memory/episodicStore.js +40 -0
- package/src/memory/episodicStore.ts +46 -0
- package/src/memory.js +67 -0
- package/src/memory.ts +65 -0
- package/src/modelVariants.js +45 -0
- package/src/modelVariants.ts +54 -0
- package/src/outputRecovery.js +3 -2
- package/src/outputRecovery.ts +4 -2
- package/src/permissionPresets.js +327 -0
- package/src/permissionPresets.ts +361 -0
- package/src/personalization.js +365 -0
- package/src/personalization.ts +471 -0
- package/src/projectInstructions.js +30 -10
- package/src/projectInstructions.ts +31 -12
- package/src/providers/acp.js +3 -2
- package/src/providers/acp.ts +3 -2
- package/src/providers/antigravity.js +64 -9
- package/src/providers/antigravity.ts +75 -9
- package/src/providers/byokHttp.js +7 -1
- package/src/providers/byokHttp.ts +6 -1
- package/src/providers/byokStream.js +21 -8
- package/src/providers/byokStream.ts +17 -7
- package/src/providers/dashscope-byok.js +21 -5
- package/src/providers/dashscope-byok.ts +29 -11
- package/src/providers/moonshot.js +26 -7
- package/src/providers/moonshot.ts +34 -13
- package/src/providers/muse.js +6 -0
- package/src/providers/muse.ts +8 -0
- package/src/providers/ollama.js +39 -7
- package/src/providers/ollama.ts +36 -7
- package/src/providers/openai-compatible.js +16 -3
- package/src/providers/openai-compatible.ts +13 -3
- package/src/providers/openai.js +62 -4
- package/src/providers/openai.ts +50 -4
- package/src/providers/openrouter.js +19 -4
- package/src/providers/openrouter.ts +21 -4
- package/src/providers/qwen-byok.js +21 -5
- package/src/providers/qwen-byok.ts +29 -11
- package/src/providers/xai.js +26 -10
- package/src/providers/xai.ts +34 -16
- package/src/reporting.js +4 -2
- package/src/reporting.ts +4 -2
- package/src/sandbox.js +34 -0
- package/src/sandbox.ts +43 -0
- package/src/scheduler/scheduler.js +372 -0
- package/src/scheduler/scheduler.ts +433 -0
- package/src/sessionSearchIndex.js +267 -0
- package/src/sessionSearchIndex.ts +311 -0
- package/src/skillsManager.js +2 -3
- package/src/skillsManager.ts +2 -3
- package/src/toolPacks.js +6 -0
- package/src/toolPacks.ts +6 -0
- package/src/tools/applyPatch.js +1 -1
- package/src/tools/applyPatch.ts +1 -1
- package/src/tools/generateMediaViaApi.js +4 -3
- package/src/tools/generateMediaViaApi.ts +4 -3
- package/src/tools/memoryWrite.js +15 -1
- package/src/tools/memoryWrite.ts +16 -1
- 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 +1 -1
- package/src/tools/osSandbox.ts +1 -1
- package/src/tools/payloadSanitizer.js +0 -1
- package/src/tools/payloadSanitizer.ts +0 -1
- package/src/tools/pdfReader.js +122 -20
- package/src/tools/pdfReader.ts +111 -20
- package/src/tools/presentDeliverable.js +103 -0
- package/src/tools/presentDeliverable.ts +127 -0
- package/src/tools/ptcRuntime.js +444 -0
- package/src/tools/ptcRuntime.ts +490 -0
- package/src/tools/ptyTerminal.js +1108 -0
- package/src/tools/ptyTerminal.ts +1245 -0
- package/src/tools/registry.js +21 -12
- package/src/tools/registry.ts +21 -12
- package/src/tools/toolOutputStore.js +26 -4
- package/src/tools/toolOutputStore.ts +22 -4
- package/src/tools/webFetch.js +158 -11
- package/src/tools/webFetch.ts +145 -11
- package/src/tools/webSearch.js +123 -36
- package/src/tools/webSearch.ts +124 -33
- package/src/tui/banner.js +5 -1
- package/src/tui/banner.ts +6 -1
- package/src/tui/chatRenderer.js +1 -2
- package/src/tui/chatRenderer.ts +1 -2
- package/src/tui/completion.js +1 -0
- package/src/tui/completion.ts +1 -0
- package/src/tui/composerControls.js +111 -27
- package/src/tui/composerControls.ts +124 -28
- package/src/tui/dialogs.js +3 -16
- package/src/tui/dialogs.ts +3 -16
- package/src/tui/home.js +1 -0
- package/src/tui/home.ts +1 -0
- package/src/tui/invocation.js +1 -2
- package/src/tui/invocation.ts +1 -2
- package/src/tui/modelPicker.js +22 -12
- package/src/tui/modelPicker.ts +22 -12
- package/src/tui/overlay.js +2 -5
- package/src/tui/overlay.ts +2 -5
- package/src/tui/prompt.js +6 -4
- package/src/tui/prompt.ts +6 -4
- package/src/tui/selectList.js +4 -12
- package/src/tui/selectList.ts +4 -12
- package/src/tui/setup.js +22 -9
- package/src/tui/setup.ts +26 -9
- package/src/tui/statusLine.ts +2 -0
- package/src/web/client/browserPanel.js +905 -0
- package/src/web/client/browserPanel.ts +872 -0
- package/src/web/client/chatStream.js +321 -0
- package/src/web/client/chatStream.ts +297 -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 +271 -0
- package/src/web/client/dom.ts +272 -0
- package/src/web/client/filesAndCanvas.js +233 -0
- package/src/web/client/filesAndCanvas.ts +240 -0
- package/src/web/client/gameLauncherUi.js +78 -0
- package/src/web/client/gameLauncherUi.ts +78 -0
- package/src/web/client/main.js +316 -0
- package/src/web/client/main.ts +391 -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 +824 -0
- package/src/web/client/settingsModal.ts +959 -0
- package/src/web/client/state.js +280 -0
- package/src/web/client/state.ts +259 -0
- package/src/web/client/streamSmoother.js +127 -0
- package/src/web/client/streamSmoother.ts +119 -0
- package/src/web/client/studioLayout.js +89 -0
- package/src/web/client/studioLayout.ts +103 -0
- package/src/web/client/studioShell.js +660 -0
- package/src/web/client/studioShell.ts +672 -0
- package/src/web/client/studioStart.js +77 -0
- package/src/web/client/studioStart.ts +89 -0
- package/src/web/client/terminalPanel.js +606 -0
- package/src/web/client/terminalPanel.ts +632 -0
- package/src/web/client/terminalTheme.js +249 -0
- package/src/web/client/terminalTheme.ts +258 -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 +322 -0
- package/src/web/client/validators.js +147 -0
- package/src/web/client/validators.ts +140 -0
- package/src/web/server/activeRuns.js +152 -0
- package/src/web/server/activeRuns.ts +171 -0
- package/src/web/server/routesBrowser.js +409 -0
- package/src/web/server/routesBrowser.ts +435 -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/routesSettings.js +344 -0
- package/src/web/server/routesSettings.ts +397 -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 +104 -0
- package/src/web/server/staticAssets.ts +116 -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/skybridgeServer.js +78 -2448
- package/src/web/skybridgeServer.ts +120 -2600
- package/src/web/skybridgeUi.js +20 -450
- package/src/web/skybridgeUi.ts +24 -455
- package/src/web/styles/agent.css +380 -0
- package/src/web/styles/composer.css +193 -0
- package/src/web/styles/overlays.css +935 -0
- package/src/web/styles/shell.css +387 -0
- package/src/web/styles/studio.css +951 -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 +388 -0
- package/src/web/ui/modalsTemplate.ts +388 -0
- package/src/web/ui/sidebarTemplate.js +63 -0
- package/src/web/ui/sidebarTemplate.ts +64 -0
- package/src/web/ui/studioTemplate.js +256 -0
- package/src/web/ui/studioTemplate.ts +256 -0
- package/src/web/ui/workspaceTemplate.js +72 -0
- package/src/web/ui/workspaceTemplate.ts +73 -0
- package/src/worktreeManager.js +16 -1
- package/src/worktreeManager.ts +22 -1
- package/src/web/skybridgeClientScript.js +0 -3951
- package/src/web/skybridgeClientScript.ts +0 -3952
- package/src/web/skybridgeStyles.js +0 -827
- package/src/web/skybridgeStyles.ts +0 -828
package/src/acp/server.ts
CHANGED
|
@@ -6,6 +6,12 @@ import { AgentLoop } from '../agentLoop.js';
|
|
|
6
6
|
import type { AgentLoopEvent } from '../agentLoop.js';
|
|
7
7
|
import { createApprovalScope } from '../approvalGrants.js';
|
|
8
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';
|
|
9
15
|
import { createSession, getSession, saveSessionMessages, forkSession } from '../sessionJournal.js';
|
|
10
16
|
import { isBlockedWorkspaceRoot } from '../sandboxPolicy.js';
|
|
11
17
|
import { safeDisplay } from '../tui/text.js';
|
|
@@ -40,11 +46,17 @@ import type {
|
|
|
40
46
|
PromptRequest,
|
|
41
47
|
PromptResponse,
|
|
42
48
|
RequestPermissionResponse,
|
|
49
|
+
SessionConfigOption,
|
|
43
50
|
SessionInfo,
|
|
51
|
+
SessionModelState,
|
|
44
52
|
SessionModeState,
|
|
45
53
|
SessionNotification,
|
|
46
54
|
SessionUpdate,
|
|
55
|
+
SetSessionConfigOptionRequest,
|
|
56
|
+
SetSessionConfigOptionResponse,
|
|
47
57
|
SetSessionModeRequest,
|
|
58
|
+
SetSessionModelRequest,
|
|
59
|
+
SetSessionModelResponse,
|
|
48
60
|
StopReason,
|
|
49
61
|
ToolCall,
|
|
50
62
|
ToolCallStatus,
|
|
@@ -90,6 +102,9 @@ interface AcpSession {
|
|
|
90
102
|
title: string;
|
|
91
103
|
cwd: string;
|
|
92
104
|
modeId: string;
|
|
105
|
+
model?: string | undefined;
|
|
106
|
+
variant?: string | undefined;
|
|
107
|
+
mcpServers?: McpServerDefinition[] | undefined;
|
|
93
108
|
loop: AgentLoop | null;
|
|
94
109
|
busy: boolean;
|
|
95
110
|
cancelled: boolean;
|
|
@@ -101,6 +116,41 @@ interface AcpSession {
|
|
|
101
116
|
approvalScope: ApprovalScope;
|
|
102
117
|
}
|
|
103
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
|
+
|
|
104
154
|
const MODE_TO_AUTONOMY: Record<string, 'A' | 'B' | 'C'> = {
|
|
105
155
|
autonomous: 'C',
|
|
106
156
|
standard: 'B',
|
|
@@ -250,6 +300,7 @@ export class AcpServer {
|
|
|
250
300
|
if (this.input && this.endListener) this.input.off('end', this.endListener);
|
|
251
301
|
if (this.input && this.errorListener) this.input.off('error', this.errorListener);
|
|
252
302
|
this.buffer = '';
|
|
303
|
+
const closingIds = [...this.sessions.keys()];
|
|
253
304
|
for (const session of this.sessions.values()) {
|
|
254
305
|
session.cancelled = true;
|
|
255
306
|
session.generation++;
|
|
@@ -260,6 +311,7 @@ export class AcpServer {
|
|
|
260
311
|
}
|
|
261
312
|
}
|
|
262
313
|
this.sessions.clear();
|
|
314
|
+
await Promise.allSettled(closingIds.map((id) => unregisterSessionMcpServers(id)));
|
|
263
315
|
for (const [id, pending] of this.pending) {
|
|
264
316
|
clearTimeout(pending.timer);
|
|
265
317
|
pending.reject(new Error('server stopped'));
|
|
@@ -355,6 +407,12 @@ export class AcpServer {
|
|
|
355
407
|
case ACP_METHODS.SET_MODE:
|
|
356
408
|
this.writeResult(request.id, this.setMode(request.params as SetSessionModeRequest | undefined));
|
|
357
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;
|
|
358
416
|
case ACP_METHODS.LIST:
|
|
359
417
|
this.writeResult(request.id, this.listSessions(request.params as ListSessionsRequest | undefined));
|
|
360
418
|
return;
|
|
@@ -404,23 +462,94 @@ export class AcpServer {
|
|
|
404
462
|
return error;
|
|
405
463
|
}
|
|
406
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
|
+
|
|
407
534
|
private newSession(params: NewSessionRequest | undefined): NewSessionResponse {
|
|
408
535
|
if (!params || typeof params.cwd !== 'string' || !params.cwd.trim()) {
|
|
409
536
|
throw this.paramsError('session/new requires cwd');
|
|
410
537
|
}
|
|
411
|
-
if (params.mcpServers !== undefined && (!Array.isArray(params.mcpServers) || params.mcpServers.length > 0)) {
|
|
412
|
-
throw this.paramsError('MCP servers are not supported by this agent');
|
|
413
|
-
}
|
|
414
538
|
if (params.additionalDirectories !== undefined && (!Array.isArray(params.additionalDirectories) || params.additionalDirectories.length > 0)) {
|
|
415
539
|
throw this.paramsError('additionalDirectories is not supported by this agent');
|
|
416
540
|
}
|
|
417
541
|
const cwd = this.resolveWorkspace(params.cwd);
|
|
542
|
+
const mcpServers = this.parseSessionMcpServers(params.mcpServers, cwd);
|
|
418
543
|
this.bindWorkspace(cwd);
|
|
419
544
|
if (this.sessions.size >= MAX_SESSIONS) {
|
|
420
545
|
throw this.paramsError(`Maximum concurrent sessions (${MAX_SESSIONS}) exceeded`);
|
|
421
546
|
}
|
|
422
547
|
const record = createSession(cwd, 'Untitled', false);
|
|
423
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
|
+
}
|
|
424
553
|
return this.sessionResponse(session);
|
|
425
554
|
}
|
|
426
555
|
|
|
@@ -478,10 +607,97 @@ export class AcpServer {
|
|
|
478
607
|
};
|
|
479
608
|
}
|
|
480
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
|
+
|
|
481
694
|
private sessionResponse(session: AcpSession): NewSessionResponse {
|
|
695
|
+
const catalog = this.buildSessionCatalog(session);
|
|
482
696
|
return {
|
|
483
697
|
sessionId: session.id,
|
|
484
|
-
modes: this.modesFor(session)
|
|
698
|
+
modes: this.modesFor(session),
|
|
699
|
+
...(catalog.models ? { models: catalog.models } : {}),
|
|
700
|
+
...(catalog.configOptions ? { configOptions: catalog.configOptions } : {})
|
|
485
701
|
};
|
|
486
702
|
}
|
|
487
703
|
|
|
@@ -538,10 +754,23 @@ export class AcpServer {
|
|
|
538
754
|
readyState: 1,
|
|
539
755
|
send: (payload: string) => { if (acceptingEvents && !session.cancelled && this.sessions.get(session.id) === session) this.onLoopPayload(session, payload); }
|
|
540
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
|
+
: [];
|
|
541
767
|
const loopOptions = {
|
|
542
768
|
workspaceRoot: session.cwd,
|
|
543
769
|
memorySessionId: session.memorySessionId,
|
|
544
|
-
approvalScope: session.approvalScope
|
|
770
|
+
approvalScope: session.approvalScope,
|
|
771
|
+
...(session.model ? { model: session.model } : {}),
|
|
772
|
+
...(session.variant ? { variant: session.variant } : {}),
|
|
773
|
+
...(peerMcpServers.length > 0 ? { peerMcpServers } : {})
|
|
545
774
|
};
|
|
546
775
|
let loop: AgentLoop;
|
|
547
776
|
try {
|
|
@@ -818,6 +1047,45 @@ export class AcpServer {
|
|
|
818
1047
|
return {};
|
|
819
1048
|
}
|
|
820
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
|
+
|
|
821
1089
|
private canonicalizePath(targetPath: string): string {
|
|
822
1090
|
const resolved = path.resolve(targetPath);
|
|
823
1091
|
try {
|
|
@@ -854,6 +1122,7 @@ export class AcpServer {
|
|
|
854
1122
|
// Closing never blocks on cancellation.
|
|
855
1123
|
}
|
|
856
1124
|
this.sessions.delete(session.id);
|
|
1125
|
+
void unregisterSessionMcpServers(session.id);
|
|
857
1126
|
return {};
|
|
858
1127
|
}
|
|
859
1128
|
|
|
@@ -862,9 +1131,6 @@ export class AcpServer {
|
|
|
862
1131
|
if (!params || typeof params.sessionId !== 'string' || !params.sessionId) {
|
|
863
1132
|
throw this.paramsError('session/load requires sessionId');
|
|
864
1133
|
}
|
|
865
|
-
if (params.mcpServers !== undefined && (!Array.isArray(params.mcpServers) || params.mcpServers.length > 0)) {
|
|
866
|
-
throw this.paramsError('MCP servers are not supported by this agent');
|
|
867
|
-
}
|
|
868
1134
|
const live = this.sessions.get(params.sessionId);
|
|
869
1135
|
if (live) {
|
|
870
1136
|
if (params.cwd !== undefined && this.resolveWorkspace(params.cwd) !== live.cwd) {
|
|
@@ -873,7 +1139,12 @@ export class AcpServer {
|
|
|
873
1139
|
if (live.busy || live.pendingPrompts > 0) {
|
|
874
1140
|
throw this.paramsError('session is busy; cancel it before loading');
|
|
875
1141
|
}
|
|
1142
|
+
const mcpServers = this.parseSessionMcpServers(params.mcpServers, live.cwd);
|
|
876
1143
|
this.bindWorkspace(live.cwd);
|
|
1144
|
+
if (mcpServers.length > 0) {
|
|
1145
|
+
live.mcpServers = mcpServers;
|
|
1146
|
+
registerSessionMcpServers(live.id, mcpServers);
|
|
1147
|
+
}
|
|
877
1148
|
this.replayTranscript(live, getSession(live.memorySessionId)?.messages ?? []);
|
|
878
1149
|
return { modes: this.modesFor(live) };
|
|
879
1150
|
}
|
|
@@ -884,8 +1155,13 @@ export class AcpServer {
|
|
|
884
1155
|
if (record.workspace && this.canonicalizePath(record.workspace) !== cwd) {
|
|
885
1156
|
throw this.paramsError('session workspace does not match cwd');
|
|
886
1157
|
}
|
|
1158
|
+
const mcpServers = this.parseSessionMcpServers(params.mcpServers, cwd);
|
|
887
1159
|
this.bindWorkspace(cwd);
|
|
888
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
|
+
}
|
|
889
1165
|
this.replayTranscript(session, record.messages);
|
|
890
1166
|
return { modes: this.modesFor(session) };
|
|
891
1167
|
}
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* not exit with an unresolved task solely because there are no other handles.
|
|
8
8
|
*/
|
|
9
9
|
export function waitForAbortableDelay(durationMs, signal) {
|
|
10
|
-
if (!Number.isFinite(durationMs) || durationMs < 0) {
|
|
11
|
-
return Promise.reject(new RangeError('Backoff duration must be
|
|
10
|
+
if (!Number.isFinite(durationMs) || durationMs < 0 || durationMs > 2_147_483_647) {
|
|
11
|
+
return Promise.reject(new RangeError('Backoff duration must be between 0 and 2147483647 ms'));
|
|
12
12
|
}
|
|
13
13
|
if (signal?.aborted)
|
|
14
14
|
return Promise.resolve('aborted');
|
|
@@ -10,8 +10,8 @@ export function waitForAbortableDelay(
|
|
|
10
10
|
durationMs: number,
|
|
11
11
|
signal?: AbortSignal | null
|
|
12
12
|
): Promise<'elapsed' | 'aborted'> {
|
|
13
|
-
if (!Number.isFinite(durationMs) || durationMs < 0) {
|
|
14
|
-
return Promise.reject(new RangeError('Backoff duration must be
|
|
13
|
+
if (!Number.isFinite(durationMs) || durationMs < 0 || durationMs > 2_147_483_647) {
|
|
14
|
+
return Promise.reject(new RangeError('Backoff duration must be between 0 and 2147483647 ms'));
|
|
15
15
|
}
|
|
16
16
|
if (signal?.aborted) return Promise.resolve('aborted');
|
|
17
17
|
if (durationMs === 0) return Promise.resolve('elapsed');
|
|
@@ -17,6 +17,8 @@ export function classifyAgentError(error) {
|
|
|
17
17
|
// A provider may have charged for completed steps before the turn failed.
|
|
18
18
|
// Replaying that turn can repeat actions and spend the same tokens again.
|
|
19
19
|
const posTokens = (v) => {
|
|
20
|
+
if (typeof v !== 'number' && typeof v !== 'string')
|
|
21
|
+
return 0;
|
|
20
22
|
const n = Number(v);
|
|
21
23
|
return Number.isFinite(n) && n > 0 ? n : 0;
|
|
22
24
|
};
|
|
@@ -119,9 +121,15 @@ export function classifyAgentError(error) {
|
|
|
119
121
|
msg.includes('api key')) {
|
|
120
122
|
return 'auth_error';
|
|
121
123
|
}
|
|
124
|
+
if (errObj?.code === 'AGY_INVALID_MODEL_SELECTION') {
|
|
125
|
+
return 'invalid_request_error';
|
|
126
|
+
}
|
|
122
127
|
if (msg.includes('400') ||
|
|
123
128
|
msg.includes('invalid_parameter') ||
|
|
124
129
|
msg.includes('invalid_request') ||
|
|
130
|
+
msg.includes('invalid model selection') ||
|
|
131
|
+
msg.includes('conflicts with --effort') ||
|
|
132
|
+
msg.includes('--effort is not supported') ||
|
|
125
133
|
msg.includes('required property') ||
|
|
126
134
|
msg.includes('bad request')) {
|
|
127
135
|
return 'invalid_request_error';
|
|
@@ -149,5 +157,5 @@ const RETRY_HINTS = {
|
|
|
149
157
|
unknown_error: 'An unexpected error occurred. Try a different approach entirely.'
|
|
150
158
|
};
|
|
151
159
|
export function getRetryHintForError(errorType) {
|
|
152
|
-
return RETRY_HINTS[errorType] ?? RETRY_HINTS.unknown_error;
|
|
160
|
+
return Object.hasOwn(RETRY_HINTS, errorType) ? (RETRY_HINTS[errorType] ?? RETRY_HINTS.unknown_error) : RETRY_HINTS.unknown_error;
|
|
153
161
|
}
|
|
@@ -46,6 +46,7 @@ export function classifyAgentError(error: unknown): AgentErrorClass {
|
|
|
46
46
|
// A provider may have charged for completed steps before the turn failed.
|
|
47
47
|
// Replaying that turn can repeat actions and spend the same tokens again.
|
|
48
48
|
const posTokens = (v: unknown): number => {
|
|
49
|
+
if (typeof v !== 'number' && typeof v !== 'string') return 0;
|
|
49
50
|
const n = Number(v);
|
|
50
51
|
return Number.isFinite(n) && n > 0 ? n : 0;
|
|
51
52
|
};
|
|
@@ -163,10 +164,16 @@ export function classifyAgentError(error: unknown): AgentErrorClass {
|
|
|
163
164
|
) {
|
|
164
165
|
return 'auth_error';
|
|
165
166
|
}
|
|
167
|
+
if (errObj?.code === 'AGY_INVALID_MODEL_SELECTION') {
|
|
168
|
+
return 'invalid_request_error';
|
|
169
|
+
}
|
|
166
170
|
if (
|
|
167
171
|
msg.includes('400') ||
|
|
168
172
|
msg.includes('invalid_parameter') ||
|
|
169
173
|
msg.includes('invalid_request') ||
|
|
174
|
+
msg.includes('invalid model selection') ||
|
|
175
|
+
msg.includes('conflicts with --effort') ||
|
|
176
|
+
msg.includes('--effort is not supported') ||
|
|
170
177
|
msg.includes('required property') ||
|
|
171
178
|
msg.includes('bad request')
|
|
172
179
|
) {
|
|
@@ -200,5 +207,5 @@ const RETRY_HINTS: Record<string, string> = {
|
|
|
200
207
|
};
|
|
201
208
|
|
|
202
209
|
export function getRetryHintForError(errorType: string): string {
|
|
203
|
-
return RETRY_HINTS[errorType] ?? RETRY_HINTS.unknown_error!;
|
|
210
|
+
return Object.hasOwn(RETRY_HINTS, errorType) ? (RETRY_HINTS[errorType] ?? RETRY_HINTS.unknown_error!) : RETRY_HINTS.unknown_error!;
|
|
204
211
|
}
|