codepage-bridge-mcp 0.1.0 → 0.1.6
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.mcp.json +2 -10
- package/README.md +81 -764
- package/README_CN.md +161 -584
- package/dist/src/core.d.ts +3 -2
- package/dist/src/core.js +46 -18
- package/dist/src/core.js.map +1 -1
- package/dist/src/filesystem/cache.d.ts +1 -2
- package/dist/src/filesystem/cache.js +9 -17
- package/dist/src/filesystem/cache.js.map +1 -1
- package/dist/src/limits.d.ts +2 -0
- package/dist/src/limits.js +17 -0
- package/dist/src/limits.js.map +1 -0
- package/dist/src/tools/grep.js +81 -28
- package/dist/src/tools/grep.js.map +1 -1
- package/dist/src/tools/read.js +5 -0
- package/dist/src/tools/read.js.map +1 -1
- package/dist/src/tools/write.js +1 -1
- package/dist/src/tools/write.js.map +1 -1
- package/install/install-unix.sh +29 -0
- package/install/install-windows.ps1 +29 -0
- package/package.json +1 -1
package/README_CN.md
CHANGED
|
@@ -2,350 +2,120 @@
|
|
|
2
2
|
|
|
3
3
|
[English README](README.md)
|
|
4
4
|
|
|
5
|
-
Codepage Bridge
|
|
5
|
+
Codepage Bridge 是给 Claude Code 用的一组文件工具。
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
它解决的问题很简单:
|
|
8
8
|
|
|
9
|
-
- `Read`
|
|
10
|
-
- `Grep`
|
|
11
|
-
- `Edit`
|
|
12
|
-
- `Write`
|
|
9
|
+
如果你的项目不是 UTF-8,而是 GBK、Big5、Shift-JIS、UTF-16 这类编码,Claude Code 自带的 `Read`、`Grep`、`Edit`、`Write` 很容易把文件读乱、搜错、改坏。
|
|
13
10
|
|
|
14
|
-
|
|
11
|
+
Codepage Bridge 会按项目里的 `.encoding-rules` 读写文件:
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
-
|
|
19
|
-
- 磁盘上的文件仍保持项目原本的编码体系;
|
|
20
|
-
- 如果新文本无法表示为目标编码,会直接报错,而不是偷偷写成 `?`。
|
|
13
|
+
- 读文件时,先按规则解码,再把正常文字给模型;
|
|
14
|
+
- 改文件时,按原规则再写回去;
|
|
15
|
+
- 如果新内容不能用目标编码表示,会直接报错,而不是偷偷写坏。
|
|
21
16
|
|
|
22
17
|
---
|
|
23
18
|
|
|
24
|
-
##
|
|
25
|
-
|
|
26
|
-
你现在有三种安装方式:
|
|
27
|
-
|
|
28
|
-
### 方案 A:Marketplace 安装(即将提供)
|
|
29
|
-
|
|
30
|
-
这将来会成为普通用户最简单的安装方式。
|
|
31
|
-
|
|
32
|
-
目标体验:
|
|
33
|
-
|
|
34
|
-
- market 一键安装;
|
|
35
|
-
- 自动注册 MCP;
|
|
36
|
-
- 不需要本地 `git clone`;
|
|
37
|
-
- 不需要本地 `npm install`;
|
|
38
|
-
- 安装后只需极少量手动配置。
|
|
39
|
-
|
|
40
|
-
目前还没上 market,所以现在请使用 **GitHub Release 安装**。
|
|
41
|
-
|
|
42
|
-
### 方案 B:GitHub Release 安装(当前最推荐)
|
|
43
|
-
|
|
44
|
-
这是当前最适合普通用户的安装方式。
|
|
45
|
-
|
|
46
|
-
你有两种使用路径:
|
|
47
|
-
|
|
48
|
-
1. **你已经下载并解压好了 Release 包**;
|
|
49
|
-
2. **你想让脚本帮你下载 Release 包**。
|
|
50
|
-
|
|
51
|
-
这两种方式都**不需要**:
|
|
19
|
+
## 适合什么项目
|
|
52
20
|
|
|
53
|
-
|
|
54
|
-
- 本地 `npm install`
|
|
55
|
-
- 本地 `npm run build`
|
|
21
|
+
适合这些情况:
|
|
56
22
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
- `
|
|
60
|
-
-
|
|
61
|
-
|
|
62
|
-
### 方案 C:源码安装(仅面向开发者)
|
|
63
|
-
|
|
64
|
-
只有在以下场景才建议使用:
|
|
65
|
-
|
|
66
|
-
- 你要开发 Codepage Bridge 本身;
|
|
67
|
-
- 你要调试安装问题;
|
|
68
|
-
- 你要修改或审查源码实现。
|
|
69
|
-
|
|
70
|
-
如果你只是普通使用者,不建议把源码安装作为首选入口。
|
|
23
|
+
- C / C++ 老项目还在用 GBK;
|
|
24
|
+
- Windows 老项目用 `windows-1251`、`windows-1252`;
|
|
25
|
+
- 日文项目用 `Shift-JIS`;
|
|
26
|
+
- 一部分文件是 UTF-16;
|
|
27
|
+
- Claude Code 一读文件就乱码,或者一改文件就把编码改坏。
|
|
71
28
|
|
|
72
29
|
---
|
|
73
30
|
|
|
74
|
-
##
|
|
75
|
-
|
|
76
|
-
这是普通用户当前最合适的安装方式。
|
|
77
|
-
|
|
78
|
-
### 路径 1:你已经下载并解压好了 Release 包
|
|
79
|
-
|
|
80
|
-
如果你当前就处于一个已解压好的 Release 包目录中,推荐直接使用本地包安装脚本。
|
|
81
|
-
|
|
82
|
-
#### Windows
|
|
83
|
-
|
|
84
|
-
```powershell
|
|
85
|
-
powershell -ExecutionPolicy Bypass -File .\install\install-this-release-windows.ps1
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
#### macOS / Linux
|
|
31
|
+
## 安装(推荐方式)
|
|
89
32
|
|
|
90
|
-
|
|
91
|
-
bash ./install/install-this-release-unix.sh
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
它会:
|
|
95
|
-
|
|
96
|
-
- 检查当前目录是否真的包含 `dist/src/server.js`;
|
|
97
|
-
- 直接使用当前解压包注册 Claude Code MCP;
|
|
98
|
-
- **不会再次下载**。
|
|
33
|
+
只需要执行下面两条命令:
|
|
99
34
|
|
|
100
|
-
###
|
|
101
|
-
|
|
102
|
-
如果你希望脚本自动去 GitHub Release 下载,再注册 MCP,使用下载脚本。
|
|
103
|
-
|
|
104
|
-
#### Windows
|
|
35
|
+
### Windows
|
|
105
36
|
|
|
106
37
|
```powershell
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
#### macOS / Linux
|
|
38
|
+
# 如果以前装过同名的旧版本,先删除旧配置。
|
|
39
|
+
claude mcp remove codepage-bridge -s user
|
|
111
40
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
它会:
|
|
117
|
-
|
|
118
|
-
- 请求 GitHub Release API;
|
|
119
|
-
- 下载当前平台对应的发布包;
|
|
120
|
-
- 解压到用户目录;
|
|
121
|
-
- 自动注册 Claude Code MCP。
|
|
122
|
-
|
|
123
|
-
### 安装指定版本
|
|
124
|
-
|
|
125
|
-
#### Windows
|
|
126
|
-
|
|
127
|
-
```powershell
|
|
128
|
-
powershell -ExecutionPolicy Bypass -File .\install\download-release-windows.ps1 -Version v0.1.0
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
#### macOS / Linux
|
|
132
|
-
|
|
133
|
-
```bash
|
|
134
|
-
bash ./install/download-release-unix.sh v0.1.0
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
### 兼容脚本
|
|
138
|
-
|
|
139
|
-
仓库中保留了兼容入口:
|
|
140
|
-
|
|
141
|
-
- `install-from-release-windows.ps1`
|
|
142
|
-
- `install-from-release-unix.sh`
|
|
143
|
-
|
|
144
|
-
它们的行为是:
|
|
145
|
-
|
|
146
|
-
- 如果当前目录已经是解压包,就直接本地安装;
|
|
147
|
-
- 如果当前目录不是解压包,就回退到下载模式。
|
|
148
|
-
|
|
149
|
-
因此更清晰的推荐是直接使用:
|
|
150
|
-
|
|
151
|
-
- `install-this-release-*`
|
|
152
|
-
- `download-release-*`
|
|
153
|
-
|
|
154
|
-
而不是继续依赖兼容入口。
|
|
155
|
-
|
|
156
|
-
---
|
|
157
|
-
|
|
158
|
-
## 源码安装(仅面向开发者)
|
|
159
|
-
|
|
160
|
-
只有在以下场景才建议使用:
|
|
161
|
-
|
|
162
|
-
- 你要开发 Codepage Bridge 本身;
|
|
163
|
-
- 你要调试安装问题;
|
|
164
|
-
- 你要修改或审查源码实现。
|
|
165
|
-
|
|
166
|
-
### 1. 克隆仓库
|
|
167
|
-
|
|
168
|
-
```bash
|
|
169
|
-
git clone git@github.com:skyispainted/codepage-bridge-mcp.git
|
|
170
|
-
cd codepage-bridge-mcp
|
|
41
|
+
# 只在用户级注册一次 npm 包。Windows 需要使用 `cmd` 包装启动器。
|
|
42
|
+
claude mcp add --scope user codepage-bridge -- cmd /d /s /c "npx -y codepage-bridge-mcp"
|
|
43
|
+
claude mcp get codepage-bridge
|
|
171
44
|
```
|
|
172
45
|
|
|
173
|
-
###
|
|
46
|
+
### macOS / Linux
|
|
174
47
|
|
|
175
48
|
```bash
|
|
176
|
-
|
|
177
|
-
|
|
49
|
+
# 如果以前装过同名的旧版本,先删除旧配置。
|
|
50
|
+
claude mcp remove codepage-bridge -s user
|
|
178
51
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
npm run build
|
|
52
|
+
# 只在用户级注册一次 npm 包。
|
|
53
|
+
claude mcp add --scope user codepage-bridge -- npx -y codepage-bridge-mcp
|
|
54
|
+
claude mcp get codepage-bridge
|
|
183
55
|
```
|
|
184
56
|
|
|
185
|
-
|
|
57
|
+
如果第二条命令显示 `Connected`,说明安装成功。
|
|
186
58
|
|
|
187
|
-
|
|
188
|
-
dist/src/server.js
|
|
189
|
-
```
|
|
59
|
+
### 避免重复注册
|
|
190
60
|
|
|
191
|
-
|
|
61
|
+
`codepage-bridge` 只能在一个配置范围内注册一次。若用户级旧配置仍指向本机构建、而项目 `.mcp.json` 又指向 npm 包,Claude Code 会把同名但命令不同的服务报告为冲突。
|
|
192
62
|
|
|
193
|
-
|
|
63
|
+
用 `claude mcp list` 查看重复项,保留要使用的端点,再删除另一项:
|
|
194
64
|
|
|
195
65
|
```powershell
|
|
196
|
-
|
|
197
|
-
|
|
66
|
+
# 保留用户级 npm 安装时,删除项目级配置。
|
|
67
|
+
claude mcp remove codepage-bridge -s project
|
|
198
68
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
```bash
|
|
202
|
-
test -f ./dist/src/server.js && echo ok
|
|
69
|
+
# 保留项目级配置时,删除旧的用户级安装。
|
|
70
|
+
claude mcp remove codepage-bridge -s user
|
|
203
71
|
```
|
|
204
72
|
|
|
205
|
-
|
|
73
|
+
删除后重新运行 `claude mcp get codepage-bridge`。只有一个端点且状态为 `Connected` 才表示配置正确。
|
|
206
74
|
|
|
207
|
-
|
|
75
|
+
### 大文本文件
|
|
76
|
+
|
|
77
|
+
`Read` 和 `Grep` 默认允许单个文本文件最大为 `32 MiB`。如需调整,在启动 Claude Code 前把 `CODEPAGE_BRIDGE_MAX_TEXT_FILE_MIB` 设为正整数:
|
|
208
78
|
|
|
209
79
|
```powershell
|
|
210
|
-
|
|
80
|
+
setx CODEPAGE_BRIDGE_MAX_TEXT_FILE_MIB 64
|
|
211
81
|
```
|
|
212
82
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
```bash
|
|
216
|
-
bash ./install/install-from-source-unix.sh
|
|
217
|
-
```
|
|
83
|
+
修改环境变量后请重启 Claude Code。文件越大,解码、按行拆分和正则匹配所需的 Node.js 内存越多。
|
|
218
84
|
|
|
219
85
|
---
|
|
220
86
|
|
|
221
|
-
##
|
|
222
|
-
|
|
223
|
-
如果你的项目还在使用这些编码:
|
|
224
|
-
|
|
225
|
-
- GBK / GB2312 / GB18030
|
|
226
|
-
- Big5
|
|
227
|
-
- Shift-JIS
|
|
228
|
-
- EUC-KR
|
|
229
|
-
- Windows-1251 / Windows-1252
|
|
230
|
-
- UTF-16
|
|
231
|
-
|
|
232
|
-
那么 Claude Code 的内置 `Read` / `Grep` / `Edit` / `Write` 很容易出现:
|
|
233
|
-
|
|
234
|
-
- 中文注释乱码;
|
|
235
|
-
- 搜索不到真实内容;
|
|
236
|
-
- 编辑后把文件误写成 UTF-8;
|
|
237
|
-
- 旧代码页文件被破坏。
|
|
87
|
+
## 安装前提
|
|
238
88
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
---
|
|
242
|
-
|
|
243
|
-
## 核心特性
|
|
244
|
-
|
|
245
|
-
- 按 `.encoding-rules` 透明解码/写回。
|
|
246
|
-
- 支持 `Read`、`Grep`、`Edit`、`Write`。
|
|
247
|
-
- 最近的 `.encoding-rules` 决定项目根与生效规则。
|
|
248
|
-
- 最后一条匹配规则生效。
|
|
249
|
-
- `!pattern` 表示取消之前匹配并回到严格 UTF-8。
|
|
250
|
-
- `*.cpp` 这类无目录分隔符规则会匹配任意层级目录。
|
|
251
|
-
- `Edit` 支持大文件局部编辑:只要模型读过目标行,就可以修改,不必整文件读取。
|
|
252
|
-
- 写入前会重新读取并做 hash 校验,防止 stale write。
|
|
253
|
-
- 保留 BOM 与主导换行风格。
|
|
254
|
-
- 原子写入、路径锁、符号链接边界保护。
|
|
255
|
-
- 支持图片、PDF、Notebook 的读取。
|
|
256
|
-
|
|
257
|
-
---
|
|
89
|
+
你的电脑里需要已经有:
|
|
258
90
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
需要本机已经安装:
|
|
262
|
-
|
|
263
|
-
- Node.js 20+
|
|
264
|
-
- npm(仅源码安装需要)
|
|
265
|
-
- Claude Code
|
|
266
|
-
|
|
267
|
-
可选:
|
|
268
|
-
|
|
269
|
-
- `pdfinfo`
|
|
270
|
-
- `pdftoppm`
|
|
91
|
+
- `claude`
|
|
92
|
+
- `node`
|
|
271
93
|
|
|
272
|
-
|
|
94
|
+
可以先检查:
|
|
273
95
|
|
|
274
|
-
### Windows
|
|
96
|
+
### Windows
|
|
275
97
|
|
|
276
98
|
```powershell
|
|
277
|
-
node --version
|
|
278
|
-
npm --version
|
|
279
99
|
claude --version
|
|
100
|
+
node --version
|
|
280
101
|
```
|
|
281
102
|
|
|
282
|
-
### macOS / Linux
|
|
103
|
+
### macOS / Linux
|
|
283
104
|
|
|
284
105
|
```bash
|
|
285
|
-
node --version
|
|
286
|
-
npm --version
|
|
287
106
|
claude --version
|
|
107
|
+
node --version
|
|
288
108
|
```
|
|
289
109
|
|
|
290
110
|
---
|
|
291
111
|
|
|
292
|
-
##
|
|
293
|
-
|
|
294
|
-
你可以按两种范围安装:
|
|
295
|
-
|
|
296
|
-
- **用户级**:所有项目通用;
|
|
297
|
-
- **项目级**:跟随某一个仓库。
|
|
298
|
-
|
|
299
|
-
### 方案 A:用户级安装
|
|
300
|
-
|
|
301
|
-
#### Windows
|
|
302
|
-
|
|
303
|
-
```powershell
|
|
304
|
-
claude mcp add --scope user codepage-bridge -- node C:\absolute\path\to\codepage-bridge-mcp\dist\src\server.js
|
|
305
|
-
```
|
|
112
|
+
## 安装完以后,还必须做的三件事
|
|
306
113
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
```bash
|
|
310
|
-
claude mcp add --scope user codepage-bridge -- node /absolute/path/to/codepage-bridge-mcp/dist/src/server.js
|
|
311
|
-
```
|
|
114
|
+
安装 MCP 只是第一步。要让 Claude Code 真正稳定地使用它,还要做下面三件事。
|
|
312
115
|
|
|
313
|
-
|
|
116
|
+
### 1. 禁用 Claude Code 内置文件工具
|
|
314
117
|
|
|
315
|
-
|
|
316
|
-
claude mcp get codepage-bridge
|
|
317
|
-
claude mcp list
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
### 方案 B:项目级安装
|
|
321
|
-
|
|
322
|
-
在项目根目录创建 `.mcp.json`:
|
|
323
|
-
|
|
324
|
-
```json
|
|
325
|
-
{
|
|
326
|
-
"mcpServers": {
|
|
327
|
-
"codepage-bridge": {
|
|
328
|
-
"type": "stdio",
|
|
329
|
-
"command": "node",
|
|
330
|
-
"args": [
|
|
331
|
-
"/absolute/path/to/codepage-bridge-mcp/dist/src/server.js"
|
|
332
|
-
]
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
```
|
|
337
|
-
|
|
338
|
-
项目级模板见:
|
|
339
|
-
|
|
340
|
-
- `examples/minimal-project/.mcp.json`
|
|
341
|
-
|
|
342
|
-
---
|
|
343
|
-
|
|
344
|
-
## 最重要:必须禁用 Claude Code 内置文件工具
|
|
345
|
-
|
|
346
|
-
仅安装 MCP 还不够。
|
|
347
|
-
|
|
348
|
-
如果不禁用 Claude Code 内置工具,模型仍然可能继续调用:
|
|
118
|
+
不禁用的话,模型还是可能继续调用内置:
|
|
349
119
|
|
|
350
120
|
- `Read`
|
|
351
121
|
- `Grep`
|
|
@@ -355,9 +125,7 @@ claude mcp list
|
|
|
355
125
|
|
|
356
126
|
这些工具不会遵循 `.encoding-rules`。
|
|
357
127
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
把以下内容合并到现有文件中:
|
|
128
|
+
把下面内容合并到你的 `~/.claude/settings.json`:
|
|
361
129
|
|
|
362
130
|
```json
|
|
363
131
|
{
|
|
@@ -379,36 +147,49 @@ claude mcp list
|
|
|
379
147
|
}
|
|
380
148
|
```
|
|
381
149
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
模板见:
|
|
150
|
+
现成模板:
|
|
385
151
|
|
|
386
152
|
- `examples/claude-config/settings.fragment.json`
|
|
387
153
|
|
|
154
|
+
> 不要整份覆盖已有 `settings.json`,除非那个文件本来就是空的。
|
|
155
|
+
|
|
388
156
|
---
|
|
389
157
|
|
|
390
|
-
|
|
158
|
+
### 2. 加一个 `CLAUDE.md`
|
|
391
159
|
|
|
392
|
-
|
|
160
|
+
即使你禁掉了内置工具,模型仍可能想用 shell、PowerShell、Python 脚本去绕过编码桥。
|
|
393
161
|
|
|
394
|
-
|
|
162
|
+
所以建议在项目根目录加一个 `CLAUDE.md`,内容类似:
|
|
395
163
|
|
|
396
|
-
|
|
164
|
+
```markdown
|
|
165
|
+
## File encoding policy
|
|
397
166
|
|
|
398
|
-
|
|
167
|
+
Use Codepage Bridge for all project file content operations:
|
|
168
|
+
|
|
169
|
+
- Read with `mcp__codepage-bridge__Read`.
|
|
170
|
+
- Search with `mcp__codepage-bridge__Grep`.
|
|
171
|
+
- Edit with `mcp__codepage-bridge__Edit`.
|
|
172
|
+
- Create or completely rewrite with `mcp__codepage-bridge__Write`.
|
|
399
173
|
|
|
400
|
-
|
|
174
|
+
Do not use built-in Read, Grep, Edit, Write, NotebookEdit, shell commands,
|
|
175
|
+
PowerShell commands, or scripts as substitutes for project file content access.
|
|
176
|
+
Glob may only be used to discover paths.
|
|
177
|
+
|
|
178
|
+
Do not manually transcode files or normalize line endings. `.encoding-rules`
|
|
179
|
+
is the source of truth.
|
|
180
|
+
```
|
|
401
181
|
|
|
402
|
-
|
|
403
|
-
|
|
182
|
+
现成模板:
|
|
183
|
+
|
|
184
|
+
- `examples/minimal-project/CLAUDE.md`
|
|
404
185
|
|
|
405
186
|
---
|
|
406
187
|
|
|
407
|
-
|
|
188
|
+
### 3. 给项目加 `.encoding-rules`
|
|
408
189
|
|
|
409
190
|
每个要使用 Codepage Bridge 的项目根目录,都必须有 `.encoding-rules`。
|
|
410
191
|
|
|
411
|
-
|
|
192
|
+
例如:
|
|
412
193
|
|
|
413
194
|
```text
|
|
414
195
|
# Last matching rule wins
|
|
@@ -423,61 +204,58 @@ assets/**/*.csv shift_jis
|
|
|
423
204
|
!SourceCode/generated/**
|
|
424
205
|
```
|
|
425
206
|
|
|
426
|
-
|
|
207
|
+
现成模板:
|
|
427
208
|
|
|
428
|
-
|
|
429
|
-
<glob-pattern> <encoding>
|
|
430
|
-
```
|
|
209
|
+
- `examples/minimal-project/.encoding-rules`
|
|
431
210
|
|
|
432
|
-
|
|
211
|
+
规则含义:
|
|
433
212
|
|
|
434
|
-
-
|
|
435
|
-
-
|
|
436
|
-
-
|
|
437
|
-
-
|
|
438
|
-
- 含 `/` 的模式相对于 `.encoding-rules` 所在目录;
|
|
439
|
-
- 最后一条匹配规则生效;
|
|
440
|
-
- `!pattern` 取消先前匹配,回到严格 UTF-8;
|
|
441
|
-
- 未命中规则的文件使用严格 UTF-8;
|
|
442
|
-
- 最近的 `.encoding-rules` 同时决定项目根边界。
|
|
213
|
+
- `*.cpp gbk`:所有 cpp 文件按 GBK 处理;
|
|
214
|
+
- `**/*.json utf8`:所有 JSON 按 UTF-8;
|
|
215
|
+
- `!pattern`:取消前面的规则,回到严格 UTF-8;
|
|
216
|
+
- 最后一条匹配规则生效。
|
|
443
217
|
|
|
444
|
-
|
|
218
|
+
---
|
|
445
219
|
|
|
446
|
-
|
|
220
|
+
## 怎么确认它真的在工作
|
|
447
221
|
|
|
448
|
-
|
|
222
|
+
### 第一步:检查 MCP 已连接
|
|
449
223
|
|
|
450
|
-
|
|
224
|
+
```bash
|
|
225
|
+
claude mcp get codepage-bridge
|
|
226
|
+
```
|
|
451
227
|
|
|
452
|
-
|
|
228
|
+
你应该看到:
|
|
453
229
|
|
|
454
|
-
-
|
|
455
|
-
- `
|
|
456
|
-
- `examples/minimal-project/CLAUDE.md`
|
|
457
|
-
- `examples/claude-config/settings.fragment.json`
|
|
230
|
+
- 名称:`codepage-bridge`
|
|
231
|
+
- 状态:`Connected`
|
|
458
232
|
|
|
459
|
-
|
|
233
|
+
### 第二步:重开一个新的 Claude Code 会话
|
|
460
234
|
|
|
461
|
-
|
|
235
|
+
### 第三步:让 Claude 读取或搜索一个旧编码文件
|
|
462
236
|
|
|
463
|
-
|
|
237
|
+
例如:
|
|
464
238
|
|
|
465
|
-
```
|
|
466
|
-
|
|
239
|
+
```text
|
|
240
|
+
Read SourceCode/Main.cpp and show the first 10 lines.
|
|
467
241
|
```
|
|
468
242
|
|
|
469
|
-
|
|
243
|
+
或者:
|
|
244
|
+
|
|
245
|
+
```text
|
|
246
|
+
Search SourceCode for the string 错误码.
|
|
247
|
+
```
|
|
470
248
|
|
|
471
|
-
###
|
|
249
|
+
### 第四步:确认它调用的是桥接工具
|
|
472
250
|
|
|
473
|
-
|
|
251
|
+
应该调用:
|
|
474
252
|
|
|
475
253
|
- `mcp__codepage-bridge__Read`
|
|
476
254
|
- `mcp__codepage-bridge__Grep`
|
|
477
255
|
- `mcp__codepage-bridge__Edit`
|
|
478
256
|
- `mcp__codepage-bridge__Write`
|
|
479
257
|
|
|
480
|
-
|
|
258
|
+
不应该调用:
|
|
481
259
|
|
|
482
260
|
- `Read`
|
|
483
261
|
- `Grep`
|
|
@@ -486,295 +264,94 @@ claude mcp get codepage-bridge
|
|
|
486
264
|
|
|
487
265
|
---
|
|
488
266
|
|
|
489
|
-
##
|
|
267
|
+
## 它具体能做什么
|
|
490
268
|
|
|
491
|
-
###
|
|
269
|
+
### Read
|
|
492
270
|
|
|
493
|
-
- 按 `.encoding-rules`
|
|
494
|
-
-
|
|
495
|
-
-
|
|
496
|
-
- 同一文件多次分段 Read 会合并覆盖范围;
|
|
497
|
-
- 文件变化后覆盖状态会失效;
|
|
498
|
-
- 支持图片、PDF 页面和 Notebook 读取;
|
|
499
|
-
- Notebook 不支持文本行级 `offset/limit`。
|
|
271
|
+
- 按 `.encoding-rules` 解码文件;
|
|
272
|
+
- 大文件支持 `offset` / `limit` 分段读;
|
|
273
|
+
- 支持图片、PDF、Notebook 读取。
|
|
500
274
|
|
|
501
|
-
###
|
|
275
|
+
### Grep
|
|
502
276
|
|
|
277
|
+
- 支持按内容搜索;
|
|
503
278
|
- 支持 `content` / `files_with_matches` / `count`;
|
|
504
|
-
- 支持 `glob
|
|
505
|
-
- 支持常见 `type` 过滤;
|
|
506
|
-
- 支持 `-i` / `-n` / `-o`;
|
|
507
|
-
- 支持 `-A` / `-B` / `-C` / `context`;
|
|
508
|
-
- 支持 `multiline`;
|
|
509
|
-
- 支持 `head_limit` / `offset`。
|
|
279
|
+
- 支持 `glob`、`type`、上下文行、分页。
|
|
510
280
|
|
|
511
|
-
###
|
|
281
|
+
### Edit
|
|
512
282
|
|
|
513
283
|
- 不要求整文件都读完;
|
|
514
|
-
-
|
|
515
|
-
-
|
|
516
|
-
-
|
|
517
|
-
- 保留原编码、BOM 和主导换行;
|
|
518
|
-
- 无法表示的字符会拒绝写入。
|
|
284
|
+
- 只要目标行已经读过,就可以改;
|
|
285
|
+
- 改之前会重新检查文件有没有变化;
|
|
286
|
+
- 保留原编码、BOM 和换行风格。
|
|
519
287
|
|
|
520
|
-
###
|
|
288
|
+
### Write
|
|
521
289
|
|
|
522
290
|
- 新文件按 `.encoding-rules` 选择编码;
|
|
523
|
-
-
|
|
524
|
-
-
|
|
525
|
-
- 整体重写按调用方换行内容写回。
|
|
526
|
-
|
|
527
|
-
---
|
|
528
|
-
|
|
529
|
-
## NPM_TOKEN 自动发布说明
|
|
530
|
-
|
|
531
|
-
GitHub Release workflow 现在会在打包 release 资产之前,先自动发布 npm 包。
|
|
532
|
-
|
|
533
|
-
仓库维护者必须在 GitHub Secrets 中配置:
|
|
534
|
-
|
|
535
|
-
- NPM_TOKEN`r
|
|
536
|
-
|
|
537
|
-
重要:如果某个 npm token 曾经被贴到聊天、终端截图、日志或其他公开位置,请立即在 npm 后台撤销并重新生成新的发布 token,再写入 GitHub Secrets。
|
|
538
|
-
|
|
539
|
-
## 维护者发布流程
|
|
540
|
-
|
|
541
|
-
发布新版本:
|
|
542
|
-
|
|
543
|
-
```bash
|
|
544
|
-
git tag v0.1.0
|
|
545
|
-
git push origin v0.1.0
|
|
546
|
-
```
|
|
547
|
-
|
|
548
|
-
GitHub Release workflow 会自动:`r`n`r`n- 使用 `NPM_TOKEN` 自动发布 npm 包;
|
|
549
|
-
|
|
550
|
-
- 执行类型检查;
|
|
551
|
-
- 执行完整测试;
|
|
552
|
-
- 构建项目;
|
|
553
|
-
- 裁剪开发依赖;
|
|
554
|
-
- 打包多平台产物;
|
|
555
|
-
- 生成 SHA256 校验文件;
|
|
556
|
-
- 上传到 GitHub Releases。
|
|
291
|
+
- 已有文件要求先完整读过;
|
|
292
|
+
- 会保留已有文件的编码和 BOM。
|
|
557
293
|
|
|
558
294
|
---
|
|
559
295
|
|
|
560
|
-
##
|
|
561
|
-
|
|
562
|
-
仓库现在已经具备 npm 发布条件。
|
|
563
|
-
|
|
564
|
-
### 发布包内容
|
|
565
|
-
|
|
566
|
-
最终 npm 包只包含:
|
|
567
|
-
|
|
568
|
-
- `dist/src/`
|
|
569
|
-
- `.claude-plugin/`
|
|
570
|
-
- `.mcp.json`
|
|
571
|
-
- `install/`
|
|
572
|
-
- `examples/`
|
|
573
|
-
- `README.md`
|
|
574
|
-
- `README_CN.md`
|
|
575
|
-
- `LICENSE`
|
|
576
|
-
|
|
577
|
-
不会发布:
|
|
578
|
-
|
|
579
|
-
- `src/`
|
|
580
|
-
- `test/`
|
|
581
|
-
- `node_modules/`
|
|
582
|
-
- 项目私有 `.claude/`
|
|
583
|
-
- 本地构建缓存
|
|
584
|
-
|
|
585
|
-
### 发布前检查
|
|
586
|
-
|
|
587
|
-
`prepublishOnly` 已配置为自动执行:
|
|
588
|
-
|
|
589
|
-
```bash
|
|
590
|
-
npm run check
|
|
591
|
-
npm test
|
|
592
|
-
npm run build
|
|
593
|
-
```
|
|
594
|
-
|
|
595
|
-
### 打包预检查
|
|
596
|
-
|
|
597
|
-
正式发布前先执行:
|
|
296
|
+
## 常见问题
|
|
598
297
|
|
|
599
|
-
|
|
600
|
-
npm pack --dry-run
|
|
601
|
-
```
|
|
602
|
-
|
|
603
|
-
用于确认最终发布包内容。
|
|
604
|
-
|
|
605
|
-
### 发布步骤
|
|
606
|
-
|
|
607
|
-
1. 登录 npm:
|
|
608
|
-
|
|
609
|
-
```bash
|
|
610
|
-
npm login
|
|
611
|
-
```
|
|
298
|
+
### 1. `No .encoding-rules found`
|
|
612
299
|
|
|
613
|
-
|
|
300
|
+
说明项目根没有 `.encoding-rules`,或者你读的文件不在项目根范围内。
|
|
614
301
|
|
|
615
|
-
|
|
616
|
-
npm publish
|
|
617
|
-
```
|
|
618
|
-
|
|
619
|
-
3. 验证:
|
|
620
|
-
|
|
621
|
-
```bash
|
|
622
|
-
npx -y codepage-bridge-mcp
|
|
623
|
-
```
|
|
302
|
+
### 2. `Invalid byte sequence for utf-8`
|
|
624
303
|
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
```json
|
|
628
|
-
{
|
|
629
|
-
"mcpServers": {
|
|
630
|
-
"codepage-bridge": {
|
|
631
|
-
"command": "npx",
|
|
632
|
-
"args": ["-y", "codepage-bridge-mcp"]
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
```
|
|
637
|
-
## 最终的 Marketplace 发布与安装方案
|
|
638
|
-
|
|
639
|
-
Codepage Bridge 现在已经同时具备:
|
|
640
|
-
|
|
641
|
-
- **插件结构就绪**
|
|
642
|
-
- **npm 发布就绪**
|
|
643
|
-
|
|
644
|
-
### 已经完成的部分
|
|
645
|
-
|
|
646
|
-
- 插件清单已就绪:
|
|
647
|
-
- `.claude-plugin/plugin.json`
|
|
648
|
-
- `.claude-plugin/marketplace.json`
|
|
649
|
-
- 插件根 MCP 声明已就绪:
|
|
650
|
-
- `.mcp.json`
|
|
651
|
-
- 插件命令已就绪:
|
|
652
|
-
- `/setup`
|
|
653
|
-
- `/setup-project`
|
|
654
|
-
- `/doctor`
|
|
655
|
-
- `package.json` 已具备 npm 发布所需元数据
|
|
656
|
-
- `npm pack --dry-run` 已验证通过
|
|
657
|
-
- `claude plugin validate . --strict` 已通过
|
|
658
|
-
|
|
659
|
-
### 在真正支持 market 安装之前,还差什么
|
|
660
|
-
|
|
661
|
-
1. 登录 npm
|
|
662
|
-
2. 发布 `codepage-bridge-mcp`
|
|
663
|
-
3. 把本仓库加入 Claude Code marketplace 源
|
|
664
|
-
4. 从 market 安装插件
|
|
665
|
-
|
|
666
|
-
### 实际发布清单
|
|
667
|
-
|
|
668
|
-
本地执行:
|
|
669
|
-
|
|
670
|
-
```bash
|
|
671
|
-
npm login
|
|
672
|
-
npm whoami
|
|
673
|
-
npm pack --dry-run
|
|
674
|
-
npm publish
|
|
675
|
-
```
|
|
304
|
+
说明这个文件实际上不是 UTF-8,但你的规则没匹配到它。
|
|
676
305
|
|
|
677
|
-
|
|
306
|
+
最常见修法:
|
|
678
307
|
|
|
679
|
-
```
|
|
680
|
-
|
|
308
|
+
```text
|
|
309
|
+
*.cpp gbk
|
|
310
|
+
*.h gbk
|
|
681
311
|
```
|
|
682
312
|
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
### npm 发布后,market 安装的目标流程
|
|
686
|
-
|
|
687
|
-
1. 在 Claude Code 中添加或更新 marketplace 源
|
|
688
|
-
2. 从 marketplace 安装插件
|
|
689
|
-
3. 执行 `/setup`
|
|
690
|
-
4. 合并 `examples/claude-config/settings.fragment.json`
|
|
691
|
-
5. 添加项目 `.encoding-rules`
|
|
692
|
-
6. 添加 `CLAUDE.md` 策略
|
|
693
|
-
|
|
694
|
-
### 重要限制
|
|
695
|
-
|
|
696
|
-
market 安装可以安装插件并声明 MCP,但想安全使用仍然依赖项目配置:
|
|
697
|
-
|
|
698
|
-
- deny 内置 `Read` / `Grep` / `Edit` / `Write` / `NotebookEdit`
|
|
699
|
-
- 所有文件内容操作必须走 Codepage Bridge
|
|
700
|
-
- legacy 编码项目必须提供 `.encoding-rules`
|
|
701
|
-
## 常见问题排查
|
|
702
|
-
|
|
703
|
-
### `No .encoding-rules found`
|
|
704
|
-
|
|
705
|
-
原因:
|
|
706
|
-
|
|
707
|
-
- 项目根没有 `.encoding-rules`;
|
|
708
|
-
- 访问文件不在项目树内。
|
|
709
|
-
|
|
710
|
-
### `Invalid byte sequence for utf-8`
|
|
711
|
-
|
|
712
|
-
原因:
|
|
713
|
-
|
|
714
|
-
- 文件实际不是 UTF-8;
|
|
715
|
-
- 规则没有匹配到目标文件。
|
|
313
|
+
### 3. `Text contains characters not representable in ...`
|
|
716
314
|
|
|
717
|
-
|
|
315
|
+
说明你要写入的新字符,目标编码表示不了。
|
|
718
316
|
|
|
719
|
-
|
|
317
|
+
### 4. `The target text has not been read`
|
|
720
318
|
|
|
721
|
-
|
|
319
|
+
说明模型想改的那几行,它其实还没真正读过。按提示再补读那几行即可。
|
|
722
320
|
|
|
723
|
-
###
|
|
321
|
+
### 5. Claude 还是在用内置工具
|
|
724
322
|
|
|
725
|
-
|
|
323
|
+
通常是因为:
|
|
726
324
|
|
|
727
|
-
-
|
|
325
|
+
- 没有配置 `deny`
|
|
326
|
+
- 没加 `CLAUDE.md`
|
|
327
|
+
- 会话没重开
|
|
728
328
|
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
原因:
|
|
732
|
-
|
|
733
|
-
- 项目 `.mcp.json` 还没被批准。
|
|
734
|
-
|
|
735
|
-
### `Failed to connect`
|
|
736
|
-
|
|
737
|
-
检查:
|
|
738
|
-
|
|
739
|
-
- `node --version`
|
|
740
|
-
- `claude --version`
|
|
741
|
-
- `dist/src/server.js` 是否存在
|
|
742
|
-
- `claude mcp get codepage-bridge`
|
|
329
|
+
---
|
|
743
330
|
|
|
744
|
-
|
|
331
|
+
## 现成模板
|
|
745
332
|
|
|
746
|
-
|
|
333
|
+
仓库里已经带了最小模板:
|
|
747
334
|
|
|
748
|
-
-
|
|
749
|
-
-
|
|
750
|
-
-
|
|
335
|
+
- `examples/minimal-project/.encoding-rules`
|
|
336
|
+
- `examples/minimal-project/.mcp.json`
|
|
337
|
+
- `examples/minimal-project/CLAUDE.md`
|
|
338
|
+
- `examples/claude-config/settings.fragment.json`
|
|
751
339
|
|
|
752
340
|
---
|
|
753
341
|
|
|
754
|
-
##
|
|
342
|
+
## 开发者补充说明
|
|
755
343
|
|
|
756
|
-
|
|
757
|
-
2. 在大规模编辑前,先用 `Read` 或 `Grep` 验证规则是否匹配正确。
|
|
758
|
-
3. 优先用 basename 规则描述整类源码,例如 `*.cpp gbk`。
|
|
759
|
-
4. 不要静默转换编码。
|
|
760
|
-
5. 不要用 shell 或脚本绕过桥接层。
|
|
761
|
-
6. 该 MCP 对项目根内文件有读写能力,只应在可信项目中启用。
|
|
762
|
-
7. 编码安全不等于语义正确,仍需审查 diff。
|
|
763
|
-
8. PDF 支持依赖 Poppler,可选安装。
|
|
764
|
-
9. 不提供 `NotebookEdit`。
|
|
765
|
-
10. Windows UNC / device path 会在 I/O 前直接拒绝。
|
|
766
|
-
|
|
767
|
-
---
|
|
344
|
+
如果你是维护者或贡献者:
|
|
768
345
|
|
|
769
|
-
|
|
346
|
+
- npm 包已经可用:
|
|
347
|
+
```bash
|
|
348
|
+
npx -y codepage-bridge-mcp
|
|
349
|
+
```
|
|
350
|
+
- 仓库仍保留 GitHub Release 打包;
|
|
351
|
+
- 仓库也已经具备 plugin / marketplace 结构;
|
|
352
|
+
- 但这些都不是普通用户当前最推荐的安装路径。
|
|
770
353
|
|
|
771
|
-
|
|
772
|
-
npm install
|
|
773
|
-
npm run check
|
|
774
|
-
npm test
|
|
775
|
-
npm run build
|
|
776
|
-
npm start
|
|
777
|
-
```
|
|
354
|
+
---
|
|
778
355
|
|
|
779
356
|
## 许可证
|
|
780
357
|
|