@tencent-ai/agent-sdk 0.3.37 → 0.3.39

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 (44) hide show
  1. package/cli/CHANGELOG.md +57 -0
  2. package/cli/dist/codebuddy.js +5 -5
  3. package/cli/package.json +1 -1
  4. package/cli/product.cloudhosted.json +11 -6
  5. package/cli/product.internal.json +13 -8
  6. package/cli/product.ioa.json +13 -8
  7. package/cli/product.json +28 -7
  8. package/cli/product.selfhosted.json +9 -4
  9. package/lib/acp/agent.d.ts +19 -0
  10. package/lib/acp/agent.d.ts.map +1 -1
  11. package/lib/acp/agent.js +115 -19
  12. package/lib/acp/agent.js.map +1 -1
  13. package/lib/acp/converter.d.ts +23 -5
  14. package/lib/acp/converter.d.ts.map +1 -1
  15. package/lib/acp/converter.js +103 -22
  16. package/lib/acp/converter.js.map +1 -1
  17. package/lib/acp/server.d.ts +17 -0
  18. package/lib/acp/server.d.ts.map +1 -1
  19. package/lib/acp/server.js +115 -43
  20. package/lib/acp/server.js.map +1 -1
  21. package/lib/index.d.ts +2 -1
  22. package/lib/index.d.ts.map +1 -1
  23. package/lib/index.js.map +1 -1
  24. package/lib/session.d.ts +14 -1
  25. package/lib/session.d.ts.map +1 -1
  26. package/lib/session.js +64 -0
  27. package/lib/session.js.map +1 -1
  28. package/lib/transport/index.d.ts +17 -1
  29. package/lib/transport/index.d.ts.map +1 -1
  30. package/lib/transport/index.js.map +1 -1
  31. package/lib/transport/process-transport.d.ts +12 -2
  32. package/lib/transport/process-transport.d.ts.map +1 -1
  33. package/lib/transport/process-transport.js +43 -0
  34. package/lib/transport/process-transport.js.map +1 -1
  35. package/lib/types.d.ts +79 -1
  36. package/lib/types.d.ts.map +1 -1
  37. package/lib/utils/stream.d.ts +8 -0
  38. package/lib/utils/stream.d.ts.map +1 -1
  39. package/lib/utils/stream.js +12 -0
  40. package/lib/utils/stream.js.map +1 -1
  41. package/lib/utils/type-guards.d.ts.map +1 -1
  42. package/lib/utils/type-guards.js +3 -1
  43. package/lib/utils/type-guards.js.map +1 -1
  44. package/package.json +1 -1
package/cli/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tencent-ai/codebuddy-code",
3
- "version": "2.44.0",
3
+ "version": "2.45.0",
4
4
  "description": "Use CodeBuddy, Tencent's AI assistant, right from your terminal. CodeBuddy can understand your codebase, edit files, run terminal commands, and handle entire workflows for you.",
5
5
  "main": "lib/node/index.js",
6
6
  "typings": "lib/node/index.d.ts",
@@ -42,7 +42,8 @@
42
42
  "AskUserQuestion",
43
43
  "LSP",
44
44
  "StructuredOutput",
45
- "ImageGen"
45
+ "ImageGen",
46
+ "ToolSearch"
46
47
  ],
47
48
  "tags": [
48
49
  "cli",
@@ -177,6 +178,9 @@
177
178
  "description": "Fast agent specialized for exploring codebases. Use this when you need to quickly find files by patterns (eg. \"src/components/**/*.tsx\"), search code for keywords (eg. \"API endpoints\"), or answer questions about the codebase (eg. \"how do API endpoints work?\"). When calling this agent, specify the desired thoroughness level: \"quick\" for basic searches, \"medium\" for moderate exploration, or \"very thorough\" for comprehensive analysis across multiple locations and naming conventions. (Tools: All tools)",
178
179
  "tools": [
179
180
  "Read",
181
+ "Write",
182
+ "Edit",
183
+ "MultiEdit",
180
184
  "Bash",
181
185
  "Glob",
182
186
  "Grep",
@@ -314,7 +318,7 @@
314
318
  "name": "Kimi-K2-Thinking",
315
319
  "vendor": "f",
316
320
  "maxOutputTokens": 32000,
317
- "maxInputTokens": 205000,
321
+ "maxInputTokens": 164000,
318
322
  "supportsToolCall": true,
319
323
  "supportsImages": false,
320
324
  "supportsReasoning": true,
@@ -324,7 +328,7 @@
324
328
  "effort": "medium",
325
329
  "summary": "auto"
326
330
  },
327
- "maxAllowedSize": 205000
331
+ "maxAllowedSize": 164000
328
332
  },
329
333
  {
330
334
  "id": "hunyuan-image-v3.0",
@@ -347,8 +351,9 @@
347
351
  "productFeatures": {
348
352
  "BillingNotice": false,
349
353
  "CustomModelsJSON": true,
350
- "ImageGen": true
354
+ "ImageGen": true,
355
+ "DeferToolLoading": true
351
356
  },
352
- "commit": "10228f026d6ae28624f739de283a081024b8f76b",
353
- "date": "2026-02-02T07:36:56.128Z"
357
+ "commit": "c4e444e0a4ff80e357bbb7c9288e5188b8c7ab30",
358
+ "date": "2026-02-03T15:31:57.458Z"
354
359
  }
@@ -45,7 +45,8 @@
45
45
  "AskUserQuestion",
46
46
  "LSP",
47
47
  "StructuredOutput",
48
- "ImageGen"
48
+ "ImageGen",
49
+ "ToolSearch"
49
50
  ],
50
51
  "tags": [
51
52
  "cli",
@@ -180,6 +181,9 @@
180
181
  "description": "Fast agent specialized for exploring codebases. Use this when you need to quickly find files by patterns (eg. \"src/components/**/*.tsx\"), search code for keywords (eg. \"API endpoints\"), or answer questions about the codebase (eg. \"how do API endpoints work?\"). When calling this agent, specify the desired thoroughness level: \"quick\" for basic searches, \"medium\" for moderate exploration, or \"very thorough\" for comprehensive analysis across multiple locations and naming conventions. (Tools: All tools)",
181
182
  "tools": [
182
183
  "Read",
184
+ "Write",
185
+ "Edit",
186
+ "MultiEdit",
183
187
  "Bash",
184
188
  "Glob",
185
189
  "Grep",
@@ -317,7 +321,7 @@
317
321
  "name": "Kimi-K2-Thinking",
318
322
  "vendor": "f",
319
323
  "maxOutputTokens": 32000,
320
- "maxInputTokens": 205000,
324
+ "maxInputTokens": 164000,
321
325
  "supportsToolCall": true,
322
326
  "supportsImages": false,
323
327
  "supportsReasoning": true,
@@ -327,7 +331,7 @@
327
331
  "effort": "medium",
328
332
  "summary": "auto"
329
333
  },
330
- "maxAllowedSize": 205000
334
+ "maxAllowedSize": 164000
331
335
  },
332
336
  {
333
337
  "credits": "x0.42 credits",
@@ -335,7 +339,7 @@
335
339
  "name": "Kimi-K2.5",
336
340
  "vendor": "f",
337
341
  "maxOutputTokens": 32000,
338
- "maxInputTokens": 205000,
342
+ "maxInputTokens": 164000,
339
343
  "supportsToolCall": true,
340
344
  "supportsImages": true,
341
345
  "supportsReasoning": true,
@@ -345,7 +349,7 @@
345
349
  "effort": "medium",
346
350
  "summary": "auto"
347
351
  },
348
- "maxAllowedSize": 205000
352
+ "maxAllowedSize": 164000
349
353
  },
350
354
  {
351
355
  "id": "hunyuan-image-v3.0",
@@ -368,8 +372,9 @@
368
372
  "productFeatures": {
369
373
  "BillingNotice": false,
370
374
  "CustomModelsJSON": true,
371
- "ImageGen": true
375
+ "ImageGen": true,
376
+ "DeferToolLoading": true
372
377
  },
373
- "commit": "10228f026d6ae28624f739de283a081024b8f76b",
374
- "date": "2026-02-02T07:36:53.459Z"
378
+ "commit": "c4e444e0a4ff80e357bbb7c9288e5188b8c7ab30",
379
+ "date": "2026-02-03T15:31:54.829Z"
375
380
  }
@@ -59,7 +59,8 @@
59
59
  "AskUserQuestion",
60
60
  "LSP",
61
61
  "StructuredOutput",
62
- "ImageGen"
62
+ "ImageGen",
63
+ "ToolSearch"
63
64
  ],
64
65
  "tags": [
65
66
  "cli",
@@ -204,6 +205,9 @@
204
205
  "description": "Fast agent specialized for exploring codebases. Use this when you need to quickly find files by patterns (eg. \"src/components/**/*.tsx\"), search code for keywords (eg. \"API endpoints\"), or answer questions about the codebase (eg. \"how do API endpoints work?\"). When calling this agent, specify the desired thoroughness level: \"quick\" for basic searches, \"medium\" for moderate exploration, or \"very thorough\" for comprehensive analysis across multiple locations and naming conventions. (Tools: All tools)",
205
206
  "tools": [
206
207
  "Read",
208
+ "Write",
209
+ "Edit",
210
+ "MultiEdit",
207
211
  "Bash",
208
212
  "Glob",
209
213
  "Grep",
@@ -255,7 +259,7 @@
255
259
  "name": "Kimi-K2-Thinking",
256
260
  "vendor": "f",
257
261
  "maxOutputTokens": 32000,
258
- "maxInputTokens": 205000,
262
+ "maxInputTokens": 164000,
259
263
  "supportsToolCall": true,
260
264
  "supportsImages": false,
261
265
  "supportsReasoning": true,
@@ -265,7 +269,7 @@
265
269
  "effort": "medium",
266
270
  "summary": "auto"
267
271
  },
268
- "maxAllowedSize": 205000
272
+ "maxAllowedSize": 164000
269
273
  },
270
274
  {
271
275
  "credits": "x0.00 credits",
@@ -273,7 +277,7 @@
273
277
  "name": "Kimi-K2.5",
274
278
  "vendor": "f",
275
279
  "maxOutputTokens": 32000,
276
- "maxInputTokens": 205000,
280
+ "maxInputTokens": 164000,
277
281
  "supportsToolCall": true,
278
282
  "supportsImages": true,
279
283
  "supportsReasoning": true,
@@ -283,7 +287,7 @@
283
287
  "effort": "medium",
284
288
  "summary": "auto"
285
289
  },
286
- "maxAllowedSize": 205000
290
+ "maxAllowedSize": 164000
287
291
  },
288
292
  {
289
293
  "credits": "x0.00 credits",
@@ -534,8 +538,9 @@
534
538
  "productFeatures": {
535
539
  "BillingNotice": false,
536
540
  "CustomModelsJSON": true,
537
- "ImageGen": true
541
+ "ImageGen": true,
542
+ "DeferToolLoading": true
538
543
  },
539
- "commit": "10228f026d6ae28624f739de283a081024b8f76b",
540
- "date": "2026-02-02T07:36:54.786Z"
544
+ "commit": "c4e444e0a4ff80e357bbb7c9288e5188b8c7ab30",
545
+ "date": "2026-02-03T15:31:56.145Z"
541
546
  }
package/cli/product.json CHANGED
@@ -30,7 +30,8 @@
30
30
  "internalDomain": [
31
31
  "copilot.tencent.com",
32
32
  "staging-copilot.tencent.com",
33
- "www.codebuddy.cn"
33
+ "www.codebuddy.cn",
34
+ "staging.codebuddy.cn"
34
35
  ],
35
36
  "externalDomain": [
36
37
  "www.codebuddy.ai",
@@ -39,13 +40,16 @@
39
40
  "iOADomain": [
40
41
  "tencent.sso.copilot.tencent.com",
41
42
  "tencent.sso.copilot-staging.tencent.com",
42
- "tencent.sso.codebuddy.cn"
43
+ "tencent.sso.codebuddy.cn",
44
+ "tencent.staging-sso.codebuddy.cn"
43
45
  ],
44
46
  "cloudHostedDomain": [
45
47
  "*.sso.copilot.tencent.com",
46
48
  "*.sso.copilot-staging.tencent.com",
47
49
  "*.copilot.qq.com",
48
- "*.copilot-staging.qq.com"
50
+ "*.copilot-staging.qq.com",
51
+ "*.sso.codebuddy.cn",
52
+ "*.staging-sso.codebuddy.cn"
49
53
  ]
50
54
  }
51
55
  },
@@ -529,6 +533,14 @@
529
533
  {
530
534
  "name": "cli-output-style-description",
531
535
  "template": "You are an interactive CLI tool that helps users according to your \"Output Style\" below, which describes how you should respond to user queries. Use the instructions below and the tools available to you to assist the user."
536
+ },
537
+ {
538
+ "name": "tool-toolsearch-description",
539
+ "template": "Search for available tools using natural language queries.\n\nUse this tool when you need to discover tools that can help with a specific task. Some tools are not loaded by default to save context space - use this to find and activate them.\n\nUsage:\n- Provide a natural language description of what you want to do\n- Returns a list of matching tools sorted by relevance\n- Found tools are automatically activated for use in subsequent messages\n\nExample queries:\n- \"send email notification\"\n- \"database operations\"\n- \"image processing\"\n\nAfter searching, matching tools become available and you can call them directly.\n{%- if toolSearchDeferredTools -%}\n\nAvailable deferred tools (use ToolSearch to discover more):\n{{toolSearchDeferredTools}}\n{%- endif -%}\n"
540
+ },
541
+ {
542
+ "name": "tool-describetool-description",
543
+ "template": "Get detailed information about a specific tool by name.\n\nUse this when you already know the tool name and need its full definition (description and input schema). This is more efficient than searching when the tool name is known.\n\nUsage:\n- Provide the exact tool name (case-sensitive)\n- Returns the tool's full description and parameter schema\n- The tool is automatically activated for use in subsequent messages\n\nIf the tool is not found, consider using ToolSearch to discover available tools by description.\n"
532
544
  }
533
545
  ],
534
546
  "variables": [
@@ -617,7 +629,8 @@
617
629
  "AskUserQuestion",
618
630
  "LSP",
619
631
  "StructuredOutput",
620
- "ImageGen"
632
+ "ImageGen",
633
+ "ToolSearch"
621
634
  ],
622
635
  "tags": [
623
636
  "cli",
@@ -761,6 +774,9 @@
761
774
  "description": "Fast agent specialized for exploring codebases. Use this when you need to quickly find files by patterns (eg. \"src/components/**/*.tsx\"), search code for keywords (eg. \"API endpoints\"), or answer questions about the codebase (eg. \"how do API endpoints work?\"). When calling this agent, specify the desired thoroughness level: \"quick\" for basic searches, \"medium\" for moderate exploration, or \"very thorough\" for comprehensive analysis across multiple locations and naming conventions. (Tools: All tools)",
762
775
  "tools": [
763
776
  "Read",
777
+ "Write",
778
+ "Edit",
779
+ "MultiEdit",
764
780
  "Bash",
765
781
  "Glob",
766
782
  "Grep",
@@ -883,8 +899,9 @@
883
899
  "SelectComponent": true,
884
900
  "UIComponentLibrary": true,
885
901
  "CustomModelsJSON": true,
902
+ "ImageGen": false,
886
903
  "BillingNotice": true,
887
- "ImageGen": false
904
+ "DeferToolLoading": true
888
905
  },
889
906
  "featureToggles": {
890
907
  "SupportHttpsAgentProxy": true
@@ -1062,8 +1079,12 @@
1062
1079
  {
1063
1080
  "name": "ImageGen",
1064
1081
  "description": "tool-imagegen-description"
1082
+ },
1083
+ {
1084
+ "name": "ToolSearch",
1085
+ "description": "tool-toolsearch-description"
1065
1086
  }
1066
1087
  ],
1067
- "commit": "10228f026d6ae28624f739de283a081024b8f76b",
1068
- "date": "2026-02-02T07:36:52.137Z"
1088
+ "commit": "c4e444e0a4ff80e357bbb7c9288e5188b8c7ab30",
1089
+ "date": "2026-02-03T15:31:53.538Z"
1069
1090
  }
@@ -35,7 +35,8 @@
35
35
  "Skill",
36
36
  "AskUserQuestion",
37
37
  "Lsp",
38
- "StructuredOutput"
38
+ "StructuredOutput",
39
+ "ToolSearch"
39
40
  ],
40
41
  "tags": [
41
42
  "cli",
@@ -171,6 +172,9 @@
171
172
  "description": "Fast agent specialized for exploring codebases. Use this when you need to quickly find files by patterns (eg. \"src/components/**/*.tsx\"), search code for keywords (eg. \"API endpoints\"), or answer questions about the codebase (eg. \"how do API endpoints work?\"). When calling this agent, specify the desired thoroughness level: \"quick\" for basic searches, \"medium\" for moderate exploration, or \"very thorough\" for comprehensive analysis across multiple locations and naming conventions. (Tools: All tools)",
172
173
  "tools": [
173
174
  "Read",
175
+ "Write",
176
+ "Edit",
177
+ "MultiEdit",
174
178
  "Bash",
175
179
  "Glob",
176
180
  "Grep",
@@ -218,8 +222,9 @@
218
222
  },
219
223
  "productFeatures": {
220
224
  "BillingNotice": false,
221
- "CustomModelsJSON": true
225
+ "CustomModelsJSON": true,
226
+ "DeferToolLoading": true
222
227
  },
223
- "commit": "10228f026d6ae28624f739de283a081024b8f76b",
224
- "date": "2026-02-02T07:36:57.467Z"
228
+ "commit": "c4e444e0a4ff80e357bbb7c9288e5188b8c7ab30",
229
+ "date": "2026-02-03T15:31:58.747Z"
225
230
  }
@@ -242,6 +242,8 @@ export declare class AcpAgent implements Agent {
242
242
  private sessionLastActivity;
243
243
  /** Track in-progress session loading to prevent race conditions */
244
244
  private sessionLoadingPromises;
245
+ /** Track commands notification handlers per session for cleanup */
246
+ private sessionCommandsHandlers;
245
247
  /**
246
248
  * Create an AcpAgent.
247
249
  *
@@ -361,6 +363,14 @@ export declare class AcpAgent implements Agent {
361
363
  * @param session - Optional session to get current model and available models from.
362
364
  */
363
365
  private getSessionModels;
366
+ /**
367
+ * Subscribe to commands channel and forward all updates to ACP client.
368
+ * Sets up a persistent listener that sends available_commands_update for each notification.
369
+ * This ensures no updates are missed when commands change multiple times.
370
+ * @param sessionId - The session ID to send the updates for
371
+ * @param session - The session to subscribe to commands channel
372
+ */
373
+ private subscribeToCommands;
364
374
  /**
365
375
  * Convert ACP ContentBlock[] to SDK UserMessage.
366
376
  * Delegates to AcpConverter for the actual content block conversion.
@@ -378,6 +388,15 @@ export declare class AcpAgent implements Agent {
378
388
  * @param mode - Conversion mode: 'stream' for prompt(), 'history' for loadSession()
379
389
  */
380
390
  private sendUpdates;
391
+ /**
392
+ * Send system info notification when CLI reports model/permissionMode.
393
+ * Uses custom notification '_codebuddy.ai/system_init' with model and permissionMode.
394
+ */
395
+ private sendSystemInfoNotification;
396
+ /**
397
+ * Filter history messages: only keep the last topic message.
398
+ */
399
+ private filterHistoryMessages;
381
400
  /**
382
401
  * Create a canUseTool handler that wraps the original handler
383
402
  * and intercepts AskUserQuestion requests.
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src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AM,GAAG,OAAO,GAAG,SAAS;IAQnD;;OAEG;IACH,iBAAiB,IAAI,OAAO,GAAG,SAAS;IAIxC;;OAEG;IACH,aAAa,IAAI,MAAM,EAAE;IAIzB;;OAEG;IACH,eAAe,IAAI,MAAM;IAIzB;;;;;OAKG;IACH,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,UAAO,GAAG,OAAO;IA2B9D;;;OAGG;IACH,iBAAiB,CAAC,aAAa,UAAO,GAAG,IAAI;IAM7C;;OAEG;IACH,cAAc,IAAI;QACd,YAAY,EAAE,MAAM,CAAC;QACrB,cAAc,EAAE,MAAM,CAAC;QACvB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;KAC/B;IAiBL;;;OAGG;IACH,OAAO,CAAC,eAAe;IAmBvB;;OAEG;IACH,OAAO,CAAC,YAAY;IAMpB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAoB1B;;;;OAIG;YACW,eAAe;IAa7B;;;;;;OAMG;YACW,gBAAgB;IAqC9B;;;;;;OAMG;YACW,mBAAmB;IAwCjC;;;OAGG;IACH,OAAO,CAAC,6BAA6B;IAcrC;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAS3B;;;;;;OAMG;YACW,WAAW;IAwCzB;;;OAGG;YACW,0BAA0B;IAYxC;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAoB7B;;;;;;;OAOG;IACH,OAAO,CAAC,uBAAuB;IAwB/B;;;;;;;;;;OAUG;YACW,qBAAqB;IA0FnC;;;OAGG;IACH,OAAO,CAAC,OAAO;CAQlB"}
package/lib/acp/agent.js CHANGED
@@ -57,6 +57,8 @@ class AcpAgent {
57
57
  this.sessionLastActivity = new Map();
58
58
  /** Track in-progress session loading to prevent race conditions */
59
59
  this.sessionLoadingPromises = new Map();
60
+ /** Track commands notification handlers per session for cleanup */
61
+ this.sessionCommandsHandlers = new Map();
60
62
  this.connection = connection;
61
63
  this.defaultSession = session;
62
64
  this.options = {
@@ -128,18 +130,22 @@ class AcpAgent {
128
130
  const session = await this.options.onNewSession(params);
129
131
  const sessionId = session.sessionId; // Get the auto-generated sessionId
130
132
  this.registerSession(sessionId, session);
133
+ // Subscribe to commands channel for available_commands_update (async, after return)
134
+ setTimeout(() => this.subscribeToCommands(sessionId, session), 0);
131
135
  return {
132
136
  sessionId,
133
- modes: this.getSessionModes(session),
137
+ modes: await this.getSessionModes(session),
134
138
  models: await this.getSessionModels(session),
135
139
  };
136
140
  }
137
141
  // If we have a default session, return the first registered sessionId
138
142
  if (this.defaultSession && this.sessions.size > 0) {
139
143
  const firstSessionId = this.sessions.keys().next().value;
144
+ // Subscribe to commands channel for available_commands_update (async, after return)
145
+ setTimeout(() => this.subscribeToCommands(firstSessionId, this.defaultSession), 0);
140
146
  return {
141
147
  sessionId: firstSessionId,
142
- modes: this.getSessionModes(this.defaultSession),
148
+ modes: await this.getSessionModes(this.defaultSession),
143
149
  models: await this.getSessionModels(this.defaultSession),
144
150
  };
145
151
  }
@@ -155,8 +161,10 @@ class AcpAgent {
155
161
  const existingPromise = this.sessionLoadingPromises.get(sessionId);
156
162
  if (existingPromise) {
157
163
  const session = await existingPromise;
164
+ // Subscribe to commands channel for available_commands_update (async, after return)
165
+ setTimeout(() => this.subscribeToCommands(sessionId, session), 0);
158
166
  return {
159
- modes: this.getSessionModes(session),
167
+ modes: await this.getSessionModes(session),
160
168
  models: await this.getSessionModels(session),
161
169
  };
162
170
  }
@@ -181,19 +189,29 @@ class AcpAgent {
181
189
  // the Agent MUST respond to the original session/load request."
182
190
  if (session.hasPendingHistory()) {
183
191
  try {
192
+ // Collect all messages first
193
+ const messages = [];
184
194
  for await (const message of session.stream()) {
185
- await this.sendUpdates(sessionId, message, 'history');
195
+ messages.push(message);
186
196
  if (message.type === 'result' || message.type === 'error') {
187
197
  break;
188
198
  }
189
199
  }
200
+ // Filter: only keep the last topic message
201
+ const filtered = this.filterHistoryMessages(messages);
202
+ // Send updates
203
+ for (const message of filtered) {
204
+ await this.sendUpdates(sessionId, message, 'history');
205
+ }
190
206
  }
191
207
  catch (_a) {
192
208
  // ignore streaming errors, still return response
193
209
  }
194
210
  }
211
+ // Subscribe to commands channel for available_commands_update (async, after return)
212
+ setTimeout(() => this.subscribeToCommands(sessionId, session), 0);
195
213
  return {
196
- modes: this.getSessionModes(session),
214
+ modes: await this.getSessionModes(session),
197
215
  models: await this.getSessionModels(session),
198
216
  };
199
217
  }
@@ -204,8 +222,12 @@ class AcpAgent {
204
222
  // No session loader - check if session is already loaded
205
223
  if (this.sessions.has(sessionId)) {
206
224
  const session = this.sessions.get(sessionId);
225
+ // Subscribe to commands channel for available_commands_update (async, after return)
226
+ if (session) {
227
+ setTimeout(() => this.subscribeToCommands(sessionId, session), 0);
228
+ }
207
229
  return {
208
- modes: this.getSessionModes(session),
230
+ modes: await this.getSessionModes(session),
209
231
  models: await this.getSessionModels(session),
210
232
  };
211
233
  }
@@ -244,6 +266,10 @@ class AcpAgent {
244
266
  if ((_a = this.promptAbortController) === null || _a === void 0 ? void 0 : _a.signal.aborted) {
245
267
  return { stopReason: 'cancelled' };
246
268
  }
269
+ // Handle system init message - send custom notification with model/permissionMode
270
+ if (message.type === 'system' && message.subtype === 'init') {
271
+ await this.sendSystemInfoNotification(sessionId, message);
272
+ }
247
273
  // Convert SDK message to ACP format and send updates (stream mode)
248
274
  await this.sendUpdates(sessionId, message, 'stream');
249
275
  // Check for result message (end of turn)
@@ -395,6 +421,9 @@ class AcpAgent {
395
421
  // Ignore close errors
396
422
  }
397
423
  }
424
+ // Clean up commands notification handler if exists
425
+ // Note: We don't need to explicitly unsubscribe from CLI since session is closing
426
+ this.sessionCommandsHandlers.delete(sessionId);
398
427
  // Clean up all associated resources
399
428
  this.sessions.delete(sessionId);
400
429
  this.sessionConverters.delete(sessionId);
@@ -479,21 +508,10 @@ class AcpAgent {
479
508
  * Returns the available modes and current mode from the given session.
480
509
  * @param session - Optional session to get current mode from. If not provided, uses default.
481
510
  */
482
- getSessionModes(session) {
511
+ async getSessionModes(session) {
483
512
  var _a, _b;
484
513
  // Use configured modes or default basic set
485
- const availableModes = (_a = this.options.availableModes) !== null && _a !== void 0 ? _a : [
486
- {
487
- id: 'default',
488
- name: 'Default',
489
- description: 'Standard assistant mode with full capabilities',
490
- },
491
- {
492
- id: 'plan',
493
- name: 'Plan',
494
- description: 'Planning mode for designing implementation approaches',
495
- },
496
- ];
514
+ const availableModes = (_a = this.options.availableModes) !== null && _a !== void 0 ? _a : (session ? await session.getAvailableModes().catch(() => []) : []);
497
515
  // Get current mode from the provided session or fall back to default
498
516
  const currentModeId = (_b = session === null || session === void 0 ? void 0 : session.getPermissionMode()) !== null && _b !== void 0 ? _b : 'default';
499
517
  return {
@@ -543,6 +561,50 @@ class AcpAgent {
543
561
  : undefined,
544
562
  };
545
563
  }
564
+ /**
565
+ * Subscribe to commands channel and forward all updates to ACP client.
566
+ * Sets up a persistent listener that sends available_commands_update for each notification.
567
+ * This ensures no updates are missed when commands change multiple times.
568
+ * @param sessionId - The session ID to send the updates for
569
+ * @param session - The session to subscribe to commands channel
570
+ */
571
+ async subscribeToCommands(sessionId, session) {
572
+ try {
573
+ // Create handler that forwards all commands notifications to ACP client
574
+ const handler = (notification) => {
575
+ const data = notification.data;
576
+ const commands = data.commands.map(cmd => {
577
+ const result = {
578
+ // Remove leading '/' from command name if present
579
+ name: cmd.name.startsWith('/') ? cmd.name.substring(1) : cmd.name,
580
+ description: cmd.description || '',
581
+ };
582
+ if (cmd.argumentHint) {
583
+ result.input = { hint: cmd.argumentHint };
584
+ }
585
+ return result;
586
+ });
587
+ // Send update to ACP client (fire-and-forget)
588
+ this.connection.sessionUpdate({
589
+ sessionId,
590
+ update: {
591
+ sessionUpdate: 'available_commands_update',
592
+ availableCommands: commands,
593
+ },
594
+ }).catch(error => {
595
+ console.error('[AcpAgent] Failed to send available commands update:', error);
596
+ });
597
+ };
598
+ // Store handler for cleanup
599
+ this.sessionCommandsHandlers.set(sessionId, handler);
600
+ // Subscribe to commands channel via session's subscribeToCommands method
601
+ await session.subscribeToCommands(handler);
602
+ }
603
+ catch (error) {
604
+ // Silently ignore errors - available commands are optional
605
+ console.error('[AcpAgent] Failed to subscribe to commands channel:', error);
606
+ }
607
+ }
546
608
  /**
547
609
  * Convert ACP ContentBlock[] to SDK UserMessage.
548
610
  * Delegates to AcpConverter for the actual content block conversion.
@@ -611,6 +673,40 @@ class AcpAgent {
611
673
  }
612
674
  }
613
675
  }
676
+ /**
677
+ * Send system info notification when CLI reports model/permissionMode.
678
+ * Uses custom notification '_codebuddy.ai/system_init' with model and permissionMode.
679
+ */
680
+ async sendSystemInfoNotification(sessionId, sysMsg) {
681
+ try {
682
+ await this.connection.extNotification('_codebuddy.ai/system_init', {
683
+ sessionId,
684
+ model: sysMsg.model,
685
+ permissionMode: sysMsg.permissionMode,
686
+ });
687
+ }
688
+ catch (_a) {
689
+ // Silently ignore notification errors
690
+ }
691
+ }
692
+ /**
693
+ * Filter history messages: only keep the last topic message.
694
+ */
695
+ filterHistoryMessages(messages) {
696
+ const result = [];
697
+ let foundLastTopic = false;
698
+ for (let i = messages.length - 1; i >= 0; i--) {
699
+ const msg = messages[i];
700
+ if ('type' in msg && msg.type === 'topic') {
701
+ if (foundLastTopic) {
702
+ continue; // Skip earlier topic messages
703
+ }
704
+ foundLastTopic = true;
705
+ }
706
+ result.unshift(msg);
707
+ }
708
+ return result;
709
+ }
614
710
  // ============= AskUserQuestion Support =============
615
711
  /**
616
712
  * Create a canUseTool handler that wraps the original handler