encoding-aware-fs 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/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "encoding-aware-fs",
3
+ "version": "0.1.0",
4
+ "description": "Encoding-aware file operations MCP Server for AI tools working with GB18030 projects",
5
+ "main": "dist/server.js",
6
+ "bin": {
7
+ "encoding-aware-fs": "dist/index.js"
8
+ },
9
+ "scripts": {
10
+ "build": "node build.js",
11
+ "prepare": "node build.js",
12
+ "test": "vitest run",
13
+ "test:watch": "vitest",
14
+ "typecheck": "tsc --noEmit"
15
+ },
16
+ "keywords": ["mcp", "encoding", "gb18030", "utf-8", "claude-code", "opencode"],
17
+ "license": "MIT",
18
+ "dependencies": {
19
+ "@modelcontextprotocol/sdk": "^1.26.0",
20
+ "zod": "^3.25.0",
21
+ "iconv-lite": "^0.6.3",
22
+ "diff": "^8.0.3",
23
+ "@inquirer/prompts": "^7.0.0"
24
+ },
25
+ "devDependencies": {
26
+ "esbuild": "^0.20.0",
27
+ "typescript": "^5.5.0",
28
+ "vitest": "^3.0.0",
29
+ "@types/node": "^22.0.0"
30
+ }
31
+ }
@@ -0,0 +1,133 @@
1
+ ---
2
+ name: encoding-aware-fs
3
+ description: >
4
+ Use encoding-aware-fs MCP tools for all file operations in this project.
5
+ This project contains files encoded in GB18030/GBK/GB2312, and the MCP server
6
+ handles encoding detection and conversion transparently. Use this skill whenever
7
+ you are reading, writing, or editing files in this project — even if the user
8
+ doesn't mention encoding. The MCP tools replace the built-in Read, Write, and
9
+ Edit tools for any file inside the project directory.
10
+ ---
11
+
12
+ # Encoding-Aware File Operations
13
+
14
+ This project uses the **encoding-aware-fs** MCP server to handle files that may
15
+ be encoded in GB18030, GBK, or GB2312. The server automatically detects file
16
+ encoding and converts to/from UTF-8, so you always work with readable text.
17
+
18
+ ## Why This Matters
19
+
20
+ Many source files in this project are stored in GB18030 (a Chinese character
21
+ encoding). If you read them with the standard Read tool, Chinese text will appear
22
+ as garbled bytes. If you write UTF-8 content back without re-encoding, you'll
23
+ corrupt the file for other tools that expect GB18030. The MCP tools handle all
24
+ of this transparently.
25
+
26
+ ## Tool Mapping
27
+
28
+ Use these MCP tools **instead of** the built-in equivalents:
29
+
30
+ | Built-in Tool | MCP Tool | Purpose |
31
+ |---------------|---------------|--------------------------------------------|
32
+ | Read | `read_file` | Read file content (returns UTF-8) |
33
+ | Edit | `edit_file` | Find-and-replace edits (preserves encoding)|
34
+ | Write | `write_file` | Write content to file (encodes to original)|
35
+
36
+ ## Tool Parameters
37
+
38
+ ### read_file
39
+ ```json
40
+ {
41
+ "path": "/absolute/path/to/file.txt",
42
+ "head": 50,
43
+ "tail": 20
44
+ }
45
+ ```
46
+ - `path` (required): Absolute file path
47
+ - `head` (optional): Return only the first N lines
48
+ - `tail` (optional): Return only the last N lines
49
+ - Cannot specify both `head` and `tail`
50
+
51
+ ### edit_file
52
+ ```json
53
+ {
54
+ "path": "/absolute/path/to/file.txt",
55
+ "edits": [
56
+ { "oldText": "text to find", "newText": "replacement text" }
57
+ ],
58
+ "dryRun": false
59
+ }
60
+ ```
61
+ - `path` (required): Absolute file path
62
+ - `edits` (required): Array of `{oldText, newText}` replacements
63
+ - `dryRun` (optional): Preview changes without writing (returns unified diff)
64
+ - Supports exact match and fuzzy line-by-line matching with indentation preservation
65
+
66
+ ### write_file
67
+ ```json
68
+ {
69
+ "path": "/absolute/path/to/file.txt",
70
+ "content": "UTF-8 text content to write"
71
+ }
72
+ ```
73
+ - `path` (required): Absolute file path
74
+ - `content` (required): UTF-8 text to write
75
+ - Preserves existing file encoding; new files use project default encoding
76
+
77
+ ## Usage Examples
78
+
79
+ **Reading a GB18030-encoded source file:**
80
+ ```
81
+ Use read_file with path "/project/src/module.cpp"
82
+ → Returns clean UTF-8 text, Chinese characters display correctly
83
+ ```
84
+
85
+ **Editing a function in an encoded file:**
86
+ ```
87
+ Use edit_file with:
88
+ path: "/project/src/utils.cpp"
89
+ edits: [{ oldText: "旧的函数实现", newText: "新的函数实现" }]
90
+ → File stays in GB18030, only the targeted text changes
91
+ ```
92
+
93
+ **Writing a new file (inherits project encoding):**
94
+ ```
95
+ Use write_file with:
96
+ path: "/project/src/new-module.cpp"
97
+ content: "// 新模块\n#include <stdio.h>\n"
98
+ → Written in the project's default encoding (GB18030)
99
+ ```
100
+
101
+ ## When to Use MCP Tools vs Built-in Tools
102
+
103
+ **Use MCP tools (`read_file` / `edit_file` / `write_file`) for:**
104
+ - Any file inside the project directory
105
+ - Any file that might be GB-encoded
106
+ - All project source files, config files, and data files
107
+
108
+ **Use built-in tools (Read / Edit / Write) for:**
109
+ - Files outside the project directory (e.g., system files, other projects)
110
+ - Files that you know are not part of this project
111
+
112
+ ## Fallback Behavior
113
+
114
+ If an MCP tool call fails (e.g., server not running, connection error), fall back
115
+ to the built-in tool for that operation. The built-in tool won't handle encoding
116
+ conversion, but it's better than failing entirely. Inform the user that encoding
117
+ may not be handled correctly in this case.
118
+
119
+ ## Project Configuration
120
+
121
+ The file `.encoding-converter.json` in the project root controls encoding behavior:
122
+
123
+ ```json
124
+ {
125
+ "sourceEncoding": "GB18030",
126
+ "targetEncoding": "UTF-8",
127
+ "confidenceThreshold": 0.8
128
+ }
129
+ ```
130
+
131
+ - `sourceEncoding`: Default encoding for files when auto-detection is uncertain
132
+ - `targetEncoding`: Always UTF-8 (the encoding you see and produce)
133
+ - `confidenceThreshold`: Minimum confidence (0-1) to trust auto-detected encoding
@@ -0,0 +1,133 @@
1
+ ---
2
+ name: encoding-aware-fs
3
+ description: >
4
+ Use encoding-aware-fs MCP tools for all file operations in this project.
5
+ This project contains files encoded in GB18030/GBK/GB2312, and the MCP server
6
+ handles encoding detection and conversion transparently. Use this skill whenever
7
+ you are reading, writing, or editing files in this project — even if the user
8
+ doesn't mention encoding. The MCP tools replace the built-in file read/write/edit
9
+ tools for any file inside the project directory.
10
+ ---
11
+
12
+ # Encoding-Aware File Operations
13
+
14
+ This project uses the **encoding-aware-fs** MCP server to handle files that may
15
+ be encoded in GB18030, GBK, or GB2312. The server automatically detects file
16
+ encoding and converts to/from UTF-8, so you always work with readable text.
17
+
18
+ ## Why This Matters
19
+
20
+ Many source files in this project are stored in GB18030 (a Chinese character
21
+ encoding). If you read them with standard file tools, Chinese text will appear
22
+ as garbled bytes. If you write UTF-8 content back without re-encoding, you'll
23
+ corrupt the file for other tools that expect GB18030. The MCP tools handle all
24
+ of this transparently.
25
+
26
+ ## Tool Mapping
27
+
28
+ Use these MCP tools **instead of** the built-in equivalents:
29
+
30
+ | Action | MCP Tool | Purpose |
31
+ |----------------|---------------|--------------------------------------------|
32
+ | Read a file | `read_file` | Read file content (returns UTF-8) |
33
+ | Edit a file | `edit_file` | Find-and-replace edits (preserves encoding)|
34
+ | Write a file | `write_file` | Write content to file (encodes to original)|
35
+
36
+ ## Tool Parameters
37
+
38
+ ### read_file
39
+ ```json
40
+ {
41
+ "path": "/absolute/path/to/file.txt",
42
+ "head": 50,
43
+ "tail": 20
44
+ }
45
+ ```
46
+ - `path` (required): Absolute file path
47
+ - `head` (optional): Return only the first N lines
48
+ - `tail` (optional): Return only the last N lines
49
+ - Cannot specify both `head` and `tail`
50
+
51
+ ### edit_file
52
+ ```json
53
+ {
54
+ "path": "/absolute/path/to/file.txt",
55
+ "edits": [
56
+ { "oldText": "text to find", "newText": "replacement text" }
57
+ ],
58
+ "dryRun": false
59
+ }
60
+ ```
61
+ - `path` (required): Absolute file path
62
+ - `edits` (required): Array of `{oldText, newText}` replacements
63
+ - `dryRun` (optional): Preview changes without writing (returns unified diff)
64
+ - Supports exact match and fuzzy line-by-line matching with indentation preservation
65
+
66
+ ### write_file
67
+ ```json
68
+ {
69
+ "path": "/absolute/path/to/file.txt",
70
+ "content": "UTF-8 text content to write"
71
+ }
72
+ ```
73
+ - `path` (required): Absolute file path
74
+ - `content` (required): UTF-8 text to write
75
+ - Preserves existing file encoding; new files use project default encoding
76
+
77
+ ## Usage Examples
78
+
79
+ **Reading a GB18030-encoded source file:**
80
+ ```
81
+ Use read_file with path "/project/src/module.cpp"
82
+ → Returns clean UTF-8 text, Chinese characters display correctly
83
+ ```
84
+
85
+ **Editing a function in an encoded file:**
86
+ ```
87
+ Use edit_file with:
88
+ path: "/project/src/utils.cpp"
89
+ edits: [{ oldText: "旧的函数实现", newText: "新的函数实现" }]
90
+ → File stays in GB18030, only the targeted text changes
91
+ ```
92
+
93
+ **Writing a new file (inherits project encoding):**
94
+ ```
95
+ Use write_file with:
96
+ path: "/project/src/new-module.cpp"
97
+ content: "// 新模块\n#include <stdio.h>\n"
98
+ → Written in the project's default encoding (GB18030)
99
+ ```
100
+
101
+ ## When to Use MCP Tools vs Built-in Tools
102
+
103
+ **Use MCP tools (`read_file` / `edit_file` / `write_file`) for:**
104
+ - Any file inside the project directory
105
+ - Any file that might be GB-encoded
106
+ - All project source files, config files, and data files
107
+
108
+ **Use built-in tools for:**
109
+ - Files outside the project directory (e.g., system files, other projects)
110
+ - Files that you know are not part of this project
111
+
112
+ ## Fallback Behavior
113
+
114
+ If an MCP tool call fails (e.g., server not running, connection error), fall back
115
+ to the built-in tool for that operation. The built-in tool won't handle encoding
116
+ conversion, but it's better than failing entirely. Inform the user that encoding
117
+ may not be handled correctly in this case.
118
+
119
+ ## Project Configuration
120
+
121
+ The file `.encoding-converter.json` in the project root controls encoding behavior:
122
+
123
+ ```json
124
+ {
125
+ "sourceEncoding": "GB18030",
126
+ "targetEncoding": "UTF-8",
127
+ "confidenceThreshold": 0.8
128
+ }
129
+ ```
130
+
131
+ - `sourceEncoding`: Default encoding for files when auto-detection is uncertain
132
+ - `targetEncoding`: Always UTF-8 (the encoding you see and produce)
133
+ - `confidenceThreshold`: Minimum confidence (0-1) to trust auto-detected encoding