fix(cli): clip oversized shell tool output in collapsed tool results (#883)
Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
@@ -10,6 +10,7 @@ const PREFIX_WIDTH = 5; // " ⎿ " or " "
|
||||
interface CollapsedOutputDisplayProps {
|
||||
output: string; // Full output from completion
|
||||
maxLines?: number; // Max lines to show before collapsing (Infinity = show all)
|
||||
maxChars?: number; // Max chars to show before clipping
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -22,12 +23,24 @@ export const CollapsedOutputDisplay = memo(
|
||||
({
|
||||
output,
|
||||
maxLines = DEFAULT_COLLAPSED_LINES,
|
||||
maxChars,
|
||||
}: CollapsedOutputDisplayProps) => {
|
||||
const columns = useTerminalWidth();
|
||||
const contentWidth = Math.max(0, columns - PREFIX_WIDTH);
|
||||
|
||||
let displayOutput = output;
|
||||
let clippedByChars = false;
|
||||
if (
|
||||
typeof maxChars === "number" &&
|
||||
maxChars > 0 &&
|
||||
output.length > maxChars
|
||||
) {
|
||||
displayOutput = `${output.slice(0, maxChars)}…`;
|
||||
clippedByChars = true;
|
||||
}
|
||||
|
||||
// Keep empty lines for accurate display (don't filter them out)
|
||||
const lines = output.split("\n");
|
||||
const lines = displayOutput.split("\n");
|
||||
// Remove trailing empty line from final newline
|
||||
if (lines.length > 0 && lines[lines.length - 1] === "") {
|
||||
lines.pop();
|
||||
@@ -75,6 +88,17 @@ export const CollapsedOutputDisplay = memo(
|
||||
</Box>
|
||||
</Box>
|
||||
)}
|
||||
{/* Character clipping hint */}
|
||||
{clippedByChars && (
|
||||
<Box flexDirection="row">
|
||||
<Box width={PREFIX_WIDTH} flexShrink={0}>
|
||||
<Text>{" "}</Text>
|
||||
</Box>
|
||||
<Box flexGrow={1} width={contentWidth}>
|
||||
<Text dimColor>… output clipped</Text>
|
||||
</Box>
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
},
|
||||
|
||||
@@ -855,7 +855,7 @@ export const ToolCallMessage = memo(
|
||||
line.phase === "finished" &&
|
||||
line.resultText &&
|
||||
line.resultOk !== false && (
|
||||
<CollapsedOutputDisplay output={line.resultText} />
|
||||
<CollapsedOutputDisplay output={line.resultText} maxChars={300} />
|
||||
)}
|
||||
|
||||
{/* Tool result for non-shell tools or shell tool errors */}
|
||||
|
||||
Reference in New Issue
Block a user