Skip to content

Commit aea5467

Browse files
piotrskiclaude
andcommitted
fix: preserve content lines when truncation and footer both apply
When --max-lines is set and the tree is truncated, the truncation notice now uses the pre-reserved footer slot (combined line) instead of replacing the last content line. This shows one additional component line within the same budget. Also fixes the --max-lines 1 edge case where the footer was emitted after the truncation notice, producing 2 lines instead of 1. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e0b7a4e commit aea5467

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

packages/agent-react-devtools/src/__tests__/formatters.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ describe('formatTree', () => {
168168
];
169169

170170
const result = formatTree(nodes, { maxLines: 3, totalCount: 100 });
171-
// Should have truncation + summary footer
171+
// Truncation notice and total count are combined into one line (preserves content lines)
172172
expect(result).toContain('truncated');
173-
expect(result).toContain('components shown');
173+
expect(result).toContain('100 total components');
174174
});
175175
});
176176

packages/agent-react-devtools/src/formatters.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,20 @@ export function formatTree(nodes: TreeNode[], hintOrOpts?: string | FormatTreeOp
159159
}
160160

161161
if (truncated) {
162-
// Replace last tree line with truncation notice to stay within budget
163-
if (lines.length > 0) {
164-
lines[lines.length - 1] = `... output truncated at ${maxLines} lines`;
162+
if (totalCount !== undefined) {
163+
// Use the reserved footer slot for the truncation notice so no content line is lost.
164+
// Combine with total count so the summary info isn't dropped.
165+
lines.push(`... output truncated at ${maxLines} lines (${totalCount.toLocaleString()} total components)`);
165166
} else {
166-
lines.push(`... output truncated at ${maxLines} lines`);
167+
// No footer reserved — replace last content line with truncation notice.
168+
if (lines.length > 0) {
169+
lines[lines.length - 1] = `... output truncated at ${maxLines} lines`;
170+
} else {
171+
lines.push(`... output truncated at ${maxLines} lines`);
172+
}
167173
}
168-
}
169-
170-
// Summary footer
171-
if (totalCount !== undefined) {
174+
} else if (totalCount !== undefined) {
175+
// Summary footer (only when output was not truncated)
172176
const shown = nodes.length;
173177
const totalFormatted = totalCount.toLocaleString();
174178
if (shown < totalCount) {

0 commit comments

Comments
 (0)