@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
package/esm/index.d.mts CHANGED
@@ -1,13 +1,13 @@
1
- import { BookAdapter, BookExport, BookFacts, BookFile, BookFileType, BookImport, BookMobileApp, BookNamedThing, BookNamedType, BookPage, BookPageLink, BookRoute, BookScreen, BookSite } from "./contracts/adapter.mjs";
1
+ import { BookAdapter, BookExport, BookFacts, BookFile, BookFileType, BookHost, BookImport, BookMobileApp, BookNamedThing, BookNamedType, BookPage, BookPageLink, BookRoute, BookScreen, BookSite } from "./contracts/adapter.mjs";
2
2
  import { Located, SourceLocation } from "./contracts/location.mjs";
3
3
  import { GrimoireCheckReport, GrimoireCodeArea, GrimoireCodeDefinition, GrimoireFinding, GrimoireFindingInput, GrimoireSeverity, RouteFreshness } from "./contracts/findings.mjs";
4
4
  import { BOOK_SCHEMA_VERSION, BookAnnotations, BookEntry, BookFactsCache, BookManifest, BookManifestFile, BookMobileScreensFile, BookModuleSummary, BookRouteRef, BookRoutesFile, BookSitePagesFile, BuildBookOptions, BuildBookResult, LoadedBook, WriteBookResult } from "./contracts/book.mjs";
5
- import { CASE_QUESTIONS, COLLECTED_END_MARKER, COLLECTED_START_MARKER, CaseQuestion, ChangeWord, CriterionId, FeatureVersion, FlowRef, StepType, TaskStatus, TaskType, WrittenApp, WrittenBlockFile, WrittenBlockRow, WrittenCase, WrittenChangelog, WrittenChangelogEntry, WrittenChangelogSection, WrittenChangesWith, WrittenCriterion, WrittenEntryPoint, WrittenFeature, WrittenFeatureReadme, WrittenFlow, WrittenGrimoire, WrittenLayout, WrittenListLine, WrittenOrigin, WrittenPage, WrittenRelease, WrittenReleaseListed, WrittenStatus, WrittenStep, WrittenTask, WrittenVersionBrief, WrittenWho } from "./contracts/written.mjs";
6
- import { CriterionStatus, ProofLine, ProofResult, TestOutcome, TestResultsStore } from "./contracts/test-results.mjs";
5
+ import { CASE_QUESTIONS, COLLECTED_END_MARKER, COLLECTED_START_MARKER, CaseQuestion, ChangeWord, CriterionId, FeatureVersion, FlowRef, StepType, TaskStatus, TaskType, WrittenApp, WrittenBlockFile, WrittenBlockRow, WrittenCase, WrittenChangelog, WrittenChangelogEntry, WrittenChangelogSection, WrittenChangesWith, WrittenCriterion, WrittenEntryPoint, WrittenFeature, WrittenFeatureReadme, WrittenFlow, WrittenGrimoire, WrittenLayout, WrittenListLine, WrittenOrigin, WrittenPage, WrittenRelease, WrittenReleaseListed, WrittenScreenshot, WrittenStatus, WrittenStep, WrittenStoryStep, WrittenTask, WrittenVersionBrief, WrittenWho } from "./contracts/written.mjs";
6
+ import { CriterionStatus, ProofLine, ProofResult, TestOutcome, TestResultsInfo, TestResultsStore, UnmatchedProof } from "./contracts/test-results.mjs";
7
7
  import { CollectedFiles, FeatureBookmap, FeaturesIndex, FileOwnership, FlowBookmap, FlowBookmapCriterion, FlowBookmapStep, Ownership, TaskSummary, TasksIndex } from "./contracts/bookmap.mjs";
8
8
  import { AppMatch, GrimoireRule, GrimoireSnapshot, OpenGrimoireOptions } from "./contracts/snapshot.mjs";
9
+ import { ScryFeatureFlow, ScryFeatureResult, ScryFileResult, ScryFlowResult, ScryHit, ScryHitType, ScryImpactResult, ScryNotes, ScryPageRef, ScryQuery, ScryResult, ScryRouteResult, ScrySearchResult } from "./contracts/scry.mjs";
9
10
  import { CollectedListText, ReleaseCollection, ReleaseEntry, WriteReleaseResult } from "./contracts/releases.mjs";
10
- import { ScryFeatureResult, ScryFileResult, ScryFlowResult, ScryHit, ScryHitType, ScryImpactResult, ScryNotes, ScryPageRef, ScryQuery, ScryResult, ScryRouteResult, ScrySearchResult } from "./contracts/scry.mjs";
11
11
  import { GRIMOIRE_CODES, GRIMOIRE_CODE_LIST, GrimoireCode } from "./codes/codes.mjs";
12
12
  import { GRIMOIRE_CODES_DOCS_URL, GrimoireError, createFinding, explainGrimoireCode, grimoireCodeDocsUrl, isGrimoireCode } from "./codes/index.mjs";
13
13
  import { BookPathInput, GRIMOIRE_DIR, GRIMOIRE_IGNORE_RULES, GRIMOIRE_PATHS, bookEntryPath, bookEntryPaths, toPosixPath } from "./paths/index.mjs";
@@ -30,4 +30,4 @@ import { readTestResults } from "./test-results/index.mjs";
30
30
  import { formatScryResult } from "./scry/format.mjs";
31
31
  import { parseScryQuery } from "./scry/parse.mjs";
32
32
  import { scry } from "./scry/query.mjs";
33
- export { AppMatch, BOOK_SCHEMA_VERSION, BookAdapter, BookAnnotations, BookEntry, BookExport, BookFacts, BookFactsCache, BookFile, BookFileType, BookImport, BookManifest, BookManifestFile, BookMobileApp, BookMobileScreensFile, BookModuleSummary, BookNamedThing, BookNamedType, BookPage, BookPageLink, type BookPathInput, BookRoute, BookRouteRef, BookRoutesFile, BookScreen, BookSite, BookSitePagesFile, BuildBookOptions, BuildBookResult, CASE_QUESTIONS, COLLECTED_END_MARKER, COLLECTED_START_MARKER, CaseQuestion, ChangeWord, CollectedFiles, type CollectedInput, CollectedListText, CriterionId, CriterionStatus, type CriterionTestResult, FeatureBookmap, FeatureVersion, FeaturesIndex, type FileGraph, FileOwnership, FlowBookmap, FlowBookmapCriterion, FlowBookmapStep, FlowRef, type FrontMatterField, type FrontMatterResult, type FrontMatterValue, GRIMOIRE_CODES, GRIMOIRE_CODES_DOCS_URL, GRIMOIRE_CODE_LIST, GRIMOIRE_DIR, GRIMOIRE_IGNORE_RULES, GRIMOIRE_PATHS, GrimoireCheckReport, type GrimoireCode, GrimoireCodeArea, GrimoireCodeDefinition, GrimoireError, GrimoireFinding, GrimoireFindingInput, GrimoireRule, GrimoireSeverity, GrimoireSnapshot, LoadedBook, Located, OpenGrimoireOptions, Ownership, type ParseGrimoireResult, ProofLine, ProofResult, ReleaseCollection, ReleaseEntry, RouteFreshness, type ScanProofsResult, ScryFeatureResult, ScryFileResult, ScryFlowResult, ScryHit, ScryHitType, ScryImpactResult, ScryNotes, ScryPageRef, ScryQuery, ScryResult, ScryRouteResult, ScrySearchResult, SourceLocation, StepType, TaskStatus, TaskSummary, TaskType, TasksIndex, TestOutcome, TestResultsStore, WriteBookResult, WriteReleaseResult, WrittenApp, WrittenBlockFile, WrittenBlockRow, WrittenCase, WrittenChangelog, WrittenChangelogEntry, WrittenChangelogSection, WrittenChangesWith, WrittenCriterion, WrittenEntryPoint, WrittenFeature, WrittenFeatureReadme, WrittenFlow, WrittenGrimoire, WrittenLayout, WrittenListLine, WrittenOrigin, WrittenPage, WrittenRelease, WrittenReleaseListed, WrittenStatus, WrittenStep, WrittenTask, WrittenVersionBrief, WrittenWho, bookEntryPath, bookEntryPaths, buildBook, buildCollectedFiles, checkGrimoire, collectRelease, createFinding, criterionStatus, explainGrimoireCode, fileGraph, formatCheckReport, formatScryResult, grimoireCodeDocsUrl, importClosure, importerClosure, isGrimoireCode, loadBook, matchApps, openGrimoire, parseGrimoire, parseScryQuery, readFrontMatter, readTestResults, renderCollectedList, resolveOwnership, scanProofs, scanProofsInText, scry, toPosixPath, writeBook, writeCollectedFiles, writeRelease };
33
+ export { AppMatch, BOOK_SCHEMA_VERSION, BookAdapter, BookAnnotations, BookEntry, BookExport, BookFacts, BookFactsCache, BookFile, BookFileType, BookHost, BookImport, BookManifest, BookManifestFile, BookMobileApp, BookMobileScreensFile, BookModuleSummary, BookNamedThing, BookNamedType, BookPage, BookPageLink, type BookPathInput, BookRoute, BookRouteRef, BookRoutesFile, BookScreen, BookSite, BookSitePagesFile, BuildBookOptions, BuildBookResult, CASE_QUESTIONS, COLLECTED_END_MARKER, COLLECTED_START_MARKER, CaseQuestion, ChangeWord, CollectedFiles, type CollectedInput, CollectedListText, CriterionId, CriterionStatus, type CriterionTestResult, FeatureBookmap, FeatureVersion, FeaturesIndex, type FileGraph, FileOwnership, FlowBookmap, FlowBookmapCriterion, FlowBookmapStep, FlowRef, type FrontMatterField, type FrontMatterResult, type FrontMatterValue, GRIMOIRE_CODES, GRIMOIRE_CODES_DOCS_URL, GRIMOIRE_CODE_LIST, GRIMOIRE_DIR, GRIMOIRE_IGNORE_RULES, GRIMOIRE_PATHS, GrimoireCheckReport, type GrimoireCode, GrimoireCodeArea, GrimoireCodeDefinition, GrimoireError, GrimoireFinding, GrimoireFindingInput, GrimoireRule, GrimoireSeverity, GrimoireSnapshot, LoadedBook, Located, OpenGrimoireOptions, Ownership, type ParseGrimoireResult, ProofLine, ProofResult, ReleaseCollection, ReleaseEntry, RouteFreshness, type ScanProofsResult, ScryFeatureFlow, ScryFeatureResult, ScryFileResult, ScryFlowResult, ScryHit, ScryHitType, ScryImpactResult, ScryNotes, ScryPageRef, ScryQuery, ScryResult, ScryRouteResult, ScrySearchResult, SourceLocation, StepType, TaskStatus, TaskSummary, TaskType, TasksIndex, TestOutcome, TestResultsInfo, TestResultsStore, UnmatchedProof, WriteBookResult, WriteReleaseResult, WrittenApp, WrittenBlockFile, WrittenBlockRow, WrittenCase, WrittenChangelog, WrittenChangelogEntry, WrittenChangelogSection, WrittenChangesWith, WrittenCriterion, WrittenEntryPoint, WrittenFeature, WrittenFeatureReadme, WrittenFlow, WrittenGrimoire, WrittenLayout, WrittenListLine, WrittenOrigin, WrittenPage, WrittenRelease, WrittenReleaseListed, WrittenScreenshot, WrittenStatus, WrittenStep, WrittenStoryStep, WrittenTask, WrittenVersionBrief, WrittenWho, bookEntryPath, bookEntryPaths, buildBook, buildCollectedFiles, checkGrimoire, collectRelease, createFinding, criterionStatus, explainGrimoireCode, fileGraph, formatCheckReport, formatScryResult, grimoireCodeDocsUrl, importClosure, importerClosure, isGrimoireCode, loadBook, matchApps, openGrimoire, parseGrimoire, parseScryQuery, readFrontMatter, readTestResults, renderCollectedList, resolveOwnership, scanProofs, scanProofsInText, scry, toPosixPath, writeBook, writeCollectedFiles, writeRelease };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/ownership/index.ts"],"mappings":";;;;;wBAqIgB,iBAAiB,SAAS,iBAAiB,OAAO,YAAY"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/ownership/index.ts"],"mappings":";;;;;wBA+MgB,iBAAiB,SAAS,iBAAiB,OAAO,YAAY"}
@@ -17,6 +17,65 @@ function taggedFeatures(file) {
17
17
  function countsForFeature(file) {
18
18
  return file.type !== "spec";
19
19
  }
20
+ /**
21
+ * File roles no flow step can reach, yet which are real, used code: they run
22
+ * by being present (a migration, a seed, a command, the boot file, a layout or
23
+ * root component). The check does not ask a flow to reach them (`GR3006`).
24
+ */
25
+ const UNREACHED_ROLES = /* @__PURE__ */ new Set([
26
+ "migration",
27
+ "seed",
28
+ "command",
29
+ "main",
30
+ "layout",
31
+ "root"
32
+ ]);
33
+ /** Whether a file's role exempts it from needing a flow to reach it. */
34
+ function isExemptFromReach(file) {
35
+ return UNREACHED_ROLES.has(file.type);
36
+ }
37
+ const HELPER_FOLDERS = /* @__PURE__ */ new Set([
38
+ "tests",
39
+ "__tests__",
40
+ "fixtures",
41
+ "support",
42
+ "test-utils"
43
+ ]);
44
+ /** Whether a path is where test helpers live: a tests/fixtures/support folder or a `*.test-utils.*` file. */
45
+ function isTestHelperPath(file) {
46
+ const parts = file.split("/");
47
+ const name = parts[parts.length - 1] ?? "";
48
+ return parts.slice(0, -1).some((part) => HELPER_FOLDERS.has(part)) || /^(?:test-utils|.+\.test-utils)\.[a-z]+$/.test(name);
49
+ }
50
+ /**
51
+ * Files only specs import, directly or through other such files, and that sit in a helper location
52
+ * (`tests/`, `__tests__/`, `fixtures/`, `support/`, `test-utils`): test helpers.
53
+ * Specs are not own files, so a helper they alone use counts as reached. A source file only its
54
+ * spec imports is not a helper: it is dead code and stays reported.
55
+ */
56
+ function specOnlyFiles(files) {
57
+ const importers = /* @__PURE__ */ new Map();
58
+ for (const file of files) for (const entry of file.imports) {
59
+ if (entry.file === null || entry.file === file.file) continue;
60
+ const list = importers.get(entry.file) ?? /* @__PURE__ */ new Set();
61
+ list.add(file.file);
62
+ importers.set(entry.file, list);
63
+ }
64
+ const specs = new Set(files.filter((file) => file.type === "spec").map((file) => file.file));
65
+ const result = /* @__PURE__ */ new Set();
66
+ let changed = true;
67
+ while (changed) {
68
+ changed = false;
69
+ for (const [file, list] of importers) {
70
+ if (specs.has(file) || result.has(file) || !isTestHelperPath(file)) continue;
71
+ if ([...list].every((importer) => specs.has(importer) || result.has(importer))) {
72
+ result.add(file);
73
+ changed = true;
74
+ }
75
+ }
76
+ }
77
+ return result;
78
+ }
20
79
  function decide(file, features, folders) {
21
80
  const result = {
22
81
  file: file.file,
@@ -133,5 +192,5 @@ function resolveOwnership(written, facts) {
133
192
  }
134
193
 
135
194
  //#endregion
136
- export { countsForFeature, resolveOwnership };
195
+ export { UNREACHED_ROLES, countsForFeature, isExemptFromReach, isTestHelperPath, resolveOwnership, specOnlyFiles };
137
196
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/ownership/index.ts"],"sourcesContent":["/**\n * Who owns each source file (owned by T-128). Rules in `FileOwnership`.\n *\n * - A `@feature <id>` header tag that names a feature wins. A tag that names\n * no feature is left out here (the check reports it as `GR3004`), so the\n * folder rule decides.\n * - Otherwise a `folders` entry that names the file itself (an entry with a\n * code-file extension) owns it: a file entry is more specific than any\n * folder entry, so it wins over the folder of another feature.\n * - Otherwise the feature whose `folders` entry is the deepest folder holding\n * the file owns it.\n * - Two features claiming the file the same way (two different tags, the\n * same file listed by two features, or the same deepest folder listed by\n * two features) is a conflict: the file gets no owner and `conflicts`\n * lists the claims (`GR3003`).\n * - A feature borrows a file it does not own when one of its own files\n * imports it directly. Spec files are never own or borrowed files and do\n * not make a feature borrow anything.\n */\nimport type { BookFacts, BookFile } from \"../contracts/adapter\";\nimport type { FileOwnership, Ownership } from \"../contracts/bookmap\";\nimport type { WrittenGrimoire } from \"../contracts/written\";\nimport { isCodeFile, isInsideFolder, toPosixPath } from \"../paths\";\n\ntype Claim = { feature: string; via: \"tag\" | \"folder\"; folder: string | null };\n\n/** Whether a `folders` entry names one code file instead of a folder. */\nfunction isFileEntry(entry: string): boolean {\n return isCodeFile(entry);\n}\n\nfunction normalizeFolder(folder: string): string {\n return toPosixPath(folder.trim()).replace(/^\\.\\//, \"\").replace(/\\/+$/, \"\");\n}\n\n/** Feature ids named by a file's `@feature` tags, trimmed, unique, in tag order. */\nfunction taggedFeatures(file: BookFile): string[] {\n const values = (file.tags.feature ?? [])\n .map((value) => value.trim().split(/\\s+/)[0] ?? \"\")\n .filter((value) => value.length > 0);\n\n return [...new Set(values)];\n}\n\n/** Whether a file counts as an own, borrowed or unreached file of a feature. */\nexport function countsForFeature(file: Pick<BookFile, \"type\">): boolean {\n return file.type !== \"spec\";\n}\n\nfunction decide(\n file: BookFile,\n features: Set<string>,\n folders: Map<string, string[]>,\n): FileOwnership {\n const result: FileOwnership = {\n file: file.file,\n owner: null,\n via: null,\n folder: null,\n conflicts: [],\n borrowedBy: [],\n };\n const tags = taggedFeatures(file).filter((feature) => features.has(feature));\n\n if (tags.length === 1) {\n result.owner = tags[0] ?? null;\n result.via = \"tag\";\n\n return result;\n }\n\n if (tags.length > 1) {\n result.conflicts = tags.sort().map((feature) => ({ feature, via: \"tag\" }));\n\n return result;\n }\n\n const fileOwners = [...folders]\n .filter(([, list]) => list.includes(file.file))\n .map(([feature]) => feature)\n .sort();\n\n if (fileOwners.length === 1) {\n result.owner = fileOwners[0] ?? null;\n result.via = \"file\";\n\n return result;\n }\n\n if (fileOwners.length > 1) {\n result.conflicts = fileOwners.map((feature) => ({ feature, via: \"file\" }));\n\n return result;\n }\n\n let deepest: Claim[] = [];\n let depth = -1;\n\n for (const [feature, list] of folders) {\n for (const folder of list) {\n if (isFileEntry(folder)) continue;\n\n if (!isInsideFolder(file.file, folder)) continue;\n\n const folderDepth = folder.split(\"/\").length;\n\n if (folderDepth > depth) {\n depth = folderDepth;\n deepest = [{ feature, via: \"folder\", folder }];\n } else if (folderDepth === depth && !deepest.some((claim) => claim.feature === feature)) {\n deepest.push({ feature, via: \"folder\", folder });\n }\n }\n }\n\n if (deepest.length === 1) {\n const claim = deepest[0];\n\n if (claim) {\n result.owner = claim.feature;\n result.via = \"folder\";\n result.folder = claim.folder;\n }\n } else if (deepest.length > 1) {\n result.conflicts = deepest\n .map((claim) => ({ feature: claim.feature, via: claim.via }))\n .sort((left, right) => left.feature.localeCompare(right.feature));\n }\n\n return result;\n}\n\n/** Owner, conflicts and borrowers of every code file in `facts`. Pure. */\nexport function resolveOwnership(written: WrittenGrimoire, facts: BookFacts): Ownership {\n const featureIds = new Set(written.features.map((feature) => feature.id));\n const folders = new Map<string, string[]>();\n\n for (const feature of written.features) {\n const list = (feature.readme?.folders ?? [])\n .map((folder) => normalizeFolder(folder.value))\n .filter((folder) => folder.length > 0);\n\n folders.set(feature.id, [...new Set(list)]);\n }\n\n const files: Record<string, FileOwnership> = {};\n\n for (const file of facts.files) {\n files[file.file] = decide(file, featureIds, folders);\n }\n\n const features: Ownership[\"features\"] = {};\n\n for (const id of [...featureIds].sort()) {\n features[id] = { own: [], borrowed: [] };\n }\n\n const byPath = new Map(facts.files.map((file) => [file.file, file]));\n const borrowers = new Map<string, Set<string>>();\n\n for (const file of facts.files) {\n const owner = files[file.file]?.owner ?? null;\n\n if (owner === null || !countsForFeature(file)) continue;\n\n features[owner]?.own.push(file.file);\n\n for (const entry of file.imports) {\n if (entry.file === null || entry.file === file.file) continue;\n\n const imported = files[entry.file];\n\n if (!imported || imported.owner === owner) continue;\n\n const importedFile = byPath.get(entry.file);\n\n if (importedFile && !countsForFeature(importedFile)) continue;\n\n const set = borrowers.get(entry.file) ?? new Set<string>();\n set.add(owner);\n borrowers.set(entry.file, set);\n }\n }\n\n for (const [file, set] of borrowers) {\n const ownership = files[file];\n const sorted = [...set].sort();\n\n if (ownership) ownership.borrowedBy = sorted;\n\n for (const feature of sorted) features[feature]?.borrowed.push(file);\n }\n\n for (const entry of Object.values(features)) {\n entry.own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AAI,WAAW,UAAU,aAAa;EAEtC,KAAK,MAAM,WAAW,QAAQ,SAAS,QAAQ,EAAE,SAAS,KAAK,IAAI;CACrE;CAEA,KAAK,MAAM,SAAS,OAAO,OAAO,QAAQ,GAAG;EAC3C,MAAM,IAAI,KAAK;EACf,MAAM,SAAS,KAAK;CACtB;CAEA,OAAO;EAAE;EAAO;CAAS;AAC3B"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/ownership/index.ts"],"sourcesContent":["/**\n * Who owns each source file (owned by T-128). Rules in `FileOwnership`.\n *\n * - A `@feature <id>` header tag that names a feature wins. A tag that names\n * no feature is left out here (the check reports it as `GR3004`), so the\n * folder rule decides.\n * - Otherwise a `folders` entry that names the file itself (an entry with a\n * code-file extension) owns it: a file entry is more specific than any\n * folder entry, so it wins over the folder of another feature.\n * - Otherwise the feature whose `folders` entry is the deepest folder holding\n * the file owns it.\n * - Two features claiming the file the same way (two different tags, the\n * same file listed by two features, or the same deepest folder listed by\n * two features) is a conflict: the file gets no owner and `conflicts`\n * lists the claims (`GR3003`).\n * - A feature borrows a file it does not own when one of its own files\n * imports it directly. Spec files are never own or borrowed files and do\n * not make a feature borrow anything.\n */\nimport type { BookFacts, BookFile } from \"../contracts/adapter\";\nimport type { FileOwnership, Ownership } from \"../contracts/bookmap\";\nimport type { WrittenGrimoire } from \"../contracts/written\";\nimport { isCodeFile, isInsideFolder, toPosixPath } from \"../paths\";\n\ntype Claim = { feature: string; via: \"tag\" | \"folder\"; folder: string | null };\n\n/** Whether a `folders` entry names one code file instead of a folder. */\nfunction isFileEntry(entry: string): boolean {\n return isCodeFile(entry);\n}\n\nfunction normalizeFolder(folder: string): string {\n return toPosixPath(folder.trim()).replace(/^\\.\\//, \"\").replace(/\\/+$/, \"\");\n}\n\n/** Feature ids named by a file's `@feature` tags, trimmed, unique, in tag order. */\nfunction taggedFeatures(file: BookFile): string[] {\n const values = (file.tags.feature ?? [])\n .map((value) => value.trim().split(/\\s+/)[0] ?? \"\")\n .filter((value) => value.length > 0);\n\n return [...new Set(values)];\n}\n\n/** Whether a file counts as an own, borrowed or unreached file of a feature. */\nexport function countsForFeature(file: Pick<BookFile, \"type\">): boolean {\n return file.type !== \"spec\";\n}\n\n/**\n * File roles no flow step can reach, yet which are real, used code: they run\n * by being present (a migration, a seed, a command, the boot file, a layout or\n * root component). The check does not ask a flow to reach them (`GR3006`).\n */\nexport const UNREACHED_ROLES: ReadonlySet<string> = new Set([\n \"migration\",\n \"seed\",\n \"command\",\n \"main\",\n \"layout\",\n \"root\",\n]);\n\n/** Whether a file's role exempts it from needing a flow to reach it. */\nexport function isExemptFromReach(file: Pick<BookFile, \"type\">): boolean {\n return UNREACHED_ROLES.has(file.type);\n}\n\nconst HELPER_FOLDERS = new Set([\"tests\", \"__tests__\", \"fixtures\", \"support\", \"test-utils\"]);\n\n/** Whether a path is where test helpers live: a tests/fixtures/support folder or a `*.test-utils.*` file. */\nexport function isTestHelperPath(file: string): boolean {\n const parts = file.split(\"/\");\n const name = parts[parts.length - 1] ?? \"\";\n\n return (\n parts.slice(0, -1).some((part) => HELPER_FOLDERS.has(part)) ||\n /^(?:test-utils|.+\\.test-utils)\\.[a-z]+$/.test(name)\n );\n}\n\n/**\n * Files only specs import, directly or through other such files, and that sit in a helper location\n * (`tests/`, `__tests__/`, `fixtures/`, `support/`, `test-utils`): test helpers.\n * Specs are not own files, so a helper they alone use counts as reached. A source file only its\n * spec imports is not a helper: it is dead code and stays reported.\n */\nexport function specOnlyFiles(\n files: readonly Pick<BookFile, \"file\" | \"type\" | \"imports\">[],\n): Set<string> {\n const importers = new Map<string, Set<string>>();\n\n for (const file of files) {\n for (const entry of file.imports) {\n if (entry.file === null || entry.file === file.file) continue;\n\n const list = importers.get(entry.file) ?? new Set<string>();\n\n list.add(file.file);\n importers.set(entry.file, list);\n }\n }\n\n const specs = new Set(files.filter((file) => file.type === \"spec\").map((file) => file.file));\n const result = new Set<string>();\n let changed = true;\n\n while (changed) {\n changed = false;\n\n for (const [file, list] of importers) {\n if (specs.has(file) || result.has(file) || !isTestHelperPath(file)) continue;\n\n if ([...list].every((importer) => specs.has(importer) || result.has(importer))) {\n result.add(file);\n changed = true;\n }\n }\n }\n\n return result;\n}\n\nfunction decide(\n file: BookFile,\n features: Set<string>,\n folders: Map<string, string[]>,\n): FileOwnership {\n const result: FileOwnership = {\n file: file.file,\n owner: null,\n via: null,\n folder: null,\n conflicts: [],\n borrowedBy: [],\n };\n const tags = taggedFeatures(file).filter((feature) => features.has(feature));\n\n if (tags.length === 1) {\n result.owner = tags[0] ?? null;\n result.via = \"tag\";\n\n return result;\n }\n\n if (tags.length > 1) {\n result.conflicts = tags.sort().map((feature) => ({ feature, via: \"tag\" }));\n\n return result;\n }\n\n const fileOwners = [...folders]\n .filter(([, list]) => list.includes(file.file))\n .map(([feature]) => feature)\n .sort();\n\n if (fileOwners.length === 1) {\n result.owner = fileOwners[0] ?? null;\n result.via = \"file\";\n\n return result;\n }\n\n if (fileOwners.length > 1) {\n result.conflicts = fileOwners.map((feature) => ({ feature, via: \"file\" }));\n\n return result;\n }\n\n let deepest: Claim[] = [];\n let depth = -1;\n\n for (const [feature, list] of folders) {\n for (const folder of list) {\n if (isFileEntry(folder)) continue;\n\n if (!isInsideFolder(file.file, folder)) continue;\n\n const folderDepth = folder.split(\"/\").length;\n\n if (folderDepth > depth) {\n depth = folderDepth;\n deepest = [{ feature, via: \"folder\", folder }];\n } else if (folderDepth === depth && !deepest.some((claim) => claim.feature === feature)) {\n deepest.push({ feature, via: \"folder\", folder });\n }\n }\n }\n\n if (deepest.length === 1) {\n const claim = deepest[0];\n\n if (claim) {\n result.owner = claim.feature;\n result.via = \"folder\";\n result.folder = claim.folder;\n }\n } else if (deepest.length > 1) {\n result.conflicts = deepest\n .map((claim) => ({ feature: claim.feature, via: claim.via }))\n .sort((left, right) => left.feature.localeCompare(right.feature));\n }\n\n return result;\n}\n\n/** Owner, conflicts and borrowers of every code file in `facts`. Pure. */\nexport function resolveOwnership(written: WrittenGrimoire, facts: BookFacts): Ownership {\n const featureIds = new Set(written.features.map((feature) => feature.id));\n const folders = new Map<string, string[]>();\n\n for (const feature of written.features) {\n const list = (feature.readme?.folders ?? [])\n .map((folder) => normalizeFolder(folder.value))\n .filter((folder) => folder.length > 0);\n\n folders.set(feature.id, [...new Set(list)]);\n }\n\n const files: Record<string, FileOwnership> = {};\n\n for (const file of facts.files) {\n files[file.file] = decide(file, featureIds, folders);\n }\n\n const features: Ownership[\"features\"] = {};\n\n for (const id of [...featureIds].sort()) {\n features[id] = { own: [], borrowed: [] };\n }\n\n const byPath = new Map(facts.files.map((file) => [file.file, file]));\n const borrowers = new Map<string, Set<string>>();\n\n for (const file of facts.files) {\n const owner = files[file.file]?.owner ?? null;\n\n if (owner === null || !countsForFeature(file)) continue;\n\n features[owner]?.own.push(file.file);\n\n for (const entry of file.imports) {\n if (entry.file === null || entry.file === file.file) continue;\n\n const imported = files[entry.file];\n\n if (!imported || imported.owner === owner) continue;\n\n const importedFile = byPath.get(entry.file);\n\n if (importedFile && !countsForFeature(importedFile)) continue;\n\n const set = borrowers.get(entry.file) ?? new Set<string>();\n set.add(owner);\n borrowers.set(entry.file, set);\n }\n }\n\n for (const [file, set] of borrowers) {\n const ownership = files[file];\n const sorted = [...set].sort();\n\n if (ownership) ownership.borrowedBy = sorted;\n\n for (const feature of sorted) features[feature]?.borrowed.push(file);\n }\n\n for (const entry of Object.values(features)) {\n entry.own.sort();\n entry.borrowed.sort();\n }\n\n return { files, features };\n}\n"],"mappings":";;;;AA2BA,SAAS,YAAY,OAAwB;CAC3C,OAAO,WAAW,KAAK;AACzB;AAEA,SAAS,gBAAgB,QAAwB;CAC/C,OAAO,YAAY,OAAO,KAAK,CAAC,CAAC,CAAC,QAAQ,SAAS,EAAE,CAAC,CAAC,QAAQ,QAAQ,EAAE;AAC3E;;AAGA,SAAS,eAAe,MAA0B;CAChD,MAAM,UAAU,KAAK,KAAK,WAAW,CAAC,E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PATHS: {
25
25
  /** Warlock. */
26
26
  readonly tasksIndex: "grimoire/tasks/index.json";
27
27
  readonly releases: "grimoire/releases";
28
+ /** Images that written files show (`![alt](path)` lines point inside this folder). */
29
+ readonly screenshots: "grimoire/screenshots";
28
30
  };
29
31
  /** Lines a project's `.gitignore` needs so Warlock's files stay out of git. */
30
32
  export declare const GRIMOIRE_IGNORE_RULES: readonly ["/grimoire/book/", "/grimoire/features/index.json", "/grimoire/features/**/bookmap.json", "/grimoire/features/**/*.bookmap.json", "/grimoire/tasks/index.json"];
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/paths/index.ts"],"mappings":";;qBAOa;;qBAGA;;WAEX;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;WACA;;WAEA;WACA;WACA;WACA;WACA;;WAEA;WACA;;;qBAIW;;wBAWG,YAAY;;YAkDhB;EACV;;EAEA;IAAc;IAAY;;;;;;;;;;;;;;;wBAeZ,eAAe,gBAAgB,kBAAkB;;wBAiCjD,cAAc,OAAO"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/paths/index.ts"],"mappings":";;qBAOa;;qBAGA;;WAEX;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;WACA;;WAEA;WACA;WACA;WACA;WACA;;WAEA;WACA;;WAEA;;;qBAIW;;wBAWG,YAAY;;YAkDhB;EACV;;EAEA;IAAc;IAAY;;;;;;;;;;;;;;;wBAeZ,eAAe,gBAAgB,kBAAkB;;wBAiCjD,cAAc,OAAO"}
@@ -30,7 +30,9 @@ const GRIMOIRE_PATHS = {
30
30
  doneTasks: "grimoire/tasks/done",
31
31
  /** Warlock. */
32
32
  tasksIndex: "grimoire/tasks/index.json",
33
- releases: "grimoire/releases"
33
+ releases: "grimoire/releases",
34
+ /** Images that written files show (`![alt](path)` lines point inside this folder). */
35
+ screenshots: "grimoire/screenshots"
34
36
  };
35
37
  /** Lines a project's `.gitignore` needs so Warlock's files stay out of git. */
36
38
  const GRIMOIRE_IGNORE_RULES = [
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/paths/index.ts"],"sourcesContent":["/**\n * Where everything lives under `grimoire/`, and how a source file maps to its\n * book entry. Every path here is project-relative and uses `/`.\n */\nimport path from \"node:path\";\n\n/** The folder at the project root. */\nexport const GRIMOIRE_DIR = \"grimoire\";\n\n/** Project-relative paths of the Grimoire layout. Agent-written unless marked Warlock. */\nexport const GRIMOIRE_PATHS = {\n /** Warlock. The generated book (ignored by git). */\n book: \"grimoire/book\",\n /** Warlock. The freshness fingerprint. */\n bookManifest: \"grimoire/book/manifest.json\",\n /** Warlock. The adapter's last facts (machine use). */\n bookFactsCache: \"grimoire/book/.cache/facts.json\",\n /** Warlock. Every route, by module. */\n bookRoutes: \"grimoire/book/app/routes.json\",\n /** Warlock (the Vitest reporter). Test results per proving test. */\n testResults: \"grimoire/book/test-results.json\",\n /** Warlock. Default folder of the static devtools export. */\n staticSite: \"grimoire/book/site\",\n features: \"grimoire/features\",\n /** Warlock. */\n featuresIndex: \"grimoire/features/index.json\",\n apps: \"grimoire/apps\",\n tasks: \"grimoire/tasks\",\n openTasks: \"grimoire/tasks/open\",\n doneTasks: \"grimoire/tasks/done\",\n /** Warlock. */\n tasksIndex: \"grimoire/tasks/index.json\",\n releases: \"grimoire/releases\",\n} as const;\n\n/** Lines a project's `.gitignore` needs so Warlock's files stay out of git. */\nexport const GRIMOIRE_IGNORE_RULES = [\n \"/grimoire/book/\",\n \"/grimoire/features/index.json\",\n \"/grimoire/features/**/bookmap.json\",\n \"/grimoire/features/**/*.bookmap.json\",\n \"/grimoire/tasks/index.json\",\n] as const;\n\nconst CODE_EXTENSION = /\\.(?:d\\.ts|[cm]?[jt]s|[jt]sx)$/;\n\n/** A path with `\\` turned into `/`. */\nexport function toPosixPath(file: string): string {\n return file.split(\"\\\\\").join(\"/\");\n}\n\n/** A project-relative POSIX path for an absolute or relative path. */\nexport function projectPath(root: string, file: string): string {\n return toPosixPath(path.relative(root, path.resolve(root, file)));\n}\n\n/** Whether a project-relative file is inside a project-relative folder (or is it). */\nexport function isInsideFolder(file: string, folder: string): boolean {\n const normalizedFolder = toPosixPath(folder).replace(/\\/+$/, \"\");\n const normalizedFile = toPosixPath(file);\n\n return normalizedFile === normalizedFolder || normalizedFile.startsWith(`${normalizedFolder}/`);\n}\n\n/** Whether a file name is a code file the book has an entry for. */\nexport function isCodeFile(file: string): boolean {\n return CODE_EXTENSION.test(file);\n}\n\n/** Book paths Warlock writes for lists; a mirrored entry never takes one of them. */\nexport function isReservedBookPath(bookPath: string): boolean {\n return (\n bookPath === GRIMOIRE_PATHS.bookManifest ||\n bookPath === GRIMOIRE_PATHS.bookRoutes ||\n bookPath === GRIMOIRE_PATHS.testResults ||\n bookPath.startsWith(`${GRIMOIRE_PATHS.book}/.cache/`) ||\n bookPath.startsWith(`${GRIMOIRE_PATHS.staticSite}/`) ||\n /^grimoire\\/book\\/web\\/[^/]+\\.pages\\.json$/.test(bookPath) ||\n /^grimoire\\/book\\/mobile\\/[^/]+\\.screens\\.json$/.test(bookPath)\n );\n}\n\n/** The mirror of a source file without the collision rules: `src/` dropped, extension → `.json`. */\nfunction plainEntryPath(file: string, mobileApp: string | null, mobileRoot: string | null): string {\n const posix = toPosixPath(file);\n let relative: string;\n\n if (mobileApp !== null && mobileRoot !== null && isInsideFolder(posix, mobileRoot)) {\n relative = `mobile/${mobileApp}/${posix.slice(toPosixPath(mobileRoot).replace(/\\/+$/, \"\").length + 1)}`;\n } else {\n relative = posix.startsWith(\"src/\") ? posix.slice(4) : posix;\n }\n\n return `${GRIMOIRE_PATHS.book}/${relative.replace(CODE_EXTENSION, \"\")}.json`;\n}\n\n/** One file to place in the book. */\nexport type BookPathInput = {\n file: string;\n /** Mobile app id and root when the file belongs to a mobile app. */\n mobileApp?: { id: string; root: string } | null;\n};\n\n/**\n * The book entry path of every given code file.\n *\n * `src/app/auth/controllers/login.controller.ts` →\n * `grimoire/book/app/auth/controllers/login.controller.json`; a mobile app\n * file `mobile/app/index.tsx` of app `mobile` →\n * `grimoire/book/mobile/mobile/app/index.json`.\n *\n * When two files would share a path (`a.ts` and `a.tsx`), or a file would\n * take a reserved list path (`src/app/routes.ts` → `app/routes.json`), those\n * files keep their full name instead: `a.ts.json`, `routes.ts.json`.\n */\nexport function bookEntryPaths(files: readonly BookPathInput[]): Map<string, string> {\n const plain = new Map<string, string>();\n const counts = new Map<string, number>();\n\n for (const input of files) {\n const entry = plainEntryPath(\n input.file,\n input.mobileApp?.id ?? null,\n input.mobileApp?.root ?? null,\n );\n plain.set(input.file, entry);\n counts.set(entry, (counts.get(entry) ?? 0) + 1);\n }\n\n const result = new Map<string, string>();\n\n for (const input of files) {\n const entry = plain.get(input.file);\n\n if (entry === undefined) continue;\n\n if ((counts.get(entry) ?? 0) > 1 || isReservedBookPath(entry)) {\n const name = path.posix.basename(toPosixPath(input.file));\n result.set(input.file, `${path.posix.dirname(entry)}/${name}.json`);\n } else {\n result.set(input.file, entry);\n }\n }\n\n return result;\n}\n\n/** The book entry path of one file, when no other file can collide with it. */\nexport function bookEntryPath(input: BookPathInput): string {\n return bookEntryPaths([input]).get(input.file) ?? plainEntryPath(input.file, null, null);\n}\n\n/** `grimoire/book/web/<site>.pages.json`. */\nexport function sitePagesPath(site: string): string {\n return `${GRIMOIRE_PATHS.book}/web/${site}.pages.json`;\n}\n\n/** `grimoire/book/mobile/<app>.screens.json`. */\nexport function mobileScreensPath(app: string): string {\n return `${GRIMOIRE_PATHS.book}/mobile/${app}.screens.json`;\n}\n\n/** `grimoire/book/<module without src/>/index.md`. */\nexport function moduleSummaryPath(module: string): string {\n const posix = toPosixPath(module);\n\n return `${GRIMOIRE_PATHS.book}/${posix.startsWith(\"src/\") ? posix.slice(4) : posix}/index.md`;\n}\n\n/** `grimoire/features/<feature>/bookmap.json`. */\nexport function featureBookmapPath(feature: string): string {\n return `${GRIMOIRE_PATHS.features}/${feature}/bookmap.json`;\n}\n\n/** `grimoire/features/<feature>/flows/<flow>.bookmap.json`. */\nexport function flowBookmapPath(feature: string, flow: string): string {\n return `${GRIMOIRE_PATHS.features}/${feature}/flows/${flow}.bookmap.json`;\n}\n\n/** `grimoire/releases/<release>.md`. */\nexport function releaseFilePath(release: string): string {\n return `${GRIMOIRE_PATHS.releases}/${release}.md`;\n}\n"],"mappings":";;;;;;;;AAOA,MAAa,eAAe;;AAG5B,MAAa,iBAAiB;;CAE5B,MAAM;;CAEN,cAAc;;CAEd,gBAAgB;;CAEhB,YAAY;;CAEZ,aAAa;;CAEb,YAAY;CACZ,UAAU;;CAEV,eAAe;CACf,MAAM;CACN,OAAO;CACP,WAAW;CACX,WAAW;;CAEX,YAAY;CACZ,UAAU;AACZ;;AAGA,MAAa,wBAAwB;CACnC;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,iBAAiB;;AAGvB,SAAgB,YAAY,MAAsB;CAChD,OAAO,KAAK,MAAM,IAAI,CAAC,CAAC,KAAK,GAAG;AAClC;;AAGA,SAAgB,YAAY,MAAc,MAAsB;CAC9D,OAAO,YAAY,KAAK,SAAS,MAAM,KAAK,QAAQ,MAAM,IAAI,CAAC,CAAC;AAClE;;AAGA,SAAgB,eAAe,MAAc,QAAyB;CACpE,MAAM,mBAAmB,YAAY,MAAM,CAAC,CAAC,QAAQ,QAAQ,EAAE;CAC/D,MAAM,iBAAiB,YAAY,IAAI;CAEvC,OAAO,mBAAmB,oBAAoB,eAAe,WAAW,GAAG,iBAAiB,EAAE;AAChG;;AAGA,SAAgB,WAAW,MAAuB;CAChD,OAAO,eAAe,KAAK,IAAI;AACjC;;AAGA,SAAgB,mBAAmB,UAA2B;CAC5D,OACE,aAAa,eAAe,gBAC5B,aAAa,eAAe,cAC5B,aAAa,eAAe,eAC5B,SAAS,WAAW,GAAG,eAAe,KAAK,SAAS,KACpD,SAAS,WAAW,GAAG,eAAe,WAAW,EAAE,KACnD,4CAA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CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,MAAM,IAAI,KAAK,eAAe,MAAM,MAAM,MAAM,IAAI;AACzF;;AAGA,SAAgB,cAAc,MAAsB;CAClD,OAAO,GAAG,eAAe,KAAK,OAAO,KAAK;AAC5C;;AAGA,SAAgB,kBAAkB,KAAqB;CACrD,OAAO,GAAG,eAAe,KAAK,UAAU,IAAI;AAC9C;;AAGA,SAAgB,kBAAkB,QAAwB;CACxD,MAAM,QAAQ,YAAY,MAAM;CAEhC,OAAO,GAAG,eAAe,KAAK,GAAG,MAAM,WAAW,MAAM,IAAI,MAAM,MAAM,CAAC,IAAI,MAAM;AACrF;;AAGA,SAAgB,mBAAmB,SAAyB;CAC1D,OAAO,GAAG,eAAe,SAAS,GAAG,QAAQ;AAC/C;;AAGA,SAAgB,gBAAgB,SAAiB,MAAsB;CACrE,OAAO,GAAG,eAAe,SAAS,GAAG,QAAQ,SAAS,KAAK;AAC7D;;AAGA,SAAgB,gBAAgB,SAAyB;CACvD,OAAO,GAAG,eAAe,SAAS,GAAG,QAAQ;AAC/C"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/paths/index.ts"],"sourcesContent":["/**\n * Where everything lives under `grimoire/`, and how a source file maps to its\n * book entry. Every path here is project-relative and uses `/`.\n */\nimport path from \"node:path\";\n\n/** The folder at the project root. */\nexport const GRIMOIRE_DIR = \"grimoire\";\n\n/** Project-relative paths of the Grimoire layout. Agent-written unless marked Warlock. */\nexport const GRIMOIRE_PATHS = {\n /** Warlock. The generated book (ignored by git). */\n book: \"grimoire/book\",\n /** Warlock. The freshness fingerprint. */\n bookManifest: \"grimoire/book/manifest.json\",\n /** Warlock. The adapter's last facts (machine use). */\n bookFactsCache: \"grimoire/book/.cache/facts.json\",\n /** Warlock. Every route, by module. */\n bookRoutes: \"grimoire/book/app/routes.json\",\n /** Warlock (the Vitest reporter). Test results per proving test. */\n testResults: \"grimoire/book/test-results.json\",\n /** Warlock. Default folder of the static devtools export. */\n staticSite: \"grimoire/book/site\",\n features: \"grimoire/features\",\n /** Warlock. */\n featuresIndex: \"grimoire/features/index.json\",\n apps: \"grimoire/apps\",\n tasks: \"grimoire/tasks\",\n openTasks: \"grimoire/tasks/open\",\n doneTasks: \"grimoire/tasks/done\",\n /** Warlock. */\n tasksIndex: \"grimoire/tasks/index.json\",\n releases: \"grimoire/releases\",\n /** Images that written files show (`![alt](path)` lines point inside this folder). */\n screenshots: \"grimoire/screenshots\",\n} as const;\n\n/** Lines a project's `.gitignore` needs so Warlock's files stay out of git. */\nexport const GRIMOIRE_IGNORE_RULES = [\n \"/grimoire/book/\",\n \"/grimoire/features/index.json\",\n \"/grimoire/features/**/bookmap.json\",\n \"/grimoire/features/**/*.bookmap.json\",\n \"/grimoire/tasks/index.json\",\n] as const;\n\nconst CODE_EXTENSION = /\\.(?:d\\.ts|[cm]?[jt]s|[jt]sx)$/;\n\n/** A path with `\\` turned into `/`. */\nexport function toPosixPath(file: string): string {\n return file.split(\"\\\\\").join(\"/\");\n}\n\n/** A project-relative POSIX path for an absolute or relative path. */\nexport function projectPath(root: string, file: string): string {\n return toPosixPath(path.relative(root, path.resolve(root, file)));\n}\n\n/** Whether a project-relative file is inside a project-relative folder (or is it). */\nexport function isInsideFolder(file: string, folder: string): boolean {\n const normalizedFolder = toPosixPath(folder).replace(/\\/+$/, \"\");\n const normalizedFile = toPosixPath(file);\n\n return normalizedFile === normalizedFolder || normalizedFile.startsWith(`${normalizedFolder}/`);\n}\n\n/** Whether a file name is a code file the book has an entry for. */\nexport function isCodeFile(file: string): boolean {\n return CODE_EXTENSION.test(file);\n}\n\n/** Book paths Warlock writes for lists; a mirrored entry never takes one of them. */\nexport function isReservedBookPath(bookPath: string): boolean {\n return (\n bookPath === GRIMOIRE_PATHS.bookManifest ||\n bookPath === GRIMOIRE_PATHS.bookRoutes ||\n bookPath === GRIMOIRE_PATHS.testResults ||\n bookPath.startsWith(`${GRIMOIRE_PATHS.book}/.cache/`) ||\n bookPath.startsWith(`${GRIMOIRE_PATHS.staticSite}/`) ||\n /^grimoire\\/book\\/web\\/[^/]+\\.pages\\.json$/.test(bookPath) ||\n /^grimoire\\/book\\/mobile\\/[^/]+\\.screens\\.json$/.test(bookPath)\n );\n}\n\n/** The mirror of a source file without the collision rules: `src/` dropped, extension → `.json`. */\nfunction plainEntryPath(file: string, mobileApp: string | null, mobileRoot: string | null): string {\n const posix = toPosixPath(file);\n let relative: string;\n\n if (mobileApp !== null && mobileRoot !== null && isInsideFolder(posix, mobileRoot)) {\n relative = `mobile/${mobileApp}/${posix.slice(toPosixPath(mobileRoot).replace(/\\/+$/, \"\").length + 1)}`;\n } else {\n relative = posix.startsWith(\"src/\") ? posix.slice(4) : posix;\n }\n\n return `${GRIMOIRE_PATHS.book}/${relative.replace(CODE_EXTENSION, \"\")}.json`;\n}\n\n/** One file to place in the book. */\nexport type BookPathInput = {\n file: string;\n /** Mobile app id and root when the file belongs to a mobile app. */\n mobileApp?: { id: string; root: string } | null;\n};\n\n/**\n * The book entry path of every given code file.\n *\n * `src/app/auth/controllers/login.controller.ts` →\n * `grimoire/book/app/auth/controllers/login.controller.json`; a mobile app\n * file `mobile/app/index.tsx` of app `mobile` →\n * `grimoire/book/mobile/mobile/app/index.json`.\n *\n * When two files would share a path (`a.ts` and `a.tsx`), or a file would\n * take a reserved list path (`src/app/routes.ts` → `app/routes.json`), those\n * files keep their full name instead: `a.ts.json`, `routes.ts.json`.\n */\nexport function bookEntryPaths(files: readonly BookPathInput[]): Map<string, string> {\n const plain = new Map<string, string>();\n const counts = new Map<string, number>();\n\n for (const input of files) {\n const entry = plainEntryPath(\n input.file,\n input.mobileApp?.id ?? null,\n input.mobileApp?.root ?? null,\n );\n plain.set(input.file, entry);\n counts.set(entry, (counts.get(entry) ?? 0) + 1);\n }\n\n const result = new Map<string, string>();\n\n for (const input of files) {\n const entry = plain.get(input.file);\n\n if (entry === undefined) continue;\n\n if ((counts.get(entry) ?? 0) > 1 || isReservedBookPath(entry)) {\n const name = path.posix.basename(toPosixPath(input.file));\n result.set(input.file, `${path.posix.dirname(entry)}/${name}.json`);\n } else {\n result.set(input.file, entry);\n }\n }\n\n return result;\n}\n\n/** The book entry path of one file, when no other file can collide with it. */\nexport function bookEntryPath(input: BookPathInput): string {\n return bookEntryPaths([input]).get(input.file) ?? plainEntryPath(input.file, null, null);\n}\n\n/** `grimoire/book/web/<site>.pages.json`. */\nexport function sitePagesPath(site: string): string {\n return `${GRIMOIRE_PATHS.book}/web/${site}.pages.json`;\n}\n\n/** `grimoire/book/mobile/<app>.screens.json`. */\nexport function mobileScreensPath(app: string): string {\n return `${GRIMOIRE_PATHS.book}/mobile/${app}.screens.json`;\n}\n\n/** `grimoire/book/<module without src/>/index.md`. */\nexport function moduleSummaryPath(module: string): string {\n const posix = toPosixPath(module);\n\n return `${GRIMOIRE_PATHS.book}/${posix.startsWith(\"src/\") ? posix.slice(4) : posix}/index.md`;\n}\n\n/** `grimoire/features/<feature>/bookmap.json`. */\nexport function featureBookmapPath(feature: string): string {\n return `${GRIMOIRE_PATHS.features}/${feature}/bookmap.json`;\n}\n\n/** `grimoire/features/<feature>/flows/<flow>.bookmap.json`. */\nexport function flowBookmapPath(feature: string, flow: string): string {\n return `${GRIMOIRE_PATHS.features}/${feature}/flows/${flow}.bookmap.json`;\n}\n\n/** `grimoire/releases/<release>.md`. */\nexport function releaseFilePath(release: string): string {\n return `${GRIMOIRE_PATHS.releases}/${release}.md`;\n}\n"],"mappings":";;;;;;;;AAOA,MAAa,eAAe;;AAG5B,MAAa,iBAAiB;;CAE5B,MAAM;;CAEN,cAAc;;CAEd,gBAAgB;;CAEhB,YAAY;;CAEZ,aAAa;;CAEb,YAAY;CACZ,UAAU;;CAEV,eAAe;CACf,MAAM;CACN,OAAO;CACP,WAAW;CACX,WAAW;;CAEX,YAAY;CACZ,UAAU;;CAEV,aAAa;AACf;;AAGA,MAAa,wBAAwB;CACnC;CACA;CACA;CACA;CACA;AACF;AAEA,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,QAAQ,SAAS,KAAK;AAC7D;;AAGA,SAAgB,gBAAgB,SAAyB;CACvD,OAAO,GAAG,eAAe,SAAS,GAAG,QAAQ;AAC/C"}
@@ -0,0 +1,170 @@
1
+ import { testResultsInfo } from "../test-results/index.mjs";
2
+
3
+ //#region ../../packages/grimoire/src/scry/compact.ts
4
+ /** The file sets a step can list, in the order a view shows them. */
5
+ const STEP_FILE_SETS = [
6
+ "direct",
7
+ "feature",
8
+ "reachable",
9
+ "type-only"
10
+ ];
11
+ const byText = (left, right) => left < right ? -1 : left > right ? 1 : 0;
12
+ /** The files of a step the flow's feature owns. */
13
+ function featureFiles(snapshot, feature, step) {
14
+ return step.files.filter((file) => snapshot.ownership.files[file]?.owner === feature);
15
+ }
16
+ /** How many files a step reaches, by set. */
17
+ function stepCounts(snapshot, feature, step) {
18
+ return {
19
+ direct: step.direct.length,
20
+ feature: featureFiles(snapshot, feature, step).length,
21
+ reachable: step.files.length,
22
+ typeOnly: step.typeOnlyFiles.length
23
+ };
24
+ }
25
+ /** The flows of a feature in the README's Flows order, else in file order. */
26
+ function flowOrder(feature) {
27
+ const byId = new Map(feature.flows.map((flow) => [flow.id.value, flow]));
28
+ const listed = (feature.readme?.flows ?? []).flatMap((line) => {
29
+ const flow = byId.get(line.name);
30
+ return flow === void 0 ? [] : [flow];
31
+ });
32
+ if (listed.length === 0) return feature.flows;
33
+ const seen = new Set(listed);
34
+ return [...listed, ...feature.flows.filter((flow) => !seen.has(flow))];
35
+ }
36
+ function neighbour(flow) {
37
+ return flow === void 0 ? null : {
38
+ id: flow.id.value,
39
+ heading: flow.heading?.value ?? null
40
+ };
41
+ }
42
+ /** The flow before and after `flowId` in its feature. */
43
+ function neighboursOf(feature, flowId) {
44
+ const order = flowOrder(feature);
45
+ const position = order.findIndex((flow) => flow.id.value === flowId);
46
+ if (position < 0) return {
47
+ previous: null,
48
+ next: null
49
+ };
50
+ return {
51
+ previous: neighbour(order[position - 1]),
52
+ next: neighbour(order[position + 1])
53
+ };
54
+ }
55
+ /** The health strip numbers of a flow (criteria, steps, findings). */
56
+ function flowHealth(result) {
57
+ const byStatus = {
58
+ pass: 0,
59
+ fail: 0,
60
+ stale: 0,
61
+ "not-run": 0,
62
+ "no-test": 0
63
+ };
64
+ for (const criterion of result.bookmap.criteria) byStatus[criterion.status] += 1;
65
+ const checked = result.bookmap.steps.filter((step) => step.found !== null);
66
+ const unexpected = result.findings.filter((finding) => !finding.expected);
67
+ const errors = unexpected.filter((finding) => finding.severity === "error").length;
68
+ return {
69
+ criteria: {
70
+ total: result.bookmap.criteria.length,
71
+ proven: byStatus.pass,
72
+ byStatus
73
+ },
74
+ steps: {
75
+ total: checked.length,
76
+ resolved: checked.filter((step) => step.found === true).length,
77
+ unchecked: result.bookmap.steps.length - checked.length
78
+ },
79
+ findings: {
80
+ errors,
81
+ warnings: unexpected.length - errors,
82
+ expected: result.findings.length - unexpected.length
83
+ }
84
+ };
85
+ }
86
+ /** One step with counts and the first direct imports; the file lists are left out. */
87
+ function compactStep(snapshot, feature, step, written) {
88
+ const { files: _files, typeOnlyFiles: _typeOnly, direct, ...rest } = step;
89
+ const target = written?.steps.find((item) => item.index === step.index)?.affects ?? null;
90
+ let linked = null;
91
+ if (target !== null && target.flow !== null) {
92
+ const other = (target.feature === feature.id ? feature : snapshot.written.features.find((item) => item.id === target.feature))?.flows.find((item) => item.id.value === target.flow);
93
+ if (other !== void 0) linked = {
94
+ ref: other.ref,
95
+ heading: other.heading?.value ?? null,
96
+ summary: other.summary
97
+ };
98
+ }
99
+ return {
100
+ ...rest,
101
+ counts: stepCounts(snapshot, feature.id, step),
102
+ direct: direct.slice(0, 50),
103
+ linked
104
+ };
105
+ }
106
+ /** The scry flow answer made compact, with the flow page header data. */
107
+ function compactFlow(snapshot, result) {
108
+ const feature = snapshot.written.features.find((item) => item.id === result.flow.feature);
109
+ if (feature === void 0) throw new Error(`Feature ${result.flow.feature} is not written.`);
110
+ const readme = feature.readme;
111
+ const { previous, next } = neighboursOf(feature, result.flow.id.value);
112
+ return {
113
+ ...result,
114
+ bookmap: {
115
+ ...result.bookmap,
116
+ steps: result.bookmap.steps.map((step) => compactStep(snapshot, feature, step, result.flow))
117
+ },
118
+ feature: {
119
+ id: feature.id,
120
+ title: readme?.title.value ?? feature.id,
121
+ status: readme?.status.value ?? result.flow.status.value,
122
+ apps: (readme?.apps ?? []).map((app) => app.value)
123
+ },
124
+ previous,
125
+ next,
126
+ health: flowHealth(result),
127
+ results: testResultsInfo(snapshot)
128
+ };
129
+ }
130
+ /** The files of one set of a step, sorted by module and then path. */
131
+ function stepFileSet(snapshot, feature, step, set) {
132
+ const files = set === "direct" ? step.direct : set === "feature" ? featureFiles(snapshot, feature, step) : set === "reachable" ? step.files : step.typeOnlyFiles;
133
+ const modules = new Map(snapshot.book.facts.files.map((item) => [item.file, item.module]));
134
+ const moduleOf = (file) => modules.get(file) ?? "";
135
+ return [...files].sort((left, right) => byText(moduleOf(left), moduleOf(right)) || byText(left, right));
136
+ }
137
+ /**
138
+ * One page of a step's files with the module counts of the whole set.
139
+ * `limit` is capped at {@link STEP_FILES_PAGE_LIMIT}.
140
+ */
141
+ function stepFilePage(snapshot, bookmap, step, set, offset, limit) {
142
+ const sorted = stepFileSet(snapshot, bookmap.feature, step, set);
143
+ const modules = new Map(snapshot.book.facts.files.map((item) => [item.file, item.module]));
144
+ const moduleOf = (file) => modules.get(file) ?? "";
145
+ const size = Math.min(Math.max(1, Math.floor(limit)), 200);
146
+ const start = Math.max(0, Math.floor(offset));
147
+ const counts = /* @__PURE__ */ new Map();
148
+ for (const file of sorted) counts.set(moduleOf(file), (counts.get(moduleOf(file)) ?? 0) + 1);
149
+ return {
150
+ ref: bookmap.ref,
151
+ index: step.index,
152
+ set,
153
+ total: sorted.length,
154
+ offset: start,
155
+ limit: size,
156
+ files: sorted.slice(start, start + size).map((file) => ({
157
+ file,
158
+ module: moduleOf(file),
159
+ owner: snapshot.ownership.files[file]?.owner ?? null
160
+ })),
161
+ modules: [...counts].map(([module, count]) => ({
162
+ module,
163
+ count
164
+ })).sort((left, right) => right.count - left.count || byText(left.module, right.module))
165
+ };
166
+ }
167
+
168
+ //#endregion
169
+ export { STEP_FILE_SETS, compactFlow, compactStep, flowHealth, flowOrder, neighboursOf, stepCounts, stepFilePage, stepFileSet };
170
+ //# sourceMappingURL=compact.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compact.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/scry/compact.ts"],"sourcesContent":["/**\n * The compact flow answer: a flow's steps as counts and the first direct\n * imports instead of every reachable file, plus what a flow page header needs\n * (feature, neighbours, health, test results). The devtools route\n * `GET /flows/:feature/:flow` and the MCP tool `grimoire_flow` both send it;\n * `scry()` itself keeps the full answer.\n */\nimport type { FlowBookmap, FlowBookmapStep } from \"../contracts/bookmap\";\nimport type { ScryFlowResult } from \"../contracts/scry\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport type { CriterionStatus } from \"../contracts/test-results\";\nimport type { WrittenFeature, WrittenFlow } from \"../contracts/written\";\nimport {\n FLOW_STEP_DIRECT_LIMIT,\n STEP_FILES_PAGE_LIMIT,\n type GrimoireFlowAnswer,\n type GrimoireFlowHealth,\n type GrimoireFlowNeighbour,\n type GrimoireFlowStep,\n type GrimoireStepFilesAnswer,\n type StepFileCounts,\n type StepFileSet,\n} from \"../devtools/answers\";\nimport { testResultsInfo } from \"../test-results\";\n\n/** The file sets a step can list, in the order a view shows them. */\nexport const STEP_FILE_SETS: readonly StepFileSet[] = [\n \"direct\",\n \"feature\",\n \"reachable\",\n \"type-only\",\n];\n\nconst byText = (left: string, right: string): number => (left < right ? -1 : left > right ? 1 : 0);\n\n/** The files of a step the flow's feature owns. */\nfunction featureFiles(\n snapshot: GrimoireSnapshot,\n feature: string,\n step: FlowBookmapStep,\n): string[] {\n return step.files.filter((file) => snapshot.ownership.files[file]?.owner === feature);\n}\n\n/** How many files a step reaches, by set. */\nexport function stepCounts(\n snapshot: GrimoireSnapshot,\n feature: string,\n step: FlowBookmapStep,\n): StepFileCounts {\n return {\n direct: step.direct.length,\n feature: featureFiles(snapshot, feature, step).length,\n reachable: step.files.length,\n typeOnly: step.typeOnlyFiles.length,\n };\n}\n\n/** The flows of a feature in the README's Flows order, else in file order. */\nexport function flowOrder(feature: WrittenFeature): WrittenFlow[] {\n const byId = new Map(feature.flows.map((flow) => [flow.id.value, flow]));\n const listed = (feature.readme?.flows ?? []).flatMap((line) => {\n const flow = byId.get(line.name);\n\n return flow === undefined ? [] : [flow];\n });\n\n if (listed.length === 0) return feature.flows;\n\n // A flow the README does not list follows the listed ones, in file order.\n const seen = new Set(listed);\n\n return [...listed, ...feature.flows.filter((flow) => !seen.has(flow))];\n}\n\nfunction neighbour(flow: WrittenFlow | undefined): GrimoireFlowNeighbour | null {\n return flow === undefined ? null : { id: flow.id.value, heading: flow.heading?.value ?? null };\n}\n\n/** The flow before and after `flowId` in its feature. */\nexport function neighboursOf(\n feature: WrittenFeature,\n flowId: string,\n): { previous: GrimoireFlowNeighbour | null; next: GrimoireFlowNeighbour | null } {\n const order = flowOrder(feature);\n const position = order.findIndex((flow) => flow.id.value === flowId);\n\n if (position < 0) return { previous: null, next: null };\n\n return { previous: neighbour(order[position - 1]), next: neighbour(order[position + 1]) };\n}\n\n/** The health strip numbers of a flow (criteria, steps, findings). */\nexport function flowHealth(result: ScryFlowResult): GrimoireFlowHealth {\n const byStatus: Record<CriterionStatus, number> = {\n pass: 0,\n fail: 0,\n stale: 0,\n \"not-run\": 0,\n \"no-test\": 0,\n };\n\n for (const criterion of result.bookmap.criteria) byStatus[criterion.status] += 1;\n\n const checked = result.bookmap.steps.filter((step) => step.found !== null);\n const unexpected = result.findings.filter((finding) => !finding.expected);\n const errors = unexpected.filter((finding) => finding.severity === \"error\").length;\n\n return {\n criteria: { total: result.bookmap.criteria.length, proven: byStatus.pass, byStatus },\n steps: {\n total: checked.length,\n resolved: checked.filter((step) => step.found === true).length,\n unchecked: result.bookmap.steps.length - checked.length,\n },\n findings: {\n errors,\n warnings: unexpected.length - errors,\n expected: result.findings.length - unexpected.length,\n },\n };\n}\n\n/** One step with counts and the first direct imports; the file lists are left out. */\nexport function compactStep(\n snapshot: GrimoireSnapshot,\n feature: WrittenFeature,\n step: FlowBookmapStep,\n written: WrittenFlow | undefined,\n): GrimoireFlowStep {\n const { files: _files, typeOnlyFiles: _typeOnly, direct, ...rest } = step;\n const target = written?.steps.find((item) => item.index === step.index)?.affects ?? null;\n let linked: GrimoireFlowStep[\"linked\"] = null;\n\n if (target !== null && target.flow !== null) {\n const owner =\n target.feature === feature.id\n ? feature\n : snapshot.written.features.find((item) => item.id === target.feature);\n const other = owner?.flows.find((item) => item.id.value === target.flow);\n\n if (other !== undefined) {\n linked = { ref: other.ref, heading: other.heading?.value ?? null, summary: other.summary };\n }\n }\n\n return {\n ...rest,\n counts: stepCounts(snapshot, feature.id, step),\n direct: direct.slice(0, FLOW_STEP_DIRECT_LIMIT),\n linked,\n };\n}\n\n/** The scry flow answer made compact, with the flow page header data. */\nexport function compactFlow(\n snapshot: GrimoireSnapshot,\n result: ScryFlowResult,\n): GrimoireFlowAnswer {\n const feature = snapshot.written.features.find((item) => item.id === result.flow.feature);\n\n if (feature === undefined) {\n throw new Error(`Feature ${result.flow.feature} is not written.`);\n }\n\n const readme = feature.readme;\n const { previous, next } = neighboursOf(feature, result.flow.id.value);\n\n return {\n ...result,\n bookmap: {\n ...result.bookmap,\n steps: result.bookmap.steps.map((step) => compactStep(snapshot, feature, step, result.flow)),\n },\n feature: {\n id: feature.id,\n title: readme?.title.value ?? feature.id,\n status: readme?.status.value ?? result.flow.status.value,\n apps: (readme?.apps ?? []).map((app) => app.value),\n },\n previous,\n next,\n health: flowHealth(result),\n results: testResultsInfo(snapshot),\n };\n}\n\n/** The files of one set of a step, sorted by module and then path. */\nexport function stepFileSet(\n snapshot: GrimoireSnapshot,\n feature: string,\n step: FlowBookmapStep,\n set: StepFileSet,\n): string[] {\n const files =\n set === \"direct\"\n ? step.direct\n : set === \"feature\"\n ? featureFiles(snapshot, feature, step)\n : set === \"reachable\"\n ? step.files\n : step.typeOnlyFiles;\n const modules = new Map(snapshot.book.facts.files.map((item) => [item.file, item.module]));\n const moduleOf = (file: string): string => modules.get(file) ?? \"\";\n\n return [...files].sort(\n (left, right) => byText(moduleOf(left), moduleOf(right)) || byText(left, right),\n );\n}\n\n/**\n * One page of a step's files with the module counts of the whole set.\n * `limit` is capped at {@link STEP_FILES_PAGE_LIMIT}.\n */\nexport function stepFilePage(\n snapshot: GrimoireSnapshot,\n bookmap: FlowBookmap,\n step: FlowBookmapStep,\n set: StepFileSet,\n offset: number,\n limit: number,\n): GrimoireStepFilesAnswer {\n const sorted = stepFileSet(snapshot, bookmap.feature, step, set);\n const modules = new Map(snapshot.book.facts.files.map((item) => [item.file, item.module]));\n const moduleOf = (file: string): string => modules.get(file) ?? \"\";\n const size = Math.min(Math.max(1, Math.floor(limit)), STEP_FILES_PAGE_LIMIT);\n const start = Math.max(0, Math.floor(offset));\n const counts = new Map<string, number>();\n\n for (const file of sorted) counts.set(moduleOf(file), (counts.get(moduleOf(file)) ?? 0) + 1);\n\n return {\n ref: bookmap.ref,\n index: step.index,\n set,\n total: sorted.length,\n offset: start,\n limit: size,\n files: sorted.slice(start, start + size).map((file) => ({\n file,\n module: moduleOf(file),\n owner: snapshot.ownership.files[file]?.owner ?? null,\n })),\n modules: [...counts]\n .map(([module, count]) => ({ module, count }))\n .sort((left, right) => right.count - left.count || byText(left.module, right.module)),\n };\n}\n"],"mappings":";;;;AA0BA,MAAa,iBAAyC;CACpD;CACA;CACA;CACA;AACF;AAEA,MAAM,UAAU,MAAc,UAA2B,OAAO,QAAQ,KAAK,OAAO,QAAQ,IAAI;;AAGhG,SAAS,aACP,UACA,SACA,MACU;CACV,OAAO,KAAK,MAAM,QAAQ,SAAS,SAAS,UAAU,MAAM,KAAK,EAAE,UAAU,OAAO;AACtF;;AAGA,SAAgB,WACd,UACA,SACA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K,MAAM,KAAK,MAAM,CAAC,CAAC;CACzF,MAAM,YAAY,SAAyB,QAAQ,IAAI,IAAI,KAAK;CAChE,MAAM,OAAO,KAAK,IAAI,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK,CAAC,MAAwB;CAC3E,MAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,MAAM,MAAM,CAAC;CAC5C,MAAM,yBAAS,IAAI,IAAoB;CAEvC,KAAK,MAAM,QAAQ,QAAQ,OAAO,IAAI,SAAS,IAAI,IAAI,OAAO,IAAI,SAAS,IAAI,CAAC,KAAK,KAAK,CAAC;CAE3F,OAAO;EACL,KAAK,QAAQ;EACb,OAAO,KAAK;EACZ;EACA,OAAO,OAAO;EACd,QAAQ;EACR,OAAO;EACP,OAAO,OAAO,MAAM,OAAO,QAAQ,IAAI,CAAC,CAAC,KAAK,UAAU;GACtD;GACA,QAAQ,SAAS,IAAI;GACrB,OAAO,SAAS,UAAU,MAAM,KAAK,EAAE,SAAS;EAClD,EAAE;EACF,SAAS,CAAC,GAAG,MAAM,CAAC,CACjB,KAAK,CAAC,QAAQ,YAAY;GAAE;GAAQ;EAAM,EAAE,CAAC,CAC7C,MAAM,MAAM,UAAU,MAAM,QAAQ,KAAK,SAAS,OAAO,KAAK,QAAQ,MAAM,MAAM,CAAC;CACxF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"format.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/scry/format.ts"],"mappings":";;;YAmCY;;EAEV;;;;;;wBAoVc,iBAAiB,QAAQ,YAAY,UAAS"}
1
+ {"version":3,"file":"format.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/scry/format.ts"],"mappings":";;;YAmCY;;EAEV;;;;;;wBA8Wc,iBAAiB,QAAQ,YAAY,UAAS"}
@@ -128,11 +128,16 @@ const STATUS_TEXT = {
128
128
  "not-run": "not run",
129
129
  "no-test": "no test"
130
130
  };
131
+ /** ` (+12 reachable, 3 type-only)`: what a step reaches beyond its entry file; empty when nothing. */
132
+ function reachNote(step) {
133
+ const parts = [...step.files.length > 1 ? [`+${step.files.length - 1} reachable`] : [], ...step.typeOnlyFiles.length > 0 ? [`${step.typeOnlyFiles.length} type-only`] : []];
134
+ return parts.length === 0 ? "" : ` (${parts.join(", ")})`;
135
+ }
131
136
  function stepLines(steps) {
132
137
  const typeWidth = Math.max(0, ...steps.map((step) => step.type.length));
133
138
  const targetWidth = Math.max(0, ...steps.map((step) => step.target.length));
134
139
  return steps.map((step) => {
135
- const where = step.found === false ? "not found" : step.entry === null ? step.found === null && step.type === "route" ? "no route facts" : "—" : `${step.entry}${step.files.length > 1 ? ` (+${step.files.length - 1} files)` : ""}`;
140
+ const where = step.found === false ? "not found" : step.entry === null ? step.found === null && step.type === "route" ? "no route facts" : "—" : `${step.entry}${reachNote(step)}`;
136
141
  return `${step.index}. ${step.type.padEnd(typeWidth)} ${step.target.padEnd(targetWidth)} ${where}`;
137
142
  });
138
143
  }
@@ -157,6 +162,7 @@ function formatFlow(result) {
157
162
  `${flow.status.value} since ${flow.since.value}`,
158
163
  `who ${flow.who.value}`
159
164
  ].join(" "),
165
+ ...flow.summary === null ? [] : [flow.summary],
160
166
  ...stepLines(result.bookmap.steps),
161
167
  ...section("differs", flow.differs.map((line) => `${line.name}: ${line.text}`)),
162
168
  ...section("not handled", flow.notHandled.map((line) => `${line.name}: ${line.text}`), 12),
@@ -168,10 +174,21 @@ function formatFlow(result) {
168
174
  ...notes(result)
169
175
  ];
170
176
  }
177
+ /** One line telling what the limit cut, per type, or nothing when every match is listed. */
178
+ function truncatedLine(result) {
179
+ const total = Object.values(result.counts).reduce((sum, count) => sum + (count ?? 0), 0);
180
+ if (total <= result.hits.length) return [];
181
+ const parts = Object.entries(result.counts).map(([type, count]) => `${count} ${type}`);
182
+ return [`showing ${result.hits.length} of ${total} (${parts.join(", ")}); raise --limit for more`];
183
+ }
171
184
  function formatSearch(result) {
172
185
  if (result.hits.length === 0) return [`no match for ${JSON.stringify(result.text)}`, ...notes(result)];
173
186
  const idWidth = Math.min(32, Math.max(0, ...result.hits.map((hit) => hit.id.length)));
174
- return [...result.hits.map((hit) => (hit.detail === null ? `${hit.type.padEnd(9)}${hit.id}` : `${hit.type.padEnd(9)}${hit.id.padEnd(idWidth)} ${hit.detail}`).trimEnd()), ...notes(result)];
187
+ return [
188
+ ...result.hits.map((hit) => (hit.detail === null ? `${hit.type.padEnd(9)}${hit.id}` : `${hit.type.padEnd(9)}${hit.id.padEnd(idWidth)} ${hit.detail}`).trimEnd() + (hit.matched === void 0 ? "" : ` [${hit.matched}]`)),
189
+ ...truncatedLine(result),
190
+ ...notes(result)
191
+ ];
175
192
  }
176
193
  /**
177
194
  * The compact text of a result (formats in the commands guide). Long lists in an