( gitPath: string, absoluteFilePath: string, )
| 502 | } |
| 503 | |
| 504 | async function generateSyntheticDiff( |
| 505 | gitPath: string, |
| 506 | absoluteFilePath: string, |
| 507 | ): Promise<Omit<ToolUseDiff, 'repository'> | null> { |
| 508 | try { |
| 509 | if (!isFileWithinReadSizeLimit(absoluteFilePath, MAX_DIFF_SIZE_BYTES)) { |
| 510 | return null |
| 511 | } |
| 512 | const content = await readFile(absoluteFilePath, 'utf-8') |
| 513 | const lines = content.split('\n') |
| 514 | // Remove trailing empty line from split if file ends with newline |
| 515 | if (lines.length > 0 && lines.at(-1) === '') { |
| 516 | lines.pop() |
| 517 | } |
| 518 | const lineCount = lines.length |
| 519 | const addedLines = lines.map(line => `+${line}`).join('\n') |
| 520 | const patch = `@@ -0,0 +1,${lineCount} @@\n${addedLines}` |
| 521 | return { |
| 522 | filename: gitPath, |
| 523 | status: 'added', |
| 524 | additions: lineCount, |
| 525 | deletions: 0, |
| 526 | changes: lineCount, |
| 527 | patch, |
| 528 | } |
| 529 | } catch { |
| 530 | return null |
| 531 | } |
| 532 | } |
no test coverage detected