Skip to content

avoid garbled Chinese when call runTerminalCommandTool in windows #6599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"handlebars": "^4.7.8",
"http-proxy-agent": "^7.0.1",
"https-proxy-agent": "^7.0.3",
"iconv-lite": "^0.6.3",
"ignore": "^5.3.1",
"is-localhost-ip": "^2.0.0",
"jinja-js": "0.1.8",
Expand Down
21 changes: 19 additions & 2 deletions core/tools/implementations/runTerminalCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
import iconv from "iconv-lite";
import childProcess from "node:child_process";
import util from "node:util";
// Automatically decode the buffer according to the platform to avoid garbled Chinese
function getDecodedOutput(data: Buffer): string {
if (process.platform === "win32") {
try {
let out = iconv.decode(data, "utf-8");
if (/�/.test(out)) {
out = iconv.decode(data, "gbk");
}
return out;
} catch {
return iconv.decode(data, "gbk");
}
} else {
return data.toString();
}
}

import { fileURLToPath } from "node:url";
import { ToolImpl } from ".";
Expand Down Expand Up @@ -77,7 +94,7 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => {
// Skip if this process has been backgrounded
if (isProcessBackgrounded(toolCallId)) return;

const newOutput = data.toString();
const newOutput = getDecodedOutput(data);
terminalOutput += newOutput;

// Send partial output to UI
Expand All @@ -103,7 +120,7 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => {
// Skip if this process has been backgrounded
if (isProcessBackgrounded(toolCallId)) return;

const newOutput = data.toString();
const newOutput = getDecodedOutput(data);
terminalOutput += newOutput;

// Send partial output to UI, status is not required
Expand Down
Loading