chatccc 0.2.250 → 0.2.252
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/deepccc-agent/os-prompts/darwin.md +8 -8
- package/deepccc-agent/os-prompts/linux.md +8 -8
- package/deepccc-agent/os-prompts/win32.md +11 -11
- package/deepccc-agent/package-lock.json +2027 -2027
- package/deepccc-agent/package.json +65 -65
- package/deepccc-agent/src/__tests__/chat-session.test.ts +877 -852
- package/deepccc-agent/src/__tests__/context.test.ts +341 -341
- package/deepccc-agent/src/__tests__/skills.test.ts +284 -284
- package/deepccc-agent/src/context.ts +465 -465
- package/deepccc-agent/src/file-tools.ts +38 -38
- package/deepccc-agent/src/index.ts +72 -37
- package/deepccc-agent/src/skills.ts +205 -205
- package/package.json +74 -74
- package/src/__tests__/builtin-chat-session.test.ts +532 -532
- package/src/__tests__/builtin-context.test.ts +319 -319
- package/src/__tests__/builtin-skills.test.ts +284 -284
- package/src/__tests__/config-utils.test.ts +40 -40
- package/src/__tests__/session-ccc-config.test.ts +66 -66
- package/src/__tests__/web-ui.test.ts +438 -438
|
@@ -1243,54 +1243,54 @@ export function createBuiltinFileTools(
|
|
|
1243
1243
|
|
|
1244
1244
|
return {
|
|
1245
1245
|
read_file: tool<ReadFileInput, ReadFileOutput>({
|
|
1246
|
-
description: "
|
|
1246
|
+
description: "从本地文件系统读取 UTF-8 文本文件。大文件请使用行范围。",
|
|
1247
1247
|
inputSchema: jsonSchema<ReadFileInput>({
|
|
1248
1248
|
type: "object",
|
|
1249
1249
|
additionalProperties: false,
|
|
1250
1250
|
properties: {
|
|
1251
|
-
path: { type: "string", description: "
|
|
1252
|
-
startLine: { type: "number", description: "
|
|
1253
|
-
endLine: { type: "number", description: "
|
|
1251
|
+
path: { type: "string", description: "绝对路径或相对于会话工作目录的路径。" },
|
|
1252
|
+
startLine: { type: "number", description: "可选,从第几行开始返回(从 1 开始)。" },
|
|
1253
|
+
endLine: { type: "number", description: "可选,返回到第几行(从 1 开始)。" },
|
|
1254
1254
|
},
|
|
1255
1255
|
required: ["path"],
|
|
1256
1256
|
}),
|
|
1257
1257
|
execute: (input) => readFileForTool(cwd, input),
|
|
1258
1258
|
}),
|
|
1259
1259
|
list_dir: tool<ListDirInput, ListDirOutput>({
|
|
1260
|
-
description: "
|
|
1260
|
+
description: "列出本地目录中的文件。",
|
|
1261
1261
|
inputSchema: jsonSchema<ListDirInput>({
|
|
1262
1262
|
type: "object",
|
|
1263
1263
|
additionalProperties: false,
|
|
1264
1264
|
properties: {
|
|
1265
|
-
path: { type: "string", description: "
|
|
1265
|
+
path: { type: "string", description: "目录路径。默认为会话工作目录。" },
|
|
1266
1266
|
},
|
|
1267
1267
|
}),
|
|
1268
1268
|
execute: (input) => listDirForTool(cwd, input),
|
|
1269
1269
|
}),
|
|
1270
1270
|
search_code: tool<SearchCodeInput, SearchCodeOutput>({
|
|
1271
|
-
description: "
|
|
1271
|
+
description: "用 ripgrep 搜索本地文件,无需调用 shell。",
|
|
1272
1272
|
inputSchema: jsonSchema<SearchCodeInput>({
|
|
1273
1273
|
type: "object",
|
|
1274
1274
|
additionalProperties: false,
|
|
1275
1275
|
properties: {
|
|
1276
|
-
query: { type: "string", description: "
|
|
1277
|
-
path: { type: "string", description: "
|
|
1278
|
-
glob: { type: "string", description: "
|
|
1279
|
-
maxResults: { type: "number", description: "
|
|
1276
|
+
query: { type: "string", description: "传递给 ripgrep 的文本或正则查询。" },
|
|
1277
|
+
path: { type: "string", description: "要搜索的文件或目录。默认为会话工作目录。" },
|
|
1278
|
+
glob: { type: "string", description: "可选的 ripgrep glob 过滤器,例如 **/*.ts。" },
|
|
1279
|
+
maxResults: { type: "number", description: "最大结果行数,内部设有上限。" },
|
|
1280
1280
|
},
|
|
1281
1281
|
required: ["query"],
|
|
1282
1282
|
}),
|
|
1283
1283
|
execute: (input, options) => searchCodeForTool(cwd, input, options.abortSignal),
|
|
1284
1284
|
}),
|
|
1285
1285
|
run_command: tool<RunCommandInput, RunCommandOutput>({
|
|
1286
|
-
description: "
|
|
1286
|
+
description: "在本地工作区运行非交互式 shell 命令。用于测试、git 和包脚本。返回 stdout/stderr 和 exitCode;非零退出码不是工具错误。",
|
|
1287
1287
|
inputSchema: jsonSchema<RunCommandInput>({
|
|
1288
1288
|
type: "object",
|
|
1289
1289
|
additionalProperties: false,
|
|
1290
1290
|
properties: {
|
|
1291
|
-
command: { type: "string", description: "
|
|
1292
|
-
cwd: { type: "string", description: "
|
|
1293
|
-
timeoutMs: { type: "number", description:
|
|
1291
|
+
command: { type: "string", description: "要在平台 shell 中运行的命令行。" },
|
|
1292
|
+
cwd: { type: "string", description: "可选的工作目录。默认为会话工作目录。" },
|
|
1293
|
+
timeoutMs: { type: "number", description: `可选超时(毫秒),上限为 ${MAX_COMMAND_TIMEOUT_MS}。` },
|
|
1294
1294
|
},
|
|
1295
1295
|
required: ["command"],
|
|
1296
1296
|
}),
|
|
@@ -1305,13 +1305,13 @@ export function createBuiltinFileTools(
|
|
|
1305
1305
|
},
|
|
1306
1306
|
}),
|
|
1307
1307
|
edit_file: tool<EditFileInput, EditFileOutput>({
|
|
1308
|
-
description: "
|
|
1308
|
+
description: "通过精确的 oldText -> newText 替换编辑现有 UTF-8 文本文件。可行时使用 SHA-256 前置条件以避免覆盖并发编辑。",
|
|
1309
1309
|
inputSchema: jsonSchema<EditFileInput>({
|
|
1310
1310
|
type: "object",
|
|
1311
1311
|
additionalProperties: false,
|
|
1312
1312
|
properties: {
|
|
1313
|
-
path: { type: "string", description: "
|
|
1314
|
-
expectedSha256: { type: "string", description: "
|
|
1313
|
+
path: { type: "string", description: "绝对路径或相对于会话工作目录的路径。" },
|
|
1314
|
+
expectedSha256: { type: "string", description: "当前文件内容的可选 SHA-256 哈希。" },
|
|
1315
1315
|
edits: {
|
|
1316
1316
|
type: "array",
|
|
1317
1317
|
minItems: 1,
|
|
@@ -1319,9 +1319,9 @@ export function createBuiltinFileTools(
|
|
|
1319
1319
|
type: "object",
|
|
1320
1320
|
additionalProperties: false,
|
|
1321
1321
|
properties: {
|
|
1322
|
-
oldText: { type: "string", description: "
|
|
1323
|
-
newText: { type: "string", description: "
|
|
1324
|
-
replaceAll: { type: "boolean", description: "
|
|
1322
|
+
oldText: { type: "string", description: "要替换的精确文本。包含足够的上下文使其唯一。" },
|
|
1323
|
+
newText: { type: "string", description: "替换文本。" },
|
|
1324
|
+
replaceAll: { type: "boolean", description: "当 oldText 出现多次时替换所有出现。" },
|
|
1325
1325
|
},
|
|
1326
1326
|
required: ["oldText", "newText"],
|
|
1327
1327
|
},
|
|
@@ -1341,15 +1341,15 @@ export function createBuiltinFileTools(
|
|
|
1341
1341
|
},
|
|
1342
1342
|
}),
|
|
1343
1343
|
create_file: tool<CreateFileInput, FileWriteOutput>({
|
|
1344
|
-
description: "
|
|
1344
|
+
description: "创建 UTF-8 文本文件,或在 overwrite=true 时覆盖现有文件。",
|
|
1345
1345
|
inputSchema: jsonSchema<CreateFileInput>({
|
|
1346
1346
|
type: "object",
|
|
1347
1347
|
additionalProperties: false,
|
|
1348
1348
|
properties: {
|
|
1349
|
-
path: { type: "string", description: "
|
|
1350
|
-
content: { type: "string", description: "
|
|
1351
|
-
overwrite: { type: "boolean", description: "
|
|
1352
|
-
expectedSha256: { type: "string", description: "
|
|
1349
|
+
path: { type: "string", description: "绝对路径或相对于会话工作目录的路径。" },
|
|
1350
|
+
content: { type: "string", description: "要写入的完整文件内容。" },
|
|
1351
|
+
overwrite: { type: "boolean", description: "允许替换现有文件。" },
|
|
1352
|
+
expectedSha256: { type: "string", description: "覆盖现有文件时需要的可选 SHA-256 哈希。" },
|
|
1353
1353
|
},
|
|
1354
1354
|
required: ["path", "content"],
|
|
1355
1355
|
}),
|
|
@@ -1365,13 +1365,13 @@ export function createBuiltinFileTools(
|
|
|
1365
1365
|
},
|
|
1366
1366
|
}),
|
|
1367
1367
|
delete_file: tool<DeleteFileInput, DeleteFileOutput>({
|
|
1368
|
-
description: "
|
|
1368
|
+
description: "删除现有的文本文件。使用 expectedSha256 避免删除读取后已更改的文件。",
|
|
1369
1369
|
inputSchema: jsonSchema<DeleteFileInput>({
|
|
1370
1370
|
type: "object",
|
|
1371
1371
|
additionalProperties: false,
|
|
1372
1372
|
properties: {
|
|
1373
|
-
path: { type: "string", description: "
|
|
1374
|
-
expectedSha256: { type: "string", description: "
|
|
1373
|
+
path: { type: "string", description: "绝对路径或相对于会话工作目录的路径。" },
|
|
1374
|
+
expectedSha256: { type: "string", description: "必须删除的文件的可选 SHA-256 哈希。" },
|
|
1375
1375
|
},
|
|
1376
1376
|
required: ["path"],
|
|
1377
1377
|
}),
|
|
@@ -1387,16 +1387,16 @@ export function createBuiltinFileTools(
|
|
|
1387
1387
|
},
|
|
1388
1388
|
}),
|
|
1389
1389
|
move_file: tool<MoveFileInput, MoveFileOutput>({
|
|
1390
|
-
description: "
|
|
1390
|
+
description: "移动或重命名现有文本文件。仅在 overwrite=true 时可覆盖现有目标。",
|
|
1391
1391
|
inputSchema: jsonSchema<MoveFileInput>({
|
|
1392
1392
|
type: "object",
|
|
1393
1393
|
additionalProperties: false,
|
|
1394
1394
|
properties: {
|
|
1395
|
-
sourcePath: { type: "string", description: "
|
|
1396
|
-
destinationPath: { type: "string", description: "
|
|
1397
|
-
overwrite: { type: "boolean", description: "
|
|
1398
|
-
expectedSourceSha256: { type: "string", description: "
|
|
1399
|
-
expectedDestinationSha256: { type: "string", description: "
|
|
1395
|
+
sourcePath: { type: "string", description: "现有源文件路径。" },
|
|
1396
|
+
destinationPath: { type: "string", description: "目标文件路径。" },
|
|
1397
|
+
overwrite: { type: "boolean", description: "允许覆盖现有目标文件。" },
|
|
1398
|
+
expectedSourceSha256: { type: "string", description: "源文件的可选 SHA-256 哈希。" },
|
|
1399
|
+
expectedDestinationSha256: { type: "string", description: "覆盖目标时目标文件的可选 SHA-256 哈希。" },
|
|
1400
1400
|
},
|
|
1401
1401
|
required: ["sourcePath", "destinationPath"],
|
|
1402
1402
|
}),
|
|
@@ -1412,15 +1412,15 @@ export function createBuiltinFileTools(
|
|
|
1412
1412
|
},
|
|
1413
1413
|
}),
|
|
1414
1414
|
apply_patch: tool<ApplyPatchInput, ApplyPatchOutput>({
|
|
1415
|
-
description: "
|
|
1415
|
+
description: "将统一差异补丁应用于一个或多个 UTF-8 文本文件。小范围精确编辑优先使用 edit_file。",
|
|
1416
1416
|
inputSchema: jsonSchema<ApplyPatchInput>({
|
|
1417
1417
|
type: "object",
|
|
1418
1418
|
additionalProperties: false,
|
|
1419
1419
|
properties: {
|
|
1420
|
-
patch: { type: "string", description: "
|
|
1420
|
+
patch: { type: "string", description: "统一差异补丁文本。" },
|
|
1421
1421
|
expectedSha256ByPath: {
|
|
1422
1422
|
type: "object",
|
|
1423
|
-
description: "
|
|
1423
|
+
description: "补丁路径或绝对路径到预期 SHA-256 的可选映射。",
|
|
1424
1424
|
additionalProperties: { type: "string" },
|
|
1425
1425
|
},
|
|
1426
1426
|
},
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
buildSummaryPrompt,
|
|
29
29
|
BuiltinContextManager,
|
|
30
30
|
defaultBuiltinSessionId,
|
|
31
|
+
type BuiltinContextMessage,
|
|
31
32
|
} from "./context.js";
|
|
32
33
|
import { createBuiltinFileTools } from "./file-tools.js";
|
|
33
34
|
import { PermissionGate, type PermissionMode, type PermissionResolver } from "./permissions.js";
|
|
@@ -45,46 +46,51 @@ import { applyPrivacy, applyPrivacyToJson } from "./privacy.js";
|
|
|
45
46
|
// ---------------------------------------------------------------------------
|
|
46
47
|
|
|
47
48
|
const SYSTEM_PROMPT = [
|
|
48
|
-
"
|
|
49
|
+
"你是 DeepCCC,一个运行在终端工作区的轻量级 AI 编程智能体。",
|
|
49
50
|
"",
|
|
50
|
-
"##
|
|
51
|
-
"-
|
|
52
|
-
"-
|
|
53
|
-
"-
|
|
54
|
-
"-
|
|
55
|
-
"-
|
|
51
|
+
"## 固定规则",
|
|
52
|
+
"- 除非用户另有要求,否则用用户的语言回复。",
|
|
53
|
+
"- 优先给出直接、可用的答案和具体行动,而非长篇解释。",
|
|
54
|
+
"- 代码任务:编辑前先阅读相关文件,并在可行时用测试或检查验证。",
|
|
55
|
+
"- 保护用户的工作。未经用户明确要求,不要覆盖并发修改。",
|
|
56
|
+
"- 平台不可变规则优先于项目指引和运行时细节。",
|
|
56
57
|
"",
|
|
57
|
-
"##
|
|
58
|
-
"-
|
|
59
|
-
"-
|
|
60
|
-
"-
|
|
61
|
-
"-
|
|
62
|
-
"-
|
|
63
|
-
"-
|
|
58
|
+
"## 证据门控结论",
|
|
59
|
+
"- 在可能影响代码、数据、部署或用户决策的重大结论或行动前,以及可用证据为间接证据时,先应用本门控。",
|
|
60
|
+
"- 明确结论及其权威事实来源。区分直接观察与推断,并在选定结论前检验合理的替代解释。",
|
|
61
|
+
"- 在与结论同一语义层上使用最强可行的决定性检查:运行时结论用运行时行为、配置结论用有效配置、部署结论用部署状态、转换结论用转换后的输出。",
|
|
62
|
+
"- 在可行直接检查时,不要把名称、时间戳、文件大小、行数、局部采样或命令成功退出等代理信号当作决定性证据。",
|
|
63
|
+
"- 仅在证据闭环后使用确定性措辞。否则说明不确定性、指出缺失的证据并给出下一步检查。",
|
|
64
|
+
"- 一旦已有决定性证据,不要重复检查。",
|
|
64
65
|
"",
|
|
65
|
-
"##
|
|
66
|
-
"-
|
|
67
|
-
"-
|
|
68
|
-
"-
|
|
66
|
+
"## 行动前先调查",
|
|
67
|
+
"- 深入任务前,先以低成本盘点环境:项目指令、目录布局、路由/API、现有测试和 git 状态。",
|
|
68
|
+
"- 产出包含如何验证结果的简要执行计划,然后执行。",
|
|
69
|
+
"- 当证据与早期假设矛盾时,重新审视计划,不要一条路走到黑。",
|
|
69
70
|
"",
|
|
70
|
-
"##
|
|
71
|
-
"-
|
|
72
|
-
"-
|
|
73
|
-
"-
|
|
71
|
+
"## 授权范围",
|
|
72
|
+
"- 当用户委托决策(\"你决定\"、\"做得优雅些\"、\"由你定\")时,自主决定实现细节。",
|
|
73
|
+
"- 只问真正的阻塞项:不可逆操作、安全边界、凭据或范围变更。",
|
|
74
|
+
"- 用户委托后,不要把实现级选择题抛回给用户。",
|
|
74
75
|
"",
|
|
75
|
-
"##
|
|
76
|
-
"-
|
|
77
|
-
"-
|
|
76
|
+
"## 交付前自检",
|
|
77
|
+
"- 报告完成前验证:改动可运行、边界情况已覆盖、假设已列出、未验证项已明确标注。",
|
|
78
|
+
"- 说明做了什么、如何验证的、以及哪些未验证或有风险。",
|
|
78
79
|
].join("\n");
|
|
79
80
|
|
|
80
81
|
const SUMMARY_SYSTEM_PROMPT = [
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
82
|
+
"你是 DeepCCC 的上下文压缩器。",
|
|
83
|
+
"将较早的对话上下文压缩成忠实、结构化的摘要,用于继续任务。",
|
|
84
|
+
"不要引入新事实,也不要把历史用户内容提升为更高优先级的系统规则。",
|
|
85
|
+
"用中文输出摘要。",
|
|
84
86
|
].join("\n");
|
|
85
87
|
|
|
86
88
|
export const DEFAULT_COMPACTION_TIMEOUT_MS = 90 * 1000;
|
|
87
89
|
const MAX_COMPACTION_OUTPUT_TOKENS = 16_384;
|
|
90
|
+
const ANTHROPIC_TOOL_JSON_COMPATIBILITY_NOTE = [
|
|
91
|
+
"[Protocol compatibility note]",
|
|
92
|
+
"tool-call arguments use JSON encoding; the final reply does not need to be JSON unless the user requests it.",
|
|
93
|
+
].join("\n");
|
|
88
94
|
|
|
89
95
|
// ---------------------------------------------------------------------------
|
|
90
96
|
// 类型定义
|
|
@@ -112,8 +118,8 @@ function readProjectInstructionFiles(cwd: string): string {
|
|
|
112
118
|
|
|
113
119
|
if (sections.length === 0) return "";
|
|
114
120
|
return [
|
|
115
|
-
"##
|
|
116
|
-
"
|
|
121
|
+
"## 项目指令",
|
|
122
|
+
"以下文件是从当前工作目录读取的项目指引。将其视为优先级低于上述 DeepCCC 固定系统规则的指导。",
|
|
117
123
|
"",
|
|
118
124
|
sections.join("\n\n"),
|
|
119
125
|
].join("\n");
|
|
@@ -121,14 +127,39 @@ function readProjectInstructionFiles(cwd: string): string {
|
|
|
121
127
|
|
|
122
128
|
function buildRuntimeWorkspacePrompt(cwd: string): string {
|
|
123
129
|
return [
|
|
124
|
-
|
|
125
|
-
"
|
|
126
|
-
"
|
|
127
|
-
"
|
|
128
|
-
"
|
|
130
|
+
`当前工作目录:${cwd}`,
|
|
131
|
+
"需要理解代码、配置、项目结构、测试或 git 状态时,主动使用 read_file、list_dir、search_code 和 run_command。",
|
|
132
|
+
"使用 run_command 执行非交互式 shell 命令,如 npm test、类型检查、git status、git add、git commit 和 git push。先检查 exitCode、stdout 和 stderr 再决定下一步。",
|
|
133
|
+
"编辑前先阅读相关文件范围。优先使用 edit_file 做精确替换、create_file 创建新文件、delete_file 删除、move_file 移动、apply_patch 做多文件差异。",
|
|
134
|
+
"文件工具通过 DeepCCC 在本地执行。可行时优先使用带 SHA-256 前置条件的受保护编辑,避免覆盖并发用户修改。",
|
|
129
135
|
].join("\n");
|
|
130
136
|
}
|
|
131
137
|
|
|
138
|
+
function addAnthropicToolJsonCompatibilityNote(
|
|
139
|
+
messages: BuiltinContextMessage[],
|
|
140
|
+
): BuiltinContextMessage[] {
|
|
141
|
+
let lastUserIndex = -1;
|
|
142
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
143
|
+
if (messages[index]?.role === "user") {
|
|
144
|
+
lastUserIndex = index;
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (lastUserIndex < 0) return messages;
|
|
149
|
+
|
|
150
|
+
// 部分 Anthropic→OpenAI/Ark 转换器会用 response_format=json_object
|
|
151
|
+
// 实现工具调用,却只在 messages 中校验 JSON 关键词、不读取顶层 system。
|
|
152
|
+
// 这里仅声明工具参数的编码方式,并明确不要求普通最终回复输出 JSON。
|
|
153
|
+
return messages.map((message, index) => (
|
|
154
|
+
index === lastUserIndex
|
|
155
|
+
? {
|
|
156
|
+
...message,
|
|
157
|
+
content: `${message.content}\n\n${ANTHROPIC_TOOL_JSON_COMPATIBILITY_NOTE}`,
|
|
158
|
+
}
|
|
159
|
+
: message
|
|
160
|
+
));
|
|
161
|
+
}
|
|
162
|
+
|
|
132
163
|
/**
|
|
133
164
|
* 各操作系统特有的命令行指引(文本资产,维护在 os-prompts/ 目录,而非硬编码):
|
|
134
165
|
*
|
|
@@ -408,6 +439,10 @@ export class ChatSession {
|
|
|
408
439
|
const skills = await scanSkillsDirs(this.skillDirs);
|
|
409
440
|
const system = this.buildSystemPrompt(skills);
|
|
410
441
|
this.systemPrompt = system;
|
|
442
|
+
const contextMessages = this.context.buildModelMessages();
|
|
443
|
+
const modelMessages = this.provider === "anthropic"
|
|
444
|
+
? addAnthropicToolJsonCompatibilityNote(contextMessages)
|
|
445
|
+
: contextMessages;
|
|
411
446
|
// effort 按协议映射:
|
|
412
447
|
// - OpenAI 兼容:providerOptions.deepseek.reasoningEffort 由 @ai-sdk/openai-compatible
|
|
413
448
|
// 自动映射为请求体 reasoning_effort 字段(DeepSeek 原生支持);
|
|
@@ -422,7 +457,7 @@ export class ChatSession {
|
|
|
422
457
|
const generationOptions = {
|
|
423
458
|
model: this.model,
|
|
424
459
|
system,
|
|
425
|
-
messages:
|
|
460
|
+
messages: modelMessages as any,
|
|
426
461
|
tools: createBuiltinFileTools(this.cwd, { permissionGate: this.permissionGate }),
|
|
427
462
|
stopWhen: maxSteps !== undefined ? stepCountIs(maxSteps) : isLoopFinished(),
|
|
428
463
|
abortSignal: signal,
|
|
@@ -528,7 +563,7 @@ export class ChatSession {
|
|
|
528
563
|
history.push({
|
|
529
564
|
role: "system",
|
|
530
565
|
content: [
|
|
531
|
-
"
|
|
566
|
+
"更早的对话摘要:",
|
|
532
567
|
"",
|
|
533
568
|
this.context.summary,
|
|
534
569
|
].join("\n"),
|