saturndocs 0.2.0 → 0.3.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 (63) hide show
  1. package/dist/auth-OIEL34E4.js +16 -0
  2. package/dist/{chunk-GGGL4O7Z.js → chunk-32ATWMIS.js} +3 -3
  3. package/dist/{chunk-QF2ADHQZ.js → chunk-3EW6ZPL6.js} +5 -5
  4. package/dist/{chunk-ADZOBRZE.js → chunk-3KCCCMQY.js} +325 -35
  5. package/dist/{chunk-2RZEC3VH.js → chunk-3X2NBWZN.js} +123 -35
  6. package/dist/{chunk-EB7RWFQA.js → chunk-5ZYUBLEH.js} +1463 -130
  7. package/dist/{chunk-WBI4EI3D.js → chunk-6EKGBIUR.js} +2 -2
  8. package/dist/{chunk-W3GKH5DY.js → chunk-BOWRQKXR.js} +12 -6
  9. package/dist/{chunk-FGKHDJOC.js → chunk-E3G56DR2.js} +287 -35
  10. package/dist/chunk-FUZE54DG.js +905 -0
  11. package/dist/chunk-HBSJ4Z4S.js +53 -0
  12. package/dist/{chunk-DBMFJXKP.js → chunk-IJOYWJVM.js} +5 -5
  13. package/dist/chunk-IWIVHHZI.js +426 -0
  14. package/dist/{chunk-Z5CBPJ2L.js → chunk-PU37LVIF.js} +3 -3
  15. package/dist/{chunk-4ORVQCHY.js → chunk-RKM7YWPD.js} +25 -6
  16. package/dist/{chunk-2YTD2XNI.js → chunk-T3MCJYSF.js} +1 -1
  17. package/dist/{chunk-YSFP37B7.js → chunk-TEYHAN2L.js} +20 -6
  18. package/dist/{chunk-WUPP3THV.js → chunk-VDGVERLX.js} +5 -5
  19. package/dist/{chunk-SVDVBZPA.js → chunk-W3FZTCKV.js} +6 -4
  20. package/dist/chunk-WMS6FUKK.js +414 -0
  21. package/dist/chunk-WXLJZ7RD.js +115 -0
  22. package/dist/{chunk-56U46JVN.js → chunk-YGVC4N4V.js} +2 -1
  23. package/dist/{chunk-6JGAA5TF.js → chunk-YPWPLIEZ.js} +4 -4
  24. package/dist/cli.js +6 -6
  25. package/dist/{coverage-EBWULNQQ.js → coverage-SRIA65FT.js} +5 -5
  26. package/dist/{dist-XISZDQTR.js → dist-LJSALT4X.js} +33 -3
  27. package/dist/index.d.ts +69 -37
  28. package/dist/index.js +112 -47
  29. package/dist/{init-PI4VTG7V.js → init-Y3GDNDWW.js} +5 -3
  30. package/dist/{lint-SXBP37G3.js → lint-XM26WIGE.js} +3 -3
  31. package/dist/login-HIXLPRUI.js +22 -0
  32. package/dist/{manage-OB6DQK3Q.js → manage-3HEBB3EQ.js} +6 -2
  33. package/dist/{nav-R4OORY2G.js → nav-K43WZJ4J.js} +4 -4
  34. package/dist/openapiCheck-CL2AH3YC.js +105 -0
  35. package/dist/pages-4VWB7Z4S.js +16 -0
  36. package/dist/{read-VECMKHBW.js → read-DYGYUOFK.js} +5 -4
  37. package/dist/{read-WWOMA67R.js → read-RKT6HUZ7.js} +41 -7
  38. package/dist/requests-CZYE6GI3.js +13 -0
  39. package/dist/{schema-NKOXZHQH.js → schema-QMJMGD5P.js} +3 -3
  40. package/dist/{sites-XMMGWPY2.js → sites-JKS25SEM.js} +5 -4
  41. package/dist/{status-SYIUUSSU.js → status-FM2ALQUJ.js} +4 -4
  42. package/dist/{suggestions-GX5CQK26.js → suggestions-Z6XIHMFN.js} +13 -7
  43. package/dist/unavailable-DVPNUO3J.js +40 -0
  44. package/dist/validate-X42T4TJ6.js +12 -0
  45. package/package.json +15 -9
  46. package/dist/auth-DUYYFNEZ.js +0 -14
  47. package/dist/brokenLinks-E364XYH3.js +0 -48
  48. package/dist/build-F5PWGP57.js +0 -39
  49. package/dist/chunk-4J33CCAC.js +0 -49
  50. package/dist/chunk-D3CLXV7D.js +0 -131
  51. package/dist/chunk-GLI3OUYL.js +0 -637
  52. package/dist/chunk-K5YY6NSF.js +0 -71
  53. package/dist/chunk-KOJJUISB.js +0 -39
  54. package/dist/chunk-O72DR5FK.js +0 -152
  55. package/dist/chunk-VNYDYHXM.js +0 -22
  56. package/dist/chunk-VXEUNRVA.js +0 -26
  57. package/dist/chunk-WHNL6UYJ.js +0 -57
  58. package/dist/deploy-QUVLOGII.js +0 -13
  59. package/dist/dev-VDSDCBO2.js +0 -43
  60. package/dist/openapiCheck-X2QQGETY.js +0 -66
  61. package/dist/pages-MKFZAVGI.js +0 -15
  62. package/dist/requests-A7WC3B4M.js +0 -13
  63. package/dist/validate-D4I3DY2W.js +0 -32
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  readPageFiles
3
- } from "./chunk-56U46JVN.js";
3
+ } from "./chunk-YGVC4N4V.js";
4
4
  import {
5
5
  applyCommandHelp
6
6
  } from "./chunk-M2BZEDAS.js";
@@ -8,17 +8,17 @@ import {
8
8
  commandMetadata,
9
9
  createResultWriter,
10
10
  failureResult,
11
- invalidInput,
11
+ invalidInput2 as invalidInput,
12
12
  resolveGlobalOptions,
13
13
  successResult
14
- } from "./chunk-ADZOBRZE.js";
14
+ } from "./chunk-3KCCCMQY.js";
15
15
 
16
16
  // src/commands/lint.ts
17
17
  import { existsSync } from "fs";
18
18
  import { resolve } from "path";
19
19
  var LINT_METADATA = Object.freeze([
20
20
  commandMetadata("lint", {
21
- description: "Run the content lint and the known-pitfalls catalog over every page under pages/ in a docs directory. Each finding carries its severity. The command exits 2 (invalid_input, with the report as data) when any finding is an error, and 0 otherwise.",
21
+ description: "Run ingest page checks, content lint, and the known-pitfalls catalog over every page under pages/ in a docs directory. Each finding carries its severity. The command exits 2 (invalid_input, with the report as data) when any finding is an error, and 0 otherwise.",
22
22
  target: { arguments: [{ name: "dir", required: false, description: "The docs directory, which holds docs.json. Defaults to the current directory." }] },
23
23
  effect: "Nothing. It reads page files on this machine and calls no service. Exits 2 when any finding is an error.",
24
24
  output: { fields: ["pages", "findings"], ids: [], limitations: [] },
@@ -30,10 +30,23 @@ var LINT_METADATA = Object.freeze([
30
30
  })
31
31
  ]);
32
32
  async function lintDocsDir(docsDir) {
33
- const { lintContent, checkPitfalls } = await import("./dist-XISZDQTR.js");
33
+ const { lintContent, checkPitfalls, validatePageBytes, violationGuidance } = await import("./dist-LJSALT4X.js");
34
34
  const pages = await readPageFiles(docsDir);
35
35
  const findings = [];
36
36
  for (const page of pages) {
37
+ const issues = [];
38
+ validatePageBytes(page.path, page.bytes, issues, "all");
39
+ for (const issue of issues) {
40
+ findings.push({
41
+ path: page.path,
42
+ line: issue.line ?? 1,
43
+ column: issue.column ?? 1,
44
+ rule: issue.code,
45
+ severity: "error",
46
+ message: issue.message,
47
+ fix: issue.fix ?? violationGuidance(issue.code)?.requirement ?? issue.message
48
+ });
49
+ }
37
50
  for (const finding of lintContent(page.path, page.content)) {
38
51
  findings.push({ path: page.path, line: finding.line, rule: finding.rule, severity: finding.severity, message: finding.message });
39
52
  }
@@ -46,7 +59,8 @@ async function lintDocsDir(docsDir) {
46
59
  function reportText(report) {
47
60
  const count = `${report.pages} page(s)`;
48
61
  if (report.findings.length === 0) return `No findings in ${count}.`;
49
- const lines = report.findings.map((f) => `${f.path}${f.line === null ? "" : `:${f.line}`} ${f.rule}: ${f.message}`);
62
+ const lines = report.findings.map((f) => `${f.path}${f.line === null ? "" : `:${f.line}`}${f.column === void 0 ? "" : `:${f.column}`} ${f.rule}: ${f.message}${f.fix ? `
63
+ fix: ${f.fix}` : ""}`);
50
64
  return [...lines, `${report.findings.length} finding(s) in ${count}.`].join("\n");
51
65
  }
52
66
  function registerLint(program) {
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  readPageFiles
3
- } from "./chunk-56U46JVN.js";
3
+ } from "./chunk-YGVC4N4V.js";
4
4
  import {
5
5
  asCliError
6
- } from "./chunk-KOJJUISB.js";
6
+ } from "./chunk-FUZE54DG.js";
7
7
  import {
8
8
  applyCommandHelp
9
9
  } from "./chunk-M2BZEDAS.js";
@@ -11,11 +11,11 @@ import {
11
11
  commandMetadata,
12
12
  createResultWriter,
13
13
  failureResult,
14
- invalidInput,
14
+ invalidInput2 as invalidInput,
15
15
  messageOf,
16
16
  resolveGlobalOptions,
17
17
  successResult
18
- } from "./chunk-ADZOBRZE.js";
18
+ } from "./chunk-3KCCCMQY.js";
19
19
 
20
20
  // src/commands/coverage.ts
21
21
  import { existsSync } from "fs";
@@ -49,7 +49,7 @@ async function runCoverage(docsDir, outlinePath) {
49
49
  } catch (error) {
50
50
  throw invalidInput(`Cannot read the outline file ${outlinePath}: ${messageOf(error)}`);
51
51
  }
52
- const { parseOutline, outlineCoverage } = await import("./dist-XISZDQTR.js");
52
+ const { parseOutline, outlineCoverage } = await import("./dist-LJSALT4X.js");
53
53
  let outline;
54
54
  try {
55
55
  outline = parseOutline(JSON.parse(raw));
@@ -1,3 +1,9 @@
1
+ // ../openapi/dist/chunk-TIOX3SX7.js
2
+ var SCHEMA_REF = /* @__PURE__ */ Symbol("schemaRef");
3
+ function decodePointerToken(token) {
4
+ return token.replace(/~1/g, "/").replace(/~0/g, "~");
5
+ }
6
+
1
7
  // ../openapi/dist/index.js
2
8
  import { parse as parseYaml } from "yaml";
3
9
  var nodeImport = async (specifier) => await import(specifier);
@@ -12,7 +18,6 @@ var HTTP_METHODS = [
12
18
  "trace"
13
19
  ];
14
20
  var MAX_REF_DEPTH = 40;
15
- var SCHEMA_REF = /* @__PURE__ */ Symbol("schemaRef");
16
21
  function isRecord(value) {
17
22
  return typeof value === "object" && value !== null && !Array.isArray(value);
18
23
  }
@@ -21,9 +26,6 @@ function withSchemaRef(value, ref) {
21
26
  Object.defineProperty(value, SCHEMA_REF, { value: ref, enumerable: false, configurable: true });
22
27
  return value;
23
28
  }
24
- function decodePointerToken(token) {
25
- return token.replace(/~1/g, "/").replace(/~0/g, "~");
26
- }
27
29
  function lookupPointer(root, ref) {
28
30
  const pointer = ref.slice(1);
29
31
  const tokens = pointer === "" ? [] : pointer.slice(1).split("/");
@@ -0,0 +1,414 @@
1
+ import {
2
+ RESERVED_URL_PREFIXES,
3
+ findUnresolvedLinks,
4
+ outlineDocId,
5
+ pageAssetReferences,
6
+ resolveHref,
7
+ stripPage,
8
+ validateBundleSemanticsAsync,
9
+ validateBundleStructure,
10
+ violationGuidance
11
+ } from "./chunk-5ZYUBLEH.js";
12
+ import {
13
+ parseOpenApiFile
14
+ } from "./chunk-W3FZTCKV.js";
15
+ import {
16
+ assetPathname,
17
+ configuredAssetHref,
18
+ loadDocsConfig,
19
+ loadModelsConfig,
20
+ navigationGroups,
21
+ navigationIconRefs
22
+ } from "./chunk-E3G56DR2.js";
23
+ import {
24
+ createResultWriter,
25
+ failureResult,
26
+ invalidInput2 as invalidInput,
27
+ resolveGlobalOptions,
28
+ successResult
29
+ } from "./chunk-3KCCCMQY.js";
30
+
31
+ // src/commands/validate.ts
32
+ import { existsSync as existsSync3 } from "fs";
33
+ import { resolve } from "path";
34
+
35
+ // src/lib/validate.ts
36
+ import { existsSync as existsSync2 } from "fs";
37
+ import { readFile as readFile2 } from "fs/promises";
38
+ import { join as join3, relative, sep } from "path";
39
+
40
+ // src/lib/assets.ts
41
+ import { posix } from "path";
42
+ import { LineCounter, isNode, parseDocument } from "yaml";
43
+
44
+ // ../components/src/icon-resolver.ts
45
+ import { getIconData, iconToSVG } from "@iconify/utils";
46
+ import { icons as lucideIcons } from "@iconify-json/lucide";
47
+ import { icons as tablerIcons } from "@iconify-json/tabler";
48
+ import { icons as fa6SolidIcons } from "@iconify-json/fa6-solid";
49
+ var ICON_SETS = [
50
+ ["lucide", lucideIcons],
51
+ ["tabler", tablerIcons],
52
+ ["fa6-solid", fa6SolidIcons]
53
+ ];
54
+ function resolveIconSet(name) {
55
+ const trimmed = name.trim();
56
+ if (trimmed.length === 0) return null;
57
+ for (const [setName, set] of ICON_SETS) {
58
+ if (getIconData(set, trimmed) !== null) return setName;
59
+ }
60
+ return null;
61
+ }
62
+
63
+ // src/lib/assets.ts
64
+ function configLocator(source) {
65
+ const lines = new LineCounter();
66
+ const document = parseDocument(source, { schema: "json", lineCounter: lines });
67
+ return (keys) => {
68
+ const node = document.getIn(keys, true);
69
+ if (!isNode(node) || !node.range) return void 0;
70
+ const { line, col } = lines.linePos(node.range[0]);
71
+ return { line, column: col };
72
+ };
73
+ }
74
+ function validateAssets(config, locate, pages, files) {
75
+ const issues = [];
76
+ const checkIcon = (path, value, place2) => {
77
+ if (resolveIconSet(value) === null) issues.push({
78
+ path,
79
+ ...place2,
80
+ severity: "error",
81
+ code: "unknown_icon",
82
+ message: `Unknown icon "${value}".`,
83
+ fix: "Use an icon name from lucide, tabler, or fa6-solid."
84
+ });
85
+ };
86
+ const checkImage = (path, value, href, place2, sourceRelative = false) => {
87
+ if (href && /^[a-z][a-z0-9+.-]*:/i.test(href)) return;
88
+ let file;
89
+ try {
90
+ if (href !== void 0) {
91
+ const pathname = assetPathname(href);
92
+ if (pathname.startsWith("/")) file = `public${posix.normalize(pathname)}`;
93
+ else if (sourceRelative) file = posix.join(posix.dirname(path), pathname);
94
+ else file = posix.join("public", posix.dirname(outlineDocId(path)), pathname);
95
+ }
96
+ } catch (error) {
97
+ if (!(error instanceof URIError)) throw error;
98
+ }
99
+ if (file !== void 0 && files.has(file)) return;
100
+ const fix = file?.startsWith("public/") ? `Add ${file} or correct the image path.` : "Use a root-relative path to an image under public/.";
101
+ issues.push({
102
+ path,
103
+ ...place2,
104
+ severity: "error",
105
+ code: "missing_image",
106
+ message: `Image "${value}" does not resolve to a file.`,
107
+ fix
108
+ });
109
+ };
110
+ for (const ref of navigationIconRefs(config)) {
111
+ if (!ref.icon.startsWith("/")) checkIcon("docs.json", ref.icon, locate(ref.keys));
112
+ }
113
+ const configured = (keys, value) => {
114
+ if (!value) return;
115
+ const href = configuredAssetHref(value, (file) => files.has(`public/${file}`));
116
+ checkImage("docs.json", value, href, locate(keys));
117
+ };
118
+ if (typeof config.logo === "string") configured(["logo"], config.logo);
119
+ else {
120
+ configured(["logo", "light"], config.logo?.light);
121
+ configured(["logo", "dark"], config.logo?.dark);
122
+ }
123
+ configured(["favicon"], config.favicon);
124
+ configured(["ai", "triggerIcon"], config.ai?.triggerIcon);
125
+ for (const path of pages) {
126
+ for (const ref of pageAssetReferences(path, files.get(path))) {
127
+ const { line, column, value } = ref;
128
+ if (ref.kind === "icon") checkIcon(path, value, { line, column });
129
+ else checkImage(path, value, value, { line, column }, ref.kind === "markdown-image");
130
+ }
131
+ }
132
+ return issues;
133
+ }
134
+
135
+ // src/lib/bundle.ts
136
+ import { lstat, readFile, readdir } from "fs/promises";
137
+ import { join, posix as posix2 } from "path";
138
+ var isLocalNoise = (entry) => entry.name.startsWith(".") || entry.isDirectory() && entry.name === "node_modules";
139
+ async function collectDirectory(root, relative2, files) {
140
+ const absolute = join(root, ...relative2.split("/"));
141
+ const entries = await readdir(absolute, { withFileTypes: true });
142
+ for (const entry of entries.sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0)) {
143
+ if (isLocalNoise(entry)) continue;
144
+ const path = posix2.join(relative2, entry.name);
145
+ const absolutePath = join(root, ...path.split("/"));
146
+ if (entry.isSymbolicLink()) throw new Error(`source bundle cannot contain a symbolic link: ${path}`);
147
+ if (entry.isDirectory()) await collectDirectory(root, path, files);
148
+ else if (entry.isFile()) files.push({ path, absolutePath, bytes: new Uint8Array(await readFile(absolutePath)) });
149
+ else throw new Error(`source bundle contains an unsupported filesystem entry: ${path}`);
150
+ }
151
+ }
152
+ var SOURCE_FILES = ["docs.json", "models.toml"];
153
+ var SOURCE_ROOTS = ["pages", "public", "openapi"];
154
+ async function collectSourceFiles(docsDir) {
155
+ const files = [];
156
+ for (const [legacy, replacement] of [["assets", "public"], ["api-reference", "openapi"]]) {
157
+ if (await lstat(join(docsDir, legacy)).catch(() => null) !== null) {
158
+ throw new Error(`legacy ${legacy}/ source is not publishable; move it to ${replacement}/`);
159
+ }
160
+ }
161
+ for (const name of SOURCE_FILES) {
162
+ const absolutePath = join(docsDir, name);
163
+ const info = await lstat(absolutePath).catch(() => null);
164
+ if (info === null) continue;
165
+ if (info.isSymbolicLink() || !info.isFile()) throw new Error(`${name} must be a regular file`);
166
+ files.push({ path: name, absolutePath, bytes: new Uint8Array(await readFile(absolutePath)) });
167
+ }
168
+ for (const name of SOURCE_ROOTS) {
169
+ const absolutePath = join(docsDir, name);
170
+ const info = await lstat(absolutePath).catch(() => null);
171
+ if (info === null) continue;
172
+ if (info.isSymbolicLink() || !info.isDirectory()) throw new Error(`${name} must be a regular directory`);
173
+ await collectDirectory(docsDir, name, files);
174
+ }
175
+ return files.sort((left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0);
176
+ }
177
+ async function collectOutsideRootFiles(docsDir) {
178
+ const inRoots = /* @__PURE__ */ new Set([...SOURCE_FILES, ...SOURCE_ROOTS]);
179
+ const files = [];
180
+ const walk = async (relative2) => {
181
+ for (const entry of await readdir(join(docsDir, ...relative2.split("/")), { withFileTypes: true })) {
182
+ const path = posix2.join(relative2, entry.name);
183
+ if (isLocalNoise(entry) || relative2 === "" && inRoots.has(entry.name)) continue;
184
+ if (entry.isDirectory()) {
185
+ await walk(path);
186
+ } else if (entry.isFile()) {
187
+ files.push({ path, size: (await lstat(join(docsDir, ...path.split("/")))).size });
188
+ }
189
+ }
190
+ };
191
+ await walk("");
192
+ return files;
193
+ }
194
+ function pageSourcePaths(files) {
195
+ return files.map((file) => file.path).filter((path) => path.startsWith("pages/") && /\.(?:md|mdx)$/i.test(path));
196
+ }
197
+
198
+ // src/lib/pages.ts
199
+ import { existsSync } from "fs";
200
+ import { join as join2 } from "path";
201
+ function resolvePageFile(docsDir, entry) {
202
+ const mdxPath = join2(docsDir, "pages", `${entry}.mdx`);
203
+ const mdPath = join2(docsDir, "pages", `${entry}.md`);
204
+ const hasMdx = existsSync(mdxPath);
205
+ const hasMd = existsSync(mdPath);
206
+ if (hasMdx && hasMd) {
207
+ throw new Error(
208
+ `Page "${entry}" resolves to both pages/${entry}.mdx and pages/${entry}.md; keep only one.`
209
+ );
210
+ }
211
+ if (hasMdx) return { entry, file: mdxPath, ext: ".mdx" };
212
+ if (hasMd) return { entry, file: mdPath, ext: ".md" };
213
+ throw new Error(
214
+ `Page "${entry}" not found: expected pages/${entry}.mdx or pages/${entry}.md.`
215
+ );
216
+ }
217
+ function pageUrl(entry) {
218
+ return entry === "index" ? "/" : `/${entry}`;
219
+ }
220
+ function collectPageEntries(config) {
221
+ return navigationGroups(config).flatMap((group) => group.pages);
222
+ }
223
+
224
+ // src/lib/validate.ts
225
+ function messageOf(error) {
226
+ return error instanceof Error ? error.message : String(error);
227
+ }
228
+ function finding(code, message, text, place2 = {}) {
229
+ return {
230
+ issue: {
231
+ path: place2.path ?? null,
232
+ line: place2.line ?? null,
233
+ column: place2.column ?? null,
234
+ code,
235
+ message,
236
+ fix: place2.fix ?? violationGuidance(code)?.requirement ?? null
237
+ },
238
+ text
239
+ };
240
+ }
241
+ function violationFindings(violations) {
242
+ return violations.filter((violation) => violation.severity === "error").map((violation) => finding(violation.code, violation.message, `${violation.path ?? "bundle"}: ${violation.message}`, violation));
243
+ }
244
+ function docsRelative(docsDir, file) {
245
+ return relative(docsDir, file).split(sep).join("/");
246
+ }
247
+ var isSiteRoot = (href) => (href.split("#")[0] ?? "").split("?")[0] === "/";
248
+ var RESERVED_SEGMENTS = new Set(RESERVED_URL_PREFIXES.map((prefix) => prefix.replace(/^\//, "").replace(/\/\*$/, "")));
249
+ var isReservedRoute = (target) => target !== null && RESERVED_SEGMENTS.has(target.split("/")[0] ?? "");
250
+ async function validateBundle(docsDir, config, routeDocIds) {
251
+ let files;
252
+ let outsideRoots;
253
+ try {
254
+ files = await collectSourceFiles(docsDir);
255
+ outsideRoots = await collectOutsideRootFiles(docsDir);
256
+ } catch (error) {
257
+ return [finding("read_error", messageOf(error), messageOf(error))];
258
+ }
259
+ const errors = violationFindings(validateBundleStructure([
260
+ ...files.map((file) => ({ path: file.path, size: file.bytes.byteLength })),
261
+ ...outsideRoots
262
+ ]));
263
+ const byPath = new Map(files.map((file) => [file.path, file.bytes]));
264
+ const pagePaths = pageSourcePaths(files);
265
+ const docsJson = byPath.get("docs.json") ?? new Uint8Array();
266
+ const locate = configLocator(new TextDecoder().decode(docsJson));
267
+ if (errors.length === 0) {
268
+ errors.push(...violationFindings(await validateBundleSemanticsAsync({
269
+ docsJson,
270
+ configLocation: locate,
271
+ modelsToml: byPath.get("models.toml"),
272
+ pagePaths,
273
+ readFile: async (path) => byPath.get(path) ?? null,
274
+ pageIssues: "all"
275
+ })));
276
+ }
277
+ const decoder = new TextDecoder();
278
+ const pages = pagePaths.map((path) => ({ path, docId: outlineDocId(path), source: decoder.decode(byPath.get(path)) }));
279
+ errors.push(...violationFindings(validateAssets(config, locate, pagePaths, byPath)));
280
+ const docIds = /* @__PURE__ */ new Set([...pages.map((page) => page.docId), ...routeDocIds]);
281
+ for (const miss of findUnresolvedLinks(pages, docIds)) {
282
+ if (isSiteRoot(miss.href) && docIds.has("index")) continue;
283
+ if (isReservedRoute(resolveHref(miss.href, outlineDocId(miss.path)))) continue;
284
+ const message = `link to ${miss.href} does not resolve to a page`;
285
+ errors.push(finding("unresolved_link", message, `${miss.path}: ${message}`, {
286
+ path: miss.path,
287
+ fix: "link to a page listed in docs.json navigation, an OpenAPI operation page, or a full URL"
288
+ }));
289
+ }
290
+ return errors;
291
+ }
292
+ async function validateDocsReport(docsDir) {
293
+ return sortIssues((await validateFindings(docsDir)).map((entry) => entry.issue));
294
+ }
295
+ async function validateDocs(docsDir) {
296
+ return (await validateFindings(docsDir)).map((entry) => entry.text);
297
+ }
298
+ function sortIssues(issues) {
299
+ return issues.map((issue, index) => ({ issue, index })).sort((left, right) => {
300
+ const leftPath = left.issue.path ?? "";
301
+ const rightPath = right.issue.path ?? "";
302
+ if (leftPath !== rightPath) return leftPath < rightPath ? -1 : 1;
303
+ const lineOrder = (left.issue.line ?? Number.MAX_SAFE_INTEGER) - (right.issue.line ?? Number.MAX_SAFE_INTEGER);
304
+ if (lineOrder !== 0) return lineOrder;
305
+ const columnOrder = (left.issue.column ?? 0) - (right.issue.column ?? 0);
306
+ return columnOrder !== 0 ? columnOrder : left.index - right.index;
307
+ }).map((entry) => entry.issue);
308
+ }
309
+ async function validateFindings(docsDir) {
310
+ const errors = [];
311
+ const docsJsonPath = join3(docsDir, "docs.json");
312
+ if (!existsSync2(docsJsonPath)) {
313
+ const message = `docs.json not found in ${docsDir}.`;
314
+ return [finding("missing_docs_json", message, message, { path: "docs.json" })];
315
+ }
316
+ let config;
317
+ try {
318
+ config = await loadDocsConfig(docsJsonPath);
319
+ } catch (error) {
320
+ return [finding("invalid_docs_json", messageOf(error), `docs.json: ${messageOf(error)}`, { path: "docs.json" })];
321
+ }
322
+ const modelsTomlPath = join3(docsDir, "models.toml");
323
+ if (existsSync2(modelsTomlPath)) {
324
+ try {
325
+ await loadModelsConfig(modelsTomlPath);
326
+ } catch (error) {
327
+ errors.push(finding("invalid_models_toml", messageOf(error), `models.toml: ${messageOf(error)}`, { path: "models.toml" }));
328
+ }
329
+ }
330
+ for (const entry of collectPageEntries(config)) {
331
+ let resolved;
332
+ try {
333
+ resolved = resolvePageFile(docsDir, entry);
334
+ } catch (error) {
335
+ errors.push(finding("missing_page", messageOf(error), messageOf(error), { path: "docs.json" }));
336
+ continue;
337
+ }
338
+ const pagePath = docsRelative(docsDir, resolved.file);
339
+ try {
340
+ const { frontmatter } = stripPage(await readFile2(resolved.file, "utf8"), resolved.file);
341
+ const groups = frontmatter.groups;
342
+ const grouped = Array.isArray(groups) && groups.length > 0;
343
+ if (grouped && frontmatter.pagefind !== false) {
344
+ const message = `Page "${entry}" restricts access with \`groups\` but is missing \`pagefind: false\`; gated content must stay out of the shared search index.`;
345
+ errors.push(finding("pagefind_required", message, message, { path: pagePath }));
346
+ }
347
+ } catch (error) {
348
+ errors.push(finding("invalid_frontmatter", messageOf(error), `Page "${entry}": ${messageOf(error)}`, { path: pagePath }));
349
+ }
350
+ }
351
+ const operationDocIds = [];
352
+ for (const group of navigationGroups(config)) {
353
+ if (!group.openapi) continue;
354
+ const openapiPath = join3(docsDir, group.openapi);
355
+ if (!existsSync2(openapiPath)) {
356
+ const message = `OpenAPI file not found: ${group.openapi}`;
357
+ errors.push(finding("missing_openapi", message, message, { path: group.openapi }));
358
+ continue;
359
+ }
360
+ try {
361
+ const spec = await parseOpenApiFile(openapiPath);
362
+ operationDocIds.push(...spec.operations.map((operation) => `api-reference/${operation.slug}`));
363
+ } catch (error) {
364
+ errors.push(finding("invalid_openapi", messageOf(error), `OpenAPI ${group.openapi}: ${messageOf(error)}`, { path: group.openapi }));
365
+ }
366
+ }
367
+ if (errors.length > 0) return errors;
368
+ return validateBundle(docsDir, config, operationDocIds);
369
+ }
370
+
371
+ // src/commands/validate.ts
372
+ function place(issue) {
373
+ if (issue.path === null) return "bundle";
374
+ if (issue.line === null) return issue.path;
375
+ return issue.column === null ? `${issue.path}:${issue.line}` : `${issue.path}:${issue.line}:${issue.column}`;
376
+ }
377
+ function validateReportText(report) {
378
+ if (report.valid) return `\u2713 ${report.docs_dir} is valid.`;
379
+ const lines = [`\u2716 ${report.errors.length} validation error(s) in ${report.docs_dir}:`];
380
+ for (const issue of report.errors) {
381
+ lines.push(` - ${place(issue)} ${issue.code}: ${issue.message}`);
382
+ if (issue.fix !== null) lines.push(` fix: ${issue.fix}`);
383
+ }
384
+ return lines.join("\n");
385
+ }
386
+ function registerValidate(program) {
387
+ program.command("validate").description("Validate docs.json, models.toml, page files, and OpenAPI specs").argument("[dir]", "docs directory (contains docs.json)").action(async (dir, _options, self) => {
388
+ const globals = resolveGlobalOptions(self);
389
+ const writer = createResultWriter({ json: globals.json });
390
+ const context = { command: "validate", siteId: null };
391
+ try {
392
+ const docsDir = resolve(dir ?? process.cwd());
393
+ if (!existsSync3(resolve(docsDir, "docs.json"))) {
394
+ throw invalidInput(`No docs.json found in ${docsDir}. Pass a docs directory.`);
395
+ }
396
+ const errors = await validateDocsReport(docsDir);
397
+ const report = { docs_dir: docsDir, valid: errors.length === 0, errors };
398
+ if (!report.valid) throw invalidInput(validateReportText(report), { data: report });
399
+ process.exitCode = writer.write(successResult(context, report), { text: validateReportText(report) });
400
+ } catch (error) {
401
+ process.exitCode = writer.write(failureResult(error, context));
402
+ }
403
+ });
404
+ }
405
+
406
+ export {
407
+ resolvePageFile,
408
+ pageUrl,
409
+ collectPageEntries,
410
+ validateDocsReport,
411
+ validateDocs,
412
+ validateReportText,
413
+ registerValidate
414
+ };
@@ -0,0 +1,115 @@
1
+ import {
2
+ asCliError,
3
+ clientFor,
4
+ environmentToken,
5
+ flowContext,
6
+ grantStatus,
7
+ loginAgainRecovery,
8
+ loginEnvironment,
9
+ resolveSavedLogin
10
+ } from "./chunk-FUZE54DG.js";
11
+ import {
12
+ applyCommandHelp
13
+ } from "./chunk-M2BZEDAS.js";
14
+ import {
15
+ CliError,
16
+ commandMetadata,
17
+ createResultWriter,
18
+ failureResult,
19
+ invalidInput2 as invalidInput,
20
+ listSites,
21
+ parseOrigin,
22
+ resolveGlobalOptions,
23
+ successResult
24
+ } from "./chunk-3KCCCMQY.js";
25
+
26
+ // src/commands/auth.ts
27
+ var AUTH_METADATA = Object.freeze([
28
+ commandMetadata("auth status", {
29
+ description: "Report the credential every other command will use. With SATURNDOCS_MANAGEMENT_TOKEN set, read GET /v1/sites with it and report the site it resolves to; that read proves read access and nothing else, so no scopes are listed. Otherwise use the saved login from saturndocs login, refreshing it if needed, and report its site, its approved permissions, its expiry times, whether the site has a connected repository, and where the login is stored.",
30
+ target: { arguments: [] },
31
+ effect: "Nothing. One read of the site listing.",
32
+ output: { fields: ["current", "sites", "read_verified", "credential"], ids: [], limitations: [] },
33
+ errors: ["invalid_input", "unauthorized", "forbidden", "rate_limited", "service_unavailable", "transport_failure", "interrupted"],
34
+ examples: [
35
+ { command: "saturndocs auth status", description: "Check that the credential in the environment can read, and see which site it acts on." },
36
+ { command: "saturndocs auth status --json --no-input", description: "The same check as one result object, for an agent." }
37
+ ]
38
+ })
39
+ ]);
40
+ function savedLoginStatusOf(status, store) {
41
+ return {
42
+ current: status.site_id,
43
+ sites: [{ site_id: status.site_id, primary_host: status.primary_host }],
44
+ read_verified: true,
45
+ credential: {
46
+ kind: "agent_grant",
47
+ store,
48
+ grant_id: status.grant_id,
49
+ capabilities: ["read", ...status.capabilities.filter((capability) => capability !== "read")],
50
+ access_expires_at: status.access_expires_at,
51
+ idle_expires_at: status.idle_expires_at,
52
+ approval_expires_at: status.approval_expires_at,
53
+ repo_connected: status.repo_connected ?? null
54
+ }
55
+ };
56
+ }
57
+ function authStatusOf(discovery) {
58
+ return { current: discovery.current, sites: discovery.sites, read_verified: true };
59
+ }
60
+ function statusText(status) {
61
+ if (status.credential !== void 0) {
62
+ const credential = status.credential;
63
+ return [
64
+ `Saved login for ${status.current}, stored in the ${credential.store}.`,
65
+ `Permissions: ${credential.capabilities.join(", ")}.`,
66
+ `Unused logins end at ${credential.idle_expires_at}; approval ends at ${credential.approval_expires_at}.`,
67
+ credential.repo_connected === false ? "The site has no connected documentation repository yet." : null
68
+ ].filter((line) => line !== null).join("\n");
69
+ }
70
+ const others = status.sites.map((site) => site.site_id).filter((id) => id !== status.current);
71
+ const reach = others.length === 0 ? "" : `
72
+ Also reached: ${others.join(", ")}.`;
73
+ return [
74
+ `Read access verified: GET /v1/sites answered.`,
75
+ `This credential acts on ${status.current}.${reach}`,
76
+ "The server does not report a credential's permissions, so nothing here says whether this one may write or approve."
77
+ ].join("\n");
78
+ }
79
+ function registerAuth(program, _cliDir, environment = {}) {
80
+ const auth = program.command("auth").description("Check the credential this CLI will use");
81
+ const status = auth.command("status").action(async (_options, self) => {
82
+ const globals = resolveGlobalOptions(self);
83
+ const writer = createResultWriter({ json: globals.json });
84
+ const context = { command: "auth status", siteId: null };
85
+ try {
86
+ const login = loginEnvironment(environment);
87
+ let data;
88
+ if (environmentToken(login.env) !== void 0) {
89
+ data = authStatusOf(await listSites(clientFor(globals, environment)));
90
+ } else {
91
+ const origin = parseOrigin(globals.api ?? void 0);
92
+ const saved = await resolveSavedLogin(origin, globals.site, login);
93
+ if (saved === null) throw invalidInput("Not logged in. Run saturndocs login, or set SATURNDOCS_MANAGEMENT_TOKEN.", { recovery: { command: "saturndocs login", replay: null, message: "Ask a person to approve this agent for a site." } });
94
+ const status2 = await grantStatus(flowContext(origin, login), saved.token);
95
+ if (status2 === null) throw new CliError("unauthorized", `The server refused the saved login for ${saved.grant.site_id}.`, { recovery: loginAgainRecovery(saved.grant.site_id) });
96
+ data = savedLoginStatusOf(status2, saved.store.label);
97
+ }
98
+ context.siteId = data.current;
99
+ if (globals.site !== null && globals.site !== data.current && !data.sites.some((site) => site.site_id === globals.site)) {
100
+ throw invalidInput(`This credential acts on ${data.current}, not ${globals.site}.`);
101
+ }
102
+ process.exitCode = writer.write(successResult(context, data), { text: statusText(data) });
103
+ } catch (error) {
104
+ process.exitCode = writer.write(failureResult(asCliError(error), context));
105
+ }
106
+ });
107
+ applyCommandHelp(status, AUTH_METADATA[0]);
108
+ }
109
+
110
+ export {
111
+ AUTH_METADATA,
112
+ savedLoginStatusOf,
113
+ authStatusOf,
114
+ registerAuth
115
+ };
@@ -13,7 +13,8 @@ async function walk(absDir, relDir, out) {
13
13
  const rel = posix.join(relDir, entry.name);
14
14
  if (entry.isDirectory()) await walk(join(absDir, entry.name), rel, out);
15
15
  else if (entry.isFile() && /\.mdx?$/.test(entry.name)) {
16
- out.push({ path: rel, content: await readFile(join(absDir, entry.name), "utf8") });
16
+ const bytes = await readFile(join(absDir, entry.name));
17
+ out.push({ path: rel, content: bytes.toString("utf8"), bytes });
17
18
  }
18
19
  }
19
20
  }