@warlock.js/grimoire 5.57.0 → 5.58.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 (105) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/esm/book/build.d.mts.map +1 -1
  3. package/esm/book/build.mjs +2 -1
  4. package/esm/book/build.mjs.map +1 -1
  5. package/esm/book/render.mjs +10 -0
  6. package/esm/book/render.mjs.map +1 -1
  7. package/esm/bookmap/build.d.mts.map +1 -1
  8. package/esm/bookmap/build.mjs +2 -2
  9. package/esm/bookmap/build.mjs.map +1 -1
  10. package/esm/bookmap/steps.mjs +53 -38
  11. package/esm/bookmap/steps.mjs.map +1 -1
  12. package/esm/check/check-grimoire.d.mts.map +1 -1
  13. package/esm/check/check-grimoire.mjs +4 -1
  14. package/esm/check/check-grimoire.mjs.map +1 -1
  15. package/esm/check/rules/criteria.mjs +21 -2
  16. package/esm/check/rules/criteria.mjs.map +1 -1
  17. package/esm/check/rules/screenshots.mjs +57 -0
  18. package/esm/check/rules/screenshots.mjs.map +1 -0
  19. package/esm/codes/codes.d.mts +12 -0
  20. package/esm/codes/codes.d.mts.map +1 -1
  21. package/esm/codes/codes.mjs +6 -0
  22. package/esm/codes/codes.mjs.map +1 -1
  23. package/esm/contracts/adapter.d.mts +6 -0
  24. package/esm/contracts/adapter.d.mts.map +1 -1
  25. package/esm/contracts/book.d.mts +2 -0
  26. package/esm/contracts/book.d.mts.map +1 -1
  27. package/esm/contracts/book.mjs.map +1 -1
  28. package/esm/contracts/bookmap.d.mts +19 -1
  29. package/esm/contracts/bookmap.d.mts.map +1 -1
  30. package/esm/contracts/snapshot.d.mts +11 -0
  31. package/esm/contracts/snapshot.d.mts.map +1 -1
  32. package/esm/contracts/test-results.d.mts +34 -0
  33. package/esm/contracts/test-results.d.mts.map +1 -1
  34. package/esm/contracts/written.d.mts +44 -0
  35. package/esm/contracts/written.d.mts.map +1 -1
  36. package/esm/contracts/written.mjs.map +1 -1
  37. package/esm/devtools/data.mjs +94 -3
  38. package/esm/devtools/data.mjs.map +1 -1
  39. package/esm/devtools/index.d.mts +26 -0
  40. package/esm/devtools/index.d.mts.map +1 -1
  41. package/esm/devtools/index.mjs +88 -5
  42. package/esm/devtools/index.mjs.map +1 -1
  43. package/esm/devtools/product-map.d.mts +14 -0
  44. package/esm/devtools/product-map.d.mts.map +1 -0
  45. package/esm/devtools/product-map.mjs +385 -0
  46. package/esm/devtools/product-map.mjs.map +1 -0
  47. package/esm/devtools/site.d.mts.map +1 -1
  48. package/esm/devtools/site.mjs +85 -13
  49. package/esm/devtools/site.mjs.map +1 -1
  50. package/esm/devtools/snapshot-source.mjs +10 -6
  51. package/esm/devtools/snapshot-source.mjs.map +1 -1
  52. package/esm/graph/index.d.mts +10 -1
  53. package/esm/graph/index.d.mts.map +1 -1
  54. package/esm/graph/index.mjs +3 -2
  55. package/esm/graph/index.mjs.map +1 -1
  56. package/esm/index.d.mts +4 -4
  57. package/esm/paths/index.d.mts +2 -0
  58. package/esm/paths/index.d.mts.map +1 -1
  59. package/esm/paths/index.mjs +3 -1
  60. package/esm/paths/index.mjs.map +1 -1
  61. package/esm/scry/compact.mjs +169 -0
  62. package/esm/scry/compact.mjs.map +1 -0
  63. package/esm/scry/format.d.mts.map +1 -1
  64. package/esm/scry/format.mjs +7 -1
  65. package/esm/scry/format.mjs.map +1 -1
  66. package/esm/scry/query.d.mts.map +1 -1
  67. package/esm/scry/query.mjs +12 -1
  68. package/esm/scry/query.mjs.map +1 -1
  69. package/esm/test-results/index.d.mts +7 -2
  70. package/esm/test-results/index.d.mts.map +1 -1
  71. package/esm/test-results/index.mjs +79 -12
  72. package/esm/test-results/index.mjs.map +1 -1
  73. package/esm/vitest/index.d.mts +6 -0
  74. package/esm/vitest/index.d.mts.map +1 -1
  75. package/esm/vitest/index.mjs +22 -6
  76. package/esm/vitest/index.mjs.map +1 -1
  77. package/esm/warlock/adapter.d.mts.map +1 -1
  78. package/esm/warlock/adapter.mjs +6 -2
  79. package/esm/warlock/adapter.mjs.map +1 -1
  80. package/esm/warlock/mcp-tools.mjs +48 -12
  81. package/esm/warlock/mcp-tools.mjs.map +1 -1
  82. package/esm/workspace/index.d.mts.map +1 -1
  83. package/esm/workspace/index.mjs +4 -2
  84. package/esm/workspace/index.mjs.map +1 -1
  85. package/esm/written/apps.mjs +4 -2
  86. package/esm/written/apps.mjs.map +1 -1
  87. package/esm/written/features.mjs +119 -6
  88. package/esm/written/features.mjs.map +1 -1
  89. package/esm/written/markdown.mjs +66 -1
  90. package/esm/written/markdown.mjs.map +1 -1
  91. package/esm/written/parse-grimoire.d.mts.map +1 -1
  92. package/esm/written/parse-grimoire.mjs +1 -1
  93. package/esm/written/parse-grimoire.mjs.map +1 -1
  94. package/llms-full.txt +76 -3
  95. package/package.json +3 -3
  96. package/skills/backfill-a-grimoire/SKILL.md +5 -0
  97. package/skills/describe-an-app/SKILL.md +12 -0
  98. package/skills/record-a-change/SKILL.md +8 -0
  99. package/skills/use-the-grimoire/SKILL.md +14 -1
  100. package/skills/write-a-feature/SKILL.md +37 -2
  101. package/ui/grimoire-static.js +4 -0
  102. package/ui/grimoire-view.js +1016 -178
  103. package/ui/grimoire.css +427 -2
  104. package/ui/product-map.css +636 -0
  105. package/ui/product-map.js +817 -0
@@ -9,6 +9,7 @@
9
9
 
10
10
  /** The tabs: `[route, label]`. */
11
11
  const TABS = [
12
+ ["product", "Product map"],
12
13
  ["", "Overview"],
13
14
  ["features", "Features"],
14
15
  ["apps", "Apps"],
@@ -46,9 +47,11 @@ function plural(count, word) {
46
47
 
47
48
  /** Which tab a hash route belongs to; `null` when it belongs to none. */
48
49
  function tabOf(route) {
49
- const type = route.split("/")[0] ?? "";
50
+ const type = (route.split("?")[0] ?? "").split("/")[0] ?? "";
50
51
 
51
52
  switch (type) {
53
+ case "product":
54
+ return "product";
52
55
  case "features":
53
56
  case "feature":
54
57
  case "flow":
@@ -158,6 +161,7 @@ function toneOf(status) {
158
161
  case "done":
159
162
  case "fresh":
160
163
  case "cached":
164
+ case "clean":
161
165
  return "good";
162
166
  case "building":
163
167
  case "open":
@@ -169,6 +173,8 @@ function toneOf(status) {
169
173
  case "stale":
170
174
  case "missing":
171
175
  case "untested":
176
+ case "not-run":
177
+ case "no-test":
172
178
  return "warn";
173
179
  case "failing":
174
180
  case "fail":
@@ -217,7 +223,9 @@ function table(ctx, headings, rows) {
217
223
  ctx.el(
218
224
  "tr",
219
225
  {},
220
- row.map((cell) => ctx.el("td", {}, cell)),
226
+ row.map((cell, column) =>
227
+ ctx.el("td", { "data-label": headings[column] ?? "" }, cell),
228
+ ),
221
229
  ),
222
230
  ),
223
231
  ),
@@ -317,6 +325,204 @@ function routeLink(ctx, method, path) {
317
325
  );
318
326
  }
319
327
 
328
+ /** Split a hash route into its path and its query (`check?code=GR3006&feature=cart`). */
329
+ function parseRoute(route) {
330
+ const at = route.indexOf("?");
331
+ const query = {};
332
+
333
+ if (at >= 0) {
334
+ for (const [key, value] of new URLSearchParams(route.slice(at + 1))) query[key] = value;
335
+ }
336
+
337
+ return { path: at < 0 ? route : route.slice(0, at), query };
338
+ }
339
+
340
+ /** The hash route of the Check tab for a filter; empty values are left out. */
341
+ function checkTarget(filter) {
342
+ const params = new URLSearchParams();
343
+
344
+ for (const key of ["code", "feature", "flow", "severity", "state", "offset", "limit"]) {
345
+ const value = filter[key];
346
+
347
+ if (value !== undefined && value !== null && value !== "") params.set(key, String(value));
348
+ }
349
+
350
+ const text = params.toString();
351
+
352
+ return text ? `check?${text}` : "check";
353
+ }
354
+
355
+ /**
356
+ * Text with `` `code` `` spans as nodes: plain strings and `<code>` elements.
357
+ * Every part is set as text. Unbalanced backticks stay as written.
358
+ */
359
+ function codeText(ctx, text) {
360
+ const value = String(text ?? "");
361
+
362
+ if (!value.includes("`")) return value;
363
+
364
+ const parts = value.split("`");
365
+
366
+ if (parts.length % 2 === 0) return value;
367
+
368
+ return parts
369
+ .map((part, index) =>
370
+ index % 2 === 1 ? ctx.el("code", { class: "grimoire-code", text: part }) : part,
371
+ )
372
+ .filter((part) => part !== "");
373
+ }
374
+
375
+ /** The reason of a "does not apply" case, without the words the view groups it under. */
376
+ function stripDoesNotApply(answer) {
377
+ const rest = String(answer ?? "")
378
+ .replace(/^does not apply\b[:\s—-]*/i, "")
379
+ .trim();
380
+
381
+ return rest || "no reason written";
382
+ }
383
+
384
+ /** Select a node's text so the reader can copy it by hand. */
385
+ function selectNode(node, done) {
386
+ try {
387
+ const selection = globalThis.getSelection?.();
388
+ const range = globalThis.document?.createRange?.();
389
+
390
+ if (selection && range) {
391
+ range.selectNodeContents(node);
392
+ selection.removeAllRanges();
393
+ selection.addRange(range);
394
+ done("Selected. Press Ctrl+C to copy.");
395
+ return;
396
+ }
397
+ } catch {
398
+ // Fall through to the plain message.
399
+ }
400
+
401
+ done("Select the line and copy it by hand.");
402
+ }
403
+
404
+ /** Copy text with the clipboard API; fall back to selecting `node`. Never throws. */
405
+ function copyText(text, node, done) {
406
+ try {
407
+ const clipboard = globalThis.navigator?.clipboard;
408
+
409
+ if (clipboard && typeof clipboard.writeText === "function") {
410
+ Promise.resolve(clipboard.writeText(text)).then(
411
+ () => done("Copied."),
412
+ () => selectNode(node, done),
413
+ );
414
+ return;
415
+ }
416
+ } catch {
417
+ // Fall through to selecting.
418
+ }
419
+
420
+ selectNode(node, done);
421
+ }
422
+
423
+ const STEP_ICONS = {
424
+ page: [["rect", { x: "3", y: "4", width: "18", height: "14", rx: "2" }], ["path", { d: "M3 9h18" }]],
425
+ 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" }]],
427
+ 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" }]],
429
+ event: [["path", { d: "M13 2L4 14h7l-1 8 9-12h-7z" }]],
430
+ "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
+ 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" }],
433
+ ],
434
+ };
435
+
436
+ /** A small icon for a flow step type. */
437
+ function stepIcon(ctx, type) {
438
+ const { svg } = ctx;
439
+ const shapes = STEP_ICONS[type] ?? STEP_ICONS.route;
440
+
441
+ return svg(
442
+ "svg",
443
+ {
444
+ viewBox: "0 0 24 24",
445
+ width: "18",
446
+ height: "18",
447
+ fill: "none",
448
+ stroke: "currentColor",
449
+ "stroke-width": "1.8",
450
+ "stroke-linecap": "round",
451
+ "stroke-linejoin": "round",
452
+ "aria-hidden": "true",
453
+ class: "grimoire-step-icon",
454
+ },
455
+ shapes.map(([tag, attrs]) => svg(tag, attrs)),
456
+ );
457
+ }
458
+
459
+ /** Show a node's children only while open; the content is built on the first open. */
460
+ function expander(ctx, label, make) {
461
+ const panel = ctx.el("div", { class: "grimoire-expand" });
462
+ let node = null;
463
+ let open = false;
464
+ const button = ctx.el("button", {
465
+ type: "button",
466
+ class: "grimoire-more",
467
+ "aria-expanded": "false",
468
+ text: label,
469
+ onclick: () => {
470
+ open = !open;
471
+ if (open && node === null) node = make();
472
+ panel.replaceChildren(...(open && node ? [node] : []));
473
+ button.setAttribute("aria-expanded", String(open));
474
+ button.textContent = open ? "Hide" : label;
475
+ },
476
+ });
477
+
478
+ return { button, panel };
479
+ }
480
+
481
+ /**
482
+ * Findings loaded page by page from the check route: `filter` is a
483
+ * `GrimoireCheckFilter`; "Load more" appends the next page.
484
+ */
485
+ function pagedFindings(ctx, filter, options = {}) {
486
+ const { el } = ctx;
487
+ const size = options.size ?? 20;
488
+ const list = el("ul", { class: "grimoire-findings" });
489
+ const status = el("p", { class: "grimoire-muted", role: "status" });
490
+ const more = el("button", { type: "button", class: "grimoire-filter", text: "Load more" });
491
+ const holder = el("div", { class: "grimoire-paged" });
492
+ let offset = 0;
493
+ let busy = false;
494
+
495
+ function paint(total, failed) {
496
+ status.textContent = failed
497
+ ? `Could not load the findings: ${failed}. Try again.`
498
+ : `Showing ${offset} of ${total}`;
499
+ more.textContent = failed ? "Try again" : `Load ${Math.min(size, total - offset)} more`;
500
+ holder.replaceChildren(list, status, failed || offset < total ? more : "");
501
+ }
502
+
503
+ async function load() {
504
+ if (busy) return;
505
+ busy = true;
506
+
507
+ try {
508
+ const page = await ctx.api(checkTarget({ ...filter, offset, limit: size }));
509
+
510
+ for (const finding of page.findings) list.append(findingItem(ctx, finding, options));
511
+ offset += page.findings.length;
512
+ paint(page.total, null);
513
+ } catch (error) {
514
+ paint(0, error && error.message ? error.message : String(error));
515
+ }
516
+
517
+ busy = false;
518
+ }
519
+
520
+ more.addEventListener("click", load);
521
+ holder.append(el("p", { class: "grimoire-muted", role: "status", text: "Loading findings…" }));
522
+ load();
523
+ return holder;
524
+ }
525
+
320
526
  /**
321
527
  * A filterable, sortable listing: a text box, status buttons with counts, an
322
528
  * optional sort menu and an "N of M" line. `render(shown)` returns the one
@@ -427,31 +633,36 @@ function listing(ctx, options) {
427
633
  return el("div", { class: "grimoire-listing" }, [bar, count, body]);
428
634
  }
429
635
 
636
+ /** One finding: severity, code, message, what to do (unless `hints` is `false`), and where. */
637
+ function findingItem(ctx, finding, options = {}) {
638
+ const place = finding.at ? `${finding.at.file}:${finding.at.line}` : null;
639
+ const file = finding.subject.file;
640
+
641
+ return ctx.el("li", { class: "grimoire-finding" }, [
642
+ ctx.el("div", { class: "grimoire-finding-head" }, [
643
+ pill(ctx, finding.severity, toneOf(finding.severity)),
644
+ finding.expected ? pill(ctx, "expected") : "",
645
+ mono(ctx, finding.code),
646
+ ]),
647
+ ctx.el("p", { class: "grimoire-finding-message" }, codeText(ctx, finding.message)),
648
+ finding.hint && options.hints !== false
649
+ ? ctx.el("p", { class: "grimoire-muted" }, codeText(ctx, finding.hint))
650
+ : "",
651
+ place || file
652
+ ? ctx.el("div", { class: "grimoire-chips" }, [
653
+ place ? mono(ctx, place) : "",
654
+ file && file !== finding.at?.file ? fileLink(ctx, file) : "",
655
+ ])
656
+ : "",
657
+ ]);
658
+ }
659
+
430
660
  /** A list of findings: severity, code, message, what to do, and where. */
431
- function findingList(ctx, findings) {
661
+ function findingList(ctx, findings, options = {}) {
432
662
  return ctx.el(
433
663
  "ul",
434
664
  { class: "grimoire-findings" },
435
- findings.map((finding) => {
436
- const place = finding.at ? `${finding.at.file}:${finding.at.line}` : null;
437
- const file = finding.subject.file;
438
-
439
- return ctx.el("li", { class: "grimoire-finding" }, [
440
- ctx.el("div", { class: "grimoire-finding-head" }, [
441
- pill(ctx, finding.severity, toneOf(finding.severity)),
442
- finding.expected ? pill(ctx, "expected") : "",
443
- mono(ctx, finding.code),
444
- ]),
445
- ctx.el("p", { class: "grimoire-finding-message", text: finding.message }),
446
- finding.hint ? ctx.el("p", { class: "grimoire-muted", text: finding.hint }) : "",
447
- place || file
448
- ? ctx.el("div", { class: "grimoire-chips" }, [
449
- place ? mono(ctx, place) : "",
450
- file && file !== finding.at?.file ? fileLink(ctx, file) : "",
451
- ])
452
- : "",
453
- ]);
454
- }),
665
+ findings.map((finding) => findingItem(ctx, finding, options)),
455
666
  );
456
667
  }
457
668
 
@@ -463,7 +674,7 @@ function changesView(ctx, changes) {
463
674
  pill(ctx, change.word),
464
675
  ` ${plain(change.version)} `,
465
676
  change.flow ? [flowLink(ctx, `${change.feature}/${change.flow}`), " "] : "",
466
- change.text,
677
+ codeText(ctx, change.text),
467
678
  change.release
468
679
  ? ` (release ${change.release}${change.date ? `, ${change.date}` : ""})`
469
680
  : " (not released)",
@@ -531,7 +742,11 @@ function graphView(ctx, graph, title) {
531
742
  );
532
743
  }
533
744
 
534
- for (const node of graph.nodes) {
745
+ // Labels overlap on a crowded ring: stagger them, and past 40 nodes name only the centre
746
+ // (every node keeps its tooltip, and the module list sits under the graph).
747
+ const labelled = graph.nodes.length <= 40;
748
+
749
+ for (const [position, node] of graph.nodes.entries()) {
535
750
  const at = place.get(node.id);
536
751
  if (!at) continue;
537
752
  const target = nodeTarget(node.id);
@@ -543,17 +758,31 @@ function graphView(ctx, graph, title) {
543
758
  });
544
759
  const label = svg("text", {
545
760
  x: at[0].toFixed(1),
546
- y: (at[1] + (node.type === "center" ? 24 : 18)).toFixed(1),
761
+ y: (at[1] + (node.type === "center" ? 24 : 18 + (position % 2) * 12)).toFixed(1),
547
762
  "text-anchor": "middle",
548
763
  fill: "var(--foreground)",
549
764
  "font-size": "11",
550
- text: shorten(node.label),
765
+ text: shorten(node.label, node.type === "center" ? 26 : 16),
551
766
  });
552
- const group = svg("g", {}, [svg("title", { text: node.label }), circle, label]);
767
+ const group = svg(
768
+ "g",
769
+ {},
770
+ [svg("title", { text: node.label }), circle, labelled || node.type === "center" ? label : ""].filter(
771
+ (child) => child !== "",
772
+ ),
773
+ );
553
774
  canvas.append(target === null ? group : svg("a", { href: href(target) }, [group]));
554
775
  }
555
776
 
556
- card.append(canvas);
777
+ card.append(el("div", { class: "grimoire-scroll" }, [canvas]));
778
+ if (!labelled) {
779
+ card.append(
780
+ el("p", {
781
+ class: "grimoire-muted",
782
+ text: "Too many nodes to label. Point at a node for its name; every module is listed below.",
783
+ }),
784
+ );
785
+ }
557
786
  return card;
558
787
  }
559
788
 
@@ -577,7 +806,7 @@ const STATUS_ORDER = ["shipped", "building", "proposed", "retired"];
577
806
  async function overviewView(ctx, summaryRequest) {
578
807
  const [data, check, releases] = await Promise.all([
579
808
  summaryRequest,
580
- ctx.api("check").catch(() => null),
809
+ ctx.api("check/groups").catch(() => null),
581
810
  ctx.api("releases").catch(() => null),
582
811
  ]);
583
812
  const { el } = ctx;
@@ -661,7 +890,16 @@ async function overviewView(ctx, summaryRequest) {
661
890
  );
662
891
  }
663
892
 
664
- const problems = (check?.findings ?? []).filter((finding) => !finding.expected).slice(0, 5);
893
+ // Errors first, then the biggest groups; each leads to the Check tab filtered to its code.
894
+ const problems = (check?.groups ?? [])
895
+ .filter((group) => group.count > 0)
896
+ .sort(
897
+ (left, right) =>
898
+ (left.severity === "error" ? 0 : 1) - (right.severity === "error" ? 0 : 1) ||
899
+ right.count - left.count ||
900
+ left.code.localeCompare(right.code),
901
+ )
902
+ .slice(0, 5);
665
903
  const recent = [...(releases?.releases ?? [])]
666
904
  .sort((left, right) => right.date.localeCompare(left.date))
667
905
  .slice(0, 5);
@@ -671,7 +909,18 @@ async function overviewView(ctx, summaryRequest) {
671
909
  section(ctx, "Top problems", [
672
910
  check
673
911
  ? problems.length
674
- ? findingList(ctx, problems)
912
+ ? list(
913
+ ctx,
914
+ problems.map((group) => [
915
+ pill(ctx, group.severity, toneOf(group.severity)),
916
+ " ",
917
+ link(ctx, group.code, checkTarget({ code: group.code }), { class: "grimoire-mono" }),
918
+ " ",
919
+ ...[codeText(ctx, group.title)].flat(),
920
+ " ",
921
+ pill(ctx, String(group.count)),
922
+ ]),
923
+ )
675
924
  : el("p", {}, [pill(ctx, "clean", "good"), " Nothing to fix."])
676
925
  : ctx.empty("The check report could not be loaded."),
677
926
  check ? el("p", {}, [link(ctx, "Open the check report", "check")]) : "",
@@ -896,8 +1145,10 @@ async function featureView(ctx, id) {
896
1145
  list(
897
1146
  ctx,
898
1147
  data.tasks.map((task) => [
899
- link(ctx, task.id, `task/${encodeURIComponent(task.id)}`),
900
- ` ${task.title} `,
1148
+ link(ctx, task.id, `task/${encodeURIComponent(task.id)}`, { class: "grimoire-nowrap" }),
1149
+ " ",
1150
+ codeText(ctx, task.title),
1151
+ " ",
901
1152
  pill(ctx, task.status, toneOf(task.status)),
902
1153
  ]),
903
1154
  ),
@@ -912,121 +1163,491 @@ async function featureView(ctx, id) {
912
1163
  return out;
913
1164
  }
914
1165
 
1166
+ const STEP_FILE_SETS = [
1167
+ ["direct", "Direct imports", "direct"],
1168
+ ["feature", "In this feature", "feature"],
1169
+ ["reachable", "All reachable", "reachable"],
1170
+ ["type-only", "Type-only", "typeOnly"],
1171
+ ];
1172
+
1173
+ /** The files behind one step, loaded a page at a time from the step files route. */
1174
+ function stepFilesPanel(ctx, feature, flowId, step) {
1175
+ const { el } = ctx;
1176
+ const counts = step.counts ?? { direct: 0, feature: 0, reachable: 0, typeOnly: 0 };
1177
+ const sets = STEP_FILE_SETS.filter(([, , key]) => key !== "typeOnly" || counts[key] > 0);
1178
+ const body = el("div", { class: "grimoire-step-files-body" });
1179
+ const tabs = el("div", { class: "grimoire-subtabs", role: "tablist", "aria-label": "File set" });
1180
+ const loaded = new Map();
1181
+ const buttons = [];
1182
+
1183
+ function paint(state) {
1184
+ const groups = new Map();
1185
+
1186
+ for (const item of state.files) groups.set(item.module, [...(groups.get(item.module) ?? []), item]);
1187
+
1188
+ state.box.replaceChildren(
1189
+ ...[...groups.entries()].map(([name, items]) =>
1190
+ el("div", { class: "grimoire-module-group" }, [
1191
+ el("h5", { text: `${name || "(no module)"} (${items.length})` }),
1192
+ el(
1193
+ "div",
1194
+ { class: "grimoire-chips" },
1195
+ items.map((item) => fileLink(ctx, item.file)),
1196
+ ),
1197
+ ]),
1198
+ ),
1199
+ state.files.length || state.error ? "" : muted(ctx, "No files in this set."),
1200
+ state.error
1201
+ ? el("p", { class: "grimoire-error-title", text: `Could not load the files: ${state.error}. Try again.` })
1202
+ : "",
1203
+ state.files.length < state.total || state.error
1204
+ ? el("button", {
1205
+ type: "button",
1206
+ class: "grimoire-filter",
1207
+ text: state.error ? "Try again" : `Load ${Math.min(STEP_FILES_PAGE, state.total - state.files.length)} more`,
1208
+ onclick: () => fetchPage(state),
1209
+ })
1210
+ : "",
1211
+ );
1212
+ }
1213
+
1214
+ async function fetchPage(state) {
1215
+ if (state.busy) return;
1216
+ state.busy = true;
1217
+
1218
+ try {
1219
+ const answer = await ctx.api(
1220
+ `flows/${encodeURIComponent(feature)}/${encodeURIComponent(flowId)}/steps/${step.index}/files?set=${state.set}&offset=${state.files.length}`,
1221
+ );
1222
+
1223
+ state.files.push(...answer.files);
1224
+ state.total = answer.total;
1225
+ state.error = null;
1226
+ } catch (error) {
1227
+ state.error = error && error.message ? error.message : String(error);
1228
+ }
1229
+
1230
+ state.busy = false;
1231
+ paint(state);
1232
+ }
1233
+
1234
+ function open(set) {
1235
+ let state = loaded.get(set);
1236
+
1237
+ if (!state) {
1238
+ state = { set, files: [], total: 0, error: null, busy: false, box: el("div", {}) };
1239
+ state.box.append(muted(ctx, "Loading files…"));
1240
+ loaded.set(set, state);
1241
+ fetchPage(state);
1242
+ }
1243
+
1244
+ for (const [button, key] of buttons) {
1245
+ button.setAttribute("aria-selected", String(key === set));
1246
+ button.setAttribute("class", key === set ? "grimoire-subtab is-active" : "grimoire-subtab");
1247
+ }
1248
+
1249
+ body.replaceChildren(state.box);
1250
+ }
1251
+
1252
+ for (const [key, label, countKey] of sets) {
1253
+ const button = el("button", {
1254
+ type: "button",
1255
+ role: "tab",
1256
+ class: "grimoire-subtab",
1257
+ "aria-selected": "false",
1258
+ text: `${label} ${counts[countKey]}`,
1259
+ onclick: () => open(key),
1260
+ });
1261
+
1262
+ buttons.push([button, key]);
1263
+ tabs.append(button);
1264
+ }
1265
+
1266
+ open("direct");
1267
+ return el("div", { class: "grimoire-step-files" }, [tabs, body]);
1268
+ }
1269
+
1270
+ const STEP_FILES_PAGE = 200;
1271
+
1272
+ /** A number tile that leads nowhere. */
1273
+ function tile(ctx, { label, value, sub, tone = "" }) {
1274
+ return ctx.el("div", { class: tone ? `grimoire-stat is-${tone}` : "grimoire-stat" }, [
1275
+ ctx.el("span", { class: "grimoire-stat-label", text: label }),
1276
+ ctx.el("span", { class: "grimoire-stat-value", text: String(value) }),
1277
+ ctx.el("span", { class: "grimoire-stat-sub", text: sub }),
1278
+ ]);
1279
+ }
1280
+
1281
+ /** How many files a step reaches, in words. */
1282
+ function countsLine(counts) {
1283
+ const parts = [
1284
+ `${counts.direct} direct`,
1285
+ `${counts.feature} in feature`,
1286
+ `${counts.reachable} reachable`,
1287
+ ];
1288
+
1289
+ if (counts.typeOnly > 0) parts.push(`${counts.typeOnly} type-only`);
1290
+
1291
+ return parts.join(" · ");
1292
+ }
1293
+
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
+ /** The health numbers; older answers have none, so they are counted from the criteria. */
1342
+ function flowHealth(data) {
1343
+ if (data.health) return data.health;
1344
+
1345
+ const criteria = data.bookmap.criteria;
1346
+ const byStatus = { pass: 0, fail: 0, stale: 0, "not-run": 0, "no-test": 0 };
1347
+
1348
+ for (const item of criteria) byStatus[item.status] = (byStatus[item.status] ?? 0) + 1;
1349
+
1350
+ return {
1351
+ criteria: { total: criteria.length, proven: byStatus.pass, byStatus },
1352
+ steps: {
1353
+ total: data.bookmap.steps.length,
1354
+ resolved: data.bookmap.steps.filter((step) => step.found !== false).length,
1355
+ },
1356
+ findings: { errors: 0, warnings: 0, expected: 0 },
1357
+ };
1358
+ }
1359
+
1360
+ /** The first criterion to work on: failing, then without a test, then not run or stale. */
1361
+ function fixNextCriterion(criteria) {
1362
+ for (const status of ["fail", "no-test", "not-run", "stale"]) {
1363
+ const found = criteria.find((item) => item.status === status);
1364
+
1365
+ if (found) return found;
1366
+ }
1367
+
1368
+ return null;
1369
+ }
1370
+
1371
+ /** The "Fix next" box. */
1372
+ function fixNextBox(ctx, ref, criterion) {
1373
+ const { el } = ctx;
1374
+
1375
+ if (!criterion) {
1376
+ return el("section", { class: "grimoire-card grimoire-fixnext is-good" }, [
1377
+ el("h3", { text: "Fix next" }),
1378
+ el("p", {}, [pill(ctx, "done", "good"), " Every criterion is proven by a passing test."]),
1379
+ ]);
1380
+ }
1381
+
1382
+ const status = criterion.status;
1383
+ const first = criterion.tests[0];
1384
+ const line = `// @proves ${ref} ${criterion.id}`;
1385
+ const lead =
1386
+ status === "fail"
1387
+ ? `${criterion.id} fails${first ? ` in ${first.file}:${first.line}` : ""}. Fix the code or the test, then run the tests again.`
1388
+ : status === "no-test"
1389
+ ? `${criterion.id} has no test. Put this line directly above the test that proves it.`
1390
+ : status === "stale"
1391
+ ? `${criterion.id} has a result older than its test file. Run the tests again.`
1392
+ : `${criterion.id} has a test that has not run. Run the tests with the Grimoire reporter.`;
1393
+ const code = el("code", { class: "grimoire-code grimoire-proof-line", text: line });
1394
+ const note = el("span", { class: "grimoire-muted", role: "status" });
1395
+ const body = [
1396
+ el("p", { class: "grimoire-fixnext-lead" }, [
1397
+ pill(ctx, status, toneOf(status)),
1398
+ " ",
1399
+ codeText(ctx, lead),
1400
+ ]),
1401
+ el("p", { class: "grimoire-muted" }, codeText(ctx, criterion.text)),
1402
+ ];
1403
+
1404
+ if (status === "no-test") {
1405
+ body.push(
1406
+ el("div", { class: "grimoire-copyline" }, [
1407
+ code,
1408
+ el("button", {
1409
+ type: "button",
1410
+ class: "grimoire-filter",
1411
+ text: "Copy",
1412
+ onclick: () => copyText(line, code, (message) => (note.textContent = message)),
1413
+ }),
1414
+ note,
1415
+ ]),
1416
+ );
1417
+ }
1418
+
1419
+ return el("section", { class: "grimoire-card grimoire-fixnext" }, [el("h3", { text: "Fix next" }), ...body]);
1420
+ }
1421
+
1422
+ /** One criterion with one status pill and the tests behind it. */
1423
+ function proofRow(ctx, criterion, untracked) {
1424
+ const { el } = ctx;
1425
+ // Tagged tests with no results file read "tagged", not "not-run".
1426
+ const label = (status) => (untracked && status === "not-run" ? "tagged" : status);
1427
+ const tone = (status) => (untracked && status === "not-run" ? "" : toneOf(status));
1428
+
1429
+ return el("li", { class: "grimoire-proof", id: `grimoire-ac-${criterion.id}` }, [
1430
+ el("div", { class: "grimoire-proof-head" }, [
1431
+ mono(ctx, criterion.id),
1432
+ criterion.app ? pill(ctx, criterion.app) : "",
1433
+ pill(ctx, label(criterion.status), tone(criterion.status)),
1434
+ ]),
1435
+ el("p", { class: "grimoire-proof-text" }, codeText(ctx, criterion.text)),
1436
+ criterion.tests.length
1437
+ ? el(
1438
+ "ul",
1439
+ { class: "grimoire-proof-tests" },
1440
+ criterion.tests.map((test) =>
1441
+ el("li", {}, [
1442
+ fileLink(ctx, test.file),
1443
+ mono(ctx, `:${test.line}`),
1444
+ test.name ? el("span", {}, [" ", test.name]) : "",
1445
+ " ",
1446
+ pill(
1447
+ ctx,
1448
+ test.stale ? `${label(test.result)}, stale` : label(test.result),
1449
+ test.stale ? "warn" : tone(test.result),
1450
+ ),
1451
+ ]),
1452
+ ),
1453
+ )
1454
+ : "",
1455
+ ]);
1456
+ }
1457
+
1458
+ /** A flow's neighbours in the README order. */
1459
+ function neighbours(ctx, feature, data, className) {
1460
+ const make = (item, arrow) =>
1461
+ 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
+ })
1466
+ : "";
1467
+
1468
+ if (!data.previous && !data.next) return "";
1469
+
1470
+ return ctx.el("nav", { class: className, "aria-label": "Other flows of this feature" }, [
1471
+ make(data.previous, "prev"),
1472
+ make(data.next, "next"),
1473
+ ]);
1474
+ }
1475
+
915
1476
  async function flowView(ctx, feature, flowId) {
916
1477
  const data = await ctx.api(`flows/${encodeURIComponent(feature)}/${encodeURIComponent(flowId)}`);
917
1478
  const { el } = ctx;
918
1479
  const flow = data.flow;
919
1480
  const map = data.bookmap;
1481
+ const ref = `${feature}/${flowId}`;
920
1482
  const status = plain(flow.status);
921
- const out = el("div", { class: "grimoire-view" }, [
1483
+ const origin = flow.origin ? plain(flow.origin) : null;
1484
+ const title = plain(flow.heading) ?? plain(flow.id);
1485
+ const summary = plain(flow.summary) ?? null;
1486
+ const health = flowHealth(data);
1487
+ const results = data.results ?? null;
1488
+ const untracked = Boolean(results && results.recorded === false && results.proofs > 0);
1489
+ const apps = data.feature && data.feature.apps ? data.feature.apps : [];
1490
+ const problems = health.findings.errors + health.findings.warnings;
1491
+ const proven = health.criteria.proven;
1492
+ const total = health.criteria.total;
1493
+ const failing = health.criteria.byStatus.fail ?? 0;
1494
+ const out = el("div", { class: "grimoire-view grimoire-flow" }, [
1495
+ el("div", { class: "grimoire-minihead" }, [
1496
+ el("strong", { text: title }),
1497
+ pill(ctx, status, toneOf(status)),
1498
+ muted(ctx, `${proven}/${total} proven`),
1499
+ ]),
922
1500
  crumbs(ctx, [
923
1501
  ["Features", "features"],
924
- [feature, `feature/${encodeURIComponent(feature)}`],
925
- [`${plain(flow.heading) ?? plain(flow.id)}`],
1502
+ [(data.feature && data.feature.title) || feature, `feature/${encodeURIComponent(feature)}`],
1503
+ [title],
926
1504
  ]),
927
- heading(ctx, plain(flow.heading) ?? plain(flow.id), [
928
- mono(ctx, `${feature}/${flowId}`),
1505
+ heading(ctx, title, [
1506
+ mono(ctx, ref),
929
1507
  pill(ctx, status, toneOf(status)),
1508
+ origin ? pill(ctx, origin, toneOf(origin)) : "",
930
1509
  muted(ctx, `since ${plain(flow.since)}, for ${plain(flow.who)}`),
931
- link(ctx, `Back to ${feature}`, `feature/${encodeURIComponent(feature)}`),
1510
+ ...apps.map((app) => pill(ctx, app)),
1511
+ neighbours(ctx, feature, data, "grimoire-switcher"),
1512
+ ]),
1513
+ summary
1514
+ ? el("p", { class: "grimoire-lede" }, codeText(ctx, summary))
1515
+ : el("p", {
1516
+ class: "grimoire-muted",
1517
+ text: "No summary yet. Add one sentence under the title of the flow file.",
1518
+ }),
1519
+ el("div", { class: "grimoire-stats grimoire-health" }, [
1520
+ tile(ctx, {
1521
+ label: "Criteria proven",
1522
+ value: `${proven}/${total}`,
1523
+ sub: failing ? `${plural(failing, "criterion")} failing` : total ? "passing tests" : "none written",
1524
+ tone: failing ? "bad" : total && proven === total ? "good" : total ? "warn" : "",
1525
+ }),
1526
+ el("div", { class: "grimoire-stat" }, [
1527
+ el("span", { class: "grimoire-stat-label", text: "Last test run" }),
1528
+ el("span", {
1529
+ class: "grimoire-stat-value grimoire-stat-small",
1530
+ text: results && results.recorded && results.updatedAt ? results.updatedAt.slice(0, 10) : "none",
1531
+ }),
1532
+ el("span", {
1533
+ class: "grimoire-stat-sub",
1534
+ text: results && results.recorded ? "results recorded" : "no results recorded",
1535
+ }),
1536
+ ]),
1537
+ stat(ctx, {
1538
+ label: "Findings",
1539
+ value: problems,
1540
+ sub: `${plural(health.findings.errors, "error")}, ${plural(health.findings.warnings, "warning")}`,
1541
+ target: checkTarget({ flow: ref }),
1542
+ tone: health.findings.errors ? "bad" : problems ? "warn" : "good",
1543
+ }),
1544
+ el("div", { class: "grimoire-stat" }, [
1545
+ el("span", { class: "grimoire-stat-label", text: "Steps resolved" }),
1546
+ el("span", {
1547
+ class: "grimoire-stat-value",
1548
+ text: `${health.steps.resolved}/${health.steps.total}`,
1549
+ }),
1550
+ el("span", { class: "grimoire-stat-sub", text: "found in the book" }),
1551
+ ]),
932
1552
  ]),
933
1553
  ]);
934
1554
 
935
- out.append(
936
- section(ctx, "Steps", [
937
- map.steps.length
938
- ? table(
939
- ctx,
940
- ["#", "Type", "Target", "Found", "Files"],
941
- map.steps.map((step) => [
942
- [String(step.index)],
943
- [step.type],
944
- [
945
- step.type === "route" && step.target.includes(" ")
946
- ? routeLink(
947
- ctx,
948
- step.target.split(" ")[0],
949
- step.target.slice(step.target.indexOf(" ") + 1),
950
- )
951
- : step.target,
952
- ],
953
- [
954
- step.found === null
955
- ? ""
956
- : pill(ctx, step.found ? "yes" : "no", step.found ? "good" : "bad"),
957
- ],
958
- [step.files.length ? fileChips(ctx, step.files, 6) : ""],
959
- ]),
960
- )
961
- : ctx.empty("This flow has no steps."),
962
- ]),
963
- );
1555
+ if (untracked) {
1556
+ out.append(
1557
+ el("div", { class: "grimoire-note", role: "note" }, [
1558
+ el("strong", { text: "No test results recorded yet. " }),
1559
+ codeText(
1560
+ ctx,
1561
+ `${results.proofs} tagged ${results.proofs === 1 ? "test is" : "tests are"} waiting for a result. Add \`grimoireReporter()\` to the Vitest config and run the tests, or set the panel option \`testResultsFile\`. Looking in ${results.file}.`,
1562
+ ),
1563
+ ]),
1564
+ );
1565
+ }
964
1566
 
1567
+ out.append(fixNextBox(ctx, ref, fixNextCriterion(map.criteria)));
1568
+ out.append(section(ctx, "Journey", [journey(ctx, feature, flowId, flow, map.steps)]));
965
1569
  out.append(
966
- section(ctx, "Acceptance criteria", [
1570
+ section(ctx, "Proof", [
967
1571
  map.criteria.length
968
- ? table(
969
- ctx,
970
- ["Id", "App", "Criterion", "Result", "Tests"],
971
- map.criteria.map((criterion) => [
972
- [mono(ctx, criterion.id)],
973
- [criterion.app ?? "all"],
974
- [criterion.text],
975
- [pill(ctx, criterion.status, toneOf(criterion.status))],
976
- [
977
- criterion.tests.length
978
- ? list(
979
- ctx,
980
- criterion.tests.map((test) => [
981
- fileLink(ctx, test.file),
982
- `:${test.line} `,
983
- test.name ?? "",
984
- " ",
985
- pill(
986
- ctx,
987
- test.stale ? `${test.result}, stale` : test.result,
988
- test.stale ? "warn" : toneOf(test.result),
989
- ),
990
- ]),
991
- )
992
- : muted(ctx, "no test"),
993
- ],
994
- ]),
1572
+ ? el(
1573
+ "ul",
1574
+ { class: "grimoire-proofs" },
1575
+ map.criteria.map((criterion) => proofRow(ctx, criterion, untracked)),
995
1576
  )
996
1577
  : ctx.empty("No criteria written."),
997
1578
  ]),
998
1579
  );
999
1580
 
1000
- out.append(
1001
- section(ctx, "Shown by", [
1002
- map.shownBy.length
1003
- ? list(
1004
- ctx,
1005
- map.shownBy.map((shown) => [
1006
- shown.type === "layout"
1007
- ? `${shown.app} layout ${shown.id}`
1008
- : link(
1009
- ctx,
1010
- `${shown.app} ${shown.type} ${shown.id}`,
1011
- `page/${encodeURIComponent(shown.app)}/${encodeURIComponent(shown.id)}`,
1012
- ),
1013
- ` as block ${shown.block}`,
1014
- ]),
1015
- )
1016
- : ctx.empty("No app page shows this flow."),
1017
- ]),
1018
- );
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
+ }
1019
1591
 
1020
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
+ });
1609
+
1021
1610
  out.append(
1022
1611
  section(ctx, "Cases", [
1023
- table(
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
+ ),
1626
+ )
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
+ : "",
1641
+ ]),
1642
+ );
1643
+ }
1644
+
1645
+ if ((flow.notHandled ?? []).length) {
1646
+ out.append(
1647
+ section(ctx, "Not handled", [
1648
+ list(
1024
1649
  ctx,
1025
- ["Question", "Answer"],
1026
- flow.cases.map((item) => [
1027
- [item.question],
1028
- [item.doesNotApply ? `does not apply: ${item.answer}` : item.answer],
1029
- ]),
1650
+ flow.notHandled.map((item) => [el("strong", { text: item.name }), " ", codeText(ctx, item.text)]),
1030
1651
  ),
1031
1652
  ]),
1032
1653
  );
@@ -1037,14 +1658,39 @@ async function flowView(ctx, feature, flowId) {
1037
1658
  section(ctx, "Unknowns", [
1038
1659
  list(
1039
1660
  ctx,
1040
- flow.unknowns.map((item) => [item.text]),
1661
+ flow.unknowns.map((item) => [codeText(ctx, item.text)]),
1041
1662
  ),
1042
1663
  ]),
1043
1664
  );
1044
1665
  }
1045
1666
 
1667
+ 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
+ ]),
1685
+ );
1046
1686
  out.append(section(ctx, "History", [changesView(ctx, data.history)]));
1047
- if (data.findings.length) out.append(section(ctx, "Findings", [findingList(ctx, data.findings)]));
1687
+
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"));
1048
1694
  return out;
1049
1695
  }
1050
1696
 
@@ -1303,7 +1949,7 @@ async function appsView(ctx) {
1303
1949
  function taskCard(ctx, task) {
1304
1950
  return section(ctx, task.id, [
1305
1951
  facts(ctx, [
1306
- ["Title", task.title],
1952
+ ["Title", codeText(ctx, task.title)],
1307
1953
  ["Type", task.type],
1308
1954
  ["Status", pill(ctx, task.status, toneOf(task.status))],
1309
1955
  [
@@ -1369,8 +2015,12 @@ async function tasksView(ctx, only) {
1369
2015
  ctx,
1370
2016
  ["Task", "Title", "Type", "Status", "Feature", "Decision needed"],
1371
2017
  tasks.map((task) => [
1372
- [link(ctx, task.id, `task/${encodeURIComponent(task.id)}`)],
1373
- [task.title],
2018
+ [
2019
+ link(ctx, task.id, `task/${encodeURIComponent(task.id)}`, {
2020
+ class: "grimoire-nowrap",
2021
+ }),
2022
+ ],
2023
+ [codeText(ctx, task.title)],
1374
2024
  [task.type],
1375
2025
  [pill(ctx, task.status, toneOf(group))],
1376
2026
  [
@@ -1448,60 +2098,211 @@ async function releaseView(ctx, id) {
1448
2098
  ]);
1449
2099
  }
1450
2100
 
1451
- async function checkView(ctx) {
1452
- const report = await ctx.api("check");
2101
+ /** One link of a filter row; the active one is marked. */
2102
+ function filterLink(ctx, label, target, active) {
2103
+ return ctx.el("a", {
2104
+ href: ctx.href(target),
2105
+ class: active ? "grimoire-filter is-active" : "grimoire-filter",
2106
+ ...(active ? { "aria-current": "true" } : {}),
2107
+ text: label,
2108
+ });
2109
+ }
2110
+
2111
+ /** A select that opens the Check tab with one more filter set. */
2112
+ function filterSelect(ctx, label, key, options, query) {
2113
+ return ctx.el(
2114
+ "select",
2115
+ {
2116
+ class: "grimoire-sort",
2117
+ "aria-label": label,
2118
+ onchange: (event) => ctx.navigate(checkTarget({ ...query, [key]: event.target.value })),
2119
+ },
2120
+ [
2121
+ ctx.el("option", { value: "", text: `${label}: all` }),
2122
+ ...options.map((option) =>
2123
+ ctx.el("option", {
2124
+ value: option,
2125
+ text: option,
2126
+ ...(query[key] === option ? { selected: "selected" } : {}),
2127
+ }),
2128
+ ),
2129
+ ],
2130
+ );
2131
+ }
2132
+
2133
+ /** One code of the check: its title, the fix once, and its features with a count and "Show". */
2134
+ function checkGroupCard(ctx, group, mode, query) {
2135
+ const { el } = ctx;
2136
+ const count = mode === "expected" ? group.expected : group.count;
2137
+ const filter = { state: mode, ...(query.severity ? { severity: query.severity } : {}) };
2138
+ // Files no flow reaches are one finding per file: shown one row per feature, files on request.
2139
+ const perFeature = group.code === "GR3006";
2140
+ const features = group.features;
2141
+
2142
+ return el("section", { class: "grimoire-card grimoire-check-group" }, [
2143
+ el("header", { class: "grimoire-check-head" }, [
2144
+ pill(ctx, group.severity, mode === "expected" ? "" : toneOf(group.severity)),
2145
+ mono(ctx, group.code),
2146
+ el("h3", {}, codeText(ctx, group.title)),
2147
+ pill(ctx, String(count)),
2148
+ ]),
2149
+ group.fix ? el("p", { class: "grimoire-muted" }, codeText(ctx, group.fix)) : "",
2150
+ features.length
2151
+ ? el(
2152
+ "ul",
2153
+ { class: "grimoire-check-features" },
2154
+ features.map((item) => {
2155
+ const shown = expander(ctx, perFeature ? "Show files" : "Show", () =>
2156
+ pagedFindings(
2157
+ ctx,
2158
+ { ...filter, code: group.code, ...(item.feature === "(none)" ? {} : { feature: item.feature }) },
2159
+ { hints: false },
2160
+ ),
2161
+ );
2162
+
2163
+ return el("li", { class: "grimoire-check-feature" }, [
2164
+ el("div", { class: "grimoire-check-feature-row" }, [
2165
+ item.feature === "(none)"
2166
+ ? muted(ctx, "no feature")
2167
+ : link(
2168
+ ctx,
2169
+ item.feature,
2170
+ checkTarget({ ...filter, code: group.code, feature: item.feature }),
2171
+ ),
2172
+ pill(ctx, plural(item.count, perFeature ? "file" : "finding")),
2173
+ shown.button,
2174
+ ]),
2175
+ shown.panel,
2176
+ ]);
2177
+ }),
2178
+ )
2179
+ : "",
2180
+ perFeature
2181
+ ? ""
2182
+ : (() => {
2183
+ const all = expander(ctx, `Show all ${count}`, () =>
2184
+ pagedFindings(ctx, { ...filter, code: group.code }, { hints: false }),
2185
+ );
2186
+
2187
+ return el("div", {}, [all.button, all.panel]);
2188
+ })(),
2189
+ ]);
2190
+ }
2191
+
2192
+ async function checkView(ctx, query = {}) {
2193
+ const report = await ctx.api("check/groups");
1453
2194
  const { counts } = report;
1454
2195
  const { el } = ctx;
1455
- const items = report.findings.map((finding) => ({
1456
- finding,
1457
- state: finding.expected ? "expected" : finding.severity,
1458
- }));
2196
+ const groups = report.groups ?? [];
2197
+ const kinds = groups.filter((group) => group.count > 0).length;
2198
+ const expectedMode = query.state === "expected";
2199
+ const matches = (group) =>
2200
+ (!query.code || group.code === query.code) &&
2201
+ (!query.severity || group.severity === query.severity) &&
2202
+ (!query.feature || group.features.some((item) => item.feature === query.feature));
2203
+ const main = expectedMode ? [] : groups.filter((group) => group.count > 0 && matches(group));
2204
+ const expected = groups.filter(
2205
+ (group) => group.expected > 0 && (expectedMode || group.count === 0) && matches(group),
2206
+ );
2207
+ const flat = Boolean(query.flow || query.feature);
2208
+ const names = [...new Set(groups.flatMap((group) => group.features.map((item) => item.feature)))]
2209
+ .filter((name) => name !== "(none)")
2210
+ .sort();
2211
+ const active = ["code", "feature", "flow", "severity", "state"].filter((key) => query[key]);
1459
2212
 
1460
- return el("div", { class: "grimoire-view" }, [
1461
- heading(ctx, report.ok ? "Check: no unexpected errors" : "Check: errors found", [
1462
- pill(ctx, plural(counts.errors, "error"), counts.errors ? "bad" : "good"),
2213
+ const out = el("div", { class: "grimoire-view" }, [
2214
+ heading(ctx, "Check", [
2215
+ pill(ctx, `${plural(counts.errors, "error")}`, counts.errors ? "bad" : "good"),
1463
2216
  pill(ctx, plural(counts.warnings, "warning"), counts.warnings ? "warn" : ""),
1464
2217
  pill(ctx, `${counts.expected} expected`),
1465
- muted(ctx, `routes ${report.routes}`),
2218
+ muted(ctx, `routes ${report.routes ?? "cached"}`),
1466
2219
  ]),
1467
- items.length
1468
- ? listing(ctx, {
1469
- items,
1470
- noun: "findings",
1471
- textOf: ({ finding }) =>
1472
- [
1473
- finding.code,
1474
- finding.message,
1475
- finding.at?.file ?? "",
1476
- finding.subject.file ?? "",
1477
- finding.subject.feature ?? "",
1478
- ].join(" "),
1479
- statusOf: (item) => item.state,
1480
- statusOrder: ["error", "warning", "expected"],
1481
- render: (shown) => {
1482
- const fix = shown
1483
- .filter((item) => item.state !== "expected")
1484
- .map((item) => item.finding);
1485
- const expected = shown
1486
- .filter((item) => item.state === "expected")
1487
- .map((item) => item.finding);
1488
-
1489
- return el("div", { class: "grimoire-view-groups" }, [
1490
- fix.length ? section(ctx, `To fix (${fix.length})`, [findingList(ctx, fix)]) : "",
1491
- expected.length
1492
- ? section(ctx, `Expected: proposed work (${expected.length})`, [
1493
- el("p", {
1494
- class: "grimoire-muted",
1495
- text: "These concern features or flows that are still proposed, so the code does not exist yet. They never fail the check.",
1496
- }),
1497
- findingList(ctx, expected),
1498
- ])
1499
- : "",
1500
- ]);
1501
- },
1502
- })
1503
- : ctx.empty("No findings."),
2220
+ el("p", {
2221
+ class: "grimoire-headline",
2222
+ text: `${plural(counts.errors, "error")} · ${plural(counts.warnings, "warning")} in ${plural(kinds, "kind")}`,
2223
+ }),
2224
+ el("div", { class: "grimoire-toolbar grimoire-check-filters" }, [
2225
+ el("div", { class: "grimoire-filters", role: "group", "aria-label": "Severity" }, [
2226
+ 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"),
2229
+ ]),
2230
+ el("div", { class: "grimoire-filters", role: "group", "aria-label": "State" }, [
2231
+ filterLink(ctx, "to fix", checkTarget({ ...query, state: "" }), !query.state),
2232
+ filterLink(ctx, "expected", checkTarget({ ...query, state: "expected" }), expectedMode),
2233
+ ]),
2234
+ filterSelect(ctx, "Code", "code", groups.map((group) => group.code), query),
2235
+ filterSelect(ctx, "Feature", "feature", names, query),
2236
+ ]),
2237
+ active.some((key) => key === "code" || key === "feature" || key === "flow")
2238
+ ? el(
2239
+ "div",
2240
+ { class: "grimoire-chips" },
2241
+ ["code", "feature", "flow"]
2242
+ .filter((key) => query[key])
2243
+ .map((key) =>
2244
+ link(ctx, `${key}: ${query[key]} ×`, checkTarget({ ...query, [key]: "" }), {
2245
+ class: "grimoire-chip",
2246
+ title: `Clear the ${key} filter`,
2247
+ }),
2248
+ ),
2249
+ )
2250
+ : "",
1504
2251
  ]);
2252
+
2253
+ if (flat) {
2254
+ out.append(
2255
+ section(ctx, "Findings", [
2256
+ pagedFindings(
2257
+ ctx,
2258
+ {
2259
+ code: query.code,
2260
+ feature: query.feature,
2261
+ flow: query.flow,
2262
+ severity: query.severity,
2263
+ state: query.state ?? "unexpected",
2264
+ },
2265
+ { size: 50 },
2266
+ ),
2267
+ ]),
2268
+ );
2269
+ return out;
2270
+ }
2271
+
2272
+ if (!main.length && !expected.length) {
2273
+ out.append(
2274
+ ctx.empty(
2275
+ active.length
2276
+ ? "No findings match these filters. Clear a filter to see more."
2277
+ : "No findings. The written files and the code agree.",
2278
+ ),
2279
+ );
2280
+ return out;
2281
+ }
2282
+
2283
+ if (main.length) {
2284
+ out.append(
2285
+ el("div", { class: "grimoire-view-groups" }, [
2286
+ el("h3", { class: "grimoire-subhead", text: `To fix (${plural(main.length, "kind")})` }),
2287
+ ...main.map((group) => checkGroupCard(ctx, group, "unexpected", query)),
2288
+ ]),
2289
+ );
2290
+ }
2291
+
2292
+ if (expected.length) {
2293
+ out.append(
2294
+ el("div", { class: "grimoire-view-groups" }, [
2295
+ el("h3", { class: "grimoire-subhead", text: `Expected: proposed work (${plural(expected.length, "kind")})` }),
2296
+ el("p", {
2297
+ class: "grimoire-muted",
2298
+ text: "These concern features or flows that are still proposed, so the code does not exist yet. They never fail the check.",
2299
+ }),
2300
+ ...expected.map((group) => checkGroupCard(ctx, group, "expected", query)),
2301
+ ]),
2302
+ );
2303
+ }
2304
+
2305
+ return out;
1505
2306
  }
1506
2307
 
1507
2308
  async function fileView(ctx, path) {
@@ -1642,12 +2443,33 @@ async function modulesView(ctx) {
1642
2443
 
1643
2444
  // ── Shell ───────────────────────────────────────────────────────────────────
1644
2445
 
2446
+ /**
2447
+ * An asset URL `import()` accepts. A host may hand out a page-relative path
2448
+ * (`panels/grimoire/x.js`), which `import()` reads as a bare module specifier
2449
+ * and refuses; resolve it against the page first.
2450
+ */
2451
+ function moduleUrl(url) {
2452
+ const base = globalThis.document?.baseURI ?? globalThis.location?.href;
2453
+
2454
+ try {
2455
+ return base ? new URL(url, base).href : url;
2456
+ } catch {
2457
+ return url;
2458
+ }
2459
+ }
2460
+
1645
2461
  /** Pick the view for the hash route. */
1646
2462
  async function body(ctx, summaryRequest) {
1647
- const parts = ctx.route ? ctx.route.split("/").map(decodeSegment) : [];
2463
+ const { path, query } = parseRoute(ctx.route ?? "");
2464
+ const parts = path ? path.split("/").map(decodeSegment) : [];
1648
2465
  const [type = "", first = "", second = ""] = parts;
1649
2466
 
1650
2467
  switch (type) {
2468
+ case "product": {
2469
+ const map = globalThis.grimoireProductMap ?? (await import(/* @vite-ignore */ moduleUrl(ctx.asset("product-map.js"))));
2470
+
2471
+ return map.productMapView(ctx, parts.slice(1));
2472
+ }
1651
2473
  case "features":
1652
2474
  return featuresView(ctx);
1653
2475
  case "feature":
@@ -1667,7 +2489,7 @@ async function body(ctx, summaryRequest) {
1667
2489
  case "release":
1668
2490
  return releaseView(ctx, first);
1669
2491
  case "check":
1670
- return checkView(ctx);
2492
+ return checkView(ctx, query);
1671
2493
  case "file":
1672
2494
  return fileView(ctx, first);
1673
2495
  case "route":
@@ -1681,8 +2503,9 @@ async function body(ctx, summaryRequest) {
1681
2503
 
1682
2504
  /** What the view is about, for error messages, and the list to go back to. */
1683
2505
  function describe(route) {
1684
- const type = route.split("/")[0] ?? "";
2506
+ const type = (route.split("?")[0] ?? "").split("/")[0] ?? "";
1685
2507
  const map = {
2508
+ product: ["the product map", null],
1686
2509
  features: ["the features", null],
1687
2510
  feature: ["the feature", ["Features", "features"]],
1688
2511
  flow: ["the flow", ["Features", "features"]],
@@ -1782,6 +2605,7 @@ function header(ctx, route, summaryRequest) {
1782
2605
  const results = el("div", { class: "grimoire-results" });
1783
2606
  const active = tabOf(route);
1784
2607
  const badges = new Map();
2608
+ let activeTab = null;
1785
2609
  let token = 0;
1786
2610
  let timer = null;
1787
2611
  let rows = [];
@@ -1933,7 +2757,8 @@ function header(ctx, route, summaryRequest) {
1933
2757
  const badge = el("span", { class: "grimoire-tab-count" });
1934
2758
 
1935
2759
  badges.set(target, badge);
1936
- return el(
2760
+
2761
+ const tab = el(
1937
2762
  "a",
1938
2763
  {
1939
2764
  href: ctx.href(target),
@@ -1942,6 +2767,10 @@ function header(ctx, route, summaryRequest) {
1942
2767
  },
1943
2768
  [label, " ", badge],
1944
2769
  );
2770
+
2771
+ if (target === active) activeTab = tab;
2772
+
2773
+ return tab;
1945
2774
  }),
1946
2775
  );
1947
2776
 
@@ -1970,6 +2799,14 @@ function header(ctx, route, summaryRequest) {
1970
2799
  ]),
1971
2800
  run,
1972
2801
  input,
2802
+ /** Bring the open tab into view in a scrolling tab bar (phones). */
2803
+ revealActive: () => {
2804
+ try {
2805
+ activeTab?.scrollIntoView?.({ inline: "center", block: "nearest" });
2806
+ } catch {
2807
+ // A host without scrollIntoView options keeps the bar where it is.
2808
+ }
2809
+ },
1973
2810
  };
1974
2811
  }
1975
2812
 
@@ -2002,6 +2839,7 @@ async function renderGrimoire(context) {
2002
2839
 
2003
2840
  content.append(skeleton(ctx));
2004
2841
  root.append(el("div", { class: "grimoire-root" }, [top.element, content]));
2842
+ top.revealActive();
2005
2843
 
2006
2844
  const loaded = (async () => {
2007
2845
  try {