turva-llms-txt-validator 0.5.1 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -82,7 +82,7 @@ The two discovery checks return `pass` or `info`. They never change the summary
82
82
  npx --yes turva-llms-txt-validator example.com --json --strict
83
83
  ```
84
84
 
85
- Completed validation returns `{ target, summary, checks }`, where `target` is `https://<host>/llms.txt`. Each check contains `{ id, status, label, detail }`. The `input-path` check, which reports a path given with the domain and then ignored, also carries `value`, that path cut to 120 characters.
85
+ Completed validation returns `{ target, summary, checks }`, where `target` is `https://<host>/llms.txt`. Each check contains `{ id, status, label, detail }`. Read `id` and `status` in a script, because the wording of `detail` can change between versions. The `input-path` check, which reports a path given with the domain and then ignored, also carries `value`, that path cut to 120 characters.
86
86
 
87
87
  With `--json`, an invalid domain or a failed fetch returns `{ "error": "...", "target": "..." }` and exits with code `2`. A network error adds `code`, such as `EAI_AGAIN`. An unknown option, a second domain and a missing domain return `{ "error": "..." }` only, with no target, and also exit with code `2`.
88
88
 
@@ -114,6 +114,8 @@ Some failures stop the file checks early. For example, an HTML response is repor
114
114
  Links are read the way CommonMark reads them for the forms listed here.
115
115
 
116
116
  - A link inside inline code, after an escaped bracket or in an image does not count.
117
+ - Inline code pairs only inside one block, the way CommonMark reads blocks. A blank line, a heading, a list item, a thematic break and a setext underline each end a block. An empty list item or a numbered item that does not start at 1 does not end a paragraph, unless the line closes an open list item, so a backtick pair across such a line is inline code. Block quotes and HTML blocks are not read as blocks here, so a backtick pair across the start of one, or across lines inside a block quote, stays inline code. CommonMark ends the block at a block quote and at an HTML block that can interrupt a paragraph.
118
+ - A fence inside a list item counts as a fence, closed or not, in either fence character, on the marker line or up to three columns past the item's content column. It ends when the item closes. Four or more columns past that column is indented code.
117
119
  - A link in an ordered list, a target in angle brackets and a target with a title in double or single quotes do count.
118
120
  - A title in parentheses is not read, so `[Guide](https://example.org/guide (Overview))` is not collected.
119
121
  - An unbracketed target ends at its first closing parenthesis, so `https://example.org/docs_(v2)` is read only up to `https://example.org/docs_(v2`. Write a target that contains parentheses in angle brackets.
@@ -125,13 +127,14 @@ Links are read the way CommonMark reads them for the forms listed here.
125
127
 
126
128
  A heading is an H2 when `##` is followed by a space or a tab, or when it is one line of text underlined with hyphens. The text line must follow a blank line or the start of the file. A list item above a line of hyphens is not an H2, and neither is a line of hyphens after a blank line.
127
129
 
128
- A link in a four-space indented code block counts as a link, but such a block does not count as a file list under an H2.
130
+ A link in a four-space indented code block counts as a link unless a backtick pair encloses it. Outside a list item, such a block does not count as a file list under an H2.
129
131
 
130
132
  A link on a line that continues a list item, such as the line after a bare `-`, counts as that item's link:
131
133
 
132
134
  - After a bare marker the next line counts only when it is indented to the item's content column, which is 2 for `-` and 3 for `1.`. A blank line right after a bare marker ends the item.
133
135
  - After a blank line inside an item, a line counts only when it is indented to the content column, where the item's text starts, so `- item` needs 4 columns.
134
- - A code fence indented less than that column ends the item. A fence indented to it keeps the item open, and the line after the fence then counts only when it is indented to that column too.
136
+ - A code fence indented less than that column ends the item. A fence indented to it keeps the item open, and a lazy continuation cannot follow a fence, so the line after it needs the indent too.
137
+ - In a nested list, the content column of any item still open is enough for a line after a blank line or a fence.
135
138
 
136
139
  ### Home-page discovery
137
140
 
@@ -199,7 +202,7 @@ For vulnerability reporting and supported versions, see [SECURITY.md](https://gi
199
202
 
200
203
  The source is TypeScript under `src/` and `bin/`, compiled with `tsc` to `dist/`. The tarball ships only `dist/src/index.js`, `dist/src/index.d.ts`, `dist/bin/cli.js`, the README, the license, the third-party notices and `package.json`, which npm always includes. `dist/` is generated, and `npm pack` builds it through the `prepack` script.
201
204
 
202
- GitHub Actions tests Node.js 22 and 24 on Ubuntu and Node.js 22 on Windows. A version tag starts the release workflow, `.github/workflows/publish.yml`. It runs the type check and the tests, fails when the tag and `package.json` name different versions, publishes with npm trusted publishing over OIDC and creates the GitHub release from the CHANGELOG section. npm writes a provenance attestation. No npm token is stored in the repository or in the workflow.
205
+ GitHub Actions tests Node.js 22, 24 and 26 on Ubuntu and Node.js 22 on Windows. A version tag starts the release workflow, `.github/workflows/publish.yml`. It runs the type check and the tests, fails when the tag and `package.json` name different versions, publishes with npm trusted publishing over OIDC and creates the GitHub release from the CHANGELOG section. npm writes a provenance attestation. No npm token is stored in the repository or in the workflow.
203
206
 
204
207
  ## From JavaScript to TypeScript
205
208
 
@@ -212,10 +215,10 @@ The strict type check found two inputs that could leave `undefined` in a check's
212
215
  GitHub Actions publishes every version from 0.1.3 on with npm trusted publishing, and each one carries a provenance attestation. To check one, install it in an empty directory and ask npm to verify the signatures. Replace the version with the one you want to check.
213
216
 
214
217
  ```sh
215
- mkdir verify-llms && cd verify-llms && npm init -y && npm install turva-llms-txt-validator@0.5.1 --ignore-scripts && npm audit signatures
218
+ mkdir verify-llms && cd verify-llms && npm init -y && npm install turva-llms-txt-validator@0.6.1 --ignore-scripts && npm audit signatures
216
219
  ```
217
220
 
218
- `npm audit signatures` checks the registry signature and the provenance attestation of each installed package that has one. The attestation of this package names three things to compare with what you expect: the repository `github.com/erekola/llms-txt-validator`, the workflow file `.github/workflows/publish.yml` and the commit that produced the tarball. The npm version page shows them under Provenance. Tag `v0.5.1` must point at that same commit, and `gh api repos/erekola/llms-txt-validator/commits/v0.5.1 --jq .sha` prints it. A mismatch is a reason not to use that version. Provenance proves which workflow built a release and from which commit. It does not prove that the code is safe, so reading the source and the dependencies stays your job.
221
+ `npm audit signatures` checks the registry signature and the provenance attestation of each installed package that has one. The attestation of this package names three things to compare with what you expect: the repository `github.com/erekola/llms-txt-validator`, the workflow file `.github/workflows/publish.yml` and the commit that produced the tarball. The npm version page shows them under Provenance. Tag `v0.6.1` must point at that same commit, and `gh api repos/erekola/llms-txt-validator/commits/v0.6.1 --jq .sha` prints it. A mismatch is a reason not to use that version. Provenance proves which workflow built a release and from which commit. It does not prove that the code is safe, so reading the source and the dependencies stays your job.
219
222
 
220
223
  ## Development
221
224
 
package/dist/src/index.js CHANGED
@@ -273,35 +273,30 @@ function isEscaped(s, i) {
273
273
  // span itself crosses a real line ending. V2 (Tek-526): a fenceless "`[a](b)\ncontinued`" was
274
274
  // masked only on its own line, so the second line escaped the mask and its bracket read as a
275
275
  // real link. A span opens with a run of backticks and closes with the next run of the same
276
- // length anywhere in the text; a pair that crosses a block boundary, a blank line (blank or
277
- // made only of spaces and tabs), a heading line or a new list item, is not a code span in
278
- // CommonMark, so it is left unmasked and its backticks stay literal (VREG2, round 3 Tek-542:
279
- // backticks in two different list items used to enclose a real hyperlink between them). Such a
280
- // pair consumes neither run: its closer is still free to open a span of its own in its own
276
+ // length anywhere in the text. A pair in two different blocks, as inlineBlockReader reads them,
277
+ // is not a code span in CommonMark, so it is left unmasked and its backticks stay literal (VREG2,
278
+ // round 3 Tek-542: backticks in two different list items used to enclose a real hyperlink
279
+ // between them). Such a pair consumes neither run: its closer is still free to open a span of its own in its own
281
280
  // block. Until 2026-11-04 the scan jumped past the closer, so a stray backtick moved the mask by
282
281
  // one run, a link inside the next real span counted as a link and text after it could count as
283
282
  // code (Tek-745). An escaped first backtick is literal and the rest of its run still opens, while
284
283
  // a closing run is never escaped, because a backslash inside a code span is literal. Each run
285
- // carries the number of boundary lines before it, read once per line, so comparing two runs
284
+ // carries the number of its block, read once per line, so comparing two runs
286
285
  // costs nothing however far apart they sit. Runs are grouped by length and every group is read
287
286
  // with one forward pointer, so the scan stays linear on a document of unmatched runs. Mirrored
288
- // from the hosted validator at turva.dev in 0.5.1.
289
- function endsInlineBlock(line) {
290
- return /^[ \t]*$/.test(line) || /^ {0,3}(#{1,6}(?:[ \t]|$)|[-*+][ \t]|\d{1,9}[.)][ \t])/.test(line);
291
- }
292
- function codeSpanMask(text) {
287
+ // from the hosted validator at turva.dev in 0.6.0.
288
+ function codeSpanMask(text, lineBlocks = readBlocks(text.split("\n"))) {
293
289
  const mask = new Uint8Array(text.length);
294
290
  const runs = [];
295
- let block = 0;
291
+ let line = 0;
292
+ let block = lineBlocks[0];
296
293
  for (let i = 0; i < text.length;) {
297
294
  if (text[i] === "\n") {
298
- const next = text.indexOf("\n", i + 1);
299
- if (endsInlineBlock(text.slice(i + 1, next < 0 ? text.length : next)))
300
- block++;
295
+ block = lineBlocks[++line];
301
296
  i++;
302
297
  continue;
303
298
  }
304
- if (text[i] !== "`") {
299
+ if (text[i] !== "`" || block < 0) {
305
300
  i++;
306
301
  continue;
307
302
  }
@@ -335,6 +330,153 @@ function codeSpanMask(text) {
335
330
  }
336
331
  return mask;
337
332
  }
333
+ // Which inline block each line belongs to, read once per line in document order, because two
334
+ // backtick runs pair only inside one block. Measured against commonmark.js 0.31.2, Tek-747. A
335
+ // blank line, an ATX heading, a thematic break and a setext underline end a paragraph, and the
336
+ // next line starts a new block, so a backtick on a heading line never pairs with the next line. A
337
+ // list marker starts a new block, with the exception CommonMark sets: a line that would continue
338
+ // an open paragraph cannot open a list with an empty item or with a number other than 1. The
339
+ // number is compared as a number, so "01." counts as 1. That exception holds only while the
340
+ // paragraph is the innermost open container. A line indented less than an open item's content
341
+ // column closes that item, so "2." there is the list's next item, which is why the reader keeps
342
+ // the content column of every open item. An empty item followed by a blank line is closed. An
343
+ // indented line continues an open paragraph, and a run of indented lines with no paragraph open is
344
+ // one block, so backticks in it still pair. For every line of a fence the reader returns -1. The reader
345
+ // runs over the raw lines only: readBlocks gives the numbers, fenceMask blanks
346
+ // the lines marked -1 and codeSpanMask pairs by the same numbers, because reading the blanked text a
347
+ // second time could disagree with the first reading and hide a real link (found by the independent
348
+ // checks of Tek-749). A fence holds whatever comes before its closer, in either character, and it
349
+ // ends when an open item it sits in closes. An opening backtick fence may
350
+ // not carry a backtick in its info string, while a tilde fence may. A later round will read the
351
+ // consequence as a bug and it is not: in ```js `x` the info string holds a backtick, so that line is
352
+ // prose, and a bare ``` after it OPENS a block instead of closing one. CommonMark reads the same
353
+ // input the same way, measured against the spec 2026-09-10. Block quotes and HTML blocks
354
+ // are not read here, neither the start of one nor the lines of a block quote. Every pattern runs at
355
+ // a fixed position, the thematic break test and the closing fence test run once per line, and the
356
+ // walk over the open items stops at the line's own width, so the reader stays linear however deep
357
+ // the items nest.
358
+ const INLINE_HEADING = /#{1,6}(?:[ \t]|$)/y;
359
+ const INLINE_UNDERLINE = /(?:=+|-+)[ \t]*$/y;
360
+ const INLINE_THEMATIC = /([-*_])(?:[ \t]*\1){2,}[ \t]*$/y;
361
+ const INLINE_MARKER = /(?:[-*+]|(\d{1,9})[.)])(?=[ \t]|$)/y;
362
+ const INLINE_FENCE = /(`{3,})[^`]*$|(~{3,})/y;
363
+ function matchAt(re, s, at) {
364
+ re.lastIndex = at;
365
+ return re.exec(s);
366
+ }
367
+ function readBlocks(lines) {
368
+ const blockOf = inlineBlockReader();
369
+ return lines.map((l) => blockOf(l));
370
+ }
371
+ function inlineBlockReader() {
372
+ let block = 0, para = false, code = false, emptyItem = false;
373
+ let fenceChar = "", fenceLen = 0, fenceDepth = 0;
374
+ const items = [];
375
+ return (line) => {
376
+ let p = 0, col = 0;
377
+ const skipBlanks = () => {
378
+ for (; p < line.length; p++) {
379
+ if (line[p] === " ")
380
+ col++;
381
+ else if (line[p] === "\t")
382
+ col += 4 - (col % 4);
383
+ else
384
+ break;
385
+ }
386
+ };
387
+ skipBlanks();
388
+ if (p === line.length) {
389
+ if (fenceChar !== "")
390
+ return -1;
391
+ if (emptyItem)
392
+ items.pop();
393
+ emptyItem = false;
394
+ para = false;
395
+ code = false;
396
+ return ++block;
397
+ }
398
+ emptyItem = false;
399
+ let depth = 0;
400
+ while (depth < items.length && col >= items[depth])
401
+ depth++;
402
+ if (fenceChar !== "") {
403
+ if (depth >= fenceDepth) {
404
+ if (col - (fenceDepth > 0 ? items[fenceDepth - 1] : 0) < 4) {
405
+ let end = p;
406
+ while (line[end] === fenceChar)
407
+ end++;
408
+ if (end - p >= fenceLen && line.slice(end).trim() === "")
409
+ fenceChar = "";
410
+ }
411
+ return -1;
412
+ }
413
+ fenceChar = "";
414
+ }
415
+ let inParagraph = para && depth === items.length;
416
+ let thematicRead = false;
417
+ for (;;) {
418
+ if (col - (depth > 0 ? items[depth - 1] : 0) >= 4) {
419
+ if (para)
420
+ return block;
421
+ items.length = depth;
422
+ if (code)
423
+ return block;
424
+ code = true;
425
+ return ++block;
426
+ }
427
+ code = false;
428
+ if (matchAt(INLINE_HEADING, line, p)) {
429
+ items.length = depth;
430
+ para = false;
431
+ return ++block;
432
+ }
433
+ const fence = matchAt(INLINE_FENCE, line, p);
434
+ if (fence) {
435
+ items.length = depth;
436
+ para = false;
437
+ fenceChar = line[p];
438
+ fenceLen = (fence[1] || fence[2]).length;
439
+ fenceDepth = depth;
440
+ return -1;
441
+ }
442
+ if (inParagraph && matchAt(INLINE_UNDERLINE, line, p)) {
443
+ para = false;
444
+ return block;
445
+ }
446
+ if (!thematicRead && matchAt(INLINE_THEMATIC, line, p)) {
447
+ items.length = depth;
448
+ para = false;
449
+ return ++block;
450
+ }
451
+ thematicRead = true;
452
+ const marker = matchAt(INLINE_MARKER, line, p);
453
+ if (!marker)
454
+ break;
455
+ p += marker[0].length;
456
+ col += marker[0].length;
457
+ const afterMarker = col;
458
+ skipBlanks();
459
+ const empty = p === line.length;
460
+ if (inParagraph && (empty || (marker[1] !== undefined && Number(marker[1]) !== 1)))
461
+ break;
462
+ items.length = depth;
463
+ items.push(empty || col - afterMarker >= 5 ? afterMarker + 1 : col);
464
+ depth = items.length;
465
+ para = false;
466
+ inParagraph = false;
467
+ if (empty) {
468
+ emptyItem = true;
469
+ return block;
470
+ }
471
+ }
472
+ if (!para) {
473
+ items.length = depth;
474
+ para = true;
475
+ block++;
476
+ }
477
+ return block;
478
+ };
479
+ }
338
480
  // A CommonMark link reference label is matched without regard to case or the exact run of
339
481
  // whitespace inside it, so "[Guide]" and "[ guide ]" name the same definition.
340
482
  function normalizeLinkLabel(s) {
@@ -352,10 +494,10 @@ function normalizeLinkLabel(s) {
352
494
  // the whole line not a definition, matching CommonMark instead of reading everything up to the
353
495
  // next space as the title's own value. Only the first definition of a given label counts, per
354
496
  // spec. A destination wrapped in angle brackets has them stripped.
355
- function collectLinkDefinitions(text) {
497
+ function collectLinkDefinitions(text, lineBlocks) {
356
498
  const defs = new Map();
357
499
  const lines = text.split("\n");
358
- const code = codeSpanMask(text);
500
+ const code = codeSpanMask(text, lineBlocks);
359
501
  const starts = [];
360
502
  {
361
503
  let offset = 0;
@@ -403,11 +545,11 @@ function collectLinkDefinitions(text) {
403
545
  // the furthest failed plain target is remembered as before, and the closing ">", quote and line
404
546
  // end are looked up through a cache that only moves forward, so a file that repeats "[a](" or
405
547
  // "[a](x \"" stays linear.
406
- function collectLinks(text, defs) {
548
+ function collectLinks(text, defs, lineBlocks) {
407
549
  const out = [];
408
- const code = codeSpanMask(text);
550
+ const code = codeSpanMask(text, lineBlocks);
409
551
  if (!defs)
410
- defs = collectLinkDefinitions(text);
552
+ defs = collectLinkDefinitions(text, lineBlocks);
411
553
  const cache = Object.create(null);
412
554
  const nextIdx = (c, from) => {
413
555
  const h = cache[c];
@@ -571,50 +713,14 @@ function collectLinks(text, defs) {
571
713
  }
572
714
  // CommonMark fenced code blocks, marked line by line. A "## " or a link inside a fence is
573
715
  // example text and not the file's own structure, but until 2026-09-10 both counted, so a
574
- // file whose only section and only link lived inside ``` or ~~~ was reported valid. The
575
- // scan is one pass over the lines with no backtracking pattern, because the ReDoS repair
576
- // of 2026-08-24 bought a worse accuracy defect with a bounded quantifier and the rule out
577
- // of it was to scan by index instead (mds/gotchas.md 2026-08-24 (jatko 12)).
716
+ // file whose only section and only link lived inside ``` or ~~~ was reported valid. The fence
717
+ // itself is read by inlineBlockReader, so the validator has one reading of a fence, inside a list
718
+ // item too (Tek-749). Until 2026-11-04 this function read lines at 0 to 3 columns on its own, so
719
+ // it did not see a fence opened on a list marker line or indented further, and that fence's
720
+ // closing line at 0 to 3 columns opened a new fence that hid the lines up to the next fence. Mirrored from the hosted validator at turva.dev in 0.6.1.
578
721
  // Returns one boolean per line: true for a fence line and for everything inside it.
579
722
  function fenceMask(lines) {
580
- const mask = new Array(lines.length).fill(false);
581
- let fenceChar = "", fenceLen = 0;
582
- for (let i = 0; i < lines.length; i++) {
583
- const l = lines[i];
584
- let p = 0;
585
- while (p < 4 && l[p] === " ")
586
- p++;
587
- if (p > 3) {
588
- mask[i] = fenceChar !== "";
589
- continue;
590
- }
591
- const c = l[p];
592
- let run = 0;
593
- if (c === "`" || c === "~") {
594
- while (l[p + run] === c)
595
- run++;
596
- }
597
- if (fenceChar === "") {
598
- // An opening backtick fence may not carry a backtick in its info string; a tilde
599
- // fence may. Anything shorter than three markers is not a fence at all. A later
600
- // round will read the consequence as a bug and it is not: in ```js `x` the info
601
- // string holds a backtick, so that line is prose, and a bare ``` after it OPENS a
602
- // block instead of closing one. CommonMark reads the same input the same way,
603
- // measured against the spec 2026-09-10. Leave it.
604
- if (run >= 3 && (c !== "`" || l.indexOf("`", p + run) === -1)) {
605
- fenceChar = c;
606
- fenceLen = run;
607
- mask[i] = true;
608
- }
609
- continue;
610
- }
611
- mask[i] = true;
612
- if (c === fenceChar && run >= fenceLen && l.slice(p + run).trim() === "") {
613
- fenceChar = "";
614
- fenceLen = 0;
615
- }
616
- }
617
- return mask;
723
+ return readBlocks(lines).map((block) => block < 0);
618
724
  }
619
725
  // A markdown list item that carries a link. A bullet or an ordered marker (1. or 1)) followed by
620
726
  // a space or a tab opens the item; an ordered list and a tab after the marker were not read as
@@ -800,8 +906,8 @@ function h2Lines(lines, fenced) {
800
906
  // CommonMark's: an unclosed backtick run, or a pair that crosses a block boundary, is literal text.
801
907
  // A real tag, a closing tag or a comment start in prose still warns, and an autolink is still not
802
908
  // a tag. The package turva-llms-txt-validator mirrors this from 0.5.0.
803
- function blankCodeForHtml(prose) {
804
- const mask = codeSpanMask(prose);
909
+ function blankCodeForHtml(prose, lineBlocks) {
910
+ const mask = codeSpanMask(prose, lineBlocks);
805
911
  const out = [];
806
912
  for (let i = 0; i < prose.length; i++) {
807
913
  const c = prose[i];
@@ -862,8 +968,8 @@ function entryLineList(hits) {
862
968
  }
863
969
  function unparsedEntriesNote(found) {
864
970
  const u = found.unparsed.length, k = found.marker.length;
865
- return (u > 0 ? "; " + (u === 1 ? "1 list line looks like a link entry but is not a Markdown link" : u + " list lines look like link entries but are not Markdown links") + entryLineList(found.unparsed) : "")
866
- + (k > 0 ? "; " + (k === 1 ? "1 list line opens with a dash or bullet that is not a Markdown list marker" : k + " list lines open with a dash or bullet that is not a Markdown list marker") + entryLineList(found.marker) : "");
971
+ return (u > 0 ? ". " + (u === 1 ? "1 list line looks like a link entry but is not a Markdown link" : u + " list lines look like link entries but are not Markdown links") + entryLineList(found.unparsed) : "")
972
+ + (k > 0 ? ". " + (k === 1 ? "1 list line opens with a dash or bullet that is not a Markdown list marker" : k + " list lines open with a dash or bullet that is not a Markdown list marker") + entryLineList(found.marker) : "");
867
973
  }
868
974
  // The text of an ATX H1, or null when the line is not one. One to three leading spaces, a
869
975
  // single "#", then a space, a tab or the end of the line. A closing run of "#" preceded by a
@@ -910,11 +1016,11 @@ function isAbsoluteHttpUrl(t) {
910
1016
  }
911
1017
  function redirectFailDetail(f) {
912
1018
  if (f.reason === "off-host")
913
- return "redirects to " + f.location + ", a different host; llms.txt is host-scoped, so validate that host directly";
1019
+ return "redirects to " + f.location + ", a different host. llms.txt is host-scoped, so validate that host directly";
914
1020
  if (f.reason === "unsafe-target")
915
- return "redirects to an unsupported target (" + f.location + "); only https redirects to the same site are followed";
1021
+ return "redirects to an unsupported target (" + f.location + "). Only https redirects to the same site are followed";
916
1022
  if (f.reason === "too-many")
917
- return "too many redirects; the llms.txt is not served at a stable URL";
1023
+ return "too many redirects. The llms.txt is not served at a stable URL";
918
1024
  return "got a " + f.status + " redirect without a usable Location header";
919
1025
  }
920
1026
  export function validateLlmsTxt(f) {
@@ -974,7 +1080,7 @@ export function validateLlmsTxt(f) {
974
1080
  add("h1-title", "pass", "Starts with an H1 title", JSON.stringify(cut(first, 80)));
975
1081
  }
976
1082
  else if (title === "") {
977
- add("h1-title", "fail", "Starts with an H1 title", "the H1 has no text; the format requires the project name there");
1083
+ add("h1-title", "fail", "Starts with an H1 title", "the H1 has no text. The format requires the project name there");
978
1084
  }
979
1085
  else {
980
1086
  add("h1-title", "fail", "Starts with an H1 title", "the first non-empty line should be a markdown H1 (# Site name, or one line of text underlined with =)");
@@ -1032,7 +1138,8 @@ export function validateLlmsTxt(f) {
1032
1138
  // listItemHasLink have allowed since 2026-08-29. Until 2026-09-10 this one line still
1033
1139
  // demanded column zero, so a correct file indented by one to three spaces was reported as
1034
1140
  // having no sections at all while its list under the same indentation counted fine.
1035
- const fenced = fenceMask(lines);
1141
+ const lineBlocks = readBlocks(lines);
1142
+ const fenced = lineBlocks.map((block) => block < 0);
1036
1143
  // Computed once for both the section-list scan below and the links check further down, so a
1037
1144
  // reference link definition written anywhere in the prose resolves the same way for each
1038
1145
  // (outside review 2026-09-28, V2): "[text][label]" used to be recognized in the whole-document
@@ -1041,8 +1148,8 @@ export function validateLlmsTxt(f) {
1041
1148
  // joining the survivors let a link's own target span straight across a fenced code block, as
1042
1149
  // if the fence had never separated the two halves.
1043
1150
  const proseText = lines.map((l, i) => (fenced[i] ? "" : l)).join("\n");
1044
- const linkDefs = collectLinkDefinitions(proseText);
1045
- const proseLinks = collectLinks(proseText, linkDefs);
1151
+ const linkDefs = collectLinkDefinitions(proseText, lineBlocks);
1152
+ const proseLinks = collectLinks(proseText, linkDefs, lineBlocks);
1046
1153
  // Which original line each recognized link starts on, so the section scan below can ask "does
1047
1154
  // this line carry a link" against the same whole-document result the links check itself uses,
1048
1155
  // instead of re-finding links one isolated line at a time (outside review 2026-09-28, V2).
@@ -1076,7 +1183,10 @@ export function validateLlmsTxt(f) {
1076
1183
  // Both passed until 2026-09-27 (Tek-496). The first one is named in the detail.
1077
1184
  let sectionsWithList = 0, misplaced = -1;
1078
1185
  {
1079
- let inSection = false, counted = false, seenH2 = false, itemOpen = false, itemGap = false, itemEmpty = false, itemCol = 0, afterFence = false;
1186
+ let inSection = false, counted = false, seenH2 = false, itemOpen = false, itemGap = false, itemEmpty = false, emptyOuter = false, afterFence = false;
1187
+ // The content column of the outermost open list item. A line after a blank line or a fence stays in
1188
+ // the list when it reaches this column, so in a nested list it can be the outer item's (Tek-749).
1189
+ let outerCol = 0;
1080
1190
  // Width of the leading white space of a line in columns, a tab running to the next multiple of 4.
1081
1191
  const indentWidth = (s) => { let c = 0; for (const ch of s) {
1082
1192
  if (ch === " ")
@@ -1088,16 +1198,18 @@ export function validateLlmsTxt(f) {
1088
1198
  } return c; };
1089
1199
  for (let i = 0; i < lines.length; i++) {
1090
1200
  const l = lines[i];
1091
- // A code fence indented less than the item's content column closes the open item, so a link
1201
+ // A code fence indented less than an item's content column closes that item, so a link
1092
1202
  // after it is not that item's link. The content column is where the item's text starts, 2 for
1093
1203
  // "- item" and 4 for "- item". A fence indented to that column is inside the item and keeps
1094
1204
  // it open, as in CommonMark, but the line after it then counts only when it is indented to
1095
1205
  // that column too, because a lazy continuation cannot follow a fence.
1096
1206
  if (fenced[i]) {
1097
- if (l.trim() !== "" && indentWidth(l) < itemCol)
1207
+ if (l.trim() !== "" && indentWidth(l) < outerCol)
1098
1208
  itemOpen = false;
1099
- if (itemOpen)
1209
+ if (itemOpen) {
1100
1210
  afterFence = true;
1211
+ itemEmpty = false;
1212
+ }
1101
1213
  continue;
1102
1214
  }
1103
1215
  if (hm.under[i] || sx.under[i])
@@ -1124,15 +1236,17 @@ export function validateLlmsTxt(f) {
1124
1236
  // continuation (CommonMark): the next line counts only when indented to the content column,
1125
1237
  // and a blank line right after the empty marker closes the item.
1126
1238
  if (l.trim() === "") {
1127
- if (itemEmpty)
1128
- itemOpen = false;
1239
+ if (itemEmpty) {
1240
+ if (emptyOuter)
1241
+ itemOpen = false;
1242
+ itemEmpty = false;
1243
+ }
1129
1244
  itemGap = itemOpen;
1130
1245
  continue;
1131
1246
  }
1132
1247
  const fromFence = afterFence;
1133
1248
  afterFence = false;
1134
1249
  if (/^ {0,3}(?:[-*+]|\d{1,9}[.)])(?:[ \t]|$)/.test(l)) {
1135
- itemOpen = true;
1136
1250
  itemGap = false;
1137
1251
  itemEmpty = /^ {0,3}(?:[-*+]|\d{1,9}[.)])[ \t]*$/.test(l);
1138
1252
  {
@@ -1144,8 +1258,13 @@ export function validateLlmsTxt(f) {
1144
1258
  let c = markerEnd;
1145
1259
  for (const ch of mk[3])
1146
1260
  c += ch === "\t" ? 4 - (c % 4) : 1;
1147
- itemCol = (mk[0].length === l.length || c - markerEnd > 4) ? markerEnd + 1 : c;
1261
+ emptyOuter = false;
1262
+ if (!itemOpen || mk[1].length < outerCol) {
1263
+ outerCol = (mk[0].length === l.length || c - markerEnd > 4) ? markerEnd + 1 : c;
1264
+ emptyOuter = itemEmpty;
1265
+ }
1148
1266
  }
1267
+ itemOpen = true;
1149
1268
  if (inSection && !counted && listItemHasLink(l, linkedLineIdx.has(i))) {
1150
1269
  sectionsWithList++;
1151
1270
  counted = true;
@@ -1156,7 +1275,7 @@ export function validateLlmsTxt(f) {
1156
1275
  itemOpen = false;
1157
1276
  continue;
1158
1277
  }
1159
- const indented = indentWidth(l) >= itemCol;
1278
+ const indented = indentWidth(l) >= outerCol;
1160
1279
  if (itemOpen && (!itemGap || indented) && (!itemEmpty || indented) && (!fromFence || indented)) {
1161
1280
  if (inSection && !counted && linkedLineIdx.has(i)) {
1162
1281
  sectionsWithList++;
@@ -1174,15 +1293,15 @@ export function validateLlmsTxt(f) {
1174
1293
  add("sections", "pass", "H2 sections group the content", h2Count + " section" + (h2Count === 1 ? "" : "s") + ", " + sectionsWithList + " carrying a file list");
1175
1294
  }
1176
1295
  else if (h2Count > 0) {
1177
- add("sections", "warn", "H2 sections group the content", h2Count + " section" + (h2Count === 1 ? "" : "s") + " but no file list under any of them; the format puts a section's links in a markdown list");
1296
+ add("sections", "warn", "H2 sections group the content", h2Count + " section" + (h2Count === 1 ? "" : "s") + " but no file list under any of them. The format puts a section's links in a markdown list");
1178
1297
  }
1179
1298
  else {
1180
- add("sections", "warn", "H2 sections group the content", "no H2 sections found; sections are the convention for grouping links");
1299
+ add("sections", "warn", "H2 sections group the content", "no H2 sections found. Sections are the convention for grouping links");
1181
1300
  }
1182
1301
  if (misplaced !== -1) {
1183
1302
  const s = checks[checks.length - 1];
1184
1303
  s.status = "warn";
1185
- s.detail += "; the heading at line " + (misplaced + 1) + " is out of place, because the format has one H1 and no other heading before the first H2";
1304
+ s.detail += ". The heading at line " + (misplaced + 1) + " is out of place, because the format has one H1 and no other heading before the first H2";
1186
1305
  }
1187
1306
  // Links are collected from the prose only, for the same reason the headings are: a link
1188
1307
  // shown inside a code fence is an example of a link, not one an agent can follow. Computed
@@ -1197,7 +1316,7 @@ export function validateLlmsTxt(f) {
1197
1316
  add("links", "warn", "Markdown links an agent can follow", "no markdown links found");
1198
1317
  }
1199
1318
  else if (unnamed > 0) {
1200
- add("links", "warn", "Markdown links an agent can follow", links.length + " link" + (links.length === 1 ? "" : "s") + ", " + unnamed + " with an empty link name; an entry needs a name an agent can show");
1319
+ add("links", "warn", "Markdown links an agent can follow", links.length + " link" + (links.length === 1 ? "" : "s") + ", " + unnamed + " with an empty link name. An entry needs a name an agent can show");
1201
1320
  }
1202
1321
  else if (absolute === named.length) {
1203
1322
  add("links", "pass", "Markdown links an agent can follow", named.length + " link" + (named.length === 1 ? "" : "s") + ", all absolute URLs");
@@ -1205,7 +1324,7 @@ export function validateLlmsTxt(f) {
1205
1324
  else {
1206
1325
  const relativeCount = named.filter((m) => !/^[a-z][a-z0-9+.-]*:/i.test(m.target)).length;
1207
1326
  const hostless = named.length - absolute - relativeCount;
1208
- add("links", "warn", "Markdown links an agent can follow", named.length + " links, " + relativeCount + " relative" + (hostless > 0 ? " and " + hostless + " that are not valid http or https URLs" : "") + "; absolute URLs travel better when the file is read out of context");
1327
+ add("links", "warn", "Markdown links an agent can follow", named.length + " links, " + relativeCount + " relative" + (hostless > 0 ? " and " + hostless + " that are not valid http or https URLs" : "") + ". Absolute URLs travel better when the file is read out of context");
1209
1328
  }
1210
1329
  // A list line that looks like a link entry but is not one (Tek-730) turns the links check to a warn.
1211
1330
  const lookalikes = unparsedLinkEntries(lines, fenced, new Set(proseLinks.map((m) => m.at)));
@@ -1221,7 +1340,7 @@ export function validateLlmsTxt(f) {
1221
1340
  add("size", "pass", "Small enough to be cheap to read", f.bytes + " bytes");
1222
1341
  }
1223
1342
  else {
1224
- add("size", "warn", "Small enough to be cheap to read", f.bytes + " bytes; consider moving detail to llms-full.txt");
1343
+ add("size", "warn", "Small enough to be cheap to read", f.bytes + " bytes. Consider moving detail to llms-full.txt");
1225
1344
  }
1226
1345
  // A tag needs its closing ">" (Tek-560): an opening tag with well formed attributes, a closing tag
1227
1346
  // or a comment start. "a <b + c" is prose and no longer warns. An attribute name is any run of
@@ -1232,9 +1351,9 @@ export function validateLlmsTxt(f) {
1232
1351
  // the same text, so the scan stays linear. A tag still open at the end of the file, as in
1233
1352
  // '<div class="x"', has no closing ">" and does not warn. Code is blanked first (Tek-730): a tag-like
1234
1353
  // string inside an inline code span, a fenced block or after a backslash is not markup.
1235
- const htmlScan = blankCodeForHtml(proseText);
1354
+ const htmlScan = blankCodeForHtml(proseText, lineBlocks);
1236
1355
  if (/<[a-zA-Z][a-zA-Z0-9-]*(?:\s+[^\s"'<>\/=\p{L}\p{N}_]*[\p{L}\p{N}_][^\s"'<>\/=]*(?:\s*=\s*(?:"[^"]*"|'[^']*'|(?!["'])[^\s<>]+))?)*\s*\/?>|<\/[a-zA-Z][a-zA-Z0-9-]*\s*>|<!--/u.test(htmlScan)) {
1237
- add("no-html", "warn", "No HTML markup in the file", "HTML tags found; llms.txt should be plain markdown");
1356
+ add("no-html", "warn", "No HTML markup in the file", "HTML tags found. llms.txt should be plain markdown");
1238
1357
  }
1239
1358
  else {
1240
1359
  add("no-html", "pass", "No HTML markup in the file", "plain markdown");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turva-llms-txt-validator",
3
- "version": "0.5.1",
3
+ "version": "0.6.1",
4
4
  "description": "Validate a site's llms.txt structure: eight checks as pass/warn/fail plus two llms.txt v2 discovery checks that read pass or info and never move the summary, JSON output. Same checks as the hosted validator at turva.dev/llms-txt-validator.",
5
5
  "type": "module",
6
6
  "main": "./dist/src/index.js",