@warlock.js/grimoire 0.0.0-stage → 5.56.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 (211) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/LICENSE +21 -0
  3. package/README.md +55 -2
  4. package/esm/apps/check-apps.mjs +207 -0
  5. package/esm/apps/check-apps.mjs.map +1 -0
  6. package/esm/apps/index.mjs +4 -0
  7. package/esm/apps/match-apps.d.mts +12 -0
  8. package/esm/apps/match-apps.d.mts.map +1 -0
  9. package/esm/apps/match-apps.mjs +30 -0
  10. package/esm/apps/match-apps.mjs.map +1 -0
  11. package/esm/book/build.d.mts +14 -0
  12. package/esm/book/build.d.mts.map +1 -0
  13. package/esm/book/build.mjs +300 -0
  14. package/esm/book/build.mjs.map +1 -0
  15. package/esm/book/index.mjs +5 -0
  16. package/esm/book/io.mjs +162 -0
  17. package/esm/book/io.mjs.map +1 -0
  18. package/esm/book/normalize.mjs +71 -0
  19. package/esm/book/normalize.mjs.map +1 -0
  20. package/esm/book/render.mjs +262 -0
  21. package/esm/book/render.mjs.map +1 -0
  22. package/esm/book/write.d.mts +12 -0
  23. package/esm/book/write.d.mts.map +1 -0
  24. package/esm/book/write.mjs +90 -0
  25. package/esm/book/write.mjs.map +1 -0
  26. package/esm/bookmap/build.d.mts +21 -0
  27. package/esm/bookmap/build.d.mts.map +1 -0
  28. package/esm/bookmap/build.mjs +272 -0
  29. package/esm/bookmap/build.mjs.map +1 -0
  30. package/esm/bookmap/index.mjs +5 -0
  31. package/esm/bookmap/steps.mjs +137 -0
  32. package/esm/bookmap/steps.mjs.map +1 -0
  33. package/esm/bookmap/write.d.mts +19 -0
  34. package/esm/bookmap/write.d.mts.map +1 -0
  35. package/esm/bookmap/write.mjs +118 -0
  36. package/esm/bookmap/write.mjs.map +1 -0
  37. package/esm/check/check-grimoire.d.mts +7 -0
  38. package/esm/check/check-grimoire.d.mts.map +1 -0
  39. package/esm/check/check-grimoire.mjs +98 -0
  40. package/esm/check/check-grimoire.mjs.map +1 -0
  41. package/esm/check/format-check-report.d.mts +20 -0
  42. package/esm/check/format-check-report.d.mts.map +1 -0
  43. package/esm/check/format-check-report.mjs +55 -0
  44. package/esm/check/format-check-report.mjs.map +1 -0
  45. package/esm/check/index.mjs +4 -0
  46. package/esm/check/rules/book-notes.mjs +18 -0
  47. package/esm/check/rules/book-notes.mjs.map +1 -0
  48. package/esm/check/rules/criteria.mjs +48 -0
  49. package/esm/check/rules/criteria.mjs.map +1 -0
  50. package/esm/check/rules/links.mjs +196 -0
  51. package/esm/check/rules/links.mjs.map +1 -0
  52. package/esm/check/rules/lookup.mjs +41 -0
  53. package/esm/check/rules/lookup.mjs.map +1 -0
  54. package/esm/check/rules/source-files.mjs +119 -0
  55. package/esm/check/rules/source-files.mjs.map +1 -0
  56. package/esm/check/rules/versions.mjs +92 -0
  57. package/esm/check/rules/versions.mjs.map +1 -0
  58. package/esm/codes/codes.d.mts +182 -0
  59. package/esm/codes/codes.d.mts.map +1 -0
  60. package/esm/codes/codes.mjs +111 -0
  61. package/esm/codes/codes.mjs.map +1 -0
  62. package/esm/codes/index.d.mts +33 -0
  63. package/esm/codes/index.d.mts.map +1 -0
  64. package/esm/codes/index.mjs +63 -0
  65. package/esm/codes/index.mjs.map +1 -0
  66. package/esm/contracts/adapter.d.mts +209 -0
  67. package/esm/contracts/adapter.d.mts.map +1 -0
  68. package/esm/contracts/book.d.mts +233 -0
  69. package/esm/contracts/book.d.mts.map +1 -0
  70. package/esm/contracts/book.mjs +7 -0
  71. package/esm/contracts/book.mjs.map +1 -0
  72. package/esm/contracts/bookmap.d.mts +175 -0
  73. package/esm/contracts/bookmap.d.mts.map +1 -0
  74. package/esm/contracts/findings.d.mts +79 -0
  75. package/esm/contracts/findings.d.mts.map +1 -0
  76. package/esm/contracts/location.d.mts +22 -0
  77. package/esm/contracts/location.d.mts.map +1 -0
  78. package/esm/contracts/releases.d.mts +53 -0
  79. package/esm/contracts/releases.d.mts.map +1 -0
  80. package/esm/contracts/scry.d.mts +143 -0
  81. package/esm/contracts/scry.d.mts.map +1 -0
  82. package/esm/contracts/snapshot.d.mts +52 -0
  83. package/esm/contracts/snapshot.d.mts.map +1 -0
  84. package/esm/contracts/test-results.d.mts +63 -0
  85. package/esm/contracts/test-results.d.mts.map +1 -0
  86. package/esm/contracts/written.d.mts +363 -0
  87. package/esm/contracts/written.d.mts.map +1 -0
  88. package/esm/contracts/written.mjs +19 -0
  89. package/esm/contracts/written.mjs.map +1 -0
  90. package/esm/devtools/data.mjs +171 -0
  91. package/esm/devtools/data.mjs.map +1 -0
  92. package/esm/devtools/graphs.mjs +142 -0
  93. package/esm/devtools/graphs.mjs.map +1 -0
  94. package/esm/devtools/index.d.mts +42 -0
  95. package/esm/devtools/index.d.mts.map +1 -0
  96. package/esm/devtools/index.mjs +103 -0
  97. package/esm/devtools/index.mjs.map +1 -0
  98. package/esm/devtools/site.d.mts +26 -0
  99. package/esm/devtools/site.d.mts.map +1 -0
  100. package/esm/devtools/site.mjs +190 -0
  101. package/esm/devtools/site.mjs.map +1 -0
  102. package/esm/devtools/snapshot-source.mjs +70 -0
  103. package/esm/devtools/snapshot-source.mjs.map +1 -0
  104. package/esm/front-matter/index.d.mts +33 -0
  105. package/esm/front-matter/index.d.mts.map +1 -0
  106. package/esm/front-matter/index.mjs +130 -0
  107. package/esm/front-matter/index.mjs.map +1 -0
  108. package/esm/graph/index.d.mts +15 -0
  109. package/esm/graph/index.d.mts.map +1 -0
  110. package/esm/graph/index.mjs +42 -0
  111. package/esm/graph/index.mjs.map +1 -0
  112. package/esm/index.d.mts +33 -0
  113. package/esm/index.mjs +33 -0
  114. package/esm/ownership/index.d.mts +8 -0
  115. package/esm/ownership/index.d.mts.map +1 -0
  116. package/esm/ownership/index.mjs +137 -0
  117. package/esm/ownership/index.mjs.map +1 -0
  118. package/esm/paths/index.d.mts +58 -0
  119. package/esm/paths/index.d.mts.map +1 -0
  120. package/esm/paths/index.mjs +137 -0
  121. package/esm/paths/index.mjs.map +1 -0
  122. package/esm/proves/index.mjs +3 -0
  123. package/esm/proves/scan-proofs.d.mts +22 -0
  124. package/esm/proves/scan-proofs.d.mts.map +1 -0
  125. package/esm/proves/scan-proofs.mjs +214 -0
  126. package/esm/proves/scan-proofs.mjs.map +1 -0
  127. package/esm/releases/index.d.mts +29 -0
  128. package/esm/releases/index.d.mts.map +1 -0
  129. package/esm/releases/index.mjs +157 -0
  130. package/esm/releases/index.mjs.map +1 -0
  131. package/esm/scry/format.d.mts +14 -0
  132. package/esm/scry/format.d.mts.map +1 -0
  133. package/esm/scry/format.mjs +193 -0
  134. package/esm/scry/format.mjs.map +1 -0
  135. package/esm/scry/index.mjs +5 -0
  136. package/esm/scry/parse.d.mts +10 -0
  137. package/esm/scry/parse.d.mts.map +1 -0
  138. package/esm/scry/parse.mjs +108 -0
  139. package/esm/scry/parse.mjs.map +1 -0
  140. package/esm/scry/query.d.mts +11 -0
  141. package/esm/scry/query.d.mts.map +1 -0
  142. package/esm/scry/query.mjs +457 -0
  143. package/esm/scry/query.mjs.map +1 -0
  144. package/esm/tasks/index.mjs +116 -0
  145. package/esm/tasks/index.mjs.map +1 -0
  146. package/esm/test-results/criterion-status.d.mts +15 -0
  147. package/esm/test-results/criterion-status.d.mts.map +1 -0
  148. package/esm/test-results/criterion-status.mjs +17 -0
  149. package/esm/test-results/criterion-status.mjs.map +1 -0
  150. package/esm/test-results/index.d.mts +8 -0
  151. package/esm/test-results/index.d.mts.map +1 -0
  152. package/esm/test-results/index.mjs +124 -0
  153. package/esm/test-results/index.mjs.map +1 -0
  154. package/esm/vitest/index.d.mts +15 -0
  155. package/esm/vitest/index.d.mts.map +1 -0
  156. package/esm/vitest/index.mjs +146 -0
  157. package/esm/vitest/index.mjs.map +1 -0
  158. package/esm/warlock/actions.mjs +265 -0
  159. package/esm/warlock/actions.mjs.map +1 -0
  160. package/esm/warlock/adapter.d.mts +28 -0
  161. package/esm/warlock/adapter.d.mts.map +1 -0
  162. package/esm/warlock/adapter.mjs +377 -0
  163. package/esm/warlock/adapter.mjs.map +1 -0
  164. package/esm/warlock/commands.d.mts +15 -0
  165. package/esm/warlock/commands.d.mts.map +1 -0
  166. package/esm/warlock/commands.mjs +199 -0
  167. package/esm/warlock/commands.mjs.map +1 -0
  168. package/esm/warlock/index.d.mts +4 -0
  169. package/esm/warlock/index.mjs +5 -0
  170. package/esm/warlock/mcp-tools.mjs +247 -0
  171. package/esm/warlock/mcp-tools.mjs.map +1 -0
  172. package/esm/warlock/mobile-facts.d.mts +32 -0
  173. package/esm/warlock/mobile-facts.d.mts.map +1 -0
  174. package/esm/warlock/mobile-facts.mjs +185 -0
  175. package/esm/warlock/mobile-facts.mjs.map +1 -0
  176. package/esm/workspace/index.d.mts +11 -0
  177. package/esm/workspace/index.d.mts.map +1 -0
  178. package/esm/workspace/index.mjs +122 -0
  179. package/esm/workspace/index.mjs.map +1 -0
  180. package/esm/written/apps.mjs +227 -0
  181. package/esm/written/apps.mjs.map +1 -0
  182. package/esm/written/features.mjs +400 -0
  183. package/esm/written/features.mjs.map +1 -0
  184. package/esm/written/fields.mjs +173 -0
  185. package/esm/written/fields.mjs.map +1 -0
  186. package/esm/written/index.mjs +3 -0
  187. package/esm/written/lists.mjs +68 -0
  188. package/esm/written/lists.mjs.map +1 -0
  189. package/esm/written/markdown.mjs +173 -0
  190. package/esm/written/markdown.mjs.map +1 -0
  191. package/esm/written/parse-grimoire.d.mts +20 -0
  192. package/esm/written/parse-grimoire.d.mts.map +1 -0
  193. package/esm/written/parse-grimoire.mjs +552 -0
  194. package/esm/written/parse-grimoire.mjs.map +1 -0
  195. package/esm/written/sink.mjs +65 -0
  196. package/esm/written/sink.mjs.map +1 -0
  197. package/esm/written/tasks-releases.mjs +166 -0
  198. package/esm/written/tasks-releases.mjs.map +1 -0
  199. package/llms-full.txt +869 -0
  200. package/llms.txt +15 -0
  201. package/package.json +66 -4
  202. package/skills/backfill-a-grimoire/SKILL.md +128 -0
  203. package/skills/describe-an-app/SKILL.md +162 -0
  204. package/skills/document-a-file/SKILL.md +75 -0
  205. package/skills/index.md +26 -0
  206. package/skills/record-a-change/SKILL.md +139 -0
  207. package/skills/use-the-grimoire/SKILL.md +137 -0
  208. package/skills/write-a-feature/SKILL.md +168 -0
  209. package/ui/grimoire-static.js +136 -0
  210. package/ui/grimoire-view.js +1005 -0
  211. package/ui/grimoire.css +88 -0
@@ -0,0 +1,58 @@
1
+ //#region ../../packages/grimoire/src/paths/index.d.ts
2
+ /** The folder at the project root. */
3
+ export declare const GRIMOIRE_DIR = "grimoire";
4
+ /** Project-relative paths of the Grimoire layout. Agent-written unless marked Warlock. */
5
+ export declare const GRIMOIRE_PATHS: {
6
+ /** Warlock. The generated book (ignored by git). */
7
+ readonly book: "grimoire/book";
8
+ /** Warlock. The freshness fingerprint. */
9
+ readonly bookManifest: "grimoire/book/manifest.json";
10
+ /** Warlock. The adapter's last facts (machine use). */
11
+ readonly bookFactsCache: "grimoire/book/.cache/facts.json";
12
+ /** Warlock. Every route, by module. */
13
+ readonly bookRoutes: "grimoire/book/app/routes.json";
14
+ /** Warlock (the Vitest reporter). Test results per proving test. */
15
+ readonly testResults: "grimoire/book/test-results.json";
16
+ /** Warlock. Default folder of the static devtools export. */
17
+ readonly staticSite: "grimoire/book/site";
18
+ readonly features: "grimoire/features";
19
+ /** Warlock. */
20
+ readonly featuresIndex: "grimoire/features/index.json";
21
+ readonly apps: "grimoire/apps";
22
+ readonly tasks: "grimoire/tasks";
23
+ readonly openTasks: "grimoire/tasks/open";
24
+ readonly doneTasks: "grimoire/tasks/done";
25
+ /** Warlock. */
26
+ readonly tasksIndex: "grimoire/tasks/index.json";
27
+ readonly releases: "grimoire/releases";
28
+ };
29
+ /** Lines a project's `.gitignore` needs so Warlock's files stay out of git. */
30
+ 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"];
31
+ /** A path with `\` turned into `/`. */
32
+ export declare function toPosixPath(file: string): string;
33
+ /** One file to place in the book. */
34
+ export type BookPathInput = {
35
+ file: string;
36
+ /** Mobile app id and root when the file belongs to a mobile app. */
37
+ mobileApp?: {
38
+ id: string;
39
+ root: string;
40
+ } | null;
41
+ };
42
+ /**
43
+ * The book entry path of every given code file.
44
+ *
45
+ * `src/app/auth/controllers/login.controller.ts` →
46
+ * `grimoire/book/app/auth/controllers/login.controller.json`; a mobile app
47
+ * file `mobile/app/index.tsx` of app `mobile` →
48
+ * `grimoire/book/mobile/mobile/app/index.json`.
49
+ *
50
+ * When two files would share a path (`a.ts` and `a.tsx`), or a file would
51
+ * take a reserved list path (`src/app/routes.ts` → `app/routes.json`), those
52
+ * files keep their full name instead: `a.ts.json`, `routes.ts.json`.
53
+ */
54
+ export declare function bookEntryPaths(files: readonly BookPathInput[]): Map<string, string>;
55
+ /** The book entry path of one file, when no other file can collide with it. */
56
+ export declare function bookEntryPath(input: BookPathInput): string;
57
+ //#endregion
58
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +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;;;qBAIW;;wBAWG,YAAY;;YAkDhB;EACV;;EAEA;IAAc;IAAY;;;;;;;;;;;;;;;wBAeZ,eAAe,gBAAgB,kBAAkB;;wBAiCjD,cAAc,OAAO"}
@@ -0,0 +1,137 @@
1
+ import path from "node:path";
2
+
3
+ //#region ../../packages/grimoire/src/paths/index.ts
4
+ /**
5
+ * Where everything lives under `grimoire/`, and how a source file maps to its
6
+ * book entry. Every path here is project-relative and uses `/`.
7
+ */
8
+ /** The folder at the project root. */
9
+ const GRIMOIRE_DIR = "grimoire";
10
+ /** Project-relative paths of the Grimoire layout. Agent-written unless marked Warlock. */
11
+ const GRIMOIRE_PATHS = {
12
+ /** Warlock. The generated book (ignored by git). */
13
+ book: "grimoire/book",
14
+ /** Warlock. The freshness fingerprint. */
15
+ bookManifest: "grimoire/book/manifest.json",
16
+ /** Warlock. The adapter's last facts (machine use). */
17
+ bookFactsCache: "grimoire/book/.cache/facts.json",
18
+ /** Warlock. Every route, by module. */
19
+ bookRoutes: "grimoire/book/app/routes.json",
20
+ /** Warlock (the Vitest reporter). Test results per proving test. */
21
+ testResults: "grimoire/book/test-results.json",
22
+ /** Warlock. Default folder of the static devtools export. */
23
+ staticSite: "grimoire/book/site",
24
+ features: "grimoire/features",
25
+ /** Warlock. */
26
+ featuresIndex: "grimoire/features/index.json",
27
+ apps: "grimoire/apps",
28
+ tasks: "grimoire/tasks",
29
+ openTasks: "grimoire/tasks/open",
30
+ doneTasks: "grimoire/tasks/done",
31
+ /** Warlock. */
32
+ tasksIndex: "grimoire/tasks/index.json",
33
+ releases: "grimoire/releases"
34
+ };
35
+ /** Lines a project's `.gitignore` needs so Warlock's files stay out of git. */
36
+ const GRIMOIRE_IGNORE_RULES = [
37
+ "/grimoire/book/",
38
+ "/grimoire/features/index.json",
39
+ "/grimoire/features/**/bookmap.json",
40
+ "/grimoire/features/**/*.bookmap.json",
41
+ "/grimoire/tasks/index.json"
42
+ ];
43
+ const CODE_EXTENSION = /\.(?:d\.ts|[cm]?[jt]s|[jt]sx)$/;
44
+ /** A path with `\` turned into `/`. */
45
+ function toPosixPath(file) {
46
+ return file.split("\\").join("/");
47
+ }
48
+ /** A project-relative POSIX path for an absolute or relative path. */
49
+ function projectPath(root, file) {
50
+ return toPosixPath(path.relative(root, path.resolve(root, file)));
51
+ }
52
+ /** Whether a project-relative file is inside a project-relative folder (or is it). */
53
+ function isInsideFolder(file, folder) {
54
+ const normalizedFolder = toPosixPath(folder).replace(/\/+$/, "");
55
+ const normalizedFile = toPosixPath(file);
56
+ return normalizedFile === normalizedFolder || normalizedFile.startsWith(`${normalizedFolder}/`);
57
+ }
58
+ /** Whether a file name is a code file the book has an entry for. */
59
+ function isCodeFile(file) {
60
+ return CODE_EXTENSION.test(file);
61
+ }
62
+ /** Book paths Warlock writes for lists; a mirrored entry never takes one of them. */
63
+ function isReservedBookPath(bookPath) {
64
+ return bookPath === GRIMOIRE_PATHS.bookManifest || bookPath === GRIMOIRE_PATHS.bookRoutes || bookPath === GRIMOIRE_PATHS.testResults || bookPath.startsWith(`${GRIMOIRE_PATHS.book}/.cache/`) || bookPath.startsWith(`${GRIMOIRE_PATHS.staticSite}/`) || /^grimoire\/book\/web\/[^/]+\.pages\.json$/.test(bookPath) || /^grimoire\/book\/mobile\/[^/]+\.screens\.json$/.test(bookPath);
65
+ }
66
+ /** The mirror of a source file without the collision rules: `src/` dropped, extension → `.json`. */
67
+ function plainEntryPath(file, mobileApp, mobileRoot) {
68
+ const posix = toPosixPath(file);
69
+ let relative;
70
+ if (mobileApp !== null && mobileRoot !== null && isInsideFolder(posix, mobileRoot)) relative = `mobile/${mobileApp}/${posix.slice(toPosixPath(mobileRoot).replace(/\/+$/, "").length + 1)}`;
71
+ else relative = posix.startsWith("src/") ? posix.slice(4) : posix;
72
+ return `${GRIMOIRE_PATHS.book}/${relative.replace(CODE_EXTENSION, "")}.json`;
73
+ }
74
+ /**
75
+ * The book entry path of every given code file.
76
+ *
77
+ * `src/app/auth/controllers/login.controller.ts` →
78
+ * `grimoire/book/app/auth/controllers/login.controller.json`; a mobile app
79
+ * file `mobile/app/index.tsx` of app `mobile` →
80
+ * `grimoire/book/mobile/mobile/app/index.json`.
81
+ *
82
+ * When two files would share a path (`a.ts` and `a.tsx`), or a file would
83
+ * take a reserved list path (`src/app/routes.ts` → `app/routes.json`), those
84
+ * files keep their full name instead: `a.ts.json`, `routes.ts.json`.
85
+ */
86
+ function bookEntryPaths(files) {
87
+ const plain = /* @__PURE__ */ new Map();
88
+ const counts = /* @__PURE__ */ new Map();
89
+ for (const input of files) {
90
+ const entry = plainEntryPath(input.file, input.mobileApp?.id ?? null, input.mobileApp?.root ?? null);
91
+ plain.set(input.file, entry);
92
+ counts.set(entry, (counts.get(entry) ?? 0) + 1);
93
+ }
94
+ const result = /* @__PURE__ */ new Map();
95
+ for (const input of files) {
96
+ const entry = plain.get(input.file);
97
+ if (entry === void 0) continue;
98
+ if ((counts.get(entry) ?? 0) > 1 || isReservedBookPath(entry)) {
99
+ const name = path.posix.basename(toPosixPath(input.file));
100
+ result.set(input.file, `${path.posix.dirname(entry)}/${name}.json`);
101
+ } else result.set(input.file, entry);
102
+ }
103
+ return result;
104
+ }
105
+ /** The book entry path of one file, when no other file can collide with it. */
106
+ function bookEntryPath(input) {
107
+ return bookEntryPaths([input]).get(input.file) ?? plainEntryPath(input.file, null, null);
108
+ }
109
+ /** `grimoire/book/web/<site>.pages.json`. */
110
+ function sitePagesPath(site) {
111
+ return `${GRIMOIRE_PATHS.book}/web/${site}.pages.json`;
112
+ }
113
+ /** `grimoire/book/mobile/<app>.screens.json`. */
114
+ function mobileScreensPath(app) {
115
+ return `${GRIMOIRE_PATHS.book}/mobile/${app}.screens.json`;
116
+ }
117
+ /** `grimoire/book/<module without src/>/index.md`. */
118
+ function moduleSummaryPath(module) {
119
+ const posix = toPosixPath(module);
120
+ return `${GRIMOIRE_PATHS.book}/${posix.startsWith("src/") ? posix.slice(4) : posix}/index.md`;
121
+ }
122
+ /** `grimoire/features/<feature>/bookmap.json`. */
123
+ function featureBookmapPath(feature) {
124
+ return `${GRIMOIRE_PATHS.features}/${feature}/bookmap.json`;
125
+ }
126
+ /** `grimoire/features/<feature>/flows/<flow>.bookmap.json`. */
127
+ function flowBookmapPath(feature, flow) {
128
+ return `${GRIMOIRE_PATHS.features}/${feature}/flows/${flow}.bookmap.json`;
129
+ }
130
+ /** `grimoire/releases/<release>.md`. */
131
+ function releaseFilePath(release) {
132
+ return `${GRIMOIRE_PATHS.releases}/${release}.md`;
133
+ }
134
+
135
+ //#endregion
136
+ export { GRIMOIRE_DIR, GRIMOIRE_IGNORE_RULES, GRIMOIRE_PATHS, bookEntryPath, bookEntryPaths, featureBookmapPath, flowBookmapPath, isCodeFile, isInsideFolder, isReservedBookPath, mobileScreensPath, moduleSummaryPath, projectPath, releaseFilePath, sitePagesPath, toPosixPath };
137
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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} 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;AACZ;;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,SAAS,MAAM,KAAK,QAAQ,MAAM,IAAI,CAAC,CAAC;AAClE;;AAGA,SAAgB,eAAe,MAAc,QAAyB;CACpE,MAAM,mBAAmB,YAAY,MAAM,CAAC,CAAC,QAAQ,QAAQ,EAAE;CAC/D,MAAM,iBAAiB,YAAY,IAAI;CAEvC,OAAO,mBAAmB,oBAAoB,eAAe,WAAW,GAAG,iBAAiB,EAAE;AAChG;;AAGA,SAAgB,WAAW,MAAuB;CAChD,OAAO,eAAe,KAAK,IAAI;AACjC;;AAGA,SAAgB,mBAAmB,UAA2B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KAAK,MAAM,QAAQ,KAAK,EAAE,GAAG,KAAK,MAAM;EACpE,OACE,OAAO,IAAI,MAAM,MAAM,KAAK;CAEhC;CAEA,OAAO;AACT;;AAGA,SAAgB,cAAc,OAA8B;CAC1D,OAAO,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,MAAM,IAAI,KAAK,eAAe,MAAM,MAAM,MAAM,IAAI;AACzF;;AAGA,SAAgB,cAAc,MAAsB;CAClD,OAAO,GAAG,eAAe,KAAK,OAAO,KAAK;AAC5C;;AAGA,SAAgB,kBAAkB,KAAqB;CACrD,OAAO,GAAG,eAAe,KAAK,UAAU,IAAI;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;;AAGA,SAAgB,gBAAgB,SAAyB;CACvD,OAAO,GAAG,eAAe,SAAS,GAAG,QAAQ;AAC/C"}
@@ -0,0 +1,3 @@
1
+ import { scanProofs, scanProofsInText } from "./scan-proofs.mjs";
2
+
3
+ export { scanProofs, scanProofsInText };
@@ -0,0 +1,22 @@
1
+ import { GrimoireFinding } from "../contracts/findings.mjs";
2
+ import { ProofLine } from "../contracts/test-results.mjs";
3
+ //#region ../../packages/grimoire/src/proves/scan-proofs.d.ts
4
+ /** What a scan returns. */
5
+ export type ScanProofsResult = {
6
+ proofs: ProofLine[];
7
+ /** `GR4003` (malformed line), `GR4004` (no test under it), `GR4005` (two proofs on one test). */
8
+ findings: GrimoireFinding[];
9
+ };
10
+ /** Read the proof lines of one test file's content. Pure. */
11
+ export declare function scanProofsInText(text: string, file: string): ScanProofsResult;
12
+ /**
13
+ * Read the proof lines of every test file. Files that cannot be read (removed
14
+ * since the book was built) are skipped. Proofs and findings come out in
15
+ * file order, then line order.
16
+ *
17
+ * @param root Absolute project root.
18
+ * @param testFiles Project-relative test files (`BookFacts.tests`).
19
+ */
20
+ export declare function scanProofs(root: string, testFiles: readonly string[]): Promise<ScanProofsResult>;
21
+ //#endregion
22
+ //# sourceMappingURL=scan-proofs.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scan-proofs.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/proves/scan-proofs.ts"],"mappings":";;;;YAQY;EACV,QAAQ;;EAER,UAAU;;;wBA0BI,iBAAiB,cAAc,eAAe;;;;;;;;;wBAwGxC,WACpB,cACA,+BACC,QAAQ"}
@@ -0,0 +1,214 @@
1
+ import { createFinding } from "../codes/index.mjs";
2
+ import { toPosixPath } from "../paths/index.mjs";
3
+ import path from "node:path";
4
+ import { readFile } from "node:fs/promises";
5
+
6
+ //#region ../../packages/grimoire/src/proves/scan-proofs.ts
7
+ /** How many test files `scanProofs` reads at once. */
8
+ const READ_CONCURRENCY = 32;
9
+ /** A `// @proves …` line comment on its own line; group 1 is the rest of the line. */
10
+ const PROOF_LINE = /^\s*\/\/\s*@proves\b(.*)$/;
11
+ /** A `// @proves` comment after code on the same line. */
12
+ const TRAILING_PROOF = /\S.*\/\/\s*@proves\b/;
13
+ /** The rest of a well-formed proof line: ` <feature>/<flow> AC-<n>`. */
14
+ const PROOF_TARGET = /^\s+([a-z0-9]+(?:-[a-z0-9]+)*)\/([a-z0-9]+(?:-[a-z0-9]+)*)\s+(AC-\d+)\s*$/;
15
+ /** `it(`, `test(`, `it.only(`, `test.each(…)(`, `it.skipIf(…)(`, `` test.each` ``… */
16
+ const TEST_CALL = /^(?:it|test)((?:\s*\.\s*(?:only|skip|todo|concurrent|sequential|fails|failing|each|for|skipIf|runIf|fixme|slow))*)\s*[(`]/;
17
+ /** Modifiers that take their own arguments before the test's call. */
18
+ const MODIFIER_WITH_ARGUMENTS = /\.\s*(?:each|for|skipIf|runIf)\s*$/;
19
+ /** Read the proof lines of one test file's content. Pure. */
20
+ function scanProofsInText(text, file) {
21
+ const testFile = toPosixPath(file);
22
+ const code = withoutBlockComments(text.split(/\r?\n/));
23
+ const findings = [];
24
+ const proofs = [];
25
+ /** Proofs waiting for the next code line, in file order. */
26
+ let pending = [];
27
+ const settle = (testLine) => {
28
+ if (pending.length === 0) return;
29
+ const test = testLine === null ? null : {
30
+ name: testName(code[testLine - 1] ?? ""),
31
+ line: testLine
32
+ };
33
+ for (const proof of pending) {
34
+ const ref = `${proof.feature}/${proof.flow}`;
35
+ const at = {
36
+ file: testFile,
37
+ line: proof.line,
38
+ column: null
39
+ };
40
+ proofs.push({
41
+ feature: proof.feature,
42
+ flow: proof.flow,
43
+ ref,
44
+ criterion: proof.criterion,
45
+ test,
46
+ at
47
+ });
48
+ if (!test) findings.push(createFinding({
49
+ code: "GR4004",
50
+ message: `"@proves ${ref} ${proof.criterion}" is not directly above a test`,
51
+ at,
52
+ feature: proof.feature,
53
+ flow: ref
54
+ }));
55
+ }
56
+ const distinct = [...new Set(pending.map((proof) => `${proof.feature}/${proof.flow} ${proof.criterion}`))];
57
+ const first = pending[0];
58
+ if (test && first && distinct.length > 1) findings.push(createFinding({
59
+ code: "GR4005",
60
+ message: `test ${test.name === null ? `on line ${test.line}` : JSON.stringify(test.name)} proves ${distinct.length} criteria: ${distinct.join(", ")}`,
61
+ at: {
62
+ file: testFile,
63
+ line: first.line,
64
+ column: null
65
+ },
66
+ feature: first.feature,
67
+ flow: `${first.feature}/${first.flow}`
68
+ }));
69
+ pending = [];
70
+ };
71
+ code.forEach((content, index) => {
72
+ const lineNumber = index + 1;
73
+ const proof = PROOF_LINE.exec(content);
74
+ if (proof) {
75
+ const target = PROOF_TARGET.exec(proof[1] ?? "");
76
+ if (target) pending.push({
77
+ feature: target[1] ?? "",
78
+ flow: target[2] ?? "",
79
+ criterion: target[3] ?? "",
80
+ line: lineNumber
81
+ });
82
+ else findings.push(malformed(testFile, lineNumber, content));
83
+ return;
84
+ }
85
+ const trimmed = content.trim();
86
+ if (trimmed === "" || trimmed.startsWith("//")) return;
87
+ if (TRAILING_PROOF.test(content)) findings.push(malformed(testFile, lineNumber, content));
88
+ settle(TEST_CALL.test(trimmed) ? lineNumber : null);
89
+ });
90
+ settle(null);
91
+ return {
92
+ proofs,
93
+ findings
94
+ };
95
+ }
96
+ /**
97
+ * Read the proof lines of every test file. Files that cannot be read (removed
98
+ * since the book was built) are skipped. Proofs and findings come out in
99
+ * file order, then line order.
100
+ *
101
+ * @param root Absolute project root.
102
+ * @param testFiles Project-relative test files (`BookFacts.tests`).
103
+ */
104
+ async function scanProofs(root, testFiles) {
105
+ const files = [...new Set(testFiles.map(toPosixPath))].sort();
106
+ const results = new Array(files.length);
107
+ let next = 0;
108
+ const worker = async () => {
109
+ while (next < files.length) {
110
+ const index = next++;
111
+ const file = files[index] ?? "";
112
+ try {
113
+ results[index] = scanProofsInText(await readFile(path.join(root, ...file.split("/")), "utf8"), file);
114
+ } catch {
115
+ results[index] = {
116
+ proofs: [],
117
+ findings: []
118
+ };
119
+ }
120
+ }
121
+ };
122
+ await Promise.all(Array.from({ length: Math.min(READ_CONCURRENCY, files.length) }, worker));
123
+ return {
124
+ proofs: results.flatMap((result) => result.proofs),
125
+ findings: results.flatMap((result) => result.findings)
126
+ };
127
+ }
128
+ function malformed(file, line, content) {
129
+ return createFinding({
130
+ code: "GR4003",
131
+ message: `"${content.trim()}" is not "// @proves <feature>/<flow> AC-<n>" on its own line`,
132
+ at: {
133
+ file,
134
+ line,
135
+ column: null
136
+ }
137
+ });
138
+ }
139
+ /**
140
+ * Each line with its block comments (`/* … *\/`, across lines) blanked out,
141
+ * so a `@proves` or a test call inside a block comment is never read. Line
142
+ * comments are kept. String contents are not considered.
143
+ */
144
+ function withoutBlockComments(lines) {
145
+ let open = false;
146
+ return lines.map((content) => {
147
+ let code = "";
148
+ let rest = content;
149
+ while (rest !== "") {
150
+ if (open) {
151
+ const close = rest.indexOf("*/");
152
+ if (close === -1) return code;
153
+ open = false;
154
+ rest = rest.slice(close + 2);
155
+ continue;
156
+ }
157
+ const block = rest.indexOf("/*");
158
+ const line = rest.indexOf("//");
159
+ if (block === -1 || line !== -1 && line < block) return code + rest;
160
+ code += rest.slice(0, block);
161
+ open = true;
162
+ rest = rest.slice(block + 2);
163
+ }
164
+ return code;
165
+ });
166
+ }
167
+ /**
168
+ * The name of the test a call line declares: the first string literal of the
169
+ * call that takes the name (after the arguments of `.each(…)`, `.skipIf(…)`…).
170
+ * `null` when the line does not hold it (a name on the next line, a variable).
171
+ */
172
+ function testName(content) {
173
+ const call = TEST_CALL.exec(content.trim());
174
+ if (!call) return null;
175
+ let rest = content.trim().slice(call[0].length - 1);
176
+ if (MODIFIER_WITH_ARGUMENTS.test(call[1] ?? "")) {
177
+ const end = rest.startsWith("`") ? closingQuote(rest, 0) : closingParen(rest);
178
+ if (end === -1) return null;
179
+ rest = rest.slice(end + 1).trimStart();
180
+ }
181
+ if (!rest.startsWith("(")) return null;
182
+ rest = rest.slice(1).trimStart();
183
+ const quote = rest[0];
184
+ if (quote !== "\"" && quote !== "'" && quote !== "`") return null;
185
+ const end = closingQuote(rest, 0);
186
+ return end === -1 ? null : rest.slice(1, end).replace(/\\(.)/g, "$1");
187
+ }
188
+ /** Index of the quote that closes the string opening at `start`, or -1. */
189
+ function closingQuote(text, start) {
190
+ const quote = text[start];
191
+ for (let index = start + 1; index < text.length; index++) if (text[index] === "\\") index++;
192
+ else if (text[index] === quote) return index;
193
+ return -1;
194
+ }
195
+ /** Index of the `)` that closes the `(` at index 0, skipping strings, or -1. */
196
+ function closingParen(text) {
197
+ let depth = 0;
198
+ for (let index = 0; index < text.length; index++) {
199
+ const char = text[index];
200
+ if (char === "\"" || char === "'" || char === "`") {
201
+ index = closingQuote(text, index);
202
+ if (index === -1) return -1;
203
+ } else if (char === "(" || char === "[" || char === "{") depth++;
204
+ else if (char === ")" || char === "]" || char === "}") {
205
+ depth--;
206
+ if (depth === 0) return index;
207
+ }
208
+ }
209
+ return -1;
210
+ }
211
+
212
+ //#endregion
213
+ export { scanProofs, scanProofsInText };
214
+ //# sourceMappingURL=scan-proofs.mjs.map
@@ -0,0 +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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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"}
@@ -0,0 +1,29 @@
1
+ import { WrittenGrimoire } from "../contracts/written.mjs";
2
+ import { ReleaseCollection, ReleaseEntry, WriteReleaseResult } from "../contracts/releases.mjs";
3
+ //#region ../../packages/grimoire/src/releases/index.d.ts
4
+ /** What `writeRelease()` returns: the contract result plus the entries it left out. */
5
+ export type WriteReleaseOutcome = WriteReleaseResult & {
6
+ /** Entries still under `## Unreleased`; not collected. */
7
+ unreleased: ReleaseEntry[];
8
+ };
9
+ /**
10
+ * The entries a release lists: the entries the agent stamped with that release
11
+ * (under `## <release> (<date>)`). Entries under `## Unreleased` are never
12
+ * collected. Throws a `GrimoireError` with `GR9005` when
13
+ * `grimoire/releases/<release>.md` does not exist, has no `release` and
14
+ * `date`, or has no brief.
15
+ */
16
+ export declare function collectRelease(written: WrittenGrimoire, release: string): ReleaseCollection;
17
+ /** The Markdown between (and including) the collected-list markers. Pure. */
18
+ export declare function renderCollectedList(collection: ReleaseCollection): string;
19
+ /**
20
+ * Collect the release and write the list into its file: replaces the text
21
+ * between the markers, or appends the markers and the list at the end. Never
22
+ * touches any other file or any text outside the markers. Refuses (`GR9005`)
23
+ * when the agent has not written the release file and its brief.
24
+ *
25
+ * @param root Absolute project root.
26
+ */
27
+ export declare function writeRelease(root: string, written: WrittenGrimoire, release: string): Promise<WriteReleaseOutcome>;
28
+ //#endregion
29
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/releases/index.ts"],"mappings":";;;;YAuBY,sBAAsB;;EAEhC,YAAY;;;;;;;;;wBA0DE,eAAe,SAAS,iBAAiB,kBAAkB;;wBA0C3D,oBAAoB,YAAY;;;;;;;;;wBAiC1B,aACpB,cACA,SAAS,iBACT,kBACC,QAAQ"}