@warlock.js/grimoire 5.56.0 → 5.58.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 (105) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/esm/book/build.d.mts.map +1 -1
  3. package/esm/book/build.mjs +2 -1
  4. package/esm/book/build.mjs.map +1 -1
  5. package/esm/book/render.mjs +10 -0
  6. package/esm/book/render.mjs.map +1 -1
  7. package/esm/bookmap/build.d.mts.map +1 -1
  8. package/esm/bookmap/build.mjs +2 -2
  9. package/esm/bookmap/build.mjs.map +1 -1
  10. package/esm/bookmap/steps.mjs +53 -38
  11. package/esm/bookmap/steps.mjs.map +1 -1
  12. package/esm/check/check-grimoire.d.mts.map +1 -1
  13. package/esm/check/check-grimoire.mjs +4 -1
  14. package/esm/check/check-grimoire.mjs.map +1 -1
  15. package/esm/check/rules/criteria.mjs +21 -2
  16. package/esm/check/rules/criteria.mjs.map +1 -1
  17. package/esm/check/rules/screenshots.mjs +57 -0
  18. package/esm/check/rules/screenshots.mjs.map +1 -0
  19. package/esm/codes/codes.d.mts +12 -0
  20. package/esm/codes/codes.d.mts.map +1 -1
  21. package/esm/codes/codes.mjs +6 -0
  22. package/esm/codes/codes.mjs.map +1 -1
  23. package/esm/contracts/adapter.d.mts +6 -0
  24. package/esm/contracts/adapter.d.mts.map +1 -1
  25. package/esm/contracts/book.d.mts +2 -0
  26. package/esm/contracts/book.d.mts.map +1 -1
  27. package/esm/contracts/book.mjs.map +1 -1
  28. package/esm/contracts/bookmap.d.mts +19 -1
  29. package/esm/contracts/bookmap.d.mts.map +1 -1
  30. package/esm/contracts/snapshot.d.mts +11 -0
  31. package/esm/contracts/snapshot.d.mts.map +1 -1
  32. package/esm/contracts/test-results.d.mts +34 -0
  33. package/esm/contracts/test-results.d.mts.map +1 -1
  34. package/esm/contracts/written.d.mts +44 -0
  35. package/esm/contracts/written.d.mts.map +1 -1
  36. package/esm/contracts/written.mjs.map +1 -1
  37. package/esm/devtools/data.mjs +126 -4
  38. package/esm/devtools/data.mjs.map +1 -1
  39. package/esm/devtools/index.d.mts +31 -1
  40. package/esm/devtools/index.d.mts.map +1 -1
  41. package/esm/devtools/index.mjs +94 -5
  42. package/esm/devtools/index.mjs.map +1 -1
  43. package/esm/devtools/product-map.d.mts +14 -0
  44. package/esm/devtools/product-map.d.mts.map +1 -0
  45. package/esm/devtools/product-map.mjs +385 -0
  46. package/esm/devtools/product-map.mjs.map +1 -0
  47. package/esm/devtools/site.d.mts.map +1 -1
  48. package/esm/devtools/site.mjs +97 -21
  49. package/esm/devtools/site.mjs.map +1 -1
  50. package/esm/devtools/snapshot-source.mjs +71 -22
  51. package/esm/devtools/snapshot-source.mjs.map +1 -1
  52. package/esm/graph/index.d.mts +10 -1
  53. package/esm/graph/index.d.mts.map +1 -1
  54. package/esm/graph/index.mjs +3 -2
  55. package/esm/graph/index.mjs.map +1 -1
  56. package/esm/index.d.mts +4 -4
  57. package/esm/paths/index.d.mts +2 -0
  58. package/esm/paths/index.d.mts.map +1 -1
  59. package/esm/paths/index.mjs +3 -1
  60. package/esm/paths/index.mjs.map +1 -1
  61. package/esm/scry/compact.mjs +169 -0
  62. package/esm/scry/compact.mjs.map +1 -0
  63. package/esm/scry/format.d.mts.map +1 -1
  64. package/esm/scry/format.mjs +7 -1
  65. package/esm/scry/format.mjs.map +1 -1
  66. package/esm/scry/query.d.mts.map +1 -1
  67. package/esm/scry/query.mjs +12 -1
  68. package/esm/scry/query.mjs.map +1 -1
  69. package/esm/test-results/index.d.mts +7 -2
  70. package/esm/test-results/index.d.mts.map +1 -1
  71. package/esm/test-results/index.mjs +79 -12
  72. package/esm/test-results/index.mjs.map +1 -1
  73. package/esm/vitest/index.d.mts +6 -0
  74. package/esm/vitest/index.d.mts.map +1 -1
  75. package/esm/vitest/index.mjs +22 -6
  76. package/esm/vitest/index.mjs.map +1 -1
  77. package/esm/warlock/adapter.d.mts.map +1 -1
  78. package/esm/warlock/adapter.mjs +6 -2
  79. package/esm/warlock/adapter.mjs.map +1 -1
  80. package/esm/warlock/mcp-tools.mjs +48 -12
  81. package/esm/warlock/mcp-tools.mjs.map +1 -1
  82. package/esm/workspace/index.d.mts.map +1 -1
  83. package/esm/workspace/index.mjs +4 -2
  84. package/esm/workspace/index.mjs.map +1 -1
  85. package/esm/written/apps.mjs +4 -2
  86. package/esm/written/apps.mjs.map +1 -1
  87. package/esm/written/features.mjs +119 -6
  88. package/esm/written/features.mjs.map +1 -1
  89. package/esm/written/markdown.mjs +66 -1
  90. package/esm/written/markdown.mjs.map +1 -1
  91. package/esm/written/parse-grimoire.d.mts.map +1 -1
  92. package/esm/written/parse-grimoire.mjs +1 -1
  93. package/esm/written/parse-grimoire.mjs.map +1 -1
  94. package/llms-full.txt +77 -2
  95. package/package.json +3 -3
  96. package/skills/backfill-a-grimoire/SKILL.md +5 -0
  97. package/skills/describe-an-app/SKILL.md +12 -0
  98. package/skills/record-a-change/SKILL.md +8 -0
  99. package/skills/use-the-grimoire/SKILL.md +15 -0
  100. package/skills/write-a-feature/SKILL.md +37 -2
  101. package/ui/grimoire-static.js +4 -0
  102. package/ui/grimoire-view.js +2283 -428
  103. package/ui/grimoire.css +1036 -45
  104. package/ui/product-map.css +636 -0
  105. package/ui/product-map.js +817 -0
package/esm/index.d.mts CHANGED
@@ -2,12 +2,12 @@ import { BookAdapter, BookExport, BookFacts, BookFile, BookFileType, BookImport,
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 { CollectedListText, ReleaseCollection, ReleaseEntry, WriteReleaseResult } from "./contracts/releases.mjs";
10
9
  import { ScryFeatureResult, ScryFileResult, ScryFlowResult, ScryHit, ScryHitType, ScryImpactResult, ScryNotes, ScryPageRef, ScryQuery, ScryResult, ScryRouteResult, ScrySearchResult } from "./contracts/scry.mjs";
10
+ import { CollectedListText, ReleaseCollection, ReleaseEntry, WriteReleaseResult } from "./contracts/releases.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, 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, 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 };
@@ -25,6 +25,8 @@ export declare const GRIMOIRE_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;AACh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C7D,MAAM,OAAO,KAAK,MAAM,SAAS,YAAY,MAAM,IAAI,CAAC;GACxD,OAAO,IAAI,MAAM,MAAM,GAAG,KAAK,MAAM,QAAQ,KAAK,EAAE,GAAG,KAAK,MAAM;EACpE,OACE,OAAO,IAAI,MAAM,MAAM,KAAK;CAEhC;CAEA,OAAO;AACT;;AAGA,SAAgB,cAAc,OAA8B;CAC1D,OAAO,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,MAAM,IAAI,KAAK,eAAe,MAAM,MAAM,MAAM,IAAI;AACzF;;AAGA,SAAgB,cAAc,MAAsB;CAClD,OAAO,GAAG,eAAe,KAAK,OAAO,KAAK;AAC5C;;AAGA,SAAgB,kBAAkB,KAAqB;CACrD,OAAO,GAAG,eAAe,KAAK,UAAU,IAAI;AAC9C;;AAGA,SAAgB,kBAAkB,QAAwB;CACxD,MAAM,QAAQ,YAAY,MAAM;CAEhC,OAAO,GAAG,eAAe,KAAK,GAAG,MAAM,WAAW,MAAM,IAAI,MAAM,MAAM,CAAC,IAAI,MAAM;AACrF;;AAGA,SAAgB,mBAAmB,SAAyB;CAC1D,OAAO,GAAG,eAAe,SAAS,GAAG,QAAQ;AAC/C;;AAGA,SAAgB,gBAAgB,SAAiB,MAAsB;CACrE,OAAO,GAAG,eAAe,SAAS,GAAG,QAAQ,SAAS,KAAK;AAC7D;;AAGA,SAAgB,gBAAgB,SAAyB;CACvD,OAAO,GAAG,eAAe,SAAS,GAAG,QAAQ;AAC/C"}
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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AAM;CAEhC,OAAO,GAAG,eAAe,KAAK,GAAG,MAAM,WAAW,MAAM,IAAI,MAAM,MAAM,CAAC,IAAI,MAAM;AACrF;;AAGA,SAAgB,mBAAmB,SAAyB;CAC1D,OAAO,GAAG,eAAe,SAAS,GAAG,QAAQ;AAC/C;;AAGA,SAAgB,gBAAgB,SAAiB,MAAsB;CACrE,OAAO,GAAG,eAAe,SAAS,GAAG,QAAQ,SAAS,KAAK;AAC7D;;AAGA,SAAgB,gBAAgB,SAAyB;CACvD,OAAO,GAAG,eAAe,SAAS,GAAG,QAAQ;AAC/C"}
@@ -0,0 +1,169 @@
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
+ },
78
+ findings: {
79
+ errors,
80
+ warnings: unexpected.length - errors,
81
+ expected: result.findings.length - unexpected.length
82
+ }
83
+ };
84
+ }
85
+ /** One step with counts and the first direct imports; the file lists are left out. */
86
+ function compactStep(snapshot, feature, step, written) {
87
+ const { files: _files, typeOnlyFiles: _typeOnly, direct, ...rest } = step;
88
+ const target = written?.steps.find((item) => item.index === step.index)?.affects ?? null;
89
+ let linked = null;
90
+ if (target !== null && target.flow !== null) {
91
+ const other = (target.feature === feature.id ? feature : snapshot.written.features.find((item) => item.id === target.feature))?.flows.find((item) => item.id.value === target.flow);
92
+ if (other !== void 0) linked = {
93
+ ref: other.ref,
94
+ heading: other.heading?.value ?? null,
95
+ summary: other.summary
96
+ };
97
+ }
98
+ return {
99
+ ...rest,
100
+ counts: stepCounts(snapshot, feature.id, step),
101
+ direct: direct.slice(0, 50),
102
+ linked
103
+ };
104
+ }
105
+ /** The scry flow answer made compact, with the flow page header data. */
106
+ function compactFlow(snapshot, result) {
107
+ const feature = snapshot.written.features.find((item) => item.id === result.flow.feature);
108
+ if (feature === void 0) throw new Error(`Feature ${result.flow.feature} is not written.`);
109
+ const readme = feature.readme;
110
+ const { previous, next } = neighboursOf(feature, result.flow.id.value);
111
+ return {
112
+ ...result,
113
+ bookmap: {
114
+ ...result.bookmap,
115
+ steps: result.bookmap.steps.map((step) => compactStep(snapshot, feature, step, result.flow))
116
+ },
117
+ feature: {
118
+ id: feature.id,
119
+ title: readme?.title.value ?? feature.id,
120
+ status: readme?.status.value ?? result.flow.status.value,
121
+ apps: (readme?.apps ?? []).map((app) => app.value)
122
+ },
123
+ previous,
124
+ next,
125
+ health: flowHealth(result),
126
+ results: testResultsInfo(snapshot)
127
+ };
128
+ }
129
+ /** The files of one set of a step, sorted by module and then path. */
130
+ function stepFileSet(snapshot, feature, step, set) {
131
+ const files = set === "direct" ? step.direct : set === "feature" ? featureFiles(snapshot, feature, step) : set === "reachable" ? step.files : step.typeOnlyFiles;
132
+ const modules = new Map(snapshot.book.facts.files.map((item) => [item.file, item.module]));
133
+ const moduleOf = (file) => modules.get(file) ?? "";
134
+ return [...files].sort((left, right) => byText(moduleOf(left), moduleOf(right)) || byText(left, right));
135
+ }
136
+ /**
137
+ * One page of a step's files with the module counts of the whole set.
138
+ * `limit` is capped at {@link STEP_FILES_PAGE_LIMIT}.
139
+ */
140
+ function stepFilePage(snapshot, bookmap, step, set, offset, limit) {
141
+ const sorted = stepFileSet(snapshot, bookmap.feature, step, set);
142
+ const modules = new Map(snapshot.book.facts.files.map((item) => [item.file, item.module]));
143
+ const moduleOf = (file) => modules.get(file) ?? "";
144
+ const size = Math.min(Math.max(1, Math.floor(limit)), 200);
145
+ const start = Math.max(0, Math.floor(offset));
146
+ const counts = /* @__PURE__ */ new Map();
147
+ for (const file of sorted) counts.set(moduleOf(file), (counts.get(moduleOf(file)) ?? 0) + 1);
148
+ return {
149
+ ref: bookmap.ref,
150
+ index: step.index,
151
+ set,
152
+ total: sorted.length,
153
+ offset: start,
154
+ limit: size,
155
+ files: sorted.slice(start, start + size).map((file) => ({
156
+ file,
157
+ module: moduleOf(file),
158
+ owner: snapshot.ownership.files[file]?.owner ?? null
159
+ })),
160
+ modules: [...counts].map(([module, count]) => ({
161
+ module,
162
+ count
163
+ })).sort((left, right) => right.count - left.count || byText(left.module, right.module))
164
+ };
165
+ }
166
+
167
+ //#endregion
168
+ export { STEP_FILE_SETS, compactFlow, compactStep, flowHealth, flowOrder, neighboursOf, stepCounts, stepFilePage, stepFileSet };
169
+ //# 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[] = [\"direct\", \"feature\", \"reachable\", \"type-only\"];\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(snapshot: GrimoireSnapshot, feature: string, step: FlowBookmapStep): 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: { total: checked.length, resolved: checked.filter((step) => step.found === true).length },\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(snapshot: GrimoireSnapshot, result: ScryFlowResult): 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((left, right) => byText(moduleOf(left), moduleOf(right)) || byText(left, right));\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;CAAC;CAAU;CAAW;CAAa;AAAW;AAEpG,MAAM,UAAU,MAAc,UAA2B,OAAO,QAAQ,KAAK,OAAO,QAAQ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CACzB,MAAM,SAAS,YAAY,UAAU,QAAQ,SAAS,MAAM,GAAG;CAC/D,MAAM,UAAU,IAAI,IAAI,SAAS,KAAK,MAAM,MAAM,KAAK,SAAS,CAAC,KAAK,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;;;;;;wBA+Vc,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),
@@ -1 +1 @@
1
- {"version":3,"file":"format.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/scry/format.ts"],"sourcesContent":["/**\n * The compact text of a scry answer: a title line, then `label value` lines\n * with the labels in one column. Empty sections are left out.\n */\nimport type { FlowBookmapCriterion, FlowBookmapStep } from \"../contracts/bookmap\";\nimport type { CriterionStatus } from \"../contracts/test-results\";\nimport type { GrimoireFinding } from \"../contracts/findings\";\nimport type {\n ScryFeatureResult,\n ScryFileResult,\n ScryFlowResult,\n ScryImpactResult,\n ScryResult,\n ScryRouteResult,\n ScrySearchResult,\n} from \"../contracts/scry\";\nimport type { WrittenChangelogEntry } from \"../contracts/written\";\n\nconst LABEL = 10;\n\n/** `label` padded to the column, then the first value; more values go on indented lines. */\nfunction section(label: string, values: readonly string[], width = LABEL): string[] {\n if (values.length === 0) return [];\n\n const pad = \" \".repeat(Math.max(width, label.length + 1));\n\n return values.map((value, index) =>\n index === 0 ? `${label.padEnd(pad.length)}${value}` : `${pad}${value}`,\n );\n}\n\n/** Longest list a text section prints before it says how many more there are. */\nconst SECTION_CAP = 20;\n\n/** What the text formatters may be told. */\nexport type FormatScryOptions = {\n /** Print every line of every section, not the first 20. */\n all?: boolean;\n};\n\n/** A section whose heading carries the count (`routes (3)`) and whose list stops at the cap. */\nfunction countedSection(\n label: string,\n values: readonly string[],\n options: FormatScryOptions,\n width: number,\n): string[] {\n const shown = options.all === true ? values : values.slice(0, SECTION_CAP);\n const lines = section(`${label} (${values.length})`, shown, width);\n\n if (shown.length < values.length) {\n lines.push(\n `${\" \".repeat(Math.max(width, label.length + 1))}… and ${values.length - shown.length} more (--all lists every one)`,\n );\n }\n\n return lines;\n}\n\nconst plural = (count: number, word: string): string => `${count} ${word}${count === 1 ? \"\" : \"s\"}`;\n\n/** Cut text at a word so it fits `max` characters, ending with ` …`. */\nfunction shorten(text: string, max: number): string {\n if (text.length <= max) return text;\n\n const words = text.split(\" \");\n let kept = \"\";\n\n for (const word of words) {\n const next = kept === \"\" ? word : `${kept} ${word}`;\n\n if (next.length + 2 > max) break;\n\n kept = next;\n }\n\n return `${kept === \"\" ? text.slice(0, max - 2) : kept} …`;\n}\n\nfunction notes(result: ScryResult): string[] {\n return section(\"note\", result.notes);\n}\n\nfunction countsLine(findings: readonly GrimoireFinding[]): string {\n const errors = findings.filter(\n (finding) => !finding.expected && finding.severity === \"error\",\n ).length;\n const warnings = findings.filter(\n (finding) => !finding.expected && finding.severity === \"warning\",\n ).length;\n const expected = findings.filter((finding) => finding.expected).length;\n\n return `${plural(errors, \"error\")}, ${plural(warnings, \"warning\")}, ${expected} expected`;\n}\n\nfunction releaseOf(entry: WrittenChangelogEntry): string {\n return entry.release === null ? \"unreleased\" : `${entry.release}, ${entry.date ?? \"no date\"}`;\n}\n\nfunction formatFile(result: ScryFileResult): string[] {\n const entry = result.entry;\n const feature =\n entry.feature === null && entry.borrowedBy.length === 0\n ? []\n : [\n `${entry.feature ?? \"none\"}${entry.borrowedBy.length > 0 ? ` (borrowed by: ${entry.borrowedBy.join(\", \")})` : \"\"}`,\n ];\n const exportWidth = Math.max(0, ...entry.exports.map((item) => item.name.length));\n\n return [\n `${entry.file} ${entry.type} ${plural(entry.lines, \"line\")}`,\n ...section(\"about\", entry.about === null ? [] : [entry.about]),\n ...section(\"feature\", feature),\n ...section(\"flows\", entry.flows),\n ...section(\n \"exports\",\n entry.exports.map((item) =>\n item.about === null ? item.name : `${item.name.padEnd(exportWidth)} ${item.about}`,\n ),\n ),\n ...section(\"packages\", entry.packages.length > 0 ? [entry.packages.join(\" \")] : []),\n ...section(\"imports\", entry.imports),\n ...section(\"used by\", entry.importedBy),\n ...section(\n \"routes\",\n entry.routes.map(\n (route) =>\n `${route.method} ${route.path}${route.via === \"handles\" ? \" (handles)\" : \" (registers)\"}`,\n ),\n ),\n ...section(\n \"pages\",\n entry.pages.map((page) => `${page.site} ${page.route} (${page.via})`),\n ),\n ...section(\n \"screens\",\n entry.screens.map((screen) => `${screen.app} ${screen.route} (${screen.via})`),\n ),\n ...section(\"entry\", result.bookEntry === null ? [] : [result.bookEntry]),\n ...notes(result),\n ];\n}\n\nfunction formatImpact(result: ScryImpactResult, options: FormatScryOptions): string[] {\n const width = 14;\n\n return [\n `impact of ${result.file}`,\n `${\"importers\".padEnd(width)}${result.importers.direct.length} direct, ${result.importers.all.length} in all`,\n ...countedSection(\n \"routes\",\n result.routes.map((route) => `${route.method} ${route.path}`),\n options,\n width,\n ),\n ...countedSection(\n \"pages\",\n result.pages.map((page) => `${page.app} ${page.route}`),\n options,\n width,\n ),\n ...countedSection(\"flows\", result.flows, options, width),\n ...countedSection(\n \"features\",\n result.features.map((feature) => `${feature.id} (${feature.via})`),\n options,\n width,\n ),\n ...countedSection(\"tests\", result.tests, options, width),\n ...notes(result),\n ];\n}\n\nfunction formatRoute(result: ScryRouteResult): string[] {\n const route = result.route;\n const width = 12;\n const auth = route.auth.required\n ? `required (${route.auth.userTypes.length > 0 ? route.auth.userTypes.join(\", \") : \"any user\"})`\n : \"none\";\n\n return [\n `${route.method} ${route.path}${route.name === null ? \"\" : ` ${route.name}`}`,\n ...section(\n \"handler\",\n [`${route.handler}${route.handlerFile === null ? \"\" : ` ${route.handlerFile}`}`],\n width,\n ),\n ...section(\"registered\", route.sourceFile === null ? [] : [route.sourceFile], width),\n ...section(\n \"middleware\",\n route.middleware.length > 0 ? [route.middleware.join(\" \")] : [],\n width,\n ),\n ...section(\"auth\", [auth], width),\n ...section(\"description\", route.description === null ? [] : [route.description], width),\n ...section(\n \"page\",\n result.page === null ? [] : [`${result.page.site} ${result.page.route} ${result.page.file}`],\n width,\n ),\n ...section(\"files\", result.files, width),\n ...section(\n \"steps\",\n result.steps.map((step) => `${step.flow} step ${step.index}`),\n width,\n ),\n ...notes(result),\n ];\n}\n\nfunction changeLine(entry: WrittenChangelogEntry): string {\n const text = `${entry.flow === null ? \"\" : `${entry.flow}: `}${entry.text}`;\n\n return `${entry.version.value} ${entry.word} ${shorten(text, 60)} (${releaseOf(entry)})`;\n}\n\nfunction formatFeature(result: ScryFeatureResult): string[] {\n const readme = result.readme;\n const bookmap = result.bookmap;\n const idWidth = Math.max(0, ...result.flows.map((flow) => flow.id.length));\n const statusWidth = Math.max(0, ...result.flows.map((flow) => flow.status.length));\n const pages = Object.entries(bookmap.pages)\n .sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))\n .flatMap(([app, list]) => list.map((page) => `${app} ${page.route}`));\n const apps = readme.apps.map((app) => app.value);\n\n return [\n [\n readme.id.value,\n readme.title.value,\n `${readme.status.value} ${readme.version.value}`,\n `updated ${readme.updated.value}`,\n ...(apps.length > 0 ? [`apps ${apps.join(\", \")}`] : []),\n ].join(\" \"),\n ...section(\n \"flows\",\n result.flows.map(\n (flow) =>\n `${flow.id.padEnd(idWidth)} ${flow.status.padEnd(statusWidth)} since ${flow.since}`,\n ),\n ),\n ...section(\"own\", [\n `${plural(bookmap.own.length, \"file\")} (unreached: ${bookmap.unreached.length === 0 ? \"none\" : bookmap.unreached.length})`,\n ]),\n ...section(\"unreached\", bookmap.unreached),\n ...section(\n \"borrows\",\n bookmap.borrowed.map((item) => item.file),\n ),\n ...section(\n \"routes\",\n bookmap.routes.length > 0\n ? [bookmap.routes.map((route) => `${route.method} ${route.path}`).join(\" \")]\n : [],\n ),\n ...section(\"pages\", pages.length > 0 ? [pages.join(\" \")] : []),\n ...section(\"changes\", result.changes.map(changeLine)),\n ...section(\n \"tasks\",\n result.tasks.map((task) => `${task.id} ${task.status} ${task.title}`),\n ),\n ...section(\"check\", [countsLine(result.findings)]),\n ...notes(result),\n ];\n}\n\nconst STATUS_TEXT: Record<CriterionStatus, string> = {\n pass: \"pass\",\n fail: \"fail\",\n stale: \"stale\",\n \"not-run\": \"not run\",\n \"no-test\": \"no test\",\n};\n\nfunction stepLines(steps: readonly FlowBookmapStep[]): string[] {\n const typeWidth = Math.max(0, ...steps.map((step) => step.type.length));\n const targetWidth = Math.max(0, ...steps.map((step) => step.target.length));\n\n return steps.map((step) => {\n const where =\n step.found === false\n ? \"not found\"\n : step.entry === null\n ? step.found === null && step.type === \"route\"\n ? \"no route facts\"\n : \"—\"\n : `${step.entry}${step.files.length > 1 ? ` (+${step.files.length - 1} files)` : \"\"}`;\n\n return `${step.index}. ${step.type.padEnd(typeWidth)} ${step.target.padEnd(targetWidth)} ${where}`;\n });\n}\n\nfunction criterionLines(criteria: readonly FlowBookmapCriterion[]): string[] {\n const labels = criteria.map(\n (criterion) => `${criterion.id}${criterion.app === null ? \"\" : ` [${criterion.app}]`}`,\n );\n const labelWidth = Math.max(0, ...labels.map((label) => label.length));\n const texts = criteria.map((criterion) => shorten(criterion.text, 36));\n const textWidth = Math.max(0, ...texts.map((text) => text.length));\n\n return criteria.map((criterion, index) => {\n const test = criterion.tests[0];\n const where =\n test === undefined\n ? \"\"\n : `${test.file}:${test.line}${criterion.tests.length > 1 ? ` (+${criterion.tests.length - 1})` : \"\"}`;\n const line = `${(labels[index] ?? \"\").padEnd(labelWidth)} ${STATUS_TEXT[criterion.status].padEnd(7)} ${\n where === \"\" ? (texts[index] ?? \"\") : `${(texts[index] ?? \"\").padEnd(textWidth)} ${where}`\n }`;\n\n return line.trimEnd();\n });\n}\n\nfunction formatFlow(result: ScryFlowResult): string[] {\n const flow = result.flow;\n const shown = result.bookmap.shownBy.map((item) => `${item.app} ${item.id}: ${item.block}`);\n\n return [\n [\n flow.ref,\n ...(flow.heading === null ? [] : [flow.heading.value]),\n `${flow.status.value} since ${flow.since.value}`,\n `who ${flow.who.value}`,\n ].join(\" \"),\n ...stepLines(result.bookmap.steps),\n ...section(\n \"differs\",\n flow.differs.map((line) => `${line.name}: ${line.text}`),\n ),\n ...section(\n \"not handled\",\n flow.notHandled.map((line) => `${line.name}: ${line.text}`),\n 12,\n ),\n ...section(\n \"unknown\",\n flow.unknowns.map((item) => item.text.replace(/^Unknown:\\s*/, \"\")),\n ),\n ...criterionLines(result.bookmap.criteria),\n ...section(\"shown on\", shown.length > 0 ? [shown.join(\" \")] : []),\n ...section(\n \"history\",\n result.history.length > 0\n ? [\n result.history\n .map((entry) => `${entry.version.value} ${entry.word} (${releaseOf(entry)})`)\n .join(\" \"),\n ]\n : [],\n ),\n ...section(\"check\", [countsLine(result.findings)]),\n ...notes(result),\n ];\n}\n\nfunction formatSearch(result: ScrySearchResult): string[] {\n if (result.hits.length === 0)\n return [`no match for ${JSON.stringify(result.text)}`, ...notes(result)];\n\n const idWidth = Math.min(32, Math.max(0, ...result.hits.map((hit) => hit.id.length)));\n\n return [\n ...result.hits.map((hit) =>\n (hit.detail === null\n ? `${hit.type.padEnd(9)}${hit.id}`\n : `${hit.type.padEnd(9)}${hit.id.padEnd(idWidth)} ${hit.detail}`\n ).trimEnd(),\n ),\n ...notes(result),\n ];\n}\n\n/**\n * The compact text of a result (formats in the commands guide). Long lists in an\n * impact answer stop after 20 lines with a count; `options.all` prints them all.\n */\nexport function formatScryResult(result: ScryResult, options: FormatScryOptions = {}): string[] {\n switch (result.type) {\n case \"file\":\n return formatFile(result);\n case \"impact\":\n return formatImpact(result, options);\n case \"route\":\n return formatRoute(result);\n case \"feature\":\n return formatFeature(result);\n case \"flow\":\n return formatFlow(result);\n case \"search\":\n return formatSearch(result);\n }\n}\n"],"mappings":";AAkBA,MAAM,QAAQ;;AAGd,SAAS,QAAQ,OAAe,QAA2B,QAAQ,OAAiB;CAClF,IAAI,OAAO,WAAW,GAAG,OAAO,CAAC;CAEjC,MAAM,MAAM,IAAI,OAAO,KAAK,IAAI,OAAO,MAAM,SAAS,CAAC,CAAC;CAExD,OAAO,OAAO,KAAK,OAAO,UACxB,UAAU,IAAI,GAAG,MAAM,OAAO,IAAI,MAAM,IAAI,UAAU,GAAG,MAAM,OACjE;AACF;;AAGA,MAAM,cAAc;;AASpB,SAAS,eACP,OACA,QACA,SACA,OACU;CACV,MAAM,QAAQ,QAAQ,QAAQ,OAAO,SAAS,OAAO,MAAM,GAAG,WAAW;CACzE,MAAM,QAAQ,QAAQ,GAAG,MAAM,IAAI,OAAO,OAAO,IAAI,OAAO,KAAK;CAEjE,IAAI,MAAM,SAAS,OAAO,QACxB,MAAM,KACJ,GAAG,IAAI,OAAO,KAAK,IAAI,OAAO,MAAM,SAAS,CAAC,CAAC,EAAE,QAAQ,OAAO,SAAS,MAAM,OAAO,8BACxF;CAGF,OAAO;AACT;AAEA,MAAM,UAAU,OAAe,SAAyB,GAAG,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,IAAI,IAAI,GAAG,OAAO,OAAO,EAAE,IAAI,IAAI,SAAQ,CACjE,QAAQ,CACZ,GACA,GAAG,MAAM,MAAM,CACjB;AACF;;;;;AAMA,SAAgB,iBAAiB,QAAoB,UAA6B,CAAC,GAAa;CAC9F,QAAQ,OAAO,MAAf;EACE,KAAK,QACH,OAAO,WAAW,MAAM;EAC1B,KAAK,UACH,OAAO,aAAa,QAAQ,OAAO;EACrC,KAAK,SACH,OAAO,YAAY,MAAM;EAC3B,KAAK,WACH,OAAO,cAAc,MAAM;EAC7B,KAAK,QACH,OAAO,WAAW,MAAM;EAC1B,KAAK,UACH,OAAO,aAAa,MAAM;CAC9B;AACF"}
1
+ {"version":3,"file":"format.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/scry/format.ts"],"sourcesContent":["/**\n * The compact text of a scry answer: a title line, then `label value` lines\n * with the labels in one column. Empty sections are left out.\n */\nimport type { FlowBookmapCriterion, FlowBookmapStep } from \"../contracts/bookmap\";\nimport type { CriterionStatus } from \"../contracts/test-results\";\nimport type { GrimoireFinding } from \"../contracts/findings\";\nimport type {\n ScryFeatureResult,\n ScryFileResult,\n ScryFlowResult,\n ScryImpactResult,\n ScryResult,\n ScryRouteResult,\n ScrySearchResult,\n} from \"../contracts/scry\";\nimport type { WrittenChangelogEntry } from \"../contracts/written\";\n\nconst LABEL = 10;\n\n/** `label` padded to the column, then the first value; more values go on indented lines. */\nfunction section(label: string, values: readonly string[], width = LABEL): string[] {\n if (values.length === 0) return [];\n\n const pad = \" \".repeat(Math.max(width, label.length + 1));\n\n return values.map((value, index) =>\n index === 0 ? `${label.padEnd(pad.length)}${value}` : `${pad}${value}`,\n );\n}\n\n/** Longest list a text section prints before it says how many more there are. */\nconst SECTION_CAP = 20;\n\n/** What the text formatters may be told. */\nexport type FormatScryOptions = {\n /** Print every line of every section, not the first 20. */\n all?: boolean;\n};\n\n/** A section whose heading carries the count (`routes (3)`) and whose list stops at the cap. */\nfunction countedSection(\n label: string,\n values: readonly string[],\n options: FormatScryOptions,\n width: number,\n): string[] {\n const shown = options.all === true ? values : values.slice(0, SECTION_CAP);\n const lines = section(`${label} (${values.length})`, shown, width);\n\n if (shown.length < values.length) {\n lines.push(\n `${\" \".repeat(Math.max(width, label.length + 1))}… and ${values.length - shown.length} more (--all lists every one)`,\n );\n }\n\n return lines;\n}\n\nconst plural = (count: number, word: string): string => `${count} ${word}${count === 1 ? \"\" : \"s\"}`;\n\n/** Cut text at a word so it fits `max` characters, ending with ` …`. */\nfunction shorten(text: string, max: number): string {\n if (text.length <= max) return text;\n\n const words = text.split(\" \");\n let kept = \"\";\n\n for (const word of words) {\n const next = kept === \"\" ? word : `${kept} ${word}`;\n\n if (next.length + 2 > max) break;\n\n kept = next;\n }\n\n return `${kept === \"\" ? text.slice(0, max - 2) : kept} …`;\n}\n\nfunction notes(result: ScryResult): string[] {\n return section(\"note\", result.notes);\n}\n\nfunction countsLine(findings: readonly GrimoireFinding[]): string {\n const errors = findings.filter(\n (finding) => !finding.expected && finding.severity === \"error\",\n ).length;\n const warnings = findings.filter(\n (finding) => !finding.expected && finding.severity === \"warning\",\n ).length;\n const expected = findings.filter((finding) => finding.expected).length;\n\n return `${plural(errors, \"error\")}, ${plural(warnings, \"warning\")}, ${expected} expected`;\n}\n\nfunction releaseOf(entry: WrittenChangelogEntry): string {\n return entry.release === null ? \"unreleased\" : `${entry.release}, ${entry.date ?? \"no date\"}`;\n}\n\nfunction formatFile(result: ScryFileResult): string[] {\n const entry = result.entry;\n const feature =\n entry.feature === null && entry.borrowedBy.length === 0\n ? []\n : [\n `${entry.feature ?? \"none\"}${entry.borrowedBy.length > 0 ? ` (borrowed by: ${entry.borrowedBy.join(\", \")})` : \"\"}`,\n ];\n const exportWidth = Math.max(0, ...entry.exports.map((item) => item.name.length));\n\n return [\n `${entry.file} ${entry.type} ${plural(entry.lines, \"line\")}`,\n ...section(\"about\", entry.about === null ? [] : [entry.about]),\n ...section(\"feature\", feature),\n ...section(\"flows\", entry.flows),\n ...section(\n \"exports\",\n entry.exports.map((item) =>\n item.about === null ? item.name : `${item.name.padEnd(exportWidth)} ${item.about}`,\n ),\n ),\n ...section(\"packages\", entry.packages.length > 0 ? [entry.packages.join(\" \")] : []),\n ...section(\"imports\", entry.imports),\n ...section(\"used by\", entry.importedBy),\n ...section(\n \"routes\",\n entry.routes.map(\n (route) =>\n `${route.method} ${route.path}${route.via === \"handles\" ? \" (handles)\" : \" (registers)\"}`,\n ),\n ),\n ...section(\n \"pages\",\n entry.pages.map((page) => `${page.site} ${page.route} (${page.via})`),\n ),\n ...section(\n \"screens\",\n entry.screens.map((screen) => `${screen.app} ${screen.route} (${screen.via})`),\n ),\n ...section(\"entry\", result.bookEntry === null ? [] : [result.bookEntry]),\n ...notes(result),\n ];\n}\n\nfunction formatImpact(result: ScryImpactResult, options: FormatScryOptions): string[] {\n const width = 14;\n\n return [\n `impact of ${result.file}`,\n `${\"importers\".padEnd(width)}${result.importers.direct.length} direct, ${result.importers.all.length} in all`,\n ...countedSection(\n \"routes\",\n result.routes.map((route) => `${route.method} ${route.path}`),\n options,\n width,\n ),\n ...countedSection(\n \"pages\",\n result.pages.map((page) => `${page.app} ${page.route}`),\n options,\n width,\n ),\n ...countedSection(\"flows\", result.flows, options, width),\n ...countedSection(\n \"features\",\n result.features.map((feature) => `${feature.id} (${feature.via})`),\n options,\n width,\n ),\n ...countedSection(\"tests\", result.tests, options, width),\n ...notes(result),\n ];\n}\n\nfunction formatRoute(result: ScryRouteResult): string[] {\n const route = result.route;\n const width = 12;\n const auth = route.auth.required\n ? `required (${route.auth.userTypes.length > 0 ? route.auth.userTypes.join(\", \") : \"any user\"})`\n : \"none\";\n\n return [\n `${route.method} ${route.path}${route.name === null ? \"\" : ` ${route.name}`}`,\n ...section(\n \"handler\",\n [`${route.handler}${route.handlerFile === null ? \"\" : ` ${route.handlerFile}`}`],\n width,\n ),\n ...section(\"registered\", route.sourceFile === null ? [] : [route.sourceFile], width),\n ...section(\n \"middleware\",\n route.middleware.length > 0 ? [route.middleware.join(\" \")] : [],\n width,\n ),\n ...section(\"auth\", [auth], width),\n ...section(\"description\", route.description === null ? [] : [route.description], width),\n ...section(\n \"page\",\n result.page === null ? [] : [`${result.page.site} ${result.page.route} ${result.page.file}`],\n width,\n ),\n ...section(\"files\", result.files, width),\n ...section(\n \"steps\",\n result.steps.map((step) => `${step.flow} step ${step.index}`),\n width,\n ),\n ...notes(result),\n ];\n}\n\nfunction changeLine(entry: WrittenChangelogEntry): string {\n const text = `${entry.flow === null ? \"\" : `${entry.flow}: `}${entry.text}`;\n\n return `${entry.version.value} ${entry.word} ${shorten(text, 60)} (${releaseOf(entry)})`;\n}\n\nfunction formatFeature(result: ScryFeatureResult): string[] {\n const readme = result.readme;\n const bookmap = result.bookmap;\n const idWidth = Math.max(0, ...result.flows.map((flow) => flow.id.length));\n const statusWidth = Math.max(0, ...result.flows.map((flow) => flow.status.length));\n const pages = Object.entries(bookmap.pages)\n .sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))\n .flatMap(([app, list]) => list.map((page) => `${app} ${page.route}`));\n const apps = readme.apps.map((app) => app.value);\n\n return [\n [\n readme.id.value,\n readme.title.value,\n `${readme.status.value} ${readme.version.value}`,\n `updated ${readme.updated.value}`,\n ...(apps.length > 0 ? [`apps ${apps.join(\", \")}`] : []),\n ].join(\" \"),\n ...section(\n \"flows\",\n result.flows.map(\n (flow) =>\n `${flow.id.padEnd(idWidth)} ${flow.status.padEnd(statusWidth)} since ${flow.since}`,\n ),\n ),\n ...section(\"own\", [\n `${plural(bookmap.own.length, \"file\")} (unreached: ${bookmap.unreached.length === 0 ? \"none\" : bookmap.unreached.length})`,\n ]),\n ...section(\"unreached\", bookmap.unreached),\n ...section(\n \"borrows\",\n bookmap.borrowed.map((item) => item.file),\n ),\n ...section(\n \"routes\",\n bookmap.routes.length > 0\n ? [bookmap.routes.map((route) => `${route.method} ${route.path}`).join(\" \")]\n : [],\n ),\n ...section(\"pages\", pages.length > 0 ? [pages.join(\" \")] : []),\n ...section(\"changes\", result.changes.map(changeLine)),\n ...section(\n \"tasks\",\n result.tasks.map((task) => `${task.id} ${task.status} ${task.title}`),\n ),\n ...section(\"check\", [countsLine(result.findings)]),\n ...notes(result),\n ];\n}\n\nconst STATUS_TEXT: Record<CriterionStatus, string> = {\n pass: \"pass\",\n fail: \"fail\",\n stale: \"stale\",\n \"not-run\": \"not run\",\n \"no-test\": \"no test\",\n};\n\n/** ` (+12 reachable, 3 type-only)`: what a step reaches beyond its entry file; empty when nothing. */\nfunction reachNote(step: FlowBookmapStep): string {\n const parts = [\n ...(step.files.length > 1 ? [`+${step.files.length - 1} reachable`] : []),\n ...(step.typeOnlyFiles.length > 0 ? [`${step.typeOnlyFiles.length} type-only`] : []),\n ];\n\n return parts.length === 0 ? \"\" : ` (${parts.join(\", \")})`;\n}\n\nfunction stepLines(steps: readonly FlowBookmapStep[]): string[] {\n const typeWidth = Math.max(0, ...steps.map((step) => step.type.length));\n const targetWidth = Math.max(0, ...steps.map((step) => step.target.length));\n\n return steps.map((step) => {\n const where =\n step.found === false\n ? \"not found\"\n : step.entry === null\n ? step.found === null && step.type === \"route\"\n ? \"no route facts\"\n : \"—\"\n : `${step.entry}${reachNote(step)}`;\n\n return `${step.index}. ${step.type.padEnd(typeWidth)} ${step.target.padEnd(targetWidth)} ${where}`;\n });\n}\n\nfunction criterionLines(criteria: readonly FlowBookmapCriterion[]): string[] {\n const labels = criteria.map(\n (criterion) => `${criterion.id}${criterion.app === null ? \"\" : ` [${criterion.app}]`}`,\n );\n const labelWidth = Math.max(0, ...labels.map((label) => label.length));\n const texts = criteria.map((criterion) => shorten(criterion.text, 36));\n const textWidth = Math.max(0, ...texts.map((text) => text.length));\n\n return criteria.map((criterion, index) => {\n const test = criterion.tests[0];\n const where =\n test === undefined\n ? \"\"\n : `${test.file}:${test.line}${criterion.tests.length > 1 ? ` (+${criterion.tests.length - 1})` : \"\"}`;\n const line = `${(labels[index] ?? \"\").padEnd(labelWidth)} ${STATUS_TEXT[criterion.status].padEnd(7)} ${\n where === \"\" ? (texts[index] ?? \"\") : `${(texts[index] ?? \"\").padEnd(textWidth)} ${where}`\n }`;\n\n return line.trimEnd();\n });\n}\n\nfunction formatFlow(result: ScryFlowResult): string[] {\n const flow = result.flow;\n const shown = result.bookmap.shownBy.map((item) => `${item.app} ${item.id}: ${item.block}`);\n\n return [\n [\n flow.ref,\n ...(flow.heading === null ? [] : [flow.heading.value]),\n `${flow.status.value} since ${flow.since.value}`,\n `who ${flow.who.value}`,\n ].join(\" \"),\n ...(flow.summary === null ? [] : [flow.summary]),\n ...stepLines(result.bookmap.steps),\n ...section(\n \"differs\",\n flow.differs.map((line) => `${line.name}: ${line.text}`),\n ),\n ...section(\n \"not handled\",\n flow.notHandled.map((line) => `${line.name}: ${line.text}`),\n 12,\n ),\n ...section(\n \"unknown\",\n flow.unknowns.map((item) => item.text.replace(/^Unknown:\\s*/, \"\")),\n ),\n ...criterionLines(result.bookmap.criteria),\n ...section(\"shown on\", shown.length > 0 ? [shown.join(\" \")] : []),\n ...section(\n \"history\",\n result.history.length > 0\n ? [\n result.history\n .map((entry) => `${entry.version.value} ${entry.word} (${releaseOf(entry)})`)\n .join(\" \"),\n ]\n : [],\n ),\n ...section(\"check\", [countsLine(result.findings)]),\n ...notes(result),\n ];\n}\n\nfunction formatSearch(result: ScrySearchResult): string[] {\n if (result.hits.length === 0)\n return [`no match for ${JSON.stringify(result.text)}`, ...notes(result)];\n\n const idWidth = Math.min(32, Math.max(0, ...result.hits.map((hit) => hit.id.length)));\n\n return [\n ...result.hits.map((hit) =>\n (hit.detail === null\n ? `${hit.type.padEnd(9)}${hit.id}`\n : `${hit.type.padEnd(9)}${hit.id.padEnd(idWidth)} ${hit.detail}`\n ).trimEnd(),\n ),\n ...notes(result),\n ];\n}\n\n/**\n * The compact text of a result (formats in the commands guide). Long lists in an\n * impact answer stop after 20 lines with a count; `options.all` prints them all.\n */\nexport function formatScryResult(result: ScryResult, options: FormatScryOptions = {}): string[] {\n switch (result.type) {\n case \"file\":\n return formatFile(result);\n case \"impact\":\n return formatImpact(result, options);\n case \"route\":\n return formatRoute(result);\n case \"feature\":\n return formatFeature(result);\n case \"flow\":\n return formatFlow(result);\n case \"search\":\n return formatSearch(result);\n }\n}\n"],"mappings":";AAkBA,MAAM,QAAQ;;AAGd,SAAS,QAAQ,OAAe,QAA2B,QAAQ,OAAiB;CAClF,IAAI,OAAO,WAAW,GAAG,OAAO,CAAC;CAEjC,MAAM,MAAM,IAAI,OAAO,KAAK,IAAI,OAAO,MAAM,SAAS,CAAC,CAAC;CAExD,OAAO,OAAO,KAAK,OAAO,UACxB,UAAU,IAAI,GAAG,MAAM,OAAO,IAAI,MAAM,IAAI,UAAU,GAAG,MAAM,OACjE;AACF;;AAGA,MAAM,cAAc;;AASpB,SAAS,eACP,OACA,QACA,SACA,OACU;CACV,MAAM,QAAQ,QAAQ,QAAQ,OAAO,SAAS,OAAO,MAAM,GAAG,WAAW;CACzE,MAAM,QAAQ,QAAQ,GAAG,MAAM,IAAI,OAAO,OAAO,IAAI,OAAO,KAAK;CAEjE,IAAI,MAAM,SAAS,OAAO,QACxB,MAAM,KACJ,GAAG,IAAI,OAAO,KAAK,IAAI,OAAO,MAAM,SAAS,CAAC,CAAC,EAAE,QAAQ,OAAO,SAAS,MAAM,OAAO,8BACxF;CAGF,OAAO;AACT;AAEA,MAAM,UAAU,OAAe,SAAyB,GAAG,MAAM,GAAG,OAAO,UAAU,IAAI,KAAK;;AAG9F,SAAS,QAAQ,MAAc,KAAqB;CAClD,IAAI,KAAK,UAAU,KAAK,OAAO;CAE/B,MAAM,QAAQ,KAAK,MAAM,GAAG;CAC5B,IAAI,OAAO;CAEX,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,OAAO,SAAS,KAAK,OAAO,GAAG,KAAK,GAAG;EAE7C,IAAI,KAAK,SAAS,IAAI,KAAK;EAE3B,OAAO;CACT;CAEA,OAAO,GAAG,SAAS,KAA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AO,OAAO,EAAE,IAAI,IAAI,SAAQ,CACjE,QAAQ,CACZ,GACA,GAAG,MAAM,MAAM,CACjB;AACF;;;;;AAMA,SAAgB,iBAAiB,QAAoB,UAA6B,CAAC,GAAa;CAC9F,QAAQ,OAAO,MAAf;EACE,KAAK,QACH,OAAO,WAAW,MAAM;EAC1B,KAAK,UACH,OAAO,aAAa,QAAQ,OAAO;EACrC,KAAK,SACH,OAAO,YAAY,MAAM;EAC3B,KAAK,WACH,OAAO,cAAc,MAAM;EAC7B,KAAK,QACH,OAAO,WAAW,MAAM;EAC1B,KAAK,UACH,OAAO,aAAa,MAAM;CAC9B;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"query.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/scry/query.ts"],"mappings":";;;;;;;;wBAqqBgB,KAAK,UAAU,kBAAkB,OAAO,YAAY"}
1
+ {"version":3,"file":"query.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/scry/query.ts"],"mappings":";;;;;;;;wBAyrBgB,KAAK,UAAU,kBAAkB,OAAO,YAAY"}
@@ -45,6 +45,16 @@ function siteApp(snapshot, site) {
45
45
  function mobileApp(snapshot, mobile) {
46
46
  return Object.values(snapshot.apps).find((app) => app.mobile?.id === mobile)?.app ?? mobile;
47
47
  }
48
+ /** The project files a file imports only through type-only imports, sorted. */
49
+ function typeOnlyImportsOf(file) {
50
+ const value = /* @__PURE__ */ new Set();
51
+ const typeOnly = /* @__PURE__ */ new Set();
52
+ for (const entry of file.imports) {
53
+ if (entry.file === null) continue;
54
+ (entry.typeOnly === true ? typeOnly : value).add(entry.file);
55
+ }
56
+ return sortedUnique([...typeOnly].filter((target) => !value.has(target)));
57
+ }
48
58
  /** The book entry of one file, as the book writes it. */
49
59
  function entryOf(snapshot, file) {
50
60
  const facts = snapshot.book.facts;
@@ -71,6 +81,7 @@ function entryOf(snapshot, file) {
71
81
  })),
72
82
  packages: packagesOf(file),
73
83
  imports: sortedUnique(file.imports.flatMap((entry) => entry.file === null ? [] : [entry.file])),
84
+ typeOnlyImports: typeOnlyImportsOf(file),
74
85
  importedBy: sortedUnique(file.importedBy),
75
86
  routes: [...routes.filter((route) => route.sourceFile === file.file).map((route) => ({
76
87
  ...routeRef(route),
@@ -153,7 +164,7 @@ function scryImpact(snapshot, query) {
153
164
  file: screen.file,
154
165
  type: "screen"
155
166
  })))];
156
- const flows = flowBookmaps(snapshot).filter((bookmap) => bookmap.steps.some((step) => step.files.includes(target.file))).map((bookmap) => bookmap.ref);
167
+ const flows = flowBookmaps(snapshot).filter((bookmap) => bookmap.steps.some((step) => step.files.includes(target.file) || step.typeOnlyFiles.includes(target.file))).map((bookmap) => bookmap.ref);
157
168
  const ownership = snapshot.ownership.files;
158
169
  const owner = ownership[target.file]?.owner ?? null;
159
170
  const specFiles = new Set(facts.files.filter((item) => item.type === "spec").map((item) => item.file));