Elffuss BraidHub

kikocis/continue public

avoid garbled Chinese when call runTerminalCommandTool in windows
Changesetdd146195b1d49d93eb397aa3152675fc1ada79aeb31443d8c89e540ab86fc3d4
AuthorQiuYang Shen <1741258352@qq.com> · 2025-07-13 19:00 +08:00
CommitterQiuYang Shen <1741258352@qq.com> · 2025-07-13 19:00 +08:00
Parentsf66ac292f7a0

Browse the files at this changeset

2 files changed

modified core/package.json +1 −0
@@ -78,6 +78,7 @@
7878 "handlebars": "^4.7.8",
7979 "http-proxy-agent": "^7.0.1",
8080 "https-proxy-agent": "^7.0.3",
81+ "iconv-lite": "^0.6.3",
8182 "ignore": "^5.3.1",
8283 "is-localhost-ip": "^2.0.0",
8384 "jinja-js": "0.1.8",
modified core/tools/implementations/runTerminalCommand.ts +19 −2
@@ -1,5 +1,22 @@
1+import iconv from "iconv-lite";
12 import childProcess from "node:child_process";
23 import util from "node:util";
4+// Automatically decode the buffer according to the platform to avoid garbled Chinese
5+function getDecodedOutput(data: Buffer): string {
6+ if (process.platform === "win32") {
7+ try {
8+ let out = iconv.decode(data, "utf-8");
9+ if (/�/.test(out)) {
10+ out = iconv.decode(data, "gbk");
11+ }
12+ return out;
13+ } catch {
14+ return iconv.decode(data, "gbk");
15+ }
16+ } else {
17+ return data.toString();
18+ }
19+}
320
421 import { fileURLToPath } from "node:url";
522 import { ToolImpl } from ".";
@@ -77,7 +94,7 @@
7794 // Skip if this process has been backgrounded
7895 if (isProcessBackgrounded(toolCallId)) return;
7996
80- const newOutput = data.toString();
97+ const newOutput = getDecodedOutput(data);
8198 terminalOutput += newOutput;
8299
83100 // Send partial output to UI
@@ -103,7 +120,7 @@
103120 // Skip if this process has been backgrounded
104121 if (isProcessBackgrounded(toolCallId)) return;
105122
106- const newOutput = data.toString();
123+ const newOutput = getDecodedOutput(data);
107124 terminalOutput += newOutput;
108125
109126 // Send partial output to UI, status is not required