mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-23 16:55:51 +00:00
feat: 添加 GBK 编码自动检测支持,文件读写工具透明处理非 UTF-8 文件
新增 encoding.ts 核心模块实现三层编码检测(BOM → UTF-8 fatal → GBK 回退), 改造同步/异步读取路径和写入路径,使 FileReadTool/FileEditTool/FileWriteTool 能正确处理 GBK 编码文件。包含完整单元测试和 spec 文档。 Co-Authored-By: glm-5-turbo <zai-org@claude-code-best.win>
This commit is contained in:
@@ -29,6 +29,7 @@ import { extractClaudeCodeHints } from 'src/utils/claudeCodeHints.js';
|
||||
import { detectCodeIndexingFromCommand } from 'src/utils/codeIndexing.js';
|
||||
import { isEnvTruthy } from 'src/utils/envUtils.js';
|
||||
import { isENOENT, ShellError } from 'src/utils/errors.js';
|
||||
import { decodeBuffer } from 'src/utils/encoding.js';
|
||||
import { detectFileEncoding, detectLineEndings, getFileModificationTime, writeTextContent } from 'src/utils/file.js';
|
||||
import { fileHistoryEnabled, fileHistoryTrackEdit } from 'src/utils/fileHistory.js';
|
||||
import { truncate } from 'src/utils/format.js';
|
||||
@@ -511,7 +512,8 @@ async function applySedEdit(
|
||||
const encoding = detectFileEncoding(absoluteFilePath);
|
||||
let originalContent: string;
|
||||
try {
|
||||
originalContent = await fs.readFile(absoluteFilePath, { encoding });
|
||||
const rawBuffer = await fs.readFileBytes(absoluteFilePath);
|
||||
originalContent = decodeBuffer(rawBuffer, encoding);
|
||||
} catch (e) {
|
||||
if (isENOENT(e)) {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user