turva-llms-txt-validator 0.1.5 → 0.1.7
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 +1 -1
- package/package.json +1 -1
- package/src/index.mjs +6 -2
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ 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
|
|
31
|
+
| 3 | Starts with an H1 title | first non-empty line is not a markdown H1 | |
|
|
32
32
|
| 4 | Blockquote summary after the title | | missing one-line summary |
|
|
33
33
|
| 5 | H2 sections group the content | | no H2 sections |
|
|
34
34
|
| 6 | Markdown links an agent can follow | | no links, or relative links |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "turva-llms-txt-validator",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Validate a site's llms.txt structure: eight checks, pass/warn/fail, 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
|
@@ -41,10 +41,14 @@ export async function fetchLlmsTxt(host, opts = {}) {
|
|
|
41
41
|
const reqApex = host.startsWith("www.") ? host.slice(4) : host;
|
|
42
42
|
let url = "https://" + host + "/llms.txt";
|
|
43
43
|
let redirectedFrom = null;
|
|
44
|
+
// One budget for the whole redirect chain, not one per hop. Mirrors the hosted validator
|
|
45
|
+
// (turva.dev/llms-txt-validator), which is canonical: with five hops a per-hop signal made
|
|
46
|
+
// the caller's timeout five times longer than the value it passed in.
|
|
47
|
+
const deadline = Date.now() + timeoutMs;
|
|
44
48
|
for (let hop = 0; ; hop++) {
|
|
45
49
|
const res = await fetch(url, {
|
|
46
50
|
redirect: "manual",
|
|
47
|
-
signal: AbortSignal.timeout(
|
|
51
|
+
signal: AbortSignal.timeout(Math.max(1, deadline - Date.now())),
|
|
48
52
|
headers: { "user-agent": opts.userAgent ?? UA, "accept": "text/plain, text/markdown;q=0.9, */*;q=0.1" }
|
|
49
53
|
});
|
|
50
54
|
if (res.status >= 300 && res.status < 400) {
|
|
@@ -144,7 +148,7 @@ export function validateLlmsTxt(f) {
|
|
|
144
148
|
} else {
|
|
145
149
|
add("sections", "warn", "H2 sections group the content", "no H2 sections found; sections are the convention for grouping links");
|
|
146
150
|
}
|
|
147
|
-
const links = [...f.text.matchAll(/\[([^\]]*)\]\(([^)\s]+)\)/g)];
|
|
151
|
+
const links = [...f.text.matchAll(/\[([^\][]*)\]\(([^)\s]+)\)/g)];
|
|
148
152
|
const absolute = links.filter((m) => /^https?:\/\//.test(m[2])).length;
|
|
149
153
|
if (links.length === 0) {
|
|
150
154
|
add("links", "warn", "Markdown links an agent can follow", "no markdown links found");
|