aai-lark-bridge 0.1.7 → 0.1.9

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.9",
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",
@@ -978,6 +978,7 @@ function resolveAppPaths(opts = {}) {
978
978
  configFile: join4(rootDir, "config.json"),
979
979
  activeProfileFile: join4(rootDir, "active-profile"),
980
980
  sessionsFile: join4(profileDir, "sessions.json"),
981
+ inboundStateFile: join4(profileDir, "inbound.json"),
981
982
  workspacesFile: join4(profileDir, "workspaces.json"),
982
983
  secretsFile: join4(profileDir, "secrets.enc"),
983
984
  keystoreSaltFile: join4(profileDir, ".keystore.salt"),
@@ -1782,6 +1783,9 @@ function enable(profile2) {
1782
1783
  function kickstart(profile2) {
1783
1784
  return runLaunchctl(["kickstart", "-k", serviceTarget(profile2)]);
1784
1785
  }
1786
+ function nudge(profile2) {
1787
+ return runLaunchctl(["kickstart", serviceTarget(profile2)]);
1788
+ }
1785
1789
  function isLoaded(profile2) {
1786
1790
  const r = spawnSync("launchctl", ["print", serviceTarget(profile2)], {
1787
1791
  stdio: ["ignore", "ignore", "ignore"]
@@ -2023,7 +2027,10 @@ function makeLaunchdAdapter(profile2, runArgs) {
2023
2027
  // DB, where it would stay dead through bootstrap. Always enable first.
2024
2028
  start: () => {
2025
2029
  enable(profile2);
2026
- return bootstrap(profile2);
2030
+ const loaded = bootstrap(profile2);
2031
+ if (!loaded.ok) return loaded;
2032
+ const nudged = nudge(profile2);
2033
+ return nudged.ok ? loaded : nudged;
2027
2034
  },
2028
2035
  stop: () => bootout(profile2),
2029
2036
  // bootout alone is session-scoped: the plist keeps RunAtLoad=true, so
@@ -6064,6 +6071,8 @@ bridge \u4F1A\u7ED9\u4F60\u7684\u5B50\u8FDB\u7A0B\u6CE8\u5165\u5F53\u524D\u8FD0\
6064
6071
 
6065
6072
  ## \u6545\u969C\u8BCA\u65AD\u4E0E\u5B8C\u6210\u72B6\u6001
6066
6073
 
6074
+ - \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
6075
+ - \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
6076
  - \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
6077
  - \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
6078
  - \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 +6189,14 @@ function* translateEvent(raw) {
6180
6189
  return;
6181
6190
  }
6182
6191
  if (evt.is_error === true) {
6183
- const apiError = evt.terminal_reason === "api_error";
6192
+ const message = errorMessage2(evt);
6193
+ const authError = isAuthFailure(message);
6194
+ const apiError = !authError && evt.terminal_reason === "api_error";
6184
6195
  yield {
6185
6196
  type: "error",
6186
- message: errorMessage2(evt),
6197
+ message,
6187
6198
  terminationReason: "failed",
6199
+ ...authError ? { authError: true } : {},
6188
6200
  ...apiError ? { apiError: true } : {}
6189
6201
  };
6190
6202
  return;
@@ -6192,6 +6204,10 @@ function* translateEvent(raw) {
6192
6204
  yield { type: "done", sessionId: evt.session_id, terminationReason: "normal" };
6193
6205
  }
6194
6206
  }
6207
+ var AUTH_FAILURE = /failed to authenticate|login expired|not logged in|invalid api key|re-authenticate/i;
6208
+ function isAuthFailure(message) {
6209
+ return AUTH_FAILURE.test(message);
6210
+ }
6195
6211
  function errorMessage2(evt) {
6196
6212
  const text = typeof evt.result === "string" ? evt.result.trim() : "";
6197
6213
  if (text) return text;
@@ -6971,7 +6987,7 @@ function isWindowsCommandNotFoundLine2(line) {
6971
6987
 
6972
6988
  // src/bridge/bot/channel.ts
6973
6989
  import { createLarkChannel } from "@larksuite/channel";
6974
- import { dirname as dirname18, join as join22 } from "path";
6990
+ import { dirname as dirname18, join as join23 } from "path";
6975
6991
 
6976
6992
  // src/bridge/agent/capability.ts
6977
6993
  function claudeCapability(profile2) {
@@ -7013,9 +7029,11 @@ function codexCapability(profile2) {
7013
7029
  var DEFAULT_MODEL = "default";
7014
7030
  var CLAUDE_MODELS = [
7015
7031
  { value: DEFAULT_MODEL, label: "\u8DDF\u968F\u9ED8\u8BA4\uFF08\u4E0D\u6307\u5B9A\uFF09" },
7032
+ { value: "claude-opus-5-5", label: "Opus 5.5" },
7016
7033
  { value: "claude-opus-5", label: "Opus 5\uFF08\u6700\u65B0\uFF09" },
7017
7034
  { value: "claude-opus-4-8", label: "Opus 4.8" },
7018
7035
  { value: "claude-opus-4-7", label: "Opus 4.7" },
7036
+ { value: "claude-sonnet-5-5", label: "Sonnet 5.5" },
7019
7037
  { value: "claude-sonnet-5", label: "Sonnet 5\uFF08\u6700\u65B0\uFF09" },
7020
7038
  { value: "claude-sonnet-4-6", label: "Sonnet 4.6" },
7021
7039
  { value: "claude-haiku-4-5", label: "Haiku 4.5\uFF08\u6700\u65B0\uFF09" },
@@ -8066,123 +8084,41 @@ function deepMaskEmails(value) {
8066
8084
  }
8067
8085
 
8068
8086
  // 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
- };
8087
+ function actionLabel(name) {
8115
8088
  switch (name) {
8116
8089
  case "Bash":
8117
- return pick("command");
8090
+ case "command_execution":
8091
+ case "exec_command":
8092
+ return "\u6267\u884C\u547D\u4EE4";
8118
8093
  case "Read":
8094
+ return "\u8BFB\u53D6\u6587\u4EF6";
8119
8095
  case "Edit":
8120
8096
  case "Write":
8121
8097
  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
- }
8098
+ case "apply_patch":
8099
+ return "\u4FEE\u6539\u6587\u4EF6";
8100
+ case "Grep":
8128
8101
  case "Glob":
8129
- return pick("pattern");
8102
+ return "\u641C\u7D22\u6587\u4EF6";
8130
8103
  case "WebFetch":
8131
- return pick("url");
8132
8104
  case "WebSearch":
8133
- return pick("query", 60);
8105
+ return "\u67E5\u8BE2\u7F51\u9875";
8134
8106
  case "Agent":
8135
8107
  case "Task":
8136
- return pick("description") || pick("subagent_type");
8108
+ return "\u6267\u884C\u5B50\u4EFB\u52A1";
8137
8109
  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 "";
8110
+ return "\u8C03\u7528\u5DE5\u5177";
8173
8111
  }
8174
8112
  }
8175
- function renderBashOutput(out) {
8176
- return `**Output**
8177
- \`\`\`
8178
- ${out}
8179
- \`\`\``;
8113
+ function toolHeaderText(tool, finalized = false) {
8114
+ const icon = tool.status === "done" ? "\u2705" : tool.status === "error" ? "\u274C" : finalized ? "\u26AA" : "\u23F3";
8115
+ const suffix = finalized && tool.status === "running" ? "\uFF08\u5DF2\u7ED3\u675F\uFF0C\u672A\u6536\u5230\u7ED3\u679C\uFF09" : "";
8116
+ return `${icon} **${actionLabel(tool.name)}**${suffix}`;
8180
8117
  }
8181
- function shortenPath(p3) {
8182
- return p3;
8183
- }
8184
- function truncate2(s, max) {
8185
- return s.length > max ? `${s.slice(0, max)}\u2026` : s;
8118
+ function toolBodyMd(tool, finalized = false) {
8119
+ if (tool.status === "done") return "\u6267\u884C\u5B8C\u6210\u3002";
8120
+ if (tool.status === "error") return "\u6267\u884C\u5931\u8D25\uFF0C\u5177\u4F53\u539F\u56E0\u8BF7\u89C1\u52A9\u624B\u8BF4\u660E\u3002";
8121
+ return finalized ? "\u672C\u8F6E\u5DF2\u7ED3\u675F\uFF0C\u672A\u6536\u5230\u6B64\u5DE5\u5177\u7684\u7ED3\u679C\u3002" : "\u6B63\u5728\u6267\u884C\u2026";
8186
8122
  }
8187
8123
 
8188
8124
  // src/bridge/card/run-renderer.ts
@@ -8208,13 +8144,7 @@ function renderCard(state, options = {}) {
8208
8144
  const mins = state.idleTimeoutMinutes ?? 0;
8209
8145
  elements.push(noteMd(`_\u23F1 ${mins} \u5206\u949F\u65E0\u54CD\u5E94,\u5DF2\u81EA\u52A8\u7EC8\u6B62_`));
8210
8146
  } 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
- );
8147
+ elements.push(noteMd(errorNote(state, state.errorMsg)));
8218
8148
  } else if (state.terminal === "done" && elements.length === 0) {
8219
8149
  elements.push(noteMd("_\uFF08\u672A\u8FD4\u56DE\u5185\u5BB9\uFF09_"));
8220
8150
  }
@@ -8249,7 +8179,7 @@ function* groupBlocks(blocks) {
8249
8179
  function renderToolGroup(tools, finalized) {
8250
8180
  if (tools.length === 0) return [];
8251
8181
  if (tools.length < COLLAPSE_TOOL_THRESHOLD) {
8252
- return tools.map((t) => toolPanel(t, false));
8182
+ return tools.map((t) => toolPanel(t, false, finalized));
8253
8183
  }
8254
8184
  if (finalized) {
8255
8185
  return [collapsedToolSummary(tools, true)];
@@ -8267,21 +8197,21 @@ function reasoningPanel(content, active3) {
8267
8197
  title,
8268
8198
  expanded: active3,
8269
8199
  border: "grey",
8270
- body: truncate3(content, REASONING_MAX)
8200
+ body: truncate2(content, REASONING_MAX)
8271
8201
  });
8272
8202
  }
8273
- function toolPanel(tool, expanded) {
8203
+ function toolPanel(tool, expanded, finalized = false) {
8274
8204
  return collapsiblePanel({
8275
- title: toolHeaderText(tool),
8205
+ title: toolHeaderText(tool, finalized),
8276
8206
  expanded,
8277
8207
  border: tool.status === "error" ? "red" : "grey",
8278
- body: toolBodyMd(tool) || "_\u65E0\u8F93\u51FA_"
8208
+ body: toolBodyMd(tool, finalized)
8279
8209
  });
8280
8210
  }
8281
8211
  function collapsedToolSummary(tools, finalized) {
8282
8212
  const suffix = finalized ? "\uFF08\u5DF2\u7ED3\u675F\uFF09" : "";
8283
8213
  const title = `\u2615 **${tools.length} \u4E2A\u5DE5\u5177\u8C03\u7528${suffix}**`;
8284
- const headerList = tools.map((t) => `- ${toolHeaderText(t)}`).join("\n");
8214
+ const headerList = tools.map((t) => `- ${toolHeaderText(t, finalized)}`).join("\n");
8285
8215
  return {
8286
8216
  tag: "collapsible_panel",
8287
8217
  expanded: false,
@@ -8340,17 +8270,33 @@ function apiRetryText(apiRetry) {
8340
8270
  const of = apiRetry.maxRetries ? `/${apiRetry.maxRetries}` : "";
8341
8271
  return `\u{1F50C} API \u8FDE\u63A5\u4E2D\u65AD,\u6B63\u5728\u91CD\u8BD5 (${apiRetry.attempt}${of})`;
8342
8272
  }
8273
+ function errorNote(state, errorMsg) {
8274
+ if (state.authError) {
8275
+ return `\u26A0\uFE0F agent \u8BA4\u8BC1\u5931\u8D25\uFF1A${errorMsg}
8276
+
8277
+ _\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_`;
8278
+ }
8279
+ if (state.apiError) {
8280
+ return `\u26A0\uFE0F \u4E0A\u6E38 API \u8FDE\u63A5\u4E2D\u65AD\uFF1A${errorMsg}
8281
+
8282
+ _\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_`;
8283
+ }
8284
+ return `\u26A0\uFE0F agent \u5931\u8D25\uFF1A${errorMsg}`;
8285
+ }
8343
8286
  function summaryText(state) {
8344
8287
  if (state.terminal === "interrupted") return "\u5DF2\u4E2D\u65AD";
8345
8288
  if (state.terminal === "idle_timeout") return "\u5DF2\u8D85\u65F6";
8346
- if (state.terminal === "error") return state.apiError ? "API \u8FDE\u63A5\u4E2D\u65AD" : "\u51FA\u9519";
8289
+ if (state.terminal === "error") {
8290
+ if (state.authError) return "\u8BA4\u8BC1\u5931\u8D25";
8291
+ return state.apiError ? "API \u8FDE\u63A5\u4E2D\u65AD" : "\u51FA\u9519";
8292
+ }
8347
8293
  if (state.terminal === "done") return "\u5DF2\u5B8C\u6210";
8348
8294
  if (state.footer === "api_retry") return "API \u91CD\u8BD5\u4E2D";
8349
8295
  if (state.footer === "tool_running") return "\u6B63\u5728\u8C03\u7528\u5DE5\u5177";
8350
8296
  if (state.footer === "streaming") return "\u6B63\u5728\u8F93\u51FA";
8351
8297
  return "\u601D\u8003\u4E2D";
8352
8298
  }
8353
- function truncate3(s, max) {
8299
+ function truncate2(s, max) {
8354
8300
  return s.length > max ? `${s.slice(0, max)}\u2026` : s;
8355
8301
  }
8356
8302
 
@@ -8444,6 +8390,7 @@ function reduce(state, evt) {
8444
8390
  terminal,
8445
8391
  errorMsg: terminal === "error" ? evt.message : state.errorMsg,
8446
8392
  ...terminal === "error" && evt.apiError ? { apiError: true } : {},
8393
+ ...terminal === "error" && evt.authError ? { authError: true } : {},
8447
8394
  footer: null
8448
8395
  };
8449
8396
  }
@@ -11698,12 +11645,63 @@ async function lookupMessageThreadId(channel, messageId) {
11698
11645
  }
11699
11646
  }
11700
11647
 
11648
+ // src/bridge/card/handoff.ts
11649
+ import { createHash as createHash3 } from "crypto";
11650
+ import { existsSync as existsSync6, mkdirSync as mkdirSync3, renameSync as renameSync2, writeFileSync as writeFileSync3 } from "fs";
11651
+ import { isAbsolute as isAbsolute3, join as join21 } from "path";
11652
+ function handoffDirs(raw) {
11653
+ if (!raw || typeof raw !== "object") return {};
11654
+ const out = {};
11655
+ for (const [kind, dir] of Object.entries(raw)) {
11656
+ if (typeof dir === "string" && isAbsolute3(dir)) out[kind] = dir;
11657
+ else log.warn("cardAction", "handoff-bad-dir", { kind });
11658
+ }
11659
+ return out;
11660
+ }
11661
+ function tryHandoff(evt, dirs) {
11662
+ const value = evt.action?.value;
11663
+ if (!value || typeof value !== "object") return false;
11664
+ const kind = value.kind;
11665
+ if (typeof kind !== "string" || !dirs[kind]) return false;
11666
+ const raw = evt.raw;
11667
+ const token = typeof raw?.token === "string" && raw.token.startsWith("c-") ? raw.token : "";
11668
+ const eventId = typeof raw?.event_id === "string" ? raw.event_id : "";
11669
+ const key = eventId || `${evt.messageId}:${evt.operator.openId}:${JSON.stringify(value)}`;
11670
+ const name = `${createHash3("sha256").update(key).digest("hex").slice(0, 24)}.json`;
11671
+ const dir = dirs[kind];
11672
+ try {
11673
+ mkdirSync3(dir, { recursive: true });
11674
+ const file = join21(dir, name);
11675
+ if (existsSync6(file)) return true;
11676
+ const tmp = join21(dir, `.${name}.${process.pid}.tmp`);
11677
+ writeFileSync3(
11678
+ tmp,
11679
+ JSON.stringify({
11680
+ event_id: eventId,
11681
+ kind,
11682
+ value,
11683
+ operator_open_id: evt.operator.openId,
11684
+ message_id: evt.messageId,
11685
+ chat_id: evt.chatId,
11686
+ token,
11687
+ received_at: (/* @__PURE__ */ new Date()).toISOString()
11688
+ })
11689
+ );
11690
+ renameSync2(tmp, file);
11691
+ log.info("cardAction", "handoff", { kind, file: name });
11692
+ } catch (err) {
11693
+ log.fail("cardAction", err, { kind, step: "handoff" });
11694
+ }
11695
+ return true;
11696
+ }
11697
+
11701
11698
  // src/bridge/card/dispatcher.ts
11702
11699
  var BRIDGE_CALLBACK_MARKER = "__bridge_cb";
11703
11700
  var LEGACY_CLAUDE_CALLBACK_MARKER = "__claude_cb";
11704
11701
  async function handleCardAction(deps) {
11705
11702
  const value = deps.evt.action.value;
11706
11703
  if (!value || typeof value !== "object") return;
11704
+ if (tryHandoff(deps.evt, handoffDirs(deps.controls.profileConfig.preferences.cardHandoffs))) return;
11707
11705
  const payload = value;
11708
11706
  const operatorId = deps.evt.operator.openId;
11709
11707
  const chatId = deps.evt.chatId;
@@ -12077,7 +12075,7 @@ function decodeEntry(value) {
12077
12075
  function renderText(state) {
12078
12076
  const parts = [];
12079
12077
  for (const block of state.blocks) {
12080
- const piece = renderBlock(block);
12078
+ const piece = renderBlock(block, state.terminal !== "running");
12081
12079
  if (piece) parts.push(piece);
12082
12080
  }
12083
12081
  if (state.terminal === "interrupted") {
@@ -12086,24 +12084,33 @@ function renderText(state) {
12086
12084
  const mins = state.idleTimeoutMinutes ?? 0;
12087
12085
  parts.push(`_\u23F1 ${mins} \u5206\u949F\u65E0\u54CD\u5E94,\u5DF2\u81EA\u52A8\u7EC8\u6B62_`);
12088
12086
  } 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
- );
12087
+ parts.push(errorNote2(state, state.errorMsg));
12094
12088
  } else if (state.terminal === "running" && state.footer) {
12095
12089
  parts.push(footerLine(state.footer, state.apiRetry));
12096
12090
  }
12097
12091
  return maskEmails(parts.join("\n\n"));
12098
12092
  }
12099
- function renderBlock(block) {
12093
+ function errorNote2(state, errorMsg) {
12094
+ if (state.authError) {
12095
+ return `\u26A0\uFE0F agent \u8BA4\u8BC1\u5931\u8D25:${errorMsg}
12096
+
12097
+ _\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_`;
12098
+ }
12099
+ if (state.apiError) {
12100
+ return `\u26A0\uFE0F \u4E0A\u6E38 API \u8FDE\u63A5\u4E2D\u65AD:${errorMsg}
12101
+
12102
+ _\u4E0D\u662F\u8FD9\u6761\u8BF7\u6C42\u7684\u95EE\u9898,\u91CD\u53D1\u5373\u53EF\u7EE7\u7EED(\u4F1A\u8BDD\u4E0A\u4E0B\u6587\u6CA1\u4E22)\u3002_`;
12103
+ }
12104
+ return `\u26A0\uFE0F agent \u5931\u8D25:${errorMsg}`;
12105
+ }
12106
+ function renderBlock(block, finalized) {
12100
12107
  if (block.kind === "text") {
12101
12108
  return block.content.trim();
12102
12109
  }
12103
- return toolLine(block.tool);
12110
+ return toolLine(block.tool, finalized);
12104
12111
  }
12105
- function toolLine(tool) {
12106
- return `> ${toolHeaderText(tool)}`;
12112
+ function toolLine(tool, finalized) {
12113
+ return `> ${toolHeaderText(tool, finalized)}`;
12107
12114
  }
12108
12115
  function footerLine(status, apiRetry) {
12109
12116
  if (status === "thinking") return "_\u{1F9E0} \u6B63\u5728\u601D\u8003\u2026_";
@@ -12117,10 +12124,10 @@ function footerLine(status, apiRetry) {
12117
12124
  }
12118
12125
 
12119
12126
  // src/bridge/media/cache.ts
12120
- import { createHash as createHash3 } from "crypto";
12127
+ import { createHash as createHash4 } from "crypto";
12121
12128
  import { createReadStream as createReadStream2 } from "fs";
12122
12129
  import { mkdir as mkdir14, readdir as readdir5, rename as rename4, rm as rm12, stat as stat7 } from "fs/promises";
12123
- import { join as join21 } from "path";
12130
+ import { join as join22 } from "path";
12124
12131
 
12125
12132
  // src/bridge/media/attachment.ts
12126
12133
  var DEFAULT_POLICY = {
@@ -12256,7 +12263,7 @@ var MediaCache = class {
12256
12263
  return null;
12257
12264
  }
12258
12265
  const kind = r.type;
12259
- const tmpPath = join21(
12266
+ const tmpPath = join22(
12260
12267
  this.rootDir,
12261
12268
  `.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`
12262
12269
  );
@@ -12270,7 +12277,7 @@ var MediaCache = class {
12270
12277
  const hash = await hashFile(tmpPath);
12271
12278
  const mime = contentType ?? defaultMime(kind);
12272
12279
  const ext = safeExtensionForMime(mime);
12273
- const absPath = join21(this.rootDir, `${hash}.${ext}`);
12280
+ const absPath = join22(this.rootDir, `${hash}.${ext}`);
12274
12281
  try {
12275
12282
  await stat7(absPath);
12276
12283
  await rm12(tmpPath, { force: true });
@@ -12312,7 +12319,7 @@ async function listFiles(root) {
12312
12319
  const out = [];
12313
12320
  const entries = await readdir5(root, { withFileTypes: true }).catch(() => []);
12314
12321
  for (const entry of entries) {
12315
- const full = join21(root, entry.name);
12322
+ const full = join22(root, entry.name);
12316
12323
  if (entry.isDirectory()) {
12317
12324
  out.push(...await listFiles(full));
12318
12325
  } else if (entry.isFile()) {
@@ -12322,7 +12329,7 @@ async function listFiles(root) {
12322
12329
  return out;
12323
12330
  }
12324
12331
  async function hashFile(path) {
12325
- const hash = createHash3("sha256");
12332
+ const hash = createHash4("sha256");
12326
12333
  for await (const chunk of createReadStream2(path)) {
12327
12334
  hash.update(chunk);
12328
12335
  }
@@ -12827,9 +12834,9 @@ import { mkdir as mkdir15 } from "fs/promises";
12827
12834
  import { dirname as dirname17 } from "path";
12828
12835
 
12829
12836
  // src/bridge/bot/comment-resource.ts
12830
- import { createHash as createHash4 } from "crypto";
12837
+ import { createHash as createHash5 } from "crypto";
12831
12838
  function commentTokenDigest(token) {
12832
- return createHash4("sha256").update(token).digest("hex").slice(0, 16);
12839
+ return createHash5("sha256").update(token).digest("hex").slice(0, 16);
12833
12840
  }
12834
12841
  function commentDocumentScopeId(fileToken) {
12835
12842
  return `comment-doc:${commentTokenDigest(fileToken)}`;
@@ -13381,6 +13388,98 @@ function preview(text) {
13381
13388
  return text.length > 80 ? `${text.slice(0, 80)}\u2026` : text;
13382
13389
  }
13383
13390
 
13391
+ // src/bridge/bot/inbound-mark.ts
13392
+ import { readFile as readFile14 } from "fs/promises";
13393
+ function inboundGapFields(prev, now) {
13394
+ if (!prev) return { first: true };
13395
+ const gapMs = now - prev.at;
13396
+ if (!prev.acrossRestart) return { gapMs };
13397
+ if (gapMs < 0) return { first: true };
13398
+ return { gapMs, acrossRestart: true };
13399
+ }
13400
+ var InboundMarkStore = class {
13401
+ path;
13402
+ appId;
13403
+ write;
13404
+ // Only the newest time matters, so writes coalesce: at most one in flight,
13405
+ // plus the latest value waiting behind it. `pending` = a record() not yet
13406
+ // attempted; each record() buys at most one write attempt, so a failing
13407
+ // disk never makes this spin, yet a failure is retried on the next record()
13408
+ // even when it carries the same millisecond.
13409
+ latest;
13410
+ written;
13411
+ pending = false;
13412
+ inFlight;
13413
+ constructor(path, appId, opts = {}) {
13414
+ this.path = path;
13415
+ this.appId = appId;
13416
+ this.write = opts.write ?? ((p3, data) => writeFileAtomic(p3, data, { mode: 384 }));
13417
+ }
13418
+ /** Persisted time, or undefined when missing, invalid or from another app. Never throws. */
13419
+ async load() {
13420
+ let raw;
13421
+ try {
13422
+ raw = await readFile14(this.path, "utf8");
13423
+ } catch (err) {
13424
+ if (err.code === "ENOENT") return void 0;
13425
+ log.warn("ws", "inbound-state-invalid", { reason: "read", err: String(err) });
13426
+ return void 0;
13427
+ }
13428
+ let parsed;
13429
+ try {
13430
+ parsed = JSON.parse(raw);
13431
+ } catch {
13432
+ log.warn("ws", "inbound-state-invalid", { reason: "json" });
13433
+ return void 0;
13434
+ }
13435
+ if (!isRecord3(parsed)) {
13436
+ log.warn("ws", "inbound-state-invalid", { reason: "shape" });
13437
+ return void 0;
13438
+ }
13439
+ if (parsed.appId !== this.appId) return void 0;
13440
+ return parsed.at;
13441
+ }
13442
+ /** Remember `at` and persist it in the background. Returns immediately, never throws. */
13443
+ record(at) {
13444
+ this.latest = at;
13445
+ this.pending = true;
13446
+ this.kick();
13447
+ }
13448
+ kick() {
13449
+ if (this.inFlight) return;
13450
+ const run = this.drain().finally(() => {
13451
+ if (this.inFlight !== run) return;
13452
+ this.inFlight = void 0;
13453
+ if (this.pending) this.kick();
13454
+ });
13455
+ this.inFlight = run;
13456
+ }
13457
+ /** Wait for in-flight and queued writes (disconnect and tests). */
13458
+ async flush() {
13459
+ while (this.inFlight) await this.inFlight;
13460
+ }
13461
+ async drain() {
13462
+ while (this.pending) {
13463
+ this.pending = false;
13464
+ const at = this.latest;
13465
+ if (at === void 0 || at === this.written) continue;
13466
+ const record = { v: 1, appId: this.appId, at };
13467
+ try {
13468
+ await this.write(this.path, `${JSON.stringify(record)}
13469
+ `);
13470
+ this.written = at;
13471
+ } catch (err) {
13472
+ log.fail("ws", err, { step: "inbound-persist" });
13473
+ }
13474
+ }
13475
+ }
13476
+ };
13477
+ function isRecord3(value) {
13478
+ if (!value || typeof value !== "object") return false;
13479
+ const v = value;
13480
+ return v.v === 1 && typeof v.appId === "string" && v.appId.length > 0 && typeof v.at === "number" && Number.isSafeInteger(v.at) && v.at > 0;
13481
+ }
13482
+
13384
13483
  // src/bridge/bot/keepalive.ts
13385
13484
  var KEEPALIVE_INTERVAL_MS = 15e3;
13386
13485
  var SLEEP_DETECT_MS = 3e4;
@@ -14012,7 +14111,7 @@ async function consumeCotEvents(events, publisher, opts) {
14012
14111
  toolCallId,
14013
14112
  icon: showSummary ? cotToolIcon(evt.name) : "default",
14014
14113
  title,
14015
- toolCallName: showSummary ? evt.name : "tool"
14114
+ toolCallName: detailed ? evt.name : "tool"
14016
14115
  });
14017
14116
  if (detailed && evt.input !== void 0) {
14018
14117
  publisher.enqueue("TOOL_CALL_ARGS", {
@@ -14205,7 +14304,7 @@ async function startChannel(deps) {
14205
14304
  const pool = new ProcessPool(() => getMaxConcurrentRuns(controls.cfg));
14206
14305
  const executor = new RunExecutor({ agent, pool, activeRuns });
14207
14306
  const appSecret = await resolveAppSecret(cfg, deps.appPaths);
14208
- const callbackNonceStore = deps.appPaths?.mediaDir ? new CallbackNonceStore(join22(dirname18(deps.appPaths.mediaDir), "callback-nonces.json")) : void 0;
14307
+ const callbackNonceStore = deps.appPaths?.mediaDir ? new CallbackNonceStore(join23(dirname18(deps.appPaths.mediaDir), "callback-nonces.json")) : void 0;
14209
14308
  await callbackNonceStore?.load();
14210
14309
  const callbackAuth = callbackNonceStore ? new CallbackAuth({
14211
14310
  keys: [{ version: 1, secret: appSecret }],
@@ -14315,14 +14414,14 @@ async function startChannel(deps) {
14315
14414
  });
14316
14415
  });
14317
14416
  let consecutiveReconnects = 0;
14318
- let lastInboundAt = 0;
14417
+ const inboundMarks = deps.appPaths?.inboundStateFile ? new InboundMarkStore(deps.appPaths.inboundStateFile, cfg.accounts.app.id) : void 0;
14418
+ const persistedInboundAt = await inboundMarks?.load();
14419
+ let lastInbound = persistedInboundAt !== void 0 ? { at: persistedInboundAt, acrossRestart: true } : void 0;
14319
14420
  const markInbound = (kind) => {
14320
14421
  const at = Date.now();
14321
- log.info("ws", "inbound", {
14322
- kind,
14323
- ...lastInboundAt > 0 ? { gapMs: at - lastInboundAt } : { first: true }
14324
- });
14325
- lastInboundAt = at;
14422
+ log.info("ws", "inbound", { kind, ...inboundGapFields(lastInbound, at) });
14423
+ lastInbound = { at, acrossRestart: false };
14424
+ inboundMarks?.record(at);
14326
14425
  };
14327
14426
  channel.on({
14328
14427
  message: async (msg) => {
@@ -14507,7 +14606,8 @@ async function startChannel(deps) {
14507
14606
  sessions2.flush(),
14508
14607
  sessionCatalog?.flush(),
14509
14608
  callbackNonceStore?.flush(),
14510
- workspaces.flush()
14609
+ workspaces.flush(),
14610
+ inboundMarks?.flush()
14511
14611
  ]);
14512
14612
  if (stopAllResult.status === "rejected") {
14513
14613
  log.fail("disconnect", stopAllResult.reason, { step: "stopAll" });
@@ -15003,6 +15103,7 @@ async function runAgentBatch(deps) {
15003
15103
  log.fail("stream", err, { mode: replyMode, step: "progress-stream" });
15004
15104
  }
15005
15105
  await recallIfEmptyStreamedReply(channel, progress, filterForPrefs(latestState), scope);
15106
+ scheduleProgressTerminalUpdate(channel, progress, filterForPrefs(latestState), scope, replyMode);
15006
15107
  if (controls.profileConfig.agentKind === "codex") {
15007
15108
  await sendFinalReply({
15008
15109
  channel,
@@ -15083,6 +15184,7 @@ async function runAgentBatch(deps) {
15083
15184
  log.fail("stream", err, { mode: replyMode, step: "progress-stream" });
15084
15185
  }
15085
15186
  await recallIfEmptyStreamedReply(channel, progress, filterForPrefs(latestState), scope);
15187
+ scheduleProgressTerminalUpdate(channel, progress, filterForPrefs(latestState), scope, replyMode);
15086
15188
  if (controls.profileConfig.agentKind === "codex") {
15087
15189
  await sendFinalReply({
15088
15190
  channel,
@@ -15182,7 +15284,9 @@ function shouldOpenProgressStream(state) {
15182
15284
  return renderText({ ...state, footer: null }).trim() !== "";
15183
15285
  }
15184
15286
  function finalReplyState(progress, state) {
15185
- if (!progress.opened() || progress.abandoned()) return finalAnswerOnlyState(state);
15287
+ if (!progress.opened() || progress.abandoned() || streamOutlivedCardLifetime(progress)) {
15288
+ return finalAnswerOnlyState(state);
15289
+ }
15186
15290
  return {
15187
15291
  ...state,
15188
15292
  blocks: state.finalText ? [{ kind: "text", content: state.finalText, streaming: false }] : [],
@@ -15192,6 +15296,30 @@ function finalReplyState(progress, state) {
15192
15296
  errorMsg: void 0
15193
15297
  };
15194
15298
  }
15299
+ function scheduleProgressTerminalUpdate(channel, progress, state, scope, mode) {
15300
+ if (!streamOutlivedCardLifetime(progress) || renderText(state).trim() === "") return;
15301
+ void progress.settled.then(async (result) => {
15302
+ const messageId = result?.messageId;
15303
+ if (!messageId) return;
15304
+ try {
15305
+ const terminalState = {
15306
+ ...state,
15307
+ // Markdown never shows reasoning; a repair must preserve that boundary.
15308
+ reasoning: mode === "markdown" ? { content: "", active: false } : state.reasoning,
15309
+ blocks: state.terminal === "done" ? [...state.blocks, { kind: "text", content: "\u672C\u8F6E\u6267\u884C\u5DF2\u7ED3\u675F\u3002", streaming: false }] : state.blocks
15310
+ };
15311
+ await channel.updateCard(messageId, renderCard(terminalState));
15312
+ log.info("outbound", "progress-terminal-updated", { scope, messageId, terminal: state.terminal });
15313
+ } catch (err) {
15314
+ log.warn("outbound", "progress-terminal-update-failed", {
15315
+ scope,
15316
+ messageId,
15317
+ err: err instanceof Error ? err.message : String(err)
15318
+ });
15319
+ }
15320
+ }, () => {
15321
+ });
15322
+ }
15195
15323
  async function recallIfEmptyStreamedReply(channel, progress, finalState, scope) {
15196
15324
  if (!progress.opened()) return;
15197
15325
  if (progress.abandoned()) {
@@ -15651,11 +15779,11 @@ function parseJson2(text) {
15651
15779
  return void 0;
15652
15780
  }
15653
15781
  }
15654
- function isRecord3(v) {
15782
+ function isRecord4(v) {
15655
15783
  return Boolean(v) && typeof v === "object" && !Array.isArray(v);
15656
15784
  }
15657
15785
  function pickString(obj, keys, depth = 0) {
15658
- if (depth > 4 || !isRecord3(obj)) return void 0;
15786
+ if (depth > 4 || !isRecord4(obj)) return void 0;
15659
15787
  for (const key of keys) {
15660
15788
  const v = obj[key];
15661
15789
  if (typeof v === "string" && v.trim()) return v;
@@ -15667,7 +15795,7 @@ function pickString(obj, keys, depth = 0) {
15667
15795
  return void 0;
15668
15796
  }
15669
15797
  function findString(obj, re, depth = 0) {
15670
- if (depth > 4 || !isRecord3(obj)) return void 0;
15798
+ if (depth > 4 || !isRecord4(obj)) return void 0;
15671
15799
  for (const [k, v] of Object.entries(obj)) {
15672
15800
  if (typeof v === "string" && re.test(k) && v.trim()) return v;
15673
15801
  }
@@ -15680,8 +15808,8 @@ function findString(obj, re, depth = 0) {
15680
15808
  async function getUserAuthStatus(ctx, exec = defaultExec) {
15681
15809
  const r = await exec(["auth", "status", "--json"], larkCliEnv(ctx), 15e3);
15682
15810
  const json = parseJson2(r.stdout);
15683
- const user = isRecord3(json) && isRecord3(json.identities) ? json.identities.user : void 0;
15684
- if (!isRecord3(user)) return { loggedIn: false, scopes: [] };
15811
+ const user = isRecord4(json) && isRecord4(json.identities) ? json.identities.user : void 0;
15812
+ if (!isRecord4(user)) return { loggedIn: false, scopes: [] };
15685
15813
  const loggedIn = user.available === true && (user.tokenStatus === "valid" || user.status === "ready");
15686
15814
  const scopes = typeof user.scope === "string" ? user.scope.split(/\s+/).filter(Boolean) : [];
15687
15815
  return {
@@ -15718,7 +15846,7 @@ async function startDeviceLogin(ctx, scopes = LIST_CHAT_SCOPES, exec = defaultEx
15718
15846
  `\u65E0\u6CD5\u5F00\u59CB\u6388\u6743\uFF1A${r.stderr.trim() || r.stdout.trim() || "lark-cli auth login \u672A\u8FD4\u56DE\u9A8C\u8BC1\u94FE\u63A5"}`
15719
15847
  );
15720
15848
  }
15721
- const expiresIn = isRecord3(json) && typeof json.expiresIn === "number" ? json.expiresIn : isRecord3(json) && typeof json.expires_in === "number" ? json.expires_in : void 0;
15849
+ const expiresIn = isRecord4(json) && typeof json.expiresIn === "number" ? json.expiresIn : isRecord4(json) && typeof json.expires_in === "number" ? json.expires_in : void 0;
15722
15850
  return { verificationUrl, deviceCode, ...userCode ? { userCode } : {}, ...expiresIn ? { expiresIn } : {} };
15723
15851
  }
15724
15852
  async function completeDeviceLogin(ctx, deviceCode, exec = defaultExec) {
@@ -15736,7 +15864,7 @@ var DEFAULT_PAGE_SIZE = 8;
15736
15864
  function toChats(items) {
15737
15865
  const chats = [];
15738
15866
  for (const it of items) {
15739
- if (!isRecord3(it)) continue;
15867
+ if (!isRecord4(it)) continue;
15740
15868
  const id = typeof it.chat_id === "string" ? it.chat_id : typeof it.id === "string" ? it.id : "";
15741
15869
  if (!id) continue;
15742
15870
  const name = typeof it.name === "string" && it.name.trim() ? it.name : "(\u65E0\u540D\u7FA4)";
@@ -15747,7 +15875,7 @@ function toChats(items) {
15747
15875
  function parseChatsPage(r, prefix) {
15748
15876
  if (r.code !== 0) throw new Error(cliError(r, prefix));
15749
15877
  const json = parseJson2(r.stdout);
15750
- const data = isRecord3(json) && isRecord3(json.data) ? json.data : isRecord3(json) ? json : {};
15878
+ const data = isRecord4(json) && isRecord4(json.data) ? json.data : isRecord4(json) ? json : {};
15751
15879
  const hasMore = data.has_more === true;
15752
15880
  const pageToken = typeof data.page_token === "string" ? data.page_token : void 0;
15753
15881
  return {
@@ -15805,11 +15933,11 @@ async function addBotToChat(ctx, chatId, botAppId, exec = defaultExec) {
15805
15933
  3e4
15806
15934
  );
15807
15935
  const json = parseJson2(r.stdout);
15808
- const data = isRecord3(json) && isRecord3(json.data) ? json.data : isRecord3(json) ? json : {};
15809
- const invalid = extractArray(isRecord3(data) ? data.invalid_id_list : void 0);
15810
- const notExisted = extractArray(isRecord3(data) ? data.not_existed_id_list : void 0);
15811
- const pendingList = extractArray(isRecord3(data) ? data.pending_approval_id_list : void 0);
15812
- const inList = (arr) => arr.some((x) => typeof x === "string" ? x === botAppId : isRecord3(x) && x.id === botAppId);
15936
+ const data = isRecord4(json) && isRecord4(json.data) ? json.data : isRecord4(json) ? json : {};
15937
+ const invalid = extractArray(isRecord4(data) ? data.invalid_id_list : void 0);
15938
+ const notExisted = extractArray(isRecord4(data) ? data.not_existed_id_list : void 0);
15939
+ const pendingList = extractArray(isRecord4(data) ? data.pending_approval_id_list : void 0);
15940
+ const inList = (arr) => arr.some((x) => typeof x === "string" ? x === botAppId : isRecord4(x) && x.id === botAppId);
15813
15941
  if (r.code === 0 && (inList(invalid) || inList(notExisted))) {
15814
15942
  return {
15815
15943
  ok: false,
@@ -15827,11 +15955,11 @@ async function addBotToChat(ctx, chatId, botAppId, exec = defaultExec) {
15827
15955
  }
15828
15956
  function extractArray(v) {
15829
15957
  if (Array.isArray(v)) return v;
15830
- if (!isRecord3(v)) return [];
15958
+ if (!isRecord4(v)) return [];
15831
15959
  const keys = ["items", "chats", "list", "invalid_id_list", "not_existed_id_list", "pending_approval_id_list"];
15832
15960
  for (const container of [v, v.data]) {
15833
15961
  if (Array.isArray(container)) return container;
15834
- if (isRecord3(container)) {
15962
+ if (isRecord4(container)) {
15835
15963
  for (const key of keys) {
15836
15964
  if (Array.isArray(container[key])) return container[key];
15837
15965
  }
@@ -15879,7 +16007,7 @@ var defaultExec2 = (args, env) => new Promise((resolve3) => {
15879
16007
  resolve3({ code, stdout, stderr });
15880
16008
  });
15881
16009
  });
15882
- function isRecord4(v) {
16010
+ function isRecord5(v) {
15883
16011
  return Boolean(v) && typeof v === "object" && !Array.isArray(v);
15884
16012
  }
15885
16013
  function parseJson3(text) {
@@ -15906,13 +16034,13 @@ function classifyPreflight(payload) {
15906
16034
  requiredEvents: MEETING_REQUIRED_EVENTS,
15907
16035
  requiredScopes: MEETING_REQUIRED_SCOPES
15908
16036
  };
15909
- if (!isRecord4(payload)) {
16037
+ if (!isRecord5(payload)) {
15910
16038
  return { ...base, status: "unknown", message: "\u65E0\u6CD5\u89E3\u6790 lark-cli \u8F93\u51FA" };
15911
16039
  }
15912
16040
  if (payload.ok === true) {
15913
16041
  return { ...base, status: "ok", message: "\u5E94\u7528\u8EAB\u4EFD\u6743\u9650\u5DF2\u5C31\u7EEA" };
15914
16042
  }
15915
- const err = isRecord4(payload.error) ? payload.error : {};
16043
+ const err = isRecord5(payload.error) ? payload.error : {};
15916
16044
  const code = typeof err.code === "number" ? err.code : void 0;
15917
16045
  const subtype = typeof err.subtype === "string" ? err.subtype : "";
15918
16046
  const message = typeof err.message === "string" ? err.message : "\u6743\u9650\u68C0\u67E5\u5931\u8D25";
@@ -16783,7 +16911,7 @@ async function route(req, res, deps, url) {
16783
16911
  }
16784
16912
 
16785
16913
  // src/bridge/session/store.ts
16786
- import { readFile as readFile14 } from "fs/promises";
16914
+ import { readFile as readFile15 } from "fs/promises";
16787
16915
  var SessionStore = class {
16788
16916
  data = {};
16789
16917
  saving = Promise.resolve();
@@ -16794,7 +16922,7 @@ var SessionStore = class {
16794
16922
  }
16795
16923
  async load() {
16796
16924
  try {
16797
- const text = await readFile14(this.path, "utf8");
16925
+ const text = await readFile15(this.path, "utf8");
16798
16926
  const raw = JSON.parse(text);
16799
16927
  this.data = {};
16800
16928
  for (const [chatId, entry] of Object.entries(raw)) {
@@ -16907,7 +17035,7 @@ var SessionStore = class {
16907
17035
 
16908
17036
  // src/bridge/session/catalog.ts
16909
17037
  import { randomUUID as randomUUID4 } from "crypto";
16910
- import { open as open3, readFile as readFile15, rename as rename5, mkdir as mkdir16 } from "fs/promises";
17038
+ import { open as open3, readFile as readFile16, rename as rename5, mkdir as mkdir16 } from "fs/promises";
16911
17039
  import { dirname as dirname19 } from "path";
16912
17040
  var DEFAULT_MAX_ARCHIVED_AGE_MS = 90 * 24 * 60 * 60 * 1e3;
16913
17041
  var DEFAULT_MAX_ENTRIES_PER_SCOPE = 20;
@@ -16930,7 +17058,7 @@ var SessionCatalog = class {
16930
17058
  }
16931
17059
  async load() {
16932
17060
  try {
16933
- const raw = JSON.parse(await readFile15(this.path, "utf8"));
17061
+ const raw = JSON.parse(await readFile16(this.path, "utf8"));
16934
17062
  if (!Array.isArray(raw)) {
16935
17063
  this.data.clear();
16936
17064
  return;
@@ -17104,7 +17232,7 @@ function assertAgentIdentity(input) {
17104
17232
  }
17105
17233
 
17106
17234
  // src/bridge/workspace/store.ts
17107
- import { readFile as readFile16 } from "fs/promises";
17235
+ import { readFile as readFile17 } from "fs/promises";
17108
17236
  var WorkspaceStore = class {
17109
17237
  data = { chats: {}, named: {} };
17110
17238
  saving = Promise.resolve();
@@ -17114,7 +17242,7 @@ var WorkspaceStore = class {
17114
17242
  }
17115
17243
  async load() {
17116
17244
  try {
17117
- const text = await readFile16(this.path, "utf8");
17245
+ const text = await readFile17(this.path, "utf8");
17118
17246
  const parsed = JSON.parse(text);
17119
17247
  this.data = {
17120
17248
  chats: parsed.chats ?? {},