MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / parseCreateDiff

Function parseCreateDiff

sdk/src/tools/apply-patch.ts:112–142  ·  view source on GitHub ↗
(lines: string[])

Source from the content-addressed store, hash-verified

110}
111
112function parseCreateDiff(lines: string[]): string {
113 // Keep compatibility with unified create payloads by ignoring common diff headers.
114 const filteredLines = lines.filter(
115 (line) =>
116 !line.startsWith('---') &&
117 !line.startsWith('+++') &&
118 !line.startsWith('@@') &&
119 !line.startsWith('***'),
120 )
121
122 const parser: ParserState = {
123 lines: [...filteredLines, END_PATCH],
124 index: 0,
125 fuzz: 0,
126 }
127
128 const output: string[] = []
129
130 while (!isDone(parser, SECTION_TERMINATORS)) {
131 const line = parser.lines[parser.index]!
132 parser.index += 1
133
134 if (!line.startsWith('+')) {
135 throw new Error(`Invalid Add File Line: ${line}`)
136 }
137
138 output.push(line.slice(1))
139 }
140
141 return output.join('\n')
142}
143
144function advanceCursorToAnchor(
145 anchor: string,

Callers 1

applyDiffFunction · 0.85

Calls 1

isDoneFunction · 0.85

Tested by

no test coverage detected