@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.
- package/CHANGELOG.md +28 -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
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { isInside } from "./discover.js";
|
|
5
|
+
const MANIFEST_FILE = "manifest.json";
|
|
6
|
+
const MANIFEST_VERSION = 1;
|
|
7
|
+
class DocSourcesReconcileError extends Error {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(`docSources: ${message}`);
|
|
10
|
+
this.name = "DocSourcesReconcileError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function hash(content) {
|
|
14
|
+
return createHash("sha256").update(content).digest("hex");
|
|
15
|
+
}
|
|
16
|
+
function toKey(projectRoot, abs) {
|
|
17
|
+
return path.relative(projectRoot, abs).split(path.sep).join("/");
|
|
18
|
+
}
|
|
19
|
+
function readManifest(manifestPath) {
|
|
20
|
+
let raw;
|
|
21
|
+
try {
|
|
22
|
+
raw = fs.readFileSync(manifestPath, "utf8");
|
|
23
|
+
} catch {
|
|
24
|
+
return { version: MANIFEST_VERSION, roots: [], files: {} };
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const parsed = JSON.parse(raw);
|
|
28
|
+
if (parsed.version === MANIFEST_VERSION && Array.isArray(parsed.roots) && parsed.files && typeof parsed.files === "object") {
|
|
29
|
+
return parsed;
|
|
30
|
+
}
|
|
31
|
+
} catch {
|
|
32
|
+
}
|
|
33
|
+
throw new DocSourcesReconcileError(
|
|
34
|
+
`the ownership manifest "${manifestPath}" is unreadable. Remove it together with the generated document-source sections, then rebuild.`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
function fileHash(abs) {
|
|
38
|
+
try {
|
|
39
|
+
const stat = fs.lstatSync(abs);
|
|
40
|
+
if (!stat.isFile()) return "not-a-file";
|
|
41
|
+
return hash(fs.readFileSync(abs));
|
|
42
|
+
} catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function assertContained(abs, roots, projectRoot) {
|
|
47
|
+
const lexicalRoot = roots.find((root) => isInside(abs, root) && abs !== root);
|
|
48
|
+
if (lexicalRoot === void 0) {
|
|
49
|
+
throw new DocSourcesReconcileError(`refusing to write "${toKey(projectRoot, abs)}": outside the document-source output roots`);
|
|
50
|
+
}
|
|
51
|
+
let probe = path.dirname(abs);
|
|
52
|
+
while (!fs.existsSync(probe) && probe !== path.dirname(probe)) probe = path.dirname(probe);
|
|
53
|
+
const realProbe = fs.realpathSync.native(probe);
|
|
54
|
+
const realRoots = roots.map((root) => {
|
|
55
|
+
let r = path.dirname(root);
|
|
56
|
+
while (!fs.existsSync(r) && r !== path.dirname(r)) r = path.dirname(r);
|
|
57
|
+
const real = fs.realpathSync.native(r);
|
|
58
|
+
return path.join(real, path.relative(r, root));
|
|
59
|
+
});
|
|
60
|
+
const inside = realRoots.some((root) => isInside(realProbe, root) || isInside(root, realProbe));
|
|
61
|
+
if (!inside) {
|
|
62
|
+
throw new DocSourcesReconcileError(
|
|
63
|
+
`refusing to write "${toKey(projectRoot, abs)}": its directory resolves outside the output roots through a symlink`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function removeEmptyDirs(start, roots) {
|
|
68
|
+
let dir = start;
|
|
69
|
+
while (roots.some((root) => isInside(dir, root))) {
|
|
70
|
+
try {
|
|
71
|
+
if (fs.readdirSync(dir).length > 0) return;
|
|
72
|
+
fs.rmdirSync(dir);
|
|
73
|
+
} catch {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
dir = path.dirname(dir);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function reconcile(options) {
|
|
80
|
+
const { projectRoot, stateDir, outputs, outputRoots } = options;
|
|
81
|
+
const manifestPath = path.join(stateDir, MANIFEST_FILE);
|
|
82
|
+
const manifest = readManifest(manifestPath);
|
|
83
|
+
const diagnostics = [];
|
|
84
|
+
const planned = /* @__PURE__ */ new Map();
|
|
85
|
+
for (const output of outputs) {
|
|
86
|
+
const key = toKey(projectRoot, output.abs);
|
|
87
|
+
if (key.startsWith("..") || path.isAbsolute(key)) {
|
|
88
|
+
throw new DocSourcesReconcileError(`output "${output.abs}" lies outside the project root`);
|
|
89
|
+
}
|
|
90
|
+
assertContained(output.abs, outputRoots, projectRoot);
|
|
91
|
+
planned.set(key, { abs: output.abs, content: output.content, digest: hash(output.content) });
|
|
92
|
+
}
|
|
93
|
+
const toWrite = [];
|
|
94
|
+
let unchanged = 0;
|
|
95
|
+
for (const [key, entry] of planned) {
|
|
96
|
+
const current = fileHash(entry.abs);
|
|
97
|
+
const owned = manifest.files[key];
|
|
98
|
+
if (current === entry.digest) {
|
|
99
|
+
unchanged++;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (current !== null) {
|
|
103
|
+
if (owned === void 0) {
|
|
104
|
+
throw new DocSourcesReconcileError(
|
|
105
|
+
`"${key}" already exists and was not generated by docSources. Move or remove that file, or choose another mount or "to" path.`
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
if (owned !== current) {
|
|
109
|
+
throw new DocSourcesReconcileError(
|
|
110
|
+
`generated file "${key}" was modified after generation. Edit the source file instead, then remove "${key}" so it can be regenerated.`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
toWrite.push({ key, ...entry });
|
|
115
|
+
}
|
|
116
|
+
const toRemove = [];
|
|
117
|
+
for (const [key, digest] of Object.entries(manifest.files)) {
|
|
118
|
+
if (planned.has(key)) continue;
|
|
119
|
+
const abs = path.resolve(projectRoot, ...key.split("/"));
|
|
120
|
+
if (!isInside(abs, projectRoot)) continue;
|
|
121
|
+
const current = fileHash(abs);
|
|
122
|
+
if (current === null) continue;
|
|
123
|
+
if (current !== digest) {
|
|
124
|
+
diagnostics.push({
|
|
125
|
+
level: "warn",
|
|
126
|
+
message: `stale generated file "${key}" was modified after generation; kept and no longer managed`
|
|
127
|
+
});
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
toRemove.push({ key, abs });
|
|
131
|
+
}
|
|
132
|
+
const nextFiles = {};
|
|
133
|
+
for (const [key, entry] of planned) nextFiles[key] = entry.digest;
|
|
134
|
+
for (const item of toWrite) {
|
|
135
|
+
fs.mkdirSync(path.dirname(item.abs), { recursive: true });
|
|
136
|
+
fs.writeFileSync(item.abs, item.content);
|
|
137
|
+
}
|
|
138
|
+
const ownedRoots = [
|
|
139
|
+
...outputRoots,
|
|
140
|
+
...manifest.roots.map((root) => path.resolve(projectRoot, ...root.split("/")))
|
|
141
|
+
];
|
|
142
|
+
for (const item of toRemove) {
|
|
143
|
+
fs.unlinkSync(item.abs);
|
|
144
|
+
removeEmptyDirs(path.dirname(item.abs), ownedRoots);
|
|
145
|
+
}
|
|
146
|
+
for (const root of ownedRoots) removeEmptyDirs(root, [root]);
|
|
147
|
+
if (Object.keys(nextFiles).length === 0) {
|
|
148
|
+
fs.rmSync(manifestPath, { force: true });
|
|
149
|
+
try {
|
|
150
|
+
fs.rmdirSync(stateDir);
|
|
151
|
+
} catch {
|
|
152
|
+
}
|
|
153
|
+
} else {
|
|
154
|
+
const sorted = Object.fromEntries(Object.entries(nextFiles).sort(([a], [b]) => a.localeCompare(b)));
|
|
155
|
+
const roots = [...new Set(outputRoots.map((root) => toKey(projectRoot, root)))].sort();
|
|
156
|
+
const serialized = `${JSON.stringify({ version: MANIFEST_VERSION, roots, files: sorted }, null, 2)}
|
|
157
|
+
`;
|
|
158
|
+
let previous = "";
|
|
159
|
+
try {
|
|
160
|
+
previous = fs.readFileSync(manifestPath, "utf8");
|
|
161
|
+
} catch {
|
|
162
|
+
previous = "";
|
|
163
|
+
}
|
|
164
|
+
if (previous !== serialized) {
|
|
165
|
+
fs.mkdirSync(stateDir, { recursive: true });
|
|
166
|
+
const tmp = `${manifestPath}.tmp`;
|
|
167
|
+
fs.writeFileSync(tmp, serialized);
|
|
168
|
+
fs.renameSync(tmp, manifestPath);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
written: toWrite.map((item) => item.key),
|
|
173
|
+
removed: toRemove.map((item) => item.key),
|
|
174
|
+
unchanged,
|
|
175
|
+
diagnostics
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
export {
|
|
179
|
+
DocSourcesReconcileError,
|
|
180
|
+
MANIFEST_FILE,
|
|
181
|
+
reconcile
|
|
182
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { parse } from "smol-toml";
|
|
2
|
+
import { escapeForMdx } from "./escape-for-mdx.js";
|
|
3
|
+
import { escapeMarkdownTableCell, renderCodeFence } from "./markdown-structure.js";
|
|
4
|
+
import { isRecord } from "./types.js";
|
|
5
|
+
function optionalString(record, field, warn) {
|
|
6
|
+
const value = record[field];
|
|
7
|
+
if (value === void 0) return void 0;
|
|
8
|
+
if (typeof value === "string") return value;
|
|
9
|
+
warn(`${field} must be a string; omitting it`);
|
|
10
|
+
return void 0;
|
|
11
|
+
}
|
|
12
|
+
function renderCodexAgent(source, fallbackName, warn) {
|
|
13
|
+
let parsed;
|
|
14
|
+
try {
|
|
15
|
+
parsed = parse(source);
|
|
16
|
+
} catch (error) {
|
|
17
|
+
warn(`unable to parse TOML; rendering the source only: ${String(error)}`);
|
|
18
|
+
parsed = {};
|
|
19
|
+
}
|
|
20
|
+
const record = isRecord(parsed) ? parsed : {};
|
|
21
|
+
const name = optionalString(record, "name", warn) ?? fallbackName;
|
|
22
|
+
const description = optionalString(record, "description", warn) ?? "";
|
|
23
|
+
const model = optionalString(record, "model", warn);
|
|
24
|
+
const reasoning = optionalString(record, "model_reasoning_effort", warn);
|
|
25
|
+
const sandbox = optionalString(record, "sandbox_mode", warn);
|
|
26
|
+
const instructions = optionalString(record, "developer_instructions", warn);
|
|
27
|
+
const badges = [
|
|
28
|
+
model ? `**Model:** ${escapeMarkdownTableCell(model)}` : "",
|
|
29
|
+
reasoning ? `**Reasoning effort:** ${escapeMarkdownTableCell(reasoning)}` : "",
|
|
30
|
+
sandbox ? `**Sandbox:** ${escapeMarkdownTableCell(sandbox)}` : ""
|
|
31
|
+
].filter(Boolean);
|
|
32
|
+
const sections = [badges.join("\n")];
|
|
33
|
+
if (instructions !== void 0) {
|
|
34
|
+
sections.push(`## Developer instructions
|
|
35
|
+
|
|
36
|
+
${escapeForMdx(instructions.trim())}`);
|
|
37
|
+
}
|
|
38
|
+
sections.push(`## Source
|
|
39
|
+
|
|
40
|
+
${renderCodeFence(source, "toml")}`);
|
|
41
|
+
return { title: name, description, body: sections.filter(Boolean).join("\n\n") };
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
renderCodexAgent
|
|
45
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { parse, TomlDate } from "smol-toml";
|
|
2
|
+
import {
|
|
3
|
+
escapeMarkdownTableCell,
|
|
4
|
+
renderCodeFence,
|
|
5
|
+
renderTableRow
|
|
6
|
+
} from "./markdown-structure.js";
|
|
7
|
+
import { isRecord } from "./types.js";
|
|
8
|
+
function renderValue(value) {
|
|
9
|
+
if (typeof value === "string") return value;
|
|
10
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
11
|
+
if (Array.isArray(value)) return JSON.stringify(value);
|
|
12
|
+
if (value instanceof TomlDate) return value.toISOString();
|
|
13
|
+
return String(value);
|
|
14
|
+
}
|
|
15
|
+
function renderCodexConfig(source, filename, warn) {
|
|
16
|
+
let parsed = {};
|
|
17
|
+
try {
|
|
18
|
+
parsed = parse(source);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
warn(`unable to parse TOML; rendering the source only: ${String(error)}`);
|
|
21
|
+
}
|
|
22
|
+
const record = isRecord(parsed) ? parsed : {};
|
|
23
|
+
const settings = Object.entries(record).filter(([, value]) => !isRecord(value) || value instanceof TomlDate).map(([key, value]) => renderTableRow([key, renderValue(value)]));
|
|
24
|
+
const sections = source.match(/^\s*\[\[?[^\]]+\]\]?/gm) ?? [];
|
|
25
|
+
const sectionList = sections.length === 0 ? "\u2014" : sections.map((section) => `- ${escapeMarkdownTableCell(section.trim())}`).join("\n");
|
|
26
|
+
const body = [
|
|
27
|
+
"## Settings",
|
|
28
|
+
"",
|
|
29
|
+
"| Key | Value |",
|
|
30
|
+
"| --- | --- |",
|
|
31
|
+
...settings.length > 0 ? settings : [renderTableRow([void 0, void 0])],
|
|
32
|
+
"",
|
|
33
|
+
"## Sections",
|
|
34
|
+
"",
|
|
35
|
+
sectionList,
|
|
36
|
+
"",
|
|
37
|
+
"## Source",
|
|
38
|
+
"",
|
|
39
|
+
renderCodeFence(source, "toml")
|
|
40
|
+
].join("\n");
|
|
41
|
+
return { title: filename, description: `Codex configuration from ${filename}`, body };
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
renderCodexConfig
|
|
45
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { renderCodeFence, renderTableRow } from "./markdown-structure.js";
|
|
2
|
+
import { isRecord } from "./types.js";
|
|
3
|
+
function readHookRows(source, warn) {
|
|
4
|
+
let parsed;
|
|
5
|
+
try {
|
|
6
|
+
parsed = JSON.parse(source);
|
|
7
|
+
} catch (error) {
|
|
8
|
+
warn(`unable to parse JSON, rendering the source only: ${String(error)}`);
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
if (!isRecord(parsed) || !isRecord(parsed.hooks)) {
|
|
12
|
+
warn("hooks.hooks must be a non-null object; rendering the source only");
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const rows = [];
|
|
16
|
+
for (const [event, groups] of Object.entries(parsed.hooks)) {
|
|
17
|
+
if (!Array.isArray(groups)) {
|
|
18
|
+
warn(`hooks.${event} must be an array; skipping event`);
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
for (const [groupIndex, group] of groups.entries()) {
|
|
22
|
+
if (!isRecord(group) || !Array.isArray(group.hooks)) {
|
|
23
|
+
warn(
|
|
24
|
+
`hooks.${event}[${groupIndex}].hooks must be an array; skipping group`
|
|
25
|
+
);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
for (const [handlerIndex, handler] of group.hooks.entries()) {
|
|
29
|
+
if (!isRecord(handler) || typeof handler.command !== "string") {
|
|
30
|
+
warn(
|
|
31
|
+
`hooks.${event}[${groupIndex}].hooks[${handlerIndex}] must be an object with a string command; skipping row`
|
|
32
|
+
);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
rows.push({
|
|
36
|
+
event,
|
|
37
|
+
matcher: group.matcher,
|
|
38
|
+
type: handler.type,
|
|
39
|
+
command: handler.command,
|
|
40
|
+
timeout: handler.timeout,
|
|
41
|
+
async: handler.async
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return rows;
|
|
47
|
+
}
|
|
48
|
+
function renderCodexHooks(source, filename, warn) {
|
|
49
|
+
const rows = readHookRows(source, warn) ?? [];
|
|
50
|
+
const tableRows = rows.map(
|
|
51
|
+
(row) => renderTableRow([row.event, row.matcher, row.type, row.command, row.timeout, row.async])
|
|
52
|
+
);
|
|
53
|
+
const body = [
|
|
54
|
+
"| Event | Matcher | Type | Command | Timeout | Async |",
|
|
55
|
+
"| --- | --- | --- | --- | --- | --- |",
|
|
56
|
+
...tableRows.length > 0 ? tableRows : [renderTableRow(Array.from({ length: 6 }))],
|
|
57
|
+
"",
|
|
58
|
+
"## Source",
|
|
59
|
+
"",
|
|
60
|
+
renderCodeFence(source, "json")
|
|
61
|
+
].join("\n");
|
|
62
|
+
return { title: filename, description: "Codex lifecycle hook configuration", body };
|
|
63
|
+
}
|
|
64
|
+
export {
|
|
65
|
+
renderCodexHooks
|
|
66
|
+
};
|
package/dist/plugins/internal/{codex-resources/rules.js → doc-sources/render/codex-rules.js}
RENAMED
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import {
|
|
4
|
-
formatFrontmatterString,
|
|
5
|
-
cleanDir,
|
|
6
|
-
ensureDir,
|
|
7
|
-
renderCodeFence,
|
|
8
|
-
resolveResourceLabel,
|
|
9
|
-
writeCategoryIndex
|
|
10
|
-
} from "../resource-docs-shared/index.js";
|
|
11
|
-
import {
|
|
12
|
-
assertUniqueSlug,
|
|
13
|
-
renderTableRow,
|
|
14
|
-
warn,
|
|
15
|
-
writeGeneratedPage
|
|
16
|
-
} from "./utils.js";
|
|
1
|
+
import { renderCodeFence, renderTableRow } from "./markdown-structure.js";
|
|
17
2
|
function freshState() {
|
|
18
3
|
return { quote: null, triple: false, escaped: false, comment: false };
|
|
19
4
|
}
|
|
@@ -190,79 +175,21 @@ function parseRule(body) {
|
|
|
190
175
|
justification: args.has("justification") ? parseStringLiteral(args.get("justification") ?? "") : void 0
|
|
191
176
|
};
|
|
192
177
|
}
|
|
193
|
-
function
|
|
194
|
-
const
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const items = [];
|
|
208
|
-
const emitted = /* @__PURE__ */ new Map();
|
|
209
|
-
for (const filename of files) {
|
|
210
|
-
const filePath = path.join(rulesDir, filename);
|
|
211
|
-
const slug = filename.replace(/\.rules$/, "");
|
|
212
|
-
assertUniqueSlug("rule", slug, filePath, emitted);
|
|
213
|
-
let source;
|
|
214
|
-
try {
|
|
215
|
-
source = fs.readFileSync(filePath, "utf8");
|
|
216
|
-
} catch (error) {
|
|
217
|
-
warn(filePath, `unable to read rules file, skipping it: ${String(error)}`);
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
const rows = findPrefixRuleBodies(source).map(parseRule);
|
|
221
|
-
const body = [
|
|
222
|
-
"## Rules",
|
|
223
|
-
"",
|
|
224
|
-
"| Pattern | Decision | Justification |",
|
|
225
|
-
"| --- | --- | --- |",
|
|
226
|
-
...rows.length > 0 ? rows.map(
|
|
227
|
-
(row) => renderTableRow([row.pattern, row.decision, row.justification])
|
|
228
|
-
) : [renderTableRow(Array.from({ length: 3 }))],
|
|
229
|
-
"",
|
|
230
|
-
"## Source",
|
|
231
|
-
"",
|
|
232
|
-
renderCodeFence(source, "python")
|
|
233
|
-
].join("\n");
|
|
234
|
-
writeGeneratedPage({
|
|
235
|
-
outputPath: path.join(outputDir, `${slug}.mdx`),
|
|
236
|
-
title: filename,
|
|
237
|
-
description: `Command approval rules from ${filename}`,
|
|
238
|
-
sidebarLabel: filename,
|
|
239
|
-
body
|
|
240
|
-
});
|
|
241
|
-
items.push({ filename, slug });
|
|
242
|
-
}
|
|
243
|
-
if (items.length > 0) {
|
|
244
|
-
writeCategoryIndex(
|
|
245
|
-
outputDir,
|
|
246
|
-
resolveResourceLabel({
|
|
247
|
-
translations: config.translations,
|
|
248
|
-
locale: config.defaultLocale ?? "en",
|
|
249
|
-
defaultLocale: config.defaultLocale,
|
|
250
|
-
key: "resource.codexRules.label",
|
|
251
|
-
fallbackLiteral: "Rules"
|
|
252
|
-
}),
|
|
253
|
-
909,
|
|
254
|
-
resolveResourceLabel({
|
|
255
|
-
translations: config.translations,
|
|
256
|
-
locale: config.defaultLocale ?? "en",
|
|
257
|
-
defaultLocale: config.defaultLocale,
|
|
258
|
-
key: "resource.codexRules.description",
|
|
259
|
-
fallbackLiteral: "Command approval rules"
|
|
260
|
-
}),
|
|
261
|
-
formatFrontmatterString
|
|
262
|
-
);
|
|
263
|
-
}
|
|
264
|
-
return items;
|
|
178
|
+
function renderCodexRules(source, filename) {
|
|
179
|
+
const rows = findPrefixRuleBodies(source).map(parseRule);
|
|
180
|
+
const body = [
|
|
181
|
+
"## Rules",
|
|
182
|
+
"",
|
|
183
|
+
"| Pattern | Decision | Justification |",
|
|
184
|
+
"| --- | --- | --- |",
|
|
185
|
+
...rows.length > 0 ? rows.map((row) => renderTableRow([row.pattern, row.decision, row.justification])) : [renderTableRow(Array.from({ length: 3 }))],
|
|
186
|
+
"",
|
|
187
|
+
"## Source",
|
|
188
|
+
"",
|
|
189
|
+
renderCodeFence(source, "python")
|
|
190
|
+
].join("\n");
|
|
191
|
+
return { title: filename, description: `Command approval rules from ${filename}`, body };
|
|
265
192
|
}
|
|
266
193
|
export {
|
|
267
|
-
|
|
194
|
+
renderCodexRules
|
|
268
195
|
};
|
|
@@ -75,7 +75,7 @@ const htmlTags = /* @__PURE__ */ new Set([
|
|
|
75
75
|
function escapeForMdx(content) {
|
|
76
76
|
const codeBlocks = [];
|
|
77
77
|
const placeholder = "\0CODEBLOCK_";
|
|
78
|
-
const codeBlockRegex = /(`{3,})[^\n]*\n[\s\S]*?\1/g;
|
|
78
|
+
const codeBlockRegex = /(`{3,}|~{3,})[^\n]*\n[\s\S]*?\1/g;
|
|
79
79
|
const withPlaceholders = content.replace(codeBlockRegex, (match) => {
|
|
80
80
|
const idx = codeBlocks.length;
|
|
81
81
|
codeBlocks.push(match);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function parseFrontmatter(content: string): import("../../../../frontmatter/index.js").ParsedFrontmatter | null;
|
|
2
|
+
/**
|
|
3
|
+
* Render a string as a YAML scalar in mdx-formatter's canonical form, so a
|
|
4
|
+
* formatter pass over generated output never rewrites it.
|
|
5
|
+
*/
|
|
6
|
+
export declare function formatFrontmatterString(value: string): string;
|
|
7
|
+
export type FrontmatterValue = string | number | boolean | undefined;
|
|
8
|
+
/** Render an ordered frontmatter block, omitting undefined values. */
|
|
9
|
+
export declare function renderFrontmatter(fields: Array<[string, FrontmatterValue]>): string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { matter } from "../../../../frontmatter/index.js";
|
|
2
|
+
function parseFrontmatter(content) {
|
|
3
|
+
try {
|
|
4
|
+
return matter(content);
|
|
5
|
+
} catch {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function formatFrontmatterString(value) {
|
|
10
|
+
const formatterRequiresQuotes = /["']/.test(value) || /^[?:-]/.test(value) || /^(?:yes|no|on|off)$/iu.test(value) || /^\+?(?:nan|inf(?:inity)?)$/iu.test(value);
|
|
11
|
+
if (!/[\r\n]/.test(value)) {
|
|
12
|
+
try {
|
|
13
|
+
const parsed = matter(`---
|
|
14
|
+
value: ${value}
|
|
15
|
+
---
|
|
16
|
+
`).data.value;
|
|
17
|
+
if (parsed === value && !formatterRequiresQuotes) return value;
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return JSON.stringify(value);
|
|
22
|
+
}
|
|
23
|
+
function renderFrontmatter(fields) {
|
|
24
|
+
const lines = ["---"];
|
|
25
|
+
for (const [key, value] of fields) {
|
|
26
|
+
if (value === void 0) continue;
|
|
27
|
+
lines.push(
|
|
28
|
+
`${key}: ${typeof value === "string" ? formatFrontmatterString(value) : String(value)}`
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
lines.push("---");
|
|
32
|
+
return lines.join("\n");
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
formatFrontmatterString,
|
|
36
|
+
parseFrontmatter,
|
|
37
|
+
renderFrontmatter
|
|
38
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type LinkResolution = {
|
|
2
|
+
kind: "keep";
|
|
3
|
+
} | {
|
|
4
|
+
kind: "rewrite";
|
|
5
|
+
url: string;
|
|
6
|
+
} | {
|
|
7
|
+
kind: "unmapped";
|
|
8
|
+
};
|
|
9
|
+
export type LinkResolver = (url: string) => LinkResolution;
|
|
10
|
+
/** Whether a destination refers to a sibling file rather than a site URL. */
|
|
11
|
+
export declare function isRelativeReference(url: string): boolean;
|
|
12
|
+
/** Readable stand-in for a reference that is not published. */
|
|
13
|
+
export declare function readableReference(text: string, url: string): string;
|
|
14
|
+
export interface RewriteResult {
|
|
15
|
+
content: string;
|
|
16
|
+
unmapped: string[];
|
|
17
|
+
}
|
|
18
|
+
export declare function rewriteLinks(content: string, resolve: LinkResolver): RewriteResult;
|
|
19
|
+
/** Split a destination into its path, query and fragment parts. */
|
|
20
|
+
export declare function splitDestination(url: string): {
|
|
21
|
+
pathPart: string;
|
|
22
|
+
query: string;
|
|
23
|
+
fragment: string;
|
|
24
|
+
};
|
|
25
|
+
export declare function safeDecode(value: string): string;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
function isRelativeReference(url) {
|
|
2
|
+
const trimmed = url.trim();
|
|
3
|
+
if (trimmed === "") return false;
|
|
4
|
+
if (trimmed.startsWith("#")) return false;
|
|
5
|
+
if (trimmed.startsWith("/")) return false;
|
|
6
|
+
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(trimmed)) return false;
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
const PLACEHOLDER = "\0DSCODE_";
|
|
10
|
+
function protectCode(content) {
|
|
11
|
+
const saved = [];
|
|
12
|
+
const keep = (match) => {
|
|
13
|
+
saved.push(match);
|
|
14
|
+
return `${PLACEHOLDER}${saved.length - 1}\0`;
|
|
15
|
+
};
|
|
16
|
+
let text = content.replace(/^( {0,3})(`{3,}|~{3,})[^\n]*\n[\s\S]*?(?:\n {0,3}\2[`~]*[ \t]*(?=\n|(?![\s\S]))|(?![\s\S]))/gm, keep);
|
|
17
|
+
text = text.replace(/(`+)(?!`)([\s\S]*?[^`])\1(?!`)/g, keep);
|
|
18
|
+
return {
|
|
19
|
+
text,
|
|
20
|
+
restore: (s) => s.replace(new RegExp(`${PLACEHOLDER}(\\d+)\0`, "g"), (_, i) => saved[Number(i)] ?? "")
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function codeSpan(value) {
|
|
24
|
+
const longest = (value.match(/`+/g) ?? []).reduce((max, run) => Math.max(max, run.length), 0);
|
|
25
|
+
const fence = "`".repeat(longest + 1);
|
|
26
|
+
return /^`|`$/.test(value) ? `${fence} ${value} ${fence}` : `${fence}${value}${fence}`;
|
|
27
|
+
}
|
|
28
|
+
function readableReference(text, url) {
|
|
29
|
+
const label = text.trim();
|
|
30
|
+
return label === "" || label === url ? codeSpan(url) : `${label} (${codeSpan(url)})`;
|
|
31
|
+
}
|
|
32
|
+
function unwrapDestination(raw) {
|
|
33
|
+
return raw.startsWith("<") && raw.endsWith(">") ? raw.slice(1, -1) : raw;
|
|
34
|
+
}
|
|
35
|
+
function formatDestination(url) {
|
|
36
|
+
return url.replace(/[\s()<>]/g, (char) => encodeURIComponent(char));
|
|
37
|
+
}
|
|
38
|
+
const INLINE_LINK = /(!?)\[((?:[^[\]\n]|\[[^\]\n]*\])*)\]\(\s*(<[^>\n]*>|[^\s()]+(?:\([^\s()]*\)[^\s()]*)*)(\s+(?:"[^"\n]*"|'[^'\n]*'|\([^)\n]*\)))?\s*\)/g;
|
|
39
|
+
const REFERENCE_DEFINITION = /^( {0,3})\[([^\]\n]+)\]:[ \t]*(<[^>\n]*>|\S+)([^\n]*)$/gm;
|
|
40
|
+
const HTML_ATTRIBUTE = /(<(?:a|img|source)\b[^>]*?\s)(href|src)=("([^"]*)"|'([^']*)')/gi;
|
|
41
|
+
function rewriteLinks(content, resolve) {
|
|
42
|
+
const unmapped = [];
|
|
43
|
+
const resolveDestination = (url) => {
|
|
44
|
+
if (!isRelativeReference(url)) return { kind: "keep" };
|
|
45
|
+
const resolution = resolve(url);
|
|
46
|
+
if (resolution.kind === "unmapped") unmapped.push(url);
|
|
47
|
+
return resolution;
|
|
48
|
+
};
|
|
49
|
+
const { text, restore } = protectCode(content);
|
|
50
|
+
const unmappedRefs = /* @__PURE__ */ new Map();
|
|
51
|
+
let out = text.replace(REFERENCE_DEFINITION, (match, indent, id, rawDest, rest) => {
|
|
52
|
+
const url = unwrapDestination(rawDest);
|
|
53
|
+
const resolution = resolveDestination(url);
|
|
54
|
+
if (resolution.kind === "keep") return match;
|
|
55
|
+
if (resolution.kind === "rewrite") {
|
|
56
|
+
return `${indent}[${id}]: ${formatDestination(resolution.url)}${rest}`;
|
|
57
|
+
}
|
|
58
|
+
unmappedRefs.set(id.trim().toLowerCase(), url);
|
|
59
|
+
return "";
|
|
60
|
+
});
|
|
61
|
+
if (unmappedRefs.size > 0) {
|
|
62
|
+
out = out.replace(/(!?)\[([^[\]\n]+)\](?:\[([^[\]\n]*)\])?(?![(:[])/g, (match, _bang, text2, ref) => {
|
|
63
|
+
const id = (ref === void 0 || ref === "" ? text2 : ref).trim().toLowerCase();
|
|
64
|
+
const url = unmappedRefs.get(id);
|
|
65
|
+
return url === void 0 ? match : readableReference(text2, url);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
out = out.replace(INLINE_LINK, (match, _bang, label, rawDest, title) => {
|
|
69
|
+
const url = unwrapDestination(rawDest);
|
|
70
|
+
const resolution = resolveDestination(url);
|
|
71
|
+
if (resolution.kind === "keep") return match;
|
|
72
|
+
if (resolution.kind === "unmapped") return readableReference(label, url);
|
|
73
|
+
const prefix = match.slice(0, match.indexOf("](") + 2);
|
|
74
|
+
return `${prefix}${formatDestination(resolution.url)}${title ?? ""})`;
|
|
75
|
+
});
|
|
76
|
+
out = out.replace(HTML_ATTRIBUTE, (match, head, attr, _quoted, dq, sq) => {
|
|
77
|
+
const url = dq ?? sq ?? "";
|
|
78
|
+
const resolution = resolveDestination(url);
|
|
79
|
+
if (resolution.kind === "keep") return match;
|
|
80
|
+
if (resolution.kind === "rewrite") return `${head}${attr}="${resolution.url.replace(/"/g, """)}"`;
|
|
81
|
+
return `${head}data-source-${attr.toLowerCase()}="${url.replace(/"/g, """)}"`;
|
|
82
|
+
});
|
|
83
|
+
return { content: restore(out), unmapped };
|
|
84
|
+
}
|
|
85
|
+
function splitDestination(url) {
|
|
86
|
+
const hashIndex = url.indexOf("#");
|
|
87
|
+
const beforeHash = hashIndex === -1 ? url : url.slice(0, hashIndex);
|
|
88
|
+
const fragment = hashIndex === -1 ? "" : url.slice(hashIndex);
|
|
89
|
+
const queryIndex = beforeHash.indexOf("?");
|
|
90
|
+
return {
|
|
91
|
+
pathPart: queryIndex === -1 ? beforeHash : beforeHash.slice(0, queryIndex),
|
|
92
|
+
query: queryIndex === -1 ? "" : beforeHash.slice(queryIndex),
|
|
93
|
+
fragment
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function safeDecode(value) {
|
|
97
|
+
try {
|
|
98
|
+
return decodeURIComponent(value);
|
|
99
|
+
} catch {
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
export {
|
|
104
|
+
isRelativeReference,
|
|
105
|
+
readableReference,
|
|
106
|
+
rewriteLinks,
|
|
107
|
+
safeDecode,
|
|
108
|
+
splitDestination
|
|
109
|
+
};
|
package/dist/plugins/internal/{resource-docs-shared → doc-sources/render}/markdown-structure.d.ts
RENAMED
|
@@ -7,3 +7,7 @@ export declare function renderCodeFence(source: string, language?: string): stri
|
|
|
7
7
|
* for the surrounding table and physical newlines are collapsed to spaces.
|
|
8
8
|
*/
|
|
9
9
|
export declare function escapeMarkdownTableCell(value: unknown): string;
|
|
10
|
+
/** Render one Markdown table row with structurally safe cells. */
|
|
11
|
+
export declare function renderTableRow(values: unknown[]): string;
|
|
12
|
+
/** Fence language for a source file name; empty when unknown. */
|
|
13
|
+
export declare function languageForFilename(filename: string): string;
|