@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.
Files changed (65) hide show
  1. package/dist/client.global.js +1 -1
  2. package/dist/edit.global.js +269 -263
  3. package/dist/engine/compiler/check.js +17 -0
  4. package/dist/engine/compiler/export.js +18 -1
  5. package/dist/engine/compiler/files.js +13 -2
  6. package/dist/engine/compiler/manifest.js +4 -0
  7. package/dist/engine/compiler/skills.d.ts +10 -0
  8. package/dist/engine/compiler/skills.js +95 -0
  9. package/dist/engine/core/content-metadata.d.ts +7 -1
  10. package/dist/engine/core/content-metadata.js +52 -18
  11. package/dist/engine/core/files.d.ts +1 -0
  12. package/dist/engine/core/files.js +3 -0
  13. package/dist/frontend/document-application.d.ts +11 -2
  14. package/dist/frontend/document-application.js +356 -130
  15. package/dist/frontend/language-picker.js +1 -0
  16. package/dist/frontend/locales/eng.json +17 -1
  17. package/dist/frontend/locales/jpn.json +17 -1
  18. package/dist/frontend/locales/zho.json +17 -1
  19. package/dist/frontend/mcp-operations.js +57 -1
  20. package/dist/frontend/nav-focus.d.ts +1 -1
  21. package/dist/frontend/nav-focus.js +25 -2
  22. package/dist/frontend/nav-update.js +12 -0
  23. package/dist/frontend/page-jump.d.ts +3 -0
  24. package/dist/frontend/page-jump.js +130 -0
  25. package/dist/frontend/resource-download.d.ts +1 -1
  26. package/dist/frontend/resource-download.js +118 -28
  27. package/dist/frontend/resource-library.js +16 -7
  28. package/dist/frontend/search.js +18 -5
  29. package/dist/frontend/theme-picker.js +11 -0
  30. package/dist/manifest.global.js +349 -0
  31. package/dist/mcp-relay.mjs +71 -1
  32. package/dist/plugins.global.js +4 -4
  33. package/dist/server/assets.d.ts +1 -0
  34. package/dist/server/assets.js +4 -1
  35. package/dist/server/build-media.d.ts +6 -0
  36. package/dist/server/build-media.js +136 -0
  37. package/dist/server/build-output.d.ts +2 -1
  38. package/dist/server/build-output.js +32 -2
  39. package/dist/server/build-split.d.ts +15 -0
  40. package/dist/server/build-split.js +160 -0
  41. package/dist/server/build.d.ts +6 -1
  42. package/dist/server/build.js +37 -10
  43. package/dist/server/cli.js +20 -2
  44. package/dist/server/mcp.js +14 -1
  45. package/dist/server/serve.d.ts +21 -2
  46. package/dist/server/serve.js +26 -20
  47. package/dist/server/static-client.js +2 -1
  48. package/dist/server/workspace-server.d.ts +1 -1
  49. package/dist/server/workspace-server.js +24 -4
  50. package/dist/subformats.global.js +38 -38
  51. package/dist/ui.global.js +68 -68
  52. package/dist/workspace/client.d.ts +1 -1
  53. package/dist/workspace/client.js +22 -3
  54. package/dist/workspace/mcp-tools.js +32 -0
  55. package/dist/workspace/mcp.js +50 -1
  56. package/dist/workspace/protocol.d.ts +3 -0
  57. package/dist/workspace/server.d.ts +1 -1
  58. package/dist/workspace/server.js +14 -3
  59. package/dist/workspace/site-icon.js +17 -12
  60. package/dist/workspace/textfile.js +16 -4
  61. package/dist/workspace-mcp-worker.global.js +234 -119
  62. package/dist/workspace-reader-mcp-worker.global.js +234 -119
  63. package/dist/workspace-reader-worker.global.js +234 -119
  64. package/dist/workspace-worker.global.js +234 -119
  65. package/package.json +2 -2
@@ -1,6 +1,6 @@
1
1
  import { type WorkspacePort } from "./protocol.js";
2
2
  export interface WorkspaceClient {
3
- request<T = unknown>(op: string, args?: Record<string, unknown>): Promise<T>;
3
+ request<T = unknown>(op: string, args?: Record<string, unknown>, signal?: AbortSignal): Promise<T>;
4
4
  /** Returns the function that stops listening. */
5
5
  on(event: string, handler: (data: unknown) => void): () => void;
6
6
  /** Runs on every (re)connection; right away on a channel that is always connected. */
@@ -19,25 +19,44 @@ export const createWorkspaceClient = (port) => {
19
19
  if (!request)
20
20
  return;
21
21
  pending.delete(id);
22
+ request.cleanup();
22
23
  if (typeof error === "string")
23
24
  request.reject(new Error(error));
24
25
  else
25
26
  request.resolve(value);
26
27
  });
27
28
  port.closed?.(() => {
28
- for (const request of pending.values())
29
+ for (const request of pending.values()) {
30
+ request.cleanup();
29
31
  request.reject(new Error("Workspace connection closed"));
32
+ }
30
33
  pending.clear();
31
34
  });
32
35
  return {
33
- request: (op, args) => new Promise((resolve, reject) => {
36
+ request: (op, args, signal) => new Promise((resolve, reject) => {
37
+ if (signal?.aborted)
38
+ return reject(signal.reason);
34
39
  const id = ++next;
35
- pending.set(id, { resolve: resolve, reject });
40
+ const cleanup = () => signal?.removeEventListener("abort", abort);
41
+ const abort = () => {
42
+ pending.delete(id);
43
+ cleanup();
44
+ reject(signal?.reason);
45
+ try {
46
+ port.send({ cancel: id });
47
+ }
48
+ catch {
49
+ // A closed connection has already discarded the request.
50
+ }
51
+ };
52
+ pending.set(id, { resolve: resolve, reject, cleanup });
53
+ signal?.addEventListener("abort", abort, { once: true });
36
54
  try {
37
55
  port.send({ id, op, args });
38
56
  }
39
57
  catch (error) {
40
58
  pending.delete(id);
59
+ cleanup();
41
60
  reject(error instanceof Error ? error : new Error(String(error)));
42
61
  }
43
62
  }),
@@ -4,6 +4,17 @@ const num = { type: "integer", minimum: 0 };
4
4
  const bool = { type: "boolean" };
5
5
  const strings = { type: "array", items: str };
6
6
  const definitions = {
7
+ skills: {
8
+ description: "Discover project-authored workflows for applying dooc content as checklists, development conventions or other guidance. list returns skill metadata and file URIs; get returns one skill's metadata; read retrieves its instructions or supporting files. Use document tools to read the project information those instructions reference. Skill files are returned as content, never executed.",
9
+ props: {
10
+ action: { ...str, enum: ["list", "get", "read"] },
11
+ uri: {
12
+ ...str,
13
+ description: "Exact skill:// URI from list; required for get and read.",
14
+ },
15
+ },
16
+ required: ["action"],
17
+ },
7
18
  export: {
8
19
  description: "Collect dooc.yaml and its source dependencies into dist/bundle.zip, without executing plugins or fetching remote data.",
9
20
  props: {},
@@ -25,6 +36,26 @@ const definitions = {
25
36
  ...str,
26
37
  description: "Public source directory URL for card copy links in HTML, relative to dooc.yaml.",
27
38
  },
39
+ split: {
40
+ ...bool,
41
+ description: "HTML only: emit separate pages, JS, CSS and resources; serve over HTTP(S).",
42
+ },
43
+ compress: {
44
+ ...bool,
45
+ description: "HTML only: optimize previews with FFmpeg (lossy JPEG/WebP/video); implies split. Original source downloads are preserved.",
46
+ },
47
+ max_file_size: {
48
+ ...str,
49
+ description: "Maximum bytes per output file, e.g. 25MiB; implies split. No limit by default.",
50
+ },
51
+ max_build_size: {
52
+ ...str,
53
+ description: "Maximum total output bytes, e.g. 100MiB; implies split. No limit by default.",
54
+ },
55
+ warnings_as_errors: {
56
+ ...bool,
57
+ description: "Fail when requested compression is unsupported or unavailable.",
58
+ },
28
59
  },
29
60
  required: ["format"],
30
61
  },
@@ -217,6 +248,7 @@ const definitions = {
217
248
  },
218
249
  };
219
250
  const readTools = new Set([
251
+ "skills",
220
252
  "list_docs",
221
253
  "search_docs",
222
254
  "read_doc",
@@ -58,11 +58,60 @@ export const handleRpc = async (tools, msg, versions = ["2024-11-05", ...MCP_HTT
58
58
  protocolVersion: versions.includes(String(params.protocolVersion))
59
59
  ? params.protocolVersion
60
60
  : "2025-11-25",
61
- capabilities: { tools: {} },
61
+ capabilities: {
62
+ tools: {},
63
+ ...(Object.hasOwn(tools, "skills")
64
+ ? { resources: {}, extensions: { "io.modelcontextprotocol/skills": {} } }
65
+ : {}),
66
+ },
62
67
  serverInfo: { name: "dooc", version: "0" },
63
68
  });
64
69
  case "ping":
65
70
  return reply({});
71
+ case "skills/list":
72
+ case "skills/get":
73
+ case "resources/list":
74
+ case "resources/templates/list":
75
+ case "resources/read": {
76
+ if (!Object.hasOwn(tools, "skills"))
77
+ return error(-32601, "method not found");
78
+ if (params.cursor !== undefined)
79
+ return error(-32602, "unknown cursor");
80
+ if (msg.method === "resources/templates/list")
81
+ return reply({ resourceTemplates: [] });
82
+ const action = msg.method === "skills/get"
83
+ ? "get"
84
+ : msg.method === "resources/read"
85
+ ? "read"
86
+ : "list";
87
+ if (action !== "list" && (typeof params.uri !== "string" || !params.uri))
88
+ return error(-32602, "a resource URI is required");
89
+ try {
90
+ const result = await callMcpTool(tools, "skills", {
91
+ action,
92
+ ...(action === "list" ? {} : { uri: params.uri }),
93
+ });
94
+ if (!record(result))
95
+ return error(-32603, "invalid skill response");
96
+ if (typeof result.error === "string")
97
+ return error(result.status === 404 ? -32602 : -32603, result.error);
98
+ if (msg.method === "resources/list") {
99
+ const skills = result.skills;
100
+ return reply({
101
+ resources: skills.map((skill) => ({
102
+ uri: skill.uri,
103
+ name: skill.frontmatter.name,
104
+ description: skill.frontmatter.description,
105
+ mimeType: "text/markdown",
106
+ })),
107
+ });
108
+ }
109
+ return reply(result);
110
+ }
111
+ catch (e) {
112
+ return error(-32603, e instanceof Error ? e.message : String(e));
113
+ }
114
+ }
66
115
  case "tools/list":
67
116
  return reply({
68
117
  tools: Object.entries(tools).map(([name, t]) => ({
@@ -5,6 +5,9 @@ export interface WorkspaceRequest {
5
5
  op: string;
6
6
  args?: Record<string, unknown>;
7
7
  }
8
+ export interface WorkspaceCancel {
9
+ cancel: number;
10
+ }
8
11
  export type WorkspaceResponse = {
9
12
  id: number;
10
13
  value: unknown;
@@ -1,6 +1,6 @@
1
1
  import { type WorkspaceHello, type WorkspacePort } from "./protocol.js";
2
2
  /** `session` is whatever the host attached to the connection (who is asking, how far to trust). */
3
- export type WorkspaceOps<Session> = Record<string, (args: Record<string, unknown>, session: Session) => unknown>;
3
+ export type WorkspaceOps<Session> = Record<string, (args: Record<string, unknown>, session: Session, signal?: AbortSignal) => unknown>;
4
4
  export interface WorkspaceServer<Session> {
5
5
  /** Returns the function that detaches the port. */
6
6
  connect(port: WorkspacePort, session: Session): () => void;
@@ -11,15 +11,23 @@ export const createWorkspaceServer = (ops, info = {}) => {
11
11
  return {
12
12
  connect(port, session) {
13
13
  ports.add(port);
14
+ const requests = new Map();
14
15
  port.receive((message) => {
15
16
  if (!ports.has(port) || typeof message !== "object" || message === null)
16
17
  return;
17
- const { id, op, args } = message;
18
+ const { id, op, args, cancel } = message;
19
+ if (typeof cancel === "number") {
20
+ requests.get(cancel)?.abort();
21
+ return;
22
+ }
18
23
  // Without an id there is nothing to answer.
19
24
  if (typeof id !== "number")
20
25
  return;
26
+ const controller = new AbortController();
27
+ requests.set(id, controller);
21
28
  const reply = (response) => {
22
- if (ports.has(port))
29
+ requests.delete(id);
30
+ if (ports.has(port) && !controller.signal.aborted)
23
31
  port.send(response);
24
32
  };
25
33
  void (async () => {
@@ -29,7 +37,7 @@ export const createWorkspaceServer = (ops, info = {}) => {
29
37
  throw new Error(`Unknown workspace operation: ${String(op)}`);
30
38
  return ops[op]?.(typeof args === "object" && args !== null && !Array.isArray(args)
31
39
  ? args
32
- : {}, session);
40
+ : {}, session, controller.signal);
33
41
  })().then((value) => reply({ id, value }), (error) => reply({
34
42
  id,
35
43
  error: error instanceof Error ? error.message : String(error),
@@ -37,6 +45,9 @@ export const createWorkspaceServer = (ops, info = {}) => {
37
45
  });
38
46
  return () => {
39
47
  ports.delete(port);
48
+ for (const controller of requests.values())
49
+ controller.abort();
50
+ requests.clear();
40
51
  };
41
52
  },
42
53
  broadcast(event, data) {
@@ -3,6 +3,7 @@ import { existsSync } from "../engine/compiler/host.js";
3
3
  import { ICONS_DIR, squareSvg } from "../engine/compiler/icons.js";
4
4
  import { manifestFile, parseManifestText } from "../engine/compiler/manifest.js";
5
5
  import { readTextfile, textfilePath, writeTextfile } from "../engine/compiler/textfile.js";
6
+ import { migrateDocumentIcon } from "../engine/core/content-metadata.js";
6
7
  import { defaultFilePath } from "../engine/core/files.js";
7
8
  export const siteIconResponse = (root, input) => {
8
9
  const svg = typeof input?.data === "string"
@@ -23,11 +24,16 @@ export const siteIconResponse = (root, input) => {
23
24
  const theme = input?.theme ?? "light";
24
25
  if (theme !== "light" && theme !== "dark")
25
26
  throw new Error("Expected a light or dark theme");
26
- const file = (manifest.format !== undefined ? manifest.themeIcons?.[theme] : manifest.icon) ??
27
+ const configured = manifest.format !== undefined
28
+ ? (manifest.themeIcons?.[theme] ??
29
+ (manifest.format === "document" && !manifest.themeIcons
30
+ ? manifest.icon
31
+ : undefined))
32
+ : manifest.icon;
33
+ const file = configured ??
27
34
  (manifest.files?.defaultLayout !== false
28
35
  ? defaultFilePath(manifest.format !== undefined ? `_site-${theme}.svg` : "_site.svg")
29
36
  : `${ICONS_DIR}/_site${manifest.format !== undefined ? `-${theme}` : ""}.svg`);
30
- const configured = manifest.format !== undefined ? manifest.themeIcons?.[theme] : manifest.icon;
31
37
  if (!configured && existsSync(textfilePath(root, file)))
32
38
  return {
33
39
  status: 409,
@@ -36,20 +42,19 @@ export const siteIconResponse = (root, input) => {
36
42
  const base = existsSync(textfilePath(root, file)) ? readTextfile(root, file) : null;
37
43
  if (!writeTextfile(root, file, svg, base))
38
44
  return { status: 409, body: { error: "Icon changed externally. Try again." } };
39
- if (!configured) {
40
- const parsed = parseDocument(raw ?? "docs: []\n");
41
- const document = isSeq(parsed.contents) || parsed.contents == null
42
- ? new Document({ docs: parsed.toJS() ?? [] })
43
- : parsed;
44
- if (manifest.format !== undefined)
45
+ const parsed = parseDocument(raw ?? "docs: []\n");
46
+ const document = isSeq(parsed.contents) || parsed.contents == null
47
+ ? new Document({ docs: parsed.toJS() ?? [] })
48
+ : parsed;
49
+ const migrated = migrateDocumentIcon(document);
50
+ if (!configured || migrated) {
51
+ if (!configured && manifest.format !== undefined)
45
52
  document.setIn([
46
- ...(manifest.format === "document"
47
- ? ["document", "sidebar"]
48
- : ["left_sidebar"]),
53
+ ...(manifest.format === "document" ? ["document"] : ["left_sidebar"]),
49
54
  "icon",
50
55
  theme,
51
56
  ], file);
52
- else
57
+ else if (!configured)
53
58
  document.set("icon", file);
54
59
  if (!writeTextfile(root, manifestFile(root), document.toString(), raw))
55
60
  return { status: 409, body: { error: "Manifest changed externally. Try again." } };
@@ -1,7 +1,9 @@
1
- import { readManifest } from "../engine/compiler/manifest.js";
1
+ import { parseDocument } from "yaml";
2
+ import { parseManifestText, readManifest } from "../engine/compiler/manifest.js";
2
3
  import { compileSubformatSchema, isSubformatSchemaFile, validateSubformatFile, } from "../engine/compiler/subformats.js";
3
4
  import { readTextfile, readTextfileAsync, textfilePath, writeTextfile, } from "../engine/compiler/textfile.js";
4
5
  import { TextfileUnavailable } from "../engine/compiler/textfile-remote.js";
6
+ import { isManifestFile, migrateDocumentIcon } from "../engine/core/content-metadata.js";
5
7
  import { isRemoteTextfile } from "../engine/core/textfile.js";
6
8
  export const previewTextfiles = (root, input) => {
7
9
  if (input === undefined)
@@ -27,13 +29,23 @@ export const textfileResponse = async (root, input, domains = []) => {
27
29
  if (typeof input.content !== "string" ||
28
30
  (input.base !== null && typeof input.base !== "string"))
29
31
  return { status: 400, body: { error: "Content and original text are required" } };
30
- validateSubformatFile(root, input.file, input.content, domains);
31
- if (!writeTextfile(root, input.file, input.content, input.base))
32
+ let content = input.content;
33
+ if (isManifestFile(input.file.split("/").at(-1) ?? "")) {
34
+ const { errors } = parseManifestText(content, input.file);
35
+ if (errors.length)
36
+ throw new Error(errors.join("\n"));
37
+ const document = parseDocument(content);
38
+ if (migrateDocumentIcon(document))
39
+ content = document.toString({ lineWidth: 0 });
40
+ }
41
+ else
42
+ validateSubformatFile(root, input.file, content, domains);
43
+ if (!writeTextfile(root, input.file, content, input.base))
32
44
  return {
33
45
  status: 409,
34
46
  body: { error: "File changed externally. Reload it before saving." },
35
47
  };
36
- return { status: 200, body: { content: input.content } };
48
+ return { status: 200, body: { content } };
37
49
  }
38
50
  const configs = isRemoteTextfile(input.file) ? [] : (readManifest(root).subformats ?? []);
39
51
  const extension = input.file.split(".").at(-1);