turva-llms-txt-validator 0.5.0 → 0.5.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
@@ -103,7 +103,7 @@ In an error report the `target` is the address given on the command line. When i
103
103
  | 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 | none |
104
104
  | 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 |
105
105
  | 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 |
106
- | 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 that looks like a link entry but is not a Markdown link: an unclosed destination such as `- [Name](https://example.com/a.md: notes)`, or an en dash, an em dash or a bullet in place of the list marker. The detail gives the count and the first five line numbers |
106
+ | 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, whether or not its link parses. The detail has one sentence per kind, each with its count and the first five line numbers |
107
107
  | 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 |
108
108
  | 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 |
109
109
 
@@ -142,7 +142,7 @@ These checks are labelled **v2** in the output. They look for link relations in
142
142
  | 9 | Home page points to its llms.txt | `rel="describedby"` has a non-empty target | `info` |
143
143
  | 10 | Home page points to a Markdown version | `rel="alternate"` has media type `text/markdown` and a non-empty target | `info` |
144
144
 
145
- The validator detects these declarations without fetching their targets. It reads the first 65,536 UTF-16 code units of the head after comments and the contents of script, style, title, noscript, noframes and template elements have been set aside. When a relation is missing from a longer head, the result says that only that part was read. A target is shown with its credentials and fragment removed and its query values masked.
145
+ The validator detects these declarations without fetching their targets. It reads the first 65,536 UTF-16 code units of the head after comments and the contents of script, style, title, noscript, noframes and template elements have been set aside. When a relation is missing from a longer head, the result says that only that part was read. The home page itself is read up to 256 KiB. When it was cut there and no relation is found in the part that was read, the info text says "in the first 256 KiB of the home page, the part that was read, or in the Link header". A target is shown with its credentials and fragment removed and its query values masked.
146
146
 
147
147
  The validator does not follow the links inside `llms.txt`, crawl the site or test whether an AI agent can complete a task there.
148
148
 
@@ -187,7 +187,7 @@ Any CI runner with Node.js 22 or newer can run the same command. Omit `--strict`
187
187
  The default validation requests two documents: `https://<host>/llms.txt` and `https://<host>/`. Redirects may add requests, but linked pages and discovery targets are never fetched. The validator stores no results.
188
188
 
189
189
  - Timeout: eight seconds per document, shared across its redirect chain.
190
- - Read limit: 256 KiB, which is 262,144 bytes, per response.
190
+ - Read limit: 256 KiB, which is 262,144 bytes, per response. A file cut there gets the size note "over 256 KiB, read truncated".
191
191
  - Redirects: up to four hops, over HTTPS, to the same host or its `www`/apex equivalent. Off-site redirects, embedded credentials and unsupported ports are rejected. A redirect target is reported with its credentials and fragment removed and its query values masked, whether the redirect was followed or rejected.
192
192
  - Host checks: IP literals, bracketed IPv6 addresses, localhost and the internal-use TLDs `localdomain`, `local`, `internal`, `home`, `lan`, `corp`, `test`, `invalid`, `arpa` and `onion` are rejected before a request is sent. An address that holds `@`, `?` or `#` is not repeated in the error message, because it can carry a user name, a password or a query value. One trailing dot on the host you give, as in `example.com.`, is removed first. Redirect targets are checked too.
193
193
 
@@ -212,10 +212,10 @@ The strict type check found two inputs that could leave `undefined` in a check's
212
212
  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.
213
213
 
214
214
  ```sh
215
- mkdir verify-llms && cd verify-llms && npm init -y && npm install turva-llms-txt-validator@0.5.0 --ignore-scripts && npm audit signatures
215
+ mkdir verify-llms && cd verify-llms && npm init -y && npm install turva-llms-txt-validator@0.5.1 --ignore-scripts && npm audit signatures
216
216
  ```
217
217
 
218
- `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.5.0` must point at that same commit, and `gh api repos/erekola/llms-txt-validator/commits/v0.5.0 --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.
218
+ `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.5.1` must point at that same commit, and `gh api repos/erekola/llms-txt-validator/commits/v0.5.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.
219
219
 
220
220
  ## Development
221
221
 
@@ -16,6 +16,7 @@ export type LinkRelations = {
16
16
  describedby: string | null;
17
17
  markdown: string | null;
18
18
  headCut?: boolean;
19
+ readCut?: boolean;
19
20
  };
20
21
  export type FetchedLlmsTxt = {
21
22
  redirect?: undefined;
@@ -53,7 +54,7 @@ export declare function enteredPath(raw: unknown): string;
53
54
  export declare function isValidPublicHost(host: string | null | undefined): boolean;
54
55
  export declare function fetchLlmsTxt(host: string, opts?: FetchOptions): Promise<FetchedLlmsTxt | FetchRedirect>;
55
56
  export declare function validateLlmsTxt(f: LlmsTxtInput): LlmsCheck[];
56
- export declare function findLinkRelations(html: string, linkHeader: string): LinkRelations;
57
+ export declare function findLinkRelations(html: string, linkHeader: string, readCut?: boolean): LinkRelations;
57
58
  export declare function validateV2Discovery(found: LinkRelations | null, unreadReason?: string): LlmsCheck[];
58
59
  export declare function summarizeChecks(checks: LlmsCheck[]): ChecksSummary;
59
60
  export declare function validateHost(input: unknown, opts?: ValidateHostOptions): Promise<ValidationResult>;
package/dist/src/index.js CHANGED
@@ -174,7 +174,7 @@ export function isValidPublicHost(host) {
174
174
  }
175
175
  // opts.path and opts.accept were added for the v2 discovery checks, which need the
176
176
  // site's home page as well as its llms.txt. Nothing else moved: the redirect budget,
177
- // the same-host rule, the credential and port rejections and the 256 KB cap are the
177
+ // the same-host rule, the credential and port rejections and the 256 KiB cap are the
178
178
  // guards this function was measured against.
179
179
  export async function fetchLlmsTxt(host, opts = {}) {
180
180
  const timeoutMs = opts.timeoutMs ?? 8000;
@@ -270,32 +270,37 @@ function isEscaped(s, i) {
270
270
  }
271
271
  // Inline code spans, marked per character across the whole document, so a link written inside
272
272
  // backticks is read as the code it is (outside audit 2026-09-26, Tek-496), including when the
273
- // span itself crosses a real line ending: a fenceless "`[a](b)\ncontinued`" used to be masked
274
- // only on its own line, so the second line escaped the mask and its bracket read as a real link
275
- // (outside review 2026-09-28). A span opens with a run of backticks and closes with the next run
276
- // of the same length anywhere in the text; a pair that crosses a block boundary, a blank line
277
- // (blank or made only of spaces and tabs), a heading line or a new list item, is not a code span
278
- // in CommonMark, so it is left unmasked and its backticks stay literal (VREG2, round 3 Tek-542:
279
- // backticks in two different list items used to enclose a real hyperlink between them). An
280
- // escaped first backtick is literal and the rest of its run still opens, while a closing run is
281
- // never escaped, because a backslash inside a code span is literal. Runs are grouped by length
282
- // and every group is read with one forward pointer, so the scan stays linear on a document of
283
- // unmatched runs.
284
- function crossesBlockBoundary(text, start, end) {
285
- const inner = text.slice(start, end);
286
- if (/\n[ \t]*\n/.test(inner))
287
- return true;
288
- const lines = inner.split("\n");
289
- for (let i = 1; i < lines.length; i++) {
290
- if (/^ {0,3}(#{1,6}(?:[ \t]|$)|[-*+][ \t]|\d{1,9}[.)][ \t])/.test(lines[i]))
291
- return true;
292
- }
293
- return false;
273
+ // span itself crosses a real line ending. V2 (Tek-526): a fenceless "`[a](b)\ncontinued`" was
274
+ // masked only on its own line, so the second line escaped the mask and its bracket read as a
275
+ // real link. A span opens with a run of backticks and closes with the next run of the same
276
+ // length anywhere in the text; a pair that crosses a block boundary, a blank line (blank or
277
+ // made only of spaces and tabs), a heading line or a new list item, is not a code span in
278
+ // CommonMark, so it is left unmasked and its backticks stay literal (VREG2, round 3 Tek-542:
279
+ // backticks in two different list items used to enclose a real hyperlink between them). Such a
280
+ // pair consumes neither run: its closer is still free to open a span of its own in its own
281
+ // block. Until 2026-11-04 the scan jumped past the closer, so a stray backtick moved the mask by
282
+ // one run, a link inside the next real span counted as a link and text after it could count as
283
+ // code (Tek-745). An escaped first backtick is literal and the rest of its run still opens, while
284
+ // a closing run is never escaped, because a backslash inside a code span is literal. Each run
285
+ // carries the number of boundary lines before it, read once per line, so comparing two runs
286
+ // costs nothing however far apart they sit. Runs are grouped by length and every group is read
287
+ // with one forward pointer, so the scan stays linear on a document of unmatched runs. Mirrored
288
+ // from the hosted validator at turva.dev in 0.5.1.
289
+ function endsInlineBlock(line) {
290
+ return /^[ \t]*$/.test(line) || /^ {0,3}(#{1,6}(?:[ \t]|$)|[-*+][ \t]|\d{1,9}[.)][ \t])/.test(line);
294
291
  }
295
292
  function codeSpanMask(text) {
296
293
  const mask = new Uint8Array(text.length);
297
294
  const runs = [];
295
+ let block = 0;
298
296
  for (let i = 0; i < text.length;) {
297
+ if (text[i] === "\n") {
298
+ const next = text.indexOf("\n", i + 1);
299
+ if (endsInlineBlock(text.slice(i + 1, next < 0 ? text.length : next)))
300
+ block++;
301
+ i++;
302
+ continue;
303
+ }
299
304
  if (text[i] !== "`") {
300
305
  i++;
301
306
  continue;
@@ -303,7 +308,7 @@ function codeSpanMask(text) {
303
308
  let j = i;
304
309
  while (j < text.length && text[j] === "`")
305
310
  j++;
306
- runs.push({ at: i, len: j - i, escaped: isEscaped(text, i) });
311
+ runs.push({ at: i, len: j - i, escaped: isEscaped(text, i), block });
307
312
  i = j;
308
313
  }
309
314
  const byLen = new Map();
@@ -323,10 +328,9 @@ function codeSpanMask(text) {
323
328
  if (p === list.length)
324
329
  continue;
325
330
  const close = runs[list[p]];
326
- const start = r.escaped ? r.at + 1 : r.at;
327
- const end = close.at + close.len;
328
- if (!crossesBlockBoundary(text, start, end))
329
- mask.fill(1, start, end);
331
+ if (close.block !== r.block)
332
+ continue;
333
+ mask.fill(1, r.escaped ? r.at + 1 : r.at, close.at + close.len);
330
334
  k = list[p];
331
335
  }
332
336
  return mask;
@@ -815,9 +819,11 @@ function blankCodeForHtml(prose) {
815
819
  // period or a parenthesis) or one of the three look-alike markers, then white space and "[", and
816
820
  // no link that collectLinks found starts at that "[". A line with one of the three look-alike
817
821
  // markers counts whether or not its link parses, because it is no list item either way. A task
818
- // list box such as "- [x] done" is not an entry. Returns the one-based line numbers.
822
+ // list box such as "- [x] done" is not an entry. Returns the one-based line numbers by kind,
823
+ // because the two kinds need different words: a look-alike marker with a link that parses is
824
+ // counted as a link and is still no list item (Tek-745).
819
825
  function unparsedLinkEntries(lines, fenced, linkAt) {
820
- const hits = [];
826
+ const unparsed = [], marker = [];
821
827
  const h2 = h2Lines(lines, fenced).h2;
822
828
  let inH2 = false, offset = 0;
823
829
  for (let i = 0; i < lines.length; i++) {
@@ -843,14 +849,21 @@ function unparsedLinkEntries(lines, fenced, linkAt) {
843
849
  const bracketAt = m[0].length - 1;
844
850
  if (/^\[[ xX]\](?:[ \t]|$)/.test(l.slice(bracketAt)))
845
851
  continue;
846
- if (alt || !linkAt.has(start + bracketAt))
847
- hits.push(i + 1);
852
+ if (alt)
853
+ marker.push(i + 1);
854
+ else if (!linkAt.has(start + bracketAt))
855
+ unparsed.push(i + 1);
848
856
  }
849
- return hits;
857
+ return { unparsed, marker };
850
858
  }
851
- function unparsedEntriesNote(hits) {
859
+ function entryLineList(hits) {
852
860
  const n = hits.length;
853
- return "; " + (n === 1 ? "1 list line looks like a link entry but is not a Markdown link, so an agent will not follow it" : n + " list lines look like link entries but are not Markdown links, so an agent will not follow them") + " (line" + (n === 1 ? "" : "s") + " " + hits.slice(0, 5).join(", ") + (n > 5 ? " and " + (n - 5) + " more" : "") + ")";
861
+ return " (line" + (n === 1 ? "" : "s") + " " + hits.slice(0, 5).join(", ") + (n > 5 ? " and " + (n - 5) + " more" : "") + ")";
862
+ }
863
+ function unparsedEntriesNote(found) {
864
+ const u = found.unparsed.length, k = found.marker.length;
865
+ return (u > 0 ? "; " + (u === 1 ? "1 list line looks like a link entry but is not a Markdown link" : u + " list lines look like link entries but are not Markdown links") + entryLineList(found.unparsed) : "")
866
+ + (k > 0 ? "; " + (k === 1 ? "1 list line opens with a dash or bullet that is not a Markdown list marker" : k + " list lines open with a dash or bullet that is not a Markdown list marker") + entryLineList(found.marker) : "");
854
867
  }
855
868
  // The text of an ATX H1, or null when the line is not one. One to three leading spaces, a
856
869
  // single "#", then a space, a tab or the end of the line. A closing run of "#" preceded by a
@@ -1196,13 +1209,13 @@ export function validateLlmsTxt(f) {
1196
1209
  }
1197
1210
  // A list line that looks like a link entry but is not one (Tek-730) turns the links check to a warn.
1198
1211
  const lookalikes = unparsedLinkEntries(lines, fenced, new Set(proseLinks.map((m) => m.at)));
1199
- if (lookalikes.length > 0) {
1212
+ if (lookalikes.unparsed.length + lookalikes.marker.length > 0) {
1200
1213
  const lk = checks[checks.length - 1];
1201
1214
  lk.status = "warn";
1202
1215
  lk.detail += unparsedEntriesNote(lookalikes);
1203
1216
  }
1204
1217
  if (f.truncated) {
1205
- add("size", "warn", "Small enough to be cheap to read", "over 256 KB, read truncated");
1218
+ add("size", "warn", "Small enough to be cheap to read", "over 256 KiB, read truncated");
1206
1219
  }
1207
1220
  else if (f.bytes <= 51200) {
1208
1221
  add("size", "pass", "Small enough to be cheap to read", f.bytes + " bytes");
@@ -2213,7 +2226,7 @@ function nextLinkValue(s, from) {
2213
2226
  // as a Link response header. That is a property of the site, not of the file, so these
2214
2227
  // two carry their own status, "info". They are never a warn and never a fail, the
2215
2228
  // summary line is unchanged, and --strict keeps exiting on warnings only.
2216
- export function findLinkRelations(html, linkHeader) {
2229
+ export function findLinkRelations(html, linkHeader, readCut = false) {
2217
2230
  const found = { describedby: null, markdown: null };
2218
2231
  // Only the head, and only what a parser would put there: a commented-out link element,
2219
2232
  // one inside a script or a template, and one the parser moves into the body are all not
@@ -2263,6 +2276,11 @@ export function findLinkRelations(html, linkHeader) {
2263
2276
  // reported as missing from the part read, not from the page (Tek-496).
2264
2277
  if (whole.length > 65536)
2265
2278
  found.headCut = true;
2279
+ // The home page itself is read up to the 256 KiB limit, and headOfDocument drops comments and
2280
+ // scripts before the head is measured, so a page cut inside one of those reaches this point with
2281
+ // a short head. Such a result reports what was read as well (Tek-745).
2282
+ if (readCut)
2283
+ found.readCut = true;
2266
2284
  return found;
2267
2285
  }
2268
2286
  // A caller that passes null without a reason gets a neutral one instead of an undefined detail (Tek-668,
@@ -2278,7 +2296,7 @@ export function validateV2Discovery(found, unreadReason = "the home page was not
2278
2296
  // A target is shown through maskLocation, as a redirect target is, so a user name, a password,
2279
2297
  // a query value or a fragment in a published link stays out of the report; until 2026-09-27 it
2280
2298
  // was only cut (Tek-496). A relative target stays relative.
2281
- const where = found.headCut ? "in the first 65,536 characters of the head, the part that was read, or in the Link header" : "in the head or the Link header";
2299
+ const where = found.headCut ? "in the first 65,536 characters of the head, the part that was read, or in the Link header" : found.readCut ? "in the first 256 KiB of the home page, the part that was read, or in the Link header" : "in the head or the Link header";
2282
2300
  add("v2-describedby", found.describedby ? "pass" : "info", "Home page points to its llms.txt (v2)", found.describedby ? 'rel="describedby" to ' + cut(maskLocation(found.describedby), 120) : 'no rel="describedby" ' + where + '; v2 recommends it so an agent finds the file without guessing');
2283
2301
  add("v2-markdown-alternate", found.markdown ? "pass" : "info", "Home page points to a markdown version (v2)", found.markdown ? 'rel="alternate" type="text/markdown" to ' + cut(maskLocation(found.markdown), 120) : 'no rel="alternate" type="text/markdown" ' + where + '; v2 recommends it so an agent finds the markdown form without guessing');
2284
2302
  return checks;
@@ -2312,7 +2330,7 @@ export async function validateHost(input, opts = {}) {
2312
2330
  ? validateV2Discovery(null, "the home page redirects away from this host, so this was not measured")
2313
2331
  : home.status !== 200
2314
2332
  ? validateV2Discovery(null, "the home page returned HTTP " + home.status + ", so this was not measured")
2315
- : validateV2Discovery(findLinkRelations(home.text, home.linkHeader));
2333
+ : validateV2Discovery(findLinkRelations(home.text, home.linkHeader, home.truncated));
2316
2334
  }
2317
2335
  catch {
2318
2336
  discovery = validateV2Discovery(null, "the home page could not be read, so this was not measured");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turva-llms-txt-validator",
3
- "version": "0.5.0",
3
+ "version": "0.5.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",