@takazudo/zudo-doc 13.0.1 → 14.0.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 (104) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/bin/zudo-doc.mjs +32 -0
  3. package/dist/config.d.ts +10 -27
  4. package/dist/doc-content-header/index.js +1 -1
  5. package/dist/doc-page-renderer/index.js +3 -1
  6. package/dist/doc-sources/types.d.ts +65 -0
  7. package/dist/doc-sources/types.js +0 -0
  8. package/dist/docs-schema/index.d.ts +3 -0
  9. package/dist/docs-schema/index.js +4 -0
  10. package/dist/frontmatter-preview-defaults/index.js +3 -0
  11. package/dist/i18n-defaults/index.js +36 -50
  12. package/dist/plugins/{codex-resources.d.ts → doc-sources.d.ts} +0 -1
  13. package/dist/plugins/doc-sources.js +40 -0
  14. package/dist/plugins/internal/doc-sources/discover.d.ts +33 -0
  15. package/dist/plugins/internal/doc-sources/discover.js +176 -0
  16. package/dist/plugins/internal/doc-sources/glob.d.ts +8 -0
  17. package/dist/plugins/internal/doc-sources/glob.js +80 -0
  18. package/dist/plugins/internal/doc-sources/labels.d.ts +8 -0
  19. package/dist/plugins/internal/doc-sources/labels.js +7 -0
  20. package/dist/plugins/internal/doc-sources/locale-routes.d.ts +6 -0
  21. package/dist/plugins/internal/doc-sources/locale-routes.js +8 -0
  22. package/dist/plugins/internal/doc-sources/model.d.ts +64 -0
  23. package/dist/plugins/internal/doc-sources/model.js +0 -0
  24. package/dist/plugins/internal/doc-sources/normalize.d.ts +20 -0
  25. package/dist/plugins/internal/doc-sources/normalize.js +192 -0
  26. package/dist/plugins/internal/doc-sources/plan.d.ts +28 -0
  27. package/dist/plugins/internal/doc-sources/plan.js +350 -0
  28. package/dist/plugins/internal/doc-sources/presets.d.ts +12 -0
  29. package/dist/plugins/internal/doc-sources/presets.js +182 -0
  30. package/dist/plugins/internal/doc-sources/reconcile.d.ts +20 -0
  31. package/dist/plugins/internal/doc-sources/reconcile.js +182 -0
  32. package/dist/plugins/internal/doc-sources/render/codex-agent.d.ts +2 -0
  33. package/dist/plugins/internal/doc-sources/render/codex-agent.js +45 -0
  34. package/dist/plugins/internal/doc-sources/render/codex-config.d.ts +2 -0
  35. package/dist/plugins/internal/doc-sources/render/codex-config.js +45 -0
  36. package/dist/plugins/internal/doc-sources/render/codex-hooks.d.ts +2 -0
  37. package/dist/plugins/internal/doc-sources/render/codex-hooks.js +66 -0
  38. package/dist/plugins/internal/doc-sources/render/codex-rules.d.ts +2 -0
  39. package/dist/plugins/internal/{codex-resources/rules.js → doc-sources/render/codex-rules.js} +16 -89
  40. package/dist/plugins/internal/{resource-docs-shared → doc-sources/render}/escape-for-mdx.js +1 -1
  41. package/dist/plugins/internal/doc-sources/render/frontmatter.d.ts +9 -0
  42. package/dist/plugins/internal/doc-sources/render/frontmatter.js +38 -0
  43. package/dist/plugins/internal/doc-sources/render/links.d.ts +25 -0
  44. package/dist/plugins/internal/doc-sources/render/links.js +109 -0
  45. package/dist/plugins/internal/{resource-docs-shared → doc-sources/render}/markdown-structure.d.ts +4 -0
  46. package/dist/plugins/internal/{resource-docs-shared → doc-sources/render}/markdown-structure.js +37 -1
  47. package/dist/plugins/internal/doc-sources/render/skill.d.ts +10 -0
  48. package/dist/plugins/internal/doc-sources/render/skill.js +97 -0
  49. package/dist/plugins/internal/doc-sources/render/types.d.ts +7 -0
  50. package/dist/plugins/internal/doc-sources/render/types.js +6 -0
  51. package/dist/plugins/internal/doc-sources/run.d.ts +53 -0
  52. package/dist/plugins/internal/doc-sources/run.js +110 -0
  53. package/dist/plugins/internal/doc-sources/watch.d.ts +33 -0
  54. package/dist/plugins/internal/doc-sources/watch.js +187 -0
  55. package/dist/plugins/routes.js +1 -1
  56. package/dist/preset.d.ts +3 -19
  57. package/dist/preset.js +23 -30
  58. package/dist/route-context-payload/index.js +4 -1
  59. package/dist/settings-defaults.js +1 -2
  60. package/dist/settings.d.ts +4 -10
  61. package/package.json +15 -19
  62. package/dist/plugins/claude-resources.d.ts +0 -4
  63. package/dist/plugins/claude-resources.js +0 -45
  64. package/dist/plugins/codex-resources.js +0 -45
  65. package/dist/plugins/internal/claude-resources/generate.d.ts +0 -31
  66. package/dist/plugins/internal/claude-resources/generate.js +0 -375
  67. package/dist/plugins/internal/claude-resources/index.d.ts +0 -54
  68. package/dist/plugins/internal/claude-resources/index.js +0 -33
  69. package/dist/plugins/internal/codex-resources/agents-md.d.ts +0 -6
  70. package/dist/plugins/internal/codex-resources/agents-md.js +0 -83
  71. package/dist/plugins/internal/codex-resources/agents.d.ts +0 -7
  72. package/dist/plugins/internal/codex-resources/agents.js +0 -117
  73. package/dist/plugins/internal/codex-resources/config.d.ts +0 -6
  74. package/dist/plugins/internal/codex-resources/config.js +0 -124
  75. package/dist/plugins/internal/codex-resources/generate.d.ts +0 -29
  76. package/dist/plugins/internal/codex-resources/generate.js +0 -46
  77. package/dist/plugins/internal/codex-resources/hooks.d.ts +0 -6
  78. package/dist/plugins/internal/codex-resources/hooks.js +0 -187
  79. package/dist/plugins/internal/codex-resources/index.d.ts +0 -33
  80. package/dist/plugins/internal/codex-resources/index.js +0 -33
  81. package/dist/plugins/internal/codex-resources/overview.d.ts +0 -10
  82. package/dist/plugins/internal/codex-resources/overview.js +0 -163
  83. package/dist/plugins/internal/codex-resources/rules.d.ts +0 -6
  84. package/dist/plugins/internal/codex-resources/skills.d.ts +0 -2
  85. package/dist/plugins/internal/codex-resources/skills.js +0 -97
  86. package/dist/plugins/internal/codex-resources/utils.d.ts +0 -14
  87. package/dist/plugins/internal/codex-resources/utils.js +0 -80
  88. package/dist/plugins/internal/resource-docs-shared/fs.d.ts +0 -36
  89. package/dist/plugins/internal/resource-docs-shared/fs.js +0 -101
  90. package/dist/plugins/internal/resource-docs-shared/index.d.ts +0 -9
  91. package/dist/plugins/internal/resource-docs-shared/index.js +0 -69
  92. package/dist/plugins/internal/resource-docs-shared/labels.d.ts +0 -24
  93. package/dist/plugins/internal/resource-docs-shared/labels.js +0 -14
  94. package/dist/plugins/internal/resource-docs-shared/links.d.ts +0 -27
  95. package/dist/plugins/internal/resource-docs-shared/links.js +0 -62
  96. package/dist/plugins/internal/resource-docs-shared/locale-routes.d.ts +0 -16
  97. package/dist/plugins/internal/resource-docs-shared/locale-routes.js +0 -14
  98. package/dist/plugins/internal/resource-docs-shared/mdx.d.ts +0 -28
  99. package/dist/plugins/internal/resource-docs-shared/mdx.js +0 -64
  100. package/dist/plugins/internal/resource-docs-shared/skills.d.ts +0 -37
  101. package/dist/plugins/internal/resource-docs-shared/skills.js +0 -340
  102. package/dist/plugins/internal/resource-docs-shared/walk.d.ts +0 -20
  103. package/dist/plugins/internal/resource-docs-shared/walk.js +0 -41
  104. /package/dist/plugins/internal/{resource-docs-shared → doc-sources/render}/escape-for-mdx.d.ts +0 -0
@@ -0,0 +1,350 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { resolveLabel } from "./labels.js";
4
+ import { shouldEmitLocaleRoute } from "./locale-routes.js";
5
+ import { renderCodexAgent } from "./render/codex-agent.js";
6
+ import { renderCodexConfig } from "./render/codex-config.js";
7
+ import { renderCodexHooks } from "./render/codex-hooks.js";
8
+ import { renderCodexRules } from "./render/codex-rules.js";
9
+ import { escapeForMdx } from "./render/escape-for-mdx.js";
10
+ import { parseFrontmatter, renderFrontmatter } from "./render/frontmatter.js";
11
+ import {
12
+ rewriteLinks,
13
+ safeDecode,
14
+ splitDestination
15
+ } from "./render/links.js";
16
+ import {
17
+ escapeMarkdownTableCell,
18
+ languageForFilename,
19
+ renderCodeFence,
20
+ renderTableRow
21
+ } from "./render/markdown-structure.js";
22
+ import {
23
+ renderSkillFileStructure,
24
+ renderSkillInterfaceMetadata
25
+ } from "./render/skill.js";
26
+ const ASSET_DIR = "doc-sources";
27
+ class DocSourcesPlanError extends Error {
28
+ constructor(message) {
29
+ super(`docSources: ${message}`);
30
+ this.name = "DocSourcesPlanError";
31
+ }
32
+ }
33
+ function routeSegment(name) {
34
+ return name.normalize("NFC").toLowerCase().replace(/[^\p{L}\p{N}_-]+/gu, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
35
+ }
36
+ function describe(file) {
37
+ return `source "${file.mapping.sourceId}" mapping "${file.mapping.id}" file "${file.rel}"`;
38
+ }
39
+ function stripExtension(name, extensions) {
40
+ const lower = name.toLowerCase();
41
+ const ext = extensions.find((candidate) => lower.endsWith(candidate) && lower.length > candidate.length);
42
+ return ext === void 0 ? name : name.slice(0, -ext.length);
43
+ }
44
+ function joinRoute(...parts) {
45
+ return parts.filter((part) => part !== "").join("/");
46
+ }
47
+ function buildPlan(options, discovery) {
48
+ const diagnostics = [...discovery.diagnostics];
49
+ const sourcesById = new Map(options.sources.map((s) => [s.id, s]));
50
+ const docs = [];
51
+ const assets = [];
52
+ const outputOwners = /* @__PURE__ */ new Map();
53
+ const claim = (key, owner) => {
54
+ const previous = outputOwners.get(key);
55
+ if (previous !== void 0) {
56
+ throw new DocSourcesPlanError(
57
+ `route collision: ${previous} and ${owner} both resolve to "${key}". Rename one file, or change a mapping's "to" or a source's mount.`
58
+ );
59
+ }
60
+ outputOwners.set(key, owner);
61
+ };
62
+ const directories = /* @__PURE__ */ new Map();
63
+ const sectionPositions = /* @__PURE__ */ new Map();
64
+ const noteDirectory = (routeDir, info) => {
65
+ const existing = directories.get(routeDir);
66
+ if (existing === void 0) {
67
+ directories.set(routeDir, info);
68
+ } else if (existing.source !== info.source) {
69
+ throw new DocSourcesPlanError(
70
+ `route collision: sources "${existing.source.id}" and "${info.source.id}" both own "/docs/${routeDir}/"`
71
+ );
72
+ }
73
+ };
74
+ options.sources.forEach((source, sourceIndex) => {
75
+ noteDirectory(source.mount, {
76
+ source,
77
+ label: source.title,
78
+ description: source.description,
79
+ position: 900 + sourceIndex
80
+ });
81
+ let position = 0;
82
+ for (const mapping of source.mappings) {
83
+ if (mapping.to === "") continue;
84
+ const segments = mapping.to.split("/");
85
+ segments.forEach((_, index) => {
86
+ const routeDir = joinRoute(source.mount, ...segments.slice(0, index + 1));
87
+ const isSection = index === segments.length - 1;
88
+ if (!sectionPositions.has(routeDir) && isSection) sectionPositions.set(routeDir, ++position);
89
+ const existing = directories.get(routeDir);
90
+ if (existing === void 0 || isSection && existing.label.key === void 0 && mapping.sectionLabel?.key !== void 0) {
91
+ directories.set(routeDir, {
92
+ source,
93
+ label: isSection && mapping.sectionLabel ? mapping.sectionLabel : { fallback: segments[index] },
94
+ description: isSection ? mapping.sectionDescription : void 0,
95
+ position: sectionPositions.get(routeDir)
96
+ });
97
+ }
98
+ });
99
+ }
100
+ });
101
+ for (const file of discovery.files) {
102
+ const source = sourcesById.get(file.mapping.sourceId);
103
+ const mapping = file.mapping;
104
+ const segments = file.rel.split("/");
105
+ const baseName = segments.pop();
106
+ const dirSegments = segments.map((segment) => {
107
+ const slug = routeSegment(segment);
108
+ if (slug === "") {
109
+ throw new DocSourcesPlanError(`${describe(file)}: directory "${segment}" has no usable route segment`);
110
+ }
111
+ return slug;
112
+ });
113
+ const baseRoute = joinRoute(source.mount, mapping.to);
114
+ if (file.kind === "asset") {
115
+ const outputAbs = path.join(options.publicDir, ASSET_DIR, ...baseRoute.split("/"), ...file.rel.split("/"));
116
+ claim(`asset:${path.relative(options.publicDir, outputAbs)}`, describe(file));
117
+ const url = `/${[ASSET_DIR, ...baseRoute.split("/"), ...file.rel.split("/")].map(encodeURIComponent).join("/")}`;
118
+ assets.push({ file, outputAbs, url });
119
+ continue;
120
+ }
121
+ const lowerBase = baseName.toLowerCase();
122
+ const landing = file.kind === "document" && mapping.renderer === "skill" ? lowerBase === "skill.md" : mapping.landingNames.includes(lowerBase);
123
+ const stem = file.kind === "skill-page" ? stripExtension(baseName, [".md", ".mdx"]) : stripExtension(baseName, mapping.stripExtensions);
124
+ let routeDir = joinRoute(baseRoute, ...dirSegments);
125
+ let outputRel;
126
+ if (file.kind === "skill-page") {
127
+ const skillDir = file.skillDir ?? ".";
128
+ const skillSegments = skillDir === "." ? [] : skillDir.split("/").map(routeSegment);
129
+ routeDir = joinRoute(baseRoute, ...skillSegments);
130
+ const inner = skillDir === "." ? file.rel : file.rel.slice(skillDir.length + 1);
131
+ const slug = routeSegment(stripExtension(inner, [".md", ".mdx"]).replace(/\//g, "-"));
132
+ outputRel = joinRoute(routeDir, `${slug}.mdx`);
133
+ claim(`doc:${outputRel}`, describe(file));
134
+ docs.push({ file, source, routeDir, outputRel, landing: false });
135
+ continue;
136
+ }
137
+ if (landing) {
138
+ outputRel = joinRoute(routeDir, "index.mdx");
139
+ } else {
140
+ const slug = routeSegment(stem);
141
+ if (slug === "") {
142
+ throw new DocSourcesPlanError(`${describe(file)}: file name has no usable route segment`);
143
+ }
144
+ outputRel = joinRoute(routeDir, `${slug}.mdx`);
145
+ }
146
+ claim(`doc:${outputRel}`, describe(file));
147
+ docs.push({ file, source, routeDir, outputRel, landing });
148
+ segments.forEach((original, index) => {
149
+ const dir = joinRoute(baseRoute, ...dirSegments.slice(0, index + 1));
150
+ if (!directories.has(dir)) directories.set(dir, { source, label: { fallback: original } });
151
+ });
152
+ }
153
+ const ownedDirs = new Set(docs.filter((d) => d.landing).map((d) => d.routeDir));
154
+ const publishedDirs = /* @__PURE__ */ new Set();
155
+ for (const doc of docs) {
156
+ const parts = doc.routeDir.split("/");
157
+ for (let i = 1; i <= parts.length; i++) publishedDirs.add(parts.slice(0, i).join("/"));
158
+ }
159
+ const lookupByPath = /* @__PURE__ */ new Map();
160
+ const remember = (p, entry) => {
161
+ if (!lookupByPath.has(p)) lookupByPath.set(p, entry);
162
+ };
163
+ for (const doc of docs) {
164
+ remember(doc.file.abs, { doc });
165
+ remember(doc.file.real, { doc });
166
+ }
167
+ for (const asset of assets) {
168
+ remember(asset.file.abs, { asset });
169
+ remember(asset.file.real, { asset });
170
+ }
171
+ const outputs = [];
172
+ const locales = Object.entries(options.locales);
173
+ const label = (ref, locale) => resolveLabel(ref, locale, options.defaultLocale, options.translations);
174
+ let indexCount = 0;
175
+ for (const [routeDir, info] of [...directories.entries()].sort(([a], [b]) => a.localeCompare(b))) {
176
+ if (ownedDirs.has(routeDir) || !publishedDirs.has(routeDir)) continue;
177
+ const targets = [[options.defaultLocale, options.docsDir]];
178
+ for (const [locale, dir] of locales) {
179
+ if (shouldEmitLocaleRoute(routeDir, locale, options.defaultLocale, options.defaultLocaleOnlyPrefixes)) {
180
+ targets.push([locale, dir]);
181
+ }
182
+ }
183
+ for (const [locale, contentDir] of targets) {
184
+ const title = label(info.label, locale);
185
+ const description = info.description ? label(info.description, locale) : void 0;
186
+ const frontmatter = renderFrontmatter([
187
+ ["title", title],
188
+ ["description", description],
189
+ ["sidebar_position", info.position],
190
+ ["generated", true],
191
+ ["doc_source", info.source.id]
192
+ ]);
193
+ outputs.push({
194
+ abs: path.join(contentDir, ...routeDir.split("/"), "index.mdx"),
195
+ content: `${frontmatter}
196
+
197
+ <CategoryNav category=${JSON.stringify(routeDir)} />
198
+ `
199
+ });
200
+ indexCount++;
201
+ }
202
+ }
203
+ for (const doc of docs) {
204
+ const { file } = doc;
205
+ const warn = (message) => diagnostics.push({ level: "warn", message: `${describe(file)}: ${message}` });
206
+ let source;
207
+ try {
208
+ source = fs.readFileSync(file.abs, "utf8");
209
+ } catch (error) {
210
+ throw new DocSourcesPlanError(`${describe(file)}: cannot read source (${String(error)})`);
211
+ }
212
+ const resolve = (url) => {
213
+ const { pathPart, query, fragment } = splitDestination(url);
214
+ if (pathPart === "") return { kind: "keep" };
215
+ const target = path.resolve(path.dirname(file.abs), safeDecode(pathPart));
216
+ const candidates = [target];
217
+ if (pathPart.endsWith("/") || !/\.[^/]+$/.test(pathPart)) {
218
+ for (const name of ["README.md", "index.md", "index.mdx", "SKILL.md", "CLAUDE.md", "AGENTS.md"]) {
219
+ candidates.push(path.join(target, name));
220
+ }
221
+ }
222
+ for (const candidate of candidates) {
223
+ let hit = lookupByPath.get(candidate);
224
+ if (hit === void 0) {
225
+ try {
226
+ hit = lookupByPath.get(fs.realpathSync.native(candidate));
227
+ } catch {
228
+ hit = void 0;
229
+ }
230
+ }
231
+ if (hit?.doc !== void 0) {
232
+ let rel = path.posix.relative(path.posix.dirname(doc.outputRel), hit.doc.outputRel);
233
+ if (!rel.startsWith(".")) rel = `./${rel}`;
234
+ return { kind: "rewrite", url: `${rel}${query}${fragment}` };
235
+ }
236
+ if (hit?.asset !== void 0) {
237
+ return { kind: "rewrite", url: `${hit.asset.url}${query}${fragment}` };
238
+ }
239
+ }
240
+ return { kind: "unmapped" };
241
+ };
242
+ const linkify = (markdown) => {
243
+ const result = rewriteLinks(markdown, resolve);
244
+ if (result.unmapped.length > 0) {
245
+ warn(`unpublished link target(s) kept as text: ${[...new Set(result.unmapped)].join(", ")}`);
246
+ }
247
+ return result.content;
248
+ };
249
+ const { mapping } = file;
250
+ const baseName = path.posix.basename(file.rel);
251
+ let title;
252
+ let description = "";
253
+ let body;
254
+ if (file.kind === "skill-page" || mapping.renderer === "markdown" || mapping.renderer === "skill") {
255
+ const parsed = parseFrontmatter(source);
256
+ const data = parsed?.data ?? {};
257
+ const content = parsed?.content ?? source;
258
+ const fmString = (key) => typeof data[key] === "string" && data[key] !== "" ? data[key] : void 0;
259
+ const h1 = content.match(/^#\s+(.+?)\s*#*\s*$/m)?.[1];
260
+ const isSkill = file.kind === "document" && mapping.renderer === "skill";
261
+ const skillDir = path.posix.dirname(file.rel);
262
+ const skillName = skillDir === "." ? path.basename(mapping.root) : path.posix.basename(skillDir);
263
+ title = mapping.titleFromPath && file.kind === "document" ? file.rel : fmString("title") ?? fmString("name") ?? (isSkill ? skillName : void 0) ?? h1 ?? stripExtension(baseName, [".md", ".mdx"]);
264
+ description = fmString("description") ?? "";
265
+ if (isSkill && description.length > 200) description = `${description.slice(0, 200)}...`;
266
+ const metaRows = Object.entries(data).filter(([key, value]) => !["title", "name", "description"].includes(key) && (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || Array.isArray(value) && value.every((v) => typeof v !== "object"))).map(([key, value]) => renderTableRow([key, Array.isArray(value) ? value.join(", ") : value]));
267
+ const metaTable = metaRows.length > 0 ? ["| Field | Value |", "| --- | --- |", ...metaRows].join("\n") : "";
268
+ let extra = "";
269
+ let structure = "";
270
+ if (isSkill) {
271
+ const tree = discovery.skillTrees.get(`${mapping.sourceId}\0${mapping.id}\0${skillDir}`) ?? [];
272
+ if (tree.includes("agents/openai.yaml")) {
273
+ try {
274
+ extra = renderSkillInterfaceMetadata(
275
+ fs.readFileSync(path.join(path.dirname(file.abs), "agents", "openai.yaml"), "utf8"),
276
+ skillName,
277
+ warn
278
+ );
279
+ } catch (error) {
280
+ warn(`agents/openai.yaml: unable to read (${String(error)})`);
281
+ }
282
+ }
283
+ structure = renderSkillFileStructure(skillName, tree);
284
+ }
285
+ const markdown = [structure, content.trim()].filter(Boolean).join("\n\n");
286
+ body = [extra, metaTable, escapeForMdx(linkify(markdown))].filter(Boolean).join("\n\n");
287
+ } else if (mapping.renderer === "code") {
288
+ title = baseName;
289
+ const firstLines = source.split("\n", 2);
290
+ const commentLine = (firstLines[0] ?? "").startsWith("#!") ? firstLines[1] ?? "" : firstLines[0] ?? "";
291
+ description = commentLine.match(/^(?:#|\/\/)\s*(.+)/)?.[1]?.trim() ?? "";
292
+ body = `## Source
293
+
294
+ ${renderCodeFence(source, languageForFilename(baseName))}`;
295
+ } else if (mapping.renderer === "codex-agent") {
296
+ ({ title, description, body } = renderCodexAgent(source, stripExtension(baseName, [".toml"]), warn));
297
+ } else if (mapping.renderer === "codex-config") {
298
+ ({ title, description, body } = renderCodexConfig(source, baseName, warn));
299
+ } else if (mapping.renderer === "codex-hooks") {
300
+ ({ title, description, body } = renderCodexHooks(source, baseName, warn));
301
+ } else {
302
+ ({ title, description, body } = renderCodexRules(source, baseName));
303
+ }
304
+ const section = directories.get(doc.routeDir);
305
+ const ownsSection = doc.landing && section !== void 0 && section.position !== void 0;
306
+ const fields = [
307
+ ["title", title],
308
+ ["description", description],
309
+ ["sidebar_label", ownsSection ? label(section.label, options.defaultLocale) : void 0],
310
+ ["sidebar_position", ownsSection ? section.position : void 0],
311
+ ["unlisted", file.kind === "skill-page" ? true : void 0],
312
+ ["generated", true],
313
+ ["doc_source", mapping.sourceId],
314
+ ["doc_source_mapping", mapping.id],
315
+ ["doc_source_path", file.rel]
316
+ ];
317
+ outputs.push({
318
+ abs: path.join(options.docsDir, ...doc.outputRel.split("/")),
319
+ content: `${renderFrontmatter(fields)}
320
+
321
+ ${body.trim()}
322
+ `
323
+ });
324
+ }
325
+ for (const asset of assets) {
326
+ try {
327
+ outputs.push({ abs: asset.outputAbs, content: fs.readFileSync(asset.file.abs) });
328
+ } catch (error) {
329
+ throw new DocSourcesPlanError(`${describe(asset.file)}: cannot read asset (${String(error)})`);
330
+ }
331
+ }
332
+ const outputRoots = options.sources.flatMap((source) => [
333
+ path.join(options.docsDir, source.mount),
334
+ ...locales.map(([, dir]) => path.join(dir, source.mount)),
335
+ path.join(options.publicDir, ASSET_DIR, source.mount)
336
+ ]);
337
+ return {
338
+ outputs,
339
+ outputRoots,
340
+ diagnostics,
341
+ counts: { documents: docs.length, assets: assets.length, indexes: indexCount }
342
+ };
343
+ }
344
+ export {
345
+ ASSET_DIR,
346
+ DocSourcesPlanError,
347
+ buildPlan,
348
+ escapeMarkdownTableCell,
349
+ routeSegment
350
+ };
@@ -0,0 +1,12 @@
1
+ import type { NormalizedSource } from "./model.js";
2
+ /** Directories skipped by the bundled instruction scans at any depth. */
3
+ export declare const DEFAULT_SCAN_EXCLUDES: string[];
4
+ export interface PresetInput {
5
+ id: string;
6
+ mount: string;
7
+ /** Absolute agent configuration directory. */
8
+ root: string;
9
+ /** Absolute instruction scan root. */
10
+ scanRoot: string;
11
+ }
12
+ export declare const PRESETS: Record<string, (input: PresetInput) => NormalizedSource>;
@@ -0,0 +1,182 @@
1
+ import path from "node:path";
2
+ const DEFAULT_SCAN_EXCLUDES = [
3
+ "**/.*/**",
4
+ "**/node_modules/**",
5
+ "**/dist/**",
6
+ "**/out/**",
7
+ "**/public/**",
8
+ "**/worktrees/**",
9
+ "**/__inbox/**",
10
+ "**/test-results/**"
11
+ ];
12
+ const MARKDOWN_EXTENSIONS = [".md", ".mdx"];
13
+ function section(name, fallback, description) {
14
+ return {
15
+ sectionLabel: { key: `docSources.section.${name}.label`, fallback },
16
+ sectionDescription: { key: `docSources.section.${name}.description`, fallback: description }
17
+ };
18
+ }
19
+ function mapping(sourceId, fields) {
20
+ return {
21
+ sourceId,
22
+ exclude: [],
23
+ missing: "skip",
24
+ landingNames: [],
25
+ stripExtensions: [],
26
+ titleFromPath: false,
27
+ ...fields
28
+ };
29
+ }
30
+ function claudeCode(input) {
31
+ const { id, root, scanRoot } = input;
32
+ return {
33
+ id,
34
+ mount: input.mount,
35
+ preset: "claude-code",
36
+ title: { key: "docSources.claudeCode.title", fallback: "Claude Code" },
37
+ description: {
38
+ key: "docSources.claudeCode.description",
39
+ fallback: "Claude Code configuration reference."
40
+ },
41
+ requiredRoots: [root],
42
+ mappings: [
43
+ mapping(id, {
44
+ id: "instructions",
45
+ root: scanRoot,
46
+ include: ["**/CLAUDE.md"],
47
+ exclude: DEFAULT_SCAN_EXCLUDES,
48
+ to: "instructions",
49
+ renderer: "markdown",
50
+ missing: "error",
51
+ landingNames: ["claude.md"],
52
+ stripExtensions: MARKDOWN_EXTENSIONS,
53
+ titleFromPath: true,
54
+ ...section("instructions", "Instructions", "Project instruction files")
55
+ }),
56
+ mapping(id, {
57
+ id: "commands",
58
+ root: path.join(root, "commands"),
59
+ include: ["**/*.md"],
60
+ to: "commands",
61
+ renderer: "markdown",
62
+ stripExtensions: MARKDOWN_EXTENSIONS,
63
+ ...section("commands", "Commands", "Custom slash commands")
64
+ }),
65
+ mapping(id, {
66
+ id: "skills",
67
+ root: path.join(root, "skills"),
68
+ include: ["*/SKILL.md"],
69
+ to: "skills",
70
+ renderer: "skill",
71
+ stripExtensions: MARKDOWN_EXTENSIONS,
72
+ ...section("skills", "Skills", "Skill packages")
73
+ }),
74
+ mapping(id, {
75
+ id: "agents",
76
+ root: path.join(root, "agents"),
77
+ include: ["**/*.md"],
78
+ to: "agents",
79
+ renderer: "markdown",
80
+ stripExtensions: MARKDOWN_EXTENSIONS,
81
+ ...section("agents", "Agents", "Custom subagents")
82
+ })
83
+ ]
84
+ };
85
+ }
86
+ function codex(input) {
87
+ const { id, root, scanRoot } = input;
88
+ return {
89
+ id,
90
+ mount: input.mount,
91
+ preset: "codex",
92
+ title: { key: "docSources.codex.title", fallback: "Codex" },
93
+ description: {
94
+ key: "docSources.codex.description",
95
+ fallback: "OpenAI Codex configuration reference."
96
+ },
97
+ requiredRoots: [root],
98
+ mappings: [
99
+ mapping(id, {
100
+ id: "instructions",
101
+ root: scanRoot,
102
+ include: ["**/AGENTS.md", "**/AGENTS.override.md"],
103
+ exclude: DEFAULT_SCAN_EXCLUDES,
104
+ to: "instructions",
105
+ renderer: "markdown",
106
+ missing: "error",
107
+ landingNames: ["agents.md"],
108
+ stripExtensions: MARKDOWN_EXTENSIONS,
109
+ titleFromPath: true,
110
+ ...section("instructions", "Instructions", "Project instruction files")
111
+ }),
112
+ mapping(id, {
113
+ id: "config",
114
+ root,
115
+ include: ["config.toml", "config.toml.example", "*.config.toml"],
116
+ to: "config",
117
+ renderer: "codex-config",
118
+ ...section("config", "Config", "config.toml and profiles")
119
+ }),
120
+ mapping(id, {
121
+ id: "agents",
122
+ root: path.join(root, "agents"),
123
+ include: ["*.toml"],
124
+ to: "agents",
125
+ renderer: "codex-agent",
126
+ stripExtensions: [".toml"],
127
+ ...section("agents", "Agents", "Custom subagents")
128
+ }),
129
+ mapping(id, {
130
+ id: "hooks-config",
131
+ root,
132
+ include: ["hooks.json"],
133
+ to: "hooks",
134
+ renderer: "codex-hooks",
135
+ ...section("hooks", "Hooks", "Lifecycle hooks")
136
+ }),
137
+ mapping(id, {
138
+ id: "hooks",
139
+ root: path.join(root, "hooks"),
140
+ include: ["**/*"],
141
+ to: "hooks",
142
+ renderer: "code",
143
+ ...section("hooks", "Hooks", "Lifecycle hooks")
144
+ }),
145
+ mapping(id, {
146
+ id: "rules",
147
+ root: path.join(root, "rules"),
148
+ include: ["*.rules"],
149
+ to: "rules",
150
+ renderer: "codex-rules",
151
+ stripExtensions: [".rules"],
152
+ ...section("rules", "Rules", "Command approval rules")
153
+ }),
154
+ mapping(id, {
155
+ id: "skills",
156
+ root: path.join(root, "skills"),
157
+ include: ["*/SKILL.md"],
158
+ to: "skills",
159
+ renderer: "skill",
160
+ stripExtensions: MARKDOWN_EXTENSIONS,
161
+ ...section("skills", "Skills", "Skill packages")
162
+ }),
163
+ mapping(id, {
164
+ id: "team-skills",
165
+ root: path.join(scanRoot, ".agents", "skills"),
166
+ include: ["*/SKILL.md"],
167
+ to: "skills",
168
+ renderer: "skill",
169
+ stripExtensions: MARKDOWN_EXTENSIONS,
170
+ ...section("skills", "Skills", "Skill packages")
171
+ })
172
+ ]
173
+ };
174
+ }
175
+ const PRESETS = {
176
+ "claude-code": claudeCode,
177
+ codex
178
+ };
179
+ export {
180
+ DEFAULT_SCAN_EXCLUDES,
181
+ PRESETS
182
+ };
@@ -0,0 +1,20 @@
1
+ import type { DocSourcesDiagnostic } from "./model.js";
2
+ import type { PlannedOutput } from "./plan.js";
3
+ export declare const MANIFEST_FILE = "manifest.json";
4
+ export declare class DocSourcesReconcileError extends Error {
5
+ constructor(message: string);
6
+ }
7
+ export interface ReconcileOptions {
8
+ projectRoot: string;
9
+ stateDir: string;
10
+ outputs: PlannedOutput[];
11
+ /** Absolute roots planned outputs must stay inside. */
12
+ outputRoots: string[];
13
+ }
14
+ export interface ReconcileResult {
15
+ written: string[];
16
+ removed: string[];
17
+ unchanged: number;
18
+ diagnostics: DocSourcesDiagnostic[];
19
+ }
20
+ export declare function reconcile(options: ReconcileOptions): ReconcileResult;