encoding-converter-ai 0.1.0
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 +75 -0
- package/dist/converter.js +4160 -0
- package/dist/index.js +4118 -0
- package/dist/plugin.js +4136 -0
- package/package.json +28 -0
- package/templates/settings.hooks.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# encoding-converter-ai
|
|
2
|
+
|
|
3
|
+
> AI 编程工具的透明编码桥梁 —— 让 GB18030 项目与 UTF-8 世界无缝衔接。
|
|
4
|
+
|
|
5
|
+
Claude Code、OpenCode 等 AI 编程工具只认 UTF-8,但你的项目偏偏是 GB18030。本工具通过 Hook 机制在 AI 读写文件时自动完成编码转换,全程无感知,文件编码纹丝不动。
|
|
6
|
+
|
|
7
|
+
## 原理
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
AI 读文件 → [Hook: GB18030 → UTF-8] → AI 正常工作 → [Hook: UTF-8 → GB18030] → 文件原封不动
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
| 工具 | 调用前 | 调用后 |
|
|
14
|
+
|------|--------|--------|
|
|
15
|
+
| **Read / Edit** | 转为 UTF-8,记录原始编码 | 还原为原始编码 |
|
|
16
|
+
| **Write** | 仅记录原始编码 | 将 AI 写入的内容转为原始编码 |
|
|
17
|
+
|
|
18
|
+
## 快速开始
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npx encoding-converter-ai
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
交互式安装器会自动检测依赖、引导选择目标平台并完成配置。
|
|
25
|
+
|
|
26
|
+
**前置依赖:** Node.js ≥ 18 · Python 3 · chardet(`pip install chardet`)
|
|
27
|
+
|
|
28
|
+
## 项目配置
|
|
29
|
+
|
|
30
|
+
在项目根目录放置 `.encoding-converter.json`(可选):
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"sourceEncoding": "GB18030",
|
|
35
|
+
"confidenceThreshold": 0.6,
|
|
36
|
+
"defaultEncoding": "GB18030"
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
| 字段 | 默认值 | 说明 |
|
|
41
|
+
|------|--------|------|
|
|
42
|
+
| `sourceEncoding` | `GB18030` | 项目源文件编码 |
|
|
43
|
+
| `confidenceThreshold` | `0.8` | chardet 置信度阈值 |
|
|
44
|
+
| `defaultEncoding` | — | 置信度不足时的回落编码,建议设置以避免误判漏转 |
|
|
45
|
+
|
|
46
|
+
## 恢复与卸载
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# 崩溃后恢复残留在 UTF-8 状态的文件
|
|
50
|
+
npx encoding-converter-ai cleanup
|
|
51
|
+
npx encoding-converter-ai cleanup --all # 扫描所有项目
|
|
52
|
+
|
|
53
|
+
# 一键卸载,移除所有 hook 和插件
|
|
54
|
+
npx encoding-converter-ai uninstall
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
> 建议在首次使用前做一次版本控制提交,以备万一。
|
|
58
|
+
|
|
59
|
+
## 设计要点
|
|
60
|
+
|
|
61
|
+
- **编码检测** — 基于 Python chardet,对 GB18030/GBK/GB2312 等 CJK 编码的识别远优于纯 JS 方案
|
|
62
|
+
- **并发安全** — 原子文件锁 + 每文件独立状态 + SHA-256 完整性校验,多会话互不干扰
|
|
63
|
+
- **静默容错** — Hook 出错时绝不阻断 AI 工具,只写日志不报异常
|
|
64
|
+
- **日志调试** — 日志位于 `~/.encoding-converter/logs/converter.log`,通过 `ENCODING_CONVERTER_LOG=debug|info|error` 控制级别
|
|
65
|
+
|
|
66
|
+
## 支持平台
|
|
67
|
+
|
|
68
|
+
| 平台 | Hook 机制 |
|
|
69
|
+
|------|-----------|
|
|
70
|
+
| [Claude Code](https://docs.anthropic.com/en/docs/claude-code) | PreToolUse / PostToolUse / PostToolUseFailure |
|
|
71
|
+
| [OpenCode](https://github.com/opencode-ai/opencode) | tool.execute.before / tool.execute.after |
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
MIT
|