@dooc-dev/dooc 0.0.28 → 0.0.30

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 (88) hide show
  1. package/dist/client.global.js +1 -1
  2. package/dist/edit.global.js +220 -221
  3. package/dist/engine/compiler/check.js +5 -3
  4. package/dist/engine/compiler/compile.d.ts +5 -0
  5. package/dist/engine/compiler/compile.js +44 -23
  6. package/dist/engine/compiler/dialect.js +1 -1
  7. package/dist/engine/compiler/document-diff.d.ts +53 -0
  8. package/dist/engine/compiler/document-diff.js +92 -0
  9. package/dist/engine/compiler/export.js +11 -3
  10. package/dist/engine/compiler/files.d.ts +1 -0
  11. package/dist/engine/compiler/files.js +75 -14
  12. package/dist/engine/compiler/from-mdast.js +12 -1
  13. package/dist/engine/compiler/icons.d.ts +7 -7
  14. package/dist/engine/compiler/icons.js +35 -37
  15. package/dist/engine/compiler/manifest.d.ts +1 -0
  16. package/dist/engine/compiler/manifest.js +25 -0
  17. package/dist/engine/compiler/ops.d.ts +2 -2
  18. package/dist/engine/compiler/ops.js +55 -112
  19. package/dist/engine/compiler/resource-index.js +4 -4
  20. package/dist/engine/compiler/root-page.d.ts +13 -0
  21. package/dist/engine/compiler/root-page.js +96 -0
  22. package/dist/engine/compiler/sidebar-removal.d.ts +63 -0
  23. package/dist/engine/compiler/sidebar-removal.js +317 -0
  24. package/dist/engine/compiler/subformats.d.ts +3 -0
  25. package/dist/engine/compiler/subformats.js +126 -32
  26. package/dist/engine/core/blocks.d.ts +5 -0
  27. package/dist/engine/core/content-metadata.d.ts +9 -4
  28. package/dist/engine/core/content-metadata.js +100 -16
  29. package/dist/engine/core/file-embed.d.ts +2 -1
  30. package/dist/engine/core/file-embed.js +4 -0
  31. package/dist/engine/core/files.d.ts +1 -0
  32. package/dist/engine/core/files.js +6 -1
  33. package/dist/engine/core/format-collections.js +2 -2
  34. package/dist/engine/core/formats.d.ts +1 -1
  35. package/dist/engine/core/formats.js +1 -1
  36. package/dist/engine/core/html.d.ts +4 -1
  37. package/dist/engine/core/html.js +13 -6
  38. package/dist/engine/core/icons.d.ts +7 -0
  39. package/dist/engine/core/icons.js +38 -0
  40. package/dist/engine/core/subformats.d.ts +2 -1
  41. package/dist/engine/core/subformats.js +6 -1
  42. package/dist/engine/core/toc-library.d.ts +5 -0
  43. package/dist/engine/core/toc-library.js +27 -0
  44. package/dist/frontend/document-application.d.ts +5 -2
  45. package/dist/frontend/document-application.js +477 -189
  46. package/dist/frontend/edit-dialog.d.ts +1 -0
  47. package/dist/frontend/edit-dialog.js +12 -8
  48. package/dist/frontend/file-references.js +1 -1
  49. package/dist/frontend/locales/eng.json +63 -1
  50. package/dist/frontend/locales/jpn.json +63 -1
  51. package/dist/frontend/locales/zho.json +63 -1
  52. package/dist/frontend/page-jump.js +17 -10
  53. package/dist/frontend/resize.js +38 -12
  54. package/dist/frontend/resource-download.js +7 -1
  55. package/dist/frontend/resource-library.js +1 -0
  56. package/dist/frontend/search.js +2 -0
  57. package/dist/frontend/theme-picker.d.ts +2 -2
  58. package/dist/frontend/theme-picker.js +2 -2
  59. package/dist/frontend/toc-ui.js +13 -0
  60. package/dist/manifest.global.js +193 -192
  61. package/dist/mcp-relay.mjs +8 -4
  62. package/dist/plugins.global.js +49 -49
  63. package/dist/server/cli.js +12 -0
  64. package/dist/server/document-diff-cli.d.ts +1 -0
  65. package/dist/server/document-diff-cli.js +193 -0
  66. package/dist/server/document-diff-report.d.ts +3 -0
  67. package/dist/server/document-diff-report.js +124 -0
  68. package/dist/server/document-diff-sources.d.ts +40 -0
  69. package/dist/server/document-diff-sources.js +128 -0
  70. package/dist/server/document-versions.d.ts +3 -1
  71. package/dist/server/document-versions.js +19 -70
  72. package/dist/server/git-diff.d.ts +1 -0
  73. package/dist/server/git-diff.js +22 -2
  74. package/dist/server/git-document-snapshot.d.ts +2 -0
  75. package/dist/server/git-document-snapshot.js +63 -0
  76. package/dist/server/operation-log.js +2 -0
  77. package/dist/server/serve.d.ts +2 -2
  78. package/dist/server/serve.js +4 -9
  79. package/dist/server/workspace-server.js +6 -10
  80. package/dist/subformats.global.js +478 -74
  81. package/dist/ui.global.js +435 -80
  82. package/dist/workspace/file-operation.d.ts +10 -0
  83. package/dist/workspace/file-operation.js +47 -0
  84. package/dist/workspace/mcp-tools.js +8 -4
  85. package/dist/workspace/site-icon.js +30 -23
  86. package/dist/workspace/textfile.js +8 -8
  87. package/dist/workspace-worker.global.js +261 -202
  88. package/package.json +2 -2
@@ -1,4 +1,5 @@
1
1
  import type { SubformatCollection } from "../engine/core/subformats.js";
2
+ export declare function changedTrackedFiles(root: string): Promise<Set<string>>;
2
3
  /**
3
4
  * `revision` identifies the working tree contents (filesSnapshot); with it the status is reused
4
5
  * until the files, the index or HEAD change.
@@ -3,8 +3,28 @@ import { isDeepStrictEqual } from "node:util";
3
3
  import { parseDoc } from "../engine/compiler/dialect.js";
4
4
  import { manifestFile, parseManifestText } from "../engine/compiler/manifest.js";
5
5
  import { textfilePath } from "../engine/compiler/textfile.js";
6
- import { parseGitChanges } from "./git.js";
7
- import { gitSignature } from "./workspace.js";
6
+ import { git, parseGitChanges } from "./git.js";
7
+ import { gitHeadFile, gitSignature } from "./workspace.js";
8
+ export async function changedTrackedFiles(root) {
9
+ if (!gitHeadFile(root))
10
+ return new Set();
11
+ const head = (await git(root, ["rev-parse", "--revs-only", "HEAD"])).trim();
12
+ if (!head)
13
+ return new Set();
14
+ const paths = await git(root, [
15
+ "diff",
16
+ "--relative",
17
+ "--name-only",
18
+ "-z",
19
+ "--no-renames",
20
+ "--no-ext-diff",
21
+ "--diff-filter=MTU",
22
+ head,
23
+ "--",
24
+ ".",
25
+ ]);
26
+ return new Set(paths.split("\0").filter(Boolean));
27
+ }
8
28
  // Git answers are reused until the metadata they were read from changes (see gitSignature).
9
29
  const memo = new Map();
10
30
  const remember = (scope, signature, key, read) => {
@@ -0,0 +1,2 @@
1
+ /** Read exact blobs and modes. Git archives can omit or rewrite sources through .gitattributes. */
2
+ export declare const gitDocumentSnapshot: (root: string, manifest: string, revision: string, destination: string) => Promise<string>;
@@ -0,0 +1,63 @@
1
+ import { execFile } from "node:child_process";
2
+ import { mkdirSync, symlinkSync, writeFileSync } from "node:fs";
3
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
4
+ import { promisify } from "node:util";
5
+ import { projectRoot } from "../engine/compiler/manifest.js";
6
+ import { textfilePath } from "../engine/compiler/textfile.js";
7
+ import { git } from "./git.js";
8
+ /** Read exact blobs and modes. Git archives can omit or rewrite sources through .gitattributes. */
9
+ export const gitDocumentSnapshot = async (root, manifest, revision, destination) => {
10
+ if (!/^[a-f\d]{40}(?:[a-f\d]{24})?$/.test(revision))
11
+ throw new Error("Invalid document revision");
12
+ const tree = await git(root, ["ls-tree", "-rlz", revision, "--", "."]);
13
+ const entries = [];
14
+ let bytes = 0;
15
+ for (const record of tree.split("\0")) {
16
+ const tab = record.indexOf("\t");
17
+ const [mode, type, id, length] = record.slice(0, tab).split(/\s+/);
18
+ const name = record.slice(tab + 1);
19
+ // The tree contains tracked files only. Reapplying its ignore rules would hide tracked inputs.
20
+ if (type !== "blob" ||
21
+ !id ||
22
+ basename(name) === ".gitignore" ||
23
+ name.split("/").includes(".git"))
24
+ continue;
25
+ const size = Number(length);
26
+ bytes += size;
27
+ if (bytes > 256 * 1024 * 1024)
28
+ throw new Error("Historical document exceeds 256 MiB");
29
+ entries.push({ name, id, mode, size });
30
+ }
31
+ const batch = promisify(execFile)("git", ["-C", root, "cat-file", "--batch"], {
32
+ encoding: "buffer",
33
+ timeout: 30_000,
34
+ maxBuffer: bytes + entries.length * 128 + 1024,
35
+ });
36
+ batch.child.stdin?.on("error", () => {
37
+ /* execFile reports process failures. */
38
+ });
39
+ batch.child.stdin?.end(entries.map((entry) => entry.id).join("\n") + (entries.length ? "\n" : ""));
40
+ const { stdout } = await batch;
41
+ mkdirSync(destination, { recursive: true });
42
+ let offset = 0;
43
+ for (const { name, id, mode, size } of entries) {
44
+ const end = stdout.indexOf(10, offset);
45
+ if (stdout.toString("ascii", offset, end) !== `${id} blob ${size}` ||
46
+ stdout[end + size + 1] !== 10)
47
+ throw new Error(`Incomplete historical blob: ${name}`);
48
+ const data = stdout.subarray(end + 1, end + 1 + size);
49
+ offset = end + size + 2;
50
+ const path = textfilePath(destination, name);
51
+ mkdirSync(dirname(path), { recursive: true });
52
+ if (mode === "120000") {
53
+ const target = data.toString("utf8");
54
+ const rel = relative(destination, resolve(dirname(path), target));
55
+ if (isAbsolute(target) || rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel))
56
+ throw new Error("Historical symlink points outside the document root");
57
+ symlinkSync(target, path);
58
+ }
59
+ else
60
+ writeFileSync(path, data, { mode: mode === "100755" ? 0o755 : 0o644 });
61
+ }
62
+ return projectRoot(join(destination, manifest));
63
+ };
@@ -26,6 +26,8 @@ export const loggedWorkspaceOps = (ops) => Object.fromEntries(Object.entries(ops
26
26
  "read",
27
27
  "list",
28
28
  "complete",
29
+ "hashes",
30
+ "icon-preview",
29
31
  "diff",
30
32
  "prFiles",
31
33
  "branches",
@@ -3,7 +3,7 @@ import { type ServeMode } from "../frontend/document-application.js";
3
3
  import { type ReaderRuntime } from "./plugin-config.js";
4
4
  export type { EditorBoot, Entry, ServeMode, Site, } from "../frontend/document-application.js";
5
5
  export { assembleDoc };
6
- export declare const clientShell: (readOnly?: boolean) => string, siteFrom: ({ title, icon, iconVariants, docs, terms, figures, sources, siteErrors, defaultLang, previews, contentLanguages, themes, subformats, }: import("../engine/compiler/compile.js").Compiled, languages?: readonly import("./index.js").LanguageAdapter[], code?: Pick<import("./languages.js").SiteLanguages, "codeLanguages" | "codeGrammars">) => import("../frontend/document-application.js").Site, filePreviewResults: (entry: import("../frontend/document-application.js").Entry, site: import("../frontend/document-application.js").Site) => import("../frontend/file-references.js").FilePreviewResults, renderEntryHtml: (site: import("../frontend/document-application.js").Site, entry: import("../frontend/document-application.js").Entry) => {
6
+ export declare const clientShell: (readOnly?: boolean) => string, siteFrom: ({ title, icon, iconVariants, accentColor, docs, terms, figures, sources, siteErrors, defaultLang, previews, contentLanguages, themes, subformats, }: import("../engine/compiler/compile.js").Compiled, languages?: readonly import("./index.js").LanguageAdapter[], code?: Pick<import("./languages.js").SiteLanguages, "codeLanguages" | "codeGrammars">) => import("../frontend/document-application.js").Site, filePreviewResults: (entry: import("../frontend/document-application.js").Entry, site: import("../frontend/document-application.js").Site) => import("../frontend/file-references.js").FilePreviewResults, renderEntryHtml: (site: import("../frontend/document-application.js").Site, entry: import("../frontend/document-application.js").Entry) => {
7
7
  html: string;
8
8
  errors: string[];
9
9
  }, renderDocFile: (site: import("../frontend/document-application.js").Site, file: string, raw: string) => {
@@ -26,7 +26,7 @@ export declare const clientShell: (readOnly?: boolean) => string, siteFrom: ({ t
26
26
  id: string;
27
27
  name: string;
28
28
  abs: string;
29
- } | undefined, navGroupsHtml: (mode: ServeMode, site: Pick<import("../frontend/document-application.js").Site, "title" | "icon" | "themes" | "subformats" | "workspace" | "contentLanguage"> & {
29
+ } | undefined, navGroupsHtml: (mode: ServeMode, site: Pick<import("../frontend/document-application.js").Site, "uploadDirectory" | "title" | "icon" | "themes" | "accentColor" | "subformats" | "iconVariants" | "workspace" | "contentLanguage"> & {
30
30
  entries: {
31
31
  id: string;
32
32
  file: string;
@@ -1,5 +1,5 @@
1
- import { completeFilePaths, filesSnapshot, updateFiles, uploadFile, } from "../engine/compiler/files.js";
2
1
  import { MAX_FILE_UPLOAD_BYTES } from "../engine/core/files.js";
2
+ import { fileOperation } from "../workspace/file-operation.js";
3
3
  // Combined Node reader: serves frontend assets and the shared document application.
4
4
  // Workspace requests and change notifications travel over a same-origin WebSocket.
5
5
  import { spawn } from "node:child_process";
@@ -25,7 +25,7 @@ import { createExtensionManager } from "./extensions.js";
25
25
  import { fontCss, readFont } from "./fonts.js";
26
26
  import { frameBlocked } from "./frame-policy.js";
27
27
  import { createGitHandler, validateGitOrigin } from "./git.js";
28
- import { gitBaseBody, gitBaseText, setSubformatChanges } from "./git-diff.js";
28
+ import { changedTrackedFiles, gitBaseBody, gitBaseText, setSubformatChanges } from "./git-diff.js";
29
29
  import { workspaceHistory } from "./history.js";
30
30
  import { watchProject } from "./hmr.js";
31
31
  import { loadSiteLanguages } from "./languages.js";
@@ -51,6 +51,7 @@ const application = createDocumentApplication(root, {
51
51
  sourceFileBase,
52
52
  gitBaseBody,
53
53
  gitBaseText,
54
+ changedTrackedFiles,
54
55
  setSubformatChanges,
55
56
  runCodeTool,
56
57
  validateCodeTools,
@@ -163,13 +164,7 @@ export const startServer = async (mode, port = 5179, pluginModule, startup) => {
163
164
  session.user = parsePerson(input);
164
165
  return session.user;
165
166
  },
166
- files: (input) => input.action === "complete"
167
- ? completeFilePaths(root, input.prefix)
168
- : input.action === "read"
169
- ? filesSnapshot(root)
170
- : input.action === "upload"
171
- ? uploadFile(root, input)
172
- : updateFiles(root, input),
167
+ files: (input) => fileOperation(root, input),
173
168
  git: async (input, session) => {
174
169
  if (!session.local)
175
170
  throw new Error("Git requires a same-origin local editor request");
@@ -2,7 +2,6 @@ import { createHash } from "node:crypto";
2
2
  import { existsSync, mkdirSync } from "node:fs";
3
3
  import { basename, dirname, join, resolve } from "node:path";
4
4
  import { WebSocketServer } from "ws";
5
- import { completeFilePaths, filesSnapshot, updateFiles, uploadFile, } from "../engine/compiler/files.js";
6
5
  import { manifestFile, projectRoot, readManifest, sectionManifest, } from "../engine/compiler/manifest.js";
7
6
  import { flattenTree } from "../engine/core/content-metadata.js";
8
7
  import { latestVersionOnly, parseVersionSelection, selectVersions, } from "../engine/core/document-version.js";
@@ -12,6 +11,7 @@ import { docPath } from "../engine/core/routing.js";
12
11
  import { parseWorkspaceSource } from "../engine/core/workspace.js";
13
12
  import { applicationRequest, } from "../frontend/application-request.js";
14
13
  import { createDocumentApplication } from "../frontend/document-application.js";
14
+ import { fileOperation } from "../workspace/file-operation.js";
15
15
  import { createHistoryOp, parsePerson } from "../workspace/history.js";
16
16
  import { assertReadOnlyOperation } from "../workspace/read-only.js";
17
17
  import { createWorkspaceServer } from "../workspace/server.js";
@@ -21,7 +21,7 @@ import { createExtensionManager } from "./extensions.js";
21
21
  import { fontCss } from "./fonts.js";
22
22
  import { frameBlocked } from "./frame-policy.js";
23
23
  import { createGitHandler, git, gitManifestPath, gitWorktrees, hasGitManifest, validateGitOrigin, } from "./git.js";
24
- import { gitBaseBody, gitBaseText, setSubformatChanges } from "./git-diff.js";
24
+ import { changedTrackedFiles, gitBaseBody, gitBaseText, setSubformatChanges } from "./git-diff.js";
25
25
  import { workspaceHistory } from "./history.js";
26
26
  import { watchProject } from "./hmr.js";
27
27
  import { DEFAULT_SITE_LANGUAGES, loadSiteLanguages } from "./languages.js";
@@ -97,6 +97,7 @@ export const nodeWorkspaceOperations = async (manifest, pluginModule, notify = (
97
97
  sourceFileBase,
98
98
  gitBaseBody,
99
99
  gitBaseText,
100
+ changedTrackedFiles,
100
101
  setSubformatChanges,
101
102
  runCodeTool,
102
103
  validateCodeTools,
@@ -305,13 +306,7 @@ export const nodeWorkspaceOperations = async (manifest, pluginModule, notify = (
305
306
  },
306
307
  files: (input) => {
307
308
  const { root } = entry(input);
308
- return input.action === "read"
309
- ? filesSnapshot(root)
310
- : input.action === "complete"
311
- ? completeFilePaths(root, input.prefix)
312
- : input.action === "upload"
313
- ? uploadFile(root, input)
314
- : updateFiles(root, input);
309
+ return fileOperation(root, input);
315
310
  },
316
311
  git: (input, session) => {
317
312
  if (!session.local)
@@ -382,7 +377,8 @@ export const nodeWorkspaceOperations = async (manifest, pluginModule, notify = (
382
377
  return operation({ ...input, workspace: target.description.id }, session, signal);
383
378
  };
384
379
  const reading = (name === "http" && input.method === "GET") ||
385
- (name === "files" && ["read", "complete"].includes(String(input.action))) ||
380
+ (name === "files" &&
381
+ ["read", "complete", "hashes", "icon-preview"].includes(String(input.action))) ||
386
382
  (name === "git" &&
387
383
  ["read", "branches", "diff", "prFiles"].includes(String(input.action)));
388
384
  const active = reads.get(id) ?? new Set();