@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
@@ -0,0 +1,817 @@
1
+ /**
2
+ * The product map: the Grimoire for readers who do not read code. A browser
3
+ * ES module with two entry points:
4
+ *
5
+ * - `productMapView(ctx, parts)`: the "Product map" section inside the Grimoire
6
+ * tab. `parts` are the hash route segments after `product` (`[]`,
7
+ * `["feature", id]`, `["flow", feature, flow]`). Returns an element.
8
+ * - the default export `renderProductMap(context)`: the page a read-only
9
+ * share link opens (`context.shared === true`), with the same context
10
+ * helpers as a panel view.
11
+ *
12
+ * It builds the DOM with the context's `el()` helper and sets every string
13
+ * from the data as text, never as HTML. Every top-level name starts with
14
+ * `product` or `PRODUCT` because the static export inlines this file next to
15
+ * the Grimoire view.
16
+ *
17
+ * Keep the last line as it is: the static export swaps it out to inline this file.
18
+ */
19
+
20
+ const PRODUCT_STATUS = {
21
+ proposed: "Planned",
22
+ building: "Being built",
23
+ shipped: "Live",
24
+ retired: "Retired",
25
+ };
26
+
27
+ const PRODUCT_LIGHT = {
28
+ good: { label: "Working well", glyph: "✓" },
29
+ attention: { label: "Needs attention", glyph: "!" },
30
+ problem: { label: "Has problems", glyph: "✕" },
31
+ unknown: { label: "Not checked yet", glyph: "?" },
32
+ };
33
+
34
+ const PRODUCT_PROOF = {
35
+ pass: { level: "good", label: "Passing" },
36
+ fail: { level: "problem", label: "Failing" },
37
+ stale: { level: "attention", label: "Needs a new check (the tests changed)" },
38
+ "not-run": { level: "attention", label: "Not checked yet" },
39
+ "no-test": { level: "attention", label: "No test yet" },
40
+ };
41
+
42
+ const PRODUCT_CHANGE = { added: "Added", changed: "Changed", fixed: "Fixed", removed: "Removed" };
43
+
44
+ const PRODUCT_DEVELOPER_KEY = "grimoire-product-developer";
45
+
46
+ /** The helpers of one render: the context's `el()` made tolerant of nested and empty children. */
47
+ function productKit(ctx) {
48
+ const flat = (children) =>
49
+ Array.isArray(children)
50
+ ? children
51
+ .flat(Infinity)
52
+ .filter((child) => child !== null && child !== undefined && child !== false)
53
+ : children;
54
+ const el = (tag, attrs = {}, children = []) => ctx.el(tag, attrs, flat(children));
55
+ const shared = ctx.shared === true;
56
+ const link = (to, text, attrs = {}) =>
57
+ el("a", {
58
+ ...attrs,
59
+ // The host's href keeps a link inside its page (`#share/<route>` behind a share link), so it survives a reload or a new tab.
60
+ href: typeof ctx.href === "function" ? ctx.href(to) : `#${to}`,
61
+ text,
62
+ onclick: (event) => {
63
+ if (event && (event.metaKey || event.ctrlKey || event.shiftKey || event.button > 0)) return;
64
+ event?.preventDefault?.();
65
+ ctx.navigate(to);
66
+ },
67
+ });
68
+
69
+ return { el, shared, link };
70
+ }
71
+
72
+ function productPlural(count, one, many = `${one}s`) {
73
+ return `${count} ${count === 1 ? one : many}`;
74
+ }
75
+
76
+ function productDecode(text) {
77
+ try {
78
+ return decodeURIComponent(text);
79
+ } catch {
80
+ return text;
81
+ }
82
+ }
83
+
84
+ function productEncode(text) {
85
+ return encodeURIComponent(text);
86
+ }
87
+
88
+ function productDate(value) {
89
+ if (!value) return null;
90
+ const date = new Date(value);
91
+
92
+ if (Number.isNaN(date.getTime())) return String(value);
93
+
94
+ try {
95
+ return date.toLocaleDateString(undefined, { year: "numeric", month: "short", day: "numeric" });
96
+ } catch {
97
+ return String(value);
98
+ }
99
+ }
100
+
101
+ function productStatusChip(kit, status) {
102
+ return kit.el("span", { class: `pm-chip pm-status pm-status--${status}`, text: PRODUCT_STATUS[status] ?? status });
103
+ }
104
+
105
+ /** A traffic light: a shape and words as well as a colour. */
106
+ function productLight(kit, level, label) {
107
+ const light = PRODUCT_LIGHT[level] ?? PRODUCT_LIGHT.unknown;
108
+
109
+ return kit.el("span", { class: `pm-light pm-light--${PRODUCT_LIGHT[level] ? level : "unknown"}` }, [
110
+ kit.el("span", { class: "pm-light-glyph", "aria-hidden": "true", text: light.glyph }),
111
+ kit.el("span", { text: label ?? light.label }),
112
+ ]);
113
+ }
114
+
115
+ function productHealth(kit, health) {
116
+ return kit.el("div", { class: "pm-health" }, [
117
+ productLight(kit, health.level),
118
+ kit.el("span", { class: "pm-health-reason", text: health.reason }),
119
+ ]);
120
+ }
121
+
122
+ function productChips(kit, items, kind) {
123
+ if (!items || items.length === 0) return null;
124
+
125
+ return kit.el(
126
+ "ul",
127
+ { class: `pm-chips pm-chips--${kind}`, "aria-label": kind === "audience" ? "Who it is for" : "Where it lives" },
128
+ items.map((item) => kit.el("li", { class: `pm-chip pm-chip--${kind}`, text: item })),
129
+ );
130
+ }
131
+
132
+ function productSection(kit, title, body, attrs = {}) {
133
+ return kit.el("section", { class: "pm-section", ...attrs }, [
134
+ kit.el("h3", { class: "pm-section-title", text: title }),
135
+ body,
136
+ ]);
137
+ }
138
+
139
+ function productBreadcrumb(kit, trail) {
140
+ return kit.el("nav", { class: "pm-crumbs", "aria-label": "Breadcrumb" }, [
141
+ kit.el(
142
+ "ol",
143
+ {},
144
+ trail.map((item, index) =>
145
+ kit.el("li", {}, [
146
+ item.to !== undefined && index < trail.length - 1
147
+ ? kit.link(item.to, item.text)
148
+ : kit.el("span", { "aria-current": "page", text: item.text }),
149
+ ]),
150
+ ),
151
+ ),
152
+ ]);
153
+ }
154
+
155
+ // ── Screenshots ───────────────────────────────────────────────────────────
156
+
157
+ /** One shared dialog per view; a screenshot button fills it and opens it. */
158
+ function productLightbox(ctx, kit) {
159
+ const image = kit.el("img", { class: "pm-lightbox-image", alt: "" });
160
+ const caption = kit.el("p", { class: "pm-lightbox-caption" });
161
+ const dialog = kit.el(
162
+ "dialog",
163
+ {
164
+ class: "pm-lightbox",
165
+ "aria-label": "Screenshot",
166
+ onclick: (event) => {
167
+ if (event && event.target === dialog) dialog.close?.();
168
+ },
169
+ },
170
+ [
171
+ kit.el("div", { class: "pm-lightbox-body" }, [
172
+ image,
173
+ caption,
174
+ kit.el("button", {
175
+ type: "button",
176
+ class: "pm-button",
177
+ text: "Close",
178
+ onclick: () => (typeof dialog.close === "function" ? dialog.close() : undefined),
179
+ }),
180
+ ]),
181
+ ],
182
+ );
183
+
184
+ return {
185
+ dialog,
186
+ open(shot) {
187
+ image.setAttribute("src", ctx.file(shot.src));
188
+ image.setAttribute("alt", shot.alt);
189
+ caption.textContent = shot.alt;
190
+
191
+ if (typeof dialog.showModal === "function") dialog.showModal();
192
+ else dialog.setAttribute("open", "");
193
+ },
194
+ };
195
+ }
196
+
197
+ const PRODUCT_SHOT_EXTENSION = /\.(png|jpe?g|webp|gif)$/i;
198
+
199
+ /**
200
+ * Whether a screenshot path is a plain path inside the screenshots folder: no
201
+ * scheme, no absolute path, no backslash and no empty, `.` or `..` segment, so
202
+ * `ctx.file()` can never point an image outside the folder.
203
+ */
204
+ function productShotPath(src) {
205
+ if (typeof src !== "string" || src === "" || src.startsWith("/") || /[\\:\0?#]/.test(src)) return false;
206
+
207
+ const segments = src.split("/");
208
+
209
+ return segments.every((segment) => segment !== "" && segment !== "." && segment !== "..") && PRODUCT_SHOT_EXTENSION.test(src);
210
+ }
211
+
212
+ function productShots(ctx, kit, list, lightbox) {
213
+ const shots = (list ?? []).filter((shot) => productShotPath(shot?.src));
214
+
215
+ if (shots.length === 0 || typeof ctx.file !== "function") return null;
216
+
217
+ return kit.el(
218
+ "ul",
219
+ { class: "pm-shots" },
220
+ shots.map((shot) =>
221
+ kit.el("li", {}, [
222
+ kit.el(
223
+ "button",
224
+ {
225
+ type: "button",
226
+ class: "pm-shot",
227
+ "aria-label": `Enlarge screenshot${shot.alt ? `: ${shot.alt}` : ""}`,
228
+ onclick: () => lightbox.open(shot),
229
+ },
230
+ [kit.el("img", { src: ctx.file(shot.src), alt: shot.alt, loading: "lazy" })],
231
+ ),
232
+ ]),
233
+ ),
234
+ );
235
+ }
236
+
237
+ function productAppearances(ctx, kit, appearances, lightbox, withFlowLinks) {
238
+ if (!appearances || appearances.length === 0) return null;
239
+
240
+ const byApp = new Map();
241
+
242
+ for (const item of appearances) {
243
+ if (!byApp.has(item.app)) byApp.set(item.app, []);
244
+ byApp.get(item.app).push(item);
245
+ }
246
+
247
+ return productSection(
248
+ kit,
249
+ "Where you see it",
250
+ kit.el(
251
+ "div",
252
+ { class: "pm-apps" },
253
+ [...byApp.entries()].map(([app, items]) =>
254
+ kit.el("div", { class: "pm-app" }, [
255
+ kit.el("h4", { text: app }),
256
+ kit.el(
257
+ "ul",
258
+ { class: "pm-places" },
259
+ items.map((item) =>
260
+ kit.el("li", { class: "pm-place" }, [
261
+ kit.el("div", { class: "pm-place-head" }, [
262
+ kit.el("strong", { text: item.title ?? item.id }),
263
+ item.route ? kit.el("span", { class: "pm-place-route", text: item.route }) : null,
264
+ withFlowLinks && item.flow
265
+ ? kit.link(`product/flow/${item.flow.split("/").map(productEncode).join("/")}`, "See the story", { class: "pm-place-flow" })
266
+ : null,
267
+ ]),
268
+ productShots(ctx, kit, item.screenshots, lightbox),
269
+ ]),
270
+ ),
271
+ ),
272
+ ]),
273
+ ),
274
+ ),
275
+ );
276
+ }
277
+
278
+ // ── Developer toggle ──────────────────────────────────────────────────────
279
+
280
+ function productDeveloperToggle(kit, body) {
281
+ let on = false;
282
+
283
+ try {
284
+ on = globalThis.localStorage?.getItem(PRODUCT_DEVELOPER_KEY) === "1";
285
+ } catch {
286
+ on = false;
287
+ }
288
+
289
+ const button = kit.el("button", {
290
+ type: "button",
291
+ class: "pm-button pm-developer-toggle",
292
+ "aria-pressed": String(on),
293
+ text: "For developers",
294
+ });
295
+ const panel = kit.el("section", { class: "pm-developer", "aria-label": "For developers" }, on ? body() : []);
296
+
297
+ if (!on) panel.setAttribute("hidden", "");
298
+
299
+ let built = on;
300
+
301
+ button.addEventListener("click", () => {
302
+ on = !on;
303
+
304
+ try {
305
+ globalThis.localStorage?.setItem(PRODUCT_DEVELOPER_KEY, on ? "1" : "0");
306
+ } catch {
307
+ // The choice is only a convenience.
308
+ }
309
+
310
+ button.setAttribute("aria-pressed", String(on));
311
+
312
+ if (on && !built) {
313
+ panel.replaceChildren(...[body()].flat());
314
+ built = true;
315
+ }
316
+
317
+ if (on) panel.removeAttribute?.("hidden");
318
+ else panel.setAttribute("hidden", "");
319
+ });
320
+
321
+ return { button, panel };
322
+ }
323
+
324
+ // ── Pages ─────────────────────────────────────────────────────────────────
325
+
326
+ function productLoadError(ctx, kit, what, error) {
327
+ return kit.el("div", { class: "pm-error", role: "alert" }, [
328
+ kit.el("h3", { text: `Could not load ${what}` }),
329
+ kit.el("p", { text: error?.message ?? String(error) }),
330
+ kit.el("p", {
331
+ class: "pm-muted",
332
+ text: kit.shared
333
+ ? "Reload the page. If it still fails, the link may have expired or been revoked: ask the person who shared it for a new one."
334
+ : "Check that the app is running, then try again.",
335
+ }),
336
+ kit.el("button", {
337
+ type: "button",
338
+ class: "pm-button",
339
+ text: "Try again",
340
+ onclick: () => ctx.refresh?.(),
341
+ }),
342
+ ]);
343
+ }
344
+
345
+ function productMapPage(ctx, kit, answer) {
346
+ const features = answer.features ?? [];
347
+ const live = features.filter((feature) => feature.status === "shipped").length;
348
+ const attention = features.filter(
349
+ (feature) => feature.health.level === "attention" || feature.health.level === "problem",
350
+ ).length;
351
+ const share = ctx.share?.enabled ? ctx.share : null;
352
+
353
+ const header = kit.el("header", { class: "pm-hero" }, [
354
+ kit.el("div", {}, [
355
+ kit.el("h2", { text: "Product map" }),
356
+ kit.el("p", {
357
+ class: "pm-lead",
358
+ text: "What the product does, who it is for and how healthy each part is, in plain words.",
359
+ }),
360
+ ]),
361
+ share
362
+ ? kit.el("a", { class: "pm-button pm-button--primary", href: share.manageHref, text: "Share this map" })
363
+ : null,
364
+ ]);
365
+
366
+ if (features.length === 0) {
367
+ return kit.el("div", { class: "pm-page" }, [
368
+ header,
369
+ kit.el("div", { class: "pm-empty" }, [
370
+ kit.el("h3", { text: "No features are written yet" }),
371
+ kit.el("p", {
372
+ text: "Ask your agent to describe the product in grimoire/features. Each feature you describe becomes a card here.",
373
+ }),
374
+ ]),
375
+ ]);
376
+ }
377
+
378
+ const apps = [...new Set(features.flatMap((feature) => feature.apps))].sort();
379
+ const audiences = [...new Set(features.flatMap((feature) => feature.audience))].sort();
380
+ const state = { text: "", app: "", audience: "" };
381
+ const grid = kit.el("ul", { class: "pm-grid" });
382
+ const count = kit.el("p", { class: "pm-count", role: "status", "aria-live": "polite" });
383
+ const none = kit.el("p", { class: "pm-empty pm-empty--inline", text: "No feature matches. Clear the search or a filter." });
384
+
385
+ const card = (feature) =>
386
+ kit.el("li", { class: "pm-card" }, [
387
+ kit.el("div", { class: "pm-card-top" }, [
388
+ productStatusChip(kit, feature.status),
389
+ kit.el("span", { class: "pm-muted", text: productPlural(feature.flows, "flow") }),
390
+ ]),
391
+ kit.el("h3", { class: "pm-card-title" }, [
392
+ kit.link(`product/feature/${productEncode(feature.id)}`, feature.title, { class: "pm-card-link" }),
393
+ ]),
394
+ kit.el("p", {
395
+ class: "pm-card-summary",
396
+ text: feature.summary ?? "No summary yet.",
397
+ }),
398
+ productChips(kit, feature.audience, "audience"),
399
+ productChips(kit, feature.apps, "app"),
400
+ productHealth(kit, feature.health),
401
+ ]);
402
+
403
+ const show = () => {
404
+ const needle = state.text.trim().toLowerCase();
405
+ const matches = features.filter(
406
+ (feature) =>
407
+ (state.app === "" || feature.apps.includes(state.app)) &&
408
+ (state.audience === "" || feature.audience.includes(state.audience)) &&
409
+ (needle === "" ||
410
+ feature.title.toLowerCase().includes(needle) ||
411
+ (feature.summary ?? "").toLowerCase().includes(needle)),
412
+ );
413
+
414
+ grid.replaceChildren(...matches.map(card));
415
+ count.textContent = `Showing ${matches.length} of ${features.length} features`;
416
+ if (matches.length === 0) grid.append(none);
417
+ };
418
+
419
+ const select = (label, options, key) =>
420
+ kit.el("label", { class: "pm-field" }, [
421
+ kit.el("span", { text: label }),
422
+ kit.el(
423
+ "select",
424
+ {
425
+ onchange: (event) => {
426
+ state[key] = event?.target?.value ?? "";
427
+ show();
428
+ },
429
+ },
430
+ [
431
+ kit.el("option", { value: "", text: `All ${label.toLowerCase()}s` }),
432
+ ...options.map((option) => kit.el("option", { value: option, text: option })),
433
+ ],
434
+ ),
435
+ ]);
436
+
437
+ const filters = kit.el("div", { class: "pm-filters", role: "search" }, [
438
+ kit.el("label", { class: "pm-field pm-field--grow" }, [
439
+ kit.el("span", { text: "Search" }),
440
+ kit.el("input", {
441
+ type: "search",
442
+ placeholder: "Search by name or summary",
443
+ oninput: (event) => {
444
+ state.text = event?.target?.value ?? "";
445
+ show();
446
+ },
447
+ }),
448
+ ]),
449
+ apps.length > 1 ? select("App", apps, "app") : null,
450
+ audiences.length > 0 ? select("Audience", audiences, "audience") : null,
451
+ ]);
452
+
453
+ show();
454
+
455
+ return kit.el("div", { class: "pm-page" }, [
456
+ header,
457
+ kit.el("ul", { class: "pm-stats", "aria-label": "At a glance" }, [
458
+ kit.el("li", {}, [kit.el("strong", { text: String(features.length) }), kit.el("span", { text: "features" })]),
459
+ kit.el("li", {}, [kit.el("strong", { text: String(live) }), kit.el("span", { text: "live" })]),
460
+ kit.el("li", {}, [
461
+ kit.el("strong", { text: String(attention) }),
462
+ kit.el("span", { text: attention === 1 ? "needs attention" : "need attention" }),
463
+ ]),
464
+ ]),
465
+ filters,
466
+ count,
467
+ grid,
468
+ ]);
469
+ }
470
+
471
+ function productFlowCard(kit, flow) {
472
+ return kit.el("li", { class: "pm-card pm-card--flow" }, [
473
+ kit.el("div", { class: "pm-card-top" }, [
474
+ productStatusChip(kit, flow.status),
475
+ kit.el("span", { class: "pm-muted", text: flow.who }),
476
+ ]),
477
+ kit.el("h4", { class: "pm-card-title" }, [
478
+ kit.link(`product/flow/${flow.ref.split("/").map(productEncode).join("/")}`, flow.title, { class: "pm-card-link" }),
479
+ ]),
480
+ kit.el("p", { class: "pm-card-summary", text: flow.summary ?? "No summary yet." }),
481
+ productHealth(kit, flow.health),
482
+ ]);
483
+ }
484
+
485
+ function productTimeline(kit, releases) {
486
+ const ordered = [...releases].sort(
487
+ (left, right) => Number(right.release === null) - Number(left.release === null),
488
+ );
489
+
490
+ return kit.el(
491
+ "ol",
492
+ { class: "pm-timeline" },
493
+ ordered.map((item) => {
494
+ const when = [
495
+ item.release === null ? "Not released yet" : `Release ${item.release}`,
496
+ productDate(item.date),
497
+ ].filter(Boolean);
498
+
499
+ return kit.el("li", { class: "pm-release" }, [
500
+ kit.el("div", { class: "pm-release-head" }, [
501
+ kit.el("strong", { text: `Version ${item.version}` }),
502
+ kit.el("span", { class: "pm-muted", text: when.join(" · ") }),
503
+ ]),
504
+ kit.el(
505
+ "ul",
506
+ { class: "pm-changes" },
507
+ item.changes.map((change) =>
508
+ kit.el("li", {}, [
509
+ kit.el("span", { class: `pm-chip pm-change pm-change--${change.word}`, text: PRODUCT_CHANGE[change.word] ?? change.word }),
510
+ kit.el("span", { text: change.text }),
511
+ ]),
512
+ ),
513
+ ),
514
+ ]);
515
+ }),
516
+ );
517
+ }
518
+
519
+ function productPlanned(kit, planned) {
520
+ return kit.el(
521
+ "ul",
522
+ { class: "pm-list" },
523
+ planned.map((item) =>
524
+ kit.el("li", {}, [
525
+ kit.el("span", { class: "pm-chip", text: item.type === "bug" ? "Fix" : item.type === "feature" ? "New" : item.type === "decision" ? "Decision" : "Upkeep" }),
526
+ kit.el("span", { text: item.title }),
527
+ kit.el("span", { class: "pm-muted", text: item.status }),
528
+ ]),
529
+ ),
530
+ );
531
+ }
532
+
533
+ function productFeaturePage(ctx, kit, answer, lightbox) {
534
+ const feature = answer.feature;
535
+ const health = answer.health;
536
+ const sections = [];
537
+
538
+ sections.push(
539
+ kit.el("header", { class: "pm-title" }, [
540
+ kit.el("div", { class: "pm-title-row" }, [
541
+ kit.el("h2", { text: feature.title }),
542
+ productStatusChip(kit, feature.status),
543
+ ]),
544
+ kit.el("p", { class: "pm-lead", text: feature.summary ?? "No summary yet." }),
545
+ productChips(kit, feature.audience, "audience"),
546
+ productChips(kit, feature.apps, "app"),
547
+ kit.el("p", { class: "pm-muted", text: `Version ${feature.version}` }),
548
+ ]),
549
+ );
550
+
551
+ sections.push(
552
+ kit.el("section", { class: "pm-section pm-callout", "aria-label": "Health" }, [
553
+ productHealth(kit, health),
554
+ health.errors && health.errors.count > 0
555
+ ? kit.el("p", {
556
+ class: "pm-muted",
557
+ text: `${productPlural(health.errors.count, "error")} in the last hour on the pages and routes this feature uses.`,
558
+ })
559
+ : null,
560
+ ]),
561
+ );
562
+
563
+ if (feature.why) sections.push(productSection(kit, "Why it exists", kit.el("p", { class: "pm-prose", text: feature.why })));
564
+
565
+ if (answer.flows.length > 0)
566
+ sections.push(
567
+ productSection(
568
+ kit,
569
+ "What people can do",
570
+ kit.el("ul", { class: "pm-grid pm-grid--flows" }, answer.flows.map((flow) => productFlowCard(kit, flow))),
571
+ ),
572
+ );
573
+
574
+ sections.push(productAppearances(ctx, kit, answer.appearances, lightbox, true));
575
+
576
+ sections.push(
577
+ productSection(
578
+ kit,
579
+ "What changed",
580
+ answer.releases.length > 0
581
+ ? productTimeline(kit, answer.releases)
582
+ : kit.el("p", { class: "pm-muted", text: "No changes are recorded yet." }),
583
+ ),
584
+ );
585
+
586
+ if (answer.planned.length > 0)
587
+ sections.push(productSection(kit, "Coming next", productPlanned(kit, answer.planned)));
588
+
589
+ return sections;
590
+ }
591
+
592
+ function productFeatureDeveloper(kit, developer) {
593
+ return () => [
594
+ kit.el("h3", { class: "pm-section-title", text: "For developers" }),
595
+ kit.el("dl", { class: "pm-facts" }, [
596
+ kit.el("dt", { text: "Folders" }),
597
+ kit.el("dd", { class: "pm-mono", text: developer.folders.join(", ") || "none" }),
598
+ kit.el("dt", { text: "Files it owns" }),
599
+ kit.el("dd", { text: String(developer.files) }),
600
+ kit.el("dt", { text: "Check findings" }),
601
+ kit.el("dd", {
602
+ text: `${productPlural(developer.findings.errors, "error")}, ${productPlural(developer.findings.warnings, "warning")}`,
603
+ }),
604
+ kit.el("dt", { text: "Routes" }),
605
+ kit.el(
606
+ "dd",
607
+ {},
608
+ developer.routes.length === 0
609
+ ? "none"
610
+ : kit.el(
611
+ "ul",
612
+ { class: "pm-mono pm-plain-list" },
613
+ developer.routes.map((route) => kit.el("li", { text: `${route.method} ${route.path}` })),
614
+ ),
615
+ ),
616
+ ]),
617
+ ];
618
+ }
619
+
620
+ function productStory(ctx, kit, story, lightbox) {
621
+ if (story.length === 0)
622
+ return kit.el("p", { class: "pm-muted", text: "No steps are written for this flow yet." });
623
+
624
+ return kit.el(
625
+ "ol",
626
+ { class: "pm-story" },
627
+ story.map((step) =>
628
+ kit.el("li", { class: "pm-step" }, [
629
+ kit.el("p", { text: step.text }),
630
+ step.derived ? kit.el("span", { class: "pm-chip pm-chip--soft", text: "from the technical steps" }) : null,
631
+ productShots(ctx, kit, step.screenshots, lightbox),
632
+ ]),
633
+ ),
634
+ );
635
+ }
636
+
637
+ function productCases(kit, cases) {
638
+ const handled = cases.filter((item) => item.handled);
639
+ const skipped = cases.filter((item) => !item.handled);
640
+ const item = (entry) =>
641
+ kit.el("li", {}, [
642
+ kit.el("strong", { text: entry.question }),
643
+ kit.el("p", { text: entry.handled ? entry.answer : entry.answer.replace(/^does not apply\b[:\s—-]*/i, "") }),
644
+ entry.criteria.length > 0
645
+ ? kit.el("span", { class: "pm-chip pm-chip--soft", text: `Checked by ${entry.criteria.join(", ")}` })
646
+ : null,
647
+ ]);
648
+
649
+ return [
650
+ handled.length > 0
651
+ ? kit.el("ul", { class: "pm-cases" }, handled.map(item))
652
+ : kit.el("p", { class: "pm-muted", text: "No edge cases are written yet." }),
653
+ skipped.length > 0
654
+ ? kit.el("details", { class: "pm-details" }, [
655
+ kit.el("summary", { text: `Does not apply (${skipped.length})` }),
656
+ kit.el("ul", { class: "pm-cases" }, skipped.map(item)),
657
+ ])
658
+ : null,
659
+ ];
660
+ }
661
+
662
+ function productProof(kit, proof) {
663
+ return kit.el(
664
+ "ul",
665
+ { class: "pm-proof" },
666
+ proof.map((item) => {
667
+ const status = PRODUCT_PROOF[item.status] ?? PRODUCT_PROOF["not-run"];
668
+
669
+ return kit.el("li", {}, [
670
+ productLight(kit, status.level, status.label),
671
+ kit.el("span", { text: item.text }),
672
+ ]);
673
+ }),
674
+ );
675
+ }
676
+
677
+ function productFlowPage(ctx, kit, answer, lightbox) {
678
+ const flow = answer.flow;
679
+ const neighbour = (item, label) =>
680
+ item === null
681
+ ? null
682
+ : kit.link(`product/flow/${productEncode(flow.feature)}/${productEncode(item.id)}`, `${label}: ${item.heading ?? item.id}`, {
683
+ class: "pm-button",
684
+ });
685
+ const sections = [
686
+ productBreadcrumb(kit, [
687
+ { text: "Product map", to: "product" },
688
+ { text: flow.featureTitle, to: `product/feature/${productEncode(flow.feature)}` },
689
+ { text: flow.title },
690
+ ]),
691
+ kit.el("header", { class: "pm-title" }, [
692
+ kit.el("div", { class: "pm-title-row" }, [kit.el("h2", { text: flow.title }), productStatusChip(kit, flow.status)]),
693
+ kit.el("p", { class: "pm-lead", text: flow.summary ?? "No summary yet." }),
694
+ kit.el("p", { class: "pm-muted", text: `For ${flow.who} · since version ${flow.since}` }),
695
+ ]),
696
+ kit.el("section", { class: "pm-section pm-callout", "aria-label": "Health" }, [productHealth(kit, answer.health)]),
697
+ productSection(kit, "How it goes", productStory(ctx, kit, answer.story, lightbox)),
698
+ productSection(
699
+ kit,
700
+ "What proves it",
701
+ answer.proof.length > 0
702
+ ? productProof(kit, answer.proof)
703
+ : kit.el("p", { class: "pm-muted", text: "No checks are written for this flow yet." }),
704
+ ),
705
+ productSection(kit, "What if…", kit.el("div", {}, productCases(kit, answer.cases))),
706
+ productAppearances(ctx, kit, answer.appearances, lightbox, false),
707
+ kit.el("nav", { class: "pm-neighbours", "aria-label": "Other flows of this feature" }, [
708
+ neighbour(answer.previous, "Previous"),
709
+ neighbour(answer.next, "Next"),
710
+ ]),
711
+ ];
712
+
713
+ return sections;
714
+ }
715
+
716
+ /** A step's file counts, like the technical flow page: the type-only count only when there is one. */
717
+ function productStepCounts(counts) {
718
+ const parts = [`${counts.direct} direct`, `${counts.feature} in this feature`, `${counts.reachable} reachable`];
719
+
720
+ if (counts.typeOnly > 0) parts.push(`${counts.typeOnly} type-only`);
721
+
722
+ return parts.join(" · ");
723
+ }
724
+
725
+ function productFlowDeveloper(ctx, kit, answer) {
726
+ return () => [
727
+ kit.el("h3", { class: "pm-section-title", text: "For developers" }),
728
+ kit.link(`flows/${answer.flow.ref}`, "Open the technical flow page"),
729
+ kit.el(
730
+ "ol",
731
+ { class: "pm-tech-steps" },
732
+ answer.developer.steps.map((step) =>
733
+ kit.el("li", {}, [
734
+ kit.el("strong", { text: `${step.type} ` }),
735
+ kit.el("span", { class: "pm-mono", text: step.target }),
736
+ step.entry ? kit.el("div", { class: "pm-mono pm-muted", text: step.entry }) : null,
737
+ kit.el("div", {
738
+ class: "pm-muted",
739
+ text: productStepCounts(step.counts),
740
+ }),
741
+ ]),
742
+ ),
743
+ ),
744
+ ];
745
+ }
746
+
747
+ // ── Entry points ──────────────────────────────────────────────────────────
748
+
749
+ /** The product map section for the hash route segments after `product`. */
750
+ export async function productMapView(ctx, parts = []) {
751
+ const kit = productKit(ctx);
752
+ const { el } = kit;
753
+ const root = el("div", { class: `pm-root${kit.shared ? " pm-shared" : ""}` });
754
+ const lightbox = productLightbox(ctx, kit);
755
+
756
+ if (typeof ctx.asset === "function")
757
+ root.append(el("link", { rel: "stylesheet", href: ctx.asset("product-map.css") }));
758
+
759
+ const main = el("main", { class: "pm-main", "aria-busy": "true" });
760
+ const [kind, first, second] = parts.map(productDecode);
761
+
762
+ root.append(main);
763
+
764
+ try {
765
+ if (kind === "feature" && first) {
766
+ const answer = await ctx.api(`product/features/${productEncode(first)}`);
767
+ const body = [
768
+ productBreadcrumb(kit, [{ text: "Product map", to: "product" }, { text: answer.feature.title }]),
769
+ ...productFeaturePage(ctx, kit, answer, lightbox),
770
+ ];
771
+
772
+ if (!kit.shared && answer.developer) {
773
+ const toggle = productDeveloperToggle(kit, productFeatureDeveloper(kit, answer.developer));
774
+
775
+ body.splice(1, 0, el("div", { class: "pm-toolbar" }, [toggle.button]));
776
+ body.push(toggle.panel);
777
+ }
778
+
779
+ main.append(el("div", { class: "pm-page" }, body));
780
+ } else if (kind === "flow" && first && second) {
781
+ const answer = await ctx.api(`product/flows/${productEncode(first)}/${productEncode(second)}`);
782
+ const body = productFlowPage(ctx, kit, answer, lightbox);
783
+
784
+ if (!kit.shared && answer.developer) {
785
+ const toggle = productDeveloperToggle(kit, productFlowDeveloper(ctx, kit, answer));
786
+
787
+ body.splice(2, 0, el("div", { class: "pm-toolbar" }, [toggle.button]));
788
+ body.push(toggle.panel);
789
+ }
790
+
791
+ main.append(el("div", { class: "pm-page" }, body));
792
+ } else {
793
+ main.append(productMapPage(ctx, kit, await ctx.api("product")));
794
+ }
795
+ } catch (error) {
796
+ main.append(productLoadError(ctx, kit, kind === "feature" ? "this feature" : kind === "flow" ? "this flow" : "the product map", error));
797
+ }
798
+
799
+ main.setAttribute("aria-busy", "false");
800
+ root.append(lightbox.dialog);
801
+
802
+ if (kit.shared) root.append(el("footer", { class: "pm-footer", text: "Read-only view" }));
803
+
804
+ return root;
805
+ }
806
+
807
+ /** The shared page: the map with no developer detail and no links into the rest of the tab. */
808
+ async function renderProductMap(context) {
809
+ const parts = (context.route ?? "").split("/").filter(Boolean);
810
+
811
+ if (parts[0] === "share" && (parts.length === 1 || parts[1] === "feature" || parts[1] === "flow")) parts.shift();
812
+ if (parts[0] === "product") parts.shift();
813
+
814
+ return productMapView({ ...context, shared: true }, parts);
815
+ }
816
+
817
+ export default renderProductMap;