turva-llms-txt-validator 0.5.0 → 0.6.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 +9 -7
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +211 -52
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -82,7 +82,7 @@ The two discovery checks return `pass` or `info`. They never change the summary
|
|
|
82
82
|
npx --yes turva-llms-txt-validator example.com --json --strict
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
-
Completed validation returns `{ target, summary, checks }`, where `target` is `https://<host>/llms.txt`. Each check contains `{ id, status, label, detail }`. The `input-path` check, which reports a path given with the domain and then ignored, also carries `value`, that path cut to 120 characters.
|
|
85
|
+
Completed validation returns `{ target, summary, checks }`, where `target` is `https://<host>/llms.txt`. Each check contains `{ id, status, label, detail }`. Read `id` and `status` in a script, because the wording of `detail` can change between versions. The `input-path` check, which reports a path given with the domain and then ignored, also carries `value`, that path cut to 120 characters.
|
|
86
86
|
|
|
87
87
|
With `--json`, an invalid domain or a failed fetch returns `{ "error": "...", "target": "..." }` and exits with code `2`. A network error adds `code`, such as `EAI_AGAIN`. An unknown option, a second domain and a missing domain return `{ "error": "..." }` only, with no target, and also exit with code `2`.
|
|
88
88
|
|
|
@@ -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
|
|
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
|
|
|
@@ -114,6 +114,8 @@ Some failures stop the file checks early. For example, an HTML response is repor
|
|
|
114
114
|
Links are read the way CommonMark reads them for the forms listed here.
|
|
115
115
|
|
|
116
116
|
- A link inside inline code, after an escaped bracket or in an image does not count.
|
|
117
|
+
- Inline code pairs only inside one block, the way CommonMark reads blocks. A blank line, a heading, a list item, a thematic break and a setext underline each end a block. An empty list item or a numbered item that does not start at 1 does not end a paragraph, unless the line closes an open list item, so a backtick pair across such a line is inline code. Block quotes and HTML blocks are not read as blocks here, so a backtick pair across the start of one, or across lines inside a block quote, stays inline code. CommonMark ends the block at a block quote and at an HTML block that can interrupt a paragraph.
|
|
118
|
+
- A fence indented past three columns inside a list item hides what it holds, closed or not, as long as it sits less than four columns past the item's content column. Further in, CommonMark reads indented code, and this validator still counts a link in it. One gap remains for a fence opened on a list marker line, at four or more columns or by a tab: its closing line at 0 to 3 columns reads as a new opening fence, so the lines after it are skipped until the next fence.
|
|
117
119
|
- A link in an ordered list, a target in angle brackets and a target with a title in double or single quotes do count.
|
|
118
120
|
- A title in parentheses is not read, so `[Guide](https://example.org/guide (Overview))` is not collected.
|
|
119
121
|
- An unbracketed target ends at its first closing parenthesis, so `https://example.org/docs_(v2)` is read only up to `https://example.org/docs_(v2`. Write a target that contains parentheses in angle brackets.
|
|
@@ -142,7 +144,7 @@ These checks are labelled **v2** in the output. They look for link relations in
|
|
|
142
144
|
| 9 | Home page points to its llms.txt | `rel="describedby"` has a non-empty target | `info` |
|
|
143
145
|
| 10 | Home page points to a Markdown version | `rel="alternate"` has media type `text/markdown` and a non-empty target | `info` |
|
|
144
146
|
|
|
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.
|
|
147
|
+
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
148
|
|
|
147
149
|
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
150
|
|
|
@@ -187,7 +189,7 @@ Any CI runner with Node.js 22 or newer can run the same command. Omit `--strict`
|
|
|
187
189
|
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
190
|
|
|
189
191
|
- Timeout: eight seconds per document, shared across its redirect chain.
|
|
190
|
-
- Read limit: 256 KiB, which is 262,144 bytes, per response.
|
|
192
|
+
- 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
193
|
- 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
194
|
- 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
195
|
|
|
@@ -199,7 +201,7 @@ For vulnerability reporting and supported versions, see [SECURITY.md](https://gi
|
|
|
199
201
|
|
|
200
202
|
The source is TypeScript under `src/` and `bin/`, compiled with `tsc` to `dist/`. The tarball ships only `dist/src/index.js`, `dist/src/index.d.ts`, `dist/bin/cli.js`, the README, the license, the third-party notices and `package.json`, which npm always includes. `dist/` is generated, and `npm pack` builds it through the `prepack` script.
|
|
201
203
|
|
|
202
|
-
GitHub Actions tests Node.js 22 and
|
|
204
|
+
GitHub Actions tests Node.js 22, 24 and 26 on Ubuntu and Node.js 22 on Windows. A version tag starts the release workflow, `.github/workflows/publish.yml`. It runs the type check and the tests, fails when the tag and `package.json` name different versions, publishes with npm trusted publishing over OIDC and creates the GitHub release from the CHANGELOG section. npm writes a provenance attestation. No npm token is stored in the repository or in the workflow.
|
|
203
205
|
|
|
204
206
|
## From JavaScript to TypeScript
|
|
205
207
|
|
|
@@ -212,10 +214,10 @@ The strict type check found two inputs that could leave `undefined` in a check's
|
|
|
212
214
|
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
215
|
|
|
214
216
|
```sh
|
|
215
|
-
mkdir verify-llms && cd verify-llms && npm init -y && npm install turva-llms-txt-validator@0.
|
|
217
|
+
mkdir verify-llms && cd verify-llms && npm init -y && npm install turva-llms-txt-validator@0.6.0 --ignore-scripts && npm audit signatures
|
|
216
218
|
```
|
|
217
219
|
|
|
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.
|
|
220
|
+
`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.6.0` must point at that same commit, and `gh api repos/erekola/llms-txt-validator/commits/v0.6.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.
|
|
219
221
|
|
|
220
222
|
## Development
|
|
221
223
|
|
package/dist/src/index.d.ts
CHANGED
|
@@ -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
|
|
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,40 +270,48 @@ 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`"
|
|
274
|
-
// only on its own line, so the second line escaped the mask and its bracket read as a
|
|
275
|
-
//
|
|
276
|
-
//
|
|
277
|
-
//
|
|
278
|
-
//
|
|
279
|
-
//
|
|
280
|
-
//
|
|
281
|
-
//
|
|
282
|
-
//
|
|
283
|
-
//
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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;
|
|
294
|
-
}
|
|
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 in two different blocks, as inlineBlockReader reads them,
|
|
277
|
+
// is not a code span in CommonMark, so it is left unmasked and its backticks stay literal (VREG2,
|
|
278
|
+
// round 3 Tek-542: backticks in two different list items used to enclose a real hyperlink
|
|
279
|
+
// between them). Such a pair consumes neither run: its closer is still free to open a span of its own in its own
|
|
280
|
+
// block. Until 2026-11-04 the scan jumped past the closer, so a stray backtick moved the mask by
|
|
281
|
+
// one run, a link inside the next real span counted as a link and text after it could count as
|
|
282
|
+
// code (Tek-745). An escaped first backtick is literal and the rest of its run still opens, while
|
|
283
|
+
// a closing run is never escaped, because a backslash inside a code span is literal. Each run
|
|
284
|
+
// carries the number of its block, read once per line, so comparing two runs
|
|
285
|
+
// costs nothing however far apart they sit. Runs are grouped by length and every group is read
|
|
286
|
+
// with one forward pointer, so the scan stays linear on a document of unmatched runs. Mirrored
|
|
287
|
+
// from the hosted validator at turva.dev in 0.6.0.
|
|
295
288
|
function codeSpanMask(text) {
|
|
296
289
|
const mask = new Uint8Array(text.length);
|
|
297
290
|
const runs = [];
|
|
291
|
+
const blockOf = inlineBlockReader();
|
|
292
|
+
let block = 0;
|
|
293
|
+
const readLine = (from) => {
|
|
294
|
+
const next = text.indexOf("\n", from);
|
|
295
|
+
const end = next < 0 ? text.length : next;
|
|
296
|
+
block = blockOf(text.slice(from, end));
|
|
297
|
+
if (block < 0)
|
|
298
|
+
mask.fill(1, from, end);
|
|
299
|
+
};
|
|
300
|
+
readLine(0);
|
|
298
301
|
for (let i = 0; i < text.length;) {
|
|
299
|
-
if (text[i]
|
|
302
|
+
if (text[i] === "\n") {
|
|
303
|
+
readLine(i + 1);
|
|
304
|
+
i++;
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
if (text[i] !== "`" || block < 0) {
|
|
300
308
|
i++;
|
|
301
309
|
continue;
|
|
302
310
|
}
|
|
303
311
|
let j = i;
|
|
304
312
|
while (j < text.length && text[j] === "`")
|
|
305
313
|
j++;
|
|
306
|
-
runs.push({ at: i, len: j - i, escaped: isEscaped(text, i) });
|
|
314
|
+
runs.push({ at: i, len: j - i, escaped: isEscaped(text, i), block });
|
|
307
315
|
i = j;
|
|
308
316
|
}
|
|
309
317
|
const byLen = new Map();
|
|
@@ -323,14 +331,151 @@ function codeSpanMask(text) {
|
|
|
323
331
|
if (p === list.length)
|
|
324
332
|
continue;
|
|
325
333
|
const close = runs[list[p]];
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
mask.fill(1, start, end);
|
|
334
|
+
if (close.block !== r.block)
|
|
335
|
+
continue;
|
|
336
|
+
mask.fill(1, r.escaped ? r.at + 1 : r.at, close.at + close.len);
|
|
330
337
|
k = list[p];
|
|
331
338
|
}
|
|
332
339
|
return mask;
|
|
333
340
|
}
|
|
341
|
+
// Which inline block each line belongs to, read once per line in document order, because two
|
|
342
|
+
// backtick runs pair only inside one block. Measured against commonmark.js 0.31.2, Tek-747. A
|
|
343
|
+
// blank line, an ATX heading, a thematic break and a setext underline end a paragraph, and the
|
|
344
|
+
// next line starts a new block, so a backtick on a heading line never pairs with the next line. A
|
|
345
|
+
// list marker starts a new block, with the exception CommonMark sets: a line that would continue
|
|
346
|
+
// an open paragraph cannot open a list with an empty item or with a number other than 1. The
|
|
347
|
+
// number is compared as a number, so "01." counts as 1. That exception holds only while the
|
|
348
|
+
// paragraph is the innermost open container. A line indented less than an open item's content
|
|
349
|
+
// column closes that item, so "2." there is the list's next item, which is why the reader keeps
|
|
350
|
+
// the content column of every open item. An empty item followed by a blank line is closed. An
|
|
351
|
+
// indented line continues an open paragraph, and a run of indented lines with no paragraph open is
|
|
352
|
+
// one block, so backticks in it still pair. A fence this reader sees is one the caller did not
|
|
353
|
+
// blank, because fenceMask reads only lines at 0 to 3 columns: a fence indented further inside a
|
|
354
|
+
// list item, or opened on a marker line. For every line of such a fence the reader returns -1 and
|
|
355
|
+
// the scan masks the line whole, so a fence hides what it holds whatever closes it and whichever
|
|
356
|
+
// character it uses. A fence ends when an open item it sits in closes. Block quotes and HTML blocks
|
|
357
|
+
// are not read here, neither the start of one nor the lines of a block quote. Every pattern runs at
|
|
358
|
+
// a fixed position, the thematic break test and the closing fence test run once per line, and the
|
|
359
|
+
// walk over the open items stops at the line's own width, so the reader stays linear however deep
|
|
360
|
+
// the items nest.
|
|
361
|
+
const INLINE_HEADING = /#{1,6}(?:[ \t]|$)/y;
|
|
362
|
+
const INLINE_UNDERLINE = /(?:=+|-+)[ \t]*$/y;
|
|
363
|
+
const INLINE_THEMATIC = /([-*_])(?:[ \t]*\1){2,}[ \t]*$/y;
|
|
364
|
+
const INLINE_MARKER = /(?:[-*+]|(\d{1,9})[.)])(?=[ \t]|$)/y;
|
|
365
|
+
const INLINE_FENCE = /(`{3,})[^`]*$|(~{3,})/y;
|
|
366
|
+
function matchAt(re, s, at) {
|
|
367
|
+
re.lastIndex = at;
|
|
368
|
+
return re.exec(s);
|
|
369
|
+
}
|
|
370
|
+
function inlineBlockReader() {
|
|
371
|
+
let block = 0, para = false, code = false, emptyItem = false;
|
|
372
|
+
let fenceChar = "", fenceLen = 0, fenceDepth = 0;
|
|
373
|
+
const items = [];
|
|
374
|
+
return (line) => {
|
|
375
|
+
let p = 0, col = 0;
|
|
376
|
+
const skipBlanks = () => {
|
|
377
|
+
for (; p < line.length; p++) {
|
|
378
|
+
if (line[p] === " ")
|
|
379
|
+
col++;
|
|
380
|
+
else if (line[p] === "\t")
|
|
381
|
+
col += 4 - (col % 4);
|
|
382
|
+
else
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
skipBlanks();
|
|
387
|
+
if (p === line.length) {
|
|
388
|
+
if (fenceChar !== "")
|
|
389
|
+
return -1;
|
|
390
|
+
if (emptyItem)
|
|
391
|
+
items.pop();
|
|
392
|
+
emptyItem = false;
|
|
393
|
+
para = false;
|
|
394
|
+
code = false;
|
|
395
|
+
return ++block;
|
|
396
|
+
}
|
|
397
|
+
emptyItem = false;
|
|
398
|
+
let depth = 0;
|
|
399
|
+
while (depth < items.length && col >= items[depth])
|
|
400
|
+
depth++;
|
|
401
|
+
if (fenceChar !== "") {
|
|
402
|
+
if (depth >= fenceDepth) {
|
|
403
|
+
if (col - (fenceDepth > 0 ? items[fenceDepth - 1] : 0) < 4) {
|
|
404
|
+
let end = p;
|
|
405
|
+
while (line[end] === fenceChar)
|
|
406
|
+
end++;
|
|
407
|
+
if (end - p >= fenceLen && line.slice(end).trim() === "")
|
|
408
|
+
fenceChar = "";
|
|
409
|
+
}
|
|
410
|
+
return -1;
|
|
411
|
+
}
|
|
412
|
+
fenceChar = "";
|
|
413
|
+
}
|
|
414
|
+
let inParagraph = para && depth === items.length;
|
|
415
|
+
let thematicRead = false;
|
|
416
|
+
for (;;) {
|
|
417
|
+
if (col - (depth > 0 ? items[depth - 1] : 0) >= 4) {
|
|
418
|
+
if (para)
|
|
419
|
+
return block;
|
|
420
|
+
items.length = depth;
|
|
421
|
+
if (code)
|
|
422
|
+
return block;
|
|
423
|
+
code = true;
|
|
424
|
+
return ++block;
|
|
425
|
+
}
|
|
426
|
+
code = false;
|
|
427
|
+
if (matchAt(INLINE_HEADING, line, p)) {
|
|
428
|
+
items.length = depth;
|
|
429
|
+
para = false;
|
|
430
|
+
return ++block;
|
|
431
|
+
}
|
|
432
|
+
const fence = matchAt(INLINE_FENCE, line, p);
|
|
433
|
+
if (fence) {
|
|
434
|
+
items.length = depth;
|
|
435
|
+
para = false;
|
|
436
|
+
fenceChar = line[p];
|
|
437
|
+
fenceLen = (fence[1] || fence[2]).length;
|
|
438
|
+
fenceDepth = depth;
|
|
439
|
+
return -1;
|
|
440
|
+
}
|
|
441
|
+
if (inParagraph && matchAt(INLINE_UNDERLINE, line, p)) {
|
|
442
|
+
para = false;
|
|
443
|
+
return block;
|
|
444
|
+
}
|
|
445
|
+
if (!thematicRead && matchAt(INLINE_THEMATIC, line, p)) {
|
|
446
|
+
items.length = depth;
|
|
447
|
+
para = false;
|
|
448
|
+
return ++block;
|
|
449
|
+
}
|
|
450
|
+
thematicRead = true;
|
|
451
|
+
const marker = matchAt(INLINE_MARKER, line, p);
|
|
452
|
+
if (!marker)
|
|
453
|
+
break;
|
|
454
|
+
p += marker[0].length;
|
|
455
|
+
col += marker[0].length;
|
|
456
|
+
const afterMarker = col;
|
|
457
|
+
skipBlanks();
|
|
458
|
+
const empty = p === line.length;
|
|
459
|
+
if (inParagraph && (empty || (marker[1] !== undefined && Number(marker[1]) !== 1)))
|
|
460
|
+
break;
|
|
461
|
+
items.length = depth;
|
|
462
|
+
items.push(empty || col - afterMarker >= 5 ? afterMarker + 1 : col);
|
|
463
|
+
depth = items.length;
|
|
464
|
+
para = false;
|
|
465
|
+
inParagraph = false;
|
|
466
|
+
if (empty) {
|
|
467
|
+
emptyItem = true;
|
|
468
|
+
return block;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
if (!para) {
|
|
472
|
+
items.length = depth;
|
|
473
|
+
para = true;
|
|
474
|
+
block++;
|
|
475
|
+
}
|
|
476
|
+
return block;
|
|
477
|
+
};
|
|
478
|
+
}
|
|
334
479
|
// A CommonMark link reference label is matched without regard to case or the exact run of
|
|
335
480
|
// whitespace inside it, so "[Guide]" and "[ guide ]" name the same definition.
|
|
336
481
|
function normalizeLinkLabel(s) {
|
|
@@ -815,9 +960,11 @@ function blankCodeForHtml(prose) {
|
|
|
815
960
|
// period or a parenthesis) or one of the three look-alike markers, then white space and "[", and
|
|
816
961
|
// no link that collectLinks found starts at that "[". A line with one of the three look-alike
|
|
817
962
|
// 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
|
|
963
|
+
// list box such as "- [x] done" is not an entry. Returns the one-based line numbers by kind,
|
|
964
|
+
// because the two kinds need different words: a look-alike marker with a link that parses is
|
|
965
|
+
// counted as a link and is still no list item (Tek-745).
|
|
819
966
|
function unparsedLinkEntries(lines, fenced, linkAt) {
|
|
820
|
-
const
|
|
967
|
+
const unparsed = [], marker = [];
|
|
821
968
|
const h2 = h2Lines(lines, fenced).h2;
|
|
822
969
|
let inH2 = false, offset = 0;
|
|
823
970
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -843,14 +990,21 @@ function unparsedLinkEntries(lines, fenced, linkAt) {
|
|
|
843
990
|
const bracketAt = m[0].length - 1;
|
|
844
991
|
if (/^\[[ xX]\](?:[ \t]|$)/.test(l.slice(bracketAt)))
|
|
845
992
|
continue;
|
|
846
|
-
if (alt
|
|
847
|
-
|
|
993
|
+
if (alt)
|
|
994
|
+
marker.push(i + 1);
|
|
995
|
+
else if (!linkAt.has(start + bracketAt))
|
|
996
|
+
unparsed.push(i + 1);
|
|
848
997
|
}
|
|
849
|
-
return
|
|
998
|
+
return { unparsed, marker };
|
|
850
999
|
}
|
|
851
|
-
function
|
|
1000
|
+
function entryLineList(hits) {
|
|
852
1001
|
const n = hits.length;
|
|
853
|
-
return "
|
|
1002
|
+
return " (line" + (n === 1 ? "" : "s") + " " + hits.slice(0, 5).join(", ") + (n > 5 ? " and " + (n - 5) + " more" : "") + ")";
|
|
1003
|
+
}
|
|
1004
|
+
function unparsedEntriesNote(found) {
|
|
1005
|
+
const u = found.unparsed.length, k = found.marker.length;
|
|
1006
|
+
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) : "")
|
|
1007
|
+
+ (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
1008
|
}
|
|
855
1009
|
// The text of an ATX H1, or null when the line is not one. One to three leading spaces, a
|
|
856
1010
|
// single "#", then a space, a tab or the end of the line. A closing run of "#" preceded by a
|
|
@@ -897,11 +1051,11 @@ function isAbsoluteHttpUrl(t) {
|
|
|
897
1051
|
}
|
|
898
1052
|
function redirectFailDetail(f) {
|
|
899
1053
|
if (f.reason === "off-host")
|
|
900
|
-
return "redirects to " + f.location + ", a different host
|
|
1054
|
+
return "redirects to " + f.location + ", a different host. llms.txt is host-scoped, so validate that host directly";
|
|
901
1055
|
if (f.reason === "unsafe-target")
|
|
902
|
-
return "redirects to an unsupported target (" + f.location + ")
|
|
1056
|
+
return "redirects to an unsupported target (" + f.location + "). Only https redirects to the same site are followed";
|
|
903
1057
|
if (f.reason === "too-many")
|
|
904
|
-
return "too many redirects
|
|
1058
|
+
return "too many redirects. The llms.txt is not served at a stable URL";
|
|
905
1059
|
return "got a " + f.status + " redirect without a usable Location header";
|
|
906
1060
|
}
|
|
907
1061
|
export function validateLlmsTxt(f) {
|
|
@@ -961,7 +1115,7 @@ export function validateLlmsTxt(f) {
|
|
|
961
1115
|
add("h1-title", "pass", "Starts with an H1 title", JSON.stringify(cut(first, 80)));
|
|
962
1116
|
}
|
|
963
1117
|
else if (title === "") {
|
|
964
|
-
add("h1-title", "fail", "Starts with an H1 title", "the H1 has no text
|
|
1118
|
+
add("h1-title", "fail", "Starts with an H1 title", "the H1 has no text. The format requires the project name there");
|
|
965
1119
|
}
|
|
966
1120
|
else {
|
|
967
1121
|
add("h1-title", "fail", "Starts with an H1 title", "the first non-empty line should be a markdown H1 (# Site name, or one line of text underlined with =)");
|
|
@@ -1161,15 +1315,15 @@ export function validateLlmsTxt(f) {
|
|
|
1161
1315
|
add("sections", "pass", "H2 sections group the content", h2Count + " section" + (h2Count === 1 ? "" : "s") + ", " + sectionsWithList + " carrying a file list");
|
|
1162
1316
|
}
|
|
1163
1317
|
else if (h2Count > 0) {
|
|
1164
|
-
add("sections", "warn", "H2 sections group the content", h2Count + " section" + (h2Count === 1 ? "" : "s") + " but no file list under any of them
|
|
1318
|
+
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");
|
|
1165
1319
|
}
|
|
1166
1320
|
else {
|
|
1167
|
-
add("sections", "warn", "H2 sections group the content", "no H2 sections found
|
|
1321
|
+
add("sections", "warn", "H2 sections group the content", "no H2 sections found. Sections are the convention for grouping links");
|
|
1168
1322
|
}
|
|
1169
1323
|
if (misplaced !== -1) {
|
|
1170
1324
|
const s = checks[checks.length - 1];
|
|
1171
1325
|
s.status = "warn";
|
|
1172
|
-
s.detail += "
|
|
1326
|
+
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";
|
|
1173
1327
|
}
|
|
1174
1328
|
// Links are collected from the prose only, for the same reason the headings are: a link
|
|
1175
1329
|
// shown inside a code fence is an example of a link, not one an agent can follow. Computed
|
|
@@ -1184,7 +1338,7 @@ export function validateLlmsTxt(f) {
|
|
|
1184
1338
|
add("links", "warn", "Markdown links an agent can follow", "no markdown links found");
|
|
1185
1339
|
}
|
|
1186
1340
|
else if (unnamed > 0) {
|
|
1187
|
-
add("links", "warn", "Markdown links an agent can follow", links.length + " link" + (links.length === 1 ? "" : "s") + ", " + unnamed + " with an empty link name
|
|
1341
|
+
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");
|
|
1188
1342
|
}
|
|
1189
1343
|
else if (absolute === named.length) {
|
|
1190
1344
|
add("links", "pass", "Markdown links an agent can follow", named.length + " link" + (named.length === 1 ? "" : "s") + ", all absolute URLs");
|
|
@@ -1192,23 +1346,23 @@ export function validateLlmsTxt(f) {
|
|
|
1192
1346
|
else {
|
|
1193
1347
|
const relativeCount = named.filter((m) => !/^[a-z][a-z0-9+.-]*:/i.test(m.target)).length;
|
|
1194
1348
|
const hostless = named.length - absolute - relativeCount;
|
|
1195
|
-
add("links", "warn", "Markdown links an agent can follow", named.length + " links, " + relativeCount + " relative" + (hostless > 0 ? " and " + hostless + " that are not valid http or https URLs" : "") + "
|
|
1349
|
+
add("links", "warn", "Markdown links an agent can follow", named.length + " links, " + 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");
|
|
1196
1350
|
}
|
|
1197
1351
|
// A list line that looks like a link entry but is not one (Tek-730) turns the links check to a warn.
|
|
1198
1352
|
const lookalikes = unparsedLinkEntries(lines, fenced, new Set(proseLinks.map((m) => m.at)));
|
|
1199
|
-
if (lookalikes.length > 0) {
|
|
1353
|
+
if (lookalikes.unparsed.length + lookalikes.marker.length > 0) {
|
|
1200
1354
|
const lk = checks[checks.length - 1];
|
|
1201
1355
|
lk.status = "warn";
|
|
1202
1356
|
lk.detail += unparsedEntriesNote(lookalikes);
|
|
1203
1357
|
}
|
|
1204
1358
|
if (f.truncated) {
|
|
1205
|
-
add("size", "warn", "Small enough to be cheap to read", "over 256
|
|
1359
|
+
add("size", "warn", "Small enough to be cheap to read", "over 256 KiB, read truncated");
|
|
1206
1360
|
}
|
|
1207
1361
|
else if (f.bytes <= 51200) {
|
|
1208
1362
|
add("size", "pass", "Small enough to be cheap to read", f.bytes + " bytes");
|
|
1209
1363
|
}
|
|
1210
1364
|
else {
|
|
1211
|
-
add("size", "warn", "Small enough to be cheap to read", f.bytes + " bytes
|
|
1365
|
+
add("size", "warn", "Small enough to be cheap to read", f.bytes + " bytes. Consider moving detail to llms-full.txt");
|
|
1212
1366
|
}
|
|
1213
1367
|
// A tag needs its closing ">" (Tek-560): an opening tag with well formed attributes, a closing tag
|
|
1214
1368
|
// or a comment start. "a <b + c" is prose and no longer warns. An attribute name is any run of
|
|
@@ -1221,7 +1375,7 @@ export function validateLlmsTxt(f) {
|
|
|
1221
1375
|
// string inside an inline code span, a fenced block or after a backslash is not markup.
|
|
1222
1376
|
const htmlScan = blankCodeForHtml(proseText);
|
|
1223
1377
|
if (/<[a-zA-Z][a-zA-Z0-9-]*(?:\s+[^\s"'<>\/=\p{L}\p{N}_]*[\p{L}\p{N}_][^\s"'<>\/=]*(?:\s*=\s*(?:"[^"]*"|'[^']*'|(?!["'])[^\s<>]+))?)*\s*\/?>|<\/[a-zA-Z][a-zA-Z0-9-]*\s*>|<!--/u.test(htmlScan)) {
|
|
1224
|
-
add("no-html", "warn", "No HTML markup in the file", "HTML tags found
|
|
1378
|
+
add("no-html", "warn", "No HTML markup in the file", "HTML tags found. llms.txt should be plain markdown");
|
|
1225
1379
|
}
|
|
1226
1380
|
else {
|
|
1227
1381
|
add("no-html", "pass", "No HTML markup in the file", "plain markdown");
|
|
@@ -2213,7 +2367,7 @@ function nextLinkValue(s, from) {
|
|
|
2213
2367
|
// as a Link response header. That is a property of the site, not of the file, so these
|
|
2214
2368
|
// two carry their own status, "info". They are never a warn and never a fail, the
|
|
2215
2369
|
// summary line is unchanged, and --strict keeps exiting on warnings only.
|
|
2216
|
-
export function findLinkRelations(html, linkHeader) {
|
|
2370
|
+
export function findLinkRelations(html, linkHeader, readCut = false) {
|
|
2217
2371
|
const found = { describedby: null, markdown: null };
|
|
2218
2372
|
// Only the head, and only what a parser would put there: a commented-out link element,
|
|
2219
2373
|
// one inside a script or a template, and one the parser moves into the body are all not
|
|
@@ -2263,6 +2417,11 @@ export function findLinkRelations(html, linkHeader) {
|
|
|
2263
2417
|
// reported as missing from the part read, not from the page (Tek-496).
|
|
2264
2418
|
if (whole.length > 65536)
|
|
2265
2419
|
found.headCut = true;
|
|
2420
|
+
// The home page itself is read up to the 256 KiB limit, and headOfDocument drops comments and
|
|
2421
|
+
// scripts before the head is measured, so a page cut inside one of those reaches this point with
|
|
2422
|
+
// a short head. Such a result reports what was read as well (Tek-745).
|
|
2423
|
+
if (readCut)
|
|
2424
|
+
found.readCut = true;
|
|
2266
2425
|
return found;
|
|
2267
2426
|
}
|
|
2268
2427
|
// A caller that passes null without a reason gets a neutral one instead of an undefined detail (Tek-668,
|
|
@@ -2278,7 +2437,7 @@ export function validateV2Discovery(found, unreadReason = "the home page was not
|
|
|
2278
2437
|
// A target is shown through maskLocation, as a redirect target is, so a user name, a password,
|
|
2279
2438
|
// a query value or a fragment in a published link stays out of the report; until 2026-09-27 it
|
|
2280
2439
|
// 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";
|
|
2440
|
+
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
2441
|
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
2442
|
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
2443
|
return checks;
|
|
@@ -2312,7 +2471,7 @@ export async function validateHost(input, opts = {}) {
|
|
|
2312
2471
|
? validateV2Discovery(null, "the home page redirects away from this host, so this was not measured")
|
|
2313
2472
|
: home.status !== 200
|
|
2314
2473
|
? validateV2Discovery(null, "the home page returned HTTP " + home.status + ", so this was not measured")
|
|
2315
|
-
: validateV2Discovery(findLinkRelations(home.text, home.linkHeader));
|
|
2474
|
+
: validateV2Discovery(findLinkRelations(home.text, home.linkHeader, home.truncated));
|
|
2316
2475
|
}
|
|
2317
2476
|
catch {
|
|
2318
2477
|
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.
|
|
3
|
+
"version": "0.6.0",
|
|
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",
|