@warlock.js/grimoire 5.63.1 → 5.64.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 (194) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/esm/book/build.d.mts.map +1 -1
  3. package/esm/book/build.mjs +24 -2
  4. package/esm/book/build.mjs.map +1 -1
  5. package/esm/check/check-grimoire.d.mts.map +1 -1
  6. package/esm/check/check-grimoire.mjs +11 -1
  7. package/esm/check/check-grimoire.mjs.map +1 -1
  8. package/esm/check/rules/api-snapshot.mjs +39 -0
  9. package/esm/check/rules/api-snapshot.mjs.map +1 -0
  10. package/esm/check/rules/code-rules.mjs +45 -0
  11. package/esm/check/rules/code-rules.mjs.map +1 -0
  12. package/esm/check/rules/drift.mjs +54 -0
  13. package/esm/check/rules/drift.mjs.map +1 -0
  14. package/esm/check/rules/focused-tests.mjs +39 -0
  15. package/esm/check/rules/focused-tests.mjs.map +1 -0
  16. package/esm/check/rules/shows.mjs +52 -0
  17. package/esm/check/rules/shows.mjs.map +1 -0
  18. package/esm/codes/codes.d.mts +48 -0
  19. package/esm/codes/codes.d.mts.map +1 -1
  20. package/esm/codes/codes.mjs +26 -1
  21. package/esm/codes/codes.mjs.map +1 -1
  22. package/esm/contracts/adapter.d.mts +6 -0
  23. package/esm/contracts/adapter.d.mts.map +1 -1
  24. package/esm/contracts/guard.d.mts +104 -0
  25. package/esm/contracts/guard.d.mts.map +1 -0
  26. package/esm/contracts/index.mjs +5 -0
  27. package/esm/contracts/matrix.d.mts +75 -0
  28. package/esm/contracts/matrix.d.mts.map +1 -0
  29. package/esm/contracts/scry.d.mts +21 -0
  30. package/esm/contracts/scry.d.mts.map +1 -1
  31. package/esm/contracts/settings.d.mts +71 -0
  32. package/esm/contracts/settings.d.mts.map +1 -0
  33. package/esm/contracts/settings.mjs +67 -0
  34. package/esm/contracts/settings.mjs.map +1 -0
  35. package/esm/contracts/shots.d.mts +146 -0
  36. package/esm/contracts/shots.d.mts.map +1 -0
  37. package/esm/contracts/snapshot.d.mts +10 -0
  38. package/esm/contracts/snapshot.d.mts.map +1 -1
  39. package/esm/contracts/written.d.mts +13 -0
  40. package/esm/contracts/written.d.mts.map +1 -1
  41. package/esm/contracts/written.mjs +7 -1
  42. package/esm/contracts/written.mjs.map +1 -1
  43. package/esm/devtools/approvals.mjs +59 -0
  44. package/esm/devtools/approvals.mjs.map +1 -0
  45. package/esm/devtools/data.mjs +2 -0
  46. package/esm/devtools/data.mjs.map +1 -1
  47. package/esm/devtools/graphs.mjs +13 -3
  48. package/esm/devtools/graphs.mjs.map +1 -1
  49. package/esm/devtools/index.d.mts.map +1 -1
  50. package/esm/devtools/index.mjs +32 -2
  51. package/esm/devtools/index.mjs.map +1 -1
  52. package/esm/devtools/matrix.mjs +207 -0
  53. package/esm/devtools/matrix.mjs.map +1 -0
  54. package/esm/devtools/product-map.d.mts.map +1 -1
  55. package/esm/devtools/product-map.mjs +87 -1
  56. package/esm/devtools/product-map.mjs.map +1 -1
  57. package/esm/devtools/site.d.mts.map +1 -1
  58. package/esm/devtools/site.mjs +12 -3
  59. package/esm/devtools/site.mjs.map +1 -1
  60. package/esm/devtools/snapshot-source.mjs +5 -1
  61. package/esm/devtools/snapshot-source.mjs.map +1 -1
  62. package/esm/git/index.d.mts +20 -0
  63. package/esm/git/index.d.mts.map +1 -0
  64. package/esm/git/index.mjs +280 -0
  65. package/esm/git/index.mjs.map +1 -0
  66. package/esm/guard/api.mjs +70 -0
  67. package/esm/guard/api.mjs.map +1 -0
  68. package/esm/guard/assertions.mjs +18 -0
  69. package/esm/guard/assertions.mjs.map +1 -0
  70. package/esm/guard/collect.mjs +139 -0
  71. package/esm/guard/collect.mjs.map +1 -0
  72. package/esm/guard/format.mjs +27 -0
  73. package/esm/guard/format.mjs.map +1 -0
  74. package/esm/guard/glob.mjs +79 -0
  75. package/esm/guard/glob.mjs.map +1 -0
  76. package/esm/guard/index.mjs +9 -0
  77. package/esm/guard/rules.mjs +310 -0
  78. package/esm/guard/rules.mjs.map +1 -0
  79. package/esm/guard/scope.mjs +95 -0
  80. package/esm/guard/scope.mjs.map +1 -0
  81. package/esm/index.d.mts +10 -3
  82. package/esm/index.mjs +6 -2
  83. package/esm/paths/index.d.mts +15 -1
  84. package/esm/paths/index.d.mts.map +1 -1
  85. package/esm/paths/index.mjs +27 -3
  86. package/esm/paths/index.mjs.map +1 -1
  87. package/esm/proves/index.mjs +2 -1
  88. package/esm/proves/scan-proofs.mjs +1 -1
  89. package/esm/proves/scan-proofs.mjs.map +1 -1
  90. package/esm/proves/scan-shows.d.mts +21 -0
  91. package/esm/proves/scan-shows.d.mts.map +1 -0
  92. package/esm/proves/scan-shows.mjs +168 -0
  93. package/esm/proves/scan-shows.mjs.map +1 -0
  94. package/esm/releases/index.d.mts.map +1 -1
  95. package/esm/releases/index.mjs +5 -3
  96. package/esm/releases/index.mjs.map +1 -1
  97. package/esm/releases/stamp.mjs +121 -0
  98. package/esm/releases/stamp.mjs.map +1 -0
  99. package/esm/rules/focused.mjs +26 -0
  100. package/esm/rules/focused.mjs.map +1 -0
  101. package/esm/rules/index.mjs +88 -0
  102. package/esm/rules/index.mjs.map +1 -0
  103. package/esm/rules/logical-css.mjs +112 -0
  104. package/esm/rules/logical-css.mjs.map +1 -0
  105. package/esm/rules/no-js-imports.mjs +22 -0
  106. package/esm/rules/no-js-imports.mjs.map +1 -0
  107. package/esm/rules/scan.mjs +196 -0
  108. package/esm/rules/scan.mjs.map +1 -0
  109. package/esm/rules/specific-errors.mjs +51 -0
  110. package/esm/rules/specific-errors.mjs.map +1 -0
  111. package/esm/rules/type-discriminator.mjs +27 -0
  112. package/esm/rules/type-discriminator.mjs.map +1 -0
  113. package/esm/scry/also-changes.mjs +106 -0
  114. package/esm/scry/also-changes.mjs.map +1 -0
  115. package/esm/scry/format.d.mts.map +1 -1
  116. package/esm/scry/format.mjs +22 -0
  117. package/esm/scry/format.mjs.map +1 -1
  118. package/esm/scry/query.d.mts.map +1 -1
  119. package/esm/scry/query.mjs +7 -2
  120. package/esm/scry/query.mjs.map +1 -1
  121. package/esm/scry/search.d.mts.map +1 -1
  122. package/esm/scry/search.mjs +43 -11
  123. package/esm/scry/search.mjs.map +1 -1
  124. package/esm/shots/approve.mjs +195 -0
  125. package/esm/shots/approve.mjs.map +1 -0
  126. package/esm/shots/drift.mjs +174 -0
  127. package/esm/shots/drift.mjs.map +1 -0
  128. package/esm/shots/png.mjs +166 -0
  129. package/esm/shots/png.mjs.map +1 -0
  130. package/esm/shots/state.mjs +43 -0
  131. package/esm/shots/state.mjs.map +1 -0
  132. package/esm/shots/store.mjs +66 -0
  133. package/esm/shots/store.mjs.map +1 -0
  134. package/esm/shots/touched.mjs +38 -0
  135. package/esm/shots/touched.mjs.map +1 -0
  136. package/esm/warlock/adapter.d.mts.map +1 -1
  137. package/esm/warlock/adapter.mjs +15 -2
  138. package/esm/warlock/adapter.mjs.map +1 -1
  139. package/esm/warlock/api-command.mjs +41 -0
  140. package/esm/warlock/api-command.mjs.map +1 -0
  141. package/esm/warlock/approve-command.mjs +80 -0
  142. package/esm/warlock/approve-command.mjs.map +1 -0
  143. package/esm/warlock/commands.d.mts +1 -1
  144. package/esm/warlock/commands.d.mts.map +1 -1
  145. package/esm/warlock/commands.mjs +61 -8
  146. package/esm/warlock/commands.mjs.map +1 -1
  147. package/esm/warlock/guard-command.mjs +116 -0
  148. package/esm/warlock/guard-command.mjs.map +1 -0
  149. package/esm/warlock/index.d.mts +2 -1
  150. package/esm/warlock/index.mjs +2 -1
  151. package/esm/warlock/languages.mjs +75 -0
  152. package/esm/warlock/languages.mjs.map +1 -0
  153. package/esm/warlock/mcp-tools.mjs +2 -2
  154. package/esm/warlock/mcp-tools.mjs.map +1 -1
  155. package/esm/warlock/release-command.mjs +65 -0
  156. package/esm/warlock/release-command.mjs.map +1 -0
  157. package/esm/warlock/shows.d.mts +35 -0
  158. package/esm/warlock/shows.d.mts.map +1 -0
  159. package/esm/warlock/shows.mjs +195 -0
  160. package/esm/warlock/shows.mjs.map +1 -0
  161. package/esm/workspace/cache.mjs +4 -1
  162. package/esm/workspace/cache.mjs.map +1 -1
  163. package/esm/workspace/derived.mjs +11 -6
  164. package/esm/workspace/derived.mjs.map +1 -1
  165. package/esm/workspace/index.d.mts.map +1 -1
  166. package/esm/workspace/index.mjs +8 -1
  167. package/esm/workspace/index.mjs.map +1 -1
  168. package/esm/workspace/stored.mjs +4 -1
  169. package/esm/workspace/stored.mjs.map +1 -1
  170. package/esm/written/features.mjs +21 -5
  171. package/esm/written/features.mjs.map +1 -1
  172. package/esm/written/index.mjs +2 -1
  173. package/esm/written/parse-grimoire.d.mts.map +1 -1
  174. package/esm/written/parse-grimoire.mjs +16 -3
  175. package/esm/written/parse-grimoire.mjs.map +1 -1
  176. package/esm/written/settings.d.mts +11 -0
  177. package/esm/written/settings.d.mts.map +1 -0
  178. package/esm/written/settings.mjs +88 -0
  179. package/esm/written/settings.mjs.map +1 -0
  180. package/llms-full.txt +276 -39
  181. package/llms.txt +2 -0
  182. package/package.json +3 -3
  183. package/skills/backfill-a-grimoire/SKILL.md +4 -0
  184. package/skills/describe-an-app/SKILL.md +4 -1
  185. package/skills/guard-a-change/SKILL.md +85 -0
  186. package/skills/index.md +7 -3
  187. package/skills/record-a-change/SKILL.md +52 -16
  188. package/skills/review-a-change/SKILL.md +53 -0
  189. package/skills/use-the-grimoire/SKILL.md +21 -18
  190. package/skills/write-a-feature/SKILL.md +42 -1
  191. package/ui/grimoire-view.js +756 -40
  192. package/ui/grimoire.css +303 -28
  193. package/ui/product-map.css +43 -7
  194. package/ui/product-map.js +212 -37
@@ -10,6 +10,7 @@
10
10
  /** The tabs: `[route, label]`. */
11
11
  const TABS = [
12
12
  ["product", "Product map"],
13
+ ["bird-view", "Bird view"],
13
14
  ["", "Overview"],
14
15
  ["features", "Features"],
15
16
  ["apps", "Apps"],
@@ -19,6 +20,9 @@ const TABS = [
19
20
  ["modules", "Modules"],
20
21
  ];
21
22
 
23
+ /** An app group with more pages than this starts closed on the Apps page. */
24
+ const APP_GROUP_OPEN_LIMIT = 6;
25
+
22
26
  const SVG_WIDTH = 720;
23
27
  const SVG_HEIGHT = 440;
24
28
 
@@ -52,6 +56,8 @@ function tabOf(route) {
52
56
  switch (type) {
53
57
  case "product":
54
58
  return "product";
59
+ case "bird-view":
60
+ return "bird-view";
55
61
  case "features":
56
62
  case "feature":
57
63
  case "flow":
@@ -134,6 +140,11 @@ function shorten(text, max = 26) {
134
140
  return text.length > max ? `…${text.slice(text.length - max + 1)}` : text;
135
141
  }
136
142
 
143
+ /** Cut a long label from the end, so the start of a name stays readable. The full name is in the node's `<title>`. */
144
+ function shortenEnd(text, max = 16) {
145
+ return text.length > max ? `${text.slice(0, max - 1)}…` : text;
146
+ }
147
+
137
148
  const NODE_COLOURS = {
138
149
  center: "var(--brand)",
139
150
  feature: "var(--chart-2)",
@@ -802,11 +813,18 @@ function graphView(ctx, graph, title) {
802
813
 
803
814
  if (centre) place.set(centre.id, [middleX, middleY]);
804
815
 
816
+ // Module graph: sites, mobile and other roots sit on an inner ring, the `src/app` modules on the outer one.
817
+ const roots = centre ? [] : others.filter((node) => node.group === "roots");
818
+ const apart = roots.length > 0 && roots.length < others.length;
805
819
  const inner = centre ? Math.min(others.length, 18) : 0;
806
- const rings = centre ? [others.slice(0, inner), others.slice(inner)] : [others, []];
820
+ const rings = centre
821
+ ? [others.slice(0, inner), others.slice(inner)]
822
+ : apart
823
+ ? [roots, others.filter((node) => node.group !== "roots")]
824
+ : [others, []];
807
825
  rings.forEach((ring, index) => {
808
- const radiusX = centre ? (index === 0 ? 210 : 320) : 300;
809
- const radiusY = centre ? (index === 0 ? 150 : 195) : 185;
826
+ const radiusX = centre ? (index === 0 ? 210 : 320) : apart ? (index === 0 ? 120 : 310) : 300;
827
+ const radiusY = centre ? (index === 0 ? 150 : 195) : apart ? (index === 0 ? 85 : 190) : 185;
810
828
  ring.forEach((node, position) => {
811
829
  const angle =
812
830
  (position / Math.max(ring.length, 1)) * 2 * Math.PI - Math.PI / 2 + index * 0.15;
@@ -860,13 +878,16 @@ function graphView(ctx, graph, title) {
860
878
  "text-anchor": "middle",
861
879
  fill: "var(--foreground)",
862
880
  "font-size": "11",
863
- text: shorten(node.label, node.type === "center" ? 26 : 16),
881
+ text:
882
+ node.type === "module"
883
+ ? shortenEnd(node.label, 16)
884
+ : shorten(node.label, node.type === "center" ? 26 : 16),
864
885
  });
865
886
  const group = svg(
866
887
  "g",
867
888
  {},
868
889
  [
869
- svg("title", { text: node.label }),
890
+ svg("title", { text: node.title ?? node.label }),
870
891
  circle,
871
892
  labelled || node.type === "center" ? label : "",
872
893
  ].filter((child) => child !== ""),
@@ -875,6 +896,14 @@ function graphView(ctx, graph, title) {
875
896
  }
876
897
 
877
898
  card.append(el("div", { class: "grimoire-scroll" }, [canvas]));
899
+ if (apart) {
900
+ card.append(
901
+ el("p", {
902
+ class: "grimoire-muted",
903
+ text: "Inner ring: sites, mobile and other roots. Outer ring: modules under src/app.",
904
+ }),
905
+ );
906
+ }
878
907
  if (!labelled) {
879
908
  card.append(
880
909
  el("p", {
@@ -920,8 +949,9 @@ async function overviewView(ctx, summaryRequest) {
920
949
  .sort(([a], [b]) => STATUS_ORDER.indexOf(a) - STATUS_ORDER.indexOf(b))
921
950
  .map(([status, total]) => `${total} ${status}`)
922
951
  .join(", ");
952
+ // `waiting` is the part of `open` that waits for the owner, so the tile counts the same tasks as the tab badge.
923
953
  const waiting = data.tasks.waiting.length;
924
- const open = data.tasks.open.length - waiting;
954
+ const open = data.tasks.open.length;
925
955
  const routeFacts = routeFactsState(data.routes);
926
956
  const stale = routeFacts.stale;
927
957
  const out = el("div", { class: "grimoire-view" });
@@ -945,7 +975,7 @@ async function overviewView(ctx, summaryRequest) {
945
975
  stat(ctx, {
946
976
  label: "Tasks",
947
977
  value: open,
948
- sub: `${open} open, ${waiting} waiting, ${data.tasks.done.length} done`,
978
+ sub: `${open} open, ${waiting} of them waiting for approval; ${data.tasks.done.length} done`,
949
979
  target: "tasks",
950
980
  tone: waiting ? "warn" : "",
951
981
  }),
@@ -1760,6 +1790,9 @@ async function featureView(ctx, id, tab = "") {
1760
1790
 
1761
1791
  box.append(featureHealthStrip(ctx, featureId, data, unexpected));
1762
1792
  box.append(section(ctx, "Feature map", [featureMapView(ctx, featureId, data.map)]));
1793
+
1794
+ if (graph) box.append(graphView(ctx, graph, "The feature and its neighbours"));
1795
+
1763
1796
  box.append(
1764
1797
  section(ctx, "Flows", [
1765
1798
  data.flows.length
@@ -1772,8 +1805,6 @@ async function featureView(ctx, id, tab = "") {
1772
1805
  ]),
1773
1806
  );
1774
1807
 
1775
- if (graph) box.append(graphView(ctx, graph, "The feature and its neighbours"));
1776
-
1777
1808
  if (data.tasks.length) {
1778
1809
  box.append(
1779
1810
  section(ctx, "Open tasks", [
@@ -2733,34 +2764,45 @@ async function appsView(ctx) {
2733
2764
  ? [...groups.entries()]
2734
2765
  .sort(([a], [b]) => (a === "" ? -1 : b === "" ? 1 : a.localeCompare(b)))
2735
2766
  .map(([name, group]) =>
2736
- el("div", { class: "grimoire-group" }, [
2737
- el("h4", { text: `${name ? `/${name}` : "Top level"} (${group.length})` }),
2738
- table(
2739
- ctx,
2740
- ["Page", "Route or screen", "Title", "Layout", "Blocks", "Status"],
2741
- [...group]
2742
- .sort((a, b) => (a.route ?? a.id).localeCompare(b.route ?? b.id))
2743
- .map((row) => [
2744
- [
2745
- link(
2746
- ctx,
2747
- row.id,
2748
- `page/${encodeURIComponent(app.id)}/${encodeURIComponent(row.id)}`,
2749
- ),
2750
- row.type === "screen" ? [" ", pill(ctx, "screen")] : "",
2751
- ],
2752
- [row.route ? mono(ctx, row.route) : ""],
2753
- [row.heading ?? ""],
2754
- [row.layout ?? ""],
2755
- [row.blocks === null ? "" : String(row.blocks)],
2756
- [
2757
- row.origin
2758
- ? pill(ctx, row.origin, toneOf(row.origin))
2759
- : muted(ctx, "unmarked"),
2760
- ],
2761
- ]),
2762
- ),
2763
- ]),
2767
+ // A big group starts closed, so a phone does not open on a wall of tables; a filter opens them all.
2768
+ el(
2769
+ "details",
2770
+ {
2771
+ class: "grimoire-group grimoire-app-group",
2772
+ ...(group.length <= APP_GROUP_OPEN_LIMIT || filtered ? { open: "" } : {}),
2773
+ },
2774
+ [
2775
+ el("summary", {
2776
+ class: "grimoire-app-group-title",
2777
+ text: `${name ? `/${name}` : "Top level"} (${group.length})`,
2778
+ }),
2779
+ table(
2780
+ ctx,
2781
+ ["Page", "Route or screen", "Title", "Layout", "Blocks", "Status"],
2782
+ [...group]
2783
+ .sort((a, b) => (a.route ?? a.id).localeCompare(b.route ?? b.id))
2784
+ .map((row) => [
2785
+ [
2786
+ link(
2787
+ ctx,
2788
+ row.id,
2789
+ `page/${encodeURIComponent(app.id)}/${encodeURIComponent(row.id)}`,
2790
+ ),
2791
+ row.type === "screen" ? [" ", pill(ctx, "screen")] : "",
2792
+ ],
2793
+ [row.route ? mono(ctx, row.route) : ""],
2794
+ [row.heading ?? ""],
2795
+ [row.layout ?? ""],
2796
+ [row.blocks === null ? "" : String(row.blocks)],
2797
+ [
2798
+ row.origin
2799
+ ? pill(ctx, row.origin, toneOf(row.origin))
2800
+ : muted(ctx, "unmarked"),
2801
+ ],
2802
+ ]),
2803
+ ),
2804
+ ],
2805
+ ),
2764
2806
  )
2765
2807
  : ctx.empty("No pages written."),
2766
2808
  ]);
@@ -3294,6 +3336,76 @@ async function routeView(ctx, method, path) {
3294
3336
  return out;
3295
3337
  }
3296
3338
 
3339
+ /** More modules than this and the default view is the matrix, not the graph. */
3340
+ const MODULES_GRAPH_LIMIT = 40;
3341
+ /** How many of the most connected modules the matrix shows. */
3342
+ const MODULES_MATRIX_SIZE = 20;
3343
+
3344
+ /** Import counts between the most connected modules: rows import, columns are imported. */
3345
+ function modulesMatrix(ctx, graph, weight) {
3346
+ const { el } = ctx;
3347
+ const top = [...graph.nodes]
3348
+ .sort(
3349
+ (left, right) =>
3350
+ (weight.get(right.id) ?? 0) - (weight.get(left.id) ?? 0) ||
3351
+ (left.title ?? left.label).localeCompare(right.title ?? right.label),
3352
+ )
3353
+ .slice(0, MODULES_MATRIX_SIZE);
3354
+ const ids = new Set(top.map((node) => node.id));
3355
+ const counts = new Map();
3356
+ let biggest = 1;
3357
+
3358
+ for (const edge of graph.edges) {
3359
+ if (!ids.has(edge.from) || !ids.has(edge.to)) continue;
3360
+
3361
+ const value = edge.weight ?? 1;
3362
+
3363
+ counts.set(`${edge.from}\n${edge.to}`, value);
3364
+ biggest = Math.max(biggest, value);
3365
+ }
3366
+
3367
+ const name = (node) => node.title ?? node.label;
3368
+
3369
+ return el("div", { class: "grimoire-card grimoire-modmatrix" }, [
3370
+ el("h3", { text: `The ${top.length} most connected modules` }),
3371
+ el("p", {
3372
+ class: "grimoire-muted",
3373
+ text: "Each cell counts the imports from the module on its row to the module in its column. Point at a name for its full path.",
3374
+ }),
3375
+ el("div", { class: "grimoire-scroll" }, [
3376
+ el("table", { class: "grimoire-table grimoire-modmatrix-table" }, [
3377
+ el("thead", {}, [
3378
+ el("tr", {}, [
3379
+ el("th", { scope: "col", text: "From / to" }),
3380
+ ...top.map((node) =>
3381
+ el("th", { scope: "col", title: name(node), text: shortenEnd(node.label, 10) }),
3382
+ ),
3383
+ ]),
3384
+ ]),
3385
+ el(
3386
+ "tbody",
3387
+ {},
3388
+ top.map((row) =>
3389
+ el("tr", {}, [
3390
+ el("th", { scope: "row", title: name(row), text: shortenEnd(row.label, 24) }),
3391
+ ...top.map((column) => {
3392
+ const value = counts.get(`${row.id}\n${column.id}`) ?? 0;
3393
+
3394
+ return el("td", {
3395
+ class: value ? "grimoire-modmatrix-cell has-imports" : "grimoire-modmatrix-cell",
3396
+ title: `${name(row)} imports ${name(column)} ${plural(value, "time")}`,
3397
+ style: value ? `--gm-level:${Math.round(10 + (value / biggest) * 60)}%` : null,
3398
+ text: value ? String(value) : "",
3399
+ });
3400
+ }),
3401
+ ]),
3402
+ ),
3403
+ ),
3404
+ ]),
3405
+ ]),
3406
+ ]);
3407
+ }
3408
+
3297
3409
  async function modulesView(ctx) {
3298
3410
  const graph = await ctx.api("graph/modules");
3299
3411
  const { el } = ctx;
@@ -3304,15 +3416,60 @@ async function modulesView(ctx) {
3304
3416
  weight.set(end, (weight.get(end) ?? 0) + (edge.weight ?? 1));
3305
3417
  }
3306
3418
 
3307
- const items = graph.nodes.map((node) => ({ label: node.label, links: weight.get(node.id) ?? 0 }));
3419
+ const items = graph.nodes.map((node) => ({
3420
+ label: node.title ?? node.label,
3421
+ links: weight.get(node.id) ?? 0,
3422
+ }));
3423
+ const big = graph.nodes.length > MODULES_GRAPH_LIMIT;
3424
+ const holder = el("div", { class: "grimoire-modview" });
3425
+ let mode = big ? "matrix" : "graph";
3426
+
3427
+ const toggle = el("div", { class: "grimoire-modtoggle", role: "group", "aria-label": "View" });
3428
+ const buttons = new Map();
3429
+
3430
+ function show(next) {
3431
+ mode = next;
3432
+ holder.replaceChildren(
3433
+ mode === "matrix" ? modulesMatrix(ctx, graph, weight) : graphView(ctx, graph, "Modules"),
3434
+ );
3435
+
3436
+ for (const [key, button] of buttons) {
3437
+ button.setAttribute("aria-pressed", String(key === mode));
3438
+ button.setAttribute(
3439
+ "class",
3440
+ key === mode ? "grimoire-bird-button is-primary" : "grimoire-bird-button",
3441
+ );
3442
+ }
3443
+ }
3444
+
3445
+ if (big) {
3446
+ for (const [key, label] of [
3447
+ ["matrix", "Matrix"],
3448
+ ["graph", "Graph"],
3449
+ ]) {
3450
+ const button = el("button", {
3451
+ type: "button",
3452
+ text: label,
3453
+ onclick: () => show(key),
3454
+ });
3455
+
3456
+ buttons.set(key, button);
3457
+ toggle.append(button);
3458
+ }
3459
+ }
3460
+
3461
+ show(mode);
3308
3462
 
3309
3463
  return el("div", { class: "grimoire-view" }, [
3310
3464
  heading(ctx, "Module coupling"),
3311
3465
  el("p", {
3312
3466
  class: "grimoire-muted",
3313
- text: "Lines are imports between modules; thicker means more imports. The most connected modules are drawn.",
3467
+ text: big
3468
+ ? `Imports between modules. There are ${graph.nodes.length} modules, so the matrix of the most connected ones opens first; the graph is one click away.`
3469
+ : "Lines are imports between modules; thicker means more imports. The most connected modules are drawn.",
3314
3470
  }),
3315
- graphView(ctx, graph, "Modules"),
3471
+ big ? toggle : "",
3472
+ holder,
3316
3473
  items.length
3317
3474
  ? listing(ctx, {
3318
3475
  items,
@@ -3339,6 +3496,561 @@ async function modulesView(ctx) {
3339
3496
  ]);
3340
3497
  }
3341
3498
 
3499
+ // ── Bird view ───────────────────────────────────────────────────────────────
3500
+
3501
+ /** The words, glyph and tone of a cell state. A colour is never the only signal: every cell prints its words. */
3502
+ const BIRD_STATES = {
3503
+ rejected: { label: "Rejected", glyph: "✕", tone: "bad" },
3504
+ fail: { label: "Failing", glyph: "✕", tone: "bad" },
3505
+ changed: { label: "Changed, not approved", glyph: "≠", tone: "warn" },
3506
+ stale: { label: "Needs a new run", glyph: "!", tone: "warn" },
3507
+ "not-run": { label: "Not run yet", glyph: "…", tone: "warn" },
3508
+ "no-test": { label: "No test", glyph: "–", tone: "" },
3509
+ pass: { label: "Passing", glyph: "✓", tone: "good" },
3510
+ };
3511
+
3512
+ const BIRD_STATE_ORDER = ["rejected", "fail", "changed", "stale", "not-run", "no-test", "pass"];
3513
+
3514
+ /** The target the Approve all button sends when there is no baseline yet (the baseline is created from the current state). */
3515
+ const BIRD_APPROVE_ALL = "all";
3516
+
3517
+ /** What an Approve or Reject failure says: the server's message, its status and reference, and what to do next. */
3518
+ function birdFailure(verb, failure) {
3519
+ const details = [
3520
+ failure?.status ? `status ${failure.status}` : "",
3521
+ failure?.ref ? `reference ${failure.ref}` : "",
3522
+ ].filter(Boolean);
3523
+
3524
+ return `Could not ${verb}: ${failure?.message ?? "the server did not answer"}${
3525
+ details.length ? ` (${details.join(", ")})` : ""
3526
+ }. Nothing was changed. Try again, or run warlock grimoire ${verb} in a terminal.`;
3527
+ }
3528
+
3529
+ /** What a drift item says, in plain words. */
3530
+ const BIRD_DRIFT_WORDS = {
3531
+ "shot-changed": "The screenshot changed",
3532
+ "shot-added": "A new screenshot was captured",
3533
+ "shot-removed": "The screenshot is no longer captured",
3534
+ "flow-added": "The flow is new",
3535
+ "flow-removed": "The flow was removed",
3536
+ "criterion-added": "A criterion was added",
3537
+ "criterion-removed": "A criterion was removed",
3538
+ "criterion-changed": "The criterion text changed",
3539
+ "case-added": "A case was added",
3540
+ "case-removed": "A case was removed",
3541
+ "proof-removed": "A proving test was removed",
3542
+ };
3543
+
3544
+ /** Whether a path is a plain image path inside the screenshots folder (no scheme, no `..`), so `ctx.file()` cannot leave it. */
3545
+ function birdShotPath(src) {
3546
+ if (typeof src !== "string" || src === "" || src.startsWith("/") || /[\\:\0?#]/.test(src))
3547
+ return false;
3548
+
3549
+ return (
3550
+ src.split("/").every((part) => part !== "" && part !== "." && part !== "..") &&
3551
+ /\.(png|jpe?g|webp|gif)$/i.test(src)
3552
+ );
3553
+ }
3554
+
3555
+ function birdLanguage(language) {
3556
+ return language === "" ? "All languages" : language;
3557
+ }
3558
+
3559
+ /** The sentence of a drift item for the side-by-side panel. */
3560
+ function birdDriftWords(item) {
3561
+ const base = BIRD_DRIFT_WORDS[item.type] ?? item.type;
3562
+ const named = item.case ? `${base}: ${item.case}` : base;
3563
+
3564
+ return item.language ? `${named} (${item.language})` : named;
3565
+ }
3566
+
3567
+ /** How a filter text matches: an `AC-n` text matches that criterion exactly, anything else is a substring. */
3568
+ function birdMatcher(text) {
3569
+ const needle = text.trim().toLowerCase();
3570
+ const exactCriterion = /^ac-\d+$/.test(needle);
3571
+
3572
+ return {
3573
+ empty: needle === "",
3574
+ feature: (feature) =>
3575
+ feature.id.toLowerCase().includes(needle) || feature.title.toLowerCase().includes(needle),
3576
+ flow: (flow) =>
3577
+ flow.ref.toLowerCase().includes(needle) || flow.title.toLowerCase().includes(needle),
3578
+ criterion: (row) =>
3579
+ exactCriterion ? row.id.toLowerCase() === needle : row.id.toLowerCase().includes(needle),
3580
+ };
3581
+ }
3582
+
3583
+ /** The features, flows and criteria that match a filter; a matching feature or flow keeps everything under it. */
3584
+ function birdFilter(features, text) {
3585
+ const match = birdMatcher(text);
3586
+
3587
+ if (match.empty) return features;
3588
+
3589
+ return features.flatMap((feature) => {
3590
+ if (match.feature(feature)) return [feature];
3591
+
3592
+ const flows = feature.flows.flatMap((flow) => {
3593
+ if (match.flow(flow)) return [flow];
3594
+
3595
+ const criteria = flow.criteria.filter(match.criterion);
3596
+
3597
+ return criteria.length ? [{ ...flow, criteria }] : [];
3598
+ });
3599
+
3600
+ return flows.length ? [{ ...feature, flows }] : [];
3601
+ });
3602
+ }
3603
+
3604
+ /** Cells per state over some flows. */
3605
+ function birdCounts(flows) {
3606
+ const counts = {};
3607
+
3608
+ for (const flow of flows)
3609
+ for (const row of flow.criteria)
3610
+ for (const cell of row.cells) counts[cell.state] = (counts[cell.state] ?? 0) + 1;
3611
+
3612
+ return counts;
3613
+ }
3614
+
3615
+ /** Pills for the states that need a look, or "all passing". */
3616
+ function birdCountPills(ctx, counts) {
3617
+ const shown = BIRD_STATE_ORDER.filter((state) => state !== "pass" && counts[state]);
3618
+
3619
+ if (!shown.length)
3620
+ return counts.pass ? pill(ctx, `${counts.pass} passing`, "good") : muted(ctx, "no criteria");
3621
+
3622
+ return shown.map((state) =>
3623
+ pill(
3624
+ ctx,
3625
+ `${counts[state]} ${BIRD_STATES[state].label.toLowerCase()}`,
3626
+ BIRD_STATES[state].tone,
3627
+ ),
3628
+ );
3629
+ }
3630
+
3631
+ /** One image of the side-by-side panel, or the words that say there is none. */
3632
+ function birdFigure(ctx, title, src, none) {
3633
+ const { el } = ctx;
3634
+
3635
+ return el("figure", { class: "grimoire-bird-figure" }, [
3636
+ el("figcaption", { text: title }),
3637
+ birdShotPath(src) && typeof ctx.file === "function"
3638
+ ? el("img", { src: ctx.file(src), alt: title, loading: "lazy" })
3639
+ : el("p", { class: "grimoire-muted grimoire-bird-none", text: none }),
3640
+ ]);
3641
+ }
3642
+
3643
+ /**
3644
+ * The side-by-side panel: approved left, captured right, what changed, and
3645
+ * (in development) Approve and Reject. A failed request keeps the panel open
3646
+ * and says what failed.
3647
+ */
3648
+ function birdPanel(ctx, data, develop) {
3649
+ const { el } = ctx;
3650
+ const body = el("div", { class: "grimoire-bird-panel-body" });
3651
+ const dialog = el(
3652
+ "dialog",
3653
+ {
3654
+ class: "grimoire-bird-panel",
3655
+ "aria-label": "Compare",
3656
+ onclick: (event) => {
3657
+ if (event && event.target === dialog) dialog.close?.();
3658
+ },
3659
+ },
3660
+ [body],
3661
+ );
3662
+ const byId = new Map((data.drift ?? []).map((item) => [item.id, item]));
3663
+
3664
+ async function send(action, ids, note, error, button) {
3665
+ const verb = action === "approve" ? "approve" : "reject";
3666
+
3667
+ error.textContent = "";
3668
+ button.setAttribute("disabled", "");
3669
+
3670
+ try {
3671
+ await ctx.api(action, {
3672
+ method: "POST",
3673
+ headers: { "Content-Type": "application/json" },
3674
+ body: JSON.stringify(note ? { ids, note } : { ids }),
3675
+ });
3676
+ dialog.close?.();
3677
+ ctx.refresh();
3678
+ } catch (failure) {
3679
+ button.removeAttribute?.("disabled");
3680
+ // The dialog stays open: the failure is shown where the click happened.
3681
+ error.textContent = birdFailure(verb, failure);
3682
+ }
3683
+ }
3684
+
3685
+ function open({ title, language, state, test, shown, drift }) {
3686
+ const items = drift.map((id) => byId.get(id)).filter(Boolean);
3687
+ const info = BIRD_STATES[state] ?? BIRD_STATES["no-test"];
3688
+ const error = el("p", { class: "grimoire-error-title", role: "alert" });
3689
+ const note = el("input", {
3690
+ type: "text",
3691
+ class: "grimoire-filter-input",
3692
+ placeholder: "Why? (optional, kept with a rejection)",
3693
+ "aria-label": "Why reject",
3694
+ });
3695
+ const approve = el("button", {
3696
+ type: "button",
3697
+ class: "grimoire-bird-button is-primary",
3698
+ text: items.length > 1 ? `Approve ${items.length} changes` : "Approve",
3699
+ onclick: () => send("approve", drift, "", error, approve),
3700
+ });
3701
+ const reject = el("button", {
3702
+ type: "button",
3703
+ class: "grimoire-bird-button",
3704
+ text: items.length > 1 ? `Reject ${items.length} changes` : "Reject",
3705
+ onclick: () => send("reject", drift, (note.value ?? "").trim(), error, reject),
3706
+ });
3707
+
3708
+ body.replaceChildren(
3709
+ el("header", { class: "grimoire-bird-panel-head" }, [
3710
+ el("h3", { text: title }),
3711
+ language === null ? "" : pill(ctx, birdLanguage(language)),
3712
+ pill(ctx, info.label, info.tone),
3713
+ ]),
3714
+ test ? el("p", {}, ["Test: ", pill(ctx, test, toneOf(test))]) : "",
3715
+ shown
3716
+ ? el("div", { class: "grimoire-bird-compare" }, [
3717
+ birdFigure(ctx, "Approved", shown.approved, "No approved image yet."),
3718
+ birdFigure(
3719
+ ctx,
3720
+ "Captured",
3721
+ shown.shot,
3722
+ shown.outcome === "fail"
3723
+ ? "The scene failed, so there is no capture."
3724
+ : "Not captured yet.",
3725
+ ),
3726
+ ])
3727
+ : "",
3728
+ items.length
3729
+ ? el("section", { class: "grimoire-bird-changes", "aria-label": "Changes not approved" }, [
3730
+ el("h4", { text: "Changes not approved" }),
3731
+ el(
3732
+ "ul",
3733
+ { class: "grimoire-list" },
3734
+ items.map((item) =>
3735
+ el("li", {}, [
3736
+ el("strong", { text: birdDriftWords(item) }),
3737
+ item.rejected
3738
+ ? [
3739
+ " ",
3740
+ pill(ctx, "rejected", "bad"),
3741
+ item.rejected.note ? ` ${item.rejected.note}` : "",
3742
+ ]
3743
+ : "",
3744
+ item.before !== null || item.after !== null
3745
+ ? el("p", { class: "grimoire-muted" }, [
3746
+ item.before !== null ? `Before: ${item.before}` : "",
3747
+ item.before !== null && item.after !== null ? " · " : "",
3748
+ item.after !== null ? `Now: ${item.after}` : "",
3749
+ ])
3750
+ : "",
3751
+ ]),
3752
+ ),
3753
+ ),
3754
+ ])
3755
+ : el("p", { class: "grimoire-muted", text: "Nothing here is waiting for approval." }),
3756
+ develop && items.length
3757
+ ? el("div", { class: "grimoire-bird-actions" }, [note, approve, reject])
3758
+ : "",
3759
+ error,
3760
+ el("button", {
3761
+ type: "button",
3762
+ class: "grimoire-bird-button",
3763
+ text: "Close",
3764
+ onclick: () => dialog.close?.(),
3765
+ }),
3766
+ );
3767
+
3768
+ if (typeof dialog.showModal === "function") dialog.showModal();
3769
+ else dialog.setAttribute("open", "");
3770
+ }
3771
+
3772
+ return { dialog, open };
3773
+ }
3774
+
3775
+ /** One cell: the state in words and glyph, with the captured image as a thumbnail. */
3776
+ function birdCell(ctx, cell, label, panel, context) {
3777
+ const { el } = ctx;
3778
+ const info = BIRD_STATES[cell.state] ?? BIRD_STATES["no-test"];
3779
+ const shot = cell.shown?.shot ?? null;
3780
+
3781
+ return el("td", { class: "grimoire-bird-td" }, [
3782
+ el(
3783
+ "button",
3784
+ {
3785
+ type: "button",
3786
+ class: `grimoire-bird-cell is-${cell.state}`,
3787
+ "aria-label": `${label}, ${birdLanguage(cell.language)}: ${info.label}`,
3788
+ onclick: () =>
3789
+ panel.open({
3790
+ ...context,
3791
+ language: cell.language,
3792
+ state: cell.state,
3793
+ test: cell.test,
3794
+ shown: cell.shown,
3795
+ drift: cell.drift,
3796
+ }),
3797
+ },
3798
+ [
3799
+ birdShotPath(shot) && typeof ctx.file === "function"
3800
+ ? el("img", {
3801
+ class: "grimoire-bird-thumb",
3802
+ src: ctx.file(shot),
3803
+ alt: "",
3804
+ loading: "lazy",
3805
+ })
3806
+ : "",
3807
+ el("span", { class: "grimoire-bird-state" }, [
3808
+ el("span", { class: "grimoire-bird-glyph", "aria-hidden": "true", text: info.glyph }),
3809
+ el("span", { text: info.label }),
3810
+ ]),
3811
+ ],
3812
+ ),
3813
+ ]);
3814
+ }
3815
+
3816
+ function birdFlow(ctx, data, feature, flow, panel, forceOpen, develop) {
3817
+ const { el } = ctx;
3818
+ const counts = birdCounts([flow]);
3819
+ const hot =
3820
+ ["rejected", "fail", "changed"].some((state) => counts[state]) || flow.drift.length > 0;
3821
+ const title = `${feature.title} / ${flow.title}`;
3822
+ const head = [
3823
+ el("span", { class: "grimoire-bird-name", text: flow.title }),
3824
+ mono(ctx, flow.ref),
3825
+ flow.removed ? pill(ctx, "removed", "warn") : "",
3826
+ flow.differsIn.length ? pill(ctx, `differs in ${flow.differsIn.join(", ")}`) : "",
3827
+ !flow.screenshots && data.mode !== "off" ? pill(ctx, "no screenshots") : "",
3828
+ flow.drift.length
3829
+ ? pill(ctx, `${plural(flow.drift.length, "change")} not approved`, "warn")
3830
+ : "",
3831
+ birdCountPills(ctx, counts),
3832
+ ];
3833
+ const lines = flow.criteria.map((row) =>
3834
+ el("tr", { class: row.removed ? "is-removed" : "" }, [
3835
+ el("th", { scope: "row", class: "grimoire-bird-rowhead" }, [
3836
+ el("span", { class: "grimoire-mono", text: row.id }),
3837
+ row.app ? [" ", pill(ctx, row.app)] : "",
3838
+ row.removed ? [" ", pill(ctx, "removed", "warn")] : "",
3839
+ el("span", { class: "grimoire-bird-text", text: row.text }),
3840
+ ]),
3841
+ ...row.cells.map((cell) =>
3842
+ birdCell(ctx, cell, `${flow.ref} ${row.id}`, panel, {
3843
+ title: `${title}, ${row.id}`,
3844
+ }),
3845
+ ),
3846
+ ]),
3847
+ );
3848
+
3849
+ return el("details", { class: "grimoire-bird-flow", ...(forceOpen || hot ? { open: "" } : {}) }, [
3850
+ el("summary", { class: "grimoire-bird-summary" }, head),
3851
+ el("div", { class: "grimoire-bird-flowbody" }, [
3852
+ flow.drift.length
3853
+ ? el("p", {}, [
3854
+ el("button", {
3855
+ type: "button",
3856
+ class: "grimoire-bird-button",
3857
+ text: develop ? "Review the flow's changes" : "See the flow's changes",
3858
+ onclick: () =>
3859
+ panel.open({
3860
+ title,
3861
+ language: null,
3862
+ state: "changed",
3863
+ test: null,
3864
+ shown: null,
3865
+ drift: flow.drift,
3866
+ }),
3867
+ }),
3868
+ ])
3869
+ : "",
3870
+ flow.criteria.length
3871
+ ? el("div", { class: "grimoire-scroll" }, [
3872
+ el("table", { class: "grimoire-table grimoire-bird-table" }, [
3873
+ el("thead", {}, [
3874
+ el("tr", {}, [
3875
+ el("th", { scope: "col", text: "Criterion" }),
3876
+ ...data.languages.map((language) =>
3877
+ el("th", { scope: "col", text: language === "" ? "All" : language }),
3878
+ ),
3879
+ ]),
3880
+ ]),
3881
+ el("tbody", {}, lines),
3882
+ ]),
3883
+ ])
3884
+ : ctx.empty("This flow has no acceptance criteria."),
3885
+ link(
3886
+ ctx,
3887
+ "Open the flow",
3888
+ `flow/${encodeURIComponent(flow.ref.split("/")[0])}/${encodeURIComponent(flow.id)}`,
3889
+ ),
3890
+ ]),
3891
+ ]);
3892
+ }
3893
+
3894
+ /** The Bird view: every feature, flow and criterion against the app's languages. */
3895
+ async function birdView(ctx, query = {}) {
3896
+ const data = await ctx.api("matrix");
3897
+ const { el } = ctx;
3898
+ const develop = data.development === true && ctx.shared !== true;
3899
+ const panel = birdPanel(ctx, data, develop);
3900
+ const results = el("div", { class: "grimoire-bird-list" });
3901
+ const count = el("p", { class: "grimoire-muted", role: "status", "aria-live": "polite" });
3902
+ let text = String(query.q ?? "");
3903
+
3904
+ const paint = () => {
3905
+ const matches = birdFilter(data.features, text);
3906
+ const flows = matches.flatMap((feature) => feature.flows);
3907
+ const forceOpen = text.trim() !== "";
3908
+
3909
+ count.textContent = forceOpen
3910
+ ? `${plural(flows.length, "flow")} match`
3911
+ : `${plural(data.features.length, "feature")}, ${plural(
3912
+ data.features.reduce((total, feature) => total + feature.flows.length, 0),
3913
+ "flow",
3914
+ )}`;
3915
+ results.replaceChildren(
3916
+ ...(matches.length
3917
+ ? matches.map((feature) => {
3918
+ const counts = birdCounts(feature.flows);
3919
+ const hot = ["rejected", "fail", "changed"].some((state) => counts[state]);
3920
+
3921
+ return el(
3922
+ "details",
3923
+ { class: "grimoire-bird-feature", ...(forceOpen || hot ? { open: "" } : {}) },
3924
+ [
3925
+ el("summary", { class: "grimoire-bird-summary" }, [
3926
+ el("span", { class: "grimoire-bird-name", text: feature.title }),
3927
+ mono(ctx, feature.id),
3928
+ feature.designSystem ? pill(ctx, "design system", "info") : "",
3929
+ birdCountPills(ctx, counts),
3930
+ ]),
3931
+ el(
3932
+ "div",
3933
+ { class: "grimoire-bird-featurebody" },
3934
+ feature.flows.length
3935
+ ? feature.flows.map((flow) =>
3936
+ birdFlow(ctx, data, feature, flow, panel, forceOpen, develop),
3937
+ )
3938
+ : ctx.empty("This feature has no flows yet."),
3939
+ ),
3940
+ ],
3941
+ );
3942
+ })
3943
+ : [
3944
+ ctx.empty(
3945
+ `Nothing matches "${text.trim()}". Try a feature, a flow or an AC number such as AC-3.`,
3946
+ ),
3947
+ ]),
3948
+ );
3949
+ };
3950
+
3951
+ const input = el("input", {
3952
+ type: "search",
3953
+ class: "grimoire-filter-input",
3954
+ value: text,
3955
+ placeholder: "Jump to a feature, a flow or AC-3",
3956
+ "aria-label": "Jump to a feature, a flow or a criterion",
3957
+ oninput: (event) => {
3958
+ text = event?.target?.value ?? "";
3959
+ rememberRoute(
3960
+ ctx,
3961
+ text.trim() ? `bird-view?q=${encodeURIComponent(text.trim())}` : "bird-view",
3962
+ );
3963
+ paint();
3964
+ },
3965
+ });
3966
+ const banners = [];
3967
+ const waiting = (data.drift ?? []).filter((item) => item.rejected === null).length;
3968
+
3969
+ if (data.mode === "off") {
3970
+ banners.push(
3971
+ el("p", {
3972
+ class: "grimoire-note",
3973
+ text: "Screenshots are off in grimoire/settings.md. The matrix shows test status only.",
3974
+ }),
3975
+ );
3976
+ }
3977
+
3978
+ // One button that approves some ids; a failure is written next to it and the button stays usable.
3979
+ const approveButton = (label, ids, primary) => {
3980
+ const error = el("span", { class: "grimoire-error-title", role: "alert" });
3981
+ const button = el("button", {
3982
+ type: "button",
3983
+ class: primary ? "grimoire-bird-button is-primary" : "grimoire-bird-button",
3984
+ text: label,
3985
+ onclick: async () => {
3986
+ error.textContent = "";
3987
+
3988
+ try {
3989
+ await ctx.api("approve", {
3990
+ method: "POST",
3991
+ headers: { "Content-Type": "application/json" },
3992
+ body: JSON.stringify({ ids }),
3993
+ });
3994
+ ctx.refresh();
3995
+ } catch (failure) {
3996
+ error.textContent = ` ${birdFailure("approve", failure)}`;
3997
+ }
3998
+ },
3999
+ });
4000
+
4001
+ return [button, error];
4002
+ };
4003
+
4004
+ if (data.baseline === null) {
4005
+ banners.push(
4006
+ el("p", { class: "grimoire-note" }, [
4007
+ "Nothing approved yet: approve all to start. Until then the matrix shows test status and the latest screenshots, and nothing counts as changed. ",
4008
+ develop ? approveButton("Approve all", [BIRD_APPROVE_ALL], true) : "",
4009
+ ]),
4010
+ );
4011
+ } else if (develop && waiting > 0) {
4012
+ banners.push(
4013
+ el("p", { class: "grimoire-note" }, [
4014
+ `${plural(waiting, "change")} not approved. `,
4015
+ approveButton(
4016
+ `Approve all ${waiting}`,
4017
+ data.drift.filter((item) => item.rejected === null).map((item) => item.id),
4018
+ false,
4019
+ ),
4020
+ ]),
4021
+ );
4022
+ }
4023
+
4024
+ paint();
4025
+
4026
+ return el("div", { class: "grimoire-view grimoire-bird" }, [
4027
+ heading(ctx, "Bird view"),
4028
+ el("p", {
4029
+ class: "grimoire-muted",
4030
+ text: "Every criterion against every language: its test status, and the screenshot of the scene that shows it. Open a cell to compare it with the approved image.",
4031
+ }),
4032
+ el(
4033
+ "ul",
4034
+ { class: "grimoire-bird-legend", "aria-label": "Cell states" },
4035
+ BIRD_STATE_ORDER.map((state) =>
4036
+ el("li", {}, [
4037
+ pill(
4038
+ ctx,
4039
+ `${BIRD_STATES[state].glyph} ${BIRD_STATES[state].label}`,
4040
+ BIRD_STATES[state].tone,
4041
+ ),
4042
+ " ",
4043
+ muted(ctx, String(data.counts?.[state] ?? 0)),
4044
+ ]),
4045
+ ),
4046
+ ),
4047
+ ...banners,
4048
+ el("div", { class: "grimoire-toolbar" }, [input, count]),
4049
+ results,
4050
+ panel.dialog,
4051
+ ]);
4052
+ }
4053
+
3342
4054
  // ── Shell ───────────────────────────────────────────────────────────────────
3343
4055
 
3344
4056
  /**
@@ -3370,6 +4082,8 @@ async function body(ctx, summaryRequest) {
3370
4082
 
3371
4083
  return map.productMapView(ctx, parts.slice(1));
3372
4084
  }
4085
+ case "bird-view":
4086
+ return birdView(ctx, query);
3373
4087
  case "features":
3374
4088
  return featuresView(ctx);
3375
4089
  case "feature":
@@ -3406,6 +4120,7 @@ function describe(route) {
3406
4120
  const type = (route.split("?")[0] ?? "").split("/")[0] ?? "";
3407
4121
  const map = {
3408
4122
  product: ["the product map", null],
4123
+ "bird-view": ["the bird view", null],
3409
4124
  features: ["the features", null],
3410
4125
  feature: ["the feature", ["Features", "features"]],
3411
4126
  flow: ["the flow", ["Features", "features"]],
@@ -3758,6 +4473,7 @@ function header(ctx, route, summaryRequest) {
3758
4473
  const badge = badges.get(key);
3759
4474
  if (badge && value !== undefined && value !== null) badge.textContent = String(value);
3760
4475
  };
4476
+ set("bird-view", data.birdView || undefined);
3761
4477
  set("features", data.features?.features?.length);
3762
4478
  set("apps", data.apps?.apps);
3763
4479
  set("tasks", data.tasks ? data.tasks.open.length : undefined);