Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,12 @@ describe("tailClaudeTaskOutput", () => {
}).pipe(Effect.forkScoped);
assert.equal(yield* Queue.take(chunks), "start\n");

yield* fileSystem.writeFileString(file, `start\n${"y\n".repeat(1_000_000)}end\n`);
// The skip lands on the second byte of a two-byte é.
yield* fileSystem.writeFileString(file, `start\n${"é\n".repeat(1_000_000)}end.\n`);
const flooded = yield* Queue.take(chunks);
assert.isAtMost(flooded.length, 256 * 1024 + 1);
assert.isTrue(flooded.startsWith("\n"));
assert.isTrue(flooded.endsWith("y\nend\n"));
assert.equal(flooded.slice(0, 3), "\n\né");
assert.isTrue(flooded.endsWith("é\nend.\n"));
}),
).pipe(Effect.provide(NodeServices.layer)),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,15 @@ export const tailClaudeTaskOutput = Effect.fn("ClaudeTaskOutputTail.tail")(funct
if (Option.isSome(bytes)) {
// Skipped output must not splice two unrelated lines together.
const skipped = start > offset;
// Reset partial UTF-8 bytes when skipping output.
if (skipped) decoder = new TextDecoder("utf-8", { fatal: false });
let first = 0;
if (skipped) {
// Reset partial UTF-8 bytes, and skip the rest of a code point the cut landed inside.
decoder = new TextDecoder("utf-8", { fatal: false });
while (((bytes.value[first] ?? 0) & 0xc0) === 0x80) first += 1;
}
offset = start + bytes.value.byteLength;
const text = (skipped ? "\n" : "") + decoder.decode(bytes.value, { stream: true });
const text =
(skipped ? "\n" : "") + decoder.decode(bytes.value.subarray(first), { stream: true });
if (text.length > 0) yield* input.onChunk(text);
}
}
Expand Down
Loading