turva-llms-txt-validator 0.1.4 → 0.1.6

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
@@ -1,6 +1,6 @@
1
1
  # turva-llms-txt-validator
2
2
 
3
- Validate a site's llms.txt structure from the command line, from Node, or in CI. Eight checks, each reported as pass, warn or fail, with a one-line detail. No score on purpose: a structure check can say what is there and what is missing, and a number on top of eight checks would look like an agent-readiness score without measuring one.
3
+ Validate a site's llms.txt structure from the command line, from Node or in CI. Eight checks, each reported as pass, warn or fail, with a one-line detail. No score on purpose: a structure check can say what is there and what is missing, and a number on top of eight checks would look like an agent-readiness score without measuring one.
4
4
 
5
5
  This is the open-source form of the hosted validator at [turva.dev/llms-txt-validator](https://turva.dev/llms-txt-validator), which runs the same logic inside the open [turva.dev Cloudflare Worker](https://github.com/erekola/turva-worker). The hosted validator stays canonical: if the two ever disagree, the hosted one wins and this package gets the fix.
6
6
 
@@ -20,13 +20,15 @@ Or run it without installing:
20
20
 
21
21
  Exit codes: 0 valid (warnings allowed), 1 not valid (with --strict, warnings also exit 1), 2 fetch or input error. Only the target site's /llms.txt is fetched over https, following a redirect only to the same host or its www/apex twin (an off-site or unsafe redirect fails the first check), the fetch times out after 8 seconds and the read is capped at 256 KB. Nothing is stored.
22
22
 
23
+ The target has to be a public domain name: an IP literal, a bracketed IPv6 address, localhost and the internal-use TLDs local, internal, home, lan, corp, test and invalid are all refused before any request goes out, and every redirect hop is checked by the same rule. Names are not resolved here, so a public name that points at a private address is stopped by the network the fetch runs on rather than by this code. On the hosted validator that network is the Cloudflare edge, which does not route to private address space.
24
+
23
25
  ## The eight checks
24
26
 
25
27
  | # | Check | fail | warn |
26
28
  |---|-------|------|------|
27
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 | |
28
30
  | 2 | Response is plain text | body looks like HTML | content-type is not text/plain or text/markdown |
29
- | 3 | Starts with a single 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 | |
30
32
  | 4 | Blockquote summary after the title | | missing one-line summary |
31
33
  | 5 | H2 sections group the content | | no H2 sections |
32
34
  | 6 | Markdown links an agent can follow | | no links, or relative links |
@@ -56,8 +58,8 @@ Woodpecker or any other runner: the same npx line works anywhere Node 18.17 or n
56
58
 
57
59
  ## Why these checks
58
60
 
59
- The llms.txt format is a plain text map of a site for AI agents: an H1 title, a one-line blockquote summary, and H2 sections of markdown links. The checks test exactly that structure and nothing else. What the format is and why it matters is written out at [llms.txt explained](https://turva.dev/guides/llms-txt), and the free tools this package belongs to are collected at [turva.dev/tools](https://turva.dev/tools).
61
+ The llms.txt format is a plain text map of a site for AI agents: an H1 title, a one-line blockquote summary and H2 sections of markdown links. The checks test exactly that structure and nothing else. What the format is and why it matters is written out at [llms.txt explained](https://turva.dev/guides/llms-txt), and the free tools this package belongs to are collected at [turva.dev/tools](https://turva.dev/tools).
60
62
 
61
63
  ## License
62
64
 
63
- MIT. Source at [github.com/erekola/llms-txt-validator](https://github.com/erekola/llms-txt-validator), mirrored at [codeberg.org/erekola/llms-txt-validator](https://codeberg.org/erekola/llms-txt-validator). Published to npm from GitHub Actions with provenance, a signed attestation of where and how the package was built, verifiable on the npm package page.
65
+ MIT. Source at [github.com/erekola/llms-txt-validator](https://github.com/erekola/llms-txt-validator). Published to npm from GitHub Actions with provenance, a signed attestation of where and how the package was built, verifiable on the npm package page.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turva-llms-txt-validator",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
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(timeoutMs),
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) {