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 / ask / armed-ask-of.ts
31 lines · 865 BRaw
1import type Git from '../git'
2import Limits from '../limits'
3import type { ArmedAsk } from './armed-ask'
4
5/**
6 * A file's diff as the context block the next prompt carries when the
7 * person presses ask.
8 *
9 * A line saying where it came from, then the hunks in unified form, cut at
10 * MAX_LINES_PER_FILE lines.
11 *
12 * @param path the file's repository-relative path
13 * @param hunks its hunks as the pane shows them
14 * @returns the armed ask
15 */
16export function armedAskOf(path: string, hunks: readonly Git.Hunk[]): ArmedAsk {
17 const body = hunks
18 .flatMap(hunk => [
19 `@@ -${hunk.oldStart} +${hunk.newStart} @@`,
20 ...hunk.lines,
21 ])
22 .slice(0, Limits.MAX_LINES_PER_FILE)
23
24 return {
25 path,
26 text:
27 `The user attached the diff of ${path} from the diff pane to this ` +
28 `prompt:\n${body.join('\n')}`,
29 lines: body.length,
30 }
31}