turva-llms-txt-validator 0.2.1 → 0.3.0
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 +5 -5
- package/package.json +1 -1
- package/src/index.mjs +49 -17
package/README.md
CHANGED
|
@@ -28,10 +28,10 @@ The target has to be a public domain name: an IP literal, a bracketed IPv6 addre
|
|
|
28
28
|
|---|-------|------|------|
|
|
29
29
|
| 1 | File exists at /llms.txt, HTTP 200 (a same-site www/apex redirect is followed) | non-200, or an off-site or unsafe redirect | |
|
|
30
30
|
| 2 | Response is plain text | body looks like HTML | content-type is not text/plain or text/markdown |
|
|
31
|
-
| 3 | Starts with an H1 title | first non-empty line is not a markdown H1 | |
|
|
31
|
+
| 3 | Starts with an H1 title | first non-empty line is not a markdown H1, indentation included, since four spaces make it a code block | |
|
|
32
32
|
| 4 | Blockquote summary after the title | | missing one-line summary |
|
|
33
|
-
| 5 | H2 sections group the content | | no H2 sections |
|
|
34
|
-
| 6 | Markdown links an agent can follow | | no links, or relative links |
|
|
33
|
+
| 5 | H2 sections group the content | | no H2 sections, or no section carrying a markdown file list |
|
|
34
|
+
| 6 | Markdown links an agent can follow | | no links, an empty link name, a scheme without a host, or relative links |
|
|
35
35
|
| 7 | Small enough to be cheap to read | | over 50 KB, or read truncated at 256 KB |
|
|
36
36
|
| 8 | No HTML markup in the file | | HTML tags found |
|
|
37
37
|
|
|
@@ -39,8 +39,8 @@ Two more checks read the site's home page for the link relations v2 of the forma
|
|
|
39
39
|
|
|
40
40
|
| # | Check | pass | info |
|
|
41
41
|
|---|-------|------|------|
|
|
42
|
-
| 9 | Home page points to its llms.txt (v2) | `rel="describedby"` found in the head or the Link header | not found, or the home page could not be read |
|
|
43
|
-
| 10 | Home page points to a markdown version (v2) | `rel="alternate" type
|
|
42
|
+
| 9 | Home page points to its llms.txt (v2) | `rel="describedby"` with a target, found in the head or the Link header | not found, no target on the relation, or the home page could not be read |
|
|
43
|
+
| 10 | Home page points to a markdown version (v2) | `rel="alternate"` with the media type `text/markdown` and a target, found in the head or the Link header | not found, no target on the relation, a different media type, or the home page could not be read |
|
|
44
44
|
|
|
45
45
|
## Node API
|
|
46
46
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "turva-llms-txt-validator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Validate a site's llms.txt structure: eight checks as pass/warn/fail plus two llms.txt v2 discovery checks as information, 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
|
@@ -135,8 +135,12 @@ export function validateLlmsTxt(f) {
|
|
|
135
135
|
}
|
|
136
136
|
const lines = f.text.split(/\r?\n/);
|
|
137
137
|
const firstIdx = lines.findIndex((l) => l.trim() !== "");
|
|
138
|
-
const
|
|
139
|
-
|
|
138
|
+
const firstRaw = firstIdx === -1 ? "" : lines[firstIdx];
|
|
139
|
+
const first = firstRaw.trim();
|
|
140
|
+
// The line is read as markdown and not trimmed first. Four spaces or a tab make it an
|
|
141
|
+
// indented code block rather than a heading, and trimming erased that difference, so
|
|
142
|
+
// " # Site" passed as the H1 until 2026-08-29. CommonMark allows three spaces.
|
|
143
|
+
if (/^ {0,3}# \S/.test(firstRaw)) {
|
|
140
144
|
add("h1-title", "pass", "Starts with an H1 title", JSON.stringify(first.slice(0, 80)));
|
|
141
145
|
} else {
|
|
142
146
|
add("h1-title", "fail", "Starts with an H1 title", "the first non-empty line should be a markdown H1 (# Site name)");
|
|
@@ -148,19 +152,40 @@ export function validateLlmsTxt(f) {
|
|
|
148
152
|
add("summary", "warn", "Blockquote summary after the title", "recommended by the format (> one-line summary), not required");
|
|
149
153
|
}
|
|
150
154
|
const h2Count = (f.text.match(/^## /gm) || []).length;
|
|
151
|
-
|
|
152
|
-
|
|
155
|
+
// A section counts when it carries a file list. An H2 followed by a paragraph satisfied
|
|
156
|
+
// this check until 2026-08-29, and the format puts each section's links in a list.
|
|
157
|
+
let sectionsWithList = 0;
|
|
158
|
+
{
|
|
159
|
+
let inSection = false, counted = false;
|
|
160
|
+
for (const l of lines) {
|
|
161
|
+
if (/^## /.test(l)) { inSection = true; counted = false; continue; }
|
|
162
|
+
if (/^# /.test(l)) { inSection = false; continue; }
|
|
163
|
+
if (inSection && !counted && /^ {0,3}[-*+] .*\[[^\][]*\]\([^)\s]+\)/.test(l)) { sectionsWithList++; counted = true; }
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (h2Count > 0 && sectionsWithList > 0) {
|
|
167
|
+
add("sections", "pass", "H2 sections group the content", h2Count + " section" + (h2Count === 1 ? "" : "s") + ", " + sectionsWithList + " carrying a file list");
|
|
168
|
+
} else if (h2Count > 0) {
|
|
169
|
+
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");
|
|
153
170
|
} else {
|
|
154
171
|
add("sections", "warn", "H2 sections group the content", "no H2 sections found; sections are the convention for grouping links");
|
|
155
172
|
}
|
|
156
173
|
const links = [...f.text.matchAll(/\[([^\][]*)\]\(([^)\s]{1,2048})\)/g)];
|
|
157
|
-
|
|
174
|
+
// An entry an agent can use has a name and a target with a host. An empty name and a
|
|
175
|
+
// bare "https://" both counted as valid absolute links until 2026-08-29.
|
|
176
|
+
const named = links.filter((m) => m[1].trim() !== "");
|
|
177
|
+
const unnamed = links.length - named.length;
|
|
178
|
+
const absolute = named.filter((m) => /^https?:\/\/[^/\s?#]+/.test(m[2])).length;
|
|
158
179
|
if (links.length === 0) {
|
|
159
180
|
add("links", "warn", "Markdown links an agent can follow", "no markdown links found");
|
|
160
|
-
} else if (
|
|
161
|
-
add("links", "
|
|
181
|
+
} else if (unnamed > 0) {
|
|
182
|
+
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");
|
|
183
|
+
} else if (absolute === named.length) {
|
|
184
|
+
add("links", "pass", "Markdown links an agent can follow", named.length + " link" + (named.length === 1 ? "" : "s") + ", all absolute URLs");
|
|
162
185
|
} else {
|
|
163
|
-
|
|
186
|
+
const relativeCount = named.filter((m) => !/^[a-z][a-z0-9+.-]*:/i.test(m[2])).length;
|
|
187
|
+
const hostless = named.length - absolute - relativeCount;
|
|
188
|
+
add("links", "warn", "Markdown links an agent can follow", named.length + " links, " + relativeCount + " relative" + (hostless > 0 ? " and " + hostless + " with a scheme but no host" : "") + "; absolute URLs travel better when the file is read out of context");
|
|
164
189
|
}
|
|
165
190
|
if (f.truncated) {
|
|
166
191
|
add("size", "warn", "Small enough to be cheap to read", "over 256 KB, read truncated");
|
|
@@ -414,20 +439,27 @@ export function findLinkRelations(html, linkHeader) {
|
|
|
414
439
|
// NAME is "link<link", not as a link element, so \b would count a relation the site
|
|
415
440
|
// does not publish. Measured against parse5, 2026-08-24.
|
|
416
441
|
if (!/^<link(?=[\s/>])/i.test(tag)) continue;
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
442
|
+
// The attribute name has to start the token. \b sits between the hyphen and the name,
|
|
443
|
+
// so data-rel, data-type and data-href were read as the real attributes until
|
|
444
|
+
// 2026-08-29, and a page could claim a relation it does not publish.
|
|
445
|
+
const rel = ((tag.match(/(?:^|[\s/])rel\s*=\s*["']?([^"'>]+)/i) || [])[1] || "").toLowerCase().trim().split(/\s+/);
|
|
446
|
+
const type = ((tag.match(/(?:^|[\s/])type\s*=\s*["']?([^"'>\s]+)/i) || [])[1] || "").toLowerCase();
|
|
447
|
+
const href = ((tag.match(/(?:^|[\s/])href\s*=\s*"([^"]*)"|(?:^|[\s/])href\s*=\s*'([^']*)'|(?:^|[\s/])href\s*=\s*([^\s"'>]+)/i) || []).slice(1).find((x) => x !== undefined) || "").trim();
|
|
448
|
+
// text/markdown, not anything that starts with it, and a relation without a target is
|
|
449
|
+
// not a relation: both passed until 2026-08-29.
|
|
450
|
+
const isMarkdown = type.split(";")[0].trim() === "text/markdown";
|
|
451
|
+
if (!found.describedby && href && rel.includes("describedby")) found.describedby = href;
|
|
452
|
+
if (!found.markdown && href && rel.includes("alternate") && isMarkdown) found.markdown = href;
|
|
422
453
|
}
|
|
423
454
|
for (const part of String(linkHeader || "").split(/,(?=\s*<)/)) {
|
|
424
455
|
const lt = part.indexOf("<");
|
|
425
456
|
const gt = lt === -1 ? -1 : part.indexOf(">", lt + 1);
|
|
426
457
|
const href = (gt === -1 ? "" : part.slice(lt + 1, gt)).trim();
|
|
427
|
-
const rel = ((part.match(/rel\s*=\s*"?([^";,]+)"?/i) || [])[1] || "").toLowerCase().trim().split(/\s+/);
|
|
428
|
-
const type = ((part.match(/type\s*=\s*"?([^";,]+)"?/i) || [])[1] || "").toLowerCase().trim();
|
|
429
|
-
|
|
430
|
-
if (!found.
|
|
458
|
+
const rel = ((part.match(/(?:^|[;\s])rel\s*=\s*"?([^";,]+)"?/i) || [])[1] || "").toLowerCase().trim().split(/\s+/);
|
|
459
|
+
const type = ((part.match(/(?:^|[;\s])type\s*=\s*"?([^";,]+)"?/i) || [])[1] || "").toLowerCase().trim();
|
|
460
|
+
const isMarkdownHeader = type.split(";")[0].trim() === "text/markdown";
|
|
461
|
+
if (!found.describedby && href && rel.includes("describedby")) found.describedby = href;
|
|
462
|
+
if (!found.markdown && href && rel.includes("alternate") && isMarkdownHeader) found.markdown = href;
|
|
431
463
|
}
|
|
432
464
|
return found;
|
|
433
465
|
}
|