rebilder 0.4.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/CHANGELOG.md +8 -0
- package/README.md +34 -4
- package/dist/bin.js +1769 -8
- package/dist/bin.js.map +1 -1
- package/dist/index.d.ts +118 -5
- package/dist/index.js +1770 -9
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/bin.js
CHANGED
|
@@ -35,10 +35,12 @@ var UsageError = class extends Error {
|
|
|
35
35
|
// src/args.ts
|
|
36
36
|
var FORMATS = ["pretty", "json", "markdown", "junit"];
|
|
37
37
|
var GRADES = ["A", "B", "C", "D", "F"];
|
|
38
|
-
var COMMANDS = ["check", "diff", "init", "badge"];
|
|
38
|
+
var COMMANDS = ["check", "docs-check", "diff", "init", "badge"];
|
|
39
39
|
var OPTIONS = {
|
|
40
40
|
format: { type: "string" },
|
|
41
|
+
json: { type: "boolean" },
|
|
41
42
|
"fail-on": { type: "string" },
|
|
43
|
+
"fail-on-blocking": { type: "boolean" },
|
|
42
44
|
out: { type: "string" },
|
|
43
45
|
"allow-private": { type: "boolean" },
|
|
44
46
|
"allow-http": { type: "boolean" },
|
|
@@ -138,6 +140,15 @@ function parseCommandLine(argv) {
|
|
|
138
140
|
const out = values.out ?? null;
|
|
139
141
|
const allowPrivate = values["allow-private"] === true;
|
|
140
142
|
const allowHttp = values["allow-http"] === true || allowPrivate;
|
|
143
|
+
if (values["fail-on-blocking"] === true && name !== "docs-check") {
|
|
144
|
+
throw new UsageError(
|
|
145
|
+
`--fail-on-blocking is only supported by \`docs-check\`. Use \`rebilder check --fail-on <grade>\` for ARS grading.`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
if (values.json === true && values.format !== void 0 && values.format !== "json") {
|
|
149
|
+
throw new UsageError(`--json cannot be combined with --format ${values.format}.`);
|
|
150
|
+
}
|
|
151
|
+
const resolvedFormat = values.json === true ? "json" : asFormat(values.format, "pretty");
|
|
141
152
|
switch (name) {
|
|
142
153
|
case "check": {
|
|
143
154
|
if (rest.length === 0) {
|
|
@@ -148,7 +159,7 @@ function parseCommandLine(argv) {
|
|
|
148
159
|
command: {
|
|
149
160
|
name: "check",
|
|
150
161
|
urls: rest,
|
|
151
|
-
format:
|
|
162
|
+
format: resolvedFormat,
|
|
152
163
|
failOn: asGrade(values["fail-on"]),
|
|
153
164
|
out,
|
|
154
165
|
allowPrivate,
|
|
@@ -157,6 +168,35 @@ function parseCommandLine(argv) {
|
|
|
157
168
|
}
|
|
158
169
|
};
|
|
159
170
|
}
|
|
171
|
+
case "docs-check": {
|
|
172
|
+
if (rest.length === 0) {
|
|
173
|
+
throw new UsageError("docs-check needs a URL. Usage: rebilder docs-check <url>");
|
|
174
|
+
}
|
|
175
|
+
if (rest.length > 1) {
|
|
176
|
+
throw new UsageError("docs-check takes exactly one URL.");
|
|
177
|
+
}
|
|
178
|
+
if (values["fail-on"] !== void 0) {
|
|
179
|
+
throw new UsageError(
|
|
180
|
+
"--fail-on is not supported by `docs-check`. Use `--fail-on-blocking` to fail when blocking docs findings are present."
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
const url = rest[0];
|
|
184
|
+
if (url === void 0) {
|
|
185
|
+
throw new UsageError("docs-check needs a URL. Usage: rebilder docs-check <url>");
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
kind: "command",
|
|
189
|
+
command: {
|
|
190
|
+
name: "docs-check",
|
|
191
|
+
url,
|
|
192
|
+
format: resolvedFormat,
|
|
193
|
+
failOnBlocking: values["fail-on-blocking"] === true,
|
|
194
|
+
out,
|
|
195
|
+
allowPrivate,
|
|
196
|
+
allowHttp
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
160
200
|
case "diff": {
|
|
161
201
|
if (rest.length === 0) throw new UsageError("diff needs a URL. Usage: rebilder diff <url>");
|
|
162
202
|
if (rest.length > 1) {
|
|
@@ -465,12 +505,26 @@ async function runInit(command, runtime2) {
|
|
|
465
505
|
}
|
|
466
506
|
return { ...SCAFFOLDS[framework], framework, detection };
|
|
467
507
|
}
|
|
508
|
+
var INGEST_ORIGIN = "https://api.rebilder.com";
|
|
509
|
+
var CONSOLE_INSTALL_URL = "https://rebilder.com/console/install";
|
|
468
510
|
var SHARED_NOTES = [
|
|
469
511
|
"The resolvers return your source of truth. Every substantive value \u2014 price, stock, hours, policy text \u2014 comes from these fields; the gateway never invents one.",
|
|
470
|
-
"The Apache-2.0 SDK serves without a Rebilder account or subscription.
|
|
512
|
+
"The Apache-2.0 SDK serves without a Rebilder account or subscription.",
|
|
513
|
+
`Reporting is wired in. Install \`@rebilder/events\`, create a free account, then set REBILDER_STORE_ID and REBILDER_API_KEY from ${CONSOLE_INSTALL_URL}. Without the key, nothing is sent.`,
|
|
471
514
|
`Run \`rebilder check <url>\` before and after to see what changed. Sending a Markdown copy from the page address is D2.1 (${DEFAULT_RULESET.weights["machine-representation.negotiated-response"] ?? 0} points) and unlocks D2.3 and D2.4.`
|
|
472
515
|
];
|
|
473
516
|
var CONFIG_BODY = `import type { GatewayConfig } from '@rebilder/gateway'
|
|
517
|
+
import { createHttpEventSink } from '@rebilder/events'
|
|
518
|
+
|
|
519
|
+
// Reports agent visits to your Rebilder Console. Free accounts include it.
|
|
520
|
+
// Copy both values from ${CONSOLE_INSTALL_URL} into your environment.
|
|
521
|
+
// Without REBILDER_API_KEY, nothing is sent.
|
|
522
|
+
const env = (name: string): string | undefined =>
|
|
523
|
+
(globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env?.[name]
|
|
524
|
+
const apiKey = env('REBILDER_API_KEY')
|
|
525
|
+
|
|
526
|
+
// Module scope, not per request: the sink batches (20 events, or every 2s).
|
|
527
|
+
const sink = apiKey ? createHttpEventSink({ url: '${INGEST_ORIGIN}', apiKey }) : null
|
|
474
528
|
|
|
475
529
|
/**
|
|
476
530
|
* Wiring to YOUR source of truth. Each resolver takes a URL and returns the
|
|
@@ -480,7 +534,7 @@ var CONFIG_BODY = `import type { GatewayConfig } from '@rebilder/gateway'
|
|
|
480
534
|
* call except a cache. Anything slower belongs in a build step.
|
|
481
535
|
*/
|
|
482
536
|
export const gatewayConfig: GatewayConfig = {
|
|
483
|
-
storeId: 'TODO-your-store-id',
|
|
537
|
+
storeId: env('REBILDER_STORE_ID') ?? 'TODO-your-store-id',
|
|
484
538
|
sources: {
|
|
485
539
|
// TODO: return your product fields, or null when the URL is not a PDP.
|
|
486
540
|
product: async (url) => {
|
|
@@ -489,8 +543,7 @@ export const gatewayConfig: GatewayConfig = {
|
|
|
489
543
|
},
|
|
490
544
|
// TODO: policies, catalog, document, collection \u2014 add the ones you have.
|
|
491
545
|
},
|
|
492
|
-
|
|
493
|
-
// onEvent: (event) => { void event },
|
|
546
|
+
onEvent: (event) => sink?.emit(event),
|
|
494
547
|
}
|
|
495
548
|
`;
|
|
496
549
|
function scaffold(suggestedPath, mount, notes) {
|
|
@@ -564,7 +617,7 @@ import { createShopifyAppProxyHandler } from '@rebilder/gateway/shopify'
|
|
|
564
617
|
import { gatewayConfig } from './gateway-config'
|
|
565
618
|
|
|
566
619
|
export const loader = createShopifyAppProxyHandler(gatewayConfig, {
|
|
567
|
-
sharedSecret: process.env.
|
|
620
|
+
sharedSecret: process.env.SHOPIFY_APP_SECRET ?? '',
|
|
568
621
|
})
|
|
569
622
|
`,
|
|
570
623
|
[
|
|
@@ -776,6 +829,1492 @@ export default async function middleware(request: Request) {
|
|
|
776
829
|
)
|
|
777
830
|
};
|
|
778
831
|
|
|
832
|
+
// src/docs-check.ts
|
|
833
|
+
var DOCS_CHECK_SCOPE = "This check reads the fetched page locally on your machine. It sends no data to Rebilder, does not install packages, and runs no code.";
|
|
834
|
+
function mediaTypeOf(contentType) {
|
|
835
|
+
if (contentType === null) return null;
|
|
836
|
+
return (contentType.split(";")[0] ?? "").trim().toLowerCase() || null;
|
|
837
|
+
}
|
|
838
|
+
function isMarkdownResponse(contentType, body) {
|
|
839
|
+
const type = mediaTypeOf(contentType);
|
|
840
|
+
if (type !== "text/markdown" && type !== "text/x-markdown" && type !== "text/plain") return false;
|
|
841
|
+
if (body === null) return false;
|
|
842
|
+
return !/^\s*(?:<!doctype html|<html\b)/i.test(body.slice(0, 2e3));
|
|
843
|
+
}
|
|
844
|
+
function captureToRep(capture) {
|
|
845
|
+
return {
|
|
846
|
+
status: capture.status,
|
|
847
|
+
contentType: capture.headers["content-type"]?.[0] ?? null,
|
|
848
|
+
body: capture.body ?? null,
|
|
849
|
+
finalUrl: capture.finalUrl
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
function recordToRep(record) {
|
|
853
|
+
if (record === null || record === void 0 || !record.result.ok) return null;
|
|
854
|
+
return captureToRep(record.result.capture);
|
|
855
|
+
}
|
|
856
|
+
function is2xx(rep) {
|
|
857
|
+
return rep !== null && rep.status >= 200 && rep.status < 300 && rep.body !== null;
|
|
858
|
+
}
|
|
859
|
+
function factsFromEvidence(evidence) {
|
|
860
|
+
const browser = recordToRep(evidence.probes.browser);
|
|
861
|
+
const agent = recordToRep(evidence.probes.agent);
|
|
862
|
+
const alt = recordToRep(evidence.probes.markdownAlternate);
|
|
863
|
+
let markdown = null;
|
|
864
|
+
if (is2xx(agent) && isMarkdownResponse(agent.contentType, agent.body)) {
|
|
865
|
+
markdown = { source: "negotiated", url: agent.finalUrl, body: agent.body };
|
|
866
|
+
} else if (is2xx(alt) && isMarkdownResponse(alt.contentType, alt.body)) {
|
|
867
|
+
markdown = { source: "alternate", url: alt.finalUrl, body: alt.body };
|
|
868
|
+
}
|
|
869
|
+
const llmsUrl = `${evidence.target.origin}/llms.txt`;
|
|
870
|
+
const llmsRecord = evidence.probes.llmsTxt;
|
|
871
|
+
let llmsTxt = { state: "unavailable", body: null, url: llmsUrl };
|
|
872
|
+
if (llmsRecord !== null && llmsRecord.result.ok) {
|
|
873
|
+
const cap = llmsRecord.result.capture;
|
|
874
|
+
const body = cap.body ?? "";
|
|
875
|
+
const ct = cap.headers["content-type"]?.[0] ?? null;
|
|
876
|
+
const looksHtml = /^\s*(?:<!doctype html|<html\b)/i.test(body.slice(0, 1e3));
|
|
877
|
+
if (cap.status >= 200 && cap.status < 300 && body.trim() !== "" && !looksHtml) {
|
|
878
|
+
llmsTxt = { state: "found", body, url: llmsUrl };
|
|
879
|
+
} else if (cap.status === 404 || cap.status === 410 || looksHtml || mediaTypeOf(ct) === "text/html") {
|
|
880
|
+
llmsTxt = { state: "missing", body: null, url: llmsUrl };
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
return {
|
|
884
|
+
url: evidence.target.url,
|
|
885
|
+
browser,
|
|
886
|
+
agent,
|
|
887
|
+
markdown,
|
|
888
|
+
llmsTxt
|
|
889
|
+
};
|
|
890
|
+
}
|
|
891
|
+
function classifyEvidenceStatus(evidence) {
|
|
892
|
+
const agent = evidence.probes.agent.result;
|
|
893
|
+
const browser = evidence.probes.browser.result;
|
|
894
|
+
if (agent.ok || browser.ok) return { status: "ok", detail: null };
|
|
895
|
+
if (agent.error === "policy-rejected" || browser.error === "policy-rejected") {
|
|
896
|
+
const detail2 = agent.error === "policy-rejected" ? agent.detail ?? "Blocked by robots.txt or probe policy." : browser.detail ?? "Blocked by robots.txt or probe policy.";
|
|
897
|
+
return { status: "policy", detail: detail2 };
|
|
898
|
+
}
|
|
899
|
+
const detail = browser.detail ?? agent.detail ?? `Probe failed (${browser.error})`;
|
|
900
|
+
return { status: "unreachable", detail };
|
|
901
|
+
}
|
|
902
|
+
var MAX_CODE_BLOCKS = 80;
|
|
903
|
+
var MAX_BLOCK_CHARS = 2e4;
|
|
904
|
+
var CONTEXT_CHARS = 600;
|
|
905
|
+
var NAMED_ENTITIES = {
|
|
906
|
+
amp: "&",
|
|
907
|
+
lt: "<",
|
|
908
|
+
gt: ">",
|
|
909
|
+
quot: '"',
|
|
910
|
+
apos: "'",
|
|
911
|
+
nbsp: " ",
|
|
912
|
+
hellip: "\u2026",
|
|
913
|
+
mdash: "\u2014",
|
|
914
|
+
ndash: "\u2013",
|
|
915
|
+
rsquo: "\u2019",
|
|
916
|
+
lsquo: "\u2018",
|
|
917
|
+
rdquo: "\u201D",
|
|
918
|
+
ldquo: "\u201C",
|
|
919
|
+
copy: "\xA9"
|
|
920
|
+
};
|
|
921
|
+
function decodeEntities(text2) {
|
|
922
|
+
return text2.replace(/&(#x[0-9a-f]{1,6}|#[0-9]{1,7}|[a-z]{2,8});/gi, (whole, ref) => {
|
|
923
|
+
if (ref[0] === "#") {
|
|
924
|
+
const code = ref[1] === "x" || ref[1] === "X" ? Number.parseInt(ref.slice(2), 16) : Number.parseInt(ref.slice(1), 10);
|
|
925
|
+
if (!Number.isFinite(code) || code <= 0 || code > 1114111) return whole;
|
|
926
|
+
try {
|
|
927
|
+
return String.fromCodePoint(code);
|
|
928
|
+
} catch {
|
|
929
|
+
return whole;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
return NAMED_ENTITIES[ref.toLowerCase()] ?? whole;
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
function stripTags(html) {
|
|
936
|
+
return html.replace(/<[^>]*>/g, "");
|
|
937
|
+
}
|
|
938
|
+
function htmlProse(html) {
|
|
939
|
+
const withBreaks = html.replace(/<br\s*\/?>/gi, "\n").replace(
|
|
940
|
+
/<\/?(?:p|div|li|ul|ol|tr|td|th|table|section|article|header|footer|aside|nav|blockquote|dd|dt|dl|figure|figcaption|details|summary)\b[^>]*>/gi,
|
|
941
|
+
"\n"
|
|
942
|
+
);
|
|
943
|
+
return decodeEntities(stripTags(withBreaks)).split("\n").map((line) => line.replace(/[ \t\u00a0]+/g, " ").trim()).filter((line) => line !== "");
|
|
944
|
+
}
|
|
945
|
+
function attrValue(tag, name) {
|
|
946
|
+
const patterns = {
|
|
947
|
+
class: /\sclass\s*=\s*(?:"([^"]*)"|'([^']*)')/i,
|
|
948
|
+
"data-language": /\sdata-language\s*=\s*(?:"([^"]*)"|'([^']*)')/i,
|
|
949
|
+
"data-lang": /\sdata-lang\s*=\s*(?:"([^"]*)"|'([^']*)')/i,
|
|
950
|
+
alt: /\salt\s*=\s*(?:"([^"]*)"|'([^']*)')/i,
|
|
951
|
+
src: /\ssrc\s*=\s*(?:"([^"]*)"|'([^']*)')/i
|
|
952
|
+
};
|
|
953
|
+
const match = patterns[name].exec(tag);
|
|
954
|
+
if (!match) return null;
|
|
955
|
+
return decodeEntities(match[1] ?? match[2] ?? "");
|
|
956
|
+
}
|
|
957
|
+
var LANG_ALIASES = {
|
|
958
|
+
sh: "shell",
|
|
959
|
+
bash: "shell",
|
|
960
|
+
zsh: "shell",
|
|
961
|
+
shell: "shell",
|
|
962
|
+
shellscript: "shell",
|
|
963
|
+
"shell-session": "console",
|
|
964
|
+
shellsession: "console",
|
|
965
|
+
terminal: "shell",
|
|
966
|
+
console: "console",
|
|
967
|
+
powershell: "powershell",
|
|
968
|
+
ps1: "powershell",
|
|
969
|
+
js: "javascript",
|
|
970
|
+
mjs: "javascript",
|
|
971
|
+
cjs: "javascript",
|
|
972
|
+
javascript: "javascript",
|
|
973
|
+
jsx: "jsx",
|
|
974
|
+
ts: "typescript",
|
|
975
|
+
typescript: "typescript",
|
|
976
|
+
tsx: "tsx",
|
|
977
|
+
py: "python",
|
|
978
|
+
python: "python",
|
|
979
|
+
python3: "python",
|
|
980
|
+
plaintext: "text",
|
|
981
|
+
plain: "text",
|
|
982
|
+
txt: "text",
|
|
983
|
+
text: "text",
|
|
984
|
+
none: "text",
|
|
985
|
+
yml: "yaml",
|
|
986
|
+
dotenv: "env",
|
|
987
|
+
env: "env"
|
|
988
|
+
};
|
|
989
|
+
function normalizeLang(raw) {
|
|
990
|
+
const lang = raw.trim().toLowerCase().replace(/^\{?\.?/, "").replace(/[{}]/g, "").split(/[\s,:{]/)[0];
|
|
991
|
+
if (lang === void 0 || lang === "") return null;
|
|
992
|
+
return LANG_ALIASES[lang] ?? lang;
|
|
993
|
+
}
|
|
994
|
+
function languageFromTag(tag) {
|
|
995
|
+
const data = attrValue(tag, "data-language") ?? attrValue(tag, "data-lang");
|
|
996
|
+
if (data !== null && data.trim() !== "") return normalizeLang(data);
|
|
997
|
+
const classes = attrValue(tag, "class");
|
|
998
|
+
if (classes === null) return null;
|
|
999
|
+
for (const token of classes.split(/\s+/)) {
|
|
1000
|
+
const match = /^(?:language|lang|highlight-source|highlight)-([a-z0-9+#._-]{1,30})$/i.exec(
|
|
1001
|
+
token
|
|
1002
|
+
);
|
|
1003
|
+
if (match?.[1]) return normalizeLang(match[1]);
|
|
1004
|
+
}
|
|
1005
|
+
return null;
|
|
1006
|
+
}
|
|
1007
|
+
function linkContext(nodes, source) {
|
|
1008
|
+
const blocks = [];
|
|
1009
|
+
let section = null;
|
|
1010
|
+
for (const node of nodes) {
|
|
1011
|
+
if (node.kind === "heading") section = node.text;
|
|
1012
|
+
if (node.kind === "code") {
|
|
1013
|
+
node.block.section = section;
|
|
1014
|
+
blocks.push(node.block);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
1018
|
+
const node = nodes[i];
|
|
1019
|
+
if (node?.kind !== "code") continue;
|
|
1020
|
+
let before = "";
|
|
1021
|
+
for (let j = i - 1; j >= 0 && before.length < CONTEXT_CHARS; j--) {
|
|
1022
|
+
const prev = nodes[j];
|
|
1023
|
+
if (prev === void 0 || prev.kind === "code") break;
|
|
1024
|
+
if (prev.kind === "text" || prev.kind === "heading") before = `${prev.text}
|
|
1025
|
+
${before}`;
|
|
1026
|
+
}
|
|
1027
|
+
let after = "";
|
|
1028
|
+
for (let j = i + 1; j < nodes.length && after.length < CONTEXT_CHARS; j++) {
|
|
1029
|
+
const next = nodes[j];
|
|
1030
|
+
if (next === void 0 || next.kind === "code" || next.kind === "heading") break;
|
|
1031
|
+
if (next.kind === "text") after = `${after}${next.text}
|
|
1032
|
+
`;
|
|
1033
|
+
}
|
|
1034
|
+
node.block.before = before.slice(-CONTEXT_CHARS);
|
|
1035
|
+
node.block.after = after.slice(0, CONTEXT_CHARS);
|
|
1036
|
+
}
|
|
1037
|
+
const prose = nodes.flatMap((node) => node.kind === "text" || node.kind === "heading" ? [node.text] : []).join("\n");
|
|
1038
|
+
return { source, nodes, blocks, prose };
|
|
1039
|
+
}
|
|
1040
|
+
function contentRegion(html) {
|
|
1041
|
+
const main = /<main\b[^>]*>([\s\S]*)<\/main>/i.exec(html);
|
|
1042
|
+
if (main?.[1] !== void 0) return main[1];
|
|
1043
|
+
const article = /<article\b[^>]*>([\s\S]*)<\/article>/i.exec(html);
|
|
1044
|
+
if (article?.[1] !== void 0) return article[1];
|
|
1045
|
+
const body = /<body\b[^>]*>([\s\S]*)<\/body>/i.exec(html);
|
|
1046
|
+
return body?.[1] ?? html;
|
|
1047
|
+
}
|
|
1048
|
+
function stripInvisible(html) {
|
|
1049
|
+
return html.replace(/<!--[\s\S]*?-->/g, " ").replace(/<script\b[^>]*>[\s\S]*?<\/script\s*>/gi, " ").replace(/<style\b[^>]*>[\s\S]*?<\/style\s*>/gi, " ").replace(/<svg\b[^>]*>[\s\S]*?<\/svg\s*>/gi, " ").replace(/<template\b[^>]*>[\s\S]*?<\/template\s*>/gi, " ").replace(/<head\b[^>]*>[\s\S]*?<\/head\s*>/gi, " ");
|
|
1050
|
+
}
|
|
1051
|
+
function parseHtmlDocument(html) {
|
|
1052
|
+
const region = stripInvisible(contentRegion(stripInvisible(html)));
|
|
1053
|
+
const nodes = [];
|
|
1054
|
+
const pattern = /<pre\b[^>]*>[\s\S]*?<\/pre\s*>|<h([1-6])\b[^>]*>[\s\S]*?<\/h\1\s*>|<img\b[^>]*>/gi;
|
|
1055
|
+
let last = 0;
|
|
1056
|
+
let blockIndex = 0;
|
|
1057
|
+
const pushText = (chunk) => {
|
|
1058
|
+
for (const line of htmlProse(chunk)) nodes.push({ kind: "text", text: line });
|
|
1059
|
+
};
|
|
1060
|
+
for (let match = pattern.exec(region); match !== null; match = pattern.exec(region)) {
|
|
1061
|
+
pushText(region.slice(last, match.index));
|
|
1062
|
+
last = match.index + match[0].length;
|
|
1063
|
+
const whole = match[0];
|
|
1064
|
+
if (/^<pre\b/i.test(whole)) {
|
|
1065
|
+
if (blockIndex >= MAX_CODE_BLOCKS) continue;
|
|
1066
|
+
const openPre = /^<pre\b[^>]*>/i.exec(whole)?.[0] ?? "";
|
|
1067
|
+
const openCode = /<code\b[^>]*>/i.exec(whole)?.[0] ?? "";
|
|
1068
|
+
const wrapper = region.slice(Math.max(0, match.index - 300), match.index);
|
|
1069
|
+
const wrapperTags = wrapper.match(/<[a-z][^>]*>/gi) ?? [];
|
|
1070
|
+
const lang = languageFromTag(openPre) ?? languageFromTag(openCode) ?? (wrapperTags.length > 0 ? languageFromTag(wrapperTags[wrapperTags.length - 1] ?? "") : null);
|
|
1071
|
+
const inner = whole.replace(/^<pre\b[^>]*>/i, "").replace(/<\/pre\s*>$/i, "").replace(/<br\s*\/?>/gi, "\n").replace(/<\/div>\s*<div\b[^>]*>/gi, "\n");
|
|
1072
|
+
const codeText = decodeEntities(stripTags(inner)).replace(/\n$/, "").slice(0, MAX_BLOCK_CHARS);
|
|
1073
|
+
nodes.push({
|
|
1074
|
+
kind: "code",
|
|
1075
|
+
block: { index: blockIndex++, lang, code: codeText, section: null, before: "", after: "" }
|
|
1076
|
+
});
|
|
1077
|
+
} else if (/^<h[1-6]\b/i.test(whole)) {
|
|
1078
|
+
const level = Number(match[1] ?? "2");
|
|
1079
|
+
const text2 = decodeEntities(stripTags(whole)).replace(/\s+/g, " ").trim();
|
|
1080
|
+
if (text2 !== "") nodes.push({ kind: "heading", level, text: text2 });
|
|
1081
|
+
} else {
|
|
1082
|
+
nodes.push({
|
|
1083
|
+
kind: "image",
|
|
1084
|
+
alt: (attrValue(whole, "alt") ?? "").trim(),
|
|
1085
|
+
src: (attrValue(whole, "src") ?? "").trim()
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
pushText(region.slice(last));
|
|
1090
|
+
return linkContext(nodes, "html");
|
|
1091
|
+
}
|
|
1092
|
+
function parseMarkdownDocument(markdown) {
|
|
1093
|
+
const nodes = [];
|
|
1094
|
+
const lines = markdown.replace(/\r\n?/g, "\n").split("\n");
|
|
1095
|
+
let i = 0;
|
|
1096
|
+
if (lines[0]?.trim() === "---") {
|
|
1097
|
+
const end = lines.findIndex((line, n) => n > 0 && line.trim() === "---");
|
|
1098
|
+
if (end > 0) i = end + 1;
|
|
1099
|
+
}
|
|
1100
|
+
let blockIndex = 0;
|
|
1101
|
+
while (i < lines.length) {
|
|
1102
|
+
const line = lines[i] ?? "";
|
|
1103
|
+
const fence = /^ {0,3}(`{3,}|~{3,})(.*)$/.exec(line);
|
|
1104
|
+
if (fence) {
|
|
1105
|
+
const marker = fence[1] ?? "```";
|
|
1106
|
+
const info = (fence[2] ?? "").trim();
|
|
1107
|
+
const body = [];
|
|
1108
|
+
i++;
|
|
1109
|
+
while (i < lines.length) {
|
|
1110
|
+
const candidate = (lines[i] ?? "").trim();
|
|
1111
|
+
const closes = candidate.length >= marker.length && candidate[0] === marker[0] && /^(?:`+|~+)$/.test(candidate);
|
|
1112
|
+
if (closes) break;
|
|
1113
|
+
body.push(lines[i] ?? "");
|
|
1114
|
+
i++;
|
|
1115
|
+
}
|
|
1116
|
+
i++;
|
|
1117
|
+
if (blockIndex < MAX_CODE_BLOCKS) {
|
|
1118
|
+
nodes.push({
|
|
1119
|
+
kind: "code",
|
|
1120
|
+
block: {
|
|
1121
|
+
index: blockIndex++,
|
|
1122
|
+
lang: info === "" ? null : normalizeLang(info),
|
|
1123
|
+
code: body.join("\n").slice(0, MAX_BLOCK_CHARS),
|
|
1124
|
+
section: null,
|
|
1125
|
+
before: "",
|
|
1126
|
+
after: ""
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
continue;
|
|
1131
|
+
}
|
|
1132
|
+
const heading = /^ {0,3}(#{1,6})\s+(.+)$/.exec(line);
|
|
1133
|
+
if (heading) {
|
|
1134
|
+
const text3 = (heading[2] ?? "").replace(/\s+#+\s*$/, "").trim();
|
|
1135
|
+
if (text3 !== "") nodes.push({ kind: "heading", level: heading[1]?.length ?? 2, text: text3 });
|
|
1136
|
+
i++;
|
|
1137
|
+
continue;
|
|
1138
|
+
}
|
|
1139
|
+
const imagePattern = /!\[([^\]]{0,300})\]\(\s*([^)\s]{1,2048})[^)]{0,300}\)/g;
|
|
1140
|
+
let rest = line;
|
|
1141
|
+
for (let image = imagePattern.exec(line); image !== null; image = imagePattern.exec(line)) {
|
|
1142
|
+
nodes.push({ kind: "image", alt: image[1] ?? "", src: image[2] ?? "" });
|
|
1143
|
+
rest = rest.replace(image[0], " ");
|
|
1144
|
+
}
|
|
1145
|
+
const text2 = rest.trim();
|
|
1146
|
+
if (text2 !== "") nodes.push({ kind: "text", text: text2 });
|
|
1147
|
+
i++;
|
|
1148
|
+
}
|
|
1149
|
+
return linkContext(nodes, "markdown");
|
|
1150
|
+
}
|
|
1151
|
+
var SHELL_LANGS = /* @__PURE__ */ new Set(["shell", "console", "powershell", "cmd", "bat"]);
|
|
1152
|
+
var JS_LANGS = /* @__PURE__ */ new Set(["javascript", "typescript", "jsx", "tsx"]);
|
|
1153
|
+
var PY_LANGS = /* @__PURE__ */ new Set(["python"]);
|
|
1154
|
+
var NON_RUNNABLE_LANGS = /* @__PURE__ */ new Set(["text", "output", "log", "console", "diff"]);
|
|
1155
|
+
var MARKUP_LANGS = /* @__PURE__ */ new Set([
|
|
1156
|
+
"html",
|
|
1157
|
+
"xml",
|
|
1158
|
+
"jsx",
|
|
1159
|
+
"tsx",
|
|
1160
|
+
"vue",
|
|
1161
|
+
"svelte",
|
|
1162
|
+
"markup",
|
|
1163
|
+
"astro"
|
|
1164
|
+
]);
|
|
1165
|
+
var PROGRAM_LANGS = /* @__PURE__ */ new Set([
|
|
1166
|
+
"javascript",
|
|
1167
|
+
"typescript",
|
|
1168
|
+
"jsx",
|
|
1169
|
+
"tsx",
|
|
1170
|
+
"python",
|
|
1171
|
+
"go",
|
|
1172
|
+
"ruby",
|
|
1173
|
+
"rust",
|
|
1174
|
+
"java",
|
|
1175
|
+
"kotlin",
|
|
1176
|
+
"csharp",
|
|
1177
|
+
"cs",
|
|
1178
|
+
"c#",
|
|
1179
|
+
"php",
|
|
1180
|
+
"swift",
|
|
1181
|
+
"dart",
|
|
1182
|
+
"elixir",
|
|
1183
|
+
"scala"
|
|
1184
|
+
]);
|
|
1185
|
+
var SHELL_START = /^\s*(?:\$|%|>)?\s*(?:npm|npx|pnpm|yarn|bun|pip3?|python3?|uv|poetry|pipenv|curl|wget|git|cd|export|go|cargo|gem|bundle|composer|dotnet|brew|docker|kubectl|mkdir|echo|source)\b/;
|
|
1186
|
+
var PROGRAM_LINE = /^\s*(?:import\s+[\w*{'"]|from\s+[\w.]+\s+import\s|(?:const|let|var)\s+[\w${}\s,]+=\s*require\(|export\s+(?:default|const|function|class)\s|package\s+\w+\s*;?\s*$|#include\s*[<"]|using\s+[\w.]+\s*;)/m;
|
|
1187
|
+
var PROMPT = /^\s*(?:\$|%|PS [^>\n]{0,80}>|[A-Za-z]:\\[^>\n]{0,80}>)\s/;
|
|
1188
|
+
function isShellBlock(block) {
|
|
1189
|
+
if (block.lang !== null) return SHELL_LANGS.has(block.lang);
|
|
1190
|
+
const first = block.code.split("\n").find((line) => line.trim() !== "" && !/^\s*#/.test(line)) ?? "";
|
|
1191
|
+
return SHELL_START.test(first);
|
|
1192
|
+
}
|
|
1193
|
+
function isProgramBlock(block) {
|
|
1194
|
+
if (block.lang !== null) return PROGRAM_LANGS.has(block.lang);
|
|
1195
|
+
return !isShellBlock(block) && PROGRAM_LINE.test(block.code);
|
|
1196
|
+
}
|
|
1197
|
+
function stripPrompt(line) {
|
|
1198
|
+
return line.replace(PROMPT, "");
|
|
1199
|
+
}
|
|
1200
|
+
function promptUse(block) {
|
|
1201
|
+
const lines = block.code.split("\n");
|
|
1202
|
+
const promptLines = lines.filter((line) => PROMPT.test(line));
|
|
1203
|
+
if (promptLines.length === 0) return { promptLines, outputLines: [] };
|
|
1204
|
+
const outputLines = [];
|
|
1205
|
+
let continued = false;
|
|
1206
|
+
for (const line of lines) {
|
|
1207
|
+
const trimmed = line.trim();
|
|
1208
|
+
if (trimmed === "") {
|
|
1209
|
+
continued = false;
|
|
1210
|
+
continue;
|
|
1211
|
+
}
|
|
1212
|
+
if (PROMPT.test(line)) {
|
|
1213
|
+
continued = trimmed.endsWith("\\");
|
|
1214
|
+
continue;
|
|
1215
|
+
}
|
|
1216
|
+
if (continued) {
|
|
1217
|
+
continued = trimmed.endsWith("\\");
|
|
1218
|
+
continue;
|
|
1219
|
+
}
|
|
1220
|
+
if (trimmed.startsWith("#")) continue;
|
|
1221
|
+
outputLines.push(line);
|
|
1222
|
+
}
|
|
1223
|
+
return { promptLines, outputLines };
|
|
1224
|
+
}
|
|
1225
|
+
function elisionLines(block) {
|
|
1226
|
+
if (block.lang !== null && NON_RUNNABLE_LANGS.has(block.lang)) return [];
|
|
1227
|
+
return block.code.split("\n").filter((line) => {
|
|
1228
|
+
const trimmed = line.trim();
|
|
1229
|
+
if (trimmed === "..." || trimmed === "\u2026") return true;
|
|
1230
|
+
if (/^(?:\/\/|#|--|\/\*|<!--)\s*(?:\.\.\.|…)/.test(trimmed)) return true;
|
|
1231
|
+
if (trimmed.includes("\u2026")) return true;
|
|
1232
|
+
return /(?:^|[^\w.])\.\.\.(?![\w$[({'"`.])/.test(line);
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1235
|
+
var PLACEHOLDER_PATTERNS = [
|
|
1236
|
+
/\b(?:YOUR|MY)_[A-Z0-9_]{2,40}\b/g,
|
|
1237
|
+
/\b(?:your|my)[-_][a-z0-9][a-z0-9_-]{1,40}\b/g,
|
|
1238
|
+
/\b(?:REPLACE_ME|CHANGE_?ME|INSERT_[A-Z0-9_]{2,40})\b/g,
|
|
1239
|
+
/(?<![\w-])[xX]{3,}(?![\w-])/g
|
|
1240
|
+
];
|
|
1241
|
+
var ANGLE_PLACEHOLDER = /<([A-Za-z][\w -]{0,30})>/g;
|
|
1242
|
+
var ANGLE_KEYWORDS = /(?:key|token|secret|password|passwd|id|name|project|org|account|value|url|domain|host|region|user|email|your|workspace|tenant)/i;
|
|
1243
|
+
var EXPLAINS_VALUE = /\b(?:replace|substitute|dashboard|settings|console|portal|account page|keys? page|generate|create (?:an?|your|the)|obtain|copy (?:it|your|the)|found (?:in|under|on)|get (?:an?|your)|sign up|you(?:'|’)ll need|retrieve)\b/i;
|
|
1244
|
+
function angleAllowed(block, line, index, length) {
|
|
1245
|
+
const before = line[index - 1];
|
|
1246
|
+
const after = line[index + length];
|
|
1247
|
+
const quoted = (before === '"' || before === "'") && (after === '"' || after === "'");
|
|
1248
|
+
if (quoted) return true;
|
|
1249
|
+
if (block.lang !== null && MARKUP_LANGS.has(block.lang)) return false;
|
|
1250
|
+
if (block.lang === null || isShellBlock(block)) return true;
|
|
1251
|
+
return ["env", "yaml", "toml", "json", "ini", "http", "text", "properties"].includes(block.lang);
|
|
1252
|
+
}
|
|
1253
|
+
function findPlaceholders(blocks) {
|
|
1254
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1255
|
+
const out = [];
|
|
1256
|
+
for (const block of blocks) {
|
|
1257
|
+
const context = `${block.before}
|
|
1258
|
+
${block.after}`;
|
|
1259
|
+
for (const line of block.code.split("\n")) {
|
|
1260
|
+
const tokens = [];
|
|
1261
|
+
for (const pattern of PLACEHOLDER_PATTERNS) {
|
|
1262
|
+
for (const match of line.matchAll(pattern)) tokens.push(match[0]);
|
|
1263
|
+
}
|
|
1264
|
+
for (const match of line.matchAll(ANGLE_PLACEHOLDER)) {
|
|
1265
|
+
const inner = match[1] ?? "";
|
|
1266
|
+
if (!ANGLE_KEYWORDS.test(inner)) continue;
|
|
1267
|
+
if (!angleAllowed(block, line, match.index ?? 0, match[0].length)) continue;
|
|
1268
|
+
tokens.push(match[0]);
|
|
1269
|
+
}
|
|
1270
|
+
for (const token of tokens) {
|
|
1271
|
+
const key = token.toLowerCase();
|
|
1272
|
+
if (seen.has(key)) continue;
|
|
1273
|
+
seen.add(key);
|
|
1274
|
+
const bare = token.replace(/^<|>$/g, "").toLowerCase();
|
|
1275
|
+
const explained = context.toLowerCase().includes(bare) || EXPLAINS_VALUE.test(context);
|
|
1276
|
+
out.push({ token, block, line: line.trim(), explained });
|
|
1277
|
+
if (out.length >= 20) return out;
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
return out;
|
|
1282
|
+
}
|
|
1283
|
+
var NPM_SEGMENT = /^[a-z0-9][a-z0-9._~-]{0,213}$/;
|
|
1284
|
+
var PYPI_CHARS = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;
|
|
1285
|
+
function isNpmName(name) {
|
|
1286
|
+
if (name.startsWith("@")) {
|
|
1287
|
+
const slash = name.indexOf("/");
|
|
1288
|
+
if (slash <= 1 || slash !== name.lastIndexOf("/")) return false;
|
|
1289
|
+
const scope = name.slice(1, slash);
|
|
1290
|
+
const pkg = name.slice(slash + 1);
|
|
1291
|
+
return scope.length <= 101 && NPM_SEGMENT.test(scope) && NPM_SEGMENT.test(pkg);
|
|
1292
|
+
}
|
|
1293
|
+
return NPM_SEGMENT.test(name);
|
|
1294
|
+
}
|
|
1295
|
+
function isPypiName(name) {
|
|
1296
|
+
if (name.length === 0 || name.length > 100) return false;
|
|
1297
|
+
if (!PYPI_CHARS.test(name)) return false;
|
|
1298
|
+
return /[A-Za-z0-9]$/.test(name);
|
|
1299
|
+
}
|
|
1300
|
+
function npmSpec(token, line) {
|
|
1301
|
+
const cleaned = token.replace(/^['"]|['"]$/g, "");
|
|
1302
|
+
if (cleaned === "" || /^(?:\.|\/|~|git|https?:|file:|npm:|github:|link:|workspace:)/.test(cleaned)) {
|
|
1303
|
+
return null;
|
|
1304
|
+
}
|
|
1305
|
+
const at = cleaned.startsWith("@") ? cleaned.indexOf("@", 1) : cleaned.indexOf("@");
|
|
1306
|
+
const name = at > 0 ? cleaned.slice(0, at) : cleaned;
|
|
1307
|
+
if (!isNpmName(name)) return null;
|
|
1308
|
+
return { ecosystem: "npm", name, evidence: line };
|
|
1309
|
+
}
|
|
1310
|
+
function pypiSpec(token, line) {
|
|
1311
|
+
const cleaned = token.replace(/^['"]|['"],?$/g, "").trim();
|
|
1312
|
+
if (cleaned === "" || cleaned.includes("/") || cleaned.endsWith(".whl") || cleaned.startsWith(".")) {
|
|
1313
|
+
return null;
|
|
1314
|
+
}
|
|
1315
|
+
const opIndex = cleaned.search(/===|==|~=|>=|<=|!=|>|</);
|
|
1316
|
+
const head = (opIndex >= 0 ? cleaned.slice(0, opIndex) : cleaned).trim();
|
|
1317
|
+
const bracket = head.indexOf("[");
|
|
1318
|
+
const name = (bracket >= 0 ? head.slice(0, bracket) : head).trim();
|
|
1319
|
+
if (!isPypiName(name)) return null;
|
|
1320
|
+
return { ecosystem: "pypi", name, evidence: line };
|
|
1321
|
+
}
|
|
1322
|
+
var MANAGER_RULES = [
|
|
1323
|
+
{ manager: "npm", ecosystem: "npm", pattern: /^npm\s+(?:install|i|add)(?=\s|$)/ },
|
|
1324
|
+
{ manager: "pnpm", ecosystem: "npm", pattern: /^pnpm\s+(?:add|install|i)(?=\s|$)/ },
|
|
1325
|
+
{ manager: "yarn", ecosystem: "npm", pattern: /^yarn\s+(?:global\s+add|add)(?=\s|$)/ },
|
|
1326
|
+
{ manager: "bun", ecosystem: "npm", pattern: /^bun\s+(?:add|install|i)(?=\s|$)/ },
|
|
1327
|
+
{
|
|
1328
|
+
manager: "pip",
|
|
1329
|
+
ecosystem: "pypi",
|
|
1330
|
+
pattern: /^(?:python3?\s+-m\s+pip3?|pip3?)\s+install(?=\s|$)/
|
|
1331
|
+
},
|
|
1332
|
+
{ manager: "uv", ecosystem: "pypi", pattern: /^uv\s+(?:pip\s+install|add)(?=\s|$)/ },
|
|
1333
|
+
{ manager: "poetry", ecosystem: "pypi", pattern: /^poetry\s+add(?=\s|$)/ },
|
|
1334
|
+
{ manager: "pipenv", ecosystem: "pypi", pattern: /^pipenv\s+install(?=\s|$)/ },
|
|
1335
|
+
{ manager: "go", ecosystem: "other", pattern: /^go\s+(?:get|install)(?=\s|$)/ },
|
|
1336
|
+
{ manager: "cargo", ecosystem: "other", pattern: /^cargo\s+(?:add|install)(?=\s|$)/ },
|
|
1337
|
+
{ manager: "gem", ecosystem: "other", pattern: /^(?:gem\s+install|bundle\s+add)(?=\s|$)/ },
|
|
1338
|
+
{ manager: "composer", ecosystem: "other", pattern: /^composer\s+require(?=\s|$)/ },
|
|
1339
|
+
{ manager: "dotnet", ecosystem: "other", pattern: /^dotnet\s+add\s+package(?=\s|$)/ },
|
|
1340
|
+
{ manager: "brew", ecosystem: "other", pattern: /^brew\s+install(?=\s|$)/ }
|
|
1341
|
+
];
|
|
1342
|
+
var ARG_FLAGS = /* @__PURE__ */ new Set([
|
|
1343
|
+
"-r",
|
|
1344
|
+
"--requirement",
|
|
1345
|
+
"-e",
|
|
1346
|
+
"--editable",
|
|
1347
|
+
"-c",
|
|
1348
|
+
"--constraint",
|
|
1349
|
+
"-i",
|
|
1350
|
+
"--index-url",
|
|
1351
|
+
"--extra-index-url",
|
|
1352
|
+
"--registry",
|
|
1353
|
+
"--filter",
|
|
1354
|
+
"-w",
|
|
1355
|
+
"--workspace",
|
|
1356
|
+
"-C",
|
|
1357
|
+
"--cwd"
|
|
1358
|
+
]);
|
|
1359
|
+
function parseInstallLine(raw) {
|
|
1360
|
+
const line = stripPrompt(raw).trim().replace(/^sudo\s+/, "");
|
|
1361
|
+
for (const rule of MANAGER_RULES) {
|
|
1362
|
+
const head = rule.pattern.exec(line);
|
|
1363
|
+
if (!head) continue;
|
|
1364
|
+
const tail = line.slice(head[0].length).split(/\s(?:&&|\|\||;|\||#)\s?|[;|]/)[0] ?? "";
|
|
1365
|
+
const tokens = tail.split(/\s+/).filter((token) => token !== "" && token !== "\\");
|
|
1366
|
+
const packages = [];
|
|
1367
|
+
for (let n = 0; n < tokens.length; n++) {
|
|
1368
|
+
const token = tokens[n] ?? "";
|
|
1369
|
+
if (token.startsWith("-")) {
|
|
1370
|
+
if (ARG_FLAGS.has(token)) n++;
|
|
1371
|
+
continue;
|
|
1372
|
+
}
|
|
1373
|
+
if (rule.ecosystem === "npm") {
|
|
1374
|
+
const ref = npmSpec(token, line);
|
|
1375
|
+
if (ref) packages.push(ref);
|
|
1376
|
+
} else if (rule.ecosystem === "pypi") {
|
|
1377
|
+
const ref = pypiSpec(token, line);
|
|
1378
|
+
if (ref) packages.push(ref);
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
return { manager: rule.manager, ecosystem: rule.ecosystem, line, packages };
|
|
1382
|
+
}
|
|
1383
|
+
return null;
|
|
1384
|
+
}
|
|
1385
|
+
function findInstallCommands(doc) {
|
|
1386
|
+
const out = [];
|
|
1387
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1388
|
+
const add = (command) => {
|
|
1389
|
+
if (command === null || seen.has(command.line) || out.length >= 30) return;
|
|
1390
|
+
seen.add(command.line);
|
|
1391
|
+
out.push(command);
|
|
1392
|
+
};
|
|
1393
|
+
for (const block of doc.blocks) {
|
|
1394
|
+
if (!(isShellBlock(block) || block.lang === null || block.lang === "text")) continue;
|
|
1395
|
+
for (const line of block.code.split("\n")) add(parseInstallLine(line));
|
|
1396
|
+
}
|
|
1397
|
+
for (const node of doc.nodes) {
|
|
1398
|
+
if (node.kind !== "text") continue;
|
|
1399
|
+
const inline = /\b((?:npm|pnpm|yarn|bun|pip3?|python3? -m pip|uv|poetry|pipenv|go|cargo|gem|composer|dotnet|brew)\s+(?:install|i|add|get|require|pip install)\b[^`\n]{0,160})/.exec(
|
|
1400
|
+
node.text
|
|
1401
|
+
);
|
|
1402
|
+
if (inline?.[1]) add(parseInstallLine(inline[1].replace(/[.,)]+$/, "")));
|
|
1403
|
+
}
|
|
1404
|
+
return out;
|
|
1405
|
+
}
|
|
1406
|
+
var NODE_BUILTINS = /* @__PURE__ */ new Set([
|
|
1407
|
+
"assert",
|
|
1408
|
+
"async_hooks",
|
|
1409
|
+
"buffer",
|
|
1410
|
+
"child_process",
|
|
1411
|
+
"cluster",
|
|
1412
|
+
"console",
|
|
1413
|
+
"crypto",
|
|
1414
|
+
"dgram",
|
|
1415
|
+
"dns",
|
|
1416
|
+
"events",
|
|
1417
|
+
"fs",
|
|
1418
|
+
"http",
|
|
1419
|
+
"http2",
|
|
1420
|
+
"https",
|
|
1421
|
+
"module",
|
|
1422
|
+
"net",
|
|
1423
|
+
"os",
|
|
1424
|
+
"path",
|
|
1425
|
+
"perf_hooks",
|
|
1426
|
+
"process",
|
|
1427
|
+
"querystring",
|
|
1428
|
+
"readline",
|
|
1429
|
+
"stream",
|
|
1430
|
+
"string_decoder",
|
|
1431
|
+
"timers",
|
|
1432
|
+
"tls",
|
|
1433
|
+
"url",
|
|
1434
|
+
"util",
|
|
1435
|
+
"v8",
|
|
1436
|
+
"vm",
|
|
1437
|
+
"worker_threads",
|
|
1438
|
+
"zlib"
|
|
1439
|
+
]);
|
|
1440
|
+
var PY_STDLIB = /* @__PURE__ */ new Set([
|
|
1441
|
+
"__future__",
|
|
1442
|
+
"abc",
|
|
1443
|
+
"argparse",
|
|
1444
|
+
"asyncio",
|
|
1445
|
+
"base64",
|
|
1446
|
+
"collections",
|
|
1447
|
+
"contextlib",
|
|
1448
|
+
"copy",
|
|
1449
|
+
"csv",
|
|
1450
|
+
"dataclasses",
|
|
1451
|
+
"datetime",
|
|
1452
|
+
"decimal",
|
|
1453
|
+
"enum",
|
|
1454
|
+
"functools",
|
|
1455
|
+
"glob",
|
|
1456
|
+
"hashlib",
|
|
1457
|
+
"hmac",
|
|
1458
|
+
"http",
|
|
1459
|
+
"importlib",
|
|
1460
|
+
"io",
|
|
1461
|
+
"itertools",
|
|
1462
|
+
"json",
|
|
1463
|
+
"logging",
|
|
1464
|
+
"math",
|
|
1465
|
+
"os",
|
|
1466
|
+
"pathlib",
|
|
1467
|
+
"pickle",
|
|
1468
|
+
"pprint",
|
|
1469
|
+
"random",
|
|
1470
|
+
"re",
|
|
1471
|
+
"shutil",
|
|
1472
|
+
"signal",
|
|
1473
|
+
"socket",
|
|
1474
|
+
"sqlite3",
|
|
1475
|
+
"ssl",
|
|
1476
|
+
"string",
|
|
1477
|
+
"subprocess",
|
|
1478
|
+
"sys",
|
|
1479
|
+
"tempfile",
|
|
1480
|
+
"textwrap",
|
|
1481
|
+
"threading",
|
|
1482
|
+
"time",
|
|
1483
|
+
"traceback",
|
|
1484
|
+
"typing",
|
|
1485
|
+
"unittest",
|
|
1486
|
+
"urllib",
|
|
1487
|
+
"uuid",
|
|
1488
|
+
"warnings",
|
|
1489
|
+
"xml",
|
|
1490
|
+
"zipfile"
|
|
1491
|
+
]);
|
|
1492
|
+
function npmPackageOf(specifier) {
|
|
1493
|
+
if (/^(?:\.|\/|node:|#|https?:|~|@\/|bun:|deno:|jsr:|npm:)/.test(specifier)) return null;
|
|
1494
|
+
const parts = specifier.split("/");
|
|
1495
|
+
const name = specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0] ?? "";
|
|
1496
|
+
if (!isNpmName(name) || NODE_BUILTINS.has(name)) return null;
|
|
1497
|
+
return name;
|
|
1498
|
+
}
|
|
1499
|
+
function findImports(doc) {
|
|
1500
|
+
const out = [];
|
|
1501
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1502
|
+
const add = (ref) => {
|
|
1503
|
+
const key = `${ref.ecosystem}:${ref.name}`;
|
|
1504
|
+
if (seen.has(key)) return;
|
|
1505
|
+
seen.add(key);
|
|
1506
|
+
out.push(ref);
|
|
1507
|
+
};
|
|
1508
|
+
for (const block of doc.blocks) {
|
|
1509
|
+
const lang = block.lang;
|
|
1510
|
+
const js = lang !== null && JS_LANGS.has(lang);
|
|
1511
|
+
const py = lang !== null && PY_LANGS.has(lang);
|
|
1512
|
+
if (!js && !py && lang !== null) continue;
|
|
1513
|
+
for (const line of block.code.split("\n")) {
|
|
1514
|
+
if (js || lang === null) {
|
|
1515
|
+
for (const match of line.matchAll(
|
|
1516
|
+
/\b(?:from|import|require\(|import\()\s*['"]([^'"\s]{1,214})['"]/g
|
|
1517
|
+
)) {
|
|
1518
|
+
const name = npmPackageOf(match[1] ?? "");
|
|
1519
|
+
if (name !== null) add({ ecosystem: "npm", name, line: line.trim() });
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
if (py || lang === null) {
|
|
1523
|
+
const fromImport = /^\s*from\s+([A-Za-z_][\w.]{0,100})\s+import\b/.exec(line);
|
|
1524
|
+
const plainImport = /^\s*import\s+([A-Za-z_][\w., ]{0,200})$/.exec(line);
|
|
1525
|
+
const modules = fromImport ? [fromImport[1] ?? ""] : plainImport ? (plainImport[1] ?? "").split(",").map((part) => part.trim().split(/\s+/)[0] ?? "") : [];
|
|
1526
|
+
for (const moduleName of modules) {
|
|
1527
|
+
const top = moduleName.split(".")[0] ?? "";
|
|
1528
|
+
if (top === "" || PY_STDLIB.has(top) || /['"]/.test(line)) continue;
|
|
1529
|
+
if (lang === null && /\bfrom\s+['"]/.test(line)) continue;
|
|
1530
|
+
add({ ecosystem: "pypi", name: top, line: line.trim() });
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
return out.slice(0, 40);
|
|
1536
|
+
}
|
|
1537
|
+
var PY_IMPORT_ALIASES = {
|
|
1538
|
+
bs4: "beautifulsoup4",
|
|
1539
|
+
PIL: "pillow",
|
|
1540
|
+
yaml: "pyyaml",
|
|
1541
|
+
cv2: "opencv-python",
|
|
1542
|
+
sklearn: "scikit-learn",
|
|
1543
|
+
dotenv: "python-dotenv",
|
|
1544
|
+
dateutil: "python-dateutil",
|
|
1545
|
+
jwt: "pyjwt",
|
|
1546
|
+
magic: "python-magic",
|
|
1547
|
+
OpenSSL: "pyopenssl"
|
|
1548
|
+
};
|
|
1549
|
+
function normalizePy(name) {
|
|
1550
|
+
return name.toLowerCase().replace(/[-_.]+/g, "_");
|
|
1551
|
+
}
|
|
1552
|
+
function installProvides(installed, imported) {
|
|
1553
|
+
if (installed.ecosystem !== imported.ecosystem) return false;
|
|
1554
|
+
if (installed.ecosystem === "npm") return installed.name === imported.name;
|
|
1555
|
+
const dist = normalizePy(installed.name);
|
|
1556
|
+
const importedModule = normalizePy(imported.name);
|
|
1557
|
+
const alias = PY_IMPORT_ALIASES[imported.name];
|
|
1558
|
+
if (alias !== void 0 && normalizePy(alias) === dist) return true;
|
|
1559
|
+
const stripped = dist.replace(/^(?:python|py)_/, "").replace(/_(?:python|py|sdk|client)$/, "");
|
|
1560
|
+
return dist === importedModule || stripped === importedModule || dist.startsWith(`${importedModule}_`) || importedModule.startsWith(`${stripped}_`);
|
|
1561
|
+
}
|
|
1562
|
+
var CREDENTIAL_NAME = /(?:KEY|TOKEN|SECRET|PASSWORD|PASSWD|CREDENTIAL|CREDENTIALS|AUTH|API)/;
|
|
1563
|
+
function isCredentialName(name) {
|
|
1564
|
+
return CREDENTIAL_NAME.test(name);
|
|
1565
|
+
}
|
|
1566
|
+
function envNamesReadByCode(blocks) {
|
|
1567
|
+
const names = /* @__PURE__ */ new Set();
|
|
1568
|
+
const readers = [
|
|
1569
|
+
/process\.env\.([A-Z][A-Z0-9_]{1,80})/g,
|
|
1570
|
+
/process\.env\[\s*['"]([A-Z][A-Z0-9_]{1,80})['"]\s*\]/g,
|
|
1571
|
+
/import\.meta\.env\.([A-Z][A-Z0-9_]{1,80})/g,
|
|
1572
|
+
/os\.environ\[\s*['"]([A-Z][A-Z0-9_]{1,80})['"]\s*\]/g,
|
|
1573
|
+
/os\.environ\.get\(\s*['"]([A-Z][A-Z0-9_]{1,80})['"]/g,
|
|
1574
|
+
/os\.getenv\(\s*['"]([A-Z][A-Z0-9_]{1,80})['"]/g,
|
|
1575
|
+
/Deno\.env\.get\(\s*['"]([A-Z][A-Z0-9_]{1,80})['"]/g,
|
|
1576
|
+
/\bENV\[\s*['"]([A-Z][A-Z0-9_]{1,80})['"]\s*\]/g,
|
|
1577
|
+
/os\.Getenv\(\s*"([A-Z][A-Z0-9_]{1,80})"/g,
|
|
1578
|
+
/System\.getenv\(\s*"([A-Z][A-Z0-9_]{1,80})"/g,
|
|
1579
|
+
/Environment\.GetEnvironmentVariable\(\s*"([A-Z][A-Z0-9_]{1,80})"/g
|
|
1580
|
+
];
|
|
1581
|
+
for (const block of blocks) {
|
|
1582
|
+
for (const reader of readers) {
|
|
1583
|
+
for (const match of block.code.matchAll(reader)) if (match[1]) names.add(match[1]);
|
|
1584
|
+
}
|
|
1585
|
+
if (isShellBlock(block)) {
|
|
1586
|
+
for (const line of block.code.split("\n")) {
|
|
1587
|
+
const trimmed = stripPrompt(line).trim().replace(/^export\s+/, "");
|
|
1588
|
+
if (/^[A-Z][A-Z0-9_]*=/.test(trimmed)) continue;
|
|
1589
|
+
for (const match of line.matchAll(/\$\{?([A-Z][A-Z0-9]*_[A-Z0-9_]{1,80})\}?/g)) {
|
|
1590
|
+
if (match[1]) names.add(match[1]);
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
return [...names].filter(isCredentialName).slice(0, 20);
|
|
1596
|
+
}
|
|
1597
|
+
function envNamesInSetup(doc) {
|
|
1598
|
+
const names = /* @__PURE__ */ new Set();
|
|
1599
|
+
for (const block of doc.blocks) {
|
|
1600
|
+
const setupBlock = isShellBlock(block) || block.lang === "env" || block.lang === null || block.lang === "text";
|
|
1601
|
+
if (!setupBlock) continue;
|
|
1602
|
+
for (const line of block.code.split("\n")) {
|
|
1603
|
+
const cleaned = stripPrompt(line).trim().replace(/^(?:export\s+|set\s+|\$env:)/, "");
|
|
1604
|
+
const assignment = /^([A-Z][A-Z0-9]*_[A-Z0-9_]{1,80})\s*=/.exec(cleaned);
|
|
1605
|
+
if (assignment?.[1]) names.add(assignment[1]);
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
for (const match of doc.prose.matchAll(/\b([A-Z][A-Z0-9]*_[A-Z0-9_]{1,80})\b/g)) {
|
|
1609
|
+
if (match[1]) names.add(match[1]);
|
|
1610
|
+
}
|
|
1611
|
+
return [...names].filter(isCredentialName).slice(0, 20);
|
|
1612
|
+
}
|
|
1613
|
+
var CREDENTIAL_SOURCE = [
|
|
1614
|
+
/\b(?:api[ -]?keys?|tokens?|secrets?|credentials?|access keys?)\b[^.\n]{0,100}\b(?:dashboard|settings|console|portal|account|create|generate|get|obtain|sign up|copy|issued|from)\b/i,
|
|
1615
|
+
/\b(?:dashboard|settings|console|portal|create|generate|get|obtain|copy|sign up)\b[^.\n]{0,100}\b(?:api[ -]?keys?|tokens?|secrets?|credentials?|access keys?)\b/i
|
|
1616
|
+
];
|
|
1617
|
+
function credentialSourceSentence(prose) {
|
|
1618
|
+
for (const line of prose.split("\n")) {
|
|
1619
|
+
for (const pattern of CREDENTIAL_SOURCE) {
|
|
1620
|
+
if (pattern.exec(line)) return line.length > 240 ? `${line.slice(0, 237)}\u2026` : line;
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
return null;
|
|
1624
|
+
}
|
|
1625
|
+
function examplesNeedCredential(blocks, placeholders) {
|
|
1626
|
+
const envName = envNamesReadByCode(blocks)[0];
|
|
1627
|
+
if (envName !== void 0) return envName;
|
|
1628
|
+
const keyPlaceholder = placeholders.find(
|
|
1629
|
+
(use) => /key|token|secret|password|credential/i.test(use.token)
|
|
1630
|
+
);
|
|
1631
|
+
if (keyPlaceholder !== void 0) return keyPlaceholder.token;
|
|
1632
|
+
for (const block of blocks) {
|
|
1633
|
+
const auth = /\b(?:Authorization|X-Api-Key|api[_-]?key|apiKey)\b/i.exec(block.code);
|
|
1634
|
+
if (auth) return auth[0];
|
|
1635
|
+
}
|
|
1636
|
+
return null;
|
|
1637
|
+
}
|
|
1638
|
+
function runnableExample(blocks) {
|
|
1639
|
+
for (const block of blocks) {
|
|
1640
|
+
if (elisionLines(block).length > 0) continue;
|
|
1641
|
+
if (isProgramBlock(block)) {
|
|
1642
|
+
const lines = block.code.split("\n").filter((line) => line.trim() !== "");
|
|
1643
|
+
if (lines.length >= 3 || /\b(?:import|require|from|package|using|use)\b/.test(block.code)) {
|
|
1644
|
+
return block;
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
if (isShellBlock(block) && /\bcurl\b[^\n]*https?:\/\//.test(block.code)) return block;
|
|
1648
|
+
}
|
|
1649
|
+
return null;
|
|
1650
|
+
}
|
|
1651
|
+
var VERIFY_TEXT = /\b(?:you should see|expected output|should (?:print|return|output|log|see|respond)|prints?|outputs?|returns?|responds? with|verify|confirm|check that|to test|succeeded|success(?:fully)?|if (?:it|everything) (?:works|worked))\b/i;
|
|
1652
|
+
function verificationSignal(doc, example) {
|
|
1653
|
+
for (const block of doc.blocks) {
|
|
1654
|
+
if (block.lang === "output" || block.lang === "console" || /^(?:output|response|result)\b/i.test(block.section ?? "")) {
|
|
1655
|
+
return `An output block${block.section ? ` under \u201C${block.section}\u201D` : ""}`;
|
|
1656
|
+
}
|
|
1657
|
+
const comment = /(?:\/\/|#)\s*(?:=>|→|output:|prints?:?|returns?:?|expected:?)[^\n]{0,120}/i.exec(block.code);
|
|
1658
|
+
if (comment) return comment[0].trim();
|
|
1659
|
+
}
|
|
1660
|
+
const lines = example === null ? doc.prose.split("\n") : `${example.after}
|
|
1661
|
+
${doc.prose}`.split("\n");
|
|
1662
|
+
for (const line of lines) {
|
|
1663
|
+
if (VERIFY_TEXT.test(line)) return line.length > 240 ? `${line.slice(0, 237)}\u2026` : line;
|
|
1664
|
+
}
|
|
1665
|
+
return null;
|
|
1666
|
+
}
|
|
1667
|
+
var DATE_TEXT = /\b(?:last (?:updated|modified|edited|reviewed)|updated(?: on)?|modified)\s*:?\s*((?:[A-Z][a-z]{2,8}\.? \d{1,2},? \d{4})|(?:\d{1,2} [A-Z][a-z]{2,8}\.? \d{4})|(?:\d{4}-\d{2}-\d{2})|(?:\d{1,2}\/\d{1,2}\/\d{4}))/i;
|
|
1668
|
+
function statedUpdatedDate(html, markdown) {
|
|
1669
|
+
if (html !== null) {
|
|
1670
|
+
const meta = /<meta\b[^>]*(?:property|name|itemprop)\s*=\s*["'](?:article:modified_time|og:updated_time|last-modified|dateModified|revised)["'][^>]*>/i.exec(
|
|
1671
|
+
html
|
|
1672
|
+
);
|
|
1673
|
+
if (meta) {
|
|
1674
|
+
const content = /\scontent\s*=\s*["']([^"']{4,40})["']/i.exec(meta[0]);
|
|
1675
|
+
if (content?.[1]) return { date: content[1], where: "page metadata" };
|
|
1676
|
+
}
|
|
1677
|
+
const jsonLd = /"dateModified"\s*:\s*"([^"]{4,40})"/.exec(html);
|
|
1678
|
+
if (jsonLd?.[1]) return { date: jsonLd[1], where: "structured data (dateModified)" };
|
|
1679
|
+
}
|
|
1680
|
+
if (markdown !== null && markdown.startsWith("---")) {
|
|
1681
|
+
const front = /^(?:last_?updated|lastUpdated|updated|last_modified|date_modified|modified)\s*:\s*["']?([^"'\n]{4,40})/im.exec(
|
|
1682
|
+
markdown.slice(0, 2e3)
|
|
1683
|
+
);
|
|
1684
|
+
if (front?.[1]) return { date: front[1].trim(), where: "front matter" };
|
|
1685
|
+
}
|
|
1686
|
+
const visible = [
|
|
1687
|
+
html === null ? "" : htmlProse(stripInvisible(html)).join("\n"),
|
|
1688
|
+
markdown ?? ""
|
|
1689
|
+
].join("\n");
|
|
1690
|
+
const prose = DATE_TEXT.exec(visible);
|
|
1691
|
+
if (prose?.[1]) return { date: prose[1], where: "page text" };
|
|
1692
|
+
if (html !== null) {
|
|
1693
|
+
const time = /<time\b[^>]*\sdatetime\s*=\s*["']([^"']{4,40})["']/i.exec(html);
|
|
1694
|
+
if (time?.[1]) return { date: time[1], where: "a <time> element" };
|
|
1695
|
+
}
|
|
1696
|
+
return null;
|
|
1697
|
+
}
|
|
1698
|
+
function excerpt(text2, maxLines = 4, maxChars = 280) {
|
|
1699
|
+
const lines = text2.split("\n").filter((line) => line.trim() !== "").slice(0, maxLines);
|
|
1700
|
+
const joined = lines.join("\n");
|
|
1701
|
+
return joined.length > maxChars ? `${joined.slice(0, maxChars - 1)}\u2026` : joined;
|
|
1702
|
+
}
|
|
1703
|
+
function comparablePath(href) {
|
|
1704
|
+
try {
|
|
1705
|
+
const url = new URL(href);
|
|
1706
|
+
return `${url.host}${url.pathname.replace(/\/index(?:\.html|\.htm|\.md)?$/, "").replace(/\.(?:md|html?)$/, "").replace(/\/$/, "")}`;
|
|
1707
|
+
} catch {
|
|
1708
|
+
return null;
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
function llmsTxtCoverage(body, pageUrl) {
|
|
1712
|
+
const page = comparablePath(pageUrl);
|
|
1713
|
+
if (page === null) return "no-link";
|
|
1714
|
+
const parent = page.includes("/") ? page.slice(0, page.lastIndexOf("/")) : page;
|
|
1715
|
+
let section = false;
|
|
1716
|
+
for (const match of body.matchAll(
|
|
1717
|
+
/\]\(\s*([^)\s]{1,2048})\s*\)|(https?:\/\/[^\s)>\]]{1,2048})/g
|
|
1718
|
+
)) {
|
|
1719
|
+
const raw = match[1] ?? match[2] ?? "";
|
|
1720
|
+
let href;
|
|
1721
|
+
try {
|
|
1722
|
+
href = new URL(raw, pageUrl).href;
|
|
1723
|
+
} catch {
|
|
1724
|
+
continue;
|
|
1725
|
+
}
|
|
1726
|
+
const linked = comparablePath(href);
|
|
1727
|
+
if (linked === null) continue;
|
|
1728
|
+
if (linked === page) return "links-page";
|
|
1729
|
+
if (parent.includes("/") && (linked === parent || linked.startsWith(`${parent}/`))) {
|
|
1730
|
+
section = true;
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
return section ? "links-section" : "no-link";
|
|
1734
|
+
}
|
|
1735
|
+
function codeInline(text2) {
|
|
1736
|
+
return `\`${text2.replace(/`/g, "")}\``;
|
|
1737
|
+
}
|
|
1738
|
+
function listWords(items) {
|
|
1739
|
+
if (items.length <= 1) return items.join("");
|
|
1740
|
+
return `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}`;
|
|
1741
|
+
}
|
|
1742
|
+
function namedInProse(name, prose) {
|
|
1743
|
+
const hay = prose.toLowerCase();
|
|
1744
|
+
const needle = name.toLowerCase();
|
|
1745
|
+
if (needle === "") return false;
|
|
1746
|
+
const plainWord = /^[a-z]+$/.test(needle);
|
|
1747
|
+
const outside = (ch) => ch === void 0 || !/[\w@/-]/.test(ch);
|
|
1748
|
+
for (let at = hay.indexOf(needle); at !== -1; at = hay.indexOf(needle, at + 1)) {
|
|
1749
|
+
if (!outside(hay[at - 1])) continue;
|
|
1750
|
+
const end = at + needle.length;
|
|
1751
|
+
if (hay.startsWith(".js", end) && outside(hay[end + 3])) return true;
|
|
1752
|
+
if (!outside(hay[end])) continue;
|
|
1753
|
+
if (!plainWord) return true;
|
|
1754
|
+
if (/^\s+(?:v?\d|apps?\b|projects?\b|applications?\b)/.test(hay.slice(end, end + 16))) {
|
|
1755
|
+
return true;
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
return false;
|
|
1759
|
+
}
|
|
1760
|
+
function fetchFindings(facts, html, content) {
|
|
1761
|
+
const out = [];
|
|
1762
|
+
const agentType = mediaTypeOf(facts.agent?.contentType ?? null);
|
|
1763
|
+
if (facts.markdown?.source === "negotiated") {
|
|
1764
|
+
out.push({
|
|
1765
|
+
id: "markdown-negotiated",
|
|
1766
|
+
check: "fetch",
|
|
1767
|
+
severity: "passed",
|
|
1768
|
+
title: "Serves Markdown to agents that ask for it",
|
|
1769
|
+
detail: `A request with \`Accept: text/markdown\` received \`${agentType ?? "text/markdown"}\`.`,
|
|
1770
|
+
evidence: [excerpt(facts.markdown.body.replace(/^---\n[\s\S]*?\n---\n/, ""), 3)],
|
|
1771
|
+
fix: null
|
|
1772
|
+
});
|
|
1773
|
+
} else if (facts.markdown?.source === "alternate") {
|
|
1774
|
+
out.push({
|
|
1775
|
+
id: "markdown-alternate",
|
|
1776
|
+
check: "fetch",
|
|
1777
|
+
severity: "passed",
|
|
1778
|
+
title: "Links a Markdown copy of the page",
|
|
1779
|
+
detail: `The page declares a Markdown alternate at ${facts.markdown.url}, and it returned Markdown.`,
|
|
1780
|
+
evidence: [facts.markdown.url],
|
|
1781
|
+
fix: null
|
|
1782
|
+
});
|
|
1783
|
+
} else {
|
|
1784
|
+
out.push({
|
|
1785
|
+
id: "markdown-missing",
|
|
1786
|
+
check: "fetch",
|
|
1787
|
+
severity: "should-fix",
|
|
1788
|
+
title: "No Markdown version of the page",
|
|
1789
|
+
detail: `A request with \`Accept: text/markdown\` received ${agentType === null ? "no content type" : `\`${agentType}\``}, and the page declares no Markdown alternate. Coding agents then read the HTML, navigation and all.`,
|
|
1790
|
+
evidence: [`Content-Type: ${facts.agent?.contentType ?? "not sent"}`],
|
|
1791
|
+
fix: 'Serve `text/markdown` when the Accept header prefers it, or link a copy with `<link rel="alternate" type="text/markdown" href="\u2026">`.'
|
|
1792
|
+
});
|
|
1793
|
+
}
|
|
1794
|
+
const htmlBlocks = html?.blocks.length ?? 0;
|
|
1795
|
+
const contentBlocks = content?.blocks.length ?? 0;
|
|
1796
|
+
if (html !== null && htmlBlocks > 0) {
|
|
1797
|
+
out.push({
|
|
1798
|
+
id: "server-html-has-code",
|
|
1799
|
+
check: "fetch",
|
|
1800
|
+
severity: "passed",
|
|
1801
|
+
title: "Instructions are in the server HTML",
|
|
1802
|
+
detail: `The HTML response contains ${htmlBlocks} code ${htmlBlocks === 1 ? "block" : "blocks"} before any JavaScript runs.`,
|
|
1803
|
+
evidence: [excerpt(html.blocks[0]?.code ?? "", 2)],
|
|
1804
|
+
fix: null
|
|
1805
|
+
});
|
|
1806
|
+
} else if (html !== null && facts.markdown !== null && contentBlocks > 0) {
|
|
1807
|
+
out.push({
|
|
1808
|
+
id: "code-needs-javascript",
|
|
1809
|
+
check: "fetch",
|
|
1810
|
+
severity: "should-fix",
|
|
1811
|
+
title: "Code examples appear only after JavaScript runs",
|
|
1812
|
+
detail: `The Markdown copy has ${contentBlocks} code ${contentBlocks === 1 ? "block" : "blocks"}, but the HTML response has none. Agents that fetch the HTML without running JavaScript see no commands.`,
|
|
1813
|
+
evidence: [`${html.prose.length} characters of text and 0 code blocks in the HTML response`],
|
|
1814
|
+
fix: "Render code examples on the server, or prerender the docs pages."
|
|
1815
|
+
});
|
|
1816
|
+
} else if (html !== null && contentBlocks === 0 && html.prose.length < 400) {
|
|
1817
|
+
out.push({
|
|
1818
|
+
id: "content-needs-javascript",
|
|
1819
|
+
check: "fetch",
|
|
1820
|
+
severity: "blocking",
|
|
1821
|
+
title: "The page content needs JavaScript to appear",
|
|
1822
|
+
detail: `The HTML response holds only ${html.prose.length} characters of text and no code blocks, so an agent that reads the response sees no instructions.`,
|
|
1823
|
+
evidence: [excerpt(html.prose, 3) || "(no visible text)"],
|
|
1824
|
+
fix: "Render the docs on the server or prerender them, and serve a Markdown copy to agents."
|
|
1825
|
+
});
|
|
1826
|
+
}
|
|
1827
|
+
if (facts.llmsTxt.state === "missing") {
|
|
1828
|
+
out.push({
|
|
1829
|
+
id: "llms-txt-missing",
|
|
1830
|
+
check: "fetch",
|
|
1831
|
+
severity: "should-fix",
|
|
1832
|
+
title: "No /llms.txt on this site",
|
|
1833
|
+
detail: `${facts.llmsTxt.url} did not return a file. An llms.txt gives agents a map of the docs, with links to the pages that matter.`,
|
|
1834
|
+
evidence: [facts.llmsTxt.url],
|
|
1835
|
+
fix: "Publish /llms.txt with a link to this page under its section."
|
|
1836
|
+
});
|
|
1837
|
+
} else if (facts.llmsTxt.state === "found" && facts.llmsTxt.body !== null) {
|
|
1838
|
+
const coverage = llmsTxtCoverage(facts.llmsTxt.body, facts.url);
|
|
1839
|
+
if (coverage === "no-link") {
|
|
1840
|
+
out.push({
|
|
1841
|
+
id: "llms-txt-no-link",
|
|
1842
|
+
check: "fetch",
|
|
1843
|
+
severity: "should-fix",
|
|
1844
|
+
title: "/llms.txt does not link this page",
|
|
1845
|
+
detail: "The site has an llms.txt, but no link in it points at this page or its section.",
|
|
1846
|
+
evidence: [facts.llmsTxt.url],
|
|
1847
|
+
fix: `Add a link to ${facts.url} under the matching section of /llms.txt.`
|
|
1848
|
+
});
|
|
1849
|
+
} else {
|
|
1850
|
+
out.push({
|
|
1851
|
+
id: coverage === "links-page" ? "llms-txt-links-page" : "llms-txt-links-section",
|
|
1852
|
+
check: "fetch",
|
|
1853
|
+
severity: "passed",
|
|
1854
|
+
title: coverage === "links-page" ? "/llms.txt links this page" : "/llms.txt links this section",
|
|
1855
|
+
detail: coverage === "links-page" ? "An agent starting from /llms.txt can find this page." : "An agent starting from /llms.txt can find pages next to this one.",
|
|
1856
|
+
evidence: [facts.llmsTxt.url],
|
|
1857
|
+
fix: null
|
|
1858
|
+
});
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
return out;
|
|
1862
|
+
}
|
|
1863
|
+
function codeFindings(doc) {
|
|
1864
|
+
const out = [];
|
|
1865
|
+
const blocks = doc.blocks;
|
|
1866
|
+
if (blocks.length === 0) {
|
|
1867
|
+
out.push({
|
|
1868
|
+
id: "no-code",
|
|
1869
|
+
check: "code",
|
|
1870
|
+
severity: "blocking",
|
|
1871
|
+
title: "No code examples on this page",
|
|
1872
|
+
detail: "The page has no code blocks, so an agent has no command or snippet to copy.",
|
|
1873
|
+
evidence: [excerpt(doc.prose, 2) || "(no visible text)"],
|
|
1874
|
+
fix: "Show the install command and a minimal example as code blocks."
|
|
1875
|
+
});
|
|
1876
|
+
return out;
|
|
1877
|
+
}
|
|
1878
|
+
const unlabeled = blocks.filter((block) => block.lang === null);
|
|
1879
|
+
if (unlabeled.length > 0) {
|
|
1880
|
+
out.push({
|
|
1881
|
+
id: "code-unlabeled",
|
|
1882
|
+
check: "code",
|
|
1883
|
+
severity: "should-fix",
|
|
1884
|
+
title: `${unlabeled.length} of ${blocks.length} code ${blocks.length === 1 ? "block" : "blocks"} ${unlabeled.length === 1 ? "has" : "have"} no language label`,
|
|
1885
|
+
detail: "Without a label an agent has to guess which blocks are terminal commands and which are source files.",
|
|
1886
|
+
evidence: unlabeled.slice(0, 3).map((block) => excerpt(block.code, 2)),
|
|
1887
|
+
fix: "Label every block (```bash, ```ts, ```python) and use `text` for output."
|
|
1888
|
+
});
|
|
1889
|
+
} else {
|
|
1890
|
+
out.push({
|
|
1891
|
+
id: "code-labeled",
|
|
1892
|
+
check: "code",
|
|
1893
|
+
severity: "passed",
|
|
1894
|
+
title: "Every code block has a language label",
|
|
1895
|
+
detail: `${blocks.length} code ${blocks.length === 1 ? "block" : "blocks"}, all labeled.`,
|
|
1896
|
+
evidence: [],
|
|
1897
|
+
fix: null
|
|
1898
|
+
});
|
|
1899
|
+
}
|
|
1900
|
+
const prompted = [];
|
|
1901
|
+
for (const block of blocks) {
|
|
1902
|
+
if (!isShellBlock(block)) continue;
|
|
1903
|
+
const use = promptUse(block);
|
|
1904
|
+
if (use.promptLines.length > 0) {
|
|
1905
|
+
prompted.push({ block, prompts: use.promptLines, output: use.outputLines });
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
const mixed = prompted.filter((entry) => entry.output.length > 0);
|
|
1909
|
+
if (mixed.length > 0) {
|
|
1910
|
+
out.push({
|
|
1911
|
+
id: "shell-mixes-output",
|
|
1912
|
+
check: "code",
|
|
1913
|
+
severity: "should-fix",
|
|
1914
|
+
title: "Shell examples mix commands with their output",
|
|
1915
|
+
detail: `${mixed.length} terminal ${mixed.length === 1 ? "block puts" : "blocks put"} \`$\`-prompted commands and output lines together. Copied whole, the output lines run as commands.`,
|
|
1916
|
+
evidence: mixed.slice(0, 3).map((entry) => excerpt(entry.block.code, 4)),
|
|
1917
|
+
fix: "Put commands in their own block with no prompt, and show expected output in a separate `text` block."
|
|
1918
|
+
});
|
|
1919
|
+
} else if (prompted.length > 0) {
|
|
1920
|
+
out.push({
|
|
1921
|
+
id: "shell-prompts",
|
|
1922
|
+
check: "code",
|
|
1923
|
+
severity: "should-fix",
|
|
1924
|
+
title: "Shell commands start with a prompt",
|
|
1925
|
+
detail: "Copied as written, `$ npm install` fails with \u201Ccommand not found: $\u201D.",
|
|
1926
|
+
evidence: prompted.slice(0, 3).map((entry) => entry.prompts[0]?.trim() ?? ""),
|
|
1927
|
+
fix: "Remove the `$` prompts from command blocks."
|
|
1928
|
+
});
|
|
1929
|
+
}
|
|
1930
|
+
const placeholders = findPlaceholders(blocks);
|
|
1931
|
+
const unexplained = placeholders.filter((use) => !use.explained);
|
|
1932
|
+
for (const use of unexplained.slice(0, 3)) {
|
|
1933
|
+
out.push({
|
|
1934
|
+
id: "placeholder-unexplained",
|
|
1935
|
+
check: "code",
|
|
1936
|
+
severity: "blocking",
|
|
1937
|
+
title: `Placeholder ${codeInline(use.token)} has no explanation`,
|
|
1938
|
+
detail: `The text around this block does not say what to put in ${codeInline(use.token)} or where that value comes from, so an agent cannot fill it in.`,
|
|
1939
|
+
evidence: [use.line],
|
|
1940
|
+
fix: `Say where ${codeInline(use.token)} comes from next to the block (for example, \u201CCreate a key under Settings \u2192 API keys\u201D), or read it from an environment variable the setup step names.`
|
|
1941
|
+
});
|
|
1942
|
+
}
|
|
1943
|
+
if (placeholders.length > 0 && unexplained.length === 0) {
|
|
1944
|
+
out.push({
|
|
1945
|
+
id: "placeholders-explained",
|
|
1946
|
+
check: "code",
|
|
1947
|
+
severity: "passed",
|
|
1948
|
+
title: "Placeholders are explained",
|
|
1949
|
+
detail: `${listWords(placeholders.slice(0, 4).map((use) => codeInline(use.token)))} ${placeholders.length === 1 ? "is" : "are"} explained next to the code.`,
|
|
1950
|
+
evidence: [],
|
|
1951
|
+
fix: null
|
|
1952
|
+
});
|
|
1953
|
+
}
|
|
1954
|
+
const elided = blocks.map((block) => ({ block, lines: elisionLines(block) })).filter((entry) => entry.lines.length > 0);
|
|
1955
|
+
if (elided.length > 0) {
|
|
1956
|
+
out.push({
|
|
1957
|
+
id: "code-elisions",
|
|
1958
|
+
check: "code",
|
|
1959
|
+
severity: "should-fix",
|
|
1960
|
+
title: "Code meant to be run has \u201C...\u201D gaps",
|
|
1961
|
+
detail: `${elided.length} code ${elided.length === 1 ? "block leaves" : "blocks leave"} out part of the code with \`...\`. An agent copying the block gets code that does not parse or run.`,
|
|
1962
|
+
evidence: elided.slice(0, 3).map((entry) => entry.lines[0]?.trim() ?? ""),
|
|
1963
|
+
fix: "Show the complete snippet, or mark the block as a fragment and link the full example."
|
|
1964
|
+
});
|
|
1965
|
+
}
|
|
1966
|
+
const installHeading = /\b(?:install|installation|set ?up|getting started|quick ?start|configure|configuration|prerequisites?|step \d+)\b/i;
|
|
1967
|
+
let section = null;
|
|
1968
|
+
let sectionHasCode = false;
|
|
1969
|
+
let sectionImages = [];
|
|
1970
|
+
const imageOnly = [];
|
|
1971
|
+
const flush = () => {
|
|
1972
|
+
if (section !== null && installHeading.test(section) && !sectionHasCode && sectionImages.length > 0) {
|
|
1973
|
+
const image = sectionImages[0];
|
|
1974
|
+
imageOnly.push(
|
|
1975
|
+
`\u201C${section}\u201D: ${image?.alt ? `image \u201C${image.alt}\u201D` : `image ${image?.src ?? ""}`}`
|
|
1976
|
+
);
|
|
1977
|
+
}
|
|
1978
|
+
};
|
|
1979
|
+
for (const node of doc.nodes) {
|
|
1980
|
+
if (node.kind === "heading") {
|
|
1981
|
+
flush();
|
|
1982
|
+
section = node.text;
|
|
1983
|
+
sectionHasCode = false;
|
|
1984
|
+
sectionImages = [];
|
|
1985
|
+
} else if (node.kind === "code") sectionHasCode = true;
|
|
1986
|
+
else if (node.kind === "image") sectionImages.push(node);
|
|
1987
|
+
}
|
|
1988
|
+
flush();
|
|
1989
|
+
if (imageOnly.length > 0) {
|
|
1990
|
+
out.push({
|
|
1991
|
+
id: "screenshot-only-step",
|
|
1992
|
+
check: "code",
|
|
1993
|
+
severity: "should-fix",
|
|
1994
|
+
title: "A setup step is shown only as an image",
|
|
1995
|
+
detail: "These setup sections have a screenshot and no command or code. An agent cannot read the step from the image.",
|
|
1996
|
+
evidence: imageOnly.slice(0, 3),
|
|
1997
|
+
fix: "Write the step as text, with the exact command, setting name or value, and keep the screenshot as a supplement."
|
|
1998
|
+
});
|
|
1999
|
+
}
|
|
2000
|
+
return out;
|
|
2001
|
+
}
|
|
2002
|
+
function installFindings(commands, imports, prose) {
|
|
2003
|
+
const out = [];
|
|
2004
|
+
if (commands.length === 0) {
|
|
2005
|
+
const first = imports[0];
|
|
2006
|
+
out.push(
|
|
2007
|
+
first !== void 0 ? {
|
|
2008
|
+
id: "install-missing",
|
|
2009
|
+
check: "install",
|
|
2010
|
+
severity: "blocking",
|
|
2011
|
+
title: `The examples import ${codeInline(first.name)}, but the page never installs it`,
|
|
2012
|
+
detail: "There is no install command on the page, so an agent has to guess the package name and manager.",
|
|
2013
|
+
evidence: [first.line],
|
|
2014
|
+
fix: `Add the install command for each package manager you support, for example ${codeInline(first.ecosystem === "npm" ? `npm install ${first.name}` : `pip install ${first.name}`)}.`
|
|
2015
|
+
} : {
|
|
2016
|
+
id: "install-none",
|
|
2017
|
+
check: "install",
|
|
2018
|
+
severity: "should-fix",
|
|
2019
|
+
title: "No install command on this page",
|
|
2020
|
+
detail: "If this page is where a developer starts, an agent needs the exact install command here.",
|
|
2021
|
+
evidence: [],
|
|
2022
|
+
fix: "Add the install command near the top, in a labeled terminal block."
|
|
2023
|
+
}
|
|
2024
|
+
);
|
|
2025
|
+
return out;
|
|
2026
|
+
}
|
|
2027
|
+
const managers = [...new Set(commands.map((command) => command.manager))];
|
|
2028
|
+
out.push({
|
|
2029
|
+
id: "install-found",
|
|
2030
|
+
check: "install",
|
|
2031
|
+
severity: "passed",
|
|
2032
|
+
title: `Install command for ${listWords(managers)}`,
|
|
2033
|
+
detail: `The page shows ${commands.length === 1 ? "an install command" : `${commands.length} install commands`}.`,
|
|
2034
|
+
evidence: commands.slice(0, 3).map((command) => command.line),
|
|
2035
|
+
fix: null
|
|
2036
|
+
});
|
|
2037
|
+
for (const ecosystem of ["npm", "pypi"]) {
|
|
2038
|
+
const installed = commands.flatMap((command) => command.packages).filter((ref) => ref.ecosystem === ecosystem);
|
|
2039
|
+
const imported = imports.filter((ref) => ref.ecosystem === ecosystem);
|
|
2040
|
+
if (installed.length === 0 || imported.length === 0) continue;
|
|
2041
|
+
const provided = imported.filter((ref) => installed.some((pkg) => installProvides(pkg, ref)));
|
|
2042
|
+
if (provided.length === 0) {
|
|
2043
|
+
const importedRef = imported[0];
|
|
2044
|
+
out.push({
|
|
2045
|
+
id: "install-import-mismatch",
|
|
2046
|
+
check: "install",
|
|
2047
|
+
severity: "blocking",
|
|
2048
|
+
title: "The install command and the import name different packages",
|
|
2049
|
+
detail: `The page installs ${listWords(installed.slice(0, 3).map((ref) => codeInline(ref.name)))} but the example imports ${codeInline(importedRef?.name ?? "")}. An agent following both gets a \u201Cmodule not found\u201D error.`,
|
|
2050
|
+
evidence: [installed[0]?.evidence ?? "", importedRef?.line ?? ""],
|
|
2051
|
+
fix: "Make the install command and the import use the same package name."
|
|
2052
|
+
});
|
|
2053
|
+
continue;
|
|
2054
|
+
}
|
|
2055
|
+
const missing = imported.filter(
|
|
2056
|
+
(ref) => !installed.some((pkg) => installProvides(pkg, ref)) && !namedInProse(ref.name, prose)
|
|
2057
|
+
);
|
|
2058
|
+
if (missing.length > 0) {
|
|
2059
|
+
out.push({
|
|
2060
|
+
id: "import-not-installed",
|
|
2061
|
+
check: "install",
|
|
2062
|
+
severity: "should-fix",
|
|
2063
|
+
title: `The examples import ${listWords(missing.slice(0, 3).map((ref) => codeInline(ref.name)))}, which the install step does not install`,
|
|
2064
|
+
detail: "If the example needs these packages, an agent has to discover that from an error.",
|
|
2065
|
+
evidence: missing.slice(0, 3).map((ref) => ref.line),
|
|
2066
|
+
fix: "Add the packages to the install command, or say that they are already expected in the project."
|
|
2067
|
+
});
|
|
2068
|
+
} else {
|
|
2069
|
+
out.push({
|
|
2070
|
+
id: "install-import-match",
|
|
2071
|
+
check: "install",
|
|
2072
|
+
severity: "passed",
|
|
2073
|
+
title: "Install and import names match",
|
|
2074
|
+
detail: `${listWords(provided.slice(0, 3).map((ref) => codeInline(ref.name)))} ${provided.length === 1 ? "is" : "are"} installed and imported under the same name.`,
|
|
2075
|
+
evidence: [],
|
|
2076
|
+
fix: null
|
|
2077
|
+
});
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
return out;
|
|
2081
|
+
}
|
|
2082
|
+
function authFindings(doc) {
|
|
2083
|
+
const out = [];
|
|
2084
|
+
const placeholders = findPlaceholders(doc.blocks);
|
|
2085
|
+
const needs = examplesNeedCredential(doc.blocks, placeholders);
|
|
2086
|
+
if (needs !== null) {
|
|
2087
|
+
const source = credentialSourceSentence(doc.prose);
|
|
2088
|
+
out.push(
|
|
2089
|
+
source === null ? {
|
|
2090
|
+
id: "credential-source-missing",
|
|
2091
|
+
check: "auth",
|
|
2092
|
+
severity: "blocking",
|
|
2093
|
+
title: "The page does not say where the credential comes from",
|
|
2094
|
+
detail: `The examples use ${codeInline(needs)}, but no step says where to create or copy it.`,
|
|
2095
|
+
evidence: [needs],
|
|
2096
|
+
fix: "Add a step before the example: where to create the key (the exact page or command) and which environment variable to put it in."
|
|
2097
|
+
} : {
|
|
2098
|
+
id: "credential-source",
|
|
2099
|
+
check: "auth",
|
|
2100
|
+
severity: "passed",
|
|
2101
|
+
title: "Says where the credential comes from",
|
|
2102
|
+
detail: "The setup text names where to get the credential the examples use.",
|
|
2103
|
+
evidence: [source],
|
|
2104
|
+
fix: null
|
|
2105
|
+
}
|
|
2106
|
+
);
|
|
2107
|
+
}
|
|
2108
|
+
const readByCode = envNamesReadByCode(doc.blocks);
|
|
2109
|
+
const inSetup = envNamesInSetup(doc);
|
|
2110
|
+
if (readByCode.length > 0) {
|
|
2111
|
+
const unset = readByCode.filter((name) => !inSetup.includes(name));
|
|
2112
|
+
const unused = inSetup.filter((name) => !readByCode.includes(name));
|
|
2113
|
+
if (unset.length > 0 && unused.length > 0) {
|
|
2114
|
+
out.push({
|
|
2115
|
+
id: "env-name-mismatch",
|
|
2116
|
+
check: "auth",
|
|
2117
|
+
severity: "blocking",
|
|
2118
|
+
title: `The setup sets ${codeInline(unused[0] ?? "")} but the code reads ${codeInline(unset[0] ?? "")}`,
|
|
2119
|
+
detail: "An agent that follows the setup step exactly ends up with an empty credential in the example.",
|
|
2120
|
+
evidence: [...unused.slice(0, 2), ...unset.slice(0, 2)],
|
|
2121
|
+
fix: "Use one environment variable name in the setup text and in every example."
|
|
2122
|
+
});
|
|
2123
|
+
} else if (unset.length > 0) {
|
|
2124
|
+
out.push({
|
|
2125
|
+
id: "env-name-unexplained",
|
|
2126
|
+
check: "auth",
|
|
2127
|
+
severity: "should-fix",
|
|
2128
|
+
title: `The code reads ${listWords(unset.slice(0, 3).map(codeInline))}, which the setup never mentions`,
|
|
2129
|
+
detail: "Name the variable in the setup step so an agent sets it before running the example.",
|
|
2130
|
+
evidence: unset.slice(0, 3),
|
|
2131
|
+
fix: `Add a setup step such as ${codeInline(`export ${unset[0] ?? "API_KEY"}=\u2026`)} with where the value comes from.`
|
|
2132
|
+
});
|
|
2133
|
+
} else {
|
|
2134
|
+
out.push({
|
|
2135
|
+
id: "env-names-match",
|
|
2136
|
+
check: "auth",
|
|
2137
|
+
severity: "passed",
|
|
2138
|
+
title: "Environment variable names match",
|
|
2139
|
+
detail: `${listWords(readByCode.slice(0, 3).map(codeInline))} ${readByCode.length === 1 ? "is" : "are"} named in the setup and read by the code.`,
|
|
2140
|
+
evidence: [],
|
|
2141
|
+
fix: null
|
|
2142
|
+
});
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
const example = runnableExample(doc.blocks);
|
|
2146
|
+
if (example === null) {
|
|
2147
|
+
out.push({
|
|
2148
|
+
id: "runnable-example-missing",
|
|
2149
|
+
check: "auth",
|
|
2150
|
+
severity: "should-fix",
|
|
2151
|
+
title: "No complete example to run",
|
|
2152
|
+
detail: "No code block is a complete program or request: each is either a fragment, has `...` gaps, or is only an install command.",
|
|
2153
|
+
evidence: [],
|
|
2154
|
+
fix: "Add one minimal, complete example that runs as written after the install and setup steps."
|
|
2155
|
+
});
|
|
2156
|
+
} else {
|
|
2157
|
+
out.push({
|
|
2158
|
+
id: "runnable-example",
|
|
2159
|
+
check: "auth",
|
|
2160
|
+
severity: "passed",
|
|
2161
|
+
title: "Has a minimal example to run",
|
|
2162
|
+
detail: `${example.section ? `Under \u201C${example.section}\u201D, a` : "A"} ${example.lang ?? "terminal"} block reads as a complete example.`,
|
|
2163
|
+
evidence: [excerpt(example.code, 3)],
|
|
2164
|
+
fix: null
|
|
2165
|
+
});
|
|
2166
|
+
}
|
|
2167
|
+
const verification = verificationSignal(doc, example);
|
|
2168
|
+
out.push(
|
|
2169
|
+
verification === null ? {
|
|
2170
|
+
id: "verification-missing",
|
|
2171
|
+
check: "auth",
|
|
2172
|
+
severity: "should-fix",
|
|
2173
|
+
title: "No way to confirm the example worked",
|
|
2174
|
+
detail: "The page shows no expected output and no check command, so an agent cannot tell success from a silent failure.",
|
|
2175
|
+
evidence: [],
|
|
2176
|
+
fix: "Show the expected output after the example, or a command that confirms the setup (for example, one that prints the SDK version or a test response)."
|
|
2177
|
+
} : {
|
|
2178
|
+
id: "verification",
|
|
2179
|
+
check: "auth",
|
|
2180
|
+
severity: "passed",
|
|
2181
|
+
title: "States how to confirm it worked",
|
|
2182
|
+
detail: "The page shows expected output or a check.",
|
|
2183
|
+
evidence: [verification],
|
|
2184
|
+
fix: null
|
|
2185
|
+
}
|
|
2186
|
+
);
|
|
2187
|
+
return out;
|
|
2188
|
+
}
|
|
2189
|
+
function freshnessFindings(facts) {
|
|
2190
|
+
const html = facts.browser !== null && facts.browser.body !== null && !isMarkdownResponse(facts.browser.contentType, facts.browser.body) ? facts.browser.body : null;
|
|
2191
|
+
const stated = statedUpdatedDate(html, facts.markdown?.body ?? null);
|
|
2192
|
+
return [
|
|
2193
|
+
stated === null ? {
|
|
2194
|
+
id: "updated-date-missing",
|
|
2195
|
+
check: "freshness",
|
|
2196
|
+
severity: "should-fix",
|
|
2197
|
+
title: "No last-updated date on the page",
|
|
2198
|
+
detail: "A stated date tells an agent, and the developer reviewing its work, how current the instructions are.",
|
|
2199
|
+
evidence: [],
|
|
2200
|
+
fix: "Show a \u201CLast updated\u201D date, and include `dateModified` in the page\u2019s structured data."
|
|
2201
|
+
} : {
|
|
2202
|
+
id: "updated-date",
|
|
2203
|
+
check: "freshness",
|
|
2204
|
+
severity: "passed",
|
|
2205
|
+
title: `States a last-updated date: ${stated.date}`,
|
|
2206
|
+
detail: `Found in ${stated.where}.`,
|
|
2207
|
+
evidence: [stated.date],
|
|
2208
|
+
fix: null
|
|
2209
|
+
}
|
|
2210
|
+
];
|
|
2211
|
+
}
|
|
2212
|
+
var STEP_ORDER = {
|
|
2213
|
+
fetch: 0,
|
|
2214
|
+
install: 1,
|
|
2215
|
+
code: 2,
|
|
2216
|
+
auth: 3,
|
|
2217
|
+
freshness: 4
|
|
2218
|
+
};
|
|
2219
|
+
var SEVERITY_ORDER = {
|
|
2220
|
+
blocking: 0,
|
|
2221
|
+
"should-fix": 1,
|
|
2222
|
+
passed: 2
|
|
2223
|
+
};
|
|
2224
|
+
function analyzeDocsFacts(facts, checkedAt) {
|
|
2225
|
+
const htmlBody = is2xx(facts.browser) && !isMarkdownResponse(facts.browser.contentType, facts.browser.body) ? facts.browser.body : null;
|
|
2226
|
+
const html = htmlBody === null ? null : parseHtmlDocument(htmlBody);
|
|
2227
|
+
const markdown = facts.markdown === null ? null : parseMarkdownDocument(facts.markdown.body);
|
|
2228
|
+
const content = markdown ?? html;
|
|
2229
|
+
const findings = [];
|
|
2230
|
+
const finalUrl = facts.browser?.finalUrl ?? facts.agent?.finalUrl ?? facts.url;
|
|
2231
|
+
const browserStatus = facts.browser?.status ?? null;
|
|
2232
|
+
if (content === null) {
|
|
2233
|
+
findings.push({
|
|
2234
|
+
id: "page-unreadable",
|
|
2235
|
+
check: "fetch",
|
|
2236
|
+
severity: "blocking",
|
|
2237
|
+
title: browserStatus === null ? "The page could not be fetched" : `The page returned HTTP ${browserStatus}`,
|
|
2238
|
+
detail: browserStatus === null ? "Neither request reached the page, so an agent cannot read it either." : "An agent requesting this address gets an error instead of the instructions.",
|
|
2239
|
+
evidence: [finalUrl],
|
|
2240
|
+
fix: "Make the page publicly reachable at this address with a 200 response."
|
|
2241
|
+
});
|
|
2242
|
+
} else {
|
|
2243
|
+
findings.push(...fetchFindings(facts, html, content));
|
|
2244
|
+
findings.push(...codeFindings(content));
|
|
2245
|
+
const commands = findInstallCommands(content);
|
|
2246
|
+
findings.push(...installFindings(commands, findImports(content), content.prose));
|
|
2247
|
+
findings.push(...authFindings(content));
|
|
2248
|
+
findings.push(...freshnessFindings(facts));
|
|
2249
|
+
}
|
|
2250
|
+
const ordered = findings.map((finding, position) => ({ finding, position })).sort(
|
|
2251
|
+
(a, b) => SEVERITY_ORDER[a.finding.severity] - SEVERITY_ORDER[b.finding.severity] || STEP_ORDER[a.finding.check] - STEP_ORDER[b.finding.check] || a.position - b.position
|
|
2252
|
+
).map((entry) => ({
|
|
2253
|
+
...entry.finding,
|
|
2254
|
+
evidence: entry.finding.evidence.filter((item) => item !== "").slice(0, 3)
|
|
2255
|
+
}));
|
|
2256
|
+
const blocking = ordered.filter((finding) => finding.severity === "blocking");
|
|
2257
|
+
const shouldFix = ordered.filter((finding) => finding.severity === "should-fix");
|
|
2258
|
+
const passed = ordered.filter((finding) => finding.severity === "passed");
|
|
2259
|
+
return {
|
|
2260
|
+
url: facts.url,
|
|
2261
|
+
finalUrl,
|
|
2262
|
+
checkedAt: checkedAt.toISOString(),
|
|
2263
|
+
verdict: blocking.length === 0 ? "can-follow" : "likely-stuck",
|
|
2264
|
+
stuckAt: blocking.map((finding) => finding.title),
|
|
2265
|
+
analyzedSource: facts.markdown !== null ? "markdown" : "html",
|
|
2266
|
+
fetch: {
|
|
2267
|
+
browserStatus,
|
|
2268
|
+
agentStatus: facts.agent?.status ?? null,
|
|
2269
|
+
agentContentType: facts.agent?.contentType ?? null,
|
|
2270
|
+
markdown: facts.markdown?.source ?? "none",
|
|
2271
|
+
markdownUrl: facts.markdown?.url ?? null,
|
|
2272
|
+
serverHtmlCodeBlocks: html?.blocks.length ?? 0,
|
|
2273
|
+
llmsTxt: facts.llmsTxt.state === "found" && facts.llmsTxt.body !== null ? llmsTxtCoverage(facts.llmsTxt.body, facts.url) : facts.llmsTxt.state === "found" ? "no-link" : facts.llmsTxt.state
|
|
2274
|
+
},
|
|
2275
|
+
installManagers: content === null ? [] : [...new Set(findInstallCommands(content).map((command) => command.manager))],
|
|
2276
|
+
blocking,
|
|
2277
|
+
shouldFix,
|
|
2278
|
+
passed,
|
|
2279
|
+
findings: ordered,
|
|
2280
|
+
scope: DOCS_CHECK_SCOPE
|
|
2281
|
+
};
|
|
2282
|
+
}
|
|
2283
|
+
function analyzeDocsEvidence(evidence, checkedAt) {
|
|
2284
|
+
return analyzeDocsFacts(factsFromEvidence(evidence), checkedAt);
|
|
2285
|
+
}
|
|
2286
|
+
async function runDocsCheck(command, probe, now) {
|
|
2287
|
+
const outcome = await probe(command.url);
|
|
2288
|
+
if (!outcome.ok) {
|
|
2289
|
+
return {
|
|
2290
|
+
kind: "rejected",
|
|
2291
|
+
url: command.url,
|
|
2292
|
+
failOnBlocking: command.failOnBlocking,
|
|
2293
|
+
rejection: outcome.rejection,
|
|
2294
|
+
detail: outcome.detail
|
|
2295
|
+
};
|
|
2296
|
+
}
|
|
2297
|
+
const { status, detail } = classifyEvidenceStatus(outcome.evidence);
|
|
2298
|
+
const report = analyzeDocsEvidence(outcome.evidence, now);
|
|
2299
|
+
return {
|
|
2300
|
+
kind: "probed",
|
|
2301
|
+
url: command.url,
|
|
2302
|
+
failOnBlocking: command.failOnBlocking,
|
|
2303
|
+
probeStatus: status,
|
|
2304
|
+
probeDetail: detail,
|
|
2305
|
+
report
|
|
2306
|
+
};
|
|
2307
|
+
}
|
|
2308
|
+
function exitCodeForDocsCheck(payload) {
|
|
2309
|
+
if (payload.kind === "rejected") {
|
|
2310
|
+
return payload.rejection === "invalid-url" ? EXIT.USAGE : EXIT.POLICY;
|
|
2311
|
+
}
|
|
2312
|
+
if (payload.probeStatus === "policy") return EXIT.POLICY;
|
|
2313
|
+
if (payload.probeStatus === "unreachable") return EXIT.PROBE;
|
|
2314
|
+
if (payload.failOnBlocking && payload.report.blocking.length > 0) return EXIT.THRESHOLD;
|
|
2315
|
+
return EXIT.OK;
|
|
2316
|
+
}
|
|
2317
|
+
|
|
779
2318
|
// src/disclosure.ts
|
|
780
2319
|
var ARS_NOTICE_LINES = [
|
|
781
2320
|
"ARS measures format and retrievability. It does not measure whether the",
|
|
@@ -885,6 +2424,34 @@ function jsonValue(payload, ctx) {
|
|
|
885
2424
|
...report.kind === "rejected" ? { rejection: report.rejection, detail: report.detail, result: null } : { rejection: null, detail: null, result: report.result }
|
|
886
2425
|
}))
|
|
887
2426
|
};
|
|
2427
|
+
case "docs-check": {
|
|
2428
|
+
const { docsCheck } = payload;
|
|
2429
|
+
const exitCode = exitCodeForDocsCheck(docsCheck);
|
|
2430
|
+
if (docsCheck.kind === "rejected") {
|
|
2431
|
+
return {
|
|
2432
|
+
...envelope,
|
|
2433
|
+
command: "docs-check",
|
|
2434
|
+
url: docsCheck.url,
|
|
2435
|
+
failOnBlocking: docsCheck.failOnBlocking,
|
|
2436
|
+
status: "rejected",
|
|
2437
|
+
exitCode,
|
|
2438
|
+
rejection: docsCheck.rejection,
|
|
2439
|
+
detail: docsCheck.detail,
|
|
2440
|
+
report: null
|
|
2441
|
+
};
|
|
2442
|
+
}
|
|
2443
|
+
return {
|
|
2444
|
+
...envelope,
|
|
2445
|
+
command: "docs-check",
|
|
2446
|
+
url: docsCheck.url,
|
|
2447
|
+
failOnBlocking: docsCheck.failOnBlocking,
|
|
2448
|
+
status: docsCheck.probeStatus,
|
|
2449
|
+
exitCode,
|
|
2450
|
+
rejection: null,
|
|
2451
|
+
detail: docsCheck.probeDetail,
|
|
2452
|
+
report: docsCheck.report
|
|
2453
|
+
};
|
|
2454
|
+
}
|
|
888
2455
|
case "diff":
|
|
889
2456
|
return {
|
|
890
2457
|
...envelope,
|
|
@@ -958,6 +2525,12 @@ function renderJunit(payload, ctx) {
|
|
|
958
2525
|
failures += suite.failures;
|
|
959
2526
|
errors += suite.errors;
|
|
960
2527
|
}
|
|
2528
|
+
} else if (payload.command === "docs-check") {
|
|
2529
|
+
const suite = docsCheckSuite(payload.docsCheck, ctx);
|
|
2530
|
+
suites.push(suite.xml);
|
|
2531
|
+
tests += suite.tests;
|
|
2532
|
+
failures += suite.failures;
|
|
2533
|
+
errors += suite.errors;
|
|
961
2534
|
} else if (payload.command === "diff") {
|
|
962
2535
|
const suite = checkSuite(payload.diff.report, null, ctx);
|
|
963
2536
|
suites.push(suite.xml);
|
|
@@ -977,6 +2550,72 @@ function renderJunit(payload, ctx) {
|
|
|
977
2550
|
""
|
|
978
2551
|
].join("\n");
|
|
979
2552
|
}
|
|
2553
|
+
function docsCheckSuite(payload, ctx) {
|
|
2554
|
+
const cases = [];
|
|
2555
|
+
let tests = 0;
|
|
2556
|
+
let failures = 0;
|
|
2557
|
+
let errors = 0;
|
|
2558
|
+
const exitCode = exitCodeForDocsCheck(payload);
|
|
2559
|
+
const properties = [
|
|
2560
|
+
` <property name="url" value="${escapeXml(payload.url)}"/>`,
|
|
2561
|
+
` <property name="generatedAt" value="${escapeXml(ctx.generatedAt)}"/>`,
|
|
2562
|
+
` <property name="tool" value="rebilder ${escapeXml(ctx.cliVersion)}"/>`,
|
|
2563
|
+
` <property name="exitCode" value="${exitCode}"/>`
|
|
2564
|
+
];
|
|
2565
|
+
if (payload.kind === "rejected" || payload.probeStatus !== "ok") {
|
|
2566
|
+
tests = 1;
|
|
2567
|
+
errors = 1;
|
|
2568
|
+
const type = payload.kind === "rejected" ? payload.rejection : payload.probeStatus;
|
|
2569
|
+
const message = payload.kind === "rejected" ? payload.detail : payload.probeDetail ?? "Page could not be probed";
|
|
2570
|
+
cases.push(
|
|
2571
|
+
[
|
|
2572
|
+
` <testcase classname="${escapeXml(payload.url)}" name="probe">`,
|
|
2573
|
+
` <error type="${escapeXml(type)}" message="${escapeXml(message)}"/>`,
|
|
2574
|
+
" </testcase>"
|
|
2575
|
+
].join("\n")
|
|
2576
|
+
);
|
|
2577
|
+
} else {
|
|
2578
|
+
const { report } = payload;
|
|
2579
|
+
properties.push(
|
|
2580
|
+
` <property name="verdict" value="${escapeXml(report.verdict)}"/>`,
|
|
2581
|
+
` <property name="analyzedSource" value="${escapeXml(report.analyzedSource)}"/>`
|
|
2582
|
+
);
|
|
2583
|
+
for (const finding of report.findings) {
|
|
2584
|
+
tests += 1;
|
|
2585
|
+
const name = `${finding.check}.${finding.id}`;
|
|
2586
|
+
if (finding.severity === "blocking") {
|
|
2587
|
+
failures += 1;
|
|
2588
|
+
const body = [finding.detail, finding.fix ? `Fix: ${finding.fix}` : ""].filter((part) => part !== "").join("\n");
|
|
2589
|
+
cases.push(
|
|
2590
|
+
[
|
|
2591
|
+
` <testcase classname="${escapeXml(payload.url)}" name="${escapeXml(name)}">`,
|
|
2592
|
+
` <failure type="blocking" message="${escapeXml(finding.title)}">${escapeXml(body)}</failure>`,
|
|
2593
|
+
" </testcase>"
|
|
2594
|
+
].join("\n")
|
|
2595
|
+
);
|
|
2596
|
+
} else if (finding.severity === "should-fix") {
|
|
2597
|
+
cases.push(
|
|
2598
|
+
[
|
|
2599
|
+
` <testcase classname="${escapeXml(payload.url)}" name="${escapeXml(name)}">`,
|
|
2600
|
+
` <skipped type="should-fix" message="${escapeXml(finding.title)}"/>`,
|
|
2601
|
+
" </testcase>"
|
|
2602
|
+
].join("\n")
|
|
2603
|
+
);
|
|
2604
|
+
} else {
|
|
2605
|
+
cases.push(` <testcase classname="${escapeXml(payload.url)}" name="${escapeXml(name)}"/>`);
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
}
|
|
2609
|
+
const xml = [
|
|
2610
|
+
` <testsuite name="${escapeXml(payload.url)}" tests="${tests}" failures="${failures}" errors="${errors}">`,
|
|
2611
|
+
" <properties>",
|
|
2612
|
+
...properties,
|
|
2613
|
+
" </properties>",
|
|
2614
|
+
...cases,
|
|
2615
|
+
" </testsuite>"
|
|
2616
|
+
].join("\n");
|
|
2617
|
+
return { xml, tests, failures, errors };
|
|
2618
|
+
}
|
|
980
2619
|
function checkSuite(report, failOn, ctx) {
|
|
981
2620
|
const cases = [];
|
|
982
2621
|
let tests = 0;
|
|
@@ -1110,6 +2749,8 @@ function renderMarkdown(payload, ctx) {
|
|
|
1110
2749
|
switch (payload.command) {
|
|
1111
2750
|
case "check":
|
|
1112
2751
|
return payload.reports.map((report) => checkSection(report)).join("\n---\n\n") + notice();
|
|
2752
|
+
case "docs-check":
|
|
2753
|
+
return docsCheckSection(payload.docsCheck);
|
|
1113
2754
|
case "diff":
|
|
1114
2755
|
return diffSection(payload.diff) + notice();
|
|
1115
2756
|
case "init":
|
|
@@ -1194,6 +2835,45 @@ function policyLine(result) {
|
|
|
1194
2835
|
function identityLine(result) {
|
|
1195
2836
|
return `ARS ${result.specVersion} \xB7 ruleset \`${shortHash(result.rulesetHash)}\` \xB7 corpus \`${shortHash(result.corpusHash)}\` \xB7 evidence \`${shortHash(result.evidenceHash)}\` \xB7 vantage ${result.vantage}`;
|
|
1196
2837
|
}
|
|
2838
|
+
function docsCheckSection(payload) {
|
|
2839
|
+
const out = [`## ${escapeCell(payload.url)} \u2014 docs check`, ""];
|
|
2840
|
+
if (payload.kind === "rejected") {
|
|
2841
|
+
out.push(`**REJECTED** \u2014 ${payload.rejection}: ${payload.detail}`, "");
|
|
2842
|
+
return out.join("\n");
|
|
2843
|
+
}
|
|
2844
|
+
if (payload.probeStatus !== "ok") {
|
|
2845
|
+
const label = payload.probeStatus === "policy" ? "BLOCKED BY POLICY" : "UNREACHABLE";
|
|
2846
|
+
out.push(`**${label}** \u2014 ${payload.probeDetail ?? ""}`, "");
|
|
2847
|
+
return out.join("\n");
|
|
2848
|
+
}
|
|
2849
|
+
const { report } = payload;
|
|
2850
|
+
const verdict = report.verdict === "can-follow" ? "Can follow" : "Likely stuck";
|
|
2851
|
+
out.push(
|
|
2852
|
+
`**${verdict}** \xB7 ${report.blocking.length} blocking \xB7 ${report.shouldFix.length} should-fix \xB7 ${report.passed.length} passed`,
|
|
2853
|
+
"",
|
|
2854
|
+
"| Check | Value |",
|
|
2855
|
+
"| --- | --- |",
|
|
2856
|
+
`| Analyzed source | \`${report.analyzedSource}\` |`,
|
|
2857
|
+
`| Markdown | \`${report.fetch.markdown}\` |`,
|
|
2858
|
+
`| Server HTML code blocks | ${report.fetch.serverHtmlCodeBlocks} |`,
|
|
2859
|
+
`| /llms.txt | \`${report.fetch.llmsTxt}\` |`,
|
|
2860
|
+
""
|
|
2861
|
+
);
|
|
2862
|
+
const renderGroup = (title, items) => {
|
|
2863
|
+
if (items.length === 0) return;
|
|
2864
|
+
out.push(`### ${title}`, "");
|
|
2865
|
+
for (const item of items) {
|
|
2866
|
+
out.push(`- **${escapeCell(item.title)}** (\`${item.id}\`) \u2014 ${item.detail}`);
|
|
2867
|
+
if (item.fix !== null) out.push(` - Fix: ${item.fix}`);
|
|
2868
|
+
}
|
|
2869
|
+
out.push("");
|
|
2870
|
+
};
|
|
2871
|
+
renderGroup("Blocking", report.blocking);
|
|
2872
|
+
renderGroup("Should fix", report.shouldFix);
|
|
2873
|
+
renderGroup("Passed", report.passed);
|
|
2874
|
+
out.push(`> ${report.scope}`, "");
|
|
2875
|
+
return out.join("\n");
|
|
2876
|
+
}
|
|
1197
2877
|
function diffSection(diff) {
|
|
1198
2878
|
const out = [`## ${escapeCell(diff.url)} \u2014 agent view vs browser view`, ""];
|
|
1199
2879
|
if (diff.report.kind === "rejected") {
|
|
@@ -1373,6 +3053,8 @@ function renderPretty(payload, caps, _ctx) {
|
|
|
1373
3053
|
switch (payload.command) {
|
|
1374
3054
|
case "check":
|
|
1375
3055
|
return joinBlocks(payload.reports.map((report) => checkBlock(report, pretty)));
|
|
3056
|
+
case "docs-check":
|
|
3057
|
+
return joinBlocks([docsCheckBlock(payload.docsCheck, pretty)]);
|
|
1376
3058
|
case "diff":
|
|
1377
3059
|
return joinBlocks([diffBlock(payload.diff, pretty)]);
|
|
1378
3060
|
case "init":
|
|
@@ -1540,6 +3222,52 @@ function identityLines(result, pretty) {
|
|
|
1540
3222
|
function noticeLines(pretty) {
|
|
1541
3223
|
return ["", ...ARS_NOTICE_LINES.map((line) => pretty.paint(line, "gray"))];
|
|
1542
3224
|
}
|
|
3225
|
+
function docsCheckBlock(payload, pretty) {
|
|
3226
|
+
const { paint, caps } = pretty;
|
|
3227
|
+
const glyphs = glyphsFor(caps.unicode);
|
|
3228
|
+
const lines = [
|
|
3229
|
+
paint(truncate(payload.url, caps.width, caps.unicode), "bold"),
|
|
3230
|
+
paint(glyphs.horizontal.repeat(Math.min(caps.width, 64)), "gray")
|
|
3231
|
+
];
|
|
3232
|
+
if (payload.kind === "rejected") {
|
|
3233
|
+
lines.push(`${paint("REJECTED", "red", "bold")} ${payload.rejection}: ${payload.detail}`);
|
|
3234
|
+
return lines;
|
|
3235
|
+
}
|
|
3236
|
+
if (payload.probeStatus !== "ok") {
|
|
3237
|
+
const label = payload.probeStatus === "policy" ? "BLOCKED BY POLICY" : "UNREACHABLE";
|
|
3238
|
+
lines.push(`${paint(label, "yellow", "bold")} ${payload.probeDetail ?? ""}`.trimEnd());
|
|
3239
|
+
return lines;
|
|
3240
|
+
}
|
|
3241
|
+
const { report } = payload;
|
|
3242
|
+
const verdictLabel = report.verdict === "can-follow" ? paint("CAN FOLLOW", "green", "bold") : paint("LIKELY STUCK", "red", "bold");
|
|
3243
|
+
lines.push(
|
|
3244
|
+
`${verdictLabel} ${paint(`${report.blocking.length} blocking \xB7 ${report.shouldFix.length} should-fix \xB7 ${report.passed.length} passed`, "gray")}`
|
|
3245
|
+
);
|
|
3246
|
+
lines.push(
|
|
3247
|
+
paint(
|
|
3248
|
+
`source: ${report.analyzedSource} \xB7 markdown: ${report.fetch.markdown} \xB7 /llms.txt: ${report.fetch.llmsTxt} \xB7 server HTML code blocks: ${report.fetch.serverHtmlCodeBlocks}`,
|
|
3249
|
+
"gray"
|
|
3250
|
+
)
|
|
3251
|
+
);
|
|
3252
|
+
const pushGroup = (heading, items, tone, mark) => {
|
|
3253
|
+
if (items.length === 0) return;
|
|
3254
|
+
lines.push("");
|
|
3255
|
+
lines.push(paint(heading, "bold"));
|
|
3256
|
+
for (const item of items) {
|
|
3257
|
+
lines.push(` ${paint(mark, tone)} ${paint(item.title, "bold")} ${paint(`[${item.id}]`, "gray")}`);
|
|
3258
|
+
lines.push(paint(` ${item.detail}`, "gray"));
|
|
3259
|
+
if (item.fix !== null) {
|
|
3260
|
+
lines.push(` Fix: ${item.fix}`);
|
|
3261
|
+
}
|
|
3262
|
+
}
|
|
3263
|
+
};
|
|
3264
|
+
pushGroup("Blocking", report.blocking, "red", caps.unicode ? "\u2718" : "x");
|
|
3265
|
+
pushGroup("Should fix", report.shouldFix, "yellow", caps.unicode ? "\u25D0" : "~");
|
|
3266
|
+
pushGroup("Passed", report.passed, "green", caps.unicode ? "\u2714" : "+");
|
|
3267
|
+
lines.push("");
|
|
3268
|
+
lines.push(paint(report.scope, "gray"));
|
|
3269
|
+
return lines;
|
|
3270
|
+
}
|
|
1543
3271
|
function diffBlock(diff, pretty) {
|
|
1544
3272
|
const { paint, caps } = pretty;
|
|
1545
3273
|
const glyphs = glyphsFor(caps.unicode);
|
|
@@ -1696,6 +3424,7 @@ USAGE
|
|
|
1696
3424
|
rebilder check <url...> [--format ${FORMATS.join("|")}] [--fail-on ${GRADES.join("|")}]
|
|
1697
3425
|
[--out <file>] [--allow-private] [--allow-http]
|
|
1698
3426
|
[--concurrency <n>]
|
|
3427
|
+
rebilder docs-check <url> [--json] [--fail-on-blocking] [--allow-private]
|
|
1699
3428
|
rebilder diff <url> agent view vs browser view
|
|
1700
3429
|
rebilder init gateway config scaffold for the detected framework
|
|
1701
3430
|
rebilder badge <domain> embed snippet
|
|
@@ -1799,8 +3528,32 @@ OPTIONS
|
|
|
1799
3528
|
--format ${FORMATS.join("|")} junit is refused: badge makes no observations
|
|
1800
3529
|
--out <file> write the snippet to a file
|
|
1801
3530
|
`;
|
|
3531
|
+
var DOCS_CHECK = `rebilder docs-check <url>
|
|
3532
|
+
|
|
3533
|
+
Checks whether a coding agent can follow a documentation page without getting
|
|
3534
|
+
stuck: Markdown negotiation, JS-dependent content, /llms.txt coverage, code
|
|
3535
|
+
block language labels, shell prompts, "..." elisions, unexplained placeholders,
|
|
3536
|
+
install-vs-import consistency, credential setup & env-var naming, runnable
|
|
3537
|
+
example, verification signal, and last-updated date.
|
|
3538
|
+
|
|
3539
|
+
Runs locally from your machine with zero telemetry \u2014 nothing is sent to
|
|
3540
|
+
Rebilder, no packages are installed, and no code is executed.
|
|
3541
|
+
|
|
3542
|
+
OPTIONS
|
|
3543
|
+
--format ${FORMATS.join("|")} default pretty
|
|
3544
|
+
--json shorthand for --format json
|
|
3545
|
+
--fail-on-blocking default off. Exit 1 when blocking findings
|
|
3546
|
+
are present (never exits 1 on probe or
|
|
3547
|
+
policy errors).
|
|
3548
|
+
--out <file> write the same rendering to a file
|
|
3549
|
+
--allow-http permit plain http targets
|
|
3550
|
+
--allow-private permit private, loopback and link-local
|
|
3551
|
+
targets (per-invocation opt-in, implies
|
|
3552
|
+
--allow-http)
|
|
3553
|
+
`;
|
|
1802
3554
|
var TOPICS = {
|
|
1803
3555
|
check: CHECK,
|
|
3556
|
+
"docs-check": DOCS_CHECK,
|
|
1804
3557
|
diff: DIFF,
|
|
1805
3558
|
init: INIT,
|
|
1806
3559
|
badge: BADGE
|
|
@@ -1811,7 +3564,7 @@ function helpText(topic) {
|
|
|
1811
3564
|
}
|
|
1812
3565
|
|
|
1813
3566
|
// src/cli.ts
|
|
1814
|
-
var CLI_VERSION = "0.
|
|
3567
|
+
var CLI_VERSION = "0.6.0";
|
|
1815
3568
|
async function runCli(argv, runtime2) {
|
|
1816
3569
|
const caps = detectCapabilities({
|
|
1817
3570
|
env: runtime2.env,
|
|
@@ -1865,6 +3618,14 @@ async function execute(command, runtime2) {
|
|
|
1865
3618
|
exitCode: worstExit(reports.map((report) => exitCodeFor(report, command.failOn)))
|
|
1866
3619
|
};
|
|
1867
3620
|
}
|
|
3621
|
+
case "docs-check": {
|
|
3622
|
+
const probe = await buildProbe(runtime2, 1, command);
|
|
3623
|
+
const docsCheck = await runDocsCheck(command, probe, runtime2.now());
|
|
3624
|
+
return {
|
|
3625
|
+
payload: { command: "docs-check", docsCheck },
|
|
3626
|
+
exitCode: exitCodeForDocsCheck(docsCheck)
|
|
3627
|
+
};
|
|
3628
|
+
}
|
|
1868
3629
|
case "diff": {
|
|
1869
3630
|
const probe = await buildProbe(runtime2, 1, command);
|
|
1870
3631
|
const diff = await runDiff(command, probe);
|