@warlock.js/grimoire 5.57.0 → 5.59.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.
- package/CHANGELOG.md +44 -0
- package/esm/apps/check-apps.mjs +11 -5
- package/esm/apps/check-apps.mjs.map +1 -1
- package/esm/book/build.d.mts.map +1 -1
- package/esm/book/build.mjs +2 -1
- package/esm/book/build.mjs.map +1 -1
- package/esm/book/render.mjs +10 -0
- package/esm/book/render.mjs.map +1 -1
- package/esm/bookmap/build.d.mts.map +1 -1
- package/esm/bookmap/build.mjs +7 -5
- package/esm/bookmap/build.mjs.map +1 -1
- package/esm/bookmap/steps.mjs +85 -39
- package/esm/bookmap/steps.mjs.map +1 -1
- package/esm/check/check-grimoire.d.mts.map +1 -1
- package/esm/check/check-grimoire.mjs +4 -1
- package/esm/check/check-grimoire.mjs.map +1 -1
- package/esm/check/rules/criteria.mjs +21 -2
- package/esm/check/rules/criteria.mjs.map +1 -1
- package/esm/check/rules/screenshots.mjs +57 -0
- package/esm/check/rules/screenshots.mjs.map +1 -0
- package/esm/codes/codes.d.mts +12 -0
- package/esm/codes/codes.d.mts.map +1 -1
- package/esm/codes/codes.mjs +6 -0
- package/esm/codes/codes.mjs.map +1 -1
- package/esm/contracts/adapter.d.mts +28 -1
- package/esm/contracts/adapter.d.mts.map +1 -1
- package/esm/contracts/book.d.mts +2 -0
- package/esm/contracts/book.d.mts.map +1 -1
- package/esm/contracts/book.mjs.map +1 -1
- package/esm/contracts/bookmap.d.mts +19 -1
- package/esm/contracts/bookmap.d.mts.map +1 -1
- package/esm/contracts/scry.d.mts +26 -6
- package/esm/contracts/scry.d.mts.map +1 -1
- package/esm/contracts/snapshot.d.mts +14 -1
- package/esm/contracts/snapshot.d.mts.map +1 -1
- package/esm/contracts/test-results.d.mts +34 -0
- package/esm/contracts/test-results.d.mts.map +1 -1
- package/esm/contracts/written.d.mts +44 -0
- package/esm/contracts/written.d.mts.map +1 -1
- package/esm/contracts/written.mjs.map +1 -1
- package/esm/devtools/data.mjs +116 -5
- package/esm/devtools/data.mjs.map +1 -1
- package/esm/devtools/feature-map.mjs +149 -0
- package/esm/devtools/feature-map.mjs.map +1 -0
- package/esm/devtools/index.d.mts +28 -2
- package/esm/devtools/index.d.mts.map +1 -1
- package/esm/devtools/index.mjs +111 -7
- package/esm/devtools/index.mjs.map +1 -1
- package/esm/devtools/product-map.d.mts +14 -0
- package/esm/devtools/product-map.d.mts.map +1 -0
- package/esm/devtools/product-map.mjs +460 -0
- package/esm/devtools/product-map.mjs.map +1 -0
- package/esm/devtools/site.d.mts +43 -1
- package/esm/devtools/site.d.mts.map +1 -1
- package/esm/devtools/site.mjs +190 -22
- package/esm/devtools/site.mjs.map +1 -1
- package/esm/devtools/snapshot-source.mjs +24 -7
- package/esm/devtools/snapshot-source.mjs.map +1 -1
- package/esm/graph/index.d.mts +10 -1
- package/esm/graph/index.d.mts.map +1 -1
- package/esm/graph/index.mjs +3 -2
- package/esm/graph/index.mjs.map +1 -1
- package/esm/index.d.mts +5 -5
- package/esm/ownership/index.d.mts.map +1 -1
- package/esm/ownership/index.mjs +60 -1
- package/esm/ownership/index.mjs.map +1 -1
- package/esm/paths/index.d.mts +2 -0
- package/esm/paths/index.d.mts.map +1 -1
- package/esm/paths/index.mjs +3 -1
- package/esm/paths/index.mjs.map +1 -1
- package/esm/scry/compact.mjs +170 -0
- package/esm/scry/compact.mjs.map +1 -0
- package/esm/scry/format.d.mts.map +1 -1
- package/esm/scry/format.mjs +19 -2
- package/esm/scry/format.mjs.map +1 -1
- package/esm/scry/query.d.mts.map +1 -1
- package/esm/scry/query.mjs +159 -24
- package/esm/scry/query.mjs.map +1 -1
- package/esm/test-results/index.d.mts +7 -2
- package/esm/test-results/index.d.mts.map +1 -1
- package/esm/test-results/index.mjs +79 -12
- package/esm/test-results/index.mjs.map +1 -1
- package/esm/vitest/index.d.mts +6 -0
- package/esm/vitest/index.d.mts.map +1 -1
- package/esm/vitest/index.mjs +22 -6
- package/esm/vitest/index.mjs.map +1 -1
- package/esm/warlock/actions.mjs +15 -7
- package/esm/warlock/actions.mjs.map +1 -1
- package/esm/warlock/adapter.d.mts.map +1 -1
- package/esm/warlock/adapter.mjs +42 -4
- package/esm/warlock/adapter.mjs.map +1 -1
- package/esm/warlock/commands.mjs +7 -2
- package/esm/warlock/commands.mjs.map +1 -1
- package/esm/warlock/logo.mjs +12 -0
- package/esm/warlock/logo.mjs.map +1 -0
- package/esm/warlock/mcp-tools.mjs +51 -15
- package/esm/warlock/mcp-tools.mjs.map +1 -1
- package/esm/workspace/cache.mjs +194 -0
- package/esm/workspace/cache.mjs.map +1 -0
- package/esm/workspace/index.d.mts.map +1 -1
- package/esm/workspace/index.mjs +7 -3
- package/esm/workspace/index.mjs.map +1 -1
- package/esm/written/apps.mjs +4 -2
- package/esm/written/apps.mjs.map +1 -1
- package/esm/written/features.mjs +119 -6
- package/esm/written/features.mjs.map +1 -1
- package/esm/written/markdown.mjs +66 -1
- package/esm/written/markdown.mjs.map +1 -1
- package/esm/written/parse-grimoire.d.mts.map +1 -1
- package/esm/written/parse-grimoire.mjs +1 -1
- package/esm/written/parse-grimoire.mjs.map +1 -1
- package/llms-full.txt +108 -12
- package/package.json +3 -3
- package/skills/backfill-a-grimoire/SKILL.md +5 -0
- package/skills/describe-an-app/SKILL.md +12 -0
- package/skills/record-a-change/SKILL.md +10 -0
- package/skills/use-the-grimoire/SKILL.md +44 -10
- package/skills/write-a-feature/SKILL.md +37 -2
- package/ui/grimoire-static.js +61 -6
- package/ui/grimoire-view.js +2133 -316
- package/ui/grimoire.css +1030 -24
- package/ui/product-map.css +785 -0
- package/ui/product-map.js +1265 -0
package/esm/devtools/site.mjs
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { GRIMOIRE_PATHS, projectPath, toPosixPath } from "../paths/index.mjs";
|
|
2
2
|
import { featureGraph, fileGraph, pageGraph } from "./graphs.mjs";
|
|
3
|
-
import { apps, check, feature, features, file,
|
|
3
|
+
import { apps, check, checkGroups, feature, features, file, flowAnswer, graphOfModules, page, releases, summary, tasks } from "./data.mjs";
|
|
4
|
+
import { productFeature, productFlow, productMap } from "./product-map.mjs";
|
|
4
5
|
import { createSnapshotSource } from "./snapshot-source.mjs";
|
|
6
|
+
import { stampOf } from "../workspace/cache.mjs";
|
|
5
7
|
import path from "node:path";
|
|
6
|
-
import {
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
import { copyFile, mkdir, open, readFile, realpath, stat, writeFile } from "node:fs/promises";
|
|
7
10
|
import { fileURLToPath } from "node:url";
|
|
8
11
|
|
|
9
12
|
//#region ../../packages/grimoire/src/devtools/site.ts
|
|
@@ -14,6 +17,15 @@ import { fileURLToPath } from "node:url";
|
|
|
14
17
|
*/
|
|
15
18
|
/** The most files the export keeps per-file answers for (the most imported first). */
|
|
16
19
|
const SITE_FILE_LIMIT = 3e3;
|
|
20
|
+
/** The written text of a flow the exported search reads, with criteria ids so `AC-5` is findable. */
|
|
21
|
+
function flowSearchText(flow) {
|
|
22
|
+
return [
|
|
23
|
+
flow.summary ?? "",
|
|
24
|
+
...flow.story.map((step) => step.text),
|
|
25
|
+
...flow.cases.map((item) => `${item.question} ${item.answer} ${item.criteria.join(" ")}`),
|
|
26
|
+
...flow.criteria.map((item) => `${item.id} ${item.text}`)
|
|
27
|
+
].filter((part) => part !== "").join(" | ");
|
|
28
|
+
}
|
|
17
29
|
const uiFolder = fileURLToPath(new URL("../../ui/", import.meta.url));
|
|
18
30
|
/** Every answer the static page can give, keyed by the data route it replaces. */
|
|
19
31
|
function buildSiteData(snapshot) {
|
|
@@ -29,6 +41,14 @@ function buildSiteData(snapshot) {
|
|
|
29
41
|
},
|
|
30
42
|
"graph/modules": graphOfModules(snapshot)
|
|
31
43
|
};
|
|
44
|
+
const productOptions = {
|
|
45
|
+
shared: false,
|
|
46
|
+
errors: null
|
|
47
|
+
};
|
|
48
|
+
const productAnswer = attempt(() => productMap(snapshot, productOptions));
|
|
49
|
+
const groups = attempt(() => checkGroups(snapshot));
|
|
50
|
+
if (productAnswer !== void 0) routes.product = productAnswer;
|
|
51
|
+
if (groups !== void 0) routes["check/groups"] = groups;
|
|
32
52
|
const search = [];
|
|
33
53
|
for (const release of snapshot.written.releases) routes[`releases/${release.release.value}`] = release;
|
|
34
54
|
for (const feature$1 of snapshot.written.features) {
|
|
@@ -36,20 +56,26 @@ function buildSiteData(snapshot) {
|
|
|
36
56
|
search.push({
|
|
37
57
|
type: "feature",
|
|
38
58
|
id: feature$1.id,
|
|
39
|
-
detail: readme?.title.value ?? null
|
|
59
|
+
detail: readme?.title.value ?? null,
|
|
60
|
+
text: [readme?.summary ?? "", readme?.why ?? ""].filter((part) => part !== "").join(" | ")
|
|
40
61
|
});
|
|
41
62
|
const answered = attempt(() => feature(snapshot, feature$1.id));
|
|
42
63
|
if (answered !== void 0) routes[`features/${feature$1.id}`] = answered;
|
|
43
64
|
const graph = featureGraph(snapshot, feature$1.id);
|
|
44
65
|
if (graph !== null) routes[`graph/feature/${feature$1.id}`] = graph;
|
|
45
|
-
|
|
66
|
+
const product = attempt(() => productFeature(snapshot, feature$1.id, productOptions));
|
|
67
|
+
if (product !== void 0) routes[`product/features/${feature$1.id}`] = product;
|
|
68
|
+
for (const flow of feature$1.flows) {
|
|
46
69
|
search.push({
|
|
47
70
|
type: "flow",
|
|
48
|
-
id: flow
|
|
49
|
-
detail: flow
|
|
71
|
+
id: flow.ref,
|
|
72
|
+
detail: flow.heading?.value ?? null,
|
|
73
|
+
text: flowSearchText(flow)
|
|
50
74
|
});
|
|
51
|
-
const flowAnswer = attempt(() =>
|
|
52
|
-
|
|
75
|
+
const flowAnswer$1 = attempt(() => flowAnswer(snapshot, feature$1.id, flow.id.value));
|
|
76
|
+
const productFlowAnswer = attempt(() => productFlow(snapshot, feature$1.id, flow.id.value, productOptions));
|
|
77
|
+
if (flowAnswer$1 !== void 0) routes[`flows/${flow.ref}`] = flowAnswer$1;
|
|
78
|
+
if (productFlowAnswer !== void 0) routes[`product/flows/${flow.ref}`] = productFlowAnswer;
|
|
53
79
|
}
|
|
54
80
|
}
|
|
55
81
|
for (const app of snapshot.written.apps) {
|
|
@@ -105,6 +131,33 @@ function buildSiteData(snapshot) {
|
|
|
105
131
|
search
|
|
106
132
|
};
|
|
107
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* The business-only data of the static export: the share-safe Product map, its feature
|
|
136
|
+
* and flow pages, and nothing else. No file paths, test names, export names, check
|
|
137
|
+
* findings or per-file answers; the search list is empty.
|
|
138
|
+
*/
|
|
139
|
+
function buildProductSiteData(snapshot) {
|
|
140
|
+
const options = {
|
|
141
|
+
shared: true,
|
|
142
|
+
errors: null
|
|
143
|
+
};
|
|
144
|
+
const routes = {};
|
|
145
|
+
const map = attempt(() => productMap(snapshot, options));
|
|
146
|
+
if (map !== void 0) routes.product = map;
|
|
147
|
+
for (const feature of snapshot.written.features) {
|
|
148
|
+
const answer = attempt(() => productFeature(snapshot, feature.id, options));
|
|
149
|
+
if (answer !== void 0) routes[`product/features/${feature.id}`] = answer;
|
|
150
|
+
for (const flow of feature.flows) {
|
|
151
|
+
const flowAnswer = attempt(() => productFlow(snapshot, feature.id, flow.id.value, options));
|
|
152
|
+
if (flowAnswer !== void 0) routes[`product/flows/${flow.ref}`] = flowAnswer;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
routes,
|
|
157
|
+
files: {},
|
|
158
|
+
search: []
|
|
159
|
+
};
|
|
160
|
+
}
|
|
108
161
|
/** JSON for an inline `<script>`: every `<` is escaped, so no `<\/script` or `<!--` can appear. */
|
|
109
162
|
function inlineJson(value) {
|
|
110
163
|
return JSON.stringify(value).replaceAll("<", "\\u003c");
|
|
@@ -113,6 +166,51 @@ function inlineJson(value) {
|
|
|
113
166
|
function inlineCode(code) {
|
|
114
167
|
return code.replace(/<\/(script)/gi, "<\\/$1").replaceAll("<!--", "<\\!--");
|
|
115
168
|
}
|
|
169
|
+
/** The image types the export copies (the same list the devtools panel serves). */
|
|
170
|
+
const SCREENSHOT_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
171
|
+
".png",
|
|
172
|
+
".jpg",
|
|
173
|
+
".jpeg",
|
|
174
|
+
".webp",
|
|
175
|
+
".gif"
|
|
176
|
+
]);
|
|
177
|
+
/** Every `WrittenScreenshot.path` in the written files, once each. */
|
|
178
|
+
function collectScreenshotPaths(written) {
|
|
179
|
+
const found = /* @__PURE__ */ new Set();
|
|
180
|
+
const walk = (value) => {
|
|
181
|
+
if (Array.isArray(value)) for (const item of value) walk(item);
|
|
182
|
+
else if (value !== null && typeof value === "object") {
|
|
183
|
+
const record = value;
|
|
184
|
+
if (typeof record.path === "string" && typeof record.written === "string" && typeof record.alt === "string") found.add(record.path);
|
|
185
|
+
for (const item of Object.values(record)) walk(item);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
walk(written);
|
|
189
|
+
return [...found].sort();
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Copy the screenshots the written files use into `<out>/screenshots/`. A path that leaves
|
|
193
|
+
* `grimoire/screenshots/`, has another extension or does not exist is skipped.
|
|
194
|
+
*
|
|
195
|
+
* @returns The paths that were copied.
|
|
196
|
+
*/
|
|
197
|
+
async function copyScreenshots(root, outFolder, paths) {
|
|
198
|
+
const folder = await realpath(path.join(root, GRIMOIRE_PATHS.screenshots)).catch(() => null);
|
|
199
|
+
const copied = [];
|
|
200
|
+
if (folder === null) return copied;
|
|
201
|
+
for (const written of paths) {
|
|
202
|
+
const segments = written.split("/");
|
|
203
|
+
if (written === "" || written.includes("\\") || written.includes("\0") || path.isAbsolute(written) || segments.some((segment) => segment === "" || segment === "." || segment === "..") || !SCREENSHOT_EXTENSIONS.has(path.extname(written).toLowerCase())) continue;
|
|
204
|
+
const source = await realpath(path.join(folder, ...segments)).catch(() => null);
|
|
205
|
+
if (source === null || !source.startsWith(folder + path.sep)) continue;
|
|
206
|
+
if (!(await stat(source)).isFile()) continue;
|
|
207
|
+
const target = path.join(outFolder, "screenshots", ...segments);
|
|
208
|
+
await mkdir(path.dirname(target), { recursive: true });
|
|
209
|
+
await copyFile(source, target);
|
|
210
|
+
copied.push(written);
|
|
211
|
+
}
|
|
212
|
+
return copied;
|
|
213
|
+
}
|
|
116
214
|
/** The answer, or `undefined` when the item cannot be answered (the export skips it). */
|
|
117
215
|
function attempt(answer) {
|
|
118
216
|
try {
|
|
@@ -128,13 +226,22 @@ function inlineView(source) {
|
|
|
128
226
|
return source.replace(marker, "");
|
|
129
227
|
}
|
|
130
228
|
/**
|
|
229
|
+
* The product map module as inline code: its `export` keywords are removed and the Grimoire view
|
|
230
|
+
* finds it as `globalThis.grimoireProductMap`.
|
|
231
|
+
*/
|
|
232
|
+
function inlineProductMap(source) {
|
|
233
|
+
const marker = "export default renderProductMap;";
|
|
234
|
+
if (!source.includes(marker)) throw new Error("product-map.js must end with `export default renderProductMap;`.");
|
|
235
|
+
return `${source.replace(marker, "").replace(/^export (async )?function /gm, "$1function ")}\nglobalThis.grimoireProductMap = { productMapView };\n`;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
131
238
|
* The page's own styles: it defines every devtools panel token (light, then dark under
|
|
132
239
|
* `prefers-color-scheme`), so `grimoire.css` renders the same here as in the dashboard.
|
|
133
240
|
* The values keep text AA on `--background` and `--card`.
|
|
134
241
|
*/
|
|
135
242
|
const PAGE_STYLE = `
|
|
136
|
-
:root{color-scheme:light dark;--background:#
|
|
137
|
-
@media (prefers-color-scheme:dark){:root{--background:#
|
|
243
|
+
:root{color-scheme:light dark;--background:#faf8f2;--foreground:#1a1814;--card:#fff;--card-foreground:#1a1814;--popover:#fff;--popover-foreground:#1a1814;--primary:#1a1814;--primary-foreground:#faf8f2;--secondary:#f0ece0;--secondary-foreground:#1a1814;--muted:#f0ece0;--muted-foreground:#5c574b;--accent:#f3ecd6;--accent-foreground:#1a1814;--destructive:#b42318;--border:#e0d9c6;--input:#d2cab3;--ring:#8a5a00;--radius:10px;--brand:#8a5a00;--brand-foreground:#fff;--success:#13693b;--warning:#8a5300;--info:#0b66a3;--chart-1:#8a5a00;--chart-2:#13693b;--chart-3:#0b66a3;--chart-4:#6d3ac7;--chart-5:#b4306b;font-family:system-ui,-apple-system,"Segoe UI",sans-serif}
|
|
244
|
+
@media (prefers-color-scheme:dark){:root{--background:#0b0b0c;--foreground:#f2f2ee;--card:#141416;--card-foreground:#f2f2ee;--popover:#141416;--popover-foreground:#f2f2ee;--primary:#ffc61a;--primary-foreground:#1a1300;--secondary:#1f1f22;--secondary-foreground:#f2f2ee;--muted:#1f1f22;--muted-foreground:#a9a9b0;--accent:#26262a;--accent-foreground:#f2f2ee;--destructive:#ff8f86;--border:#2a2a2e;--input:#34343a;--ring:#ffc61a;--radius:10px;--brand:#ffc61a;--brand-foreground:#1a1300;--success:#5fd391;--warning:#f3a24a;--info:#6cc0f5;--chart-1:#ffc61a;--chart-2:#5fd391;--chart-3:#6cc0f5;--chart-4:#b79cff;--chart-5:#ff8fbd}}
|
|
138
245
|
*{box-sizing:border-box}body{margin:0;background:var(--background);color:var(--foreground);font-size:14px;line-height:1.5}
|
|
139
246
|
main{max-width:1180px;margin:0 auto;padding:16px}
|
|
140
247
|
.empty{padding:12px;color:var(--muted-foreground)}.error{padding:12px;color:var(--destructive)}
|
|
@@ -142,14 +249,17 @@ main{max-width:1180px;margin:0 auto;padding:16px}
|
|
|
142
249
|
/** The `index.html` text. */
|
|
143
250
|
function renderSiteHtml(siteData, sources) {
|
|
144
251
|
const json = inlineJson(siteData);
|
|
145
|
-
|
|
252
|
+
if (sources.product === true && sources.productMap === void 0) throw new Error("A product export needs product-map.js.");
|
|
253
|
+
const mounted = sources.product === true ? "renderProductMap" : "renderGrimoire";
|
|
254
|
+
const script = inlineCode(`${sources.productMap === void 0 ? "" : inlineProductMap(sources.productMap)}${sources.product === true ? "" : inlineView(sources.view)}\n${sources.loader}\ngrimoireStaticMount(JSON.parse(document.getElementById("grimoire-data").textContent), document.getElementById("grimoire-root"), ${mounted});\n`);
|
|
255
|
+
const styles = sources.product === true ? "" : sources.css;
|
|
146
256
|
return `<!doctype html>
|
|
147
257
|
<html lang="en">
|
|
148
258
|
<head>
|
|
149
259
|
<meta charset="utf-8">
|
|
150
260
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
151
|
-
<title
|
|
152
|
-
<style>${PAGE_STYLE}${sources.
|
|
261
|
+
${sources.stamp === void 0 ? "" : `<meta name="grimoire-stamp" content="${sources.stamp}">\n`}<title>${sources.product === true ? "Product map" : "Grimoire"}</title>
|
|
262
|
+
<style>${PAGE_STYLE}${styles}${sources.productCss ?? ""}</style>
|
|
153
263
|
</head>
|
|
154
264
|
<body>
|
|
155
265
|
<main id="grimoire-root"><p class="empty">Opening the book…</p></main>
|
|
@@ -159,6 +269,37 @@ function renderSiteHtml(siteData, sources) {
|
|
|
159
269
|
</html>
|
|
160
270
|
`;
|
|
161
271
|
}
|
|
272
|
+
/** The stamp is written near the top of the page; this much of the file is enough to find it. */
|
|
273
|
+
const STAMP_HEAD_BYTES = 2048;
|
|
274
|
+
/** The stamp of the page that is already in `index.html`, or `null` (no page, or one without a stamp). */
|
|
275
|
+
async function writtenStamp(file) {
|
|
276
|
+
let handle;
|
|
277
|
+
try {
|
|
278
|
+
handle = await open(file, "r");
|
|
279
|
+
const { buffer, bytesRead } = await handle.read(Buffer.alloc(STAMP_HEAD_BYTES), 0, STAMP_HEAD_BYTES, 0);
|
|
280
|
+
return /<meta name="grimoire-stamp" content="([0-9a-f]+)">/.exec(buffer.toString("utf8", 0, bytesRead))?.[1] ?? null;
|
|
281
|
+
} catch {
|
|
282
|
+
return null;
|
|
283
|
+
} finally {
|
|
284
|
+
await handle?.close();
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
/** Modified times of the files the page is built from, so a new framework version rebuilds the page. */
|
|
288
|
+
async function uiStamp() {
|
|
289
|
+
return (await Promise.all([
|
|
290
|
+
"grimoire-view.js",
|
|
291
|
+
"grimoire-static.js",
|
|
292
|
+
"grimoire.css",
|
|
293
|
+
"product-map.js",
|
|
294
|
+
"product-map.css"
|
|
295
|
+
].map(async (name) => {
|
|
296
|
+
try {
|
|
297
|
+
return (await stat(path.join(uiFolder, name))).mtimeMs;
|
|
298
|
+
} catch {
|
|
299
|
+
return 0;
|
|
300
|
+
}
|
|
301
|
+
}))).join(",");
|
|
302
|
+
}
|
|
162
303
|
/**
|
|
163
304
|
* Write the tab as a static folder for people without the app running.
|
|
164
305
|
*
|
|
@@ -167,28 +308,55 @@ function renderSiteHtml(siteData, sources) {
|
|
|
167
308
|
* page and use `#grimoire/...` links; the answers that need the running app
|
|
168
309
|
* (impact of a file) say so in place.
|
|
169
310
|
*
|
|
311
|
+
* With `product: true` the page is the business export: the share-safe
|
|
312
|
+
* Product map only, no file paths, test names or per-file answers.
|
|
313
|
+
*
|
|
314
|
+
* The page carries a freshness stamp (the files of the book, the written
|
|
315
|
+
* folders and the test results). When the folder already holds a page with
|
|
316
|
+
* the same stamp and the same mode, nothing is rebuilt or written (`force`
|
|
317
|
+
* writes it anyway).
|
|
318
|
+
*
|
|
170
319
|
* @param root Absolute project root.
|
|
171
|
-
* @returns The output folder, project-relative.
|
|
172
320
|
*/
|
|
173
|
-
async function
|
|
321
|
+
async function exportGrimoireSiteDetailed(root, options = {}) {
|
|
174
322
|
const outDir = projectPath(root, toPosixPath(options.outDir ?? GRIMOIRE_PATHS.staticSite)).replace(/\/+$/, "");
|
|
175
323
|
const snapshot = options.snapshot ?? await createSnapshotSource(root, options.adapter === void 0 ? {} : { adapter: options.adapter }).get();
|
|
176
|
-
const
|
|
324
|
+
const absolute = path.resolve(root, outDir);
|
|
325
|
+
const product = options.product === true;
|
|
326
|
+
const stamp = createHash("sha1").update(`${product ? "product" : "full"}|${await stampOf(root, snapshot)}|${await uiStamp()}`).digest("hex");
|
|
327
|
+
if (options.force !== true && await writtenStamp(path.join(absolute, "index.html")) === stamp) return {
|
|
328
|
+
outDir,
|
|
329
|
+
upToDate: true
|
|
330
|
+
};
|
|
331
|
+
const [view, loader, css, productMapSource, productCss] = await Promise.all([
|
|
177
332
|
"grimoire-view.js",
|
|
178
333
|
"grimoire-static.js",
|
|
179
|
-
"grimoire.css"
|
|
334
|
+
"grimoire.css",
|
|
335
|
+
"product-map.js",
|
|
336
|
+
"product-map.css"
|
|
180
337
|
].map((name) => readFile(path.join(uiFolder, name), "utf8")));
|
|
181
|
-
const html = renderSiteHtml(buildSiteData(snapshot), {
|
|
338
|
+
const html = renderSiteHtml(product ? buildProductSiteData(snapshot) : buildSiteData(snapshot), {
|
|
182
339
|
view: view ?? "",
|
|
183
340
|
loader: loader ?? "",
|
|
184
|
-
css: css ?? ""
|
|
341
|
+
css: css ?? "",
|
|
342
|
+
productMap: productMapSource ?? "",
|
|
343
|
+
productCss: productCss ?? "",
|
|
344
|
+
product,
|
|
345
|
+
stamp
|
|
185
346
|
});
|
|
186
|
-
const absolute = path.resolve(root, outDir);
|
|
187
347
|
await mkdir(absolute, { recursive: true });
|
|
188
348
|
await writeFile(path.join(absolute, "index.html"), html);
|
|
189
|
-
|
|
349
|
+
await copyScreenshots(root, absolute, collectScreenshotPaths(snapshot.written));
|
|
350
|
+
return {
|
|
351
|
+
outDir,
|
|
352
|
+
upToDate: false
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
/** `exportGrimoireSiteDetailed()` that returns only the output folder, project-relative. */
|
|
356
|
+
async function exportGrimoireSite(root, options = {}) {
|
|
357
|
+
return (await exportGrimoireSiteDetailed(root, options)).outDir;
|
|
190
358
|
}
|
|
191
359
|
|
|
192
360
|
//#endregion
|
|
193
|
-
export { PAGE_STYLE, SITE_FILE_LIMIT, buildSiteData, exportGrimoireSite, inlineView, renderSiteHtml };
|
|
361
|
+
export { PAGE_STYLE, SITE_FILE_LIMIT, buildProductSiteData, buildSiteData, collectScreenshotPaths, copyScreenshots, exportGrimoireSite, exportGrimoireSiteDetailed, inlineProductMap, inlineView, renderSiteHtml };
|
|
194
362
|
//# sourceMappingURL=site.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"site.mjs","names":["data.summary","data.features","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 features: data.features(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\n/**\n * The page's own styles: it defines every devtools panel token (light, then dark under\n * `prefers-color-scheme`), so `grimoire.css` renders the same here as in the dashboard.\n * The values keep text AA on `--background` and `--card`.\n */\nexport const PAGE_STYLE = `\n:root{color-scheme:light dark;--background:#f7f8fa;--foreground:#161b22;--card:#fff;--card-foreground:#161b22;--popover:#fff;--popover-foreground:#161b22;--primary:#1f2937;--primary-foreground:#fff;--secondary:#eceff3;--secondary-foreground:#1f2937;--muted:#eceff3;--muted-foreground:#4b5565;--accent:#e4e9f2;--accent-foreground:#161b22;--destructive:#b42318;--border:#d5dae3;--input:#c3cad6;--ring:#2f5fd0;--radius:10px;--brand:#2757c4;--brand-foreground:#fff;--success:#13693b;--warning:#8a5300;--info:#0b66a3;--chart-1:#2757c4;--chart-2:#13693b;--chart-3:#8a5300;--chart-4:#6d3ac7;--chart-5:#b4306b;font-family:system-ui,-apple-system,\"Segoe UI\",sans-serif}\n@media (prefers-color-scheme:dark){:root{--background:#14171c;--foreground:#eceff4;--card:#1c2027;--card-foreground:#eceff4;--popover:#1c2027;--popover-foreground:#eceff4;--primary:#eceff4;--primary-foreground:#14171c;--secondary:#272c35;--secondary-foreground:#eceff4;--muted:#272c35;--muted-foreground:#a9b2c1;--accent:#2d3440;--accent-foreground:#eceff4;--destructive:#ff8f86;--border:#343b47;--input:#3f4756;--ring:#8fb0ff;--radius:10px;--brand:#86adff;--brand-foreground:#0d1320;--success:#5fd391;--warning:#f3b25a;--info:#6cc0f5;--chart-1:#86adff;--chart-2:#5fd391;--chart-3:#f3b25a;--chart-4:#b79cff;--chart-5:#ff8fbd}}\n*{box-sizing:border-box}body{margin:0;background:var(--background);color:var(--foreground);font-size:14px;line-height:1.5}\nmain{max-width:1180px;margin:0 auto;padding:16px}\n.empty{padding:12px;color:var(--muted-foreground)}.error{padding:12px;color:var(--destructive)}\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\">Opening the book…</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,UAAUC,SAAc,QAAQ;EAChC,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,a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K,CAAC;CACzC,MAAM,UAAU,KAAK,KAAK,UAAU,YAAY,GAAG,IAAI;CAEvD,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"site.mjs","names":["data.summary","data.features","data.apps","data.tasks","data.releases","data.check","data.graphOfModules","data.checkGroups","feature","data.feature","flowAnswer","data.flowAnswer","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 { createHash } from \"node:crypto\";\nimport { copyFile, mkdir, open, readFile, realpath, stat, 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 type { WrittenFlow } from \"../contracts/written\";\nimport { GRIMOIRE_PATHS, projectPath, toPosixPath } from \"../paths\";\nimport { stampOf } from \"../workspace/cache\";\nimport * as data from \"./data\";\nimport { featureGraph, fileGraph, pageGraph } from \"./graphs\";\nimport { productFeature, productFlow, productMap } from \"./product-map\";\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 * Export the business view only: the share-safe Product map (no file paths, test\n * names or export names, no per-file answers, no check or search of code). The\n * page opens on the Product map.\n */\n product?: boolean;\n /** Write the page even when the folder already holds one built from the same book. Default `false`. */\n force?: boolean;\n};\n\n/** What `exportGrimoireSite()` did. */\nexport type GrimoireSiteExport = {\n /** The output folder, project-relative. */\n outDir: string;\n /** `true` when the folder already held a page built from the same book and nothing was written. */\n upToDate: boolean;\n};\n\n/** The most files the export keeps per-file answers for (the most imported first). */\nexport const SITE_FILE_LIMIT = 3000;\n\n/** One entry of the exported search list. `text` is written content (a flow's summary, story, cases and criteria) the search also reads. */\ntype SearchItem = { type: string; id: string; detail: string | null; text?: string };\n\n/** The written text of a flow the exported search reads, with criteria ids so `AC-5` is findable. */\nfunction flowSearchText(flow: WrittenFlow): string {\n return [\n flow.summary ?? \"\",\n ...flow.story.map((step) => step.text),\n ...flow.cases.map((item) => `${item.question} ${item.answer} ${item.criteria.join(\" \")}`),\n ...flow.criteria.map((item) => `${item.id} ${item.text}`),\n ]\n .filter((part) => part !== \"\")\n .join(\" | \");\n}\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 features: data.features(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 // The static page is the signed-in view: developer detail stays, and no monitor reports errors.\n const productOptions = { shared: false, errors: null } as const;\n const productAnswer = attempt(() => productMap(snapshot, productOptions));\n const groups = attempt(() => data.checkGroups(snapshot));\n\n if (productAnswer !== undefined) routes.product = productAnswer;\n\n if (groups !== undefined) routes[\"check/groups\"] = groups;\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({\n type: \"feature\",\n id: feature.id,\n detail: readme?.title.value ?? null,\n text: [readme?.summary ?? \"\", readme?.why ?? \"\"].filter((part) => part !== \"\").join(\" | \"),\n });\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 const product = attempt(() => productFeature(snapshot, feature.id, productOptions));\n\n if (product !== undefined) routes[`product/features/${feature.id}`] = product;\n\n for (const flow of feature.flows) {\n search.push({\n type: \"flow\",\n id: flow.ref,\n detail: flow.heading?.value ?? null,\n text: flowSearchText(flow),\n });\n const flowAnswer = attempt(() => data.flowAnswer(snapshot, feature.id, flow.id.value));\n const productFlowAnswer = attempt(() =>\n productFlow(snapshot, feature.id, flow.id.value, productOptions),\n );\n\n if (flowAnswer !== undefined) routes[`flows/${flow.ref}`] = flowAnswer;\n\n if (productFlowAnswer !== undefined) routes[`product/flows/${flow.ref}`] = productFlowAnswer;\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/**\n * The business-only data of the static export: the share-safe Product map, its feature\n * and flow pages, and nothing else. No file paths, test names, export names, check\n * findings or per-file answers; the search list is empty.\n */\nexport function buildProductSiteData(snapshot: GrimoireSnapshot) {\n const options = { shared: true, errors: null } as const;\n const routes: Record<string, unknown> = {};\n const map = attempt(() => productMap(snapshot, options));\n\n if (map !== undefined) routes.product = map;\n\n for (const feature of snapshot.written.features) {\n const answer = attempt(() => productFeature(snapshot, feature.id, options));\n\n if (answer !== undefined) routes[`product/features/${feature.id}`] = answer;\n\n for (const flow of feature.flows) {\n const flowAnswer = attempt(() => productFlow(snapshot, feature.id, flow.id.value, options));\n\n if (flowAnswer !== undefined) routes[`product/flows/${flow.ref}`] = flowAnswer;\n }\n }\n\n return { routes, files: {}, search: [] as SearchItem[] };\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 image types the export copies (the same list the devtools panel serves). */\nconst SCREENSHOT_EXTENSIONS = new Set([\".png\", \".jpg\", \".jpeg\", \".webp\", \".gif\"]);\n\n/** Every `WrittenScreenshot.path` in the written files, once each. */\nexport function collectScreenshotPaths(written: unknown): string[] {\n const found = new Set<string>();\n const walk = (value: unknown): void => {\n if (Array.isArray(value)) {\n for (const item of value) walk(item);\n } else if (value !== null && typeof value === \"object\") {\n const record = value as Record<string, unknown>;\n\n if (\n typeof record.path === \"string\" &&\n typeof record.written === \"string\" &&\n typeof record.alt === \"string\"\n )\n found.add(record.path);\n\n for (const item of Object.values(record)) walk(item);\n }\n };\n\n walk(written);\n\n return [...found].sort();\n}\n\n/**\n * Copy the screenshots the written files use into `<out>/screenshots/`. A path that leaves\n * `grimoire/screenshots/`, has another extension or does not exist is skipped.\n *\n * @returns The paths that were copied.\n */\nexport async function copyScreenshots(\n root: string,\n outFolder: string,\n paths: readonly string[],\n): Promise<string[]> {\n const folder = await realpath(path.join(root, GRIMOIRE_PATHS.screenshots)).catch(() => null);\n const copied: string[] = [];\n\n if (folder === null) return copied;\n\n for (const written of paths) {\n const segments = written.split(\"/\");\n\n if (\n written === \"\" ||\n written.includes(\"\\\\\") ||\n written.includes(\"\\0\") ||\n path.isAbsolute(written) ||\n segments.some((segment) => segment === \"\" || segment === \".\" || segment === \"..\") ||\n !SCREENSHOT_EXTENSIONS.has(path.extname(written).toLowerCase())\n )\n continue;\n\n const source = await realpath(path.join(folder, ...segments)).catch(() => null);\n\n if (source === null || !source.startsWith(folder + path.sep)) continue;\n\n if (!(await stat(source)).isFile()) continue;\n\n const target = path.join(outFolder, \"screenshots\", ...segments);\n\n await mkdir(path.dirname(target), { recursive: true });\n await copyFile(source, target);\n copied.push(written);\n }\n\n return copied;\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\n/**\n * The product map module as inline code: its `export` keywords are removed and the Grimoire view\n * finds it as `globalThis.grimoireProductMap`.\n */\nexport function inlineProductMap(source: string): string {\n const marker = \"export default renderProductMap;\";\n\n if (!source.includes(marker))\n throw new Error(\"product-map.js must end with `export default renderProductMap;`.\");\n\n return `${source.replace(marker, \"\").replace(/^export (async )?function /gm, \"$1function \")}\\nglobalThis.grimoireProductMap = { productMapView };\\n`;\n}\n\n/**\n * The page's own styles: it defines every devtools panel token (light, then dark under\n * `prefers-color-scheme`), so `grimoire.css` renders the same here as in the dashboard.\n * The values keep text AA on `--background` and `--card`.\n */\nexport const PAGE_STYLE = `\n:root{color-scheme:light dark;--background:#faf8f2;--foreground:#1a1814;--card:#fff;--card-foreground:#1a1814;--popover:#fff;--popover-foreground:#1a1814;--primary:#1a1814;--primary-foreground:#faf8f2;--secondary:#f0ece0;--secondary-foreground:#1a1814;--muted:#f0ece0;--muted-foreground:#5c574b;--accent:#f3ecd6;--accent-foreground:#1a1814;--destructive:#b42318;--border:#e0d9c6;--input:#d2cab3;--ring:#8a5a00;--radius:10px;--brand:#8a5a00;--brand-foreground:#fff;--success:#13693b;--warning:#8a5300;--info:#0b66a3;--chart-1:#8a5a00;--chart-2:#13693b;--chart-3:#0b66a3;--chart-4:#6d3ac7;--chart-5:#b4306b;font-family:system-ui,-apple-system,\"Segoe UI\",sans-serif}\n@media (prefers-color-scheme:dark){:root{--background:#0b0b0c;--foreground:#f2f2ee;--card:#141416;--card-foreground:#f2f2ee;--popover:#141416;--popover-foreground:#f2f2ee;--primary:#ffc61a;--primary-foreground:#1a1300;--secondary:#1f1f22;--secondary-foreground:#f2f2ee;--muted:#1f1f22;--muted-foreground:#a9a9b0;--accent:#26262a;--accent-foreground:#f2f2ee;--destructive:#ff8f86;--border:#2a2a2e;--input:#34343a;--ring:#ffc61a;--radius:10px;--brand:#ffc61a;--brand-foreground:#1a1300;--success:#5fd391;--warning:#f3a24a;--info:#6cc0f5;--chart-1:#ffc61a;--chart-2:#5fd391;--chart-3:#6cc0f5;--chart-4:#b79cff;--chart-5:#ff8fbd}}\n*{box-sizing:border-box}body{margin:0;background:var(--background);color:var(--foreground);font-size:14px;line-height:1.5}\nmain{max-width:1180px;margin:0 auto;padding:16px}\n.empty{padding:12px;color:var(--muted-foreground)}.error{padding:12px;color:var(--destructive)}\n`;\n\n/** The `index.html` text. */\nexport function renderSiteHtml(\n siteData: unknown,\n sources: {\n view: string;\n loader: string;\n css: string;\n productMap?: string;\n productCss?: string;\n /** Mount the share-safe Product map alone (the business export): `view` and `css` are not inlined. */\n product?: boolean;\n /** A freshness stamp written into the page, so the next export can tell it is current. */\n stamp?: string;\n },\n): string {\n const json = inlineJson(siteData);\n\n if (sources.product === true && sources.productMap === undefined) {\n throw new Error(\"A product export needs product-map.js.\");\n }\n\n const mounted = sources.product === true ? \"renderProductMap\" : \"renderGrimoire\";\n const script = inlineCode(\n `${sources.productMap === undefined ? \"\" : inlineProductMap(sources.productMap)}${sources.product === true ? \"\" : inlineView(sources.view)}\\n${sources.loader}\\ngrimoireStaticMount(JSON.parse(document.getElementById(\"grimoire-data\").textContent), document.getElementById(\"grimoire-root\"), ${mounted});\\n`,\n );\n const styles = sources.product === true ? \"\" : sources.css;\n const stamp =\n sources.stamp === undefined ? \"\" : `<meta name=\"grimoire-stamp\" content=\"${sources.stamp}\">\\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${stamp}<title>${sources.product === true ? \"Product map\" : \"Grimoire\"}</title>\n<style>${PAGE_STYLE}${styles}${sources.productCss ?? \"\"}</style>\n</head>\n<body>\n<main id=\"grimoire-root\"><p class=\"empty\">Opening the book…</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/** The stamp is written near the top of the page; this much of the file is enough to find it. */\nconst STAMP_HEAD_BYTES = 2048;\n\n/** The stamp of the page that is already in `index.html`, or `null` (no page, or one without a stamp). */\nasync function writtenStamp(file: string): Promise<string | null> {\n let handle;\n\n try {\n handle = await open(file, \"r\");\n\n const { buffer, bytesRead } = await handle.read(\n Buffer.alloc(STAMP_HEAD_BYTES),\n 0,\n STAMP_HEAD_BYTES,\n 0,\n );\n\n return (\n /<meta name=\"grimoire-stamp\" content=\"([0-9a-f]+)\">/.exec(\n buffer.toString(\"utf8\", 0, bytesRead),\n )?.[1] ?? null\n );\n } catch {\n return null;\n } finally {\n await handle?.close();\n }\n}\n\n/** Modified times of the files the page is built from, so a new framework version rebuilds the page. */\nasync function uiStamp(): Promise<string> {\n const names = [\n \"grimoire-view.js\",\n \"grimoire-static.js\",\n \"grimoire.css\",\n \"product-map.js\",\n \"product-map.css\",\n ];\n const times = await Promise.all(\n names.map(async (name) => {\n try {\n return (await stat(path.join(uiFolder, name))).mtimeMs;\n } catch {\n return 0;\n }\n }),\n );\n\n return times.join(\",\");\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 * With `product: true` the page is the business export: the share-safe\n * Product map only, no file paths, test names or per-file answers.\n *\n * The page carries a freshness stamp (the files of the book, the written\n * folders and the test results). When the folder already holds a page with\n * the same stamp and the same mode, nothing is rebuilt or written (`force`\n * writes it anyway).\n *\n * @param root Absolute project root.\n */\nexport async function exportGrimoireSiteDetailed(\n root: string,\n options: ExportGrimoireSiteOptions = {},\n): Promise<GrimoireSiteExport> {\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 absolute = path.resolve(root, outDir);\n const product = options.product === true;\n const stamp = createHash(\"sha1\")\n .update(`${product ? \"product\" : \"full\"}|${await stampOf(root, snapshot)}|${await uiStamp()}`)\n .digest(\"hex\");\n\n if (options.force !== true && (await writtenStamp(path.join(absolute, \"index.html\"))) === stamp) {\n return { outDir, upToDate: true };\n }\n\n const [view, loader, css, productMapSource, productCss] = await Promise.all(\n [\n \"grimoire-view.js\",\n \"grimoire-static.js\",\n \"grimoire.css\",\n \"product-map.js\",\n \"product-map.css\",\n ].map((name) => readFile(path.join(uiFolder, name), \"utf8\")),\n );\n const html = renderSiteHtml(product ? buildProductSiteData(snapshot) : buildSiteData(snapshot), {\n view: view ?? \"\",\n loader: loader ?? \"\",\n css: css ?? \"\",\n productMap: productMapSource ?? \"\",\n productCss: productCss ?? \"\",\n product,\n stamp,\n });\n\n await mkdir(absolute, { recursive: true });\n await writeFile(path.join(absolute, \"index.html\"), html);\n await copyScreenshots(root, absolute, collectScreenshotPaths(snapshot.written));\n\n return { outDir, upToDate: false };\n}\n\n/** `exportGrimoireSiteDetailed()` that returns only the output folder, project-relative. */\nexport async function exportGrimoireSite(\n root: string,\n options: ExportGrimoireSiteOptions = {},\n): Promise<string> {\n return (await exportGrimoireSiteDetailed(root, options)).outDir;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA8CA,MAAa,kBAAkB;;AAM/B,SAAS,eAAe,MAA2B;CACjD,OAAO;EACL,KAAK,WAAW;EAChB,GAAG,KAAK,MAAM,KAAK,SAAS,KAAK,IAAI;EACrC,GAAG,KAAK,MAAM,KAAK,SAAS,GAAG,KAAK,SAAS,GAAG,KAAK,OAAO,GAAG,KAAK,SAAS,KAAK,GAAG,GAAG;EACxF,GAAG,KAAK,SAAS,KAAK,SAAS,GAAG,KAAK,GAAG,GAAG,KAAK,MAAM;CAC1D,CAAC,CACE,QAAQ,SAAS,SAAS,EAAE,CAAC,CAC7B,KAAK,KAAK;AACf;AAEA,MAAM,WAAW,cAAc,IAAI,IAAI,aAAa,YAAY,GAAG,CAAC;;AAGpE,SAAgB,cAAc,UAA4B;CACxD,MAAM,SAAkC;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AAM,2BAA2B,MAAM,OAAO,EAAC,CAAE;AAC3D"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GRIMOIRE_PATHS } from "../paths/index.mjs";
|
|
2
|
+
import { resolveResultsFile } from "../test-results/index.mjs";
|
|
2
3
|
import { openGrimoire } from "../workspace/index.mjs";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import { stat } from "node:fs/promises";
|
|
@@ -40,10 +41,11 @@ const STAMPED = [
|
|
|
40
41
|
GRIMOIRE_PATHS.doneTasks,
|
|
41
42
|
GRIMOIRE_PATHS.releases
|
|
42
43
|
];
|
|
43
|
-
async function changeStamp(root) {
|
|
44
|
-
|
|
44
|
+
async function changeStamp(root, resultsFile) {
|
|
45
|
+
const files = [...STAMPED.map((entry) => path.join(root, ...entry.split("/"))), resultsFile];
|
|
46
|
+
return (await Promise.all(files.map(async (file) => {
|
|
45
47
|
try {
|
|
46
|
-
return (await stat(
|
|
48
|
+
return (await stat(file)).mtimeMs;
|
|
47
49
|
} catch {
|
|
48
50
|
return 0;
|
|
49
51
|
}
|
|
@@ -60,20 +62,35 @@ async function loadAdapter(option) {
|
|
|
60
62
|
function createSnapshotSource(root, options = {}) {
|
|
61
63
|
let cached = null;
|
|
62
64
|
let opening = null;
|
|
65
|
+
let collected = options.collectRoutes !== true || options.mode === "production";
|
|
66
|
+
const resultsFile = resolveResultsFile(root, options.testResultsFile);
|
|
63
67
|
const keepUntilChanged = options.mode === "production" && options.ttlMs === void 0;
|
|
64
68
|
const reuseFor = (took) => options.ttlMs ?? Math.max(2e3, took * 5);
|
|
65
69
|
async function open() {
|
|
66
70
|
const started = Date.now();
|
|
67
71
|
const adapter = await loadAdapter(options.adapter);
|
|
68
|
-
const
|
|
72
|
+
const openOptions = {
|
|
73
|
+
write: options.write ?? false,
|
|
74
|
+
...options.testResultsFile === void 0 ? {} : { testResultsFile: options.testResultsFile }
|
|
75
|
+
};
|
|
76
|
+
let snapshot = await openGrimoire(root, adapter, {
|
|
69
77
|
routes: "cached",
|
|
70
|
-
|
|
78
|
+
...openOptions
|
|
71
79
|
});
|
|
80
|
+
if (!collected && snapshot.routes === "missing") {
|
|
81
|
+
collected = true;
|
|
82
|
+
try {
|
|
83
|
+
snapshot = await openGrimoire(root, adapter, {
|
|
84
|
+
routes: "fresh",
|
|
85
|
+
...openOptions
|
|
86
|
+
});
|
|
87
|
+
} catch {}
|
|
88
|
+
}
|
|
72
89
|
const at = Date.now();
|
|
73
90
|
cached = {
|
|
74
91
|
snapshot,
|
|
75
92
|
at,
|
|
76
|
-
stamp: await changeStamp(root),
|
|
93
|
+
stamp: await changeStamp(root, resultsFile),
|
|
77
94
|
took: at - started
|
|
78
95
|
};
|
|
79
96
|
return snapshot;
|
|
@@ -89,7 +106,7 @@ function createSnapshotSource(root, options = {}) {
|
|
|
89
106
|
async get() {
|
|
90
107
|
if (cached === null) return ensureOpening();
|
|
91
108
|
const known = cached;
|
|
92
|
-
const changed = await changeStamp(root) !== known.stamp;
|
|
109
|
+
const changed = await changeStamp(root, resultsFile) !== known.stamp;
|
|
93
110
|
if (changed || options.mode === "production") {
|
|
94
111
|
if (!changed && (keepUntilChanged || Date.now() - known.at < reuseFor(known.took))) return known.snapshot;
|
|
95
112
|
return ensureOpening().catch(() => known.snapshot);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot-source.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/snapshot-source.ts"],"sourcesContent":["/**\n * Where the panel's routes get the snapshot: opened once with\n * `routes: \"cached\"` (a devtools request never boots the app) and kept in\n * memory. Concurrent requests share one open. A change stamp (the book\n * manifest plus the agent-written folders and indexes, a few `stat` calls and\n * no directory walk) tells when the book changed.\n *\n * - Production (`mode: \"production\"`): a snapshot is reused until the stamp\n * changes, with no time limit, unless `ttlMs` is set. A request that finds\n * the stamp changed waits for the new open. `warm()` opens the book ahead\n * of the first request.\n * - Development: the snapshot is reused for a short window (2 s, or five times\n * the last open when that is longer, so a slow open on a large app is not\n * repeated on every view; written files change while an agent works). A\n * request that finds the stamp changed waits for the new open. After the\n * window, with the stamp unchanged (a file edited in place), the cached\n * snapshot is served at once and one background open refreshes it (stale\n * while revalidate).\n *\n * An open that fails keeps serving the old snapshot; its error surfaces on a\n * request only when there is no snapshot at all. The panel passes\n * `write: true` in development, so the generated book stays current and the\n * next open is incremental; with `write: false` a stored book behind the\n * sources is rebuilt in memory on every open.\n */\nimport { stat } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport { GRIMOIRE_PATHS } from \"../paths\";\nimport { openGrimoire } from \"../workspace\";\n\n/** Options of the panel's snapshot source. */\nexport type SnapshotSourceOptions = {\n /** The adapter, or a function that loads it. Default: the Warlock adapter, imported on first use. */\n adapter?: BookAdapter | (() => Promise<BookAdapter>);\n /**\n * How long a snapshot is reused when the book did not change (ms).\n * Default in development: 2000, or five times as long as the last open took\n * when that is longer. Default in production: no limit (reused until the\n * book changes).\n */\n ttlMs?: number;\n /** Where the source runs. `\"production\"` keeps a snapshot until the book changes. Default: `\"development\"`. */\n mode?: \"development\" | \"production\";\n /** Let `openGrimoire` write the generated book and collected files (never agent-written files). Default `false`; the devtools panel passes `true`. */\n write?: boolean;\n};\n\n/** A cached, shared snapshot of one project. */\nexport type SnapshotSource = {\n get(): Promise<GrimoireSnapshot>;\n /** Forget the cached snapshot; the next `get()` opens again. */\n invalidate(): void;\n /** Start opening the book now, so the first `get()` is fast. Failures are ignored here and surface on `get()`. */\n warm(): void;\n /** Resolves when no open is running (specs and shutdown). Never rejects. */\n idle(): Promise<void>;\n};\n\n/** Files and folders whose modified time moves when the book or an agent-written file is added, removed or regenerated. */\nconst STAMPED = [\n GRIMOIRE_PATHS.bookManifest,\n GRIMOIRE_PATHS.featuresIndex,\n GRIMOIRE_PATHS.tasksIndex,\n GRIMOIRE_PATHS.features,\n GRIMOIRE_PATHS.apps,\n GRIMOIRE_PATHS.openTasks,\n GRIMOIRE_PATHS.doneTasks,\n GRIMOIRE_PATHS.releases,\n];\n\nasync function changeStamp(root: string): Promise<string> {\n const times = await Promise.all(\n STAMPED.map(async (entry) => {\n try {\n return (await stat(path.join(root, ...entry.split(\"/\")))).mtimeMs;\n } catch {\n return 0;\n }\n }),\n );\n\n return times.join(\",\");\n}\n\nasync function loadAdapter(option: SnapshotSourceOptions[\"adapter\"]): Promise<BookAdapter> {\n if (option === undefined) {\n const { createWarlockAdapter } = await import(\"../warlock\");\n\n return createWarlockAdapter();\n }\n\n return typeof option === \"function\" ? option() : option;\n}\n\n/** Create the source for the project at `root`. */\nexport function createSnapshotSource(\n root: string,\n options: SnapshotSourceOptions = {},\n): SnapshotSource {\n let cached: { snapshot: GrimoireSnapshot; at: number; stamp: string; took: number } | null = null;\n let opening: Promise<GrimoireSnapshot> | null = null;\n\n const keepUntilChanged = options.mode === \"production\" && options.ttlMs === undefined;\n const reuseFor = (took: number): number => options.ttlMs ?? Math.max(2000, took * 5);\n\n async function open(): Promise<GrimoireSnapshot> {\n const started = Date.now();\n const adapter = await loadAdapter(options.adapter);\n const snapshot = await openGrimoire(root, adapter, {\n routes: \"cached\",\n write: options.write ?? false,\n });\n\n const at = Date.now();\n\n cached = { snapshot, at, stamp: await changeStamp(root), took: at - started };\n\n return snapshot;\n }\n\n /** The open in flight, or a new one; concurrent callers share it. */\n function ensureOpening(): Promise<GrimoireSnapshot> {\n opening ??= open().finally(() => {\n opening = null;\n });\n\n return opening;\n }\n\n return {\n async get() {\n if (cached === null) return ensureOpening();\n\n const known = cached;\n const changed = (await changeStamp(root)) !== known.stamp;\n\n if (changed || options.mode === \"production\") {\n if (!changed && (keepUntilChanged || Date.now() - known.at < reuseFor(known.took))) {\n return known.snapshot;\n }\n\n // A failed open keeps the old snapshot; the next request tries again.\n return ensureOpening().catch(() => known.snapshot);\n }\n\n if (Date.now() - known.at < reuseFor(known.took)) return known.snapshot;\n\n // Development, nothing known to have changed: serve the old snapshot now and refresh behind it.\n ensureOpening().catch(() => {});\n\n return known.snapshot;\n },\n invalidate() {\n cached = null;\n },\n warm() {\n if (cached === null) ensureOpening().catch(() => {});\n },\n async idle() {\n await opening?.catch(() => {});\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,MAAM,UAAU;CACd,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;AACjB;AAEA,eAAe,YAAY,MAA+B;CAWxD,QAAO,MAVa,QAAQ,IAC1B,QAAQ,IAAI,OAAO,UAAU;EAC3B,IAAI;GACF,QAAQ,MAAM,KAAK,KAAK,KAAK,MAAM,GAAG,MAAM,MAAM,GAAG,CAAC,CAAC,EAAC,CAAE;EAC5D,QAAQ;GACN,OAAO;EACT;CACF,CAAC,CACH,EAEY,CAAC,KAAK,GAAG;AACvB;AAEA,eAAe,YAAY,QAAgE;CACzF,IAAI,WAAW,QAAW;EACxB,MAAM,EAAE,yBAAyB,MAAM,OAAO;EAE9C,OAAO,qBAAqB;CAC9B;CAEA,OAAO,OAAO,WAAW,aAAa,OAAO,IAAI;AACnD;;AAGA,SAAgB,qBACd,MACA,UAAiC,CAAC,GAClB;CAChB,IAAI,SAAyF;CAC7F,IAAI,UAA4C;CAEhD,MAAM,mBAAmB,QAAQ,SAAS,gBAAgB,QAAQ,UAAU;CAC5E,MAAM,YAAY,SAAyB,QAAQ,SAAS,KAAK,IAAI,KAAM,OAAO,CAAC;CAEnF,eAAe,OAAkC;EAC/C,MAAM,UAAU,KAAK,IAAI;EACzB,MAAM,UAAU,MAAM,YAAY,QAAQ,OAAO;EACjD,MAAM,WAAW,MAAM,aAAa,MAAM,SAAS;GACjD,QAAQ;GACR,OAAO,QAAQ,SAAS;EAC1B,CAAC;EAED,MAAM,KAAK,KAAK,IAAI;EAEpB,SAAS;GAAE;GAAU;GAAI,OAAO,MAAM,YAAY,IAAI;GAAG,MAAM,KAAK;EAAQ;EAE5E,OAAO;CACT;;CAGA,SAAS,gBAA2C;EAClD,YAAY,KAAK,CAAC,CAAC,cAAc;GAC/B,UAAU;EACZ,CAAC;EAED,OAAO;CACT;CAEA,OAAO;EACL,MAAM,MAAM;GACV,IAAI,WAAW,MAAM,OAAO,cAAc;GAE1C,MAAM,QAAQ;GACd,MAAM,UAAW,MAAM,YAAY,IAAI,MAAO,MAAM;GAEpD,IAAI,WAAW,QAAQ,SAAS,cAAc;IAC5C,IAAI,CAAC,YAAY,oBAAoB,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,MAAM,IAAI,IAC9E,OAAO,MAAM;IAIf,OAAO,cAAc,CAAC,CAAC,YAAY,MAAM,QAAQ;GACnD;GAEA,IAAI,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,MAAM,IAAI,GAAG,OAAO,MAAM;GAG/D,cAAc,CAAC,CAAC,YAAY,CAAC,CAAC;GAE9B,OAAO,MAAM;EACf;EACA,aAAa;GACX,SAAS;EACX;EACA,OAAO;GACL,IAAI,WAAW,MAAM,cAAc,CAAC,CAAC,YAAY,CAAC,CAAC;EACrD;EACA,MAAM,OAAO;GACX,MAAM,SAAS,YAAY,CAAC,CAAC;EAC/B;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"snapshot-source.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/snapshot-source.ts"],"sourcesContent":["/**\n * Where the panel's routes get the snapshot: opened once with\n * `routes: \"cached\"` (a devtools request never boots the app) and kept in\n * memory. Concurrent requests share one open. A change stamp (the book\n * manifest plus the agent-written folders and indexes, a few `stat` calls and\n * no directory walk) tells when the book changed.\n *\n * - Production (`mode: \"production\"`): a snapshot is reused until the stamp\n * changes, with no time limit, unless `ttlMs` is set. A request that finds\n * the stamp changed waits for the new open. `warm()` opens the book ahead\n * of the first request.\n * - Development: the snapshot is reused for a short window (2 s, or five times\n * the last open when that is longer, so a slow open on a large app is not\n * repeated on every view; written files change while an agent works). A\n * request that finds the stamp changed waits for the new open. After the\n * window, with the stamp unchanged (a file edited in place), the cached\n * snapshot is served at once and one background open refreshes it (stale\n * while revalidate).\n *\n * An open that fails keeps serving the old snapshot; its error surfaces on a\n * request only when there is no snapshot at all. The panel passes\n * `write: true` in development, so the generated book stays current and the\n * next open is incremental; with `write: false` a stored book behind the\n * sources is rebuilt in memory on every open.\n */\nimport { stat } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport { GRIMOIRE_PATHS } from \"../paths\";\nimport { resolveResultsFile } from \"../test-results\";\nimport { openGrimoire } from \"../workspace\";\n\n/** Options of the panel's snapshot source. */\nexport type SnapshotSourceOptions = {\n /** The adapter, or a function that loads it. Default: the Warlock adapter, imported on first use. */\n adapter?: BookAdapter | (() => Promise<BookAdapter>);\n /**\n * How long a snapshot is reused when the book did not change (ms).\n * Default in development: 2000, or five times as long as the last open took\n * when that is longer. Default in production: no limit (reused until the\n * book changes).\n */\n ttlMs?: number;\n /** Where the source runs. `\"production\"` keeps a snapshot until the book changes. Default: `\"development\"`. */\n mode?: \"development\" | \"production\";\n /** Let `openGrimoire` write the generated book and collected files (never agent-written files). Default `false`; the devtools panel passes `true`. */\n write?: boolean;\n /**\n * Where the test results are read from (project-relative or absolute).\n * Default `grimoire/book/test-results.json`. The file's modified time is part\n * of the change stamp, so results written after the snapshot opened show up\n * without a restart.\n */\n testResultsFile?: string;\n /**\n * Read the route facts once when the first open finds none (`routes: \"missing\"`), so the development tab is\n * never \"missing\" without a manual `warlock grimoire build`. The adapter's booted inspect runs at most once per\n * process; a boot that fails keeps the cached answer. Default `false`. Never set it in a process that serves the app: the boot\n * pass boots every connector and re-imports the route and event modules, which registers them twice. The devtools panel\n * does not set it; use it from a separate tool process.\n */\n collectRoutes?: boolean;\n};\n\n/** A cached, shared snapshot of one project. */\nexport type SnapshotSource = {\n get(): Promise<GrimoireSnapshot>;\n /** Forget the cached snapshot; the next `get()` opens again. */\n invalidate(): void;\n /** Start opening the book now, so the first `get()` is fast. Failures are ignored here and surface on `get()`. */\n warm(): void;\n /** Resolves when no open is running (specs and shutdown). Never rejects. */\n idle(): Promise<void>;\n};\n\n/** Files and folders whose modified time moves when the book or an agent-written file is added, removed or regenerated. */\nconst STAMPED = [\n GRIMOIRE_PATHS.bookManifest,\n GRIMOIRE_PATHS.featuresIndex,\n GRIMOIRE_PATHS.tasksIndex,\n GRIMOIRE_PATHS.features,\n GRIMOIRE_PATHS.apps,\n GRIMOIRE_PATHS.openTasks,\n GRIMOIRE_PATHS.doneTasks,\n GRIMOIRE_PATHS.releases,\n];\n\nasync function changeStamp(root: string, resultsFile: string): Promise<string> {\n const files = [...STAMPED.map((entry) => path.join(root, ...entry.split(\"/\"))), resultsFile];\n const times = await Promise.all(\n files.map(async (file) => {\n try {\n return (await stat(file)).mtimeMs;\n } catch {\n return 0;\n }\n }),\n );\n\n return times.join(\",\");\n}\n\nasync function loadAdapter(option: SnapshotSourceOptions[\"adapter\"]): Promise<BookAdapter> {\n if (option === undefined) {\n const { createWarlockAdapter } = await import(\"../warlock\");\n\n return createWarlockAdapter();\n }\n\n return typeof option === \"function\" ? option() : option;\n}\n\n/** Create the source for the project at `root`. */\nexport function createSnapshotSource(\n root: string,\n options: SnapshotSourceOptions = {},\n): SnapshotSource {\n let cached: { snapshot: GrimoireSnapshot; at: number; stamp: string; took: number } | null = null;\n let opening: Promise<GrimoireSnapshot> | null = null;\n\n let collected = options.collectRoutes !== true || options.mode === \"production\";\n const resultsFile = resolveResultsFile(root, options.testResultsFile);\n\n const keepUntilChanged = options.mode === \"production\" && options.ttlMs === undefined;\n const reuseFor = (took: number): number => options.ttlMs ?? Math.max(2000, took * 5);\n\n async function open(): Promise<GrimoireSnapshot> {\n const started = Date.now();\n const adapter = await loadAdapter(options.adapter);\n const openOptions = {\n write: options.write ?? false,\n ...(options.testResultsFile === undefined\n ? {}\n : { testResultsFile: options.testResultsFile }),\n };\n let snapshot = await openGrimoire(root, adapter, { routes: \"cached\", ...openOptions });\n\n if (!collected && snapshot.routes === \"missing\") {\n // Once per source: the route, event and job facts come from one boot pass, then live in the book.\n collected = true;\n\n try {\n snapshot = await openGrimoire(root, adapter, { routes: \"fresh\", ...openOptions });\n } catch {\n // The app did not boot (GR8002): keep the cached answer; the tab says the facts are missing.\n }\n }\n\n const at = Date.now();\n\n cached = { snapshot, at, stamp: await changeStamp(root, resultsFile), took: at - started };\n\n return snapshot;\n }\n\n /** The open in flight, or a new one; concurrent callers share it. */\n function ensureOpening(): Promise<GrimoireSnapshot> {\n opening ??= open().finally(() => {\n opening = null;\n });\n\n return opening;\n }\n\n return {\n async get() {\n if (cached === null) return ensureOpening();\n\n const known = cached;\n const changed = (await changeStamp(root, resultsFile)) !== known.stamp;\n\n if (changed || options.mode === \"production\") {\n if (!changed && (keepUntilChanged || Date.now() - known.at < reuseFor(known.took))) {\n return known.snapshot;\n }\n\n // A failed open keeps the old snapshot; the next request tries again.\n return ensureOpening().catch(() => known.snapshot);\n }\n\n if (Date.now() - known.at < reuseFor(known.took)) return known.snapshot;\n\n // Development, nothing known to have changed: serve the old snapshot now and refresh behind it.\n ensureOpening().catch(() => {});\n\n return known.snapshot;\n },\n invalidate() {\n cached = null;\n },\n warm() {\n if (cached === null) ensureOpening().catch(() => {});\n },\n async idle() {\n await opening?.catch(() => {});\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EA,MAAM,UAAU;CACd,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;AACjB;AAEA,eAAe,YAAY,MAAc,aAAsC;CAC7E,MAAM,QAAQ,CAAC,GAAG,QAAQ,KAAK,UAAU,KAAK,KAAK,MAAM,GAAG,MAAM,MAAM,GAAG,CAAC,CAAC,GAAG,WAAW;CAW3F,QAAO,MAVa,QAAQ,IAC1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AGA,SAAS,gBAA2C;EAClD,YAAY,KAAK,CAAC,CAAC,cAAc;GAC/B,UAAU;EACZ,CAAC;EAED,OAAO;CACT;CAEA,OAAO;EACL,MAAM,MAAM;GACV,IAAI,WAAW,MAAM,OAAO,cAAc;GAE1C,MAAM,QAAQ;GACd,MAAM,UAAW,MAAM,YAAY,MAAM,WAAW,MAAO,MAAM;GAEjE,IAAI,WAAW,QAAQ,SAAS,cAAc;IAC5C,IAAI,CAAC,YAAY,oBAAoB,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,MAAM,IAAI,IAC9E,OAAO,MAAM;IAIf,OAAO,cAAc,CAAC,CAAC,YAAY,MAAM,QAAQ;GACnD;GAEA,IAAI,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,MAAM,IAAI,GAAG,OAAO,MAAM;GAG/D,cAAc,CAAC,CAAC,YAAY,CAAC,CAAC;GAE9B,OAAO,MAAM;EACf;EACA,aAAa;GACX,SAAS;EACX;EACA,OAAO;GACL,IAAI,WAAW,MAAM,cAAc,CAAC,CAAC,YAAY,CAAC,CAAC;EACrD;EACA,MAAM,OAAO;GACX,MAAM,SAAS,YAAY,CAAC,CAAC;EAC/B;CACF;AACF"}
|
package/esm/graph/index.d.mts
CHANGED
|
@@ -4,11 +4,20 @@ import { BookFile } from "../contracts/adapter.mjs";
|
|
|
4
4
|
export type FileGraph = ReadonlyMap<string, Pick<BookFile, "file" | "imports" | "importedBy">>;
|
|
5
5
|
/** Index files by path. */
|
|
6
6
|
export declare function fileGraph(files: readonly Pick<BookFile, "file" | "imports" | "importedBy">[]): FileGraph;
|
|
7
|
+
/** Options of {@link importClosure}. */
|
|
8
|
+
export type ImportClosureOptions = {
|
|
9
|
+
/**
|
|
10
|
+
* Leave out import edges marked `typeOnly` (erased at runtime), so a page
|
|
11
|
+
* that imports a type through a barrel does not reach the barrel's server
|
|
12
|
+
* files. Default `false`: every edge is followed.
|
|
13
|
+
*/
|
|
14
|
+
skipTypeOnly?: boolean;
|
|
15
|
+
};
|
|
7
16
|
/**
|
|
8
17
|
* The start files and every project file they import, transitively, sorted.
|
|
9
18
|
* Files not in the graph are left out. Cycles are walked once.
|
|
10
19
|
*/
|
|
11
|
-
export declare function importClosure(graph: FileGraph, start: readonly string[]): string[];
|
|
20
|
+
export declare function importClosure(graph: FileGraph, start: readonly string[], options?: ImportClosureOptions): string[];
|
|
12
21
|
/** The start files and every project file that imports them, transitively, sorted. */
|
|
13
22
|
export declare function importerClosure(graph: FileGraph, start: readonly string[]): string[];
|
|
14
23
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/graph/index.ts"],"mappings":";;;YAQY,YAAY,oBAAoB,KAAK;;wBAGjC,UACd,gBAAgB,KAAK,iDACpB
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/graph/index.ts"],"mappings":";;;YAQY,YAAY,oBAAoB,KAAK;;wBAGjC,UACd,gBAAgB,KAAK,iDACpB;;YAyBS;;;;;;EAMV;;;;;;wBAOc,cACd,OAAO,WACP,0BACA,UAAS;;wBAYK,gBAAgB,OAAO,WAAW"}
|
package/esm/graph/index.mjs
CHANGED
|
@@ -18,8 +18,9 @@ function walk(graph, start, next) {
|
|
|
18
18
|
* The start files and every project file they import, transitively, sorted.
|
|
19
19
|
* Files not in the graph are left out. Cycles are walked once.
|
|
20
20
|
*/
|
|
21
|
-
function importClosure(graph, start) {
|
|
22
|
-
|
|
21
|
+
function importClosure(graph, start, options = {}) {
|
|
22
|
+
const skipTypeOnly = options.skipTypeOnly === true;
|
|
23
|
+
return walk(graph, start, (file) => (graph.get(file)?.imports ?? []).flatMap((entry) => entry.file === null || skipTypeOnly && entry.typeOnly === true ? [] : [entry.file]));
|
|
23
24
|
}
|
|
24
25
|
/** The start files and every project file that imports them, transitively, sorted. */
|
|
25
26
|
function importerClosure(graph, start) {
|
package/esm/graph/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/graph/index.ts"],"sourcesContent":["/**\n * Walks over the import graph of the book's files. Shared by the book maps\n * (files behind a step), `scry --route` (files behind a handler) and\n * `scry --impact` (files that reach a file).\n */\nimport type { BookFile } from \"../contracts/adapter\";\n\n/** Files indexed by path, for the walks below. */\nexport type FileGraph = ReadonlyMap<string, Pick<BookFile, \"file\" | \"imports\" | \"importedBy\">>;\n\n/** Index files by path. */\nexport function fileGraph(\n files: readonly Pick<BookFile, \"file\" | \"imports\" | \"importedBy\">[],\n): FileGraph {\n return new Map(files.map((file) => [file.file, file]));\n}\n\nfunction walk(\n graph: FileGraph,\n start: readonly string[],\n next: (file: string) => string[],\n): string[] {\n const seen = new Set<string>();\n const pending = [...start];\n\n while (pending.length > 0) {\n const current = pending.pop();\n\n if (current === undefined || seen.has(current) || !graph.has(current)) continue;\n\n seen.add(current);\n pending.push(...next(current));\n }\n\n return [...seen].sort();\n}\n\n/**\n * The start files and every project file they import, transitively, sorted.\n * Files not in the graph are left out. Cycles are walked once.\n */\nexport function importClosure(graph: FileGraph
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/graph/index.ts"],"sourcesContent":["/**\n * Walks over the import graph of the book's files. Shared by the book maps\n * (files behind a step), `scry --route` (files behind a handler) and\n * `scry --impact` (files that reach a file).\n */\nimport type { BookFile } from \"../contracts/adapter\";\n\n/** Files indexed by path, for the walks below. */\nexport type FileGraph = ReadonlyMap<string, Pick<BookFile, \"file\" | \"imports\" | \"importedBy\">>;\n\n/** Index files by path. */\nexport function fileGraph(\n files: readonly Pick<BookFile, \"file\" | \"imports\" | \"importedBy\">[],\n): FileGraph {\n return new Map(files.map((file) => [file.file, file]));\n}\n\nfunction walk(\n graph: FileGraph,\n start: readonly string[],\n next: (file: string) => string[],\n): string[] {\n const seen = new Set<string>();\n const pending = [...start];\n\n while (pending.length > 0) {\n const current = pending.pop();\n\n if (current === undefined || seen.has(current) || !graph.has(current)) continue;\n\n seen.add(current);\n pending.push(...next(current));\n }\n\n return [...seen].sort();\n}\n\n/** Options of {@link importClosure}. */\nexport type ImportClosureOptions = {\n /**\n * Leave out import edges marked `typeOnly` (erased at runtime), so a page\n * that imports a type through a barrel does not reach the barrel's server\n * files. Default `false`: every edge is followed.\n */\n skipTypeOnly?: boolean;\n};\n\n/**\n * The start files and every project file they import, transitively, sorted.\n * Files not in the graph are left out. Cycles are walked once.\n */\nexport function importClosure(\n graph: FileGraph,\n start: readonly string[],\n options: ImportClosureOptions = {},\n): string[] {\n const skipTypeOnly = options.skipTypeOnly === true;\n\n return walk(graph, start, (file) =>\n (graph.get(file)?.imports ?? []).flatMap((entry) =>\n entry.file === null || (skipTypeOnly && entry.typeOnly === true) ? [] : [entry.file],\n ),\n );\n}\n\n/** The start files and every project file that imports them, transitively, sorted. */\nexport function importerClosure(graph: FileGraph, start: readonly string[]): string[] {\n return walk(graph, start, (file) => [...(graph.get(file)?.importedBy ?? [])]);\n}\n\n/**\n * The package name of a bare import specifier (`@warlock.js/core/tooling` →\n * `@warlock.js/core`, `dayjs/plugin/utc` → `dayjs`), or `null` for a relative\n * path, a `node:` builtin or an alias that starts with a path character.\n */\nexport function packageNameOf(specifier: string): string | null {\n if (specifier.startsWith(\".\") || specifier.startsWith(\"/\") || specifier.startsWith(\"node:\")) {\n return null;\n }\n\n const parts = specifier.split(\"/\");\n\n if (specifier.startsWith(\"@\")) {\n return parts.length >= 2 && parts[1] ? `${parts[0]}/${parts[1]}` : null;\n }\n\n return parts[0] || null;\n}\n"],"mappings":";;AAWA,SAAgB,UACd,OACW;CACX,OAAO,IAAI,IAAI,MAAM,KAAK,SAAS,CAAC,KAAK,MAAM,IAAI,CAAC,CAAC;AACvD;AAEA,SAAS,KACP,OACA,OACA,MACU;CACV,MAAM,uBAAO,IAAI,IAAY;CAC7B,MAAM,UAAU,CAAC,GAAG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