turva-llms-txt-validator 0.3.18 → 0.3.20
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 +2 -2
- package/package.json +1 -1
- package/src/index.mjs +83 -2
package/README.md
CHANGED
|
@@ -137,10 +137,10 @@ For vulnerability reporting and supported versions, see [SECURITY.md](https://gi
|
|
|
137
137
|
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.
|
|
138
138
|
|
|
139
139
|
```sh
|
|
140
|
-
mkdir verify-llms && cd verify-llms && npm init -y && npm install turva-llms-txt-validator@0.3.
|
|
140
|
+
mkdir verify-llms && cd verify-llms && npm init -y && npm install turva-llms-txt-validator@0.3.20 --ignore-scripts && npm audit signatures
|
|
141
141
|
```
|
|
142
142
|
|
|
143
|
-
`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.3.
|
|
143
|
+
`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.3.20` must point at that same commit, and `gh api repos/erekola/llms-txt-validator/commits/v0.3.20 --jq .sha` prints it. A mismatch is a reason not to use that version. Provenance proves where a release was built and from which commit. It does not prove that the code is safe, so reading the source and the dependencies stays your job.
|
|
144
144
|
|
|
145
145
|
## Hosted version and source
|
|
146
146
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "turva-llms-txt-validator",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.20",
|
|
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": "./src/index.mjs",
|
package/src/index.mjs
CHANGED
|
@@ -539,6 +539,86 @@ function isSetextH1(line, next) {
|
|
|
539
539
|
return isSetextText(line);
|
|
540
540
|
}
|
|
541
541
|
|
|
542
|
+
// Lines that open a block of their own in CommonMark, so they are never setext text after the
|
|
543
|
+
// title: a thematic break, the start of an HTML block (an autolink such as <https://...> is not
|
|
544
|
+
// one, it stays paragraph text) and a link reference definition. Only the later-H1 reading skips
|
|
545
|
+
// them; the title reading keeps its Tek-560 predicate. QA 2 of Tek-564 measured "---", "<div>" and
|
|
546
|
+
// "[a]: url" over a run of "=" warning as a second H1 although 0.3.18 passed them.
|
|
547
|
+
const HTML_BLOCK_START = /^ {0,3}<(?:[A-Za-z][A-Za-z0-9-]*(?:[\s\/>]|$)|\/[A-Za-z][A-Za-z0-9-]*(?:[\s>]|$)|!--|\?|![A-Za-z]|!\[CDATA\[)/;
|
|
548
|
+
const LINK_REF_DEF = /^ {0,3}\[[^\]]+\]:/;
|
|
549
|
+
// HTML blocks of CommonMark types 1 to 5 end at a marker, not at a blank line: <pre>, <script>,
|
|
550
|
+
// <style> and <textarea> at "</...>", "<!--" at "-->", "<?" at "?>", "<!X" at ">" and "<![CDATA[" at
|
|
551
|
+
// "]]>". Each entry is [start, end]; the end marker is looked for after the start on the same line.
|
|
552
|
+
const RAW_HTML_BLOCKS = [
|
|
553
|
+
[/^ {0,3}<(?:pre|script|style|textarea)(?:[ \t>]|$)/i, /<\/(?:pre|script|style|textarea)>/i],
|
|
554
|
+
[/^ {0,3}<!--/, /-->/],
|
|
555
|
+
[/^ {0,3}<\?/, /\?>/],
|
|
556
|
+
[/^ {0,3}<!\[CDATA\[/, /\]\]>/],
|
|
557
|
+
[/^ {0,3}<![A-Za-z]/, />/]
|
|
558
|
+
];
|
|
559
|
+
function startsOtherBlock(line) {
|
|
560
|
+
return /^ {0,3}([-*_])(?:[ \t]*\1){2,}[ \t]*$/.test(line)
|
|
561
|
+
|| HTML_BLOCK_START.test(line)
|
|
562
|
+
|| LINK_REF_DEF.test(line);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// Setext H1 lines after the title (Tek-564). A second H1 written as one text line over a run of "="
|
|
566
|
+
// is out of place exactly like "# Second title" is, and ends the section before it the same way.
|
|
567
|
+
// The text line is read by isSetextH1, the predicate the first-title reading uses. It must start
|
|
568
|
+
// a paragraph: a line that follows other paragraph text, a list item or a blockquote without a
|
|
569
|
+
// blank line is a continuation line, so a title over several lines is not read as a heading, and
|
|
570
|
+
// text that starts with "#" is not an H1 (isSetextText). The underline is returned separately
|
|
571
|
+
// because it is not a heading and not content.
|
|
572
|
+
// An indented code block is not a paragraph (Tek-565, outside review W46): a line indented four
|
|
573
|
+
// columns or more that does not continue a paragraph is code, so the text after it starts a new
|
|
574
|
+
// paragraph and "Title" over "===" there is a second H1. A four-space line right after paragraph
|
|
575
|
+
// text stays a continuation line (the accepted Tek-564 limit). The exception is a list item: its
|
|
576
|
+
// blank lines and indented lines belong to the item as continuation paragraphs, not as code, so
|
|
577
|
+
// while a list item is open (listCtx) an indented line is read as before. The list context ends at
|
|
578
|
+
// a thematic break or an ATX heading, or at a line with no indent after a blank line. When unsure
|
|
579
|
+
// the function stays in the list context, which is the 0.3.19 reading. A block quote, an HTML block
|
|
580
|
+
// and a link reference definition keep the old reading too, until the next blank line, and an HTML
|
|
581
|
+
// block of type 1 to 5 (<pre>, a comment, <?, <!X, CDATA) until its end marker: an indented line
|
|
582
|
+
// there continues the quote paragraph or the HTML block, or follows a "=" line that is itself
|
|
583
|
+
// paragraph text, and is not code.
|
|
584
|
+
function laterSetextH1(lines, fenced) {
|
|
585
|
+
const text = new Array(lines.length).fill(false);
|
|
586
|
+
const under = new Array(lines.length).fill(false);
|
|
587
|
+
let open = false;
|
|
588
|
+
let listCtx = false;
|
|
589
|
+
let blankBefore = false;
|
|
590
|
+
let quoteCtx = false;
|
|
591
|
+
let htmlCtx = false;
|
|
592
|
+
let rawEnd = null;
|
|
593
|
+
let rawDone = false;
|
|
594
|
+
for (let i = 0; i < lines.length; i++) {
|
|
595
|
+
const l = lines[i];
|
|
596
|
+
if (rawDone) { htmlCtx = false; rawDone = false; }
|
|
597
|
+
if (fenced[i]) { open = false; continue; }
|
|
598
|
+
if (l.trim() === "") { open = false; blankBefore = true; quoteCtx = false; if (!rawEnd) htmlCtx = false; continue; }
|
|
599
|
+
const indented = /^(?: {4}| {0,3}\t)/.test(l);
|
|
600
|
+
if (/^ ?#{1,6}(?:[ \t]|$)/.test(l) || /^ ?([-*_])(?:[ \t]*\1){2,}[ \t]*$/.test(l)) listCtx = false;
|
|
601
|
+
else if (/^ {0,3}(?:[-*+]|\d{1,9}[.)])(?:[ \t]|$)/.test(l)) listCtx = true;
|
|
602
|
+
else if (blankBefore && /^ ?[^ \t]/.test(l)) listCtx = false;
|
|
603
|
+
blankBefore = false;
|
|
604
|
+
if (/^ {0,3}>/.test(l)) quoteCtx = true;
|
|
605
|
+
if (rawEnd) {
|
|
606
|
+
if (rawEnd.test(l)) { rawEnd = null; rawDone = true; }
|
|
607
|
+
} else {
|
|
608
|
+
if (HTML_BLOCK_START.test(l) || LINK_REF_DEF.test(l)) htmlCtx = true;
|
|
609
|
+
for (const [start, end] of RAW_HTML_BLOCKS) {
|
|
610
|
+
const m = start.exec(l);
|
|
611
|
+
if (m) { if (!end.test(l.slice(m[0].length))) rawEnd = end; break; }
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
if (!open && !listCtx && !quoteCtx && !htmlCtx && indented) continue;
|
|
615
|
+
if (!open && !fenced[i + 1] && !startsOtherBlock(l) && isSetextH1(l, lines[i + 1])) { text[i] = true; under[i + 1] = true; i++; continue; }
|
|
616
|
+
if (open && /^ {0,3}=+[ \t]*$/.test(l)) { open = false; continue; }
|
|
617
|
+
open = !(/^ {0,3}#{1,6}(?:[ \t]|$)/.test(l) || /^ {0,3}(?:-+|([-*_])(?: *\1){2,})[ \t]*$/.test(l));
|
|
618
|
+
}
|
|
619
|
+
return { text, under };
|
|
620
|
+
}
|
|
621
|
+
|
|
542
622
|
// Which lines are H2 headings, outside fences. One reader for every place that asks "is this an
|
|
543
623
|
// H2": the section count, the section membership and the place where the late-summary scan stops.
|
|
544
624
|
// An ATX H2 is "##" followed by a space or a tab (a bare "##" is not one, and "###" is deeper). A
|
|
@@ -735,6 +815,7 @@ export function validateLlmsTxt(f) {
|
|
|
735
815
|
}
|
|
736
816
|
}
|
|
737
817
|
const hm = h2Lines(lines, fenced);
|
|
818
|
+
const sx = laterSetextH1(lines, fenced);
|
|
738
819
|
const h2Count = hm.h2.filter(Boolean).length;
|
|
739
820
|
// A section counts when it carries a file list. An H2 followed by a paragraph satisfied
|
|
740
821
|
// this check until 2026-08-29, and the format puts each section's links in a list.
|
|
@@ -758,9 +839,9 @@ export function validateLlmsTxt(f) {
|
|
|
758
839
|
if (itemOpen) afterFence = true;
|
|
759
840
|
continue;
|
|
760
841
|
}
|
|
761
|
-
if (hm.under[i]) continue;
|
|
842
|
+
if (hm.under[i] || sx.under[i]) continue;
|
|
762
843
|
if (hm.h2[i]) { inSection = true; counted = false; seenH2 = true; itemOpen = false; continue; }
|
|
763
|
-
const h1 = /^ {0,3}#(?:[ \t]|$)/.test(l);
|
|
844
|
+
const h1 = /^ {0,3}#(?:[ \t]|$)/.test(l) || sx.text[i];
|
|
764
845
|
if (misplaced === -1 && i > firstIdx && (h1 || (!seenH2 && /^ {0,3}#{3,6}(?:[ \t]|$)/.test(l)))) misplaced = i;
|
|
765
846
|
if (h1) { inSection = false; itemOpen = false; continue; }
|
|
766
847
|
// A link on a line that continues an open list item counts as that item's link (Tek-560):
|