@devries-cameron20 / t3code Mirror · read-only / commits / 2d0a9dfd51
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 02:00 UTC

fix(provider-acp): preserve UTF-8 across interleaved terminal streams (#32391)

Co-authored-by: GPT 6.1 Sol <codex@openai.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Wout Stiens committed Nov 7, 2026 at 11:48 UTC 2d0a9dfd5137b3c0e90bec7329ee018b27643b46
2 files changed +58 -4
packages/provider-acp/src/server/clientTerminals.test.ts
+54 -4
@@ -51,6 +51,52 @@ describe("AcpClientTerminals", () => {
51 ),
52 );
53
54 + it.effect("preserves UTF-8 when stderr interleaves a split stdout character", () =>
55 + Effect.gen(function* () {
56 + const stdoutStarted = yield* Deferred.make<void>();
57 + const stderrWritten = yield* Deferred.make<void>();
58 + const child = ChildProcessSpawner.makeHandle({
59 + pid: ChildProcessSpawner.ProcessId(1),
60 + exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(0)),
61 + isRunning: Effect.succeed(false),
62 + kill: () => Effect.void,
63 + stdin: Sink.drain,
64 + stdout: Stream.make(new Uint8Array([0xe2])).pipe(
65 + Stream.concat(Stream.fromEffectDrain(Deferred.succeed(stdoutStarted, undefined))),
66 + Stream.concat(Stream.fromEffectDrain(Deferred.await(stderrWritten))),
67 + Stream.concat(Stream.make(new Uint8Array([0x82, 0xac]))),
68 + ),
69 + stderr: Stream.fromEffectDrain(Deferred.await(stdoutStarted)).pipe(
70 + Stream.concat(Stream.make(new Uint8Array([0x58]))),
71 + Stream.concat(Stream.fromEffectDrain(Deferred.succeed(stderrWritten, undefined))),
72 + ),
73 + all: Stream.empty,
74 + getInputFd: () => Sink.drain,
75 + getOutputFd: () => Stream.empty,
76 + unref: Effect.succeed(Effect.void),
77 + });
78 + const terminals = yield* makeAcpClientTerminals({ defaultCwd: process.cwd() }).pipe(
79 + Effect.provideService(
80 + ChildProcessSpawner.ChildProcessSpawner,
81 + ChildProcessSpawner.make(() => Effect.succeed(child)),
82 + ),
83 + );
84 + yield* Effect.addFinalizer(() => terminals.disposeAll);
85 + const terminal = yield* terminals.create({ sessionId: "session", command: "fixture" });
86 + const request = { sessionId: "session", ...terminal };
87 + yield* terminals.waitForExit(request);
88 +
89 + const output = yield* terminals.output(request);
90 + expect(output.output).toContain("€");
91 + expect(output.output).toContain("X");
92 + expect(output.output).not.toContain("\uFFFD");
93 + expect(output.truncated).toBe(false);
94 + expect(terminals.readOutputSnapshot("session", terminal.terminalId)?.output).toBe(
95 + output.output,
96 + );
97 + }).pipe(Effect.scoped),
98 + );
99 +
100 it.live("resolves terminal environment from the requesting ACP session", () =>
101 Effect.gen(function* () {
102 const terminals = yield* makeAcpClientTerminals({
@@ -96,14 +142,17 @@ describe("AcpClientTerminals", () => {
142 }).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
143 );
144
99 - it.live("truncates buffered output from the beginning at the byte limit", () =>
145 + it.live.each([
146 + { text: "a".repeat(64) + "TAIL", limit: 16 },
147 + { text: "€".repeat(16) + "TAIL", limit: 6 },
148 + ])("truncates buffered output from the beginning at the $limit byte limit", ({ text, limit }) =>
149 withTerminals((terminals) =>
150 Effect.gen(function* () {
151 const created = yield* terminals.create({
152 sessionId: "session",
153 command: process.execPath,
105 - args: ["-e", "process.stdout.write('a'.repeat(64) + 'TAIL');"],
106 - outputByteLimit: 16,
154 + args: ["-e", `process.stdout.write(${JSON.stringify(text)});`],
155 + outputByteLimit: limit,
156 });
157 yield* terminals.waitForExit({ sessionId: "session", terminalId: created.terminalId });
158
@@ -113,7 +162,8 @@ describe("AcpClientTerminals", () => {
162 });
163 expect(output.truncated).toBe(true);
164 expect(output.output.endsWith("TAIL")).toBe(true);
116 - expect(output.output.length).toBeLessThanOrEqual(16);
165 + expect(Buffer.byteLength(output.output)).toBeLessThanOrEqual(limit);
166 + expect(output.output).not.toContain("\uFFFD");
167 }),
168 ),
169 );
packages/provider-acp/src/server/clientTerminals.ts
+4
@@ -1,3 +1,4 @@
1 +import * as Channel from "effect/Channel";
2 import * as Deferred from "effect/Deferred";
3 import * as Duration from "effect/Duration";
4 import * as Effect from "effect/Effect";
@@ -277,6 +278,9 @@ export const makeAcpClientTerminals = Effect.fn("makeAcpClientTerminals")(functi
278
279 const pump = (stream: typeof child.stdout) =>
280 stream.pipe(
281 + // Keep each pipe's UTF-8 decoder independent and preserve literal BOMs.
282 + Stream.pipeThroughChannel(Channel.decodeText("utf-8", { ignoreBOM: true })),
283 + Stream.encodeText,
284 Stream.runForEach((chunk) =>
285 Effect.sync(() => {
286 appendOutput(record.buffer, chunk);