{"record":{"id":"335a2bef968cf184","repo":"koala73/worldmonitor","slug":"llms-txt-path-carries-headings-length-comparisons-heading","errorCode":null,"errorMessage":"${LLMS_TXT_PATH} carries ${headings.length} \"${COMPARISONS_HEADING}\" headings; keep exactly one","messagePattern":"(.+?) carries (.+?) \"(.+?)\" headings; keep exactly one","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/build-llms-full.mjs","lineNumber":275,"sourceCode":"    '## Source provider directory',\n    '',\n    `World Monitor publishes ${catalog.length} named providers across ${pages.length} source catalog pages. Each linked page contains provider names, source hosts, origins and coverage in static HTML; no search or JavaScript is required.`,\n    '',\n    ...pages.map((page) => `- [${page.name}](${SITE_ORIGIN}${page.path}): ${page.providers.length} providers.`),\n  ].join('\\n');\n}\n\n/**\n * Splice the generated Comparisons section into the hand-maintained\n * llms.txt: replace the existing section in place, or insert it ahead of\n * Live Instances the first time. Idempotent, so --check can diff it.\n */\nexport function withComparisonsSection(llmsTxt) {\n  const text = String(llmsTxt);\n  const block = renderComparisons();\n  const headings = [...text.matchAll(/^## Comparisons$/gm)];\n  if (headings.length > 1) {\n    throw new Error(`${LLMS_TXT_PATH} carries ${headings.length} \"${COMPARISONS_HEADING}\" headings; keep exactly one`);\n  }\n  if (headings.length === 1) {\n    const start = headings[0].index;\n    const nextHeading = text.indexOf('\\n## ', start + COMPARISONS_HEADING.length);\n    const end = nextHeading === -1 ? text.length : nextHeading;\n    return `${text.slice(0, start)}${block}\\n${text.slice(end)}`;\n  }\n  const anchor = `\\n${COMPARISONS_ANCHOR_HEADING}\\n`;\n  const at = text.indexOf(anchor);\n  if (at === -1) {\n    throw new Error(`${LLMS_TXT_PATH} must carry a \"${COMPARISONS_ANCHOR_HEADING}\" heading to anchor the Comparisons section`);\n  }\n  return `${text.slice(0, at + 1)}${block}\\n${text.slice(at)}`;\n}\n\nexport function buildLlmsFullText({ rootDir = ROOT } = {}) {\n  const existing = existsSync(join(rootDir, OUTPUT_PATH))\n    ? read(rootDir, OUTPUT_PATH)","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/koala73/worldmonitor/blob/7d06c8633d256c18e38133030bc3613976a96ec9/scripts/build-llms-full.mjs#L257-L293","documentation":"withComparisonsSection injects the Comparisons section into llms.txt. It scans for the exact markdown heading '^## Comparisons$'; if the text already contains more than one such heading, splicing would be ambiguous, so it throws instructing you to keep exactly one.","triggerScenarios":"Calling withComparisonsSection (or the build-llms-full pipeline) on an llms.txt that already contains two or more literal '## Comparisons' H2 headings — typically because the section was manually pasted in or a previous injection was duplicated.","commonSituations":"Hand-editing public/llms.txt and copy-pasting the Comparisons block twice; merging branches that both added the section; re-running an older script version that appended instead of replacing.","solutions":["Open public/llms.txt and remove the duplicate '## Comparisons' heading(s), keeping one (or none — the function will insert it).","Prefer regenerating: delete the hand-added copies and run npm run build:llms-full so the function injects the canonical block.","Check the input source for accidental duplication from a merge or earlier script run."],"exampleFix":"// before (llms.txt)\n## Comparisons\n...\n## Comparisons\n...\n// after\n## Comparisons\n... (single instance)","handlingStrategy":"validation","validationCode":"const n = [...text.matchAll(/^## Comparisons$/gm)].length;\nif (n > 1) throw new Error(`duplicate ## Comparisons headings: ${n}`);","typeGuard":null,"tryCatchPattern":"try { out = withComparisonsSection(txt); } catch (e) { console.error('Fix llms.txt:', e.message); process.exit(1); }","preventionTips":["Never hand-paste the Comparisons block into llms.txt.","Regenerate with npm run build:llms-full instead of editing.","Watch for merge conflicts around the section."],"tags":["build","llms-txt","duplicate-content"],"backgroundTag":"internal-invariant-violation","analyzedSha":"7d06c8633d256c18e38133030bc3613976a96ec9","analyzedAt":"2026-09-15T16:44:39.439Z","contentChangedAt":"2026-09-15T16:44:39.439Z","schemaVersion":2},"datasetVersion":"2026-09-15T18:17:12.389Z"}