| 110 | } |
| 111 | |
| 112 | function 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 | |
| 144 | function advanceCursorToAnchor( |
| 145 | anchor: string, |