fix: handle CRLF line endings in markdown heading regex

The HEADING_RE regex used `$` to anchor the end of heading lines,
but on Windows, `String.split('\n')` leaves `\r` at the end of each
line. The `$` anchor does not match before `\r` in JavaScript's
non-multiline mode, causing the regex to silently skip every heading
in CRLF-encoded files.

This resulted in 0 Section nodes being created for markdown files
on Windows, while the same files indexed correctly on macOS/Linux.

Fix: replace `.+$` with `.+?[\r\t ]*$` to consume optional trailing
whitespace and carriage returns before the anchor.

Tested on a 424-file markdown-heavy repo on Windows:
  Before: 22 sections (only from LF-encoded files)
  After:  8,072 sections (all files)
This commit is contained in:
Roger Parkinson 2026-03-21 23:19:31 -04:00
parent b75e380bd0
commit 8ea1f46ae5

View file

@ -10,7 +10,7 @@ import path from 'node:path';
import { generateId } from '../../lib/utils.js';
import { KnowledgeGraph, GraphNode, GraphRelationship } from '../graph/types.js';
const HEADING_RE = /^(#{1,6})\s+(.+)$/;
const HEADING_RE = /^(#{1,6})\s+(.+?)[\r\t ]*$/;
const LINK_RE = /\[([^\]]*)\]\(([^)]+)\)/g;
const MD_EXTENSIONS = new Set(['.md', '.mdx']);