spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / diff / hooks / git / cut-hunks / cut-hunks.ts
30 lines · 832 BRaw
1import Limits from '../../limits'
2import type Types from '../types'
3
4/**
5 * Hunks with their lines cut at MAX_LINES_PER_FILE in all, in order, and
6 * whether any line was dropped.
7 *
8 * The one bound on every body the pane draws or attaches, whether git
9 * printed it or the transcript carried it.
10 *
11 * @param hunks the hunks as parsed or reported
12 * @returns the cut hunks and whether the cut dropped lines
13 */
14export function cutHunks(
15 hunks: readonly Types.Hunk[],
16): Pick<Types.FileHunks, 'hunks' | 'isTruncated'> {
17 let budget = Limits.MAX_LINES_PER_FILE
18 let total = 0
19
20 return {
21 hunks: hunks.map(hunk => {
22 const lines = hunk.lines.slice(0, budget)
23 budget -= lines.length
24 total += hunk.lines.length
25
26 return { ...hunk, lines }
27 }),
28 isTruncated: total > Limits.MAX_LINES_PER_FILE,
29 }
30}