opencode-windows-encoding 1.2.0 → 2.0.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/dist/utf8-encoding.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { PluginInput } from '@opencode-ai/plugin';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* OpenCode Plugin — UTF-8 Encoding Fix for Windows + PowerShell
|
|
3
5
|
*
|
|
@@ -6,8 +8,15 @@
|
|
|
6
8
|
* 工作原理:拦截所有 bash/shell 工具调用,在命令前注入 PowerShell
|
|
7
9
|
* UTF-8 编码配置,解决 Windows 下中文/非 ASCII 字符乱码问题。
|
|
8
10
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
|
|
12
|
+
declare const Utf8EncodingPlugin: (_input: PluginInput) => Promise<{
|
|
13
|
+
"tool.execute.before": (input: {
|
|
14
|
+
tool: string;
|
|
15
|
+
sessionID: string;
|
|
16
|
+
callID: string;
|
|
17
|
+
}, output: {
|
|
18
|
+
args: any;
|
|
19
|
+
}) => Promise<void>;
|
|
11
20
|
}>;
|
|
12
21
|
|
|
13
|
-
export { Utf8EncodingPlugin };
|
|
22
|
+
export { Utf8EncodingPlugin, Utf8EncodingPlugin as default };
|
package/dist/utf8-encoding.js
CHANGED
|
@@ -16,14 +16,14 @@ function stripSetPrefixes(cmd) {
|
|
|
16
16
|
if (m) return { prefixes: m[1], cleanCmd: cmd.slice(m[1].length) };
|
|
17
17
|
return { prefixes: "", cleanCmd: cmd };
|
|
18
18
|
}
|
|
19
|
-
var Utf8EncodingPlugin = async () => {
|
|
19
|
+
var Utf8EncodingPlugin = async (_input) => {
|
|
20
20
|
flog("=== LOADED ===");
|
|
21
21
|
return {
|
|
22
22
|
"tool.execute.before": async (input, output) => {
|
|
23
23
|
const tool = String(input?.tool ?? "");
|
|
24
24
|
flog(`[tool.before] tool="${tool}"`);
|
|
25
25
|
if (tool !== "bash" && tool !== "shell") return;
|
|
26
|
-
const args = output
|
|
26
|
+
const args = output.args;
|
|
27
27
|
if (!args) {
|
|
28
28
|
flog(" no args");
|
|
29
29
|
return;
|
|
@@ -44,7 +44,9 @@ var Utf8EncodingPlugin = async () => {
|
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
46
|
};
|
|
47
|
+
var utf8_encoding_default = Utf8EncodingPlugin;
|
|
47
48
|
export {
|
|
48
|
-
Utf8EncodingPlugin
|
|
49
|
+
Utf8EncodingPlugin,
|
|
50
|
+
utf8_encoding_default as default
|
|
49
51
|
};
|
|
50
52
|
//# sourceMappingURL=utf8-encoding.js.map
|
|
@@ -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:
|
|
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\"\nimport type { PluginInput } from \"@opencode-ai/plugin\"\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 (_input: PluginInput) => {\n flog(\"=== LOADED ===\")\n\n return {\n \"tool.execute.before\": async (input: { tool: string; sessionID: string; callID: string }, output: { args: any }) => {\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\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\nexport default Utf8EncodingPlugin\n"],"mappings":";AASA,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AACvB,SAAS,YAAY;AAIrB,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,OAAO,WAAwB;AAC/D,OAAK,gBAAgB;AAErB,SAAO;AAAA,IACL,uBAAuB,OAAO,OAA4D,WAA0B;AAClH,YAAM,OAAO,OAAO,OAAO,QAAQ,EAAE;AACrC,WAAK,uBAAuB,IAAI,GAAG;AAEnC,UAAI,SAAS,UAAU,SAAS,QAAS;AAEzC,YAAM,OAAO,OAAO;AACpB,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;AAEA,IAAO,wBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-windows-encoding",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.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",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"license": "AGPL-3.0",
|
|
37
37
|
"dependencies": {},
|
|
38
38
|
"devDependencies": {
|
|
39
|
+
"@opencode-ai/plugin": "^1.17.0",
|
|
39
40
|
"@types/node": "^22.0.0",
|
|
40
41
|
"tsup": "^8.0.0",
|
|
41
42
|
"typescript": "^5.8.0"
|