@warlock.js/grimoire 5.63.1 → 5.65.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +61 -0
- package/esm/book/build.d.mts.map +1 -1
- package/esm/book/build.mjs +24 -2
- package/esm/book/build.mjs.map +1 -1
- package/esm/check/check-grimoire.d.mts.map +1 -1
- package/esm/check/check-grimoire.mjs +11 -1
- package/esm/check/check-grimoire.mjs.map +1 -1
- package/esm/check/rules/api-snapshot.mjs +39 -0
- package/esm/check/rules/api-snapshot.mjs.map +1 -0
- package/esm/check/rules/code-rules.mjs +45 -0
- package/esm/check/rules/code-rules.mjs.map +1 -0
- package/esm/check/rules/drift.mjs +54 -0
- package/esm/check/rules/drift.mjs.map +1 -0
- package/esm/check/rules/focused-tests.mjs +39 -0
- package/esm/check/rules/focused-tests.mjs.map +1 -0
- package/esm/check/rules/shows.mjs +52 -0
- package/esm/check/rules/shows.mjs.map +1 -0
- package/esm/codes/codes.d.mts +48 -0
- package/esm/codes/codes.d.mts.map +1 -1
- package/esm/codes/codes.mjs +26 -1
- package/esm/codes/codes.mjs.map +1 -1
- package/esm/contracts/adapter.d.mts +6 -0
- package/esm/contracts/adapter.d.mts.map +1 -1
- package/esm/contracts/guard.d.mts +104 -0
- package/esm/contracts/guard.d.mts.map +1 -0
- package/esm/contracts/index.mjs +5 -0
- package/esm/contracts/matrix.d.mts +75 -0
- package/esm/contracts/matrix.d.mts.map +1 -0
- package/esm/contracts/scry.d.mts +42 -0
- package/esm/contracts/scry.d.mts.map +1 -1
- package/esm/contracts/settings.d.mts +71 -0
- package/esm/contracts/settings.d.mts.map +1 -0
- package/esm/contracts/settings.mjs +67 -0
- package/esm/contracts/settings.mjs.map +1 -0
- package/esm/contracts/shots.d.mts +146 -0
- package/esm/contracts/shots.d.mts.map +1 -0
- package/esm/contracts/snapshot.d.mts +10 -0
- package/esm/contracts/snapshot.d.mts.map +1 -1
- package/esm/contracts/written.d.mts +13 -0
- package/esm/contracts/written.d.mts.map +1 -1
- package/esm/contracts/written.mjs +7 -1
- package/esm/contracts/written.mjs.map +1 -1
- package/esm/devtools/approvals.mjs +59 -0
- package/esm/devtools/approvals.mjs.map +1 -0
- package/esm/devtools/data.mjs +2 -0
- package/esm/devtools/data.mjs.map +1 -1
- package/esm/devtools/graphs.mjs +13 -3
- package/esm/devtools/graphs.mjs.map +1 -1
- package/esm/devtools/index.d.mts +7 -0
- package/esm/devtools/index.d.mts.map +1 -1
- package/esm/devtools/index.mjs +33 -3
- package/esm/devtools/index.mjs.map +1 -1
- package/esm/devtools/matrix.mjs +207 -0
- package/esm/devtools/matrix.mjs.map +1 -0
- package/esm/devtools/product-map.d.mts.map +1 -1
- package/esm/devtools/product-map.mjs +87 -1
- package/esm/devtools/product-map.mjs.map +1 -1
- package/esm/devtools/site.d.mts.map +1 -1
- package/esm/devtools/site.mjs +12 -3
- package/esm/devtools/site.mjs.map +1 -1
- package/esm/devtools/snapshot-source.mjs +13 -3
- package/esm/devtools/snapshot-source.mjs.map +1 -1
- package/esm/git/index.d.mts +20 -0
- package/esm/git/index.d.mts.map +1 -0
- package/esm/git/index.mjs +280 -0
- package/esm/git/index.mjs.map +1 -0
- package/esm/guard/api.mjs +70 -0
- package/esm/guard/api.mjs.map +1 -0
- package/esm/guard/assertions.mjs +18 -0
- package/esm/guard/assertions.mjs.map +1 -0
- package/esm/guard/collect.mjs +139 -0
- package/esm/guard/collect.mjs.map +1 -0
- package/esm/guard/format.mjs +27 -0
- package/esm/guard/format.mjs.map +1 -0
- package/esm/guard/glob.mjs +79 -0
- package/esm/guard/glob.mjs.map +1 -0
- package/esm/guard/index.mjs +9 -0
- package/esm/guard/rules.mjs +310 -0
- package/esm/guard/rules.mjs.map +1 -0
- package/esm/guard/scope.mjs +95 -0
- package/esm/guard/scope.mjs.map +1 -0
- package/esm/index.d.mts +10 -3
- package/esm/index.mjs +6 -2
- package/esm/paths/index.d.mts +15 -1
- package/esm/paths/index.d.mts.map +1 -1
- package/esm/paths/index.mjs +27 -3
- package/esm/paths/index.mjs.map +1 -1
- package/esm/proves/index.mjs +2 -1
- package/esm/proves/scan-proofs.mjs +1 -1
- package/esm/proves/scan-proofs.mjs.map +1 -1
- package/esm/proves/scan-shows.d.mts +21 -0
- package/esm/proves/scan-shows.d.mts.map +1 -0
- package/esm/proves/scan-shows.mjs +168 -0
- package/esm/proves/scan-shows.mjs.map +1 -0
- package/esm/releases/index.d.mts.map +1 -1
- package/esm/releases/index.mjs +5 -3
- package/esm/releases/index.mjs.map +1 -1
- package/esm/releases/stamp.mjs +121 -0
- package/esm/releases/stamp.mjs.map +1 -0
- package/esm/rules/focused.mjs +26 -0
- package/esm/rules/focused.mjs.map +1 -0
- package/esm/rules/index.mjs +88 -0
- package/esm/rules/index.mjs.map +1 -0
- package/esm/rules/logical-css.mjs +112 -0
- package/esm/rules/logical-css.mjs.map +1 -0
- package/esm/rules/no-js-imports.mjs +22 -0
- package/esm/rules/no-js-imports.mjs.map +1 -0
- package/esm/rules/scan.mjs +196 -0
- package/esm/rules/scan.mjs.map +1 -0
- package/esm/rules/specific-errors.mjs +51 -0
- package/esm/rules/specific-errors.mjs.map +1 -0
- package/esm/rules/type-discriminator.mjs +27 -0
- package/esm/rules/type-discriminator.mjs.map +1 -0
- package/esm/scry/also-changes.mjs +107 -0
- package/esm/scry/also-changes.mjs.map +1 -0
- package/esm/scry/format.d.mts.map +1 -1
- package/esm/scry/format.mjs +35 -0
- package/esm/scry/format.mjs.map +1 -1
- package/esm/scry/query.d.mts.map +1 -1
- package/esm/scry/query.mjs +40 -2
- package/esm/scry/query.mjs.map +1 -1
- package/esm/scry/search.d.mts.map +1 -1
- package/esm/scry/search.mjs +43 -11
- package/esm/scry/search.mjs.map +1 -1
- package/esm/shots/approve.mjs +195 -0
- package/esm/shots/approve.mjs.map +1 -0
- package/esm/shots/drift.mjs +174 -0
- package/esm/shots/drift.mjs.map +1 -0
- package/esm/shots/png.mjs +166 -0
- package/esm/shots/png.mjs.map +1 -0
- package/esm/shots/state.mjs +43 -0
- package/esm/shots/state.mjs.map +1 -0
- package/esm/shots/store.mjs +66 -0
- package/esm/shots/store.mjs.map +1 -0
- package/esm/shots/touched.mjs +38 -0
- package/esm/shots/touched.mjs.map +1 -0
- package/esm/warlock/adapter.d.mts.map +1 -1
- package/esm/warlock/adapter.mjs +22 -2
- package/esm/warlock/adapter.mjs.map +1 -1
- package/esm/warlock/api-command.mjs +41 -0
- package/esm/warlock/api-command.mjs.map +1 -0
- package/esm/warlock/approve-command.mjs +80 -0
- package/esm/warlock/approve-command.mjs.map +1 -0
- package/esm/warlock/collect-off-thread.mjs +66 -0
- package/esm/warlock/collect-off-thread.mjs.map +1 -0
- package/esm/warlock/commands.d.mts +1 -1
- package/esm/warlock/commands.d.mts.map +1 -1
- package/esm/warlock/commands.mjs +61 -8
- package/esm/warlock/commands.mjs.map +1 -1
- package/esm/warlock/guard-command.mjs +116 -0
- package/esm/warlock/guard-command.mjs.map +1 -0
- package/esm/warlock/index.d.mts +2 -1
- package/esm/warlock/index.mjs +2 -1
- package/esm/warlock/languages.mjs +75 -0
- package/esm/warlock/languages.mjs.map +1 -0
- package/esm/warlock/mcp-tools.mjs +2 -2
- package/esm/warlock/mcp-tools.mjs.map +1 -1
- package/esm/warlock/release-command.mjs +65 -0
- package/esm/warlock/release-command.mjs.map +1 -0
- package/esm/warlock/shows.d.mts +35 -0
- package/esm/warlock/shows.d.mts.map +1 -0
- package/esm/warlock/shows.mjs +195 -0
- package/esm/warlock/shows.mjs.map +1 -0
- package/esm/workspace/cache.mjs +4 -1
- package/esm/workspace/cache.mjs.map +1 -1
- package/esm/workspace/derived.mjs +11 -6
- package/esm/workspace/derived.mjs.map +1 -1
- package/esm/workspace/index.d.mts.map +1 -1
- package/esm/workspace/index.mjs +8 -1
- package/esm/workspace/index.mjs.map +1 -1
- package/esm/workspace/stored.mjs +4 -1
- package/esm/workspace/stored.mjs.map +1 -1
- package/esm/written/features.mjs +21 -5
- package/esm/written/features.mjs.map +1 -1
- package/esm/written/index.mjs +2 -1
- package/esm/written/parse-grimoire.d.mts.map +1 -1
- package/esm/written/parse-grimoire.mjs +16 -3
- package/esm/written/parse-grimoire.mjs.map +1 -1
- package/esm/written/settings.d.mts +11 -0
- package/esm/written/settings.d.mts.map +1 -0
- package/esm/written/settings.mjs +88 -0
- package/esm/written/settings.mjs.map +1 -0
- package/llms-full.txt +282 -39
- package/llms.txt +2 -0
- package/package.json +3 -3
- package/skills/backfill-a-grimoire/SKILL.md +4 -0
- package/skills/describe-an-app/SKILL.md +4 -1
- package/skills/guard-a-change/SKILL.md +85 -0
- package/skills/index.md +7 -3
- package/skills/record-a-change/SKILL.md +52 -16
- package/skills/review-a-change/SKILL.md +53 -0
- package/skills/use-the-grimoire/SKILL.md +27 -18
- package/skills/write-a-feature/SKILL.md +42 -1
- package/ui/grimoire-view.js +756 -40
- package/ui/grimoire.css +303 -28
- package/ui/product-map.css +43 -7
- package/ui/product-map.js +212 -37
package/esm/paths/index.mjs
CHANGED
|
@@ -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 (`` 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
|
package/esm/paths/index.mjs.map
CHANGED
|
@@ -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 (`` 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;CACN,OAAO;CACP,WAAW;CACX,WAAW;;CAEX,YAAY;CACZ,UAAU;;CAEV,aAAa;AACf;;AAGA,MAAa,wBAAwB;CACnC;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,iBAAiB;;AAGvB,SAAgB,YAAY,MAAsB;CAChD,OAAO,KAAK,MAAM,IAAI,CAAC,CAAC,KAAK,GAAG;AAClC;;AAGA,SAAgB,YAAY,MAAc,MAAsB;CAC9D,OAAO,YAAY,KAAK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../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 (`` 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,gBAAgB;;CAEhB,YAAY;;CAEZ,aAAa;;CAEb,YAAY;CACZ,UAAU;;CAEV,eAAe;CACf,MAAM;CACN,OAAO;CACP,WAAW;CACX,WAAW;;CAEX,YAAY;CACZ,UAAU;;CAEV,aAAa;;CAEb,UAAU;;CAEV,UAAU;;CAEV,UAAU;;CAEV,aAAa;;CAEb,eAAe;;CAEf,eAAe;;CAEf,cAAc;AAChB;;AAGA,MAAa,wBAAwB;CACnC;CACA;CACA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AO,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"}
|
package/esm/proves/index.mjs
CHANGED
|
@@ -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":";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AAE,GAAG;EAC/C,MAAM,MAAM,KAAK,WAAW,GAAG,IAAI,aAAa,MAAM,CAAC,IAAI,aAAa,IAAI;EAE5E,IAAI,QAAQ,IAAI,OAAO;EAEvB,OAAO,KAAK,MAAM,MAAM,CAAC,CAAC,CAAC,UAAU;CACvC;CAEA,IAAI,CAAC,KAAK,WAAW,GAAG,GAAG,OAAO;CAElC,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,UAAU;CAE/B,MAAM,QAAQ,KAAK;CAEnB,IAAI,UAAU,QAAO,UAAU,OAAO,UAAU,KAAK,OAAO;CAE5D,MAAM,MAAM,aAAa,MAAM,CAAC;CAEhC,OAAO,QAAQ,KAAK,OAAO,KAAK,MAAM,GAAG,GAAG,CAAC,CAAC,QAAQ,UAAU,IAAI;AACtE;;AAGA,SAAS,aAAa,MAAc,OAAuB;CACzD,MAAM,QAAQ,KAAK;CAEnB,KAAK,IAAI,QAAQ,QAAQ,GAAG,QAAQ,KAAK,QAAQ,SAC/C,IAAI,KAAK,WAAW,MAAM;MACrB,IAAI,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,MA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O,KAAK,MAAM,GAAG,GAAG,CAAC,CAAC,QAAQ,UAAU,IAAI;AACtE;;AAGA,SAAS,aAAa,MAAc,OAAuB;CACzD,MAAM,QAAQ,KAAK;CAEnB,KAAK,IAAI,QAAQ,QAAQ,GAAG,QAAQ,KAAK,QAAQ,SAC/C,IAAI,KAAK,WAAW,MAAM;MACrB,IAAI,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"}
|
|
@@ -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"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { createFinding } from "../codes/index.mjs";
|
|
2
|
+
import { toPosixPath } from "../paths/index.mjs";
|
|
3
|
+
import { withoutBlockComments } from "./scan-proofs.mjs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { readFile } from "node:fs/promises";
|
|
6
|
+
|
|
7
|
+
//#region ../../packages/grimoire/src/proves/scan-shows.ts
|
|
8
|
+
const READ_CONCURRENCY = 32;
|
|
9
|
+
/** A `// @shows …` line comment on its own line; group 1 is the rest of the line. */
|
|
10
|
+
const SHOWS_LINE = /^\s*\/\/\s*@shows\b(.*)$/;
|
|
11
|
+
/** A `// @shows` comment after code on the same line. */
|
|
12
|
+
const TRAILING_SHOWS = /\S.*\/\/\s*@shows\b/;
|
|
13
|
+
/** The rest of a well-formed line: ` <feature>/<flow> AC-<n>`. */
|
|
14
|
+
const SHOWS_TARGET = /^\s+([a-z0-9]+(?:-[a-z0-9]+)*)\/([a-z0-9]+(?:-[a-z0-9]+)*)\s+(AC-\d+)\s*$/;
|
|
15
|
+
/** The start of a `shows(` call: `shows(`, `await shows(`, `grimoire.shows(`. */
|
|
16
|
+
const SHOWS_CALL = /^(?:await\s+)?(?:[A-Za-z_$][\w$]*\s*\.\s*)?shows\s*\(/;
|
|
17
|
+
/** The first string argument after the first argument (`context`). */
|
|
18
|
+
const CALL_REF = /^[^,]*,\s*(["'`])([^"'`]*)\1/;
|
|
19
|
+
/** How many lines a call's first arguments may span. */
|
|
20
|
+
const CALL_LOOKAHEAD = 6;
|
|
21
|
+
/** The criteria of every flow of a written grimoire. */
|
|
22
|
+
function knownCriteria(written) {
|
|
23
|
+
const known = /* @__PURE__ */ new Map();
|
|
24
|
+
for (const feature of written.features) for (const flow of feature.flows) known.set(flow.ref, new Set(flow.criteria.map((criterion) => criterion.id)));
|
|
25
|
+
return known;
|
|
26
|
+
}
|
|
27
|
+
/** Read the `@shows` lines of one test file's content. Pure. */
|
|
28
|
+
function scanShowsInText(text, file, known) {
|
|
29
|
+
const testFile = toPosixPath(file);
|
|
30
|
+
const code = withoutBlockComments(text.split(/\r?\n/));
|
|
31
|
+
const findings = [];
|
|
32
|
+
const shows = [];
|
|
33
|
+
let pending = null;
|
|
34
|
+
const settle = (callLine) => {
|
|
35
|
+
if (pending === null) return;
|
|
36
|
+
const { feature, flow, criterion, line } = pending;
|
|
37
|
+
const ref = `${feature}/${flow}`;
|
|
38
|
+
const at = {
|
|
39
|
+
file: testFile,
|
|
40
|
+
line,
|
|
41
|
+
column: null
|
|
42
|
+
};
|
|
43
|
+
pending = null;
|
|
44
|
+
if (known !== void 0) {
|
|
45
|
+
const criteria = known.get(ref);
|
|
46
|
+
if (criteria === void 0 || !criteria.has(criterion)) {
|
|
47
|
+
findings.push(createFinding({
|
|
48
|
+
code: "GR4014",
|
|
49
|
+
message: criteria === void 0 ? `"@shows ${ref} ${criterion}" names a flow that does not exist` : `"@shows ${ref} ${criterion}" names a criterion the flow does not have`,
|
|
50
|
+
at,
|
|
51
|
+
feature,
|
|
52
|
+
flow: ref
|
|
53
|
+
}));
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
let call = null;
|
|
58
|
+
if (callLine !== null) {
|
|
59
|
+
const named = callRef(code, callLine - 1);
|
|
60
|
+
if (named === `${ref} ${criterion}`) call = { line: callLine };
|
|
61
|
+
else findings.push(createFinding({
|
|
62
|
+
code: "GR4013",
|
|
63
|
+
message: named === null ? `"@shows ${ref} ${criterion}" is not directly above a shows() call that names "${ref} ${criterion}"` : `"@shows ${ref} ${criterion}" is above a shows() call that names ${JSON.stringify(named)}`,
|
|
64
|
+
at,
|
|
65
|
+
feature,
|
|
66
|
+
flow: ref
|
|
67
|
+
}));
|
|
68
|
+
} else findings.push(createFinding({
|
|
69
|
+
code: "GR4013",
|
|
70
|
+
message: `"@shows ${ref} ${criterion}" is not directly above a shows() call`,
|
|
71
|
+
at,
|
|
72
|
+
feature,
|
|
73
|
+
flow: ref
|
|
74
|
+
}));
|
|
75
|
+
shows.push({
|
|
76
|
+
feature,
|
|
77
|
+
flow,
|
|
78
|
+
ref,
|
|
79
|
+
criterion,
|
|
80
|
+
call,
|
|
81
|
+
at
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
code.forEach((content, index) => {
|
|
85
|
+
const lineNumber = index + 1;
|
|
86
|
+
const match = SHOWS_LINE.exec(content);
|
|
87
|
+
if (match) {
|
|
88
|
+
settle(null);
|
|
89
|
+
const target = SHOWS_TARGET.exec(match[1] ?? "");
|
|
90
|
+
if (target) pending = {
|
|
91
|
+
feature: target[1] ?? "",
|
|
92
|
+
flow: target[2] ?? "",
|
|
93
|
+
criterion: target[3] ?? "",
|
|
94
|
+
line: lineNumber
|
|
95
|
+
};
|
|
96
|
+
else findings.push(malformed(testFile, lineNumber, content));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const trimmed = content.trim();
|
|
100
|
+
if (trimmed === "" || trimmed.startsWith("//")) return;
|
|
101
|
+
if (TRAILING_SHOWS.test(content)) findings.push(malformed(testFile, lineNumber, content));
|
|
102
|
+
settle(SHOWS_CALL.test(trimmed) ? lineNumber : null);
|
|
103
|
+
});
|
|
104
|
+
settle(null);
|
|
105
|
+
return {
|
|
106
|
+
shows,
|
|
107
|
+
findings
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Read the `@shows` lines of every test file. Files that cannot be read are
|
|
112
|
+
* skipped. Lines and findings come out in file order, then line order.
|
|
113
|
+
*
|
|
114
|
+
* @param root Absolute project root.
|
|
115
|
+
* @param testFiles Project-relative test files (`BookFacts.tests`).
|
|
116
|
+
* @param written The written grimoire; with it, a line naming no flow or criterion is `GR4014`.
|
|
117
|
+
*/
|
|
118
|
+
async function scanShows(root, testFiles, written) {
|
|
119
|
+
const files = [...new Set(testFiles.map(toPosixPath))].sort();
|
|
120
|
+
const known = written === void 0 ? void 0 : knownCriteria(written);
|
|
121
|
+
const results = new Array(files.length);
|
|
122
|
+
let next = 0;
|
|
123
|
+
const worker = async () => {
|
|
124
|
+
while (next < files.length) {
|
|
125
|
+
const index = next++;
|
|
126
|
+
const file = files[index] ?? "";
|
|
127
|
+
try {
|
|
128
|
+
const content = await readFile(path.join(root, ...file.split("/")), "utf8");
|
|
129
|
+
results[index] = content.includes("@shows") ? scanShowsInText(content, file, known) : {
|
|
130
|
+
shows: [],
|
|
131
|
+
findings: []
|
|
132
|
+
};
|
|
133
|
+
} catch {
|
|
134
|
+
results[index] = {
|
|
135
|
+
shows: [],
|
|
136
|
+
findings: []
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
await Promise.all(Array.from({ length: Math.min(READ_CONCURRENCY, files.length) }, worker));
|
|
142
|
+
return {
|
|
143
|
+
shows: results.flatMap((result) => result.shows),
|
|
144
|
+
findings: results.flatMap((result) => result.findings)
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/** The ref string the `shows(` call that starts at `code[start]` names, or `null`. */
|
|
148
|
+
function callRef(code, start) {
|
|
149
|
+
const joined = code.slice(start, start + CALL_LOOKAHEAD).join("\n").trim();
|
|
150
|
+
const open = SHOWS_CALL.exec(joined);
|
|
151
|
+
if (!open) return null;
|
|
152
|
+
return CALL_REF.exec(joined.slice(open[0].length))?.[2] ?? null;
|
|
153
|
+
}
|
|
154
|
+
function malformed(file, line, content) {
|
|
155
|
+
return createFinding({
|
|
156
|
+
code: "GR4013",
|
|
157
|
+
message: `"${content.trim()}" is not "// @shows <feature>/<flow> AC-<n>" on its own line`,
|
|
158
|
+
at: {
|
|
159
|
+
file,
|
|
160
|
+
line,
|
|
161
|
+
column: null
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
//#endregion
|
|
167
|
+
export { knownCriteria, scanShows, scanShowsInText };
|
|
168
|
+
//# sourceMappingURL=scan-shows.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scan-shows.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/proves/scan-shows.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 { ShowsLine } from \"../contracts/shots\";\nimport type { WrittenGrimoire } from \"../contracts/written\";\nimport { toPosixPath } from \"../paths\";\nimport { withoutBlockComments } from \"./scan-proofs\";\n\n/** What a scan returns. */\nexport type ScanShowsResult = {\n shows: ShowsLine[];\n /** `GR4013` (wrong form, no matching `shows()` call) and `GR4014` (names no flow or criterion). */\n findings: GrimoireFinding[];\n};\n\n/** The criteria each flow has, by `<feature>/<flow>`; the scanner reports `GR4014` for a line outside it. */\nexport type KnownCriteria = ReadonlyMap<string, ReadonlySet<string>>;\n\nconst READ_CONCURRENCY = 32;\n\n/** A `// @shows …` line comment on its own line; group 1 is the rest of the line. */\nconst SHOWS_LINE = /^\\s*\\/\\/\\s*@shows\\b(.*)$/;\n/** A `// @shows` comment after code on the same line. */\nconst TRAILING_SHOWS = /\\S.*\\/\\/\\s*@shows\\b/;\n/** The rest of a well-formed line: ` <feature>/<flow> AC-<n>`. */\nconst SHOWS_TARGET = /^\\s+([a-z0-9]+(?:-[a-z0-9]+)*)\\/([a-z0-9]+(?:-[a-z0-9]+)*)\\s+(AC-\\d+)\\s*$/;\n/** The start of a `shows(` call: `shows(`, `await shows(`, `grimoire.shows(`. */\nconst SHOWS_CALL = /^(?:await\\s+)?(?:[A-Za-z_$][\\w$]*\\s*\\.\\s*)?shows\\s*\\(/;\n/** The first string argument after the first argument (`context`). */\nconst CALL_REF = /^[^,]*,\\s*([\"'`])([^\"'`]*)\\1/;\n/** How many lines a call's first arguments may span. */\nconst CALL_LOOKAHEAD = 6;\n\n/** The criteria of every flow of a written grimoire. */\nexport function knownCriteria(written: WrittenGrimoire): KnownCriteria {\n const known = new Map<string, Set<string>>();\n\n for (const feature of written.features) {\n for (const flow of feature.flows) {\n known.set(flow.ref, new Set(flow.criteria.map((criterion) => criterion.id)));\n }\n }\n\n return known;\n}\n\n/** Read the `@shows` lines of one test file's content. Pure. */\nexport function scanShowsInText(\n text: string,\n file: string,\n known?: KnownCriteria,\n): ScanShowsResult {\n const testFile = toPosixPath(file);\n const code = withoutBlockComments(text.split(/\\r?\\n/));\n const findings: GrimoireFinding[] = [];\n const shows: ShowsLine[] = [];\n let pending: { feature: string; flow: string; criterion: string; line: number } | null = null;\n\n const settle = (callLine: number | null): void => {\n if (pending === null) return;\n\n const { feature, flow, criterion, line } = pending;\n const ref = `${feature}/${flow}`;\n const at = { file: testFile, line, column: null };\n\n pending = null;\n\n if (known !== undefined) {\n const criteria = known.get(ref);\n\n if (criteria === undefined || !criteria.has(criterion)) {\n findings.push(\n createFinding({\n code: \"GR4014\",\n message:\n criteria === undefined\n ? `\"@shows ${ref} ${criterion}\" names a flow that does not exist`\n : `\"@shows ${ref} ${criterion}\" names a criterion the flow does not have`,\n at,\n feature,\n flow: ref,\n }),\n );\n\n return;\n }\n }\n\n let call: { line: number } | null = null;\n\n if (callLine !== null) {\n const named = callRef(code, callLine - 1);\n\n if (named === `${ref} ${criterion}`) call = { line: callLine };\n else {\n findings.push(\n createFinding({\n code: \"GR4013\",\n message:\n named === null\n ? `\"@shows ${ref} ${criterion}\" is not directly above a shows() call that names \"${ref} ${criterion}\"`\n : `\"@shows ${ref} ${criterion}\" is above a shows() call that names ${JSON.stringify(named)}`,\n at,\n feature,\n flow: ref,\n }),\n );\n }\n } else {\n findings.push(\n createFinding({\n code: \"GR4013\",\n message: `\"@shows ${ref} ${criterion}\" is not directly above a shows() call`,\n at,\n feature,\n flow: ref,\n }),\n );\n }\n\n shows.push({ feature, flow, ref, criterion, call, at });\n };\n\n code.forEach((content, index) => {\n const lineNumber = index + 1;\n const match = SHOWS_LINE.exec(content);\n\n if (match) {\n // A second line stacked above the same call: the first has no call of its own.\n settle(null);\n\n const target = SHOWS_TARGET.exec(match[1] ?? \"\");\n\n if (target) {\n pending = {\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_SHOWS.test(content)) findings.push(malformed(testFile, lineNumber, content));\n\n settle(SHOWS_CALL.test(trimmed) ? lineNumber : null);\n });\n\n settle(null);\n\n return { shows, findings };\n}\n\n/**\n * Read the `@shows` lines of every test file. Files that cannot be read are\n * skipped. Lines and findings come out in file order, then line order.\n *\n * @param root Absolute project root.\n * @param testFiles Project-relative test files (`BookFacts.tests`).\n * @param written The written grimoire; with it, a line naming no flow or criterion is `GR4014`.\n */\nexport async function scanShows(\n root: string,\n testFiles: readonly string[],\n written?: WrittenGrimoire,\n): Promise<ScanShowsResult> {\n const files = [...new Set(testFiles.map(toPosixPath))].sort();\n const known = written === undefined ? undefined : knownCriteria(written);\n const results: ScanShowsResult[] = new Array(files.length);\n let next = 0;\n\n const worker = async (): Promise<void> => {\n while (next < files.length) {\n const index = next++;\n const file = files[index] ?? \"\";\n\n try {\n const content = await readFile(path.join(root, ...file.split(\"/\")), \"utf8\");\n\n // Most test files never mention it; skip the line scan for them.\n results[index] = content.includes(\"@shows\")\n ? scanShowsInText(content, file, known)\n : { shows: [], findings: [] };\n } catch {\n results[index] = { shows: [], findings: [] };\n }\n }\n };\n\n await Promise.all(Array.from({ length: Math.min(READ_CONCURRENCY, files.length) }, worker));\n\n return {\n shows: results.flatMap((result) => result.shows),\n findings: results.flatMap((result) => result.findings),\n };\n}\n\n/** The ref string the `shows(` call that starts at `code[start]` names, or `null`. */\nfunction callRef(code: readonly string[], start: number): string | null {\n const joined = code\n .slice(start, start + CALL_LOOKAHEAD)\n .join(\"\\n\")\n .trim();\n const open = SHOWS_CALL.exec(joined);\n\n if (!open) return null;\n\n return CALL_REF.exec(joined.slice(open[0].length))?.[2] ?? null;\n}\n\nfunction malformed(file: string, line: number, content: string): GrimoireFinding {\n return createFinding({\n code: \"GR4013\",\n message: `\"${content.trim()}\" is not \"// @shows <feature>/<flow> AC-<n>\" on its own line`,\n at: { file, line, column: null },\n });\n}\n"],"mappings":";;;;;;;AAmBA,MAAM,mBAAmB;;AAGzB,MAAM,aAAa;;AAEnB,MAAM,iBAAiB;;AAEvB,MAAM,eAAe;;AAErB,MAAM,aAAa;;AAEnB,MAAM,WAAW;;AAEjB,MAAM,iBAAiB;;AAGvB,SAAgB,cAAc,SAAyC;CACrE,MAAM,wBAAQ,IAAI,IAAyB;CAE3C,KAAK,MAAM,WAAW,QAAQ,UAC5B,KAAK,MAAM,QAAQ,QAAQ,OACzB,MAAM,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,SAAS,KAAK,cAAc,UAAU,EAAE,CAAC,CAAC;CAI/E,OAAO;AACT;;AAGA,SAAgB,gBACd,MACA,MACA,OACiB;CACjB,MAAM,WAAW,YAAY,IAAI;CACjC,MAAM,OAAO,qBAAqB,KAAK,MAAM,OAAO,CAAC;CACrD,MAAM,WAA8B,CAAC;CACrC,MAAM,QAAqB,CAAC;CAC5B,IAAI,UAAqF;CAEzF,MAAM,UAAU,aA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C/C,UAAU,QAAQ,SAAS,WAAW,OAAO,QAAQ;CACvD;AACF;;AAGA,SAAS,QAAQ,MAAyB,OAA8B;CACtE,MAAM,SAAS,KACZ,MAAM,OAAO,QAAQ,cAAc,CAAC,CACpC,KAAK,IAAI,CAAC,CACV,KAAK;CACR,MAAM,OAAO,WAAW,KAAK,MAAM;CAEnC,IAAI,CAAC,MAAM,OAAO;CAElB,OAAO,SAAS,KAAK,OAAO,MAAM,KAAK,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM;AAC7D;AAEA,SAAS,UAAU,MAAc,MAAc,SAAkC;CAC/E,OAAO,cAAc;EACnB,MAAM;EACN,SAAS,IAAI,QAAQ,KAAK,EAAE;EAC5B,IAAI;GAAE;GAAM;GAAM,QAAQ;EAAK;CACjC,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/releases/index.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/releases/index.ts"],"mappings":";;;;YA0BY,sBAAsB;;EAEhC,YAAY;;;;;;;;;wBA0DE,eAAe,SAAS,iBAAiB,kBAAkB;;wBA0C3D,oBAAoB,YAAY;;;;;;;;;wBAiC1B,aACpB,cACA,SAAS,iBACT,kBACC,QAAQ"}
|
package/esm/releases/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { COLLECTED_END_MARKER, COLLECTED_START_MARKER } from "../contracts/written.mjs";
|
|
2
2
|
import { GrimoireError, createFinding } from "../codes/index.mjs";
|
|
3
3
|
import { releaseFilePath } from "../paths/index.mjs";
|
|
4
|
+
import { applyStamp, planStamp } from "./stamp.mjs";
|
|
4
5
|
import path from "node:path";
|
|
5
6
|
import { readFile, writeFile } from "node:fs/promises";
|
|
6
7
|
|
|
@@ -9,8 +10,9 @@ import { readFile, writeFile } from "node:fs/promises";
|
|
|
9
10
|
* Releases: collecting the changelog entries the agent stamped with a release
|
|
10
11
|
* into `grimoire/releases/<release>.md`, and the GR6001–GR6003 rules.
|
|
11
12
|
*
|
|
12
|
-
*
|
|
13
|
-
* the text between the collected-list markers of the release file.
|
|
13
|
+
* Collecting never edits a feature changelog or the agent's brief: it writes only
|
|
14
|
+
* the text between the collected-list markers of the release file. Stamping
|
|
15
|
+
* (`stamp.ts`, only on `--stamp`) is the one edit Warlock makes to written files.
|
|
14
16
|
*/
|
|
15
17
|
function findRelease(written, release) {
|
|
16
18
|
return written.releases.find((item) => item.release.value === release);
|
|
@@ -153,5 +155,5 @@ function checkReleases(snapshot) {
|
|
|
153
155
|
}
|
|
154
156
|
|
|
155
157
|
//#endregion
|
|
156
|
-
export { checkReleases, collectRelease, renderCollectedList, unreleasedEntries, writeRelease };
|
|
158
|
+
export { applyStamp, checkReleases, collectRelease, planStamp, renderCollectedList, unreleasedEntries, writeRelease };
|
|
157
159
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/releases/index.ts"],"sourcesContent":["/**\n * Releases: collecting the changelog entries the agent stamped with a release\n * into `grimoire/releases/<release>.md`, and the GR6001–GR6003 rules.\n *\n * Warlock never edits a feature changelog or the agent's brief. It writes only\n * the text between the collected-list markers of the release file.\n */\nimport { readFile, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { GrimoireError, createFinding } from \"../codes\";\nimport type { GrimoireFinding } from \"../contracts/findings\";\nimport type { ReleaseCollection, ReleaseEntry, WriteReleaseResult } from \"../contracts/releases\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport {\n COLLECTED_END_MARKER,\n COLLECTED_START_MARKER,\n type WrittenChangelogEntry,\n type WrittenGrimoire,\n type WrittenRelease,\n} from \"../contracts/written\";\nimport { releaseFilePath } from \"../paths\";\n\n/** What `writeRelease()` returns: the contract result plus the entries it left out. */\nexport type WriteReleaseOutcome = WriteReleaseResult & {\n /** Entries still under `## Unreleased`; not collected. */\n unreleased: ReleaseEntry[];\n};\n\nfunction findRelease(written: WrittenGrimoire, release: string): WrittenRelease | undefined {\n return written.releases.find((item) => item.release.value === release);\n}\n\nfunction toReleaseEntry(entry: WrittenChangelogEntry, state: ReleaseEntry[\"state\"]): ReleaseEntry {\n return {\n feature: entry.feature,\n version: entry.version.value,\n word: entry.word,\n flow: entry.flow,\n criteria: [...entry.criteria],\n text: entry.text,\n state,\n source: entry.at,\n };\n}\n\n/** Compare two `<whole>.<decimal>` versions, newest first. */\nfunction compareVersionsDescending(a: string, b: string): number {\n const [aWhole = 0, aDecimal = 0] = a.split(\".\").map(Number);\n const [bWhole = 0, bDecimal = 0] = b.split(\".\").map(Number);\n\n return bWhole - aWhole || bDecimal - aDecimal;\n}\n\nfunction sortEntries(entries: ReleaseEntry[]): ReleaseEntry[] {\n // `sort` is stable, so equal versions keep their changelog order.\n return entries.sort(\n (a, b) => a.feature.localeCompare(b.feature) || compareVersionsDescending(a.version, b.version),\n );\n}\n\n/**\n * The entries still under `## Unreleased` in every feature changelog. They are\n * not part of any release until the agent stamps them.\n */\nexport function unreleasedEntries(written: WrittenGrimoire): ReleaseEntry[] {\n const entries: ReleaseEntry[] = [];\n\n for (const feature of written.features) {\n for (const entry of feature.changelog?.entries ?? []) {\n if (entry.release === null) entries.push(toReleaseEntry(entry, \"unreleased\"));\n }\n }\n\n return sortEntries(entries);\n}\n\n/**\n * The entries a release lists: the entries the agent stamped with that release\n * (under `## <release> (<date>)`). Entries under `## Unreleased` are never\n * collected. Throws a `GrimoireError` with `GR9005` when\n * `grimoire/releases/<release>.md` does not exist, has no `release` and\n * `date`, or has no brief.\n */\nexport function collectRelease(written: WrittenGrimoire, release: string): ReleaseCollection {\n const file = findRelease(written, release);\n\n if (!file || file.release.value === \"\" || file.date.value === \"\") {\n throw new GrimoireError(\n \"GR9005\",\n `${releaseFilePath(release)} does not exist or has no release and date. Write the brief first, with \\`release\\` and \\`date\\` in the front matter.`,\n );\n }\n\n if (file.brief.trim() === \"\") {\n throw new GrimoireError(\n \"GR9005\",\n `${file.file} has no brief yet. Write the brief under the heading, then run the command again.`,\n );\n }\n\n const entries: ReleaseEntry[] = [];\n\n for (const feature of written.features) {\n for (const entry of feature.changelog?.entries ?? []) {\n if (entry.release === release) entries.push(toReleaseEntry(entry, \"stamped\"));\n }\n }\n\n return { release, date: file.date.value, entries: sortEntries(entries) };\n}\n\nfunction entryLine(entry: {\n version: string;\n word: string;\n flow: string | null;\n criteria: string[];\n text: string;\n}): string {\n const flow = entry.flow === null ? \"\" : `${entry.flow}: `;\n const criteria = entry.criteria.length > 0 ? ` (${entry.criteria.join(\", \")})` : \"\";\n\n return `- ${entry.version} ${entry.word} ${flow}${entry.text}${criteria}`;\n}\n\n/** The Markdown between (and including) the collected-list markers. Pure. */\nexport function renderCollectedList(collection: ReleaseCollection): string {\n const lines: string[] = [COLLECTED_START_MARKER];\n\n if (collection.entries.length === 0) {\n lines.push(\"No feature changes.\");\n } else {\n lines.push(\"## Changes\");\n\n let current: string | null = null;\n\n for (const entry of collection.entries) {\n if (entry.feature !== current) {\n current = entry.feature;\n lines.push(\"\", `### ${entry.feature}`);\n }\n\n lines.push(entryLine(entry));\n }\n }\n\n lines.push(COLLECTED_END_MARKER);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Collect the release and write the list into its file: replaces the text\n * between the markers, or appends the markers and the list at the end. Never\n * touches any other file or any text outside the markers. Refuses (`GR9005`)\n * when the agent has not written the release file and its brief.\n *\n * @param root Absolute project root.\n */\nexport async function writeRelease(\n root: string,\n written: WrittenGrimoire,\n release: string,\n): Promise<WriteReleaseOutcome> {\n const collection = collectRelease(written, release);\n const file = findRelease(written, release)?.file ?? releaseFilePath(release);\n const absolute = path.join(root, ...file.split(\"/\"));\n const current = await readFile(absolute, \"utf8\");\n const eol = current.includes(\"\\r\\n\") ? \"\\r\\n\" : \"\\n\";\n const list = renderCollectedList(collection).split(\"\\n\").join(eol);\n const start = current.indexOf(COLLECTED_START_MARKER);\n const end = current.indexOf(COLLECTED_END_MARKER);\n\n let next: string;\n\n if (start === -1 && end === -1) {\n const base = current.replace(/\\s+$/, \"\");\n\n next = `${base}${eol}${eol}${list}${eol}`;\n } else if (\n start === -1 ||\n end === -1 ||\n end < start ||\n current.indexOf(COLLECTED_START_MARKER, start + 1) !== -1 ||\n current.indexOf(COLLECTED_END_MARKER, end + 1) !== -1\n ) {\n throw new GrimoireError(\n \"GR1024\",\n `${file} has broken collected-list markers. Keep one start marker followed by one end marker, or remove both.`,\n );\n } else {\n next = current.slice(0, start) + list + current.slice(end + COLLECTED_END_MARKER.length);\n }\n\n const changed = next !== current;\n\n if (changed) await writeFile(absolute, next);\n\n return { file, collection, changed, unreleased: unreleasedEntries(written) };\n}\n\nfunction sameEntry(\n listed: { feature: string; version: string; word: string; flow: string | null; text: string },\n entry: WrittenChangelogEntry,\n): boolean {\n return (\n listed.feature === entry.feature &&\n listed.version === entry.version.value &&\n listed.word === entry.word &&\n listed.flow === entry.flow &&\n listed.text === entry.text\n );\n}\n\n/** The GR6001–GR6003 rules. Read-only. */\nexport function checkReleases(snapshot: GrimoireSnapshot): GrimoireFinding[] {\n const { written } = snapshot;\n const findings: GrimoireFinding[] = [];\n\n // GR6001: a listed entry with no matching entry stamped with this release.\n for (const file of written.releases) {\n for (const listed of file.collected?.entries ?? []) {\n const changelog = written.features.find(\n (feature) => feature.id === listed.feature,\n )?.changelog;\n const stamped = (changelog?.entries ?? []).some(\n (entry) =>\n entry.release === file.release.value && entry.date !== null && sameEntry(listed, entry),\n );\n\n if (!stamped) {\n findings.push(\n createFinding({\n code: \"GR6001\",\n message: `release ${file.release.value} lists \"${listed.feature} ${listed.version} ${listed.word}: ${listed.text}\", but no entry in that changelog is stamped with ${file.release.value} and a date`,\n at: listed.at,\n feature: listed.feature,\n file: file.file,\n }),\n );\n }\n }\n }\n\n // GR6002 and GR6003: a changelog release section needs its release file and date.\n for (const feature of written.features) {\n for (const section of feature.changelog?.sections ?? []) {\n if (section.release === null) continue;\n\n const file = findRelease(written, section.release);\n\n if (!file) {\n findings.push(\n createFinding({\n code: \"GR6002\",\n message: `${feature.id} changelog has a section for release ${section.release}, but ${releaseFilePath(section.release)} does not exist`,\n at: section.at,\n feature: feature.id,\n file: section.at.file,\n }),\n );\n } else if (section.date !== null && section.date !== file.date.value) {\n findings.push(\n createFinding({\n code: \"GR6003\",\n message: `${feature.id} changelog dates release ${section.release} ${section.date}, but ${file.file} says ${file.date.value}`,\n at: section.at,\n feature: feature.id,\n file: section.at.file,\n }),\n );\n }\n }\n }\n\n return findings;\n}\n"],"mappings":";;;;;;;;;;;;;;AA4BA,SAAS,YAAY,SAA0B,SAA6C;CAC1F,OAAO,QAAQ,SAAS,MAAM,SAAS,KAAK,QAAQ,UAAU,OAAO;AACvE;AAEA,SAAS,eAAe,OAA8B,OAA4C;CAChG,OAAO;EACL,SAAS,MAAM;EACf,SAAS,MAAM,QAAQ;EACvB,MAAM,MAAM;EACZ,MAAM,MAAM;EACZ,UAAU,CAAC,GAAG,MAAM,QAAQ;EAC5B,MAAM,MAAM;EACZ;EACA,QAAQ,MAAM;CAChB;AACF;;AAGA,SAAS,0BAA0B,GAAW,GAAmB;CAC/D,MAAM,CAAC,SAAS,GAAG,WAAW,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM;CAC1D,MAAM,CAAC,SAAS,GAAG,WAAW,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM;CAE1D,OAAO,SAAS,UAAU,WAAW;AACvC;AAEA,SAAS,YAAY,SAAyC;CAE5D,OAAO,QAAQ,MACZ,GAAG,MAAM,EAAE,QAAQ,cAAc,EAAE,OAAO,KAAK,0BAA0B,EAAE,SAAS,EAAE,OAAO,CAChG;AACF;;;;;AAMA,SAAgB,kBAAkB,SAA0C;CAC1E,MAAM,UAA0B,CAAC;CAEjC,KAAK,MAA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,KAAK,KAAK,QAAQ,KAAK,KAAK;GACtH,IAAI,QAAQ;GACZ,SAAS,QAAQ;GACjB,MAAM,QAAQ,GAAG;EACnB,CAAC,CACH;CAEJ;CAGF,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/releases/index.ts"],"sourcesContent":["/**\n * Releases: collecting the changelog entries the agent stamped with a release\n * into `grimoire/releases/<release>.md`, and the GR6001–GR6003 rules.\n *\n * Collecting never edits a feature changelog or the agent's brief: it writes only\n * the text between the collected-list markers of the release file. Stamping\n * (`stamp.ts`, only on `--stamp`) is the one edit Warlock makes to written files.\n */\nimport { readFile, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { GrimoireError, createFinding } from \"../codes\";\nimport type { GrimoireFinding } from \"../contracts/findings\";\nimport type { ReleaseCollection, ReleaseEntry, WriteReleaseResult } from \"../contracts/releases\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport {\n COLLECTED_END_MARKER,\n COLLECTED_START_MARKER,\n type WrittenChangelogEntry,\n type WrittenGrimoire,\n type WrittenRelease,\n} from \"../contracts/written\";\nimport { releaseFilePath } from \"../paths\";\n\nexport { applyStamp, planStamp, type StampInput, type StampPlan } from \"./stamp\";\n\n/** What `writeRelease()` returns: the contract result plus the entries it left out. */\nexport type WriteReleaseOutcome = WriteReleaseResult & {\n /** Entries still under `## Unreleased`; not collected. */\n unreleased: ReleaseEntry[];\n};\n\nfunction findRelease(written: WrittenGrimoire, release: string): WrittenRelease | undefined {\n return written.releases.find((item) => item.release.value === release);\n}\n\nfunction toReleaseEntry(entry: WrittenChangelogEntry, state: ReleaseEntry[\"state\"]): ReleaseEntry {\n return {\n feature: entry.feature,\n version: entry.version.value,\n word: entry.word,\n flow: entry.flow,\n criteria: [...entry.criteria],\n text: entry.text,\n state,\n source: entry.at,\n };\n}\n\n/** Compare two `<whole>.<decimal>` versions, newest first. */\nfunction compareVersionsDescending(a: string, b: string): number {\n const [aWhole = 0, aDecimal = 0] = a.split(\".\").map(Number);\n const [bWhole = 0, bDecimal = 0] = b.split(\".\").map(Number);\n\n return bWhole - aWhole || bDecimal - aDecimal;\n}\n\nfunction sortEntries(entries: ReleaseEntry[]): ReleaseEntry[] {\n // `sort` is stable, so equal versions keep their changelog order.\n return entries.sort(\n (a, b) => a.feature.localeCompare(b.feature) || compareVersionsDescending(a.version, b.version),\n );\n}\n\n/**\n * The entries still under `## Unreleased` in every feature changelog. They are\n * not part of any release until the agent stamps them.\n */\nexport function unreleasedEntries(written: WrittenGrimoire): ReleaseEntry[] {\n const entries: ReleaseEntry[] = [];\n\n for (const feature of written.features) {\n for (const entry of feature.changelog?.entries ?? []) {\n if (entry.release === null) entries.push(toReleaseEntry(entry, \"unreleased\"));\n }\n }\n\n return sortEntries(entries);\n}\n\n/**\n * The entries a release lists: the entries the agent stamped with that release\n * (under `## <release> (<date>)`). Entries under `## Unreleased` are never\n * collected. Throws a `GrimoireError` with `GR9005` when\n * `grimoire/releases/<release>.md` does not exist, has no `release` and\n * `date`, or has no brief.\n */\nexport function collectRelease(written: WrittenGrimoire, release: string): ReleaseCollection {\n const file = findRelease(written, release);\n\n if (!file || file.release.value === \"\" || file.date.value === \"\") {\n throw new GrimoireError(\n \"GR9005\",\n `${releaseFilePath(release)} does not exist or has no release and date. Write the brief first, with \\`release\\` and \\`date\\` in the front matter.`,\n );\n }\n\n if (file.brief.trim() === \"\") {\n throw new GrimoireError(\n \"GR9005\",\n `${file.file} has no brief yet. Write the brief under the heading, then run the command again.`,\n );\n }\n\n const entries: ReleaseEntry[] = [];\n\n for (const feature of written.features) {\n for (const entry of feature.changelog?.entries ?? []) {\n if (entry.release === release) entries.push(toReleaseEntry(entry, \"stamped\"));\n }\n }\n\n return { release, date: file.date.value, entries: sortEntries(entries) };\n}\n\nfunction entryLine(entry: {\n version: string;\n word: string;\n flow: string | null;\n criteria: string[];\n text: string;\n}): string {\n const flow = entry.flow === null ? \"\" : `${entry.flow}: `;\n const criteria = entry.criteria.length > 0 ? ` (${entry.criteria.join(\", \")})` : \"\";\n\n return `- ${entry.version} ${entry.word} ${flow}${entry.text}${criteria}`;\n}\n\n/** The Markdown between (and including) the collected-list markers. Pure. */\nexport function renderCollectedList(collection: ReleaseCollection): string {\n const lines: string[] = [COLLECTED_START_MARKER];\n\n if (collection.entries.length === 0) {\n lines.push(\"No feature changes.\");\n } else {\n lines.push(\"## Changes\");\n\n let current: string | null = null;\n\n for (const entry of collection.entries) {\n if (entry.feature !== current) {\n current = entry.feature;\n lines.push(\"\", `### ${entry.feature}`);\n }\n\n lines.push(entryLine(entry));\n }\n }\n\n lines.push(COLLECTED_END_MARKER);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Collect the release and write the list into its file: replaces the text\n * between the markers, or appends the markers and the list at the end. Never\n * touches any other file or any text outside the markers. Refuses (`GR9005`)\n * when the agent has not written the release file and its brief.\n *\n * @param root Absolute project root.\n */\nexport async function writeRelease(\n root: string,\n written: WrittenGrimoire,\n release: string,\n): Promise<WriteReleaseOutcome> {\n const collection = collectRelease(written, release);\n const file = findRelease(written, release)?.file ?? releaseFilePath(release);\n const absolute = path.join(root, ...file.split(\"/\"));\n const current = await readFile(absolute, \"utf8\");\n const eol = current.includes(\"\\r\\n\") ? \"\\r\\n\" : \"\\n\";\n const list = renderCollectedList(collection).split(\"\\n\").join(eol);\n const start = current.indexOf(COLLECTED_START_MARKER);\n const end = current.indexOf(COLLECTED_END_MARKER);\n\n let next: string;\n\n if (start === -1 && end === -1) {\n const base = current.replace(/\\s+$/, \"\");\n\n next = `${base}${eol}${eol}${list}${eol}`;\n } else if (\n start === -1 ||\n end === -1 ||\n end < start ||\n current.indexOf(COLLECTED_START_MARKER, start + 1) !== -1 ||\n current.indexOf(COLLECTED_END_MARKER, end + 1) !== -1\n ) {\n throw new GrimoireError(\n \"GR1024\",\n `${file} has broken collected-list markers. Keep one start marker followed by one end marker, or remove both.`,\n );\n } else {\n next = current.slice(0, start) + list + current.slice(end + COLLECTED_END_MARKER.length);\n }\n\n const changed = next !== current;\n\n if (changed) await writeFile(absolute, next);\n\n return { file, collection, changed, unreleased: unreleasedEntries(written) };\n}\n\nfunction sameEntry(\n listed: { feature: string; version: string; word: string; flow: string | null; text: string },\n entry: WrittenChangelogEntry,\n): boolean {\n return (\n listed.feature === entry.feature &&\n listed.version === entry.version.value &&\n listed.word === entry.word &&\n listed.flow === entry.flow &&\n listed.text === entry.text\n );\n}\n\n/** The GR6001–GR6003 rules. Read-only. */\nexport function checkReleases(snapshot: GrimoireSnapshot): GrimoireFinding[] {\n const { written } = snapshot;\n const findings: GrimoireFinding[] = [];\n\n // GR6001: a listed entry with no matching entry stamped with this release.\n for (const file of written.releases) {\n for (const listed of file.collected?.entries ?? []) {\n const changelog = written.features.find(\n (feature) => feature.id === listed.feature,\n )?.changelog;\n const stamped = (changelog?.entries ?? []).some(\n (entry) =>\n entry.release === file.release.value && entry.date !== null && sameEntry(listed, entry),\n );\n\n if (!stamped) {\n findings.push(\n createFinding({\n code: \"GR6001\",\n message: `release ${file.release.value} lists \"${listed.feature} ${listed.version} ${listed.word}: ${listed.text}\", but no entry in that changelog is stamped with ${file.release.value} and a date`,\n at: listed.at,\n feature: listed.feature,\n file: file.file,\n }),\n );\n }\n }\n }\n\n // GR6002 and GR6003: a changelog release section needs its release file and date.\n for (const feature of written.features) {\n for (const section of feature.changelog?.sections ?? []) {\n if (section.release === null) continue;\n\n const file = findRelease(written, section.release);\n\n if (!file) {\n findings.push(\n createFinding({\n code: \"GR6002\",\n message: `${feature.id} changelog has a section for release ${section.release}, but ${releaseFilePath(section.release)} does not exist`,\n at: section.at,\n feature: feature.id,\n file: section.at.file,\n }),\n );\n } else if (section.date !== null && section.date !== file.date.value) {\n findings.push(\n createFinding({\n code: \"GR6003\",\n message: `${feature.id} changelog dates release ${section.release} ${section.date}, but ${file.file} says ${file.date.value}`,\n at: section.at,\n feature: feature.id,\n file: section.at.file,\n }),\n );\n }\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