mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-19 23:05: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:
@@ -3,6 +3,7 @@ import React, { Suspense, use, useMemo } from 'react';
|
||||
import { FileEditToolDiff } from 'src/components/FileEditToolDiff.js';
|
||||
import { getCwd } from 'src/utils/cwd.js';
|
||||
import { isENOENT } from 'src/utils/errors.js';
|
||||
import { decodeBuffer } from 'src/utils/encoding.js';
|
||||
import { detectEncodingForResolvedPath } from 'src/utils/fileRead.js';
|
||||
import { getFsImplementation } from 'src/utils/fsOperations.js';
|
||||
import { Text } from '@anthropic/ink';
|
||||
@@ -33,9 +34,10 @@ export function SedEditPermissionRequest({ sedInfo, ...props }: SedEditPermissio
|
||||
// render correctly. This matches what readFileSync did before the
|
||||
// async conversion.
|
||||
const encoding = detectEncodingForResolvedPath(filePath);
|
||||
const raw = await getFsImplementation().readFile(filePath, { encoding });
|
||||
const rawBuffer = await getFsImplementation().readFileBytes(filePath);
|
||||
const raw = decodeBuffer(rawBuffer, encoding).replaceAll('\r\n', '\n');
|
||||
return {
|
||||
oldContent: raw.replaceAll('\r\n', '\n'),
|
||||
oldContent: raw,
|
||||
fileExists: true,
|
||||
};
|
||||
})().catch((e: unknown): FileReadResult => {
|
||||
|
||||
Reference in New Issue
Block a user