chatccc 0.2.302 → 0.2.303

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/README.md CHANGED
@@ -22,8 +22,8 @@ ChatCCC 把本地 AI 编程工具接入即时通讯软件。你可以在手机
22
22
  - **飞书体验更完整**:私聊可持续对话,`/new` 创建的一群一会话支持多任务并行,CardKit 卡片可流式更新。
23
23
  - **微信接入更轻**:不用创建飞书应用,启动后扫码即可在微信私聊里使用。
24
24
  - **多 Agent 切换**:`/new` 使用默认 Agent,也可以用 `/new claude`、`/new cursor`、`/new codex`、`/new ccc`、`/new dsh` 指定工具。
25
- - **群里能跑 git**:`/git status`、`/git pull`、`/git log` 会在当前会话工作目录执行,并把输出发回聊天窗口。
26
- - **飞书混合附件不丢失**:同一条富文本中的文字、图片、视频和文件按顺序传给 Agent;视频保留原附件下载信息,不把封面误当成原视频。附件信息不完整时会明确提示。视频和文件仍由 Agent 按需下载处理,不代表模型原生支持视频输入。
25
+ - **群里能跑 git**:`/git status`、`/git pull`、`/git log` 会在当前会话工作目录执行,并把输出发回聊天窗口。
26
+ - **飞书混合附件不丢失**:同一条富文本中的文字、图片、视频和文件按顺序传给 Agent;视频保留原附件下载信息,不把封面误当成原视频。附件信息不完整时会明确提示。视频和文件仍由 Agent 按需下载处理,不代表模型原生支持视频输入。
27
27
 
28
28
  ## 飞书和微信的差异
29
29
 
@@ -210,6 +210,14 @@ npm run dev
210
210
 
211
211
  如果你同时使用公司飞书和个人飞书,建议把个人账号放在另一个客户端里:安卓可用系统「应用双开」,iOS 可用 Lark。
212
212
 
213
+ #### 最终回复的表格汇总
214
+
215
+ 飞书中的 Agent 最终回复包含 Markdown 表格时,ChatCCC 会保留完整原回复,并额外合并发送一张原生「表格汇总」卡片。适用于 Claude、Codex、Cursor、CCC 和 DSH;生成过程、工具输出和代码块中的示例表格不会单独发卡,也不会调用模型重新概括数据。数字、单位、链接和空单元格按原内容保留。
216
+
217
+ 默认开启;如需关闭,在 `~/.chatccc/config.json` 中设置 `platforms.feishu.tableSummary: false` 并重新加载配置或重启。微信不发送这类补充卡片。
218
+
219
+ 受[飞书表格组件限制](https://open.feishu.cn/document/feishu-cards/card-json-v2-components/content-components/table),超过每卡 5 个表格、每表 50 列或消息大小预算时,会按行/列分段并标注编号,全部数据保留。单个单元格或表头过长时,改用标明位置的完整文本续页;客户端可能折叠较长单元格,可点击查看。补充卡片发送失败会记录日志,原回复仍可使用;为避免重连或结果不确定时重复发送,不自动重发补充卡片。若进程恰好在原回复成功后退出,补充卡片可能未发完。
220
+
213
221
  #### 微信 iLink(可选)
214
222
 
215
223
  微信模式不需要创建飞书应用。保持 `config.json` 里的 `platforms.ilink.enabled` 为 `true`(默认开启),启动 `chatccc` 后,终端会打印微信扫码登录二维码。
@@ -228,11 +236,11 @@ Claude Code、Cursor 和 Codex 需要对应的本地工具;CCC Agent 内置于
228
236
 
229
237
  #### CCC Agent
230
238
 
231
- CCC Agent 是 ChatCCC 内置的编程 Agent,不需要额外安装 CLI,开箱即用。在首次配置向导或 Web 管理页中启用后,填写 API Key、Base URL 和模型即可使用;它可以设为 `/new` 的默认 Agent,也可以通过 `/new ccc` 显式创建会话。
232
-
233
- CCC Agent 支持图片理解:飞书/微信发送的图片与独立 DeepCCC 的 Web/CLI 附件共用内核,可看多张截图、图表及本地 `read_image` 工具产物。支持 PNG/JPEG/WebP/GIF,每条最多 10 张、单图 20 MiB、图片合计 24 MiB。主模型支持视觉时直接传图;主模型不支持时,可在设置页填写“图片模型”(`ccc.visionModel`,如 `deepseek-flash`),先由它观察图片,再由主模型继续任务。留空跟随独立 DeepCCC 的 `visionModel`;两边都未配置则使用主模型原生视觉。图片模型复用当前 API Key/Base URL/协议,界面显示实际使用的模型;错误不会静默降级。历史保存附件引用,日志过滤图片编码。详见 [DeepCCC 图片与 CLI 用法](deepccc-agent/README.md)。
234
-
235
- 纯 CLI 用户可以运行 `cccagent --image "C:\截图\报错.png"` 后输入问题,或在运行中的交互终端等待回复结束后输入 `/image "图片路径"`,再发下一条问题。多图重复添加;一次性运行可用 `cccagent --stream-json --prompt "解释截图" --image "图片路径"`。`cccagent` 读取 `~/.deepccc/config.json` 或 `DEEPCCC_*` 环境变量。
239
+ CCC Agent 是 ChatCCC 内置的编程 Agent,不需要额外安装 CLI,开箱即用。在首次配置向导或 Web 管理页中启用后,填写 API Key、Base URL 和模型即可使用;它可以设为 `/new` 的默认 Agent,也可以通过 `/new ccc` 显式创建会话。
240
+
241
+ CCC Agent 支持图片理解:飞书/微信发送的图片与独立 DeepCCC 的 Web/CLI 附件共用内核,可看多张截图、图表及本地 `read_image` 工具产物。支持 PNG/JPEG/WebP/GIF,每条最多 10 张、单图 20 MiB、图片合计 24 MiB。主模型支持视觉时直接传图;主模型不支持时,可在设置页填写“图片模型”(`ccc.visionModel`,如 `deepseek-flash`),先由它观察图片,再由主模型继续任务。留空跟随独立 DeepCCC 的 `visionModel`;两边都未配置则使用主模型原生视觉。图片模型复用当前 API Key/Base URL/协议,界面显示实际使用的模型;错误不会静默降级。历史保存附件引用,日志过滤图片编码。详见 [DeepCCC 图片与 CLI 用法](deepccc-agent/README.md)。
242
+
243
+ 纯 CLI 用户可以运行 `cccagent --image "C:\截图\报错.png"` 后输入问题,或在运行中的交互终端等待回复结束后输入 `/image "图片路径"`,再发下一条问题。多图重复添加;一次性运行可用 `cccagent --stream-json --prompt "解释截图" --image "图片路径"`。`cccagent` 读取 `~/.deepccc/config.json` 或 `DEEPCCC_*` 环境变量。
236
244
 
237
245
  CCC Agent 支持**协作式让位**:任务运行期间你可以继续在群里发消息,ChatCCC 会在 Agent 的每个模型步骤边界把新消息注入当前任务,不打断正在执行的工具步骤、不新开一轮对话。已完成的中间工作会保留,Agent 收到插话后会调整后续方向。运行中的消息进入独立的注入队列(深度 50),与整轮排队(深度 1)分离。飞书中每条消息实际注入后,机器人会发送一条最多 200 字的回执,冻结注入前的过程卡片,并用新的“生成中”卡片展示后续过程。
238
246
 
@@ -4,7 +4,7 @@
4
4
  "appSecret": ""
5
5
  },
6
6
  "platforms": {
7
- "feishu": { "enabled": true, "platformType": "feishu" },
7
+ "feishu": { "enabled": true, "platformType": "feishu", "tableSummary": true },
8
8
  "ilink": { "enabled": true, "reuseTokenOnStart": true }
9
9
  },
10
10
  "webUi": {
@@ -55,9 +55,9 @@
55
55
  "defaultAgent": false,
56
56
  "DEEPSEEK_API_KEY": "",
57
57
  "DEEPSEEK_BASE_URL": "https://api.deepseek.com/v1",
58
- "model": "deepseek-v4-pro",
59
- "subModel": "",
60
- "visionModel": "deepseek-flash",
58
+ "model": "deepseek-v4-pro",
59
+ "subModel": "",
60
+ "visionModel": "deepseek-flash",
61
61
  "alternativeModel": "",
62
62
  "effort": "",
63
63
  "maxOutputTokens": null,
@@ -163,11 +163,11 @@ Web UI 支持新建、恢复、重命名和删除多会话,多个会话可以
163
163
 
164
164
  模型文本、reasoning 心跳和工具事件通过 SSE 实时更新。每轮消息按真实发生顺序持久化和回放,因此刷新后仍会保持“阶段说明 → 工具调用 → 后续结论”的交错时间线;旧版会话没有顺序数据时,会兼容显示为“工具调用 → 最终回答”。每次工具调用与对应结果合并成一张卡片,折叠态显示 emoji、工具名、状态和关键参数;展开后调用参数默认保留前 8/后 4 行,工具结果保留前 12/后 6 行,省略内容可继续展开。工具卡及省略行的展开状态保存在当前浏览器标签页的 `sessionStorage`,持续生成、切换会话和刷新页面均不会自动收起。消息正文支持标题、表格、列表、引用、链接和代码块等常用 Markdown。
165
165
 
166
- 图片会转换成模型可见的原生视觉输入。Web 支持选择、粘贴和拖拽 PNG/JPEG/WebP/GIF;CLI 可用 `--image` 或交互命令 `/image`。每条消息最多 10 张、单图最大 20 MiB、图片合计最大 24 MiB,单边最多 8192 像素;超限时提示分图或缩小,保留原图细节。附件复制到 `~/.deepccc/attachments/<session-id>/`,聊天历史只保存引用,raw 日志过滤图片编码。删除 Web 会话时附件一并清理。
167
-
168
- 默认由当前模型直接看图。若主模型不支持视觉,可在 API 设置中指定 `visionModel`(如 `deepseek-flash`),或设置 `DEEPCCC_VISION_MODEL` / CLI `--vision-model`;该模型使用同一 API 协议、Base URL 和 Key,先分析图片,再由主模型结合观察继续任务。界面及 JSONL 会显示实际图片模型和模式。未配置图片模型的 `deepseek-v4-pro` 收图会明确报错;其他兼容模型需服务端支持图像,接口错误不会降级成“假装看过”。官方 DeepSeek 端点的旧 Flash 名称仅在视觉请求中映射到当前 `deepseek-flash`,自定义网关保留用户配置的名称。
169
-
170
- Agent 可用 `read_image` 查看本地截图、图表或工具产物,并通过 `question` 指定需要观察的细节;`present_file` 用于把图片展示给用户。后续追问会按预算重新加载近期图片;较早图片保留路径供 `read_image` 重新查看。独立图片模型的观察按原文问题、模型、端点与图片内容哈希缓存;细节追问可重新调用 `read_image`。压缩后的摘要应保留重要图片引用,缺失或损坏图片会明确报错。本版本支持图片输入,不包含音频、视频或 PDF 原生输入。
166
+ 图片会转换成模型可见的原生视觉输入。Web 支持选择、粘贴和拖拽 PNG/JPEG/WebP/GIF;CLI 可用 `--image` 或交互命令 `/image`。每条消息最多 10 张、单图最大 20 MiB、图片合计最大 24 MiB,单边最多 8192 像素;超限时提示分图或缩小,保留原图细节。附件复制到 `~/.deepccc/attachments/<session-id>/`,聊天历史只保存引用,raw 日志过滤图片编码。删除 Web 会话时附件一并清理。
167
+
168
+ 默认由当前模型直接看图。若主模型不支持视觉,可在 API 设置中指定 `visionModel`(如 `deepseek-flash`),或设置 `DEEPCCC_VISION_MODEL` / CLI `--vision-model`;该模型使用同一 API 协议、Base URL 和 Key,先分析图片,再由主模型结合观察继续任务。界面及 JSONL 会显示实际图片模型和模式。未配置图片模型的 `deepseek-v4-pro` 收图会明确报错;其他兼容模型需服务端支持图像,接口错误不会降级成“假装看过”。官方 DeepSeek 端点的旧 Flash 名称仅在视觉请求中映射到当前 `deepseek-flash`,自定义网关保留用户配置的名称。
169
+
170
+ Agent 可用 `read_image` 查看本地截图、图表或工具产物,并通过 `question` 指定需要观察的细节;`present_file` 用于把图片展示给用户。后续追问会按预算重新加载近期图片;较早图片保留路径供 `read_image` 重新查看。独立图片模型的观察按原文问题、模型、端点与图片内容哈希缓存;细节追问可重新调用 `read_image`。压缩后的摘要应保留重要图片引用,缺失或损坏图片会明确报错。本版本支持图片输入,不包含音频、视频或 PDF 原生输入。
171
171
 
172
172
  API 设置采用单一 Provider 配置,支持 OpenAI-compatible 与 Anthropic Messages。完整 API Key 只保存在本机 `~/.deepccc/config.json`,浏览器读取设置时仅返回掩码。危险命令会在会话中暂停并请求“拒绝、允许一次、本会话允许、永久允许”,浏览器断开或审批超时默认拒绝。
173
173
 
@@ -244,22 +244,22 @@ deepccc-cli --provider anthropic --base-url https://api.example.com --api-key "$
244
244
  deepccc-cli --cwd /path/to/project
245
245
  ```
246
246
 
247
- 附加一张或多张本地图片(重复传入 `--image`;路径含空格时加引号):
247
+ 附加一张或多张本地图片(重复传入 `--image`;路径含空格时加引号):
248
248
 
249
249
  ```bash
250
- deepccc-cli --image ./error.png --image ./expected.webp
251
- ```
252
-
253
- 启动后再加图:输入 `/image "C:\截图\报错截图.png"`,看到“图片已加入下一条消息”后输入问题并回车。多图重复 `/image`;相对路径按会话工作目录(`--cwd`)解析。该命令在当前回复结束后使用。启动时的 `--image` 也只加入队列,随后输入问题发送。
254
-
255
- 脚本或纯命令模式可直接发送图片并获取 JSONL:
256
-
257
- ```bash
258
- deepccc-cli --model deepseek-flash --stream-json --prompt "解释截图里的错误" --image "./error screenshot.png"
259
- deepccc-cli --model deepseek-v4-pro --vision-model deepseek-flash --stream-json --prompt "对比两张图" --image ./before.png --image ./after.png
260
- ```
261
-
262
- 安装 ChatCCC 后提供的 `cccagent` 使用同一 CLI:将上述 `deepccc-cli` 换成 `cccagent` 即可。它读取 `~/.deepccc/config.json`、`DEEPCCC_*` 环境变量或命令行参数;ChatCCC 机器人里的 API 配置不会自动改写独立 CLI 配置。聊天窗口的图片粘贴/拖拽属于 Web 功能,纯终端请使用文件路径。
250
+ deepccc-cli --image ./error.png --image ./expected.webp
251
+ ```
252
+
253
+ 启动后再加图:输入 `/image "C:\截图\报错截图.png"`,看到“图片已加入下一条消息”后输入问题并回车。多图重复 `/image`;相对路径按会话工作目录(`--cwd`)解析。该命令在当前回复结束后使用。启动时的 `--image` 也只加入队列,随后输入问题发送。
254
+
255
+ 脚本或纯命令模式可直接发送图片并获取 JSONL:
256
+
257
+ ```bash
258
+ deepccc-cli --model deepseek-flash --stream-json --prompt "解释截图里的错误" --image "./error screenshot.png"
259
+ deepccc-cli --model deepseek-v4-pro --vision-model deepseek-flash --stream-json --prompt "对比两张图" --image ./before.png --image ./after.png
260
+ ```
261
+
262
+ 安装 ChatCCC 后提供的 `cccagent` 使用同一 CLI:将上述 `deepccc-cli` 换成 `cccagent` 即可。它读取 `~/.deepccc/config.json`、`DEEPCCC_*` 环境变量或命令行参数;ChatCCC 机器人里的 API 配置不会自动改写独立 CLI 配置。聊天窗口的图片粘贴/拖拽属于 Web 功能,纯终端请使用文件路径。
263
263
 
264
264
  恢复当前工作目录最近一次会话:
265
265
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deepccc",
3
- "version": "0.2.27",
3
+ "version": "0.2.27",
4
4
  "description": "A lightweight coding agent with OpenAI-compatible and Anthropic Messages API support.",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -466,6 +466,7 @@ function loadConfig() {
466
466
  platformType: normalizePlatformType(typeof parsed.platforms?.feishu === "object"
467
467
  ? String(parsed.platforms.feishu.platformType ?? "feishu")
468
468
  : "feishu"),
469
+ tableSummary: parsed.platforms?.feishu?.tableSummary !== false,
469
470
  },
470
471
  ilink: {
471
472
  enabled: typeof parsed.platforms?.ilink === "object"
@@ -1314,8 +1314,12 @@ export async function sendCardReply(token, chatId, title, content, template = "g
1314
1314
  return false;
1315
1315
  }
1316
1316
  }
1317
- export async function sendRawCard(token, chatId, cardJson) {
1318
- const safeJson = applyPrivacy(cardJson);
1317
+ export async function sendRawCard(token, chatId, cardJson, options) {
1318
+ // Table summaries sanitize before JSON encoding and size splitting. Do not
1319
+ // apply replacement rules twice (or inject unescaped quotes into their JSON).
1320
+ const safeJson = options?.privacyApplied ? cardJson : applyPrivacy(cardJson);
1321
+ const controller = new AbortController();
1322
+ const timer = setTimeout(() => controller.abort(), 15_000);
1319
1323
  try {
1320
1324
  const resp = await fetch(`${BASE_URL}/im/v1/messages?receive_id_type=chat_id`, {
1321
1325
  method: "POST",
@@ -1324,6 +1328,7 @@ export async function sendRawCard(token, chatId, cardJson) {
1324
1328
  "Content-Type": "application/json",
1325
1329
  },
1326
1330
  body: JSON.stringify({ receive_id: chatId, msg_type: "interactive", content: safeJson }),
1331
+ signal: controller.signal,
1327
1332
  });
1328
1333
  const data = (await resp.json().catch(() => ({})));
1329
1334
  if (data.code !== 0) {
@@ -1337,6 +1342,9 @@ export async function sendRawCard(token, chatId, cardJson) {
1337
1342
  console.error(`[${ts()}] [SEND] raw_card FAIL: chatId=${chatId} ${err.message}`);
1338
1343
  return false;
1339
1344
  }
1345
+ finally {
1346
+ clearTimeout(timer);
1347
+ }
1340
1348
  }
1341
1349
  // 重启后,向最后有发言的会话发送 "已重启" 卡片(基于 chat_logs 的文件修改时间)
1342
1350
  export async function sendRestartCard(token) {
@@ -0,0 +1,37 @@
1
+ import { buildTableSummaryCards } from "./final-table-card.js";
2
+ /** Serialize all final-delivery entry points for a turn, including display and fallback paths. */
3
+ export function createFinalReplyDelivery(deps) {
4
+ const inFlight = new Map();
5
+ return function deliver(platform, chatId, sessionId, turn, text) {
6
+ const key = JSON.stringify([sessionId, turn]);
7
+ const pending = inFlight.get(key);
8
+ if (pending)
9
+ return pending;
10
+ const task = (async () => {
11
+ if (await deps.isSent(sessionId, turn))
12
+ return true;
13
+ const sent = await platform.sendText(chatId, text).then(ok => ok !== false).catch(() => false);
14
+ if (!sent)
15
+ return false;
16
+ // Persist the original before supplementary delivery: a summary failure must
17
+ // never cause the original answer or already accepted summaries to be resent.
18
+ await deps.markSent(sessionId, turn);
19
+ if (platform.kind === "feishu" && deps.enabled()) {
20
+ try {
21
+ const cards = buildTableSummaryCards(deps.sanitize(text));
22
+ for (const [index, json] of cards.entries()) {
23
+ const ok = await platform.sendRawCard(chatId, json, { privacyApplied: true }).then(result => result !== false).catch(() => false);
24
+ if (!ok)
25
+ deps.warn(`table summary delivery failed: session=${sessionId} turn=${turn} part=${index + 1}/${cards.length}; original retained`);
26
+ }
27
+ }
28
+ catch {
29
+ deps.warn(`table summary preparation failed: session=${sessionId} turn=${turn}; original retained`);
30
+ }
31
+ }
32
+ return true;
33
+ })().finally(() => { inFlight.delete(key); });
34
+ inFlight.set(key, task);
35
+ return task;
36
+ };
37
+ }
@@ -0,0 +1,175 @@
1
+ // Leave headroom below the IM message limit, counting the JSON-escaped content too.
2
+ export const TABLE_CARD_BYTE_LIMIT = 24_000;
3
+ function cells(line) {
4
+ const text = line.trim();
5
+ const parts = [];
6
+ let cell = "";
7
+ let ticks = 0;
8
+ let separators = 0;
9
+ let lastWasSeparator = false;
10
+ for (let i = 0; i < text.length; i++) {
11
+ const ch = text[i];
12
+ if (ch === "\\" && i + 1 < text.length) {
13
+ // Escaped pipes are content. Preserve all other Markdown escapes.
14
+ const next = text[++i];
15
+ cell += next === "|" ? "|" : "\\" + next;
16
+ lastWasSeparator = false;
17
+ }
18
+ else if (ch === "`") {
19
+ let end = i + 1;
20
+ while (text[end] === "`")
21
+ end++;
22
+ const count = end - i;
23
+ if (ticks === count)
24
+ ticks = 0;
25
+ else if (!ticks && text.indexOf("`".repeat(count), end) >= 0)
26
+ ticks = count;
27
+ cell += text.slice(i, end);
28
+ i = end - 1;
29
+ lastWasSeparator = false;
30
+ }
31
+ else if (ch === "|" && !ticks) {
32
+ parts.push(cell.trim());
33
+ cell = "";
34
+ separators++;
35
+ lastWasSeparator = true;
36
+ }
37
+ else {
38
+ cell += ch;
39
+ lastWasSeparator = false;
40
+ }
41
+ }
42
+ if (!separators)
43
+ return null;
44
+ parts.push(cell.trim());
45
+ if (text.startsWith("|"))
46
+ parts.shift();
47
+ if (lastWasSeparator)
48
+ parts.pop();
49
+ return parts.length ? parts : null;
50
+ }
51
+ export function extractMarkdownTables(text) {
52
+ const lines = text.replace(/\r\n?/g, "\n").split("\n").map(line => line.replace(/^(?: {0,3}> ?)+/, ""));
53
+ const usable = [];
54
+ let fence;
55
+ for (const line of lines) {
56
+ const match = /^ {0,3}(`{3,}|~{3,})(.*)$/.exec(line);
57
+ if (fence) {
58
+ usable.push(false);
59
+ if (match && match[1][0] === fence.char && match[1].length >= fence.length && !match[2].trim())
60
+ fence = undefined;
61
+ }
62
+ else if (match) {
63
+ fence = { char: match[1][0], length: match[1].length };
64
+ usable.push(false);
65
+ }
66
+ else
67
+ usable.push(!/^( {4}|\t)/.test(line));
68
+ }
69
+ const tables = [];
70
+ let heading = "";
71
+ for (let i = 0; i + 1 < lines.length; i++) {
72
+ if (!usable[i])
73
+ continue;
74
+ const h = /^ {0,3}#{1,6}\s+(.+?)(?:\s+#+)?\s*$/.exec(lines[i]);
75
+ if (h)
76
+ heading = h[1];
77
+ if (!usable[i + 1])
78
+ continue;
79
+ const headers = cells(lines[i]);
80
+ const separator = cells(lines[i + 1]);
81
+ if (!headers || !separator || headers.length !== separator.length || !separator.every(c => /^:?-+:?$/.test(c)))
82
+ continue;
83
+ const align = separator.map((c) => c.endsWith(":") ? c.startsWith(":") ? "center" : "right" : "left");
84
+ const rows = [];
85
+ let end = i + 2;
86
+ while (end < lines.length && usable[end] && lines[end].trim()) {
87
+ const row = cells(lines[end]);
88
+ if (!row)
89
+ break;
90
+ // A new header + delimiter starts a separate adjacent table.
91
+ const next = usable[end + 1] ? cells(lines[end + 1] ?? "") : null;
92
+ if (next?.length === row.length && next.every(c => /^:?-+:?$/.test(c)))
93
+ break;
94
+ rows.push(row);
95
+ end++;
96
+ }
97
+ const width = Math.max(headers.length, ...rows.map(r => r.length));
98
+ while (headers.length < width) {
99
+ headers.push(`列 ${headers.length + 1}(无表头)`);
100
+ align.push("left");
101
+ }
102
+ for (const row of rows)
103
+ while (row.length < width)
104
+ row.push("");
105
+ tables.push({ title: heading, headers, align, rows });
106
+ i = end - 1;
107
+ }
108
+ return tables;
109
+ }
110
+ function card(elements, title) {
111
+ return { schema: "2.0", config: { update_multi: true }, header: { template: "blue", title: { tag: "plain_text", content: title } }, body: { elements } };
112
+ }
113
+ function transportBytes(elements) {
114
+ return Buffer.byteLength(JSON.stringify({ content: JSON.stringify(card(elements, "表格汇总(999999/999999)")) }), "utf8");
115
+ }
116
+ const labelElement = (content) => ({ tag: "div", text: { tag: "plain_text", content } });
117
+ /** Split dimensions first; a single huge cell falls back to labelled plain-text continuations. */
118
+ function* tableParts(table, number, r0 = 0, r1 = table.rows.length, c0 = 0, c1 = table.headers.length) {
119
+ if (c1 - c0 > 50) {
120
+ for (let col = c0; col < c1; col += 50)
121
+ yield* tableParts(table, number, r0, r1, col, Math.min(col + 50, c1));
122
+ return;
123
+ }
124
+ const label = `表格 ${number}${table.title ? ` · ${table.title.slice(0, 160)}` : ""}(行 ${r1 ? r0 + 1 : 0}–${r1}/${table.rows.length},列 ${c0 + 1}–${c1}/${table.headers.length})`;
125
+ const elements = [labelElement(label), {
126
+ tag: "table", page_size: 10, row_height: "auto", row_max_height: "200px", freeze_first_column: true,
127
+ header_style: { bold: true, background_style: "grey", lines: 2 },
128
+ columns: table.headers.slice(c0, c1).map((h, i) => ({ name: `c${i + c0}`, display_name: h, data_type: "markdown", width: "auto", vertical_align: "top", horizontal_align: table.align[i + c0] })),
129
+ rows: table.rows.slice(r0, r1).map(row => Object.fromEntries(row.slice(c0, c1).map((v, i) => [`c${i + c0}`, v]))),
130
+ }];
131
+ if (transportBytes(elements) <= TABLE_CARD_BYTE_LIMIT) {
132
+ yield { elements, tables: 1 };
133
+ return;
134
+ }
135
+ if (r1 - r0 > 1) {
136
+ const mid = Math.floor((r0 + r1) / 2);
137
+ yield* tableParts(table, number, r0, mid, c0, c1);
138
+ yield* tableParts(table, number, mid, r1, c0, c1);
139
+ }
140
+ else if (c1 - c0 > 1) {
141
+ const mid = Math.floor((c0 + c1) / 2);
142
+ yield* tableParts(table, number, r0, r1, c0, mid);
143
+ yield* tableParts(table, number, r0, r1, mid, c1);
144
+ }
145
+ else {
146
+ // Plain text does not break a very long Markdown link into invalid link markup.
147
+ const full = `${table.headers[c0]}\n${r1 ? table.rows[r0][c0] : ""}`;
148
+ const chars = Array.from(full);
149
+ for (let start = 0; start < chars.length; start += 2500) {
150
+ yield { tables: 0, elements: [
151
+ { tag: "markdown", content: `${label} · 超长单元格,完整文本续页 ${Math.floor(start / 2500) + 1}` },
152
+ labelElement(chars.slice(start, start + 2500).join("")),
153
+ ] };
154
+ }
155
+ }
156
+ }
157
+ export function buildTableSummaryCards(text) {
158
+ const groups = [];
159
+ let elements = [];
160
+ let tableCount = 0;
161
+ for (const [index, table] of extractMarkdownTables(text).entries()) {
162
+ for (const part of tableParts(table, index + 1)) {
163
+ if (elements.length && (tableCount + part.tables > 5 || elements.length + part.elements.length > 180 || transportBytes([...elements, ...part.elements]) > TABLE_CARD_BYTE_LIMIT)) {
164
+ groups.push(elements);
165
+ elements = [];
166
+ tableCount = 0;
167
+ }
168
+ elements.push(...part.elements);
169
+ tableCount += part.tables;
170
+ }
171
+ }
172
+ if (elements.length)
173
+ groups.push(elements);
174
+ return groups.map((group, i) => JSON.stringify(card(group, groups.length > 1 ? `表格汇总(${i + 1}/${groups.length})` : "表格汇总")));
175
+ }
package/dist/src/index.js CHANGED
@@ -69,8 +69,8 @@ function createFeishuAdapter() {
69
69
  async sendCard(chatId, title, content, template) {
70
70
  return sendCardReply(await auth(), chatId, title, content, template);
71
71
  },
72
- async sendRawCard(chatId, cardJson) {
73
- return sendRawCard(await auth(), chatId, cardJson);
72
+ async sendRawCard(chatId, cardJson, options) {
73
+ return sendRawCard(await auth(), chatId, cardJson, options);
74
74
  },
75
75
  // ---- 群聊管理 ----
76
76
  async createGroup(name, userIds) {
@@ -16,6 +16,8 @@ import { killProcessTree } from "./adapters/proc-tree-kill.js";
16
16
  import { resourceMonitor, registerProcess, unregisterProcess } from "./adapters/resource-monitor.js";
17
17
  import { buildImSkillsPromptCached, exportSkillSubDocs, sessionImSkillsCacheDir, } from "./im-skills.js";
18
18
  import { clearAgentCapabilityGrants, issueAgentCapabilityGrant, } from "./agent-capability-grants.js";
19
+ import { createFinalReplyDelivery } from "./final-reply-delivery.js";
20
+ import { applyPrivacy } from "./privacy.js";
19
21
  import { hasResponseStalled, observeResponseProgress } from "./response-stall.js";
20
22
  import { classifyTerminalError, formatTerminalErrorNotice, formatTerminalErrorReason, } from "./terminal-error.js";
21
23
  import { MAX_PROCESSED, clearFeishuMessageLedgerMemory, processedMessages, } from "./feishu-message-ingress.js";
@@ -30,12 +32,16 @@ function compressWechatDisplayText(text) {
30
32
  import { readStreamState, writeStreamState, createEmptyStreamState, isFinalReplySentForTurn, markFinalReplySent, } from "./stream-state.js";
31
33
  import { addCardToTurn, finalizeTurnCards, markCardDone } from "./turn-cards.js";
32
34
  import { bindChatToSession, unbindChatFromSession, getChatsForSession, activePrompts, displayCards, unifiedDisplayLoopHandle, setUnifiedDisplayLoopHandle, rebuildSessionChatsFromRegistry, recordLastActiveChat, getLastActiveChat, pickDisplayChat, dequeueMessage, consumeQueuedMessage, cancelQueuedMessage, shiftInjection, unshiftInjection, drainRemainingInjections, clearInjections, setQueuePreservedChat, consumeQueuePreservedChat, markSessionFinalizing, clearSessionFinalizing, reserveAutoRecovery, consumeAutoRecoveryReservation, cancelAutoRecoveryReservation, hasAutoRecoveryReservation, hasPendingInjection, } from "./session-chat-binding.js";
33
- async function sendFinalReplyTextOnce(platform, chatId, sessionId, turnCount, text) {
34
- const sent = await platform.sendText(chatId, text).then((ok) => ok !== false).catch(() => false);
35
- if (sent)
36
- await markFinalReplySent(sessionId, turnCount);
37
- return sent;
38
- }
35
+ const sendFinalReplyTextOnce = createFinalReplyDelivery({
36
+ isSent: async (sessionId, turnCount) => {
37
+ const state = await readStreamState(sessionId);
38
+ return state?.turnCount === turnCount && isFinalReplySentForTurn(state);
39
+ },
40
+ markSent: (sessionId, turnCount) => markFinalReplySent(sessionId, turnCount),
41
+ enabled: () => config.platforms.feishu.tableSummary !== false,
42
+ sanitize: applyPrivacy,
43
+ warn: message => console.warn(`[${ts()}] [FINAL-TABLE] ${message}`),
44
+ });
39
45
  async function createVisibleProgressCard(platform, chatId, sessionId, turnCount, notifyFailureText, headerTitle = "正在启动 Agent · 0秒") {
40
46
  for (let attempt = 1; attempt <= 2; attempt++) {
41
47
  let cardId = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chatccc",
3
- "version": "0.2.302",
3
+ "version": "0.2.303",
4
4
  "description": "Feishu bot bridge for Claude Code",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",