@takazudo/zudo-doc 13.0.0 → 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 +28 -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
package/CHANGELOG.md CHANGED
@@ -6,6 +6,34 @@ The format is based on Keep a Changelog, and release notes are generated from th
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [14.0.0] - 2026-11-24
10
+
11
+ ### Breaking Changes
12
+
13
+ - The `@takazudo/zudo-doc-history-server` peer floor moves from `^13.0.0` to `^14.0.0`. Projects that enable document history need history-server 14.x.
14
+ - The `claudeResources` and `codexResources` settings, and the `@takazudo/zudo-doc/plugins/claude-resources` and `plugins/codex-resources` plugins, are removed without compatibility shims. Configure the same content through `docSources` with the `claude-code` and `codex` presets. The old routes (`/docs/claude-md/…`, `/docs/claude-commands/…`, `/docs/claude-skills/…`, `/docs/claude-agents/…`, `/docs/codex-agents-md/…`, `/docs/codex-config/…`, `/docs/codex-agents/…`, `/docs/codex-hooks/…`, `/docs/codex-rules/…`, `/docs/codex-skills/…`) are not redirected; their pages now live below each source's mount, such as `/docs/claude/skills/…`. Update `headerNav` items, `defaultLocaleOnlyPrefixes` entries and inbound links, and rename `resource.*` translation overrides to the matching `docSources.*` keys. See the migration section of Document Sources.
15
+ - One-time cleanup for existing checkouts: the old generators left gitignored output in `claude/`, `claude-agents/`, `claude-commands/`, `claude-md/`, `claude-skills/`, `codex/`, `codex-agents/`, `codex-agents-md/`, `codex-config/`, `codex-hooks/`, `codex-rules/` and `codex-skills/` under the default content directory and each locale directory. The new engine refuses to overwrite files it does not own under `claude/` and `codex/`. Before the first build, list the files in those directories whose frontmatter has `generated: true` (for example with `grep -rl '^generated: true'`), review the list, and delete only those files. Keep anything else for manual review. The guide has a ready-made snippet.
16
+
17
+ ### Features
18
+
19
+ - New optional `docSources` setting (default `[]`) publishes files from outside `docsDir` as generated sections at `/docs/<mount>/<section>/<path>/`. Entries are bundled presets (`{ id, preset: "claude-code" | "codex", root, scanRoot?, mount? }`) or custom sources with explicit mappings (`{ id, title, mount?, mappings }`), each mapping selecting files by glob from a root (relative, absolute or `~/`) and rendering them as `markdown`, `code` or `skill`. `index.md`, `index.mdx` and `README.md` become directory landings, indexes are synthesized only where no document owns the route, and route collisions fail the build.
20
+ - Links between mapped files are rewritten to the generated pages (fragments and queries kept); unmapped targets stay readable text with a build warning, and mapped assets are copied to `public/doc-sources/<mount>/…`. Generated pages carry `generated: true` with `doc_source`, `doc_source_mapping` and `doc_source_path` provenance and show no document history or view-source link.
21
+ - Generated output is tracked in a build-local manifest (`.zfb/doc-sources/manifest.json`): only changed files are written, stale unchanged outputs are removed (also when `docSources` is `[]`), authored files are never overwritten, and a failed run keeps the previous output.
22
+ - New `zudo-doc sources watch` command regenerates document-source output beside `zfb dev` on file and directory changes. It replaces the repository's former `dev-claude-watch` and `dev-codex-watch` scripts.
23
+
24
+ ### Other Changes
25
+
26
+ - Require the ZFB 7.2.0 family (`^7.2.0`). 7.2.0 keeps the Linux arm64 npm CLI and CSS carrier that 7.1.0 restored, and updates the `url` crate to 2.5.9 for RUSTSEC-2026-0592. The rest of 7.2.0 is dev-server recovery (trailing-slash request-time SSR, a rejected content snapshot that keeps the last good generation, and route reselection after a failed refresh) plus the optional `ZFB_DEV_PROVENANCE_TRACE` variable. Production bundles and the public config surface are unchanged. Upgrade `@takazudo/zfb`, `@takazudo/zfb-runtime`, `@takazudo/zfb-md-wasm` and, when used, `@takazudo/zfb-adapter-cloudflare` together.
27
+ - The workspace uses `@takazudo/zdtp` 0.9.10. The peer floor stays `^0.5.2 || ^0.6.0 || ^0.7.0 || ^0.8.0 || ^0.9.0`, which already admits 0.9.10. 0.9.10 keeps that zfb peer (`^5.1.2 || ^6.0.0 || ^7.0.0`) and builds against zfb 7.2.0 and zudo-doc 13.0.1.
28
+ - The `@inquirer/prompts` dependency floor moves from `^8.7.5` to `^8.8.1`.
29
+
30
+ ## [13.0.1] - 2026-11-19
31
+
32
+ ### Other Changes
33
+
34
+ - Require the ZFB 7.1.0 family (`^7.1.0`). 7.1.0 publishes `@takazudo/zfb-linux-arm64-gnu` again, so a Linux arm64 npm install receives the CLI and CSS carrier that 7.0.0 omitted. Linux x64, macOS and Windows npm installs are unchanged.
35
+ - The workspace uses `@takazudo/zdtp` 0.9.9. The peer floor stays `^0.5.2 || ^0.6.0 || ^0.7.0 || ^0.8.0 || ^0.9.0`, which already admits 0.9.9. 0.9.9 keeps that same zfb peer and builds against zfb 7.1.0.
36
+
9
37
  ## [13.0.0] - 2026-11-16
10
38
 
11
39
  ### Breaking Changes
package/bin/zudo-doc.mjs CHANGED
@@ -24,6 +24,7 @@
24
24
  // zudo-doc theme list # list installed theme packs + the active one
25
25
  // zudo-doc theme apply <slug> # rewrite zfb.config.ts's themePack field
26
26
  // zudo-doc check images # fail when built HTML references a missing asset
27
+ // zudo-doc sources watch # regenerate docSources output while `zfb dev` runs
27
28
  // zudo-doc --help # show help
28
29
 
29
30
  import minimist from "minimist";
@@ -69,6 +70,9 @@ ${pc.bold("Subcommands:")}
69
70
  theme apply <slug> Rewrite zfb.config.ts's themePack field to <slug>.
70
71
  check images [options]
71
72
  Fail when built HTML references a missing local asset.
73
+ sources watch Regenerate docSources output when source files change.
74
+ Run it beside \`zfb dev\`; it reuses the configuration
75
+ the docSources build plugin recorded.
72
76
 
73
77
  ${pc.bold("Ejectable components:")}
74
78
  ${validNames}
@@ -262,6 +266,33 @@ function runCheckImages(checkArgs) {
262
266
  );
263
267
  }
264
268
 
269
+ async function runSourcesWatch(watchArgs) {
270
+ if (watchArgs.length > 0) {
271
+ console.error(pc.red(`Unexpected argument "${watchArgs[0]}".`) + "\nUsage: zudo-doc sources watch");
272
+ process.exit(1);
273
+ }
274
+ const { homedir } = await import("node:os");
275
+ const { startDocSourcesWatcher } = await import("../dist/plugins/internal/doc-sources/watch.js");
276
+ const watcher = startDocSourcesWatcher({
277
+ projectRoot: process.cwd(),
278
+ homeDir: () => homedir(),
279
+ logger: {
280
+ info: (message) => console.log(pc.dim(message)),
281
+ warn: (message) => console.warn(pc.yellow(message)),
282
+ error: (message) => console.error(pc.red(message)),
283
+ },
284
+ });
285
+ let closing = false;
286
+ const shutdown = async () => {
287
+ if (closing) return;
288
+ closing = true;
289
+ await watcher.close();
290
+ process.exit(0);
291
+ };
292
+ process.on("SIGINT", shutdown);
293
+ process.on("SIGTERM", shutdown);
294
+ }
295
+
265
296
  async function main() {
266
297
  if (argv._[0] === "check" && argv._[1] === "images" && argv["help"]) {
267
298
  printCheckImagesHelp();
@@ -279,6 +310,7 @@ async function main() {
279
310
  if (subcommand === "eject") return runEject(rest[0]);
280
311
  if (subcommand === "theme") return runTheme(rest);
281
312
  if (subcommand === "check" && rest[0] === "images") return runCheckImages(rest.slice(1));
313
+ if (subcommand === "sources" && rest[0] === "watch") return runSourcesWatch(rest.slice(1));
282
314
 
283
315
  console.error(
284
316
  pc.red(`Unknown subcommand "${subcommand}".`) +
package/dist/config.d.ts CHANGED
@@ -68,21 +68,10 @@
68
68
  */
69
69
  import type { ZfbConfig, BundleConfig, WindConfig } from "@takazudo/zfb/config";
70
70
  import type { ZodType } from "zod";
71
+ import type { DocSourceEntry } from "./doc-sources/types.js";
71
72
  import type { DirectiveVocabulary, PresetTranslations, PresetTagVocabularyEntry } from "./preset.js";
72
73
  import type { ColorScheme } from "./color-scheme-utils.js";
73
74
  import type { Settings, ColorModeConfig, ContentSignalsConfig, LocaleConfig, MetaTagsConfig, SiteHeadConfig, TagPlacement, TagGovernanceMode, VersionConfig, FooterConfig, HeaderNavItem, HeaderRightItem, HomeConfig, AssetViewerIndexingConfig, FrontmatterPreviewConfig, BodyFootUtilAreaConfig, HtmlPreviewConfig, FaviconConfig, HeaderBrandConfig, DateFormatSetting } from "./settings.js";
74
- /** The `settings.claudeResources` block (or `false` when disabled). */
75
- type ClaudeResourcesConfig = {
76
- claudeDir: string;
77
- projectRoot?: string;
78
- scanRoot?: string;
79
- } | false;
80
- /** The `settings.codexResources` block (or `false` when disabled). */
81
- type CodexResourcesConfig = {
82
- codexDir: string;
83
- projectRoot?: string;
84
- scanRoot?: string;
85
- } | false;
86
75
  export { DEFAULT_SETTINGS } from "./settings-defaults.js";
87
76
  export interface ZudoDocConfig {
88
77
  /**
@@ -503,22 +492,16 @@ export interface ZudoDocConfig {
503
492
  */
504
493
  versions?: VersionConfig[] | false;
505
494
  /**
506
- * Claude-resources ingestion config, or `false` to disable.
507
- * @default false
508
- */
509
- claudeResources?: ClaudeResourcesConfig;
510
- /**
511
- * Codex-resources ingestion config, or `false` to disable.
512
- * `codexDir` is the `.codex/` directory, resolved against `projectRoot`.
513
- * `projectRoot` anchors relative paths and the output base. `scanRoot` is
514
- * the repo-wide discovery root for the `AGENTS.md` / `AGENTS.override.md`
515
- * walk (including its relPath base for titles/slugs) and the repo-level
516
- * `.agents/skills/` root; it defaults to `projectRoot`. This lets a doc site
517
- * in a repo subdirectory scan repo-wide instructions and team skills while
518
- * writing into its own collection (#2558).
519
- * @default false
495
+ * Files outside `docsDir` baked into nested documentation routes
496
+ * (`/docs/<mount>/<section>/<path>`). Each entry is a bundled preset
497
+ * (`{ id, preset: "claude-code" | "codex", root, scanRoot?, mount? }`) or a
498
+ * custom source (`{ id, title, mount?, mappings: [...] }`). Data only:
499
+ * relative paths resolve from the project root; absolute paths and `~/`
500
+ * are accepted. The package plugin does all filesystem work at build time
501
+ * and removes stale generated output when entries are removed.
502
+ * @default []
520
503
  */
521
- codexResources?: CodexResourcesConfig;
504
+ docSources?: DocSourceEntry[];
522
505
  /**
523
506
  * Route prefixes served only in the default locale (never locale-prefixed).
524
507
  * @default []
@@ -35,7 +35,7 @@ function createDocContentHeader(ctx) {
35
35
  entry.data.date && entry.data.updated ? " \xB7 " : null,
36
36
  entry.data.updated ? `${t("doc.updated", locale)} ${formatDate(entry.data.updated, locale, dateFormatsFor(locale).full)}` : null
37
37
  ] }),
38
- !version && /* @__PURE__ */ jsx(DocMetainfoArea, { slug, locale, isFallback }),
38
+ !version && !entry.data.generated && /* @__PURE__ */ jsx(DocMetainfoArea, { slug, locale, isFallback }),
39
39
  !version && /* @__PURE__ */ jsx(DocTagsArea, { slug, locale, tags: entry.data.tags }),
40
40
  isFallback && !entry.data.generated && /* @__PURE__ */ jsx(
41
41
  "div",
@@ -119,7 +119,9 @@ function createRenderDocPage(ctx) {
119
119
  docHistorySlot: (
120
120
  // #1916 #5: doc-history hidden on versioned pages until versioned
121
121
  // history is supported.
122
- !version && opts.docHistoryContentDir !== void 0 && props.kind === "entry" && !props.entry.data.unlisted ? /* @__PURE__ */ jsx(
122
+ !version && opts.docHistoryContentDir !== void 0 && props.kind === "entry" && !props.entry.data.unlisted && // docSources pages: the history and view-source link of the derived
123
+ // MDX file would point at a gitignored build artifact, not the source.
124
+ !props.entry.data.generated ? /* @__PURE__ */ jsx(
123
125
  DocHistoryArea,
124
126
  {
125
127
  slug,
@@ -0,0 +1,65 @@
1
+ /** Bundled presets that expand into ordinary mappings. */
2
+ export type DocSourcePresetName = "claude-code" | "codex";
3
+ /** How a mapped file is rendered into documentation. */
4
+ export type DocSourceFormat = "markdown" | "code" | "skill";
5
+ /** What to do when a mapping root does not exist. */
6
+ export type DocSourceMissingPolicy = "error" | "skip";
7
+ /** A file selection relative to a mapping root. */
8
+ export interface DocSourceAssetSelection {
9
+ /** Glob patterns (relative to the mapping root) of assets to publish. */
10
+ include: string[];
11
+ /** Glob patterns removed from `include`. */
12
+ exclude?: string[];
13
+ }
14
+ /** One custom mapping from a source tree into a documentation subtree. */
15
+ export interface DocSourceMapping {
16
+ /** Stable mapping identifier, unique within its source. */
17
+ id: string;
18
+ /**
19
+ * Directory the mapping reads from. Relative paths resolve from the
20
+ * documentation project root; absolute paths and an explicit `~/` prefix
21
+ * are also accepted.
22
+ */
23
+ root: string;
24
+ /** Glob patterns, relative to `root`, selecting the documents to publish. */
25
+ include: string[];
26
+ /** Glob patterns removed from `include`. */
27
+ exclude?: string[];
28
+ /**
29
+ * Relative route subtree below the source mount (for example
30
+ * `"handbook"` or `"guides/ops"`). Defaults to the mount itself.
31
+ */
32
+ to?: string;
33
+ /** Rendering of every selected document. */
34
+ format: DocSourceFormat;
35
+ /** Missing-root policy. Defaults to `"error"`. */
36
+ missing?: DocSourceMissingPolicy;
37
+ /** Non-document files (images, attachments) to publish as managed assets. */
38
+ assets?: DocSourceAssetSelection;
39
+ }
40
+ /** A bundled preset instance. */
41
+ export interface DocSourcePresetEntry {
42
+ /** Stable source identifier. Also the default mount. */
43
+ id: string;
44
+ preset: DocSourcePresetName;
45
+ /** The agent configuration directory, for example `.claude` or `.codex`. */
46
+ root: string;
47
+ /**
48
+ * Directory scanned for instruction files (`CLAUDE.md`, `AGENTS.md`) and,
49
+ * for Codex, `.agents/skills`. Defaults to the documentation project root.
50
+ */
51
+ scanRoot?: string;
52
+ /** Top-level documentation segment. Defaults to `id`. */
53
+ mount?: string;
54
+ }
55
+ /** A custom source built from explicit mappings. */
56
+ export interface DocSourceCustomEntry {
57
+ /** Stable source identifier. Also the default mount. */
58
+ id: string;
59
+ /** Display title of the source's landing page. */
60
+ title: string;
61
+ /** Top-level documentation segment. Defaults to `id`. */
62
+ mount?: string;
63
+ mappings: DocSourceMapping[];
64
+ }
65
+ export type DocSourceEntry = DocSourcePresetEntry | DocSourceCustomEntry;
File without changes
@@ -57,6 +57,9 @@ export declare function buildDocsSchema(opts?: BuildDocsSchemaOptions): z.ZodObj
57
57
  standalone: z.ZodOptional<z.ZodBoolean>;
58
58
  slug: z.ZodOptional<z.ZodString>;
59
59
  generated: z.ZodOptional<z.ZodBoolean>;
60
+ doc_source: z.ZodOptional<z.ZodString>;
61
+ doc_source_mapping: z.ZodOptional<z.ZodString>;
62
+ doc_source_path: z.ZodOptional<z.ZodString>;
60
63
  cover: z.ZodOptional<z.ZodString>;
61
64
  og_image: z.ZodOptional<z.ZodString>;
62
65
  category_no_page: z.ZodOptional<z.ZodBoolean>;
@@ -31,6 +31,10 @@ function buildDocsSchema(opts) {
31
31
  standalone: z.boolean().optional(),
32
32
  slug: z.string().optional(),
33
33
  generated: z.boolean().optional(),
34
+ // Provenance written by docSources: source id, mapping id, source-relative path.
35
+ doc_source: z.string().optional(),
36
+ doc_source_mapping: z.string().optional(),
37
+ doc_source_path: z.string().optional(),
34
38
  // Home-grid card picture for a top-level category's index page, a root-absolute site path.
35
39
  cover: z.string().refine(isRootAbsoluteSitePath, {
36
40
  message: 'cover must be a root-absolute site path such as "/img/guides.png"'
@@ -18,6 +18,9 @@ const defaultFrontmatterPreviewIgnoreKeys = [
18
18
  "standalone",
19
19
  "slug",
20
20
  "generated",
21
+ "doc_source",
22
+ "doc_source_mapping",
23
+ "doc_source_path",
21
24
  "category_no_page",
22
25
  "category_sort_order",
23
26
  "category_shape",
@@ -56,31 +56,24 @@ const defaultTranslations = {
56
56
  "doc.seeAllTags": "See all tags",
57
57
  "doc.created": "Created",
58
58
  "doc.updated": "Updated",
59
- "resource.claudeMd.label": "CLAUDE.md",
60
- "resource.claudeMd.description": "Project-specific instructions",
61
- "resource.claudeCommands.label": "Commands",
62
- "resource.claudeCommands.description": "Custom slash commands",
63
- "resource.claudeSkills.label": "Skills",
64
- "resource.claudeSkills.description": "Skill packages",
65
- "resource.claudeAgents.label": "Agents",
66
- "resource.claudeAgents.description": "Custom subagents",
67
- "resource.codexAgentsMd.label": "AGENTS.md",
68
- "resource.codexAgentsMd.description": "Project instructions for Codex",
69
- "resource.codexConfig.label": "Config",
70
- "resource.codexConfig.description": "config.toml and profiles",
71
- "resource.codexAgents.label": "Agents",
72
- "resource.codexAgents.description": "Custom subagents",
73
- "resource.codexHooks.label": "Hooks",
74
- "resource.codexHooks.description": "Lifecycle hooks",
75
- "resource.codexRules.label": "Rules",
76
- "resource.codexRules.description": "Command approval rules",
77
- "resource.codexSkills.label": "Skills",
78
- "resource.codexSkills.description": "Skill packages",
79
- "resource.claude.title": "Claude",
80
- "resource.claude.description": "Claude Code configuration reference.",
81
- "resource.codex.title": "Codex",
82
- "resource.codex.description": "OpenAI Codex configuration reference.",
83
- "resource.resources": "Resources",
59
+ "docSources.claudeCode.title": "Claude Code",
60
+ "docSources.claudeCode.description": "Claude Code configuration reference.",
61
+ "docSources.codex.title": "Codex",
62
+ "docSources.codex.description": "OpenAI Codex configuration reference.",
63
+ "docSources.section.instructions.label": "Instructions",
64
+ "docSources.section.instructions.description": "Project instruction files",
65
+ "docSources.section.commands.label": "Commands",
66
+ "docSources.section.commands.description": "Custom slash commands",
67
+ "docSources.section.skills.label": "Skills",
68
+ "docSources.section.skills.description": "Skill packages",
69
+ "docSources.section.agents.label": "Agents",
70
+ "docSources.section.agents.description": "Custom subagents",
71
+ "docSources.section.config.label": "Config",
72
+ "docSources.section.config.description": "config.toml and profiles",
73
+ "docSources.section.hooks.label": "Hooks",
74
+ "docSources.section.hooks.description": "Lifecycle hooks",
75
+ "docSources.section.rules.label": "Rules",
76
+ "docSources.section.rules.description": "Command approval rules",
84
77
  "asset.badge": "Asset",
85
78
  "asset.crumb": "Assets",
86
79
  "asset.indexBadge": "Index",
@@ -198,31 +191,24 @@ const defaultTranslations = {
198
191
  "doc.seeAllTags": "\u3059\u3079\u3066\u306E\u30BF\u30B0\u3092\u898B\u308B",
199
192
  "doc.created": "\u4F5C\u6210",
200
193
  "doc.updated": "\u66F4\u65B0",
201
- "resource.claudeMd.label": "CLAUDE.md",
202
- "resource.claudeMd.description": "\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u56FA\u6709\u306E\u6307\u793A",
203
- "resource.claudeCommands.label": "\u30B3\u30DE\u30F3\u30C9",
204
- "resource.claudeCommands.description": "\u30AB\u30B9\u30BF\u30E0\u30B9\u30E9\u30C3\u30B7\u30E5\u30B3\u30DE\u30F3\u30C9",
205
- "resource.claudeSkills.label": "\u30B9\u30AD\u30EB",
206
- "resource.claudeSkills.description": "\u30B9\u30AD\u30EB\u30D1\u30C3\u30B1\u30FC\u30B8",
207
- "resource.claudeAgents.label": "\u30A8\u30FC\u30B8\u30A7\u30F3\u30C8",
208
- "resource.claudeAgents.description": "\u30AB\u30B9\u30BF\u30E0\u30B5\u30D6\u30A8\u30FC\u30B8\u30A7\u30F3\u30C8",
209
- "resource.codexAgentsMd.label": "AGENTS.md",
210
- "resource.codexAgentsMd.description": "Codex \u5411\u3051\u306E\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u6307\u793A",
211
- "resource.codexConfig.label": "\u8A2D\u5B9A",
212
- "resource.codexConfig.description": "config.toml \u3068\u30D7\u30ED\u30D5\u30A1\u30A4\u30EB",
213
- "resource.codexAgents.label": "\u30A8\u30FC\u30B8\u30A7\u30F3\u30C8",
214
- "resource.codexAgents.description": "\u30AB\u30B9\u30BF\u30E0\u30B5\u30D6\u30A8\u30FC\u30B8\u30A7\u30F3\u30C8",
215
- "resource.codexHooks.label": "\u30D5\u30C3\u30AF",
216
- "resource.codexHooks.description": "\u30E9\u30A4\u30D5\u30B5\u30A4\u30AF\u30EB\u30D5\u30C3\u30AF",
217
- "resource.codexRules.label": "\u30EB\u30FC\u30EB",
218
- "resource.codexRules.description": "\u30B3\u30DE\u30F3\u30C9\u627F\u8A8D\u30EB\u30FC\u30EB",
219
- "resource.codexSkills.label": "\u30B9\u30AD\u30EB",
220
- "resource.codexSkills.description": "\u30B9\u30AD\u30EB\u30D1\u30C3\u30B1\u30FC\u30B8",
221
- "resource.claude.title": "Claude",
222
- "resource.claude.description": "Claude Code \u306E\u8A2D\u5B9A\u30EA\u30D5\u30A1\u30EC\u30F3\u30B9\u3002",
223
- "resource.codex.title": "Codex",
224
- "resource.codex.description": "OpenAI Codex \u306E\u8A2D\u5B9A\u30EA\u30D5\u30A1\u30EC\u30F3\u30B9\u3002",
225
- "resource.resources": "\u30EA\u30BD\u30FC\u30B9",
194
+ "docSources.claudeCode.title": "Claude Code",
195
+ "docSources.claudeCode.description": "Claude Code \u306E\u8A2D\u5B9A\u30EA\u30D5\u30A1\u30EC\u30F3\u30B9\u3002",
196
+ "docSources.codex.title": "Codex",
197
+ "docSources.codex.description": "OpenAI Codex \u306E\u8A2D\u5B9A\u30EA\u30D5\u30A1\u30EC\u30F3\u30B9\u3002",
198
+ "docSources.section.instructions.label": "\u6307\u793A\u30D5\u30A1\u30A4\u30EB",
199
+ "docSources.section.instructions.description": "\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u306E\u6307\u793A\u30D5\u30A1\u30A4\u30EB",
200
+ "docSources.section.commands.label": "\u30B3\u30DE\u30F3\u30C9",
201
+ "docSources.section.commands.description": "\u30AB\u30B9\u30BF\u30E0\u30B9\u30E9\u30C3\u30B7\u30E5\u30B3\u30DE\u30F3\u30C9",
202
+ "docSources.section.skills.label": "\u30B9\u30AD\u30EB",
203
+ "docSources.section.skills.description": "\u30B9\u30AD\u30EB\u30D1\u30C3\u30B1\u30FC\u30B8",
204
+ "docSources.section.agents.label": "\u30A8\u30FC\u30B8\u30A7\u30F3\u30C8",
205
+ "docSources.section.agents.description": "\u30AB\u30B9\u30BF\u30E0\u30B5\u30D6\u30A8\u30FC\u30B8\u30A7\u30F3\u30C8",
206
+ "docSources.section.config.label": "\u8A2D\u5B9A",
207
+ "docSources.section.config.description": "config.toml \u3068\u30D7\u30ED\u30D5\u30A1\u30A4\u30EB",
208
+ "docSources.section.hooks.label": "\u30D5\u30C3\u30AF",
209
+ "docSources.section.hooks.description": "\u30E9\u30A4\u30D5\u30B5\u30A4\u30AF\u30EB\u30D5\u30C3\u30AF",
210
+ "docSources.section.rules.label": "\u30EB\u30FC\u30EB",
211
+ "docSources.section.rules.description": "\u30B3\u30DE\u30F3\u30C9\u627F\u8A8D\u30EB\u30FC\u30EB",
226
212
  "asset.badge": "\u30A2\u30BB\u30C3\u30C8",
227
213
  "asset.crumb": "\u30A2\u30BB\u30C3\u30C8",
228
214
  "asset.indexBadge": "\u30A4\u30F3\u30C7\u30C3\u30AF\u30B9",
@@ -1,4 +1,3 @@
1
1
  import type { ZfbPlugin } from "@takazudo/zfb/plugins";
2
- export { runCodexResourcesPreStep } from "./internal/codex-resources/index.js";
3
2
  declare const plugin: ZfbPlugin;
4
3
  export default plugin;
@@ -0,0 +1,40 @@
1
+ import os from "node:os";
2
+ import {
3
+ resolveRunOptions,
4
+ runDocSources,
5
+ summarize,
6
+ writeWatchState
7
+ } from "./internal/doc-sources/run.js";
8
+ const plugin = {
9
+ name: "@takazudo/zudo-doc-doc-sources",
10
+ async preBuild(ctx) {
11
+ const pluginOptions = ctx.options;
12
+ const environment = {
13
+ projectRoot: ctx.projectRoot,
14
+ publicDir: ctx.config.publicDir ?? "public",
15
+ outDir: ctx.outDir,
16
+ homeDir: () => os.homedir()
17
+ };
18
+ const options = resolveRunOptions(pluginOptions, environment);
19
+ const result = runDocSources(options);
20
+ writeWatchState(
21
+ {
22
+ plugin: pluginOptions,
23
+ projectRoot: options.projectRoot,
24
+ publicDir: options.publicDir,
25
+ outDir: ctx.outDir
26
+ },
27
+ options.sources.length > 0
28
+ );
29
+ for (const diagnostic of result.diagnostics) {
30
+ if (diagnostic.level === "warn") ctx.logger.warn(diagnostic.message);
31
+ }
32
+ if (result.sources > 0 || result.written.length > 0 || result.removed.length > 0) {
33
+ ctx.logger.info(summarize(result));
34
+ }
35
+ }
36
+ };
37
+ var doc_sources_default = plugin;
38
+ export {
39
+ doc_sources_default as default
40
+ };
@@ -0,0 +1,33 @@
1
+ import type { DocSourcesDiagnostic, NormalizedMapping, NormalizedSource } from "./model.js";
2
+ export interface DiscoveredFile {
3
+ mapping: NormalizedMapping;
4
+ /** POSIX path relative to the mapping root (logical, through symlinks). */
5
+ rel: string;
6
+ /** Logical absolute path. */
7
+ abs: string;
8
+ /** Real absolute path. */
9
+ real: string;
10
+ kind: "document" | "skill-page" | "asset";
11
+ /** For skill pages: the skill directory (relative to the mapping root). */
12
+ skillDir?: string;
13
+ }
14
+ export interface WatchTarget {
15
+ /** Absolute directory to watch (non-recursively). */
16
+ dir: string;
17
+ /** When set, only events for this direct child name matter. */
18
+ name?: string;
19
+ }
20
+ export interface DiscoveryResult {
21
+ files: DiscoveredFile[];
22
+ /** Every regular file seen below each skill directory, keyed by real skill dir. */
23
+ skillTrees: Map<string, string[]>;
24
+ watch: WatchTarget[];
25
+ diagnostics: DocSourcesDiagnostic[];
26
+ }
27
+ export declare class DocSourcesDiscoveryError extends Error {
28
+ constructor(message: string);
29
+ }
30
+ export declare function isInside(child: string, parent: string): boolean;
31
+ /** Parent-directory anchors that notice each mapping root appearing or disappearing. */
32
+ export declare function rootAnchors(sources: NormalizedSource[]): WatchTarget[];
33
+ export declare function discover(sources: NormalizedSource[], excludedRoots: string[]): DiscoveryResult;
@@ -0,0 +1,176 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { excludesDirectory, matchesAny } from "./glob.js";
4
+ class DocSourcesDiscoveryError extends Error {
5
+ constructor(message) {
6
+ super(`docSources: ${message}`);
7
+ this.name = "DocSourcesDiscoveryError";
8
+ }
9
+ }
10
+ function realOrNull(p) {
11
+ try {
12
+ return fs.realpathSync.native(p);
13
+ } catch {
14
+ return null;
15
+ }
16
+ }
17
+ function isInside(child, parent) {
18
+ const rel = path.relative(parent, child);
19
+ return rel === "" || !rel.startsWith("..") && !path.isAbsolute(rel);
20
+ }
21
+ function nearestExistingAncestor(p) {
22
+ let current = p;
23
+ for (; ; ) {
24
+ const parent = path.dirname(current);
25
+ if (parent === current) return null;
26
+ if (realOrNull(parent) !== null) return { dir: parent, name: path.basename(current) };
27
+ current = parent;
28
+ }
29
+ }
30
+ function rootAnchors(sources) {
31
+ const targets = [];
32
+ for (const source of sources) {
33
+ for (const root of [...source.requiredRoots, ...source.mappings.map((m) => m.root)]) {
34
+ const anchor = nearestExistingAncestor(root);
35
+ if (anchor !== null) targets.push(anchor);
36
+ }
37
+ }
38
+ return targets;
39
+ }
40
+ function discover(sources, excludedRoots) {
41
+ const files = [];
42
+ const skillTrees = /* @__PURE__ */ new Map();
43
+ const diagnostics = [];
44
+ const watchDirs = /* @__PURE__ */ new Map();
45
+ const addWatch = (target) => {
46
+ const key = `${target.dir}\0${target.name ?? ""}`;
47
+ if (!watchDirs.has(key)) watchDirs.set(key, target);
48
+ };
49
+ const excluded = /* @__PURE__ */ new Set();
50
+ for (const root of excludedRoots) {
51
+ excluded.add(path.resolve(root));
52
+ const real = realOrNull(root);
53
+ if (real !== null) excluded.add(real);
54
+ }
55
+ const isExcluded = (p) => [...excluded].some((root) => isInside(p, root));
56
+ const allowed = [];
57
+ for (const source of sources) {
58
+ for (const required of source.requiredRoots) {
59
+ const real = realOrNull(required);
60
+ if (real === null) {
61
+ throw new DocSourcesDiscoveryError(
62
+ `source "${source.id}" root "${required}" does not exist`
63
+ );
64
+ }
65
+ allowed.push(real);
66
+ }
67
+ for (const mapping of source.mappings) {
68
+ const real = realOrNull(mapping.root);
69
+ if (real !== null) allowed.push(real);
70
+ }
71
+ }
72
+ const isAllowed = (p) => allowed.some((root) => isInside(p, root));
73
+ for (const source of sources) {
74
+ for (const mapping of source.mappings) {
75
+ const label = `source "${source.id}" mapping "${mapping.id}"`;
76
+ const anchor = nearestExistingAncestor(mapping.root);
77
+ if (anchor !== null) addWatch(anchor);
78
+ const realRoot = realOrNull(mapping.root);
79
+ if (realRoot === null || !fs.statSync(realRoot).isDirectory()) {
80
+ if (mapping.missing === "error") {
81
+ throw new DocSourcesDiscoveryError(
82
+ `${label} root "${mapping.root}" does not exist (set missing: "skip" for an optional source)`
83
+ );
84
+ }
85
+ diagnostics.push({ level: "info", message: `${label}: root is missing, skipped` });
86
+ continue;
87
+ }
88
+ if (isExcluded(realRoot)) {
89
+ throw new DocSourcesDiscoveryError(
90
+ `${label} root "${mapping.root}" lies inside a documentation output directory`
91
+ );
92
+ }
93
+ const seenFiles = [];
94
+ const walk = (dirAbs, dirReal, rel, ancestors) => {
95
+ addWatch({ dir: dirReal });
96
+ let entries;
97
+ try {
98
+ entries = fs.readdirSync(dirAbs, { withFileTypes: true });
99
+ } catch (error) {
100
+ diagnostics.push({ level: "warn", message: `${label}: cannot read "${rel || "."}": ${String(error)}` });
101
+ return;
102
+ }
103
+ entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
104
+ for (const entry of entries) {
105
+ const childRel = rel === "" ? entry.name : `${rel}/${entry.name}`;
106
+ const childAbs = path.join(dirAbs, entry.name);
107
+ let childReal = path.join(dirReal, entry.name);
108
+ let isDir = entry.isDirectory();
109
+ let isFile = entry.isFile();
110
+ if (entry.isSymbolicLink()) {
111
+ const target = realOrNull(childAbs);
112
+ if (target === null) {
113
+ diagnostics.push({ level: "warn", message: `${label}: broken symlink "${childRel}" skipped` });
114
+ continue;
115
+ }
116
+ if (!isAllowed(target)) {
117
+ diagnostics.push({
118
+ level: "warn",
119
+ message: `${label}: symlink "${childRel}" points outside the configured roots and was skipped; configure its target as a mapping root to publish it`
120
+ });
121
+ continue;
122
+ }
123
+ childReal = target;
124
+ const stat = fs.statSync(target);
125
+ isDir = stat.isDirectory();
126
+ isFile = stat.isFile();
127
+ }
128
+ if (isExcluded(childReal)) continue;
129
+ if (isDir) {
130
+ if (excludesDirectory(childRel, mapping.exclude)) continue;
131
+ if (ancestors.has(childReal)) {
132
+ diagnostics.push({ level: "warn", message: `${label}: symlink cycle at "${childRel}" skipped` });
133
+ continue;
134
+ }
135
+ const next = new Set(ancestors);
136
+ next.add(childReal);
137
+ walk(childAbs, childReal, childRel, next);
138
+ } else if (isFile) {
139
+ if (matchesAny(childRel, mapping.exclude)) continue;
140
+ if (matchesAny(childRel, mapping.include)) {
141
+ files.push({ mapping, rel: childRel, abs: childAbs, real: childReal, kind: "document" });
142
+ } else if (mapping.assets !== void 0 && matchesAny(childRel, mapping.assets.include) && !matchesAny(childRel, mapping.assets.exclude)) {
143
+ files.push({ mapping, rel: childRel, abs: childAbs, real: childReal, kind: "asset" });
144
+ } else if (mapping.renderer === "skill") {
145
+ seenFiles.push({ rel: childRel, abs: childAbs, real: childReal });
146
+ }
147
+ }
148
+ }
149
+ };
150
+ walk(mapping.root, realRoot, "", /* @__PURE__ */ new Set([realRoot]));
151
+ if (mapping.renderer === "skill") {
152
+ const skillDirs = files.filter((f) => f.mapping === mapping && f.kind === "document" && path.posix.basename(f.rel).toLowerCase() === "skill.md").map((f) => path.posix.dirname(f.rel));
153
+ for (const skillDir of skillDirs) {
154
+ const prefix = skillDir === "." ? "" : `${skillDir}/`;
155
+ const tree = [];
156
+ for (const seen of seenFiles) {
157
+ if (prefix !== "" && !seen.rel.startsWith(prefix)) continue;
158
+ const inner = seen.rel.slice(prefix.length);
159
+ tree.push(inner);
160
+ if (/\.mdx?$/i.test(inner)) {
161
+ files.push({ mapping, ...seen, kind: "skill-page", skillDir });
162
+ }
163
+ }
164
+ skillTrees.set(`${mapping.sourceId}\0${mapping.id}\0${skillDir}`, tree.sort());
165
+ }
166
+ }
167
+ }
168
+ }
169
+ return { files, skillTrees, watch: [...watchDirs.values()], diagnostics };
170
+ }
171
+ export {
172
+ DocSourcesDiscoveryError,
173
+ discover,
174
+ isInside,
175
+ rootAnchors
176
+ };