@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.
Files changed (197) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/esm/book/build.d.mts.map +1 -1
  3. package/esm/book/build.mjs +24 -2
  4. package/esm/book/build.mjs.map +1 -1
  5. package/esm/check/check-grimoire.d.mts.map +1 -1
  6. package/esm/check/check-grimoire.mjs +11 -1
  7. package/esm/check/check-grimoire.mjs.map +1 -1
  8. package/esm/check/rules/api-snapshot.mjs +39 -0
  9. package/esm/check/rules/api-snapshot.mjs.map +1 -0
  10. package/esm/check/rules/code-rules.mjs +45 -0
  11. package/esm/check/rules/code-rules.mjs.map +1 -0
  12. package/esm/check/rules/drift.mjs +54 -0
  13. package/esm/check/rules/drift.mjs.map +1 -0
  14. package/esm/check/rules/focused-tests.mjs +39 -0
  15. package/esm/check/rules/focused-tests.mjs.map +1 -0
  16. package/esm/check/rules/shows.mjs +52 -0
  17. package/esm/check/rules/shows.mjs.map +1 -0
  18. package/esm/codes/codes.d.mts +48 -0
  19. package/esm/codes/codes.d.mts.map +1 -1
  20. package/esm/codes/codes.mjs +26 -1
  21. package/esm/codes/codes.mjs.map +1 -1
  22. package/esm/contracts/adapter.d.mts +6 -0
  23. package/esm/contracts/adapter.d.mts.map +1 -1
  24. package/esm/contracts/guard.d.mts +104 -0
  25. package/esm/contracts/guard.d.mts.map +1 -0
  26. package/esm/contracts/index.mjs +5 -0
  27. package/esm/contracts/matrix.d.mts +75 -0
  28. package/esm/contracts/matrix.d.mts.map +1 -0
  29. package/esm/contracts/scry.d.mts +42 -0
  30. package/esm/contracts/scry.d.mts.map +1 -1
  31. package/esm/contracts/settings.d.mts +71 -0
  32. package/esm/contracts/settings.d.mts.map +1 -0
  33. package/esm/contracts/settings.mjs +67 -0
  34. package/esm/contracts/settings.mjs.map +1 -0
  35. package/esm/contracts/shots.d.mts +146 -0
  36. package/esm/contracts/shots.d.mts.map +1 -0
  37. package/esm/contracts/snapshot.d.mts +10 -0
  38. package/esm/contracts/snapshot.d.mts.map +1 -1
  39. package/esm/contracts/written.d.mts +13 -0
  40. package/esm/contracts/written.d.mts.map +1 -1
  41. package/esm/contracts/written.mjs +7 -1
  42. package/esm/contracts/written.mjs.map +1 -1
  43. package/esm/devtools/approvals.mjs +59 -0
  44. package/esm/devtools/approvals.mjs.map +1 -0
  45. package/esm/devtools/data.mjs +2 -0
  46. package/esm/devtools/data.mjs.map +1 -1
  47. package/esm/devtools/graphs.mjs +13 -3
  48. package/esm/devtools/graphs.mjs.map +1 -1
  49. package/esm/devtools/index.d.mts +7 -0
  50. package/esm/devtools/index.d.mts.map +1 -1
  51. package/esm/devtools/index.mjs +33 -3
  52. package/esm/devtools/index.mjs.map +1 -1
  53. package/esm/devtools/matrix.mjs +207 -0
  54. package/esm/devtools/matrix.mjs.map +1 -0
  55. package/esm/devtools/product-map.d.mts.map +1 -1
  56. package/esm/devtools/product-map.mjs +87 -1
  57. package/esm/devtools/product-map.mjs.map +1 -1
  58. package/esm/devtools/site.d.mts.map +1 -1
  59. package/esm/devtools/site.mjs +12 -3
  60. package/esm/devtools/site.mjs.map +1 -1
  61. package/esm/devtools/snapshot-source.mjs +13 -3
  62. package/esm/devtools/snapshot-source.mjs.map +1 -1
  63. package/esm/git/index.d.mts +20 -0
  64. package/esm/git/index.d.mts.map +1 -0
  65. package/esm/git/index.mjs +280 -0
  66. package/esm/git/index.mjs.map +1 -0
  67. package/esm/guard/api.mjs +70 -0
  68. package/esm/guard/api.mjs.map +1 -0
  69. package/esm/guard/assertions.mjs +18 -0
  70. package/esm/guard/assertions.mjs.map +1 -0
  71. package/esm/guard/collect.mjs +139 -0
  72. package/esm/guard/collect.mjs.map +1 -0
  73. package/esm/guard/format.mjs +27 -0
  74. package/esm/guard/format.mjs.map +1 -0
  75. package/esm/guard/glob.mjs +79 -0
  76. package/esm/guard/glob.mjs.map +1 -0
  77. package/esm/guard/index.mjs +9 -0
  78. package/esm/guard/rules.mjs +310 -0
  79. package/esm/guard/rules.mjs.map +1 -0
  80. package/esm/guard/scope.mjs +95 -0
  81. package/esm/guard/scope.mjs.map +1 -0
  82. package/esm/index.d.mts +10 -3
  83. package/esm/index.mjs +6 -2
  84. package/esm/paths/index.d.mts +15 -1
  85. package/esm/paths/index.d.mts.map +1 -1
  86. package/esm/paths/index.mjs +27 -3
  87. package/esm/paths/index.mjs.map +1 -1
  88. package/esm/proves/index.mjs +2 -1
  89. package/esm/proves/scan-proofs.mjs +1 -1
  90. package/esm/proves/scan-proofs.mjs.map +1 -1
  91. package/esm/proves/scan-shows.d.mts +21 -0
  92. package/esm/proves/scan-shows.d.mts.map +1 -0
  93. package/esm/proves/scan-shows.mjs +168 -0
  94. package/esm/proves/scan-shows.mjs.map +1 -0
  95. package/esm/releases/index.d.mts.map +1 -1
  96. package/esm/releases/index.mjs +5 -3
  97. package/esm/releases/index.mjs.map +1 -1
  98. package/esm/releases/stamp.mjs +121 -0
  99. package/esm/releases/stamp.mjs.map +1 -0
  100. package/esm/rules/focused.mjs +26 -0
  101. package/esm/rules/focused.mjs.map +1 -0
  102. package/esm/rules/index.mjs +88 -0
  103. package/esm/rules/index.mjs.map +1 -0
  104. package/esm/rules/logical-css.mjs +112 -0
  105. package/esm/rules/logical-css.mjs.map +1 -0
  106. package/esm/rules/no-js-imports.mjs +22 -0
  107. package/esm/rules/no-js-imports.mjs.map +1 -0
  108. package/esm/rules/scan.mjs +196 -0
  109. package/esm/rules/scan.mjs.map +1 -0
  110. package/esm/rules/specific-errors.mjs +51 -0
  111. package/esm/rules/specific-errors.mjs.map +1 -0
  112. package/esm/rules/type-discriminator.mjs +27 -0
  113. package/esm/rules/type-discriminator.mjs.map +1 -0
  114. package/esm/scry/also-changes.mjs +107 -0
  115. package/esm/scry/also-changes.mjs.map +1 -0
  116. package/esm/scry/format.d.mts.map +1 -1
  117. package/esm/scry/format.mjs +35 -0
  118. package/esm/scry/format.mjs.map +1 -1
  119. package/esm/scry/query.d.mts.map +1 -1
  120. package/esm/scry/query.mjs +40 -2
  121. package/esm/scry/query.mjs.map +1 -1
  122. package/esm/scry/search.d.mts.map +1 -1
  123. package/esm/scry/search.mjs +43 -11
  124. package/esm/scry/search.mjs.map +1 -1
  125. package/esm/shots/approve.mjs +195 -0
  126. package/esm/shots/approve.mjs.map +1 -0
  127. package/esm/shots/drift.mjs +174 -0
  128. package/esm/shots/drift.mjs.map +1 -0
  129. package/esm/shots/png.mjs +166 -0
  130. package/esm/shots/png.mjs.map +1 -0
  131. package/esm/shots/state.mjs +43 -0
  132. package/esm/shots/state.mjs.map +1 -0
  133. package/esm/shots/store.mjs +66 -0
  134. package/esm/shots/store.mjs.map +1 -0
  135. package/esm/shots/touched.mjs +38 -0
  136. package/esm/shots/touched.mjs.map +1 -0
  137. package/esm/warlock/adapter.d.mts.map +1 -1
  138. package/esm/warlock/adapter.mjs +22 -2
  139. package/esm/warlock/adapter.mjs.map +1 -1
  140. package/esm/warlock/api-command.mjs +41 -0
  141. package/esm/warlock/api-command.mjs.map +1 -0
  142. package/esm/warlock/approve-command.mjs +80 -0
  143. package/esm/warlock/approve-command.mjs.map +1 -0
  144. package/esm/warlock/collect-off-thread.mjs +66 -0
  145. package/esm/warlock/collect-off-thread.mjs.map +1 -0
  146. package/esm/warlock/commands.d.mts +1 -1
  147. package/esm/warlock/commands.d.mts.map +1 -1
  148. package/esm/warlock/commands.mjs +61 -8
  149. package/esm/warlock/commands.mjs.map +1 -1
  150. package/esm/warlock/guard-command.mjs +116 -0
  151. package/esm/warlock/guard-command.mjs.map +1 -0
  152. package/esm/warlock/index.d.mts +2 -1
  153. package/esm/warlock/index.mjs +2 -1
  154. package/esm/warlock/languages.mjs +75 -0
  155. package/esm/warlock/languages.mjs.map +1 -0
  156. package/esm/warlock/mcp-tools.mjs +2 -2
  157. package/esm/warlock/mcp-tools.mjs.map +1 -1
  158. package/esm/warlock/release-command.mjs +65 -0
  159. package/esm/warlock/release-command.mjs.map +1 -0
  160. package/esm/warlock/shows.d.mts +35 -0
  161. package/esm/warlock/shows.d.mts.map +1 -0
  162. package/esm/warlock/shows.mjs +195 -0
  163. package/esm/warlock/shows.mjs.map +1 -0
  164. package/esm/workspace/cache.mjs +4 -1
  165. package/esm/workspace/cache.mjs.map +1 -1
  166. package/esm/workspace/derived.mjs +11 -6
  167. package/esm/workspace/derived.mjs.map +1 -1
  168. package/esm/workspace/index.d.mts.map +1 -1
  169. package/esm/workspace/index.mjs +8 -1
  170. package/esm/workspace/index.mjs.map +1 -1
  171. package/esm/workspace/stored.mjs +4 -1
  172. package/esm/workspace/stored.mjs.map +1 -1
  173. package/esm/written/features.mjs +21 -5
  174. package/esm/written/features.mjs.map +1 -1
  175. package/esm/written/index.mjs +2 -1
  176. package/esm/written/parse-grimoire.d.mts.map +1 -1
  177. package/esm/written/parse-grimoire.mjs +16 -3
  178. package/esm/written/parse-grimoire.mjs.map +1 -1
  179. package/esm/written/settings.d.mts +11 -0
  180. package/esm/written/settings.d.mts.map +1 -0
  181. package/esm/written/settings.mjs +88 -0
  182. package/esm/written/settings.mjs.map +1 -0
  183. package/llms-full.txt +282 -39
  184. package/llms.txt +2 -0
  185. package/package.json +3 -3
  186. package/skills/backfill-a-grimoire/SKILL.md +4 -0
  187. package/skills/describe-an-app/SKILL.md +4 -1
  188. package/skills/guard-a-change/SKILL.md +85 -0
  189. package/skills/index.md +7 -3
  190. package/skills/record-a-change/SKILL.md +52 -16
  191. package/skills/review-a-change/SKILL.md +53 -0
  192. package/skills/use-the-grimoire/SKILL.md +27 -18
  193. package/skills/write-a-feature/SKILL.md +42 -1
  194. package/ui/grimoire-view.js +756 -40
  195. package/ui/grimoire.css +303 -28
  196. package/ui/product-map.css +43 -7
  197. package/ui/product-map.js +212 -37
@@ -0,0 +1,70 @@
1
+ import { GRIMOIRE_PATHS } from "../paths/index.mjs";
2
+ import path from "node:path";
3
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
4
+
5
+ //#region ../../packages/grimoire/src/guard/api.ts
6
+ /**
7
+ * The approved public API: the HTTP routes the app serves, kept in
8
+ * `grimoire/approved/api.json` so that any change to them is deliberate.
9
+ */
10
+ /** The sorted route lines of a route list: `GET /orders [auth]`. Page routes are not API. */
11
+ function routeLines(routes) {
12
+ const lines = /* @__PURE__ */ new Set();
13
+ for (const route of routes) {
14
+ if (route.isPage) continue;
15
+ lines.add(`${route.method.toUpperCase()} ${route.path}${route.auth.required ? " [auth]" : ""}`);
16
+ }
17
+ return [...lines].sort();
18
+ }
19
+ /** An `api.json` text, or `null` when it is not one. */
20
+ function parseApiSnapshot(text) {
21
+ try {
22
+ const parsed = JSON.parse(text);
23
+ if (!Array.isArray(parsed.routes)) return null;
24
+ return {
25
+ schemaVersion: 1,
26
+ approvedAt: typeof parsed.approvedAt === "string" ? parsed.approvedAt : "",
27
+ routes: parsed.routes.filter((line) => typeof line === "string")
28
+ };
29
+ } catch {
30
+ return null;
31
+ }
32
+ }
33
+ /** `grimoire/approved/api.json`, or `null` when it was never approved or cannot be read. */
34
+ async function readApiSnapshot(root) {
35
+ try {
36
+ return parseApiSnapshot(await readFile(path.join(root, ...GRIMOIRE_PATHS.apiSnapshot.split("/")), "utf8"));
37
+ } catch {
38
+ return null;
39
+ }
40
+ }
41
+ /** Write `grimoire/approved/api.json`. */
42
+ async function writeApiSnapshot(root, routes, now = /* @__PURE__ */ new Date()) {
43
+ const snapshot = {
44
+ schemaVersion: 1,
45
+ approvedAt: now.toISOString(),
46
+ routes: [...routes].sort()
47
+ };
48
+ const file = path.join(root, ...GRIMOIRE_PATHS.apiSnapshot.split("/"));
49
+ await mkdir(path.dirname(file), { recursive: true });
50
+ await writeFile(file, `${JSON.stringify(snapshot, null, 2)}\n`);
51
+ return snapshot;
52
+ }
53
+ /** The routes added to and removed from the approved list. */
54
+ function diffRoutes(approved, current) {
55
+ const before = new Set(approved);
56
+ const after = new Set(current);
57
+ return {
58
+ added: current.filter((line) => !before.has(line)),
59
+ removed: approved.filter((line) => !after.has(line))
60
+ };
61
+ }
62
+ /** A short text of a route difference: `added GET /a, removed POST /b`. */
63
+ function describeRouteDiff(diff) {
64
+ const part = (label, lines) => lines.length === 0 ? "" : `${label} ${lines.slice(0, 5).join(", ")}${lines.length > 5 ? `, … ${lines.length - 5} more` : ""}`;
65
+ return [part("added", diff.added), part("removed", diff.removed)].filter(Boolean).join("; ");
66
+ }
67
+
68
+ //#endregion
69
+ export { describeRouteDiff, diffRoutes, parseApiSnapshot, readApiSnapshot, routeLines, writeApiSnapshot };
70
+ //# sourceMappingURL=api.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/guard/api.ts"],"sourcesContent":["/**\n * The approved public API: the HTTP routes the app serves, kept in\n * `grimoire/approved/api.json` so that any change to them is deliberate.\n */\nimport { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { BookRoute } from \"../contracts/adapter\";\nimport type { ApiSnapshot } from \"../contracts/guard\";\nimport { GRIMOIRE_PATHS } from \"../paths\";\n\n/** The sorted route lines of a route list: `GET /orders [auth]`. Page routes are not API. */\nexport function routeLines(routes: readonly BookRoute[]): string[] {\n const lines = new Set<string>();\n\n for (const route of routes) {\n if (route.isPage) continue;\n\n lines.add(`${route.method.toUpperCase()} ${route.path}${route.auth.required ? \" [auth]\" : \"\"}`);\n }\n\n return [...lines].sort();\n}\n\n/** An `api.json` text, or `null` when it is not one. */\nexport function parseApiSnapshot(text: string): ApiSnapshot | null {\n try {\n const parsed = JSON.parse(text) as Partial<ApiSnapshot>;\n\n if (!Array.isArray(parsed.routes)) return null;\n\n return {\n schemaVersion: 1,\n approvedAt: typeof parsed.approvedAt === \"string\" ? parsed.approvedAt : \"\",\n routes: parsed.routes.filter((line): line is string => typeof line === \"string\"),\n };\n } catch {\n return null;\n }\n}\n\n/** `grimoire/approved/api.json`, or `null` when it was never approved or cannot be read. */\nexport async function readApiSnapshot(root: string): Promise<ApiSnapshot | null> {\n try {\n return parseApiSnapshot(\n await readFile(path.join(root, ...GRIMOIRE_PATHS.apiSnapshot.split(\"/\")), \"utf8\"),\n );\n } catch {\n return null;\n }\n}\n\n/** Write `grimoire/approved/api.json`. */\nexport async function writeApiSnapshot(\n root: string,\n routes: readonly string[],\n now: Date = new Date(),\n): Promise<ApiSnapshot> {\n const snapshot: ApiSnapshot = {\n schemaVersion: 1,\n approvedAt: now.toISOString(),\n routes: [...routes].sort(),\n };\n const file = path.join(root, ...GRIMOIRE_PATHS.apiSnapshot.split(\"/\"));\n\n await mkdir(path.dirname(file), { recursive: true });\n await writeFile(file, `${JSON.stringify(snapshot, null, 2)}\\n`);\n\n return snapshot;\n}\n\n/** The routes added to and removed from the approved list. */\nexport function diffRoutes(\n approved: readonly string[],\n current: readonly string[],\n): { added: string[]; removed: string[] } {\n const before = new Set(approved);\n const after = new Set(current);\n\n return {\n added: current.filter((line) => !before.has(line)),\n removed: approved.filter((line) => !after.has(line)),\n };\n}\n\n/** A short text of a route difference: `added GET /a, removed POST /b`. */\nexport function describeRouteDiff(diff: { added: string[]; removed: string[] }): string {\n const part = (label: string, lines: string[]): string =>\n lines.length === 0\n ? \"\"\n : `${label} ${lines.slice(0, 5).join(\", \")}${lines.length > 5 ? `, … ${lines.length - 5} more` : \"\"}`;\n\n return [part(\"added\", diff.added), part(\"removed\", diff.removed)].filter(Boolean).join(\"; \");\n}\n"],"mappings":";;;;;;;;;;AAWA,SAAgB,WAAW,QAAwC;CACjE,MAAM,wBAAQ,IAAI,IAAY;CAE9B,KAAK,MAAM,SAAS,QAAQ;EAC1B,IAAI,MAAM,QAAQ;EAElB,MAAM,IAAI,GAAG,MAAM,OAAO,YAAY,EAAE,GAAG,MAAM,OAAO,MAAM,KAAK,WAAW,YAAY,IAAI;CAChG;CAEA,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,KAAK;AACzB;;AAGA,SAAgB,iBAAiB,MAAkC;CACjE,IAAI;E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AI,IAAI,MAAM,SAAS,IAAI,OAAO,MAAM,SAAS,EAAE,SAAS;CAErG,OAAO,CAAC,KAAK,SAAS,KAAK,KAAK,GAAG,KAAK,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,IAAI;AAC7F"}
@@ -0,0 +1,18 @@
1
+ import { scanSource } from "../rules/scan.mjs";
2
+
3
+ //#region ../../packages/grimoire/src/guard/assertions.ts
4
+ /**
5
+ * Counting a test file's assertions: `expect(`, `expect.soft(`,
6
+ * `expect.poll(`, `assert(`, `assert.<word>(` and `.should(`. Comments and
7
+ * strings are skipped by the source scanner. Limit: an assertion helper
8
+ * of your own (`checkTotals(…)`) is not counted.
9
+ */
10
+ const ASSERTION = /(?<![\w$.])(?:expect(?:\.(?:soft|poll))?|assert(?:\.\w+)?)\s*\(|\.should\s*\(/g;
11
+ /** How many assertions the text holds. */
12
+ function countAssertions(text) {
13
+ return [...scanSource(text, "code").bare.matchAll(ASSERTION)].length;
14
+ }
15
+
16
+ //#endregion
17
+ export { countAssertions };
18
+ //# sourceMappingURL=assertions.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertions.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/guard/assertions.ts"],"sourcesContent":["/**\n * Counting a test file's assertions: `expect(`, `expect.soft(`,\n * `expect.poll(`, `assert(`, `assert.<word>(` and `.should(`. Comments and\n * strings are skipped by the source scanner. Limit: an assertion helper\n * of your own (`checkTotals(…)`) is not counted.\n */\nimport { scanSource } from \"../rules/scan\";\n\nconst ASSERTION = /(?<![\\w$.])(?:expect(?:\\.(?:soft|poll))?|assert(?:\\.\\w+)?)\\s*\\(|\\.should\\s*\\(/g;\n\n/** How many assertions the text holds. */\nexport function countAssertions(text: string): number {\n return [...scanSource(text, \"code\").bare.matchAll(ASSERTION)].length;\n}\n"],"mappings":";;;;;;;;;AAQA,MAAM,YAAY;;AAGlB,SAAgB,gBAAgB,MAAsB;CACpD,OAAO,CAAC,GAAG,WAAW,MAAM,MAAM,CAAC,CAAC,KAAK,SAAS,SAAS,CAAC,CAAC,CAAC;AAChE"}
@@ -0,0 +1,139 @@
1
+ import { DEFAULT_GRIMOIRE_SETTINGS } from "../contracts/settings.mjs";
2
+ import { GrimoireError } from "../codes/index.mjs";
3
+ import { parseGrimoire } from "../written/parse-grimoire.mjs";
4
+ import "../written/index.mjs";
5
+ import { readApiSnapshot, routeLines } from "./api.mjs";
6
+ import { matchesAny } from "./glob.mjs";
7
+ import { findTask, mergeScopes, readTaskScope } from "./scope.mjs";
8
+ import { commitsIn, filesAt, showFile } from "../git/index.mjs";
9
+ import path from "node:path";
10
+ import { mkdir, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
11
+ import { tmpdir } from "node:os";
12
+
13
+ //#region ../../packages/grimoire/src/guard/collect.ts
14
+ /**
15
+ * Gathering a {@link GuardInput}: the part of the guard that talks to git
16
+ * and the file system. The rules themselves are in `rules.ts`.
17
+ */
18
+ /** Files Warlock writes and git ignores; they never count as changes (the snapshot is opened after `git` lists the change, but a project may lack the ignore lines). */
19
+ const GENERATED = [
20
+ "grimoire/book/**",
21
+ "grimoire/screenshots/captured/**",
22
+ "grimoire/features/index.json",
23
+ "grimoire/features/**/bookmap.json",
24
+ "grimoire/features/**/*.bookmap.json",
25
+ "grimoire/tasks/index.json"
26
+ ];
27
+ const TEXT_FILE = /\.(?:[cm]?[jt]sx?|css|scss|less|json)$/;
28
+ const MAX_TEXT = 1048576;
29
+ /** The changes the guard looks at: git's list without the files Warlock generates. */
30
+ function guardedChanges(changed) {
31
+ return changed.filter((change) => !matchesAny(change.file, GENERATED));
32
+ }
33
+ async function readCurrent(root, file) {
34
+ const absolute = path.join(root, ...file.split("/"));
35
+ try {
36
+ if ((await stat(absolute)).size > MAX_TEXT) return null;
37
+ return await readFile(absolute, "utf8");
38
+ } catch {
39
+ return null;
40
+ }
41
+ }
42
+ /** The text of every changed code, style and JSON file, now and at the base. */
43
+ async function readTexts(root, base, changed) {
44
+ const texts = {};
45
+ for (const change of changed) {
46
+ if (!TEXT_FILE.test(change.file) && !(change.from !== null && TEXT_FILE.test(change.from))) continue;
47
+ const before = change.status === "added" ? null : await showFile(root, base, change.from ?? change.file);
48
+ texts[change.file] = {
49
+ base: before !== null && before.length > MAX_TEXT ? null : before,
50
+ current: change.status === "deleted" ? null : await readCurrent(root, change.file)
51
+ };
52
+ }
53
+ return texts;
54
+ }
55
+ /** The written features at the base, parsed from a temporary copy; `null` when the change touches none. */
56
+ async function readBaseWritten(root, base, changed) {
57
+ if (!changed.some((change) => [change.file, change.from ?? ""].some((file) => file.startsWith("grimoire/features/")))) return null;
58
+ const folder = await mkdtemp(path.join(tmpdir(), "grimoire-guard-"));
59
+ try {
60
+ for (const file of await filesAt(root, base, "grimoire/features")) {
61
+ if (!file.endsWith(".md")) continue;
62
+ const text = await showFile(root, base, file);
63
+ if (text === null) continue;
64
+ const target = path.join(folder, ...file.split("/"));
65
+ await mkdir(path.dirname(target), { recursive: true });
66
+ await writeFile(target, text);
67
+ }
68
+ return (await parseGrimoire(folder)).written;
69
+ } finally {
70
+ await rm(folder, {
71
+ recursive: true,
72
+ force: true
73
+ });
74
+ }
75
+ }
76
+ /** The task ids the commit messages name (`T-12`), in the order they appear. */
77
+ function taskIdsIn(commits) {
78
+ const ids = [];
79
+ for (const commit of commits) for (const match of `${commit.subject}\n${commit.body}`.matchAll(/\bT-(\d+)\b/g)) {
80
+ const id = `T-${Number(match[1])}`;
81
+ if (!ids.includes(id)) ids.push(id);
82
+ }
83
+ return ids;
84
+ }
85
+ /**
86
+ * The task(s) the change is checked against: the argument, else the tasks
87
+ * the commits name, else the one task `in progress`. `null` when none.
88
+ * Throws `GR9008` when the argument names no task file.
89
+ */
90
+ function resolveScope(snapshot, argument, commits) {
91
+ const { written } = snapshot;
92
+ if (argument !== void 0 && argument.trim() !== "") {
93
+ const task = findTask(written, argument);
94
+ if (task === null) throw new GrimoireError("GR9008", `${JSON.stringify(argument)} matches no task file under grimoire/tasks. Pass an id like T-12.`);
95
+ return readTaskScope(task);
96
+ }
97
+ if (commits !== null) {
98
+ const named = taskIdsIn(commits).flatMap((id) => {
99
+ const task = findTask(written, id);
100
+ return task === null ? [] : [task];
101
+ });
102
+ if (named.length > 0) return mergeScopes(named.map(readTaskScope));
103
+ }
104
+ const active = written.tasks.filter((task) => task.status.value === "in progress");
105
+ return active.length === 1 && active[0] ? readTaskScope(active[0]) : null;
106
+ }
107
+ /** Gather everything the rules read. `snapshot` is opened by the caller. */
108
+ async function collectGuardInput(root, snapshot, changed, options) {
109
+ const commits = options.commits === void 0 ? null : await commitsIn(root, options.commits);
110
+ const flowFiles = {};
111
+ for (const [ref, flow] of Object.entries(snapshot.collected.flows)) flowFiles[ref] = [...new Set(flow.steps.flatMap((step) => [
112
+ ...step.files,
113
+ ...step.typeOnlyFiles,
114
+ ...step.entries
115
+ ]))];
116
+ const routes = snapshot.book.facts.routes;
117
+ return {
118
+ scope: resolveScope(snapshot, options.task, commits),
119
+ changed: [...changed],
120
+ texts: await readTexts(root, options.base, changed),
121
+ ownership: snapshot.ownership,
122
+ flowFiles,
123
+ proofs: snapshot.proofs,
124
+ baseWritten: await readBaseWritten(root, options.base, changed),
125
+ written: snapshot.written,
126
+ settings: snapshot.settings ?? DEFAULT_GRIMOIRE_SETTINGS,
127
+ testFiles: snapshot.book.facts.tests,
128
+ api: {
129
+ approved: await readApiSnapshot(root),
130
+ routes: routes === null ? null : routeLines(routes)
131
+ },
132
+ commits,
133
+ taskIds: snapshot.written.tasks.map((task) => task.id.value)
134
+ };
135
+ }
136
+
137
+ //#endregion
138
+ export { collectGuardInput, guardedChanges, readBaseWritten, readTexts, resolveScope, taskIdsIn };
139
+ //# sourceMappingURL=collect.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collect.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/guard/collect.ts"],"sourcesContent":["/**\n * Gathering a {@link GuardInput}: the part of the guard that talks to git\n * and the file system. The rules themselves are in `rules.ts`.\n */\nimport { mkdtemp, mkdir, readFile, rm, stat, writeFile } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport path from \"node:path\";\nimport { GrimoireError } from \"../codes\";\nimport type { GuardFileText, GuardInput, TaskScope } from \"../contracts/guard\";\nimport { DEFAULT_GRIMOIRE_SETTINGS } from \"../contracts/settings\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport type { WrittenGrimoire } from \"../contracts/written\";\nimport { commitsIn, filesAt, showFile, type ChangedFile, type CommitInfo } from \"../git\";\nimport { parseGrimoire } from \"../written\";\nimport { readApiSnapshot, routeLines } from \"./api\";\nimport { matchesAny } from \"./glob\";\nimport { findTask, mergeScopes, readTaskScope } from \"./scope\";\n\n/** Files Warlock writes and git ignores; they never count as changes (the snapshot is opened after `git` lists the change, but a project may lack the ignore lines). */\nconst GENERATED = [\n \"grimoire/book/**\",\n \"grimoire/screenshots/captured/**\",\n \"grimoire/features/index.json\",\n \"grimoire/features/**/bookmap.json\",\n \"grimoire/features/**/*.bookmap.json\",\n \"grimoire/tasks/index.json\",\n];\n\nconst TEXT_FILE = /\\.(?:[cm]?[jt]sx?|css|scss|less|json)$/;\nconst MAX_TEXT = 1024 * 1024;\n\n/** The changes the guard looks at: git's list without the files Warlock generates. */\nexport function guardedChanges(changed: readonly ChangedFile[]): ChangedFile[] {\n return changed.filter((change) => !matchesAny(change.file, GENERATED));\n}\n\nasync function readCurrent(root: string, file: string): Promise<string | null> {\n const absolute = path.join(root, ...file.split(\"/\"));\n\n try {\n if ((await stat(absolute)).size > MAX_TEXT) return null;\n\n return await readFile(absolute, \"utf8\");\n } catch {\n return null;\n }\n}\n\n/** The text of every changed code, style and JSON file, now and at the base. */\nexport async function readTexts(\n root: string,\n base: string,\n changed: readonly ChangedFile[],\n): Promise<Record<string, GuardFileText>> {\n const texts: Record<string, GuardFileText> = {};\n\n for (const change of changed) {\n if (!TEXT_FILE.test(change.file) && !(change.from !== null && TEXT_FILE.test(change.from)))\n continue;\n\n const before =\n change.status === \"added\" ? null : await showFile(root, base, change.from ?? change.file);\n\n texts[change.file] = {\n base: before !== null && before.length > MAX_TEXT ? null : before,\n current: change.status === \"deleted\" ? null : await readCurrent(root, change.file),\n };\n }\n\n return texts;\n}\n\n/** The written features at the base, parsed from a temporary copy; `null` when the change touches none. */\nexport async function readBaseWritten(\n root: string,\n base: string,\n changed: readonly ChangedFile[],\n): Promise<WrittenGrimoire | null> {\n const touchesFeatures = changed.some((change) =>\n [change.file, change.from ?? \"\"].some((file) => file.startsWith(\"grimoire/features/\")),\n );\n\n if (!touchesFeatures) return null;\n\n const folder = await mkdtemp(path.join(tmpdir(), \"grimoire-guard-\"));\n\n try {\n for (const file of await filesAt(root, base, \"grimoire/features\")) {\n if (!file.endsWith(\".md\")) continue;\n\n const text = await showFile(root, base, file);\n\n if (text === null) continue;\n\n const target = path.join(folder, ...file.split(\"/\"));\n\n await mkdir(path.dirname(target), { recursive: true });\n await writeFile(target, text);\n }\n\n return (await parseGrimoire(folder)).written;\n } finally {\n await rm(folder, { recursive: true, force: true });\n }\n}\n\n/** The task ids the commit messages name (`T-12`), in the order they appear. */\nexport function taskIdsIn(commits: readonly CommitInfo[]): string[] {\n const ids: string[] = [];\n\n for (const commit of commits) {\n for (const match of `${commit.subject}\\n${commit.body}`.matchAll(/\\bT-(\\d+)\\b/g)) {\n const id = `T-${Number(match[1])}`;\n\n if (!ids.includes(id)) ids.push(id);\n }\n }\n\n return ids;\n}\n\n/**\n * The task(s) the change is checked against: the argument, else the tasks\n * the commits name, else the one task `in progress`. `null` when none.\n * Throws `GR9008` when the argument names no task file.\n */\nexport function resolveScope(\n snapshot: GrimoireSnapshot,\n argument: string | undefined,\n commits: readonly CommitInfo[] | null,\n): TaskScope | null {\n const { written } = snapshot;\n\n if (argument !== undefined && argument.trim() !== \"\") {\n const task = findTask(written, argument);\n\n if (task === null) {\n throw new GrimoireError(\n \"GR9008\",\n `${JSON.stringify(argument)} matches no task file under grimoire/tasks. Pass an id like T-12.`,\n );\n }\n\n return readTaskScope(task);\n }\n\n if (commits !== null) {\n const named = taskIdsIn(commits).flatMap((id) => {\n const task = findTask(written, id);\n\n return task === null ? [] : [task];\n });\n\n if (named.length > 0) return mergeScopes(named.map(readTaskScope));\n }\n\n const active = written.tasks.filter((task) => task.status.value === \"in progress\");\n\n return active.length === 1 && active[0] ? readTaskScope(active[0]) : null;\n}\n\n/** What the command was asked. */\nexport type GuardOptions = { task?: string; base: string; commits?: string };\n\n/** Gather everything the rules read. `snapshot` is opened by the caller. */\nexport async function collectGuardInput(\n root: string,\n snapshot: GrimoireSnapshot,\n changed: readonly ChangedFile[],\n options: GuardOptions,\n): Promise<GuardInput> {\n const commits = options.commits === undefined ? null : await commitsIn(root, options.commits);\n const flowFiles: Record<string, string[]> = {};\n\n for (const [ref, flow] of Object.entries(snapshot.collected.flows)) {\n flowFiles[ref] = [\n ...new Set(\n flow.steps.flatMap((step) => [...step.files, ...step.typeOnlyFiles, ...step.entries]),\n ),\n ];\n }\n\n const routes = snapshot.book.facts.routes;\n\n return {\n scope: resolveScope(snapshot, options.task, commits),\n changed: [...changed],\n texts: await readTexts(root, options.base, changed),\n ownership: snapshot.ownership,\n flowFiles,\n proofs: snapshot.proofs,\n baseWritten: await readBaseWritten(root, options.base, changed),\n written: snapshot.written,\n settings: snapshot.settings ?? DEFAULT_GRIMOIRE_SETTINGS,\n testFiles: snapshot.book.facts.tests,\n api: {\n approved: await readApiSnapshot(root),\n routes: routes === null ? null : routeLines(routes),\n },\n commits,\n taskIds: snapshot.written.tasks.map((task) => task.id.value),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,MAAM,YAAY;CAChB;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,YAAY;AAClB,MAAM,WAAW;;AAGjB,SAAgB,eAAe,SAAgD;CAC7E,OAAO,QAAQ,QAAQ,WAAW,CAAC,WAAW,OAAO,MAAM,SAAS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AAU,QAAQ,YAAY,SAAY,OAAO,MAAM,UAAU,MAAM,QAAQ,OAAO;CAC5F,MAAM,YAAsC,CAAC;CAE7C,KAAK,MAAM,CAAC,KAAK,SAAS,OAAO,QAAQ,SAAS,UAAU,KAAK,GAC/D,UAAU,OAAO,CACf,GAAG,IAAI,IACL,KAAK,MAAM,SAAS,SAAS;EAAC,GAAG,KAAK;EAAO,GAAG,KAAK;EAAe,GAAG,KAAK;CAAO,CAAC,CACtF,CACF;CAGF,MAAM,SAAS,SAAS,KAAK,MAAM;CAEnC,OAAO;EACL,OAAO,aAAa,UAAU,QAAQ,MAAM,OAAO;EACnD,SAAS,CAAC,GAAG,OAAO;EACpB,OAAO,MAAM,UAAU,MAAM,QAAQ,MAAM,OAAO;EAClD,WAAW,SAAS;EACpB;EACA,QAAQ,SAAS;EACjB,aAAa,MAAM,gBAAgB,MAAM,QAAQ,MAAM,OAAO;EAC9D,SAAS,SAAS;EAClB,UAAU,SAAS,YAAY;EAC/B,WAAW,SAAS,KAAK,MAAM;EAC/B,KAAK;GACH,UAAU,MAAM,gBAAgB,IAAI;GACpC,QAAQ,WAAW,OAAO,OAAO,WAAW,MAAM;EACpD;EACA;EACA,SAAS,SAAS,QAAQ,MAAM,KAAK,SAAS,KAAK,GAAG,KAAK;CAC7D;AACF"}
@@ -0,0 +1,27 @@
1
+ import { formatCheckReport } from "../check/format-check-report.mjs";
2
+
3
+ //#region ../../packages/grimoire/src/guard/format.ts
4
+ /** The text of a guard report: the check's finding lines, the changes not approved, and the verdict. */
5
+ /** Lines for `warlock grimoire guard` (no `--json`). */
6
+ function formatGuardReport(report, root) {
7
+ const check = {
8
+ schemaVersion: 1,
9
+ root,
10
+ findings: report.findings,
11
+ counts: report.counts,
12
+ ok: report.ok,
13
+ routes: "cached"
14
+ };
15
+ const lines = formatCheckReport(check, { all: true }).slice(0, -1);
16
+ if (report.notApproved.length > 0) {
17
+ lines.push(`not approved: ${report.notApproved.length} change${report.notApproved.length === 1 ? "" : "s"}`);
18
+ for (const item of report.notApproved) lines.push(` ${item.id}`);
19
+ }
20
+ const { errors, warnings } = report.counts;
21
+ lines.push(report.ok ? `guard: ok${warnings > 0 ? ` (${warnings} warning${warnings === 1 ? "" : "s"})` : ""}` : `guard: ${errors} error${errors === 1 ? "" : "s"}`);
22
+ return lines;
23
+ }
24
+
25
+ //#endregion
26
+ export { formatGuardReport };
27
+ //# sourceMappingURL=format.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/guard/format.ts"],"sourcesContent":["/** The text of a guard report: the check's finding lines, the changes not approved, and the verdict. */\nimport { formatCheckReport } from \"../check/format-check-report\";\nimport type { GrimoireCheckReport } from \"../contracts/findings\";\nimport type { GuardReport } from \"../contracts/guard\";\n\n/** Lines for `warlock grimoire guard` (no `--json`). */\nexport function formatGuardReport(report: GuardReport, root: string): string[] {\n const check: GrimoireCheckReport = {\n schemaVersion: 1,\n root,\n findings: report.findings,\n counts: report.counts,\n ok: report.ok,\n routes: \"cached\",\n };\n const lines = formatCheckReport(check, { all: true }).slice(0, -1);\n\n if (report.notApproved.length > 0) {\n lines.push(\n `not approved: ${report.notApproved.length} change${report.notApproved.length === 1 ? \"\" : \"s\"}`,\n );\n\n for (const item of report.notApproved) lines.push(` ${item.id}`);\n }\n\n const { errors, warnings } = report.counts;\n\n lines.push(\n report.ok\n ? `guard: ok${warnings > 0 ? ` (${warnings} warning${warnings === 1 ? \"\" : \"s\"})` : \"\"}`\n : `guard: ${errors} error${errors === 1 ? \"\" : \"s\"}`,\n );\n\n return lines;\n}\n"],"mappings":";;;;;AAMA,SAAgB,kBAAkB,QAAqB,MAAwB;CAC7E,MAAM,QAA6B;EACjC,eAAe;EACf;EACA,UAAU,OAAO;EACjB,QAAQ,OAAO;EACf,IAAI,OAAO;EACX,QAAQ;CACV;CACA,MAAM,QAAQ,kBAAkB,OAAO,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,GAAG,EAAE;CAEjE,IAAI,OAAO,YAAY,SAAS,GAAG;EACjC,MAAM,KACJ,iBAAiB,OAAO,YAAY,OAAO,SAAS,OAAO,YAAY,WAAW,IAAI,KAAK,KAC7F;EAEA,KAAK,MAAM,QAAQ,OAAO,aAAa,MAAM,KAAK,KAAK,KAAK,IAAI;CAClE;CAEA,MAAM,EAAE,QAAQ,aAAa,OAAO;CAEpC,MAAM,KACJ,OAAO,KACH,YAAY,WAAW,IAAI,KAAK,SAAS,UAAU,aAAa,IAAI,KAAK,IAAI,KAAK,OAClF,UAAU,OAAO,QAAQ,WAAW,IAAI,KAAK,KACnD;CAEA,OAAO;AACT"}
@@ -0,0 +1,79 @@
1
+ //#region ../../packages/grimoire/src/guard/glob.ts
2
+ /**
3
+ * The small glob language of `Files:`, `Locked:` and the protected areas:
4
+ * `**` crosses folders, `*` and `?` stay inside one, `{a,b}` picks one.
5
+ * A plain path (no wildcard) matches itself and everything under it.
6
+ */
7
+ const cache = /* @__PURE__ */ new Map();
8
+ /** Split a comma list, leaving commas inside `{…}` alone. Entries are trimmed; empty ones dropped. */
9
+ function splitList(value) {
10
+ const parts = [];
11
+ let depth = 0;
12
+ let current = "";
13
+ for (const char of value) {
14
+ if (char === "{") depth++;
15
+ if (char === "}") depth = Math.max(0, depth - 1);
16
+ if (char === "," && depth === 0) {
17
+ parts.push(current);
18
+ current = "";
19
+ continue;
20
+ }
21
+ current += char;
22
+ }
23
+ parts.push(current);
24
+ return parts.map((part) => part.trim().replace(/^`+|`+$/g, "").trim()).filter((part) => part !== "");
25
+ }
26
+ function escapeRegExp(char) {
27
+ return /[\\^$.*+?()[\]{}|/-]/.test(char) ? `\\${char}` : char;
28
+ }
29
+ function toSource(glob) {
30
+ let source = "";
31
+ let braces = 0;
32
+ for (let index = 0; index < glob.length; index++) {
33
+ const char = glob[index] ?? "";
34
+ if (char === "*") {
35
+ if (glob[index + 1] === "*") {
36
+ if (glob[index + 2] === "/") {
37
+ source += "(?:.*/)?";
38
+ index += 2;
39
+ } else {
40
+ source += ".*";
41
+ index += 1;
42
+ }
43
+ } else source += "[^/]*";
44
+ } else if (char === "?") source += "[^/]";
45
+ else if (char === "{") {
46
+ braces++;
47
+ source += "(?:";
48
+ } else if (char === "}" && braces > 0) {
49
+ braces--;
50
+ source += ")";
51
+ } else if (char === "," && braces > 0) source += "|";
52
+ else source += escapeRegExp(char);
53
+ }
54
+ return source + ")".repeat(braces);
55
+ }
56
+ /** The pattern of a glob. */
57
+ function globToRegExp(glob) {
58
+ const key = glob;
59
+ const known = cache.get(key);
60
+ if (known) return known;
61
+ const normalized = glob.replace(/\\/g, "/").replace(/^\.\//, "");
62
+ const plain = !/[*?{]/.test(normalized);
63
+ const folder = normalized.replace(/\/+$/, "");
64
+ const regex = plain ? new RegExp(`^${toSource(folder)}(?:/.*)?$`) : new RegExp(`^${toSource(normalized.endsWith("/") ? `${folder}/**` : normalized)}$`);
65
+ cache.set(key, regex);
66
+ return regex;
67
+ }
68
+ /** Whether a project-relative path matches the glob. */
69
+ function matchesGlob(file, glob) {
70
+ return globToRegExp(glob).test(file.replace(/\\/g, "/"));
71
+ }
72
+ /** Whether a path matches any of the globs. */
73
+ function matchesAny(file, globs) {
74
+ return globs.some((glob) => matchesGlob(file, glob));
75
+ }
76
+
77
+ //#endregion
78
+ export { globToRegExp, matchesAny, matchesGlob, splitList };
79
+ //# sourceMappingURL=glob.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"glob.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/guard/glob.ts"],"sourcesContent":["/**\n * The small glob language of `Files:`, `Locked:` and the protected areas:\n * `**` crosses folders, `*` and `?` stay inside one, `{a,b}` picks one.\n * A plain path (no wildcard) matches itself and everything under it.\n */\n\nconst cache = new Map<string, RegExp>();\n\n/** Split a comma list, leaving commas inside `{…}` alone. Entries are trimmed; empty ones dropped. */\nexport function splitList(value: string): string[] {\n const parts: string[] = [];\n let depth = 0;\n let current = \"\";\n\n for (const char of value) {\n if (char === \"{\") depth++;\n if (char === \"}\") depth = Math.max(0, depth - 1);\n\n if (char === \",\" && depth === 0) {\n parts.push(current);\n current = \"\";\n continue;\n }\n\n current += char;\n }\n\n parts.push(current);\n\n return parts\n .map((part) =>\n part\n .trim()\n .replace(/^`+|`+$/g, \"\")\n .trim(),\n )\n .filter((part) => part !== \"\");\n}\n\nfunction escapeRegExp(char: string): string {\n return /[\\\\^$.*+?()[\\]{}|/-]/.test(char) ? `\\\\${char}` : char;\n}\n\nfunction toSource(glob: string): string {\n let source = \"\";\n let braces = 0;\n\n for (let index = 0; index < glob.length; index++) {\n const char = glob[index] ?? \"\";\n\n if (char === \"*\") {\n if (glob[index + 1] === \"*\") {\n const after = glob[index + 2];\n\n if (after === \"/\") {\n source += \"(?:.*/)?\";\n index += 2;\n } else {\n source += \".*\";\n index += 1;\n }\n } else {\n source += \"[^/]*\";\n }\n } else if (char === \"?\") source += \"[^/]\";\n else if (char === \"{\") {\n braces++;\n source += \"(?:\";\n } else if (char === \"}\" && braces > 0) {\n braces--;\n source += \")\";\n } else if (char === \",\" && braces > 0) source += \"|\";\n else source += escapeRegExp(char);\n }\n\n return source + \")\".repeat(braces);\n}\n\n/** The pattern of a glob. */\nexport function globToRegExp(glob: string): RegExp {\n const key = glob;\n const known = cache.get(key);\n\n if (known) return known;\n\n const normalized = glob.replace(/\\\\/g, \"/\").replace(/^\\.\\//, \"\");\n const plain = !/[*?{]/.test(normalized);\n const folder = normalized.replace(/\\/+$/, \"\");\n const regex = plain\n ? new RegExp(`^${toSource(folder)}(?:/.*)?$`)\n : new RegExp(`^${toSource(normalized.endsWith(\"/\") ? `${folder}/**` : normalized)}$`);\n\n cache.set(key, regex);\n\n return regex;\n}\n\n/** Whether a project-relative path matches the glob. */\nexport function matchesGlob(file: string, glob: string): boolean {\n return globToRegExp(glob).test(file.replace(/\\\\/g, \"/\"));\n}\n\n/** Whether a path matches any of the globs. */\nexport function matchesAny(file: string, globs: readonly string[]): boolean {\n return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,aAAa,MAAsB;CACjD,MAAM,MAAM;CACZ,MAAM,QAAQ,MAAM,IAAI,GAAG;CAE3B,IAAI,OAAO,OAAO;CAElB,MAAM,aAAa,KAAK,QAAQ,OAAO,GAAG,CAAC,CAAC,QAAQ,SAAS,EAAE;CAC/D,MAAM,QAAQ,CAAC,QAAQ,KAAK,UAAU;CACtC,MAAM,SAAS,WAAW,QAAQ,QAAQ,EAAE;CAC5C,MAAM,QAAQ,QACV,IAAI,OAAO,IAAI,SAAS,MAAM,EAAE,UAAU,IAC1C,IAAI,OAAO,IAAI,SAAS,WAAW,SAAS,GAAG,IAAI,GAAG,OAAO,OAAO,UAAU,EAAE,EAAE;CAEtF,MAAM,IAAI,KAAK,KAAK;CAEpB,OAAO;AACT;;AAGA,SAAgB,YAAY,MAAc,MAAuB;CAC/D,OAAO,aAAa,IAAI,CAAC,CAAC,KAAK,KAAK,QAAQ,OAAO,GAAG,CAAC;AACzD;;AAGA,SAAgB,WAAW,MAAc,OAAmC;CAC1E,OAAO,MAAM,MAAM,SAAS,YAAY,MAAM,IAAI,CAAC;AACrD"}
@@ -0,0 +1,9 @@
1
+ import { describeRouteDiff, diffRoutes, parseApiSnapshot, readApiSnapshot, routeLines, writeApiSnapshot } from "./api.mjs";
2
+ import { countAssertions } from "./assertions.mjs";
3
+ import { globToRegExp, matchesAny, matchesGlob, splitList } from "./glob.mjs";
4
+ import { findTask, mergeScopes, parseRemoveEntry, readTaskScope, scopeFeatures, scopeFlows, taskNumber } from "./scope.mjs";
5
+ import { isTestPath, runGuardChecks } from "./rules.mjs";
6
+ import { collectGuardInput, guardedChanges, readBaseWritten, readTexts, resolveScope, taskIdsIn } from "./collect.mjs";
7
+ import { formatGuardReport } from "./format.mjs";
8
+
9
+ export { collectGuardInput, describeRouteDiff, diffRoutes, formatGuardReport, guardedChanges, readApiSnapshot, routeLines, runGuardChecks, writeApiSnapshot };