fix(agent): preserve oversized tail output with trailing newline

closes #4715
This commit is contained in:
Mario Zechner
2026-05-18 23:05:34 +02:00
parent 93ecdbea35
commit b1893b3d77
3 changed files with 16 additions and 0 deletions

View File

@@ -2,6 +2,10 @@
## [Unreleased]
### Fixed
- Fixed tail truncation for oversized single-line output that ends with a trailing newline ([#4715](https://github.com/earendil-works/pi/issues/4715)).
## [0.75.3] - 2026-05-18
## [0.75.2] - 2026-05-18

View File

@@ -218,6 +218,7 @@ export function truncateTail(content: string, options: TruncationOptions = {}):
const totalBytes = utf8ByteLength(content);
const lines = content.split("\n");
if (lines.length > 1 && lines[lines.length - 1] === "") lines.pop();
const totalLines = lines.length;
// Check if no truncation needed

View File

@@ -102,6 +102,17 @@ describe("truncate utilities", () => {
expect(result.outputBytes).toBe(5);
});
it("truncates an oversized single line with a trailing newline", () => {
const input = `${"X".repeat(300_000)}\n`;
const result = truncateTail(input, { maxBytes: 1024, maxLines: 100 });
expect(result.content).toBe("X".repeat(1024));
expect(result.outputBytes).toBe(1024);
expect(result.outputLines).toBe(1);
expect(result.lastLinePartial).toBe(true);
expect(result.truncatedBy).toBe("bytes");
});
it("drops an oversized trailing character when it cannot fit in tail byte limit", () => {
const result = truncateTail("abc🙂", { maxBytes: 3, maxLines: 10 });