| 651 | * arrives as `42\t```` and cannot close the block early. |
| 652 | */ |
| 653 | export function attributeSourceBytes(finalText: string): Map<string, number> { |
| 654 | const out = new Map<string, number>(); |
| 655 | if (!finalText) return out; |
| 656 | const lines = finalText.split('\n'); |
| 657 | let current: string | null = null; |
| 658 | let inFence = false; |
| 659 | let acc: string[] = []; |
| 660 | const flush = () => { |
| 661 | if (current && acc.length > 0) { |
| 662 | out.set(current, (out.get(current) ?? 0) + acc.join('\n').length); |
| 663 | } |
| 664 | acc = []; |
| 665 | }; |
| 666 | for (const line of lines) { |
| 667 | if (!inFence) { |
| 668 | const header = /^\*\*`([^`]+)`\*\*/.exec(line); |
| 669 | if (header) { |
| 670 | current = header[1]!; |
| 671 | continue; |
| 672 | } |
| 673 | if (current && line.startsWith('```')) { |
| 674 | inFence = true; |
| 675 | continue; |
| 676 | } |
| 677 | continue; |
| 678 | } |
| 679 | if (line === '```') { |
| 680 | inFence = false; |
| 681 | flush(); |
| 682 | continue; |
| 683 | } |
| 684 | acc.push(line); |
| 685 | } |
| 686 | // Unterminated fence (final-ceiling truncation cut mid-block): count it. |
| 687 | if (inFence) flush(); |
| 688 | return out; |
| 689 | } |
| 690 | |
| 691 | /** Human-readable stderr rendering of the JSON report. */ |
| 692 | export function renderTable(report: ExploreDiagnosticReport): string { |