// kb-headers.mjs — Parse optional authority headers from KB reference files. // Zero dependencies. Scans only the top of the file (header region) where the // **Source:** / **Primary source:** line lives, mirroring report-changes' // parseLastUpdated convention. const HEADER_REGION_BYTES = 500; const SOURCE_PATTERNS = [ /\*\*Source:\*\*\s*(\S+)/i, /\*\*Primary source:\*\*\s*(\S+)/i, ]; /** * Extract the declared authority source URL from a KB reference file's header. * @param {string} content — full file content (only the first 500 bytes are scanned) * @returns {string|null} the source URL, or null if no header is present */ export function parseSourceHeader(content) { if (!content || typeof content !== 'string') return null; const head = content.slice(0, HEADER_REGION_BYTES); for (const pattern of SOURCE_PATTERNS) { const match = head.match(pattern); if (match) return match[1].trim(); } return null; }