aai-lark-bridge 0.1.7 → 0.1.8

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/dist/cli.js CHANGED
@@ -4,7 +4,7 @@ import { Command } from "commander";
4
4
  // package.json
5
5
  var package_default = {
6
6
  name: "aai-lark-bridge",
7
- version: "0.1.7",
7
+ version: "0.1.8",
8
8
  description: "Lark AI Native Bridge - Lark\u57FA\u7840\u8BBE\u65BD\u5C42\u548CCLI\u96C6\u6210",
9
9
  type: "module",
10
10
  main: "./dist/index.js",
@@ -6064,6 +6064,8 @@ bridge \u4F1A\u7ED9\u4F60\u7684\u5B50\u8FDB\u7A0B\u6CE8\u5165\u5F53\u524D\u8FD0\
6064
6064
 
6065
6065
  ## \u6545\u969C\u8BCA\u65AD\u4E0E\u5B8C\u6210\u72B6\u6001
6066
6066
 
6067
+ - \u7528\u6237\u4ECE\u98DE\u4E66\u9605\u8BFB\u7B54\u590D\uFF0C\u65E0\u6CD5\u6253\u5F00\u672C\u673A\u7EDD\u5BF9\u8DEF\u5F84\u3001file:// \u6216\u672C\u673A\u7F16\u8F91\u5668\u94FE\u63A5\u3002\u4EE3\u7801\u4EA4\u4ED8\u63D0\u4F9B\u5DF2\u521B\u5EFA\u5E76\u6838\u5B9E\u7684 MR URL\uFF1B\u9700\u8981\u4EA4\u4ED8\u6587\u4EF6\u65F6\u6309\u4EFB\u52A1\u6388\u6743\u4E0A\u4F20\u5230\u98DE\u4E66\u5E76\u6838\u9A8C\u8FD4\u56DE\u94FE\u63A5\u6216\u9644\u4EF6\u3002\u53EA\u5199\u5165\u672C\u673A\u65F6\u660E\u786E\u201C\u4EC5\u4FDD\u5B58\u5728\u672C\u673A\uFF0C\u5C1A\u672A\u4E0A\u4F20\u201D\uFF0C\u53EF\u7528\u7EAF\u6587\u672C\u8DEF\u5F84\u4F9B\u5B9A\u4F4D\uFF0C\u4F46\u4E0D\u80FD\u5305\u88C5\u6210\u5DF2\u4EA4\u4ED8\u7684\u53EF\u70B9\u51FB\u94FE\u63A5\u3002\u51C6\u5907\u597D MR \u63CF\u8FF0\u4E0D\u7B49\u4E8E\u5DF2\u63D0\u4EA4 MR\u3002
6068
+ - \u8FDB\u5EA6\u7528\u7B80\u77ED\u52A8\u4F5C\u548C\u5B9E\u9645\u7ED3\u679C\u8BF4\u660E\uFF1B\u4E0D\u8981\u590D\u5236\u539F\u59CB shell \u547D\u4EE4\u3001\u73AF\u5883\u53D8\u91CF\u6216\u5DE5\u5177\u8F93\u51FA\u5230\u7528\u6237\u8FDB\u5EA6\u3002\u9700\u8981\u6392\u969C\u7EC6\u8282\u65F6\u53EA\u5C55\u793A\u4E0E\u95EE\u9898\u6709\u5173\u4E14\u5DF2\u8131\u654F\u7684\u5185\u5BB9\u3002
6067
6069
  - \u5206\u5F00\u62A5\u544A\u672C\u5730\u63D0\u4EA4\u3001\u8FDC\u7AEF\u63A8\u9001\u3001MR \u521B\u5EFA\u3001\u5408\u5E76\u3001\u53D1\u5E03\u3001\u5B89\u88C5\u3001\u91CD\u542F\u3001\u771F\u5B9E\u4E1A\u52A1\u9A8C\u6536\u3002\u6BCF\u4E00\u9879\u53EA\u6309\u672C\u8F6E\u53EF\u6838\u67E5\u8BC1\u636E\u786E\u8BA4\uFF1B\u8FDB\u7A0B\u5728\u7EBF\u6216\u6D4B\u8BD5\u901A\u8FC7\u4E0D\u80FD\u66FF\u4EE3\u7528\u6237\u8981\u6C42\u7684\u4EA4\u4ED8\u7269\u3002
6068
6070
  - \u7F51\u7EDC\u6216\u6743\u9650\u4E0D\u8DB3\u65F6\u8BF4\u201C\u65E0\u6CD5\u6838\u5B9E\u201D\uFF0C\u4E0D\u8981\u4ECE\u672C\u5730\u63A8\u9001\u5931\u8D25\u3001\u65E7\u5206\u652F\u6216\u65E7\u56DE\u7B54\u63A8\u65AD\u8FDC\u7AEF MR \u4E0D\u5B58\u5728\u3002\u8DE8\u65E5\u6216\u957F\u65F6\u95F4\u7EED\u804A\u5148\u6838\u5BF9\u5F53\u524D\u65F6\u95F4\u3002
6069
6071
  - \u591A\u6B21\u5931\u8D25\u8981\u9010\u6B21\u6838\u5BF9 scope\u3001\u6062\u590D\u7684\u4F1A\u8BDD\u3001\u8FD0\u884C\u7248\u672C\u548C\u9519\u8BEF\u53D1\u751F\u9636\u6BB5\u3002\u666E\u901A\u79C1\u804A\u7684 topicContext=0\uFF0C\u4E0D\u80FD\u7528\u8BDD\u9898\u91CD\u590D\u6CE8\u5165\u89E3\u91CA\uFF1B\u6267\u884C\u8FC7\u5DE5\u5177\u540E\u624D\u62D2\u7EDD\uFF0C\u4E5F\u4E0D\u80FD\u8BF4\u6210\u6240\u6709\u8BF7\u6C42\u90FD\u5728\u4F1A\u8BDD\u5EFA\u7ACB\u524D\u5931\u8D25\u3002
@@ -6180,11 +6182,14 @@ function* translateEvent(raw) {
6180
6182
  return;
6181
6183
  }
6182
6184
  if (evt.is_error === true) {
6183
- const apiError = evt.terminal_reason === "api_error";
6185
+ const message = errorMessage2(evt);
6186
+ const authError = isAuthFailure(message);
6187
+ const apiError = !authError && evt.terminal_reason === "api_error";
6184
6188
  yield {
6185
6189
  type: "error",
6186
- message: errorMessage2(evt),
6190
+ message,
6187
6191
  terminationReason: "failed",
6192
+ ...authError ? { authError: true } : {},
6188
6193
  ...apiError ? { apiError: true } : {}
6189
6194
  };
6190
6195
  return;
@@ -6192,6 +6197,10 @@ function* translateEvent(raw) {
6192
6197
  yield { type: "done", sessionId: evt.session_id, terminationReason: "normal" };
6193
6198
  }
6194
6199
  }
6200
+ var AUTH_FAILURE = /failed to authenticate|login expired|not logged in|invalid api key|re-authenticate/i;
6201
+ function isAuthFailure(message) {
6202
+ return AUTH_FAILURE.test(message);
6203
+ }
6195
6204
  function errorMessage2(evt) {
6196
6205
  const text = typeof evt.result === "string" ? evt.result.trim() : "";
6197
6206
  if (text) return text;
@@ -8066,123 +8075,41 @@ function deepMaskEmails(value) {
8066
8075
  }
8067
8076
 
8068
8077
  // src/bridge/card/tool-render.ts
8069
- var HEADER_SUMMARY_MAX = 80;
8070
- var BODY_FIELD_MAX = 600;
8071
- var OUTPUT_MAX = 1200;
8072
- var BODY_TOTAL_MAX = 2500;
8073
- function toolHeaderText(tool) {
8074
- const icon = tool.status === "done" ? "\u2705" : tool.status === "error" ? "\u274C" : "\u23F3";
8075
- const summary = summarizeInput(tool.name, tool.input);
8076
- return summary ? `${icon} **${tool.name}** \u2014 ${summary}` : `${icon} **${tool.name}**`;
8077
- }
8078
- function toolBodyMd(tool) {
8079
- const parts = [];
8080
- const inputMd = renderInput(tool);
8081
- if (inputMd) parts.push(inputMd);
8082
- if (tool.output) {
8083
- const truncated = truncate2(tool.output, OUTPUT_MAX);
8084
- if (tool.status === "error") {
8085
- parts.push(`**Error**
8086
- \`\`\`
8087
- ${truncated}
8088
- \`\`\``);
8089
- } else if (tool.name === "Bash") {
8090
- parts.push(renderBashOutput(truncated));
8091
- } else {
8092
- parts.push(`**Output**
8093
- \`\`\`
8094
- ${truncated}
8095
- \`\`\``);
8096
- }
8097
- } else if (tool.status === "running") {
8098
- parts.push("_\u8FD0\u884C\u4E2D\u2026_");
8099
- }
8100
- const body = parts.join("\n\n");
8101
- if (body.length <= BODY_TOTAL_MAX) return body;
8102
- return `${body.slice(0, BODY_TOTAL_MAX)}\u2026
8103
-
8104
- _\uFF08body \u5DF2\u622A\u65AD,\u5B8C\u6574\u5185\u5BB9\u67E5 \`/doctor\` \u6216\u65E5\u5FD7\uFF09_`;
8105
- }
8106
- function summarizeInput(name, input) {
8107
- if (!input || typeof input !== "object") return "";
8108
- const rec = input;
8109
- const pick = (key, max = HEADER_SUMMARY_MAX) => {
8110
- const v = rec[key];
8111
- if (typeof v !== "string") return "";
8112
- const oneLine = v.replace(/\s+/g, " ").trim();
8113
- return oneLine.length > max ? `${oneLine.slice(0, max)}\u2026` : oneLine;
8114
- };
8078
+ function actionLabel(name) {
8115
8079
  switch (name) {
8116
8080
  case "Bash":
8117
- return pick("command");
8081
+ case "command_execution":
8082
+ case "exec_command":
8083
+ return "\u6267\u884C\u547D\u4EE4";
8118
8084
  case "Read":
8085
+ return "\u8BFB\u53D6\u6587\u4EF6";
8119
8086
  case "Edit":
8120
8087
  case "Write":
8121
8088
  case "NotebookEdit":
8122
- return shortenPath(pick("file_path"));
8123
- case "Grep": {
8124
- const pat = pick("pattern", 40);
8125
- const path = pick("path", 30);
8126
- return path ? `${pat} in ${shortenPath(path)}` : pat;
8127
- }
8089
+ case "apply_patch":
8090
+ return "\u4FEE\u6539\u6587\u4EF6";
8091
+ case "Grep":
8128
8092
  case "Glob":
8129
- return pick("pattern");
8093
+ return "\u641C\u7D22\u6587\u4EF6";
8130
8094
  case "WebFetch":
8131
- return pick("url");
8132
8095
  case "WebSearch":
8133
- return pick("query", 60);
8096
+ return "\u67E5\u8BE2\u7F51\u9875";
8134
8097
  case "Agent":
8135
8098
  case "Task":
8136
- return pick("description") || pick("subagent_type");
8099
+ return "\u6267\u884C\u5B50\u4EFB\u52A1";
8137
8100
  default:
8138
- return pick("command") || pick("file_path") || pick("path") || pick("query");
8139
- }
8140
- }
8141
- function renderInput(tool) {
8142
- const input = tool.input;
8143
- if (!input || typeof input !== "object") return "";
8144
- const rec = input;
8145
- const str2 = (k) => typeof rec[k] === "string" ? rec[k] : "";
8146
- switch (tool.name) {
8147
- case "Bash": {
8148
- const cmd = str2("command");
8149
- return cmd ? `**Command**
8150
- \`\`\`bash
8151
- ${truncate2(cmd, BODY_FIELD_MAX)}
8152
- \`\`\`` : "";
8153
- }
8154
- case "Read":
8155
- case "Edit":
8156
- case "Write":
8157
- case "NotebookEdit": {
8158
- const fp = str2("file_path");
8159
- return fp ? `**File** \`${fp}\`` : "";
8160
- }
8161
- case "Grep": {
8162
- const lines = [];
8163
- if (str2("pattern")) lines.push(`**Pattern** \`${str2("pattern")}\``);
8164
- if (str2("path")) lines.push(`**Path** \`${str2("path")}\``);
8165
- return lines.join("\n");
8166
- }
8167
- case "WebFetch":
8168
- return str2("url") ? `**URL** ${str2("url")}` : "";
8169
- case "WebSearch":
8170
- return str2("query") ? `**Query** \`${truncate2(str2("query"), BODY_FIELD_MAX)}\`` : "";
8171
- default:
8172
- return "";
8101
+ return "\u8C03\u7528\u5DE5\u5177";
8173
8102
  }
8174
8103
  }
8175
- function renderBashOutput(out) {
8176
- return `**Output**
8177
- \`\`\`
8178
- ${out}
8179
- \`\`\``;
8104
+ function toolHeaderText(tool, finalized = false) {
8105
+ const icon = tool.status === "done" ? "\u2705" : tool.status === "error" ? "\u274C" : finalized ? "\u26AA" : "\u23F3";
8106
+ const suffix = finalized && tool.status === "running" ? "\uFF08\u5DF2\u7ED3\u675F\uFF0C\u672A\u6536\u5230\u7ED3\u679C\uFF09" : "";
8107
+ return `${icon} **${actionLabel(tool.name)}**${suffix}`;
8180
8108
  }
8181
- function shortenPath(p3) {
8182
- return p3;
8183
- }
8184
- function truncate2(s, max) {
8185
- return s.length > max ? `${s.slice(0, max)}\u2026` : s;
8109
+ function toolBodyMd(tool, finalized = false) {
8110
+ if (tool.status === "done") return "\u6267\u884C\u5B8C\u6210\u3002";
8111
+ if (tool.status === "error") return "\u6267\u884C\u5931\u8D25\uFF0C\u5177\u4F53\u539F\u56E0\u8BF7\u89C1\u52A9\u624B\u8BF4\u660E\u3002";
8112
+ return finalized ? "\u672C\u8F6E\u5DF2\u7ED3\u675F\uFF0C\u672A\u6536\u5230\u6B64\u5DE5\u5177\u7684\u7ED3\u679C\u3002" : "\u6B63\u5728\u6267\u884C\u2026";
8186
8113
  }
8187
8114
 
8188
8115
  // src/bridge/card/run-renderer.ts
@@ -8208,13 +8135,7 @@ function renderCard(state, options = {}) {
8208
8135
  const mins = state.idleTimeoutMinutes ?? 0;
8209
8136
  elements.push(noteMd(`_\u23F1 ${mins} \u5206\u949F\u65E0\u54CD\u5E94,\u5DF2\u81EA\u52A8\u7EC8\u6B62_`));
8210
8137
  } else if (state.terminal === "error" && state.errorMsg) {
8211
- elements.push(
8212
- noteMd(
8213
- state.apiError ? `\u26A0\uFE0F \u4E0A\u6E38 API \u8FDE\u63A5\u4E2D\u65AD\uFF1A${state.errorMsg}
8214
-
8215
- _\u4E0D\u662F\u8FD9\u6761\u8BF7\u6C42\u7684\u95EE\u9898\uFF0C\u91CD\u53D1\u5373\u53EF\u7EE7\u7EED\uFF08\u4F1A\u8BDD\u4E0A\u4E0B\u6587\u6CA1\u4E22\uFF09\u3002_` : `\u26A0\uFE0F agent \u5931\u8D25\uFF1A${state.errorMsg}`
8216
- )
8217
- );
8138
+ elements.push(noteMd(errorNote(state, state.errorMsg)));
8218
8139
  } else if (state.terminal === "done" && elements.length === 0) {
8219
8140
  elements.push(noteMd("_\uFF08\u672A\u8FD4\u56DE\u5185\u5BB9\uFF09_"));
8220
8141
  }
@@ -8249,7 +8170,7 @@ function* groupBlocks(blocks) {
8249
8170
  function renderToolGroup(tools, finalized) {
8250
8171
  if (tools.length === 0) return [];
8251
8172
  if (tools.length < COLLAPSE_TOOL_THRESHOLD) {
8252
- return tools.map((t) => toolPanel(t, false));
8173
+ return tools.map((t) => toolPanel(t, false, finalized));
8253
8174
  }
8254
8175
  if (finalized) {
8255
8176
  return [collapsedToolSummary(tools, true)];
@@ -8267,21 +8188,21 @@ function reasoningPanel(content, active3) {
8267
8188
  title,
8268
8189
  expanded: active3,
8269
8190
  border: "grey",
8270
- body: truncate3(content, REASONING_MAX)
8191
+ body: truncate2(content, REASONING_MAX)
8271
8192
  });
8272
8193
  }
8273
- function toolPanel(tool, expanded) {
8194
+ function toolPanel(tool, expanded, finalized = false) {
8274
8195
  return collapsiblePanel({
8275
- title: toolHeaderText(tool),
8196
+ title: toolHeaderText(tool, finalized),
8276
8197
  expanded,
8277
8198
  border: tool.status === "error" ? "red" : "grey",
8278
- body: toolBodyMd(tool) || "_\u65E0\u8F93\u51FA_"
8199
+ body: toolBodyMd(tool, finalized)
8279
8200
  });
8280
8201
  }
8281
8202
  function collapsedToolSummary(tools, finalized) {
8282
8203
  const suffix = finalized ? "\uFF08\u5DF2\u7ED3\u675F\uFF09" : "";
8283
8204
  const title = `\u2615 **${tools.length} \u4E2A\u5DE5\u5177\u8C03\u7528${suffix}**`;
8284
- const headerList = tools.map((t) => `- ${toolHeaderText(t)}`).join("\n");
8205
+ const headerList = tools.map((t) => `- ${toolHeaderText(t, finalized)}`).join("\n");
8285
8206
  return {
8286
8207
  tag: "collapsible_panel",
8287
8208
  expanded: false,
@@ -8340,17 +8261,33 @@ function apiRetryText(apiRetry) {
8340
8261
  const of = apiRetry.maxRetries ? `/${apiRetry.maxRetries}` : "";
8341
8262
  return `\u{1F50C} API \u8FDE\u63A5\u4E2D\u65AD,\u6B63\u5728\u91CD\u8BD5 (${apiRetry.attempt}${of})`;
8342
8263
  }
8264
+ function errorNote(state, errorMsg) {
8265
+ if (state.authError) {
8266
+ return `\u26A0\uFE0F agent \u8BA4\u8BC1\u5931\u8D25\uFF1A${errorMsg}
8267
+
8268
+ _\u91CD\u53D1\u6CA1\u7528\u2014\u2014\u8981\u5230\u8DD1 bridge \u7684\u673A\u5668\u4E0A\u91CD\u65B0\u767B\u5F55\uFF08Claude Code \u91CC\u6267\u884C \`/login\`\uFF09\uFF0C\u767B\u5F55\u540E\u8FD9\u4E2A\u4F1A\u8BDD\u53EF\u4EE5\u63A5\u7740\u7528\u3002_`;
8269
+ }
8270
+ if (state.apiError) {
8271
+ return `\u26A0\uFE0F \u4E0A\u6E38 API \u8FDE\u63A5\u4E2D\u65AD\uFF1A${errorMsg}
8272
+
8273
+ _\u4E0D\u662F\u8FD9\u6761\u8BF7\u6C42\u7684\u95EE\u9898\uFF0C\u91CD\u53D1\u5373\u53EF\u7EE7\u7EED\uFF08\u4F1A\u8BDD\u4E0A\u4E0B\u6587\u6CA1\u4E22\uFF09\u3002_`;
8274
+ }
8275
+ return `\u26A0\uFE0F agent \u5931\u8D25\uFF1A${errorMsg}`;
8276
+ }
8343
8277
  function summaryText(state) {
8344
8278
  if (state.terminal === "interrupted") return "\u5DF2\u4E2D\u65AD";
8345
8279
  if (state.terminal === "idle_timeout") return "\u5DF2\u8D85\u65F6";
8346
- if (state.terminal === "error") return state.apiError ? "API \u8FDE\u63A5\u4E2D\u65AD" : "\u51FA\u9519";
8280
+ if (state.terminal === "error") {
8281
+ if (state.authError) return "\u8BA4\u8BC1\u5931\u8D25";
8282
+ return state.apiError ? "API \u8FDE\u63A5\u4E2D\u65AD" : "\u51FA\u9519";
8283
+ }
8347
8284
  if (state.terminal === "done") return "\u5DF2\u5B8C\u6210";
8348
8285
  if (state.footer === "api_retry") return "API \u91CD\u8BD5\u4E2D";
8349
8286
  if (state.footer === "tool_running") return "\u6B63\u5728\u8C03\u7528\u5DE5\u5177";
8350
8287
  if (state.footer === "streaming") return "\u6B63\u5728\u8F93\u51FA";
8351
8288
  return "\u601D\u8003\u4E2D";
8352
8289
  }
8353
- function truncate3(s, max) {
8290
+ function truncate2(s, max) {
8354
8291
  return s.length > max ? `${s.slice(0, max)}\u2026` : s;
8355
8292
  }
8356
8293
 
@@ -8444,6 +8381,7 @@ function reduce(state, evt) {
8444
8381
  terminal,
8445
8382
  errorMsg: terminal === "error" ? evt.message : state.errorMsg,
8446
8383
  ...terminal === "error" && evt.apiError ? { apiError: true } : {},
8384
+ ...terminal === "error" && evt.authError ? { authError: true } : {},
8447
8385
  footer: null
8448
8386
  };
8449
8387
  }
@@ -12077,7 +12015,7 @@ function decodeEntry(value) {
12077
12015
  function renderText(state) {
12078
12016
  const parts = [];
12079
12017
  for (const block of state.blocks) {
12080
- const piece = renderBlock(block);
12018
+ const piece = renderBlock(block, state.terminal !== "running");
12081
12019
  if (piece) parts.push(piece);
12082
12020
  }
12083
12021
  if (state.terminal === "interrupted") {
@@ -12086,24 +12024,33 @@ function renderText(state) {
12086
12024
  const mins = state.idleTimeoutMinutes ?? 0;
12087
12025
  parts.push(`_\u23F1 ${mins} \u5206\u949F\u65E0\u54CD\u5E94,\u5DF2\u81EA\u52A8\u7EC8\u6B62_`);
12088
12026
  } else if (state.terminal === "error" && state.errorMsg) {
12089
- parts.push(
12090
- state.apiError ? `\u26A0\uFE0F \u4E0A\u6E38 API \u8FDE\u63A5\u4E2D\u65AD:${state.errorMsg}
12091
-
12092
- _\u4E0D\u662F\u8FD9\u6761\u8BF7\u6C42\u7684\u95EE\u9898,\u91CD\u53D1\u5373\u53EF\u7EE7\u7EED(\u4F1A\u8BDD\u4E0A\u4E0B\u6587\u6CA1\u4E22)\u3002_` : `\u26A0\uFE0F agent \u5931\u8D25:${state.errorMsg}`
12093
- );
12027
+ parts.push(errorNote2(state, state.errorMsg));
12094
12028
  } else if (state.terminal === "running" && state.footer) {
12095
12029
  parts.push(footerLine(state.footer, state.apiRetry));
12096
12030
  }
12097
12031
  return maskEmails(parts.join("\n\n"));
12098
12032
  }
12099
- function renderBlock(block) {
12033
+ function errorNote2(state, errorMsg) {
12034
+ if (state.authError) {
12035
+ return `\u26A0\uFE0F agent \u8BA4\u8BC1\u5931\u8D25:${errorMsg}
12036
+
12037
+ _\u91CD\u53D1\u6CA1\u7528\u2014\u2014\u8981\u5230\u8DD1 bridge \u7684\u673A\u5668\u4E0A\u91CD\u65B0\u767B\u5F55(Claude Code \u91CC\u6267\u884C \`/login\`),\u767B\u5F55\u540E\u8FD9\u4E2A\u4F1A\u8BDD\u53EF\u4EE5\u63A5\u7740\u7528\u3002_`;
12038
+ }
12039
+ if (state.apiError) {
12040
+ return `\u26A0\uFE0F \u4E0A\u6E38 API \u8FDE\u63A5\u4E2D\u65AD:${errorMsg}
12041
+
12042
+ _\u4E0D\u662F\u8FD9\u6761\u8BF7\u6C42\u7684\u95EE\u9898,\u91CD\u53D1\u5373\u53EF\u7EE7\u7EED(\u4F1A\u8BDD\u4E0A\u4E0B\u6587\u6CA1\u4E22)\u3002_`;
12043
+ }
12044
+ return `\u26A0\uFE0F agent \u5931\u8D25:${errorMsg}`;
12045
+ }
12046
+ function renderBlock(block, finalized) {
12100
12047
  if (block.kind === "text") {
12101
12048
  return block.content.trim();
12102
12049
  }
12103
- return toolLine(block.tool);
12050
+ return toolLine(block.tool, finalized);
12104
12051
  }
12105
- function toolLine(tool) {
12106
- return `> ${toolHeaderText(tool)}`;
12052
+ function toolLine(tool, finalized) {
12053
+ return `> ${toolHeaderText(tool, finalized)}`;
12107
12054
  }
12108
12055
  function footerLine(status, apiRetry) {
12109
12056
  if (status === "thinking") return "_\u{1F9E0} \u6B63\u5728\u601D\u8003\u2026_";
@@ -14012,7 +13959,7 @@ async function consumeCotEvents(events, publisher, opts) {
14012
13959
  toolCallId,
14013
13960
  icon: showSummary ? cotToolIcon(evt.name) : "default",
14014
13961
  title,
14015
- toolCallName: showSummary ? evt.name : "tool"
13962
+ toolCallName: detailed ? evt.name : "tool"
14016
13963
  });
14017
13964
  if (detailed && evt.input !== void 0) {
14018
13965
  publisher.enqueue("TOOL_CALL_ARGS", {
@@ -15003,6 +14950,7 @@ async function runAgentBatch(deps) {
15003
14950
  log.fail("stream", err, { mode: replyMode, step: "progress-stream" });
15004
14951
  }
15005
14952
  await recallIfEmptyStreamedReply(channel, progress, filterForPrefs(latestState), scope);
14953
+ scheduleProgressTerminalUpdate(channel, progress, filterForPrefs(latestState), scope, replyMode);
15006
14954
  if (controls.profileConfig.agentKind === "codex") {
15007
14955
  await sendFinalReply({
15008
14956
  channel,
@@ -15083,6 +15031,7 @@ async function runAgentBatch(deps) {
15083
15031
  log.fail("stream", err, { mode: replyMode, step: "progress-stream" });
15084
15032
  }
15085
15033
  await recallIfEmptyStreamedReply(channel, progress, filterForPrefs(latestState), scope);
15034
+ scheduleProgressTerminalUpdate(channel, progress, filterForPrefs(latestState), scope, replyMode);
15086
15035
  if (controls.profileConfig.agentKind === "codex") {
15087
15036
  await sendFinalReply({
15088
15037
  channel,
@@ -15182,7 +15131,9 @@ function shouldOpenProgressStream(state) {
15182
15131
  return renderText({ ...state, footer: null }).trim() !== "";
15183
15132
  }
15184
15133
  function finalReplyState(progress, state) {
15185
- if (!progress.opened() || progress.abandoned()) return finalAnswerOnlyState(state);
15134
+ if (!progress.opened() || progress.abandoned() || streamOutlivedCardLifetime(progress)) {
15135
+ return finalAnswerOnlyState(state);
15136
+ }
15186
15137
  return {
15187
15138
  ...state,
15188
15139
  blocks: state.finalText ? [{ kind: "text", content: state.finalText, streaming: false }] : [],
@@ -15192,6 +15143,30 @@ function finalReplyState(progress, state) {
15192
15143
  errorMsg: void 0
15193
15144
  };
15194
15145
  }
15146
+ function scheduleProgressTerminalUpdate(channel, progress, state, scope, mode) {
15147
+ if (!streamOutlivedCardLifetime(progress) || renderText(state).trim() === "") return;
15148
+ void progress.settled.then(async (result) => {
15149
+ const messageId = result?.messageId;
15150
+ if (!messageId) return;
15151
+ try {
15152
+ const terminalState = {
15153
+ ...state,
15154
+ // Markdown never shows reasoning; a repair must preserve that boundary.
15155
+ reasoning: mode === "markdown" ? { content: "", active: false } : state.reasoning,
15156
+ blocks: state.terminal === "done" ? [...state.blocks, { kind: "text", content: "\u672C\u8F6E\u6267\u884C\u5DF2\u7ED3\u675F\u3002", streaming: false }] : state.blocks
15157
+ };
15158
+ await channel.updateCard(messageId, renderCard(terminalState));
15159
+ log.info("outbound", "progress-terminal-updated", { scope, messageId, terminal: state.terminal });
15160
+ } catch (err) {
15161
+ log.warn("outbound", "progress-terminal-update-failed", {
15162
+ scope,
15163
+ messageId,
15164
+ err: err instanceof Error ? err.message : String(err)
15165
+ });
15166
+ }
15167
+ }, () => {
15168
+ });
15169
+ }
15195
15170
  async function recallIfEmptyStreamedReply(channel, progress, finalState, scope) {
15196
15171
  if (!progress.opened()) return;
15197
15172
  if (progress.abandoned()) {