| 101 | } |
| 102 | |
| 103 | function parseUpdateFileChunks(lines: string[], startIdx: number): { chunks: UpdateFileChunk[]; nextIdx: number } { |
| 104 | const chunks: UpdateFileChunk[] = [] |
| 105 | let i = startIdx |
| 106 | |
| 107 | while (i < lines.length && !lines[i].startsWith("***")) { |
| 108 | if (lines[i].startsWith("@@")) { |
| 109 | // Parse context line |
| 110 | const contextLine = lines[i].substring(2).trim() |
| 111 | i++ |
| 112 | |
| 113 | const oldLines: string[] = [] |
| 114 | const newLines: string[] = [] |
| 115 | let isEndOfFile = false |
| 116 | |
| 117 | // Parse change lines |
| 118 | while (i < lines.length && !lines[i].startsWith("@@") && !lines[i].startsWith("***")) { |
| 119 | const changeLine = lines[i] |
| 120 | |
| 121 | if (changeLine === "*** End of File") { |
| 122 | isEndOfFile = true |
| 123 | i++ |
| 124 | break |
| 125 | } |
| 126 | |
| 127 | if (changeLine.startsWith(" ")) { |
| 128 | // Keep line - appears in both old and new |
| 129 | const content = changeLine.substring(1) |
| 130 | oldLines.push(content) |
| 131 | newLines.push(content) |
| 132 | } else if (changeLine.startsWith("-")) { |
| 133 | // Remove line - only in old |
| 134 | oldLines.push(changeLine.substring(1)) |
| 135 | } else if (changeLine.startsWith("+")) { |
| 136 | // Add line - only in new |
| 137 | newLines.push(changeLine.substring(1)) |
| 138 | } |
| 139 | |
| 140 | i++ |
| 141 | } |
| 142 | |
| 143 | chunks.push({ |
| 144 | old_lines: oldLines, |
| 145 | new_lines: newLines, |
| 146 | change_context: contextLine || undefined, |
| 147 | is_end_of_file: isEndOfFile || undefined, |
| 148 | }) |
| 149 | } else { |
| 150 | i++ |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | return { chunks, nextIdx: i } |
| 155 | } |
| 156 | |
| 157 | function parseAddFileContent(lines: string[], startIdx: number): { content: string; nextIdx: number } { |
| 158 | let content = "" |