@warlock.js/grimoire 0.0.0-stage → 5.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/LICENSE +21 -0
  3. package/README.md +55 -2
  4. package/esm/apps/check-apps.mjs +207 -0
  5. package/esm/apps/check-apps.mjs.map +1 -0
  6. package/esm/apps/index.mjs +4 -0
  7. package/esm/apps/match-apps.d.mts +12 -0
  8. package/esm/apps/match-apps.d.mts.map +1 -0
  9. package/esm/apps/match-apps.mjs +30 -0
  10. package/esm/apps/match-apps.mjs.map +1 -0
  11. package/esm/book/build.d.mts +14 -0
  12. package/esm/book/build.d.mts.map +1 -0
  13. package/esm/book/build.mjs +300 -0
  14. package/esm/book/build.mjs.map +1 -0
  15. package/esm/book/index.mjs +5 -0
  16. package/esm/book/io.mjs +162 -0
  17. package/esm/book/io.mjs.map +1 -0
  18. package/esm/book/normalize.mjs +71 -0
  19. package/esm/book/normalize.mjs.map +1 -0
  20. package/esm/book/render.mjs +262 -0
  21. package/esm/book/render.mjs.map +1 -0
  22. package/esm/book/write.d.mts +12 -0
  23. package/esm/book/write.d.mts.map +1 -0
  24. package/esm/book/write.mjs +90 -0
  25. package/esm/book/write.mjs.map +1 -0
  26. package/esm/bookmap/build.d.mts +21 -0
  27. package/esm/bookmap/build.d.mts.map +1 -0
  28. package/esm/bookmap/build.mjs +272 -0
  29. package/esm/bookmap/build.mjs.map +1 -0
  30. package/esm/bookmap/index.mjs +5 -0
  31. package/esm/bookmap/steps.mjs +137 -0
  32. package/esm/bookmap/steps.mjs.map +1 -0
  33. package/esm/bookmap/write.d.mts +19 -0
  34. package/esm/bookmap/write.d.mts.map +1 -0
  35. package/esm/bookmap/write.mjs +118 -0
  36. package/esm/bookmap/write.mjs.map +1 -0
  37. package/esm/check/check-grimoire.d.mts +7 -0
  38. package/esm/check/check-grimoire.d.mts.map +1 -0
  39. package/esm/check/check-grimoire.mjs +98 -0
  40. package/esm/check/check-grimoire.mjs.map +1 -0
  41. package/esm/check/format-check-report.d.mts +20 -0
  42. package/esm/check/format-check-report.d.mts.map +1 -0
  43. package/esm/check/format-check-report.mjs +55 -0
  44. package/esm/check/format-check-report.mjs.map +1 -0
  45. package/esm/check/index.mjs +4 -0
  46. package/esm/check/rules/book-notes.mjs +18 -0
  47. package/esm/check/rules/book-notes.mjs.map +1 -0
  48. package/esm/check/rules/criteria.mjs +48 -0
  49. package/esm/check/rules/criteria.mjs.map +1 -0
  50. package/esm/check/rules/links.mjs +196 -0
  51. package/esm/check/rules/links.mjs.map +1 -0
  52. package/esm/check/rules/lookup.mjs +41 -0
  53. package/esm/check/rules/lookup.mjs.map +1 -0
  54. package/esm/check/rules/source-files.mjs +119 -0
  55. package/esm/check/rules/source-files.mjs.map +1 -0
  56. package/esm/check/rules/versions.mjs +92 -0
  57. package/esm/check/rules/versions.mjs.map +1 -0
  58. package/esm/codes/codes.d.mts +182 -0
  59. package/esm/codes/codes.d.mts.map +1 -0
  60. package/esm/codes/codes.mjs +111 -0
  61. package/esm/codes/codes.mjs.map +1 -0
  62. package/esm/codes/index.d.mts +33 -0
  63. package/esm/codes/index.d.mts.map +1 -0
  64. package/esm/codes/index.mjs +63 -0
  65. package/esm/codes/index.mjs.map +1 -0
  66. package/esm/contracts/adapter.d.mts +209 -0
  67. package/esm/contracts/adapter.d.mts.map +1 -0
  68. package/esm/contracts/book.d.mts +233 -0
  69. package/esm/contracts/book.d.mts.map +1 -0
  70. package/esm/contracts/book.mjs +7 -0
  71. package/esm/contracts/book.mjs.map +1 -0
  72. package/esm/contracts/bookmap.d.mts +175 -0
  73. package/esm/contracts/bookmap.d.mts.map +1 -0
  74. package/esm/contracts/findings.d.mts +79 -0
  75. package/esm/contracts/findings.d.mts.map +1 -0
  76. package/esm/contracts/location.d.mts +22 -0
  77. package/esm/contracts/location.d.mts.map +1 -0
  78. package/esm/contracts/releases.d.mts +53 -0
  79. package/esm/contracts/releases.d.mts.map +1 -0
  80. package/esm/contracts/scry.d.mts +143 -0
  81. package/esm/contracts/scry.d.mts.map +1 -0
  82. package/esm/contracts/snapshot.d.mts +52 -0
  83. package/esm/contracts/snapshot.d.mts.map +1 -0
  84. package/esm/contracts/test-results.d.mts +63 -0
  85. package/esm/contracts/test-results.d.mts.map +1 -0
  86. package/esm/contracts/written.d.mts +363 -0
  87. package/esm/contracts/written.d.mts.map +1 -0
  88. package/esm/contracts/written.mjs +19 -0
  89. package/esm/contracts/written.mjs.map +1 -0
  90. package/esm/devtools/data.mjs +171 -0
  91. package/esm/devtools/data.mjs.map +1 -0
  92. package/esm/devtools/graphs.mjs +142 -0
  93. package/esm/devtools/graphs.mjs.map +1 -0
  94. package/esm/devtools/index.d.mts +35 -0
  95. package/esm/devtools/index.d.mts.map +1 -0
  96. package/esm/devtools/index.mjs +102 -0
  97. package/esm/devtools/index.mjs.map +1 -0
  98. package/esm/devtools/site.d.mts +26 -0
  99. package/esm/devtools/site.d.mts.map +1 -0
  100. package/esm/devtools/site.mjs +190 -0
  101. package/esm/devtools/site.mjs.map +1 -0
  102. package/esm/devtools/snapshot-source.mjs +70 -0
  103. package/esm/devtools/snapshot-source.mjs.map +1 -0
  104. package/esm/front-matter/index.d.mts +33 -0
  105. package/esm/front-matter/index.d.mts.map +1 -0
  106. package/esm/front-matter/index.mjs +130 -0
  107. package/esm/front-matter/index.mjs.map +1 -0
  108. package/esm/graph/index.d.mts +15 -0
  109. package/esm/graph/index.d.mts.map +1 -0
  110. package/esm/graph/index.mjs +42 -0
  111. package/esm/graph/index.mjs.map +1 -0
  112. package/esm/index.d.mts +33 -0
  113. package/esm/index.mjs +33 -0
  114. package/esm/ownership/index.d.mts +8 -0
  115. package/esm/ownership/index.d.mts.map +1 -0
  116. package/esm/ownership/index.mjs +137 -0
  117. package/esm/ownership/index.mjs.map +1 -0
  118. package/esm/paths/index.d.mts +58 -0
  119. package/esm/paths/index.d.mts.map +1 -0
  120. package/esm/paths/index.mjs +137 -0
  121. package/esm/paths/index.mjs.map +1 -0
  122. package/esm/proves/index.mjs +3 -0
  123. package/esm/proves/scan-proofs.d.mts +22 -0
  124. package/esm/proves/scan-proofs.d.mts.map +1 -0
  125. package/esm/proves/scan-proofs.mjs +214 -0
  126. package/esm/proves/scan-proofs.mjs.map +1 -0
  127. package/esm/releases/index.d.mts +29 -0
  128. package/esm/releases/index.d.mts.map +1 -0
  129. package/esm/releases/index.mjs +157 -0
  130. package/esm/releases/index.mjs.map +1 -0
  131. package/esm/scry/format.d.mts +14 -0
  132. package/esm/scry/format.d.mts.map +1 -0
  133. package/esm/scry/format.mjs +193 -0
  134. package/esm/scry/format.mjs.map +1 -0
  135. package/esm/scry/index.mjs +5 -0
  136. package/esm/scry/parse.d.mts +10 -0
  137. package/esm/scry/parse.d.mts.map +1 -0
  138. package/esm/scry/parse.mjs +108 -0
  139. package/esm/scry/parse.mjs.map +1 -0
  140. package/esm/scry/query.d.mts +11 -0
  141. package/esm/scry/query.d.mts.map +1 -0
  142. package/esm/scry/query.mjs +457 -0
  143. package/esm/scry/query.mjs.map +1 -0
  144. package/esm/tasks/index.mjs +116 -0
  145. package/esm/tasks/index.mjs.map +1 -0
  146. package/esm/test-results/criterion-status.d.mts +15 -0
  147. package/esm/test-results/criterion-status.d.mts.map +1 -0
  148. package/esm/test-results/criterion-status.mjs +17 -0
  149. package/esm/test-results/criterion-status.mjs.map +1 -0
  150. package/esm/test-results/index.d.mts +8 -0
  151. package/esm/test-results/index.d.mts.map +1 -0
  152. package/esm/test-results/index.mjs +124 -0
  153. package/esm/test-results/index.mjs.map +1 -0
  154. package/esm/vitest/index.d.mts +15 -0
  155. package/esm/vitest/index.d.mts.map +1 -0
  156. package/esm/vitest/index.mjs +146 -0
  157. package/esm/vitest/index.mjs.map +1 -0
  158. package/esm/warlock/actions.mjs +265 -0
  159. package/esm/warlock/actions.mjs.map +1 -0
  160. package/esm/warlock/adapter.d.mts +28 -0
  161. package/esm/warlock/adapter.d.mts.map +1 -0
  162. package/esm/warlock/adapter.mjs +377 -0
  163. package/esm/warlock/adapter.mjs.map +1 -0
  164. package/esm/warlock/commands.d.mts +15 -0
  165. package/esm/warlock/commands.d.mts.map +1 -0
  166. package/esm/warlock/commands.mjs +199 -0
  167. package/esm/warlock/commands.mjs.map +1 -0
  168. package/esm/warlock/index.d.mts +4 -0
  169. package/esm/warlock/index.mjs +5 -0
  170. package/esm/warlock/mcp-tools.mjs +247 -0
  171. package/esm/warlock/mcp-tools.mjs.map +1 -0
  172. package/esm/warlock/mobile-facts.d.mts +32 -0
  173. package/esm/warlock/mobile-facts.d.mts.map +1 -0
  174. package/esm/warlock/mobile-facts.mjs +185 -0
  175. package/esm/warlock/mobile-facts.mjs.map +1 -0
  176. package/esm/workspace/index.d.mts +11 -0
  177. package/esm/workspace/index.d.mts.map +1 -0
  178. package/esm/workspace/index.mjs +122 -0
  179. package/esm/workspace/index.mjs.map +1 -0
  180. package/esm/written/apps.mjs +227 -0
  181. package/esm/written/apps.mjs.map +1 -0
  182. package/esm/written/features.mjs +400 -0
  183. package/esm/written/features.mjs.map +1 -0
  184. package/esm/written/fields.mjs +173 -0
  185. package/esm/written/fields.mjs.map +1 -0
  186. package/esm/written/index.mjs +3 -0
  187. package/esm/written/lists.mjs +68 -0
  188. package/esm/written/lists.mjs.map +1 -0
  189. package/esm/written/markdown.mjs +173 -0
  190. package/esm/written/markdown.mjs.map +1 -0
  191. package/esm/written/parse-grimoire.d.mts +20 -0
  192. package/esm/written/parse-grimoire.d.mts.map +1 -0
  193. package/esm/written/parse-grimoire.mjs +552 -0
  194. package/esm/written/parse-grimoire.mjs.map +1 -0
  195. package/esm/written/sink.mjs +65 -0
  196. package/esm/written/sink.mjs.map +1 -0
  197. package/esm/written/tasks-releases.mjs +166 -0
  198. package/esm/written/tasks-releases.mjs.map +1 -0
  199. package/llms-full.txt +869 -0
  200. package/llms.txt +15 -0
  201. package/package.json +66 -4
  202. package/skills/backfill-a-grimoire/SKILL.md +128 -0
  203. package/skills/describe-an-app/SKILL.md +162 -0
  204. package/skills/document-a-file/SKILL.md +75 -0
  205. package/skills/index.md +26 -0
  206. package/skills/record-a-change/SKILL.md +139 -0
  207. package/skills/use-the-grimoire/SKILL.md +137 -0
  208. package/skills/write-a-feature/SKILL.md +168 -0
  209. package/ui/grimoire-static.js +136 -0
  210. package/ui/grimoire-view.js +1005 -0
  211. package/ui/grimoire.css +88 -0
@@ -0,0 +1,142 @@
1
+ //#region ../../packages/grimoire/src/devtools/graphs.ts
2
+ /** The most nodes a graph answer holds. */
3
+ const GRAPH_LIMIT = 60;
4
+ /** Collects nodes and edges, dropping what goes over the limit. */
5
+ var GraphBuilder = class {
6
+ nodes = /* @__PURE__ */ new Map();
7
+ edges = /* @__PURE__ */ new Map();
8
+ node(id, label, type) {
9
+ if (this.nodes.has(id)) return true;
10
+ if (this.nodes.size >= 60) return false;
11
+ this.nodes.set(id, {
12
+ id,
13
+ label,
14
+ type
15
+ });
16
+ return true;
17
+ }
18
+ edge(from, to, type, weight) {
19
+ if (!this.nodes.has(from) || !this.nodes.has(to) || from === to) return;
20
+ const key = `${from}\n${to}\n${type}`;
21
+ if (this.edges.has(key)) return;
22
+ this.edges.set(key, weight === void 0 ? {
23
+ from,
24
+ to,
25
+ type
26
+ } : {
27
+ from,
28
+ to,
29
+ type,
30
+ weight
31
+ });
32
+ }
33
+ build() {
34
+ return {
35
+ nodes: [...this.nodes.values()],
36
+ edges: [...this.edges.values()]
37
+ };
38
+ }
39
+ };
40
+ /** The short name shown for a project path. */
41
+ function fileLabel(file) {
42
+ return file.split("/").slice(-2).join("/");
43
+ }
44
+ /** A file, the files it imports and the files that import it. `null` when the file is not in the book. */
45
+ function fileGraph(snapshot, file) {
46
+ const entry = snapshot.book.facts.files.find((candidate) => candidate.file === file);
47
+ if (entry === void 0) return null;
48
+ const graph = new GraphBuilder();
49
+ const center = `file:${file}`;
50
+ graph.node(center, fileLabel(file), "center");
51
+ for (const target of entry.imports) {
52
+ if (target.file === null) continue;
53
+ if (graph.node(`file:${target.file}`, fileLabel(target.file), "file")) graph.edge(center, `file:${target.file}`, "imports");
54
+ }
55
+ for (const importer of entry.importedBy) if (graph.node(`file:${importer}`, fileLabel(importer), "file")) graph.edge(`file:${importer}`, center, "imports");
56
+ return graph.build();
57
+ }
58
+ /** A feature, its flows, the apps showing them and the features it borrows from, lends to or affects. `null` for an unknown feature. */
59
+ function featureGraph(snapshot, feature) {
60
+ const written = snapshot.written.features.find((candidate) => candidate.id === feature);
61
+ if (written === void 0) return null;
62
+ const graph = new GraphBuilder();
63
+ const center = `feature:${feature}`;
64
+ graph.node(center, feature, "center");
65
+ for (const flow of written.flows) {
66
+ const id = `flow:${flow.ref}`;
67
+ if (graph.node(id, flow.id.value, "flow")) graph.edge(center, id, "has");
68
+ for (const step of flow.steps) {
69
+ if (step.affects === null) continue;
70
+ const other = `feature:${step.affects.feature}`;
71
+ if (graph.node(other, step.affects.feature, "feature")) graph.edge(id, other, "affects");
72
+ }
73
+ }
74
+ const bookmap = snapshot.collected.features[feature];
75
+ for (const borrowed of bookmap?.borrowed ?? []) {
76
+ if (borrowed.owner === null) continue;
77
+ const other = `feature:${borrowed.owner}`;
78
+ if (graph.node(other, borrowed.owner, "feature")) graph.edge(center, other, "borrows");
79
+ }
80
+ for (const [other, ownership] of Object.entries(snapshot.ownership.features)) if (other !== feature && ownership.borrowed.some((file) => snapshot.ownership.files[file]?.owner === feature)) {
81
+ if (graph.node(`feature:${other}`, other, "feature")) graph.edge(`feature:${other}`, center, "borrows");
82
+ }
83
+ for (const [flowRef, flowMap] of Object.entries(snapshot.collected.flows)) {
84
+ if (flowMap.feature !== feature) continue;
85
+ for (const shown of flowMap.shownBy) {
86
+ const id = `app:${shown.app}`;
87
+ if (graph.node(id, shown.app, "app")) graph.edge(id, `flow:${flowRef}`, "shows");
88
+ }
89
+ }
90
+ return graph.build();
91
+ }
92
+ /** A page (or screen), its layout, its blocks and the flows the blocks show. `null` for an unknown page. */
93
+ function pageGraph(snapshot, app, pageKey) {
94
+ const written = snapshot.written.apps.find((candidate) => candidate.id.value === app);
95
+ const page = [...written?.pages ?? [], ...written?.screens ?? []].find((candidate) => candidate.id === pageKey || candidate.route?.value === pageKey || candidate.screen?.value === pageKey);
96
+ if (written === void 0 || page === void 0) return null;
97
+ const graph = new GraphBuilder();
98
+ const center = `page:${app}/${page.id}`;
99
+ graph.node(center, page.heading?.value ?? page.id, "center");
100
+ const layoutId = page.layout?.value ?? null;
101
+ const layout = layoutId === null ? void 0 : written.layouts.find((candidate) => candidate.id === layoutId);
102
+ if (layout !== void 0 && graph.node(`layout:${app}/${layout.id}`, layout.id, "layout")) graph.edge(`layout:${app}/${layout.id}`, center, "wraps");
103
+ const blocks = [...layout?.blocks ?? [], ...page.blocks];
104
+ for (const block of blocks) {
105
+ const id = `block:${app}/${page.id}/${block.block}`;
106
+ if (!graph.node(id, block.block, "block")) continue;
107
+ graph.edge(center, id, "shows");
108
+ if (block.flow !== null && graph.node(`flow:${block.flow}`, block.flow, "flow")) graph.edge(id, `flow:${block.flow}`, "shows");
109
+ }
110
+ return graph.build();
111
+ }
112
+ /** Modules as nodes, weighted import edges between them; the most connected modules when there are more than the limit. */
113
+ function moduleGraph(snapshot) {
114
+ const moduleOf = /* @__PURE__ */ new Map();
115
+ const sizes = /* @__PURE__ */ new Map();
116
+ for (const file of snapshot.book.facts.files) {
117
+ moduleOf.set(file.file, file.module);
118
+ sizes.set(file.module, (sizes.get(file.module) ?? 0) + 1);
119
+ }
120
+ const weights = /* @__PURE__ */ new Map();
121
+ const degree = /* @__PURE__ */ new Map();
122
+ for (const file of snapshot.book.facts.files) for (const target of file.imports) {
123
+ const to = target.file === null ? void 0 : moduleOf.get(target.file);
124
+ if (to === void 0 || to === file.module) continue;
125
+ const key = `${file.module}\n${to}`;
126
+ weights.set(key, (weights.get(key) ?? 0) + 1);
127
+ degree.set(file.module, (degree.get(file.module) ?? 0) + 1);
128
+ degree.set(to, (degree.get(to) ?? 0) + 1);
129
+ }
130
+ const modules = [...sizes.keys()].sort((left, right) => (degree.get(right) ?? 0) - (degree.get(left) ?? 0) || left.localeCompare(right)).slice(0, 60);
131
+ const graph = new GraphBuilder();
132
+ for (const module of modules) graph.node(`module:${module}`, `${module} (${sizes.get(module) ?? 0})`, "module");
133
+ for (const [key, weight] of [...weights.entries()].sort(([left], [right]) => left.localeCompare(right))) {
134
+ const [from, to] = key.split("\n");
135
+ if (from !== void 0 && to !== void 0) graph.edge(`module:${from}`, `module:${to}`, "imports", weight);
136
+ }
137
+ return graph.build();
138
+ }
139
+
140
+ //#endregion
141
+ export { featureGraph, fileGraph, moduleGraph, pageGraph };
142
+ //# sourceMappingURL=graphs.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphs.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/graphs.ts"],"sourcesContent":["/**\n * The small graphs of the tab: a file's neighbours, a feature and its\n * neighbours, a page and its blocks, and module coupling. Each answer has at\n * most `GRAPH_LIMIT` nodes. Node ids carry their kind (`file:`, `feature:`,\n * `flow:`, `page:`, `block:`, `layout:`, `module:`, `app:`) so the view can link them.\n */\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\n\n/** The most nodes a graph answer holds. */\nexport const GRAPH_LIMIT = 60;\n\nexport type GraphNode = { id: string; label: string; type: string };\nexport type GraphEdge = { from: string; to: string; type: string; weight?: number };\nexport type GrimoireGraph = { nodes: GraphNode[]; edges: GraphEdge[] };\n\n/** Collects nodes and edges, dropping what goes over the limit. */\nclass GraphBuilder {\n private readonly nodes = new Map<string, GraphNode>();\n private readonly edges = new Map<string, GraphEdge>();\n\n public node(id: string, label: string, type: string): boolean {\n if (this.nodes.has(id)) return true;\n\n if (this.nodes.size >= GRAPH_LIMIT) return false;\n\n this.nodes.set(id, { id, label, type });\n\n return true;\n }\n\n public edge(from: string, to: string, type: string, weight?: number): void {\n if (!this.nodes.has(from) || !this.nodes.has(to) || from === to) return;\n\n const key = `${from}\\n${to}\\n${type}`;\n\n if (this.edges.has(key)) return;\n\n this.edges.set(key, weight === undefined ? { from, to, type } : { from, to, type, weight });\n }\n\n public build(): GrimoireGraph {\n return { nodes: [...this.nodes.values()], edges: [...this.edges.values()] };\n }\n}\n\n/** The short name shown for a project path. */\nfunction fileLabel(file: string): string {\n const parts = file.split(\"/\");\n\n return parts.slice(-2).join(\"/\");\n}\n\n/** A file, the files it imports and the files that import it. `null` when the file is not in the book. */\nexport function fileGraph(snapshot: GrimoireSnapshot, file: string): GrimoireGraph | null {\n const entry = snapshot.book.facts.files.find((candidate) => candidate.file === file);\n\n if (entry === undefined) return null;\n\n const graph = new GraphBuilder();\n const center = `file:${file}`;\n\n graph.node(center, fileLabel(file), \"center\");\n\n for (const target of entry.imports) {\n if (target.file === null) continue;\n\n if (graph.node(`file:${target.file}`, fileLabel(target.file), \"file\")) {\n graph.edge(center, `file:${target.file}`, \"imports\");\n }\n }\n\n for (const importer of entry.importedBy) {\n if (graph.node(`file:${importer}`, fileLabel(importer), \"file\")) {\n graph.edge(`file:${importer}`, center, \"imports\");\n }\n }\n\n return graph.build();\n}\n\n/** A feature, its flows, the apps showing them and the features it borrows from, lends to or affects. `null` for an unknown feature. */\nexport function featureGraph(snapshot: GrimoireSnapshot, feature: string): GrimoireGraph | null {\n const written = snapshot.written.features.find((candidate) => candidate.id === feature);\n\n if (written === undefined) return null;\n\n const graph = new GraphBuilder();\n const center = `feature:${feature}`;\n\n graph.node(center, feature, \"center\");\n\n for (const flow of written.flows) {\n const id = `flow:${flow.ref}`;\n\n if (graph.node(id, flow.id.value, \"flow\")) graph.edge(center, id, \"has\");\n\n for (const step of flow.steps) {\n if (step.affects === null) continue;\n\n const other = `feature:${step.affects.feature}`;\n\n if (graph.node(other, step.affects.feature, \"feature\")) graph.edge(id, other, \"affects\");\n }\n }\n\n const bookmap = snapshot.collected.features[feature];\n\n for (const borrowed of bookmap?.borrowed ?? []) {\n if (borrowed.owner === null) continue;\n\n const other = `feature:${borrowed.owner}`;\n\n if (graph.node(other, borrowed.owner, \"feature\")) graph.edge(center, other, \"borrows\");\n }\n\n for (const [other, ownership] of Object.entries(snapshot.ownership.features)) {\n if (\n other !== feature &&\n ownership.borrowed.some((file) => snapshot.ownership.files[file]?.owner === feature)\n ) {\n if (graph.node(`feature:${other}`, other, \"feature\"))\n graph.edge(`feature:${other}`, center, \"borrows\");\n }\n }\n\n for (const [flowRef, flowMap] of Object.entries(snapshot.collected.flows)) {\n if (flowMap.feature !== feature) continue;\n\n for (const shown of flowMap.shownBy) {\n const id = `app:${shown.app}`;\n\n if (graph.node(id, shown.app, \"app\")) graph.edge(id, `flow:${flowRef}`, \"shows\");\n }\n }\n\n return graph.build();\n}\n\n/** A page (or screen), its layout, its blocks and the flows the blocks show. `null` for an unknown page. */\nexport function pageGraph(\n snapshot: GrimoireSnapshot,\n app: string,\n pageKey: string,\n): GrimoireGraph | null {\n const written = snapshot.written.apps.find((candidate) => candidate.id.value === app);\n const page = [...(written?.pages ?? []), ...(written?.screens ?? [])].find(\n (candidate) =>\n candidate.id === pageKey ||\n candidate.route?.value === pageKey ||\n candidate.screen?.value === pageKey,\n );\n\n if (written === undefined || page === undefined) return null;\n\n const graph = new GraphBuilder();\n const center = `page:${app}/${page.id}`;\n\n graph.node(center, page.heading?.value ?? page.id, \"center\");\n\n const layoutId = page.layout?.value ?? null;\n const layout =\n layoutId === null ? undefined : written.layouts.find((candidate) => candidate.id === layoutId);\n\n if (layout !== undefined && graph.node(`layout:${app}/${layout.id}`, layout.id, \"layout\")) {\n graph.edge(`layout:${app}/${layout.id}`, center, \"wraps\");\n }\n\n const blocks = [...(layout?.blocks ?? []), ...page.blocks];\n\n for (const block of blocks) {\n const id = `block:${app}/${page.id}/${block.block}`;\n\n if (!graph.node(id, block.block, \"block\")) continue;\n\n graph.edge(center, id, \"shows\");\n\n if (block.flow !== null && graph.node(`flow:${block.flow}`, block.flow, \"flow\")) {\n graph.edge(id, `flow:${block.flow}`, \"shows\");\n }\n }\n\n return graph.build();\n}\n\n/** Modules as nodes, weighted import edges between them; the most connected modules when there are more than the limit. */\nexport function moduleGraph(snapshot: GrimoireSnapshot): GrimoireGraph {\n const moduleOf = new Map<string, string>();\n const sizes = new Map<string, number>();\n\n for (const file of snapshot.book.facts.files) {\n moduleOf.set(file.file, file.module);\n sizes.set(file.module, (sizes.get(file.module) ?? 0) + 1);\n }\n\n const weights = new Map<string, number>();\n const degree = new Map<string, number>();\n\n for (const file of snapshot.book.facts.files) {\n for (const target of file.imports) {\n const to = target.file === null ? undefined : moduleOf.get(target.file);\n\n if (to === undefined || to === file.module) continue;\n\n const key = `${file.module}\\n${to}`;\n\n weights.set(key, (weights.get(key) ?? 0) + 1);\n degree.set(file.module, (degree.get(file.module) ?? 0) + 1);\n degree.set(to, (degree.get(to) ?? 0) + 1);\n }\n }\n\n const modules = [...sizes.keys()]\n .sort(\n (left, right) =>\n (degree.get(right) ?? 0) - (degree.get(left) ?? 0) || left.localeCompare(right),\n )\n .slice(0, GRAPH_LIMIT);\n const graph = new GraphBuilder();\n\n for (const module of modules)\n graph.node(`module:${module}`, `${module} (${sizes.get(module) ?? 0})`, \"module\");\n\n for (const [key, weight] of [...weights.entries()].sort(([left], [right]) =>\n left.localeCompare(right),\n )) {\n const [from, to] = key.split(\"\\n\");\n\n if (from !== undefined && to !== undefined)\n graph.edge(`module:${from}`, `module:${to}`, \"imports\", weight);\n }\n\n return graph.build();\n}\n"],"mappings":";;AASA,MAAa,cAAc;;AAO3B,IAAM,eAAN,MAAmB;CACjB,AAAiB,wBAAQ,IAAI,IAAuB;CACpD,AAAiB,wBAAQ,IAAI,IAAuB;CAEpD,AAAO,KAAK,IAAY,OAAe,MAAuB;EAC5D,IAAI,KAAK,MAAM,IAAI,EAAE,GAAG,OAAO;EAE/B,IAAI,KAAK,MAAM,YAAqB,OAAO;EAE3C,KAAK,MAAM,IAAI,IAAI;GAAE;GAAI;GAAO;EAAK,CAAC;EAEtC,OAAO;CACT;CAEA,A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M,CAAC,KAAK,WAAW,CAAC,GAAG,QAAQ,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,WAChE,KAAK,cAAc,KAAK,CAC1B,GAAG;EACD,MAAM,CAAC,MAAM,MAAM,IAAI,MAAM,IAAI;EAEjC,IAAI,SAAS,UAAa,OAAO,QAC/B,MAAM,KAAK,UAAU,QAAQ,UAAU,MAAM,WAAW,MAAM;CAClE;CAEA,OAAO,MAAM,MAAM;AACrB"}
@@ -0,0 +1,35 @@
1
+ import { BookAdapter } from "../contracts/adapter.mjs";
2
+ import { ExportGrimoireSiteOptions, exportGrimoireSite } from "./site.mjs";
3
+ //#region ../../packages/grimoire/src/devtools/index.d.ts
4
+ /** The parts of devtools' `DevtoolsPanelRequest` the routes read. */
5
+ export type GrimoirePanelRequest = {
6
+ params: Readonly<Record<string, string>>;
7
+ query: Readonly<Record<string, string | readonly string[]>>;
8
+ body: unknown;
9
+ };
10
+ /** Devtools' `DevtoolsPanel`, structurally. */
11
+ export type GrimoireDevtoolsPanel = {
12
+ id: string;
13
+ title: string;
14
+ view: string | URL;
15
+ routes?: readonly {
16
+ method?: "GET" | "POST";
17
+ path: string;
18
+ handler: (request: GrimoirePanelRequest) => unknown;
19
+ }[];
20
+ assets?: Readonly<Record<string, string | URL>>;
21
+ };
22
+ /** What the panel factory takes: devtools passes `{ root }`; the rest is for tests and custom setups. */
23
+ export type GrimoirePanelContext = {
24
+ /** The app root. */
25
+ root: string;
26
+ /** The adapter to open the book with. Default: the Warlock adapter, loaded on first request. */
27
+ adapter?: BookAdapter | (() => Promise<BookAdapter>);
28
+ /** How long an opened snapshot is reused when the book manifest did not change (ms). Default 2000, longer after a slow open. */
29
+ ttlMs?: number;
30
+ };
31
+ /** Build the panel for the app at `root`. */
32
+ export declare function grimoireDevtoolsPanel(context: GrimoirePanelContext): Promise<GrimoireDevtoolsPanel>;
33
+ //#endregion
34
+ export { type ExportGrimoireSiteOptions, grimoireDevtoolsPanel as default, exportGrimoireSite };
35
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/index.ts"],"mappings":";;;;YAuBY;EACV,QAAQ,SAAS;EACjB,OAAO,SAAS;EAChB;;;YAIU;EACV;EACA;EACA,eAAe;EACf;IACE;IACA;IACA,UAAU,SAAS;;EAErB,SAAS,SAAS,wBAAwB;;;YAIhC;;EAEV;;EAEA,UAAU,qBAAqB,QAAQ;;EAEvC;;;wBAWoB,sBACpB,SAAS,uBACR,QAAQ"}
@@ -0,0 +1,102 @@
1
+ import { apps, check, feature, file, flow, graphOfFeature, graphOfFile, graphOfModules, graphOfPage, impact, page, release, releases, route, search, summary, tasks } from "./data.mjs";
2
+ import { createSnapshotSource } from "./snapshot-source.mjs";
3
+ import { exportGrimoireSite } from "./site.mjs";
4
+
5
+ //#region ../../packages/grimoire/src/devtools/index.ts
6
+ /** The first value of a query parameter. */
7
+ function one(query, name) {
8
+ const value = query[name];
9
+ return Array.isArray(value) ? value[0] : value;
10
+ }
11
+ /** Build the panel for the app at `root`. */
12
+ async function grimoireDevtoolsPanel(context) {
13
+ const source = createSnapshotSource(context.root, {
14
+ write: true,
15
+ ...context.adapter === void 0 ? {} : { adapter: context.adapter },
16
+ ...context.ttlMs === void 0 ? {} : { ttlMs: context.ttlMs }
17
+ });
18
+ const answer = (read) => async (request) => read(await source.get(), request);
19
+ return {
20
+ id: "grimoire",
21
+ title: "Grimoire",
22
+ view: new URL("../../ui/grimoire-view.js", import.meta.url),
23
+ assets: { "grimoire.css": new URL("../../ui/grimoire.css", import.meta.url) },
24
+ routes: [
25
+ {
26
+ path: "/summary",
27
+ handler: answer((snapshot) => summary(snapshot))
28
+ },
29
+ {
30
+ path: "/search",
31
+ handler: answer((snapshot, { query }) => {
32
+ const limit = Number(one(query, "limit"));
33
+ return search(snapshot, one(query, "q") ?? "", Number.isFinite(limit) && limit > 0 ? limit : void 0);
34
+ })
35
+ },
36
+ {
37
+ path: "/file",
38
+ handler: answer((snapshot, { query }) => file(snapshot, one(query, "path")))
39
+ },
40
+ {
41
+ path: "/impact",
42
+ handler: answer((snapshot, { query }) => impact(snapshot, one(query, "path")))
43
+ },
44
+ {
45
+ path: "/route",
46
+ handler: answer((snapshot, { query }) => route(snapshot, one(query, "method"), one(query, "path")))
47
+ },
48
+ {
49
+ path: "/features/:feature",
50
+ handler: answer((snapshot, { params }) => feature(snapshot, params.feature))
51
+ },
52
+ {
53
+ path: "/flows/:feature/:flow",
54
+ handler: answer((snapshot, { params }) => flow(snapshot, params.feature, params.flow))
55
+ },
56
+ {
57
+ path: "/apps",
58
+ handler: answer((snapshot) => apps(snapshot))
59
+ },
60
+ {
61
+ path: "/apps/:app/pages/:page",
62
+ handler: answer((snapshot, { params }) => page(snapshot, params.app, params.page))
63
+ },
64
+ {
65
+ path: "/tasks",
66
+ handler: answer((snapshot) => tasks(snapshot))
67
+ },
68
+ {
69
+ path: "/releases",
70
+ handler: answer((snapshot) => releases(snapshot))
71
+ },
72
+ {
73
+ path: "/releases/:release",
74
+ handler: answer((snapshot, { params }) => release(snapshot, params.release))
75
+ },
76
+ {
77
+ path: "/check",
78
+ handler: answer((snapshot) => check(snapshot))
79
+ },
80
+ {
81
+ path: "/graph/file",
82
+ handler: answer((snapshot, { query }) => graphOfFile(snapshot, one(query, "path")))
83
+ },
84
+ {
85
+ path: "/graph/feature/:feature",
86
+ handler: answer((snapshot, { params }) => graphOfFeature(snapshot, params.feature))
87
+ },
88
+ {
89
+ path: "/graph/page",
90
+ handler: answer((snapshot, { query }) => graphOfPage(snapshot, one(query, "app"), one(query, "page")))
91
+ },
92
+ {
93
+ path: "/graph/modules",
94
+ handler: answer((snapshot) => graphOfModules(snapshot))
95
+ }
96
+ ]
97
+ };
98
+ }
99
+
100
+ //#endregion
101
+ export { grimoireDevtoolsPanel as default, grimoireDevtoolsPanel, exportGrimoireSite };
102
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["data.summary","data.search","data.file","data.impact","data.route","data.feature","data.flow","data.apps","data.page","data.tasks","data.releases","data.release","data.check","data.graphOfFile","data.graphOfFeature","data.graphOfPage","data.graphOfModules"],"sources":["../../../../../../../../packages/grimoire/src/devtools/index.ts"],"sourcesContent":["/**\n * `@warlock.js/grimoire/devtools`: the Grimoire tab of the devtools\n * dashboard. An app enables it in `src/config/devtools.ts`:\n *\n * ```ts\n * panels: [\"@warlock.js/grimoire/devtools\"]\n * ```\n *\n * The default export is a panel factory (devtools' `DevtoolsPanelExport`),\n * typed structurally here so this entry needs no `@warlock.js/devtools`\n * import. The browser view lives in the package's `ui/` folder. Data routes\n * open the snapshot with `routes: \"cached\"` (never booting the app) and keep\n * the generated book up to date; agent-written files are only read.\n */\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport * as data from \"./data\";\nimport { createSnapshotSource } from \"./snapshot-source\";\n\nexport { exportGrimoireSite } from \"./site\";\nexport type { ExportGrimoireSiteOptions } from \"./site\";\n\n/** The parts of devtools' `DevtoolsPanelRequest` the routes read. */\nexport type GrimoirePanelRequest = {\n params: Readonly<Record<string, string>>;\n query: Readonly<Record<string, string | readonly string[]>>;\n body: unknown;\n};\n\n/** Devtools' `DevtoolsPanel`, structurally. */\nexport type GrimoireDevtoolsPanel = {\n id: string;\n title: string;\n view: string | URL;\n routes?: readonly {\n method?: \"GET\" | \"POST\";\n path: string;\n handler: (request: GrimoirePanelRequest) => unknown;\n }[];\n assets?: Readonly<Record<string, string | URL>>;\n};\n\n/** What the panel factory takes: devtools passes `{ root }`; the rest is for tests and custom setups. */\nexport type GrimoirePanelContext = {\n /** The app root. */\n root: string;\n /** The adapter to open the book with. Default: the Warlock adapter, loaded on first request. */\n adapter?: BookAdapter | (() => Promise<BookAdapter>);\n /** How long an opened snapshot is reused when the book manifest did not change (ms). Default 2000, longer after a slow open. */\n ttlMs?: number;\n};\n\n/** The first value of a query parameter. */\nfunction one(query: GrimoirePanelRequest[\"query\"], name: string): string | undefined {\n const value = query[name];\n\n return Array.isArray(value) ? value[0] : (value as string | undefined);\n}\n\n/** Build the panel for the app at `root`. */\nexport async function grimoireDevtoolsPanel(\n context: GrimoirePanelContext,\n): Promise<GrimoireDevtoolsPanel> {\n // The tab keeps Warlock's generated files (book, book maps, indexes) up to date, so the next\n // open is incremental. Agent-written files are only read, and cached routes never boot the app.\n const source = createSnapshotSource(context.root, {\n write: true,\n ...(context.adapter === undefined ? {} : { adapter: context.adapter }),\n ...(context.ttlMs === undefined ? {} : { ttlMs: context.ttlMs }),\n });\n const answer =\n <Answer>(read: (snapshot: GrimoireSnapshot, request: GrimoirePanelRequest) => Answer) =>\n async (request: GrimoirePanelRequest): Promise<Answer> =>\n read(await source.get(), request);\n\n return {\n id: \"grimoire\",\n title: \"Grimoire\",\n view: new URL(\"../../ui/grimoire-view.js\", import.meta.url),\n assets: { \"grimoire.css\": new URL(\"../../ui/grimoire.css\", import.meta.url) },\n routes: [\n { path: \"/summary\", handler: answer((snapshot) => data.summary(snapshot)) },\n {\n path: \"/search\",\n handler: answer((snapshot, { query }) => {\n const limit = Number(one(query, \"limit\"));\n\n return data.search(\n snapshot,\n one(query, \"q\") ?? \"\",\n Number.isFinite(limit) && limit > 0 ? limit : undefined,\n );\n }),\n },\n {\n path: \"/file\",\n handler: answer((snapshot, { query }) => data.file(snapshot, one(query, \"path\"))),\n },\n {\n path: \"/impact\",\n handler: answer((snapshot, { query }) => data.impact(snapshot, one(query, \"path\"))),\n },\n {\n path: \"/route\",\n handler: answer((snapshot, { query }) =>\n data.route(snapshot, one(query, \"method\"), one(query, \"path\")),\n ),\n },\n {\n path: \"/features/:feature\",\n handler: answer((snapshot, { params }) => data.feature(snapshot, params.feature)),\n },\n {\n path: \"/flows/:feature/:flow\",\n handler: answer((snapshot, { params }) => data.flow(snapshot, params.feature, params.flow)),\n },\n { path: \"/apps\", handler: answer((snapshot) => data.apps(snapshot)) },\n {\n path: \"/apps/:app/pages/:page\",\n handler: answer((snapshot, { params }) => data.page(snapshot, params.app, params.page)),\n },\n { path: \"/tasks\", handler: answer((snapshot) => data.tasks(snapshot)) },\n { path: \"/releases\", handler: answer((snapshot) => data.releases(snapshot)) },\n {\n path: \"/releases/:release\",\n handler: answer((snapshot, { params }) => data.release(snapshot, params.release)),\n },\n { path: \"/check\", handler: answer((snapshot) => data.check(snapshot)) },\n {\n path: \"/graph/file\",\n handler: answer((snapshot, { query }) => data.graphOfFile(snapshot, one(query, \"path\"))),\n },\n {\n path: \"/graph/feature/:feature\",\n handler: answer((snapshot, { params }) => data.graphOfFeature(snapshot, params.feature)),\n },\n {\n path: \"/graph/page\",\n handler: answer((snapshot, { query }) =>\n data.graphOfPage(snapshot, one(query, \"app\"), one(query, \"page\")),\n ),\n },\n { path: \"/graph/modules\", handler: answer((snapshot) => data.graphOfModules(snapshot)) },\n ],\n };\n}\n\nexport default grimoireDevtoolsPanel;\n"],"mappings":";;;;;;AAqDA,SAAS,IAAI,OAAsC,MAAkC;CACnF,MAAM,QAAQ,MAAM;CAEpB,OAAO,MAAM,QAAQ,KAAK,IAAI,MAAM,KAAM;AAC5C;;AAGA,eAAsB,sBACpB,SACgC;CAGhC,MAAM,SAAS,qBAAqB,QAAQ,MAAM;EAChD,OAAO;EACP,GAAI,QAAQ,YAAY,SAAY,CAAC,IAAI,EAAE,SAAS,QAAQ,QAAQ;EACpE,GAAI,QAAQ,UAAU,SAAY,CAAC,IAAI,EAAE,OAAO,QAAQ,MAAM;CAChE,CAAC;CACD,MAAM,UACK,SACT,OAAO,YACL,KAAK,MAAM,OAAO,IAAI,GAAG,OAAO;CAEpC,OAAO;EACL,IAAI;EACJ,OAAO;EACP,MAAM,IAAI,IAAI,6BAA6B,YAAY,GAAG;EAC1D,QAAQ,EAAE,gBAAgB,IAAI,IAAI,yBAAyB,YAAY,GAAG,EAAE;EAC5E,QAAQ;GACN;IAAE,MAAM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,aAAaC,MAAW,QAAQ,CAAC;GAAE;GACtE;IACE,MAAM;IACN,SAAS,QAAQ,UAAU,EAAE,YAAYC,YAAiB,UAAU,IAAI,OAAO,MAAM,CAAC,CAAC;GACzF;GACA;IACE,MAAM;IACN,SAAS,QAAQ,UAAU,EAAE,aAAaC,eAAoB,UAAU,OAAO,OAAO,CAAC;GACzF;GACA;IACE,MAAM;IACN,SAAS,QAAQ,UAAU,EAAE,YAC3BC,YAAiB,UAAU,IAAI,OAAO,KAAK,GAAG,IAAI,OAAO,MAAM,CAAC,CAClE;GACF;GACA;IAAE,MAAM;IAAkB,SAAS,QAAQ,aAAaC,eAAoB,QAAQ,CAAC;GAAE;EACzF;CACF;AACF"}
@@ -0,0 +1,26 @@
1
+ import { BookAdapter } from "../contracts/adapter.mjs";
2
+ import { GrimoireSnapshot } from "../contracts/snapshot.mjs";
3
+ //#region ../../packages/grimoire/src/devtools/site.d.ts
4
+ /** Options of `exportGrimoireSite()`. */
5
+ export type ExportGrimoireSiteOptions = {
6
+ /** Output folder, project-relative or absolute. Default `grimoire/book/site` (the book writer leaves it alone and git ignores it). */
7
+ outDir?: string;
8
+ /** The adapter to open the book with. Default: the Warlock adapter. */
9
+ adapter?: BookAdapter | (() => Promise<BookAdapter>);
10
+ /** An already opened snapshot; skips opening one. */
11
+ snapshot?: GrimoireSnapshot;
12
+ };
13
+ /**
14
+ * Write the tab as a static folder for people without the app running.
15
+ *
16
+ * The folder holds `index.html` only: the view, the loader, the styles and
17
+ * the data (as JSON) are inside it, so it opens straight from disk. Open the
18
+ * page and use `#grimoire/...` links; the answers that need the running app
19
+ * (impact of a file) say so in place.
20
+ *
21
+ * @param root Absolute project root.
22
+ * @returns The output folder, project-relative.
23
+ */
24
+ export declare function exportGrimoireSite(root: string, options?: ExportGrimoireSiteOptions): Promise<string>;
25
+ //#endregion
26
+ //# sourceMappingURL=site.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/site.ts"],"mappings":";;;;YAgBY;;EAEV;;EAEA,UAAU,qBAAqB,QAAQ;;EAEvC,WAAW;;;;;;;;;;;;;wBA4LS,mBACpB,cACA,UAAS,4BACR"}
@@ -0,0 +1,190 @@
1
+ import { GRIMOIRE_PATHS, projectPath, toPosixPath } from "../paths/index.mjs";
2
+ import { featureGraph, fileGraph, pageGraph } from "./graphs.mjs";
3
+ import { apps, check, feature, file, flow, graphOfModules, page, releases, summary, tasks } from "./data.mjs";
4
+ import { createSnapshotSource } from "./snapshot-source.mjs";
5
+ import path from "node:path";
6
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
7
+ import { fileURLToPath } from "node:url";
8
+
9
+ //#region ../../packages/grimoire/src/devtools/site.ts
10
+ /**
11
+ * The static export: one folder with an `index.html` that holds the view, the
12
+ * loader, the styles and the data as JSON. It opens from disk (`file://`) or
13
+ * any static host and needs no running app.
14
+ */
15
+ /** The most files the export keeps per-file answers for (the most imported first). */
16
+ const SITE_FILE_LIMIT = 3e3;
17
+ const uiFolder = fileURLToPath(new URL("../../ui/", import.meta.url));
18
+ /** Every answer the static page can give, keyed by the data route it replaces. */
19
+ function buildSiteData(snapshot) {
20
+ const routes = {
21
+ summary: summary(snapshot),
22
+ apps: apps(snapshot),
23
+ tasks: tasks(snapshot),
24
+ releases: releases(snapshot),
25
+ check: {
26
+ ...check(snapshot),
27
+ root: "."
28
+ },
29
+ "graph/modules": graphOfModules(snapshot)
30
+ };
31
+ const search = [];
32
+ for (const release of snapshot.written.releases) routes[`releases/${release.release.value}`] = release;
33
+ for (const feature$1 of snapshot.written.features) {
34
+ const readme = feature$1.readme;
35
+ search.push({
36
+ type: "feature",
37
+ id: feature$1.id,
38
+ detail: readme?.title.value ?? null
39
+ });
40
+ const answered = attempt(() => feature(snapshot, feature$1.id));
41
+ if (answered !== void 0) routes[`features/${feature$1.id}`] = answered;
42
+ const graph = featureGraph(snapshot, feature$1.id);
43
+ if (graph !== null) routes[`graph/feature/${feature$1.id}`] = graph;
44
+ for (const flow$1 of feature$1.flows) {
45
+ search.push({
46
+ type: "flow",
47
+ id: flow$1.ref,
48
+ detail: flow$1.heading?.value ?? null
49
+ });
50
+ const flowAnswer = attempt(() => flow(snapshot, feature$1.id, flow$1.id.value));
51
+ if (flowAnswer !== void 0) routes[`flows/${flow$1.ref}`] = flowAnswer;
52
+ }
53
+ }
54
+ for (const app of snapshot.written.apps) {
55
+ const appId = app.id.value;
56
+ for (const page$1 of [...app.pages, ...app.screens]) {
57
+ const route = page$1.route?.value ?? page$1.screen?.value ?? null;
58
+ const answer = attempt(() => page(snapshot, appId, page$1.id));
59
+ const graph = pageGraph(snapshot, appId, page$1.id);
60
+ for (const key of /* @__PURE__ */ new Set([page$1.id, ...route === null ? [] : [route]])) {
61
+ if (answer !== void 0) routes[`apps/${appId}/pages/${key}`] = answer;
62
+ if (graph !== null) routes[`graph/page/${appId}/${key}`] = graph;
63
+ }
64
+ if (route !== null) search.push({
65
+ type: page$1.type,
66
+ id: `${appId} ${route}`,
67
+ detail: page$1.heading?.value ?? null
68
+ });
69
+ for (const block of page$1.blockFiles) search.push({
70
+ type: "block",
71
+ id: `${appId}/${page$1.id}/${block.id}`,
72
+ detail: block.flow?.value ?? null
73
+ });
74
+ }
75
+ }
76
+ for (const found of snapshot.book.facts.routes ?? []) search.push({
77
+ type: "route",
78
+ id: `${found.method} ${found.path}`,
79
+ detail: found.description ?? found.handler
80
+ });
81
+ for (const task of snapshot.collected.tasksIndex.open.concat(snapshot.collected.tasksIndex.done)) search.push({
82
+ type: "task",
83
+ id: task.id,
84
+ detail: task.title
85
+ });
86
+ const files = {};
87
+ const ranked = [...snapshot.book.facts.files].sort((left, right) => right.importedBy.length - left.importedBy.length || left.file.localeCompare(right.file));
88
+ for (const [index, file$1] of ranked.entries()) {
89
+ search.push({
90
+ type: "file",
91
+ id: file$1.file,
92
+ detail: file$1.about
93
+ });
94
+ if (index >= 3e3) continue;
95
+ const result = attempt(() => file(snapshot, file$1.file));
96
+ if (result !== void 0) files[file$1.file] = {
97
+ result,
98
+ graph: fileGraph(snapshot, file$1.file)
99
+ };
100
+ }
101
+ return {
102
+ routes,
103
+ files,
104
+ search
105
+ };
106
+ }
107
+ /** JSON for an inline `<script>`: every `<` is escaped, so no `<\/script` or `<!--` can appear. */
108
+ function inlineJson(value) {
109
+ return JSON.stringify(value).replaceAll("<", "\\u003c");
110
+ }
111
+ /** Code for an inline `<script>`: `<\/script` (in any case) and `<!--` (only possible in strings and comments) are broken up. */
112
+ function inlineCode(code) {
113
+ return code.replace(/<\/(script)/gi, "<\\/$1").replaceAll("<!--", "<\\!--");
114
+ }
115
+ /** The answer, or `undefined` when the item cannot be answered (the export skips it). */
116
+ function attempt(answer) {
117
+ try {
118
+ return answer();
119
+ } catch {
120
+ return;
121
+ }
122
+ }
123
+ /** Everything before the page's `export default`, so the view can sit in an inline module. */
124
+ function inlineView(source) {
125
+ const marker = "export default renderGrimoire;";
126
+ if (!source.includes(marker)) throw new Error("grimoire-view.js must end with `export default renderGrimoire;`.");
127
+ return source.replace(marker, "");
128
+ }
129
+ const PAGE_STYLE = `
130
+ :root{color-scheme:light dark;--bg:#f5f6f8;--surface:#fff;--line:#d9dde5;--text:#18202a;--muted:#667085;--accent:#285fc1;--good:#167a43;--warn:#a96000;--bad:#b42318;--bar:#5b7cfa;font-family:system-ui,-apple-system,"Segoe UI",sans-serif}
131
+ @media (prefers-color-scheme:dark){:root{--bg:#16191f;--surface:#20242c;--line:#383e49;--text:#edf0f5;--muted:#aab3c2;--accent:#83adff;--good:#65d394;--warn:#f6b65a;--bad:#ff9c95;--bar:#8ca7ff}}
132
+ *{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--text);font-size:14px}
133
+ main{max-width:1100px;margin:0 auto;padding:16px}
134
+ .card{background:var(--surface);border:1px solid var(--line);border-radius:8px;padding:12px 14px}
135
+ .badge{display:inline-block;padding:0 6px;border:1px solid var(--line);border-radius:10px;font-size:12px}
136
+ .empty,.error{padding:12px;color:var(--muted)}.error{color:var(--bad)}
137
+ `;
138
+ /** The `index.html` text. */
139
+ function renderSiteHtml(siteData, sources) {
140
+ const json = inlineJson(siteData);
141
+ const script = inlineCode(`${inlineView(sources.view)}\n${sources.loader}\ngrimoireStaticMount(JSON.parse(document.getElementById("grimoire-data").textContent), document.getElementById("grimoire-root"), renderGrimoire);\n`);
142
+ return `<!doctype html>
143
+ <html lang="en">
144
+ <head>
145
+ <meta charset="utf-8">
146
+ <meta name="viewport" content="width=device-width, initial-scale=1">
147
+ <title>Grimoire</title>
148
+ <style>${PAGE_STYLE}${sources.css}</style>
149
+ </head>
150
+ <body>
151
+ <main id="grimoire-root"><p class="empty">Loading the Grimoire…</p></main>
152
+ <script type="application/json" id="grimoire-data">${json}<\/script>
153
+ <script type="module">${script}<\/script>
154
+ </body>
155
+ </html>
156
+ `;
157
+ }
158
+ /**
159
+ * Write the tab as a static folder for people without the app running.
160
+ *
161
+ * The folder holds `index.html` only: the view, the loader, the styles and
162
+ * the data (as JSON) are inside it, so it opens straight from disk. Open the
163
+ * page and use `#grimoire/...` links; the answers that need the running app
164
+ * (impact of a file) say so in place.
165
+ *
166
+ * @param root Absolute project root.
167
+ * @returns The output folder, project-relative.
168
+ */
169
+ async function exportGrimoireSite(root, options = {}) {
170
+ const outDir = projectPath(root, toPosixPath(options.outDir ?? GRIMOIRE_PATHS.staticSite)).replace(/\/+$/, "");
171
+ const snapshot = options.snapshot ?? await createSnapshotSource(root, options.adapter === void 0 ? {} : { adapter: options.adapter }).get();
172
+ const [view, loader, css] = await Promise.all([
173
+ "grimoire-view.js",
174
+ "grimoire-static.js",
175
+ "grimoire.css"
176
+ ].map((name) => readFile(path.join(uiFolder, name), "utf8")));
177
+ const html = renderSiteHtml(buildSiteData(snapshot), {
178
+ view: view ?? "",
179
+ loader: loader ?? "",
180
+ css: css ?? ""
181
+ });
182
+ const absolute = path.resolve(root, outDir);
183
+ await mkdir(absolute, { recursive: true });
184
+ await writeFile(path.join(absolute, "index.html"), html);
185
+ return outDir;
186
+ }
187
+
188
+ //#endregion
189
+ export { SITE_FILE_LIMIT, buildSiteData, exportGrimoireSite, inlineView, renderSiteHtml };
190
+ //# sourceMappingURL=site.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site.mjs","names":["data.summary","data.apps","data.tasks","data.releases","data.check","data.graphOfModules","feature","data.feature","flow","data.flow","page","data.page","file","data.file"],"sources":["../../../../../../../../packages/grimoire/src/devtools/site.ts"],"sourcesContent":["/**\n * The static export: one folder with an `index.html` that holds the view, the\n * loader, the styles and the data as JSON. It opens from disk (`file://`) or\n * any static host and needs no running app.\n */\nimport { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport { GRIMOIRE_PATHS, projectPath, toPosixPath } from \"../paths\";\nimport * as data from \"./data\";\nimport { featureGraph, fileGraph, pageGraph } from \"./graphs\";\nimport { createSnapshotSource } from \"./snapshot-source\";\n\n/** Options of `exportGrimoireSite()`. */\nexport type ExportGrimoireSiteOptions = {\n /** Output folder, project-relative or absolute. Default `grimoire/book/site` (the book writer leaves it alone and git ignores it). */\n outDir?: string;\n /** The adapter to open the book with. Default: the Warlock adapter. */\n adapter?: BookAdapter | (() => Promise<BookAdapter>);\n /** An already opened snapshot; skips opening one. */\n snapshot?: GrimoireSnapshot;\n};\n\n/** The most files the export keeps per-file answers for (the most imported first). */\nexport const SITE_FILE_LIMIT = 3000;\n\ntype SearchItem = { type: string; id: string; detail: string | null };\n\nconst uiFolder = fileURLToPath(new URL(\"../../ui/\", import.meta.url));\n\n/** Every answer the static page can give, keyed by the data route it replaces. */\nexport function buildSiteData(snapshot: GrimoireSnapshot) {\n const routes: Record<string, unknown> = {\n summary: data.summary(snapshot),\n apps: data.apps(snapshot),\n tasks: data.tasks(snapshot),\n releases: data.releases(snapshot),\n // The page is meant to be shared: it does not name where the project sits on this machine.\n check: { ...data.check(snapshot), root: \".\" },\n \"graph/modules\": data.graphOfModules(snapshot),\n };\n const search: SearchItem[] = [];\n\n for (const release of snapshot.written.releases) {\n routes[`releases/${release.release.value}`] = release;\n }\n\n for (const feature of snapshot.written.features) {\n const readme = feature.readme;\n\n search.push({ type: \"feature\", id: feature.id, detail: readme?.title.value ?? null });\n const answered = attempt(() => data.feature(snapshot, feature.id));\n\n if (answered !== undefined) routes[`features/${feature.id}`] = answered;\n\n const graph = featureGraph(snapshot, feature.id);\n\n if (graph !== null) routes[`graph/feature/${feature.id}`] = graph;\n\n for (const flow of feature.flows) {\n search.push({ type: \"flow\", id: flow.ref, detail: flow.heading?.value ?? null });\n const flowAnswer = attempt(() => data.flow(snapshot, feature.id, flow.id.value));\n\n if (flowAnswer !== undefined) routes[`flows/${flow.ref}`] = flowAnswer;\n }\n }\n\n for (const app of snapshot.written.apps) {\n const appId = app.id.value;\n\n for (const page of [...app.pages, ...app.screens]) {\n const route = page.route?.value ?? page.screen?.value ?? null;\n const answer = attempt(() => data.page(snapshot, appId, page.id));\n const graph = pageGraph(snapshot, appId, page.id);\n\n for (const key of new Set([page.id, ...(route === null ? [] : [route])])) {\n if (answer !== undefined) routes[`apps/${appId}/pages/${key}`] = answer;\n\n if (graph !== null) routes[`graph/page/${appId}/${key}`] = graph;\n }\n\n if (route !== null)\n search.push({\n type: page.type,\n id: `${appId} ${route}`,\n detail: page.heading?.value ?? null,\n });\n\n for (const block of page.blockFiles) {\n search.push({\n type: \"block\",\n id: `${appId}/${page.id}/${block.id}`,\n detail: block.flow?.value ?? null,\n });\n }\n }\n }\n\n for (const found of snapshot.book.facts.routes ?? []) {\n search.push({\n type: \"route\",\n id: `${found.method} ${found.path}`,\n detail: found.description ?? found.handler,\n });\n }\n\n for (const task of snapshot.collected.tasksIndex.open.concat(\n snapshot.collected.tasksIndex.done,\n )) {\n search.push({ type: \"task\", id: task.id, detail: task.title });\n }\n\n const files: Record<string, { result: unknown; graph: unknown }> = {};\n const ranked = [...snapshot.book.facts.files].sort(\n (left, right) =>\n right.importedBy.length - left.importedBy.length || left.file.localeCompare(right.file),\n );\n\n for (const [index, file] of ranked.entries()) {\n search.push({ type: \"file\", id: file.file, detail: file.about });\n\n if (index >= SITE_FILE_LIMIT) continue;\n\n const result = attempt(() => data.file(snapshot, file.file));\n\n if (result !== undefined) files[file.file] = { result, graph: fileGraph(snapshot, file.file) };\n }\n\n return { routes, files, search };\n}\n\n/** JSON for an inline `<script>`: every `<` is escaped, so no `</script` or `<!--` can appear. */\nfunction inlineJson(value: unknown): string {\n return JSON.stringify(value).replaceAll(\"<\", \"\\\\u003c\");\n}\n\n/** Code for an inline `<script>`: `</script` (in any case) and `<!--` (only possible in strings and comments) are broken up. */\nfunction inlineCode(code: string): string {\n return code.replace(/<\\/(script)/gi, \"<\\\\/$1\").replaceAll(\"<!--\", \"<\\\\!--\");\n}\n\n/** The answer, or `undefined` when the item cannot be answered (the export skips it). */\nfunction attempt<Value>(answer: () => Value): Value | undefined {\n try {\n return answer();\n } catch {\n return undefined;\n }\n}\n\n/** Everything before the page's `export default`, so the view can sit in an inline module. */\nexport function inlineView(source: string): string {\n const marker = \"export default renderGrimoire;\";\n\n if (!source.includes(marker))\n throw new Error(\"grimoire-view.js must end with `export default renderGrimoire;`.\");\n\n return source.replace(marker, \"\");\n}\n\nconst PAGE_STYLE = `\n:root{color-scheme:light dark;--bg:#f5f6f8;--surface:#fff;--line:#d9dde5;--text:#18202a;--muted:#667085;--accent:#285fc1;--good:#167a43;--warn:#a96000;--bad:#b42318;--bar:#5b7cfa;font-family:system-ui,-apple-system,\"Segoe UI\",sans-serif}\n@media (prefers-color-scheme:dark){:root{--bg:#16191f;--surface:#20242c;--line:#383e49;--text:#edf0f5;--muted:#aab3c2;--accent:#83adff;--good:#65d394;--warn:#f6b65a;--bad:#ff9c95;--bar:#8ca7ff}}\n*{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--text);font-size:14px}\nmain{max-width:1100px;margin:0 auto;padding:16px}\n.card{background:var(--surface);border:1px solid var(--line);border-radius:8px;padding:12px 14px}\n.badge{display:inline-block;padding:0 6px;border:1px solid var(--line);border-radius:10px;font-size:12px}\n.empty,.error{padding:12px;color:var(--muted)}.error{color:var(--bad)}\n`;\n\n/** The `index.html` text. */\nexport function renderSiteHtml(\n siteData: unknown,\n sources: { view: string; loader: string; css: string },\n): string {\n const json = inlineJson(siteData);\n const script = inlineCode(\n `${inlineView(sources.view)}\\n${sources.loader}\\ngrimoireStaticMount(JSON.parse(document.getElementById(\"grimoire-data\").textContent), document.getElementById(\"grimoire-root\"), renderGrimoire);\\n`,\n );\n\n return `<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<title>Grimoire</title>\n<style>${PAGE_STYLE}${sources.css}</style>\n</head>\n<body>\n<main id=\"grimoire-root\"><p class=\"empty\">Loading the Grimoire…</p></main>\n<script type=\"application/json\" id=\"grimoire-data\">${json}</script>\n<script type=\"module\">${script}</script>\n</body>\n</html>\n`;\n}\n\n/**\n * Write the tab as a static folder for people without the app running.\n *\n * The folder holds `index.html` only: the view, the loader, the styles and\n * the data (as JSON) are inside it, so it opens straight from disk. Open the\n * page and use `#grimoire/...` links; the answers that need the running app\n * (impact of a file) say so in place.\n *\n * @param root Absolute project root.\n * @returns The output folder, project-relative.\n */\nexport async function exportGrimoireSite(\n root: string,\n options: ExportGrimoireSiteOptions = {},\n): Promise<string> {\n // Project-relative from here on; an absolute folder is kept where it is.\n const outDir = projectPath(\n root,\n toPosixPath(options.outDir ?? GRIMOIRE_PATHS.staticSite),\n ).replace(/\\/+$/, \"\");\n const snapshot =\n options.snapshot ??\n (await createSnapshotSource(\n root,\n options.adapter === undefined ? {} : { adapter: options.adapter },\n ).get());\n const [view, loader, css] = await Promise.all(\n [\"grimoire-view.js\", \"grimoire-static.js\", \"grimoire.css\"].map((name) =>\n readFile(path.join(uiFolder, name), \"utf8\"),\n ),\n );\n const html = renderSiteHtml(buildSiteData(snapshot), {\n view: view ?? \"\",\n loader: loader ?? \"\",\n css: css ?? \"\",\n });\n const absolute = path.resolve(root, outDir);\n\n await mkdir(absolute, { recursive: true });\n await writeFile(path.join(absolute, \"index.html\"), html);\n\n return outDir;\n}\n"],"mappings":";;;;;;;;;;;;;;;AA0BA,MAAa,kBAAkB;AAI/B,MAAM,WAAW,cAAc,IAAI,IAAI,aAAa,YAAY,GAAG,CAAC;;AAGpE,SAAgB,cAAc,UAA4B;CACxD,MAAM,SAAkC;EACtC,SAASA,QAAa,QAAQ;EAC9B,MAAMC,KAAU,QAAQ;EACxB,OAAOC,MAAW,QAAQ;EAC1B,UAAUC,SAAc,QAAQ;EAEhC,OAAO;GAAE,GAAGC,MAAW,QAAQ;GAAG,MAAM;EAAI;EAC5C,iBAAiBC,eAAoB,QAAQ;CAC/C;CACA,MAAM,SAAuB,CAAC;CAE9B,KAAK,MAAM,WAAW,SAAS,QAAQ,UACrC,OAAO,YAAY,QAAQ,QAAQ,WAAW;CAGhD,KAAK,MAAMC,aAAW,SAAS,QAAQ,UAAU;EAC/C,MAAM,SAASA,UAAQ;EAEvB,OAAO,KAAK;GAAE,MAAM;GAAW,IAAIA,UAAQ;GAAI,QAAQ,QAAQ,MAAM,SAAS;EAAK,CAAC;EACpF,MAAM,WAAW,cAAcC,QAAa,UAAUD,UAAQ,EAAE,CAAC;EAEjE,IAAI,aAAa,QAAW,OAAO,YAAYA,UAAQ,QAAQ;EAE/D,MAAM,QAAQ,aAAa,UAAUA,UAAQ,EAAE;EAE/C,IAAI,UAAU,MAAM,OAAO,iBAAiBA,UAAQ,QAAQ;EAE5D,KAAK,MAAME,UAAQF,UAAQ,OAAO;GAChC,OAAO,KAAK;IAAE,MAAM;IAAQ,IAAIE,OAAK;IAAK,QAAQA,OAAK,SAAS,SAAS;GAAK,CAAC;GAC/E,MAAM,aAAa,cAAcC,KAAU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