@causyne/agent 1.20.124 → 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.
Files changed (235) hide show
  1. package/bin/causyne.js +1 -1
  2. package/package.json +4 -4
  3. package/src/acp/protocol.ts +19 -1
  4. package/src/acp/server.js +282 -8
  5. package/src/acp/server.ts +284 -8
  6. package/src/agent/abortableDelay.js +2 -2
  7. package/src/agent/abortableDelay.ts +2 -2
  8. package/src/agent/errorClassifier.js +9 -1
  9. package/src/agent/errorClassifier.ts +8 -1
  10. package/src/agentLoop.js +83 -27
  11. package/src/agentLoop.ts +92 -26
  12. package/src/approvalPolicy.js +34 -10
  13. package/src/approvalPolicy.ts +42 -11
  14. package/src/browser/causyneBrowser.js +30 -3
  15. package/src/browser/causyneBrowser.ts +33 -3
  16. package/src/browser/urlPolicy.js +14 -1
  17. package/src/browser/urlPolicy.ts +12 -1
  18. package/src/cliMode.js +21 -9
  19. package/src/cliMode.ts +20 -8
  20. package/src/commands.js +188 -32
  21. package/src/commands.ts +209 -32
  22. package/src/config.js +19 -4
  23. package/src/config.ts +18 -4
  24. package/src/core/contextCompactor.js +54 -7
  25. package/src/core/contextCompactor.ts +63 -7
  26. package/src/core/goalLoop.js +257 -0
  27. package/src/core/goalLoop.ts +310 -0
  28. package/src/entrypoint.js +135 -3
  29. package/src/entrypoint.ts +136 -3
  30. package/src/game/causyneCoreBridge.js +686 -0
  31. package/src/game/causyneCoreBridge.ts +702 -0
  32. package/src/game/gameLauncher.js +287 -0
  33. package/src/game/gameLauncher.ts +352 -0
  34. package/src/game/gameProvisioner.js +425 -0
  35. package/src/game/gameProvisioner.ts +488 -0
  36. package/src/headlessCli.js +19 -12
  37. package/src/headlessCli.ts +22 -8
  38. package/src/infra/atomicWriter.js +40 -4
  39. package/src/infra/atomicWriter.ts +36 -4
  40. package/src/launchIntent.js +73 -3
  41. package/src/launchIntent.ts +76 -3
  42. package/src/lsp/lspClient.js +83 -12
  43. package/src/lsp/lspClient.ts +75 -12
  44. package/src/mcp/mcpRegistry.js +75 -8
  45. package/src/mcp/mcpRegistry.ts +70 -7
  46. package/src/memory/contextBudget.js +2 -0
  47. package/src/memory/contextBudget.ts +1 -0
  48. package/src/modelVariants.js +45 -0
  49. package/src/modelVariants.ts +54 -0
  50. package/src/outputRecovery.js +3 -2
  51. package/src/outputRecovery.ts +4 -2
  52. package/src/permissionPresets.js +327 -0
  53. package/src/permissionPresets.ts +361 -0
  54. package/src/providers/antigravity.js +62 -9
  55. package/src/providers/antigravity.ts +73 -9
  56. package/src/providers/byokHttp.js +7 -1
  57. package/src/providers/byokHttp.ts +6 -1
  58. package/src/providers/byokStream.js +21 -8
  59. package/src/providers/byokStream.ts +17 -7
  60. package/src/providers/dashscope-byok.js +21 -5
  61. package/src/providers/dashscope-byok.ts +29 -11
  62. package/src/providers/moonshot.js +26 -7
  63. package/src/providers/moonshot.ts +34 -13
  64. package/src/providers/muse.js +6 -0
  65. package/src/providers/muse.ts +8 -0
  66. package/src/providers/ollama.js +39 -7
  67. package/src/providers/ollama.ts +36 -7
  68. package/src/providers/openai-compatible.js +16 -3
  69. package/src/providers/openai-compatible.ts +13 -3
  70. package/src/providers/openai.js +62 -4
  71. package/src/providers/openai.ts +50 -4
  72. package/src/providers/openrouter.js +19 -4
  73. package/src/providers/openrouter.ts +21 -4
  74. package/src/providers/qwen-byok.js +21 -5
  75. package/src/providers/qwen-byok.ts +29 -11
  76. package/src/providers/xai.js +26 -10
  77. package/src/providers/xai.ts +34 -16
  78. package/src/reporting.js +4 -2
  79. package/src/reporting.ts +4 -2
  80. package/src/sandbox.js +34 -0
  81. package/src/sandbox.ts +43 -0
  82. package/src/scheduler/scheduler.js +372 -0
  83. package/src/scheduler/scheduler.ts +433 -0
  84. package/src/sessionSearchIndex.js +267 -0
  85. package/src/sessionSearchIndex.ts +311 -0
  86. package/src/skillsManager.js +2 -3
  87. package/src/skillsManager.ts +2 -3
  88. package/src/toolPacks.js +6 -0
  89. package/src/toolPacks.ts +6 -0
  90. package/src/tools/applyPatch.js +1 -1
  91. package/src/tools/applyPatch.ts +1 -1
  92. package/src/tools/generateMediaViaApi.js +4 -3
  93. package/src/tools/generateMediaViaApi.ts +4 -3
  94. package/src/tools/nativeEngine.js +2 -2
  95. package/src/tools/nativeEngine.ts +2 -2
  96. package/src/tools/openSourceToolProvisioner.js +2 -2
  97. package/src/tools/openSourceToolProvisioner.ts +2 -2
  98. package/src/tools/payloadSanitizer.js +0 -1
  99. package/src/tools/payloadSanitizer.ts +0 -1
  100. package/src/tools/pdfReader.js +122 -20
  101. package/src/tools/pdfReader.ts +111 -20
  102. package/src/tools/presentDeliverable.js +103 -0
  103. package/src/tools/presentDeliverable.ts +127 -0
  104. package/src/tools/ptcRuntime.js +444 -0
  105. package/src/tools/ptcRuntime.ts +490 -0
  106. package/src/tools/ptyTerminal.js +1096 -0
  107. package/src/tools/ptyTerminal.ts +1231 -0
  108. package/src/tools/registry.js +21 -12
  109. package/src/tools/registry.ts +21 -12
  110. package/src/tools/toolOutputStore.js +26 -4
  111. package/src/tools/toolOutputStore.ts +22 -4
  112. package/src/tools/webFetch.js +158 -11
  113. package/src/tools/webFetch.ts +145 -11
  114. package/src/tools/webSearch.js +123 -36
  115. package/src/tools/webSearch.ts +124 -33
  116. package/src/tui/banner.js +5 -1
  117. package/src/tui/banner.ts +6 -1
  118. package/src/tui/chatRenderer.js +1 -2
  119. package/src/tui/chatRenderer.ts +1 -2
  120. package/src/tui/completion.js +1 -0
  121. package/src/tui/completion.ts +1 -0
  122. package/src/tui/composerControls.js +111 -27
  123. package/src/tui/composerControls.ts +124 -28
  124. package/src/tui/dialogs.js +3 -16
  125. package/src/tui/dialogs.ts +3 -16
  126. package/src/tui/home.js +1 -0
  127. package/src/tui/home.ts +1 -0
  128. package/src/tui/invocation.js +1 -2
  129. package/src/tui/invocation.ts +1 -2
  130. package/src/tui/modelPicker.js +22 -12
  131. package/src/tui/modelPicker.ts +22 -12
  132. package/src/tui/overlay.js +2 -5
  133. package/src/tui/overlay.ts +2 -5
  134. package/src/tui/prompt.js +6 -4
  135. package/src/tui/prompt.ts +6 -4
  136. package/src/tui/selectList.js +4 -12
  137. package/src/tui/selectList.ts +4 -12
  138. package/src/tui/setup.js +22 -9
  139. package/src/tui/setup.ts +26 -9
  140. package/src/tui/statusLine.ts +2 -0
  141. package/src/web/client/browserPanel.js +702 -0
  142. package/src/web/client/browserPanel.ts +663 -0
  143. package/src/web/client/chatStream.js +309 -0
  144. package/src/web/client/chatStream.ts +289 -0
  145. package/src/web/client/cliPanel.js +165 -0
  146. package/src/web/client/cliPanel.ts +171 -0
  147. package/src/web/client/composer.js +204 -0
  148. package/src/web/client/composer.ts +209 -0
  149. package/src/web/client/diffPanel.js +176 -0
  150. package/src/web/client/diffPanel.ts +203 -0
  151. package/src/web/client/dom.js +220 -0
  152. package/src/web/client/dom.ts +221 -0
  153. package/src/web/client/filesAndCanvas.js +231 -0
  154. package/src/web/client/filesAndCanvas.ts +238 -0
  155. package/src/web/client/gameLauncherUi.js +78 -0
  156. package/src/web/client/gameLauncherUi.ts +78 -0
  157. package/src/web/client/main.js +301 -0
  158. package/src/web/client/main.ts +368 -0
  159. package/src/web/client/markdown.js +364 -0
  160. package/src/web/client/markdown.ts +373 -0
  161. package/src/web/client/modelPicker.js +455 -0
  162. package/src/web/client/modelPicker.ts +451 -0
  163. package/src/web/client/permissionPresetsUi.js +307 -0
  164. package/src/web/client/permissionPresetsUi.ts +333 -0
  165. package/src/web/client/sessions.js +353 -0
  166. package/src/web/client/sessions.ts +372 -0
  167. package/src/web/client/settingsModal.js +191 -0
  168. package/src/web/client/settingsModal.ts +176 -0
  169. package/src/web/client/state.js +250 -0
  170. package/src/web/client/state.ts +233 -0
  171. package/src/web/client/streamSmoother.js +127 -0
  172. package/src/web/client/streamSmoother.ts +119 -0
  173. package/src/web/client/studioLayout.js +54 -0
  174. package/src/web/client/studioLayout.ts +60 -0
  175. package/src/web/client/studioShell.js +327 -0
  176. package/src/web/client/studioShell.ts +340 -0
  177. package/src/web/client/studioStart.js +77 -0
  178. package/src/web/client/studioStart.ts +89 -0
  179. package/src/web/client/terminalPanel.js +357 -0
  180. package/src/web/client/terminalPanel.ts +345 -0
  181. package/src/web/client/turnView.js +934 -0
  182. package/src/web/client/turnView.ts +981 -0
  183. package/src/web/client/types.js +1 -0
  184. package/src/web/client/types.ts +319 -0
  185. package/src/web/client/validators.js +106 -0
  186. package/src/web/client/validators.ts +96 -0
  187. package/src/web/server/activeRuns.js +152 -0
  188. package/src/web/server/activeRuns.ts +171 -0
  189. package/src/web/server/routesBrowser.js +355 -0
  190. package/src/web/server/routesBrowser.ts +386 -0
  191. package/src/web/server/routesChat.js +304 -0
  192. package/src/web/server/routesChat.ts +347 -0
  193. package/src/web/server/routesCore.js +472 -0
  194. package/src/web/server/routesCore.ts +522 -0
  195. package/src/web/server/routesTerminal.js +162 -0
  196. package/src/web/server/routesTerminal.ts +182 -0
  197. package/src/web/server/routesWorkspace.js +510 -0
  198. package/src/web/server/routesWorkspace.ts +546 -0
  199. package/src/web/server/security.js +98 -0
  200. package/src/web/server/security.ts +108 -0
  201. package/src/web/server/sessionTranscript.js +586 -0
  202. package/src/web/server/sessionTranscript.ts +566 -0
  203. package/src/web/server/staticAssets.js +80 -0
  204. package/src/web/server/staticAssets.ts +91 -0
  205. package/src/web/server/types.js +1 -0
  206. package/src/web/server/types.ts +135 -0
  207. package/src/web/server/workspaceFiles.js +368 -0
  208. package/src/web/server/workspaceFiles.ts +363 -0
  209. package/src/web/skybridgeServer.js +76 -2449
  210. package/src/web/skybridgeServer.ts +118 -2600
  211. package/src/web/skybridgeUi.js +16 -450
  212. package/src/web/skybridgeUi.ts +16 -454
  213. package/src/web/styles/agent.css +380 -0
  214. package/src/web/styles/composer.css +193 -0
  215. package/src/web/styles/overlays.css +436 -0
  216. package/src/web/styles/shell.css +387 -0
  217. package/src/web/styles/studio.css +723 -0
  218. package/src/web/styles/thread.css +221 -0
  219. package/src/web/styles/tokens.css +94 -0
  220. package/src/web/ui/brandMark.js +73 -0
  221. package/src/web/ui/brandMark.ts +82 -0
  222. package/src/web/ui/modalsTemplate.js +139 -0
  223. package/src/web/ui/modalsTemplate.ts +139 -0
  224. package/src/web/ui/sidebarTemplate.js +63 -0
  225. package/src/web/ui/sidebarTemplate.ts +64 -0
  226. package/src/web/ui/studioTemplate.js +258 -0
  227. package/src/web/ui/studioTemplate.ts +258 -0
  228. package/src/web/ui/workspaceTemplate.js +72 -0
  229. package/src/web/ui/workspaceTemplate.ts +73 -0
  230. package/src/worktreeManager.js +16 -1
  231. package/src/worktreeManager.ts +22 -1
  232. package/src/web/skybridgeClientScript.js +0 -3951
  233. package/src/web/skybridgeClientScript.ts +0 -3952
  234. package/src/web/skybridgeStyles.js +0 -827
  235. package/src/web/skybridgeStyles.ts +0 -828
package/bin/causyne.js CHANGED
@@ -19,7 +19,7 @@ process.once('exit', restoreTerminal);
19
19
  function shouldSkipAutoUpdateCheck(argv) {
20
20
  const tokens = Array.isArray(argv) ? argv.slice(2) : [];
21
21
  const skipTokens = new Set([
22
- 'acp', 'web', 'gui', 'studio', 'browser-mcp',
22
+ 'acp', 'web', 'gui', 'studio', 'game', 'browser-mcp',
23
23
  'status', 'doctor', 'diff', 'license',
24
24
  'context', 'usage', 'checkpoints', 'undo', 'mcp', 'peers',
25
25
  'policy', 'audit', 'lsp', 'worktree', 'pr', 'rules', 'map',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@causyne/agent",
3
- "version": "1.20.124",
3
+ "version": "1.20.127",
4
4
  "description": "Agentic AI for software, tools, and computer workflows",
5
5
  "main": "bin/causyne.js",
6
6
  "type": "module",
@@ -24,13 +24,13 @@
24
24
  "prestart": "npm run build",
25
25
  "start": "node ./bin/causyne.js",
26
26
  "test": "node --test --import ./tests/helpers/isolateState.js \"tests/**/*.test.{js,ts}\"",
27
- "build": "node scripts/compile_skills.js && tsc -p tsconfig.runtime.json",
27
+ "build": "node scripts/compile_skills.js && tsc -p tsconfig.runtime.json && tsc -p tsconfig.web.json",
28
28
  "benchmark:plan-cache": "node src/benchmarks/planCache.js",
29
29
  "check:release": "node scripts/check_release.js",
30
30
  "check:public": "npm run check:release && node scripts/check_public_release.js",
31
31
  "prepublishOnly": "npm run check:public && npm test && npm run typecheck:strict",
32
- "typecheck": "tsc -p tsconfig.strict.json",
33
- "typecheck:ts": "tsc -p tsconfig.strict.json",
32
+ "typecheck": "tsc -p tsconfig.strict.json && tsc -p tsconfig.web.json --noEmit",
33
+ "typecheck:ts": "tsc -p tsconfig.strict.json && tsc -p tsconfig.web.json --noEmit",
34
34
  "typecheck:strict": "npm run typecheck:ts",
35
35
  "verify:features": "node scripts/verify-features.mjs",
36
36
  "verify:ui": "node scripts/verify-ui.mjs",
@@ -373,7 +373,19 @@ export interface SetSessionModelRequest {
373
373
  modelId: string;
374
374
  }
375
375
 
376
- export type SetSessionModelResponse = Record<string, never>;
376
+ export interface SetSessionModelResponse {
377
+ configOptions?: SessionConfigOption[];
378
+ }
379
+
380
+ export interface SetSessionConfigOptionRequest {
381
+ sessionId: string;
382
+ configId: string;
383
+ value: string;
384
+ }
385
+
386
+ export interface SetSessionConfigOptionResponse {
387
+ configOptions?: SessionConfigOption[];
388
+ }
377
389
 
378
390
  export interface AuthenticateRequest {
379
391
  methodId: string;
@@ -534,8 +546,14 @@ export interface CurrentModeUpdateNotification {
534
546
  currentModeId: string;
535
547
  }
536
548
 
549
+ export interface ConfigOptionUpdateNotification {
550
+ sessionUpdate: 'config_option_update';
551
+ configOptions: SessionConfigOption[];
552
+ }
553
+
537
554
  export type SessionUpdate =
538
555
  | AgentMessageChunkUpdate
556
+ | ConfigOptionUpdateNotification
539
557
  | AgentThoughtChunkUpdate
540
558
  | UserMessageChunkUpdate
541
559
  | ToolCallUpdateNotification
package/src/acp/server.js CHANGED
@@ -4,10 +4,50 @@ import path from 'node:path';
4
4
  import { StringDecoder } from 'node:string_decoder';
5
5
  import { AgentLoop } from '../agentLoop.js';
6
6
  import { createApprovalScope } from '../approvalGrants.js';
7
+ import { loadConfig } from '../config.js';
8
+ import { DEFAULT_MODEL_BY_PROVIDER, MODEL_CATALOGUE, PEER_MODEL_CATALOGUE } from '../modelCatalogue.js';
9
+ import { resolveModelVariants } from '../modelVariants.js';
10
+ import { McpClient } from '../mcp/mcpClient.js';
11
+ import { registerSessionMcpServers, unregisterSessionMcpServers } from '../mcp/mcpRegistry.js';
7
12
  import { createSession, getSession, saveSessionMessages, forkSession } from '../sessionJournal.js';
8
13
  import { isBlockedWorkspaceRoot } from '../sandboxPolicy.js';
9
14
  import { safeDisplay } from '../tui/text.js';
10
15
  import { ACP_ERROR_CODES, ACP_METHODS, ACP_PROTOCOL_VERSION, isJsonRpcNotification, isJsonRpcRequest, isJsonRpcResponse } from './protocol.js';
16
+ const FORBIDDEN_ENV_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
17
+ const MAX_SESSION_MCP_SERVERS = 16;
18
+ function providerModelsForCatalogue(provider) {
19
+ const norm = provider.trim().toLowerCase();
20
+ if (!norm)
21
+ return [];
22
+ const peerKey = norm.startsWith('acp/') ? norm.slice(4) : norm;
23
+ if (Object.hasOwn(PEER_MODEL_CATALOGUE, peerKey)) {
24
+ return [...(PEER_MODEL_CATALOGUE[peerKey] ?? [])];
25
+ }
26
+ const providerLabelMatch = {
27
+ deepseek: ['DeepSeek'],
28
+ qwen: ['Qwen'],
29
+ dashscope: ['Qwen'],
30
+ 'dashscope-byok': ['Qwen'],
31
+ anthropic: ['Anthropic'],
32
+ openai: ['OpenAI'],
33
+ gemini: ['Gemini'],
34
+ 'gemini-free': ['Gemini (Free Tier)'],
35
+ moonshot: ['Moonshot'],
36
+ xai: ['xAI'],
37
+ groq: ['Groq (Free Tier)'],
38
+ cerebras: ['Cerebras (Free Tier)'],
39
+ openrouter: ['OpenRouter (Free Tier)'],
40
+ mistral: ['Mistral (Free Tier)']
41
+ };
42
+ const labels = providerLabelMatch[norm] ?? [];
43
+ const models = [];
44
+ for (const label of labels) {
45
+ const entries = MODEL_CATALOGUE[label];
46
+ if (Array.isArray(entries))
47
+ models.push(...entries);
48
+ }
49
+ return models;
50
+ }
11
51
  const MODE_TO_AUTONOMY = {
12
52
  autonomous: 'C',
13
53
  standard: 'B',
@@ -165,6 +205,7 @@ export class AcpServer {
165
205
  if (this.input && this.errorListener)
166
206
  this.input.off('error', this.errorListener);
167
207
  this.buffer = '';
208
+ const closingIds = [...this.sessions.keys()];
168
209
  for (const session of this.sessions.values()) {
169
210
  session.cancelled = true;
170
211
  session.generation++;
@@ -176,6 +217,7 @@ export class AcpServer {
176
217
  }
177
218
  }
178
219
  this.sessions.clear();
220
+ await Promise.allSettled(closingIds.map((id) => unregisterSessionMcpServers(id)));
179
221
  for (const [id, pending] of this.pending) {
180
222
  clearTimeout(pending.timer);
181
223
  pending.reject(new Error('server stopped'));
@@ -271,6 +313,12 @@ export class AcpServer {
271
313
  case ACP_METHODS.SET_MODE:
272
314
  this.writeResult(request.id, this.setMode(request.params));
273
315
  return;
316
+ case ACP_METHODS.SET_MODEL:
317
+ this.writeResult(request.id, this.setModel(request.params));
318
+ return;
319
+ case ACP_METHODS.SET_CONFIG_OPTION:
320
+ this.writeResult(request.id, this.setConfigOption(request.params));
321
+ return;
274
322
  case ACP_METHODS.LIST:
275
323
  this.writeResult(request.id, this.listSessions(request.params));
276
324
  return;
@@ -316,23 +364,99 @@ export class AcpServer {
316
364
  error.acpCode = ACP_ERROR_CODES.INVALID_PARAMS;
317
365
  return error;
318
366
  }
367
+ parseSessionMcpServers(raw, cwd) {
368
+ if (raw === undefined)
369
+ return [];
370
+ if (!Array.isArray(raw)) {
371
+ throw this.paramsError('mcpServers must be an array');
372
+ }
373
+ if (raw.length > MAX_SESSION_MCP_SERVERS) {
374
+ throw this.paramsError(`Maximum ${MAX_SESSION_MCP_SERVERS} MCP servers per session exceeded`);
375
+ }
376
+ const definitions = [];
377
+ for (const entry of raw) {
378
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
379
+ throw this.paramsError('Each MCP server entry must be an object');
380
+ }
381
+ const item = entry;
382
+ const rawType = typeof item.type === 'string' ? item.type.trim().toLowerCase() : '';
383
+ if (rawType === 'http' || rawType === 'sse' || typeof item.url === 'string') {
384
+ throw this.paramsError('HTTP/SSE MCP servers are not supported by this agent');
385
+ }
386
+ if (typeof item.name !== 'string' || !item.name.trim()) {
387
+ throw this.paramsError('Stdio MCP server requires a non-empty name');
388
+ }
389
+ if (typeof item.command !== 'string' || !item.command.trim()) {
390
+ throw this.paramsError('Stdio MCP server requires a non-empty command');
391
+ }
392
+ if (!Array.isArray(item.args) || !item.args.every((arg) => typeof arg === 'string')) {
393
+ throw this.paramsError('Stdio MCP server requires an args string array');
394
+ }
395
+ let env;
396
+ if (item.env !== undefined) {
397
+ const mapped = Object.create(null);
398
+ if (Array.isArray(item.env)) {
399
+ for (const pair of item.env) {
400
+ if (!pair || typeof pair !== 'object' || Array.isArray(pair)) {
401
+ throw this.paramsError('Stdio MCP server env entries must be { name, value } objects');
402
+ }
403
+ const rec = pair;
404
+ if (typeof rec.name !== 'string' || !rec.name || typeof rec.value !== 'string') {
405
+ throw this.paramsError('Stdio MCP server env entries require string name and value');
406
+ }
407
+ if (!FORBIDDEN_ENV_KEYS.has(rec.name))
408
+ mapped[rec.name] = rec.value;
409
+ }
410
+ }
411
+ else if (typeof item.env === 'object' && item.env !== null) {
412
+ for (const [k, v] of Object.entries(item.env)) {
413
+ if (typeof v !== 'string') {
414
+ throw this.paramsError('Stdio MCP server env values must be strings');
415
+ }
416
+ if (!FORBIDDEN_ENV_KEYS.has(k))
417
+ mapped[k] = v;
418
+ }
419
+ }
420
+ else {
421
+ throw this.paramsError('Stdio MCP server env must be an array or object');
422
+ }
423
+ if (Object.keys(mapped).length > 0)
424
+ env = { ...mapped };
425
+ }
426
+ const def = {
427
+ name: item.name.trim(),
428
+ command: item.command.trim(),
429
+ args: [...item.args],
430
+ ...(env ? { env } : {}),
431
+ cwd
432
+ };
433
+ const problem = McpClient.validateDefinition(def);
434
+ if (problem) {
435
+ throw this.paramsError(`Invalid MCP server "${def.name}": ${problem}`);
436
+ }
437
+ definitions.push(def);
438
+ }
439
+ return definitions;
440
+ }
319
441
  newSession(params) {
320
442
  if (!params || typeof params.cwd !== 'string' || !params.cwd.trim()) {
321
443
  throw this.paramsError('session/new requires cwd');
322
444
  }
323
- if (params.mcpServers !== undefined && (!Array.isArray(params.mcpServers) || params.mcpServers.length > 0)) {
324
- throw this.paramsError('MCP servers are not supported by this agent');
325
- }
326
445
  if (params.additionalDirectories !== undefined && (!Array.isArray(params.additionalDirectories) || params.additionalDirectories.length > 0)) {
327
446
  throw this.paramsError('additionalDirectories is not supported by this agent');
328
447
  }
329
448
  const cwd = this.resolveWorkspace(params.cwd);
449
+ const mcpServers = this.parseSessionMcpServers(params.mcpServers, cwd);
330
450
  this.bindWorkspace(cwd);
331
451
  if (this.sessions.size >= MAX_SESSIONS) {
332
452
  throw this.paramsError(`Maximum concurrent sessions (${MAX_SESSIONS}) exceeded`);
333
453
  }
334
454
  const record = createSession(cwd, 'Untitled', false);
335
455
  const session = this.addSession(record.id, cwd, record.title, MODES.currentModeId);
456
+ if (mcpServers.length > 0) {
457
+ session.mcpServers = mcpServers;
458
+ registerSessionMcpServers(session.id, mcpServers);
459
+ }
336
460
  return this.sessionResponse(session);
337
461
  }
338
462
  resolveWorkspace(cwd) {
@@ -389,10 +513,98 @@ export class AcpServer {
389
513
  availableModes: MODES.availableModes.map((mode) => ({ ...mode }))
390
514
  };
391
515
  }
516
+ buildSessionCatalog(session) {
517
+ let config = {};
518
+ try {
519
+ config = loadConfig();
520
+ }
521
+ catch {
522
+ config = {};
523
+ }
524
+ const provider = typeof config.provider === 'string' && config.provider.trim()
525
+ ? config.provider.trim()
526
+ : 'deepseek';
527
+ const configuredModel = typeof config.model === 'string' && config.model.trim()
528
+ ? config.model.trim()
529
+ : (DEFAULT_MODEL_BY_PROVIDER[provider.toLowerCase()] || '');
530
+ const activeModel = session.model || configuredModel;
531
+ const seen = new Set();
532
+ const modelIds = [];
533
+ const addModel = (id) => {
534
+ const clean = id.trim();
535
+ if (!clean || seen.has(clean))
536
+ return;
537
+ seen.add(clean);
538
+ modelIds.push(clean);
539
+ };
540
+ if (activeModel)
541
+ addModel(activeModel);
542
+ if (configuredModel)
543
+ addModel(configuredModel);
544
+ for (const candidate of providerModelsForCatalogue(provider)) {
545
+ addModel(candidate);
546
+ if (modelIds.length >= 64)
547
+ break;
548
+ }
549
+ const configOptions = [];
550
+ const primaryModelId = activeModel || modelIds[0];
551
+ if (modelIds.length > 0 && primaryModelId) {
552
+ configOptions.push({
553
+ id: 'model',
554
+ name: 'Model',
555
+ category: 'model',
556
+ type: 'select',
557
+ currentValue: primaryModelId,
558
+ options: modelIds.map((id) => ({ value: id, name: id }))
559
+ });
560
+ }
561
+ const currentVariant = session.variant
562
+ || (typeof config.reasoningEffort === 'string' && config.reasoningEffort.trim() ? config.reasoningEffort.trim() : undefined);
563
+ if (activeModel) {
564
+ try {
565
+ const variantSpec = resolveModelVariants({
566
+ provider,
567
+ model: activeModel,
568
+ currentVariant: currentVariant ?? null
569
+ });
570
+ if (variantSpec.supported && variantSpec.options.length > 0) {
571
+ const resolvedVariant = currentVariant || variantSpec.defaultVariant || variantSpec.options[0]?.id;
572
+ configOptions.push({
573
+ id: 'thought_level',
574
+ name: 'Reasoning effort',
575
+ category: 'thought_level',
576
+ type: 'select',
577
+ ...(resolvedVariant ? { currentValue: resolvedVariant } : {}),
578
+ options: variantSpec.options.map((opt) => ({
579
+ value: opt.id,
580
+ name: opt.label,
581
+ description: opt.description
582
+ }))
583
+ });
584
+ }
585
+ }
586
+ catch {
587
+ // Variant discovery is best-effort; never fail session creation.
588
+ }
589
+ }
590
+ const models = modelIds.length > 0 && primaryModelId
591
+ ? {
592
+ currentModelId: primaryModelId,
593
+ availableModels: modelIds.map((id) => ({ modelId: id, name: id }))
594
+ }
595
+ : undefined;
596
+ return {
597
+ ...(models ? { models } : {}),
598
+ ...(configOptions.length > 0 ? { configOptions } : {})
599
+ };
600
+ }
392
601
  sessionResponse(session) {
602
+ const catalog = this.buildSessionCatalog(session);
393
603
  return {
394
604
  sessionId: session.id,
395
- modes: this.modesFor(session)
605
+ modes: this.modesFor(session),
606
+ ...(catalog.models ? { models: catalog.models } : {}),
607
+ ...(catalog.configOptions ? { configOptions: catalog.configOptions } : {})
396
608
  };
397
609
  }
398
610
  requireSession(sessionId) {
@@ -449,10 +661,23 @@ export class AcpServer {
449
661
  send: (payload) => { if (acceptingEvents && !session.cancelled && this.sessions.get(session.id) === session)
450
662
  this.onLoopPayload(session, payload); }
451
663
  };
664
+ const peerMcpServers = Array.isArray(session.mcpServers) && session.mcpServers.length > 0
665
+ ? session.mcpServers
666
+ .filter((def) => typeof def.command === 'string' && def.command.length > 0)
667
+ .map((def) => ({
668
+ name: def.name,
669
+ command: def.command,
670
+ args: Array.isArray(def.args) ? [...def.args] : [],
671
+ env: Object.entries(def.env ?? {}).map(([name, value]) => ({ name, value }))
672
+ }))
673
+ : [];
452
674
  const loopOptions = {
453
675
  workspaceRoot: session.cwd,
454
676
  memorySessionId: session.memorySessionId,
455
- approvalScope: session.approvalScope
677
+ approvalScope: session.approvalScope,
678
+ ...(session.model ? { model: session.model } : {}),
679
+ ...(session.variant ? { variant: session.variant } : {}),
680
+ ...(peerMcpServers.length > 0 ? { peerMcpServers } : {})
456
681
  };
457
682
  let loop;
458
683
  try {
@@ -756,6 +981,47 @@ export class AcpServer {
756
981
  this.notify(session.id, { sessionUpdate: 'current_mode_update', currentModeId: session.modeId });
757
982
  return {};
758
983
  }
984
+ setModel(params) {
985
+ if (!params || typeof params.modelId !== 'string' || !params.modelId.trim()) {
986
+ throw this.paramsError('session/set_model requires a non-empty modelId');
987
+ }
988
+ const session = this.requireSession(params.sessionId);
989
+ const modelId = params.modelId.trim();
990
+ if (modelId.length > 200)
991
+ throw this.paramsError('modelId is too long');
992
+ session.model = modelId === 'default' ? undefined : modelId;
993
+ session.updatedAt = Date.now();
994
+ const { configOptions } = this.buildSessionCatalog(session);
995
+ if (configOptions) {
996
+ this.notify(session.id, { sessionUpdate: 'config_option_update', configOptions });
997
+ }
998
+ return configOptions ? { configOptions } : {};
999
+ }
1000
+ setConfigOption(params) {
1001
+ if (!params || typeof params.configId !== 'string' || typeof params.value !== 'string') {
1002
+ throw this.paramsError('session/set_config_option requires configId and value');
1003
+ }
1004
+ const session = this.requireSession(params.sessionId);
1005
+ const configId = params.configId.trim().toLowerCase();
1006
+ const value = params.value.trim();
1007
+ if (!value || value.length > 200)
1008
+ throw this.paramsError('Invalid config option value');
1009
+ if (configId === 'model') {
1010
+ session.model = value === 'default' ? undefined : value;
1011
+ }
1012
+ else if (configId === 'thought_level' || configId === 'reasoning_effort' || configId === 'thinking' || configId === 'effort') {
1013
+ session.variant = value === 'default' || value === 'auto' ? undefined : value;
1014
+ }
1015
+ else {
1016
+ throw this.paramsError(`Unknown config option: ${params.configId}`);
1017
+ }
1018
+ session.updatedAt = Date.now();
1019
+ const { configOptions } = this.buildSessionCatalog(session);
1020
+ if (configOptions) {
1021
+ this.notify(session.id, { sessionUpdate: 'config_option_update', configOptions });
1022
+ }
1023
+ return configOptions ? { configOptions } : {};
1024
+ }
759
1025
  canonicalizePath(targetPath) {
760
1026
  const resolved = path.resolve(targetPath);
761
1027
  try {
@@ -793,6 +1059,7 @@ export class AcpServer {
793
1059
  // Closing never blocks on cancellation.
794
1060
  }
795
1061
  this.sessions.delete(session.id);
1062
+ void unregisterSessionMcpServers(session.id);
796
1063
  return {};
797
1064
  }
798
1065
  /** Resume a persisted conversation, replaying its transcript to the client. */
@@ -800,9 +1067,6 @@ export class AcpServer {
800
1067
  if (!params || typeof params.sessionId !== 'string' || !params.sessionId) {
801
1068
  throw this.paramsError('session/load requires sessionId');
802
1069
  }
803
- if (params.mcpServers !== undefined && (!Array.isArray(params.mcpServers) || params.mcpServers.length > 0)) {
804
- throw this.paramsError('MCP servers are not supported by this agent');
805
- }
806
1070
  const live = this.sessions.get(params.sessionId);
807
1071
  if (live) {
808
1072
  if (params.cwd !== undefined && this.resolveWorkspace(params.cwd) !== live.cwd) {
@@ -811,7 +1075,12 @@ export class AcpServer {
811
1075
  if (live.busy || live.pendingPrompts > 0) {
812
1076
  throw this.paramsError('session is busy; cancel it before loading');
813
1077
  }
1078
+ const mcpServers = this.parseSessionMcpServers(params.mcpServers, live.cwd);
814
1079
  this.bindWorkspace(live.cwd);
1080
+ if (mcpServers.length > 0) {
1081
+ live.mcpServers = mcpServers;
1082
+ registerSessionMcpServers(live.id, mcpServers);
1083
+ }
815
1084
  this.replayTranscript(live, getSession(live.memorySessionId)?.messages ?? []);
816
1085
  return { modes: this.modesFor(live) };
817
1086
  }
@@ -823,8 +1092,13 @@ export class AcpServer {
823
1092
  if (record.workspace && this.canonicalizePath(record.workspace) !== cwd) {
824
1093
  throw this.paramsError('session workspace does not match cwd');
825
1094
  }
1095
+ const mcpServers = this.parseSessionMcpServers(params.mcpServers, cwd);
826
1096
  this.bindWorkspace(cwd);
827
1097
  const session = this.addSession(record.id, cwd, record.title, MODES.currentModeId);
1098
+ if (mcpServers.length > 0) {
1099
+ session.mcpServers = mcpServers;
1100
+ registerSessionMcpServers(session.id, mcpServers);
1101
+ }
828
1102
  this.replayTranscript(session, record.messages);
829
1103
  return { modes: this.modesFor(session) };
830
1104
  }