(diffContent: string)
| 25 | * @returns Object with additions and deletions counts |
| 26 | */ |
| 27 | export function calculateDiffStats(diffContent: string): DiffStats { |
| 28 | if (!diffContent || diffContent.trim() === "") { |
| 29 | return { additions: 0, deletions: 0 }; |
| 30 | } |
| 31 | |
| 32 | const lines = diffContent.split("\n"); |
| 33 | let additions = 0; |
| 34 | let deletions = 0; |
| 35 | |
| 36 | for (const line of lines) { |
| 37 | // Skip diff metadata lines |
| 38 | // File headers contain a space: "--- a/file" or "+++ b/file" |
| 39 | // But code changes with ++ or -- at start don't: "+++counter;" or "---counter;" |
| 40 | if ( |
| 41 | (line.startsWith("+++") && (line.length === 3 || line[3] === " ")) || |
| 42 | (line.startsWith("---") && (line.length === 3 || line[3] === " ")) || |
| 43 | line.startsWith("@@") || |
| 44 | line.startsWith("diff ") || |
| 45 | line.startsWith("index ") || |
| 46 | line.startsWith("Binary files") |
| 47 | ) { |
| 48 | continue; |
| 49 | } |
| 50 | |
| 51 | // Count actual code changes |
| 52 | if (line.startsWith("+")) { |
| 53 | additions++; |
| 54 | } else if (line.startsWith("-")) { |
| 55 | deletions++; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | return { additions, deletions }; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Extract the last assistant message from conversation history |
no outgoing calls
no test coverage detected