opencode-windows-encoding 1.1.0 → 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 CHANGED
@@ -1,4 +1,4 @@
1
- # opencode-windows-encoding
1
+ # Opencode Windows Encoding
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/opencode-windows-encoding)](https://www.npmjs.com/package/opencode-windows-encoding)
4
4
  [![License: AGPL v3](https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
@@ -51,12 +51,11 @@ Or with a specific version:
51
51
  }
52
52
  ```
53
53
 
54
- After adding the plugin, restart OpenCode. All subsequent shell commands will use UTF-8 encoding automatically.
55
54
  After adding the plugin, restart OpenCode. All subsequent shell commands will use UTF-8 encoding automatically.
56
55
 
57
- ## 本地使用(复制即用)
56
+ ## Local Usage (Copy & Go)
58
57
 
59
- 本项目是单文件插件,`src/utf8-encoding.ts` 可以直接复制到 OpenCode 插件目录使用,零依赖:
58
+ This is a single-file plugin. Copy `src/utf8-encoding.ts` directly to OpenCode's plugins directory — no dependencies required:
60
59
 
61
60
  **PowerShell:**
62
61
  ```powershell
@@ -68,9 +67,9 @@ Copy-Item src/utf8-encoding.ts $env:USERPROFILE/.config/opencode/plugins/utf8-en
68
67
  cp src/utf8-encoding.ts ~/.config/opencode/plugins/utf8-encoding.ts
69
68
  ```
70
69
 
71
- 重启 OpenCode 即生效。无需 `npm install`,无需构建。
70
+ Restart OpenCode to apply. No `npm install`, no build step.
72
71
 
73
- `src/utf8-encoding.ts` 仅使用 Node.js 内置模块(`node:fs`, `node:os`, `node:path`),无任何 npm 依赖。
72
+ `src/utf8-encoding.ts` uses only Node.js built-ins (`node:fs`, `node:os`, `node:path`) — zero npm dependencies.
74
73
  ## Requirements
75
74
 
76
75
  - **OpenCode** (any recent version with plugin support)
@@ -93,10 +92,9 @@ npm run typecheck
93
92
  npm run dev
94
93
  ```
95
94
 
96
- ### 本地开发测试
97
-
98
- 直接引用源码即可:
95
+ ### Local Development Testing
99
96
 
97
+ Reference the source file directly:
100
98
  ```jsonc
101
99
  {
102
100
  "plugin": [
@@ -39,7 +39,7 @@ var Utf8EncodingPlugin = async () => {
39
39
  flog(" skip (idempotent)");
40
40
  return;
41
41
  }
42
- args.command = prefixes + UTF8_ENC + cleanCmd;
42
+ args.command = prefixes + UTF8_ENC + "\n" + cleanCmd;
43
43
  flog(" INJECTED");
44
44
  }
45
45
  };
@@ -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;AACrC,WAAK,YAAY;AAAA,IACnB;AAAA,EACF;AACF;","names":[]}
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,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,OAAO;AAC5C,WAAK,YAAY;AAAA,IACnB;AAAA,EACF;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-windows-encoding",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "OpenCode plugin to fix UTF-8 encoding issues in PowerShell on Windows",
5
5
  "type": "module",
6
6
  "main": "./dist/utf8-encoding.js",