dsh-agent-sdk-bridge 1.3.0 → 1.3.3

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/DEVELOPMENT.md CHANGED
@@ -161,6 +161,12 @@
161
161
  执行世界;Qoder / CodeBuddy / MiniMax 在图片块前插入这条句柄,历史图片(rebuild 时按文本重放、
162
162
  不发像素)同样带路径。另外三个适配器都会记住每个路由上一次验证过的 `vision` 能力:目录某次读不到
163
163
  时不再谎报 text-only——那会让 DSH 在适配器之前就把像素剥成占位符。
164
+ - **工具结果的图片走 MCP/ACP 结果通道**:`read_image` 把图片放在 tool 消息里返回,而这三条路由的
165
+ 工具结果不经提示词 feed,而是由 `renderResultContent` / `renderCodeBuddyResult` /
166
+ `renderToolResult` 序列化成 MCP(或 ACP)结果。此前 CodeBuddy 把它换成
167
+ `[图片结果未转发给 CodeBuddy]`、MiniMax 退化成 JSON 文本,模型只看到路径、看不到像素。现在
168
+ 适配器先对「未喂过的 tail」统一解析图片(`resolveTurnImages`,含 tool 消息),渲染器把可解析的
169
+ 附件输出为 `{type:'image', data, mimeType}`,宿主读不到时退回 `textOnlyImageText` 句柄,不静默丢弃。
164
170
  - **CodeBuddy 额度**:SDK 没有额度方法,`readQuotaWithToken()` 用登录 token 调
165
171
  `POST /v2/billing/meter/get-user-resource`(国内与国际同协议),按积分包汇总实时余额;
166
172
  额度读取优先用保存的 token,缺失时才静默 `authenticate`,不会拉起浏览器。卡片里的积分包
package/FAQ.md CHANGED
@@ -129,6 +129,21 @@ CodeBuddy 那句显眼的报错。现在两条路径共用 `HostToolRegistry`,
129
129
  共用它,不再各写一份一层 `slice`。判据是 `test/mcp-naming.test.ts`,其中「双层前缀剥到
130
130
  `edit`」和「三家一致」两条在单层剥离下确认过是红的。
131
131
 
132
+
133
+ **改完之后还是会报 `Tool "mcp__dsh_host__read_files" does not exist in the current tool set.`?** 也已修复,
134
+ 这是同一个症状的第三层:**模型发出的名字和 CLI 调用查找表里的名字拼写不一致**。CLI 建调用表时
135
+ 用的是注册键**原样**(过去是 `dsh-host`,于是键是 `mcp__dsh-host__read_files`),而它自己的多个
136
+ 代码路径(`parseMcpToolName`、插件工具命名、线上格式规范器)都会把服务器名里的非字母数字字符
137
+ 改写成 `_`。模型只要发出规范化拼写的 `mcp__dsh_host__read_files`——真实会话里就是这么发的——
138
+ 在 CLI 的查找表里就没有这个键,`findToolInMap` 只做大小写容错,于是在**到达本插件之前**就被
139
+ CLI 拒了;上一轮的剥层修复(`hostToolName`)根本没机会运行。本地日志与会话记录里查不到这条
140
+ 报错,也是因为这个:报错发生在内层 CLI 里,只有截图能看到。
141
+
142
+ 修法是从源头消灭第二种拼写:注册键直接用 CLI 的规范形 `dsh_host`(`CODEBUDDY_MCP_SERVER_KEY`)。
143
+ 这样「模型看到的列表名 = CLI 调用表的键 = CLI 各处规范化输出」三者完全一致,无从猜错;旧的
144
+ 连字符拼写仍被 `isHostTool()` / `hostToolName()` 接受,在途的名字照常处理。判据是
145
+ `test/codebuddy-session.test.ts`:「注册键为 `dsh_host`」与「识别 CLI 规范化拼写」两条。
146
+
132
147
  顺带一提:同一张截图里的 `cannot modify "…": file has not been read — read the file, then retry`
133
148
  是**另一回事**——那是 DSH 的 `dsh-tool-fs` 观测策略(`FS_NOT_OBSERVED`),要求改之前先读;
134
149
  它属于宿主侧的正常门禁,跟工具注册无关。模型当时也注意到了这一点(它说「要先 read」)。
@@ -173,6 +188,12 @@ prompt 里出现指令、且**不出现**「下一条助手回复」,并逐家
173
188
  模型可以直接复制、处理并保存。顺带修好另一个隐患:目录某一刻读不到时,不再把视觉模型临时当成
174
189
  text-only,否则 DSH 会在适配器之前就把像素换成占位文本。
175
190
 
191
+ **让模型看本地图片(如 `C:\pictures\9.png`)时,它为什么说看不到?** DSH 会先调用 `read_image`,
192
+ 图片放在 tool 消息里返回。Qoder / CodeBuddy / MiniMax 的工具结果走 MCP/ACP 结果通道而不是提示词,
193
+ 桥接此前在 CodeBuddy 路径上把它换成了「图片结果未转发」的文本、在 MiniMax 路径上序列化成 JSON,
194
+ 像素因此丢失。现在两条路径都会把附件解析成真正的图片块,宿主读不到时才退回带路径的句柄文本。
195
+ 升级插件并重启 DSH 后再试。
196
+
176
197
  **点了「登录」却没有弹出浏览器,或者弹出了两个?** CodeBuddy 的 CLI 在登录流程里会自己打开
177
198
  浏览器,插件只把登录链接显示在卡片上作为兜底,不再额外打开,所以一次登录只会有一个标签页。
178
199
  每次点击还会先清除该区域在 CLI 中缓存的旧凭据,再启动全新的授权流程;SDK 的 `authenticate()`
package/client.js CHANGED
@@ -95,8 +95,8 @@ window.__ModuleLoader__.load({
95
95
  cliLogoutConfirm: '确定要退出当前 Qoder 账号吗?退出后会关闭已打开的会话并清空额度,需要重新登录才能继续使用;CLI 本身不会被卸载。',
96
96
  cliLoggingOut: '正在退出登录…',
97
97
  cliLogoutOk: '已退出登录',
98
- cliVersionMismatch: 'CLI 版本与插件不匹配:本机',
99
- cliVersionMismatchTail: ',插件需要',
98
+ cliVersionMismatch: 'CLI 版本过旧:本机',
99
+ cliVersionMismatchTail: ',插件至少需要',
100
100
  intlNav: 'Qoder 国际版',
101
101
  intlTitle: 'Qoder 国际版',
102
102
  intlIntro: '国际版账户(qoder.com)的模型与额度。勾选要启用的模型,并为需要的模型指定上下文窗口。改动即时生效,无需重启。',
@@ -298,8 +298,8 @@ window.__ModuleLoader__.load({
298
298
  cliLogoutConfirm: 'Sign out of the current Qoder account? Open sessions will be closed and quota cleared; you will need to sign in again. The CLI itself stays installed.',
299
299
  cliLoggingOut: 'Signing out…',
300
300
  cliLogoutOk: 'Signed out',
301
- cliVersionMismatch: 'CLI version does not match the plugin: this machine has',
302
- cliVersionMismatchTail: 'but the plugin needs',
301
+ cliVersionMismatch: 'CLI too old: this machine has',
302
+ cliVersionMismatchTail: 'but the plugin needs at least',
303
303
  intlNav: 'Qoder International',
304
304
  intlTitle: 'Qoder International',
305
305
  intlIntro: 'Models and quota for the international account (qoder.com). Tick the models you want available and set a context window where needed. Changes apply immediately.',
@@ -2431,8 +2431,10 @@ window.__ModuleLoader__.load({
2431
2431
  brand.kind !== 'qoder' ? null : h('div', { style: css.group },
2432
2432
  h('h3', { style: css.h3 }, t(brand.cliGroupKey)),
2433
2433
  h('div', { style: css.note }, t(brand.cliHintKey)),
2434
- // Each SDK release pins one CLI build; a mismatch kills every session
2435
- // with a bare exit code, so warn before the user signs in or chats.
2434
+ // The CLI moves on its own (`qodercli update`), so only a build older
2435
+ // than the SDK's pin is reported: that is the one that fails every
2436
+ // session with a bare exit code. A newer build is fine and follows
2437
+ // upstream as the user expects.
2436
2438
  setup?.versionMismatch === true
2437
2439
  ? h('div', { style: { ...css.err, marginTop: '6px' } },
2438
2440
  `${t('cliVersionMismatch')} ${setup.cliVersion ?? '?'} ${t('cliVersionMismatchTail')} ${setup.requiredCliVersion ?? '?'}`)
package/lib/index.js CHANGED
@@ -4292,8 +4292,25 @@ const CODEBUDDY_FETCH_TIMEOUT_MS = 3e4;
4292
4292
  const LOGIN_TIMEOUT_MS = 3e5;
4293
4293
  /** Bound for clearing stale credentials before a fresh browser login. */
4294
4294
  const LOGOUT_TIMEOUT_MS = 2e4;
4295
+ /**
4296
+ * The key this plugin's MCP server is registered under, in the CodeBuddy CLI.
4297
+ *
4298
+ * It is the CLI's own normalised spelling - `dsh_host`, not `dsh-host` - and
4299
+ * that choice is the fix for the recurring "tool went missing": the CLI builds
4300
+ * its call-time tool map from `mcp__<key>__<tool>` with the key verbatim,
4301
+ * while several of its own code paths (`parseMcpToolName`, the plugin tool
4302
+ * namer, the wire-format normaliser) rewrite every non-alphanumeric character
4303
+ * to `_`. With a hyphenated key the list showed `mcp__dsh-host__read_files`
4304
+ * while a model that emitted the normalised `mcp__dsh_host__read_files` - as
4305
+ * one did, verbatim, in a failed session - found no entry, and the CLI refused
4306
+ * the call with `Tool "..." does not exist in the current tool set.` before it
4307
+ * ever reached this server. Registering under the normalised spelling makes
4308
+ * list, lookup and normalisation one and the same name, so there is no second
4309
+ * spelling to guess.
4310
+ */
4311
+ const CODEBUDDY_MCP_SERVER_KEY = "dsh_host";
4295
4312
  /** Both spellings, in the order the shared stripper tries them. */
4296
- const HOST_TOOL_PREFIXES$1 = [`mcp__${MCP_SERVER_NAME}__`, `mcp__${MCP_SERVER_NAME.replace(/[^a-zA-Z0-9]/g, "_")}__`];
4313
+ const HOST_TOOL_PREFIXES$1 = [`mcp__${CODEBUDDY_MCP_SERVER_KEY}__`, `mcp__${MCP_SERVER_NAME}__`];
4297
4314
  /** Whether a CLI tool name belongs to this plugin's MCP server. */
4298
4315
  function isHostTool(toolName) {
4299
4316
  return stripMcpNamespace(toolName, HOST_TOOL_PREFIXES$1) !== null;
@@ -5127,7 +5144,7 @@ var CodeBuddySession = class {
5127
5144
  this.registry.reconcile(this.toolSchemas);
5128
5145
  }
5129
5146
  /** Hand the host's tool results to parked or buffered handlers. */
5130
- deliverToolResults(tail) {
5147
+ deliverToolResults(tail, images) {
5131
5148
  let freshUserTurn = false;
5132
5149
  const delivered = /* @__PURE__ */ new Set();
5133
5150
  for (const message of tail) {
@@ -5137,7 +5154,7 @@ var CodeBuddySession = class {
5137
5154
  }
5138
5155
  if (message.role !== "tool") continue;
5139
5156
  delivered.add(this.pairing.deliver(String(message.toolCallId), {
5140
- content: renderCodeBuddyResult(message.content),
5157
+ content: renderCodeBuddyResult(message.content, images),
5141
5158
  isError: message.isError === true
5142
5159
  }));
5143
5160
  }
@@ -5210,7 +5227,7 @@ var CodeBuddySession = class {
5210
5227
  if (this.session !== null) return this.session;
5211
5228
  const sdk = await loadCodeBuddySdk();
5212
5229
  this.mcp ??= sdk.createSdkMcpServer({
5213
- name: MCP_SERVER_NAME,
5230
+ name: CODEBUDDY_MCP_SERVER_KEY,
5214
5231
  tools: []
5215
5232
  });
5216
5233
  this.registry ??= new HostToolRegistry(this.mcp.instance, () => async () => {
@@ -5226,7 +5243,7 @@ var CodeBuddySession = class {
5226
5243
  environment: codeBuddyEnvironment(this.region),
5227
5244
  sessionId: randomUUID(),
5228
5245
  model: this.model,
5229
- mcpServers: { [MCP_SERVER_NAME]: this.mcp },
5246
+ mcpServers: { [CODEBUDDY_MCP_SERVER_KEY]: this.mcp },
5230
5247
  canUseTool: this.canUseTool,
5231
5248
  tools: [],
5232
5249
  ...cliEnv(this.region),
@@ -5568,7 +5585,7 @@ var CodeBuddySession = class {
5568
5585
  }
5569
5586
  };
5570
5587
  /** Render host tool-result blocks into the MCP content the inner model reads. */
5571
- function renderCodeBuddyResult(blocks) {
5588
+ function renderCodeBuddyResult(blocks, images) {
5572
5589
  if (!Array.isArray(blocks)) return [{
5573
5590
  type: "text",
5574
5591
  text: String(blocks ?? "")
@@ -5578,11 +5595,18 @@ function renderCodeBuddyResult(blocks) {
5578
5595
  type: "text",
5579
5596
  text: block.text ?? ""
5580
5597
  });
5581
- else if (block.type === "image") content.push({
5582
- type: "text",
5583
- text: "[图片结果未转发给 CodeBuddy]"
5584
- });
5585
- else content.push({
5598
+ else if (block.type === "image" && block.attachment !== null && typeof block.attachment === "object") {
5599
+ const attachment = block.attachment;
5600
+ const resolved = images?.get(String(attachment.attachmentId));
5601
+ content.push(resolved === void 0 ? {
5602
+ type: "text",
5603
+ text: textOnlyImageText(attachment)
5604
+ } : {
5605
+ type: "image",
5606
+ data: resolved.data,
5607
+ mimeType: resolved.mediaType
5608
+ });
5609
+ } else content.push({
5586
5610
  type: "text",
5587
5611
  text: JSON.stringify(block)
5588
5612
  });
@@ -5872,10 +5896,24 @@ var CodeBuddyAdapter = class extends LlmAdapter {
5872
5896
  * prompt instead of failing the whole turn.
5873
5897
  */
5874
5898
  async resolveFeedImages(feed, vision, signal) {
5899
+ return await this.resolveImages(feedImageRefs(feed), vision, signal);
5900
+ }
5901
+ /**
5902
+ * Images carried by the messages the inner session has not seen yet.
5903
+ *
5904
+ * Tool results are included: `read_image` hands its pixels back through the
5905
+ * MCP tool result, not through the prompt text, so this tail is the only
5906
+ * place the bytes can come from.
5907
+ */
5908
+ async resolveTurnImages(tail, vision, signal) {
5909
+ const refs = tail.flatMap((message) => message.role === "assistant" ? [] : imageRefs(message.content));
5910
+ return await this.resolveImages(refs, vision, signal);
5911
+ }
5912
+ async resolveImages(refs, vision, signal) {
5875
5913
  const map = /* @__PURE__ */ new Map();
5876
5914
  const readImage = this.options.readImage;
5877
5915
  if (!vision || readImage === void 0) return map;
5878
- for (const ref of feedImageRefs(feed)) {
5916
+ for (const ref of refs) {
5879
5917
  const key = String(ref.attachmentId);
5880
5918
  if (map.has(key)) continue;
5881
5919
  try {
@@ -6013,7 +6051,9 @@ var CodeBuddyAdapter = class extends LlmAdapter {
6013
6051
  return;
6014
6052
  }
6015
6053
  const tail = options.messages.slice(session.fedMessages.length);
6016
- session.deliverToolResults(tail);
6054
+ const vision = await this.modelVision(options.model);
6055
+ const images = await this.resolveTurnImages(tail, vision, options.signal);
6056
+ session.deliverToolResults(tail, images);
6017
6057
  const plan = planContinuation(session.fedMessages, options.messages);
6018
6058
  if (plan.rebuild) {
6019
6059
  this.sessions.dispose(sessionId);
@@ -6030,7 +6070,6 @@ var CodeBuddyAdapter = class extends LlmAdapter {
6030
6070
  session.ensureTools(options.tools ?? []);
6031
6071
  session.fedMessages = options.messages;
6032
6072
  session.fedSystem = options.system;
6033
- const vision = await this.modelVision(options.model);
6034
6073
  const feed = plan.feed === null ? null : await this.buildFeed(plan.feed, vision, options.signal);
6035
6074
  yield* session.stream(options, feed);
6036
6075
  }
@@ -7130,8 +7169,15 @@ var EventQueue = class {
7130
7169
  });
7131
7170
  }
7132
7171
  };
7133
- /** Render a harness tool result for the MCP caller. */
7134
- function renderToolResult(content) {
7172
+ /**
7173
+ * Render a harness tool result for the MCP caller.
7174
+ *
7175
+ * A tool result can carry pixels (`read_image` returns the picture beside its
7176
+ * path envelope). The MCP result schema passes an image block straight to the
7177
+ * agent, so a resolvable attachment becomes `{type:'image'}`; one the host
7178
+ * could not read falls back to the harness handle text instead of vanishing.
7179
+ */
7180
+ function renderToolResult(content, images) {
7135
7181
  const text = (value) => {
7136
7182
  if (typeof value === "string") return value;
7137
7183
  if (value === null || value === void 0) return "";
@@ -7143,22 +7189,49 @@ function renderToolResult(content) {
7143
7189
  };
7144
7190
  if (Array.isArray(content)) {
7145
7191
  const parts = [];
7192
+ let pending = [];
7193
+ const flush = () => {
7194
+ if (pending.length === 0) return;
7195
+ parts.push({
7196
+ type: "text",
7197
+ text: pending.join("\n")
7198
+ });
7199
+ pending = [];
7200
+ };
7146
7201
  for (const block of content) {
7147
7202
  if (typeof block === "string") {
7148
- parts.push(block);
7203
+ pending.push(block);
7149
7204
  continue;
7150
7205
  }
7151
- if (block !== null && typeof block === "object" && block.type === "text") {
7152
- parts.push(text(block.text));
7153
- continue;
7206
+ if (block !== null && typeof block === "object") {
7207
+ const typed = block;
7208
+ if (typed.type === "text") {
7209
+ pending.push(text(typed.text));
7210
+ continue;
7211
+ }
7212
+ if (typed.type === "image" && typed.attachment !== null && typeof typed.attachment === "object") {
7213
+ const attachment = typed.attachment;
7214
+ const resolved = images?.get(String(attachment.attachmentId));
7215
+ flush();
7216
+ parts.push(resolved === void 0 ? {
7217
+ type: "text",
7218
+ text: textOnlyImageText(attachment)
7219
+ } : {
7220
+ type: "image",
7221
+ data: resolved.data,
7222
+ mimeType: resolved.mediaType
7223
+ });
7224
+ continue;
7225
+ }
7154
7226
  }
7155
- parts.push(text(block));
7227
+ pending.push(text(block));
7156
7228
  }
7157
- const joined = parts.join("\n").trim();
7158
- return { content: [{
7229
+ flush();
7230
+ if (parts.length === 0) return { content: [{
7159
7231
  type: "text",
7160
- text: joined === "" ? "(宿主工具没有返回内容)" : joined
7232
+ text: "(宿主工具没有返回内容)"
7161
7233
  }] };
7234
+ return { content: parts };
7162
7235
  }
7163
7236
  const joined = text(content).trim();
7164
7237
  return { content: [{
@@ -7876,7 +7949,7 @@ var MinimaxSession = class {
7876
7949
  this.bridge.setTools(tools);
7877
7950
  }
7878
7951
  /** Hand the host's tool results to parked handlers. */
7879
- deliverToolResults(tail) {
7952
+ deliverToolResults(tail, images) {
7880
7953
  let freshUserTurn = false;
7881
7954
  for (const message of tail) {
7882
7955
  if (message.role === "user") {
@@ -7890,7 +7963,7 @@ var MinimaxSession = class {
7890
7963
  clearTimeout(pending.timer);
7891
7964
  this.pending.delete(callId);
7892
7965
  pending.resolve({
7893
- ...renderToolResult(message.content),
7966
+ ...renderToolResult(message.content, images),
7894
7967
  ...message.isError === true ? { isError: true } : {}
7895
7968
  });
7896
7969
  }
@@ -8755,7 +8828,9 @@ var MinimaxAdapter = class extends LlmAdapter {
8755
8828
  return;
8756
8829
  }
8757
8830
  const tail = options.messages.slice(session.fedMessages.length);
8758
- session.deliverToolResults(tail);
8831
+ const vision = await this.modelVision(model, region);
8832
+ const images = await this.resolveTurnImages(tail, vision, options.signal);
8833
+ session.deliverToolResults(tail, images);
8759
8834
  const plan = planContinuation(session.fedMessages, options.messages);
8760
8835
  if (plan.rebuild) {
8761
8836
  this.sessions.dispose(sessionId);
@@ -8782,7 +8857,6 @@ var MinimaxAdapter = class extends LlmAdapter {
8782
8857
  session.ensureTools(options.tools ?? []);
8783
8858
  session.fedMessages = options.messages;
8784
8859
  session.fedSystem = options.system;
8785
- const vision = await this.modelVision(model, region);
8786
8860
  const feed = plan.feed === null ? null : await this.buildFeed(plan.feed, vision, options.signal);
8787
8861
  yield* session.stream(options, feed);
8788
8862
  }
@@ -8821,20 +8895,7 @@ var MinimaxAdapter = class extends LlmAdapter {
8821
8895
  async buildFeed(feed, vision, signal) {
8822
8896
  if (typeof feed === "string") return feed;
8823
8897
  if (!vision) return feedToText(feed, this.options.imagePath);
8824
- const images = /* @__PURE__ */ new Map();
8825
- const readImage = this.options.readImage;
8826
- if (readImage !== void 0) for (const ref of feedImageRefs(feed)) {
8827
- const key = String(ref.attachmentId);
8828
- if (images.has(key)) continue;
8829
- try {
8830
- const image = await readImage(ref, signal);
8831
- if (image !== void 0) images.set(key, {
8832
- data: Buffer.from(image.bytes).toString("base64"),
8833
- mediaType: image.mediaType
8834
- });
8835
- } catch {}
8836
- }
8837
- const parts = resolvedFeedParts(feed, images);
8898
+ const parts = resolvedFeedParts(feed, await this.resolveImages(feedImageRefs(feed), vision, signal));
8838
8899
  if (!parts.some((part) => part.type !== "text")) return parts.map((part) => part.type === "text" ? part.text : "").join("\n\n");
8839
8900
  const content = [];
8840
8901
  for (const part of parts) {
@@ -8859,6 +8920,34 @@ var MinimaxAdapter = class extends LlmAdapter {
8859
8920
  }
8860
8921
  return content;
8861
8922
  }
8923
+ /**
8924
+ * Images carried by the messages the inner session has not seen yet.
8925
+ *
8926
+ * Tool results are included: `read_image` hands its pixels back through the
8927
+ * ACP tool result, not through the prompt text, so this tail is the only
8928
+ * place the bytes can come from.
8929
+ */
8930
+ async resolveTurnImages(tail, vision, signal) {
8931
+ const refs = tail.flatMap((message) => message.role === "assistant" ? [] : imageRefs(message.content));
8932
+ return await this.resolveImages(refs, vision, signal);
8933
+ }
8934
+ async resolveImages(refs, vision, signal) {
8935
+ const map = /* @__PURE__ */ new Map();
8936
+ const readImage = this.options.readImage;
8937
+ if (!vision || readImage === void 0) return map;
8938
+ for (const ref of refs) {
8939
+ const key = String(ref.attachmentId);
8940
+ if (map.has(key)) continue;
8941
+ try {
8942
+ const image = await readImage(ref, signal);
8943
+ if (image !== void 0) map.set(key, {
8944
+ data: Buffer.from(image.bytes).toString("base64"),
8945
+ mediaType: image.mediaType
8946
+ });
8947
+ } catch {}
8948
+ }
8949
+ return map;
8950
+ }
8862
8951
  cwdOf(options) {
8863
8952
  return options.cwd;
8864
8953
  }
@@ -9028,7 +9117,7 @@ function readSetupStatus(brand = "cn") {
9028
9117
  installed,
9029
9118
  ...cliVersion === void 0 ? {} : { cliVersion },
9030
9119
  ...required === void 0 ? {} : { requiredCliVersion: required },
9031
- ...cliVersion === void 0 || required === void 0 ? {} : { versionMismatch: cliVersion !== required }
9120
+ ...cliVersion === void 0 || required === void 0 ? {} : { versionMismatch: compareVersions(cliVersion, required) < 0 }
9032
9121
  };
9033
9122
  const run = current.get(brand);
9034
9123
  if (run === void 0) return {
@@ -9076,6 +9165,29 @@ function cancelSetup(brand) {
9076
9165
  return true;
9077
9166
  }
9078
9167
  /**
9168
+ * Compare two dotted versions, numerically per segment.
9169
+ *
9170
+ * A plain string compare would rank `1.1.9` above `1.1.10`, which is exactly
9171
+ * backwards for the decision this feeds.
9172
+ *
9173
+ * @param left - one version, e.g. `1.1.84`.
9174
+ * @param right - the other, e.g. `1.1.81`.
9175
+ * @returns negative when `left` is older, positive when newer, 0 when equal.
9176
+ */
9177
+ function compareVersions(left, right) {
9178
+ const parse = (value) => value.split(/[.-]/).map((part) => {
9179
+ const n = Number.parseInt(part, 10);
9180
+ return Number.isFinite(n) ? n : 0;
9181
+ });
9182
+ const a = parse(left);
9183
+ const b = parse(right);
9184
+ for (let i = 0; i < Math.max(a.length, b.length); i += 1) {
9185
+ const diff = (a[i] ?? 0) - (b[i] ?? 0);
9186
+ if (diff !== 0) return diff < 0 ? -1 : 1;
9187
+ }
9188
+ return 0;
9189
+ }
9190
+ /**
9079
9191
  * Abandon the running helper, if any.
9080
9192
  *
9081
9193
  * Called when the plugin is disposed. Killing `cmd.exe` does not reap the CLI it
@@ -88,6 +88,15 @@ export declare class CodeBuddyAdapter extends LlmAdapter {
88
88
  * prompt instead of failing the whole turn.
89
89
  */
90
90
  private resolveFeedImages;
91
+ /**
92
+ * Images carried by the messages the inner session has not seen yet.
93
+ *
94
+ * Tool results are included: `read_image` hands its pixels back through the
95
+ * MCP tool result, not through the prompt text, so this tail is the only
96
+ * place the bytes can come from.
97
+ */
98
+ private resolveTurnImages;
99
+ private resolveImages;
91
100
  /**
92
101
  * Turn a feed into what one CLI turn receives.
93
102
  *
@@ -16,7 +16,7 @@ import type { RawLanguageModel } from '@tencent-ai/agent-sdk';
16
16
  import type { CodeBuddyRegion } from './brand.ts';
17
17
  import { CodeBuddyStateStore } from './codebuddy-state.ts';
18
18
  import type { Live } from './live.ts';
19
- import type { ChannelContent } from './session.ts';
19
+ import type { ChannelContent, ResolvedImages, ToolResultPayload } from './session.ts';
20
20
  /** Default context capacity assumed for a CodeBuddy model that declares none. */
21
21
  export declare const CODEBUDDY_DEFAULT_CONTEXT_WINDOW = 200000;
22
22
  /** Default output cap when the catalog declares none. */
@@ -346,7 +346,7 @@ export declare class CodeBuddySession {
346
346
  toolCallId?: unknown;
347
347
  content?: unknown;
348
348
  isError?: boolean;
349
- }[]): void;
349
+ }[], images?: ResolvedImages): void;
350
350
  /** Run one host turn; `feed` is new user content, or null for a tool continuation. */
351
351
  stream(options: GenerateOptions, feed: string | ChannelContent[] | null): AsyncGenerator<StreamChunk>;
352
352
  /** Tear the inner CLI down; parked handlers settle with a cancellation. */
@@ -363,6 +363,8 @@ export declare class CodeBuddySession {
363
363
  private usage;
364
364
  private endTurn;
365
365
  }
366
+ /** Render host tool-result blocks into the MCP content the inner model reads. */
367
+ export declare function renderCodeBuddyResult(blocks: unknown, images?: ResolvedImages): ToolResultPayload['content'];
366
368
  /**
367
369
  * Warm sessions keyed by host session id. A region change retires the old
368
370
  * session rather than mutating one, because the CLI process was started with
@@ -106,6 +106,15 @@ export declare class MinimaxAdapter extends LlmAdapter {
106
106
  * keeps its handle text, so it degrades one part instead of failing the turn.
107
107
  */
108
108
  private buildFeed;
109
+ /**
110
+ * Images carried by the messages the inner session has not seen yet.
111
+ *
112
+ * Tool results are included: `read_image` hands its pixels back through the
113
+ * ACP tool result, not through the prompt text, so this tail is the only
114
+ * place the bytes can come from.
115
+ */
116
+ private resolveTurnImages;
117
+ private resolveImages;
109
118
  private cwdOf;
110
119
  close(): void;
111
120
  }
@@ -48,10 +48,14 @@ export interface MinimaxModel {
48
48
  }
49
49
  /** One tool call's result, in the shape the MCP bridge returns. */
50
50
  export interface MinimaxMcpToolResult {
51
- content: {
51
+ content: ({
52
52
  type: 'text';
53
53
  text: string;
54
- }[];
54
+ } | {
55
+ type: 'image';
56
+ data: string;
57
+ mimeType: string;
58
+ })[];
55
59
  isError?: boolean;
56
60
  }
57
61
  /**
@@ -272,6 +276,18 @@ type SessionEvent = {
272
276
  kind: 'closed';
273
277
  error: Error;
274
278
  };
279
+ /**
280
+ * Render a harness tool result for the MCP caller.
281
+ *
282
+ * A tool result can carry pixels (`read_image` returns the picture beside its
283
+ * path envelope). The MCP result schema passes an image block straight to the
284
+ * agent, so a resolvable attachment becomes `{type:'image'}`; one the host
285
+ * could not read falls back to the harness handle text instead of vanishing.
286
+ */
287
+ export declare function renderToolResult(content: unknown, images?: ReadonlyMap<string, {
288
+ data: string;
289
+ mediaType: string;
290
+ }>): MinimaxMcpToolResult;
275
291
  /** Options for one ACP process. */
276
292
  interface MinimaxAcpOptions {
277
293
  region: MinimaxRegion;
@@ -487,7 +503,10 @@ export declare class MinimaxSession {
487
503
  toolCallId?: unknown;
488
504
  content?: unknown;
489
505
  isError?: boolean;
490
- }[]): void;
506
+ }[], images?: ReadonlyMap<string, {
507
+ data: string;
508
+ mediaType: string;
509
+ }>): void;
491
510
  /** Run one harness turn. `feed` is new user content, or null for a continuation. */
492
511
  stream(options: GenerateOptions, feed: string | readonly MinimaxPromptBlock[] | null): AsyncGenerator<StreamChunk>;
493
512
  /** Tear the ACP process down; parked handlers settle with a cancellation. */
@@ -102,6 +102,17 @@ export declare function readSetupStatus(brand?: QoderBrand): SetupStatus;
102
102
  * @returns whether a run was actually in flight.
103
103
  */
104
104
  export declare function cancelSetup(brand: QoderBrand): boolean;
105
+ /**
106
+ * Compare two dotted versions, numerically per segment.
107
+ *
108
+ * A plain string compare would rank `1.1.9` above `1.1.10`, which is exactly
109
+ * backwards for the decision this feeds.
110
+ *
111
+ * @param left - one version, e.g. `1.1.84`.
112
+ * @param right - the other, e.g. `1.1.81`.
113
+ * @returns negative when `left` is older, positive when newer, 0 when equal.
114
+ */
115
+ export declare function compareVersions(left: string, right: string): number;
105
116
  /**
106
117
  * Abandon the running helper, if any.
107
118
  *
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "dsh-agent-sdk-bridge",
3
3
  "displayName": "Agent SDK Bridge",
4
4
  "description": "DeepSeek Harness LLM adapter bridge for Qoder CN, Qoder International, Tencent CodeBuddy and MiniMax Code subscriptions. It reuses each provider's own SDK or official ACP server and CLI login, shows available quota, and exposes per-provider settings pages with independent international and mainland login regions.",
5
- "version": "1.3.0",
5
+ "version": "1.3.3",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "author": "k1-h2",
@@ -79,17 +79,24 @@ if defined CLIV (
79
79
  echo [--] qodercli not found
80
80
  )
81
81
 
82
- rem The SDK speaks a wire protocol that is pinned to one CLI release. CLI
83
- rem 1.1.81 dropped the old SDK session handshake and exits 42 on it, which the
84
- rem settings page could only report as "process exited with code 42". Reading
85
- rem the requirement from the installed SDK keeps this helper on a version the
86
- rem plugin can actually talk to, instead of whatever latest happens to be.
82
+ rem The SDK speaks a wire protocol pinned to one CLI release, and only a build
83
+ rem OLDER than that pin is a problem: CLI 1.1.81 dropped the old SDK session
84
+ rem handshake and exits 42 on it. A newer build that still speaks the protocol
85
+ rem is fine (1.1.84 runs against the SDK pinned at 1.1.81), and the CLI updates
86
+ rem itself, so this helper installs the pinned build only when what is present
87
+ rem is older. It never downgrades a version the user has moved forward.
87
88
  set "WANTV="
88
89
  set "MANIFEST=%~dp0..\node_modules\@qoder-ai\qoder-agent-sdk\dist\runtime-manifest.json"
89
90
  if exist "%MANIFEST%" for /f "usebackq delims=" %%V in (`node -e "try{process.stdout.write(require(process.argv[1]).qoderCliVersion||'')}catch(e){}" "%MANIFEST%"`) do set "WANTV=%%V"
90
91
  set "PKGSPEC=%PKG%"
91
92
  if defined WANTV set "PKGSPEC=%PKG%@%WANTV%"
92
- if defined WANTV echo [--] this plugin needs CLI !WANTV!
93
+ if defined WANTV echo [--] this plugin was tested with CLI !WANTV!
94
+
95
+ rem OUTDATED=1 only when a required version exists and the installed one is
96
+ rem numerically older. `node -e` does the comparing because cmd compares
97
+ rem strings, where "1.1.9" ranks above "1.1.10".
98
+ set "OUTDATED="
99
+ if defined WANTV if defined CLIV for /f "usebackq delims=" %%R in (`node -e "const a=process.argv[1].split('.').map(Number),b=process.argv[2].split('.').map(Number);let r=0;for(let i=0;i<Math.max(a.length,b.length);i++){const d=(a[i]||0)-(b[i]||0);if(d){r=d^<0?-1:1;break}}process.stdout.write(r^<0?'1':'')" "!CLIV!" "!WANTV!"`) do set "OUTDATED=%%R"
93
100
 
94
101
  rem ------------------------------------------------------------- 3 install
95
102
  echo.
@@ -100,8 +107,8 @@ if not "%MODE%"=="setup" (
100
107
  echo Run this script without an argument to install it.
101
108
  goto :fail
102
109
  )
103
- if defined WANTV if not "!CLIV!"=="!WANTV!" (
104
- echo [X] installed !CLIV!, but this plugin needs !WANTV!.
110
+ if defined OUTDATED (
111
+ echo [X] installed !CLIV!, but this plugin needs !WANTV! or newer.
105
112
  echo Run this script without an argument to install it.
106
113
  goto :fail
107
114
  )
@@ -109,9 +116,8 @@ if not "%MODE%"=="setup" (
109
116
  goto :login
110
117
  )
111
118
  if defined QCMD (
112
- if not defined WANTV goto :skipinstall
113
- if "!CLIV!"=="!WANTV!" goto :skipinstall
114
- echo [--] installed !CLIV!, this plugin needs !WANTV! - reinstalling
119
+ if not defined OUTDATED goto :skipinstall
120
+ echo [--] installed !CLIV! is older than !WANTV! - reinstalling
115
121
  goto :doinstall
116
122
  )
117
123
  :skipinstall
@@ -79,17 +79,24 @@ if defined CLIV (
79
79
  echo [--] qoderclicn not found
80
80
  )
81
81
 
82
- rem The SDK speaks a wire protocol that is pinned to one CLI release. CLI
83
- rem 1.1.81 dropped the old SDK session handshake and exits 42 on it, which the
84
- rem settings page could only report as "process exited with code 42". Reading
85
- rem the requirement from the installed SDK keeps this helper on a version the
86
- rem plugin can actually talk to, instead of whatever latest happens to be.
82
+ rem The SDK speaks a wire protocol pinned to one CLI release, and only a build
83
+ rem OLDER than that pin is a problem: CLI 1.1.81 dropped the old SDK session
84
+ rem handshake and exits 42 on it. A newer build that still speaks the protocol
85
+ rem is fine (1.1.84 runs against the SDK pinned at 1.1.81), and the CLI updates
86
+ rem itself, so this helper installs the pinned build only when what is present
87
+ rem is older. It never downgrades a version the user has moved forward.
87
88
  set "WANTV="
88
89
  set "MANIFEST=%~dp0..\node_modules\@qodercn-ai\qodercn-agent-sdk\dist\runtime-manifest.json"
89
90
  if exist "%MANIFEST%" for /f "usebackq delims=" %%V in (`node -e "try{process.stdout.write(require(process.argv[1]).qoderCliVersion||'')}catch(e){}" "%MANIFEST%"`) do set "WANTV=%%V"
90
91
  set "PKGSPEC=%PKG%"
91
92
  if defined WANTV set "PKGSPEC=%PKG%@%WANTV%"
92
- if defined WANTV echo [--] this plugin needs CLI !WANTV!
93
+ if defined WANTV echo [--] this plugin was tested with CLI !WANTV!
94
+
95
+ rem OUTDATED=1 only when a required version exists and the installed one is
96
+ rem numerically older. `node -e` does the comparing because cmd compares
97
+ rem strings, where "1.1.9" ranks above "1.1.10".
98
+ set "OUTDATED="
99
+ if defined WANTV if defined CLIV for /f "usebackq delims=" %%R in (`node -e "const a=process.argv[1].split('.').map(Number),b=process.argv[2].split('.').map(Number);let r=0;for(let i=0;i<Math.max(a.length,b.length);i++){const d=(a[i]||0)-(b[i]||0);if(d){r=d^<0?-1:1;break}}process.stdout.write(r^<0?'1':'')" "!CLIV!" "!WANTV!"`) do set "OUTDATED=%%R"
93
100
 
94
101
  rem ------------------------------------------------------------- 3 install
95
102
  echo.
@@ -100,8 +107,8 @@ if not "%MODE%"=="setup" (
100
107
  echo Run this script without an argument to install it.
101
108
  goto :fail
102
109
  )
103
- if defined WANTV if not "!CLIV!"=="!WANTV!" (
104
- echo [X] installed !CLIV!, but this plugin needs !WANTV!.
110
+ if defined OUTDATED (
111
+ echo [X] installed !CLIV!, but this plugin needs !WANTV! or newer.
105
112
  echo Run this script without an argument to install it.
106
113
  goto :fail
107
114
  )
@@ -109,9 +116,8 @@ if not "%MODE%"=="setup" (
109
116
  goto :login
110
117
  )
111
118
  if defined QCMD (
112
- if not defined WANTV goto :skipinstall
113
- if "!CLIV!"=="!WANTV!" goto :skipinstall
114
- echo [--] installed !CLIV!, this plugin needs !WANTV! - reinstalling
119
+ if not defined OUTDATED goto :skipinstall
120
+ echo [--] installed !CLIV! is older than !WANTV! - reinstalling
115
121
  goto :doinstall
116
122
  )
117
123
  :skipinstall
@@ -23,7 +23,8 @@ import type { ImageRequestReader } from './adapter.ts'
23
23
  import type { Live } from './live.ts'
24
24
  import { readLive, readLiveOptional } from './live.ts'
25
25
  import type { Feed, ImagePathResolver } from './render.ts'
26
- import { feedImageRefs, feedToText, imageRefText, renderInitialFeed, renderSideChannelFeed, resolvedFeedParts } from './render.ts'
26
+ import type { ImageAttachmentRef } from '@deepseek-ai/dsh-attachment'
27
+ import { feedImageRefs, feedToText, imageRefText, imageRefs, renderInitialFeed, renderSideChannelFeed, resolvedFeedParts } from './render.ts'
27
28
  import type { ChannelContent } from './session.ts'
28
29
 
29
30
  /** The CodeBuddy provider route. */
@@ -223,11 +224,35 @@ export class CodeBuddyAdapter extends LlmAdapter {
223
224
  feed: Feed,
224
225
  vision: boolean,
225
226
  signal?: AbortSignal,
227
+ ): Promise<ReadonlyMap<string, { data: string, mediaType: string }>> {
228
+ return await this.resolveImages(feedImageRefs(feed), vision, signal)
229
+ }
230
+
231
+ /**
232
+ * Images carried by the messages the inner session has not seen yet.
233
+ *
234
+ * Tool results are included: `read_image` hands its pixels back through the
235
+ * MCP tool result, not through the prompt text, so this tail is the only
236
+ * place the bytes can come from.
237
+ */
238
+ private async resolveTurnImages(
239
+ tail: readonly RequestMessage[],
240
+ vision: boolean,
241
+ signal?: AbortSignal,
242
+ ): Promise<ReadonlyMap<string, { data: string, mediaType: string }>> {
243
+ const refs = tail.flatMap(message => message.role === 'assistant' ? [] : imageRefs(message.content))
244
+ return await this.resolveImages(refs, vision, signal)
245
+ }
246
+
247
+ private async resolveImages(
248
+ refs: readonly ImageAttachmentRef[],
249
+ vision: boolean,
250
+ signal?: AbortSignal,
226
251
  ): Promise<ReadonlyMap<string, { data: string, mediaType: string }>> {
227
252
  const map = new Map<string, { data: string, mediaType: string }>()
228
253
  const readImage = this.options.readImage
229
254
  if (!vision || readImage === undefined) return map
230
- for (const ref of feedImageRefs(feed)) {
255
+ for (const ref of refs) {
231
256
  const key = String(ref.attachmentId)
232
257
  if (map.has(key)) continue
233
258
  try {
@@ -390,7 +415,12 @@ export class CodeBuddyAdapter extends LlmAdapter {
390
415
  return
391
416
  }
392
417
  const tail = options.messages.slice(session.fedMessages.length)
393
- session.deliverToolResults(tail)
418
+ // Resolve images before the tool results are delivered: a tool result can
419
+ // carry pixels (`read_image`), and the MCP result is the only channel that
420
+ // reaches the inner model for this turn.
421
+ const vision = await this.modelVision(options.model)
422
+ const images = await this.resolveTurnImages(tail, vision, options.signal)
423
+ session.deliverToolResults(tail, images)
394
424
  const plan = planContinuation(session.fedMessages, options.messages)
395
425
  if (plan.rebuild) {
396
426
  this.sessions.dispose(sessionId)
@@ -404,7 +434,6 @@ export class CodeBuddyAdapter extends LlmAdapter {
404
434
  session.ensureTools(options.tools ?? [])
405
435
  session.fedMessages = options.messages
406
436
  session.fedSystem = options.system
407
- const vision = await this.modelVision(options.model)
408
437
  const feed = plan.feed === null
409
438
  ? null
410
439
  : await this.buildFeed(plan.feed, vision, options.signal)
package/src/codebuddy.ts CHANGED
@@ -13,7 +13,8 @@
13
13
  */
14
14
 
15
15
  import { randomBytes, randomUUID } from 'node:crypto'
16
- import { EMPTY_RESPONSE_CODE, ToolCallId } from '@deepseek-ai/dsh-llm'
16
+ import type { ImageAttachmentRef } from '@deepseek-ai/dsh-attachment'
17
+ import { EMPTY_RESPONSE_CODE, ToolCallId, textOnlyImageText } from '@deepseek-ai/dsh-llm'
17
18
  import type {
18
19
  FinishReason, GenerateOptions, StreamChunk, TokenUsage,
19
20
  } from '@deepseek-ai/dsh-llm'
@@ -59,7 +60,7 @@ function toCodeBuddyUserMessage(
59
60
  }
60
61
  }
61
62
  import { MCP_SERVER_NAME, HostToolRegistry, ToolResultPairing, TurnQueue } from './session.ts'
62
- import type { ChannelContent, ToolResultPayload, ToolRegistryHost } from './session.ts'
63
+ import type { ChannelContent, ResolvedImages, ToolResultPayload, ToolRegistryHost } from './session.ts'
63
64
  import { TurnOutputAccounting, estimateTextTokens } from './tokens.ts'
64
65
 
65
66
  /** Default context capacity assumed for a CodeBuddy model that declares none. */
@@ -78,17 +79,34 @@ const LOGOUT_TIMEOUT_MS = 20_000
78
79
  /** The session object the SDK's createSession returns (not a named export). */
79
80
  type SessionImpl = ReturnType<typeof import('@tencent-ai/agent-sdk').unstable_v2_createSession>
80
81
 
81
- const MCP_TOOL_PREFIX = `mcp__${MCP_SERVER_NAME}__`
82
82
  /**
83
- * The same namespace after the CLI normalises the server name.
83
+ * The key this plugin's MCP server is registered under, in the CodeBuddy CLI.
84
84
  *
85
- * CodeBuddy rewrites every non-alphanumeric character in an MCP server name to
86
- * `_`, so a server registered as `dsh-host` is exposed to the model as
87
- * `mcp__dsh_host__<tool>`. Matching only the registered spelling rejected the
88
- * host's own tools as "built-ins", which is exactly why the model fell back to
89
- * `Bash`. The Qoder CLI keeps the hyphen, so both spellings are accepted.
85
+ * It is the CLI's own normalised spelling - `dsh_host`, not `dsh-host` - and
86
+ * that choice is the fix for the recurring "tool went missing": the CLI builds
87
+ * its call-time tool map from `mcp__<key>__<tool>` with the key verbatim,
88
+ * while several of its own code paths (`parseMcpToolName`, the plugin tool
89
+ * namer, the wire-format normaliser) rewrite every non-alphanumeric character
90
+ * to `_`. With a hyphenated key the list showed `mcp__dsh-host__read_files`
91
+ * while a model that emitted the normalised `mcp__dsh_host__read_files` - as
92
+ * one did, verbatim, in a failed session - found no entry, and the CLI refused
93
+ * the call with `Tool "..." does not exist in the current tool set.` before it
94
+ * ever reached this server. Registering under the normalised spelling makes
95
+ * list, lookup and normalisation one and the same name, so there is no second
96
+ * spelling to guess.
90
97
  */
91
- const MCP_TOOL_PREFIX_SANITIZED = `mcp__${MCP_SERVER_NAME.replace(/[^a-zA-Z0-9]/g, '_')}__`
98
+ const CODEBUDDY_MCP_SERVER_KEY = 'dsh_host'
99
+
100
+ const MCP_TOOL_PREFIX = `mcp__${CODEBUDDY_MCP_SERVER_KEY}__`
101
+ /**
102
+ * The hyphenated spelling, kept for names already in flight.
103
+ *
104
+ * The server used to be keyed `dsh-host`; older prefixes and doubled forms can
105
+ * still carry `mcp__dsh-host__<tool>`, and both spellings name the same
106
+ * server, so the matcher accepts them all. See {@link CODEBUDDY_MCP_SERVER_KEY}
107
+ * for why the registered key itself is now the normalised spelling.
108
+ */
109
+ const MCP_TOOL_PREFIX_SANITIZED = `mcp__${MCP_SERVER_NAME}__`
92
110
  /** Both spellings, in the order the shared stripper tries them. */
93
111
  const HOST_TOOL_PREFIXES = [MCP_TOOL_PREFIX, MCP_TOOL_PREFIX_SANITIZED]
94
112
 
@@ -1104,7 +1122,10 @@ export class CodeBuddySession {
1104
1122
  }
1105
1123
 
1106
1124
  /** Hand the host's tool results to parked or buffered handlers. */
1107
- deliverToolResults(tail: readonly { role: string, toolCallId?: unknown, content?: unknown, isError?: boolean }[]): void {
1125
+ deliverToolResults(
1126
+ tail: readonly { role: string, toolCallId?: unknown, content?: unknown, isError?: boolean }[],
1127
+ images?: ResolvedImages,
1128
+ ): void {
1108
1129
  let freshUserTurn = false
1109
1130
  const delivered = new Set<string>()
1110
1131
  for (const message of tail) {
@@ -1114,7 +1135,7 @@ export class CodeBuddySession {
1114
1135
  }
1115
1136
  if (message.role !== 'tool') continue
1116
1137
  delivered.add(this.pairing.deliver(String(message.toolCallId), {
1117
- content: renderCodeBuddyResult(message.content),
1138
+ content: renderCodeBuddyResult(message.content, images),
1118
1139
  isError: message.isError === true,
1119
1140
  }))
1120
1141
  }
@@ -1182,7 +1203,7 @@ export class CodeBuddySession {
1182
1203
  private async ensureStarted(): Promise<SessionImpl> {
1183
1204
  if (this.session !== null) return this.session
1184
1205
  const sdk = await loadCodeBuddySdk()
1185
- this.mcp ??= sdk.createSdkMcpServer({ name: MCP_SERVER_NAME, tools: [] })
1206
+ this.mcp ??= sdk.createSdkMcpServer({ name: CODEBUDDY_MCP_SERVER_KEY, tools: [] })
1186
1207
  // Host tools must exist in the MCP server before the CLI lists them. The
1187
1208
  // registry is created here, with the server it installs into, and the
1188
1209
  // replay below is what puts the first turn's schemas in place.
@@ -1210,7 +1231,7 @@ export class CodeBuddySession {
1210
1231
  environment: codeBuddyEnvironment(this.region),
1211
1232
  sessionId: randomUUID(),
1212
1233
  model: this.model,
1213
- mcpServers: { [MCP_SERVER_NAME]: this.mcp },
1234
+ mcpServers: { [CODEBUDDY_MCP_SERVER_KEY]: this.mcp },
1214
1235
  canUseTool: this.canUseTool as CanUseTool,
1215
1236
  // Only the host's MCP tools may run: the CLI's own Bash/Read/Edit have no
1216
1237
  // host-side counterpart, and the permission gate denies them anyway.
@@ -1493,12 +1514,21 @@ export class CodeBuddySession {
1493
1514
  }
1494
1515
 
1495
1516
  /** Render host tool-result blocks into the MCP content the inner model reads. */
1496
- function renderCodeBuddyResult(blocks: unknown): ToolResultPayload['content'] {
1517
+ export function renderCodeBuddyResult(blocks: unknown, images?: ResolvedImages): ToolResultPayload['content'] {
1497
1518
  if (!Array.isArray(blocks)) return [{ type: 'text', text: String(blocks ?? '') }]
1498
1519
  const content: ToolResultPayload['content'] = []
1499
1520
  for (const block of blocks as { type?: string, text?: string, attachment?: unknown }[]) {
1500
1521
  if (block.type === 'text') content.push({ type: 'text', text: block.text ?? '' })
1501
- else if (block.type === 'image') content.push({ type: 'text', text: '[图片结果未转发给 CodeBuddy]' })
1522
+ else if (block.type === 'image' && block.attachment !== null && typeof block.attachment === 'object') {
1523
+ // A tool can return pixels (`read_image` does). The MCP result shape
1524
+ // carries them as an image block; dropping them here was why the inner
1525
+ // model could read a path in the result text but never see the picture.
1526
+ const attachment = block.attachment as ImageAttachmentRef
1527
+ const resolved = images?.get(String(attachment.attachmentId))
1528
+ content.push(resolved === undefined
1529
+ ? { type: 'text', text: textOnlyImageText(attachment) }
1530
+ : { type: 'image', data: resolved.data, mimeType: resolved.mediaType })
1531
+ }
1502
1532
  else content.push({ type: 'text', text: JSON.stringify(block) })
1503
1533
  }
1504
1534
  return content
@@ -30,7 +30,8 @@ import type { ImageRequestReader } from './adapter.ts'
30
30
  import type { Live } from './live.ts'
31
31
  import { readLive, readLiveOptional } from './live.ts'
32
32
  import type { Feed, ImagePathResolver } from './render.ts'
33
- import { feedImageRefs, feedToText, imageRefText, renderInitialFeed, renderSideChannelFeed, resolvedFeedParts } from './render.ts'
33
+ import { feedImageRefs, feedToText, imageRefText, imageRefs, renderInitialFeed, renderSideChannelFeed, resolvedFeedParts } from './render.ts'
34
+ import type { ImageAttachmentRef } from '@deepseek-ai/dsh-attachment'
34
35
 
35
36
  /** The MiniMax Code provider route. */
36
37
  export const MINIMAX_PROVIDER = 'minimax-acp'
@@ -325,7 +326,12 @@ export class MinimaxAdapter extends LlmAdapter {
325
326
  return
326
327
  }
327
328
  const tail = options.messages.slice(session.fedMessages.length)
328
- session.deliverToolResults(tail)
329
+ // Resolve images before the tool results are delivered: a tool result can
330
+ // carry pixels (`read_image`), and this ACP tool result is the only channel
331
+ // that reaches the inner model for the round.
332
+ const vision = await this.modelVision(model, region)
333
+ const images = await this.resolveTurnImages(tail, vision, options.signal)
334
+ session.deliverToolResults(tail, images)
329
335
  const plan = planContinuation(session.fedMessages, options.messages)
330
336
  if (plan.rebuild) {
331
337
  this.sessions.dispose(sessionId)
@@ -358,7 +364,6 @@ export class MinimaxAdapter extends LlmAdapter {
358
364
  session.ensureTools(options.tools ?? [])
359
365
  session.fedMessages = options.messages
360
366
  session.fedSystem = options.system
361
- const vision = await this.modelVision(model, region)
362
367
  const feed = plan.feed === null
363
368
  ? null
364
369
  : await this.buildFeed(plan.feed, vision, options.signal)
@@ -418,22 +423,7 @@ export class MinimaxAdapter extends LlmAdapter {
418
423
  ): Promise<string | MinimaxPromptBlock[]> {
419
424
  if (typeof feed === 'string') return feed
420
425
  if (!vision) return feedToText(feed, this.options.imagePath)
421
- const images = new Map<string, { data: string, mediaType: string }>()
422
- const readImage = this.options.readImage
423
- if (readImage !== undefined) {
424
- for (const ref of feedImageRefs(feed)) {
425
- const key = String(ref.attachmentId)
426
- if (images.has(key)) continue
427
- try {
428
- const image = await readImage(ref, signal)
429
- if (image !== undefined) {
430
- images.set(key, { data: Buffer.from(image.bytes).toString('base64'), mediaType: image.mediaType })
431
- }
432
- } catch {
433
- // Degrade this attachment to its handle text.
434
- }
435
- }
436
- }
426
+ const images = await this.resolveImages(feedImageRefs(feed), vision, signal)
437
427
  const parts = resolvedFeedParts(feed, images)
438
428
  if (!parts.some(part => part.type !== 'text')) {
439
429
  return parts.map(part => part.type === 'text' ? part.text : '').join('\n\n')
@@ -460,6 +450,45 @@ export class MinimaxAdapter extends LlmAdapter {
460
450
  return content
461
451
  }
462
452
 
453
+ /**
454
+ * Images carried by the messages the inner session has not seen yet.
455
+ *
456
+ * Tool results are included: `read_image` hands its pixels back through the
457
+ * ACP tool result, not through the prompt text, so this tail is the only
458
+ * place the bytes can come from.
459
+ */
460
+ private async resolveTurnImages(
461
+ tail: readonly RequestMessage[],
462
+ vision: boolean,
463
+ signal?: AbortSignal,
464
+ ): Promise<ReadonlyMap<string, { data: string, mediaType: string }>> {
465
+ const refs = tail.flatMap(message => message.role === 'assistant' ? [] : imageRefs(message.content))
466
+ return await this.resolveImages(refs, vision, signal)
467
+ }
468
+
469
+ private async resolveImages(
470
+ refs: readonly ImageAttachmentRef[],
471
+ vision: boolean,
472
+ signal?: AbortSignal,
473
+ ): Promise<ReadonlyMap<string, { data: string, mediaType: string }>> {
474
+ const map = new Map<string, { data: string, mediaType: string }>()
475
+ const readImage = this.options.readImage
476
+ if (!vision || readImage === undefined) return map
477
+ for (const ref of refs) {
478
+ const key = String(ref.attachmentId)
479
+ if (map.has(key)) continue
480
+ try {
481
+ const image = await readImage(ref, signal)
482
+ if (image !== undefined) {
483
+ map.set(key, { data: Buffer.from(image.bytes).toString('base64'), mediaType: image.mediaType })
484
+ }
485
+ } catch {
486
+ // Degrade this attachment to its handle text.
487
+ }
488
+ }
489
+ return map
490
+ }
491
+
463
492
  private cwdOf(options: GenerateOptions): string | undefined {
464
493
  return (options as GenerateOptions & { cwd?: string }).cwd
465
494
  }
package/src/minimax.ts CHANGED
@@ -32,12 +32,13 @@ import { Readable, Writable } from 'node:stream'
32
32
  import {
33
33
  ClientSideConnection, ndJsonStream, PROTOCOL_VERSION,
34
34
  } from '@agentclientprotocol/sdk'
35
- import { EMPTY_RESPONSE_CODE, ToolCallId } from '@deepseek-ai/dsh-llm'
35
+ import { EMPTY_RESPONSE_CODE, ToolCallId, textOnlyImageText } from '@deepseek-ai/dsh-llm'
36
36
  import type {
37
37
  FinishReason, GenerateOptions, RequestMessage, StreamChunk, TokenUsage,
38
38
  } from '@deepseek-ai/dsh-llm'
39
- import type { MinimaxRegion } from './brand.ts'
39
+ import type { ImageAttachmentRef } from '@deepseek-ai/dsh-attachment'
40
40
  import { minimaxCliRegion } from './brand.ts'
41
+ import type { MinimaxRegion } from './brand.ts'
41
42
  import type { Live } from './live.ts'
42
43
  import { readLive } from './live.ts'
43
44
  import { stripMcpNamespace } from './mcp-naming.ts'
@@ -74,7 +75,7 @@ export interface MinimaxModel {
74
75
 
75
76
  /** One tool call's result, in the shape the MCP bridge returns. */
76
77
  export interface MinimaxMcpToolResult {
77
- content: { type: 'text', text: string }[]
78
+ content: ({ type: 'text', text: string } | { type: 'image', data: string, mimeType: string })[]
78
79
  isError?: boolean
79
80
  }
80
81
 
@@ -1124,8 +1125,18 @@ interface PendingHostCall {
1124
1125
  timer: NodeJS.Timeout
1125
1126
  }
1126
1127
 
1127
- /** Render a harness tool result for the MCP caller. */
1128
- function renderToolResult(content: unknown): MinimaxMcpToolResult {
1128
+ /**
1129
+ * Render a harness tool result for the MCP caller.
1130
+ *
1131
+ * A tool result can carry pixels (`read_image` returns the picture beside its
1132
+ * path envelope). The MCP result schema passes an image block straight to the
1133
+ * agent, so a resolvable attachment becomes `{type:'image'}`; one the host
1134
+ * could not read falls back to the harness handle text instead of vanishing.
1135
+ */
1136
+ export function renderToolResult(
1137
+ content: unknown,
1138
+ images?: ReadonlyMap<string, { data: string, mediaType: string }>,
1139
+ ): MinimaxMcpToolResult {
1129
1140
  const text = (value: unknown): string => {
1130
1141
  if (typeof value === 'string') return value
1131
1142
  if (value === null || value === undefined) return ''
@@ -1136,20 +1147,39 @@ function renderToolResult(content: unknown): MinimaxMcpToolResult {
1136
1147
  }
1137
1148
  }
1138
1149
  if (Array.isArray(content)) {
1139
- const parts: string[] = []
1150
+ const parts: MinimaxMcpToolResult['content'] = []
1151
+ let pending: string[] = []
1152
+ const flush = (): void => {
1153
+ if (pending.length === 0) return
1154
+ parts.push({ type: 'text', text: pending.join('\n') })
1155
+ pending = []
1156
+ }
1140
1157
  for (const block of content) {
1141
1158
  if (typeof block === 'string') {
1142
- parts.push(block)
1159
+ pending.push(block)
1143
1160
  continue
1144
1161
  }
1145
- if (block !== null && typeof block === 'object' && (block as { type?: unknown }).type === 'text') {
1146
- parts.push(text((block as { text?: unknown }).text))
1147
- continue
1162
+ if (block !== null && typeof block === 'object') {
1163
+ const typed = block as { type?: unknown, text?: unknown, attachment?: unknown }
1164
+ if (typed.type === 'text') {
1165
+ pending.push(text(typed.text))
1166
+ continue
1167
+ }
1168
+ if (typed.type === 'image' && typed.attachment !== null && typeof typed.attachment === 'object') {
1169
+ const attachment = typed.attachment as ImageAttachmentRef
1170
+ const resolved = images?.get(String(attachment.attachmentId))
1171
+ flush()
1172
+ parts.push(resolved === undefined
1173
+ ? { type: 'text', text: textOnlyImageText(attachment) }
1174
+ : { type: 'image', data: resolved.data, mimeType: resolved.mediaType })
1175
+ continue
1176
+ }
1148
1177
  }
1149
- parts.push(text(block))
1178
+ pending.push(text(block))
1150
1179
  }
1151
- const joined = parts.join('\n').trim()
1152
- return { content: [{ type: 'text', text: joined === '' ? '(宿主工具没有返回内容)' : joined }] }
1180
+ flush()
1181
+ if (parts.length === 0) return { content: [{ type: 'text', text: '(宿主工具没有返回内容)' }] }
1182
+ return { content: parts }
1153
1183
  }
1154
1184
  const joined = text(content).trim()
1155
1185
  return { content: [{ type: 'text', text: joined === '' ? '(宿主工具没有返回内容)' : joined }] }
@@ -1928,7 +1958,10 @@ export class MinimaxSession {
1928
1958
  }
1929
1959
 
1930
1960
  /** Hand the host's tool results to parked handlers. */
1931
- deliverToolResults(tail: readonly { role: string, toolCallId?: unknown, content?: unknown, isError?: boolean }[]): void {
1961
+ deliverToolResults(
1962
+ tail: readonly { role: string, toolCallId?: unknown, content?: unknown, isError?: boolean }[],
1963
+ images?: ReadonlyMap<string, { data: string, mediaType: string }>,
1964
+ ): void {
1932
1965
  let freshUserTurn = false
1933
1966
  for (const message of tail) {
1934
1967
  if (message.role === 'user') {
@@ -1942,7 +1975,7 @@ export class MinimaxSession {
1942
1975
  clearTimeout(pending.timer)
1943
1976
  this.pending.delete(callId)
1944
1977
  pending.resolve({
1945
- ...renderToolResult(message.content),
1978
+ ...renderToolResult(message.content, images),
1946
1979
  ...message.isError === true ? { isError: true } : {},
1947
1980
  })
1948
1981
  }
package/src/setup.ts CHANGED
@@ -244,11 +244,21 @@ export function readSetupStatus(brand: QoderBrand = 'cn'): SetupStatus {
244
244
  installed,
245
245
  ...cliVersion === undefined ? {} : { cliVersion },
246
246
  ...required === undefined ? {} : { requiredCliVersion: required },
247
- // Unknown on either side is not a mismatch: a native build carries no
248
- // manifest, and warning about a version nobody could read would be noise.
247
+ // Only an OLDER CLI is a problem. The SDK pins the build it was tested
248
+ // against, but the CLI is a separate package the user (or its own `update`
249
+ // command) may move ahead of that pin, and a newer build that still speaks
250
+ // the protocol works fine — verified: SDK 1.0.58 (pinned 1.1.81) runs
251
+ // catalog reads, quota and full turns on CLI 1.1.84. Warning on "not equal"
252
+ // turned a normal update into a standing error, and the bundled helper then
253
+ // pulled the CLI back down, which is the opposite of following upstream.
254
+ //
255
+ // Below the pin is the real failure mode: CLI 1.1.81 removed the
256
+ // worker-session handshake that older SDKs spoke, so every query dies with
257
+ // exit code 42 (`sdk_worker_removed`). Unknown on either side stays quiet —
258
+ // a native build carries no manifest.
249
259
  ...cliVersion === undefined || required === undefined
250
260
  ? {}
251
- : { versionMismatch: cliVersion !== required },
261
+ : { versionMismatch: compareVersions(cliVersion, required) < 0 },
252
262
  }
253
263
  const run = current.get(brand)
254
264
  if (run === undefined) return { running: false, lines: [], truncated: false, ...build }
@@ -296,6 +306,31 @@ export function cancelSetup(brand: QoderBrand): boolean {
296
306
  return true
297
307
  }
298
308
 
309
+ /**
310
+ * Compare two dotted versions, numerically per segment.
311
+ *
312
+ * A plain string compare would rank `1.1.9` above `1.1.10`, which is exactly
313
+ * backwards for the decision this feeds.
314
+ *
315
+ * @param left - one version, e.g. `1.1.84`.
316
+ * @param right - the other, e.g. `1.1.81`.
317
+ * @returns negative when `left` is older, positive when newer, 0 when equal.
318
+ */
319
+ export function compareVersions(left: string, right: string): number {
320
+ const parse = (value: string): number[] =>
321
+ value.split(/[.-]/).map(part => {
322
+ const n = Number.parseInt(part, 10)
323
+ return Number.isFinite(n) ? n : 0
324
+ })
325
+ const a = parse(left)
326
+ const b = parse(right)
327
+ for (let i = 0; i < Math.max(a.length, b.length); i += 1) {
328
+ const diff = (a[i] ?? 0) - (b[i] ?? 0)
329
+ if (diff !== 0) return diff < 0 ? -1 : 1
330
+ }
331
+ return 0
332
+ }
333
+
299
334
  /**
300
335
  * Abandon the running helper, if any.
301
336
  *