* Capture untracked files (git diff doesn't include them). * Respects size limits and skips binary files.
()
| 616 | * Respects size limits and skips binary files. |
| 617 | */ |
| 618 | async function captureUntrackedFiles(): Promise< |
| 619 | Array<{ path: string; content: string }> |
| 620 | > { |
| 621 | const { stdout, code } = await execFileNoThrow( |
| 622 | gitExe(), |
| 623 | ['ls-files', '--others', '--exclude-standard'], |
| 624 | { preserveOutputOnError: false }, |
| 625 | ) |
| 626 | |
| 627 | const trimmed = stdout.trim() |
| 628 | if (code !== 0 || !trimmed) { |
| 629 | return [] |
| 630 | } |
| 631 | |
| 632 | const files = trimmed.split('\n').filter(Boolean) |
| 633 | const result: Array<{ path: string; content: string }> = [] |
| 634 | let totalSize = 0 |
| 635 | |
| 636 | for (const filePath of files) { |
| 637 | // Check file count limit |
| 638 | if (result.length >= MAX_FILE_COUNT) { |
| 639 | logForDebugging( |
| 640 | `Untracked file capture: reached max file count (${MAX_FILE_COUNT})`, |
| 641 | ) |
| 642 | break |
| 643 | } |
| 644 | |
| 645 | // Skip binary files by extension - zero I/O |
| 646 | if (hasBinaryExtension(filePath)) { |
| 647 | continue |
| 648 | } |
| 649 | |
| 650 | try { |
| 651 | const stats = await stat(filePath) |
| 652 | const fileSize = stats.size |
| 653 | |
| 654 | // Skip files exceeding per-file limit |
| 655 | if (fileSize > MAX_FILE_SIZE_BYTES) { |
| 656 | logForDebugging( |
| 657 | `Untracked file capture: skipping ${filePath} (exceeds ${MAX_FILE_SIZE_BYTES} bytes)`, |
| 658 | ) |
| 659 | continue |
| 660 | } |
| 661 | |
| 662 | // Check total size limit |
| 663 | if (totalSize + fileSize > MAX_TOTAL_SIZE_BYTES) { |
| 664 | logForDebugging( |
| 665 | `Untracked file capture: reached total size limit (${MAX_TOTAL_SIZE_BYTES} bytes)`, |
| 666 | ) |
| 667 | break |
| 668 | } |
| 669 | |
| 670 | // Empty file - no need to open |
| 671 | if (fileSize === 0) { |
| 672 | result.push({ path: filePath, content: '' }) |
| 673 | continue |
| 674 | } |
| 675 |
no test coverage detected