@warlock.js/grimoire 5.57.0 → 5.59.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 (123) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/esm/apps/check-apps.mjs +11 -5
  3. package/esm/apps/check-apps.mjs.map +1 -1
  4. package/esm/book/build.d.mts.map +1 -1
  5. package/esm/book/build.mjs +2 -1
  6. package/esm/book/build.mjs.map +1 -1
  7. package/esm/book/render.mjs +10 -0
  8. package/esm/book/render.mjs.map +1 -1
  9. package/esm/bookmap/build.d.mts.map +1 -1
  10. package/esm/bookmap/build.mjs +7 -5
  11. package/esm/bookmap/build.mjs.map +1 -1
  12. package/esm/bookmap/steps.mjs +85 -39
  13. package/esm/bookmap/steps.mjs.map +1 -1
  14. package/esm/check/check-grimoire.d.mts.map +1 -1
  15. package/esm/check/check-grimoire.mjs +4 -1
  16. package/esm/check/check-grimoire.mjs.map +1 -1
  17. package/esm/check/rules/criteria.mjs +21 -2
  18. package/esm/check/rules/criteria.mjs.map +1 -1
  19. package/esm/check/rules/screenshots.mjs +57 -0
  20. package/esm/check/rules/screenshots.mjs.map +1 -0
  21. package/esm/codes/codes.d.mts +12 -0
  22. package/esm/codes/codes.d.mts.map +1 -1
  23. package/esm/codes/codes.mjs +6 -0
  24. package/esm/codes/codes.mjs.map +1 -1
  25. package/esm/contracts/adapter.d.mts +28 -1
  26. package/esm/contracts/adapter.d.mts.map +1 -1
  27. package/esm/contracts/book.d.mts +2 -0
  28. package/esm/contracts/book.d.mts.map +1 -1
  29. package/esm/contracts/book.mjs.map +1 -1
  30. package/esm/contracts/bookmap.d.mts +19 -1
  31. package/esm/contracts/bookmap.d.mts.map +1 -1
  32. package/esm/contracts/scry.d.mts +26 -6
  33. package/esm/contracts/scry.d.mts.map +1 -1
  34. package/esm/contracts/snapshot.d.mts +14 -1
  35. package/esm/contracts/snapshot.d.mts.map +1 -1
  36. package/esm/contracts/test-results.d.mts +34 -0
  37. package/esm/contracts/test-results.d.mts.map +1 -1
  38. package/esm/contracts/written.d.mts +44 -0
  39. package/esm/contracts/written.d.mts.map +1 -1
  40. package/esm/contracts/written.mjs.map +1 -1
  41. package/esm/devtools/data.mjs +116 -5
  42. package/esm/devtools/data.mjs.map +1 -1
  43. package/esm/devtools/feature-map.mjs +149 -0
  44. package/esm/devtools/feature-map.mjs.map +1 -0
  45. package/esm/devtools/index.d.mts +28 -2
  46. package/esm/devtools/index.d.mts.map +1 -1
  47. package/esm/devtools/index.mjs +111 -7
  48. package/esm/devtools/index.mjs.map +1 -1
  49. package/esm/devtools/product-map.d.mts +14 -0
  50. package/esm/devtools/product-map.d.mts.map +1 -0
  51. package/esm/devtools/product-map.mjs +460 -0
  52. package/esm/devtools/product-map.mjs.map +1 -0
  53. package/esm/devtools/site.d.mts +43 -1
  54. package/esm/devtools/site.d.mts.map +1 -1
  55. package/esm/devtools/site.mjs +190 -22
  56. package/esm/devtools/site.mjs.map +1 -1
  57. package/esm/devtools/snapshot-source.mjs +24 -7
  58. package/esm/devtools/snapshot-source.mjs.map +1 -1
  59. package/esm/graph/index.d.mts +10 -1
  60. package/esm/graph/index.d.mts.map +1 -1
  61. package/esm/graph/index.mjs +3 -2
  62. package/esm/graph/index.mjs.map +1 -1
  63. package/esm/index.d.mts +5 -5
  64. package/esm/ownership/index.d.mts.map +1 -1
  65. package/esm/ownership/index.mjs +60 -1
  66. package/esm/ownership/index.mjs.map +1 -1
  67. package/esm/paths/index.d.mts +2 -0
  68. package/esm/paths/index.d.mts.map +1 -1
  69. package/esm/paths/index.mjs +3 -1
  70. package/esm/paths/index.mjs.map +1 -1
  71. package/esm/scry/compact.mjs +170 -0
  72. package/esm/scry/compact.mjs.map +1 -0
  73. package/esm/scry/format.d.mts.map +1 -1
  74. package/esm/scry/format.mjs +19 -2
  75. package/esm/scry/format.mjs.map +1 -1
  76. package/esm/scry/query.d.mts.map +1 -1
  77. package/esm/scry/query.mjs +159 -24
  78. package/esm/scry/query.mjs.map +1 -1
  79. package/esm/test-results/index.d.mts +7 -2
  80. package/esm/test-results/index.d.mts.map +1 -1
  81. package/esm/test-results/index.mjs +79 -12
  82. package/esm/test-results/index.mjs.map +1 -1
  83. package/esm/vitest/index.d.mts +6 -0
  84. package/esm/vitest/index.d.mts.map +1 -1
  85. package/esm/vitest/index.mjs +22 -6
  86. package/esm/vitest/index.mjs.map +1 -1
  87. package/esm/warlock/actions.mjs +15 -7
  88. package/esm/warlock/actions.mjs.map +1 -1
  89. package/esm/warlock/adapter.d.mts.map +1 -1
  90. package/esm/warlock/adapter.mjs +42 -4
  91. package/esm/warlock/adapter.mjs.map +1 -1
  92. package/esm/warlock/commands.mjs +7 -2
  93. package/esm/warlock/commands.mjs.map +1 -1
  94. package/esm/warlock/logo.mjs +12 -0
  95. package/esm/warlock/logo.mjs.map +1 -0
  96. package/esm/warlock/mcp-tools.mjs +51 -15
  97. package/esm/warlock/mcp-tools.mjs.map +1 -1
  98. package/esm/workspace/cache.mjs +194 -0
  99. package/esm/workspace/cache.mjs.map +1 -0
  100. package/esm/workspace/index.d.mts.map +1 -1
  101. package/esm/workspace/index.mjs +7 -3
  102. package/esm/workspace/index.mjs.map +1 -1
  103. package/esm/written/apps.mjs +4 -2
  104. package/esm/written/apps.mjs.map +1 -1
  105. package/esm/written/features.mjs +119 -6
  106. package/esm/written/features.mjs.map +1 -1
  107. package/esm/written/markdown.mjs +66 -1
  108. package/esm/written/markdown.mjs.map +1 -1
  109. package/esm/written/parse-grimoire.d.mts.map +1 -1
  110. package/esm/written/parse-grimoire.mjs +1 -1
  111. package/esm/written/parse-grimoire.mjs.map +1 -1
  112. package/llms-full.txt +108 -12
  113. package/package.json +3 -3
  114. package/skills/backfill-a-grimoire/SKILL.md +5 -0
  115. package/skills/describe-an-app/SKILL.md +12 -0
  116. package/skills/record-a-change/SKILL.md +10 -0
  117. package/skills/use-the-grimoire/SKILL.md +44 -10
  118. package/skills/write-a-feature/SKILL.md +37 -2
  119. package/ui/grimoire-static.js +61 -6
  120. package/ui/grimoire-view.js +2133 -316
  121. package/ui/grimoire.css +1030 -24
  122. package/ui/product-map.css +785 -0
  123. package/ui/product-map.js +1265 -0
@@ -9,16 +9,38 @@ import { readFileSync } from "node:fs";
9
9
  //#region ../../packages/grimoire/src/test-results/index.ts
10
10
  /**
11
11
  * Test results per criterion: reading, merging, writing the store the Vitest
12
- * reporter fills, and the check rules over it (`GR4006`–`GR4008`).
12
+ * reporter fills, and the check rules over it (`GR4006`–`GR4010`).
13
13
  */
14
14
  /** sha256 (hex) of a test file's bytes: the value stored as `testFileHash`. */
15
15
  function hashTestFile(content) {
16
16
  return createHash("sha256").update(content).digest("hex");
17
17
  }
18
- /** Read `grimoire/book/test-results.json`; `null` when absent or unreadable. */
19
- async function readTestResults(root) {
18
+ /**
19
+ * The absolute path of the results file: `file` (project-relative or
20
+ * absolute) when given, else `grimoire/book/test-results.json`.
21
+ */
22
+ function resolveResultsFile(root, file) {
23
+ return file === void 0 || file === "" ? path.join(root, ...GRIMOIRE_PATHS.testResults.split("/")) : path.resolve(root, file);
24
+ }
25
+ /**
26
+ * The results file as the snapshot reports it: project-relative POSIX when it
27
+ * lies inside the project, else the absolute path.
28
+ */
29
+ function resultsFileLabel(root, file) {
30
+ const absolute = resolveResultsFile(root, file);
31
+ const relative = path.relative(root, absolute);
32
+ if (relative === "" || relative.startsWith("..") || path.isAbsolute(relative)) return toPosixPath(absolute);
33
+ return toPosixPath(relative);
34
+ }
35
+ /**
36
+ * Read the results store (`grimoire/book/test-results.json`, or `file`);
37
+ * `null` when absent or unreadable.
38
+ *
39
+ * @param file Project-relative or absolute path of another results file.
40
+ */
41
+ async function readTestResults(root, file) {
20
42
  try {
21
- const parsed = JSON.parse(await readFile(path.join(root, GRIMOIRE_PATHS.testResults), "utf8"));
43
+ const parsed = JSON.parse(await readFile(resolveResultsFile(root, file), "utf8"));
22
44
  if (!isStore(parsed)) return null;
23
45
  return parsed;
24
46
  } catch {
@@ -30,6 +52,24 @@ function isStore(value) {
30
52
  const store = value;
31
53
  return store.schemaVersion === 1 && Array.isArray(store.results);
32
54
  }
55
+ /**
56
+ * What the readers know about the results store: whether one was read, where
57
+ * from, and how many `@proves` lines have a result. Lets a view tell "never
58
+ * recorded" from "did not run".
59
+ */
60
+ function testResultsInfo(snapshot) {
61
+ const store = snapshot.results;
62
+ const results = store?.results ?? [];
63
+ const withResult = snapshot.proofs.filter((proof) => results.some((result) => toPosixPath(result.testFile) === toPosixPath(proof.at.file) && result.feature === proof.feature && result.flow === proof.flow && result.criterion === proof.criterion)).length;
64
+ return {
65
+ recorded: store !== null,
66
+ file: snapshot.resultsFile,
67
+ updatedAt: store?.updatedAt ?? null,
68
+ proofs: snapshot.proofs.length,
69
+ withResult,
70
+ unmatched: store?.unmatched?.length ?? 0
71
+ };
72
+ }
33
73
  function compareResults(a, b) {
34
74
  if (a.testFile !== b.testFile) return a.testFile < b.testFile ? -1 : 1;
35
75
  if (a.line !== b.line) return a.line - b.line;
@@ -43,19 +83,21 @@ function compareResults(a, b) {
43
83
  *
44
84
  * @param ranFiles Test files the run executed (even those with no proving test).
45
85
  */
46
- function mergeTestResults(store, run, ranFiles, now) {
86
+ function mergeTestResults(store, run, ranFiles, now, unmatched = []) {
47
87
  const ran = new Set([...ranFiles, ...run.map((result) => result.testFile)].map(toPosixPath));
48
88
  const kept = (store?.results ?? []).filter((result) => !ran.has(toPosixPath(result.testFile)));
89
+ const allUnmatched = [...(store?.unmatched ?? []).filter((entry) => !ran.has(toPosixPath(entry.testFile))), ...unmatched].sort((a, b) => (a.testFile < b.testFile ? -1 : a.testFile > b.testFile ? 1 : 0) || a.line - b.line);
49
90
  return {
50
91
  schemaVersion: 1,
51
92
  updatedAt: now.toISOString(),
52
93
  runner: "vitest",
53
- results: [...kept, ...run].sort(compareResults)
94
+ results: [...kept, ...run].sort(compareResults),
95
+ ...allUnmatched.length > 0 ? { unmatched: allUnmatched } : {}
54
96
  };
55
97
  }
56
- /** Write the store (atomically: temp file, then rename). */
57
- async function writeTestResults(root, store) {
58
- const target = path.join(root, GRIMOIRE_PATHS.testResults);
98
+ /** Write the store (atomically: temp file, then rename), to `file` when given. */
99
+ async function writeTestResults(root, store, file) {
100
+ const target = resolveResultsFile(root, file);
59
101
  const temp = `${target}.${process.pid}.${Date.now()}.tmp`;
60
102
  await mkdir(path.dirname(target), { recursive: true });
61
103
  try {
@@ -66,10 +108,20 @@ async function writeTestResults(root, store) {
66
108
  throw error;
67
109
  }
68
110
  }
69
- /** The GR4006–GR4008 rules. Read-only; nothing when no results exist. */
111
+ /** The GR4006–GR4010 rules. Read-only. */
70
112
  function checkTestResults(snapshot) {
71
113
  const store = snapshot.results;
72
- if (!store) return [];
114
+ if (!store) {
115
+ const first = snapshot.proofs[0];
116
+ return first === void 0 ? [] : [createFinding({
117
+ code: "GR4009",
118
+ message: `${snapshot.proofs.length} proving ${snapshot.proofs.length === 1 ? "test is" : "tests are"} written but no test results were found at ${snapshot.resultsFile}`,
119
+ at: first.at,
120
+ feature: first.feature,
121
+ flow: first.ref,
122
+ file: toPosixPath(first.at.file)
123
+ })];
124
+ }
73
125
  const proposed = new Set(snapshot.written.features.flatMap((feature) => feature.flows.filter((flow) => flow.status.value === "proposed").map((flow) => flow.ref)));
74
126
  const hashes = /* @__PURE__ */ new Map();
75
127
  const currentHash = (file) => {
@@ -116,9 +168,24 @@ function checkTestResults(snapshot) {
116
168
  findings.push(finding);
117
169
  }
118
170
  }
171
+ for (const entry of store.unmatched ?? []) {
172
+ const file = toPosixPath(entry.testFile);
173
+ const proof = snapshot.proofs.find((item) => toPosixPath(item.at.file) === file && item.at.line === entry.line && item.feature === entry.feature && item.flow === entry.flow && item.criterion === entry.criterion);
174
+ if (!proof) continue;
175
+ const finding = createFinding({
176
+ code: "GR4010",
177
+ message: `${proof.ref} ${proof.criterion}: the reporter could not match the test under this @proves line to a result`,
178
+ at: proof.at,
179
+ feature: proof.feature,
180
+ flow: proof.ref,
181
+ file
182
+ });
183
+ if (proposed.has(proof.ref)) finding.expected = true;
184
+ findings.push(finding);
185
+ }
119
186
  return findings;
120
187
  }
121
188
 
122
189
  //#endregion
123
- export { checkTestResults, criterionStatus, hashTestFile, mergeTestResults, readTestResults, writeTestResults };
190
+ export { checkTestResults, criterionStatus, hashTestFile, mergeTestResults, readTestResults, resolveResultsFile, resultsFileLabel, testResultsInfo, writeTestResults };
124
191
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/test-results/index.ts"],"sourcesContent":["/**\n * Test results per criterion: reading, merging, writing the store the Vitest\n * reporter fills, and the check rules over it (`GR4006`–`GR4008`).\n */\nimport { createHash } from \"node:crypto\";\nimport { mkdir, readFile, rename, rm, writeFile } from \"node:fs/promises\";\nimport { readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { createFinding } from \"../codes\";\nimport { GRIMOIRE_PATHS, toPosixPath } from \"../paths\";\nimport type { GrimoireFinding } from \"../contracts/findings\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport type { ProofResult, TestResultsStore } from \"../contracts/test-results\";\n\nexport { criterionStatus, type CriterionTestResult } from \"./criterion-status\";\n\n/** sha256 (hex) of a test file's bytes: the value stored as `testFileHash`. */\nexport function hashTestFile(content: string | Uint8Array): string {\n return createHash(\"sha256\").update(content).digest(\"hex\");\n}\n\n/** Read `grimoire/book/test-results.json`; `null` when absent or unreadable. */\nexport async function readTestResults(root: string): Promise<TestResultsStore | null> {\n try {\n const parsed: unknown = JSON.parse(\n await readFile(path.join(root, GRIMOIRE_PATHS.testResults), \"utf8\"),\n );\n\n if (!isStore(parsed)) return null;\n\n return parsed;\n } catch {\n return null;\n }\n}\n\nfunction isStore(value: unknown): value is TestResultsStore {\n if (typeof value !== \"object\" || value === null) return false;\n\n const store = value as Partial<TestResultsStore>;\n\n return store.schemaVersion === 1 && Array.isArray(store.results);\n}\n\nfunction compareResults(a: ProofResult, b: ProofResult): number {\n if (a.testFile !== b.testFile) return a.testFile < b.testFile ? -1 : 1;\n if (a.line !== b.line) return a.line - b.line;\n if (a.feature !== b.feature) return a.feature < b.feature ? -1 : 1;\n if (a.flow !== b.flow) return a.flow < b.flow ? -1 : 1;\n\n return a.criterion < b.criterion ? -1 : a.criterion > b.criterion ? 1 : 0;\n}\n\n/**\n * Merge one run into the store: results of the test files the run covered\n * replace the old ones; results of other files stay. Pure.\n *\n * @param ranFiles Test files the run executed (even those with no proving test).\n */\nexport function mergeTestResults(\n store: TestResultsStore | null,\n run: readonly ProofResult[],\n ranFiles: readonly string[],\n now: Date,\n): TestResultsStore {\n const ran = new Set([...ranFiles, ...run.map((result) => result.testFile)].map(toPosixPath));\n const kept = (store?.results ?? []).filter((result) => !ran.has(toPosixPath(result.testFile)));\n\n return {\n schemaVersion: 1,\n updatedAt: now.toISOString(),\n runner: \"vitest\",\n results: [...kept, ...run].sort(compareResults),\n };\n}\n\n/** Write the store (atomically: temp file, then rename). */\nexport async function writeTestResults(root: string, store: TestResultsStore): Promise<void> {\n const target = path.join(root, GRIMOIRE_PATHS.testResults);\n const temp = `${target}.${process.pid}.${Date.now()}.tmp`;\n\n await mkdir(path.dirname(target), { recursive: true });\n\n try {\n await writeFile(temp, `${JSON.stringify(store, null, 2)}\\n`, \"utf8\");\n await rename(temp, target);\n } catch (error) {\n await rm(temp, { force: true });\n\n throw error;\n }\n}\n\n/** The GR4006–GR4008 rules. Read-only; nothing when no results exist. */\nexport function checkTestResults(snapshot: GrimoireSnapshot): GrimoireFinding[] {\n const store = snapshot.results;\n\n if (!store) return [];\n\n const proposed = new Set(\n snapshot.written.features.flatMap((feature) =>\n feature.flows.filter((flow) => flow.status.value === \"proposed\").map((flow) => flow.ref),\n ),\n );\n const hashes = new Map<string, string | null>();\n const currentHash = (file: string): string | null => {\n if (!hashes.has(file)) {\n try {\n hashes.set(file, hashTestFile(readFileSync(path.join(snapshot.root, file))));\n } catch {\n hashes.set(file, null);\n }\n }\n\n return hashes.get(file) ?? null;\n };\n const findings: GrimoireFinding[] = [];\n\n for (const proof of snapshot.proofs) {\n const file = toPosixPath(proof.at.file);\n const candidates = store.results.filter(\n (result) =>\n toPosixPath(result.testFile) === file &&\n result.feature === proof.feature &&\n result.flow === proof.flow &&\n result.criterion === proof.criterion,\n );\n const result = candidates.find((item) => item.outcome === \"fail\") ?? candidates[0];\n const label = `${proof.ref} ${proof.criterion}`;\n const base = { at: proof.at, feature: proof.feature, flow: proof.ref, file };\n let finding: GrimoireFinding | null = null;\n\n if (!result || result.outcome === \"skip\") {\n finding = createFinding({\n ...base,\n code: \"GR4008\",\n message: `${label}: its test did not run in the last run${proof.test?.name ? ` (\"${proof.test.name}\")` : \"\"}`,\n });\n } else if (result.outcome === \"fail\") {\n finding = createFinding({\n ...base,\n code: \"GR4006\",\n message: `${label}: its test failed in the last run (\"${result.testName}\")`,\n });\n } else {\n const hash = currentHash(file);\n\n if (hash !== null && hash !== result.testFileHash) {\n finding = createFinding({\n ...base,\n code: \"GR4007\",\n message: `${label}: its result is older than ${file} (ran ${result.ranAt})`,\n });\n }\n }\n\n if (finding) {\n if (proposed.has(proof.ref)) finding.expected = true;\n\n findings.push(finding);\n }\n }\n\n return findings;\n}\n"],"mappings":";;;;;;;;;;;;;;AAiBA,SAAgB,aAAa,SAAsC;CACjE,OAAO,WAAW,QAAQ,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,OAAO,KAAK;AAC1D;;AAGA,eAAsB,gBAAgB,MAAgD;CACpF,IAAI;EACF,MAAM,SAAkB,KAAK,MAC3B,MAAM,SAAS,KAAK,KAAK,MAAM,eAAe,WAAW,GAAG,MAAM,CACpE;EAEA,IAAI,CAAC,QAAQ,MAAM,GAAG,OAAO;EAE7B,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAS,QAAQ,OAA2C;CAC1D,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;CAExD,MAAM,QAAQ;CAEd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M;EAC3G,CAAC;OACI,IAAI,OAAO,YAAY,QAC5B,UAAU,cAAc;GACtB,GAAG;GACH,MAAM;GACN,SAAS,GAAG,MAAM,sCAAsC,OAAO,SAAS;EAC1E,CAAC;OACI;GACL,MAAM,OAAO,YAAY,IAAI;GAE7B,IAAI,SAAS,QAAQ,SAAS,OAAO,cACnC,UAAU,cAAc;IACtB,GAAG;IACH,MAAM;IACN,SAAS,GAAG,MAAM,6BAA6B,KAAK,QAAQ,OAAO,MAAM;GAC3E,CAAC;EAEL;EAEA,IAAI,SAAS;GACX,IAAI,SAAS,IAAI,MAAM,GAAG,GAAG,QAAQ,WAAW;GAEhD,SAAS,KAAK,OAAO;EACvB;CACF;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/test-results/index.ts"],"sourcesContent":["/**\n * Test results per criterion: reading, merging, writing the store the Vitest\n * reporter fills, and the check rules over it (`GR4006`–`GR4010`).\n */\nimport { createHash } from \"node:crypto\";\nimport { mkdir, readFile, rename, rm, writeFile } from \"node:fs/promises\";\nimport { readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { createFinding } from \"../codes\";\nimport { GRIMOIRE_PATHS, toPosixPath } from \"../paths\";\nimport type { GrimoireFinding } from \"../contracts/findings\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport type {\n ProofResult,\n TestResultsInfo,\n TestResultsStore,\n UnmatchedProof,\n} from \"../contracts/test-results\";\n\nexport { criterionStatus, type CriterionTestResult } from \"./criterion-status\";\n\n/** sha256 (hex) of a test file's bytes: the value stored as `testFileHash`. */\nexport function hashTestFile(content: string | Uint8Array): string {\n return createHash(\"sha256\").update(content).digest(\"hex\");\n}\n\n/**\n * The absolute path of the results file: `file` (project-relative or\n * absolute) when given, else `grimoire/book/test-results.json`.\n */\nexport function resolveResultsFile(root: string, file?: string): string {\n return file === undefined || file === \"\"\n ? path.join(root, ...GRIMOIRE_PATHS.testResults.split(\"/\"))\n : path.resolve(root, file);\n}\n\n/**\n * The results file as the snapshot reports it: project-relative POSIX when it\n * lies inside the project, else the absolute path.\n */\nexport function resultsFileLabel(root: string, file?: string): string {\n const absolute = resolveResultsFile(root, file);\n const relative = path.relative(root, absolute);\n\n if (relative === \"\" || relative.startsWith(\"..\") || path.isAbsolute(relative))\n return toPosixPath(absolute);\n\n return toPosixPath(relative);\n}\n\n/**\n * Read the results store (`grimoire/book/test-results.json`, or `file`);\n * `null` when absent or unreadable.\n *\n * @param file Project-relative or absolute path of another results file.\n */\nexport async function readTestResults(\n root: string,\n file?: string,\n): Promise<TestResultsStore | null> {\n try {\n const parsed: unknown = JSON.parse(await readFile(resolveResultsFile(root, file), \"utf8\"));\n\n if (!isStore(parsed)) return null;\n\n return parsed;\n } catch {\n return null;\n }\n}\n\nfunction isStore(value: unknown): value is TestResultsStore {\n if (typeof value !== \"object\" || value === null) return false;\n\n const store = value as Partial<TestResultsStore>;\n\n return store.schemaVersion === 1 && Array.isArray(store.results);\n}\n\n/**\n * What the readers know about the results store: whether one was read, where\n * from, and how many `@proves` lines have a result. Lets a view tell \"never\n * recorded\" from \"did not run\".\n */\nexport function testResultsInfo(snapshot: GrimoireSnapshot): TestResultsInfo {\n const store = snapshot.results;\n const results = store?.results ?? [];\n const withResult = snapshot.proofs.filter((proof) =>\n results.some(\n (result) =>\n toPosixPath(result.testFile) === toPosixPath(proof.at.file) &&\n result.feature === proof.feature &&\n result.flow === proof.flow &&\n result.criterion === proof.criterion,\n ),\n ).length;\n\n return {\n recorded: store !== null,\n file: snapshot.resultsFile,\n updatedAt: store?.updatedAt ?? null,\n proofs: snapshot.proofs.length,\n withResult,\n unmatched: store?.unmatched?.length ?? 0,\n };\n}\n\nfunction compareResults(a: ProofResult, b: ProofResult): number {\n if (a.testFile !== b.testFile) return a.testFile < b.testFile ? -1 : 1;\n if (a.line !== b.line) return a.line - b.line;\n if (a.feature !== b.feature) return a.feature < b.feature ? -1 : 1;\n if (a.flow !== b.flow) return a.flow < b.flow ? -1 : 1;\n\n return a.criterion < b.criterion ? -1 : a.criterion > b.criterion ? 1 : 0;\n}\n\n/**\n * Merge one run into the store: results of the test files the run covered\n * replace the old ones; results of other files stay. Pure.\n *\n * @param ranFiles Test files the run executed (even those with no proving test).\n */\nexport function mergeTestResults(\n store: TestResultsStore | null,\n run: readonly ProofResult[],\n ranFiles: readonly string[],\n now: Date,\n unmatched: readonly UnmatchedProof[] = [],\n): TestResultsStore {\n const ran = new Set([...ranFiles, ...run.map((result) => result.testFile)].map(toPosixPath));\n const kept = (store?.results ?? []).filter((result) => !ran.has(toPosixPath(result.testFile)));\n const keptUnmatched = (store?.unmatched ?? []).filter(\n (entry) => !ran.has(toPosixPath(entry.testFile)),\n );\n const allUnmatched = [...keptUnmatched, ...unmatched].sort(\n (a, b) => (a.testFile < b.testFile ? -1 : a.testFile > b.testFile ? 1 : 0) || a.line - b.line,\n );\n\n return {\n schemaVersion: 1,\n updatedAt: now.toISOString(),\n runner: \"vitest\",\n results: [...kept, ...run].sort(compareResults),\n ...(allUnmatched.length > 0 ? { unmatched: allUnmatched } : {}),\n };\n}\n\n/** Write the store (atomically: temp file, then rename), to `file` when given. */\nexport async function writeTestResults(\n root: string,\n store: TestResultsStore,\n file?: string,\n): Promise<void> {\n const target = resolveResultsFile(root, file);\n const temp = `${target}.${process.pid}.${Date.now()}.tmp`;\n\n await mkdir(path.dirname(target), { recursive: true });\n\n try {\n await writeFile(temp, `${JSON.stringify(store, null, 2)}\\n`, \"utf8\");\n await rename(temp, target);\n } catch (error) {\n await rm(temp, { force: true });\n\n throw error;\n }\n}\n\n/** The GR4006–GR4010 rules. Read-only. */\nexport function checkTestResults(snapshot: GrimoireSnapshot): GrimoireFinding[] {\n const store = snapshot.results;\n\n if (!store) {\n const first = snapshot.proofs[0];\n\n // Proofs exist and no run ever wrote results: one finding for the project, at the first proof.\n return first === undefined\n ? []\n : [\n createFinding({\n code: \"GR4009\",\n message: `${snapshot.proofs.length} proving ${snapshot.proofs.length === 1 ? \"test is\" : \"tests are\"} written but no test results were found at ${snapshot.resultsFile}`,\n at: first.at,\n feature: first.feature,\n flow: first.ref,\n file: toPosixPath(first.at.file),\n }),\n ];\n }\n\n const proposed = new Set(\n snapshot.written.features.flatMap((feature) =>\n feature.flows.filter((flow) => flow.status.value === \"proposed\").map((flow) => flow.ref),\n ),\n );\n const hashes = new Map<string, string | null>();\n const currentHash = (file: string): string | null => {\n if (!hashes.has(file)) {\n try {\n hashes.set(file, hashTestFile(readFileSync(path.join(snapshot.root, file))));\n } catch {\n hashes.set(file, null);\n }\n }\n\n return hashes.get(file) ?? null;\n };\n const findings: GrimoireFinding[] = [];\n\n for (const proof of snapshot.proofs) {\n const file = toPosixPath(proof.at.file);\n const candidates = store.results.filter(\n (result) =>\n toPosixPath(result.testFile) === file &&\n result.feature === proof.feature &&\n result.flow === proof.flow &&\n result.criterion === proof.criterion,\n );\n const result = candidates.find((item) => item.outcome === \"fail\") ?? candidates[0];\n const label = `${proof.ref} ${proof.criterion}`;\n const base = { at: proof.at, feature: proof.feature, flow: proof.ref, file };\n let finding: GrimoireFinding | null = null;\n\n if (!result || result.outcome === \"skip\") {\n finding = createFinding({\n ...base,\n code: \"GR4008\",\n message: `${label}: its test did not run in the last run${proof.test?.name ? ` (\"${proof.test.name}\")` : \"\"}`,\n });\n } else if (result.outcome === \"fail\") {\n finding = createFinding({\n ...base,\n code: \"GR4006\",\n message: `${label}: its test failed in the last run (\"${result.testName}\")`,\n });\n } else {\n const hash = currentHash(file);\n\n if (hash !== null && hash !== result.testFileHash) {\n finding = createFinding({\n ...base,\n code: \"GR4007\",\n message: `${label}: its result is older than ${file} (ran ${result.ranAt})`,\n });\n }\n }\n\n if (finding) {\n if (proposed.has(proof.ref)) finding.expected = true;\n\n findings.push(finding);\n }\n }\n\n for (const entry of store.unmatched ?? []) {\n const file = toPosixPath(entry.testFile);\n const proof = snapshot.proofs.find(\n (item) =>\n toPosixPath(item.at.file) === file &&\n item.at.line === entry.line &&\n item.feature === entry.feature &&\n item.flow === entry.flow &&\n item.criterion === entry.criterion,\n );\n\n // The `@proves` line is gone or moved since the run: the next run replaces the entry.\n if (!proof) continue;\n\n const finding = createFinding({\n code: \"GR4010\",\n message: `${proof.ref} ${proof.criterion}: the reporter could not match the test under this @proves line to a result`,\n at: proof.at,\n feature: proof.feature,\n flow: proof.ref,\n file,\n });\n\n if (proposed.has(proof.ref)) finding.expected = true;\n\n findings.push(finding);\n }\n\n return findings;\n}\n"],"mappings":";;;;;;;;;;;;;;AAsBA,SAAgB,aAAa,SAAsC;CACjE,OAAO,WAAW,QAAQ,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,OAAO,KAAK;AAC1D;;;;;AAMA,SAAgB,mBAAmB,MAAc,MAAuB;CACtE,OAAO,SAAS,UAAa,SAAS,KAClC,KAAK,KAAK,MAAM,GAAG,eAAe,YAAY,MAAM,GAAG,CAAC,IACxD,KAAK,QAAQ,MAAM,IAAI;AAC7B;;;;;AAMA,SAAgB,iBAAiB,MAAc,MAAuB;CACpE,MAAM,WAAW,mBAAmB,MAAM,IAAI;CAC9C,MAAM,WAAW,KAAK,SAAS,MAAM,QAAQ;CAE7C,IAAI,aAAa,MAAM,SAAS,WAAW,IAAI,KAAK,KAAK,WAAW,QAAQ,GAC1E,OAAO,YAAY,QAAQ;CAE7B,OAAO,YAAY,QAAQ;AAC7B;;;;;;;AAQA,eAAsB,gBACpB,MACA,MACkC;CAClC,IAAI;EACF,MAAM,SAAkB,KAAK,MAAM,MAAM,SAAS,mBAAmB,MAAM,IAAI,GAAG,MAAM,CAAC;EAEzF,IAAI,CAAC,QAAQ,MAAM,GAAG,OAAO;EAE7B,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAS,QAAQ,OAA2C;CAC1D,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;CAExD,MAAM,QAAQ;CAEd,OAAO,MAAM,kBAAkB,KAAK,MAAM,QAAQ,MAAM,O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Ac;IACtB,GAAG;IACH,MAAM;IACN,SAAS,GAAG,MAAM,6BAA6B,KAAK,QAAQ,OAAO,MAAM;GAC3E,CAAC;EAEL;EAEA,IAAI,SAAS;GACX,IAAI,SAAS,IAAI,MAAM,GAAG,GAAG,QAAQ,WAAW;GAEhD,SAAS,KAAK,OAAO;EACvB;CACF;CAEA,KAAK,MAAM,SAAS,MAAM,aAAa,CAAC,GAAG;EACzC,MAAM,OAAO,YAAY,MAAM,QAAQ;EACvC,MAAM,QAAQ,SAAS,OAAO,MAC3B,SACC,YAAY,KAAK,GAAG,IAAI,MAAM,QAC9B,KAAK,GAAG,SAAS,MAAM,QACvB,KAAK,YAAY,MAAM,WACvB,KAAK,SAAS,MAAM,QACpB,KAAK,cAAc,MAAM,SAC7B;EAGA,IAAI,CAAC,OAAO;EAEZ,MAAM,UAAU,cAAc;GAC5B,MAAM;GACN,SAAS,GAAG,MAAM,IAAI,GAAG,MAAM,UAAU;GACzC,IAAI,MAAM;GACV,SAAS,MAAM;GACf,MAAM,MAAM;GACZ;EACF,CAAC;EAED,IAAI,SAAS,IAAI,MAAM,GAAG,GAAG,QAAQ,WAAW;EAEhD,SAAS,KAAK,OAAO;CACvB;CAEA,OAAO;AACT"}
@@ -3,6 +3,12 @@
3
3
  export type GrimoireReporterOptions = {
4
4
  /** Project root. Default: Vitest's `config.root`, else `process.cwd()`. */
5
5
  root?: string;
6
+ /**
7
+ * Where to write the results: a project-relative or absolute path. Default
8
+ * `grimoire/book/test-results.json`. Point it at a file the deploy ships
9
+ * and give the panel the same `testResultsFile`.
10
+ */
11
+ file?: string;
6
12
  };
7
13
  /** The reporter, typed structurally (only the hooks it implements). */
8
14
  export type GrimoireReporter = {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/vitest/index.ts"],"mappings":";;YA2BY;;EAEV;;;YAIU;EACV,QAAQ;EACR,iBAAiB,yBAAyB;;;wBA4B5B,iBAAiB,UAAS,0BAA+B"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/vitest/index.ts"],"mappings":";;YA6BY;;EAEV;;;;;;EAMA;;;YAIU;EACV,QAAQ;EACR,iBAAiB,yBAAyB;;;wBA4B5B,iBAAiB,UAAS,0BAA+B"}
@@ -8,7 +8,8 @@ import { readFile } from "node:fs/promises";
8
8
  //#region ../../packages/grimoire/src/vitest/index.ts
9
9
  /**
10
10
  * `@warlock.js/grimoire/vitest`: a Vitest reporter that records the outcome
11
- * of every test proving a criterion in `grimoire/book/test-results.json`.
11
+ * of every test proving a criterion in `grimoire/book/test-results.json`
12
+ * (or the file given in `grimoireReporter({ file })`).
12
13
  *
13
14
  * ```ts
14
15
  * // vitest.config.ts
@@ -44,18 +45,20 @@ function grimoireReporter(options = {}) {
44
45
  try {
45
46
  const modules = Array.isArray(args[0]) ? args[0] : [];
46
47
  const root = options.root ?? configRoot ?? process.cwd();
47
- const previous = await readTestResults(root);
48
+ const previous = await readTestResults(root, options.file);
48
49
  const now = /* @__PURE__ */ new Date();
49
50
  const run = [];
50
51
  const ranFiles = [];
52
+ const unmatched = [];
51
53
  for (const module of modules) {
52
54
  const done = await recordModule(root, module, previous, now);
53
55
  if (!done) continue;
54
56
  ranFiles.push(done.file);
55
57
  run.push(...done.results);
58
+ unmatched.push(...done.unmatched);
56
59
  }
57
60
  if (ranFiles.length === 0) return;
58
- await writeTestResults(root, mergeTestResults(previous, run, ranFiles, now));
61
+ await writeTestResults(root, mergeTestResults(previous, run, ranFiles, now, unmatched), options.file);
59
62
  } catch (error) {
60
63
  warn(error);
61
64
  }
@@ -79,9 +82,11 @@ async function recordModule(root, module, previous, now) {
79
82
  const hash = hashTestFile(buffer);
80
83
  const { proofs } = scanProofsInText(buffer.toString("utf8"), relative);
81
84
  const results = [];
85
+ const unmatched = [];
82
86
  if (proofs.length === 0) return {
83
87
  file: relative,
84
- results
88
+ results,
89
+ unmatched
85
90
  };
86
91
  const cases = [...module.children.allTests()];
87
92
  for (const proof of proofs) {
@@ -90,7 +95,17 @@ async function recordModule(root, module, previous, now) {
90
95
  outcome: OUTCOMES[test.result().state]
91
96
  }));
92
97
  if (outcomes.some((item) => item.outcome === void 0)) return null;
93
- if (outcomes.length === 0 || !proof.test) continue;
98
+ if (!proof.test) continue;
99
+ if (outcomes.length === 0) {
100
+ unmatched.push({
101
+ feature: proof.feature,
102
+ flow: proof.flow,
103
+ criterion: proof.criterion,
104
+ testFile: relative,
105
+ line: proof.at.line
106
+ });
107
+ continue;
108
+ }
94
109
  const outcome = combine(outcomes.map((item) => item.outcome));
95
110
  const first = outcomes[0]?.test;
96
111
  if (!first) continue;
@@ -114,7 +129,8 @@ async function recordModule(root, module, previous, now) {
114
129
  }
115
130
  return {
116
131
  file: relative,
117
- results
132
+ results,
133
+ unmatched
118
134
  };
119
135
  }
120
136
  function matches(proof, test) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/vitest/index.ts"],"sourcesContent":["/**\n * `@warlock.js/grimoire/vitest`: a Vitest reporter that records the outcome\n * of every test proving a criterion in `grimoire/book/test-results.json`.\n *\n * ```ts\n * // vitest.config.ts\n * import { grimoireReporter } from \"@warlock.js/grimoire/vitest\";\n *\n * export default defineConfig({ test: { reporters: [\"default\", grimoireReporter()] } });\n * ```\n *\n * Framework-neutral: this entry must not import `@warlock.js/core`,\n * `@warlock.js/web` or `vitest` at runtime (the reporter is typed structurally).\n */\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type {\n ProofLine,\n ProofResult,\n TestOutcome,\n TestResultsStore,\n} from \"../contracts/test-results\";\nimport { toPosixPath } from \"../paths\";\nimport { scanProofsInText } from \"../proves\";\nimport { hashTestFile, mergeTestResults, readTestResults, writeTestResults } from \"../test-results\";\n\n/** Options of `grimoireReporter()`. */\nexport type GrimoireReporterOptions = {\n /** Project root. Default: Vitest's `config.root`, else `process.cwd()`. */\n root?: string;\n};\n\n/** The reporter, typed structurally (only the hooks it implements). */\nexport type GrimoireReporter = {\n onInit?(context: unknown): void;\n onTestRunEnd?(...args: unknown[]): void | Promise<void>;\n};\n\n/** The part of Vitest's `TestCase` the reporter reads. */\ntype ReportedCase = {\n name: string;\n fullName: string;\n location?: { line: number } | undefined;\n result(): { state: string };\n diagnostic?(): { duration?: number } | undefined;\n};\n\n/** The part of Vitest's `TestModule` the reporter reads. */\ntype ReportedModule = {\n moduleId: string;\n state?(): string;\n children: { allTests(): Iterable<ReportedCase> };\n};\n\ntype VitestContext = { config?: { root?: string; includeTaskLocation?: boolean } };\n\nconst OUTCOMES: Record<string, TestOutcome | undefined> = {\n passed: \"pass\",\n failed: \"fail\",\n skipped: \"skip\",\n};\n\n/** Create the reporter. */\nexport function grimoireReporter(options: GrimoireReporterOptions = {}): GrimoireReporter {\n let configRoot: string | undefined;\n let warned = false;\n\n const warn = (error: unknown): void => {\n if (warned) return;\n\n warned = true;\n console.warn(\n `[grimoire] Could not record test results: ${error instanceof Error ? error.message : String(error)}`,\n );\n };\n\n return {\n onInit(context) {\n const config = (context as VitestContext | undefined)?.config;\n\n configRoot = config?.root;\n\n // Test locations are how a test is matched to its `@proves` line.\n if (config) config.includeTaskLocation = true;\n },\n\n async onTestRunEnd(...args) {\n try {\n const modules = (Array.isArray(args[0]) ? args[0] : []) as ReportedModule[];\n const root = options.root ?? configRoot ?? process.cwd();\n const previous = await readTestResults(root);\n const now = new Date();\n const run: ProofResult[] = [];\n const ranFiles: string[] = [];\n\n for (const module of modules) {\n const done = await recordModule(root, module, previous, now);\n\n if (!done) continue;\n\n ranFiles.push(done.file);\n run.push(...done.results);\n }\n\n if (ranFiles.length === 0) return;\n\n await writeTestResults(root, mergeTestResults(previous, run, ranFiles, now));\n } catch (error) {\n warn(error);\n }\n },\n };\n}\n\ntype ModuleRecord = { file: string; results: ProofResult[] };\n\n/** Results of one test file, or `null` when the file did not finish (it must not erase old results). */\nasync function recordModule(\n root: string,\n module: ReportedModule,\n previous: TestResultsStore | null,\n now: Date,\n): Promise<ModuleRecord | null> {\n // `queued` (never started) and `pending` (cut short) files must keep their old results.\n const state = module.state?.();\n\n if (state === \"pending\" || state === \"queued\") return null;\n\n const absolute = path.resolve(root, module.moduleId);\n const fromRoot = path.relative(root, absolute);\n const relative = toPosixPath(fromRoot);\n\n // Outside the project (another drive on Windows gives an absolute path).\n if (relative === \"..\" || relative.startsWith(\"../\") || path.isAbsolute(fromRoot)) return null;\n\n let buffer: Buffer;\n\n try {\n buffer = await readFile(absolute);\n } catch {\n return null;\n }\n\n const hash = hashTestFile(buffer);\n const { proofs } = scanProofsInText(buffer.toString(\"utf8\"), relative);\n const results: ProofResult[] = [];\n\n if (proofs.length === 0) return { file: relative, results };\n\n const cases = [...module.children.allTests()];\n\n for (const proof of proofs) {\n const matched = cases.filter((test) => matches(proof, test));\n const outcomes = matched.map((test) => ({ test, outcome: OUTCOMES[test.result().state] }));\n\n // A test still pending means the run was cut short: say nothing about this file.\n if (outcomes.some((item) => item.outcome === undefined)) return null;\n if (outcomes.length === 0 || !proof.test) continue;\n\n const outcome = combine(outcomes.map((item) => item.outcome as TestOutcome));\n const first = outcomes[0]?.test;\n\n if (!first) continue;\n\n const old = previous?.results.find(\n (item) =>\n item.testFile === relative &&\n item.feature === proof.feature &&\n item.flow === proof.flow &&\n item.criterion === proof.criterion &&\n item.testFileHash === hash,\n );\n\n // A skipped test (a `-t` filter, `.skip`) keeps the last real result of the same file content.\n if (outcome === \"skip\" && old) {\n results.push(old);\n\n continue;\n }\n\n results.push({\n feature: proof.feature,\n flow: proof.flow,\n criterion: proof.criterion,\n testFile: relative,\n testName: first.fullName,\n line: proof.test.line,\n outcome,\n durationMs: totalDuration(outcomes.map((item) => item.test)),\n ranAt: now.toISOString(),\n testFileHash: hash,\n });\n }\n\n return { file: relative, results };\n}\n\nfunction matches(proof: ProofLine, test: ReportedCase): boolean {\n if (!proof.test) return false;\n if (test.location) return test.location.line === proof.test.line;\n\n return proof.test.name !== null && proof.test.name === test.name;\n}\n\n/** One proving test can run several times (`it.each`): fail beats pass, pass beats skip. */\nfunction combine(outcomes: TestOutcome[]): TestOutcome {\n if (outcomes.includes(\"fail\")) return \"fail\";\n if (outcomes.includes(\"pass\")) return \"pass\";\n\n return \"skip\";\n}\n\nfunction totalDuration(tests: ReportedCase[]): number | null {\n let total = 0;\n let known = false;\n\n for (const test of tests) {\n const duration = test.diagnostic?.()?.duration;\n\n if (typeof duration === \"number\") {\n total += duration;\n known = true;\n }\n }\n\n return known ? Math.round(total) : null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwDA,MAAM,WAAoD;CACxD,QAAQ;CACR,QAAQ;CACR,SAAS;AACX;;AAGA,SAAgB,iBAAiB,UAAmC,CAAC,GAAqB;CACxF,IAAI;CACJ,IAAI,SAAS;CAEb,MAAM,QAAQ,UAAyB;EACrC,IAAI,QAAQ;EAEZ,SAAS;EACT,QAAQ,KACN,6CAA6C,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GACpG;CACF;CAEA,OAAO;EACL,OAAO,SAAS;GACd,MAAM,SAAU,SAAuC;GAEvD,aAAa,QAAQ;GAGrB,IAAI,QAAQ,OAAO,sBAAsB;EAC3C;EAEA,MAAM,aAAa,GAAG,MAAM;GAC1B,IAAI;IACF,MAAM,UAAW,MAAM,QAAQ,KAAK,EAAE,IAAI,KAAK,KAAK,CAAC;IACrD,MAAM,OAAO,QAAQ,QAAQ,cAAc,QAAQ,IAAI;IACvD,MAAM,WAAW,MAAM,gBAAgB,IAAI;IAC3C,MAAM,sBAAM,IAAI,KAAK;IACrB,MAAM,MAAqB,CAAC;IAC5B,MAAM,WAAqB,CAAC;IAE5B,KAAK,MAAM,UAAU,SAAS;KAC5B,MAAM,OAAO,MAAM,aAAa,MAAM,QAAQ,UAAU,GAAG;KAE3D,IAAI,CAAC,MAAM;KAEX,SAAS,KAAK,KAAK,IAAI;KACvB,IAAI,KAAK,GAAG,KAAK,OAAO;I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MAAM,MAAM,UAAU,QAAQ,MAC3B,SACC,KAAK,aAAa,YAClB,KAAK,YAAY,MAAM,WACvB,KAAK,SAAS,MAAM,QACpB,KAAK,cAAc,MAAM,aACzB,KAAK,iBAAiB,IAC1B;EAGA,IAAI,YAAY,UAAU,KAAK;GAC7B,QAAQ,KAAK,GAAG;GAEhB;EACF;EAEA,QAAQ,KAAK;GACX,SAAS,MAAM;GACf,MAAM,MAAM;GACZ,WAAW,MAAM;GACjB,UAAU;GACV,UAAU,MAAM;GAChB,MAAM,MAAM,KAAK;GACjB;GACA,YAAY,cAAc,SAAS,KAAK,SAAS,KAAK,IAAI,CAAC;GAC3D,OAAO,IAAI,YAAY;GACvB,cAAc;EAChB,CAAC;CACH;CAEA,OAAO;EAAE,MAAM;EAAU;CAAQ;AACnC;AAEA,SAAS,QAAQ,OAAkB,MAA6B;CAC9D,IAAI,CAAC,MAAM,MAAM,OAAO;CACxB,IAAI,KAAK,UAAU,OAAO,KAAK,SAAS,SAAS,MAAM,KAAK;CAE5D,OAAO,MAAM,KAAK,SAAS,QAAQ,MAAM,KAAK,SAAS,KAAK;AAC9D;;AAGA,SAAS,QAAQ,UAAsC;CACrD,IAAI,SAAS,SAAS,MAAM,GAAG,OAAO;CACtC,IAAI,SAAS,SAAS,MAAM,GAAG,OAAO;CAEtC,OAAO;AACT;AAEA,SAAS,cAAc,OAAsC;CAC3D,IAAI,QAAQ;CACZ,IAAI,QAAQ;CAEZ,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,WAAW,KAAK,aAAa,CAAC,EAAE;EAEtC,IAAI,OAAO,aAAa,UAAU;GAChC,SAAS;GACT,QAAQ;EACV;CACF;CAEA,OAAO,QAAQ,KAAK,MAAM,KAAK,IAAI;AACrC"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/vitest/index.ts"],"sourcesContent":["/**\n * `@warlock.js/grimoire/vitest`: a Vitest reporter that records the outcome\n * of every test proving a criterion in `grimoire/book/test-results.json`\n * (or the file given in `grimoireReporter({ file })`).\n *\n * ```ts\n * // vitest.config.ts\n * import { grimoireReporter } from \"@warlock.js/grimoire/vitest\";\n *\n * export default defineConfig({ test: { reporters: [\"default\", grimoireReporter()] } });\n * ```\n *\n * Framework-neutral: this entry must not import `@warlock.js/core`,\n * `@warlock.js/web` or `vitest` at runtime (the reporter is typed structurally).\n */\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type {\n ProofLine,\n ProofResult,\n TestOutcome,\n TestResultsStore,\n UnmatchedProof,\n} from \"../contracts/test-results\";\nimport { toPosixPath } from \"../paths\";\nimport { scanProofsInText } from \"../proves\";\nimport { hashTestFile, mergeTestResults, readTestResults, writeTestResults } from \"../test-results\";\n\n/** Options of `grimoireReporter()`. */\nexport type GrimoireReporterOptions = {\n /** Project root. Default: Vitest's `config.root`, else `process.cwd()`. */\n root?: string;\n /**\n * Where to write the results: a project-relative or absolute path. Default\n * `grimoire/book/test-results.json`. Point it at a file the deploy ships\n * and give the panel the same `testResultsFile`.\n */\n file?: string;\n};\n\n/** The reporter, typed structurally (only the hooks it implements). */\nexport type GrimoireReporter = {\n onInit?(context: unknown): void;\n onTestRunEnd?(...args: unknown[]): void | Promise<void>;\n};\n\n/** The part of Vitest's `TestCase` the reporter reads. */\ntype ReportedCase = {\n name: string;\n fullName: string;\n location?: { line: number } | undefined;\n result(): { state: string };\n diagnostic?(): { duration?: number } | undefined;\n};\n\n/** The part of Vitest's `TestModule` the reporter reads. */\ntype ReportedModule = {\n moduleId: string;\n state?(): string;\n children: { allTests(): Iterable<ReportedCase> };\n};\n\ntype VitestContext = { config?: { root?: string; includeTaskLocation?: boolean } };\n\nconst OUTCOMES: Record<string, TestOutcome | undefined> = {\n passed: \"pass\",\n failed: \"fail\",\n skipped: \"skip\",\n};\n\n/** Create the reporter. */\nexport function grimoireReporter(options: GrimoireReporterOptions = {}): GrimoireReporter {\n let configRoot: string | undefined;\n let warned = false;\n\n const warn = (error: unknown): void => {\n if (warned) return;\n\n warned = true;\n console.warn(\n `[grimoire] Could not record test results: ${error instanceof Error ? error.message : String(error)}`,\n );\n };\n\n return {\n onInit(context) {\n const config = (context as VitestContext | undefined)?.config;\n\n configRoot = config?.root;\n\n // Test locations are how a test is matched to its `@proves` line.\n if (config) config.includeTaskLocation = true;\n },\n\n async onTestRunEnd(...args) {\n try {\n const modules = (Array.isArray(args[0]) ? args[0] : []) as ReportedModule[];\n const root = options.root ?? configRoot ?? process.cwd();\n const previous = await readTestResults(root, options.file);\n const now = new Date();\n const run: ProofResult[] = [];\n const ranFiles: string[] = [];\n const unmatched: UnmatchedProof[] = [];\n\n for (const module of modules) {\n const done = await recordModule(root, module, previous, now);\n\n if (!done) continue;\n\n ranFiles.push(done.file);\n run.push(...done.results);\n unmatched.push(...done.unmatched);\n }\n\n if (ranFiles.length === 0) return;\n\n await writeTestResults(\n root,\n mergeTestResults(previous, run, ranFiles, now, unmatched),\n options.file,\n );\n } catch (error) {\n warn(error);\n }\n },\n };\n}\n\ntype ModuleRecord = { file: string; results: ProofResult[]; unmatched: UnmatchedProof[] };\n\n/** Results of one test file, or `null` when the file did not finish (it must not erase old results). */\nasync function recordModule(\n root: string,\n module: ReportedModule,\n previous: TestResultsStore | null,\n now: Date,\n): Promise<ModuleRecord | null> {\n // `queued` (never started) and `pending` (cut short) files must keep their old results.\n const state = module.state?.();\n\n if (state === \"pending\" || state === \"queued\") return null;\n\n const absolute = path.resolve(root, module.moduleId);\n const fromRoot = path.relative(root, absolute);\n const relative = toPosixPath(fromRoot);\n\n // Outside the project (another drive on Windows gives an absolute path).\n if (relative === \"..\" || relative.startsWith(\"../\") || path.isAbsolute(fromRoot)) return null;\n\n let buffer: Buffer;\n\n try {\n buffer = await readFile(absolute);\n } catch {\n return null;\n }\n\n const hash = hashTestFile(buffer);\n const { proofs } = scanProofsInText(buffer.toString(\"utf8\"), relative);\n const results: ProofResult[] = [];\n const unmatched: UnmatchedProof[] = [];\n\n if (proofs.length === 0) return { file: relative, results, unmatched };\n\n const cases = [...module.children.allTests()];\n\n for (const proof of proofs) {\n const matched = cases.filter((test) => matches(proof, test));\n const outcomes = matched.map((test) => ({ test, outcome: OUTCOMES[test.result().state] }));\n\n // A test still pending means the run was cut short: say nothing about this file.\n if (outcomes.some((item) => item.outcome === undefined)) return null;\n if (!proof.test) continue;\n\n if (outcomes.length === 0) {\n unmatched.push({\n feature: proof.feature,\n flow: proof.flow,\n criterion: proof.criterion,\n testFile: relative,\n line: proof.at.line,\n });\n\n continue;\n }\n\n const outcome = combine(outcomes.map((item) => item.outcome as TestOutcome));\n const first = outcomes[0]?.test;\n\n if (!first) continue;\n\n const old = previous?.results.find(\n (item) =>\n item.testFile === relative &&\n item.feature === proof.feature &&\n item.flow === proof.flow &&\n item.criterion === proof.criterion &&\n item.testFileHash === hash,\n );\n\n // A skipped test (a `-t` filter, `.skip`) keeps the last real result of the same file content.\n if (outcome === \"skip\" && old) {\n results.push(old);\n\n continue;\n }\n\n results.push({\n feature: proof.feature,\n flow: proof.flow,\n criterion: proof.criterion,\n testFile: relative,\n testName: first.fullName,\n line: proof.test.line,\n outcome,\n durationMs: totalDuration(outcomes.map((item) => item.test)),\n ranAt: now.toISOString(),\n testFileHash: hash,\n });\n }\n\n return { file: relative, results, unmatched };\n}\n\nfunction matches(proof: ProofLine, test: ReportedCase): boolean {\n if (!proof.test) return false;\n if (test.location) return test.location.line === proof.test.line;\n\n return proof.test.name !== null && proof.test.name === test.name;\n}\n\n/** One proving test can run several times (`it.each`): fail beats pass, pass beats skip. */\nfunction combine(outcomes: TestOutcome[]): TestOutcome {\n if (outcomes.includes(\"fail\")) return \"fail\";\n if (outcomes.includes(\"pass\")) return \"pass\";\n\n return \"skip\";\n}\n\nfunction totalDuration(tests: ReportedCase[]): number | null {\n let total = 0;\n let known = false;\n\n for (const test of tests) {\n const duration = test.diagnostic?.()?.duration;\n\n if (typeof duration === \"number\") {\n total += duration;\n known = true;\n }\n }\n\n return known ? Math.round(total)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SAAS,MAAM,QACpB,KAAK,cAAc,MAAM,aACzB,KAAK,iBAAiB,IAC1B;EAGA,IAAI,YAAY,UAAU,KAAK;GAC7B,QAAQ,KAAK,GAAG;GAEhB;EACF;EAEA,QAAQ,KAAK;GACX,SAAS,MAAM;GACf,MAAM,MAAM;GACZ,WAAW,MAAM;GACjB,UAAU;GACV,UAAU,MAAM;GAChB,MAAM,MAAM,KAAK;GACjB;GACA,YAAY,cAAc,SAAS,KAAK,SAAS,KAAK,IAAI,CAAC;GAC3D,OAAO,IAAI,YAAY;GACvB,cAAc;EAChB,CAAC;CACH;CAEA,OAAO;EAAE,MAAM;EAAU;EAAS;CAAU;AAC9C;AAEA,SAAS,QAAQ,OAAkB,MAA6B;CAC9D,IAAI,CAAC,MAAM,MAAM,OAAO;CACxB,IAAI,KAAK,UAAU,OAAO,KAAK,SAAS,SAAS,MAAM,KAAK;CAE5D,OAAO,MAAM,KAAK,SAAS,QAAQ,MAAM,KAAK,SAAS,KAAK;AAC9D;;AAGA,SAAS,QAAQ,UAAsC;CACrD,IAAI,SAAS,SAAS,MAAM,GAAG,OAAO;CACtC,IAAI,SAAS,SAAS,MAAM,GAAG,OAAO;CAEtC,OAAO;AACT;AAEA,SAAS,cAAc,OAAsC;CAC3D,IAAI,QAAQ;CACZ,IAAI,QAAQ;CAEZ,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,WAAW,KAAK,aAAa,CAAC,EAAE;EAEtC,IAAI,OAAO,aAAa,UAAU;GAChC,SAAS;GACT,QAAQ;EACV;CACF;CAEA,OAAO,QAAQ,KAAK,MAAM,KAAK,IAAI;AACrC"}
@@ -4,7 +4,7 @@ import { parseGrimoire } from "../written/parse-grimoire.mjs";
4
4
  import "../written/index.mjs";
5
5
  import { loadBook } from "../book/build.mjs";
6
6
  import "../book/index.mjs";
7
- import { openGrimoire, runGrimoire } from "../workspace/index.mjs";
7
+ import { runGrimoire } from "../workspace/index.mjs";
8
8
  import { writeRelease } from "../releases/index.mjs";
9
9
  import { checkGrimoire } from "../check/check-grimoire.mjs";
10
10
  import { formatCheckReport } from "../check/format-check-report.mjs";
@@ -13,6 +13,7 @@ import { formatScryResult } from "../scry/format.mjs";
13
13
  import { parseScryQuery } from "../scry/parse.mjs";
14
14
  import { scry } from "../scry/query.mjs";
15
15
  import "../scry/index.mjs";
16
+ import { openGrimoireCached } from "../workspace/cache.mjs";
16
17
  import path from "node:path";
17
18
  import { createHash } from "node:crypto";
18
19
  import { readFile, readdir } from "node:fs/promises";
@@ -133,7 +134,7 @@ function siteFolder(root, out) {
133
134
  function elapsedLine(started) {
134
135
  return `time ${((Date.now() - started) / 1e3).toFixed(1)}s`;
135
136
  }
136
- /** `warlock grimoire build [--force] [--site [--out <dir>]] [--json]`. */
137
+ /** `warlock grimoire build [--force] [--site [--product] [--out <dir>]] [--json]`. */
137
138
  async function runBuild(context, options = {}) {
138
139
  const { root, adapter, io } = context;
139
140
  const started = Date.now();
@@ -145,13 +146,18 @@ async function runBuild(context, options = {}) {
145
146
  force
146
147
  }));
147
148
  let site = null;
148
- if (options.site === true || typeof options.out === "string") {
149
- const { exportGrimoireSite } = await import("../devtools/index.mjs");
150
- site = await exportGrimoireSite(root, {
149
+ let siteUpToDate = false;
150
+ if (options.site === true || options.product === true || typeof options.out === "string") {
151
+ const { exportGrimoireSiteDetailed } = await import("../devtools/index.mjs");
152
+ const exported = await exportGrimoireSiteDetailed(root, {
151
153
  adapter,
152
154
  snapshot: run.snapshot,
155
+ force,
156
+ ...options.product === true ? { product: true } : {},
153
157
  ...outDir === void 0 ? {} : { outDir }
154
158
  });
159
+ site = exported.outDir;
160
+ siteUpToDate = exported.upToDate;
155
161
  }
156
162
  if (options.json === true) {
157
163
  printJson(io, {
@@ -161,6 +167,8 @@ async function runBuild(context, options = {}) {
161
167
  removed: [...run.book.removed, ...run.collected.removed],
162
168
  routes: run.snapshot.routes,
163
169
  site,
170
+ siteUpToDate,
171
+ siteMode: site === null ? null : options.product === true ? "product" : "full",
164
172
  problems: bootProblem === null ? [] : [bootProblem]
165
173
  });
166
174
  return 0;
@@ -172,7 +180,7 @@ async function runBuild(context, options = {}) {
172
180
  }
173
181
  io.out(summary.book);
174
182
  io.out(summary.collected);
175
- if (site !== null) io.out(`site ${site}/index.html`);
183
+ if (site !== null) io.out(`site ${site}/index.html${options.product === true ? " (product map only)" : ""}${siteUpToDate ? " (up to date, not rebuilt)" : ""}`);
176
184
  io.out(elapsedLine(started));
177
185
  return 0;
178
186
  } catch (error) {
@@ -241,7 +249,7 @@ async function runRelease(context, release, options = {}) {
241
249
  /** Open the snapshot for a scry question: cached routes, fresh once when a route question finds none. */
242
250
  async function openForScry(root, adapter, query) {
243
251
  const routes = query.type === "route" && !await hasRouteFacts(root) ? "fresh" : "cached";
244
- return openGrimoire(root, adapter, { routes });
252
+ return openGrimoireCached(root, adapter, { routes });
245
253
  }
246
254
  /** Answer a parsed query (shared by the CLI and the MCP tools). */
247
255
  async function answer(root, adapter, query) {
@@ -1 +1 @@
1
- {"version":3,"file":"actions.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/warlock/actions.ts"],"sourcesContent":["/**\n * What `warlock grimoire …` and `warlock scry …` do, as functions that write\n * to an `io` and return the exit code, so specs run them without a process.\n * Loaded lazily by the commands: it pulls in every Grimoire module.\n */\nimport { createHash } from \"node:crypto\";\nimport { readdir, readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { checkGrimoire, formatCheckReport } from \"../check\";\nimport { createFinding, explainGrimoireCode, GrimoireError } from \"../codes\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { GrimoireCheckReport, GrimoireFinding } from \"../contracts/findings\";\nimport type { ScryQuery, ScryResult } from \"../contracts/scry\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport { loadBook } from \"../book\";\nimport { projectPath } from \"../paths\";\nimport { writeRelease } from \"../releases\";\nimport { formatScryResult, parseScryQuery, scry } from \"../scry\";\nimport { openGrimoire, runGrimoire, type GrimoireRun } from \"../workspace\";\nimport { parseGrimoire } from \"../written\";\n\n/** Where a command writes: `out` for its answer, `err` for problems. */\nexport type CommandIO = {\n out(line: string): void;\n err(line: string): void;\n};\n\n/** The project and adapter a command runs against. */\nexport type CommandContext = {\n /** Absolute project root. */\n root: string;\n adapter: BookAdapter;\n io: CommandIO;\n};\n\ntype Options = Readonly<Record<string, string | boolean | number>>;\n\nconst plural = (count: number, word: string, many = `${word}s`): string =>\n `${count} ${count === 1 ? word : many}`;\n\n/** Print a Grimoire error the way every command does, and return exit code 1. */\nexport function reportError(io: CommandIO, error: unknown): number {\n if (error instanceof GrimoireError) {\n io.err(`${error.code} ${error.message}`);\n\n const fix = explainGrimoireCode(error.code)?.fix;\n\n if (fix) io.err(` fix: ${fix}`);\n\n return 1;\n }\n\n throw error;\n}\n\nfunction printJson(io: CommandIO, value: unknown): void {\n io.out(JSON.stringify(value, null, 2));\n}\n\n/**\n * Open with fresh routes; when the app does not boot (`GR8002`), open again\n * with the cached ones and return the boot problem as a warning finding.\n */\nasync function withFreshRoutes<T>(\n open: (routes: \"fresh\" | \"cached\") => Promise<T>,\n): Promise<{ value: T; bootProblem: GrimoireFinding | null }> {\n try {\n return { value: await open(\"fresh\"), bootProblem: null };\n } catch (error) {\n if (!(error instanceof GrimoireError) || error.code !== \"GR8002\") throw error;\n\n return {\n value: await open(\"cached\"),\n // Finding messages start lower-case, like every other line of the check report.\n bootProblem: createFinding({\n code: \"GR8002\",\n message: `${error.message.charAt(0).toLowerCase()}${error.message.slice(1)}`,\n }),\n };\n }\n}\n\n/** Whether the book holds route facts already (a `--route` question with none boots once). */\nexport async function hasRouteFacts(root: string): Promise<boolean> {\n return (await loadBook(root))?.facts.routes != null;\n}\n\n/** sha256 of a project file, `\"\"` when it is missing (the book's boot-cache rule). */\nasync function inputHash(root: string, file: string): Promise<string> {\n try {\n return createHash(\"sha256\")\n .update(await readFile(path.join(root, ...file.split(\"/\"))))\n .digest(\"hex\");\n } catch {\n return \"\";\n }\n}\n\n/** File names whose appearance makes the route facts stale: routes files and named mails, jobs, events, notifications. */\nconst BOOT_INPUT = /^(?:routes|.+\\.(?:mail|job|event|notification))\\.[cm]?[jt]sx?$/;\n\n/** Every boot-cache candidate under `src/`: a new one makes the route facts stale. */\nasync function routesFiles(root: string, dir = \"src\"): Promise<string[]> {\n let entries;\n\n try {\n entries = await readdir(path.join(root, ...dir.split(\"/\")), { withFileTypes: true });\n } catch {\n return [];\n }\n\n const found: string[] = [];\n\n for (const entry of entries) {\n if (entry.name === \"node_modules\" || entry.name.startsWith(\".\")) continue;\n\n const file = `${dir}/${entry.name}`;\n\n if (entry.isDirectory()) found.push(...(await routesFiles(root, file)));\n else if (\n BOOT_INPUT.test(entry.name) ||\n (file.startsWith(\"src/config/\") && /\\.[cm]?[jt]sx?$/.test(entry.name))\n )\n found.push(file);\n }\n\n return found;\n}\n\n/**\n * Whether `build` or `check` will have to boot the app: `force`, no book, no\n * route facts yet, or a route-cache input changed, appeared or went away.\n * Reads files only and never calls the adapter, so it runs before anything\n * is loaded.\n */\nexport async function needsBoot(root: string, force: boolean): Promise<boolean> {\n if (force) return true;\n\n const book = await loadBook(root);\n\n if (!book || book.facts.routes === null || book.manifest.boot.collectedAt === null) return true;\n\n const inputs = book.manifest.boot.inputs;\n\n for (const [file, hash] of Object.entries(inputs)) {\n if ((await inputHash(root, file)) !== hash) return true;\n }\n\n return (await routesFiles(root)).some((file) => inputs[file] === undefined);\n}\n\n/** Whether the app has several sites, whose page routes need `src/config/web.ts` loaded. */\nexport async function isMultiSite(root: string): Promise<boolean> {\n try {\n return (await readdir(path.join(root, \"src\", \"web\", \"$sites\"), { withFileTypes: true })).some(\n (entry) => entry.isDirectory(),\n );\n } catch {\n return false;\n }\n}\n\nfunction buildSummary(run: GrimoireRun): { book: string; collected: string } {\n const snapshot = run.snapshot;\n const tasks = snapshot.collected.tasksIndex;\n const bookmaps = run.collected.written.filter((file) => file.endsWith(\"bookmap.json\")).length;\n const nothing =\n !run.rebuilt &&\n run.book.written.length +\n run.book.removed.length +\n run.collected.written.length +\n run.collected.removed.length ===\n 0;\n const book = nothing\n ? \"book up to date\"\n : `book ${plural(snapshot.book.facts.files.length, \"file\")} (${run.book.written.length} written, ${run.book.removed.length} removed), routes ${snapshot.routes}`;\n\n return {\n book,\n // `waiting` is a part of `open`: count each task once, as the devtools tab does.\n collected: `features ${snapshot.collected.featuresIndex.features.length} (bookmaps written: ${bookmaps}) tasks ${tasks.open.length - tasks.waiting.length} open, ${tasks.waiting.length} waiting, ${tasks.done.length} done`,\n };\n}\n\n/**\n * The `--out` folder of the static site, project-relative. A folder outside\n * the project, or the project itself (its own `index.html`), is refused.\n */\nfunction siteFolder(root: string, out: string): string {\n const folder = projectPath(root, out.trim());\n\n if (\n out.trim() === \"\" ||\n folder === \"\" ||\n folder === \"..\" ||\n folder.startsWith(\"../\") ||\n path.isAbsolute(folder)\n ) {\n throw new GrimoireError(\n \"GR9006\",\n `--out ${JSON.stringify(out)} is not a folder inside the project. Pass a project-relative folder, like --out public/grimoire.`,\n );\n }\n\n return folder;\n}\n\n/** `time 4.2s`, the last line of `build` and `check`. */\nfunction elapsedLine(started: number): string {\n return `time ${((Date.now() - started) / 1000).toFixed(1)}s`;\n}\n\n/** `warlock grimoire build [--force] [--site [--out <dir>]] [--json]`. */\nexport async function runBuild(context: CommandContext, options: Options = {}): Promise<number> {\n const { root, adapter, io } = context;\n const started = Date.now();\n\n try {\n const force = options.force === true;\n const outDir = typeof options.out === \"string\" ? siteFolder(root, options.out) : undefined;\n const { value: run, bootProblem } = await withFreshRoutes((routes) =>\n runGrimoire(root, adapter, { routes, force }),\n );\n let site: string | null = null;\n\n if (options.site === true || typeof options.out === \"string\") {\n const { exportGrimoireSite } = await import(\"../devtools\");\n\n site = await exportGrimoireSite(root, {\n adapter,\n snapshot: run.snapshot,\n ...(outDir === undefined ? {} : { outDir }),\n });\n }\n\n if (options.json === true) {\n printJson(io, {\n rebuilt: run.rebuilt,\n changed: run.changed,\n written: [...run.book.written, ...run.collected.written],\n removed: [...run.book.removed, ...run.collected.removed],\n routes: run.snapshot.routes,\n site,\n problems: bootProblem === null ? [] : [bootProblem],\n });\n\n return 0;\n }\n\n const summary = buildSummary(run);\n\n // The app's own boot output comes before this point; the summary is always the last lines.\n if (bootProblem !== null) {\n io.err(`${bootProblem.code} ${bootProblem.message}`);\n io.err(` fix: ${bootProblem.hint}`);\n }\n\n io.out(summary.book);\n io.out(summary.collected);\n\n if (site !== null) io.out(`site ${site}/index.html`);\n\n io.out(elapsedLine(started));\n\n return 0;\n } catch (error) {\n return reportError(io, error);\n }\n}\n\n/** Add a boot problem to a check report as an unexpected warning. */\nfunction withProblem(\n report: GrimoireCheckReport,\n problem: GrimoireFinding | null,\n): GrimoireCheckReport {\n if (problem === null) return report;\n\n const firstExpected = report.findings.findIndex((finding) => finding.expected);\n const findings = [...report.findings];\n\n findings.splice(firstExpected === -1 ? findings.length : firstExpected, 0, problem);\n\n return {\n ...report,\n findings,\n counts: { ...report.counts, warnings: report.counts.warnings + 1 },\n };\n}\n\n/** `warlock grimoire check [--all] [--json]`: exit 1 only when the report is not ok. */\nexport async function runCheck(context: CommandContext, options: Options = {}): Promise<number> {\n const { root, adapter, io } = context;\n const started = Date.now();\n\n try {\n const { value: run, bootProblem } = await withFreshRoutes((routes) =>\n runGrimoire(root, adapter, { routes }),\n );\n const report = withProblem(checkGrimoire(run.snapshot), bootProblem);\n\n if (options.json === true) printJson(io, report);\n else {\n for (const line of formatCheckReport(report, { all: options.all === true })) io.out(line);\n\n // The app's own boot output comes before the report; the summary is always the last lines.\n io.out(buildSummary(run).book);\n io.out(elapsedLine(started));\n }\n\n return report.ok ? 0 : 1;\n } catch (error) {\n return reportError(io, error);\n }\n}\n\n/** `warlock grimoire release <release> [--json]`. */\nexport async function runRelease(\n context: CommandContext,\n release: string | undefined,\n options: Options = {},\n): Promise<number> {\n const { root, io } = context;\n\n try {\n const name = release?.trim() ?? \"\";\n\n if (name === \"\" || /[\\\\/]/.test(name) || name.startsWith(\".\")) {\n throw new GrimoireError(\n \"GR9006\",\n `Pass the release name, like warlock grimoire release 1.1.0 (got ${JSON.stringify(release ?? \"\")}). It must match a file in grimoire/releases/.`,\n );\n }\n\n const { written } = await parseGrimoire(root);\n const outcome = await writeRelease(root, written, name);\n\n if (options.json === true) {\n printJson(io, outcome);\n return 0;\n }\n\n const entries = outcome.collection.entries;\n const listed = entries\n .map((entry) => `${entry.feature} ${entry.version} ${entry.word}`)\n .join(\", \");\n\n io.out(\n `${outcome.file}: ${plural(entries.length, \"entry\", \"entries\")} collected${\n entries.length > 0 ? ` (${listed})` : \"\"\n }${outcome.changed ? \"\" : \", file unchanged\"}`,\n );\n\n const unreleased = outcome.unreleased;\n\n if (unreleased.length > 0) {\n const names = unreleased.map((entry) => `${entry.feature} ${entry.version}`).join(\", \");\n const verb = unreleased.length === 1 ? \"entry is\" : \"entries are\";\n\n io.out(\n `note: ${unreleased.length} ${verb} still unreleased: ${names}. To ship them in ${name}, move them under \"## ${name} (${outcome.collection.date})\" in each feature's CHANGELOG.md and run this command again.`,\n );\n }\n\n return 0;\n } catch (error) {\n return reportError(io, error);\n }\n}\n\n/** Open the snapshot for a scry question: cached routes, fresh once when a route question finds none. */\nasync function openForScry(\n root: string,\n adapter: BookAdapter,\n query: ScryQuery,\n): Promise<GrimoireSnapshot> {\n const routes: \"fresh\" | \"cached\" =\n query.type === \"route\" && !(await hasRouteFacts(root)) ? \"fresh\" : \"cached\";\n\n return openGrimoire(root, adapter, { routes });\n}\n\n/** Answer a parsed query (shared by the CLI and the MCP tools). */\nexport async function answer(\n root: string,\n adapter: BookAdapter,\n query: ScryQuery,\n): Promise<ScryResult> {\n return scry(await openForScry(root, adapter, query), query);\n}\n\n/** `warlock scry <file> | --impact … | --route … | --feature … | --flow … | --search … [--limit n] [--all] [--json]`. */\nexport async function runScry(\n context: CommandContext,\n args: readonly string[],\n options: Options = {},\n): Promise<number> {\n const { root, adapter, io } = context;\n\n try {\n const query = parseScryQuery(args, options);\n const result = await answer(root, adapter, query);\n\n if (options.json === true) printJson(io, result);\n else for (const line of formatScryResult(result, { all: options.all === true })) io.out(line);\n\n return 0;\n } catch (error) {\n return reportError(io, error);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,MAAM,UAAU,OAAe,MAAc,OAAO,GAAG,KAAK,OAC1D,GAAG,MAAM,GAAG,UAAU,IAAI,OAAO;;AAGnC,SAAgB,YAAY,IAAe,OAAwB;CACjE,IAAI,iBAAiB,eAAe;EAClC,GAAG,IAAI,GAAG,MAAM,KAAK,IAAI,MAAM,SAAS;EAExC,MAAM,MAAM,oBAAoB,MAAM,IAAI,CAAC,EAAE;EAE7C,IAAI,KAAK,GAAG,IAAI,UAAU,KAAK;EAE/B,OAAO;CACT;CAEA,MAAM;AACR;AAEA,SAAS,UAAU,IAAe,OAAsB;CACtD,GAAG,IAAI,KAAK,UAAU,OAAO,MAAM,CAAC,CAAC;AACvC;;;;;AAMA,eAAe,gBACb,MAC4D;CAC5D,IAAI;EACF,OAAO;GAAE,OAAO,MAAM,KAAK,OAAO;GAAG,aAAa;EAAK;CACzD,SAAS,OAAO;EACd,IAAI,EAAE,iBAAiB,kBAAkB,MAAM,SAAS,UAAU,MAAM;EAExE,OAAO;GACL,OAAO,MAAM,KAAK,QAAQ;GAE1B,aAAa,cAAc;IACzB,MAAM;IACN,SAAS,GAAG,MAAM,QAAQ,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,MAAM,QAAQ,MAAM,CAAC;GAC3E,CAAC;EACH;CACF;AACF;;AAGA,eAAsB,cAAc,MAAgC;CAClE,QAAQ,MAAM,SAAS,IAAI,EAAC,EAAG,MAAM,UAAU;AACjD;;AAGA,eAAe,UAAU,MAAc,MAA+B;CACpE,IAAI;EACF,OAAO,WAAW,QAAQ,CAAC,CACxB,OAAO,MAAM,SAAS,KAAK,KAAK,MAAM,GAAG,KAAK,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,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,MAAM,QAAQ,iBAAiB,QAAQ,EAAE,KAAK,QAAQ,QAAQ,KAAK,CAAC,GAAG,GAAG,IAAI,IAAI;EAE5F,OAAO;CACT,SAAS,OAAO;EACd,OAAO,YAAY,IAAI,KAAK;CAC9B;AACF"}
1
+ {"version":3,"file":"actions.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/warlock/actions.ts"],"sourcesContent":["/**\n * What `warlock grimoire …` and `warlock scry …` do, as functions that write\n * to an `io` and return the exit code, so specs run them without a process.\n * Loaded lazily by the commands: it pulls in every Grimoire module.\n */\nimport { createHash } from \"node:crypto\";\nimport { readdir, readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { checkGrimoire, formatCheckReport } from \"../check\";\nimport { createFinding, explainGrimoireCode, GrimoireError } from \"../codes\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { GrimoireCheckReport, GrimoireFinding } from \"../contracts/findings\";\nimport type { ScryQuery, ScryResult } from \"../contracts/scry\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport { loadBook } from \"../book\";\nimport { projectPath } from \"../paths\";\nimport { writeRelease } from \"../releases\";\nimport { formatScryResult, parseScryQuery, scry } from \"../scry\";\nimport { runGrimoire, type GrimoireRun } from \"../workspace\";\nimport { openGrimoireCached } from \"../workspace/cache\";\nimport { parseGrimoire } from \"../written\";\n\n/** Where a command writes: `out` for its answer, `err` for problems. */\nexport type CommandIO = {\n out(line: string): void;\n err(line: string): void;\n};\n\n/** The project and adapter a command runs against. */\nexport type CommandContext = {\n /** Absolute project root. */\n root: string;\n adapter: BookAdapter;\n io: CommandIO;\n};\n\ntype Options = Readonly<Record<string, string | boolean | number>>;\n\nconst plural = (count: number, word: string, many = `${word}s`): string =>\n `${count} ${count === 1 ? word : many}`;\n\n/** Print a Grimoire error the way every command does, and return exit code 1. */\nexport function reportError(io: CommandIO, error: unknown): number {\n if (error instanceof GrimoireError) {\n io.err(`${error.code} ${error.message}`);\n\n const fix = explainGrimoireCode(error.code)?.fix;\n\n if (fix) io.err(` fix: ${fix}`);\n\n return 1;\n }\n\n throw error;\n}\n\nfunction printJson(io: CommandIO, value: unknown): void {\n io.out(JSON.stringify(value, null, 2));\n}\n\n/**\n * Open with fresh routes; when the app does not boot (`GR8002`), open again\n * with the cached ones and return the boot problem as a warning finding.\n */\nasync function withFreshRoutes<T>(\n open: (routes: \"fresh\" | \"cached\") => Promise<T>,\n): Promise<{ value: T; bootProblem: GrimoireFinding | null }> {\n try {\n return { value: await open(\"fresh\"), bootProblem: null };\n } catch (error) {\n if (!(error instanceof GrimoireError) || error.code !== \"GR8002\") throw error;\n\n return {\n value: await open(\"cached\"),\n // Finding messages start lower-case, like every other line of the check report.\n bootProblem: createFinding({\n code: \"GR8002\",\n message: `${error.message.charAt(0).toLowerCase()}${error.message.slice(1)}`,\n }),\n };\n }\n}\n\n/** Whether the book holds route facts already (a `--route` question with none boots once). */\nexport async function hasRouteFacts(root: string): Promise<boolean> {\n return (await loadBook(root))?.facts.routes != null;\n}\n\n/** sha256 of a project file, `\"\"` when it is missing (the book's boot-cache rule). */\nasync function inputHash(root: string, file: string): Promise<string> {\n try {\n return createHash(\"sha256\")\n .update(await readFile(path.join(root, ...file.split(\"/\"))))\n .digest(\"hex\");\n } catch {\n return \"\";\n }\n}\n\n/** File names whose appearance makes the route facts stale: routes files and named mails, jobs, events, notifications. */\nconst BOOT_INPUT = /^(?:routes|.+\\.(?:mail|job|event|notification))\\.[cm]?[jt]sx?$/;\n\n/** Every boot-cache candidate under `src/`: a new one makes the route facts stale. */\nasync function routesFiles(root: string, dir = \"src\"): Promise<string[]> {\n let entries;\n\n try {\n entries = await readdir(path.join(root, ...dir.split(\"/\")), { withFileTypes: true });\n } catch {\n return [];\n }\n\n const found: string[] = [];\n\n for (const entry of entries) {\n if (entry.name === \"node_modules\" || entry.name.startsWith(\".\")) continue;\n\n const file = `${dir}/${entry.name}`;\n\n if (entry.isDirectory()) found.push(...(await routesFiles(root, file)));\n else if (\n BOOT_INPUT.test(entry.name) ||\n (file.startsWith(\"src/config/\") && /\\.[cm]?[jt]sx?$/.test(entry.name))\n )\n found.push(file);\n }\n\n return found;\n}\n\n/**\n * Whether `build` or `check` will have to boot the app: `force`, no book, no\n * route facts yet, or a route-cache input changed, appeared or went away.\n * Reads files only and never calls the adapter, so it runs before anything\n * is loaded.\n */\nexport async function needsBoot(root: string, force: boolean): Promise<boolean> {\n if (force) return true;\n\n const book = await loadBook(root);\n\n if (!book || book.facts.routes === null || book.manifest.boot.collectedAt === null) return true;\n\n const inputs = book.manifest.boot.inputs;\n\n for (const [file, hash] of Object.entries(inputs)) {\n if ((await inputHash(root, file)) !== hash) return true;\n }\n\n return (await routesFiles(root)).some((file) => inputs[file] === undefined);\n}\n\n/** Whether the app has several sites, whose page routes need `src/config/web.ts` loaded. */\nexport async function isMultiSite(root: string): Promise<boolean> {\n try {\n return (await readdir(path.join(root, \"src\", \"web\", \"$sites\"), { withFileTypes: true })).some(\n (entry) => entry.isDirectory(),\n );\n } catch {\n return false;\n }\n}\n\nfunction buildSummary(run: GrimoireRun): { book: string; collected: string } {\n const snapshot = run.snapshot;\n const tasks = snapshot.collected.tasksIndex;\n const bookmaps = run.collected.written.filter((file) => file.endsWith(\"bookmap.json\")).length;\n const nothing =\n !run.rebuilt &&\n run.book.written.length +\n run.book.removed.length +\n run.collected.written.length +\n run.collected.removed.length ===\n 0;\n const book = nothing\n ? \"book up to date\"\n : `book ${plural(snapshot.book.facts.files.length, \"file\")} (${run.book.written.length} written, ${run.book.removed.length} removed), routes ${snapshot.routes}`;\n\n return {\n book,\n // `waiting` is a part of `open`: count each task once, as the devtools tab does.\n collected: `features ${snapshot.collected.featuresIndex.features.length} (bookmaps written: ${bookmaps}) tasks ${tasks.open.length - tasks.waiting.length} open, ${tasks.waiting.length} waiting, ${tasks.done.length} done`,\n };\n}\n\n/**\n * The `--out` folder of the static site, project-relative. A folder outside\n * the project, or the project itself (its own `index.html`), is refused.\n */\nfunction siteFolder(root: string, out: string): string {\n const folder = projectPath(root, out.trim());\n\n if (\n out.trim() === \"\" ||\n folder === \"\" ||\n folder === \"..\" ||\n folder.startsWith(\"../\") ||\n path.isAbsolute(folder)\n ) {\n throw new GrimoireError(\n \"GR9006\",\n `--out ${JSON.stringify(out)} is not a folder inside the project. Pass a project-relative folder, like --out public/grimoire.`,\n );\n }\n\n return folder;\n}\n\n/** `time 4.2s`, the last line of `build` and `check`. */\nfunction elapsedLine(started: number): string {\n return `time ${((Date.now() - started) / 1000).toFixed(1)}s`;\n}\n\n/** `warlock grimoire build [--force] [--site [--product] [--out <dir>]] [--json]`. */\nexport async function runBuild(context: CommandContext, options: Options = {}): Promise<number> {\n const { root, adapter, io } = context;\n const started = Date.now();\n\n try {\n const force = options.force === true;\n const outDir = typeof options.out === \"string\" ? siteFolder(root, options.out) : undefined;\n const { value: run, bootProblem } = await withFreshRoutes((routes) =>\n runGrimoire(root, adapter, { routes, force }),\n );\n let site: string | null = null;\n let siteUpToDate = false;\n\n if (options.site === true || options.product === true || typeof options.out === \"string\") {\n const { exportGrimoireSiteDetailed } = await import(\"../devtools\");\n // A page built from the same book is kept; --force writes it again.\n const exported = await exportGrimoireSiteDetailed(root, {\n adapter,\n snapshot: run.snapshot,\n force,\n ...(options.product === true ? { product: true } : {}),\n ...(outDir === undefined ? {} : { outDir }),\n });\n\n site = exported.outDir;\n siteUpToDate = exported.upToDate;\n }\n\n if (options.json === true) {\n printJson(io, {\n rebuilt: run.rebuilt,\n changed: run.changed,\n written: [...run.book.written, ...run.collected.written],\n removed: [...run.book.removed, ...run.collected.removed],\n routes: run.snapshot.routes,\n site,\n siteUpToDate,\n siteMode: site === null ? null : options.product === true ? \"product\" : \"full\",\n problems: bootProblem === null ? [] : [bootProblem],\n });\n\n return 0;\n }\n\n const summary = buildSummary(run);\n\n // The app's own boot output comes before this point; the summary is always the last lines.\n if (bootProblem !== null) {\n io.err(`${bootProblem.code} ${bootProblem.message}`);\n io.err(` fix: ${bootProblem.hint}`);\n }\n\n io.out(summary.book);\n io.out(summary.collected);\n\n if (site !== null) {\n io.out(\n `site ${site}/index.html${options.product === true ? \" (product map only)\" : \"\"}${siteUpToDate ? \" (up to date, not rebuilt)\" : \"\"}`,\n );\n }\n\n io.out(elapsedLine(started));\n\n return 0;\n } catch (error) {\n return reportError(io, error);\n }\n}\n\n/** Add a boot problem to a check report as an unexpected warning. */\nfunction withProblem(\n report: GrimoireCheckReport,\n problem: GrimoireFinding | null,\n): GrimoireCheckReport {\n if (problem === null) return report;\n\n const firstExpected = report.findings.findIndex((finding) => finding.expected);\n const findings = [...report.findings];\n\n findings.splice(firstExpected === -1 ? findings.length : firstExpected, 0, problem);\n\n return {\n ...report,\n findings,\n counts: { ...report.counts, warnings: report.counts.warnings + 1 },\n };\n}\n\n/** `warlock grimoire check [--all] [--json]`: exit 1 only when the report is not ok. */\nexport async function runCheck(context: CommandContext, options: Options = {}): Promise<number> {\n const { root, adapter, io } = context;\n const started = Date.now();\n\n try {\n const { value: run, bootProblem } = await withFreshRoutes((routes) =>\n runGrimoire(root, adapter, { routes }),\n );\n const report = withProblem(checkGrimoire(run.snapshot), bootProblem);\n\n if (options.json === true) printJson(io, report);\n else {\n for (const line of formatCheckReport(report, { all: options.all === true })) io.out(line);\n\n // The app's own boot output comes before the report; the summary is always the last lines.\n io.out(buildSummary(run).book);\n io.out(elapsedLine(started));\n }\n\n return report.ok ? 0 : 1;\n } catch (error) {\n return reportError(io, error);\n }\n}\n\n/** `warlock grimoire release <release> [--json]`. */\nexport async function runRelease(\n context: CommandContext,\n release: string | undefined,\n options: Options = {},\n): Promise<number> {\n const { root, io } = context;\n\n try {\n const name = release?.trim() ?? \"\";\n\n if (name === \"\" || /[\\\\/]/.test(name) || name.startsWith(\".\")) {\n throw new GrimoireError(\n \"GR9006\",\n `Pass the release name, like warlock grimoire release 1.1.0 (got ${JSON.stringify(release ?? \"\")}). It must match a file in grimoire/releases/.`,\n );\n }\n\n const { written } = await parseGrimoire(root);\n const outcome = await writeRelease(root, written, name);\n\n if (options.json === true) {\n printJson(io, outcome);\n return 0;\n }\n\n const entries = outcome.collection.entries;\n const listed = entries\n .map((entry) => `${entry.feature} ${entry.version} ${entry.word}`)\n .join(\", \");\n\n io.out(\n `${outcome.file}: ${plural(entries.length, \"entry\", \"entries\")} collected${\n entries.length > 0 ? ` (${listed})` : \"\"\n }${outcome.changed ? \"\" : \", file unchanged\"}`,\n );\n\n const unreleased = outcome.unreleased;\n\n if (unreleased.length > 0) {\n const names = unreleased.map((entry) => `${entry.feature} ${entry.version}`).join(\", \");\n const verb = unreleased.length === 1 ? \"entry is\" : \"entries are\";\n\n io.out(\n `note: ${unreleased.length} ${verb} still unreleased: ${names}. To ship them in ${name}, move them under \"## ${name} (${outcome.collection.date})\" in each feature's CHANGELOG.md and run this command again.`,\n );\n }\n\n return 0;\n } catch (error) {\n return reportError(io, error);\n }\n}\n\n/** Open the snapshot for a scry question: cached routes, fresh once when a route question finds none. */\nasync function openForScry(\n root: string,\n adapter: BookAdapter,\n query: ScryQuery,\n): Promise<GrimoireSnapshot> {\n const routes: \"fresh\" | \"cached\" =\n query.type === \"route\" && !(await hasRouteFacts(root)) ? \"fresh\" : \"cached\";\n\n return openGrimoireCached(root, adapter, { routes });\n}\n\n/** Answer a parsed query (shared by the CLI and the MCP tools). */\nexport async function answer(\n root: string,\n adapter: BookAdapter,\n query: ScryQuery,\n): Promise<ScryResult> {\n return scry(await openForScry(root, adapter, query), query);\n}\n\n/** `warlock scry <file> | --impact … | --route … | --feature … | --flow … | --search … [--limit n] [--all] [--json]`. */\nexport async function runScry(\n context: CommandContext,\n args: readonly string[],\n options: Options = {},\n): Promise<number> {\n const { root, adapter, io } = context;\n\n try {\n const query = parseScryQuery(args, options);\n const result = await answer(root, adapter, query);\n\n if (options.json === true) printJson(io, result);\n else for (const line of formatScryResult(result, { all: options.all === true })) io.out(line);\n\n return 0;\n } catch (error) {\n return reportError(io, error);\n }\n}\n"],"mappings":";;;;;;;;;;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AO,MAAM,SADpB,eAAe,MAAM,OACY,CAAC;EAEhD,IAAI,QAAQ,SAAS,MAAM,UAAU,IAAI,MAAM;OAC1C,KAAK,MAAM,QAAQ,iBAAiB,QAAQ,EAAE,KAAK,QAAQ,QAAQ,KAAK,CAAC,GAAG,GAAG,IAAI,IAAI;EAE5F,OAAO;CACT,SAAS,OAAO;EACd,OAAO,YAAY,IAAI,KAAK;CAC9B;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/warlock/adapter.ts"],"mappings":";;;;;;;;;;YAsCY,kBACV,cACA,mBAAmB,qBAChB,QAAQ;;YAGD;;;;;;;;EAQV,kBAAkB;;EAElB,UAAU;;;wBAoSI,qBAAqB,UAAS,wBAA6B"}
1
+ {"version":3,"file":"adapter.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/warlock/adapter.ts"],"mappings":";;;;;;;;;;YAwCY,kBACV,cACA,mBAAmB,qBAChB,QAAQ;;YAGD;;;;;;;;EAQV,kBAAkB;;EAElB,UAAU;;;wBAqVI,qBAAqB,UAAS,wBAA6B"}
@@ -1,4 +1,5 @@
1
1
  import { isCodeFile, isInsideFolder, toPosixPath } from "../paths/index.mjs";
2
+ import { WARLOCK_LOGO_DATA_URI } from "./logo.mjs";
2
3
  import { collectMobileFacts } from "./mobile-facts.mjs";
3
4
  import path from "node:path";
4
5
  import { readdir } from "node:fs/promises";
@@ -60,6 +61,27 @@ function coreVersion() {
60
61
  const resolve = typeof import.meta.resolve === "function" ? (specifier) => import.meta.resolve(specifier) : void 0;
61
62
  return installedVersion("@warlock.js/core", path.dirname(fileURLToPath(import.meta.url)), resolve) ?? "unknown";
62
63
  }
64
+ /** The app's own `name` and `version` from `<root>/package.json`, or `null` when it has no name. */
65
+ function appIdentity(root) {
66
+ try {
67
+ const manifest = JSON.parse(readFileSync(path.join(root, "package.json"), "utf8"));
68
+ return typeof manifest.name === "string" && manifest.name !== "" ? {
69
+ name: manifest.name,
70
+ version: typeof manifest.version === "string" ? manifest.version : null
71
+ } : null;
72
+ } catch {
73
+ return null;
74
+ }
75
+ }
76
+ /** The Warlock.js brand (logo and installed version) and the app at `root`, for the view's header and footer. */
77
+ function warlockHost(root, frameworkVersion) {
78
+ return {
79
+ name: "Warlock.js",
80
+ version: frameworkVersion === "unknown" ? null : frameworkVersion,
81
+ logo: WARLOCK_LOGO_DATA_URI,
82
+ app: appIdentity(root)
83
+ };
84
+ }
63
85
  /** Run `work` with `console.log`/`info`/`debug` on stderr, so a boot never mixes with `--json` output. */
64
86
  async function withConsoleOnStderr(work) {
65
87
  const { log, info, debug } = console;
@@ -99,13 +121,24 @@ function stemOf(file, ...suffixes) {
99
121
  for (const suffix of suffixes) if (base.endsWith(`.${suffix}`)) return base.slice(0, -suffix.length - 1);
100
122
  return base;
101
123
  }
124
+ /**
125
+ * The book's role of a file: the framework's role, with CLI command files
126
+ * (`*.command.ts`, or a file directly in `<module>/commands/`) told apart from
127
+ * plain source.
128
+ */
129
+ function bookRole(file) {
130
+ if (file.role !== "source") return file.role;
131
+ const stem = path.posix.basename(file.file).replace(/\.(?:d\.ts|[cm]?[jt]sx?)$/, "");
132
+ const folders = file.file.split("/").slice(0, -1);
133
+ return stem.endsWith(".command") || folders.length === 4 && folders[3] === "commands" ? "command" : file.role;
134
+ }
102
135
  function toBookFile(file, mobile) {
103
136
  const docs = file.exportDocs ?? {};
104
137
  const app = mobile.find((item) => isInsideFolder(file.file, item.root));
105
138
  return {
106
139
  file: file.file,
107
140
  module: file.module,
108
- type: file.role,
141
+ type: bookRole(file),
109
142
  lines: file.lines ?? 0,
110
143
  about: file.about ?? null,
111
144
  tags: file.tags ?? {},
@@ -113,10 +146,14 @@ function toBookFile(file, mobile) {
113
146
  name,
114
147
  about: docs[name] ?? null
115
148
  })),
116
- imports: file.imports.map((entry) => ({
149
+ imports: file.imports.map((entry) => entry.typeOnly === true ? {
150
+ specifier: entry.specifier,
151
+ file: entry.file,
152
+ typeOnly: true
153
+ } : {
117
154
  specifier: entry.specifier,
118
155
  file: entry.file
119
- })),
156
+ }),
120
157
  importedBy: [...file.importedBy],
121
158
  mobileApp: app?.id ?? null
122
159
  };
@@ -262,6 +299,7 @@ function createWarlockAdapter(options = {}) {
262
299
  return {
263
300
  name: "warlock",
264
301
  version: coreVersion(),
302
+ host: (root) => warlockHost(root, coreVersion()),
265
303
  async sourceRoots(root) {
266
304
  return sourceFolders(root, await mobileApps(root));
267
305
  },
@@ -373,5 +411,5 @@ function createWarlockAdapter(options = {}) {
373
411
  }
374
412
 
375
413
  //#endregion
376
- export { createWarlockAdapter, installedVersion };
414
+ export { appIdentity, bookRole, createWarlockAdapter, installedVersion, warlockHost };
377
415
  //# sourceMappingURL=adapter.mjs.map