fix(cli): bound memory growth in high-volume components

This commit is contained in:
Spencer
2026-04-07 21:16:38 +00:00
parent 34b4f1c6e4
commit 76f7b1bffd
3 changed files with 30 additions and 7 deletions
@@ -35,16 +35,17 @@ export const AnsiOutputText: React.FC<AnsiOutputProps> = ({
? Math.min(availableHeightLimit, maxLines)
: (availableHeightLimit ?? maxLines ?? DEFAULT_HEIGHT);
const MAXIMUM_ANSI_LINES_RENDERED = 1000;
const lastLines = Array.isArray(data)
? disableTruncation
? data
? data.slice(-MAXIMUM_ANSI_LINES_RENDERED)
: numLinesRetained === 0
? []
: data.slice(-numLinesRetained)
: [];
return (
<Box flexDirection="column" width={width} flexShrink={0} overflow="hidden">
{(lastLines as AnsiLine[]).map((line: AnsiLine, lineIndex: number) => (
{lastLines.map((line: AnsiLine, lineIndex: number) => (
<Box key={lineIndex} height={1} overflow="hidden">
<AnsiLineText line={line} />
</Box>
@@ -86,8 +86,9 @@ export const SubagentProgressDisplay: React.FC<
</Box>
)}
<Box flexDirection="column" marginLeft={0} gap={0}>
{(historyOverrides ?? progress.recentActivity).map(
(item: SubagentActivityItem) => {
{(historyOverrides ?? progress.recentActivity)
.slice(-100)
.map((item: SubagentActivityItem) => {
if (item.type === 'thought') {
const isCancellation = item.content === 'Request cancelled.';
const icon = isCancellation ? ' ' : '💭';
@@ -155,8 +156,7 @@ export const SubagentProgressDisplay: React.FC<
);
}
return null;
},
)}
})}
</Box>
{progress.result && (
@@ -2779,7 +2779,29 @@ export function textBufferReducer(
action: TextBufferAction,
options: TextBufferOptions = {},
): TextBufferState {
const newState = textBufferReducerLogic(state, action, options);
let newState = textBufferReducerLogic(state, action, options);
const MAX_TEXT_BUFFER_LINES = 10000;
if (newState.lines.length > MAX_TEXT_BUFFER_LINES) {
const excess = newState.lines.length - MAX_TEXT_BUFFER_LINES;
const newLines = newState.lines.slice(excess);
const newCursorRow = Math.max(0, newState.cursorRow - excess);
let newExpandedPaste = newState.expandedPaste;
if (newExpandedPaste) {
const newStartLine = newExpandedPaste.startLine - excess;
if (newStartLine < 0) {
newExpandedPaste = null;
} else {
newExpandedPaste = { ...newExpandedPaste, startLine: newStartLine };
}
}
newState = {
...newState,
lines: newLines,
cursorRow: newCursorRow,
expandedPaste: newExpandedPaste,
};
}
const newTransformedLines =
newState.lines !== state.lines