MCPcopy
hub / github.com/continuedev/continue / truncateOutputFromStart

Function truncateOutputFromStart

extensions/cli/src/util/truncateOutput.ts:43–81  ·  view source on GitHub ↗
(
  output: string,
  limits: TruncationLimits,
)

Source from the content-addressed store, hash-verified

41 * @param limits - The character and line limits to apply
42 */
43export function truncateOutputFromStart(
44 output: string,
45 limits: TruncationLimits,
46): TruncationResult {
47 if (!output) {
48 return { output, wasTruncated: false };
49 }
50
51 const { maxChars, maxLines } = limits;
52 const lines = output.split("\n");
53
54 // Check if we need to truncate by lines first
55 if (lines.length > maxLines) {
56 const linesTruncated = lines.length - maxLines;
57 const preservedLines = lines.slice(-maxLines);
58 const contentAfterLineTruncation = preservedLines.join("\n");
59
60 // After line truncation, check character limit
61 if (contentAfterLineTruncation.length > maxChars) {
62 return truncateCharactersFromStart(
63 contentAfterLineTruncation,
64 linesTruncated,
65 maxChars,
66 );
67 }
68
69 return {
70 output: `(previous ${linesTruncated} lines truncated)\n\n${contentAfterLineTruncation}`,
71 wasTruncated: true,
72 };
73 }
74
75 // Check character limit
76 if (output.length > maxChars) {
77 return truncateCharactersFromStart(output, 0, maxChars);
78 }
79
80 return { output, wasTruncated: false };
81}
82
83/**
84 * Truncates output from the end to fit within a character limit, preserving the beginning.

Callers 5

moveToBackgroundFunction · 0.85
resetTimeoutFunction · 0.85
JobsSelectorFunction · 0.85

Calls 1

Tested by

no test coverage detected