MCPcopy Index your code
hub / github.com/codeaashu/claude-code / generatePreview

Function generatePreview

src/utils/toolResultStorage.ts:339–356  ·  view source on GitHub ↗
(
  content: string,
  maxBytes: number,
)

Source from the content-addressed store, hash-verified

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

Calls

no outgoing calls

Tested by

no test coverage detected