Elffuss BraidHub

kikocis/continue public

Merge pull request #6599 from xiaohuanxiong3/main

avoid garbled Chinese when call runTerminalCommandTool in windows
Changesetc10bddf80ff02dbd2b2564e3c297cf2e4db4ea73eb9a01a91af63e88b586b286
AuthorDallin Romney <dallinromney@gmail.com> · 2025-07-17 16:28 +02:00
CommitterGitHub <noreply@github.com> · 2025-07-17 16:28 +02:00
Parentsc62dd677e3bc, da930d52ff71

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