|
| 1 | +#!/usr/bin/env tsx |
| 2 | + |
| 3 | +/** |
| 4 | + * Binary search to find problematic Mermaid gantt entries |
| 5 | + * Usage: tsx scripts/debug/debug_mermaid.ts |
| 6 | + */ |
| 7 | + |
| 8 | +import { readFileSync, writeFileSync } from 'fs'; |
| 9 | + |
| 10 | +function main() { |
| 11 | + const inputFile = '/tmp/rivet-engine-gantt.md'; |
| 12 | + const content = readFileSync(inputFile, 'utf-8'); |
| 13 | + const lines = content.split('\n'); |
| 14 | + |
| 15 | + // Find the start and end of the mermaid block |
| 16 | + const startIdx = lines.findIndex(line => line.trim() === '```mermaid'); |
| 17 | + const endIdx = lines.findIndex((line, idx) => idx > startIdx && line.trim() === '```'); |
| 18 | + |
| 19 | + if (startIdx === -1 || endIdx === -1) { |
| 20 | + console.error('Could not find mermaid block'); |
| 21 | + process.exit(1); |
| 22 | + } |
| 23 | + |
| 24 | + const mermaidLines = lines.slice(startIdx + 1, endIdx); |
| 25 | + |
| 26 | + // Find where sections start |
| 27 | + const sectionStarts: number[] = []; |
| 28 | + mermaidLines.forEach((line, idx) => { |
| 29 | + if (line.trim().startsWith('section ')) { |
| 30 | + sectionStarts.push(idx); |
| 31 | + } |
| 32 | + }); |
| 33 | + |
| 34 | + console.log(`Found ${sectionStarts.length} sections`); |
| 35 | + |
| 36 | + // Try with just the header |
| 37 | + console.log('\nTesting with just header...'); |
| 38 | + let testLines = mermaidLines.slice(0, Math.max(...sectionStarts.filter(s => s < 10))); |
| 39 | + writeTestFile(testLines, '/tmp/test-gantt.md'); |
| 40 | + console.log('Created /tmp/test-gantt.md with just headers'); |
| 41 | + |
| 42 | + // Try with first section only |
| 43 | + console.log('\nTesting with first section only...'); |
| 44 | + const firstSectionEnd = sectionStarts[1] || mermaidLines.length; |
| 45 | + testLines = mermaidLines.slice(0, firstSectionEnd); |
| 46 | + writeTestFile(testLines, '/tmp/test-gantt-section1.md'); |
| 47 | + console.log('Created /tmp/test-gantt-section1.md with first section'); |
| 48 | + |
| 49 | + // Create files with incremental sections |
| 50 | + for (let i = 0; i < sectionStarts.length; i++) { |
| 51 | + const endLine = i + 1 < sectionStarts.length ? sectionStarts[i + 1] : mermaidLines.length; |
| 52 | + testLines = mermaidLines.slice(0, endLine); |
| 53 | + writeTestFile(testLines, `/tmp/test-gantt-${i + 1}sections.md`); |
| 54 | + console.log(`Created /tmp/test-gantt-${i + 1}sections.md`); |
| 55 | + } |
| 56 | + |
| 57 | + // Also create a minimal test |
| 58 | + console.log('\nCreating minimal test...'); |
| 59 | + const minimal = [ |
| 60 | + 'gantt', |
| 61 | + ' title Test', |
| 62 | + ' dateFormat YYYY-MM-DDTHH:mm:ss', |
| 63 | + ' axisFormat %H:%M:%S', |
| 64 | + ' section Test Section', |
| 65 | + ' task1 :a1, 2025-11-12T22:30:21, 2025-11-12T22:30:22', |
| 66 | + ' task2 :crit, a2, 2025-11-12T22:30:22, 2025-11-12T22:30:23', |
| 67 | + ' task3 :active, a3, 2025-11-12T22:30:23, 2025-11-12T22:30:24', |
| 68 | + ' task4 :milestone, a4, 2025-11-12T22:30:24, 2025-11-12T22:30:24', |
| 69 | + ]; |
| 70 | + writeTestFile(minimal, '/tmp/test-gantt-minimal.md'); |
| 71 | + console.log('Created /tmp/test-gantt-minimal.md'); |
| 72 | + |
| 73 | + // Print first few task lines for inspection |
| 74 | + console.log('\nFirst 10 task lines:'); |
| 75 | + let taskCount = 0; |
| 76 | + for (const line of mermaidLines) { |
| 77 | + if (line.trim() && !line.trim().startsWith('gantt') && !line.trim().startsWith('title') && |
| 78 | + !line.trim().startsWith('dateFormat') && !line.trim().startsWith('axisFormat') && |
| 79 | + !line.trim().startsWith('section')) { |
| 80 | + console.log(` ${line}`); |
| 81 | + taskCount++; |
| 82 | + if (taskCount >= 10) break; |
| 83 | + } |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +function writeTestFile(mermaidLines: string[], outputPath: string) { |
| 88 | + const output = [ |
| 89 | + '# Test Mermaid Gantt', |
| 90 | + '', |
| 91 | + '```mermaid', |
| 92 | + ...mermaidLines, |
| 93 | + '```' |
| 94 | + ].join('\n'); |
| 95 | + writeFileSync(outputPath, output); |
| 96 | +} |
| 97 | + |
| 98 | +if (require.main === module) { |
| 99 | + main(); |
| 100 | +} |
0 commit comments