MCPcopy Index your code
hub / github.com/continuedev/continue / truncateOutputFromEnd

Function truncateOutputFromEnd

extensions/cli/src/util/truncateOutput.ts:91–119  ·  view source on GitHub ↗
(
  output: string,
  maxChars: number,
  context?: string,
)

Source from the content-addressed store, hash-verified

89 * @param context - Optional context for the truncation message (e.g., "file content", "diff")
90 */
91export function truncateOutputFromEnd(
92 output: string,
93 maxChars: number,
94 context?: string,
95): TruncationResult {
96 if (!output || output.length <= maxChars) {
97 return { output, wasTruncated: false };
98 }
99
100 const truncatedContent = output.slice(0, maxChars);
101
102 // Try to end at a clean line boundary
103 const lastNewline = truncatedContent.lastIndexOf("\n");
104 const shouldSnapToLine =
105 lastNewline !== -1 &&
106 truncatedContent.length - lastNewline < TRUNCATION_LINE_SNAP_THRESHOLD;
107 const cleanContent = shouldSnapToLine
108 ? truncatedContent.slice(0, lastNewline)
109 : truncatedContent;
110
111 const actualCharsRemoved = output.length - cleanContent.length;
112 const contextStr = context ? ` of ${context}` : "";
113 const suffix = `\n\n(${actualCharsRemoved} characters${contextStr} truncated)`;
114
115 return {
116 output: cleanContent + suffix,
117 wasTruncated: true,
118 };
119}
120
121/**
122 * Truncates output by line count from the end, preserving the beginning.

Callers 4

viewDiff.tsFile · 0.85
fetch.tsFile · 0.85
truncateByLinesAndCharsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected