@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.
- package/CHANGELOG.md +21 -0
- package/bin/zudo-doc.mjs +32 -0
- package/dist/config.d.ts +10 -27
- package/dist/doc-content-header/index.js +1 -1
- package/dist/doc-page-renderer/index.js +3 -1
- package/dist/doc-sources/types.d.ts +65 -0
- package/dist/doc-sources/types.js +0 -0
- package/dist/docs-schema/index.d.ts +3 -0
- package/dist/docs-schema/index.js +4 -0
- package/dist/frontmatter-preview-defaults/index.js +3 -0
- package/dist/i18n-defaults/index.js +36 -50
- package/dist/plugins/{codex-resources.d.ts → doc-sources.d.ts} +0 -1
- package/dist/plugins/doc-sources.js +40 -0
- package/dist/plugins/internal/doc-sources/discover.d.ts +33 -0
- package/dist/plugins/internal/doc-sources/discover.js +176 -0
- package/dist/plugins/internal/doc-sources/glob.d.ts +8 -0
- package/dist/plugins/internal/doc-sources/glob.js +80 -0
- package/dist/plugins/internal/doc-sources/labels.d.ts +8 -0
- package/dist/plugins/internal/doc-sources/labels.js +7 -0
- package/dist/plugins/internal/doc-sources/locale-routes.d.ts +6 -0
- package/dist/plugins/internal/doc-sources/locale-routes.js +8 -0
- package/dist/plugins/internal/doc-sources/model.d.ts +64 -0
- package/dist/plugins/internal/doc-sources/model.js +0 -0
- package/dist/plugins/internal/doc-sources/normalize.d.ts +20 -0
- package/dist/plugins/internal/doc-sources/normalize.js +192 -0
- package/dist/plugins/internal/doc-sources/plan.d.ts +28 -0
- package/dist/plugins/internal/doc-sources/plan.js +350 -0
- package/dist/plugins/internal/doc-sources/presets.d.ts +12 -0
- package/dist/plugins/internal/doc-sources/presets.js +182 -0
- package/dist/plugins/internal/doc-sources/reconcile.d.ts +20 -0
- package/dist/plugins/internal/doc-sources/reconcile.js +182 -0
- package/dist/plugins/internal/doc-sources/render/codex-agent.d.ts +2 -0
- package/dist/plugins/internal/doc-sources/render/codex-agent.js +45 -0
- package/dist/plugins/internal/doc-sources/render/codex-config.d.ts +2 -0
- package/dist/plugins/internal/doc-sources/render/codex-config.js +45 -0
- package/dist/plugins/internal/doc-sources/render/codex-hooks.d.ts +2 -0
- package/dist/plugins/internal/doc-sources/render/codex-hooks.js +66 -0
- package/dist/plugins/internal/doc-sources/render/codex-rules.d.ts +2 -0
- package/dist/plugins/internal/{codex-resources/rules.js → doc-sources/render/codex-rules.js} +16 -89
- package/dist/plugins/internal/{resource-docs-shared → doc-sources/render}/escape-for-mdx.js +1 -1
- package/dist/plugins/internal/doc-sources/render/frontmatter.d.ts +9 -0
- package/dist/plugins/internal/doc-sources/render/frontmatter.js +38 -0
- package/dist/plugins/internal/doc-sources/render/links.d.ts +25 -0
- package/dist/plugins/internal/doc-sources/render/links.js +109 -0
- package/dist/plugins/internal/{resource-docs-shared → doc-sources/render}/markdown-structure.d.ts +4 -0
- package/dist/plugins/internal/{resource-docs-shared → doc-sources/render}/markdown-structure.js +37 -1
- package/dist/plugins/internal/doc-sources/render/skill.d.ts +10 -0
- package/dist/plugins/internal/doc-sources/render/skill.js +97 -0
- package/dist/plugins/internal/doc-sources/render/types.d.ts +7 -0
- package/dist/plugins/internal/doc-sources/render/types.js +6 -0
- package/dist/plugins/internal/doc-sources/run.d.ts +53 -0
- package/dist/plugins/internal/doc-sources/run.js +110 -0
- package/dist/plugins/internal/doc-sources/watch.d.ts +33 -0
- package/dist/plugins/internal/doc-sources/watch.js +187 -0
- package/dist/plugins/routes.js +1 -1
- package/dist/preset.d.ts +3 -19
- package/dist/preset.js +23 -30
- package/dist/route-context-payload/index.js +4 -1
- package/dist/settings-defaults.js +1 -2
- package/dist/settings.d.ts +4 -10
- package/package.json +15 -19
- package/dist/plugins/claude-resources.d.ts +0 -4
- package/dist/plugins/claude-resources.js +0 -45
- package/dist/plugins/codex-resources.js +0 -45
- package/dist/plugins/internal/claude-resources/generate.d.ts +0 -31
- package/dist/plugins/internal/claude-resources/generate.js +0 -375
- package/dist/plugins/internal/claude-resources/index.d.ts +0 -54
- package/dist/plugins/internal/claude-resources/index.js +0 -33
- package/dist/plugins/internal/codex-resources/agents-md.d.ts +0 -6
- package/dist/plugins/internal/codex-resources/agents-md.js +0 -83
- package/dist/plugins/internal/codex-resources/agents.d.ts +0 -7
- package/dist/plugins/internal/codex-resources/agents.js +0 -117
- package/dist/plugins/internal/codex-resources/config.d.ts +0 -6
- package/dist/plugins/internal/codex-resources/config.js +0 -124
- package/dist/plugins/internal/codex-resources/generate.d.ts +0 -29
- package/dist/plugins/internal/codex-resources/generate.js +0 -46
- package/dist/plugins/internal/codex-resources/hooks.d.ts +0 -6
- package/dist/plugins/internal/codex-resources/hooks.js +0 -187
- package/dist/plugins/internal/codex-resources/index.d.ts +0 -33
- package/dist/plugins/internal/codex-resources/index.js +0 -33
- package/dist/plugins/internal/codex-resources/overview.d.ts +0 -10
- package/dist/plugins/internal/codex-resources/overview.js +0 -163
- package/dist/plugins/internal/codex-resources/rules.d.ts +0 -6
- package/dist/plugins/internal/codex-resources/skills.d.ts +0 -2
- package/dist/plugins/internal/codex-resources/skills.js +0 -97
- package/dist/plugins/internal/codex-resources/utils.d.ts +0 -14
- package/dist/plugins/internal/codex-resources/utils.js +0 -80
- package/dist/plugins/internal/resource-docs-shared/fs.d.ts +0 -36
- package/dist/plugins/internal/resource-docs-shared/fs.js +0 -101
- package/dist/plugins/internal/resource-docs-shared/index.d.ts +0 -9
- package/dist/plugins/internal/resource-docs-shared/index.js +0 -69
- package/dist/plugins/internal/resource-docs-shared/labels.d.ts +0 -24
- package/dist/plugins/internal/resource-docs-shared/labels.js +0 -14
- package/dist/plugins/internal/resource-docs-shared/links.d.ts +0 -27
- package/dist/plugins/internal/resource-docs-shared/links.js +0 -62
- package/dist/plugins/internal/resource-docs-shared/locale-routes.d.ts +0 -16
- package/dist/plugins/internal/resource-docs-shared/locale-routes.js +0 -14
- package/dist/plugins/internal/resource-docs-shared/mdx.d.ts +0 -28
- package/dist/plugins/internal/resource-docs-shared/mdx.js +0 -64
- package/dist/plugins/internal/resource-docs-shared/skills.d.ts +0 -37
- package/dist/plugins/internal/resource-docs-shared/skills.js +0 -340
- package/dist/plugins/internal/resource-docs-shared/walk.d.ts +0 -20
- package/dist/plugins/internal/resource-docs-shared/walk.js +0 -41
- /package/dist/plugins/internal/{resource-docs-shared → doc-sources/render}/escape-for-mdx.d.ts +0 -0
package/dist/plugins/internal/{resource-docs-shared → doc-sources/render}/markdown-structure.js
RENAMED
|
@@ -16,7 +16,43 @@ function escapeMarkdownTableCell(value) {
|
|
|
16
16
|
const needsPadding = /^[` ]|[` ]$/.test(content);
|
|
17
17
|
return needsPadding ? `${delimiter} ${content} ${delimiter}` : `${delimiter}${content}${delimiter}`;
|
|
18
18
|
}
|
|
19
|
+
function renderTableRow(values) {
|
|
20
|
+
return `| ${values.map(escapeMarkdownTableCell).join(" | ")} |`;
|
|
21
|
+
}
|
|
22
|
+
function languageForFilename(filename) {
|
|
23
|
+
const lower = filename.toLowerCase();
|
|
24
|
+
const ext = lower.slice(lower.lastIndexOf(".") + 1);
|
|
25
|
+
switch (ext) {
|
|
26
|
+
case "sh":
|
|
27
|
+
case "bash":
|
|
28
|
+
case "zsh":
|
|
29
|
+
return "bash";
|
|
30
|
+
case "py":
|
|
31
|
+
return "python";
|
|
32
|
+
case "js":
|
|
33
|
+
case "mjs":
|
|
34
|
+
case "cjs":
|
|
35
|
+
return "javascript";
|
|
36
|
+
case "ts":
|
|
37
|
+
case "mts":
|
|
38
|
+
case "cts":
|
|
39
|
+
return "typescript";
|
|
40
|
+
case "json":
|
|
41
|
+
return "json";
|
|
42
|
+
case "toml":
|
|
43
|
+
return "toml";
|
|
44
|
+
case "yaml":
|
|
45
|
+
case "yml":
|
|
46
|
+
return "yaml";
|
|
47
|
+
case "rules":
|
|
48
|
+
return "python";
|
|
49
|
+
default:
|
|
50
|
+
return "";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
19
53
|
export {
|
|
20
54
|
escapeMarkdownTableCell,
|
|
21
|
-
|
|
55
|
+
languageForFilename,
|
|
56
|
+
renderCodeFence,
|
|
57
|
+
renderTableRow
|
|
22
58
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Warn } from "./types.js";
|
|
2
|
+
/** Render a list of POSIX paths as a box-drawing file tree. */
|
|
3
|
+
export declare function renderFileTree(rootName: string, paths: string[]): string;
|
|
4
|
+
/** Render optional `agents/openai.yaml` interface metadata of a skill. */
|
|
5
|
+
export declare function renderSkillInterfaceMetadata(yaml: string, skillName: string, warn: Warn): string;
|
|
6
|
+
/**
|
|
7
|
+
* The "File Structure" section of a skill landing page. Markdown files get
|
|
8
|
+
* source-relative links; the shared link pass resolves them to routes.
|
|
9
|
+
*/
|
|
10
|
+
export declare function renderSkillFileStructure(skillDirName: string, tree: string[]): string;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { matter } from "../../../../frontmatter/index.js";
|
|
2
|
+
import { escapeForMdx } from "./escape-for-mdx.js";
|
|
3
|
+
import { isRecord } from "./types.js";
|
|
4
|
+
function renderFileTree(rootName, paths) {
|
|
5
|
+
const root = { name: rootName, children: /* @__PURE__ */ new Map(), isDir: true };
|
|
6
|
+
for (const p of paths) {
|
|
7
|
+
let node = root;
|
|
8
|
+
const segments = p.split("/");
|
|
9
|
+
segments.forEach((segment, index) => {
|
|
10
|
+
let child = node.children.get(segment);
|
|
11
|
+
if (child === void 0) {
|
|
12
|
+
child = { name: segment, children: /* @__PURE__ */ new Map(), isDir: index < segments.length - 1 };
|
|
13
|
+
node.children.set(segment, child);
|
|
14
|
+
}
|
|
15
|
+
node = child;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
const lines = [`${rootName}/`];
|
|
19
|
+
const visit = (node, indent) => {
|
|
20
|
+
const children = [...node.children.values()].sort((a, b) => {
|
|
21
|
+
if (a.name === "SKILL.md") return -1;
|
|
22
|
+
if (b.name === "SKILL.md") return 1;
|
|
23
|
+
if (a.isDir !== b.isDir) return a.isDir ? 1 : -1;
|
|
24
|
+
return a.name.localeCompare(b.name);
|
|
25
|
+
});
|
|
26
|
+
children.forEach((child, index) => {
|
|
27
|
+
const last = index === children.length - 1;
|
|
28
|
+
lines.push(`${indent}${last ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 "}${child.name}${child.isDir ? "/" : ""}`);
|
|
29
|
+
if (child.isDir) visit(child, `${indent}${last ? " " : "\u2502 "}`);
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
visit(root, "");
|
|
33
|
+
return lines.join("\n");
|
|
34
|
+
}
|
|
35
|
+
function optionalMetadataString(record, field, warn) {
|
|
36
|
+
const value = record[field];
|
|
37
|
+
if (value === void 0) return void 0;
|
|
38
|
+
if (typeof value === "string") return value;
|
|
39
|
+
warn(`agents/openai.yaml: ${field} must be a string; omitting it`);
|
|
40
|
+
return void 0;
|
|
41
|
+
}
|
|
42
|
+
function renderSkillInterfaceMetadata(yaml, skillName, warn) {
|
|
43
|
+
let data;
|
|
44
|
+
try {
|
|
45
|
+
data = matter(`---
|
|
46
|
+
${yaml}
|
|
47
|
+
---
|
|
48
|
+
`).data;
|
|
49
|
+
} catch (error) {
|
|
50
|
+
warn(`agents/openai.yaml: unable to parse YAML, omitting metadata: ${String(error)}`);
|
|
51
|
+
return "";
|
|
52
|
+
}
|
|
53
|
+
if (!isRecord(data)) {
|
|
54
|
+
warn("agents/openai.yaml: YAML root must be an object; omitting metadata");
|
|
55
|
+
return "";
|
|
56
|
+
}
|
|
57
|
+
const interfaceData = isRecord(data.interface) ? data.interface : void 0;
|
|
58
|
+
if (data.interface !== void 0 && interfaceData === void 0) {
|
|
59
|
+
warn("agents/openai.yaml: interface must be an object; omitting interface metadata");
|
|
60
|
+
}
|
|
61
|
+
const policy = isRecord(data.policy) ? data.policy : void 0;
|
|
62
|
+
if (data.policy !== void 0 && policy === void 0) {
|
|
63
|
+
warn("agents/openai.yaml: policy must be an object; omitting policy metadata");
|
|
64
|
+
}
|
|
65
|
+
const displayName = interfaceData ? optionalMetadataString(interfaceData, "display_name", warn) : void 0;
|
|
66
|
+
const shortDescription = interfaceData ? optionalMetadataString(interfaceData, "short_description", warn) : void 0;
|
|
67
|
+
let explicitOnly = false;
|
|
68
|
+
if (policy?.allow_implicit_invocation !== void 0) {
|
|
69
|
+
if (typeof policy.allow_implicit_invocation === "boolean") {
|
|
70
|
+
explicitOnly = policy.allow_implicit_invocation === false;
|
|
71
|
+
} else {
|
|
72
|
+
warn("agents/openai.yaml: policy.allow_implicit_invocation must be a boolean; omitting invocation metadata");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return [
|
|
76
|
+
displayName ? `**Display name:** ${escapeForMdx(displayName)}` : "",
|
|
77
|
+
shortDescription ? `**Short description:** ${escapeForMdx(shortDescription)}` : "",
|
|
78
|
+
explicitOnly ? `**Invocation:** explicit only (\`$${skillName}\`)` : ""
|
|
79
|
+
].filter(Boolean).join("\n");
|
|
80
|
+
}
|
|
81
|
+
function renderSkillFileStructure(skillDirName, tree) {
|
|
82
|
+
if (tree.length === 0) return "";
|
|
83
|
+
const block = `\`\`\`
|
|
84
|
+
${renderFileTree(skillDirName, ["SKILL.md", ...tree])}
|
|
85
|
+
\`\`\``;
|
|
86
|
+
const links = tree.filter((p) => /\.mdx?$/i.test(p)).map((p) => `- [${p}](${p.split("/").map(encodeURIComponent).join("/")})`);
|
|
87
|
+
return `## File Structure
|
|
88
|
+
|
|
89
|
+
${block}${links.length > 0 ? `
|
|
90
|
+
|
|
91
|
+
${links.join("\n")}` : ""}`;
|
|
92
|
+
}
|
|
93
|
+
export {
|
|
94
|
+
renderFileTree,
|
|
95
|
+
renderSkillFileStructure,
|
|
96
|
+
renderSkillInterfaceMetadata
|
|
97
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type WatchTarget } from "./discover.js";
|
|
2
|
+
import type { DocSourcesDiagnostic, DocSourcesRunOptions } from "./model.js";
|
|
3
|
+
/** Plugin options produced by `zudoDocPreset()`: data only, no absolute paths required. */
|
|
4
|
+
export interface DocSourcesPluginOptions {
|
|
5
|
+
sources?: unknown;
|
|
6
|
+
docsDir?: string;
|
|
7
|
+
locales?: Record<string, {
|
|
8
|
+
dir: string;
|
|
9
|
+
}>;
|
|
10
|
+
defaultLocale?: string;
|
|
11
|
+
defaultLocaleOnlyPrefixes?: string[];
|
|
12
|
+
translations?: Record<string, Record<string, string>>;
|
|
13
|
+
/** Snapshot content directories (versions); excluded from every scan. */
|
|
14
|
+
excludeDirs?: string[];
|
|
15
|
+
}
|
|
16
|
+
export interface DocSourcesEnvironment {
|
|
17
|
+
projectRoot: string;
|
|
18
|
+
/** Absolute or project-relative public directory. Defaults to `public`. */
|
|
19
|
+
publicDir?: string;
|
|
20
|
+
/** Absolute or project-relative build output directory. */
|
|
21
|
+
outDir?: string;
|
|
22
|
+
/** Injected home-directory resolver for `~/` paths. */
|
|
23
|
+
homeDir: () => string;
|
|
24
|
+
}
|
|
25
|
+
export declare const STATE_DIR: string;
|
|
26
|
+
export declare const WATCH_STATE_FILE = "watch-state.json";
|
|
27
|
+
export declare function resolveRunOptions(plugin: DocSourcesPluginOptions, env: DocSourcesEnvironment): DocSourcesRunOptions;
|
|
28
|
+
export interface DocSourcesRunResult {
|
|
29
|
+
sources: number;
|
|
30
|
+
documents: number;
|
|
31
|
+
assets: number;
|
|
32
|
+
indexes: number;
|
|
33
|
+
written: string[];
|
|
34
|
+
removed: string[];
|
|
35
|
+
diagnostics: DocSourcesDiagnostic[];
|
|
36
|
+
/** Directories the development watcher should observe. */
|
|
37
|
+
watch: WatchTarget[];
|
|
38
|
+
}
|
|
39
|
+
export declare function runDocSources(options: DocSourcesRunOptions): DocSourcesRunResult;
|
|
40
|
+
/** Build-local state the watcher reads: the same plugin options and environment. */
|
|
41
|
+
export interface WatchState {
|
|
42
|
+
plugin: DocSourcesPluginOptions;
|
|
43
|
+
projectRoot: string;
|
|
44
|
+
publicDir: string;
|
|
45
|
+
outDir: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Record the resolved inputs for `zudo-doc sources watch`. An empty
|
|
49
|
+
* configuration removes the state so the watcher stays idle.
|
|
50
|
+
*/
|
|
51
|
+
export declare function writeWatchState(state: WatchState, hasSources: boolean): void;
|
|
52
|
+
export declare function readWatchState(projectRoot: string): WatchState | null;
|
|
53
|
+
export declare function summarize(result: DocSourcesRunResult): string;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { discover } from "./discover.js";
|
|
4
|
+
import { normalizeDocSources } from "./normalize.js";
|
|
5
|
+
import { ASSET_DIR, buildPlan } from "./plan.js";
|
|
6
|
+
import { reconcile } from "./reconcile.js";
|
|
7
|
+
const STATE_DIR = path.join(".zfb", "doc-sources");
|
|
8
|
+
const WATCH_STATE_FILE = "watch-state.json";
|
|
9
|
+
function abs(projectRoot, p) {
|
|
10
|
+
return path.isAbsolute(p) ? path.normalize(p) : path.resolve(projectRoot, p);
|
|
11
|
+
}
|
|
12
|
+
function resolveRunOptions(plugin, env) {
|
|
13
|
+
const projectRoot = path.resolve(env.projectRoot);
|
|
14
|
+
const docsDir = abs(projectRoot, plugin.docsDir ?? "src/content/docs");
|
|
15
|
+
const locales = {};
|
|
16
|
+
for (const [locale, config] of Object.entries(plugin.locales ?? {})) {
|
|
17
|
+
if (config === null || typeof config !== "object" || typeof config.dir !== "string") {
|
|
18
|
+
throw new TypeError(`docSources: locale "${locale}" must configure { dir: string }`);
|
|
19
|
+
}
|
|
20
|
+
locales[locale] = abs(projectRoot, config.dir);
|
|
21
|
+
}
|
|
22
|
+
const publicDir = abs(projectRoot, env.publicDir ?? "public");
|
|
23
|
+
const stateDir = path.join(projectRoot, STATE_DIR);
|
|
24
|
+
return {
|
|
25
|
+
projectRoot,
|
|
26
|
+
sources: normalizeDocSources(plugin.sources, { projectRoot, homeDir: env.homeDir }),
|
|
27
|
+
docsDir,
|
|
28
|
+
locales,
|
|
29
|
+
defaultLocale: plugin.defaultLocale ?? "en",
|
|
30
|
+
defaultLocaleOnlyPrefixes: plugin.defaultLocaleOnlyPrefixes ?? [],
|
|
31
|
+
translations: plugin.translations ?? {},
|
|
32
|
+
publicDir,
|
|
33
|
+
excludedRoots: [
|
|
34
|
+
docsDir,
|
|
35
|
+
...Object.values(locales),
|
|
36
|
+
...(plugin.excludeDirs ?? []).map((dir) => abs(projectRoot, dir)),
|
|
37
|
+
path.join(publicDir, ASSET_DIR),
|
|
38
|
+
abs(projectRoot, env.outDir ?? "dist"),
|
|
39
|
+
path.join(projectRoot, ".zfb"),
|
|
40
|
+
path.join(projectRoot, ".zfb-build")
|
|
41
|
+
],
|
|
42
|
+
stateDir
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function runDocSources(options) {
|
|
46
|
+
const discovery = options.sources.length === 0 ? { files: [], skillTrees: /* @__PURE__ */ new Map(), watch: [], diagnostics: [] } : discover(options.sources, options.excludedRoots);
|
|
47
|
+
const plan = buildPlan(options, discovery);
|
|
48
|
+
const result = reconcile({
|
|
49
|
+
projectRoot: options.projectRoot,
|
|
50
|
+
stateDir: options.stateDir,
|
|
51
|
+
outputs: plan.outputs,
|
|
52
|
+
outputRoots: plan.outputRoots
|
|
53
|
+
});
|
|
54
|
+
try {
|
|
55
|
+
fs.rmdirSync(path.join(options.publicDir, ASSET_DIR));
|
|
56
|
+
} catch {
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
sources: options.sources.length,
|
|
60
|
+
...plan.counts,
|
|
61
|
+
written: result.written,
|
|
62
|
+
removed: result.removed,
|
|
63
|
+
diagnostics: [...plan.diagnostics, ...result.diagnostics],
|
|
64
|
+
watch: discovery.watch
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function writeWatchState(state, hasSources) {
|
|
68
|
+
const file = path.join(state.projectRoot, STATE_DIR, WATCH_STATE_FILE);
|
|
69
|
+
if (!hasSources) {
|
|
70
|
+
fs.rmSync(file, { force: true });
|
|
71
|
+
try {
|
|
72
|
+
fs.rmdirSync(path.dirname(file));
|
|
73
|
+
} catch {
|
|
74
|
+
}
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const serialized = `${JSON.stringify(state, null, 2)}
|
|
78
|
+
`;
|
|
79
|
+
let previous = "";
|
|
80
|
+
try {
|
|
81
|
+
previous = fs.readFileSync(file, "utf8");
|
|
82
|
+
} catch {
|
|
83
|
+
previous = "";
|
|
84
|
+
}
|
|
85
|
+
if (previous === serialized) return;
|
|
86
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
87
|
+
fs.writeFileSync(`${file}.tmp`, serialized);
|
|
88
|
+
fs.renameSync(`${file}.tmp`, file);
|
|
89
|
+
}
|
|
90
|
+
function readWatchState(projectRoot) {
|
|
91
|
+
try {
|
|
92
|
+
return JSON.parse(
|
|
93
|
+
fs.readFileSync(path.join(projectRoot, STATE_DIR, WATCH_STATE_FILE), "utf8")
|
|
94
|
+
);
|
|
95
|
+
} catch {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function summarize(result) {
|
|
100
|
+
return `doc-sources: ${result.sources} source(s), ${result.documents} document(s), ${result.assets} asset(s), ${result.indexes} index page(s); ${result.written.length} written, ${result.removed.length} removed`;
|
|
101
|
+
}
|
|
102
|
+
export {
|
|
103
|
+
STATE_DIR,
|
|
104
|
+
WATCH_STATE_FILE,
|
|
105
|
+
readWatchState,
|
|
106
|
+
resolveRunOptions,
|
|
107
|
+
runDocSources,
|
|
108
|
+
summarize,
|
|
109
|
+
writeWatchState
|
|
110
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface WatchLogger {
|
|
2
|
+
info(message: string): void;
|
|
3
|
+
warn(message: string): void;
|
|
4
|
+
error(message: string): void;
|
|
5
|
+
}
|
|
6
|
+
/** Debounced, serialized task runner with a single queued follow-up. */
|
|
7
|
+
export declare function createSerialScheduler(task: () => Promise<void> | void, debounceMs: number): {
|
|
8
|
+
trigger(): void;
|
|
9
|
+
close(): Promise<void>;
|
|
10
|
+
idle(): Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
export interface DocSourcesWatcherOptions {
|
|
13
|
+
projectRoot: string;
|
|
14
|
+
homeDir: () => string;
|
|
15
|
+
logger: WatchLogger;
|
|
16
|
+
debounceMs?: number;
|
|
17
|
+
/** Poll interval for the recorded state file (config changes restart `zfb dev`). */
|
|
18
|
+
statePollMs?: number;
|
|
19
|
+
/** Injected for tests. */
|
|
20
|
+
watchDir?: (dir: string, listener: (filename: string | null) => void) => {
|
|
21
|
+
close(): void;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export interface DocSourcesWatcher {
|
|
25
|
+
/** Directories currently watched. */
|
|
26
|
+
watchedDirs(): string[];
|
|
27
|
+
/** Resolves when no run is pending. */
|
|
28
|
+
idle(): Promise<void>;
|
|
29
|
+
/** Completed regeneration runs. */
|
|
30
|
+
runs(): number;
|
|
31
|
+
close(): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
export declare function startDocSourcesWatcher(options: DocSourcesWatcherOptions): DocSourcesWatcher;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { discover, isInside, rootAnchors } from "./discover.js";
|
|
4
|
+
import {
|
|
5
|
+
readWatchState,
|
|
6
|
+
resolveRunOptions,
|
|
7
|
+
runDocSources,
|
|
8
|
+
STATE_DIR,
|
|
9
|
+
summarize,
|
|
10
|
+
WATCH_STATE_FILE
|
|
11
|
+
} from "./run.js";
|
|
12
|
+
function createSerialScheduler(task, debounceMs) {
|
|
13
|
+
let timer;
|
|
14
|
+
let running;
|
|
15
|
+
let queued = false;
|
|
16
|
+
let closed = false;
|
|
17
|
+
const start = () => {
|
|
18
|
+
timer = void 0;
|
|
19
|
+
if (closed) return;
|
|
20
|
+
if (running !== void 0) {
|
|
21
|
+
queued = true;
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
running = (async () => {
|
|
25
|
+
try {
|
|
26
|
+
await task();
|
|
27
|
+
} finally {
|
|
28
|
+
running = void 0;
|
|
29
|
+
if (queued && !closed) {
|
|
30
|
+
queued = false;
|
|
31
|
+
trigger();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
})();
|
|
35
|
+
};
|
|
36
|
+
const trigger = () => {
|
|
37
|
+
if (closed) return;
|
|
38
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
39
|
+
timer = setTimeout(start, debounceMs);
|
|
40
|
+
};
|
|
41
|
+
const idle = async () => {
|
|
42
|
+
while (timer !== void 0 || running !== void 0) {
|
|
43
|
+
if (running !== void 0) await running;
|
|
44
|
+
else await new Promise((resolve) => setTimeout(resolve, debounceMs));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
trigger,
|
|
49
|
+
idle,
|
|
50
|
+
async close() {
|
|
51
|
+
closed = true;
|
|
52
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
53
|
+
timer = void 0;
|
|
54
|
+
if (running !== void 0) await running;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function defaultWatchDir(dir, listener) {
|
|
59
|
+
const watcher = fs.watch(dir, { persistent: true }, (_event, filename) => {
|
|
60
|
+
listener(filename === null ? null : String(filename));
|
|
61
|
+
});
|
|
62
|
+
watcher.on("error", () => listener(null));
|
|
63
|
+
return watcher;
|
|
64
|
+
}
|
|
65
|
+
function startDocSourcesWatcher(options) {
|
|
66
|
+
const { projectRoot, logger } = options;
|
|
67
|
+
const debounceMs = options.debounceMs ?? 150;
|
|
68
|
+
const watchDir = options.watchDir ?? defaultWatchDir;
|
|
69
|
+
const stateFile = path.join(projectRoot, STATE_DIR, WATCH_STATE_FILE);
|
|
70
|
+
const active = /* @__PURE__ */ new Map();
|
|
71
|
+
let runOptions = null;
|
|
72
|
+
let runCount = 0;
|
|
73
|
+
let closed = false;
|
|
74
|
+
const relevant = (dir, filename, names) => {
|
|
75
|
+
if (runOptions === null) return false;
|
|
76
|
+
if (filename !== null) {
|
|
77
|
+
if (!names.has(void 0) && !names.has(filename)) return false;
|
|
78
|
+
const full = path.join(dir, filename);
|
|
79
|
+
if (runOptions.excludedRoots.some((root) => isInside(full, root))) return false;
|
|
80
|
+
}
|
|
81
|
+
return true;
|
|
82
|
+
};
|
|
83
|
+
const syncWatchers = (targets) => {
|
|
84
|
+
const wanted = /* @__PURE__ */ new Map();
|
|
85
|
+
for (const target of targets) {
|
|
86
|
+
const names = wanted.get(target.dir) ?? /* @__PURE__ */ new Set();
|
|
87
|
+
names.add(target.name);
|
|
88
|
+
wanted.set(target.dir, names);
|
|
89
|
+
}
|
|
90
|
+
for (const [dir, entry] of active) {
|
|
91
|
+
if (!wanted.has(dir)) {
|
|
92
|
+
entry.close();
|
|
93
|
+
active.delete(dir);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
for (const [dir, names] of wanted) {
|
|
97
|
+
const existing = active.get(dir);
|
|
98
|
+
if (existing !== void 0) {
|
|
99
|
+
existing.names = names;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
const entry = { names, close: () => {
|
|
104
|
+
} };
|
|
105
|
+
const handle = watchDir(dir, (filename) => {
|
|
106
|
+
if (relevant(dir, filename, entry.names)) scheduler.trigger();
|
|
107
|
+
});
|
|
108
|
+
entry.close = () => handle.close();
|
|
109
|
+
active.set(dir, entry);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
logger.warn(`doc-sources watch: cannot watch "${dir}": ${String(error)}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const loadOptions = () => {
|
|
116
|
+
const state = readWatchState(projectRoot);
|
|
117
|
+
if (state === null) {
|
|
118
|
+
runOptions = null;
|
|
119
|
+
syncWatchers([]);
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
runOptions = resolveRunOptions(state.plugin, {
|
|
123
|
+
projectRoot: state.projectRoot,
|
|
124
|
+
publicDir: state.publicDir,
|
|
125
|
+
outDir: state.outDir,
|
|
126
|
+
homeDir: options.homeDir
|
|
127
|
+
});
|
|
128
|
+
if (runOptions.sources.length === 0) {
|
|
129
|
+
syncWatchers([]);
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
return true;
|
|
133
|
+
};
|
|
134
|
+
const prime = () => {
|
|
135
|
+
try {
|
|
136
|
+
if (!loadOptions() || runOptions === null) {
|
|
137
|
+
logger.info("doc-sources watch: no document sources configured; idle");
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const discovery = discover(runOptions.sources, runOptions.excludedRoots);
|
|
141
|
+
syncWatchers([...discovery.watch, ...rootAnchors(runOptions.sources)]);
|
|
142
|
+
logger.info(`doc-sources watch: watching ${active.size} director${active.size === 1 ? "y" : "ies"}`);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
logger.error(`doc-sources watch: ${error instanceof Error ? error.message : String(error)}`);
|
|
145
|
+
if (runOptions !== null) syncWatchers(rootAnchors(runOptions.sources));
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
const scheduler = createSerialScheduler(() => {
|
|
149
|
+
if (closed || runOptions === null) return;
|
|
150
|
+
let result;
|
|
151
|
+
try {
|
|
152
|
+
result = runDocSources(runOptions);
|
|
153
|
+
} catch (error) {
|
|
154
|
+
logger.error(`doc-sources watch: ${error instanceof Error ? error.message : String(error)}`);
|
|
155
|
+
syncWatchers(rootAnchors(runOptions.sources).concat([...active.keys()].map((dir) => ({ dir }))));
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
runCount++;
|
|
159
|
+
syncWatchers([...result.watch, ...rootAnchors(runOptions.sources)]);
|
|
160
|
+
for (const diagnostic of result.diagnostics) {
|
|
161
|
+
if (diagnostic.level === "warn") logger.warn(diagnostic.message);
|
|
162
|
+
}
|
|
163
|
+
if (result.written.length > 0 || result.removed.length > 0) logger.info(summarize(result));
|
|
164
|
+
}, debounceMs);
|
|
165
|
+
const onStateChange = () => {
|
|
166
|
+
if (closed) return;
|
|
167
|
+
prime();
|
|
168
|
+
};
|
|
169
|
+
fs.watchFile(stateFile, { interval: options.statePollMs ?? 1e3, persistent: true }, onStateChange);
|
|
170
|
+
prime();
|
|
171
|
+
return {
|
|
172
|
+
watchedDirs: () => [...active.keys()].sort(),
|
|
173
|
+
idle: () => scheduler.idle(),
|
|
174
|
+
runs: () => runCount,
|
|
175
|
+
async close() {
|
|
176
|
+
closed = true;
|
|
177
|
+
fs.unwatchFile(stateFile, onStateChange);
|
|
178
|
+
await scheduler.close();
|
|
179
|
+
for (const entry of active.values()) entry.close();
|
|
180
|
+
active.clear();
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
export {
|
|
185
|
+
createSerialScheduler,
|
|
186
|
+
startDocSourcesWatcher
|
|
187
|
+
};
|
package/dist/plugins/routes.js
CHANGED
|
@@ -186,7 +186,7 @@ const plugin = definePlugin({
|
|
|
186
186
|
name: "@takazudo/zudo-doc/plugins/routes",
|
|
187
187
|
async setup(ctx) {
|
|
188
188
|
const options = ctx.options;
|
|
189
|
-
const settings = options.settings ?? {};
|
|
189
|
+
const { docSources: _privateDocSources, ...settings } = options.settings ?? {};
|
|
190
190
|
const translations = options.translations ?? {};
|
|
191
191
|
const tagVocabulary = options.tagVocabulary ?? [];
|
|
192
192
|
const colorSchemes = options.colorSchemes ?? null;
|
package/dist/preset.d.ts
CHANGED
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
*/
|
|
36
36
|
import { z } from "zod";
|
|
37
37
|
import type { DirectiveSpec, ZfbConfig } from "@takazudo/zfb/config";
|
|
38
|
+
import type { DocSourceEntry } from "./doc-sources/types.js";
|
|
38
39
|
import type { ColorScheme } from "./color-scheme-utils.js";
|
|
39
40
|
import type { ContentSignalsConfig, AssetViewerIndexingConfig, TagVocabularyEntry, FaviconConfig, HeaderBrandConfig, HomeConfig } from "./settings.js";
|
|
40
41
|
/** A single locale's content directory (`settings.locales[code]`). */
|
|
@@ -50,23 +51,6 @@ export interface PresetVersionConfig {
|
|
|
50
51
|
dir: string;
|
|
51
52
|
}>;
|
|
52
53
|
}
|
|
53
|
-
/** The `settings.claudeResources` block (or `false` when disabled). */
|
|
54
|
-
export interface PresetClaudeResourcesConfig {
|
|
55
|
-
claudeDir: string;
|
|
56
|
-
projectRoot?: string;
|
|
57
|
-
/**
|
|
58
|
-
* Root for `CLAUDE.md` discovery; defaults to `projectRoot`. Decouples
|
|
59
|
-
* repo-wide scanning from the output base for subdirectory doc sites (#2558).
|
|
60
|
-
*/
|
|
61
|
-
scanRoot?: string;
|
|
62
|
-
}
|
|
63
|
-
/** The `settings.codexResources` block (or `false` when disabled). */
|
|
64
|
-
export interface PresetCodexResourcesConfig {
|
|
65
|
-
codexDir: string;
|
|
66
|
-
projectRoot?: string;
|
|
67
|
-
/** Root for `AGENTS.md` / `AGENTS.override.md` and `.agents/skills/` discovery; defaults to `projectRoot`. */
|
|
68
|
-
scanRoot?: string;
|
|
69
|
-
}
|
|
70
54
|
export interface PresetChangelogConfig {
|
|
71
55
|
sourceDir: string;
|
|
72
56
|
outputFile: string;
|
|
@@ -163,8 +147,8 @@ export interface PresetSettings {
|
|
|
163
147
|
assetViewerExclude?: string[];
|
|
164
148
|
/** Per-output opt-in controls for indexing generated asset-viewer pages. */
|
|
165
149
|
assetViewerIndexing?: AssetViewerIndexingConfig | false;
|
|
166
|
-
|
|
167
|
-
|
|
150
|
+
/** External document sources baked into nested routes (default `[]`). */
|
|
151
|
+
docSources?: DocSourceEntry[];
|
|
168
152
|
/** Route prefixes served only from the unprefixed default locale. */
|
|
169
153
|
defaultLocaleOnlyPrefixes?: string[];
|
|
170
154
|
/**
|
package/dist/preset.js
CHANGED
|
@@ -150,6 +150,10 @@ function buildMarkdownFeatures(settings, directiveVocabulary) {
|
|
|
150
150
|
headingIds: { strategy: "hierarchical" }
|
|
151
151
|
};
|
|
152
152
|
}
|
|
153
|
+
function publicRouteSettings(settings) {
|
|
154
|
+
const { docSources: _private, ...rest } = settings;
|
|
155
|
+
return rest;
|
|
156
|
+
}
|
|
153
157
|
function buildPlugins(settings, routeContext) {
|
|
154
158
|
const localeArray = Object.entries(settings.locales).map(([code, locale]) => ({
|
|
155
159
|
code,
|
|
@@ -215,7 +219,7 @@ function buildPlugins(settings, routeContext) {
|
|
|
215
219
|
// Serializable project settings — JSON.stringify-d verbatim into
|
|
216
220
|
// the virtual module. No function-valued fields (verified in
|
|
217
221
|
// src/config/settings.ts), so it round-trips losslessly.
|
|
218
|
-
settings,
|
|
222
|
+
settings: publicRouteSettings(settings),
|
|
219
223
|
translations: routeContext.translations ?? {},
|
|
220
224
|
tagVocabulary: routeContext.tagVocabulary ?? [],
|
|
221
225
|
colorSchemes: routeContext.colorSchemes ?? null,
|
|
@@ -234,36 +238,25 @@ function buildPlugins(settings, routeContext) {
|
|
|
234
238
|
}
|
|
235
239
|
}
|
|
236
240
|
] : [],
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
name: "@takazudo/zudo-doc/plugins/codex-resources",
|
|
255
|
-
options: {
|
|
256
|
-
codexDir: settings.codexResources.codexDir,
|
|
257
|
-
projectRoot: settings.codexResources.projectRoot,
|
|
258
|
-
scanRoot: settings.codexResources.scanRoot,
|
|
259
|
-
docsDir: settings.docsDir,
|
|
260
|
-
locales: localeRecord,
|
|
261
|
-
defaultLocale: settings.defaultLocale,
|
|
262
|
-
translations: routeContext.translations,
|
|
263
|
-
defaultLocaleOnlyPrefixes: settings.defaultLocaleOnlyPrefixes ?? []
|
|
264
|
-
}
|
|
241
|
+
// Always registered: reconciliation must also run with `docSources`
|
|
242
|
+
// empty so removed or disabled sources leave no stale generated output.
|
|
243
|
+
// The options carry configuration data only; the plugin resolves paths
|
|
244
|
+
// and touches the filesystem inside Node build execution.
|
|
245
|
+
{
|
|
246
|
+
name: "@takazudo/zudo-doc/plugins/doc-sources",
|
|
247
|
+
options: {
|
|
248
|
+
sources: settings.docSources ?? [],
|
|
249
|
+
docsDir: settings.docsDir,
|
|
250
|
+
locales: localeRecord,
|
|
251
|
+
defaultLocale: settings.defaultLocale,
|
|
252
|
+
defaultLocaleOnlyPrefixes: settings.defaultLocaleOnlyPrefixes ?? [],
|
|
253
|
+
translations: routeContext.translations ?? {},
|
|
254
|
+
excludeDirs: settings.versions ? settings.versions.flatMap((version) => [
|
|
255
|
+
version.docsDir,
|
|
256
|
+
...Object.values(version.locales ?? {}).map((locale) => locale.dir)
|
|
257
|
+
]) : []
|
|
265
258
|
}
|
|
266
|
-
|
|
259
|
+
},
|
|
267
260
|
...settings.docHistory ? [
|
|
268
261
|
{
|
|
269
262
|
name: "@takazudo/zudo-doc/plugins/doc-history",
|