turva-llms-txt-validator 0.6.0 → 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
@@ -115,7 +115,7 @@ 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
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 indented past three columns inside a list item hides what it holds, closed or not, as long as it sits less than four columns past the item's content column. Further in, CommonMark reads indented code, and this validator still counts a link in it. One gap remains for a fence opened on a list marker line, at four or more columns or by a tab: its closing line at 0 to 3 columns reads as a new opening fence, so the lines after it are skipped until the next fence.
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.
119
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.
120
120
  - A title in parentheses is not read, so `[Guide](https://example.org/guide (Overview))` is not collected.
121
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.
@@ -127,13 +127,14 @@ Links are read the way CommonMark reads them for the forms listed here.
127
127
 
128
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.
129
129
 
130
- 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.
131
131
 
132
132
  A link on a line that continues a list item, such as the line after a bare `-`, counts as that item's link:
133
133
 
134
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.
135
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.
136
- - 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.
137
138
 
138
139
  ### Home-page discovery
139
140
 
@@ -214,10 +215,10 @@ The strict type check found two inputs that could leave `undefined` in a check's
214
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.
215
216
 
216
217
  ```sh
217
- mkdir verify-llms && cd verify-llms && npm init -y && npm install turva-llms-txt-validator@0.6.0 --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
218
219
  ```
219
220
 
220
- `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.0` must point at that same commit, and `gh api repos/erekola/llms-txt-validator/commits/v0.6.0 --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.
221
222
 
222
223
  ## Development
223
224
 
package/dist/src/index.js CHANGED
@@ -285,22 +285,14 @@ function isEscaped(s, i) {
285
285
  // costs nothing however far apart they sit. Runs are grouped by length and every group is read
286
286
  // with one forward pointer, so the scan stays linear on a document of unmatched runs. Mirrored
287
287
  // from the hosted validator at turva.dev in 0.6.0.
288
- function codeSpanMask(text) {
288
+ function codeSpanMask(text, lineBlocks = readBlocks(text.split("\n"))) {
289
289
  const mask = new Uint8Array(text.length);
290
290
  const runs = [];
291
- const blockOf = inlineBlockReader();
292
- let block = 0;
293
- const readLine = (from) => {
294
- const next = text.indexOf("\n", from);
295
- const end = next < 0 ? text.length : next;
296
- block = blockOf(text.slice(from, end));
297
- if (block < 0)
298
- mask.fill(1, from, end);
299
- };
300
- readLine(0);
291
+ let line = 0;
292
+ let block = lineBlocks[0];
301
293
  for (let i = 0; i < text.length;) {
302
294
  if (text[i] === "\n") {
303
- readLine(i + 1);
295
+ block = lineBlocks[++line];
304
296
  i++;
305
297
  continue;
306
298
  }
@@ -349,11 +341,16 @@ function codeSpanMask(text) {
349
341
  // column closes that item, so "2." there is the list's next item, which is why the reader keeps
350
342
  // the content column of every open item. An empty item followed by a blank line is closed. An
351
343
  // indented line continues an open paragraph, and a run of indented lines with no paragraph open is
352
- // one block, so backticks in it still pair. A fence this reader sees is one the caller did not
353
- // blank, because fenceMask reads only lines at 0 to 3 columns: a fence indented further inside a
354
- // list item, or opened on a marker line. For every line of such a fence the reader returns -1 and
355
- // the scan masks the line whole, so a fence hides what it holds whatever closes it and whichever
356
- // character it uses. A fence ends when an open item it sits in closes. Block quotes and HTML blocks
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
357
354
  // are not read here, neither the start of one nor the lines of a block quote. Every pattern runs at
358
355
  // a fixed position, the thematic break test and the closing fence test run once per line, and the
359
356
  // walk over the open items stops at the line's own width, so the reader stays linear however deep
@@ -367,6 +364,10 @@ function matchAt(re, s, at) {
367
364
  re.lastIndex = at;
368
365
  return re.exec(s);
369
366
  }
367
+ function readBlocks(lines) {
368
+ const blockOf = inlineBlockReader();
369
+ return lines.map((l) => blockOf(l));
370
+ }
370
371
  function inlineBlockReader() {
371
372
  let block = 0, para = false, code = false, emptyItem = false;
372
373
  let fenceChar = "", fenceLen = 0, fenceDepth = 0;
@@ -493,10 +494,10 @@ function normalizeLinkLabel(s) {
493
494
  // the whole line not a definition, matching CommonMark instead of reading everything up to the
494
495
  // next space as the title's own value. Only the first definition of a given label counts, per
495
496
  // spec. A destination wrapped in angle brackets has them stripped.
496
- function collectLinkDefinitions(text) {
497
+ function collectLinkDefinitions(text, lineBlocks) {
497
498
  const defs = new Map();
498
499
  const lines = text.split("\n");
499
- const code = codeSpanMask(text);
500
+ const code = codeSpanMask(text, lineBlocks);
500
501
  const starts = [];
501
502
  {
502
503
  let offset = 0;
@@ -544,11 +545,11 @@ function collectLinkDefinitions(text) {
544
545
  // the furthest failed plain target is remembered as before, and the closing ">", quote and line
545
546
  // end are looked up through a cache that only moves forward, so a file that repeats "[a](" or
546
547
  // "[a](x \"" stays linear.
547
- function collectLinks(text, defs) {
548
+ function collectLinks(text, defs, lineBlocks) {
548
549
  const out = [];
549
- const code = codeSpanMask(text);
550
+ const code = codeSpanMask(text, lineBlocks);
550
551
  if (!defs)
551
- defs = collectLinkDefinitions(text);
552
+ defs = collectLinkDefinitions(text, lineBlocks);
552
553
  const cache = Object.create(null);
553
554
  const nextIdx = (c, from) => {
554
555
  const h = cache[c];
@@ -712,50 +713,14 @@ function collectLinks(text, defs) {
712
713
  }
713
714
  // CommonMark fenced code blocks, marked line by line. A "## " or a link inside a fence is
714
715
  // example text and not the file's own structure, but until 2026-09-10 both counted, so a
715
- // file whose only section and only link lived inside ``` or ~~~ was reported valid. The
716
- // scan is one pass over the lines with no backtracking pattern, because the ReDoS repair
717
- // of 2026-08-24 bought a worse accuracy defect with a bounded quantifier and the rule out
718
- // 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.
719
721
  // Returns one boolean per line: true for a fence line and for everything inside it.
720
722
  function fenceMask(lines) {
721
- const mask = new Array(lines.length).fill(false);
722
- let fenceChar = "", fenceLen = 0;
723
- for (let i = 0; i < lines.length; i++) {
724
- const l = lines[i];
725
- let p = 0;
726
- while (p < 4 && l[p] === " ")
727
- p++;
728
- if (p > 3) {
729
- mask[i] = fenceChar !== "";
730
- continue;
731
- }
732
- const c = l[p];
733
- let run = 0;
734
- if (c === "`" || c === "~") {
735
- while (l[p + run] === c)
736
- run++;
737
- }
738
- if (fenceChar === "") {
739
- // An opening backtick fence may not carry a backtick in its info string; a tilde
740
- // fence may. Anything shorter than three markers is not a fence at all. A later
741
- // round will read the consequence as a bug and it is not: in ```js `x` the info
742
- // string holds a backtick, so that line is prose, and a bare ``` after it OPENS a
743
- // block instead of closing one. CommonMark reads the same input the same way,
744
- // measured against the spec 2026-09-10. Leave it.
745
- if (run >= 3 && (c !== "`" || l.indexOf("`", p + run) === -1)) {
746
- fenceChar = c;
747
- fenceLen = run;
748
- mask[i] = true;
749
- }
750
- continue;
751
- }
752
- mask[i] = true;
753
- if (c === fenceChar && run >= fenceLen && l.slice(p + run).trim() === "") {
754
- fenceChar = "";
755
- fenceLen = 0;
756
- }
757
- }
758
- return mask;
723
+ return readBlocks(lines).map((block) => block < 0);
759
724
  }
760
725
  // A markdown list item that carries a link. A bullet or an ordered marker (1. or 1)) followed by
761
726
  // a space or a tab opens the item; an ordered list and a tab after the marker were not read as
@@ -941,8 +906,8 @@ function h2Lines(lines, fenced) {
941
906
  // CommonMark's: an unclosed backtick run, or a pair that crosses a block boundary, is literal text.
942
907
  // A real tag, a closing tag or a comment start in prose still warns, and an autolink is still not
943
908
  // a tag. The package turva-llms-txt-validator mirrors this from 0.5.0.
944
- function blankCodeForHtml(prose) {
945
- const mask = codeSpanMask(prose);
909
+ function blankCodeForHtml(prose, lineBlocks) {
910
+ const mask = codeSpanMask(prose, lineBlocks);
946
911
  const out = [];
947
912
  for (let i = 0; i < prose.length; i++) {
948
913
  const c = prose[i];
@@ -1173,7 +1138,8 @@ export function validateLlmsTxt(f) {
1173
1138
  // listItemHasLink have allowed since 2026-08-29. Until 2026-09-10 this one line still
1174
1139
  // demanded column zero, so a correct file indented by one to three spaces was reported as
1175
1140
  // having no sections at all while its list under the same indentation counted fine.
1176
- const fenced = fenceMask(lines);
1141
+ const lineBlocks = readBlocks(lines);
1142
+ const fenced = lineBlocks.map((block) => block < 0);
1177
1143
  // Computed once for both the section-list scan below and the links check further down, so a
1178
1144
  // reference link definition written anywhere in the prose resolves the same way for each
1179
1145
  // (outside review 2026-09-28, V2): "[text][label]" used to be recognized in the whole-document
@@ -1182,8 +1148,8 @@ export function validateLlmsTxt(f) {
1182
1148
  // joining the survivors let a link's own target span straight across a fenced code block, as
1183
1149
  // if the fence had never separated the two halves.
1184
1150
  const proseText = lines.map((l, i) => (fenced[i] ? "" : l)).join("\n");
1185
- const linkDefs = collectLinkDefinitions(proseText);
1186
- const proseLinks = collectLinks(proseText, linkDefs);
1151
+ const linkDefs = collectLinkDefinitions(proseText, lineBlocks);
1152
+ const proseLinks = collectLinks(proseText, linkDefs, lineBlocks);
1187
1153
  // Which original line each recognized link starts on, so the section scan below can ask "does
1188
1154
  // this line carry a link" against the same whole-document result the links check itself uses,
1189
1155
  // instead of re-finding links one isolated line at a time (outside review 2026-09-28, V2).
@@ -1217,7 +1183,10 @@ export function validateLlmsTxt(f) {
1217
1183
  // Both passed until 2026-09-27 (Tek-496). The first one is named in the detail.
1218
1184
  let sectionsWithList = 0, misplaced = -1;
1219
1185
  {
1220
- 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;
1221
1190
  // Width of the leading white space of a line in columns, a tab running to the next multiple of 4.
1222
1191
  const indentWidth = (s) => { let c = 0; for (const ch of s) {
1223
1192
  if (ch === " ")
@@ -1229,16 +1198,18 @@ export function validateLlmsTxt(f) {
1229
1198
  } return c; };
1230
1199
  for (let i = 0; i < lines.length; i++) {
1231
1200
  const l = lines[i];
1232
- // 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
1233
1202
  // after it is not that item's link. The content column is where the item's text starts, 2 for
1234
1203
  // "- item" and 4 for "- item". A fence indented to that column is inside the item and keeps
1235
1204
  // it open, as in CommonMark, but the line after it then counts only when it is indented to
1236
1205
  // that column too, because a lazy continuation cannot follow a fence.
1237
1206
  if (fenced[i]) {
1238
- if (l.trim() !== "" && indentWidth(l) < itemCol)
1207
+ if (l.trim() !== "" && indentWidth(l) < outerCol)
1239
1208
  itemOpen = false;
1240
- if (itemOpen)
1209
+ if (itemOpen) {
1241
1210
  afterFence = true;
1211
+ itemEmpty = false;
1212
+ }
1242
1213
  continue;
1243
1214
  }
1244
1215
  if (hm.under[i] || sx.under[i])
@@ -1265,15 +1236,17 @@ export function validateLlmsTxt(f) {
1265
1236
  // continuation (CommonMark): the next line counts only when indented to the content column,
1266
1237
  // and a blank line right after the empty marker closes the item.
1267
1238
  if (l.trim() === "") {
1268
- if (itemEmpty)
1269
- itemOpen = false;
1239
+ if (itemEmpty) {
1240
+ if (emptyOuter)
1241
+ itemOpen = false;
1242
+ itemEmpty = false;
1243
+ }
1270
1244
  itemGap = itemOpen;
1271
1245
  continue;
1272
1246
  }
1273
1247
  const fromFence = afterFence;
1274
1248
  afterFence = false;
1275
1249
  if (/^ {0,3}(?:[-*+]|\d{1,9}[.)])(?:[ \t]|$)/.test(l)) {
1276
- itemOpen = true;
1277
1250
  itemGap = false;
1278
1251
  itemEmpty = /^ {0,3}(?:[-*+]|\d{1,9}[.)])[ \t]*$/.test(l);
1279
1252
  {
@@ -1285,8 +1258,13 @@ export function validateLlmsTxt(f) {
1285
1258
  let c = markerEnd;
1286
1259
  for (const ch of mk[3])
1287
1260
  c += ch === "\t" ? 4 - (c % 4) : 1;
1288
- 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
+ }
1289
1266
  }
1267
+ itemOpen = true;
1290
1268
  if (inSection && !counted && listItemHasLink(l, linkedLineIdx.has(i))) {
1291
1269
  sectionsWithList++;
1292
1270
  counted = true;
@@ -1297,7 +1275,7 @@ export function validateLlmsTxt(f) {
1297
1275
  itemOpen = false;
1298
1276
  continue;
1299
1277
  }
1300
- const indented = indentWidth(l) >= itemCol;
1278
+ const indented = indentWidth(l) >= outerCol;
1301
1279
  if (itemOpen && (!itemGap || indented) && (!itemEmpty || indented) && (!fromFence || indented)) {
1302
1280
  if (inSection && !counted && linkedLineIdx.has(i)) {
1303
1281
  sectionsWithList++;
@@ -1373,7 +1351,7 @@ export function validateLlmsTxt(f) {
1373
1351
  // the same text, so the scan stays linear. A tag still open at the end of the file, as in
1374
1352
  // '<div class="x"', has no closing ">" and does not warn. Code is blanked first (Tek-730): a tag-like
1375
1353
  // string inside an inline code span, a fenced block or after a backslash is not markup.
1376
- const htmlScan = blankCodeForHtml(proseText);
1354
+ const htmlScan = blankCodeForHtml(proseText, lineBlocks);
1377
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)) {
1378
1356
  add("no-html", "warn", "No HTML markup in the file", "HTML tags found. llms.txt should be plain markdown");
1379
1357
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turva-llms-txt-validator",
3
- "version": "0.6.0",
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",