turva-llms-txt-validator 0.8.6 → 0.9.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
@@ -107,11 +107,13 @@ In an error report the `target` is the address given on the command line. When i
107
107
  | 2 | Response is plain text | Body looks like an HTML page | The media type, read without its parameters, with only spaces, tabs and line breaks removed from its ends and only ASCII letters lowercased, is neither `text/plain` nor `text/markdown` |
108
108
  | 3 | First non-empty line is a Markdown H1, written `# Title` or as one line of text underlined with `=` | Missing H1, a title indented as a code block, or an H1 with no text, whether written with `#` or underlined with `=` | none |
109
109
  | 4 | Blockquote summary follows the title | none | Missing summary, a blockquote block in which no line has text after the `>`, or a blockquote after other text but before the first H2, named by its line |
110
- | 5 | H2 sections group the content | none | No H2 sections, no section with a Markdown link list, a heading between the title and the first H2, or a second H1 |
111
- | 6 | Markdown links have names and absolute HTTP or HTTPS targets | none | Missing links, empty names, relative targets or targets that do not parse as HTTP or HTTPS URLs, or a list line under an H2 of one of two kinds. The first kind looks like a link entry but is not a Markdown link, such as an unclosed destination in `- [Name](https://example.com/a.md: notes)`. The second kind opens with an en dash, an em dash or a bullet instead of a list marker, followed by a space or a tab and an opening bracket, whether or not its link parses. A line with such a character and no opening bracket is not counted, and a no-break space does not count as the space. When the read was truncated, the last line read is not counted, because the read limit may have cut it. The detail has one sentence per kind, each with its count and the first five line numbers |
110
+ | 5 | H2 sections group the content | none | No H2 sections, no section with a Markdown link list, or a second H1. An H3 or deeper heading in the top section, before the first H2, is allowed |
111
+ | 6 | Markdown links have names and HTTP or HTTPS targets, absolute or relative | none | Missing links, empty names, a `Base URL:` line in the top section whose value is not an absolute HTTP or HTTPS URL, targets with a scheme that do not parse as HTTP or HTTPS URLs, or a list line under an H2 of one of two kinds. The first kind looks like a link entry but is not a Markdown link, such as an unclosed destination in `- [Name](https://example.com/a.md: notes)`. The second kind opens with an en dash, an em dash or a bullet instead of a list marker, followed by a space or a tab and an opening bracket, whether or not its link parses. A line with such a character and no opening bracket is not counted, and a no-break space does not count as the space. When the read was truncated, the last line read is not counted, because the read limit may have cut it. The detail has one sentence per kind, each with its count and the first five line numbers |
112
112
  | 7 | File is small enough to read cheaply | none | Over 50 KiB, which is 51,200 bytes, or truncated at the 256 KiB read limit |
113
113
  | 8 | File contains no HTML markup | none | An opening tag with its closing `>`, a closing tag or an HTML comment is found in the prose. Inline code spans, fenced code and backslash-escaped angle brackets such as `\<node-name\>` are not read, so `<endpoint-id>` in a code span does not warn. An attribute name is any run of characters other than white space, quotes, `<`, `>`, `/` and `=` that holds a Unicode letter, a Unicode digit or the character `_`, so `<div @click="x">` warns. Autolinks such as `<https://example.com>` and prose such as `a <b + c` are not tags. A tag still open at the end of the file, such as `<div class="x"`, has no closing `>` and does not warn |
114
114
 
115
+ Since 0.9.0 the checks follow llms.txt v2.1. A relative link in a file list passes. An optional standalone `Base URL: https://example.com/` line in the top section, before the first H2, names the address that relative links resolve against. Without that line they resolve against the address the file was fetched from, so the links check passes and its detail says that they break when the file is read from disk or a mirror. A `Base URL:` line whose value is not an absolute HTTP or HTTPS URL is a warning that names its line. A section may open with a summary paragraph before its file list, and a section named `Optional` is read like any other.
116
+
115
117
  Some failures stop the file checks early. For example, an HTML response is reported as a failed plain-text check rather than parsed as Markdown. The response bytes are always decoded as UTF-8, and the `charset` parameter of the media type is not used.
116
118
 
117
119
  ### How links, headings and list items are read
@@ -133,7 +135,7 @@ Links are read the way CommonMark reads them for the forms listed here.
133
135
  - In this validator a raw HTML block is one of types 1 to 7 of CommonMark, and it is read only where its start is certain. The opener must be on the first line, after a blank line, or after a heading that itself stood at such a place. It must be indented at most three columns and stand outside every open list item. Under a paragraph line, a quote line, a list item line or another HTML line the opener hides nothing, and the lines after it keep their ordinary reading. The lines of a block hold no links, definitions, list items or headings for the checks. A `## Docs` line inside such a block is part of the block and no H2 section. Examples are the line between `<?x` and `?>` and the line directly under a `<div>` that stands after a blank line, with no blank line between them. Until 0.8.0 such a line counted as a section. The no-HTML check still reads them. A fence opener inside an HTML block is still read as a fence.
134
136
  - A title (written with `#` or underlined with `=`), a link name or a summary whose text is only character references to white space, code spans of white space or empty quote markers counts as empty: `# &#32;`, `` [` `](https://example.org/a) ``, `>>` and `> >`. A line with only a no-break or ideographic space is not a blank line.
135
137
  - A quote escaped with a backslash inside a link title, as in `[A](https://example.org/a "Ti\"tle\"")`, is not recognised, so that link is dropped. A title that spans a line break is dropped the same way.
136
- - Nested brackets in a link label, as in `[A [x] B](https://example.org/a)`, drop the link. A link label cannot span a blank line.
138
+ - A link text may hold a balanced pair of brackets or a backslash-escaped bracket, as in `[A [x] B](https://example.org/a)`. A link text that holds a complete link of its own is not a link, so only the inner link counts, and the line still draws the look-alike warning. An opening bracket that is never closed, as in `[A [x](https://example.org/a)`, leaves only the inner link, and that line draws the warning too. A link text cannot span a blank line.
137
139
  - A backslash escape in a target is resolved before the URL test, so `https\://example.org/guide` is read as `https://example.org/guide`.
138
140
  - CR and CRLF line endings are read as LF. A setext title, which is a text line underlined with `=`, is read only when it is a single line.
139
141
 
@@ -253,12 +255,12 @@ The strict type check found two inputs that could leave `undefined` in a check's
253
255
  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.
254
256
 
255
257
  ```sh
256
- mkdir verify-llms && cd verify-llms && npm init -y && npm install turva-llms-txt-validator@0.8.6 --ignore-scripts && npm audit signatures
258
+ mkdir verify-llms && cd verify-llms && npm init -y && npm install turva-llms-txt-validator@0.9.1 --ignore-scripts && npm audit signatures
257
259
  ```
258
260
 
259
261
  `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, the workflow file `.github/workflows/publish.yml` and the commit that produced the tarball. Versions up to and including 0.8.4 were built in `github.com/erekola/llms-txt-validator`, before the repository moved to the turva-dev organization on 2026-11-25. Every later release is built in `github.com/turva-dev/llms-txt-validator`. The npm version page shows them under Provenance.
260
262
 
261
- Tag `v0.8.6` must point at that same commit, and `gh api repos/turva-dev/llms-txt-validator/commits/v0.8.6 --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.
263
+ Tag `v0.9.1` must point at that same commit, and `gh api repos/turva-dev/llms-txt-validator/commits/v0.9.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.
262
264
 
263
265
  ## Development
264
266
 
package/dist/src/index.js CHANGED
@@ -993,7 +993,8 @@ function collectLinkDefinitions(text, lineBlocks, defAt) {
993
993
  // nor break one (S3, LV-05). A target may be written in angle brackets and may carry a title in quotes, as CommonMark allows;
994
994
  // a plain target keeps balanced parentheses ("a_(b)") and an unbalanced one is no link (S3, WL-12); an empty target is a link
995
995
  // with an empty target (S3, LV-07). An image nested in the link text, such as "[a ![i](x)](y)", is link content and is skipped
996
- // whole, and the alt text of an image holds no link (S3, LV-08). Any other nested "[" still ends the scan, because CommonMark
996
+ // whole, and the alt text of an image holds no link (S3, LV-08). The text of a link may hold balanced brackets and escaped ones, and it ends at the "]" that
997
+ // closeOf paired with its "[", but a link whose text holds another link is no link, because CommonMark
997
998
  // does not allow a link inside a link. A label ends at the paragraph, which the block numbers of the reader say (S3, LV-06). A
998
999
  // full or collapsed reference link, "[text][label]" or "[text][]", resolves against collectLinkDefinitions; an unresolved label
999
1000
  // is read as plain brackets, and so is a shortcut reference "[text]" after an inline attempt that did not parse (S3, LV-11). A
@@ -1159,15 +1160,6 @@ function collectLinks(text, defs, lineBlocks) {
1159
1160
  return { target: text.slice(k, e), end: e };
1160
1161
  return e < text.length ? afterTarget(text.slice(k, e), e) : null;
1161
1162
  };
1162
- // The text of a link label from j on, up to the "]" or "[" that ends it or the line break that ends the paragraph. A bracket
1163
- // inside a code span is code and neither closes nor opens. A backslash before a line break is a hard
1164
- // line break and escapes nothing, so the break still ends the paragraph it ends (CommonMark); the label scan and closeOf
1165
- // below used to step over it, and a link label then ran on into the next list item or heading.
1166
- const scanLabel = (j) => {
1167
- while (j < text.length && (code[j] || (text[j] !== "]" && text[j] !== "[" && !blankAt(j))))
1168
- j += !code[j] && text[j] === "\\" && text[j + 1] !== "\n" ? 2 : 1;
1169
- return j;
1170
- };
1171
1163
  // A definition is decoded once, however many references use it: a long destination used by many labels would otherwise be
1172
1164
  // decoded again for each of them.
1173
1165
  const decoded = new Map();
@@ -1253,43 +1245,20 @@ function collectLinks(text, defs, lineBlocks) {
1253
1245
  }
1254
1246
  return i - lineStart <= 64 && DEF_HEAD.test(text.slice(lineStart, i));
1255
1247
  };
1256
- for (let i = 0; i < text.length; i++) {
1257
- if (text[i] !== "[" || code[i] || isEscaped(text, i))
1258
- continue;
1259
- if (i > 0 && text[i - 1] === "!" && !isEscaped(text, i - 1)) {
1260
- const after = skipImage(i);
1261
- if (after !== null)
1262
- i = after - 1;
1263
- continue;
1264
- }
1265
- let j = i + 1;
1266
- for (;;) {
1267
- j = scanLabel(j);
1268
- if (j >= text.length || text[j] !== "[")
1269
- break;
1270
- if (code[j] || text[j - 1] !== "!" || isEscaped(text, j - 1))
1271
- break;
1272
- const after = skipImage(j);
1273
- if (after === null)
1274
- break;
1275
- j = after;
1276
- }
1277
- if (j >= text.length)
1278
- break;
1279
- if (text[j] === "\n") {
1280
- i = j;
1281
- continue;
1282
- }
1283
- if (text[j] === "[") {
1284
- i = j - 1;
1285
- continue;
1286
- }
1248
+ // The brackets that closeOf paired and whose "]" has not been reached yet, innermost last. The text of a link may hold
1249
+ // balanced brackets ("[rewrite Optional[T] to T](x)") and backslash-escaped ones, so a label ends at the "]" that closeOf
1250
+ // paired with its "[", and the link is read there, once everything inside has been read. child records that another "[" opened
1251
+ // inside, which keeps a shortcut or collapsed reference from taking a label with brackets in it. Links do not nest: when a
1252
+ // link was found inside the text, the outer one is not a link and its "]" is plain text (CommonMark 0.31.2, section 6.3).
1253
+ const pending = [];
1254
+ // Reads what follows the "]" at j of the link text opened at i: an inline target, a full or collapsed reference, or a
1255
+ // shortcut reference. Returns the index the scan resumes from, or j when no link starts at i.
1256
+ const closeLink = (i, j, plain) => {
1287
1257
  if (text[j + 1] === "(") {
1288
1258
  const t = readTarget(j + 2);
1289
1259
  if (t) {
1290
1260
  out.push({ name: text.slice(i + 1, j), target: decodeDestination(t.target), at: i });
1291
- i = t.end;
1292
- continue;
1261
+ return t.end;
1293
1262
  }
1294
1263
  // A target that does not parse leaves "[text]" to be read as a shortcut reference below (S3, LV-11).
1295
1264
  }
@@ -1299,16 +1268,17 @@ function collectLinks(text, defs, lineBlocks) {
1299
1268
  m += text[m] === "\\" ? 2 : 1;
1300
1269
  if (m < text.length && text[m] === "]") {
1301
1270
  const rawLabel = text.slice(j + 2, m);
1302
- const label = normalizeLinkLabel(rawLabel === "" ? text.slice(i + 1, j) : rawLabel);
1303
- const dest = label ? refs.get(label) : undefined;
1304
- if (dest !== undefined) {
1305
- out.push({ name: text.slice(i + 1, j), target: decodeRef(label, dest), at: i });
1306
- i = m;
1307
- continue;
1271
+ if (rawLabel !== "" || plain) {
1272
+ const label = normalizeLinkLabel(rawLabel === "" ? text.slice(i + 1, j) : rawLabel);
1273
+ const dest = label ? refs.get(label) : undefined;
1274
+ if (dest !== undefined) {
1275
+ out.push({ name: text.slice(i + 1, j), target: decodeRef(label, dest), at: i });
1276
+ return m;
1277
+ }
1308
1278
  }
1309
1279
  }
1310
1280
  }
1311
- else {
1281
+ else if (plain) {
1312
1282
  // A shortcut reference, "[text]" alone with neither "(" nor "[" right after it, resolves
1313
1283
  // against a definition using the link text itself as the label (VN2, round 3 Tek-542).
1314
1284
  // Checked last, and only here, so it never overrides the full or collapsed reference
@@ -1318,11 +1288,35 @@ function collectLinks(text, defs, lineBlocks) {
1318
1288
  const dest = label ? refs.get(label) : undefined;
1319
1289
  if (dest !== undefined) {
1320
1290
  out.push({ name: text.slice(i + 1, j), target: decodeRef(label, dest), at: i });
1321
- i = j;
1322
- continue;
1291
+ return j;
1323
1292
  }
1324
1293
  }
1325
- i = j;
1294
+ return j;
1295
+ };
1296
+ for (let i = 0; i < text.length; i++) {
1297
+ while (pending.length > 0 && pending[pending.length - 1].close < i)
1298
+ pending.pop();
1299
+ if (pending.length > 0 && pending[pending.length - 1].close === i) {
1300
+ const p = pending.pop();
1301
+ // Nothing found inside the text: the outer bracket pair may be a link.
1302
+ if (out.length === p.outLen)
1303
+ i = closeLink(p.open, i, !p.child);
1304
+ continue;
1305
+ }
1306
+ if (text[i] !== "[" || code[i] || isEscaped(text, i))
1307
+ continue;
1308
+ if (pending.length > 0)
1309
+ pending[pending.length - 1].child = true;
1310
+ if (i > 0 && text[i - 1] === "!" && !isEscaped(text, i - 1)) {
1311
+ const after = skipImage(i);
1312
+ if (after !== null)
1313
+ i = after - 1;
1314
+ continue;
1315
+ }
1316
+ const c = closeOf()[i];
1317
+ if (c >= 0) {
1318
+ pending.push({ open: i, close: c, outLen: out.length, child: false });
1319
+ }
1326
1320
  }
1327
1321
  return out;
1328
1322
  }
@@ -2019,9 +2013,9 @@ export function validateLlmsTxt(f) {
2019
2013
  const h2Count = hm.h2.filter(Boolean).length;
2020
2014
  // A section counts when it carries a file list. An H2 followed by a paragraph satisfied
2021
2015
  // this check until 2026-08-29, and the format puts each section's links in a list.
2022
- // A heading between the title and the first H2, or a second H1 anywhere, is out of place,
2023
- // because the format has one H1 and allows only paragraphs and lists before the file lists.
2024
- // Both passed until 2026-09-27 (Tek-496). The first one is named in the detail.
2016
+ // A second H1 anywhere is out of place, because the format has one H1. Since llms.txt v2.1
2017
+ // (decision P1, 2026-11-30) an H3 or deeper heading in the top section, before the first H2, is allowed,
2018
+ // so only an H1 is named. A second H1 passed until 2026-09-27 (Tek-496).
2025
2019
  let sectionsWithList = 0, misplaced = -1;
2026
2020
  {
2027
2021
  let inSection = false, counted = false, seenH2 = false, itemOpen = false, itemGap = false, itemEmpty = false, emptyOuter = false, afterFence = false;
@@ -2065,7 +2059,7 @@ export function validateLlmsTxt(f) {
2065
2059
  // A line inside a raw HTML block is no heading for these checks either (h2Mask also holds the fenced lines,
2066
2060
  // which were skipped above, so here it only adds the HTML block lines).
2067
2061
  const h1 = !h2Mask[i] && (/^ {0,3}#(?:[ \t]|$)/.test(l) || sx.text[i]);
2068
- if (misplaced === -1 && i > firstIdx && (h1 || (!seenH2 && !h2Mask[i] && /^ {0,3}#{3,6}(?:[ \t]|$)/.test(l))))
2062
+ if (misplaced === -1 && i > firstIdx && h1)
2069
2063
  misplaced = i;
2070
2064
  if (h1) {
2071
2065
  inSection = false;
@@ -2146,7 +2140,7 @@ export function validateLlmsTxt(f) {
2146
2140
  if (misplaced !== -1) {
2147
2141
  const s = checks[checks.length - 1];
2148
2142
  s.status = "warn";
2149
- s.detail += ". The heading at line " + (misplaced + 1) + " is out of place, because the format has one H1 and no other heading before the first H2";
2143
+ s.detail += ". The heading at line " + (misplaced + 1) + " is out of place, because the format has one H1";
2150
2144
  }
2151
2145
  // Links are collected from the prose only, for the same reason the headings are: a link
2152
2146
  // shown inside a code fence is an example of a link, not one an agent can follow. Computed
@@ -2167,6 +2161,25 @@ export function validateLlmsTxt(f) {
2167
2161
  return r;
2168
2162
  };
2169
2163
  const absolute = named.filter((m) => isAbs(m.target)).length;
2164
+ // llms.txt v2.1 (decision P1, 2026-11-30): file lists may hold relative links next to an optional standalone
2165
+ // "Base URL:" line in the top section, before the first H2. The first such line outside fences and raw HTML
2166
+ // blocks counts. A value that is not an absolute http or https URL is a warn; relative links are no longer one.
2167
+ let baseValue = null, baseLine = -1;
2168
+ {
2169
+ const firstH2 = hm.h2.findIndex(Boolean);
2170
+ const stop = firstH2 === -1 ? lines.length : firstH2;
2171
+ for (let i = 0; i < stop; i++) {
2172
+ if (h2Mask[i])
2173
+ continue;
2174
+ const bm = /^ {0,3}Base URL:[ \t]*(.*?)[ \t]*$/.exec(lines[i]);
2175
+ if (bm) {
2176
+ baseValue = bm[1];
2177
+ baseLine = i + 1;
2178
+ break;
2179
+ }
2180
+ }
2181
+ }
2182
+ const baseValid = baseValue !== null && isAbs(baseValue);
2170
2183
  if (links.length === 0) {
2171
2184
  add("links", "warn", "Markdown links an agent can follow", "no markdown links found");
2172
2185
  }
@@ -2190,7 +2203,20 @@ export function validateLlmsTxt(f) {
2190
2203
  };
2191
2204
  const relativeCount = named.filter((m) => !hasScheme(m.target)).length;
2192
2205
  const hostless = named.length - absolute - relativeCount;
2193
- add("links", "warn", "Markdown links an agent can follow", named.length + " link" + (named.length === 1 ? "" : "s") + ", " + relativeCount + " relative" + (hostless > 0 ? " and " + hostless + " that are not valid http or https URLs" : "") + ". Absolute URLs travel better when the file is read out of context");
2206
+ if (hostless > 0) {
2207
+ add("links", "warn", "Markdown links an agent can follow", named.length + " link" + (named.length === 1 ? "" : "s") + ", " + relativeCount + " relative and " + hostless + " that are not valid http or https URLs. Absolute URLs travel better when the file is read out of context");
2208
+ }
2209
+ else if (baseValid) {
2210
+ add("links", "pass", "Markdown links an agent can follow", named.length + " link" + (named.length === 1 ? "" : "s") + ", " + relativeCount + " relative and " + absolute + " absolute. The relative links resolve against the Base URL line");
2211
+ }
2212
+ else {
2213
+ add("links", "pass", "Markdown links an agent can follow", named.length + " link" + (named.length === 1 ? "" : "s") + ", " + relativeCount + " relative and " + absolute + " absolute. The relative links resolve against the address the file was fetched from and break when the file is read from disk or a mirror. A Base URL line keeps them working");
2214
+ }
2215
+ }
2216
+ if (baseValue !== null && !baseValid) {
2217
+ const bl = checks[checks.length - 1];
2218
+ bl.status = "warn";
2219
+ bl.detail += ". The Base URL line at line " + baseLine + " is not an absolute http or https URL";
2194
2220
  }
2195
2221
  // A list line that looks like a link entry but is not one (Tek-730) turns the links check to a warn.
2196
2222
  const lookalikes = unparsedLinkEntries(lines, fenced, new Set(proseLinks.map((m) => m.at)), codeSpanMask(linkText, linkBlocks), defAt, htmlLine);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turva-llms-txt-validator",
3
- "version": "0.8.6",
3
+ "version": "0.9.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",