@warlock.js/grimoire 5.58.0 → 5.60.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 (71) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/esm/apps/check-apps.mjs +11 -5
  3. package/esm/apps/check-apps.mjs.map +1 -1
  4. package/esm/book/build.d.mts.map +1 -1
  5. package/esm/book/build.mjs.map +1 -1
  6. package/esm/bookmap/build.d.mts.map +1 -1
  7. package/esm/bookmap/build.mjs +5 -3
  8. package/esm/bookmap/build.mjs.map +1 -1
  9. package/esm/bookmap/steps.mjs +34 -3
  10. package/esm/bookmap/steps.mjs.map +1 -1
  11. package/esm/contracts/adapter.d.mts +22 -1
  12. package/esm/contracts/adapter.d.mts.map +1 -1
  13. package/esm/contracts/scry.d.mts +26 -6
  14. package/esm/contracts/scry.d.mts.map +1 -1
  15. package/esm/contracts/snapshot.d.mts +3 -1
  16. package/esm/contracts/snapshot.d.mts.map +1 -1
  17. package/esm/devtools/data.mjs +23 -3
  18. package/esm/devtools/data.mjs.map +1 -1
  19. package/esm/devtools/feature-map.mjs +149 -0
  20. package/esm/devtools/feature-map.mjs.map +1 -0
  21. package/esm/devtools/index.d.mts +2 -2
  22. package/esm/devtools/index.mjs +30 -9
  23. package/esm/devtools/index.mjs.map +1 -1
  24. package/esm/devtools/product-map.d.mts.map +1 -1
  25. package/esm/devtools/product-map.mjs +82 -7
  26. package/esm/devtools/product-map.mjs.map +1 -1
  27. package/esm/devtools/site.d.mts +43 -1
  28. package/esm/devtools/site.d.mts.map +1 -1
  29. package/esm/devtools/site.mjs +111 -15
  30. package/esm/devtools/site.mjs.map +1 -1
  31. package/esm/devtools/snapshot-source.mjs +15 -2
  32. package/esm/devtools/snapshot-source.mjs.map +1 -1
  33. package/esm/index.d.mts +3 -3
  34. package/esm/ownership/index.d.mts.map +1 -1
  35. package/esm/ownership/index.mjs +60 -1
  36. package/esm/ownership/index.mjs.map +1 -1
  37. package/esm/scry/compact.mjs +2 -1
  38. package/esm/scry/compact.mjs.map +1 -1
  39. package/esm/scry/format.d.mts.map +1 -1
  40. package/esm/scry/format.mjs +12 -1
  41. package/esm/scry/format.mjs.map +1 -1
  42. package/esm/scry/query.d.mts.map +1 -1
  43. package/esm/scry/query.mjs +147 -23
  44. package/esm/scry/query.mjs.map +1 -1
  45. package/esm/test-results/index.d.mts.map +1 -1
  46. package/esm/test-results/index.mjs.map +1 -1
  47. package/esm/warlock/actions.mjs +15 -7
  48. package/esm/warlock/actions.mjs.map +1 -1
  49. package/esm/warlock/adapter.d.mts.map +1 -1
  50. package/esm/warlock/adapter.mjs +36 -2
  51. package/esm/warlock/adapter.mjs.map +1 -1
  52. package/esm/warlock/commands.mjs +7 -2
  53. package/esm/warlock/commands.mjs.map +1 -1
  54. package/esm/warlock/logo.mjs +12 -0
  55. package/esm/warlock/logo.mjs.map +1 -0
  56. package/esm/warlock/mcp-tools.mjs +6 -6
  57. package/esm/warlock/mcp-tools.mjs.map +1 -1
  58. package/esm/workspace/cache.mjs +194 -0
  59. package/esm/workspace/cache.mjs.map +1 -0
  60. package/esm/workspace/index.d.mts.map +1 -1
  61. package/esm/workspace/index.mjs +3 -1
  62. package/esm/workspace/index.mjs.map +1 -1
  63. package/llms-full.txt +32 -9
  64. package/package.json +3 -3
  65. package/skills/record-a-change/SKILL.md +2 -0
  66. package/skills/use-the-grimoire/SKILL.md +30 -9
  67. package/ui/grimoire-static.js +57 -6
  68. package/ui/grimoire-view.js +1289 -310
  69. package/ui/grimoire.css +583 -2
  70. package/ui/product-map.css +157 -8
  71. package/ui/product-map.js +507 -59
@@ -151,6 +151,19 @@ function link(ctx, text, target, attrs = {}) {
151
151
  return ctx.el("a", { href: ctx.href(target), text, ...attrs });
152
152
  }
153
153
 
154
+ /** The words for the state of the route facts, shared by Overview and Check. */
155
+ function routeFactsState(state) {
156
+ const value = state ?? "cached";
157
+ const sub = {
158
+ fresh: "read from the running app",
159
+ cached: "from the last build",
160
+ stale: "older than the code. Run warlock grimoire build to refresh them",
161
+ missing: "none yet: route, mail and notification steps are not checked",
162
+ };
163
+
164
+ return { value, sub: sub[value] ?? "", stale: value === "stale" || value === "missing" };
165
+ }
166
+
154
167
  /** The tone (`good`, `info`, `warn`, `bad`, or none) a status word is shown in. */
155
168
  function toneOf(status) {
156
169
  switch (status) {
@@ -197,6 +210,88 @@ function muted(ctx, text) {
197
210
  return ctx.el("span", { class: "grimoire-muted", text });
198
211
  }
199
212
 
213
+ /** "Warlock.js v5.58.0" with the framework logo, from the adapter's host; nothing when the adapter reports none. */
214
+ function grimoireBrand(ctx, host) {
215
+ if (!host || !host.name) return null;
216
+
217
+ return ctx.el("div", { class: "grimoire-brand" }, [
218
+ host.logo
219
+ ? ctx.el("img", {
220
+ class: "grimoire-brand-logo",
221
+ src: host.logo,
222
+ alt: "",
223
+ width: "24",
224
+ height: "24",
225
+ })
226
+ : "",
227
+ ctx.el("span", { class: "grimoire-brand-name", text: host.name }),
228
+ host.version
229
+ ? ctx.el("span", { class: "grimoire-brand-version", text: `v${host.version}` })
230
+ : "",
231
+ ]);
232
+ }
233
+
234
+ /** The app's own name and version ("shop 1.4.0") for the bottom of the view; `null` when unknown. */
235
+ function grimoireAppLine(ctx, host) {
236
+ const app = host && host.app;
237
+
238
+ if (!app || !app.name) return null;
239
+
240
+ return ctx.el("p", { class: "grimoire-appline" }, [
241
+ ctx.el("span", { class: "grimoire-muted", text: "App " }),
242
+ ctx.el("span", {
243
+ class: "grimoire-mono",
244
+ text: app.version ? `${app.name} ${app.version}` : app.name,
245
+ }),
246
+ ]);
247
+ }
248
+
249
+ /** One flow card: the heading as the title, the id under it, the status, and the counts that are known. */
250
+ function grimoireFlowCard(ctx, feature, flow) {
251
+ const { el } = ctx;
252
+ const count = (value, one, many = `${one}s`) =>
253
+ typeof value === "number" ? `${value} ${value === 1 ? one : many}` : null;
254
+ const metrics = [
255
+ count(flow.steps, "step"),
256
+ count(flow.cases, "case"),
257
+ typeof flow.criteria === "number"
258
+ ? typeof flow.tested === "number"
259
+ ? `${flow.tested}/${flow.criteria} criteria tested`
260
+ : count(flow.criteria, "criterion", "criteria")
261
+ : null,
262
+ ].filter(Boolean);
263
+ const findings = typeof flow.findings === "number" ? flow.findings : 0;
264
+
265
+ return el("li", { class: "grimoire-flowcard" }, [
266
+ el("div", { class: "grimoire-flowcard-top" }, [
267
+ pill(ctx, flow.status, toneOf(flow.status)),
268
+ el("span", { class: "grimoire-muted", text: `since ${flow.since}` }),
269
+ ]),
270
+ el("h4", { class: "grimoire-flowcard-title" }, [
271
+ link(
272
+ ctx,
273
+ flow.heading ?? flow.id,
274
+ `flow/${encodeURIComponent(feature)}/${encodeURIComponent(flow.id)}`,
275
+ { class: "grimoire-flowcard-link" },
276
+ ),
277
+ ]),
278
+ flow.heading ? el("span", { class: "grimoire-mono grimoire-muted", text: flow.id }) : "",
279
+ metrics.length
280
+ ? el(
281
+ "ul",
282
+ { class: "grimoire-flowcard-metrics" },
283
+ metrics.map((text) => el("li", { text })),
284
+ )
285
+ : "",
286
+ findings > 0
287
+ ? el("span", {
288
+ class: "grimoire-pill is-warn grimoire-flowcard-findings",
289
+ text: `${findings} ${findings === 1 ? "finding" : "findings"}`,
290
+ })
291
+ : "",
292
+ ]);
293
+ }
294
+
200
295
  function list(ctx, items) {
201
296
  return ctx.el(
202
297
  "ul",
@@ -223,9 +318,7 @@ function table(ctx, headings, rows) {
223
318
  ctx.el(
224
319
  "tr",
225
320
  {},
226
- row.map((cell, column) =>
227
- ctx.el("td", { "data-label": headings[column] ?? "" }, cell),
228
- ),
321
+ row.map((cell, column) => ctx.el("td", { "data-label": headings[column] ?? "" }, cell)),
229
322
  ),
230
323
  ),
231
324
  ),
@@ -421,20 +514,34 @@ function copyText(text, node, done) {
421
514
  }
422
515
 
423
516
  const STEP_ICONS = {
424
- page: [["rect", { x: "3", y: "4", width: "18", height: "14", rx: "2" }], ["path", { d: "M3 9h18" }]],
517
+ page: [
518
+ ["rect", { x: "3", y: "4", width: "18", height: "14", rx: "2" }],
519
+ ["path", { d: "M3 9h18" }],
520
+ ],
425
521
  route: [["path", { d: "M5 12h14M13 6l6 6-6 6" }]],
426
- mail: [["rect", { x: "3", y: "5", width: "18", height: "14", rx: "2" }], ["path", { d: "M3 7l9 6 9-6" }]],
522
+ mail: [
523
+ ["rect", { x: "3", y: "5", width: "18", height: "14", rx: "2" }],
524
+ ["path", { d: "M3 7l9 6 9-6" }],
525
+ ],
427
526
  notification: [["path", { d: "M6 16v-5a6 6 0 0 1 12 0v5l2 2H4zM10 21h4" }]],
428
- job: [["circle", { cx: "12", cy: "12", r: "9" }], ["path", { d: "M12 7v5l3 2" }]],
527
+ job: [
528
+ ["circle", { cx: "12", cy: "12", r: "9" }],
529
+ ["path", { d: "M12 7v5l3 2" }],
530
+ ],
429
531
  event: [["path", { d: "M13 2L4 14h7l-1 8 9-12h-7z" }]],
430
532
  "outside service": [["path", { d: "M7 18a4 4 0 0 1 0-8 5 5 0 0 1 9.6-1.2A4 4 0 0 1 17 18z" }]],
431
533
  affects: [
432
- ["path", { d: "M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1" }],
534
+ [
535
+ "path",
536
+ {
537
+ d: "M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1",
538
+ },
539
+ ],
433
540
  ],
434
541
  };
435
542
 
436
543
  /** A small icon for a flow step type. */
437
- function stepIcon(ctx, type) {
544
+ function stepIcon(ctx, type, size = 18) {
438
545
  const { svg } = ctx;
439
546
  const shapes = STEP_ICONS[type] ?? STEP_ICONS.route;
440
547
 
@@ -442,8 +549,8 @@ function stepIcon(ctx, type) {
442
549
  "svg",
443
550
  {
444
551
  viewBox: "0 0 24 24",
445
- width: "18",
446
- height: "18",
552
+ width: String(size),
553
+ height: String(size),
447
554
  fill: "none",
448
555
  stroke: "currentColor",
449
556
  "stroke-width": "1.8",
@@ -657,15 +764,6 @@ function findingItem(ctx, finding, options = {}) {
657
764
  ]);
658
765
  }
659
766
 
660
- /** A list of findings: severity, code, message, what to do, and where. */
661
- function findingList(ctx, findings, options = {}) {
662
- return ctx.el(
663
- "ul",
664
- { class: "grimoire-findings" },
665
- findings.map((finding) => findingItem(ctx, finding, options)),
666
- );
667
- }
668
-
669
767
  function changesView(ctx, changes) {
670
768
  if (!changes.length) return ctx.empty("No changelog entries.");
671
769
  return list(
@@ -767,9 +865,11 @@ function graphView(ctx, graph, title) {
767
865
  const group = svg(
768
866
  "g",
769
867
  {},
770
- [svg("title", { text: node.label }), circle, labelled || node.type === "center" ? label : ""].filter(
771
- (child) => child !== "",
772
- ),
868
+ [
869
+ svg("title", { text: node.label }),
870
+ circle,
871
+ labelled || node.type === "center" ? label : "",
872
+ ].filter((child) => child !== ""),
773
873
  );
774
874
  canvas.append(target === null ? group : svg("a", { href: href(target) }, [group]));
775
875
  }
@@ -822,7 +922,8 @@ async function overviewView(ctx, summaryRequest) {
822
922
  .join(", ");
823
923
  const waiting = data.tasks.waiting.length;
824
924
  const open = data.tasks.open.length - waiting;
825
- const stale = data.routes === "stale" || data.routes === "missing";
925
+ const routeFacts = routeFactsState(data.routes);
926
+ const stale = routeFacts.stale;
826
927
  const out = el("div", { class: "grimoire-view" });
827
928
 
828
929
  out.append(
@@ -863,8 +964,8 @@ async function overviewView(ctx, summaryRequest) {
863
964
  }),
864
965
  stat(ctx, {
865
966
  label: "Route facts",
866
- value: data.routes,
867
- sub: stale ? "need a refresh" : "up to date",
967
+ value: routeFacts.value,
968
+ sub: routeFacts.sub,
868
969
  target: "check",
869
970
  tone: toneOf(data.routes),
870
971
  }),
@@ -875,7 +976,7 @@ async function overviewView(ctx, summaryRequest) {
875
976
  out.append(
876
977
  el("p", {
877
978
  class: "grimoire-note",
878
- text: "The route facts are old or missing. Run warlock grimoire build to refresh them.",
979
+ text: `Route facts: ${routeFacts.value}, ${routeFacts.sub}.`,
879
980
  }),
880
981
  );
881
982
  }
@@ -914,7 +1015,9 @@ async function overviewView(ctx, summaryRequest) {
914
1015
  problems.map((group) => [
915
1016
  pill(ctx, group.severity, toneOf(group.severity)),
916
1017
  " ",
917
- link(ctx, group.code, checkTarget({ code: group.code }), { class: "grimoire-mono" }),
1018
+ link(ctx, group.code, checkTarget({ code: group.code }), {
1019
+ class: "grimoire-mono",
1020
+ }),
918
1021
  " ",
919
1022
  ...[codeText(ctx, group.title)].flat(),
920
1023
  " ",
@@ -1053,7 +1156,580 @@ async function featuresView(ctx) {
1053
1156
  ]);
1054
1157
  }
1055
1158
 
1056
- async function featureView(ctx, id) {
1159
+ // ── Tabs, groups and the feature map ────────────────────────────────────────
1160
+
1161
+ /** Move the address bar to `route` without reloading the view (the tab is already shown). */
1162
+ function rememberRoute(ctx, route) {
1163
+ try {
1164
+ globalThis.history?.replaceState?.(null, "", ctx.href(route));
1165
+ } catch {
1166
+ // A host that keeps its own history leaves the address as it is.
1167
+ }
1168
+ }
1169
+
1170
+ /**
1171
+ * Real tab buttons over lazily built panels. `tabs` is
1172
+ * `[{ id, label, count?, make }]`; `make()` runs the first time a tab opens, so
1173
+ * a long list in a closed tab costs nothing. `route(id)` is the hash route the
1174
+ * tab owns; the first tab is the default.
1175
+ */
1176
+ function tabbed(ctx, { tabs, active, label, prefix, route }) {
1177
+ const { el } = ctx;
1178
+ const strip = el("div", { class: "grimoire-pagetabs", role: "tablist", "aria-label": label });
1179
+ const panel = el("div", { class: "grimoire-tabpanel", role: "tabpanel", tabindex: "0" });
1180
+ const buttons = new Map();
1181
+ const built = new Map();
1182
+
1183
+ function show(id, user) {
1184
+ const tab = tabs.find((item) => item.id === id) ?? tabs[0];
1185
+
1186
+ for (const [key, button] of buttons) {
1187
+ const on = key === tab.id;
1188
+
1189
+ button.setAttribute("aria-selected", String(on));
1190
+ button.setAttribute("tabindex", on ? "0" : "-1");
1191
+ button.setAttribute("class", on ? "grimoire-pagetab is-active" : "grimoire-pagetab");
1192
+ }
1193
+
1194
+ if (!built.has(tab.id)) built.set(tab.id, tab.make());
1195
+
1196
+ panel.setAttribute("aria-labelledby", `${prefix}-tab-${tab.id}`);
1197
+ panel.replaceChildren(built.get(tab.id));
1198
+ if (user) rememberRoute(ctx, route(tab.id));
1199
+ }
1200
+
1201
+ function move(from, step) {
1202
+ const next = tabs[(from + step + tabs.length) % tabs.length];
1203
+
1204
+ show(next.id, true);
1205
+ buttons.get(next.id)?.focus?.();
1206
+ }
1207
+
1208
+ tabs.forEach((tab, index) => {
1209
+ const button = el(
1210
+ "button",
1211
+ {
1212
+ type: "button",
1213
+ role: "tab",
1214
+ id: `${prefix}-tab-${tab.id}`,
1215
+ class: "grimoire-pagetab",
1216
+ "aria-selected": "false",
1217
+ "aria-controls": `${prefix}-panel`,
1218
+ tabindex: "-1",
1219
+ onclick: () => show(tab.id, true),
1220
+ onkeydown: (event) => {
1221
+ const keys = {
1222
+ ArrowRight: () => move(index, 1),
1223
+ ArrowLeft: () => move(index, -1),
1224
+ Home: () => move(0, 0),
1225
+ End: () => move(tabs.length - 1, 0),
1226
+ };
1227
+ const act = keys[event.key];
1228
+
1229
+ if (!act) return;
1230
+ event.preventDefault?.();
1231
+ act();
1232
+ },
1233
+ },
1234
+ [
1235
+ tab.label,
1236
+ typeof tab.count === "number"
1237
+ ? el("span", { class: "grimoire-tab-count", text: String(tab.count) })
1238
+ : "",
1239
+ ],
1240
+ );
1241
+
1242
+ buttons.set(tab.id, button);
1243
+ strip.append(button);
1244
+ });
1245
+
1246
+ panel.setAttribute("id", `${prefix}-panel`);
1247
+ show(active, false);
1248
+
1249
+ return el("div", { class: "grimoire-tabbed" }, [strip, panel]);
1250
+ }
1251
+
1252
+ /**
1253
+ * A group that is closed until opened. `make()` builds the body on the first
1254
+ * open, so a closed group costs one row.
1255
+ */
1256
+ function group(ctx, { title, count, tone = "", lead = [], make, open = false, className = "" }) {
1257
+ const { el } = ctx;
1258
+ const body = el("div", { class: "grimoire-group-body" });
1259
+ let built = false;
1260
+ let isOpen = false;
1261
+ const button = el(
1262
+ "button",
1263
+ {
1264
+ type: "button",
1265
+ class: "grimoire-group-head",
1266
+ "aria-expanded": "false",
1267
+ onclick: () => toggle(!isOpen),
1268
+ },
1269
+ [
1270
+ el("span", { class: "grimoire-group-caret", "aria-hidden": "true", text: "▸" }),
1271
+ ...lead,
1272
+ el("span", { class: "grimoire-group-title", text: title }),
1273
+ typeof count === "number"
1274
+ ? el("span", { class: "grimoire-tab-count", text: String(count) })
1275
+ : "",
1276
+ ],
1277
+ );
1278
+
1279
+ function toggle(next) {
1280
+ isOpen = next;
1281
+
1282
+ if (isOpen && !built) {
1283
+ built = true;
1284
+ body.append(make());
1285
+ }
1286
+
1287
+ button.setAttribute("aria-expanded", String(isOpen));
1288
+ body.setAttribute("class", isOpen ? "grimoire-group-body is-open" : "grimoire-group-body");
1289
+ }
1290
+
1291
+ const node = el(
1292
+ "div",
1293
+ { class: `grimoire-group ${tone ? `is-${tone}` : ""} ${className}`.trim() },
1294
+ [button, body],
1295
+ );
1296
+
1297
+ node.toggle = toggle;
1298
+ if (open) toggle(true);
1299
+
1300
+ return node;
1301
+ }
1302
+
1303
+ /** A long list shown a slice at a time: `make(item)` builds one row; "Show more" adds the next slice. */
1304
+ function slicedList(ctx, items, make, options = {}) {
1305
+ const { el } = ctx;
1306
+ const size = options.size ?? 30;
1307
+ const tag = options.tag ?? "ul";
1308
+ const list = el(tag, { class: options.className ?? "grimoire-list" });
1309
+ const more = el("button", { type: "button", class: "grimoire-more" });
1310
+ const holder = el("div", {}, [list, more]);
1311
+ let shown = 0;
1312
+
1313
+ function paint() {
1314
+ const next = items.slice(shown, shown + size);
1315
+
1316
+ for (const item of next) list.append(make(item));
1317
+ shown += next.length;
1318
+ more.textContent = `Show ${Math.min(size, items.length - shown)} more (${items.length - shown} left)`;
1319
+ more.setAttribute("class", shown >= items.length ? "grimoire-more is-hidden" : "grimoire-more");
1320
+ more.setAttribute("aria-hidden", String(shown >= items.length));
1321
+ }
1322
+
1323
+ more.addEventListener("click", paint);
1324
+ paint();
1325
+ return holder;
1326
+ }
1327
+
1328
+ /** What a feature-map chip leads to: the written page, the route, or the entry file. */
1329
+ function mapChipTarget(chip) {
1330
+ if (chip.type === "page" && chip.app && chip.page) {
1331
+ return `page/${encodeURIComponent(chip.app)}/${encodeURIComponent(chip.page)}`;
1332
+ }
1333
+ if (chip.type === "route" && chip.method && chip.path) {
1334
+ return `route/${encodeURIComponent(chip.method)}/${encodeURIComponent(chip.path)}`;
1335
+ }
1336
+ return chip.file ? `file/${encodeURIComponent(chip.file)}` : null;
1337
+ }
1338
+
1339
+ /** One chip of the feature map: a glyph and the name; a dashed look when the step matched nothing. */
1340
+ function mapChip(ctx, chip) {
1341
+ const target = mapChipTarget(chip);
1342
+ const missing = chip.found === false;
1343
+ const attrs = {
1344
+ class: `grimoire-mapchip is-${chip.type.replace(/\s+/g, "-")}${missing ? " is-missing" : ""}`,
1345
+ title: `${chip.type}, step ${chip.step}${missing ? ", not found in the book" : ""}: ${chip.label}`,
1346
+ };
1347
+ const inner = [
1348
+ stepIcon(ctx, chip.type, 14),
1349
+ ctx.el("span", { class: "grimoire-mapchip-label", text: chip.label }),
1350
+ ];
1351
+
1352
+ return target
1353
+ ? ctx.el("a", { ...attrs, href: ctx.href(target) }, inner)
1354
+ : ctx.el("span", attrs, inner);
1355
+ }
1356
+
1357
+ /** The feature map: flows as rows, the places they run as columns. */
1358
+ function featureMapView(ctx, feature, map) {
1359
+ const { el } = ctx;
1360
+
1361
+ if (!map)
1362
+ return ctx.empty("This answer has no feature map. Update the Grimoire package and reload.");
1363
+ if (!map.rows.length) return ctx.empty("This feature has no flows yet.");
1364
+ if (!map.columns.length) {
1365
+ return ctx.empty(
1366
+ "No step of any flow resolves to a page, screen, route or background job yet.",
1367
+ );
1368
+ }
1369
+
1370
+ return el("div", { class: "grimoire-scroll grimoire-featuremap" }, [
1371
+ el("table", { class: "grimoire-table grimoire-mapgrid" }, [
1372
+ el("caption", { class: "grimoire-sr", text: "Flows and the places they run" }),
1373
+ el("thead", {}, [
1374
+ el("tr", {}, [
1375
+ el("th", { scope: "col", text: "Flow" }),
1376
+ ...map.columns.map((column) =>
1377
+ el("th", { scope: "col", class: `is-${column.type}` }, [
1378
+ el("span", {
1379
+ class: "grimoire-maptype",
1380
+ text:
1381
+ column.type === "site" ? "site" : column.type === "mobile" ? "mobile app" : "",
1382
+ }),
1383
+ el("span", { text: column.title }),
1384
+ ]),
1385
+ ),
1386
+ ]),
1387
+ ]),
1388
+ el(
1389
+ "tbody",
1390
+ {},
1391
+ map.rows.map((row) =>
1392
+ el("tr", {}, [
1393
+ el("th", { scope: "row", class: "grimoire-maprow" }, [
1394
+ link(
1395
+ ctx,
1396
+ row.heading ?? row.flow,
1397
+ `flow/${encodeURIComponent(feature)}/${encodeURIComponent(row.flow)}`,
1398
+ ),
1399
+ row.heading
1400
+ ? el("span", { class: "grimoire-mono grimoire-muted", text: row.flow })
1401
+ : "",
1402
+ ]),
1403
+ ...map.columns.map((column) => {
1404
+ const chips = row.cells[column.id] ?? [];
1405
+
1406
+ return el(
1407
+ "td",
1408
+ { "data-label": column.title, class: chips.length ? "" : "is-empty" },
1409
+ chips.length
1410
+ ? el(
1411
+ "div",
1412
+ { class: "grimoire-mapcell" },
1413
+ chips.map((chip) => mapChip(ctx, chip)),
1414
+ )
1415
+ : el("span", { class: "grimoire-muted", "aria-label": "none", text: "–" }),
1416
+ );
1417
+ }),
1418
+ ]),
1419
+ ),
1420
+ ),
1421
+ ]),
1422
+ ]);
1423
+ }
1424
+
1425
+ /** The criteria of a feature, counted from its proofs. */
1426
+ function featureCriteria(data) {
1427
+ const byStatus = {};
1428
+ let total = 0;
1429
+
1430
+ for (const item of data.proofs ?? []) {
1431
+ for (const criterion of item.criteria) {
1432
+ total += 1;
1433
+ byStatus[criterion.status] = (byStatus[criterion.status] ?? 0) + 1;
1434
+ }
1435
+ }
1436
+
1437
+ return {
1438
+ total,
1439
+ proven: byStatus.pass ?? 0,
1440
+ failing: byStatus.fail ?? 0,
1441
+ noTest: byStatus["no-test"] ?? 0,
1442
+ };
1443
+ }
1444
+
1445
+ /** The feature's health tiles. */
1446
+ function featureHealthStrip(ctx, id, data, unexpected) {
1447
+ const criteria = featureCriteria(data);
1448
+ const flows = data.flows;
1449
+ const shipped = flows.filter((flow) => flow.status === "shipped").length;
1450
+ const errors = unexpected.filter((finding) => finding.severity === "error").length;
1451
+
1452
+ return ctx.el("div", { class: "grimoire-stats grimoire-health" }, [
1453
+ tile(ctx, { label: "Flows", value: flows.length, sub: `${shipped} shipped` }),
1454
+ tile(ctx, {
1455
+ label: "Criteria proven",
1456
+ value: `${criteria.proven}/${criteria.total}`,
1457
+ sub: criteria.failing
1458
+ ? `${plural(criteria.failing, "criterion")} failing`
1459
+ : criteria.noTest
1460
+ ? `${criteria.noTest} without a test`
1461
+ : criteria.total
1462
+ ? "by passing tests"
1463
+ : "none written",
1464
+ tone: criteria.failing
1465
+ ? "bad"
1466
+ : criteria.total && criteria.proven === criteria.total
1467
+ ? "good"
1468
+ : criteria.total
1469
+ ? "warn"
1470
+ : "",
1471
+ }),
1472
+ stat(ctx, {
1473
+ label: "Findings",
1474
+ value: unexpected.length,
1475
+ sub: `${plural(errors, "error")}, ${plural(unexpected.length - errors, "warning")}`,
1476
+ target: checkTarget({ feature: id }),
1477
+ tone: errors ? "bad" : unexpected.length ? "warn" : "good",
1478
+ }),
1479
+ tile(ctx, {
1480
+ label: "Own files",
1481
+ value: data.bookmap.own.length,
1482
+ sub: `${data.bookmap.unreached.length} not reached by a flow`,
1483
+ }),
1484
+ ]);
1485
+ }
1486
+
1487
+ /** Findings grouped by code, each group closed; the check's titles come with the first open. */
1488
+ function findingGroups(ctx, findings, options = {}) {
1489
+ const { el } = ctx;
1490
+
1491
+ if (!findings.length) {
1492
+ return el("p", {}, [pill(ctx, "clean", "good"), " No findings."]);
1493
+ }
1494
+
1495
+ const byCode = new Map();
1496
+
1497
+ for (const finding of findings)
1498
+ byCode.set(finding.code, [...(byCode.get(finding.code) ?? []), finding]);
1499
+
1500
+ const titles = ctx.api("check/groups").then(
1501
+ (answer) => new Map((answer.groups ?? []).map((item) => [item.code, item.title])),
1502
+ () => new Map(),
1503
+ );
1504
+ const groups = [...byCode.entries()]
1505
+ .map(([code, items]) => ({
1506
+ code,
1507
+ items,
1508
+ severity: items.some((item) => item.severity === "error") ? "error" : "warning",
1509
+ }))
1510
+ .sort(
1511
+ (left, right) =>
1512
+ (left.severity === "error" ? 0 : 1) - (right.severity === "error" ? 0 : 1) ||
1513
+ right.items.length - left.items.length ||
1514
+ left.code.localeCompare(right.code),
1515
+ );
1516
+
1517
+ return el(
1518
+ "div",
1519
+ { class: "grimoire-groups" },
1520
+ groups.map((item) => {
1521
+ const title = el("span", { class: "grimoire-muted grimoire-group-note" });
1522
+
1523
+ titles.then((known) => {
1524
+ const text = known.get(item.code);
1525
+
1526
+ if (text) title.textContent = text;
1527
+ });
1528
+
1529
+ return group(ctx, {
1530
+ title: item.code,
1531
+ count: item.items.length,
1532
+ tone: toneOf(item.severity),
1533
+ lead: [pill(ctx, item.severity, toneOf(item.severity))],
1534
+ make: () =>
1535
+ el("div", {}, [
1536
+ title,
1537
+ slicedList(ctx, item.items, (finding) => findingItem(ctx, finding, options), {
1538
+ className: "grimoire-findings",
1539
+ size: 25,
1540
+ }),
1541
+ ]),
1542
+ });
1543
+ }),
1544
+ );
1545
+ }
1546
+
1547
+ /** Files grouped by module with a filter box; each group is closed and built when opened. */
1548
+ function fileGroupsView(ctx, groups, extras) {
1549
+ const { el } = ctx;
1550
+ const holder = el("div", { class: "grimoire-groups" });
1551
+ const status = el("p", { class: "grimoire-muted", role: "status", "aria-live": "polite" });
1552
+ const input = el("input", {
1553
+ type: "search",
1554
+ class: "grimoire-filterbox",
1555
+ placeholder: "Filter files and modules",
1556
+ "aria-label": "Filter files",
1557
+ oninput: (event) => paint(String(event.target.value ?? "")),
1558
+ });
1559
+
1560
+ function paint(text) {
1561
+ const needle = text.trim().toLowerCase();
1562
+ let files = 0;
1563
+ let shown = 0;
1564
+ const nodes = [];
1565
+
1566
+ for (const item of groups) {
1567
+ const matches = needle
1568
+ ? item.module.toLowerCase().includes(needle)
1569
+ ? item.files
1570
+ : item.files.filter((file) => file.toLowerCase().includes(needle))
1571
+ : item.files;
1572
+
1573
+ files += item.files.length;
1574
+ if (!matches.length) continue;
1575
+
1576
+ shown += matches.length;
1577
+ nodes.push(
1578
+ group(ctx, {
1579
+ title: item.module || "(no module)",
1580
+ count: matches.length,
1581
+ open: needle !== "" && matches.length <= 40,
1582
+ make: () =>
1583
+ el(
1584
+ "div",
1585
+ { class: "grimoire-chips" },
1586
+ matches.map((file) => fileLink(ctx, file)),
1587
+ ),
1588
+ }),
1589
+ );
1590
+ }
1591
+
1592
+ status.textContent = needle
1593
+ ? `${shown} of ${files} files match`
1594
+ : `${plural(files, "file")} in ${plural(groups.length, "module")}`;
1595
+ holder.replaceChildren(...(needle ? [] : extras), ...nodes);
1596
+ }
1597
+
1598
+ paint("");
1599
+ return el("div", {}, [el("div", { class: "grimoire-toolbar" }, [input, status]), holder]);
1600
+ }
1601
+
1602
+ /** The extra groups of the Files tab: routes, pages and screens, borrowed files, files no flow reaches. */
1603
+ function featureCodeGroups(ctx, map) {
1604
+ const { el } = ctx;
1605
+ const pages = Object.entries(map.pages).flatMap(([app, items]) =>
1606
+ items.map((item) => ({ app, ...item })),
1607
+ );
1608
+
1609
+ return [
1610
+ map.routes.length
1611
+ ? group(ctx, {
1612
+ title: "Routes",
1613
+ count: map.routes.length,
1614
+ make: () =>
1615
+ slicedList(ctx, map.routes, (item) =>
1616
+ el("li", {}, [
1617
+ routeLink(ctx, item.method, item.path),
1618
+ " in ",
1619
+ fileLink(ctx, item.file),
1620
+ ]),
1621
+ ),
1622
+ })
1623
+ : "",
1624
+ pages.length
1625
+ ? group(ctx, {
1626
+ title: "Pages and screens",
1627
+ count: pages.length,
1628
+ make: () =>
1629
+ slicedList(ctx, pages, (item) =>
1630
+ el("li", {}, [
1631
+ link(
1632
+ ctx,
1633
+ `${item.app} ${item.route}`,
1634
+ `page/${encodeURIComponent(item.app)}/${encodeURIComponent(item.route)}`,
1635
+ ),
1636
+ ]),
1637
+ ),
1638
+ })
1639
+ : "",
1640
+ map.borrowed.length
1641
+ ? group(ctx, {
1642
+ title: "Borrowed from other features",
1643
+ count: map.borrowed.length,
1644
+ make: () =>
1645
+ el(
1646
+ "div",
1647
+ { class: "grimoire-chips" },
1648
+ map.borrowed.map((item) => fileLink(ctx, item.file)),
1649
+ ),
1650
+ })
1651
+ : "",
1652
+ map.unreached.length
1653
+ ? group(ctx, {
1654
+ title: "Not reached by a flow",
1655
+ count: map.unreached.length,
1656
+ tone: "warn",
1657
+ make: () =>
1658
+ el(
1659
+ "div",
1660
+ { class: "grimoire-chips" },
1661
+ map.unreached.map((file) => fileLink(ctx, file)),
1662
+ ),
1663
+ })
1664
+ : "",
1665
+ ];
1666
+ }
1667
+
1668
+ /** The criteria of each flow with the tests behind them. */
1669
+ function testsView(ctx, feature, proofs) {
1670
+ const { el } = ctx;
1671
+ const filled = proofs.filter((item) => item.criteria.length);
1672
+
1673
+ if (!filled.length) return ctx.empty("No flow of this feature has acceptance criteria yet.");
1674
+
1675
+ return el(
1676
+ "div",
1677
+ { class: "grimoire-groups" },
1678
+ filled.map((item) => {
1679
+ const proven = item.criteria.filter((criterion) => criterion.status === "pass").length;
1680
+ const failing = item.criteria.some((criterion) => criterion.status === "fail");
1681
+
1682
+ return group(ctx, {
1683
+ title: item.heading ?? item.flow,
1684
+ count: item.criteria.length,
1685
+ tone: failing ? "bad" : proven === item.criteria.length ? "good" : "warn",
1686
+ lead: [muted(ctx, `${proven}/${item.criteria.length} proven`)],
1687
+ make: () =>
1688
+ el("div", {}, [
1689
+ el("p", {}, [
1690
+ link(
1691
+ ctx,
1692
+ "Open the flow",
1693
+ `flow/${encodeURIComponent(feature)}/${encodeURIComponent(item.flow)}/proof`,
1694
+ ),
1695
+ ]),
1696
+ el(
1697
+ "ul",
1698
+ { class: "grimoire-proofs" },
1699
+ item.criteria.map((criterion) => proofRow(ctx, criterion, false)),
1700
+ ),
1701
+ ]),
1702
+ });
1703
+ }),
1704
+ );
1705
+ }
1706
+
1707
+ /** The Flows tab: one row per flow with its counts. */
1708
+ function flowsTable(ctx, feature, flows) {
1709
+ if (!flows.length) return ctx.empty("This feature has no flows yet.");
1710
+
1711
+ return table(
1712
+ ctx,
1713
+ ["Flow", "Status", "Steps", "Cases", "Criteria tested", "Findings"],
1714
+ flows.map((flow) => [
1715
+ [
1716
+ link(
1717
+ ctx,
1718
+ flow.heading ?? flow.id,
1719
+ `flow/${encodeURIComponent(feature)}/${encodeURIComponent(flow.id)}`,
1720
+ ),
1721
+ flow.heading ? [" ", mono(ctx, flow.id)] : "",
1722
+ ],
1723
+ [pill(ctx, flow.status, toneOf(flow.status))],
1724
+ [String(flow.steps)],
1725
+ [String(flow.cases)],
1726
+ [`${flow.tested}/${flow.criteria}`],
1727
+ [flow.findings ? pill(ctx, String(flow.findings), "warn") : muted(ctx, "0")],
1728
+ ]),
1729
+ );
1730
+ }
1731
+
1732
+ async function featureView(ctx, id, tab = "") {
1057
1733
  const [data, graph] = await Promise.all([
1058
1734
  ctx.api(`features/${encodeURIComponent(id)}`),
1059
1735
  ctx.api(`graph/feature/${encodeURIComponent(id)}`).catch(() => null),
@@ -1061,10 +1737,15 @@ async function featureView(ctx, id) {
1061
1737
  const { el } = ctx;
1062
1738
  const readme = data.readme;
1063
1739
  const status = plain(readme.status);
1740
+ const featureId = String(plain(readme.id));
1741
+ const unexpected = data.findings.filter((finding) => !finding.expected);
1742
+ const criteria = featureCriteria(data);
1743
+ const base = `feature/${encodeURIComponent(id)}`;
1744
+ const map = data.bookmap;
1064
1745
  const out = el("div", { class: "grimoire-view" }, [
1065
- crumbs(ctx, [["Features", "features"], [String(plain(readme.id))]]),
1746
+ crumbs(ctx, [["Features", "features"], [featureId]]),
1066
1747
  heading(ctx, plain(readme.title), [
1067
- mono(ctx, plain(readme.id)),
1748
+ mono(ctx, featureId),
1068
1749
  pill(ctx, status, toneOf(status)),
1069
1750
  pill(ctx, `version ${plain(readme.version)}`),
1070
1751
  readme.origin ? pill(ctx, plain(readme.origin), toneOf(plain(readme.origin))) : "",
@@ -1072,94 +1753,93 @@ async function featureView(ctx, id) {
1072
1753
  ]),
1073
1754
  ]);
1074
1755
 
1075
- if (readme.summary) out.append(el("p", { class: "grimoire-lede", text: readme.summary }));
1756
+ const overview = () => {
1757
+ const box = el("div", { class: "grimoire-tabstack" });
1076
1758
 
1077
- out.append(
1078
- section(ctx, "Flows", [
1079
- data.flows.length
1080
- ? table(
1081
- ctx,
1082
- ["Flow", "Status", "Since", "Heading"],
1083
- data.flows.map((flow) => [
1084
- [
1085
- link(
1086
- ctx,
1087
- flow.id,
1088
- `flow/${encodeURIComponent(plain(readme.id))}/${encodeURIComponent(flow.id)}`,
1089
- ),
1090
- ],
1091
- [pill(ctx, flow.status, toneOf(flow.status))],
1092
- [flow.since],
1093
- [flow.heading ?? ""],
1094
- ]),
1095
- )
1096
- : ctx.empty("This feature has no flows yet."),
1097
- ]),
1098
- );
1759
+ if (readme.summary) box.append(el("p", { class: "grimoire-lede", text: readme.summary }));
1099
1760
 
1100
- const map = data.bookmap;
1101
- out.append(
1102
- section(ctx, "Code", [
1103
- facts(ctx, [
1104
- ["Own files", String(map.own.length)],
1105
- ["Borrowed", String(map.borrowed.length)],
1106
- ["Routes", String(map.routes.length)],
1107
- ["Not reached by a flow", String(map.unreached.length)],
1761
+ box.append(featureHealthStrip(ctx, featureId, data, unexpected));
1762
+ box.append(section(ctx, "Feature map", [featureMapView(ctx, featureId, data.map)]));
1763
+ box.append(
1764
+ section(ctx, "Flows", [
1765
+ data.flows.length
1766
+ ? el(
1767
+ "ul",
1768
+ { class: "grimoire-flowcards" },
1769
+ data.flows.map((flow) => grimoireFlowCard(ctx, featureId, flow)),
1770
+ )
1771
+ : ctx.empty("This feature has no flows yet."),
1108
1772
  ]),
1109
- el("h4", { text: "Routes" }),
1110
- map.routes.length
1111
- ? list(
1773
+ );
1774
+
1775
+ if (graph) box.append(graphView(ctx, graph, "The feature and its neighbours"));
1776
+
1777
+ if (data.tasks.length) {
1778
+ box.append(
1779
+ section(ctx, "Open tasks", [
1780
+ list(
1112
1781
  ctx,
1113
- map.routes.map((item) => [
1114
- routeLink(ctx, item.method, item.path),
1115
- " in ",
1116
- fileLink(ctx, item.file),
1782
+ data.tasks.map((task) => [
1783
+ link(ctx, task.id, `task/${encodeURIComponent(task.id)}`, {
1784
+ class: "grimoire-nowrap",
1785
+ }),
1786
+ " ",
1787
+ codeText(ctx, task.title),
1788
+ " ",
1789
+ pill(ctx, task.status, toneOf(task.status)),
1117
1790
  ]),
1118
- )
1119
- : muted(ctx, "none"),
1120
- el("h4", { text: "Pages and screens" }),
1121
- Object.keys(map.pages).length
1122
- ? list(
1123
- ctx,
1124
- Object.entries(map.pages).flatMap(([app, pages]) =>
1125
- pages.map((item) => [
1126
- link(
1127
- ctx,
1128
- `${app} ${item.route}`,
1129
- `page/${encodeURIComponent(app)}/${encodeURIComponent(item.route)}`,
1130
- ),
1131
- ]),
1132
- ),
1133
- )
1134
- : muted(ctx, "none"),
1135
- el("h4", { text: "Own files" }),
1136
- fileChips(ctx, map.own, 12),
1137
- el("h4", { text: "Files no flow reaches" }),
1138
- fileChips(ctx, map.unreached, 12),
1139
- ]),
1140
- );
1791
+ ),
1792
+ ]),
1793
+ );
1794
+ }
1141
1795
 
1142
- if (data.tasks.length) {
1143
- out.append(
1144
- section(ctx, "Open tasks", [
1145
- list(
1146
- ctx,
1147
- data.tasks.map((task) => [
1148
- link(ctx, task.id, `task/${encodeURIComponent(task.id)}`, { class: "grimoire-nowrap" }),
1149
- " ",
1150
- codeText(ctx, task.title),
1151
- " ",
1152
- pill(ctx, task.status, toneOf(task.status)),
1153
- ]),
1154
- ),
1155
- ]),
1156
- );
1157
- }
1796
+ box.append(section(ctx, "Recent changes", [changesView(ctx, data.changes)]));
1797
+ return box;
1798
+ };
1158
1799
 
1159
- out.append(section(ctx, "Recent changes", [changesView(ctx, data.changes)]));
1800
+ out.append(
1801
+ tabbed(ctx, {
1802
+ label: "This feature",
1803
+ prefix: "grimoire-feature",
1804
+ active: tab,
1805
+ route: (key) => (key === "overview" ? base : `${base}/${key}`),
1806
+ tabs: [
1807
+ { id: "overview", label: "Overview", make: overview },
1808
+ {
1809
+ id: "flows",
1810
+ label: "Flows",
1811
+ count: data.flows.length,
1812
+ make: () => section(ctx, "Flows", [flowsTable(ctx, featureId, data.flows)]),
1813
+ },
1814
+ {
1815
+ id: "files",
1816
+ label: "Files",
1817
+ count: map.own.length,
1818
+ make: () =>
1819
+ section(ctx, "Files", [
1820
+ fileGroupsView(
1821
+ ctx,
1822
+ data.fileGroups ?? [{ module: "", files: map.own }],
1823
+ featureCodeGroups(ctx, map),
1824
+ ),
1825
+ ]),
1826
+ },
1827
+ {
1828
+ id: "findings",
1829
+ label: "Findings",
1830
+ count: unexpected.length,
1831
+ make: () => section(ctx, "Findings", [findingGroups(ctx, data.findings)]),
1832
+ },
1833
+ {
1834
+ id: "tests",
1835
+ label: "Tests",
1836
+ count: criteria.total,
1837
+ make: () => section(ctx, "Tests", [testsView(ctx, featureId, data.proofs ?? [])]),
1838
+ },
1839
+ ],
1840
+ }),
1841
+ );
1160
1842
 
1161
- if (data.findings.length) out.append(section(ctx, "Findings", [findingList(ctx, data.findings)]));
1162
- if (graph) out.append(graphView(ctx, graph, "The feature and its neighbours"));
1163
1843
  return out;
1164
1844
  }
1165
1845
 
@@ -1183,7 +1863,8 @@ function stepFilesPanel(ctx, feature, flowId, step) {
1183
1863
  function paint(state) {
1184
1864
  const groups = new Map();
1185
1865
 
1186
- for (const item of state.files) groups.set(item.module, [...(groups.get(item.module) ?? []), item]);
1866
+ for (const item of state.files)
1867
+ groups.set(item.module, [...(groups.get(item.module) ?? []), item]);
1187
1868
 
1188
1869
  state.box.replaceChildren(
1189
1870
  ...[...groups.entries()].map(([name, items]) =>
@@ -1198,13 +1879,18 @@ function stepFilesPanel(ctx, feature, flowId, step) {
1198
1879
  ),
1199
1880
  state.files.length || state.error ? "" : muted(ctx, "No files in this set."),
1200
1881
  state.error
1201
- ? el("p", { class: "grimoire-error-title", text: `Could not load the files: ${state.error}. Try again.` })
1882
+ ? el("p", {
1883
+ class: "grimoire-error-title",
1884
+ text: `Could not load the files: ${state.error}. Try again.`,
1885
+ })
1202
1886
  : "",
1203
1887
  state.files.length < state.total || state.error
1204
1888
  ? el("button", {
1205
1889
  type: "button",
1206
1890
  class: "grimoire-filter",
1207
- text: state.error ? "Try again" : `Load ${Math.min(STEP_FILES_PAGE, state.total - state.files.length)} more`,
1891
+ text: state.error
1892
+ ? "Try again"
1893
+ : `Load ${Math.min(STEP_FILES_PAGE, state.total - state.files.length)} more`,
1208
1894
  onclick: () => fetchPage(state),
1209
1895
  })
1210
1896
  : "",
@@ -1291,53 +1977,6 @@ function countsLine(counts) {
1291
1977
  return parts.join(" · ");
1292
1978
  }
1293
1979
 
1294
- /** The journey: steps as a vertical stepper. */
1295
- function journey(ctx, feature, flowId, flow, steps) {
1296
- const { el } = ctx;
1297
-
1298
- if (!steps.length) return ctx.empty("This flow has no steps.");
1299
-
1300
- return el(
1301
- "ol",
1302
- { class: "grimoire-stepper" },
1303
- steps.map((step) => {
1304
- const written = (flow.steps ?? []).find((item) => item.index === step.index);
1305
- const note = written && written.note ? written.note : null;
1306
- const counts = step.counts ?? { direct: 0, feature: 0, reachable: 0, typeOnly: 0 };
1307
- const shown = expander(ctx, "Show files", () => stepFilesPanel(ctx, feature, flowId, step));
1308
- const space = step.target.indexOf(" ");
1309
-
1310
- return el("li", { class: "grimoire-step" }, [
1311
- el("span", { class: "grimoire-step-marker" }, [stepIcon(ctx, step.type)]),
1312
- el("div", { class: "grimoire-step-body" }, [
1313
- el("div", { class: "grimoire-step-head" }, [
1314
- mono(ctx, `${step.index}`),
1315
- pill(ctx, step.type),
1316
- step.type === "route" && space > 0
1317
- ? routeLink(ctx, step.target.slice(0, space), step.target.slice(space + 1))
1318
- : el("span", { class: "grimoire-step-target", text: step.target }),
1319
- step.found === false ? pill(ctx, "not found in the book", "bad") : "",
1320
- ]),
1321
- note ? el("p", { class: "grimoire-muted" }, codeText(ctx, note)) : "",
1322
- step.linked
1323
- ? el("p", { class: "grimoire-linked" }, [
1324
- "Affects ",
1325
- flowLink(ctx, step.linked.ref),
1326
- step.linked.heading ? ` (${step.linked.heading})` : "",
1327
- step.linked.summary ? el("span", { class: "grimoire-muted" }, [" ", step.linked.summary]) : "",
1328
- ])
1329
- : "",
1330
- step.entry ? el("p", {}, [muted(ctx, "Starts at "), fileLink(ctx, step.entry)]) : "",
1331
- counts.reachable || counts.direct
1332
- ? el("div", { class: "grimoire-step-counts" }, [muted(ctx, countsLine(counts)), shown.button])
1333
- : "",
1334
- shown.panel,
1335
- ]),
1336
- ]);
1337
- }),
1338
- );
1339
- }
1340
-
1341
1980
  /** The health numbers; older answers have none, so they are counted from the criteria. */
1342
1981
  function flowHealth(data) {
1343
1982
  if (data.health) return data.health;
@@ -1351,7 +1990,8 @@ function flowHealth(data) {
1351
1990
  criteria: { total: criteria.length, proven: byStatus.pass, byStatus },
1352
1991
  steps: {
1353
1992
  total: data.bookmap.steps.length,
1354
- resolved: data.bookmap.steps.filter((step) => step.found !== false).length,
1993
+ resolved: data.bookmap.steps.filter((step) => step.found === true).length,
1994
+ unchecked: data.bookmap.steps.filter((step) => step.found === null).length,
1355
1995
  },
1356
1996
  findings: { errors: 0, warnings: 0, expected: 0 },
1357
1997
  };
@@ -1416,7 +2056,10 @@ function fixNextBox(ctx, ref, criterion) {
1416
2056
  );
1417
2057
  }
1418
2058
 
1419
- return el("section", { class: "grimoire-card grimoire-fixnext" }, [el("h3", { text: "Fix next" }), ...body]);
2059
+ return el("section", { class: "grimoire-card grimoire-fixnext" }, [
2060
+ el("h3", { text: "Fix next" }),
2061
+ ...body,
2062
+ ]);
1420
2063
  }
1421
2064
 
1422
2065
  /** One criterion with one status pill and the tests behind it. */
@@ -1459,10 +2102,15 @@ function proofRow(ctx, criterion, untracked) {
1459
2102
  function neighbours(ctx, feature, data, className) {
1460
2103
  const make = (item, arrow) =>
1461
2104
  item
1462
- ? link(ctx, arrow === "prev" ? `‹ ${item.heading ?? item.id}` : `${item.heading ?? item.id} ›`, `flow/${encodeURIComponent(feature)}/${encodeURIComponent(item.id)}`, {
1463
- class: `grimoire-neighbour is-${arrow}`,
1464
- rel: arrow,
1465
- })
2105
+ ? link(
2106
+ ctx,
2107
+ arrow === "prev" ? `‹ ${item.heading ?? item.id}` : `${item.heading ?? item.id} ›`,
2108
+ `flow/${encodeURIComponent(feature)}/${encodeURIComponent(item.id)}`,
2109
+ {
2110
+ class: `grimoire-neighbour is-${arrow}`,
2111
+ rel: arrow,
2112
+ },
2113
+ )
1466
2114
  : "";
1467
2115
 
1468
2116
  if (!data.previous && !data.next) return "";
@@ -1473,7 +2121,185 @@ function neighbours(ctx, feature, data, className) {
1473
2121
  ]);
1474
2122
  }
1475
2123
 
1476
- async function flowView(ctx, feature, flowId) {
2124
+ /** The label a journey node shows for a step. */
2125
+ function nodeLabel(step) {
2126
+ const tail = step.target.indexOf(" [");
2127
+
2128
+ return tail > 0 ? step.target.slice(0, tail) : step.target;
2129
+ }
2130
+
2131
+ /** Why a node looks the way it does, in words. */
2132
+ function nodeState(step) {
2133
+ if (step.found === false) return "not found in the book";
2134
+ if (step.found === null) return "not checked by the book";
2135
+ return "found in the book";
2136
+ }
2137
+
2138
+ /** What a selected journey node shows: its note, link, entry file and the files it reaches. */
2139
+ function journeyDetail(ctx, feature, flowId, flow, step) {
2140
+ const { el } = ctx;
2141
+ const written = (flow.steps ?? []).find((item) => item.index === step.index);
2142
+ const note = written && written.note ? written.note : null;
2143
+ const counts = step.counts ?? { direct: 0, feature: 0, reachable: 0, typeOnly: 0 };
2144
+ const shown = expander(ctx, "Show files", () => stepFilesPanel(ctx, feature, flowId, step));
2145
+ const space = step.target.indexOf(" ");
2146
+
2147
+ return el("div", { class: "grimoire-jdetail" }, [
2148
+ el("div", { class: "grimoire-step-head" }, [
2149
+ mono(ctx, `${step.index}`),
2150
+ pill(ctx, step.type),
2151
+ step.type === "route" && space > 0
2152
+ ? routeLink(ctx, step.target.slice(0, space), step.target.slice(space + 1))
2153
+ : el("span", { class: "grimoire-step-target", text: step.target }),
2154
+ step.found === false ? pill(ctx, "not found in the book", "bad") : "",
2155
+ ]),
2156
+ note ? el("p", { class: "grimoire-muted" }, codeText(ctx, note)) : "",
2157
+ step.linked
2158
+ ? el("p", { class: "grimoire-linked" }, [
2159
+ "Affects ",
2160
+ flowLink(ctx, step.linked.ref),
2161
+ step.linked.heading ? ` (${step.linked.heading})` : "",
2162
+ step.linked.summary
2163
+ ? el("span", { class: "grimoire-muted" }, [" ", step.linked.summary])
2164
+ : "",
2165
+ ])
2166
+ : "",
2167
+ step.entry ? el("p", {}, [muted(ctx, "Starts at "), fileLink(ctx, step.entry)]) : "",
2168
+ counts.reachable || counts.direct
2169
+ ? el("div", { class: "grimoire-step-counts" }, [muted(ctx, countsLine(counts)), shown.button])
2170
+ : "",
2171
+ shown.panel,
2172
+ ]);
2173
+ }
2174
+
2175
+ /**
2176
+ * The journey: the written steps drawn in order as connected nodes (a row
2177
+ * that wraps; one column on a phone). Each node is a button; the one picked
2178
+ * opens its panel under the drawing.
2179
+ */
2180
+ function journeyView(ctx, feature, flowId, flow, steps) {
2181
+ const { el } = ctx;
2182
+
2183
+ if (!steps.length) return ctx.empty("This flow has no steps.");
2184
+
2185
+ const detail = el("div", {
2186
+ class: "grimoire-jpanel",
2187
+ id: `grimoire-jpanel-${flowId}`,
2188
+ role: "region",
2189
+ "aria-label": "Step detail",
2190
+ });
2191
+ const nodes = new Map();
2192
+ let current = null;
2193
+
2194
+ function pick(step) {
2195
+ const same = current === step.index;
2196
+
2197
+ current = same ? null : step.index;
2198
+
2199
+ for (const [index, button] of nodes) {
2200
+ const on = index === current;
2201
+
2202
+ button.setAttribute("aria-expanded", String(on));
2203
+ button.setAttribute("class", `${button.baseClass}${on ? " is-selected" : ""}`);
2204
+ }
2205
+
2206
+ detail.replaceChildren(...(same ? [] : [journeyDetail(ctx, feature, flowId, flow, step)]));
2207
+ }
2208
+
2209
+ const list = el(
2210
+ "ol",
2211
+ { class: "grimoire-jny", "aria-label": "Steps in order" },
2212
+ steps.map((step) => {
2213
+ const state = step.found === false ? " is-missing" : step.found === null ? " is-unknown" : "";
2214
+ const baseClass = `grimoire-jnode is-${step.type.replace(/\s+/g, "-")}${state}`;
2215
+ const button = el(
2216
+ "button",
2217
+ {
2218
+ type: "button",
2219
+ class: baseClass,
2220
+ "aria-expanded": "false",
2221
+ "aria-controls": `grimoire-jpanel-${flowId}`,
2222
+ title: `Step ${step.index}, ${step.type}: ${nodeLabel(step)} (${nodeState(step)})`,
2223
+ onclick: () => pick(step),
2224
+ },
2225
+ [
2226
+ el("span", { class: "grimoire-jnode-top" }, [
2227
+ stepIcon(ctx, step.type, 16),
2228
+ el("span", { class: "grimoire-jnode-type", text: step.type }),
2229
+ el("span", { class: "grimoire-jnode-index", text: String(step.index) }),
2230
+ ]),
2231
+ el("span", { class: "grimoire-jnode-label", text: nodeLabel(step) }),
2232
+ step.found === false
2233
+ ? el("span", { class: "grimoire-jnode-flag", text: "not found" })
2234
+ : "",
2235
+ ],
2236
+ );
2237
+
2238
+ button.baseClass = baseClass;
2239
+ nodes.set(step.index, button);
2240
+
2241
+ return el("li", { class: "grimoire-jstep" }, [button]);
2242
+ }),
2243
+ );
2244
+
2245
+ return el("div", { class: "grimoire-journey" }, [list, detail]);
2246
+ }
2247
+
2248
+ /** The "What if…" lane: each handled case as a small card; no card is tied to a step, the data does not say which. */
2249
+ function whatIfLane(ctx, feature, flowId, flow) {
2250
+ const { el } = ctx;
2251
+ const cases = flow.cases ?? [];
2252
+ const handled = cases.filter((item) => !item.doesNotApply);
2253
+ const skipped = cases.filter((item) => item.doesNotApply);
2254
+
2255
+ if (!cases.length) return "";
2256
+
2257
+ return section(ctx, "What if…", [
2258
+ handled.length
2259
+ ? el(
2260
+ "ul",
2261
+ { class: "grimoire-whatif" },
2262
+ handled.map((item) =>
2263
+ el("li", { class: "grimoire-whatif-card" }, [
2264
+ el("strong", { class: "grimoire-whatif-q", text: `What if ${item.question}?` }),
2265
+ el("p", {}, codeText(ctx, item.answer)),
2266
+ (item.criteria ?? []).length
2267
+ ? el("span", { class: "grimoire-chips" }, [
2268
+ muted(ctx, "proven by "),
2269
+ ...item.criteria.map((id) =>
2270
+ link(
2271
+ ctx,
2272
+ id,
2273
+ `flow/${encodeURIComponent(feature)}/${encodeURIComponent(flowId)}/proof`,
2274
+ {
2275
+ class: "grimoire-chip",
2276
+ title: `Open the Proof tab for ${id}`,
2277
+ },
2278
+ ),
2279
+ ),
2280
+ ])
2281
+ : "",
2282
+ ]),
2283
+ ),
2284
+ )
2285
+ : muted(ctx, "No handled cases written."),
2286
+ skipped.length
2287
+ ? el("details", { class: "grimoire-details" }, [
2288
+ el("summary", { text: `Does not apply (${skipped.length})` }),
2289
+ list(
2290
+ ctx,
2291
+ skipped.map((item) => [
2292
+ el("strong", { text: item.question }),
2293
+ " ",
2294
+ codeText(ctx, stripDoesNotApply(item.answer)),
2295
+ ]),
2296
+ ),
2297
+ ])
2298
+ : "",
2299
+ ]);
2300
+ }
2301
+
2302
+ async function flowView(ctx, feature, flowId, tab = "") {
1477
2303
  const data = await ctx.api(`flows/${encodeURIComponent(feature)}/${encodeURIComponent(flowId)}`);
1478
2304
  const { el } = ctx;
1479
2305
  const flow = data.flow;
@@ -1491,6 +2317,9 @@ async function flowView(ctx, feature, flowId) {
1491
2317
  const proven = health.criteria.proven;
1492
2318
  const total = health.criteria.total;
1493
2319
  const failing = health.criteria.byStatus.fail ?? 0;
2320
+ const base = `flow/${encodeURIComponent(feature)}/${encodeURIComponent(flowId)}`;
2321
+ // Missing tests are already shown per criterion in the Proof tab, so they are not listed twice.
2322
+ const rest = data.findings.filter((finding) => finding.code !== "GR4001");
1494
2323
  const out = el("div", { class: "grimoire-view grimoire-flow" }, [
1495
2324
  el("div", { class: "grimoire-minihead" }, [
1496
2325
  el("strong", { text: title }),
@@ -1520,14 +2349,21 @@ async function flowView(ctx, feature, flowId) {
1520
2349
  tile(ctx, {
1521
2350
  label: "Criteria proven",
1522
2351
  value: `${proven}/${total}`,
1523
- sub: failing ? `${plural(failing, "criterion")} failing` : total ? "passing tests" : "none written",
2352
+ sub: failing
2353
+ ? `${plural(failing, "criterion")} failing`
2354
+ : total
2355
+ ? "passing tests"
2356
+ : "none written",
1524
2357
  tone: failing ? "bad" : total && proven === total ? "good" : total ? "warn" : "",
1525
2358
  }),
1526
2359
  el("div", { class: "grimoire-stat" }, [
1527
2360
  el("span", { class: "grimoire-stat-label", text: "Last test run" }),
1528
2361
  el("span", {
1529
2362
  class: "grimoire-stat-value grimoire-stat-small",
1530
- text: results && results.recorded && results.updatedAt ? results.updatedAt.slice(0, 10) : "none",
2363
+ text:
2364
+ results && results.recorded && results.updatedAt
2365
+ ? results.updatedAt.slice(0, 10)
2366
+ : "none",
1531
2367
  }),
1532
2368
  el("span", {
1533
2369
  class: "grimoire-stat-sub",
@@ -1545,9 +2381,14 @@ async function flowView(ctx, feature, flowId) {
1545
2381
  el("span", { class: "grimoire-stat-label", text: "Steps resolved" }),
1546
2382
  el("span", {
1547
2383
  class: "grimoire-stat-value",
1548
- text: `${health.steps.resolved}/${health.steps.total}`,
2384
+ text: `${health.steps.resolved}/${health.steps.total - (health.steps.unchecked ?? 0)}`,
2385
+ }),
2386
+ el("span", {
2387
+ class: "grimoire-stat-sub",
2388
+ text: health.steps.unchecked
2389
+ ? `found in the book; ${health.steps.unchecked} not checked`
2390
+ : "found in the book",
1549
2391
  }),
1550
- el("span", { class: "grimoire-stat-sub", text: "found in the book" }),
1551
2392
  ]),
1552
2393
  ]),
1553
2394
  ]);
@@ -1564,133 +2405,148 @@ async function flowView(ctx, feature, flowId) {
1564
2405
  );
1565
2406
  }
1566
2407
 
1567
- out.append(fixNextBox(ctx, ref, fixNextCriterion(map.criteria)));
1568
- out.append(section(ctx, "Journey", [journey(ctx, feature, flowId, flow, map.steps)]));
1569
- out.append(
1570
- section(ctx, "Proof", [
1571
- map.criteria.length
1572
- ? el(
1573
- "ul",
1574
- { class: "grimoire-proofs" },
1575
- map.criteria.map((criterion) => proofRow(ctx, criterion, untracked)),
1576
- )
1577
- : ctx.empty("No criteria written."),
1578
- ]),
1579
- );
2408
+ const journeyTab = () => {
2409
+ const box = el("div", { class: "grimoire-tabstack" });
1580
2410
 
1581
- if ((flow.differs ?? []).length) {
1582
- out.append(
1583
- section(ctx, "Differs by app", [
1584
- list(
1585
- ctx,
1586
- flow.differs.map((item) => [mono(ctx, item.name), " ", codeText(ctx, item.text)]),
1587
- ),
1588
- ]),
1589
- );
1590
- }
2411
+ if ((flow.story ?? []).length) {
2412
+ box.append(
2413
+ section(ctx, "Story", [
2414
+ el(
2415
+ "ol",
2416
+ { class: "grimoire-story" },
2417
+ flow.story.map((item) => el("li", {}, codeText(ctx, item.text))),
2418
+ ),
2419
+ ]),
2420
+ );
2421
+ }
1591
2422
 
1592
- if (flow.cases.length) {
1593
- const handled = flow.cases.filter((item) => !item.doesNotApply);
1594
- const skipped = flow.cases.filter((item) => item.doesNotApply);
1595
- const jump = (id) =>
1596
- el("button", {
1597
- type: "button",
1598
- class: "grimoire-chip",
1599
- title: `Go to ${id}`,
1600
- text: id,
1601
- onclick: () => {
1602
- const target = out.findAll
1603
- ? out.findAll((node) => node.attributes && node.attributes.id === `grimoire-ac-${id}`)[0]
1604
- : out.querySelector?.(`[id="grimoire-ac-${id}"]`);
1605
-
1606
- target?.scrollIntoView?.({ block: "center" });
1607
- },
1608
- });
2423
+ box.append(section(ctx, "Journey", [journeyView(ctx, feature, flowId, flow, map.steps)]));
2424
+ box.append(whatIfLane(ctx, feature, flowId, flow));
1609
2425
 
1610
- out.append(
1611
- section(ctx, "Cases", [
1612
- handled.length
1613
- ? el(
1614
- "ul",
1615
- { class: "grimoire-cases" },
1616
- handled.map((item) =>
1617
- el("li", {}, [
1618
- el("strong", { text: item.question }),
1619
- " ",
1620
- codeText(ctx, item.answer),
1621
- (item.criteria ?? []).length
1622
- ? el("span", { class: "grimoire-chips" }, [" proven by ", ...item.criteria.map(jump)])
1623
- : "",
1624
- ]),
1625
- ),
2426
+ if ((flow.differs ?? []).length) {
2427
+ box.append(
2428
+ section(ctx, "Differs by app", [
2429
+ list(
2430
+ ctx,
2431
+ flow.differs.map((item) => [mono(ctx, item.name), " ", codeText(ctx, item.text)]),
2432
+ ),
2433
+ ]),
2434
+ );
2435
+ }
2436
+
2437
+ if ((flow.notHandled ?? []).length) {
2438
+ box.append(
2439
+ section(ctx, "Not handled", [
2440
+ list(
2441
+ ctx,
2442
+ flow.notHandled.map((item) => [
2443
+ el("strong", { text: item.name }),
2444
+ " ",
2445
+ codeText(ctx, item.text),
2446
+ ]),
2447
+ ),
2448
+ ]),
2449
+ );
2450
+ }
2451
+
2452
+ if (flow.unknowns.length) {
2453
+ box.append(
2454
+ section(ctx, "Unknowns", [
2455
+ list(
2456
+ ctx,
2457
+ flow.unknowns.map((item) => [codeText(ctx, item.text)]),
2458
+ ),
2459
+ ]),
2460
+ );
2461
+ }
2462
+
2463
+ box.append(
2464
+ section(ctx, "Where users see it", [
2465
+ map.shownBy.length
2466
+ ? list(
2467
+ ctx,
2468
+ map.shownBy.map((shown) => [
2469
+ shown.type === "layout"
2470
+ ? `${shown.app} layout ${shown.id}`
2471
+ : link(
2472
+ ctx,
2473
+ `${shown.app} ${shown.type} ${shown.id}`,
2474
+ `page/${encodeURIComponent(shown.app)}/${encodeURIComponent(shown.id)}`,
2475
+ ),
2476
+ ` as block ${shown.block}`,
2477
+ ]),
1626
2478
  )
1627
- : muted(ctx, "No handled cases written."),
1628
- skipped.length
1629
- ? el("details", { class: "grimoire-details" }, [
1630
- el("summary", { text: `Does not apply (${skipped.length})` }),
1631
- list(
1632
- ctx,
1633
- skipped.map((item) => [
1634
- el("strong", { text: item.question }),
1635
- " ",
1636
- codeText(ctx, stripDoesNotApply(item.answer)),
1637
- ]),
1638
- ),
1639
- ])
1640
- : "",
2479
+ : ctx.empty("No app page shows this flow."),
1641
2480
  ]),
1642
2481
  );
1643
- }
2482
+ box.append(section(ctx, "History", [changesView(ctx, data.history)]));
2483
+ box.append(neighbours(ctx, feature, data, "grimoire-pager"));
2484
+ return box;
2485
+ };
1644
2486
 
1645
- if ((flow.notHandled ?? []).length) {
1646
- out.append(
1647
- section(ctx, "Not handled", [
1648
- list(
1649
- ctx,
1650
- flow.notHandled.map((item) => [el("strong", { text: item.name }), " ", codeText(ctx, item.text)]),
1651
- ),
2487
+ const proofTab = () =>
2488
+ el("div", { class: "grimoire-tabstack" }, [
2489
+ fixNextBox(ctx, ref, fixNextCriterion(map.criteria)),
2490
+ section(ctx, "Proof", [
2491
+ map.criteria.length
2492
+ ? el(
2493
+ "ul",
2494
+ { class: "grimoire-proofs" },
2495
+ map.criteria.map((criterion) => proofRow(ctx, criterion, untracked)),
2496
+ )
2497
+ : ctx.empty("No criteria written."),
1652
2498
  ]),
1653
- );
1654
- }
2499
+ ]);
1655
2500
 
1656
- if (flow.unknowns.length) {
1657
- out.append(
1658
- section(ctx, "Unknowns", [
1659
- list(
1660
- ctx,
1661
- flow.unknowns.map((item) => [codeText(ctx, item.text)]),
1662
- ),
1663
- ]),
1664
- );
1665
- }
2501
+ const filesTab = () =>
2502
+ section(ctx, "Files per step", [
2503
+ map.steps.length
2504
+ ? el(
2505
+ "div",
2506
+ { class: "grimoire-groups" },
2507
+ map.steps.map((step) => {
2508
+ const counts = step.counts ?? { direct: 0, feature: 0, reachable: 0, typeOnly: 0 };
2509
+
2510
+ return group(ctx, {
2511
+ title: `${step.index}. ${nodeLabel(step)}`,
2512
+ count: counts.reachable,
2513
+ tone: step.found === false ? "warn" : "",
2514
+ lead: [pill(ctx, step.type)],
2515
+ make: () =>
2516
+ counts.reachable || counts.direct
2517
+ ? stepFilesPanel(ctx, feature, flowId, step)
2518
+ : muted(
2519
+ ctx,
2520
+ step.found === false
2521
+ ? "The step matched nothing in the book."
2522
+ : "This step reaches no files.",
2523
+ ),
2524
+ });
2525
+ }),
2526
+ )
2527
+ : ctx.empty("This flow has no steps."),
2528
+ ]);
1666
2529
 
1667
2530
  out.append(
1668
- section(ctx, "Where users see it", [
1669
- map.shownBy.length
1670
- ? list(
1671
- ctx,
1672
- map.shownBy.map((shown) => [
1673
- shown.type === "layout"
1674
- ? `${shown.app} layout ${shown.id}`
1675
- : link(
1676
- ctx,
1677
- `${shown.app} ${shown.type} ${shown.id}`,
1678
- `page/${encodeURIComponent(shown.app)}/${encodeURIComponent(shown.id)}`,
1679
- ),
1680
- ` as block ${shown.block}`,
1681
- ]),
1682
- )
1683
- : ctx.empty("No app page shows this flow."),
1684
- ]),
2531
+ tabbed(ctx, {
2532
+ label: "This flow",
2533
+ prefix: "grimoire-flowtab",
2534
+ active: tab,
2535
+ route: (key) => (key === "journey" ? base : `${base}/${key}`),
2536
+ tabs: [
2537
+ { id: "journey", label: "Journey", count: map.steps.length, make: journeyTab },
2538
+ { id: "proof", label: "Proof", count: map.criteria.length, make: proofTab },
2539
+ { id: "files", label: "Files", make: filesTab },
2540
+ {
2541
+ id: "findings",
2542
+ label: "Findings",
2543
+ count: rest.length,
2544
+ make: () => section(ctx, "Findings", [findingGroups(ctx, rest)]),
2545
+ },
2546
+ ],
2547
+ }),
1685
2548
  );
1686
- out.append(section(ctx, "History", [changesView(ctx, data.history)]));
1687
2549
 
1688
- // Missing tests are already shown per criterion above, so they are not listed twice.
1689
- const rest = data.findings.filter((finding) => finding.code !== "GR4001");
1690
-
1691
- if (rest.length) out.append(section(ctx, "Findings", [findingList(ctx, rest)]));
1692
-
1693
- out.append(neighbours(ctx, feature, data, "grimoire-pager"));
1694
2550
  return out;
1695
2551
  }
1696
2552
 
@@ -2155,7 +3011,11 @@ function checkGroupCard(ctx, group, mode, query) {
2155
3011
  const shown = expander(ctx, perFeature ? "Show files" : "Show", () =>
2156
3012
  pagedFindings(
2157
3013
  ctx,
2158
- { ...filter, code: group.code, ...(item.feature === "(none)" ? {} : { feature: item.feature }) },
3014
+ {
3015
+ ...filter,
3016
+ code: group.code,
3017
+ ...(item.feature === "(none)" ? {} : { feature: item.feature }),
3018
+ },
2159
3019
  { hints: false },
2160
3020
  ),
2161
3021
  );
@@ -2215,7 +3075,10 @@ async function checkView(ctx, query = {}) {
2215
3075
  pill(ctx, `${plural(counts.errors, "error")}`, counts.errors ? "bad" : "good"),
2216
3076
  pill(ctx, plural(counts.warnings, "warning"), counts.warnings ? "warn" : ""),
2217
3077
  pill(ctx, `${counts.expected} expected`),
2218
- muted(ctx, `routes ${report.routes ?? "cached"}`),
3078
+ muted(
3079
+ ctx,
3080
+ `Route facts: ${routeFactsState(report.routes).value}, ${routeFactsState(report.routes).sub}`,
3081
+ ),
2219
3082
  ]),
2220
3083
  el("p", {
2221
3084
  class: "grimoire-headline",
@@ -2224,14 +3087,30 @@ async function checkView(ctx, query = {}) {
2224
3087
  el("div", { class: "grimoire-toolbar grimoire-check-filters" }, [
2225
3088
  el("div", { class: "grimoire-filters", role: "group", "aria-label": "Severity" }, [
2226
3089
  filterLink(ctx, "all", checkTarget({ ...query, severity: "" }), !query.severity),
2227
- filterLink(ctx, "errors", checkTarget({ ...query, severity: "error" }), query.severity === "error"),
2228
- filterLink(ctx, "warnings", checkTarget({ ...query, severity: "warning" }), query.severity === "warning"),
3090
+ filterLink(
3091
+ ctx,
3092
+ "errors",
3093
+ checkTarget({ ...query, severity: "error" }),
3094
+ query.severity === "error",
3095
+ ),
3096
+ filterLink(
3097
+ ctx,
3098
+ "warnings",
3099
+ checkTarget({ ...query, severity: "warning" }),
3100
+ query.severity === "warning",
3101
+ ),
2229
3102
  ]),
2230
3103
  el("div", { class: "grimoire-filters", role: "group", "aria-label": "State" }, [
2231
3104
  filterLink(ctx, "to fix", checkTarget({ ...query, state: "" }), !query.state),
2232
3105
  filterLink(ctx, "expected", checkTarget({ ...query, state: "expected" }), expectedMode),
2233
3106
  ]),
2234
- filterSelect(ctx, "Code", "code", groups.map((group) => group.code), query),
3107
+ filterSelect(
3108
+ ctx,
3109
+ "Code",
3110
+ "code",
3111
+ groups.map((group) => group.code),
3112
+ query,
3113
+ ),
2235
3114
  filterSelect(ctx, "Feature", "feature", names, query),
2236
3115
  ]),
2237
3116
  active.some((key) => key === "code" || key === "feature" || key === "flow")
@@ -2292,7 +3171,10 @@ async function checkView(ctx, query = {}) {
2292
3171
  if (expected.length) {
2293
3172
  out.append(
2294
3173
  el("div", { class: "grimoire-view-groups" }, [
2295
- el("h3", { class: "grimoire-subhead", text: `Expected: proposed work (${plural(expected.length, "kind")})` }),
3174
+ el("h3", {
3175
+ class: "grimoire-subhead",
3176
+ text: `Expected: proposed work (${plural(expected.length, "kind")})`,
3177
+ }),
2296
3178
  el("p", {
2297
3179
  class: "grimoire-muted",
2298
3180
  text: "These concern features or flows that are still proposed, so the code does not exist yet. They never fail the check.",
@@ -2466,16 +3348,18 @@ async function body(ctx, summaryRequest) {
2466
3348
 
2467
3349
  switch (type) {
2468
3350
  case "product": {
2469
- const map = globalThis.grimoireProductMap ?? (await import(/* @vite-ignore */ moduleUrl(ctx.asset("product-map.js"))));
3351
+ const map =
3352
+ globalThis.grimoireProductMap ??
3353
+ (await import(/* @vite-ignore */ moduleUrl(ctx.asset("product-map.js"))));
2470
3354
 
2471
3355
  return map.productMapView(ctx, parts.slice(1));
2472
3356
  }
2473
3357
  case "features":
2474
3358
  return featuresView(ctx);
2475
3359
  case "feature":
2476
- return featureView(ctx, first);
3360
+ return featureView(ctx, first, second);
2477
3361
  case "flow":
2478
- return flowView(ctx, first, second);
3362
+ return flowView(ctx, first, second, parts[3] ?? "");
2479
3363
  case "page":
2480
3364
  return pageView(ctx, first, parts.slice(2).join("/"));
2481
3365
  case "apps":
@@ -2524,29 +3408,103 @@ function describe(route) {
2524
3408
  return map[type] ?? ["the overview", null];
2525
3409
  }
2526
3410
 
2527
- /** The loading state: shown at once, so a large book never leaves a blank area. */
3411
+ /** The hint under the progress line: more specific the longer the book takes. */
3412
+ function loadingHint(seconds) {
3413
+ if (seconds >= 40)
3414
+ return "Still opening after 40 s. Check that the app is running and look at its server log; Retry appears if the request fails.";
3415
+ if (seconds >= 15)
3416
+ return "This is taking longer than usual. A very large book can need up to 30 s the first time; keep this tab open.";
3417
+ if (seconds >= 5) return "Large books take 5–15 s the first time; later opens are instant.";
3418
+
3419
+ return "Reading the book. The first open of a large book can take a few seconds.";
3420
+ }
3421
+
3422
+ // Inline, so the layout holds even when grimoire.css fails to load (tokens only).
3423
+ const SKEL_GRID =
3424
+ "display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,150px),1fr));gap:12px;margin-top:6px";
3425
+ const SKEL_BLOCK = "height:76px;border-radius:var(--radius,10px);background-color:var(--muted)";
3426
+ const SKEL_ROW =
3427
+ "height:34px;border-radius:calc(var(--radius,10px) - 4px);background-color:var(--muted)";
3428
+ const SKEL_TRACK =
3429
+ "height:4px;border-radius:2px;background:var(--muted);overflow:hidden;position:relative;max-width:260px";
3430
+ const SKEL_BAR = "height:100%;width:40%;border-radius:2px;background:var(--brand,var(--primary))";
3431
+
3432
+ /**
3433
+ * The loading state: a skeleton of the Overview with a progress line, a live
3434
+ * elapsed counter and a hint that grows more specific with time. `stop()` ends
3435
+ * the counter; call it once the view is filled in or failed.
3436
+ */
2528
3437
  function skeleton(ctx) {
2529
3438
  const { el } = ctx;
3439
+ const started = Date.now();
3440
+ const counter = el("span", { class: "grimoire-load-elapsed", text: "0 s" });
3441
+ const hint = el("p", { class: "grimoire-muted grimoire-load-hint", text: loadingHint(0) });
3442
+ const timer =
3443
+ typeof setInterval === "function"
3444
+ ? setInterval(() => {
3445
+ const seconds = Math.floor((Date.now() - started) / 1000);
3446
+
3447
+ counter.textContent = `${seconds} s`;
3448
+ hint.textContent = loadingHint(seconds);
3449
+ }, 1000)
3450
+ : null;
3451
+
3452
+ const node = el(
3453
+ "div",
3454
+ {
3455
+ class: "grimoire-skeleton",
3456
+ role: "status",
3457
+ "aria-live": "polite",
3458
+ style: "display:grid;gap:10px",
3459
+ },
3460
+ [
3461
+ el("p", {
3462
+ class: "grimoire-skeleton-title",
3463
+ style: "margin:0;font-weight:600",
3464
+ text: "Opening the book…",
3465
+ }),
3466
+ el("div", { class: "grimoire-load-progress", style: "display:grid;gap:6px" }, [
3467
+ el("div", { class: "grimoire-load-track", style: SKEL_TRACK, "aria-hidden": "true" }, [
3468
+ el("div", { class: "grimoire-load-bar", style: SKEL_BAR }),
3469
+ ]),
3470
+ el("p", { class: "grimoire-muted", style: "margin:0" }, ["Elapsed ", counter]),
3471
+ ]),
3472
+ hint,
3473
+ el(
3474
+ "div",
3475
+ { class: "grimoire-skeleton-grid", style: SKEL_GRID, "aria-hidden": "true" },
3476
+ [1, 2, 3, 4, 5, 6].map(() =>
3477
+ el("div", { class: "grimoire-skeleton-block", style: SKEL_BLOCK }),
3478
+ ),
3479
+ ),
3480
+ el(
3481
+ "div",
3482
+ {
3483
+ class: "grimoire-skeleton-rows",
3484
+ style: "display:grid;gap:8px;margin-top:6px",
3485
+ "aria-hidden": "true",
3486
+ },
3487
+ [1, 2, 3, 4, 5].map(() => el("div", { class: "grimoire-skeleton-row", style: SKEL_ROW })),
3488
+ ),
3489
+ ],
3490
+ );
2530
3491
 
2531
- return el("div", { class: "grimoire-skeleton", role: "status" }, [
2532
- el("p", { class: "grimoire-skeleton-title", text: "Opening the book…" }),
2533
- el("p", {
2534
- class: "grimoire-muted",
2535
- text: "A large book can take a few seconds to open the first time.",
2536
- }),
2537
- el(
2538
- "div",
2539
- { class: "grimoire-skeleton-grid", "aria-hidden": "true" },
2540
- [1, 2, 3, 4, 5, 6].map(() => el("div", { class: "grimoire-skeleton-block" })),
2541
- ),
2542
- ]);
3492
+ return {
3493
+ node,
3494
+ stop: () => {
3495
+ if (timer !== null) clearInterval(timer);
3496
+ },
3497
+ };
2543
3498
  }
2544
3499
 
2545
3500
  /** A failed view: what failed, why, what to do, and a way to try again. */
2546
3501
  function errorBox(ctx, route, error) {
2547
3502
  const { el } = ctx;
2548
3503
  const [what, back] = describe(route);
2549
- const message = error && error.message ? error.message : String(error);
3504
+ const base = error && error.message ? error.message : String(error);
3505
+ const status =
3506
+ error && typeof error.status === "number" && error.status > 0 ? ` (HTTP ${error.status})` : "";
3507
+ const message = base + status;
2550
3508
  const needsApp = message.includes("running app");
2551
3509
 
2552
3510
  return el("div", { class: "grimoire-error", role: "alert" }, [
@@ -2603,6 +3561,7 @@ function bindShortcut(input) {
2603
3561
  function header(ctx, route, summaryRequest) {
2604
3562
  const { el } = ctx;
2605
3563
  const results = el("div", { class: "grimoire-results" });
3564
+ const brandSlot = el("div", { class: "grimoire-brand-slot" });
2606
3565
  const active = tabOf(route);
2607
3566
  const badges = new Map();
2608
3567
  let activeTab = null;
@@ -2788,12 +3747,17 @@ function header(ctx, route, summaryRequest) {
2788
3747
  set("tasks", data.tasks ? data.tasks.open.length : undefined);
2789
3748
  set("releases", data.releases);
2790
3749
  set("check", data.counts ? data.counts.errors + data.counts.warnings : undefined);
3750
+
3751
+ const brand = grimoireBrand(ctx, data.host);
3752
+
3753
+ if (brand) brandSlot.replaceChildren(brand);
2791
3754
  },
2792
3755
  () => undefined,
2793
3756
  );
2794
3757
 
2795
3758
  return {
2796
3759
  element: el("div", { class: "grimoire-header" }, [
3760
+ brandSlot,
2797
3761
  nav,
2798
3762
  el("div", { class: "grimoire-searchbox" }, [input, results]),
2799
3763
  ]),
@@ -2837,8 +3801,21 @@ async function renderGrimoire(context) {
2837
3801
  const top = header(ctx, route, summaryRequest);
2838
3802
  const content = el("div", { class: "grimoire-body", "aria-busy": "true" });
2839
3803
 
2840
- content.append(skeleton(ctx));
2841
- root.append(el("div", { class: "grimoire-root" }, [top.element, content]));
3804
+ const loading = skeleton(ctx);
3805
+
3806
+ content.append(loading.node);
3807
+ top.input.disabled = true;
3808
+ const footer = el("footer", { class: "grimoire-footer" });
3809
+
3810
+ summaryRequest.then(
3811
+ (data) => {
3812
+ const line = grimoireAppLine(ctx, data.host);
3813
+
3814
+ if (line) footer.replaceChildren(line);
3815
+ },
3816
+ () => undefined,
3817
+ );
3818
+ root.append(el("div", { class: "grimoire-root" }, [top.element, content, footer]));
2842
3819
  top.revealActive();
2843
3820
 
2844
3821
  const loaded = (async () => {
@@ -2847,6 +3824,8 @@ async function renderGrimoire(context) {
2847
3824
  } catch (error) {
2848
3825
  content.replaceChildren(errorBox(ctx, route, error));
2849
3826
  }
3827
+ loading.stop();
3828
+ top.input.disabled = false;
2850
3829
  content.setAttribute("aria-busy", "false");
2851
3830
  })();
2852
3831