turva-llms-txt-validator 0.9.0 → 0.9.2
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 +8 -8
- package/dist/bin/cli.js +2 -2
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +153 -63
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -88,13 +88,13 @@ The validator removes C0 and C1 control characters, bidirectional controls and i
|
|
|
88
88
|
|
|
89
89
|
With `--json`, an invalid domain or a failed fetch returns `{ "error": "...", "target": "..." }` and exits with code `2`. A network error adds `code` when the error carries one, 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`. `--help` and `--version` win over argument errors, also with `--json`, and exit with code `0`. An unknown option is named by its dashes and the letters, digits and dashes after them, and the rest of the argument is not shown, so a target typed with a leading dash, as in `-u:secret@example.com`, gives `unknown option "-u" (the rest of the argument is not shown)`.
|
|
90
90
|
|
|
91
|
-
In an error report the `target` is the address given on the command line. When it parses as a URL with a host, the user name and password are removed and each query value becomes `***`. Other values follow these cases:
|
|
91
|
+
In an error report the `target` is the address given on the command line. A value that starts with a single slash and still holds an `@` after masking, such as `/user:secret@example.com`, is shown as `/***`, because the text is your own argument and may be user information. When it parses as a URL with a host, the user name and password are removed and each query value becomes `***`. Other values follow these cases:
|
|
92
92
|
|
|
93
93
|
- In a value such as `user:secret@example.com` or `example.org:8443#a@b`, the part before the colon reads as a URL scheme and no authority follows it, so only `//***` is shown.
|
|
94
94
|
- A value with no scheme and no slash is read as user information when a colon comes before its last `@` and before its first `?` or `#`. So `user_name:secret@example.com` and `user_name:se#cret@example.com` are shown as `***@example.com`. A backslash counts as part of the user name, as in a Windows domain account, so `CORP\erik:se#cret@example.com` is shown as `***@example.com` too. The same reading holds when such a value is a relative redirect target that is resolved against the request address, so the password does not come back in the path of the shown address. When the validator follows such a redirect, the address it reached is shown as its scheme, its host and `/***`, as in `https://example.com/***`, and so is an address reached after it while its `Location` keeps part of the earlier path or query. An address whose `Location` keeps none of it, such as an absolute address or a path from the root, is shown as usual. There a `?` or `#` before the last `@` shows only `***`, because the text after it could also be read as a query or a fragment. When a `?` or `#` comes before the colon, as in `user?x:secret@example.com`, the text from that character on is masked or cut, so the part before it is shown and the password is not.
|
|
95
95
|
- Without that colon, as in `path@2x.png` or an e-mail address, the value is shown as given and holds no password.
|
|
96
|
-
- An address that holds an `@` shows only `***`, with the scheme in front when a slash follows its colon and with no host, when a URL parser and a person would read it differently. That covers a backslash, a `?` or a `#` before the `@` and before any `/`, and a start that is not exactly a scheme, two slashes and a character other than a slash. `https://user:pa?ss@example.com/`, `https://example.org?e=a@b.com` and `https:///host?e=a@b.com` are shown as `https://***`. `user:secret@host.example://dd`, where no slash follows the scheme colon, is shown as `//***`. The same holds for a word that a URL parser refuses as a scheme when a slash or a backslash follows its colon, as in `my_app:/user:secret@host`, and for an address that the parser refuses when a `?` or `#` comes before its last `@`, as in `https://user:pa/ss?secret@example.com`. A redirect to such an address is reported as "a different host that this report does not name". A `/` before the `@` makes it a path, so `https://user:12/ss@example.com/` is the host `user` with the port 12 and the path `/ss@example.com/`, and it is shown as written. A relative reference such as
|
|
97
|
-
- Spaces, C0 control characters, Unicode spaces and invisible characters such as U+200B at either end of a value are removed before it is read, so a value that starts with U+2003 before `https:/user:secret@example.com` is read as `https:/user:secret@example.com` and shown as `https://***`. The edge set follows Unicode classes: spaces, control characters, format characters and default-ignorable characters. A `Location` header reaches the validator as bytes that the platform reads as Latin-1. When those bytes form valid UTF-8, the validator reads them as UTF-8 for masking,
|
|
96
|
+
- An address that holds an `@` shows only `***`, with the scheme in front when a slash follows its colon and with no host, when a URL parser and a person would read it differently. That covers a backslash, a `?` or a `#` before the `@` and before any `/`, and a start that is not exactly a scheme, two slashes and a character other than a slash. `https://user:pa?ss@example.com/`, `https://example.org?e=a@b.com` and `https:///host?e=a@b.com` are shown as `https://***`. `user:secret@host.example://dd`, where no slash follows the scheme colon, is shown as `//***`. The same holds for a word that a URL parser refuses as a scheme when a slash or a backslash follows its colon, as in `my_app:/user:secret@host`, and for an address that the parser refuses when a `?` or `#` comes before its last `@`, as in `https://user:pa/ss?secret@example.com`. A redirect to such an address is reported as "a different host that this report does not name". A `/` before the `@` makes it a path, so `https://user:12/ss@example.com/` is the host `user` with the port 12 and the path `/ss@example.com/`, and it is shown as written. A relative reference such as `docs/@name` is shown as given, and one that starts with a single slash, such as `/a@b`, is shown as `/***`.
|
|
97
|
+
- Spaces, C0 control characters, Unicode spaces and invisible characters such as U+200B at either end of a value are removed before it is read, so a value that starts with U+2003 before `https:/user:secret@example.com` is read as `https:/user:secret@example.com` and shown as `https://***`. The edge set follows Unicode classes: spaces, control characters, format characters and default-ignorable characters, plus U+0085, U+180E, U+200B, U+2800 and U+FFFD. A `Location` header reaches the validator as bytes that the platform reads as Latin-1. When those bytes form valid UTF-8, the validator reads them as UTF-8 for masking and for resolving the address it follows. The bytes of `/caf` followed by C3 A9 are requested as `/caf%C3%A9`. Because the bytes are read as UTF-8 for masking, a U+3000 at the start of a `Location` is removed in its real form and in its byte form. A byte that is not valid UTF-8 stays as it arrived between the first and the last printable ASCII character. Before the first and after the last one it counts as an edge character. A followed address with such a byte at its edge is shown as `https://host/***`, and the address shown with a redirect refused as one hop too many leaves the byte out.
|
|
98
98
|
- Text before `://` that a URL parser does not accept as a scheme, such as `my_app://user:secret@host/p`, `1app://user:secret@host/p` or `ht tps://user:secret@host/p`, is masked from the text: everything up to the last `@` is shown as `***`.
|
|
99
99
|
|
|
100
100
|
## What it checks
|
|
@@ -135,7 +135,7 @@ Links are read the way CommonMark reads them for the forms listed here.
|
|
|
135
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.
|
|
136
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: `#  `, `` [` `](https://example.org/a) ``, `>>` and `> >`. A line with only a no-break or ideographic space is not a blank line.
|
|
137
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.
|
|
138
|
-
-
|
|
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.
|
|
139
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`.
|
|
140
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.
|
|
141
141
|
|
|
@@ -156,7 +156,7 @@ These checks are labelled **v2** in the output. They look for link relations in
|
|
|
156
156
|
|
|
157
157
|
| # | Check | Pass condition | Otherwise |
|
|
158
158
|
| --- | --- | --- | --- |
|
|
159
|
-
| 9 | Home page points to its llms.txt | `rel="describedby"` has a
|
|
159
|
+
| 9 | Home page points to its llms.txt | `rel="describedby"` has a target that is not empty, not made only of white space or invisible characters and not a bare fragment such as `#top` | `info` |
|
|
160
160
|
| 10 | Home page points to a Markdown version | `rel="alternate"` has media type `text/markdown` and a non-empty target | `info` |
|
|
161
161
|
|
|
162
162
|
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. Inside a script, `<!-->` and `<!--->` end the comment escape at once, as the HTML tokenizer reads them, and a `<template>` inside `<svg>` or `<math>` is an ordinary element that opens no template level. Until 0.8.0 both shapes made the scan skip a relation that the parser puts in the head, or read one that it moves into the body.
|
|
@@ -232,7 +232,7 @@ The default validation requests two documents: `https://<host>/llms.txt` and `ht
|
|
|
232
232
|
- Timeout: eight seconds per document, shared across its redirect chain.
|
|
233
233
|
- Read limit: 256 KiB, which is 262,144 bytes, per response by default. A file cut there gets the size note "over 256 KiB, read truncated". A library caller can change the limit, see the options above.
|
|
234
234
|
- 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. A result names a redirect target in the `location` field, in the sentences about another host and an unsupported target, and in the address a followed redirect reached. The sentences about too many redirects and an unusable `Location` name no target.
|
|
235
|
-
- 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. The message names the host that a URL parser reads from such an address only when that host is the text right after the last `@`, or when the address holds no `@`. So `//user?@example.com`, where the parser reads the user name as the host, names no host. The address `//user.example?@example.com` is accepted as the host `user.example`, because a URL parser ends the host at the `?`. It requests that host and shows it as the target. One trailing dot on the host you give, as in `example.com.`, is removed first. Redirect targets are checked too, and one trailing dot on a redirect target is removed the same way.
|
|
235
|
+
- 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. Any other address is repeated with control, bidirectional and invisible characters removed. The message names the host that a URL parser reads from such an address only when that host is the whole text right after the last `@`, up to a port, a path, a query or a fragment, or when the address holds no `@`. So `//user?@example.com`, where the parser reads the user name as the host, names no host. The address `//user.example?@example.com` is accepted as the host `user.example`, because a URL parser ends the host at the `?`. It requests that host and shows it as the target. One trailing dot on the host you give, as in `example.com.`, is removed first. Redirect targets are checked too, and one trailing dot on a redirect target is removed the same way.
|
|
236
236
|
|
|
237
237
|
**DNS resolution is not checked for private addresses.** A syntactically public domain can resolve to a private IP, so if you expose this package through a service that accepts untrusted domains, enforce private-address restrictions at the network layer. Local and CI runs use their own network policy. The hosted validator runs on the Cloudflare edge.
|
|
238
238
|
|
|
@@ -255,12 +255,12 @@ The strict type check found two inputs that could leave `undefined` in a check's
|
|
|
255
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.
|
|
256
256
|
|
|
257
257
|
```sh
|
|
258
|
-
mkdir verify-llms && cd verify-llms && npm init -y && npm install turva-llms-txt-validator@0.9.
|
|
258
|
+
mkdir verify-llms && cd verify-llms && npm init -y && npm install turva-llms-txt-validator@0.9.2 --ignore-scripts && npm audit signatures
|
|
259
259
|
```
|
|
260
260
|
|
|
261
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.
|
|
262
262
|
|
|
263
|
-
Tag `v0.9.
|
|
263
|
+
Tag `v0.9.2` must point at that same commit, and `gh api repos/turva-dev/llms-txt-validator/commits/v0.9.2 --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.
|
|
264
264
|
|
|
265
265
|
## Development
|
|
266
266
|
|
package/dist/bin/cli.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// curl -H "Accept: application/json" "https://turva.dev/llms-txt-validator?url=example.com"
|
|
8
8
|
import { readFileSync } from "node:fs";
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
|
-
import { validateHost, stripControls,
|
|
10
|
+
import { validateHost, stripControls, maskTypedTarget } from "../src/index.js";
|
|
11
11
|
const USAGE = [
|
|
12
12
|
"usage: llms-txt-validate <domain-or-url> [--json] [--strict]",
|
|
13
13
|
" --json print the result as JSON (same shape as the hosted validator for a completed validation)",
|
|
@@ -97,7 +97,7 @@ catch (err) {
|
|
|
97
97
|
// a password or a query value typed into the command line is never echoed back.
|
|
98
98
|
const code = (err && err.cause && err.cause.code) || (err && err.code);
|
|
99
99
|
if (json) {
|
|
100
|
-
const report = { error: message, target:
|
|
100
|
+
const report = { error: message, target: maskTypedTarget(targets[0]) };
|
|
101
101
|
if (code)
|
|
102
102
|
report.code = stripControls(String(code));
|
|
103
103
|
console.log(JSON.stringify(report, null, 2));
|
package/dist/src/index.d.ts
CHANGED
|
@@ -52,6 +52,7 @@ export declare function stripBidi(s: unknown): string;
|
|
|
52
52
|
export declare function stripControls(s: unknown): string;
|
|
53
53
|
export declare function normalizeHostInput(raw: unknown): string | null;
|
|
54
54
|
export declare function enteredPath(raw: unknown): string;
|
|
55
|
+
export declare function maskTypedTarget(raw: string): string;
|
|
55
56
|
export declare function isValidPublicHost(host: string | null | undefined): boolean;
|
|
56
57
|
export declare function fetchLlmsTxt(host: string, opts?: FetchOptions): Promise<FetchedLlmsTxt | FetchRedirect>;
|
|
57
58
|
export declare function validateLlmsTxt(f: LlmsTxtInput): LlmsCheck[];
|
package/dist/src/index.js
CHANGED
|
@@ -431,7 +431,49 @@ export function enteredPath(raw) {
|
|
|
431
431
|
function typedHostEcho(raw) {
|
|
432
432
|
const host = normalizeHostInput(raw) || "";
|
|
433
433
|
const at = raw.lastIndexOf("@");
|
|
434
|
-
|
|
434
|
+
// The text after the last @ has to be the parsed host in full: the host is followed by the end of the text, a port, a path,
|
|
435
|
+
// a query, a fragment or a backslash, once with one trailing dot in between. A bare prefix match named the user name of
|
|
436
|
+
// "//admin?@admin.example.com" as "admin" (K12 of the Antigravity review, 2026-12-01). Mirrors worker.ts echoHostEnds().
|
|
437
|
+
return host && (at < 0 || echoHostEnds(raw.slice(at + 1).toLowerCase(), host)) ? host : "";
|
|
438
|
+
}
|
|
439
|
+
function echoHostEnds(rest, host) {
|
|
440
|
+
if (!rest.startsWith(host))
|
|
441
|
+
return false;
|
|
442
|
+
let next = rest.slice(host.length);
|
|
443
|
+
if (next.startsWith("."))
|
|
444
|
+
next = next.slice(1);
|
|
445
|
+
return next === "" || /^[:\/?#\\]/.test(next);
|
|
446
|
+
}
|
|
447
|
+
// A Location value reaches this code as one code unit per byte. When those bytes are valid UTF-8 text with at least one
|
|
448
|
+
// non-ASCII byte, the address is read from the text, as a browser does and as markdown-parity-check has done since 0.2.43:
|
|
449
|
+
// "/caf" + the bytes C3 A9 resolves to /caf%C3%A9 and not to the double-encoded /caf%C3%83%C2%A9 (K13 of the Antigravity
|
|
450
|
+
// review, 2026-12-01). Any other value is returned as it arrived. Mirrors worker.ts locationAsUtf8().
|
|
451
|
+
function locationAsUtf8(raw) {
|
|
452
|
+
let high = false;
|
|
453
|
+
for (let i = 0; i < raw.length; i++) {
|
|
454
|
+
const c = raw.charCodeAt(i);
|
|
455
|
+
if (c > 0xff)
|
|
456
|
+
return raw;
|
|
457
|
+
if (c > 0x7f)
|
|
458
|
+
high = true;
|
|
459
|
+
}
|
|
460
|
+
if (!high)
|
|
461
|
+
return raw;
|
|
462
|
+
try {
|
|
463
|
+
return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(Uint8Array.from(raw, (ch) => ch.charCodeAt(0)));
|
|
464
|
+
}
|
|
465
|
+
catch {
|
|
466
|
+
return raw;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
// The address a --json error report names as its target (K11 of the Antigravity review, 2026-12-01). It is the address
|
|
470
|
+
// typed on the command line, masked like every address the tool prints. A relative reference that still holds an "@" after
|
|
471
|
+
// masking, such as "/user:secret@host", is shown as "/***": maskLocation keeps it as a path for a Location header
|
|
472
|
+
// (decision Tek-898), but here the text is the user's own argument and may be user information. Every other form keeps
|
|
473
|
+
// the masked text maskLocation gives.
|
|
474
|
+
export function maskTypedTarget(raw) {
|
|
475
|
+
const shown = stripInvisible(stripControls(stripBidi(maskLocation(raw))));
|
|
476
|
+
return shown.includes("@") && /^\/(?!\/)/.test(shown) ? "/***" : shown;
|
|
435
477
|
}
|
|
436
478
|
export function isValidPublicHost(host) {
|
|
437
479
|
if (!host || host.length > 253)
|
|
@@ -533,13 +575,14 @@ export async function fetchLlmsTxt(host, opts = {}) {
|
|
|
533
575
|
catch { /* the verdict below is the answer */ }
|
|
534
576
|
const loc = res.headers.get("location") || "";
|
|
535
577
|
const shown = headerText(loc);
|
|
578
|
+
const locUrl = locationAsUtf8(loc);
|
|
536
579
|
if (!loc)
|
|
537
580
|
return { redirect: true, reason: "no-location", status: res.status, location: "" };
|
|
538
581
|
if (hop >= 4)
|
|
539
582
|
return { redirect: true, reason: "too-many", status: res.status, location: cut(maskLocation(shown, hidden ? undefined : url), 120) };
|
|
540
583
|
let next;
|
|
541
584
|
try {
|
|
542
|
-
next = new URL(
|
|
585
|
+
next = new URL(locUrl, url);
|
|
543
586
|
}
|
|
544
587
|
catch {
|
|
545
588
|
return { redirect: true, reason: "bad-location", status: res.status, location: cut(maskLocation(shown, hidden ? undefined : url), 120) };
|
|
@@ -568,7 +611,7 @@ export async function fetchLlmsTxt(host, opts = {}) {
|
|
|
568
611
|
// marked address did not reach it. Bases one segment deep let ".." and "../x" clear the mark while the hidden
|
|
569
612
|
// segments stayed (F1 of the seventh check, 2026-11-22).
|
|
570
613
|
const inheritsBase = (() => { const u0 = new URL(url); let n = 0; const alt = u0.origin + u0.pathname.replace(/[^\/]+/g, () => "zz9q" + n++) + (u0.search ? "?zz9q" : ""); try {
|
|
571
|
-
return new URL(
|
|
614
|
+
return new URL(locUrl, url).href !== new URL(locUrl, alt).href;
|
|
572
615
|
}
|
|
573
616
|
catch {
|
|
574
617
|
return true;
|
|
@@ -592,7 +635,11 @@ export async function fetchLlmsTxt(host, opts = {}) {
|
|
|
592
635
|
truncated = true;
|
|
593
636
|
chunks.push(value.slice(0, value.length - (bytes - cap)));
|
|
594
637
|
bytes = cap;
|
|
595
|
-
|
|
638
|
+
// A cancel that throws must not turn a read that already hit the cap into a network error (K45 of the Antigravity review).
|
|
639
|
+
try {
|
|
640
|
+
await reader.cancel();
|
|
641
|
+
}
|
|
642
|
+
catch { /* the cap is the answer */ }
|
|
596
643
|
break;
|
|
597
644
|
}
|
|
598
645
|
chunks.push(value);
|
|
@@ -941,7 +988,7 @@ function collectLinkDefinitions(text, lineBlocks, defAt) {
|
|
|
941
988
|
offset += l.length + 1;
|
|
942
989
|
}
|
|
943
990
|
}
|
|
944
|
-
let prevDef = false, prevQuote = 0, prevInner = "";
|
|
991
|
+
let prevDef = false, prevQuote = 0, prevInner = "", titleLine = -1;
|
|
945
992
|
for (let i = 0; i < lines.length; i++) {
|
|
946
993
|
const line = lines[i];
|
|
947
994
|
const qm = quoteMarkers(line);
|
|
@@ -955,6 +1002,12 @@ function collectLinkDefinitions(text, lineBlocks, defAt) {
|
|
|
955
1002
|
prevDef = false;
|
|
956
1003
|
prevQuote = qm.quote;
|
|
957
1004
|
prevInner = inner;
|
|
1005
|
+
// The title of the definition above, written alone on this line, belongs to that definition, so the line after it still
|
|
1006
|
+
// opens a definition (K18a of the Antigravity review, 2026-12-01).
|
|
1007
|
+
if (i === titleLine) {
|
|
1008
|
+
prevDef = true;
|
|
1009
|
+
continue;
|
|
1010
|
+
}
|
|
958
1011
|
let opens;
|
|
959
1012
|
if (i === 0 || wasDef || qm.quote > before)
|
|
960
1013
|
opens = true;
|
|
@@ -979,6 +1032,12 @@ function collectLinkDefinitions(text, lineBlocks, defAt) {
|
|
|
979
1032
|
if (!label)
|
|
980
1033
|
continue;
|
|
981
1034
|
prevDef = true;
|
|
1035
|
+
if (!m[3] && i + 1 < lines.length) {
|
|
1036
|
+
const nextLine = lines[i + 1];
|
|
1037
|
+
const nextMarks = quoteMarkers(nextLine);
|
|
1038
|
+
if (/^[ \t]*(?:"[^"\n]*"|'[^'\n]*'|\([^()\n]*\))[ \t]*$/.test(nextLine.slice(nextMarks.at)) && nextMarks.quote === qm.quote)
|
|
1039
|
+
titleLine = i + 1;
|
|
1040
|
+
}
|
|
982
1041
|
if (defAt)
|
|
983
1042
|
defAt.add(bracketAt);
|
|
984
1043
|
if (defs.has(label))
|
|
@@ -993,7 +1052,8 @@ function collectLinkDefinitions(text, lineBlocks, defAt) {
|
|
|
993
1052
|
// 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
1053
|
// 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
1054
|
// with an empty target (S3, LV-07). An image nested in the link text, such as "[a ](y)", is link content and is skipped
|
|
996
|
-
// whole, and the alt text of an image holds no link (S3, LV-08).
|
|
1055
|
+
// 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
|
|
1056
|
+
// closeOf paired with its "[", but a link whose text holds another link is no link, because CommonMark
|
|
997
1057
|
// 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
1058
|
// full or collapsed reference link, "[text][label]" or "[text][]", resolves against collectLinkDefinitions; an unresolved label
|
|
999
1059
|
// 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 +1219,6 @@ function collectLinks(text, defs, lineBlocks) {
|
|
|
1159
1219
|
return { target: text.slice(k, e), end: e };
|
|
1160
1220
|
return e < text.length ? afterTarget(text.slice(k, e), e) : null;
|
|
1161
1221
|
};
|
|
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
1222
|
// A definition is decoded once, however many references use it: a long destination used by many labels would otherwise be
|
|
1172
1223
|
// decoded again for each of them.
|
|
1173
1224
|
const decoded = new Map();
|
|
@@ -1198,8 +1249,17 @@ function collectLinks(text, defs, lineBlocks) {
|
|
|
1198
1249
|
stack.push(k);
|
|
1199
1250
|
else if (c === "]") {
|
|
1200
1251
|
const o = stack.pop();
|
|
1201
|
-
if (o !== undefined)
|
|
1252
|
+
if (o !== undefined) {
|
|
1202
1253
|
pairs[o] = k;
|
|
1254
|
+
// The destination and the title of an inline link or image are no bracket text: a "]" in "" or a
|
|
1255
|
+
// "[" in "(x.png?x=[1)" would otherwise close or open a pair of the outer link text (K14 of the Antigravity review,
|
|
1256
|
+
// 2026-12-01). A target that does not parse is left as it is.
|
|
1257
|
+
if (text[k + 1] === "(") {
|
|
1258
|
+
const t = readTarget(k + 2);
|
|
1259
|
+
if (t)
|
|
1260
|
+
k = t.end;
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1203
1263
|
}
|
|
1204
1264
|
else if (c === "\n" && blankAt(k))
|
|
1205
1265
|
stack.length = 0;
|
|
@@ -1253,43 +1313,20 @@ function collectLinks(text, defs, lineBlocks) {
|
|
|
1253
1313
|
}
|
|
1254
1314
|
return i - lineStart <= 64 && DEF_HEAD.test(text.slice(lineStart, i));
|
|
1255
1315
|
};
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
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
|
-
}
|
|
1316
|
+
// The brackets that closeOf paired and whose "]" has not been reached yet, innermost last. The text of a link may hold
|
|
1317
|
+
// balanced brackets ("[rewrite Optional[T] to T](x)") and backslash-escaped ones, so a label ends at the "]" that closeOf
|
|
1318
|
+
// paired with its "[", and the link is read there, once everything inside has been read. child records that another "[" opened
|
|
1319
|
+
// inside, which keeps a shortcut or collapsed reference from taking a label with brackets in it. Links do not nest: when a
|
|
1320
|
+
// 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).
|
|
1321
|
+
const pending = [];
|
|
1322
|
+
// Reads what follows the "]" at j of the link text opened at i: an inline target, a full or collapsed reference, or a
|
|
1323
|
+
// shortcut reference. Returns the index the scan resumes from, or j when no link starts at i.
|
|
1324
|
+
const closeLink = (i, j, plain) => {
|
|
1287
1325
|
if (text[j + 1] === "(") {
|
|
1288
1326
|
const t = readTarget(j + 2);
|
|
1289
1327
|
if (t) {
|
|
1290
1328
|
out.push({ name: text.slice(i + 1, j), target: decodeDestination(t.target), at: i });
|
|
1291
|
-
|
|
1292
|
-
continue;
|
|
1329
|
+
return t.end;
|
|
1293
1330
|
}
|
|
1294
1331
|
// A target that does not parse leaves "[text]" to be read as a shortcut reference below (S3, LV-11).
|
|
1295
1332
|
}
|
|
@@ -1299,16 +1336,17 @@ function collectLinks(text, defs, lineBlocks) {
|
|
|
1299
1336
|
m += text[m] === "\\" ? 2 : 1;
|
|
1300
1337
|
if (m < text.length && text[m] === "]") {
|
|
1301
1338
|
const rawLabel = text.slice(j + 2, m);
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1339
|
+
if (rawLabel !== "" || plain) {
|
|
1340
|
+
const label = normalizeLinkLabel(rawLabel === "" ? text.slice(i + 1, j) : rawLabel);
|
|
1341
|
+
const dest = label ? refs.get(label) : undefined;
|
|
1342
|
+
if (dest !== undefined) {
|
|
1343
|
+
out.push({ name: text.slice(i + 1, j), target: decodeRef(label, dest), at: i });
|
|
1344
|
+
return m;
|
|
1345
|
+
}
|
|
1308
1346
|
}
|
|
1309
1347
|
}
|
|
1310
1348
|
}
|
|
1311
|
-
else {
|
|
1349
|
+
else if (plain) {
|
|
1312
1350
|
// A shortcut reference, "[text]" alone with neither "(" nor "[" right after it, resolves
|
|
1313
1351
|
// against a definition using the link text itself as the label (VN2, round 3 Tek-542).
|
|
1314
1352
|
// Checked last, and only here, so it never overrides the full or collapsed reference
|
|
@@ -1318,11 +1356,35 @@ function collectLinks(text, defs, lineBlocks) {
|
|
|
1318
1356
|
const dest = label ? refs.get(label) : undefined;
|
|
1319
1357
|
if (dest !== undefined) {
|
|
1320
1358
|
out.push({ name: text.slice(i + 1, j), target: decodeRef(label, dest), at: i });
|
|
1321
|
-
|
|
1322
|
-
continue;
|
|
1359
|
+
return j;
|
|
1323
1360
|
}
|
|
1324
1361
|
}
|
|
1325
|
-
|
|
1362
|
+
return j;
|
|
1363
|
+
};
|
|
1364
|
+
for (let i = 0; i < text.length; i++) {
|
|
1365
|
+
while (pending.length > 0 && pending[pending.length - 1].close < i)
|
|
1366
|
+
pending.pop();
|
|
1367
|
+
if (pending.length > 0 && pending[pending.length - 1].close === i) {
|
|
1368
|
+
const p = pending.pop();
|
|
1369
|
+
// Nothing found inside the text: the outer bracket pair may be a link.
|
|
1370
|
+
if (out.length === p.outLen)
|
|
1371
|
+
i = closeLink(p.open, i, !p.child);
|
|
1372
|
+
continue;
|
|
1373
|
+
}
|
|
1374
|
+
if (text[i] !== "[" || code[i] || isEscaped(text, i))
|
|
1375
|
+
continue;
|
|
1376
|
+
if (pending.length > 0)
|
|
1377
|
+
pending[pending.length - 1].child = true;
|
|
1378
|
+
if (i > 0 && text[i - 1] === "!" && !isEscaped(text, i - 1)) {
|
|
1379
|
+
const after = skipImage(i);
|
|
1380
|
+
if (after !== null)
|
|
1381
|
+
i = after - 1;
|
|
1382
|
+
continue;
|
|
1383
|
+
}
|
|
1384
|
+
const c = closeOf()[i];
|
|
1385
|
+
if (c >= 0) {
|
|
1386
|
+
pending.push({ open: i, close: c, outLen: out.length, child: false });
|
|
1387
|
+
}
|
|
1326
1388
|
}
|
|
1327
1389
|
return out;
|
|
1328
1390
|
}
|
|
@@ -1726,6 +1788,17 @@ function blankCodeForHtml(prose, lineBlocks) {
|
|
|
1726
1788
|
const c = prose[i];
|
|
1727
1789
|
out.push(c !== "\n" && (mask[i] === 1 || ((c === "<" || c === ">") && isEscaped(prose, i))) ? " " : c);
|
|
1728
1790
|
}
|
|
1791
|
+
// A link destination in angle brackets, "[Guide](<guide (1).md>)" or "[Guide](<api>)", is no HTML tag, and the README
|
|
1792
|
+
// recommends the form (K15 of the Antigravity review, 2026-12-01). Only a destination that is followed by the end of
|
|
1793
|
+
// the link, ")" or a title, is blanked, so "](<b>bold</b>" stays a tag.
|
|
1794
|
+
const angleDestination = /\]\([ \t]*(<[^<>\n]*>)(?=[ \t]*(?:\)|["'(]))/g;
|
|
1795
|
+
for (let m = angleDestination.exec(prose); m; m = angleDestination.exec(prose)) {
|
|
1796
|
+
if (mask[m.index] === 1 || isEscaped(prose, m.index))
|
|
1797
|
+
continue;
|
|
1798
|
+
const s = m.index + m[0].length - m[1].length;
|
|
1799
|
+
for (let k = s; k < s + m[1].length; k++)
|
|
1800
|
+
out[k] = " ";
|
|
1801
|
+
}
|
|
1729
1802
|
return out.join("");
|
|
1730
1803
|
}
|
|
1731
1804
|
// List lines that look like a link entry and are not one (Tek-730, 2026-10-31). Two measured
|
|
@@ -1915,7 +1988,15 @@ export function validateLlmsTxt(f) {
|
|
|
1915
1988
|
else {
|
|
1916
1989
|
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 =)");
|
|
1917
1990
|
}
|
|
1918
|
-
|
|
1991
|
+
let afterIdx = lines.findIndex((l, i) => i > h1End && !isMdBlank(l));
|
|
1992
|
+
// A file whose first line opens a code fence or a raw HTML block has no title, and what stands inside that block is no
|
|
1993
|
+
// summary: the lines of the block are skipped (K17 of the Antigravity review, 2026-12-01).
|
|
1994
|
+
if (firstIdx !== -1 && title === null && !setext) {
|
|
1995
|
+
const startBlocks = readBlocks(lines);
|
|
1996
|
+
const startHtml = htmlBlockLines(lines, startBlocks);
|
|
1997
|
+
if (startBlocks[h1End] < 0 || startHtml[h1End])
|
|
1998
|
+
afterIdx = lines.findIndex((l, i) => i > h1End && !isMdBlank(l) && startBlocks[i] >= 0 && !startHtml[i]);
|
|
1999
|
+
}
|
|
1919
2000
|
const afterH1 = afterIdx === -1 ? "" : lines[afterIdx];
|
|
1920
2001
|
// Read the same way as the H1 check and the "late" blockquote search below: at most three
|
|
1921
2002
|
// leading spaces, per CommonMark. A trim-first prefix test used to erase the difference, so
|
|
@@ -3376,6 +3457,13 @@ function describesOtherResource(anchor, homeUrls) {
|
|
|
3376
3457
|
return false;
|
|
3377
3458
|
} });
|
|
3378
3459
|
}
|
|
3460
|
+
// A relation target that points nowhere names no file: it is empty, holds only white space or characters a reader does not
|
|
3461
|
+
// see (a no-break space from " "), or is a bare fragment, which stays on the page that carries it (K16 of the
|
|
3462
|
+
// Antigravity review, 2026-12-01). Such a target is no relation. Mirrors worker.ts pointsNowhere().
|
|
3463
|
+
function pointsNowhere(href) {
|
|
3464
|
+
const t = trimEnds(href, isUrlEdge);
|
|
3465
|
+
return t === "" || t[0] === "#";
|
|
3466
|
+
}
|
|
3379
3467
|
export function findLinkRelations(html, linkHeader, readCut = false, homeUrls = []) {
|
|
3380
3468
|
const found = { describedby: null, markdown: null };
|
|
3381
3469
|
// Only the head, and only what a parser would put there: a commented-out link element,
|
|
@@ -3407,7 +3495,7 @@ export function findLinkRelations(html, linkHeader, readCut = false, homeUrls =
|
|
|
3407
3495
|
// text/markdown, not anything that starts with it, and a relation without a target is
|
|
3408
3496
|
// not a relation: both passed until 2026-08-29.
|
|
3409
3497
|
const isMarkdown = trimChars(type.split(";")[0], HTTP_WHITESPACE) === "text/markdown";
|
|
3410
|
-
if (!found.describedby && href && rel.includes("describedby"))
|
|
3498
|
+
if (!found.describedby && href && !pointsNowhere(href) && rel.includes("describedby"))
|
|
3411
3499
|
found.describedby = href;
|
|
3412
3500
|
if (!found.markdown && href && rel.includes("alternate") && isMarkdown)
|
|
3413
3501
|
found.markdown = href;
|
|
@@ -3419,7 +3507,7 @@ export function findLinkRelations(html, linkHeader, readCut = false, homeUrls =
|
|
|
3419
3507
|
const rel = trimChars(asciiLower(link.params.rel || ""), HTTP_WHITESPACE).split(/[\t\n\r ]+/);
|
|
3420
3508
|
const type = trimChars(asciiLower(link.params.type || ""), HTTP_WHITESPACE);
|
|
3421
3509
|
const isMarkdownHeader = trimChars(type.split(";")[0], HTTP_WHITESPACE) === "text/markdown";
|
|
3422
|
-
if (!found.describedby && href && rel.includes("describedby"))
|
|
3510
|
+
if (!found.describedby && href && !pointsNowhere(href) && rel.includes("describedby"))
|
|
3423
3511
|
found.describedby = href;
|
|
3424
3512
|
if (!found.markdown && href && rel.includes("alternate") && isMarkdownHeader)
|
|
3425
3513
|
found.markdown = href;
|
|
@@ -3471,7 +3559,9 @@ export async function validateHost(input, opts = {}) {
|
|
|
3471
3559
|
// its first 120 characters into stderr and the --json error (Tek-496). Such an entry is
|
|
3472
3560
|
// named by the host the parser reads from it, or not at all, as the hosted form does.
|
|
3473
3561
|
const raw = String(input ?? "");
|
|
3474
|
-
|
|
3562
|
+
// The text of the error leaves without control, bidirectional or invisible characters, as the text quoted from a file
|
|
3563
|
+
// does (K20 of the Antigravity review, 2026-12-01).
|
|
3564
|
+
const shown = /[@?#]/.test(raw) ? typedHostEcho(raw) : stripInvisible(stripControls(stripBidi(cut(raw, 120))));
|
|
3475
3565
|
throw new Error(shown ? "not a public domain name: " + shown : "not a public domain name");
|
|
3476
3566
|
}
|
|
3477
3567
|
// opts comes from the caller, and path and accept exist for this function's own
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "turva-llms-txt-validator",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
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",
|