@warlock.js/grimoire 5.63.1 → 5.64.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/esm/book/build.d.mts.map +1 -1
  3. package/esm/book/build.mjs +24 -2
  4. package/esm/book/build.mjs.map +1 -1
  5. package/esm/check/check-grimoire.d.mts.map +1 -1
  6. package/esm/check/check-grimoire.mjs +11 -1
  7. package/esm/check/check-grimoire.mjs.map +1 -1
  8. package/esm/check/rules/api-snapshot.mjs +39 -0
  9. package/esm/check/rules/api-snapshot.mjs.map +1 -0
  10. package/esm/check/rules/code-rules.mjs +45 -0
  11. package/esm/check/rules/code-rules.mjs.map +1 -0
  12. package/esm/check/rules/drift.mjs +54 -0
  13. package/esm/check/rules/drift.mjs.map +1 -0
  14. package/esm/check/rules/focused-tests.mjs +39 -0
  15. package/esm/check/rules/focused-tests.mjs.map +1 -0
  16. package/esm/check/rules/shows.mjs +52 -0
  17. package/esm/check/rules/shows.mjs.map +1 -0
  18. package/esm/codes/codes.d.mts +48 -0
  19. package/esm/codes/codes.d.mts.map +1 -1
  20. package/esm/codes/codes.mjs +26 -1
  21. package/esm/codes/codes.mjs.map +1 -1
  22. package/esm/contracts/adapter.d.mts +6 -0
  23. package/esm/contracts/adapter.d.mts.map +1 -1
  24. package/esm/contracts/guard.d.mts +104 -0
  25. package/esm/contracts/guard.d.mts.map +1 -0
  26. package/esm/contracts/index.mjs +5 -0
  27. package/esm/contracts/matrix.d.mts +75 -0
  28. package/esm/contracts/matrix.d.mts.map +1 -0
  29. package/esm/contracts/scry.d.mts +21 -0
  30. package/esm/contracts/scry.d.mts.map +1 -1
  31. package/esm/contracts/settings.d.mts +71 -0
  32. package/esm/contracts/settings.d.mts.map +1 -0
  33. package/esm/contracts/settings.mjs +67 -0
  34. package/esm/contracts/settings.mjs.map +1 -0
  35. package/esm/contracts/shots.d.mts +146 -0
  36. package/esm/contracts/shots.d.mts.map +1 -0
  37. package/esm/contracts/snapshot.d.mts +10 -0
  38. package/esm/contracts/snapshot.d.mts.map +1 -1
  39. package/esm/contracts/written.d.mts +13 -0
  40. package/esm/contracts/written.d.mts.map +1 -1
  41. package/esm/contracts/written.mjs +7 -1
  42. package/esm/contracts/written.mjs.map +1 -1
  43. package/esm/devtools/approvals.mjs +59 -0
  44. package/esm/devtools/approvals.mjs.map +1 -0
  45. package/esm/devtools/data.mjs +2 -0
  46. package/esm/devtools/data.mjs.map +1 -1
  47. package/esm/devtools/graphs.mjs +13 -3
  48. package/esm/devtools/graphs.mjs.map +1 -1
  49. package/esm/devtools/index.d.mts.map +1 -1
  50. package/esm/devtools/index.mjs +32 -2
  51. package/esm/devtools/index.mjs.map +1 -1
  52. package/esm/devtools/matrix.mjs +207 -0
  53. package/esm/devtools/matrix.mjs.map +1 -0
  54. package/esm/devtools/product-map.d.mts.map +1 -1
  55. package/esm/devtools/product-map.mjs +87 -1
  56. package/esm/devtools/product-map.mjs.map +1 -1
  57. package/esm/devtools/site.d.mts.map +1 -1
  58. package/esm/devtools/site.mjs +12 -3
  59. package/esm/devtools/site.mjs.map +1 -1
  60. package/esm/devtools/snapshot-source.mjs +5 -1
  61. package/esm/devtools/snapshot-source.mjs.map +1 -1
  62. package/esm/git/index.d.mts +20 -0
  63. package/esm/git/index.d.mts.map +1 -0
  64. package/esm/git/index.mjs +280 -0
  65. package/esm/git/index.mjs.map +1 -0
  66. package/esm/guard/api.mjs +70 -0
  67. package/esm/guard/api.mjs.map +1 -0
  68. package/esm/guard/assertions.mjs +18 -0
  69. package/esm/guard/assertions.mjs.map +1 -0
  70. package/esm/guard/collect.mjs +139 -0
  71. package/esm/guard/collect.mjs.map +1 -0
  72. package/esm/guard/format.mjs +27 -0
  73. package/esm/guard/format.mjs.map +1 -0
  74. package/esm/guard/glob.mjs +79 -0
  75. package/esm/guard/glob.mjs.map +1 -0
  76. package/esm/guard/index.mjs +9 -0
  77. package/esm/guard/rules.mjs +310 -0
  78. package/esm/guard/rules.mjs.map +1 -0
  79. package/esm/guard/scope.mjs +95 -0
  80. package/esm/guard/scope.mjs.map +1 -0
  81. package/esm/index.d.mts +10 -3
  82. package/esm/index.mjs +6 -2
  83. package/esm/paths/index.d.mts +15 -1
  84. package/esm/paths/index.d.mts.map +1 -1
  85. package/esm/paths/index.mjs +27 -3
  86. package/esm/paths/index.mjs.map +1 -1
  87. package/esm/proves/index.mjs +2 -1
  88. package/esm/proves/scan-proofs.mjs +1 -1
  89. package/esm/proves/scan-proofs.mjs.map +1 -1
  90. package/esm/proves/scan-shows.d.mts +21 -0
  91. package/esm/proves/scan-shows.d.mts.map +1 -0
  92. package/esm/proves/scan-shows.mjs +168 -0
  93. package/esm/proves/scan-shows.mjs.map +1 -0
  94. package/esm/releases/index.d.mts.map +1 -1
  95. package/esm/releases/index.mjs +5 -3
  96. package/esm/releases/index.mjs.map +1 -1
  97. package/esm/releases/stamp.mjs +121 -0
  98. package/esm/releases/stamp.mjs.map +1 -0
  99. package/esm/rules/focused.mjs +26 -0
  100. package/esm/rules/focused.mjs.map +1 -0
  101. package/esm/rules/index.mjs +88 -0
  102. package/esm/rules/index.mjs.map +1 -0
  103. package/esm/rules/logical-css.mjs +112 -0
  104. package/esm/rules/logical-css.mjs.map +1 -0
  105. package/esm/rules/no-js-imports.mjs +22 -0
  106. package/esm/rules/no-js-imports.mjs.map +1 -0
  107. package/esm/rules/scan.mjs +196 -0
  108. package/esm/rules/scan.mjs.map +1 -0
  109. package/esm/rules/specific-errors.mjs +51 -0
  110. package/esm/rules/specific-errors.mjs.map +1 -0
  111. package/esm/rules/type-discriminator.mjs +27 -0
  112. package/esm/rules/type-discriminator.mjs.map +1 -0
  113. package/esm/scry/also-changes.mjs +106 -0
  114. package/esm/scry/also-changes.mjs.map +1 -0
  115. package/esm/scry/format.d.mts.map +1 -1
  116. package/esm/scry/format.mjs +22 -0
  117. package/esm/scry/format.mjs.map +1 -1
  118. package/esm/scry/query.d.mts.map +1 -1
  119. package/esm/scry/query.mjs +7 -2
  120. package/esm/scry/query.mjs.map +1 -1
  121. package/esm/scry/search.d.mts.map +1 -1
  122. package/esm/scry/search.mjs +43 -11
  123. package/esm/scry/search.mjs.map +1 -1
  124. package/esm/shots/approve.mjs +195 -0
  125. package/esm/shots/approve.mjs.map +1 -0
  126. package/esm/shots/drift.mjs +174 -0
  127. package/esm/shots/drift.mjs.map +1 -0
  128. package/esm/shots/png.mjs +166 -0
  129. package/esm/shots/png.mjs.map +1 -0
  130. package/esm/shots/state.mjs +43 -0
  131. package/esm/shots/state.mjs.map +1 -0
  132. package/esm/shots/store.mjs +66 -0
  133. package/esm/shots/store.mjs.map +1 -0
  134. package/esm/shots/touched.mjs +38 -0
  135. package/esm/shots/touched.mjs.map +1 -0
  136. package/esm/warlock/adapter.d.mts.map +1 -1
  137. package/esm/warlock/adapter.mjs +15 -2
  138. package/esm/warlock/adapter.mjs.map +1 -1
  139. package/esm/warlock/api-command.mjs +41 -0
  140. package/esm/warlock/api-command.mjs.map +1 -0
  141. package/esm/warlock/approve-command.mjs +80 -0
  142. package/esm/warlock/approve-command.mjs.map +1 -0
  143. package/esm/warlock/commands.d.mts +1 -1
  144. package/esm/warlock/commands.d.mts.map +1 -1
  145. package/esm/warlock/commands.mjs +61 -8
  146. package/esm/warlock/commands.mjs.map +1 -1
  147. package/esm/warlock/guard-command.mjs +116 -0
  148. package/esm/warlock/guard-command.mjs.map +1 -0
  149. package/esm/warlock/index.d.mts +2 -1
  150. package/esm/warlock/index.mjs +2 -1
  151. package/esm/warlock/languages.mjs +75 -0
  152. package/esm/warlock/languages.mjs.map +1 -0
  153. package/esm/warlock/mcp-tools.mjs +2 -2
  154. package/esm/warlock/mcp-tools.mjs.map +1 -1
  155. package/esm/warlock/release-command.mjs +65 -0
  156. package/esm/warlock/release-command.mjs.map +1 -0
  157. package/esm/warlock/shows.d.mts +35 -0
  158. package/esm/warlock/shows.d.mts.map +1 -0
  159. package/esm/warlock/shows.mjs +195 -0
  160. package/esm/warlock/shows.mjs.map +1 -0
  161. package/esm/workspace/cache.mjs +4 -1
  162. package/esm/workspace/cache.mjs.map +1 -1
  163. package/esm/workspace/derived.mjs +11 -6
  164. package/esm/workspace/derived.mjs.map +1 -1
  165. package/esm/workspace/index.d.mts.map +1 -1
  166. package/esm/workspace/index.mjs +8 -1
  167. package/esm/workspace/index.mjs.map +1 -1
  168. package/esm/workspace/stored.mjs +4 -1
  169. package/esm/workspace/stored.mjs.map +1 -1
  170. package/esm/written/features.mjs +21 -5
  171. package/esm/written/features.mjs.map +1 -1
  172. package/esm/written/index.mjs +2 -1
  173. package/esm/written/parse-grimoire.d.mts.map +1 -1
  174. package/esm/written/parse-grimoire.mjs +16 -3
  175. package/esm/written/parse-grimoire.mjs.map +1 -1
  176. package/esm/written/settings.d.mts +11 -0
  177. package/esm/written/settings.d.mts.map +1 -0
  178. package/esm/written/settings.mjs +88 -0
  179. package/esm/written/settings.mjs.map +1 -0
  180. package/llms-full.txt +276 -39
  181. package/llms.txt +2 -0
  182. package/package.json +3 -3
  183. package/skills/backfill-a-grimoire/SKILL.md +4 -0
  184. package/skills/describe-an-app/SKILL.md +4 -1
  185. package/skills/guard-a-change/SKILL.md +85 -0
  186. package/skills/index.md +7 -3
  187. package/skills/record-a-change/SKILL.md +52 -16
  188. package/skills/review-a-change/SKILL.md +53 -0
  189. package/skills/use-the-grimoire/SKILL.md +21 -18
  190. package/skills/write-a-feature/SKILL.md +42 -1
  191. package/ui/grimoire-view.js +756 -40
  192. package/ui/grimoire.css +303 -28
  193. package/ui/product-map.css +43 -7
  194. package/ui/product-map.js +212 -37
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/guard/rules.ts"],"sourcesContent":["/**\n * The guard's rules: a pure function over a {@link GuardInput}. No git and\n * no file is read here, so every rule is tested with plain data.\n */\nimport { createFinding } from \"../codes\";\nimport type { GrimoireFinding } from \"../contracts/findings\";\nimport type { GuardInput, TaskScope } from \"../contracts/guard\";\nimport { CODE_RULES } from \"../contracts/settings\";\nimport { scanProofsInText } from \"../proves\";\nimport { findFocusedTests } from \"../rules/focused\";\nimport { runCodeRules } from \"../rules\";\nimport { countAssertions } from \"./assertions\";\nimport { describeRouteDiff, diffRoutes } from \"./api\";\nimport { matchesAny } from \"./glob\";\nimport { scopeFeatures, scopeFlows } from \"./scope\";\n\nconst TEST_FILE = /(?:\\.(?:test|spec|e2e)\\.[cm]?[jt]sx?$|(?:^|\\/)(?:tests?|e2e|__tests__)\\/)/;\nconst DEPENDENCY_SECTIONS = [\n \"dependencies\",\n \"devDependencies\",\n \"peerDependencies\",\n \"optionalDependencies\",\n];\n\n/** Whether a path is a test file by name or folder. */\nexport function isTestPath(file: string): boolean {\n return TEST_FILE.test(file);\n}\n\nfunction at(file: string, line: number | null): { file: string; line: number; column: null } {\n return { file, line: line ?? 1, column: null };\n}\n\n/** The paths of a change: each file, and the old path of a rename. */\nfunction pathsOf(input: GuardInput): string[] {\n return input.changed.flatMap((change) =>\n change.from === null ? [change.file] : [change.file, change.from],\n );\n}\n\n/** Whether `removes` names this feature, flow, criterion or case (a wider entry covers what is inside it). */\nfunction isRemoved(\n scope: TaskScope,\n feature: string,\n flow?: string,\n criterion?: string,\n caseQuestion?: string,\n): boolean {\n return scope.removes.some((entry) => {\n if (entry.feature !== feature) return false;\n\n if (entry.flow === null) return true;\n\n if (flow === undefined || entry.flow !== flow) return false;\n\n if (entry.criterion === null && entry.case === null) return true;\n\n return (\n (criterion !== undefined && entry.criterion === criterion.toUpperCase()) ||\n (caseQuestion !== undefined && entry.case === caseQuestion.toLowerCase())\n );\n });\n}\n\n/** The files a task allows (everything else that changes is GR7006). */\nfunction allowedFiles(input: GuardInput, scope: TaskScope): Set<string> {\n const allowed = new Set<string>([scope.file]);\n const features = scopeFeatures(scope);\n const flows = scopeFlows(scope);\n\n for (const feature of features) {\n for (const file of input.ownership.features[feature]?.own ?? []) allowed.add(file);\n }\n\n for (const [file, owner] of Object.entries(input.ownership.files)) {\n if (owner.owner !== null && features.includes(owner.owner)) allowed.add(file);\n }\n\n for (const ref of flows) {\n for (const file of input.flowFiles[ref] ?? []) allowed.add(file);\n }\n\n // Tests that prove the task's criteria: those of its flows, or of its features when it names no flow.\n for (const proof of input.proofs) {\n if (flows.length > 0 ? flows.includes(proof.ref) : features.includes(proof.feature)) {\n allowed.add(proof.at.file);\n }\n }\n\n // A deleted or rewritten test proved the task's criteria at the base.\n for (const [file, text] of Object.entries(input.texts)) {\n if (text.base === null || !text.base.includes(\"@proves\")) continue;\n\n for (const proof of scanProofsInText(text.base, file).proofs) {\n if (flows.length > 0 ? flows.includes(proof.ref) : features.includes(proof.feature))\n allowed.add(file);\n }\n }\n\n return allowed;\n}\n\nfunction inScope(file: string, scope: TaskScope, allowed: ReadonlySet<string>): boolean {\n return (\n allowed.has(file) ||\n file.startsWith(\"grimoire/tasks/\") ||\n file.startsWith(\"grimoire/releases/\") ||\n // Written only by approve and reject, which the guard reports on its own (the changes not approved).\n file.startsWith(\"grimoire/approved/\") ||\n file.startsWith(\"grimoire/screenshots/approved/\") ||\n scopeFeatures(scope).some((feature) => file.startsWith(`grimoire/features/${feature}/`)) ||\n matchesAny(file, scope.files)\n );\n}\n\nfunction scopeFindings(input: GuardInput, scope: TaskScope): GrimoireFinding[] {\n const allowed = allowedFiles(input, scope);\n const findings: GrimoireFinding[] = [];\n\n for (const change of input.changed) {\n // A change is in scope when both sides of a rename are.\n const outside = [change.file, ...(change.from === null ? [] : [change.from])].filter(\n (file) => !inScope(file, scope, allowed),\n );\n\n if (outside.length === 0) continue;\n\n findings.push(\n createFinding({\n code: \"GR7006\",\n message: `${change.status} ${JSON.stringify(outside[0])} is outside ${scope.id}${scope.feature === null ? \"\" : ` (${scope.flow ?? scope.feature})`}`,\n at: at(change.file, null),\n task: scope.id,\n }),\n );\n }\n\n return findings;\n}\n\nfunction removalFindings(input: GuardInput, scope: TaskScope): GrimoireFinding[] {\n const base = input.baseWritten;\n const findings: GrimoireFinding[] = [];\n\n if (base === null) return findings;\n\n const report = (\n message: string,\n file: string,\n line: number,\n feature: string,\n flow: string | null,\n ): void => {\n findings.push(\n createFinding({ code: \"GR7007\", message, at: at(file, line), task: scope.id, feature, flow }),\n );\n };\n\n for (const feature of base.features) {\n const current = input.written.features.find((item) => item.id === feature.id);\n\n if (current === undefined) {\n if (!isRemoved(scope, feature.id)) {\n report(\n `the change removes the feature ${JSON.stringify(feature.id)} (${feature.flows.length} flows)`,\n feature.readme?.file ?? `grimoire/features/${feature.id}/README.md`,\n 1,\n feature.id,\n null,\n );\n }\n\n continue;\n }\n\n for (const flow of feature.flows) {\n const next = current.flows.find((item) => item.id.value === flow.id.value);\n\n if (next === undefined) {\n if (!isRemoved(scope, feature.id, flow.id.value)) {\n report(\n `the change removes the flow ${JSON.stringify(flow.ref)}`,\n flow.file,\n 1,\n feature.id,\n flow.ref,\n );\n }\n\n continue;\n }\n\n for (const criterion of flow.criteria) {\n if (next.criteria.some((item) => item.id === criterion.id)) continue;\n\n if (!isRemoved(scope, feature.id, flow.id.value, criterion.id)) {\n report(\n `the change removes ${criterion.id} of ${flow.ref}: ${JSON.stringify(criterion.text)}`,\n next.file,\n 1,\n feature.id,\n flow.ref,\n );\n }\n }\n\n for (const item of flow.cases) {\n if (next.cases.some((other) => other.question === item.question)) continue;\n\n if (!isRemoved(scope, feature.id, flow.id.value, undefined, item.question)) {\n report(\n `the change removes the case ${JSON.stringify(item.question)} of ${flow.ref}`,\n next.file,\n 1,\n feature.id,\n flow.ref,\n );\n }\n }\n }\n }\n\n return findings;\n}\n\nfunction proofFindings(input: GuardInput, scope: TaskScope): GrimoireFinding[] {\n const touched = new Set(pathsOf(input));\n const current = new Set<string>();\n const findings: GrimoireFinding[] = [];\n\n for (const proof of input.proofs) {\n if (!touched.has(proof.at.file)) current.add(`${proof.ref} ${proof.criterion}`);\n }\n\n for (const [file, text] of Object.entries(input.texts)) {\n if (text.current === null) continue;\n\n for (const proof of scanProofsInText(text.current, file).proofs) {\n current.add(`${proof.ref} ${proof.criterion}`);\n }\n }\n\n const reported = new Set<string>();\n\n for (const [file, text] of Object.entries(input.texts)) {\n if (text.base === null || !text.base.includes(\"@proves\")) continue;\n\n for (const proof of scanProofsInText(text.base, file).proofs) {\n const key = `${proof.ref} ${proof.criterion}`;\n\n if (current.has(key) || reported.has(key)) continue;\n\n if (isRemoved(scope, proof.feature, proof.flow, proof.criterion)) continue;\n\n reported.add(key);\n findings.push(\n createFinding({\n code: \"GR7008\",\n message: `no test proves ${proof.criterion} of ${proof.ref} any more${proof.test?.name ? ` (was ${JSON.stringify(proof.test.name)})` : \"\"}`,\n at: at(file, proof.at.line),\n task: scope.id,\n feature: proof.feature,\n flow: proof.ref,\n }),\n );\n }\n }\n\n return findings;\n}\n\nfunction lockedFindings(input: GuardInput, scope: TaskScope): GrimoireFinding[] {\n if (scope.locked.length === 0) return [];\n\n return input.changed.flatMap((change) => {\n const locked = [change.file, ...(change.from === null ? [] : [change.from])].find((file) =>\n matchesAny(file, scope.locked),\n );\n\n return locked === undefined\n ? []\n : [\n createFinding({\n code: \"GR7009\",\n message: `${JSON.stringify(locked)} is a locked test of ${scope.id} and was ${change.status}`,\n at: at(change.file, null),\n task: scope.id,\n }),\n ];\n });\n}\n\nfunction assertionFindings(input: GuardInput, scope: TaskScope | null): GrimoireFinding[] {\n const tests = new Set(input.testFiles);\n const findings: GrimoireFinding[] = [];\n\n for (const [file, text] of Object.entries(input.texts)) {\n if (text.base === null || text.current === null || !(tests.has(file) || isTestPath(file)))\n continue;\n\n const before = countAssertions(text.base);\n const after = countAssertions(text.current);\n\n if (after < before) {\n findings.push(\n createFinding({\n code: \"GR7010\",\n message: `the test file has ${after} assertions, it had ${before}`,\n at: at(file, null),\n task: scope?.id ?? null,\n }),\n );\n }\n }\n\n return findings;\n}\n\nfunction dependencyChanges(before: string | null, after: string | null): string[] {\n if (after === null) return [];\n\n let next: Record<string, unknown>;\n let previous: Record<string, unknown> = {};\n\n try {\n next = JSON.parse(after) as Record<string, unknown>;\n\n if (before !== null) previous = JSON.parse(before) as Record<string, unknown>;\n } catch {\n return [];\n }\n\n const changes: string[] = [];\n\n for (const section of DEPENDENCY_SECTIONS) {\n const now = next[section];\n const was = previous[section];\n\n if (typeof now !== \"object\" || now === null) continue;\n\n for (const [name, version] of Object.entries(now as Record<string, unknown>)) {\n const old =\n typeof was === \"object\" && was !== null\n ? (was as Record<string, unknown>)[name]\n : undefined;\n\n if (old !== version) changes.push(`${name}@${String(version)}`);\n }\n }\n\n return changes;\n}\n\nfunction protectedFindings(input: GuardInput, scope: TaskScope): GrimoireFinding[] {\n const findings: GrimoireFinding[] = [];\n\n for (const area of input.settings.protected) {\n const name = area.name.toLowerCase();\n\n if (scope.touches.includes(name)) continue;\n\n if (name === \"public-api\") {\n const { approved, routes } = input.api;\n\n if (approved === null || routes === null) continue;\n\n const diff = diffRoutes(approved.routes, routes);\n\n if (diff.added.length + diff.removed.length > 0) {\n findings.push(\n createFinding({\n code: \"GR7011\",\n message: `the public API changed (${describeRouteDiff(diff)}) and ${scope.id} does not name public-api in Touches`,\n at: at(\"grimoire/approved/api.json\", null),\n task: scope.id,\n }),\n );\n }\n\n continue;\n }\n\n for (const change of input.changed) {\n const file = [change.file, change.from ?? \"\"].find(\n (candidate) => candidate !== \"\" && matchesAny(candidate, area.globs),\n );\n\n if (file === undefined) continue;\n\n if (name === \"dependencies\") {\n const text = input.texts[change.file];\n const added = dependencyChanges(text?.base ?? null, text?.current ?? null);\n\n if (added.length === 0) continue;\n\n findings.push(\n createFinding({\n code: \"GR7011\",\n message: `${JSON.stringify(file)} adds or changes ${added.slice(0, 5).join(\", \")}${added.length > 5 ? ` and ${added.length - 5} more` : \"\"}, and ${scope.id} does not name dependencies in Touches`,\n at: at(change.file, null),\n task: scope.id,\n }),\n );\n continue;\n }\n\n findings.push(\n createFinding({\n code: \"GR7011\",\n message: `${JSON.stringify(file)} is in the protected area ${JSON.stringify(area.name)} and ${scope.id} does not name it in Touches`,\n at: at(change.file, null),\n task: scope.id,\n }),\n );\n }\n }\n\n return findings;\n}\n\nfunction addedLineFindings(input: GuardInput, scope: TaskScope | null): GrimoireFinding[] {\n const findings: GrimoireFinding[] = [];\n const rules = input.settings.rules ?? CODE_RULES;\n const tests = new Set(input.testFiles);\n\n for (const change of input.changed) {\n const text = input.texts[change.file]?.current;\n\n if (change.status === \"deleted\" || text === undefined || text === null) continue;\n\n const added = new Set(change.addedLines);\n\n if (rules.length > 0) {\n for (const hit of runCodeRules(change.file, text, rules)) {\n if (!added.has(hit.line)) continue;\n\n findings.push(\n createFinding({\n code: hit.code,\n message: hit.message,\n at: { file: change.file, line: hit.line, column: hit.column },\n task: scope?.id ?? null,\n }),\n );\n }\n }\n\n if (tests.has(change.file) || isTestPath(change.file)) {\n for (const hit of findFocusedTests(text)) {\n if (!added.has(hit.line)) continue;\n\n findings.push(\n createFinding({\n code: hit.type === \"only\" ? \"GR4011\" : \"GR4012\",\n // `.skip` is a warning in a check; a change that adds one is an error.\n severity: \"error\",\n message: `${hit.call} was added`,\n at: { file: change.file, line: hit.line, column: null },\n task: scope?.id ?? null,\n }),\n );\n }\n }\n }\n\n return findings;\n}\n\nfunction commitFindings(input: GuardInput): GrimoireFinding[] {\n if (input.commits === null) return [];\n\n const known = new Set(input.taskIds.map((id) => Number(id.replace(/\\D/g, \"\"))));\n const findings: GrimoireFinding[] = [];\n\n for (const commit of input.commits) {\n if (/^Merge (?:pull request|branch|remote-tracking branch)\\b/.test(commit.subject)) continue;\n\n const ids = [\n ...new Set(\n [...`${commit.subject}\\n${commit.body}`.matchAll(/\\bT-(\\d+)\\b/g)].map((match) =>\n Number(match[1]),\n ),\n ),\n ];\n const label = `commit ${commit.sha.slice(0, 7)} ${JSON.stringify(commit.subject)}`;\n\n if (ids.length === 0) {\n findings.push(createFinding({ code: \"GR7012\", message: `${label} names no task` }));\n } else if (!ids.some((id) => known.has(id))) {\n findings.push(\n createFinding({\n code: \"GR7012\",\n message: `${label} names ${ids.map((id) => `T-${id}`).join(\", \")}, which has no task file`,\n }),\n );\n }\n }\n\n return findings;\n}\n\n/** Every finding of the guard for a change. Pure. */\nexport function runGuardChecks(input: GuardInput): GrimoireFinding[] {\n const { scope } = input;\n const findings: GrimoireFinding[] = [];\n\n if (scope === null) {\n findings.push(\n createFinding({\n code: \"GR9008\",\n message:\n \"no task was found: none was passed, the commits name none, and not exactly one task is in progress\",\n }),\n );\n } else {\n findings.push(\n ...scopeFindings(input, scope),\n ...removalFindings(input, scope),\n ...proofFindings(input, scope),\n ...lockedFindings(input, scope),\n ...protectedFindings(input, scope),\n );\n }\n\n findings.push(\n ...assertionFindings(input, scope),\n ...addedLineFindings(input, scope),\n ...commitFindings(input),\n );\n\n return findings;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,MAAM,YAAY;AAClB,MAAM,sBAAsB;CAC1B;CACA;CACA;CACA;AACF;;AAGA,SAAgB,WAAW,MAAuB;CAChD,OAAO,UAAU,KAAK,IAAI;AAC5B;AAEA,SAAS,GAAG,MAAc,MAAmE;CAC3F,OAAO;EAAE;EAAM,MAAM,QAAQ;EAAG,QAAQ;CAAK;AAC/C;;AAGA,SAAS,QAAQ,OAA6B;CAC5C,OAAO,MAAM,QAAQ,SAAS,WAC5B,OAAO,SAAS,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,MAAM,OAAO,IAAI,CAClE;AACF;;AAGA,SAAS,UACP,OACA,SACA,MACA,WACA,cACS;CACT,OAAO,MAAM,QAAQ,MAAM,UAAU;EACnC,IAAI,MAAM,YAAY,SAAS,OAAO;EAEtC,IAAI,MAAM,SAAS,MAAM,OAAO;EAEhC,IAAI,SAAS,UAAa,MAAM,SAAS,MAAM,OAAO;EAEtD,IAAI,MAAM,cAAc,QAAQ,MAAM,SAAS,MAAM,OAAO;EAE5D,OACG,cAAc,UAAa,MAAM,cAAc,UAAU,YAAY,KACrE,iBAAiB,UAAa,MAA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GAC7B,GAAG,gBAAgB,OAAO,KAAK,GAC/B,GAAG,cAAc,OAAO,KAAK,GAC7B,GAAG,eAAe,OAAO,KAAK,GAC9B,GAAG,kBAAkB,OAAO,KAAK,CACnC;CAGF,SAAS,KACP,GAAG,kBAAkB,OAAO,KAAK,GACjC,GAAG,kBAAkB,OAAO,KAAK,GACjC,GAAG,eAAe,KAAK,CACzB;CAEA,OAAO;AACT"}
@@ -0,0 +1,95 @@
1
+ import { splitList } from "./glob.mjs";
2
+
3
+ //#region ../../packages/grimoire/src/guard/scope.ts
4
+ const keyOf = (key) => key.trim().replace(/\s+/g, " ").toLowerCase();
5
+ /** The numeric part of a task id (`T-12`, `12`, `T-012`), or `null`. */
6
+ function taskNumber(text) {
7
+ const match = /^(?:T-)?0*(\d+)$/i.exec(text.trim());
8
+ return match ? Number(match[1]) : null;
9
+ }
10
+ /** The task files that match `text` by number (`T-12`, `12`, `T-012`). */
11
+ function findTask(written, text) {
12
+ const wanted = taskNumber(text);
13
+ if (wanted === null) return null;
14
+ return written.tasks.find((task) => taskNumber(task.id.value) === wanted) ?? null;
15
+ }
16
+ /** One `Removes:` entry. Entries that do not read as `<feature>[/<flow>[ AC-n | case <question>]]` are kept as a feature name. */
17
+ function parseRemoveEntry(text) {
18
+ const match = /^([a-z0-9][a-z0-9-]*)(?:\/([a-z0-9][a-z0-9-]*))?(?:\s+(?:(AC-\d+)|case\s+(.+)))?$/i.exec(text.trim());
19
+ if (!match) return {
20
+ feature: text.trim(),
21
+ flow: null,
22
+ criterion: null,
23
+ case: null,
24
+ text: text.trim()
25
+ };
26
+ return {
27
+ feature: (match[1] ?? "").toLowerCase(),
28
+ flow: match[2] === void 0 ? null : match[2].toLowerCase(),
29
+ criterion: match[3] === void 0 ? null : match[3].toUpperCase(),
30
+ case: match[4] === void 0 ? null : match[4].trim().toLowerCase(),
31
+ text: text.trim()
32
+ };
33
+ }
34
+ function fieldValues(task, name) {
35
+ return task.fields.filter((field) => keyOf(field.key) === name).flatMap((field) => splitList(field.value));
36
+ }
37
+ /** The flow ref a task names: `flow` is a flow id of `feature`, or a full `<feature>/<flow>`. */
38
+ function flowRefOf(task) {
39
+ const value = task.flow?.value;
40
+ if (value === void 0) return null;
41
+ if (value.includes("/")) return value;
42
+ return task.feature ? `${task.feature.value}/${value}` : null;
43
+ }
44
+ /** What one task allows. */
45
+ function readTaskScope(task) {
46
+ const feature = task.feature?.value ?? null;
47
+ const flow = flowRefOf(task);
48
+ const features = /* @__PURE__ */ new Set();
49
+ if (feature !== null) features.add(feature);
50
+ else if (flow !== null) features.add(flow.split("/")[0] ?? "");
51
+ for (const entry of fieldValues(task, "features")) features.add(entry);
52
+ return {
53
+ id: task.id.value,
54
+ file: task.file,
55
+ feature: feature ?? (flow === null ? null : flow.split("/")[0] ?? null),
56
+ flow,
57
+ features: [...features],
58
+ files: fieldValues(task, "files"),
59
+ locked: fieldValues(task, "locked"),
60
+ touches: fieldValues(task, "touches").map((name) => name.toLowerCase()),
61
+ removes: fieldValues(task, "removes").map(parseRemoveEntry)
62
+ };
63
+ }
64
+ /** Several tasks as one scope (the union of what each allows). */
65
+ function mergeScopes(scopes) {
66
+ const [first, ...rest] = scopes;
67
+ if (first === void 0) return null;
68
+ if (rest.length === 0) return first;
69
+ const union = (pick) => [...new Set(scopes.flatMap(pick))];
70
+ return {
71
+ id: scopes.map((scope) => scope.id).join(", "),
72
+ file: first.file,
73
+ feature: first.feature,
74
+ flow: first.flow,
75
+ features: union((scope) => scope.features),
76
+ files: union((scope) => [...scope.files, scope.file]),
77
+ locked: union((scope) => scope.locked),
78
+ touches: union((scope) => scope.touches),
79
+ removes: scopes.flatMap((scope) => scope.removes)
80
+ };
81
+ }
82
+ /** The flow refs of a scope: its own flow and every `Features:` entry written as `<feature>/<flow>`. */
83
+ function scopeFlows(scope) {
84
+ const flows = scope.features.filter((entry) => entry.includes("/"));
85
+ if (scope.flow !== null) flows.push(scope.flow);
86
+ return [...new Set(flows)];
87
+ }
88
+ /** The feature ids of a scope (a `<feature>/<flow>` entry gives its feature). */
89
+ function scopeFeatures(scope) {
90
+ return [...new Set(scope.features.map((entry) => entry.split("/")[0] ?? entry))];
91
+ }
92
+
93
+ //#endregion
94
+ export { findTask, mergeScopes, parseRemoveEntry, readTaskScope, scopeFeatures, scopeFlows, taskNumber };
95
+ //# sourceMappingURL=scope.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/guard/scope.ts"],"sourcesContent":["/**\n * Reading a task for the guard: which features, files, locked tests,\n * protected areas and removals its body allows.\n *\n * ```md\n * - Files: src/app/shared/utils/money.ts, src/config/catalog.ts\n * - Features: orders, catalog/wishlist\n * - Locked: src/app/catalog/tests/new-arrivals.test.ts\n * - Touches: migrations, dependencies\n * - Removes: catalog/new-arrivals AC-3, catalog/wishlist case duplicate\n * ```\n */\nimport type { RemoveEntry, TaskScope } from \"../contracts/guard\";\nimport type { WrittenGrimoire, WrittenTask } from \"../contracts/written\";\nimport { splitList } from \"./glob\";\n\nconst keyOf = (key: string): string => key.trim().replace(/\\s+/g, \" \").toLowerCase();\n\n/** The numeric part of a task id (`T-12`, `12`, `T-012`), or `null`. */\nexport function taskNumber(text: string): number | null {\n const match = /^(?:T-)?0*(\\d+)$/i.exec(text.trim());\n\n return match ? Number(match[1]) : null;\n}\n\n/** The task files that match `text` by number (`T-12`, `12`, `T-012`). */\nexport function findTask(written: WrittenGrimoire, text: string): WrittenTask | null {\n const wanted = taskNumber(text);\n\n if (wanted === null) return null;\n\n return written.tasks.find((task) => taskNumber(task.id.value) === wanted) ?? null;\n}\n\n/** One `Removes:` entry. Entries that do not read as `<feature>[/<flow>[ AC-n | case <question>]]` are kept as a feature name. */\nexport function parseRemoveEntry(text: string): RemoveEntry {\n const match =\n /^([a-z0-9][a-z0-9-]*)(?:\\/([a-z0-9][a-z0-9-]*))?(?:\\s+(?:(AC-\\d+)|case\\s+(.+)))?$/i.exec(\n text.trim(),\n );\n\n if (!match)\n return { feature: text.trim(), flow: null, criterion: null, case: null, text: text.trim() };\n\n return {\n feature: (match[1] ?? \"\").toLowerCase(),\n flow: match[2] === undefined ? null : match[2].toLowerCase(),\n criterion: match[3] === undefined ? null : match[3].toUpperCase(),\n case: match[4] === undefined ? null : match[4].trim().toLowerCase(),\n text: text.trim(),\n };\n}\n\nfunction fieldValues(task: WrittenTask, name: string): string[] {\n return task.fields\n .filter((field) => keyOf(field.key) === name)\n .flatMap((field) => splitList(field.value));\n}\n\n/** The flow ref a task names: `flow` is a flow id of `feature`, or a full `<feature>/<flow>`. */\nfunction flowRefOf(task: WrittenTask): string | null {\n const value = task.flow?.value;\n\n if (value === undefined) return null;\n\n if (value.includes(\"/\")) return value;\n\n return task.feature ? `${task.feature.value}/${value}` : null;\n}\n\n/** What one task allows. */\nexport function readTaskScope(task: WrittenTask): TaskScope {\n const feature = task.feature?.value ?? null;\n const flow = flowRefOf(task);\n const features = new Set<string>();\n\n if (feature !== null) features.add(feature);\n else if (flow !== null) features.add(flow.split(\"/\")[0] ?? \"\");\n\n for (const entry of fieldValues(task, \"features\")) features.add(entry);\n\n return {\n id: task.id.value,\n file: task.file,\n feature: feature ?? (flow === null ? null : (flow.split(\"/\")[0] ?? null)),\n flow,\n features: [...features],\n files: fieldValues(task, \"files\"),\n locked: fieldValues(task, \"locked\"),\n touches: fieldValues(task, \"touches\").map((name) => name.toLowerCase()),\n removes: fieldValues(task, \"removes\").map(parseRemoveEntry),\n };\n}\n\n/** Several tasks as one scope (the union of what each allows). */\nexport function mergeScopes(scopes: readonly TaskScope[]): TaskScope | null {\n const [first, ...rest] = scopes;\n\n if (first === undefined) return null;\n\n if (rest.length === 0) return first;\n\n const union = <T>(pick: (scope: TaskScope) => T[]): T[] => [...new Set(scopes.flatMap(pick))];\n\n return {\n id: scopes.map((scope) => scope.id).join(\", \"),\n file: first.file,\n feature: first.feature,\n flow: first.flow,\n features: union((scope) => scope.features),\n files: union((scope) => [...scope.files, scope.file]),\n locked: union((scope) => scope.locked),\n touches: union((scope) => scope.touches),\n removes: scopes.flatMap((scope) => scope.removes),\n };\n}\n\n/** The flow refs of a scope: its own flow and every `Features:` entry written as `<feature>/<flow>`. */\nexport function scopeFlows(scope: TaskScope): string[] {\n const flows = scope.features.filter((entry) => entry.includes(\"/\"));\n\n if (scope.flow !== null) flows.push(scope.flow);\n\n return [...new Set(flows)];\n}\n\n/** The feature ids of a scope (a `<feature>/<flow>` entry gives its feature). */\nexport function scopeFeatures(scope: TaskScope): string[] {\n return [...new Set(scope.features.map((entry) => entry.split(\"/\")[0] ?? entry))];\n}\n"],"mappings":";;;AAgBA,MAAM,SAAS,QAAwB,IAAI,KAAK,CAAC,CAAC,QAAQ,QAAQ,GAAG,CAAC,CAAC,YAAY;;AAGnF,SAAgB,WAAW,MAA6B;CACtD,MAAM,QAAQ,oBAAoB,KAAK,KAAK,KAAK,CAAC;CAElD,OAAO,QAAQ,OAAO,MAAM,EAAE,IAAI;AACpC;;AAGA,SAAgB,SAAS,SAA0B,MAAkC;CACnF,MAAM,SAAS,WAAW,IAAI;CAE9B,IAAI,WAAW,MAAM,OAAO;CAE5B,OAAO,QAAQ,MAAM,MAAM,SAAS,WAAW,KAAK,GAAG,KAAK,MAAM,MAAM,KAAK;AAC/E;;AAGA,SAAgB,iBAAiB,MAA2B;CAC1D,MAAM,QACJ,qFAAqF,KACnF,KAAK,KAAK,CACZ;CAEF,IAAI,CAAC,OACH,OAAO;EAAE,SAAS,KAAK,KAAK;EAAG,MAAM;EAAM,WAAW;EAAM,MAAM;EAAM,MAAM,KAAK,KAAK;CAAE;CAE5F,OAAO;EACL,UAAU,MAAM,MAAM,GAAE,CAAE,YAAY;EACtC,MAAM,MAAM,OAAO,SAAY,OAAO,MAAM,EAAE,CAAC,YAAY;EAC3D,WAAW,MAAM,OAAO,SAAY,OAAO,MAAM,EAAE,CAAC,YAAY;EAChE,MAAM,MAAM,OAAO,SAAY,OAAO,MAAM,EAAE,CAAC,KAAK,CA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MAAM,SAAY,SAAyC,CAAC,GAAG,IAAI,IAAI,OAAO,QAAQ,IAAI,CAAC,CAAC;CAE5F,OAAO;EACL,IAAI,OAAO,KAAK,UAAU,MAAM,EAAE,CAAC,CAAC,KAAK,IAAI;EAC7C,MAAM,MAAM;EACZ,SAAS,MAAM;EACf,MAAM,MAAM;EACZ,UAAU,OAAO,UAAU,MAAM,QAAQ;EACzC,OAAO,OAAO,UAAU,CAAC,GAAG,MAAM,OAAO,MAAM,IAAI,CAAC;EACpD,QAAQ,OAAO,UAAU,MAAM,MAAM;EACrC,SAAS,OAAO,UAAU,MAAM,OAAO;EACvC,SAAS,OAAO,SAAS,UAAU,MAAM,OAAO;CAClD;AACF;;AAGA,SAAgB,WAAW,OAA4B;CACrD,MAAM,QAAQ,MAAM,SAAS,QAAQ,UAAU,MAAM,SAAS,GAAG,CAAC;CAElE,IAAI,MAAM,SAAS,MAAM,MAAM,KAAK,MAAM,IAAI;CAE9C,OAAO,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC;AAC3B;;AAGA,SAAgB,cAAc,OAA4B;CACxD,OAAO,CAAC,GAAG,IAAI,IAAI,MAAM,SAAS,KAAK,UAAU,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;AACjF"}
package/esm/index.d.mts CHANGED
@@ -2,11 +2,16 @@ import { BookAdapter, BookExport, BookFacts, BookFile, BookFileType, BookHost, B
2
2
  import { Located, SourceLocation } from "./contracts/location.mjs";
3
3
  import { GrimoireCheckReport, GrimoireCodeArea, GrimoireCodeDefinition, GrimoireFinding, GrimoireFindingInput, GrimoireSeverity, RouteFreshness } from "./contracts/findings.mjs";
4
4
  import { BOOK_SCHEMA_VERSION, BookAnnotations, BookEntry, BookFactsCache, BookManifest, BookManifestFile, BookMobileScreensFile, BookModuleSummary, BookRouteRef, BookRoutesFile, BookSitePagesFile, BuildBookOptions, BuildBookResult, LoadedBook, WriteBookResult } from "./contracts/book.mjs";
5
- import { CASE_QUESTIONS, COLLECTED_END_MARKER, COLLECTED_START_MARKER, CaseQuestion, ChangeWord, CriterionId, FeatureVersion, FlowRef, StepType, TaskStatus, TaskType, WrittenApp, WrittenBlockFile, WrittenBlockRow, WrittenCase, WrittenChangelog, WrittenChangelogEntry, WrittenChangelogSection, WrittenChangesWith, WrittenCriterion, WrittenEntryPoint, WrittenFeature, WrittenFeatureReadme, WrittenFlow, WrittenGrimoire, WrittenLayout, WrittenListLine, WrittenOrigin, WrittenPage, WrittenRelease, WrittenReleaseListed, WrittenScreenshot, WrittenStatus, WrittenStep, WrittenStoryStep, WrittenTask, WrittenVersionBrief, WrittenWho } from "./contracts/written.mjs";
5
+ import { CODE_RULES, CodeRuleName, DEFAULT_GRIMOIRE_SETTINGS, DEFAULT_PROTECTED_AREAS, GrimoireSettings, ProtectedArea, SCREENSHOT_MODES, ScreenshotMode, WrittenSettings } from "./contracts/settings.mjs";
6
+ import { CASE_QUESTIONS, COLLECTED_END_MARKER, COLLECTED_START_MARKER, CaseQuestion, ChangeWord, CriterionId, FeatureVersion, FlowRef, StepType, TaskStatus, TaskType, UI_CASE_QUESTIONS, UiCaseQuestion, WrittenApp, WrittenBlockFile, WrittenBlockRow, WrittenCase, WrittenChangelog, WrittenChangelogEntry, WrittenChangelogSection, WrittenChangesWith, WrittenCriterion, WrittenEntryPoint, WrittenFeature, WrittenFeatureReadme, WrittenFlow, WrittenGrimoire, WrittenLayout, WrittenListLine, WrittenOrigin, WrittenPage, WrittenRelease, WrittenReleaseListed, WrittenScreenshot, WrittenStatus, WrittenStep, WrittenStoryStep, WrittenTask, WrittenVersionBrief, WrittenWho } from "./contracts/written.mjs";
6
7
  import { CriterionStatus, ProofLine, ProofResult, TestOutcome, TestResultsInfo, TestResultsStore, UnmatchedProof } from "./contracts/test-results.mjs";
7
8
  import { CollectedFiles, FeatureBookmap, FeaturesIndex, FileOwnership, FlowBookmap, FlowBookmapCriterion, FlowBookmapStep, Ownership, TaskSummary, TasksIndex } from "./contracts/bookmap.mjs";
9
+ import { ApprovedBaseline, ApprovedFlow, ApprovedProof, ApprovedShot, DriftItem, DriftType, RejectedChange, ShotCapture, ShotCaptureIndex, ShotOutcome, ShotsState, ShowsLine } from "./contracts/shots.mjs";
8
10
  import { AppMatch, GrimoireRule, GrimoireSnapshot, OpenGrimoireOptions } from "./contracts/snapshot.mjs";
9
- import { ScryError, ScryFeatureFlow, ScryFeatureResult, ScryFileResult, ScryFlowResult, ScryHit, ScryHitType, ScryImpactResult, ScryNotes, ScryPageRef, ScryQuery, ScryResult, ScryRoutePage, ScryRouteResult, ScrySearchResult } from "./contracts/scry.mjs";
11
+ import { ScryAlsoChange, ScryError, ScryFeatureFlow, ScryFeatureResult, ScryFileResult, ScryFlowResult, ScryHit, ScryHitType, ScryImpactResult, ScryNotes, ScryPageRef, ScryQuery, ScryResult, ScryRoutePage, ScryRouteResult, ScrySearchResult } from "./contracts/scry.mjs";
12
+ import { ChangedFile, ChangedFileStatus, CommitInfo } from "./git/index.mjs";
13
+ import { ApiSnapshot, GuardFileText, GuardInput, GuardReport, RemoveEntry, TaskScope } from "./contracts/guard.mjs";
14
+ import { GrimoireMatrix, MatrixCell, MatrixCellState, MatrixCriterionRow, MatrixFeatureRow, MatrixFlowRow } from "./contracts/matrix.mjs";
10
15
  import { CollectedListText, ReleaseCollection, ReleaseEntry, WriteReleaseResult } from "./contracts/releases.mjs";
11
16
  import { GRIMOIRE_CODES, GRIMOIRE_CODE_LIST, GrimoireCode } from "./codes/codes.mjs";
12
17
  import { GRIMOIRE_CODES_DOCS_URL, GrimoireError, createFinding, explainGrimoireCode, grimoireCodeDocsUrl, isGrimoireCode } from "./codes/index.mjs";
@@ -14,6 +19,7 @@ import { BookPathInput, GRIMOIRE_DIR, GRIMOIRE_IGNORE_RULES, GRIMOIRE_PATHS, boo
14
19
  import { FrontMatterField, FrontMatterResult, FrontMatterValue, readFrontMatter } from "./front-matter/index.mjs";
15
20
  import { FileGraph, fileGraph, importClosure, importerClosure } from "./graph/index.mjs";
16
21
  import { ParseGrimoireResult, parseGrimoire } from "./written/parse-grimoire.mjs";
22
+ import { resolveSettings } from "./written/settings.mjs";
17
23
  import { BookCheck, buildBook, checkBook, loadBook } from "./book/build.mjs";
18
24
  import { writeBook } from "./book/write.mjs";
19
25
  import { resolveOwnership } from "./ownership/index.mjs";
@@ -23,6 +29,7 @@ import { writeCollectedFiles } from "./bookmap/write.mjs";
23
29
  import { openGrimoire } from "./workspace/index.mjs";
24
30
  import { openStoredGrimoire } from "./workspace/stored.mjs";
25
31
  import { ScanProofsResult, scanProofs, scanProofsInText } from "./proves/scan-proofs.mjs";
32
+ import { ScanShowsResult, scanShows } from "./proves/scan-shows.mjs";
26
33
  import { checkGrimoire } from "./check/check-grimoire.mjs";
27
34
  import { formatCheckReport } from "./check/format-check-report.mjs";
28
35
  import { collectRelease, renderCollectedList, writeRelease } from "./releases/index.mjs";
@@ -32,4 +39,4 @@ import { formatScryResult } from "./scry/format.mjs";
32
39
  import { parseScryQuery } from "./scry/parse.mjs";
33
40
  import { scry } from "./scry/query.mjs";
34
41
  import { SCRY_STOP_WORDS } from "./scry/search.mjs";
35
- export { AppMatch, BOOK_SCHEMA_VERSION, BookAdapter, BookAnnotations, type BookCheck, BookEntry, BookExport, BookFacts, BookFactsCache, BookFile, BookFileType, BookHost, BookImport, BookManifest, BookManifestFile, BookMobileApp, BookMobileScreensFile, BookModuleSummary, BookNamedThing, BookNamedType, BookPage, BookPageLink, type BookPathInput, BookRoute, BookRouteRef, BookRoutesFile, BookScreen, BookSite, BookSitePagesFile, BuildBookOptions, BuildBookResult, CASE_QUESTIONS, COLLECTED_END_MARKER, COLLECTED_START_MARKER, CaseQuestion, ChangeWord, CollectedFiles, type CollectedInput, CollectedListText, CriterionId, CriterionStatus, type CriterionTestResult, FeatureBookmap, FeatureVersion, FeaturesIndex, type FileGraph, FileOwnership, FlowBookmap, FlowBookmapCriterion, FlowBookmapStep, FlowRef, type FrontMatterField, type FrontMatterResult, type FrontMatterValue, GRIMOIRE_CODES, GRIMOIRE_CODES_DOCS_URL, GRIMOIRE_CODE_LIST, GRIMOIRE_DIR, GRIMOIRE_IGNORE_RULES, GRIMOIRE_PATHS, GrimoireCheckReport, type GrimoireCode, GrimoireCodeArea, GrimoireCodeDefinition, GrimoireError, GrimoireFinding, GrimoireFindingInput, GrimoireRule, GrimoireSeverity, GrimoireSnapshot, LoadedBook, Located, OpenGrimoireOptions, Ownership, type ParseGrimoireResult, ProofLine, ProofResult, ReleaseCollection, ReleaseEntry, RouteFreshness, SCRY_STOP_WORDS, type ScanProofsResult, ScryError, ScryFeatureFlow, ScryFeatureResult, ScryFileResult, ScryFlowResult, ScryHit, ScryHitType, ScryImpactResult, ScryNotes, ScryPageRef, ScryQuery, ScryResult, ScryRoutePage, ScryRouteResult, ScrySearchResult, SourceLocation, StepType, TaskStatus, TaskSummary, TaskType, TasksIndex, TestOutcome, TestResultsInfo, TestResultsStore, UnmatchedProof, WriteBookResult, WriteReleaseResult, WrittenApp, WrittenBlockFile, WrittenBlockRow, WrittenCase, WrittenChangelog, WrittenChangelogEntry, WrittenChangelogSection, WrittenChangesWith, WrittenCriterion, WrittenEntryPoint, WrittenFeature, WrittenFeatureReadme, WrittenFlow, WrittenGrimoire, WrittenLayout, WrittenListLine, WrittenOrigin, WrittenPage, WrittenRelease, WrittenReleaseListed, WrittenScreenshot, WrittenStatus, WrittenStep, WrittenStoryStep, WrittenTask, WrittenVersionBrief, WrittenWho, bookEntryPath, bookEntryPaths, buildBook, buildCollectedFiles, checkBook, checkGrimoire, collectRelease, createFinding, criterionStatus, explainGrimoireCode, fileGraph, formatCheckReport, formatScryResult, grimoireCodeDocsUrl, importClosure, importerClosure, isGrimoireCode, loadBook, matchApps, openGrimoire, openStoredGrimoire, parseGrimoire, parseScryQuery, readFrontMatter, readTestResults, renderCollectedList, resolveOwnership, scanProofs, scanProofsInText, scry, toPosixPath, writeBook, writeCollectedFiles, writeRelease };
42
+ export { ApiSnapshot, AppMatch, ApprovedBaseline, ApprovedFlow, ApprovedProof, ApprovedShot, BOOK_SCHEMA_VERSION, BookAdapter, BookAnnotations, type BookCheck, BookEntry, BookExport, BookFacts, BookFactsCache, BookFile, BookFileType, BookHost, BookImport, BookManifest, BookManifestFile, BookMobileApp, BookMobileScreensFile, BookModuleSummary, BookNamedThing, BookNamedType, BookPage, BookPageLink, type BookPathInput, BookRoute, BookRouteRef, BookRoutesFile, BookScreen, BookSite, BookSitePagesFile, BuildBookOptions, BuildBookResult, CASE_QUESTIONS, CODE_RULES, COLLECTED_END_MARKER, COLLECTED_START_MARKER, CaseQuestion, ChangeWord, type ChangedFile, type ChangedFileStatus, CodeRuleName, CollectedFiles, type CollectedInput, CollectedListText, type CommitInfo, CriterionId, CriterionStatus, type CriterionTestResult, DEFAULT_GRIMOIRE_SETTINGS, DEFAULT_PROTECTED_AREAS, DriftItem, DriftType, FeatureBookmap, FeatureVersion, FeaturesIndex, type FileGraph, FileOwnership, FlowBookmap, FlowBookmapCriterion, FlowBookmapStep, FlowRef, type FrontMatterField, type FrontMatterResult, type FrontMatterValue, GRIMOIRE_CODES, GRIMOIRE_CODES_DOCS_URL, GRIMOIRE_CODE_LIST, GRIMOIRE_DIR, GRIMOIRE_IGNORE_RULES, GRIMOIRE_PATHS, GrimoireCheckReport, type GrimoireCode, GrimoireCodeArea, GrimoireCodeDefinition, GrimoireError, GrimoireFinding, GrimoireFindingInput, GrimoireMatrix, GrimoireRule, GrimoireSettings, GrimoireSeverity, GrimoireSnapshot, GuardFileText, GuardInput, GuardReport, LoadedBook, Located, MatrixCell, MatrixCellState, MatrixCriterionRow, MatrixFeatureRow, MatrixFlowRow, OpenGrimoireOptions, Ownership, type ParseGrimoireResult, ProofLine, ProofResult, ProtectedArea, RejectedChange, ReleaseCollection, ReleaseEntry, RemoveEntry, RouteFreshness, SCREENSHOT_MODES, SCRY_STOP_WORDS, type ScanProofsResult, type ScanShowsResult, ScreenshotMode, ScryAlsoChange, ScryError, ScryFeatureFlow, ScryFeatureResult, ScryFileResult, ScryFlowResult, ScryHit, ScryHitType, ScryImpactResult, ScryNotes, ScryPageRef, ScryQuery, ScryResult, ScryRoutePage, ScryRouteResult, ScrySearchResult, ShotCapture, ShotCaptureIndex, ShotOutcome, ShotsState, ShowsLine, SourceLocation, StepType, TaskScope, TaskStatus, TaskSummary, TaskType, TasksIndex, TestOutcome, TestResultsInfo, TestResultsStore, UI_CASE_QUESTIONS, UiCaseQuestion, UnmatchedProof, WriteBookResult, WriteReleaseResult, WrittenApp, WrittenBlockFile, WrittenBlockRow, WrittenCase, WrittenChangelog, WrittenChangelogEntry, WrittenChangelogSection, WrittenChangesWith, WrittenCriterion, WrittenEntryPoint, WrittenFeature, WrittenFeatureReadme, WrittenFlow, WrittenGrimoire, WrittenLayout, WrittenListLine, WrittenOrigin, WrittenPage, WrittenRelease, WrittenReleaseListed, WrittenScreenshot, WrittenSettings, WrittenStatus, WrittenStep, WrittenStoryStep, WrittenTask, WrittenVersionBrief, WrittenWho, bookEntryPath, bookEntryPaths, buildBook, buildCollectedFiles, checkBook, checkGrimoire, collectRelease, createFinding, criterionStatus, explainGrimoireCode, fileGraph, formatCheckReport, formatScryResult, grimoireCodeDocsUrl, importClosure, importerClosure, isGrimoireCode, loadBook, matchApps, openGrimoire, openStoredGrimoire, parseGrimoire, parseScryQuery, readFrontMatter, readTestResults, renderCollectedList, resolveOwnership, resolveSettings, scanProofs, scanProofsInText, scanShows, scry, toPosixPath, writeBook, writeCollectedFiles, writeRelease };
package/esm/index.mjs CHANGED
@@ -1,10 +1,13 @@
1
1
  import { BOOK_SCHEMA_VERSION } from "./contracts/book.mjs";
2
- import { CASE_QUESTIONS, COLLECTED_END_MARKER, COLLECTED_START_MARKER } from "./contracts/written.mjs";
2
+ import { CODE_RULES, DEFAULT_GRIMOIRE_SETTINGS, DEFAULT_PROTECTED_AREAS, SCREENSHOT_MODES } from "./contracts/settings.mjs";
3
+ import { CASE_QUESTIONS, COLLECTED_END_MARKER, COLLECTED_START_MARKER, UI_CASE_QUESTIONS } from "./contracts/written.mjs";
4
+ import "./contracts/index.mjs";
3
5
  import { GRIMOIRE_CODES, GRIMOIRE_CODE_LIST } from "./codes/codes.mjs";
4
6
  import { GRIMOIRE_CODES_DOCS_URL, GrimoireError, createFinding, explainGrimoireCode, grimoireCodeDocsUrl, isGrimoireCode } from "./codes/index.mjs";
5
7
  import { GRIMOIRE_DIR, GRIMOIRE_IGNORE_RULES, GRIMOIRE_PATHS, bookEntryPath, bookEntryPaths, toPosixPath } from "./paths/index.mjs";
6
8
  import { readFrontMatter } from "./front-matter/index.mjs";
7
9
  import { fileGraph, importClosure, importerClosure } from "./graph/index.mjs";
10
+ import { resolveSettings } from "./written/settings.mjs";
8
11
  import { parseGrimoire } from "./written/parse-grimoire.mjs";
9
12
  import "./written/index.mjs";
10
13
  import { buildBook, checkBook, loadBook } from "./book/build.mjs";
@@ -19,6 +22,7 @@ import { buildCollectedFiles } from "./bookmap/build.mjs";
19
22
  import { writeCollectedFiles } from "./bookmap/write.mjs";
20
23
  import "./bookmap/index.mjs";
21
24
  import { scanProofs, scanProofsInText } from "./proves/scan-proofs.mjs";
25
+ import { scanShows } from "./proves/scan-shows.mjs";
22
26
  import "./proves/index.mjs";
23
27
  import { openGrimoire } from "./workspace/index.mjs";
24
28
  import { openStoredGrimoire } from "./workspace/stored.mjs";
@@ -32,4 +36,4 @@ import { SCRY_STOP_WORDS } from "./scry/search.mjs";
32
36
  import { scry } from "./scry/query.mjs";
33
37
  import "./scry/index.mjs";
34
38
 
35
- export { BOOK_SCHEMA_VERSION, CASE_QUESTIONS, COLLECTED_END_MARKER, COLLECTED_START_MARKER, GRIMOIRE_CODES, GRIMOIRE_CODES_DOCS_URL, GRIMOIRE_CODE_LIST, GRIMOIRE_DIR, GRIMOIRE_IGNORE_RULES, GRIMOIRE_PATHS, GrimoireError, SCRY_STOP_WORDS, bookEntryPath, bookEntryPaths, buildBook, buildCollectedFiles, checkBook, checkGrimoire, collectRelease, createFinding, criterionStatus, explainGrimoireCode, fileGraph, formatCheckReport, formatScryResult, grimoireCodeDocsUrl, importClosure, importerClosure, isGrimoireCode, loadBook, matchApps, openGrimoire, openStoredGrimoire, parseGrimoire, parseScryQuery, readFrontMatter, readTestResults, renderCollectedList, resolveOwnership, scanProofs, scanProofsInText, scry, toPosixPath, writeBook, writeCollectedFiles, writeRelease };
39
+ export { BOOK_SCHEMA_VERSION, CASE_QUESTIONS, CODE_RULES, COLLECTED_END_MARKER, COLLECTED_START_MARKER, DEFAULT_GRIMOIRE_SETTINGS, DEFAULT_PROTECTED_AREAS, GRIMOIRE_CODES, GRIMOIRE_CODES_DOCS_URL, GRIMOIRE_CODE_LIST, GRIMOIRE_DIR, GRIMOIRE_IGNORE_RULES, GRIMOIRE_PATHS, GrimoireError, SCREENSHOT_MODES, SCRY_STOP_WORDS, UI_CASE_QUESTIONS, bookEntryPath, bookEntryPaths, buildBook, buildCollectedFiles, checkBook, checkGrimoire, collectRelease, createFinding, criterionStatus, explainGrimoireCode, fileGraph, formatCheckReport, formatScryResult, grimoireCodeDocsUrl, importClosure, importerClosure, isGrimoireCode, loadBook, matchApps, openGrimoire, openStoredGrimoire, parseGrimoire, parseScryQuery, readFrontMatter, readTestResults, renderCollectedList, resolveOwnership, resolveSettings, scanProofs, scanProofsInText, scanShows, scry, toPosixPath, writeBook, writeCollectedFiles, writeRelease };
@@ -27,9 +27,23 @@ export declare const GRIMOIRE_PATHS: {
27
27
  readonly releases: "grimoire/releases";
28
28
  /** Images that written files show (`![alt](path)` lines point inside this folder). */
29
29
  readonly screenshots: "grimoire/screenshots";
30
+ /** Project settings (languages, screenshot mode, code rules, protected areas). Optional. */
31
+ readonly settings: "grimoire/settings.md";
32
+ /** Approved state, written only by `warlock grimoire approve` / `reject` and the tab's buttons (in git). */
33
+ readonly approved: "grimoire/approved";
34
+ /** The approved flows, criteria, cases, proving tests and images. */
35
+ readonly baseline: "grimoire/approved/baseline.json";
36
+ /** The approved public API (the routes). */
37
+ readonly apiSnapshot: "grimoire/approved/api.json";
38
+ /** Approved images of `@shows` scenes (in git). */
39
+ readonly approvedShots: "grimoire/screenshots/approved";
40
+ /** Warlock. The last capture of every `@shows` scene (ignored by git). */
41
+ readonly capturedShots: "grimoire/screenshots/captured";
42
+ /** Warlock. What the last captures were (ignored by git). */
43
+ readonly captureIndex: "grimoire/screenshots/captured/index.json";
30
44
  };
31
45
  /** Lines a project's `.gitignore` needs so Warlock's files stay out of git. */
32
- export declare const GRIMOIRE_IGNORE_RULES: readonly ["/grimoire/book/", "/grimoire/features/index.json", "/grimoire/features/**/bookmap.json", "/grimoire/features/**/*.bookmap.json", "/grimoire/tasks/index.json"];
46
+ export declare const GRIMOIRE_IGNORE_RULES: readonly ["/grimoire/book/", "/grimoire/features/index.json", "/grimoire/features/**/bookmap.json", "/grimoire/features/**/*.bookmap.json", "/grimoire/tasks/index.json", "/grimoire/screenshots/captured/"];
33
47
  /** A path with `\` turned into `/`. */
34
48
  export declare function toPosixPath(file: string): string;
35
49
  /** One file to place in the book. */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/paths/index.ts"],"mappings":";;qBAOa;;qBAGA;;WAEX;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;WACA;;WAEA;WACA;WACA;WACA;WACA;;WAEA;WACA;;WAEA;;;qBAIW;;wBAWG,YAAY;;YAkDhB;EACV;;EAEA;IAAc;IAAY;;;;;;;;;;;;;;;wBAeZ,eAAe,gBAAgB,kBAAkB;;wBAiCjD,cAAc,OAAO"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/paths/index.ts"],"mappings":";;qBAOa;;qBAGA;;WAEX;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;WACA;;WAEA;WACA;WACA;WACA;WACA;;WAEA;WACA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;qBAIW;;wBAYG,YAAY;;YAkDhB;EACV;;EAEA;IAAc;IAAY;;;;;;;;;;;;;;;wBAeZ,eAAe,gBAAgB,kBAAkB;;wBAiCjD,cAAc,OAAO"}
@@ -32,7 +32,21 @@ const GRIMOIRE_PATHS = {
32
32
  tasksIndex: "grimoire/tasks/index.json",
33
33
  releases: "grimoire/releases",
34
34
  /** Images that written files show (`![alt](path)` lines point inside this folder). */
35
- screenshots: "grimoire/screenshots"
35
+ screenshots: "grimoire/screenshots",
36
+ /** Project settings (languages, screenshot mode, code rules, protected areas). Optional. */
37
+ settings: "grimoire/settings.md",
38
+ /** Approved state, written only by `warlock grimoire approve` / `reject` and the tab's buttons (in git). */
39
+ approved: "grimoire/approved",
40
+ /** The approved flows, criteria, cases, proving tests and images. */
41
+ baseline: "grimoire/approved/baseline.json",
42
+ /** The approved public API (the routes). */
43
+ apiSnapshot: "grimoire/approved/api.json",
44
+ /** Approved images of `@shows` scenes (in git). */
45
+ approvedShots: "grimoire/screenshots/approved",
46
+ /** Warlock. The last capture of every `@shows` scene (ignored by git). */
47
+ capturedShots: "grimoire/screenshots/captured",
48
+ /** Warlock. What the last captures were (ignored by git). */
49
+ captureIndex: "grimoire/screenshots/captured/index.json"
36
50
  };
37
51
  /** Lines a project's `.gitignore` needs so Warlock's files stay out of git. */
38
52
  const GRIMOIRE_IGNORE_RULES = [
@@ -40,7 +54,8 @@ const GRIMOIRE_IGNORE_RULES = [
40
54
  "/grimoire/features/index.json",
41
55
  "/grimoire/features/**/bookmap.json",
42
56
  "/grimoire/features/**/*.bookmap.json",
43
- "/grimoire/tasks/index.json"
57
+ "/grimoire/tasks/index.json",
58
+ "/grimoire/screenshots/captured/"
44
59
  ];
45
60
  const CODE_EXTENSION = /\.(?:d\.ts|[cm]?[jt]s|[jt]sx)$/;
46
61
  /** A path with `\` turned into `/`. */
@@ -129,11 +144,20 @@ function featureBookmapPath(feature) {
129
144
  function flowBookmapPath(feature, flow) {
130
145
  return `${GRIMOIRE_PATHS.features}/${feature}/flows/${flow}.bookmap.json`;
131
146
  }
147
+ /**
148
+ * The image of one criterion in one language, relative to its folder under
149
+ * `grimoire/screenshots/` (`approved/` or `captured/`):
150
+ * `contact/send-message/AC-2.ar.png`, or `…/AC-2.png` when the app names no
151
+ * language.
152
+ */
153
+ function criterionShotName(ref, criterion, language) {
154
+ return `${ref}/${criterion}${language === "" ? "" : `.${language}`}.png`;
155
+ }
132
156
  /** `grimoire/releases/<release>.md`. */
133
157
  function releaseFilePath(release) {
134
158
  return `${GRIMOIRE_PATHS.releases}/${release}.md`;
135
159
  }
136
160
 
137
161
  //#endregion
138
- export { GRIMOIRE_DIR, GRIMOIRE_IGNORE_RULES, GRIMOIRE_PATHS, bookEntryPath, bookEntryPaths, featureBookmapPath, flowBookmapPath, isCodeFile, isInsideFolder, isReservedBookPath, mobileScreensPath, moduleSummaryPath, projectPath, releaseFilePath, sitePagesPath, toPosixPath };
162
+ export { GRIMOIRE_DIR, GRIMOIRE_IGNORE_RULES, GRIMOIRE_PATHS, bookEntryPath, bookEntryPaths, criterionShotName, featureBookmapPath, flowBookmapPath, isCodeFile, isInsideFolder, isReservedBookPath, mobileScreensPath, moduleSummaryPath, projectPath, releaseFilePath, sitePagesPath, toPosixPath };
139
163
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/paths/index.ts"],"sourcesContent":["/**\n * Where everything lives under `grimoire/`, and how a source file maps to its\n * book entry. Every path here is project-relative and uses `/`.\n */\nimport path from \"node:path\";\n\n/** The folder at the project root. */\nexport const GRIMOIRE_DIR = \"grimoire\";\n\n/** Project-relative paths of the Grimoire layout. Agent-written unless marked Warlock. */\nexport const GRIMOIRE_PATHS = {\n /** Warlock. The generated book (ignored by git). */\n book: \"grimoire/book\",\n /** Warlock. The freshness fingerprint. */\n bookManifest: \"grimoire/book/manifest.json\",\n /** Warlock. The adapter's last facts (machine use). */\n bookFactsCache: \"grimoire/book/.cache/facts.json\",\n /** Warlock. Every route, by module. */\n bookRoutes: \"grimoire/book/app/routes.json\",\n /** Warlock (the Vitest reporter). Test results per proving test. */\n testResults: \"grimoire/book/test-results.json\",\n /** Warlock. Default folder of the static devtools export. */\n staticSite: \"grimoire/book/site\",\n features: \"grimoire/features\",\n /** Warlock. */\n featuresIndex: \"grimoire/features/index.json\",\n apps: \"grimoire/apps\",\n tasks: \"grimoire/tasks\",\n openTasks: \"grimoire/tasks/open\",\n doneTasks: \"grimoire/tasks/done\",\n /** Warlock. */\n tasksIndex: \"grimoire/tasks/index.json\",\n releases: \"grimoire/releases\",\n /** Images that written files show (`![alt](path)` lines point inside this folder). */\n screenshots: \"grimoire/screenshots\",\n} as const;\n\n/** Lines a project's `.gitignore` needs so Warlock's files stay out of git. */\nexport const GRIMOIRE_IGNORE_RULES = [\n \"/grimoire/book/\",\n \"/grimoire/features/index.json\",\n \"/grimoire/features/**/bookmap.json\",\n \"/grimoire/features/**/*.bookmap.json\",\n \"/grimoire/tasks/index.json\",\n] as const;\n\nconst CODE_EXTENSION = /\\.(?:d\\.ts|[cm]?[jt]s|[jt]sx)$/;\n\n/** A path with `\\` turned into `/`. */\nexport function toPosixPath(file: string): string {\n return file.split(\"\\\\\").join(\"/\");\n}\n\n/** A project-relative POSIX path for an absolute or relative path. */\nexport function projectPath(root: string, file: string): string {\n return toPosixPath(path.relative(root, path.resolve(root, file)));\n}\n\n/** Whether a project-relative file is inside a project-relative folder (or is it). */\nexport function isInsideFolder(file: string, folder: string): boolean {\n const normalizedFolder = toPosixPath(folder).replace(/\\/+$/, \"\");\n const normalizedFile = toPosixPath(file);\n\n return normalizedFile === normalizedFolder || normalizedFile.startsWith(`${normalizedFolder}/`);\n}\n\n/** Whether a file name is a code file the book has an entry for. */\nexport function isCodeFile(file: string): boolean {\n return CODE_EXTENSION.test(file);\n}\n\n/** Book paths Warlock writes for lists; a mirrored entry never takes one of them. */\nexport function isReservedBookPath(bookPath: string): boolean {\n return (\n bookPath === GRIMOIRE_PATHS.bookManifest ||\n bookPath === GRIMOIRE_PATHS.bookRoutes ||\n bookPath === GRIMOIRE_PATHS.testResults ||\n bookPath.startsWith(`${GRIMOIRE_PATHS.book}/.cache/`) ||\n bookPath.startsWith(`${GRIMOIRE_PATHS.staticSite}/`) ||\n /^grimoire\\/book\\/web\\/[^/]+\\.pages\\.json$/.test(bookPath) ||\n /^grimoire\\/book\\/mobile\\/[^/]+\\.screens\\.json$/.test(bookPath)\n );\n}\n\n/** The mirror of a source file without the collision rules: `src/` dropped, extension → `.json`. */\nfunction plainEntryPath(file: string, mobileApp: string | null, mobileRoot: string | null): string {\n const posix = toPosixPath(file);\n let relative: string;\n\n if (mobileApp !== null && mobileRoot !== null && isInsideFolder(posix, mobileRoot)) {\n relative = `mobile/${mobileApp}/${posix.slice(toPosixPath(mobileRoot).replace(/\\/+$/, \"\").length + 1)}`;\n } else {\n relative = posix.startsWith(\"src/\") ? posix.slice(4) : posix;\n }\n\n return `${GRIMOIRE_PATHS.book}/${relative.replace(CODE_EXTENSION, \"\")}.json`;\n}\n\n/** One file to place in the book. */\nexport type BookPathInput = {\n file: string;\n /** Mobile app id and root when the file belongs to a mobile app. */\n mobileApp?: { id: string; root: string } | null;\n};\n\n/**\n * The book entry path of every given code file.\n *\n * `src/app/auth/controllers/login.controller.ts` →\n * `grimoire/book/app/auth/controllers/login.controller.json`; a mobile app\n * file `mobile/app/index.tsx` of app `mobile` →\n * `grimoire/book/mobile/mobile/app/index.json`.\n *\n * When two files would share a path (`a.ts` and `a.tsx`), or a file would\n * take a reserved list path (`src/app/routes.ts` → `app/routes.json`), those\n * files keep their full name instead: `a.ts.json`, `routes.ts.json`.\n */\nexport function bookEntryPaths(files: readonly BookPathInput[]): Map<string, string> {\n const plain = new Map<string, string>();\n const counts = new Map<string, number>();\n\n for (const input of files) {\n const entry = plainEntryPath(\n input.file,\n input.mobileApp?.id ?? null,\n input.mobileApp?.root ?? null,\n );\n plain.set(input.file, entry);\n counts.set(entry, (counts.get(entry) ?? 0) + 1);\n }\n\n const result = new Map<string, string>();\n\n for (const input of files) {\n const entry = plain.get(input.file);\n\n if (entry === undefined) continue;\n\n if ((counts.get(entry) ?? 0) > 1 || isReservedBookPath(entry)) {\n const name = path.posix.basename(toPosixPath(input.file));\n result.set(input.file, `${path.posix.dirname(entry)}/${name}.json`);\n } else {\n result.set(input.file, entry);\n }\n }\n\n return result;\n}\n\n/** The book entry path of one file, when no other file can collide with it. */\nexport function bookEntryPath(input: BookPathInput): string {\n return bookEntryPaths([input]).get(input.file) ?? plainEntryPath(input.file, null, null);\n}\n\n/** `grimoire/book/web/<site>.pages.json`. */\nexport function sitePagesPath(site: string): string {\n return `${GRIMOIRE_PATHS.book}/web/${site}.pages.json`;\n}\n\n/** `grimoire/book/mobile/<app>.screens.json`. */\nexport function mobileScreensPath(app: string): string {\n return `${GRIMOIRE_PATHS.book}/mobile/${app}.screens.json`;\n}\n\n/** `grimoire/book/<module without src/>/index.md`. */\nexport function moduleSummaryPath(module: string): string {\n const posix = toPosixPath(module);\n\n return `${GRIMOIRE_PATHS.book}/${posix.startsWith(\"src/\") ? posix.slice(4) : posix}/index.md`;\n}\n\n/** `grimoire/features/<feature>/bookmap.json`. */\nexport function featureBookmapPath(feature: string): string {\n return `${GRIMOIRE_PATHS.features}/${feature}/bookmap.json`;\n}\n\n/** `grimoire/features/<feature>/flows/<flow>.bookmap.json`. */\nexport function flowBookmapPath(feature: string, flow: string): string {\n return `${GRIMOIRE_PATHS.features}/${feature}/flows/${flow}.bookmap.json`;\n}\n\n/** `grimoire/releases/<release>.md`. */\nexport function releaseFilePath(release: string): string {\n return `${GRIMOIRE_PATHS.releases}/${release}.md`;\n}\n"],"mappings":";;;;;;;;AAOA,MAAa,eAAe;;AAG5B,MAAa,iBAAiB;;CAE5B,MAAM;;CAEN,cAAc;;CAEd,gBAAgB;;CAEhB,YAAY;;CAEZ,aAAa;;CAEb,YAAY;CACZ,UAAU;;CAEV,eAAe;CACf,MAAM;C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,SAAyB;CAC1D,OAAO,GAAG,eAAe,SAAS,GAAG,QAAQ;AAC/C;;AAGA,SAAgB,gBAAgB,SAAiB,MAAsB;CACrE,OAAO,GAAG,eAAe,SAAS,GAAG,QAAQ,SAAS,KAAK;AAC7D;;AAGA,SAAgB,gBAAgB,SAAyB;CACvD,OAAO,GAAG,eAAe,SAAS,GAAG,QAAQ;AAC/C"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/paths/index.ts"],"sourcesContent":["/**\n * Where everything lives under `grimoire/`, and how a source file maps to its\n * book entry. Every path here is project-relative and uses `/`.\n */\nimport path from \"node:path\";\n\n/** The folder at the project root. */\nexport const GRIMOIRE_DIR = \"grimoire\";\n\n/** Project-relative paths of the Grimoire layout. Agent-written unless marked Warlock. */\nexport const GRIMOIRE_PATHS = {\n /** Warlock. The generated book (ignored by git). */\n book: \"grimoire/book\",\n /** Warlock. The freshness fingerprint. */\n bookManifest: \"grimoire/book/manifest.json\",\n /** Warlock. The adapter's last facts (machine use). */\n bookFactsCache: \"grimoire/book/.cache/facts.json\",\n /** Warlock. Every route, by module. */\n bookRoutes: \"grimoire/book/app/routes.json\",\n /** Warlock (the Vitest reporter). Test results per proving test. */\n testResults: \"grimoire/book/test-results.json\",\n /** Warlock. Default folder of the static devtools export. */\n staticSite: \"grimoire/book/site\",\n features: \"grimoire/features\",\n /** Warlock. */\n featuresIndex: \"grimoire/features/index.json\",\n apps: \"grimoire/apps\",\n tasks: \"grimoire/tasks\",\n openTasks: \"grimoire/tasks/open\",\n doneTasks: \"grimoire/tasks/done\",\n /** Warlock. */\n tasksIndex: \"grimoire/tasks/index.json\",\n releases: \"grimoire/releases\",\n /** Images that written files show (`![alt](path)` lines point inside this folder). */\n screenshots: \"grimoire/screenshots\",\n /** Project settings (languages, screenshot mode, code rules, protected areas). Optional. */\n settings: \"grimoire/settings.md\",\n /** Approved state, written only by `warlock grimoire approve` / `reject` and the tab's buttons (in git). */\n approved: \"grimoire/approved\",\n /** The approved flows, criteria, cases, proving tests and images. */\n baseline: \"grimoire/approved/baseline.json\",\n /** The approved public API (the routes). */\n apiSnapshot: \"grimoire/approved/api.json\",\n /** Approved images of `@shows` scenes (in git). */\n approvedShots: \"grimoire/screenshots/approved\",\n /** Warlock. The last capture of every `@shows` scene (ignored by git). */\n capturedShots: \"grimoire/screenshots/captured\",\n /** Warlock. What the last captures were (ignored by git). */\n captureIndex: \"grimoire/screenshots/captured/index.json\",\n} as const;\n\n/** Lines a project's `.gitignore` needs so Warlock's files stay out of git. */\nexport const GRIMOIRE_IGNORE_RULES = [\n \"/grimoire/book/\",\n \"/grimoire/features/index.json\",\n \"/grimoire/features/**/bookmap.json\",\n \"/grimoire/features/**/*.bookmap.json\",\n \"/grimoire/tasks/index.json\",\n \"/grimoire/screenshots/captured/\",\n] as const;\n\nconst CODE_EXTENSION = /\\.(?:d\\.ts|[cm]?[jt]s|[jt]sx)$/;\n\n/** A path with `\\` turned into `/`. */\nexport function toPosixPath(file: string): string {\n return file.split(\"\\\\\").join(\"/\");\n}\n\n/** A project-relative POSIX path for an absolute or relative path. */\nexport function projectPath(root: string, file: string): string {\n return toPosixPath(path.relative(root, path.resolve(root, file)));\n}\n\n/** Whether a project-relative file is inside a project-relative folder (or is it). */\nexport function isInsideFolder(file: string, folder: string): boolean {\n const normalizedFolder = toPosixPath(folder).replace(/\\/+$/, \"\");\n const normalizedFile = toPosixPath(file);\n\n return normalizedFile === normalizedFolder || normalizedFile.startsWith(`${normalizedFolder}/`);\n}\n\n/** Whether a file name is a code file the book has an entry for. */\nexport function isCodeFile(file: string): boolean {\n return CODE_EXTENSION.test(file);\n}\n\n/** Book paths Warlock writes for lists; a mirrored entry never takes one of them. */\nexport function isReservedBookPath(bookPath: string): boolean {\n return (\n bookPath === GRIMOIRE_PATHS.bookManifest ||\n bookPath === GRIMOIRE_PATHS.bookRoutes ||\n bookPath === GRIMOIRE_PATHS.testResults ||\n bookPath.startsWith(`${GRIMOIRE_PATHS.book}/.cache/`) ||\n bookPath.startsWith(`${GRIMOIRE_PATHS.staticSite}/`) ||\n /^grimoire\\/book\\/web\\/[^/]+\\.pages\\.json$/.test(bookPath) ||\n /^grimoire\\/book\\/mobile\\/[^/]+\\.screens\\.json$/.test(bookPath)\n );\n}\n\n/** The mirror of a source file without the collision rules: `src/` dropped, extension → `.json`. */\nfunction plainEntryPath(file: string, mobileApp: string | null, mobileRoot: string | null): string {\n const posix = toPosixPath(file);\n let relative: string;\n\n if (mobileApp !== null && mobileRoot !== null && isInsideFolder(posix, mobileRoot)) {\n relative = `mobile/${mobileApp}/${posix.slice(toPosixPath(mobileRoot).replace(/\\/+$/, \"\").length + 1)}`;\n } else {\n relative = posix.startsWith(\"src/\") ? posix.slice(4) : posix;\n }\n\n return `${GRIMOIRE_PATHS.book}/${relative.replace(CODE_EXTENSION, \"\")}.json`;\n}\n\n/** One file to place in the book. */\nexport type BookPathInput = {\n file: string;\n /** Mobile app id and root when the file belongs to a mobile app. */\n mobileApp?: { id: string; root: string } | null;\n};\n\n/**\n * The book entry path of every given code file.\n *\n * `src/app/auth/controllers/login.controller.ts` →\n * `grimoire/book/app/auth/controllers/login.controller.json`; a mobile app\n * file `mobile/app/index.tsx` of app `mobile` →\n * `grimoire/book/mobile/mobile/app/index.json`.\n *\n * When two files would share a path (`a.ts` and `a.tsx`), or a file would\n * take a reserved list path (`src/app/routes.ts` → `app/routes.json`), those\n * files keep their full name instead: `a.ts.json`, `routes.ts.json`.\n */\nexport function bookEntryPaths(files: readonly BookPathInput[]): Map<string, string> {\n const plain = new Map<string, string>();\n const counts = new Map<string, number>();\n\n for (const input of files) {\n const entry = plainEntryPath(\n input.file,\n input.mobileApp?.id ?? null,\n input.mobileApp?.root ?? null,\n );\n plain.set(input.file, entry);\n counts.set(entry, (counts.get(entry) ?? 0) + 1);\n }\n\n const result = new Map<string, string>();\n\n for (const input of files) {\n const entry = plain.get(input.file);\n\n if (entry === undefined) continue;\n\n if ((counts.get(entry) ?? 0) > 1 || isReservedBookPath(entry)) {\n const name = path.posix.basename(toPosixPath(input.file));\n result.set(input.file, `${path.posix.dirname(entry)}/${name}.json`);\n } else {\n result.set(input.file, entry);\n }\n }\n\n return result;\n}\n\n/** The book entry path of one file, when no other file can collide with it. */\nexport function bookEntryPath(input: BookPathInput): string {\n return bookEntryPaths([input]).get(input.file) ?? plainEntryPath(input.file, null, null);\n}\n\n/** `grimoire/book/web/<site>.pages.json`. */\nexport function sitePagesPath(site: string): string {\n return `${GRIMOIRE_PATHS.book}/web/${site}.pages.json`;\n}\n\n/** `grimoire/book/mobile/<app>.screens.json`. */\nexport function mobileScreensPath(app: string): string {\n return `${GRIMOIRE_PATHS.book}/mobile/${app}.screens.json`;\n}\n\n/** `grimoire/book/<module without src/>/index.md`. */\nexport function moduleSummaryPath(module: string): string {\n const posix = toPosixPath(module);\n\n return `${GRIMOIRE_PATHS.book}/${posix.startsWith(\"src/\") ? posix.slice(4) : posix}/index.md`;\n}\n\n/** `grimoire/features/<feature>/bookmap.json`. */\nexport function featureBookmapPath(feature: string): string {\n return `${GRIMOIRE_PATHS.features}/${feature}/bookmap.json`;\n}\n\n/** `grimoire/features/<feature>/flows/<flow>.bookmap.json`. */\nexport function flowBookmapPath(feature: string, flow: string): string {\n return `${GRIMOIRE_PATHS.features}/${feature}/flows/${flow}.bookmap.json`;\n}\n\n/**\n * The image of one criterion in one language, relative to its folder under\n * `grimoire/screenshots/` (`approved/` or `captured/`):\n * `contact/send-message/AC-2.ar.png`, or `…/AC-2.png` when the app names no\n * language.\n */\nexport function criterionShotName(ref: string, criterion: string, language: string): string {\n return `${ref}/${criterion}${language === \"\" ? \"\" : `.${language}`}.png`;\n}\n\n/** `grimoire/releases/<release>.md`. */\nexport function releaseFilePath(release: string): string {\n return `${GRIMOIRE_PATHS.releases}/${release}.md`;\n}\n"],"mappings":";;;;;;;;AAOA,MAAa,eAAe;;AAG5B,MAAa,iBAAiB;;CAE5B,MAAM;;CAEN,cAAc;;CAEd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AAC9C;;AAGA,SAAgB,kBAAkB,QAAwB;CACxD,MAAM,QAAQ,YAAY,MAAM;CAEhC,OAAO,GAAG,eAAe,KAAK,GAAG,MAAM,WAAW,MAAM,IAAI,MAAM,MAAM,CAAC,IAAI,MAAM;AACrF;;AAGA,SAAgB,mBAAmB,SAAyB;CAC1D,OAAO,GAAG,eAAe,SAAS,GAAG,QAAQ;AAC/C;;AAGA,SAAgB,gBAAgB,SAAiB,MAAsB;CACrE,OAAO,GAAG,eAAe,SAAS,GAAG,QAAQ,SAAS,KAAK;AAC7D;;;;;;;AAQA,SAAgB,kBAAkB,KAAa,WAAmB,UAA0B;CAC1F,OAAO,GAAG,IAAI,GAAG,YAAY,aAAa,KAAK,KAAK,IAAI,WAAW;AACrE;;AAGA,SAAgB,gBAAgB,SAAyB;CACvD,OAAO,GAAG,eAAe,SAAS,GAAG,QAAQ;AAC/C"}
@@ -1,3 +1,4 @@
1
1
  import { scanProofs, scanProofsInText } from "./scan-proofs.mjs";
2
+ import { knownCriteria, scanShows, scanShowsInText } from "./scan-shows.mjs";
2
3
 
3
- export { scanProofs, scanProofsInText };
4
+ export { scanProofs, scanProofsInText, scanShows };
@@ -210,5 +210,5 @@ function closingParen(text) {
210
210
  }
211
211
 
212
212
  //#endregion
213
- export { scanProofs, scanProofsInText };
213
+ export { scanProofs, scanProofsInText, withoutBlockComments };
214
214
  //# sourceMappingURL=scan-proofs.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"scan-proofs.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/proves/scan-proofs.ts"],"sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { createFinding } from \"../codes\";\nimport type { GrimoireFinding } from \"../contracts/findings\";\nimport type { ProofLine } from \"../contracts/test-results\";\nimport { toPosixPath } from \"../paths\";\n\n/** What a scan returns. */\nexport type ScanProofsResult = {\n proofs: ProofLine[];\n /** `GR4003` (malformed line), `GR4004` (no test under it), `GR4005` (two proofs on one test). */\n findings: GrimoireFinding[];\n};\n\n/** How many test files `scanProofs` reads at once. */\nconst READ_CONCURRENCY = 32;\n\n/** A `// @proves …` line comment on its own line; group 1 is the rest of the line. */\nconst PROOF_LINE = /^\\s*\\/\\/\\s*@proves\\b(.*)$/;\n/** A `// @proves` comment after code on the same line. */\nconst TRAILING_PROOF = /\\S.*\\/\\/\\s*@proves\\b/;\n/** The rest of a well-formed proof line: ` <feature>/<flow> AC-<n>`. */\nconst PROOF_TARGET = /^\\s+([a-z0-9]+(?:-[a-z0-9]+)*)\\/([a-z0-9]+(?:-[a-z0-9]+)*)\\s+(AC-\\d+)\\s*$/;\n/** `it(`, `test(`, `it.only(`, `test.each(…)(`, `it.skipIf(…)(`, `` test.each` ``… */\nconst TEST_CALL =\n /^(?:it|test)((?:\\s*\\.\\s*(?:only|skip|todo|concurrent|sequential|fails|failing|each|for|skipIf|runIf|fixme|slow))*)\\s*[(`]/;\n/** Modifiers that take their own arguments before the test's call. */\nconst MODIFIER_WITH_ARGUMENTS = /\\.\\s*(?:each|for|skipIf|runIf)\\s*$/;\n\ntype ParsedProof = {\n feature: string;\n flow: string;\n criterion: string;\n line: number;\n};\n\n/** Read the proof lines of one test file's content. Pure. */\nexport function scanProofsInText(text: string, file: string): ScanProofsResult {\n const testFile = toPosixPath(file);\n const lines = text.split(/\\r?\\n/);\n const code = withoutBlockComments(lines);\n const findings: GrimoireFinding[] = [];\n const proofs: ProofLine[] = [];\n /** Proofs waiting for the next code line, in file order. */\n let pending: ParsedProof[] = [];\n\n const settle = (testLine: number | null): void => {\n if (pending.length === 0) return;\n\n const test =\n testLine === null ? null : { name: testName(code[testLine - 1] ?? \"\"), line: testLine };\n\n for (const proof of pending) {\n const ref = `${proof.feature}/${proof.flow}`;\n const at = { file: testFile, line: proof.line, column: null };\n\n proofs.push({\n feature: proof.feature,\n flow: proof.flow,\n ref,\n criterion: proof.criterion,\n test,\n at,\n });\n\n if (!test) {\n findings.push(\n createFinding({\n code: \"GR4004\",\n message: `\"@proves ${ref} ${proof.criterion}\" is not directly above a test`,\n at,\n feature: proof.feature,\n flow: ref,\n }),\n );\n }\n }\n\n const distinct = [\n ...new Set(pending.map((proof) => `${proof.feature}/${proof.flow} ${proof.criterion}`)),\n ];\n const first = pending[0];\n\n if (test && first && distinct.length > 1) {\n findings.push(\n createFinding({\n code: \"GR4005\",\n message: `test ${test.name === null ? `on line ${test.line}` : JSON.stringify(test.name)} proves ${distinct.length} criteria: ${distinct.join(\", \")}`,\n at: { file: testFile, line: first.line, column: null },\n feature: first.feature,\n flow: `${first.feature}/${first.flow}`,\n }),\n );\n }\n\n pending = [];\n };\n\n code.forEach((content, index) => {\n const lineNumber = index + 1;\n const proof = PROOF_LINE.exec(content);\n\n if (proof) {\n const target = PROOF_TARGET.exec(proof[1] ?? \"\");\n\n if (target) {\n pending.push({\n feature: target[1] ?? \"\",\n flow: target[2] ?? \"\",\n criterion: target[3] ?? \"\",\n line: lineNumber,\n });\n } else {\n findings.push(malformed(testFile, lineNumber, content));\n }\n\n return;\n }\n\n const trimmed = content.trim();\n\n if (trimmed === \"\" || trimmed.startsWith(\"//\")) return;\n\n if (TRAILING_PROOF.test(content)) findings.push(malformed(testFile, lineNumber, content));\n\n settle(TEST_CALL.test(trimmed) ? lineNumber : null);\n });\n\n settle(null);\n\n return { proofs, findings };\n}\n\n/**\n * Read the proof lines of every test file. Files that cannot be read (removed\n * since the book was built) are skipped. Proofs and findings come out in\n * file order, then line order.\n *\n * @param root Absolute project root.\n * @param testFiles Project-relative test files (`BookFacts.tests`).\n */\nexport async function scanProofs(\n root: string,\n testFiles: readonly string[],\n): Promise<ScanProofsResult> {\n const files = [...new Set(testFiles.map(toPosixPath))].sort();\n const results: ScanProofsResult[] = new Array(files.length);\n let next = 0;\n\n // A few reads at a time: opening thousands of test files at once fails with EMFILE, and a\n // failed read would drop that file's proofs without a word.\n const worker = async (): Promise<void> => {\n while (next < files.length) {\n const index = next++;\n const file = files[index] ?? \"\";\n\n try {\n results[index] = scanProofsInText(\n await readFile(path.join(root, ...file.split(\"/\")), \"utf8\"),\n file,\n );\n } catch {\n results[index] = { proofs: [], findings: [] };\n }\n }\n };\n\n await Promise.all(Array.from({ length: Math.min(READ_CONCURRENCY, files.length) }, worker));\n\n return {\n proofs: results.flatMap((result) => result.proofs),\n findings: results.flatMap((result) => result.findings),\n };\n}\n\nfunction malformed(file: string, line: number, content: string): GrimoireFinding {\n return createFinding({\n code: \"GR4003\",\n message: `\"${content.trim()}\" is not \"// @proves <feature>/<flow> AC-<n>\" on its own line`,\n at: { file, line, column: null },\n });\n}\n\n/**\n * Each line with its block comments (`/* … *\\/`, across lines) blanked out,\n * so a `@proves` or a test call inside a block comment is never read. Line\n * comments are kept. String contents are not considered.\n */\nfunction withoutBlockComments(lines: readonly string[]): string[] {\n let open = false;\n\n return lines.map((content) => {\n let code = \"\";\n let rest = content;\n\n while (rest !== \"\") {\n if (open) {\n const close = rest.indexOf(\"*/\");\n\n if (close === -1) return code;\n\n open = false;\n rest = rest.slice(close + 2);\n continue;\n }\n\n const block = rest.indexOf(\"/*\");\n const line = rest.indexOf(\"//\");\n\n if (block === -1 || (line !== -1 && line < block)) return code + rest;\n\n code += rest.slice(0, block);\n open = true;\n rest = rest.slice(block + 2);\n }\n\n return code;\n });\n}\n\n/**\n * The name of the test a call line declares: the first string literal of the\n * call that takes the name (after the arguments of `.each(…)`, `.skipIf(…)`…).\n * `null` when the line does not hold it (a name on the next line, a variable).\n */\nfunction testName(content: string): string | null {\n const call = TEST_CALL.exec(content.trim());\n\n if (!call) return null;\n\n let rest = content.trim().slice(call[0].length - 1);\n\n if (MODIFIER_WITH_ARGUMENTS.test(call[1] ?? \"\")) {\n const end = rest.startsWith(\"`\") ? closingQuote(rest, 0) : closingParen(rest);\n\n if (end === -1) return null;\n\n rest = rest.slice(end + 1).trimStart();\n }\n\n if (!rest.startsWith(\"(\")) return null;\n\n rest = rest.slice(1).trimStart();\n\n const quote = rest[0];\n\n if (quote !== '\"' && quote !== \"'\" && quote !== \"`\") return null;\n\n const end = closingQuote(rest, 0);\n\n return end === -1 ? null : rest.slice(1, end).replace(/\\\\(.)/g, \"$1\");\n}\n\n/** Index of the quote that closes the string opening at `start`, or -1. */\nfunction closingQuote(text: string, start: number): number {\n const quote = text[start];\n\n for (let index = start + 1; index < text.length; index++) {\n if (text[index] === \"\\\\\") index++;\n else if (text[index] === quote) return index;\n }\n\n return -1;\n}\n\n/** Index of the `)` that closes the `(` at index 0, skipping strings, or -1. */\nfunction closingParen(text: string): number {\n let depth = 0;\n\n for (let index = 0; index < text.length; index++) {\n const char = text[index];\n\n if (char === '\"' || char === \"'\" || char === \"`\") {\n index = closingQuote(text, index);\n\n if (index === -1) return -1;\n } else if (char === \"(\" || char === \"[\" || char === \"{\") {\n depth++;\n } else if (char === \")\" || char === \"]\" || char === \"}\") {\n depth--;\n\n if (depth === 0) return index;\n }\n }\n\n return -1;\n}\n"],"mappings":";;;;;;;AAeA,MAAM,mBAAmB;;AAGzB,MAAM,aAAa;;AAEnB,MAAM,iBAAiB;;AAEvB,MAAM,eAAe;;AAErB,MAAM,YACJ;;AAEF,MAAM,0BAA0B;;AAUhC,SAAgB,iBAAiB,MAAc,MAAgC;CAC7E,MAAM,WAAW,YAAY,IAAI;CAEjC,MAAM,OAAO,qBADC,KAAK,MAAM,OACa,CAAC;CACvC,MAAM,WAA8B,CAAC;CACrC,MAAM,SAAsB,CAAC;;CAE7B,IAAI,UAAyB,CAAC;CAE9B,MAAM,UAAU,aAAkC;EAChD,IAAI,QAAQ,WAAW,GAAG;EAE1B,MAAM,OACJ,aAAa,OAAO,OAAO;GAAE,MAAM,SAAS,KAAK,WAAW,MAAM,EAAE;GAAG,MAAM;EAAS;EAExF,KAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,MAAM,GAAG,MAAM,QAAQ,GAAG,MAAM;GACtC,MAAM,KAAK;IAAE,MAAM;IAAU,MAAM,MAAM;IAAM,QAAQ;GAAK;GAE5D,OAAO,KAAK;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AAI,KAAK,WAAW,OAAO,OAAO;CAGzC,OAAO;AACT;;AAGA,SAAS,aAAa,MAAsB;CAC1C,IAAI,QAAQ;CAEZ,KAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,QAAQ,SAAS;EAChD,MAAM,OAAO,KAAK;EAElB,IAAI,SAAS,QAAO,SAAS,OAAO,SAAS,KAAK;GAChD,QAAQ,aAAa,MAAM,KAAK;GAEhC,IAAI,UAAU,IAAI,OAAO;EAC3B,OAAO,IAAI,SAAS,OAAO,SAAS,OAAO,SAAS,KAClD;OACK,IAAI,SAAS,OAAO,SAAS,OAAO,SAAS,KAAK;GACvD;GAEA,IAAI,UAAU,GAAG,OAAO;EAC1B;CACF;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"scan-proofs.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/proves/scan-proofs.ts"],"sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { createFinding } from \"../codes\";\nimport type { GrimoireFinding } from \"../contracts/findings\";\nimport type { ProofLine } from \"../contracts/test-results\";\nimport { toPosixPath } from \"../paths\";\n\n/** What a scan returns. */\nexport type ScanProofsResult = {\n proofs: ProofLine[];\n /** `GR4003` (malformed line), `GR4004` (no test under it), `GR4005` (two proofs on one test). */\n findings: GrimoireFinding[];\n};\n\n/** How many test files `scanProofs` reads at once. */\nconst READ_CONCURRENCY = 32;\n\n/** A `// @proves …` line comment on its own line; group 1 is the rest of the line. */\nconst PROOF_LINE = /^\\s*\\/\\/\\s*@proves\\b(.*)$/;\n/** A `// @proves` comment after code on the same line. */\nconst TRAILING_PROOF = /\\S.*\\/\\/\\s*@proves\\b/;\n/** The rest of a well-formed proof line: ` <feature>/<flow> AC-<n>`. */\nconst PROOF_TARGET = /^\\s+([a-z0-9]+(?:-[a-z0-9]+)*)\\/([a-z0-9]+(?:-[a-z0-9]+)*)\\s+(AC-\\d+)\\s*$/;\n/** `it(`, `test(`, `it.only(`, `test.each(…)(`, `it.skipIf(…)(`, `` test.each` ``… */\nconst TEST_CALL =\n /^(?:it|test)((?:\\s*\\.\\s*(?:only|skip|todo|concurrent|sequential|fails|failing|each|for|skipIf|runIf|fixme|slow))*)\\s*[(`]/;\n/** Modifiers that take their own arguments before the test's call. */\nconst MODIFIER_WITH_ARGUMENTS = /\\.\\s*(?:each|for|skipIf|runIf)\\s*$/;\n\ntype ParsedProof = {\n feature: string;\n flow: string;\n criterion: string;\n line: number;\n};\n\n/** Read the proof lines of one test file's content. Pure. */\nexport function scanProofsInText(text: string, file: string): ScanProofsResult {\n const testFile = toPosixPath(file);\n const lines = text.split(/\\r?\\n/);\n const code = withoutBlockComments(lines);\n const findings: GrimoireFinding[] = [];\n const proofs: ProofLine[] = [];\n /** Proofs waiting for the next code line, in file order. */\n let pending: ParsedProof[] = [];\n\n const settle = (testLine: number | null): void => {\n if (pending.length === 0) return;\n\n const test =\n testLine === null ? null : { name: testName(code[testLine - 1] ?? \"\"), line: testLine };\n\n for (const proof of pending) {\n const ref = `${proof.feature}/${proof.flow}`;\n const at = { file: testFile, line: proof.line, column: null };\n\n proofs.push({\n feature: proof.feature,\n flow: proof.flow,\n ref,\n criterion: proof.criterion,\n test,\n at,\n });\n\n if (!test) {\n findings.push(\n createFinding({\n code: \"GR4004\",\n message: `\"@proves ${ref} ${proof.criterion}\" is not directly above a test`,\n at,\n feature: proof.feature,\n flow: ref,\n }),\n );\n }\n }\n\n const distinct = [\n ...new Set(pending.map((proof) => `${proof.feature}/${proof.flow} ${proof.criterion}`)),\n ];\n const first = pending[0];\n\n if (test && first && distinct.length > 1) {\n findings.push(\n createFinding({\n code: \"GR4005\",\n message: `test ${test.name === null ? `on line ${test.line}` : JSON.stringify(test.name)} proves ${distinct.length} criteria: ${distinct.join(\", \")}`,\n at: { file: testFile, line: first.line, column: null },\n feature: first.feature,\n flow: `${first.feature}/${first.flow}`,\n }),\n );\n }\n\n pending = [];\n };\n\n code.forEach((content, index) => {\n const lineNumber = index + 1;\n const proof = PROOF_LINE.exec(content);\n\n if (proof) {\n const target = PROOF_TARGET.exec(proof[1] ?? \"\");\n\n if (target) {\n pending.push({\n feature: target[1] ?? \"\",\n flow: target[2] ?? \"\",\n criterion: target[3] ?? \"\",\n line: lineNumber,\n });\n } else {\n findings.push(malformed(testFile, lineNumber, content));\n }\n\n return;\n }\n\n const trimmed = content.trim();\n\n if (trimmed === \"\" || trimmed.startsWith(\"//\")) return;\n\n if (TRAILING_PROOF.test(content)) findings.push(malformed(testFile, lineNumber, content));\n\n settle(TEST_CALL.test(trimmed) ? lineNumber : null);\n });\n\n settle(null);\n\n return { proofs, findings };\n}\n\n/**\n * Read the proof lines of every test file. Files that cannot be read (removed\n * since the book was built) are skipped. Proofs and findings come out in\n * file order, then line order.\n *\n * @param root Absolute project root.\n * @param testFiles Project-relative test files (`BookFacts.tests`).\n */\nexport async function scanProofs(\n root: string,\n testFiles: readonly string[],\n): Promise<ScanProofsResult> {\n const files = [...new Set(testFiles.map(toPosixPath))].sort();\n const results: ScanProofsResult[] = new Array(files.length);\n let next = 0;\n\n // A few reads at a time: opening thousands of test files at once fails with EMFILE, and a\n // failed read would drop that file's proofs without a word.\n const worker = async (): Promise<void> => {\n while (next < files.length) {\n const index = next++;\n const file = files[index] ?? \"\";\n\n try {\n results[index] = scanProofsInText(\n await readFile(path.join(root, ...file.split(\"/\")), \"utf8\"),\n file,\n );\n } catch {\n results[index] = { proofs: [], findings: [] };\n }\n }\n };\n\n await Promise.all(Array.from({ length: Math.min(READ_CONCURRENCY, files.length) }, worker));\n\n return {\n proofs: results.flatMap((result) => result.proofs),\n findings: results.flatMap((result) => result.findings),\n };\n}\n\nfunction malformed(file: string, line: number, content: string): GrimoireFinding {\n return createFinding({\n code: \"GR4003\",\n message: `\"${content.trim()}\" is not \"// @proves <feature>/<flow> AC-<n>\" on its own line`,\n at: { file, line, column: null },\n });\n}\n\n/**\n * Each line with its block comments (`/* … *\\/`, across lines) blanked out,\n * so a `@proves` or a test call inside a block comment is never read. Line\n * comments are kept. String contents are not considered.\n */\nexport function withoutBlockComments(lines: readonly string[]): string[] {\n let open = false;\n\n return lines.map((content) => {\n let code = \"\";\n let rest = content;\n\n while (rest !== \"\") {\n if (open) {\n const close = rest.indexOf(\"*/\");\n\n if (close === -1) return code;\n\n open = false;\n rest = rest.slice(close + 2);\n continue;\n }\n\n const block = rest.indexOf(\"/*\");\n const line = rest.indexOf(\"//\");\n\n if (block === -1 || (line !== -1 && line < block)) return code + rest;\n\n code += rest.slice(0, block);\n open = true;\n rest = rest.slice(block + 2);\n }\n\n return code;\n });\n}\n\n/**\n * The name of the test a call line declares: the first string literal of the\n * call that takes the name (after the arguments of `.each(…)`, `.skipIf(…)`…).\n * `null` when the line does not hold it (a name on the next line, a variable).\n */\nfunction testName(content: string): string | null {\n const call = TEST_CALL.exec(content.trim());\n\n if (!call) return null;\n\n let rest = content.trim().slice(call[0].length - 1);\n\n if (MODIFIER_WITH_ARGUMENTS.test(call[1] ?? \"\")) {\n const end = rest.startsWith(\"`\") ? closingQuote(rest, 0) : closingParen(rest);\n\n if (end === -1) return null;\n\n rest = rest.slice(end + 1).trimStart();\n }\n\n if (!rest.startsWith(\"(\")) return null;\n\n rest = rest.slice(1).trimStart();\n\n const quote = rest[0];\n\n if (quote !== '\"' && quote !== \"'\" && quote !== \"`\") return null;\n\n const end = closingQuote(rest, 0);\n\n return end === -1 ? null : rest.slice(1, end).replace(/\\\\(.)/g, \"$1\");\n}\n\n/** Index of the quote that closes the string opening at `start`, or -1. */\nfunction closingQuote(text: string, start: number): number {\n const quote = text[start];\n\n for (let index = start + 1; index < text.length; index++) {\n if (text[index] === \"\\\\\") index++;\n else if (text[index] === quote) return index;\n }\n\n return -1;\n}\n\n/** Index of the `)` that closes the `(` at index 0, skipping strings, or -1. */\nfunction closingParen(text: string): number {\n let depth = 0;\n\n for (let index = 0; index < text.length; index++) {\n const char = text[index];\n\n if (char === '\"' || char === \"'\" || char === \"`\") {\n index = closingQuote(text, index);\n\n if (index === -1) return -1;\n } else if (char === \"(\" || char === \"[\" || char === \"{\") {\n depth++;\n } else if (char === \")\" || char === \"]\" || char === \"}\") {\n depth--;\n\n if (depth === 0) return index;\n }\n }\n\n return -1;\n}\n"],"mappings":";;;;;;;AAeA,MAAM,mBAAmB;;AAGzB,MAAM,aAAa;;AAEnB,MAAM,iBAAiB;;AAEvB,MAAM,eAAe;;AAErB,MAAM,YACJ;;AAEF,MAAM,0BAA0B;;AAUhC,SAAgB,iBAAiB,MAAc,MAAgC;CAC7E,MAAM,WAAW,YAAY,IAAI;CAEjC,MAAM,OAAO,qBADC,KAAK,MAAM,OACa,CAAC;CACvC,MAAM,WAA8B,CAAC;CACrC,MAAM,SAAsB,CAAC;;CAE7B,IAAI,UAAyB,CAAC;CAE9B,MAAM,UAAU,aAAkC;EAChD,IAAI,QAAQ,WAAW,GAAG;EAE1B,MAAM,OACJ,aAAa,OAAO,OAAO;GAAE,MAAM,SAAS,KAAK,WAAW,MAAM,EAAE;GAAG,MAAM;EAAS;EAExF,KAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,MAAM,GAAG,MAAM,QAAQ,GAAG,MAAM;GACtC,MAAM,KAAK;IAAE,MAAM;IAAU,MAAM,MAAM;IAAM,QAAQ;GAAK;GAE5D,OAAO,KAAK;IACV,SAAS,MAAM;IACf,MAAM,MAAM;IACZ;IACA,WAAW,MAAM;IACjB;IACA;GACF,CAAC;GAED,IAAI,CAAC,MACH,SAAS,KACP,cAAc;IACZ,MAAM;IACN,SAAS,YAAY,IAAI,GAAG,MAAM,UAAU;IAC5C;IACA,SAAS,MAAM;IACf,MAAM;GACR,CAAC,CACH;EAEJ;EAEA,MAAM,WAAW,CACf,GAAG,IAAI,IAAI,QAAQ,KAAK,UAAU,GAAG,MAAM,QAAQ,GAAG,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,CACxF;EACA,MAAM,QAAQ,QAAQ;EAEtB,IAAI,QAAQ,SAAS,SAAS,SAAS,GACrC,SAAS,KACP,cA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;CAEA,OAAO;AACT"}
@@ -0,0 +1,21 @@
1
+ import { GrimoireFinding } from "../contracts/findings.mjs";
2
+ import { WrittenGrimoire } from "../contracts/written.mjs";
3
+ import { ShowsLine } from "../contracts/shots.mjs";
4
+ //#region ../../packages/grimoire/src/proves/scan-shows.d.ts
5
+ /** What a scan returns. */
6
+ export type ScanShowsResult = {
7
+ shows: ShowsLine[];
8
+ /** `GR4013` (wrong form, no matching `shows()` call) and `GR4014` (names no flow or criterion). */
9
+ findings: GrimoireFinding[];
10
+ };
11
+ /**
12
+ * Read the `@shows` lines of every test file. Files that cannot be read are
13
+ * skipped. Lines and findings come out in file order, then line order.
14
+ *
15
+ * @param root Absolute project root.
16
+ * @param testFiles Project-relative test files (`BookFacts.tests`).
17
+ * @param written The written grimoire; with it, a line naming no flow or criterion is `GR4014`.
18
+ */
19
+ export declare function scanShows(root: string, testFiles: readonly string[], written?: WrittenGrimoire): Promise<ScanShowsResult>;
20
+ //#endregion
21
+ //# sourceMappingURL=scan-shows.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scan-shows.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/proves/scan-shows.ts"],"mappings":";;;;;YAUY;EACV,OAAO;;EAEP,UAAU;;;;;;;;;;wBA6JU,UACpB,cACA,8BACA,UAAU,kBACT,QAAQ"}