(lineIndex: number)
| 987 | |
| 988 | // Find the current section header for context |
| 989 | const getCurrentHeader = (lineIndex: number): string => { |
| 990 | let headerContext = ""; |
| 991 | let currentHeaderLevel = Number.MAX_SAFE_INTEGER; |
| 992 | |
| 993 | for (const header of headers) { |
| 994 | if (header.lineIndex < lineIndex && header.level <= currentHeaderLevel) { |
| 995 | headerContext = `${"#".repeat(header.level)} ${header.title}`; |
| 996 | currentHeaderLevel = header.level; |
| 997 | |
| 998 | // If it's the main h1 header, we don't need to go further |
| 999 | // This ensures we get the nearest section header, not the document title |
| 1000 | if ( |
| 1001 | header.level === 1 && |
| 1002 | headers.some((h) => h.level === 2 && h.lineIndex < lineIndex) |
| 1003 | ) { |
| 1004 | continue; |
| 1005 | } |
| 1006 | |
| 1007 | // We found a direct section header (h2 or h3) |
| 1008 | if (header.level === 2 || header.level === 3) { |
| 1009 | break; |
| 1010 | } |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | return headerContext; |
| 1015 | }; |
| 1016 | |
| 1017 | // Step 2: Process content based on document type |
| 1018 | // For llms.txt files, we need to handle both bullet point lists and non-bullet point format |
no outgoing calls
no test coverage detected