@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.
- package/CHANGELOG.md +20 -0
- package/esm/book/build.d.mts.map +1 -1
- package/esm/book/build.mjs +2 -1
- package/esm/book/build.mjs.map +1 -1
- package/esm/book/render.mjs +10 -0
- package/esm/book/render.mjs.map +1 -1
- package/esm/bookmap/build.d.mts.map +1 -1
- package/esm/bookmap/build.mjs +2 -2
- package/esm/bookmap/build.mjs.map +1 -1
- package/esm/bookmap/steps.mjs +53 -38
- package/esm/bookmap/steps.mjs.map +1 -1
- package/esm/check/check-grimoire.d.mts.map +1 -1
- package/esm/check/check-grimoire.mjs +4 -1
- package/esm/check/check-grimoire.mjs.map +1 -1
- package/esm/check/rules/criteria.mjs +21 -2
- package/esm/check/rules/criteria.mjs.map +1 -1
- package/esm/check/rules/screenshots.mjs +57 -0
- package/esm/check/rules/screenshots.mjs.map +1 -0
- package/esm/codes/codes.d.mts +12 -0
- package/esm/codes/codes.d.mts.map +1 -1
- package/esm/codes/codes.mjs +6 -0
- package/esm/codes/codes.mjs.map +1 -1
- package/esm/contracts/adapter.d.mts +6 -0
- package/esm/contracts/adapter.d.mts.map +1 -1
- package/esm/contracts/book.d.mts +2 -0
- package/esm/contracts/book.d.mts.map +1 -1
- package/esm/contracts/book.mjs.map +1 -1
- package/esm/contracts/bookmap.d.mts +19 -1
- package/esm/contracts/bookmap.d.mts.map +1 -1
- package/esm/contracts/snapshot.d.mts +11 -0
- package/esm/contracts/snapshot.d.mts.map +1 -1
- package/esm/contracts/test-results.d.mts +34 -0
- package/esm/contracts/test-results.d.mts.map +1 -1
- package/esm/contracts/written.d.mts +44 -0
- package/esm/contracts/written.d.mts.map +1 -1
- package/esm/contracts/written.mjs.map +1 -1
- package/esm/devtools/data.mjs +94 -3
- package/esm/devtools/data.mjs.map +1 -1
- package/esm/devtools/index.d.mts +26 -0
- package/esm/devtools/index.d.mts.map +1 -1
- package/esm/devtools/index.mjs +88 -5
- package/esm/devtools/index.mjs.map +1 -1
- package/esm/devtools/product-map.d.mts +14 -0
- package/esm/devtools/product-map.d.mts.map +1 -0
- package/esm/devtools/product-map.mjs +385 -0
- package/esm/devtools/product-map.mjs.map +1 -0
- package/esm/devtools/site.d.mts.map +1 -1
- package/esm/devtools/site.mjs +85 -13
- package/esm/devtools/site.mjs.map +1 -1
- package/esm/devtools/snapshot-source.mjs +10 -6
- package/esm/devtools/snapshot-source.mjs.map +1 -1
- package/esm/graph/index.d.mts +10 -1
- package/esm/graph/index.d.mts.map +1 -1
- package/esm/graph/index.mjs +3 -2
- package/esm/graph/index.mjs.map +1 -1
- package/esm/index.d.mts +4 -4
- package/esm/paths/index.d.mts +2 -0
- package/esm/paths/index.d.mts.map +1 -1
- package/esm/paths/index.mjs +3 -1
- package/esm/paths/index.mjs.map +1 -1
- package/esm/scry/compact.mjs +169 -0
- package/esm/scry/compact.mjs.map +1 -0
- package/esm/scry/format.d.mts.map +1 -1
- package/esm/scry/format.mjs +7 -1
- package/esm/scry/format.mjs.map +1 -1
- package/esm/scry/query.d.mts.map +1 -1
- package/esm/scry/query.mjs +12 -1
- package/esm/scry/query.mjs.map +1 -1
- package/esm/test-results/index.d.mts +7 -2
- package/esm/test-results/index.d.mts.map +1 -1
- package/esm/test-results/index.mjs +79 -12
- package/esm/test-results/index.mjs.map +1 -1
- package/esm/vitest/index.d.mts +6 -0
- package/esm/vitest/index.d.mts.map +1 -1
- package/esm/vitest/index.mjs +22 -6
- package/esm/vitest/index.mjs.map +1 -1
- package/esm/warlock/adapter.d.mts.map +1 -1
- package/esm/warlock/adapter.mjs +6 -2
- package/esm/warlock/adapter.mjs.map +1 -1
- package/esm/warlock/mcp-tools.mjs +48 -12
- package/esm/warlock/mcp-tools.mjs.map +1 -1
- package/esm/workspace/index.d.mts.map +1 -1
- package/esm/workspace/index.mjs +4 -2
- package/esm/workspace/index.mjs.map +1 -1
- package/esm/written/apps.mjs +4 -2
- package/esm/written/apps.mjs.map +1 -1
- package/esm/written/features.mjs +119 -6
- package/esm/written/features.mjs.map +1 -1
- package/esm/written/markdown.mjs +66 -1
- package/esm/written/markdown.mjs.map +1 -1
- package/esm/written/parse-grimoire.d.mts.map +1 -1
- package/esm/written/parse-grimoire.mjs +1 -1
- package/esm/written/parse-grimoire.mjs.map +1 -1
- package/llms-full.txt +76 -3
- package/package.json +3 -3
- package/skills/backfill-a-grimoire/SKILL.md +5 -0
- package/skills/describe-an-app/SKILL.md +12 -0
- package/skills/record-a-change/SKILL.md +8 -0
- package/skills/use-the-grimoire/SKILL.md +14 -1
- package/skills/write-a-feature/SKILL.md +37 -2
- package/ui/grimoire-static.js +4 -0
- package/ui/grimoire-view.js +1016 -178
- package/ui/grimoire.css +427 -2
- package/ui/product-map.css +636 -0
- package/ui/product-map.js +817 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-tools.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/warlock/mcp-tools.ts"],"sourcesContent":["/**\n * The Grimoire tools `warlock mcp` and `warlock dev --mcp` serve. Each tool\n * loads its code inside `run`, so registering them costs nothing at start.\n * Answers are the same JSON objects `--json` prints.\n */\nimport { inputSchema, type WarlockMcpContext, type WarlockMcpTool } from \"@warlock.js/core\";\nimport { explainGrimoireCode, GrimoireError, grimoireCodeDocsUrl } from \"../codes\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { ScryQuery } from \"../contracts/scry\";\nimport type { WarlockAdapterOptions } from \"./adapter\";\n\n/** The names of the tools, in the order they are listed. */\nexport const GRIMOIRE_MCP_TOOL_NAMES = [\n \"grimoire_file\",\n \"grimoire_impact\",\n \"grimoire_route\",\n \"grimoire_feature\",\n \"grimoire_flow\",\n \"grimoire_search\",\n \"grimoire_check\",\n \"grimoire_build\",\n \"grimoire_release\",\n \"grimoire_explain\",\n] as const;\n\n/** A Grimoire error as a tool error: the code, what failed, and what to do. */\nfunction toolError(error: unknown): never {\n if (error instanceof GrimoireError) {\n const fix = explainGrimoireCode(error.code)?.fix;\n\n throw new Error(`${error.code}: ${error.message}${fix ? ` Fix: ${fix}` : \"\"}`);\n }\n\n throw error;\n}\n\nfunction text(input: Record<string, unknown>, name: string): string {\n const value = input[name];\n\n return typeof value === \"string\" ? value : \"\";\n}\n\n/** The tools for one MCP server. `adapterFor` is replaced in specs. */\nexport function createGrimoireMcpTools(\n context: Pick<WarlockMcpContext, \"cwd\" | \"inspect\">,\n options: WarlockAdapterOptions = {},\n adapterFor?: () => Promise<BookAdapter>,\n): WarlockMcpTool[] {\n const root = context.cwd;\n let adapter: Promise<BookAdapter> | undefined;\n\n // The server's own inspect: `warlock mcp` boots once for every tool, `warlock dev --mcp` reads the live app.\n const loadAdapter = (): Promise<BookAdapter> => {\n adapter ??=\n adapterFor?.() ??\n import(\"./adapter\").then(({ createWarlockAdapter }) =>\n createWarlockAdapter({\n ...options,\n inspect: (_root, sections) => context.inspect(sections),\n }),\n );\n\n return adapter;\n };\n\n const ask =\n (query: (input: Record<string, unknown>) => Promise<ScryQuery> | ScryQuery) =>\n async (input: Record<string, unknown>): Promise<unknown> => {\n try {\n const { answer } = await import(\"./actions\");\n\n return await answer(root, await loadAdapter(), await query(input));\n } catch (error) {\n return toolError(error);\n }\n };\n\n const scryParts = () => import(\"../scry\");\n\n return [\n {\n name: \"grimoire_file\",\n description:\n \"One source file from the Grimoire book: header sentence, owning feature and borrowers, flows that reach it, exports, imports, importers, routes, pages. Read-only; reads cached route facts and never boots the app.\",\n input: inputSchema(\n { file: { type: \"string\", description: \"Project-relative path (either separator).\" } },\n [\"file\"],\n ),\n writes: false,\n run: ask((input) => ({ type: \"file\", file: text(input, \"file\") })),\n },\n {\n name: \"grimoire_impact\",\n description:\n \"What a change to a file reaches: importers (direct and all), API routes, pages and screens, flows, features (owner and borrowers) and tests. Read-only.\",\n input: inputSchema(\n { file: { type: \"string\", description: \"Project-relative path of the file to change.\" } },\n [\"file\"],\n ),\n writes: false,\n run: ask((input) => ({ type: \"impact\", file: text(input, \"file\") })),\n },\n {\n name: \"grimoire_route\",\n description:\n \"One HTTP route: handler and its file, routes file, middleware, guard, the files behind it and the flow steps that name it. Read-only.\",\n input: inputSchema(\n {\n method: { type: \"string\", description: \"HTTP method (GET, POST…).\" },\n path: { type: \"string\", description: \"Path as registered (/api/products/:id).\" },\n },\n [\"method\", \"path\"],\n ),\n writes: false,\n run: ask(async (input) => {\n const { parseRouteText } = await scryParts();\n\n return {\n type: \"route\",\n ...parseRouteText(`${text(input, \"method\")} ${text(input, \"path\")}`),\n };\n }),\n },\n {\n name: \"grimoire_feature\",\n description:\n \"One feature: README, flows with status, its book map (own, borrowed and unreached files, routes, pages), recent changes, open tasks and its check findings. Read-only.\",\n input: inputSchema(\n {\n feature: { type: \"string\", description: \"Feature id (folder under grimoire/features/).\" },\n },\n [\"feature\"],\n ),\n writes: false,\n run: ask(async (input) => {\n const { parseFeatureText } = await scryParts();\n\n return { type: \"feature\", feature: parseFeatureText(text(input, \"feature\")) };\n }),\n },\n {\n name: \"grimoire_flow\",\n description:\n \"One flow: steps with the files behind each, cases, criteria with their tests and last results (pass, fail, stale, not run, no test), where it is shown, history and findings. Read-only.\",\n input: inputSchema(\n { flow: { type: \"string\", description: \"<feature>/<flow>, like catalog/new-arrivals.\" } },\n [\"flow\"],\n ),\n writes: false,\n run: ask(async (input) => {\n const { parseFlowText } = await scryParts();\n\n return { type: \"flow\", ...parseFlowText(text(input, \"flow\")) };\n }),\n },\n {\n name: \"grimoire_search\",\n description:\n \"Search the Grimoire by words: features, flows, blocks, pages, screens, routes, file paths, export names, header sentences and tasks, best match first. Read-only.\",\n input: inputSchema(\n {\n text: { type: \"string\", description: \"Words to look for, in any order.\" },\n limit: { type: \"integer\", description: \"Most hits to return (default 20).\", minimum: 1 },\n },\n [\"text\"],\n ),\n writes: false,\n run: ask(async (input) => {\n const limit = input.limit;\n\n if (limit === undefined || limit === null)\n return { type: \"search\", text: text(input, \"text\") };\n\n const { parseLimit } = await scryParts();\n\n // A limit of 0, a negative or a fraction is refused with GR9006, as `--limit` is.\n return {\n type: \"search\",\n text: text(input, \"text\"),\n limit: parseLimit(typeof limit === \"number\" || typeof limit === \"string\" ? limit : true),\n };\n }),\n },\n {\n name: \"grimoire_check\",\n description:\n \"Run the Grimoire check: written names that point at nothing, files without a header or feature, criteria without tests, version and changelog problems. Findings on proposed work are marked expected. Read-only; uses cached route facts.\",\n input: inputSchema({}),\n writes: false,\n run: async () => {\n try {\n const [{ openGrimoire }, { checkGrimoire }] = await Promise.all([\n import(\"../workspace\"),\n import(\"../check\"),\n ]);\n\n return checkGrimoire(await openGrimoire(root, await loadAdapter(), { routes: \"cached\" }));\n } catch (error) {\n return toolError(error);\n }\n },\n },\n {\n name: \"grimoire_build\",\n description:\n \"Bring the generated book (grimoire/book, a git-ignored cache) up to date, reading the routes again when they changed. Writes no project file.\",\n input: inputSchema({ force: { type: \"boolean\", description: \"Rebuild every entry.\" } }),\n writes: false,\n run: async (input) => {\n try {\n const { runGrimoire } = await import(\"../workspace\");\n const loaded = await loadAdapter();\n const force = input.force === true;\n let run;\n let note: string | null = null;\n\n try {\n run = await runGrimoire(root, loaded, { routes: \"fresh\", force });\n } catch (error) {\n if (!(error instanceof GrimoireError) || error.code !== \"GR8002\") throw error;\n\n note = `${error.code}: ${error.message}`;\n run = await runGrimoire(root, loaded, { routes: \"cached\", force });\n }\n\n return {\n rebuilt: run.rebuilt,\n written: [...run.book.written, ...run.collected.written],\n removed: [...run.book.removed, ...run.collected.removed],\n routes: run.snapshot.routes,\n ...(note === null ? {} : { note }),\n };\n } catch (error) {\n return toolError(error);\n }\n },\n },\n {\n name: \"grimoire_release\",\n description:\n \"Write the collected list of a release into grimoire/releases/<release>.md (between its markers; the agent writes the brief and stamps the changelog entries first). Writes a project file.\",\n input: inputSchema(\n { release: { type: \"string\", description: \"Release name, like 1.1.0.\" } },\n [\"release\"],\n ),\n writes: true,\n run: async (input) => {\n try {\n const [{ parseGrimoire }, { writeRelease }] = await Promise.all([\n import(\"../written\"),\n import(\"../releases\"),\n ]);\n const release = text(input, \"release\").trim();\n\n if (release === \"\" || /[\\\\/]/.test(release)) {\n throw new GrimoireError(\n \"GR9006\",\n `Pass a release name like 1.1.0 (got ${JSON.stringify(release)}).`,\n );\n }\n\n return await writeRelease(root, (await parseGrimoire(root)).written, release);\n } catch (error) {\n return toolError(error);\n }\n },\n },\n {\n name: \"grimoire_explain\",\n description:\n \"What a Grimoire code (GR1001…GR9006) means, what to do, the skill that explains it and its docs link. Read-only.\",\n input: inputSchema({ code: { type: \"string\", description: \"The code, like GR2001.\" } }, [\n \"code\",\n ]),\n writes: false,\n run: async (input) => {\n const definition = explainGrimoireCode(text(input, \"code\"));\n\n if (!definition) {\n throw new Error(\n `Unknown Grimoire code ${JSON.stringify(text(input, \"code\"))}. Codes look like GR2001; the full list is at the check guide.`,\n );\n }\n\n return { ...definition, docs: grimoireCodeDocsUrl(definition.code) };\n },\n },\n ];\n}\n"],"mappings":";;;;;;;;;;AA0BA,SAAS,UAAU,OAAuB;CACxC,IAAI,iBAAiB,eAAe;EAClC,MAAM,MAAM,oBAAoB,MAAM,IAAI,CAAC,EAAE;EAE7C,MAAM,IAAI,MAAM,GAAG,MAAM,KAAK,IAAI,MAAM,UAAU,MAAM,SAAS,QAAQ,IAAI;CAC/E;CAEA,MAAM;AACR;AAEA,SAAS,KAAK,OAAgC,MAAsB;CAClE,MAAM,QAAQ,MAAM;CAEpB,OAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;;AAGA,SAAgB,uBACd,SACA,UAAiC,CAAC,GAClC,YACkB;CAClB,MAAM,OAAO,QAAQ;CACrB,IAAI;CAGJ,MAAM,oBAA0C;EAC9C,YACE,aAAa,KACb,OAAO,gBAAY,CAAC,MAAM,EAAE,2BAC1B,qBAAqB;GACnB,GAAG;GACH,UAAU,OAAO,aAAa,QAAQ,QAAQ,QAAQ;EACxD,CAAC,CACH;EAEF,OAA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AK,UAAU,OAAO,EAAE,GACjE;KAGF,OAAO,MAAM,aAAa,OAAO,MAAM,cAAc,IAAI,EAAC,CAAE,SAAS,OAAO;IAC9E,SAAS,OAAO;KACd,OAAO,UAAU,KAAK;IACxB;GACF;EACF;EACA;GACE,MAAM;GACN,aACE;GACF,OAAO,YAAY,EAAE,MAAM;IAAE,MAAM;IAAU,aAAa;GAAyB,EAAE,GAAG,CACtF,MACF,CAAC;GACD,QAAQ;GACR,KAAK,OAAO,UAAU;IACpB,MAAM,aAAa,oBAAoB,KAAK,OAAO,MAAM,CAAC;IAE1D,IAAI,CAAC,YACH,MAAM,IAAI,MACR,yBAAyB,KAAK,UAAU,KAAK,OAAO,MAAM,CAAC,EAAE,+DAC/D;IAGF,OAAO;KAAE,GAAG;KAAY,MAAM,oBAAoB,WAAW,IAAI;IAAE;GACrE;EACF;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"mcp-tools.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/warlock/mcp-tools.ts"],"sourcesContent":["/**\n * The Grimoire tools `warlock mcp` and `warlock dev --mcp` serve. Each tool\n * loads its code inside `run`, so registering them costs nothing at start.\n * Answers are the same JSON objects `--json` prints.\n */\nimport { inputSchema, type WarlockMcpContext, type WarlockMcpTool } from \"@warlock.js/core\";\nimport { explainGrimoireCode, GrimoireError, grimoireCodeDocsUrl } from \"../codes\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { ScryQuery } from \"../contracts/scry\";\nimport type { WarlockAdapterOptions } from \"./adapter\";\n\n/** The names of the tools, in the order they are listed. */\nexport const GRIMOIRE_MCP_TOOL_NAMES = [\n \"grimoire_file\",\n \"grimoire_impact\",\n \"grimoire_route\",\n \"grimoire_feature\",\n \"grimoire_flow\",\n \"grimoire_search\",\n \"grimoire_check\",\n \"grimoire_build\",\n \"grimoire_release\",\n \"grimoire_explain\",\n] as const;\n\n/** A Grimoire error as a tool error: the code, what failed, and what to do. */\nfunction toolError(error: unknown): never {\n if (error instanceof GrimoireError) {\n const fix = explainGrimoireCode(error.code)?.fix;\n\n throw new Error(`${error.code}: ${error.message}${fix ? ` Fix: ${fix}` : \"\"}`);\n }\n\n throw error;\n}\n\nfunction text(input: Record<string, unknown>, name: string): string {\n const value = input[name];\n\n return typeof value === \"string\" ? value : \"\";\n}\n\n/** The tools for one MCP server. `adapterFor` is replaced in specs. */\nexport function createGrimoireMcpTools(\n context: Pick<WarlockMcpContext, \"cwd\" | \"inspect\">,\n options: WarlockAdapterOptions = {},\n adapterFor?: () => Promise<BookAdapter>,\n): WarlockMcpTool[] {\n const root = context.cwd;\n let adapter: Promise<BookAdapter> | undefined;\n\n // The server's own inspect: `warlock mcp` boots once for every tool, `warlock dev --mcp` reads the live app.\n const loadAdapter = (): Promise<BookAdapter> => {\n adapter ??=\n adapterFor?.() ??\n import(\"./adapter\").then(({ createWarlockAdapter }) =>\n createWarlockAdapter({\n ...options,\n inspect: (_root, sections) => context.inspect(sections),\n }),\n );\n\n return adapter;\n };\n\n const ask =\n (query: (input: Record<string, unknown>) => Promise<ScryQuery> | ScryQuery) =>\n async (input: Record<string, unknown>): Promise<unknown> => {\n try {\n const { answer } = await import(\"./actions\");\n\n return await answer(root, await loadAdapter(), await query(input));\n } catch (error) {\n return toolError(error);\n }\n };\n\n const scryParts = () => import(\"../scry\");\n\n return [\n {\n name: \"grimoire_file\",\n description:\n \"One source file from the Grimoire book: header sentence, owning feature and borrowers, flows that reach it, exports, imports, importers, routes, pages. Read-only; reads cached route facts and never boots the app.\",\n input: inputSchema(\n { file: { type: \"string\", description: \"Project-relative path (either separator).\" } },\n [\"file\"],\n ),\n writes: false,\n run: ask((input) => ({ type: \"file\", file: text(input, \"file\") })),\n },\n {\n name: \"grimoire_impact\",\n description:\n \"What a change to a file reaches: importers (direct and all), API routes, pages and screens, flows, features (owner and borrowers) and tests. Read-only.\",\n input: inputSchema(\n { file: { type: \"string\", description: \"Project-relative path of the file to change.\" } },\n [\"file\"],\n ),\n writes: false,\n run: ask((input) => ({ type: \"impact\", file: text(input, \"file\") })),\n },\n {\n name: \"grimoire_route\",\n description:\n \"One HTTP route: handler and its file, routes file, middleware, guard, the files behind it and the flow steps that name it. Read-only.\",\n input: inputSchema(\n {\n method: { type: \"string\", description: \"HTTP method (GET, POST…).\" },\n path: { type: \"string\", description: \"Path as registered (/api/products/:id).\" },\n },\n [\"method\", \"path\"],\n ),\n writes: false,\n run: ask(async (input) => {\n const { parseRouteText } = await scryParts();\n\n return {\n type: \"route\",\n ...parseRouteText(`${text(input, \"method\")} ${text(input, \"path\")}`),\n };\n }),\n },\n {\n name: \"grimoire_feature\",\n description:\n \"One feature: README, flows with status, its book map (own, borrowed and unreached files, routes, pages), recent changes, open tasks and its check findings. Read-only.\",\n input: inputSchema(\n {\n feature: { type: \"string\", description: \"Feature id (folder under grimoire/features/).\" },\n },\n [\"feature\"],\n ),\n writes: false,\n run: ask(async (input) => {\n const { parseFeatureText } = await scryParts();\n\n return { type: \"feature\", feature: parseFeatureText(text(input, \"feature\")) };\n }),\n },\n {\n name: \"grimoire_flow\",\n description:\n \"One flow: its summary, steps with file counts (direct, in the feature, reachable, type-only) and the first direct imports of each, cases, criteria with their tests and last results (pass, fail, stale, not run, no test), where it is shown, history and findings. Pass files with step to list one step's reachable or type-only files, a page at a time. Read-only.\",\n input: inputSchema(\n {\n flow: { type: \"string\", description: \"<feature>/<flow>, like catalog/new-arrivals.\" },\n files: {\n type: \"string\",\n enum: [\"reachable\", \"type-only\"],\n description: \"With step: list the step's files that run (reachable) or only type imports reach (type-only).\",\n },\n step: { type: \"integer\", description: \"Step number, for files.\", minimum: 0 },\n offset: { type: \"integer\", description: \"First file to list (default 0); a page holds 200.\", minimum: 0 },\n },\n [\"flow\"],\n ),\n writes: false,\n run: async (input) => {\n try {\n const [{ parseFlowText, scry }, { openGrimoire }, compact] = await Promise.all([\n scryParts(),\n import(\"../workspace\"),\n import(\"../scry/compact\"),\n ]);\n const query = { type: \"flow\" as const, ...parseFlowText(text(input, \"flow\")) };\n const snapshot = await openGrimoire(root, await loadAdapter(), { routes: \"cached\" });\n const result = scry(snapshot, query);\n\n if (result.type !== \"flow\") return result;\n\n const set = input.files;\n\n if (set === undefined || set === null) return compact.compactFlow(snapshot, result);\n\n if (set !== \"reachable\" && set !== \"type-only\") {\n throw new GrimoireError(\"GR9006\", 'Pass files as \"reachable\" or \"type-only\".');\n }\n\n const stepNumber = input.step;\n const step = result.bookmap.steps.find((item) => item.index === stepNumber);\n\n if (typeof stepNumber !== \"number\" || step === undefined) {\n throw new GrimoireError(\n \"GR9006\",\n `Pass step as one of the step numbers of ${result.bookmap.ref} (${result.bookmap.steps.map((item) => item.index).join(\", \")}).`,\n );\n }\n\n const offset = typeof input.offset === \"number\" && input.offset > 0 ? input.offset : 0;\n\n return compact.stepFilePage(snapshot, result.bookmap, step, set, offset, 200);\n } catch (error) {\n return toolError(error);\n }\n },\n },\n {\n name: \"grimoire_search\",\n description:\n \"Search the Grimoire by words: features, flows, blocks, pages, screens, routes, file paths, export names, header sentences and tasks, best match first. Read-only.\",\n input: inputSchema(\n {\n text: { type: \"string\", description: \"Words to look for, in any order.\" },\n limit: { type: \"integer\", description: \"Most hits to return (default 20).\", minimum: 1 },\n },\n [\"text\"],\n ),\n writes: false,\n run: ask(async (input) => {\n const limit = input.limit;\n\n if (limit === undefined || limit === null)\n return { type: \"search\", text: text(input, \"text\") };\n\n const { parseLimit } = await scryParts();\n\n // A limit of 0, a negative or a fraction is refused with GR9006, as `--limit` is.\n return {\n type: \"search\",\n text: text(input, \"text\"),\n limit: parseLimit(typeof limit === \"number\" || typeof limit === \"string\" ? limit : true),\n };\n }),\n },\n {\n name: \"grimoire_check\",\n description:\n \"Run the Grimoire check: written names that point at nothing, files without a header or feature, criteria without tests, version and changelog problems. Findings on proposed work are marked expected. Read-only; uses cached route facts.\",\n input: inputSchema({}),\n writes: false,\n run: async () => {\n try {\n const [{ openGrimoire }, { checkGrimoire }] = await Promise.all([\n import(\"../workspace\"),\n import(\"../check\"),\n ]);\n\n return checkGrimoire(await openGrimoire(root, await loadAdapter(), { routes: \"cached\" }));\n } catch (error) {\n return toolError(error);\n }\n },\n },\n {\n name: \"grimoire_build\",\n description:\n \"Bring the generated book (grimoire/book, a git-ignored cache) up to date, reading the routes again when they changed. Writes no project file.\",\n input: inputSchema({ force: { type: \"boolean\", description: \"Rebuild every entry.\" } }),\n writes: false,\n run: async (input) => {\n try {\n const { runGrimoire } = await import(\"../workspace\");\n const loaded = await loadAdapter();\n const force = input.force === true;\n let run;\n let note: string | null = null;\n\n try {\n run = await runGrimoire(root, loaded, { routes: \"fresh\", force });\n } catch (error) {\n if (!(error instanceof GrimoireError) || error.code !== \"GR8002\") throw error;\n\n note = `${error.code}: ${error.message}`;\n run = await runGrimoire(root, loaded, { routes: \"cached\", force });\n }\n\n return {\n rebuilt: run.rebuilt,\n written: [...run.book.written, ...run.collected.written],\n removed: [...run.book.removed, ...run.collected.removed],\n routes: run.snapshot.routes,\n ...(note === null ? {} : { note }),\n };\n } catch (error) {\n return toolError(error);\n }\n },\n },\n {\n name: \"grimoire_release\",\n description:\n \"Write the collected list of a release into grimoire/releases/<release>.md (between its markers; the agent writes the brief and stamps the changelog entries first). Writes a project file.\",\n input: inputSchema(\n { release: { type: \"string\", description: \"Release name, like 1.1.0.\" } },\n [\"release\"],\n ),\n writes: true,\n run: async (input) => {\n try {\n const [{ parseGrimoire }, { writeRelease }] = await Promise.all([\n import(\"../written\"),\n import(\"../releases\"),\n ]);\n const release = text(input, \"release\").trim();\n\n if (release === \"\" || /[\\\\/]/.test(release)) {\n throw new GrimoireError(\n \"GR9006\",\n `Pass a release name like 1.1.0 (got ${JSON.stringify(release)}).`,\n );\n }\n\n return await writeRelease(root, (await parseGrimoire(root)).written, release);\n } catch (error) {\n return toolError(error);\n }\n },\n },\n {\n name: \"grimoire_explain\",\n description:\n \"What a Grimoire code (GR1001…GR9006) means, what to do, the skill that explains it and its docs link. Read-only.\",\n input: inputSchema({ code: { type: \"string\", description: \"The code, like GR2001.\" } }, [\n \"code\",\n ]),\n writes: false,\n run: async (input) => {\n const definition = explainGrimoireCode(text(input, \"code\"));\n\n if (!definition) {\n throw new Error(\n `Unknown Grimoire code ${JSON.stringify(text(input, \"code\"))}. Codes look like GR2001; the full list is at the check guide.`,\n );\n }\n\n return { ...definition, docs: grimoireCodeDocsUrl(definition.code) };\n },\n },\n ];\n}\n"],"mappings":";;;;;;;;;;AA0BA,SAAS,UAAU,OAAuB;CACxC,IAAI,iBAAiB,eAAe;EAClC,MAAM,MAAM,oBAAoB,MAAM,IAAI,CAAC,EAAE;EAE7C,MAAM,IAAI,MAAM,GAAG,MAAM,KAAK,IAAI,MAAM,UAAU,MAAM,SAAS,QAAQ,IAAI;CAC/E;CAEA,MAAM;AACR;AAEA,SAAS,KAAK,OAAgC,MAAsB;CAClE,MAAM,QAAQ,MAAM;CAEpB,OAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;;AAGA,SAAgB,uBACd,SACA,UAAiC,CAAC,GAClC,YACkB;CAClB,MAAM,OAAO,QAAQ;CACrB,IAAI;CAGJ,MAAM,oBAA0C;EAC9C,YACE,aAAa,KACb,OAAO,gBAAY,CAAC,MAAM,EAAE,2BAC1B,qBAAqB;GACnB,GAAG;GACH,UAAU,OAAO,aAAa,QAAQ,QAAQ,QAAQ;EACxD,CAAC,CACH;EAEF,OAAO;CACT;CAEA,MAAM,OACH,UACD,OAAO,UAAqD;EAC1D,IAAI;GACF,MAAM,EAAE,WAAW,MAAM,OAAO;GAEhC,OAAO,MAAM,OAAO,MAAM,MAAM,YAAY,GAAG,MAAM,MAAM,KAAK,CAAC;EACnE,SAAS,OAAO;GACd,OAAO,UAAU,KAAK;EACxB;CACF;CAEF,MAAM,kBAAkB,OAAO;CAE/B,OAAO;EACL;GACE,MAAM;GACN,aACE;GACF,OAAO,YACL,EAAE,MAAM;IAAE,MAAM;IAAU,aAAa;GAA4C,EAAE,GACrF,CAAC,MAAM,CACT;GACA,QAAQ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|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/workspace/index.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/workspace/index.ts"],"mappings":";;;;;;;;wBAoJsB,aACpB,cACA,SAAS,aACT,UAAS,sBACR,QAAQ"}
|
package/esm/workspace/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import "../book/index.mjs";
|
|
|
7
7
|
import { resolveOwnership } from "../ownership/index.mjs";
|
|
8
8
|
import { matchApps } from "../apps/match-apps.mjs";
|
|
9
9
|
import "../apps/index.mjs";
|
|
10
|
-
import { readTestResults } from "../test-results/index.mjs";
|
|
10
|
+
import { readTestResults, resultsFileLabel } from "../test-results/index.mjs";
|
|
11
11
|
import { annotationsFrom, buildCollectedFiles } from "../bookmap/build.mjs";
|
|
12
12
|
import { writeCollectedFiles } from "../bookmap/write.mjs";
|
|
13
13
|
import "../bookmap/index.mjs";
|
|
@@ -62,7 +62,8 @@ async function runGrimoire(root, adapter, options = {}) {
|
|
|
62
62
|
const apps = matchApps(written.apps, book.facts);
|
|
63
63
|
const ownership = resolveOwnership(written, book.facts);
|
|
64
64
|
const { proofs, findings: proofFindings } = await scanProofs(root, book.facts.tests);
|
|
65
|
-
const
|
|
65
|
+
const resultsFile = resultsFileLabel(root, options.testResultsFile);
|
|
66
|
+
const results = await readTestResults(root, options.testResultsFile);
|
|
66
67
|
const testHashes = await testFileHashes(root, book.facts.tests, book.manifest.tests);
|
|
67
68
|
const input = {
|
|
68
69
|
written,
|
|
@@ -98,6 +99,7 @@ async function runGrimoire(root, adapter, options = {}) {
|
|
|
98
99
|
proofs,
|
|
99
100
|
proofFindings,
|
|
100
101
|
results,
|
|
102
|
+
resultsFile,
|
|
101
103
|
collected,
|
|
102
104
|
annotations,
|
|
103
105
|
routes: book.routes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/workspace/index.ts"],"sourcesContent":["/**\n * The pipeline every command runs first (owned by T-128):\n *\n * 1. `parseGrimoire(root)`;\n * 2. `buildBook(root, adapter, { routes })`;\n * 3. `matchApps`, `resolveOwnership`, `scanProofs`, `readTestResults`;\n * 4. `buildCollectedFiles`, `annotationsFrom`;\n * 5. when `write` is not `false`: `writeBook` and `writeCollectedFiles`.\n *\n * A second run with nothing changed calls no adapter method and writes no file.\n */\nimport { createHash } from \"node:crypto\";\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { matchApps } from \"../apps\";\nimport { buildBook, writeBook } from \"../book\";\nimport {\n annotationsFrom,\n buildCollectedFiles,\n writeCollectedFiles,\n type CollectedInput,\n} from \"../bookmap\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { BuildBookOptions, WriteBookResult } from \"../contracts/book\";\nimport type { GrimoireSnapshot, OpenGrimoireOptions } from \"../contracts/snapshot\";\nimport { resolveOwnership } from \"../ownership\";\nimport { toPosixPath } from \"../paths\";\nimport { scanProofs } from \"../proves\";\nimport { readTestResults } from \"../test-results\";\nimport { parseGrimoire } from \"../written\";\n\n/** The current sha256 of each test file: the manifest's, else read now (missing files are left out). */\nasync function testFileHashes(\n root: string,\n tests: readonly string[],\n known: Readonly<Record<string, string>>,\n): Promise<Record<string, string>> {\n const hashes: Record<string, string> = {};\n\n for (const test of [...new Set(tests.map(toPosixPath))].sort()) {\n const hash = known[test];\n\n if (hash !== undefined) {\n hashes[test] = hash;\n continue;\n }\n\n try {\n const content = await readFile(path.join(root, ...test.split(\"/\")));\n hashes[test] = createHash(\"sha256\").update(content).digest(\"hex\");\n } catch {\n // A listed test file that is gone has no hash; its results are not marked stale.\n }\n }\n\n return hashes;\n}\n\n/** What one pass of the pipeline did, with the snapshot it produced (`warlock grimoire build` prints it). */\nexport type GrimoireRun = {\n snapshot: GrimoireSnapshot;\n /** `false` when the book's fingerprint matched and the adapter was not asked for files. */\n rebuilt: boolean;\n /** Source files added, changed or removed since the last build. */\n changed: string[];\n /** Book files written and removed (both empty with `write: false`). */\n book: WriteBookResult;\n /** Collected files (book maps, indexes) written and removed (both empty with `write: false`). */\n collected: { written: string[]; removed: string[] };\n};\n\n/**\n * Run the pipeline and say what it wrote. `openGrimoire` is this without the\n * counts.\n *\n * @param root Absolute project root.\n */\nexport async function runGrimoire(\n root: string,\n adapter: BookAdapter,\n options: OpenGrimoireOptions = {},\n): Promise<GrimoireRun> {\n const write = options.write !== false;\n const { written, findings: structure } = await parseGrimoire(root);\n\n const bookOptions: BuildBookOptions & { write?: boolean } = {\n routes: options.routes ?? \"cached\",\n };\n\n if (options.force !== undefined) bookOptions.force = options.force;\n if (options.now !== undefined) bookOptions.now = options.now;\n if (!write) bookOptions.write = false;\n\n const { book, rebuilt, changed } = await buildBook(root, adapter, bookOptions);\n const apps = matchApps(written.apps, book.facts);\n const ownership = resolveOwnership(written, book.facts);\n const { proofs, findings: proofFindings } = await scanProofs(root, book.facts.tests);\n const results = await readTestResults(root);\n const testHashes = await testFileHashes(root, book.facts.tests, book.manifest.tests);\n\n const input: CollectedInput = {\n written,\n facts: book.facts,\n ownership,\n apps,\n proofs,\n results,\n testHashes,\n };\n const collected = buildCollectedFiles(input);\n const annotations = annotationsFrom(input, collected, { tests: testHashes });\n let bookWrite: WriteBookResult = { written: [], removed: [] };\n let collectedWrite: { written: string[]; removed: string[] } = { written: [], removed: [] };\n\n if (write) {\n bookWrite = await writeBook(book, annotations);\n collectedWrite = await writeCollectedFiles(root, collected);\n }\n\n return {\n snapshot: {\n root,\n written,\n structure,\n book,\n ownership,\n apps,\n proofs,\n proofFindings,\n results,\n collected,\n annotations,\n routes: book.routes,\n },\n rebuilt,\n changed,\n book: bookWrite,\n collected: collectedWrite,\n };\n}\n\n/**\n * Load, refresh and return everything about the project's grimoire.\n *\n * @param root Absolute project root.\n */\nexport async function openGrimoire(\n root: string,\n adapter: BookAdapter,\n options: OpenGrimoireOptions = {},\n): Promise<GrimoireSnapshot> {\n return (await runGrimoire(root, adapter, options)).snapshot;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,eAAe,eACb,MACA,OACA,OACiC;CACjC,MAAM,SAAiC,CAAC;CAExC,KAAK,MAAM,QAAQ,CAAC,GAAG,IAAI,IAAI,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG;EAC9D,MAAM,OAAO,MAAM;EAEnB,IAAI,SAAS,QAAW;GACtB,OAAO,QAAQ;GACf;EACF;EAEA,IAAI;GACF,MAAM,UAAU,MAAM,SAAS,KAAK,KAAK,MAAM,GAAG,KAAK,MAAM,GAAG,CAAC,CAAC;GAClE,OAAO,QAAQ,WAAW,QAAQ,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,OAAO,KAAK;EAClE,QAAQ,CAER;CACF;CAEA,OAAO;AACT;;;;;;;AAqBA,eAAsB,YACpB,MACA,SACA,UAA+B,CAAC,GACV;CACtB,MAAM,QAAQ,QAAQ,UAAU;CAChC,MAAM,EAAE,SAAS,UAAU,cAAc,MAAM,cAAc,IAAI;CAEjE,MAAM,cAAsD,EAC1D,QAAQ,QAAQ,UAAU,SAC5B;CAEA,IAAI,QAAQ,UAAU,QAAW,YAAY,QAAQ,QAAQ;CAC7D,IAAI,QAAQ,QAAQ,QAAW,YAAY,MAAM,QAAQ;CACzD,IAAI,CAAC,OAAO,YAAY,QAAQ;CAEhC,MAAM,EAAE,MAAM,SAAS,YAAY,MAAM,UAAU,MAAM,SAAS,WAAW;CAC7E,MAAM,OAAO,UAAU,QAAQ,MAAM,KAAK,KAAK;CAC/C,MAAM,YAAY,iBAAiB,SAAS,KAAK,KAAK;CACtD,MAAM,EAAE,QAAQ,UAAU,kBAAkB,MAAM,WAAW,MAAM,KAAK,MAAM,KAAK;CACnF,MAAM,UAAU,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/workspace/index.ts"],"sourcesContent":["/**\n * The pipeline every command runs first (owned by T-128):\n *\n * 1. `parseGrimoire(root)`;\n * 2. `buildBook(root, adapter, { routes })`;\n * 3. `matchApps`, `resolveOwnership`, `scanProofs`, `readTestResults`;\n * 4. `buildCollectedFiles`, `annotationsFrom`;\n * 5. when `write` is not `false`: `writeBook` and `writeCollectedFiles`.\n *\n * A second run with nothing changed calls no adapter method and writes no file.\n */\nimport { createHash } from \"node:crypto\";\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { matchApps } from \"../apps\";\nimport { buildBook, writeBook } from \"../book\";\nimport {\n annotationsFrom,\n buildCollectedFiles,\n writeCollectedFiles,\n type CollectedInput,\n} from \"../bookmap\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { BuildBookOptions, WriteBookResult } from \"../contracts/book\";\nimport type { GrimoireSnapshot, OpenGrimoireOptions } from \"../contracts/snapshot\";\nimport { resolveOwnership } from \"../ownership\";\nimport { toPosixPath } from \"../paths\";\nimport { scanProofs } from \"../proves\";\nimport { readTestResults, resultsFileLabel } from \"../test-results\";\nimport { parseGrimoire } from \"../written\";\n\n/** The current sha256 of each test file: the manifest's, else read now (missing files are left out). */\nasync function testFileHashes(\n root: string,\n tests: readonly string[],\n known: Readonly<Record<string, string>>,\n): Promise<Record<string, string>> {\n const hashes: Record<string, string> = {};\n\n for (const test of [...new Set(tests.map(toPosixPath))].sort()) {\n const hash = known[test];\n\n if (hash !== undefined) {\n hashes[test] = hash;\n continue;\n }\n\n try {\n const content = await readFile(path.join(root, ...test.split(\"/\")));\n hashes[test] = createHash(\"sha256\").update(content).digest(\"hex\");\n } catch {\n // A listed test file that is gone has no hash; its results are not marked stale.\n }\n }\n\n return hashes;\n}\n\n/** What one pass of the pipeline did, with the snapshot it produced (`warlock grimoire build` prints it). */\nexport type GrimoireRun = {\n snapshot: GrimoireSnapshot;\n /** `false` when the book's fingerprint matched and the adapter was not asked for files. */\n rebuilt: boolean;\n /** Source files added, changed or removed since the last build. */\n changed: string[];\n /** Book files written and removed (both empty with `write: false`). */\n book: WriteBookResult;\n /** Collected files (book maps, indexes) written and removed (both empty with `write: false`). */\n collected: { written: string[]; removed: string[] };\n};\n\n/**\n * Run the pipeline and say what it wrote. `openGrimoire` is this without the\n * counts.\n *\n * @param root Absolute project root.\n */\nexport async function runGrimoire(\n root: string,\n adapter: BookAdapter,\n options: OpenGrimoireOptions = {},\n): Promise<GrimoireRun> {\n const write = options.write !== false;\n const { written, findings: structure } = await parseGrimoire(root);\n\n const bookOptions: BuildBookOptions & { write?: boolean } = {\n routes: options.routes ?? \"cached\",\n };\n\n if (options.force !== undefined) bookOptions.force = options.force;\n if (options.now !== undefined) bookOptions.now = options.now;\n if (!write) bookOptions.write = false;\n\n const { book, rebuilt, changed } = await buildBook(root, adapter, bookOptions);\n const apps = matchApps(written.apps, book.facts);\n const ownership = resolveOwnership(written, book.facts);\n const { proofs, findings: proofFindings } = await scanProofs(root, book.facts.tests);\n const resultsFile = resultsFileLabel(root, options.testResultsFile);\n const results = await readTestResults(root, options.testResultsFile);\n const testHashes = await testFileHashes(root, book.facts.tests, book.manifest.tests);\n\n const input: CollectedInput = {\n written,\n facts: book.facts,\n ownership,\n apps,\n proofs,\n results,\n testHashes,\n };\n const collected = buildCollectedFiles(input);\n const annotations = annotationsFrom(input, collected, { tests: testHashes });\n let bookWrite: WriteBookResult = { written: [], removed: [] };\n let collectedWrite: { written: string[]; removed: string[] } = { written: [], removed: [] };\n\n if (write) {\n bookWrite = await writeBook(book, annotations);\n collectedWrite = await writeCollectedFiles(root, collected);\n }\n\n return {\n snapshot: {\n root,\n written,\n structure,\n book,\n ownership,\n apps,\n proofs,\n proofFindings,\n results,\n resultsFile,\n collected,\n annotations,\n routes: book.routes,\n },\n rebuilt,\n changed,\n book: bookWrite,\n collected: collectedWrite,\n };\n}\n\n/**\n * Load, refresh and return everything about the project's grimoire.\n *\n * @param root Absolute project root.\n */\nexport async function openGrimoire(\n root: string,\n adapter: BookAdapter,\n options: OpenGrimoireOptions = {},\n): Promise<GrimoireSnapshot> {\n return (await runGrimoire(root, adapter, options)).snapshot;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,eAAe,eACb,MACA,OACA,OACiC;CACjC,MAAM,SAAiC,CAAC;CAExC,KAAK,MAAM,QAAQ,CAAC,GAAG,IAAI,IAAI,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG;EAC9D,MAAM,OAAO,MAAM;EAEnB,IAAI,SAAS,QAAW;GACtB,OAAO,QAAQ;GACf;EACF;EAEA,IAAI;GACF,MAAM,UAAU,MAAM,SAAS,KAAK,KAAK,MAAM,GAAG,KAAK,MAAM,GAAG,CAAC,CAAC;GAClE,OAAO,QAAQ,WAAW,QAAQ,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,OAAO,KAAK;EAClE,QAAQ,CAER;CACF;CAEA,OAAO;AACT;;;;;;;AAqBA,eAAsB,YACpB,MACA,SACA,UAA+B,CAAC,GACV;CACtB,MAAM,QAAQ,QAAQ,UAAU;CAChC,MAAM,EAAE,SAAS,UAAU,cAAc,MAAM,cAAc,IAAI;CAEjE,MAAM,cAAsD,EAC1D,QAAQ,QAAQ,UAAU,SAC5B;CAEA,IAAI,QAAQ,UAAU,QAAW,YAAY,QAAQ,QAAQ;CAC7D,IAAI,QAAQ,QAAQ,QAAW,YAAY,MAAM,QAAQ;CACzD,IAAI,CAAC,OAAO,YAAY,QAAQ;CAEhC,MAAM,EAAE,MAAM,SAAS,YAAY,MAAM,UAAU,MAAM,SAAS,WAAW;CAC7E,MAAM,OAAO,UAAU,QAAQ,MAAM,KAAK,KAAK;CAC/C,MAAM,YAAY,iBAAiB,SAAS,KAAK,KAAK;CACtD,MAAM,EAAE,QAAQ,UAAU,kBAAkB,MAAM,WAAW,MAAM,KAAK,MAAM,KAAK;CACnF,MAAM,cAAc,iBAAiB,MAAM,QAAQ,eAAe;CAClE,MAAM,UAAU,MAAM,gBAAgB,MAAM,QAAQ,eAAe;CACnE,MAAM,aAAa,MAAM,eAAe,MAAM,KAAK,MAAM,OAAO,KAAK,SAAS,KAAK;CAEnF,MAAM,QAAwB;EAC5B;EACA,OAAO,KAAK;EACZ;EACA;EACA;EACA;EACA;CACF;CACA,MAAM,YAAY,oBAAoB,KAAK;CAC3C,MAAM,cAAc,gBAAgB,OAAO,WAAW,EAAE,OAAO,WAAW,CAAC;CAC3E,IAAI,YAA6B;EAAE,SAAS,CAAC;EAAG,SAAS,CAAC;CAAE;CAC5D,IAAI,iBAA2D;EAAE,SAAS,CAAC;EAAG,SAAS,CAAC;CAAE;CAE1F,IAAI,OAAO;EACT,YAAY,MAAM,UAAU,MAAM,WAAW;EAC7C,iBAAiB,MAAM,oBAAoB,MAAM,SAAS;CAC5D;CAEA,OAAO;EACL,UAAU;GACR;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA,QAAQ,KAAK;EACf;EACA;EACA;EACA,MAAM;EACN,WAAW;CACb;AACF;;;;;;AAOA,eAAsB,aACpB,MACA,SACA,UAA+B,CAAC,GACL;CAC3B,QAAQ,MAAM,YAAY,MAAM,SAAS,OAAO,EAAC,CAAE;AACrD"}
|
package/esm/written/apps.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { checkHeadings, findSection, lineAt, normalizeKey, paragraphAfterTitle, readDocument } from "./markdown.mjs";
|
|
1
|
+
import { checkHeadings, findSection, lineAt, normalizeKey, paragraphAfterTitle, readDocument, readScreenshots } from "./markdown.mjs";
|
|
2
2
|
import { FLOW_REF, FrontMatterReader, checks, projectFolder } from "./fields.mjs";
|
|
3
3
|
import { readListLines } from "./lists.mjs";
|
|
4
4
|
import { ORIGINS } from "./features.mjs";
|
|
@@ -198,6 +198,7 @@ function parsePage(file, text, app, type, id, sink) {
|
|
|
198
198
|
origin: fields.optionalOneOf("origin", ORIGINS),
|
|
199
199
|
heading: heading(document),
|
|
200
200
|
purpose: paragraphAfterTitle(document),
|
|
201
|
+
screenshots: readScreenshots(file, document.body, sink),
|
|
201
202
|
blocks: blocks ? parseBlocksTable(file, blocks, sink) : [],
|
|
202
203
|
alsoReachedFrom,
|
|
203
204
|
blockFiles: []
|
|
@@ -218,7 +219,8 @@ function parseBlockFile(file, text, app, page, id, sink) {
|
|
|
218
219
|
check: checks.flowRef
|
|
219
220
|
}),
|
|
220
221
|
heading: heading(document),
|
|
221
|
-
details: readListLines(file, document.body, "detail", sink)
|
|
222
|
+
details: readListLines(file, document.body, "detail", sink),
|
|
223
|
+
screenshots: readScreenshots(file, document.body, sink)
|
|
222
224
|
};
|
|
223
225
|
}
|
|
224
226
|
|
package/esm/written/apps.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apps.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/written/apps.ts"],"sourcesContent":["/**\n * The files of one app folder: `README.md`, `layouts/<id>.md`,\n * `pages/<id>/README.md`, `screens/<id>/README.md` and their\n * `blocks/<id>.md` files, and the `## Blocks` table they share.\n */\nimport type {\n WrittenBlockFile,\n WrittenBlockRow,\n WrittenChangesWith,\n WrittenEntryPoint,\n WrittenLayout,\n WrittenListLine,\n WrittenOrigin,\n WrittenPage,\n} from \"../contracts/written\";\nimport type { Located } from \"../contracts/location\";\nimport { ORIGINS } from \"./features\";\nimport { FLOW_REF, FrontMatterReader, checks, projectFolder } from \"./fields\";\nimport { readListLines } from \"./lists\";\nimport {\n checkHeadings,\n findSection,\n lineAt,\n normalizeKey,\n paragraphAfterTitle,\n readDocument,\n type BodyLine,\n type WrittenDocument,\n} from \"./markdown\";\nimport type { FindingSink } from \"./sink\";\n\n/** The parts of `grimoire/apps/<id>/README.md` (the folder's other files are added by the walker). */\nexport type AppReadme = {\n id: Located<string>;\n type: Located<\"site\" | \"mobile\">;\n root: Located<string>;\n origin: Located<WrittenOrigin> | null;\n heading: Located<string> | null;\n conditions: WrittenListLine[];\n};\n\nconst BLOCK_COLUMNS = [\"block\", \"flow\", \"who sees it\", \"changes with\"];\nconst EMPTY_CELL = /^(?:—|–|-+)?$/;\nconst SEPARATOR_CELL = /^:?-+:?$/;\nconst CONDITION_ITEM = /^([a-z][a-z0-9-]*(?::[a-z0-9-]+)?):[ \\t]+(\\S.*)$/;\n\nfunction heading(document: WrittenDocument): Located<string> | null {\n return document.title\n ? { value: document.title.text, at: lineAt(document.file, document.title.line) }\n : null;\n}\n\n/** The cells of a table row, with or without outer pipes; `\\|` stays a pipe inside a cell. */\nexport function tableCells(row: string): string[] {\n let text = row.trim();\n\n if (text.startsWith(\"|\")) text = text.slice(1);\n if (text.endsWith(\"|\") && !text.endsWith(\"\\\\|\")) text = text.slice(0, -1);\n\n return text.split(/(?<!\\\\)\\|/).map((cell) => cell.trim().replace(/\\\\\\|/g, \"|\"));\n}\n\n/**\n * Read the `## Blocks` table: a header row `Block | Flow | Who sees it |\n * Changes with`, a separator row, then one row per block. Text before the\n * table is allowed; the table ends at the first line without a `|`.\n */\nexport function parseBlocksTable(\n file: string,\n section: { line: number; lines: readonly BodyLine[] },\n sink: FindingSink,\n): WrittenBlockRow[] {\n const rows: WrittenBlockRow[] = [];\n const lines = section.lines;\n const start = lines.findIndex((line) => !line.fenced && line.text.includes(\"|\"));\n\n if (start === -1) {\n sink.report(\"GR1018\", \"the Blocks section has no table.\", lineAt(file, section.line));\n\n return rows;\n }\n\n const header = lines[start];\n const separator = lines[start + 1];\n\n if (header === undefined) return rows;\n\n const columns = tableCells(header.text).map(normalizeKey);\n\n if (\n columns.length !== BLOCK_COLUMNS.length ||\n columns.some((column, index) => column !== BLOCK_COLUMNS[index])\n ) {\n sink.report(\n \"GR1018\",\n `the Blocks table header is ${JSON.stringify(header.text.trim())}; use the columns Block | Flow | Who sees it | Changes with.`,\n lineAt(file, header.line),\n );\n\n return rows;\n }\n\n const separatorCells =\n separator === undefined || separator.fenced ? [] : tableCells(separator.text);\n\n if (\n separatorCells.length !== BLOCK_COLUMNS.length ||\n !separatorCells.every((cell) => SEPARATOR_CELL.test(cell))\n ) {\n sink.report(\n \"GR1018\",\n \"the Blocks table header is not followed by a separator row (`| --- | --- | --- | --- |`).\",\n lineAt(file, separator?.line ?? header.line),\n );\n\n return rows;\n }\n\n for (let index = start + 2; index < lines.length; index++) {\n const line = lines[index];\n\n if (line === undefined || line.fenced || !line.text.includes(\"|\")) break;\n\n const at = lineAt(file, line.line);\n const cells = tableCells(line.text);\n\n if (cells.length !== BLOCK_COLUMNS.length) {\n sink.report(\"GR1018\", `the Blocks row has ${cells.length} cells instead of 4.`, at);\n continue;\n }\n\n const [block = \"\", flow = \"\", who = \"\", changesWith = \"\"] = cells;\n\n if (block === \"\") {\n sink.report(\"GR1018\", \"the Blocks row has no block name.\", at);\n continue;\n }\n\n if (!EMPTY_CELL.test(flow) && !FLOW_REF.test(flow)) {\n sink.report(\n \"GR1018\",\n `the Flow cell ${JSON.stringify(flow)} of block \"${block}\" is not <feature>/<flow> or —.`,\n at,\n );\n continue;\n }\n\n if (EMPTY_CELL.test(who)) {\n sink.report(\n \"GR1018\",\n `the \"Who sees it\" cell of block \"${block}\" is empty; write everyone or condition names.`,\n at,\n );\n continue;\n }\n\n const whoItems = who\n .split(\",\")\n .map((item) => item.trim())\n .filter((item) => item !== \"\");\n\n rows.push({\n block,\n flow: EMPTY_CELL.test(flow) ? null : flow,\n who: {\n everyone: whoItems.some((item) => item.toLowerCase() === \"everyone\"),\n conditions: whoItems.filter((item) => item.toLowerCase() !== \"everyone\"),\n },\n changesWith: EMPTY_CELL.test(changesWith)\n ? []\n : changesWith\n .split(\";\")\n .map((item) => item.trim())\n .filter((item) => item !== \"\")\n .map((item): WrittenChangesWith => {\n const condition = CONDITION_ITEM.exec(item);\n\n return condition\n ? { condition: condition[1] ?? \"\", text: (condition[2] ?? \"\").trim() }\n : { condition: null, text: item };\n }),\n at,\n });\n }\n\n return rows;\n}\n\n/** `grimoire/apps/<id>/README.md`. */\nexport function parseAppReadme(\n file: string,\n text: string,\n folder: string,\n fallbackType: \"site\" | \"mobile\",\n sink: FindingSink,\n): AppReadme {\n const document = readDocument(file, text, \"required\", sink);\n const fields = new FrontMatterReader(document, sink);\n\n fields.onlyKeys([\"id\", \"type\", \"root\", \"origin\"], \"app README\");\n\n const id = fields.required(\"id\", checks.id);\n\n if (id.value !== \"\" && id.value !== folder) {\n sink.report(\n \"GR1019\",\n `the app id ${JSON.stringify(id.value)} must equal its folder name ${JSON.stringify(folder)}.`,\n id.at,\n );\n }\n\n const root = fields.required(\"root\", checks.folder);\n\n checkHeadings(document, { title: false, required: [\"Conditions\"], optional: [] }, sink);\n\n return {\n id: id.value === \"\" ? { value: folder, at: id.at } : id,\n type: fields.oneOf(\"type\", [\"site\", \"mobile\"] as const, fallbackType),\n root: { value: projectFolder(root.value) ?? root.value, at: root.at },\n origin: fields.optionalOneOf(\"origin\", ORIGINS),\n heading: heading(document),\n conditions: readListLines(file, findSection(document, \"conditions\")?.lines, \"Conditions\", sink),\n };\n}\n\n/** `grimoire/apps/<app>/layouts/<id>.md`. */\nexport function parseLayout(\n file: string,\n text: string,\n app: string,\n id: string,\n sink: FindingSink,\n): WrittenLayout {\n const document = readDocument(file, text, \"none\", sink);\n const fields = new FrontMatterReader(document, sink);\n\n fields.onlyKeys([\"origin\"], \"a layout\");\n checkHeadings(document, { title: false, required: [\"Blocks\"], optional: [] }, sink);\n\n const blocks = findSection(document, \"blocks\");\n\n return {\n file,\n app,\n id,\n origin: fields.optionalOneOf(\"origin\", ORIGINS),\n heading: heading(document),\n blocks: blocks ? parseBlocksTable(file, blocks, sink) : [],\n };\n}\n\n/** `grimoire/apps/<app>/pages/<id>/README.md` or `screens/<id>/README.md`. */\nexport function parsePage(\n file: string,\n text: string,\n app: string,\n type: \"page\" | \"screen\",\n id: string,\n sink: FindingSink,\n): WrittenPage {\n const document = readDocument(file, text, \"required\", sink);\n const fields = new FrontMatterReader(document, sink);\n\n fields.onlyKeys(\n type === \"page\" ? [\"route\", \"layout\", \"origin\"] : [\"route\", \"screen\", \"layout\", \"origin\"],\n type,\n );\n\n const route = fields.scalar(\"route\", { required: type === \"page\", check: checks.route });\n const screen =\n type === \"screen\" ? fields.scalar(\"screen\", { required: false, check: checks.name }) : null;\n\n if (type === \"screen\" && fields.present && route === null && screen === null) {\n sink.report(\n \"GR1003\",\n 'a screen needs the front matter key \"route\" (file-based routing) or \"screen\" (its name in code).',\n lineAt(file, 1),\n );\n }\n\n checkHeadings(\n document,\n { title: true, required: [], optional: [\"Blocks\", \"Also reached from\"] },\n sink,\n );\n\n const blocks = findSection(document, \"blocks\");\n const alsoReachedFrom: WrittenEntryPoint[] = readListLines(\n file,\n findSection(document, \"also reached from\")?.lines,\n \"Also reached from\",\n sink,\n ).map((line) => ({ type: line.name, name: line.text, at: line.at }));\n\n return {\n file,\n app,\n type,\n id,\n route,\n screen,\n layout: fields.scalar(\"layout\", { required: false, check: checks.id }),\n origin: fields.optionalOneOf(\"origin\", ORIGINS),\n heading: heading(document),\n purpose: paragraphAfterTitle(document),\n blocks: blocks ? parseBlocksTable(file, blocks, sink) : [],\n alsoReachedFrom,\n blockFiles: [],\n };\n}\n\n/** `grimoire/apps/<app>/pages/<page>/blocks/<id>.md`. */\nexport function parseBlockFile(\n file: string,\n text: string,\n app: string,\n page: string,\n id: string,\n sink: FindingSink,\n): WrittenBlockFile {\n const document = readDocument(file, text, \"required\", sink);\n const fields = new FrontMatterReader(document, sink);\n\n fields.onlyKeys([\"flow\"], \"block file\");\n\n return {\n file,\n app,\n page,\n id,\n flow: fields.scalar(\"flow\", { required: true, check: checks.flowRef }),\n heading: heading(document),\n details: readListLines(file, document.body, \"detail\", sink),\n };\n}\n"],"mappings":";;;;;;AAyCA,MAAM,gBAAgB;CAAC;CAAS;CAAQ;CAAe;AAAc;AACrE,MAAM,aAAa;AACnB,MAAM,iBAAiB;AACvB,MAAM,iBAAiB;AAEvB,SAAS,QAAQ,UAAmD;CAClE,O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U;EAAE,MAAM,KAAK;EAAM,MAAM,KAAK;EAAM,IAAI,KAAK;CAAG,EAAE;CAEnE,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA,QAAQ,OAAO,OAAO,UAAU;GAAE,UAAU;GAAO,OAAO,OAAO;EAAG,CAAC;EACrE,QAAQ,OAAO,cAAc,UAAU,OAAO;EAC9C,SAAS,QAAQ,QAAQ;EACzB,SAAS,oBAAoB,QAAQ;EACrC,QAAQ,SAAS,iBAAiB,MAAM,QAAQ,IAAI,IAAI,CAAC;EACzD;EACA,YAAY,CAAC;CACf;AACF;;AAGA,SAAgB,eACd,MACA,MACA,KACA,MACA,IACA,MACkB;CAClB,MAAM,WAAW,aAAa,MAAM,MAAM,YAAY,IAAI;CAC1D,MAAM,SAAS,IAAI,kBAAkB,UAAU,IAAI;CAEnD,OAAO,SAAS,CAAC,MAAM,GAAG,YAAY;CAEtC,OAAO;EACL;EACA;EACA;EACA;EACA,MAAM,OAAO,OAAO,QAAQ;GAAE,UAAU;GAAM,OAAO,OAAO;EAAQ,CAAC;EACrE,SAAS,QAAQ,QAAQ;EACzB,SAAS,cAAc,MAAM,SAAS,MAAM,UAAU,IAAI;CAC5D;AACF"}
|
|
1
|
+
{"version":3,"file":"apps.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/written/apps.ts"],"sourcesContent":["/**\n * The files of one app folder: `README.md`, `layouts/<id>.md`,\n * `pages/<id>/README.md`, `screens/<id>/README.md` and their\n * `blocks/<id>.md` files, and the `## Blocks` table they share.\n */\nimport type {\n WrittenBlockFile,\n WrittenBlockRow,\n WrittenChangesWith,\n WrittenEntryPoint,\n WrittenLayout,\n WrittenListLine,\n WrittenOrigin,\n WrittenPage,\n} from \"../contracts/written\";\nimport type { Located } from \"../contracts/location\";\nimport { ORIGINS } from \"./features\";\nimport { FLOW_REF, FrontMatterReader, checks, projectFolder } from \"./fields\";\nimport { readListLines } from \"./lists\";\nimport {\n checkHeadings,\n findSection,\n lineAt,\n normalizeKey,\n paragraphAfterTitle,\n readDocument,\n readScreenshots,\n type BodyLine,\n type WrittenDocument,\n} from \"./markdown\";\nimport type { FindingSink } from \"./sink\";\n\n/** The parts of `grimoire/apps/<id>/README.md` (the folder's other files are added by the walker). */\nexport type AppReadme = {\n id: Located<string>;\n type: Located<\"site\" | \"mobile\">;\n root: Located<string>;\n origin: Located<WrittenOrigin> | null;\n heading: Located<string> | null;\n conditions: WrittenListLine[];\n};\n\nconst BLOCK_COLUMNS = [\"block\", \"flow\", \"who sees it\", \"changes with\"];\nconst EMPTY_CELL = /^(?:—|–|-+)?$/;\nconst SEPARATOR_CELL = /^:?-+:?$/;\nconst CONDITION_ITEM = /^([a-z][a-z0-9-]*(?::[a-z0-9-]+)?):[ \\t]+(\\S.*)$/;\n\nfunction heading(document: WrittenDocument): Located<string> | null {\n return document.title\n ? { value: document.title.text, at: lineAt(document.file, document.title.line) }\n : null;\n}\n\n/** The cells of a table row, with or without outer pipes; `\\|` stays a pipe inside a cell. */\nexport function tableCells(row: string): string[] {\n let text = row.trim();\n\n if (text.startsWith(\"|\")) text = text.slice(1);\n if (text.endsWith(\"|\") && !text.endsWith(\"\\\\|\")) text = text.slice(0, -1);\n\n return text.split(/(?<!\\\\)\\|/).map((cell) => cell.trim().replace(/\\\\\\|/g, \"|\"));\n}\n\n/**\n * Read the `## Blocks` table: a header row `Block | Flow | Who sees it |\n * Changes with`, a separator row, then one row per block. Text before the\n * table is allowed; the table ends at the first line without a `|`.\n */\nexport function parseBlocksTable(\n file: string,\n section: { line: number; lines: readonly BodyLine[] },\n sink: FindingSink,\n): WrittenBlockRow[] {\n const rows: WrittenBlockRow[] = [];\n const lines = section.lines;\n const start = lines.findIndex((line) => !line.fenced && line.text.includes(\"|\"));\n\n if (start === -1) {\n sink.report(\"GR1018\", \"the Blocks section has no table.\", lineAt(file, section.line));\n\n return rows;\n }\n\n const header = lines[start];\n const separator = lines[start + 1];\n\n if (header === undefined) return rows;\n\n const columns = tableCells(header.text).map(normalizeKey);\n\n if (\n columns.length !== BLOCK_COLUMNS.length ||\n columns.some((column, index) => column !== BLOCK_COLUMNS[index])\n ) {\n sink.report(\n \"GR1018\",\n `the Blocks table header is ${JSON.stringify(header.text.trim())}; use the columns Block | Flow | Who sees it | Changes with.`,\n lineAt(file, header.line),\n );\n\n return rows;\n }\n\n const separatorCells =\n separator === undefined || separator.fenced ? [] : tableCells(separator.text);\n\n if (\n separatorCells.length !== BLOCK_COLUMNS.length ||\n !separatorCells.every((cell) => SEPARATOR_CELL.test(cell))\n ) {\n sink.report(\n \"GR1018\",\n \"the Blocks table header is not followed by a separator row (`| --- | --- | --- | --- |`).\",\n lineAt(file, separator?.line ?? header.line),\n );\n\n return rows;\n }\n\n for (let index = start + 2; index < lines.length; index++) {\n const line = lines[index];\n\n if (line === undefined || line.fenced || !line.text.includes(\"|\")) break;\n\n const at = lineAt(file, line.line);\n const cells = tableCells(line.text);\n\n if (cells.length !== BLOCK_COLUMNS.length) {\n sink.report(\"GR1018\", `the Blocks row has ${cells.length} cells instead of 4.`, at);\n continue;\n }\n\n const [block = \"\", flow = \"\", who = \"\", changesWith = \"\"] = cells;\n\n if (block === \"\") {\n sink.report(\"GR1018\", \"the Blocks row has no block name.\", at);\n continue;\n }\n\n if (!EMPTY_CELL.test(flow) && !FLOW_REF.test(flow)) {\n sink.report(\n \"GR1018\",\n `the Flow cell ${JSON.stringify(flow)} of block \"${block}\" is not <feature>/<flow> or —.`,\n at,\n );\n continue;\n }\n\n if (EMPTY_CELL.test(who)) {\n sink.report(\n \"GR1018\",\n `the \"Who sees it\" cell of block \"${block}\" is empty; write everyone or condition names.`,\n at,\n );\n continue;\n }\n\n const whoItems = who\n .split(\",\")\n .map((item) => item.trim())\n .filter((item) => item !== \"\");\n\n rows.push({\n block,\n flow: EMPTY_CELL.test(flow) ? null : flow,\n who: {\n everyone: whoItems.some((item) => item.toLowerCase() === \"everyone\"),\n conditions: whoItems.filter((item) => item.toLowerCase() !== \"everyone\"),\n },\n changesWith: EMPTY_CELL.test(changesWith)\n ? []\n : changesWith\n .split(\";\")\n .map((item) => item.trim())\n .filter((item) => item !== \"\")\n .map((item): WrittenChangesWith => {\n const condition = CONDITION_ITEM.exec(item);\n\n return condition\n ? { condition: condition[1] ?? \"\", text: (condition[2] ?? \"\").trim() }\n : { condition: null, text: item };\n }),\n at,\n });\n }\n\n return rows;\n}\n\n/** `grimoire/apps/<id>/README.md`. */\nexport function parseAppReadme(\n file: string,\n text: string,\n folder: string,\n fallbackType: \"site\" | \"mobile\",\n sink: FindingSink,\n): AppReadme {\n const document = readDocument(file, text, \"required\", sink);\n const fields = new FrontMatterReader(document, sink);\n\n fields.onlyKeys([\"id\", \"type\", \"root\", \"origin\"], \"app README\");\n\n const id = fields.required(\"id\", checks.id);\n\n if (id.value !== \"\" && id.value !== folder) {\n sink.report(\n \"GR1019\",\n `the app id ${JSON.stringify(id.value)} must equal its folder name ${JSON.stringify(folder)}.`,\n id.at,\n );\n }\n\n const root = fields.required(\"root\", checks.folder);\n\n checkHeadings(document, { title: false, required: [\"Conditions\"], optional: [] }, sink);\n\n return {\n id: id.value === \"\" ? { value: folder, at: id.at } : id,\n type: fields.oneOf(\"type\", [\"site\", \"mobile\"] as const, fallbackType),\n root: { value: projectFolder(root.value) ?? root.value, at: root.at },\n origin: fields.optionalOneOf(\"origin\", ORIGINS),\n heading: heading(document),\n conditions: readListLines(file, findSection(document, \"conditions\")?.lines, \"Conditions\", sink),\n };\n}\n\n/** `grimoire/apps/<app>/layouts/<id>.md`. */\nexport function parseLayout(\n file: string,\n text: string,\n app: string,\n id: string,\n sink: FindingSink,\n): WrittenLayout {\n const document = readDocument(file, text, \"none\", sink);\n const fields = new FrontMatterReader(document, sink);\n\n fields.onlyKeys([\"origin\"], \"a layout\");\n checkHeadings(document, { title: false, required: [\"Blocks\"], optional: [] }, sink);\n\n const blocks = findSection(document, \"blocks\");\n\n return {\n file,\n app,\n id,\n origin: fields.optionalOneOf(\"origin\", ORIGINS),\n heading: heading(document),\n blocks: blocks ? parseBlocksTable(file, blocks, sink) : [],\n };\n}\n\n/** `grimoire/apps/<app>/pages/<id>/README.md` or `screens/<id>/README.md`. */\nexport function parsePage(\n file: string,\n text: string,\n app: string,\n type: \"page\" | \"screen\",\n id: string,\n sink: FindingSink,\n): WrittenPage {\n const document = readDocument(file, text, \"required\", sink);\n const fields = new FrontMatterReader(document, sink);\n\n fields.onlyKeys(\n type === \"page\" ? [\"route\", \"layout\", \"origin\"] : [\"route\", \"screen\", \"layout\", \"origin\"],\n type,\n );\n\n const route = fields.scalar(\"route\", { required: type === \"page\", check: checks.route });\n const screen =\n type === \"screen\" ? fields.scalar(\"screen\", { required: false, check: checks.name }) : null;\n\n if (type === \"screen\" && fields.present && route === null && screen === null) {\n sink.report(\n \"GR1003\",\n 'a screen needs the front matter key \"route\" (file-based routing) or \"screen\" (its name in code).',\n lineAt(file, 1),\n );\n }\n\n checkHeadings(\n document,\n { title: true, required: [], optional: [\"Blocks\", \"Also reached from\"] },\n sink,\n );\n\n const blocks = findSection(document, \"blocks\");\n const alsoReachedFrom: WrittenEntryPoint[] = readListLines(\n file,\n findSection(document, \"also reached from\")?.lines,\n \"Also reached from\",\n sink,\n ).map((line) => ({ type: line.name, name: line.text, at: line.at }));\n\n return {\n file,\n app,\n type,\n id,\n route,\n screen,\n layout: fields.scalar(\"layout\", { required: false, check: checks.id }),\n origin: fields.optionalOneOf(\"origin\", ORIGINS),\n heading: heading(document),\n purpose: paragraphAfterTitle(document),\n screenshots: readScreenshots(file, document.body, sink),\n blocks: blocks ? parseBlocksTable(file, blocks, sink) : [],\n alsoReachedFrom,\n blockFiles: [],\n };\n}\n\n/** `grimoire/apps/<app>/pages/<page>/blocks/<id>.md`. */\nexport function parseBlockFile(\n file: string,\n text: string,\n app: string,\n page: string,\n id: string,\n sink: FindingSink,\n): WrittenBlockFile {\n const document = readDocument(file, text, \"required\", sink);\n const fields = new FrontMatterReader(document, sink);\n\n fields.onlyKeys([\"flow\"], \"block file\");\n\n return {\n file,\n app,\n page,\n id,\n flow: fields.scalar(\"flow\", { required: true, check: checks.flowRef }),\n heading: heading(document),\n details: readListLines(file, document.body, \"detail\", sink),\n screenshots: readScreenshots(file, document.body, sink),\n };\n}\n"],"mappings":";;;;;;AA0CA,MAAM,gBAAgB;CAAC;CAAS;CAAQ;CAAe;AAAc;AACrE,MAAM,aAAa;AACnB,MAAM,iBAAiB;AACvB,MAAM,iBAAiB;AAEvB,SAAS,QAAQ,UAAmD;CAClE,OAAO,SAAS,QACZ;EAAE,OAAO,SAAS,MAAM;EAAM,IAAI,OAAO,SAAS,MAAM,SAAS,MAAM,IAAI;CAAE,IAC7E;AACN;;AAGA,SAAgB,WAAW,KAAuB;CAChD,IAAI,OAAO,IAAI,KAAK;CAEpB,IAAI,KAAK,WAAW,GAAG,GAAG,OAAO,KAAK,MAAM,CAAC;CAC7C,IAAI,KAAK,SAAS,GAAG,KAAK,CAAC,KAAK,SAAS,KAAK,GAAG,OAAO,KAAK,MAAM,GAAG,EAAE;CAExE,OAAO,KAAK,MAAM,WAAW,CAAC,CAAC,KAAK,SAAS,KAAK,KAAK,CAAC,CAAC,QAAQ,SAAS,GAAG,CAAC;AAChF;;;;;;AAOA,SAAgB,iBACd,MACA,SACA,MACmB;CACnB,MAAM,OAA0B,CAAC;CACjC,MAAM,QAAQ,QAAQ;CACtB,MAAM,QAAQ,MAAM,WAAW,SAAS,CAAC,KAAK,UAAU,KAAK,KAAK,SAAS,GAAG,CAAC;CAE/E,IAAI,UAAU,IAAI;EAChB,KAAK,OAAO,UAAU,oCAAoC,OAAO,MAAM,QAAQ,IAAI,CAAC;EAEpF,OAAO;CACT;CAEA,MAAM,SAAS,MAAM;CACrB,MAAM,YAAY,MAAM,QAAQ;CAEhC,IAAI,WAAW,QAAW,OAAO;CAEjC,MAAM,UAAU,WAAW,OAAO,IAAI,CAAC,CAAC,IAAI,YAAY;CAExD,IACE,QAAQ,WAAW,cAAc,UACjC,QAAQ,MAAM,QA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../contracts/written.mjs";
|
|
2
|
-
import { checkHeadings, findSection, lineAt, logicalLines, normalizeKey, paragraphAfterTitle, readDocument } from "./markdown.mjs";
|
|
2
|
+
import { checkHeadings, findSection, isImageLine, lineAt, logicalLines, normalizeKey, paragraphAfterTitle, readDocument, readScreenshots, withoutImages } from "./markdown.mjs";
|
|
3
3
|
import { FrontMatterReader, ID, SEP, VERSION, checks, isDate, projectFolder } from "./fields.mjs";
|
|
4
4
|
import { BULLET, bulletLines, readListLines, splitListLine } from "./lists.mjs";
|
|
5
5
|
|
|
@@ -75,6 +75,22 @@ function splitEntryText(text) {
|
|
|
75
75
|
text: rest
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
|
+
/** `## Why`: the paragraphs of the section, joined with a blank line; `null` when absent or empty. */
|
|
79
|
+
function readWhy(document) {
|
|
80
|
+
const paragraphs = [];
|
|
81
|
+
let open = [];
|
|
82
|
+
const close = () => {
|
|
83
|
+
if (open.length > 0) paragraphs.push(open.join(" "));
|
|
84
|
+
open = [];
|
|
85
|
+
};
|
|
86
|
+
for (const line of findSection(document, "why")?.lines ?? []) {
|
|
87
|
+
const trimmed = line.text.trim();
|
|
88
|
+
if (line.fenced || trimmed === "") close();
|
|
89
|
+
else open.push(trimmed);
|
|
90
|
+
}
|
|
91
|
+
close();
|
|
92
|
+
return paragraphs.length > 0 ? paragraphs.join("\n\n") : null;
|
|
93
|
+
}
|
|
78
94
|
/** `grimoire/features/<id>/README.md`. */
|
|
79
95
|
function parseFeatureReadme(file, text, folder, sink) {
|
|
80
96
|
const document = readDocument(file, text, "required", sink);
|
|
@@ -87,7 +103,8 @@ function parseFeatureReadme(file, text, folder, sink) {
|
|
|
87
103
|
"updated",
|
|
88
104
|
"apps",
|
|
89
105
|
"folders",
|
|
90
|
-
"origin"
|
|
106
|
+
"origin",
|
|
107
|
+
"audience"
|
|
91
108
|
], "feature README");
|
|
92
109
|
const id = fields.required("id", checks.id);
|
|
93
110
|
sameAsName(id, folder, "feature id", sink);
|
|
@@ -110,13 +127,22 @@ function parseFeatureReadme(file, text, folder, sink) {
|
|
|
110
127
|
origin: fields.optionalOneOf("origin", ORIGINS),
|
|
111
128
|
heading: heading(document),
|
|
112
129
|
summary: paragraphAfterTitle(document),
|
|
130
|
+
audience: fields.list("audience", {
|
|
131
|
+
required: false,
|
|
132
|
+
check: checks.text
|
|
133
|
+
}),
|
|
134
|
+
why: readWhy(document),
|
|
113
135
|
flows: [],
|
|
114
136
|
relations: []
|
|
115
137
|
};
|
|
116
138
|
checkHeadings(document, {
|
|
117
139
|
title: true,
|
|
118
140
|
required: [],
|
|
119
|
-
optional: [
|
|
141
|
+
optional: [
|
|
142
|
+
"Why",
|
|
143
|
+
"Flows",
|
|
144
|
+
"Affects and affected by"
|
|
145
|
+
]
|
|
120
146
|
}, sink);
|
|
121
147
|
for (const flow of readListLines(file, findSection(document, "flows")?.lines, "Flows", sink)) {
|
|
122
148
|
if (!ID.test(flow.name)) {
|
|
@@ -280,6 +306,82 @@ function parseSteps(file, document, sink) {
|
|
|
280
306
|
if (first !== void 0) sink.report("GR1010", `step ${first.number} should be step ${wrong + 1}; number the steps 1, 2, 3 in order.`, lineAt(file, first.line));
|
|
281
307
|
return steps;
|
|
282
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* `## Story`: numbered sentences in the user's words. Indented lines continue
|
|
311
|
+
* the item, image lines attach screenshots. GR1008 for any other line, GR1010
|
|
312
|
+
* for numbers out of order.
|
|
313
|
+
*/
|
|
314
|
+
function parseStory(file, document, sink) {
|
|
315
|
+
const story = [];
|
|
316
|
+
const numbers = [];
|
|
317
|
+
let open = null;
|
|
318
|
+
let continuing = false;
|
|
319
|
+
const finish = () => {
|
|
320
|
+
if (open !== null) open.step.text = open.text.join(" ");
|
|
321
|
+
open = null;
|
|
322
|
+
};
|
|
323
|
+
const attach = (line) => {
|
|
324
|
+
open?.step.screenshots.push(...readScreenshots(file, [line], sink));
|
|
325
|
+
};
|
|
326
|
+
for (const line of findSection(document, "story")?.lines ?? []) {
|
|
327
|
+
const trimmed = line.text.trim();
|
|
328
|
+
const at = lineAt(file, line.line);
|
|
329
|
+
if (line.fenced) {
|
|
330
|
+
continuing = false;
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
if (trimmed === "") {
|
|
334
|
+
continuing = false;
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
const numbered = NUMBERED.exec(trimmed);
|
|
338
|
+
if (numbered) {
|
|
339
|
+
finish();
|
|
340
|
+
const sentence = withoutImages(trimmed.replace(NUMBERED, ""));
|
|
341
|
+
if (sentence === "") {
|
|
342
|
+
sink.report("GR1008", `the story line ${JSON.stringify(trimmed)} is not \`<n>. <sentence>\`.`, at);
|
|
343
|
+
continuing = false;
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
const number = Number(numbered[1]);
|
|
347
|
+
const step = {
|
|
348
|
+
index: number,
|
|
349
|
+
text: sentence,
|
|
350
|
+
screenshots: [],
|
|
351
|
+
at
|
|
352
|
+
};
|
|
353
|
+
numbers.push({
|
|
354
|
+
number,
|
|
355
|
+
line: line.line
|
|
356
|
+
});
|
|
357
|
+
story.push(step);
|
|
358
|
+
open = {
|
|
359
|
+
step,
|
|
360
|
+
text: [sentence]
|
|
361
|
+
};
|
|
362
|
+
continuing = true;
|
|
363
|
+
attach(line);
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
if (isImageLine(trimmed)) {
|
|
367
|
+
if (open === null) sink.report("GR1008", `the story line ${JSON.stringify(trimmed)} is an image before any story step.`, at);
|
|
368
|
+
else attach(line);
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
if (open !== null && continuing && /^[ \t]/.test(line.text)) {
|
|
372
|
+
const more = withoutImages(trimmed);
|
|
373
|
+
if (more !== "") open.text.push(more);
|
|
374
|
+
attach(line);
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
sink.report("GR1008", `the story line ${JSON.stringify(trimmed)} is not \`<n>. <sentence>\`.`, at);
|
|
378
|
+
}
|
|
379
|
+
finish();
|
|
380
|
+
const wrong = numbers.findIndex((entry, position) => entry.number !== position + 1);
|
|
381
|
+
const first = numbers[wrong];
|
|
382
|
+
if (first !== void 0) sink.report("GR1010", `story step ${first.number} should be story step ${wrong + 1}; number the story steps 1, 2, 3 in order.`, lineAt(file, first.line));
|
|
383
|
+
return story;
|
|
384
|
+
}
|
|
283
385
|
function parseCases(file, document, sink) {
|
|
284
386
|
const cases = [];
|
|
285
387
|
for (const line of bulletLines(findSection(document, "cases")?.lines ?? [])) {
|
|
@@ -289,11 +391,14 @@ function parseCases(file, document, sink) {
|
|
|
289
391
|
continue;
|
|
290
392
|
}
|
|
291
393
|
const question = normalizeKey(split.name);
|
|
394
|
+
const suffix = CRITERIA_SUFFIX.exec(split.text);
|
|
395
|
+
const answer = suffix ? split.text.slice(0, suffix.index).trimEnd() : split.text;
|
|
292
396
|
cases.push({
|
|
293
397
|
question,
|
|
294
398
|
fixed: CASE_QUESTIONS.includes(question),
|
|
295
|
-
answer
|
|
296
|
-
doesNotApply: /^does not apply\b/i.test(
|
|
399
|
+
answer,
|
|
400
|
+
doesNotApply: /^does not apply\b/i.test(answer),
|
|
401
|
+
criteria: suffix ? (suffix[1] ?? "").split(",").map((criterion) => criterion.trim()) : [],
|
|
297
402
|
at: lineAt(file, line.line)
|
|
298
403
|
});
|
|
299
404
|
}
|
|
@@ -348,6 +453,8 @@ function parseFlow(file, text, feature, name, sink) {
|
|
|
348
453
|
who: fields.required("who", checks.text),
|
|
349
454
|
origin: fields.optionalOneOf("origin", ORIGINS),
|
|
350
455
|
heading: heading(document),
|
|
456
|
+
summary: paragraphAfterTitle(document),
|
|
457
|
+
story: [],
|
|
351
458
|
steps: [],
|
|
352
459
|
differs: [],
|
|
353
460
|
cases: [],
|
|
@@ -362,8 +469,14 @@ function parseFlow(file, text, feature, name, sink) {
|
|
|
362
469
|
"Cases",
|
|
363
470
|
"Acceptance criteria"
|
|
364
471
|
],
|
|
365
|
-
optional: [
|
|
472
|
+
optional: [
|
|
473
|
+
"Story",
|
|
474
|
+
"Differs by app",
|
|
475
|
+
"Not handled"
|
|
476
|
+
]
|
|
366
477
|
}, sink);
|
|
478
|
+
if (flow.summary === null) sink.report("GR1030", "the flow has no summary; write one or two sentences under the title.", lineAt(file, document.title?.line ?? document.bodyStartLine));
|
|
479
|
+
flow.story = parseStory(file, document, sink);
|
|
367
480
|
flow.steps = parseSteps(file, document, sink);
|
|
368
481
|
flow.differs = readListLines(file, findSection(document, "differs by app")?.lines, "Differs by app", sink);
|
|
369
482
|
flow.cases = parseCases(file, document, sink);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/written/features.ts"],"sourcesContent":["/**\n * The files of one feature folder: `README.md`, `CHANGELOG.md`,\n * `flows/<flow>.md` and `versions/v<n>.md`.\n */\nimport type { SourceLocation } from \"../contracts/location\";\nimport {\n CASE_QUESTIONS,\n type ChangeWord,\n type StepType,\n type WrittenCase,\n type WrittenChangelog,\n type WrittenChangelogEntry,\n type WrittenChangelogSection,\n type WrittenCriterion,\n type WrittenFeatureReadme,\n type WrittenFlow,\n type WrittenOrigin,\n type WrittenStatus,\n type WrittenStep,\n type WrittenVersionBrief,\n} from \"../contracts/written\";\nimport { FrontMatterReader, ID, SEP, VERSION, checks, isDate, projectFolder } from \"./fields\";\nimport { BULLET, bulletLines, readListLines, splitListLine } from \"./lists\";\nimport {\n checkHeadings,\n findSection,\n lineAt,\n logicalLines,\n normalizeKey,\n paragraphAfterTitle,\n readDocument,\n type WrittenDocument,\n} from \"./markdown\";\nimport type { FindingSink } from \"./sink\";\n\nexport const STATUSES: readonly WrittenStatus[] = [\"proposed\", \"building\", \"shipped\", \"retired\"];\nexport const ORIGINS: readonly WrittenOrigin[] = [\"inferred\", \"confirmed\"];\nexport const CHANGE_WORDS: readonly ChangeWord[] = [\"added\", \"changed\", \"fixed\", \"removed\"];\n/** Step kinds, longest first so `outside service` is tried before shorter words. */\nexport const STEP_TYPES: readonly StepType[] = [\n \"outside service\",\n \"notification\",\n \"affects\",\n \"event\",\n \"route\",\n \"page\",\n \"mail\",\n \"job\",\n];\n\n/** A status that is missing or wrong is read as `building`: never `proposed`, which would hide findings. */\nconst FALLBACK_STATUS: WrittenStatus = \"building\";\n\n// The parts of a step, a criterion and a changelog entry are split by spaces\n// or tabs: two or more line them up, one is read too (a Markdown formatter\n// collapses them).\nconst STEP = new RegExp(\n String.raw`^(\\d+)\\.[ \\t]+(${STEP_TYPES.join(\"|\")})[ \\t]+(\\S.*?)(?:[ \\t]+(?:—|--)[ \\t]+(\\S.*))?$`,\n);\nconst STEP_ANY_TYPE = new RegExp(String.raw`^(\\d+)\\.[ \\t]+(\\S.*?)${SEP}(\\S.*)$`);\nconst STEP_FIRST_WORD = /^(\\d+)\\.[ \\t]+(\\S+)[ \\t]+(\\S.*)$/;\nconst NUMBERED = /^(\\d+)\\.(?:[ \\t]|$)/;\nconst PAGE_TARGET = /^(\\S+)[ \\t]+\\[([a-z0-9]+(?:-[a-z0-9]+)*)\\]$/;\nconst ROUTE_TARGET = /^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|ALL)[ \\t]+(\\/\\S*)$/i;\nconst AFFECTS_TARGET = /^([a-z0-9]+(?:-[a-z0-9]+)*)(?:\\/([a-z0-9]+(?:-[a-z0-9]+)*))?$/;\nconst CRITERION = /^[-*][ \\t]+AC-(\\d+)(?:[ \\t]+\\[([a-z0-9-]+)\\])?[ \\t]+([^\\s[].*)$/;\nconst CHANGELOG_ENTRY = /^[-*][ \\t]+(\\S+)[ \\t]+(\\S+)[ \\t]+(\\S.*)$/;\nconst RELEASE_HEADING = /^##[ \\t]+(\\S+)[ \\t]+\\((.+)\\)$/;\nconst UNRELEASED_HEADING = /^##[ \\t]+unreleased$/i;\nconst FLOW_PREFIX = /^([a-z0-9-]+):[ \\t]+(\\S.*)$/;\nconst CRITERIA_SUFFIX = /[ \\t]*\\((AC-\\d+(?:[ \\t]*,[ \\t]*AC-\\d+)*)\\)$/;\nconst FLOW_REF_IN_TEXT =\n /(?<![\\w/-])([a-z0-9]+(?:-[a-z0-9]+)*\\/[a-z0-9]+(?:-[a-z0-9]+)*)(?![\\w/-])/g;\n\nfunction heading(document: WrittenDocument): WrittenFeatureReadme[\"heading\"] {\n return document.title\n ? { value: document.title.text, at: lineAt(document.file, document.title.line) }\n : null;\n}\n\n/** GR1019 when a front matter id differs from the folder or file name it must equal. */\nfunction sameAsName(\n located: { value: string; at: SourceLocation },\n name: string,\n what: string,\n sink: FindingSink,\n): void {\n if (located.value !== \"\" && located.value !== name) {\n sink.report(\n \"GR1019\",\n `the ${what} ${JSON.stringify(located.value)} must equal its ${JSON.stringify(name)} name.`,\n located.at,\n );\n }\n}\n\n/** The text of a changelog entry: the flow prefix, the text and the trailing criteria. */\nexport function splitEntryText(text: string): {\n flow: string | null;\n criteria: string[];\n text: string;\n} {\n let rest = text.trim();\n let flow: string | null = null;\n let criteria: string[] = [];\n const prefix = FLOW_PREFIX.exec(rest);\n\n if (prefix) {\n flow = prefix[1] ?? null;\n rest = prefix[2] ?? \"\";\n }\n\n const suffix = CRITERIA_SUFFIX.exec(rest);\n\n if (suffix) {\n criteria = (suffix[1] ?? \"\").split(\",\").map((criterion) => criterion.trim());\n rest = rest.slice(0, suffix.index).trimEnd();\n }\n\n return { flow, criteria, text: rest };\n}\n\n// ── README ─────────────────────────────────────────────────────────────────\n\n/** `grimoire/features/<id>/README.md`. */\nexport function parseFeatureReadme(\n file: string,\n text: string,\n folder: string,\n sink: FindingSink,\n): WrittenFeatureReadme {\n const document = readDocument(file, text, \"required\", sink);\n const fields = new FrontMatterReader(document, sink);\n\n fields.onlyKeys(\n [\"id\", \"title\", \"status\", \"version\", \"updated\", \"apps\", \"folders\", \"origin\"],\n \"feature README\",\n );\n\n const id = fields.required(\"id\", checks.id);\n sameAsName(id, folder, \"feature id\", sink);\n\n const readme: WrittenFeatureReadme = {\n file,\n id,\n title: fields.required(\"title\", checks.text),\n status: fields.oneOf(\"status\", STATUSES, FALLBACK_STATUS),\n version: fields.required(\"version\", checks.version),\n updated: fields.required(\"updated\", checks.date),\n apps: fields.list(\"apps\", { required: true, check: checks.id }),\n folders: fields.list(\"folders\", {\n required: true,\n check: checks.folder,\n map: (value) => projectFolder(value) ?? value,\n }),\n origin: fields.optionalOneOf(\"origin\", ORIGINS),\n heading: heading(document),\n summary: paragraphAfterTitle(document),\n flows: [],\n relations: [],\n };\n\n checkHeadings(\n document,\n { title: true, required: [], optional: [\"Flows\", \"Affects and affected by\"] },\n sink,\n );\n\n for (const flow of readListLines(file, findSection(document, \"flows\")?.lines, \"Flows\", sink)) {\n if (!ID.test(flow.name)) {\n sink.report(\n \"GR1028\",\n `the Flows line names ${JSON.stringify(flow.name)}, which is not a flow id.`,\n flow.at,\n );\n continue;\n }\n\n readme.flows.push(flow);\n }\n\n for (const line of logicalLines(findSection(document, \"affects and affected by\")?.lines ?? [])) {\n const relation = line.text.replace(BULLET, \"\").trim();\n\n readme.relations.push({\n text: relation,\n refs: [...relation.matchAll(FLOW_REF_IN_TEXT)].map((match) => match[1] ?? \"\"),\n at: lineAt(file, line.line),\n });\n }\n\n return readme;\n}\n\n// ── CHANGELOG ──────────────────────────────────────────────────────────────\n\n/** `grimoire/features/<feature>/CHANGELOG.md`. */\nexport function parseChangelog(\n file: string,\n text: string,\n feature: string,\n sink: FindingSink,\n): WrittenChangelog {\n const document = readDocument(file, text, \"none\", sink);\n\n new FrontMatterReader(document, sink).onlyKeys([], \"a changelog\");\n\n const sections: WrittenChangelogSection[] = [];\n const entries: WrittenChangelogEntry[] = [];\n const seen = new Set<string>();\n let current: WrittenChangelogSection | null = null;\n\n for (const line of logicalLines(document.body)) {\n const at = lineAt(file, line.line);\n\n if (/^#[ \\t]/.test(line.text)) continue;\n\n if (line.text.startsWith(\"#\")) {\n const release = RELEASE_HEADING.exec(line.text);\n let section: WrittenChangelogSection | null = null;\n\n if (UNRELEASED_HEADING.test(line.text)) {\n section = { release: null, date: null, at };\n } else if (release && isDate(release[2] ?? \"\")) {\n section = { release: release[1] ?? \"\", date: release[2] ?? \"\", at };\n }\n\n if (section === null) {\n sink.report(\n \"GR1017\",\n `the changelog heading ${JSON.stringify(line.text)} is neither \"## Unreleased\" nor \"## <release> (<yyyy-mm-dd>)\".`,\n at,\n );\n continue;\n }\n\n const key = section.release ?? \"\";\n\n if (seen.has(key)) {\n sink.report(\n \"GR1017\",\n `the changelog heading ${JSON.stringify(line.text)} is written twice; write each section once.`,\n at,\n );\n }\n\n seen.add(key);\n sections.push(section);\n current = section;\n continue;\n }\n\n if (!BULLET.test(line.text)) {\n sink.report(\"GR1015\", `the changelog line ${JSON.stringify(line.text)} is not an entry.`, at);\n continue;\n }\n\n const match = CHANGELOG_ENTRY.exec(line.text);\n const version = match?.[1] ?? \"\";\n const word = match?.[2] ?? \"\";\n\n if (!match || !VERSION.test(version)) {\n sink.report(\n \"GR1015\",\n `the changelog line ${JSON.stringify(line.text)} is not \\`- <version> <word> <text>\\`.`,\n at,\n );\n continue;\n }\n\n if (!CHANGE_WORDS.includes(word as ChangeWord)) {\n sink.report(\n \"GR1016\",\n `the changelog word ${JSON.stringify(word)} is not one of ${CHANGE_WORDS.join(\", \")}.`,\n at,\n );\n continue;\n }\n\n if (current === null) {\n sink.report(\n \"GR1015\",\n `the changelog entry ${JSON.stringify(line.text)} is not under \"## Unreleased\" or a release heading.`,\n at,\n );\n }\n\n const parts = splitEntryText(match[3] ?? \"\");\n\n entries.push({\n feature,\n version: { value: version, at },\n word: word as ChangeWord,\n flow: parts.flow,\n criteria: parts.criteria,\n text: parts.text,\n release: current?.release ?? null,\n date: current?.date ?? null,\n at,\n });\n }\n\n return { file, sections, entries };\n}\n\n// ── Flows ──────────────────────────────────────────────────────────────────\n\nfunction parseSteps(file: string, document: WrittenDocument, sink: FindingSink): WrittenStep[] {\n const steps: WrittenStep[] = [];\n const numbers: { number: number; line: number }[] = [];\n\n for (const line of logicalLines(findSection(document, \"steps\")?.lines ?? [])) {\n const at = lineAt(file, line.line);\n const numbered = NUMBERED.exec(line.text);\n\n if (!numbered) {\n if (BULLET.test(line.text)) {\n sink.report(\n \"GR1008\",\n `the step ${JSON.stringify(line.text)} is a bullet; number steps \\`1. <kind> <name>\\`.`,\n at,\n );\n }\n\n continue;\n }\n\n numbers.push({ number: Number(numbered[1]), line: line.line });\n\n const match = STEP.exec(line.text);\n\n if (!match) {\n const other = STEP_ANY_TYPE.exec(line.text) ?? STEP_FIRST_WORD.exec(line.text);\n const type = other?.[2] ?? \"\";\n\n if (other && !STEP_TYPES.includes(type as StepType)) {\n sink.report(\n \"GR1009\",\n `the step kind ${JSON.stringify(type)} is not one of: ${STEP_TYPES.join(\", \")}.`,\n at,\n );\n } else {\n sink.report(\n \"GR1008\",\n `the step ${JSON.stringify(line.text)} is not \\`<n>. <kind> <name>\\`.`,\n at,\n );\n }\n\n continue;\n }\n\n const type = match[2] as StepType;\n let target = (match[3] ?? \"\").trim();\n let app: string | null = null;\n let route: WrittenStep[\"route\"] = null;\n let affects: WrittenStep[\"affects\"] = null;\n\n if (type === \"page\") {\n const scoped = PAGE_TARGET.exec(target);\n\n if (scoped) {\n target = scoped[1] ?? \"\";\n app = scoped[2] ?? null;\n }\n }\n\n if (type === \"route\") {\n const routeMatch = ROUTE_TARGET.exec(target);\n\n if (!routeMatch) {\n sink.report(\n \"GR1008\",\n `the route step ${JSON.stringify(target)} is not \\`<METHOD> /path\\`.`,\n at,\n );\n continue;\n }\n\n route = { method: (routeMatch[1] ?? \"\").toUpperCase(), path: routeMatch[2] ?? \"\" };\n }\n\n if (type === \"affects\") {\n const affectsMatch = AFFECTS_TARGET.exec(target);\n\n if (!affectsMatch) {\n sink.report(\n \"GR1008\",\n `the affects step ${JSON.stringify(target)} is not \\`<feature>\\` or \\`<feature>/<flow>\\`.`,\n at,\n );\n continue;\n }\n\n affects = { feature: affectsMatch[1] ?? \"\", flow: affectsMatch[2] ?? null };\n }\n\n steps.push({\n index: Number(match[1]),\n type,\n target,\n app,\n route,\n affects,\n note: match[4]?.trim() ?? null,\n at,\n });\n }\n\n const wrong = numbers.findIndex((entry, position) => entry.number !== position + 1);\n const first = numbers[wrong];\n\n if (first !== undefined) {\n sink.report(\n \"GR1010\",\n `step ${first.number} should be step ${wrong + 1}; number the steps 1, 2, 3 in order.`,\n lineAt(file, first.line),\n );\n }\n\n return steps;\n}\n\nfunction parseCases(file: string, document: WrittenDocument, sink: FindingSink): WrittenCase[] {\n const cases: WrittenCase[] = [];\n\n for (const line of bulletLines(findSection(document, \"cases\")?.lines ?? [])) {\n const split = splitListLine(line.text, CASE_QUESTIONS);\n\n if (split === null) {\n sink.report(\n \"GR1011\",\n `the case ${JSON.stringify(line.text)} is not \\`- <question> <answer>\\`.`,\n lineAt(file, line.line),\n );\n continue;\n }\n\n const question = normalizeKey(split.name);\n\n cases.push({\n question,\n fixed: (CASE_QUESTIONS as readonly string[]).includes(question),\n answer: split.text,\n doesNotApply: /^does not apply\\b/i.test(split.text),\n at: lineAt(file, line.line),\n });\n }\n\n return cases;\n}\n\nfunction parseCriteria(\n file: string,\n document: WrittenDocument,\n sink: FindingSink,\n): WrittenCriterion[] {\n const criteria: WrittenCriterion[] = [];\n const seen = new Set<number>();\n\n for (const line of bulletLines(findSection(document, \"acceptance criteria\")?.lines ?? [])) {\n const at = lineAt(file, line.line);\n const match = CRITERION.exec(line.text);\n\n if (!match) {\n sink.report(\n \"GR1013\",\n `the criterion ${JSON.stringify(line.text)} is not \\`- AC-<n> <text>\\` or \\`- AC-<n> [<app>] <text>\\`.`,\n at,\n );\n continue;\n }\n\n const number = Number(match[1]);\n\n if (seen.has(number)) {\n sink.report(\"GR1014\", `AC-${number} is used twice in this flow.`, at);\n continue;\n }\n\n seen.add(number);\n criteria.push({\n id: `AC-${number}`,\n number,\n app: match[2] ?? null,\n text: (match[3] ?? \"\").trim(),\n at,\n });\n }\n\n return criteria;\n}\n\n/** `grimoire/features/<feature>/flows/<name>.md`. */\nexport function parseFlow(\n file: string,\n text: string,\n feature: string,\n name: string,\n sink: FindingSink,\n): WrittenFlow {\n const document = readDocument(file, text, \"required\", sink);\n const fields = new FrontMatterReader(document, sink);\n\n fields.onlyKeys([\"id\", \"since\", \"status\", \"who\", \"origin\"], \"flow\");\n\n const id = fields.required(\"id\", checks.id);\n sameAsName(id, name, \"flow id\", sink);\n\n const flow: WrittenFlow = {\n file,\n feature,\n id,\n ref: `${feature}/${name}`,\n since: fields.required(\"since\", checks.version),\n status: fields.oneOf(\"status\", STATUSES, FALLBACK_STATUS),\n who: fields.required(\"who\", checks.text),\n origin: fields.optionalOneOf(\"origin\", ORIGINS),\n heading: heading(document),\n steps: [],\n differs: [],\n cases: [],\n notHandled: [],\n unknowns: [],\n criteria: [],\n };\n\n checkHeadings(\n document,\n {\n title: true,\n required: [\"Steps\", \"Cases\", \"Acceptance criteria\"],\n optional: [\"Differs by app\", \"Not handled\"],\n },\n sink,\n );\n\n flow.steps = parseSteps(file, document, sink);\n flow.differs = readListLines(\n file,\n findSection(document, \"differs by app\")?.lines,\n \"Differs by app\",\n sink,\n );\n flow.cases = parseCases(file, document, sink);\n flow.notHandled = readListLines(\n file,\n findSection(document, \"not handled\")?.lines,\n \"Not handled\",\n sink,\n CASE_QUESTIONS,\n );\n flow.criteria = parseCriteria(file, document, sink);\n\n for (const line of document.body) {\n const trimmed = line.text.trim();\n\n if (!line.fenced && trimmed.startsWith(\"Unknown:\")) {\n flow.unknowns.push({\n text: trimmed.slice(\"Unknown:\".length).trim(),\n at: lineAt(file, line.line),\n });\n }\n }\n\n const cases = findSection(document, \"cases\");\n\n if (cases !== null) {\n const answered = new Set([\n ...flow.cases.map((entry) => entry.question),\n ...flow.notHandled.map((entry) => normalizeKey(entry.name)),\n ]);\n\n for (const question of CASE_QUESTIONS) {\n if (!answered.has(question)) {\n sink.report(\n \"GR1012\",\n `the case question \"${question}\" is answered neither under Cases nor under Not handled.`,\n lineAt(file, cases.line),\n );\n }\n }\n }\n\n return flow;\n}\n\n// ── Version briefs ─────────────────────────────────────────────────────────\n\n/** `grimoire/features/<feature>/versions/v<n>.md`: free text under a title. */\nexport function parseVersionBrief(\n file: string,\n text: string,\n feature: string,\n major: number,\n sink: FindingSink,\n): WrittenVersionBrief {\n const document = readDocument(file, text, \"none\", sink);\n\n new FrontMatterReader(document, sink).onlyKeys([], \"a version brief\");\n\n return { file, feature, major, heading: heading(document) };\n}\n"],"mappings":";;;;;;AAmCA,MAAa,WAAqC;CAAC;CAAY;CAAY;CAAW;AAAS;AAC/F,MAAa,UAAoC,CAAC,YAAY,WAAW;AACzE,MAAa,eAAsC;CAAC;CAAS;CAAW;CAAS;AAAS;;AAE1F,MAAa,aAAkC;CAC7C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAM,kBAAiC;AAKvC,MAAM,OAAO,IAAI,OACf,OAAO,GAAG,kBAAkB,WAAW,KAAK,GAAG,EAAE,+CACnD;AACA,MAAM,gBAAgB,IAAI,OAAO,OAAO,GAAG,wBAAwB,IAAI,QAAQ;AAC/E,MAAM,kBAAkB;AACxB,MAAM,WAAW;AACjB,MAAM,cAAc;AACpB,MAAM,eAAe;AACrB,MAAM,iBAAiB;AACvB,MAAM,YAAY;AAClB,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;AACxB,MAAM,qBAAqB;AAC3B,MAAM,cAAc;AACpB,MAAM,kBAAkB;AACxB,MAAM,mBACJ;AAEF,SAAS,QAAQ,UAA4D;CAC3E,OAAO,SAAS,QACZ;EAAE,OAAO,SAAS,MAAM;EAAM,IAAI,OAAO,SAAS,MAAM,SAAS,MAAM,IAAI;CAAE,IAC7E;AACN;;AAGA,SAAS,WACP,SACA,MACA,MACA,MACM;CACN,IAAI,QAAQ,UAAU,MAAM,QAAQ,UAAU,MAC5C,KAAK,OACH,UACA,OAAO,KAAK,GAAG,KAAK,UAAU,QAAQ,KAAK,EAAE,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M,2BAAW,IAAI,IAAI,CACvB,GAAG,KAAK,MAAM,KAAK,UAAU,MAAM,QAAQ,GAC3C,GAAG,KAAK,WAAW,KAAK,UAAU,aAAa,MAAM,IAAI,CAAC,CAC5D,CAAC;EAED,KAAK,MAAM,YAAY,gBACrB,IAAI,CAAC,SAAS,IAAI,QAAQ,GACxB,KAAK,OACH,UACA,sBAAsB,SAAS,2DAC/B,OAAO,MAAM,MAAM,IAAI,CACzB;CAGN;CAEA,OAAO;AACT;;AAKA,SAAgB,kBACd,MACA,MACA,SACA,OACA,MACqB;CACrB,MAAM,WAAW,aAAa,MAAM,MAAM,QAAQ,IAAI;CAEtD,IAAI,kBAAkB,UAAU,IAAI,CAAC,CAAC,SAAS,CAAC,GAAG,iBAAiB;CAEpE,OAAO;EAAE;EAAM;EAAS;EAAO,SAAS,QAAQ,QAAQ;CAAE;AAC5D"}
|
|
1
|
+
{"version":3,"file":"features.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/written/features.ts"],"sourcesContent":["/**\n * The files of one feature folder: `README.md`, `CHANGELOG.md`,\n * `flows/<flow>.md` and `versions/v<n>.md`.\n */\nimport type { SourceLocation } from \"../contracts/location\";\nimport {\n CASE_QUESTIONS,\n type ChangeWord,\n type StepType,\n type WrittenCase,\n type WrittenChangelog,\n type WrittenChangelogEntry,\n type WrittenChangelogSection,\n type WrittenCriterion,\n type WrittenFeatureReadme,\n type WrittenFlow,\n type WrittenOrigin,\n type WrittenStatus,\n type WrittenStep,\n type WrittenStoryStep,\n type WrittenVersionBrief,\n} from \"../contracts/written\";\nimport { FrontMatterReader, ID, SEP, VERSION, checks, isDate, projectFolder } from \"./fields\";\nimport { BULLET, bulletLines, readListLines, splitListLine } from \"./lists\";\nimport {\n checkHeadings,\n findSection,\n isImageLine,\n lineAt,\n logicalLines,\n normalizeKey,\n paragraphAfterTitle,\n readDocument,\n readScreenshots,\n withoutImages,\n type BodyLine,\n type WrittenDocument,\n} from \"./markdown\";\nimport type { FindingSink } from \"./sink\";\n\nexport const STATUSES: readonly WrittenStatus[] = [\"proposed\", \"building\", \"shipped\", \"retired\"];\nexport const ORIGINS: readonly WrittenOrigin[] = [\"inferred\", \"confirmed\"];\nexport const CHANGE_WORDS: readonly ChangeWord[] = [\"added\", \"changed\", \"fixed\", \"removed\"];\n/** Step kinds, longest first so `outside service` is tried before shorter words. */\nexport const STEP_TYPES: readonly StepType[] = [\n \"outside service\",\n \"notification\",\n \"affects\",\n \"event\",\n \"route\",\n \"page\",\n \"mail\",\n \"job\",\n];\n\n/** A status that is missing or wrong is read as `building`: never `proposed`, which would hide findings. */\nconst FALLBACK_STATUS: WrittenStatus = \"building\";\n\n// The parts of a step, a criterion and a changelog entry are split by spaces\n// or tabs: two or more line them up, one is read too (a Markdown formatter\n// collapses them).\nconst STEP = new RegExp(\n String.raw`^(\\d+)\\.[ \\t]+(${STEP_TYPES.join(\"|\")})[ \\t]+(\\S.*?)(?:[ \\t]+(?:—|--)[ \\t]+(\\S.*))?$`,\n);\nconst STEP_ANY_TYPE = new RegExp(String.raw`^(\\d+)\\.[ \\t]+(\\S.*?)${SEP}(\\S.*)$`);\nconst STEP_FIRST_WORD = /^(\\d+)\\.[ \\t]+(\\S+)[ \\t]+(\\S.*)$/;\nconst NUMBERED = /^(\\d+)\\.(?:[ \\t]|$)/;\nconst PAGE_TARGET = /^(\\S+)[ \\t]+\\[([a-z0-9]+(?:-[a-z0-9]+)*)\\]$/;\nconst ROUTE_TARGET = /^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|ALL)[ \\t]+(\\/\\S*)$/i;\nconst AFFECTS_TARGET = /^([a-z0-9]+(?:-[a-z0-9]+)*)(?:\\/([a-z0-9]+(?:-[a-z0-9]+)*))?$/;\nconst CRITERION = /^[-*][ \\t]+AC-(\\d+)(?:[ \\t]+\\[([a-z0-9-]+)\\])?[ \\t]+([^\\s[].*)$/;\nconst CHANGELOG_ENTRY = /^[-*][ \\t]+(\\S+)[ \\t]+(\\S+)[ \\t]+(\\S.*)$/;\nconst RELEASE_HEADING = /^##[ \\t]+(\\S+)[ \\t]+\\((.+)\\)$/;\nconst UNRELEASED_HEADING = /^##[ \\t]+unreleased$/i;\nconst FLOW_PREFIX = /^([a-z0-9-]+):[ \\t]+(\\S.*)$/;\nconst CRITERIA_SUFFIX = /[ \\t]*\\((AC-\\d+(?:[ \\t]*,[ \\t]*AC-\\d+)*)\\)$/;\nconst FLOW_REF_IN_TEXT =\n /(?<![\\w/-])([a-z0-9]+(?:-[a-z0-9]+)*\\/[a-z0-9]+(?:-[a-z0-9]+)*)(?![\\w/-])/g;\n\nfunction heading(document: WrittenDocument): WrittenFeatureReadme[\"heading\"] {\n return document.title\n ? { value: document.title.text, at: lineAt(document.file, document.title.line) }\n : null;\n}\n\n/** GR1019 when a front matter id differs from the folder or file name it must equal. */\nfunction sameAsName(\n located: { value: string; at: SourceLocation },\n name: string,\n what: string,\n sink: FindingSink,\n): void {\n if (located.value !== \"\" && located.value !== name) {\n sink.report(\n \"GR1019\",\n `the ${what} ${JSON.stringify(located.value)} must equal its ${JSON.stringify(name)} name.`,\n located.at,\n );\n }\n}\n\n/** The text of a changelog entry: the flow prefix, the text and the trailing criteria. */\nexport function splitEntryText(text: string): {\n flow: string | null;\n criteria: string[];\n text: string;\n} {\n let rest = text.trim();\n let flow: string | null = null;\n let criteria: string[] = [];\n const prefix = FLOW_PREFIX.exec(rest);\n\n if (prefix) {\n flow = prefix[1] ?? null;\n rest = prefix[2] ?? \"\";\n }\n\n const suffix = CRITERIA_SUFFIX.exec(rest);\n\n if (suffix) {\n criteria = (suffix[1] ?? \"\").split(\",\").map((criterion) => criterion.trim());\n rest = rest.slice(0, suffix.index).trimEnd();\n }\n\n return { flow, criteria, text: rest };\n}\n\n// ── README ─────────────────────────────────────────────────────────────────\n\n/** `## Why`: the paragraphs of the section, joined with a blank line; `null` when absent or empty. */\nfunction readWhy(document: WrittenDocument): string | null {\n const paragraphs: string[] = [];\n let open: string[] = [];\n\n const close = (): void => {\n if (open.length > 0) paragraphs.push(open.join(\" \"));\n\n open = [];\n };\n\n for (const line of findSection(document, \"why\")?.lines ?? []) {\n const trimmed = line.text.trim();\n\n if (line.fenced || trimmed === \"\") close();\n else open.push(trimmed);\n }\n\n close();\n\n return paragraphs.length > 0 ? paragraphs.join(\"\\n\\n\") : null;\n}\n\n/** `grimoire/features/<id>/README.md`. */\nexport function parseFeatureReadme(\n file: string,\n text: string,\n folder: string,\n sink: FindingSink,\n): WrittenFeatureReadme {\n const document = readDocument(file, text, \"required\", sink);\n const fields = new FrontMatterReader(document, sink);\n\n fields.onlyKeys(\n [\"id\", \"title\", \"status\", \"version\", \"updated\", \"apps\", \"folders\", \"origin\", \"audience\"],\n \"feature README\",\n );\n\n const id = fields.required(\"id\", checks.id);\n sameAsName(id, folder, \"feature id\", sink);\n\n const readme: WrittenFeatureReadme = {\n file,\n id,\n title: fields.required(\"title\", checks.text),\n status: fields.oneOf(\"status\", STATUSES, FALLBACK_STATUS),\n version: fields.required(\"version\", checks.version),\n updated: fields.required(\"updated\", checks.date),\n apps: fields.list(\"apps\", { required: true, check: checks.id }),\n folders: fields.list(\"folders\", {\n required: true,\n check: checks.folder,\n map: (value) => projectFolder(value) ?? value,\n }),\n origin: fields.optionalOneOf(\"origin\", ORIGINS),\n heading: heading(document),\n summary: paragraphAfterTitle(document),\n audience: fields.list(\"audience\", { required: false, check: checks.text }),\n why: readWhy(document),\n flows: [],\n relations: [],\n };\n\n checkHeadings(\n document,\n { title: true, required: [], optional: [\"Why\", \"Flows\", \"Affects and affected by\"] },\n sink,\n );\n\n for (const flow of readListLines(file, findSection(document, \"flows\")?.lines, \"Flows\", sink)) {\n if (!ID.test(flow.name)) {\n sink.report(\n \"GR1028\",\n `the Flows line names ${JSON.stringify(flow.name)}, which is not a flow id.`,\n flow.at,\n );\n continue;\n }\n\n readme.flows.push(flow);\n }\n\n for (const line of logicalLines(findSection(document, \"affects and affected by\")?.lines ?? [])) {\n const relation = line.text.replace(BULLET, \"\").trim();\n\n readme.relations.push({\n text: relation,\n refs: [...relation.matchAll(FLOW_REF_IN_TEXT)].map((match) => match[1] ?? \"\"),\n at: lineAt(file, line.line),\n });\n }\n\n return readme;\n}\n\n// ── CHANGELOG ──────────────────────────────────────────────────────────────\n\n/** `grimoire/features/<feature>/CHANGELOG.md`. */\nexport function parseChangelog(\n file: string,\n text: string,\n feature: string,\n sink: FindingSink,\n): WrittenChangelog {\n const document = readDocument(file, text, \"none\", sink);\n\n new FrontMatterReader(document, sink).onlyKeys([], \"a changelog\");\n\n const sections: WrittenChangelogSection[] = [];\n const entries: WrittenChangelogEntry[] = [];\n const seen = new Set<string>();\n let current: WrittenChangelogSection | null = null;\n\n for (const line of logicalLines(document.body)) {\n const at = lineAt(file, line.line);\n\n if (/^#[ \\t]/.test(line.text)) continue;\n\n if (line.text.startsWith(\"#\")) {\n const release = RELEASE_HEADING.exec(line.text);\n let section: WrittenChangelogSection | null = null;\n\n if (UNRELEASED_HEADING.test(line.text)) {\n section = { release: null, date: null, at };\n } else if (release && isDate(release[2] ?? \"\")) {\n section = { release: release[1] ?? \"\", date: release[2] ?? \"\", at };\n }\n\n if (section === null) {\n sink.report(\n \"GR1017\",\n `the changelog heading ${JSON.stringify(line.text)} is neither \"## Unreleased\" nor \"## <release> (<yyyy-mm-dd>)\".`,\n at,\n );\n continue;\n }\n\n const key = section.release ?? \"\";\n\n if (seen.has(key)) {\n sink.report(\n \"GR1017\",\n `the changelog heading ${JSON.stringify(line.text)} is written twice; write each section once.`,\n at,\n );\n }\n\n seen.add(key);\n sections.push(section);\n current = section;\n continue;\n }\n\n if (!BULLET.test(line.text)) {\n sink.report(\"GR1015\", `the changelog line ${JSON.stringify(line.text)} is not an entry.`, at);\n continue;\n }\n\n const match = CHANGELOG_ENTRY.exec(line.text);\n const version = match?.[1] ?? \"\";\n const word = match?.[2] ?? \"\";\n\n if (!match || !VERSION.test(version)) {\n sink.report(\n \"GR1015\",\n `the changelog line ${JSON.stringify(line.text)} is not \\`- <version> <word> <text>\\`.`,\n at,\n );\n continue;\n }\n\n if (!CHANGE_WORDS.includes(word as ChangeWord)) {\n sink.report(\n \"GR1016\",\n `the changelog word ${JSON.stringify(word)} is not one of ${CHANGE_WORDS.join(\", \")}.`,\n at,\n );\n continue;\n }\n\n if (current === null) {\n sink.report(\n \"GR1015\",\n `the changelog entry ${JSON.stringify(line.text)} is not under \"## Unreleased\" or a release heading.`,\n at,\n );\n }\n\n const parts = splitEntryText(match[3] ?? \"\");\n\n entries.push({\n feature,\n version: { value: version, at },\n word: word as ChangeWord,\n flow: parts.flow,\n criteria: parts.criteria,\n text: parts.text,\n release: current?.release ?? null,\n date: current?.date ?? null,\n at,\n });\n }\n\n return { file, sections, entries };\n}\n\n// ── Flows ──────────────────────────────────────────────────────────────────\n\nfunction parseSteps(file: string, document: WrittenDocument, sink: FindingSink): WrittenStep[] {\n const steps: WrittenStep[] = [];\n const numbers: { number: number; line: number }[] = [];\n\n for (const line of logicalLines(findSection(document, \"steps\")?.lines ?? [])) {\n const at = lineAt(file, line.line);\n const numbered = NUMBERED.exec(line.text);\n\n if (!numbered) {\n if (BULLET.test(line.text)) {\n sink.report(\n \"GR1008\",\n `the step ${JSON.stringify(line.text)} is a bullet; number steps \\`1. <kind> <name>\\`.`,\n at,\n );\n }\n\n continue;\n }\n\n numbers.push({ number: Number(numbered[1]), line: line.line });\n\n const match = STEP.exec(line.text);\n\n if (!match) {\n const other = STEP_ANY_TYPE.exec(line.text) ?? STEP_FIRST_WORD.exec(line.text);\n const type = other?.[2] ?? \"\";\n\n if (other && !STEP_TYPES.includes(type as StepType)) {\n sink.report(\n \"GR1009\",\n `the step kind ${JSON.stringify(type)} is not one of: ${STEP_TYPES.join(\", \")}.`,\n at,\n );\n } else {\n sink.report(\n \"GR1008\",\n `the step ${JSON.stringify(line.text)} is not \\`<n>. <kind> <name>\\`.`,\n at,\n );\n }\n\n continue;\n }\n\n const type = match[2] as StepType;\n let target = (match[3] ?? \"\").trim();\n let app: string | null = null;\n let route: WrittenStep[\"route\"] = null;\n let affects: WrittenStep[\"affects\"] = null;\n\n if (type === \"page\") {\n const scoped = PAGE_TARGET.exec(target);\n\n if (scoped) {\n target = scoped[1] ?? \"\";\n app = scoped[2] ?? null;\n }\n }\n\n if (type === \"route\") {\n const routeMatch = ROUTE_TARGET.exec(target);\n\n if (!routeMatch) {\n sink.report(\n \"GR1008\",\n `the route step ${JSON.stringify(target)} is not \\`<METHOD> /path\\`.`,\n at,\n );\n continue;\n }\n\n route = { method: (routeMatch[1] ?? \"\").toUpperCase(), path: routeMatch[2] ?? \"\" };\n }\n\n if (type === \"affects\") {\n const affectsMatch = AFFECTS_TARGET.exec(target);\n\n if (!affectsMatch) {\n sink.report(\n \"GR1008\",\n `the affects step ${JSON.stringify(target)} is not \\`<feature>\\` or \\`<feature>/<flow>\\`.`,\n at,\n );\n continue;\n }\n\n affects = { feature: affectsMatch[1] ?? \"\", flow: affectsMatch[2] ?? null };\n }\n\n steps.push({\n index: Number(match[1]),\n type,\n target,\n app,\n route,\n affects,\n note: match[4]?.trim() ?? null,\n at,\n });\n }\n\n const wrong = numbers.findIndex((entry, position) => entry.number !== position + 1);\n const first = numbers[wrong];\n\n if (first !== undefined) {\n sink.report(\n \"GR1010\",\n `step ${first.number} should be step ${wrong + 1}; number the steps 1, 2, 3 in order.`,\n lineAt(file, first.line),\n );\n }\n\n return steps;\n}\n\n/**\n * `## Story`: numbered sentences in the user's words. Indented lines continue\n * the item, image lines attach screenshots. GR1008 for any other line, GR1010\n * for numbers out of order.\n */\nfunction parseStory(\n file: string,\n document: WrittenDocument,\n sink: FindingSink,\n): WrittenStoryStep[] {\n const story: WrittenStoryStep[] = [];\n const numbers: { number: number; line: number }[] = [];\n let open: { step: WrittenStoryStep; text: string[] } | null = null;\n let continuing = false;\n\n const finish = (): void => {\n if (open !== null) open.step.text = open.text.join(\" \");\n\n open = null;\n };\n\n const attach = (line: BodyLine): void => {\n open?.step.screenshots.push(...readScreenshots(file, [line], sink));\n };\n\n for (const line of findSection(document, \"story\")?.lines ?? []) {\n const trimmed = line.text.trim();\n const at = lineAt(file, line.line);\n\n if (line.fenced) {\n continuing = false;\n continue;\n }\n\n if (trimmed === \"\") {\n continuing = false;\n continue;\n }\n\n const numbered = NUMBERED.exec(trimmed);\n\n if (numbered) {\n finish();\n\n const sentence = withoutImages(trimmed.replace(NUMBERED, \"\"));\n\n if (sentence === \"\") {\n sink.report(\n \"GR1008\",\n `the story line ${JSON.stringify(trimmed)} is not \\`<n>. <sentence>\\`.`,\n at,\n );\n continuing = false;\n continue;\n }\n\n const number = Number(numbered[1]);\n const step: WrittenStoryStep = { index: number, text: sentence, screenshots: [], at };\n\n numbers.push({ number, line: line.line });\n story.push(step);\n open = { step, text: [sentence] };\n continuing = true;\n attach(line);\n continue;\n }\n\n if (isImageLine(trimmed)) {\n if (open === null) {\n sink.report(\n \"GR1008\",\n `the story line ${JSON.stringify(trimmed)} is an image before any story step.`,\n at,\n );\n } else {\n attach(line);\n }\n\n continue;\n }\n\n if (open !== null && continuing && /^[ \\t]/.test(line.text)) {\n const more = withoutImages(trimmed);\n\n if (more !== \"\") open.text.push(more);\n\n attach(line);\n continue;\n }\n\n sink.report(\n \"GR1008\",\n `the story line ${JSON.stringify(trimmed)} is not \\`<n>. <sentence>\\`.`,\n at,\n );\n }\n\n finish();\n\n const wrong = numbers.findIndex((entry, position) => entry.number !== position + 1);\n const first = numbers[wrong];\n\n if (first !== undefined) {\n sink.report(\n \"GR1010\",\n `story step ${first.number} should be story step ${wrong + 1}; number the story steps 1, 2, 3 in order.`,\n lineAt(file, first.line),\n );\n }\n\n return story;\n}\n\nfunction parseCases(file: string, document: WrittenDocument, sink: FindingSink): WrittenCase[] {\n const cases: WrittenCase[] = [];\n\n for (const line of bulletLines(findSection(document, \"cases\")?.lines ?? [])) {\n const split = splitListLine(line.text, CASE_QUESTIONS);\n\n if (split === null) {\n sink.report(\n \"GR1011\",\n `the case ${JSON.stringify(line.text)} is not \\`- <question> <answer>\\`.`,\n lineAt(file, line.line),\n );\n continue;\n }\n\n const question = normalizeKey(split.name);\n const suffix = CRITERIA_SUFFIX.exec(split.text);\n const answer = suffix ? split.text.slice(0, suffix.index).trimEnd() : split.text;\n\n cases.push({\n question,\n fixed: (CASE_QUESTIONS as readonly string[]).includes(question),\n answer,\n doesNotApply: /^does not apply\\b/i.test(answer),\n criteria: suffix ? (suffix[1] ?? \"\").split(\",\").map((criterion) => criterion.trim()) : [],\n at: lineAt(file, line.line),\n });\n }\n\n return cases;\n}\n\nfunction parseCriteria(\n file: string,\n document: WrittenDocument,\n sink: FindingSink,\n): WrittenCriterion[] {\n const criteria: WrittenCriterion[] = [];\n const seen = new Set<number>();\n\n for (const line of bulletLines(findSection(document, \"acceptance criteria\")?.lines ?? [])) {\n const at = lineAt(file, line.line);\n const match = CRITERION.exec(line.text);\n\n if (!match) {\n sink.report(\n \"GR1013\",\n `the criterion ${JSON.stringify(line.text)} is not \\`- AC-<n> <text>\\` or \\`- AC-<n> [<app>] <text>\\`.`,\n at,\n );\n continue;\n }\n\n const number = Number(match[1]);\n\n if (seen.has(number)) {\n sink.report(\"GR1014\", `AC-${number} is used twice in this flow.`, at);\n continue;\n }\n\n seen.add(number);\n criteria.push({\n id: `AC-${number}`,\n number,\n app: match[2] ?? null,\n text: (match[3] ?? \"\").trim(),\n at,\n });\n }\n\n return criteria;\n}\n\n/** `grimoire/features/<feature>/flows/<name>.md`. */\nexport function parseFlow(\n file: string,\n text: string,\n feature: string,\n name: string,\n sink: FindingSink,\n): WrittenFlow {\n const document = readDocument(file, text, \"required\", sink);\n const fields = new FrontMatterReader(document, sink);\n\n fields.onlyKeys([\"id\", \"since\", \"status\", \"who\", \"origin\"], \"flow\");\n\n const id = fields.required(\"id\", checks.id);\n sameAsName(id, name, \"flow id\", sink);\n\n const flow: WrittenFlow = {\n file,\n feature,\n id,\n ref: `${feature}/${name}`,\n since: fields.required(\"since\", checks.version),\n status: fields.oneOf(\"status\", STATUSES, FALLBACK_STATUS),\n who: fields.required(\"who\", checks.text),\n origin: fields.optionalOneOf(\"origin\", ORIGINS),\n heading: heading(document),\n summary: paragraphAfterTitle(document),\n story: [],\n steps: [],\n differs: [],\n cases: [],\n notHandled: [],\n unknowns: [],\n criteria: [],\n };\n\n checkHeadings(\n document,\n {\n title: true,\n required: [\"Steps\", \"Cases\", \"Acceptance criteria\"],\n optional: [\"Story\", \"Differs by app\", \"Not handled\"],\n },\n sink,\n );\n\n if (flow.summary === null) {\n sink.report(\n \"GR1030\",\n \"the flow has no summary; write one or two sentences under the title.\",\n lineAt(file, document.title?.line ?? document.bodyStartLine),\n );\n }\n\n flow.story = parseStory(file, document, sink);\n flow.steps = parseSteps(file, document, sink);\n flow.differs = readListLines(\n file,\n findSection(document, \"differs by app\")?.lines,\n \"Differs by app\",\n sink,\n );\n flow.cases = parseCases(file, document, sink);\n flow.notHandled = readListLines(\n file,\n findSection(document, \"not handled\")?.lines,\n \"Not handled\",\n sink,\n CASE_QUESTIONS,\n );\n flow.criteria = parseCriteria(file, document, sink);\n\n for (const line of document.body) {\n const trimmed = line.text.trim();\n\n if (!line.fenced && trimmed.startsWith(\"Unknown:\")) {\n flow.unknowns.push({\n text: trimmed.slice(\"Unknown:\".length).trim(),\n at: lineAt(file, line.line),\n });\n }\n }\n\n const cases = findSection(document, \"cases\");\n\n if (cases !== null) {\n const answered = new Set([\n ...flow.cases.map((entry) => entry.question),\n ...flow.notHandled.map((entry) => normalizeKey(entry.name)),\n ]);\n\n for (const question of CASE_QUESTIONS) {\n if (!answered.has(question)) {\n sink.report(\n \"GR1012\",\n `the case question \"${question}\" is answered neither under Cases nor under Not handled.`,\n lineAt(file, cases.line),\n );\n }\n }\n }\n\n return flow;\n}\n\n// ── Version briefs ─────────────────────────────────────────────────────────\n\n/** `grimoire/features/<feature>/versions/v<n>.md`: free text under a title. */\nexport function parseVersionBrief(\n file: string,\n text: string,\n feature: string,\n major: number,\n sink: FindingSink,\n): WrittenVersionBrief {\n const document = readDocument(file, text, \"none\", sink);\n\n new FrontMatterReader(document, sink).onlyKeys([], \"a version brief\");\n\n return { file, feature, major, heading: heading(document) };\n}\n"],"mappings":";;;;;;AAwCA,MAAa,WAAqC;CAAC;CAAY;CAAY;CAAW;AAAS;AAC/F,MAAa,UAAoC,CAAC,YAAY,WAAW;AACzE,MAAa,eAAsC;CAAC;CAAS;CAAW;CAAS;AAAS;;AAE1F,MAAa,aAAkC;CAC7C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAM,kBAAiC;AAKvC,MAAM,OAAO,IAAI,OACf,OAAO,GAAG,kBAAkB,WAAW,KAAK,GAAG,EAAE,+CACnD;AACA,MAAM,gBAAgB,IAAI,OAAO,OAAO,GAAG,wBAAwB,IAAI,QAAQ;AAC/E,MAAM,kBAAkB;AACxB,MAAM,WAAW;AACjB,MAAM,cAAc;AACpB,MAAM,eAAe;AACrB,MAAM,iBAAiB;AACvB,MAAM,YAAY;AAClB,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;AACxB,MAAM,qBAAqB;AAC3B,MAAM,cAAc;AACpB,MAAM,kBAAkB;AACxB,MAAM,mBACJ;AAEF,SAAS,QAAQ,UAA4D;CAC3E,OAAO,SAAS,QACZ;EAAE,OAAO,SAAS,MAAM;EAAM,IAAI,OAAO,SAAS,MAAM,SAAS,MAAM,IAAI;CAAE,IAC7E;AACN;;AAGA,SAAS,WACP,SACA,MACA,MACA,MACM;CACN,IAAI,QAAQ,UAAU,MAAM,QAAQ,UAAU,MAC5C,KAAK,OACH,UACA,OAAO,KAAK,GAAG,KAAK,UAAU,QAAQ,KAAK,EAAE,kBAAkB,KAAK,UAAU,IAAI,EAAE,SACpF,QAAQ,EACV;AAEJ;;AAGA,SAAgB,eAAe,MAI7B;CACA,IAAI,OAAO,KAAK,KAAK;CACrB,IAAI,OAAsB;CAC1B,IAAI,WAAqB,CAAC;CAC1B,MAAM,SAAS,YAAY,KAAK,IAAI;CAEpC,IAA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