@dooc-dev/dooc 0.0.22 → 0.0.23
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/dist/client.global.js +1 -1
- package/dist/edit.global.js +269 -263
- package/dist/engine/compiler/check.js +17 -0
- package/dist/engine/compiler/export.js +18 -1
- package/dist/engine/compiler/files.js +13 -2
- package/dist/engine/compiler/manifest.js +4 -0
- package/dist/engine/compiler/skills.d.ts +10 -0
- package/dist/engine/compiler/skills.js +95 -0
- package/dist/engine/core/content-metadata.d.ts +7 -1
- package/dist/engine/core/content-metadata.js +52 -18
- package/dist/engine/core/files.d.ts +1 -0
- package/dist/engine/core/files.js +3 -0
- package/dist/frontend/document-application.d.ts +11 -2
- package/dist/frontend/document-application.js +356 -130
- package/dist/frontend/language-picker.js +1 -0
- package/dist/frontend/locales/eng.json +17 -1
- package/dist/frontend/locales/jpn.json +17 -1
- package/dist/frontend/locales/zho.json +17 -1
- package/dist/frontend/mcp-operations.js +57 -1
- package/dist/frontend/nav-focus.d.ts +1 -1
- package/dist/frontend/nav-focus.js +25 -2
- package/dist/frontend/nav-update.js +12 -0
- package/dist/frontend/page-jump.d.ts +3 -0
- package/dist/frontend/page-jump.js +130 -0
- package/dist/frontend/resource-download.d.ts +1 -1
- package/dist/frontend/resource-download.js +118 -28
- package/dist/frontend/resource-library.js +16 -7
- package/dist/frontend/search.js +18 -5
- package/dist/frontend/theme-picker.js +11 -0
- package/dist/manifest.global.js +349 -0
- package/dist/mcp-relay.mjs +71 -1
- package/dist/plugins.global.js +4 -4
- package/dist/server/assets.d.ts +1 -0
- package/dist/server/assets.js +4 -1
- package/dist/server/build-media.d.ts +6 -0
- package/dist/server/build-media.js +136 -0
- package/dist/server/build-output.d.ts +2 -1
- package/dist/server/build-output.js +32 -2
- package/dist/server/build-split.d.ts +15 -0
- package/dist/server/build-split.js +160 -0
- package/dist/server/build.d.ts +6 -1
- package/dist/server/build.js +37 -10
- package/dist/server/cli.js +20 -2
- package/dist/server/mcp.js +14 -1
- package/dist/server/serve.d.ts +21 -2
- package/dist/server/serve.js +26 -20
- package/dist/server/static-client.js +2 -1
- package/dist/server/workspace-server.d.ts +1 -1
- package/dist/server/workspace-server.js +24 -4
- package/dist/subformats.global.js +38 -38
- package/dist/ui.global.js +68 -68
- package/dist/workspace/client.d.ts +1 -1
- package/dist/workspace/client.js +22 -3
- package/dist/workspace/mcp-tools.js +32 -0
- package/dist/workspace/mcp.js +50 -1
- package/dist/workspace/protocol.d.ts +3 -0
- package/dist/workspace/server.d.ts +1 -1
- package/dist/workspace/server.js +14 -3
- package/dist/workspace/site-icon.js +17 -12
- package/dist/workspace/textfile.js +16 -4
- package/dist/workspace-mcp-worker.global.js +234 -119
- package/dist/workspace-reader-mcp-worker.global.js +234 -119
- package/dist/workspace-reader-worker.global.js +234 -119
- package/dist/workspace-worker.global.js +234 -119
- package/package.json +2 -2
|
@@ -14,6 +14,7 @@ import { createHash, existsSync, readdirSync, readFileSync, resolve, statSync }
|
|
|
14
14
|
import { contentLanguageCode, isContentLanguage } from "./language-codes.js";
|
|
15
15
|
import { siteContentLanguages, translationFile } from "./locales.js";
|
|
16
16
|
import { manifestFile, readManifest } from "./manifest.js";
|
|
17
|
+
import { readProjectSkills } from "./skills.js";
|
|
17
18
|
import { textfilePath } from "./textfile.js";
|
|
18
19
|
import { siteThemes, themeVariants } from "./theme-variants.js";
|
|
19
20
|
export { CHECK_KINDS } from "./check-types.js";
|
|
@@ -176,6 +177,22 @@ export const checkSite = (root, options = {}) => {
|
|
|
176
177
|
return finish(report, options);
|
|
177
178
|
if (manifest.licence)
|
|
178
179
|
read(manifest.licence, { sourceFile: manifestFile(root) });
|
|
180
|
+
for (const file of [
|
|
181
|
+
...(manifest.libraryFiles ?? []),
|
|
182
|
+
...(manifest.includedLibraryFiles ?? []),
|
|
183
|
+
]) {
|
|
184
|
+
const data = read(file, { sourceFile: manifestFile(root) });
|
|
185
|
+
if (data)
|
|
186
|
+
text(file, data, { sourceFile: manifestFile(root) });
|
|
187
|
+
}
|
|
188
|
+
for (const file of [manifestFile(root), ...(manifest.includedManifests ?? [])]) {
|
|
189
|
+
try {
|
|
190
|
+
readProjectSkills(root, file);
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
add("MANIFEST_INVALID", "error", file, messageOf(error));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
179
196
|
let sourceLanguage;
|
|
180
197
|
try {
|
|
181
198
|
sourceLanguage = contentLanguageCode(manifest.defaultLang ?? DEFAULT_LANG);
|
|
@@ -14,7 +14,8 @@ import { PROJECT_FONTS_DIR } from "./fonts.js";
|
|
|
14
14
|
import { existsSync, fileURLToPath, pathToFileURL, posix, readdirSync, readFileSync, realpathSync, relative as relativePath, statSync, } from "./host.js";
|
|
15
15
|
import { assertNotIgnored, ignoredFiles } from "./ignored-files.js";
|
|
16
16
|
import { siteContentLanguages, translationFile } from "./locales.js";
|
|
17
|
-
import { manifestFile, readManifest } from "./manifest.js";
|
|
17
|
+
import { manifestFile, readManifest, sourceOrigin } from "./manifest.js";
|
|
18
|
+
import { readProjectSkills } from "./skills.js";
|
|
18
19
|
import { readTextfile, textfilePath } from "./textfile.js";
|
|
19
20
|
import { siteThemes, themeVariants } from "./theme-variants.js";
|
|
20
21
|
import { zip } from "./zip.js";
|
|
@@ -26,10 +27,20 @@ export const exportEntries = (root, file = manifestFile(root)) => {
|
|
|
26
27
|
const themes = siteThemes(root, manifest);
|
|
27
28
|
const entries = new Map();
|
|
28
29
|
const origins = new Map();
|
|
30
|
+
const skillFiles = new Map();
|
|
31
|
+
for (const source of [file, ...(manifest.includedManifests ?? [])])
|
|
32
|
+
for (const skill of readProjectSkills(root, source))
|
|
33
|
+
for (const [name, data] of skill.files)
|
|
34
|
+
skillFiles.set(posix.join(posix.dirname(skill.file), name), data);
|
|
29
35
|
const add = (file, origin) => {
|
|
30
36
|
file = file.replace(/^(\.\/)+/, "");
|
|
31
37
|
if (entries.has(file))
|
|
32
38
|
return;
|
|
39
|
+
const skillData = skillFiles.get(file);
|
|
40
|
+
if (skillData) {
|
|
41
|
+
entries.set(file, { name: file, data: skillData });
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
33
44
|
const settingsFile = [PROJECT_FONTS_DIR, CODE_LANGUAGES_DIR, ".dooc/editor-tools"].some((dir) => file.startsWith(`${dir}/`) && localFile(file.slice(dir.length + 1)));
|
|
34
45
|
// References are already URL-decoded; # and ? are literal filename characters here.
|
|
35
46
|
if (!localFile(file.replace(/[?#]/g, "_")) && !settingsFile)
|
|
@@ -55,6 +66,8 @@ export const exportEntries = (root, file = manifestFile(root)) => {
|
|
|
55
66
|
add(file);
|
|
56
67
|
if (manifest.licence)
|
|
57
68
|
add(manifest.licence);
|
|
69
|
+
for (const file of [...(manifest.libraryFiles ?? []), ...(manifest.includedLibraryFiles ?? [])])
|
|
70
|
+
add(file, sourceOrigin(manifest, file));
|
|
58
71
|
optional(CONFIG_FILE);
|
|
59
72
|
for (const node of flattenTree(manifest.tree)) {
|
|
60
73
|
const { id, origin } = node;
|
|
@@ -132,6 +145,8 @@ export const exportEntries = (root, file = manifestFile(root)) => {
|
|
|
132
145
|
}
|
|
133
146
|
// Map iteration visits dependencies appended while walking the graph, once per path.
|
|
134
147
|
for (const entry of entries.values()) {
|
|
148
|
+
if (skillFiles.has(entry.name))
|
|
149
|
+
continue;
|
|
135
150
|
const ext = fileExtension(entry.name);
|
|
136
151
|
if (["md", "callouth"].includes(ext)) {
|
|
137
152
|
const origin = origins.get(entry.name);
|
|
@@ -161,6 +176,8 @@ export const exportEntries = (root, file = manifestFile(root)) => {
|
|
|
161
176
|
return url;
|
|
162
177
|
});
|
|
163
178
|
}
|
|
179
|
+
for (const [name, data] of skillFiles)
|
|
180
|
+
entries.set(name, { name, data });
|
|
164
181
|
return [...entries.values()];
|
|
165
182
|
};
|
|
166
183
|
export const exportBundle = (root) => zip(exportEntries(root));
|
|
@@ -15,7 +15,7 @@ import { translationFile, translationFiles, translationLanguages } from "./local
|
|
|
15
15
|
import { manifestFile, parseManifestText, readManifest, sourceOrigin } from "./manifest.js";
|
|
16
16
|
import { isRemoteSourceFile } from "./remote-manifests.js";
|
|
17
17
|
import { rewriteSchemaFiles } from "./schema-file-references.js";
|
|
18
|
-
import { textfilePath, writeTextfile } from "./textfile.js";
|
|
18
|
+
import { readTextfile, textfilePath, writeTextfile } from "./textfile.js";
|
|
19
19
|
import { themeNames, themeVariants } from "./theme-variants.js";
|
|
20
20
|
// Project settings and translations have their own layout, outside file restructuring.
|
|
21
21
|
const reserved = new Set(["docs.config.mjs", "node_modules", "build", "dist", "locales"]);
|
|
@@ -277,6 +277,8 @@ const rewriteManifestPaths = (manifest, moves) => {
|
|
|
277
277
|
manifest.icon = rewrite(manifest.icon);
|
|
278
278
|
if (manifest.licence)
|
|
279
279
|
manifest.licence = rewrite(manifest.licence);
|
|
280
|
+
if (manifest.libraryFiles)
|
|
281
|
+
manifest.libraryFiles = manifest.libraryFiles.map(rewrite);
|
|
280
282
|
for (const format of manifest.subformats ?? []) {
|
|
281
283
|
format.schema = rewrite(format.schema);
|
|
282
284
|
if (format.icon)
|
|
@@ -299,6 +301,13 @@ export const updateFiles = (root, input) => {
|
|
|
299
301
|
const manifest = readManifest(root);
|
|
300
302
|
const layout = snapshot.layout;
|
|
301
303
|
const paths = snapshot.files.map((file) => file.path);
|
|
304
|
+
const skillManifests = new Map([
|
|
305
|
+
[manifestFile(root), manifest.skills ?? []],
|
|
306
|
+
...(manifest.includedManifests ?? []).map((file) => [file, parseManifestText(readTextfile(root, file), file).skills ?? []]),
|
|
307
|
+
]);
|
|
308
|
+
const skillDirectories = [...skillManifests].flatMap(([file, skills]) => skills.map((skill) => `${posix.join(posix.dirname(file), posix.dirname(skill))}/`));
|
|
309
|
+
const skillFile = (file) => !!skillManifests.get(file)?.length ||
|
|
310
|
+
skillDirectories.some((directory) => file.startsWith(directory));
|
|
302
311
|
const pages = flattenTree(manifest.tree);
|
|
303
312
|
const moves = new Map();
|
|
304
313
|
if (input.action === "layout") {
|
|
@@ -309,7 +318,7 @@ export const updateFiles = (root, input) => {
|
|
|
309
318
|
else if (input.action === "restructure") {
|
|
310
319
|
const taken = new Set(paths);
|
|
311
320
|
for (const file of paths) {
|
|
312
|
-
if (file.startsWith("themes/") || isRemoteSourceFile(file))
|
|
321
|
+
if (file.startsWith("themes/") || isRemoteSourceFile(file) || skillFile(file))
|
|
313
322
|
continue;
|
|
314
323
|
let target = defaultFilePath(file);
|
|
315
324
|
if (target === file)
|
|
@@ -368,6 +377,8 @@ export const updateFiles = (root, input) => {
|
|
|
368
377
|
}
|
|
369
378
|
else
|
|
370
379
|
throw new Error("Unknown file action");
|
|
380
|
+
if ([...moves].some(([source, target]) => skillFile(source) || skillFile(target)))
|
|
381
|
+
throw new Error("Keep configured skill directories intact; edit system.skills to relocate a skill");
|
|
371
382
|
if ([...moves].some(([source, target]) => isRemoteSourceFile(source) || isRemoteSourceFile(target)))
|
|
372
383
|
throw new Error("Remote document sources are read-only");
|
|
373
384
|
for (const [source, target] of [...moves]) {
|
|
@@ -115,6 +115,8 @@ export const readManifest = (root, file = manifestFile(root)) => {
|
|
|
115
115
|
manifest.includedManifests.push(included, ...(child.includedManifests ?? []));
|
|
116
116
|
manifest.includedAssets ??= [];
|
|
117
117
|
manifest.includedAssets.push(...(child.includedAssets ?? []));
|
|
118
|
+
manifest.includedLibraryFiles ??= [];
|
|
119
|
+
manifest.includedLibraryFiles.push(...(child.libraryFiles ?? []), ...(child.includedLibraryFiles ?? []));
|
|
118
120
|
manifest.files ??= parseFileLayout({});
|
|
119
121
|
Object.assign(rebasedIcons, child.files?.icons);
|
|
120
122
|
const includedIcon = child.files?.icons?.[node.resolved.id];
|
|
@@ -134,6 +136,8 @@ export const readManifest = (root, file = manifestFile(root)) => {
|
|
|
134
136
|
}
|
|
135
137
|
};
|
|
136
138
|
if (imported) {
|
|
139
|
+
if (manifest.libraryFiles)
|
|
140
|
+
manifest.libraryFiles = manifest.libraryFiles.map(qualify);
|
|
137
141
|
manifest.includedAssets = [
|
|
138
142
|
manifest.icon,
|
|
139
143
|
manifest.licence,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface ProjectSkill {
|
|
2
|
+
file: string;
|
|
3
|
+
frontmatter: Record<string, unknown> & {
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
};
|
|
7
|
+
files: Map<string, Buffer>;
|
|
8
|
+
}
|
|
9
|
+
/** Read only skills explicitly declared by the selected project's manifest. */
|
|
10
|
+
export declare const readProjectSkills: (root: string, manifestPath?: string) => ProjectSkill[];
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { parse } from "yaml";
|
|
2
|
+
import { localFile } from "../core/files.js";
|
|
3
|
+
import { join, lstatSync, posix, readdirSync, readFileSync, statSync } from "./host.js";
|
|
4
|
+
import { assertNotIgnored, ignoredFiles, withIgnoredFilesCache } from "./ignored-files.js";
|
|
5
|
+
import { manifestFile, parseManifestText } from "./manifest.js";
|
|
6
|
+
import { readTextfile, textfilePath } from "./textfile.js";
|
|
7
|
+
/** Read only skills explicitly declared by the selected project's manifest. */
|
|
8
|
+
export const readProjectSkills = (root, manifestPath = manifestFile(root)) => withIgnoredFilesCache(() => {
|
|
9
|
+
const manifest = parseManifestText(readTextfile(root, manifestPath), manifestPath);
|
|
10
|
+
if (manifest.errors.length)
|
|
11
|
+
throw new Error(manifest.errors.join("\n"));
|
|
12
|
+
const names = new Set();
|
|
13
|
+
return (manifest.skills ?? []).map((configured) => {
|
|
14
|
+
const file = posix.join(posix.dirname(manifestPath), configured);
|
|
15
|
+
const directory = posix.dirname(file);
|
|
16
|
+
const path = textfilePath(root, directory);
|
|
17
|
+
let ancestor = root;
|
|
18
|
+
for (const part of directory.split("/")) {
|
|
19
|
+
ancestor = join(ancestor, part);
|
|
20
|
+
if (lstatSync(ancestor).isSymbolicLink())
|
|
21
|
+
throw new Error(`Skill paths must not contain symlinks: ${directory}`);
|
|
22
|
+
}
|
|
23
|
+
assertNotIgnored(root, file);
|
|
24
|
+
const files = new Map();
|
|
25
|
+
let bytes = 0;
|
|
26
|
+
const walk = (relative, depth = 0) => {
|
|
27
|
+
if (depth > 32)
|
|
28
|
+
throw new Error(`Skill directory nesting exceeds 32 levels: ${file}`);
|
|
29
|
+
const entries = readdirSync(join(path, relative), { withFileTypes: true });
|
|
30
|
+
entries.sort((a, b) => a.name.localeCompare(b.name, "en"));
|
|
31
|
+
const ignored = ignoredFiles(root, entries.map((entry) => posix.join(directory, relative, entry.name) +
|
|
32
|
+
(entry.isDirectory() ? "/" : "")));
|
|
33
|
+
for (const entry of entries) {
|
|
34
|
+
const name = posix.join(relative, entry.name);
|
|
35
|
+
const source = posix.join(directory, name);
|
|
36
|
+
if (entry.name.startsWith(".") ||
|
|
37
|
+
ignored.has(source + (entry.isDirectory() ? "/" : "")))
|
|
38
|
+
continue;
|
|
39
|
+
if (!localFile(name.replace(/[?#]/g, "_")) || entry.isSymbolicLink())
|
|
40
|
+
throw new Error(`Invalid skill file or symlink: ${source}`);
|
|
41
|
+
if (entry.isDirectory()) {
|
|
42
|
+
walk(name, depth + 1);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (!entry.isFile())
|
|
46
|
+
throw new Error(`Expected a regular skill file: ${source}`);
|
|
47
|
+
const sourcePath = textfilePath(path, name);
|
|
48
|
+
if (files.size >= 512 || bytes + statSync(sourcePath).size > 16 * 1024 * 1024)
|
|
49
|
+
throw new Error(`Skill exceeds 512 files or 16 MiB: ${file}`);
|
|
50
|
+
const data = readFileSync(sourcePath);
|
|
51
|
+
bytes += data.length;
|
|
52
|
+
if (bytes > 16 * 1024 * 1024)
|
|
53
|
+
throw new Error(`Skill exceeds 16 MiB: ${file}`);
|
|
54
|
+
files.set(name, data);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
walk("");
|
|
58
|
+
const data = files.get("SKILL.md");
|
|
59
|
+
if (!data)
|
|
60
|
+
throw new Error(`Missing or ignored skill file: ${file}`);
|
|
61
|
+
const text = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(data);
|
|
62
|
+
const yaml = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(text)?.[1];
|
|
63
|
+
if (yaml === undefined || text.includes("\0"))
|
|
64
|
+
throw new Error(`Skill must start with YAML frontmatter: ${file}`);
|
|
65
|
+
const frontmatter = parse(yaml);
|
|
66
|
+
if (!frontmatter || typeof frontmatter !== "object" || Array.isArray(frontmatter))
|
|
67
|
+
throw new Error(`Invalid skill frontmatter: ${file}`);
|
|
68
|
+
const { name, description, license, compatibility, metadata } = frontmatter;
|
|
69
|
+
if (typeof name !== "string" ||
|
|
70
|
+
name.length > 64 ||
|
|
71
|
+
!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name) ||
|
|
72
|
+
name !== posix.basename(directory))
|
|
73
|
+
throw new Error(`Skill name must match its directory and use 1-64 lowercase letters, digits or single hyphens: ${file}`);
|
|
74
|
+
if (typeof description !== "string" || !description.trim() || description.length > 1024)
|
|
75
|
+
throw new Error(`Skill description must contain 1-1024 characters: ${file}`);
|
|
76
|
+
if ((license !== undefined && typeof license !== "string") ||
|
|
77
|
+
(compatibility !== undefined &&
|
|
78
|
+
(typeof compatibility !== "string" ||
|
|
79
|
+
!compatibility.trim() ||
|
|
80
|
+
compatibility.length > 500)) ||
|
|
81
|
+
(frontmatter["allowed-tools"] !== undefined &&
|
|
82
|
+
typeof frontmatter["allowed-tools"] !== "string") ||
|
|
83
|
+
(metadata !== undefined &&
|
|
84
|
+
(!metadata ||
|
|
85
|
+
typeof metadata !== "object" ||
|
|
86
|
+
Array.isArray(metadata) ||
|
|
87
|
+
Object.values(metadata).some((value) => typeof value !== "string"))))
|
|
88
|
+
throw new Error(`Invalid optional skill frontmatter: ${file}`);
|
|
89
|
+
JSON.stringify(frontmatter);
|
|
90
|
+
if (names.has(name))
|
|
91
|
+
throw new Error(`Duplicate skill name: ${name}`);
|
|
92
|
+
names.add(name);
|
|
93
|
+
return { file, frontmatter, files };
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Document } from "yaml";
|
|
1
2
|
import { type VersionConfig } from "./document-version.js";
|
|
2
3
|
import { type FileLayout } from "./files.js";
|
|
3
4
|
import { type Subformat } from "./subformats.js";
|
|
@@ -28,6 +29,9 @@ export interface ParsedManifest {
|
|
|
28
29
|
icon?: string;
|
|
29
30
|
defaultLang?: string;
|
|
30
31
|
licence?: string;
|
|
32
|
+
skills?: string[];
|
|
33
|
+
libraryFiles?: string[];
|
|
34
|
+
includedLibraryFiles?: string[];
|
|
31
35
|
files?: FileLayout;
|
|
32
36
|
/** Content languages offered by the site, including defaultLang; normalized to ISO 639-3. */
|
|
33
37
|
languages?: string[];
|
|
@@ -59,8 +63,10 @@ export declare const docIdOfFile: (name: string) => string | undefined;
|
|
|
59
63
|
* Validates id shape and duplicates.
|
|
60
64
|
*/
|
|
61
65
|
export declare const parseManifest: (value: unknown) => ParsedManifest;
|
|
66
|
+
/** Move the former sidebar icon without discarding YAML comments or choosing between duplicates. */
|
|
67
|
+
export declare const migrateDocumentIcon: (document: Document) => boolean;
|
|
62
68
|
/** Serialize the authored format; legacy manifests remain readable during migration. */
|
|
63
|
-
export declare const serializeManifest: (tree: readonly DocNode[], { format, version, titles, themeIcons, title, icon, defaultLang, licence, files, languages, themes, subformats, defaultSubformatFolder, includedSubformats, }?: Omit<ParsedManifest, "tree" | "errors">) => string;
|
|
69
|
+
export declare const serializeManifest: (tree: readonly DocNode[], { format, version, titles, themeIcons, title, icon, defaultLang, licence, skills, libraryFiles, files, languages, themes, subformats, defaultSubformatFolder, includedSubformats, }?: Omit<ParsedManifest, "tree" | "errors">) => string;
|
|
64
70
|
/** Flatten the tree into display order (pre-order). parent omitted = top level. */
|
|
65
71
|
export declare const flattenTree: (tree: readonly DocNode[]) => (Omit<DocNode, "children"> & {
|
|
66
72
|
parent?: string;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// by complete source paths; legacy manifests retain their authored IDs during migration.
|
|
3
3
|
import { stringify } from "yaml";
|
|
4
4
|
import { parseVersionConfig } from "./document-version.js";
|
|
5
|
-
import { docFile, fileDocumentId, localFile, parseFileLayout } from "./files.js";
|
|
5
|
+
import { docFile, fileDocumentId, isSkillFile, localFile, parseFileLayout, } from "./files.js";
|
|
6
6
|
import { contentLanguageCode, DEFAULT_LANG, isLangTag } from "./language.js";
|
|
7
7
|
import { isRemoteManifest, remoteManifestSource } from "./remote-manifest.js";
|
|
8
8
|
import { parseSubformats } from "./subformats.js";
|
|
@@ -314,10 +314,23 @@ const parseNestedManifest = (input) => {
|
|
|
314
314
|
const document = documentFormat
|
|
315
315
|
? object(root.document, ["title", "url", "icon", "sidebar", "children", "subformat", "library"], "document")
|
|
316
316
|
: undefined;
|
|
317
|
-
const system = object(root.system ?? {}, ["languages", "default_lang", "themes", "licence", "files"], "system");
|
|
317
|
+
const system = object(root.system ?? {}, ["languages", "default_lang", "themes", "licence", "skills", "files", "library"], "system");
|
|
318
|
+
const library = object(system.library ?? {}, ["files"], "system.library");
|
|
319
|
+
const libraryFiles = library.files;
|
|
320
|
+
if (libraryFiles !== undefined &&
|
|
321
|
+
(!Array.isArray(libraryFiles) ||
|
|
322
|
+
libraryFiles.some((file) => !localFile(file) || !file.trim() || file.includes("*")) ||
|
|
323
|
+
new Set(libraryFiles).size !== libraryFiles.length))
|
|
324
|
+
throw new Error("system.library.files must be a list of unique local file paths");
|
|
318
325
|
const licence = system.licence;
|
|
319
326
|
if (licence !== undefined && (!localFile(licence) || !licence.trim()))
|
|
320
327
|
throw new Error("system.licence must be a local file path");
|
|
328
|
+
const skills = system.skills;
|
|
329
|
+
if (skills !== undefined &&
|
|
330
|
+
(!Array.isArray(skills) ||
|
|
331
|
+
skills.some((file) => !isSkillFile(file)) ||
|
|
332
|
+
new Set(skills).size !== skills.length))
|
|
333
|
+
throw new Error("system.skills must be a list of unique project-relative SKILL.md paths");
|
|
321
334
|
const sidebar = object(document?.sidebar ?? root.left_sidebar ?? {}, ["title", "icon"], "sidebar");
|
|
322
335
|
const layout = object(system.files ?? {}, ["default_layout", "order"], "system.files");
|
|
323
336
|
const titles = {};
|
|
@@ -333,15 +346,20 @@ const parseNestedManifest = (input) => {
|
|
|
333
346
|
titles[code] = title.trim();
|
|
334
347
|
}
|
|
335
348
|
}
|
|
349
|
+
if (document?.icon !== undefined && sidebar.icon !== undefined)
|
|
350
|
+
throw new Error("Use document.icon only; remove document.sidebar.icon");
|
|
351
|
+
const rootIcon = document?.icon !== undefined ? document.icon : sidebar.icon;
|
|
352
|
+
const scalarIcon = documentFormat && typeof rootIcon === "string" ? rootIcon : undefined;
|
|
336
353
|
const themeIcons = {};
|
|
337
|
-
if (
|
|
338
|
-
const icons = object(
|
|
354
|
+
if (rootIcon !== undefined && scalarIcon === undefined) {
|
|
355
|
+
const icons = object(rootIcon, ["light", "dark"], documentFormat ? "document.icon" : "left_sidebar.icon");
|
|
339
356
|
for (const [theme, file] of Object.entries(icons)) {
|
|
340
357
|
if (!localFile(file) || !file.endsWith(".svg"))
|
|
341
358
|
throw new Error("Site icons must be local SVG files");
|
|
342
359
|
themeIcons[theme] = file;
|
|
343
360
|
}
|
|
344
361
|
}
|
|
362
|
+
const icon = scalarIcon ?? themeIcons.light ?? themeIcons.dark;
|
|
345
363
|
const documents = {};
|
|
346
364
|
const icons = {};
|
|
347
365
|
const walk = (value, position = "root") => {
|
|
@@ -371,8 +389,8 @@ const parseNestedManifest = (input) => {
|
|
|
371
389
|
const location = documentFormat
|
|
372
390
|
? { url, ...(position === "root" ? { root: true } : {}) }
|
|
373
391
|
: {};
|
|
374
|
-
|
|
375
|
-
|
|
392
|
+
const nodeIcon = documentFormat && position === "root" ? icon : node.icon;
|
|
393
|
+
if (nodeIcon !== undefined && (!localFile(nodeIcon) || !nodeIcon.endsWith(".svg")))
|
|
376
394
|
throw new Error("Document icons must be local SVG files");
|
|
377
395
|
if (node.library !== undefined) {
|
|
378
396
|
if (!isLibraryView(node.library) ||
|
|
@@ -383,8 +401,8 @@ const parseNestedManifest = (input) => {
|
|
|
383
401
|
(typeof node.title !== "string" || !node.title.trim())))
|
|
384
402
|
throw new Error("Library pages require a view and a non-empty title");
|
|
385
403
|
const id = libraryPageId(node.library);
|
|
386
|
-
if (typeof
|
|
387
|
-
icons[id] =
|
|
404
|
+
if (typeof nodeIcon === "string")
|
|
405
|
+
icons[id] = nodeIcon;
|
|
388
406
|
return {
|
|
389
407
|
id,
|
|
390
408
|
...location,
|
|
@@ -402,8 +420,8 @@ const parseNestedManifest = (input) => {
|
|
|
402
420
|
(typeof node.title !== "string" || !node.title.trim())))
|
|
403
421
|
throw new Error("Subformat pages require a registered subformat and a non-empty title");
|
|
404
422
|
const id = subformatPageId(config.ext);
|
|
405
|
-
if (typeof
|
|
406
|
-
icons[id] =
|
|
423
|
+
if (typeof nodeIcon === "string")
|
|
424
|
+
icons[id] = nodeIcon;
|
|
407
425
|
return {
|
|
408
426
|
id,
|
|
409
427
|
...location,
|
|
@@ -425,8 +443,8 @@ const parseNestedManifest = (input) => {
|
|
|
425
443
|
throw new Error(`Duplicate document: ${node.file}`);
|
|
426
444
|
if (file)
|
|
427
445
|
documents[id] = file;
|
|
428
|
-
if (typeof
|
|
429
|
-
icons[id] =
|
|
446
|
+
if (typeof nodeIcon === "string")
|
|
447
|
+
icons[id] = nodeIcon;
|
|
430
448
|
const remote = url && isRemoteManifest(url) ? remoteManifestSource(url) : undefined;
|
|
431
449
|
const manifestPath = remote?.path ?? url;
|
|
432
450
|
return {
|
|
@@ -491,9 +509,7 @@ const parseNestedManifest = (input) => {
|
|
|
491
509
|
...(titles[source] || document?.title
|
|
492
510
|
? { title: titles[source] ?? document?.title }
|
|
493
511
|
: {}),
|
|
494
|
-
...(
|
|
495
|
-
? { icon: themeIcons.light ?? themeIcons.dark }
|
|
496
|
-
: {}),
|
|
512
|
+
...(icon === undefined ? {} : { icon }),
|
|
497
513
|
files: {
|
|
498
514
|
defaultLayout: layout.default_layout,
|
|
499
515
|
documents,
|
|
@@ -509,8 +525,10 @@ const parseNestedManifest = (input) => {
|
|
|
509
525
|
format: documentFormat ? "document" : "nested",
|
|
510
526
|
tree,
|
|
511
527
|
...(licence === undefined ? {} : { licence }),
|
|
528
|
+
...(skills === undefined ? {} : { skills: skills }),
|
|
529
|
+
...(libraryFiles === undefined ? {} : { libraryFiles: libraryFiles }),
|
|
512
530
|
...(sidebar.title === undefined ? {} : { titles }),
|
|
513
|
-
...(
|
|
531
|
+
...(rootIcon !== undefined && scalarIcon === undefined ? { themeIcons } : {}),
|
|
514
532
|
};
|
|
515
533
|
}
|
|
516
534
|
catch (error) {
|
|
@@ -521,8 +539,19 @@ const parseNestedManifest = (input) => {
|
|
|
521
539
|
};
|
|
522
540
|
}
|
|
523
541
|
};
|
|
542
|
+
/** Move the former sidebar icon without discarding YAML comments or choosing between duplicates. */
|
|
543
|
+
export const migrateDocumentIcon = (document) => {
|
|
544
|
+
const previous = ["document", "sidebar", "icon"];
|
|
545
|
+
if (!document.hasIn(previous))
|
|
546
|
+
return false;
|
|
547
|
+
if (document.hasIn(["document", "icon"]))
|
|
548
|
+
throw new Error("Use document.icon only; remove document.sidebar.icon");
|
|
549
|
+
document.setIn(["document", "icon"], document.getIn(previous, true));
|
|
550
|
+
document.deleteIn(previous);
|
|
551
|
+
return true;
|
|
552
|
+
};
|
|
524
553
|
/** Serialize the authored format; legacy manifests remain readable during migration. */
|
|
525
|
-
export const serializeManifest = (tree, { format, version, titles, themeIcons, title, icon, defaultLang, licence, files, languages, themes, subformats, defaultSubformatFolder, includedSubformats, } = {}) => {
|
|
554
|
+
export const serializeManifest = (tree, { format, version, titles, themeIcons, title, icon, defaultLang, licence, skills, libraryFiles, files, languages, themes, subformats, defaultSubformatFolder, includedSubformats, } = {}) => {
|
|
526
555
|
if (format) {
|
|
527
556
|
const contents = (nodes) => nodes.map((node) => {
|
|
528
557
|
const page = {
|
|
@@ -549,7 +578,9 @@ export const serializeManifest = (tree, { format, version, titles, themeIcons, t
|
|
|
549
578
|
...(titles || (format !== "document" && title)
|
|
550
579
|
? { title: titles ?? { [contentLanguageCode(defaultLang ?? DEFAULT_LANG)]: title } }
|
|
551
580
|
: {}),
|
|
552
|
-
...(
|
|
581
|
+
...(format !== "document" && (themeIcons || icon)
|
|
582
|
+
? { icon: themeIcons ?? { light: icon, dark: icon } }
|
|
583
|
+
: {}),
|
|
553
584
|
};
|
|
554
585
|
const hasSidebar = Object.keys(sidebar).length > 0;
|
|
555
586
|
const pages = contents(tree);
|
|
@@ -559,6 +590,8 @@ export const serializeManifest = (tree, { format, version, titles, themeIcons, t
|
|
|
559
590
|
...(languages ? { languages } : {}),
|
|
560
591
|
default_lang: defaultLang ?? DEFAULT_LANG,
|
|
561
592
|
...(licence === undefined ? {} : { licence }),
|
|
593
|
+
...(skills === undefined ? {} : { skills }),
|
|
594
|
+
...(libraryFiles === undefined ? {} : { library: { files: libraryFiles } }),
|
|
562
595
|
...(themes ? { themes } : {}),
|
|
563
596
|
...(files
|
|
564
597
|
? {
|
|
@@ -574,6 +607,7 @@ export const serializeManifest = (tree, { format, version, titles, themeIcons, t
|
|
|
574
607
|
...(pages[0]?.document ?? {
|
|
575
608
|
url: "",
|
|
576
609
|
}),
|
|
610
|
+
...(themeIcons || icon ? { icon: themeIcons ?? icon } : {}),
|
|
577
611
|
...(hasSidebar ? { sidebar } : {}),
|
|
578
612
|
},
|
|
579
613
|
}
|
|
@@ -6,6 +6,7 @@ export interface FileLayout {
|
|
|
6
6
|
export declare const MAX_FILE_UPLOAD_BYTES: number;
|
|
7
7
|
export declare const manifestDirectory: (origin?: string) => string;
|
|
8
8
|
export declare const localFile: (value: unknown) => value is string;
|
|
9
|
+
export declare const isSkillFile: (value: unknown) => value is string;
|
|
9
10
|
export declare const isDocumentFileName: (value: unknown) => value is string;
|
|
10
11
|
export declare const suggestDocFileName: (title: string) => string;
|
|
11
12
|
export declare const fileExtension: (file: string) => string;
|
|
@@ -5,6 +5,9 @@ export const localFile = (value) => typeof value === "string" &&
|
|
|
5
5
|
!/[\\:?#]/.test(value) &&
|
|
6
6
|
[...value].every((char) => char.charCodeAt(0) >= 32) &&
|
|
7
7
|
value.split("/").every((part) => !!part && !part.startsWith("."));
|
|
8
|
+
export const isSkillFile = (value) => typeof value === "string" &&
|
|
9
|
+
value.endsWith("/SKILL.md") &&
|
|
10
|
+
localFile(value.replace(/(^|\/)\.agents\//g, "$1agents/"));
|
|
8
11
|
export const isDocumentFileName = (value) => localFile(value) && !value.includes("/") && value.endsWith(".md");
|
|
9
12
|
export const suggestDocFileName = (title) => {
|
|
10
13
|
const name = [...title]
|
|
@@ -87,6 +87,14 @@ export interface Site {
|
|
|
87
87
|
contentLanguages?: readonly string[];
|
|
88
88
|
themes?: readonly ("light" | "dark")[];
|
|
89
89
|
}
|
|
90
|
+
type NavigationEntry = Pick<Entry, "id" | "url" | "root" | "name" | "origin" | "included" | "parent" | "file" | "sourceFile" | "frontmatter" | "icon" | "subformat" | "library" | "translatedLanguages">;
|
|
91
|
+
type NavigationSite = Pick<Site, "title" | "icon" | "workspace" | "subformats" | "contentLanguage"> & {
|
|
92
|
+
entries: NavigationEntry[];
|
|
93
|
+
};
|
|
94
|
+
export interface PublishOutput {
|
|
95
|
+
asset: (source: string, extension: "html" | "js" | "css") => string;
|
|
96
|
+
graph?: string;
|
|
97
|
+
}
|
|
90
98
|
/**
|
|
91
99
|
* Boot data for the client (edit-client.ts) — the same shape is passed for the initial render and
|
|
92
100
|
* on doc switch. Insertion happens via the client's in-editor autocomplete (`/` palette), so the
|
|
@@ -177,7 +185,7 @@ export declare const createDocumentApplication: (root: string, host: Application
|
|
|
177
185
|
name: string;
|
|
178
186
|
abs: string;
|
|
179
187
|
} | undefined;
|
|
180
|
-
navGroupsHtml: (mode: ServeMode, site:
|
|
188
|
+
navGroupsHtml: (mode: ServeMode, site: NavigationSite, currentId?: string, currentRes?: string) => string;
|
|
181
189
|
textfilePreviewHtml: (site: Site, file: string, source: string) => string;
|
|
182
190
|
textfilePreviewErrors: (site: Site, file: string, source: string) => string[];
|
|
183
191
|
resourcesMain: (site: Site, rest: string) => {
|
|
@@ -185,7 +193,7 @@ export declare const createDocumentApplication: (root: string, host: Application
|
|
|
185
193
|
main: string;
|
|
186
194
|
sourceFile?: string;
|
|
187
195
|
} | undefined;
|
|
188
|
-
publishHtml: (site: Site, graphJs: string, title?: string, codeJs?: string, mode?: "static" | "network" | "live", pluginJs?: string, subformatJs?: string) => string;
|
|
196
|
+
publishHtml: (site: Site, graphJs: string, title?: string, codeJs?: string, mode?: "static" | "network" | "live", pluginJs?: string, subformatJs?: string, output?: PublishOutput) => string;
|
|
189
197
|
languageFieldHtml: (defaultLang: string, language?: string, translatedLanguages?: readonly string[], declaredLanguages?: readonly string[]) => string;
|
|
190
198
|
editorBoot: (entry: Entry, site: Site) => EditorBoot;
|
|
191
199
|
pageDataResponse: (site: Site, path: unknown) => {
|
|
@@ -207,3 +215,4 @@ export declare const createDocumentApplication: (root: string, host: Application
|
|
|
207
215
|
watch?: (files: Iterable<string>) => void;
|
|
208
216
|
}): void;
|
|
209
217
|
};
|
|
218
|
+
export {};
|