turva-llms-txt-validator 0.4.2 → 0.5.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 -5
- package/dist/bin/cli.js +1 -1
- package/dist/src/index.js +88 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -103,9 +103,9 @@ 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 |
|
|
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 |
|
|
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
|
-
| 8 | File contains no HTML markup | none | An opening tag with its closing `>`, a closing tag or an HTML comment is found
|
|
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
|
|
|
110
110
|
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.
|
|
111
111
|
|
|
@@ -201,17 +201,21 @@ The source is TypeScript under `src/` and `bin/`, compiled with `tsc` to `dist/`
|
|
|
201
201
|
|
|
202
202
|
GitHub Actions tests Node.js 22 and 24 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
203
|
|
|
204
|
-
|
|
204
|
+
## From JavaScript to TypeScript
|
|
205
|
+
|
|
206
|
+
Up to 0.3.21 the package was plain JavaScript modules, starting with `src/index.mjs`. Version 0.4.0, released on 21 October 2026, ports it to TypeScript compiled to `dist/`, and the entry point moved to `dist/src/index.js` behind the same `exports` name. The compiled library has the same 12 493 JavaScript tokens as 0.3.21, apart from the relative path to `package.json`. A differential run fed both versions 4 160 000 generated `llms.txt` inputs and 832 000 HTML heads and found no difference. The CLI kept its flags, its output and its exit codes.
|
|
207
|
+
|
|
208
|
+
The strict type check found two inputs that could leave `undefined` in a check's detail. Neither `fetchLlmsTxt` nor `validateHost` produces them, and 0.4.1 fixed both. Each release is described in [CHANGELOG.md](https://github.com/erekola/llms-txt-validator/blob/main/CHANGELOG.md).
|
|
205
209
|
|
|
206
210
|
## Verify a release
|
|
207
211
|
|
|
208
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.
|
|
209
213
|
|
|
210
214
|
```sh
|
|
211
|
-
mkdir verify-llms && cd verify-llms && npm init -y && npm install turva-llms-txt-validator@0.
|
|
215
|
+
mkdir verify-llms && cd verify-llms && npm init -y && npm install turva-llms-txt-validator@0.5.0 --ignore-scripts && npm audit signatures
|
|
212
216
|
```
|
|
213
217
|
|
|
214
|
-
`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.
|
|
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.
|
|
215
219
|
|
|
216
220
|
## Development
|
|
217
221
|
|
package/dist/bin/cli.js
CHANGED
|
@@ -65,7 +65,7 @@ try {
|
|
|
65
65
|
// published link cannot write an escape sequence to the terminal. A check's reflected
|
|
66
66
|
// value, when it has one, is printed ahead of the sentence, the same position the old
|
|
67
67
|
// concatenated string put it in, so text output reads the same while the JSON field stays
|
|
68
|
-
// separate (round 3 Tek-542, mirrored from worker.
|
|
68
|
+
// separate (round 3 Tek-542, mirrored from worker.ts decision 19, Tek-526).
|
|
69
69
|
console.log(result.target);
|
|
70
70
|
for (const c of result.checks)
|
|
71
71
|
console.log(" " + mark[c.status] + " " + c.label + " (" + (c.value !== undefined ? c.value + " " : "") + c.detail + ")");
|
package/dist/src/index.js
CHANGED
|
@@ -17,7 +17,7 @@ const UA = "turva-llms-txt-validator/" + VERSION + " (+https://turva.dev/llms-tx
|
|
|
17
17
|
// pair leaves half of it, and the character is lost. How the half is written depends on
|
|
18
18
|
// the runtime: Node's UTF-8 encoder replaces it with U+FFFD, and the hosted validator in
|
|
19
19
|
// workerd wrote three bytes that were not valid UTF-8 (round 16 S3-1 and S3-2, measured
|
|
20
|
-
// there 2026-09-03). Mirrors worker.
|
|
20
|
+
// there 2026-09-03). Mirrors worker.ts cut().
|
|
21
21
|
export function cut(s, n) {
|
|
22
22
|
s = String(s).slice(0, n);
|
|
23
23
|
return /[\uD800-\uDBFF]$/.test(s) ? s.slice(0, -1) : s;
|
|
@@ -29,7 +29,7 @@ export function cut(s, n) {
|
|
|
29
29
|
// https://user:password@host/ kept both in the check's detail and in the returned location (outside
|
|
30
30
|
// review, 2026-09-22). A target the URL parser refuses is masked by hand: nothing after the first ?
|
|
31
31
|
// or # survives, and when the target has a scheme or starts with two slashes, everything up to the
|
|
32
|
-
// last @ before them is shown as ***. Mirrors worker.
|
|
32
|
+
// last @ before them is shown as ***. Mirrors worker.ts maskLocation().
|
|
33
33
|
export function maskLocation(href, base) {
|
|
34
34
|
let u = null;
|
|
35
35
|
try {
|
|
@@ -101,14 +101,14 @@ export function maskLocation(href, base) {
|
|
|
101
101
|
// Unicode bidi controls (U+202A to U+202E, U+2066 to U+2069) have no place in a check's
|
|
102
102
|
// detail: text quoted from the fetched file could otherwise read in a different order here
|
|
103
103
|
// than in the file itself, and the right-to-left override is the classic way to do that
|
|
104
|
-
// (round 19, V6-U1). Mirrors worker.
|
|
104
|
+
// (round 19, V6-U1). Mirrors worker.ts stripBidi().
|
|
105
105
|
export function stripBidi(s) {
|
|
106
106
|
return String(s).replace(/[\u202A-\u202E\u2066-\u2069]/g, "");
|
|
107
107
|
}
|
|
108
108
|
// C0 and C1 control characters leave a check's detail as well. JSON escapes them, but a program
|
|
109
109
|
// that prints a detail to a terminal passes ESC through, so a published link could carry a
|
|
110
110
|
// sequence that clears the screen (Tek-496).
|
|
111
|
-
// Mirrors worker.
|
|
111
|
+
// Mirrors worker.ts stripControls().
|
|
112
112
|
export function stripControls(s) {
|
|
113
113
|
return String(s).replace(/[\u0000-\u001F\u007F-\u009F]/g, "");
|
|
114
114
|
}
|
|
@@ -132,7 +132,7 @@ export function normalizeHostInput(raw) {
|
|
|
132
132
|
if (u.username || u.password)
|
|
133
133
|
return null;
|
|
134
134
|
// One trailing dot names the same host in absolute form, so "example.com." is read as
|
|
135
|
-
// example.com instead of refused (round 19, K7-P5). Mirrors worker.
|
|
135
|
+
// example.com instead of refused (round 19, K7-P5). Mirrors worker.ts normalizeHostInput().
|
|
136
136
|
const typedHost = u.hostname;
|
|
137
137
|
return typedHost.length > 1 && typedHost.endsWith(".") ? typedHost.slice(0, -1) : typedHost;
|
|
138
138
|
}
|
|
@@ -141,7 +141,7 @@ export function normalizeHostInput(raw) {
|
|
|
141
141
|
// as a fetch proxy, so a typed /docs/llms.txt used to be dropped without a word while the result
|
|
142
142
|
// described the root file (outside retest 2026-09-26). The result now names the unused path in an
|
|
143
143
|
// info check. The case of the path is kept, and the query and fragment are never returned.
|
|
144
|
-
// Mirrors worker.
|
|
144
|
+
// Mirrors worker.ts enteredPath() (v3.176.0).
|
|
145
145
|
export function enteredPath(raw) {
|
|
146
146
|
let s = String(raw || "").trim();
|
|
147
147
|
if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(s))
|
|
@@ -787,6 +787,71 @@ function h2Lines(lines, fenced) {
|
|
|
787
787
|
}
|
|
788
788
|
return { h2, under };
|
|
789
789
|
}
|
|
790
|
+
// Code is not markup (Tek-730, 2026-10-31). Before the HTML check reads the file, every character
|
|
791
|
+
// of an inline code span and every backslash-escaped angle bracket is blanked, so
|
|
792
|
+
// `https://fal.ai/models/<endpoint-id>/llms.txt`, `submit_<form>_form` and an escaped
|
|
793
|
+
// \<node-name\> no longer read as tags. The text it receives is the prose the links check also
|
|
794
|
+
// reads, with fenced lines already blanked, so fenced code is not markup either. Line breaks stay,
|
|
795
|
+
// so a tag split over two lines keeps its shape. The span rule is codeSpanMask's, which is
|
|
796
|
+
// CommonMark's: an unclosed backtick run, or a pair that crosses a block boundary, is literal text.
|
|
797
|
+
// A real tag, a closing tag or a comment start in prose still warns, and an autolink is still not
|
|
798
|
+
// a tag. The package turva-llms-txt-validator mirrors this from 0.5.0.
|
|
799
|
+
function blankCodeForHtml(prose) {
|
|
800
|
+
const mask = codeSpanMask(prose);
|
|
801
|
+
const out = [];
|
|
802
|
+
for (let i = 0; i < prose.length; i++) {
|
|
803
|
+
const c = prose[i];
|
|
804
|
+
out.push(c !== "\n" && (mask[i] === 1 || ((c === "<" || c === ">") && isEscaped(prose, i))) ? " " : c);
|
|
805
|
+
}
|
|
806
|
+
return out.join("");
|
|
807
|
+
}
|
|
808
|
+
// List lines that look like a link entry and are not one (Tek-730, 2026-10-31). Two measured
|
|
809
|
+
// shapes: an entry whose destination is not closed, "- [Name](https://x.example/a.md: notes)",
|
|
810
|
+
// which holds a space and so is no CommonMark link, and an entry whose marker is an en dash, an
|
|
811
|
+
// em dash or a bullet, which is no Markdown list marker. Both read as links to a person and are
|
|
812
|
+
// invisible to the parser, so the links check counted the file as fine while an agent skipped the
|
|
813
|
+
// entry. Only lines outside fences and under an H2 are read. A line counts when it opens, after
|
|
814
|
+
// optional indentation, with a list marker (a hyphen, an asterisk, a plus or a number with a
|
|
815
|
+
// period or a parenthesis) or one of the three look-alike markers, then white space and "[", and
|
|
816
|
+
// no link that collectLinks found starts at that "[". A line with one of the three look-alike
|
|
817
|
+
// 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.
|
|
819
|
+
function unparsedLinkEntries(lines, fenced, linkAt) {
|
|
820
|
+
const hits = [];
|
|
821
|
+
const h2 = h2Lines(lines, fenced).h2;
|
|
822
|
+
let inH2 = false, offset = 0;
|
|
823
|
+
for (let i = 0; i < lines.length; i++) {
|
|
824
|
+
const l = lines[i];
|
|
825
|
+
const start = offset;
|
|
826
|
+
offset += (fenced[i] ? 0 : l.length) + 1;
|
|
827
|
+
if (fenced[i])
|
|
828
|
+
continue;
|
|
829
|
+
if (h2[i]) {
|
|
830
|
+
inH2 = true;
|
|
831
|
+
continue;
|
|
832
|
+
}
|
|
833
|
+
if (/^ {0,3}#(?:[ \t]|$)/.test(l)) {
|
|
834
|
+
inH2 = false;
|
|
835
|
+
continue;
|
|
836
|
+
}
|
|
837
|
+
if (!inH2)
|
|
838
|
+
continue;
|
|
839
|
+
const m = /^[ \t]*(?:[-*+]|\d{1,9}[.)]|[\u2013\u2014\u2022])[ \t]+\[/.exec(l);
|
|
840
|
+
if (!m)
|
|
841
|
+
continue;
|
|
842
|
+
const alt = /^[ \t]*[\u2013\u2014\u2022]/.test(l);
|
|
843
|
+
const bracketAt = m[0].length - 1;
|
|
844
|
+
if (/^\[[ xX]\](?:[ \t]|$)/.test(l.slice(bracketAt)))
|
|
845
|
+
continue;
|
|
846
|
+
if (alt || !linkAt.has(start + bracketAt))
|
|
847
|
+
hits.push(i + 1);
|
|
848
|
+
}
|
|
849
|
+
return hits;
|
|
850
|
+
}
|
|
851
|
+
function unparsedEntriesNote(hits) {
|
|
852
|
+
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" : "") + ")";
|
|
854
|
+
}
|
|
790
855
|
// The text of an ATX H1, or null when the line is not one. One to three leading spaces, a
|
|
791
856
|
// single "#", then a space, a tab or the end of the line. A closing run of "#" preceded by a
|
|
792
857
|
// space or a tab is not part of the title, and the title is what remains once both ends are
|
|
@@ -850,7 +915,7 @@ export function validateLlmsTxt(f) {
|
|
|
850
915
|
add("http-status", "fail", "File exists at /llms.txt", "expected HTTP 200, got " + f.status);
|
|
851
916
|
return checks;
|
|
852
917
|
}
|
|
853
|
-
// An accepted redirect is shown masked as well (round 19, K7-2, mirrored from worker.
|
|
918
|
+
// An accepted redirect is shown masked as well (round 19, K7-2, mirrored from worker.ts
|
|
854
919
|
// v3.164.0): a query value or a fragment in a same-host Location used to reach this
|
|
855
920
|
// detail as sent. An input with redirectedFrom and no finalUrl, which fetchLlmsTxt never returns but a
|
|
856
921
|
// caller of this function can pass, names the address it was redirected from alone instead of ending
|
|
@@ -906,7 +971,7 @@ export function validateLlmsTxt(f) {
|
|
|
906
971
|
// Read the same way as the H1 check and the "late" blockquote search below: at most three
|
|
907
972
|
// leading spaces, per CommonMark. A trim-first prefix test used to erase the difference, so
|
|
908
973
|
// a four-space or tab-indented code block right after the title passed as the summary until
|
|
909
|
-
// 2026-09-27 (Tek-496, mirrored from worker.
|
|
974
|
+
// 2026-09-27 (Tek-496, mirrored from worker.ts).
|
|
910
975
|
// A blockquote marker is 0-3 leading spaces plus ">", optionally followed by one space that
|
|
911
976
|
// is then part of the marker and not the content; CommonMark reads ">Summary" and a tab the
|
|
912
977
|
// same way, and four or more leading spaces stay indented code, not a blockquote (outside
|
|
@@ -930,7 +995,7 @@ export function validateLlmsTxt(f) {
|
|
|
930
995
|
}
|
|
931
996
|
else {
|
|
932
997
|
// A blockquote further down, before the first H2, is a summary in the wrong place and not a
|
|
933
|
-
// missing one, and the detail says which (outside retest 2026-09-26, mirrored from worker.
|
|
998
|
+
// missing one, and the detail says which (outside retest 2026-09-26, mirrored from worker.ts
|
|
934
999
|
// v3.176.0). The status is warn either way, because the format places the summary directly
|
|
935
1000
|
// after the title.
|
|
936
1001
|
const fence = fenceMask(lines);
|
|
@@ -1129,6 +1194,13 @@ export function validateLlmsTxt(f) {
|
|
|
1129
1194
|
const hostless = named.length - absolute - relativeCount;
|
|
1130
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" : "") + "; absolute URLs travel better when the file is read out of context");
|
|
1131
1196
|
}
|
|
1197
|
+
// A list line that looks like a link entry but is not one (Tek-730) turns the links check to a warn.
|
|
1198
|
+
const lookalikes = unparsedLinkEntries(lines, fenced, new Set(proseLinks.map((m) => m.at)));
|
|
1199
|
+
if (lookalikes.length > 0) {
|
|
1200
|
+
const lk = checks[checks.length - 1];
|
|
1201
|
+
lk.status = "warn";
|
|
1202
|
+
lk.detail += unparsedEntriesNote(lookalikes);
|
|
1203
|
+
}
|
|
1132
1204
|
if (f.truncated) {
|
|
1133
1205
|
add("size", "warn", "Small enough to be cheap to read", "over 256 KB, read truncated");
|
|
1134
1206
|
}
|
|
@@ -1145,8 +1217,10 @@ export function validateLlmsTxt(f) {
|
|
|
1145
1217
|
// operator such as the "+" in "a <b + c > d" does not. The tag name itself is ASCII. An unquoted
|
|
1146
1218
|
// value may not start with a quote, which keeps the quoted and the unquoted form from matching
|
|
1147
1219
|
// the same text, so the scan stays linear. A tag still open at the end of the file, as in
|
|
1148
|
-
// '<div class="x"', has no closing ">" and does not warn.
|
|
1149
|
-
|
|
1220
|
+
// '<div class="x"', has no closing ">" and does not warn. Code is blanked first (Tek-730): a tag-like
|
|
1221
|
+
// string inside an inline code span, a fenced block or after a backslash is not markup.
|
|
1222
|
+
const htmlScan = blankCodeForHtml(proseText);
|
|
1223
|
+
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)) {
|
|
1150
1224
|
add("no-html", "warn", "No HTML markup in the file", "HTML tags found; llms.txt should be plain markdown");
|
|
1151
1225
|
}
|
|
1152
1226
|
else {
|
|
@@ -2244,17 +2318,17 @@ export async function validateHost(input, opts = {}) {
|
|
|
2244
2318
|
discovery = validateV2Discovery(null, "the home page could not be read, so this was not measured");
|
|
2245
2319
|
}
|
|
2246
2320
|
const checks = validateLlmsTxt(fetched).concat(discovery);
|
|
2247
|
-
// A path in the typed address is not used, and the result says so first (mirrored from worker.
|
|
2321
|
+
// A path in the typed address is not used, and the result says so first (mirrored from worker.ts
|
|
2248
2322
|
// v3.176.0). Information moves no summary and no exit code.
|
|
2249
2323
|
const unusedPath = enteredPath(input);
|
|
2250
2324
|
// The typed path goes on its own field with the same 120 character cut it always had (VREG,
|
|
2251
|
-
// round 3 Tek-542, mirrored from worker.
|
|
2325
|
+
// round 3 Tek-542, mirrored from worker.ts decision 19, Tek-526), instead of being built into
|
|
2252
2326
|
// the sentence, so a JSON caller reads the raw value from one field instead of parsing it
|
|
2253
2327
|
// back out of a message meant for people.
|
|
2254
2328
|
if (unusedPath)
|
|
2255
2329
|
checks.unshift({ id: "input-path", status: "info", label: "Path in the address you entered", value: cut(unusedPath, 120), detail: "This path is not used, because the validator always reads /llms.txt at the root of the host." });
|
|
2256
2330
|
// Text quoted from the fetched file leaves without bidirectional controls (round 19,
|
|
2257
|
-
// V6-U1, mirrored from worker.
|
|
2331
|
+
// V6-U1, mirrored from worker.ts v3.164.0): a site's own H1 or summary could otherwise
|
|
2258
2332
|
// read in another order here than in the file itself.
|
|
2259
2333
|
const stripped = checks.map((c) => (typeof c.detail === "string" ? { ...c, detail: stripControls(stripBidi(c.detail)) } : c));
|
|
2260
2334
|
return { target: "https://" + host + "/llms.txt", summary: summarizeChecks(stripped), checks: stripped };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "turva-llms-txt-validator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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",
|