MCPcopy Index your code
hub / github.com/callstack/agent-device / applyContextWindow

Function applyContextWindow

src/utils/output.ts:577–594  ·  view source on GitHub ↗
(lines: SnapshotDiffLine[], contextWindow: number)

Source from the content-addressed store, hash-verified

575}
576
577function applyContextWindow(lines: SnapshotDiffLine[], contextWindow: number): SnapshotDiffLine[] {
578 if (lines.length === 0) return lines;
579 const changedIndices = lines
580 .map((line, index) => ({ index, kind: line.kind }))
581 .filter((entry) => entry.kind === 'added' || entry.kind === 'removed')
582 .map((entry) => entry.index);
583 if (changedIndices.length === 0) return lines;
584
585 const keep = new Array<boolean>(lines.length).fill(false);
586 for (const index of changedIndices) {
587 const start = Math.max(0, index - contextWindow);
588 const end = Math.min(lines.length - 1, index + contextWindow);
589 for (let i = start; i <= end; i += 1) {
590 keep[i] = true;
591 }
592 }
593 return lines.filter((_, index) => keep[index]);
594}
595
596export function supportsColor(stream: { isTTY?: boolean } = process.stdout): boolean {
597 const forceColor = process.env.FORCE_COLOR;

Callers 1

formatSnapshotDiffTextFunction · 0.85

Calls 1

fillMethod · 0.80

Tested by

no test coverage detected