@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
@@ -1,9 +1,20 @@
1
1
  import { readFrontMatter } from "../front-matter/index.mjs";
2
+ import path from "node:path";
2
3
 
3
4
  //#region ../../packages/grimoire/src/written/markdown.ts
5
+ /**
6
+ * One pass over a written file's lines: front matter, headings, `##`
7
+ * sections and the logical lines of a list section. Every parser of a
8
+ * written file starts from the `WrittenDocument` this module builds, so a
9
+ * file is split once and scanned line by line, never re-scanned whole.
10
+ */
4
11
  const HEADING = /^(#{1,6})[ \t]+(.+?)(?:[ \t]+#+)?$/;
5
12
  const FENCE = /^[ \t]*(?:```|~~~)/;
6
13
  const ITEM_START = /^(?:[-*][ \t]|\d+\.[ \t])/;
14
+ const IMAGE = /!\[([^\]]*)\]\(\s*<?([^)\s>]+)>?(?:\s+(?:"[^"]*"|'[^']*'))?\s*\)/g;
15
+ const IMAGE_ONLY = /^(?:!\[[^\]]*\]\([^)]*\)\s*)+$/;
16
+ /** Where screenshots live, relative to the project root. */
17
+ const SCREENSHOTS_DIR = "grimoire/screenshots/";
7
18
  /** Lower-case a heading or a question and collapse its spaces. */
8
19
  function normalizeKey(text) {
9
20
  return text.trim().replace(/\s+/g, " ").toLowerCase();
@@ -158,6 +169,7 @@ function paragraphAfterTitle(document) {
158
169
  if (parts.length > 0) break;
159
170
  continue;
160
171
  }
172
+ if (IMAGE_ONLY.test(trimmed)) continue;
161
173
  parts.push(trimmed);
162
174
  }
163
175
  return parts.length > 0 ? parts.join(" ") : null;
@@ -167,7 +179,60 @@ function textAfterTitle(document, endLine) {
167
179
  const from = document.title?.line ?? 0;
168
180
  return document.body.filter((bodyLine) => bodyLine.line > from && (endLine === void 0 || bodyLine.line < endLine)).map((bodyLine) => bodyLine.text).join("\n").trim();
169
181
  }
182
+ /**
183
+ * The path under `grimoire/screenshots/` an image line points at, or `null`
184
+ * when it points elsewhere. The path is relative to the Markdown file, or
185
+ * starts with `/grimoire/screenshots/`.
186
+ */
187
+ function screenshotPath(file, written) {
188
+ const target = written.replace(/[?#].*$/, "").replace(/\\/g, "/");
189
+ if (/^[a-z][a-z0-9+.-]*:/i.test(target) || target.startsWith("//")) return null;
190
+ const resolved = target.startsWith("/") ? path.posix.normalize(target.slice(1)) : path.posix.join(path.posix.dirname(file.replace(/\\/g, "/")), target);
191
+ const normal = path.posix.normalize(resolved);
192
+ if (!normal.startsWith(SCREENSHOTS_DIR) || normal.length === 21) return null;
193
+ return normal.slice(21);
194
+ }
195
+ /**
196
+ * The image lines `![alt](path)` of some body lines, outside code fences.
197
+ * GR1029 (warning) for a path that is not inside `grimoire/screenshots/`;
198
+ * the screenshot is kept with `path: null`.
199
+ */
200
+ function readScreenshots(file, lines, sink) {
201
+ const screenshots = [];
202
+ for (const bodyLine of lines) {
203
+ if (bodyLine.fenced) continue;
204
+ for (const match of bodyLine.text.matchAll(IMAGE)) {
205
+ const written = match[2] ?? "";
206
+ const resolved = screenshotPath(file, decodeUri(written));
207
+ const at = lineAt(file, bodyLine.line);
208
+ if (resolved === null) sink.report("GR1029", `the image ${JSON.stringify(written)} is not inside grimoire/screenshots/.`, at);
209
+ screenshots.push({
210
+ alt: (match[1] ?? "").trim(),
211
+ written,
212
+ path: resolved,
213
+ at
214
+ });
215
+ }
216
+ }
217
+ return screenshots;
218
+ }
219
+ /** `%20` and the like in an image path; a malformed escape is kept as written. */
220
+ function decodeUri(value) {
221
+ try {
222
+ return decodeURI(value);
223
+ } catch {
224
+ return value;
225
+ }
226
+ }
227
+ /** A line that holds only image markup. */
228
+ function isImageLine(text) {
229
+ return IMAGE_ONLY.test(text.trim());
230
+ }
231
+ /** The line with its image markup removed, trimmed. */
232
+ function withoutImages(text) {
233
+ return text.replace(IMAGE, "").replace(/\s+/g, " ").trim();
234
+ }
170
235
 
171
236
  //#endregion
172
- export { checkHeadings, findSection, lineAt, logicalLines, normalizeKey, paragraphAfterTitle, readDocument, splitLines, textAfterTitle };
237
+ export { checkHeadings, findSection, isImageLine, lineAt, logicalLines, normalizeKey, paragraphAfterTitle, readDocument, readScreenshots, screenshotPath, splitLines, textAfterTitle, withoutImages };
173
238
  //# sourceMappingURL=markdown.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/written/markdown.ts"],"sourcesContent":["/**\n * One pass over a written file's lines: front matter, headings, `##`\n * sections and the logical lines of a list section. Every parser of a\n * written file starts from the `WrittenDocument` this module builds, so a\n * file is split once and scanned line by line, never re-scanned whole.\n */\nimport type { SourceLocation } from \"../contracts/location\";\nimport { readFrontMatter, type FrontMatterField } from \"../front-matter\";\nimport type { FindingSink } from \"./sink\";\n\n/** One line of the body, trailing whitespace (and `\\r`) removed. */\nexport type BodyLine = {\n text: string;\n /** 1-based line in the file. */\n line: number;\n /** Inside a fenced code block (the fence lines included). */\n fenced: boolean;\n};\n\n/** A Markdown heading outside code fences. */\nexport type Heading = {\n level: number;\n text: string;\n line: number;\n};\n\n/** A `##` heading and the body lines up to the next `#` or `##` heading. */\nexport type Section = {\n title: string;\n /** `title` lower-cased with single spaces, for comparing with the template. */\n key: string;\n line: number;\n lines: BodyLine[];\n};\n\n/** A written file split into its parts. */\nexport type WrittenDocument = {\n file: string;\n /** Every line of the file, `\\r` removed, trailing whitespace kept. */\n raw: string[];\n /** `null` when the file has no front matter (or it was never closed). */\n fields: Map<string, FrontMatterField> | null;\n /** The body lines (after the front matter). */\n body: BodyLine[];\n /** The first `#` heading. */\n title: Heading | null;\n /** Every `##` section, in order. */\n sections: Section[];\n /** 1-based line of the body's first line. */\n bodyStartLine: number;\n};\n\n/** A list item with its indented continuation lines joined by one space. */\nexport type LogicalLine = {\n text: string;\n line: number;\n};\n\nconst HEADING = /^(#{1,6})[ \\t]+(.+?)(?:[ \\t]+#+)?$/;\nconst FENCE = /^[ \\t]*(?:```|~~~)/;\nconst ITEM_START = /^(?:[-*][ \\t]|\\d+\\.[ \\t])/;\n\n/** Lower-case a heading or a question and collapse its spaces. */\nexport function normalizeKey(text: string): string {\n return text.trim().replace(/\\s+/g, \" \").toLowerCase();\n}\n\n/** Split text into lines on `\\n`, `\\r\\n` or a lone `\\r`. A leading BOM is dropped. */\nexport function splitLines(text: string): string[] {\n return text.replace(/^\\uFEFF/, \"\").split(/\\r\\n|\\r|\\n/);\n}\n\n/** A location of a whole line. */\nexport function lineAt(file: string, line: number): SourceLocation {\n return { file, line, column: null };\n}\n\n/**\n * Read a written file: its front matter (GR1001 when `frontMatter` is\n * `\"required\"` and the file has none; GR1002 for lines it cannot read),\n * then its headings and `##` sections.\n */\nexport function readDocument(\n file: string,\n text: string,\n frontMatter: \"required\" | \"none\",\n sink: FindingSink,\n): WrittenDocument {\n const raw = splitLines(text);\n let fields: Map<string, FrontMatterField> | null = null;\n let bodyStartLine = 1;\n\n if (frontMatter === \"required\" || raw[0]?.trim() === \"---\") {\n const result = readFrontMatter(raw.join(\"\\n\"), file);\n\n // A file with no front matter in its template may start with a `---`\n // rule that is never closed: that is body text, not a broken block.\n if (frontMatter === \"required\" || result.fields !== null) {\n for (const error of result.errors) sink.push(error);\n\n fields = result.fields;\n bodyStartLine = result.bodyStartLine;\n }\n\n if (fields === null && result.errors.length === 0 && frontMatter === \"required\") {\n sink.report(\n \"GR1001\",\n \"the file has no front matter; it must start with a `---` line.\",\n lineAt(file, 1),\n );\n }\n }\n\n const body: BodyLine[] = [];\n const headings: Heading[] = [];\n let inFence = false;\n\n for (let index = bodyStartLine - 1; index < raw.length; index++) {\n const text = (raw[index] ?? \"\").trimEnd();\n const line = index + 1;\n const fenceLine = FENCE.test(text);\n\n if (fenceLine) inFence = !inFence;\n\n const fenced = inFence || fenceLine;\n body.push({ text, line, fenced });\n\n if (fenced) continue;\n\n const heading = HEADING.exec(text);\n\n if (heading)\n headings.push({ level: (heading[1] ?? \"\").length, text: (heading[2] ?? \"\").trim(), line });\n }\n\n const sections: Section[] = [];\n let title: Heading | null = null;\n let current: Section | null = null;\n const firstBodyLine = body[0]?.line ?? bodyStartLine;\n let headingIndex = 0;\n\n for (const bodyLine of body) {\n const heading = headings[headingIndex];\n\n if (heading !== undefined && heading.line === bodyLine.line) {\n headingIndex++;\n\n if (heading.level === 1) {\n title ??= heading;\n current = null;\n continue;\n }\n\n if (heading.level === 2) {\n current = {\n title: heading.text,\n key: normalizeKey(heading.text),\n line: heading.line,\n lines: [],\n };\n sections.push(current);\n continue;\n }\n }\n\n current?.lines.push(bodyLine);\n }\n\n return {\n file,\n raw,\n fields,\n body,\n title,\n sections,\n bodyStartLine: Math.min(firstBodyLine, raw.length) || 1,\n };\n}\n\n/** The first section with this (normalised) title. */\nexport function findSection(document: WrittenDocument, key: string): Section | null {\n return document.sections.find((section) => section.key === key) ?? null;\n}\n\n/**\n * GR1006 for each required `##` heading that is missing (and for a missing\n * `#` title when `title` is required); GR1007 for each `##` heading the\n * template does not have, or one written twice.\n */\nexport function checkHeadings(\n document: WrittenDocument,\n template: { title: boolean; required: readonly string[]; optional: readonly string[] },\n sink: FindingSink,\n): void {\n const where = lineAt(document.file, document.title?.line ?? document.bodyStartLine);\n\n if (template.title && document.title === null) {\n sink.report(\"GR1006\", \"the file has no `# ` title heading.\", where);\n }\n\n for (const required of template.required) {\n if (!document.sections.some((section) => section.key === normalizeKey(required))) {\n sink.report(\"GR1006\", `the heading \"## ${required}\" is missing.`, where);\n }\n }\n\n const known = new Set([...template.required, ...template.optional].map(normalizeKey));\n const seen = new Set<string>();\n\n for (const section of document.sections) {\n if (!known.has(section.key)) {\n sink.report(\n \"GR1007\",\n `the heading \"## ${section.title}\" is not part of the template.`,\n lineAt(document.file, section.line),\n );\n } else if (seen.has(section.key)) {\n sink.report(\n \"GR1007\",\n `the heading \"## ${section.title}\" is written twice; only the first is read.`,\n lineAt(document.file, section.line),\n );\n }\n\n seen.add(section.key);\n }\n}\n\n/**\n * The logical lines of some body lines: a line that does not start with\n * whitespace (or that starts a list item) opens a new logical line, and the\n * indented lines right after it are joined to it with one space. Blank lines\n * and fenced lines end the current one.\n */\nexport function logicalLines(lines: readonly BodyLine[]): LogicalLine[] {\n const result: LogicalLine[] = [];\n let open: LogicalLine | null = null;\n\n for (const bodyLine of lines) {\n const trimmed = bodyLine.text.trim();\n\n if (bodyLine.fenced || trimmed === \"\") {\n open = null;\n continue;\n }\n\n const indented = /^[ \\t]/.test(bodyLine.text);\n\n if (open !== null && indented && !ITEM_START.test(trimmed)) {\n open.text = `${open.text} ${trimmed}`;\n continue;\n }\n\n open = { text: trimmed, line: bodyLine.line };\n result.push(open);\n }\n\n return result;\n}\n\n/** The first paragraph after the `# ` title: non-blank lines up to a blank line or a heading. */\nexport function paragraphAfterTitle(document: WrittenDocument): string | null {\n if (document.title === null) return null;\n\n const parts: string[] = [];\n\n for (const bodyLine of document.body) {\n if (bodyLine.line <= document.title.line) continue;\n\n const trimmed = bodyLine.text.trim();\n\n if (bodyLine.fenced || trimmed.startsWith(\"#\")) break;\n\n if (trimmed === \"\") {\n if (parts.length > 0) break;\n continue;\n }\n\n parts.push(trimmed);\n }\n\n return parts.length > 0 ? parts.join(\" \") : null;\n}\n\n/** The body text after the `# ` title (or the whole body), trimmed. */\nexport function textAfterTitle(document: WrittenDocument, endLine?: number): string {\n const from = document.title?.line ?? 0;\n\n return document.body\n .filter(\n (bodyLine) => bodyLine.line > from && (endLine === undefined || bodyLine.line < endLine),\n )\n .map((bodyLine) => bodyLine.text)\n .join(\"\\n\")\n .trim();\n}\n"],"mappings":";;;AA0DA,MAAM,UAAU;AAChB,MAAM,QAAQ;AACd,MAAM,aAAa;;AAGnB,SAAgB,aAAa,MAAsB;CACjD,OAAO,KAAK,KAAK,CAAC,CAAC,QAAQ,QAAQ,GAAG,CAAC,CAAC,YAAY;AACtD;;AAGA,SAAgB,WAAW,MAAwB;CACjD,OAAO,KAAK,QAAQ,WAAW,EAAE,CAAC,CAAC,MAAM,YAAY;AACvD;;AAGA,SAAgB,OAAO,MAAc,MAA8B;CACjE,OAAO;EAAE;EAAM;EAAM,QAAQ;CAAK;AACpC;;;;;;AAOA,SAAgB,aACd,MACA,MACA,aACA,MACiB;CACjB,MAAM,MAAM,WAAW,IAAI;CAC3B,IAAI,SAA+C;CACnD,IAAI,gBAAgB;CAEpB,IAAI,gBAAgB,cAAc,IAAI,EAAE,EAAE,KAAK,MAAM,OAAO;EAC1D,MAAM,SAAS,gBAAgB,IAAI,KAAK,IAAI,GAAG,IAAI;EAInD,IAAI,gBAAgB,cAAc,OAAO,WAAW,MAAM;GACxD,KAAK,MAAM,SAAS,OAAO,QAAQ,KAAK,KAAK,KAAK;GAElD,SAAS,OAAO;GAChB,gBAAgB,OAAO;EACzB;EAEA,IAAI,WAAW,QAAQ,OAAO,OAAO,WAAW,KAAK,gBAAgB,YACnE,KAAK,OACH,UACA,kEACA,OAAO,MAAM,C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GAC5B;EACF;EAEA,OAAO;GAAE,MAAM;GAAS,MAAM,SAAS;EAAK;EAC5C,OAAO,KAAK,IAAI;CAClB;CAEA,OAAO;AACT;;AAGA,SAAgB,oBAAoB,UAA0C;CAC5E,IAAI,SAAS,UAAU,MAAM,OAAO;CAEpC,MAAM,QAAkB,CAAC;CAEzB,KAAK,MAAM,YAAY,SAAS,MAAM;EACpC,IAAI,SAAS,QAAQ,SAAS,MAAM,MAAM;EAE1C,MAAM,UAAU,SAAS,KAAK,KAAK;EAEnC,IAAI,SAAS,UAAU,QAAQ,WAAW,GAAG,GAAG;EAEhD,IAAI,YAAY,IAAI;GAClB,IAAI,MAAM,SAAS,GAAG;GACtB;EACF;EAEA,MAAM,KAAK,OAAO;CACpB;CAEA,OAAO,MAAM,SAAS,IAAI,MAAM,KAAK,GAAG,IAAI;AAC9C;;AAGA,SAAgB,eAAe,UAA2B,SAA0B;CAClF,MAAM,OAAO,SAAS,OAAO,QAAQ;CAErC,OAAO,SAAS,KACb,QACE,aAAa,SAAS,OAAO,SAAS,YAAY,UAAa,SAAS,OAAO,QAClF,CAAC,CACA,KAAK,aAAa,SAAS,IAAI,CAAC,CAChC,KAAK,IAAI,CAAC,CACV,KAAK;AACV"}
1
+ {"version":3,"file":"markdown.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/written/markdown.ts"],"sourcesContent":["/**\n * One pass over a written file's lines: front matter, headings, `##`\n * sections and the logical lines of a list section. Every parser of a\n * written file starts from the `WrittenDocument` this module builds, so a\n * file is split once and scanned line by line, never re-scanned whole.\n */\nimport path from \"node:path\";\nimport type { SourceLocation } from \"../contracts/location\";\nimport type { WrittenScreenshot } from \"../contracts/written\";\nimport { readFrontMatter, type FrontMatterField } from \"../front-matter\";\nimport type { FindingSink } from \"./sink\";\n\n/** One line of the body, trailing whitespace (and `\\r`) removed. */\nexport type BodyLine = {\n text: string;\n /** 1-based line in the file. */\n line: number;\n /** Inside a fenced code block (the fence lines included). */\n fenced: boolean;\n};\n\n/** A Markdown heading outside code fences. */\nexport type Heading = {\n level: number;\n text: string;\n line: number;\n};\n\n/** A `##` heading and the body lines up to the next `#` or `##` heading. */\nexport type Section = {\n title: string;\n /** `title` lower-cased with single spaces, for comparing with the template. */\n key: string;\n line: number;\n lines: BodyLine[];\n};\n\n/** A written file split into its parts. */\nexport type WrittenDocument = {\n file: string;\n /** Every line of the file, `\\r` removed, trailing whitespace kept. */\n raw: string[];\n /** `null` when the file has no front matter (or it was never closed). */\n fields: Map<string, FrontMatterField> | null;\n /** The body lines (after the front matter). */\n body: BodyLine[];\n /** The first `#` heading. */\n title: Heading | null;\n /** Every `##` section, in order. */\n sections: Section[];\n /** 1-based line of the body's first line. */\n bodyStartLine: number;\n};\n\n/** A list item with its indented continuation lines joined by one space. */\nexport type LogicalLine = {\n text: string;\n line: number;\n};\n\nconst HEADING = /^(#{1,6})[ \\t]+(.+?)(?:[ \\t]+#+)?$/;\nconst FENCE = /^[ \\t]*(?:```|~~~)/;\nconst ITEM_START = /^(?:[-*][ \\t]|\\d+\\.[ \\t])/;\nconst IMAGE = /!\\[([^\\]]*)\\]\\(\\s*<?([^)\\s>]+)>?(?:\\s+(?:\"[^\"]*\"|'[^']*'))?\\s*\\)/g;\nconst IMAGE_ONLY = /^(?:!\\[[^\\]]*\\]\\([^)]*\\)\\s*)+$/;\n/** Where screenshots live, relative to the project root. */\nconst SCREENSHOTS_DIR = \"grimoire/screenshots/\";\n\n/** Lower-case a heading or a question and collapse its spaces. */\nexport function normalizeKey(text: string): string {\n return text.trim().replace(/\\s+/g, \" \").toLowerCase();\n}\n\n/** Split text into lines on `\\n`, `\\r\\n` or a lone `\\r`. A leading BOM is dropped. */\nexport function splitLines(text: string): string[] {\n return text.replace(/^\\uFEFF/, \"\").split(/\\r\\n|\\r|\\n/);\n}\n\n/** A location of a whole line. */\nexport function lineAt(file: string, line: number): SourceLocation {\n return { file, line, column: null };\n}\n\n/**\n * Read a written file: its front matter (GR1001 when `frontMatter` is\n * `\"required\"` and the file has none; GR1002 for lines it cannot read),\n * then its headings and `##` sections.\n */\nexport function readDocument(\n file: string,\n text: string,\n frontMatter: \"required\" | \"none\",\n sink: FindingSink,\n): WrittenDocument {\n const raw = splitLines(text);\n let fields: Map<string, FrontMatterField> | null = null;\n let bodyStartLine = 1;\n\n if (frontMatter === \"required\" || raw[0]?.trim() === \"---\") {\n const result = readFrontMatter(raw.join(\"\\n\"), file);\n\n // A file with no front matter in its template may start with a `---`\n // rule that is never closed: that is body text, not a broken block.\n if (frontMatter === \"required\" || result.fields !== null) {\n for (const error of result.errors) sink.push(error);\n\n fields = result.fields;\n bodyStartLine = result.bodyStartLine;\n }\n\n if (fields === null && result.errors.length === 0 && frontMatter === \"required\") {\n sink.report(\n \"GR1001\",\n \"the file has no front matter; it must start with a `---` line.\",\n lineAt(file, 1),\n );\n }\n }\n\n const body: BodyLine[] = [];\n const headings: Heading[] = [];\n let inFence = false;\n\n for (let index = bodyStartLine - 1; index < raw.length; index++) {\n const text = (raw[index] ?? \"\").trimEnd();\n const line = index + 1;\n const fenceLine = FENCE.test(text);\n\n if (fenceLine) inFence = !inFence;\n\n const fenced = inFence || fenceLine;\n body.push({ text, line, fenced });\n\n if (fenced) continue;\n\n const heading = HEADING.exec(text);\n\n if (heading)\n headings.push({ level: (heading[1] ?? \"\").length, text: (heading[2] ?? \"\").trim(), line });\n }\n\n const sections: Section[] = [];\n let title: Heading | null = null;\n let current: Section | null = null;\n const firstBodyLine = body[0]?.line ?? bodyStartLine;\n let headingIndex = 0;\n\n for (const bodyLine of body) {\n const heading = headings[headingIndex];\n\n if (heading !== undefined && heading.line === bodyLine.line) {\n headingIndex++;\n\n if (heading.level === 1) {\n title ??= heading;\n current = null;\n continue;\n }\n\n if (heading.level === 2) {\n current = {\n title: heading.text,\n key: normalizeKey(heading.text),\n line: heading.line,\n lines: [],\n };\n sections.push(current);\n continue;\n }\n }\n\n current?.lines.push(bodyLine);\n }\n\n return {\n file,\n raw,\n fields,\n body,\n title,\n sections,\n bodyStartLine: Math.min(firstBodyLine, raw.length) || 1,\n };\n}\n\n/** The first section with this (normalised) title. */\nexport function findSection(document: WrittenDocument, key: string): Section | null {\n return document.sections.find((section) => section.key === key) ?? null;\n}\n\n/**\n * GR1006 for each required `##` heading that is missing (and for a missing\n * `#` title when `title` is required); GR1007 for each `##` heading the\n * template does not have, or one written twice.\n */\nexport function checkHeadings(\n document: WrittenDocument,\n template: { title: boolean; required: readonly string[]; optional: readonly string[] },\n sink: FindingSink,\n): void {\n const where = lineAt(document.file, document.title?.line ?? document.bodyStartLine);\n\n if (template.title && document.title === null) {\n sink.report(\"GR1006\", \"the file has no `# ` title heading.\", where);\n }\n\n for (const required of template.required) {\n if (!document.sections.some((section) => section.key === normalizeKey(required))) {\n sink.report(\"GR1006\", `the heading \"## ${required}\" is missing.`, where);\n }\n }\n\n const known = new Set([...template.required, ...template.optional].map(normalizeKey));\n const seen = new Set<string>();\n\n for (const section of document.sections) {\n if (!known.has(section.key)) {\n sink.report(\n \"GR1007\",\n `the heading \"## ${section.title}\" is not part of the template.`,\n lineAt(document.file, section.line),\n );\n } else if (seen.has(section.key)) {\n sink.report(\n \"GR1007\",\n `the heading \"## ${section.title}\" is written twice; only the first is read.`,\n lineAt(document.file, section.line),\n );\n }\n\n seen.add(section.key);\n }\n}\n\n/**\n * The logical lines of some body lines: a line that does not start with\n * whitespace (or that starts a list item) opens a new logical line, and the\n * indented lines right after it are joined to it with one space. Blank lines\n * and fenced lines end the current one.\n */\nexport function logicalLines(lines: readonly BodyLine[]): LogicalLine[] {\n const result: LogicalLine[] = [];\n let open: LogicalLine | null = null;\n\n for (const bodyLine of lines) {\n const trimmed = bodyLine.text.trim();\n\n if (bodyLine.fenced || trimmed === \"\") {\n open = null;\n continue;\n }\n\n const indented = /^[ \\t]/.test(bodyLine.text);\n\n if (open !== null && indented && !ITEM_START.test(trimmed)) {\n open.text = `${open.text} ${trimmed}`;\n continue;\n }\n\n open = { text: trimmed, line: bodyLine.line };\n result.push(open);\n }\n\n return result;\n}\n\n/** The first paragraph after the `# ` title: non-blank lines up to a blank line or a heading. */\nexport function paragraphAfterTitle(document: WrittenDocument): string | null {\n if (document.title === null) return null;\n\n const parts: string[] = [];\n\n for (const bodyLine of document.body) {\n if (bodyLine.line <= document.title.line) continue;\n\n const trimmed = bodyLine.text.trim();\n\n if (bodyLine.fenced || trimmed.startsWith(\"#\")) break;\n\n if (trimmed === \"\") {\n if (parts.length > 0) break;\n continue;\n }\n\n // An image line is not text: a screenshot may sit right under the title.\n if (IMAGE_ONLY.test(trimmed)) continue;\n\n parts.push(trimmed);\n }\n\n return parts.length > 0 ? parts.join(\" \") : null;\n}\n\n/** The body text after the `# ` title (or the whole body), trimmed. */\nexport function textAfterTitle(document: WrittenDocument, endLine?: number): string {\n const from = document.title?.line ?? 0;\n\n return document.body\n .filter(\n (bodyLine) => bodyLine.line > from && (endLine === undefined || bodyLine.line < endLine),\n )\n .map((bodyLine) => bodyLine.text)\n .join(\"\\n\")\n .trim();\n}\n\n/**\n * The path under `grimoire/screenshots/` an image line points at, or `null`\n * when it points elsewhere. The path is relative to the Markdown file, or\n * starts with `/grimoire/screenshots/`.\n */\nexport function screenshotPath(file: string, written: string): string | null {\n const target = written.replace(/[?#].*$/, \"\").replace(/\\\\/g, \"/\");\n\n if (/^[a-z][a-z0-9+.-]*:/i.test(target) || target.startsWith(\"//\")) return null;\n\n const resolved = target.startsWith(\"/\")\n ? path.posix.normalize(target.slice(1))\n : path.posix.join(path.posix.dirname(file.replace(/\\\\/g, \"/\")), target);\n const normal = path.posix.normalize(resolved);\n\n if (!normal.startsWith(SCREENSHOTS_DIR) || normal.length === SCREENSHOTS_DIR.length) return null;\n\n return normal.slice(SCREENSHOTS_DIR.length);\n}\n\n/**\n * The image lines `![alt](path)` of some body lines, outside code fences.\n * GR1029 (warning) for a path that is not inside `grimoire/screenshots/`;\n * the screenshot is kept with `path: null`.\n */\nexport function readScreenshots(\n file: string,\n lines: readonly BodyLine[],\n sink: FindingSink,\n): WrittenScreenshot[] {\n const screenshots: WrittenScreenshot[] = [];\n\n for (const bodyLine of lines) {\n if (bodyLine.fenced) continue;\n\n for (const match of bodyLine.text.matchAll(IMAGE)) {\n const written = match[2] ?? \"\";\n const resolved = screenshotPath(file, decodeUri(written));\n const at = lineAt(file, bodyLine.line);\n\n if (resolved === null) {\n sink.report(\n \"GR1029\",\n `the image ${JSON.stringify(written)} is not inside grimoire/screenshots/.`,\n at,\n );\n }\n\n screenshots.push({ alt: (match[1] ?? \"\").trim(), written, path: resolved, at });\n }\n }\n\n return screenshots;\n}\n\n/** `%20` and the like in an image path; a malformed escape is kept as written. */\nfunction decodeUri(value: string): string {\n try {\n return decodeURI(value);\n } catch {\n return value;\n }\n}\n\n/** A line that holds only image markup. */\nexport function isImageLine(text: string): boolean {\n return IMAGE_ONLY.test(text.trim());\n}\n\n/** The line with its image markup removed, trimmed. */\nexport function withoutImages(text: string): string {\n return text.replace(IMAGE, \"\").replace(/\\s+/g, \" \").trim();\n}\n"],"mappings":";;;;;;;;;;AA4DA,MAAM,UAAU;AAChB,MAAM,QAAQ;AACd,MAAM,aAAa;AACnB,MAAM,QAAQ;AACd,MAAM,aAAa;;AAEnB,MAAM,kBAAkB;;AAGxB,SAAgB,aAAa,MAAsB;CACjD,OAAO,KAAK,KAAK,CAAC,CAAC,QAAQ,QAAQ,GAAG,CAAC,CAAC,YAAY;AACtD;;AAGA,SAAgB,WAAW,MAAwB;CACjD,OAAO,KAAK,QAAQ,WAAW,EAAE,CAAC,CAAC,MAAM,YAAY;AACvD;;AAGA,SAAgB,OAAO,MAAc,MAA8B;CACjE,OAAO;EAAE;EAAM;EAAM,QAAQ;CAAK;AACpC;;;;;;AAOA,SAAgB,aACd,MACA,MACA,aACA,MACiB;CACjB,MAAM,MAAM,WAAW,IAAI;CAC3B,IAAI,SAA+C;CACnD,IAAI,gBAAgB;CAEpB,IAAI,gBAAgB,cAAc,IAAI,EAAE,EAAE,KAAK,MAAM,OAA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sources":["../../../../../../../../packages/grimoire/src/written/parse-grimoire.ts"],"mappings":";;;;YA6BY;EACV,SAAS;;EAET,UAAU;;;;;;;;;;wBAkeU,cAAc,eAAe,QAAQ"}
1
+ {"version":3,"file":"parse-grimoire.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/written/parse-grimoire.ts"],"mappings":";;;;YA6BY;EACV,SAAS;;EAET,UAAU;;;;;;;;;;wBAmeU,cAAc,eAAe,QAAQ"}
@@ -89,7 +89,7 @@ var Walker = class {
89
89
  for (const name of top.files) this.unknown(`${GRIMOIRE_DIR}/${name}`);
90
90
  for (const name of top.dirs) {
91
91
  const dir = `${GRIMOIRE_DIR}/${name}`;
92
- if (name === "book") continue;
92
+ if (name === "book" || name === "screenshots") continue;
93
93
  else if (name === "features") await this.walkFeatures(dir);
94
94
  else if (name === "apps") await this.walkApps(dir);
95
95
  else if (name === "tasks") await this.walkTasks(dir);
@@ -1 +1 @@
1
- {"version":3,"file":"parse-grimoire.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/written/parse-grimoire.ts"],"sourcesContent":["/**\n * Walks `<root>/grimoire`, reads each written file once, and hands it to the\n * parser of its kind. Paths are built as project-relative POSIX strings from\n * the folder names, so they read the same on every platform.\n */\nimport { createHash } from \"node:crypto\";\nimport type { Dirent } from \"node:fs\";\nimport { readFile, readdir, realpath, stat } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { GrimoireFinding } from \"../contracts/findings\";\nimport type { Located } from \"../contracts/location\";\nimport type {\n WrittenApp,\n WrittenBlockFile,\n WrittenFeature,\n WrittenGrimoire,\n WrittenLayout,\n WrittenPage,\n WrittenRelease,\n WrittenTask,\n} from \"../contracts/written\";\nimport { GRIMOIRE_DIR } from \"../paths\";\nimport { parseAppReadme, parseBlockFile, parseLayout, parsePage, type AppReadme } from \"./apps\";\nimport { parseChangelog, parseFeatureReadme, parseFlow, parseVersionBrief } from \"./features\";\nimport { lineAt } from \"./markdown\";\nimport { FindingSink } from \"./sink\";\nimport { parseRelease, parseTask, type TaskPlace } from \"./tasks-releases\";\n\n/** What `parseGrimoire()` returns. */\nexport type ParseGrimoireResult = {\n written: WrittenGrimoire;\n /** Structure findings (`GR1xxx`), in file and line order. */\n findings: GrimoireFinding[];\n};\n\ntype PageType = \"page\" | \"screen\";\n\n/** One written file to read, and what it is. */\ntype Job =\n | { type: \"feature-readme\"; file: string; feature: string }\n | { type: \"changelog\"; file: string; feature: string }\n | { type: \"flow\"; file: string; feature: string; name: string }\n | { type: \"version\"; file: string; feature: string; major: number }\n | { type: \"app-readme\"; file: string; app: string; fallbackType: \"site\" | \"mobile\" }\n | { type: \"layout\"; file: string; app: string; id: string }\n | { type: \"page\"; file: string; app: string; pageType: PageType; id: string }\n | { type: \"block\"; file: string; app: string; pageType: PageType; page: string; id: string }\n | { type: \"task\"; file: string; place: TaskPlace }\n | { type: \"release\"; file: string; name: string };\n\ntype Listing = { files: string[]; dirs: string[] };\n\nconst TASK_FILE = /^(T-\\d+)-[a-z0-9]+(?:-[a-z0-9]+)*\\.md$/;\nconst MONTH = /^\\d{4}-(?:0[1-9]|1[0-2])$/;\nconst VERSION_BRIEF = /^v(\\d+)\\.md$/;\nconst decoder = new TextDecoder(\"utf-8\", { fatal: true });\n\n/** The walk over the folders: what to read, and the layout findings. */\nclass Walker {\n public readonly jobs: Job[] = [];\n /** Feature and app folders, in name order. */\n public readonly features: string[] = [];\n public readonly apps: { id: string; dir: string; hasReadme: boolean }[] = [];\n /** Real paths of the folders the deep walks entered: a linked folder loop is walked once. */\n private readonly entered = new Set<string>();\n\n public constructor(\n private readonly root: string,\n private readonly sink: FindingSink,\n ) {}\n\n private absolute(file: string): string {\n return path.join(this.root, ...file.split(\"/\"));\n }\n\n /** The visible files and folders of a folder, each list in name order. Dot files are skipped. */\n public async list(dir: string): Promise<Listing> {\n let entries: Dirent[];\n\n try {\n entries = await readdir(this.absolute(dir), { withFileTypes: true });\n } catch {\n return { files: [], dirs: [] };\n }\n\n const files: string[] = [];\n const dirs: string[] = [];\n\n for (const entry of entries) {\n if (entry.name.startsWith(\".\")) continue;\n\n let isDirectory = entry.isDirectory();\n let isFile = entry.isFile();\n\n if (entry.isSymbolicLink()) {\n const target = await stat(this.absolute(`${dir}/${entry.name}`)).catch(() => null);\n isDirectory = target?.isDirectory() ?? false;\n isFile = target?.isFile() ?? false;\n }\n\n if (isDirectory) dirs.push(entry.name);\n else if (isFile) files.push(entry.name);\n }\n\n const byName = (left: string, right: string): number =>\n left < right ? -1 : left > right ? 1 : 0;\n\n return { files: files.sort(byName), dirs: dirs.sort(byName) };\n }\n\n /** GR1020 for a file the layout has no place for. */\n public unknown(file: string, sink: FindingSink = this.sink): void {\n sink.report(\"GR1020\", `the file ${file} is not part of the grimoire layout.`, lineAt(file, 1));\n }\n\n /** Whether a deep walk enters `dir` for the first time (a linked folder loop is entered once). */\n private async enter(dir: string): Promise<boolean> {\n const real = await realpath(this.absolute(dir)).catch(() => null);\n\n if (real === null || this.entered.has(real)) return false;\n\n this.entered.add(real);\n\n return true;\n }\n\n /** GR1020 for every file under a folder the layout has no place for (a linked folder loop is walked once). */\n public async unknownFolder(dir: string, sink: FindingSink = this.sink, depth = 0): Promise<void> {\n if (depth > 16 || !(await this.enter(dir))) return;\n\n const listing = await this.list(dir);\n\n for (const name of listing.files) this.unknown(`${dir}/${name}`, sink);\n for (const name of listing.dirs) await this.unknownFolder(`${dir}/${name}`, sink, depth + 1);\n }\n\n public async walk(): Promise<void> {\n const top = await this.list(GRIMOIRE_DIR);\n\n for (const name of top.files) this.unknown(`${GRIMOIRE_DIR}/${name}`);\n\n for (const name of top.dirs) {\n const dir = `${GRIMOIRE_DIR}/${name}`;\n\n if (name === \"book\") continue;\n else if (name === \"features\") await this.walkFeatures(dir);\n else if (name === \"apps\") await this.walkApps(dir);\n else if (name === \"tasks\") await this.walkTasks(dir);\n else if (name === \"releases\") await this.walkReleases(dir);\n else await this.unknownFolder(dir);\n }\n }\n\n private async walkFeatures(featuresDir: string): Promise<void> {\n const listing = await this.list(featuresDir);\n\n for (const name of listing.files) {\n if (name !== \"index.json\") this.unknown(`${featuresDir}/${name}`);\n }\n\n for (const feature of listing.dirs) {\n const dir = `${featuresDir}/${feature}`;\n const sink = this.sink.scope({ feature });\n const inside = await this.list(dir);\n\n this.features.push(feature);\n\n for (const name of inside.files) {\n const file = `${dir}/${name}`;\n\n if (name === \"README.md\") this.jobs.push({ type: \"feature-readme\", file, feature });\n else if (name === \"CHANGELOG.md\") this.jobs.push({ type: \"changelog\", file, feature });\n else if (!name.endsWith(\".json\")) this.unknown(file, sink);\n }\n\n if (!inside.files.includes(\"README.md\")) {\n sink.report(\n \"GR1021\",\n `the feature folder ${dir} has no README.md.`,\n lineAt(`${dir}/README.md`, 1),\n );\n }\n\n for (const sub of inside.dirs) {\n const subDir = `${dir}/${sub}`;\n\n if (sub === \"flows\") {\n const flows = await this.list(subDir);\n\n for (const name of flows.files) {\n const file = `${subDir}/${name}`;\n\n if (name.endsWith(\".md\"))\n this.jobs.push({ type: \"flow\", file, feature, name: name.slice(0, -3) });\n else if (!name.endsWith(\".bookmap.json\")) this.unknown(file, sink);\n }\n\n for (const name of flows.dirs) await this.unknownFolder(`${subDir}/${name}`, sink);\n } else if (sub === \"versions\") {\n const versions = await this.list(subDir);\n\n for (const name of versions.files) {\n const match = VERSION_BRIEF.exec(name);\n const file = `${subDir}/${name}`;\n\n if (match) this.jobs.push({ type: \"version\", file, feature, major: Number(match[1]) });\n else this.unknown(file, sink);\n }\n\n for (const name of versions.dirs) await this.unknownFolder(`${subDir}/${name}`, sink);\n } else {\n await this.unknownFolder(subDir, sink);\n }\n }\n }\n }\n\n private async walkApps(appsDir: string): Promise<void> {\n const listing = await this.list(appsDir);\n\n for (const name of listing.files) this.unknown(`${appsDir}/${name}`);\n\n for (const app of listing.dirs) {\n const dir = `${appsDir}/${app}`;\n const sink = this.sink.scope({ app });\n const inside = await this.list(dir);\n const hasReadme = inside.files.includes(\"README.md\");\n\n this.apps.push({ id: app, dir, hasReadme });\n\n for (const name of inside.files) {\n if (name === \"README.md\") {\n this.jobs.push({\n type: \"app-readme\",\n file: `${dir}/${name}`,\n app,\n fallbackType: inside.dirs.includes(\"screens\") ? \"mobile\" : \"site\",\n });\n } else {\n this.unknown(`${dir}/${name}`, sink);\n }\n }\n\n if (!hasReadme) {\n sink.report(\n \"GR1021\",\n `the app folder ${dir} has no README.md.`,\n lineAt(`${dir}/README.md`, 1),\n );\n }\n\n for (const sub of inside.dirs) {\n const subDir = `${dir}/${sub}`;\n\n if (sub === \"layouts\") {\n const layouts = await this.list(subDir);\n\n for (const name of layouts.files) {\n const file = `${subDir}/${name}`;\n\n if (name.endsWith(\".md\"))\n this.jobs.push({ type: \"layout\", file, app, id: name.slice(0, -3) });\n else this.unknown(file, sink);\n }\n\n for (const name of layouts.dirs) await this.unknownFolder(`${subDir}/${name}`, sink);\n } else if (sub === \"pages\" || sub === \"screens\") {\n await this.walkPages(subDir, app, sub === \"pages\" ? \"page\" : \"screen\", sink);\n } else {\n await this.unknownFolder(subDir, sink);\n }\n }\n }\n }\n\n private async walkPages(\n pagesDir: string,\n app: string,\n pageType: PageType,\n sink: FindingSink,\n ): Promise<void> {\n const listing = await this.list(pagesDir);\n\n for (const name of listing.files) this.unknown(`${pagesDir}/${name}`, sink);\n\n for (const page of listing.dirs) {\n const dir = `${pagesDir}/${page}`;\n const inside = await this.list(dir);\n\n for (const name of inside.files) {\n if (name === \"README.md\")\n this.jobs.push({ type: \"page\", file: `${dir}/${name}`, app, pageType, id: page });\n else this.unknown(`${dir}/${name}`, sink);\n }\n\n if (!inside.files.includes(\"README.md\")) {\n sink.report(\n \"GR1021\",\n `the ${pageType} folder ${dir} has no README.md.`,\n lineAt(`${dir}/README.md`, 1),\n );\n }\n\n for (const sub of inside.dirs) {\n const subDir = `${dir}/${sub}`;\n\n if (sub !== \"blocks\") {\n await this.unknownFolder(subDir, sink);\n continue;\n }\n\n const blocks = await this.list(subDir);\n\n for (const name of blocks.files) {\n const file = `${subDir}/${name}`;\n\n if (name.endsWith(\".md\"))\n this.jobs.push({ type: \"block\", file, app, pageType, page, id: name.slice(0, -3) });\n else this.unknown(file, sink);\n }\n\n for (const name of blocks.dirs) await this.unknownFolder(`${subDir}/${name}`, sink);\n }\n }\n }\n\n /** GR1023 for a task file outside `open/` and `done/<yyyy-mm>/`; other files get GR1020. */\n private async misplacedTasks(dir: string, depth = 0): Promise<void> {\n if (depth > 16 || !(await this.enter(dir))) return;\n\n const listing = await this.list(dir);\n\n for (const name of listing.files) this.misplacedTask(`${dir}/${name}`);\n for (const name of listing.dirs) await this.misplacedTasks(`${dir}/${name}`, depth + 1);\n }\n\n private misplacedTask(file: string): void {\n if (!file.endsWith(\".md\")) {\n this.unknown(file);\n return;\n }\n\n this.sink.report(\n \"GR1023\",\n `the task file ${file} is not in tasks/open/ or tasks/done/<yyyy-mm>/; it is not read.`,\n lineAt(file, 1),\n );\n }\n\n private taskFiles(\n dir: string,\n names: readonly string[],\n folder: \"open\" | \"done\",\n month: string | null,\n ): void {\n for (const name of names) {\n const file = `${dir}/${name}`;\n\n if (!name.endsWith(\".md\")) {\n this.unknown(file);\n continue;\n }\n\n const match = TASK_FILE.exec(name);\n\n if (!match) {\n this.sink.report(\n \"GR1023\",\n `the task file name ${name} is not T-<n>-<slug>.md.`,\n lineAt(file, 1),\n );\n }\n\n this.jobs.push({ type: \"task\", file, place: { folder, month, nameId: match?.[1] ?? null } });\n }\n }\n\n private async walkTasks(tasksDir: string): Promise<void> {\n const listing = await this.list(tasksDir);\n\n for (const name of listing.files) {\n if (name !== \"index.json\") this.misplacedTask(`${tasksDir}/${name}`);\n }\n\n for (const sub of listing.dirs) {\n const dir = `${tasksDir}/${sub}`;\n const inside = await this.list(dir);\n\n if (sub === \"open\") {\n this.taskFiles(dir, inside.files, \"open\", null);\n for (const name of inside.dirs) await this.misplacedTasks(`${dir}/${name}`);\n } else if (sub === \"done\") {\n for (const name of inside.files) this.misplacedTask(`${dir}/${name}`);\n\n for (const month of inside.dirs) {\n const monthDir = `${dir}/${month}`;\n\n if (!MONTH.test(month)) {\n await this.misplacedTasks(monthDir);\n continue;\n }\n\n const files = await this.list(monthDir);\n\n this.taskFiles(monthDir, files.files, \"done\", month);\n for (const name of files.dirs) await this.misplacedTasks(`${monthDir}/${name}`);\n }\n } else {\n await this.misplacedTasks(dir);\n }\n }\n }\n\n private async walkReleases(releasesDir: string): Promise<void> {\n const listing = await this.list(releasesDir);\n\n for (const name of listing.files) {\n const file = `${releasesDir}/${name}`;\n\n if (name.endsWith(\".md\")) this.jobs.push({ type: \"release\", file, name: name.slice(0, -3) });\n else this.unknown(file);\n }\n\n for (const name of listing.dirs) await this.unknownFolder(`${releasesDir}/${name}`);\n }\n}\n\n/**\n * Files read at once. A grimoire grows by a task file a change, so reading\n * them all at once runs out of file handles (`EMFILE`) on a large project.\n */\nconst READ_CONCURRENCY = 32;\n\n/** `items.map(run)` with at most `limit` calls in flight; results keep the order of `items`. */\nasync function mapLimited<T, R>(\n items: readonly T[],\n limit: number,\n run: (item: T) => Promise<R>,\n): Promise<R[]> {\n const results = new Array<R>(items.length);\n let next = 0;\n\n const worker = async (): Promise<void> => {\n while (next < items.length) {\n const index = next++;\n\n results[index] = await run(items[index] as T);\n }\n };\n\n await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));\n\n return results;\n}\n\n/** Read one file as UTF-8; `null` (with GR1025) when it cannot be read or is not UTF-8. */\nasync function readWritten(\n root: string,\n file: string,\n sink: FindingSink,\n): Promise<{ bytes: Uint8Array; text: string } | null> {\n try {\n const bytes = await readFile(path.join(root, ...file.split(\"/\")));\n\n try {\n return { bytes, text: decoder.decode(bytes) };\n } catch {\n sink.report(\"GR1025\", `the file ${file} is not UTF-8 text.`, lineAt(file, 1));\n\n return null;\n }\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n\n sink.report(\"GR1025\", `the file ${file} cannot be read: ${reason}`, lineAt(file, 1));\n\n return null;\n }\n}\n\nfunction sinkFor(job: Job, sink: FindingSink): FindingSink {\n switch (job.type) {\n case \"feature-readme\":\n case \"changelog\":\n case \"version\":\n return sink.scope({ feature: job.feature });\n case \"flow\":\n return sink.scope({ feature: job.feature, flow: `${job.feature}/${job.name}` });\n case \"app-readme\":\n case \"layout\":\n case \"page\":\n case \"block\":\n return sink.scope({ app: job.app });\n case \"task\":\n return sink.scope({ task: job.place.nameId });\n case \"release\":\n return sink;\n }\n}\n\nfunction taskNumber(task: WrittenTask): number {\n const match = /^T-(\\d+)$/.exec(task.id.value) ?? /(?:^|\\/)T-(\\d+)-[^/]*$/.exec(task.file);\n\n return match ? Number(match[1]) : Number.MAX_SAFE_INTEGER;\n}\n\n/**\n * Parse every written file under `<root>/grimoire`. A project without a\n * `grimoire/` folder gives `written.exists === false` and no findings. Bad\n * input never throws: each problem is a `GR1xxx` finding at its line, and\n * the rest of the file is still read.\n *\n * @param root Absolute project root.\n */\nexport async function parseGrimoire(root: string): Promise<ParseGrimoireResult> {\n const absoluteRoot = path.resolve(root);\n const sink = new FindingSink();\n const hash = createHash(\"sha256\");\n const written: WrittenGrimoire = {\n root: absoluteRoot,\n exists: false,\n features: [],\n apps: [],\n tasks: [],\n releases: [],\n hash: \"\",\n };\n\n const grimoireStat = await stat(path.join(absoluteRoot, GRIMOIRE_DIR)).catch(() => null);\n\n if (!grimoireStat?.isDirectory()) {\n written.hash = hash.digest(\"hex\");\n\n return { written, findings: [] };\n }\n\n written.exists = true;\n\n const walker = new Walker(absoluteRoot, sink);\n await walker.walk();\n\n const texts = await mapLimited(walker.jobs, READ_CONCURRENCY, (job) =>\n readWritten(absoluteRoot, job.file, sinkFor(job, sink)),\n );\n const hashed = walker.jobs\n .map((job, index) => ({ file: job.file, read: texts[index] }))\n .sort((left, right) => (left.file < right.file ? -1 : left.file > right.file ? 1 : 0));\n\n for (const { file, read } of hashed) {\n if (!read) continue;\n\n hash.update(file);\n hash.update(\"\\0\");\n hash.update(read.bytes);\n hash.update(\"\\0\");\n }\n\n written.hash = hash.digest(\"hex\");\n\n const features = new Map<string, WrittenFeature>(\n walker.features.map((id) => [\n id,\n {\n id,\n dir: `${GRIMOIRE_DIR}/features/${id}`,\n readme: null,\n changelog: null,\n flows: [],\n versions: [],\n },\n ]),\n );\n const appReadmes = new Map<string, { file: string; readme: AppReadme }>();\n const layouts = new Map<string, WrittenLayout[]>();\n const pages = new Map<string, WrittenPage[]>();\n const blockFiles = new Map<string, WrittenBlockFile[]>();\n const tasks: WrittenTask[] = [];\n const releases: WrittenRelease[] = [];\n const push = <T>(map: Map<string, T[]>, key: string, value: T): void => {\n const list = map.get(key);\n\n if (list) list.push(value);\n else map.set(key, [value]);\n };\n\n walker.jobs.forEach((job, index) => {\n const read = texts[index];\n\n if (!read) return;\n\n const fileSink = sinkFor(job, sink);\n const text = read.text;\n\n switch (job.type) {\n case \"feature-readme\": {\n const feature = features.get(job.feature);\n if (feature) feature.readme = parseFeatureReadme(job.file, text, job.feature, fileSink);\n return;\n }\n case \"changelog\": {\n const feature = features.get(job.feature);\n if (feature) feature.changelog = parseChangelog(job.file, text, job.feature, fileSink);\n return;\n }\n case \"flow\":\n features\n .get(job.feature)\n ?.flows.push(parseFlow(job.file, text, job.feature, job.name, fileSink));\n return;\n case \"version\":\n features\n .get(job.feature)\n ?.versions.push(parseVersionBrief(job.file, text, job.feature, job.major, fileSink));\n return;\n case \"app-readme\":\n appReadmes.set(job.app, {\n file: job.file,\n readme: parseAppReadme(job.file, text, job.app, job.fallbackType, fileSink),\n });\n return;\n case \"layout\":\n push(layouts, job.app, parseLayout(job.file, text, job.app, job.id, fileSink));\n return;\n case \"page\":\n push(\n pages,\n `${job.app}/${job.pageType}/${job.id}`,\n parsePage(job.file, text, job.app, job.pageType, job.id, fileSink),\n );\n return;\n case \"block\":\n push(\n blockFiles,\n `${job.app}/${job.pageType}/${job.page}`,\n parseBlockFile(job.file, text, job.app, job.page, job.id, fileSink),\n );\n return;\n case \"task\":\n tasks.push(parseTask(job.file, text, job.place, fileSink));\n return;\n case \"release\":\n releases.push(parseRelease(job.file, text, job.name, fileSink));\n return;\n }\n });\n\n for (const feature of features.values()) {\n feature.versions.sort((left, right) => left.major - right.major);\n linkFlows(feature, sink.scope({ feature: feature.id }));\n written.features.push(feature);\n }\n\n for (const app of walker.apps) {\n const found = appReadmes.get(app.id);\n const missing = { value: app.id, at: lineAt(`${app.dir}/README.md`, 1) };\n const appPages = (type: PageType): WrittenPage[] =>\n [...pages.entries()]\n .filter(([key]) => key.startsWith(`${app.id}/${type}/`))\n .map(([key, list]) =>\n list.map((page) => ({ ...page, blockFiles: blockFiles.get(key) ?? [] })),\n )\n .flat();\n const pageList = appPages(\"page\");\n const screenList = appPages(\"screen\");\n\n written.apps.push({\n dir: app.dir,\n file: found?.file ?? null,\n id: found?.readme.id ?? missing,\n type: found?.readme.type ?? {\n value: screenList.length > 0 ? \"mobile\" : \"site\",\n at: missing.at,\n },\n root: found?.readme.root ?? { value: \"\", at: missing.at },\n origin: found?.readme.origin ?? null,\n heading: found?.readme.heading ?? null,\n conditions: found?.readme.conditions ?? [],\n layouts: layouts.get(app.id) ?? [],\n pages: pageList,\n screens: screenList,\n } satisfies WrittenApp);\n }\n\n duplicates(\n written.apps\n .filter((app) => app.file !== null)\n .map((app) => ({ id: app.id, subject: { app: app.id.value } })),\n \"app\",\n sink,\n );\n\n tasks.sort(\n (left, right) => taskNumber(left) - taskNumber(right) || (left.file < right.file ? -1 : 1),\n );\n duplicates(\n tasks\n .filter((task) => task.id.value !== \"\")\n .map((task) => ({ id: task.id, subject: { task: task.id.value } })),\n \"task\",\n sink,\n );\n written.tasks = tasks;\n written.releases = releases;\n\n return { written, findings: sink.sorted() };\n}\n\n/** GR1026 for a README flow with no file; GR1027 for a flow file the README does not list. */\nfunction linkFlows(feature: WrittenFeature, sink: FindingSink): void {\n if (feature.readme === null) return;\n\n const files = new Set(feature.flows.map((flow) => flow.ref.slice(feature.id.length + 1)));\n const listed = new Set(feature.readme.flows.map((line) => line.name));\n\n for (const line of feature.readme.flows) {\n if (!files.has(line.name)) {\n sink\n .scope({ flow: `${feature.id}/${line.name}` })\n .report(\n \"GR1026\",\n `the README lists the flow \"${line.name}\", which has no file flows/${line.name}.md.`,\n line.at,\n );\n }\n }\n\n for (const flow of feature.flows) {\n const name = flow.ref.slice(feature.id.length + 1);\n\n if (!listed.has(name)) {\n sink\n .scope({ flow: flow.ref })\n .report(\n \"GR1027\",\n `the flow \"${name}\" is not listed under \"## Flows\" in the feature README.`,\n lineAt(flow.file, 1),\n );\n }\n }\n}\n\n/** GR1022 for each id already used by an earlier file. */\nfunction duplicates(\n items: { id: Located<string>; subject: { app?: string; task?: string } }[],\n what: string,\n sink: FindingSink,\n): void {\n const seen = new Map<string, string>();\n\n for (const item of items) {\n const first = seen.get(item.id.value);\n\n if (first !== undefined) {\n sink\n .scope(item.subject)\n .report(\"GR1022\", `the ${what} id ${item.id.value} is also used by ${first}.`, item.id.at);\n continue;\n }\n\n seen.set(item.id.value, item.id.at.file);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAoDA,MAAM,YAAY;AAClB,MAAM,QAAQ;AACd,MAAM,gBAAgB;AACtB,MAAM,UAAU,IAAI,YAAY,SAAS,EAAE,OAAO,KAAK,CAAC;;AAGxD,IAAM,SAAN,MAAa;CASQ;CACA;CATnB,AAAgB,OAAc,CAAC;;CAE/B,AAAgB,WAAqB,CAAC;CACtC,AAAgB,OAA0D,CAAC;;CAE3E,AAAiB,0BAAU,IAAI,IAAY;CAE3C,AAAO,YACL,AAAiB,MACjB,AAAiB,MACjB;EAFiB;EACA;CAChB;CAEH,AAAQ,SAAS,MAAsB;EACrC,OAAO,KAAK,KAAK,KAAK,MAAM,GAAG,KAAK,MAAM,GAAG,CAAC;CAChD;;CAGA,MAAa,KAAK,KAA+B;EAC/C,IAAI;EAEJ,IAAI;GACF,UAAU,MAAM,QAAQ,KAAK,SAAS,GAAG,GAAG,EAAE,eAAe,KAAK,CAAC;EACrE,QAAQ;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Q,IAAI,IAAI,QAAQ,MAAM,KAAK,SAAS,KAAK,IAAI,MAAM,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC;CACxF,MAAM,SAAS,IAAI,IAAI,QAAQ,OAAO,MAAM,KAAK,SAAS,KAAK,IAAI,CAAC;CAEpE,KAAK,MAAM,QAAQ,QAAQ,OAAO,OAChC,IAAI,CAAC,MAAM,IAAI,KAAK,IAAI,GACtB,KACG,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,GAAG,KAAK,OAAO,CAAC,CAAC,CAC7C,OACC,UACA,8BAA8B,KAAK,KAAK,6BAA6B,KAAK,KAAK,OAC/E,KAAK,EACP;CAIN,KAAK,MAAM,QAAQ,QAAQ,OAAO;EAChC,MAAM,OAAO,KAAK,IAAI,MAAM,QAAQ,GAAG,SAAS,CAAC;EAEjD,IAAI,CAAC,OAAO,IAAI,IAAI,GAClB,KACG,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC,CAAC,CACzB,OACC,UACA,aAAa,KAAK,0DAClB,OAAO,KAAK,MAAM,CAAC,CACrB;CAEN;AACF;;AAGA,SAAS,WACP,OACA,MACA,MACM;CACN,MAAM,uBAAO,IAAI,IAAoB;CAErC,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,QAAQ,KAAK,IAAI,KAAK,GAAG,KAAK;EAEpC,IAAI,UAAU,QAAW;GACvB,KACG,MAAM,KAAK,OAAO,CAAC,CACnB,OAAO,UAAU,OAAO,KAAK,MAAM,KAAK,GAAG,MAAM,mBAAmB,MAAM,IAAI,KAAK,GAAG,EAAE;GAC3F;EACF;EAEA,KAAK,IAAI,KAAK,GAAG,OAAO,KAAK,GAAG,GAAG,IAAI;CACzC;AACF"}
1
+ {"version":3,"file":"parse-grimoire.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/written/parse-grimoire.ts"],"sourcesContent":["/**\n * Walks `<root>/grimoire`, reads each written file once, and hands it to the\n * parser of its kind. Paths are built as project-relative POSIX strings from\n * the folder names, so they read the same on every platform.\n */\nimport { createHash } from \"node:crypto\";\nimport type { Dirent } from \"node:fs\";\nimport { readFile, readdir, realpath, stat } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { GrimoireFinding } from \"../contracts/findings\";\nimport type { Located } from \"../contracts/location\";\nimport type {\n WrittenApp,\n WrittenBlockFile,\n WrittenFeature,\n WrittenGrimoire,\n WrittenLayout,\n WrittenPage,\n WrittenRelease,\n WrittenTask,\n} from \"../contracts/written\";\nimport { GRIMOIRE_DIR } from \"../paths\";\nimport { parseAppReadme, parseBlockFile, parseLayout, parsePage, type AppReadme } from \"./apps\";\nimport { parseChangelog, parseFeatureReadme, parseFlow, parseVersionBrief } from \"./features\";\nimport { lineAt } from \"./markdown\";\nimport { FindingSink } from \"./sink\";\nimport { parseRelease, parseTask, type TaskPlace } from \"./tasks-releases\";\n\n/** What `parseGrimoire()` returns. */\nexport type ParseGrimoireResult = {\n written: WrittenGrimoire;\n /** Structure findings (`GR1xxx`), in file and line order. */\n findings: GrimoireFinding[];\n};\n\ntype PageType = \"page\" | \"screen\";\n\n/** One written file to read, and what it is. */\ntype Job =\n | { type: \"feature-readme\"; file: string; feature: string }\n | { type: \"changelog\"; file: string; feature: string }\n | { type: \"flow\"; file: string; feature: string; name: string }\n | { type: \"version\"; file: string; feature: string; major: number }\n | { type: \"app-readme\"; file: string; app: string; fallbackType: \"site\" | \"mobile\" }\n | { type: \"layout\"; file: string; app: string; id: string }\n | { type: \"page\"; file: string; app: string; pageType: PageType; id: string }\n | { type: \"block\"; file: string; app: string; pageType: PageType; page: string; id: string }\n | { type: \"task\"; file: string; place: TaskPlace }\n | { type: \"release\"; file: string; name: string };\n\ntype Listing = { files: string[]; dirs: string[] };\n\nconst TASK_FILE = /^(T-\\d+)-[a-z0-9]+(?:-[a-z0-9]+)*\\.md$/;\nconst MONTH = /^\\d{4}-(?:0[1-9]|1[0-2])$/;\nconst VERSION_BRIEF = /^v(\\d+)\\.md$/;\nconst decoder = new TextDecoder(\"utf-8\", { fatal: true });\n\n/** The walk over the folders: what to read, and the layout findings. */\nclass Walker {\n public readonly jobs: Job[] = [];\n /** Feature and app folders, in name order. */\n public readonly features: string[] = [];\n public readonly apps: { id: string; dir: string; hasReadme: boolean }[] = [];\n /** Real paths of the folders the deep walks entered: a linked folder loop is walked once. */\n private readonly entered = new Set<string>();\n\n public constructor(\n private readonly root: string,\n private readonly sink: FindingSink,\n ) {}\n\n private absolute(file: string): string {\n return path.join(this.root, ...file.split(\"/\"));\n }\n\n /** The visible files and folders of a folder, each list in name order. Dot files are skipped. */\n public async list(dir: string): Promise<Listing> {\n let entries: Dirent[];\n\n try {\n entries = await readdir(this.absolute(dir), { withFileTypes: true });\n } catch {\n return { files: [], dirs: [] };\n }\n\n const files: string[] = [];\n const dirs: string[] = [];\n\n for (const entry of entries) {\n if (entry.name.startsWith(\".\")) continue;\n\n let isDirectory = entry.isDirectory();\n let isFile = entry.isFile();\n\n if (entry.isSymbolicLink()) {\n const target = await stat(this.absolute(`${dir}/${entry.name}`)).catch(() => null);\n isDirectory = target?.isDirectory() ?? false;\n isFile = target?.isFile() ?? false;\n }\n\n if (isDirectory) dirs.push(entry.name);\n else if (isFile) files.push(entry.name);\n }\n\n const byName = (left: string, right: string): number =>\n left < right ? -1 : left > right ? 1 : 0;\n\n return { files: files.sort(byName), dirs: dirs.sort(byName) };\n }\n\n /** GR1020 for a file the layout has no place for. */\n public unknown(file: string, sink: FindingSink = this.sink): void {\n sink.report(\"GR1020\", `the file ${file} is not part of the grimoire layout.`, lineAt(file, 1));\n }\n\n /** Whether a deep walk enters `dir` for the first time (a linked folder loop is entered once). */\n private async enter(dir: string): Promise<boolean> {\n const real = await realpath(this.absolute(dir)).catch(() => null);\n\n if (real === null || this.entered.has(real)) return false;\n\n this.entered.add(real);\n\n return true;\n }\n\n /** GR1020 for every file under a folder the layout has no place for (a linked folder loop is walked once). */\n public async unknownFolder(dir: string, sink: FindingSink = this.sink, depth = 0): Promise<void> {\n if (depth > 16 || !(await this.enter(dir))) return;\n\n const listing = await this.list(dir);\n\n for (const name of listing.files) this.unknown(`${dir}/${name}`, sink);\n for (const name of listing.dirs) await this.unknownFolder(`${dir}/${name}`, sink, depth + 1);\n }\n\n public async walk(): Promise<void> {\n const top = await this.list(GRIMOIRE_DIR);\n\n for (const name of top.files) this.unknown(`${GRIMOIRE_DIR}/${name}`);\n\n for (const name of top.dirs) {\n const dir = `${GRIMOIRE_DIR}/${name}`;\n\n // `book/` is generated; `screenshots/` holds the images the written files show.\n if (name === \"book\" || name === \"screenshots\") continue;\n else if (name === \"features\") await this.walkFeatures(dir);\n else if (name === \"apps\") await this.walkApps(dir);\n else if (name === \"tasks\") await this.walkTasks(dir);\n else if (name === \"releases\") await this.walkReleases(dir);\n else await this.unknownFolder(dir);\n }\n }\n\n private async walkFeatures(featuresDir: string): Promise<void> {\n const listing = await this.list(featuresDir);\n\n for (const name of listing.files) {\n if (name !== \"index.json\") this.unknown(`${featuresDir}/${name}`);\n }\n\n for (const feature of listing.dirs) {\n const dir = `${featuresDir}/${feature}`;\n const sink = this.sink.scope({ feature });\n const inside = await this.list(dir);\n\n this.features.push(feature);\n\n for (const name of inside.files) {\n const file = `${dir}/${name}`;\n\n if (name === \"README.md\") this.jobs.push({ type: \"feature-readme\", file, feature });\n else if (name === \"CHANGELOG.md\") this.jobs.push({ type: \"changelog\", file, feature });\n else if (!name.endsWith(\".json\")) this.unknown(file, sink);\n }\n\n if (!inside.files.includes(\"README.md\")) {\n sink.report(\n \"GR1021\",\n `the feature folder ${dir} has no README.md.`,\n lineAt(`${dir}/README.md`, 1),\n );\n }\n\n for (const sub of inside.dirs) {\n const subDir = `${dir}/${sub}`;\n\n if (sub === \"flows\") {\n const flows = await this.list(subDir);\n\n for (const name of flows.files) {\n const file = `${subDir}/${name}`;\n\n if (name.endsWith(\".md\"))\n this.jobs.push({ type: \"flow\", file, feature, name: name.slice(0, -3) });\n else if (!name.endsWith(\".bookmap.json\")) this.unknown(file, sink);\n }\n\n for (const name of flows.dirs) await this.unknownFolder(`${subDir}/${name}`, sink);\n } else if (sub === \"versions\") {\n const versions = await this.list(subDir);\n\n for (const name of versions.files) {\n const match = VERSION_BRIEF.exec(name);\n const file = `${subDir}/${name}`;\n\n if (match) this.jobs.push({ type: \"version\", file, feature, major: Number(match[1]) });\n else this.unknown(file, sink);\n }\n\n for (const name of versions.dirs) await this.unknownFolder(`${subDir}/${name}`, sink);\n } else {\n await this.unknownFolder(subDir, sink);\n }\n }\n }\n }\n\n private async walkApps(appsDir: string): Promise<void> {\n const listing = await this.list(appsDir);\n\n for (const name of listing.files) this.unknown(`${appsDir}/${name}`);\n\n for (const app of listing.dirs) {\n const dir = `${appsDir}/${app}`;\n const sink = this.sink.scope({ app });\n const inside = await this.list(dir);\n const hasReadme = inside.files.includes(\"README.md\");\n\n this.apps.push({ id: app, dir, hasReadme });\n\n for (const name of inside.files) {\n if (name === \"README.md\") {\n this.jobs.push({\n type: \"app-readme\",\n file: `${dir}/${name}`,\n app,\n fallbackType: inside.dirs.includes(\"screens\") ? \"mobile\" : \"site\",\n });\n } else {\n this.unknown(`${dir}/${name}`, sink);\n }\n }\n\n if (!hasReadme) {\n sink.report(\n \"GR1021\",\n `the app folder ${dir} has no README.md.`,\n lineAt(`${dir}/README.md`, 1),\n );\n }\n\n for (const sub of inside.dirs) {\n const subDir = `${dir}/${sub}`;\n\n if (sub === \"layouts\") {\n const layouts = await this.list(subDir);\n\n for (const name of layouts.files) {\n const file = `${subDir}/${name}`;\n\n if (name.endsWith(\".md\"))\n this.jobs.push({ type: \"layout\", file, app, id: name.slice(0, -3) });\n else this.unknown(file, sink);\n }\n\n for (const name of layouts.dirs) await this.unknownFolder(`${subDir}/${name}`, sink);\n } else if (sub === \"pages\" || sub === \"screens\") {\n await this.walkPages(subDir, app, sub === \"pages\" ? \"page\" : \"screen\", sink);\n } else {\n await this.unknownFolder(subDir, sink);\n }\n }\n }\n }\n\n private async walkPages(\n pagesDir: string,\n app: string,\n pageType: PageType,\n sink: FindingSink,\n ): Promise<void> {\n const listing = await this.list(pagesDir);\n\n for (const name of listing.files) this.unknown(`${pagesDir}/${name}`, sink);\n\n for (const page of listing.dirs) {\n const dir = `${pagesDir}/${page}`;\n const inside = await this.list(dir);\n\n for (const name of inside.files) {\n if (name === \"README.md\")\n this.jobs.push({ type: \"page\", file: `${dir}/${name}`, app, pageType, id: page });\n else this.unknown(`${dir}/${name}`, sink);\n }\n\n if (!inside.files.includes(\"README.md\")) {\n sink.report(\n \"GR1021\",\n `the ${pageType} folder ${dir} has no README.md.`,\n lineAt(`${dir}/README.md`, 1),\n );\n }\n\n for (const sub of inside.dirs) {\n const subDir = `${dir}/${sub}`;\n\n if (sub !== \"blocks\") {\n await this.unknownFolder(subDir, sink);\n continue;\n }\n\n const blocks = await this.list(subDir);\n\n for (const name of blocks.files) {\n const file = `${subDir}/${name}`;\n\n if (name.endsWith(\".md\"))\n this.jobs.push({ type: \"block\", file, app, pageType, page, id: name.slice(0, -3) });\n else this.unknown(file, sink);\n }\n\n for (const name of blocks.dirs) await this.unknownFolder(`${subDir}/${name}`, sink);\n }\n }\n }\n\n /** GR1023 for a task file outside `open/` and `done/<yyyy-mm>/`; other files get GR1020. */\n private async misplacedTasks(dir: string, depth = 0): Promise<void> {\n if (depth > 16 || !(await this.enter(dir))) return;\n\n const listing = await this.list(dir);\n\n for (const name of listing.files) this.misplacedTask(`${dir}/${name}`);\n for (const name of listing.dirs) await this.misplacedTasks(`${dir}/${name}`, depth + 1);\n }\n\n private misplacedTask(file: string): void {\n if (!file.endsWith(\".md\")) {\n this.unknown(file);\n return;\n }\n\n this.sink.report(\n \"GR1023\",\n `the task file ${file} is not in tasks/open/ or tasks/done/<yyyy-mm>/; it is not read.`,\n lineAt(file, 1),\n );\n }\n\n private taskFiles(\n dir: string,\n names: readonly string[],\n folder: \"open\" | \"done\",\n month: string | null,\n ): void {\n for (const name of names) {\n const file = `${dir}/${name}`;\n\n if (!name.endsWith(\".md\")) {\n this.unknown(file);\n continue;\n }\n\n const match = TASK_FILE.exec(name);\n\n if (!match) {\n this.sink.report(\n \"GR1023\",\n `the task file name ${name} is not T-<n>-<slug>.md.`,\n lineAt(file, 1),\n );\n }\n\n this.jobs.push({ type: \"task\", file, place: { folder, month, nameId: match?.[1] ?? null } });\n }\n }\n\n private async walkTasks(tasksDir: string): Promise<void> {\n const listing = await this.list(tasksDir);\n\n for (const name of listing.files) {\n if (name !== \"index.json\") this.misplacedTask(`${tasksDir}/${name}`);\n }\n\n for (const sub of listing.dirs) {\n const dir = `${tasksDir}/${sub}`;\n const inside = await this.list(dir);\n\n if (sub === \"open\") {\n this.taskFiles(dir, inside.files, \"open\", null);\n for (const name of inside.dirs) await this.misplacedTasks(`${dir}/${name}`);\n } else if (sub === \"done\") {\n for (const name of inside.files) this.misplacedTask(`${dir}/${name}`);\n\n for (const month of inside.dirs) {\n const monthDir = `${dir}/${month}`;\n\n if (!MONTH.test(month)) {\n await this.misplacedTasks(monthDir);\n continue;\n }\n\n const files = await this.list(monthDir);\n\n this.taskFiles(monthDir, files.files, \"done\", month);\n for (const name of files.dirs) await this.misplacedTasks(`${monthDir}/${name}`);\n }\n } else {\n await this.misplacedTasks(dir);\n }\n }\n }\n\n private async walkReleases(releasesDir: string): Promise<void> {\n const listing = await this.list(releasesDir);\n\n for (const name of listing.files) {\n const file = `${releasesDir}/${name}`;\n\n if (name.endsWith(\".md\")) this.jobs.push({ type: \"release\", file, name: name.slice(0, -3) });\n else this.unknown(file);\n }\n\n for (const name of listing.dirs) await this.unknownFolder(`${releasesDir}/${name}`);\n }\n}\n\n/**\n * Files read at once. A grimoire grows by a task file a change, so reading\n * them all at once runs out of file handles (`EMFILE`) on a large project.\n */\nconst READ_CONCURRENCY = 32;\n\n/** `items.map(run)` with at most `limit` calls in flight; results keep the order of `items`. */\nasync function mapLimited<T, R>(\n items: readonly T[],\n limit: number,\n run: (item: T) => Promise<R>,\n): Promise<R[]> {\n const results = new Array<R>(items.length);\n let next = 0;\n\n const worker = async (): Promise<void> => {\n while (next < items.length) {\n const index = next++;\n\n results[index] = await run(items[index] as T);\n }\n };\n\n await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));\n\n return results;\n}\n\n/** Read one file as UTF-8; `null` (with GR1025) when it cannot be read or is not UTF-8. */\nasync function readWritten(\n root: string,\n file: string,\n sink: FindingSink,\n): Promise<{ bytes: Uint8Array; text: string } | null> {\n try {\n const bytes = await readFile(path.join(root, ...file.split(\"/\")));\n\n try {\n return { bytes, text: decoder.decode(bytes) };\n } catch {\n sink.report(\"GR1025\", `the file ${file} is not UTF-8 text.`, lineAt(file, 1));\n\n return null;\n }\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n\n sink.report(\"GR1025\", `the file ${file} cannot be read: ${reason}`, lineAt(file, 1));\n\n return null;\n }\n}\n\nfunction sinkFor(job: Job, sink: FindingSink): FindingSink {\n switch (job.type) {\n case \"feature-readme\":\n case \"changelog\":\n case \"version\":\n return sink.scope({ feature: job.feature });\n case \"flow\":\n return sink.scope({ feature: job.feature, flow: `${job.feature}/${job.name}` });\n case \"app-readme\":\n case \"layout\":\n case \"page\":\n case \"block\":\n return sink.scope({ app: job.app });\n case \"task\":\n return sink.scope({ task: job.place.nameId });\n case \"release\":\n return sink;\n }\n}\n\nfunction taskNumber(task: WrittenTask): number {\n const match = /^T-(\\d+)$/.exec(task.id.value) ?? /(?:^|\\/)T-(\\d+)-[^/]*$/.exec(task.file);\n\n return match ? Number(match[1]) : Number.MAX_SAFE_INTEGER;\n}\n\n/**\n * Parse every written file under `<root>/grimoire`. A project without a\n * `grimoire/` folder gives `written.exists === false` and no findings. Bad\n * input never throws: each problem is a `GR1xxx` finding at its line, and\n * the rest of the file is still read.\n *\n * @param root Absolute project root.\n */\nexport async function parseGrimoire(root: string): Promise<ParseGrimoireResult> {\n const absoluteRoot = path.resolve(root);\n const sink = new FindingSink();\n const hash = createHash(\"sha256\");\n const written: WrittenGrimoire = {\n root: absoluteRoot,\n exists: false,\n features: [],\n apps: [],\n tasks: [],\n releases: [],\n hash: \"\",\n };\n\n const grimoireStat = await stat(path.join(absoluteRoot, GRIMOIRE_DIR)).catch(() => null);\n\n if (!grimoireStat?.isDirectory()) {\n written.hash = hash.digest(\"hex\");\n\n return { written, findings: [] };\n }\n\n written.exists = true;\n\n const walker = new Walker(absoluteRoot, sink);\n await walker.walk();\n\n const texts = await mapLimited(walker.jobs, READ_CONCURRENCY, (job) =>\n readWritten(absoluteRoot, job.file, sinkFor(job, sink)),\n );\n const hashed = walker.jobs\n .map((job, index) => ({ file: job.file, read: texts[index] }))\n .sort((left, right) => (left.file < right.file ? -1 : left.file > right.file ? 1 : 0));\n\n for (const { file, read } of hashed) {\n if (!read) continue;\n\n hash.update(file);\n hash.update(\"\\0\");\n hash.update(read.bytes);\n hash.update(\"\\0\");\n }\n\n written.hash = hash.digest(\"hex\");\n\n const features = new Map<string, WrittenFeature>(\n walker.features.map((id) => [\n id,\n {\n id,\n dir: `${GRIMOIRE_DIR}/features/${id}`,\n readme: null,\n changelog: null,\n flows: [],\n versions: [],\n },\n ]),\n );\n const appReadmes = new Map<string, { file: string; readme: AppReadme }>();\n const layouts = new Map<string, WrittenLayout[]>();\n const pages = new Map<string, WrittenPage[]>();\n const blockFiles = new Map<string, WrittenBlockFile[]>();\n const tasks: WrittenTask[] = [];\n const releases: WrittenRelease[] = [];\n const push = <T>(map: Map<string, T[]>, key: string, value: T): void => {\n const list = map.get(key);\n\n if (list) list.push(value);\n else map.set(key, [value]);\n };\n\n walker.jobs.forEach((job, index) => {\n const read = texts[index];\n\n if (!read) return;\n\n const fileSink = sinkFor(job, sink);\n const text = read.text;\n\n switch (job.type) {\n case \"feature-readme\": {\n const feature = features.get(job.feature);\n if (feature) feature.readme = parseFeatureReadme(job.file, text, job.feature, fileSink);\n return;\n }\n case \"changelog\": {\n const feature = features.get(job.feature);\n if (feature) feature.changelog = parseChangelog(job.file, text, job.feature, fileSink);\n return;\n }\n case \"flow\":\n features\n .get(job.feature)\n ?.flows.push(parseFlow(job.file, text, job.feature, job.name, fileSink));\n return;\n case \"version\":\n features\n .get(job.feature)\n ?.versions.push(parseVersionBrief(job.file, text, job.feature, job.major, fileSink));\n return;\n case \"app-readme\":\n appReadmes.set(job.app, {\n file: job.file,\n readme: parseAppReadme(job.file, text, job.app, job.fallbackType, fileSink),\n });\n return;\n case \"layout\":\n push(layouts, job.app, parseLayout(job.file, text, job.app, job.id, fileSink));\n return;\n case \"page\":\n push(\n pages,\n `${job.app}/${job.pageType}/${job.id}`,\n parsePage(job.file, text, job.app, job.pageType, job.id, fileSink),\n );\n return;\n case \"block\":\n push(\n blockFiles,\n `${job.app}/${job.pageType}/${job.page}`,\n parseBlockFile(job.file, text, job.app, job.page, job.id, fileSink),\n );\n return;\n case \"task\":\n tasks.push(parseTask(job.file, text, job.place, fileSink));\n return;\n case \"release\":\n releases.push(parseRelease(job.file, text, job.name, fileSink));\n return;\n }\n });\n\n for (const feature of features.values()) {\n feature.versions.sort((left, right) => left.major - right.major);\n linkFlows(feature, sink.scope({ feature: feature.id }));\n written.features.push(feature);\n }\n\n for (const app of walker.apps) {\n const found = appReadmes.get(app.id);\n const missing = { value: app.id, at: lineAt(`${app.dir}/README.md`, 1) };\n const appPages = (type: PageType): WrittenPage[] =>\n [...pages.entries()]\n .filter(([key]) => key.startsWith(`${app.id}/${type}/`))\n .map(([key, list]) =>\n list.map((page) => ({ ...page, blockFiles: blockFiles.get(key) ?? [] })),\n )\n .flat();\n const pageList = appPages(\"page\");\n const screenList = appPages(\"screen\");\n\n written.apps.push({\n dir: app.dir,\n file: found?.file ?? null,\n id: found?.readme.id ?? missing,\n type: found?.readme.type ?? {\n value: screenList.length > 0 ? \"mobile\" : \"site\",\n at: missing.at,\n },\n root: found?.readme.root ?? { value: \"\", at: missing.at },\n origin: found?.readme.origin ?? null,\n heading: found?.readme.heading ?? null,\n conditions: found?.readme.conditions ?? [],\n layouts: layouts.get(app.id) ?? [],\n pages: pageList,\n screens: screenList,\n } satisfies WrittenApp);\n }\n\n duplicates(\n written.apps\n .filter((app) => app.file !== null)\n .map((app) => ({ id: app.id, subject: { app: app.id.value } })),\n \"app\",\n sink,\n );\n\n tasks.sort(\n (left, right) => taskNumber(left) - taskNumber(right) || (left.file < right.file ? -1 : 1),\n );\n duplicates(\n tasks\n .filter((task) => task.id.value !== \"\")\n .map((task) => ({ id: task.id, subject: { task: task.id.value } })),\n \"task\",\n sink,\n );\n written.tasks = tasks;\n written.releases = releases;\n\n return { written, findings: sink.sorted() };\n}\n\n/** GR1026 for a README flow with no file; GR1027 for a flow file the README does not list. */\nfunction linkFlows(feature: WrittenFeature, sink: FindingSink): void {\n if (feature.readme === null) return;\n\n const files = new Set(feature.flows.map((flow) => flow.ref.slice(feature.id.length + 1)));\n const listed = new Set(feature.readme.flows.map((line) => line.name));\n\n for (const line of feature.readme.flows) {\n if (!files.has(line.name)) {\n sink\n .scope({ flow: `${feature.id}/${line.name}` })\n .report(\n \"GR1026\",\n `the README lists the flow \"${line.name}\", which has no file flows/${line.name}.md.`,\n line.at,\n );\n }\n }\n\n for (const flow of feature.flows) {\n const name = flow.ref.slice(feature.id.length + 1);\n\n if (!listed.has(name)) {\n sink\n .scope({ flow: flow.ref })\n .report(\n \"GR1027\",\n `the flow \"${name}\" is not listed under \"## Flows\" in the feature README.`,\n lineAt(flow.file, 1),\n );\n }\n }\n}\n\n/** GR1022 for each id already used by an earlier file. */\nfunction duplicates(\n items: { id: Located<string>; subject: { app?: string; task?: string } }[],\n what: string,\n sink: FindingSink,\n): void {\n const seen = new Map<string, string>();\n\n for (const item of items) {\n const first = seen.get(item.id.value);\n\n if (first !== undefined) {\n sink\n .scope(item.subject)\n .report(\"GR1022\", `the ${what} id ${item.id.value} is also used by ${first}.`, item.id.at);\n continue;\n }\n\n seen.set(item.id.value, item.id.at.file);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAoDA,MAAM,YAAY;AAClB,MAAM,QAAQ;AACd,MAAM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A,MACA,MACM;CACN,MAAM,uBAAO,IAAI,IAAoB;CAErC,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,QAAQ,KAAK,IAAI,KAAK,GAAG,KAAK;EAEpC,IAAI,UAAU,QAAW;GACvB,KACG,MAAM,KAAK,OAAO,CAAC,CACnB,OAAO,UAAU,OAAO,KAAK,MAAM,KAAK,GAAG,MAAM,mBAAmB,MAAM,IAAI,KAAK,GAAG,EAAE;GAC3F;EACF;EAEA,KAAK,IAAI,KAAK,GAAG,OAAO,KAAK,GAAG,GAAG,IAAI;CACzC;AACF"}
package/llms-full.txt CHANGED
@@ -98,6 +98,11 @@ folders: [src/app/auth]
98
98
  ```
99
99
 
100
100
  - `origin: inferred` on the README and on each flow. The owner changes it to `confirmed`.
101
+ - **Summaries and stories in plain words.** Write the paragraph under each flow's title (what a user
102
+ does and gets, in one or two sentences) and, where the route and page names make the path clear,
103
+ a `## Story` of numbered sentences in the user's words. Add `audience` and a short `## Why` to
104
+ the README when the code shows who uses the feature and for what. Mark all of it inferred and
105
+ leave a screenshot out unless you can capture it; the owner confirms the wording.
101
106
  - Start every feature at `1.0`. Do not reconstruct history; the changelog gets one line under `## Unreleased`
102
107
  in the feature's own `CHANGELOG.md` (`grimoire/features/auth/CHANGELOG.md`), never in the README:
103
108
 
@@ -263,6 +268,8 @@ layout: site
263
268
 
264
269
  The first page a visitor sees.
265
270
 
271
+ ![The home page](../../../../screenshots/web/home.png)
272
+
266
273
  ## Blocks
267
274
 
268
275
  | Block | Flow | Who sees it | Changes with |
@@ -296,11 +303,21 @@ flow: catalog/new-arrivals
296
303
 
297
304
  # New arrivals on the home page
298
305
 
306
+ ![The new arrivals row](../../../../../screenshots/web/home-new-arrivals.png)
307
+
299
308
  - position second row, under Featured products
300
309
  - shows a grid of up to 20 products
301
310
  - phones one row that scrolls sideways
302
311
  ```
303
312
 
313
+ ## Screenshots
314
+
315
+ Keep image files in `grimoire/screenshots/` (`.png`, `.jpg`, `.jpeg`, `.webp`, `.gif`), for example
316
+ `grimoire/screenshots/web/home.png`. Write an image line `![alt](path)` anywhere in a page, screen
317
+ or block file, with the path relative to the Markdown file or starting with `/grimoire/screenshots/`.
318
+ The Product map shows these as "where you see it". An image outside the folder is a warning
319
+ (`GR1029`); a missing file is a warning (`GR2014`).
320
+
304
321
  ## Where a difference between apps goes
305
322
 
306
323
  | The difference | Goes in |
@@ -494,11 +511,19 @@ npx warlock grimoire check
494
511
  | A step names a route, page, mail or job that does not exist | Fix the name in the flow, or the code |
495
512
  | A criterion has no test | Write the test, or say in the task why not |
496
513
  | A test points at a criterion that does not exist | Fix the `@proves` line |
514
+ | Proofs exist but no test results were found (`GR4009`) | Record results, see below |
515
+ | A proving test the reporter could not match (`GR4010`) | Fix the `@proves` line or the test name |
497
516
  | A file has no header, or no feature | `document-a-file` |
498
517
  | A file in the feature's folders that no flow reaches | Describe the behaviour in a flow, or delete dead code |
499
518
  | A README `updated` older than its newest changelog entry | Reshape the README |
500
519
  | A changelog version that does not fit the word (`added` with `2.1`) | Fix the version |
501
520
 
521
+ **Recording results.** The check and the devtools tab read test results from
522
+ `grimoire/book/test-results.json`, written by the Grimoire Vitest reporter when the tests run. That
523
+ folder is not committed, so run the tests with the reporter in CI and ship the results file with the
524
+ deploy. To write it elsewhere, pass `grimoireReporter({ file })` and point the devtools panel at it
525
+ with the `testResultsFile` option.
526
+
502
527
  Fix every line it prints. Do not finish with problems you caused. Findings on a flow or feature
503
528
  with `status: proposed` print with `(expected)` and do not fail the check: leave them until the
504
529
  code exists.
@@ -678,6 +703,11 @@ From `@warlock.js/grimoire` (no dependency on core or web):
678
703
  release between `COLLECTED_START_MARKER` and `COLLECTED_END_MARKER`.
679
704
  - `scanProofs` and `scanProofsInText` read `// @proves` lines; `criterionStatus` turns test
680
705
  results into a criterion's status; `CASE_QUESTIONS` lists the questions every flow answers.
706
+ - Flow steps list `entries` (every file the step starts from), `direct` (their direct imports), `files` (what
707
+ runs: type-only imports are not followed) and `typeOnlyFiles` (reached only through type-only imports).
708
+ `importClosure(graph, start, { skipTypeOnly: true })` leaves type-only edges out. `warlock scry --flow --json`
709
+ keeps every list; the MCP tool `grimoire_flow` and the devtools flow route send counts and the first 50 direct
710
+ imports per step, and list one step's files on request (`files: "reachable"` or `"type-only"` with `step`).
681
711
  - Helpers: `loadBook`, `readFrontMatter`, `fileGraph`, `importClosure`, `importerClosure`,
682
712
  `bookEntryPath`, `bookEntryPaths`, `toPosixPath`, `GRIMOIRE_DIR`, `GRIMOIRE_PATHS`,
683
713
  `GRIMOIRE_IGNORE_RULES` (the `.gitignore` lines) and `BOOK_SCHEMA_VERSION`.
@@ -689,12 +719,20 @@ the `grimoire` and `scry` commands for `cli.commands` in `warlock.config.ts`;
689
719
 
690
720
  From `@warlock.js/grimoire/vitest`: `grimoireReporter` records the last result of every test marked
691
721
  `// @proves` into `grimoire/book/test-results.json`. Add it to the Vitest `reporters` list.
722
+ `grimoireReporter({ file })` writes to another path (for a deploy that ships CI results); `readTestResults(root, file?)`
723
+ reads it, and the panel option `testResultsFile` and `openGrimoire` option `testResultsFile` point the tab at it.
724
+ The check warns with `GR4009` when `@proves` lines exist and no results were found, and with `GR4010` when the
725
+ reporter could not match a proving test.
692
726
 
693
727
  From `@warlock.js/grimoire/devtools`: `grimoireDevtoolsPanel` (the default export) is the Grimoire
694
728
  tab for `@warlock.js/devtools`, listed in `panels` of `src/config/devtools.ts`;
695
729
  `exportGrimoireSite` writes the same view as a static site.
696
730
  The tab keeps its snapshot until the book changes in production and refreshes it in the background in
697
- development; set `ttlMs` with `panels: [["@warlock.js/grimoire/devtools", { ttlMs: 60_000 }]]`.
731
+ development; the results file's modified time is part of the change stamp, so new results show without a restart.
732
+ The tab also has a Product map: the features, flows, apps, releases and planned work in plain words, from the written
733
+ files (summaries, `audience`, `## Why`, `## Story`) and the images in `grimoire/screenshots/`. Its routes are
734
+ `/product`, `/product/features/:feature` and `/product/flows/:feature/:flow`; `/check/groups` and `/check?code=`
735
+ give the check by code and a page of one code's findings. Set `ttlMs` with `panels: [["@warlock.js/grimoire/devtools", { ttlMs: 60_000 }]]`.
698
736
 
699
737
 
700
738
  ## write-a-feature `@warlock.js/grimoire/skills/write-a-feature/SKILL.md`
@@ -763,12 +801,17 @@ version: 3.0
763
801
  updated: 2026-11-16
764
802
  apps: [web-client, mobile]
765
803
  folders: [src/app/catalog, src/web/$sites/client/products]
804
+ audience: [shoppers, store staff]
766
805
  ---
767
806
 
768
807
  # Product catalog
769
808
 
770
809
  Customers browse products, search them and see what is new.
771
810
 
811
+ ## Why
812
+
813
+ Shoppers decide what to buy from the catalog, so it has to be quick to browse and clear about what is new.
814
+
772
815
  ## Flows
773
816
 
774
817
  - browse-products list and filter products
@@ -780,6 +823,9 @@ Customers browse products, search them and see what is new.
780
823
  - affected by orders/place-order (lowers stock)
781
824
  ```
782
825
 
826
+ `audience` (optional) lists who the feature is for, in plain words. `## Why` (optional) says why the
827
+ feature exists in a few sentences. Without `audience`, readers use the `who` of the flows.
828
+
783
829
  `id` never changes. `folders` are the folders whose files belong to this feature. An entry with a
784
830
  code-file extension names one file (`src/web/components/client/home/pricing-table.tsx`), for a
785
831
  feature that owns a few files in a folder shared with others. A file entry wins over the folder
@@ -801,6 +847,15 @@ who: customer
801
847
 
802
848
  # Save a product to the wishlist
803
849
 
850
+ A customer saves a product they like and finds it again later on their wishlist.
851
+
852
+ ## Story
853
+
854
+ 1. The customer opens a product and taps "Save for later".
855
+ 2. The product shows a filled heart.
856
+ ![The saved product](../../../screenshots/web/wishlist-saved.png)
857
+ 3. Later, the customer opens their wishlist and sees the product there.
858
+
804
859
  ## Steps
805
860
 
806
861
  1. page /products/:id
@@ -817,7 +872,7 @@ who: customer
817
872
  - invalid input a product id that is not an id → 422
818
873
  - not allowed guest → sent to sign in, then back to the product
819
874
  - not found the product does not exist → 404
820
- - duplicate already saved → stays saved, no error
875
+ - duplicate already saved → stays saved, no error (AC-2)
821
876
  - limits at most 200 products
822
877
  - expiry does not apply: saved products do not expire
823
878
  - double submit two taps save once
@@ -831,6 +886,23 @@ who: customer
831
886
  - AC-4 [mobile] the product card has a save button
832
887
  ```
833
888
 
889
+ **Summary.** The paragraph under the `# Title`: one or two plain sentences saying who does what and
890
+ what they get. A flow with none gets a warning (`GR1030`).
891
+
892
+ **Story.** Optional. Numbered sentences in the user's words, without file names or code, for readers
893
+ who do not read code. Indent a second line to continue a sentence. An image line
894
+ `![alt](path)` under a step attaches a screenshot to it.
895
+
896
+ **Screenshots.** Keep image files in `grimoire/screenshots/` (any subfolders; `.png`, `.jpg`,
897
+ `.jpeg`, `.webp` or `.gif`). Write the path relative to the Markdown file, so it also shows on a git
898
+ host (`../../../screenshots/web/wishlist-saved.png` from a flow file), or start it with
899
+ `/grimoire/screenshots/`. An image outside that folder is a warning (`GR1029`), a missing file too
900
+ (`GR2014`).
901
+
902
+ **Product map.** The Grimoire tab has a Product map for readers who are not developers. They see the
903
+ flow summary, the feature's why and audience, the story in plain words and the screenshots there,
904
+ so write them for a person who has never opened the code.
905
+
834
906
  **Steps.** Each step has a kind and the name used in code: `page`, `route`, `mail`,
835
907
  `notification`, `job`, `event`, `outside service`. Use `affects` for an effect on another
836
908
  feature (`affects catalog/stock`). Warlock checks every name exists. A mail is a `*.mail.ts` or
@@ -841,7 +913,8 @@ When two sites, or a site and the mobile app, have a page with the same path, na
841
913
  the path in brackets: `page /support [web-admin]`. The step then looks in that app only (its
842
914
  pages, or its screens for a mobile app). Without brackets it looks in the apps the feature lists.
843
915
 
844
- **Cases.** Answer all eight questions (invalid input, not allowed, not found, duplicate, limits,
916
+ **Cases.** End a case line with `(AC-n)` (or `(AC-1, AC-2)`) to link it to the criterion that
917
+ proves it; a number the flow does not have is an error (`GR2013`). Answer all eight questions (invalid input, not allowed, not found, duplicate, limits,
845
918
  expiry, double submit, outside service down), each with a case or "does not apply" and the
846
919
  reason. A flow that skips one gets a finding. Do not invent cases beyond the questions unless the owner described one.
847
920
 
package/package.json CHANGED
@@ -26,15 +26,15 @@
26
26
  "environment": "server"
27
27
  },
28
28
  "peerDependencies": {
29
- "@warlock.js/core": "5.57.0",
30
- "@warlock.js/web": "5.57.0"
29
+ "@warlock.js/core": "5.58.0",
30
+ "@warlock.js/web": "5.58.0"
31
31
  },
32
32
  "peerDependenciesMeta": {
33
33
  "@warlock.js/web": {
34
34
  "optional": true
35
35
  }
36
36
  },
37
- "version": "5.57.0",
37
+ "version": "5.58.0",
38
38
  "type": "module",
39
39
  "main": "./esm/index.mjs",
40
40
  "module": "./esm/index.mjs",
@@ -60,6 +60,11 @@ folders: [src/app/auth]
60
60
  ```
61
61
 
62
62
  - `origin: inferred` on the README and on each flow. The owner changes it to `confirmed`.
63
+ - **Summaries and stories in plain words.** Write the paragraph under each flow's title (what a user
64
+ does and gets, in one or two sentences) and, where the route and page names make the path clear,
65
+ a `## Story` of numbered sentences in the user's words. Add `audience` and a short `## Why` to
66
+ the README when the code shows who uses the feature and for what. Mark all of it inferred and
67
+ leave a screenshot out unless you can capture it; the owner confirms the wording.
63
68
  - Start every feature at `1.0`. Do not reconstruct history; the changelog gets one line under `## Unreleased`
64
69
  in the feature's own `CHANGELOG.md` (`grimoire/features/auth/CHANGELOG.md`), never in the README:
65
70
 
@@ -93,6 +93,8 @@ layout: site
93
93
 
94
94
  The first page a visitor sees.
95
95
 
96
+ ![The home page](../../../../screenshots/web/home.png)
97
+
96
98
  ## Blocks
97
99
 
98
100
  | Block | Flow | Who sees it | Changes with |
@@ -126,11 +128,21 @@ flow: catalog/new-arrivals
126
128
 
127
129
  # New arrivals on the home page
128
130
 
131
+ ![The new arrivals row](../../../../../screenshots/web/home-new-arrivals.png)
132
+
129
133
  - position second row, under Featured products
130
134
  - shows a grid of up to 20 products
131
135
  - phones one row that scrolls sideways
132
136
  ```
133
137
 
138
+ ## Screenshots
139
+
140
+ Keep image files in `grimoire/screenshots/` (`.png`, `.jpg`, `.jpeg`, `.webp`, `.gif`), for example
141
+ `grimoire/screenshots/web/home.png`. Write an image line `![alt](path)` anywhere in a page, screen
142
+ or block file, with the path relative to the Markdown file or starting with `/grimoire/screenshots/`.
143
+ The Product map shows these as "where you see it". An image outside the folder is a warning
144
+ (`GR1029`); a missing file is a warning (`GR2014`).
145
+
134
146
  ## Where a difference between apps goes
135
147
 
136
148
  | The difference | Goes in |