MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / generatePreview

Function generatePreview

source code/utils/toolResultStorage.ts:341–358  ·  view source on GitHub ↗
(
  content: string,
  maxBytes: number,
)

Source from the content-addressed store, hash-verified

339 * Generate a preview of content, truncating at a newline boundary when possible.
340 */
341export function generatePreview(
342 content: string,
343 maxBytes: number,
344): { preview: string; hasMore: boolean } {
345 if (content.length <= maxBytes) {
346 return { preview: content, hasMore: false }
347 }
348
349 // Find the last newline within the limit to avoid cutting mid-line
350 const truncated = content.slice(0, maxBytes)
351 const lastNewline = truncated.lastIndexOf('\n')
352
353 // If we found a newline reasonably close to the limit, use it
354 // Otherwise fall back to the exact limit
355 const cutPoint = lastNewline > maxBytes * 0.5 ? lastNewline : maxBytes
356
357 return { preview: content.slice(0, cutPoint), hasMore: true }
358}
359
360/**
361 * Type guard to check if persist result is an error

Calls

no outgoing calls

Tested by

no test coverage detected