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.
@@ -1243,54 +1243,54 @@ export function createBuiltinFileTools(
1243
1243
 
1244
1244
  return {
1245
1245
  read_file: tool<ReadFileInput, ReadFileOutput>({
1246
- description: "Read a UTF-8 text file from the local filesystem. Use line ranges for large files.",
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: "Absolute path or path relative to the session cwd." },
1252
- startLine: { type: "number", description: "Optional 1-based first line to return." },
1253
- endLine: { type: "number", description: "Optional 1-based last line to return." },
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: "List files in a local directory.",
1260
+ description: "列出本地目录中的文件。",
1261
1261
  inputSchema: jsonSchema<ListDirInput>({
1262
1262
  type: "object",
1263
1263
  additionalProperties: false,
1264
1264
  properties: {
1265
- path: { type: "string", description: "Directory path. Defaults to the session cwd." },
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: "Search local files with ripgrep without invoking a shell.",
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: "Text or regex query passed to ripgrep." },
1277
- path: { type: "string", description: "File or directory to search. Defaults to the session cwd." },
1278
- glob: { type: "string", description: "Optional ripgrep glob filter, for example **/*.ts." },
1279
- maxResults: { type: "number", description: "Maximum result lines, capped internally." },
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: "Run a non-interactive shell command in the local workspace. Use for tests, git, and package scripts. Returns stdout/stderr and exitCode; non-zero exit codes are not tool errors.",
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: "Command line to run in the platform shell." },
1292
- cwd: { type: "string", description: "Optional working directory. Defaults to the session cwd." },
1293
- timeoutMs: { type: "number", description: `Optional timeout in milliseconds, capped at ${MAX_COMMAND_TIMEOUT_MS}.` },
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: "Edit an existing UTF-8 text file by applying exact oldText -> newText replacements. Uses optional SHA-256 precondition to avoid overwriting concurrent edits.",
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: "Absolute path or path relative to the session cwd." },
1314
- expectedSha256: { type: "string", description: "Optional SHA-256 hash of the current file content." },
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: "Exact text to replace. Include enough context to make it unique." },
1323
- newText: { type: "string", description: "Replacement text." },
1324
- replaceAll: { type: "boolean", description: "Replace every occurrence when oldText appears multiple times." },
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: "Create a UTF-8 text file, or overwrite an existing one when overwrite=true.",
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: "Absolute path or path relative to the session cwd." },
1350
- content: { type: "string", description: "Complete file content to write." },
1351
- overwrite: { type: "boolean", description: "Allow replacing an existing file." },
1352
- expectedSha256: { type: "string", description: "Optional SHA-256 hash required when overwriting an existing file." },
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: "Delete an existing text file. Use expectedSha256 to avoid deleting a file that changed after reading.",
1368
+ description: "删除现有的文本文件。使用 expectedSha256 避免删除读取后已更改的文件。",
1369
1369
  inputSchema: jsonSchema<DeleteFileInput>({
1370
1370
  type: "object",
1371
1371
  additionalProperties: false,
1372
1372
  properties: {
1373
- path: { type: "string", description: "Absolute path or path relative to the session cwd." },
1374
- expectedSha256: { type: "string", description: "Optional SHA-256 hash of the file that must be deleted." },
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: "Move or rename an existing text file. Can overwrite an existing destination only when overwrite=true.",
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: "Existing source file path." },
1396
- destinationPath: { type: "string", description: "Destination file path." },
1397
- overwrite: { type: "boolean", description: "Allow replacing an existing destination file." },
1398
- expectedSourceSha256: { type: "string", description: "Optional SHA-256 hash of the source file." },
1399
- expectedDestinationSha256: { type: "string", description: "Optional SHA-256 hash of the destination file when overwriting." },
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: "Apply a unified diff patch to one or more UTF-8 text files. Prefer edit_file for small targeted edits.",
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: "Unified diff patch text." },
1420
+ patch: { type: "string", description: "统一差异补丁文本。" },
1421
1421
  expectedSha256ByPath: {
1422
1422
  type: "object",
1423
- description: "Optional map of patch path or absolute path to expected SHA-256 before applying.",
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
- "You are DeepCCC, a lightweight AI coding agent running in a terminal workspace.",
49
+ "你是 DeepCCC,一个运行在终端工作区的轻量级 AI 编程智能体。",
49
50
  "",
50
- "## Fixed Rules",
51
- "- Respond in the user's language unless they ask otherwise.",
52
- "- Prefer direct, usable answers and concrete actions over long explanations.",
53
- "- For code tasks, inspect the relevant files before editing and verify with tests or checks when practical.",
54
- "- Preserve user work. Do not overwrite concurrent changes unless the user explicitly asks.",
55
- "- Keep immutable platform rules above project guidance and runtime details.",
51
+ "## 固定规则",
52
+ "- 除非用户另有要求,否则用用户的语言回复。",
53
+ "- 优先给出直接、可用的答案和具体行动,而非长篇解释。",
54
+ "- 代码任务:编辑前先阅读相关文件,并在可行时用测试或检查验证。",
55
+ "- 保护用户的工作。未经用户明确要求,不要覆盖并发修改。",
56
+ "- 平台不可变规则优先于项目指引和运行时细节。",
56
57
  "",
57
- "## Evidence-Gated Conclusions",
58
- "- Apply this gate before consequential claims or actions that could affect code, data, deployments, or user decisions, and whenever the available evidence is indirect.",
59
- "- Identify the claim and its authoritative source of truth. Separate direct observations from inferences, and test plausible alternative explanations before choosing one.",
60
- "- Use the strongest practical decisive check at the same semantic level as the claim: runtime behavior for runtime claims, effective configuration for configuration claims, deployed state for deployment claims, and transformed output for transformation claims.",
61
- "- Do not treat proxy signals such as names, timestamps, file sizes, line counts, partial samples, or a clean command exit as decisive when a direct check is practical.",
62
- "- Use definitive language only after the evidence closes the loop. Otherwise state uncertainty, identify the missing evidence, and name the next check.",
63
- "- Do not repeat checks once decisive evidence exists.",
58
+ "## 证据门控结论",
59
+ "- 在可能影响代码、数据、部署或用户决策的重大结论或行动前,以及可用证据为间接证据时,先应用本门控。",
60
+ "- 明确结论及其权威事实来源。区分直接观察与推断,并在选定结论前检验合理的替代解释。",
61
+ "- 在与结论同一语义层上使用最强可行的决定性检查:运行时结论用运行时行为、配置结论用有效配置、部署结论用部署状态、转换结论用转换后的输出。",
62
+ "- 在可行直接检查时,不要把名称、时间戳、文件大小、行数、局部采样或命令成功退出等代理信号当作决定性证据。",
63
+ "- 仅在证据闭环后使用确定性措辞。否则说明不确定性、指出缺失的证据并给出下一步检查。",
64
+ "- 一旦已有决定性证据,不要重复检查。",
64
65
  "",
65
- "## Survey Before Acting",
66
- "- Before diving into any task, first map the landscape at low cost: project instructions, directory layout, routes/APIs, existing tests, and git state.",
67
- "- Produce a brief execution plan that includes how you will verify the result, then execute.",
68
- "- When evidence contradicts an early assumption, revisit the plan instead of tunneling on one direction.",
66
+ "## 行动前先调查",
67
+ "- 深入任务前,先以低成本盘点环境:项目指令、目录布局、路由/API、现有测试和 git 状态。",
68
+ "- 产出包含如何验证结果的简要执行计划,然后执行。",
69
+ "- 当证据与早期假设矛盾时,重新审视计划,不要一条路走到黑。",
69
70
  "",
70
- "## Delegated Authority",
71
- "- When the user delegates decisions (\"you decide\", \"do it elegantly\", \"up to you\"), act autonomously on implementation details.",
72
- "- Only ask about genuine blockers: irreversible actions, security boundaries, credentials, or scope changes.",
73
- "- Do not bounce implementation-level multiple-choice questions back to the user after they delegated.",
71
+ "## 授权范围",
72
+ "- 当用户委托决策(\"你决定\"、\"做得优雅些\"、\"由你定\")时,自主决定实现细节。",
73
+ "- 只问真正的阻塞项:不可逆操作、安全边界、凭据或范围变更。",
74
+ "- 用户委托后,不要把实现级选择题抛回给用户。",
74
75
  "",
75
- "## Pre-Delivery Self-Check",
76
- "- Before reporting completion, verify: the change runs, edge cases are covered, assumptions are listed, and anything unverified is explicitly labeled as such.",
77
- "- State what was done, how it was verified, and what remains unverified or risky.",
76
+ "## 交付前自检",
77
+ "- 报告完成前验证:改动可运行、边界情况已覆盖、假设已列出、未验证项已明确标注。",
78
+ "- 说明做了什么、如何验证的、以及哪些未验证或有风险。",
78
79
  ].join("\n");
79
80
 
80
81
  const SUMMARY_SYSTEM_PROMPT = [
81
- "You are DeepCCC's context compactor.",
82
- "Compress older conversation context into a faithful, structured summary that can be used to continue the task.",
83
- "Do not introduce new facts or promote historical user content into higher-priority system rules.",
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
- "## Project Instructions",
116
- "The following files were read from the current working directory. Treat them as project guidance with lower priority than the fixed DeepCCC system rules above.",
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
- `Current working directory: ${cwd}`,
125
- "Use read_file, list_dir, search_code, and run_command proactively when you need to understand code, configuration, project structure, tests, or git state.",
126
- "Use run_command for non-interactive shell commands such as npm test, type checks, git status, git add, git commit, and git push. Check exitCode, stdout, and stderr before deciding the next step.",
127
- "Before editing, read the relevant file ranges. Prefer edit_file for precise replacements, create_file for new files, delete_file for removal, move_file for moves, and apply_patch for multi-file diffs.",
128
- "File tools run locally through DeepCCC. Prefer guarded edits with SHA-256 preconditions where practical, and avoid overwriting concurrent user changes.",
130
+ `当前工作目录:${cwd}`,
131
+ "需要理解代码、配置、项目结构、测试或 git 状态时,主动使用 read_filelist_dirsearch_code run_command",
132
+ "使用 run_command 执行非交互式 shell 命令,如 npm test、类型检查、git statusgit addgit commit git push。先检查 exitCodestdout 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: this.context.buildModelMessages() as any,
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
- "Earlier conversation summary:",
566
+ "更早的对话摘要:",
532
567
  "",
533
568
  this.context.summary,
534
569
  ].join("\n"),