Changesets · Branches · Tags · Compare
| Changeset | c10bddf80ff02dbd2b2564e3c297cf2e4db4ea73eb9a01a91af63e88b586b286 |
|---|---|
| Author | Dallin Romney <dallinromney@gmail.com> · 2025-07-17 16:28 +02:00 |
| Committer | GitHub <noreply@github.com> · 2025-07-17 16:28 +02:00 |
| Parents | c62dd677e3bc, da930d52ff71 |
2 files changed
modified core/package.json +1 −0
| @@ -78,6 +78,7 @@ | ||
| 78 | 78 | "handlebars": "^4.7.8", |
| 79 | 79 | "http-proxy-agent": "^7.0.1", |
| 80 | 80 | "https-proxy-agent": "^7.0.3", |
| 81 | + "iconv-lite": "^0.6.3", | |
| 81 | 82 | "ignore": "^5.3.1", |
| 82 | 83 | "is-localhost-ip": "^2.0.0", |
| 83 | 84 | "jinja-js": "0.1.8", |
modified core/tools/implementations/runTerminalCommand.ts +19 −2
| @@ -1,5 +1,22 @@ | ||
| 1 | +import iconv from "iconv-lite"; | |
| 1 | 2 | import childProcess from "node:child_process"; |
| 2 | 3 | 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 | +} | |
| 3 | 20 | |
| 4 | 21 | import { fileURLToPath } from "node:url"; |
| 5 | 22 | import { ToolImpl } from "."; |
| @@ -77,7 +94,7 @@ | ||
| 77 | 94 | // Skip if this process has been backgrounded |
| 78 | 95 | if (isProcessBackgrounded(toolCallId)) return; |
| 79 | 96 | |
| 80 | - const newOutput = data.toString(); | |
| 97 | + const newOutput = getDecodedOutput(data); | |
| 81 | 98 | terminalOutput += newOutput; |
| 82 | 99 | |
| 83 | 100 | // Send partial output to UI |
| @@ -103,7 +120,7 @@ | ||
| 103 | 120 | // Skip if this process has been backgrounded |
| 104 | 121 | if (isProcessBackgrounded(toolCallId)) return; |
| 105 | 122 | |
| 106 | - const newOutput = data.toString(); | |
| 123 | + const newOutput = getDecodedOutput(data); | |
| 107 | 124 | terminalOutput += newOutput; |
| 108 | 125 | |
| 109 | 126 | // Send partial output to UI, status is not required |