saturndocs 0.5.1 → 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.
Files changed (70) hide show
  1. package/dist/auth-ITFO2JZX.js +17 -0
  2. package/dist/broken-links-RL4CXACC.js +50 -0
  3. package/dist/{build-MHVOQFLW.js → build-A4TQWOOV.js} +18 -7
  4. package/dist/check-QPS7MTQP.js +160 -0
  5. package/dist/{chunk-GZWCWTWW.js → chunk-23HQUZXQ.js} +36 -13
  6. package/dist/{chunk-73NLPKNN.js → chunk-2NFN6VFP.js} +10 -185
  7. package/dist/{chunk-6YU3R6KT.js → chunk-45AKGRMZ.js} +1 -0
  8. package/dist/{chunk-5USJZ6NW.js → chunk-4CKO5OQL.js} +11 -9
  9. package/dist/{chunk-EG5W7EGK.js → chunk-4D3NBTL6.js} +27 -10
  10. package/dist/{chunk-ZNLLNDCO.js → chunk-ALDS7N4Q.js} +65 -43
  11. package/dist/{broken-links-4AGMC2MO.js → chunk-AUKI4MTV.js} +132 -38
  12. package/dist/{chunk-VAQXCTVC.js → chunk-C7NSZ6OB.js} +9 -7
  13. package/dist/{chunk-4Y6MLUWG.js → chunk-CTNXOVXJ.js} +8 -6
  14. package/dist/{chunk-K5VTXKBR.js → chunk-CVJ2XMAD.js} +10 -8
  15. package/dist/{renderer-76D7VFQ3.js → chunk-D5WG63T5.js} +2 -1
  16. package/dist/{chunk-MRM7F2AG.js → chunk-EMEVC3I7.js} +8 -6
  17. package/dist/{chunk-M2BZEDAS.js → chunk-FNZJHYAX.js} +2 -1
  18. package/dist/{chunk-YT6RV4YV.js → chunk-GDBDMUT4.js} +4 -2
  19. package/dist/{chunk-DEHR3XUP.js → chunk-GSZ7EXCV.js} +2 -2
  20. package/dist/{chunk-TFUZHZYD.js → chunk-HBK4T5U5.js} +18 -6
  21. package/dist/{chunk-KTQKLRHK.js → chunk-LR4MHIOQ.js} +12 -10
  22. package/dist/{chunk-IKQ7AGQF.js → chunk-M3DLP36J.js} +11 -4
  23. package/dist/{chunk-NYNPT2QB.js → chunk-MJCIWAS4.js} +12 -10
  24. package/dist/{chunk-5UES2U73.js → chunk-P7YJ2EEB.js} +2 -2
  25. package/dist/chunk-QLA74ZD6.js +109 -0
  26. package/dist/{chunk-OWKBGNGZ.js → chunk-QSJHJKJP.js} +18 -0
  27. package/dist/chunk-SN4CWEHN.js +21 -0
  28. package/dist/{chunk-KBVOLS2Y.js → chunk-TAL5XRPC.js} +59 -12
  29. package/dist/{chunk-E4GSFRKL.js → chunk-VUBV3KNZ.js} +33 -11
  30. package/dist/chunk-WTGIPAFR.js +192 -0
  31. package/dist/chunk-X3QUPC5K.js +79 -0
  32. package/dist/{chunk-APABCEY4.js → chunk-XXL6UJYJ.js} +10 -8
  33. package/dist/{chunk-5MPSOIDR.js → chunk-YVF5SRRV.js} +12 -10
  34. package/dist/{chunk-76LHDHYT.js → chunk-ZMEJOXWN.js} +14 -12
  35. package/dist/cli.js +18 -8
  36. package/dist/coverage-J37TZFNH.js +16 -0
  37. package/dist/{dev-QPQMWQQS.js → dev-DTOZC26U.js} +59 -12
  38. package/dist/{dist-HWVPEW6T.js → dist-Q7BIZ2ZM.js} +4 -2
  39. package/dist/index.d.ts +3 -2
  40. package/dist/index.js +53 -51
  41. package/dist/init-5UAYTRNK.js +18 -0
  42. package/dist/{lint-UXAQS37W.js → lint-JB2T2XON.js} +4 -3
  43. package/dist/local-metadata-JSZPFCDP.js +19 -0
  44. package/dist/{login-PYPRPZKQ.js → login-C6NODYYR.js} +6 -5
  45. package/dist/manage-73GX3EOY.js +17 -0
  46. package/dist/nav-CGOD74U6.js +15 -0
  47. package/dist/{openapiCheck-IUYQOHOT.js → openapiCheck-V3HL4OLS.js} +23 -22
  48. package/dist/pages-RN3UBKKG.js +17 -0
  49. package/dist/{read-5JX2VT5I.js → read-7KFJFSBV.js} +14 -12
  50. package/dist/{read-OIAJVVWF.js → read-BWDXUPIU.js} +13 -11
  51. package/dist/renderer-LKTT533L.js +12 -0
  52. package/dist/requests-6GFLCAZH.js +14 -0
  53. package/dist/schema-Y7ZZFE42.js +14 -0
  54. package/dist/sites-UAZ2V62J.js +16 -0
  55. package/dist/status-U4I2APGB.js +15 -0
  56. package/dist/{suggestions-3WG7NIQQ.js → suggestions-PUSFPY4M.js} +14 -12
  57. package/dist/validate-Z4P4AGLW.js +15 -0
  58. package/package.json +6 -6
  59. package/dist/auth-3MLMF5Q3.js +0 -16
  60. package/dist/chunk-AJ2ZMY42.js +0 -62
  61. package/dist/coverage-N6W4AASU.js +0 -15
  62. package/dist/init-HAGN6VFO.js +0 -15
  63. package/dist/manage-WI3VBXEU.js +0 -16
  64. package/dist/nav-OGQ6A4T6.js +0 -14
  65. package/dist/pages-KNXVBA6S.js +0 -16
  66. package/dist/requests-HBN7JHUH.js +0 -13
  67. package/dist/schema-Q7AE5RAW.js +0 -13
  68. package/dist/sites-J6VTPRTR.js +0 -15
  69. package/dist/status-YB26LFPN.js +0 -14
  70. package/dist/validate-JVRDLMND.js +0 -12
@@ -0,0 +1,17 @@
1
+ import {
2
+ AUTH_METADATA,
3
+ authStatusOf,
4
+ registerAuth,
5
+ savedLoginStatusOf
6
+ } from "./chunk-C7NSZ6OB.js";
7
+ import "./chunk-HBK4T5U5.js";
8
+ import "./chunk-GDBDMUT4.js";
9
+ import "./chunk-FNZJHYAX.js";
10
+ import "./chunk-WTGIPAFR.js";
11
+ import "./chunk-2NFN6VFP.js";
12
+ export {
13
+ AUTH_METADATA,
14
+ authStatusOf,
15
+ registerAuth,
16
+ savedLoginStatusOf
17
+ };
@@ -0,0 +1,50 @@
1
+ import {
2
+ checkLinks
3
+ } from "./chunk-AUKI4MTV.js";
4
+ import "./chunk-QSJHJKJP.js";
5
+ import "./chunk-GSZ7EXCV.js";
6
+ import "./chunk-23HQUZXQ.js";
7
+ import {
8
+ requireDocsDir
9
+ } from "./chunk-SN4CWEHN.js";
10
+ import "./chunk-TAL5XRPC.js";
11
+ import "./chunk-ALDS7N4Q.js";
12
+ import "./chunk-45AKGRMZ.js";
13
+ import {
14
+ applyCommandHelp
15
+ } from "./chunk-FNZJHYAX.js";
16
+ import {
17
+ createResultWriter,
18
+ failureResult,
19
+ invalidInput,
20
+ resolveGlobalOptions,
21
+ successResult
22
+ } from "./chunk-WTGIPAFR.js";
23
+ import {
24
+ BROKEN_LINKS_METADATA
25
+ } from "./chunk-QLA74ZD6.js";
26
+ import "./chunk-2NFN6VFP.js";
27
+
28
+ // src/commands/broken-links.ts
29
+ function linkLine(d) {
30
+ const place = d.line === null ? d.file : `${d.file}:${d.line}:${d.column}`;
31
+ return `${place}: ${d.link} \u2014 ${d.reason}${d.occurrences > 1 ? ` (on ${d.occurrences} rendered pages, first ${d.rendered})` : ""}`;
32
+ }
33
+ function registerBrokenLinks(program, provide, cache) {
34
+ const command = program.command("broken-links [docs-dir]").option("--site-url <url>", "Override the production site URL.").action(async (dir, options, self) => {
35
+ const writer = createResultWriter({ json: resolveGlobalOptions(self).json });
36
+ const context = { command: "broken-links", siteId: null };
37
+ try {
38
+ const report = await checkLinks(requireDocsDir(dir), cache, provide, options.siteUrl);
39
+ if (report.diagnostics.length) throw invalidInput(report.diagnostics.map(linkLine).join("\n"), { data: report });
40
+ process.exitCode = writer.write(successResult(context, report), { text: "Author preview has no broken internal links." });
41
+ } catch (error) {
42
+ process.exitCode = writer.write(failureResult(error, context));
43
+ }
44
+ });
45
+ applyCommandHelp(command, BROKEN_LINKS_METADATA[0]);
46
+ }
47
+ export {
48
+ linkLine,
49
+ registerBrokenLinks
50
+ };
@@ -3,16 +3,26 @@ import {
3
3
  } from "./chunk-LDE53VKA.js";
4
4
  import {
5
5
  buildGeneration
6
- } from "./chunk-GZWCWTWW.js";
7
- import "./chunk-KBVOLS2Y.js";
8
- import "./chunk-ZNLLNDCO.js";
9
- import "./chunk-6YU3R6KT.js";
6
+ } from "./chunk-23HQUZXQ.js";
7
+ import {
8
+ requireDocsDir
9
+ } from "./chunk-SN4CWEHN.js";
10
+ import "./chunk-TAL5XRPC.js";
11
+ import "./chunk-ALDS7N4Q.js";
12
+ import "./chunk-45AKGRMZ.js";
13
+ import {
14
+ applyCommandHelp
15
+ } from "./chunk-FNZJHYAX.js";
10
16
  import {
11
17
  createResultWriter,
12
18
  failureResult,
13
19
  resolveGlobalOptions,
14
20
  successResult
15
- } from "./chunk-73NLPKNN.js";
21
+ } from "./chunk-WTGIPAFR.js";
22
+ import {
23
+ BUILD_METADATA
24
+ } from "./chunk-QLA74ZD6.js";
25
+ import "./chunk-2NFN6VFP.js";
16
26
 
17
27
  // src/lib/preview/output.ts
18
28
  import { createHash, randomUUID } from "crypto";
@@ -121,11 +131,11 @@ async function exportBuild(docsDir, outDir, siteUrl, cacheDir, provide) {
121
131
 
122
132
  // src/commands/build.ts
123
133
  function registerBuild(program, provider, cache) {
124
- program.command("build [docs-dir]").requiredOption("--out-dir <path>").option("--site-url <url>", "Site URL", "http://localhost").action(async (dir, options, self) => {
134
+ const command = program.command("build [docs-dir]").requiredOption("--out-dir <path>", "Directory for the static site. It must be outside the docs directory.").option("--site-url <url>", "Site URL to render against.", "http://localhost").action(async (dir, options, self) => {
125
135
  const writer = createResultWriter({ json: resolveGlobalOptions(self).json });
126
136
  const context = { command: "build", siteId: null };
127
137
  try {
128
- const report = await exportBuild(dir ?? process.cwd(), options.outDir, options.siteUrl, cache, provider);
138
+ const report = await exportBuild(requireDocsDir(dir), options.outDir, options.siteUrl, cache, provider);
129
139
  process.exitCode = writer.write(successResult(context, report), {
130
140
  text: [`Built author preview at ${report.output_path}`, ...report.warnings].join("\n")
131
141
  });
@@ -133,6 +143,7 @@ function registerBuild(program, provider, cache) {
133
143
  process.exitCode = writer.write(failureResult(error, context));
134
144
  }
135
145
  });
146
+ applyCommandHelp(command, BUILD_METADATA[0]);
136
147
  }
137
148
  export {
138
149
  registerBuild
@@ -0,0 +1,160 @@
1
+ import {
2
+ checkLinks
3
+ } from "./chunk-AUKI4MTV.js";
4
+ import "./chunk-QSJHJKJP.js";
5
+ import "./chunk-D5WG63T5.js";
6
+ import {
7
+ RendererError
8
+ } from "./chunk-LDE53VKA.js";
9
+ import {
10
+ lintDocsDir
11
+ } from "./chunk-4D3NBTL6.js";
12
+ import "./chunk-YGVC4N4V.js";
13
+ import "./chunk-GSZ7EXCV.js";
14
+ import "./chunk-23HQUZXQ.js";
15
+ import {
16
+ requireDocsDir
17
+ } from "./chunk-SN4CWEHN.js";
18
+ import {
19
+ validateDocsDetailed
20
+ } from "./chunk-TAL5XRPC.js";
21
+ import "./chunk-ALDS7N4Q.js";
22
+ import "./chunk-45AKGRMZ.js";
23
+ import {
24
+ applyCommandHelp
25
+ } from "./chunk-FNZJHYAX.js";
26
+ import {
27
+ CliError,
28
+ createResultWriter,
29
+ failureResult,
30
+ invalidInput,
31
+ resolveGlobalOptions,
32
+ successResult
33
+ } from "./chunk-WTGIPAFR.js";
34
+ import {
35
+ CHECK_METADATA
36
+ } from "./chunk-QLA74ZD6.js";
37
+ import "./chunk-2NFN6VFP.js";
38
+
39
+ // src/commands/check.ts
40
+ var MISSING_ANCHOR = "No element with this id on the target page";
41
+ var LINK_FIX = "Link to a page in docs.json navigation, a file under public/, a docs.json redirect source, or a full URL.";
42
+ var ANCHOR_FIX = "Use the id of a heading on the target page. A heading's id is its text in lower case, with a hyphen for each space.";
43
+ function fromIssue(issue, severity) {
44
+ return { check: "validate", severity, path: issue.path, line: issue.line, column: issue.column, rule: issue.code, message: issue.message, fix: issue.fix };
45
+ }
46
+ function fromLink(link) {
47
+ const anchor = link.reason === MISSING_ANCHOR;
48
+ const count = link.occurrences > 1 ? ` It is on ${link.occurrences} rendered pages; the first is ${link.rendered}.` : "";
49
+ return {
50
+ check: "links",
51
+ severity: "error",
52
+ path: link.file,
53
+ line: link.line,
54
+ column: link.column,
55
+ rule: anchor ? "missing_anchor" : "broken_link",
56
+ message: `link to ${link.link} does not resolve: ${link.reason}.${count}`,
57
+ fix: anchor ? ANCHOR_FIX : LINK_FIX
58
+ };
59
+ }
60
+ var placeKey = (finding) => `${finding.path}\0${finding.line}\0${finding.column}\0${finding.rule}`;
61
+ function ordered(findings) {
62
+ return findings.map((finding, index) => ({ finding, index })).sort((left, right) => {
63
+ const a = left.finding;
64
+ const b = right.finding;
65
+ if (a.path !== b.path) return a.path === null ? 1 : b.path === null ? -1 : a.path < b.path ? -1 : 1;
66
+ const line = (a.line ?? Number.MAX_SAFE_INTEGER) - (b.line ?? Number.MAX_SAFE_INTEGER);
67
+ if (line !== 0) return line;
68
+ const column = (a.column ?? 0) - (b.column ?? 0);
69
+ return column !== 0 ? column : left.index - right.index;
70
+ }).map((entry) => entry.finding);
71
+ }
72
+ async function checkDocs(docsDir, options) {
73
+ const limitations = [];
74
+ const validation = await validateDocsDetailed(docsDir);
75
+ let findings = [
76
+ ...validation.errors.map((issue) => fromIssue(issue, "error")),
77
+ ...validation.warnings.map((issue) => fromIssue(issue, "warning"))
78
+ ];
79
+ const seen = new Set(findings.map(placeKey));
80
+ const lint = await lintDocsDir(docsDir);
81
+ for (const found of lint.findings) {
82
+ const finding = {
83
+ check: "lint",
84
+ severity: found.severity,
85
+ path: found.path === "" ? null : found.path,
86
+ line: found.line,
87
+ column: found.column ?? null,
88
+ rule: found.rule,
89
+ message: found.message,
90
+ fix: found.fix ?? null
91
+ };
92
+ if (seen.has(placeKey(finding)) || seen.has(placeKey({ ...finding, column: null }))) continue;
93
+ findings.push(finding);
94
+ }
95
+ const failed = (check) => findings.some((finding) => finding.check === check && finding.severity === "error");
96
+ const checks = { validate: failed("validate") ? "failed" : "passed", lint: failed("lint") ? "failed" : "passed", links: "skipped" };
97
+ const unbuildable = validation.errors.some((issue) => issue.code !== "unresolved_link");
98
+ const without = (message, state) => {
99
+ checks.links = state;
100
+ limitations.push({ code: "section_unavailable", at: "checks.links", message });
101
+ };
102
+ if (!options.links) {
103
+ without("The rendered link and fragment check did not run, because --skip-links was passed.", "skipped");
104
+ } else if (unbuildable) {
105
+ without("The rendered link and fragment check did not run, because the site does not build until the errors are fixed. Fix them and run check again.", "skipped");
106
+ } else {
107
+ try {
108
+ const rendered = await checkLinks(docsDir, options.cache, options.provide, options.siteUrl);
109
+ findings = findings.filter((finding) => finding.rule !== "unresolved_link");
110
+ findings.push(...rendered.diagnostics.map(fromLink));
111
+ checks.links = rendered.diagnostics.length > 0 ? "failed" : "passed";
112
+ checks.validate = failed("validate") ? "failed" : "passed";
113
+ } catch (error) {
114
+ const issues = error instanceof CliError && error.code === "invalid_input" ? error.data?.errors : void 0;
115
+ if (error instanceof RendererError || issues?.every((issue) => issue.code === "preview_unsupported")) {
116
+ without(`The rendered link and fragment check did not run: ${error.message.split("\n")[0]}`, "unavailable");
117
+ } else if (issues !== void 0) {
118
+ findings.push(...issues.map((issue) => ({ ...fromIssue(issue, "error"), check: "links" })));
119
+ checks.links = "failed";
120
+ } else {
121
+ throw error;
122
+ }
123
+ }
124
+ }
125
+ findings = ordered(findings);
126
+ const errors = findings.filter((finding) => finding.severity === "error").length;
127
+ return {
128
+ report: { docs_dir: docsDir, passed: errors === 0, errors, warnings: findings.length - errors, checks, findings },
129
+ limitations
130
+ };
131
+ }
132
+ function checkReportText(report) {
133
+ const lines = report.findings.flatMap((finding) => {
134
+ const place = finding.path === null ? "bundle" : finding.line === null ? finding.path : finding.column === null ? `${finding.path}:${finding.line}` : `${finding.path}:${finding.line}:${finding.column}`;
135
+ const head = `${place} ${finding.severity} ${finding.rule} (${finding.check}): ${finding.message}`;
136
+ return finding.fix === null ? [head] : [head, ` fix: ${finding.fix}`];
137
+ });
138
+ const states = ["validate", "lint", "links"].map((check) => `${check} ${report.checks[check]}`).join(", ");
139
+ lines.push(`${report.passed ? "\u2713" : "\u2716"} ${report.errors} error(s) and ${report.warnings} warning(s) in ${report.docs_dir}: ${states}.`);
140
+ return lines.join("\n");
141
+ }
142
+ function registerCheck(program, provide, cache) {
143
+ const command = program.command("check").argument("[dir]", "The docs directory. Defaults to the current directory.").option("--skip-links", "Skip the rendered link and fragment check, which builds the site.").option("--site-url <url>", "Override the production site URL for the link check.").action(async (dir, options, self) => {
144
+ const writer = createResultWriter({ json: resolveGlobalOptions(self).json });
145
+ const context = { command: "check", siteId: null };
146
+ try {
147
+ const { report, limitations } = await checkDocs(requireDocsDir(dir), { links: options.skipLinks !== true, siteUrl: options.siteUrl, cache, provide });
148
+ if (!report.passed) throw invalidInput(checkReportText(report), { data: report, limitations });
149
+ process.exitCode = writer.write(successResult({ ...context, limitations }, report), { text: checkReportText(report) });
150
+ } catch (error) {
151
+ process.exitCode = writer.write(failureResult(error, context));
152
+ }
153
+ });
154
+ applyCommandHelp(command, CHECK_METADATA[0]);
155
+ }
156
+ export {
157
+ checkDocs,
158
+ checkReportText,
159
+ registerCheck
160
+ };
@@ -2,7 +2,7 @@ import {
2
2
  collectOutsideRootFiles,
3
3
  configLocator,
4
4
  validateDocsDetailed
5
- } from "./chunk-KBVOLS2Y.js";
5
+ } from "./chunk-TAL5XRPC.js";
6
6
  import {
7
7
  SOURCE_ALLOWED_ROOTS,
8
8
  SOURCE_LIMITS,
@@ -12,10 +12,13 @@ import {
12
12
  frontmatterPolicy,
13
13
  normalizeComponentMarkdown,
14
14
  validateBundleStructure
15
- } from "./chunk-ZNLLNDCO.js";
15
+ } from "./chunk-ALDS7N4Q.js";
16
16
  import {
17
17
  parseDocsConfig
18
- } from "./chunk-6YU3R6KT.js";
18
+ } from "./chunk-45AKGRMZ.js";
19
+ import {
20
+ invalidInput
21
+ } from "./chunk-WTGIPAFR.js";
19
22
 
20
23
  // src/lib/preview/components.ts
21
24
  import { spawn } from "child_process";
@@ -1567,11 +1570,23 @@ async function previewFonts(config, cache, directory, signal) {
1567
1570
  // src/lib/preview/generation.ts
1568
1571
  var roots = new Map(SOURCE_ALLOWED_ROOTS.map((pattern) => [pattern.split("/")[0], pattern.includes("/")]));
1569
1572
  var previewRoots = new Set(roots.keys());
1573
+ var NO_READER_PREVIEW = "Check this site with validate and lint. Local preview does not support reader sign-in.";
1574
+ function issueLine(issue) {
1575
+ const head = `${issue.path ?? "bundle"}:${issue.line ?? 1}:${issue.column ?? 1}: ${issue.message}`;
1576
+ return issue.fix === null || issue.message.includes(issue.fix) ? head : `${head}
1577
+ fix: ${issue.fix}`;
1578
+ }
1579
+ function sourceError(issues) {
1580
+ return invalidInput(issues.map(issueLine).join("\n"), { data: { errors: issues } });
1581
+ }
1582
+ function sourceIssue(path2, line, column, code, message, fix = null) {
1583
+ return { path: path2, line, column, code, message, fix };
1584
+ }
1570
1585
  function checkConfig(text) {
1571
1586
  const config = parseDocsConfig(JSON.parse(text));
1572
1587
  if (config.type === "portal" || config.auth?.oidc) {
1573
1588
  const loc = configLocator(text)(config.type === "portal" ? ["type"] : ["auth", "oidc"]);
1574
- throw new Error(`docs.json:${loc?.line ?? 1}:${loc?.column ?? 1}: Reader authentication requires a hosted preview.`);
1589
+ throw sourceError([sourceIssue("docs.json", loc?.line ?? 1, loc?.column ?? 1, "preview_unsupported", "Reader sign-in cannot be previewed on this computer.", NO_READER_PREVIEW)]);
1575
1590
  }
1576
1591
  return config;
1577
1592
  }
@@ -1579,10 +1594,13 @@ function checkPage(file, bytes) {
1579
1594
  try {
1580
1595
  if (!frontmatterPolicy(bytes).grouped) return;
1581
1596
  } catch (error) {
1582
- throw new Error(`${file}:1:1: Cannot read reader policy. Correct the page frontmatter. ${error}`);
1597
+ throw sourceError([sourceIssue(file, 1, 1, "invalid_frontmatter", `Cannot read reader policy. Correct the page frontmatter. ${error}`)]);
1583
1598
  }
1584
1599
  const line = new TextDecoder().decode(bytes).split("\n").findIndex((l) => /^groups\s*:/.test(l));
1585
- throw new Error(`${file}:${Math.max(1, line + 1)}:1: Reader groups require a hosted preview.`);
1600
+ throw sourceError([sourceIssue(file, Math.max(1, line + 1), 1, "preview_unsupported", "Reader groups cannot be previewed on this computer.", NO_READER_PREVIEW)]);
1601
+ }
1602
+ function isSourceError(error) {
1603
+ return error instanceof Error && error.name === "CliError" && error.code === "invalid_input";
1586
1604
  }
1587
1605
  async function buildGeneration(docs, dir, cache, renderer, siteUrl, policyChecked, signal, linkCheck = "source") {
1588
1606
  const started = performance.now();
@@ -1593,7 +1611,8 @@ async function buildGeneration(docs, dir, cache, renderer, siteUrl, policyChecke
1593
1611
  try {
1594
1612
  config = checkConfig(readFileSync2(join4(source, "docs.json"), "utf8"));
1595
1613
  } catch (error) {
1596
- throw new Error(`Cannot admit docs.json. Check the site configuration. ${error}`);
1614
+ if (isSourceError(error)) throw error;
1615
+ throw sourceError([sourceIssue("docs.json", 1, 1, "invalid_docs_json", `Cannot admit docs.json. Check the site configuration. ${error}`)]);
1597
1616
  }
1598
1617
  for (const file of paths.filter((file2) => file2.startsWith("pages/"))) checkPage(file, readFileSync2(join4(source, file)));
1599
1618
  policyChecked?.(true);
@@ -1605,14 +1624,18 @@ async function buildGeneration(docs, dir, cache, renderer, siteUrl, policyChecke
1605
1624
  hash.update(JSON.stringify([path2, bytes.length])).update(bytes);
1606
1625
  }
1607
1626
  const invalid = validateBundleStructure(inventory).filter((v) => v.severity === "error");
1608
- if (invalid.length) throw new Error(invalid.map((v) => `${v.path}: ${v.message}`).join("\n"));
1627
+ if (invalid.length) {
1628
+ throw sourceError(invalid.map((v) => ({ path: v.path ?? null, line: v.line ?? null, column: v.column ?? null, code: v.code, message: v.message, fix: v.fix ?? null })));
1629
+ }
1609
1630
  const validation = await validateDocsDetailed(source, new Set(paths));
1610
- const errors = validation.errors.filter((e) => linkCheck === "source" || e.code !== "unresolved_link");
1611
- if (errors.length) throw new Error(errors.map((e) => `${e.path ?? "bundle"}:${e.line ?? 1}:${e.column ?? 1}: ${e.message} ${e.fix ?? ""}`).join("\n"));
1631
+ const deadLinks = validation.errors.filter((e) => e.code === "unresolved_link");
1632
+ const errors = validation.errors.filter((e) => e.code !== "unresolved_link");
1633
+ if (errors.length) throw sourceError(errors);
1612
1634
  const site = new URL(siteUrl ?? config.siteUrl ?? "http://localhost/");
1613
- if (!["https:", "http:"].includes(site.protocol) || site.username || site.password) throw new Error("Expected an HTTP(S) site URL");
1635
+ if (!["https:", "http:"].includes(site.protocol) || site.username || site.password) throw invalidInput("Expected an HTTP(S) site URL");
1614
1636
  const { fonts, warnings } = await previewFonts(config, cache, join4(dir, "fonts"), signal);
1615
1637
  warnings.push(...validation.warnings.map((issue) => `${issue.path ?? "bundle"}: ${issue.message}`));
1638
+ if (linkCheck === "source") warnings.push(...deadLinks.map((issue) => `${issue.path}:${issue.line ?? 1}:${issue.column ?? 1}: ${issue.message}`));
1616
1639
  signal?.throwIfAborted();
1617
1640
  const components = await previewComponents(source, paths, dir, renderer.root, signal);
1618
1641
  const out = join4(dir, "site");
@@ -1624,11 +1647,11 @@ async function buildGeneration(docs, dir, cache, renderer, siteUrl, policyChecke
1624
1647
  policy = JSON.parse(readFileSync2(join4(worker, "auth-manifest.json"), "utf8"));
1625
1648
  } catch {
1626
1649
  policyChecked?.(false);
1627
- throw new Error("worker/auth-manifest.json:1:1: Cannot read reader policy. Use a hosted preview.");
1650
+ throw new Error("worker/auth-manifest.json:1:1: Cannot read reader policy.");
1628
1651
  }
1629
1652
  if (!isAuthzManifest(policy) || policy.requireAuth || policy.routes.length || policy.oidc) {
1630
1653
  policyChecked?.(false);
1631
- throw new Error("worker/auth-manifest.json:1:1: Missing or restricted reader policy. Use a hosted preview.");
1654
+ throw sourceError([sourceIssue("docs.json", 1, 1, "preview_unsupported", "The rendered site restricts reader access, which cannot be previewed on this computer.", NO_READER_PREVIEW)]);
1632
1655
  }
1633
1656
  return { out, worker, policy, report: {
1634
1657
  author_preview: true,
@@ -1920,6 +1920,7 @@ var SESSION_MESSAGE_LIMIT = 2e3;
1920
1920
  var REVISION_NOTE_LIMIT = 4e3;
1921
1921
  var cursor = { name: "--cursor", value: "string", required: false, description: "The next_cursor of the preceding page. One page is read per invocation." };
1922
1922
  var limit = { name: "--limit", value: "integer", required: false, description: "Page size, within the operation's server ceiling." };
1923
+ var LOCAL_BUILD_EXITS = Object.freeze([EXIT.success, EXIT.invalid_input, EXIT.service_failure, EXIT.interrupted]);
1923
1924
  var P0_COMMANDS = [
1924
1925
  { name: "auth status", operation: "sites.list", operations: ["sites.list"], permission: "manage:read", mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [], exits: READ_EXITS, summary: "Verify read access and report the credential's own site. Says nothing about scopes the server did not return." },
1925
1926
  { name: "login", operation: null, operations: [], permission: null, mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [{ name: "--new-site", value: "string", required: false, description: "Propose a new site address; the person creates the site while approving." }, { name: "--scope", value: "string", required: false, description: "Comma-separated permissions to request: read, draft, build, publish. Omit to let the person choose from the defaults." }, { name: "--no-wait", value: "boolean", required: false, description: "Print the approval link and exit; finish later with --resume." }, { name: "--resume", value: "boolean", required: false, description: "Wait for the approval started by an earlier --no-wait." }, { name: "--open", value: "boolean", required: false, description: "Open the approval link in the default browser." }], exits: WAIT_EXITS, summary: "Ask a person to approve this agent for one site in the browser, then save the resulting login." },
@@ -1933,6 +1934,13 @@ var P0_COMMANDS = [
1933
1934
  { name: "nav", operation: null, operations: [], permission: null, mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [{ name: "--outline", value: "string", required: true, description: "Path to the approved outline JSON." }], exits: [EXIT.success, EXIT.invalid_input, EXIT.interrupted], summary: "Rewrite docs.json navigation from an approved outline. Local; no credential and no network." },
1934
1935
  { name: "lint", operation: null, operations: [], permission: null, mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [], exits: [EXIT.success, EXIT.invalid_input, EXIT.interrupted], summary: "Content lint and the known-pitfalls catalog over every page; exits 2 when any finding is an error. Local." },
1935
1936
  { name: "coverage", operation: null, operations: [], permission: null, mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [{ name: "--outline", value: "string", required: true, description: "Path to the approved outline JSON." }], exits: [EXIT.success, EXIT.invalid_input, EXIT.interrupted], summary: "Compare the pages on disk with an approved outline. Local." },
1937
+ { name: "check", operation: null, operations: [], permission: null, mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [{ name: "--skip-links", value: "boolean", required: false, description: "Skip the rendered link and fragment check, which builds the site." }, { name: "--site-url", value: "string", required: false, description: "Override the production site URL for the link check." }], exits: LOCAL_BUILD_EXITS, summary: "Run every local check before a push: validate, lint, and rendered links. Exits 2 when any finding is an error." },
1938
+ { name: "init", operation: null, operations: [], permission: null, mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [{ name: "--name", value: "string", required: false, description: "Site name. Defaults to the directory name." }, { name: "--primary", value: "string", required: false, description: "Primary brand color, as a CSS color." }, { name: "--from-url", value: "string", required: false, description: "Read the name and brand color from a website." }, { name: "--yes", value: "boolean", required: false, description: "Accepted for scripts. The command asks no question." }], exits: LOCAL_BUILD_EXITS, summary: "Scaffold a docs project: docs.json, two starter pages, and AGENTS.md." },
1939
+ { name: "validate", operation: null, operations: [], permission: null, mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [], exits: [EXIT.success, EXIT.invalid_input, EXIT.interrupted], summary: "Validate docs.json, page files, assets, links, and OpenAPI specs; exits 2 on any error. Local." },
1940
+ { name: "openapi-check", operation: null, operations: [], permission: null, mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [], exits: [EXIT.success, EXIT.invalid_input, EXIT.interrupted], summary: "Parse the OpenAPI specs that docs.json references and print an operation table. Local." },
1941
+ { name: "dev", operation: null, operations: [], permission: null, mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [{ name: "--port", value: "integer", required: false, description: "Loopback port. Defaults to a free port." }, { name: "--open", value: "boolean", required: false, description: "Open the author preview in the default browser and sign it in." }], exits: LOCAL_BUILD_EXITS, summary: "Preview the docs on this computer with the production renderer, rebuilding on each change. Use this preview on single-user machines." },
1942
+ { name: "build", operation: null, operations: [], permission: null, mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [{ name: "--out-dir", value: "string", required: true, description: "Directory for the static site. It must be outside the docs directory." }, { name: "--site-url", value: "string", required: false, description: "Site URL to render against. Defaults to http://localhost." }], exits: LOCAL_BUILD_EXITS, summary: "Build the docs into a static site with the production renderer." },
1943
+ { name: "broken-links", operation: null, operations: [], permission: null, mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [{ name: "--site-url", value: "string", required: false, description: "Override the production site URL." }], exits: LOCAL_BUILD_EXITS, summary: "Build the docs and report every link and fragment that does not resolve; exits 2 when any does not." },
1936
1944
  { name: "manage", operation: null, operations: [], permission: null, mutation: false, requires_site: true, text_input: "optional", text_limit: null, flags: [{ name: "--data", value: "string", required: false, description: "JSON body, or @path to read one." }, { name: "--file", value: "string", required: false, description: "A multipart file part, repeatable." }, { name: "--revision", value: "string", required: false, description: "The quoted settings revision for If-Match." }], exits: WRITE_EXITS, summary: "One existing management operation chosen by the caller, under the same target and precondition rules as every other command." },
1937
1945
  { name: "requests create", operation: "requests.create", operations: ["requests.create"], permission: "manage:write", mutation: true, requires_site: true, text_input: "required", text_limit: REQUEST_TEXT_LIMIT, flags: [...TEXT, { name: "--submission-id", value: "string", required: true, description: "A UUID the caller keeps. Replaying it with the same payload recovers the same job." }, { name: "--page", value: "string", required: false, description: "The page the request is about." }], exits: WRITE_EXITS, summary: "Submit a documentation request and return its queued job and root thread." },
1938
1946
  { name: "requests reply", operation: "requests.create", operations: ["requests.create"], permission: "manage:write", mutation: true, requires_site: true, text_input: "required", text_limit: REQUEST_TEXT_LIMIT, flags: [...TEXT, { name: "--thread", value: "string", required: true, description: "The root job of the conversation being answered." }, { name: "--submission-id", value: "string", required: true, description: "A UUID the caller keeps, so a lost answer replays instead of duplicating." }], exits: WRITE_EXITS, summary: "Answer a clarification. The root thread is kept; a new job comes back." },
@@ -4041,178 +4049,6 @@ function requestChangesIds(result) {
4041
4049
  return { suggestion_id: result.suggestion_id, pr_number: result.pr_number };
4042
4050
  }
4043
4051
 
4044
- // src/adapter/globals.ts
4045
- import { InvalidArgumentError } from "commander";
4046
- var GLOBAL_OPTION_KEYS = ["json", "site", "api", "input", "timeout"];
4047
- var GLOBAL_DEFAULTS = { json: false, site: null, api: null, input: true, timeout: null };
4048
- function positiveSeconds(value) {
4049
- const seconds = Number(value);
4050
- if (!Number.isInteger(seconds) || seconds <= 0) {
4051
- throw new InvalidArgumentError("Give a positive whole number of seconds.");
4052
- }
4053
- return seconds;
4054
- }
4055
- var GLOBAL_FLAGS2 = [
4056
- ["--json", "One result object and a newline on stdout. Diagnostics stay on stderr."],
4057
- ["--site <site-id>", "The site to act on. Required for every remote mutation."],
4058
- ["--api <origin>", "Management API origin."],
4059
- ["--no-input", "Never read from a terminal."],
4060
- ["--timeout <seconds>", "Seconds a wait or a request may take.", positiveSeconds]
4061
- ];
4062
- function longOf(flags) {
4063
- return flags.split(/[ ,|]/)[0] ?? flags;
4064
- }
4065
- function applyGlobalFlags(command) {
4066
- const declared = new Set(command.options.map((option) => option.long));
4067
- for (const [flags, description, parser] of GLOBAL_FLAGS2) {
4068
- const long = longOf(flags);
4069
- if (declared.has(long) || long === "--no-input" && declared.has("--input")) continue;
4070
- if (parser === void 0) command.option(flags, description);
4071
- else command.option(flags, description, parser);
4072
- }
4073
- return command;
4074
- }
4075
- function applyGlobalFlagsDeep(command) {
4076
- applyGlobalFlags(command);
4077
- for (const child of command.commands) applyGlobalFlagsDeep(child);
4078
- }
4079
- function resolveGlobalOptions(command) {
4080
- const chain = [];
4081
- for (let node = command; node !== null; node = node.parent) chain.unshift(node);
4082
- const resolved = { ...GLOBAL_DEFAULTS };
4083
- for (const node of chain) {
4084
- for (const key of GLOBAL_OPTION_KEYS) {
4085
- const source = node.getOptionValueSource(key);
4086
- if (source === void 0 || source === "default") continue;
4087
- const value = node.getOptionValue(key);
4088
- if (value === void 0) continue;
4089
- resolved[key] = value;
4090
- }
4091
- }
4092
- return {
4093
- json: resolved.json === true,
4094
- site: typeof resolved.site === "string" ? resolved.site : null,
4095
- api: typeof resolved.api === "string" ? resolved.api : null,
4096
- input: resolved.input !== false,
4097
- timeout: typeof resolved.timeout === "number" ? resolved.timeout : null
4098
- };
4099
- }
4100
-
4101
- // src/adapter/errors.ts
4102
- var CliError = class extends Error {
4103
- code;
4104
- server;
4105
- retryable;
4106
- mutation;
4107
- exit;
4108
- limitations;
4109
- recovery;
4110
- data;
4111
- constructor(code, message, options = {}) {
4112
- super(message, options.cause === void 0 ? void 0 : { cause: options.cause });
4113
- this.name = "CliError";
4114
- this.code = code;
4115
- this.server = options.server ?? null;
4116
- this.retryable = options.retryable ?? CLIENT_ERROR_CATEGORIES[code].retryable;
4117
- this.mutation = options.mutation ?? CLIENT_ERROR_CATEGORIES[code].mutation;
4118
- this.exit = options.exit ?? CLIENT_ERROR_CATEGORIES[code].exit;
4119
- this.limitations = options.limitations ?? [];
4120
- this.recovery = options.recovery ?? null;
4121
- this.data = options.data;
4122
- }
4123
- };
4124
- function invalidInput2(message, options = {}) {
4125
- return new CliError("invalid_input", message, options);
4126
- }
4127
- function interrupted2(message = CLIENT_ERROR_CATEGORIES.interrupted.meaning, options = {}) {
4128
- return new CliError("interrupted", message, options);
4129
- }
4130
- function clientError2(code, message, server = null) {
4131
- const category = CLIENT_ERROR_CATEGORIES[code];
4132
- return { code, message, retryable: category.retryable, mutation: category.mutation, exit: category.exit, server };
4133
- }
4134
- function envelope2(context) {
4135
- return {
4136
- schema_version: CLIENT_SCHEMA_VERSION,
4137
- command: context.command,
4138
- site_id: context.siteId ?? null,
4139
- ids: context.ids ?? {},
4140
- limitations: [...context.limitations ?? []],
4141
- recovery: context.recovery ?? null
4142
- };
4143
- }
4144
- function successResult(context, data) {
4145
- return { ...envelope2(context), ok: true, data };
4146
- }
4147
- function messageOf(error) {
4148
- if (error instanceof Error && error.message !== "") return error.message;
4149
- const text = String(error);
4150
- return text === "" ? "The command failed and said nothing." : text;
4151
- }
4152
- var UNCLASSIFIED = "service_unavailable";
4153
- function failureResult(error, context) {
4154
- const classified = error instanceof CliError;
4155
- const code = classified ? error.code : UNCLASSIFIED;
4156
- const base = envelope2({
4157
- ...context,
4158
- limitations: [...context.limitations ?? [], ...classified ? error.limitations : []],
4159
- recovery: (classified ? error.recovery : null) ?? context.recovery ?? null
4160
- });
4161
- const failure = {
4162
- ...base,
4163
- ok: false,
4164
- error: classified ? {
4165
- code,
4166
- message: messageOf(error),
4167
- retryable: error.retryable,
4168
- mutation: error.mutation,
4169
- exit: error.exit,
4170
- server: error.server
4171
- } : clientError2(code, messageOf(error))
4172
- };
4173
- if (classified && error.data !== void 0) failure.data = error.data;
4174
- return failure;
4175
- }
4176
-
4177
- // src/adapter/output.ts
4178
- function createResultWriter(options) {
4179
- const stdout = options.stdout ?? process.stdout;
4180
- const stderr = options.stderr ?? process.stderr;
4181
- let written = false;
4182
- let exit = 0;
4183
- return {
4184
- json: options.json,
4185
- get written() {
4186
- return written;
4187
- },
4188
- write(result, writeOptions = {}) {
4189
- if (written) return exit;
4190
- written = true;
4191
- exit = exitForResult(result);
4192
- if (options.json) {
4193
- stdout.write(`${JSON.stringify(result)}
4194
- `);
4195
- return exit;
4196
- }
4197
- if (result.ok) {
4198
- if (writeOptions.text !== void 0) stdout.write(`${writeOptions.text}
4199
- `);
4200
- } else {
4201
- stderr.write(`error: ${result.error.message}
4202
- `);
4203
- }
4204
- for (const limitation of result.limitations) {
4205
- stderr.write(`note: ${limitation.message}
4206
- `);
4207
- }
4208
- return exit;
4209
- }
4210
- };
4211
- }
4212
- function wantsJson(argv) {
4213
- return argv.includes("--json");
4214
- }
4215
-
4216
4052
  export {
4217
4053
  SUGGESTION_TABS,
4218
4054
  EXIT,
@@ -4220,6 +4056,7 @@ export {
4220
4056
  CLIENT_ERROR_CODES,
4221
4057
  CLIENT_ERROR_CATEGORIES,
4222
4058
  CLIENT_SCHEMA_VERSION,
4059
+ exitForResult,
4223
4060
  requiresManagementReceipt,
4224
4061
  invalidInput,
4225
4062
  isManagementError,
@@ -4295,17 +4132,5 @@ export {
4295
4132
  sendSessionMessage,
4296
4133
  conversationIds,
4297
4134
  requestSuggestionChanges,
4298
- requestChangesIds,
4299
- applyGlobalFlags,
4300
- applyGlobalFlagsDeep,
4301
- resolveGlobalOptions,
4302
- CliError,
4303
- invalidInput2,
4304
- interrupted2 as interrupted,
4305
- clientError2 as clientError,
4306
- successResult,
4307
- messageOf,
4308
- failureResult,
4309
- createResultWriter,
4310
- wantsJson
4135
+ requestChangesIds
4311
4136
  };
@@ -1482,6 +1482,7 @@ export {
1482
1482
  normalizedRedirectPath,
1483
1483
  isRedirectPattern,
1484
1484
  compileRedirects,
1485
+ MAX_REDIRECT_CHAIN,
1485
1486
  resolveRootRedirectDestination,
1486
1487
  openApiPublicationCollision,
1487
1488
  ungatedOpenApiSpecPaths,