From 7293d7cb8213cdbe3f4ebefcdbff9251a50fc8b5 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Sat, 10 Jan 2026 13:55:02 +0100 Subject: [PATCH] fix(coding-agent): UTF-8 corruption in remote bash execution Applied streaming TextDecoder fix to executeBashWithOperations(), matching the fix in executeBash() from PR #433. Remote execution (SSH, containers) was still using Buffer.toString() which corrupts multi-byte UTF-8 sequences split across chunk boundaries. fixes #608 --- packages/coding-agent/CHANGELOG.md | 1 + packages/coding-agent/src/core/bash-executor.ts | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md index 0973868c..15ad8f55 100644 --- a/packages/coding-agent/CHANGELOG.md +++ b/packages/coding-agent/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixed - Bash output expanded hint now says "(ctrl+o to collapse)" ([#610](https://github.com/badlogic/pi-mono/pull/610) by [@tallshort](https://github.com/tallshort)) +- Fixed UTF-8 text corruption in remote bash execution (SSH, containers) by using streaming TextDecoder ([#608](https://github.com/badlogic/pi-mono/issues/608)) ## [0.42.3] - 2026-01-10 diff --git a/packages/coding-agent/src/core/bash-executor.ts b/packages/coding-agent/src/core/bash-executor.ts index 12da78b1..5db79685 100644 --- a/packages/coding-agent/src/core/bash-executor.ts +++ b/packages/coding-agent/src/core/bash-executor.ts @@ -197,11 +197,13 @@ export async function executeBashWithOperations( let tempFileStream: WriteStream | undefined; let totalBytes = 0; + const decoder = new TextDecoder(); + const onData = (data: Buffer) => { totalBytes += data.length; // Sanitize: strip ANSI, replace binary garbage, normalize newlines - const text = sanitizeBinaryOutput(stripAnsi(data.toString("utf-8"))).replace(/\r/g, ""); + const text = sanitizeBinaryOutput(stripAnsi(decoder.decode(data, { stream: true }))).replace(/\r/g, ""); // Start writing to temp file if exceeds threshold if (totalBytes > DEFAULT_MAX_BYTES && !tempFilePath) {