MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / readWithSlice

Function readWithSlice

src/integrations/misc/indentation-reader.ts:434–469  ·  view source on GitHub ↗
(
	content: string,
	offset: number = 0,
	limit: number = DEFAULT_LINE_LIMIT,
)

Source from the content-addressed store, hash-verified

432 * @returns The extracted content with metadata
433 */
434export function readWithSlice(
435 content: string,
436 offset: number = 0,
437 limit: number = DEFAULT_LINE_LIMIT,
438): IndentationReadResult {
439 const lines = parseLines(content)
440 const totalLines = lines.length
441
442 // Validate offset
443 if (offset < 0) offset = 0
444 if (offset >= totalLines) {
445 return {
446 content: `Error: offset ${offset} is beyond file end (${totalLines} lines)`,
447 includedRanges: [],
448 totalLines,
449 returnedLines: 0,
450 wasTruncated: false,
451 }
452 }
453
454 // Slice lines
455 const endIdx = Math.min(offset + limit, totalLines)
456 const selectedLines = lines.slice(offset, endIdx)
457 const wasTruncated = endIdx < totalLines
458
459 // Format output
460 const formattedContent = formatWithLineNumbers(selectedLines)
461
462 return {
463 content: formattedContent,
464 includedRanges: [[offset + 1, endIdx]], // 1-based
465 totalLines,
466 returnedLines: selectedLines.length,
467 wasTruncated,
468 }
469}

Callers 4

processTextFileMethod · 0.90
executeLegacyMethod · 0.90

Calls 2

parseLinesFunction · 0.85
formatWithLineNumbersFunction · 0.85

Tested by

no test coverage detected