opencode-windows-encoding 1.0.3 → 1.2.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 +9 -10
- package/dist/utf8-encoding.js +1 -1
- package/dist/utf8-encoding.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Opencode Windows Encoding
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/opencode-windows-encoding)
|
|
4
4
|
[](https://www.gnu.org/licenses/agpl-3.0)
|
|
5
5
|
|
|
6
|
-
OpenCode plugin that fixes UTF-8 encoding issues when executing PowerShell commands on Windows.
|
|
6
|
+
OpenCode plugin that fixes UTF-8 encoding issues when executing PowerShell commands on Windows. Single-file, zero npm dependencies.
|
|
7
7
|
|
|
8
8
|
## The Problem
|
|
9
9
|
|
|
@@ -46,16 +46,16 @@ Or with a specific version:
|
|
|
46
46
|
```jsonc
|
|
47
47
|
{
|
|
48
48
|
"plugin": [
|
|
49
|
-
"opencode-windows-encoding
|
|
49
|
+
"opencode-windows-encoding@^1.1"
|
|
50
50
|
]
|
|
51
51
|
}
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
After adding the plugin, restart OpenCode. All subsequent shell commands will use UTF-8 encoding automatically.
|
|
55
55
|
|
|
56
|
-
##
|
|
56
|
+
## Local Usage (Copy & Go)
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
This is a single-file plugin. Copy `src/utf8-encoding.ts` directly to OpenCode's plugins directory — no dependencies required:
|
|
59
59
|
|
|
60
60
|
**PowerShell:**
|
|
61
61
|
```powershell
|
|
@@ -67,9 +67,9 @@ Copy-Item src/utf8-encoding.ts $env:USERPROFILE/.config/opencode/plugins/utf8-en
|
|
|
67
67
|
cp src/utf8-encoding.ts ~/.config/opencode/plugins/utf8-encoding.ts
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
Restart OpenCode to apply. No `npm install`, no build step.
|
|
71
71
|
|
|
72
|
-
`src/utf8-encoding.ts`
|
|
72
|
+
`src/utf8-encoding.ts` uses only Node.js built-ins (`node:fs`, `node:os`, `node:path`) — zero npm dependencies.
|
|
73
73
|
## Requirements
|
|
74
74
|
|
|
75
75
|
- **OpenCode** (any recent version with plugin support)
|
|
@@ -92,10 +92,9 @@ npm run typecheck
|
|
|
92
92
|
npm run dev
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
-
###
|
|
96
|
-
|
|
97
|
-
直接引用源码即可:
|
|
95
|
+
### Local Development Testing
|
|
98
96
|
|
|
97
|
+
Reference the source file directly:
|
|
99
98
|
```jsonc
|
|
100
99
|
{
|
|
101
100
|
"plugin": [
|
package/dist/utf8-encoding.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utf8-encoding.ts"],"sourcesContent":["/**\n * OpenCode Plugin — UTF-8 Encoding Fix for Windows + PowerShell\n *\n * 单文件插件,可直接复制到 ~/.config/opencode/plugins/ 使用,无需 npm install。\n *\n * 工作原理:拦截所有 bash/shell 工具调用,在命令前注入 PowerShell\n * UTF-8 编码配置,解决 Windows 下中文/非 ASCII 字符乱码问题。\n */\n\nimport { appendFileSync } from \"node:fs\"\nimport { tmpdir } from \"node:os\"\nimport { join } from \"node:path\"\n\n// ── 调试日志(写入临时目录) ──\nconst LOG = join(tmpdir(), \"utf8-plugin.log\")\nfunction flog(msg: string) {\n try { appendFileSync(LOG, `[${new Date().toISOString()}] ${msg}\\n`, \"utf8\") } catch {}\n}\n\n// ── PowerShell UTF-8 编码前缀 ──\nconst UTF8_ENC =\n \"[Console]::OutputEncoding=[Console]::InputEncoding=[Text.Encoding]::UTF8;$OutputEncoding=[Text.Encoding]::UTF8;\"\n\n/** 提取 opencode 在命令前追加的 set VAR=\"value\" && 前缀 */\nfunction stripSetPrefixes(cmd: string): { prefixes: string; cleanCmd: string } {\n const m = cmd.match(/^((?:set\\s+\\w+=\"[^\"]*\"\\s*&&\\s*)+)/)\n if (m) return { prefixes: m[1], cleanCmd: cmd.slice(m[1].length) }\n return { prefixes: \"\", cleanCmd: cmd }\n}\n\nexport const Utf8EncodingPlugin = async () => {\n flog(\"=== LOADED ===\")\n\n return {\n \"tool.execute.before\": async (input: Record<string, unknown>, output: Record<string, unknown>) => {\n const tool = String(input?.tool ?? \"\")\n flog(`[tool.before] tool=\"${tool}\"`)\n\n if (tool !== \"bash\" && tool !== \"shell\") return\n\n const args = output?.args as Record<string, unknown> | undefined\n if (!args) { flog(\" no args\"); return }\n\n const cmd = args.command\n if (typeof cmd !== \"string\" || !cmd) {\n flog(` args keys: ${JSON.stringify(Object.keys(args))}`)\n return\n }\n\n const { prefixes, cleanCmd } = stripSetPrefixes(cmd)\n flog(` orig: ${cleanCmd.slice(0, 120)}`)\n\n // 防止重复注入\n if (cleanCmd.includes(\"OutputEncoding\")) { flog(\" skip (idempotent)\"); return }\n\n args.command = prefixes + UTF8_ENC + cleanCmd\n flog(\" INJECTED\")\n },\n }\n}\n"],"mappings":";AASA,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AACvB,SAAS,YAAY;AAGrB,IAAM,MAAM,KAAK,OAAO,GAAG,iBAAiB;AAC5C,SAAS,KAAK,KAAa;AACzB,MAAI;AAAE,mBAAe,KAAK,KAAI,oBAAI,KAAK,GAAE,YAAY,CAAC,KAAK,GAAG;AAAA,GAAM,MAAM;AAAA,EAAE,QAAQ;AAAA,EAAC;AACvF;AAGA,IAAM,WACJ;AAGF,SAAS,iBAAiB,KAAqD;AAC7E,QAAM,IAAI,IAAI,MAAM,mCAAmC;AACvD,MAAI,EAAG,QAAO,EAAE,UAAU,EAAE,CAAC,GAAG,UAAU,IAAI,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE;AACjE,SAAO,EAAE,UAAU,IAAI,UAAU,IAAI;AACvC;AAEO,IAAM,qBAAqB,YAAY;AAC5C,OAAK,gBAAgB;AAErB,SAAO;AAAA,IACL,uBAAuB,OAAO,OAAgC,WAAoC;AAChG,YAAM,OAAO,OAAO,OAAO,QAAQ,EAAE;AACrC,WAAK,uBAAuB,IAAI,GAAG;AAEnC,UAAI,SAAS,UAAU,SAAS,QAAS;AAEzC,YAAM,OAAO,QAAQ;AACrB,UAAI,CAAC,MAAM;AAAE,aAAK,WAAW;AAAG;AAAA,MAAO;AAEvC,YAAM,MAAM,KAAK;AACjB,UAAI,OAAO,QAAQ,YAAY,CAAC,KAAK;AACnC,aAAK,gBAAgB,KAAK,UAAU,OAAO,KAAK,IAAI,CAAC,CAAC,EAAE;AACxD;AAAA,MACF;AAEA,YAAM,EAAE,UAAU,SAAS,IAAI,iBAAiB,GAAG;AACnD,WAAK,WAAW,SAAS,MAAM,GAAG,GAAG,CAAC,EAAE;AAGxC,UAAI,SAAS,SAAS,gBAAgB,GAAG;AAAE,aAAK,qBAAqB;AAAG;AAAA,MAAO;AAE/E,WAAK,UAAU,WAAW,WAAW;
|
|
1
|
+
{"version":3,"sources":["../src/utf8-encoding.ts"],"sourcesContent":["/**\n * OpenCode Plugin — UTF-8 Encoding Fix for Windows + PowerShell\n *\n * 单文件插件,可直接复制到 ~/.config/opencode/plugins/ 使用,无需 npm install。\n *\n * 工作原理:拦截所有 bash/shell 工具调用,在命令前注入 PowerShell\n * UTF-8 编码配置,解决 Windows 下中文/非 ASCII 字符乱码问题。\n */\n\nimport { appendFileSync } from \"node:fs\"\nimport { tmpdir } from \"node:os\"\nimport { join } from \"node:path\"\n\n// ── 调试日志(写入临时目录) ──\nconst LOG = join(tmpdir(), \"utf8-plugin.log\")\nfunction flog(msg: string) {\n try { appendFileSync(LOG, `[${new Date().toISOString()}] ${msg}\\n`, \"utf8\") } catch {}\n}\n\n// ── PowerShell UTF-8 编码前缀 ──\nconst UTF8_ENC =\n \"[Console]::OutputEncoding=[Console]::InputEncoding=[Text.Encoding]::UTF8;$OutputEncoding=[Text.Encoding]::UTF8;\"\n\n/** 提取 opencode 在命令前追加的 set VAR=\"value\" && 前缀 */\nfunction stripSetPrefixes(cmd: string): { prefixes: string; cleanCmd: string } {\n const m = cmd.match(/^((?:set\\s+\\w+=\"[^\"]*\"\\s*&&\\s*)+)/)\n if (m) return { prefixes: m[1], cleanCmd: cmd.slice(m[1].length) }\n return { prefixes: \"\", cleanCmd: cmd }\n}\n\nexport const Utf8EncodingPlugin = async () => {\n flog(\"=== LOADED ===\")\n\n return {\n \"tool.execute.before\": async (input: Record<string, unknown>, output: Record<string, unknown>) => {\n const tool = String(input?.tool ?? \"\")\n flog(`[tool.before] tool=\"${tool}\"`)\n\n if (tool !== \"bash\" && tool !== \"shell\") return\n\n const args = output?.args as Record<string, unknown> | undefined\n if (!args) { flog(\" no args\"); return }\n\n const cmd = args.command\n if (typeof cmd !== \"string\" || !cmd) {\n flog(` args keys: ${JSON.stringify(Object.keys(args))}`)\n return\n }\n\n const { prefixes, cleanCmd } = stripSetPrefixes(cmd)\n flog(` orig: ${cleanCmd.slice(0, 120)}`)\n\n // 防止重复注入\n if (cleanCmd.includes(\"OutputEncoding\")) { flog(\" skip (idempotent)\"); return }\n\n args.command = prefixes + UTF8_ENC + \"\\n\" + cleanCmd\n flog(\" INJECTED\")\n },\n }\n}\n"],"mappings":";AASA,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AACvB,SAAS,YAAY;AAGrB,IAAM,MAAM,KAAK,OAAO,GAAG,iBAAiB;AAC5C,SAAS,KAAK,KAAa;AACzB,MAAI;AAAE,mBAAe,KAAK,KAAI,oBAAI,KAAK,GAAE,YAAY,CAAC,KAAK,GAAG;AAAA,GAAM,MAAM;AAAA,EAAE,QAAQ;AAAA,EAAC;AACvF;AAGA,IAAM,WACJ;AAGF,SAAS,iBAAiB,KAAqD;AAC7E,QAAM,IAAI,IAAI,MAAM,mCAAmC;AACvD,MAAI,EAAG,QAAO,EAAE,UAAU,EAAE,CAAC,GAAG,UAAU,IAAI,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE;AACjE,SAAO,EAAE,U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