chatccc 0.2.306 → 0.2.308
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 +24 -20
- package/config.sample.json +4 -4
- package/deepccc-agent/README.md +23 -5
- package/deepccc-agent/package.json +1 -1
- package/dist/deepccc-agent/src/cli.js +11 -0
- package/dist/deepccc-agent/src/context.js +26 -12
- package/dist/deepccc-agent/src/file-tools.js +70 -9
- package/dist/deepccc-agent/src/index.js +59 -40
- package/dist/deepccc-agent/src/instruction-replay.js +91 -0
- package/dist/deepccc-agent/src/model-tool-view.js +20 -0
- package/dist/deepccc-agent/src/progress/reducer.js +1 -0
- package/dist/deepccc-agent/src/project-instructions.js +71 -0
- package/dist/deepccc-agent/src/tool-argument-artifacts.js +58 -0
- package/dist/deepccc-agent/src/tool-argument-replay.js +107 -0
- package/dist/deepccc-agent/src/turn-context.js +189 -59
- package/dist/deepccc-agent/src/web-page.js +6 -6
- package/dist/src/format-message.js +75 -41
- package/dist/src/litellm-proxy.js +1 -1
- package/dist/src/progress/reducer.js +1 -0
- package/dist/src/web-ui.js +18 -18
- package/package.json +77 -77
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
|
-
-
|
|
25
|
+
- **群里能跑 git**:`/git status`、`/git pull`、`/git log` 会在当前会话工作目录执行,并把输出发回聊天窗口。
|
|
26
|
+
- **飞书混合附件不丢失**:同一条富文本中的标题、文字、图片、视频和文件传给 Agent,兼容正文为空但标题和顶层 `files` 有内容的组合消息;保留正文顺序,顶层附件按原顺序补在正文后,并按文件 key 避免与内联附件重复。正文为空时兼容 `content_v2`,无法识别的富文本给出明确提示,不再静默忽略。视频保留原附件下载信息,不把封面误当成原视频。附件信息不完整时会明确提示。视频和文件仍由 Agent 按需下载处理,不代表模型原生支持视频输入。
|
|
27
27
|
|
|
28
28
|
## 飞书和微信的差异
|
|
29
29
|
|
|
@@ -208,17 +208,17 @@ npm run dev
|
|
|
208
208
|
5. 创建应用版本并发布(企业内部可用即可)。
|
|
209
209
|
6. 在「凭证与基础信息」复制 **App ID** 和 **App Secret**,填入本地 Web 配置向导或 `config.json`。
|
|
210
210
|
|
|
211
|
-
如果你同时使用公司飞书和个人飞书,建议把个人账号放在另一个客户端里:安卓可用系统「应用双开」,iOS 可用 Lark。
|
|
212
|
-
|
|
213
|
-
#### 最终回复的表格汇总
|
|
214
|
-
|
|
215
|
-
飞书中的 Agent 最终回复包含 Markdown 表格时,ChatCCC 会保留完整原回复,并额外合并发送一张原生「表格汇总」卡片。适用于 Claude、Codex、Cursor、CCC 和 DSH;生成过程、工具输出和代码块中的示例表格不会单独发卡,也不会调用模型重新概括数据。数字、单位、链接和空单元格按原内容保留。
|
|
216
|
-
|
|
217
|
-
默认开启;如需关闭,在 `~/.chatccc/config.json` 中设置 `platforms.feishu.tableSummary: false` 并重新加载配置或重启。微信不发送这类补充卡片。
|
|
218
|
-
|
|
219
|
-
汇总表格不冻结首列,所有列一起横向滚动,避免手机端表头换行时冻结区域与其余列出现纵向偏移;长名称仍允许自动换行。升级只影响新生成的卡片,历史卡片不会自动重排。
|
|
220
|
-
|
|
221
|
-
受[飞书表格组件限制](https://open.feishu.cn/document/feishu-cards/card-json-v2-components/content-components/table),超过每卡 5 个表格、每表 50 列或消息大小预算时,会按行/列分段并标注编号,全部数据保留。单个单元格或表头过长时,改用标明位置的完整文本续页;客户端可能折叠较长单元格,可点击查看。补充卡片发送失败会记录日志,原回复仍可使用;为避免重连或结果不确定时重复发送,不自动重发补充卡片。若进程恰好在原回复成功后退出,补充卡片可能未发完。
|
|
211
|
+
如果你同时使用公司飞书和个人飞书,建议把个人账号放在另一个客户端里:安卓可用系统「应用双开」,iOS 可用 Lark。
|
|
212
|
+
|
|
213
|
+
#### 最终回复的表格汇总
|
|
214
|
+
|
|
215
|
+
飞书中的 Agent 最终回复包含 Markdown 表格时,ChatCCC 会保留完整原回复,并额外合并发送一张原生「表格汇总」卡片。适用于 Claude、Codex、Cursor、CCC 和 DSH;生成过程、工具输出和代码块中的示例表格不会单独发卡,也不会调用模型重新概括数据。数字、单位、链接和空单元格按原内容保留。
|
|
216
|
+
|
|
217
|
+
默认开启;如需关闭,在 `~/.chatccc/config.json` 中设置 `platforms.feishu.tableSummary: false` 并重新加载配置或重启。微信不发送这类补充卡片。
|
|
218
|
+
|
|
219
|
+
汇总表格不冻结首列,所有列一起横向滚动,避免手机端表头换行时冻结区域与其余列出现纵向偏移;长名称仍允许自动换行。升级只影响新生成的卡片,历史卡片不会自动重排。
|
|
220
|
+
|
|
221
|
+
受[飞书表格组件限制](https://open.feishu.cn/document/feishu-cards/card-json-v2-components/content-components/table),超过每卡 5 个表格、每表 50 列或消息大小预算时,会按行/列分段并标注编号,全部数据保留。单个单元格或表头过长时,改用标明位置的完整文本续页;客户端可能折叠较长单元格,可点击查看。补充卡片发送失败会记录日志,原回复仍可使用;为避免重连或结果不确定时重复发送,不自动重发补充卡片。若进程恰好在原回复成功后退出,补充卡片可能未发完。
|
|
222
222
|
|
|
223
223
|
#### 微信 iLink(可选)
|
|
224
224
|
|
|
@@ -238,11 +238,11 @@ Claude Code、Cursor 和 Codex 需要对应的本地工具;CCC Agent 内置于
|
|
|
238
238
|
|
|
239
239
|
#### CCC Agent
|
|
240
240
|
|
|
241
|
-
CCC Agent 是 ChatCCC 内置的编程 Agent,不需要额外安装 CLI,开箱即用。在首次配置向导或 Web 管理页中启用后,填写 API Key、Base URL 和模型即可使用;它可以设为 `/new` 的默认 Agent,也可以通过 `/new ccc` 显式创建会话。
|
|
242
|
-
|
|
243
|
-
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)。
|
|
244
|
-
|
|
245
|
-
纯 CLI 用户可以运行 `cccagent --image "C:\截图\报错.png"` 后输入问题,或在运行中的交互终端等待回复结束后输入 `/image "图片路径"`,再发下一条问题。多图重复添加;一次性运行可用 `cccagent --stream-json --prompt "解释截图" --image "图片路径"`。`cccagent` 读取 `~/.deepccc/config.json` 或 `DEEPCCC_*` 环境变量。
|
|
241
|
+
CCC Agent 是 ChatCCC 内置的编程 Agent,不需要额外安装 CLI,开箱即用。在首次配置向导或 Web 管理页中启用后,填写 API Key、Base URL 和模型即可使用;它可以设为 `/new` 的默认 Agent,也可以通过 `/new ccc` 显式创建会话。
|
|
242
|
+
|
|
243
|
+
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)。
|
|
244
|
+
|
|
245
|
+
纯 CLI 用户可以运行 `cccagent --image "C:\截图\报错.png"` 后输入问题,或在运行中的交互终端等待回复结束后输入 `/image "图片路径"`,再发下一条问题。多图重复添加;一次性运行可用 `cccagent --stream-json --prompt "解释截图" --image "图片路径"`。`cccagent` 读取 `~/.deepccc/config.json` 或 `DEEPCCC_*` 环境变量。
|
|
246
246
|
|
|
247
247
|
CCC Agent 支持**协作式让位**:任务运行期间你可以继续在群里发消息,ChatCCC 会在 Agent 的每个模型步骤边界把新消息注入当前任务,不打断正在执行的工具步骤、不新开一轮对话。已完成的中间工作会保留,Agent 收到插话后会调整后续方向。运行中的消息进入独立的注入队列(深度 50),与整轮排队(深度 1)分离。飞书中每条消息实际注入后,机器人会发送一条最多 200 字的回执,冻结注入前的过程卡片,并用新的“生成中”卡片展示后续过程。
|
|
248
248
|
|
|
@@ -426,7 +426,7 @@ ChatCCC 通过 Codex 的 **app-server 模式**(一个常驻进程 + WebSocket
|
|
|
426
426
|
|
|
427
427
|
**微信:** 扫码登录后,在机器人私聊里发送 `/new` 或指定 Agent 的 `/new ...` 命令即可开始。功能与飞书基本一致,但展示为纯文本。
|
|
428
428
|
|
|
429
|
-
**会话停滞保护:** 只有 Agent 明确进入“生成回复中”后,连续没有新增回复字符或推理进展心跳且尚未报告权威终态,ChatCCC 才判定停滞:**DeepCCC(CCC Agent)默认等待 10 分钟,其他 Agent 仍为 3 分钟**。触发后结束旧执行,并优先补发一次“完成了吗?如果没完成继续”;恢复轮使用同一阈值,再次停滞时不再递归续跑,日志及恢复失败提示会显示对应时长。这是 ChatCCC 的流式无进展保护,不是整轮时长上限,也不修改模型服务或工具超时;独立 DeepCCC CLI/Web 不受此看门狗配置影响。启动、上下文压缩、思考、搜索和工具调用阶段不会触发这项回复停滞计时;DeepCCC 关闭 streaming 时只会在请求完成后一次性返回结果,因此不会启用这项基于流式进度的停滞检测。其中 CCC Agent 会单独显示“压缩上下文中”,压缩最多等待 5 分钟,失败时直接报告具体原因且不自动重放。`/new claude` 和 `/new cursor` 等创建会话操作仍有独立的 3 分钟 init 超时,进程资源监控也继续负责识别真正僵死。Codex 只有 `turn.completed` 才算权威终态,阶段性的 `agent_message` 不算;任一 Agent 报告权威终态后若输出流仍超过 10 秒未关闭,ChatCCC 会强制清理该 CLI 并按正常完成收尾,不会重复询问 Agent。
|
|
429
|
+
**会话停滞保护:** 只有 Agent 明确进入“生成回复中”后,连续没有新增回复字符或推理进展心跳且尚未报告权威终态,ChatCCC 才判定停滞:**DeepCCC(CCC Agent)默认等待 10 分钟,其他 Agent 仍为 3 分钟**。触发后结束旧执行,并优先补发一次“完成了吗?如果没完成继续”;恢复轮使用同一阈值,再次停滞时不再递归续跑,日志及恢复失败提示会显示对应时长。这是 ChatCCC 的流式无进展保护,不是整轮时长上限,也不修改模型服务或工具超时;独立 DeepCCC CLI/Web 不受此看门狗配置影响。启动、上下文压缩、思考、搜索和工具调用阶段不会触发这项回复停滞计时;DeepCCC 关闭 streaming 时只会在请求完成后一次性返回结果,因此不会启用这项基于流式进度的停滞检测。其中 CCC Agent 会单独显示“压缩上下文中”,压缩最多等待 5 分钟,失败时直接报告具体原因且不自动重放。`/new claude` 和 `/new cursor` 等创建会话操作仍有独立的 3 分钟 init 超时,进程资源监控也继续负责识别真正僵死。Codex 只有 `turn.completed` 才算权威终态,阶段性的 `agent_message` 不算;任一 Agent 报告权威终态后若输出流仍超过 10 秒未关闭,ChatCCC 会强制清理该 CLI 并按正常完成收尾,不会重复询问 Agent。
|
|
430
430
|
|
|
431
431
|
**CCC Agent 代码搜索:** `search_code` 使用项目自带的跨平台 ripgrep,不要求系统另行安装 `rg`。如果当前平台没有可用的 bundled/system ripgrep,会自动降级为内置 Node 搜索,并继续支持常用正则、glob、结果上限、中止和超时控制。
|
|
432
432
|
|
|
@@ -484,6 +484,10 @@ Agent 的初始化、输入回显与重连通知不代表任务成功。Cursor
|
|
|
484
484
|
|
|
485
485
|
---
|
|
486
486
|
|
|
487
|
-
##
|
|
487
|
+
## 联合发布
|
|
488
|
+
|
|
489
|
+
ChatCCC 与独立 Deepccc 是两个 npm 包。联合发布须分别更新版本、检查构建产物并发布,合并 ChatCCC PR 不代表 ChatCCC npm 已更新。流程为私有 dev 开发测试并推送、私有 PR 合并、同步公开 dev、公开 PR 以 merge commit 合并、同步独立 Deepccc main、验证并发布两个 npm 包;内核无新增变化时复用已验证的同版本包,不重复发布同一版本。发布完成以 registry 中两个版本及产物摘要核同为准,本机安装和运行中进程版本分别核验。
|
|
490
|
+
|
|
491
|
+
## 技术栈
|
|
488
492
|
|
|
489
493
|
TypeScript(发布前编译为 JavaScript,tsx 仅用于开发)/ Node.js >= 20 / AI SDK / Anthropic Claude Agent SDK(按需下载)/ DeepSeek Harness SDK + JSON-RPC Runtime(按需下载,要求 Node.js >= 22.19.0)/ Cursor Agent CLI / Codex CLI / 飞书 WebSocket API / CardKit / 微信 iLink
|
package/config.sample.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"appSecret": ""
|
|
5
5
|
},
|
|
6
6
|
"platforms": {
|
|
7
|
-
"feishu": { "enabled": true, "platformType": "feishu", "tableSummary": true },
|
|
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,
|
package/deepccc-agent/README.md
CHANGED
|
@@ -8,7 +8,13 @@ DeepCCC 是一个本地优先的开源 Coding Agent,同时提供浏览器多
|
|
|
8
8
|
|
|
9
9
|
## 安装与快速开始
|
|
10
10
|
|
|
11
|
-
模型原生流未收到完成事件、返回错误结束原因或达到输出长度限制时,会报告异常并保留已经输出的内容,不将不完整回复判为成功。没有回复且没有工具执行的空结果也会明确报错。用户主动取消仍按中断处理。
|
|
11
|
+
模型原生流未收到完成事件、返回错误结束原因或达到输出长度限制时,会报告异常并保留已经输出的内容,不将不完整回复判为成功。没有回复且没有工具执行的空结果也会明确报错。用户主动取消仍按中断处理。
|
|
12
|
+
|
|
13
|
+
命令工具拒绝缺失或类型不符的必需参数,并指出具体字段,供模型修正后再调用。`run_script` 必须显式传入 `language`(`python` 或 `node`)和完整 `code`;不会猜测脚本语言或自动执行不完整调用。
|
|
14
|
+
|
|
15
|
+
启用会话持久化时,过长的工具输入字符串会在被上下文预算省略前保存到该会话的 `tool-arguments/<SHA256>.txt`,标记给出工件文件名,运行时指令给出目录。预算不足以保留参数对象时可用短 JSON 工件引用,内部仍可能包含需继续读取的字符串工件引用。通过本会话 `read_file` 读取这些工件时会校验内容哈希;复用前仍须读取并核对当前任务。工件记录生成过的参数,不证明原调用成功。
|
|
16
|
+
|
|
17
|
+
单个工件上限为 1 MiB,与文件读取上限一致;保存失败、超限或无法容纳引用时保留不可恢复标记,不编造原值。未启用持久化的会话不写工件,重置会话会清除其参数工件。现有上下文预算保留,工件引用、不可用元数据和新旧省略标记在工具入口被拦截,不直接执行或写入为文件内容。
|
|
12
18
|
|
|
13
19
|
全局安装:
|
|
14
20
|
|
|
@@ -376,10 +382,22 @@ deepccc-cli --stream-json --prompt "检查这个仓库并总结测试命令"
|
|
|
376
382
|
也可以从 stdin 传入提示词:
|
|
377
383
|
|
|
378
384
|
```bash
|
|
379
|
-
echo "运行测试并解释失败原因" | deepccc-cli --stream-json
|
|
380
|
-
```
|
|
381
|
-
|
|
382
|
-
|
|
385
|
+
echo "运行测试并解释失败原因" | deepccc-cli --stream-json
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
`--stream-json` 默认对工具/正文事件应用展示层隐私替换。需要把执行路径、原文及其 SHA 交给本地程序继续处理时,可以显式使用原始流:
|
|
389
|
+
|
|
390
|
+
```bash
|
|
391
|
+
deepccc-cli --raw-stream-json --prompt "Read the specified files" > machine-events.jsonl
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
此选项隐含 JSONL 模式,保留工具参数、结果、错误和正文的原始字符串,`start.event_payloads` 为 `original`。原始流可能包含未脱敏内容,应存入受信任的本地工作流;公开展示前仍需脱敏。它不修改全局隐私设置、模型输入、持久化上下文或工具权限,也不输出模型推理正文。程序化集成可给 `ChatSession` 传 `redactEvents: false`;省略时维持默认展示脱敏。不要把展示流中的别名路径当作可执行路径,或把脱敏后的正文与原文件 SHA 当作逐字节一致的数据。
|
|
395
|
+
|
|
396
|
+
0.2.39 起,启用原始 JSONL 且使用流式模型请求时,`start.model_tool_view_protocol` 为 `sha256-json-v1`,并产生 `model_tool_view` 事件。它记录模型请求准备阶段实际保留的工具结果(`content` 是 SDK tool-output 包装),以及原始/模型结果的 JSON UTF-8 SHA256、JavaScript 字符数、工具调用 ID 和步骤。相同调用的视图变化时另记事件;这与原始 `tool_result` 是两种证据,均不认证语义理解或业务正确。普通展示模式不产生此类原始内容事件,推理正文仍不输出。
|
|
397
|
+
|
|
398
|
+
当前最新工具批次在总预算允许时优先保留完整结果;历史单项上限不再无条件截短尚未读取的新结果。总预算仍生效,过大结果或多结果批次仍可能缩短,须按实际视图和缩短标记分段读取。原始日志完整不能代替这一步检查。
|
|
399
|
+
|
|
400
|
+
输出是逐行 JSON:
|
|
383
401
|
|
|
384
402
|
```jsonl
|
|
385
403
|
{"type":"start","session_id":"session-...","mode":"new","cwd":"/repo","model":"deepseek-v4-pro"}
|
|
@@ -114,6 +114,10 @@ function parseArgs(argv = process.argv.slice(2)) {
|
|
|
114
114
|
else if (arg === "--stream-json") {
|
|
115
115
|
streamJson = true;
|
|
116
116
|
}
|
|
117
|
+
else if (arg === "--raw-stream-json") {
|
|
118
|
+
streamJson = true;
|
|
119
|
+
options.redactEvents = false;
|
|
120
|
+
}
|
|
117
121
|
else if (arg === "--prompt" && next !== undefined) {
|
|
118
122
|
prompt = next;
|
|
119
123
|
i++;
|
|
@@ -163,6 +167,7 @@ function printHelp(appConfig) {
|
|
|
163
167
|
" --resume [id] Resume latest cwd session, or the explicit session id",
|
|
164
168
|
" --list-sessions List saved sessions and exit",
|
|
165
169
|
" --stream-json One-shot mode: write JSONL events to stdout",
|
|
170
|
+
" --raw-stream-json JSONL with original tool/text payloads for trusted local automation; bypasses display redaction",
|
|
166
171
|
" --prompt <text> Prompt text for --stream-json",
|
|
167
172
|
" --image <path> Attach a PNG/JPEG/WebP/GIF file (repeatable; quote paths with spaces)",
|
|
168
173
|
" Interactive: /image <path> queues one image for your next message; repeat for multiple images",
|
|
@@ -265,6 +270,9 @@ function streamJsonEvent(event) {
|
|
|
265
270
|
input: event.input,
|
|
266
271
|
});
|
|
267
272
|
}
|
|
273
|
+
else if (event.type === "model_tool_view") {
|
|
274
|
+
writeJsonLine({ ...event });
|
|
275
|
+
}
|
|
268
276
|
else if (event.type === "tool_result") {
|
|
269
277
|
writeJsonLine({
|
|
270
278
|
type: "tool_result",
|
|
@@ -350,6 +358,9 @@ async function runStreamJson(args) {
|
|
|
350
358
|
mode: resolvedSession.mode,
|
|
351
359
|
cwd,
|
|
352
360
|
model: args.config.model ?? runtime.appConfig.model,
|
|
361
|
+
event_payloads: args.options.redactEvents === false ? "original" : "display-redacted",
|
|
362
|
+
...(args.options.redactEvents === false && (args.config.streaming ?? runtime.appConfig.streaming)
|
|
363
|
+
? { model_tool_view_protocol: "sha256-json-v1" } : {}),
|
|
353
364
|
attachments: attachments.map((attachment) => ({
|
|
354
365
|
attachment_id: attachment.attachmentId,
|
|
355
366
|
name: attachment.originalName,
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { createHash, randomBytes } from "node:crypto";
|
|
2
|
+
import { compactJsonText } from "./tool-argument-replay.js";
|
|
3
|
+
import { ToolArgumentArtifactStore } from "./tool-argument-artifacts.js";
|
|
2
4
|
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
3
5
|
import { homedir } from "node:os";
|
|
4
6
|
import { join } from "node:path";
|
|
@@ -57,7 +59,10 @@ export function normalizeCompactedSummary(summary) {
|
|
|
57
59
|
].join("\n");
|
|
58
60
|
}
|
|
59
61
|
export function normalizeBuiltinSessionId(value) {
|
|
60
|
-
|
|
62
|
+
const normalized = value.replace(/[^a-zA-Z0-9_.-]+/g, "_").replace(/^_+|_+$/g, "") || "default";
|
|
63
|
+
if (/^\.+$/.test(normalized))
|
|
64
|
+
throw new Error("Session ID cannot be a dot path segment");
|
|
65
|
+
return normalized;
|
|
61
66
|
}
|
|
62
67
|
export function defaultBuiltinSessionId(cwd = process.cwd()) {
|
|
63
68
|
const hash = createHash("sha1").update(cwd).digest("hex").slice(0, 12);
|
|
@@ -322,23 +327,24 @@ function toolPayloadBudgets(lengths, maximum) {
|
|
|
322
327
|
}
|
|
323
328
|
return budgets;
|
|
324
329
|
}
|
|
325
|
-
function truncateStructuredToolCalls(calls, maxChars) {
|
|
330
|
+
function truncateStructuredToolCalls(calls, maxChars, preserveArgument) {
|
|
326
331
|
const payloads = calls.flatMap((call) => [call.input ?? "", call.output ?? ""]).filter(Boolean);
|
|
327
332
|
const total = payloads.reduce((sum, value) => sum + value.length, 0);
|
|
328
333
|
if (total <= maxChars)
|
|
329
334
|
return calls;
|
|
330
335
|
const budgets = toolPayloadBudgets(payloads.map(value => value.length), maxChars);
|
|
331
336
|
let payloadIndex = 0;
|
|
332
|
-
const truncatePayload = (value) => {
|
|
337
|
+
const truncatePayload = (value, output) => {
|
|
333
338
|
if (value === undefined || value.length === 0)
|
|
334
339
|
return value;
|
|
335
340
|
const budget = budgets[payloadIndex++];
|
|
336
|
-
return
|
|
341
|
+
return compactJsonText(value, budget, output, output ? undefined : preserveArgument)
|
|
342
|
+
?? truncateMiddle(value, budget, TOOL_TRANSCRIPT_TRUNCATED_MARKER);
|
|
337
343
|
};
|
|
338
344
|
return calls.map((call) => ({
|
|
339
345
|
...call,
|
|
340
|
-
...(call.input !== undefined ? { input: truncatePayload(call.input) } : {}),
|
|
341
|
-
...(call.output !== undefined ? { output: truncatePayload(call.output) } : {}),
|
|
346
|
+
...(call.input !== undefined ? { input: truncatePayload(call.input, false) } : {}),
|
|
347
|
+
...(call.output !== undefined ? { output: truncatePayload(call.output, true) } : {}),
|
|
342
348
|
}));
|
|
343
349
|
}
|
|
344
350
|
/**
|
|
@@ -350,15 +356,15 @@ export function buildPersistedAssistantMessage(params) {
|
|
|
350
356
|
const maxTranscriptChars = params.maxTranscriptChars ?? DEFAULT_PERSISTED_TOOL_TRANSCRIPT_CHARS;
|
|
351
357
|
const persistedAssistantText = truncateMiddle(params.fullText, maxAssistantChars, ASSISTANT_TRUNCATED_MARKER);
|
|
352
358
|
const message = { role: "assistant", content: persistedAssistantText };
|
|
353
|
-
const toolCalls = truncateStructuredToolCalls(normalizeToolCalls(params.toolCalls), maxTranscriptChars);
|
|
359
|
+
const toolCalls = truncateStructuredToolCalls(normalizeToolCalls(params.toolCalls), maxTranscriptChars, params.preserveToolArgument);
|
|
354
360
|
if (toolCalls.length > 0)
|
|
355
361
|
message.toolCalls = toolCalls;
|
|
356
|
-
const timeline = truncatePersistedTimeline(normalizeTimeline(params.timeline));
|
|
362
|
+
const timeline = truncatePersistedTimeline(normalizeTimeline(params.timeline), params.preserveToolArgument);
|
|
357
363
|
if (timeline.length > 0)
|
|
358
364
|
message.timeline = timeline;
|
|
359
365
|
return message;
|
|
360
366
|
}
|
|
361
|
-
function truncatePersistedTimeline(entries) {
|
|
367
|
+
function truncatePersistedTimeline(entries, preserveArgument) {
|
|
362
368
|
const maxTextChars = DEFAULT_PERSISTED_ASSISTANT_TEXT_CHARS;
|
|
363
369
|
const maxToolChars = DEFAULT_PERSISTED_TOOL_TRANSCRIPT_CHARS;
|
|
364
370
|
const totalText = entries.reduce((sum, entry) => sum + (entry.type === "text" ? entry.text.length : 0), 0);
|
|
@@ -387,11 +393,13 @@ function truncatePersistedTimeline(entries) {
|
|
|
387
393
|
}
|
|
388
394
|
if (entry.type === "tool_use" && entry.input !== undefined) {
|
|
389
395
|
const budget = entry.input.length ? toolBudgets[toolPayloadIndex++] : 0;
|
|
390
|
-
return { ...entry, input:
|
|
396
|
+
return { ...entry, input: compactJsonText(entry.input, budget, false, preserveArgument)
|
|
397
|
+
?? truncatePayload(entry.input, budget, TOOL_TRANSCRIPT_TRUNCATED_MARKER) };
|
|
391
398
|
}
|
|
392
399
|
if (entry.type === "tool_result" && entry.output !== undefined) {
|
|
393
400
|
const budget = entry.output.length ? toolBudgets[toolPayloadIndex++] : 0;
|
|
394
|
-
return { ...entry, output:
|
|
401
|
+
return { ...entry, output: compactJsonText(entry.output, budget, true)
|
|
402
|
+
?? truncatePayload(entry.output, budget, TOOL_TRANSCRIPT_TRUNCATED_MARKER) };
|
|
395
403
|
}
|
|
396
404
|
return entry;
|
|
397
405
|
});
|
|
@@ -403,7 +411,7 @@ function parseToolInput(value) {
|
|
|
403
411
|
return JSON.parse(value);
|
|
404
412
|
}
|
|
405
413
|
catch {
|
|
406
|
-
return {
|
|
414
|
+
return { __deepccc_input_unavailable: true, originalChars: value.length };
|
|
407
415
|
}
|
|
408
416
|
}
|
|
409
417
|
function parseToolOutput(value) {
|
|
@@ -562,12 +570,14 @@ export class BuiltinContextManager {
|
|
|
562
570
|
maxToolContextTokens;
|
|
563
571
|
keepRecentMessages;
|
|
564
572
|
cwd;
|
|
573
|
+
argumentArtifacts;
|
|
565
574
|
state;
|
|
566
575
|
constructor(options = {}) {
|
|
567
576
|
this.persist = options.persist ?? false;
|
|
568
577
|
this.contextDir = options.contextDir ?? DEFAULT_BUILTIN_CONTEXT_DIR;
|
|
569
578
|
this.sessionId = normalizeBuiltinSessionId(options.sessionId ?? defaultBuiltinSessionId());
|
|
570
579
|
this.cwd = options.cwd;
|
|
580
|
+
this.argumentArtifacts = new ToolArgumentArtifactStore(join(this.contextDir, this.sessionId));
|
|
571
581
|
this.compactAtTokens = options.compactAtTokens
|
|
572
582
|
?? Math.floor((options.contextWindow ?? DEFAULT_CONTEXT_WINDOW_TOKENS) * COMPACTION_THRESHOLD_RATIO);
|
|
573
583
|
this.maxToolContextTokens = Math.max(1, options.maxToolContextTokens
|
|
@@ -587,6 +597,8 @@ export class BuiltinContextManager {
|
|
|
587
597
|
get contextFilePath() {
|
|
588
598
|
return contextFilePath(this.contextDir, this.sessionId);
|
|
589
599
|
}
|
|
600
|
+
get toolArgumentArtifactDirectory() { return this.argumentArtifacts.directory; }
|
|
601
|
+
preserveToolArgument = text => this.persist ? this.argumentArtifacts.preserve(text) : undefined;
|
|
590
602
|
appendMessage(message) {
|
|
591
603
|
this.state.messages.push(message);
|
|
592
604
|
this.state.totalMessages += 1;
|
|
@@ -666,6 +678,8 @@ export class BuiltinContextManager {
|
|
|
666
678
|
this.save();
|
|
667
679
|
}
|
|
668
680
|
reset() {
|
|
681
|
+
if (this.persist)
|
|
682
|
+
this.argumentArtifacts.clear();
|
|
669
683
|
this.state = emptyState(this.sessionId, this.cwd);
|
|
670
684
|
this.save();
|
|
671
685
|
}
|
|
@@ -6,6 +6,8 @@ import { createRequire } from "node:module";
|
|
|
6
6
|
import { homedir } from "node:os";
|
|
7
7
|
import { basename, delimiter, dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
8
8
|
import { createInterface } from "node:readline";
|
|
9
|
+
import { isOmittedToolArgument } from "./tool-argument-replay.js";
|
|
10
|
+
import { expectedToolArgumentArtifactHash } from "./tool-argument-artifacts.js";
|
|
9
11
|
import { jsonSchema, tool } from "ai";
|
|
10
12
|
import { isDangerousCommand } from "./permissions.js";
|
|
11
13
|
import { detectImageMime, MAX_ATTACHMENT_BYTES } from "./attachments.js";
|
|
@@ -344,8 +346,9 @@ function applyParsedHunks(path, text, hunks) {
|
|
|
344
346
|
output.push(...original.slice(oldIndex));
|
|
345
347
|
return output.join(eol);
|
|
346
348
|
}
|
|
347
|
-
export async function readFileForTool(cwd, input) {
|
|
349
|
+
export async function readFileForTool(cwd, input, argumentArtifactDirectory) {
|
|
348
350
|
const filePath = resolveToolPath(cwd, input.path);
|
|
351
|
+
const expectedArtifactHash = expectedToolArgumentArtifactHash(argumentArtifactDirectory, filePath);
|
|
349
352
|
const info = await stat(filePath);
|
|
350
353
|
if (info.isDirectory()) {
|
|
351
354
|
throw new Error(`Path is a directory: ${filePath}`);
|
|
@@ -359,8 +362,13 @@ export async function readFileForTool(cwd, input) {
|
|
|
359
362
|
finally {
|
|
360
363
|
await handle.close();
|
|
361
364
|
}
|
|
362
|
-
const fileSha256 =
|
|
363
|
-
|
|
365
|
+
const fileSha256 = expectedArtifactHash
|
|
366
|
+
? createHash("sha256").update(buffer).digest("hex") : await sha256File(filePath);
|
|
367
|
+
if (expectedArtifactHash && (info.size > MAX_READ_BYTES || fileSha256 !== expectedArtifactHash)) {
|
|
368
|
+
throw new Error("Saved tool argument artifact failed its content hash check; do not reuse it");
|
|
369
|
+
}
|
|
370
|
+
// Managed values were written from UTF-8 strings, including possible NULs.
|
|
371
|
+
const isBinary = !expectedArtifactHash && isBinaryBuffer(buffer);
|
|
364
372
|
if (isBinary) {
|
|
365
373
|
return {
|
|
366
374
|
path: filePath,
|
|
@@ -377,7 +385,10 @@ export async function readFileForTool(cwd, input) {
|
|
|
377
385
|
const startLine = toPositiveInt(input.startLine) ?? 1;
|
|
378
386
|
const endLine = toPositiveInt(input.endLine) ?? totalLines;
|
|
379
387
|
const normalizedEnd = Math.max(startLine, Math.min(endLine, totalLines));
|
|
380
|
-
const content =
|
|
388
|
+
const content = expectedArtifactHash
|
|
389
|
+
? (startLine === 1 && normalizedEnd === totalLines ? text
|
|
390
|
+
: (text.match(/[^\n]*\n|[^\n]+$/g) ?? []).slice(startLine - 1, normalizedEnd).join(""))
|
|
391
|
+
: lines.slice(startLine - 1, normalizedEnd).join("\n");
|
|
381
392
|
return {
|
|
382
393
|
path: filePath,
|
|
383
394
|
size: info.size,
|
|
@@ -1104,6 +1115,9 @@ export async function runScriptForTool(cwd, input, abortSignal, shouldYield) {
|
|
|
1104
1115
|
if (typeof input.code !== "string" || !input.code.trim()) {
|
|
1105
1116
|
throw new Error("code is required");
|
|
1106
1117
|
}
|
|
1118
|
+
if (isOmittedToolArgument(input.code)) {
|
|
1119
|
+
throw new Error("This historical argument was omitted; read the complete saved file or rebuild the full script before reuse");
|
|
1120
|
+
}
|
|
1107
1121
|
if (Buffer.byteLength(input.code, "utf8") > MAX_SCRIPT_BYTES) {
|
|
1108
1122
|
throw new Error(`script exceeds ${MAX_SCRIPT_BYTES} bytes`);
|
|
1109
1123
|
}
|
|
@@ -1237,6 +1251,9 @@ export async function editFileForTool(cwd, input) {
|
|
|
1237
1251
|
};
|
|
1238
1252
|
}
|
|
1239
1253
|
export async function createFileForTool(cwd, input) {
|
|
1254
|
+
if (isOmittedToolArgument(input.content)) {
|
|
1255
|
+
throw new Error("This historical argument was omitted; read the complete saved file or rebuild the full content before reuse");
|
|
1256
|
+
}
|
|
1240
1257
|
const filePath = resolveToolPath(cwd, input.path);
|
|
1241
1258
|
assertTextSize(filePath, input.content, MAX_CREATE_BYTES);
|
|
1242
1259
|
let beforeSha;
|
|
@@ -1479,12 +1496,37 @@ export function killAllBackgroundTasks() {
|
|
|
1479
1496
|
function requireCommandArguments(name, input, requiredStrings, allowEmpty = []) {
|
|
1480
1497
|
const value = input && typeof input === "object" && !Array.isArray(input)
|
|
1481
1498
|
? input : undefined;
|
|
1482
|
-
|
|
1483
|
-
|| (!allowEmpty.includes(key) && !value[key].trim()))
|
|
1499
|
+
const invalidFields = requiredStrings.filter((key) => !value || typeof value[key] !== "string"
|
|
1500
|
+
|| (!allowEmpty.includes(key) && !value[key].trim()));
|
|
1501
|
+
if (!value || invalidFields.length > 0) {
|
|
1502
|
+
const detail = value
|
|
1503
|
+
? `Missing or invalid string fields: ${invalidFields.join(", ")}. `
|
|
1504
|
+
: "The supplied arguments are not a JSON object. ";
|
|
1484
1505
|
throw new Error(`Invalid ${name} arguments: expected a structured object with string fields ${requiredStrings.join(", ")}. `
|
|
1506
|
+
+ detail
|
|
1507
|
+
+ (name === "run_script" ? "Always pass language explicitly as python or node; there is no default language. " : "")
|
|
1485
1508
|
+ "Pass these named fields directly; do not wrap the arguments in raw or a JSON string.");
|
|
1486
1509
|
}
|
|
1487
1510
|
}
|
|
1511
|
+
function requireCompleteHistoricalArguments(input) {
|
|
1512
|
+
const pending = [input];
|
|
1513
|
+
const seen = new WeakSet();
|
|
1514
|
+
while (pending.length) {
|
|
1515
|
+
const value = pending.pop();
|
|
1516
|
+
const metadata = value && typeof value === "object" ? value : undefined;
|
|
1517
|
+
const artifactReference = typeof metadata?.__deepccc_input_artifact === "string"
|
|
1518
|
+
&& /^[a-f0-9]{64}\.txt$/.test(metadata.__deepccc_input_artifact);
|
|
1519
|
+
if (isOmittedToolArgument(value) || artifactReference || metadata?.__deepccc_input_unavailable === true
|
|
1520
|
+
|| metadata?.__deepccc_payload_unavailable === true) {
|
|
1521
|
+
throw new Error("This historical argument was omitted; read its referenced artifact or original saved file before reuse");
|
|
1522
|
+
}
|
|
1523
|
+
if (value && typeof value === "object" && !seen.has(value)) {
|
|
1524
|
+
seen.add(value);
|
|
1525
|
+
for (const child of Object.values(value))
|
|
1526
|
+
pending.push(child);
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1488
1530
|
export function createBuiltinFileTools(cwd, options = {}) {
|
|
1489
1531
|
const gate = options.permissionGate;
|
|
1490
1532
|
const runTask = options.runTask;
|
|
@@ -1509,7 +1551,7 @@ export function createBuiltinFileTools(cwd, options = {}) {
|
|
|
1509
1551
|
throw new Error(`权限拒绝:${request.detail}(已按规则或用户选择拦截;如需放行请调整 ~/.deepccc/allow.json,或使用 --dangerously-bypass-permissions)`);
|
|
1510
1552
|
}
|
|
1511
1553
|
};
|
|
1512
|
-
|
|
1554
|
+
const builtinTools = {
|
|
1513
1555
|
read_file: tool({
|
|
1514
1556
|
description: "从本地文件系统读取 UTF-8 文本文件。大文件请使用行范围。",
|
|
1515
1557
|
inputSchema: jsonSchema({
|
|
@@ -1522,7 +1564,9 @@ export function createBuiltinFileTools(cwd, options = {}) {
|
|
|
1522
1564
|
},
|
|
1523
1565
|
required: ["path"],
|
|
1524
1566
|
}),
|
|
1525
|
-
execute: (input) =>
|
|
1567
|
+
execute: async (input) => {
|
|
1568
|
+
return readFileForTool(cwd, input, options.toolArgumentArtifactDir);
|
|
1569
|
+
},
|
|
1526
1570
|
}),
|
|
1527
1571
|
...(options.readImage ? { read_image: tool({
|
|
1528
1572
|
description: "查看本地 PNG/JPEG/WebP/GIF 图片。图片作为视觉输入提供给模型,返回的是附件引用而非图片文字。可指定 question 聚焦细节;用于历史图片、报错截图、图表和工具生成的图片。",
|
|
@@ -1624,7 +1668,7 @@ export function createBuiltinFileTools(cwd, options = {}) {
|
|
|
1624
1668
|
},
|
|
1625
1669
|
}),
|
|
1626
1670
|
run_script: tool({
|
|
1627
|
-
description: "运行多行 Node.js 或 Python
|
|
1671
|
+
description: "运行多行 Node.js 或 Python 脚本。必须显式提供 language(python 或 node)和完整 code,不能只传 code;无默认语言。代码通过 stdin 传入解释器(shell:false),避免 python -c/node -e 的多层引号问题。Python 默认优先使用 cwd 下的 .venv,也可显式指定 executable。",
|
|
1628
1672
|
inputSchema: jsonSchema({
|
|
1629
1673
|
type: "object",
|
|
1630
1674
|
additionalProperties: false,
|
|
@@ -1956,4 +2000,21 @@ export function createBuiltinFileTools(cwd, options = {}) {
|
|
|
1956
2000
|
}),
|
|
1957
2001
|
}),
|
|
1958
2002
|
};
|
|
2003
|
+
// Reject unavailable historical values before any permission prompt or side
|
|
2004
|
+
// effect, including file-edit fields and nested process arguments.
|
|
2005
|
+
for (const definition of Object.values(builtinTools)) {
|
|
2006
|
+
const execute = definition.execute;
|
|
2007
|
+
if (!execute)
|
|
2008
|
+
continue;
|
|
2009
|
+
definition.execute = (input, executionOptions) => {
|
|
2010
|
+
try {
|
|
2011
|
+
requireCompleteHistoricalArguments(input);
|
|
2012
|
+
}
|
|
2013
|
+
catch (error) {
|
|
2014
|
+
return Promise.reject(error);
|
|
2015
|
+
}
|
|
2016
|
+
return execute(input, executionOptions);
|
|
2017
|
+
};
|
|
2018
|
+
}
|
|
2019
|
+
return builtinTools;
|
|
1959
2020
|
}
|