@dooc-dev/dooc 0.0.7 → 0.0.8

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 (302) hide show
  1. package/dist/client.global.js +1 -0
  2. package/dist/code-worker.global.js +11 -11
  3. package/dist/code.global.js +75 -75
  4. package/dist/edit.global.js +234 -231
  5. package/dist/{compiler → engine/compiler}/bundle-urls.js +1 -4
  6. package/dist/{compiler → engine/compiler}/check-prose.d.ts +1 -1
  7. package/dist/{compiler → engine/compiler}/check-prose.js +1 -1
  8. package/dist/{compiler → engine/compiler}/check.js +15 -27
  9. package/dist/{compiler → engine/compiler}/code-blocks.js +3 -1
  10. package/dist/{compiler → engine/compiler}/code-languages.js +1 -2
  11. package/dist/{compiler → engine/compiler}/compile.d.ts +5 -4
  12. package/dist/{compiler → engine/compiler}/compile.js +91 -32
  13. package/dist/{compiler → engine/compiler}/config.js +1 -3
  14. package/dist/{compiler → engine/compiler}/dialect.d.ts +1 -3
  15. package/dist/{compiler → engine/compiler}/dialect.js +8 -52
  16. package/dist/{compiler → engine/compiler}/dxf.js +1 -1
  17. package/dist/{compiler → engine/compiler}/export.js +15 -8
  18. package/dist/{compiler → engine/compiler}/figures.js +26 -22
  19. package/dist/{compiler → engine/compiler}/file-cache.d.ts +1 -2
  20. package/dist/{compiler → engine/compiler}/file-cache.js +8 -15
  21. package/dist/{compiler → engine/compiler}/files.js +49 -38
  22. package/dist/{compiler → engine/compiler}/fonts.js +1 -3
  23. package/dist/{compiler → engine/compiler}/from-mdast.js +1 -1
  24. package/dist/engine/compiler/host.d.ts +10 -0
  25. package/dist/engine/compiler/host.js +16 -0
  26. package/dist/{compiler → engine/compiler}/icons.d.ts +3 -0
  27. package/dist/{compiler → engine/compiler}/icons.js +28 -10
  28. package/dist/{compiler → engine/compiler}/ignored-files.d.ts +2 -0
  29. package/dist/{compiler → engine/compiler}/ignored-files.js +12 -3
  30. package/dist/{compiler → engine/compiler}/locales.js +2 -8
  31. package/dist/{compiler → engine/compiler}/manifest.d.ts +3 -2
  32. package/dist/engine/compiler/manifest.js +46 -0
  33. package/dist/{compiler → engine/compiler}/ops.d.ts +4 -1
  34. package/dist/{compiler → engine/compiler}/ops.js +36 -21
  35. package/dist/engine/compiler/schema-file-references.d.ts +2 -0
  36. package/dist/engine/compiler/schema-file-references.js +82 -0
  37. package/dist/engine/compiler/serialize.d.ts +2 -0
  38. package/dist/engine/compiler/serialize.js +5 -0
  39. package/dist/{compiler → engine/compiler}/subformat-schema.js +1 -3
  40. package/dist/{compiler → engine/compiler}/subformats.d.ts +10 -0
  41. package/dist/{compiler → engine/compiler}/subformats.js +122 -18
  42. package/dist/{compiler → engine/compiler}/textfile-remote.js +1 -2
  43. package/dist/{compiler → engine/compiler}/textfile.js +4 -6
  44. package/dist/{compiler → engine/compiler}/theme-variants.js +1 -1
  45. package/dist/{compiler → engine/compiler}/zip.js +1 -1
  46. package/dist/{core → engine/core}/blocks.d.ts +6 -4
  47. package/dist/{core → engine/core}/content-metadata.d.ts +6 -1
  48. package/dist/{core → engine/core}/content-metadata.js +84 -18
  49. package/dist/{core → engine/core}/content-types.d.ts +4 -2
  50. package/dist/{core → engine/core}/html.d.ts +7 -0
  51. package/dist/{core → engine/core}/html.js +44 -3
  52. package/dist/{core → engine/core}/icons.d.ts +3 -0
  53. package/dist/engine/core/icons.js +20 -0
  54. package/dist/{core → engine/core}/routing.d.ts +2 -0
  55. package/dist/{core → engine/core}/routing.js +9 -0
  56. package/dist/{core → engine/core}/schema-refs.d.ts +1 -1
  57. package/dist/{core → engine/core}/schema-refs.js +3 -1
  58. package/dist/engine/core/subformat-references.d.ts +5 -0
  59. package/dist/engine/core/subformat-references.js +33 -0
  60. package/dist/{core → engine/core}/subformats.d.ts +7 -0
  61. package/dist/{core → engine/core}/subformats.js +5 -1
  62. package/dist/{core → engine/core}/taxonomy.d.ts +2 -3
  63. package/dist/{core → engine/core}/taxonomy.js +1 -5
  64. package/dist/flow.global.js +306 -306
  65. package/dist/frontend/application-request.d.ts +14 -0
  66. package/dist/frontend/application-request.js +36 -0
  67. package/dist/frontend/document-application.d.ts +200 -0
  68. package/dist/{viewer/serve.js → frontend/document-application.js} +1611 -1670
  69. package/dist/frontend/figure-preview.d.ts +4 -0
  70. package/dist/{viewer → frontend}/figure-preview.js +4 -4
  71. package/dist/{viewer → frontend}/file-references.d.ts +1 -1
  72. package/dist/{viewer → frontend}/file-references.js +3 -3
  73. package/dist/{viewer → frontend}/font-picker.d.ts +1 -1
  74. package/dist/{viewer → frontend}/font-settings.d.ts +1 -1
  75. package/dist/{viewer → frontend}/language-picker.js +112 -18
  76. package/dist/{viewer → frontend}/locales/eng.json +16 -2
  77. package/dist/{viewer → frontend}/locales/jpn.json +16 -2
  78. package/dist/{viewer → frontend}/locales/zho.json +16 -2
  79. package/dist/{viewer → frontend}/nav-focus.js +2 -0
  80. package/dist/{viewer → frontend}/plugin-blocks.js +2 -2
  81. package/dist/{viewer → frontend}/resize.js +14 -2
  82. package/dist/frontend/resource-download.d.ts +2 -0
  83. package/dist/frontend/resource-download.js +43 -0
  84. package/dist/{viewer → frontend}/resource-library.d.ts +9 -2
  85. package/dist/{viewer → frontend}/resource-library.js +133 -37
  86. package/dist/{core → frontend}/schema-graph-flow.d.ts +1 -1
  87. package/dist/{core → frontend}/schema-graph-flow.js +1 -1
  88. package/dist/{viewer → frontend}/search.d.ts +2 -2
  89. package/dist/{viewer → frontend}/search.js +26 -8
  90. package/dist/graph/schema-graph-global.js +17 -17
  91. package/dist/install.sh +68 -0
  92. package/dist/plugins.global.js +62 -62
  93. package/dist/{viewer → server}/assets.d.ts +2 -0
  94. package/dist/server/assets.js +7 -0
  95. package/dist/{viewer → server}/build-plugins.js +4 -4
  96. package/dist/{viewer → server}/build.d.ts +2 -1
  97. package/dist/{viewer → server}/build.js +31 -15
  98. package/dist/{cli.js → server/cli.js} +199 -66
  99. package/dist/server/editor-tools.d.ts +1 -0
  100. package/dist/server/editor-tools.js +1 -0
  101. package/dist/{viewer → server}/extension-pack.js +2 -2
  102. package/dist/{viewer → server}/extensions.d.ts +1 -1
  103. package/dist/{viewer → server}/extensions.js +3 -3
  104. package/dist/server/git-diff.d.ts +10 -0
  105. package/dist/{viewer → server}/git-diff.js +45 -10
  106. package/dist/server/git-origin.d.ts +4 -0
  107. package/dist/server/git-origin.js +103 -0
  108. package/dist/server/git.d.ts +9 -0
  109. package/dist/{viewer → server}/git.js +50 -6
  110. package/dist/server/history.d.ts +14 -0
  111. package/dist/server/history.js +205 -0
  112. package/dist/{viewer → server}/hmr.d.ts +0 -22
  113. package/dist/server/hmr.js +168 -0
  114. package/dist/server/index.d.ts +17 -0
  115. package/dist/{index.js → server/index.js} +16 -16
  116. package/dist/{viewer → server}/ja-lint.d.ts +1 -1
  117. package/dist/{viewer → server}/languages.d.ts +1 -1
  118. package/dist/{viewer → server}/languages.js +3 -3
  119. package/dist/{mcp.d.ts → server/mcp.d.ts} +2 -2
  120. package/dist/{mcp.js → server/mcp.js} +60 -21
  121. package/dist/{viewer → server}/plugin-config.d.ts +2 -2
  122. package/dist/{viewer → server}/plugin-config.js +2 -2
  123. package/dist/{plugins → server/plugins}/local-storage.d.ts +1 -1
  124. package/dist/{plugins → server/plugins}/local-storage.js +1 -1
  125. package/dist/{plugins → server/plugins}/runtime.d.ts +4 -4
  126. package/dist/{plugins → server/plugins}/runtime.js +4 -4
  127. package/dist/{viewer → server}/plugins.d.ts +3 -3
  128. package/dist/{viewer → server}/plugins.js +14 -13
  129. package/dist/server/resource-library.d.ts +1 -0
  130. package/dist/server/resource-library.js +1 -0
  131. package/dist/server/self.d.ts +5 -0
  132. package/dist/server/self.js +98 -0
  133. package/dist/server/serve.d.ts +61 -0
  134. package/dist/server/serve.js +503 -0
  135. package/dist/server/static-client.d.ts +4 -0
  136. package/dist/server/static-client.js +117 -0
  137. package/dist/server/workspace-server.d.ts +16 -0
  138. package/dist/server/workspace-server.js +266 -0
  139. package/dist/{viewer → server}/workspace.d.ts +6 -1
  140. package/dist/{viewer → server}/workspace.js +46 -0
  141. package/dist/subformats.global.js +92 -6
  142. package/dist/ui.global.js +85 -72
  143. package/dist/workspace/client.d.ts +13 -0
  144. package/dist/workspace/client.js +114 -0
  145. package/dist/{viewer → workspace}/code-file.d.ts +1 -1
  146. package/dist/{viewer → workspace}/code-file.js +7 -7
  147. package/dist/workspace/connection.d.ts +27 -0
  148. package/dist/workspace/connection.js +38 -0
  149. package/dist/{viewer → workspace}/editor-tools.d.ts +7 -1
  150. package/dist/{viewer → workspace}/editor-tools.js +12 -9
  151. package/dist/{viewer → workspace}/git-types.d.ts +7 -0
  152. package/dist/workspace/github.d.ts +4 -0
  153. package/dist/workspace/github.js +99 -0
  154. package/dist/workspace/history.d.ts +46 -0
  155. package/dist/workspace/history.js +86 -0
  156. package/dist/workspace/protocol.d.ts +38 -0
  157. package/dist/workspace/protocol.js +20 -0
  158. package/dist/workspace/resource-download.d.ts +1 -0
  159. package/dist/workspace/resource-download.js +8 -0
  160. package/dist/workspace/server.d.ts +9 -0
  161. package/dist/workspace/server.js +48 -0
  162. package/dist/{viewer → workspace}/site-icon.js +9 -10
  163. package/dist/{viewer → workspace}/site-title.js +6 -7
  164. package/dist/{viewer → workspace}/textfile.d.ts +1 -1
  165. package/dist/{viewer → workspace}/textfile.js +5 -5
  166. package/dist/workspace-worker.global.js +2859 -0
  167. package/package.json +34 -20
  168. package/dist/compiler/manifest.js +0 -37
  169. package/dist/compiler/serialize.d.ts +0 -3
  170. package/dist/compiler/serialize.js +0 -16
  171. package/dist/core/icons.js +0 -5
  172. package/dist/index.d.ts +0 -17
  173. package/dist/viewer/assets.js +0 -3
  174. package/dist/viewer/figure-preview.d.ts +0 -4
  175. package/dist/viewer/git-diff.d.ts +0 -6
  176. package/dist/viewer/git.d.ts +0 -5
  177. package/dist/viewer/hmr.js +0 -341
  178. package/dist/viewer/serve.d.ts +0 -216
  179. /package/dist/{compiler → engine/compiler}/asset-references.d.ts +0 -0
  180. /package/dist/{compiler → engine/compiler}/asset-references.js +0 -0
  181. /package/dist/{compiler → engine/compiler}/bundle-urls.d.ts +0 -0
  182. /package/dist/{compiler → engine/compiler}/check-types.d.ts +0 -0
  183. /package/dist/{compiler → engine/compiler}/check-types.js +0 -0
  184. /package/dist/{compiler → engine/compiler}/check.d.ts +0 -0
  185. /package/dist/{compiler → engine/compiler}/code-blocks.d.ts +0 -0
  186. /package/dist/{compiler → engine/compiler}/code-languages.d.ts +0 -0
  187. /package/dist/{compiler → engine/compiler}/config.d.ts +0 -0
  188. /package/dist/{compiler → engine/compiler}/drawio.d.ts +0 -0
  189. /package/dist/{compiler → engine/compiler}/drawio.js +0 -0
  190. /package/dist/{compiler → engine/compiler}/dxf.d.ts +0 -0
  191. /package/dist/{compiler → engine/compiler}/export.d.ts +0 -0
  192. /package/dist/{compiler → engine/compiler}/figures.d.ts +0 -0
  193. /package/dist/{compiler → engine/compiler}/files.d.ts +0 -0
  194. /package/dist/{compiler → engine/compiler}/fonts.d.ts +0 -0
  195. /package/dist/{compiler → engine/compiler}/format.d.ts +0 -0
  196. /package/dist/{compiler → engine/compiler}/format.js +0 -0
  197. /package/dist/{compiler → engine/compiler}/from-mdast.d.ts +0 -0
  198. /package/dist/{compiler → engine/compiler}/language-codes.d.ts +0 -0
  199. /package/dist/{compiler → engine/compiler}/language-codes.js +0 -0
  200. /package/dist/{compiler → engine/compiler}/locales.d.ts +0 -0
  201. /package/dist/{compiler → engine/compiler}/public-file.d.ts +0 -0
  202. /package/dist/{compiler → engine/compiler}/public-file.js +0 -0
  203. /package/dist/{compiler → engine/compiler}/subformat-schema.d.ts +0 -0
  204. /package/dist/{compiler → engine/compiler}/terms.d.ts +0 -0
  205. /package/dist/{compiler → engine/compiler}/terms.js +0 -0
  206. /package/dist/{compiler → engine/compiler}/textfile-remote.d.ts +0 -0
  207. /package/dist/{compiler → engine/compiler}/textfile.d.ts +0 -0
  208. /package/dist/{compiler → engine/compiler}/theme-variants.d.ts +0 -0
  209. /package/dist/{compiler → engine/compiler}/zip.d.ts +0 -0
  210. /package/dist/{core → engine/core}/blocks.js +0 -0
  211. /package/dist/{core → engine/core}/code-file.d.ts +0 -0
  212. /package/dist/{core → engine/core}/code-file.js +0 -0
  213. /package/dist/{core → engine/core}/code-grammars.d.ts +0 -0
  214. /package/dist/{core → engine/core}/code-grammars.js +0 -0
  215. /package/dist/{core → engine/core}/content-types.js +0 -0
  216. /package/dist/{core → engine/core}/escape-html.d.ts +0 -0
  217. /package/dist/{core → engine/core}/escape-html.js +0 -0
  218. /package/dist/{core → engine/core}/extension-package.d.ts +0 -0
  219. /package/dist/{core → engine/core}/extension-package.js +0 -0
  220. /package/dist/{core → engine/core}/figure-frame.d.ts +0 -0
  221. /package/dist/{core → engine/core}/figure-frame.js +0 -0
  222. /package/dist/{core → engine/core}/file-embed.d.ts +0 -0
  223. /package/dist/{core → engine/core}/file-embed.js +0 -0
  224. /package/dist/{core → engine/core}/files.d.ts +0 -0
  225. /package/dist/{core → engine/core}/files.js +0 -0
  226. /package/dist/{core → engine/core}/graph-common.d.ts +0 -0
  227. /package/dist/{core → engine/core}/graph-common.js +0 -0
  228. /package/dist/{core → engine/core}/graph.d.ts +0 -0
  229. /package/dist/{core → engine/core}/graph.js +0 -0
  230. /package/dist/{core → engine/core}/inline.d.ts +0 -0
  231. /package/dist/{core → engine/core}/inline.js +0 -0
  232. /package/dist/{core → engine/core}/json-tools.d.ts +0 -0
  233. /package/dist/{core → engine/core}/json-tools.js +0 -0
  234. /package/dist/{core → engine/core}/language.d.ts +0 -0
  235. /package/dist/{core → engine/core}/language.js +0 -0
  236. /package/dist/{core → engine/core}/languages/ja.d.ts +0 -0
  237. /package/dist/{core → engine/core}/languages/ja.js +0 -0
  238. /package/dist/{core → engine/core}/markdown.d.ts +0 -0
  239. /package/dist/{core → engine/core}/markdown.js +0 -0
  240. /package/dist/{core → engine/core}/previewers.d.ts +0 -0
  241. /package/dist/{core → engine/core}/previewers.js +0 -0
  242. /package/dist/{core → engine/core}/schema-comments.d.ts +0 -0
  243. /package/dist/{core → engine/core}/schema-comments.js +0 -0
  244. /package/dist/{core → engine/core}/schema-fields.d.ts +0 -0
  245. /package/dist/{core → engine/core}/schema-fields.js +0 -0
  246. /package/dist/{core → engine/core}/schema-graph.d.ts +0 -0
  247. /package/dist/{core → engine/core}/schema-graph.js +0 -0
  248. /package/dist/{core → engine/core}/subformat-record.d.ts +0 -0
  249. /package/dist/{core → engine/core}/subformat-record.js +0 -0
  250. /package/dist/{core → engine/core}/term-reference.d.ts +0 -0
  251. /package/dist/{core → engine/core}/term-reference.js +0 -0
  252. /package/dist/{core → engine/core}/textfile.d.ts +0 -0
  253. /package/dist/{core → engine/core}/textfile.js +0 -0
  254. /package/dist/{core → engine/core}/theme-variants.d.ts +0 -0
  255. /package/dist/{core → engine/core}/theme-variants.js +0 -0
  256. /package/dist/{core → engine/core}/workspace.d.ts +0 -0
  257. /package/dist/{core → engine/core}/workspace.js +0 -0
  258. /package/dist/{viewer → frontend}/bundle-network.d.ts +0 -0
  259. /package/dist/{viewer → frontend}/bundle-network.js +0 -0
  260. /package/dist/{core → frontend}/flow-base-css.generated.d.ts +0 -0
  261. /package/dist/{core → frontend}/flow-base-css.generated.js +0 -0
  262. /package/dist/{core → frontend}/flow-css.d.ts +0 -0
  263. /package/dist/{core → frontend}/flow-css.js +0 -0
  264. /package/dist/{viewer → frontend}/font-picker.js +0 -0
  265. /package/dist/{viewer → frontend}/font-settings.js +0 -0
  266. /package/dist/{viewer → frontend}/i18n.d.ts +0 -0
  267. /package/dist/{viewer → frontend}/i18n.js +0 -0
  268. /package/dist/{viewer → frontend}/language-picker.d.ts +0 -0
  269. /package/dist/{viewer → frontend}/lazy-preview.d.ts +0 -0
  270. /package/dist/{viewer → frontend}/lazy-preview.js +0 -0
  271. /package/dist/{viewer → frontend}/nav-focus.d.ts +0 -0
  272. /package/dist/{viewer → frontend}/nav-update.d.ts +0 -0
  273. /package/dist/{viewer → frontend}/nav-update.js +0 -0
  274. /package/dist/{viewer → frontend}/plugin-blocks.d.ts +0 -0
  275. /package/dist/{viewer → frontend}/plugin-style.d.ts +0 -0
  276. /package/dist/{viewer → frontend}/plugin-style.js +0 -0
  277. /package/dist/{viewer → frontend}/plugin-view.d.ts +0 -0
  278. /package/dist/{viewer → frontend}/plugin-view.js +0 -0
  279. /package/dist/{viewer → frontend}/resize.d.ts +0 -0
  280. /package/dist/{core → frontend}/schema-graph-mount.d.ts +0 -0
  281. /package/dist/{core → frontend}/schema-graph-mount.js +0 -0
  282. /package/dist/{core → frontend}/table-ui.d.ts +0 -0
  283. /package/dist/{core → frontend}/table-ui.js +0 -0
  284. /package/dist/{core → frontend}/terms-ui.d.ts +0 -0
  285. /package/dist/{core → frontend}/terms-ui.js +0 -0
  286. /package/dist/{viewer → frontend}/theme-picker.d.ts +0 -0
  287. /package/dist/{viewer → frontend}/theme-picker.js +0 -0
  288. /package/dist/{core → frontend}/toc-ui.d.ts +0 -0
  289. /package/dist/{core → frontend}/toc-ui.js +0 -0
  290. /package/dist/{core → frontend}/video-ui.d.ts +0 -0
  291. /package/dist/{core → frontend}/video-ui.js +0 -0
  292. /package/dist/{viewer → server}/build-plugins.d.ts +0 -0
  293. /package/dist/{cli.d.ts → server/cli.d.ts} +0 -0
  294. /package/dist/{viewer → server}/extension-pack.d.ts +0 -0
  295. /package/dist/{viewer → server}/fonts/LICENSE.txt +0 -0
  296. /package/dist/{viewer → server}/fonts/udev-gothic-regular.woff2 +0 -0
  297. /package/dist/{viewer → server}/fonts.d.ts +0 -0
  298. /package/dist/{viewer → server}/fonts.js +0 -0
  299. /package/dist/{viewer → server}/ja-lint.js +0 -0
  300. /package/dist/{viewer → workspace}/git-types.js +0 -0
  301. /package/dist/{viewer → workspace}/site-icon.d.ts +0 -0
  302. /package/dist/{viewer → workspace}/site-title.d.ts +0 -0
@@ -0,0 +1,168 @@
1
+ // HMR for the dev server (shared by preview / edit). Classifies and watches changes; serve.ts
2
+ // broadcasts them as workspace "change" events and hmr-client.ts applies them. By source:
3
+ // data side (content/*.md, dooc.yaml, figures/*) = picked up by this module's watcher;
4
+ // preview swaps only the main body + nav (keeping scroll). edit likewise does a partial
5
+ // update of just the body + nav (no reload; keeps CodeMirror cursor/scroll/undo and
6
+ // unsaved content) — only on pages where edit-client.ts registered `onContent`
7
+ // (unregistered, e.g. the new page, reloads).
8
+ // client bundle side (src/viewer/edit-client.ts, src/core/*.tsx = bundle sources of the schema
9
+ // graph interaction layer `/assets/graph.js`) = not imported by the server (esbuild
10
+ // bundles them on demand), so tsx watch doesn't react → the data-side watcher picks
11
+ // them up as "client" and triggers a reload.
12
+ // server side (all other src/*.ts) = tsx watch restarts the whole process, so not watched.
13
+ // The client notices the swap from the bootId difference in `hello` on reconnect and
14
+ // reloads.
15
+ // All content events reach the editor, which compares disk contents with its saved base.
16
+ import { existsSync, readFileSync, realpathSync, unwatchFile, watch, watchFile } from "node:fs";
17
+ import { dirname, join, resolve } from "node:path";
18
+ import { managedFile } from "../engine/compiler/files.js";
19
+ import { textfilePath } from "../engine/compiler/textfile.js";
20
+ import { isManifestFile } from "../engine/core/content-metadata.js";
21
+ import { isRemoteTextfile } from "../engine/core/textfile.js";
22
+ import { prebuilt } from "./assets.js";
23
+ import { gitHeadFile } from "./workspace.js";
24
+ /**
25
+ * Changed path (repo-root relative) → HMR kind. undefined for out-of-scope files
26
+ * (dist output, temp files etc.).
27
+ */
28
+ export const classifyChange = (rel) => {
29
+ const p = rel.replace(/\\/g, "/");
30
+ // Browser-only sources are bundled per request, not imported by the server, so `tsx watch`
31
+ // never restarts for them; classify them as "client" to trigger a reload. Everything else
32
+ // under packages/ is server-side: the restart changes the boot id and the page reloads.
33
+ if (/^packages\/frontend\/src\/.+\.(tsx?|json)$/.test(p) ||
34
+ p === "packages/workspace/src/client.ts") {
35
+ return "client";
36
+ }
37
+ // content = body text (.md) and dooc.yaml (= SoT for hierarchy and ordering).
38
+ if (isManifestFile(p) || (p.startsWith("content/") && p.endsWith(".md"))) {
39
+ return "content";
40
+ }
41
+ if (p.startsWith("locales/") && p.endsWith(".md"))
42
+ return "content";
43
+ if (p.startsWith("figures/") && /\.(svg|html|png|webp|jpe?g)$/.test(p)) {
44
+ return "content";
45
+ }
46
+ // icons/<id>.svg (doc icons) is data side too = partial update.
47
+ if (p.startsWith("icons/") && p.endsWith(".svg")) {
48
+ return "content";
49
+ }
50
+ return undefined;
51
+ };
52
+ /**
53
+ * Folders to watch. The docs-side ones are relative to docsRoot, src to pkgRoot (only files that
54
+ * classifyChange marks "client" count).
55
+ */
56
+ /**
57
+ * Notifies data-side changes batched by kind. An editor save fires multiple events
58
+ * (rename + change), so debounce collapses them into one. Referenced text files can be added
59
+ * as drafts are compiled; close() releases all watchers.
60
+ */
61
+ export const watchProject = (docsRoot, pkgRoot, onChange, debounceMs = 60) => {
62
+ const pending = new Map();
63
+ let timer;
64
+ const flush = () => {
65
+ timer = undefined;
66
+ const byKind = new Map();
67
+ for (const [file, kind] of pending) {
68
+ byKind.set(kind, [...(byKind.get(kind) ?? []), file]);
69
+ }
70
+ pending.clear();
71
+ for (const [kind, files] of byKind) {
72
+ onChange(kind, files);
73
+ }
74
+ };
75
+ const note = (rel, kind = classifyChange(rel)) => {
76
+ if (!kind) {
77
+ return;
78
+ }
79
+ pending.set(rel, kind);
80
+ if (!timer) {
81
+ timer = setTimeout(flush, debounceMs);
82
+ timer.unref();
83
+ }
84
+ };
85
+ // Skip missing folders (checkouts / test fixtures without optional asset folders) to avoid ENOENT.
86
+ const dirs = [["packages", join(pkgRoot, "packages")]];
87
+ const watchers = dirs
88
+ .filter(([, abs]) => !prebuilt && existsSync(abs))
89
+ .map(([dir, abs]) => watch(abs, { recursive: true }, (_event, name) => {
90
+ if (name) {
91
+ note(`${dir}/${String(name)}`);
92
+ }
93
+ }));
94
+ // Watch the directory so atomic replacements of the manifest are detected too.
95
+ watchers.push(watch(docsRoot, { recursive: true }, (_event, name) => {
96
+ if (!name)
97
+ return;
98
+ const path = String(name).replaceAll("\\", "/");
99
+ if (isManifestFile(path) ||
100
+ path.startsWith("locales/") ||
101
+ /(^|\/)\.gitignore$/.test(path))
102
+ note(path, "content");
103
+ else if (managedFile(path) && !path.startsWith("src/") && !/\.(tmp|swp)$/.test(path))
104
+ note(path, "content");
105
+ }));
106
+ const textfiles = new Map();
107
+ const headFile = gitHeadFile(docsRoot);
108
+ if (headFile) {
109
+ for (let parent = realpathSync(docsRoot); !existsSync(join(parent, ".git"));) {
110
+ const next = dirname(parent);
111
+ if (next === parent)
112
+ break;
113
+ parent = next;
114
+ watchers.push(watch(parent, (_event, name) => {
115
+ if (String(name) === ".gitignore")
116
+ note(".gitignore", "content");
117
+ }));
118
+ }
119
+ const directory = dirname(headFile);
120
+ const common = join(directory, "commondir");
121
+ const directories = new Set([
122
+ directory,
123
+ existsSync(common)
124
+ ? resolve(directory, readFileSync(common, "utf8").trim())
125
+ : directory,
126
+ ]);
127
+ for (const path of directories)
128
+ watchers.push(watch(path, { recursive: true }, (_event, name) => {
129
+ const file = String(name).replaceAll("\\", "/");
130
+ if (file === "HEAD" || file === "packed-refs" || file.startsWith("refs/"))
131
+ note(".git/HEAD", "content");
132
+ else if (file === "index" || file === "info/exclude" || file === "config")
133
+ note(`.git/${file}`, "content");
134
+ }));
135
+ }
136
+ // shortcut: keep encountered file watches until shutdown; prune if sessions collect many removed references.
137
+ const watchTextfiles = (files) => {
138
+ for (const file of files) {
139
+ if (isRemoteTextfile(file))
140
+ continue;
141
+ try {
142
+ textfilePath(docsRoot, file);
143
+ }
144
+ catch {
145
+ continue;
146
+ }
147
+ const path = resolve(docsRoot, file);
148
+ if (textfiles.has(path))
149
+ continue;
150
+ const changed = () => note(file.replace(/^(\.\/)+/, ""), "content");
151
+ // Poll referenced paths so atomic saves, deletion and creation are all detected.
152
+ watchFile(path, { persistent: false, interval: 200 }, changed);
153
+ textfiles.set(path, changed);
154
+ }
155
+ };
156
+ const close = () => {
157
+ if (timer) {
158
+ clearTimeout(timer);
159
+ timer = undefined;
160
+ }
161
+ for (const w of watchers) {
162
+ w.close();
163
+ }
164
+ for (const [path, listener] of textfiles)
165
+ unwatchFile(path, listener);
166
+ };
167
+ return { close, watchTextfiles };
168
+ };
@@ -0,0 +1,17 @@
1
+ export * from "../engine/core/blocks.js";
2
+ export * from "../engine/core/content-metadata.js";
3
+ export type * from "../engine/core/content-types.js";
4
+ export * from "../engine/core/figure-frame.js";
5
+ export * from "../engine/core/graph.js";
6
+ export * from "../engine/core/graph-common.js";
7
+ export * from "../engine/core/html.js";
8
+ export * from "../engine/core/inline.js";
9
+ export * from "../engine/core/language.js";
10
+ export * from "../engine/core/languages/ja.js";
11
+ export * from "../engine/core/previewers.js";
12
+ export * from "../engine/core/routing.js";
13
+ export * from "../engine/core/schema-graph.js";
14
+ export * from "../engine/core/taxonomy.js";
15
+ export { mountThemeVariants, themeVariantFile } from "../engine/core/theme-variants.js";
16
+ export * from "../engine/core/workspace.js";
17
+ export * from "../frontend/terms-ui.js";
@@ -1,31 +1,31 @@
1
1
  // Browser-safe content types, parsers and rendering helpers. No project data is bundled.
2
- export * from "./core/blocks.js";
3
- export * from "./core/content-metadata.js";
2
+ export * from "../engine/core/blocks.js";
3
+ export * from "../engine/core/content-metadata.js";
4
4
  // Isolated figure rendering (sandboxed iframe) and its parent-side mount (theme following /
5
5
  // html figure height).
6
- export * from "./core/figure-frame.js";
6
+ export * from "../engine/core/figure-frame.js";
7
7
  // node / edge DSL (`graphth`): parse / graph model / deterministic layout via Dagre.
8
8
  // graph-common.js is the SoT for the geometry parts shared with the schema graph (text width
9
9
  // estimation / orthogonal routing / uid).
10
- export * from "./core/graph.js";
11
- export * from "./core/graph-common.js";
10
+ export * from "../engine/core/graph.js";
11
+ export * from "../engine/core/graph-common.js";
12
12
  // Block AST → HTML renderer, shared with the viewer.
13
- export * from "./core/html.js";
14
- export * from "./core/inline.js";
13
+ export * from "../engine/core/html.js";
14
+ export * from "../engine/core/inline.js";
15
15
  // Language socket: the adapter interface + generic rules, and the built-in Japanese adapter
16
16
  // (browser-safe part; its prose lint is Node-only and lives in the viewer).
17
- export * from "./core/language.js";
18
- export * from "./core/languages/ja.js";
19
- export * from "./core/previewers.js";
20
- export * from "./core/routing.js";
17
+ export * from "../engine/core/language.js";
18
+ export * from "../engine/core/languages/ja.js";
19
+ export * from "../engine/core/previewers.js";
20
+ export * from "../engine/core/routing.js";
21
21
  // table DSL (`schemath`): parse / graph model / deterministic layout. html.ts uses it for
22
22
  // rendering, and it also serves as the model source when consumers build their own UI
23
23
  // (interactive graphs etc.).
24
- export * from "./core/schema-graph.js";
24
+ export * from "../engine/core/schema-graph.js";
25
25
  // The schema graph's interactive UI (React Flow) requires react, so it is imported not from
26
26
  // this react-free entry but from the subpath export `./flow` (dist/core/schema-graph-mount.js)
27
27
  // and, for script tags, `./flow.global.js`.
28
- export * from "./core/taxonomy.js";
29
- export * from "./core/terms-ui.js";
30
- export { mountThemeVariants, themeVariantFile } from "./core/theme-variants.js";
31
- export * from "./core/workspace.js";
28
+ export * from "../engine/core/taxonomy.js";
29
+ export { mountThemeVariants, themeVariantFile } from "../engine/core/theme-variants.js";
30
+ export * from "../engine/core/workspace.js";
31
+ export * from "../frontend/terms-ui.js";
@@ -1,3 +1,3 @@
1
- import type { LintFinding } from "../core/language.js";
1
+ import type { LintFinding } from "../engine/core/language.js";
2
2
  /** Lints body (md content without front matter) and returns typo findings with offsets. */
3
3
  export declare const lintJa: (body: string) => Promise<LintFinding[]>;
@@ -1,5 +1,5 @@
1
1
  import type { LanguageRegistration } from "shiki/core";
2
- import type { LanguageAdapter } from "../core/language.js";
2
+ import type { LanguageAdapter } from "../engine/core/language.js";
3
3
  export declare const BUILTIN_LANGUAGES: readonly LanguageAdapter[];
4
4
  export interface SiteLanguages {
5
5
  languages: readonly LanguageAdapter[];
@@ -1,8 +1,8 @@
1
1
  // Built-in language adapters for the Node tools (viewer / CLI / MCP): the browser-safe core
2
2
  // adapters plus their Node-only prose lint. docs.config.mjs adapters take precedence.
3
- import { loadCodeLanguages } from "../compiler/code-languages.js";
4
- import { loadDocsConfig } from "../compiler/config.js";
5
- import { ja } from "../core/languages/ja.js";
3
+ import { loadCodeLanguages } from "../engine/compiler/code-languages.js";
4
+ import { loadDocsConfig } from "../engine/compiler/config.js";
5
+ import { ja } from "../engine/core/languages/ja.js";
6
6
  export const BUILTIN_LANGUAGES = [
7
7
  // textlint is heavy; load it on the first lint request.
8
8
  { ...ja, lint: async (body) => (await import("./ja-lint.js")).lintJa(body) },
@@ -1,5 +1,5 @@
1
- import { type CompileOptions } from "./compiler/compile.js";
2
- import type { GitOrigin } from "./viewer/git-types.js";
1
+ import { type CompileOptions } from "../engine/compiler/compile.js";
2
+ import type { GitOrigin } from "../workspace/git-types.js";
3
3
  type Args = Record<string, unknown>;
4
4
  interface Property {
5
5
  type: string | string[];
@@ -5,21 +5,23 @@ import { randomUUID } from "node:crypto";
5
5
  import { mkdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
6
6
  import { dirname, join, relative } from "node:path";
7
7
  import { createInterface } from "node:readline";
8
- import { checkSite } from "./compiler/check.js";
9
- import { CHECK_KINDS } from "./compiler/check-types.js";
10
- import { createCompiler } from "./compiler/compile.js";
11
- import { exportBundle } from "./compiler/export.js";
12
- import { filesSnapshot, updateFiles, uploadFile } from "./compiler/files.js";
13
- import { addProjectFont, listProjectFonts, removeProjectFont } from "./compiler/fonts.js";
14
- import { createDocOps, isOpError } from "./compiler/ops.js";
15
- import { validateSubformatFile } from "./compiler/subformats.js";
16
- import { readTextfile, textfilePath, writeTextfile } from "./compiler/textfile.js";
17
- import { MANIFEST_FILE } from "./core/content-metadata.js";
18
- import { localFile } from "./core/files.js";
19
- import { docDisplayName } from "./core/taxonomy.js";
20
- import { buildBundle } from "./viewer/build.js";
21
- import { createGitHandler, validateGitOrigin } from "./viewer/git.js";
22
- import { resourceIndex } from "./viewer/resource-library.js";
8
+ import { checkSite } from "../engine/compiler/check.js";
9
+ import { CHECK_KINDS } from "../engine/compiler/check-types.js";
10
+ import { createCompiler } from "../engine/compiler/compile.js";
11
+ import { exportBundle } from "../engine/compiler/export.js";
12
+ import { filesSnapshot, updateFiles, uploadFile } from "../engine/compiler/files.js";
13
+ import { addProjectFont, listProjectFonts, removeProjectFont, } from "../engine/compiler/fonts.js";
14
+ import { manifestFile } from "../engine/compiler/manifest.js";
15
+ import { createDocOps, isOpError } from "../engine/compiler/ops.js";
16
+ import { validateSubformatFile } from "../engine/compiler/subformats.js";
17
+ import { readTextfile, textfilePath, writeTextfile } from "../engine/compiler/textfile.js";
18
+ import { localFile } from "../engine/core/files.js";
19
+ import { docDisplayName } from "../engine/core/taxonomy.js";
20
+ import { parsePerson } from "../workspace/history.js";
21
+ import { buildBundle } from "./build.js";
22
+ import { createGitHandler, validateGitOrigin } from "./git.js";
23
+ import { folderHistory, gitHistory, workspaceHistory } from "./history.js";
24
+ import { resourceIndex } from "./resource-library.js";
23
25
  const str = { type: "string" };
24
26
  const num = { type: "integer", minimum: 0 };
25
27
  const bool = { type: "boolean" };
@@ -70,6 +72,10 @@ export const createTools = (root, options = {}) => {
70
72
  url_preview: { ...str, enum: ["embed", "network"] },
71
73
  mode: { ...str, enum: ["static", "live"] },
72
74
  auth: { ...str, enum: ["external"] },
75
+ easy_download: {
76
+ type: "boolean",
77
+ description: "Enable individual resource downloads in HTML (default: false).",
78
+ },
73
79
  source_url: {
74
80
  ...str,
75
81
  description: "Public source directory URL for card copy links in HTML, relative to dooc.yaml.",
@@ -85,6 +91,7 @@ export const createTools = (root, options = {}) => {
85
91
  mode: a.mode,
86
92
  auth: a.auth,
87
93
  sourceUrl: a.source_url,
94
+ easyDownload: a.easy_download,
88
95
  previews: options.previews,
89
96
  });
90
97
  const path = textfilePath(root, file);
@@ -149,7 +156,7 @@ export const createTools = (root, options = {}) => {
149
156
  run: (a) => updateFiles(root, a),
150
157
  },
151
158
  list_resources: {
152
- description: "List Statics: codeblocks (including term definitions and local text-file embeds, with normalized format and reference locations), URLs from Markdown links, and URL previews from Markdown images, with source files and line numbers.",
159
+ description: "List Library: codeblocks (including term definitions and local text-file embeds, with normalized format and reference locations), URLs from Markdown links, and URL previews from Markdown images, with source files and line numbers.",
153
160
  props: {},
154
161
  run: () => resourceIndex(root, filesSnapshot(root).files.map((file) => file.path), options.previews?.domains),
155
162
  },
@@ -213,6 +220,35 @@ export const createTools = (root, options = {}) => {
213
220
  required: ["action"],
214
221
  run: git,
215
222
  },
223
+ history: {
224
+ description: "Edit history as workspace snapshots. list (default) returns snapshots newest first from both stores: source=git (commits, co-authors from Co-authored-by trailers) and source=dooc (copies under .dooc/snapshots); user keeps only snapshots that person or agent authored or co-authored. snapshot records the current files with message, credited to user (e.g. the agent's name).",
225
+ props: {
226
+ action: { ...str, enum: ["list", "snapshot"] },
227
+ source: { ...str, enum: ["git", "dooc"] },
228
+ user: { ...str, description: "Author name, case-insensitive" },
229
+ message: str,
230
+ },
231
+ run: async (a) => {
232
+ const user = optStr(a.user);
233
+ if (a.action === "snapshot") {
234
+ const message = optStr(a.message)?.trim();
235
+ if (!message)
236
+ throw new Error("A snapshot needs a message");
237
+ return workspaceHistory(root).snapshot(message, user ? { author: parsePerson({ name: user }) } : undefined);
238
+ }
239
+ const name = user?.toLowerCase();
240
+ const stores = { git: gitHistory(root), dooc: folderHistory(root) };
241
+ // shortcut: filters the newest 200 commits, page through git log when a user's older edits are needed.
242
+ const snapshots = (await Promise.all(["git", "dooc"]
243
+ .filter((source) => !a.source || a.source === source)
244
+ .map(async (source) => (await stores[source].list()).map((s) => ({ source, ...s })))))
245
+ .flat()
246
+ .filter((s) => !name ||
247
+ [s.author, ...(s.coAuthors ?? [])].some((person) => person?.toLowerCase() === name))
248
+ .sort((x, y) => Date.parse(y.time) - Date.parse(x.time));
249
+ return { snapshots };
250
+ },
251
+ },
216
252
  list_docs: {
217
253
  description: "The doc tree (in manifest display order) and figures. Each doc has id / file / title / parent / depth.",
218
254
  props: {},
@@ -225,7 +261,8 @@ export const createTools = (root, options = {}) => {
225
261
  depth.set(d.id, dep);
226
262
  return {
227
263
  id: d.id,
228
- file: d.subformat ? MANIFEST_FILE : d.file,
264
+ file: d.subformat || d.library ? manifestFile(root) : d.file,
265
+ ...(d.library ? { library: d.library } : {}),
229
266
  ...(d.subformat ? { subformat: d.subformat.ext } : {}),
230
267
  title: docDisplayName(d, d.id),
231
268
  parent: d.parent,
@@ -258,16 +295,18 @@ export const createTools = (root, options = {}) => {
258
295
  },
259
296
  },
260
297
  read_doc: {
261
- description: "A doc's raw md (including front-matter) and its validation errors. Figure links use file paths; list_docs maps each file to its read_figure name.",
298
+ description: "A doc's raw md and its validation errors. Figure links use file paths; list_docs maps each file to its read_figure name.",
262
299
  props: { id: { ...str, description: "doc id" } },
263
300
  required: ["id"],
264
301
  run: (a) => {
265
302
  const id = String(a.id);
266
303
  const compiled = compiler.compile();
267
304
  const doc = compiled.docs.find((d) => d.id === id);
305
+ if (doc?.library)
306
+ return { file: manifestFile(root), library: doc.library, errors: [] };
268
307
  if (doc?.subformat)
269
308
  return {
270
- file: MANIFEST_FILE,
309
+ file: manifestFile(root),
271
310
  subformat: doc.subformat,
272
311
  errors: compiled.sources.get(doc.file)?.errors ?? [],
273
312
  };
@@ -321,10 +360,10 @@ export const createTools = (root, options = {}) => {
321
360
  run: (a) => ops.add(String(a.id), String(a.title), optStr(a.parent)),
322
361
  },
323
362
  write_doc: {
324
- description: "Overwrite the entire raw text of an existing doc (including front-matter). Returns the validation errors after writing.",
363
+ description: "Overwrite the entire raw text of an existing doc. Titles live in dooc.yaml. Returns the validation errors after writing.",
325
364
  props: {
326
365
  id: { ...str, description: "doc id" },
327
- content: { ...str, description: "Full md text (from ---\\ntitle: ...\\n---)" },
366
+ content: { ...str, description: "Full md text" },
328
367
  },
329
368
  required: ["id", "content"],
330
369
  run: (a) => {
@@ -1,6 +1,6 @@
1
- import { type WorkspaceSource } from "../core/workspace.js";
2
1
  import type { DataPlugin } from "../plugins/types.js";
3
- import type { GitOrigin } from "./git-types.js";
2
+ import { type WorkspaceSource } from "../engine/core/workspace.js";
3
+ import type { GitOrigin } from "../workspace/git-types.js";
4
4
  export interface PluginMock {
5
5
  origin: string;
6
6
  /** Complete local mock authorization automatically when displaying a preview. */
@@ -1,9 +1,9 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { isAbsolute, resolve } from "node:path";
3
3
  import { pathToFileURL } from "node:url";
4
- import { parsePreviewSettings } from "../core/previewers.js";
5
- import { parseWorkspaceSource } from "../core/workspace.js";
6
4
  import { httpsUrl, validatePlugins } from "../plugins/oauth.js";
5
+ import { parsePreviewSettings } from "../engine/core/previewers.js";
6
+ import { parseWorkspaceSource } from "../engine/core/workspace.js";
7
7
  import { validateGitOrigin } from "./git.js";
8
8
  /** Viewer modules are explicitly injected; document roots never select executable plugins. */
9
9
  export const loadViewerPlugins = async (specifier) => {
@@ -1,4 +1,4 @@
1
- import type { DataPlugin, OAuthToken, PluginUser } from "./types.js";
1
+ import type { DataPlugin, OAuthToken, PluginUser } from "../../plugins/types.js";
2
2
  export interface SavedConnection {
3
3
  token: OAuthToken;
4
4
  expires: number;
@@ -3,7 +3,7 @@ import { lstatSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync }
3
3
  import { homedir } from "node:os";
4
4
  import { join } from "node:path";
5
5
  import { setTimeout as delay } from "node:timers/promises";
6
- import { parseOAuthToken } from "./oauth.js";
6
+ import { parseOAuthToken } from "../../plugins/oauth.js";
7
7
  /** Personal state is outside document roots and never included in exported bundles. */
8
8
  export const createLocalPluginStorage = (userDir = process.env.DOOC_USER_DIR ?? join(homedir(), ".dooc")) => {
9
9
  const folder = join(userDir, "plugins");
@@ -1,6 +1,6 @@
1
- import { type PluginActionResult } from "./actions.js";
1
+ import { type PluginActionResult } from "../../plugins/actions.js";
2
+ import type { DataPlugin, PluginUser } from "../../plugins/types.js";
2
3
  import type { PluginCredentialStore } from "./local-storage.js";
3
- import type { DataPlugin, PluginUser } from "./types.js";
4
4
  export declare const createPluginRuntime: (definitions: readonly DataPlugin[], transport?: typeof fetch, credentials?: PluginCredentialStore) => {
5
5
  resolve(source: unknown): string | undefined;
6
6
  register(plugin: DataPlugin): void;
@@ -19,11 +19,11 @@ export declare const createPluginRuntime: (definitions: readonly DataPlugin[], t
19
19
  status(id: string, pluginId: string): PluginUser | undefined;
20
20
  read(id: string, pluginId: string, source: unknown): Promise<{
21
21
  user: PluginUser;
22
- view: import("./view.js").PluginView;
22
+ view: import("../../plugins/view.js").PluginView;
23
23
  }>;
24
24
  actions(id: string, pluginId: string, source: unknown): Promise<{
25
25
  user: PluginUser;
26
- actions: import("./actions.js").PluginAction[];
26
+ actions: import("../../plugins/actions.js").PluginAction[];
27
27
  }>;
28
28
  act(id: string, pluginId: string, source: unknown, input: unknown, requestId: unknown): Promise<{
29
29
  user: PluginUser;
@@ -1,7 +1,7 @@
1
1
  import { createHash, randomBytes } from "node:crypto";
2
- import { validatePluginActionRequest, validatePluginActions, validatePluginActionValues, } from "./actions.js";
3
- import { fetchPluginJson, httpsUrl, isPluginError, PluginError, parseOAuthToken, validatePlugins, } from "./oauth.js";
4
- import { parsePluginUrl, validatePluginView } from "./view.js";
2
+ import { validatePluginActionRequest, validatePluginActions, validatePluginActionValues, } from "../../plugins/actions.js";
3
+ import { fetchPluginJson, httpsUrl, isPluginError, PluginError, parseOAuthToken, validatePlugins, } from "../../plugins/oauth.js";
4
+ import { parsePluginUrl, validatePluginView } from "../../plugins/view.js";
5
5
  const nonce = () => randomBytes(32).toString("base64url");
6
6
  const expired = () => new PluginError(401, "Connect this plugin again");
7
7
  const expiry = (token) => token.expires_in === undefined ? Infinity : Date.now() + token.expires_in * 1000;
@@ -252,7 +252,7 @@ export const createPluginRuntime = (definitions, transport, credentials) => {
252
252
  if (plugin.oauth.deviceAuthorizationUrl)
253
253
  throw new PluginError(400, "Use device authorization for this plugin");
254
254
  const redirect = new URL(redirectUri);
255
- if (redirect.protocol !== "http:" ||
255
+ if (!["http:", "https:"].includes(redirect.protocol) ||
256
256
  !["localhost", "127.0.0.1", "[::1]"].includes(redirect.hostname) ||
257
257
  redirect.username ||
258
258
  redirect.password ||
@@ -1,9 +1,9 @@
1
1
  import type { IncomingMessage, ServerResponse } from "node:http";
2
- import type { PluginCredentialStore } from "../plugins/local-storage.js";
3
2
  import type { DataPlugin } from "../plugins/types.js";
4
- export type { GitWorkspace, StorageWorkspace, WorkspaceSource } from "../core/workspace.js";
3
+ import type { PluginCredentialStore } from "./plugins/local-storage.js";
4
+ export type { GitWorkspace, StorageWorkspace, WorkspaceSource, } from "../engine/core/workspace.js";
5
5
  import { type ViewerPluginRegistry, type ViewerPlugins } from "./plugin-config.js";
6
- export type { GitContext, GitOrigin, GitOriginAction, GitOriginState, GitPullRequest, } from "./git-types.js";
6
+ export type { GitContext, GitOrigin, GitOriginAction, GitOriginState, GitPullRequest, } from "../workspace/git-types.js";
7
7
  export type { PluginMock, ViewerPluginRegistry, ViewerPlugins, ViewerRuntime, } from "./plugin-config.js";
8
8
  /** Local viewer only: the cookie identifies a browser session, never a document-supplied user. */
9
9
  export declare const createPluginHandler: (plugins: readonly DataPlugin[], presentation?: Pick<ViewerPlugins, "mocks">, credentials?: PluginCredentialStore) => ((req: IncomingMessage, res: ServerResponse) => Promise<boolean>) & ViewerPluginRegistry & {
@@ -1,8 +1,8 @@
1
1
  import { randomBytes } from "node:crypto";
2
- import { escapeHtml } from "../core/escape-html.js";
3
2
  import { isPluginError, PluginError } from "../plugins/oauth.js";
4
- import { createPluginRuntime } from "../plugins/runtime.js";
5
- import { isLocalToolRequest } from "./editor-tools.js";
3
+ import { escapeHtml } from "../engine/core/escape-html.js";
4
+ import { isLocalToolRequest, requestScheme } from "./editor-tools.js";
5
+ import { createPluginRuntime } from "./plugins/runtime.js";
6
6
  import { validateViewerPlugins, } from "./plugin-config.js";
7
7
  const readBody = (req) => new Promise((resolve, reject) => {
8
8
  let body = "";
@@ -96,15 +96,15 @@ export const createPluginHandler = (plugins, presentation = { mocks: {} }, crede
96
96
  tickets.set(ticket, { plugin, origin, expires: Date.now() + 10 * 60 * 1000 });
97
97
  return `${origin}/api/plugins/login/${plugin}?ticket=${ticket}`;
98
98
  };
99
- const authorizationUrl = async (session, plugin, host) => {
99
+ const authorizationUrl = async (session, plugin, base) => {
100
100
  if (config.plugins.find((item) => item.id === plugin)?.oauth.deviceAuthorizationUrl) {
101
101
  const state = await runtime.connectDevice(session, plugin);
102
- return `http://${host}/api/plugins/device/${plugin}?state=${state}`;
102
+ return `${base}/api/plugins/device/${plugin}?state=${state}`;
103
103
  }
104
- const authorization = new URL(runtime.connect(session, plugin, `http://${host}/api/plugins/callback/${plugin}`));
104
+ const authorization = new URL(runtime.connect(session, plugin, `${base}/api/plugins/callback/${plugin}`));
105
105
  const mock = origins.get(authorization.origin);
106
106
  return mock
107
- ? `http://${host}/api/plugins/mock/${mock.id}${authorization.pathname}${authorization.search}`
107
+ ? `${base}/api/plugins/mock/${mock.id}${authorization.pathname}${authorization.search}`
108
108
  : authorization.href;
109
109
  };
110
110
  const handle = async (req, res) => {
@@ -121,6 +121,7 @@ export const createPluginHandler = (plugins, presentation = { mocks: {} }, crede
121
121
  };
122
122
  try {
123
123
  const host = req.headers.host ?? "";
124
+ const base = `${requestScheme(req)}://${host}`;
124
125
  if (!["localhost", "127.0.0.1", "[::1]"].some((name) => host === `${name}:${req.socket.localPort}`))
125
126
  throw new PluginError(403, "Plugins require the local viewer");
126
127
  if (req.method === "GET" && url.pathname === "/api/plugins/events") {
@@ -142,7 +143,7 @@ export const createPluginHandler = (plugins, presentation = { mocks: {} }, crede
142
143
  throw new PluginError(404, "Mock authorization is not configured");
143
144
  if (req.method !== "GET" &&
144
145
  (req.method !== "POST" ||
145
- req.headers.origin !== `http://${host}` ||
146
+ req.headers.origin !== base ||
146
147
  req.headers["content-type"]?.split(";")[0] !==
147
148
  "application/x-www-form-urlencoded"))
148
149
  throw new PluginError(403, "Mock consent requires a same-origin request");
@@ -156,7 +157,7 @@ export const createPluginHandler = (plugins, presentation = { mocks: {} }, crede
156
157
  : {}),
157
158
  }));
158
159
  const location = response.headers.get("location");
159
- if (location && !location.startsWith(`http://${host}/api/plugins/callback/`))
160
+ if (location && !location.startsWith(`${base}/api/plugins/callback/`))
160
161
  throw new PluginError(400, "Invalid mock callback");
161
162
  // Preserve the Origin header on local consent form submissions.
162
163
  res.setHeader("referrer-policy", "same-origin");
@@ -184,13 +185,13 @@ export const createPluginHandler = (plugins, presentation = { mocks: {} }, crede
184
185
  if (!ticket ||
185
186
  ticket.expires <= Date.now() ||
186
187
  ticket.plugin !== login[1] ||
187
- ticket.origin !== `http://${host}`)
188
+ ticket.origin !== base)
188
189
  throw new PluginError(400, "Invalid or expired login link");
189
190
  tickets.delete(key);
190
191
  if (!runtime.hasSession(session))
191
192
  createSession();
192
193
  res.writeHead(303, {
193
- location: await authorizationUrl(session, ticket.plugin, host),
194
+ location: await authorizationUrl(session, ticket.plugin, base),
194
195
  });
195
196
  res.end();
196
197
  return true;
@@ -235,7 +236,7 @@ setTimeout(poll, ${pending.retryAfter * 1000});
235
236
  if (req.method === "GET" && callback?.[1]) {
236
237
  let cancelled = false;
237
238
  try {
238
- await runtime.callback(session, callback[1], `http://${host}${url.pathname}`, url.searchParams);
239
+ await runtime.callback(session, callback[1], `${base}${url.pathname}`, url.searchParams);
239
240
  }
240
241
  catch (error) {
241
242
  if (!isPluginError(error) ||
@@ -274,7 +275,7 @@ setTimeout(poll, ${pending.retryAfter * 1000});
274
275
  (credentials || input.action === "connect" || input.action === "status"))
275
276
  createSession();
276
277
  if (input.action === "connect") {
277
- send(200, { url: await authorizationUrl(session, input.plugin, host) });
278
+ send(200, { url: await authorizationUrl(session, input.plugin, base) });
278
279
  }
279
280
  else if (input.action === "status") {
280
281
  send(200, { user: runtime.status(session, input.plugin) ?? null });
@@ -0,0 +1 @@
1
+ export * from "../frontend/resource-library.js";
@@ -0,0 +1 @@
1
+ export * from "../frontend/resource-library.js";
@@ -0,0 +1,5 @@
1
+ export declare const selfUpdate: () => void;
2
+ export declare const prepareSelfDocs: () => Promise<{
3
+ root: string;
4
+ dispose: () => void;
5
+ }>;